From af23d9108f0d60eee4883c72f48e44fadb5f130a Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Thu, 7 May 2020 17:46:31 -0400 Subject: [PATCH 0001/1222] Fix nit and cargo.lock --- util/dev | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 util/dev diff --git a/util/dev b/util/dev new file mode 100755 index 000000000000..319de217e0d9 --- /dev/null +++ b/util/dev @@ -0,0 +1,7 @@ +#!/bin/sh +CARGO_TARGET_DIR=$(pwd)/target/ +export CARGO_TARGET_DIR + +echo 'Deprecated! `util/dev` usage is deprecated, please use `cargo dev` instead.' + +cd clippy_dev && cargo run -- "$@" From 9ea61e3dbaa70505af7febd4e20ac8e3d70f66c3 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 8 May 2020 13:57:01 +0200 Subject: [PATCH 0002/1222] Fix clippy. --- clippy_lints/src/bytecount.rs | 7 ++++--- clippy_lints/src/inline_fn_without_body.rs | 5 +++-- clippy_lints/src/len_zero.rs | 6 +++--- clippy_lints/src/lib.rs | 2 +- clippy_lints/src/map_clone.rs | 4 ++-- clippy_lints/src/non_expressive_names.rs | 4 ++-- clippy_lints/src/unsafe_removed_from_name.rs | 4 ++-- clippy_lints/src/utils/hir_utils.rs | 4 ++-- clippy_lints/src/utils/internal_lints.rs | 10 +++++----- clippy_lints/src/utils/mod.rs | 2 +- clippy_lints/src/utils/ptr.rs | 9 ++++----- clippy_lints/src/utils/usage.rs | 5 ++--- 12 files changed, 31 insertions(+), 31 deletions(-) diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index 91d3e47d7870..278d043732f4 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -3,12 +3,13 @@ use crate::utils::{ span_lint_and_sugg, walk_ptrs_ty, }; use if_chain::if_chain; -use rustc_ast::ast::{Name, UintTy}; +use rustc_ast::ast::{UintTy}; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::Symbol; declare_clippy_lint! { /// **What it does:** Checks for naive byte counts @@ -95,11 +96,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount { } } -fn check_arg(name: Name, arg: Name, needle: &Expr<'_>) -> bool { +fn check_arg(name: Symbol, arg: Symbol, needle: &Expr<'_>) -> bool { name == arg && !contains_name(name, needle) } -fn get_path_name(expr: &Expr<'_>) -> Option { +fn get_path_name(expr: &Expr<'_>) -> Option { match expr.kind { ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) | ExprKind::Unary(UnOp::UnDeref, ref e) => { get_path_name(e) diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index 1ebfb3c8162a..475610dda475 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -2,11 +2,12 @@ use crate::utils::span_lint_and_then; use crate::utils::sugg::DiagnosticBuilderExt; -use rustc_ast::ast::{Attribute, Name}; +use rustc_ast::ast::Attribute; use rustc_errors::Applicability; use rustc_hir::{TraitFn, TraitItem, TraitItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::Symbol; declare_clippy_lint! { /// **What it does:** Checks for `#[inline]` on trait methods without bodies @@ -38,7 +39,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InlineFnWithoutBody { } } -fn check_attrs(cx: &LateContext<'_, '_>, name: Name, attrs: &[Attribute]) { +fn check_attrs(cx: &LateContext<'_, '_>, name: Symbol, attrs: &[Attribute]) { for attr in attrs { if !attr.check_name(sym!(inline)) { continue; diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 1d86ca9696f2..2ec0b5a8d6fb 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -1,5 +1,5 @@ use crate::utils::{get_item_name, snippet_with_applicability, span_lint, span_lint_and_sugg, walk_ptrs_ty}; -use rustc_ast::ast::{LitKind, Name}; +use rustc_ast::ast::LitKind; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; @@ -7,7 +7,7 @@ use rustc_hir::{AssocItemKind, BinOpKind, Expr, ExprKind, ImplItemRef, Item, Ite use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::{Span, Spanned}; +use rustc_span::source_map::{Span, Spanned, Symbol}; declare_clippy_lint! { /// **What it does:** Checks for getting the length of something via `.len()` @@ -226,7 +226,7 @@ fn check_cmp(cx: &LateContext<'_, '_>, span: Span, method: &Expr<'_>, lit: &Expr fn check_len( cx: &LateContext<'_, '_>, span: Span, - method_name: Name, + method_name: Symbol, args: &[Expr<'_>], lit: &LitKind, op: &str, diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index c995be5edc25..1f135cba6e4e 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -333,7 +333,7 @@ mod zero_div_zero; pub use crate::utils::conf::Conf; mod reexport { - pub use rustc_ast::ast::Name; + pub use rustc_span::Symbol as Name; } /// Register all pre expansion lints diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 0b346393ac38..0163b3f8dbc8 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -3,14 +3,14 @@ use crate::utils::{ is_copy, is_type_diagnostic_item, match_trait_method, remove_blocks, snippet_with_applicability, span_lint_and_sugg, }; use if_chain::if_chain; -use rustc_ast::ast::Ident; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::Mutability; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; +use rustc_span::Span; +use rustc_span::symbol::Ident; declare_clippy_lint! { /// **What it does:** Checks for usage of `iterator.map(|x| x.clone())` and suggests diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 45809b359866..2b51b7320758 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -1,13 +1,13 @@ use crate::utils::{span_lint, span_lint_and_then}; use rustc_ast::ast::{ - Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Ident, Item, ItemKind, Local, MacCall, Pat, PatKind, + Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Item, ItemKind, Local, MacCall, Pat, PatKind, }; use rustc_ast::attr; use rustc_ast::visit::{walk_block, walk_expr, walk_pat, Visitor}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; -use rustc_span::symbol::SymbolStr; +use rustc_span::symbol::{Ident, SymbolStr}; use std::cmp::Ordering; declare_clippy_lint! { diff --git a/clippy_lints/src/unsafe_removed_from_name.rs b/clippy_lints/src/unsafe_removed_from_name.rs index 86c469a4dccf..735800e7e741 100644 --- a/clippy_lints/src/unsafe_removed_from_name.rs +++ b/clippy_lints/src/unsafe_removed_from_name.rs @@ -1,9 +1,9 @@ use crate::utils::span_lint; -use rustc_ast::ast::{Ident, Item, ItemKind, UseTree, UseTreeKind}; +use rustc_ast::ast::{Item, ItemKind, UseTree, UseTreeKind}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; -use rustc_span::symbol::SymbolStr; +use rustc_span::symbol::{Ident, SymbolStr}; declare_clippy_lint! { /// **What it does:** Checks for imports that remove "unsafe" from an item's diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index 02b721fd378f..bd7da57c665d 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -1,6 +1,5 @@ use crate::consts::{constant_context, constant_simple}; use crate::utils::differing_macro_contexts; -use rustc_ast::ast::Name; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir::{ BinOpKind, Block, BlockCheckMode, BodyId, BorrowKind, CaptureBy, Expr, ExprKind, Field, FnRetTy, GenericArg, @@ -10,6 +9,7 @@ use rustc_hir::{ use rustc_lint::LateContext; use rustc_middle::ich::StableHashingContextProvider; use rustc_middle::ty::TypeckTables; +use rustc_span::Symbol; use std::hash::Hash; /// Type used to check whether two ast are the same. This is different from the @@ -544,7 +544,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } - pub fn hash_name(&mut self, n: Name) { + pub fn hash_name(&mut self, n: Symbol) { n.as_str().hash(&mut self.s); } diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 5bf9acdc5f7c..8e1b047f6f80 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -4,7 +4,7 @@ use crate::utils::{ span_lint_and_help, span_lint_and_sugg, walk_ptrs_ty, }; use if_chain::if_chain; -use rustc_ast::ast::{Crate as AstCrate, ItemKind, LitKind, Name, NodeId}; +use rustc_ast::ast::{Crate as AstCrate, ItemKind, LitKind, NodeId}; use rustc_ast::visit::FnKind; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::Applicability; @@ -17,7 +17,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::{Span, Spanned}; -use rustc_span::symbol::SymbolStr; +use rustc_span::symbol::{Symbol, SymbolStr}; use std::borrow::{Borrow, Cow}; @@ -245,8 +245,8 @@ impl EarlyLintPass for ClippyLintsInternal { #[derive(Clone, Debug, Default)] pub struct LintWithoutLintPass { - declared_lints: FxHashMap, - registered_lints: FxHashSet, + declared_lints: FxHashMap, + registered_lints: FxHashSet, } impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS]); @@ -357,7 +357,7 @@ fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty<'_>) -> bool { } struct LintCollector<'a, 'tcx> { - output: &'a mut FxHashSet, + output: &'a mut FxHashSet, cx: &'a LateContext<'a, 'tcx>, } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 04b4b4237619..2fd080e9ef0f 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1069,7 +1069,7 @@ pub fn is_allowed(cx: &LateContext<'_, '_>, lint: &'static Lint, id: HirId) -> b cx.tcx.lint_level_at_node(lint, id).0 == Level::Allow } -pub fn get_arg_name(pat: &Pat<'_>) -> Option { +pub fn get_arg_name(pat: &Pat<'_>) -> Option { match pat.kind { PatKind::Binding(.., ident, None) => Some(ident.name), PatKind::Ref(ref subpat, _) => get_arg_name(subpat), diff --git a/clippy_lints/src/utils/ptr.rs b/clippy_lints/src/utils/ptr.rs index 240bf2449cb5..fb6bd5e81585 100644 --- a/clippy_lints/src/utils/ptr.rs +++ b/clippy_lints/src/utils/ptr.rs @@ -1,10 +1,9 @@ use crate::utils::{get_pat_name, match_var, snippet}; -use rustc_ast::ast::Name; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_hir::{Body, BodyId, Expr, ExprKind, Param}; use rustc_lint::LateContext; use rustc_middle::hir::map::Map; -use rustc_span::source_map::Span; +use rustc_span::{Span, Symbol}; use std::borrow::Cow; pub fn get_spans( @@ -25,7 +24,7 @@ pub fn get_spans( fn extract_clone_suggestions<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - name: Name, + name: Symbol, replace: &[(&'static str, &'static str)], body: &'tcx Body<'_>, ) -> Option)>> { @@ -46,7 +45,7 @@ fn extract_clone_suggestions<'a, 'tcx>( struct PtrCloneVisitor<'a, 'tcx> { cx: &'a LateContext<'a, 'tcx>, - name: Name, + name: Symbol, replace: &'a [(&'static str, &'static str)], spans: Vec<(Span, Cow<'static, str>)>, abort: bool, @@ -83,6 +82,6 @@ impl<'a, 'tcx> Visitor<'tcx> for PtrCloneVisitor<'a, 'tcx> { } } -fn get_binding_name(arg: &Param<'_>) -> Option { +fn get_binding_name(arg: &Param<'_>) -> Option { get_pat_name(&arg.pat) } diff --git a/clippy_lints/src/utils/usage.rs b/clippy_lints/src/utils/usage.rs index c14da6aacea0..e85356779877 100644 --- a/clippy_lints/src/utils/usage.rs +++ b/clippy_lints/src/utils/usage.rs @@ -1,5 +1,4 @@ use crate::utils::match_var; -use rustc_ast::ast; use rustc_data_structures::fx::FxHashSet; use rustc_hir::def::Res; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; @@ -8,7 +7,7 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::hir::map::Map; use rustc_middle::ty; -use rustc_span::symbol::Ident; +use rustc_span::symbol::{Ident, Symbol}; use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Place, PlaceBase}; /// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined. @@ -78,7 +77,7 @@ impl<'tcx> Delegate<'tcx> for MutVarsDelegate { } pub struct UsedVisitor { - pub var: ast::Name, // var to look for + pub var: Symbol, // var to look for pub used: bool, // has the var been used otherwise? } From 2f07bb4059434b62e4bdff2c314a6cc12613752d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 10 May 2020 23:36:41 +0200 Subject: [PATCH 0003/1222] rustc_driver: factor out computing the exit code --- src/driver.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index 2c699998ea90..1ce0300f2390 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -296,7 +296,7 @@ pub fn main() { rustc_driver::init_rustc_env_logger(); lazy_static::initialize(&ICE_HOOK); exit( - rustc_driver::catch_fatal_errors(move || { + rustc_driver::catch_with_exit_code(move || { let mut orig_args: Vec = env::args().collect(); if orig_args.iter().any(|a| a == "--version" || a == "-V") { @@ -411,7 +411,5 @@ pub fn main() { if clippy_enabled { &mut clippy } else { &mut default }; rustc_driver::run_compiler(&args, callbacks, None, None) }) - .and_then(|result| result) - .is_err() as i32, ) } From a542f9d3772cfa30255d70a269f78f4cb205ee55 Mon Sep 17 00:00:00 2001 From: Julian Wollersberger <24991778+Julian-Wollersberger@users.noreply.github.com> Date: Wed, 13 May 2020 10:03:49 +0200 Subject: [PATCH 0004/1222] Replace some usages of the old `unescape_` functions in AST, clippy and tests. --- clippy_lints/src/write.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 5ad43ad55a36..26bf463bd292 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -483,8 +483,8 @@ fn check_newlines(fmtstr: &StrLit) -> bool { }; match fmtstr.style { - StrStyle::Cooked => unescape::unescape_str(contents, &mut cb), - StrStyle::Raw(_) => unescape::unescape_raw_str(contents, &mut cb), + StrStyle::Cooked => unescape::unescape_literal(contents, unescape::Mode::Str, &mut cb), + StrStyle::Raw(_) => unescape::unescape_literal(contents, unescape::Mode::RawStr, &mut cb), } should_lint From 52f5d507c3be92214daaabf4945659b437c05662 Mon Sep 17 00:00:00 2001 From: csmoe Date: Thu, 14 May 2020 23:07:46 +0800 Subject: [PATCH 0005/1222] implement type_implments_trait query --- clippy_lints/src/utils/mod.rs | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 2fd080e9ef0f..84a324f76c5b 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -40,15 +40,12 @@ use rustc_hir::{ use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, Level, Lint, LintContext}; use rustc_middle::hir::map::Map; -use rustc_middle::traits; use rustc_middle::ty::{self, layout::IntegerExt, subst::GenericArg, Binder, Ty, TyCtxt, TypeFoldable}; use rustc_span::hygiene::{ExpnKind, MacroKind}; use rustc_span::source_map::original_sp; use rustc_span::symbol::{self, kw, Symbol}; use rustc_span::{BytePos, Pos, Span, DUMMY_SP}; use rustc_target::abi::Integer; -use rustc_trait_selection::traits::predicate_for_trait_def; -use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt; use rustc_trait_selection::traits::query::normalize::AtExt; use smallvec::SmallVec; @@ -326,19 +323,8 @@ pub fn implements_trait<'a, 'tcx>( trait_id: DefId, ty_params: &[GenericArg<'tcx>], ) -> bool { - let ty = cx.tcx.erase_regions(&ty); - let obligation = predicate_for_trait_def( - cx.tcx, - cx.param_env, - traits::ObligationCause::dummy(), - trait_id, - 0, - ty, - ty_params, - ); - cx.tcx - .infer_ctxt() - .enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation)) + let ty_params = cx.tcx.mk_substs(ty_params.iter()); + cx.tcx.type_implements_trait((trait_id, ty, ty_params, cx.param_env)) } /// Gets the `hir::TraitRef` of the trait the given method is implemented for. From 4d57e09042aa11b273e77fa64c387c32b809f57b Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Wed, 6 May 2020 15:03:53 +0100 Subject: [PATCH 0006/1222] Handle InlineAsm in clippy --- clippy_lints/src/loops.rs | 18 ++++++++-- clippy_lints/src/utils/author.rs | 4 +++ clippy_lints/src/utils/hir_utils.rs | 55 +++++++++++++++++++++++++++-- clippy_lints/src/utils/inspector.rs | 27 +++++++++++++- clippy_lints/src/utils/sugg.rs | 2 ++ clippy_lints/src/write.rs | 5 +-- 6 files changed, 104 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 84e8a010738c..38a5829b3f74 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -16,8 +16,8 @@ use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor}; use rustc_hir::{ - def_id, BinOpKind, BindingAnnotation, Block, BorrowKind, Expr, ExprKind, GenericArg, HirId, LoopSource, - MatchSource, Mutability, Node, Pat, PatKind, QPath, Stmt, StmtKind, + def_id, BinOpKind, BindingAnnotation, Block, BorrowKind, Expr, ExprKind, GenericArg, HirId, InlineAsmOperand, + LoopSource, MatchSource, Mutability, Node, Pat, PatKind, QPath, Stmt, StmtKind, }; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass, LintContext}; @@ -693,6 +693,20 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { NeverLoopResult::AlwaysBreak } }, + ExprKind::InlineAsm(ref asm) => asm + .operands + .iter() + .map(|o| match o { + InlineAsmOperand::In { expr, .. } + | InlineAsmOperand::InOut { expr, .. } + | InlineAsmOperand::Const { expr } + | InlineAsmOperand::Sym { expr } => never_loop_expr(expr, main_loop_id), + InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter(), main_loop_id), + InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { + never_loop_expr_all(&mut once(in_expr).chain(out_expr.iter()), main_loop_id) + }, + }) + .fold(NeverLoopResult::Otherwise, combine_both), ExprKind::Struct(_, _, None) | ExprKind::Yield(_, _) | ExprKind::Closure(_, _, _, _, _) diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 74601008dca4..bbcf396eef7d 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -469,6 +469,10 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { println!("Ret(None) = {};", current); } }, + ExprKind::InlineAsm(_) => { + println!("InlineAsm(_) = {};", current); + println!(" // unimplemented: `ExprKind::InlineAsm` is not further destructured at the moment"); + }, ExprKind::LlvmInlineAsm(_) => { println!("LlvmInlineAsm(_) = {};", current); println!(" // unimplemented: `ExprKind::LlvmInlineAsm` is not further destructured at the moment"); diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index bd7da57c665d..92c27e79452a 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -1,10 +1,11 @@ use crate::consts::{constant_context, constant_simple}; use crate::utils::differing_macro_contexts; +use rustc_ast::ast::InlineAsmTemplatePiece; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir::{ BinOpKind, Block, BlockCheckMode, BodyId, BorrowKind, CaptureBy, Expr, ExprKind, Field, FnRetTy, GenericArg, - GenericArgs, Guard, Lifetime, LifetimeName, ParamName, Pat, PatKind, Path, PathSegment, QPath, Stmt, StmtKind, Ty, - TyKind, TypeBinding, + GenericArgs, Guard, InlineAsmOperand, Lifetime, LifetimeName, ParamName, Pat, PatKind, Path, PathSegment, QPath, + Stmt, StmtKind, Ty, TyKind, TypeBinding, }; use rustc_lint::LateContext; use rustc_middle::ich::StableHashingContextProvider; @@ -474,6 +475,56 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_expr(a); self.hash_expr(i); }, + ExprKind::InlineAsm(ref asm) => { + for piece in asm.template { + match piece { + InlineAsmTemplatePiece::String(s) => s.hash(&mut self.s), + InlineAsmTemplatePiece::Placeholder { + operand_idx, + modifier, + span: _, + } => { + operand_idx.hash(&mut self.s); + modifier.hash(&mut self.s); + }, + } + } + asm.options.hash(&mut self.s); + for op in asm.operands { + match op { + InlineAsmOperand::In { reg, expr } => { + reg.hash(&mut self.s); + self.hash_expr(expr); + }, + InlineAsmOperand::Out { reg, late, expr } => { + reg.hash(&mut self.s); + late.hash(&mut self.s); + if let Some(expr) = expr { + self.hash_expr(expr); + } + }, + InlineAsmOperand::InOut { reg, late, expr } => { + reg.hash(&mut self.s); + late.hash(&mut self.s); + self.hash_expr(expr); + }, + InlineAsmOperand::SplitInOut { + reg, + late, + in_expr, + out_expr, + } => { + reg.hash(&mut self.s); + late.hash(&mut self.s); + self.hash_expr(in_expr); + if let Some(out_expr) = out_expr { + self.hash_expr(out_expr); + } + }, + InlineAsmOperand::Const { expr } | InlineAsmOperand::Sym { expr } => self.hash_expr(expr), + } + } + }, ExprKind::LlvmInlineAsm(..) | ExprKind::Err => {}, ExprKind::Lit(ref l) => { l.node.hash(&mut self.s); diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 7e8c61ba24a2..748c11fac64f 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -1,7 +1,7 @@ //! checks for attributes use crate::utils::get_attr; -use rustc_ast::ast::Attribute; +use rustc_ast::ast::{Attribute, InlineAsmTemplatePiece}; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::Session; @@ -282,6 +282,31 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, indent: usize) { print_expr(cx, e, indent + 1); } }, + hir::ExprKind::InlineAsm(ref asm) => { + println!("{}InlineAsm", ind); + println!("{}template: {}", ind, InlineAsmTemplatePiece::to_string(asm.template)); + println!("{}options: {:?}", ind, asm.options); + println!("{}operands:", ind); + for op in asm.operands { + match op { + hir::InlineAsmOperand::In { expr, .. } => print_expr(cx, expr, indent + 1), + hir::InlineAsmOperand::Out { expr, .. } => { + if let Some(expr) = expr { + print_expr(cx, expr, indent + 1); + } + }, + hir::InlineAsmOperand::InOut { expr, .. } => print_expr(cx, expr, indent + 1), + hir::InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { + print_expr(cx, in_expr, indent + 1); + if let Some(out_expr) = out_expr { + print_expr(cx, out_expr, indent + 1); + } + }, + hir::InlineAsmOperand::Const { expr } => print_expr(cx, expr, indent + 1), + hir::InlineAsmOperand::Sym { expr } => print_expr(cx, expr, indent + 1), + } + } + }, hir::ExprKind::LlvmInlineAsm(ref asm) => { let inputs = &asm.inputs_exprs; let outputs = &asm.outputs_exprs; diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index a8fe637d3d97..4ebe2e2852fb 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -108,6 +108,7 @@ impl<'a> Sugg<'a> { | hir::ExprKind::Call(..) | hir::ExprKind::Field(..) | hir::ExprKind::Index(..) + | hir::ExprKind::InlineAsm(..) | hir::ExprKind::LlvmInlineAsm(..) | hir::ExprKind::Lit(..) | hir::ExprKind::Loop(..) @@ -150,6 +151,7 @@ impl<'a> Sugg<'a> { | ast::ExprKind::Field(..) | ast::ExprKind::ForLoop(..) | ast::ExprKind::Index(..) + | ast::ExprKind::InlineAsm(..) | ast::ExprKind::LlvmInlineAsm(..) | ast::ExprKind::Lit(..) | ast::ExprKind::Loop(..) diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 26bf463bd292..dfa6223f1b9d 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -353,7 +353,8 @@ impl Write { is_write: bool, ) -> (Option, Option) { use fmt_macros::{ - AlignUnknown, ArgumentImplicitlyIs, ArgumentIs, ArgumentNamed, CountImplied, FormatSpec, Parser, Piece, + AlignUnknown, ArgumentImplicitlyIs, ArgumentIs, ArgumentNamed, CountImplied, FormatSpec, ParseMode, Parser, + Piece, }; let tts = tts.clone(); @@ -376,7 +377,7 @@ impl Write { }; let tmp = fmtstr.symbol.as_str(); let mut args = vec![]; - let mut fmt_parser = Parser::new(&tmp, None, Vec::new(), false); + let mut fmt_parser = Parser::new(&tmp, None, None, false, ParseMode::Format); while let Some(piece) = fmt_parser.next() { if !fmt_parser.errors.is_empty() { return (None, expr); From ab33c00ecac83a939452aac984523be99ac1d523 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Mon, 11 May 2020 21:09:57 +0200 Subject: [PATCH 0007/1222] rename `Predicate` to `PredicateKind`, introduce alias --- clippy_lints/src/future_not_send.rs | 2 +- clippy_lints/src/methods/mod.rs | 4 ++-- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/utils/mod.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 704a95ec0a09..2c2965433fd0 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -3,7 +3,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{Opaque, Predicate::Trait, ToPolyTraitRef}; +use rustc_middle::ty::{Opaque, PredicateKind::Trait, ToPolyTraitRef}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt; diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 626427c15ecf..79c21d9bc0a6 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -18,7 +18,7 @@ use rustc_lint::{LateContext, LateLintPass, Lint, LintContext}; use rustc_middle::hir::map::Map; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::subst::GenericArgKind; -use rustc_middle::ty::{self, Predicate, Ty}; +use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::symbol::{sym, SymbolStr}; @@ -1497,7 +1497,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { // one of the associated types must be Self for predicate in cx.tcx.predicates_of(def_id).predicates { match predicate { - (Predicate::Projection(poly_projection_predicate), _) => { + (ty::PredicateKind::Projection(poly_projection_predicate), _) => { let binder = poly_projection_predicate.ty(); let associated_type = binder.skip_binder(); diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index ed48ab548978..8f94f143bae7 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -114,7 +114,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.iter().copied()) .filter(|p| !p.is_global()) .filter_map(|obligation| { - if let ty::Predicate::Trait(poly_trait_ref, _) = obligation.predicate { + if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate { if poly_trait_ref.def_id() == sized_trait || poly_trait_ref.skip_binder().has_escaping_bound_vars() { return None; diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 438a9f42ccd2..3f5693d7e680 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1299,7 +1299,7 @@ pub fn is_must_use_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> boo ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates { - if let ty::Predicate::Trait(ref poly_trait_predicate, _) = predicate { + if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate { if must_use_attr(&cx.tcx.get_attrs(poly_trait_predicate.skip_binder().trait_ref.def_id)).is_some() { return true; } From 65e45e226917ce4066b06c43a3b7203d49559dca Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Mon, 11 May 2020 22:06:41 +0200 Subject: [PATCH 0008/1222] introduce newtype'd `Predicate<'tcx>` --- clippy_lints/src/future_not_send.rs | 2 +- clippy_lints/src/methods/mod.rs | 6 +++--- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/utils/mod.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 2c2965433fd0..0a02aa7533c1 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -91,7 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FutureNotSend { cx.tcx.infer_ctxt().enter(|infcx| { for FulfillmentError { obligation, .. } in send_errors { infcx.maybe_note_obligation_cause_for_async_await(db, &obligation); - if let Trait(trait_pred, _) = obligation.predicate { + if let Trait(trait_pred, _) = obligation.predicate.kind() { let trait_ref = trait_pred.to_poly_trait_ref(); db.note(&*format!( "`{}` doesn't implement `{}`", diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 79c21d9bc0a6..810a226b50d2 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1496,8 +1496,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { if let ty::Opaque(def_id, _) = ret_ty.kind { // one of the associated types must be Self for predicate in cx.tcx.predicates_of(def_id).predicates { - match predicate { - (ty::PredicateKind::Projection(poly_projection_predicate), _) => { + match predicate.0.kind() { + ty::PredicateKind::Projection(poly_projection_predicate) => { let binder = poly_projection_predicate.ty(); let associated_type = binder.skip_binder(); @@ -1506,7 +1506,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { return; } }, - (_, _) => {}, + _ => {}, } } } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 8f94f143bae7..60c536005433 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -114,7 +114,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.iter().copied()) .filter(|p| !p.is_global()) .filter_map(|obligation| { - if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate { + if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate.kind() { if poly_trait_ref.def_id() == sized_trait || poly_trait_ref.skip_binder().has_escaping_bound_vars() { return None; diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 3f5693d7e680..f22473275c46 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1299,7 +1299,7 @@ pub fn is_must_use_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> boo ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates { - if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate { + if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate.kind() { if must_use_attr(&cx.tcx.get_attrs(poly_trait_predicate.skip_binder().trait_ref.def_id)).is_some() { return true; } From 164374df5940051a4594455c9476ba6c928e8aac Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 22 May 2020 15:29:47 +0000 Subject: [PATCH 0009/1222] Stabilize str_strip feature --- src/driver.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/driver.rs b/src/driver.rs index d3a7e24937f9..3e1f423865b1 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -1,6 +1,5 @@ #![cfg_attr(feature = "deny-warnings", deny(warnings))] #![feature(rustc_private)] -#![feature(str_strip)] // FIXME: switch to something more ergonomic here, once available. // (Currently there is no way to opt into sysroot crates without `extern crate`.) From 9b62fb63e0c9d69f760530acfccd8783c6b3a4a6 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Fri, 15 May 2020 21:44:28 -0700 Subject: [PATCH 0010/1222] Use `OnceCell` instead of `Once` --- clippy_lints/src/missing_inline.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 5300fd2215b3..3ad3d5aee4d4 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -71,7 +71,7 @@ fn check_missing_inline_attrs(cx: &LateContext<'_, '_>, attrs: &[ast::Attribute] fn is_executable(cx: &LateContext<'_, '_>) -> bool { use rustc_session::config::CrateType; - cx.tcx.sess.crate_types.get().iter().any(|t: &CrateType| match t { + cx.tcx.sess.crate_types().iter().any(|t: &CrateType| match t { CrateType::Executable => true, _ => false, }) From 3f445d2652bc35f05ac970cd4cbf84a578989fd6 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Sat, 23 May 2020 11:49:24 +0200 Subject: [PATCH 0011/1222] iterate List by value --- clippy_lints/src/needless_pass_by_value.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 60c536005433..1621c7f947c3 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -111,7 +111,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { let fn_def_id = cx.tcx.hir().local_def_id(hir_id); - let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.iter().copied()) + let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.iter()) .filter(|p| !p.is_global()) .filter_map(|obligation| { if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate.kind() { @@ -179,7 +179,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { .substs .iter() .skip(1) - .cloned() .collect::>(); implements_trait(cx, ty_empty_region, t.def_id(), ty_params) }) From 83633ad204736fb4b7df2cc318397b615e96d222 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 28 May 2020 17:19:30 +0200 Subject: [PATCH 0012/1222] Temp fix: don't run cargo lint tests in rustc test suite --- tests/compile-test.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 2758b9a7e760..1c4914a470c9 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -153,6 +153,9 @@ fn run_ui_toml(config: &mut compiletest::Config) { } fn run_ui_cargo(config: &mut compiletest::Config) { + if cargo::is_rustc_test_suite() { + return; + } fn run_tests( config: &compiletest::Config, filter: &Option, From 2492ac71e4b935aeb0346b276ecadf7cc1121ba1 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 30 May 2020 18:48:54 +0900 Subject: [PATCH 0013/1222] Return early to avoid ICE --- clippy_lints/src/utils/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 6c1488664bf0..6dd8fef7e82d 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -323,6 +323,11 @@ pub fn implements_trait<'a, 'tcx>( trait_id: DefId, ty_params: &[GenericArg<'tcx>], ) -> bool { + // Do not check on infer_types to avoid panic in evaluate_obligation. + if ty.has_infer_types() { + return false; + } + let ty = cx.tcx.erase_regions(&ty); let ty_params = cx.tcx.mk_substs(ty_params.iter()); cx.tcx.type_implements_trait((trait_id, ty, ty_params, cx.param_env)) } From f6b6915e4f259cf95571e7a634f288e66a3cfdc6 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Sat, 23 May 2020 11:12:06 -0700 Subject: [PATCH 0014/1222] Call `skip_binder` or `no_bound_vars` before `self_ty` --- clippy_lints/src/future_not_send.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 0a02aa7533c1..17dd3cd5493e 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -95,7 +95,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FutureNotSend { let trait_ref = trait_pred.to_poly_trait_ref(); db.note(&*format!( "`{}` doesn't implement `{}`", - trait_ref.self_ty(), + trait_ref.skip_binder().self_ty(), trait_ref.print_only_trait_path(), )); } From a71f4a532caed7e199f874d61980682a4f71f90b Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 2 Jun 2020 20:19:49 +0300 Subject: [PATCH 0015/1222] Rename the crates in source code --- clippy_lints/src/write.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index dfa6223f1b9d..006503b546ed 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -352,7 +352,7 @@ impl Write { tts: &TokenStream, is_write: bool, ) -> (Option, Option) { - use fmt_macros::{ + use rustc_parse_format::{ AlignUnknown, ArgumentImplicitlyIs, ArgumentIs, ArgumentNamed, CountImplied, FormatSpec, ParseMode, Parser, Piece, }; From 6557865d330c14a9e7ba7a0e3c450fae41ad6395 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 2 Jun 2020 22:46:42 +0300 Subject: [PATCH 0016/1222] Update fulldeps tests and clippy --- clippy_lints/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 902f3d56c1e4..b7d928d249f9 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -16,8 +16,6 @@ // FIXME: switch to something more ergonomic here, once available. // (Currently there is no way to opt into sysroot crates without `extern crate`.) #[allow(unused_extern_crates)] -extern crate fmt_macros; -#[allow(unused_extern_crates)] extern crate rustc_ast; #[allow(unused_extern_crates)] extern crate rustc_ast_pretty; @@ -48,6 +46,8 @@ extern crate rustc_mir; #[allow(unused_extern_crates)] extern crate rustc_parse; #[allow(unused_extern_crates)] +extern crate rustc_parse_format; +#[allow(unused_extern_crates)] extern crate rustc_session; #[allow(unused_extern_crates)] extern crate rustc_span; From 0df88f3afcfd81a9c7d477e9660ec0dad8e2e563 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Wed, 3 Jun 2020 15:15:53 -0400 Subject: [PATCH 0017/1222] Bump to 1.46 --- clippy_lints/src/write.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index dfa6223f1b9d..37fbc2bad468 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -279,13 +279,13 @@ impl EarlyLintPass for Write { if let (Some(fmt_str), expr) = self.check_tts(cx, &mac.args.inner_tokens(), true) { if fmt_str.symbol == Symbol::intern("") { let mut applicability = Applicability::MachineApplicable; - let suggestion = expr.map_or_else( - move || { + let suggestion = match expr { + Some(expr) => snippet_with_applicability(cx, expr.span, "v", &mut applicability), + None => { applicability = Applicability::HasPlaceholders; Cow::Borrowed("v") }, - move |expr| snippet_with_applicability(cx, expr.span, "v", &mut applicability), - ); + }; span_lint_and_sugg( cx, From e433aab22168fbae69531c9a78a73aaf044632d5 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 2 Jun 2020 07:59:11 +0000 Subject: [PATCH 0018/1222] Migrate to numeric associated consts --- clippy_lints/src/consts.rs | 10 ++--- clippy_lints/src/enum_clike.rs | 2 +- clippy_lints/src/types.rs | 52 ++++++++++++------------- tests/ui/cast.rs | 10 ++--- tests/ui/implicit_saturating_sub.rs | 14 +++---- tests/ui/implicit_saturating_sub.stderr | 14 +++---- 6 files changed, 51 insertions(+), 51 deletions(-) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 81ddc8c0067c..22c5acca064e 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -254,11 +254,11 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { if let ["core", "num", int_impl, "max_value"] = *def_path; then { let value = match int_impl { - "" => i8::max_value() as u128, - "" => i16::max_value() as u128, - "" => i32::max_value() as u128, - "" => i64::max_value() as u128, - "" => i128::max_value() as u128, + "" => i8::MAX as u128, + "" => i16::MAX as u128, + "" => i32::MAX as u128, + "" => i64::MAX as u128, + "" => i128::MAX as u128, _ => return None, }; Some(Constant::Int(value)) diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index a1fed3fb6e20..12b62f5cf978 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -65,7 +65,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant { continue; } }, - ty::Uint(UintTy::Usize) if val > u128::from(u32::max_value()) => {}, + ty::Uint(UintTy::Usize) if val > u128::from(u32::MAX) => {}, _ => continue, } span_lint( diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index bc5fe44b30f8..a9d8c66f2618 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -1946,18 +1946,18 @@ fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_ let which = match (&ty.kind, cv) { (&ty::Bool, Constant::Bool(false)) | (&ty::Uint(_), Constant::Int(0)) => Minimum, (&ty::Int(ity), Constant::Int(i)) - if i == unsext(cx.tcx, i128::min_value() >> (128 - int_bits(cx.tcx, ity)), ity) => + if i == unsext(cx.tcx, i128::MIN >> (128 - int_bits(cx.tcx, ity)), ity) => { Minimum }, (&ty::Bool, Constant::Bool(true)) => Maximum, (&ty::Int(ity), Constant::Int(i)) - if i == unsext(cx.tcx, i128::max_value() >> (128 - int_bits(cx.tcx, ity)), ity) => + if i == unsext(cx.tcx, i128::MAX >> (128 - int_bits(cx.tcx, ity)), ity) => { Maximum }, - (&ty::Uint(uty), Constant::Int(i)) if clip(cx.tcx, u128::max_value(), uty) == i => Maximum, + (&ty::Uint(uty), Constant::Int(i)) if clip(cx.tcx, u128::MAX, uty) == i => Maximum, _ => return None, }; @@ -2039,7 +2039,7 @@ impl FullInt { fn cmp_s_u(s: i128, u: u128) -> Ordering { if s < 0 { Ordering::Less - } else if u > (i128::max_value() as u128) { + } else if u > (i128::MAX as u128) { Ordering::Greater } else { (s as u128).cmp(&u) @@ -2084,48 +2084,48 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'_>) match pre_cast_ty.kind { ty::Int(int_ty) => Some(match int_ty { IntTy::I8 => ( - FullInt::S(i128::from(i8::min_value())), - FullInt::S(i128::from(i8::max_value())), + FullInt::S(i128::from(i8::MIN)), + FullInt::S(i128::from(i8::MAX)), ), IntTy::I16 => ( - FullInt::S(i128::from(i16::min_value())), - FullInt::S(i128::from(i16::max_value())), + FullInt::S(i128::from(i16::MIN)), + FullInt::S(i128::from(i16::MAX)), ), IntTy::I32 => ( - FullInt::S(i128::from(i32::min_value())), - FullInt::S(i128::from(i32::max_value())), + FullInt::S(i128::from(i32::MIN)), + FullInt::S(i128::from(i32::MAX)), ), IntTy::I64 => ( - FullInt::S(i128::from(i64::min_value())), - FullInt::S(i128::from(i64::max_value())), + FullInt::S(i128::from(i64::MIN)), + FullInt::S(i128::from(i64::MAX)), ), - IntTy::I128 => (FullInt::S(i128::min_value()), FullInt::S(i128::max_value())), + IntTy::I128 => (FullInt::S(i128::MIN), FullInt::S(i128::MAX)), IntTy::Isize => ( - FullInt::S(isize::min_value() as i128), - FullInt::S(isize::max_value() as i128), + FullInt::S(isize::MIN as i128), + FullInt::S(isize::MAX as i128), ), }), ty::Uint(uint_ty) => Some(match uint_ty { UintTy::U8 => ( - FullInt::U(u128::from(u8::min_value())), - FullInt::U(u128::from(u8::max_value())), + FullInt::U(u128::from(u8::MIN)), + FullInt::U(u128::from(u8::MAX)), ), UintTy::U16 => ( - FullInt::U(u128::from(u16::min_value())), - FullInt::U(u128::from(u16::max_value())), + FullInt::U(u128::from(u16::MIN)), + FullInt::U(u128::from(u16::MAX)), ), UintTy::U32 => ( - FullInt::U(u128::from(u32::min_value())), - FullInt::U(u128::from(u32::max_value())), + FullInt::U(u128::from(u32::MIN)), + FullInt::U(u128::from(u32::MAX)), ), UintTy::U64 => ( - FullInt::U(u128::from(u64::min_value())), - FullInt::U(u128::from(u64::max_value())), + FullInt::U(u128::from(u64::MIN)), + FullInt::U(u128::from(u64::MAX)), ), - UintTy::U128 => (FullInt::U(u128::min_value()), FullInt::U(u128::max_value())), + UintTy::U128 => (FullInt::U(u128::MIN), FullInt::U(u128::MAX)), UintTy::Usize => ( - FullInt::U(usize::min_value() as u128), - FullInt::U(usize::max_value() as u128), + FullInt::U(usize::MIN as u128), + FullInt::U(usize::MAX as u128), ), }), _ => None, diff --git a/tests/ui/cast.rs b/tests/ui/cast.rs index 7e0b211d862c..8ee0969b0f07 100644 --- a/tests/ui/cast.rs +++ b/tests/ui/cast.rs @@ -37,11 +37,11 @@ fn main() { 1isize as usize; -1isize as usize; 0i8 as u8; - i8::max_value() as u8; - i16::max_value() as u16; - i32::max_value() as u32; - i64::max_value() as u64; - i128::max_value() as u128; + i8::MAX as u8; + i16::MAX as u16; + i32::MAX as u32; + i64::MAX as u64; + i128::MAX as u128; (-1i8).abs() as u8; (-1i16).abs() as u16; diff --git a/tests/ui/implicit_saturating_sub.rs b/tests/ui/implicit_saturating_sub.rs index 24cb216e79bf..2f32a7b15782 100644 --- a/tests/ui/implicit_saturating_sub.rs +++ b/tests/ui/implicit_saturating_sub.rs @@ -110,7 +110,7 @@ fn main() { } // Lint - if i_8 > i8::min_value() { + if i_8 > i8::MIN { i_8 -= 1; } @@ -120,7 +120,7 @@ fn main() { } // Lint - if i_8 != i8::min_value() { + if i_8 != i8::MIN { i_8 -= 1; } @@ -135,7 +135,7 @@ fn main() { } // Lint - if i_16 > i16::min_value() { + if i_16 > i16::MIN { i_16 -= 1; } @@ -145,7 +145,7 @@ fn main() { } // Lint - if i_16 != i16::min_value() { + if i_16 != i16::MIN { i_16 -= 1; } @@ -160,7 +160,7 @@ fn main() { } // Lint - if i_32 > i32::min_value() { + if i_32 > i32::MIN { i_32 -= 1; } @@ -170,7 +170,7 @@ fn main() { } // Lint - if i_32 != i32::min_value() { + if i_32 != i32::MIN { i_32 -= 1; } @@ -180,7 +180,7 @@ fn main() { let mut i_64: i64 = endi_64 - starti_64; // Lint - if i64::min_value() < i_64 { + if i64::MIN < i_64 { i_64 -= 1; } diff --git a/tests/ui/implicit_saturating_sub.stderr b/tests/ui/implicit_saturating_sub.stderr index a8ba870b1dda..2eb2023b3b9e 100644 --- a/tests/ui/implicit_saturating_sub.stderr +++ b/tests/ui/implicit_saturating_sub.stderr @@ -75,7 +75,7 @@ LL | | } error: Implicitly performing saturating subtraction --> $DIR/implicit_saturating_sub.rs:113:5 | -LL | / if i_8 > i8::min_value() { +LL | / if i_8 > i8::MIN { LL | | i_8 -= 1; LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` @@ -91,7 +91,7 @@ LL | | } error: Implicitly performing saturating subtraction --> $DIR/implicit_saturating_sub.rs:123:5 | -LL | / if i_8 != i8::min_value() { +LL | / if i_8 != i8::MIN { LL | | i_8 -= 1; LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` @@ -107,7 +107,7 @@ LL | | } error: Implicitly performing saturating subtraction --> $DIR/implicit_saturating_sub.rs:138:5 | -LL | / if i_16 > i16::min_value() { +LL | / if i_16 > i16::MIN { LL | | i_16 -= 1; LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` @@ -123,7 +123,7 @@ LL | | } error: Implicitly performing saturating subtraction --> $DIR/implicit_saturating_sub.rs:148:5 | -LL | / if i_16 != i16::min_value() { +LL | / if i_16 != i16::MIN { LL | | i_16 -= 1; LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` @@ -139,7 +139,7 @@ LL | | } error: Implicitly performing saturating subtraction --> $DIR/implicit_saturating_sub.rs:163:5 | -LL | / if i_32 > i32::min_value() { +LL | / if i_32 > i32::MIN { LL | | i_32 -= 1; LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` @@ -155,7 +155,7 @@ LL | | } error: Implicitly performing saturating subtraction --> $DIR/implicit_saturating_sub.rs:173:5 | -LL | / if i_32 != i32::min_value() { +LL | / if i_32 != i32::MIN { LL | | i_32 -= 1; LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` @@ -163,7 +163,7 @@ LL | | } error: Implicitly performing saturating subtraction --> $DIR/implicit_saturating_sub.rs:183:5 | -LL | / if i64::min_value() < i_64 { +LL | / if i64::MIN < i_64 { LL | | i_64 -= 1; LL | | } | |_____^ help: try: `i_64 = i_64.saturating_sub(1);` From 4ec25202a1045af84078b062f68acc151a42e3ec Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 9 Jun 2020 17:44:04 -0400 Subject: [PATCH 0019/1222] Update Clippy for MethodCall changes --- clippy_lints/src/atomic_ordering.rs | 2 +- clippy_lints/src/booleans.rs | 2 +- clippy_lints/src/bytecount.rs | 6 ++--- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/double_parens.rs | 2 +- clippy_lints/src/duration_subsec.rs | 2 +- clippy_lints/src/entry.rs | 4 ++-- clippy_lints/src/eta_reduction.rs | 4 ++-- clippy_lints/src/explicit_write.rs | 4 ++-- clippy_lints/src/floating_point_arithmetic.rs | 4 ++-- clippy_lints/src/format.rs | 2 +- clippy_lints/src/functions.rs | 4 ++-- clippy_lints/src/get_last_with_len.rs | 4 ++-- clippy_lints/src/if_let_mutex.rs | 2 +- clippy_lints/src/if_let_some_result.rs | 2 +- clippy_lints/src/infinite_iter.rs | 4 ++-- clippy_lints/src/len_zero.rs | 2 +- clippy_lints/src/loops.rs | 22 +++++++++---------- clippy_lints/src/map_clone.rs | 4 ++-- clippy_lints/src/map_unit_fn.rs | 2 +- clippy_lints/src/methods/mod.rs | 16 +++++++------- clippy_lints/src/misc.rs | 4 ++-- clippy_lints/src/mut_reference.rs | 2 +- clippy_lints/src/open_options.rs | 4 ++-- clippy_lints/src/option_env_unwrap.rs | 2 +- clippy_lints/src/path_buf_push_overwrite.rs | 2 +- clippy_lints/src/precedence.rs | 2 +- clippy_lints/src/ptr_offset_with_cast.rs | 2 +- clippy_lints/src/question_mark.rs | 2 +- clippy_lints/src/ranges.rs | 6 ++--- .../src/redundant_pattern_matching.rs | 2 +- .../src/slow_vector_initialization.rs | 6 ++--- clippy_lints/src/strings.rs | 2 +- clippy_lints/src/to_digit_is_some.rs | 4 ++-- clippy_lints/src/types.rs | 6 ++--- clippy_lints/src/unused_io_amount.rs | 4 ++-- clippy_lints/src/unwrap.rs | 4 ++-- clippy_lints/src/useless_conversion.rs | 2 +- clippy_lints/src/utils/author.rs | 4 ++-- clippy_lints/src/utils/hir_utils.rs | 4 ++-- clippy_lints/src/utils/inspector.rs | 2 +- clippy_lints/src/utils/internal_lints.rs | 4 ++-- clippy_lints/src/utils/mod.rs | 6 ++--- clippy_lints/src/utils/ptr.rs | 2 +- clippy_lints/src/verbose_file_reads.rs | 4 ++-- 45 files changed, 89 insertions(+), 89 deletions(-) diff --git a/clippy_lints/src/atomic_ordering.rs b/clippy_lints/src/atomic_ordering.rs index 73b4cef47250..fca9aaaff9dc 100644 --- a/clippy_lints/src/atomic_ordering.rs +++ b/clippy_lints/src/atomic_ordering.rs @@ -70,7 +70,7 @@ fn match_ordering_def_path(cx: &LateContext<'_, '_>, did: DefId, orderings: &[&s fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { - if let ExprKind::MethodCall(ref method_path, _, args) = &expr.kind; + if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind; let method = method_path.ident.name.as_str(); if type_is_atomic(cx, &args[0]); if method == "load" || method == "store"; diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 8031052e073d..f92c564543b8 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -247,7 +247,7 @@ fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option { )) }) }, - ExprKind::MethodCall(path, _, args) if args.len() == 1 => { + ExprKind::MethodCall(path, _, args, _) if args.len() == 1 => { let type_of_receiver = cx.tables.expr_ty(&args[0]); if !is_type_diagnostic_item(cx, type_of_receiver, sym!(option_type)) && !is_type_diagnostic_item(cx, type_of_receiver, sym!(result_type)) diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index 90c00ad098ff..531531a654d0 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -38,10 +38,10 @@ declare_lint_pass!(ByteCount => [NAIVE_BYTECOUNT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount { fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { - if let ExprKind::MethodCall(ref count, _, ref count_args) = expr.kind; + if let ExprKind::MethodCall(ref count, _, ref count_args, _) = expr.kind; if count.ident.name == sym!(count); if count_args.len() == 1; - if let ExprKind::MethodCall(ref filter, _, ref filter_args) = count_args[0].kind; + if let ExprKind::MethodCall(ref filter, _, ref filter_args, _) = count_args[0].kind; if filter.ident.name == sym!(filter); if filter_args.len() == 2; if let ExprKind::Closure(_, _, body_id, _, _) = filter_args[1].kind; @@ -66,7 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount { if ty::Uint(UintTy::U8) != walk_ptrs_ty(cx.tables.expr_ty(needle)).kind { return; } - let haystack = if let ExprKind::MethodCall(ref path, _, ref args) = + let haystack = if let ExprKind::MethodCall(ref path, _, ref args, _) = filter_args[0].kind { let p = path.ident.name; if (p == sym!(iter) || p == sym!(iter_mut)) && args.len() == 1 { diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 68ec07e2bcb0..1cd30ae2c638 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -42,7 +42,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Dereferencing { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if !expr.span.from_expansion(); - if let ExprKind::MethodCall(ref method_name, _, ref args) = &expr.kind; + if let ExprKind::MethodCall(ref method_name, _, ref args, _) = &expr.kind; if args.len() == 1; then { diff --git a/clippy_lints/src/double_parens.rs b/clippy_lints/src/double_parens.rs index 05517f6f9f0c..1eb380a22cc6 100644 --- a/clippy_lints/src/double_parens.rs +++ b/clippy_lints/src/double_parens.rs @@ -70,7 +70,7 @@ impl EarlyLintPass for DoubleParens { } } }, - ExprKind::MethodCall(_, ref params) => { + ExprKind::MethodCall(_, ref params, _) => { if params.len() == 2 { let param = ¶ms[1]; if let ExprKind::Paren(_) = param.kind { diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index afefa2506381..7171dcef968c 100644 --- a/clippy_lints/src/duration_subsec.rs +++ b/clippy_lints/src/duration_subsec.rs @@ -42,7 +42,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, ref left, ref right) = expr.kind; - if let ExprKind::MethodCall(ref method_path, _ , ref args) = left.kind; + if let ExprKind::MethodCall(ref method_path, _ , ref args, _) = left.kind; if match_type(cx, walk_ptrs_ty(cx.tables.expr_ty(&args[0])), &paths::DURATION); if let Some((Constant::Int(divisor), _)) = constant(cx, cx.tables, right); then { diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 7b332c761a0c..f625058b6703 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -103,7 +103,7 @@ fn check_cond<'a, 'tcx, 'b>( check: &'b Expr<'b>, ) -> Option<(&'static str, &'b Expr<'b>, &'b Expr<'b>)> { if_chain! { - if let ExprKind::MethodCall(ref path, _, ref params) = check.kind; + if let ExprKind::MethodCall(ref path, _, ref params, _) = check.kind; if params.len() >= 2; if path.ident.name == sym!(contains_key); if let ExprKind::AddrOf(BorrowKind::Ref, _, ref key) = params[1].kind; @@ -140,7 +140,7 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> { fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if_chain! { - if let ExprKind::MethodCall(ref path, _, ref params) = expr.kind; + if let ExprKind::MethodCall(ref path, _, ref params, _) = expr.kind; if params.len() == 3; if path.ident.name == sym!(insert); if get_item_name(self.cx, self.map) == get_item_name(self.cx, ¶ms[0]); diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index d093025fd3d7..a889856de274 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -71,7 +71,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaReduction { } match expr.kind { - ExprKind::Call(_, args) | ExprKind::MethodCall(_, _, args) => { + ExprKind::Call(_, args) | ExprKind::MethodCall(_, _, args, _) => { for arg in args { check_closure(cx, arg) } @@ -120,7 +120,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { ); if_chain!( - if let ExprKind::MethodCall(ref path, _, ref args) = ex.kind; + if let ExprKind::MethodCall(ref path, _, ref args, _) = ex.kind; // Not the same number of arguments, there is no way the closure is the same as the function return; if args.len() == decl.inputs.len(); diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 320121b27714..7269e2b52c2c 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -32,11 +32,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitWrite { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { // match call to unwrap - if let ExprKind::MethodCall(ref unwrap_fun, _, ref unwrap_args) = expr.kind; + if let ExprKind::MethodCall(ref unwrap_fun, _, ref unwrap_args, _) = expr.kind; if unwrap_fun.ident.name == sym!(unwrap); // match call to write_fmt if !unwrap_args.is_empty(); - if let ExprKind::MethodCall(ref write_fun, _, write_args) = + if let ExprKind::MethodCall(ref write_fun, _, write_args, _) = unwrap_args[0].kind; if write_fun.ident.name == sym!(write_fmt); // match calls to std::io::stdout() / std::io::stderr () diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index 3a912d928375..ad4f66c52c2c 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -301,7 +301,7 @@ fn check_expm1(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if cx.tables.expr_ty(lhs).is_floating_point(); if let Some((value, _)) = constant(cx, cx.tables, rhs); if F32(1.0) == value || F64(1.0) == value; - if let ExprKind::MethodCall(ref path, _, ref method_args) = lhs.kind; + if let ExprKind::MethodCall(ref path, _, ref method_args, _) = lhs.kind; if cx.tables.expr_ty(&method_args[0]).is_floating_point(); if path.ident.name.as_str() == "exp"; then { @@ -481,7 +481,7 @@ fn check_custom_abs(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FloatingPointArithmetic { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::MethodCall(ref path, _, args) = &expr.kind { + if let ExprKind::MethodCall(ref path, _, args, _) = &expr.kind { let recv_ty = cx.tables.expr_ty(&args[0]); if recv_ty.is_floating_point() { diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 1530538aa7d1..4cae5ca2c432 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -104,7 +104,7 @@ fn on_argumentv1_new<'a, 'tcx>( } } else { let snip = snippet(cx, format_args.span, ""); - if let ExprKind::MethodCall(ref path, _, _) = format_args.kind { + if let ExprKind::MethodCall(ref path, _, _, _) = format_args.kind { if path.ident.name == sym!(to_string) { return Some(format!("{}", snip)); } diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 325b6cf32a3d..991d129e8f0d 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -556,7 +556,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { } } }, - hir::ExprKind::MethodCall(_, _, args) => { + hir::ExprKind::MethodCall(_, _, args, _) => { let def_id = self.tables.type_dependent_def_id(expr.hir_id).unwrap(); let base_type = self.cx.tcx.type_of(def_id); @@ -610,7 +610,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { return; } match expr.kind { - Call(_, args) | MethodCall(_, _, args) => { + Call(_, args) | MethodCall(_, _, args, _) => { let mut tys = FxHashSet::default(); for arg in args { let def_id = arg.hir_id.owner.to_def_id(); diff --git a/clippy_lints/src/get_last_with_len.rs b/clippy_lints/src/get_last_with_len.rs index c32e0a2290d1..3629ba623ce4 100644 --- a/clippy_lints/src/get_last_with_len.rs +++ b/clippy_lints/src/get_last_with_len.rs @@ -47,7 +47,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for GetLastWithLen { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { // Is a method call - if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind; + if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; // Method name is "get" if path.ident.name == sym!(get); @@ -69,7 +69,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for GetLastWithLen { ) = &get_index_arg.kind; // LHS of subtraction is "x.len()" - if let ExprKind::MethodCall(arg_lhs_path, _, lhs_args) = &lhs.kind; + if let ExprKind::MethodCall(arg_lhs_path, _, lhs_args, _) = &lhs.kind; if arg_lhs_path.ident.name == sym!(len); if let Some(arg_lhs_struct) = lhs_args.get(0); diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index ae92a96d1634..04d17c91d63c 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -147,7 +147,7 @@ impl<'tcx, 'l> ArmVisitor<'tcx, 'l> { fn is_mutex_lock_call<'a>(cx: &LateContext<'a, '_>, expr: &'a Expr<'_>) -> Option<&'a Expr<'a>> { if_chain! { - if let ExprKind::MethodCall(path, _span, args) = &expr.kind; + if let ExprKind::MethodCall(path, _span, args, _) = &expr.kind; if path.ident.to_string() == "lock"; let ty = cx.tables.expr_ty(&args[0]); if is_type_diagnostic_item(cx, ty, sym!(mutex_type)); diff --git a/clippy_lints/src/if_let_some_result.rs b/clippy_lints/src/if_let_some_result.rs index 9b13f7609247..6a1fcdd1ce44 100644 --- a/clippy_lints/src/if_let_some_result.rs +++ b/clippy_lints/src/if_let_some_result.rs @@ -42,7 +42,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OkIfLet { if_chain! { //begin checking variables if let ExprKind::Match(ref op, ref body, source) = expr.kind; //test if expr is a match if let MatchSource::IfLetDesugar { .. } = source; //test if it is an If Let - if let ExprKind::MethodCall(_, ok_span, ref result_types) = op.kind; //check is expr.ok() has type Result.ok() + if let ExprKind::MethodCall(_, ok_span, ref result_types, _) = op.kind; //check is expr.ok() has type Result.ok(, _) if let PatKind::TupleStruct(QPath::Resolved(_, ref x), ref y, _) = body[0].pat.kind; //get operation if method_chain_args(op, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized; if is_type_diagnostic_item(cx, cx.tables.expr_ty(&result_types[0]), sym!(result_type)); diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index cd989c0ea6f6..a860a9def242 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -142,7 +142,7 @@ const HEURISTICS: [(&str, usize, Heuristic, Finiteness); 19] = [ fn is_infinite(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Finiteness { match expr.kind { - ExprKind::MethodCall(ref method, _, ref args) => { + ExprKind::MethodCall(ref method, _, ref args, _) => { for &(name, len, heuristic, cap) in &HEURISTICS { if method.ident.name.as_str() == name && args.len() == len { return (match heuristic { @@ -218,7 +218,7 @@ const INFINITE_COLLECTORS: [&[&str]; 8] = [ fn complete_infinite_iter(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Finiteness { match expr.kind { - ExprKind::MethodCall(ref method, _, ref args) => { + ExprKind::MethodCall(ref method, _, ref args, _) => { for &(name, len) in &COMPLETING_METHODS { if method.ident.name.as_str() == name && args.len() == len { return is_infinite(cx, &args[0]); diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index f5bfede75a76..13e85fda8ffe 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -211,7 +211,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item<'_>, impl_items: &[Imp } fn check_cmp(cx: &LateContext<'_, '_>, span: Span, method: &Expr<'_>, lit: &Expr<'_>, op: &str, compare_to: u32) { - if let (&ExprKind::MethodCall(ref method_path, _, ref args), &ExprKind::Lit(ref lit)) = (&method.kind, &lit.kind) { + if let (&ExprKind::MethodCall(ref method_path, _, ref args, _), &ExprKind::Lit(ref lit)) = (&method.kind, &lit.kind) { // check if we are in an is_empty() method if let Some(name) = get_item_name(cx, method) { if name.as_str() == "is_empty" { diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 57c62d739640..771bc8d05582 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -526,7 +526,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops { let pat = &arms[0].pat.kind; if let ( &PatKind::TupleStruct(ref qpath, ref pat_args, _), - &ExprKind::MethodCall(ref method_path, _, ref method_args), + &ExprKind::MethodCall(ref method_path, _, ref method_args, _), ) = (pat, &match_expr.kind) { let iter_expr = &method_args[0]; @@ -654,7 +654,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { | ExprKind::Struct(_, _, Some(ref e)) | ExprKind::Repeat(ref e, _) | ExprKind::DropTemps(ref e) => never_loop_expr(e, main_loop_id), - ExprKind::Array(ref es) | ExprKind::MethodCall(_, _, ref es) | ExprKind::Tup(ref es) => { + ExprKind::Array(ref es) | ExprKind::MethodCall(_, _, ref es, _) | ExprKind::Tup(ref es) => { never_loop_expr_all(&mut es.iter(), main_loop_id) }, ExprKind::Call(ref e, ref es) => never_loop_expr_all(&mut once(&**e).chain(es.iter()), main_loop_id), @@ -806,7 +806,7 @@ fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'_>) -> bool { fn fetch_cloned_expr<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { if_chain! { - if let ExprKind::MethodCall(method, _, args) = expr.kind; + if let ExprKind::MethodCall(method, _, args, _) = expr.kind; if method.ident.name == sym!(clone); if args.len() == 1; if let Some(arg) = args.get(0); @@ -915,7 +915,7 @@ fn build_manual_memcpy_suggestion<'a, 'tcx>( let print_limit = |end: &Expr<'_>, offset: Offset, var: &Expr<'_>| { if_chain! { - if let ExprKind::MethodCall(method, _, len_args) = end.kind; + if let ExprKind::MethodCall(method, _, len_args, _) = end.kind; if method.ident.name == sym!(len); if len_args.len() == 1; if let Some(arg) = len_args.get(0); @@ -1190,7 +1190,7 @@ fn check_for_loop_range<'a, 'tcx>( fn is_len_call(expr: &Expr<'_>, var: Name) -> bool { if_chain! { - if let ExprKind::MethodCall(ref method, _, ref len_args) = expr.kind; + if let ExprKind::MethodCall(ref method, _, ref len_args, _) = expr.kind; if len_args.len() == 1; if method.ident.name == sym!(len); if let ExprKind::Path(QPath::Resolved(_, ref path)) = len_args[0].kind; @@ -1244,7 +1244,7 @@ fn lint_iter_method(cx: &LateContext<'_, '_>, args: &[Expr<'_>], arg: &Expr<'_>, fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>, expr: &Expr<'_>) { let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used - if let ExprKind::MethodCall(ref method, _, ref args) = arg.kind { + if let ExprKind::MethodCall(ref method, _, ref args, _) = arg.kind { // just the receiver, no arguments if args.len() == 1 { let method_name = &*method.ident.as_str(); @@ -1718,7 +1718,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if_chain! { // a range index op - if let ExprKind::MethodCall(ref meth, _, ref args) = expr.kind; + if let ExprKind::MethodCall(ref meth, _, ref args, _) = expr.kind; if (meth.ident.name == sym!(index) && match_trait_method(self.cx, expr, &paths::INDEX)) || (meth.ident.name == sym!(index_mut) && match_trait_method(self.cx, expr, &paths::INDEX_MUT)); if !self.check(&args[1], &args[0], expr); @@ -1776,7 +1776,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { self.visit_expr(expr); } }, - ExprKind::MethodCall(_, _, args) => { + ExprKind::MethodCall(_, _, args, _) => { let def_id = self.cx.tables.type_dependent_def_id(expr.hir_id).unwrap(); for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) { self.prefer_mutable = false; @@ -2369,8 +2369,8 @@ const NEEDLESS_COLLECT_MSG: &str = "avoid using `collect()` when not needed"; fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'a, 'tcx>) { if_chain! { - if let ExprKind::MethodCall(ref method, _, ref args) = expr.kind; - if let ExprKind::MethodCall(ref chain_method, _, _) = args[0].kind; + if let ExprKind::MethodCall(ref method, _, ref args, _) = expr.kind; + if let ExprKind::MethodCall(ref chain_method, _, _, _) = args[0].kind; if chain_method.ident.name == sym!(collect) && match_trait_method(cx, &args[0], &paths::ITERATOR); if let Some(ref generic_args) = chain_method.args; if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0); @@ -2437,7 +2437,7 @@ fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'a, ' fn shorten_span(expr: &Expr<'_>, target_fn_name: Symbol) -> Span { let mut current_expr = expr; - while let ExprKind::MethodCall(ref path, ref span, ref args) = current_expr.kind { + while let ExprKind::MethodCall(ref path, ref span, ref args, _) = current_expr.kind { if path.ident.name == target_fn_name { return expr.span.with_lo(span.lo()); } diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index d5adf6b0f0dc..8f4fdc685ef3 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -49,7 +49,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone { } if_chain! { - if let hir::ExprKind::MethodCall(ref method, _, ref args) = e.kind; + if let hir::ExprKind::MethodCall(ref method, _, ref args, _) = e.kind; if args.len() == 2; if method.ident.as_str() == "map"; let ty = cx.tables.expr_ty(&args[0]); @@ -75,7 +75,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone { } } }, - hir::ExprKind::MethodCall(ref method, _, ref obj) => { + hir::ExprKind::MethodCall(ref method, _, ref obj, _) => { if ident_eq(name, &obj[0]) && method.ident.as_str() == "clone" && match_trait_method(cx, closure_expr, &paths::CLONE_TRAIT) { diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index fecd91c7814d..8f4b674c04f4 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -125,7 +125,7 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr<'_>) } match expr.kind { - hir::ExprKind::Call(_, _) | hir::ExprKind::MethodCall(_, _, _) => { + hir::ExprKind::Call(_, _) | hir::ExprKind::MethodCall(_, _, _, _) => { // Calls can't be reduced any more Some(expr.span) }, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 214cf0c130f2..f25a9782813b 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1429,7 +1429,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { } match expr.kind { - hir::ExprKind::MethodCall(ref method_call, ref method_span, ref args) => { + hir::ExprKind::MethodCall(ref method_call, ref method_span, ref args, _) => { lint_or_fun_call(cx, expr, *method_span, &method_call.ident.as_str(), args); lint_expect_fun_call(cx, expr, *method_span, &method_call.ident.as_str(), args); @@ -1677,7 +1677,7 @@ fn lint_or_fun_call<'a, 'tcx>( or_has_args: bool, span: Span, ) { - if let hir::ExprKind::MethodCall(ref path, _, ref args) = &arg.kind { + if let hir::ExprKind::MethodCall(ref path, _, ref args, _) = &arg.kind { if path.ident.as_str() == "len" { let ty = walk_ptrs_ty(cx.tables.expr_ty(&args[0])); @@ -1751,7 +1751,7 @@ fn lint_or_fun_call<'a, 'tcx>( ); } }, - hir::ExprKind::MethodCall(_, span, ref or_args) => check_general_case( + hir::ExprKind::MethodCall(_, span, ref or_args, _) => check_general_case( cx, name, method_span, @@ -1782,7 +1782,7 @@ fn lint_expect_fun_call( loop { arg_root = match &arg_root.kind { hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, expr) => expr, - hir::ExprKind::MethodCall(method_name, _, call_args) => { + hir::ExprKind::MethodCall(method_name, _, call_args, _) => { if call_args.len() == 1 && (method_name.ident.name == sym!(as_str) || method_name.ident.name == sym!(as_ref)) && { @@ -2002,7 +2002,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &hir: // &*x is a nop, &x.clone() is not hir::ExprKind::AddrOf(..) => return, // (*x).func() is useless, x.clone().func() can work in case func borrows mutably - hir::ExprKind::MethodCall(_, _, parent_args) if expr.hir_id == parent_args[0].hir_id => return, + hir::ExprKind::MethodCall(_, _, parent_args, _) if expr.hir_id == parent_args[0].hir_id => return, _ => {}, }, @@ -2478,7 +2478,7 @@ fn derefs_to_slice<'a, 'tcx>( } } - if let hir::ExprKind::MethodCall(ref path, _, ref args) = expr.kind { + if let hir::ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind { if path.ident.name == sym!(iter) && may_slice(cx, cx.tables.expr_ty(&args[0])) { Some(&args[0]) } else { @@ -3182,7 +3182,7 @@ fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, call_name: &str, a // allow the `as_ref` or `as_mut` if it is followed by another method call if_chain! { if let Some(parent) = get_parent_expr(cx, expr); - if let hir::ExprKind::MethodCall(_, ref span, _) = parent.kind; + if let hir::ExprKind::MethodCall(_, ref span, _, _) = parent.kind; if span != &expr.span; then { return; @@ -3310,7 +3310,7 @@ fn lint_option_as_ref_deref<'a, 'tcx>( let closure_expr = remove_blocks(&closure_body.value); match &closure_expr.kind { - hir::ExprKind::MethodCall(_, _, args) => { + hir::ExprKind::MethodCall(_, _, args, _) => { if_chain! { if args.len() == 1; if let hir::ExprKind::Path(qpath) = &args[0].kind; diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index f513161bbbc5..a0947608e607 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -545,7 +545,7 @@ fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { } if_chain! { - if let ExprKind::MethodCall(ref method_name, _, ref expressions) = expr.kind; + if let ExprKind::MethodCall(ref method_name, _, ref expressions, _) = expr.kind; if sym!(signum) == method_name.ident.name; // Check that the receiver of the signum() is a float (expressions[0] is the receiver of // the method call) @@ -572,7 +572,7 @@ fn is_array(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr<'_>, other: &Expr<'_>) { let (arg_ty, snip) = match expr.kind { - ExprKind::MethodCall(.., ref args) if args.len() == 1 => { + ExprKind::MethodCall(.., ref args, _) if args.len() == 1 => { if match_trait_method(cx, expr, &paths::TO_STRING) || match_trait_method(cx, expr, &paths::TO_OWNED) { (cx.tables.expr_ty_adjusted(&args[0]), snippet(cx, args[0].span, "..")) } else { diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 58a8e1a1064a..7fcf15f8acbe 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -42,7 +42,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed { ); } }, - ExprKind::MethodCall(ref path, _, ref arguments) => { + ExprKind::MethodCall(ref path, _, ref arguments, _) => { let def_id = cx.tables.type_dependent_def_id(e.hir_id).unwrap(); let substs = cx.tables.node_substs(e.hir_id); let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs); diff --git a/clippy_lints/src/open_options.rs b/clippy_lints/src/open_options.rs index 9d3b67988dbb..2d4629b683f0 100644 --- a/clippy_lints/src/open_options.rs +++ b/clippy_lints/src/open_options.rs @@ -29,7 +29,7 @@ declare_lint_pass!(OpenOptions => [NONSENSICAL_OPEN_OPTIONS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OpenOptions { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { - if let ExprKind::MethodCall(ref path, _, ref arguments) = e.kind { + if let ExprKind::MethodCall(ref path, _, ref arguments, _) = e.kind { let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0])); if path.ident.name == sym!(open) && match_type(cx, obj_ty, &paths::OPEN_OPTIONS) { let mut options = Vec::new(); @@ -57,7 +57,7 @@ enum OpenOption { } fn get_open_options(cx: &LateContext<'_, '_>, argument: &Expr<'_>, options: &mut Vec<(OpenOption, Argument)>) { - if let ExprKind::MethodCall(ref path, _, ref arguments) = argument.kind { + if let ExprKind::MethodCall(ref path, _, ref arguments, _) = argument.kind { let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0])); // Only proceed if this is a call on some object of type std::fs::OpenOptions diff --git a/clippy_lints/src/option_env_unwrap.rs b/clippy_lints/src/option_env_unwrap.rs index 66dfa20edb5e..fd653044a1bc 100644 --- a/clippy_lints/src/option_env_unwrap.rs +++ b/clippy_lints/src/option_env_unwrap.rs @@ -35,7 +35,7 @@ declare_lint_pass!(OptionEnvUnwrap => [OPTION_ENV_UNWRAP]); impl EarlyLintPass for OptionEnvUnwrap { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { if_chain! { - if let ExprKind::MethodCall(path_segment, args) = &expr.kind; + if let ExprKind::MethodCall(path_segment, args, _) = &expr.kind; let method_name = path_segment.ident.as_str(); if method_name == "expect" || method_name == "unwrap"; if let ExprKind::Call(caller, _) = &args[0].kind; diff --git a/clippy_lints/src/path_buf_push_overwrite.rs b/clippy_lints/src/path_buf_push_overwrite.rs index bdbaf2695c8e..88ad1e0914f2 100644 --- a/clippy_lints/src/path_buf_push_overwrite.rs +++ b/clippy_lints/src/path_buf_push_overwrite.rs @@ -43,7 +43,7 @@ declare_lint_pass!(PathBufPushOverwrite => [PATH_BUF_PUSH_OVERWRITE]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathBufPushOverwrite { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { - if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind; + if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; if path.ident.name == sym!(push); if args.len() == 2; if match_type(cx, walk_ptrs_ty(cx.tables.expr_ty(&args[0])), &paths::PATH_BUF); diff --git a/clippy_lints/src/precedence.rs b/clippy_lints/src/precedence.rs index cc783baa6872..7dce23dd2230 100644 --- a/clippy_lints/src/precedence.rs +++ b/clippy_lints/src/precedence.rs @@ -103,7 +103,7 @@ impl EarlyLintPass for Precedence { } if let ExprKind::Unary(UnOp::Neg, ref rhs) = expr.kind { - if let ExprKind::MethodCall(ref path_segment, ref args) = rhs.kind { + if let ExprKind::MethodCall(ref path_segment, ref args, _) = rhs.kind { let path_segment_str = path_segment.ident.name.as_str(); if let Some(slf) = args.first() { if let ExprKind::Lit(ref lit) = slf.kind { diff --git a/clippy_lints/src/ptr_offset_with_cast.rs b/clippy_lints/src/ptr_offset_with_cast.rs index ffc59d43750e..d23d7e59b73f 100644 --- a/clippy_lints/src/ptr_offset_with_cast.rs +++ b/clippy_lints/src/ptr_offset_with_cast.rs @@ -90,7 +90,7 @@ fn expr_as_ptr_offset_call<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, ) -> Option<(&'tcx Expr<'tcx>, &'tcx Expr<'tcx>, Method)> { - if let ExprKind::MethodCall(ref path_segment, _, ref args) = expr.kind { + if let ExprKind::MethodCall(ref path_segment, _, ref args, _) = expr.kind { if is_expr_ty_raw_ptr(cx, &args[0]) { if path_segment.ident.name == sym!(offset) { return Some((&args[0], &args[1], Method::Offset)); diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index e4361b00fb4c..3591972fe082 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -50,7 +50,7 @@ impl QuestionMark { fn check_is_none_and_early_return_none(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { if let Some((if_expr, body, else_)) = higher::if_block(&expr); - if let ExprKind::MethodCall(segment, _, args) = &if_expr.kind; + if let ExprKind::MethodCall(segment, _, args, _) = &if_expr.kind; if segment.ident.name == sym!(is_none); if Self::expression_returns_none(cx, body); if let Some(subject) = args.get(0); diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 52e540d4e00d..fcd02a196e7b 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -129,20 +129,20 @@ declare_lint_pass!(Ranges => [ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind { + if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind { let name = path.ident.as_str(); if name == "zip" && args.len() == 2 { let iter = &args[0].kind; let zip_arg = &args[1]; if_chain! { // `.iter()` call - if let ExprKind::MethodCall(ref iter_path, _, ref iter_args ) = *iter; + if let ExprKind::MethodCall(ref iter_path, _, ref iter_args , _) = *iter; if iter_path.ident.name == sym!(iter); // range expression in `.zip()` call: `0..x.len()` if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::range(cx, zip_arg); if is_integer_const(cx, start, 0); // `.len()` call - if let ExprKind::MethodCall(ref len_path, _, ref len_args) = end.kind; + if let ExprKind::MethodCall(ref len_path, _, ref len_args, _) = end.kind; if len_path.ident.name == sym!(len) && len_args.len() == 1; // `.iter()` and `.len()` called on same `Path` if let ExprKind::Path(QPath::Resolved(_, ref iter_path)) = iter_args[0].kind; diff --git a/clippy_lints/src/redundant_pattern_matching.rs b/clippy_lints/src/redundant_pattern_matching.rs index 7ee298e9833f..f16b916441ae 100644 --- a/clippy_lints/src/redundant_pattern_matching.rs +++ b/clippy_lints/src/redundant_pattern_matching.rs @@ -89,7 +89,7 @@ fn find_sugg_for_if_let<'a, 'tcx>( // check that `while_let_on_iterator` lint does not trigger if_chain! { if keyword == "while"; - if let ExprKind::MethodCall(method_path, _, _) = op.kind; + if let ExprKind::MethodCall(method_path, _, _, _) = op.kind; if method_path.ident.name == sym!(next); if match_trait_method(cx, op, &paths::ITERATOR); then { diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index a7c4f2c2291f..44c9cc19cfb4 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -207,7 +207,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { fn search_slow_extend_filling(&mut self, expr: &'tcx Expr<'_>) { if_chain! { if self.initialization_found; - if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind; + if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; if let ExprKind::Path(ref qpath_subj) = args[0].kind; if match_qpath(&qpath_subj, &[&*self.vec_alloc.variable_name.as_str()]); if path.ident.name == sym!(extend); @@ -224,7 +224,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { fn search_slow_resize_filling(&mut self, expr: &'tcx Expr<'_>) { if_chain! { if self.initialization_found; - if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind; + if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; if let ExprKind::Path(ref qpath_subj) = args[0].kind; if match_qpath(&qpath_subj, &[&*self.vec_alloc.variable_name.as_str()]); if path.ident.name == sym!(resize); @@ -246,7 +246,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { /// Returns `true` if give expression is `repeat(0).take(...)` fn is_repeat_take(&self, expr: &Expr<'_>) -> bool { if_chain! { - if let ExprKind::MethodCall(ref take_path, _, ref take_args) = expr.kind; + if let ExprKind::MethodCall(ref take_path, _, ref take_args, _) = expr.kind; if take_path.ident.name == sym!(take); // Check that take is applied to `repeat(0)` diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index f84566ef707a..d8e4bff3d702 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -164,7 +164,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes { use rustc_ast::ast::LitKind; if_chain! { - if let ExprKind::MethodCall(path, _, args) = &e.kind; + if let ExprKind::MethodCall(path, _, args, _) = &e.kind; if path.ident.name == sym!(as_bytes); if let ExprKind::Lit(lit) = &args[0].kind; if let LitKind::Str(lit_content, _) = &lit.node; diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs index c6302ca03d91..4f132c6db76f 100644 --- a/clippy_lints/src/to_digit_is_some.rs +++ b/clippy_lints/src/to_digit_is_some.rs @@ -34,12 +34,12 @@ declare_lint_pass!(ToDigitIsSome => [TO_DIGIT_IS_SOME]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ToDigitIsSome { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { if_chain! { - if let hir::ExprKind::MethodCall(is_some_path, _, is_some_args) = &expr.kind; + if let hir::ExprKind::MethodCall(is_some_path, _, is_some_args, _) = &expr.kind; if is_some_path.ident.name.as_str() == "is_some"; if let [to_digit_expr] = &**is_some_args; then { let match_result = match &to_digit_expr.kind { - hir::ExprKind::MethodCall(to_digits_path, _, to_digit_args) => { + hir::ExprKind::MethodCall(to_digits_path, _, to_digit_args, _) => { if_chain! { if let [char_arg, radix_arg] = &**to_digit_args; if to_digits_path.ident.name.as_str() == "to_digit"; diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index bc5fe44b30f8..57d5b27df574 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -778,7 +778,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg { } match expr.kind { - ExprKind::Call(_, args) | ExprKind::MethodCall(_, _, args) => { + ExprKind::Call(_, args) | ExprKind::MethodCall(_, _, args, _) => { let args_to_recover = args .iter() .filter(|arg| { @@ -1262,14 +1262,14 @@ fn check_loss_of_sign(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>, } // don't lint for the result of methods that always return non-negative values - if let ExprKind::MethodCall(ref path, _, _) = op.kind { + if let ExprKind::MethodCall(ref path, _, _, _) = op.kind { let mut method_name = path.ident.name.as_str(); let whitelisted_methods = ["abs", "checked_abs", "rem_euclid", "checked_rem_euclid"]; if_chain! { if method_name == "unwrap"; if let Some(arglist) = method_chain_args(op, &["unwrap"]); - if let ExprKind::MethodCall(ref inner_path, _, _) = &arglist[0][0].kind; + if let ExprKind::MethodCall(ref inner_path, _, _, _) = &arglist[0][0].kind; then { method_name = inner_path.ident.name.as_str(); } diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index b85134e3d7a9..5f4b5fd9dd91 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -52,7 +52,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedIoAmount { } }, - hir::ExprKind::MethodCall(ref path, _, ref args) => match &*path.ident.as_str() { + hir::ExprKind::MethodCall(ref path, _, ref args, _) => match &*path.ident.as_str() { "expect" | "unwrap" | "unwrap_or" | "unwrap_or_else" => { check_method_call(cx, &args[0], expr); }, @@ -65,7 +65,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedIoAmount { } fn check_method_call(cx: &LateContext<'_, '_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) { - if let hir::ExprKind::MethodCall(ref path, _, _) = call.kind { + if let hir::ExprKind::MethodCall(ref path, _, _, _) = call.kind { let symbol = &*path.ident.as_str(); let read_trait = match_trait_method(cx, call, &paths::IO_READ); let write_trait = match_trait_method(cx, call, &paths::IO_WRITE); diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 036dd16a224a..a6c7b5d405cd 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -112,7 +112,7 @@ fn collect_unwrap_info<'a, 'tcx>( return collect_unwrap_info(cx, expr, branch, !invert); } else { if_chain! { - if let ExprKind::MethodCall(method_name, _, args) = &expr.kind; + if let ExprKind::MethodCall(method_name, _, args, _) = &expr.kind; if let ExprKind::Path(QPath::Resolved(None, path)) = &args[0].kind; let ty = cx.tables.expr_ty(&args[0]); let name = method_name.ident.as_str(); @@ -166,7 +166,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> { } else { // find `unwrap[_err]()` calls: if_chain! { - if let ExprKind::MethodCall(ref method_name, _, ref args) = expr.kind; + if let ExprKind::MethodCall(ref method_name, _, ref args, _) = expr.kind; if let ExprKind::Path(QPath::Resolved(None, ref path)) = args[0].kind; if [sym!(unwrap), sym!(unwrap_err)].contains(&method_name.ident.name); let call_to_unwrap = method_name.ident.name == sym!(unwrap); diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 141035a980ad..78d249482d53 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -61,7 +61,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion { } }, - ExprKind::MethodCall(ref name, .., ref args) => { + ExprKind::MethodCall(ref name, .., ref args, _) => { if match_trait_method(cx, e, &paths::INTO) && &*name.ident.as_str() == "into" { let a = cx.tables.expr_ty(e); let b = cx.tables.expr_ty(&args[0]); diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index bbcf396eef7d..8b58bbb5e657 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -250,8 +250,8 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { self.visit_expr(arg); } }, - ExprKind::MethodCall(ref _method_name, ref _generics, ref _args) => { - println!("MethodCall(ref method_name, ref generics, ref args) = {};", current); + ExprKind::MethodCall(ref _method_name, ref _generics, ref _args, ref _fn_span) => { + println!("MethodCall(ref method_name, ref generics, ref args, ref fn_span) = {};", current); println!(" // unimplemented: `ExprKind::MethodCall` is not further destructured at the moment"); }, ExprKind::Tup(ref elements) => { diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index f8d197c15e8d..473a730dad50 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -132,7 +132,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { && self.eq_pat(&l.pat, &r.pat) }) }, - (&ExprKind::MethodCall(l_path, _, l_args), &ExprKind::MethodCall(r_path, _, r_args)) => { + (&ExprKind::MethodCall(l_path, _, l_args, _), &ExprKind::MethodCall(r_path, _, r_args, _)) => { !self.ignore_fn && self.eq_path_segment(l_path, r_path) && self.eq_exprs(l_args, r_args) }, (&ExprKind::Repeat(ref le, ref ll_id), &ExprKind::Repeat(ref re, ref rl_id)) => { @@ -542,7 +542,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { s.hash(&mut self.s); }, - ExprKind::MethodCall(ref path, ref _tys, args) => { + ExprKind::MethodCall(ref path, ref _tys, args, ref _fn_span) => { self.hash_name(path.ident.name); self.hash_exprs(args); }, diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 9b672b9ec225..649b166e98ee 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -167,7 +167,7 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, indent: usize) { print_expr(cx, arg, indent + 1); } }, - hir::ExprKind::MethodCall(ref path, _, args) => { + hir::ExprKind::MethodCall(ref path, _, args, _) => { println!("{}MethodCall", ind); println!("{}method name: {}", ind, path.ident.name); for arg in args { diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 8e1b047f6f80..89e2bcdd7935 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -402,7 +402,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CompilerLintFunctions { } if_chain! { - if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind; + if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; let fn_name = path.ident; if let Some(sugg) = self.map.get(&*fn_name.as_str()); let ty = walk_ptrs_ty(cx.tables.expr_ty(&args[0])); @@ -491,7 +491,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CollapsibleCalls { let stmts = &block.stmts; if stmts.len() == 1 && block.expr.is_none(); if let StmtKind::Semi(only_expr) = &stmts[0].kind; - if let ExprKind::MethodCall(ref ps, _, ref span_call_args) = &only_expr.kind; + if let ExprKind::MethodCall(ref ps, _, ref span_call_args, _) = &only_expr.kind; let and_then_snippets = get_and_then_snippets(cx, and_then_args); let mut sle = SpanlessEq::new(cx).ignore_fn(); then { diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 7b59917c2bbf..60ab19e71f5e 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -379,7 +379,7 @@ pub fn method_calls<'tcx>( let mut current = expr; for _ in 0..max_depth { - if let ExprKind::MethodCall(path, span, args) = ¤t.kind { + if let ExprKind::MethodCall(path, span, args, _) = ¤t.kind { if args.iter().any(|e| e.span.from_expansion()) { break; } @@ -406,7 +406,7 @@ pub fn method_chain_args<'a>(expr: &'a Expr<'_>, methods: &[&str]) -> Option first - if let ExprKind::MethodCall(ref path, _, ref args) = current.kind { + if let ExprKind::MethodCall(ref path, _, ref args, _) = current.kind { if path.ident.name.as_str() == *method_name { if args.iter().any(|e| e.span.from_expansion()) { return None; @@ -1324,7 +1324,7 @@ pub fn is_must_use_func_call(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool None } }, - ExprKind::MethodCall(_, _, _) => cx.tables.type_dependent_def_id(expr.hir_id), + ExprKind::MethodCall(_, _, _, _) => cx.tables.type_dependent_def_id(expr.hir_id), _ => None, }; diff --git a/clippy_lints/src/utils/ptr.rs b/clippy_lints/src/utils/ptr.rs index fb6bd5e81585..ee336ecc58d9 100644 --- a/clippy_lints/src/utils/ptr.rs +++ b/clippy_lints/src/utils/ptr.rs @@ -58,7 +58,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PtrCloneVisitor<'a, 'tcx> { if self.abort { return; } - if let ExprKind::MethodCall(ref seg, _, ref args) = expr.kind { + if let ExprKind::MethodCall(ref seg, _, ref args, _) = expr.kind { if args.len() == 1 && match_var(&args[0], self.name) { if seg.ident.name.as_str() == "capacity" { self.abort = true; diff --git a/clippy_lints/src/verbose_file_reads.rs b/clippy_lints/src/verbose_file_reads.rs index 7247518e19b9..6d420d491c50 100644 --- a/clippy_lints/src/verbose_file_reads.rs +++ b/clippy_lints/src/verbose_file_reads.rs @@ -59,7 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VerboseFileReads { fn is_file_read_to_end<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) -> bool { if_chain! { - if let ExprKind::MethodCall(method_name, _, exprs) = expr.kind; + if let ExprKind::MethodCall(method_name, _, exprs, _) = expr.kind; if method_name.ident.as_str() == "read_to_end"; if let ExprKind::Path(QPath::Resolved(None, _)) = &exprs[0].kind; let ty = cx.tables.expr_ty(&exprs[0]); @@ -73,7 +73,7 @@ fn is_file_read_to_end<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'t fn is_file_read_to_string<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) -> bool { if_chain! { - if let ExprKind::MethodCall(method_name, _, exprs) = expr.kind; + if let ExprKind::MethodCall(method_name, _, exprs, _) = expr.kind; if method_name.ident.as_str() == "read_to_string"; if let ExprKind::Path(QPath::Resolved(None, _)) = &exprs[0].kind; let ty = cx.tables.expr_ty(&exprs[0]); From 4cc8ce91a5cecc8e0bb23dc9adea12af77f0275f Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 9 Jun 2020 23:45:32 -0400 Subject: [PATCH 0020/1222] Clippy fixes --- clippy_lints/src/unnecessary_sort_by.rs | 6 +++--- clippy_lints/src/utils/ast_utils.rs | 2 +- clippy_lints/src/vec_resize_to_zero.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index 33d8331c2923..e94eebb88e49 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -95,7 +95,7 @@ fn mirrored_exprs( // The two exprs are method calls. // Check to see that the function is the same and the arguments are mirrored // This is enough because the receiver of the method is listed in the arguments - (ExprKind::MethodCall(left_segment, _, left_args), ExprKind::MethodCall(right_segment, _, right_args)) => { + (ExprKind::MethodCall(left_segment, _, left_args, _), ExprKind::MethodCall(right_segment, _, right_args, _)) => { left_segment.ident == right_segment.ident && left_args .iter() @@ -170,7 +170,7 @@ fn mirrored_exprs( fn detect_lint(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option { if_chain! { - if let ExprKind::MethodCall(name_ident, _, args) = &expr.kind; + if let ExprKind::MethodCall(name_ident, _, args, _) = &expr.kind; if let name = name_ident.ident.name.to_ident_string(); if name == "sort_by" || name == "sort_unstable_by"; if let [vec, Expr { kind: ExprKind::Closure(_, _, closure_body_id, _, _), .. }] = args; @@ -180,7 +180,7 @@ fn detect_lint(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option Param { pat: Pat { kind: PatKind::Binding(_, _, left_ident, _), .. }, ..}, Param { pat: Pat { kind: PatKind::Binding(_, _, right_ident, _), .. }, .. } ] = &closure_body.params; - if let ExprKind::MethodCall(method_path, _, [ref left_expr, ref right_expr]) = &closure_body.value.kind; + if let ExprKind::MethodCall(method_path, _, [ref left_expr, ref right_expr], _) = &closure_body.value.kind; if method_path.ident.name.to_ident_string() == "cmp"; then { let (closure_body, closure_arg, reverse) = if mirrored_exprs( diff --git a/clippy_lints/src/utils/ast_utils.rs b/clippy_lints/src/utils/ast_utils.rs index dcf09da198e2..e60e2a81e070 100755 --- a/clippy_lints/src/utils/ast_utils.rs +++ b/clippy_lints/src/utils/ast_utils.rs @@ -120,7 +120,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (Array(l), Array(r)) | (Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)), (Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value), (Call(lc, la), Call(rc, ra)) => eq_expr(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)), - (MethodCall(lc, la), MethodCall(rc, ra)) => eq_path_seg(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)), + (MethodCall(lc, la, _), MethodCall(rc, ra, _)) => eq_path_seg(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)), (Binary(lo, ll, lr), Binary(ro, rl, rr)) => lo.node == ro.node && eq_expr(ll, rl) && eq_expr(lr, rr), (Unary(lo, l), Unary(ro, r)) => mem::discriminant(lo) == mem::discriminant(ro) && eq_expr(l, r), (Lit(l), Lit(r)) => l.kind == r.kind, diff --git a/clippy_lints/src/vec_resize_to_zero.rs b/clippy_lints/src/vec_resize_to_zero.rs index 86cbfa8203d5..55758efa32e6 100644 --- a/clippy_lints/src/vec_resize_to_zero.rs +++ b/clippy_lints/src/vec_resize_to_zero.rs @@ -31,7 +31,7 @@ declare_lint_pass!(VecResizeToZero => [VEC_RESIZE_TO_ZERO]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VecResizeToZero { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { - if let hir::ExprKind::MethodCall(path_segment, _, ref args) = expr.kind; + if let hir::ExprKind::MethodCall(path_segment, _, ref args, _) = expr.kind; if let Some(method_def_id) = cx.tables.type_dependent_def_id(expr.hir_id); if match_def_path(cx, method_def_id, &paths::VEC_RESIZE) && args.len() == 3; if let ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = args[1].kind; From 3326b346cedf0482e4c29377f20eba9491c34f4b Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sun, 10 May 2020 12:15:51 +0100 Subject: [PATCH 0021/1222] Remove associated opaque types They're unused now. --- clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/manual_async_fn.rs | 2 +- clippy_lints/src/utils/hir_utils.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index d80ad47ab246..318d0b69d57b 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -379,7 +379,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { TyKind::Path(ref path) => { self.collect_anonymous_lifetimes(path, ty); }, - TyKind::Def(item, _) => { + TyKind::OpaqueDef(item, _) => { let map = self.cx.tcx.hir(); if let ItemKind::OpaqueTy(ref exist_ty) = map.expect_item(item.id).kind { for bound in exist_ty.bounds { diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index cb72a2405823..03ab274d9ca9 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -99,7 +99,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ManualAsyncFn { fn future_trait_ref<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &'tcx Ty<'tcx>) -> Option<&'tcx TraitRef<'tcx>> { if_chain! { - if let TyKind::Def(item_id, _) = ty.kind; + if let TyKind::OpaqueDef(item_id, _) = ty.kind; let item = cx.tcx.hir().item(item_id.id); if let ItemKind::OpaqueTy(opaque) = &item.kind; if opaque.bounds.len() == 1; diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index f8d197c15e8d..0096543c1fbc 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -710,7 +710,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { segment.ident.name.hash(&mut self.s); }, }, - TyKind::Def(_, arg_list) => { + TyKind::OpaqueDef(_, arg_list) => { for arg in *arg_list { match arg { GenericArg::Lifetime(ref l) => self.hash_lifetime(l), From e47f7e50da4cc193c268b6b921bbf132b527e3c2 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sun, 10 May 2020 15:05:06 +0100 Subject: [PATCH 0022/1222] Remove ImplItemKind::OpaqueTy from clippy --- clippy_lints/src/missing_doc.rs | 1 - clippy_lints/src/missing_inline.rs | 2 +- clippy_lints/src/utils/inspector.rs | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 2eefb6bbaf42..0fd1e87f9e41 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -187,7 +187,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { hir::ImplItemKind::Const(..) => "an associated constant", hir::ImplItemKind::Fn(..) => "a method", hir::ImplItemKind::TyAlias(_) => "an associated type", - hir::ImplItemKind::OpaqueTy(_) => "an existential type", }; self.check_missing_docs_attrs(cx, &impl_item.attrs, impl_item.span, desc); } diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 3ad3d5aee4d4..1802470b1841 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -142,7 +142,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline { let desc = match impl_item.kind { hir::ImplItemKind::Fn(..) => "a method", - hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) | hir::ImplItemKind::OpaqueTy(_) => return, + hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) => return, }; let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 9b672b9ec225..9a4689631cca 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -63,7 +63,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DeepCodeInspector { }, hir::ImplItemKind::Fn(..) => println!("method"), hir::ImplItemKind::TyAlias(_) => println!("associated type"), - hir::ImplItemKind::OpaqueTy(_) => println!("existential type"), } } // fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx From afedabbdf3d36f4b81a4a33fd48d93b0cca9531c Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 13 Jun 2020 01:27:14 +0000 Subject: [PATCH 0023/1222] Stabilize Option::zip --- clippy_lints/src/checked_conversions.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs index e845ef99c7cc..88145015ba8b 100644 --- a/clippy_lints/src/checked_conversions.rs +++ b/clippy_lints/src/checked_conversions.rs @@ -88,7 +88,7 @@ fn double_check<'a>(cx: &LateContext<'_, '_>, left: &'a Expr<'_>, right: &'a Exp let upper = check_upper_bound(l); let lower = check_lower_bound(r); - transpose(upper, lower).and_then(|(l, r)| l.combine(r, cx)) + upper.zip(lower).and_then(|(l, r)| l.combine(r, cx)) }; upper_lower(left, right).or_else(|| upper_lower(right, left)) @@ -131,7 +131,10 @@ impl<'a> Conversion<'a> { /// Checks if the to-type is the same (if there is a type constraint) fn has_compatible_to_type(&self, other: &Self) -> bool { - transpose(self.to_type.as_ref(), other.to_type.as_ref()).map_or(true, |(l, r)| l == r) + match (self.to_type, other.to_type) { + (Some(l), Some(r)) => l == r, + _ => true, + } } /// Try to construct a new conversion if the conversion type is valid @@ -322,14 +325,6 @@ fn int_ty_to_sym<'tcx>(path: &QPath<'_>) -> Option<&'tcx str> { } } -/// (Option, Option) -> Option<(T, U)> -fn transpose(lhs: Option, rhs: Option) -> Option<(T, U)> { - match (lhs, rhs) { - (Some(l), Some(r)) => Some((l, r)), - _ => None, - } -} - /// Will return the expressions as if they were expr1 <= expr2 fn normalize_le_ge<'a>(op: &BinOp, left: &'a Expr<'a>, right: &'a Expr<'a>) -> Option<(&'a Expr<'a>, &'a Expr<'a>)> { match op.node { From a6c34f49a440775c55f8bb546aab05da154a8fe2 Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Wed, 17 Jun 2020 18:13:05 -0400 Subject: [PATCH 0024/1222] Refactor hir::Place For the following code ```rust let c = || bar(foo.x, foo.x) ``` We generate two different `hir::Place`s for both `foo.x`. Handling this adds overhead for analysis we need to do for RFC 2229. We also want to store type information at each Projection to support analysis as part of the RFC. This resembles what we have for `mir::Place` This commit modifies the Place as follows: - Rename to `PlaceWithHirId`, where there `hir_id` is that of the expressioin. - Move any other information that describes the access out to another struct now called `Place`. - Removed `Span`, it can be accessed using the [hir API](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.span) - Modify `Projection` to be a strucutre of its own, that currently only contains the `ProjectionKind`. Adding type information to projections wil be completed as part of https://github.com/rust-lang/project-rfc-2229/issues/5 Closes https://github.com/rust-lang/project-rfc-2229/issues/3 Co-authored-by: Aman Arora Co-authored-by: Roxane Fruytier --- clippy_lints/src/escape.rs | 20 +++++++------- clippy_lints/src/loops.rs | 32 ++++++++++++---------- clippy_lints/src/needless_pass_by_value.rs | 10 +++---- clippy_lints/src/utils/usage.rs | 12 ++++---- 4 files changed, 38 insertions(+), 36 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 7227683aa5ac..59af475af175 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -6,7 +6,7 @@ use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; use rustc_target::abi::LayoutOf; -use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Place, PlaceBase}; +use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceWithHirId, PlaceBase}; use crate::utils::span_lint; @@ -112,9 +112,9 @@ fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool { } impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { - fn consume(&mut self, cmt: &Place<'tcx>, mode: ConsumeMode) { - if cmt.projections.is_empty() { - if let PlaceBase::Local(lid) = cmt.base { + fn consume(&mut self, cmt: &PlaceWithHirId<'tcx>, mode: ConsumeMode) { + if cmt.place.projections.is_empty() { + if let PlaceBase::Local(lid) = cmt.place.base { if let ConsumeMode::Move = mode { // moved out or in. clearly can't be localized self.set.remove(&lid); @@ -132,16 +132,16 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { } } - fn borrow(&mut self, cmt: &Place<'tcx>, _: ty::BorrowKind) { - if cmt.projections.is_empty() { - if let PlaceBase::Local(lid) = cmt.base { + fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: ty::BorrowKind) { + if cmt.place.projections.is_empty() { + if let PlaceBase::Local(lid) = cmt.place.base { self.set.remove(&lid); } } } - fn mutate(&mut self, cmt: &Place<'tcx>) { - if cmt.projections.is_empty() { + fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>) { + if cmt.place.projections.is_empty() { let map = &self.cx.tcx.hir(); if is_argument(*map, cmt.hir_id) { // Skip closure arguments @@ -150,7 +150,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { return; } - if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) { + if is_non_trait_box(cmt.place.ty) && !self.is_large_box(cmt.place.ty) { self.set.insert(cmt.hir_id); } return; diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 771bc8d05582..83093ec51bd9 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -28,7 +28,7 @@ use rustc_middle::ty::{self, Ty, TyS}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::symbol::Symbol; -use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Place, PlaceBase}; +use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceWithHirId, PlaceBase}; use std::iter::{once, Iterator}; use std::mem; @@ -1489,42 +1489,43 @@ fn check_for_loop_over_map_kv<'a, 'tcx>( } } -struct MutatePairDelegate { +struct MutatePairDelegate<'a, 'tcx> { + cx: &'a LateContext<'a, 'tcx>, hir_id_low: Option, hir_id_high: Option, span_low: Option, span_high: Option, } -impl<'tcx> Delegate<'tcx> for MutatePairDelegate { - fn consume(&mut self, _: &Place<'tcx>, _: ConsumeMode) {} +impl<'a, 'tcx> Delegate<'tcx> for MutatePairDelegate<'a, 'tcx> { + fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: ConsumeMode) {} - fn borrow(&mut self, cmt: &Place<'tcx>, bk: ty::BorrowKind) { + fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, bk: ty::BorrowKind) { if let ty::BorrowKind::MutBorrow = bk { - if let PlaceBase::Local(id) = cmt.base { + if let PlaceBase::Local(id) = cmt.place.base { if Some(id) == self.hir_id_low { - self.span_low = Some(cmt.span) + self.span_low = Some(self.cx.tcx.hir().span(cmt.hir_id)) } if Some(id) == self.hir_id_high { - self.span_high = Some(cmt.span) + self.span_high = Some(self.cx.tcx.hir().span(cmt.hir_id)) } } } } - fn mutate(&mut self, cmt: &Place<'tcx>) { - if let PlaceBase::Local(id) = cmt.base { + fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>) { + if let PlaceBase::Local(id) = cmt.place.base { if Some(id) == self.hir_id_low { - self.span_low = Some(cmt.span) + self.span_low = Some(self.cx.tcx.hir().span(cmt.hir_id)) } if Some(id) == self.hir_id_high { - self.span_high = Some(cmt.span) + self.span_high = Some(self.cx.tcx.hir().span(cmt.hir_id)) } } } } -impl<'tcx> MutatePairDelegate { +impl<'a, 'tcx> MutatePairDelegate<'a, 'tcx> { fn mutation_span(&self) -> (Option, Option) { (self.span_low, self.span_high) } @@ -1579,12 +1580,13 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr<'_>) -> Option, +fn check_for_mutation<'a, 'tcx> ( + cx: &LateContext<'a, 'tcx>, body: &Expr<'_>, bound_ids: &[Option], ) -> (Option, Option) { let mut delegate = MutatePairDelegate { + cx: cx, hir_id_low: bound_ids[0], hir_id_high: bound_ids[1], span_low: None, diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 218b0d27f748..ca87deac9891 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -326,21 +326,21 @@ struct MovedVariablesCtxt { } impl MovedVariablesCtxt { - fn move_common(&mut self, cmt: &euv::Place<'_>) { - if let euv::PlaceBase::Local(vid) = cmt.base { + fn move_common(&mut self, cmt: &euv::PlaceWithHirId<'_>) { + if let euv::PlaceBase::Local(vid) = cmt.place.base { self.moved_vars.insert(vid); } } } impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt { - fn consume(&mut self, cmt: &euv::Place<'tcx>, mode: euv::ConsumeMode) { + fn consume(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, mode: euv::ConsumeMode) { if let euv::ConsumeMode::Move = mode { self.move_common(cmt); } } - fn borrow(&mut self, _: &euv::Place<'tcx>, _: ty::BorrowKind) {} + fn borrow(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: ty::BorrowKind) {} - fn mutate(&mut self, _: &euv::Place<'tcx>) {} + fn mutate(&mut self, _: &euv::PlaceWithHirId<'tcx>) {} } diff --git a/clippy_lints/src/utils/usage.rs b/clippy_lints/src/utils/usage.rs index 904d948ad29e..6a7a1f1ceaae 100644 --- a/clippy_lints/src/utils/usage.rs +++ b/clippy_lints/src/utils/usage.rs @@ -8,7 +8,7 @@ use rustc_lint::LateContext; use rustc_middle::hir::map::Map; use rustc_middle::ty; use rustc_span::symbol::{Ident, Symbol}; -use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Place, PlaceBase}; +use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceWithHirId, PlaceBase}; /// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined. pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &'a LateContext<'a, 'tcx>) -> Option> { @@ -46,8 +46,8 @@ struct MutVarsDelegate { impl<'tcx> MutVarsDelegate { #[allow(clippy::similar_names)] - fn update(&mut self, cat: &Place<'tcx>) { - match cat.base { + fn update(&mut self, cat: &PlaceWithHirId<'tcx>) { + match cat.place.base { PlaceBase::Local(id) => { self.used_mutably.insert(id); }, @@ -63,15 +63,15 @@ impl<'tcx> MutVarsDelegate { } impl<'tcx> Delegate<'tcx> for MutVarsDelegate { - fn consume(&mut self, _: &Place<'tcx>, _: ConsumeMode) {} + fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: ConsumeMode) {} - fn borrow(&mut self, cmt: &Place<'tcx>, bk: ty::BorrowKind) { + fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, bk: ty::BorrowKind) { if let ty::BorrowKind::MutBorrow = bk { self.update(&cmt) } } - fn mutate(&mut self, cmt: &Place<'tcx>) { + fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>) { self.update(&cmt) } } From 7d3e7eac1b4f963c143a7a34ddc7fdf5dfbd2b08 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 21 Jun 2020 11:20:48 +0200 Subject: [PATCH 0025/1222] Make is_freeze and is_copy_modulo_regions take TyCtxtAt --- clippy_lints/src/functions.rs | 2 +- clippy_lints/src/let_if_seq.rs | 3 +-- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/question_mark.rs | 2 +- clippy_lints/src/utils/mod.rs | 2 +- 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 991d129e8f0d..1f9bd7a691b5 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -513,7 +513,7 @@ fn is_mutable_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Span, // primitive types are never mutable ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false, ty::Adt(ref adt, ref substs) => { - tys.insert(adt.did) && !ty.is_freeze(cx.tcx, cx.param_env, span) + tys.insert(adt.did) && !ty.is_freeze(cx.tcx.at(span), cx.param_env) || KNOWN_WRAPPER_TYS.iter().any(|path| match_def_path(cx, adt.did, path)) && substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)) }, diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index d7bf8a147681..e097f40f87e4 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -74,9 +74,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq { let span = stmt.span.to(if_.span); let has_interior_mutability = !cx.tables.node_type(canonical_id).is_freeze( - cx.tcx, + cx.tcx.at(span), cx.param_env, - span ); if has_interior_mutability { return; } diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 0b9b7e1b8cc1..93569a04f7a3 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -118,7 +118,7 @@ fn is_mutable_type<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Spa size.try_eval_usize(cx.tcx, cx.param_env).map_or(true, |u| u != 0) && is_mutable_type(cx, inner_ty, span) }, Tuple(..) => ty.tuple_fields().any(|ty| is_mutable_type(cx, ty, span)), - Adt(..) => cx.tcx.layout_of(cx.param_env.and(ty)).is_ok() && !ty.is_freeze(cx.tcx, cx.param_env, span), + Adt(..) => cx.tcx.layout_of(cx.param_env.and(ty)).is_ok() && !ty.is_freeze(cx.tcx.at(span), cx.param_env), _ => false, } } diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index bb257e5a542d..230dfd2ebf56 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -110,7 +110,7 @@ impl Source { } fn verify_ty_bound<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, source: Source) { - if ty.is_freeze(cx.tcx, cx.param_env, DUMMY_SP) || is_copy(cx, ty) { + if ty.is_freeze(cx.tcx.at(DUMMY_SP), cx.param_env) || is_copy(cx, ty) { // An `UnsafeCell` is `!Copy`, and an `UnsafeCell` is also the only type which // is `!Freeze`, thus if our type is `Copy` we can be sure it must be `Freeze` // as well. diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 3591972fe082..d8a73f8054bc 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -137,7 +137,7 @@ impl QuestionMark { fn moves_by_default(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool { let expr_ty = cx.tables.expr_ty(expression); - !expr_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, expression.span) + !expr_ty.is_copy_modulo_regions(cx.tcx.at(expression.span), cx.param_env) } fn is_option(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool { diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 60ab19e71f5e..6d4c6c6ce1ce 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -891,7 +891,7 @@ pub fn type_is_unsafe_function<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx } pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { - ty.is_copy_modulo_regions(cx.tcx, cx.param_env, DUMMY_SP) + ty.is_copy_modulo_regions(cx.tcx.at(DUMMY_SP), cx.param_env) } /// Checks if an expression is constructing a tuple-like enum variant or struct From fadb09c7693cde922bab6baba142e3e4287e35f0 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 22 Jun 2020 13:29:04 -0400 Subject: [PATCH 0026/1222] Stop using old version of `syn` in `rustc-workspace-hack` None of the tools seem to need syn 0.15.35, so we can just build syn 1.0. This was causing an issue with clippy's `compile-test` program: since multiple versions of `syn` would exist in the build directory, we would non-deterministically pick one based on filesystem iteration order. If the pre-1.0 version of `syn` was picked, a strange build error would occur (see https://github.com/rust-lang/rust/pull/73594#issuecomment-647671463) To prevent this kind of issue from happening again, we now panic if we find multiple versions of a crate in the build directly, instead of silently picking the first version we find. --- tests/compile-test.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/compile-test.rs b/tests/compile-test.rs index f28aedbf0ab8..368fa6a98c5d 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -49,7 +49,9 @@ fn third_party_crates() -> String { if let Some(name) = path.file_name().and_then(OsStr::to_str) { for dep in CRATES { if name.starts_with(&format!("lib{}-", dep)) && name.ends_with(".rlib") { - crates.entry(dep).or_insert(path); + if let Some(old) = crates.insert(dep, path.clone()) { + panic!("Found multiple rlibs for crate `{}`: `{:?}` and `{:?}", dep, old, path); + } break; } } From e62c2567d7cbcc1a694131a7ab047307e6aec3b4 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sun, 21 Jun 2020 15:49:56 -0700 Subject: [PATCH 0027/1222] Record span of `const` kw in GenericParamKind Context: this is needed to fix https://github.com/rust-lang/rustfmt/issues/4263, which currently records the span of a const generic param incorrectly because the location of the `const` kw is not known. I am not sure how to add tests for this; any guidance in how to do so would be appreciated :slightly_smiling_face: --- clippy_lints/src/utils/ast_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/ast_utils.rs b/clippy_lints/src/utils/ast_utils.rs index e60e2a81e070..e19a79dd8dad 100755 --- a/clippy_lints/src/utils/ast_utils.rs +++ b/clippy_lints/src/utils/ast_utils.rs @@ -476,7 +476,7 @@ pub fn eq_generic_param(l: &GenericParam, r: &GenericParam) -> bool { && match (&l.kind, &r.kind) { (Lifetime, Lifetime) => true, (Type { default: l }, Type { default: r }) => both(l, r, |l, r| eq_ty(l, r)), - (Const { ty: l }, Const { ty: r }) => eq_ty(l, r), + (Const { ty: l, kw_span: _ }, Const { ty: r, kw_span: _ }) => eq_ty(l, r), _ => false, } && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)) From 7d8b987a53ae8143beff570be183d2530bcdca55 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 26 Jun 2020 02:56:23 +0300 Subject: [PATCH 0028/1222] rustc_lint: only query `typeck_tables_of` when a lint needs it. --- clippy_lints/src/arithmetic.rs | 6 +- clippy_lints/src/assertions_on_constants.rs | 4 +- clippy_lints/src/assign_ops.rs | 6 +- clippy_lints/src/atomic_ordering.rs | 8 +- clippy_lints/src/bit_mask.rs | 2 +- clippy_lints/src/booleans.rs | 6 +- clippy_lints/src/bytecount.rs | 4 +- clippy_lints/src/cognitive_complexity.rs | 2 +- clippy_lints/src/comparison_chain.rs | 2 +- clippy_lints/src/copies.rs | 8 +- clippy_lints/src/default_trait_access.rs | 4 +- clippy_lints/src/dereference.rs | 18 +-- clippy_lints/src/drop_forget_ref.rs | 2 +- clippy_lints/src/duration_subsec.rs | 4 +- clippy_lints/src/entry.rs | 2 +- clippy_lints/src/eq_op.rs | 16 +-- clippy_lints/src/erasing_op.rs | 2 +- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/eta_reduction.rs | 6 +- clippy_lints/src/eval_order_dependence.rs | 8 +- clippy_lints/src/float_literal.rs | 2 +- clippy_lints/src/floating_point_arithmetic.rs | 24 ++-- clippy_lints/src/format.rs | 4 +- clippy_lints/src/get_last_with_len.rs | 2 +- clippy_lints/src/identity_op.rs | 8 +- clippy_lints/src/if_let_mutex.rs | 2 +- clippy_lints/src/if_let_some_result.rs | 2 +- clippy_lints/src/implicit_return.rs | 2 +- clippy_lints/src/implicit_saturating_sub.rs | 4 +- clippy_lints/src/indexing_slicing.rs | 8 +- clippy_lints/src/infinite_iter.rs | 7 +- clippy_lints/src/integer_division.rs | 2 +- clippy_lints/src/large_stack_arrays.rs | 2 +- clippy_lints/src/len_zero.rs | 2 +- clippy_lints/src/let_and_return.rs | 4 +- clippy_lints/src/let_if_seq.rs | 2 +- clippy_lints/src/let_underscore.rs | 4 +- clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/loops.rs | 34 +++--- clippy_lints/src/map_clone.rs | 6 +- clippy_lints/src/map_unit_fn.rs | 8 +- clippy_lints/src/match_on_vec_items.rs | 4 +- clippy_lints/src/matches.rs | 26 ++-- clippy_lints/src/mem_discriminant.rs | 4 +- clippy_lints/src/mem_forget.rs | 2 +- clippy_lints/src/mem_replace.rs | 10 +- .../src/methods/bind_instead_of_map.rs | 2 +- .../src/methods/inefficient_to_string.rs | 4 +- .../methods/manual_saturating_arithmetic.rs | 4 +- clippy_lints/src/methods/mod.rs | 111 +++++++++--------- .../src/methods/option_map_unwrap_or.rs | 4 +- .../src/methods/unnecessary_filter_map.rs | 2 +- clippy_lints/src/minmax.rs | 29 +++-- clippy_lints/src/misc.rs | 18 +-- clippy_lints/src/modulo_arithmetic.rs | 6 +- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/mut_mut.rs | 2 +- clippy_lints/src/mut_reference.rs | 6 +- clippy_lints/src/mutable_debug_assertion.rs | 2 +- clippy_lints/src/mutex_atomic.rs | 2 +- clippy_lints/src/needless_bool.rs | 2 +- clippy_lints/src/needless_borrow.rs | 6 +- clippy_lints/src/needless_pass_by_value.rs | 10 +- clippy_lints/src/needless_update.rs | 2 +- clippy_lints/src/neg_cmp_op_on_partial_ord.rs | 2 +- clippy_lints/src/neg_multiply.rs | 4 +- clippy_lints/src/no_effect.rs | 10 +- clippy_lints/src/non_copy_const.rs | 6 +- clippy_lints/src/open_options.rs | 4 +- .../src/overflow_check_conditional.rs | 8 +- clippy_lints/src/path_buf_push_overwrite.rs | 2 +- clippy_lints/src/ptr_offset_with_cast.rs | 4 +- clippy_lints/src/question_mark.rs | 6 +- clippy_lints/src/ranges.rs | 6 +- clippy_lints/src/regex.rs | 6 +- clippy_lints/src/shadow.rs | 2 +- clippy_lints/src/strings.rs | 2 +- clippy_lints/src/swap.rs | 2 +- clippy_lints/src/temporary_assignment.rs | 2 +- clippy_lints/src/to_digit_is_some.rs | 4 +- clippy_lints/src/trait_bounds.rs | 2 +- clippy_lints/src/transmute.rs | 6 +- clippy_lints/src/transmuting_null.rs | 2 +- clippy_lints/src/try_err.rs | 4 +- clippy_lints/src/types.rs | 36 +++--- clippy_lints/src/unnamed_address.rs | 12 +- clippy_lints/src/unnecessary_sort_by.rs | 2 +- clippy_lints/src/unwrap.rs | 2 +- clippy_lints/src/useless_conversion.rs | 18 +-- clippy_lints/src/utils/higher.rs | 4 +- clippy_lints/src/utils/hir_utils.rs | 4 +- clippy_lints/src/utils/inspector.rs | 6 +- clippy_lints/src/utils/internal_lints.rs | 6 +- clippy_lints/src/utils/mod.rs | 16 +-- clippy_lints/src/utils/usage.rs | 2 +- clippy_lints/src/vec.rs | 6 +- clippy_lints/src/vec_resize_to_zero.rs | 2 +- clippy_lints/src/verbose_file_reads.rs | 4 +- clippy_lints/src/zero_div_zero.rs | 4 +- doc/common_tools_writing_lints.md | 16 +-- 100 files changed, 361 insertions(+), 366 deletions(-) diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs index 6cbe10a5352d..cc09b99cf1dd 100644 --- a/clippy_lints/src/arithmetic.rs +++ b/clippy_lints/src/arithmetic.rs @@ -86,7 +86,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic { _ => (), } - let (l_ty, r_ty) = (cx.tables.expr_ty(l), cx.tables.expr_ty(r)); + let (l_ty, r_ty) = (cx.tables().expr_ty(l), cx.tables().expr_ty(r)); if l_ty.peel_refs().is_integral() && r_ty.peel_refs().is_integral() { span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected"); self.expr_span = Some(expr.span); @@ -96,8 +96,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic { } }, hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => { - let ty = cx.tables.expr_ty(arg); - if constant_simple(cx, cx.tables, expr).is_none() { + let ty = cx.tables().expr_ty(arg); + if constant_simple(cx, cx.tables(), expr).is_none() { if ty.is_integral() { span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected"); self.expr_span = Some(expr.span); diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index f8a8fdcd3aa3..c4536b57f8a9 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -72,7 +72,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants { } if_chain! { if let ExprKind::Unary(_, ref lit) = e.kind; - if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables, lit); + if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables(), lit); if is_true; then { lint_true(true); @@ -121,7 +121,7 @@ fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx E if let ExprKind::DropTemps(ref expr) = expr.kind; if let ExprKind::Unary(UnOp::UnNot, ref expr) = expr.kind; // bind the first argument of the `assert!` macro - if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables, expr); + if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables(), expr); // arm 1 pattern if let PatKind::Lit(ref lit_expr) = arms[0].pat.kind; if let ExprKind::Lit(ref lit) = lit_expr.kind; diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index 13e61fe98bac..51a7647d3208 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -82,8 +82,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { hir::ExprKind::Assign(assignee, e, _) => { if let hir::ExprKind::Binary(op, l, r) = &e.kind { let lint = |assignee: &hir::Expr<'_>, rhs: &hir::Expr<'_>| { - let ty = cx.tables.expr_ty(assignee); - let rty = cx.tables.expr_ty(rhs); + let ty = cx.tables().expr_ty(assignee); + let rty = cx.tables().expr_ty(rhs); macro_rules! ops { ($op:expr, $cx:expr, @@ -167,7 +167,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { // a = b commutative_op a // Limited to primitive type as these ops are know to be commutative if SpanlessEq::new(cx).ignore_fn().eq_expr(assignee, r) - && cx.tables.expr_ty(assignee).is_primitive_ty() + && cx.tables().expr_ty(assignee).is_primitive_ty() { match op.node { hir::BinOpKind::Add diff --git a/clippy_lints/src/atomic_ordering.rs b/clippy_lints/src/atomic_ordering.rs index fca9aaaff9dc..65e1e2c519c2 100644 --- a/clippy_lints/src/atomic_ordering.rs +++ b/clippy_lints/src/atomic_ordering.rs @@ -53,7 +53,7 @@ const ATOMIC_TYPES: [&str; 12] = [ ]; fn type_is_atomic(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { - if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.tables.expr_ty(expr).kind { + if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.tables().expr_ty(expr).kind { ATOMIC_TYPES .iter() .any(|ty| match_def_path(cx, did, &["core", "sync", "atomic", ty])) @@ -76,7 +76,7 @@ fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if method == "load" || method == "store"; let ordering_arg = if method == "load" { &args[1] } else { &args[2] }; if let ExprKind::Path(ref ordering_qpath) = ordering_arg.kind; - if let Some(ordering_def_id) = cx.tables.qpath_res(ordering_qpath, ordering_arg.hir_id).opt_def_id(); + if let Some(ordering_def_id) = cx.tables().qpath_res(ordering_qpath, ordering_arg.hir_id).opt_def_id(); then { if method == "load" && match_ordering_def_path(cx, ordering_def_id, &["Release", "AcqRel"]) { @@ -107,12 +107,12 @@ fn check_memory_fence(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Call(ref func, ref args) = expr.kind; if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.tables.qpath_res(func_qpath, func.hir_id).opt_def_id(); + if let Some(def_id) = cx.tables().qpath_res(func_qpath, func.hir_id).opt_def_id(); if ["fence", "compiler_fence"] .iter() .any(|func| match_def_path(cx, def_id, &["core", "sync", "atomic", func])); if let ExprKind::Path(ref ordering_qpath) = &args[0].kind; - if let Some(ordering_def_id) = cx.tables.qpath_res(ordering_qpath, args[0].hir_id).opt_def_id(); + if let Some(ordering_def_id) = cx.tables().qpath_res(ordering_qpath, args[0].hir_id).opt_def_id(); if match_ordering_def_path(cx, ordering_def_id, &["Relaxed"]); then { span_lint_and_help( diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index ccb62cb038fd..a53f3249b85b 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -319,7 +319,7 @@ fn check_ineffective_gt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128, } fn fetch_int_literal(cx: &LateContext<'_, '_>, lit: &Expr<'_>) -> Option { - match constant(cx, cx.tables, lit)?.0 { + match constant(cx, cx.tables(), lit)?.0 { Constant::Int(n) => Some(n), _ => None, } diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index f92c564543b8..cc399a1f8a00 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -248,7 +248,7 @@ fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option { }) }, ExprKind::MethodCall(path, _, args, _) if args.len() == 1 => { - let type_of_receiver = cx.tables.expr_ty(&args[0]); + let type_of_receiver = cx.tables().expr_ty(&args[0]); if !is_type_diagnostic_item(cx, type_of_receiver, sym!(option_type)) && !is_type_diagnostic_item(cx, type_of_receiver, sym!(result_type)) { @@ -450,7 +450,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { self.bool_expr(e) }, ExprKind::Unary(UnOp::UnNot, inner) => { - if self.cx.tables.node_types()[inner.hir_id].is_bool() { + if self.cx.tables().node_types()[inner.hir_id].is_bool() { self.bool_expr(e); } else { walk_expr(self, e); @@ -465,7 +465,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { } fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[])) } diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index 531531a654d0..c00bb23069bf 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -53,7 +53,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount { if let ExprKind::Binary(ref op, ref l, ref r) = body.value.kind; if op.node == BinOpKind::Eq; if match_type(cx, - walk_ptrs_ty(cx.tables.expr_ty(&filter_args[0])), + walk_ptrs_ty(cx.tables().expr_ty(&filter_args[0])), &paths::SLICE_ITER); then { let needle = match get_path_name(l) { @@ -63,7 +63,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount { _ => { return; } } }; - if ty::Uint(UintTy::U8) != walk_ptrs_ty(cx.tables.expr_ty(needle)).kind { + if ty::Uint(UintTy::U8) != walk_ptrs_ty(cx.tables().expr_ty(needle)).kind { return; } let haystack = if let ExprKind::MethodCall(ref path, _, ref args, _) = diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index 3ba72e84fa82..78e509d2ecd8 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -60,7 +60,7 @@ impl CognitiveComplexity { let mut helper = CCHelper { cc: 1, returns: 0 }; helper.visit_expr(expr); let CCHelper { cc, returns } = helper; - let ret_ty = cx.tables.node_type(expr.hir_id); + let ret_ty = cx.tables().node_type(expr.hir_id); let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym!(result_type)) { returns } else { diff --git a/clippy_lints/src/comparison_chain.rs b/clippy_lints/src/comparison_chain.rs index 93e29edcaa58..9c0d33f92801 100644 --- a/clippy_lints/src/comparison_chain.rs +++ b/clippy_lints/src/comparison_chain.rs @@ -99,7 +99,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ComparisonChain { } // Check that the type being compared implements `core::cmp::Ord` - let ty = cx.tables.expr_ty(lhs1); + let ty = cx.tables().expr_ty(lhs1); let is_ord = get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[])); if !is_ord { diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index b6d50bdfa146..efd4a31f5596 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -192,7 +192,7 @@ fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block<'_>]) { /// Implementation of `IFS_SAME_COND`. fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { let hash: &dyn Fn(&&Expr<'_>) -> u64 = &|expr| -> u64 { - let mut h = SpanlessHash::new(cx, cx.tables); + let mut h = SpanlessHash::new(cx, cx.tables()); h.hash_expr(expr); h.finish() }; @@ -215,7 +215,7 @@ fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { /// Implementation of `SAME_FUNCTIONS_IN_IF_CONDITION`. fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { let hash: &dyn Fn(&&Expr<'_>) -> u64 = &|expr| -> u64 { - let mut h = SpanlessHash::new(cx, cx.tables); + let mut h = SpanlessHash::new(cx, cx.tables()); h.hash_expr(expr); h.finish() }; @@ -251,7 +251,7 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>) { if let ExprKind::Match(_, ref arms, MatchSource::Normal) = expr.kind { let hash = |&(_, arm): &(usize, &Arm<'_>)| -> u64 { - let mut h = SpanlessHash::new(cx, cx.tables); + let mut h = SpanlessHash::new(cx, cx.tables()); h.hash_expr(&arm.body); h.finish() }; @@ -320,7 +320,7 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat<'_>) -> FxHashMap { if let Entry::Vacant(v) = map.entry(ident.name) { - v.insert(cx.tables.pat_ty(pat)); + v.insert(cx.tables().pat_ty(pat)); } if let Some(ref as_pat) = *as_pat { bindings_impl(cx, as_pat, map); diff --git a/clippy_lints/src/default_trait_access.rs b/clippy_lints/src/default_trait_access.rs index 635d609c3828..69ae509fb23e 100644 --- a/clippy_lints/src/default_trait_access.rs +++ b/clippy_lints/src/default_trait_access.rs @@ -36,7 +36,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess { if let ExprKind::Call(ref path, ..) = expr.kind; if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id); if let ExprKind::Path(ref qpath) = path.kind; - if let Some(def_id) = cx.tables.qpath_res(qpath, path.hir_id).opt_def_id(); + if let Some(def_id) = cx.tables().qpath_res(qpath, path.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD); then { match qpath { @@ -54,7 +54,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess { // TODO: Work out a way to put "whatever the imported way of referencing // this type in this file" rather than a fully-qualified type. - let expr_ty = cx.tables.expr_ty(expr); + let expr_ty = cx.tables().expr_ty(expr); if let ty::Adt(..) = expr_ty.kind { let replacement = format!("{}::default()", expr_ty); span_lint_and_sugg( diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 1cd30ae2c638..1c6cc9369009 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -73,12 +73,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Dereferencing { fn lint_deref(cx: &LateContext<'_, '_>, method_name: &str, call_expr: &Expr<'_>, var_span: Span, expr_span: Span) { match method_name { "deref" => { - if cx - .tcx - .lang_items() - .deref_trait() - .map_or(false, |id| implements_trait(cx, cx.tables.expr_ty(&call_expr), id, &[])) - { + if cx.tcx.lang_items().deref_trait().map_or(false, |id| { + implements_trait(cx, cx.tables().expr_ty(&call_expr), id, &[]) + }) { span_lint_and_sugg( cx, EXPLICIT_DEREF_METHODS, @@ -91,12 +88,9 @@ fn lint_deref(cx: &LateContext<'_, '_>, method_name: &str, call_expr: &Expr<'_>, } }, "deref_mut" => { - if cx - .tcx - .lang_items() - .deref_mut_trait() - .map_or(false, |id| implements_trait(cx, cx.tables.expr_ty(&call_expr), id, &[])) - { + if cx.tcx.lang_items().deref_mut_trait().map_or(false, |id| { + implements_trait(cx, cx.tables().expr_ty(&call_expr), id, &[]) + }) { span_lint_and_sugg( cx, EXPLICIT_DEREF_METHODS, diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 9de9056c1402..014873eb1325 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -119,7 +119,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef { let lint; let msg; let arg = &args[0]; - let arg_ty = cx.tables.expr_ty(arg); + let arg_ty = cx.tables().expr_ty(arg); if let ty::Ref(..) = arg_ty.kind { if match_def_path(cx, def_id, &paths::DROP) { diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index 7171dcef968c..5eb320ceca24 100644 --- a/clippy_lints/src/duration_subsec.rs +++ b/clippy_lints/src/duration_subsec.rs @@ -43,8 +43,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec { if_chain! { if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, ref left, ref right) = expr.kind; if let ExprKind::MethodCall(ref method_path, _ , ref args, _) = left.kind; - if match_type(cx, walk_ptrs_ty(cx.tables.expr_ty(&args[0])), &paths::DURATION); - if let Some((Constant::Int(divisor), _)) = constant(cx, cx.tables, right); + if match_type(cx, walk_ptrs_ty(cx.tables().expr_ty(&args[0])), &paths::DURATION); + if let Some((Constant::Int(divisor), _)) = constant(cx, cx.tables(), right); then { let suggested_fn = match (method_path.ident.as_str().as_ref(), divisor) { ("subsec_micros", 1_000) | ("subsec_nanos", 1_000_000) => "subsec_millis", diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index f625058b6703..e37e23b8944d 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -109,7 +109,7 @@ fn check_cond<'a, 'tcx, 'b>( if let ExprKind::AddrOf(BorrowKind::Ref, _, ref key) = params[1].kind; then { let map = ¶ms[0]; - let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(map)); + let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(map)); return if match_type(cx, obj_ty, &paths::BTREEMAP) { Some(("BTreeMap", map, key)) diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index d7819d737ea0..98757624a13b 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -103,8 +103,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { (&ExprKind::Lit(..), _) | (_, &ExprKind::Lit(..)) => {}, // &foo == &bar (&ExprKind::AddrOf(BorrowKind::Ref, _, ref l), &ExprKind::AddrOf(BorrowKind::Ref, _, ref r)) => { - let lty = cx.tables.expr_ty(l); - let rty = cx.tables.expr_ty(r); + let lty = cx.tables().expr_ty(l); + let rty = cx.tables().expr_ty(r); let lcpy = is_copy(cx, lty); let rcpy = is_copy(cx, rty); // either operator autorefs or both args are copyable @@ -126,7 +126,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { ) } else if lcpy && !rcpy - && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right).into()]) + && implements_trait(cx, lty, trait_id, &[cx.tables().expr_ty(right).into()]) { span_lint_and_then( cx, @@ -145,7 +145,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { ) } else if !lcpy && rcpy - && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty.into()]) + && implements_trait(cx, cx.tables().expr_ty(left), trait_id, &[rty.into()]) { span_lint_and_then( cx, @@ -166,10 +166,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { }, // &foo == bar (&ExprKind::AddrOf(BorrowKind::Ref, _, ref l), _) => { - let lty = cx.tables.expr_ty(l); + let lty = cx.tables().expr_ty(l); let lcpy = is_copy(cx, lty); if (requires_ref || lcpy) - && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right).into()]) + && implements_trait(cx, lty, trait_id, &[cx.tables().expr_ty(right).into()]) { span_lint_and_then( cx, @@ -190,10 +190,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { }, // foo == &bar (_, &ExprKind::AddrOf(BorrowKind::Ref, _, ref r)) => { - let rty = cx.tables.expr_ty(r); + let rty = cx.tables().expr_ty(r); let rcpy = is_copy(cx, rty); if (requires_ref || rcpy) - && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty.into()]) + && implements_trait(cx, cx.tables().expr_ty(left), trait_id, &[rty.into()]) { span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |diag| { let rsnip = snippet(cx, r.span, "...").to_string(); diff --git a/clippy_lints/src/erasing_op.rs b/clippy_lints/src/erasing_op.rs index 3ff0506e28d0..804a9c1904b7 100644 --- a/clippy_lints/src/erasing_op.rs +++ b/clippy_lints/src/erasing_op.rs @@ -48,7 +48,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp { } fn check(cx: &LateContext<'_, '_>, e: &Expr<'_>, span: Span) { - if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables, e) { + if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables(), e) { span_lint( cx, ERASING_OP, diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 77e90eeac495..bb74f193a48e 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -84,7 +84,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal { let fn_def_id = cx.tcx.hir().local_def_id(hir_id); cx.tcx.infer_ctxt().enter(|infcx| { - ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.tables).consume_body(body); + ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.tables()).consume_body(body); }); for node in v.set { diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index a889856de274..0ac8b95de8d6 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -97,7 +97,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { // Are the expression or the arguments type-adjusted? Then we need the closure if !(is_adjusted(cx, ex) || args.iter().any(|arg| is_adjusted(cx, arg))); - let fn_ty = cx.tables.expr_ty(caller); + let fn_ty = cx.tables().expr_ty(caller); if matches!(fn_ty.kind, ty::FnDef(_, _) | ty::FnPtr(_) | ty::Closure(_, _)); @@ -128,7 +128,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { // Are the expression or the arguments type-adjusted? Then we need the closure if !(is_adjusted(cx, ex) || args.iter().skip(1).any(|arg| is_adjusted(cx, arg))); - let method_def_id = cx.tables.type_dependent_def_id(ex.hir_id).unwrap(); + let method_def_id = cx.tables().type_dependent_def_id(ex.hir_id).unwrap(); if !type_is_unsafe_function(cx, cx.tcx.type_of(method_def_id)); if compare_inputs(&mut iter_input_pats(decl, body), &mut args.iter()); @@ -153,7 +153,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { /// Tries to determine the type for universal function call to be used instead of the closure fn get_ufcs_type_name(cx: &LateContext<'_, '_>, method_def_id: def_id::DefId, self_arg: &Expr<'_>) -> Option { let expected_type_of_self = &cx.tcx.fn_sig(method_def_id).inputs_and_output().skip_binder()[0]; - let actual_type_of_self = &cx.tables.node_type(self_arg.hir_id); + let actual_type_of_self = &cx.tables().node_type(self_arg.hir_id); if let Some(trait_id) = cx.tcx.trait_of_item(method_def_id) { if match_borrow_depth(expected_type_of_self, &actual_type_of_self) diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 74144fb299de..04af6c2c1f85 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -75,7 +75,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence { if let ExprKind::Path(ref qpath) = lhs.kind { if let QPath::Resolved(_, ref path) = *qpath { if path.segments.len() == 1 { - if let def::Res::Local(var) = cx.tables.qpath_res(qpath, lhs.hir_id) { + if let def::Res::Local(var) = cx.tables().qpath_res(qpath, lhs.hir_id) { let mut visitor = ReadVisitor { cx, var, @@ -137,7 +137,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { match e.kind { ExprKind::Continue(_) | ExprKind::Break(_, _) | ExprKind::Ret(_) => self.report_diverging_sub_expr(e), ExprKind::Call(ref func, _) => { - let typ = self.cx.tables.expr_ty(func); + let typ = self.cx.tables().expr_ty(func); match typ.kind { ty::FnDef(..) | ty::FnPtr(_) => { let sig = typ.fn_sig(self.cx.tcx); @@ -149,7 +149,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { } }, ExprKind::MethodCall(..) => { - let borrowed_table = self.cx.tables; + let borrowed_table = self.cx.tables(); if borrowed_table.expr_ty(e).is_never() { self.report_diverging_sub_expr(e); } @@ -309,7 +309,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> { if_chain! { if let QPath::Resolved(None, ref path) = *qpath; if path.segments.len() == 1; - if let def::Res::Local(local_id) = self.cx.tables.qpath_res(qpath, expr.hir_id); + if let def::Res::Local(local_id) = self.cx.tables().qpath_res(qpath, expr.hir_id); if local_id == self.var; // Check that this is a read, not a write. if !is_in_assignment_position(self.cx, expr); diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index 4c604cd01075..cd3d443ec58e 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -61,7 +61,7 @@ declare_lint_pass!(FloatLiteral => [EXCESSIVE_PRECISION, LOSSY_FLOAT_LITERAL]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FloatLiteral { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { if_chain! { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); if let ty::Float(fty) = ty.kind; if let hir::ExprKind::Lit(ref lit) = expr.kind; if let LitKind::Float(sym, lit_float_ty) = lit.node; diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index ad4f66c52c2c..76713cb1afc4 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -112,7 +112,7 @@ declare_lint_pass!(FloatingPointArithmetic => [ // Returns the specialized log method for a given base if base is constant // and is one of 2, 10 and e fn get_specialized_log_method(cx: &LateContext<'_, '_>, base: &Expr<'_>) -> Option<&'static str> { - if let Some((value, _)) = constant(cx, cx.tables, base) { + if let Some((value, _)) = constant(cx, cx.tables(), base) { if F32(2.0) == value || F64(2.0) == value { return Some("log2"); } else if F32(10.0) == value || F64(10.0) == value { @@ -136,7 +136,7 @@ fn prepare_receiver_sugg<'a>(cx: &LateContext<'_, '_>, mut expr: &'a Expr<'a>) - if_chain! { // if the expression is a float literal and it is unsuffixed then // add a suffix so the suggestion is valid and unambiguous - if let ty::Float(float_ty) = cx.tables.expr_ty(expr).kind; + if let ty::Float(float_ty) = cx.tables().expr_ty(expr).kind; if let ExprKind::Lit(lit) = &expr.kind; if let ast::LitKind::Float(sym, ast::LitFloatType::Unsuffixed) = lit.node; then { @@ -188,7 +188,7 @@ fn check_ln1p(cx: &LateContext<'_, '_>, expr: &Expr<'_>, args: &[Expr<'_>]) { rhs, ) = &args[0].kind { - let recv = match (constant(cx, cx.tables, lhs), constant(cx, cx.tables, rhs)) { + let recv = match (constant(cx, cx.tables(), lhs), constant(cx, cx.tables(), rhs)) { (Some((value, _)), _) if F32(1.0) == value || F64(1.0) == value => rhs, (_, Some((value, _))) if F32(1.0) == value || F64(1.0) == value => lhs, _ => return, @@ -233,7 +233,7 @@ fn get_integer_from_float_constant(value: &Constant) -> Option { fn check_powf(cx: &LateContext<'_, '_>, expr: &Expr<'_>, args: &[Expr<'_>]) { // Check receiver - if let Some((value, _)) = constant(cx, cx.tables, &args[0]) { + if let Some((value, _)) = constant(cx, cx.tables(), &args[0]) { let method = if F32(f32_consts::E) == value || F64(f64_consts::E) == value { "exp" } else if F32(2.0) == value || F64(2.0) == value { @@ -254,7 +254,7 @@ fn check_powf(cx: &LateContext<'_, '_>, expr: &Expr<'_>, args: &[Expr<'_>]) { } // Check argument - if let Some((value, _)) = constant(cx, cx.tables, &args[1]) { + if let Some((value, _)) = constant(cx, cx.tables(), &args[1]) { let (lint, help, suggestion) = if F32(1.0 / 2.0) == value || F64(1.0 / 2.0) == value { ( SUBOPTIMAL_FLOPS, @@ -298,11 +298,11 @@ fn check_powf(cx: &LateContext<'_, '_>, expr: &Expr<'_>, args: &[Expr<'_>]) { fn check_expm1(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Binary(Spanned { node: BinOpKind::Sub, .. }, ref lhs, ref rhs) = expr.kind; - if cx.tables.expr_ty(lhs).is_floating_point(); - if let Some((value, _)) = constant(cx, cx.tables, rhs); + if cx.tables().expr_ty(lhs).is_floating_point(); + if let Some((value, _)) = constant(cx, cx.tables(), rhs); if F32(1.0) == value || F64(1.0) == value; if let ExprKind::MethodCall(ref path, _, ref method_args, _) = lhs.kind; - if cx.tables.expr_ty(&method_args[0]).is_floating_point(); + if cx.tables().expr_ty(&method_args[0]).is_floating_point(); if path.ident.name.as_str() == "exp"; then { span_lint_and_sugg( @@ -324,8 +324,8 @@ fn check_expm1(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { fn is_float_mul_expr<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option<(&'a Expr<'a>, &'a Expr<'a>)> { if_chain! { if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, ref lhs, ref rhs) = &expr.kind; - if cx.tables.expr_ty(lhs).is_floating_point(); - if cx.tables.expr_ty(rhs).is_floating_point(); + if cx.tables().expr_ty(lhs).is_floating_point(); + if cx.tables().expr_ty(rhs).is_floating_point(); then { return Some((lhs, rhs)); } @@ -404,7 +404,7 @@ fn are_exprs_equal(cx: &LateContext<'_, '_>, expr1: &Expr<'_>, expr2: &Expr<'_>) /// Returns true iff expr is some zero literal fn is_zero(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { - match constant_simple(cx, cx.tables, expr) { + match constant_simple(cx, cx.tables(), expr) { Some(Constant::Int(i)) => i == 0, Some(Constant::F32(f)) => f == 0.0, Some(Constant::F64(f)) => f == 0.0, @@ -482,7 +482,7 @@ fn check_custom_abs(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FloatingPointArithmetic { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::MethodCall(ref path, _, args, _) = &expr.kind { - let recv_ty = cx.tables.expr_ty(&args[0]); + let recv_ty = cx.tables().expr_ty(&args[0]); if recv_ty.is_floating_point() { match &*path.ident.name.as_str() { diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 4cae5ca2c432..58cf0027ea4d 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -88,13 +88,13 @@ fn on_argumentv1_new<'a, 'tcx>( // matches `core::fmt::Display::fmt` if args.len() == 2; if let ExprKind::Path(ref qpath) = args[1].kind; - if let Some(did) = cx.tables.qpath_res(qpath, args[1].hir_id).opt_def_id(); + if let Some(did) = cx.tables().qpath_res(qpath, args[1].hir_id).opt_def_id(); if match_def_path(cx, did, &paths::DISPLAY_FMT_METHOD); // check `(arg0,)` in match block if let PatKind::Tuple(ref pats, None) = arms[0].pat.kind; if pats.len() == 1; then { - let ty = walk_ptrs_ty(cx.tables.pat_ty(&pats[0])); + let ty = walk_ptrs_ty(cx.tables().pat_ty(&pats[0])); if ty.kind != rustc_middle::ty::Str && !is_type_diagnostic_item(cx, ty, sym!(string_type)) { return None; } diff --git a/clippy_lints/src/get_last_with_len.rs b/clippy_lints/src/get_last_with_len.rs index 3629ba623ce4..57a7fbb56567 100644 --- a/clippy_lints/src/get_last_with_len.rs +++ b/clippy_lints/src/get_last_with_len.rs @@ -54,7 +54,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for GetLastWithLen { // Argument 0 (the struct we're calling the method on) is a vector if let Some(struct_calling_on) = args.get(0); - let struct_ty = cx.tables.expr_ty(struct_calling_on); + let struct_ty = cx.tables().expr_ty(struct_calling_on); if is_type_diagnostic_item(cx, struct_ty, sym!(vec_type)); // Argument to "get" is a subtraction diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs index 78e07d25f67c..1c25e050997e 100644 --- a/clippy_lints/src/identity_op.rs +++ b/clippy_lints/src/identity_op.rs @@ -62,8 +62,8 @@ fn is_allowed(cx: &LateContext<'_, '_>, cmp: BinOp, left: &Expr<'_>, right: &Exp // `1 << 0` is a common pattern in bit manipulation code if_chain! { if let BinOpKind::Shl = cmp.node; - if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables, right); - if let Some(Constant::Int(1)) = constant_simple(cx, cx.tables, left); + if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables(), right); + if let Some(Constant::Int(1)) = constant_simple(cx, cx.tables(), left); then { return true; } @@ -74,8 +74,8 @@ fn is_allowed(cx: &LateContext<'_, '_>, cmp: BinOp, left: &Expr<'_>, right: &Exp #[allow(clippy::cast_possible_wrap)] fn check(cx: &LateContext<'_, '_>, e: &Expr<'_>, m: i8, span: Span, arg: Span) { - if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables, e) { - let check = match cx.tables.expr_ty(e).kind { + if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables(), e) { + let check = match cx.tables().expr_ty(e).kind { ty::Int(ity) => unsext(cx.tcx, -1_i128, ity), ty::Uint(uty) => clip(cx.tcx, !0, uty), _ => return, diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index 04d17c91d63c..e357c7b3b2eb 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -149,7 +149,7 @@ fn is_mutex_lock_call<'a>(cx: &LateContext<'a, '_>, expr: &'a Expr<'_>) -> Optio if_chain! { if let ExprKind::MethodCall(path, _span, args, _) = &expr.kind; if path.ident.to_string() == "lock"; - let ty = cx.tables.expr_ty(&args[0]); + let ty = cx.tables().expr_ty(&args[0]); if is_type_diagnostic_item(cx, ty, sym!(mutex_type)); then { Some(&args[0]) diff --git a/clippy_lints/src/if_let_some_result.rs b/clippy_lints/src/if_let_some_result.rs index 6a1fcdd1ce44..3f1ae9b86d38 100644 --- a/clippy_lints/src/if_let_some_result.rs +++ b/clippy_lints/src/if_let_some_result.rs @@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OkIfLet { if let ExprKind::MethodCall(_, ok_span, ref result_types, _) = op.kind; //check is expr.ok() has type Result.ok(, _) if let PatKind::TupleStruct(QPath::Resolved(_, ref x), ref y, _) = body[0].pat.kind; //get operation if method_chain_args(op, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized; - if is_type_diagnostic_item(cx, cx.tables.expr_ty(&result_types[0]), sym!(result_type)); + if is_type_diagnostic_item(cx, cx.tables().expr_ty(&result_types[0]), sym!(result_type)); if rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(x, false)) == "Some"; then { diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index c4308fd26a30..5a0531ff749e 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -108,7 +108,7 @@ fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { ExprKind::Call(expr, ..) => { if_chain! { if let ExprKind::Path(qpath) = &expr.kind; - if let Some(path_def_id) = cx.tables.qpath_res(qpath, expr.hir_id).opt_def_id(); + if let Some(path_def_id) = cx.tables().qpath_res(qpath, expr.hir_id).opt_def_id(); if match_def_path(cx, path_def_id, &BEGIN_PANIC) || match_def_path(cx, path_def_id, &BEGIN_PANIC_FMT); then { } diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index fdaf37e5e08f..1a6cb0b0c566 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -81,7 +81,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitSaturatingSub { }; // Check if the variable in the condition statement is an integer - if !cx.tables.expr_ty(cond_var).is_integral() { + if !cx.tables().expr_ty(cond_var).is_integral() { return; } @@ -93,7 +93,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitSaturatingSub { ExprKind::Lit(ref cond_lit) => { // Check if the constant is zero if let LitKind::Int(0, _) = cond_lit.node { - if cx.tables.expr_ty(cond_left).is_signed() { + if cx.tables().expr_ty(cond_left).is_signed() { } else { print_lint_and_sugg(cx, &var_name, expr); }; diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index c5808dd540b6..c5e4abc94a8a 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -88,7 +88,7 @@ declare_lint_pass!(IndexingSlicing => [INDEXING_SLICING, OUT_OF_BOUNDS_INDEXING] impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Index(ref array, ref index) = &expr.kind { - let ty = cx.tables.expr_ty(array); + let ty = cx.tables().expr_ty(array); if let Some(range) = higher::range(cx, index) { // Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..] if let ty::Array(_, s) = ty.kind { @@ -143,7 +143,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing { // Catchall non-range index, i.e., [n] or [n << m] if let ty::Array(..) = ty.kind { // Index is a constant uint. - if let Some(..) = constant(cx, cx.tables, index) { + if let Some(..) = constant(cx, cx.tables(), index) { // Let rustc's `const_err` lint handle constant `usize` indexing on arrays. return; } @@ -169,14 +169,14 @@ fn to_const_range<'a, 'tcx>( range: higher::Range<'_>, array_size: u128, ) -> (Option, Option) { - let s = range.start.map(|expr| constant(cx, cx.tables, expr).map(|(c, _)| c)); + let s = range.start.map(|expr| constant(cx, cx.tables(), expr).map(|(c, _)| c)); let start = match s { Some(Some(Constant::Int(x))) => Some(x), Some(_) => None, None => Some(0), }; - let e = range.end.map(|expr| constant(cx, cx.tables, expr).map(|(c, _)| c)); + let e = range.end.map(|expr| constant(cx, cx.tables(), expr).map(|(c, _)| c)); let end = match e { Some(Some(Constant::Int(x))) => { if range.limits == RangeLimits::Closed { diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index a860a9def242..38f086c9221f 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -230,13 +230,14 @@ fn complete_infinite_iter(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Finitene } } if method.ident.name == sym!(last) && args.len() == 1 { - let not_double_ended = get_trait_def_id(cx, &paths::DOUBLE_ENDED_ITERATOR) - .map_or(false, |id| !implements_trait(cx, cx.tables.expr_ty(&args[0]), id, &[])); + let not_double_ended = get_trait_def_id(cx, &paths::DOUBLE_ENDED_ITERATOR).map_or(false, |id| { + !implements_trait(cx, cx.tables().expr_ty(&args[0]), id, &[]) + }); if not_double_ended { return is_infinite(cx, &args[0]); } } else if method.ident.name == sym!(collect) { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); if INFINITE_COLLECTORS.iter().any(|path| match_type(cx, ty, path)) { return is_infinite(cx, &args[0]); } diff --git a/clippy_lints/src/integer_division.rs b/clippy_lints/src/integer_division.rs index d537ef3f3238..83ae1c1a971e 100644 --- a/clippy_lints/src/integer_division.rs +++ b/clippy_lints/src/integer_division.rs @@ -50,7 +50,7 @@ fn is_integer_division<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Ex if let hir::ExprKind::Binary(binop, left, right) = &expr.kind; if let hir::BinOpKind::Div = &binop.node; then { - let (left_ty, right_ty) = (cx.tables.expr_ty(left), cx.tables.expr_ty(right)); + let (left_ty, right_ty) = (cx.tables().expr_ty(left), cx.tables().expr_ty(right)); return left_ty.is_integral() && right_ty.is_integral(); } } diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index deb57db16789..0301f263489f 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -42,7 +42,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeStackArrays { fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Repeat(_, _) = expr.kind; - if let ty::Array(element_type, cst) = cx.tables.expr_ty(expr).kind; + if let ty::Array(element_type, cst) = cx.tables().expr_ty(expr).kind; if let ConstKind::Value(val) = cst.val; if let ConstValue::Scalar(element_count) = val; if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx); diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 7838e8e8ab77..e17297e96951 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -300,7 +300,7 @@ fn has_is_empty(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { return false; } - let ty = &walk_ptrs_ty(cx.tables.expr_ty(expr)); + let ty = &walk_ptrs_ty(cx.tables().expr_ty(expr)); match ty.kind { ty::Dynamic(ref tt, ..) => { if let Some(principal) = tt.principal() { diff --git a/clippy_lints/src/let_and_return.rs b/clippy_lints/src/let_and_return.rs index 6d3fb317bcfc..299202981b1f 100644 --- a/clippy_lints/src/let_and_return.rs +++ b/clippy_lints/src/let_and_return.rs @@ -100,14 +100,14 @@ struct BorrowVisitor<'a, 'tcx> { impl BorrowVisitor<'_, '_> { fn fn_def_id(&self, expr: &Expr<'_>) -> Option { match &expr.kind { - ExprKind::MethodCall(..) => self.cx.tables.type_dependent_def_id(expr.hir_id), + ExprKind::MethodCall(..) => self.cx.tables().type_dependent_def_id(expr.hir_id), ExprKind::Call( Expr { kind: ExprKind::Path(qpath), .. }, .., - ) => self.cx.tables.qpath_res(qpath, expr.hir_id).opt_def_id(), + ) => self.cx.tables().qpath_res(qpath, expr.hir_id).opt_def_id(), _ => None, } } diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index e097f40f87e4..7b03812b8226 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -73,7 +73,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq { then { let span = stmt.span.to(if_.span); - let has_interior_mutability = !cx.tables.node_type(canonical_id).is_freeze( + let has_interior_mutability = !cx.tables().node_type(canonical_id).is_freeze( cx.tcx.at(span), cx.param_env, ); diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index acd628bbaca5..0864bbe0f912 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore { if let PatKind::Wild = local.pat.kind; if let Some(ref init) = local.init; then { - let init_ty = cx.tables.expr_ty(init); + let init_ty = cx.tables().expr_ty(init); let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() { GenericArgKind::Type(inner_ty) => { SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path)) @@ -94,7 +94,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore { "consider using an underscore-prefixed named \ binding or dropping explicitly with `std::mem::drop`" ) - } else if is_must_use_ty(cx, cx.tables.expr_ty(init)) { + } else if is_must_use_ty(cx, cx.tables().expr_ty(init)) { span_lint_and_help( cx, LET_UNDERSCORE_MUST_USE, diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 318d0b69d57b..6840e82d4bf1 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -343,7 +343,7 @@ impl<'v, 't> RefVisitor<'v, 't> { }) { let hir_id = ty.hir_id; - match self.cx.tables.qpath_res(qpath, hir_id) { + match self.cx.tables().qpath_res(qpath, hir_id) { Res::Def(DefKind::TyAlias | DefKind::Struct, def_id) => { let generics = self.cx.tcx.generics_of(def_id); for _ in generics.params.as_slice() { diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 9c8e8d8fabf4..18b979176a0a 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -535,7 +535,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops { if_chain! { if let ExprKind::MethodCall(..) | ExprKind::Call(..) = iter_expr.kind; if let Some(iter_def_id) = get_trait_def_id(cx, &paths::ITERATOR); - if implements_trait(cx, cx.tables.expr_ty(iter_expr), iter_def_id, &[]); + if implements_trait(cx, cx.tables().expr_ty(iter_expr), iter_def_id, &[]); then { return; } @@ -985,8 +985,8 @@ fn detect_manual_memcpy<'a, 'tcx>( if_chain! { if let ExprKind::Index(seqexpr_left, idx_left) = lhs.kind; if let ExprKind::Index(seqexpr_right, idx_right) = rhs.kind; - if is_slice_like(cx, cx.tables.expr_ty(seqexpr_left)) - && is_slice_like(cx, cx.tables.expr_ty(seqexpr_right)); + if is_slice_like(cx, cx.tables().expr_ty(seqexpr_left)) + && is_slice_like(cx, cx.tables().expr_ty(seqexpr_right)); if let Some(offset_left) = get_offset(cx, &idx_left, canonical_id); if let Some(offset_right) = get_offset(cx, &idx_right, canonical_id); @@ -1254,8 +1254,8 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>, e lint_iter_method(cx, args, arg, method_name); } } else if method_name == "into_iter" && match_trait_method(cx, arg, &paths::INTO_ITERATOR) { - let receiver_ty = cx.tables.expr_ty(&args[0]); - let receiver_ty_adjusted = cx.tables.expr_ty_adjusted(&args[0]); + let receiver_ty = cx.tables().expr_ty(&args[0]); + let receiver_ty_adjusted = cx.tables().expr_ty_adjusted(&args[0]); if TyS::same_type(receiver_ty, receiver_ty_adjusted) { let mut applicability = Applicability::MachineApplicable; let object = snippet_with_applicability(cx, args[0].span, "_", &mut applicability); @@ -1300,7 +1300,7 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>, e /// Checks for `for` loops over `Option`s and `Result`s. fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>) { - let ty = cx.tables.expr_ty(arg); + let ty = cx.tables().expr_ty(arg); if is_type_diagnostic_item(cx, ty, sym!(option_type)) { span_lint_and_help( cx, @@ -1405,7 +1405,7 @@ fn check_for_loop_explicit_counter<'a, 'tcx>( /// actual `Iterator` that the loop uses. fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr<'_>, applic_ref: &mut Applicability) -> String { let impls_iterator = get_trait_def_id(cx, &paths::ITERATOR) - .map_or(false, |id| implements_trait(cx, cx.tables.expr_ty(arg), id, &[])); + .map_or(false, |id| implements_trait(cx, cx.tables().expr_ty(arg), id, &[])); if impls_iterator { format!( "{}", @@ -1416,7 +1416,7 @@ fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr<'_>, applic_ref: & // (&mut x).into_iter() ==> x.iter_mut() match &arg.kind { ExprKind::AddrOf(BorrowKind::Ref, mutability, arg_inner) - if has_iter_method(cx, cx.tables.expr_ty(&arg_inner)).is_some() => + if has_iter_method(cx, cx.tables().expr_ty(&arg_inner)).is_some() => { let meth_name = match mutability { Mutability::Mut => "iter_mut", @@ -1449,7 +1449,7 @@ fn check_for_loop_over_map_kv<'a, 'tcx>( if let PatKind::Tuple(ref pat, _) = pat.kind { if pat.len() == 2 { let arg_span = arg.span; - let (new_pat_span, kind, ty, mutbl) = match cx.tables.expr_ty(arg).kind { + let (new_pat_span, kind, ty, mutbl) = match cx.tables().expr_ty(arg).kind { ty::Ref(_, ty, mutbl) => match (&pat[0].kind, &pat[1].kind) { (key, _) if pat_is_wild(key, body) => (pat[1].span, "value", ty, mutbl), (_, value) if pat_is_wild(value, body) => (pat[0].span, "key", ty, Mutability::Not), @@ -1594,7 +1594,7 @@ fn check_for_mutation<'a, 'tcx>( }; let def_id = body.hir_id.owner.to_def_id(); cx.tcx.infer_ctxt().enter(|infcx| { - ExprUseVisitor::new(&mut delegate, &infcx, def_id.expect_local(), cx.param_env, cx.tables).walk_expr(body); + ExprUseVisitor::new(&mut delegate, &infcx, def_id.expect_local(), cx.param_env, cx.tables()).walk_expr(body); }); delegate.mutation_span() } @@ -1688,7 +1688,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { if index_used_directly { self.indexed_directly.insert( seqvar.segments[0].ident.name, - (Some(extent), self.cx.tables.node_type(seqexpr.hir_id)), + (Some(extent), self.cx.tables().node_type(seqexpr.hir_id)), ); } return false; // no need to walk further *on the variable* @@ -1700,7 +1700,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { if index_used_directly { self.indexed_directly.insert( seqvar.segments[0].ident.name, - (None, self.cx.tables.node_type(seqexpr.hir_id)), + (None, self.cx.tables().node_type(seqexpr.hir_id)), ); } return false; // no need to walk further *on the variable* @@ -1768,7 +1768,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { ExprKind::Call(ref f, args) => { self.visit_expr(f); for expr in args { - let ty = self.cx.tables.expr_ty_adjusted(expr); + let ty = self.cx.tables().expr_ty_adjusted(expr); self.prefer_mutable = false; if let ty::Ref(_, _, mutbl) = ty.kind { if mutbl == Mutability::Mut { @@ -1779,7 +1779,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { } }, ExprKind::MethodCall(_, _, args, _) => { - let def_id = self.cx.tables.type_dependent_def_id(expr.hir_id).unwrap(); + let def_id = self.cx.tables().type_dependent_def_id(expr.hir_id).unwrap(); for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) { self.prefer_mutable = false; if let ty::Ref(_, _, mutbl) = ty.kind { @@ -1866,7 +1866,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> { fn is_ref_iterable_type(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool { // no walk_ptrs_ty: calling iter() on a reference can make sense because it // will allow further borrows afterwards - let ty = cx.tables.expr_ty(e); + let ty = cx.tables().expr_ty(e); is_iterable_array(ty, cx) || is_type_diagnostic_item(cx, ty, sym!(vec_type)) || match_type(cx, ty, &paths::LINKED_LIST) || @@ -2241,7 +2241,7 @@ fn path_name(e: &Expr<'_>) -> Option { } fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) { - if constant(cx, cx.tables, cond).is_some() { + if constant(cx, cx.tables(), cond).is_some() { // A pure constant condition (e.g., `while false`) is not linted. return; } @@ -2377,7 +2377,7 @@ fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'a, ' if let Some(ref generic_args) = chain_method.args; if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0); then { - let ty = cx.tables.node_type(ty.hir_id); + let ty = cx.tables().node_type(ty.hir_id); if is_type_diagnostic_item(cx, ty, sym!(vec_type)) || is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) || match_type(cx, ty, &paths::BTREEMAP) || diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 8f4fdc685ef3..9109de9458f1 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -52,7 +52,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone { if let hir::ExprKind::MethodCall(ref method, _, ref args, _) = e.kind; if args.len() == 2; if method.ident.as_str() == "map"; - let ty = cx.tables.expr_ty(&args[0]); + let ty = cx.tables().expr_ty(&args[0]); if is_type_diagnostic_item(cx, ty, sym!(option_type)) || match_trait_method(cx, e, &paths::ITERATOR); if let hir::ExprKind::Closure(_, _, body_id, _, _) = args[1].kind; let closure_body = cx.tcx.hir().body(body_id); @@ -70,7 +70,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone { match closure_expr.kind { hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner) => { if ident_eq(name, inner) { - if let ty::Ref(.., Mutability::Not) = cx.tables.expr_ty(inner).kind { + if let ty::Ref(.., Mutability::Not) = cx.tables().expr_ty(inner).kind { lint(cx, e.span, args[0].span, true); } } @@ -79,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone { if ident_eq(name, &obj[0]) && method.ident.as_str() == "clone" && match_trait_method(cx, closure_expr, &paths::CLONE_TRAIT) { - let obj_ty = cx.tables.expr_ty(&obj[0]); + let obj_ty = cx.tables().expr_ty(&obj[0]); if let ty::Ref(_, ty, _) = obj_ty.kind { let copy = is_copy(cx, ty); lint(cx, e.span, args[0].span, copy); diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 8f4b674c04f4..a4550f707ee2 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -101,7 +101,7 @@ fn is_unit_type(ty: Ty<'_>) -> bool { } fn is_unit_function(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) -> bool { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); if let ty::FnDef(id, _) = ty.kind { if let Some(fn_type) = cx.tcx.fn_sig(id).no_bound_vars() { @@ -112,7 +112,7 @@ fn is_unit_function(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) -> bool { } fn is_unit_expression(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) -> bool { - is_unit_type(cx.tables.expr_ty(expr)) + is_unit_type(cx.tables().expr_ty(expr)) } /// The expression inside a closure may or may not have surrounding braces and @@ -205,9 +205,9 @@ fn suggestion_msg(function_type: &str, map_type: &str) -> String { fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt<'_>, expr: &hir::Expr<'_>, map_args: &[hir::Expr<'_>]) { let var_arg = &map_args[0]; - let (map_type, variant, lint) = if is_type_diagnostic_item(cx, cx.tables.expr_ty(var_arg), sym!(option_type)) { + let (map_type, variant, lint) = if is_type_diagnostic_item(cx, cx.tables().expr_ty(var_arg), sym!(option_type)) { ("Option", "Some", OPTION_MAP_UNIT_FN) - } else if is_type_diagnostic_item(cx, cx.tables.expr_ty(var_arg), sym!(result_type)) { + } else if is_type_diagnostic_item(cx, cx.tables().expr_ty(var_arg), sym!(result_type)) { ("Result", "Ok", RESULT_MAP_UNIT_FN) } else { return; diff --git a/clippy_lints/src/match_on_vec_items.rs b/clippy_lints/src/match_on_vec_items.rs index ee69628e9f05..4a025e0621f9 100644 --- a/clippy_lints/src/match_on_vec_items.rs +++ b/clippy_lints/src/match_on_vec_items.rs @@ -88,13 +88,13 @@ fn is_vec_indexing<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) } fn is_vector(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); let ty = walk_ptrs_ty(ty); is_type_diagnostic_item(cx, ty, sym!(vec_type)) } fn is_full_range(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); let ty = walk_ptrs_ty(ty); match_type(cx, ty, &utils::paths::RANGE_FULL) } diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 6d7af45a4722..0c91d8885d92 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -540,7 +540,7 @@ fn check_single_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], // allow match arms with just expressions return; }; - let ty = cx.tables.expr_ty(ex); + let ty = cx.tables().expr_ty(ex); if ty.kind != ty::Bool || is_allowed(cx, MATCH_BOOL, ex.hir_id) { check_single_match_single_pattern(cx, ex, arms, expr, els); check_single_match_opt_like(cx, ex, arms, expr, ty, els); @@ -632,7 +632,7 @@ fn check_single_match_opt_like( fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { // Type of expression is `bool`. - if cx.tables.expr_ty(ex).kind == ty::Bool { + if cx.tables().expr_ty(ex).kind == ty::Bool { span_lint_and_then( cx, MATCH_BOOL, @@ -695,8 +695,8 @@ fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], e } fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr<'_>, arms: &'tcx [Arm<'_>]) { - if arms.len() >= 2 && cx.tables.expr_ty(ex).is_integral() { - let ranges = all_ranges(cx, arms, cx.tables.expr_ty(ex)); + if arms.len() >= 2 && cx.tables().expr_ty(ex).is_integral() { + let ranges = all_ranges(cx, arms, cx.tables().expr_ty(ex)); let type_ranges = type_ranges(&ranges); if !type_ranges.is_empty() { if let Some((start, end)) = overlapping(&type_ranges) { @@ -714,7 +714,7 @@ fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr<' } fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { - let ex_ty = walk_ptrs_ty(cx.tables.expr_ty(ex)); + let ex_ty = walk_ptrs_ty(cx.tables().expr_ty(ex)); if is_type_diagnostic_item(cx, ex_ty, sym!(result_type)) { for arm in arms { if let PatKind::TupleStruct(ref path, ref inner, _) = arm.pat.kind { @@ -755,7 +755,7 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) } fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { - let ty = cx.tables.expr_ty(ex); + let ty = cx.tables().expr_ty(ex); if !ty.is_enum() { // If there isn't a nice closed set of possible values that can be conveniently enumerated, // don't complain about not enumerating the mall. @@ -935,8 +935,8 @@ fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], "as_mut" }; - let output_ty = cx.tables.expr_ty(expr); - let input_ty = cx.tables.expr_ty(ex); + let output_ty = cx.tables().expr_ty(expr); + let input_ty = cx.tables().expr_ty(ex); let cast = if_chain! { if let ty::Adt(_, substs) = input_ty.kind; @@ -1006,13 +1006,13 @@ fn check_match_single_binding<'a>(cx: &LateContext<'_, 'a>, ex: &Expr<'a>, arms: match match_body.kind { ExprKind::Block(block, _) => { // macro + expr_ty(body) == () - if block.span.from_expansion() && cx.tables.expr_ty(&match_body).is_unit() { + if block.span.from_expansion() && cx.tables().expr_ty(&match_body).is_unit() { snippet_body.push(';'); } }, _ => { // expr_ty(body) == () - if cx.tables.expr_ty(&match_body).is_unit() { + if cx.tables().expr_ty(&match_body).is_unit() { snippet_body.push(';'); } }, @@ -1111,11 +1111,11 @@ fn all_ranges<'a, 'tcx>( { if let PatKind::Range(ref lhs, ref rhs, range_end) = pat.kind { let lhs = match lhs { - Some(lhs) => constant(cx, cx.tables, lhs)?.0, + Some(lhs) => constant(cx, cx.tables(), lhs)?.0, None => miri_to_const(ty.numeric_min_val(cx.tcx)?)?, }; let rhs = match rhs { - Some(rhs) => constant(cx, cx.tables, rhs)?.0, + Some(rhs) => constant(cx, cx.tables(), rhs)?.0, None => miri_to_const(ty.numeric_max_val(cx.tcx)?)?, }; let rhs = match range_end { @@ -1129,7 +1129,7 @@ fn all_ranges<'a, 'tcx>( } if let PatKind::Lit(ref value) = pat.kind { - let value = constant(cx, cx.tables, value)?.0; + let value = constant(cx, cx.tables(), value)?.0; return Some(SpannedRange { span: pat.span, node: (value.clone(), Bound::Included(value)), diff --git a/clippy_lints/src/mem_discriminant.rs b/clippy_lints/src/mem_discriminant.rs index 3f953655670c..d315c5ef89a8 100644 --- a/clippy_lints/src/mem_discriminant.rs +++ b/clippy_lints/src/mem_discriminant.rs @@ -35,10 +35,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemDiscriminant { if let ExprKind::Call(ref func, ref func_args) = expr.kind; // is `mem::discriminant` if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.tables.qpath_res(func_qpath, func.hir_id).opt_def_id(); + if let Some(def_id) = cx.tables().qpath_res(func_qpath, func.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::MEM_DISCRIMINANT); // type is non-enum - let ty_param = cx.tables.node_substs(func.hir_id).type_at(0); + let ty_param = cx.tables().node_substs(func.hir_id).type_at(0); if !ty_param.is_enum(); then { diff --git a/clippy_lints/src/mem_forget.rs b/clippy_lints/src/mem_forget.rs index c6ddc5de63b0..1821bd9135f9 100644 --- a/clippy_lints/src/mem_forget.rs +++ b/clippy_lints/src/mem_forget.rs @@ -31,7 +31,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemForget { if let ExprKind::Path(ref qpath) = path_expr.kind { if let Some(def_id) = qpath_res(cx, qpath, path_expr.hir_id).opt_def_id() { if match_def_path(cx, def_id, &paths::MEM_FORGET) { - let forgot_ty = cx.tables.expr_ty(&args[0]); + let forgot_ty = cx.tables().expr_ty(&args[0]); if forgot_ty.ty_adt_def().map_or(false, |def| def.has_dtor(cx.tcx)) { span_lint(cx, MEM_FORGET, e.span, "usage of `mem::forget` on `Drop` type"); diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index e2672e02b36d..16d31fc8346e 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -138,7 +138,7 @@ fn check_replace_option_with_none(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { if_chain! { // check if replacement is mem::MaybeUninit::uninit().assume_init() - if let Some(method_def_id) = cx.tables.type_dependent_def_id(src.hir_id); + if let Some(method_def_id) = cx.tables().type_dependent_def_id(src.hir_id); if cx.tcx.is_diagnostic_item(sym::assume_init, method_def_id); then { let mut applicability = Applicability::MachineApplicable; @@ -162,7 +162,7 @@ fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest: &Ex if let ExprKind::Call(ref repl_func, ref repl_args) = src.kind; if repl_args.is_empty(); if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; - if let Some(repl_def_id) = cx.tables.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); + if let Some(repl_def_id) = cx.tables().qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); then { if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, repl_def_id) { let mut applicability = Applicability::MachineApplicable; @@ -179,7 +179,7 @@ fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest: &Ex applicability, ); } else if cx.tcx.is_diagnostic_item(sym::mem_zeroed, repl_def_id) && - !cx.tables.expr_ty(src).is_primitive() { + !cx.tables().expr_ty(src).is_primitive() { span_lint_and_help( cx, MEM_REPLACE_WITH_UNINIT, @@ -198,7 +198,7 @@ fn check_replace_with_default(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest: &E if_chain! { if !in_external_macro(cx.tcx.sess, expr_span); if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; - if let Some(repl_def_id) = cx.tables.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); + if let Some(repl_def_id) = cx.tables().qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); if match_def_path(cx, repl_def_id, &paths::DEFAULT_TRAIT_METHOD); then { span_lint_and_then( @@ -230,7 +230,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace { // Check that `expr` is a call to `mem::replace()` if let ExprKind::Call(ref func, ref func_args) = expr.kind; if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.tables.qpath_res(func_qpath, func.hir_id).opt_def_id(); + if let Some(def_id) = cx.tables().qpath_res(func_qpath, func.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::MEM_REPLACE); if let [dest, src] = &**func_args; then { diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs index 32e86637569e..092702c8b8c7 100644 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/clippy_lints/src/methods/bind_instead_of_map.rs @@ -157,7 +157,7 @@ pub(crate) trait BindInsteadOfMap { /// Lint use of `_.and_then(|x| Some(y))` for `Option`s fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - if !match_type(cx, cx.tables.expr_ty(&args[0]), Self::TYPE_QPATH) { + if !match_type(cx, cx.tables().expr_ty(&args[0]), Self::TYPE_QPATH) { return; } diff --git a/clippy_lints/src/methods/inefficient_to_string.rs b/clippy_lints/src/methods/inefficient_to_string.rs index 06138ab9783c..d29b9adcb7d4 100644 --- a/clippy_lints/src/methods/inefficient_to_string.rs +++ b/clippy_lints/src/methods/inefficient_to_string.rs @@ -11,9 +11,9 @@ use rustc_middle::ty::{self, Ty}; /// Checks for the `INEFFICIENT_TO_STRING` lint pub fn lint<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'tcx>) { if_chain! { - if let Some(to_string_meth_did) = cx.tables.type_dependent_def_id(expr.hir_id); + if let Some(to_string_meth_did) = cx.tables().type_dependent_def_id(expr.hir_id); if match_def_path(cx, to_string_meth_did, &paths::TO_STRING_METHOD); - if let Some(substs) = cx.tables.node_substs_opt(expr.hir_id); + if let Some(substs) = cx.tables().node_substs_opt(expr.hir_id); let self_ty = substs.type_at(0); let (deref_self_ty, deref_count) = walk_ptrs_ty_depth(self_ty); if deref_count >= 1; diff --git a/clippy_lints/src/methods/manual_saturating_arithmetic.rs b/clippy_lints/src/methods/manual_saturating_arithmetic.rs index 4f5c06e785c2..eb02314f4680 100644 --- a/clippy_lints/src/methods/manual_saturating_arithmetic.rs +++ b/clippy_lints/src/methods/manual_saturating_arithmetic.rs @@ -11,7 +11,7 @@ pub fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[&[hir::Expr< let arith_lhs = &args[1][0]; let arith_rhs = &args[1][1]; - let ty = cx.tables.expr_ty(arith_lhs); + let ty = cx.tables().expr_ty(arith_lhs); if !ty.is_integral() { return; } @@ -101,7 +101,7 @@ fn is_min_or_max<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr<'_>) -> Opti } } - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); let ty_str = ty.to_string(); // `std::T::MAX` `std::T::MIN` constants diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index f25a9782813b..c4e707ecf03a 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1433,7 +1433,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { lint_or_fun_call(cx, expr, *method_span, &method_call.ident.as_str(), args); lint_expect_fun_call(cx, expr, *method_span, &method_call.ident.as_str(), args); - let self_ty = cx.tables.expr_ty_adjusted(&args[0]); + let self_ty = cx.tables().expr_ty_adjusted(&args[0]); if args.len() == 1 && method_call.ident.name == sym!(clone) { lint_clone_on_copy(cx, expr, &args[0], self_ty); lint_clone_on_ref_ptr(cx, expr, &args[0]); @@ -1639,7 +1639,7 @@ fn lint_or_fun_call<'a, 'tcx>( if let hir::ExprKind::Path(ref qpath) = fun.kind; let path = &*last_path_segment(qpath).ident.as_str(); if ["default", "new"].contains(&path); - let arg_ty = cx.tables.expr_ty(arg); + let arg_ty = cx.tables().expr_ty(arg); if let Some(default_trait_id) = get_trait_def_id(cx, &paths::DEFAULT_TRAIT); if implements_trait(cx, arg_ty, default_trait_id, &[]); @@ -1679,7 +1679,7 @@ fn lint_or_fun_call<'a, 'tcx>( ) { if let hir::ExprKind::MethodCall(ref path, _, ref args, _) = &arg.kind { if path.ident.as_str() == "len" { - let ty = walk_ptrs_ty(cx.tables.expr_ty(&args[0])); + let ty = walk_ptrs_ty(cx.tables().expr_ty(&args[0])); match ty.kind { ty::Slice(_) | ty::Array(_, _) => return, @@ -1707,7 +1707,7 @@ fn lint_or_fun_call<'a, 'tcx>( if { finder.visit_expr(&arg); finder.found }; if !contains_return(&arg); - let self_ty = cx.tables.expr_ty(self_expr); + let self_ty = cx.tables().expr_ty(self_expr); if let Some(&(_, fn_has_arguments, poss, suffix)) = know_types.iter().find(|&&i| match_type(cx, self_ty, i.0)); @@ -1786,7 +1786,7 @@ fn lint_expect_fun_call( if call_args.len() == 1 && (method_name.ident.name == sym!(as_str) || method_name.ident.name == sym!(as_ref)) && { - let arg_type = cx.tables.expr_ty(&call_args[0]); + let arg_type = cx.tables().expr_ty(&call_args[0]); let base_type = walk_ptrs_ty(arg_type); base_type.kind == ty::Str || is_type_diagnostic_item(cx, base_type, sym!(string_type)) } @@ -1805,7 +1805,7 @@ fn lint_expect_fun_call( // Only `&'static str` or `String` can be used directly in the `panic!`. Other types should be // converted to string. fn requires_to_string(cx: &LateContext<'_, '_>, arg: &hir::Expr<'_>) -> bool { - let arg_ty = cx.tables.expr_ty(arg); + let arg_ty = cx.tables().expr_ty(arg); if is_type_diagnostic_item(cx, arg_ty, sym!(string_type)) { return false; } @@ -1824,7 +1824,7 @@ fn lint_expect_fun_call( hir::ExprKind::Lit(_) => true, hir::ExprKind::Call(fun, _) => { if let hir::ExprKind::Path(ref p) = fun.kind { - match cx.tables.qpath_res(p, fun.hir_id) { + match cx.tables().qpath_res(p, fun.hir_id) { hir::def::Res::Def(hir::def::DefKind::Fn | hir::def::DefKind::AssocFn, def_id) => matches!( cx.tcx.fn_sig(def_id).output().skip_binder().kind, ty::Ref(ty::ReStatic, ..) @@ -1835,13 +1835,16 @@ fn lint_expect_fun_call( false } }, - hir::ExprKind::MethodCall(..) => cx.tables.type_dependent_def_id(arg.hir_id).map_or(false, |method_id| { - matches!( - cx.tcx.fn_sig(method_id).output().skip_binder().kind, - ty::Ref(ty::ReStatic, ..) - ) - }), - hir::ExprKind::Path(ref p) => match cx.tables.qpath_res(p, arg.hir_id) { + hir::ExprKind::MethodCall(..) => cx + .tables() + .type_dependent_def_id(arg.hir_id) + .map_or(false, |method_id| { + matches!( + cx.tcx.fn_sig(method_id).output().skip_binder().kind, + ty::Ref(ty::ReStatic, ..) + ) + }), + hir::ExprKind::Path(ref p) => match cx.tables().qpath_res(p, arg.hir_id) { hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static, _) => true, _ => false, }, @@ -1888,7 +1891,7 @@ fn lint_expect_fun_call( return; } - let receiver_type = cx.tables.expr_ty_adjusted(&args[0]); + let receiver_type = cx.tables().expr_ty_adjusted(&args[0]); let closure_args = if is_type_diagnostic_item(cx, receiver_type, sym!(option_type)) { "||" } else if is_type_diagnostic_item(cx, receiver_type, sym!(result_type)) { @@ -1954,7 +1957,7 @@ fn lint_expect_fun_call( /// Checks for the `CLONE_ON_COPY` lint. fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'_>) { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); if let ty::Ref(_, inner, _) = arg_ty.kind { if let ty::Ref(_, innermost, _) = inner.kind { span_lint_and_then( @@ -2018,11 +2021,11 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &hir: } // x.clone() might have dereferenced x, possibly through Deref impls - if cx.tables.expr_ty(arg) == ty { + if cx.tables().expr_ty(arg) == ty { snip = Some(("try removing the `clone` call", format!("{}", snippet))); } else { let deref_count = cx - .tables + .tables() .expr_adjustments(arg) .iter() .filter(|adj| { @@ -2048,7 +2051,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &hir: } fn lint_clone_on_ref_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>) { - let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(arg)); + let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(arg)); if let ty::Adt(_, subst) = obj_ty.kind { let caller_type = if is_type_diagnostic_item(cx, obj_ty, sym::Rc) { @@ -2082,7 +2085,7 @@ fn lint_string_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hi let arg = &args[1]; if let Some(arglists) = method_chain_args(arg, &["chars"]) { let target = &arglists[0][0]; - let self_ty = walk_ptrs_ty(cx.tables.expr_ty(target)); + let self_ty = walk_ptrs_ty(cx.tables().expr_ty(target)); let ref_str = if self_ty.kind == ty::Str { "" } else if is_type_diagnostic_item(cx, self_ty, sym!(string_type)) { @@ -2110,7 +2113,7 @@ fn lint_string_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hi } fn lint_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&args[0])); + let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&args[0])); if is_type_diagnostic_item(cx, obj_ty, sym!(string_type)) { lint_string_extend(cx, expr, args); } @@ -2118,7 +2121,7 @@ fn lint_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr fn lint_cstring_as_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, source: &hir::Expr<'_>, unwrap: &hir::Expr<'_>) { if_chain! { - let source_type = cx.tables.expr_ty(source); + let source_type = cx.tables().expr_ty(source); if let ty::Adt(def, substs) = source_type.kind; if cx.tcx.is_diagnostic_item(sym!(result_type), def.did); if match_type(cx, substs.type_at(0), &paths::CSTRING); @@ -2142,8 +2145,8 @@ fn lint_iter_cloned_collect<'a, 'tcx>( iter_args: &'tcx [hir::Expr<'_>], ) { if_chain! { - if is_type_diagnostic_item(cx, cx.tables.expr_ty(expr), sym!(vec_type)); - if let Some(slice) = derefs_to_slice(cx, &iter_args[0], cx.tables.expr_ty(&iter_args[0])); + if is_type_diagnostic_item(cx, cx.tables().expr_ty(expr), sym!(vec_type)); + if let Some(slice) = derefs_to_slice(cx, &iter_args[0], cx.tables().expr_ty(&iter_args[0])); if let Some(to_replace) = expr.span.trim_start(slice.span.source_callsite()); then { @@ -2250,7 +2253,7 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, fold_ar fn lint_step_by<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr<'_>, args: &'tcx [hir::Expr<'_>]) { if match_trait_method(cx, expr, &paths::ITERATOR) { - if let Some((Constant::Int(0), _)) = constant(cx, cx.tables, &args[1]) { + if let Some((Constant::Int(0), _)) = constant(cx, cx.tables(), &args[1]) { span_lint( cx, ITERATOR_STEP_BY_ZERO, @@ -2274,7 +2277,7 @@ fn lint_iter_next<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_ parent_expr_opt = get_parent_expr(cx, parent_expr); } - if derefs_to_slice(cx, caller_expr, cx.tables.expr_ty(caller_expr)).is_some() { + if derefs_to_slice(cx, caller_expr, cx.tables().expr_ty(caller_expr)).is_some() { // caller is a Slice if_chain! { if let hir::ExprKind::Index(ref caller_var, ref index_expr) = &caller_expr.kind; @@ -2295,8 +2298,8 @@ fn lint_iter_next<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_ ); } } - } else if is_type_diagnostic_item(cx, cx.tables.expr_ty(caller_expr), sym!(vec_type)) - || matches!(&walk_ptrs_ty(cx.tables.expr_ty(caller_expr)).kind, ty::Array(_, _)) + } else if is_type_diagnostic_item(cx, cx.tables().expr_ty(caller_expr), sym!(vec_type)) + || matches!(&walk_ptrs_ty(cx.tables().expr_ty(caller_expr)).kind, ty::Array(_, _)) { // caller is a Vec or an Array let mut applicability = Applicability::MachineApplicable; @@ -2323,11 +2326,11 @@ fn lint_iter_nth<'a, 'tcx>( ) { let iter_args = nth_and_iter_args[1]; let mut_str = if is_mut { "_mut" } else { "" }; - let caller_type = if derefs_to_slice(cx, &iter_args[0], cx.tables.expr_ty(&iter_args[0])).is_some() { + let caller_type = if derefs_to_slice(cx, &iter_args[0], cx.tables().expr_ty(&iter_args[0])).is_some() { "slice" - } else if is_type_diagnostic_item(cx, cx.tables.expr_ty(&iter_args[0]), sym!(vec_type)) { + } else if is_type_diagnostic_item(cx, cx.tables().expr_ty(&iter_args[0]), sym!(vec_type)) { "Vec" - } else if is_type_diagnostic_item(cx, cx.tables.expr_ty(&iter_args[0]), sym!(vecdeque_type)) { + } else if is_type_diagnostic_item(cx, cx.tables().expr_ty(&iter_args[0]), sym!(vecdeque_type)) { "VecDeque" } else { let nth_args = nth_and_iter_args[0]; @@ -2348,7 +2351,7 @@ fn lint_iter_nth<'a, 'tcx>( fn lint_iter_nth_zero<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr<'_>, nth_args: &'tcx [hir::Expr<'_>]) { if_chain! { if match_trait_method(cx, expr, &paths::ITERATOR); - if let Some((Constant::Int(0), _)) = constant(cx, cx.tables, &nth_args[1]); + if let Some((Constant::Int(0), _)) = constant(cx, cx.tables(), &nth_args[1]); then { let mut applicability = Applicability::MachineApplicable; span_lint_and_sugg( @@ -2373,7 +2376,7 @@ fn lint_get_unwrap<'a, 'tcx>( // Note: we don't want to lint `get_mut().unwrap` for `HashMap` or `BTreeMap`, // because they do not implement `IndexMut` let mut applicability = Applicability::MachineApplicable; - let expr_ty = cx.tables.expr_ty(&get_args[0]); + let expr_ty = cx.tables().expr_ty(&get_args[0]); let get_args_str = if get_args.len() > 1 { snippet_with_applicability(cx, get_args[1].span, "_", &mut applicability) } else { @@ -2479,7 +2482,7 @@ fn derefs_to_slice<'a, 'tcx>( } if let hir::ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind { - if path.ident.name == sym!(iter) && may_slice(cx, cx.tables.expr_ty(&args[0])) { + if path.ident.name == sym!(iter) && may_slice(cx, cx.tables().expr_ty(&args[0])) { Some(&args[0]) } else { None @@ -2502,7 +2505,7 @@ fn derefs_to_slice<'a, 'tcx>( /// lint use of `unwrap()` for `Option`s and `Result`s fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hir::Expr<'_>]) { - let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&unwrap_args[0])); + let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&unwrap_args[0])); let mess = if is_type_diagnostic_item(cx, obj_ty, sym!(option_type)) { Some((UNWRAP_USED, "an Option", "None")) @@ -2530,7 +2533,7 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hi /// lint use of `expect()` for `Option`s and `Result`s fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hir::Expr<'_>]) { - let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&expect_args[0])); + let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&expect_args[0])); let mess = if is_type_diagnostic_item(cx, obj_ty, sym!(option_type)) { Some((EXPECT_USED, "an Option", "None")) @@ -2556,8 +2559,8 @@ fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hi fn lint_ok_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, ok_args: &[hir::Expr<'_>]) { if_chain! { // lint if the caller of `ok()` is a `Result` - if is_type_diagnostic_item(cx, cx.tables.expr_ty(&ok_args[0]), sym!(result_type)); - let result_type = cx.tables.expr_ty(&ok_args[0]); + if is_type_diagnostic_item(cx, cx.tables().expr_ty(&ok_args[0]), sym!(result_type)); + let result_type = cx.tables().expr_ty(&ok_args[0]); if let Some(error_type) = get_error_type(cx, result_type); if has_debug_impl(error_type, cx); @@ -2595,7 +2598,7 @@ fn lint_map_flatten<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr< } // lint if caller of `.map().flatten()` is an Option - if is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_args[0]), sym!(option_type)) { + if is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_args[0]), sym!(option_type)) { let msg = "called `map(..).flatten()` on an `Option`. \ This is more succinctly expressed by calling `.and_then(..)`"; let self_snippet = snippet(cx, map_args[0].span, ".."); @@ -2621,8 +2624,8 @@ fn lint_map_unwrap_or_else<'a, 'tcx>( unwrap_args: &'tcx [hir::Expr<'_>], ) { // lint if the caller of `map()` is an `Option` - let is_option = is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_args[0]), sym!(option_type)); - let is_result = is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_args[0]), sym!(result_type)); + let is_option = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_args[0]), sym!(option_type)); + let is_result = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_args[0]), sym!(result_type)); if is_option || is_result { // Don't make a suggestion that may fail to compile due to mutably borrowing @@ -2676,8 +2679,8 @@ fn lint_map_or_none<'a, 'tcx>( expr: &'tcx hir::Expr<'_>, map_or_args: &'tcx [hir::Expr<'_>], ) { - let is_option = is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_or_args[0]), sym!(option_type)); - let is_result = is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_or_args[0]), sym!(result_type)); + let is_option = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_or_args[0]), sym!(option_type)); + let is_result = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_or_args[0]), sym!(result_type)); // There are two variants of this `map_or` lint: // (1) using `map_or` as an adapter from `Result` to `Option` @@ -3042,7 +3045,7 @@ fn lint_chars_cmp( if segment.ident.name == sym!(Some); then { let mut applicability = Applicability::MachineApplicable; - let self_ty = walk_ptrs_ty(cx.tables.expr_ty_adjusted(&args[0][0])); + let self_ty = walk_ptrs_ty(cx.tables().expr_ty_adjusted(&args[0][0])); if self_ty.kind != ty::Str { return false; @@ -3174,8 +3177,8 @@ fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, call_name: &str, a if match_trait_method(cx, expr, &paths::ASREF_TRAIT) || match_trait_method(cx, expr, &paths::ASMUT_TRAIT) { // check if the type after `as_ref` or `as_mut` is the same as before let recvr = &as_ref_args[0]; - let rcv_ty = cx.tables.expr_ty(recvr); - let res_ty = cx.tables.expr_ty(expr); + let rcv_ty = cx.tables().expr_ty(recvr); + let res_ty = cx.tables().expr_ty(expr); let (base_res_ty, res_depth) = walk_ptrs_ty_depth(res_ty); let (base_rcv_ty, rcv_depth) = walk_ptrs_ty_depth(rcv_ty); if base_rcv_ty == base_res_ty && rcv_depth >= res_depth { @@ -3244,7 +3247,7 @@ fn lint_maybe_uninit(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, outer: &hir if args.is_empty(); if let hir::ExprKind::Path(ref path) = callee.kind; if match_qpath(path, &paths::MEM_MAYBEUNINIT_UNINIT); - if !is_maybe_uninit_ty_valid(cx, cx.tables.expr_ty_adjusted(outer)); + if !is_maybe_uninit_ty_valid(cx, cx.tables().expr_ty_adjusted(outer)); then { span_lint( cx, @@ -3286,7 +3289,7 @@ fn lint_option_as_ref_deref<'a, 'tcx>( ) { let same_mutability = |m| (is_mut && m == &hir::Mutability::Mut) || (!is_mut && m == &hir::Mutability::Not); - let option_ty = cx.tables.expr_ty(&as_ref_args[0]); + let option_ty = cx.tables().expr_ty(&as_ref_args[0]); if !is_type_diagnostic_item(cx, option_ty, sym!(option_type)) { return; } @@ -3314,12 +3317,12 @@ fn lint_option_as_ref_deref<'a, 'tcx>( if_chain! { if args.len() == 1; if let hir::ExprKind::Path(qpath) = &args[0].kind; - if let hir::def::Res::Local(local_id) = cx.tables.qpath_res(qpath, args[0].hir_id); + if let hir::def::Res::Local(local_id) = cx.tables().qpath_res(qpath, args[0].hir_id); if closure_body.params[0].pat.hir_id == local_id; - let adj = cx.tables.expr_adjustments(&args[0]).iter().map(|x| &x.kind).collect::>(); + let adj = cx.tables().expr_adjustments(&args[0]).iter().map(|x| &x.kind).collect::>(); if let [ty::adjustment::Adjust::Deref(None), ty::adjustment::Adjust::Borrow(_)] = *adj; then { - let method_did = cx.tables.type_dependent_def_id(closure_expr.hir_id).unwrap(); + let method_did = cx.tables().type_dependent_def_id(closure_expr.hir_id).unwrap(); deref_aliases.iter().any(|path| match_def_path(cx, method_did, path)) } else { false @@ -3331,7 +3334,7 @@ fn lint_option_as_ref_deref<'a, 'tcx>( if let hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner1) = inner.kind; if let hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner2) = inner1.kind; if let hir::ExprKind::Path(ref qpath) = inner2.kind; - if let hir::def::Res::Local(local_id) = cx.tables.qpath_res(qpath, inner2.hir_id); + if let hir::def::Res::Local(local_id) = cx.tables().qpath_res(qpath, inner2.hir_id); then { closure_body.params[0].pat.hir_id == local_id } else { @@ -3614,7 +3617,7 @@ fn contains_return(expr: &hir::Expr<'_>) -> bool { fn check_pointer_offset(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { if_chain! { if args.len() == 2; - if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.tables.expr_ty(&args[0]).kind; + if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.tables().expr_ty(&args[0]).kind; if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty)); if layout.is_zst(); then { @@ -3624,7 +3627,7 @@ fn check_pointer_offset(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[ } fn lint_filetype_is_file(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - let ty = cx.tables.expr_ty(&args[0]); + let ty = cx.tables().expr_ty(&args[0]); if !match_type(cx, ty, &paths::FILE_TYPE) { return; diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 20c60ef33189..7f4529a5870a 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -20,8 +20,8 @@ pub(super) fn lint<'a, 'tcx>( map_span: Span, ) { // lint if the caller of `map()` is an `Option` - if is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_args[0]), sym!(option_type)) { - if !is_copy(cx, cx.tables.expr_ty(&unwrap_args[1])) { + if is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_args[0]), sym!(option_type)) { + if !is_copy(cx, cx.tables().expr_ty(&unwrap_args[1])) { // Do not lint if the `map` argument uses identifiers in the `map` // argument that are also used in the `unwrap_or` argument diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index 41c9ce7cda3e..88243a88d9dd 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -65,7 +65,7 @@ fn check_expression<'a, 'tcx>( if match_qpath(path, &paths::OPTION_SOME) { if_chain! { if let hir::ExprKind::Path(path) = &args[0].kind; - if let Res::Local(ref local) = cx.tables.qpath_res(path, args[0].hir_id); + if let Res::Local(ref local) = cx.tables().qpath_res(path, args[0].hir_id); then { if arg_id == *local { return (false, false) diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index b02c993de526..8e6f3925d660 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -36,7 +36,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MinMaxPass { } match ( outer_max, - Constant::partial_cmp(cx.tcx, cx.tables.expr_ty(ie), &outer_c, &inner_c), + Constant::partial_cmp(cx.tcx, cx.tables().expr_ty(ie), &outer_c, &inner_c), ) { (_, None) | (MinMax::Max, Some(Ordering::Less)) | (MinMax::Min, Some(Ordering::Greater)) => (), _ => { @@ -62,15 +62,18 @@ enum MinMax { fn min_max<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option<(MinMax, Constant, &'a Expr<'a>)> { if let ExprKind::Call(ref path, ref args) = expr.kind { if let ExprKind::Path(ref qpath) = path.kind { - cx.tables.qpath_res(qpath, path.hir_id).opt_def_id().and_then(|def_id| { - if match_def_path(cx, def_id, &paths::CMP_MIN) { - fetch_const(cx, args, MinMax::Min) - } else if match_def_path(cx, def_id, &paths::CMP_MAX) { - fetch_const(cx, args, MinMax::Max) - } else { - None - } - }) + cx.tables() + .qpath_res(qpath, path.hir_id) + .opt_def_id() + .and_then(|def_id| { + if match_def_path(cx, def_id, &paths::CMP_MIN) { + fetch_const(cx, args, MinMax::Min) + } else if match_def_path(cx, def_id, &paths::CMP_MAX) { + fetch_const(cx, args, MinMax::Max) + } else { + None + } + }) } else { None } @@ -87,14 +90,14 @@ fn fetch_const<'a>( if args.len() != 2 { return None; } - if let Some(c) = constant_simple(cx, cx.tables, &args[0]) { - if constant_simple(cx, cx.tables, &args[1]).is_none() { + if let Some(c) = constant_simple(cx, cx.tables(), &args[0]) { + if constant_simple(cx, cx.tables(), &args[1]).is_none() { // otherwise ignore Some((m, c, &args[1])) } else { None } - } else if let Some(c) = constant_simple(cx, cx.tables, &args[1]) { + } else if let Some(c) = constant_simple(cx, cx.tables(), &args[1]) { Some((m, c, &args[0])) } else { None diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index a0947608e607..99cd864cae4e 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -436,7 +436,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints { binding != "_result" && // FIXME: #944 is_used(cx, expr) && // don't lint if the declaration is in a macro - non_macro_local(cx, cx.tables.qpath_res(qpath, expr.hir_id)) + non_macro_local(cx, cx.tables().qpath_res(qpath, expr.hir_id)) { Some(binding) } else { @@ -496,7 +496,7 @@ fn get_lint_and_message( fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) { if_chain! { if !in_constant(cx, cmp_expr.hir_id); - if let Some((value, _)) = constant(cx, cx.tables, expr); + if let Some((value, _)) = constant(cx, cx.tables(), expr); then { let needs_lint = match value { Constant::F32(num) => num.is_nan(), @@ -517,7 +517,7 @@ fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) { } fn is_named_constant<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> bool { - if let Some((_, res)) = constant(cx, cx.tables, expr) { + if let Some((_, res)) = constant(cx, cx.tables(), expr) { res } else { false @@ -525,7 +525,7 @@ fn is_named_constant<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) } fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> bool { - match constant(cx, cx.tables, expr) { + match constant(cx, cx.tables(), expr) { Some((Constant::F32(f), _)) => f == 0.0 || f.is_infinite(), Some((Constant::F64(f), _)) => f == 0.0 || f.is_infinite(), Some((Constant::Vec(vec), _)) => vec.iter().all(|f| match f { @@ -557,7 +557,7 @@ fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { } fn is_float(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { - let value = &walk_ptrs_ty(cx.tables.expr_ty(expr)).kind; + let value = &walk_ptrs_ty(cx.tables().expr_ty(expr)).kind; if let ty::Array(arr_ty, _) = value { return matches!(arr_ty.kind, ty::Float(_)); @@ -567,14 +567,14 @@ fn is_float(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { } fn is_array(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { - matches!(&walk_ptrs_ty(cx.tables.expr_ty(expr)).kind, ty::Array(_, _)) + matches!(&walk_ptrs_ty(cx.tables().expr_ty(expr)).kind, ty::Array(_, _)) } fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr<'_>, other: &Expr<'_>) { let (arg_ty, snip) = match expr.kind { ExprKind::MethodCall(.., ref args, _) if args.len() == 1 => { if match_trait_method(cx, expr, &paths::TO_STRING) || match_trait_method(cx, expr, &paths::TO_OWNED) { - (cx.tables.expr_ty_adjusted(&args[0]), snippet(cx, args[0].span, "..")) + (cx.tables().expr_ty_adjusted(&args[0]), snippet(cx, args[0].span, "..")) } else { return; } @@ -582,7 +582,7 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr<'_>, other: &Expr<'_>) { ExprKind::Call(ref path, ref v) if v.len() == 1 => { if let ExprKind::Path(ref path) = path.kind { if match_qpath(path, &["String", "from_str"]) || match_qpath(path, &["String", "from"]) { - (cx.tables.expr_ty_adjusted(&v[0]), snippet(cx, v[0].span, "..")) + (cx.tables().expr_ty_adjusted(&v[0]), snippet(cx, v[0].span, "..")) } else { return; } @@ -593,7 +593,7 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr<'_>, other: &Expr<'_>) { _ => return, }; - let other_ty = cx.tables.expr_ty_adjusted(other); + let other_ty = cx.tables().expr_ty_adjusted(other); let partial_eq_trait_id = match cx.tcx.lang_items().eq_trait() { Some(id) => id, None => return, diff --git a/clippy_lints/src/modulo_arithmetic.rs b/clippy_lints/src/modulo_arithmetic.rs index 4ca90455bc4d..f76e4721e1f6 100644 --- a/clippy_lints/src/modulo_arithmetic.rs +++ b/clippy_lints/src/modulo_arithmetic.rs @@ -37,8 +37,8 @@ struct OperandInfo { } fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option { - match constant(cx, cx.tables, operand) { - Some((Constant::Int(v), _)) => match cx.tables.expr_ty(expr).kind { + match constant(cx, cx.tables(), operand) { + Some((Constant::Int(v), _)) => match cx.tables().expr_ty(expr).kind { ty::Int(ity) => { let value = sext(cx.tcx, v, ity); return Some(OperandInfo { @@ -106,7 +106,7 @@ fn check_const_operands<'a, 'tcx>( } fn check_non_const_operands<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, operand: &Expr<'_>) { - let operand_type = cx.tables.expr_ty(operand); + let operand_type = cx.tables().expr_ty(operand); if might_have_negative_value(operand_type) { span_lint_and_then( cx, diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 93569a04f7a3..755b196c698c 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableKeyType { if let hir::PatKind::Wild = local.pat.kind { return; } - check_ty(cx, local.span, cx.tables.pat_ty(&*local.pat)); + check_ty(cx, local.span, cx.tables().pat_ty(&*local.pat)); } } diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index f7a20a74b85e..6aa77b4df83a 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -69,7 +69,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { expr.span, "generally you want to avoid `&mut &mut _` if possible", ); - } else if let ty::Ref(_, _, hir::Mutability::Mut) = self.cx.tables.expr_ty(e).kind { + } else if let ty::Ref(_, _, hir::Mutability::Mut) = self.cx.tables().expr_ty(e).kind { span_lint( self.cx, MUT_MUT, diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 7fcf15f8acbe..dbe257069c3e 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -37,14 +37,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed { check_arguments( cx, arguments, - cx.tables.expr_ty(fn_expr), + cx.tables().expr_ty(fn_expr), &rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false)), ); } }, ExprKind::MethodCall(ref path, _, ref arguments, _) => { - let def_id = cx.tables.type_dependent_def_id(e.hir_id).unwrap(); - let substs = cx.tables.node_substs(e.hir_id); + let def_id = cx.tables().type_dependent_def_id(e.hir_id).unwrap(); + let substs = cx.tables().node_substs(e.hir_id); let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs); check_arguments(cx, arguments, method_type, &path.ident.as_str()) }, diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index 119e0905ff44..45db5140711a 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -135,7 +135,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> { return; }, ExprKind::Path(_) => { - if let Some(adj) = self.cx.tables.adjustments().get(expr.hir_id) { + if let Some(adj) = self.cx.tables().adjustments().get(expr.hir_id) { if adj .iter() .any(|a| matches!(a.target.kind, ty::Ref(_, _, Mutability::Mut))) diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index 78b15afc5a7f..c227dc54f293 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -66,7 +66,7 @@ declare_lint_pass!(Mutex => [MUTEX_ATOMIC, MUTEX_INTEGER]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Mutex { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); if let ty::Adt(_, subst) = ty.kind { if is_type_diagnostic_item(cx, ty, sym!(mutex_type)) { let mutex_param = subst.type_at(0); diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index 15b129fa0980..653f9e2ae862 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -229,7 +229,7 @@ fn check_comparison<'a, 'tcx>( use self::Expression::{Bool, Other}; if let ExprKind::Binary(op, ref left_side, ref right_side) = e.kind { - let (l_ty, r_ty) = (cx.tables.expr_ty(left_side), cx.tables.expr_ty(right_side)); + let (l_ty, r_ty) = (cx.tables().expr_ty(left_side), cx.tables().expr_ty(right_side)); if l_ty.is_bool() && r_ty.is_bool() { let mut applicability = Applicability::MachineApplicable; diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index 5880d1d61020..6bb06defb703 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -46,8 +46,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { return; } if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = e.kind { - if let ty::Ref(..) = cx.tables.expr_ty(inner).kind { - for adj3 in cx.tables.expr_adjustments(e).windows(3) { + if let ty::Ref(..) = cx.tables().expr_ty(inner).kind { + for adj3 in cx.tables().expr_adjustments(e).windows(3) { if let [Adjustment { kind: Adjust::Deref(_), .. }, Adjustment { @@ -85,7 +85,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { } if_chain! { if let PatKind::Binding(BindingAnnotation::Ref, .., name, _) = pat.kind; - if let ty::Ref(_, tam, mutbl) = cx.tables.pat_ty(pat).kind; + if let ty::Ref(_, tam, mutbl) = cx.tables().pat_ty(pat).kind; if mutbl == Mutability::Not; if let ty::Ref(_, _, mutbl) = tam.kind; // only lint immutable refs, because borrowed `&mut T` cannot be moved out diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index ca87deac9891..6954f0cc683f 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -135,7 +135,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { } = { let mut ctx = MovedVariablesCtxt::default(); cx.tcx.infer_ctxt().enter(|infcx| { - euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.tables).consume_body(body); + euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.tables()).consume_body(body); }); ctx }; @@ -173,13 +173,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { !preds.is_empty() && { let ty_empty_region = cx.tcx.mk_imm_ref(cx.tcx.lifetimes.re_root_empty, ty); preds.iter().all(|t| { - let ty_params = &t - .skip_binder() - .trait_ref - .substs - .iter() - .skip(1) - .collect::>(); + let ty_params = &t.skip_binder().trait_ref.substs.iter().skip(1).collect::>(); implements_trait(cx, ty_empty_region, t.def_id(), ty_params) }) }, diff --git a/clippy_lints/src/needless_update.rs b/clippy_lints/src/needless_update.rs index d866bab2f642..9b556dbb8540 100644 --- a/clippy_lints/src/needless_update.rs +++ b/clippy_lints/src/needless_update.rs @@ -47,7 +47,7 @@ declare_lint_pass!(NeedlessUpdate => [NEEDLESS_UPDATE]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessUpdate { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Struct(_, ref fields, Some(ref base)) = expr.kind { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); if let ty::Adt(def, _) = ty.kind { if fields.len() == def.non_enum_variant().fields.len() { span_lint( diff --git a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs index 54536ed57d3e..0f56daa3659e 100644 --- a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs @@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoNegCompOpForPartialOrd { then { - let ty = cx.tables.expr_ty(left); + let ty = cx.tables().expr_ty(left); let implements_ord = { if let Some(id) = utils::get_trait_def_id(cx, &paths::ORD) { diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index 4681e990df88..a9ce01b67b09 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -44,8 +44,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply { fn check_mul(cx: &LateContext<'_, '_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_>) { if_chain! { if let ExprKind::Lit(ref l) = lit.kind; - if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables.expr_ty_opt(lit)); - if cx.tables.expr_ty(exp).is_integral(); + if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables().expr_ty_opt(lit)); + if cx.tables().expr_ty(exp).is_integral(); then { span_lint(cx, NEG_MULTIPLY, span, "Negation by multiplying with `-1`"); } diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 2eacd3c80c48..5fdc656580f2 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -48,7 +48,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { } match expr.kind { ExprKind::Lit(..) | ExprKind::Closure(..) => true, - ExprKind::Path(..) => !has_drop(cx, cx.tables.expr_ty(expr)), + ExprKind::Path(..) => !has_drop(cx, cx.tables().expr_ty(expr)), ExprKind::Index(ref a, ref b) | ExprKind::Binary(_, ref a, ref b) => { has_no_effect(cx, a) && has_no_effect(cx, b) }, @@ -61,7 +61,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { | ExprKind::AddrOf(_, _, ref inner) | ExprKind::Box(ref inner) => has_no_effect(cx, inner), ExprKind::Struct(_, ref fields, ref base) => { - !has_drop(cx, cx.tables.expr_ty(expr)) + !has_drop(cx, cx.tables().expr_ty(expr)) && fields.iter().all(|field| has_no_effect(cx, &field.expr)) && base.as_ref().map_or(true, |base| has_no_effect(cx, base)) }, @@ -70,7 +70,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { let res = qpath_res(cx, qpath, callee.hir_id); match res { Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..) => { - !has_drop(cx, cx.tables.expr_ty(expr)) && args.iter().all(|arg| has_no_effect(cx, arg)) + !has_drop(cx, cx.tables().expr_ty(expr)) && args.iter().all(|arg| has_no_effect(cx, arg)) }, _ => false, } @@ -137,7 +137,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option | ExprKind::AddrOf(_, _, ref inner) | ExprKind::Box(ref inner) => reduce_expression(cx, inner).or_else(|| Some(vec![inner])), ExprKind::Struct(_, ref fields, ref base) => { - if has_drop(cx, cx.tables.expr_ty(expr)) { + if has_drop(cx, cx.tables().expr_ty(expr)) { None } else { Some(fields.iter().map(|f| &f.expr).chain(base).map(Deref::deref).collect()) @@ -148,7 +148,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option let res = qpath_res(cx, qpath, callee.hir_id); match res { Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..) - if !has_drop(cx, cx.tables.expr_ty(expr)) => + if !has_drop(cx, cx.tables().expr_ty(expr)) => { Some(args.iter().collect()) }, diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 230dfd2ebf56..21d7a7439f25 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -237,13 +237,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst { } let ty = if needs_check_adjustment { - let adjustments = cx.tables.expr_adjustments(dereferenced_expr); + let adjustments = cx.tables().expr_adjustments(dereferenced_expr); if let Some(i) = adjustments.iter().position(|adj| match adj.kind { Adjust::Borrow(_) | Adjust::Deref(_) => true, _ => false, }) { if i == 0 { - cx.tables.expr_ty(dereferenced_expr) + cx.tables().expr_ty(dereferenced_expr) } else { adjustments[i - 1].target } @@ -252,7 +252,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst { return; } } else { - cx.tables.expr_ty(dereferenced_expr) + cx.tables().expr_ty(dereferenced_expr) }; verify_ty_bound(cx, ty, Source::Expr { expr: expr.span }); diff --git a/clippy_lints/src/open_options.rs b/clippy_lints/src/open_options.rs index 2d4629b683f0..2467a14cea12 100644 --- a/clippy_lints/src/open_options.rs +++ b/clippy_lints/src/open_options.rs @@ -30,7 +30,7 @@ declare_lint_pass!(OpenOptions => [NONSENSICAL_OPEN_OPTIONS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OpenOptions { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::MethodCall(ref path, _, ref arguments, _) = e.kind { - let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0])); + let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&arguments[0])); if path.ident.name == sym!(open) && match_type(cx, obj_ty, &paths::OPEN_OPTIONS) { let mut options = Vec::new(); get_open_options(cx, &arguments[0], &mut options); @@ -58,7 +58,7 @@ enum OpenOption { fn get_open_options(cx: &LateContext<'_, '_>, argument: &Expr<'_>, options: &mut Vec<(OpenOption, Argument)>) { if let ExprKind::MethodCall(ref path, _, ref arguments, _) = argument.kind { - let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0])); + let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&arguments[0])); // Only proceed if this is a call on some object of type std::fs::OpenOptions if match_type(cx, obj_ty, &paths::OPEN_OPTIONS) && arguments.len() >= 2 { diff --git a/clippy_lints/src/overflow_check_conditional.rs b/clippy_lints/src/overflow_check_conditional.rs index b90fdc232e72..5984b09120d0 100644 --- a/clippy_lints/src/overflow_check_conditional.rs +++ b/clippy_lints/src/overflow_check_conditional.rs @@ -36,8 +36,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional { if let ExprKind::Path(QPath::Resolved(_, ref path2)) = ident2.kind; if let ExprKind::Path(QPath::Resolved(_, ref path3)) = second.kind; if eq(&path1.segments[0], &path3.segments[0]) || eq(&path2.segments[0], &path3.segments[0]); - if cx.tables.expr_ty(ident1).is_integral(); - if cx.tables.expr_ty(ident2).is_integral(); + if cx.tables().expr_ty(ident1).is_integral(); + if cx.tables().expr_ty(ident2).is_integral(); then { if let BinOpKind::Lt = op.node { if let BinOpKind::Add = op2.node { @@ -61,8 +61,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional { if let ExprKind::Path(QPath::Resolved(_, ref path2)) = ident2.kind; if let ExprKind::Path(QPath::Resolved(_, ref path3)) = first.kind; if eq(&path1.segments[0], &path3.segments[0]) || eq(&path2.segments[0], &path3.segments[0]); - if cx.tables.expr_ty(ident1).is_integral(); - if cx.tables.expr_ty(ident2).is_integral(); + if cx.tables().expr_ty(ident1).is_integral(); + if cx.tables().expr_ty(ident2).is_integral(); then { if let BinOpKind::Gt = op.node { if let BinOpKind::Add = op2.node { diff --git a/clippy_lints/src/path_buf_push_overwrite.rs b/clippy_lints/src/path_buf_push_overwrite.rs index 88ad1e0914f2..f26a5258782a 100644 --- a/clippy_lints/src/path_buf_push_overwrite.rs +++ b/clippy_lints/src/path_buf_push_overwrite.rs @@ -46,7 +46,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathBufPushOverwrite { if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; if path.ident.name == sym!(push); if args.len() == 2; - if match_type(cx, walk_ptrs_ty(cx.tables.expr_ty(&args[0])), &paths::PATH_BUF); + if match_type(cx, walk_ptrs_ty(cx.tables().expr_ty(&args[0])), &paths::PATH_BUF); if let Some(get_index_arg) = args.get(1); if let ExprKind::Lit(ref lit) = get_index_arg.kind; if let LitKind::Str(ref path_lit, _) = lit.node; diff --git a/clippy_lints/src/ptr_offset_with_cast.rs b/clippy_lints/src/ptr_offset_with_cast.rs index d23d7e59b73f..b35a7e64bff2 100644 --- a/clippy_lints/src/ptr_offset_with_cast.rs +++ b/clippy_lints/src/ptr_offset_with_cast.rs @@ -105,12 +105,12 @@ fn expr_as_ptr_offset_call<'a, 'tcx>( // Is the type of the expression a usize? fn is_expr_ty_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool { - cx.tables.expr_ty(expr) == cx.tcx.types.usize + cx.tables().expr_ty(expr) == cx.tcx.types.usize } // Is the type of the expression a raw pointer? fn is_expr_ty_raw_ptr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool { - cx.tables.expr_ty(expr).is_unsafe_ptr() + cx.tables().expr_ty(expr).is_unsafe_ptr() } fn build_suggestion<'a, 'tcx>( diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index d8a73f8054bc..4a6395da01c9 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -135,13 +135,13 @@ impl QuestionMark { } fn moves_by_default(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool { - let expr_ty = cx.tables.expr_ty(expression); + let expr_ty = cx.tables().expr_ty(expression); !expr_ty.is_copy_modulo_regions(cx.tcx.at(expression.span), cx.param_env) } fn is_option(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool { - let expr_ty = cx.tables.expr_ty(expression); + let expr_ty = cx.tables().expr_ty(expression); is_type_diagnostic_item(cx, expr_ty, sym!(option_type)) } @@ -158,7 +158,7 @@ impl QuestionMark { ExprKind::Ret(Some(ref expr)) => Self::expression_returns_none(cx, expr), ExprKind::Path(ref qp) => { if let Res::Def(DefKind::Ctor(def::CtorOf::Variant, def::CtorKind::Const), def_id) = - cx.tables.qpath_res(qp, expression.hir_id) + cx.tables().qpath_res(qp, expression.hir_id) { return match_def_path(cx, def_id, &paths::OPTION_NONE); } diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index fcd02a196e7b..43ef236a9242 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -272,10 +272,10 @@ fn check_reversed_empty_range(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { if let Some(higher::Range { start: Some(start), end: Some(end), limits }) = higher::range(cx, expr); - let ty = cx.tables.expr_ty(start); + let ty = cx.tables().expr_ty(start); if let ty::Int(_) | ty::Uint(_) = ty.kind; - if let Some((start_idx, _)) = constant(cx, cx.tables, start); - if let Some((end_idx, _)) = constant(cx, cx.tables, end); + if let Some((start_idx, _)) = constant(cx, cx.tables(), start); + if let Some((end_idx, _)) = constant(cx, cx.tables(), end); if let Some(ordering) = Constant::partial_cmp(cx.tcx, ty, &start_idx, &end_idx); if is_empty_range(limits, ordering); then { diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index a2c35c426734..9c54c3cbac02 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -82,7 +82,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex { if_chain! { if self.last.is_none(); if let Some(ref expr) = block.expr; - if match_type(cx, cx.tables.expr_ty(expr), &paths::REGEX); + if match_type(cx, cx.tables().expr_ty(expr), &paths::REGEX); if let Some(span) = is_expn_of(expr.span, "regex"); then { if !self.spans.contains(&span) { @@ -111,7 +111,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex { if let ExprKind::Call(ref fun, ref args) = expr.kind; if let ExprKind::Path(ref qpath) = fun.kind; if args.len() == 1; - if let Some(def_id) = cx.tables.qpath_res(qpath, fun.hir_id).opt_def_id(); + if let Some(def_id) = cx.tables().qpath_res(qpath, fun.hir_id).opt_def_id(); then { if match_def_path(cx, def_id, &paths::REGEX_NEW) || match_def_path(cx, def_id, &paths::REGEX_BUILDER_NEW) { @@ -140,7 +140,7 @@ fn str_span(base: Span, c: regex_syntax::ast::Span, offset: u16) -> Span { } fn const_str<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) -> Option { - constant(cx, cx.tables, e).and_then(|(c, _)| match c { + constant(cx, cx.tables(), e).and_then(|(c, _)| match c { Constant::Str(s) => Some(s), _ => None, }) diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 68c36f918918..4780249bcb8e 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -164,7 +164,7 @@ fn check_local<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, local: &'tcx Local<'_>, bin } fn is_binding(cx: &LateContext<'_, '_>, pat_id: HirId) -> bool { - let var_ty = cx.tables.node_type_opt(pat_id); + let var_ty = cx.tables().node_type_opt(pat_id); if let Some(var_ty) = var_ty { match var_ty.kind { ty::Adt(..) => false, diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index d8e4bff3d702..ef66850358e5 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -134,7 +134,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringAdd { } fn is_string(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool { - is_type_diagnostic_item(cx, walk_ptrs_ty(cx.tables.expr_ty(e)), sym!(string_type)) + is_type_diagnostic_item(cx, walk_ptrs_ty(cx.tables().expr_ty(e)), sym!(string_type)) } fn is_add(cx: &LateContext<'_, '_>, src: &Expr<'_>, target: &Expr<'_>) -> bool { diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index c52e6a643f2a..7fdc872c01f5 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -194,7 +194,7 @@ fn check_for_slice<'a>(cx: &LateContext<'_, '_>, lhs1: &'a Expr<'_>, lhs2: &'a E if let ExprKind::Index(ref lhs1, ref idx1) = lhs1.kind { if let ExprKind::Index(ref lhs2, ref idx2) = lhs2.kind { if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs1, lhs2) { - let ty = walk_ptrs_ty(cx.tables.expr_ty(lhs1)); + let ty = walk_ptrs_ty(cx.tables().expr_ty(lhs1)); if matches!(ty.kind, ty::Slice(_)) || matches!(ty.kind, ty::Array(_, _)) diff --git a/clippy_lints/src/temporary_assignment.rs b/clippy_lints/src/temporary_assignment.rs index bbb883aaf328..f2bbf19bea92 100644 --- a/clippy_lints/src/temporary_assignment.rs +++ b/clippy_lints/src/temporary_assignment.rs @@ -26,7 +26,7 @@ fn is_temporary(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { match &expr.kind { ExprKind::Struct(..) | ExprKind::Tup(..) => true, ExprKind::Path(qpath) => { - if let Res::Def(DefKind::Const, ..) = cx.tables.qpath_res(qpath, expr.hir_id) { + if let Res::Def(DefKind::Const, ..) = cx.tables().qpath_res(qpath, expr.hir_id) { true } else { false diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs index 4f132c6db76f..1efba3580fef 100644 --- a/clippy_lints/src/to_digit_is_some.rs +++ b/clippy_lints/src/to_digit_is_some.rs @@ -43,7 +43,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ToDigitIsSome { if_chain! { if let [char_arg, radix_arg] = &**to_digit_args; if to_digits_path.ident.name.as_str() == "to_digit"; - let char_arg_ty = cx.tables.expr_ty_adjusted(char_arg); + let char_arg_ty = cx.tables().expr_ty_adjusted(char_arg); if char_arg_ty.kind == ty::Char; then { Some((true, char_arg, radix_arg)) @@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ToDigitIsSome { if_chain! { if let [char_arg, radix_arg] = &**to_digit_args; if let hir::ExprKind::Path(to_digits_path) = &to_digits_call.kind; - if let to_digits_call_res = cx.tables.qpath_res(to_digits_path, to_digits_call.hir_id); + if let to_digits_call_res = cx.tables().qpath_res(to_digits_path, to_digits_call.hir_id); if let Some(to_digits_def_id) = to_digits_call_res.opt_def_id(); if match_def_path(cx, to_digits_def_id, &["core", "char", "methods", "", "to_digit"]); then { diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 67121729663c..1b233b8302f9 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -37,7 +37,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TraitBounds { return; } let hash = |ty| -> u64 { - let mut hasher = SpanlessHash::new(cx, cx.tables); + let mut hasher = SpanlessHash::new(cx, cx.tables()); hasher.hash_ty(ty); hasher.finish() }; diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 1869638f6ffb..9b1344949470 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -299,11 +299,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { if_chain! { if let ExprKind::Call(ref path_expr, ref args) = e.kind; if let ExprKind::Path(ref qpath) = path_expr.kind; - if let Some(def_id) = cx.tables.qpath_res(qpath, path_expr.hir_id).opt_def_id(); + if let Some(def_id) = cx.tables().qpath_res(qpath, path_expr.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::TRANSMUTE); then { - let from_ty = cx.tables.expr_ty(&args[0]); - let to_ty = cx.tables.expr_ty(e); + let from_ty = cx.tables().expr_ty(&args[0]); + let to_ty = cx.tables().expr_ty(e); match (&from_ty.kind, &to_ty.kind) { _ if from_ty == to_ty => span_lint( diff --git a/clippy_lints/src/transmuting_null.rs b/clippy_lints/src/transmuting_null.rs index 1d0332c58050..3351488a45c4 100644 --- a/clippy_lints/src/transmuting_null.rs +++ b/clippy_lints/src/transmuting_null.rs @@ -44,7 +44,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull { then { // Catching transmute over constants that resolve to `null`. - let mut const_eval_context = constant_context(cx, cx.tables); + let mut const_eval_context = constant_context(cx, cx.tables()); if_chain! { if let ExprKind::Path(ref _qpath) = args[0].kind; let x = const_eval_context.expr(&args[0]); diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs index 7018fa6804ba..e129dd84d15a 100644 --- a/clippy_lints/src/try_err.rs +++ b/clippy_lints/src/try_err.rs @@ -68,7 +68,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TryErr { if let Some(return_type) = find_err_return_type(cx, &expr.kind); then { - let err_type = cx.tables.expr_ty(err_arg); + let err_type = cx.tables().expr_ty(err_arg); let origin_snippet = if err_arg.span.from_expansion() { snippet_with_macro_callsite(cx, err_arg.span, "_") } else { @@ -114,7 +114,7 @@ fn find_err_return_type_arm<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arm: &'tcx Arm if match_qpath(from_error_fn, &paths::TRY_FROM_ERROR); if let Some(from_error_arg) = from_error_args.get(0); then { - Some(cx.tables.expr_ty(from_error_arg)) + Some(cx.tables().expr_ty(from_error_arg)) } else { None } diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 98de08f79f3d..ecfb6ee2a7de 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -603,7 +603,7 @@ declare_lint_pass!(LetUnitValue => [LET_UNIT_VALUE]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnitValue { fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) { if let StmtKind::Local(ref local) = stmt.kind { - if is_unit(cx.tables.pat_ty(&local.pat)) { + if is_unit(cx.tables().pat_ty(&local.pat)) { if in_external_macro(cx.sess(), stmt.span) || local.pat.span.from_expansion() { return; } @@ -688,7 +688,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitCmp { if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind { if let ExprKind::Binary(ref cmp, ref left, _) = expr.kind { let op = cmp.node; - if op.is_comparison() && is_unit(cx.tables.expr_ty(left)) { + if op.is_comparison() && is_unit(cx.tables().expr_ty(left)) { let result = match &*symbol.as_str() { "assert_eq" | "debug_assert_eq" => "succeed", "assert_ne" | "debug_assert_ne" => "fail", @@ -712,7 +712,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitCmp { } if let ExprKind::Binary(ref cmp, ref left, _) = expr.kind { let op = cmp.node; - if op.is_comparison() && is_unit(cx.tables.expr_ty(left)) { + if op.is_comparison() && is_unit(cx.tables().expr_ty(left)) { let result = match op { BinOpKind::Eq | BinOpKind::Le | BinOpKind::Ge => "true", _ => "false", @@ -782,7 +782,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg { let args_to_recover = args .iter() .filter(|arg| { - if is_unit(cx.tables.expr_ty(arg)) && !is_unit_literal(arg) { + if is_unit(cx.tables().expr_ty(arg)) && !is_unit_literal(arg) { if let ExprKind::Match(.., MatchSource::TryDesugar) = &arg.kind { false } else { @@ -1250,7 +1250,7 @@ fn check_loss_of_sign(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>, } // don't lint for positive constants - let const_val = constant(cx, &cx.tables, op); + let const_val = constant(cx, &cx.tables(), op); if_chain! { if let Some((const_val, _)) = const_val; if let Constant::Int(n) = const_val; @@ -1416,7 +1416,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts { return; } if let ExprKind::Cast(ref ex, _) = expr.kind { - let (cast_from, cast_to) = (cx.tables.expr_ty(ex), cx.tables.expr_ty(expr)); + let (cast_from, cast_to) = (cx.tables().expr_ty(ex), cx.tables().expr_ty(expr)); lint_fn_to_numeric_cast(cx, expr, ex, cast_from, cast_to); if let ExprKind::Lit(ref lit) = ex.kind { if_chain! { @@ -1804,7 +1804,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CharLitAsU8 { if let ExprKind::Cast(e, _) = &expr.kind; if let ExprKind::Lit(l) = &e.kind; if let LitKind::Char(c) = l.node; - if ty::Uint(UintTy::U8) == cx.tables.expr_ty(expr).kind; + if ty::Uint(UintTy::U8) == cx.tables().expr_ty(expr).kind; then { let mut applicability = Applicability::MachineApplicable; let snippet = snippet_with_applicability(cx, e.span, "'x'", &mut applicability); @@ -1880,8 +1880,8 @@ enum AbsurdComparisonResult { fn is_cast_between_fixed_and_target<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) -> bool { if let ExprKind::Cast(ref cast_exp, _) = expr.kind { - let precast_ty = cx.tables.expr_ty(cast_exp); - let cast_ty = cx.tables.expr_ty(expr); + let precast_ty = cx.tables().expr_ty(cast_exp); + let cast_ty = cx.tables().expr_ty(expr); return is_isize_or_usize(precast_ty) != is_isize_or_usize(cast_ty); } @@ -1901,7 +1901,7 @@ fn detect_absurd_comparison<'a, 'tcx>( // absurd comparison only makes sense on primitive types // primitive types don't implement comparison operators with each other - if cx.tables.expr_ty(lhs) != cx.tables.expr_ty(rhs) { + if cx.tables().expr_ty(lhs) != cx.tables().expr_ty(rhs) { return None; } @@ -1939,9 +1939,9 @@ fn detect_absurd_comparison<'a, 'tcx>( fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option> { use crate::types::ExtremeType::{Maximum, Minimum}; - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); - let cv = constant(cx, cx.tables, expr)?.0; + let cv = constant(cx, cx.tables(), expr)?.0; let which = match (&ty.kind, cv) { (&ty::Bool, Constant::Bool(false)) | (&ty::Uint(_), Constant::Int(0)) => Minimum, @@ -2071,8 +2071,8 @@ impl Ord for FullInt { fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'_>) -> Option<(FullInt, FullInt)> { if let ExprKind::Cast(ref cast_exp, _) = expr.kind { - let pre_cast_ty = cx.tables.expr_ty(cast_exp); - let cast_ty = cx.tables.expr_ty(expr); + let pre_cast_ty = cx.tables().expr_ty(cast_exp); + let cast_ty = cx.tables().expr_ty(expr); // if it's a cast from i32 to u32 wrapping will invalidate all these checks if cx.layout_of(pre_cast_ty).ok().map(|l| l.size) == cx.layout_of(cast_ty).ok().map(|l| l.size) { return None; @@ -2102,9 +2102,9 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'_>) } fn node_as_const_fullint<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option { - let val = constant(cx, cx.tables, expr)?.0; + let val = constant(cx, cx.tables(), expr)?.0; if let Constant::Int(const_int) = val { - match cx.tables.expr_ty(expr).kind { + match cx.tables().expr_ty(expr).kind { ty::Int(ity) => Some(FullInt::S(sext(cx.tcx, const_int, ity))), ty::Uint(_) => Some(FullInt::U(const_int)), _ => None, @@ -2499,7 +2499,7 @@ impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { fn new(cx: &'a LateContext<'a, 'tcx>, target: &'b ImplicitHasherType<'tcx>) -> Self { Self { cx, - body: cx.tables, + body: cx.tables(), target, suggestions: BTreeMap::new(), } @@ -2608,7 +2608,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RefToMut { if let TyKind::Ptr(MutTy { mutbl: Mutability::Mut, .. }) = t.kind; if let ExprKind::Cast(e, t) = &e.kind; if let TyKind::Ptr(MutTy { mutbl: Mutability::Not, .. }) = t.kind; - if let ty::Ref(..) = cx.tables.node_type(e.hir_id).kind; + if let ty::Ref(..) = cx.tables().node_type(e.hir_id).kind; then { span_lint( cx, diff --git a/clippy_lints/src/unnamed_address.rs b/clippy_lints/src/unnamed_address.rs index 4e077b95b5c6..53e47f09ae55 100644 --- a/clippy_lints/src/unnamed_address.rs +++ b/clippy_lints/src/unnamed_address.rs @@ -65,14 +65,14 @@ impl LateLintPass<'_, '_> for UnnamedAddress { } fn is_trait_ptr(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { - match cx.tables.expr_ty_adjusted(expr).kind { + match cx.tables().expr_ty_adjusted(expr).kind { ty::RawPtr(ty::TypeAndMut { ty, .. }) => ty.is_trait(), _ => false, } } fn is_fn_def(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { - if let ty::FnDef(..) = cx.tables.expr_ty(expr).kind { + if let ty::FnDef(..) = cx.tables().expr_ty(expr).kind { true } else { false @@ -98,11 +98,11 @@ impl LateLintPass<'_, '_> for UnnamedAddress { if_chain! { if let ExprKind::Call(ref func, [ref _left, ref _right]) = expr.kind; if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.tables.qpath_res(func_qpath, func.hir_id).opt_def_id(); + if let Some(def_id) = cx.tables().qpath_res(func_qpath, func.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::PTR_EQ) || match_def_path(cx, def_id, &paths::RC_PTR_EQ) || match_def_path(cx, def_id, &paths::ARC_PTR_EQ); - let ty_param = cx.tables.node_substs(func.hir_id).type_at(0); + let ty_param = cx.tables().node_substs(func.hir_id).type_at(0); if ty_param.is_trait(); then { span_lint_and_help( @@ -119,8 +119,8 @@ impl LateLintPass<'_, '_> for UnnamedAddress { if_chain! { if let ExprKind::Binary(binop, ref left, ref right) = expr.kind; if is_comparison(binop.node); - if cx.tables.expr_ty_adjusted(left).is_fn_ptr() && - cx.tables.expr_ty_adjusted(right).is_fn_ptr(); + if cx.tables().expr_ty_adjusted(left).is_fn_ptr() && + cx.tables().expr_ty_adjusted(right).is_fn_ptr(); if is_fn_def(cx, left) || is_fn_def(cx, right); then { span_lint( diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index 6ac6a12529c8..bb68e50b3319 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -177,7 +177,7 @@ fn detect_lint(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option if let name = name_ident.ident.name.to_ident_string(); if name == "sort_by" || name == "sort_unstable_by"; if let [vec, Expr { kind: ExprKind::Closure(_, _, closure_body_id, _, _), .. }] = args; - if utils::match_type(cx, &cx.tables.expr_ty(vec), &paths::VEC); + if utils::match_type(cx, &cx.tables().expr_ty(vec), &paths::VEC); if let closure_body = cx.tcx.hir().body(*closure_body_id); if let &[ Param { pat: Pat { kind: PatKind::Binding(_, _, left_ident, _), .. }, ..}, diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index a6c7b5d405cd..be55982f9055 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -114,7 +114,7 @@ fn collect_unwrap_info<'a, 'tcx>( if_chain! { if let ExprKind::MethodCall(method_name, _, args, _) = &expr.kind; if let ExprKind::Path(QPath::Resolved(None, path)) = &args[0].kind; - let ty = cx.tables.expr_ty(&args[0]); + let ty = cx.tables().expr_ty(&args[0]); let name = method_name.ident.as_str(); if is_relevant_option_call(cx, ty, &name) || is_relevant_result_call(cx, ty, &name); then { diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 78d249482d53..5d150ad4f03e 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -63,8 +63,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion { ExprKind::MethodCall(ref name, .., ref args, _) => { if match_trait_method(cx, e, &paths::INTO) && &*name.ident.as_str() == "into" { - let a = cx.tables.expr_ty(e); - let b = cx.tables.expr_ty(&args[0]); + let a = cx.tables().expr_ty(e); + let b = cx.tables().expr_ty(&args[0]); if TyS::same_type(a, b) { let sugg = snippet_with_macro_callsite(cx, args[0].span, "").to_string(); span_lint_and_sugg( @@ -79,8 +79,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion { } } if match_trait_method(cx, e, &paths::INTO_ITERATOR) && &*name.ident.as_str() == "into_iter" { - let a = cx.tables.expr_ty(e); - let b = cx.tables.expr_ty(&args[0]); + let a = cx.tables().expr_ty(e); + let b = cx.tables().expr_ty(&args[0]); if TyS::same_type(a, b) { let sugg = snippet(cx, args[0].span, "").into_owned(); span_lint_and_sugg( @@ -96,8 +96,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion { } if match_trait_method(cx, e, &paths::TRY_INTO_TRAIT) && &*name.ident.as_str() == "try_into" { if_chain! { - let a = cx.tables.expr_ty(e); - let b = cx.tables.expr_ty(&args[0]); + let a = cx.tables().expr_ty(e); + let b = cx.tables().expr_ty(&args[0]); if is_type_diagnostic_item(cx, a, sym!(result_type)); if let ty::Adt(_, substs) = a.kind; if let Some(a_type) = substs.types().next(); @@ -121,9 +121,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion { if_chain! { if args.len() == 1; if let ExprKind::Path(ref qpath) = path.kind; - if let Some(def_id) = cx.tables.qpath_res(qpath, path.hir_id).opt_def_id(); - let a = cx.tables.expr_ty(e); - let b = cx.tables.expr_ty(&args[0]); + if let Some(def_id) = cx.tables().qpath_res(qpath, path.hir_id).opt_def_id(); + let a = cx.tables().expr_ty(e); + let b = cx.tables().expr_ty(&args[0]); then { if_chain! { diff --git a/clippy_lints/src/utils/higher.rs b/clippy_lints/src/utils/higher.rs index 33fba7df8d33..0e78f35a1290 100644 --- a/clippy_lints/src/utils/higher.rs +++ b/clippy_lints/src/utils/higher.rs @@ -56,7 +56,7 @@ pub fn range<'a, 'b, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'b hir::Expr<'_>) Some(expr) } - let def_path = match cx.tables.expr_ty(expr).kind { + let def_path = match cx.tables().expr_ty(expr).kind { ty::Adt(def, _) => cx.tcx.def_path(def.did), _ => return None, }; @@ -262,7 +262,7 @@ pub fn vec_macro<'e>(cx: &LateContext<'_, '_>, expr: &'e hir::Expr<'_>) -> Optio if let hir::ExprKind::Call(ref fun, ref args) = expr.kind; if let hir::ExprKind::Path(ref qpath) = fun.kind; if is_expn_of(fun.span, "vec").is_some(); - if let Some(fun_def_id) = cx.tables.qpath_res(qpath, fun.hir_id).opt_def_id(); + if let Some(fun_def_id) = cx.tables().qpath_res(qpath, fun.hir_id).opt_def_id(); then { return if match_def_path(cx, fun_def_id, &paths::VEC_FROM_ELEM) && args.len() == 2 { // `vec![elem; size]` case diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index 9a9aa3f94eb4..a74ab18a063b 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -32,7 +32,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { pub fn new(cx: &'a LateContext<'a, 'tcx>) -> Self { Self { cx, - tables: cx.tables, + tables: cx.tables(), ignore_fn: false, } } @@ -40,7 +40,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { pub fn ignore_fn(self) -> Self { Self { cx: self.cx, - tables: self.cx.tables, + tables: self.cx.tables(), ignore_fn: true, } } diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index afde971f9df4..3f5659c3d8c0 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -114,7 +114,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DeepCodeInspector { } match stmt.kind { hir::StmtKind::Local(ref local) => { - println!("local variable of type {}", cx.tables.node_type(local.hir_id)); + println!("local variable of type {}", cx.tables().node_type(local.hir_id)); println!("pattern:"); print_pat(cx, &local.pat, 0); if let Some(ref e) = local.init { @@ -144,8 +144,8 @@ fn has_attr(sess: &Session, attrs: &[Attribute]) -> bool { fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, indent: usize) { let ind = " ".repeat(indent); println!("{}+", ind); - println!("{}ty: {}", ind, cx.tables.expr_ty(expr)); - println!("{}adjustments: {:?}", ind, cx.tables.adjustments().get(expr.hir_id)); + println!("{}ty: {}", ind, cx.tables().expr_ty(expr)); + println!("{}adjustments: {:?}", ind, cx.tables().adjustments().get(expr.hir_id)); match expr.kind { hir::ExprKind::Box(ref e) => { println!("{}Box", ind); diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 89e2bcdd7935..38468181d026 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -347,7 +347,7 @@ fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty<'_>) -> bool { ) = ty.kind { if let TyKind::Path(ref path) = inner.kind { - if let Res::Def(DefKind::Struct, def_id) = cx.tables.qpath_res(path, inner.hir_id) { + if let Res::Def(DefKind::Struct, def_id) = cx.tables().qpath_res(path, inner.hir_id) { return match_def_path(cx, def_id, &paths::LINT); } } @@ -405,7 +405,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CompilerLintFunctions { if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; let fn_name = path.ident; if let Some(sugg) = self.map.get(&*fn_name.as_str()); - let ty = walk_ptrs_ty(cx.tables.expr_ty(&args[0])); + let ty = walk_ptrs_ty(cx.tables().expr_ty(&args[0])); if match_type(cx, ty, &paths::EARLY_CONTEXT) || match_type(cx, ty, &paths::LATE_CONTEXT); then { @@ -438,7 +438,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnDataPass { let args = arg_lists[1]; if args.len() == 1; let self_arg = &args[0]; - let self_ty = walk_ptrs_ty(cx.tables.expr_ty(self_arg)); + let self_ty = walk_ptrs_ty(cx.tables().expr_ty(self_arg)); if match_type(cx, self_ty, &paths::SYNTAX_CONTEXT); then { span_lint_and_sugg( diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 6d4c6c6ce1ce..69ec4b7ad6d1 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -151,7 +151,7 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_, '_>, ty: Ty<'_>, diag_item: /// Checks if the method call given in `expr` belongs to the given trait. pub fn match_trait_method(cx: &LateContext<'_, '_>, expr: &Expr<'_>, path: &[&str]) -> bool { - let def_id = cx.tables.type_dependent_def_id(expr.hir_id).unwrap(); + let def_id = cx.tables().type_dependent_def_id(expr.hir_id).unwrap(); let trt_id = cx.tcx.trait_of_item(def_id); if let Some(trt_id) = trt_id { match_def_path(cx, trt_id, path) @@ -824,7 +824,7 @@ pub fn is_integer_literal(expr: &Expr<'_>, value: u128) -> bool { /// See `rustc_middle::ty::adjustment::Adjustment` and `rustc_typeck::check::coercion` for more /// information on adjustments and coercions. pub fn is_adjusted(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool { - cx.tables.adjustments().get(e.hir_id).is_some() + cx.tables().adjustments().get(e.hir_id).is_some() } /// Returns the pre-expansion span if is this comes from an expansion of the @@ -898,7 +898,7 @@ pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { if let ExprKind::Call(ref fun, _) = expr.kind { if let ExprKind::Path(ref qp) = fun.kind { - let res = cx.tables.qpath_res(qp, fun.hir_id); + let res = cx.tables().qpath_res(qp, fun.hir_id); return match res { def::Res::Def(DefKind::Variant | DefKind::Ctor(..), ..) => true, def::Res::Def(_, def_id) => cx.tcx.is_promotable_const_fn(def_id), @@ -914,7 +914,7 @@ pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_, '_>, expr: &Exp pub fn is_refutable(cx: &LateContext<'_, '_>, pat: &Pat<'_>) -> bool { fn is_enum_variant(cx: &LateContext<'_, '_>, qpath: &QPath<'_>, id: HirId) -> bool { matches!( - cx.tables.qpath_res(qpath, id), + cx.tables().qpath_res(qpath, id), def::Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(def::CtorOf::Variant, _), _) ) } @@ -941,7 +941,7 @@ pub fn is_refutable(cx: &LateContext<'_, '_>, pat: &Pat<'_>) -> bool { is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, pats.iter().map(|pat| &**pat)) }, PatKind::Slice(ref head, ref middle, ref tail) => { - match &cx.tables.node_type(pat.hir_id).kind { + match &cx.tables().node_type(pat.hir_id).kind { ty::Slice(..) => { // [..] is the only irrefutable slice pattern. !head.is_empty() || middle.is_none() || !tail.is_empty() @@ -1190,7 +1190,7 @@ pub fn match_function_call<'a, 'tcx>( if_chain! { if let ExprKind::Call(ref fun, ref args) = expr.kind; if let ExprKind::Path(ref qpath) = fun.kind; - if let Some(fun_def_id) = cx.tables.qpath_res(qpath, fun.hir_id).opt_def_id(); + if let Some(fun_def_id) = cx.tables().qpath_res(qpath, fun.hir_id).opt_def_id(); if match_def_path(cx, fun_def_id, path); then { return Some(&args) @@ -1317,14 +1317,14 @@ pub fn is_must_use_func_call(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool let did = match expr.kind { ExprKind::Call(ref path, _) => if_chain! { if let ExprKind::Path(ref qpath) = path.kind; - if let def::Res::Def(_, did) = cx.tables.qpath_res(qpath, path.hir_id); + if let def::Res::Def(_, did) = cx.tables().qpath_res(qpath, path.hir_id); then { Some(did) } else { None } }, - ExprKind::MethodCall(_, _, _, _) => cx.tables.type_dependent_def_id(expr.hir_id), + ExprKind::MethodCall(_, _, _, _) => cx.tables().type_dependent_def_id(expr.hir_id), _ => None, }; diff --git a/clippy_lints/src/utils/usage.rs b/clippy_lints/src/utils/usage.rs index 0492878fc272..d280fe4ab4e0 100644 --- a/clippy_lints/src/utils/usage.rs +++ b/clippy_lints/src/utils/usage.rs @@ -18,7 +18,7 @@ pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &'a LateContext<'a, }; let def_id = expr.hir_id.owner.to_def_id(); cx.tcx.infer_ctxt().enter(|infcx| { - ExprUseVisitor::new(&mut delegate, &infcx, def_id.expect_local(), cx.param_env, cx.tables).walk_expr(expr); + ExprUseVisitor::new(&mut delegate, &infcx, def_id.expect_local(), cx.param_env, cx.tables()).walk_expr(expr); }); if delegate.skip { diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index a8d4c7620b1e..080785b177d6 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -37,7 +37,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessVec { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { // search for `&vec![_]` expressions where the adjusted type is `&[_]` if_chain! { - if let ty::Ref(_, ty, _) = cx.tables.expr_ty_adjusted(expr).kind; + if let ty::Ref(_, ty, _) = cx.tables().expr_ty_adjusted(expr).kind; if let ty::Slice(..) = ty.kind; if let ExprKind::AddrOf(BorrowKind::Ref, _, ref addressee) = expr.kind; if let Some(vec_args) = higher::vec_macro(cx, addressee); @@ -50,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessVec { if_chain! { if let Some((_, arg, _)) = higher::for_loop(expr); if let Some(vec_args) = higher::vec_macro(cx, arg); - if is_copy(cx, vec_type(cx.tables.expr_ty_adjusted(arg))); + if is_copy(cx, vec_type(cx.tables().expr_ty_adjusted(arg))); then { // report the error around the `vec!` not inside `:` let span = arg.span @@ -70,7 +70,7 @@ fn check_vec_macro<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, vec_args: &higher::VecA let mut applicability = Applicability::MachineApplicable; let snippet = match *vec_args { higher::VecArgs::Repeat(elem, len) => { - if constant(cx, cx.tables, len).is_some() { + if constant(cx, cx.tables(), len).is_some() { format!( "&[{}; {}]", snippet_with_applicability(cx, elem.span, "elem", &mut applicability), diff --git a/clippy_lints/src/vec_resize_to_zero.rs b/clippy_lints/src/vec_resize_to_zero.rs index 55758efa32e6..bb315e64e5de 100644 --- a/clippy_lints/src/vec_resize_to_zero.rs +++ b/clippy_lints/src/vec_resize_to_zero.rs @@ -32,7 +32,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VecResizeToZero { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let hir::ExprKind::MethodCall(path_segment, _, ref args, _) = expr.kind; - if let Some(method_def_id) = cx.tables.type_dependent_def_id(expr.hir_id); + if let Some(method_def_id) = cx.tables().type_dependent_def_id(expr.hir_id); if match_def_path(cx, method_def_id, &paths::VEC_RESIZE) && args.len() == 3; if let ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = args[1].kind; if let ExprKind::Lit(Spanned { node: LitKind::Int(..), .. }) = args[2].kind; diff --git a/clippy_lints/src/verbose_file_reads.rs b/clippy_lints/src/verbose_file_reads.rs index 6d420d491c50..85f920845744 100644 --- a/clippy_lints/src/verbose_file_reads.rs +++ b/clippy_lints/src/verbose_file_reads.rs @@ -62,7 +62,7 @@ fn is_file_read_to_end<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'t if let ExprKind::MethodCall(method_name, _, exprs, _) = expr.kind; if method_name.ident.as_str() == "read_to_end"; if let ExprKind::Path(QPath::Resolved(None, _)) = &exprs[0].kind; - let ty = cx.tables.expr_ty(&exprs[0]); + let ty = cx.tables().expr_ty(&exprs[0]); if match_type(cx, ty, &paths::FILE); then { return true @@ -76,7 +76,7 @@ fn is_file_read_to_string<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr if let ExprKind::MethodCall(method_name, _, exprs, _) = expr.kind; if method_name.ident.as_str() == "read_to_string"; if let ExprKind::Path(QPath::Resolved(None, _)) = &exprs[0].kind; - let ty = cx.tables.expr_ty(&exprs[0]); + let ty = cx.tables().expr_ty(&exprs[0]); if match_type(cx, ty, &paths::FILE); then { return true diff --git a/clippy_lints/src/zero_div_zero.rs b/clippy_lints/src/zero_div_zero.rs index 0820385e01bb..f0cf17c3b954 100644 --- a/clippy_lints/src/zero_div_zero.rs +++ b/clippy_lints/src/zero_div_zero.rs @@ -36,8 +36,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ZeroDiv { // TODO - constant_simple does not fold many operations involving floats. // That's probably fine for this lint - it's pretty unlikely that someone would // do something like 0.0/(2.0 - 2.0), but it would be nice to warn on that case too. - if let Some(lhs_value) = constant_simple(cx, cx.tables, left); - if let Some(rhs_value) = constant_simple(cx, cx.tables, right); + if let Some(lhs_value) = constant_simple(cx, cx.tables(), left); + if let Some(rhs_value) = constant_simple(cx, cx.tables(), right); if Constant::F32(0.0) == lhs_value || Constant::F64(0.0) == lhs_value; if Constant::F32(0.0) == rhs_value || Constant::F64(0.0) == rhs_value; then { diff --git a/doc/common_tools_writing_lints.md b/doc/common_tools_writing_lints.md index dbc434505947..d06e359bc7aa 100644 --- a/doc/common_tools_writing_lints.md +++ b/doc/common_tools_writing_lints.md @@ -19,11 +19,11 @@ Useful Rustc dev guide links: Sometimes you may want to retrieve the type `Ty` of an expression `Expr`, for example to answer following questions: - which type does this expression correspond to (using its [`TyKind`][TyKind])? -- is it a sized type? +- is it a sized type? - is it a primitive type? - does it implement a trait? -This operation is performed using the [`expr_ty()`][expr_ty] method from the [`TypeckTables`][TypeckTables] struct, +This operation is performed using the [`expr_ty()`][expr_ty] method from the [`TypeckTables`][TypeckTables] struct, that gives you access to the underlying structure [`TyS`][TyS]. Example of use: @@ -31,7 +31,7 @@ Example of use: impl LateLintPass<'_, '_> for MyStructLint { fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) { // Get type of `expr` - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); // Match its kind to enter its type match ty.kind { ty::Adt(adt_def, _) if adt_def.is_struct() => println!("Our `expr` is a struct!"), @@ -41,14 +41,14 @@ impl LateLintPass<'_, '_> for MyStructLint { } ``` -Similarly in [`TypeckTables`][TypeckTables] methods, you have the [`pat_ty()`][pat_ty] method +Similarly in [`TypeckTables`][TypeckTables] methods, you have the [`pat_ty()`][pat_ty] method to retrieve a type from a pattern. Two noticeable items here: -- `cx` is the lint context [`LateContext`][LateContext]. - The two most useful data structures in this context are `tcx` and `tables`, +- `cx` is the lint context [`LateContext`][LateContext]. + The two most useful data structures in this context are `tcx` and `tables`, allowing us to jump to type definitions and other compilation stages such as HIR. -- `tables` is [`TypeckTables`][TypeckTables] and is created by type checking step, +- `tables` is [`TypeckTables`][TypeckTables] and is created by type checking step, it includes useful information such as types of expressions, ways to resolve methods and so on. # Checking if an expr is calling a specific method @@ -87,7 +87,7 @@ impl LateLintPass<'_, '_> for MyStructLint { } // 2. Using type context `TyCtxt` - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); if cx.tcx.lang_items() // we are looking for the `DefId` of `Drop` trait in lang items .drop_trait() From 92a85553f14232410916e9bca041ecec908c5e45 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 25 Jun 2020 17:43:48 -0700 Subject: [PATCH 0029/1222] Update tests --- tests/ui/redundant_pattern_matching.fixed | 2 - tests/ui/redundant_pattern_matching.rs | 2 - tests/ui/redundant_pattern_matching.stderr | 56 +++++++++---------- ...undant_pattern_matching_const_result.fixed | 2 - ...redundant_pattern_matching_const_result.rs | 2 - ...ndant_pattern_matching_const_result.stderr | 12 ++-- 6 files changed, 34 insertions(+), 42 deletions(-) diff --git a/tests/ui/redundant_pattern_matching.fixed b/tests/ui/redundant_pattern_matching.fixed index 6ba5cfb1d717..8b4e2d21331c 100644 --- a/tests/ui/redundant_pattern_matching.fixed +++ b/tests/ui/redundant_pattern_matching.fixed @@ -1,7 +1,5 @@ // run-rustfix -#![feature(const_if_match)] -#![feature(const_loop)] #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow(clippy::unit_arg, unused_must_use, clippy::needless_bool, deprecated)] diff --git a/tests/ui/redundant_pattern_matching.rs b/tests/ui/redundant_pattern_matching.rs index 17de66f9ad0e..b0904e41b6f4 100644 --- a/tests/ui/redundant_pattern_matching.rs +++ b/tests/ui/redundant_pattern_matching.rs @@ -1,7 +1,5 @@ // run-rustfix -#![feature(const_if_match)] -#![feature(const_loop)] #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow(clippy::unit_arg, unused_must_use, clippy::needless_bool, deprecated)] diff --git a/tests/ui/redundant_pattern_matching.stderr b/tests/ui/redundant_pattern_matching.stderr index 1b9a4b40a2f0..51a6f4350d32 100644 --- a/tests/ui/redundant_pattern_matching.stderr +++ b/tests/ui/redundant_pattern_matching.stderr @@ -1,5 +1,5 @@ error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:10:12 + --> $DIR/redundant_pattern_matching.rs:8:12 | LL | if let Ok(_) = Ok::(42) {} | -------^^^^^--------------------- help: try this: `if Ok::(42).is_ok()` @@ -7,67 +7,67 @@ LL | if let Ok(_) = Ok::(42) {} = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:12:12 + --> $DIR/redundant_pattern_matching.rs:10:12 | LL | if let Err(_) = Err::(42) {} | -------^^^^^^---------------------- help: try this: `if Err::(42).is_err()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:14:12 + --> $DIR/redundant_pattern_matching.rs:12:12 | LL | if let None = None::<()> {} | -------^^^^------------- help: try this: `if None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:16:12 + --> $DIR/redundant_pattern_matching.rs:14:12 | LL | if let Some(_) = Some(42) {} | -------^^^^^^^----------- help: try this: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:18:12 + --> $DIR/redundant_pattern_matching.rs:16:12 | LL | if let Some(_) = Some(42) { | -------^^^^^^^----------- help: try this: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:24:15 + --> $DIR/redundant_pattern_matching.rs:22:15 | LL | while let Some(_) = Some(42) {} | ----------^^^^^^^----------- help: try this: `while Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:26:15 + --> $DIR/redundant_pattern_matching.rs:24:15 | LL | while let None = Some(42) {} | ----------^^^^----------- help: try this: `while Some(42).is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:28:15 + --> $DIR/redundant_pattern_matching.rs:26:15 | LL | while let None = None::<()> {} | ----------^^^^------------- help: try this: `while None::<()>.is_none()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:30:15 + --> $DIR/redundant_pattern_matching.rs:28:15 | LL | while let Ok(_) = Ok::(10) {} | ----------^^^^^--------------------- help: try this: `while Ok::(10).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:32:15 + --> $DIR/redundant_pattern_matching.rs:30:15 | LL | while let Err(_) = Ok::(10) {} | ----------^^^^^^--------------------- help: try this: `while Ok::(10).is_err()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:35:15 + --> $DIR/redundant_pattern_matching.rs:33:15 | LL | while let Some(_) = v.pop() { | ----------^^^^^^^---------- help: try this: `while v.pop().is_some()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:51:5 + --> $DIR/redundant_pattern_matching.rs:49:5 | LL | / match Ok::(42) { LL | | Ok(_) => true, @@ -76,7 +76,7 @@ LL | | }; | |_____^ help: try this: `Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:56:5 + --> $DIR/redundant_pattern_matching.rs:54:5 | LL | / match Ok::(42) { LL | | Ok(_) => false, @@ -85,7 +85,7 @@ LL | | }; | |_____^ help: try this: `Ok::(42).is_err()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:61:5 + --> $DIR/redundant_pattern_matching.rs:59:5 | LL | / match Err::(42) { LL | | Ok(_) => false, @@ -94,7 +94,7 @@ LL | | }; | |_____^ help: try this: `Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:66:5 + --> $DIR/redundant_pattern_matching.rs:64:5 | LL | / match Err::(42) { LL | | Ok(_) => true, @@ -103,7 +103,7 @@ LL | | }; | |_____^ help: try this: `Err::(42).is_ok()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:71:5 + --> $DIR/redundant_pattern_matching.rs:69:5 | LL | / match Some(42) { LL | | Some(_) => true, @@ -112,7 +112,7 @@ LL | | }; | |_____^ help: try this: `Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:76:5 + --> $DIR/redundant_pattern_matching.rs:74:5 | LL | / match None::<()> { LL | | Some(_) => false, @@ -121,7 +121,7 @@ LL | | }; | |_____^ help: try this: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:81:13 + --> $DIR/redundant_pattern_matching.rs:79:13 | LL | let _ = match None::<()> { | _____________^ @@ -131,61 +131,61 @@ LL | | }; | |_____^ help: try this: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:86:20 + --> $DIR/redundant_pattern_matching.rs:84:20 | LL | let _ = if let Ok(_) = Ok::(4) { true } else { false }; | -------^^^^^--------------------- help: try this: `if Ok::(4).is_ok()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:89:20 + --> $DIR/redundant_pattern_matching.rs:87:20 | LL | let x = if let Some(_) = opt { true } else { false }; | -------^^^^^^^------ help: try this: `if opt.is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:95:20 + --> $DIR/redundant_pattern_matching.rs:93:20 | LL | let _ = if let Some(_) = gen_opt() { | -------^^^^^^^------------ help: try this: `if gen_opt().is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:97:19 + --> $DIR/redundant_pattern_matching.rs:95:19 | LL | } else if let None = gen_opt() { | -------^^^^------------ help: try this: `if gen_opt().is_none()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:99:19 + --> $DIR/redundant_pattern_matching.rs:97:19 | LL | } else if let Ok(_) = gen_res() { | -------^^^^^------------ help: try this: `if gen_res().is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:101:19 + --> $DIR/redundant_pattern_matching.rs:99:19 | LL | } else if let Err(_) = gen_res() { | -------^^^^^^------------ help: try this: `if gen_res().is_err()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:134:19 + --> $DIR/redundant_pattern_matching.rs:132:19 | LL | while let Some(_) = r#try!(result_opt()) {} | ----------^^^^^^^----------------------- help: try this: `while r#try!(result_opt()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:135:16 + --> $DIR/redundant_pattern_matching.rs:133:16 | LL | if let Some(_) = r#try!(result_opt()) {} | -------^^^^^^^----------------------- help: try this: `if r#try!(result_opt()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:141:12 + --> $DIR/redundant_pattern_matching.rs:139:12 | LL | if let Some(_) = m!() {} | -------^^^^^^^------- help: try this: `if m!().is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:142:15 + --> $DIR/redundant_pattern_matching.rs:140:15 | LL | while let Some(_) = m!() {} | ----------^^^^^^^------- help: try this: `while m!().is_some()` diff --git a/tests/ui/redundant_pattern_matching_const_result.fixed b/tests/ui/redundant_pattern_matching_const_result.fixed index c8bc5458067d..8a81e92f04a7 100644 --- a/tests/ui/redundant_pattern_matching_const_result.fixed +++ b/tests/ui/redundant_pattern_matching_const_result.fixed @@ -1,7 +1,5 @@ // run-rustfix -#![feature(const_if_match)] -#![feature(const_loop)] #![feature(const_result)] #![warn(clippy::redundant_pattern_matching)] #![allow(unused)] diff --git a/tests/ui/redundant_pattern_matching_const_result.rs b/tests/ui/redundant_pattern_matching_const_result.rs index 75f37ec15c62..1cd515441d13 100644 --- a/tests/ui/redundant_pattern_matching_const_result.rs +++ b/tests/ui/redundant_pattern_matching_const_result.rs @@ -1,7 +1,5 @@ // run-rustfix -#![feature(const_if_match)] -#![feature(const_loop)] #![feature(const_result)] #![warn(clippy::redundant_pattern_matching)] #![allow(unused)] diff --git a/tests/ui/redundant_pattern_matching_const_result.stderr b/tests/ui/redundant_pattern_matching_const_result.stderr index c32292f0eee8..8ecd72158d33 100644 --- a/tests/ui/redundant_pattern_matching_const_result.stderr +++ b/tests/ui/redundant_pattern_matching_const_result.stderr @@ -1,5 +1,5 @@ error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_const_result.rs:12:12 + --> $DIR/redundant_pattern_matching_const_result.rs:10:12 | LL | if let Ok(_) = Ok::(42) {} | -------^^^^^--------------------- help: try this: `if Ok::(42).is_ok()` @@ -7,25 +7,25 @@ LL | if let Ok(_) = Ok::(42) {} = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_const_result.rs:14:12 + --> $DIR/redundant_pattern_matching_const_result.rs:12:12 | LL | if let Err(_) = Err::(42) {} | -------^^^^^^---------------------- help: try this: `if Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_const_result.rs:16:15 + --> $DIR/redundant_pattern_matching_const_result.rs:14:15 | LL | while let Ok(_) = Ok::(10) {} | ----------^^^^^--------------------- help: try this: `while Ok::(10).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_const_result.rs:18:15 + --> $DIR/redundant_pattern_matching_const_result.rs:16:15 | LL | while let Err(_) = Ok::(10) {} | ----------^^^^^^--------------------- help: try this: `while Ok::(10).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_const_result.rs:20:5 + --> $DIR/redundant_pattern_matching_const_result.rs:18:5 | LL | / match Ok::(42) { LL | | Ok(_) => true, @@ -34,7 +34,7 @@ LL | | }; | |_____^ help: try this: `Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_const_result.rs:25:5 + --> $DIR/redundant_pattern_matching_const_result.rs:23:5 | LL | / match Err::(42) { LL | | Ok(_) => false, From 6308fbf97b32129647455b7de9d6d1d5ff20f2ed Mon Sep 17 00:00:00 2001 From: Azhng Date: Wed, 24 Jun 2020 16:33:31 -0400 Subject: [PATCH 0030/1222] typeck: adding type information to projection This commit modifies the Place as follow: * remove 'ty' from ProjectionKind * add type information into to Projection * replace 'ty' in Place with 'base_ty' * introduce 'ty()' in `Place` to return the final type of the `Place` * introduce `ty_before_projection()` in `Place` to return the type of a `Place` before i'th projection is applied Closes https://github.com/rust-lang/project-rfc-2229/issues/5 --- clippy_lints/src/escape.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 59af475af175..fcb574e43748 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -150,7 +150,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { return; } - if is_non_trait_box(cmt.place.ty) && !self.is_large_box(cmt.place.ty) { + if is_non_trait_box(cmt.place.ty()) && !self.is_large_box(cmt.place.ty()) { self.set.insert(cmt.hir_id); } return; From 2e54fc9e2a997e520cf7769e840a939471ac3377 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 26 Jun 2020 05:55:23 +0300 Subject: [PATCH 0031/1222] rustc_lint: avoid using TypeckTables::empty for LateContext. --- clippy_lints/src/atomic_ordering.rs | 6 +-- clippy_lints/src/copies.rs | 6 +-- clippy_lints/src/default_trait_access.rs | 2 +- clippy_lints/src/eval_order_dependence.rs | 4 +- clippy_lints/src/format.rs | 2 +- clippy_lints/src/implicit_return.rs | 2 +- clippy_lints/src/let_and_return.rs | 2 +- clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/map_unit_fn.rs | 8 ++-- clippy_lints/src/mem_discriminant.rs | 2 +- clippy_lints/src/mem_replace.rs | 6 +-- clippy_lints/src/methods/mod.rs | 8 ++-- .../src/methods/unnecessary_filter_map.rs | 2 +- clippy_lints/src/misc.rs | 2 +- clippy_lints/src/question_mark.rs | 2 +- clippy_lints/src/regex.rs | 2 +- clippy_lints/src/temporary_assignment.rs | 2 +- clippy_lints/src/to_digit_is_some.rs | 2 +- clippy_lints/src/trait_bounds.rs | 2 +- clippy_lints/src/transmute.rs | 2 +- clippy_lints/src/types.rs | 11 ++--- clippy_lints/src/unnamed_address.rs | 2 +- clippy_lints/src/useless_conversion.rs | 2 +- clippy_lints/src/utils/higher.rs | 2 +- clippy_lints/src/utils/hir_utils.rs | 46 ++++++++++--------- clippy_lints/src/utils/internal_lints.rs | 2 +- clippy_lints/src/utils/mod.rs | 8 ++-- 27 files changed, 70 insertions(+), 69 deletions(-) diff --git a/clippy_lints/src/atomic_ordering.rs b/clippy_lints/src/atomic_ordering.rs index 65e1e2c519c2..1115ba1bf922 100644 --- a/clippy_lints/src/atomic_ordering.rs +++ b/clippy_lints/src/atomic_ordering.rs @@ -76,7 +76,7 @@ fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if method == "load" || method == "store"; let ordering_arg = if method == "load" { &args[1] } else { &args[2] }; if let ExprKind::Path(ref ordering_qpath) = ordering_arg.kind; - if let Some(ordering_def_id) = cx.tables().qpath_res(ordering_qpath, ordering_arg.hir_id).opt_def_id(); + if let Some(ordering_def_id) = cx.qpath_res(ordering_qpath, ordering_arg.hir_id).opt_def_id(); then { if method == "load" && match_ordering_def_path(cx, ordering_def_id, &["Release", "AcqRel"]) { @@ -107,12 +107,12 @@ fn check_memory_fence(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Call(ref func, ref args) = expr.kind; if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.tables().qpath_res(func_qpath, func.hir_id).opt_def_id(); + if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); if ["fence", "compiler_fence"] .iter() .any(|func| match_def_path(cx, def_id, &["core", "sync", "atomic", func])); if let ExprKind::Path(ref ordering_qpath) = &args[0].kind; - if let Some(ordering_def_id) = cx.tables().qpath_res(ordering_qpath, args[0].hir_id).opt_def_id(); + if let Some(ordering_def_id) = cx.qpath_res(ordering_qpath, args[0].hir_id).opt_def_id(); if match_ordering_def_path(cx, ordering_def_id, &["Relaxed"]); then { span_lint_and_help( diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index efd4a31f5596..8cc69c806aa9 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -192,7 +192,7 @@ fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block<'_>]) { /// Implementation of `IFS_SAME_COND`. fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { let hash: &dyn Fn(&&Expr<'_>) -> u64 = &|expr| -> u64 { - let mut h = SpanlessHash::new(cx, cx.tables()); + let mut h = SpanlessHash::new(cx); h.hash_expr(expr); h.finish() }; @@ -215,7 +215,7 @@ fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { /// Implementation of `SAME_FUNCTIONS_IN_IF_CONDITION`. fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { let hash: &dyn Fn(&&Expr<'_>) -> u64 = &|expr| -> u64 { - let mut h = SpanlessHash::new(cx, cx.tables()); + let mut h = SpanlessHash::new(cx); h.hash_expr(expr); h.finish() }; @@ -251,7 +251,7 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>) { if let ExprKind::Match(_, ref arms, MatchSource::Normal) = expr.kind { let hash = |&(_, arm): &(usize, &Arm<'_>)| -> u64 { - let mut h = SpanlessHash::new(cx, cx.tables()); + let mut h = SpanlessHash::new(cx); h.hash_expr(&arm.body); h.finish() }; diff --git a/clippy_lints/src/default_trait_access.rs b/clippy_lints/src/default_trait_access.rs index 69ae509fb23e..a918c72fb275 100644 --- a/clippy_lints/src/default_trait_access.rs +++ b/clippy_lints/src/default_trait_access.rs @@ -36,7 +36,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess { if let ExprKind::Call(ref path, ..) = expr.kind; if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id); if let ExprKind::Path(ref qpath) = path.kind; - if let Some(def_id) = cx.tables().qpath_res(qpath, path.hir_id).opt_def_id(); + if let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD); then { match qpath { diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 04af6c2c1f85..31fe7382e46d 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -75,7 +75,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence { if let ExprKind::Path(ref qpath) = lhs.kind { if let QPath::Resolved(_, ref path) = *qpath { if path.segments.len() == 1 { - if let def::Res::Local(var) = cx.tables().qpath_res(qpath, lhs.hir_id) { + if let def::Res::Local(var) = cx.qpath_res(qpath, lhs.hir_id) { let mut visitor = ReadVisitor { cx, var, @@ -309,7 +309,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> { if_chain! { if let QPath::Resolved(None, ref path) = *qpath; if path.segments.len() == 1; - if let def::Res::Local(local_id) = self.cx.tables().qpath_res(qpath, expr.hir_id); + if let def::Res::Local(local_id) = self.cx.qpath_res(qpath, expr.hir_id); if local_id == self.var; // Check that this is a read, not a write. if !is_in_assignment_position(self.cx, expr); diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 58cf0027ea4d..dc8795e3d11e 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -88,7 +88,7 @@ fn on_argumentv1_new<'a, 'tcx>( // matches `core::fmt::Display::fmt` if args.len() == 2; if let ExprKind::Path(ref qpath) = args[1].kind; - if let Some(did) = cx.tables().qpath_res(qpath, args[1].hir_id).opt_def_id(); + if let Some(did) = cx.qpath_res(qpath, args[1].hir_id).opt_def_id(); if match_def_path(cx, did, &paths::DISPLAY_FMT_METHOD); // check `(arg0,)` in match block if let PatKind::Tuple(ref pats, None) = arms[0].pat.kind; diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index 5a0531ff749e..b43babc1de87 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -108,7 +108,7 @@ fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { ExprKind::Call(expr, ..) => { if_chain! { if let ExprKind::Path(qpath) = &expr.kind; - if let Some(path_def_id) = cx.tables().qpath_res(qpath, expr.hir_id).opt_def_id(); + if let Some(path_def_id) = cx.qpath_res(qpath, expr.hir_id).opt_def_id(); if match_def_path(cx, path_def_id, &BEGIN_PANIC) || match_def_path(cx, path_def_id, &BEGIN_PANIC_FMT); then { } diff --git a/clippy_lints/src/let_and_return.rs b/clippy_lints/src/let_and_return.rs index 299202981b1f..7d338cfa86f9 100644 --- a/clippy_lints/src/let_and_return.rs +++ b/clippy_lints/src/let_and_return.rs @@ -107,7 +107,7 @@ impl BorrowVisitor<'_, '_> { .. }, .., - ) => self.cx.tables().qpath_res(qpath, expr.hir_id).opt_def_id(), + ) => self.cx.qpath_res(qpath, expr.hir_id).opt_def_id(), _ => None, } } diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 6840e82d4bf1..c0d8c1127b9d 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -343,7 +343,7 @@ impl<'v, 't> RefVisitor<'v, 't> { }) { let hir_id = ty.hir_id; - match self.cx.tables().qpath_res(qpath, hir_id) { + match self.cx.qpath_res(qpath, hir_id) { Res::Def(DefKind::TyAlias | DefKind::Struct, def_id) => { let generics = self.cx.tcx.generics_of(def_id); for _ in generics.params.as_slice() { diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index a4550f707ee2..90d4a34a19a2 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -160,10 +160,10 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr<'_>) } } -fn unit_closure<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, - expr: &'a hir::Expr<'a>, -) -> Option<(&'tcx hir::Param<'tcx>, &'a hir::Expr<'a>)> { +fn unit_closure<'tcx>( + cx: &LateContext<'_, 'tcx>, + expr: &hir::Expr<'_>, +) -> Option<(&'tcx hir::Param<'tcx>, &'tcx hir::Expr<'tcx>)> { if let hir::ExprKind::Closure(_, ref decl, inner_expr_id, _, _) = expr.kind { let body = cx.tcx.hir().body(inner_expr_id); let body_expr = &body.value; diff --git a/clippy_lints/src/mem_discriminant.rs b/clippy_lints/src/mem_discriminant.rs index d315c5ef89a8..8a665a6e1fad 100644 --- a/clippy_lints/src/mem_discriminant.rs +++ b/clippy_lints/src/mem_discriminant.rs @@ -35,7 +35,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemDiscriminant { if let ExprKind::Call(ref func, ref func_args) = expr.kind; // is `mem::discriminant` if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.tables().qpath_res(func_qpath, func.hir_id).opt_def_id(); + if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::MEM_DISCRIMINANT); // type is non-enum let ty_param = cx.tables().node_substs(func.hir_id).type_at(0); diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 16d31fc8346e..703f91f8ac02 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -162,7 +162,7 @@ fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest: &Ex if let ExprKind::Call(ref repl_func, ref repl_args) = src.kind; if repl_args.is_empty(); if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; - if let Some(repl_def_id) = cx.tables().qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); + if let Some(repl_def_id) = cx.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); then { if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, repl_def_id) { let mut applicability = Applicability::MachineApplicable; @@ -198,7 +198,7 @@ fn check_replace_with_default(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest: &E if_chain! { if !in_external_macro(cx.tcx.sess, expr_span); if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; - if let Some(repl_def_id) = cx.tables().qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); + if let Some(repl_def_id) = cx.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); if match_def_path(cx, repl_def_id, &paths::DEFAULT_TRAIT_METHOD); then { span_lint_and_then( @@ -230,7 +230,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace { // Check that `expr` is a call to `mem::replace()` if let ExprKind::Call(ref func, ref func_args) = expr.kind; if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.tables().qpath_res(func_qpath, func.hir_id).opt_def_id(); + if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::MEM_REPLACE); if let [dest, src] = &**func_args; then { diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index c4e707ecf03a..7018a2f40397 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1824,7 +1824,7 @@ fn lint_expect_fun_call( hir::ExprKind::Lit(_) => true, hir::ExprKind::Call(fun, _) => { if let hir::ExprKind::Path(ref p) = fun.kind { - match cx.tables().qpath_res(p, fun.hir_id) { + match cx.qpath_res(p, fun.hir_id) { hir::def::Res::Def(hir::def::DefKind::Fn | hir::def::DefKind::AssocFn, def_id) => matches!( cx.tcx.fn_sig(def_id).output().skip_binder().kind, ty::Ref(ty::ReStatic, ..) @@ -1844,7 +1844,7 @@ fn lint_expect_fun_call( ty::Ref(ty::ReStatic, ..) ) }), - hir::ExprKind::Path(ref p) => match cx.tables().qpath_res(p, arg.hir_id) { + hir::ExprKind::Path(ref p) => match cx.qpath_res(p, arg.hir_id) { hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static, _) => true, _ => false, }, @@ -3317,7 +3317,7 @@ fn lint_option_as_ref_deref<'a, 'tcx>( if_chain! { if args.len() == 1; if let hir::ExprKind::Path(qpath) = &args[0].kind; - if let hir::def::Res::Local(local_id) = cx.tables().qpath_res(qpath, args[0].hir_id); + if let hir::def::Res::Local(local_id) = cx.qpath_res(qpath, args[0].hir_id); if closure_body.params[0].pat.hir_id == local_id; let adj = cx.tables().expr_adjustments(&args[0]).iter().map(|x| &x.kind).collect::>(); if let [ty::adjustment::Adjust::Deref(None), ty::adjustment::Adjust::Borrow(_)] = *adj; @@ -3334,7 +3334,7 @@ fn lint_option_as_ref_deref<'a, 'tcx>( if let hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner1) = inner.kind; if let hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner2) = inner1.kind; if let hir::ExprKind::Path(ref qpath) = inner2.kind; - if let hir::def::Res::Local(local_id) = cx.tables().qpath_res(qpath, inner2.hir_id); + if let hir::def::Res::Local(local_id) = cx.qpath_res(qpath, inner2.hir_id); then { closure_body.params[0].pat.hir_id == local_id } else { diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index 88243a88d9dd..8a3df85c91bf 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -65,7 +65,7 @@ fn check_expression<'a, 'tcx>( if match_qpath(path, &paths::OPTION_SOME) { if_chain! { if let hir::ExprKind::Path(path) = &args[0].kind; - if let Res::Local(ref local) = cx.tables().qpath_res(path, args[0].hir_id); + if let Res::Local(ref local) = cx.qpath_res(path, args[0].hir_id); then { if arg_id == *local { return (false, false) diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 99cd864cae4e..fcd77088b88e 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -436,7 +436,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints { binding != "_result" && // FIXME: #944 is_used(cx, expr) && // don't lint if the declaration is in a macro - non_macro_local(cx, cx.tables().qpath_res(qpath, expr.hir_id)) + non_macro_local(cx, cx.qpath_res(qpath, expr.hir_id)) { Some(binding) } else { diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 4a6395da01c9..a77e104bb8f0 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -158,7 +158,7 @@ impl QuestionMark { ExprKind::Ret(Some(ref expr)) => Self::expression_returns_none(cx, expr), ExprKind::Path(ref qp) => { if let Res::Def(DefKind::Ctor(def::CtorOf::Variant, def::CtorKind::Const), def_id) = - cx.tables().qpath_res(qp, expression.hir_id) + cx.qpath_res(qp, expression.hir_id) { return match_def_path(cx, def_id, &paths::OPTION_NONE); } diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index 9c54c3cbac02..0b56ef02a844 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -111,7 +111,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex { if let ExprKind::Call(ref fun, ref args) = expr.kind; if let ExprKind::Path(ref qpath) = fun.kind; if args.len() == 1; - if let Some(def_id) = cx.tables().qpath_res(qpath, fun.hir_id).opt_def_id(); + if let Some(def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id(); then { if match_def_path(cx, def_id, &paths::REGEX_NEW) || match_def_path(cx, def_id, &paths::REGEX_BUILDER_NEW) { diff --git a/clippy_lints/src/temporary_assignment.rs b/clippy_lints/src/temporary_assignment.rs index f2bbf19bea92..bc282e4bd987 100644 --- a/clippy_lints/src/temporary_assignment.rs +++ b/clippy_lints/src/temporary_assignment.rs @@ -26,7 +26,7 @@ fn is_temporary(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { match &expr.kind { ExprKind::Struct(..) | ExprKind::Tup(..) => true, ExprKind::Path(qpath) => { - if let Res::Def(DefKind::Const, ..) = cx.tables().qpath_res(qpath, expr.hir_id) { + if let Res::Def(DefKind::Const, ..) = cx.qpath_res(qpath, expr.hir_id) { true } else { false diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs index 1efba3580fef..4f943eeaeebc 100644 --- a/clippy_lints/src/to_digit_is_some.rs +++ b/clippy_lints/src/to_digit_is_some.rs @@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ToDigitIsSome { if_chain! { if let [char_arg, radix_arg] = &**to_digit_args; if let hir::ExprKind::Path(to_digits_path) = &to_digits_call.kind; - if let to_digits_call_res = cx.tables().qpath_res(to_digits_path, to_digits_call.hir_id); + if let to_digits_call_res = cx.qpath_res(to_digits_path, to_digits_call.hir_id); if let Some(to_digits_def_id) = to_digits_call_res.opt_def_id(); if match_def_path(cx, to_digits_def_id, &["core", "char", "methods", "", "to_digit"]); then { diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 1b233b8302f9..c3e4eb05eb4e 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -37,7 +37,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TraitBounds { return; } let hash = |ty| -> u64 { - let mut hasher = SpanlessHash::new(cx, cx.tables()); + let mut hasher = SpanlessHash::new(cx); hasher.hash_ty(ty); hasher.finish() }; diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 9b1344949470..6ef4b8dcfc19 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -299,7 +299,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { if_chain! { if let ExprKind::Call(ref path_expr, ref args) = e.kind; if let ExprKind::Path(ref qpath) = path_expr.kind; - if let Some(def_id) = cx.tables().qpath_res(qpath, path_expr.hir_id).opt_def_id(); + if let Some(def_id) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::TRANSMUTE); then { let from_ty = cx.tables().expr_ty(&args[0]); diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index ecfb6ee2a7de..74db29e4f1d5 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -2490,7 +2490,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> { /// Looks for default-hasher-dependent constructors like `HashMap::new`. struct ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { cx: &'a LateContext<'a, 'tcx>, - body: &'a TypeckTables<'tcx>, + maybe_typeck_tables: Option<&'tcx TypeckTables<'tcx>>, target: &'b ImplicitHasherType<'tcx>, suggestions: BTreeMap, } @@ -2499,7 +2499,7 @@ impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { fn new(cx: &'a LateContext<'a, 'tcx>, target: &'b ImplicitHasherType<'tcx>) -> Self { Self { cx, - body: cx.tables(), + maybe_typeck_tables: cx.maybe_typeck_tables(), target, suggestions: BTreeMap::new(), } @@ -2510,10 +2510,9 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't type Map = Map<'tcx>; fn visit_body(&mut self, body: &'tcx Body<'_>) { - let prev_body = self.body; - self.body = self.cx.tcx.body_tables(body.id()); + let old_maybe_typeck_tables = self.maybe_typeck_tables.replace(self.cx.tcx.body_tables(body.id())); walk_body(self, body); - self.body = prev_body; + self.maybe_typeck_tables = old_maybe_typeck_tables; } fn visit_expr(&mut self, e: &'tcx Expr<'_>) { @@ -2522,7 +2521,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't if let ExprKind::Path(QPath::TypeRelative(ref ty, ref method)) = fun.kind; if let TyKind::Path(QPath::Resolved(None, ty_path)) = ty.kind; then { - if !TyS::same_type(self.target.ty(), self.body.expr_ty(e)) { + if !TyS::same_type(self.target.ty(), self.maybe_typeck_tables.unwrap().expr_ty(e)) { return; } diff --git a/clippy_lints/src/unnamed_address.rs b/clippy_lints/src/unnamed_address.rs index 53e47f09ae55..0efbf68dcd84 100644 --- a/clippy_lints/src/unnamed_address.rs +++ b/clippy_lints/src/unnamed_address.rs @@ -98,7 +98,7 @@ impl LateLintPass<'_, '_> for UnnamedAddress { if_chain! { if let ExprKind::Call(ref func, [ref _left, ref _right]) = expr.kind; if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.tables().qpath_res(func_qpath, func.hir_id).opt_def_id(); + if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::PTR_EQ) || match_def_path(cx, def_id, &paths::RC_PTR_EQ) || match_def_path(cx, def_id, &paths::ARC_PTR_EQ); diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 5d150ad4f03e..ad5ecc0c0267 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -121,7 +121,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion { if_chain! { if args.len() == 1; if let ExprKind::Path(ref qpath) = path.kind; - if let Some(def_id) = cx.tables().qpath_res(qpath, path.hir_id).opt_def_id(); + if let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id(); let a = cx.tables().expr_ty(e); let b = cx.tables().expr_ty(&args[0]); diff --git a/clippy_lints/src/utils/higher.rs b/clippy_lints/src/utils/higher.rs index 0e78f35a1290..9502d85e6ee9 100644 --- a/clippy_lints/src/utils/higher.rs +++ b/clippy_lints/src/utils/higher.rs @@ -262,7 +262,7 @@ pub fn vec_macro<'e>(cx: &LateContext<'_, '_>, expr: &'e hir::Expr<'_>) -> Optio if let hir::ExprKind::Call(ref fun, ref args) = expr.kind; if let hir::ExprKind::Path(ref qpath) = fun.kind; if is_expn_of(fun.span, "vec").is_some(); - if let Some(fun_def_id) = cx.tables().qpath_res(qpath, fun.hir_id).opt_def_id(); + if let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id(); then { return if match_def_path(cx, fun_def_id, &paths::VEC_FROM_ELEM) && args.len() == 2 { // `vec![elem; size]` case diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index a74ab18a063b..bf1017d76ec6 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -22,7 +22,7 @@ use std::hash::Hash; pub struct SpanlessEq<'a, 'tcx> { /// Context used to evaluate constant expressions. cx: &'a LateContext<'a, 'tcx>, - tables: &'a TypeckTables<'tcx>, + maybe_typeck_tables: Option<&'tcx TypeckTables<'tcx>>, /// If is true, never consider as equal expressions containing function /// calls. ignore_fn: bool, @@ -32,16 +32,15 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { pub fn new(cx: &'a LateContext<'a, 'tcx>) -> Self { Self { cx, - tables: cx.tables(), + maybe_typeck_tables: cx.maybe_typeck_tables(), ignore_fn: false, } } pub fn ignore_fn(self) -> Self { Self { - cx: self.cx, - tables: self.cx.tables(), ignore_fn: true, + ..self } } @@ -72,12 +71,14 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { return false; } - if let (Some(l), Some(r)) = ( - constant_simple(self.cx, self.tables, left), - constant_simple(self.cx, self.tables, right), - ) { - if l == r { - return true; + if let Some(tables) = self.maybe_typeck_tables { + if let (Some(l), Some(r)) = ( + constant_simple(self.cx, tables, left), + constant_simple(self.cx, tables, right), + ) { + if l == r { + return true; + } } } @@ -271,18 +272,18 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { match (left, right) { (&TyKind::Slice(ref l_vec), &TyKind::Slice(ref r_vec)) => self.eq_ty(l_vec, r_vec), (&TyKind::Array(ref lt, ref ll_id), &TyKind::Array(ref rt, ref rl_id)) => { - let full_table = self.tables; + let old_maybe_typeck_tables = self.maybe_typeck_tables; let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id.body)); - self.tables = self.cx.tcx.body_tables(ll_id.body); + self.maybe_typeck_tables = Some(self.cx.tcx.body_tables(ll_id.body)); let ll = celcx.expr(&self.cx.tcx.hir().body(ll_id.body).value); let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id.body)); - self.tables = self.cx.tcx.body_tables(rl_id.body); + self.maybe_typeck_tables = Some(self.cx.tcx.body_tables(rl_id.body)); let rl = celcx.expr(&self.cx.tcx.hir().body(rl_id.body).value); let eq_ty = self.eq_ty(lt, rt); - self.tables = full_table; + self.maybe_typeck_tables = old_maybe_typeck_tables; eq_ty && ll == rl }, (&TyKind::Ptr(ref l_mut), &TyKind::Ptr(ref r_mut)) => { @@ -347,15 +348,15 @@ pub fn over(left: &[X], right: &[X], mut eq_fn: impl FnMut(&X, &X) -> bool) - pub struct SpanlessHash<'a, 'tcx> { /// Context used to evaluate constant expressions. cx: &'a LateContext<'a, 'tcx>, - tables: &'a TypeckTables<'tcx>, + maybe_typeck_tables: Option<&'tcx TypeckTables<'tcx>>, s: StableHasher, } impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { - pub fn new(cx: &'a LateContext<'a, 'tcx>, tables: &'a TypeckTables<'tcx>) -> Self { + pub fn new(cx: &'a LateContext<'a, 'tcx>) -> Self { Self { cx, - tables, + maybe_typeck_tables: cx.maybe_typeck_tables(), s: StableHasher::new(), } } @@ -384,7 +385,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { #[allow(clippy::many_single_char_names, clippy::too_many_lines)] pub fn hash_expr(&mut self, e: &Expr<'_>) { - let simple_const = constant_simple(self.cx, self.tables, e); + let simple_const = self + .maybe_typeck_tables + .and_then(|tables| constant_simple(self.cx, tables, e)); // const hashing may result in the same hash as some unrelated node, so add a sort of // discriminant depending on which path we're choosing next @@ -599,7 +602,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_name(path.ident.name); }, } - // self.cx.tables.qpath_res(p, id).hash(&mut self.s); + // self.maybe_typeck_tables.unwrap().qpath_res(p, id).hash(&mut self.s); } pub fn hash_path(&mut self, p: &Path<'_>) { @@ -728,9 +731,8 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { pub fn hash_body(&mut self, body_id: BodyId) { // swap out TypeckTables when hashing a body - let old_tables = self.tables; - self.tables = self.cx.tcx.body_tables(body_id); + let old_maybe_typeck_tables = self.maybe_typeck_tables.replace(self.cx.tcx.body_tables(body_id)); self.hash_expr(&self.cx.tcx.hir().body(body_id).value); - self.tables = old_tables; + self.maybe_typeck_tables = old_maybe_typeck_tables; } } diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 38468181d026..ca947e9241f0 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -347,7 +347,7 @@ fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty<'_>) -> bool { ) = ty.kind { if let TyKind::Path(ref path) = inner.kind { - if let Res::Def(DefKind::Struct, def_id) = cx.tables().qpath_res(path, inner.hir_id) { + if let Res::Def(DefKind::Struct, def_id) = cx.qpath_res(path, inner.hir_id) { return match_def_path(cx, def_id, &paths::LINT); } } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 69ec4b7ad6d1..8be9ba2c3c24 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -898,7 +898,7 @@ pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { if let ExprKind::Call(ref fun, _) = expr.kind { if let ExprKind::Path(ref qp) = fun.kind { - let res = cx.tables().qpath_res(qp, fun.hir_id); + let res = cx.qpath_res(qp, fun.hir_id); return match res { def::Res::Def(DefKind::Variant | DefKind::Ctor(..), ..) => true, def::Res::Def(_, def_id) => cx.tcx.is_promotable_const_fn(def_id), @@ -914,7 +914,7 @@ pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_, '_>, expr: &Exp pub fn is_refutable(cx: &LateContext<'_, '_>, pat: &Pat<'_>) -> bool { fn is_enum_variant(cx: &LateContext<'_, '_>, qpath: &QPath<'_>, id: HirId) -> bool { matches!( - cx.tables().qpath_res(qpath, id), + cx.qpath_res(qpath, id), def::Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(def::CtorOf::Variant, _), _) ) } @@ -1190,7 +1190,7 @@ pub fn match_function_call<'a, 'tcx>( if_chain! { if let ExprKind::Call(ref fun, ref args) = expr.kind; if let ExprKind::Path(ref qpath) = fun.kind; - if let Some(fun_def_id) = cx.tables().qpath_res(qpath, fun.hir_id).opt_def_id(); + if let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id(); if match_def_path(cx, fun_def_id, path); then { return Some(&args) @@ -1317,7 +1317,7 @@ pub fn is_must_use_func_call(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool let did = match expr.kind { ExprKind::Call(ref path, _) => if_chain! { if let ExprKind::Path(ref qpath) = path.kind; - if let def::Res::Def(_, did) = cx.tables().qpath_res(qpath, path.hir_id); + if let def::Res::Def(_, did) = cx.qpath_res(qpath, path.hir_id); then { Some(did) } else { From 98f6805241f36076d90bda621f55234777573f7a Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 25 Jun 2020 23:41:36 +0300 Subject: [PATCH 0032/1222] Use 'tcx for references to AccessLevels wherever possible. --- clippy_lints/src/approx_const.rs | 8 +- clippy_lints/src/arithmetic.rs | 10 +- clippy_lints/src/assertions_on_constants.rs | 6 +- clippy_lints/src/assign_ops.rs | 8 +- clippy_lints/src/atomic_ordering.rs | 12 +- clippy_lints/src/attrs.rs | 26 +-- clippy_lints/src/await_holding_lock.rs | 8 +- clippy_lints/src/bit_mask.rs | 14 +- clippy_lints/src/blacklisted_name.rs | 4 +- clippy_lints/src/blocks_in_if_conditions.rs | 6 +- clippy_lints/src/booleans.rs | 18 +- clippy_lints/src/bytecount.rs | 4 +- clippy_lints/src/cargo_common_metadata.rs | 6 +- clippy_lints/src/checked_conversions.rs | 10 +- clippy_lints/src/cognitive_complexity.rs | 12 +- clippy_lints/src/comparison_chain.rs | 4 +- clippy_lints/src/consts.rs | 26 +-- clippy_lints/src/copies.rs | 16 +- clippy_lints/src/copy_iterator.rs | 4 +- clippy_lints/src/default_trait_access.rs | 4 +- clippy_lints/src/dereference.rs | 6 +- clippy_lints/src/derive.rs | 20 +- clippy_lints/src/doc.rs | 26 +-- clippy_lints/src/double_comparison.rs | 8 +- clippy_lints/src/drop_bounds.rs | 10 +- clippy_lints/src/drop_forget_ref.rs | 4 +- clippy_lints/src/duration_subsec.rs | 4 +- clippy_lints/src/empty_enum.rs | 4 +- clippy_lints/src/entry.rs | 11 +- clippy_lints/src/enum_clike.rs | 4 +- clippy_lints/src/eq_op.rs | 4 +- clippy_lints/src/erasing_op.rs | 6 +- clippy_lints/src/escape.rs | 6 +- clippy_lints/src/eta_reduction.rs | 10 +- clippy_lints/src/eval_order_dependence.rs | 12 +- clippy_lints/src/exit.rs | 4 +- clippy_lints/src/explicit_write.rs | 4 +- clippy_lints/src/fallible_impl_from.rs | 8 +- clippy_lints/src/float_literal.rs | 4 +- clippy_lints/src/floating_point_arithmetic.rs | 32 +-- clippy_lints/src/format.rs | 14 +- clippy_lints/src/functions.rs | 38 ++-- clippy_lints/src/future_not_send.rs | 4 +- clippy_lints/src/get_last_with_len.rs | 4 +- clippy_lints/src/identity_op.rs | 8 +- clippy_lints/src/if_let_mutex.rs | 22 +- clippy_lints/src/if_let_some_result.rs | 4 +- clippy_lints/src/implicit_return.rs | 8 +- clippy_lints/src/implicit_saturating_sub.rs | 8 +- clippy_lints/src/indexing_slicing.rs | 8 +- clippy_lints/src/infinite_iter.rs | 8 +- clippy_lints/src/inherent_impl.rs | 6 +- clippy_lints/src/inherent_to_string.rs | 6 +- clippy_lints/src/inline_fn_without_body.rs | 6 +- clippy_lints/src/integer_division.rs | 6 +- clippy_lints/src/large_const_arrays.rs | 4 +- clippy_lints/src/large_enum_variant.rs | 4 +- clippy_lints/src/large_stack_arrays.rs | 4 +- clippy_lints/src/len_zero.rs | 28 +-- clippy_lints/src/let_and_return.rs | 8 +- clippy_lints/src/let_if_seq.rs | 12 +- clippy_lints/src/let_underscore.rs | 4 +- clippy_lints/src/lifetimes.rs | 26 +-- clippy_lints/src/loops.rs | 90 ++++---- clippy_lints/src/macro_use.rs | 22 +- clippy_lints/src/main_recursion.rs | 6 +- clippy_lints/src/manual_async_fn.rs | 10 +- clippy_lints/src/map_clone.rs | 8 +- clippy_lints/src/map_unit_fn.rs | 16 +- clippy_lints/src/match_on_vec_items.rs | 10 +- clippy_lints/src/matches.rs | 40 ++-- clippy_lints/src/mem_discriminant.rs | 4 +- clippy_lints/src/mem_forget.rs | 4 +- clippy_lints/src/mem_replace.rs | 10 +- .../src/methods/bind_instead_of_map.rs | 8 +- .../src/methods/inefficient_to_string.rs | 4 +- .../methods/manual_saturating_arithmetic.rs | 4 +- clippy_lints/src/methods/mod.rs | 194 ++++++++---------- .../src/methods/option_map_unwrap_or.rs | 8 +- .../src/methods/unnecessary_filter_map.rs | 12 +- clippy_lints/src/minmax.rs | 12 +- clippy_lints/src/misc.rs | 28 +-- clippy_lints/src/missing_const_for_fn.rs | 6 +- clippy_lints/src/missing_doc.rs | 26 +-- clippy_lints/src/missing_inline.rs | 10 +- clippy_lints/src/modulo_arithmetic.rs | 12 +- clippy_lints/src/multiple_crate_versions.rs | 4 +- clippy_lints/src/mut_key.rs | 16 +- clippy_lints/src/mut_mut.rs | 8 +- clippy_lints/src/mut_reference.rs | 11 +- clippy_lints/src/mutable_debug_assertion.rs | 10 +- clippy_lints/src/mutex_atomic.rs | 4 +- clippy_lints/src/needless_bool.rs | 12 +- clippy_lints/src/needless_borrow.rs | 10 +- clippy_lints/src/needless_borrowed_ref.rs | 4 +- clippy_lints/src/needless_pass_by_value.rs | 4 +- clippy_lints/src/needless_update.rs | 4 +- clippy_lints/src/neg_cmp_op_on_partial_ord.rs | 4 +- clippy_lints/src/neg_multiply.rs | 6 +- clippy_lints/src/new_without_default.rs | 4 +- clippy_lints/src/no_effect.rs | 8 +- clippy_lints/src/non_copy_const.rs | 12 +- clippy_lints/src/open_options.rs | 8 +- .../src/overflow_check_conditional.rs | 4 +- clippy_lints/src/panic_unimplemented.rs | 6 +- clippy_lints/src/partialeq_ne_impl.rs | 4 +- clippy_lints/src/path_buf_push_overwrite.rs | 4 +- clippy_lints/src/ptr.rs | 12 +- clippy_lints/src/ptr_offset_with_cast.rs | 18 +- clippy_lints/src/question_mark.rs | 14 +- clippy_lints/src/ranges.rs | 18 +- clippy_lints/src/redundant_clone.rs | 16 +- .../src/redundant_pattern_matching.rs | 14 +- clippy_lints/src/redundant_pub_crate.rs | 6 +- clippy_lints/src/regex.rs | 16 +- clippy_lints/src/serde_api.rs | 4 +- clippy_lints/src/shadow.rs | 24 +-- .../src/slow_vector_initialization.rs | 14 +- clippy_lints/src/strings.rs | 12 +- clippy_lints/src/suspicious_trait_impl.rs | 6 +- clippy_lints/src/swap.rs | 10 +- clippy_lints/src/temporary_assignment.rs | 6 +- clippy_lints/src/to_digit_is_some.rs | 4 +- clippy_lints/src/trait_bounds.rs | 4 +- clippy_lints/src/transmute.rs | 8 +- clippy_lints/src/transmuting_null.rs | 4 +- .../src/trivially_copy_pass_by_ref.rs | 8 +- clippy_lints/src/try_err.rs | 8 +- clippy_lints/src/types.rs | 136 ++++++------ clippy_lints/src/unicode.rs | 6 +- clippy_lints/src/unnamed_address.rs | 8 +- clippy_lints/src/unnecessary_sort_by.rs | 8 +- clippy_lints/src/unused_io_amount.rs | 6 +- clippy_lints/src/unused_self.rs | 6 +- clippy_lints/src/unwrap.rs | 14 +- clippy_lints/src/use_self.rs | 14 +- clippy_lints/src/useless_conversion.rs | 6 +- clippy_lints/src/utils/author.rs | 20 +- clippy_lints/src/utils/diagnostics.rs | 4 +- clippy_lints/src/utils/higher.rs | 4 +- clippy_lints/src/utils/hir_utils.rs | 8 +- clippy_lints/src/utils/inspector.rs | 28 +-- clippy_lints/src/utils/internal_lints.rs | 35 ++-- clippy_lints/src/utils/mod.rs | 72 +++---- clippy_lints/src/utils/ptr.rs | 8 +- clippy_lints/src/utils/sugg.rs | 10 +- clippy_lints/src/utils/usage.rs | 8 +- clippy_lints/src/vec.rs | 6 +- clippy_lints/src/vec_resize_to_zero.rs | 4 +- clippy_lints/src/verbose_file_reads.rs | 8 +- clippy_lints/src/wildcard_dependencies.rs | 4 +- clippy_lints/src/wildcard_imports.rs | 6 +- clippy_lints/src/zero_div_zero.rs | 4 +- doc/common_tools_writing_lints.md | 16 +- tests/ui/outer_expn_data.fixed | 4 +- tests/ui/outer_expn_data.rs | 4 +- 156 files changed, 966 insertions(+), 1041 deletions(-) diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index 7e6e2c7eaebe..1d511a86c909 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -60,15 +60,15 @@ const KNOWN_CONSTS: [(f64, &str, usize); 18] = [ declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for ApproxConstant { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::Lit(lit) = &e.kind { check_lit(cx, &lit.node, e); } } } -fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr<'_>) { +fn check_lit(cx: &LateContext<'_>, lit: &LitKind, e: &Expr<'_>) { match *lit { LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty { FloatTy::F32 => check_known_consts(cx, e, s, "f32"), @@ -79,7 +79,7 @@ fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr<'_>) { } } -fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr<'_>, s: symbol::Symbol, module: &str) { +fn check_known_consts(cx: &LateContext<'_>, e: &Expr<'_>, s: symbol::Symbol, module: &str) { let s = s.as_str(); if s.parse::().is_ok() { for &(constant, name, min_digits) in &KNOWN_CONSTS { diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs index cc09b99cf1dd..da60856fac93 100644 --- a/clippy_lints/src/arithmetic.rs +++ b/clippy_lints/src/arithmetic.rs @@ -58,8 +58,8 @@ pub struct Arithmetic { impl_lint_pass!(Arithmetic => [INTEGER_ARITHMETIC, FLOAT_ARITHMETIC]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for Arithmetic { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if self.expr_span.is_some() { return; } @@ -111,13 +111,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic { } } - fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { + fn check_expr_post(&mut self, _: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if Some(expr.span) == self.expr_span { self.expr_span = None; } } - fn check_body(&mut self, cx: &LateContext<'_, '_>, body: &hir::Body<'_>) { + fn check_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { let body_owner = cx.tcx.hir().body_owner(body.id()); match cx.tcx.hir().body_owner_kind(body_owner) { @@ -135,7 +135,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic { } } - fn check_body_post(&mut self, cx: &LateContext<'_, '_>, body: &hir::Body<'_>) { + fn check_body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { let body_owner = cx.tcx.hir().body_owner(body.id()); let body_span = cx.tcx.hir().span(body_owner); diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index c4536b57f8a9..cffe8d94e279 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -29,8 +29,8 @@ declare_clippy_lint! { declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { let lint_true = |is_debug: bool| { span_lint_and_help( cx, @@ -114,7 +114,7 @@ enum AssertKind { /// ``` /// /// where `message` is any expression and `c` is a constant bool. -fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option { +fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option { if_chain! { if let ExprKind::Match(ref expr, ref arms, _) = expr.kind; // matches { let _t = expr; _t } diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index 51a7647d3208..bc6e868823f7 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -60,9 +60,9 @@ declare_clippy_lint! { declare_lint_pass!(AssignOps => [ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { +impl<'tcx> LateLintPass<'tcx> for AssignOps { #[allow(clippy::too_many_lines)] - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { match &expr.kind { hir::ExprKind::AssignOp(op, lhs, rhs) => { if let hir::ExprKind::Binary(binop, l, r) = &rhs.kind { @@ -191,7 +191,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { } fn lint_misrefactored_assign_op( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, expr: &hir::Expr<'_>, op: hir::BinOp, rhs: &hir::Expr<'_>, @@ -246,7 +246,7 @@ fn is_commutative(op: hir::BinOpKind) -> bool { struct ExprVisitor<'a, 'tcx> { assignee: &'a hir::Expr<'a>, counter: u8, - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, } impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> { diff --git a/clippy_lints/src/atomic_ordering.rs b/clippy_lints/src/atomic_ordering.rs index 1115ba1bf922..efd3f0f671cd 100644 --- a/clippy_lints/src/atomic_ordering.rs +++ b/clippy_lints/src/atomic_ordering.rs @@ -52,7 +52,7 @@ const ATOMIC_TYPES: [&str; 12] = [ "AtomicUsize", ]; -fn type_is_atomic(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { +fn type_is_atomic(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.tables().expr_ty(expr).kind { ATOMIC_TYPES .iter() @@ -62,13 +62,13 @@ fn type_is_atomic(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { } } -fn match_ordering_def_path(cx: &LateContext<'_, '_>, did: DefId, orderings: &[&str]) -> bool { +fn match_ordering_def_path(cx: &LateContext<'_>, did: DefId, orderings: &[&str]) -> bool { orderings .iter() .any(|ordering| match_def_path(cx, did, &["core", "sync", "atomic", "Ordering", ordering])) } -fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { +fn check_atomic_load_store(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind; let method = method_path.ident.name.as_str(); @@ -103,7 +103,7 @@ fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { } } -fn check_memory_fence(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { +fn check_memory_fence(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Call(ref func, ref args) = expr.kind; if let ExprKind::Path(ref func_qpath) = func.kind; @@ -127,8 +127,8 @@ fn check_memory_fence(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AtomicOrdering { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for AtomicOrdering { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { check_atomic_load_store(cx, expr); check_memory_fence(cx, expr); } diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 41f125d48398..2505ff32fe52 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -251,8 +251,8 @@ declare_lint_pass!(Attributes => [ UNKNOWN_CLIPPY_LINTS, ]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes { - fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) { +impl<'tcx> LateLintPass<'tcx> for Attributes { + fn check_attribute(&mut self, cx: &LateContext<'tcx>, attr: &'tcx Attribute) { if let Some(items) = &attr.meta_item_list() { if let Some(ident) = attr.ident() { match &*ident.as_str() { @@ -278,7 +278,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes { } } - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if is_relevant_item(cx, item) { check_attrs(cx, item.span, item.ident.name, &item.attrs) } @@ -350,13 +350,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes { } } - fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem<'_>) { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { if is_relevant_impl(cx, item) { check_attrs(cx, item.span, item.ident.name, &item.attrs) } } - fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem<'_>) { + fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { if is_relevant_trait(cx, item) { check_attrs(cx, item.span, item.ident.name, &item.attrs) } @@ -364,7 +364,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes { } #[allow(clippy::single_match_else)] -fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) { +fn check_clippy_lint_names(cx: &LateContext<'_>, items: &[NestedMetaItem]) { let lint_store = cx.lints(); for lint in items { if_chain! { @@ -416,7 +416,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) { } } -fn is_relevant_item(cx: &LateContext<'_, '_>, item: &Item<'_>) -> bool { +fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool { if let ItemKind::Fn(_, _, eid) = item.kind { is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value) } else { @@ -424,14 +424,14 @@ fn is_relevant_item(cx: &LateContext<'_, '_>, item: &Item<'_>) -> bool { } } -fn is_relevant_impl(cx: &LateContext<'_, '_>, item: &ImplItem<'_>) -> bool { +fn is_relevant_impl(cx: &LateContext<'_>, item: &ImplItem<'_>) -> bool { match item.kind { ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value), _ => false, } } -fn is_relevant_trait(cx: &LateContext<'_, '_>, item: &TraitItem<'_>) -> bool { +fn is_relevant_trait(cx: &LateContext<'_>, item: &TraitItem<'_>) -> bool { match item.kind { TraitItemKind::Fn(_, TraitFn::Required(_)) => true, TraitItemKind::Fn(_, TraitFn::Provided(eid)) => { @@ -441,7 +441,7 @@ fn is_relevant_trait(cx: &LateContext<'_, '_>, item: &TraitItem<'_>) -> bool { } } -fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, block: &Block<'_>) -> bool { +fn is_relevant_block(cx: &LateContext<'_>, tables: &ty::TypeckTables<'_>, block: &Block<'_>) -> bool { if let Some(stmt) = block.stmts.first() { match &stmt.kind { StmtKind::Local(_) => true, @@ -453,7 +453,7 @@ fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, bl } } -fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr<'_>) -> bool { +fn is_relevant_expr(cx: &LateContext<'_>, tables: &ty::TypeckTables<'_>, expr: &Expr<'_>) -> bool { match &expr.kind { ExprKind::Block(block, _) => is_relevant_block(cx, tables, block), ExprKind::Ret(Some(e)) => is_relevant_expr(cx, tables, e), @@ -473,7 +473,7 @@ fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, exp } } -fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attribute]) { +fn check_attrs(cx: &LateContext<'_>, span: Span, name: Name, attrs: &[Attribute]) { if span.from_expansion() { return; } @@ -498,7 +498,7 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib } } -fn check_semver(cx: &LateContext<'_, '_>, span: Span, lit: &Lit) { +fn check_semver(cx: &LateContext<'_>, span: Span, lit: &Lit) { if let LitKind::Str(is, _) = lit.kind { if Version::parse(&is.as_str()).is_ok() { return; diff --git a/clippy_lints/src/await_holding_lock.rs b/clippy_lints/src/await_holding_lock.rs index a88f922d8e03..20b91bc0f1ba 100644 --- a/clippy_lints/src/await_holding_lock.rs +++ b/clippy_lints/src/await_holding_lock.rs @@ -51,8 +51,8 @@ declare_clippy_lint! { declare_lint_pass!(AwaitHoldingLock => [AWAIT_HOLDING_LOCK]); -impl LateLintPass<'_, '_> for AwaitHoldingLock { - fn check_body(&mut self, cx: &LateContext<'_, '_>, body: &'_ Body<'_>) { +impl LateLintPass<'_> for AwaitHoldingLock { + fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { use AsyncGeneratorKind::{Block, Closure, Fn}; if let Some(GeneratorKind::Async(Block | Closure | Fn)) = body.generator_kind { let body_id = BodyId { @@ -65,7 +65,7 @@ impl LateLintPass<'_, '_> for AwaitHoldingLock { } } -fn check_interior_types(cx: &LateContext<'_, '_>, ty_causes: &[GeneratorInteriorTypeCause<'_>], span: Span) { +fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorTypeCause<'_>], span: Span) { for ty_cause in ty_causes { if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind { if is_mutex_guard(cx, adt.did) { @@ -82,7 +82,7 @@ fn check_interior_types(cx: &LateContext<'_, '_>, ty_causes: &[GeneratorInterior } } -fn is_mutex_guard(cx: &LateContext<'_, '_>, def_id: DefId) -> bool { +fn is_mutex_guard(cx: &LateContext<'_>, def_id: DefId) -> bool { match_def_path(cx, def_id, &paths::MUTEX_GUARD) || match_def_path(cx, def_id, &paths::RWLOCK_READ_GUARD) || match_def_path(cx, def_id, &paths::RWLOCK_WRITE_GUARD) diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index a53f3249b85b..d1d177e7a4ab 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -110,8 +110,8 @@ impl BitMask { impl_lint_pass!(BitMask => [BAD_BIT_MASK, INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for BitMask { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::Binary(cmp, left, right) = &e.kind { if cmp.node.is_comparison() { if let Some(cmp_opt) = fetch_int_literal(cx, right) { @@ -164,7 +164,7 @@ fn invert_cmp(cmp: BinOpKind) -> BinOpKind { } } -fn check_compare(cx: &LateContext<'_, '_>, bit_op: &Expr<'_>, cmp_op: BinOpKind, cmp_value: u128, span: Span) { +fn check_compare(cx: &LateContext<'_>, bit_op: &Expr<'_>, cmp_op: BinOpKind, cmp_value: u128, span: Span) { if let ExprKind::Binary(op, left, right) = &bit_op.kind { if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr { return; @@ -177,7 +177,7 @@ fn check_compare(cx: &LateContext<'_, '_>, bit_op: &Expr<'_>, cmp_op: BinOpKind, #[allow(clippy::too_many_lines)] fn check_bit_mask( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, bit_op: BinOpKind, cmp_op: BinOpKind, mask_value: u128, @@ -290,7 +290,7 @@ fn check_bit_mask( } } -fn check_ineffective_lt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128, op: &str) { +fn check_ineffective_lt(cx: &LateContext<'_>, span: Span, m: u128, c: u128, op: &str) { if c.is_power_of_two() && m < c { span_lint( cx, @@ -304,7 +304,7 @@ fn check_ineffective_lt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128, } } -fn check_ineffective_gt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128, op: &str) { +fn check_ineffective_gt(cx: &LateContext<'_>, span: Span, m: u128, c: u128, op: &str) { if (c + 1).is_power_of_two() && m <= c { span_lint( cx, @@ -318,7 +318,7 @@ fn check_ineffective_gt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128, } } -fn fetch_int_literal(cx: &LateContext<'_, '_>, lit: &Expr<'_>) -> Option { +fn fetch_int_literal(cx: &LateContext<'_>, lit: &Expr<'_>) -> Option { match constant(cx, cx.tables(), lit)?.0 { Constant::Int(n) => Some(n), _ => None, diff --git a/clippy_lints/src/blacklisted_name.rs b/clippy_lints/src/blacklisted_name.rs index 6f26f031431d..153870fb4165 100644 --- a/clippy_lints/src/blacklisted_name.rs +++ b/clippy_lints/src/blacklisted_name.rs @@ -35,8 +35,8 @@ impl BlacklistedName { impl_lint_pass!(BlacklistedName => [BLACKLISTED_NAME]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlacklistedName { - fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat<'_>) { +impl<'tcx> LateLintPass<'tcx> for BlacklistedName { + fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { if let PatKind::Binding(.., ident, _) = pat.kind { if self.blacklist.contains(&ident.name.to_string()) { span_lint( diff --git a/clippy_lints/src/blocks_in_if_conditions.rs b/clippy_lints/src/blocks_in_if_conditions.rs index 8fa9b05ca329..1b73ced89b32 100644 --- a/clippy_lints/src/blocks_in_if_conditions.rs +++ b/clippy_lints/src/blocks_in_if_conditions.rs @@ -45,7 +45,7 @@ declare_lint_pass!(BlocksInIfConditions => [BLOCKS_IN_IF_CONDITIONS]); struct ExVisitor<'a, 'tcx> { found_block: Option<&'tcx Expr<'tcx>>, - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, } impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> { @@ -71,8 +71,8 @@ const BRACED_EXPR_MESSAGE: &str = "omit braces around single expression conditio const COMPLEX_BLOCK_MESSAGE: &str = "in an `if` condition, avoid complex blocks or closures with blocks; \ instead, move the block or closure higher and bind it with a `let`"; -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlocksInIfConditions { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for BlocksInIfConditions { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if in_external_macro(cx.sess(), expr.span) { return; } diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index cc399a1f8a00..32d0979e99b6 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -55,10 +55,10 @@ const METHODS_WITH_NEGATION: [(&str, &str); 2] = [("is_some", "is_none"), ("is_e declare_lint_pass!(NonminimalBool => [NONMINIMAL_BOOL, LOGIC_BUG]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool { +impl<'tcx> LateLintPass<'tcx> for NonminimalBool { fn check_fn( &mut self, - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, _: FnKind<'tcx>, _: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, @@ -70,13 +70,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool { } struct NonminimalBoolVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, } use quine_mc_cluskey::Bool; struct Hir2Qmm<'a, 'tcx, 'v> { terminals: Vec<&'v Expr<'v>>, - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, } impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> { @@ -155,7 +155,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> { struct SuggestContext<'a, 'tcx, 'v> { terminals: &'v [&'v Expr<'v>], - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, output: String, } @@ -222,7 +222,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> { } } -fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option { +fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { match &expr.kind { ExprKind::Binary(binop, lhs, rhs) => { if !implements_ord(cx, lhs) { @@ -268,7 +268,7 @@ fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option { } } -fn suggest(cx: &LateContext<'_, '_>, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String { +fn suggest(cx: &LateContext<'_>, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String { let mut suggest_context = SuggestContext { terminals, cx, @@ -464,13 +464,13 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { } } -fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool { +fn implements_ord<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool { let ty = cx.tables().expr_ty(expr); get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[])) } struct NotSimplificationVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, } impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> { diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index c00bb23069bf..1cdfea1f5265 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -35,8 +35,8 @@ declare_clippy_lint! { declare_lint_pass!(ByteCount => [NAIVE_BYTECOUNT]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount { - fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for ByteCount { + fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::MethodCall(ref count, _, ref count_args, _) = expr.kind; if count.ident.name == sym!(count); diff --git a/clippy_lints/src/cargo_common_metadata.rs b/clippy_lints/src/cargo_common_metadata.rs index c40a387d2979..76a000157df0 100644 --- a/clippy_lints/src/cargo_common_metadata.rs +++ b/clippy_lints/src/cargo_common_metadata.rs @@ -36,7 +36,7 @@ declare_clippy_lint! { "common metadata is defined in `Cargo.toml`" } -fn missing_warning(cx: &LateContext<'_, '_>, package: &cargo_metadata::Package, field: &str) { +fn missing_warning(cx: &LateContext<'_>, package: &cargo_metadata::Package, field: &str) { let message = format!("package `{}` is missing `{}` metadata", package.name, field); span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, &message); } @@ -56,8 +56,8 @@ fn is_empty_vec(value: &[String]) -> bool { declare_lint_pass!(CargoCommonMetadata => [CARGO_COMMON_METADATA]); -impl LateLintPass<'_, '_> for CargoCommonMetadata { - fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) { +impl LateLintPass<'_> for CargoCommonMetadata { + fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { if !run_lints(cx, &[CARGO_COMMON_METADATA], CRATE_HIR_ID) { return; } diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs index 88145015ba8b..841902943f00 100644 --- a/clippy_lints/src/checked_conversions.rs +++ b/clippy_lints/src/checked_conversions.rs @@ -41,8 +41,8 @@ declare_clippy_lint! { declare_lint_pass!(CheckedConversions => [CHECKED_CONVERSIONS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CheckedConversions { - fn check_expr(&mut self, cx: &LateContext<'_, '_>, item: &Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for CheckedConversions { + fn check_expr(&mut self, cx: &LateContext<'_>, item: &Expr<'_>) { let result = if_chain! { if !in_external_macro(cx.sess(), item.span); if let ExprKind::Binary(op, ref left, ref right) = &item.kind; @@ -83,7 +83,7 @@ fn single_check<'tcx>(expr: &'tcx Expr<'tcx>) -> Option> { } /// Searches for a combination of upper & lower bound checks -fn double_check<'a>(cx: &LateContext<'_, '_>, left: &'a Expr<'_>, right: &'a Expr<'_>) -> Option> { +fn double_check<'a>(cx: &LateContext<'_>, left: &'a Expr<'_>, right: &'a Expr<'_>) -> Option> { let upper_lower = |l, r| { let upper = check_upper_bound(l); let lower = check_lower_bound(r); @@ -112,7 +112,7 @@ enum ConversionType { impl<'a> Conversion<'a> { /// Combine multiple conversions if the are compatible - pub fn combine(self, other: Self, cx: &LateContext<'_, '_>) -> Option> { + pub fn combine(self, other: Self, cx: &LateContext<'_>) -> Option> { if self.is_compatible(&other, cx) { // Prefer a Conversion that contains a type-constraint Some(if self.to_type.is_some() { self } else { other }) @@ -123,7 +123,7 @@ impl<'a> Conversion<'a> { /// Checks if two conversions are compatible /// same type of conversion, same 'castee' and same 'to type' - pub fn is_compatible(&self, other: &Self, cx: &LateContext<'_, '_>) -> bool { + pub fn is_compatible(&self, other: &Self, cx: &LateContext<'_>) -> bool { (self.cvt == other.cvt) && (SpanlessEq::new(cx).eq_expr(self.expr_to_cast, other.expr_to_cast)) && (self.has_compatible_to_type(other)) diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index 78e509d2ecd8..6bbdbe957cc8 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -43,9 +43,9 @@ impl_lint_pass!(CognitiveComplexity => [COGNITIVE_COMPLEXITY]); impl CognitiveComplexity { #[allow(clippy::cast_possible_truncation)] - fn check<'a, 'tcx>( + fn check<'tcx>( &mut self, - cx: &'a LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, @@ -112,10 +112,10 @@ impl CognitiveComplexity { } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CognitiveComplexity { +impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity { fn check_fn( &mut self, - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, @@ -128,10 +128,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CognitiveComplexity { } } - fn enter_lint_attrs(&mut self, cx: &LateContext<'a, 'tcx>, attrs: &'tcx [Attribute]) { + fn enter_lint_attrs(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) { self.limit.push_attrs(cx.sess(), attrs, "cognitive_complexity"); } - fn exit_lint_attrs(&mut self, cx: &LateContext<'a, 'tcx>, attrs: &'tcx [Attribute]) { + fn exit_lint_attrs(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) { self.limit.pop_attrs(cx.sess(), attrs, "cognitive_complexity"); } } diff --git a/clippy_lints/src/comparison_chain.rs b/clippy_lints/src/comparison_chain.rs index 9c0d33f92801..26476af4cb62 100644 --- a/clippy_lints/src/comparison_chain.rs +++ b/clippy_lints/src/comparison_chain.rs @@ -52,8 +52,8 @@ declare_clippy_lint! { declare_lint_pass!(ComparisonChain => [COMPARISON_CHAIN]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ComparisonChain { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for ComparisonChain { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if expr.span.from_expansion() { return; } diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 550752396c73..2f963dfcf8b1 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -172,9 +172,9 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option>) -> Constant { } } -pub fn constant<'c, 'cc>( - lcx: &LateContext<'c, 'cc>, - tables: &'c ty::TypeckTables<'cc>, +pub fn constant<'tcx>( + lcx: &LateContext<'tcx>, + tables: &ty::TypeckTables<'tcx>, e: &Expr<'_>, ) -> Option<(Constant, bool)> { let mut cx = ConstEvalLateContext { @@ -187,19 +187,19 @@ pub fn constant<'c, 'cc>( cx.expr(e).map(|cst| (cst, cx.needed_resolution)) } -pub fn constant_simple<'c, 'cc>( - lcx: &LateContext<'c, 'cc>, - tables: &'c ty::TypeckTables<'cc>, +pub fn constant_simple<'tcx>( + lcx: &LateContext<'tcx>, + tables: &ty::TypeckTables<'tcx>, e: &Expr<'_>, ) -> Option { constant(lcx, tables, e).and_then(|(cst, res)| if res { None } else { Some(cst) }) } /// Creates a `ConstEvalLateContext` from the given `LateContext` and `TypeckTables`. -pub fn constant_context<'c, 'cc>( - lcx: &'c LateContext<'c, 'cc>, - tables: &'c ty::TypeckTables<'cc>, -) -> ConstEvalLateContext<'c, 'cc> { +pub fn constant_context<'a, 'tcx>( + lcx: &'a LateContext<'tcx>, + tables: &'a ty::TypeckTables<'tcx>, +) -> ConstEvalLateContext<'a, 'tcx> { ConstEvalLateContext { lcx, tables, @@ -210,14 +210,14 @@ pub fn constant_context<'c, 'cc>( } pub struct ConstEvalLateContext<'a, 'tcx> { - lcx: &'a LateContext<'a, 'tcx>, + lcx: &'a LateContext<'tcx>, tables: &'a ty::TypeckTables<'tcx>, param_env: ty::ParamEnv<'tcx>, needed_resolution: bool, substs: SubstsRef<'tcx>, } -impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { +impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { /// Simple constant folding: Insert an expression, get a constant or none. pub fn expr(&mut self, e: &Expr<'_>) -> Option { if let Some((ref cond, ref then, otherwise)) = higher::if_block(&e) { @@ -318,7 +318,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { } /// Lookup a possibly constant expression from a `ExprKind::Path`. - fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'cc>) -> Option { + fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'tcx>) -> Option { let res = self.tables.qpath_res(qpath, id); match res { Res::Def(DefKind::Const | DefKind::AssocConst, def_id) => { diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 8cc69c806aa9..1257032337ac 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -151,8 +151,8 @@ declare_clippy_lint! { declare_lint_pass!(CopyAndPaste => [IFS_SAME_COND, SAME_FUNCTIONS_IN_IF_CONDITION, IF_SAME_THEN_ELSE, MATCH_SAME_ARMS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for CopyAndPaste { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if !expr.span.from_expansion() { // skip ifs directly in else, it will be checked in the parent if if let Some(expr) = get_parent_expr(cx, expr) { @@ -173,7 +173,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste { } /// Implementation of `IF_SAME_THEN_ELSE`. -fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block<'_>]) { +fn lint_same_then_else(cx: &LateContext<'_>, blocks: &[&Block<'_>]) { let eq: &dyn Fn(&&Block<'_>, &&Block<'_>) -> bool = &|&lhs, &rhs| -> bool { SpanlessEq::new(cx).eq_block(lhs, rhs) }; @@ -190,7 +190,7 @@ fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block<'_>]) { } /// Implementation of `IFS_SAME_COND`. -fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { +fn lint_same_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>]) { let hash: &dyn Fn(&&Expr<'_>) -> u64 = &|expr| -> u64 { let mut h = SpanlessHash::new(cx); h.hash_expr(expr); @@ -213,7 +213,7 @@ fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { } /// Implementation of `SAME_FUNCTIONS_IN_IF_CONDITION`. -fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { +fn lint_same_fns_in_if_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>]) { let hash: &dyn Fn(&&Expr<'_>) -> u64 = &|expr| -> u64 { let mut h = SpanlessHash::new(cx); h.hash_expr(expr); @@ -241,7 +241,7 @@ fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { } /// Implementation of `MATCH_SAME_ARMS`. -fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>) { +fn lint_match_arms<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) { fn same_bindings<'tcx>(lhs: &FxHashMap>, rhs: &FxHashMap>) -> bool { lhs.len() == rhs.len() && lhs @@ -309,8 +309,8 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>) { } /// Returns the list of bindings in a pattern. -fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat<'_>) -> FxHashMap> { - fn bindings_impl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat<'_>, map: &mut FxHashMap>) { +fn bindings<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'_>) -> FxHashMap> { + fn bindings_impl<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'_>, map: &mut FxHashMap>) { match pat.kind { PatKind::Box(ref pat) | PatKind::Ref(ref pat, _) => bindings_impl(cx, pat, map), PatKind::TupleStruct(_, pats, _) => { diff --git a/clippy_lints/src/copy_iterator.rs b/clippy_lints/src/copy_iterator.rs index d79aa2ef0209..349402453226 100644 --- a/clippy_lints/src/copy_iterator.rs +++ b/clippy_lints/src/copy_iterator.rs @@ -31,8 +31,8 @@ declare_clippy_lint! { declare_lint_pass!(CopyIterator => [COPY_ITERATOR]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for CopyIterator { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if let ItemKind::Impl { of_trait: Some(ref trait_ref), .. diff --git a/clippy_lints/src/default_trait_access.rs b/clippy_lints/src/default_trait_access.rs index a918c72fb275..fab95db01960 100644 --- a/clippy_lints/src/default_trait_access.rs +++ b/clippy_lints/src/default_trait_access.rs @@ -30,8 +30,8 @@ declare_clippy_lint! { declare_lint_pass!(DefaultTraitAccess => [DEFAULT_TRAIT_ACCESS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for DefaultTraitAccess { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Call(ref path, ..) = expr.kind; if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id); diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 1c6cc9369009..d740d88a77d6 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -38,8 +38,8 @@ declare_lint_pass!(Dereferencing => [ EXPLICIT_DEREF_METHODS ]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Dereferencing { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for Dereferencing { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if !expr.span.from_expansion(); if let ExprKind::MethodCall(ref method_name, _, ref args, _) = &expr.kind; @@ -70,7 +70,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Dereferencing { } } -fn lint_deref(cx: &LateContext<'_, '_>, method_name: &str, call_expr: &Expr<'_>, var_span: Span, expr_span: Span) { +fn lint_deref(cx: &LateContext<'_>, method_name: &str, call_expr: &Expr<'_>, var_span: Span, expr_span: Span) { match method_name { "deref" => { if cx.tcx.lang_items().deref_trait().map_or(false, |id| { diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 3cbb8fa72f74..59c62f1ae944 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -105,8 +105,8 @@ declare_clippy_lint! { declare_lint_pass!(Derive => [EXPL_IMPL_CLONE_ON_COPY, DERIVE_HASH_XOR_EQ, UNSAFE_DERIVE_DESERIALIZE]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for Derive { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if let ItemKind::Impl { of_trait: Some(ref trait_ref), .. @@ -127,8 +127,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive { } /// Implementation of the `DERIVE_HASH_XOR_EQ` lint. -fn check_hash_peq<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn check_hash_peq<'tcx>( + cx: &LateContext<'tcx>, span: Span, trait_ref: &TraitRef<'_>, ty: Ty<'tcx>, @@ -181,7 +181,7 @@ fn check_hash_peq<'a, 'tcx>( } /// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint. -fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item<'_>, trait_ref: &TraitRef<'_>, ty: Ty<'tcx>) { +fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &TraitRef<'_>, ty: Ty<'tcx>) { if match_path(&trait_ref.path, &paths::CLONE_TRAIT) { if !is_copy(cx, ty) { return; @@ -222,18 +222,18 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item<'_>, trait } /// Implementation of the `UNSAFE_DERIVE_DESERIALIZE` lint. -fn check_unsafe_derive_deserialize<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn check_unsafe_derive_deserialize<'tcx>( + cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &TraitRef<'_>, ty: Ty<'tcx>, ) { - fn item_from_def_id<'tcx>(cx: &LateContext<'_, 'tcx>, def_id: DefId) -> &'tcx Item<'tcx> { + fn item_from_def_id<'tcx>(cx: &LateContext<'tcx>, def_id: DefId) -> &'tcx Item<'tcx> { let hir_id = cx.tcx.hir().as_local_hir_id(def_id.expect_local()); cx.tcx.hir().expect_item(hir_id) } - fn has_unsafe<'tcx>(cx: &LateContext<'_, 'tcx>, item: &'tcx Item<'_>) -> bool { + fn has_unsafe<'tcx>(cx: &LateContext<'tcx>, item: &'tcx Item<'_>) -> bool { let mut visitor = UnsafeVisitor { cx, has_unsafe: false }; walk_item(&mut visitor, item); visitor.has_unsafe @@ -261,7 +261,7 @@ fn check_unsafe_derive_deserialize<'a, 'tcx>( } struct UnsafeVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, has_unsafe: bool, } diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 8d1e91f9adbd..d52bb8961fae 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -146,12 +146,12 @@ impl DocMarkdown { impl_lint_pass!(DocMarkdown => [DOC_MARKDOWN, MISSING_SAFETY_DOC, MISSING_ERRORS_DOC, NEEDLESS_DOCTEST_MAIN]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown { - fn check_crate(&mut self, cx: &LateContext<'a, 'tcx>, krate: &'tcx hir::Crate<'_>) { +impl<'tcx> LateLintPass<'tcx> for DocMarkdown { + fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) { check_attrs(cx, &self.valid_idents, &krate.item.attrs); } - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'_>) { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { let headers = check_attrs(cx, &self.valid_idents, &item.attrs); match item.kind { hir::ItemKind::Fn(ref sig, _, body_id) => { @@ -171,13 +171,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown { } } - fn check_item_post(&mut self, _cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'_>) { + fn check_item_post(&mut self, _cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { if let hir::ItemKind::Impl { .. } = item.kind { self.in_trait_impl = false; } } - fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem<'_>) { + fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { let headers = check_attrs(cx, &self.valid_idents, &item.attrs); if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { if !in_external_macro(cx.tcx.sess, item.span) { @@ -186,7 +186,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown { } } - fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::ImplItem<'_>) { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { let headers = check_attrs(cx, &self.valid_idents, &item.attrs); if self.in_trait_impl || in_external_macro(cx.tcx.sess, item.span) { return; @@ -197,8 +197,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown { } } -fn lint_for_missing_headers<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn lint_for_missing_headers<'tcx>( + cx: &LateContext<'tcx>, hir_id: hir::HirId, span: impl Into + Copy, sig: &hir::FnSig<'_>, @@ -313,7 +313,7 @@ struct DocHeaders { errors: bool, } -fn check_attrs<'a>(cx: &LateContext<'_, '_>, valid_idents: &FxHashSet, attrs: &'a [Attribute]) -> DocHeaders { +fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &'a [Attribute]) -> DocHeaders { let mut doc = String::new(); let mut spans = vec![]; @@ -370,7 +370,7 @@ fn check_attrs<'a>(cx: &LateContext<'_, '_>, valid_idents: &FxHashSet, a const RUST_CODE: &[&str] = &["rust", "no_run", "should_panic", "compile_fail", "edition2018"]; fn check_doc<'a, Events: Iterator, Range)>>( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, valid_idents: &FxHashSet, events: Events, spans: &[(usize, Span)], @@ -442,13 +442,13 @@ fn check_doc<'a, Events: Iterator, Range, text: &str, span: Span) { +fn check_code(cx: &LateContext<'_>, text: &str, span: Span) { if text.contains("fn main() {") && !LEAVE_MAIN_PATTERNS.iter().any(|p| text.contains(p)) { span_lint(cx, NEEDLESS_DOCTEST_MAIN, span, "needless `fn main` in doctest"); } } -fn check_text(cx: &LateContext<'_, '_>, valid_idents: &FxHashSet, text: &str, span: Span) { +fn check_text(cx: &LateContext<'_>, valid_idents: &FxHashSet, text: &str, span: Span) { for word in text.split(|c: char| c.is_whitespace() || c == '\'') { // Trim punctuation as in `some comment (see foo::bar).` // ^^ @@ -471,7 +471,7 @@ fn check_text(cx: &LateContext<'_, '_>, valid_idents: &FxHashSet, text: } } -fn check_word(cx: &LateContext<'_, '_>, word: &str, span: Span) { +fn check_word(cx: &LateContext<'_>, word: &str, span: Span) { /// Checks if a string is camel-case, i.e., contains at least two uppercase /// letters (`Clippy` is ok) and one lower-case letter (`NASA` is ok). /// Plurals are also excluded (`IDs` is ok). diff --git a/clippy_lints/src/double_comparison.rs b/clippy_lints/src/double_comparison.rs index 44f85d1ea6e1..5d16192b7543 100644 --- a/clippy_lints/src/double_comparison.rs +++ b/clippy_lints/src/double_comparison.rs @@ -37,9 +37,9 @@ declare_clippy_lint! { declare_lint_pass!(DoubleComparisons => [DOUBLE_COMPARISONS]); -impl<'a, 'tcx> DoubleComparisons { +impl<'tcx> DoubleComparisons { #[allow(clippy::similar_names)] - fn check_binop(cx: &LateContext<'a, 'tcx>, op: BinOpKind, lhs: &'tcx Expr<'_>, rhs: &'tcx Expr<'_>, span: Span) { + fn check_binop(cx: &LateContext<'tcx>, op: BinOpKind, lhs: &'tcx Expr<'_>, rhs: &'tcx Expr<'_>, span: Span) { let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (&lhs.kind, &rhs.kind) { (ExprKind::Binary(lb, llhs, lrhs), ExprKind::Binary(rb, rlhs, rrhs)) => { (lb.node, llhs, lrhs, rb.node, rlhs, rrhs) @@ -86,8 +86,8 @@ impl<'a, 'tcx> DoubleComparisons { } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DoubleComparisons { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for DoubleComparisons { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = expr.kind { Self::check_binop(cx, kind.node, lhs, rhs, expr.span); } diff --git a/clippy_lints/src/drop_bounds.rs b/clippy_lints/src/drop_bounds.rs index 5a7f759486ed..4afbd1ed0e59 100644 --- a/clippy_lints/src/drop_bounds.rs +++ b/clippy_lints/src/drop_bounds.rs @@ -1,7 +1,7 @@ use crate::utils::{match_def_path, paths, span_lint}; use if_chain::if_chain; use rustc_hir::{GenericBound, GenericParam, WhereBoundPredicate, WherePredicate}; -use rustc_lint::LateLintPass; +use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { @@ -41,13 +41,13 @@ const DROP_BOUNDS_SUMMARY: &str = "Bounds of the form `T: Drop` are useless. \ declare_lint_pass!(DropBounds => [DROP_BOUNDS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropBounds { - fn check_generic_param(&mut self, cx: &rustc_lint::LateContext<'a, 'tcx>, p: &'tcx GenericParam<'_>) { +impl<'tcx> LateLintPass<'tcx> for DropBounds { + fn check_generic_param(&mut self, cx: &LateContext<'tcx>, p: &'tcx GenericParam<'_>) { for bound in p.bounds.iter() { lint_bound(cx, bound); } } - fn check_where_predicate(&mut self, cx: &rustc_lint::LateContext<'a, 'tcx>, p: &'tcx WherePredicate<'_>) { + fn check_where_predicate(&mut self, cx: &LateContext<'tcx>, p: &'tcx WherePredicate<'_>) { if let WherePredicate::BoundPredicate(WhereBoundPredicate { bounds, .. }) = p { for bound in *bounds { lint_bound(cx, bound); @@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropBounds { } } -fn lint_bound<'a, 'tcx>(cx: &rustc_lint::LateContext<'a, 'tcx>, bound: &'tcx GenericBound<'_>) { +fn lint_bound<'tcx>(cx: &LateContext<'tcx>, bound: &'tcx GenericBound<'_>) { if_chain! { if let GenericBound::Trait(t, _) = bound; if let Some(def_id) = t.trait_ref.path.res.opt_def_id(); diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 014873eb1325..dcf772572e8c 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -108,8 +108,8 @@ const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that declare_lint_pass!(DropForgetRef => [DROP_REF, FORGET_REF, DROP_COPY, FORGET_COPY]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for DropForgetRef { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Call(ref path, ref args) = expr.kind; if let ExprKind::Path(ref qpath) = path.kind; diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index 5eb320ceca24..2ded375091c6 100644 --- a/clippy_lints/src/duration_subsec.rs +++ b/clippy_lints/src/duration_subsec.rs @@ -38,8 +38,8 @@ declare_clippy_lint! { declare_lint_pass!(DurationSubsec => [DURATION_SUBSEC]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for DurationSubsec { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, ref left, ref right) = expr.kind; if let ExprKind::MethodCall(ref method_path, _ , ref args, _) = left.kind; diff --git a/clippy_lints/src/empty_enum.rs b/clippy_lints/src/empty_enum.rs index 3bfef6f4bed1..a249117d182f 100644 --- a/clippy_lints/src/empty_enum.rs +++ b/clippy_lints/src/empty_enum.rs @@ -38,8 +38,8 @@ declare_clippy_lint! { declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum { - fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for EmptyEnum { + fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { let did = cx.tcx.hir().local_def_id(item.hir_id); if let ItemKind::Enum(..) = item.kind { let ty = cx.tcx.type_of(did); diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index e37e23b8944d..4d2e17933ed6 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -52,8 +52,8 @@ declare_clippy_lint! { declare_lint_pass!(HashMapPass => [MAP_ENTRY]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapPass { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for HashMapPass { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let Some((ref check, ref then_block, ref else_block)) = higher::if_block(&expr) { if let ExprKind::Unary(UnOp::UnNot, ref check) = check.kind { if let Some((ty, map, key)) = check_cond(cx, check) { @@ -98,10 +98,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapPass { } } -fn check_cond<'a, 'tcx, 'b>( - cx: &'a LateContext<'a, 'tcx>, - check: &'b Expr<'b>, -) -> Option<(&'static str, &'b Expr<'b>, &'b Expr<'b>)> { +fn check_cond<'a>(cx: &LateContext<'_>, check: &'a Expr<'a>) -> Option<(&'static str, &'a Expr<'a>, &'a Expr<'a>)> { if_chain! { if let ExprKind::MethodCall(ref path, _, ref params, _) = check.kind; if params.len() >= 2; @@ -127,7 +124,7 @@ fn check_cond<'a, 'tcx, 'b>( } struct InsertVisitor<'a, 'tcx, 'b> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, span: Span, ty: &'static str, map: &'b Expr<'b>, diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index 12b62f5cf978..91214f277be6 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -36,9 +36,9 @@ declare_clippy_lint! { declare_lint_pass!(UnportableVariant => [ENUM_CLIKE_UNPORTABLE_VARIANT]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant { +impl<'tcx> LateLintPass<'tcx> for UnportableVariant { #[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::cast_sign_loss)] - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if cx.tcx.data_layout.pointer_size.bits() != 64 { return; } diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 98757624a13b..ca921dcfdfe9 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -52,9 +52,9 @@ declare_clippy_lint! { declare_lint_pass!(EqOp => [EQ_OP, OP_REF]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { +impl<'tcx> LateLintPass<'tcx> for EqOp { #[allow(clippy::similar_names, clippy::too_many_lines)] - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::Binary(op, ref left, ref right) = e.kind { if e.span.from_expansion() { return; diff --git a/clippy_lints/src/erasing_op.rs b/clippy_lints/src/erasing_op.rs index 804a9c1904b7..8a2683806182 100644 --- a/clippy_lints/src/erasing_op.rs +++ b/clippy_lints/src/erasing_op.rs @@ -29,8 +29,8 @@ declare_clippy_lint! { declare_lint_pass!(ErasingOp => [ERASING_OP]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for ErasingOp { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if e.span.from_expansion() { return; } @@ -47,7 +47,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp { } } -fn check(cx: &LateContext<'_, '_>, e: &Expr<'_>, span: Span) { +fn check(cx: &LateContext<'_>, e: &Expr<'_>, span: Span) { if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables(), e) { span_lint( cx, diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index bb74f193a48e..d40cdfcca9f6 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -49,17 +49,17 @@ fn is_non_trait_box(ty: Ty<'_>) -> bool { } struct EscapeDelegate<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, set: HirIdSet, too_large_for_stack: u64, } impl_lint_pass!(BoxedLocal => [BOXED_LOCAL]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal { +impl<'tcx> LateLintPass<'tcx> for BoxedLocal { fn check_fn( &mut self, - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, _: intravisit::FnKind<'tcx>, _: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 0ac8b95de8d6..ceed6a74c4fc 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -64,8 +64,8 @@ declare_clippy_lint! { declare_lint_pass!(EtaReduction => [REDUNDANT_CLOSURE, REDUNDANT_CLOSURE_FOR_METHOD_CALLS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaReduction { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for EtaReduction { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if in_external_macro(cx.sess(), expr.span) { return; } @@ -81,7 +81,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaReduction { } } -fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { +fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) { if let ExprKind::Closure(_, ref decl, eid, _, _) = expr.kind { let body = cx.tcx.hir().body(eid); let ex = &body.value; @@ -151,7 +151,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { } /// Tries to determine the type for universal function call to be used instead of the closure -fn get_ufcs_type_name(cx: &LateContext<'_, '_>, method_def_id: def_id::DefId, self_arg: &Expr<'_>) -> Option { +fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: def_id::DefId, self_arg: &Expr<'_>) -> Option { let expected_type_of_self = &cx.tcx.fn_sig(method_def_id).inputs_and_output().skip_binder()[0]; let actual_type_of_self = &cx.tables().node_type(self_arg.hir_id); @@ -196,7 +196,7 @@ fn match_types(lhs: Ty<'_>, rhs: Ty<'_>) -> bool { } } -fn get_type_name(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> String { +fn get_type_name(cx: &LateContext<'_>, ty: Ty<'_>) -> String { match ty.kind { ty::Adt(t, _) => cx.tcx.def_path_str(t.did), ty::Ref(_, r, _) => get_type_name(cx, &r), diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 31fe7382e46d..01b0d3c5edec 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -67,8 +67,8 @@ declare_clippy_lint! { declare_lint_pass!(EvalOrderDependence => [EVAL_ORDER_DEPENDENCE, DIVERGING_SUB_EXPRESSION]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for EvalOrderDependence { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { // Find a write to a local variable. match expr.kind { ExprKind::Assign(ref lhs, ..) | ExprKind::AssignOp(_, ref lhs, _) => { @@ -91,7 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence { _ => {}, } } - fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) { + fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { match stmt.kind { StmtKind::Local(ref local) => { if let Local { init: Some(ref e), .. } = **local { @@ -105,7 +105,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence { } struct DivergenceVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, } impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> { @@ -285,7 +285,7 @@ fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt<'_>) - /// A visitor that looks for reads from a variable. struct ReadVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, /// The ID of the variable we're looking for. var: HirId, /// The expressions where the write to the variable occurred (for reporting @@ -354,7 +354,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> { } /// Returns `true` if `expr` is the LHS of an assignment, like `expr = ...`. -fn is_in_assignment_position(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { +fn is_in_assignment_position(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { if let Some(parent) = get_parent_expr(cx, expr) { if let ExprKind::Assign(ref lhs, ..) = parent.kind { return lhs.hir_id == expr.hir_id; diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index 621d56185a9d..7337d98c8be3 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -24,8 +24,8 @@ declare_clippy_lint! { declare_lint_pass!(Exit => [EXIT]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for Exit { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Call(ref path_expr, ref _args) = e.kind; if let ExprKind::Path(ref path) = path_expr.kind; diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 7269e2b52c2c..0240e80d8141 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -28,8 +28,8 @@ declare_clippy_lint! { declare_lint_pass!(ExplicitWrite => [EXPLICIT_WRITE]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitWrite { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for ExplicitWrite { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { // match call to unwrap if let ExprKind::MethodCall(ref unwrap_fun, _, ref unwrap_args, _) = expr.kind; diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 92812816461c..01ed0c426d43 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -52,8 +52,8 @@ declare_clippy_lint! { declare_lint_pass!(FallibleImplFrom => [FALLIBLE_IMPL_FROM]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { // check for `impl From for ..` let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id); if_chain! { @@ -67,12 +67,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom { } } -fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_items: &[hir::ImplItemRef<'_>]) { +fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[hir::ImplItemRef<'_>]) { use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::{Expr, ExprKind, ImplItemKind, QPath}; struct FindPanicUnwrap<'a, 'tcx> { - lcx: &'a LateContext<'a, 'tcx>, + lcx: &'a LateContext<'tcx>, tables: &'tcx ty::TypeckTables<'tcx>, result: Vec, } diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index cd3d443ec58e..a3d2a949535a 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -58,8 +58,8 @@ declare_clippy_lint! { declare_lint_pass!(FloatLiteral => [EXCESSIVE_PRECISION, LOSSY_FLOAT_LITERAL]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FloatLiteral { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for FloatLiteral { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if_chain! { let ty = cx.tables().expr_ty(expr); if let ty::Float(fty) = ty.kind; diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index 76713cb1afc4..4efd06892679 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -111,7 +111,7 @@ declare_lint_pass!(FloatingPointArithmetic => [ // Returns the specialized log method for a given base if base is constant // and is one of 2, 10 and e -fn get_specialized_log_method(cx: &LateContext<'_, '_>, base: &Expr<'_>) -> Option<&'static str> { +fn get_specialized_log_method(cx: &LateContext<'_>, base: &Expr<'_>) -> Option<&'static str> { if let Some((value, _)) = constant(cx, cx.tables(), base) { if F32(2.0) == value || F64(2.0) == value { return Some("log2"); @@ -126,7 +126,7 @@ fn get_specialized_log_method(cx: &LateContext<'_, '_>, base: &Expr<'_>) -> Opti } // Adds type suffixes and parenthesis to method receivers if necessary -fn prepare_receiver_sugg<'a>(cx: &LateContext<'_, '_>, mut expr: &'a Expr<'a>) -> Sugg<'a> { +fn prepare_receiver_sugg<'a>(cx: &LateContext<'_>, mut expr: &'a Expr<'a>) -> Sugg<'a> { let mut suggestion = Sugg::hir(cx, expr, ".."); if let ExprKind::Unary(UnOp::UnNeg, inner_expr) = &expr.kind { @@ -163,7 +163,7 @@ fn prepare_receiver_sugg<'a>(cx: &LateContext<'_, '_>, mut expr: &'a Expr<'a>) - suggestion.maybe_par() } -fn check_log_base(cx: &LateContext<'_, '_>, expr: &Expr<'_>, args: &[Expr<'_>]) { +fn check_log_base(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { if let Some(method) = get_specialized_log_method(cx, &args[1]) { span_lint_and_sugg( cx, @@ -179,7 +179,7 @@ fn check_log_base(cx: &LateContext<'_, '_>, expr: &Expr<'_>, args: &[Expr<'_>]) // TODO: Lint expressions of the form `(x + y).ln()` where y > 1 and // suggest usage of `(x + (y - 1)).ln_1p()` instead -fn check_ln1p(cx: &LateContext<'_, '_>, expr: &Expr<'_>, args: &[Expr<'_>]) { +fn check_ln1p(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { if let ExprKind::Binary( Spanned { node: BinOpKind::Add, .. @@ -231,7 +231,7 @@ fn get_integer_from_float_constant(value: &Constant) -> Option { } } -fn check_powf(cx: &LateContext<'_, '_>, expr: &Expr<'_>, args: &[Expr<'_>]) { +fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { // Check receiver if let Some((value, _)) = constant(cx, cx.tables(), &args[0]) { let method = if F32(f32_consts::E) == value || F64(f64_consts::E) == value { @@ -295,7 +295,7 @@ fn check_powf(cx: &LateContext<'_, '_>, expr: &Expr<'_>, args: &[Expr<'_>]) { // TODO: Lint expressions of the form `x.exp() - y` where y > 1 // and suggest usage of `x.exp_m1() - (y - 1)` instead -fn check_expm1(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { +fn check_expm1(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Binary(Spanned { node: BinOpKind::Sub, .. }, ref lhs, ref rhs) = expr.kind; if cx.tables().expr_ty(lhs).is_floating_point(); @@ -321,7 +321,7 @@ fn check_expm1(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { } } -fn is_float_mul_expr<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option<(&'a Expr<'a>, &'a Expr<'a>)> { +fn is_float_mul_expr<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(&'a Expr<'a>, &'a Expr<'a>)> { if_chain! { if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, ref lhs, ref rhs) = &expr.kind; if cx.tables().expr_ty(lhs).is_floating_point(); @@ -335,7 +335,7 @@ fn is_float_mul_expr<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option } // TODO: Fix rust-lang/rust-clippy#4735 -fn check_mul_add(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { +fn check_mul_add(cx: &LateContext<'_>, expr: &Expr<'_>) { if let ExprKind::Binary( Spanned { node: BinOpKind::Add, .. @@ -373,7 +373,7 @@ fn check_mul_add(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { /// test is positive or an expression which tests whether or not test /// is nonnegative. /// Used for check-custom-abs function below -fn is_testing_positive(cx: &LateContext<'_, '_>, expr: &Expr<'_>, test: &Expr<'_>) -> bool { +fn is_testing_positive(cx: &LateContext<'_>, expr: &Expr<'_>, test: &Expr<'_>) -> bool { if let ExprKind::Binary(Spanned { node: op, .. }, left, right) = expr.kind { match op { BinOpKind::Gt | BinOpKind::Ge => is_zero(cx, right) && are_exprs_equal(cx, left, test), @@ -386,7 +386,7 @@ fn is_testing_positive(cx: &LateContext<'_, '_>, expr: &Expr<'_>, test: &Expr<'_ } /// See [`is_testing_positive`] -fn is_testing_negative(cx: &LateContext<'_, '_>, expr: &Expr<'_>, test: &Expr<'_>) -> bool { +fn is_testing_negative(cx: &LateContext<'_>, expr: &Expr<'_>, test: &Expr<'_>) -> bool { if let ExprKind::Binary(Spanned { node: op, .. }, left, right) = expr.kind { match op { BinOpKind::Gt | BinOpKind::Ge => is_zero(cx, left) && are_exprs_equal(cx, right, test), @@ -398,12 +398,12 @@ fn is_testing_negative(cx: &LateContext<'_, '_>, expr: &Expr<'_>, test: &Expr<'_ } } -fn are_exprs_equal(cx: &LateContext<'_, '_>, expr1: &Expr<'_>, expr2: &Expr<'_>) -> bool { +fn are_exprs_equal(cx: &LateContext<'_>, expr1: &Expr<'_>, expr2: &Expr<'_>) -> bool { SpanlessEq::new(cx).ignore_fn().eq_expr(expr1, expr2) } /// Returns true iff expr is some zero literal -fn is_zero(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { +fn is_zero(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { match constant_simple(cx, cx.tables(), expr) { Some(Constant::Int(i)) => i == 0, Some(Constant::F32(f)) => f == 0.0, @@ -418,7 +418,7 @@ fn is_zero(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { /// one of the two expressions /// If the two expressions are not negations of each other, then it /// returns None. -fn are_negated<'a>(cx: &LateContext<'_, '_>, expr1: &'a Expr<'a>, expr2: &'a Expr<'a>) -> Option<(bool, &'a Expr<'a>)> { +fn are_negated<'a>(cx: &LateContext<'_>, expr1: &'a Expr<'a>, expr2: &'a Expr<'a>) -> Option<(bool, &'a Expr<'a>)> { if let ExprKind::Unary(UnOp::UnNeg, expr1_negated) = &expr1.kind { if are_exprs_equal(cx, expr1_negated, expr2) { return Some((false, expr2)); @@ -432,7 +432,7 @@ fn are_negated<'a>(cx: &LateContext<'_, '_>, expr1: &'a Expr<'a>, expr2: &'a Exp None } -fn check_custom_abs(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { +fn check_custom_abs(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let Some((cond, body, Some(else_body))) = higher::if_block(&expr); if let ExprKind::Block(block, _) = body.kind; @@ -479,8 +479,8 @@ fn check_custom_abs(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FloatingPointArithmetic { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for FloatingPointArithmetic { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::MethodCall(ref path, _, args, _) = &expr.kind { let recv_ty = cx.tables().expr_ty(&args[0]); diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index dc8795e3d11e..33b6bfc459f9 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -40,8 +40,8 @@ declare_clippy_lint! { declare_lint_pass!(UselessFormat => [USELESS_FORMAT]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessFormat { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for UselessFormat { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { let span = match is_expn_of(expr.span, "format") { Some(s) if !s.from_expansion() => s, _ => return, @@ -75,11 +75,7 @@ fn span_useless_format(cx: &T, span: Span, help: &str, mut sugg: }); } -fn on_argumentv1_new<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, - expr: &'tcx Expr<'_>, - arms: &'tcx [Arm<'_>], -) -> Option { +fn on_argumentv1_new<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arms: &'tcx [Arm<'_>]) -> Option { if_chain! { if let ExprKind::AddrOf(BorrowKind::Ref, _, ref format_args) = expr.kind; if let ExprKind::Array(ref elems) = arms[0].body.kind; @@ -118,7 +114,7 @@ fn on_argumentv1_new<'a, 'tcx>( None } -fn on_new_v1<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option { +fn on_new_v1<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option { if_chain! { if let Some(args) = match_function_call(cx, expr, &paths::FMT_ARGUMENTS_NEW_V1); if args.len() == 2; @@ -145,7 +141,7 @@ fn on_new_v1<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Opti None } -fn on_new_v1_fmt<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option { +fn on_new_v1_fmt<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option { if_chain! { if let Some(args) = match_function_call(cx, expr, &paths::FMT_ARGUMENTS_NEW_V1_FORMATTED); if args.len() == 3; diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 1f9bd7a691b5..3f030dd84225 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -190,10 +190,10 @@ impl_lint_pass!(Functions => [ MUST_USE_CANDIDATE, ]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions { +impl<'tcx> LateLintPass<'tcx> for Functions { fn check_fn( &mut self, - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, kind: intravisit::FnKind<'tcx>, decl: &'tcx hir::FnDecl<'_>, body: &'tcx hir::Body<'_>, @@ -230,7 +230,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions { self.check_line_number(cx, span, body); } - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'_>) { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { let attr = must_use_attr(&item.attrs); if let hir::ItemKind::Fn(ref sig, ref _generics, ref body_id) = item.kind { if let Some(attr) = attr { @@ -255,7 +255,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions { } } - fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::ImplItem<'_>) { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind { let attr = must_use_attr(&item.attrs); if let Some(attr) = attr { @@ -278,7 +278,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions { } } - fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem<'_>) { + fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { if let hir::TraitItemKind::Fn(ref sig, ref eid) = item.kind { // don't lint extern functions decls, it's not their fault if sig.header.abi == Abi::Rust { @@ -310,8 +310,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions { } } -impl<'a, 'tcx> Functions { - fn check_arg_number(self, cx: &LateContext<'_, '_>, decl: &hir::FnDecl<'_>, fn_span: Span) { +impl<'tcx> Functions { + fn check_arg_number(self, cx: &LateContext<'_>, decl: &hir::FnDecl<'_>, fn_span: Span) { let args = decl.inputs.len() as u64; if args > self.threshold { span_lint( @@ -323,7 +323,7 @@ impl<'a, 'tcx> Functions { } } - fn check_line_number(self, cx: &LateContext<'_, '_>, span: Span, body: &'tcx hir::Body<'_>) { + fn check_line_number(self, cx: &LateContext<'_>, span: Span, body: &'tcx hir::Body<'_>) { if in_external_macro(cx.sess(), span) { return; } @@ -378,7 +378,7 @@ impl<'a, 'tcx> Functions { } fn check_raw_ptr( - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, unsafety: hir::Unsafety, decl: &'tcx hir::FnDecl<'_>, body: &'tcx hir::Body<'_>, @@ -406,7 +406,7 @@ impl<'a, 'tcx> Functions { } fn check_needless_must_use( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, decl: &hir::FnDecl<'_>, item_id: hir::HirId, item_span: Span, @@ -443,8 +443,8 @@ fn check_needless_must_use( } } -fn check_must_use_candidate<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn check_must_use_candidate<'tcx>( + cx: &LateContext<'tcx>, decl: &'tcx hir::FnDecl<'_>, body: &'tcx hir::Body<'_>, item_span: Span, @@ -484,12 +484,12 @@ fn returns_unit(decl: &hir::FnDecl<'_>) -> bool { } } -fn has_mutable_arg(cx: &LateContext<'_, '_>, body: &hir::Body<'_>) -> bool { +fn has_mutable_arg(cx: &LateContext<'_>, body: &hir::Body<'_>) -> bool { let mut tys = FxHashSet::default(); body.params.iter().any(|param| is_mutable_pat(cx, ¶m.pat, &mut tys)) } -fn is_mutable_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>, tys: &mut FxHashSet) -> bool { +fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut FxHashSet) -> bool { if let hir::PatKind::Wild = pat.kind { return false; // ignore `_` patterns } @@ -508,7 +508,7 @@ fn is_mutable_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>, tys: &mut FxHash static KNOWN_WRAPPER_TYS: &[&[&str]] = &[&["alloc", "rc", "Rc"], &["std", "sync", "Arc"]]; -fn is_mutable_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Span, tys: &mut FxHashSet) -> bool { +fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, tys: &mut FxHashSet) -> bool { match ty.kind { // primitive types are never mutable ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false, @@ -537,7 +537,7 @@ fn raw_ptr_arg(arg: &hir::Param<'_>, ty: &hir::Ty<'_>) -> Option { } struct DerefVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, ptrs: FxHashSet, tables: &'a ty::TypeckTables<'tcx>, } @@ -596,7 +596,7 @@ impl<'a, 'tcx> DerefVisitor<'a, 'tcx> { } struct StaticMutVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, mutates_static: bool, } @@ -641,7 +641,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { } } -fn is_mutated_static(cx: &LateContext<'_, '_>, e: &hir::Expr<'_>) -> bool { +fn is_mutated_static(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> bool { use hir::ExprKind::{Field, Index, Path}; match e.kind { @@ -657,7 +657,7 @@ fn is_mutated_static(cx: &LateContext<'_, '_>, e: &hir::Expr<'_>) -> bool { } } -fn mutates_static<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, body: &'tcx hir::Body<'_>) -> bool { +fn mutates_static<'tcx>(cx: &LateContext<'tcx>, body: &'tcx hir::Body<'_>) -> bool { let mut v = StaticMutVisitor { cx, mutates_static: false, diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 17dd3cd5493e..92c7e66a0eb8 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -47,10 +47,10 @@ declare_clippy_lint! { declare_lint_pass!(FutureNotSend => [FUTURE_NOT_SEND]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FutureNotSend { +impl<'tcx> LateLintPass<'tcx> for FutureNotSend { fn check_fn( &mut self, - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'tcx>, _: &'tcx Body<'tcx>, diff --git a/clippy_lints/src/get_last_with_len.rs b/clippy_lints/src/get_last_with_len.rs index 57a7fbb56567..2d93ecc00a76 100644 --- a/clippy_lints/src/get_last_with_len.rs +++ b/clippy_lints/src/get_last_with_len.rs @@ -43,8 +43,8 @@ declare_clippy_lint! { declare_lint_pass!(GetLastWithLen => [GET_LAST_WITH_LEN]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for GetLastWithLen { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for GetLastWithLen { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { // Is a method call if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs index 1c25e050997e..dc9d636bc6de 100644 --- a/clippy_lints/src/identity_op.rs +++ b/clippy_lints/src/identity_op.rs @@ -28,8 +28,8 @@ declare_clippy_lint! { declare_lint_pass!(IdentityOp => [IDENTITY_OP]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for IdentityOp { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if e.span.from_expansion() { return; } @@ -58,7 +58,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp { } } -fn is_allowed(cx: &LateContext<'_, '_>, cmp: BinOp, left: &Expr<'_>, right: &Expr<'_>) -> bool { +fn is_allowed(cx: &LateContext<'_>, cmp: BinOp, left: &Expr<'_>, right: &Expr<'_>) -> bool { // `1 << 0` is a common pattern in bit manipulation code if_chain! { if let BinOpKind::Shl = cmp.node; @@ -73,7 +73,7 @@ fn is_allowed(cx: &LateContext<'_, '_>, cmp: BinOp, left: &Expr<'_>, right: &Exp } #[allow(clippy::cast_possible_wrap)] -fn check(cx: &LateContext<'_, '_>, e: &Expr<'_>, m: i8, span: Span, arg: Span) { +fn check(cx: &LateContext<'_>, e: &Expr<'_>, m: i8, span: Span, arg: Span) { if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables(), e) { let check = match cx.tables().expr_ty(e).kind { ty::Int(ity) => unsext(cx.tcx, -1_i128, ity), diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index e357c7b3b2eb..f911cb68ea57 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -40,8 +40,8 @@ declare_clippy_lint! { declare_lint_pass!(IfLetMutex => [IF_LET_MUTEX]); -impl LateLintPass<'_, '_> for IfLetMutex { - fn check_expr(&mut self, cx: &LateContext<'_, '_>, ex: &'_ Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for IfLetMutex { + fn check_expr(&mut self, cx: &LateContext<'tcx>, ex: &'tcx Expr<'tcx>) { let mut arm_visit = ArmVisitor { mutex_lock_called: false, found_mutex: None, @@ -82,13 +82,13 @@ impl LateLintPass<'_, '_> for IfLetMutex { } /// Checks if `Mutex::lock` is called in the `if let _ = expr. -pub struct OppVisitor<'tcx, 'l> { +pub struct OppVisitor<'a, 'tcx> { mutex_lock_called: bool, found_mutex: Option<&'tcx Expr<'tcx>>, - cx: &'tcx LateContext<'tcx, 'l>, + cx: &'a LateContext<'tcx>, } -impl<'tcx, 'l> Visitor<'tcx> for OppVisitor<'tcx, 'l> { +impl<'tcx> Visitor<'tcx> for OppVisitor<'_, 'tcx> { type Map = Map<'tcx>; fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { @@ -109,13 +109,13 @@ impl<'tcx, 'l> Visitor<'tcx> for OppVisitor<'tcx, 'l> { } /// Checks if `Mutex::lock` is called in any of the branches. -pub struct ArmVisitor<'tcx, 'l> { +pub struct ArmVisitor<'a, 'tcx> { mutex_lock_called: bool, found_mutex: Option<&'tcx Expr<'tcx>>, - cx: &'tcx LateContext<'tcx, 'l>, + cx: &'a LateContext<'tcx>, } -impl<'tcx, 'l> Visitor<'tcx> for ArmVisitor<'tcx, 'l> { +impl<'tcx> Visitor<'tcx> for ArmVisitor<'_, 'tcx> { type Map = Map<'tcx>; fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { @@ -135,8 +135,8 @@ impl<'tcx, 'l> Visitor<'tcx> for ArmVisitor<'tcx, 'l> { } } -impl<'tcx, 'l> ArmVisitor<'tcx, 'l> { - fn same_mutex(&self, cx: &LateContext<'_, '_>, op_mutex: &Expr<'_>) -> bool { +impl<'tcx> ArmVisitor<'_, 'tcx> { + fn same_mutex(&self, cx: &LateContext<'_>, op_mutex: &Expr<'_>) -> bool { if let Some(arm_mutex) = self.found_mutex { SpanlessEq::new(cx).eq_expr(op_mutex, arm_mutex) } else { @@ -145,7 +145,7 @@ impl<'tcx, 'l> ArmVisitor<'tcx, 'l> { } } -fn is_mutex_lock_call<'a>(cx: &LateContext<'a, '_>, expr: &'a Expr<'_>) -> Option<&'a Expr<'a>> { +fn is_mutex_lock_call<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { if_chain! { if let ExprKind::MethodCall(path, _span, args, _) = &expr.kind; if path.ident.to_string() == "lock"; diff --git a/clippy_lints/src/if_let_some_result.rs b/clippy_lints/src/if_let_some_result.rs index 3f1ae9b86d38..9e2989dc01e5 100644 --- a/clippy_lints/src/if_let_some_result.rs +++ b/clippy_lints/src/if_let_some_result.rs @@ -37,8 +37,8 @@ declare_clippy_lint! { declare_lint_pass!(OkIfLet => [IF_LET_SOME_RESULT]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OkIfLet { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for OkIfLet { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { //begin checking variables if let ExprKind::Match(ref op, ref body, source) = expr.kind; //test if expr is a match if let MatchSource::IfLetDesugar { .. } = source; //test if it is an If Let diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index b43babc1de87..22c4fef32a32 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -44,7 +44,7 @@ declare_lint_pass!(ImplicitReturn => [IMPLICIT_RETURN]); static LINT_BREAK: &str = "change `break` to `return` as shown"; static LINT_RETURN: &str = "add `return` as shown"; -fn lint(cx: &LateContext<'_, '_>, outer_span: Span, inner_span: Span, msg: &str) { +fn lint(cx: &LateContext<'_>, outer_span: Span, inner_span: Span, msg: &str) { let outer_span = outer_span.source_callsite(); let inner_span = inner_span.source_callsite(); @@ -60,7 +60,7 @@ fn lint(cx: &LateContext<'_, '_>, outer_span: Span, inner_span: Span, msg: &str) }); } -fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { +fn expr_match(cx: &LateContext<'_>, expr: &Expr<'_>) { match expr.kind { // loops could be using `break` instead of `return` ExprKind::Block(block, ..) | ExprKind::Loop(block, ..) => { @@ -122,10 +122,10 @@ fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitReturn { +impl<'tcx> LateLintPass<'tcx> for ImplicitReturn { fn check_fn( &mut self, - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, _: FnKind<'tcx>, _: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index 1a6cb0b0c566..f38530aca0ce 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -36,8 +36,8 @@ declare_clippy_lint! { declare_lint_pass!(ImplicitSaturatingSub => [IMPLICIT_SATURATING_SUB]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitSaturatingSub { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) { +impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if in_macro(expr.span) { return; } @@ -118,7 +118,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitSaturatingSub { } } -fn subtracts_one<'a>(cx: &LateContext<'_, '_>, expr: &Expr<'a>) -> Option<&'a Expr<'a>> { +fn subtracts_one<'a>(cx: &LateContext<'_>, expr: &Expr<'a>) -> Option<&'a Expr<'a>> { match expr.kind { ExprKind::AssignOp(ref op1, ref target, ref value) => { if_chain! { @@ -153,7 +153,7 @@ fn subtracts_one<'a>(cx: &LateContext<'_, '_>, expr: &Expr<'a>) -> Option<&'a Ex } } -fn print_lint_and_sugg(cx: &LateContext<'_, '_>, var_name: &str, expr: &Expr<'_>) { +fn print_lint_and_sugg(cx: &LateContext<'_>, var_name: &str, expr: &Expr<'_>) { span_lint_and_sugg( cx, IMPLICIT_SATURATING_SUB, diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index c5e4abc94a8a..5857a405b0cf 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -85,8 +85,8 @@ declare_clippy_lint! { declare_lint_pass!(IndexingSlicing => [INDEXING_SLICING, OUT_OF_BOUNDS_INDEXING]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Index(ref array, ref index) = &expr.kind { let ty = cx.tables().expr_ty(array); if let Some(range) = higher::range(cx, index) { @@ -164,8 +164,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing { /// Returns a tuple of options with the start and end (exclusive) values of /// the range. If the start or end is not constant, None is returned. -fn to_const_range<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn to_const_range<'tcx>( + cx: &LateContext<'tcx>, range: higher::Range<'_>, array_size: u128, ) -> (Option, Option) { diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index 38f086c9221f..3ffc2dd60d9c 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -44,8 +44,8 @@ declare_clippy_lint! { declare_lint_pass!(InfiniteIter => [INFINITE_ITER, MAYBE_INFINITE_ITER]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InfiniteIter { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for InfiniteIter { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { let (lint, msg) = match complete_infinite_iter(cx, expr) { Infinite => (INFINITE_ITER, "infinite iteration detected"), MaybeInfinite => (MAYBE_INFINITE_ITER, "possible infinite iteration detected"), @@ -140,7 +140,7 @@ const HEURISTICS: [(&str, usize, Heuristic, Finiteness); 19] = [ ("scan", 3, First, MaybeInfinite), ]; -fn is_infinite(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Finiteness { +fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { match expr.kind { ExprKind::MethodCall(ref method, _, ref args, _) => { for &(name, len, heuristic, cap) in &HEURISTICS { @@ -216,7 +216,7 @@ const INFINITE_COLLECTORS: [&[&str]; 8] = [ &paths::VEC_DEQUE, ]; -fn complete_infinite_iter(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Finiteness { +fn complete_infinite_iter(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { match expr.kind { ExprKind::MethodCall(ref method, _, ref args, _) => { for &(name, len) in &COMPLETING_METHODS { diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index 7e2975ac2ae9..bd7ca0388394 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -47,8 +47,8 @@ pub struct MultipleInherentImpl { impl_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl { - fn check_item(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { + fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) { if let ItemKind::Impl { ref generics, of_trait: None, @@ -64,7 +64,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl { } } - fn check_crate_post(&mut self, cx: &LateContext<'a, 'tcx>, krate: &'tcx Crate<'_>) { + fn check_crate_post(&mut self, cx: &LateContext<'tcx>, krate: &'tcx Crate<'_>) { if let Some(item) = krate.items.values().next() { // Retrieve all inherent implementations from the crate, grouped by type for impls in cx diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index 289628a2752a..f330fa8fab8f 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -92,8 +92,8 @@ declare_clippy_lint! { declare_lint_pass!(InherentToString => [INHERENT_TO_STRING, INHERENT_TO_STRING_SHADOW_DISPLAY]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InherentToString { - fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx ImplItem<'_>) { +impl<'tcx> LateLintPass<'tcx> for InherentToString { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { if impl_item.span.from_expansion() { return; } @@ -119,7 +119,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InherentToString { } } -fn show_lint(cx: &LateContext<'_, '_>, item: &ImplItem<'_>) { +fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) { let display_trait_id = get_trait_def_id(cx, &paths::DISPLAY_TRAIT).expect("Failed to get trait ID of `Display`!"); // Get the real type of 'self' diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index 475610dda475..decbee278154 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -31,15 +31,15 @@ declare_clippy_lint! { declare_lint_pass!(InlineFnWithoutBody => [INLINE_FN_WITHOUT_BODY]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InlineFnWithoutBody { - fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem<'_>) { +impl<'tcx> LateLintPass<'tcx> for InlineFnWithoutBody { + fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { if let TraitItemKind::Fn(_, TraitFn::Required(_)) = item.kind { check_attrs(cx, item.ident.name, &item.attrs); } } } -fn check_attrs(cx: &LateContext<'_, '_>, name: Symbol, attrs: &[Attribute]) { +fn check_attrs(cx: &LateContext<'_>, name: Symbol, attrs: &[Attribute]) { for attr in attrs { if !attr.check_name(sym!(inline)) { continue; diff --git a/clippy_lints/src/integer_division.rs b/clippy_lints/src/integer_division.rs index 83ae1c1a971e..e754c7b482a6 100644 --- a/clippy_lints/src/integer_division.rs +++ b/clippy_lints/src/integer_division.rs @@ -30,8 +30,8 @@ declare_clippy_lint! { declare_lint_pass!(IntegerDivision => [INTEGER_DIVISION]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IntegerDivision { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for IntegerDivision { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if is_integer_division(cx, expr) { span_lint_and_help( cx, @@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IntegerDivision { } } -fn is_integer_division<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) -> bool { +fn is_integer_division<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) -> bool { if_chain! { if let hir::ExprKind::Binary(binop, left, right) = &expr.kind; if let hir::BinOpKind::Div = &binop.node; diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index c9e12fc535ec..c6cc174a8c97 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -45,8 +45,8 @@ impl LargeConstArrays { impl_lint_pass!(LargeConstArrays => [LARGE_CONST_ARRAYS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeConstArrays { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for LargeConstArrays { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if_chain! { if !item.span.from_expansion(); if let ItemKind::Const(hir_ty, _) = &item.kind; diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index 5bc3234e3252..3c7880d74ee6 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -56,8 +56,8 @@ impl LargeEnumVariant { impl_lint_pass!(LargeEnumVariant => [LARGE_ENUM_VARIANT]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant { - fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant { + fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { let did = cx.tcx.hir().local_def_id(item.hir_id); if let ItemKind::Enum(ref def, _) = item.kind { let ty = cx.tcx.type_of(did); diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index 0301f263489f..8eb986c25ff7 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -38,8 +38,8 @@ impl LargeStackArrays { impl_lint_pass!(LargeStackArrays => [LARGE_STACK_ARRAYS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeStackArrays { - fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for LargeStackArrays { + fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Repeat(_, _) = expr.kind; if let ty::Array(element_type, cst) = cx.tables().expr_ty(expr).kind; diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index e17297e96951..26d96428771d 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -70,8 +70,8 @@ declare_clippy_lint! { declare_lint_pass!(LenZero => [LEN_ZERO, LEN_WITHOUT_IS_EMPTY]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for LenZero { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if item.span.from_expansion() { return; } @@ -87,7 +87,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero { } } - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if expr.span.from_expansion() { return; } @@ -118,8 +118,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero { } } -fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item<'_>, trait_items: &[TraitItemRef]) { - fn is_named_self(cx: &LateContext<'_, '_>, item: &TraitItemRef, name: &str) -> bool { +fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items: &[TraitItemRef]) { + fn is_named_self(cx: &LateContext<'_>, item: &TraitItemRef, name: &str) -> bool { item.ident.name.as_str() == name && if let AssocItemKind::Fn { has_self } = item.kind { has_self && { @@ -132,7 +132,7 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item<'_>, trait_i } // fill the set with current and super traits - fn fill_trait_set(traitt: DefId, set: &mut FxHashSet, cx: &LateContext<'_, '_>) { + fn fill_trait_set(traitt: DefId, set: &mut FxHashSet, cx: &LateContext<'_>) { if set.insert(traitt) { for supertrait in rustc_trait_selection::traits::supertrait_def_ids(cx.tcx, traitt) { fill_trait_set(supertrait, set, cx); @@ -169,8 +169,8 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item<'_>, trait_i } } -fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item<'_>, impl_items: &[ImplItemRef<'_>]) { - fn is_named_self(cx: &LateContext<'_, '_>, item: &ImplItemRef<'_>, name: &str) -> bool { +fn check_impl_items(cx: &LateContext<'_>, item: &Item<'_>, impl_items: &[ImplItemRef<'_>]) { + fn is_named_self(cx: &LateContext<'_>, item: &ImplItemRef<'_>, name: &str) -> bool { item.ident.name.as_str() == name && if let AssocItemKind::Fn { has_self } = item.kind { has_self && { @@ -210,7 +210,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item<'_>, impl_items: &[Imp } } -fn check_cmp(cx: &LateContext<'_, '_>, span: Span, method: &Expr<'_>, lit: &Expr<'_>, op: &str, compare_to: u32) { +fn check_cmp(cx: &LateContext<'_>, span: Span, method: &Expr<'_>, lit: &Expr<'_>, op: &str, compare_to: u32) { if let (&ExprKind::MethodCall(ref method_path, _, ref args, _), &ExprKind::Lit(ref lit)) = (&method.kind, &lit.kind) { // check if we are in an is_empty() method @@ -225,7 +225,7 @@ fn check_cmp(cx: &LateContext<'_, '_>, span: Span, method: &Expr<'_>, lit: &Expr } fn check_len( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, span: Span, method_name: Symbol, args: &[Expr<'_>], @@ -259,9 +259,9 @@ fn check_len( } /// Checks if this type has an `is_empty` method. -fn has_is_empty(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { +fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { /// Special case ranges until `range_is_empty` is stabilized. See issue 3807. - fn should_skip_range(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { + fn should_skip_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { higher::range(cx, expr).map_or(false, |_| { !cx.tcx .features() @@ -272,7 +272,7 @@ fn has_is_empty(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { } /// Gets an `AssocItem` and return true if it matches `is_empty(self)`. - fn is_is_empty(cx: &LateContext<'_, '_>, item: &ty::AssocItem) -> bool { + fn is_is_empty(cx: &LateContext<'_>, item: &ty::AssocItem) -> bool { if let ty::AssocKind::Fn = item.kind { if item.ident.name.as_str() == "is_empty" { let sig = cx.tcx.fn_sig(item.def_id); @@ -287,7 +287,7 @@ fn has_is_empty(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { } /// Checks the inherent impl's items for an `is_empty(self)` method. - fn has_is_empty_impl(cx: &LateContext<'_, '_>, id: DefId) -> bool { + fn has_is_empty_impl(cx: &LateContext<'_>, id: DefId) -> bool { cx.tcx.inherent_impls(id).iter().any(|imp| { cx.tcx .associated_items(*imp) diff --git a/clippy_lints/src/let_and_return.rs b/clippy_lints/src/let_and_return.rs index 7d338cfa86f9..ddc41f89f8de 100644 --- a/clippy_lints/src/let_and_return.rs +++ b/clippy_lints/src/let_and_return.rs @@ -40,8 +40,8 @@ declare_clippy_lint! { declare_lint_pass!(LetReturn => [LET_AND_RETURN]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetReturn { - fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>) { +impl<'tcx> LateLintPass<'tcx> for LetReturn { + fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'_>) { // we need both a let-binding stmt and an expr if_chain! { if let Some(retexpr) = block.expr; @@ -86,14 +86,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetReturn { } } -fn last_statement_borrows<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &'tcx Expr<'tcx>) -> bool { +fn last_statement_borrows<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool { let mut visitor = BorrowVisitor { cx, borrows: false }; walk_expr(&mut visitor, expr); visitor.borrows } struct BorrowVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, borrows: bool, } diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 7b03812b8226..706c73ce66c6 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -56,8 +56,8 @@ declare_clippy_lint! { declare_lint_pass!(LetIfSeq => [USELESS_LET_IF_SEQ]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq { - fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block<'_>) { +impl<'tcx> LateLintPass<'tcx> for LetIfSeq { + fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx hir::Block<'_>) { let mut it = block.stmts.iter().peekable(); while let Some(stmt) = it.next() { if_chain! { @@ -137,7 +137,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq { } struct UsedVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, id: hir::HirId, used: bool, } @@ -162,8 +162,8 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> { } } -fn check_assign<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn check_assign<'tcx>( + cx: &LateContext<'tcx>, decl: hir::HirId, block: &'tcx hir::Block<'_>, ) -> Option<&'tcx hir::Expr<'tcx>> { @@ -197,7 +197,7 @@ fn check_assign<'a, 'tcx>( None } -fn used_in_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, id: hir::HirId, expr: &'tcx hir::Expr<'_>) -> bool { +fn used_in_expr<'tcx>(cx: &LateContext<'tcx>, id: hir::HirId, expr: &'tcx hir::Expr<'_>) -> bool { let mut v = UsedVisitor { cx, id, used: false }; intravisit::walk_expr(&mut v, expr); v.used diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index 0864bbe0f912..c7dda3c99282 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -66,8 +66,8 @@ const SYNC_GUARD_PATHS: [&[&str]; 3] = [ &paths::RWLOCK_WRITE_GUARD, ]; -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore { - fn check_local(&mut self, cx: &LateContext<'_, '_>, local: &Local<'_>) { +impl<'tcx> LateLintPass<'tcx> for LetUnderscore { + fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) { if in_external_macro(cx.tcx.sess, local.span) { return; } diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index c0d8c1127b9d..a79f94855bda 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -76,14 +76,14 @@ declare_clippy_lint! { declare_lint_pass!(Lifetimes => [NEEDLESS_LIFETIMES, EXTRA_UNUSED_LIFETIMES]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Lifetimes { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for Lifetimes { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if let ItemKind::Fn(ref sig, ref generics, id) = item.kind { check_fn_inner(cx, &sig.decl, Some(id), generics, item.span, true); } } - fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem<'_>) { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { if let ImplItemKind::Fn(ref sig, id) = item.kind { let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id).is_none(); check_fn_inner( @@ -97,7 +97,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Lifetimes { } } - fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem<'_>) { + fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { if let TraitItemKind::Fn(ref sig, ref body) = item.kind { let body = match *body { TraitFn::Required(_) => None, @@ -116,8 +116,8 @@ enum RefLt { Named(Name), } -fn check_fn_inner<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn check_fn_inner<'tcx>( + cx: &LateContext<'tcx>, decl: &'tcx FnDecl<'_>, body: Option, generics: &'tcx Generics<'_>, @@ -177,8 +177,8 @@ fn check_fn_inner<'a, 'tcx>( } } -fn could_use_elision<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn could_use_elision<'tcx>( + cx: &LateContext<'tcx>, func: &'tcx FnDecl<'_>, body: Option, named_generics: &'tcx [GenericParam<'_>], @@ -296,13 +296,13 @@ fn unique_lifetimes(lts: &[RefLt]) -> usize { /// A visitor usable for `rustc_front::visit::walk_ty()`. struct RefVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, lts: Vec, abort: bool, } -impl<'v, 't> RefVisitor<'v, 't> { - fn new(cx: &'v LateContext<'v, 't>) -> Self { +impl<'a, 'tcx> RefVisitor<'a, 'tcx> { + fn new(cx: &'a LateContext<'tcx>) -> Self { Self { cx, lts: Vec::new(), @@ -412,7 +412,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { /// Are any lifetimes mentioned in the `where` clause? If so, we don't try to /// reason about elision. -fn has_where_lifetimes<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, where_clause: &'tcx WhereClause<'_>) -> bool { +fn has_where_lifetimes<'tcx>(cx: &LateContext<'tcx>, where_clause: &'tcx WhereClause<'_>) -> bool { for predicate in where_clause.predicates { match *predicate { WherePredicate::RegionPredicate(..) => return true, @@ -482,7 +482,7 @@ impl<'tcx> Visitor<'tcx> for LifetimeChecker { } } -fn report_extra_lifetimes<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, func: &'tcx FnDecl<'_>, generics: &'tcx Generics<'_>) { +fn report_extra_lifetimes<'tcx>(cx: &LateContext<'tcx>, func: &'tcx FnDecl<'_>, generics: &'tcx Generics<'_>) { let hs = generics .params .iter() diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 18b979176a0a..d821b5134841 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -438,9 +438,9 @@ declare_lint_pass!(Loops => [ WHILE_IMMUTABLE_CONDITION, ]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops { +impl<'tcx> LateLintPass<'tcx> for Loops { #[allow(clippy::too_many_lines)] - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let Some((pat, arg, body)) = higher::for_loop(expr) { // we don't want to check expanded macros // this check is not at the top of the function @@ -732,8 +732,8 @@ fn never_loop_expr_branch<'a, T: Iterator>>(e: &mut T, main_ .fold(NeverLoopResult::AlwaysBreak, combine_branches) } -fn check_for_loop<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn check_for_loop<'tcx>( + cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx Expr<'_>, body: &'tcx Expr<'_>, @@ -747,7 +747,7 @@ fn check_for_loop<'a, 'tcx>( detect_manual_memcpy(cx, pat, arg, body, expr); } -fn same_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>, var: HirId) -> bool { +fn same_var<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, var: HirId) -> bool { if_chain! { if let ExprKind::Path(qpath) = &expr.kind; if let QPath::Resolved(None, path) = qpath; @@ -794,7 +794,7 @@ struct FixedOffsetVar<'hir> { offset: Offset, } -fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'_>) -> bool { +fn is_slice_like<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'_>) -> bool { let is_slice = match ty.kind { ty::Ref(_, subty, _) => is_slice_like(cx, subty), ty::Slice(..) | ty::Array(..) => true, @@ -814,8 +814,8 @@ fn fetch_cloned_expr<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { } } -fn get_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, idx: &Expr<'_>, var: HirId) -> Option { - fn extract_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &Expr<'_>, var: HirId) -> Option { +fn get_offset<'tcx>(cx: &LateContext<'tcx>, idx: &Expr<'_>, var: HirId) -> Option { + fn extract_offset<'tcx>(cx: &LateContext<'tcx>, e: &Expr<'_>, var: HirId) -> Option { match &e.kind { ExprKind::Lit(l) => match l.node { ast::LitKind::Int(x, _ty) => Some(x.to_string()), @@ -880,8 +880,8 @@ fn get_assignments<'tcx>(body: &'tcx Expr<'tcx>) -> impl Iterator( - cx: &LateContext<'a, 'tcx>, +fn build_manual_memcpy_suggestion<'tcx>( + cx: &LateContext<'tcx>, start: &Expr<'_>, end: &Expr<'_>, limits: ast::RangeLimits, @@ -961,8 +961,8 @@ fn build_manual_memcpy_suggestion<'a, 'tcx>( } /// Checks for for loops that sequentially copy items from one slice-like /// object to another. -fn detect_manual_memcpy<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn detect_manual_memcpy<'tcx>( + cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx Expr<'_>, body: &'tcx Expr<'_>, @@ -1024,8 +1024,8 @@ fn detect_manual_memcpy<'a, 'tcx>( /// Checks for looping over a range and then indexing a sequence with it. /// The iteratee must be a range literal. #[allow(clippy::too_many_lines)] -fn check_for_loop_range<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn check_for_loop_range<'tcx>( + cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx Expr<'_>, body: &'tcx Expr<'_>, @@ -1205,7 +1205,7 @@ fn is_len_call(expr: &Expr<'_>, var: Name) -> bool { } fn is_end_eq_array_len<'tcx>( - cx: &LateContext<'_, 'tcx>, + cx: &LateContext<'tcx>, end: &Expr<'_>, limits: ast::RangeLimits, indexed_ty: Ty<'tcx>, @@ -1226,7 +1226,7 @@ fn is_end_eq_array_len<'tcx>( false } -fn lint_iter_method(cx: &LateContext<'_, '_>, args: &[Expr<'_>], arg: &Expr<'_>, method_name: &str) { +fn lint_iter_method(cx: &LateContext<'_>, args: &[Expr<'_>], arg: &Expr<'_>, method_name: &str) { let mut applicability = Applicability::MachineApplicable; let object = snippet_with_applicability(cx, args[0].span, "_", &mut applicability); let muta = if method_name == "iter_mut" { "mut " } else { "" }; @@ -1242,7 +1242,7 @@ fn lint_iter_method(cx: &LateContext<'_, '_>, args: &[Expr<'_>], arg: &Expr<'_>, ) } -fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>, expr: &Expr<'_>) { +fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, expr: &Expr<'_>) { let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used if let ExprKind::MethodCall(ref method, _, ref args, _) = arg.kind { // just the receiver, no arguments @@ -1299,7 +1299,7 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>, e } /// Checks for `for` loops over `Option`s and `Result`s. -fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>) { +fn check_arg_type(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) { let ty = cx.tables().expr_ty(arg); if is_type_diagnostic_item(cx, ty, sym!(option_type)) { span_lint_and_help( @@ -1338,8 +1338,8 @@ fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>) { } } -fn check_for_loop_explicit_counter<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn check_for_loop_explicit_counter<'tcx>( + cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx Expr<'_>, body: &'tcx Expr<'_>, @@ -1403,7 +1403,7 @@ fn check_for_loop_explicit_counter<'a, 'tcx>( /// If `arg` was the argument to a `for` loop, return the "cleanest" way of writing the /// actual `Iterator` that the loop uses. -fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr<'_>, applic_ref: &mut Applicability) -> String { +fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic_ref: &mut Applicability) -> String { let impls_iterator = get_trait_def_id(cx, &paths::ITERATOR) .map_or(false, |id| implements_trait(cx, cx.tables().expr_ty(arg), id, &[])); if impls_iterator { @@ -1437,8 +1437,8 @@ fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr<'_>, applic_ref: & } /// Checks for the `FOR_KV_MAP` lint. -fn check_for_loop_over_map_kv<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn check_for_loop_over_map_kv<'tcx>( + cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx Expr<'_>, body: &'tcx Expr<'_>, @@ -1490,7 +1490,7 @@ fn check_for_loop_over_map_kv<'a, 'tcx>( } struct MutatePairDelegate<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, hir_id_low: Option, hir_id_high: Option, span_low: Option, @@ -1531,7 +1531,7 @@ impl MutatePairDelegate<'_, '_> { } } -fn check_for_mut_range_bound(cx: &LateContext<'_, '_>, arg: &Expr<'_>, body: &Expr<'_>) { +fn check_for_mut_range_bound(cx: &LateContext<'_>, arg: &Expr<'_>, body: &Expr<'_>) { if let Some(higher::Range { start: Some(start), end: Some(end), @@ -1547,7 +1547,7 @@ fn check_for_mut_range_bound(cx: &LateContext<'_, '_>, arg: &Expr<'_>, body: &Ex } } -fn mut_warn_with_span(cx: &LateContext<'_, '_>, span: Option) { +fn mut_warn_with_span(cx: &LateContext<'_>, span: Option) { if let Some(sp) = span { span_lint( cx, @@ -1558,7 +1558,7 @@ fn mut_warn_with_span(cx: &LateContext<'_, '_>, span: Option) { } } -fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr<'_>) -> Option { +fn check_for_mutability(cx: &LateContext<'_>, bound: &Expr<'_>) -> Option { if_chain! { if let ExprKind::Path(ref qpath) = bound.kind; if let QPath::Resolved(None, _) = *qpath; @@ -1580,8 +1580,8 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr<'_>) -> Option( - cx: &LateContext<'a, 'tcx>, +fn check_for_mutation<'tcx>( + cx: &LateContext<'tcx>, body: &Expr<'_>, bound_ids: &[Option], ) -> (Option, Option) { @@ -1609,7 +1609,7 @@ fn pat_is_wild<'tcx>(pat: &'tcx PatKind<'_>, body: &'tcx Expr<'_>) -> bool { } struct LocalUsedVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, local: HirId, used: bool, } @@ -1632,7 +1632,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LocalUsedVisitor<'a, 'tcx> { struct VarVisitor<'a, 'tcx> { /// context reference - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, /// var name to look for as index var: HirId, /// indexed variables that are used mutably @@ -1803,7 +1803,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { } } -fn is_used_inside<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, container: &'tcx Expr<'_>) -> bool { +fn is_used_inside<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, container: &'tcx Expr<'_>) -> bool { let def_id = match var_def_id(cx, expr) { Some(id) => id, None => return false, @@ -1816,7 +1816,7 @@ fn is_used_inside<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, false } -fn is_iterator_used_after_while_let<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, iter_expr: &'tcx Expr<'_>) -> bool { +fn is_iterator_used_after_while_let<'tcx>(cx: &LateContext<'tcx>, iter_expr: &'tcx Expr<'_>) -> bool { let def_id = match var_def_id(cx, iter_expr) { Some(id) => id, None => return false, @@ -1835,7 +1835,7 @@ fn is_iterator_used_after_while_let<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, iter_e } struct VarUsedAfterLoopVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, def_id: HirId, iter_expr_id: HirId, past_while_let: bool, @@ -1863,7 +1863,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> { /// Returns `true` if the type of expr is one that provides `IntoIterator` impls /// for `&T` and `&mut T`, such as `Vec`. #[rustfmt::skip] -fn is_ref_iterable_type(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool { +fn is_ref_iterable_type(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { // no walk_ptrs_ty: calling iter() on a reference can make sense because it // will allow further borrows afterwards let ty = cx.tables().expr_ty(e); @@ -1878,7 +1878,7 @@ fn is_ref_iterable_type(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool { match_type(cx, ty, &paths::BTREESET) } -fn is_iterable_array<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'_, 'tcx>) -> bool { +fn is_iterable_array<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool { // IntoIterator is currently only implemented for array sizes <= 32 in rustc match ty.kind { ty::Array(_, n) => { @@ -1946,7 +1946,7 @@ enum VarState { /// Scan a for loop for variables that are incremented exactly once. struct IncrementVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, // context reference + cx: &'a LateContext<'tcx>, // context reference states: FxHashMap, // incremented variables depth: u32, // depth of conditional expressions done: bool, @@ -2004,8 +2004,8 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> { /// Checks whether a variable is initialized to zero at the start of a loop. struct InitializeVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, // context reference - end_expr: &'tcx Expr<'tcx>, // the for loop. Stop scanning here. + cx: &'a LateContext<'tcx>, // context reference + end_expr: &'tcx Expr<'tcx>, // the for loop. Stop scanning here. var_id: HirId, state: VarState, name: Option, @@ -2094,7 +2094,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { } } -fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option { +fn var_def_id(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { if let ExprKind::Path(ref qpath) = expr.kind { let path_res = qpath_res(cx, qpath, expr.hir_id); if let Res::Local(hir_id) = path_res { @@ -2118,7 +2118,7 @@ fn is_conditional(expr: &Expr<'_>) -> bool { } } -fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr<'_>, iter_expr: &Expr<'_>) -> bool { +fn is_nested(cx: &LateContext<'_>, match_expr: &Expr<'_>, iter_expr: &Expr<'_>) -> bool { if_chain! { if let Some(loop_block) = get_enclosing_block(cx, match_expr.hir_id); let parent_node = cx.tcx.hir().get_parent_node(loop_block.hir_id); @@ -2130,7 +2130,7 @@ fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr<'_>, iter_expr: &Expr<' false } -fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr<'_>, iter_expr: &Expr<'_>) -> bool { +fn is_loop_nested(cx: &LateContext<'_>, loop_expr: &Expr<'_>, iter_expr: &Expr<'_>) -> bool { let mut id = loop_expr.hir_id; let iter_name = if let Some(name) = path_name(iter_expr) { name @@ -2240,7 +2240,7 @@ fn path_name(e: &Expr<'_>) -> Option { None } -fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) { +fn check_infinite_loop<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) { if constant(cx, cx.tables(), cond).is_some() { // A pure constant condition (e.g., `while false`) is not linted. return; @@ -2321,7 +2321,7 @@ impl<'tcx> Visitor<'tcx> for HasBreakOrReturnVisitor { /// Note: In some cases such as `self`, there are no mutable annotation, /// All variables definition IDs are collected struct VarCollectorVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, ids: FxHashSet, def_ids: FxHashMap, skip: bool, @@ -2369,7 +2369,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarCollectorVisitor<'a, 'tcx> { const NEEDLESS_COLLECT_MSG: &str = "avoid using `collect()` when not needed"; -fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'a, 'tcx>) { +fn check_needless_collect<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) { if_chain! { if let ExprKind::MethodCall(ref method, _, ref args, _) = expr.kind; if let ExprKind::MethodCall(ref chain_method, _, _, _) = args[0].kind; diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index b845b20d2c01..065c7c042d36 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -44,7 +44,7 @@ pub struct MacroRefData { } impl MacroRefData { - pub fn new(name: String, callee: Span, cx: &LateContext<'_, '_>) -> Self { + pub fn new(name: String, callee: Span, cx: &LateContext<'_>) -> Self { let mut path = cx.sess().source_map().span_to_filename(callee).to_string(); // std lib paths are <::std::module::file type> @@ -72,7 +72,7 @@ pub struct MacroUseImports { impl_lint_pass!(MacroUseImports => [MACRO_USE_IMPORTS]); impl MacroUseImports { - fn push_unique_macro(&mut self, cx: &LateContext<'_, '_>, span: Span) { + fn push_unique_macro(&mut self, cx: &LateContext<'_>, span: Span) { let call_site = span.source_callsite(); let name = snippet(cx, cx.sess().source_map().span_until_char(call_site, '!'), "_"); if let Some(callee) = span.source_callee() { @@ -89,7 +89,7 @@ impl MacroUseImports { } } - fn push_unique_macro_pat_ty(&mut self, cx: &LateContext<'_, '_>, span: Span) { + fn push_unique_macro_pat_ty(&mut self, cx: &LateContext<'_>, span: Span) { let call_site = span.source_callsite(); let name = snippet(cx, cx.sess().source_map().span_until_char(call_site, '!'), "_"); if let Some(callee) = span.source_callee() { @@ -102,8 +102,8 @@ impl MacroUseImports { } } -impl<'l, 'txc> LateLintPass<'l, 'txc> for MacroUseImports { - fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for MacroUseImports { + fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) { if_chain! { if cx.sess().opts.edition == Edition::Edition2018; if let hir::ItemKind::Use(path, _kind) = &item.kind; @@ -127,33 +127,33 @@ impl<'l, 'txc> LateLintPass<'l, 'txc> for MacroUseImports { } } } - fn check_attribute(&mut self, cx: &LateContext<'_, '_>, attr: &ast::Attribute) { + fn check_attribute(&mut self, cx: &LateContext<'_>, attr: &ast::Attribute) { if in_macro(attr.span) { self.push_unique_macro(cx, attr.span); } } - fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) { + fn check_expr(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) { if in_macro(expr.span) { self.push_unique_macro(cx, expr.span); } } - fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &hir::Stmt<'_>) { + fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &hir::Stmt<'_>) { if in_macro(stmt.span) { self.push_unique_macro(cx, stmt.span); } } - fn check_pat(&mut self, cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>) { + fn check_pat(&mut self, cx: &LateContext<'_>, pat: &hir::Pat<'_>) { if in_macro(pat.span) { self.push_unique_macro_pat_ty(cx, pat.span); } } - fn check_ty(&mut self, cx: &LateContext<'_, '_>, ty: &hir::Ty<'_>) { + fn check_ty(&mut self, cx: &LateContext<'_>, ty: &hir::Ty<'_>) { if in_macro(ty.span) { self.push_unique_macro_pat_ty(cx, ty.span); } } #[allow(clippy::too_many_lines)] - fn check_crate_post(&mut self, cx: &LateContext<'_, '_>, _krate: &hir::Crate<'_>) { + fn check_crate_post(&mut self, cx: &LateContext<'_>, _krate: &hir::Crate<'_>) { let mut used = FxHashMap::default(); let mut check_dup = vec![]; for (import, span) in &self.imports { diff --git a/clippy_lints/src/main_recursion.rs b/clippy_lints/src/main_recursion.rs index 8a0e47a3d31c..eceae706e4fc 100644 --- a/clippy_lints/src/main_recursion.rs +++ b/clippy_lints/src/main_recursion.rs @@ -31,12 +31,12 @@ pub struct MainRecursion { impl_lint_pass!(MainRecursion => [MAIN_RECURSION]); -impl LateLintPass<'_, '_> for MainRecursion { - fn check_crate(&mut self, _: &LateContext<'_, '_>, krate: &Crate<'_>) { +impl LateLintPass<'_> for MainRecursion { + fn check_crate(&mut self, _: &LateContext<'_>, krate: &Crate<'_>) { self.has_no_std_attr = is_no_std_crate(krate); } - fn check_expr_post(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) { + fn check_expr_post(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { if self.has_no_std_attr { return; } diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 03ab274d9ca9..c19fb148cda5 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -38,10 +38,10 @@ declare_clippy_lint! { declare_lint_pass!(ManualAsyncFn => [MANUAL_ASYNC_FN]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ManualAsyncFn { +impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn { fn check_fn( &mut self, - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, @@ -97,7 +97,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ManualAsyncFn { } } -fn future_trait_ref<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &'tcx Ty<'tcx>) -> Option<&'tcx TraitRef<'tcx>> { +fn future_trait_ref<'tcx>(cx: &LateContext<'tcx>, ty: &'tcx Ty<'tcx>) -> Option<&'tcx TraitRef<'tcx>> { if_chain! { if let TyKind::OpaqueDef(item_id, _) = ty.kind; let item = cx.tcx.hir().item(item_id.id); @@ -129,7 +129,7 @@ fn future_output_ty<'tcx>(trait_ref: &'tcx TraitRef<'tcx>) -> Option<&'tcx Ty<'t None } -fn desugared_async_block<'tcx>(cx: &LateContext<'_, 'tcx>, block: &'tcx Block<'tcx>) -> Option<&'tcx Body<'tcx>> { +fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) -> Option<&'tcx Body<'tcx>> { if_chain! { if let Some(block_expr) = block.expr; if let Some(args) = match_function_call(cx, block_expr, &FUTURE_FROM_GENERATOR); @@ -145,7 +145,7 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'_, 'tcx>, block: &'tcx Block<'t None } -fn suggested_ret(cx: &LateContext<'_, '_>, output: &Ty<'_>) -> Option<(&'static str, String)> { +fn suggested_ret(cx: &LateContext<'_>, output: &Ty<'_>) -> Option<(&'static str, String)> { match output.kind { TyKind::Tup(tys) if tys.is_empty() => { let sugg = "remove the return type"; diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 9109de9458f1..905a3f3ca71c 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -42,8 +42,8 @@ declare_clippy_lint! { declare_lint_pass!(MapClone => [MAP_CLONE]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone { - fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for MapClone { + fn check_expr(&mut self, cx: &LateContext<'_>, e: &hir::Expr<'_>) { if e.span.from_expansion() { return; } @@ -106,7 +106,7 @@ fn ident_eq(name: Ident, path: &hir::Expr<'_>) -> bool { } } -fn lint_needless_cloning(cx: &LateContext<'_, '_>, root: Span, receiver: Span) { +fn lint_needless_cloning(cx: &LateContext<'_>, root: Span, receiver: Span) { span_lint_and_sugg( cx, MAP_CLONE, @@ -118,7 +118,7 @@ fn lint_needless_cloning(cx: &LateContext<'_, '_>, root: Span, receiver: Span) { ) } -fn lint(cx: &LateContext<'_, '_>, replace: Span, root: Span, copied: bool) { +fn lint(cx: &LateContext<'_>, replace: Span, root: Span, copied: bool) { let mut applicability = Applicability::MachineApplicable; if copied { span_lint_and_sugg( diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 90d4a34a19a2..316a71c50051 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -100,7 +100,7 @@ fn is_unit_type(ty: Ty<'_>) -> bool { } } -fn is_unit_function(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) -> bool { +fn is_unit_function(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { let ty = cx.tables().expr_ty(expr); if let ty::FnDef(id, _) = ty.kind { @@ -111,7 +111,7 @@ fn is_unit_function(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) -> bool { false } -fn is_unit_expression(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) -> bool { +fn is_unit_expression(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { is_unit_type(cx.tables().expr_ty(expr)) } @@ -119,7 +119,7 @@ fn is_unit_expression(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) -> bool { /// semicolons, which causes problems when generating a suggestion. Given an /// expression that evaluates to '()' or '!', recursively remove useless braces /// and semi-colons until is suitable for including in the suggestion template -fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr<'_>) -> Option { +fn reduce_unit_expression<'a>(cx: &LateContext<'_>, expr: &'a hir::Expr<'_>) -> Option { if !is_unit_expression(cx, expr) { return None; } @@ -161,7 +161,7 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr<'_>) } fn unit_closure<'tcx>( - cx: &LateContext<'_, 'tcx>, + cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, ) -> Option<(&'tcx hir::Param<'tcx>, &'tcx hir::Expr<'tcx>)> { if let hir::ExprKind::Closure(_, ref decl, inner_expr_id, _, _) = expr.kind { @@ -186,7 +186,7 @@ fn unit_closure<'tcx>( /// `y` => `_y` /// /// Anything else will return `a`. -fn let_binding_name(cx: &LateContext<'_, '_>, var_arg: &hir::Expr<'_>) -> String { +fn let_binding_name(cx: &LateContext<'_>, var_arg: &hir::Expr<'_>) -> String { match &var_arg.kind { hir::ExprKind::Field(_, _) => snippet(cx, var_arg.span, "_").replace(".", "_"), hir::ExprKind::Path(_) => format!("_{}", snippet(cx, var_arg.span, "")), @@ -202,7 +202,7 @@ fn suggestion_msg(function_type: &str, map_type: &str) -> String { ) } -fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt<'_>, expr: &hir::Expr<'_>, map_args: &[hir::Expr<'_>]) { +fn lint_map_unit_fn(cx: &LateContext<'_>, stmt: &hir::Stmt<'_>, expr: &hir::Expr<'_>, map_args: &[hir::Expr<'_>]) { let var_arg = &map_args[0]; let (map_type, variant, lint) = if is_type_diagnostic_item(cx, cx.tables().expr_ty(var_arg), sym!(option_type)) { @@ -258,8 +258,8 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt<'_>, expr: &hir:: } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapUnit { - fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &hir::Stmt<'_>) { +impl<'tcx> LateLintPass<'tcx> for MapUnit { + fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &hir::Stmt<'_>) { if stmt.span.from_expansion() { return; } diff --git a/clippy_lints/src/match_on_vec_items.rs b/clippy_lints/src/match_on_vec_items.rs index 4a025e0621f9..0003aa94a031 100644 --- a/clippy_lints/src/match_on_vec_items.rs +++ b/clippy_lints/src/match_on_vec_items.rs @@ -44,8 +44,8 @@ declare_clippy_lint! { declare_lint_pass!(MatchOnVecItems => [MATCH_ON_VEC_ITEMS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MatchOnVecItems { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) { +impl<'tcx> LateLintPass<'tcx> for MatchOnVecItems { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if_chain! { if !in_external_macro(cx.sess(), expr.span); if let ExprKind::Match(ref match_expr, _, MatchSource::Normal) = expr.kind; @@ -73,7 +73,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MatchOnVecItems { } } -fn is_vec_indexing<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { +fn is_vec_indexing<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { if_chain! { if let ExprKind::Index(ref array, ref index) = expr.kind; if is_vector(cx, array); @@ -87,13 +87,13 @@ fn is_vec_indexing<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) None } -fn is_vector(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { +fn is_vector(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let ty = cx.tables().expr_ty(expr); let ty = walk_ptrs_ty(ty); is_type_diagnostic_item(cx, ty, sym!(vec_type)) } -fn is_full_range(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { +fn is_full_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let ty = cx.tables().expr_ty(expr); let ty = walk_ptrs_ty(ty); match_type(cx, ty, &utils::paths::RANGE_FULL) diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 0c91d8885d92..b754a45aa404 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -430,8 +430,8 @@ impl_lint_pass!(Matches => [ REST_PAT_IN_FULLY_BOUND_STRUCTS ]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for Matches { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if in_external_macro(cx.sess(), expr.span) { return; } @@ -455,7 +455,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches { } } - fn check_local(&mut self, cx: &LateContext<'a, 'tcx>, local: &'tcx Local<'_>) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'_>) { if_chain! { if !in_external_macro(cx.sess(), local.span); if !in_macro(local.span); @@ -491,7 +491,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches { } } - fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat<'_>) { + fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { if_chain! { if !in_external_macro(cx.sess(), pat.span); if !in_macro(pat.span); @@ -518,7 +518,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches { } #[rustfmt::skip] -fn check_single_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { +fn check_single_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { if arms.len() == 2 && arms[0].guard.is_none() && arms[1].guard.is_none() { if in_macro(expr.span) { // Don't lint match expressions present in @@ -549,7 +549,7 @@ fn check_single_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], } fn check_single_match_single_pattern( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>, @@ -561,7 +561,7 @@ fn check_single_match_single_pattern( } fn report_single_match_single_pattern( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>, @@ -590,7 +590,7 @@ fn report_single_match_single_pattern( } fn check_single_match_opt_like( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>, @@ -630,7 +630,7 @@ fn check_single_match_opt_like( } } -fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { +fn check_match_bool(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { // Type of expression is `bool`. if cx.tables().expr_ty(ex).kind == ty::Bool { span_lint_and_then( @@ -694,7 +694,7 @@ fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], e } } -fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr<'_>, arms: &'tcx [Arm<'_>]) { +fn check_overlapping_arms<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'_>, arms: &'tcx [Arm<'_>]) { if arms.len() >= 2 && cx.tables().expr_ty(ex).is_integral() { let ranges = all_ranges(cx, arms, cx.tables().expr_ty(ex)); let type_ranges = type_ranges(&ranges); @@ -713,7 +713,7 @@ fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr<' } } -fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { +fn check_wild_err_arm(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { let ex_ty = walk_ptrs_ty(cx.tables().expr_ty(ex)); if is_type_diagnostic_item(cx, ex_ty, sym!(result_type)) { for arm in arms { @@ -754,7 +754,7 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) } } -fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { +fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { let ty = cx.tables().expr_ty(ex); if !ty.is_enum() { // If there isn't a nice closed set of possible values that can be conveniently enumerated, @@ -884,7 +884,7 @@ fn is_panic_block(block: &Block<'_>) -> bool { } } -fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { +fn check_match_ref_pats(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { if has_only_ref_pats(arms) { let mut suggs = Vec::with_capacity(arms.len() + 1); let (title, msg) = if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = ex.kind { @@ -919,7 +919,7 @@ fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_> } } -fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { +fn check_match_as_ref(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { if arms.len() == 2 && arms[0].guard.is_none() && arms[1].guard.is_none() { let arm_ref: Option = if is_none_arm(&arms[0]) { is_ref_some_arm(&arms[1]) @@ -971,7 +971,7 @@ fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], } } -fn check_wild_in_or_pats(cx: &LateContext<'_, '_>, arms: &[Arm<'_>]) { +fn check_wild_in_or_pats(cx: &LateContext<'_>, arms: &[Arm<'_>]) { for arm in arms { if let PatKind::Or(ref fields) = arm.pat.kind { // look for multiple fields in this arm that contains at least one Wild pattern @@ -989,7 +989,7 @@ fn check_wild_in_or_pats(cx: &LateContext<'_, '_>, arms: &[Arm<'_>]) { } } -fn check_match_single_binding<'a>(cx: &LateContext<'_, 'a>, ex: &Expr<'a>, arms: &[Arm<'_>], expr: &Expr<'_>) { +fn check_match_single_binding<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], expr: &Expr<'_>) { if in_macro(expr.span) || arms.len() != 1 || is_refutable(cx, arms[0].pat) { return; } @@ -1085,7 +1085,7 @@ fn check_match_single_binding<'a>(cx: &LateContext<'_, 'a>, ex: &Expr<'a>, arms: } /// Returns true if the `ex` match expression is in a local (`let`) statement -fn opt_parent_let<'a>(cx: &LateContext<'_, 'a>, ex: &Expr<'a>) -> Option<&'a Local<'a>> { +fn opt_parent_let<'a>(cx: &LateContext<'a>, ex: &Expr<'a>) -> Option<&'a Local<'a>> { if_chain! { let map = &cx.tcx.hir(); if let Some(Node::Expr(parent_arm_expr)) = map.find(map.get_parent_node(ex.hir_id)); @@ -1098,11 +1098,7 @@ fn opt_parent_let<'a>(cx: &LateContext<'_, 'a>, ex: &Expr<'a>) -> Option<&'a Loc } /// Gets all arms that are unbounded `PatRange`s. -fn all_ranges<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, - arms: &'tcx [Arm<'_>], - ty: Ty<'tcx>, -) -> Vec> { +fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>) -> Vec> { arms.iter() .flat_map(|arm| { if let Arm { diff --git a/clippy_lints/src/mem_discriminant.rs b/clippy_lints/src/mem_discriminant.rs index 8a665a6e1fad..06c568513035 100644 --- a/clippy_lints/src/mem_discriminant.rs +++ b/clippy_lints/src/mem_discriminant.rs @@ -29,8 +29,8 @@ declare_clippy_lint! { declare_lint_pass!(MemDiscriminant => [MEM_DISCRIMINANT_NON_ENUM]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemDiscriminant { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for MemDiscriminant { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Call(ref func, ref func_args) = expr.kind; // is `mem::discriminant` diff --git a/clippy_lints/src/mem_forget.rs b/clippy_lints/src/mem_forget.rs index 1821bd9135f9..b895ba324c78 100644 --- a/clippy_lints/src/mem_forget.rs +++ b/clippy_lints/src/mem_forget.rs @@ -25,8 +25,8 @@ declare_clippy_lint! { declare_lint_pass!(MemForget => [MEM_FORGET]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemForget { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for MemForget { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::Call(ref path_expr, ref args) = e.kind { if let ExprKind::Path(ref qpath) = path_expr.kind { if let Some(def_id) = qpath_res(cx, qpath, path_expr.hir_id).opt_def_id() { diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 703f91f8ac02..25f332cdcc28 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -97,7 +97,7 @@ declare_clippy_lint! { declare_lint_pass!(MemReplace => [MEM_REPLACE_OPTION_WITH_NONE, MEM_REPLACE_WITH_UNINIT, MEM_REPLACE_WITH_DEFAULT]); -fn check_replace_option_with_none(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { +fn check_replace_option_with_none(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { if let ExprKind::Path(ref replacement_qpath) = src.kind { // Check that second argument is `Option::None` if match_qpath(replacement_qpath, &paths::OPTION_NONE) { @@ -135,7 +135,7 @@ fn check_replace_option_with_none(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest } } -fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { +fn check_replace_with_uninit(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { if_chain! { // check if replacement is mem::MaybeUninit::uninit().assume_init() if let Some(method_def_id) = cx.tables().type_dependent_def_id(src.hir_id); @@ -193,7 +193,7 @@ fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest: &Ex } } -fn check_replace_with_default(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { +fn check_replace_with_default(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { if let ExprKind::Call(ref repl_func, _) = src.kind { if_chain! { if !in_external_macro(cx.tcx.sess, expr_span); @@ -224,8 +224,8 @@ fn check_replace_with_default(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest: &E } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for MemReplace { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { // Check that `expr` is a call to `mem::replace()` if let ExprKind::Call(ref func, ref func_args) = expr.kind; diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs index 092702c8b8c7..fcf7b509eadb 100644 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/clippy_lints/src/methods/bind_instead_of_map.rs @@ -77,7 +77,7 @@ pub(crate) trait BindInsteadOfMap { } fn lint_closure_autofixable( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>], closure_expr: &hir::Expr<'_>, @@ -120,7 +120,7 @@ pub(crate) trait BindInsteadOfMap { } } - fn lint_closure(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, closure_expr: &hir::Expr<'_>) { + fn lint_closure(cx: &LateContext<'_>, expr: &hir::Expr<'_>, closure_expr: &hir::Expr<'_>) { let mut suggs = Vec::new(); let can_sugg = find_all_ret_expressions(cx, closure_expr, |ret_expr| { if_chain! { @@ -156,7 +156,7 @@ pub(crate) trait BindInsteadOfMap { } /// Lint use of `_.and_then(|x| Some(y))` for `Option`s - fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { + fn lint(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { if !match_type(cx, cx.tables().expr_ty(&args[0]), Self::TYPE_QPATH) { return; } @@ -216,7 +216,7 @@ fn contains_try(expr: &hir::Expr<'_>) -> bool { visitor.found } -fn find_all_ret_expressions<'hir, F>(_cx: &LateContext<'_, '_>, expr: &'hir hir::Expr<'hir>, callback: F) -> bool +fn find_all_ret_expressions<'hir, F>(_cx: &LateContext<'_>, expr: &'hir hir::Expr<'hir>, callback: F) -> bool where F: FnMut(&'hir hir::Expr<'hir>) -> bool, { diff --git a/clippy_lints/src/methods/inefficient_to_string.rs b/clippy_lints/src/methods/inefficient_to_string.rs index d29b9adcb7d4..1c0018a5b95e 100644 --- a/clippy_lints/src/methods/inefficient_to_string.rs +++ b/clippy_lints/src/methods/inefficient_to_string.rs @@ -9,7 +9,7 @@ use rustc_lint::LateContext; use rustc_middle::ty::{self, Ty}; /// Checks for the `INEFFICIENT_TO_STRING` lint -pub fn lint<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'tcx>) { +pub fn lint<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'tcx>) { if_chain! { if let Some(to_string_meth_did) = cx.tables().type_dependent_def_id(expr.hir_id); if match_def_path(cx, to_string_meth_did, &paths::TO_STRING_METHOD); @@ -45,7 +45,7 @@ pub fn lint<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr<'_>, arg: &hir::E /// Returns whether `ty` specializes `ToString`. /// Currently, these are `str`, `String`, and `Cow<'_, str>`. -fn specializes_tostring(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> bool { +fn specializes_tostring(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { if let ty::Str = ty.kind { return true; } diff --git a/clippy_lints/src/methods/manual_saturating_arithmetic.rs b/clippy_lints/src/methods/manual_saturating_arithmetic.rs index eb02314f4680..9c04b6d57b90 100644 --- a/clippy_lints/src/methods/manual_saturating_arithmetic.rs +++ b/clippy_lints/src/methods/manual_saturating_arithmetic.rs @@ -6,7 +6,7 @@ use rustc_hir as hir; use rustc_lint::LateContext; use rustc_target::abi::LayoutOf; -pub fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[&[hir::Expr<'_>]], arith: &str) { +pub fn lint(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[&[hir::Expr<'_>]], arith: &str) { let unwrap_arg = &args[0][1]; let arith_lhs = &args[1][0]; let arith_rhs = &args[1][1]; @@ -85,7 +85,7 @@ enum MinMax { Max, } -fn is_min_or_max<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr<'_>) -> Option { +fn is_min_or_max<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>) -> Option { // `T::max_value()` `T::min_value()` inherent methods if_chain! { if let hir::ExprKind::Call(func, args) = &expr.kind; diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 7018a2f40397..216db12f0115 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1357,9 +1357,9 @@ declare_lint_pass!(Methods => [ OPTION_AS_REF_DEREF, ]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { +impl<'tcx> LateLintPass<'tcx> for Methods { #[allow(clippy::too_many_lines)] - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if in_macro(expr.span) { return; } @@ -1471,7 +1471,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { } } - fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { if in_external_macro(cx.sess(), impl_item.span) { return; } @@ -1585,8 +1585,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { /// Checks for the `OR_FUN_CALL` lint. #[allow(clippy::too_many_lines)] -fn lint_or_fun_call<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn lint_or_fun_call<'tcx>( + cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, method_span: Span, name: &str, @@ -1594,7 +1594,7 @@ fn lint_or_fun_call<'a, 'tcx>( ) { // Searches an expression for method calls or function calls that aren't ctors struct FunCallFinder<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, found: bool, } @@ -1625,7 +1625,7 @@ fn lint_or_fun_call<'a, 'tcx>( /// Checks for `unwrap_or(T::new())` or `unwrap_or(T::default())`. fn check_unwrap_or_default( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, name: &str, fun: &hir::Expr<'_>, self_expr: &hir::Expr<'_>, @@ -1667,8 +1667,8 @@ fn lint_or_fun_call<'a, 'tcx>( /// Checks for `*or(foo())`. #[allow(clippy::too_many_arguments)] - fn check_general_case<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, + fn check_general_case<'tcx>( + cx: &LateContext<'tcx>, name: &str, method_span: Span, fun_span: Span, @@ -1769,7 +1769,7 @@ fn lint_or_fun_call<'a, 'tcx>( /// Checks for the `EXPECT_FUN_CALL` lint. #[allow(clippy::too_many_lines)] fn lint_expect_fun_call( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, expr: &hir::Expr<'_>, method_span: Span, name: &str, @@ -1777,7 +1777,7 @@ fn lint_expect_fun_call( ) { // Strip `&`, `as_ref()` and `as_str()` off `arg` until we're left with either a `String` or // `&str` - fn get_arg_root<'a>(cx: &LateContext<'_, '_>, arg: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> { + fn get_arg_root<'a>(cx: &LateContext<'_>, arg: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> { let mut arg_root = arg; loop { arg_root = match &arg_root.kind { @@ -1804,7 +1804,7 @@ fn lint_expect_fun_call( // Only `&'static str` or `String` can be used directly in the `panic!`. Other types should be // converted to string. - fn requires_to_string(cx: &LateContext<'_, '_>, arg: &hir::Expr<'_>) -> bool { + fn requires_to_string(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool { let arg_ty = cx.tables().expr_ty(arg); if is_type_diagnostic_item(cx, arg_ty, sym!(string_type)) { return false; @@ -1819,7 +1819,7 @@ fn lint_expect_fun_call( // Check if an expression could have type `&'static str`, knowing that it // has type `&str` for some lifetime. - fn can_be_static_str(cx: &LateContext<'_, '_>, arg: &hir::Expr<'_>) -> bool { + fn can_be_static_str(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool { match arg.kind { hir::ExprKind::Lit(_) => true, hir::ExprKind::Call(fun, _) => { @@ -1853,7 +1853,7 @@ fn lint_expect_fun_call( } fn generate_format_arg_snippet( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, a: &hir::Expr<'_>, applicability: &mut Applicability, ) -> Vec { @@ -1956,7 +1956,7 @@ fn lint_expect_fun_call( } /// Checks for the `CLONE_ON_COPY` lint. -fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'_>) { +fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'_>) { let ty = cx.tables().expr_ty(expr); if let ty::Ref(_, inner, _) = arg_ty.kind { if let ty::Ref(_, innermost, _) = inner.kind { @@ -2050,7 +2050,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &hir: } } -fn lint_clone_on_ref_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>) { +fn lint_clone_on_ref_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>) { let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(arg)); if let ty::Adt(_, subst) = obj_ty.kind { @@ -2081,7 +2081,7 @@ fn lint_clone_on_ref_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &h } } -fn lint_string_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { +fn lint_string_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { let arg = &args[1]; if let Some(arglists) = method_chain_args(arg, &["chars"]) { let target = &arglists[0][0]; @@ -2112,14 +2112,14 @@ fn lint_string_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hi } } -fn lint_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { +fn lint_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&args[0])); if is_type_diagnostic_item(cx, obj_ty, sym!(string_type)) { lint_string_extend(cx, expr, args); } } -fn lint_cstring_as_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, source: &hir::Expr<'_>, unwrap: &hir::Expr<'_>) { +fn lint_cstring_as_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, source: &hir::Expr<'_>, unwrap: &hir::Expr<'_>) { if_chain! { let source_type = cx.tables().expr_ty(source); if let ty::Adt(def, substs) = source_type.kind; @@ -2139,11 +2139,7 @@ fn lint_cstring_as_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, source: & } } -fn lint_iter_cloned_collect<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, - expr: &hir::Expr<'_>, - iter_args: &'tcx [hir::Expr<'_>], -) { +fn lint_iter_cloned_collect<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, iter_args: &'tcx [hir::Expr<'_>]) { if_chain! { if is_type_diagnostic_item(cx, cx.tables().expr_ty(expr), sym!(vec_type)); if let Some(slice) = derefs_to_slice(cx, &iter_args[0], cx.tables().expr_ty(&iter_args[0])); @@ -2164,9 +2160,9 @@ fn lint_iter_cloned_collect<'a, 'tcx>( } } -fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, fold_args: &[hir::Expr<'_>], fold_span: Span) { +fn lint_unnecessary_fold(cx: &LateContext<'_>, expr: &hir::Expr<'_>, fold_args: &[hir::Expr<'_>], fold_span: Span) { fn check_fold_with_op( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, expr: &hir::Expr<'_>, fold_args: &[hir::Expr<'_>], fold_span: Span, @@ -2251,7 +2247,7 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, fold_ar } } -fn lint_step_by<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr<'_>, args: &'tcx [hir::Expr<'_>]) { +fn lint_step_by<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, args: &'tcx [hir::Expr<'_>]) { if match_trait_method(cx, expr, &paths::ITERATOR) { if let Some((Constant::Int(0), _)) = constant(cx, cx.tables(), &args[1]) { span_lint( @@ -2264,7 +2260,7 @@ fn lint_step_by<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr<'_>, args } } -fn lint_iter_next<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>, iter_args: &'tcx [hir::Expr<'_>]) { +fn lint_iter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, iter_args: &'tcx [hir::Expr<'_>]) { let caller_expr = &iter_args[0]; // Skip lint if the `iter().next()` expression is a for loop argument, @@ -2318,8 +2314,8 @@ fn lint_iter_next<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_ } } -fn lint_iter_nth<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn lint_iter_nth<'tcx>( + cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, nth_and_iter_args: &[&'tcx [hir::Expr<'tcx>]], is_mut: bool, @@ -2348,7 +2344,7 @@ fn lint_iter_nth<'a, 'tcx>( ); } -fn lint_iter_nth_zero<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr<'_>, nth_args: &'tcx [hir::Expr<'_>]) { +fn lint_iter_nth_zero<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, nth_args: &'tcx [hir::Expr<'_>]) { if_chain! { if match_trait_method(cx, expr, &paths::ITERATOR); if let Some((Constant::Int(0), _)) = constant(cx, cx.tables(), &nth_args[1]); @@ -2367,12 +2363,7 @@ fn lint_iter_nth_zero<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr<'_> } } -fn lint_get_unwrap<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, - expr: &hir::Expr<'_>, - get_args: &'tcx [hir::Expr<'_>], - is_mut: bool, -) { +fn lint_get_unwrap<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, get_args: &'tcx [hir::Expr<'_>], is_mut: bool) { // Note: we don't want to lint `get_mut().unwrap` for `HashMap` or `BTreeMap`, // because they do not implement `IndexMut` let mut applicability = Applicability::MachineApplicable; @@ -2445,7 +2436,7 @@ fn lint_get_unwrap<'a, 'tcx>( ); } -fn lint_iter_skip_next(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) { +fn lint_iter_skip_next(cx: &LateContext<'_>, expr: &hir::Expr<'_>) { // lint if caller of skip is an Iterator if match_trait_method(cx, expr, &paths::ITERATOR) { span_lint_and_help( @@ -2459,12 +2450,12 @@ fn lint_iter_skip_next(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) { } } -fn derefs_to_slice<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn derefs_to_slice<'tcx>( + cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>, ty: Ty<'tcx>, ) -> Option<&'tcx hir::Expr<'tcx>> { - fn may_slice<'a>(cx: &LateContext<'_, 'a>, ty: Ty<'a>) -> bool { + fn may_slice<'a>(cx: &LateContext<'a>, ty: Ty<'a>) -> bool { match ty.kind { ty::Slice(_) => true, ty::Adt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()), @@ -2504,7 +2495,7 @@ fn derefs_to_slice<'a, 'tcx>( } /// lint use of `unwrap()` for `Option`s and `Result`s -fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hir::Expr<'_>]) { +fn lint_unwrap(cx: &LateContext<'_>, expr: &hir::Expr<'_>, unwrap_args: &[hir::Expr<'_>]) { let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&unwrap_args[0])); let mess = if is_type_diagnostic_item(cx, obj_ty, sym!(option_type)) { @@ -2532,7 +2523,7 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hi } /// lint use of `expect()` for `Option`s and `Result`s -fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hir::Expr<'_>]) { +fn lint_expect(cx: &LateContext<'_>, expr: &hir::Expr<'_>, expect_args: &[hir::Expr<'_>]) { let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&expect_args[0])); let mess = if is_type_diagnostic_item(cx, obj_ty, sym!(option_type)) { @@ -2556,7 +2547,7 @@ fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hi } /// lint use of `ok().expect()` for `Result`s -fn lint_ok_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, ok_args: &[hir::Expr<'_>]) { +fn lint_ok_expect(cx: &LateContext<'_>, expr: &hir::Expr<'_>, ok_args: &[hir::Expr<'_>]) { if_chain! { // lint if the caller of `ok()` is a `Result` if is_type_diagnostic_item(cx, cx.tables().expr_ty(&ok_args[0]), sym!(result_type)); @@ -2578,7 +2569,7 @@ fn lint_ok_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, ok_args: &[hir } /// lint use of `map().flatten()` for `Iterators` and 'Options' -fn lint_map_flatten<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>, map_args: &'tcx [hir::Expr<'_>]) { +fn lint_map_flatten<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map_args: &'tcx [hir::Expr<'_>]) { // lint if caller of `.map().flatten()` is an Iterator if match_trait_method(cx, expr, &paths::ITERATOR) { let msg = "called `map(..).flatten()` on an `Iterator`. \ @@ -2617,8 +2608,8 @@ fn lint_map_flatten<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr< } /// lint use of `map().unwrap_or_else()` for `Option`s and `Result`s -fn lint_map_unwrap_or_else<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn lint_map_unwrap_or_else<'tcx>( + cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map_args: &'tcx [hir::Expr<'_>], unwrap_args: &'tcx [hir::Expr<'_>], @@ -2674,11 +2665,7 @@ fn lint_map_unwrap_or_else<'a, 'tcx>( } /// lint use of `_.map_or(None, _)` for `Option`s and `Result`s -fn lint_map_or_none<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, - expr: &'tcx hir::Expr<'_>, - map_or_args: &'tcx [hir::Expr<'_>], -) { +fn lint_map_or_none<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map_or_args: &'tcx [hir::Expr<'_>]) { let is_option = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_or_args[0]), sym!(option_type)); let is_result = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_or_args[0]), sym!(result_type)); @@ -2748,11 +2735,7 @@ fn lint_map_or_none<'a, 'tcx>( } /// lint use of `filter().next()` for `Iterators` -fn lint_filter_next<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, - expr: &'tcx hir::Expr<'_>, - filter_args: &'tcx [hir::Expr<'_>], -) { +fn lint_filter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, filter_args: &'tcx [hir::Expr<'_>]) { // lint if caller of `.filter().next()` is an Iterator if match_trait_method(cx, expr, &paths::ITERATOR) { let msg = "called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling \ @@ -2775,8 +2758,8 @@ fn lint_filter_next<'a, 'tcx>( } /// lint use of `skip_while().next()` for `Iterators` -fn lint_skip_while_next<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn lint_skip_while_next<'tcx>( + cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, _skip_while_args: &'tcx [hir::Expr<'_>], ) { @@ -2794,8 +2777,8 @@ fn lint_skip_while_next<'a, 'tcx>( } /// lint use of `filter().map()` for `Iterators` -fn lint_filter_map<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn lint_filter_map<'tcx>( + cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, _filter_args: &'tcx [hir::Expr<'_>], _map_args: &'tcx [hir::Expr<'_>], @@ -2809,11 +2792,7 @@ fn lint_filter_map<'a, 'tcx>( } /// lint use of `filter_map().next()` for `Iterators` -fn lint_filter_map_next<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, - expr: &'tcx hir::Expr<'_>, - filter_args: &'tcx [hir::Expr<'_>], -) { +fn lint_filter_map_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, filter_args: &'tcx [hir::Expr<'_>]) { if match_trait_method(cx, expr, &paths::ITERATOR) { let msg = "called `filter_map(p).next()` on an `Iterator`. This is more succinctly expressed by calling \ `.find_map(p)` instead."; @@ -2834,8 +2813,8 @@ fn lint_filter_map_next<'a, 'tcx>( } /// lint use of `find().map()` for `Iterators` -fn lint_find_map<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn lint_find_map<'tcx>( + cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, _find_args: &'tcx [hir::Expr<'_>], map_args: &'tcx [hir::Expr<'_>], @@ -2849,8 +2828,8 @@ fn lint_find_map<'a, 'tcx>( } /// lint use of `filter_map().map()` for `Iterators` -fn lint_filter_map_map<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn lint_filter_map_map<'tcx>( + cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, _filter_args: &'tcx [hir::Expr<'_>], _map_args: &'tcx [hir::Expr<'_>], @@ -2864,8 +2843,8 @@ fn lint_filter_map_map<'a, 'tcx>( } /// lint use of `filter().flat_map()` for `Iterators` -fn lint_filter_flat_map<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn lint_filter_flat_map<'tcx>( + cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, _filter_args: &'tcx [hir::Expr<'_>], _map_args: &'tcx [hir::Expr<'_>], @@ -2880,8 +2859,8 @@ fn lint_filter_flat_map<'a, 'tcx>( } /// lint use of `filter_map().flat_map()` for `Iterators` -fn lint_filter_map_flat_map<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn lint_filter_map_flat_map<'tcx>( + cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, _filter_args: &'tcx [hir::Expr<'_>], _map_args: &'tcx [hir::Expr<'_>], @@ -2896,8 +2875,8 @@ fn lint_filter_map_flat_map<'a, 'tcx>( } /// lint use of `flat_map` for `Iterators` where `flatten` would be sufficient -fn lint_flat_map_identity<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn lint_flat_map_identity<'tcx>( + cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, flat_map_args: &'tcx [hir::Expr<'_>], flat_map_span: Span, @@ -2945,8 +2924,8 @@ fn lint_flat_map_identity<'a, 'tcx>( } /// lint searching an Iterator followed by `is_some()` -fn lint_search_is_some<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn lint_search_is_some<'tcx>( + cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, search_method: &str, search_args: &'tcx [hir::Expr<'_>], @@ -3010,7 +2989,7 @@ struct BinaryExprInfo<'a> { } /// Checks for the `CHARS_NEXT_CMP` and `CHARS_LAST_CMP` lints. -fn lint_binary_expr_with_method_call(cx: &LateContext<'_, '_>, info: &mut BinaryExprInfo<'_>) { +fn lint_binary_expr_with_method_call(cx: &LateContext<'_>, info: &mut BinaryExprInfo<'_>) { macro_rules! lint_with_both_lhs_and_rhs { ($func:ident, $cx:expr, $info:ident) => { if !$func($cx, $info) { @@ -3030,7 +3009,7 @@ fn lint_binary_expr_with_method_call(cx: &LateContext<'_, '_>, info: &mut Binary /// Wrapper fn for `CHARS_NEXT_CMP` and `CHARS_LAST_CMP` lints. fn lint_chars_cmp( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, info: &BinaryExprInfo<'_>, chain_methods: &[&str], lint: &'static Lint, @@ -3073,12 +3052,12 @@ fn lint_chars_cmp( } /// Checks for the `CHARS_NEXT_CMP` lint. -fn lint_chars_next_cmp<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &BinaryExprInfo<'_>) -> bool { +fn lint_chars_next_cmp<'tcx>(cx: &LateContext<'tcx>, info: &BinaryExprInfo<'_>) -> bool { lint_chars_cmp(cx, info, &["chars", "next"], CHARS_NEXT_CMP, "starts_with") } /// Checks for the `CHARS_LAST_CMP` lint. -fn lint_chars_last_cmp<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &BinaryExprInfo<'_>) -> bool { +fn lint_chars_last_cmp<'tcx>(cx: &LateContext<'tcx>, info: &BinaryExprInfo<'_>) -> bool { if lint_chars_cmp(cx, info, &["chars", "last"], CHARS_LAST_CMP, "ends_with") { true } else { @@ -3087,8 +3066,8 @@ fn lint_chars_last_cmp<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &BinaryExprIn } /// Wrapper fn for `CHARS_NEXT_CMP` and `CHARS_LAST_CMP` lints with `unwrap()`. -fn lint_chars_cmp_with_unwrap<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn lint_chars_cmp_with_unwrap<'tcx>( + cx: &LateContext<'tcx>, info: &BinaryExprInfo<'_>, chain_methods: &[&str], lint: &'static Lint, @@ -3122,12 +3101,12 @@ fn lint_chars_cmp_with_unwrap<'a, 'tcx>( } /// Checks for the `CHARS_NEXT_CMP` lint with `unwrap()`. -fn lint_chars_next_cmp_with_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &BinaryExprInfo<'_>) -> bool { +fn lint_chars_next_cmp_with_unwrap<'tcx>(cx: &LateContext<'tcx>, info: &BinaryExprInfo<'_>) -> bool { lint_chars_cmp_with_unwrap(cx, info, &["chars", "next", "unwrap"], CHARS_NEXT_CMP, "starts_with") } /// Checks for the `CHARS_LAST_CMP` lint with `unwrap()`. -fn lint_chars_last_cmp_with_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &BinaryExprInfo<'_>) -> bool { +fn lint_chars_last_cmp_with_unwrap<'tcx>(cx: &LateContext<'tcx>, info: &BinaryExprInfo<'_>) -> bool { if lint_chars_cmp_with_unwrap(cx, info, &["chars", "last", "unwrap"], CHARS_LAST_CMP, "ends_with") { true } else { @@ -3136,11 +3115,7 @@ fn lint_chars_last_cmp_with_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: & } /// lint for length-1 `str`s for methods in `PATTERN_METHODS` -fn lint_single_char_pattern<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, - _expr: &'tcx hir::Expr<'_>, - arg: &'tcx hir::Expr<'_>, -) { +fn lint_single_char_pattern<'tcx>(cx: &LateContext<'tcx>, _expr: &'tcx hir::Expr<'_>, arg: &'tcx hir::Expr<'_>) { if_chain! { if let hir::ExprKind::Lit(lit) = &arg.kind; if let ast::LitKind::Str(r, style) = lit.node; @@ -3171,7 +3146,7 @@ fn lint_single_char_pattern<'a, 'tcx>( } /// Checks for the `USELESS_ASREF` lint. -fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, call_name: &str, as_ref_args: &[hir::Expr<'_>]) { +fn lint_asref(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str, as_ref_args: &[hir::Expr<'_>]) { // when we get here, we've already checked that the call name is "as_ref" or "as_mut" // check if the call is to the actual `AsRef` or `AsMut` trait if match_trait_method(cx, expr, &paths::ASREF_TRAIT) || match_trait_method(cx, expr, &paths::ASMUT_TRAIT) { @@ -3206,7 +3181,7 @@ fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, call_name: &str, a } } -fn ty_has_iter_method(cx: &LateContext<'_, '_>, self_ref_ty: Ty<'_>) -> Option<(&'static str, &'static str)> { +fn ty_has_iter_method(cx: &LateContext<'_>, self_ref_ty: Ty<'_>) -> Option<(&'static str, &'static str)> { has_iter_method(cx, self_ref_ty).map(|ty_name| { let mutbl = match self_ref_ty.kind { ty::Ref(_, _, mutbl) => mutbl, @@ -3220,7 +3195,7 @@ fn ty_has_iter_method(cx: &LateContext<'_, '_>, self_ref_ty: Ty<'_>) -> Option<( }) } -fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, self_ref_ty: Ty<'_>, method_span: Span) { +fn lint_into_iter(cx: &LateContext<'_>, expr: &hir::Expr<'_>, self_ref_ty: Ty<'_>, method_span: Span) { if !match_trait_method(cx, expr, &paths::INTO_ITERATOR) { return; } @@ -3241,7 +3216,7 @@ fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, self_ref_ty: T } /// lint for `MaybeUninit::uninit().assume_init()` (we already have the latter) -fn lint_maybe_uninit(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, outer: &hir::Expr<'_>) { +fn lint_maybe_uninit(cx: &LateContext<'_>, expr: &hir::Expr<'_>, outer: &hir::Expr<'_>) { if_chain! { if let hir::ExprKind::Call(ref callee, ref args) = expr.kind; if args.is_empty(); @@ -3259,7 +3234,7 @@ fn lint_maybe_uninit(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, outer: &hir } } -fn is_maybe_uninit_ty_valid(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> bool { +fn is_maybe_uninit_ty_valid(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { match ty.kind { ty::Array(ref component, _) => is_maybe_uninit_ty_valid(cx, component), ty::Tuple(ref types) => types.types().all(|ty| is_maybe_uninit_ty_valid(cx, ty)), @@ -3268,7 +3243,7 @@ fn is_maybe_uninit_ty_valid(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> bool { } } -fn lint_suspicious_map(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) { +fn lint_suspicious_map(cx: &LateContext<'_>, expr: &hir::Expr<'_>) { span_lint_and_help( cx, SUSPICIOUS_MAP, @@ -3280,8 +3255,8 @@ fn lint_suspicious_map(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) { } /// lint use of `_.as_ref().map(Deref::deref)` for `Option`s -fn lint_option_as_ref_deref<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn lint_option_as_ref_deref<'tcx>( + cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, as_ref_args: &[hir::Expr<'_>], map_args: &[hir::Expr<'_>], @@ -3376,7 +3351,7 @@ fn lint_option_as_ref_deref<'a, 'tcx>( } /// Given a `Result` type, return its error type (`E`). -fn get_error_type<'a>(cx: &LateContext<'_, '_>, ty: Ty<'a>) -> Option> { +fn get_error_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option> { match ty.kind { ty::Adt(_, substs) if is_type_diagnostic_item(cx, ty, sym!(result_type)) => substs.types().nth(1), _ => None, @@ -3384,7 +3359,7 @@ fn get_error_type<'a>(cx: &LateContext<'_, '_>, ty: Ty<'a>) -> Option> { } /// This checks whether a given type is known to implement Debug. -fn has_debug_impl<'a, 'b>(ty: Ty<'a>, cx: &LateContext<'b, 'a>) -> bool { +fn has_debug_impl<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool { cx.tcx .get_diagnostic_item(sym::debug_trait) .map_or(false, |debug| implements_trait(cx, ty, debug, &[])) @@ -3477,8 +3452,8 @@ enum SelfKind { } impl SelfKind { - fn matches<'a>(self, cx: &LateContext<'_, 'a>, parent_ty: Ty<'a>, ty: Ty<'a>) -> bool { - fn matches_value<'a>(cx: &LateContext<'_, 'a>, parent_ty: Ty<'_>, ty: Ty<'_>) -> bool { + fn matches<'a>(self, cx: &LateContext<'a>, parent_ty: Ty<'a>, ty: Ty<'a>) -> bool { + fn matches_value<'a>(cx: &LateContext<'a>, parent_ty: Ty<'_>, ty: Ty<'_>) -> bool { if ty == parent_ty { true } else if ty.is_box() { @@ -3494,12 +3469,7 @@ impl SelfKind { } } - fn matches_ref<'a>( - cx: &LateContext<'_, 'a>, - mutability: hir::Mutability, - parent_ty: Ty<'a>, - ty: Ty<'a>, - ) -> bool { + fn matches_ref<'a>(cx: &LateContext<'a>, mutability: hir::Mutability, parent_ty: Ty<'a>, ty: Ty<'a>) -> bool { if let ty::Ref(_, t, m) = ty.kind { return m == mutability && t == parent_ty; } @@ -3563,7 +3533,7 @@ enum OutType { } impl OutType { - fn matches(self, cx: &LateContext<'_, '_>, ty: &hir::FnRetTy<'_>) -> bool { + fn matches(self, cx: &LateContext<'_>, ty: &hir::FnRetTy<'_>) -> bool { let is_unit = |ty: &hir::Ty<'_>| SpanlessEq::new(cx).eq_ty_kind(&ty.kind, &hir::TyKind::Tup(&[])); match (self, ty) { (Self::Unit, &hir::FnRetTy::DefaultReturn(_)) => true, @@ -3614,7 +3584,7 @@ fn contains_return(expr: &hir::Expr<'_>) -> bool { visitor.found } -fn check_pointer_offset(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { +fn check_pointer_offset(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { if_chain! { if args.len() == 2; if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.tables().expr_ty(&args[0]).kind; @@ -3626,7 +3596,7 @@ fn check_pointer_offset(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[ } } -fn lint_filetype_is_file(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { +fn lint_filetype_is_file(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { let ty = cx.tables().expr_ty(&args[0]); if !match_type(cx, ty, &paths::FILE_TYPE) { diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 7f4529a5870a..672eb75c57fc 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -12,8 +12,8 @@ use rustc_span::symbol::Symbol; use super::MAP_UNWRAP_OR; /// lint use of `map().unwrap_or()` for `Option`s -pub(super) fn lint<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +pub(super) fn lint<'tcx>( + cx: &LateContext<'tcx>, expr: &rustc_hir::Expr<'_>, map_args: &'tcx [rustc_hir::Expr<'_>], unwrap_args: &'tcx [rustc_hir::Expr<'_>], @@ -87,7 +87,7 @@ pub(super) fn lint<'a, 'tcx>( } struct UnwrapVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, identifiers: FxHashSet, } @@ -105,7 +105,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrapVisitor<'a, 'tcx> { } struct MapExprVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, identifiers: FxHashSet, found_identifier: bool, } diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index 8a3df85c91bf..fdcba1105428 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -11,7 +11,7 @@ use if_chain::if_chain; use super::UNNECESSARY_FILTER_MAP; -pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { +pub(super) fn lint(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { if !match_trait_method(cx, expr, &paths::ITERATOR) { return; } @@ -52,11 +52,7 @@ pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir:: } // returns (found_mapping, found_filtering) -fn check_expression<'a, 'tcx>( - cx: &'a LateContext<'a, 'tcx>, - arg_id: hir::HirId, - expr: &'tcx hir::Expr<'_>, -) -> (bool, bool) { +fn check_expression<'tcx>(cx: &LateContext<'tcx>, arg_id: hir::HirId, expr: &'tcx hir::Expr<'_>) -> (bool, bool) { match &expr.kind { hir::ExprKind::Call(ref func, ref args) => { if_chain! { @@ -104,7 +100,7 @@ fn check_expression<'a, 'tcx>( } struct ReturnVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, arg_id: hir::HirId, // Found a non-None return that isn't Some(input) found_mapping: bool, @@ -113,7 +109,7 @@ struct ReturnVisitor<'a, 'tcx> { } impl<'a, 'tcx> ReturnVisitor<'a, 'tcx> { - fn new(cx: &'a LateContext<'a, 'tcx>, arg_id: hir::HirId) -> ReturnVisitor<'a, 'tcx> { + fn new(cx: &'a LateContext<'tcx>, arg_id: hir::HirId) -> ReturnVisitor<'a, 'tcx> { ReturnVisitor { cx, arg_id, diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index 8e6f3925d660..0a2d577396a5 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -27,8 +27,8 @@ declare_clippy_lint! { declare_lint_pass!(MinMaxPass => [MIN_MAX]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MinMaxPass { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for MinMaxPass { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let Some((outer_max, outer_c, oe)) = min_max(cx, expr) { if let Some((inner_max, inner_c, ie)) = min_max(cx, oe) { if outer_max == inner_max { @@ -59,7 +59,7 @@ enum MinMax { Max, } -fn min_max<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option<(MinMax, Constant, &'a Expr<'a>)> { +fn min_max<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(MinMax, Constant, &'a Expr<'a>)> { if let ExprKind::Call(ref path, ref args) = expr.kind { if let ExprKind::Path(ref qpath) = path.kind { cx.tables() @@ -82,11 +82,7 @@ fn min_max<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option<(MinMax, } } -fn fetch_const<'a>( - cx: &LateContext<'_, '_>, - args: &'a [Expr<'a>], - m: MinMax, -) -> Option<(MinMax, Constant, &'a Expr<'a>)> { +fn fetch_const<'a>(cx: &LateContext<'_>, args: &'a [Expr<'a>], m: MinMax) -> Option<(MinMax, Constant, &'a Expr<'a>)> { if args.len() != 2 { return None; } diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index fcd77088b88e..d7e1a62a19d5 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -260,10 +260,10 @@ declare_lint_pass!(MiscLints => [ FLOAT_CMP_CONST ]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints { +impl<'tcx> LateLintPass<'tcx> for MiscLints { fn check_fn( &mut self, - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, k: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, @@ -287,7 +287,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints { } } - fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) { + fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { if_chain! { if let StmtKind::Local(ref local) = stmt.kind; if let PatKind::Binding(an, .., name, None) = local.pat.kind; @@ -360,7 +360,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints { }; } - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { match expr.kind { ExprKind::Cast(ref e, ref ty) => { check_cast(cx, expr.span, e, ty); @@ -493,7 +493,7 @@ fn get_lint_and_message( } } -fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) { +fn check_nan(cx: &LateContext<'_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) { if_chain! { if !in_constant(cx, cmp_expr.hir_id); if let Some((value, _)) = constant(cx, cx.tables(), expr); @@ -516,7 +516,7 @@ fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) { } } -fn is_named_constant<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> bool { +fn is_named_constant<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool { if let Some((_, res)) = constant(cx, cx.tables(), expr) { res } else { @@ -524,7 +524,7 @@ fn is_named_constant<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) } } -fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> bool { +fn is_allowed<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool { match constant(cx, cx.tables(), expr) { Some((Constant::F32(f), _)) => f == 0.0 || f.is_infinite(), Some((Constant::F64(f), _)) => f == 0.0 || f.is_infinite(), @@ -538,7 +538,7 @@ fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> boo } // Return true if `expr` is the result of `signum()` invoked on a float value. -fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { +fn is_signum(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { // The negation of a signum is still a signum if let ExprKind::Unary(UnOp::UnNeg, ref child_expr) = expr.kind { return is_signum(cx, &child_expr); @@ -556,7 +556,7 @@ fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { false } -fn is_float(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { +fn is_float(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let value = &walk_ptrs_ty(cx.tables().expr_ty(expr)).kind; if let ty::Array(arr_ty, _) = value { @@ -566,11 +566,11 @@ fn is_float(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { matches!(value, ty::Float(_)) } -fn is_array(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { +fn is_array(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { matches!(&walk_ptrs_ty(cx.tables().expr_ty(expr)).kind, ty::Array(_, _)) } -fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr<'_>, other: &Expr<'_>) { +fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>) { let (arg_ty, snip) = match expr.kind { ExprKind::MethodCall(.., ref args, _) if args.len() == 1 => { if match_trait_method(cx, expr, &paths::TO_STRING) || match_trait_method(cx, expr, &paths::TO_OWNED) { @@ -655,7 +655,7 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr<'_>, other: &Expr<'_>) { /// Heuristic to see if an expression is used. Should be compatible with /// `unused_variables`'s idea /// of what it means for an expression to be "used". -fn is_used(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { +fn is_used(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { if let Some(parent) = get_parent_expr(cx, expr) { match parent.kind { ExprKind::Assign(_, ref rhs, _) | ExprKind::AssignOp(_, _, ref rhs) => { @@ -686,7 +686,7 @@ fn in_attributes_expansion(expr: &Expr<'_>) -> bool { } /// Tests whether `res` is a variable defined outside a macro. -fn non_macro_local(cx: &LateContext<'_, '_>, res: def::Res) -> bool { +fn non_macro_local(cx: &LateContext<'_>, res: def::Res) -> bool { if let def::Res::Local(id) = res { !cx.tcx.hir().span(id).from_expansion() } else { @@ -694,7 +694,7 @@ fn non_macro_local(cx: &LateContext<'_, '_>, res: def::Res) -> bool { } } -fn check_cast(cx: &LateContext<'_, '_>, span: Span, e: &Expr<'_>, ty: &Ty<'_>) { +fn check_cast(cx: &LateContext<'_>, span: Span, e: &Expr<'_>, ty: &Ty<'_>) { if_chain! { if let TyKind::Ptr(ref mut_ty) = ty.kind; if let ExprKind::Lit(ref lit) = e.kind; diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 9cfc8d191349..bdce1bf15218 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -71,10 +71,10 @@ declare_clippy_lint! { declare_lint_pass!(MissingConstForFn => [MISSING_CONST_FOR_FN]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn { +impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { fn check_fn( &mut self, - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, kind: FnKind<'_>, _: &FnDecl<'_>, _: &Body<'_>, @@ -130,7 +130,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn { /// Returns true if any of the method parameters is a type that implements `Drop`. The method /// can't be made const then, because `drop` can't be const-evaluated. -fn method_accepts_dropable(cx: &LateContext<'_, '_>, param_tys: &[hir::Ty<'_>]) -> bool { +fn method_accepts_dropable(cx: &LateContext<'_>, param_tys: &[hir::Ty<'_>]) -> bool { // If any of the params are dropable, return true param_tys.iter().any(|hir_ty| { let ty_ty = hir_ty_to_ty(cx.tcx, hir_ty); diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 0fd1e87f9e41..06e0f43c10bb 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -69,13 +69,7 @@ impl MissingDoc { } } - fn check_missing_docs_attrs( - &self, - cx: &LateContext<'_, '_>, - attrs: &[ast::Attribute], - sp: Span, - desc: &'static str, - ) { + fn check_missing_docs_attrs(&self, cx: &LateContext<'_>, attrs: &[ast::Attribute], sp: Span, desc: &'static str) { // If we're building a test harness, then warning about // documentation is probably not really relevant right now. if cx.sess().opts.test { @@ -107,8 +101,8 @@ impl MissingDoc { impl_lint_pass!(MissingDoc => [MISSING_DOCS_IN_PRIVATE_ITEMS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { - fn enter_lint_attrs(&mut self, _: &LateContext<'a, 'tcx>, attrs: &'tcx [ast::Attribute]) { +impl<'tcx> LateLintPass<'tcx> for MissingDoc { + fn enter_lint_attrs(&mut self, _: &LateContext<'tcx>, attrs: &'tcx [ast::Attribute]) { let doc_hidden = self.doc_hidden() || attrs.iter().any(|attr| { attr.check_name(sym!(doc)) @@ -120,15 +114,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { self.doc_hidden_stack.push(doc_hidden); } - fn exit_lint_attrs(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx [ast::Attribute]) { + fn exit_lint_attrs(&mut self, _: &LateContext<'tcx>, _: &'tcx [ast::Attribute]) { self.doc_hidden_stack.pop().expect("empty doc_hidden_stack"); } - fn check_crate(&mut self, cx: &LateContext<'a, 'tcx>, krate: &'tcx hir::Crate<'_>) { + fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) { self.check_missing_docs_attrs(cx, &krate.item.attrs, krate.item.span, "crate"); } - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item<'_>) { + fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) { let desc = match it.kind { hir::ItemKind::Const(..) => "a constant", hir::ItemKind::Enum(..) => "an enum", @@ -161,7 +155,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { self.check_missing_docs_attrs(cx, &it.attrs, it.span, desc); } - fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, trait_item: &'tcx hir::TraitItem<'_>) { + fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) { let desc = match trait_item.kind { hir::TraitItemKind::Const(..) => "an associated constant", hir::TraitItemKind::Fn(..) => "a trait method", @@ -171,7 +165,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { self.check_missing_docs_attrs(cx, &trait_item.attrs, trait_item.span, desc); } - fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { // If the method is an impl for a trait, don't doc. let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); match cx.tcx.associated_item(def_id).container { @@ -191,13 +185,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { self.check_missing_docs_attrs(cx, &impl_item.attrs, impl_item.span, desc); } - fn check_struct_field(&mut self, cx: &LateContext<'a, 'tcx>, sf: &'tcx hir::StructField<'_>) { + fn check_struct_field(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::StructField<'_>) { if !sf.is_positional() { self.check_missing_docs_attrs(cx, &sf.attrs, sf.span, "a struct field"); } } - fn check_variant(&mut self, cx: &LateContext<'a, 'tcx>, v: &'tcx hir::Variant<'_>) { + fn check_variant(&mut self, cx: &LateContext<'tcx>, v: &'tcx hir::Variant<'_>) { self.check_missing_docs_attrs(cx, &v.attrs, v.span, "a variant"); } } diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 1802470b1841..bf80b62afe6e 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -56,7 +56,7 @@ declare_clippy_lint! { "detects missing `#[inline]` attribute for public callables (functions, trait methods, methods...)" } -fn check_missing_inline_attrs(cx: &LateContext<'_, '_>, attrs: &[ast::Attribute], sp: Span, desc: &'static str) { +fn check_missing_inline_attrs(cx: &LateContext<'_>, attrs: &[ast::Attribute], sp: Span, desc: &'static str) { let has_inline = attrs.iter().any(|a| a.check_name(sym!(inline))); if !has_inline { span_lint( @@ -68,7 +68,7 @@ fn check_missing_inline_attrs(cx: &LateContext<'_, '_>, attrs: &[ast::Attribute] } } -fn is_executable(cx: &LateContext<'_, '_>) -> bool { +fn is_executable(cx: &LateContext<'_>) -> bool { use rustc_session::config::CrateType; cx.tcx.sess.crate_types().iter().any(|t: &CrateType| match t { @@ -79,8 +79,8 @@ fn is_executable(cx: &LateContext<'_, '_>) -> bool { declare_lint_pass!(MissingInline => [MISSING_INLINE_IN_PUBLIC_ITEMS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for MissingInline { + fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) { if rustc_middle::lint::in_external_macro(cx.sess(), it.span) || is_executable(cx) { return; } @@ -129,7 +129,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline { }; } - fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { use rustc_middle::ty::{ImplContainer, TraitContainer}; if rustc_middle::lint::in_external_macro(cx.sess(), impl_item.span) || is_executable(cx) { return; diff --git a/clippy_lints/src/modulo_arithmetic.rs b/clippy_lints/src/modulo_arithmetic.rs index f76e4721e1f6..59ccc6333fdc 100644 --- a/clippy_lints/src/modulo_arithmetic.rs +++ b/clippy_lints/src/modulo_arithmetic.rs @@ -36,7 +36,7 @@ struct OperandInfo { is_integral: bool, } -fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option { +fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { match constant(cx, cx.tables(), operand) { Some((Constant::Int(v), _)) => match cx.tables().expr_ty(expr).kind { ty::Int(ity) => { @@ -79,8 +79,8 @@ fn might_have_negative_value(t: &ty::TyS<'_>) -> bool { t.is_signed() || t.is_floating_point() } -fn check_const_operands<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn check_const_operands<'tcx>( + cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, lhs_operand: &OperandInfo, rhs_operand: &OperandInfo, @@ -105,7 +105,7 @@ fn check_const_operands<'a, 'tcx>( } } -fn check_non_const_operands<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, operand: &Expr<'_>) { +fn check_non_const_operands<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, operand: &Expr<'_>) { let operand_type = cx.tables().expr_ty(operand); if might_have_negative_value(operand_type) { span_lint_and_then( @@ -123,8 +123,8 @@ fn check_non_const_operands<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Ex } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ModuloArithmetic { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for ModuloArithmetic { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { match &expr.kind { ExprKind::Binary(op, lhs, rhs) | ExprKind::AssignOp(op, lhs, rhs) => { if let BinOpKind::Rem = op.node { diff --git a/clippy_lints/src/multiple_crate_versions.rs b/clippy_lints/src/multiple_crate_versions.rs index 6c42014b4c8a..c1773cef7a8b 100644 --- a/clippy_lints/src/multiple_crate_versions.rs +++ b/clippy_lints/src/multiple_crate_versions.rs @@ -36,8 +36,8 @@ declare_clippy_lint! { declare_lint_pass!(MultipleCrateVersions => [MULTIPLE_CRATE_VERSIONS]); -impl LateLintPass<'_, '_> for MultipleCrateVersions { - fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) { +impl LateLintPass<'_> for MultipleCrateVersions { + fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { if !run_lints(cx, &[MULTIPLE_CRATE_VERSIONS], CRATE_HIR_ID) { return; } diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 755b196c698c..d8fb8a4bb776 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -51,14 +51,14 @@ declare_clippy_lint! { declare_lint_pass!(MutableKeyType => [ MUTABLE_KEY_TYPE ]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableKeyType { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'tcx>) { +impl<'tcx> LateLintPass<'tcx> for MutableKeyType { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) { if let hir::ItemKind::Fn(ref sig, ..) = item.kind { check_sig(cx, item.hir_id, &sig.decl); } } - fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::ImplItem<'tcx>) { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'tcx>) { if let hir::ImplItemKind::Fn(ref sig, ..) = item.kind { if trait_ref_of_method(cx, item.hir_id).is_none() { check_sig(cx, item.hir_id, &sig.decl); @@ -66,13 +66,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableKeyType { } } - fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem<'tcx>) { + fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'tcx>) { if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { check_sig(cx, item.hir_id, &sig.decl); } } - fn check_local(&mut self, cx: &LateContext<'_, '_>, local: &hir::Local<'_>) { + fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::Local<'_>) { if let hir::PatKind::Wild = local.pat.kind { return; } @@ -80,7 +80,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableKeyType { } } -fn check_sig<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item_hir_id: hir::HirId, decl: &hir::FnDecl<'_>) { +fn check_sig<'tcx>(cx: &LateContext<'tcx>, item_hir_id: hir::HirId, decl: &hir::FnDecl<'_>) { let fn_def_id = cx.tcx.hir().local_def_id(item_hir_id); let fn_sig = cx.tcx.fn_sig(fn_def_id); for (hir_ty, ty) in decl.inputs.iter().zip(fn_sig.inputs().skip_binder().iter()) { @@ -95,7 +95,7 @@ fn check_sig<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item_hir_id: hir::HirId, decl // We want to lint 1. sets or maps with 2. not immutable key types and 3. no unerased // generics (because the compiler cannot ensure immutability for unknown types). -fn check_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, span: Span, ty: Ty<'tcx>) { +fn check_ty<'tcx>(cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) { let ty = walk_ptrs_ty(ty); if let Adt(def, substs) = ty.kind { if [&paths::HASHMAP, &paths::BTREEMAP, &paths::HASHSET, &paths::BTREESET] @@ -108,7 +108,7 @@ fn check_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, span: Span, ty: Ty<'tcx>) { } } -fn is_mutable_type<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Span) -> bool { +fn is_mutable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span) -> bool { match ty.kind { RawPtr(TypeAndMut { ty: inner_ty, mutbl }) | Ref(_, inner_ty, mutbl) => { mutbl == hir::Mutability::Mut || is_mutable_type(cx, inner_ty, span) diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index 6aa77b4df83a..259b4c73d760 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -28,12 +28,12 @@ declare_clippy_lint! { declare_lint_pass!(MutMut => [MUT_MUT]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutMut { - fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block<'_>) { +impl<'tcx> LateLintPass<'tcx> for MutMut { + fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx hir::Block<'_>) { intravisit::walk_block(&mut MutVisitor { cx }, block); } - fn check_ty(&mut self, cx: &LateContext<'a, 'tcx>, ty: &'tcx hir::Ty<'_>) { + fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'_>) { use rustc_hir::intravisit::Visitor; MutVisitor { cx }.visit_ty(ty); @@ -41,7 +41,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutMut { } pub struct MutVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, } impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index dbe257069c3e..53341b6eba75 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -29,8 +29,8 @@ declare_clippy_lint! { declare_lint_pass!(UnnecessaryMutPassed => [UNNECESSARY_MUT_PASSED]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { match e.kind { ExprKind::Call(ref fn_expr, ref arguments) => { if let ExprKind::Path(ref path) = fn_expr.kind { @@ -53,12 +53,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed { } } -fn check_arguments<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, - arguments: &[Expr<'_>], - type_definition: Ty<'tcx>, - name: &str, -) { +fn check_arguments<'tcx>(cx: &LateContext<'tcx>, arguments: &[Expr<'_>], type_definition: Ty<'tcx>, name: &str) { match type_definition.kind { ty::FnDef(..) | ty::FnPtr(_) => { let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs(); diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index 45db5140711a..78d2356748f1 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -35,8 +35,8 @@ declare_lint_pass!(DebugAssertWithMutCall => [DEBUG_ASSERT_WITH_MUT_CALL]); const DEBUG_MACRO_NAMES: [&str; 3] = ["debug_assert", "debug_assert_eq", "debug_assert_ne"]; -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DebugAssertWithMutCall { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for DebugAssertWithMutCall { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { for dmn in &DEBUG_MACRO_NAMES { if is_direct_expn_of(e.span, dmn).is_some() { if let Some(span) = extract_call(cx, e) { @@ -53,7 +53,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DebugAssertWithMutCall { } //HACK(hellow554): remove this when #4694 is implemented -fn extract_call<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) -> Option { +fn extract_call<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> Option { if_chain! { if let ExprKind::Block(ref block, _) = e.kind; if block.stmts.len() == 1; @@ -102,13 +102,13 @@ fn extract_call<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) -> O } struct MutArgVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, expr_span: Option, found: bool, } impl<'a, 'tcx> MutArgVisitor<'a, 'tcx> { - fn new(cx: &'a LateContext<'a, 'tcx>) -> Self { + fn new(cx: &'a LateContext<'tcx>) -> Self { Self { cx, expr_span: None, diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index c227dc54f293..1a821491fcaf 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -64,8 +64,8 @@ declare_clippy_lint! { declare_lint_pass!(Mutex => [MUTEX_ATOMIC, MUTEX_INTEGER]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Mutex { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for Mutex { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { let ty = cx.tables().expr_ty(expr); if let ty::Adt(_, subst) = ty.kind { if is_type_diagnostic_item(cx, ty, sym!(mutex_type)) { diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index 653f9e2ae862..e15376b93262 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -67,8 +67,8 @@ declare_clippy_lint! { declare_lint_pass!(NeedlessBool => [NEEDLESS_BOOL]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for NeedlessBool { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { use self::Expression::{Bool, RetBool}; if let Some((ref pred, ref then_block, Some(ref else_expr))) = higher::if_block(&e) { let reduce = |ret, not| { @@ -127,8 +127,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool { declare_lint_pass!(BoolComparison => [BOOL_COMPARISON]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for BoolComparison { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if e.span.from_expansion() { return; } @@ -218,7 +218,7 @@ fn one_side_is_unary_not<'tcx>(left_side: &'tcx Expr<'_>, right_side: &'tcx Expr } fn check_comparison<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, left_true: Option<(impl FnOnce(Sugg<'a>) -> Sugg<'a>, &str)>, left_false: Option<(impl FnOnce(Sugg<'a>) -> Sugg<'a>, &str)>, @@ -285,7 +285,7 @@ fn check_comparison<'a, 'tcx>( } fn suggest_bool_comparison<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, expr: &Expr<'_>, mut applicability: Applicability, diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index 6bb06defb703..1bea93fcb752 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -40,8 +40,8 @@ pub struct NeedlessBorrow { impl_lint_pass!(NeedlessBorrow => [NEEDLESS_BORROW]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if e.span.from_expansion() || self.derived_item.is_some() { return; } @@ -79,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { } } } - fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat<'_>) { + fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { if pat.span.from_expansion() || self.derived_item.is_some() { return; } @@ -111,14 +111,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { } } - fn check_item(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { + fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) { if item.attrs.iter().any(|a| a.check_name(sym!(automatically_derived))) { debug_assert!(self.derived_item.is_none()); self.derived_item = Some(item.hir_id); } } - fn check_item_post(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { + fn check_item_post(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) { if let Some(id) = self.derived_item { if item.hir_id == id { self.derived_item = None; diff --git a/clippy_lints/src/needless_borrowed_ref.rs b/clippy_lints/src/needless_borrowed_ref.rs index e56489c6d434..85184fdea477 100644 --- a/clippy_lints/src/needless_borrowed_ref.rs +++ b/clippy_lints/src/needless_borrowed_ref.rs @@ -52,8 +52,8 @@ declare_clippy_lint! { declare_lint_pass!(NeedlessBorrowedRef => [NEEDLESS_BORROWED_REFERENCE]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef { - fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat<'_>) { +impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowedRef { + fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { if pat.span.from_expansion() { // OK, simple enough, lints doesn't check in macro. return; diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 6954f0cc683f..bc70c675ad69 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -64,11 +64,11 @@ macro_rules! need { }; } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { +impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { #[allow(clippy::too_many_lines)] fn check_fn( &mut self, - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, diff --git a/clippy_lints/src/needless_update.rs b/clippy_lints/src/needless_update.rs index 9b556dbb8540..6ec73041604e 100644 --- a/clippy_lints/src/needless_update.rs +++ b/clippy_lints/src/needless_update.rs @@ -44,8 +44,8 @@ declare_clippy_lint! { declare_lint_pass!(NeedlessUpdate => [NEEDLESS_UPDATE]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessUpdate { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for NeedlessUpdate { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Struct(_, ref fields, Some(ref base)) = expr.kind { let ty = cx.tables().expr_ty(expr); if let ty::Adt(def, _) = ty.kind { diff --git a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs index 0f56daa3659e..1be766d8e8dc 100644 --- a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs @@ -45,8 +45,8 @@ declare_clippy_lint! { declare_lint_pass!(NoNegCompOpForPartialOrd => [NEG_CMP_OP_ON_PARTIAL_ORD]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoNegCompOpForPartialOrd { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for NoNegCompOpForPartialOrd { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if !in_external_macro(cx.sess(), expr.span); diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index a9ce01b67b09..1346145da327 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -26,8 +26,8 @@ declare_clippy_lint! { declare_lint_pass!(NegMultiply => [NEG_MULTIPLY]); #[allow(clippy::match_same_arms)] -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for NegMultiply { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::Binary(ref op, ref left, ref right) = e.kind { if BinOpKind::Mul == op.node { match (&left.kind, &right.kind) { @@ -41,7 +41,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply { } } -fn check_mul(cx: &LateContext<'_, '_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_>) { +fn check_mul(cx: &LateContext<'_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_>) { if_chain! { if let ExprKind::Lit(ref l) = lit.kind; if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables().expr_ty_opt(lit)); diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 42200385932b..2597f5f6f17e 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -56,9 +56,9 @@ pub struct NewWithoutDefault { impl_lint_pass!(NewWithoutDefault => [NEW_WITHOUT_DEFAULT]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { +impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { #[allow(clippy::too_many_lines)] - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'_>) { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { if let hir::ItemKind::Impl { of_trait: None, items, .. } = item.kind diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 5fdc656580f2..95283dae7147 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -42,7 +42,7 @@ declare_clippy_lint! { "outer expressions with no effect" } -fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { +fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { if expr.span.from_expansion() { return false; } @@ -87,8 +87,8 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { declare_lint_pass!(NoEffect => [NO_EFFECT, UNNECESSARY_OPERATION]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoEffect { - fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) { +impl<'tcx> LateLintPass<'tcx> for NoEffect { + fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { if let StmtKind::Semi(ref expr) = stmt.kind { if has_no_effect(cx, expr) { span_lint(cx, NO_EFFECT, stmt.span, "statement with no effect"); @@ -119,7 +119,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoEffect { } } -fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option>> { +fn reduce_expression<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option>> { if expr.span.from_expansion() { return None; } diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 21d7a7439f25..c11a2ff9ee07 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -109,7 +109,7 @@ impl Source { } } -fn verify_ty_bound<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, source: Source) { +fn verify_ty_bound<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, source: Source) { if ty.is_freeze(cx.tcx.at(DUMMY_SP), cx.param_env) || is_copy(cx, ty) { // An `UnsafeCell` is `!Copy`, and an `UnsafeCell` is also the only type which // is `!Freeze`, thus if our type is `Copy` we can be sure it must be `Freeze` @@ -141,15 +141,15 @@ fn verify_ty_bound<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, source: S declare_lint_pass!(NonCopyConst => [DECLARE_INTERIOR_MUTABLE_CONST, BORROW_INTERIOR_MUTABLE_CONST]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for NonCopyConst { + fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx Item<'_>) { if let ItemKind::Const(hir_ty, ..) = &it.kind { let ty = hir_ty_to_ty(cx.tcx, hir_ty); verify_ty_bound(cx, ty, Source::Item { item: it.span }); } } - fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, trait_item: &'tcx TraitItem<'_>) { + fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx TraitItem<'_>) { if let TraitItemKind::Const(hir_ty, ..) = &trait_item.kind { let ty = hir_ty_to_ty(cx.tcx, hir_ty); verify_ty_bound( @@ -163,7 +163,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst { } } - fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx ImplItem<'_>) { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { if let ImplItemKind::Const(hir_ty, ..) = &impl_item.kind { let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id); let item = cx.tcx.hir().expect_item(item_hir_id); @@ -182,7 +182,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst { } } - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Path(qpath) = &expr.kind { // Only lint if we use the const item inside a function. if in_constant(cx, expr.hir_id) { diff --git a/clippy_lints/src/open_options.rs b/clippy_lints/src/open_options.rs index 2467a14cea12..2b83efa84f64 100644 --- a/clippy_lints/src/open_options.rs +++ b/clippy_lints/src/open_options.rs @@ -27,8 +27,8 @@ declare_clippy_lint! { declare_lint_pass!(OpenOptions => [NONSENSICAL_OPEN_OPTIONS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OpenOptions { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for OpenOptions { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::MethodCall(ref path, _, ref arguments, _) = e.kind { let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&arguments[0])); if path.ident.name == sym!(open) && match_type(cx, obj_ty, &paths::OPEN_OPTIONS) { @@ -56,7 +56,7 @@ enum OpenOption { Append, } -fn get_open_options(cx: &LateContext<'_, '_>, argument: &Expr<'_>, options: &mut Vec<(OpenOption, Argument)>) { +fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec<(OpenOption, Argument)>) { if let ExprKind::MethodCall(ref path, _, ref arguments, _) = argument.kind { let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&arguments[0])); @@ -107,7 +107,7 @@ fn get_open_options(cx: &LateContext<'_, '_>, argument: &Expr<'_>, options: &mut } } -fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument)], span: Span) { +fn check_open_options(cx: &LateContext<'_>, options: &[(OpenOption, Argument)], span: Span) { let (mut create, mut append, mut truncate, mut read, mut write) = (false, false, false, false, false); let (mut create_arg, mut append_arg, mut truncate_arg, mut read_arg, mut write_arg) = (false, false, false, false, false); diff --git a/clippy_lints/src/overflow_check_conditional.rs b/clippy_lints/src/overflow_check_conditional.rs index 5984b09120d0..0850f88df44f 100644 --- a/clippy_lints/src/overflow_check_conditional.rs +++ b/clippy_lints/src/overflow_check_conditional.rs @@ -25,9 +25,9 @@ declare_clippy_lint! { declare_lint_pass!(OverflowCheckConditional => [OVERFLOW_CHECK_CONDITIONAL]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional { +impl<'tcx> LateLintPass<'tcx> for OverflowCheckConditional { // a + b < a, a > a + b, a < a - b, a - b > a - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { let eq = |l, r| SpanlessEq::new(cx).eq_path_segment(l, r); if_chain! { if let ExprKind::Binary(ref op, ref first, ref second) = expr.kind; diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs index 2cd9200ddb25..10f4694640ee 100644 --- a/clippy_lints/src/panic_unimplemented.rs +++ b/clippy_lints/src/panic_unimplemented.rs @@ -91,8 +91,8 @@ declare_clippy_lint! { declare_lint_pass!(PanicUnimplemented => [PANIC_PARAMS, UNIMPLEMENTED, UNREACHABLE, TODO, PANIC]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Block(ref block, _) = expr.kind; if let Some(ref ex) = block.expr; @@ -136,7 +136,7 @@ fn get_outer_span(expr: &Expr<'_>) -> Span { } } -fn match_panic(params: &[Expr<'_>], expr: &Expr<'_>, cx: &LateContext<'_, '_>) { +fn match_panic(params: &[Expr<'_>], expr: &Expr<'_>, cx: &LateContext<'_>) { if_chain! { if let ExprKind::Lit(ref lit) = params[0].kind; if is_direct_expn_of(expr.span, "panic").is_some(); diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index 1445df41c452..19d355e64ca8 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -30,8 +30,8 @@ declare_clippy_lint! { declare_lint_pass!(PartialEqNeImpl => [PARTIALEQ_NE_IMPL]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PartialEqNeImpl { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if_chain! { if let ItemKind::Impl{ of_trait: Some(ref trait_ref), items: impl_items, .. } = item.kind; if !is_automatically_derived(&*item.attrs); diff --git a/clippy_lints/src/path_buf_push_overwrite.rs b/clippy_lints/src/path_buf_push_overwrite.rs index f26a5258782a..48e609542793 100644 --- a/clippy_lints/src/path_buf_push_overwrite.rs +++ b/clippy_lints/src/path_buf_push_overwrite.rs @@ -40,8 +40,8 @@ declare_clippy_lint! { declare_lint_pass!(PathBufPushOverwrite => [PATH_BUF_PUSH_OVERWRITE]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathBufPushOverwrite { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for PathBufPushOverwrite { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; if path.ident.name == sym!(push); diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index c77b44e0c99c..7b6bd69ffca5 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -108,14 +108,14 @@ declare_clippy_lint! { declare_lint_pass!(Ptr => [PTR_ARG, CMP_NULL, MUT_FROM_REF]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for Ptr { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if let ItemKind::Fn(ref sig, _, body_id) = item.kind { check_fn(cx, &sig.decl, item.hir_id, Some(body_id)); } } - fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem<'_>) { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { if let ImplItemKind::Fn(ref sig, body_id) = item.kind { let parent_item = cx.tcx.hir().get_parent_item(item.hir_id); if let Some(Node::Item(it)) = cx.tcx.hir().find(parent_item) { @@ -127,7 +127,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr { } } - fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem<'_>) { + fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { if let TraitItemKind::Fn(ref sig, ref trait_method) = item.kind { let body_id = if let TraitFn::Provided(b) = *trait_method { Some(b) @@ -138,7 +138,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr { } } - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Binary(ref op, ref l, ref r) = expr.kind { if (op.node == BinOpKind::Eq || op.node == BinOpKind::Ne) && (is_null_path(l) || is_null_path(r)) { span_lint( @@ -153,7 +153,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr { } #[allow(clippy::too_many_lines)] -fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_id: Option) { +fn check_fn(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_id: Option) { let fn_def_id = cx.tcx.hir().local_def_id(fn_id); let sig = cx.tcx.fn_sig(fn_def_id); let fn_ty = sig.skip_binder(); diff --git a/clippy_lints/src/ptr_offset_with_cast.rs b/clippy_lints/src/ptr_offset_with_cast.rs index b35a7e64bff2..61e186a4b465 100644 --- a/clippy_lints/src/ptr_offset_with_cast.rs +++ b/clippy_lints/src/ptr_offset_with_cast.rs @@ -43,8 +43,8 @@ declare_clippy_lint! { declare_lint_pass!(PtrOffsetWithCast => [PTR_OFFSET_WITH_CAST]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for PtrOffsetWithCast { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { // Check if the expressions is a ptr.offset or ptr.wrapping_offset method call let (receiver_expr, arg_expr, method) = match expr_as_ptr_offset_call(cx, expr) { Some(call_arg) => call_arg, @@ -75,7 +75,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast { } // If the given expression is a cast from a usize, return the lhs of the cast -fn expr_as_cast_from_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { +fn expr_as_cast_from_usize<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { if let ExprKind::Cast(ref cast_lhs_expr, _) = expr.kind { if is_expr_ty_usize(cx, &cast_lhs_expr) { return Some(cast_lhs_expr); @@ -86,8 +86,8 @@ fn expr_as_cast_from_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Exp // If the given expression is a ptr::offset or ptr::wrapping_offset method call, return the // receiver, the arg of the method call, and the method. -fn expr_as_ptr_offset_call<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn expr_as_ptr_offset_call<'tcx>( + cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, ) -> Option<(&'tcx Expr<'tcx>, &'tcx Expr<'tcx>, Method)> { if let ExprKind::MethodCall(ref path_segment, _, ref args, _) = expr.kind { @@ -104,17 +104,17 @@ fn expr_as_ptr_offset_call<'a, 'tcx>( } // Is the type of the expression a usize? -fn is_expr_ty_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool { +fn is_expr_ty_usize<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool { cx.tables().expr_ty(expr) == cx.tcx.types.usize } // Is the type of the expression a raw pointer? -fn is_expr_ty_raw_ptr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool { +fn is_expr_ty_raw_ptr<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool { cx.tables().expr_ty(expr).is_unsafe_ptr() } -fn build_suggestion<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn build_suggestion<'tcx>( + cx: &LateContext<'tcx>, method: Method, receiver_expr: &Expr<'_>, cast_lhs_expr: &Expr<'_>, diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index a77e104bb8f0..cc9c2f196079 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -47,7 +47,7 @@ impl QuestionMark { /// ``` /// /// If it matches, it will suggest to use the question mark operator instead - fn check_is_none_and_early_return_none(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { + fn check_is_none_and_early_return_none(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let Some((if_expr, body, else_)) = higher::if_block(&expr); if let ExprKind::MethodCall(segment, _, args, _) = &if_expr.kind; @@ -93,7 +93,7 @@ impl QuestionMark { } } - fn check_if_let_some_and_early_return_none(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { + fn check_if_let_some_and_early_return_none(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Match(subject, arms, source) = &expr.kind; if *source == MatchSource::IfLetDesugar { contains_else_clause: true }; @@ -134,19 +134,19 @@ impl QuestionMark { } } - fn moves_by_default(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool { + fn moves_by_default(cx: &LateContext<'_>, expression: &Expr<'_>) -> bool { let expr_ty = cx.tables().expr_ty(expression); !expr_ty.is_copy_modulo_regions(cx.tcx.at(expression.span), cx.param_env) } - fn is_option(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool { + fn is_option(cx: &LateContext<'_>, expression: &Expr<'_>) -> bool { let expr_ty = cx.tables().expr_ty(expression); is_type_diagnostic_item(cx, expr_ty, sym!(option_type)) } - fn expression_returns_none(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool { + fn expression_returns_none(cx: &LateContext<'_>, expression: &Expr<'_>) -> bool { match expression.kind { ExprKind::Block(ref block, _) => { if let Some(return_expression) = Self::return_expression(block) { @@ -196,8 +196,8 @@ impl QuestionMark { } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for QuestionMark { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for QuestionMark { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { Self::check_is_none_and_early_return_none(cx, expr); Self::check_if_let_some_and_early_return_none(cx, expr); } diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 43ef236a9242..c164ec9aaf17 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -127,8 +127,8 @@ declare_lint_pass!(Ranges => [ REVERSED_EMPTY_RANGES, ]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for Ranges { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind { let name = path.ident.as_str(); if name == "zip" && args.len() == 2 { @@ -166,7 +166,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges { } // exclusive range plus one: `x..(y+1)` -fn check_exclusive_range_plus_one(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { +fn check_exclusive_range_plus_one(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let Some(higher::Range { start, @@ -215,7 +215,7 @@ fn check_exclusive_range_plus_one(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { } // inclusive range minus one: `x..=(y-1)` -fn check_inclusive_range_minus_one(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { +fn check_inclusive_range_minus_one(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let Some(higher::Range { start, end: Some(end), limits: RangeLimits::Closed }) = higher::range(cx, expr); if let Some(y) = y_minus_one(cx, end); @@ -240,8 +240,8 @@ fn check_inclusive_range_minus_one(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { } } -fn check_reversed_empty_range(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { - fn inside_indexing_expr(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { +fn check_reversed_empty_range(cx: &LateContext<'_>, expr: &Expr<'_>) { + fn inside_indexing_expr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { matches!( get_parent_expr(cx, expr), Some(Expr { @@ -251,7 +251,7 @@ fn check_reversed_empty_range(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { ) } - fn is_for_loop_arg(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { + fn is_for_loop_arg(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let mut cur_expr = expr; while let Some(parent_expr) = get_parent_expr(cx, cur_expr) { match higher::for_loop(parent_expr) { @@ -320,7 +320,7 @@ fn check_reversed_empty_range(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { } } -fn y_plus_one<'t>(cx: &LateContext<'_, '_>, expr: &'t Expr<'_>) -> Option<&'t Expr<'t>> { +fn y_plus_one<'t>(cx: &LateContext<'_>, expr: &'t Expr<'_>) -> Option<&'t Expr<'t>> { match expr.kind { ExprKind::Binary( Spanned { @@ -341,7 +341,7 @@ fn y_plus_one<'t>(cx: &LateContext<'_, '_>, expr: &'t Expr<'_>) -> Option<&'t Ex } } -fn y_minus_one<'t>(cx: &LateContext<'_, '_>, expr: &'t Expr<'_>) -> Option<&'t Expr<'t>> { +fn y_minus_one<'t>(cx: &LateContext<'_>, expr: &'t Expr<'_>) -> Option<&'t Expr<'t>> { match expr.kind { ExprKind::Binary( Spanned { diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index d563eb886ae7..fda7480194dc 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -66,11 +66,11 @@ declare_clippy_lint! { declare_lint_pass!(RedundantClone => [REDUNDANT_CLONE]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone { +impl<'tcx> LateLintPass<'tcx> for RedundantClone { #[allow(clippy::too_many_lines)] fn check_fn( &mut self, - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, _: FnKind<'tcx>, _: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, @@ -273,7 +273,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone { /// If `kind` is `y = func(x: &T)` where `T: !Copy`, returns `(DefId of func, x, T, y)`. fn is_call_with_ref_arg<'tcx>( - cx: &LateContext<'_, 'tcx>, + cx: &LateContext<'tcx>, mir: &'tcx mir::Body<'tcx>, kind: &'tcx mir::TerminatorKind<'tcx>, ) -> Option<(def_id::DefId, mir::Local, Ty<'tcx>, mir::Local)> { @@ -297,7 +297,7 @@ type CannotMoveOut = bool; /// Finds the first `to = (&)from`, and returns /// ``Some((from, whether `from` cannot be moved out))``. fn find_stmt_assigns_to<'tcx>( - cx: &LateContext<'_, 'tcx>, + cx: &LateContext<'tcx>, mir: &mir::Body<'tcx>, to_local: mir::Local, by_ref: bool, @@ -331,7 +331,7 @@ fn find_stmt_assigns_to<'tcx>( /// /// Also reports whether given `place` cannot be moved out. fn base_local_and_movability<'tcx>( - cx: &LateContext<'_, 'tcx>, + cx: &LateContext<'tcx>, mir: &mir::Body<'tcx>, place: mir::Place<'tcx>, ) -> Option<(mir::Local, CannotMoveOut)> { @@ -459,11 +459,11 @@ impl BottomValue for MaybeStorageLive { struct PossibleBorrowerVisitor<'a, 'tcx> { possible_borrower: TransitiveRelation, body: &'a mir::Body<'tcx>, - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, } impl<'a, 'tcx> PossibleBorrowerVisitor<'a, 'tcx> { - fn new(cx: &'a LateContext<'a, 'tcx>, body: &'a mir::Body<'tcx>) -> Self { + fn new(cx: &'a LateContext<'tcx>, body: &'a mir::Body<'tcx>) -> Self { Self { possible_borrower: TransitiveRelation::default(), cx, @@ -473,7 +473,7 @@ impl<'a, 'tcx> PossibleBorrowerVisitor<'a, 'tcx> { fn into_map( self, - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, maybe_live: ResultsCursor<'tcx, 'tcx, MaybeStorageLive>, ) -> PossibleBorrowerMap<'a, 'tcx> { let mut map = FxHashMap::default(); diff --git a/clippy_lints/src/redundant_pattern_matching.rs b/clippy_lints/src/redundant_pattern_matching.rs index 3c528a295b04..d8d16efb978a 100644 --- a/clippy_lints/src/redundant_pattern_matching.rs +++ b/clippy_lints/src/redundant_pattern_matching.rs @@ -47,8 +47,8 @@ declare_clippy_lint! { declare_lint_pass!(RedundantPatternMatching => [REDUNDANT_PATTERN_MATCHING]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantPatternMatching { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for RedundantPatternMatching { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Match(op, arms, ref match_source) = &expr.kind { match match_source { MatchSource::Normal => find_sugg_for_match(cx, expr, op, arms), @@ -60,14 +60,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantPatternMatching { } } -fn find_sugg_for_if_let<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn find_sugg_for_if_let<'tcx>( + cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op: &Expr<'_>, arms: &[Arm<'_>], keyword: &'static str, ) { - fn find_suggestion(cx: &LateContext<'_, '_>, hir_id: HirId, path: &QPath<'_>) -> Option<&'static str> { + fn find_suggestion(cx: &LateContext<'_>, hir_id: HirId, path: &QPath<'_>) -> Option<&'static str> { if match_qpath(path, &paths::RESULT_OK) && can_suggest(cx, hir_id, sym!(result_type), "is_ok") { return Some("is_ok()"); } @@ -138,7 +138,7 @@ fn find_sugg_for_if_let<'a, 'tcx>( ); } -fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, op: &Expr<'_>, arms: &[Arm<'_>]) { +fn find_sugg_for_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op: &Expr<'_>, arms: &[Arm<'_>]) { if arms.len() == 2 { let node_pair = (&arms[0].pat.kind, &arms[1].pat.kind); @@ -237,7 +237,7 @@ fn find_good_method_for_match<'a>( } } -fn can_suggest(cx: &LateContext<'_, '_>, hir_id: HirId, diag_item: Symbol, name: &str) -> bool { +fn can_suggest(cx: &LateContext<'_>, hir_id: HirId, diag_item: Symbol, name: &str) -> bool { if !in_constant(cx, hir_id) { return true; } diff --git a/clippy_lints/src/redundant_pub_crate.rs b/clippy_lints/src/redundant_pub_crate.rs index 6fc07f91660e..acd9047ace61 100644 --- a/clippy_lints/src/redundant_pub_crate.rs +++ b/clippy_lints/src/redundant_pub_crate.rs @@ -39,8 +39,8 @@ pub struct RedundantPubCrate { impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantPubCrate { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'tcx>) { +impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { if let VisibilityKind::Crate { .. } = item.vis.node { if !cx.access_levels.is_exported(item.hir_id) { if let Some(false) = self.is_exported.last() { @@ -70,7 +70,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantPubCrate { } } - fn check_item_post(&mut self, _cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'tcx>) { + fn check_item_post(&mut self, _cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { if let ItemKind::Mod { .. } = item.kind { self.is_exported.pop().expect("unbalanced check_item/check_item_post"); } diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index 0b56ef02a844..b67abad6ccb8 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -73,12 +73,12 @@ pub struct Regex { impl_lint_pass!(Regex => [INVALID_REGEX, REGEX_MACRO, TRIVIAL_REGEX]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex { - fn check_crate(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx Crate<'_>) { +impl<'tcx> LateLintPass<'tcx> for Regex { + fn check_crate(&mut self, _: &LateContext<'tcx>, _: &'tcx Crate<'_>) { self.spans.clear(); } - fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>) { + fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'_>) { if_chain! { if self.last.is_none(); if let Some(ref expr) = block.expr; @@ -100,13 +100,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex { } } - fn check_block_post(&mut self, _: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>) { + fn check_block_post(&mut self, _: &LateContext<'tcx>, block: &'tcx Block<'_>) { if self.last.map_or(false, |id| block.hir_id == id) { self.last = None; } } - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Call(ref fun, ref args) = expr.kind; if let ExprKind::Path(ref qpath) = fun.kind; @@ -139,7 +139,7 @@ fn str_span(base: Span, c: regex_syntax::ast::Span, offset: u16) -> Span { Span::new(start, end, base.ctxt()) } -fn const_str<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) -> Option { +fn const_str<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> Option { constant(cx, cx.tables(), e).and_then(|(c, _)| match c { Constant::Str(s) => Some(s), _ => None, @@ -185,7 +185,7 @@ fn is_trivial_regex(s: ®ex_syntax::hir::Hir) -> Option<&'static str> { } } -fn check_set<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, utf8: bool) { +fn check_set<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, utf8: bool) { if_chain! { if let ExprKind::AddrOf(BorrowKind::Ref, _, ref expr) = expr.kind; if let ExprKind::Array(exprs) = expr.kind; @@ -197,7 +197,7 @@ fn check_set<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, utf8: b } } -fn check_regex<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, utf8: bool) { +fn check_regex<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, utf8: bool) { let mut parser = regex_syntax::ParserBuilder::new() .unicode(utf8) .allow_invalid_utf8(!utf8) diff --git a/clippy_lints/src/serde_api.rs b/clippy_lints/src/serde_api.rs index 6820d1620bd1..339a7cf3bf5d 100644 --- a/clippy_lints/src/serde_api.rs +++ b/clippy_lints/src/serde_api.rs @@ -20,8 +20,8 @@ declare_clippy_lint! { declare_lint_pass!(SerdeAPI => [SERDE_API_MISUSE]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SerdeAPI { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for SerdeAPI { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if let ItemKind::Impl { of_trait: Some(ref trait_ref), items, diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 4780249bcb8e..7da47ee4ff94 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -96,10 +96,10 @@ declare_clippy_lint! { declare_lint_pass!(Shadow => [SHADOW_SAME, SHADOW_REUSE, SHADOW_UNRELATED]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Shadow { +impl<'tcx> LateLintPass<'tcx> for Shadow { fn check_fn( &mut self, - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, _: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, @@ -113,7 +113,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Shadow { } } -fn check_fn<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>) { +fn check_fn<'tcx>(cx: &LateContext<'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>) { let mut bindings = Vec::with_capacity(decl.inputs.len()); for arg in iter_input_pats(decl, body) { if let PatKind::Binding(.., ident, _) = arg.pat.kind { @@ -123,7 +123,7 @@ fn check_fn<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl<'_>, body: check_expr(cx, &body.value, &mut bindings); } -fn check_block<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>, bindings: &mut Vec<(Name, Span)>) { +fn check_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'_>, bindings: &mut Vec<(Name, Span)>) { let len = bindings.len(); for stmt in block.stmts { match stmt.kind { @@ -138,7 +138,7 @@ fn check_block<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>, bin bindings.truncate(len); } -fn check_local<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, local: &'tcx Local<'_>, bindings: &mut Vec<(Name, Span)>) { +fn check_local<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>, bindings: &mut Vec<(Name, Span)>) { if in_external_macro(cx.sess(), local.span) { return; } @@ -163,7 +163,7 @@ fn check_local<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, local: &'tcx Local<'_>, bin } } -fn is_binding(cx: &LateContext<'_, '_>, pat_id: HirId) -> bool { +fn is_binding(cx: &LateContext<'_>, pat_id: HirId) -> bool { let var_ty = cx.tables().node_type_opt(pat_id); if let Some(var_ty) = var_ty { match var_ty.kind { @@ -175,8 +175,8 @@ fn is_binding(cx: &LateContext<'_, '_>, pat_id: HirId) -> bool { } } -fn check_pat<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn check_pat<'tcx>( + cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, init: Option<&'tcx Expr<'_>>, span: Span, @@ -259,8 +259,8 @@ fn check_pat<'a, 'tcx>( } } -fn lint_shadow<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn lint_shadow<'tcx>( + cx: &LateContext<'tcx>, name: Name, span: Span, pattern_span: Span, @@ -326,7 +326,7 @@ fn lint_shadow<'a, 'tcx>( } } -fn check_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, bindings: &mut Vec<(Name, Span)>) { +fn check_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, bindings: &mut Vec<(Name, Span)>) { if in_external_macro(cx.sess(), expr.span) { return; } @@ -362,7 +362,7 @@ fn check_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, bindin } } -fn check_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: &'tcx Ty<'_>, bindings: &mut Vec<(Name, Span)>) { +fn check_ty<'tcx>(cx: &LateContext<'tcx>, ty: &'tcx Ty<'_>, bindings: &mut Vec<(Name, Span)>) { match ty.kind { TyKind::Slice(ref sty) => check_ty(cx, sty, bindings), TyKind::Array(ref fty, ref anon_const) => { diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 44c9cc19cfb4..96f6881556cf 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -65,8 +65,8 @@ enum InitializationType<'tcx> { Resize(&'tcx Expr<'tcx>), } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SlowVectorInit { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for SlowVectorInit { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { // Matches initialization on reassignements. For example: `vec = Vec::with_capacity(100)` if_chain! { if let ExprKind::Assign(ref left, ref right, _) = expr.kind; @@ -90,7 +90,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SlowVectorInit { } } - fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) { + fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { // Matches statements which initializes vectors. For example: `let mut vec = Vec::with_capacity(10)` if_chain! { if let StmtKind::Local(ref local) = stmt.kind; @@ -130,7 +130,7 @@ impl SlowVectorInit { } /// Search initialization for the given vector - fn search_initialization<'tcx>(cx: &LateContext<'_, 'tcx>, vec_alloc: VecAllocation<'tcx>, parent_node: HirId) { + fn search_initialization<'tcx>(cx: &LateContext<'tcx>, vec_alloc: VecAllocation<'tcx>, parent_node: HirId) { let enclosing_body = get_enclosing_block(cx, parent_node); if enclosing_body.is_none() { @@ -152,7 +152,7 @@ impl SlowVectorInit { } fn lint_initialization<'tcx>( - cx: &LateContext<'_, 'tcx>, + cx: &LateContext<'tcx>, initialization: &InitializationType<'tcx>, vec_alloc: &VecAllocation<'_>, ) { @@ -168,7 +168,7 @@ impl SlowVectorInit { } fn emit_lint<'tcx>( - cx: &LateContext<'_, 'tcx>, + cx: &LateContext<'tcx>, slow_fill: &Expr<'_>, vec_alloc: &VecAllocation<'_>, msg: &str, @@ -190,7 +190,7 @@ impl SlowVectorInit { /// `VectorInitializationVisitor` searches for unsafe or slow vector initializations for the given /// vector. struct VectorInitializationVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, /// Contains the information. vec_alloc: VecAllocation<'tcx>, diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index ef66850358e5..89aa6a4edd62 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -86,8 +86,8 @@ declare_clippy_lint! { declare_lint_pass!(StringAdd => [STRING_ADD, STRING_ADD_ASSIGN]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringAdd { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for StringAdd { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if in_external_macro(cx.sess(), e.span) { return; } @@ -133,11 +133,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringAdd { } } -fn is_string(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool { +fn is_string(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { is_type_diagnostic_item(cx, walk_ptrs_ty(cx.tables().expr_ty(e)), sym!(string_type)) } -fn is_add(cx: &LateContext<'_, '_>, src: &Expr<'_>, target: &Expr<'_>) -> bool { +fn is_add(cx: &LateContext<'_>, src: &Expr<'_>, target: &Expr<'_>) -> bool { match src.kind { ExprKind::Binary( Spanned { @@ -158,8 +158,8 @@ const MAX_LENGTH_BYTE_STRING_LIT: usize = 32; declare_lint_pass!(StringLitAsBytes => [STRING_LIT_AS_BYTES]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { use crate::utils::{snippet, snippet_with_applicability}; use rustc_ast::ast::LitKind; diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index cf71c3144a2e..6d1d083fa8d4 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -52,8 +52,8 @@ declare_clippy_lint! { declare_lint_pass!(SuspiciousImpl => [SUSPICIOUS_ARITHMETIC_IMPL, SUSPICIOUS_OP_ASSIGN_IMPL]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if let hir::ExprKind::Binary(binop, _, _) | hir::ExprKind::AssignOp(binop, ..) = expr.kind { match binop.node { hir::BinOpKind::Eq @@ -147,7 +147,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl { } fn check_binop( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, expr: &hir::Expr<'_>, binop: hir::BinOpKind, traits: &[&'static str], diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index 7fdc872c01f5..eb7d35839206 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -65,15 +65,15 @@ declare_clippy_lint! { declare_lint_pass!(Swap => [MANUAL_SWAP, ALMOST_SWAPPED]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Swap { - fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>) { +impl<'tcx> LateLintPass<'tcx> for Swap { + fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'_>) { check_manual_swap(cx, block); check_suspicious_swap(cx, block); } } /// Implementation of the `MANUAL_SWAP` lint. -fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block<'_>) { +fn check_manual_swap(cx: &LateContext<'_>, block: &Block<'_>) { for w in block.stmts.windows(3) { if_chain! { // let t = foo(); @@ -190,7 +190,7 @@ enum Slice<'a> { } /// Checks if both expressions are index operations into "slice-like" types. -fn check_for_slice<'a>(cx: &LateContext<'_, '_>, lhs1: &'a Expr<'_>, lhs2: &'a Expr<'_>) -> Slice<'a> { +fn check_for_slice<'a>(cx: &LateContext<'_>, lhs1: &'a Expr<'_>, lhs2: &'a Expr<'_>) -> Slice<'a> { if let ExprKind::Index(ref lhs1, ref idx1) = lhs1.kind { if let ExprKind::Index(ref lhs2, ref idx2) = lhs2.kind { if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs1, lhs2) { @@ -213,7 +213,7 @@ fn check_for_slice<'a>(cx: &LateContext<'_, '_>, lhs1: &'a Expr<'_>, lhs2: &'a E } /// Implementation of the `ALMOST_SWAPPED` lint. -fn check_suspicious_swap(cx: &LateContext<'_, '_>, block: &Block<'_>) { +fn check_suspicious_swap(cx: &LateContext<'_>, block: &Block<'_>) { for w in block.stmts.windows(2) { if_chain! { if let StmtKind::Semi(ref first) = w[0].kind; diff --git a/clippy_lints/src/temporary_assignment.rs b/clippy_lints/src/temporary_assignment.rs index bc282e4bd987..509bbfd27c1a 100644 --- a/clippy_lints/src/temporary_assignment.rs +++ b/clippy_lints/src/temporary_assignment.rs @@ -22,7 +22,7 @@ declare_clippy_lint! { "assignments to temporaries" } -fn is_temporary(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { +fn is_temporary(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { match &expr.kind { ExprKind::Struct(..) | ExprKind::Tup(..) => true, ExprKind::Path(qpath) => { @@ -38,8 +38,8 @@ fn is_temporary(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { declare_lint_pass!(TemporaryAssignment => [TEMPORARY_ASSIGNMENT]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TemporaryAssignment { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for TemporaryAssignment { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Assign(target, ..) = &expr.kind { let mut base = target; while let ExprKind::Field(f, _) | ExprKind::Index(f, _) = &base.kind { diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs index 4f943eeaeebc..4157103a574e 100644 --- a/clippy_lints/src/to_digit_is_some.rs +++ b/clippy_lints/src/to_digit_is_some.rs @@ -31,8 +31,8 @@ declare_clippy_lint! { declare_lint_pass!(ToDigitIsSome => [TO_DIGIT_IS_SOME]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ToDigitIsSome { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for ToDigitIsSome { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if_chain! { if let hir::ExprKind::MethodCall(is_some_path, _, is_some_args, _) = &expr.kind; if is_some_path.ident.name.as_str() == "is_some"; diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index c3e4eb05eb4e..9eb2079c3ca2 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -31,8 +31,8 @@ declare_clippy_lint! { impl_lint_pass!(TraitBounds => [TYPE_REPETITION_IN_BOUNDS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TraitBounds { - fn check_generics(&mut self, cx: &LateContext<'a, 'tcx>, gen: &'tcx Generics<'_>) { +impl<'tcx> LateLintPass<'tcx> for TraitBounds { + fn check_generics(&mut self, cx: &LateContext<'tcx>, gen: &'tcx Generics<'_>) { if in_macro(gen.span) { return; } diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 6ef4b8dcfc19..5f76d5c46efb 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -293,9 +293,9 @@ static COLLECTIONS: &[&[&str]] = &[ &paths::HASHSET, &paths::HASHMAP, ]; -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { +impl<'tcx> LateLintPass<'tcx> for Transmute { #[allow(clippy::similar_names, clippy::too_many_lines)] - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Call(ref path_expr, ref args) = e.kind; if let ExprKind::Path(ref qpath) = path_expr.kind; @@ -613,7 +613,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { /// the type's `ToString` implementation. In weird cases it could lead to types /// with invalid `'_` /// lifetime, but it should be rare. -fn get_type_snippet(cx: &LateContext<'_, '_>, path: &QPath<'_>, to_ref_ty: Ty<'_>) -> String { +fn get_type_snippet(cx: &LateContext<'_>, path: &QPath<'_>, to_ref_ty: Ty<'_>) -> String { let seg = last_path_segment(path); if_chain! { if let Some(ref params) = seg.args; @@ -633,7 +633,7 @@ fn get_type_snippet(cx: &LateContext<'_, '_>, path: &QPath<'_>, to_ref_ty: Ty<'_ // check if the component types of the transmuted collection and the result have different ABI, // size or alignment -fn is_layout_incompatible<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, from: Ty<'tcx>, to: Ty<'tcx>) -> bool { +fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<'tcx>) -> bool { let empty_param_env = ty::ParamEnv::empty(); // check if `from` and `to` are normalizable to avoid ICE (#4968) if !(is_normalizable(cx, empty_param_env, from) && is_normalizable(cx, empty_param_env, to)) { diff --git a/clippy_lints/src/transmuting_null.rs b/clippy_lints/src/transmuting_null.rs index 3351488a45c4..2f03c6db42d9 100644 --- a/clippy_lints/src/transmuting_null.rs +++ b/clippy_lints/src/transmuting_null.rs @@ -29,8 +29,8 @@ declare_lint_pass!(TransmutingNull => [TRANSMUTING_NULL]); const LINT_MSG: &str = "transmuting a known null pointer into a reference."; -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for TransmutingNull { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if in_external_macro(cx.sess(), expr.span) { return; } diff --git a/clippy_lints/src/trivially_copy_pass_by_ref.rs b/clippy_lints/src/trivially_copy_pass_by_ref.rs index 146ac4b09d5a..6a2b05e3e6df 100644 --- a/clippy_lints/src/trivially_copy_pass_by_ref.rs +++ b/clippy_lints/src/trivially_copy_pass_by_ref.rs @@ -73,7 +73,7 @@ impl<'tcx> TriviallyCopyPassByRef { Self { limit } } - fn check_poly_fn(&mut self, cx: &LateContext<'_, 'tcx>, hir_id: HirId, decl: &FnDecl<'_>, span: Option) { + fn check_poly_fn(&mut self, cx: &LateContext<'tcx>, hir_id: HirId, decl: &FnDecl<'_>, span: Option) { let fn_def_id = cx.tcx.hir().local_def_id(hir_id); let fn_sig = cx.tcx.fn_sig(fn_def_id); @@ -125,8 +125,8 @@ impl<'tcx> TriviallyCopyPassByRef { impl_lint_pass!(TriviallyCopyPassByRef => [TRIVIALLY_COPY_PASS_BY_REF]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef { - fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem<'_>) { +impl<'tcx> LateLintPass<'tcx> for TriviallyCopyPassByRef { + fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { if item.span.from_expansion() { return; } @@ -138,7 +138,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef { fn check_fn( &mut self, - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, _body: &'tcx Body<'_>, diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs index e129dd84d15a..208d248faa57 100644 --- a/clippy_lints/src/try_err.rs +++ b/clippy_lints/src/try_err.rs @@ -43,8 +43,8 @@ declare_clippy_lint! { declare_lint_pass!(TryErr => [TRY_ERR]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TryErr { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for TryErr { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { // Looks for a structure like this: // match ::std::ops::Try::into_result(Err(5)) { // ::std::result::Result::Err(err) => @@ -97,7 +97,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TryErr { // In order to determine whether to suggest `.into()` or not, we need to find the error type the // function returns. To do that, we look for the From::from call (see tree above), and capture // its output type. -fn find_err_return_type<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx ExprKind<'_>) -> Option> { +fn find_err_return_type<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx ExprKind<'_>) -> Option> { if let ExprKind::Match(_, ref arms, MatchSource::TryDesugar) = expr { arms.iter().find_map(|ty| find_err_return_type_arm(cx, ty)) } else { @@ -106,7 +106,7 @@ fn find_err_return_type<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx ExprKi } // Check for From::from in one of the match arms. -fn find_err_return_type_arm<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arm: &'tcx Arm<'_>) -> Option> { +fn find_err_return_type_arm<'tcx>(cx: &LateContext<'tcx>, arm: &'tcx Arm<'_>) -> Option> { if_chain! { if let ExprKind::Ret(Some(ref err_ret)) = arm.body.kind; if let ExprKind::Call(ref from_error_path, ref from_error_args) = err_ret.kind; diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 74db29e4f1d5..b1345f0de5e4 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -218,16 +218,8 @@ pub struct Types { impl_lint_pass!(Types => [BOX_VEC, VEC_BOX, OPTION_OPTION, LINKEDLIST, BORROWED_BOX, REDUNDANT_ALLOCATION]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Types { - fn check_fn( - &mut self, - cx: &LateContext<'_, '_>, - _: FnKind<'_>, - decl: &FnDecl<'_>, - _: &Body<'_>, - _: Span, - id: HirId, - ) { +impl<'tcx> LateLintPass<'tcx> for Types { + fn check_fn(&mut self, cx: &LateContext<'_>, _: FnKind<'_>, decl: &FnDecl<'_>, _: &Body<'_>, _: Span, id: HirId) { // Skip trait implementations; see issue #605. if let Some(hir::Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_item(id)) { if let ItemKind::Impl { of_trait: Some(_), .. } = item.kind { @@ -238,11 +230,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Types { self.check_fn_decl(cx, decl); } - fn check_struct_field(&mut self, cx: &LateContext<'_, '_>, field: &hir::StructField<'_>) { + fn check_struct_field(&mut self, cx: &LateContext<'_>, field: &hir::StructField<'_>) { self.check_ty(cx, &field.ty, false); } - fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, item: &TraitItem<'_>) { + fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &TraitItem<'_>) { match item.kind { TraitItemKind::Const(ref ty, _) | TraitItemKind::Type(_, Some(ref ty)) => self.check_ty(cx, ty, false), TraitItemKind::Fn(ref sig, _) => self.check_fn_decl(cx, &sig.decl), @@ -250,7 +242,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Types { } } - fn check_local(&mut self, cx: &LateContext<'_, '_>, local: &Local<'_>) { + fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) { if let Some(ref ty) = local.ty { self.check_ty(cx, ty, true); } @@ -258,7 +250,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Types { } /// Checks if `qpath` has last segment with type parameter matching `path` -fn match_type_parameter(cx: &LateContext<'_, '_>, qpath: &QPath<'_>, path: &[&str]) -> Option { +fn match_type_parameter(cx: &LateContext<'_>, qpath: &QPath<'_>, path: &[&str]) -> Option { let last = last_path_segment(qpath); if_chain! { if let Some(ref params) = last.args; @@ -277,7 +269,7 @@ fn match_type_parameter(cx: &LateContext<'_, '_>, qpath: &QPath<'_>, path: &[&st None } -fn match_borrows_parameter(_cx: &LateContext<'_, '_>, qpath: &QPath<'_>) -> Option { +fn match_borrows_parameter(_cx: &LateContext<'_>, qpath: &QPath<'_>) -> Option { let last = last_path_segment(qpath); if_chain! { if let Some(ref params) = last.args; @@ -299,7 +291,7 @@ impl Types { Self { vec_box_size_threshold } } - fn check_fn_decl(&mut self, cx: &LateContext<'_, '_>, decl: &FnDecl<'_>) { + fn check_fn_decl(&mut self, cx: &LateContext<'_>, decl: &FnDecl<'_>) { for input in decl.inputs { self.check_ty(cx, input, false); } @@ -315,7 +307,7 @@ impl Types { /// The parameter `is_local` distinguishes the context of the type; types from /// local bindings should only be checked for the `BORROWED_BOX` lint. #[allow(clippy::too_many_lines)] - fn check_ty(&mut self, cx: &LateContext<'_, '_>, hir_ty: &hir::Ty<'_>, is_local: bool) { + fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, is_local: bool) { if hir_ty.span.from_expansion() { return; } @@ -501,7 +493,7 @@ impl Types { fn check_ty_rptr( &mut self, - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, is_local: bool, lt: &Lifetime, @@ -600,8 +592,8 @@ declare_clippy_lint! { declare_lint_pass!(LetUnitValue => [LET_UNIT_VALUE]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnitValue { - fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) { +impl<'tcx> LateLintPass<'tcx> for LetUnitValue { + fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { if let StmtKind::Local(ref local) = stmt.kind { if is_unit(cx.tables().pat_ty(&local.pat)) { if in_external_macro(cx.sess(), stmt.span) || local.pat.span.from_expansion() { @@ -681,8 +673,8 @@ declare_clippy_lint! { declare_lint_pass!(UnitCmp => [UNIT_CMP]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitCmp { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) { +impl<'tcx> LateLintPass<'tcx> for UnitCmp { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if expr.span.from_expansion() { if let Some(callee) = expr.span.source_callee() { if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind { @@ -754,8 +746,8 @@ declare_clippy_lint! { declare_lint_pass!(UnitArg => [UNIT_ARG]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for UnitArg { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if expr.span.from_expansion() { return; } @@ -802,7 +794,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg { } } -fn lint_unit_args(cx: &LateContext<'_, '_>, expr: &Expr<'_>, args_to_recover: &[&Expr<'_>]) { +fn lint_unit_args(cx: &LateContext<'_>, expr: &Expr<'_>, args_to_recover: &[&Expr<'_>]) { let mut applicability = Applicability::MachineApplicable; let (singular, plural) = if args_to_recover.len() > 1 { ("", "s") @@ -1168,7 +1160,7 @@ fn is_isize_or_usize(typ: Ty<'_>) -> bool { } } -fn span_precision_loss_lint(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to_f64: bool) { +fn span_precision_loss_lint(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to_f64: bool) { let mantissa_nbits = if cast_to_f64 { 52 } else { 23 }; let arch_dependent = is_isize_or_usize(cast_from) && cast_to_f64; let arch_dependent_str = "on targets with 64-bit wide pointers "; @@ -1204,7 +1196,7 @@ fn should_strip_parens(op: &Expr<'_>, snip: &str) -> bool { false } -fn span_lossless_lint(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { +fn span_lossless_lint(cx: &LateContext<'_>, expr: &Expr<'_>, op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { // Do not suggest using From in consts/statics until it is valid to do so (see #2267). if in_constant(cx, expr.hir_id) { return; @@ -1244,7 +1236,7 @@ enum ArchSuffix { None, } -fn check_loss_of_sign(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { +fn check_loss_of_sign(cx: &LateContext<'_>, expr: &Expr<'_>, op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { if !cast_from.is_signed() || cast_to.is_signed() { return; } @@ -1291,7 +1283,7 @@ fn check_loss_of_sign(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>, ); } -fn check_truncation_and_wrapping(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { +fn check_truncation_and_wrapping(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { let arch_64_suffix = " on targets with 64-bit wide pointers"; let arch_32_suffix = " on targets with 32-bit wide pointers"; let cast_unsigned_to_signed = !cast_from.is_signed() && cast_to.is_signed(); @@ -1362,7 +1354,7 @@ fn check_truncation_and_wrapping(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cast } } -fn check_lossless(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { +fn check_lossless(cx: &LateContext<'_>, expr: &Expr<'_>, op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { let cast_signed_to_unsigned = cast_from.is_signed() && !cast_to.is_signed(); let from_nbits = int_ty_to_nbits(cast_from, cx.tcx); let to_nbits = int_ty_to_nbits(cast_to, cx.tcx); @@ -1386,7 +1378,7 @@ declare_lint_pass!(Casts => [ // Check if the given type is either `core::ffi::c_void` or // one of the platform specific `libc::::c_void` of libc. -fn is_c_void(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> bool { +fn is_c_void(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { if let ty::Adt(adt, _) = ty.kind { let names = cx.get_def_path(adt.did); @@ -1410,8 +1402,8 @@ fn fp_ty_mantissa_nbits(typ: Ty<'_>) -> u32 { } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for Casts { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if expr.span.from_expansion() { return; } @@ -1467,7 +1459,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts { } fn lint_numeric_casts<'tcx>( - cx: &LateContext<'_, 'tcx>, + cx: &LateContext<'tcx>, expr: &Expr<'tcx>, cast_expr: &Expr<'_>, cast_from: Ty<'tcx>, @@ -1528,7 +1520,7 @@ fn lint_numeric_casts<'tcx>( } } -fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>) { +fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>) { if_chain! { if let ty::RawPtr(from_ptr_ty) = &cast_from.kind; if let ty::RawPtr(to_ptr_ty) = &cast_to.kind; @@ -1557,7 +1549,7 @@ fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>, ca } fn lint_fn_to_numeric_cast( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_from: Ty<'_>, @@ -1637,10 +1629,10 @@ impl TypeComplexity { impl_lint_pass!(TypeComplexity => [TYPE_COMPLEXITY]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexity { +impl<'tcx> LateLintPass<'tcx> for TypeComplexity { fn check_fn( &mut self, - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, _: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, _: &'tcx Body<'_>, @@ -1650,12 +1642,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexity { self.check_fndecl(cx, decl); } - fn check_struct_field(&mut self, cx: &LateContext<'a, 'tcx>, field: &'tcx hir::StructField<'_>) { + fn check_struct_field(&mut self, cx: &LateContext<'tcx>, field: &'tcx hir::StructField<'_>) { // enum variants are also struct fields now self.check_type(cx, &field.ty); } - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { match item.kind { ItemKind::Static(ref ty, _, _) | ItemKind::Const(ref ty, _) => self.check_type(cx, ty), // functions, enums, structs, impls and traits are covered @@ -1663,7 +1655,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexity { } } - fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem<'_>) { + fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { match item.kind { TraitItemKind::Const(ref ty, _) | TraitItemKind::Type(_, Some(ref ty)) => self.check_type(cx, ty), TraitItemKind::Fn(FnSig { ref decl, .. }, TraitFn::Required(_)) => self.check_fndecl(cx, decl), @@ -1672,7 +1664,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexity { } } - fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem<'_>) { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { match item.kind { ImplItemKind::Const(ref ty, _) | ImplItemKind::TyAlias(ref ty) => self.check_type(cx, ty), // methods are covered by check_fn @@ -1680,15 +1672,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexity { } } - fn check_local(&mut self, cx: &LateContext<'a, 'tcx>, local: &'tcx Local<'_>) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'_>) { if let Some(ref ty) = local.ty { self.check_type(cx, ty); } } } -impl<'a, 'tcx> TypeComplexity { - fn check_fndecl(&self, cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl<'_>) { +impl<'tcx> TypeComplexity { + fn check_fndecl(&self, cx: &LateContext<'tcx>, decl: &'tcx FnDecl<'_>) { for arg in decl.inputs { self.check_type(cx, arg); } @@ -1697,7 +1689,7 @@ impl<'a, 'tcx> TypeComplexity { } } - fn check_type(&self, cx: &LateContext<'_, '_>, ty: &hir::Ty<'_>) { + fn check_type(&self, cx: &LateContext<'_>, ty: &hir::Ty<'_>) { if ty.span.from_expansion() { return; } @@ -1797,8 +1789,8 @@ declare_clippy_lint! { declare_lint_pass!(CharLitAsU8 => [CHAR_LIT_AS_U8]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CharLitAsU8 { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for CharLitAsU8 { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if !expr.span.from_expansion(); if let ExprKind::Cast(e, _) = &expr.kind; @@ -1878,7 +1870,7 @@ enum AbsurdComparisonResult { InequalityImpossible, } -fn is_cast_between_fixed_and_target<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) -> bool { +fn is_cast_between_fixed_and_target<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool { if let ExprKind::Cast(ref cast_exp, _) = expr.kind { let precast_ty = cx.tables().expr_ty(cast_exp); let cast_ty = cx.tables().expr_ty(expr); @@ -1889,8 +1881,8 @@ fn is_cast_between_fixed_and_target<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: false } -fn detect_absurd_comparison<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn detect_absurd_comparison<'tcx>( + cx: &LateContext<'tcx>, op: BinOpKind, lhs: &'tcx Expr<'_>, rhs: &'tcx Expr<'_>, @@ -1936,7 +1928,7 @@ fn detect_absurd_comparison<'a, 'tcx>( }) } -fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option> { +fn detect_extreme_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option> { use crate::types::ExtremeType::{Maximum, Minimum}; let ty = cx.tables().expr_ty(expr); @@ -1960,8 +1952,8 @@ fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_ Some(ExtremeExpr { which, expr }) } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AbsurdExtremeComparisons { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for AbsurdExtremeComparisons { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { use crate::types::AbsurdComparisonResult::{AlwaysFalse, AlwaysTrue, InequalityImpossible}; use crate::types::ExtremeType::{Maximum, Minimum}; @@ -2069,7 +2061,7 @@ impl Ord for FullInt { } } -fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'_>) -> Option<(FullInt, FullInt)> { +fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_>, expr: &'a Expr<'_>) -> Option<(FullInt, FullInt)> { if let ExprKind::Cast(ref cast_exp, _) = expr.kind { let pre_cast_ty = cx.tables().expr_ty(cast_exp); let cast_ty = cx.tables().expr_ty(expr); @@ -2101,7 +2093,7 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'_>) } } -fn node_as_const_fullint<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option { +fn node_as_const_fullint<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option { let val = constant(cx, cx.tables(), expr)?.0; if let Constant::Int(const_int) = val { match cx.tables().expr_ty(expr).kind { @@ -2114,7 +2106,7 @@ fn node_as_const_fullint<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr< } } -fn err_upcast_comparison(cx: &LateContext<'_, '_>, span: Span, expr: &Expr<'_>, always: bool) { +fn err_upcast_comparison(cx: &LateContext<'_>, span: Span, expr: &Expr<'_>, always: bool) { if let ExprKind::Cast(ref cast_val, _) = expr.kind { span_lint( cx, @@ -2129,8 +2121,8 @@ fn err_upcast_comparison(cx: &LateContext<'_, '_>, span: Span, expr: &Expr<'_>, } } -fn upcast_comparison_bounds_err<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn upcast_comparison_bounds_err<'tcx>( + cx: &LateContext<'tcx>, span: Span, rel: comparisons::Rel, lhs_bounds: Option<(FullInt, FullInt)>, @@ -2187,8 +2179,8 @@ fn upcast_comparison_bounds_err<'a, 'tcx>( } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidUpcastComparisons { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for InvalidUpcastComparisons { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Binary(ref cmp, ref lhs, ref rhs) = expr.kind { let normalized = comparisons::normalize_comparison(cmp.node, lhs, rhs); let (rel, normalized_lhs, normalized_rhs) = if let Some(val) = normalized { @@ -2243,13 +2235,13 @@ declare_clippy_lint! { declare_lint_pass!(ImplicitHasher => [IMPLICIT_HASHER]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitHasher { +impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { #[allow(clippy::cast_possible_truncation, clippy::too_many_lines)] - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { use rustc_span::BytePos; - fn suggestion<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, + fn suggestion<'tcx>( + cx: &LateContext<'tcx>, diag: &mut DiagnosticBuilder<'_>, generics_span: Span, generics_suggestion_span: Span, @@ -2393,7 +2385,7 @@ enum ImplicitHasherType<'tcx> { impl<'tcx> ImplicitHasherType<'tcx> { /// Checks that `ty` is a target type without a `BuildHasher`. - fn new<'a>(cx: &LateContext<'a, 'tcx>, hir_ty: &hir::Ty<'_>) -> Option { + fn new(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'_>) -> Option { if let TyKind::Path(QPath::Resolved(None, ref path)) = hir_ty.kind { let params: Vec<_> = path .segments @@ -2461,12 +2453,12 @@ impl<'tcx> ImplicitHasherType<'tcx> { } struct ImplicitHasherTypeVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, found: Vec>, } impl<'a, 'tcx> ImplicitHasherTypeVisitor<'a, 'tcx> { - fn new(cx: &'a LateContext<'a, 'tcx>) -> Self { + fn new(cx: &'a LateContext<'tcx>) -> Self { Self { cx, found: vec![] } } } @@ -2489,14 +2481,14 @@ impl<'a, 'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> { /// Looks for default-hasher-dependent constructors like `HashMap::new`. struct ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, maybe_typeck_tables: Option<&'tcx TypeckTables<'tcx>>, target: &'b ImplicitHasherType<'tcx>, suggestions: BTreeMap, } impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { - fn new(cx: &'a LateContext<'a, 'tcx>, target: &'b ImplicitHasherType<'tcx>) -> Self { + fn new(cx: &'a LateContext<'tcx>, target: &'b ImplicitHasherType<'tcx>) -> Self { Self { cx, maybe_typeck_tables: cx.maybe_typeck_tables(), @@ -2599,8 +2591,8 @@ declare_clippy_lint! { declare_lint_pass!(RefToMut => [CAST_REF_TO_MUT]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RefToMut { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for RefToMut { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Unary(UnOp::UnDeref, e) = &expr.kind; if let ExprKind::Cast(e, t) = &e.kind; diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index d073c197656c..d8c57f0e7ae7 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -65,8 +65,8 @@ declare_clippy_lint! { declare_lint_pass!(Unicode => [ZERO_WIDTH_SPACE, NON_ASCII_LITERAL, UNICODE_NOT_NFC]); -impl LateLintPass<'_, '_> for Unicode { - fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &'_ Expr<'_>) { +impl LateLintPass<'_> for Unicode { + fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) { if let ExprKind::Lit(ref lit) = expr.kind { if let LitKind::Str(_, _) = lit.node { check_str(cx, lit.span, expr.hir_id) @@ -89,7 +89,7 @@ fn escape>(s: T) -> String { result } -fn check_str(cx: &LateContext<'_, '_>, span: Span, id: HirId) { +fn check_str(cx: &LateContext<'_>, span: Span, id: HirId) { let string = snippet(cx, span, ""); if string.contains('\u{200B}') { span_lint_and_sugg( diff --git a/clippy_lints/src/unnamed_address.rs b/clippy_lints/src/unnamed_address.rs index 0efbf68dcd84..b9aa202b328f 100644 --- a/clippy_lints/src/unnamed_address.rs +++ b/clippy_lints/src/unnamed_address.rs @@ -55,8 +55,8 @@ declare_clippy_lint! { declare_lint_pass!(UnnamedAddress => [FN_ADDRESS_COMPARISONS, VTABLE_ADDRESS_COMPARISONS]); -impl LateLintPass<'_, '_> for UnnamedAddress { - fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) { +impl LateLintPass<'_> for UnnamedAddress { + fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { fn is_comparison(binop: BinOpKind) -> bool { match binop { BinOpKind::Eq | BinOpKind::Lt | BinOpKind::Le | BinOpKind::Ne | BinOpKind::Ge | BinOpKind::Gt => true, @@ -64,14 +64,14 @@ impl LateLintPass<'_, '_> for UnnamedAddress { } } - fn is_trait_ptr(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { + fn is_trait_ptr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { match cx.tables().expr_ty_adjusted(expr).kind { ty::RawPtr(ty::TypeAndMut { ty, .. }) => ty.is_trait(), _ => false, } } - fn is_fn_def(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { + fn is_fn_def(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { if let ty::FnDef(..) = cx.tables().expr_ty(expr).kind { true } else { diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index bb68e50b3319..d940776817ca 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -67,7 +67,7 @@ struct SortByKeyDetection { /// Detect if the two expressions are mirrored (identical, except one /// contains a and the other replaces it with b) fn mirrored_exprs( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, a_expr: &Expr<'_>, a_ident: &Ident, b_expr: &Expr<'_>, @@ -171,7 +171,7 @@ fn mirrored_exprs( } } -fn detect_lint(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option { +fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { if_chain! { if let ExprKind::MethodCall(name_ident, _, args, _) = &expr.kind; if let name = name_ident.ident.name.to_ident_string(); @@ -225,8 +225,8 @@ fn detect_lint(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option } } -impl LateLintPass<'_, '_> for UnnecessarySortBy { - fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) { +impl LateLintPass<'_> for UnnecessarySortBy { + fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { match detect_lint(cx, expr) { Some(LintTrigger::SortByKey(trigger)) => utils::span_lint_and_sugg( cx, diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index 5f4b5fd9dd91..1580f657d771 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -32,8 +32,8 @@ declare_clippy_lint! { declare_lint_pass!(UnusedIoAmount => [UNUSED_IO_AMOUNT]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedIoAmount { - fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt<'_>) { +impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount { + fn check_stmt(&mut self, cx: &LateContext<'_>, s: &hir::Stmt<'_>) { let expr = match s.kind { hir::StmtKind::Semi(ref expr) | hir::StmtKind::Expr(ref expr) => &**expr, _ => return, @@ -64,7 +64,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedIoAmount { } } -fn check_method_call(cx: &LateContext<'_, '_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) { +fn check_method_call(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) { if let hir::ExprKind::MethodCall(ref path, _, _, _) = call.kind { let symbol = &*path.ident.as_str(); let read_trait = match_trait_method(cx, call, &paths::IO_READ); diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index 3d5e2f9fd215..da7517125c13 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -39,8 +39,8 @@ declare_clippy_lint! { declare_lint_pass!(UnusedSelf => [UNUSED_SELF]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedSelf { - fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &ImplItem<'_>) { +impl<'tcx> LateLintPass<'tcx> for UnusedSelf { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &ImplItem<'_>) { if impl_item.span.from_expansion() { return; } @@ -80,7 +80,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedSelf { } struct UnusedSelfVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, uses_self: bool, self_hir_id: &'a HirId, } diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index be55982f9055..56ff62eca033 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -68,7 +68,7 @@ declare_clippy_lint! { /// Visitor that keeps track of which variables are unwrappable. struct UnwrappableVariablesVisitor<'a, 'tcx> { unwrappables: Vec>, - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, } /// Contains information about whether a variable can be unwrapped. #[derive(Copy, Clone, Debug)] @@ -85,17 +85,17 @@ struct UnwrapInfo<'tcx> { /// Collects the information about unwrappable variables from an if condition /// The `invert` argument tells us whether the condition is negated. -fn collect_unwrap_info<'a, 'tcx>( - cx: &'a LateContext<'a, 'tcx>, +fn collect_unwrap_info<'tcx>( + cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, branch: &'tcx Expr<'_>, invert: bool, ) -> Vec> { - fn is_relevant_option_call(cx: &LateContext<'_, '_>, ty: Ty<'_>, method_name: &str) -> bool { + fn is_relevant_option_call(cx: &LateContext<'_>, ty: Ty<'_>, method_name: &str) -> bool { is_type_diagnostic_item(cx, ty, sym!(option_type)) && ["is_some", "is_none"].contains(&method_name) } - fn is_relevant_result_call(cx: &LateContext<'_, '_>, ty: Ty<'_>, method_name: &str) -> bool { + fn is_relevant_result_call(cx: &LateContext<'_>, ty: Ty<'_>, method_name: &str) -> bool { is_type_diagnostic_item(cx, ty, sym!(result_type)) && ["is_ok", "is_err"].contains(&method_name) } @@ -209,10 +209,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> { declare_lint_pass!(Unwrap => [PANICKING_UNWRAP, UNNECESSARY_UNWRAP]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Unwrap { +impl<'tcx> LateLintPass<'tcx> for Unwrap { fn check_fn( &mut self, - cx: &LateContext<'a, 'tcx>, + cx: &LateContext<'tcx>, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index f8e1aff33e77..f85db1e2006e 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -57,7 +57,7 @@ declare_lint_pass!(UseSelf => [USE_SELF]); const SEGMENTS_MSG: &str = "segments should be composed of at least 1 element"; -fn span_use_self_lint(cx: &LateContext<'_, '_>, path: &Path<'_>, last_segment: Option<&PathSegment<'_>>) { +fn span_use_self_lint(cx: &LateContext<'_>, path: &Path<'_>, last_segment: Option<&PathSegment<'_>>) { let last_segment = last_segment.unwrap_or_else(|| path.segments.last().expect(SEGMENTS_MSG)); // Path segments only include actual path, no methods or fields. @@ -83,7 +83,7 @@ fn span_use_self_lint(cx: &LateContext<'_, '_>, path: &Path<'_>, last_segment: O // FIXME: always use this (more correct) visitor, not just in method signatures. struct SemanticUseSelfVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, self_ty: Ty<'tcx>, } @@ -110,8 +110,8 @@ impl<'a, 'tcx> Visitor<'tcx> for SemanticUseSelfVisitor<'a, 'tcx> { } } -fn check_trait_method_impl_decl<'a, 'tcx>( - cx: &'a LateContext<'a, 'tcx>, +fn check_trait_method_impl_decl<'tcx>( + cx: &LateContext<'tcx>, impl_item: &ImplItem<'_>, impl_decl: &'tcx FnDecl<'_>, impl_trait_ref: ty::TraitRef<'tcx>, @@ -157,8 +157,8 @@ fn check_trait_method_impl_decl<'a, 'tcx>( } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for UseSelf { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if in_external_macro(cx.sess(), item.span) { return; } @@ -211,7 +211,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf { struct UseSelfVisitor<'a, 'tcx> { item_path: &'a Path<'a>, - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, } impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> { diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index ad5ecc0c0267..69c0b092520d 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -40,8 +40,8 @@ pub struct UselessConversion { impl_lint_pass!(UselessConversion => [USELESS_CONVERSION]); #[allow(clippy::too_many_lines)] -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for UselessConversion { + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if e.span.from_expansion() { return; } @@ -173,7 +173,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion { } } - fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { + fn check_expr_post(&mut self, _: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if Some(&e.hir_id) == self.try_desugar_arm.last() { self.try_desugar_arm.pop(); } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 910b665ccb75..128fa87a1621 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -64,8 +64,8 @@ fn done() { println!("}}"); } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for Author { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { if !has_attr(cx.sess(), &item.attrs) { return; } @@ -74,7 +74,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author { done(); } - fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::ImplItem<'_>) { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { if !has_attr(cx.sess(), &item.attrs) { return; } @@ -83,7 +83,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author { done(); } - fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem<'_>) { + fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { if !has_attr(cx.sess(), &item.attrs) { return; } @@ -92,7 +92,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author { done(); } - fn check_variant(&mut self, cx: &LateContext<'a, 'tcx>, var: &'tcx hir::Variant<'_>) { + fn check_variant(&mut self, cx: &LateContext<'tcx>, var: &'tcx hir::Variant<'_>) { if !has_attr(cx.sess(), &var.attrs) { return; } @@ -102,7 +102,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author { done(); } - fn check_struct_field(&mut self, cx: &LateContext<'a, 'tcx>, field: &'tcx hir::StructField<'_>) { + fn check_struct_field(&mut self, cx: &LateContext<'tcx>, field: &'tcx hir::StructField<'_>) { if !has_attr(cx.sess(), &field.attrs) { return; } @@ -111,7 +111,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author { done(); } - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if !has_attr(cx.sess(), &expr.attrs) { return; } @@ -120,7 +120,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author { done(); } - fn check_arm(&mut self, cx: &LateContext<'a, 'tcx>, arm: &'tcx hir::Arm<'_>) { + fn check_arm(&mut self, cx: &LateContext<'tcx>, arm: &'tcx hir::Arm<'_>) { if !has_attr(cx.sess(), &arm.attrs) { return; } @@ -129,7 +129,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author { done(); } - fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx hir::Stmt<'_>) { + fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx hir::Stmt<'_>) { if !has_attr(cx.sess(), stmt.kind.attrs()) { return; } @@ -138,7 +138,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author { done(); } - fn check_foreign_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::ForeignItem<'_>) { + fn check_foreign_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ForeignItem<'_>) { if !has_attr(cx.sess(), &item.attrs) { return; } diff --git a/clippy_lints/src/utils/diagnostics.rs b/clippy_lints/src/utils/diagnostics.rs index f6d87c8532e4..e4e65b5f4d42 100644 --- a/clippy_lints/src/utils/diagnostics.rs +++ b/clippy_lints/src/utils/diagnostics.rs @@ -138,7 +138,7 @@ where }); } -pub fn span_lint_hir(cx: &LateContext<'_, '_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) { +pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) { cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| { let mut diag = diag.build(msg); docs_link(&mut diag, lint); @@ -147,7 +147,7 @@ pub fn span_lint_hir(cx: &LateContext<'_, '_>, lint: &'static Lint, hir_id: HirI } pub fn span_lint_hir_and_then( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, diff --git a/clippy_lints/src/utils/higher.rs b/clippy_lints/src/utils/higher.rs index 9502d85e6ee9..eb7ac2447e49 100644 --- a/clippy_lints/src/utils/higher.rs +++ b/clippy_lints/src/utils/higher.rs @@ -47,7 +47,7 @@ pub struct Range<'a> { } /// Higher a `hir` range to something similar to `ast::ExprKind::Range`. -pub fn range<'a, 'b, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'b hir::Expr<'_>) -> Option> { +pub fn range<'a, 'tcx>(cx: &LateContext<'tcx>, expr: &'a hir::Expr<'_>) -> Option> { /// Finds the field named `name` in the field. Always return `Some` for /// convenience. fn get_field<'c>(name: &str, fields: &'c [hir::Field<'_>]) -> Option<&'c hir::Expr<'c>> { @@ -257,7 +257,7 @@ pub enum VecArgs<'a> { /// Returns the arguments of the `vec!` macro if this expression was expanded /// from `vec!`. -pub fn vec_macro<'e>(cx: &LateContext<'_, '_>, expr: &'e hir::Expr<'_>) -> Option> { +pub fn vec_macro<'e>(cx: &LateContext<'_>, expr: &'e hir::Expr<'_>) -> Option> { if_chain! { if let hir::ExprKind::Call(ref fun, ref args) = expr.kind; if let hir::ExprKind::Path(ref qpath) = fun.kind; diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index bf1017d76ec6..ae58f0a1521e 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -21,7 +21,7 @@ use std::hash::Hash; /// Note that some expressions kinds are not considered but could be added. pub struct SpanlessEq<'a, 'tcx> { /// Context used to evaluate constant expressions. - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, maybe_typeck_tables: Option<&'tcx TypeckTables<'tcx>>, /// If is true, never consider as equal expressions containing function /// calls. @@ -29,7 +29,7 @@ pub struct SpanlessEq<'a, 'tcx> { } impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { - pub fn new(cx: &'a LateContext<'a, 'tcx>) -> Self { + pub fn new(cx: &'a LateContext<'tcx>) -> Self { Self { cx, maybe_typeck_tables: cx.maybe_typeck_tables(), @@ -347,13 +347,13 @@ pub fn over(left: &[X], right: &[X], mut eq_fn: impl FnMut(&X, &X) -> bool) - /// All expressions kind are hashed, but some might have a weaker hash. pub struct SpanlessHash<'a, 'tcx> { /// Context used to evaluate constant expressions. - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, maybe_typeck_tables: Option<&'tcx TypeckTables<'tcx>>, s: StableHasher, } impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { - pub fn new(cx: &'a LateContext<'a, 'tcx>) -> Self { + pub fn new(cx: &'a LateContext<'tcx>) -> Self { Self { cx, maybe_typeck_tables: cx.maybe_typeck_tables(), diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 3f5659c3d8c0..fbd103323e31 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -31,15 +31,15 @@ declare_clippy_lint! { declare_lint_pass!(DeepCodeInspector => [DEEP_CODE_INSPECTION]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DeepCodeInspector { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { if !has_attr(cx.sess(), &item.attrs) { return; } print_item(cx, item); } - fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::ImplItem<'_>) { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { if !has_attr(cx.sess(), &item.attrs) { return; } @@ -65,14 +65,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DeepCodeInspector { hir::ImplItemKind::TyAlias(_) => println!("associated type"), } } - // fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx + // fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx // hir::TraitItem) { // if !has_attr(&item.attrs) { // return; // } // } // - // fn check_variant(&mut self, cx: &LateContext<'a, 'tcx>, var: &'tcx + // fn check_variant(&mut self, cx: &LateContext<'tcx>, var: &'tcx // hir::Variant, _: // &hir::Generics) { // if !has_attr(&var.node.attrs) { @@ -80,7 +80,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DeepCodeInspector { // } // } // - // fn check_struct_field(&mut self, cx: &LateContext<'a, 'tcx>, field: &'tcx + // fn check_struct_field(&mut self, cx: &LateContext<'tcx>, field: &'tcx // hir::StructField) { // if !has_attr(&field.attrs) { // return; @@ -88,14 +88,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DeepCodeInspector { // } // - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if !has_attr(cx.sess(), &expr.attrs) { return; } print_expr(cx, expr, 0); } - fn check_arm(&mut self, cx: &LateContext<'a, 'tcx>, arm: &'tcx hir::Arm<'_>) { + fn check_arm(&mut self, cx: &LateContext<'tcx>, arm: &'tcx hir::Arm<'_>) { if !has_attr(cx.sess(), &arm.attrs) { return; } @@ -108,7 +108,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DeepCodeInspector { print_expr(cx, &arm.body, 1); } - fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx hir::Stmt<'_>) { + fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx hir::Stmt<'_>) { if !has_attr(cx.sess(), stmt.kind.attrs()) { return; } @@ -126,7 +126,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DeepCodeInspector { hir::StmtKind::Expr(ref e) | hir::StmtKind::Semi(ref e) => print_expr(cx, e, 0), } } - // fn check_foreign_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx + // fn check_foreign_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx // hir::ForeignItem) { // if !has_attr(&item.attrs) { // return; @@ -141,7 +141,7 @@ fn has_attr(sess: &Session, attrs: &[Attribute]) -> bool { #[allow(clippy::similar_names)] #[allow(clippy::too_many_lines)] -fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, indent: usize) { +fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { let ind = " ".repeat(indent); println!("{}+", ind); println!("{}ty: {}", ind, cx.tables().expr_ty(expr)); @@ -348,7 +348,7 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, indent: usize) { } } -fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item<'_>) { +fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) { let did = cx.tcx.hir().local_def_id(item.hir_id); println!("item `{}`", item.ident.name); match item.vis.node { @@ -425,7 +425,7 @@ fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item<'_>) { #[allow(clippy::similar_names)] #[allow(clippy::too_many_lines)] -fn print_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>, indent: usize) { +fn print_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, indent: usize) { let ind = " ".repeat(indent); println!("{}+", ind); match pat.kind { @@ -537,7 +537,7 @@ fn print_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>, indent: usize) { } } -fn print_guard(cx: &LateContext<'_, '_>, guard: &hir::Guard<'_>, indent: usize) { +fn print_guard(cx: &LateContext<'_>, guard: &hir::Guard<'_>, indent: usize) { let ind = " ".repeat(indent); println!("{}+", ind); match guard { diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index ca947e9241f0..38cb764adde7 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -251,8 +251,8 @@ pub struct LintWithoutLintPass { impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass { - fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { +impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if !run_lints(cx, &[DEFAULT_LINT], item.hir_id) { return; } @@ -310,7 +310,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass { } } - fn check_crate_post(&mut self, cx: &LateContext<'a, 'tcx>, _: &'tcx Crate<'_>) { + fn check_crate_post(&mut self, cx: &LateContext<'tcx>, _: &'tcx Crate<'_>) { if !run_lints(cx, &[LINT_WITHOUT_LINT_PASS], CRATE_HIR_ID) { return; } @@ -337,7 +337,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass { } } -fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty<'_>) -> bool { +fn is_lint_ref_type<'tcx>(cx: &LateContext<'tcx>, ty: &Ty<'_>) -> bool { if let TyKind::Rptr( _, MutTy { @@ -358,7 +358,7 @@ fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty<'_>) -> bool { struct LintCollector<'a, 'tcx> { output: &'a mut FxHashSet, - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, } impl<'a, 'tcx> Visitor<'tcx> for LintCollector<'a, 'tcx> { @@ -395,8 +395,8 @@ impl CompilerLintFunctions { impl_lint_pass!(CompilerLintFunctions => [COMPILER_LINT_FUNCTIONS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CompilerLintFunctions { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for CompilerLintFunctions { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if !run_lints(cx, &[COMPILER_LINT_FUNCTIONS], expr.hir_id) { return; } @@ -424,8 +424,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CompilerLintFunctions { declare_lint_pass!(OuterExpnDataPass => [OUTER_EXPN_EXPN_DATA]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnDataPass { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for OuterExpnDataPass { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if !run_lints(cx, &[OUTER_EXPN_EXPN_DATA], expr.hir_id) { return; } @@ -474,8 +474,8 @@ fn is_trigger_fn(fn_kind: FnKind<'_>) -> bool { declare_lint_pass!(CollapsibleCalls => [COLLAPSIBLE_SPAN_LINT_CALLS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CollapsibleCalls { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if !run_lints(cx, &[COLLAPSIBLE_SPAN_LINT_CALLS], expr.hir_id) { return; } @@ -529,10 +529,7 @@ struct AndThenSnippets<'a> { msg: Cow<'a, str>, } -fn get_and_then_snippets<'a, 'hir>( - cx: &LateContext<'_, '_>, - and_then_snippets: &'hir [Expr<'hir>], -) -> AndThenSnippets<'a> { +fn get_and_then_snippets<'a, 'hir>(cx: &LateContext<'_>, and_then_snippets: &'hir [Expr<'hir>]) -> AndThenSnippets<'a> { let cx_snippet = snippet(cx, and_then_snippets[0].span, "cx"); let lint_snippet = snippet(cx, and_then_snippets[1].span, ".."); let span_snippet = snippet(cx, and_then_snippets[2].span, "span"); @@ -553,7 +550,7 @@ struct SpanSuggestionSnippets<'a> { } fn span_suggestion_snippets<'a, 'hir>( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, span_call_args: &'hir [Expr<'hir>], ) -> SpanSuggestionSnippets<'a> { let help_snippet = snippet(cx, span_call_args[2].span, r#""...""#); @@ -568,7 +565,7 @@ fn span_suggestion_snippets<'a, 'hir>( } fn suggest_suggestion( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, expr: &Expr<'_>, and_then_snippets: &AndThenSnippets<'_>, span_suggestion_snippets: &SpanSuggestionSnippets<'_>, @@ -594,7 +591,7 @@ fn suggest_suggestion( } fn suggest_help( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, expr: &Expr<'_>, and_then_snippets: &AndThenSnippets<'_>, help: &str, @@ -626,7 +623,7 @@ fn suggest_help( } fn suggest_note( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, expr: &Expr<'_>, and_then_snippets: &AndThenSnippets<'_>, note: &str, diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 8be9ba2c3c24..99ba7d64331c 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -70,7 +70,7 @@ pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool { /// // Do something /// } /// ``` -pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool { +pub fn in_constant(cx: &LateContext<'_>, id: HirId) -> bool { let parent_id = cx.tcx.hir().get_parent_item(id); match cx.tcx.hir().get(parent_id) { Node::Item(&Item { @@ -134,7 +134,7 @@ pub fn is_wild<'tcx>(pat: &impl std::ops::Deref>) -> bool { } /// Checks if type is struct, enum or union type with the given def path. -pub fn match_type(cx: &LateContext<'_, '_>, ty: Ty<'_>, path: &[&str]) -> bool { +pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool { match ty.kind { ty::Adt(adt, _) => match_def_path(cx, adt.did, path), _ => false, @@ -142,7 +142,7 @@ pub fn match_type(cx: &LateContext<'_, '_>, ty: Ty<'_>, path: &[&str]) -> bool { } /// Checks if the type is equal to a diagnostic item -pub fn is_type_diagnostic_item(cx: &LateContext<'_, '_>, ty: Ty<'_>, diag_item: Symbol) -> bool { +pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symbol) -> bool { match ty.kind { ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(diag_item, adt.did), _ => false, @@ -150,7 +150,7 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_, '_>, ty: Ty<'_>, diag_item: } /// Checks if the method call given in `expr` belongs to the given trait. -pub fn match_trait_method(cx: &LateContext<'_, '_>, expr: &Expr<'_>, path: &[&str]) -> bool { +pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str]) -> bool { let def_id = cx.tables().type_dependent_def_id(expr.hir_id).unwrap(); let trt_id = cx.tcx.trait_of_item(def_id); if let Some(trt_id) = trt_id { @@ -249,7 +249,7 @@ pub fn match_path_ast(path: &ast::Path, segments: &[&str]) -> bool { } /// Gets the definition associated to a path. -pub fn path_to_res(cx: &LateContext<'_, '_>, path: &[&str]) -> Option { +pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Option { let crates = cx.tcx.crates(); let krate = crates .iter() @@ -285,7 +285,7 @@ pub fn path_to_res(cx: &LateContext<'_, '_>, path: &[&str]) -> Option } } -pub fn qpath_res(cx: &LateContext<'_, '_>, qpath: &hir::QPath<'_>, id: hir::HirId) -> Res { +pub fn qpath_res(cx: &LateContext<'_>, qpath: &hir::QPath<'_>, id: hir::HirId) -> Res { match qpath { hir::QPath::Resolved(_, path) => path.res, hir::QPath::TypeRelative(..) => { @@ -302,7 +302,7 @@ pub fn qpath_res(cx: &LateContext<'_, '_>, qpath: &hir::QPath<'_>, id: hir::HirI /// Convenience function to get the `DefId` of a trait by path. /// It could be a trait or trait alias. -pub fn get_trait_def_id(cx: &LateContext<'_, '_>, path: &[&str]) -> Option { +pub fn get_trait_def_id(cx: &LateContext<'_>, path: &[&str]) -> Option { let res = match path_to_res(cx, path) { Some(res) => res, None => return None, @@ -317,8 +317,8 @@ pub fn get_trait_def_id(cx: &LateContext<'_, '_>, path: &[&str]) -> Option( - cx: &LateContext<'a, 'tcx>, +pub fn implements_trait<'tcx>( + cx: &LateContext<'tcx>, ty: Ty<'tcx>, trait_id: DefId, ty_params: &[GenericArg<'tcx>], @@ -347,7 +347,7 @@ pub fn implements_trait<'a, 'tcx>( /// } /// } /// ``` -pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'_, 'tcx>, hir_id: HirId) -> Option<&'tcx TraitRef<'tcx>> { +pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx TraitRef<'tcx>> { // Get the implemented trait for the current function let parent_impl = cx.tcx.hir().get_parent_item(hir_id); if_chain! { @@ -360,7 +360,7 @@ pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'_, 'tcx>, hir_id: HirId) -> O } /// Checks whether this type implements `Drop`. -pub fn has_drop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { +pub fn has_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { match ty.ty_adt_def() { Some(def) => def.has_dtor(cx.tcx), None => false, @@ -426,14 +426,14 @@ pub fn method_chain_args<'a>(expr: &'a Expr<'_>, methods: &[&str]) -> Option, def_id: DefId) -> bool { +pub fn is_entrypoint_fn(cx: &LateContext<'_>, def_id: DefId) -> bool { cx.tcx .entry_fn(LOCAL_CRATE) .map_or(false, |(entry_fn_def_id, _)| def_id == entry_fn_def_id.to_def_id()) } /// Gets the name of the item the expression is in, if available. -pub fn get_item_name(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option { +pub fn get_item_name(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id); match cx.tcx.hir().find(parent_id) { Some( @@ -717,7 +717,7 @@ fn trim_multiline_inner(s: Cow<'_, str>, ignore_first: bool, indent: Option(cx: &'c LateContext<'_, '_>, e: &Expr<'_>) -> Option<&'c Expr<'c>> { +pub fn get_parent_expr<'c>(cx: &'c LateContext<'_>, e: &Expr<'_>) -> Option<&'c Expr<'c>> { let map = &cx.tcx.hir(); let hir_id = e.hir_id; let parent_id = map.get_parent_node(hir_id); @@ -733,7 +733,7 @@ pub fn get_parent_expr<'c>(cx: &'c LateContext<'_, '_>, e: &Expr<'_>) -> Option< }) } -pub fn get_enclosing_block<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, hir_id: HirId) -> Option<&'tcx Block<'tcx>> { +pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Block<'tcx>> { let map = &cx.tcx.hir(); let enclosing_node = map .get_enclosing_scope(hir_id) @@ -789,7 +789,7 @@ pub fn walk_ptrs_ty_depth(ty: Ty<'_>) -> (Ty<'_>, usize) { /// Checks whether the given expression is a constant integer of the given value. /// unlike `is_integer_literal`, this version does const folding -pub fn is_integer_const(cx: &LateContext<'_, '_>, e: &Expr<'_>, value: u128) -> bool { +pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool { if is_integer_literal(e, value) { return true; } @@ -823,7 +823,7 @@ pub fn is_integer_literal(expr: &Expr<'_>, value: u128) -> bool { /// /// See `rustc_middle::ty::adjustment::Adjustment` and `rustc_typeck::check::coercion` for more /// information on adjustments and coercions. -pub fn is_adjusted(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool { +pub fn is_adjusted(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { cx.tables().adjustments().get(e.hir_id).is_some() } @@ -876,26 +876,26 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option { } /// Convenience function to get the return type of a function. -pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: hir::HirId) -> Ty<'tcx> { +pub fn return_ty<'tcx>(cx: &LateContext<'tcx>, fn_item: hir::HirId) -> Ty<'tcx> { let fn_def_id = cx.tcx.hir().local_def_id(fn_item); let ret_ty = cx.tcx.fn_sig(fn_def_id).output(); cx.tcx.erase_late_bound_regions(&ret_ty) } /// Returns `true` if the given type is an `unsafe` function. -pub fn type_is_unsafe_function<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { +pub fn type_is_unsafe_function<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { match ty.kind { ty::FnDef(..) | ty::FnPtr(_) => ty.fn_sig(cx.tcx).unsafety() == Unsafety::Unsafe, _ => false, } } -pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { +pub fn is_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { ty.is_copy_modulo_regions(cx.tcx.at(DUMMY_SP), cx.param_env) } /// Checks if an expression is constructing a tuple-like enum variant or struct -pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { +pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { if let ExprKind::Call(ref fun, _) = expr.kind { if let ExprKind::Path(ref qp) = fun.kind { let res = cx.qpath_res(qp, fun.hir_id); @@ -911,15 +911,15 @@ pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_, '_>, expr: &Exp /// Returns `true` if a pattern is refutable. // TODO: should be implemented using rustc/mir_build/hair machinery -pub fn is_refutable(cx: &LateContext<'_, '_>, pat: &Pat<'_>) -> bool { - fn is_enum_variant(cx: &LateContext<'_, '_>, qpath: &QPath<'_>, id: HirId) -> bool { +pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { + fn is_enum_variant(cx: &LateContext<'_>, qpath: &QPath<'_>, id: HirId) -> bool { matches!( cx.qpath_res(qpath, id), def::Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(def::CtorOf::Variant, _), _) ) } - fn are_refutable<'a, I: Iterator>>(cx: &LateContext<'_, '_>, mut i: I) -> bool { + fn are_refutable<'a, I: Iterator>>(cx: &LateContext<'_>, mut i: I) -> bool { i.any(|pat| is_refutable(cx, pat)) } @@ -1050,7 +1050,7 @@ pub fn is_try<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { /// Returns `true` if the lint is allowed in the current context /// /// Useful for skipping long running code when it's unnecessary -pub fn is_allowed(cx: &LateContext<'_, '_>, lint: &'static Lint, id: HirId) -> bool { +pub fn is_allowed(cx: &LateContext<'_>, lint: &'static Lint, id: HirId) -> bool { cx.tcx.lint_level_at_node(lint, id).0 == Level::Allow } @@ -1135,7 +1135,7 @@ pub fn any_parent_is_automatically_derived(tcx: TyCtxt<'_>, node: HirId) -> bool } /// Returns true if ty has `iter` or `iter_mut` methods -pub fn has_iter_method(cx: &LateContext<'_, '_>, probably_ref_ty: Ty<'_>) -> Option<&'static str> { +pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option<&'static str> { // FIXME: instead of this hard-coded list, we should check if `::iter` // exists and has the desired signature. Unfortunately FnCtxt is not exported // so we can't use its `lookup_method` method. @@ -1182,8 +1182,8 @@ pub fn has_iter_method(cx: &LateContext<'_, '_>, probably_ref_ty: Ty<'_>) -> Opt /// ```rust,ignore /// if let Some(args) = match_function_call(cx, begin_panic_call, &paths::BEGIN_PANIC); /// ``` -pub fn match_function_call<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +pub fn match_function_call<'tcx>( + cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, path: &[&str], ) -> Option<&'tcx [Expr<'tcx>]> { @@ -1201,14 +1201,14 @@ pub fn match_function_call<'a, 'tcx>( /// Checks if `Ty` is normalizable. This function is useful /// to avoid crashes on `layout_of`. -pub fn is_normalizable<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool { +pub fn is_normalizable<'tcx>(cx: &LateContext<'tcx>, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool { cx.tcx.infer_ctxt().enter(|infcx| { let cause = rustc_middle::traits::ObligationCause::dummy(); infcx.at(&cause, param_env).normalize(&ty).is_ok() }) } -pub fn match_def_path<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, did: DefId, syms: &[&str]) -> bool { +pub fn match_def_path<'tcx>(cx: &LateContext<'tcx>, did: DefId, syms: &[&str]) -> bool { // We have to convert `syms` to `&[Symbol]` here because rustc's `match_def_path` // accepts only that. We should probably move to Symbols in Clippy as well. let syms = syms.iter().map(|p| Symbol::intern(p)).collect::>(); @@ -1250,7 +1250,7 @@ pub fn if_sequence<'tcx>( (conds, blocks) } -pub fn parent_node_is_if_expr<'a, 'b>(expr: &Expr<'_>, cx: &LateContext<'a, 'b>) -> bool { +pub fn parent_node_is_if_expr(expr: &Expr<'_>, cx: &LateContext<'_>) -> bool { let map = cx.tcx.hir(); let parent_id = map.get_parent_node(expr.hir_id); let parent_node = map.get(parent_id); @@ -1275,7 +1275,7 @@ pub fn must_use_attr(attrs: &[Attribute]) -> Option<&Attribute> { } // Returns whether the type has #[must_use] attribute -pub fn is_must_use_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { +pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { match ty.kind { ty::Adt(ref adt, _) => must_use_attr(&cx.tcx.get_attrs(adt.did)).is_some(), ty::Foreign(ref did) => must_use_attr(&cx.tcx.get_attrs(*did)).is_some(), @@ -1313,7 +1313,7 @@ pub fn is_must_use_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> boo } // check if expr is calling method or function with #[must_use] attribyte -pub fn is_must_use_func_call(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { +pub fn is_must_use_func_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let did = match expr.kind { ExprKind::Call(ref path, _) => if_chain! { if let ExprKind::Path(ref qpath) = path.kind; @@ -1352,7 +1352,7 @@ pub fn is_no_std_crate(krate: &Crate<'_>) -> bool { /// fn f() {} /// } /// ``` -pub fn is_trait_impl_item(cx: &LateContext<'_, '_>, hir_id: HirId) -> bool { +pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool { if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { matches!(item.kind, ItemKind::Impl{ of_trait: Some(_), .. }) } else { @@ -1369,7 +1369,7 @@ pub fn is_trait_impl_item(cx: &LateContext<'_, '_>, hir_id: HirId) -> bool { /// for _ in 2i32 {} /// } /// ``` -pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_, '_>, did: DefId) -> bool { +pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool { use rustc_trait_selection::traits; let predicates = cx.tcx @@ -1385,7 +1385,7 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_, '_>, did: DefId) -> bool ) } -pub fn run_lints(cx: &LateContext<'_, '_>, lints: &[&'static Lint], id: HirId) -> bool { +pub fn run_lints(cx: &LateContext<'_>, lints: &[&'static Lint], id: HirId) -> bool { lints.iter().any(|lint| { matches!( cx.tcx.lint_level_at_node(lint, id), diff --git a/clippy_lints/src/utils/ptr.rs b/clippy_lints/src/utils/ptr.rs index ee336ecc58d9..bd2c619f0002 100644 --- a/clippy_lints/src/utils/ptr.rs +++ b/clippy_lints/src/utils/ptr.rs @@ -7,7 +7,7 @@ use rustc_span::{Span, Symbol}; use std::borrow::Cow; pub fn get_spans( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, opt_body_id: Option, idx: usize, replacements: &[(&'static str, &'static str)], @@ -22,8 +22,8 @@ pub fn get_spans( } } -fn extract_clone_suggestions<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, +fn extract_clone_suggestions<'tcx>( + cx: &LateContext<'tcx>, name: Symbol, replace: &[(&'static str, &'static str)], body: &'tcx Body<'_>, @@ -44,7 +44,7 @@ fn extract_clone_suggestions<'a, 'tcx>( } struct PtrCloneVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, + cx: &'a LateContext<'tcx>, name: Symbol, replace: &'a [(&'static str, &'static str)], spans: Vec<(Span, Cow<'static, str>)>, diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index e919b1522d89..d05e81b95057 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -39,7 +39,7 @@ impl Display for Sugg<'_> { #[allow(clippy::wrong_self_convention)] // ok, because of the function `as_ty` method impl<'a> Sugg<'a> { /// Prepare a suggestion from an expression. - pub fn hir_opt(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) -> Option { + pub fn hir_opt(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option { snippet_opt(cx, expr.span).map(|snippet| { let snippet = Cow::Owned(snippet); Self::hir_from_snippet(cx, expr, snippet) @@ -48,7 +48,7 @@ impl<'a> Sugg<'a> { /// Convenience function around `hir_opt` for suggestions with a default /// text. - pub fn hir(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, default: &'a str) -> Self { + pub fn hir(cx: &LateContext<'_>, expr: &hir::Expr<'_>, default: &'a str) -> Self { Self::hir_opt(cx, expr).unwrap_or_else(|| Sugg::NonParen(Cow::Borrowed(default))) } @@ -60,7 +60,7 @@ impl<'a> Sugg<'a> { /// to /// `HasPlaceholders` pub fn hir_with_applicability( - cx: &LateContext<'_, '_>, + cx: &LateContext<'_>, expr: &hir::Expr<'_>, default: &'a str, applicability: &mut Applicability, @@ -77,7 +77,7 @@ impl<'a> Sugg<'a> { } /// Same as `hir`, but will use the pre expansion span if the `expr` was in a macro. - pub fn hir_with_macro_callsite(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, default: &'a str) -> Self { + pub fn hir_with_macro_callsite(cx: &LateContext<'_>, expr: &hir::Expr<'_>, default: &'a str) -> Self { let snippet = snippet_with_macro_callsite(cx, expr.span, default); Self::hir_from_snippet(cx, expr, snippet) @@ -85,7 +85,7 @@ impl<'a> Sugg<'a> { /// Generate a suggestion for an expression with the given snippet. This is used by the `hir_*` /// function variants of `Sugg`, since these use different snippet functions. - fn hir_from_snippet(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, snippet: Cow<'a, str>) -> Self { + fn hir_from_snippet(cx: &LateContext<'_>, expr: &hir::Expr<'_>, snippet: Cow<'a, str>) -> Self { if let Some(range) = higher::range(cx, expr) { let op = match range.limits { ast::RangeLimits::HalfOpen => AssocOp::DotDot, diff --git a/clippy_lints/src/utils/usage.rs b/clippy_lints/src/utils/usage.rs index d280fe4ab4e0..53d3a241f58a 100644 --- a/clippy_lints/src/utils/usage.rs +++ b/clippy_lints/src/utils/usage.rs @@ -11,7 +11,7 @@ use rustc_span::symbol::{Ident, Symbol}; use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; /// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined. -pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &'a LateContext<'a, 'tcx>) -> Option> { +pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) -> Option> { let mut delegate = MutVarsDelegate { used_mutably: FxHashSet::default(), skip: false, @@ -27,11 +27,7 @@ pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &'a LateContext<'a, Some(delegate.used_mutably) } -pub fn is_potentially_mutated<'a, 'tcx>( - variable: &'tcx Path<'_>, - expr: &'tcx Expr<'_>, - cx: &'a LateContext<'a, 'tcx>, -) -> bool { +pub fn is_potentially_mutated<'tcx>(variable: &'tcx Path<'_>, expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) -> bool { if let Res::Local(id) = variable.res { mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&id)) } else { diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index 080785b177d6..e1043c36e0a5 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -33,8 +33,8 @@ declare_clippy_lint! { declare_lint_pass!(UselessVec => [USELESS_VEC]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessVec { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for UselessVec { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { // search for `&vec![_]` expressions where the adjusted type is `&[_]` if_chain! { if let ty::Ref(_, ty, _) = cx.tables().expr_ty_adjusted(expr).kind; @@ -66,7 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessVec { } } -fn check_vec_macro<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, vec_args: &higher::VecArgs<'tcx>, span: Span) { +fn check_vec_macro<'tcx>(cx: &LateContext<'tcx>, vec_args: &higher::VecArgs<'tcx>, span: Span) { let mut applicability = Applicability::MachineApplicable; let snippet = match *vec_args { higher::VecArgs::Repeat(elem, len) => { diff --git a/clippy_lints/src/vec_resize_to_zero.rs b/clippy_lints/src/vec_resize_to_zero.rs index bb315e64e5de..cc5e21a7ca6f 100644 --- a/clippy_lints/src/vec_resize_to_zero.rs +++ b/clippy_lints/src/vec_resize_to_zero.rs @@ -28,8 +28,8 @@ declare_clippy_lint! { declare_lint_pass!(VecResizeToZero => [VEC_RESIZE_TO_ZERO]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VecResizeToZero { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for VecResizeToZero { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let hir::ExprKind::MethodCall(path_segment, _, ref args, _) = expr.kind; if let Some(method_def_id) = cx.tables().type_dependent_def_id(expr.hir_id); diff --git a/clippy_lints/src/verbose_file_reads.rs b/clippy_lints/src/verbose_file_reads.rs index 85f920845744..b06fe36da631 100644 --- a/clippy_lints/src/verbose_file_reads.rs +++ b/clippy_lints/src/verbose_file_reads.rs @@ -33,8 +33,8 @@ declare_clippy_lint! { declare_lint_pass!(VerboseFileReads => [VERBOSE_FILE_READS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VerboseFileReads { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) { +impl<'tcx> LateLintPass<'tcx> for VerboseFileReads { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if is_file_read_to_end(cx, expr) { span_lint_and_help( cx, @@ -57,7 +57,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VerboseFileReads { } } -fn is_file_read_to_end<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) -> bool { +fn is_file_read_to_end<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool { if_chain! { if let ExprKind::MethodCall(method_name, _, exprs, _) = expr.kind; if method_name.ident.as_str() == "read_to_end"; @@ -71,7 +71,7 @@ fn is_file_read_to_end<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'t false } -fn is_file_read_to_string<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) -> bool { +fn is_file_read_to_string<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool { if_chain! { if let ExprKind::MethodCall(method_name, _, exprs, _) = expr.kind; if method_name.ident.as_str() == "read_to_string"; diff --git a/clippy_lints/src/wildcard_dependencies.rs b/clippy_lints/src/wildcard_dependencies.rs index 511518082bec..cd1864f461d3 100644 --- a/clippy_lints/src/wildcard_dependencies.rs +++ b/clippy_lints/src/wildcard_dependencies.rs @@ -28,8 +28,8 @@ declare_clippy_lint! { declare_lint_pass!(WildcardDependencies => [WILDCARD_DEPENDENCIES]); -impl LateLintPass<'_, '_> for WildcardDependencies { - fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) { +impl LateLintPass<'_> for WildcardDependencies { + fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { if !run_lints(cx, &[WILDCARD_DEPENDENCIES], CRATE_HIR_ID) { return; } diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 79f7705e281e..e7eb7c2e9802 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -101,8 +101,8 @@ impl WildcardImports { impl_lint_pass!(WildcardImports => [ENUM_GLOB_USE, WILDCARD_IMPORTS]); -impl LateLintPass<'_, '_> for WildcardImports { - fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item<'_>) { +impl LateLintPass<'_> for WildcardImports { + fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { if is_test_module_or_function(item) { self.test_modules_deep = self.test_modules_deep.saturating_add(1); } @@ -180,7 +180,7 @@ impl LateLintPass<'_, '_> for WildcardImports { } } - fn check_item_post(&mut self, _: &LateContext<'_, '_>, item: &Item<'_>) { + fn check_item_post(&mut self, _: &LateContext<'_>, item: &Item<'_>) { if is_test_module_or_function(item) { self.test_modules_deep = self.test_modules_deep.saturating_sub(1); } diff --git a/clippy_lints/src/zero_div_zero.rs b/clippy_lints/src/zero_div_zero.rs index f0cf17c3b954..1e011ea9cba5 100644 --- a/clippy_lints/src/zero_div_zero.rs +++ b/clippy_lints/src/zero_div_zero.rs @@ -27,8 +27,8 @@ declare_clippy_lint! { declare_lint_pass!(ZeroDiv => [ZERO_DIVIDED_BY_ZERO]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ZeroDiv { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for ZeroDiv { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { // check for instances of 0.0/0.0 if_chain! { if let ExprKind::Binary(ref op, ref left, ref right) = expr.kind; diff --git a/doc/common_tools_writing_lints.md b/doc/common_tools_writing_lints.md index d06e359bc7aa..412ff99314d9 100644 --- a/doc/common_tools_writing_lints.md +++ b/doc/common_tools_writing_lints.md @@ -28,8 +28,8 @@ that gives you access to the underlying structure [`TyS`][TyS]. Example of use: ```rust -impl LateLintPass<'_, '_> for MyStructLint { - fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) { +impl LateLintPass<'_> for MyStructLint { + fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { // Get type of `expr` let ty = cx.tables().expr_ty(expr); // Match its kind to enter its type @@ -56,8 +56,8 @@ Two noticeable items here: Starting with an `expr`, you can check whether it is calling a specific method `some_method`: ```rust -impl LateLintPass<'_, '_> for MyStructLint { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { +impl LateLintPass<'_> for MyStructLint { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if_chain! { // Check our expr is calling a method if let hir::ExprKind::MethodCall(path, _, _args) = &expr.kind; @@ -78,8 +78,8 @@ There are two ways to do this, depending if the target trait is part of lang ite ```rust use crate::utils::{implements_trait, match_trait_method, paths}; -impl LateLintPass<'_, '_> for MyStructLint { - fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) { +impl LateLintPass<'_> for MyStructLint { + fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { // 1. Using expression and Clippy's convenient method // we use `match_trait_method` function from Clippy's toolbox if match_trait_method(cx, expr, &paths::INTO) { @@ -112,8 +112,8 @@ To check if our type defines a method called `some_method`: ```rust use crate::utils::{is_type_diagnostic_item, return_ty}; -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MyTypeImpl { - fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx ImplItem<'_>) { +impl<'tcx> LateLintPass<'tcx> for MyTypeImpl { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { if_chain! { // Check if item is a method/function if let ImplItemKind::Fn(ref signature, _) = impl_item.kind; diff --git a/tests/ui/outer_expn_data.fixed b/tests/ui/outer_expn_data.fixed index 999a19b289e1..b0b3498f057f 100644 --- a/tests/ui/outer_expn_data.fixed +++ b/tests/ui/outer_expn_data.fixed @@ -19,8 +19,8 @@ declare_lint! { declare_lint_pass!(Pass => [TEST_LINT]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { - fn check_expr(&mut self, _cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { +impl<'tcx> LateLintPass<'tcx> for Pass { + fn check_expr(&mut self, _cx: &LateContext<'tcx>, expr: &'tcx Expr) { let _ = expr.span.ctxt().outer_expn_data(); } } diff --git a/tests/ui/outer_expn_data.rs b/tests/ui/outer_expn_data.rs index 5405d475d1ac..55a3fed00d07 100644 --- a/tests/ui/outer_expn_data.rs +++ b/tests/ui/outer_expn_data.rs @@ -19,8 +19,8 @@ declare_lint! { declare_lint_pass!(Pass => [TEST_LINT]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { - fn check_expr(&mut self, _cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { +impl<'tcx> LateLintPass<'tcx> for Pass { + fn check_expr(&mut self, _cx: &LateContext<'tcx>, expr: &'tcx Expr) { let _ = expr.span.ctxt().outer_expn().expn_data(); } } From defde31a6e9d1768244c48288dc55d306cca9c73 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Thu, 2 Jul 2020 20:52:40 -0400 Subject: [PATCH 0033/1222] Shrink ParamEnv to 16 bytes --- clippy_lints/src/needless_pass_by_value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 6954f0cc683f..2c68ebc1f8a9 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -111,7 +111,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { let fn_def_id = cx.tcx.hir().local_def_id(hir_id); - let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.iter()) + let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds().iter()) .filter(|p| !p.is_global()) .filter_map(|obligation| { if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate.kind() { From 115cd86d0c7adf636af30670d683f1b84edd7f29 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 7 Jul 2020 11:12:44 -0400 Subject: [PATCH 0034/1222] Avoid "whitelist" Other terms are more inclusive and precise. --- clippy_lints/src/attrs.rs | 4 ++-- clippy_lints/src/eq_op.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- clippy_lints/src/non_expressive_names.rs | 18 +++++++++--------- clippy_lints/src/precedence.rs | 4 ++-- clippy_lints/src/types.rs | 4 ++-- .../{whitelist => third-party}/clippy.toml | 0 .../conf_allowlisted.rs} | 0 tests/ui/needless_pass_by_value.rs | 2 +- tests/ui/neg_cmp_op_on_partial_ord.rs | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) rename tests/ui/crashes/{whitelist => third-party}/clippy.toml (100%) rename tests/ui/crashes/{whitelist/conf_whitelisted.rs => third-party/conf_allowlisted.rs} (100%) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 2505ff32fe52..3f7d6ba64677 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -72,7 +72,7 @@ declare_clippy_lint! { /// **What it does:** Checks for `extern crate` and `use` items annotated with /// lint attributes. /// - /// This lint whitelists `#[allow(unused_imports)]`, `#[allow(deprecated)]` and + /// This lint permits `#[allow(unused_imports)]`, `#[allow(deprecated)]` and /// `#[allow(unreachable_pub)]` on `use` items and `#[allow(unused_imports)]` on /// `extern crate` items with a `#[macro_use]` attribute. /// @@ -294,7 +294,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { if let Some(ident) = attr.ident() { match &*ident.as_str() { "allow" | "warn" | "deny" | "forbid" => { - // whitelist `unused_imports`, `deprecated` and `unreachable_pub` for `use` items + // permit `unused_imports`, `deprecated` and `unreachable_pub` for `use` items // and `unused_imports` for `extern crate` items with `macro_use` for lint in lint_list { match item.kind { diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index ca921dcfdfe9..cbc93d772dd9 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -16,7 +16,7 @@ declare_clippy_lint! { /// **Known problems:** False negatives: We had some false positives regarding /// calls (notably [racer](https://github.com/phildawes/racer) had one instance /// of `x.pop() && x.pop()`), so we removed matching any function or method - /// calls. We may introduce a whitelist of known pure functions in the future. + /// calls. We may introduce a list of known pure functions in the future. /// /// **Example:** /// ```rust diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 5d47f9425e3e..29e5d4d16649 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -100,7 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { // Allow `Borrow` or functions to be taken by value let borrow_trait = need!(get_trait_def_id(cx, &paths::BORROW_TRAIT)); - let whitelisted_traits = [ + let allowed_traits = [ need!(cx.tcx.lang_items().fn_trait()), need!(cx.tcx.lang_items().fn_once_trait()), need!(cx.tcx.lang_items().fn_mut_trait()), @@ -184,7 +184,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { if !is_self(arg); if !ty.is_mutable_ptr(); if !is_copy(cx, ty); - if !whitelisted_traits.iter().any(|&t| implements_trait(cx, ty, t, &[])); + if !allowed_traits.iter().any(|&t| implements_trait(cx, ty, t, &[])); if !implements_borrow_trait; if !all_borrowable_trait; diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 5f14fe97afef..7128fee9bcf5 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -78,7 +78,7 @@ struct ExistingName { interned: SymbolStr, span: Span, len: usize, - whitelist: &'static [&'static str], + exemptions: &'static [&'static str], } struct SimilarNamesLocalVisitor<'a, 'tcx> { @@ -117,7 +117,7 @@ impl<'a, 'tcx> SimilarNamesLocalVisitor<'a, 'tcx> { // this list contains lists of names that are allowed to be similar // the assumption is that no name is ever contained in multiple lists. #[rustfmt::skip] -const WHITELIST: &[&[&str]] = &[ +const ALLOWED_TO_BE_SIMILAR: &[&[&str]] = &[ &["parsed", "parser"], &["lhs", "rhs"], &["tx", "rx"], @@ -156,17 +156,17 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for SimilarNamesNameVisitor<'a, 'tcx, 'b> { } #[must_use] -fn get_whitelist(interned_name: &str) -> Option<&'static [&'static str]> { - for &allow in WHITELIST { - if whitelisted(interned_name, allow) { - return Some(allow); +fn get_exemptions(interned_name: &str) -> Option<&'static [&'static str]> { + for &list in ALLOWED_TO_BE_SIMILAR { + if allowed_to_be_similar(interned_name, list) { + return Some(list); } } None } #[must_use] -fn whitelisted(interned_name: &str, list: &[&str]) -> bool { +fn allowed_to_be_similar(interned_name: &str, list: &[&str]) -> bool { list.iter() .any(|&name| interned_name.starts_with(name) || interned_name.ends_with(name)) } @@ -212,7 +212,7 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> { return; } for existing_name in &self.0.names { - if whitelisted(&interned_name, existing_name.whitelist) { + if allowed_to_be_similar(&interned_name, existing_name.exemptions) { continue; } let mut split_at = None; @@ -301,7 +301,7 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> { return; } self.0.names.push(ExistingName { - whitelist: get_whitelist(&interned_name).unwrap_or(&[]), + exemptions: get_exemptions(&interned_name).unwrap_or(&[]), interned: interned_name, span: ident.span, len: count, diff --git a/clippy_lints/src/precedence.rs b/clippy_lints/src/precedence.rs index 7dce23dd2230..23793678fa0e 100644 --- a/clippy_lints/src/precedence.rs +++ b/clippy_lints/src/precedence.rs @@ -5,7 +5,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Spanned; -const ODD_FUNCTIONS_WHITELIST: [&str; 14] = [ +const ALLOWED_ODD_FUNCTIONS: [&str; 14] = [ "asin", "asinh", "atan", @@ -109,7 +109,7 @@ impl EarlyLintPass for Precedence { if let ExprKind::Lit(ref lit) = slf.kind { match lit.kind { LitKind::Int(..) | LitKind::Float(..) => { - if ODD_FUNCTIONS_WHITELIST + if ALLOWED_ODD_FUNCTIONS .iter() .any(|odd_function| **odd_function == *path_segment_str) { diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index b1345f0de5e4..68f51f0afdcc 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -1256,7 +1256,7 @@ fn check_loss_of_sign(cx: &LateContext<'_>, expr: &Expr<'_>, op: &Expr<'_>, cast // don't lint for the result of methods that always return non-negative values if let ExprKind::MethodCall(ref path, _, _, _) = op.kind { let mut method_name = path.ident.name.as_str(); - let whitelisted_methods = ["abs", "checked_abs", "rem_euclid", "checked_rem_euclid"]; + let allowed_methods = ["abs", "checked_abs", "rem_euclid", "checked_rem_euclid"]; if_chain! { if method_name == "unwrap"; @@ -1267,7 +1267,7 @@ fn check_loss_of_sign(cx: &LateContext<'_>, expr: &Expr<'_>, op: &Expr<'_>, cast } } - if whitelisted_methods.iter().any(|&name| method_name == name) { + if allowed_methods.iter().any(|&name| method_name == name) { return; } } diff --git a/tests/ui/crashes/whitelist/clippy.toml b/tests/ui/crashes/third-party/clippy.toml similarity index 100% rename from tests/ui/crashes/whitelist/clippy.toml rename to tests/ui/crashes/third-party/clippy.toml diff --git a/tests/ui/crashes/whitelist/conf_whitelisted.rs b/tests/ui/crashes/third-party/conf_allowlisted.rs similarity index 100% rename from tests/ui/crashes/whitelist/conf_whitelisted.rs rename to tests/ui/crashes/third-party/conf_allowlisted.rs diff --git a/tests/ui/needless_pass_by_value.rs b/tests/ui/needless_pass_by_value.rs index e93a7fe2985b..7a9ba55590dc 100644 --- a/tests/ui/needless_pass_by_value.rs +++ b/tests/ui/needless_pass_by_value.rs @@ -116,7 +116,7 @@ extern "C" fn ext(x: MaybeUninit) -> usize { unsafe { x.assume_init() } } -// whitelist RangeArgument +// exempt RangeArgument fn range>(range: T) { let _ = range.start_bound(); } diff --git a/tests/ui/neg_cmp_op_on_partial_ord.rs b/tests/ui/neg_cmp_op_on_partial_ord.rs index ca70e3b7148e..0b4711952724 100644 --- a/tests/ui/neg_cmp_op_on_partial_ord.rs +++ b/tests/ui/neg_cmp_op_on_partial_ord.rs @@ -57,6 +57,6 @@ fn main() { // The macro always negates the result of the given comparison in its // internal check which automatically triggered the lint. As it's an // external macro there was no chance to do anything about it which led - // to a whitelisting of all external macros. + // to an exempting of all external macros. assert!(a_value < another_value); } From 6335120c5d77778471399b7baa19550da77ff096 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 30 Aug 2019 02:01:04 +0200 Subject: [PATCH 0035/1222] Stabilize `transmute` in constants and statics but not const fn --- tests/ui/missing_const_for_fn/could_be_const.stderr | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/ui/missing_const_for_fn/could_be_const.stderr b/tests/ui/missing_const_for_fn/could_be_const.stderr index 8dde56cd79f4..74d32b8a1aa9 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.stderr +++ b/tests/ui/missing_const_for_fn/could_be_const.stderr @@ -57,14 +57,6 @@ LL | | t LL | | } | |_^ -error: this could be a `const fn` - --> $DIR/could_be_const.rs:48:1 - | -LL | / fn sub(x: u32) -> usize { -LL | | unsafe { transmute(&x) } -LL | | } - | |_^ - error: this could be a `const fn` --> $DIR/could_be_const.rs:67:9 | @@ -73,5 +65,5 @@ LL | | B LL | | } | |_________^ -error: aborting due to 9 previous errors +error: aborting due to 8 previous errors From a7530f7a10dd8433b513f3e28cc39c57cc6f0328 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 8 Jul 2020 20:03:37 +1000 Subject: [PATCH 0036/1222] Remove lots of `Symbol::as_str()` calls. In various ways, such as changing functions to take a `Symbol` instead of a `&str`. --- clippy_lints/src/attrs.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index ef01364b7d96..c29432bf9338 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -421,7 +421,11 @@ fn check_clippy_lint_names(cx: &LateContext<'_>, ident: &str, items: &[NestedMet .iter() .map(|l| Symbol::intern(&l.name_lower())) .collect::>(); - let sugg = find_best_match_for_name(symbols.iter(), &format!("clippy::{}", name_lower), None); + let sugg = find_best_match_for_name( + symbols.iter(), + Symbol::intern(&format!("clippy::{}", name_lower)), + None, + ); if lint_name.chars().any(char::is_uppercase) && lint_store.find_lints(&format!("clippy::{}", name_lower)).is_ok() { From 423d19f1949c6ba9de86b4aeff59e33e9c2dfc16 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Thu, 2 Jul 2020 23:56:17 +0200 Subject: [PATCH 0037/1222] const_eval_resolve --- clippy_lints/src/consts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 2f963dfcf8b1..6ba4201b2c25 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -332,7 +332,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let result = self .lcx .tcx - .const_eval_resolve(self.param_env, def_id, substs, None, None) + .const_eval_resolve(self.param_env, ty::WithOptParam::dummy(def_id), substs, None, None) .ok() .map(|val| rustc_middle::ty::Const::from_value(self.lcx.tcx, val, ty))?; let result = miri_to_const(&result); From 06f8a44121229d1f096fb80fd49b6002c0f6737e Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Wed, 15 Jul 2020 10:50:54 +0200 Subject: [PATCH 0038/1222] improve naming --- clippy_lints/src/consts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 6ba4201b2c25..891cb69bb562 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -332,7 +332,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let result = self .lcx .tcx - .const_eval_resolve(self.param_env, ty::WithOptParam::dummy(def_id), substs, None, None) + .const_eval_resolve(self.param_env, ty::WithOptConstParam::dummy(def_id), substs, None, None) .ok() .map(|val| rustc_middle::ty::Const::from_value(self.lcx.tcx, val, ty))?; let result = miri_to_const(&result); From 5757442e74be960b970e4a95b6eebd6cc9a6db29 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Wed, 15 Jul 2020 10:55:41 +0200 Subject: [PATCH 0039/1222] WithOptConstParam::dummy -> WithOptConstParam::unknown --- clippy_lints/src/consts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 891cb69bb562..e6ef54f528f4 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -332,7 +332,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let result = self .lcx .tcx - .const_eval_resolve(self.param_env, ty::WithOptConstParam::dummy(def_id), substs, None, None) + .const_eval_resolve(self.param_env, ty::WithOptConstParam::unknown(def_id), substs, None, None) .ok() .map(|val| rustc_middle::ty::Const::from_value(self.lcx.tcx, val, ty))?; let result = miri_to_const(&result); From 809fa5699bc11d34948d723ec4403bd40a7ab834 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 13 Jul 2020 16:45:35 +1000 Subject: [PATCH 0040/1222] Avoid storing `SymbolStr` in a struct. It's intended only for very temporary use. --- clippy_lints/src/non_expressive_names.rs | 13 +++++++------ clippy_lints/src/unsafe_removed_from_name.rs | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 7128fee9bcf5..1d4772bb3d60 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -8,7 +8,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; -use rustc_span::symbol::{Ident, SymbolStr}; +use rustc_span::symbol::{Ident, Symbol}; use std::cmp::Ordering; declare_clippy_lint! { @@ -75,7 +75,7 @@ pub struct NonExpressiveNames { impl_lint_pass!(NonExpressiveNames => [SIMILAR_NAMES, MANY_SINGLE_CHAR_NAMES, JUST_UNDERSCORES_AND_DIGITS]); struct ExistingName { - interned: SymbolStr, + interned: Symbol, span: Span, len: usize, exemptions: &'static [&'static str], @@ -218,18 +218,19 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> { let mut split_at = None; match existing_name.len.cmp(&count) { Ordering::Greater => { - if existing_name.len - count != 1 || levenstein_not_1(&interned_name, &existing_name.interned) { + if existing_name.len - count != 1 || levenstein_not_1(&interned_name, &existing_name.interned.as_str()) { continue; } }, Ordering::Less => { - if count - existing_name.len != 1 || levenstein_not_1(&existing_name.interned, &interned_name) { + if count - existing_name.len != 1 || levenstein_not_1(&existing_name.interned.as_str(), &interned_name) { continue; } }, Ordering::Equal => { let mut interned_chars = interned_name.chars(); - let mut existing_chars = existing_name.interned.chars(); + let interned_str = existing_name.interned.as_str(); + let mut existing_chars = interned_str.chars(); let first_i = interned_chars.next().expect("we know we have at least one char"); let first_e = existing_chars.next().expect("we know we have at least one char"); let eq_or_numeric = |(a, b): (char, char)| a == b || a.is_numeric() && b.is_numeric(); @@ -302,7 +303,7 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> { } self.0.names.push(ExistingName { exemptions: get_exemptions(&interned_name).unwrap_or(&[]), - interned: interned_name, + interned: ident.name, span: ident.span, len: count, }); diff --git a/clippy_lints/src/unsafe_removed_from_name.rs b/clippy_lints/src/unsafe_removed_from_name.rs index 735800e7e741..154082a0fdb5 100644 --- a/clippy_lints/src/unsafe_removed_from_name.rs +++ b/clippy_lints/src/unsafe_removed_from_name.rs @@ -3,7 +3,7 @@ use rustc_ast::ast::{Item, ItemKind, UseTree, UseTreeKind}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; -use rustc_span::symbol::{Ident, SymbolStr}; +use rustc_span::symbol::Ident; declare_clippy_lint! { /// **What it does:** Checks for imports that remove "unsafe" from an item's @@ -73,6 +73,6 @@ fn unsafe_to_safe_check(old_name: Ident, new_name: Ident, cx: &EarlyContext<'_>, } #[must_use] -fn contains_unsafe(name: &SymbolStr) -> bool { +fn contains_unsafe(name: &str) -> bool { name.contains("Unsafe") || name.contains("unsafe") } From a16d60bba11a921f7ba3c9e559cc4f6d268d2dea Mon Sep 17 00:00:00 2001 From: Valentin Lazureanu Date: Fri, 17 Jul 2020 08:47:04 +0000 Subject: [PATCH 0041/1222] Rename TypeckTables to TypeckResults. --- clippy_lints/src/arithmetic.rs | 6 +- clippy_lints/src/assertions_on_constants.rs | 4 +- clippy_lints/src/assign_ops.rs | 6 +- clippy_lints/src/atomic_ordering.rs | 2 +- clippy_lints/src/attrs.rs | 23 ++-- clippy_lints/src/await_holding_lock.rs | 4 +- clippy_lints/src/bit_mask.rs | 2 +- clippy_lints/src/booleans.rs | 14 ++- clippy_lints/src/bytecount.rs | 4 +- clippy_lints/src/cognitive_complexity.rs | 2 +- clippy_lints/src/comparison_chain.rs | 2 +- clippy_lints/src/consts.rs | 78 ++++++------ clippy_lints/src/copies.rs | 2 +- clippy_lints/src/default_trait_access.rs | 2 +- clippy_lints/src/dereference.rs | 4 +- clippy_lints/src/drop_forget_ref.rs | 2 +- clippy_lints/src/duration_subsec.rs | 4 +- clippy_lints/src/entry.rs | 2 +- clippy_lints/src/eq_op.rs | 16 +-- clippy_lints/src/erasing_op.rs | 2 +- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/eta_reduction.rs | 6 +- clippy_lints/src/eval_order_dependence.rs | 4 +- clippy_lints/src/fallible_impl_from.rs | 6 +- clippy_lints/src/float_literal.rs | 2 +- clippy_lints/src/floating_point_arithmetic.rs | 37 +++--- clippy_lints/src/format.rs | 2 +- clippy_lints/src/functions.rs | 23 ++-- clippy_lints/src/get_last_with_len.rs | 2 +- clippy_lints/src/identity_op.rs | 8 +- clippy_lints/src/if_let_mutex.rs | 2 +- clippy_lints/src/if_let_some_result.rs | 2 +- clippy_lints/src/implicit_saturating_sub.rs | 4 +- clippy_lints/src/indexing_slicing.rs | 12 +- clippy_lints/src/infinite_iter.rs | 4 +- clippy_lints/src/integer_division.rs | 2 +- clippy_lints/src/large_stack_arrays.rs | 2 +- clippy_lints/src/len_zero.rs | 2 +- clippy_lints/src/let_if_seq.rs | 2 +- clippy_lints/src/let_underscore.rs | 4 +- clippy_lints/src/loops.rs | 44 ++++--- clippy_lints/src/map_clone.rs | 6 +- clippy_lints/src/map_identity.rs | 4 +- clippy_lints/src/map_unit_fn.rs | 19 +-- clippy_lints/src/match_on_vec_items.rs | 4 +- clippy_lints/src/matches.rs | 28 ++--- clippy_lints/src/mem_discriminant.rs | 2 +- clippy_lints/src/mem_forget.rs | 2 +- clippy_lints/src/mem_replace.rs | 4 +- .../src/methods/bind_instead_of_map.rs | 2 +- .../src/methods/inefficient_to_string.rs | 4 +- .../methods/manual_saturating_arithmetic.rs | 4 +- clippy_lints/src/methods/mod.rs | 114 +++++++++--------- .../src/methods/option_map_unwrap_or.rs | 4 +- clippy_lints/src/minmax.rs | 10 +- clippy_lints/src/misc.rs | 16 +-- clippy_lints/src/modulo_arithmetic.rs | 6 +- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/mut_mut.rs | 2 +- clippy_lints/src/mut_reference.rs | 6 +- clippy_lints/src/mutable_debug_assertion.rs | 2 +- clippy_lints/src/mutex_atomic.rs | 2 +- clippy_lints/src/needless_bool.rs | 5 +- clippy_lints/src/needless_borrow.rs | 6 +- clippy_lints/src/needless_pass_by_value.rs | 3 +- clippy_lints/src/needless_update.rs | 2 +- clippy_lints/src/neg_cmp_op_on_partial_ord.rs | 2 +- clippy_lints/src/neg_multiply.rs | 4 +- clippy_lints/src/no_effect.rs | 11 +- clippy_lints/src/non_copy_const.rs | 6 +- clippy_lints/src/open_options.rs | 4 +- clippy_lints/src/option_if_let_else.rs | 3 +- .../src/overflow_check_conditional.rs | 8 +- clippy_lints/src/path_buf_push_overwrite.rs | 2 +- clippy_lints/src/pattern_type_mismatch.rs | 6 +- clippy_lints/src/ptr_offset_with_cast.rs | 4 +- clippy_lints/src/question_mark.rs | 4 +- clippy_lints/src/ranges.rs | 6 +- clippy_lints/src/regex.rs | 2 +- clippy_lints/src/repeat_once.rs | 4 +- clippy_lints/src/shadow.rs | 2 +- clippy_lints/src/strings.rs | 2 +- clippy_lints/src/swap.rs | 2 +- clippy_lints/src/to_digit_is_some.rs | 2 +- clippy_lints/src/transmute.rs | 4 +- clippy_lints/src/transmuting_null.rs | 2 +- clippy_lints/src/try_err.rs | 4 +- clippy_lints/src/types.rs | 46 +++---- clippy_lints/src/unnamed_address.rs | 10 +- clippy_lints/src/unnecessary_sort_by.rs | 2 +- clippy_lints/src/unwrap.rs | 2 +- clippy_lints/src/useless_conversion.rs | 16 +-- clippy_lints/src/utils/higher.rs | 2 +- clippy_lints/src/utils/hir_utils.rs | 46 +++---- clippy_lints/src/utils/inspector.rs | 10 +- clippy_lints/src/utils/internal_lints.rs | 4 +- clippy_lints/src/utils/mod.rs | 20 ++- clippy_lints/src/utils/usage.rs | 9 +- clippy_lints/src/vec.rs | 6 +- clippy_lints/src/vec_resize_to_zero.rs | 2 +- clippy_lints/src/verbose_file_reads.rs | 4 +- clippy_lints/src/zero_div_zero.rs | 4 +- doc/common_tools_writing_lints.md | 16 +-- 103 files changed, 471 insertions(+), 424 deletions(-) diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs index da60856fac93..e84481f9b538 100644 --- a/clippy_lints/src/arithmetic.rs +++ b/clippy_lints/src/arithmetic.rs @@ -86,7 +86,7 @@ impl<'tcx> LateLintPass<'tcx> for Arithmetic { _ => (), } - let (l_ty, r_ty) = (cx.tables().expr_ty(l), cx.tables().expr_ty(r)); + let (l_ty, r_ty) = (cx.typeck_results().expr_ty(l), cx.typeck_results().expr_ty(r)); if l_ty.peel_refs().is_integral() && r_ty.peel_refs().is_integral() { span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected"); self.expr_span = Some(expr.span); @@ -96,8 +96,8 @@ impl<'tcx> LateLintPass<'tcx> for Arithmetic { } }, hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => { - let ty = cx.tables().expr_ty(arg); - if constant_simple(cx, cx.tables(), expr).is_none() { + let ty = cx.typeck_results().expr_ty(arg); + if constant_simple(cx, cx.typeck_results(), expr).is_none() { if ty.is_integral() { span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected"); self.expr_span = Some(expr.span); diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index cffe8d94e279..982d5ecf8d02 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants { } if_chain! { if let ExprKind::Unary(_, ref lit) = e.kind; - if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables(), lit); + if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), lit); if is_true; then { lint_true(true); @@ -121,7 +121,7 @@ fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) if let ExprKind::DropTemps(ref expr) = expr.kind; if let ExprKind::Unary(UnOp::UnNot, ref expr) = expr.kind; // bind the first argument of the `assert!` macro - if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables(), expr); + if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), expr); // arm 1 pattern if let PatKind::Lit(ref lit_expr) = arms[0].pat.kind; if let ExprKind::Lit(ref lit) = lit_expr.kind; diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index bc6e868823f7..dab1e96e282f 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -82,8 +82,8 @@ impl<'tcx> LateLintPass<'tcx> for AssignOps { hir::ExprKind::Assign(assignee, e, _) => { if let hir::ExprKind::Binary(op, l, r) = &e.kind { let lint = |assignee: &hir::Expr<'_>, rhs: &hir::Expr<'_>| { - let ty = cx.tables().expr_ty(assignee); - let rty = cx.tables().expr_ty(rhs); + let ty = cx.typeck_results().expr_ty(assignee); + let rty = cx.typeck_results().expr_ty(rhs); macro_rules! ops { ($op:expr, $cx:expr, @@ -167,7 +167,7 @@ impl<'tcx> LateLintPass<'tcx> for AssignOps { // a = b commutative_op a // Limited to primitive type as these ops are know to be commutative if SpanlessEq::new(cx).ignore_fn().eq_expr(assignee, r) - && cx.tables().expr_ty(assignee).is_primitive_ty() + && cx.typeck_results().expr_ty(assignee).is_primitive_ty() { match op.node { hir::BinOpKind::Add diff --git a/clippy_lints/src/atomic_ordering.rs b/clippy_lints/src/atomic_ordering.rs index efd3f0f671cd..277fe350055e 100644 --- a/clippy_lints/src/atomic_ordering.rs +++ b/clippy_lints/src/atomic_ordering.rs @@ -53,7 +53,7 @@ const ATOMIC_TYPES: [&str; 12] = [ ]; fn type_is_atomic(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.tables().expr_ty(expr).kind { + if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.typeck_results().expr_ty(expr).kind { ATOMIC_TYPES .iter() .any(|ty| match_def_path(cx, did, &["core", "sync", "atomic", ty])) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index c29432bf9338..27a7fa886223 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -461,7 +461,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_>, ident: &str, items: &[NestedMet fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool { if let ItemKind::Fn(_, _, eid) = item.kind { - is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value) + is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value) } else { true } @@ -469,7 +469,7 @@ fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool { fn is_relevant_impl(cx: &LateContext<'_>, item: &ImplItem<'_>) -> bool { match item.kind { - ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value), + ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value), _ => false, } } @@ -478,31 +478,34 @@ fn is_relevant_trait(cx: &LateContext<'_>, item: &TraitItem<'_>) -> bool { match item.kind { TraitItemKind::Fn(_, TraitFn::Required(_)) => true, TraitItemKind::Fn(_, TraitFn::Provided(eid)) => { - is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value) + is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value) }, _ => false, } } -fn is_relevant_block(cx: &LateContext<'_>, tables: &ty::TypeckTables<'_>, block: &Block<'_>) -> bool { +fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>, block: &Block<'_>) -> bool { block.stmts.first().map_or( - block.expr.as_ref().map_or(false, |e| is_relevant_expr(cx, tables, e)), + block + .expr + .as_ref() + .map_or(false, |e| is_relevant_expr(cx, typeck_results, e)), |stmt| match &stmt.kind { StmtKind::Local(_) => true, - StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, tables, expr), + StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, typeck_results, expr), _ => false, }, ) } -fn is_relevant_expr(cx: &LateContext<'_>, tables: &ty::TypeckTables<'_>, expr: &Expr<'_>) -> bool { +fn is_relevant_expr(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>, expr: &Expr<'_>) -> bool { match &expr.kind { - ExprKind::Block(block, _) => is_relevant_block(cx, tables, block), - ExprKind::Ret(Some(e)) => is_relevant_expr(cx, tables, e), + ExprKind::Block(block, _) => is_relevant_block(cx, typeck_results, block), + ExprKind::Ret(Some(e)) => is_relevant_expr(cx, typeck_results, e), ExprKind::Ret(None) | ExprKind::Break(_, None) => false, ExprKind::Call(path_expr, _) => { if let ExprKind::Path(qpath) = &path_expr.kind { - tables + typeck_results .qpath_res(qpath, path_expr.hir_id) .opt_def_id() .map_or(true, |fun_id| !match_def_path(cx, fun_id, &paths::BEGIN_PANIC)) diff --git a/clippy_lints/src/await_holding_lock.rs b/clippy_lints/src/await_holding_lock.rs index d337262dfa6e..b10b1e0a65ab 100644 --- a/clippy_lints/src/await_holding_lock.rs +++ b/clippy_lints/src/await_holding_lock.rs @@ -59,8 +59,8 @@ impl LateLintPass<'_> for AwaitHoldingLock { hir_id: body.value.hir_id, }; let def_id = cx.tcx.hir().body_owner_def_id(body_id); - let tables = cx.tcx.typeck_tables_of(def_id); - check_interior_types(cx, &tables.generator_interior_types, body.value.span); + let typeck_results = cx.tcx.typeck(def_id); + check_interior_types(cx, &typeck_results.generator_interior_types, body.value.span); } } } diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index d1d177e7a4ab..81a34021e8a0 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -319,7 +319,7 @@ fn check_ineffective_gt(cx: &LateContext<'_>, span: Span, m: u128, c: u128, op: } fn fetch_int_literal(cx: &LateContext<'_>, lit: &Expr<'_>) -> Option { - match constant(cx, cx.tables(), lit)?.0 { + match constant(cx, cx.typeck_results(), lit)?.0 { Constant::Int(n) => Some(n), _ => None, } diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 32d0979e99b6..18529f2113e7 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -111,8 +111,12 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> { match &e.kind { ExprKind::Unary(UnOp::UnNot, inner) => return Ok(Bool::Not(box self.run(inner)?)), ExprKind::Binary(binop, lhs, rhs) => match &binop.node { - BinOpKind::Or => return Ok(Bool::Or(self.extract(BinOpKind::Or, &[lhs, rhs], Vec::new())?)), - BinOpKind::And => return Ok(Bool::And(self.extract(BinOpKind::And, &[lhs, rhs], Vec::new())?)), + BinOpKind::Or => { + return Ok(Bool::Or(self.extract(BinOpKind::Or, &[lhs, rhs], Vec::new())?)); + }, + BinOpKind::And => { + return Ok(Bool::And(self.extract(BinOpKind::And, &[lhs, rhs], Vec::new())?)); + }, _ => (), }, ExprKind::Lit(lit) => match lit.node { @@ -248,7 +252,7 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { }) }, ExprKind::MethodCall(path, _, args, _) if args.len() == 1 => { - let type_of_receiver = cx.tables().expr_ty(&args[0]); + let type_of_receiver = cx.typeck_results().expr_ty(&args[0]); if !is_type_diagnostic_item(cx, type_of_receiver, sym!(option_type)) && !is_type_diagnostic_item(cx, type_of_receiver, sym!(result_type)) { @@ -450,7 +454,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { self.bool_expr(e) }, ExprKind::Unary(UnOp::UnNot, inner) => { - if self.cx.tables().node_types()[inner.hir_id].is_bool() { + if self.cx.typeck_results().node_types()[inner.hir_id].is_bool() { self.bool_expr(e); } else { walk_expr(self, e); @@ -465,7 +469,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { } fn implements_ord<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool { - let ty = cx.tables().expr_ty(expr); + let ty = cx.typeck_results().expr_ty(expr); get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[])) } diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index 1cdfea1f5265..dde799fcae4c 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount { if let ExprKind::Binary(ref op, ref l, ref r) = body.value.kind; if op.node == BinOpKind::Eq; if match_type(cx, - walk_ptrs_ty(cx.tables().expr_ty(&filter_args[0])), + walk_ptrs_ty(cx.typeck_results().expr_ty(&filter_args[0])), &paths::SLICE_ITER); then { let needle = match get_path_name(l) { @@ -63,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount { _ => { return; } } }; - if ty::Uint(UintTy::U8) != walk_ptrs_ty(cx.tables().expr_ty(needle)).kind { + if ty::Uint(UintTy::U8) != walk_ptrs_ty(cx.typeck_results().expr_ty(needle)).kind { return; } let haystack = if let ExprKind::MethodCall(ref path, _, ref args, _) = diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index 6bbdbe957cc8..14ef8c319eff 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -60,7 +60,7 @@ impl CognitiveComplexity { let mut helper = CCHelper { cc: 1, returns: 0 }; helper.visit_expr(expr); let CCHelper { cc, returns } = helper; - let ret_ty = cx.tables().node_type(expr.hir_id); + let ret_ty = cx.typeck_results().node_type(expr.hir_id); let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym!(result_type)) { returns } else { diff --git a/clippy_lints/src/comparison_chain.rs b/clippy_lints/src/comparison_chain.rs index 25ccabc1c883..99f161a0510f 100644 --- a/clippy_lints/src/comparison_chain.rs +++ b/clippy_lints/src/comparison_chain.rs @@ -99,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for ComparisonChain { } // Check that the type being compared implements `core::cmp::Ord` - let ty = cx.tables().expr_ty(lhs1); + let ty = cx.typeck_results().expr_ty(lhs1); let is_ord = get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[])); if !is_ord { diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index e6ef54f528f4..49ff86a205d9 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -174,12 +174,12 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option>) -> Constant { pub fn constant<'tcx>( lcx: &LateContext<'tcx>, - tables: &ty::TypeckTables<'tcx>, + typeck_results: &ty::TypeckResults<'tcx>, e: &Expr<'_>, ) -> Option<(Constant, bool)> { let mut cx = ConstEvalLateContext { lcx, - tables, + typeck_results, param_env: lcx.param_env, needed_resolution: false, substs: lcx.tcx.intern_substs(&[]), @@ -189,20 +189,20 @@ pub fn constant<'tcx>( pub fn constant_simple<'tcx>( lcx: &LateContext<'tcx>, - tables: &ty::TypeckTables<'tcx>, + typeck_results: &ty::TypeckResults<'tcx>, e: &Expr<'_>, ) -> Option { - constant(lcx, tables, e).and_then(|(cst, res)| if res { None } else { Some(cst) }) + constant(lcx, typeck_results, e).and_then(|(cst, res)| if res { None } else { Some(cst) }) } -/// Creates a `ConstEvalLateContext` from the given `LateContext` and `TypeckTables`. +/// Creates a `ConstEvalLateContext` from the given `LateContext` and `TypeckResults`. pub fn constant_context<'a, 'tcx>( lcx: &'a LateContext<'tcx>, - tables: &'a ty::TypeckTables<'tcx>, + typeck_results: &'a ty::TypeckResults<'tcx>, ) -> ConstEvalLateContext<'a, 'tcx> { ConstEvalLateContext { lcx, - tables, + typeck_results, param_env: lcx.param_env, needed_resolution: false, substs: lcx.tcx.intern_substs(&[]), @@ -211,7 +211,7 @@ pub fn constant_context<'a, 'tcx>( pub struct ConstEvalLateContext<'a, 'tcx> { lcx: &'a LateContext<'tcx>, - tables: &'a ty::TypeckTables<'tcx>, + typeck_results: &'a ty::TypeckResults<'tcx>, param_env: ty::ParamEnv<'tcx>, needed_resolution: bool, substs: SubstsRef<'tcx>, @@ -224,21 +224,21 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { return self.ifthenelse(cond, then, otherwise); } match e.kind { - ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id, self.tables.expr_ty(e)), + ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id, self.typeck_results.expr_ty(e)), ExprKind::Block(ref block, _) => self.block(block), - ExprKind::Lit(ref lit) => Some(lit_to_constant(&lit.node, self.tables.expr_ty_opt(e))), + ExprKind::Lit(ref lit) => Some(lit_to_constant(&lit.node, self.typeck_results.expr_ty_opt(e))), ExprKind::Array(ref vec) => self.multi(vec).map(Constant::Vec), ExprKind::Tup(ref tup) => self.multi(tup).map(Constant::Tuple), ExprKind::Repeat(ref value, _) => { - let n = match self.tables.expr_ty(e).kind { + let n = match self.typeck_results.expr_ty(e).kind { ty::Array(_, n) => n.try_eval_usize(self.lcx.tcx, self.lcx.param_env)?, _ => span_bug!(e.span, "typeck error"), }; self.expr(value).map(|v| Constant::Repeat(Box::new(v), n)) }, ExprKind::Unary(op, ref operand) => self.expr(operand).and_then(|o| match op { - UnOp::UnNot => self.constant_not(&o, self.tables.expr_ty(e)), - UnOp::UnNeg => self.constant_negate(&o, self.tables.expr_ty(e)), + UnOp::UnNot => self.constant_not(&o, self.typeck_results.expr_ty(e)), + UnOp::UnNeg => self.constant_negate(&o, self.typeck_results.expr_ty(e)), UnOp::UnDeref => Some(o), }), ExprKind::Binary(op, ref left, ref right) => self.binop(op, left, right), @@ -247,7 +247,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { if_chain! { if args.is_empty(); if let ExprKind::Path(qpath) = &callee.kind; - let res = self.tables.qpath_res(qpath, callee.hir_id); + let res = self.typeck_results.qpath_res(qpath, callee.hir_id); if let Some(def_id) = res.opt_def_id(); let def_path: Vec<_> = self.lcx.get_def_path(def_id).into_iter().map(Symbol::as_str).collect(); let def_path: Vec<&str> = def_path.iter().take(4).map(|s| &**s).collect(); @@ -319,10 +319,10 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { /// Lookup a possibly constant expression from a `ExprKind::Path`. fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'tcx>) -> Option { - let res = self.tables.qpath_res(qpath, id); + let res = self.typeck_results.qpath_res(qpath, id); match res { Res::Def(DefKind::Const | DefKind::AssocConst, def_id) => { - let substs = self.tables.node_substs(id); + let substs = self.typeck_results.node_substs(id); let substs = if self.substs.is_empty() { substs } else { @@ -332,7 +332,13 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let result = self .lcx .tcx - .const_eval_resolve(self.param_env, ty::WithOptConstParam::unknown(def_id), substs, None, None) + .const_eval_resolve( + self.param_env, + ty::WithOptConstParam::unknown(def_id), + substs, + None, + None, + ) .ok() .map(|val| rustc_middle::ty::Const::from_value(self.lcx.tcx, val, ty))?; let result = miri_to_const(&result); @@ -396,7 +402,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let l = self.expr(left)?; let r = self.expr(right); match (l, r) { - (Constant::Int(l), Some(Constant::Int(r))) => match self.tables.expr_ty_opt(left)?.kind { + (Constant::Int(l), Some(Constant::Int(r))) => match self.typeck_results.expr_ty_opt(left)?.kind { ty::Int(ity) => { let l = sext(self.lcx.tcx, l, ity); let r = sext(self.lcx.tcx, r, ity); @@ -488,23 +494,25 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { pub fn miri_to_const(result: &ty::Const<'_>) -> Option { use rustc_middle::mir::interpret::{ConstValue, Scalar}; match result.val { - ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data: d, .. })) => match result.ty.kind { - ty::Bool => Some(Constant::Bool(d == 1)), - ty::Uint(_) | ty::Int(_) => Some(Constant::Int(d)), - ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits( - d.try_into().expect("invalid f32 bit representation"), - ))), - ty::Float(FloatTy::F64) => Some(Constant::F64(f64::from_bits( - d.try_into().expect("invalid f64 bit representation"), - ))), - ty::RawPtr(type_and_mut) => { - if let ty::Uint(_) = type_and_mut.ty.kind { - return Some(Constant::RawPtr(d)); - } - None - }, - // FIXME: implement other conversions. - _ => None, + ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data: d, .. })) => { + match result.ty.kind { + ty::Bool => Some(Constant::Bool(d == 1)), + ty::Uint(_) | ty::Int(_) => Some(Constant::Int(d)), + ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits( + d.try_into().expect("invalid f32 bit representation"), + ))), + ty::Float(FloatTy::F64) => Some(Constant::F64(f64::from_bits( + d.try_into().expect("invalid f64 bit representation"), + ))), + ty::RawPtr(type_and_mut) => { + if let ty::Uint(_) = type_and_mut.ty.kind { + return Some(Constant::RawPtr(d)); + } + None + }, + // FIXME: implement other conversions. + _ => None, + } }, ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => match result.ty.kind { ty::Ref(_, tam, _) => match tam.kind { diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 1257032337ac..1f8bff8d71e0 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -320,7 +320,7 @@ fn bindings<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'_>) -> FxHashMap { if let Entry::Vacant(v) = map.entry(ident.name) { - v.insert(cx.tables().pat_ty(pat)); + v.insert(cx.typeck_results().pat_ty(pat)); } if let Some(ref as_pat) = *as_pat { bindings_impl(cx, as_pat, map); diff --git a/clippy_lints/src/default_trait_access.rs b/clippy_lints/src/default_trait_access.rs index fab95db01960..ea2447681293 100644 --- a/clippy_lints/src/default_trait_access.rs +++ b/clippy_lints/src/default_trait_access.rs @@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultTraitAccess { // TODO: Work out a way to put "whatever the imported way of referencing // this type in this file" rather than a fully-qualified type. - let expr_ty = cx.tables().expr_ty(expr); + let expr_ty = cx.typeck_results().expr_ty(expr); if let ty::Adt(..) = expr_ty.kind { let replacement = format!("{}::default()", expr_ty); span_lint_and_sugg( diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 323cad7fa1a8..102cf597d22e 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -74,7 +74,7 @@ fn lint_deref(cx: &LateContext<'_>, method_name: &str, call_expr: &Expr<'_>, var match method_name { "deref" => { let impls_deref_trait = cx.tcx.lang_items().deref_trait().map_or(false, |id| { - implements_trait(cx, cx.tables().expr_ty(&call_expr), id, &[]) + implements_trait(cx, cx.typeck_results().expr_ty(&call_expr), id, &[]) }); if impls_deref_trait { span_lint_and_sugg( @@ -90,7 +90,7 @@ fn lint_deref(cx: &LateContext<'_>, method_name: &str, call_expr: &Expr<'_>, var }, "deref_mut" => { let impls_deref_mut_trait = cx.tcx.lang_items().deref_mut_trait().map_or(false, |id| { - implements_trait(cx, cx.tables().expr_ty(&call_expr), id, &[]) + implements_trait(cx, cx.typeck_results().expr_ty(&call_expr), id, &[]) }); if impls_deref_mut_trait { span_lint_and_sugg( diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index dcf772572e8c..57ff569f14b0 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -119,7 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { let lint; let msg; let arg = &args[0]; - let arg_ty = cx.tables().expr_ty(arg); + let arg_ty = cx.typeck_results().expr_ty(arg); if let ty::Ref(..) = arg_ty.kind { if match_def_path(cx, def_id, &paths::DROP) { diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index 2ded375091c6..1dfb2eaa5797 100644 --- a/clippy_lints/src/duration_subsec.rs +++ b/clippy_lints/src/duration_subsec.rs @@ -43,8 +43,8 @@ impl<'tcx> LateLintPass<'tcx> for DurationSubsec { if_chain! { if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, ref left, ref right) = expr.kind; if let ExprKind::MethodCall(ref method_path, _ , ref args, _) = left.kind; - if match_type(cx, walk_ptrs_ty(cx.tables().expr_ty(&args[0])), &paths::DURATION); - if let Some((Constant::Int(divisor), _)) = constant(cx, cx.tables(), right); + if match_type(cx, walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0])), &paths::DURATION); + if let Some((Constant::Int(divisor), _)) = constant(cx, cx.typeck_results(), right); then { let suggested_fn = match (method_path.ident.as_str().as_ref(), divisor) { ("subsec_micros", 1_000) | ("subsec_nanos", 1_000_000) => "subsec_millis", diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 4d2e17933ed6..d616502a82a0 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -106,7 +106,7 @@ fn check_cond<'a>(cx: &LateContext<'_>, check: &'a Expr<'a>) -> Option<(&'static if let ExprKind::AddrOf(BorrowKind::Ref, _, ref key) = params[1].kind; then { let map = ¶ms[0]; - let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(map)); + let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(map)); return if match_type(cx, obj_ty, &paths::BTREEMAP) { Some(("BTreeMap", map, key)) diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 01eff28cb195..140cd21c34e6 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -103,8 +103,8 @@ impl<'tcx> LateLintPass<'tcx> for EqOp { (&ExprKind::Lit(..), _) | (_, &ExprKind::Lit(..)) => {}, // &foo == &bar (&ExprKind::AddrOf(BorrowKind::Ref, _, ref l), &ExprKind::AddrOf(BorrowKind::Ref, _, ref r)) => { - let lty = cx.tables().expr_ty(l); - let rty = cx.tables().expr_ty(r); + let lty = cx.typeck_results().expr_ty(l); + let rty = cx.typeck_results().expr_ty(r); let lcpy = is_copy(cx, lty); let rcpy = is_copy(cx, rty); // either operator autorefs or both args are copyable @@ -126,7 +126,7 @@ impl<'tcx> LateLintPass<'tcx> for EqOp { ) } else if lcpy && !rcpy - && implements_trait(cx, lty, trait_id, &[cx.tables().expr_ty(right).into()]) + && implements_trait(cx, lty, trait_id, &[cx.typeck_results().expr_ty(right).into()]) { span_lint_and_then( cx, @@ -145,7 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for EqOp { ) } else if !lcpy && rcpy - && implements_trait(cx, cx.tables().expr_ty(left), trait_id, &[rty.into()]) + && implements_trait(cx, cx.typeck_results().expr_ty(left), trait_id, &[rty.into()]) { span_lint_and_then( cx, @@ -166,10 +166,10 @@ impl<'tcx> LateLintPass<'tcx> for EqOp { }, // &foo == bar (&ExprKind::AddrOf(BorrowKind::Ref, _, ref l), _) => { - let lty = cx.tables().expr_ty(l); + let lty = cx.typeck_results().expr_ty(l); let lcpy = is_copy(cx, lty); if (requires_ref || lcpy) - && implements_trait(cx, lty, trait_id, &[cx.tables().expr_ty(right).into()]) + && implements_trait(cx, lty, trait_id, &[cx.typeck_results().expr_ty(right).into()]) { span_lint_and_then( cx, @@ -190,10 +190,10 @@ impl<'tcx> LateLintPass<'tcx> for EqOp { }, // foo == &bar (_, &ExprKind::AddrOf(BorrowKind::Ref, _, ref r)) => { - let rty = cx.tables().expr_ty(r); + let rty = cx.typeck_results().expr_ty(r); let rcpy = is_copy(cx, rty); if (requires_ref || rcpy) - && implements_trait(cx, cx.tables().expr_ty(left), trait_id, &[rty.into()]) + && implements_trait(cx, cx.typeck_results().expr_ty(left), trait_id, &[rty.into()]) { span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |diag| { let rsnip = snippet(cx, r.span, "...").to_string(); diff --git a/clippy_lints/src/erasing_op.rs b/clippy_lints/src/erasing_op.rs index 8a2683806182..dbd1ff514f0e 100644 --- a/clippy_lints/src/erasing_op.rs +++ b/clippy_lints/src/erasing_op.rs @@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for ErasingOp { } fn check(cx: &LateContext<'_>, e: &Expr<'_>, span: Span) { - if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables(), e) { + if let Some(Constant::Int(0)) = constant_simple(cx, cx.typeck_results(), e) { span_lint( cx, ERASING_OP, diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index ceb3c40d869a..82549c12d0a2 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { let fn_def_id = cx.tcx.hir().local_def_id(hir_id); cx.tcx.infer_ctxt().enter(|infcx| { - ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.tables()).consume_body(body); + ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body); }); for node in v.set { diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index fb26b9fc27d2..87254c1dbc49 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -97,7 +97,7 @@ fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) { // Are the expression or the arguments type-adjusted? Then we need the closure if !(is_adjusted(cx, ex) || args.iter().any(|arg| is_adjusted(cx, arg))); - let fn_ty = cx.tables().expr_ty(caller); + let fn_ty = cx.typeck_results().expr_ty(caller); if matches!(fn_ty.kind, ty::FnDef(_, _) | ty::FnPtr(_) | ty::Closure(_, _)); @@ -128,7 +128,7 @@ fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) { // Are the expression or the arguments type-adjusted? Then we need the closure if !(is_adjusted(cx, ex) || args.iter().skip(1).any(|arg| is_adjusted(cx, arg))); - let method_def_id = cx.tables().type_dependent_def_id(ex.hir_id).unwrap(); + let method_def_id = cx.typeck_results().type_dependent_def_id(ex.hir_id).unwrap(); if !type_is_unsafe_function(cx, cx.tcx.type_of(method_def_id)); if compare_inputs(&mut iter_input_pats(decl, body), &mut args.iter()); @@ -153,7 +153,7 @@ fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) { /// Tries to determine the type for universal function call to be used instead of the closure fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: def_id::DefId, self_arg: &Expr<'_>) -> Option { let expected_type_of_self = &cx.tcx.fn_sig(method_def_id).inputs_and_output().skip_binder()[0]; - let actual_type_of_self = &cx.tables().node_type(self_arg.hir_id); + let actual_type_of_self = &cx.typeck_results().node_type(self_arg.hir_id); if let Some(trait_id) = cx.tcx.trait_of_item(method_def_id) { if match_borrow_depth(expected_type_of_self, &actual_type_of_self) diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 01b0d3c5edec..c00638ecc0c1 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -137,7 +137,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { match e.kind { ExprKind::Continue(_) | ExprKind::Break(_, _) | ExprKind::Ret(_) => self.report_diverging_sub_expr(e), ExprKind::Call(ref func, _) => { - let typ = self.cx.tables().expr_ty(func); + let typ = self.cx.typeck_results().expr_ty(func); match typ.kind { ty::FnDef(..) | ty::FnPtr(_) => { let sig = typ.fn_sig(self.cx.tcx); @@ -149,7 +149,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { } }, ExprKind::MethodCall(..) => { - let borrowed_table = self.cx.tables(); + let borrowed_table = self.cx.typeck_results(); if borrowed_table.expr_ty(e).is_never() { self.report_diverging_sub_expr(e); } diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 01ed0c426d43..000762334f61 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -73,7 +73,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h struct FindPanicUnwrap<'a, 'tcx> { lcx: &'a LateContext<'tcx>, - tables: &'tcx ty::TypeckTables<'tcx>, + typeck_results: &'tcx ty::TypeckResults<'tcx>, result: Vec, } @@ -96,7 +96,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h // check for `unwrap` if let Some(arglists) = method_chain_args(expr, &["unwrap"]) { - let reciever_ty = walk_ptrs_ty(self.tables.expr_ty(&arglists[0][0])); + let reciever_ty = walk_ptrs_ty(self.typeck_results.expr_ty(&arglists[0][0])); if is_type_diagnostic_item(self.lcx, reciever_ty, sym!(option_type)) || is_type_diagnostic_item(self.lcx, reciever_ty, sym!(result_type)) { @@ -124,7 +124,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.id.hir_id); let mut fpu = FindPanicUnwrap { lcx: cx, - tables: cx.tcx.typeck_tables_of(impl_item_def_id), + typeck_results: cx.tcx.typeck(impl_item_def_id), result: Vec::new(), }; fpu.visit_expr(&body.value); diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index a3d2a949535a..358b9f6dcd0a 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -61,7 +61,7 @@ declare_lint_pass!(FloatLiteral => [EXCESSIVE_PRECISION, LOSSY_FLOAT_LITERAL]); impl<'tcx> LateLintPass<'tcx> for FloatLiteral { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if_chain! { - let ty = cx.tables().expr_ty(expr); + let ty = cx.typeck_results().expr_ty(expr); if let ty::Float(fty) = ty.kind; if let hir::ExprKind::Lit(ref lit) = expr.kind; if let LitKind::Float(sym, lit_float_ty) = lit.node; diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index 3087d6a940a8..93f6ec92ec71 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -112,7 +112,7 @@ declare_lint_pass!(FloatingPointArithmetic => [ // Returns the specialized log method for a given base if base is constant // and is one of 2, 10 and e fn get_specialized_log_method(cx: &LateContext<'_>, base: &Expr<'_>) -> Option<&'static str> { - if let Some((value, _)) = constant(cx, cx.tables(), base) { + if let Some((value, _)) = constant(cx, cx.typeck_results(), base) { if F32(2.0) == value || F64(2.0) == value { return Some("log2"); } else if F32(10.0) == value || F64(10.0) == value { @@ -136,7 +136,7 @@ fn prepare_receiver_sugg<'a>(cx: &LateContext<'_>, mut expr: &'a Expr<'a>) -> Su if_chain! { // if the expression is a float literal and it is unsuffixed then // add a suffix so the suggestion is valid and unambiguous - if let ty::Float(float_ty) = cx.tables().expr_ty(expr).kind; + if let ty::Float(float_ty) = cx.typeck_results().expr_ty(expr).kind; if let ExprKind::Lit(lit) = &expr.kind; if let ast::LitKind::Float(sym, ast::LitFloatType::Unsuffixed) = lit.node; then { @@ -188,7 +188,10 @@ fn check_ln1p(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { rhs, ) = &args[0].kind { - let recv = match (constant(cx, cx.tables(), lhs), constant(cx, cx.tables(), rhs)) { + let recv = match ( + constant(cx, cx.typeck_results(), lhs), + constant(cx, cx.typeck_results(), rhs), + ) { (Some((value, _)), _) if F32(1.0) == value || F64(1.0) == value => rhs, (_, Some((value, _))) if F32(1.0) == value || F64(1.0) == value => lhs, _ => return, @@ -233,7 +236,7 @@ fn get_integer_from_float_constant(value: &Constant) -> Option { fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { // Check receiver - if let Some((value, _)) = constant(cx, cx.tables(), &args[0]) { + if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[0]) { let method = if F32(f32_consts::E) == value || F64(f64_consts::E) == value { "exp" } else if F32(2.0) == value || F64(2.0) == value { @@ -254,7 +257,7 @@ fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { } // Check argument - if let Some((value, _)) = constant(cx, cx.tables(), &args[1]) { + if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[1]) { let (lint, help, suggestion) = if F32(1.0 / 2.0) == value || F64(1.0 / 2.0) == value { ( SUBOPTIMAL_FLOPS, @@ -294,7 +297,7 @@ fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { } fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { - if let Some((value, _)) = constant(cx, cx.tables(), &args[1]) { + if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[1]) { if value == Int(2) { if let Some(parent) = get_parent_expr(cx, expr) { if let Some(grandparent) = get_parent_expr(cx, parent) { @@ -382,8 +385,8 @@ fn detect_hypot(cx: &LateContext<'_>, args: &[Expr<'_>]) -> Option { _ ) = add_rhs.kind; if lmethod_name.as_str() == "powi" && rmethod_name.as_str() == "powi"; - if let Some((lvalue, _)) = constant(cx, cx.tables(), &largs[1]); - if let Some((rvalue, _)) = constant(cx, cx.tables(), &rargs[1]); + if let Some((lvalue, _)) = constant(cx, cx.typeck_results(), &largs[1]); + if let Some((rvalue, _)) = constant(cx, cx.typeck_results(), &rargs[1]); if Int(2) == lvalue && Int(2) == rvalue; then { return Some(format!("{}.hypot({})", Sugg::hir(cx, &largs[0], ".."), Sugg::hir(cx, &rargs[0], ".."))); @@ -413,11 +416,11 @@ fn check_hypot(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { fn check_expm1(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Binary(Spanned { node: BinOpKind::Sub, .. }, ref lhs, ref rhs) = expr.kind; - if cx.tables().expr_ty(lhs).is_floating_point(); - if let Some((value, _)) = constant(cx, cx.tables(), rhs); + if cx.typeck_results().expr_ty(lhs).is_floating_point(); + if let Some((value, _)) = constant(cx, cx.typeck_results(), rhs); if F32(1.0) == value || F64(1.0) == value; if let ExprKind::MethodCall(ref path, _, ref method_args, _) = lhs.kind; - if cx.tables().expr_ty(&method_args[0]).is_floating_point(); + if cx.typeck_results().expr_ty(&method_args[0]).is_floating_point(); if path.ident.name.as_str() == "exp"; then { span_lint_and_sugg( @@ -439,8 +442,8 @@ fn check_expm1(cx: &LateContext<'_>, expr: &Expr<'_>) { fn is_float_mul_expr<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(&'a Expr<'a>, &'a Expr<'a>)> { if_chain! { if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, ref lhs, ref rhs) = &expr.kind; - if cx.tables().expr_ty(lhs).is_floating_point(); - if cx.tables().expr_ty(rhs).is_floating_point(); + if cx.typeck_results().expr_ty(lhs).is_floating_point(); + if cx.typeck_results().expr_ty(rhs).is_floating_point(); then { return Some((lhs, rhs)); } @@ -527,7 +530,7 @@ fn are_exprs_equal(cx: &LateContext<'_>, expr1: &Expr<'_>, expr2: &Expr<'_>) -> /// Returns true iff expr is some zero literal fn is_zero(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - match constant_simple(cx, cx.tables(), expr) { + match constant_simple(cx, cx.typeck_results(), expr) { Some(Constant::Int(i)) => i == 0, Some(Constant::F32(f)) => f == 0.0, Some(Constant::F64(f)) => f == 0.0, @@ -662,8 +665,8 @@ fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) { mul_lhs, mul_rhs, ) = &div_lhs.kind; - if let Some((rvalue, _)) = constant(cx, cx.tables(), div_rhs); - if let Some((lvalue, _)) = constant(cx, cx.tables(), mul_rhs); + if let Some((rvalue, _)) = constant(cx, cx.typeck_results(), div_rhs); + if let Some((lvalue, _)) = constant(cx, cx.typeck_results(), mul_rhs); then { // TODO: also check for constant values near PI/180 or 180/PI if (F32(f32_consts::PI) == rvalue || F64(f64_consts::PI) == rvalue) && @@ -699,7 +702,7 @@ fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) { impl<'tcx> LateLintPass<'tcx> for FloatingPointArithmetic { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::MethodCall(ref path, _, args, _) = &expr.kind { - let recv_ty = cx.tables().expr_ty(&args[0]); + let recv_ty = cx.typeck_results().expr_ty(&args[0]); if recv_ty.is_floating_point() { match &*path.ident.name.as_str() { diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 33b6bfc459f9..572c839502f4 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -90,7 +90,7 @@ fn on_argumentv1_new<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arms: & if let PatKind::Tuple(ref pats, None) = arms[0].pat.kind; if pats.len() == 1; then { - let ty = walk_ptrs_ty(cx.tables().pat_ty(&pats[0])); + let ty = walk_ptrs_ty(cx.typeck_results().pat_ty(&pats[0])); if ty.kind != rustc_middle::ty::Str && !is_type_diagnostic_item(cx, ty, sym!(string_type)) { return None; } diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 63133a4872a3..3ee0b3f74b8c 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -392,11 +392,11 @@ impl<'tcx> Functions { .collect::>(); if !raw_ptrs.is_empty() { - let tables = cx.tcx.body_tables(body.id()); + let typeck_results = cx.tcx.typeck_body(body.id()); let mut v = DerefVisitor { cx, ptrs: raw_ptrs, - tables, + typeck_results, }; intravisit::walk_expr(&mut v, expr); @@ -494,13 +494,8 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut FxHashSet< return false; // ignore `_` patterns } let def_id = pat.hir_id.owner.to_def_id(); - if cx.tcx.has_typeck_tables(def_id) { - is_mutable_ty( - cx, - &cx.tcx.typeck_tables_of(def_id.expect_local()).pat_ty(pat), - pat.span, - tys, - ) + if cx.tcx.has_typeck_results(def_id) { + is_mutable_ty(cx, &cx.tcx.typeck(def_id.expect_local()).pat_ty(pat), pat.span, tys) } else { false } @@ -539,7 +534,7 @@ fn raw_ptr_arg(arg: &hir::Param<'_>, ty: &hir::Ty<'_>) -> Option { struct DerefVisitor<'a, 'tcx> { cx: &'a LateContext<'tcx>, ptrs: FxHashSet, - tables: &'a ty::TypeckTables<'tcx>, + typeck_results: &'a ty::TypeckResults<'tcx>, } impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { @@ -548,7 +543,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { match expr.kind { hir::ExprKind::Call(ref f, args) => { - let ty = self.tables.expr_ty(f); + let ty = self.typeck_results.expr_ty(f); if type_is_unsafe_function(self.cx, ty) { for arg in args { @@ -557,7 +552,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { } }, hir::ExprKind::MethodCall(_, _, args, _) => { - let def_id = self.tables.type_dependent_def_id(expr.hir_id).unwrap(); + let def_id = self.typeck_results.type_dependent_def_id(expr.hir_id).unwrap(); let base_type = self.cx.tcx.type_of(def_id); if type_is_unsafe_function(self.cx, base_type) { @@ -614,10 +609,10 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { let mut tys = FxHashSet::default(); for arg in args { let def_id = arg.hir_id.owner.to_def_id(); - if self.cx.tcx.has_typeck_tables(def_id) + if self.cx.tcx.has_typeck_results(def_id) && is_mutable_ty( self.cx, - self.cx.tcx.typeck_tables_of(def_id.expect_local()).expr_ty(arg), + self.cx.tcx.typeck(def_id.expect_local()).expr_ty(arg), arg.span, &mut tys, ) diff --git a/clippy_lints/src/get_last_with_len.rs b/clippy_lints/src/get_last_with_len.rs index 2d93ecc00a76..48ebcf5ebcd9 100644 --- a/clippy_lints/src/get_last_with_len.rs +++ b/clippy_lints/src/get_last_with_len.rs @@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for GetLastWithLen { // Argument 0 (the struct we're calling the method on) is a vector if let Some(struct_calling_on) = args.get(0); - let struct_ty = cx.tables().expr_ty(struct_calling_on); + let struct_ty = cx.typeck_results().expr_ty(struct_calling_on); if is_type_diagnostic_item(cx, struct_ty, sym!(vec_type)); // Argument to "get" is a subtraction diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs index dc9d636bc6de..4c62637858cd 100644 --- a/clippy_lints/src/identity_op.rs +++ b/clippy_lints/src/identity_op.rs @@ -62,8 +62,8 @@ fn is_allowed(cx: &LateContext<'_>, cmp: BinOp, left: &Expr<'_>, right: &Expr<'_ // `1 << 0` is a common pattern in bit manipulation code if_chain! { if let BinOpKind::Shl = cmp.node; - if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables(), right); - if let Some(Constant::Int(1)) = constant_simple(cx, cx.tables(), left); + if let Some(Constant::Int(0)) = constant_simple(cx, cx.typeck_results(), right); + if let Some(Constant::Int(1)) = constant_simple(cx, cx.typeck_results(), left); then { return true; } @@ -74,8 +74,8 @@ fn is_allowed(cx: &LateContext<'_>, cmp: BinOp, left: &Expr<'_>, right: &Expr<'_ #[allow(clippy::cast_possible_wrap)] fn check(cx: &LateContext<'_>, e: &Expr<'_>, m: i8, span: Span, arg: Span) { - if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables(), e) { - let check = match cx.tables().expr_ty(e).kind { + if let Some(Constant::Int(v)) = constant_simple(cx, cx.typeck_results(), e) { + let check = match cx.typeck_results().expr_ty(e).kind { ty::Int(ity) => unsext(cx.tcx, -1_i128, ity), ty::Uint(uty) => clip(cx.tcx, !0, uty), _ => return, diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index fbd2eeacc6ef..2e55094d90c6 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -146,7 +146,7 @@ fn is_mutex_lock_call<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Opt if_chain! { if let ExprKind::MethodCall(path, _span, args, _) = &expr.kind; if path.ident.to_string() == "lock"; - let ty = cx.tables().expr_ty(&args[0]); + let ty = cx.typeck_results().expr_ty(&args[0]); if is_type_diagnostic_item(cx, ty, sym!(mutex_type)); then { Some(&args[0]) diff --git a/clippy_lints/src/if_let_some_result.rs b/clippy_lints/src/if_let_some_result.rs index 9e2989dc01e5..5b22df5fe491 100644 --- a/clippy_lints/src/if_let_some_result.rs +++ b/clippy_lints/src/if_let_some_result.rs @@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for OkIfLet { if let ExprKind::MethodCall(_, ok_span, ref result_types, _) = op.kind; //check is expr.ok() has type Result.ok(, _) if let PatKind::TupleStruct(QPath::Resolved(_, ref x), ref y, _) = body[0].pat.kind; //get operation if method_chain_args(op, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized; - if is_type_diagnostic_item(cx, cx.tables().expr_ty(&result_types[0]), sym!(result_type)); + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&result_types[0]), sym!(result_type)); if rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(x, false)) == "Some"; then { diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index f38530aca0ce..5f931a0added 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -81,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { }; // Check if the variable in the condition statement is an integer - if !cx.tables().expr_ty(cond_var).is_integral() { + if !cx.typeck_results().expr_ty(cond_var).is_integral() { return; } @@ -93,7 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { ExprKind::Lit(ref cond_lit) => { // Check if the constant is zero if let LitKind::Int(0, _) = cond_lit.node { - if cx.tables().expr_ty(cond_left).is_signed() { + if cx.typeck_results().expr_ty(cond_left).is_signed() { } else { print_lint_and_sugg(cx, &var_name, expr); }; diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index 5857a405b0cf..a1f58e54ae38 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -88,7 +88,7 @@ declare_lint_pass!(IndexingSlicing => [INDEXING_SLICING, OUT_OF_BOUNDS_INDEXING] impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Index(ref array, ref index) = &expr.kind { - let ty = cx.tables().expr_ty(array); + let ty = cx.typeck_results().expr_ty(array); if let Some(range) = higher::range(cx, index) { // Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..] if let ty::Array(_, s) = ty.kind { @@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { // Catchall non-range index, i.e., [n] or [n << m] if let ty::Array(..) = ty.kind { // Index is a constant uint. - if let Some(..) = constant(cx, cx.tables(), index) { + if let Some(..) = constant(cx, cx.typeck_results(), index) { // Let rustc's `const_err` lint handle constant `usize` indexing on arrays. return; } @@ -169,14 +169,18 @@ fn to_const_range<'tcx>( range: higher::Range<'_>, array_size: u128, ) -> (Option, Option) { - let s = range.start.map(|expr| constant(cx, cx.tables(), expr).map(|(c, _)| c)); + let s = range + .start + .map(|expr| constant(cx, cx.typeck_results(), expr).map(|(c, _)| c)); let start = match s { Some(Some(Constant::Int(x))) => Some(x), Some(_) => None, None => Some(0), }; - let e = range.end.map(|expr| constant(cx, cx.tables(), expr).map(|(c, _)| c)); + let e = range + .end + .map(|expr| constant(cx, cx.typeck_results(), expr).map(|(c, _)| c)); let end = match e { Some(Some(Constant::Int(x))) => { if range.limits == RangeLimits::Closed { diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index 3ffc2dd60d9c..e511d3ea3304 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -231,13 +231,13 @@ fn complete_infinite_iter(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { } if method.ident.name == sym!(last) && args.len() == 1 { let not_double_ended = get_trait_def_id(cx, &paths::DOUBLE_ENDED_ITERATOR).map_or(false, |id| { - !implements_trait(cx, cx.tables().expr_ty(&args[0]), id, &[]) + !implements_trait(cx, cx.typeck_results().expr_ty(&args[0]), id, &[]) }); if not_double_ended { return is_infinite(cx, &args[0]); } } else if method.ident.name == sym!(collect) { - let ty = cx.tables().expr_ty(expr); + let ty = cx.typeck_results().expr_ty(expr); if INFINITE_COLLECTORS.iter().any(|path| match_type(cx, ty, path)) { return is_infinite(cx, &args[0]); } diff --git a/clippy_lints/src/integer_division.rs b/clippy_lints/src/integer_division.rs index e754c7b482a6..31181c10d23d 100644 --- a/clippy_lints/src/integer_division.rs +++ b/clippy_lints/src/integer_division.rs @@ -50,7 +50,7 @@ fn is_integer_division<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) if let hir::ExprKind::Binary(binop, left, right) = &expr.kind; if let hir::BinOpKind::Div = &binop.node; then { - let (left_ty, right_ty) = (cx.tables().expr_ty(left), cx.tables().expr_ty(right)); + let (left_ty, right_ty) = (cx.typeck_results().expr_ty(left), cx.typeck_results().expr_ty(right)); return left_ty.is_integral() && right_ty.is_integral(); } } diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index 8eb986c25ff7..a7c715879232 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -42,7 +42,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Repeat(_, _) = expr.kind; - if let ty::Array(element_type, cst) = cx.tables().expr_ty(expr).kind; + if let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind; if let ConstKind::Value(val) = cst.val; if let ConstValue::Scalar(element_count) = val; if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx); diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 1b09328ceabb..00d0b8b4e5b7 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -300,7 +300,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { return false; } - let ty = &walk_ptrs_ty(cx.tables().expr_ty(expr)); + let ty = &walk_ptrs_ty(cx.typeck_results().expr_ty(expr)); match ty.kind { ty::Dynamic(ref tt, ..) => tt.principal().map_or(false, |principal| { cx.tcx diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 706c73ce66c6..8243b0a29bc6 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -73,7 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq { then { let span = stmt.span.to(if_.span); - let has_interior_mutability = !cx.tables().node_type(canonical_id).is_freeze( + let has_interior_mutability = !cx.typeck_results().node_type(canonical_id).is_freeze( cx.tcx.at(span), cx.param_env, ); diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index c7dda3c99282..ae2f6131b5b8 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore { if let PatKind::Wild = local.pat.kind; if let Some(ref init) = local.init; then { - let init_ty = cx.tables().expr_ty(init); + let init_ty = cx.typeck_results().expr_ty(init); let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() { GenericArgKind::Type(inner_ty) => { SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path)) @@ -94,7 +94,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore { "consider using an underscore-prefixed named \ binding or dropping explicitly with `std::mem::drop`" ) - } else if is_must_use_ty(cx, cx.tables().expr_ty(init)) { + } else if is_must_use_ty(cx, cx.typeck_results().expr_ty(init)) { span_lint_and_help( cx, LET_UNDERSCORE_MUST_USE, diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 396bb6591090..7e3876ff49b4 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -535,7 +535,7 @@ impl<'tcx> LateLintPass<'tcx> for Loops { if_chain! { if let ExprKind::MethodCall(..) | ExprKind::Call(..) = iter_expr.kind; if let Some(iter_def_id) = get_trait_def_id(cx, &paths::ITERATOR); - if implements_trait(cx, cx.tables().expr_ty(iter_expr), iter_def_id, &[]); + if implements_trait(cx, cx.typeck_results().expr_ty(iter_expr), iter_def_id, &[]); then { return; } @@ -981,8 +981,8 @@ fn detect_manual_memcpy<'tcx>( if_chain! { if let ExprKind::Index(seqexpr_left, idx_left) = lhs.kind; if let ExprKind::Index(seqexpr_right, idx_right) = rhs.kind; - if is_slice_like(cx, cx.tables().expr_ty(seqexpr_left)) - && is_slice_like(cx, cx.tables().expr_ty(seqexpr_right)); + if is_slice_like(cx, cx.typeck_results().expr_ty(seqexpr_left)) + && is_slice_like(cx, cx.typeck_results().expr_ty(seqexpr_right)); if let Some(offset_left) = get_offset(cx, &idx_left, canonical_id); if let Some(offset_right) = get_offset(cx, &idx_right, canonical_id); @@ -1250,8 +1250,8 @@ fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, expr: lint_iter_method(cx, args, arg, method_name); } } else if method_name == "into_iter" && match_trait_method(cx, arg, &paths::INTO_ITERATOR) { - let receiver_ty = cx.tables().expr_ty(&args[0]); - let receiver_ty_adjusted = cx.tables().expr_ty_adjusted(&args[0]); + let receiver_ty = cx.typeck_results().expr_ty(&args[0]); + let receiver_ty_adjusted = cx.typeck_results().expr_ty_adjusted(&args[0]); if TyS::same_type(receiver_ty, receiver_ty_adjusted) { let mut applicability = Applicability::MachineApplicable; let object = snippet_with_applicability(cx, args[0].span, "_", &mut applicability); @@ -1296,7 +1296,7 @@ fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, expr: /// Checks for `for` loops over `Option`s and `Result`s. fn check_arg_type(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) { - let ty = cx.tables().expr_ty(arg); + let ty = cx.typeck_results().expr_ty(arg); if is_type_diagnostic_item(cx, ty, sym!(option_type)) { span_lint_and_help( cx, @@ -1400,8 +1400,9 @@ fn check_for_loop_explicit_counter<'tcx>( /// If `arg` was the argument to a `for` loop, return the "cleanest" way of writing the /// actual `Iterator` that the loop uses. fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic_ref: &mut Applicability) -> String { - let impls_iterator = get_trait_def_id(cx, &paths::ITERATOR) - .map_or(false, |id| implements_trait(cx, cx.tables().expr_ty(arg), id, &[])); + let impls_iterator = get_trait_def_id(cx, &paths::ITERATOR).map_or(false, |id| { + implements_trait(cx, cx.typeck_results().expr_ty(arg), id, &[]) + }); if impls_iterator { format!( "{}", @@ -1412,7 +1413,7 @@ fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic_ref: &mut // (&mut x).into_iter() ==> x.iter_mut() match &arg.kind { ExprKind::AddrOf(BorrowKind::Ref, mutability, arg_inner) - if has_iter_method(cx, cx.tables().expr_ty(&arg_inner)).is_some() => + if has_iter_method(cx, cx.typeck_results().expr_ty(&arg_inner)).is_some() => { let meth_name = match mutability { Mutability::Mut => "iter_mut", @@ -1445,7 +1446,7 @@ fn check_for_loop_over_map_kv<'tcx>( if let PatKind::Tuple(ref pat, _) = pat.kind { if pat.len() == 2 { let arg_span = arg.span; - let (new_pat_span, kind, ty, mutbl) = match cx.tables().expr_ty(arg).kind { + let (new_pat_span, kind, ty, mutbl) = match cx.typeck_results().expr_ty(arg).kind { ty::Ref(_, ty, mutbl) => match (&pat[0].kind, &pat[1].kind) { (key, _) if pat_is_wild(key, body) => (pat[1].span, "value", ty, mutbl), (_, value) if pat_is_wild(value, body) => (pat[0].span, "key", ty, Mutability::Not), @@ -1590,7 +1591,14 @@ fn check_for_mutation<'tcx>( }; let def_id = body.hir_id.owner.to_def_id(); cx.tcx.infer_ctxt().enter(|infcx| { - ExprUseVisitor::new(&mut delegate, &infcx, def_id.expect_local(), cx.param_env, cx.tables()).walk_expr(body); + ExprUseVisitor::new( + &mut delegate, + &infcx, + def_id.expect_local(), + cx.param_env, + cx.typeck_results(), + ) + .walk_expr(body); }); delegate.mutation_span() } @@ -1684,7 +1692,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { if index_used_directly { self.indexed_directly.insert( seqvar.segments[0].ident.name, - (Some(extent), self.cx.tables().node_type(seqexpr.hir_id)), + (Some(extent), self.cx.typeck_results().node_type(seqexpr.hir_id)), ); } return false; // no need to walk further *on the variable* @@ -1696,7 +1704,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { if index_used_directly { self.indexed_directly.insert( seqvar.segments[0].ident.name, - (None, self.cx.tables().node_type(seqexpr.hir_id)), + (None, self.cx.typeck_results().node_type(seqexpr.hir_id)), ); } return false; // no need to walk further *on the variable* @@ -1764,7 +1772,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { ExprKind::Call(ref f, args) => { self.visit_expr(f); for expr in args { - let ty = self.cx.tables().expr_ty_adjusted(expr); + let ty = self.cx.typeck_results().expr_ty_adjusted(expr); self.prefer_mutable = false; if let ty::Ref(_, _, mutbl) = ty.kind { if mutbl == Mutability::Mut { @@ -1775,7 +1783,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { } }, ExprKind::MethodCall(_, _, args, _) => { - let def_id = self.cx.tables().type_dependent_def_id(expr.hir_id).unwrap(); + let def_id = self.cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap(); for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) { self.prefer_mutable = false; if let ty::Ref(_, _, mutbl) = ty.kind { @@ -1862,7 +1870,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> { fn is_ref_iterable_type(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { // no walk_ptrs_ty: calling iter() on a reference can make sense because it // will allow further borrows afterwards - let ty = cx.tables().expr_ty(e); + let ty = cx.typeck_results().expr_ty(e); is_iterable_array(ty, cx) || is_type_diagnostic_item(cx, ty, sym!(vec_type)) || match_type(cx, ty, &paths::LINKED_LIST) || @@ -2221,7 +2229,7 @@ fn path_name(e: &Expr<'_>) -> Option { } fn check_infinite_loop<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) { - if constant(cx, cx.tables(), cond).is_some() { + if constant(cx, cx.typeck_results(), cond).is_some() { // A pure constant condition (e.g., `while false`) is not linted. return; } @@ -2357,7 +2365,7 @@ fn check_needless_collect<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) { if let Some(ref generic_args) = chain_method.args; if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0); then { - let ty = cx.tables().node_type(ty.hir_id); + let ty = cx.typeck_results().node_type(ty.hir_id); if is_type_diagnostic_item(cx, ty, sym!(vec_type)) || is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) || match_type(cx, ty, &paths::BTREEMAP) || diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 905a3f3ca71c..641e6a170432 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -52,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone { if let hir::ExprKind::MethodCall(ref method, _, ref args, _) = e.kind; if args.len() == 2; if method.ident.as_str() == "map"; - let ty = cx.tables().expr_ty(&args[0]); + let ty = cx.typeck_results().expr_ty(&args[0]); if is_type_diagnostic_item(cx, ty, sym!(option_type)) || match_trait_method(cx, e, &paths::ITERATOR); if let hir::ExprKind::Closure(_, _, body_id, _, _) = args[1].kind; let closure_body = cx.tcx.hir().body(body_id); @@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone { match closure_expr.kind { hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner) => { if ident_eq(name, inner) { - if let ty::Ref(.., Mutability::Not) = cx.tables().expr_ty(inner).kind { + if let ty::Ref(.., Mutability::Not) = cx.typeck_results().expr_ty(inner).kind { lint(cx, e.span, args[0].span, true); } } @@ -79,7 +79,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone { if ident_eq(name, &obj[0]) && method.ident.as_str() == "clone" && match_trait_method(cx, closure_expr, &paths::CLONE_TRAIT) { - let obj_ty = cx.tables().expr_ty(&obj[0]); + let obj_ty = cx.typeck_results().expr_ty(&obj[0]); if let ty::Ref(_, ty, _) = obj_ty.kind { let copy = is_copy(cx, ty); lint(cx, e.span, args[0].span, copy); diff --git a/clippy_lints/src/map_identity.rs b/clippy_lints/src/map_identity.rs index 24ec78c88464..d4c2e66ff4b1 100644 --- a/clippy_lints/src/map_identity.rs +++ b/clippy_lints/src/map_identity.rs @@ -63,7 +63,7 @@ fn get_map_argument<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<&'a if_chain! { if let ExprKind::MethodCall(ref method, _, ref args, _) = expr.kind; if args.len() == 2 && method.ident.as_str() == "map"; - let caller_ty = cx.tables().expr_ty(&args[0]); + let caller_ty = cx.typeck_results().expr_ty(&args[0]); if match_trait_method(cx, expr, &paths::ITERATOR) || is_type_diagnostic_item(cx, caller_ty, sym!(result_type)) || is_type_diagnostic_item(cx, caller_ty, sym!(option_type)); @@ -119,7 +119,7 @@ fn is_body_identity_function(cx: &LateContext<'_>, func: &Body<'_>) -> bool { /// Returns true iff an expression returns the same thing as a parameter's pattern fn match_expr_param(cx: &LateContext<'_>, expr: &Expr<'_>, pat: &Pat<'_>) -> bool { if let PatKind::Binding(_, _, ident, _) = pat.kind { - match_var(expr, ident.name) && !(cx.tables().hir_owner == expr.hir_id.owner && is_adjusted(cx, expr)) + match_var(expr, ident.name) && !(cx.typeck_results().hir_owner == expr.hir_id.owner && is_adjusted(cx, expr)) } else { false } diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 316a71c50051..198251c58ddc 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -101,7 +101,7 @@ fn is_unit_type(ty: Ty<'_>) -> bool { } fn is_unit_function(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { - let ty = cx.tables().expr_ty(expr); + let ty = cx.typeck_results().expr_ty(expr); if let ty::FnDef(id, _) = ty.kind { if let Some(fn_type) = cx.tcx.fn_sig(id).no_bound_vars() { @@ -112,7 +112,7 @@ fn is_unit_function(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { } fn is_unit_expression(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { - is_unit_type(cx.tables().expr_ty(expr)) + is_unit_type(cx.typeck_results().expr_ty(expr)) } /// The expression inside a closure may or may not have surrounding braces and @@ -205,13 +205,14 @@ fn suggestion_msg(function_type: &str, map_type: &str) -> String { fn lint_map_unit_fn(cx: &LateContext<'_>, stmt: &hir::Stmt<'_>, expr: &hir::Expr<'_>, map_args: &[hir::Expr<'_>]) { let var_arg = &map_args[0]; - let (map_type, variant, lint) = if is_type_diagnostic_item(cx, cx.tables().expr_ty(var_arg), sym!(option_type)) { - ("Option", "Some", OPTION_MAP_UNIT_FN) - } else if is_type_diagnostic_item(cx, cx.tables().expr_ty(var_arg), sym!(result_type)) { - ("Result", "Ok", RESULT_MAP_UNIT_FN) - } else { - return; - }; + let (map_type, variant, lint) = + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(var_arg), sym!(option_type)) { + ("Option", "Some", OPTION_MAP_UNIT_FN) + } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(var_arg), sym!(result_type)) { + ("Result", "Ok", RESULT_MAP_UNIT_FN) + } else { + return; + }; let fn_arg = &map_args[1]; if is_unit_function(cx, fn_arg) { diff --git a/clippy_lints/src/match_on_vec_items.rs b/clippy_lints/src/match_on_vec_items.rs index 0003aa94a031..4f8f2cb171d5 100644 --- a/clippy_lints/src/match_on_vec_items.rs +++ b/clippy_lints/src/match_on_vec_items.rs @@ -88,13 +88,13 @@ fn is_vec_indexing<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Opti } fn is_vector(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - let ty = cx.tables().expr_ty(expr); + let ty = cx.typeck_results().expr_ty(expr); let ty = walk_ptrs_ty(ty); is_type_diagnostic_item(cx, ty, sym!(vec_type)) } fn is_full_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - let ty = cx.tables().expr_ty(expr); + let ty = cx.typeck_results().expr_ty(expr); let ty = walk_ptrs_ty(ty); match_type(cx, ty, &utils::paths::RANGE_FULL) } diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index bd474c208070..ea6fb9e90257 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -620,7 +620,7 @@ fn check_single_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], exp return; }; - let ty = cx.tables().expr_ty(ex); + let ty = cx.typeck_results().expr_ty(ex); if ty.kind != ty::Bool || is_allowed(cx, MATCH_BOOL, ex.hir_id) { check_single_match_single_pattern(cx, ex, arms, expr, els); check_single_match_opt_like(cx, ex, arms, expr, ty, els); @@ -712,7 +712,7 @@ fn check_single_match_opt_like( fn check_match_bool(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { // Type of expression is `bool`. - if cx.tables().expr_ty(ex).kind == ty::Bool { + if cx.typeck_results().expr_ty(ex).kind == ty::Bool { span_lint_and_then( cx, MATCH_BOOL, @@ -775,8 +775,8 @@ fn check_match_bool(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: } fn check_overlapping_arms<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'_>, arms: &'tcx [Arm<'_>]) { - if arms.len() >= 2 && cx.tables().expr_ty(ex).is_integral() { - let ranges = all_ranges(cx, arms, cx.tables().expr_ty(ex)); + if arms.len() >= 2 && cx.typeck_results().expr_ty(ex).is_integral() { + let ranges = all_ranges(cx, arms, cx.typeck_results().expr_ty(ex)); let type_ranges = type_ranges(&ranges); if !type_ranges.is_empty() { if let Some((start, end)) = overlapping(&type_ranges) { @@ -794,7 +794,7 @@ fn check_overlapping_arms<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'_>, arms } fn check_wild_err_arm(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { - let ex_ty = walk_ptrs_ty(cx.tables().expr_ty(ex)); + let ex_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(ex)); if is_type_diagnostic_item(cx, ex_ty, sym!(result_type)) { for arm in arms { if let PatKind::TupleStruct(ref path, ref inner, _) = arm.pat.kind { @@ -835,7 +835,7 @@ fn check_wild_err_arm(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { } fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { - let ty = cx.tables().expr_ty(ex); + let ty = cx.typeck_results().expr_ty(ex); if !ty.is_enum() { // If there isn't a nice closed set of possible values that can be conveniently enumerated, // don't complain about not enumerating the mall. @@ -1010,8 +1010,8 @@ fn check_match_as_ref(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], exp "as_mut" }; - let output_ty = cx.tables().expr_ty(expr); - let input_ty = cx.tables().expr_ty(ex); + let output_ty = cx.typeck_results().expr_ty(expr); + let input_ty = cx.typeck_results().expr_ty(ex); let cast = if_chain! { if let ty::Adt(_, substs) = input_ty.kind; @@ -1079,7 +1079,7 @@ fn check_match_like_matches<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) fn find_matches_sugg(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>, desugared: bool) { if_chain! { if arms.len() == 2; - if cx.tables().expr_ty(expr).is_bool(); + if cx.typeck_results().expr_ty(expr).is_bool(); if is_wild(&arms[1].pat); if let Some(first) = find_bool_lit(&arms[0].body.kind, desugared); if let Some(second) = find_bool_lit(&arms[1].body.kind, desugared); @@ -1154,13 +1154,13 @@ fn check_match_single_binding<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[A match match_body.kind { ExprKind::Block(block, _) => { // macro + expr_ty(body) == () - if block.span.from_expansion() && cx.tables().expr_ty(&match_body).is_unit() { + if block.span.from_expansion() && cx.typeck_results().expr_ty(&match_body).is_unit() { snippet_body.push(';'); } }, _ => { // expr_ty(body) == () - if cx.tables().expr_ty(&match_body).is_unit() { + if cx.typeck_results().expr_ty(&match_body).is_unit() { snippet_body.push(';'); } }, @@ -1255,11 +1255,11 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>) { if let PatKind::Range(ref lhs, ref rhs, range_end) = pat.kind { let lhs = match lhs { - Some(lhs) => constant(cx, cx.tables(), lhs)?.0, + Some(lhs) => constant(cx, cx.typeck_results(), lhs)?.0, None => miri_to_const(ty.numeric_min_val(cx.tcx)?)?, }; let rhs = match rhs { - Some(rhs) => constant(cx, cx.tables(), rhs)?.0, + Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0, None => miri_to_const(ty.numeric_max_val(cx.tcx)?)?, }; let rhs = match range_end { @@ -1273,7 +1273,7 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>) } if let PatKind::Lit(ref value) = pat.kind { - let value = constant(cx, cx.tables(), value)?.0; + let value = constant(cx, cx.typeck_results(), value)?.0; return Some(SpannedRange { span: pat.span, node: (value.clone(), Bound::Included(value)), diff --git a/clippy_lints/src/mem_discriminant.rs b/clippy_lints/src/mem_discriminant.rs index 06c568513035..c71c2ee7d70a 100644 --- a/clippy_lints/src/mem_discriminant.rs +++ b/clippy_lints/src/mem_discriminant.rs @@ -38,7 +38,7 @@ impl<'tcx> LateLintPass<'tcx> for MemDiscriminant { if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::MEM_DISCRIMINANT); // type is non-enum - let ty_param = cx.tables().node_substs(func.hir_id).type_at(0); + let ty_param = cx.typeck_results().node_substs(func.hir_id).type_at(0); if !ty_param.is_enum(); then { diff --git a/clippy_lints/src/mem_forget.rs b/clippy_lints/src/mem_forget.rs index b895ba324c78..8c6fd10f98a1 100644 --- a/clippy_lints/src/mem_forget.rs +++ b/clippy_lints/src/mem_forget.rs @@ -31,7 +31,7 @@ impl<'tcx> LateLintPass<'tcx> for MemForget { if let ExprKind::Path(ref qpath) = path_expr.kind { if let Some(def_id) = qpath_res(cx, qpath, path_expr.hir_id).opt_def_id() { if match_def_path(cx, def_id, &paths::MEM_FORGET) { - let forgot_ty = cx.tables().expr_ty(&args[0]); + let forgot_ty = cx.typeck_results().expr_ty(&args[0]); if forgot_ty.ty_adt_def().map_or(false, |def| def.has_dtor(cx.tcx)) { span_lint(cx, MEM_FORGET, e.span, "usage of `mem::forget` on `Drop` type"); diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 25f332cdcc28..bb0acecc5a92 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -138,7 +138,7 @@ fn check_replace_option_with_none(cx: &LateContext<'_>, src: &Expr<'_>, dest: &E fn check_replace_with_uninit(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { if_chain! { // check if replacement is mem::MaybeUninit::uninit().assume_init() - if let Some(method_def_id) = cx.tables().type_dependent_def_id(src.hir_id); + if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(src.hir_id); if cx.tcx.is_diagnostic_item(sym::assume_init, method_def_id); then { let mut applicability = Applicability::MachineApplicable; @@ -179,7 +179,7 @@ fn check_replace_with_uninit(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<' applicability, ); } else if cx.tcx.is_diagnostic_item(sym::mem_zeroed, repl_def_id) && - !cx.tables().expr_ty(src).is_primitive() { + !cx.typeck_results().expr_ty(src).is_primitive() { span_lint_and_help( cx, MEM_REPLACE_WITH_UNINIT, diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs index fcf7b509eadb..498f12518f8a 100644 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/clippy_lints/src/methods/bind_instead_of_map.rs @@ -157,7 +157,7 @@ pub(crate) trait BindInsteadOfMap { /// Lint use of `_.and_then(|x| Some(y))` for `Option`s fn lint(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - if !match_type(cx, cx.tables().expr_ty(&args[0]), Self::TYPE_QPATH) { + if !match_type(cx, cx.typeck_results().expr_ty(&args[0]), Self::TYPE_QPATH) { return; } diff --git a/clippy_lints/src/methods/inefficient_to_string.rs b/clippy_lints/src/methods/inefficient_to_string.rs index 1c0018a5b95e..e5f815772eba 100644 --- a/clippy_lints/src/methods/inefficient_to_string.rs +++ b/clippy_lints/src/methods/inefficient_to_string.rs @@ -11,9 +11,9 @@ use rustc_middle::ty::{self, Ty}; /// Checks for the `INEFFICIENT_TO_STRING` lint pub fn lint<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'tcx>) { if_chain! { - if let Some(to_string_meth_did) = cx.tables().type_dependent_def_id(expr.hir_id); + if let Some(to_string_meth_did) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if match_def_path(cx, to_string_meth_did, &paths::TO_STRING_METHOD); - if let Some(substs) = cx.tables().node_substs_opt(expr.hir_id); + if let Some(substs) = cx.typeck_results().node_substs_opt(expr.hir_id); let self_ty = substs.type_at(0); let (deref_self_ty, deref_count) = walk_ptrs_ty_depth(self_ty); if deref_count >= 1; diff --git a/clippy_lints/src/methods/manual_saturating_arithmetic.rs b/clippy_lints/src/methods/manual_saturating_arithmetic.rs index 9c04b6d57b90..40a625758616 100644 --- a/clippy_lints/src/methods/manual_saturating_arithmetic.rs +++ b/clippy_lints/src/methods/manual_saturating_arithmetic.rs @@ -11,7 +11,7 @@ pub fn lint(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[&[hir::Expr<'_>] let arith_lhs = &args[1][0]; let arith_rhs = &args[1][1]; - let ty = cx.tables().expr_ty(arith_lhs); + let ty = cx.typeck_results().expr_ty(arith_lhs); if !ty.is_integral() { return; } @@ -101,7 +101,7 @@ fn is_min_or_max<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>) -> Option LateLintPass<'tcx> for Methods { lint_or_fun_call(cx, expr, *method_span, &method_call.ident.as_str(), args); lint_expect_fun_call(cx, expr, *method_span, &method_call.ident.as_str(), args); - let self_ty = cx.tables().expr_ty_adjusted(&args[0]); + let self_ty = cx.typeck_results().expr_ty_adjusted(&args[0]); if args.len() == 1 && method_call.ident.name == sym!(clone) { lint_clone_on_copy(cx, expr, &args[0], self_ty); lint_clone_on_ref_ptr(cx, expr, &args[0]); @@ -1639,7 +1639,7 @@ fn lint_or_fun_call<'tcx>( if let hir::ExprKind::Path(ref qpath) = fun.kind; let path = &*last_path_segment(qpath).ident.as_str(); if ["default", "new"].contains(&path); - let arg_ty = cx.tables().expr_ty(arg); + let arg_ty = cx.typeck_results().expr_ty(arg); if let Some(default_trait_id) = get_trait_def_id(cx, &paths::DEFAULT_TRAIT); if implements_trait(cx, arg_ty, default_trait_id, &[]); @@ -1679,7 +1679,7 @@ fn lint_or_fun_call<'tcx>( ) { if let hir::ExprKind::MethodCall(ref path, _, ref args, _) = &arg.kind { if path.ident.as_str() == "len" { - let ty = walk_ptrs_ty(cx.tables().expr_ty(&args[0])); + let ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0])); match ty.kind { ty::Slice(_) | ty::Array(_, _) => return, @@ -1707,7 +1707,7 @@ fn lint_or_fun_call<'tcx>( if { finder.visit_expr(&arg); finder.found }; if !contains_return(&arg); - let self_ty = cx.tables().expr_ty(self_expr); + let self_ty = cx.typeck_results().expr_ty(self_expr); if let Some(&(_, fn_has_arguments, poss, suffix)) = know_types.iter().find(|&&i| match_type(cx, self_ty, i.0)); @@ -1786,7 +1786,7 @@ fn lint_expect_fun_call( if call_args.len() == 1 && (method_name.ident.name == sym!(as_str) || method_name.ident.name == sym!(as_ref)) && { - let arg_type = cx.tables().expr_ty(&call_args[0]); + let arg_type = cx.typeck_results().expr_ty(&call_args[0]); let base_type = walk_ptrs_ty(arg_type); base_type.kind == ty::Str || is_type_diagnostic_item(cx, base_type, sym!(string_type)) } @@ -1805,7 +1805,7 @@ fn lint_expect_fun_call( // Only `&'static str` or `String` can be used directly in the `panic!`. Other types should be // converted to string. fn requires_to_string(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool { - let arg_ty = cx.tables().expr_ty(arg); + let arg_ty = cx.typeck_results().expr_ty(arg); if is_type_diagnostic_item(cx, arg_ty, sym!(string_type)) { return false; } @@ -1835,15 +1835,16 @@ fn lint_expect_fun_call( false } }, - hir::ExprKind::MethodCall(..) => cx - .tables() - .type_dependent_def_id(arg.hir_id) - .map_or(false, |method_id| { - matches!( - cx.tcx.fn_sig(method_id).output().skip_binder().kind, - ty::Ref(ty::ReStatic, ..) - ) - }), + hir::ExprKind::MethodCall(..) => { + cx.typeck_results() + .type_dependent_def_id(arg.hir_id) + .map_or(false, |method_id| { + matches!( + cx.tcx.fn_sig(method_id).output().skip_binder().kind, + ty::Ref(ty::ReStatic, ..) + ) + }) + }, hir::ExprKind::Path(ref p) => matches!( cx.qpath_res(p, arg.hir_id), hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static, _) @@ -1891,7 +1892,7 @@ fn lint_expect_fun_call( return; } - let receiver_type = cx.tables().expr_ty_adjusted(&args[0]); + let receiver_type = cx.typeck_results().expr_ty_adjusted(&args[0]); let closure_args = if is_type_diagnostic_item(cx, receiver_type, sym!(option_type)) { "||" } else if is_type_diagnostic_item(cx, receiver_type, sym!(result_type)) { @@ -1957,7 +1958,7 @@ fn lint_expect_fun_call( /// Checks for the `CLONE_ON_COPY` lint. fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'_>) { - let ty = cx.tables().expr_ty(expr); + let ty = cx.typeck_results().expr_ty(expr); if let ty::Ref(_, inner, _) = arg_ty.kind { if let ty::Ref(_, innermost, _) = inner.kind { span_lint_and_then( @@ -2005,7 +2006,9 @@ fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Exp // &*x is a nop, &x.clone() is not hir::ExprKind::AddrOf(..) => return, // (*x).func() is useless, x.clone().func() can work in case func borrows mutably - hir::ExprKind::MethodCall(_, _, parent_args, _) if expr.hir_id == parent_args[0].hir_id => return, + hir::ExprKind::MethodCall(_, _, parent_args, _) if expr.hir_id == parent_args[0].hir_id => { + return; + }, _ => {}, }, @@ -2021,11 +2024,11 @@ fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Exp } // x.clone() might have dereferenced x, possibly through Deref impls - if cx.tables().expr_ty(arg) == ty { + if cx.typeck_results().expr_ty(arg) == ty { snip = Some(("try removing the `clone` call", format!("{}", snippet))); } else { let deref_count = cx - .tables() + .typeck_results() .expr_adjustments(arg) .iter() .filter(|adj| matches!(adj.kind, ty::adjustment::Adjust::Deref(_))) @@ -2045,7 +2048,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Exp } fn lint_clone_on_ref_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>) { - let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(arg)); + let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(arg)); if let ty::Adt(_, subst) = obj_ty.kind { let caller_type = if is_type_diagnostic_item(cx, obj_ty, sym::Rc) { @@ -2079,7 +2082,7 @@ fn lint_string_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::E let arg = &args[1]; if let Some(arglists) = method_chain_args(arg, &["chars"]) { let target = &arglists[0][0]; - let self_ty = walk_ptrs_ty(cx.tables().expr_ty(target)); + let self_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(target)); let ref_str = if self_ty.kind == ty::Str { "" } else if is_type_diagnostic_item(cx, self_ty, sym!(string_type)) { @@ -2107,7 +2110,7 @@ fn lint_string_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::E } fn lint_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&args[0])); + let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0])); if is_type_diagnostic_item(cx, obj_ty, sym!(string_type)) { lint_string_extend(cx, expr, args); } @@ -2115,7 +2118,7 @@ fn lint_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_> fn lint_cstring_as_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, source: &hir::Expr<'_>, unwrap: &hir::Expr<'_>) { if_chain! { - let source_type = cx.tables().expr_ty(source); + let source_type = cx.typeck_results().expr_ty(source); if let ty::Adt(def, substs) = source_type.kind; if cx.tcx.is_diagnostic_item(sym!(result_type), def.did); if match_type(cx, substs.type_at(0), &paths::CSTRING); @@ -2135,8 +2138,8 @@ fn lint_cstring_as_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, source: &hir: fn lint_iter_cloned_collect<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, iter_args: &'tcx [hir::Expr<'_>]) { if_chain! { - if is_type_diagnostic_item(cx, cx.tables().expr_ty(expr), sym!(vec_type)); - if let Some(slice) = derefs_to_slice(cx, &iter_args[0], cx.tables().expr_ty(&iter_args[0])); + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym!(vec_type)); + if let Some(slice) = derefs_to_slice(cx, &iter_args[0], cx.typeck_results().expr_ty(&iter_args[0])); if let Some(to_replace) = expr.span.trim_start(slice.span.source_callsite()); then { @@ -2243,7 +2246,7 @@ fn lint_unnecessary_fold(cx: &LateContext<'_>, expr: &hir::Expr<'_>, fold_args: fn lint_step_by<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, args: &'tcx [hir::Expr<'_>]) { if match_trait_method(cx, expr, &paths::ITERATOR) { - if let Some((Constant::Int(0), _)) = constant(cx, cx.tables(), &args[1]) { + if let Some((Constant::Int(0), _)) = constant(cx, cx.typeck_results(), &args[1]) { span_lint( cx, ITERATOR_STEP_BY_ZERO, @@ -2267,7 +2270,7 @@ fn lint_iter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, iter_ parent_expr_opt = get_parent_expr(cx, parent_expr); } - if derefs_to_slice(cx, caller_expr, cx.tables().expr_ty(caller_expr)).is_some() { + if derefs_to_slice(cx, caller_expr, cx.typeck_results().expr_ty(caller_expr)).is_some() { // caller is a Slice if_chain! { if let hir::ExprKind::Index(ref caller_var, ref index_expr) = &caller_expr.kind; @@ -2288,8 +2291,11 @@ fn lint_iter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, iter_ ); } } - } else if is_type_diagnostic_item(cx, cx.tables().expr_ty(caller_expr), sym!(vec_type)) - || matches!(&walk_ptrs_ty(cx.tables().expr_ty(caller_expr)).kind, ty::Array(_, _)) + } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(caller_expr), sym!(vec_type)) + || matches!( + &walk_ptrs_ty(cx.typeck_results().expr_ty(caller_expr)).kind, + ty::Array(_, _) + ) { // caller is a Vec or an Array let mut applicability = Applicability::MachineApplicable; @@ -2316,11 +2322,11 @@ fn lint_iter_nth<'tcx>( ) { let iter_args = nth_and_iter_args[1]; let mut_str = if is_mut { "_mut" } else { "" }; - let caller_type = if derefs_to_slice(cx, &iter_args[0], cx.tables().expr_ty(&iter_args[0])).is_some() { + let caller_type = if derefs_to_slice(cx, &iter_args[0], cx.typeck_results().expr_ty(&iter_args[0])).is_some() { "slice" - } else if is_type_diagnostic_item(cx, cx.tables().expr_ty(&iter_args[0]), sym!(vec_type)) { + } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&iter_args[0]), sym!(vec_type)) { "Vec" - } else if is_type_diagnostic_item(cx, cx.tables().expr_ty(&iter_args[0]), sym!(vecdeque_type)) { + } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&iter_args[0]), sym!(vecdeque_type)) { "VecDeque" } else { let nth_args = nth_and_iter_args[0]; @@ -2341,7 +2347,7 @@ fn lint_iter_nth<'tcx>( fn lint_iter_nth_zero<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, nth_args: &'tcx [hir::Expr<'_>]) { if_chain! { if match_trait_method(cx, expr, &paths::ITERATOR); - if let Some((Constant::Int(0), _)) = constant(cx, cx.tables(), &nth_args[1]); + if let Some((Constant::Int(0), _)) = constant(cx, cx.typeck_results(), &nth_args[1]); then { let mut applicability = Applicability::MachineApplicable; span_lint_and_sugg( @@ -2361,7 +2367,7 @@ fn lint_get_unwrap<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, get_args: // Note: we don't want to lint `get_mut().unwrap` for `HashMap` or `BTreeMap`, // because they do not implement `IndexMut` let mut applicability = Applicability::MachineApplicable; - let expr_ty = cx.tables().expr_ty(&get_args[0]); + let expr_ty = cx.typeck_results().expr_ty(&get_args[0]); let get_args_str = if get_args.len() > 1 { snippet_with_applicability(cx, get_args[1].span, "_", &mut applicability) } else { @@ -2463,7 +2469,7 @@ fn derefs_to_slice<'tcx>( } if let hir::ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind { - if path.ident.name == sym!(iter) && may_slice(cx, cx.tables().expr_ty(&args[0])) { + if path.ident.name == sym!(iter) && may_slice(cx, cx.typeck_results().expr_ty(&args[0])) { Some(&args[0]) } else { None @@ -2486,7 +2492,7 @@ fn derefs_to_slice<'tcx>( /// lint use of `unwrap()` for `Option`s and `Result`s fn lint_unwrap(cx: &LateContext<'_>, expr: &hir::Expr<'_>, unwrap_args: &[hir::Expr<'_>]) { - let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&unwrap_args[0])); + let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&unwrap_args[0])); let mess = if is_type_diagnostic_item(cx, obj_ty, sym!(option_type)) { Some((UNWRAP_USED, "an Option", "None")) @@ -2514,7 +2520,7 @@ fn lint_unwrap(cx: &LateContext<'_>, expr: &hir::Expr<'_>, unwrap_args: &[hir::E /// lint use of `expect()` for `Option`s and `Result`s fn lint_expect(cx: &LateContext<'_>, expr: &hir::Expr<'_>, expect_args: &[hir::Expr<'_>]) { - let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&expect_args[0])); + let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&expect_args[0])); let mess = if is_type_diagnostic_item(cx, obj_ty, sym!(option_type)) { Some((EXPECT_USED, "an Option", "None")) @@ -2540,8 +2546,8 @@ fn lint_expect(cx: &LateContext<'_>, expr: &hir::Expr<'_>, expect_args: &[hir::E fn lint_ok_expect(cx: &LateContext<'_>, expr: &hir::Expr<'_>, ok_args: &[hir::Expr<'_>]) { if_chain! { // lint if the caller of `ok()` is a `Result` - if is_type_diagnostic_item(cx, cx.tables().expr_ty(&ok_args[0]), sym!(result_type)); - let result_type = cx.tables().expr_ty(&ok_args[0]); + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&ok_args[0]), sym!(result_type)); + let result_type = cx.typeck_results().expr_ty(&ok_args[0]); if let Some(error_type) = get_error_type(cx, result_type); if has_debug_impl(error_type, cx); @@ -2579,7 +2585,7 @@ fn lint_map_flatten<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map } // lint if caller of `.map().flatten()` is an Option - if is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_args[0]), sym!(option_type)) { + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_args[0]), sym!(option_type)) { let msg = "called `map(..).flatten()` on an `Option`. \ This is more succinctly expressed by calling `.and_then(..)`"; let self_snippet = snippet(cx, map_args[0].span, ".."); @@ -2605,8 +2611,8 @@ fn lint_map_unwrap_or_else<'tcx>( unwrap_args: &'tcx [hir::Expr<'_>], ) { // lint if the caller of `map()` is an `Option` - let is_option = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_args[0]), sym!(option_type)); - let is_result = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_args[0]), sym!(result_type)); + let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_args[0]), sym!(option_type)); + let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_args[0]), sym!(result_type)); if is_option || is_result { // Don't make a suggestion that may fail to compile due to mutably borrowing @@ -2656,8 +2662,8 @@ fn lint_map_unwrap_or_else<'tcx>( /// lint use of `_.map_or(None, _)` for `Option`s and `Result`s fn lint_map_or_none<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map_or_args: &'tcx [hir::Expr<'_>]) { - let is_option = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_or_args[0]), sym!(option_type)); - let is_result = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_or_args[0]), sym!(result_type)); + let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_or_args[0]), sym!(option_type)); + let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_or_args[0]), sym!(result_type)); // There are two variants of this `map_or` lint: // (1) using `map_or` as an adapter from `Result` to `Option` @@ -3014,7 +3020,7 @@ fn lint_chars_cmp( if segment.ident.name == sym!(Some); then { let mut applicability = Applicability::MachineApplicable; - let self_ty = walk_ptrs_ty(cx.tables().expr_ty_adjusted(&args[0][0])); + let self_ty = walk_ptrs_ty(cx.typeck_results().expr_ty_adjusted(&args[0][0])); if self_ty.kind != ty::Str { return false; @@ -3142,8 +3148,8 @@ fn lint_asref(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str, as_re if match_trait_method(cx, expr, &paths::ASREF_TRAIT) || match_trait_method(cx, expr, &paths::ASMUT_TRAIT) { // check if the type after `as_ref` or `as_mut` is the same as before let recvr = &as_ref_args[0]; - let rcv_ty = cx.tables().expr_ty(recvr); - let res_ty = cx.tables().expr_ty(expr); + let rcv_ty = cx.typeck_results().expr_ty(recvr); + let res_ty = cx.typeck_results().expr_ty(expr); let (base_res_ty, res_depth) = walk_ptrs_ty_depth(res_ty); let (base_rcv_ty, rcv_depth) = walk_ptrs_ty_depth(rcv_ty); if base_rcv_ty == base_res_ty && rcv_depth >= res_depth { @@ -3212,7 +3218,7 @@ fn lint_maybe_uninit(cx: &LateContext<'_>, expr: &hir::Expr<'_>, outer: &hir::Ex if args.is_empty(); if let hir::ExprKind::Path(ref path) = callee.kind; if match_qpath(path, &paths::MEM_MAYBEUNINIT_UNINIT); - if !is_maybe_uninit_ty_valid(cx, cx.tables().expr_ty_adjusted(outer)); + if !is_maybe_uninit_ty_valid(cx, cx.typeck_results().expr_ty_adjusted(outer)); then { span_lint( cx, @@ -3254,7 +3260,7 @@ fn lint_option_as_ref_deref<'tcx>( ) { let same_mutability = |m| (is_mut && m == &hir::Mutability::Mut) || (!is_mut && m == &hir::Mutability::Not); - let option_ty = cx.tables().expr_ty(&as_ref_args[0]); + let option_ty = cx.typeck_results().expr_ty(&as_ref_args[0]); if !is_type_diagnostic_item(cx, option_ty, sym!(option_type)) { return; } @@ -3284,10 +3290,10 @@ fn lint_option_as_ref_deref<'tcx>( if let hir::ExprKind::Path(qpath) = &args[0].kind; if let hir::def::Res::Local(local_id) = cx.qpath_res(qpath, args[0].hir_id); if closure_body.params[0].pat.hir_id == local_id; - let adj = cx.tables().expr_adjustments(&args[0]).iter().map(|x| &x.kind).collect::>(); + let adj = cx.typeck_results().expr_adjustments(&args[0]).iter().map(|x| &x.kind).collect::>(); if let [ty::adjustment::Adjust::Deref(None), ty::adjustment::Adjust::Borrow(_)] = *adj; then { - let method_did = cx.tables().type_dependent_def_id(closure_expr.hir_id).unwrap(); + let method_did = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id).unwrap(); deref_aliases.iter().any(|path| match_def_path(cx, method_did, path)) } else { false @@ -3577,7 +3583,7 @@ fn contains_return(expr: &hir::Expr<'_>) -> bool { fn check_pointer_offset(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { if_chain! { if args.len() == 2; - if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.tables().expr_ty(&args[0]).kind; + if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.typeck_results().expr_ty(&args[0]).kind; if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty)); if layout.is_zst(); then { @@ -3587,7 +3593,7 @@ fn check_pointer_offset(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir: } fn lint_filetype_is_file(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - let ty = cx.tables().expr_ty(&args[0]); + let ty = cx.typeck_results().expr_ty(&args[0]); if !match_type(cx, ty, &paths::FILE_TYPE) { return; diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 672eb75c57fc..95fa28e1c0f7 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -20,8 +20,8 @@ pub(super) fn lint<'tcx>( map_span: Span, ) { // lint if the caller of `map()` is an `Option` - if is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_args[0]), sym!(option_type)) { - if !is_copy(cx, cx.tables().expr_ty(&unwrap_args[1])) { + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_args[0]), sym!(option_type)) { + if !is_copy(cx, cx.typeck_results().expr_ty(&unwrap_args[1])) { // Do not lint if the `map` argument uses identifiers in the `map` // argument that are also used in the `unwrap_or` argument diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index c8aa98d34892..dae39aaf5e21 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -36,7 +36,7 @@ impl<'tcx> LateLintPass<'tcx> for MinMaxPass { } match ( outer_max, - Constant::partial_cmp(cx.tcx, cx.tables().expr_ty(ie), &outer_c, &inner_c), + Constant::partial_cmp(cx.tcx, cx.typeck_results().expr_ty(ie), &outer_c, &inner_c), ) { (_, None) | (MinMax::Max, Some(Ordering::Less)) | (MinMax::Min, Some(Ordering::Greater)) => (), _ => { @@ -62,7 +62,7 @@ enum MinMax { fn min_max<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(MinMax, Constant, &'a Expr<'a>)> { if let ExprKind::Call(ref path, ref args) = expr.kind { if let ExprKind::Path(ref qpath) = path.kind { - cx.tables() + cx.typeck_results() .qpath_res(qpath, path.hir_id) .opt_def_id() .and_then(|def_id| { @@ -86,10 +86,10 @@ fn fetch_const<'a>(cx: &LateContext<'_>, args: &'a [Expr<'a>], m: MinMax) -> Opt if args.len() != 2 { return None; } - constant_simple(cx, cx.tables(), &args[0]).map_or_else( - || constant_simple(cx, cx.tables(), &args[1]).map(|c| (m, c, &args[0])), + constant_simple(cx, cx.typeck_results(), &args[0]).map_or_else( + || constant_simple(cx, cx.typeck_results(), &args[1]).map(|c| (m, c, &args[0])), |c| { - if constant_simple(cx, cx.tables(), &args[1]).is_none() { + if constant_simple(cx, cx.typeck_results(), &args[1]).is_none() { // otherwise ignore Some((m, c, &args[1])) } else { diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 400f4b609af7..fc10e5077b83 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -496,7 +496,7 @@ fn get_lint_and_message( fn check_nan(cx: &LateContext<'_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) { if_chain! { if !in_constant(cx, cmp_expr.hir_id); - if let Some((value, _)) = constant(cx, cx.tables(), expr); + if let Some((value, _)) = constant(cx, cx.typeck_results(), expr); then { let needs_lint = match value { Constant::F32(num) => num.is_nan(), @@ -517,7 +517,7 @@ fn check_nan(cx: &LateContext<'_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) { } fn is_named_constant<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool { - if let Some((_, res)) = constant(cx, cx.tables(), expr) { + if let Some((_, res)) = constant(cx, cx.typeck_results(), expr) { res } else { false @@ -525,7 +525,7 @@ fn is_named_constant<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool } fn is_allowed<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool { - match constant(cx, cx.tables(), expr) { + match constant(cx, cx.typeck_results(), expr) { Some((Constant::F32(f), _)) => f == 0.0 || f.is_infinite(), Some((Constant::F64(f), _)) => f == 0.0 || f.is_infinite(), Some((Constant::Vec(vec), _)) => vec.iter().all(|f| match f { @@ -557,7 +557,7 @@ fn is_signum(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { } fn is_float(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - let value = &walk_ptrs_ty(cx.tables().expr_ty(expr)).kind; + let value = &walk_ptrs_ty(cx.typeck_results().expr_ty(expr)).kind; if let ty::Array(arr_ty, _) = value { return matches!(arr_ty.kind, ty::Float(_)); @@ -567,7 +567,7 @@ fn is_float(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { } fn is_array(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - matches!(&walk_ptrs_ty(cx.tables().expr_ty(expr)).kind, ty::Array(_, _)) + matches!(&walk_ptrs_ty(cx.typeck_results().expr_ty(expr)).kind, ty::Array(_, _)) } fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool) { @@ -593,7 +593,7 @@ fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: let (arg_ty, snip) = match expr.kind { ExprKind::MethodCall(.., ref args, _) if args.len() == 1 => { if match_trait_method(cx, expr, &paths::TO_STRING) || match_trait_method(cx, expr, &paths::TO_OWNED) { - (cx.tables().expr_ty(&args[0]), snippet(cx, args[0].span, "..")) + (cx.typeck_results().expr_ty(&args[0]), snippet(cx, args[0].span, "..")) } else { return; } @@ -601,7 +601,7 @@ fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: ExprKind::Call(ref path, ref v) if v.len() == 1 => { if let ExprKind::Path(ref path) = path.kind { if match_qpath(path, &["String", "from_str"]) || match_qpath(path, &["String", "from"]) { - (cx.tables().expr_ty(&v[0]), snippet(cx, v[0].span, "..")) + (cx.typeck_results().expr_ty(&v[0]), snippet(cx, v[0].span, "..")) } else { return; } @@ -612,7 +612,7 @@ fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: _ => return, }; - let other_ty = cx.tables().expr_ty(other); + let other_ty = cx.typeck_results().expr_ty(other); let without_deref = symmetric_partial_eq(cx, arg_ty, other_ty).unwrap_or_default(); let with_deref = arg_ty diff --git a/clippy_lints/src/modulo_arithmetic.rs b/clippy_lints/src/modulo_arithmetic.rs index 59ccc6333fdc..5d4436bd206d 100644 --- a/clippy_lints/src/modulo_arithmetic.rs +++ b/clippy_lints/src/modulo_arithmetic.rs @@ -37,8 +37,8 @@ struct OperandInfo { } fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { - match constant(cx, cx.tables(), operand) { - Some((Constant::Int(v), _)) => match cx.tables().expr_ty(expr).kind { + match constant(cx, cx.typeck_results(), operand) { + Some((Constant::Int(v), _)) => match cx.typeck_results().expr_ty(expr).kind { ty::Int(ity) => { let value = sext(cx.tcx, v, ity); return Some(OperandInfo { @@ -106,7 +106,7 @@ fn check_const_operands<'tcx>( } fn check_non_const_operands<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, operand: &Expr<'_>) { - let operand_type = cx.tables().expr_ty(operand); + let operand_type = cx.typeck_results().expr_ty(operand); if might_have_negative_value(operand_type) { span_lint_and_then( cx, diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index d8fb8a4bb776..9f8f401cc0f6 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType { if let hir::PatKind::Wild = local.pat.kind { return; } - check_ty(cx, local.span, cx.tables().pat_ty(&*local.pat)); + check_ty(cx, local.span, cx.typeck_results().pat_ty(&*local.pat)); } } diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index 259b4c73d760..b02e86bca271 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -69,7 +69,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { expr.span, "generally you want to avoid `&mut &mut _` if possible", ); - } else if let ty::Ref(_, _, hir::Mutability::Mut) = self.cx.tables().expr_ty(e).kind { + } else if let ty::Ref(_, _, hir::Mutability::Mut) = self.cx.typeck_results().expr_ty(e).kind { span_lint( self.cx, MUT_MUT, diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 53341b6eba75..b8dc50816329 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -37,14 +37,14 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed { check_arguments( cx, arguments, - cx.tables().expr_ty(fn_expr), + cx.typeck_results().expr_ty(fn_expr), &rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false)), ); } }, ExprKind::MethodCall(ref path, _, ref arguments, _) => { - let def_id = cx.tables().type_dependent_def_id(e.hir_id).unwrap(); - let substs = cx.tables().node_substs(e.hir_id); + let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap(); + let substs = cx.typeck_results().node_substs(e.hir_id); let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs); check_arguments(cx, arguments, method_type, &path.ident.as_str()) }, diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index 78d2356748f1..7f529f0404c0 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -135,7 +135,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> { return; }, ExprKind::Path(_) => { - if let Some(adj) = self.cx.tables().adjustments().get(expr.hir_id) { + if let Some(adj) = self.cx.typeck_results().adjustments().get(expr.hir_id) { if adj .iter() .any(|a| matches!(a.target.kind, ty::Ref(_, _, Mutability::Mut))) diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index 1a821491fcaf..568898aa5c9b 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -66,7 +66,7 @@ declare_lint_pass!(Mutex => [MUTEX_ATOMIC, MUTEX_INTEGER]); impl<'tcx> LateLintPass<'tcx> for Mutex { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - let ty = cx.tables().expr_ty(expr); + let ty = cx.typeck_results().expr_ty(expr); if let ty::Adt(_, subst) = ty.kind { if is_type_diagnostic_item(cx, ty, sym!(mutex_type)) { let mutex_param = subst.type_at(0); diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index e15376b93262..8e44f2ec2408 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -229,7 +229,10 @@ fn check_comparison<'a, 'tcx>( use self::Expression::{Bool, Other}; if let ExprKind::Binary(op, ref left_side, ref right_side) = e.kind { - let (l_ty, r_ty) = (cx.tables().expr_ty(left_side), cx.tables().expr_ty(right_side)); + let (l_ty, r_ty) = ( + cx.typeck_results().expr_ty(left_side), + cx.typeck_results().expr_ty(right_side), + ); if l_ty.is_bool() && r_ty.is_bool() { let mut applicability = Applicability::MachineApplicable; diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index 1bea93fcb752..415ab556c9fd 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -46,8 +46,8 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow { return; } if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = e.kind { - if let ty::Ref(..) = cx.tables().expr_ty(inner).kind { - for adj3 in cx.tables().expr_adjustments(e).windows(3) { + if let ty::Ref(..) = cx.typeck_results().expr_ty(inner).kind { + for adj3 in cx.typeck_results().expr_adjustments(e).windows(3) { if let [Adjustment { kind: Adjust::Deref(_), .. }, Adjustment { @@ -85,7 +85,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow { } if_chain! { if let PatKind::Binding(BindingAnnotation::Ref, .., name, _) = pat.kind; - if let ty::Ref(_, tam, mutbl) = cx.tables().pat_ty(pat).kind; + if let ty::Ref(_, tam, mutbl) = cx.typeck_results().pat_ty(pat).kind; if mutbl == Mutability::Not; if let ty::Ref(_, _, mutbl) = tam.kind; // only lint immutable refs, because borrowed `&mut T` cannot be moved out diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 29e5d4d16649..81774b617ac2 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -135,7 +135,8 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { } = { let mut ctx = MovedVariablesCtxt::default(); cx.tcx.infer_ctxt().enter(|infcx| { - euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.tables()).consume_body(body); + euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()) + .consume_body(body); }); ctx }; diff --git a/clippy_lints/src/needless_update.rs b/clippy_lints/src/needless_update.rs index 6ec73041604e..ce3f066eff5e 100644 --- a/clippy_lints/src/needless_update.rs +++ b/clippy_lints/src/needless_update.rs @@ -47,7 +47,7 @@ declare_lint_pass!(NeedlessUpdate => [NEEDLESS_UPDATE]); impl<'tcx> LateLintPass<'tcx> for NeedlessUpdate { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Struct(_, ref fields, Some(ref base)) = expr.kind { - let ty = cx.tables().expr_ty(expr); + let ty = cx.typeck_results().expr_ty(expr); if let ty::Adt(def, _) = ty.kind { if fields.len() == def.non_enum_variant().fields.len() { span_lint( diff --git a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs index 1be766d8e8dc..95613a1b82ef 100644 --- a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs @@ -56,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for NoNegCompOpForPartialOrd { then { - let ty = cx.tables().expr_ty(left); + let ty = cx.typeck_results().expr_ty(left); let implements_ord = { if let Some(id) = utils::get_trait_def_id(cx, &paths::ORD) { diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index 1346145da327..6b6c950e0abe 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -44,8 +44,8 @@ impl<'tcx> LateLintPass<'tcx> for NegMultiply { fn check_mul(cx: &LateContext<'_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_>) { if_chain! { if let ExprKind::Lit(ref l) = lit.kind; - if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables().expr_ty_opt(lit)); - if cx.tables().expr_ty(exp).is_integral(); + if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.typeck_results().expr_ty_opt(lit)); + if cx.typeck_results().expr_ty(exp).is_integral(); then { span_lint(cx, NEG_MULTIPLY, span, "Negation by multiplying with `-1`"); } diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 95283dae7147..b1b5b3439a0e 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -48,7 +48,7 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { } match expr.kind { ExprKind::Lit(..) | ExprKind::Closure(..) => true, - ExprKind::Path(..) => !has_drop(cx, cx.tables().expr_ty(expr)), + ExprKind::Path(..) => !has_drop(cx, cx.typeck_results().expr_ty(expr)), ExprKind::Index(ref a, ref b) | ExprKind::Binary(_, ref a, ref b) => { has_no_effect(cx, a) && has_no_effect(cx, b) }, @@ -61,7 +61,7 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { | ExprKind::AddrOf(_, _, ref inner) | ExprKind::Box(ref inner) => has_no_effect(cx, inner), ExprKind::Struct(_, ref fields, ref base) => { - !has_drop(cx, cx.tables().expr_ty(expr)) + !has_drop(cx, cx.typeck_results().expr_ty(expr)) && fields.iter().all(|field| has_no_effect(cx, &field.expr)) && base.as_ref().map_or(true, |base| has_no_effect(cx, base)) }, @@ -70,7 +70,8 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let res = qpath_res(cx, qpath, callee.hir_id); match res { Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..) => { - !has_drop(cx, cx.tables().expr_ty(expr)) && args.iter().all(|arg| has_no_effect(cx, arg)) + !has_drop(cx, cx.typeck_results().expr_ty(expr)) + && args.iter().all(|arg| has_no_effect(cx, arg)) }, _ => false, } @@ -137,7 +138,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option reduce_expression(cx, inner).or_else(|| Some(vec![inner])), ExprKind::Struct(_, ref fields, ref base) => { - if has_drop(cx, cx.tables().expr_ty(expr)) { + if has_drop(cx, cx.typeck_results().expr_ty(expr)) { None } else { Some(fields.iter().map(|f| &f.expr).chain(base).map(Deref::deref).collect()) @@ -148,7 +149,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option + if !has_drop(cx, cx.typeck_results().expr_ty(expr)) => { Some(args.iter().collect()) }, diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index a3521c31a6be..031d69e86a13 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -237,13 +237,13 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { } let ty = if needs_check_adjustment { - let adjustments = cx.tables().expr_adjustments(dereferenced_expr); + let adjustments = cx.typeck_results().expr_adjustments(dereferenced_expr); if let Some(i) = adjustments .iter() .position(|adj| matches!(adj.kind, Adjust::Borrow(_) | Adjust::Deref(_))) { if i == 0 { - cx.tables().expr_ty(dereferenced_expr) + cx.typeck_results().expr_ty(dereferenced_expr) } else { adjustments[i - 1].target } @@ -252,7 +252,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { return; } } else { - cx.tables().expr_ty(dereferenced_expr) + cx.typeck_results().expr_ty(dereferenced_expr) }; verify_ty_bound(cx, ty, Source::Expr { expr: expr.span }); diff --git a/clippy_lints/src/open_options.rs b/clippy_lints/src/open_options.rs index 2b83efa84f64..e99d0317ba2e 100644 --- a/clippy_lints/src/open_options.rs +++ b/clippy_lints/src/open_options.rs @@ -30,7 +30,7 @@ declare_lint_pass!(OpenOptions => [NONSENSICAL_OPEN_OPTIONS]); impl<'tcx> LateLintPass<'tcx> for OpenOptions { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::MethodCall(ref path, _, ref arguments, _) = e.kind { - let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&arguments[0])); + let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&arguments[0])); if path.ident.name == sym!(open) && match_type(cx, obj_ty, &paths::OPEN_OPTIONS) { let mut options = Vec::new(); get_open_options(cx, &arguments[0], &mut options); @@ -58,7 +58,7 @@ enum OpenOption { fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec<(OpenOption, Argument)>) { if let ExprKind::MethodCall(ref path, _, ref arguments, _) = argument.kind { - let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&arguments[0])); + let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&arguments[0])); // Only proceed if this is a call on some object of type std::fs::OpenOptions if match_type(cx, obj_ty, &paths::OPEN_OPTIONS) && arguments.len() >= 2 { diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index 8dbe58763bfb..065f863b8654 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -72,7 +72,8 @@ declare_lint_pass!(OptionIfLetElse => [OPTION_IF_LET_ELSE]); /// Returns true iff the given expression is the result of calling `Result::ok` fn is_result_ok(cx: &LateContext<'_>, expr: &'_ Expr<'_>) -> bool { if let ExprKind::MethodCall(ref path, _, &[ref receiver], _) = &expr.kind { - path.ident.name.to_ident_string() == "ok" && match_type(cx, &cx.tables().expr_ty(&receiver), &paths::RESULT) + path.ident.name.to_ident_string() == "ok" + && match_type(cx, &cx.typeck_results().expr_ty(&receiver), &paths::RESULT) } else { false } diff --git a/clippy_lints/src/overflow_check_conditional.rs b/clippy_lints/src/overflow_check_conditional.rs index 0850f88df44f..4d4a96766548 100644 --- a/clippy_lints/src/overflow_check_conditional.rs +++ b/clippy_lints/src/overflow_check_conditional.rs @@ -36,8 +36,8 @@ impl<'tcx> LateLintPass<'tcx> for OverflowCheckConditional { if let ExprKind::Path(QPath::Resolved(_, ref path2)) = ident2.kind; if let ExprKind::Path(QPath::Resolved(_, ref path3)) = second.kind; if eq(&path1.segments[0], &path3.segments[0]) || eq(&path2.segments[0], &path3.segments[0]); - if cx.tables().expr_ty(ident1).is_integral(); - if cx.tables().expr_ty(ident2).is_integral(); + if cx.typeck_results().expr_ty(ident1).is_integral(); + if cx.typeck_results().expr_ty(ident2).is_integral(); then { if let BinOpKind::Lt = op.node { if let BinOpKind::Add = op2.node { @@ -61,8 +61,8 @@ impl<'tcx> LateLintPass<'tcx> for OverflowCheckConditional { if let ExprKind::Path(QPath::Resolved(_, ref path2)) = ident2.kind; if let ExprKind::Path(QPath::Resolved(_, ref path3)) = first.kind; if eq(&path1.segments[0], &path3.segments[0]) || eq(&path2.segments[0], &path3.segments[0]); - if cx.tables().expr_ty(ident1).is_integral(); - if cx.tables().expr_ty(ident2).is_integral(); + if cx.typeck_results().expr_ty(ident1).is_integral(); + if cx.typeck_results().expr_ty(ident2).is_integral(); then { if let BinOpKind::Gt = op.node { if let BinOpKind::Add = op2.node { diff --git a/clippy_lints/src/path_buf_push_overwrite.rs b/clippy_lints/src/path_buf_push_overwrite.rs index 48e609542793..66a145a7f14b 100644 --- a/clippy_lints/src/path_buf_push_overwrite.rs +++ b/clippy_lints/src/path_buf_push_overwrite.rs @@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for PathBufPushOverwrite { if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; if path.ident.name == sym!(push); if args.len() == 2; - if match_type(cx, walk_ptrs_ty(cx.tables().expr_ty(&args[0])), &paths::PATH_BUF); + if match_type(cx, walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0])), &paths::PATH_BUF); if let Some(get_index_arg) = args.get(1); if let ExprKind::Lit(ref lit) = get_index_arg.kind; if let LitKind::Str(ref path_lit, _) = lit.node; diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index a49dc87c0b47..ef26fc667b22 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { if let StmtKind::Local(ref local) = stmt.kind { if let Some(init) = &local.init { - if let Some(init_ty) = cx.tables().node_type_opt(init.hir_id) { + if let Some(init_ty) = cx.typeck_results().node_type_opt(init.hir_id) { let pat = &local.pat; if in_external_macro(cx.sess(), pat.span) { return; @@ -106,7 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch { if let ExprKind::Match(ref expr, arms, source) = expr.kind { match source { MatchSource::Normal | MatchSource::IfLetDesugar { .. } | MatchSource::WhileLetDesugar => { - if let Some(expr_ty) = cx.tables().node_type_opt(expr.hir_id) { + if let Some(expr_ty) = cx.typeck_results().node_type_opt(expr.hir_id) { 'pattern_checks: for arm in arms { let pat = &arm.pat; if in_external_macro(cx.sess(), pat.span) { @@ -132,7 +132,7 @@ impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch { _: Span, hir_id: HirId, ) { - if let Some(fn_sig) = cx.tables().liberated_fn_sigs().get(hir_id) { + if let Some(fn_sig) = cx.typeck_results().liberated_fn_sigs().get(hir_id) { for (param, ty) in body.params.iter().zip(fn_sig.inputs().iter()) { apply_lint(cx, ¶m.pat, ty, DerefPossible::Impossible); } diff --git a/clippy_lints/src/ptr_offset_with_cast.rs b/clippy_lints/src/ptr_offset_with_cast.rs index 61e186a4b465..0a2d1b5fbe6a 100644 --- a/clippy_lints/src/ptr_offset_with_cast.rs +++ b/clippy_lints/src/ptr_offset_with_cast.rs @@ -105,12 +105,12 @@ fn expr_as_ptr_offset_call<'tcx>( // Is the type of the expression a usize? fn is_expr_ty_usize<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool { - cx.tables().expr_ty(expr) == cx.tcx.types.usize + cx.typeck_results().expr_ty(expr) == cx.tcx.types.usize } // Is the type of the expression a raw pointer? fn is_expr_ty_raw_ptr<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool { - cx.tables().expr_ty(expr).is_unsafe_ptr() + cx.typeck_results().expr_ty(expr).is_unsafe_ptr() } fn build_suggestion<'tcx>( diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index cc9c2f196079..fb12c565afd8 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -135,13 +135,13 @@ impl QuestionMark { } fn moves_by_default(cx: &LateContext<'_>, expression: &Expr<'_>) -> bool { - let expr_ty = cx.tables().expr_ty(expression); + let expr_ty = cx.typeck_results().expr_ty(expression); !expr_ty.is_copy_modulo_regions(cx.tcx.at(expression.span), cx.param_env) } fn is_option(cx: &LateContext<'_>, expression: &Expr<'_>) -> bool { - let expr_ty = cx.tables().expr_ty(expression); + let expr_ty = cx.typeck_results().expr_ty(expression); is_type_diagnostic_item(cx, expr_ty, sym!(option_type)) } diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index dd608de5723e..4c1f2e8e01a8 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -280,10 +280,10 @@ fn check_reversed_empty_range(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let Some(higher::Range { start: Some(start), end: Some(end), limits }) = higher::range(cx, expr); - let ty = cx.tables().expr_ty(start); + let ty = cx.typeck_results().expr_ty(start); if let ty::Int(_) | ty::Uint(_) = ty.kind; - if let Some((start_idx, _)) = constant(cx, cx.tables(), start); - if let Some((end_idx, _)) = constant(cx, cx.tables(), end); + if let Some((start_idx, _)) = constant(cx, cx.typeck_results(), start); + if let Some((end_idx, _)) = constant(cx, cx.typeck_results(), end); if let Some(ordering) = Constant::partial_cmp(cx.tcx, ty, &start_idx, &end_idx); if is_empty_range(limits, ordering); then { diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index f204a0ffb2c7..dfc158661cbf 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -89,7 +89,7 @@ fn str_span(base: Span, c: regex_syntax::ast::Span, offset: u16) -> Span { } fn const_str<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> Option { - constant(cx, cx.tables(), e).and_then(|(c, _)| match c { + constant(cx, cx.typeck_results(), e).and_then(|(c, _)| match c { Constant::Str(s) => Some(s), _ => None, }) diff --git a/clippy_lints/src/repeat_once.rs b/clippy_lints/src/repeat_once.rs index a3af369e41e5..77c206002ea7 100644 --- a/clippy_lints/src/repeat_once.rs +++ b/clippy_lints/src/repeat_once.rs @@ -41,10 +41,10 @@ impl<'tcx> LateLintPass<'tcx> for RepeatOnce { if_chain! { if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; if path.ident.name == sym!(repeat); - if let Some(Constant::Int(1)) = constant_context(cx, cx.tables()).expr(&args[1]); + if let Some(Constant::Int(1)) = constant_context(cx, cx.typeck_results()).expr(&args[1]); if !in_macro(args[0].span); then { - let ty = walk_ptrs_ty(cx.tables().expr_ty(&args[0])); + let ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0])); if ty.is_str() { span_lint_and_sugg( cx, diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 194786c5c414..901c0a65d7fe 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -164,7 +164,7 @@ fn check_local<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>, bindings: & } fn is_binding(cx: &LateContext<'_>, pat_id: HirId) -> bool { - let var_ty = cx.tables().node_type_opt(pat_id); + let var_ty = cx.typeck_results().node_type_opt(pat_id); var_ty.map_or(false, |var_ty| !matches!(var_ty.kind, ty::Adt(..))) } diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 89aa6a4edd62..bada6fa7c522 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for StringAdd { } fn is_string(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { - is_type_diagnostic_item(cx, walk_ptrs_ty(cx.tables().expr_ty(e)), sym!(string_type)) + is_type_diagnostic_item(cx, walk_ptrs_ty(cx.typeck_results().expr_ty(e)), sym!(string_type)) } fn is_add(cx: &LateContext<'_>, src: &Expr<'_>, target: &Expr<'_>) -> bool { diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index eb7d35839206..754f87e6b55e 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -194,7 +194,7 @@ fn check_for_slice<'a>(cx: &LateContext<'_>, lhs1: &'a Expr<'_>, lhs2: &'a Expr< if let ExprKind::Index(ref lhs1, ref idx1) = lhs1.kind { if let ExprKind::Index(ref lhs2, ref idx2) = lhs2.kind { if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs1, lhs2) { - let ty = walk_ptrs_ty(cx.tables().expr_ty(lhs1)); + let ty = walk_ptrs_ty(cx.typeck_results().expr_ty(lhs1)); if matches!(ty.kind, ty::Slice(_)) || matches!(ty.kind, ty::Array(_, _)) diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs index 4157103a574e..6750452941f2 100644 --- a/clippy_lints/src/to_digit_is_some.rs +++ b/clippy_lints/src/to_digit_is_some.rs @@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for ToDigitIsSome { if_chain! { if let [char_arg, radix_arg] = &**to_digit_args; if to_digits_path.ident.name.as_str() == "to_digit"; - let char_arg_ty = cx.tables().expr_ty_adjusted(char_arg); + let char_arg_ty = cx.typeck_results().expr_ty_adjusted(char_arg); if char_arg_ty.kind == ty::Char; then { Some((true, char_arg, radix_arg)) diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 5f76d5c46efb..d55eb1a0c938 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -302,8 +302,8 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { if let Some(def_id) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::TRANSMUTE); then { - let from_ty = cx.tables().expr_ty(&args[0]); - let to_ty = cx.tables().expr_ty(e); + let from_ty = cx.typeck_results().expr_ty(&args[0]); + let to_ty = cx.typeck_results().expr_ty(e); match (&from_ty.kind, &to_ty.kind) { _ if from_ty == to_ty => span_lint( diff --git a/clippy_lints/src/transmuting_null.rs b/clippy_lints/src/transmuting_null.rs index 2f03c6db42d9..fbf7f0b2517a 100644 --- a/clippy_lints/src/transmuting_null.rs +++ b/clippy_lints/src/transmuting_null.rs @@ -44,7 +44,7 @@ impl<'tcx> LateLintPass<'tcx> for TransmutingNull { then { // Catching transmute over constants that resolve to `null`. - let mut const_eval_context = constant_context(cx, cx.tables()); + let mut const_eval_context = constant_context(cx, cx.typeck_results()); if_chain! { if let ExprKind::Path(ref _qpath) = args[0].kind; let x = const_eval_context.expr(&args[0]); diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs index 208d248faa57..d3b351f30ef7 100644 --- a/clippy_lints/src/try_err.rs +++ b/clippy_lints/src/try_err.rs @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for TryErr { if let Some(return_type) = find_err_return_type(cx, &expr.kind); then { - let err_type = cx.tables().expr_ty(err_arg); + let err_type = cx.typeck_results().expr_ty(err_arg); let origin_snippet = if err_arg.span.from_expansion() { snippet_with_macro_callsite(cx, err_arg.span, "_") } else { @@ -114,7 +114,7 @@ fn find_err_return_type_arm<'tcx>(cx: &LateContext<'tcx>, arm: &'tcx Arm<'_>) -> if match_qpath(from_error_fn, &paths::TRY_FROM_ERROR); if let Some(from_error_arg) = from_error_args.get(0); then { - Some(cx.tables().expr_ty(from_error_arg)) + Some(cx.typeck_results().expr_ty(from_error_arg)) } else { None } diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index bca388ecdcc3..c3dea4475213 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -17,7 +17,7 @@ use rustc_hir::{ use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::hir::map::Map; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, InferTy, Ty, TyCtxt, TyS, TypeckTables}; +use rustc_middle::ty::{self, InferTy, Ty, TyCtxt, TyS, TypeckResults}; use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass}; use rustc_span::hygiene::{ExpnKind, MacroKind}; use rustc_span::source_map::Span; @@ -595,7 +595,7 @@ declare_lint_pass!(LetUnitValue => [LET_UNIT_VALUE]); impl<'tcx> LateLintPass<'tcx> for LetUnitValue { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { if let StmtKind::Local(ref local) = stmt.kind { - if is_unit(cx.tables().pat_ty(&local.pat)) { + if is_unit(cx.typeck_results().pat_ty(&local.pat)) { if in_external_macro(cx.sess(), stmt.span) || local.pat.span.from_expansion() { return; } @@ -680,7 +680,7 @@ impl<'tcx> LateLintPass<'tcx> for UnitCmp { if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind { if let ExprKind::Binary(ref cmp, ref left, _) = expr.kind { let op = cmp.node; - if op.is_comparison() && is_unit(cx.tables().expr_ty(left)) { + if op.is_comparison() && is_unit(cx.typeck_results().expr_ty(left)) { let result = match &*symbol.as_str() { "assert_eq" | "debug_assert_eq" => "succeed", "assert_ne" | "debug_assert_ne" => "fail", @@ -704,7 +704,7 @@ impl<'tcx> LateLintPass<'tcx> for UnitCmp { } if let ExprKind::Binary(ref cmp, ref left, _) = expr.kind { let op = cmp.node; - if op.is_comparison() && is_unit(cx.tables().expr_ty(left)) { + if op.is_comparison() && is_unit(cx.typeck_results().expr_ty(left)) { let result = match op { BinOpKind::Eq | BinOpKind::Le | BinOpKind::Ge => "true", _ => "false", @@ -774,7 +774,7 @@ impl<'tcx> LateLintPass<'tcx> for UnitArg { let args_to_recover = args .iter() .filter(|arg| { - if is_unit(cx.tables().expr_ty(arg)) && !is_unit_literal(arg) { + if is_unit(cx.typeck_results().expr_ty(arg)) && !is_unit_literal(arg) { !matches!(&arg.kind, ExprKind::Match(.., MatchSource::TryDesugar)) } else { false @@ -1232,7 +1232,7 @@ fn check_loss_of_sign(cx: &LateContext<'_>, expr: &Expr<'_>, op: &Expr<'_>, cast } // don't lint for positive constants - let const_val = constant(cx, &cx.tables(), op); + let const_val = constant(cx, &cx.typeck_results(), op); if_chain! { if let Some((const_val, _)) = const_val; if let Constant::Int(n) = const_val; @@ -1398,7 +1398,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts { return; } if let ExprKind::Cast(ref ex, _) = expr.kind { - let (cast_from, cast_to) = (cx.tables().expr_ty(ex), cx.tables().expr_ty(expr)); + let (cast_from, cast_to) = (cx.typeck_results().expr_ty(ex), cx.typeck_results().expr_ty(expr)); lint_fn_to_numeric_cast(cx, expr, ex, cast_from, cast_to); if let ExprKind::Lit(ref lit) = ex.kind { if_chain! { @@ -1786,7 +1786,7 @@ impl<'tcx> LateLintPass<'tcx> for CharLitAsU8 { if let ExprKind::Cast(e, _) = &expr.kind; if let ExprKind::Lit(l) = &e.kind; if let LitKind::Char(c) = l.node; - if ty::Uint(UintTy::U8) == cx.tables().expr_ty(expr).kind; + if ty::Uint(UintTy::U8) == cx.typeck_results().expr_ty(expr).kind; then { let mut applicability = Applicability::MachineApplicable; let snippet = snippet_with_applicability(cx, e.span, "'x'", &mut applicability); @@ -1862,8 +1862,8 @@ enum AbsurdComparisonResult { fn is_cast_between_fixed_and_target<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool { if let ExprKind::Cast(ref cast_exp, _) = expr.kind { - let precast_ty = cx.tables().expr_ty(cast_exp); - let cast_ty = cx.tables().expr_ty(expr); + let precast_ty = cx.typeck_results().expr_ty(cast_exp); + let cast_ty = cx.typeck_results().expr_ty(expr); return is_isize_or_usize(precast_ty) != is_isize_or_usize(cast_ty); } @@ -1883,7 +1883,7 @@ fn detect_absurd_comparison<'tcx>( // absurd comparison only makes sense on primitive types // primitive types don't implement comparison operators with each other - if cx.tables().expr_ty(lhs) != cx.tables().expr_ty(rhs) { + if cx.typeck_results().expr_ty(lhs) != cx.typeck_results().expr_ty(rhs) { return None; } @@ -1921,9 +1921,9 @@ fn detect_absurd_comparison<'tcx>( fn detect_extreme_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option> { use crate::types::ExtremeType::{Maximum, Minimum}; - let ty = cx.tables().expr_ty(expr); + let ty = cx.typeck_results().expr_ty(expr); - let cv = constant(cx, cx.tables(), expr)?.0; + let cv = constant(cx, cx.typeck_results(), expr)?.0; let which = match (&ty.kind, cv) { (&ty::Bool, Constant::Bool(false)) | (&ty::Uint(_), Constant::Int(0)) => Minimum, @@ -2053,8 +2053,8 @@ impl Ord for FullInt { fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_>, expr: &'a Expr<'_>) -> Option<(FullInt, FullInt)> { if let ExprKind::Cast(ref cast_exp, _) = expr.kind { - let pre_cast_ty = cx.tables().expr_ty(cast_exp); - let cast_ty = cx.tables().expr_ty(expr); + let pre_cast_ty = cx.typeck_results().expr_ty(cast_exp); + let cast_ty = cx.typeck_results().expr_ty(expr); // if it's a cast from i32 to u32 wrapping will invalidate all these checks if cx.layout_of(pre_cast_ty).ok().map(|l| l.size) == cx.layout_of(cast_ty).ok().map(|l| l.size) { return None; @@ -2084,9 +2084,9 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_>, expr: &'a Expr<'_>) -> } fn node_as_const_fullint<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option { - let val = constant(cx, cx.tables(), expr)?.0; + let val = constant(cx, cx.typeck_results(), expr)?.0; if let Constant::Int(const_int) = val { - match cx.tables().expr_ty(expr).kind { + match cx.typeck_results().expr_ty(expr).kind { ty::Int(ity) => Some(FullInt::S(sext(cx.tcx, const_int, ity))), ty::Uint(_) => Some(FullInt::U(const_int)), _ => None, @@ -2472,7 +2472,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> { /// Looks for default-hasher-dependent constructors like `HashMap::new`. struct ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { cx: &'a LateContext<'tcx>, - maybe_typeck_tables: Option<&'tcx TypeckTables<'tcx>>, + maybe_typeck_results: Option<&'tcx TypeckResults<'tcx>>, target: &'b ImplicitHasherType<'tcx>, suggestions: BTreeMap, } @@ -2481,7 +2481,7 @@ impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { fn new(cx: &'a LateContext<'tcx>, target: &'b ImplicitHasherType<'tcx>) -> Self { Self { cx, - maybe_typeck_tables: cx.maybe_typeck_tables(), + maybe_typeck_results: cx.maybe_typeck_results(), target, suggestions: BTreeMap::new(), } @@ -2492,9 +2492,9 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't type Map = Map<'tcx>; fn visit_body(&mut self, body: &'tcx Body<'_>) { - let old_maybe_typeck_tables = self.maybe_typeck_tables.replace(self.cx.tcx.body_tables(body.id())); + let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body.id())); walk_body(self, body); - self.maybe_typeck_tables = old_maybe_typeck_tables; + self.maybe_typeck_results = old_maybe_typeck_results; } fn visit_expr(&mut self, e: &'tcx Expr<'_>) { @@ -2503,7 +2503,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't if let ExprKind::Path(QPath::TypeRelative(ref ty, ref method)) = fun.kind; if let TyKind::Path(QPath::Resolved(None, ty_path)) = ty.kind; then { - if !TyS::same_type(self.target.ty(), self.maybe_typeck_tables.unwrap().expr_ty(e)) { + if !TyS::same_type(self.target.ty(), self.maybe_typeck_results.unwrap().expr_ty(e)) { return; } @@ -2589,7 +2589,7 @@ impl<'tcx> LateLintPass<'tcx> for RefToMut { if let TyKind::Ptr(MutTy { mutbl: Mutability::Mut, .. }) = t.kind; if let ExprKind::Cast(e, t) = &e.kind; if let TyKind::Ptr(MutTy { mutbl: Mutability::Not, .. }) = t.kind; - if let ty::Ref(..) = cx.tables().node_type(e.hir_id).kind; + if let ty::Ref(..) = cx.typeck_results().node_type(e.hir_id).kind; then { span_lint( cx, diff --git a/clippy_lints/src/unnamed_address.rs b/clippy_lints/src/unnamed_address.rs index 25d136e564d3..28b393b9f11f 100644 --- a/clippy_lints/src/unnamed_address.rs +++ b/clippy_lints/src/unnamed_address.rs @@ -65,14 +65,14 @@ impl LateLintPass<'_> for UnnamedAddress { } fn is_trait_ptr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - match cx.tables().expr_ty_adjusted(expr).kind { + match cx.typeck_results().expr_ty_adjusted(expr).kind { ty::RawPtr(ty::TypeAndMut { ty, .. }) => ty.is_trait(), _ => false, } } fn is_fn_def(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - matches!(cx.tables().expr_ty(expr).kind, ty::FnDef(..)) + matches!(cx.typeck_results().expr_ty(expr).kind, ty::FnDef(..)) } if_chain! { @@ -98,7 +98,7 @@ impl LateLintPass<'_> for UnnamedAddress { if match_def_path(cx, def_id, &paths::PTR_EQ) || match_def_path(cx, def_id, &paths::RC_PTR_EQ) || match_def_path(cx, def_id, &paths::ARC_PTR_EQ); - let ty_param = cx.tables().node_substs(func.hir_id).type_at(0); + let ty_param = cx.typeck_results().node_substs(func.hir_id).type_at(0); if ty_param.is_trait(); then { span_lint_and_help( @@ -115,8 +115,8 @@ impl LateLintPass<'_> for UnnamedAddress { if_chain! { if let ExprKind::Binary(binop, ref left, ref right) = expr.kind; if is_comparison(binop.node); - if cx.tables().expr_ty_adjusted(left).is_fn_ptr() && - cx.tables().expr_ty_adjusted(right).is_fn_ptr(); + if cx.typeck_results().expr_ty_adjusted(left).is_fn_ptr() && + cx.typeck_results().expr_ty_adjusted(right).is_fn_ptr(); if is_fn_def(cx, left) || is_fn_def(cx, right); then { span_lint( diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index 91c1789a2ffb..59993d25bb47 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -176,7 +176,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { if let name = name_ident.ident.name.to_ident_string(); if name == "sort_by" || name == "sort_unstable_by"; if let [vec, Expr { kind: ExprKind::Closure(_, _, closure_body_id, _, _), .. }] = args; - if utils::match_type(cx, &cx.tables().expr_ty(vec), &paths::VEC); + if utils::match_type(cx, &cx.typeck_results().expr_ty(vec), &paths::VEC); if let closure_body = cx.tcx.hir().body(*closure_body_id); if let &[ Param { pat: Pat { kind: PatKind::Binding(_, _, left_ident, _), .. }, ..}, diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 56ff62eca033..f2bbde28c2ab 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -114,7 +114,7 @@ fn collect_unwrap_info<'tcx>( if_chain! { if let ExprKind::MethodCall(method_name, _, args, _) = &expr.kind; if let ExprKind::Path(QPath::Resolved(None, path)) = &args[0].kind; - let ty = cx.tables().expr_ty(&args[0]); + let ty = cx.typeck_results().expr_ty(&args[0]); let name = method_name.ident.as_str(); if is_relevant_option_call(cx, ty, &name) || is_relevant_result_call(cx, ty, &name); then { diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 69c0b092520d..a48ad3185e9c 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -63,8 +63,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { ExprKind::MethodCall(ref name, .., ref args, _) => { if match_trait_method(cx, e, &paths::INTO) && &*name.ident.as_str() == "into" { - let a = cx.tables().expr_ty(e); - let b = cx.tables().expr_ty(&args[0]); + let a = cx.typeck_results().expr_ty(e); + let b = cx.typeck_results().expr_ty(&args[0]); if TyS::same_type(a, b) { let sugg = snippet_with_macro_callsite(cx, args[0].span, "").to_string(); span_lint_and_sugg( @@ -79,8 +79,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { } } if match_trait_method(cx, e, &paths::INTO_ITERATOR) && &*name.ident.as_str() == "into_iter" { - let a = cx.tables().expr_ty(e); - let b = cx.tables().expr_ty(&args[0]); + let a = cx.typeck_results().expr_ty(e); + let b = cx.typeck_results().expr_ty(&args[0]); if TyS::same_type(a, b) { let sugg = snippet(cx, args[0].span, "").into_owned(); span_lint_and_sugg( @@ -96,8 +96,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { } if match_trait_method(cx, e, &paths::TRY_INTO_TRAIT) && &*name.ident.as_str() == "try_into" { if_chain! { - let a = cx.tables().expr_ty(e); - let b = cx.tables().expr_ty(&args[0]); + let a = cx.typeck_results().expr_ty(e); + let b = cx.typeck_results().expr_ty(&args[0]); if is_type_diagnostic_item(cx, a, sym!(result_type)); if let ty::Adt(_, substs) = a.kind; if let Some(a_type) = substs.types().next(); @@ -122,8 +122,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { if args.len() == 1; if let ExprKind::Path(ref qpath) = path.kind; if let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id(); - let a = cx.tables().expr_ty(e); - let b = cx.tables().expr_ty(&args[0]); + let a = cx.typeck_results().expr_ty(e); + let b = cx.typeck_results().expr_ty(&args[0]); then { if_chain! { diff --git a/clippy_lints/src/utils/higher.rs b/clippy_lints/src/utils/higher.rs index eb7ac2447e49..f81a132c7e7b 100644 --- a/clippy_lints/src/utils/higher.rs +++ b/clippy_lints/src/utils/higher.rs @@ -56,7 +56,7 @@ pub fn range<'a, 'tcx>(cx: &LateContext<'tcx>, expr: &'a hir::Expr<'_>) -> Optio Some(expr) } - let def_path = match cx.tables().expr_ty(expr).kind { + let def_path = match cx.typeck_results().expr_ty(expr).kind { ty::Adt(def, _) => cx.tcx.def_path(def.did), _ => return None, }; diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index 34341594c198..28fb6ed12a05 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -9,7 +9,7 @@ use rustc_hir::{ }; use rustc_lint::LateContext; use rustc_middle::ich::StableHashingContextProvider; -use rustc_middle::ty::TypeckTables; +use rustc_middle::ty::TypeckResults; use rustc_span::Symbol; use std::hash::Hash; @@ -22,7 +22,7 @@ use std::hash::Hash; pub struct SpanlessEq<'a, 'tcx> { /// Context used to evaluate constant expressions. cx: &'a LateContext<'tcx>, - maybe_typeck_tables: Option<&'tcx TypeckTables<'tcx>>, + maybe_typeck_results: Option<&'tcx TypeckResults<'tcx>>, /// If is true, never consider as equal expressions containing function /// calls. ignore_fn: bool, @@ -32,7 +32,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { pub fn new(cx: &'a LateContext<'tcx>) -> Self { Self { cx, - maybe_typeck_tables: cx.maybe_typeck_tables(), + maybe_typeck_results: cx.maybe_typeck_results(), ignore_fn: false, } } @@ -71,10 +71,10 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { return false; } - if let Some(tables) = self.maybe_typeck_tables { + if let Some(typeck_results) = self.maybe_typeck_results { if let (Some(l), Some(r)) = ( - constant_simple(self.cx, tables, left), - constant_simple(self.cx, tables, right), + constant_simple(self.cx, typeck_results, left), + constant_simple(self.cx, typeck_results, right), ) { if l == r { return true; @@ -137,9 +137,9 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { !self.ignore_fn && self.eq_path_segment(l_path, r_path) && self.eq_exprs(l_args, r_args) }, (&ExprKind::Repeat(ref le, ref ll_id), &ExprKind::Repeat(ref re, ref rl_id)) => { - let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id.body)); + let mut celcx = constant_context(self.cx, self.cx.tcx.typeck_body(ll_id.body)); let ll = celcx.expr(&self.cx.tcx.hir().body(ll_id.body).value); - let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id.body)); + let mut celcx = constant_context(self.cx, self.cx.tcx.typeck_body(rl_id.body)); let rl = celcx.expr(&self.cx.tcx.hir().body(rl_id.body).value); self.eq_expr(le, re) && ll == rl @@ -272,18 +272,18 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { match (left, right) { (&TyKind::Slice(ref l_vec), &TyKind::Slice(ref r_vec)) => self.eq_ty(l_vec, r_vec), (&TyKind::Array(ref lt, ref ll_id), &TyKind::Array(ref rt, ref rl_id)) => { - let old_maybe_typeck_tables = self.maybe_typeck_tables; + let old_maybe_typeck_results = self.maybe_typeck_results; - let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id.body)); - self.maybe_typeck_tables = Some(self.cx.tcx.body_tables(ll_id.body)); + let mut celcx = constant_context(self.cx, self.cx.tcx.typeck_body(ll_id.body)); + self.maybe_typeck_results = Some(self.cx.tcx.typeck_body(ll_id.body)); let ll = celcx.expr(&self.cx.tcx.hir().body(ll_id.body).value); - let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id.body)); - self.maybe_typeck_tables = Some(self.cx.tcx.body_tables(rl_id.body)); + let mut celcx = constant_context(self.cx, self.cx.tcx.typeck_body(rl_id.body)); + self.maybe_typeck_results = Some(self.cx.tcx.typeck_body(rl_id.body)); let rl = celcx.expr(&self.cx.tcx.hir().body(rl_id.body).value); let eq_ty = self.eq_ty(lt, rt); - self.maybe_typeck_tables = old_maybe_typeck_tables; + self.maybe_typeck_results = old_maybe_typeck_results; eq_ty && ll == rl }, (&TyKind::Ptr(ref l_mut), &TyKind::Ptr(ref r_mut)) => { @@ -348,7 +348,7 @@ pub fn over(left: &[X], right: &[X], mut eq_fn: impl FnMut(&X, &X) -> bool) - pub struct SpanlessHash<'a, 'tcx> { /// Context used to evaluate constant expressions. cx: &'a LateContext<'tcx>, - maybe_typeck_tables: Option<&'tcx TypeckTables<'tcx>>, + maybe_typeck_results: Option<&'tcx TypeckResults<'tcx>>, s: StableHasher, } @@ -356,7 +356,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { pub fn new(cx: &'a LateContext<'tcx>) -> Self { Self { cx, - maybe_typeck_tables: cx.maybe_typeck_tables(), + maybe_typeck_results: cx.maybe_typeck_results(), s: StableHasher::new(), } } @@ -386,8 +386,8 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { #[allow(clippy::many_single_char_names, clippy::too_many_lines)] pub fn hash_expr(&mut self, e: &Expr<'_>) { let simple_const = self - .maybe_typeck_tables - .and_then(|tables| constant_simple(self.cx, tables, e)); + .maybe_typeck_results + .and_then(|typeck_results| constant_simple(self.cx, typeck_results, e)); // const hashing may result in the same hash as some unrelated node, so add a sort of // discriminant depending on which path we're choosing next @@ -458,7 +458,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { CaptureBy::Ref => 1, } .hash(&mut self.s); - // closures inherit TypeckTables + // closures inherit TypeckResults self.hash_expr(&self.cx.tcx.hir().body(eid).value); }, ExprKind::Field(ref e, ref f) => { @@ -602,7 +602,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_name(path.ident.name); }, } - // self.maybe_typeck_tables.unwrap().qpath_res(p, id).hash(&mut self.s); + // self.maybe_typeck_results.unwrap().qpath_res(p, id).hash(&mut self.s); } pub fn hash_path(&mut self, p: &Path<'_>) { @@ -725,10 +725,10 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } pub fn hash_body(&mut self, body_id: BodyId) { - // swap out TypeckTables when hashing a body - let old_maybe_typeck_tables = self.maybe_typeck_tables.replace(self.cx.tcx.body_tables(body_id)); + // swap out TypeckResults when hashing a body + let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body_id)); self.hash_expr(&self.cx.tcx.hir().body(body_id).value); - self.maybe_typeck_tables = old_maybe_typeck_tables; + self.maybe_typeck_results = old_maybe_typeck_results; } fn hash_generic_args(&mut self, arg_list: &[GenericArg<'_>]) { diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index fbd103323e31..d8fa1fa278e2 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector { } match stmt.kind { hir::StmtKind::Local(ref local) => { - println!("local variable of type {}", cx.tables().node_type(local.hir_id)); + println!("local variable of type {}", cx.typeck_results().node_type(local.hir_id)); println!("pattern:"); print_pat(cx, &local.pat, 0); if let Some(ref e) = local.init { @@ -144,8 +144,12 @@ fn has_attr(sess: &Session, attrs: &[Attribute]) -> bool { fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { let ind = " ".repeat(indent); println!("{}+", ind); - println!("{}ty: {}", ind, cx.tables().expr_ty(expr)); - println!("{}adjustments: {:?}", ind, cx.tables().adjustments().get(expr.hir_id)); + println!("{}ty: {}", ind, cx.typeck_results().expr_ty(expr)); + println!( + "{}adjustments: {:?}", + ind, + cx.typeck_results().adjustments().get(expr.hir_id) + ); match expr.kind { hir::ExprKind::Box(ref e) => { println!("{}Box", ind); diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 38cb764adde7..6c2356799142 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -405,7 +405,7 @@ impl<'tcx> LateLintPass<'tcx> for CompilerLintFunctions { if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; let fn_name = path.ident; if let Some(sugg) = self.map.get(&*fn_name.as_str()); - let ty = walk_ptrs_ty(cx.tables().expr_ty(&args[0])); + let ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0])); if match_type(cx, ty, &paths::EARLY_CONTEXT) || match_type(cx, ty, &paths::LATE_CONTEXT); then { @@ -438,7 +438,7 @@ impl<'tcx> LateLintPass<'tcx> for OuterExpnDataPass { let args = arg_lists[1]; if args.len() == 1; let self_arg = &args[0]; - let self_ty = walk_ptrs_ty(cx.tables().expr_ty(self_arg)); + let self_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(self_arg)); if match_type(cx, self_ty, &paths::SYNTAX_CONTEXT); then { span_lint_and_sugg( diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 4b7a1c2b537f..4b163fba5289 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -144,7 +144,7 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symb /// Checks if the method call given in `expr` belongs to the given trait. pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str]) -> bool { - let def_id = cx.tables().type_dependent_def_id(expr.hir_id).unwrap(); + let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap(); let trt_id = cx.tcx.trait_of_item(def_id); trt_id.map_or(false, |trt_id| match_def_path(cx, trt_id, path)) } @@ -278,10 +278,8 @@ pub fn qpath_res(cx: &LateContext<'_>, qpath: &hir::QPath<'_>, id: hir::HirId) - match qpath { hir::QPath::Resolved(_, path) => path.res, hir::QPath::TypeRelative(..) => { - if cx.tcx.has_typeck_tables(id.owner.to_def_id()) { - cx.tcx - .typeck_tables_of(id.owner.to_def_id().expect_local()) - .qpath_res(qpath, id) + if cx.tcx.has_typeck_results(id.owner.to_def_id()) { + cx.tcx.typeck(id.owner.to_def_id().expect_local()).qpath_res(qpath, id) } else { Res::Err } @@ -772,7 +770,7 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool let parent_item = map.get_parent_item(e.hir_id); if let Some((Constant::Int(v), _)) = map .maybe_body_owned_by(parent_item) - .and_then(|body_id| constant(cx, cx.tcx.body_tables(body_id), e)) + .and_then(|body_id| constant(cx, cx.tcx.typeck_body(body_id), e)) { value == v } else { @@ -799,7 +797,7 @@ pub fn is_integer_literal(expr: &Expr<'_>, value: u128) -> bool { /// See `rustc_middle::ty::adjustment::Adjustment` and `rustc_typeck::check::coercion` for more /// information on adjustments and coercions. pub fn is_adjusted(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { - cx.tables().adjustments().get(e.hir_id).is_some() + cx.typeck_results().adjustments().get(e.hir_id).is_some() } /// Returns the pre-expansion span if is this comes from an expansion of the @@ -916,7 +914,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, pats.iter().map(|pat| &**pat)) }, PatKind::Slice(ref head, ref middle, ref tail) => { - match &cx.tables().node_type(pat.hir_id).kind { + match &cx.typeck_results().node_type(pat.hir_id).kind { ty::Slice(..) => { // [..] is the only irrefutable slice pattern. !head.is_empty() || middle.is_none() || !tail.is_empty() @@ -1299,7 +1297,7 @@ pub fn is_must_use_func_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { None } }, - ExprKind::MethodCall(_, _, _, _) => cx.tables().type_dependent_def_id(expr.hir_id), + ExprKind::MethodCall(_, _, _, _) => cx.typeck_results().type_dependent_def_id(expr.hir_id), _ => None, }; @@ -1359,14 +1357,14 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool { /// Returns the `DefId` of the callee if the given expression is a function or method call. pub fn fn_def_id(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { match &expr.kind { - ExprKind::MethodCall(..) => cx.tables().type_dependent_def_id(expr.hir_id), + ExprKind::MethodCall(..) => cx.typeck_results().type_dependent_def_id(expr.hir_id), ExprKind::Call( Expr { kind: ExprKind::Path(qpath), .. }, .., - ) => cx.tables().qpath_res(qpath, expr.hir_id).opt_def_id(), + ) => cx.typeck_results().qpath_res(qpath, expr.hir_id).opt_def_id(), _ => None, } } diff --git a/clippy_lints/src/utils/usage.rs b/clippy_lints/src/utils/usage.rs index 53d3a241f58a..4a64b935ac9b 100644 --- a/clippy_lints/src/utils/usage.rs +++ b/clippy_lints/src/utils/usage.rs @@ -18,7 +18,14 @@ pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) -> }; let def_id = expr.hir_id.owner.to_def_id(); cx.tcx.infer_ctxt().enter(|infcx| { - ExprUseVisitor::new(&mut delegate, &infcx, def_id.expect_local(), cx.param_env, cx.tables()).walk_expr(expr); + ExprUseVisitor::new( + &mut delegate, + &infcx, + def_id.expect_local(), + cx.param_env, + cx.typeck_results(), + ) + .walk_expr(expr); }); if delegate.skip { diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index e1043c36e0a5..f2e76442a19b 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -37,7 +37,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { // search for `&vec![_]` expressions where the adjusted type is `&[_]` if_chain! { - if let ty::Ref(_, ty, _) = cx.tables().expr_ty_adjusted(expr).kind; + if let ty::Ref(_, ty, _) = cx.typeck_results().expr_ty_adjusted(expr).kind; if let ty::Slice(..) = ty.kind; if let ExprKind::AddrOf(BorrowKind::Ref, _, ref addressee) = expr.kind; if let Some(vec_args) = higher::vec_macro(cx, addressee); @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec { if_chain! { if let Some((_, arg, _)) = higher::for_loop(expr); if let Some(vec_args) = higher::vec_macro(cx, arg); - if is_copy(cx, vec_type(cx.tables().expr_ty_adjusted(arg))); + if is_copy(cx, vec_type(cx.typeck_results().expr_ty_adjusted(arg))); then { // report the error around the `vec!` not inside `:` let span = arg.span @@ -70,7 +70,7 @@ fn check_vec_macro<'tcx>(cx: &LateContext<'tcx>, vec_args: &higher::VecArgs<'tcx let mut applicability = Applicability::MachineApplicable; let snippet = match *vec_args { higher::VecArgs::Repeat(elem, len) => { - if constant(cx, cx.tables(), len).is_some() { + if constant(cx, cx.typeck_results(), len).is_some() { format!( "&[{}; {}]", snippet_with_applicability(cx, elem.span, "elem", &mut applicability), diff --git a/clippy_lints/src/vec_resize_to_zero.rs b/clippy_lints/src/vec_resize_to_zero.rs index cc5e21a7ca6f..ad73a1ea1acd 100644 --- a/clippy_lints/src/vec_resize_to_zero.rs +++ b/clippy_lints/src/vec_resize_to_zero.rs @@ -32,7 +32,7 @@ impl<'tcx> LateLintPass<'tcx> for VecResizeToZero { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let hir::ExprKind::MethodCall(path_segment, _, ref args, _) = expr.kind; - if let Some(method_def_id) = cx.tables().type_dependent_def_id(expr.hir_id); + if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if match_def_path(cx, method_def_id, &paths::VEC_RESIZE) && args.len() == 3; if let ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = args[1].kind; if let ExprKind::Lit(Spanned { node: LitKind::Int(..), .. }) = args[2].kind; diff --git a/clippy_lints/src/verbose_file_reads.rs b/clippy_lints/src/verbose_file_reads.rs index b06fe36da631..32574d9d6c9a 100644 --- a/clippy_lints/src/verbose_file_reads.rs +++ b/clippy_lints/src/verbose_file_reads.rs @@ -62,7 +62,7 @@ fn is_file_read_to_end<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> if let ExprKind::MethodCall(method_name, _, exprs, _) = expr.kind; if method_name.ident.as_str() == "read_to_end"; if let ExprKind::Path(QPath::Resolved(None, _)) = &exprs[0].kind; - let ty = cx.tables().expr_ty(&exprs[0]); + let ty = cx.typeck_results().expr_ty(&exprs[0]); if match_type(cx, ty, &paths::FILE); then { return true @@ -76,7 +76,7 @@ fn is_file_read_to_string<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) if let ExprKind::MethodCall(method_name, _, exprs, _) = expr.kind; if method_name.ident.as_str() == "read_to_string"; if let ExprKind::Path(QPath::Resolved(None, _)) = &exprs[0].kind; - let ty = cx.tables().expr_ty(&exprs[0]); + let ty = cx.typeck_results().expr_ty(&exprs[0]); if match_type(cx, ty, &paths::FILE); then { return true diff --git a/clippy_lints/src/zero_div_zero.rs b/clippy_lints/src/zero_div_zero.rs index 1e011ea9cba5..4b81a27632d8 100644 --- a/clippy_lints/src/zero_div_zero.rs +++ b/clippy_lints/src/zero_div_zero.rs @@ -36,8 +36,8 @@ impl<'tcx> LateLintPass<'tcx> for ZeroDiv { // TODO - constant_simple does not fold many operations involving floats. // That's probably fine for this lint - it's pretty unlikely that someone would // do something like 0.0/(2.0 - 2.0), but it would be nice to warn on that case too. - if let Some(lhs_value) = constant_simple(cx, cx.tables(), left); - if let Some(rhs_value) = constant_simple(cx, cx.tables(), right); + if let Some(lhs_value) = constant_simple(cx, cx.typeck_results(), left); + if let Some(rhs_value) = constant_simple(cx, cx.typeck_results(), right); if Constant::F32(0.0) == lhs_value || Constant::F64(0.0) == lhs_value; if Constant::F32(0.0) == rhs_value || Constant::F64(0.0) == rhs_value; then { diff --git a/doc/common_tools_writing_lints.md b/doc/common_tools_writing_lints.md index 412ff99314d9..9dd4c8a5f7a7 100644 --- a/doc/common_tools_writing_lints.md +++ b/doc/common_tools_writing_lints.md @@ -23,7 +23,7 @@ Sometimes you may want to retrieve the type `Ty` of an expression `Expr`, for ex - is it a primitive type? - does it implement a trait? -This operation is performed using the [`expr_ty()`][expr_ty] method from the [`TypeckTables`][TypeckTables] struct, +This operation is performed using the [`expr_ty()`][expr_ty] method from the [`TypeckResults`][TypeckResults] struct, that gives you access to the underlying structure [`TyS`][TyS]. Example of use: @@ -31,7 +31,7 @@ Example of use: impl LateLintPass<'_> for MyStructLint { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { // Get type of `expr` - let ty = cx.tables().expr_ty(expr); + let ty = cx.typeck_results().expr_ty(expr); // Match its kind to enter its type match ty.kind { ty::Adt(adt_def, _) if adt_def.is_struct() => println!("Our `expr` is a struct!"), @@ -41,14 +41,14 @@ impl LateLintPass<'_> for MyStructLint { } ``` -Similarly in [`TypeckTables`][TypeckTables] methods, you have the [`pat_ty()`][pat_ty] method +Similarly in [`TypeckResults`][TypeckResults] methods, you have the [`pat_ty()`][pat_ty] method to retrieve a type from a pattern. Two noticeable items here: - `cx` is the lint context [`LateContext`][LateContext]. The two most useful data structures in this context are `tcx` and `tables`, allowing us to jump to type definitions and other compilation stages such as HIR. -- `tables` is [`TypeckTables`][TypeckTables] and is created by type checking step, +- `tables` is [`TypeckResults`][TypeckResults] and is created by type checking step, it includes useful information such as types of expressions, ways to resolve methods and so on. # Checking if an expr is calling a specific method @@ -87,7 +87,7 @@ impl LateLintPass<'_> for MyStructLint { } // 2. Using type context `TyCtxt` - let ty = cx.tables().expr_ty(expr); + let ty = cx.typeck_results().expr_ty(expr); if cx.tcx.lang_items() // we are looking for the `DefId` of `Drop` trait in lang items .drop_trait() @@ -192,9 +192,9 @@ assert_eq!(differing_macro_contexts(x_is_some_span, x_unwrap_span), true); [TyS]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyS.html [TyKind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html -[TypeckTables]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckTables.html -[expr_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckTables.html#method.expr_ty +[TypeckResults]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html +[expr_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html#method.expr_ty [LateContext]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LateContext.html [TyCtxt]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html -[pat_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TypeckTables.html#method.pat_ty +[pat_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TypeckResults.html#method.pat_ty [paths]: ../clippy_lints/src/utils/paths.rs From a5c3d1288712c4fd61883b1e2372e9e8ee735b46 Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 22 Jun 2020 13:22:45 +0100 Subject: [PATCH 0042/1222] trait_sel: only test predicates w/ no substs This commit modifies the `substitute_normalize_and_test_predicates` query, renaming it to `impossible_predicates` and only checking predicates which do not require substs. By making this change, polymorphization doesn't have to explicitly support vtables. Signed-off-by: David Wood --- clippy_lints/src/utils/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 4b163fba5289..a4bee1c27805 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1346,7 +1346,7 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool { .predicates .iter() .filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None }); - !traits::normalize_and_test_predicates( + traits::impossible_predicates( cx.tcx, traits::elaborate_predicates(cx.tcx, predicates) .map(|o| o.predicate) From d31fdd4e41441cececde5ec24b7a4d80cc16e663 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Fri, 19 Jun 2020 10:22:25 +0200 Subject: [PATCH 0043/1222] clippy --- clippy_lints/src/future_not_send.rs | 11 +++++------ clippy_lints/src/methods/mod.rs | 9 +++------ clippy_lints/src/needless_pass_by_value.rs | 20 ++++++++++++-------- clippy_lints/src/utils/mod.rs | 4 ++-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 92c7e66a0eb8..ae28015b4c9e 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -3,7 +3,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{Opaque, PredicateKind::Trait, ToPolyTraitRef}; +use rustc_middle::ty::{Opaque, PredicateKind::Trait}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt; @@ -91,12 +91,11 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { cx.tcx.infer_ctxt().enter(|infcx| { for FulfillmentError { obligation, .. } in send_errors { infcx.maybe_note_obligation_cause_for_async_await(db, &obligation); - if let Trait(trait_pred, _) = obligation.predicate.kind() { - let trait_ref = trait_pred.to_poly_trait_ref(); - db.note(&*format!( + if let Trait(trait_pred, _) = obligation.predicate.ignore_qualifiers().skip_binder().kind() { + db.note(&format!( "`{}` doesn't implement `{}`", - trait_ref.skip_binder().self_ty(), - trait_ref.print_only_trait_path(), + trait_pred.self_ty(), + trait_pred.trait_ref.print_only_trait_path(), )); } } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 97cc58023f55..c3cdaeedd195 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1558,13 +1558,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods { // if return type is impl trait, check the associated types if let ty::Opaque(def_id, _) = ret_ty.kind { // one of the associated types must be Self - for predicate in cx.tcx.predicates_of(def_id).predicates { - if let ty::PredicateKind::Projection(poly_projection_predicate) = predicate.0.kind() { - let binder = poly_projection_predicate.ty(); - let associated_type = binder.skip_binder(); - + for &(predicate, _span) in cx.tcx.predicates_of(def_id).predicates { + if let ty::PredicateKind::Projection(projection_predicate) = predicate.ignore_qualifiers().skip_binder().kind() { // walk the associated type and check for Self - if contains_self_ty(associated_type) { + if contains_self_ty(projection_predicate.ty) { return; } } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 81774b617ac2..e39fb23365a2 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -114,12 +114,12 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds().iter()) .filter(|p| !p.is_global()) .filter_map(|obligation| { - if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate.kind() { - if poly_trait_ref.def_id() == sized_trait || poly_trait_ref.skip_binder().has_escaping_bound_vars() - { + // Note that we do not want to deal with qualified predicates here. + if let ty::PredicateKind::Trait(pred, _) = obligation.predicate.kind() { + if pred.def_id() == sized_trait { return None; } - Some(poly_trait_ref) + Some(pred) } else { None } @@ -159,14 +159,13 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { } } - // // * Exclude a type that is specifically bounded by `Borrow`. // * Exclude a type whose reference also fulfills its bound. (e.g., `std::convert::AsRef`, // `serde::Serialize`) let (implements_borrow_trait, all_borrowable_trait) = { let preds = preds .iter() - .filter(|t| t.skip_binder().self_ty() == ty) + .filter(|t| t.self_ty() == ty) .collect::>(); ( @@ -174,8 +173,13 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { !preds.is_empty() && { let ty_empty_region = cx.tcx.mk_imm_ref(cx.tcx.lifetimes.re_root_empty, ty); preds.iter().all(|t| { - let ty_params = &t.skip_binder().trait_ref.substs.iter().skip(1).collect::>(); - implements_trait(cx, ty_empty_region, t.def_id(), ty_params) + let ty_params = t + .trait_ref + .substs + .iter() + .skip(1) + .collect::>(); + implements_trait(cx, ty_empty_region, t.def_id(), &ty_params) }) }, ) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index a4bee1c27805..426772f3e9a9 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1263,8 +1263,8 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates { - if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate.kind() { - if must_use_attr(&cx.tcx.get_attrs(poly_trait_predicate.skip_binder().trait_ref.def_id)).is_some() { + if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.ignore_qualifiers().skip_binder().kind() { + if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() { return true; } } From bfe473d26ce0fb8068b9a88ec513c8ec719c8bff Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Wed, 24 Jun 2020 17:40:28 +0200 Subject: [PATCH 0044/1222] this might be unqualified, but at least it's now quantified --- clippy_lints/src/future_not_send.rs | 2 +- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/utils/mod.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index ae28015b4c9e..7eeb6a75ea7b 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { cx.tcx.infer_ctxt().enter(|infcx| { for FulfillmentError { obligation, .. } in send_errors { infcx.maybe_note_obligation_cause_for_async_await(db, &obligation); - if let Trait(trait_pred, _) = obligation.predicate.ignore_qualifiers().skip_binder().kind() { + if let Trait(trait_pred, _) = obligation.predicate.ignore_quantifiers().skip_binder().kind() { db.note(&format!( "`{}` doesn't implement `{}`", trait_pred.self_ty(), diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index c3cdaeedd195..a450d5f16f8c 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1559,7 +1559,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let ty::Opaque(def_id, _) = ret_ty.kind { // one of the associated types must be Self for &(predicate, _span) in cx.tcx.predicates_of(def_id).predicates { - if let ty::PredicateKind::Projection(projection_predicate) = predicate.ignore_qualifiers().skip_binder().kind() { + if let ty::PredicateKind::Projection(projection_predicate) = predicate.ignore_quantifiers().skip_binder().kind() { // walk the associated type and check for Self if contains_self_ty(projection_predicate.ty) { return; diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 426772f3e9a9..c4603418ee3c 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1263,7 +1263,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates { - if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.ignore_qualifiers().skip_binder().kind() { + if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.ignore_quantifiers().skip_binder().kind() { if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() { return true; } From 0e79c5d2166132f1a72b69c5a4936d5d52265b96 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Thu, 9 Jul 2020 00:35:55 +0200 Subject: [PATCH 0045/1222] introduce PredicateAtom --- clippy_lints/src/future_not_send.rs | 4 ++-- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/utils/mod.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 7eeb6a75ea7b..0fdb5b8c2a48 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -3,7 +3,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{Opaque, PredicateKind::Trait}; +use rustc_middle::ty::{Opaque, PredicateAtom::Trait}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt; @@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { cx.tcx.infer_ctxt().enter(|infcx| { for FulfillmentError { obligation, .. } in send_errors { infcx.maybe_note_obligation_cause_for_async_await(db, &obligation); - if let Trait(trait_pred, _) = obligation.predicate.ignore_quantifiers().skip_binder().kind() { + if let Trait(trait_pred, _) = obligation.predicate.skip_binders() { db.note(&format!( "`{}` doesn't implement `{}`", trait_pred.self_ty(), diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index a450d5f16f8c..2c70183d8766 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1559,7 +1559,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let ty::Opaque(def_id, _) = ret_ty.kind { // one of the associated types must be Self for &(predicate, _span) in cx.tcx.predicates_of(def_id).predicates { - if let ty::PredicateKind::Projection(projection_predicate) = predicate.ignore_quantifiers().skip_binder().kind() { + if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() { // walk the associated type and check for Self if contains_self_ty(projection_predicate.ty) { return; diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index e39fb23365a2..095778777449 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { .filter(|p| !p.is_global()) .filter_map(|obligation| { // Note that we do not want to deal with qualified predicates here. - if let ty::PredicateKind::Trait(pred, _) = obligation.predicate.kind() { + if let ty::PredicateKind::Atom(ty::PredicateAtom::Trait(pred, _)) = obligation.predicate.kind() { if pred.def_id() == sized_trait { return None; } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index c4603418ee3c..655b1133cf74 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1263,7 +1263,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates { - if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.ignore_quantifiers().skip_binder().kind() { + if let ty::PredicateAtom::Trait(trait_predicate, _) = predicate.skip_binders() { if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() { return true; } From 098ea72eeed37c3700f559a4e89333bc0e7c8271 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Mon, 27 Jul 2020 21:17:28 +0200 Subject: [PATCH 0046/1222] clippy --- clippy_lints/src/unit_return_expecting_ord.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index ac6f3d125bb4..679aaec9fcd6 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -4,7 +4,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; -use rustc_middle::ty::{GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate}; +use rustc_middle::ty::{GenericPredicates, PredicateAtom, ProjectionPredicate, TraitPredicate}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{BytePos, Span}; @@ -42,8 +42,8 @@ fn get_trait_predicates_for_trait_id<'tcx>( let mut preds = Vec::new(); for (pred, _) in generics.predicates { if_chain! { - if let PredicateKind::Trait(poly_trait_pred, _) = pred.kind(); - let trait_pred = cx.tcx.erase_late_bound_regions(&poly_trait_pred); + if let PredicateAtom::Trait(poly_trait_pred, _) = pred.skip_binders(); + let trait_pred = cx.tcx.erase_late_bound_regions(&ty::Binder::bind(poly_trait_pred)); if let Some(trait_def_id) = trait_id; if trait_def_id == trait_pred.trait_ref.def_id; then { @@ -60,8 +60,8 @@ fn get_projection_pred<'tcx>( pred: TraitPredicate<'tcx>, ) -> Option> { generics.predicates.iter().find_map(|(proj_pred, _)| { - if let PredicateKind::Projection(proj_pred) = proj_pred.kind() { - let projection_pred = cx.tcx.erase_late_bound_regions(proj_pred); + if let ty::PredicateAtom::Projection(proj_pred) = proj_pred.skip_binders() { + let projection_pred = cx.tcx.erase_late_bound_regions(&ty::Binder::bind(proj_pred)); if projection_pred.projection_ty.substs == pred.trait_ref.substs { return Some(projection_pred); } From c88907f5cc4e3a87562bd48e569f47296cd3d31d Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Wed, 29 Jul 2020 13:45:20 +0200 Subject: [PATCH 0047/1222] Update clippy ui test. The reason we do not trigger these lints anymore is that clippy sets the mir-opt-level to 0, and the recent changes subtly changed how the const propagator works. --- tests/ui/indexing_slicing_index.stderr | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/tests/ui/indexing_slicing_index.stderr b/tests/ui/indexing_slicing_index.stderr index ac5f0d0a39e8..2b3f9be2dfb9 100644 --- a/tests/ui/indexing_slicing_index.stderr +++ b/tests/ui/indexing_slicing_index.stderr @@ -1,23 +1,3 @@ -error: this operation will panic at runtime - --> $DIR/indexing_slicing_index.rs:11:5 - | -LL | x[4]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. - | ^^^^ index out of bounds: the len is 4 but the index is 4 - | - = note: `#[deny(unconditional_panic)]` on by default - -error: this operation will panic at runtime - --> $DIR/indexing_slicing_index.rs:12:5 - | -LL | x[1 << 3]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. - | ^^^^^^^^^ index out of bounds: the len is 4 but the index is 8 - -error: this operation will panic at runtime - --> $DIR/indexing_slicing_index.rs:27:5 - | -LL | x[N]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. - | ^^^^ index out of bounds: the len is 4 but the index is 15 - error: indexing may panic. --> $DIR/indexing_slicing_index.rs:10:5 | @@ -75,5 +55,5 @@ LL | v[M]; | = help: Consider using `.get(n)` or `.get_mut(n)` instead -error: aborting due to 10 previous errors +error: aborting due to 7 previous errors From 1c9a4dd9a2c7c72be989f7548aa049e6ef6a42aa Mon Sep 17 00:00:00 2001 From: Valentin Lazureanu Date: Tue, 21 Jul 2020 09:09:27 +0000 Subject: [PATCH 0048/1222] Rename HAIR to THIR (Typed HIR). --- clippy_lints/src/utils/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 655b1133cf74..3f8e15d90297 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -883,7 +883,7 @@ pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_>, expr: &Expr<'_ } /// Returns `true` if a pattern is refutable. -// TODO: should be implemented using rustc/mir_build/hair machinery +// TODO: should be implemented using rustc/mir_build/thir machinery pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { fn is_enum_variant(cx: &LateContext<'_>, qpath: &QPath<'_>, id: HirId) -> bool { matches!( From 48a23a464d1dca2edafcc26e9d180ba91e4c39a9 Mon Sep 17 00:00:00 2001 From: liuzhenyu Date: Sun, 2 Aug 2020 23:20:00 +0800 Subject: [PATCH 0049/1222] fix typos --- tests/ui/formatting.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/formatting.rs b/tests/ui/formatting.rs index 078811b8d882..f54b3f2bfe28 100644 --- a/tests/ui/formatting.rs +++ b/tests/ui/formatting.rs @@ -149,7 +149,7 @@ fn main() { 1 + 2, 3 - 4, 5 ]; - // lint if it doesnt + // lint if it doesn't let _ = &[ -1 -4, From e16f596a9f82b7eeba799c65c869e8599c7ea284 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 2 Aug 2020 13:17:20 +0300 Subject: [PATCH 0050/1222] rustc_ast: `(Nested)MetaItem::check_name` -> `has_name` For consistency with `Attribute::has_name` which doesn't mark the attribute as used either. Replace all uses of `check_name` with `has_name` outside of rustc --- clippy_lints/src/attrs.rs | 18 +++++++++--------- clippy_lints/src/doc.rs | 2 +- clippy_lints/src/inline_fn_without_body.rs | 2 +- clippy_lints/src/manual_non_exhaustive.rs | 2 +- clippy_lints/src/missing_doc.rs | 2 +- clippy_lints/src/missing_inline.rs | 2 +- clippy_lints/src/needless_borrow.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/returns.rs | 2 +- clippy_lints/src/trivially_copy_pass_by_ref.rs | 2 +- clippy_lints/src/utils/conf.rs | 2 +- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 27a7fa886223..40af6bb3d7bc 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -286,14 +286,14 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { }, _ => {}, } - if items.is_empty() || !attr.check_name(sym!(deprecated)) { + if items.is_empty() || !attr.has_name(sym!(deprecated)) { return; } for item in items { if_chain! { if let NestedMetaItem::MetaItem(mi) = &item; if let MetaItemKind::NameValue(lit) = &mi.kind; - if mi.check_name(sym!(since)); + if mi.has_name(sym!(since)); then { check_semver(cx, item.span(), lit); } @@ -309,7 +309,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { } match item.kind { ItemKind::ExternCrate(..) | ItemKind::Use(..) => { - let skip_unused_imports = item.attrs.iter().any(|attr| attr.check_name(sym!(macro_use))); + let skip_unused_imports = item.attrs.iter().any(|attr| attr.has_name(sym!(macro_use))); for attr in item.attrs { if in_external_macro(cx.sess(), attr.span) { @@ -524,7 +524,7 @@ fn check_attrs(cx: &LateContext<'_>, span: Span, name: Name, attrs: &[Attribute] for attr in attrs { if let Some(values) = attr.meta_item_list() { - if values.len() != 1 || !attr.check_name(sym!(inline)) { + if values.len() != 1 || !attr.has_name(sym!(inline)) { continue; } if is_word(&values[0], sym!(always)) { @@ -558,7 +558,7 @@ fn check_semver(cx: &LateContext<'_>, span: Span, lit: &Lit) { fn is_word(nmi: &NestedMetaItem, expected: Symbol) -> bool { if let NestedMetaItem::MetaItem(mi) = &nmi { - mi.is_word() && mi.check_name(expected) + mi.is_word() && mi.has_name(expected) } else { false } @@ -618,15 +618,15 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::as fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute) { if_chain! { // check cfg_attr - if attr.check_name(sym!(cfg_attr)); + if attr.has_name(sym!(cfg_attr)); if let Some(items) = attr.meta_item_list(); if items.len() == 2; // check for `rustfmt` if let Some(feature_item) = items[0].meta_item(); - if feature_item.check_name(sym!(rustfmt)); + if feature_item.has_name(sym!(rustfmt)); // check for `rustfmt_skip` and `rustfmt::skip` if let Some(skip_item) = &items[1].meta_item(); - if skip_item.check_name(sym!(rustfmt_skip)) || + if skip_item.has_name(sym!(rustfmt_skip)) || skip_item.path.segments.last().expect("empty path in attribute").ident.name == sym!(skip); // Only lint outer attributes, because custom inner attributes are unstable // Tracking issue: https://github.com/rust-lang/rust/issues/54726 @@ -685,7 +685,7 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) { } if_chain! { - if attr.check_name(sym!(cfg)); + if attr.has_name(sym!(cfg)); if let Some(list) = attr.meta_item_list(); let mismatched = find_mismatched_target_os(&list); if !mismatched.is_empty(); diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index d52bb8961fae..e87c33d1b09d 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -323,7 +323,7 @@ fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs let (comment, current_spans) = strip_doc_comment_decoration(&comment, attr.span); spans.extend_from_slice(¤t_spans); doc.push_str(&comment); - } else if attr.check_name(sym!(doc)) { + } else if attr.has_name(sym!(doc)) { // ignore mix of sugared and non-sugared doc // don't trigger the safety or errors check return DocHeaders { diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index decbee278154..4b605fdb366a 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -41,7 +41,7 @@ impl<'tcx> LateLintPass<'tcx> for InlineFnWithoutBody { fn check_attrs(cx: &LateContext<'_>, name: Symbol, attrs: &[Attribute]) { for attr in attrs { - if !attr.check_name(sym!(inline)) { + if !attr.has_name(sym!(inline)) { continue; } diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index f3b8902e26f6..ca1381852dae 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -83,7 +83,7 @@ fn check_manual_non_exhaustive_enum(cx: &EarlyContext<'_>, item: &Item, variants } fn is_doc_hidden(attr: &Attribute) -> bool { - attr.check_name(sym!(doc)) + attr.has_name(sym!(doc)) && match attr.meta_item_list() { Some(l) => attr::list_contains_name(&l, sym!(hidden)), None => false, diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 06e0f43c10bb..813f9c439481 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn enter_lint_attrs(&mut self, _: &LateContext<'tcx>, attrs: &'tcx [ast::Attribute]) { let doc_hidden = self.doc_hidden() || attrs.iter().any(|attr| { - attr.check_name(sym!(doc)) + attr.has_name(sym!(doc)) && match attr.meta_item_list() { None => false, Some(l) => attr::list_contains_name(&l[..], sym!(hidden)), diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 9c9626735370..3eae45b2819d 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -57,7 +57,7 @@ declare_clippy_lint! { } fn check_missing_inline_attrs(cx: &LateContext<'_>, attrs: &[ast::Attribute], sp: Span, desc: &'static str) { - let has_inline = attrs.iter().any(|a| a.check_name(sym!(inline))); + let has_inline = attrs.iter().any(|a| a.has_name(sym!(inline))); if !has_inline { span_lint( cx, diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index 415ab556c9fd..9391049c6e8f 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -112,7 +112,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow { } fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if item.attrs.iter().any(|a| a.check_name(sym!(automatically_derived))) { + if item.attrs.iter().any(|a| a.has_name(sym!(automatically_derived))) { debug_assert!(self.derived_item.is_none()); self.derived_item = Some(item.hir_id); } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 095778777449..a7f7c97fc487 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -312,7 +312,7 @@ fn requires_exact_signature(attrs: &[Attribute]) -> bool { attrs.iter().any(|attr| { [sym!(proc_macro), sym!(proc_macro_attribute), sym!(proc_macro_derive)] .iter() - .any(|&allow| attr.check_name(allow)) + .any(|&allow| attr.has_name(allow)) }) } diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index faef7e724dd0..8ed20995a70a 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -235,7 +235,7 @@ impl EarlyLintPass for Return { } fn attr_is_cfg(attr: &ast::Attribute) -> bool { - attr.meta_item_list().is_some() && attr.check_name(sym!(cfg)) + attr.meta_item_list().is_some() && attr.has_name(sym!(cfg)) } // get the def site diff --git a/clippy_lints/src/trivially_copy_pass_by_ref.rs b/clippy_lints/src/trivially_copy_pass_by_ref.rs index 6a2b05e3e6df..7948d99162b8 100644 --- a/clippy_lints/src/trivially_copy_pass_by_ref.rs +++ b/clippy_lints/src/trivially_copy_pass_by_ref.rs @@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for TriviallyCopyPassByRef { return; } for a in attrs { - if a.meta_item_list().is_some() && a.check_name(sym!(proc_macro_derive)) { + if a.meta_item_list().is_some() && a.has_name(sym!(proc_macro_derive)) { return; } } diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index de425211e38e..ba3492a6fff1 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -13,7 +13,7 @@ use std::{env, fmt, fs, io}; /// Gets the configuration file from arguments. pub fn file_from_args(args: &[NestedMetaItem]) -> Result, (&'static str, Span)> { for arg in args.iter().filter_map(NestedMetaItem::meta_item) { - if arg.check_name(sym!(conf_file)) { + if arg.has_name(sym!(conf_file)) { return match arg.kind { MetaItemKind::Word | MetaItemKind::List(_) => Err(("`conf_file` must be a named value", arg.span)), MetaItemKind::NameValue(ref value) => { From 46f12ab7cbd2641df63ad20c38c2d0a8b30b6dc1 Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Sun, 2 Aug 2020 18:41:50 -0600 Subject: [PATCH 0051/1222] run cargo dev new_lint then move transmutes_expressible_as_ptr_casts into transmute module --- CHANGELOG.md | 1 + clippy_lints/src/lib.rs | 3 +++ clippy_lints/src/transmute.rs | 23 +++++++++++++++++++ src/lintlist/mod.rs | 7 ++++++ .../ui/transmutes_expressible_as_ptr_casts.rs | 5 ++++ 5 files changed, 39 insertions(+) create mode 100644 tests/ui/transmutes_expressible_as_ptr_casts.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 776b04295f94..a6e694910177 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1730,6 +1730,7 @@ Released 2018-09-13 [`transmute_int_to_float`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_float [`transmute_ptr_to_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ptr [`transmute_ptr_to_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ref +[`transmutes_expressible_as_ptr_casts`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmutes_expressible_as_ptr_casts [`transmuting_null`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmuting_null [`trivial_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#trivial_regex [`trivially_copy_pass_by_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index f371942dbeec..87b5309ff1c7 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -798,6 +798,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &transmute::UNSOUND_COLLECTION_TRANSMUTE, &transmute::USELESS_TRANSMUTE, &transmute::WRONG_TRANSMUTE, + &transmute::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, &transmuting_null::TRANSMUTING_NULL, &trivially_copy_pass_by_ref::TRIVIALLY_COPY_PASS_BY_REF, &try_err::TRY_ERR, @@ -1426,6 +1427,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&transmute::TRANSMUTE_PTR_TO_REF), LintId::of(&transmute::UNSOUND_COLLECTION_TRANSMUTE), LintId::of(&transmute::WRONG_TRANSMUTE), + LintId::of(&transmute::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS), LintId::of(&transmuting_null::TRANSMUTING_NULL), LintId::of(&try_err::TRY_ERR), LintId::of(&types::ABSURD_EXTREME_COMPARISONS), @@ -1624,6 +1626,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&transmute::TRANSMUTE_INT_TO_FLOAT), LintId::of(&transmute::TRANSMUTE_PTR_TO_PTR), LintId::of(&transmute::TRANSMUTE_PTR_TO_REF), + LintId::of(&transmute::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS), LintId::of(&types::BORROWED_BOX), LintId::of(&types::CHAR_LIT_AS_U8), LintId::of(&types::TYPE_COMPLEXITY), diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index d55eb1a0c938..ce2ac24f5325 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -269,6 +269,28 @@ declare_clippy_lint! { correctness, "transmute between collections of layout-incompatible types" } + +declare_clippy_lint! { + /// **What it does:** + /// + /// **Why is this bad?** + /// + /// **Known problems:** None. + /// + /// **Example:** + /// + /// ```rust + /// // example code where clippy issues a warning + /// ``` + /// Use instead: + /// ```rust + /// // example code which does not raise clippy warning + /// ``` + pub TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, + complexity, + "default lint description" +} + declare_lint_pass!(Transmute => [ CROSSPOINTER_TRANSMUTE, TRANSMUTE_PTR_TO_REF, @@ -281,6 +303,7 @@ declare_lint_pass!(Transmute => [ TRANSMUTE_INT_TO_FLOAT, TRANSMUTE_FLOAT_TO_INT, UNSOUND_COLLECTION_TRANSMUTE, + TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, ]); // used to check for UNSOUND_COLLECTION_TRANSMUTE diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 1879aae77fb6..9363039041da 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -2215,6 +2215,13 @@ pub static ref ALL_LINTS: Vec = vec![ deprecation: None, module: "transmute", }, + Lint { + name: "transmutes_expressible_as_ptr_casts", + group: "complexity", + desc: "default lint description", + deprecation: None, + module: "transmute", + }, Lint { name: "transmuting_null", group: "correctness", diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs new file mode 100644 index 000000000000..2b32ae213fbb --- /dev/null +++ b/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -0,0 +1,5 @@ +#![warn(clippy::transmutes_expressible_as_ptr_casts)] + +fn main() { + // test code goes here +} From 8fab541b7dfc02f7a83e27967ae83a69fd60bff5 Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Sun, 2 Aug 2020 22:00:51 -0600 Subject: [PATCH 0052/1222] initial compiling version of TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS --- clippy_lints/src/transmute.rs | 74 ++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index ce2ac24f5325..d5b694ce3118 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -7,8 +7,10 @@ use rustc_ast::ast; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, GenericArg, Mutability, QPath, TyKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, Ty}; +use rustc_middle::ty::{self, cast::CastKind, Ty}; +use rustc_span::DUMMY_SP; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_typeck::check::{cast::CastCheck, FnCtxt, Inherited}; use std::borrow::Cow; declare_clippy_lint! { @@ -624,7 +626,21 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { ); } }, - _ => return, + (_, _) if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) => { + span_lint( + cx, + TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, + e.span, + &format!( + "transmute from `{}` to `{}` which could be expressed as a pointer cast instead", + from_ty, + to_ty + ) + ); + }, + _ => { + return + }, } } } @@ -671,3 +687,57 @@ fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<' false } } + +/// Check if the the type conversion can be expressed as a pointer cast, instead of a transmute. +fn can_be_expressed_as_pointer_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> bool { + use CastKind::*; + matches!( + check_cast(cx, e, from_ty, to_ty), + Some( + PtrPtrCast + | PtrAddrCast + | AddrPtrCast + | ArrayPtrCast + | FnPtrPtrCast + | FnPtrAddrCast + ) + ) +} + +/// If a cast from from_ty to to_ty is valid, returns an Ok containing the kind of the cast. +fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> Option { + let hir_id = e.hir_id; + let local_def_id = hir_id.owner; + + Inherited::build(cx.tcx, local_def_id).enter(|inherited| { + let fn_ctxt = FnCtxt::new( + &inherited, + // TODO should we try to get the correct ParamEnv? + ty::ParamEnv::empty(), + hir_id + ); + + // If we already have errors, we can't be sure we can pointer cast. + if fn_ctxt.errors_reported_since_creation() { + return None; + } + + if let Ok(check) = CastCheck::new( + &fn_ctxt, + e, + from_ty, + to_ty, + // We won't show any error to the user, so we don't care what the span is here. + DUMMY_SP, + DUMMY_SP, + ) { + check.do_check(&fn_ctxt) + .ok() + // do_check's documentation says that it might return Ok and create + // errors in the fcx instead of returing Err in some cases. + .filter(|_| !fn_ctxt.errors_reported_since_creation()) + } else { + None + } + }) +} \ No newline at end of file From f3d0f47dc109bbf7bc61b1ce0c1fcbca2df09453 Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Sun, 2 Aug 2020 23:17:11 -0600 Subject: [PATCH 0053/1222] write currently failing test for transmutes_expressible_as_ptr_casts There are 5 errors, when there should be 7. --- .../ui/transmutes_expressible_as_ptr_casts.rs | 54 ++++++++++++++++++- ...transmutes_expressible_as_ptr_casts.stderr | 1 + 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/ui/transmutes_expressible_as_ptr_casts.stderr diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs index 2b32ae213fbb..e6b9dddd3421 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -1,5 +1,57 @@ #![warn(clippy::transmutes_expressible_as_ptr_casts)] +// rustc_typeck::check::cast contains documentation about when a cast `e as U` is +// valid, which we quote from below. +use std::mem::transmute; + fn main() { - // test code goes here + // e is an integer and U is *U_0, while U_0: Sized; addr-ptr-cast + let ptr_i32_transmute = unsafe { + transmute::(-1) + }; + let ptr_i32 = -1isize as *const i32; + + // e has type *T, U is *U_0, and either U_0: Sized ... + let ptr_i8_transmute = unsafe { + transmute::<*const i32, *const i8>(ptr_i32) + }; + let ptr_i8 = ptr_i32 as *const i8; + + let slice_ptr = &[0,1,2,3] as *const [i32]; + + // ... or pointer_kind(T) = pointer_kind(U_0); ptr-ptr-cast + let ptr_to_unsized_transmute = unsafe { + transmute::<*const [i32], *const [u16]>(slice_ptr) + }; + let ptr_to_unsized = slice_ptr as *const [u16]; + // TODO: We could try testing vtable casts here too, but maybe + // we should wait until std::raw::TraitObject is stabilized? + + // e has type *T and U is a numeric type, while T: Sized; ptr-addr-cast + let usize_from_int_ptr_transmute = unsafe { + transmute::<*const i32, usize>(ptr_i32) + }; + let usize_from_int_ptr = ptr_i32 as usize; + + let array_ref: &[i32; 4] = &[1,2,3,4]; + + // e has type &[T; n] and U is *const T; array-ptr-cast + let array_ptr_transmute = unsafe { + transmute::<&[i32; 4], *const [i32; 4]>(array_ref) + }; + let array_ptr = array_ref as *const [i32; 4]; + + fn foo(_: usize) -> u8 { 42 } + + // e is a function pointer type and U has type *T, while T: Sized; fptr-ptr-cast + let usize_ptr_transmute = unsafe { + transmute:: u8, *const usize>(foo) + }; + let usize_ptr_transmute = foo as *const usize; + + // e is a function pointer type and U is an integer; fptr-addr-cast + let usize_from_fn_ptr_transmute = unsafe { + transmute:: u8, usize>(foo) + }; + let usize_from_fn_ptr = foo as *const usize; } diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.stderr b/tests/ui/transmutes_expressible_as_ptr_casts.stderr new file mode 100644 index 000000000000..6bae1fa1b4fc --- /dev/null +++ b/tests/ui/transmutes_expressible_as_ptr_casts.stderr @@ -0,0 +1 @@ +Should have 7 errors, one for each transmute From adad1e983b6a7a014808743d442fdfa8e95c742b Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Mon, 3 Aug 2020 00:16:11 -0600 Subject: [PATCH 0054/1222] accidentally cause an ICE by putting the TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS handling after the match The reason I did this in the first place was to try and figure out why I don't see my expected 7 error messages --- clippy_lints/src/transmute.rs | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index d5b694ce3118..d6b1a5df71fa 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -626,21 +626,25 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { ); } }, - (_, _) if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) => { - span_lint( - cx, - TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, - e.span, - &format!( - "transmute from `{}` to `{}` which could be expressed as a pointer cast instead", - from_ty, - to_ty - ) - ); - }, - _ => { - return - }, + _ => {}, + } + if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) { + span_lint_and_then( + cx, + TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, + e.span, + &format!( + "transmute from `{}` to `{}` which could be expressed as a pointer cast instead", + from_ty, + to_ty + ), + |diag| { + if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { + let sugg = format!("{} as {}", arg, to_ty); + diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified); + } + } + ) } } } From cce7821b79dcd6363cf8ae8b24d9c84f38517aaa Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Mon, 3 Aug 2020 00:54:03 -0600 Subject: [PATCH 0055/1222] try putting the can_be_expressed_as_pointer_cast at the top and find that we still get an ICE --- clippy_lints/src/transmute.rs | 42 +++++++++++++++++--------------- tests/ui/transmute.rs | 2 +- tests/ui/transmute_ptr_to_ptr.rs | 2 +- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index d6b1a5df71fa..7ab3f0d96763 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -330,6 +330,26 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { let from_ty = cx.typeck_results().expr_ty(&args[0]); let to_ty = cx.typeck_results().expr_ty(e); + if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) { + span_lint_and_then( + cx, + TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, + e.span, + &format!( + "transmute from `{}` to `{}` which could be expressed as a pointer cast instead", + from_ty, + to_ty + ), + |diag| { + if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { + let sugg = format!("{} as {}", arg, to_ty); + diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified); + } + } + ); + return + } + match (&from_ty.kind, &to_ty.kind) { _ if from_ty == to_ty => span_lint( cx, @@ -626,25 +646,9 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { ); } }, - _ => {}, - } - if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) { - span_lint_and_then( - cx, - TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, - e.span, - &format!( - "transmute from `{}` to `{}` which could be expressed as a pointer cast instead", - from_ty, - to_ty - ), - |diag| { - if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { - let sugg = format!("{} as {}", arg, to_ty); - diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified); - } - } - ) + _ => { + return; + }, } } } diff --git a/tests/ui/transmute.rs b/tests/ui/transmute.rs index bb853d237047..b3171d2e7dcf 100644 --- a/tests/ui/transmute.rs +++ b/tests/ui/transmute.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] +#![allow(clippy::transmutes_expressible_as_ptr_casts)] extern crate core; - use std::mem::transmute as my_transmute; use std::vec::Vec as MyVec; diff --git a/tests/ui/transmute_ptr_to_ptr.rs b/tests/ui/transmute_ptr_to_ptr.rs index 0d8a322f2b2b..009b5fa534cf 100644 --- a/tests/ui/transmute_ptr_to_ptr.rs +++ b/tests/ui/transmute_ptr_to_ptr.rs @@ -1,5 +1,5 @@ #![warn(clippy::transmute_ptr_to_ptr)] - +#![allow(clippy::transmutes_expressible_as_ptr_casts)] // Make sure we can modify lifetimes, which is one of the recommended uses // of transmute From 15ddf3224560409752f6f3bb2b9655c0717556b5 Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Mon, 3 Aug 2020 02:47:25 -0600 Subject: [PATCH 0056/1222] get the expected number of errors by acknowledging that other lints are covering the same ground --- clippy_lints/src/transmute.rs | 80 +++++++++---------- tests/ui/transmute.rs | 2 +- tests/ui/transmute_ptr_to_ptr.rs | 2 +- .../ui/transmutes_expressible_as_ptr_casts.rs | 10 ++- ...transmutes_expressible_as_ptr_casts.stderr | 51 +++++++++++- 5 files changed, 100 insertions(+), 45 deletions(-) diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 7ab3f0d96763..269d2f00353a 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -50,6 +50,29 @@ declare_clippy_lint! { "transmutes that have the same to and from types or could be a cast/coercion" } +// FIXME: Merge this lint with USELESS_TRANSMUTE once that is out of the nursery. +declare_clippy_lint! { + /// **What it does:**Checks for transmutes that could be a pointer cast. + /// + /// **Why is this bad?** Readability. The code tricks people into thinking that + /// something complex is going on. + /// + /// **Known problems:** None. + /// + /// **Example:** + /// + /// ```rust,ignore + /// core::intrinsics::transmute::<*const [i32], *const [u16]>(p) + /// ``` + /// Use instead: + /// ```rust + /// p as *const [u16] + /// ``` + pub TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, + complexity, + "transmutes that could be a pointer cast" +} + declare_clippy_lint! { /// **What it does:** Checks for transmutes between a type `T` and `*T`. /// @@ -272,27 +295,6 @@ declare_clippy_lint! { "transmute between collections of layout-incompatible types" } -declare_clippy_lint! { - /// **What it does:** - /// - /// **Why is this bad?** - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// // example code where clippy issues a warning - /// ``` - /// Use instead: - /// ```rust - /// // example code which does not raise clippy warning - /// ``` - pub TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, - complexity, - "default lint description" -} - declare_lint_pass!(Transmute => [ CROSSPOINTER_TRANSMUTE, TRANSMUTE_PTR_TO_REF, @@ -330,26 +332,6 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { let from_ty = cx.typeck_results().expr_ty(&args[0]); let to_ty = cx.typeck_results().expr_ty(e); - if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) { - span_lint_and_then( - cx, - TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, - e.span, - &format!( - "transmute from `{}` to `{}` which could be expressed as a pointer cast instead", - from_ty, - to_ty - ), - |diag| { - if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { - let sugg = format!("{} as {}", arg, to_ty); - diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified); - } - } - ); - return - } - match (&from_ty.kind, &to_ty.kind) { _ if from_ty == to_ty => span_lint( cx, @@ -646,6 +628,22 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { ); } }, + (_, _) if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) => span_lint_and_then( + cx, + TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, + e.span, + &format!( + "transmute from `{}` to `{}` which could be expressed as a pointer cast instead", + from_ty, + to_ty + ), + |diag| { + if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { + let sugg = arg.as_ty(&to_ty.to_string()).to_string(); + diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified); + } + } + ), _ => { return; }, diff --git a/tests/ui/transmute.rs b/tests/ui/transmute.rs index b3171d2e7dcf..bb853d237047 100644 --- a/tests/ui/transmute.rs +++ b/tests/ui/transmute.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] -#![allow(clippy::transmutes_expressible_as_ptr_casts)] extern crate core; + use std::mem::transmute as my_transmute; use std::vec::Vec as MyVec; diff --git a/tests/ui/transmute_ptr_to_ptr.rs b/tests/ui/transmute_ptr_to_ptr.rs index 009b5fa534cf..0d8a322f2b2b 100644 --- a/tests/ui/transmute_ptr_to_ptr.rs +++ b/tests/ui/transmute_ptr_to_ptr.rs @@ -1,5 +1,5 @@ #![warn(clippy::transmute_ptr_to_ptr)] -#![allow(clippy::transmutes_expressible_as_ptr_casts)] + // Make sure we can modify lifetimes, which is one of the recommended uses // of transmute diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs index e6b9dddd3421..db544b438a28 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -1,10 +1,18 @@ #![warn(clippy::transmutes_expressible_as_ptr_casts)] +// These two warnings currrently cover the cases transmutes_expressible_as_ptr_casts +// would otherwise be responsible for +#![warn(clippy::useless_transmute)] +#![warn(clippy::transmute_ptr_to_ptr)] + +use std::mem::transmute; // rustc_typeck::check::cast contains documentation about when a cast `e as U` is // valid, which we quote from below. -use std::mem::transmute; fn main() { + // We should see an error message for each transmute, and no error messages for + // the casts, since the casts are the recommended fixes. + // e is an integer and U is *U_0, while U_0: Sized; addr-ptr-cast let ptr_i32_transmute = unsafe { transmute::(-1) diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.stderr b/tests/ui/transmutes_expressible_as_ptr_casts.stderr index 6bae1fa1b4fc..7cd316bf38aa 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.stderr +++ b/tests/ui/transmutes_expressible_as_ptr_casts.stderr @@ -1 +1,50 @@ -Should have 7 errors, one for each transmute +error: transmute from an integer to a pointer + --> $DIR/transmutes_expressible_as_ptr_casts.rs:18:9 + | +LL | transmute::(-1) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-1 as *const i32` + | + = note: `-D clippy::useless-transmute` implied by `-D warnings` + +error: transmute from a pointer to a pointer + --> $DIR/transmutes_expressible_as_ptr_casts.rs:24:9 + | +LL | transmute::<*const i32, *const i8>(ptr_i32) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as *const i8` + | + = note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` + +error: transmute from a pointer to a pointer + --> $DIR/transmutes_expressible_as_ptr_casts.rs:32:9 + | +LL | transmute::<*const [i32], *const [u16]>(slice_ptr) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `slice_ptr as *const [u16]` + +error: transmute from `*const i32` to `usize` which could be expressed as a pointer cast instead + --> $DIR/transmutes_expressible_as_ptr_casts.rs:40:9 + | +LL | transmute::<*const i32, usize>(ptr_i32) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as usize` + | + = note: `-D clippy::transmutes-expressible-as-ptr-casts` implied by `-D warnings` + +error: transmute from a reference to a pointer + --> $DIR/transmutes_expressible_as_ptr_casts.rs:48:9 + | +LL | transmute::<&[i32; 4], *const [i32; 4]>(array_ref) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `array_ref as *const [i32; 4]` + +error: transmute from `fn(usize) -> u8 {main::foo}` to `*const usize` which could be expressed as a pointer cast instead + --> $DIR/transmutes_expressible_as_ptr_casts.rs:56:9 + | +LL | transmute:: u8, *const usize>(foo) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as *const usize` + +error: transmute from `fn(usize) -> u8 {main::foo}` to `usize` which could be expressed as a pointer cast instead + --> $DIR/transmutes_expressible_as_ptr_casts.rs:62:9 + | +LL | transmute:: u8, usize>(foo) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as usize` + +error: aborting due to 7 previous errors + From 84d375a52bd25df919c622fd2de54d8d3732b9b7 Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Mon, 3 Aug 2020 19:00:38 -0600 Subject: [PATCH 0057/1222] address some review comments --- clippy_lints/src/transmute.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 269d2f00353a..b6747c73f705 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -718,15 +718,12 @@ fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx> Inherited::build(cx.tcx, local_def_id).enter(|inherited| { let fn_ctxt = FnCtxt::new( &inherited, - // TODO should we try to get the correct ParamEnv? - ty::ParamEnv::empty(), + cx.param_env, hir_id ); // If we already have errors, we can't be sure we can pointer cast. - if fn_ctxt.errors_reported_since_creation() { - return None; - } + assert!(!fn_ctxt.errors_reported_since_creation()); if let Ok(check) = CastCheck::new( &fn_ctxt, @@ -746,4 +743,4 @@ fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx> None } }) -} \ No newline at end of file +} From 5814b01559a44e8f6ef779727dbccb3a5725a204 Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Tue, 4 Aug 2020 16:45:47 -0600 Subject: [PATCH 0058/1222] add description to assert --- clippy_lints/src/transmute.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index b6747c73f705..ea14f2829ea5 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -723,7 +723,10 @@ fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx> ); // If we already have errors, we can't be sure we can pointer cast. - assert!(!fn_ctxt.errors_reported_since_creation()); + assert!( + !fn_ctxt.errors_reported_since_creation(), + "Newly created FnCtxt contained errors" + ); if let Ok(check) = CastCheck::new( &fn_ctxt, From 8ec07e52c25a5edec53bfc948d2feaeeca4e9ace Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Wed, 5 Aug 2020 20:23:29 -0600 Subject: [PATCH 0059/1222] add documentation to functions that call `do_check` and add a test against lint ordering changing --- clippy_lints/src/transmute.rs | 10 ++++++++-- tests/ui/transmutes_expressible_as_ptr_casts.rs | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index ea14f2829ea5..231f13b236c1 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -694,7 +694,10 @@ fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<' } } -/// Check if the the type conversion can be expressed as a pointer cast, instead of a transmute. +/// Check if the the type conversion can be expressed as a pointer cast, instead of +/// a transmute. In certain cases, including some invalid casts from array +/// references to pointers, this may cause additional errors to be emitted and/or +/// ICE error messages. fn can_be_expressed_as_pointer_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> bool { use CastKind::*; matches!( @@ -710,7 +713,10 @@ fn can_be_expressed_as_pointer_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr< ) } -/// If a cast from from_ty to to_ty is valid, returns an Ok containing the kind of the cast. +/// If a cast from from_ty to to_ty is valid, returns an Ok containing the kind of +/// the cast. In certain cases, including some invalid casts from array references +/// to pointers, this may cause additional errors to be emitted and/or ICE error +/// messages. fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> Option { let hir_id = e.hir_id; let local_def_id = hir_id.owner; diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs index db544b438a28..007526da40df 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -63,3 +63,14 @@ fn main() { }; let usize_from_fn_ptr = foo as *const usize; } + +// If a ref-to-ptr cast of this form where the pointer type points to a type other +// than the referenced type, calling `CastCheck::do_check` has been observed to +// cause an ICE error message. `do_check` is currently called inside the +// `transmutes_expressible_as_ptr_casts` check, but other, more specific lints +// currently prevent it from being called in these cases. This test is meant to +// fail if the ordering of the checks ever changes enough to cause these cases to +// fall through into `do_check`. +fn trigger_do_check_to_emit_error(in_param: &[i32; 1]) -> *const u8 { + unsafe { transmute::<&[i32; 1], *const u8>(in_param) } +} \ No newline at end of file From c673570b9fcc3d256ba2b844eedb2a40428fcc41 Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Wed, 5 Aug 2020 21:28:22 -0600 Subject: [PATCH 0060/1222] add extra error message to the expected stderr for transmutes_expressible_as_ptr_casts test --- tests/ui/transmutes_expressible_as_ptr_casts.stderr | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.stderr b/tests/ui/transmutes_expressible_as_ptr_casts.stderr index 7cd316bf38aa..e6edacbd0de8 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.stderr +++ b/tests/ui/transmutes_expressible_as_ptr_casts.stderr @@ -46,5 +46,11 @@ error: transmute from `fn(usize) -> u8 {main::foo}` to `usize` which could be ex LL | transmute:: u8, usize>(foo) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as usize` -error: aborting due to 7 previous errors +error: transmute from a reference to a pointer + --> $DIR/transmutes_expressible_as_ptr_casts.rs:75:14 + | +LL | unsafe { transmute::<&[i32; 1], *const u8>(in_param) } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `in_param as *const [i32; 1] as *const u8` + +error: aborting due to 8 previous errors From 772ddebd0da43ec93abe72cf18827ea055e8a16b Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Thu, 6 Aug 2020 04:18:14 -0600 Subject: [PATCH 0061/1222] change filter to assert, and update comments --- clippy_lints/src/transmute.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 231f13b236c1..9f356811f220 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -697,7 +697,7 @@ fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<' /// Check if the the type conversion can be expressed as a pointer cast, instead of /// a transmute. In certain cases, including some invalid casts from array /// references to pointers, this may cause additional errors to be emitted and/or -/// ICE error messages. +/// ICE error messages. This function will panic if that occurs. fn can_be_expressed_as_pointer_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> bool { use CastKind::*; matches!( @@ -716,7 +716,7 @@ fn can_be_expressed_as_pointer_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr< /// If a cast from from_ty to to_ty is valid, returns an Ok containing the kind of /// the cast. In certain cases, including some invalid casts from array references /// to pointers, this may cause additional errors to be emitted and/or ICE error -/// messages. +/// messages. This function will panic if that occurs. fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> Option { let hir_id = e.hir_id; let local_def_id = hir_id.owner; @@ -743,11 +743,17 @@ fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx> DUMMY_SP, DUMMY_SP, ) { - check.do_check(&fn_ctxt) - .ok() - // do_check's documentation says that it might return Ok and create - // errors in the fcx instead of returing Err in some cases. - .filter(|_| !fn_ctxt.errors_reported_since_creation()) + let res = check.do_check(&fn_ctxt); + + // do_check's documentation says that it might return Ok and create + // errors in the fcx instead of returing Err in some cases. Those cases + // should be filtered out before getting here. + assert!( + !fn_ctxt.errors_reported_since_creation(), + "`fn_ctxt` contained errors after cast check!" + ); + + res.ok() } else { None } From 1ba94fed66f68589bb3a88ffca86ac74f5a57b7f Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Thu, 6 Aug 2020 04:49:06 -0600 Subject: [PATCH 0062/1222] add newline to transmutes_expressible_as_ptr_casts.rs --- tests/ui/transmutes_expressible_as_ptr_casts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs index 007526da40df..7e99c9283598 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -73,4 +73,4 @@ fn main() { // fall through into `do_check`. fn trigger_do_check_to_emit_error(in_param: &[i32; 1]) -> *const u8 { unsafe { transmute::<&[i32; 1], *const u8>(in_param) } -} \ No newline at end of file +} From 2acbe899cfe37e11d2d22749b7d158462bc3523f Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Thu, 6 Aug 2020 06:11:23 -0600 Subject: [PATCH 0063/1222] run clippy_dev update_lints --- clippy_lints/src/lib.rs | 6 +++--- src/lintlist/mod.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 87b5309ff1c7..828ee9105960 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -788,6 +788,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &to_digit_is_some::TO_DIGIT_IS_SOME, &trait_bounds::TYPE_REPETITION_IN_BOUNDS, &transmute::CROSSPOINTER_TRANSMUTE, + &transmute::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, &transmute::TRANSMUTE_BYTES_TO_STR, &transmute::TRANSMUTE_FLOAT_TO_INT, &transmute::TRANSMUTE_INT_TO_BOOL, @@ -798,7 +799,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &transmute::UNSOUND_COLLECTION_TRANSMUTE, &transmute::USELESS_TRANSMUTE, &transmute::WRONG_TRANSMUTE, - &transmute::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, &transmuting_null::TRANSMUTING_NULL, &trivially_copy_pass_by_ref::TRIVIALLY_COPY_PASS_BY_REF, &try_err::TRY_ERR, @@ -1418,6 +1418,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&temporary_assignment::TEMPORARY_ASSIGNMENT), LintId::of(&to_digit_is_some::TO_DIGIT_IS_SOME), LintId::of(&transmute::CROSSPOINTER_TRANSMUTE), + LintId::of(&transmute::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS), LintId::of(&transmute::TRANSMUTE_BYTES_TO_STR), LintId::of(&transmute::TRANSMUTE_FLOAT_TO_INT), LintId::of(&transmute::TRANSMUTE_INT_TO_BOOL), @@ -1427,7 +1428,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&transmute::TRANSMUTE_PTR_TO_REF), LintId::of(&transmute::UNSOUND_COLLECTION_TRANSMUTE), LintId::of(&transmute::WRONG_TRANSMUTE), - LintId::of(&transmute::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS), LintId::of(&transmuting_null::TRANSMUTING_NULL), LintId::of(&try_err::TRY_ERR), LintId::of(&types::ABSURD_EXTREME_COMPARISONS), @@ -1619,6 +1619,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&swap::MANUAL_SWAP), LintId::of(&temporary_assignment::TEMPORARY_ASSIGNMENT), LintId::of(&transmute::CROSSPOINTER_TRANSMUTE), + LintId::of(&transmute::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS), LintId::of(&transmute::TRANSMUTE_BYTES_TO_STR), LintId::of(&transmute::TRANSMUTE_FLOAT_TO_INT), LintId::of(&transmute::TRANSMUTE_INT_TO_BOOL), @@ -1626,7 +1627,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&transmute::TRANSMUTE_INT_TO_FLOAT), LintId::of(&transmute::TRANSMUTE_PTR_TO_PTR), LintId::of(&transmute::TRANSMUTE_PTR_TO_REF), - LintId::of(&transmute::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS), LintId::of(&types::BORROWED_BOX), LintId::of(&types::CHAR_LIT_AS_U8), LintId::of(&types::TYPE_COMPLEXITY), diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 9363039041da..1f3f70631fb2 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -2218,7 +2218,7 @@ pub static ref ALL_LINTS: Vec = vec![ Lint { name: "transmutes_expressible_as_ptr_casts", group: "complexity", - desc: "default lint description", + desc: "transmutes that could be a pointer cast", deprecation: None, module: "transmute", }, From 26ec358ab19ae92585fa1e36800ccdddd1505d30 Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Thu, 6 Aug 2020 06:15:57 -0600 Subject: [PATCH 0064/1222] run clippy_dev fmt This seemed to overdo it a bit, affecting multiple submodules, and changing a file I didn't touch, so I didn't commit those changes --- clippy_lints/src/transmute.rs | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 9f356811f220..7d707b8a0c85 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -8,8 +8,8 @@ use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, GenericArg, Mutability, QPath, TyKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, cast::CastKind, Ty}; -use rustc_span::DUMMY_SP; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::DUMMY_SP; use rustc_typeck::check::{cast::CastCheck, FnCtxt, Inherited}; use std::borrow::Cow; @@ -698,18 +698,16 @@ fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<' /// a transmute. In certain cases, including some invalid casts from array /// references to pointers, this may cause additional errors to be emitted and/or /// ICE error messages. This function will panic if that occurs. -fn can_be_expressed_as_pointer_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> bool { +fn can_be_expressed_as_pointer_cast<'tcx>( + cx: &LateContext<'tcx>, + e: &'tcx Expr<'_>, + from_ty: Ty<'tcx>, + to_ty: Ty<'tcx>, +) -> bool { use CastKind::*; matches!( check_cast(cx, e, from_ty, to_ty), - Some( - PtrPtrCast - | PtrAddrCast - | AddrPtrCast - | ArrayPtrCast - | FnPtrPtrCast - | FnPtrAddrCast - ) + Some(PtrPtrCast | PtrAddrCast | AddrPtrCast | ArrayPtrCast | FnPtrPtrCast | FnPtrAddrCast) ) } @@ -722,26 +720,18 @@ fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx> let local_def_id = hir_id.owner; Inherited::build(cx.tcx, local_def_id).enter(|inherited| { - let fn_ctxt = FnCtxt::new( - &inherited, - cx.param_env, - hir_id - ); + let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, hir_id); // If we already have errors, we can't be sure we can pointer cast. assert!( - !fn_ctxt.errors_reported_since_creation(), + !fn_ctxt.errors_reported_since_creation(), "Newly created FnCtxt contained errors" ); if let Ok(check) = CastCheck::new( - &fn_ctxt, - e, - from_ty, - to_ty, + &fn_ctxt, e, from_ty, to_ty, // We won't show any error to the user, so we don't care what the span is here. - DUMMY_SP, - DUMMY_SP, + DUMMY_SP, DUMMY_SP, ) { let res = check.do_check(&fn_ctxt); From 5fa2d9c15f5b00e52b25657cbdcc9f4d96a90318 Mon Sep 17 00:00:00 2001 From: Ryan Wiedemann Date: Thu, 6 Aug 2020 07:57:31 -0600 Subject: [PATCH 0065/1222] Apply suggestions from code review Co-authored-by: Philipp Krones --- clippy_lints/src/transmute.rs | 4 ++-- tests/ui/transmutes_expressible_as_ptr_casts.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 7d707b8a0c85..f077c1461831 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -640,7 +640,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { |diag| { if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { let sugg = arg.as_ty(&to_ty.to_string()).to_string(); - diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified); + diag.span_suggestion(e.span, "try", sugg, Applicability::MachineApplicable); } } ), @@ -694,7 +694,7 @@ fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<' } } -/// Check if the the type conversion can be expressed as a pointer cast, instead of +/// Check if the type conversion can be expressed as a pointer cast, instead of /// a transmute. In certain cases, including some invalid casts from array /// references to pointers, this may cause additional errors to be emitted and/or /// ICE error messages. This function will panic if that occurs. diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs index 7e99c9283598..2693094ba6ce 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -1,3 +1,4 @@ +// run-rustfix #![warn(clippy::transmutes_expressible_as_ptr_casts)] // These two warnings currrently cover the cases transmutes_expressible_as_ptr_casts // would otherwise be responsible for From e983ff304ffd5610a7150d69380299370990007a Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 22 Jul 2020 17:59:17 +0300 Subject: [PATCH 0066/1222] Fix clippy --- clippy_lints/src/doc.rs | 80 +++++++++++------------- clippy_lints/src/tabs_in_doc_comments.rs | 6 +- clippy_lints/src/utils/ast_utils.rs | 2 +- 3 files changed, 39 insertions(+), 49 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index e87c33d1b09d..94371b7d23e3 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -2,6 +2,7 @@ use crate::utils::{implements_trait, is_entrypoint_fn, is_type_diagnostic_item, use if_chain::if_chain; use itertools::Itertools; use rustc_ast::ast::{AttrKind, Attribute}; +use rustc_ast::token::CommentKind; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; @@ -249,7 +250,7 @@ fn lint_for_missing_headers<'tcx>( } } -/// Cleanup documentation decoration (`///` and such). +/// Cleanup documentation decoration. /// /// We can't use `rustc_ast::attr::AttributeMethods::with_desugared_doc` or /// `rustc_ast::parse::lexer::comments::strip_doc_comment_decoration` because we @@ -257,54 +258,44 @@ fn lint_for_missing_headers<'tcx>( /// the spans but this function is inspired from the later. #[allow(clippy::cast_possible_truncation)] #[must_use] -pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(usize, Span)>) { +pub fn strip_doc_comment_decoration(doc: &str, comment_kind: CommentKind, span: Span) -> (String, Vec<(usize, Span)>) { // one-line comments lose their prefix - const ONELINERS: &[&str] = &["///!", "///", "//!", "//"]; - for prefix in ONELINERS { - if comment.starts_with(*prefix) { - let doc = &comment[prefix.len()..]; - let mut doc = doc.to_owned(); - doc.push('\n'); - return ( - doc.to_owned(), - vec![(doc.len(), span.with_lo(span.lo() + BytePos(prefix.len() as u32)))], - ); - } + if comment_kind == CommentKind::Line { + let mut doc = doc.to_owned(); + doc.push('\n'); + let len = doc.len(); + return (doc, vec![(len, span.with_lo(span.lo() + BytePos(3)))]); } - if comment.starts_with("/*") { - let doc = &comment[3..comment.len() - 2]; - let mut sizes = vec![]; - let mut contains_initial_stars = false; - for line in doc.lines() { - let offset = line.as_ptr() as usize - comment.as_ptr() as usize; - debug_assert_eq!(offset as u32 as usize, offset); - contains_initial_stars |= line.trim_start().starts_with('*'); - // +1 for the newline - sizes.push((line.len() + 1, span.with_lo(span.lo() + BytePos(offset as u32)))); - } - if !contains_initial_stars { - return (doc.to_string(), sizes); - } - // remove the initial '*'s if any - let mut no_stars = String::with_capacity(doc.len()); - for line in doc.lines() { - let mut chars = line.chars(); - while let Some(c) = chars.next() { - if c.is_whitespace() { - no_stars.push(c); - } else { - no_stars.push(if c == '*' { ' ' } else { c }); - break; - } + let mut sizes = vec![]; + let mut contains_initial_stars = false; + for line in doc.lines() { + let offset = line.as_ptr() as usize - doc.as_ptr() as usize; + debug_assert_eq!(offset as u32 as usize, offset); + contains_initial_stars |= line.trim_start().starts_with('*'); + // +1 for the newline + sizes.push((line.len() + 1, span.with_lo(span.lo() + BytePos(3 + offset as u32)))); + } + if !contains_initial_stars { + return (doc.to_string(), sizes); + } + // remove the initial '*'s if any + let mut no_stars = String::with_capacity(doc.len()); + for line in doc.lines() { + let mut chars = line.chars(); + while let Some(c) = chars.next() { + if c.is_whitespace() { + no_stars.push(c); + } else { + no_stars.push(if c == '*' { ' ' } else { c }); + break; } - no_stars.push_str(chars.as_str()); - no_stars.push('\n'); } - return (no_stars, sizes); + no_stars.push_str(chars.as_str()); + no_stars.push('\n'); } - panic!("not a doc-comment: {}", comment); + (no_stars, sizes) } #[derive(Copy, Clone)] @@ -318,9 +309,8 @@ fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs let mut spans = vec![]; for attr in attrs { - if let AttrKind::DocComment(ref comment) = attr.kind { - let comment = comment.to_string(); - let (comment, current_spans) = strip_doc_comment_decoration(&comment, attr.span); + if let AttrKind::DocComment(comment_kind, comment) = attr.kind { + let (comment, current_spans) = strip_doc_comment_decoration(&comment.as_str(), comment_kind, attr.span); spans.extend_from_slice(¤t_spans); doc.push_str(&comment); } else if attr.has_name(sym!(doc)) { diff --git a/clippy_lints/src/tabs_in_doc_comments.rs b/clippy_lints/src/tabs_in_doc_comments.rs index 7b673e15b764..d00114eed696 100644 --- a/clippy_lints/src/tabs_in_doc_comments.rs +++ b/clippy_lints/src/tabs_in_doc_comments.rs @@ -60,13 +60,13 @@ declare_lint_pass!(TabsInDocComments => [TABS_IN_DOC_COMMENTS]); impl TabsInDocComments { fn warn_if_tabs_in_doc(cx: &EarlyContext<'_>, attr: &ast::Attribute) { - if let ast::AttrKind::DocComment(comment) = attr.kind { + if let ast::AttrKind::DocComment(_, comment) = attr.kind { let comment = comment.as_str(); for (lo, hi) in get_chunks_of_tabs(&comment) { let new_span = Span::new( - attr.span.lo() + BytePos(lo), - attr.span.lo() + BytePos(hi), + attr.span.lo() + BytePos(3 + lo), + attr.span.lo() + BytePos(3 + hi), attr.span.ctxt(), ); span_lint_and_sugg( diff --git a/clippy_lints/src/utils/ast_utils.rs b/clippy_lints/src/utils/ast_utils.rs index 58c1103da9f7..ad02bc5fd8e7 100755 --- a/clippy_lints/src/utils/ast_utils.rs +++ b/clippy_lints/src/utils/ast_utils.rs @@ -506,7 +506,7 @@ pub fn eq_attr(l: &Attribute, r: &Attribute) -> bool { use AttrKind::*; l.style == r.style && match (&l.kind, &r.kind) { - (DocComment(l), DocComment(r)) => l == r, + (DocComment(l1, l2), DocComment(r1, r2)) => l1 == r1 && l2 == r2, (Normal(l), Normal(r)) => eq_path(&l.path, &r.path) && eq_mac_args(&l.args, &r.args), _ => false, } From 174981591beac9cb6eee835c1a7a37fed89976bb Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 5 Aug 2020 00:26:23 +0300 Subject: [PATCH 0067/1222] Add some comments for magic numbers + Add tests --- clippy_lints/src/doc.rs | 3 ++- clippy_lints/src/tabs_in_doc_comments.rs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 94371b7d23e3..6ce36fd2360e 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -264,6 +264,7 @@ pub fn strip_doc_comment_decoration(doc: &str, comment_kind: CommentKind, span: let mut doc = doc.to_owned(); doc.push('\n'); let len = doc.len(); + // +3 skips the opening delimiter return (doc, vec![(len, span.with_lo(span.lo() + BytePos(3)))]); } @@ -273,7 +274,7 @@ pub fn strip_doc_comment_decoration(doc: &str, comment_kind: CommentKind, span: let offset = line.as_ptr() as usize - doc.as_ptr() as usize; debug_assert_eq!(offset as u32 as usize, offset); contains_initial_stars |= line.trim_start().starts_with('*'); - // +1 for the newline + // +1 adds the newline, +3 skips the opening delimiter sizes.push((line.len() + 1, span.with_lo(span.lo() + BytePos(3 + offset as u32)))); } if !contains_initial_stars { diff --git a/clippy_lints/src/tabs_in_doc_comments.rs b/clippy_lints/src/tabs_in_doc_comments.rs index d00114eed696..74ccd9235de8 100644 --- a/clippy_lints/src/tabs_in_doc_comments.rs +++ b/clippy_lints/src/tabs_in_doc_comments.rs @@ -64,6 +64,7 @@ impl TabsInDocComments { let comment = comment.as_str(); for (lo, hi) in get_chunks_of_tabs(&comment) { + // +3 skips the opening delimiter let new_span = Span::new( attr.span.lo() + BytePos(3 + lo), attr.span.lo() + BytePos(3 + hi), From d90ab59e1d4b348c436991c8e76881c2b4d47425 Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Thu, 6 Aug 2020 20:28:29 -0600 Subject: [PATCH 0068/1222] copy over *.fixed file --- .../transmutes_expressible_as_ptr_casts.fixed | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/ui/transmutes_expressible_as_ptr_casts.fixed diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.fixed b/tests/ui/transmutes_expressible_as_ptr_casts.fixed new file mode 100644 index 000000000000..ab181687e1eb --- /dev/null +++ b/tests/ui/transmutes_expressible_as_ptr_casts.fixed @@ -0,0 +1,77 @@ +// run-rustfix +#![warn(clippy::transmutes_expressible_as_ptr_casts)] +// These two warnings currrently cover the cases transmutes_expressible_as_ptr_casts +// would otherwise be responsible for +#![warn(clippy::useless_transmute)] +#![warn(clippy::transmute_ptr_to_ptr)] + +use std::mem::transmute; + +// rustc_typeck::check::cast contains documentation about when a cast `e as U` is +// valid, which we quote from below. + +fn main() { + // We should see an error message for each transmute, and no error messages for + // the casts, since the casts are the recommended fixes. + + // e is an integer and U is *U_0, while U_0: Sized; addr-ptr-cast + let ptr_i32_transmute = unsafe { + -1 as *const i32 + }; + let ptr_i32 = -1isize as *const i32; + + // e has type *T, U is *U_0, and either U_0: Sized ... + let ptr_i8_transmute = unsafe { + ptr_i32 as *const i8 + }; + let ptr_i8 = ptr_i32 as *const i8; + + let slice_ptr = &[0,1,2,3] as *const [i32]; + + // ... or pointer_kind(T) = pointer_kind(U_0); ptr-ptr-cast + let ptr_to_unsized_transmute = unsafe { + slice_ptr as *const [u16] + }; + let ptr_to_unsized = slice_ptr as *const [u16]; + // TODO: We could try testing vtable casts here too, but maybe + // we should wait until std::raw::TraitObject is stabilized? + + // e has type *T and U is a numeric type, while T: Sized; ptr-addr-cast + let usize_from_int_ptr_transmute = unsafe { + ptr_i32 as usize + }; + let usize_from_int_ptr = ptr_i32 as usize; + + let array_ref: &[i32; 4] = &[1,2,3,4]; + + // e has type &[T; n] and U is *const T; array-ptr-cast + let array_ptr_transmute = unsafe { + array_ref as *const [i32; 4] + }; + let array_ptr = array_ref as *const [i32; 4]; + + fn foo(_: usize) -> u8 { 42 } + + // e is a function pointer type and U has type *T, while T: Sized; fptr-ptr-cast + let usize_ptr_transmute = unsafe { + foo as *const usize + }; + let usize_ptr_transmute = foo as *const usize; + + // e is a function pointer type and U is an integer; fptr-addr-cast + let usize_from_fn_ptr_transmute = unsafe { + foo as usize + }; + let usize_from_fn_ptr = foo as *const usize; +} + +// If a ref-to-ptr cast of this form where the pointer type points to a type other +// than the referenced type, calling `CastCheck::do_check` has been observed to +// cause an ICE error message. `do_check` is currently called inside the +// `transmutes_expressible_as_ptr_casts` check, but other, more specific lints +// currently prevent it from being called in these cases. This test is meant to +// fail if the ordering of the checks ever changes enough to cause these cases to +// fall through into `do_check`. +fn trigger_do_check_to_emit_error(in_param: &[i32; 1]) -> *const u8 { + unsafe { in_param as *const [i32; 1] as *const u8 } +} From f8a4c8c5d5dd1001ba759d803f6704f46f7b0f53 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 30 Jul 2020 11:27:50 +1000 Subject: [PATCH 0069/1222] Eliminate the `SessionGlobals` from `librustc_ast`. By moving `{known,used}_attrs` from `SessionGlobals` to `Session`. This means they are accessed via the `Session`, rather than via TLS. A few `Attr` methods and `librustc_ast` functions are now methods of `Session`. All of this required passing a `Session` to lots of functions that didn't already have one. Some of these functions also had arguments removed, because those arguments could be accessed directly via the `Session` argument. `contains_feature_attr()` was dead, and is removed. Some functions were moved from `librustc_ast` elsewhere because they now need to access `Session`, which isn't available in that crate. - `entry_point_type()` --> `librustc_builtin_macros` - `global_allocator_spans()` --> `librustc_metadata` - `is_proc_macro_attr()` --> `Session` --- clippy_lints/src/functions.rs | 6 +++--- clippy_lints/src/manual_non_exhaustive.rs | 4 ++-- clippy_lints/src/non_expressive_names.rs | 3 +-- clippy_lints/src/utils/attrs.rs | 5 ++--- clippy_lints/src/utils/mod.rs | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 3ee0b3f74b8c..6a141f1fc786 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -239,7 +239,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions { return; } if cx.access_levels.is_exported(item.hir_id) - && !is_proc_macro(&item.attrs) + && !is_proc_macro(cx.sess(), &item.attrs) && attr_by_name(&item.attrs, "no_mangle").is_none() { check_must_use_candidate( @@ -262,7 +262,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions { let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr); } else if cx.access_levels.is_exported(item.hir_id) - && !is_proc_macro(&item.attrs) + && !is_proc_macro(cx.sess(), &item.attrs) && trait_ref_of_method(cx, item.hir_id).is_none() { check_must_use_candidate( @@ -294,7 +294,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions { let body = cx.tcx.hir().body(eid); Self::check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id); - if attr.is_none() && cx.access_levels.is_exported(item.hir_id) && !is_proc_macro(&item.attrs) { + if attr.is_none() && cx.access_levels.is_exported(item.hir_id) && !is_proc_macro(cx.sess(), &item.attrs) { check_must_use_candidate( cx, &sig.decl, diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index ca1381852dae..4e49bdbdd21b 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -102,7 +102,7 @@ fn check_manual_non_exhaustive_enum(cx: &EarlyContext<'_>, item: &Item, variants "this seems like a manual implementation of the non-exhaustive pattern", |diag| { if_chain! { - if !attr::contains_name(&item.attrs, sym!(non_exhaustive)); + if !item.attrs.iter().any(|attr| attr.has_name(sym!(non_exhaustive))); let header_span = cx.sess.source_map().span_until_char(item.span, '{'); if let Some(snippet) = snippet_opt(cx, header_span); then { @@ -154,7 +154,7 @@ fn check_manual_non_exhaustive_struct(cx: &EarlyContext<'_>, item: &Item, data: "this seems like a manual implementation of the non-exhaustive pattern", |diag| { if_chain! { - if !attr::contains_name(&item.attrs, sym!(non_exhaustive)); + if !item.attrs.iter().any(|attr| attr.has_name(sym!(non_exhaustive))); let header_span = find_header_span(cx, item, data); if let Some(snippet) = snippet_opt(cx, header_span); then { diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 48ab98418e4f..603440c0f837 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -2,7 +2,6 @@ use crate::utils::{span_lint, span_lint_and_then}; use rustc_ast::ast::{ Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Item, ItemKind, Local, MacCall, Pat, PatKind, }; -use rustc_ast::attr; use rustc_ast::visit::{walk_block, walk_expr, walk_pat, Visitor}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_middle::lint::in_external_macro; @@ -385,7 +384,7 @@ impl EarlyLintPass for NonExpressiveNames { } fn do_check(lint: &mut NonExpressiveNames, cx: &EarlyContext<'_>, attrs: &[Attribute], decl: &FnDecl, blk: &Block) { - if !attr::contains_name(attrs, sym!(test)) { + if !attrs.iter().any(|attr| attr.has_name(sym!(test))) { let mut visitor = SimilarNamesLocalVisitor { names: Vec::new(), cx, diff --git a/clippy_lints/src/utils/attrs.rs b/clippy_lints/src/utils/attrs.rs index 4bb4b087c556..407527251da2 100644 --- a/clippy_lints/src/utils/attrs.rs +++ b/clippy_lints/src/utils/attrs.rs @@ -1,5 +1,4 @@ use rustc_ast::ast; -use rustc_ast::expand::is_proc_macro_attr; use rustc_errors::Applicability; use rustc_session::Session; use std::str::FromStr; @@ -126,6 +125,6 @@ fn parse_attrs(sess: &Session, attrs: &[ast::Attribute], name: &' /// Return true if the attributes contain any of `proc_macro`, /// `proc_macro_derive` or `proc_macro_attribute`, false otherwise -pub fn is_proc_macro(attrs: &[ast::Attribute]) -> bool { - attrs.iter().any(is_proc_macro_attr) +pub fn is_proc_macro(sess: &Session, attrs: &[ast::Attribute]) -> bool { + attrs.iter().any(|attr| sess.is_proc_macro_attr(attr)) } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 3f8e15d90297..95a12fe19354 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -932,7 +932,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { /// Checks for the `#[automatically_derived]` attribute all `#[derive]`d /// implementations have. pub fn is_automatically_derived(attrs: &[ast::Attribute]) -> bool { - attr::contains_name(attrs, sym!(automatically_derived)) + attrs.iter().any(|attr| attr.has_name(sym!(automatically_derived))) } /// Remove blocks around an expression. From 53564a9d51286afdfc366203e577379a42d8bcc2 Mon Sep 17 00:00:00 2001 From: Philippe Nadon Date: Sat, 8 Aug 2020 07:53:47 -0600 Subject: [PATCH 0070/1222] Miri: Renamed "undef" to "uninit" Renamed remaining references to "undef" to "uninit" when referring to Miri. Impacted directories are: - src/librustc_codegen_llvm/consts.rs - src/librustc_middle/mir/interpret/ - src/librustc_middle/ty/print/pretty.rs - src/librustc_mir/ - src/tools/clippy/clippy_lints/src/consts.rs Upon building Miri based on the new changes it was verified that no changes needed to be made with the Miri project. Related issue #71193 --- clippy_lints/src/consts.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 49ff86a205d9..c77b80bc2373 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -517,7 +517,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option { ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => match result.ty.kind { ty::Ref(_, tam, _) => match tam.kind { ty::Str => String::from_utf8( - data.inspect_with_undef_and_ptr_outside_interpreter(start..end) + data.inspect_with_uninit_and_ptr_outside_interpreter(start..end) .to_owned(), ) .ok() @@ -530,7 +530,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option { ty::Array(sub_type, len) => match sub_type.kind { ty::Float(FloatTy::F32) => match miri_to_const(len) { Some(Constant::Int(len)) => alloc - .inspect_with_undef_and_ptr_outside_interpreter(0..(4 * len as usize)) + .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * len as usize)) .to_owned() .chunks(4) .map(|chunk| { @@ -544,7 +544,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option { }, ty::Float(FloatTy::F64) => match miri_to_const(len) { Some(Constant::Int(len)) => alloc - .inspect_with_undef_and_ptr_outside_interpreter(0..(8 * len as usize)) + .inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * len as usize)) .to_owned() .chunks(8) .map(|chunk| { From f1f08c6e2b7027c4705573a8deca3584403941fa Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Sat, 8 Aug 2020 21:03:41 -0600 Subject: [PATCH 0071/1222] update stderr for transmutes_expressible_as_ptr_casts --- .../transmutes_expressible_as_ptr_casts.stderr | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.stderr b/tests/ui/transmutes_expressible_as_ptr_casts.stderr index e6edacbd0de8..721888802157 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.stderr +++ b/tests/ui/transmutes_expressible_as_ptr_casts.stderr @@ -1,5 +1,5 @@ error: transmute from an integer to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:18:9 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:19:9 | LL | transmute::(-1) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-1 as *const i32` @@ -7,7 +7,7 @@ LL | transmute::(-1) = note: `-D clippy::useless-transmute` implied by `-D warnings` error: transmute from a pointer to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:24:9 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:25:9 | LL | transmute::<*const i32, *const i8>(ptr_i32) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as *const i8` @@ -15,13 +15,13 @@ LL | transmute::<*const i32, *const i8>(ptr_i32) = note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` error: transmute from a pointer to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:32:9 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:33:9 | LL | transmute::<*const [i32], *const [u16]>(slice_ptr) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `slice_ptr as *const [u16]` error: transmute from `*const i32` to `usize` which could be expressed as a pointer cast instead - --> $DIR/transmutes_expressible_as_ptr_casts.rs:40:9 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:41:9 | LL | transmute::<*const i32, usize>(ptr_i32) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as usize` @@ -29,25 +29,25 @@ LL | transmute::<*const i32, usize>(ptr_i32) = note: `-D clippy::transmutes-expressible-as-ptr-casts` implied by `-D warnings` error: transmute from a reference to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:48:9 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:49:9 | LL | transmute::<&[i32; 4], *const [i32; 4]>(array_ref) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `array_ref as *const [i32; 4]` error: transmute from `fn(usize) -> u8 {main::foo}` to `*const usize` which could be expressed as a pointer cast instead - --> $DIR/transmutes_expressible_as_ptr_casts.rs:56:9 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:57:9 | LL | transmute:: u8, *const usize>(foo) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as *const usize` error: transmute from `fn(usize) -> u8 {main::foo}` to `usize` which could be expressed as a pointer cast instead - --> $DIR/transmutes_expressible_as_ptr_casts.rs:62:9 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:63:9 | LL | transmute:: u8, usize>(foo) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as usize` error: transmute from a reference to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:75:14 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:76:14 | LL | unsafe { transmute::<&[i32; 1], *const u8>(in_param) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `in_param as *const [i32; 1] as *const u8` From f5b966f835197fab5317be71e4cbc33c1631328e Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Sun, 9 Aug 2020 00:15:56 -0600 Subject: [PATCH 0072/1222] add a test example of where transmutes_expressible_as_ptr_casts should not suggest anything --- tests/ui/transmutes_expressible_as_ptr_casts.fixed | 14 +++++++++++++- tests/ui/transmutes_expressible_as_ptr_casts.rs | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.fixed b/tests/ui/transmutes_expressible_as_ptr_casts.fixed index ab181687e1eb..d80c9f62ed06 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.fixed +++ b/tests/ui/transmutes_expressible_as_ptr_casts.fixed @@ -5,7 +5,7 @@ #![warn(clippy::useless_transmute)] #![warn(clippy::transmute_ptr_to_ptr)] -use std::mem::transmute; +use std::mem::{size_of, transmute}; // rustc_typeck::check::cast contains documentation about when a cast `e as U` is // valid, which we quote from below. @@ -75,3 +75,15 @@ fn main() { fn trigger_do_check_to_emit_error(in_param: &[i32; 1]) -> *const u8 { unsafe { in_param as *const [i32; 1] as *const u8 } } + +#[repr(C)] +struct Single(u64); + +#[repr(C)] +struct Pair(u32, u32); + +fn cannot_be_expressed_as_pointer_cast(in_param: Single) -> Pair { + assert_eq!(size_of::(), size_of::()); + + unsafe { transmute::(in_param) } +} diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs index 2693094ba6ce..4f27a3a88ba7 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -5,7 +5,7 @@ #![warn(clippy::useless_transmute)] #![warn(clippy::transmute_ptr_to_ptr)] -use std::mem::transmute; +use std::mem::{size_of, transmute}; // rustc_typeck::check::cast contains documentation about when a cast `e as U` is // valid, which we quote from below. @@ -75,3 +75,15 @@ fn main() { fn trigger_do_check_to_emit_error(in_param: &[i32; 1]) -> *const u8 { unsafe { transmute::<&[i32; 1], *const u8>(in_param) } } + +#[repr(C)] +struct Single(u64); + +#[repr(C)] +struct Pair(u32, u32); + +fn cannot_be_expressed_as_pointer_cast(in_param: Single) -> Pair { + assert_eq!(size_of::(), size_of::()); + + unsafe { transmute::(in_param) } +} From 886c8a3ec272a3798ca5c13b1bdd3993a93db2b5 Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Sun, 9 Aug 2020 00:28:56 -0600 Subject: [PATCH 0073/1222] fix unary minus on usize and unused variable errors in .fixed file --- .../transmutes_expressible_as_ptr_casts.fixed | 30 +++++++++---------- .../ui/transmutes_expressible_as_ptr_casts.rs | 30 +++++++++---------- ...transmutes_expressible_as_ptr_casts.stderr | 4 +-- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.fixed b/tests/ui/transmutes_expressible_as_ptr_casts.fixed index d80c9f62ed06..4d3eba93bb3e 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.fixed +++ b/tests/ui/transmutes_expressible_as_ptr_casts.fixed @@ -15,54 +15,54 @@ fn main() { // the casts, since the casts are the recommended fixes. // e is an integer and U is *U_0, while U_0: Sized; addr-ptr-cast - let ptr_i32_transmute = unsafe { - -1 as *const i32 + let _ptr_i32_transmute = unsafe { + usize::MAX as *const i32 }; - let ptr_i32 = -1isize as *const i32; + let ptr_i32 = usize::MAX as *const i32; // e has type *T, U is *U_0, and either U_0: Sized ... - let ptr_i8_transmute = unsafe { + let _ptr_i8_transmute = unsafe { ptr_i32 as *const i8 }; - let ptr_i8 = ptr_i32 as *const i8; + let _ptr_i8 = ptr_i32 as *const i8; let slice_ptr = &[0,1,2,3] as *const [i32]; // ... or pointer_kind(T) = pointer_kind(U_0); ptr-ptr-cast - let ptr_to_unsized_transmute = unsafe { + let _ptr_to_unsized_transmute = unsafe { slice_ptr as *const [u16] }; - let ptr_to_unsized = slice_ptr as *const [u16]; + let _ptr_to_unsized = slice_ptr as *const [u16]; // TODO: We could try testing vtable casts here too, but maybe // we should wait until std::raw::TraitObject is stabilized? // e has type *T and U is a numeric type, while T: Sized; ptr-addr-cast - let usize_from_int_ptr_transmute = unsafe { + let _usize_from_int_ptr_transmute = unsafe { ptr_i32 as usize }; - let usize_from_int_ptr = ptr_i32 as usize; + let _usize_from_int_ptr = ptr_i32 as usize; let array_ref: &[i32; 4] = &[1,2,3,4]; // e has type &[T; n] and U is *const T; array-ptr-cast - let array_ptr_transmute = unsafe { + let _array_ptr_transmute = unsafe { array_ref as *const [i32; 4] }; - let array_ptr = array_ref as *const [i32; 4]; + let _array_ptr = array_ref as *const [i32; 4]; fn foo(_: usize) -> u8 { 42 } // e is a function pointer type and U has type *T, while T: Sized; fptr-ptr-cast - let usize_ptr_transmute = unsafe { + let _usize_ptr_transmute = unsafe { foo as *const usize }; - let usize_ptr_transmute = foo as *const usize; + let _usize_ptr_transmute = foo as *const usize; // e is a function pointer type and U is an integer; fptr-addr-cast - let usize_from_fn_ptr_transmute = unsafe { + let _usize_from_fn_ptr_transmute = unsafe { foo as usize }; - let usize_from_fn_ptr = foo as *const usize; + let _usize_from_fn_ptr = foo as *const usize; } // If a ref-to-ptr cast of this form where the pointer type points to a type other diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs index 4f27a3a88ba7..874812106433 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -15,54 +15,54 @@ fn main() { // the casts, since the casts are the recommended fixes. // e is an integer and U is *U_0, while U_0: Sized; addr-ptr-cast - let ptr_i32_transmute = unsafe { - transmute::(-1) + let _ptr_i32_transmute = unsafe { + transmute::(usize::MAX) }; - let ptr_i32 = -1isize as *const i32; + let ptr_i32 = usize::MAX as *const i32; // e has type *T, U is *U_0, and either U_0: Sized ... - let ptr_i8_transmute = unsafe { + let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr_i32) }; - let ptr_i8 = ptr_i32 as *const i8; + let _ptr_i8 = ptr_i32 as *const i8; let slice_ptr = &[0,1,2,3] as *const [i32]; // ... or pointer_kind(T) = pointer_kind(U_0); ptr-ptr-cast - let ptr_to_unsized_transmute = unsafe { + let _ptr_to_unsized_transmute = unsafe { transmute::<*const [i32], *const [u16]>(slice_ptr) }; - let ptr_to_unsized = slice_ptr as *const [u16]; + let _ptr_to_unsized = slice_ptr as *const [u16]; // TODO: We could try testing vtable casts here too, but maybe // we should wait until std::raw::TraitObject is stabilized? // e has type *T and U is a numeric type, while T: Sized; ptr-addr-cast - let usize_from_int_ptr_transmute = unsafe { + let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, usize>(ptr_i32) }; - let usize_from_int_ptr = ptr_i32 as usize; + let _usize_from_int_ptr = ptr_i32 as usize; let array_ref: &[i32; 4] = &[1,2,3,4]; // e has type &[T; n] and U is *const T; array-ptr-cast - let array_ptr_transmute = unsafe { + let _array_ptr_transmute = unsafe { transmute::<&[i32; 4], *const [i32; 4]>(array_ref) }; - let array_ptr = array_ref as *const [i32; 4]; + let _array_ptr = array_ref as *const [i32; 4]; fn foo(_: usize) -> u8 { 42 } // e is a function pointer type and U has type *T, while T: Sized; fptr-ptr-cast - let usize_ptr_transmute = unsafe { + let _usize_ptr_transmute = unsafe { transmute:: u8, *const usize>(foo) }; - let usize_ptr_transmute = foo as *const usize; + let _usize_ptr_transmute = foo as *const usize; // e is a function pointer type and U is an integer; fptr-addr-cast - let usize_from_fn_ptr_transmute = unsafe { + let _usize_from_fn_ptr_transmute = unsafe { transmute:: u8, usize>(foo) }; - let usize_from_fn_ptr = foo as *const usize; + let _usize_from_fn_ptr = foo as *const usize; } // If a ref-to-ptr cast of this form where the pointer type points to a type other diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.stderr b/tests/ui/transmutes_expressible_as_ptr_casts.stderr index 721888802157..72fb8689d657 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.stderr +++ b/tests/ui/transmutes_expressible_as_ptr_casts.stderr @@ -1,8 +1,8 @@ error: transmute from an integer to a pointer --> $DIR/transmutes_expressible_as_ptr_casts.rs:19:9 | -LL | transmute::(-1) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-1 as *const i32` +LL | transmute::(usize::MAX) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `usize::MAX as *const i32` | = note: `-D clippy::useless-transmute` implied by `-D warnings` From 2942b679b5a4f872e9b859d80c20151f2b4c0f9f Mon Sep 17 00:00:00 2001 From: Ryan1729 Date: Sun, 9 Aug 2020 00:39:14 -0600 Subject: [PATCH 0074/1222] add allow unused_unsafe and allow dead_code --- .../ui/transmutes_expressible_as_ptr_casts.fixed | 3 ++- tests/ui/transmutes_expressible_as_ptr_casts.rs | 3 ++- .../transmutes_expressible_as_ptr_casts.stderr | 16 ++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.fixed b/tests/ui/transmutes_expressible_as_ptr_casts.fixed index 4d3eba93bb3e..98288dde6d84 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.fixed +++ b/tests/ui/transmutes_expressible_as_ptr_casts.fixed @@ -4,12 +4,13 @@ // would otherwise be responsible for #![warn(clippy::useless_transmute)] #![warn(clippy::transmute_ptr_to_ptr)] +#![allow(unused_unsafe)] +#![allow(dead_code)] use std::mem::{size_of, transmute}; // rustc_typeck::check::cast contains documentation about when a cast `e as U` is // valid, which we quote from below. - fn main() { // We should see an error message for each transmute, and no error messages for // the casts, since the casts are the recommended fixes. diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs index 874812106433..fd5055c08f63 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -4,12 +4,13 @@ // would otherwise be responsible for #![warn(clippy::useless_transmute)] #![warn(clippy::transmute_ptr_to_ptr)] +#![allow(unused_unsafe)] +#![allow(dead_code)] use std::mem::{size_of, transmute}; // rustc_typeck::check::cast contains documentation about when a cast `e as U` is // valid, which we quote from below. - fn main() { // We should see an error message for each transmute, and no error messages for // the casts, since the casts are the recommended fixes. diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.stderr b/tests/ui/transmutes_expressible_as_ptr_casts.stderr index 72fb8689d657..46597acc6c0d 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.stderr +++ b/tests/ui/transmutes_expressible_as_ptr_casts.stderr @@ -1,5 +1,5 @@ error: transmute from an integer to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:19:9 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:20:9 | LL | transmute::(usize::MAX) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `usize::MAX as *const i32` @@ -7,7 +7,7 @@ LL | transmute::(usize::MAX) = note: `-D clippy::useless-transmute` implied by `-D warnings` error: transmute from a pointer to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:25:9 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:26:9 | LL | transmute::<*const i32, *const i8>(ptr_i32) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as *const i8` @@ -15,13 +15,13 @@ LL | transmute::<*const i32, *const i8>(ptr_i32) = note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` error: transmute from a pointer to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:33:9 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:34:9 | LL | transmute::<*const [i32], *const [u16]>(slice_ptr) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `slice_ptr as *const [u16]` error: transmute from `*const i32` to `usize` which could be expressed as a pointer cast instead - --> $DIR/transmutes_expressible_as_ptr_casts.rs:41:9 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:42:9 | LL | transmute::<*const i32, usize>(ptr_i32) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as usize` @@ -29,25 +29,25 @@ LL | transmute::<*const i32, usize>(ptr_i32) = note: `-D clippy::transmutes-expressible-as-ptr-casts` implied by `-D warnings` error: transmute from a reference to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:49:9 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:50:9 | LL | transmute::<&[i32; 4], *const [i32; 4]>(array_ref) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `array_ref as *const [i32; 4]` error: transmute from `fn(usize) -> u8 {main::foo}` to `*const usize` which could be expressed as a pointer cast instead - --> $DIR/transmutes_expressible_as_ptr_casts.rs:57:9 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:58:9 | LL | transmute:: u8, *const usize>(foo) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as *const usize` error: transmute from `fn(usize) -> u8 {main::foo}` to `usize` which could be expressed as a pointer cast instead - --> $DIR/transmutes_expressible_as_ptr_casts.rs:63:9 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:64:9 | LL | transmute:: u8, usize>(foo) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as usize` error: transmute from a reference to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:76:14 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:77:14 | LL | unsafe { transmute::<&[i32; 1], *const u8>(in_param) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `in_param as *const [i32; 1] as *const u8` From 5c16b347ef7893906c6b9e1f74da6a6964a42237 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Wed, 12 Aug 2020 12:22:56 +0200 Subject: [PATCH 0075/1222] merge `as_local_hir_id` with `local_def_id_to_hir_id` --- clippy_lints/src/derive.rs | 8 ++++---- clippy_lints/src/new_without_default.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 80a067589824..58b0704294b5 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -224,7 +224,7 @@ fn check_hash_peq<'tcx>( mess, |diag| { if let Some(local_def_id) = impl_id.as_local() { - let hir_id = cx.tcx.hir().as_local_hir_id(local_def_id); + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id); diag.span_note( cx.tcx.hir().span(hir_id), "`PartialEq` implemented here" @@ -278,7 +278,7 @@ fn check_ord_partial_ord<'tcx>( mess, |diag| { if let Some(local_def_id) = impl_id.as_local() { - let hir_id = cx.tcx.hir().as_local_hir_id(local_def_id); + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id); diag.span_note( cx.tcx.hir().span(hir_id), "`PartialOrd` implemented here" @@ -341,7 +341,7 @@ fn check_unsafe_derive_deserialize<'tcx>( ty: Ty<'tcx>, ) { fn item_from_def_id<'tcx>(cx: &LateContext<'tcx>, def_id: DefId) -> &'tcx Item<'tcx> { - let hir_id = cx.tcx.hir().as_local_hir_id(def_id.expect_local()); + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); cx.tcx.hir().expect_item(hir_id) } @@ -355,7 +355,7 @@ fn check_unsafe_derive_deserialize<'tcx>( if match_path(&trait_ref.path, &paths::SERDE_DESERIALIZE); if let ty::Adt(def, _) = ty.kind; if let Some(local_def_id) = def.did.as_local(); - let adt_hir_id = cx.tcx.hir().as_local_hir_id(local_def_id); + 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 cx.tcx.inherent_impls(def.did) .iter() diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 621ebdef2f0b..28d1322e9462 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -103,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { cx.tcx.for_each_impl(default_trait_id, |d| { if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() { if let Some(local_def_id) = ty_def.did.as_local() { - impls.insert(cx.tcx.hir().as_local_hir_id(local_def_id)); + impls.insert(cx.tcx.hir().local_def_id_to_hir_id(local_def_id)); } } }); From 137b29933936d5a47df7065dfd018b25e1030801 Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 4 Aug 2020 14:24:13 +0100 Subject: [PATCH 0076/1222] clippy: support `QPath::LangItem` This commit updates clippy with the introduction of `QPath::LangItem` so that it still compiles. Signed-off-by: David Wood --- clippy_lints/src/default_trait_access.rs | 2 +- clippy_lints/src/indexing_slicing.rs | 2 +- clippy_lints/src/infinite_iter.rs | 2 +- clippy_lints/src/len_zero.rs | 2 +- clippy_lints/src/loops.rs | 6 +- clippy_lints/src/match_on_vec_items.rs | 7 +- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/misc.rs | 1 + clippy_lints/src/ranges.rs | 8 +- clippy_lints/src/try_err.rs | 8 +- clippy_lints/src/types.rs | 1 + clippy_lints/src/unused_io_amount.rs | 11 +-- clippy_lints/src/utils/author.rs | 17 +++- clippy_lints/src/utils/higher.rs | 98 ++++++------------------ clippy_lints/src/utils/hir_utils.rs | 24 +++++- clippy_lints/src/utils/inspector.rs | 6 ++ clippy_lints/src/utils/mod.rs | 13 +++- clippy_lints/src/utils/paths.rs | 13 ---- clippy_lints/src/utils/sugg.rs | 8 +- tests/ui/author/for_loop.stdout | 16 ++-- 20 files changed, 117 insertions(+), 130 deletions(-) diff --git a/clippy_lints/src/default_trait_access.rs b/clippy_lints/src/default_trait_access.rs index 874e19d9e9fb..067ea903bdd9 100644 --- a/clippy_lints/src/default_trait_access.rs +++ b/clippy_lints/src/default_trait_access.rs @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultTraitAccess { ); } }, - QPath::TypeRelative(..) => {}, + QPath::TypeRelative(..) | QPath::LangItem(..) => {}, } } } diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index a1f58e54ae38..90b1a529be79 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Index(ref array, ref index) = &expr.kind { let ty = cx.typeck_results().expr_ty(array); - if let Some(range) = higher::range(cx, index) { + if let Some(range) = higher::range(index) { // Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..] if let ty::Array(_, s) = ty.kind { let size: u128 = if let Some(size) = s.try_eval_usize(cx.tcx, cx.param_env) { diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index e511d3ea3304..129abd7d8974 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -171,7 +171,7 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { Finite } }, - ExprKind::Struct(..) => higher::range(cx, expr).map_or(false, |r| r.end.is_none()).into(), + ExprKind::Struct(..) => higher::range(expr).map_or(false, |r| r.end.is_none()).into(), _ => Finite, } } diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 00d0b8b4e5b7..e5daa30f8ca1 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -262,7 +262,7 @@ fn check_len( fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { /// Special case ranges until `range_is_empty` is stabilized. See issue 3807. fn should_skip_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - higher::range(cx, expr).map_or(false, |_| { + higher::range(expr).map_or(false, |_| { !cx.tcx .features() .declared_lib_features diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 8352a8a3d2c6..8ffcd417d1df 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -1003,7 +1003,7 @@ fn detect_manual_memcpy<'tcx>( start: Some(start), end: Some(end), limits, - }) = higher::range(cx, arg) + }) = higher::range(arg) { // the var must be a single name if let PatKind::Binding(_, canonical_id, _, _) = pat.kind { @@ -1177,7 +1177,7 @@ fn check_for_loop_range<'tcx>( start: Some(start), ref end, limits, - }) = higher::range(cx, arg) + }) = higher::range(arg) { // the var must be a single name if let PatKind::Binding(_, canonical_id, ident, _) = pat.kind { @@ -1679,7 +1679,7 @@ fn check_for_mut_range_bound(cx: &LateContext<'_>, arg: &Expr<'_>, body: &Expr<' start: Some(start), end: Some(end), .. - }) = higher::range(cx, arg) + }) = higher::range(arg) { let mut_ids = vec![check_for_mutability(cx, start), check_for_mutability(cx, end)]; if mut_ids[0].is_some() || mut_ids[1].is_some() { diff --git a/clippy_lints/src/match_on_vec_items.rs b/clippy_lints/src/match_on_vec_items.rs index 4f8f2cb171d5..faa20687ef61 100644 --- a/clippy_lints/src/match_on_vec_items.rs +++ b/clippy_lints/src/match_on_vec_items.rs @@ -1,7 +1,8 @@ -use crate::utils::{self, is_type_diagnostic_item, match_type, snippet, span_lint_and_sugg, walk_ptrs_ty}; +use crate::utils::{is_type_diagnostic_item, is_type_lang_item, snippet, span_lint_and_sugg}; +use crate::utils::walk_ptrs_ty; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, MatchSource}; +use rustc_hir::{Expr, ExprKind, LangItem, MatchSource}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -96,5 +97,5 @@ fn is_vector(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { fn is_full_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let ty = cx.typeck_results().expr_ty(expr); let ty = walk_ptrs_ty(ty); - match_type(cx, ty, &utils::paths::RANGE_FULL) + is_type_lang_item(cx, ty, LangItem::RangeFull) } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 570ae66d595e..2265a1888556 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2271,7 +2271,7 @@ fn lint_iter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, iter_ if_chain! { if let hir::ExprKind::Index(ref caller_var, ref index_expr) = &caller_expr.kind; if let Some(higher::Range { start: Some(start_expr), end: None, limits: ast::RangeLimits::HalfOpen }) - = higher::range(cx, index_expr); + = higher::range(index_expr); if let hir::ExprKind::Lit(ref start_lit) = &start_expr.kind; if let ast::LitKind::Int(start_idx, _) = start_lit.node; then { diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 26a1c32b6b3a..482a563572db 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -433,6 +433,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints { return; } let binding = match expr.kind { + ExprKind::Path(hir::QPath::LangItem(..)) => None, ExprKind::Path(ref qpath) => { let binding = last_path_segment(qpath).ident.as_str(); if binding.starts_with('_') && diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index f88075798ca7..7a75fc125d0a 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for Ranges { if let ExprKind::MethodCall(ref iter_path, _, ref iter_args , _) = *iter; if iter_path.ident.name == sym!(iter); // range expression in `.zip()` call: `0..x.len()` - if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::range(cx, zip_arg); + if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::range(zip_arg); if is_integer_const(cx, start, 0); // `.len()` call if let ExprKind::MethodCall(ref len_path, _, ref len_args, _) = end.kind; @@ -180,7 +180,7 @@ fn check_exclusive_range_plus_one(cx: &LateContext<'_>, expr: &Expr<'_>) { start, end: Some(end), limits: RangeLimits::HalfOpen - }) = higher::range(cx, expr); + }) = higher::range(expr); if let Some(y) = y_plus_one(cx, end); then { let span = if expr.span.from_expansion() { @@ -225,7 +225,7 @@ fn check_exclusive_range_plus_one(cx: &LateContext<'_>, expr: &Expr<'_>) { // inclusive range minus one: `x..=(y-1)` fn check_inclusive_range_minus_one(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { - if let Some(higher::Range { start, end: Some(end), limits: RangeLimits::Closed }) = higher::range(cx, expr); + if let Some(higher::Range { start, end: Some(end), limits: RangeLimits::Closed }) = higher::range(expr); if let Some(y) = y_minus_one(cx, end); then { span_lint_and_then( @@ -279,7 +279,7 @@ fn check_reversed_empty_range(cx: &LateContext<'_>, expr: &Expr<'_>) { } if_chain! { - if let Some(higher::Range { start: Some(start), end: Some(end), limits }) = higher::range(cx, expr); + if let Some(higher::Range { start: Some(start), end: Some(end), limits }) = higher::range(expr); let ty = cx.typeck_results().expr_ty(start); if let ty::Int(_) | ty::Uint(_) = ty.kind; if let Some((start_idx, _)) = constant(cx, cx.typeck_results(), start); diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs index 3bd73d9f21a9..a74104e92820 100644 --- a/clippy_lints/src/try_err.rs +++ b/clippy_lints/src/try_err.rs @@ -1,10 +1,10 @@ use crate::utils::{ - is_type_diagnostic_item, match_def_path, match_qpath, paths, snippet, snippet_with_macro_callsite, - span_lint_and_sugg, + is_type_diagnostic_item, match_def_path, match_qpath, paths, snippet, + snippet_with_macro_callsite, span_lint_and_sugg, }; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, MatchSource}; +use rustc_hir::{Expr, ExprKind, QPath, LangItem, MatchSource}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::{self, Ty}; @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for TryErr { if let ExprKind::Match(ref match_arg, _, MatchSource::TryDesugar) = expr.kind; if let ExprKind::Call(ref match_fun, ref try_args) = match_arg.kind; if let ExprKind::Path(ref match_fun_path) = match_fun.kind; - if match_qpath(match_fun_path, &paths::TRY_INTO_RESULT); + if matches!(match_fun_path, QPath::LangItem(LangItem::TryIntoResult, _)); if let Some(ref try_arg) = try_args.get(0); if let ExprKind::Call(ref err_fun, ref err_args) = try_arg.kind; if let Some(ref err_arg) = err_args.get(0); diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index c3dea4475213..d1a7886a47ef 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -475,6 +475,7 @@ impl Types { } } }, + QPath::LangItem(..) => {}, } }, TyKind::Rptr(ref lt, ref mut_ty) => self.check_ty_rptr(cx, hir_ty, is_local, lt, mut_ty), diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index 1580f657d771..43166d26787a 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -1,4 +1,4 @@ -use crate::utils::{is_try, match_qpath, match_trait_method, paths, span_lint}; +use crate::utils::{is_try, match_trait_method, paths, span_lint}; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -42,10 +42,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount { match expr.kind { hir::ExprKind::Match(ref res, _, _) if is_try(expr).is_some() => { if let hir::ExprKind::Call(ref func, ref args) = res.kind { - if let hir::ExprKind::Path(ref path) = func.kind { - if match_qpath(path, &paths::TRY_INTO_RESULT) && args.len() == 1 { - check_method_call(cx, &args[0], expr); - } + if matches!( + func.kind, + hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::TryIntoResult, _)) + ) { + check_method_call(cx, &args[0], expr); } } else { check_method_call(cx, res, expr); diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 128fa87a1621..9b7a268c6287 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -175,9 +175,19 @@ impl PrintVisitor { } fn print_qpath(&mut self, path: &QPath<'_>) { - print!(" if match_qpath({}, &[", self.current); - print_path(path, &mut true); - println!("]);"); + match *path { + QPath::LangItem(lang_item, _) => { + println!( + " if matches!({}, QPath::LangItem(LangItem::{:?}, _));", + self.current, lang_item, + ); + }, + _ => { + print!(" if match_qpath({}, &[", self.current); + print_path(path, &mut true); + println!("]);"); + }, + } } } @@ -760,5 +770,6 @@ fn print_path(path: &QPath<'_>, first: &mut bool) { }, ref other => print!("/* unimplemented: {:?}*/", other), }, + QPath::LangItem(..) => panic!("print_path: called for lang item qpath"), } } diff --git a/clippy_lints/src/utils/higher.rs b/clippy_lints/src/utils/higher.rs index f81a132c7e7b..ba15456014d3 100644 --- a/clippy_lints/src/utils/higher.rs +++ b/clippy_lints/src/utils/higher.rs @@ -3,12 +3,11 @@ #![deny(clippy::missing_docs_in_private_items)] -use crate::utils::{is_expn_of, match_def_path, match_qpath, paths}; +use crate::utils::{is_expn_of, match_def_path, paths}; use if_chain::if_chain; use rustc_ast::ast; use rustc_hir as hir; use rustc_lint::LateContext; -use rustc_middle::ty; /// Converts a hir binary operator to the corresponding `ast` type. #[must_use] @@ -47,7 +46,7 @@ pub struct Range<'a> { } /// Higher a `hir` range to something similar to `ast::ExprKind::Range`. -pub fn range<'a, 'tcx>(cx: &LateContext<'tcx>, expr: &'a hir::Expr<'_>) -> Option> { +pub fn range<'a>(expr: &'a hir::Expr<'_>) -> Option> { /// Finds the field named `name` in the field. Always return `Some` for /// convenience. fn get_field<'c>(name: &str, fields: &'c [hir::Field<'_>]) -> Option<&'c hir::Expr<'c>> { @@ -56,94 +55,43 @@ pub fn range<'a, 'tcx>(cx: &LateContext<'tcx>, expr: &'a hir::Expr<'_>) -> Optio Some(expr) } - let def_path = match cx.typeck_results().expr_ty(expr).kind { - ty::Adt(def, _) => cx.tcx.def_path(def.did), - _ => return None, - }; - - // sanity checks for std::ops::RangeXXXX - if def_path.data.len() != 3 { - return None; - } - if def_path.data.get(0)?.data.as_symbol() != sym!(ops) { - return None; - } - if def_path.data.get(1)?.data.as_symbol() != sym!(range) { - return None; - } - let type_name = def_path.data.get(2)?.data.as_symbol(); - let range_types = [ - "RangeFrom", - "RangeFull", - "RangeInclusive", - "Range", - "RangeTo", - "RangeToInclusive", - ]; - if !range_types.contains(&&*type_name.as_str()) { - return None; - } - - // The range syntax is expanded to literal paths starting with `core` or `std` - // depending on - // `#[no_std]`. Testing both instead of resolving the paths. - match expr.kind { - hir::ExprKind::Path(ref path) => { - if match_qpath(path, &paths::RANGE_FULL_STD) || match_qpath(path, &paths::RANGE_FULL) { - Some(Range { + hir::ExprKind::Call(ref path, ref args) if matches!( + path.kind, + hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::RangeInclusiveNew, _)) + ) => Some(Range { + start: Some(&args[0]), + end: Some(&args[1]), + limits: ast::RangeLimits::Closed, + }), + hir::ExprKind::Struct(ref path, ref fields, None) => { + match path { + hir::QPath::LangItem(hir::LangItem::RangeFull, _) => Some(Range { start: None, end: None, limits: ast::RangeLimits::HalfOpen, - }) - } else { - None - } - }, - hir::ExprKind::Call(ref path, ref args) => { - if let hir::ExprKind::Path(ref path) = path.kind { - if match_qpath(path, &paths::RANGE_INCLUSIVE_STD_NEW) || match_qpath(path, &paths::RANGE_INCLUSIVE_NEW) - { - Some(Range { - start: Some(&args[0]), - end: Some(&args[1]), - limits: ast::RangeLimits::Closed, - }) - } else { - None - } - } else { - None - } - }, - hir::ExprKind::Struct(ref path, ref fields, None) => { - if match_qpath(path, &paths::RANGE_FROM_STD) || match_qpath(path, &paths::RANGE_FROM) { - Some(Range { + }), + hir::QPath::LangItem(hir::LangItem::RangeFrom, _) => Some(Range { start: Some(get_field("start", fields)?), end: None, limits: ast::RangeLimits::HalfOpen, - }) - } else if match_qpath(path, &paths::RANGE_STD) || match_qpath(path, &paths::RANGE) { - Some(Range { + }), + hir::QPath::LangItem(hir::LangItem::Range, _) => Some(Range { start: Some(get_field("start", fields)?), end: Some(get_field("end", fields)?), limits: ast::RangeLimits::HalfOpen, - }) - } else if match_qpath(path, &paths::RANGE_TO_INCLUSIVE_STD) || match_qpath(path, &paths::RANGE_TO_INCLUSIVE) - { - Some(Range { + }), + hir::QPath::LangItem(hir::LangItem::RangeToInclusive, _) => Some(Range { start: None, end: Some(get_field("end", fields)?), limits: ast::RangeLimits::Closed, - }) - } else if match_qpath(path, &paths::RANGE_TO_STD) || match_qpath(path, &paths::RANGE_TO) { - Some(Range { + }), + hir::QPath::LangItem(hir::LangItem::RangeTo, _) => Some(Range { start: None, end: Some(get_field("end", fields)?), limits: ast::RangeLimits::HalfOpen, - }) - } else { - None + }), + _ => None, } }, _ => None, diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index 28fb6ed12a05..2eefd4a38a67 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -3,9 +3,9 @@ use crate::utils::differing_macro_contexts; use rustc_ast::ast::InlineAsmTemplatePiece; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir::{ - BinOpKind, Block, BlockCheckMode, BodyId, BorrowKind, CaptureBy, Expr, ExprKind, Field, FnRetTy, GenericArg, - GenericArgs, Guard, InlineAsmOperand, Lifetime, LifetimeName, ParamName, Pat, PatKind, Path, PathSegment, QPath, - Stmt, StmtKind, Ty, TyKind, TypeBinding, + BinOpKind, Block, BlockCheckMode, BodyId, BorrowKind, CaptureBy, Expr, ExprKind, Field, FieldPat, + FnRetTy, GenericArg, GenericArgs, Guard, InlineAsmOperand, Lifetime, LifetimeName, ParamName, + Pat, PatKind, Path, PathSegment, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding, }; use rustc_lint::LateContext; use rustc_middle::ich::StableHashingContextProvider; @@ -185,10 +185,20 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { left.name == right.name } + pub fn eq_fieldpat(&mut self, left: &FieldPat<'_>, right: &FieldPat<'_>) -> bool { + match (&left, &right) { + (FieldPat { ident: li, pat: lp, .. }, FieldPat { ident: ri, pat: rp, .. }) => + li.name.as_str() == ri.name.as_str() && self.eq_pat(lp, rp), + } + } + /// Checks whether two patterns are the same. pub fn eq_pat(&mut self, left: &Pat<'_>, right: &Pat<'_>) -> bool { match (&left.kind, &right.kind) { (&PatKind::Box(ref l), &PatKind::Box(ref r)) => self.eq_pat(l, r), + (&PatKind::Struct(ref lp, ref la, ..), &PatKind::Struct(ref rp, ref ra, ..)) => { + self.eq_qpath(lp, rp) && over(la, ra, |l, r| self.eq_fieldpat(l, r)) + }, (&PatKind::TupleStruct(ref lp, ref la, ls), &PatKind::TupleStruct(ref rp, ref ra, rs)) => { self.eq_qpath(lp, rp) && over(la, ra, |l, r| self.eq_pat(l, r)) && ls == rs }, @@ -223,6 +233,8 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { (&QPath::TypeRelative(ref lty, ref lseg), &QPath::TypeRelative(ref rty, ref rseg)) => { self.eq_ty(lty, rty) && self.eq_path_segment(lseg, rseg) }, + (&QPath::LangItem(llang_item, _), &QPath::LangItem(rlang_item, _)) => + llang_item == rlang_item, _ => false, } } @@ -601,6 +613,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { QPath::TypeRelative(_, ref path) => { self.hash_name(path.ident.name); }, + QPath::LangItem(lang_item, ..) => { + lang_item.hash_stable(&mut self.cx.tcx.get_stable_hashing_context(), &mut self.s); + } } // self.maybe_typeck_results.unwrap().qpath_res(p, id).hash(&mut self.s); } @@ -710,6 +725,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_ty(ty); segment.ident.name.hash(&mut self.s); }, + QPath::LangItem(lang_item, ..) => { + lang_item.hash(&mut self.s); + } }, TyKind::OpaqueDef(_, arg_list) => { self.hash_generic_args(arg_list); diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index d8fa1fa278e2..4701a3f26e6f 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -266,6 +266,9 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { println!("{}Relative Path, {:?}", ind, ty); println!("{}seg: {:?}", ind, seg); }, + hir::ExprKind::Path(hir::QPath::LangItem(lang_item, ..)) => { + println!("{}Lang Item Path, {:?}", ind, lang_item.name()); + }, hir::ExprKind::AddrOf(kind, ref muta, ref e) => { println!("{}AddrOf", ind); println!("kind: {:?}", kind); @@ -488,6 +491,9 @@ fn print_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, indent: usize) { println!("{}Relative Path, {:?}", ind, ty); println!("{}seg: {:?}", ind, seg); }, + hir::PatKind::Path(hir::QPath::LangItem(lang_item, ..)) => { + println!("{}Lang Item Path, {:?}", ind, lang_item.name()); + }, hir::PatKind::Tuple(pats, opt_dots_position) => { println!("{}Tuple", ind); if let Some(dot_position) = opt_dots_position { diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 223628cc610d..a56b8203513e 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -142,6 +142,14 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symb } } +/// Checks if the type is equal to a lang item +pub fn is_type_lang_item(cx: &LateContext<'_>, ty: Ty<'_>, lang_item: hir::LangItem) -> bool { + match ty.kind { + ty::Adt(adt, _) => cx.tcx.lang_items().require(lang_item).unwrap() == adt.did, + _ => false, + } +} + /// Checks if the method call given in `expr` belongs to the given trait. pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str]) -> bool { let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap(); @@ -163,6 +171,7 @@ pub fn last_path_segment<'tcx>(path: &QPath<'tcx>) -> &'tcx PathSegment<'tcx> { match *path { QPath::Resolved(_, ref path) => path.segments.last().expect("A path must have at least one segment"), QPath::TypeRelative(_, ref seg) => seg, + QPath::LangItem(..) => panic!("last_path_segment: lang item has no path segments"), } } @@ -170,6 +179,7 @@ pub fn single_segment_path<'tcx>(path: &QPath<'tcx>) -> Option<&'tcx PathSegment match *path { QPath::Resolved(_, ref path) => path.segments.get(0), QPath::TypeRelative(_, ref seg) => Some(seg), + QPath::LangItem(..) => None, } } @@ -196,6 +206,7 @@ pub fn match_qpath(path: &QPath<'_>, segments: &[&str]) -> bool { }, _ => false, }, + QPath::LangItem(..) => false, } } @@ -277,7 +288,7 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Option { pub fn qpath_res(cx: &LateContext<'_>, qpath: &hir::QPath<'_>, id: hir::HirId) -> Res { match qpath { hir::QPath::Resolved(_, path) => path.res, - hir::QPath::TypeRelative(..) => { + hir::QPath::TypeRelative(..) | hir::QPath::LangItem(..) => { if cx.tcx.has_typeck_results(id.owner.to_def_id()) { cx.tcx.typeck(id.owner.to_def_id().expect_local()).qpath_res(qpath, id) } else { diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index 923b319d7778..9c28d63d414c 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -84,19 +84,7 @@ pub const POLL: [&str; 4] = ["core", "task", "poll", "Poll"]; pub const PTR_EQ: [&str; 3] = ["core", "ptr", "eq"]; pub const PTR_NULL: [&str; 2] = ["ptr", "null"]; pub const PTR_NULL_MUT: [&str; 2] = ["ptr", "null_mut"]; -pub const RANGE: [&str; 3] = ["core", "ops", "Range"]; pub const RANGE_ARGUMENT_TRAIT: [&str; 3] = ["core", "ops", "RangeBounds"]; -pub const RANGE_FROM: [&str; 3] = ["core", "ops", "RangeFrom"]; -pub const RANGE_FROM_STD: [&str; 3] = ["std", "ops", "RangeFrom"]; -pub const RANGE_FULL: [&str; 4] = ["core", "ops", "range", "RangeFull"]; -pub const RANGE_FULL_STD: [&str; 3] = ["std", "ops", "RangeFull"]; -pub const RANGE_INCLUSIVE_NEW: [&str; 4] = ["core", "ops", "RangeInclusive", "new"]; -pub const RANGE_INCLUSIVE_STD_NEW: [&str; 4] = ["std", "ops", "RangeInclusive", "new"]; -pub const RANGE_STD: [&str; 3] = ["std", "ops", "Range"]; -pub const RANGE_TO: [&str; 3] = ["core", "ops", "RangeTo"]; -pub const RANGE_TO_INCLUSIVE: [&str; 3] = ["core", "ops", "RangeToInclusive"]; -pub const RANGE_TO_INCLUSIVE_STD: [&str; 3] = ["std", "ops", "RangeToInclusive"]; -pub const RANGE_TO_STD: [&str; 3] = ["std", "ops", "RangeTo"]; pub const RC: [&str; 3] = ["alloc", "rc", "Rc"]; pub const RC_PTR_EQ: [&str; 4] = ["alloc", "rc", "Rc", "ptr_eq"]; pub const RECEIVER: [&str; 4] = ["std", "sync", "mpsc", "Receiver"]; @@ -130,7 +118,6 @@ pub const TO_STRING: [&str; 3] = ["alloc", "string", "ToString"]; pub const TO_STRING_METHOD: [&str; 4] = ["alloc", "string", "ToString", "to_string"]; pub const TRANSMUTE: [&str; 4] = ["core", "intrinsics", "", "transmute"]; pub const TRY_FROM: [&str; 4] = ["core", "convert", "TryFrom", "try_from"]; -pub const TRY_INTO_RESULT: [&str; 4] = ["std", "ops", "Try", "into_result"]; pub const TRY_INTO_TRAIT: [&str; 3] = ["core", "convert", "TryInto"]; pub const VEC: [&str; 3] = ["alloc", "vec", "Vec"]; pub const VEC_AS_MUT_SLICE: [&str; 4] = ["alloc", "vec", "Vec", "as_mut_slice"]; diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index 0ac7714fbeb7..2955f8d8e591 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -42,7 +42,7 @@ impl<'a> Sugg<'a> { pub fn hir_opt(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option { snippet_opt(cx, expr.span).map(|snippet| { let snippet = Cow::Owned(snippet); - Self::hir_from_snippet(cx, expr, snippet) + Self::hir_from_snippet(expr, snippet) }) } @@ -80,13 +80,13 @@ impl<'a> Sugg<'a> { pub fn hir_with_macro_callsite(cx: &LateContext<'_>, expr: &hir::Expr<'_>, default: &'a str) -> Self { let snippet = snippet_with_macro_callsite(cx, expr.span, default); - Self::hir_from_snippet(cx, expr, snippet) + Self::hir_from_snippet(expr, snippet) } /// Generate a suggestion for an expression with the given snippet. This is used by the `hir_*` /// function variants of `Sugg`, since these use different snippet functions. - fn hir_from_snippet(cx: &LateContext<'_>, expr: &hir::Expr<'_>, snippet: Cow<'a, str>) -> Self { - if let Some(range) = higher::range(cx, expr) { + fn hir_from_snippet(expr: &hir::Expr<'_>, snippet: Cow<'a, str>) -> Self { + if let Some(range) = higher::range(expr) { let op = match range.limits { ast::RangeLimits::HalfOpen => AssocOp::DotDot, ast::RangeLimits::Closed => AssocOp::DotDotEq, diff --git a/tests/ui/author/for_loop.stdout b/tests/ui/author/for_loop.stdout index 81ede955347d..3bf7607c62f0 100644 --- a/tests/ui/author/for_loop.stdout +++ b/tests/ui/author/for_loop.stdout @@ -3,10 +3,10 @@ if_chain! { if let ExprKind::Match(ref expr1, ref arms, MatchSource::ForLoopDesugar) = expr.kind; if let ExprKind::Call(ref func, ref args) = expr1.kind; if let ExprKind::Path(ref path) = func.kind; - if match_qpath(path, &["{{root}}", "std", "iter", "IntoIterator", "into_iter"]); + if matches!(path, QPath::LangItem(LangItem::IntoIterIntoIter, _)); if args.len() == 1; if let ExprKind::Struct(ref path1, ref fields, None) = args[0].kind; - if match_qpath(path1, &["{{root}}", "std", "ops", "Range"]); + if matches!(path1, QPath::LangItem(LangItem::Range, _)); if fields.len() == 2; // unimplemented: field checks if arms.len() == 1; @@ -20,7 +20,7 @@ if_chain! { if let ExprKind::Match(ref expr2, ref arms1, MatchSource::ForLoopDesugar) = e.kind; if let ExprKind::Call(ref func1, ref args1) = expr2.kind; if let ExprKind::Path(ref path2) = func1.kind; - if match_qpath(path2, &["{{root}}", "std", "iter", "Iterator", "next"]); + if matches!(path2, QPath::LangItem(LangItem::IteratorNext, _)); if args1.len() == 1; if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, ref inner) = args1[0].kind; if let ExprKind::Path(ref path3) = inner.kind; @@ -31,13 +31,15 @@ if_chain! { if match_qpath(path4, &["__next"]); if let ExprKind::Path(ref path5) = value.kind; if match_qpath(path5, &["val"]); - if let PatKind::TupleStruct(ref path6, ref fields1, None) = arms1[0].pat.kind; - if match_qpath(path6, &["{{root}}", "std", "option", "Option", "Some"]); + if let PatKind::Struct(ref path6, ref fields1, false) = arms1[0].pat.kind; + if matches!(path6, QPath::LangItem(LangItem::OptionSome, _)); if fields1.len() == 1; // unimplemented: field checks if let ExprKind::Break(ref destination, None) = arms1[1].body.kind; - if let PatKind::Path(ref path7) = arms1[1].pat.kind; - if match_qpath(path7, &["{{root}}", "std", "option", "Option", "None"]); + if let PatKind::Struct(ref path7, ref fields2, false) = arms1[1].pat.kind; + if matches!(path7, QPath::LangItem(LangItem::OptionNone, _)); + if fields2.len() == 0; + // unimplemented: field checks if let StmtKind::Local(ref local1) = body.stmts[2].kind; if let Some(ref init) = local1.init; if let ExprKind::Path(ref path8) = init.kind; From f27900bc2ce2b0cb11aad0af4af10de3639f2c17 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 27 Apr 2020 23:26:11 +0530 Subject: [PATCH 0077/1222] rust_ast::ast => rustc_ast --- clippy_lints/src/attrs.rs | 6 +++--- clippy_lints/src/lib.rs | 2 +- clippy_lints/src/single_component_path_imports.rs | 2 +- clippy_lints/src/strings.rs | 2 +- clippy_lints/src/transmute.rs | 2 +- clippy_lints/src/transmuting_null.rs | 2 +- clippy_lints/src/types.rs | 2 +- clippy_lints/src/unnested_or_patterns.rs | 2 +- clippy_lints/src/utils/ast_utils.rs | 2 +- clippy_lints/src/vec_resize_to_zero.rs | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 376ac55f9c98..76ccf2e4bb98 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -5,7 +5,7 @@ use crate::utils::{ span_lint_and_sugg, span_lint_and_then, without_block_comments, }; use if_chain::if_chain; -use rustc_ast::ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem}; +use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem}; use rustc_ast::util::lev_distance::find_best_match_for_name; use rustc_errors::Applicability; use rustc_hir::{ @@ -570,7 +570,7 @@ declare_lint_pass!(EarlyAttributes => [ ]); impl EarlyLintPass for EarlyAttributes { - fn check_item(&mut self, cx: &EarlyContext<'_>, item: &rustc_ast::ast::Item) { + fn check_item(&mut self, cx: &EarlyContext<'_>, item: &rustc_ast::Item) { check_empty_line_after_outer_attr(cx, item); } @@ -580,7 +580,7 @@ impl EarlyLintPass for EarlyAttributes { } } -fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::ast::Item) { +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 diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 6ad525d76205..aa1002636406 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -339,7 +339,7 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore) { } #[doc(hidden)] -pub fn read_conf(args: &[rustc_ast::ast::NestedMetaItem], sess: &Session) -> Conf { +pub fn read_conf(args: &[rustc_ast::NestedMetaItem], sess: &Session) -> Conf { use std::path::Path; match utils::conf::file_from_args(args) { Ok(file_name) => { diff --git a/clippy_lints/src/single_component_path_imports.rs b/clippy_lints/src/single_component_path_imports.rs index 2e853e8301d6..58bfd0bc553f 100644 --- a/clippy_lints/src/single_component_path_imports.rs +++ b/clippy_lints/src/single_component_path_imports.rs @@ -1,6 +1,6 @@ use crate::utils::{in_macro, span_lint_and_sugg}; use if_chain::if_chain; -use rustc_ast::ast::{Item, ItemKind, UseTreeKind}; +use rustc_ast::{Item, ItemKind, UseTreeKind}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index bada6fa7c522..7a659bf779c0 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -161,7 +161,7 @@ declare_lint_pass!(StringLitAsBytes => [STRING_LIT_AS_BYTES]); impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { use crate::utils::{snippet, snippet_with_applicability}; - use rustc_ast::ast::LitKind; + use rustc_ast::LitKind; if_chain! { if let ExprKind::MethodCall(path, _, args, _) = &e.kind; diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 7b5e92eb5ee1..28fd55f6ff0a 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -3,7 +3,7 @@ use crate::utils::{ span_lint_and_then, sugg, }; use if_chain::if_chain; -use rustc_ast::ast; +use rustc_ast as ast; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, GenericArg, Mutability, QPath, TyKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/transmuting_null.rs b/clippy_lints/src/transmuting_null.rs index fbf7f0b2517a..d60306336c6e 100644 --- a/clippy_lints/src/transmuting_null.rs +++ b/clippy_lints/src/transmuting_null.rs @@ -1,7 +1,7 @@ use crate::consts::{constant_context, Constant}; use crate::utils::{match_qpath, paths, span_lint}; use if_chain::if_chain; -use rustc_ast::ast::LitKind; +use rustc_ast::LitKind; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index c3dea4475213..a6911da1bb19 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -5,7 +5,7 @@ use std::cmp::Ordering; use std::collections::BTreeMap; use if_chain::if_chain; -use rustc_ast::ast::{FloatTy, IntTy, LitFloatType, LitIntType, LitKind, UintTy}; +use rustc_ast::{FloatTy, IntTy, LitFloatType, LitIntType, LitKind, UintTy}; use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, FnKind, NestedVisitorMap, Visitor}; diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 502bf0c42795..b7e2eba0a817 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -2,7 +2,7 @@ use crate::utils::ast_utils::{eq_field_pat, eq_id, eq_pat, eq_path}; use crate::utils::{over, span_lint_and_then}; -use rustc_ast::ast::{self, Pat, PatKind, PatKind::*, DUMMY_NODE_ID}; +use rustc_ast::{self as ast, Pat, PatKind, PatKind::*, DUMMY_NODE_ID}; use rustc_ast::mut_visit::*; use rustc_ast::ptr::P; use rustc_ast_pretty::pprust; diff --git a/clippy_lints/src/utils/ast_utils.rs b/clippy_lints/src/utils/ast_utils.rs index ad02bc5fd8e7..c32c80dcd3ce 100644 --- a/clippy_lints/src/utils/ast_utils.rs +++ b/clippy_lints/src/utils/ast_utils.rs @@ -5,7 +5,7 @@ #![allow(clippy::similar_names, clippy::wildcard_imports, clippy::enum_glob_use)] use crate::utils::{both, over}; -use rustc_ast::ast::{self, *}; +use rustc_ast::{self as ast, *}; use rustc_ast::ptr::P; use rustc_span::symbol::Ident; use std::mem; diff --git a/clippy_lints/src/vec_resize_to_zero.rs b/clippy_lints/src/vec_resize_to_zero.rs index 58e7c354b27d..d2494b321efc 100644 --- a/clippy_lints/src/vec_resize_to_zero.rs +++ b/clippy_lints/src/vec_resize_to_zero.rs @@ -7,7 +7,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Spanned; use crate::utils::{match_def_path, paths}; -use rustc_ast::ast::LitKind; +use rustc_ast::LitKind; use rustc_hir as hir; declare_clippy_lint! { From f3b1fc4529dc7be8988c80e2e992afe52d19cab5 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 27 Jul 2020 18:02:29 -0400 Subject: [PATCH 0078/1222] Capture tokens for Pat used in macro_rules! argument This extends PR #73293 to handle patterns (Pat). Unlike expressions, patterns do not support custom attributes, so we only need to capture tokens during macro_rules! argument parsing. --- clippy_lints/src/unnested_or_patterns.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index b7e2eba0a817..9fe771cef45b 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -340,6 +340,7 @@ fn take_pat(from: &mut Pat) -> Pat { id: DUMMY_NODE_ID, kind: Wild, span: DUMMY_SP, + tokens: None }; mem::replace(from, dummy) } From 1af1af0255366d7bf8244bef93da5c937f2cbfa6 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Mon, 24 Aug 2020 14:28:01 -0700 Subject: [PATCH 0079/1222] Unbreak the clippy test --- tests/ui/len_zero_ranges.fixed | 1 + tests/ui/len_zero_ranges.rs | 1 + tests/ui/len_zero_ranges.stderr | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/ui/len_zero_ranges.fixed b/tests/ui/len_zero_ranges.fixed index 7da26f8ff4d4..eee3db9b7d4b 100644 --- a/tests/ui/len_zero_ranges.fixed +++ b/tests/ui/len_zero_ranges.fixed @@ -3,6 +3,7 @@ #![feature(range_is_empty)] #![warn(clippy::len_zero)] #![allow(unused)] +#![allow(stable_features)] // TODO: https://github.com/rust-lang/rust-clippy/issues/5956 mod issue_3807 { // With the feature enabled, `is_empty` should be suggested diff --git a/tests/ui/len_zero_ranges.rs b/tests/ui/len_zero_ranges.rs index be7b4244bc06..be2e0f38fd16 100644 --- a/tests/ui/len_zero_ranges.rs +++ b/tests/ui/len_zero_ranges.rs @@ -3,6 +3,7 @@ #![feature(range_is_empty)] #![warn(clippy::len_zero)] #![allow(unused)] +#![allow(stable_features)] // TODO: https://github.com/rust-lang/rust-clippy/issues/5956 mod issue_3807 { // With the feature enabled, `is_empty` should be suggested diff --git a/tests/ui/len_zero_ranges.stderr b/tests/ui/len_zero_ranges.stderr index 6e5fa41fb08a..acb85f7100a3 100644 --- a/tests/ui/len_zero_ranges.stderr +++ b/tests/ui/len_zero_ranges.stderr @@ -1,5 +1,5 @@ error: length comparison to zero - --> $DIR/len_zero_ranges.rs:10:17 + --> $DIR/len_zero_ranges.rs:11:17 | LL | let _ = (0..42).len() == 0; | ^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(0..42).is_empty()` From 3cfa85f20a8895ff0444b4c2df30f809d2c77c3c Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Fri, 28 Aug 2020 13:26:25 -0700 Subject: [PATCH 0080/1222] Update dataflow analyses to use new interface --- clippy_lints/src/redundant_clone.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 7932be0d4b1f..aec99cb40633 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -14,7 +14,6 @@ use rustc_middle::mir::{ visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor as _}, }; use rustc_middle::ty::{self, fold::TypeVisitor, Ty}; -use rustc_mir::dataflow::BottomValue; use rustc_mir::dataflow::{Analysis, AnalysisDomain, GenKill, GenKillAnalysis, ResultsCursor}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::{BytePos, Span}; @@ -411,14 +410,15 @@ impl<'tcx> mir::visit::Visitor<'tcx> for LocalUseVisitor { struct MaybeStorageLive; impl<'tcx> AnalysisDomain<'tcx> for MaybeStorageLive { - type Idx = mir::Local; + type Domain = BitSet; const NAME: &'static str = "maybe_storage_live"; - fn bits_per_block(&self, body: &mir::Body<'tcx>) -> usize { - body.local_decls.len() + fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain { + // bottom = dead + BitSet::new_empty(body.local_decls.len()) } - fn initialize_start_block(&self, body: &mir::Body<'tcx>, state: &mut BitSet) { + fn initialize_start_block(&self, body: &mir::Body<'tcx>, state: &mut Self::Domain) { for arg in body.args_iter() { state.insert(arg); } @@ -426,6 +426,8 @@ impl<'tcx> AnalysisDomain<'tcx> for MaybeStorageLive { } impl<'tcx> GenKillAnalysis<'tcx> for MaybeStorageLive { + type Idx = mir::Local; + fn statement_effect(&self, trans: &mut impl GenKill, stmt: &mir::Statement<'tcx>, _: mir::Location) { match stmt.kind { mir::StatementKind::StorageLive(l) => trans.gen(l), @@ -454,11 +456,6 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeStorageLive { } } -impl BottomValue for MaybeStorageLive { - /// bottom = dead - const BOTTOM_VALUE: bool = false; -} - /// Collects the possible borrowers of each local. /// For example, `b = &a; c = &a;` will make `b` and (transitively) `c` /// possible borrowers of `a`. From d863aa2282de11b5d504d227d579180142876c47 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sun, 30 Aug 2020 19:17:17 -0400 Subject: [PATCH 0081/1222] Fix clippy --- clippy_lints/src/utils/ast_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/ast_utils.rs b/clippy_lints/src/utils/ast_utils.rs index 7b419431c0f5..3c3f8b26e3ac 100644 --- a/clippy_lints/src/utils/ast_utils.rs +++ b/clippy_lints/src/utils/ast_utils.rs @@ -191,7 +191,7 @@ pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool { (Item(l), Item(r)) => eq_item(l, r, eq_item_kind), (Expr(l), Expr(r)) | (Semi(l), Semi(r)) => eq_expr(l, r), (Empty, Empty) => true, - (MacCall(l), MacCall(r)) => l.1 == r.1 && eq_mac_call(&l.0, &r.0) && over(&l.2, &r.2, |l, r| eq_attr(l, r)), + (MacCall(l), MacCall(r)) => l.style == r.style && eq_mac_call(&l.mac, &r.mac) && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)), _ => false, } } From 536c12f7c2c76fcec4d58522919c8dbccdfecca0 Mon Sep 17 00:00:00 2001 From: Sasha Date: Mon, 31 Aug 2020 11:45:50 +0200 Subject: [PATCH 0082/1222] Improve recovery on malformed format call If a comma in a format call is replaced with a similar token, then we emit an error and continue parsing, instead of stopping at this point. --- tests/ui/issue-3145.rs | 2 +- tests/ui/issue-3145.stderr | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ui/issue-3145.rs b/tests/ui/issue-3145.rs index f497d5550af5..586d13647d15 100644 --- a/tests/ui/issue-3145.rs +++ b/tests/ui/issue-3145.rs @@ -1,3 +1,3 @@ fn main() { - println!("{}" a); //~ERROR expected token: `,` + println!("{}" a); //~ERROR expected `,`, found `a` } diff --git a/tests/ui/issue-3145.stderr b/tests/ui/issue-3145.stderr index cb0d95f5e264..a35032aa150d 100644 --- a/tests/ui/issue-3145.stderr +++ b/tests/ui/issue-3145.stderr @@ -1,7 +1,7 @@ -error: expected token: `,` +error: expected `,`, found `a` --> $DIR/issue-3145.rs:2:19 | -LL | println!("{}" a); //~ERROR expected token: `,` +LL | println!("{}" a); //~ERROR expected `,`, found `a` | ^ expected `,` error: aborting due to previous error From a779d18ee079b5940f3e7bd34e74d227cd1e68bc Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Tue, 4 Aug 2020 00:18:29 +0200 Subject: [PATCH 0083/1222] `ty.kind` -> `ty.kind()` in rustdoc and clippy --- clippy_lints/src/atomic_ordering.rs | 2 +- clippy_lints/src/await_holding_lock.rs | 2 +- clippy_lints/src/bytecount.rs | 2 +- clippy_lints/src/consts.rs | 24 ++++----- clippy_lints/src/default_trait_access.rs | 2 +- clippy_lints/src/derive.rs | 8 +-- clippy_lints/src/doc.rs | 4 +- clippy_lints/src/drop_forget_ref.rs | 2 +- clippy_lints/src/enum_clike.rs | 4 +- clippy_lints/src/eta_reduction.rs | 8 +-- clippy_lints/src/eval_order_dependence.rs | 4 +- .../src/float_equality_without_abs.rs | 4 +- clippy_lints/src/float_literal.rs | 2 +- clippy_lints/src/floating_point_arithmetic.rs | 2 +- clippy_lints/src/format.rs | 2 +- clippy_lints/src/functions.rs | 2 +- clippy_lints/src/future_not_send.rs | 2 +- clippy_lints/src/identity_op.rs | 2 +- clippy_lints/src/indexing_slicing.rs | 4 +- clippy_lints/src/large_const_arrays.rs | 2 +- clippy_lints/src/large_stack_arrays.rs | 2 +- clippy_lints/src/len_zero.rs | 2 +- clippy_lints/src/loops.rs | 12 ++--- clippy_lints/src/map_clone.rs | 4 +- clippy_lints/src/map_unit_fn.rs | 4 +- clippy_lints/src/matches.rs | 16 +++--- .../src/methods/inefficient_to_string.rs | 4 +- clippy_lints/src/methods/mod.rs | 54 +++++++++---------- clippy_lints/src/misc.rs | 6 +-- clippy_lints/src/modulo_arithmetic.rs | 2 +- clippy_lints/src/mut_key.rs | 4 +- clippy_lints/src/mut_mut.rs | 2 +- clippy_lints/src/mut_reference.rs | 4 +- clippy_lints/src/mutable_debug_assertion.rs | 2 +- clippy_lints/src/mutex_atomic.rs | 6 +-- clippy_lints/src/needless_borrow.rs | 6 +-- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/needless_update.rs | 2 +- clippy_lints/src/pattern_type_mismatch.rs | 10 ++-- clippy_lints/src/ptr.rs | 2 +- clippy_lints/src/ranges.rs | 2 +- clippy_lints/src/redundant_clone.rs | 4 +- clippy_lints/src/shadow.rs | 2 +- clippy_lints/src/swap.rs | 4 +- clippy_lints/src/to_digit_is_some.rs | 2 +- clippy_lints/src/transmute.rs | 12 ++--- .../src/trivially_copy_pass_by_ref.rs | 4 +- clippy_lints/src/try_err.rs | 12 ++--- clippy_lints/src/types.rs | 40 +++++++------- clippy_lints/src/unit_return_expecting_ord.rs | 2 +- clippy_lints/src/unnamed_address.rs | 4 +- clippy_lints/src/unnecessary_sort_by.rs | 2 +- clippy_lints/src/useless_conversion.rs | 4 +- clippy_lints/src/utils/mod.rs | 45 ++++++++-------- clippy_lints/src/vec.rs | 6 +-- 55 files changed, 187 insertions(+), 188 deletions(-) diff --git a/clippy_lints/src/atomic_ordering.rs b/clippy_lints/src/atomic_ordering.rs index 277fe350055e..2d964ac2b9f6 100644 --- a/clippy_lints/src/atomic_ordering.rs +++ b/clippy_lints/src/atomic_ordering.rs @@ -53,7 +53,7 @@ const ATOMIC_TYPES: [&str; 12] = [ ]; fn type_is_atomic(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.typeck_results().expr_ty(expr).kind { + if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.typeck_results().expr_ty(expr).kind() { ATOMIC_TYPES .iter() .any(|ty| match_def_path(cx, did, &["core", "sync", "atomic", ty])) diff --git a/clippy_lints/src/await_holding_lock.rs b/clippy_lints/src/await_holding_lock.rs index b10b1e0a65ab..f18e7e5d9975 100644 --- a/clippy_lints/src/await_holding_lock.rs +++ b/clippy_lints/src/await_holding_lock.rs @@ -67,7 +67,7 @@ impl LateLintPass<'_> for AwaitHoldingLock { fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorTypeCause<'_>], span: Span) { for ty_cause in ty_causes { - if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind { + if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind() { if is_mutex_guard(cx, adt.did) { span_lint_and_note( cx, diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index cdb49d777d8d..189c07427ae9 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -63,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount { _ => { return; } } }; - if ty::Uint(UintTy::U8) != walk_ptrs_ty(cx.typeck_results().expr_ty(needle)).kind { + if ty::Uint(UintTy::U8) != *walk_ptrs_ty(cx.typeck_results().expr_ty(needle)).kind() { return; } let haystack = if let ExprKind::MethodCall(ref path, _, ref args, _) = diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index c77b80bc2373..3ee022e4e68a 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -123,7 +123,7 @@ impl Constant { (&Self::Str(ref ls), &Self::Str(ref rs)) => Some(ls.cmp(rs)), (&Self::Char(ref l), &Self::Char(ref r)) => Some(l.cmp(r)), (&Self::Int(l), &Self::Int(r)) => { - if let ty::Int(int_ty) = cmp_type.kind { + if let ty::Int(int_ty) = *cmp_type.kind() { Some(sext(tcx, l, int_ty).cmp(&sext(tcx, r, int_ty))) } else { Some(l.cmp(&r)) @@ -162,7 +162,7 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option>) -> Constant { FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()), FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()), }, - LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind { + LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind() { ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()), ty::Float(FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()), _ => bug!(), @@ -230,7 +230,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { ExprKind::Array(ref vec) => self.multi(vec).map(Constant::Vec), ExprKind::Tup(ref tup) => self.multi(tup).map(Constant::Tuple), ExprKind::Repeat(ref value, _) => { - let n = match self.typeck_results.expr_ty(e).kind { + let n = match self.typeck_results.expr_ty(e).kind() { ty::Array(_, n) => n.try_eval_usize(self.lcx.tcx, self.lcx.param_env)?, _ => span_bug!(e.span, "typeck error"), }; @@ -281,7 +281,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { Bool(b) => Some(Bool(!b)), Int(value) => { let value = !value; - match ty.kind { + match *ty.kind() { ty::Int(ity) => Some(Int(unsext(self.lcx.tcx, value as i128, ity))), ty::Uint(ity) => Some(Int(clip(self.lcx.tcx, value, ity))), _ => None, @@ -295,7 +295,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { use self::Constant::{Int, F32, F64}; match *o { Int(value) => { - let ity = match ty.kind { + let ity = match *ty.kind() { ty::Int(ity) => ity, _ => return None, }; @@ -402,7 +402,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let l = self.expr(left)?; let r = self.expr(right); match (l, r) { - (Constant::Int(l), Some(Constant::Int(r))) => match self.typeck_results.expr_ty_opt(left)?.kind { + (Constant::Int(l), Some(Constant::Int(r))) => match *self.typeck_results.expr_ty_opt(left)?.kind() { ty::Int(ity) => { let l = sext(self.lcx.tcx, l, ity); let r = sext(self.lcx.tcx, r, ity); @@ -495,7 +495,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option { use rustc_middle::mir::interpret::{ConstValue, Scalar}; match result.val { ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data: d, .. })) => { - match result.ty.kind { + match result.ty.kind() { ty::Bool => Some(Constant::Bool(d == 1)), ty::Uint(_) | ty::Int(_) => Some(Constant::Int(d)), ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits( @@ -505,7 +505,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option { d.try_into().expect("invalid f64 bit representation"), ))), ty::RawPtr(type_and_mut) => { - if let ty::Uint(_) = type_and_mut.ty.kind { + if let ty::Uint(_) = type_and_mut.ty.kind() { return Some(Constant::RawPtr(d)); } None @@ -514,8 +514,8 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option { _ => None, } }, - ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => match result.ty.kind { - ty::Ref(_, tam, _) => match tam.kind { + ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => match result.ty.kind() { + ty::Ref(_, tam, _) => match tam.kind() { ty::Str => String::from_utf8( data.inspect_with_uninit_and_ptr_outside_interpreter(start..end) .to_owned(), @@ -526,8 +526,8 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option { }, _ => None, }, - ty::ConstKind::Value(ConstValue::ByRef { alloc, offset: _ }) => match result.ty.kind { - ty::Array(sub_type, len) => match sub_type.kind { + ty::ConstKind::Value(ConstValue::ByRef { alloc, offset: _ }) => match result.ty.kind() { + ty::Array(sub_type, len) => match sub_type.kind() { ty::Float(FloatTy::F32) => match miri_to_const(len) { Some(Constant::Int(len)) => alloc .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * len as usize)) diff --git a/clippy_lints/src/default_trait_access.rs b/clippy_lints/src/default_trait_access.rs index 067ea903bdd9..1654df56a9a5 100644 --- a/clippy_lints/src/default_trait_access.rs +++ b/clippy_lints/src/default_trait_access.rs @@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultTraitAccess { // TODO: Work out a way to put "whatever the imported way of referencing // this type in this file" rather than a fully-qualified type. let expr_ty = cx.typeck_results().expr_ty(expr); - if let ty::Adt(..) = expr_ty.kind { + if let ty::Adt(..) = expr_ty.kind() { let replacement = format!("{}::default()", expr_ty); span_lint_and_sugg( cx, diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 58b0704294b5..bf8e030cc294 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -299,20 +299,20 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &T return; } - match ty.kind { + match *ty.kind() { ty::Adt(def, _) if def.is_union() => return, // Some types are not Clone by default but could be cloned “by hand” if necessary ty::Adt(def, substs) => { for variant in &def.variants { for field in &variant.fields { - if let ty::FnDef(..) = field.ty(cx.tcx, substs).kind { + if let ty::FnDef(..) = field.ty(cx.tcx, substs).kind() { return; } } for subst in substs { if let ty::subst::GenericArgKind::Type(subst) = subst.unpack() { - if let ty::Param(_) = subst.kind { + if let ty::Param(_) = subst.kind() { return; } } @@ -353,7 +353,7 @@ fn check_unsafe_derive_deserialize<'tcx>( if_chain! { if match_path(&trait_ref.path, &paths::SERDE_DESERIALIZE); - if let ty::Adt(def, _) = ty.kind; + 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); diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 9555459e240e..50121a054c79 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -239,9 +239,9 @@ fn lint_for_missing_headers<'tcx>( let mir = cx.tcx.optimized_mir(def_id.to_def_id()); let ret_ty = mir.return_ty(); if implements_trait(cx, ret_ty, future, &[]); - if let ty::Opaque(_, subs) = ret_ty.kind; + if let ty::Opaque(_, subs) = ret_ty.kind(); if let Some(gen) = subs.types().next(); - if let ty::Generator(_, subs, _) = gen.kind; + if let ty::Generator(_, subs, _) = gen.kind(); if is_type_diagnostic_item(cx, subs.as_generator().return_ty(), sym!(result_type)); then { span_lint( diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 57ff569f14b0..cf528d189b4b 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -121,7 +121,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { let arg = &args[0]; let arg_ty = cx.typeck_results().expr_ty(arg); - if let ty::Ref(..) = arg_ty.kind { + if let ty::Ref(..) = arg_ty.kind() { if match_def_path(cx, def_id, &paths::DROP) { lint = DROP_REF; msg = DROP_REF_SUMMARY.to_string(); diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index 48caf48dbdb2..fb80f48a9ccf 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -53,12 +53,12 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant { .ok() .map(|val| rustc_middle::ty::Const::from_value(cx.tcx, val, ty)); if let Some(Constant::Int(val)) = constant.and_then(miri_to_const) { - if let ty::Adt(adt, _) = ty.kind { + if let ty::Adt(adt, _) = ty.kind() { if adt.is_enum() { ty = adt.repr.discr_type().to_ty(cx.tcx); } } - match ty.kind { + match ty.kind() { ty::Int(IntTy::Isize) => { let val = ((val as i128) << 64) >> 64; if i32::try_from(val).is_ok() { diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 87254c1dbc49..53df3abbf543 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -99,7 +99,7 @@ fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) { let fn_ty = cx.typeck_results().expr_ty(caller); - if matches!(fn_ty.kind, ty::FnDef(_, _) | ty::FnPtr(_) | ty::Closure(_, _)); + if matches!(fn_ty.kind(), ty::FnDef(_, _) | ty::FnPtr(_) | ty::Closure(_, _)); if !type_is_unsafe_function(cx, fn_ty); @@ -173,14 +173,14 @@ fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: def_id::DefId, self_a } fn match_borrow_depth(lhs: Ty<'_>, rhs: Ty<'_>) -> bool { - match (&lhs.kind, &rhs.kind) { + match (&lhs.kind(), &rhs.kind()) { (ty::Ref(_, t1, mut1), ty::Ref(_, t2, mut2)) => mut1 == mut2 && match_borrow_depth(&t1, &t2), (l, r) => !matches!((l, r), (ty::Ref(_, _, _), _) | (_, ty::Ref(_, _, _))), } } fn match_types(lhs: Ty<'_>, rhs: Ty<'_>) -> bool { - match (&lhs.kind, &rhs.kind) { + match (&lhs.kind(), &rhs.kind()) { (ty::Bool, ty::Bool) | (ty::Char, ty::Char) | (ty::Int(_), ty::Int(_)) @@ -194,7 +194,7 @@ fn match_types(lhs: Ty<'_>, rhs: Ty<'_>) -> bool { } fn get_type_name(cx: &LateContext<'_>, ty: Ty<'_>) -> String { - match ty.kind { + match ty.kind() { ty::Adt(t, _) => cx.tcx.def_path_str(t.did), ty::Ref(_, r, _) => get_type_name(cx, &r), _ => ty.to_string(), diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index c00638ecc0c1..4240147f498d 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -138,10 +138,10 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { ExprKind::Continue(_) | ExprKind::Break(_, _) | ExprKind::Ret(_) => self.report_diverging_sub_expr(e), ExprKind::Call(ref func, _) => { let typ = self.cx.typeck_results().expr_ty(func); - match typ.kind { + match typ.kind() { ty::FnDef(..) | ty::FnPtr(_) => { let sig = typ.fn_sig(self.cx.tcx); - if let ty::Never = self.cx.tcx.erase_late_bound_regions(&sig).output().kind { + if let ty::Never = self.cx.tcx.erase_late_bound_regions(&sig).output().kind() { self.report_diverging_sub_expr(e); } }, diff --git a/clippy_lints/src/float_equality_without_abs.rs b/clippy_lints/src/float_equality_without_abs.rs index 9ac5a45eb459..69818b4d3c64 100644 --- a/clippy_lints/src/float_equality_without_abs.rs +++ b/clippy_lints/src/float_equality_without_abs.rs @@ -81,8 +81,8 @@ impl<'tcx> LateLintPass<'tcx> for FloatEqualityWithoutAbs { // values of the substractions on the left hand side are of the type float let t_val_l = cx.typeck_results().expr_ty(val_l); let t_val_r = cx.typeck_results().expr_ty(val_r); - if let ty::Float(_) = t_val_l.kind; - if let ty::Float(_) = t_val_r.kind; + if let ty::Float(_) = t_val_l.kind(); + if let ty::Float(_) = t_val_r.kind(); then { let sug_l = sugg::Sugg::hir(cx, &val_l, ".."); diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index 358b9f6dcd0a..1fe4461533b3 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if_chain! { let ty = cx.typeck_results().expr_ty(expr); - if let ty::Float(fty) = ty.kind; + if let ty::Float(fty) = *ty.kind(); if let hir::ExprKind::Lit(ref lit) = expr.kind; if let LitKind::Float(sym, lit_float_ty) = lit.node; then { diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index 1b02cee126d0..18fea8b34bfd 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -136,7 +136,7 @@ fn prepare_receiver_sugg<'a>(cx: &LateContext<'_>, mut expr: &'a Expr<'a>) -> Su if_chain! { // if the expression is a float literal and it is unsuffixed then // add a suffix so the suggestion is valid and unambiguous - if let ty::Float(float_ty) = cx.typeck_results().expr_ty(expr).kind; + if let ty::Float(float_ty) = cx.typeck_results().expr_ty(expr).kind(); if let ExprKind::Lit(lit) = &expr.kind; if let ast::LitKind::Float(sym, ast::LitFloatType::Unsuffixed) = lit.node; then { diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 572c839502f4..8bd85af87682 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -91,7 +91,7 @@ fn on_argumentv1_new<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arms: & if pats.len() == 1; then { let ty = walk_ptrs_ty(cx.typeck_results().pat_ty(&pats[0])); - if ty.kind != rustc_middle::ty::Str && !is_type_diagnostic_item(cx, ty, sym!(string_type)) { + if *ty.kind() != rustc_middle::ty::Str && !is_type_diagnostic_item(cx, ty, sym!(string_type)) { return None; } if let ExprKind::Lit(ref lit) = format_args.kind { diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index ac1c7aa9bbbe..89fde1d509d3 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -505,7 +505,7 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut FxHashSet< static KNOWN_WRAPPER_TYS: &[&[&str]] = &[&["alloc", "rc", "Rc"], &["std", "sync", "Arc"]]; fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, tys: &mut FxHashSet) -> bool { - match ty.kind { + match *ty.kind() { // primitive types are never mutable ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false, ty::Adt(ref adt, ref substs) => { diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 0fdb5b8c2a48..2ab257ca88e3 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { return; } let ret_ty = utils::return_ty(cx, hir_id); - if let Opaque(id, subst) = ret_ty.kind { + if let Opaque(id, subst) = *ret_ty.kind() { let preds = cx.tcx.predicates_of(id).instantiate(cx.tcx, subst); let mut is_future = false; for p in preds.predicates { diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs index 4c62637858cd..8501d3477020 100644 --- a/clippy_lints/src/identity_op.rs +++ b/clippy_lints/src/identity_op.rs @@ -75,7 +75,7 @@ fn is_allowed(cx: &LateContext<'_>, cmp: BinOp, left: &Expr<'_>, right: &Expr<'_ #[allow(clippy::cast_possible_wrap)] fn check(cx: &LateContext<'_>, e: &Expr<'_>, m: i8, span: Span, arg: Span) { if let Some(Constant::Int(v)) = constant_simple(cx, cx.typeck_results(), e) { - let check = match cx.typeck_results().expr_ty(e).kind { + let check = match *cx.typeck_results().expr_ty(e).kind() { ty::Int(ity) => unsext(cx.tcx, -1_i128, ity), ty::Uint(uty) => clip(cx.tcx, !0, uty), _ => return, diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index 90b1a529be79..a28eda8be15a 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { let ty = cx.typeck_results().expr_ty(array); if let Some(range) = higher::range(index) { // Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..] - if let ty::Array(_, s) = ty.kind { + if let ty::Array(_, s) = ty.kind() { let size: u128 = if let Some(size) = s.try_eval_usize(cx.tcx, cx.param_env) { size.into() } else { @@ -141,7 +141,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { span_lint_and_help(cx, INDEXING_SLICING, expr.span, "slicing may panic.", None, help_msg); } else { // Catchall non-range index, i.e., [n] or [n << m] - if let ty::Array(..) = ty.kind { + if let ty::Array(..) = ty.kind() { // Index is a constant uint. if let Some(..) = constant(cx, cx.typeck_results(), index) { // Let rustc's `const_err` lint handle constant `usize` indexing on arrays. diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index c6cc174a8c97..025ff86da39d 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -51,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays { if !item.span.from_expansion(); if let ItemKind::Const(hir_ty, _) = &item.kind; let ty = hir_ty_to_ty(cx.tcx, hir_ty); - if let ty::Array(element_type, cst) = ty.kind; + if let ty::Array(element_type, cst) = ty.kind(); if let ConstKind::Value(val) = cst.val; if let ConstValue::Scalar(element_count) = val; if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx); diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index a7c715879232..9fd3780e14e0 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -42,7 +42,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Repeat(_, _) = expr.kind; - if let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind; + if let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind(); if let ConstKind::Value(val) = cst.val; if let ConstValue::Scalar(element_count) = val; if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx); diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index b691d363d2f2..42a98dc963d2 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -286,7 +286,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { } let ty = &walk_ptrs_ty(cx.typeck_results().expr_ty(expr)); - match ty.kind { + match ty.kind() { ty::Dynamic(ref tt, ..) => tt.principal().map_or(false, |principal| { cx.tcx .associated_items(principal.def_id()) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index c95e43a94304..604a97e3c083 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -826,7 +826,7 @@ struct FixedOffsetVar<'hir> { } fn is_slice_like<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'_>) -> bool { - let is_slice = match ty.kind { + let is_slice = match ty.kind() { ty::Ref(_, subty, _) => is_slice_like(cx, subty), ty::Slice(..) | ty::Array(..) => true, _ => false, @@ -1375,7 +1375,7 @@ fn is_end_eq_array_len<'tcx>( if_chain! { if let ExprKind::Lit(ref lit) = end.kind; if let ast::LitKind::Int(end_int, _) = lit.node; - if let ty::Array(_, arr_len_const) = indexed_ty.kind; + if let ty::Array(_, arr_len_const) = indexed_ty.kind(); if let Some(arr_len) = arr_len_const.try_eval_usize(cx.tcx, cx.param_env); then { return match limits { @@ -1612,7 +1612,7 @@ fn check_for_loop_over_map_kv<'tcx>( if let PatKind::Tuple(ref pat, _) = pat.kind { if pat.len() == 2 { let arg_span = arg.span; - let (new_pat_span, kind, ty, mutbl) = match cx.typeck_results().expr_ty(arg).kind { + let (new_pat_span, kind, ty, mutbl) = match *cx.typeck_results().expr_ty(arg).kind() { ty::Ref(_, ty, mutbl) => match (&pat[0].kind, &pat[1].kind) { (key, _) if pat_is_wild(key, body) => (pat[1].span, "value", ty, mutbl), (_, value) if pat_is_wild(value, body) => (pat[0].span, "key", ty, Mutability::Not), @@ -1940,7 +1940,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { for expr in args { let ty = self.cx.typeck_results().expr_ty_adjusted(expr); self.prefer_mutable = false; - if let ty::Ref(_, _, mutbl) = ty.kind { + if let ty::Ref(_, _, mutbl) = *ty.kind() { if mutbl == Mutability::Mut { self.prefer_mutable = true; } @@ -1952,7 +1952,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { let def_id = self.cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap(); for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) { self.prefer_mutable = false; - if let ty::Ref(_, _, mutbl) = ty.kind { + if let ty::Ref(_, _, mutbl) = *ty.kind() { if mutbl == Mutability::Mut { self.prefer_mutable = true; } @@ -2050,7 +2050,7 @@ fn is_ref_iterable_type(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { fn is_iterable_array<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool { // IntoIterator is currently only implemented for array sizes <= 32 in rustc - match ty.kind { + match ty.kind() { ty::Array(_, n) => n .try_eval_usize(cx.tcx, cx.param_env) .map_or(false, |val| (0..=32).contains(&val)), diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 1cd5b2012922..6d1c2ffbfbdd 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone { match closure_expr.kind { hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner) => { if ident_eq(name, inner) { - if let ty::Ref(.., Mutability::Not) = cx.typeck_results().expr_ty(inner).kind { + if let ty::Ref(.., Mutability::Not) = cx.typeck_results().expr_ty(inner).kind() { lint(cx, e.span, args[0].span, true); } } @@ -80,7 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone { && match_trait_method(cx, closure_expr, &paths::CLONE_TRAIT) { let obj_ty = cx.typeck_results().expr_ty(&obj[0]); - if let ty::Ref(_, ty, _) = obj_ty.kind { + if let ty::Ref(_, ty, _) = obj_ty.kind() { let copy = is_copy(cx, ty); lint(cx, e.span, args[0].span, copy); } else { diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 198251c58ddc..1f9ae8c931a1 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -93,7 +93,7 @@ declare_clippy_lint! { declare_lint_pass!(MapUnit => [OPTION_MAP_UNIT_FN, RESULT_MAP_UNIT_FN]); fn is_unit_type(ty: Ty<'_>) -> bool { - match ty.kind { + match ty.kind() { ty::Tuple(slice) => slice.is_empty(), ty::Never => true, _ => false, @@ -103,7 +103,7 @@ fn is_unit_type(ty: Ty<'_>) -> bool { fn is_unit_function(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { let ty = cx.typeck_results().expr_ty(expr); - if let ty::FnDef(id, _) = ty.kind { + if let ty::FnDef(id, _) = *ty.kind() { if let Some(fn_type) = cx.tcx.fn_sig(id).no_bound_vars() { return is_unit_type(fn_type.output()); } diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index be879dfe28d7..7ba7397c29cb 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -573,7 +573,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches { if let QPath::Resolved(_, ref path) = qpath; if let Some(def_id) = path.res.opt_def_id(); let ty = cx.tcx.type_of(def_id); - if let ty::Adt(def, _) = ty.kind; + if let ty::Adt(def, _) = ty.kind(); if def.is_struct() || def.is_union(); if fields.len() == def.non_enum_variant().fields.len(); @@ -621,7 +621,7 @@ fn check_single_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], exp }; let ty = cx.typeck_results().expr_ty(ex); - if ty.kind != ty::Bool || is_allowed(cx, MATCH_BOOL, ex.hir_id) { + if *ty.kind() != ty::Bool || is_allowed(cx, MATCH_BOOL, ex.hir_id) { check_single_match_single_pattern(cx, ex, arms, expr, els); check_single_match_opt_like(cx, ex, arms, expr, ty, els); } @@ -712,7 +712,7 @@ fn check_single_match_opt_like( fn check_match_bool(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { // Type of expression is `bool`. - if cx.typeck_results().expr_ty(ex).kind == ty::Bool { + if *cx.typeck_results().expr_ty(ex).kind() == ty::Bool { span_lint_and_then( cx, MATCH_BOOL, @@ -860,7 +860,7 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) // already covered. let mut missing_variants = vec![]; - if let ty::Adt(def, _) = ty.kind { + if let ty::Adt(def, _) = ty.kind() { for variant in &def.variants { missing_variants.push(variant); } @@ -914,7 +914,7 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) let mut message = "wildcard match will miss any future added variants"; - if let ty::Adt(def, _) = ty.kind { + if let ty::Adt(def, _) = ty.kind() { if def.is_variant_list_non_exhaustive() { message = "match on non-exhaustive enum doesn't explicitly match all known variants"; suggestion.push(String::from("_")); @@ -1014,11 +1014,11 @@ fn check_match_as_ref(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], exp let input_ty = cx.typeck_results().expr_ty(ex); let cast = if_chain! { - if let ty::Adt(_, substs) = input_ty.kind; + if let ty::Adt(_, substs) = input_ty.kind(); let input_ty = substs.type_at(0); - if let ty::Adt(_, substs) = output_ty.kind; + if let ty::Adt(_, substs) = output_ty.kind(); let output_ty = substs.type_at(0); - if let ty::Ref(_, output_ty, _) = output_ty.kind; + if let ty::Ref(_, output_ty, _) = *output_ty.kind(); if input_ty != output_ty; then { ".map(|x| x as _)" diff --git a/clippy_lints/src/methods/inefficient_to_string.rs b/clippy_lints/src/methods/inefficient_to_string.rs index e5f815772eba..5dae7efad976 100644 --- a/clippy_lints/src/methods/inefficient_to_string.rs +++ b/clippy_lints/src/methods/inefficient_to_string.rs @@ -46,7 +46,7 @@ pub fn lint<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, arg: &hir::Expr< /// Returns whether `ty` specializes `ToString`. /// Currently, these are `str`, `String`, and `Cow<'_, str>`. fn specializes_tostring(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { - if let ty::Str = ty.kind { + if let ty::Str = ty.kind() { return true; } @@ -54,7 +54,7 @@ fn specializes_tostring(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { return true; } - if let ty::Adt(adt, substs) = ty.kind { + if let ty::Adt(adt, substs) = ty.kind() { match_def_path(cx, adt.did, &paths::COW) && substs.type_at(1).is_str() } else { false diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 9996df69470f..a7a3d6751567 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1534,8 +1534,8 @@ impl<'tcx> LateLintPass<'tcx> for Methods { } } - match self_ty.kind { - ty::Ref(_, ty, _) if ty.kind == ty::Str => { + match self_ty.kind() { + ty::Ref(_, ty, _) if *ty.kind() == ty::Str => { for &(method, pos) in &PATTERN_METHODS { if method_call.ident.name.as_str() == method && args.len() > pos { lint_single_char_pattern(cx, expr, &args[pos]); @@ -1661,7 +1661,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { } // if return type is impl trait, check the associated types - if let ty::Opaque(def_id, _) = ret_ty.kind { + if let ty::Opaque(def_id, _) = *ret_ty.kind() { // one of the associated types must be Self for &(predicate, _span) in cx.tcx.predicates_of(def_id).predicates { if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() { @@ -1803,7 +1803,7 @@ fn lint_or_fun_call<'tcx>( if path.ident.as_str() == "len" { let ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0])); - match ty.kind { + match ty.kind() { ty::Slice(_) | ty::Array(_, _) => return, _ => (), } @@ -1910,7 +1910,7 @@ fn lint_expect_fun_call( && { let arg_type = cx.typeck_results().expr_ty(&call_args[0]); let base_type = walk_ptrs_ty(arg_type); - base_type.kind == ty::Str || is_type_diagnostic_item(cx, base_type, sym!(string_type)) + *base_type.kind() == ty::Str || is_type_diagnostic_item(cx, base_type, sym!(string_type)) } { &call_args[0] @@ -1931,8 +1931,8 @@ fn lint_expect_fun_call( if is_type_diagnostic_item(cx, arg_ty, sym!(string_type)) { return false; } - if let ty::Ref(_, ty, ..) = arg_ty.kind { - if ty.kind == ty::Str && can_be_static_str(cx, arg) { + if let ty::Ref(_, ty, ..) = arg_ty.kind() { + if *ty.kind() == ty::Str && can_be_static_str(cx, arg) { return false; } }; @@ -1948,7 +1948,7 @@ fn lint_expect_fun_call( if let hir::ExprKind::Path(ref p) = fun.kind { match cx.qpath_res(p, fun.hir_id) { hir::def::Res::Def(hir::def::DefKind::Fn | hir::def::DefKind::AssocFn, def_id) => matches!( - cx.tcx.fn_sig(def_id).output().skip_binder().kind, + cx.tcx.fn_sig(def_id).output().skip_binder().kind(), ty::Ref(ty::ReStatic, ..) ), _ => false, @@ -1962,7 +1962,7 @@ fn lint_expect_fun_call( .type_dependent_def_id(arg.hir_id) .map_or(false, |method_id| { matches!( - cx.tcx.fn_sig(method_id).output().skip_binder().kind, + cx.tcx.fn_sig(method_id).output().skip_binder().kind(), ty::Ref(ty::ReStatic, ..) ) }) @@ -2081,8 +2081,8 @@ fn lint_expect_fun_call( /// Checks for the `CLONE_ON_COPY` lint. fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'_>) { let ty = cx.typeck_results().expr_ty(expr); - if let ty::Ref(_, inner, _) = arg_ty.kind { - if let ty::Ref(_, innermost, _) = inner.kind { + if let ty::Ref(_, inner, _) = arg_ty.kind() { + if let ty::Ref(_, innermost, _) = inner.kind() { span_lint_and_then( cx, CLONE_DOUBLE_REF, @@ -2093,7 +2093,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Exp if let Some(snip) = sugg::Sugg::hir_opt(cx, arg) { let mut ty = innermost; let mut n = 0; - while let ty::Ref(_, inner, _) = ty.kind { + while let ty::Ref(_, inner, _) = ty.kind() { ty = inner; n += 1; } @@ -2172,7 +2172,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Exp fn lint_clone_on_ref_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>) { let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(arg)); - if let ty::Adt(_, subst) = obj_ty.kind { + if let ty::Adt(_, subst) = obj_ty.kind() { let caller_type = if is_type_diagnostic_item(cx, obj_ty, sym::Rc) { "Rc" } else if is_type_diagnostic_item(cx, obj_ty, sym::Arc) { @@ -2202,7 +2202,7 @@ fn lint_string_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::E if let Some(arglists) = method_chain_args(arg, &["chars"]) { let target = &arglists[0][0]; let self_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(target)); - let ref_str = if self_ty.kind == ty::Str { + let ref_str = if *self_ty.kind() == ty::Str { "" } else if is_type_diagnostic_item(cx, self_ty, sym!(string_type)) { "&" @@ -2238,7 +2238,7 @@ fn lint_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_> fn lint_cstring_as_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, source: &hir::Expr<'_>, unwrap: &hir::Expr<'_>) { if_chain! { let source_type = cx.typeck_results().expr_ty(source); - if let ty::Adt(def, substs) = source_type.kind; + if let ty::Adt(def, substs) = source_type.kind(); if cx.tcx.is_diagnostic_item(sym!(result_type), def.did); if match_type(cx, substs.type_at(0), &paths::CSTRING); then { @@ -2412,7 +2412,7 @@ fn lint_iter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, iter_ } } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(caller_expr), sym!(vec_type)) || matches!( - &walk_ptrs_ty(cx.typeck_results().expr_ty(caller_expr)).kind, + &walk_ptrs_ty(cx.typeck_results().expr_ty(caller_expr)).kind(), ty::Array(_, _) ) { @@ -2579,7 +2579,7 @@ fn derefs_to_slice<'tcx>( ty: Ty<'tcx>, ) -> Option<&'tcx hir::Expr<'tcx>> { fn may_slice<'a>(cx: &LateContext<'a>, ty: Ty<'a>) -> bool { - match ty.kind { + match ty.kind() { ty::Slice(_) => true, ty::Adt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()), ty::Adt(..) => is_type_diagnostic_item(cx, ty, sym!(vec_type)), @@ -2598,7 +2598,7 @@ fn derefs_to_slice<'tcx>( None } } else { - match ty.kind { + match ty.kind() { ty::Slice(_) => Some(expr), ty::Adt(def, _) if def.is_box() && may_slice(cx, ty.boxed_ty()) => Some(expr), ty::Ref(_, inner, _) => { @@ -2692,9 +2692,9 @@ fn lint_map_flatten<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map // lint if caller of `.map().flatten()` is an Iterator if match_trait_method(cx, expr, &paths::ITERATOR) { let map_closure_ty = cx.typeck_results().expr_ty(&map_args[1]); - let is_map_to_option = match map_closure_ty.kind { + let is_map_to_option = match map_closure_ty.kind() { ty::Closure(_, _) | ty::FnDef(_, _) | ty::FnPtr(_) => { - let map_closure_sig = match map_closure_ty.kind { + let map_closure_sig = match map_closure_ty.kind() { ty::Closure(_, substs) => substs.as_closure().sig(), _ => map_closure_ty.fn_sig(cx.tcx), }; @@ -3164,7 +3164,7 @@ fn lint_chars_cmp( let mut applicability = Applicability::MachineApplicable; let self_ty = walk_ptrs_ty(cx.typeck_results().expr_ty_adjusted(&args[0][0])); - if self_ty.kind != ty::Str { + if *self_ty.kind() != ty::Str { return false; } @@ -3352,7 +3352,7 @@ fn lint_asref(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str, as_re fn ty_has_iter_method(cx: &LateContext<'_>, self_ref_ty: Ty<'_>) -> Option<(&'static str, &'static str)> { has_iter_method(cx, self_ref_ty).map(|ty_name| { - let mutbl = match self_ref_ty.kind { + let mutbl = match self_ref_ty.kind() { ty::Ref(_, _, mutbl) => mutbl, _ => unreachable!(), }; @@ -3404,7 +3404,7 @@ fn lint_maybe_uninit(cx: &LateContext<'_>, expr: &hir::Expr<'_>, outer: &hir::Ex } fn is_maybe_uninit_ty_valid(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { - match ty.kind { + match ty.kind() { ty::Array(ref component, _) => is_maybe_uninit_ty_valid(cx, component), ty::Tuple(ref types) => types.types().all(|ty| is_maybe_uninit_ty_valid(cx, ty)), ty::Adt(ref adt, _) => match_def_path(cx, adt.did, &paths::MEM_MAYBEUNINIT), @@ -3531,7 +3531,7 @@ fn lint_option_as_ref_deref<'tcx>( /// Given a `Result` type, return its error type (`E`). fn get_error_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option> { - match ty.kind { + match ty.kind() { ty::Adt(_, substs) if is_type_diagnostic_item(cx, ty, sym!(result_type)) => substs.types().nth(1), _ => None, } @@ -3685,7 +3685,7 @@ impl SelfKind { } else if ty.is_box() { ty.boxed_ty() == parent_ty } else if is_type_diagnostic_item(cx, ty, sym::Rc) || is_type_diagnostic_item(cx, ty, sym::Arc) { - if let ty::Adt(_, substs) = ty.kind { + if let ty::Adt(_, substs) = ty.kind() { substs.types().next().map_or(false, |t| t == parent_ty) } else { false @@ -3696,7 +3696,7 @@ impl SelfKind { } fn matches_ref<'a>(cx: &LateContext<'a>, mutability: hir::Mutability, parent_ty: Ty<'a>, ty: Ty<'a>) -> bool { - if let ty::Ref(_, t, m) = ty.kind { + if let ty::Ref(_, t, m) = *ty.kind() { return m == mutability && t == parent_ty; } @@ -3813,7 +3813,7 @@ fn contains_return(expr: &hir::Expr<'_>) -> bool { fn check_pointer_offset(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { if_chain! { if args.len() == 2; - if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.typeck_results().expr_ty(&args[0]).kind; + if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.typeck_results().expr_ty(&args[0]).kind(); if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty)); if layout.is_zst(); then { diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 06f367a8b775..d4a50dd9013f 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -561,17 +561,17 @@ fn is_signum(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { } fn is_float(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - let value = &walk_ptrs_ty(cx.typeck_results().expr_ty(expr)).kind; + let value = &walk_ptrs_ty(cx.typeck_results().expr_ty(expr)).kind(); if let ty::Array(arr_ty, _) = value { - return matches!(arr_ty.kind, ty::Float(_)); + return matches!(arr_ty.kind(), ty::Float(_)); }; matches!(value, ty::Float(_)) } fn is_array(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - matches!(&walk_ptrs_ty(cx.typeck_results().expr_ty(expr)).kind, ty::Array(_, _)) + matches!(&walk_ptrs_ty(cx.typeck_results().expr_ty(expr)).kind(), ty::Array(_, _)) } fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool) { diff --git a/clippy_lints/src/modulo_arithmetic.rs b/clippy_lints/src/modulo_arithmetic.rs index b1d788b5c683..da3ae1d652f6 100644 --- a/clippy_lints/src/modulo_arithmetic.rs +++ b/clippy_lints/src/modulo_arithmetic.rs @@ -38,7 +38,7 @@ struct OperandInfo { fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { match constant(cx, cx.typeck_results(), operand) { - Some((Constant::Int(v), _)) => match cx.typeck_results().expr_ty(expr).kind { + Some((Constant::Int(v), _)) => match *cx.typeck_results().expr_ty(expr).kind() { ty::Int(ity) => { let value = sext(cx.tcx, v, ity); return Some(OperandInfo { diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 9f8f401cc0f6..7423107e8f94 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -97,7 +97,7 @@ fn check_sig<'tcx>(cx: &LateContext<'tcx>, item_hir_id: hir::HirId, decl: &hir:: // generics (because the compiler cannot ensure immutability for unknown types). fn check_ty<'tcx>(cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) { let ty = walk_ptrs_ty(ty); - if let Adt(def, substs) = ty.kind { + if let Adt(def, substs) = ty.kind() { if [&paths::HASHMAP, &paths::BTREEMAP, &paths::HASHSET, &paths::BTREESET] .iter() .any(|path| match_def_path(cx, def.did, &**path)) @@ -109,7 +109,7 @@ fn check_ty<'tcx>(cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) { } fn is_mutable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span) -> bool { - match ty.kind { + match *ty.kind() { RawPtr(TypeAndMut { ty: inner_ty, mutbl }) | Ref(_, inner_ty, mutbl) => { mutbl == hir::Mutability::Mut || is_mutable_type(cx, inner_ty, span) }, diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index b02e86bca271..2f3cdb894f01 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -69,7 +69,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { expr.span, "generally you want to avoid `&mut &mut _` if possible", ); - } else if let ty::Ref(_, _, hir::Mutability::Mut) = self.cx.typeck_results().expr_ty(e).kind { + } else if let ty::Ref(_, _, hir::Mutability::Mut) = self.cx.typeck_results().expr_ty(e).kind() { span_lint( self.cx, MUT_MUT, diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index c506440ed798..3f0b765df156 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -61,11 +61,11 @@ fn check_arguments<'tcx>( name: &str, fn_kind: &str, ) { - match type_definition.kind { + match type_definition.kind() { ty::FnDef(..) | ty::FnPtr(_) => { let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs(); for (argument, parameter) in arguments.iter().zip(parameters.iter()) { - match parameter.kind { + match parameter.kind() { ty::Ref(_, _, Mutability::Not) | ty::RawPtr(ty::TypeAndMut { mutbl: Mutability::Not, .. diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index 7f529f0404c0..cc635c2a202f 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -138,7 +138,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> { if let Some(adj) = self.cx.typeck_results().adjustments().get(expr.hir_id) { if adj .iter() - .any(|a| matches!(a.target.kind, ty::Ref(_, _, Mutability::Mut))) + .any(|a| matches!(a.target.kind(), ty::Ref(_, _, Mutability::Mut))) { self.found = true; return; diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index 21efee712698..ea986874291e 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -67,7 +67,7 @@ declare_lint_pass!(Mutex => [MUTEX_ATOMIC, MUTEX_INTEGER]); impl<'tcx> LateLintPass<'tcx> for Mutex { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { let ty = cx.typeck_results().expr_ty(expr); - if let ty::Adt(_, subst) = ty.kind { + if let ty::Adt(_, subst) = ty.kind() { if is_type_diagnostic_item(cx, ty, sym!(mutex_type)) { let mutex_param = subst.type_at(0); if let Some(atomic_name) = get_atomic_name(mutex_param) { @@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for Mutex { behavior and not the internal type, consider using `Mutex<()>`", atomic_name ); - match mutex_param.kind { + match *mutex_param.kind() { ty::Uint(t) if t != ast::UintTy::Usize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg), ty::Int(t) if t != ast::IntTy::Isize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg), _ => span_lint(cx, MUTEX_ATOMIC, expr.span, &msg), @@ -88,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for Mutex { } fn get_atomic_name(ty: Ty<'_>) -> Option<&'static str> { - match ty.kind { + match ty.kind() { ty::Bool => Some("AtomicBool"), ty::Uint(_) => Some("AtomicUsize"), ty::Int(_) => Some("AtomicIsize"), diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index 9391049c6e8f..b71d5496a37a 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow { return; } if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = e.kind { - if let ty::Ref(..) = cx.typeck_results().expr_ty(inner).kind { + if let ty::Ref(..) = cx.typeck_results().expr_ty(inner).kind() { for adj3 in cx.typeck_results().expr_adjustments(e).windows(3) { if let [Adjustment { kind: Adjust::Deref(_), .. @@ -85,9 +85,9 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow { } if_chain! { if let PatKind::Binding(BindingAnnotation::Ref, .., name, _) = pat.kind; - if let ty::Ref(_, tam, mutbl) = cx.typeck_results().pat_ty(pat).kind; + if let ty::Ref(_, tam, mutbl) = *cx.typeck_results().pat_ty(pat).kind(); if mutbl == Mutability::Not; - if let ty::Ref(_, _, mutbl) = tam.kind; + if let ty::Ref(_, _, mutbl) = *tam.kind(); // only lint immutable refs, because borrowed `&mut T` cannot be moved out if mutbl == Mutability::Not; then { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 047a78b08784..7e933c674dd7 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -194,7 +194,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { // Dereference suggestion let sugg = |diag: &mut DiagnosticBuilder<'_>| { - if let ty::Adt(def, ..) = ty.kind { + if let ty::Adt(def, ..) = ty.kind() { if let Some(span) = cx.tcx.hir().span_if_local(def.did) { if can_type_implement_copy(cx.tcx, cx.param_env, ty).is_ok() { diag.span_help(span, "consider marking this type as `Copy`"); diff --git a/clippy_lints/src/needless_update.rs b/clippy_lints/src/needless_update.rs index ce3f066eff5e..98e9078094a2 100644 --- a/clippy_lints/src/needless_update.rs +++ b/clippy_lints/src/needless_update.rs @@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessUpdate { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Struct(_, ref fields, Some(ref base)) = expr.kind { let ty = cx.typeck_results().expr_ty(expr); - if let ty::Adt(def, _) = ty.kind { + if let ty::Adt(def, _) = ty.kind() { if fields.len() == def.non_enum_variant().fields.len() { span_lint( cx, diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index ef26fc667b22..5539331d0460 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -187,19 +187,19 @@ fn find_first_mismatch<'tcx>( level: Level, ) -> Option<(Span, Mutability, Level)> { if let PatKind::Ref(ref sub_pat, _) = pat.kind { - if let TyKind::Ref(_, sub_ty, _) = ty.kind { + if let TyKind::Ref(_, sub_ty, _) = ty.kind() { return find_first_mismatch(cx, sub_pat, sub_ty, Level::Lower); } } - if let TyKind::Ref(_, _, mutability) = ty.kind { + if let TyKind::Ref(_, _, mutability) = *ty.kind() { if is_non_ref_pattern(&pat.kind) { return Some((pat.span, mutability, level)); } } if let PatKind::Struct(ref qpath, ref field_pats, _) = pat.kind { - if let TyKind::Adt(ref adt_def, ref substs_ref) = ty.kind { + if let TyKind::Adt(ref adt_def, ref substs_ref) = ty.kind() { if let Some(variant) = get_variant(adt_def, qpath) { let field_defs = &variant.fields; return find_first_mismatch_in_struct(cx, field_pats, field_defs, substs_ref); @@ -208,7 +208,7 @@ fn find_first_mismatch<'tcx>( } if let PatKind::TupleStruct(ref qpath, ref pats, _) = pat.kind { - if let TyKind::Adt(ref adt_def, ref substs_ref) = ty.kind { + if let TyKind::Adt(ref adt_def, ref substs_ref) = ty.kind() { if let Some(variant) = get_variant(adt_def, qpath) { let field_defs = &variant.fields; let ty_iter = field_defs.iter().map(|field_def| field_def.ty(cx.tcx, substs_ref)); @@ -218,7 +218,7 @@ fn find_first_mismatch<'tcx>( } if let PatKind::Tuple(ref pats, _) = pat.kind { - if let TyKind::Tuple(..) = ty.kind { + if let TyKind::Tuple(..) = ty.kind() { return find_first_mismatch_in_tuple(cx, pats, ty.tuple_fields()); } } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 7dafb1555dc6..6b1c848a9467 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -180,7 +180,7 @@ fn check_fn(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_id: } } - if let ty::Ref(_, ty, Mutability::Not) = ty.kind { + if let ty::Ref(_, ty, Mutability::Not) = ty.kind() { if is_type_diagnostic_item(cx, ty, sym!(vec_type)) { let mut ty_snippet = None; if_chain! { diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 7a75fc125d0a..cc492917b9da 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -281,7 +281,7 @@ fn check_reversed_empty_range(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let Some(higher::Range { start: Some(start), end: Some(end), limits }) = higher::range(expr); let ty = cx.typeck_results().expr_ty(start); - if let ty::Int(_) | ty::Uint(_) = ty.kind; + if let ty::Int(_) | ty::Uint(_) = ty.kind(); if let Some((start_idx, _)) = constant(cx, cx.typeck_results(), start); if let Some((end_idx, _)) = constant(cx, cx.typeck_results(), end); if let Some(ordering) = Constant::partial_cmp(cx.tcx, ty, &start_idx, &end_idx); diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 7932be0d4b1f..4773731e3272 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -124,7 +124,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone { continue; } - if let ty::Adt(ref def, _) = arg_ty.kind { + if let ty::Adt(ref def, _) = arg_ty.kind() { if match_def_path(cx, def.did, &paths::MEM_MANUALLY_DROP) { continue; } @@ -287,7 +287,7 @@ fn is_call_with_ref_arg<'tcx>( if let mir::TerminatorKind::Call { func, args, destination, .. } = kind; if args.len() == 1; if let mir::Operand::Move(mir::Place { local, .. }) = &args[0]; - if let ty::FnDef(def_id, _) = func.ty(&*mir, cx.tcx).kind; + if let ty::FnDef(def_id, _) = *func.ty(&*mir, cx.tcx).kind(); if let (inner_ty, 1) = walk_ptrs_ty_depth(args[0].ty(&*mir, cx.tcx)); if !is_copy(cx, inner_ty); then { diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 2610157763a8..087d50c90e67 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -165,7 +165,7 @@ fn check_local<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>, bindings: & fn is_binding(cx: &LateContext<'_>, pat_id: HirId) -> bool { let var_ty = cx.typeck_results().node_type_opt(pat_id); - var_ty.map_or(false, |var_ty| !matches!(var_ty.kind, ty::Adt(..))) + var_ty.map_or(false, |var_ty| !matches!(var_ty.kind(), ty::Adt(..))) } fn check_pat<'tcx>( diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index cc39f060fc7f..47a73ca9a24c 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -196,8 +196,8 @@ fn check_for_slice<'a>(cx: &LateContext<'_>, lhs1: &'a Expr<'_>, lhs2: &'a Expr< if eq_expr_value(cx, lhs1, lhs2) { let ty = walk_ptrs_ty(cx.typeck_results().expr_ty(lhs1)); - if matches!(ty.kind, ty::Slice(_)) - || matches!(ty.kind, ty::Array(_, _)) + if matches!(ty.kind(), ty::Slice(_)) + || matches!(ty.kind(), ty::Array(_, _)) || is_type_diagnostic_item(cx, ty, sym!(vec_type)) || is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) { diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs index 6750452941f2..eeda39bfa208 100644 --- a/clippy_lints/src/to_digit_is_some.rs +++ b/clippy_lints/src/to_digit_is_some.rs @@ -44,7 +44,7 @@ impl<'tcx> LateLintPass<'tcx> for ToDigitIsSome { if let [char_arg, radix_arg] = &**to_digit_args; if to_digits_path.ident.name.as_str() == "to_digit"; let char_arg_ty = cx.typeck_results().expr_ty_adjusted(char_arg); - if char_arg_ty.kind == ty::Char; + if *char_arg_ty.kind() == ty::Char; then { Some((true, char_arg, radix_arg)) } else { diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 50d9c93f9d40..87c5408c7858 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -338,7 +338,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { let from_ty = cx.typeck_results().expr_ty(&args[0]); let to_ty = cx.typeck_results().expr_ty(e); - match (&from_ty.kind, &to_ty.kind) { + match (&from_ty.kind(), &to_ty.kind()) { _ if from_ty == to_ty => span_lint( cx, USELESS_TRANSMUTE, @@ -446,7 +446,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { &format!("transmute from a `{}` to a `char`", from_ty), |diag| { let arg = sugg::Sugg::hir(cx, &args[0], ".."); - let arg = if let ty::Int(_) = from_ty.kind { + let arg = if let ty::Int(_) = from_ty.kind() { arg.as_ty(ast::UintTy::U32.name_str()) } else { arg @@ -462,8 +462,8 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { }, (ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) => { if_chain! { - if let (&ty::Slice(slice_ty), &ty::Str) = (&ty_from.kind, &ty_to.kind); - if let ty::Uint(ast::UintTy::U8) = slice_ty.kind; + if let (&ty::Slice(slice_ty), &ty::Str) = (&ty_from.kind(), &ty_to.kind()); + if let ty::Uint(ast::UintTy::U8) = slice_ty.kind(); if from_mutbl == to_mutbl; then { let postfix = if *from_mutbl == Mutability::Mut { @@ -555,7 +555,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { &format!("transmute from a `{}` to a `{}`", from_ty, to_ty), |diag| { let arg = sugg::Sugg::hir(cx, &args[0], ".."); - let arg = if let ty::Int(int_ty) = from_ty.kind { + let arg = if let ty::Int(int_ty) = from_ty.kind() { arg.as_ty(format!( "u{}", int_ty.bit_width().map_or_else(|| "size".to_string(), |v| v.to_string()) @@ -601,7 +601,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { arg = sugg::Sugg::NonParen(format!("{}.to_bits()", arg.maybe_par()).into()); // cast the result of `to_bits` if `to_ty` is signed - arg = if let ty::Int(int_ty) = to_ty.kind { + arg = if let ty::Int(int_ty) = to_ty.kind() { arg.as_ty(int_ty.name_str().to_string()) } else { arg diff --git a/clippy_lints/src/trivially_copy_pass_by_ref.rs b/clippy_lints/src/trivially_copy_pass_by_ref.rs index 92f42168a1ea..1f06d2dbe914 100644 --- a/clippy_lints/src/trivially_copy_pass_by_ref.rs +++ b/clippy_lints/src/trivially_copy_pass_by_ref.rs @@ -83,7 +83,7 @@ impl<'tcx> TriviallyCopyPassByRef { // Use lifetimes to determine if we're returning a reference to the // argument. In that case we can't switch to pass-by-value as the // argument will not live long enough. - let output_lts = match fn_sig.output().kind { + let output_lts = match *fn_sig.output().kind() { ty::Ref(output_lt, _, _) => vec![output_lt], ty::Adt(_, substs) => substs.regions().collect(), _ => vec![], @@ -97,7 +97,7 @@ impl<'tcx> TriviallyCopyPassByRef { } if_chain! { - if let ty::Ref(input_lt, ty, Mutability::Not) = ty.kind; + if let ty::Ref(input_lt, ty, Mutability::Not) = ty.kind(); if !output_lts.contains(&input_lt); if is_copy(cx, ty); if let Some(size) = cx.layout_of(ty).ok().map(|l| l.size.bytes()); diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs index a4676e505b6f..3e747ec4ad9e 100644 --- a/clippy_lints/src/try_err.rs +++ b/clippy_lints/src/try_err.rs @@ -132,7 +132,7 @@ fn find_return_type<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx ExprKind<'_>) -> O /// Extracts the error type from Result. fn result_error_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option> { if_chain! { - if let ty::Adt(_, subst) = ty.kind; + if let ty::Adt(_, subst) = ty.kind(); if is_type_diagnostic_item(cx, ty, sym!(result_type)); let err_ty = subst.type_at(1); then { @@ -146,11 +146,11 @@ fn result_error_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option>. fn poll_result_error_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option> { if_chain! { - if let ty::Adt(def, subst) = ty.kind; + if let ty::Adt(def, subst) = ty.kind(); if match_def_path(cx, def.did, &paths::POLL); let ready_ty = subst.type_at(0); - if let ty::Adt(ready_def, ready_subst) = ready_ty.kind; + if let ty::Adt(ready_def, ready_subst) = ready_ty.kind(); if cx.tcx.is_diagnostic_item(sym!(result_type), ready_def.did); let err_ty = ready_subst.type_at(1); @@ -165,15 +165,15 @@ fn poll_result_error_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option< /// Extracts the error type from Poll>>. fn poll_option_result_error_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option> { if_chain! { - if let ty::Adt(def, subst) = ty.kind; + if let ty::Adt(def, subst) = ty.kind(); if match_def_path(cx, def.did, &paths::POLL); let ready_ty = subst.type_at(0); - if let ty::Adt(ready_def, ready_subst) = ready_ty.kind; + if let ty::Adt(ready_def, ready_subst) = ready_ty.kind(); if cx.tcx.is_diagnostic_item(sym!(option_type), ready_def.did); let some_ty = ready_subst.type_at(0); - if let ty::Adt(some_def, some_subst) = some_ty.kind; + if let ty::Adt(some_def, some_subst) = some_ty.kind(); if cx.tcx.is_diagnostic_item(sym!(result_type), some_def.did); let err_ty = some_subst.type_at(1); diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 7e9190bef5e7..c82deaa43b26 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -907,7 +907,7 @@ fn is_questionmark_desugar_marked_call(expr: &Expr<'_>) -> bool { } fn is_unit(ty: Ty<'_>) -> bool { - matches!(ty.kind, ty::Tuple(slice) if slice.is_empty()) + matches!(ty.kind(), ty::Tuple(slice) if slice.is_empty()) } fn is_unit_literal(expr: &Expr<'_>) -> bool { @@ -1134,7 +1134,7 @@ declare_clippy_lint! { /// Returns the size in bits of an integral type. /// Will return 0 if the type is not an int or uint variant fn int_ty_to_nbits(typ: Ty<'_>, tcx: TyCtxt<'_>) -> u64 { - match typ.kind { + match typ.kind() { ty::Int(i) => match i { IntTy::Isize => tcx.data_layout.pointer_size.bits(), IntTy::I8 => 8, @@ -1156,7 +1156,7 @@ fn int_ty_to_nbits(typ: Ty<'_>, tcx: TyCtxt<'_>) -> u64 { } fn is_isize_or_usize(typ: Ty<'_>) -> bool { - matches!(typ.kind, ty::Int(IntTy::Isize) | ty::Uint(UintTy::Usize)) + matches!(typ.kind(), ty::Int(IntTy::Isize) | ty::Uint(UintTy::Usize)) } fn span_precision_loss_lint(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to_f64: bool) { @@ -1248,7 +1248,7 @@ fn check_loss_of_sign(cx: &LateContext<'_>, expr: &Expr<'_>, op: &Expr<'_>, cast if_chain! { if let Some((const_val, _)) = const_val; if let Constant::Int(n) = const_val; - if let ty::Int(ity) = cast_from.kind; + if let ty::Int(ity) = *cast_from.kind(); if sext(cx.tcx, n, ity) >= 0; then { return @@ -1381,7 +1381,7 @@ declare_lint_pass!(Casts => [ // Check if the given type is either `core::ffi::c_void` or // one of the platform specific `libc::::c_void` of libc. fn is_c_void(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { - if let ty::Adt(adt, _) = ty.kind { + if let ty::Adt(adt, _) = ty.kind() { let names = cx.get_def_path(adt.did); if names.is_empty() { @@ -1397,7 +1397,7 @@ fn is_c_void(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { /// Returns the mantissa bits wide of a fp type. /// Will return 0 if the type is not a fp fn fp_ty_mantissa_nbits(typ: Ty<'_>) -> u32 { - match typ.kind { + match typ.kind() { ty::Float(FloatTy::F32) => 23, ty::Float(FloatTy::F64) | ty::Infer(InferTy::FloatVar(_)) => 52, _ => 0, @@ -1437,7 +1437,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts { match lit.node { LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::Float(_, LitFloatType::Unsuffixed) => {}, _ => { - if cast_from.kind == cast_to.kind && !in_external_macro(cx.sess(), expr.span) { + if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) { span_lint( cx, UNNECESSARY_CAST, @@ -1470,7 +1470,7 @@ fn lint_numeric_casts<'tcx>( match (cast_from.is_integral(), cast_to.is_integral()) { (true, false) => { let from_nbits = int_ty_to_nbits(cast_from, cx.tcx); - let to_nbits = if let ty::Float(FloatTy::F32) = cast_to.kind { + let to_nbits = if let ty::Float(FloatTy::F32) = cast_to.kind() { 32 } else { 64 @@ -1507,7 +1507,7 @@ fn lint_numeric_casts<'tcx>( check_lossless(cx, expr, cast_expr, cast_from, cast_to); }, (false, false) => { - if let (&ty::Float(FloatTy::F64), &ty::Float(FloatTy::F32)) = (&cast_from.kind, &cast_to.kind) { + if let (&ty::Float(FloatTy::F64), &ty::Float(FloatTy::F32)) = (&cast_from.kind(), &cast_to.kind()) { span_lint( cx, CAST_POSSIBLE_TRUNCATION, @@ -1515,7 +1515,7 @@ fn lint_numeric_casts<'tcx>( "casting `f64` to `f32` may truncate the value", ); } - if let (&ty::Float(FloatTy::F32), &ty::Float(FloatTy::F64)) = (&cast_from.kind, &cast_to.kind) { + if let (&ty::Float(FloatTy::F32), &ty::Float(FloatTy::F64)) = (&cast_from.kind(), &cast_to.kind()) { span_lossless_lint(cx, expr, cast_expr, cast_from, cast_to); } }, @@ -1524,8 +1524,8 @@ fn lint_numeric_casts<'tcx>( fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>) { if_chain! { - if let ty::RawPtr(from_ptr_ty) = &cast_from.kind; - if let ty::RawPtr(to_ptr_ty) = &cast_to.kind; + if let ty::RawPtr(from_ptr_ty) = &cast_from.kind(); + if let ty::RawPtr(to_ptr_ty) = &cast_to.kind(); if let Ok(from_layout) = cx.layout_of(from_ptr_ty.ty); if let Ok(to_layout) = cx.layout_of(to_ptr_ty.ty); if from_layout.align.abi < to_layout.align.abi; @@ -1558,11 +1558,11 @@ fn lint_fn_to_numeric_cast( cast_to: Ty<'_>, ) { // We only want to check casts to `ty::Uint` or `ty::Int` - match cast_to.kind { + match cast_to.kind() { ty::Uint(_) | ty::Int(..) => { /* continue on */ }, _ => return, } - match cast_from.kind { + match cast_from.kind() { ty::FnDef(..) | ty::FnPtr(_) => { let mut applicability = Applicability::MaybeIncorrect; let from_snippet = snippet_with_applicability(cx, cast_expr.span, "x", &mut applicability); @@ -1581,7 +1581,7 @@ fn lint_fn_to_numeric_cast( format!("{} as usize", from_snippet), applicability, ); - } else if cast_to.kind != ty::Uint(UintTy::Usize) { + } else if *cast_to.kind() != ty::Uint(UintTy::Usize) { span_lint_and_sugg( cx, FN_TO_NUMERIC_CAST, @@ -1798,7 +1798,7 @@ impl<'tcx> LateLintPass<'tcx> for CharLitAsU8 { if let ExprKind::Cast(e, _) = &expr.kind; if let ExprKind::Lit(l) = &e.kind; if let LitKind::Char(c) = l.node; - if ty::Uint(UintTy::U8) == cx.typeck_results().expr_ty(expr).kind; + if ty::Uint(UintTy::U8) == *cx.typeck_results().expr_ty(expr).kind(); then { let mut applicability = Applicability::MachineApplicable; let snippet = snippet_with_applicability(cx, e.span, "'x'", &mut applicability); @@ -1937,7 +1937,7 @@ fn detect_extreme_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Op let cv = constant(cx, cx.typeck_results(), expr)?.0; - let which = match (&ty.kind, cv) { + let which = match (ty.kind(), cv) { (&ty::Bool, Constant::Bool(false)) | (&ty::Uint(_), Constant::Int(0)) => Minimum, (&ty::Int(ity), Constant::Int(i)) if i == unsext(cx.tcx, i128::MIN >> (128 - int_bits(cx.tcx, ity)), ity) => { Minimum @@ -2071,7 +2071,7 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_>, expr: &'a Expr<'_>) -> if cx.layout_of(pre_cast_ty).ok().map(|l| l.size) == cx.layout_of(cast_ty).ok().map(|l| l.size) { return None; } - match pre_cast_ty.kind { + match pre_cast_ty.kind() { ty::Int(int_ty) => Some(match int_ty { IntTy::I8 => (FullInt::S(i128::from(i8::MIN)), FullInt::S(i128::from(i8::MAX))), IntTy::I16 => (FullInt::S(i128::from(i16::MIN)), FullInt::S(i128::from(i16::MAX))), @@ -2098,7 +2098,7 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_>, expr: &'a Expr<'_>) -> fn node_as_const_fullint<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option { let val = constant(cx, cx.typeck_results(), expr)?.0; if let Constant::Int(const_int) = val { - match cx.typeck_results().expr_ty(expr).kind { + match *cx.typeck_results().expr_ty(expr).kind() { ty::Int(ity) => Some(FullInt::S(sext(cx.tcx, const_int, ity))), ty::Uint(_) => Some(FullInt::U(const_int)), _ => None, @@ -2601,7 +2601,7 @@ impl<'tcx> LateLintPass<'tcx> for RefToMut { if let TyKind::Ptr(MutTy { mutbl: Mutability::Mut, .. }) = t.kind; if let ExprKind::Cast(e, t) = &e.kind; if let TyKind::Ptr(MutTy { mutbl: Mutability::Not, .. }) = t.kind; - if let ty::Ref(..) = cx.typeck_results().node_type(e.hir_id).kind; + if let ty::Ref(..) = cx.typeck_results().node_type(e.hir_id).kind(); then { span_lint( cx, diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 679aaec9fcd6..0d5a5017331b 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -110,7 +110,7 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Span, Option)> { if_chain! { if let ExprKind::Closure(_, _fn_decl, body_id, span, _) = arg.kind; - if let ty::Closure(_def_id, substs) = &cx.typeck_results().node_type(arg.hir_id).kind; + if let ty::Closure(_def_id, substs) = &cx.typeck_results().node_type(arg.hir_id).kind(); let ret_ty = substs.as_closure().sig().output(); let ty = cx.tcx.erase_late_bound_regions(&ret_ty); if ty.is_unit(); diff --git a/clippy_lints/src/unnamed_address.rs b/clippy_lints/src/unnamed_address.rs index 28b393b9f11f..9582c162e77b 100644 --- a/clippy_lints/src/unnamed_address.rs +++ b/clippy_lints/src/unnamed_address.rs @@ -65,14 +65,14 @@ impl LateLintPass<'_> for UnnamedAddress { } fn is_trait_ptr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - match cx.typeck_results().expr_ty_adjusted(expr).kind { + match cx.typeck_results().expr_ty_adjusted(expr).kind() { ty::RawPtr(ty::TypeAndMut { ty, .. }) => ty.is_trait(), _ => false, } } fn is_fn_def(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - matches!(cx.typeck_results().expr_ty(expr).kind, ty::FnDef(..)) + matches!(cx.typeck_results().expr_ty(expr).kind(), ty::FnDef(..)) } if_chain! { diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index 59993d25bb47..8b00d29acb52 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -230,7 +230,7 @@ fn key_returns_borrow(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { if let Some(def_id) = utils::fn_def_id(cx, expr) { let output = cx.tcx.fn_sig(def_id).output(); let ty = output.skip_binder(); - return matches!(ty.kind, ty::Ref(..)) + return matches!(ty.kind(), ty::Ref(..)) || ty.walk().any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_))); } diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 4ab2b5e796de..615440e15f38 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -107,7 +107,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { let a = cx.typeck_results().expr_ty(e); let b = cx.typeck_results().expr_ty(&args[0]); if is_type_diagnostic_item(cx, a, sym!(result_type)); - if let ty::Adt(_, substs) = a.kind; + if let ty::Adt(_, substs) = a.kind(); if let Some(a_type) = substs.types().next(); if TyS::same_type(a_type, b); @@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { if_chain! { if match_def_path(cx, def_id, &paths::TRY_FROM); if is_type_diagnostic_item(cx, a, sym!(result_type)); - if let ty::Adt(_, substs) = a.kind; + if let ty::Adt(_, substs) = a.kind(); if let Some(a_type) = substs.types().next(); if TyS::same_type(a_type, b); diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 820052571156..45add9ab284d 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -129,7 +129,7 @@ pub fn is_wild<'tcx>(pat: &impl std::ops::Deref>) -> bool { /// Checks if type is struct, enum or union type with the given def path. pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool { - match ty.kind { + match ty.kind() { ty::Adt(adt, _) => match_def_path(cx, adt.did, path), _ => false, } @@ -137,7 +137,7 @@ pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool { /// Checks if the type is equal to a diagnostic item pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symbol) -> bool { - match ty.kind { + match ty.kind() { ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(diag_item, adt.did), _ => false, } @@ -145,7 +145,7 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symb /// Checks if the type is equal to a lang item pub fn is_type_lang_item(cx: &LateContext<'_>, ty: Ty<'_>, lang_item: hir::LangItem) -> bool { - match ty.kind { + match ty.kind() { ty::Adt(adt, _) => cx.tcx.lang_items().require(lang_item).unwrap() == adt.did, _ => false, } @@ -754,7 +754,7 @@ pub fn walk_ptrs_hir_ty<'tcx>(ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> { /// Returns the base type for references and raw pointers. pub fn walk_ptrs_ty(ty: Ty<'_>) -> Ty<'_> { - match ty.kind { + match ty.kind() { ty::Ref(_, ty, _) => walk_ptrs_ty(ty), _ => ty, } @@ -764,7 +764,7 @@ pub fn walk_ptrs_ty(ty: Ty<'_>) -> Ty<'_> { /// depth. pub fn walk_ptrs_ty_depth(ty: Ty<'_>) -> (Ty<'_>, usize) { fn inner(ty: Ty<'_>, depth: usize) -> (Ty<'_>, usize) { - match ty.kind { + match ty.kind() { ty::Ref(_, ty, _) => inner(ty, depth + 1), _ => (ty, depth), } @@ -877,7 +877,7 @@ pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool { /// Returns `true` if the given type is an `unsafe` function. pub fn type_is_unsafe_function<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { - match ty.kind { + match ty.kind() { ty::FnDef(..) | ty::FnPtr(_) => ty.fn_sig(cx.tcx).unsafety() == Unsafety::Unsafe, _ => false, } @@ -942,7 +942,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, pats.iter().map(|pat| &**pat)) }, PatKind::Slice(ref head, ref middle, ref tail) => { - match &cx.typeck_results().node_type(pat.hir_id).kind { + match &cx.typeck_results().node_type(pat.hir_id).kind() { ty::Slice(..) => { // [..] is the only irrefutable slice pattern. !head.is_empty() || middle.is_none() || !tail.is_empty() @@ -1156,12 +1156,12 @@ pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option< &paths::RECEIVER, ]; - let ty_to_check = match probably_ref_ty.kind { + let ty_to_check = match probably_ref_ty.kind() { ty::Ref(_, ty_to_check, _) => ty_to_check, _ => probably_ref_ty, }; - let def_id = match ty_to_check.kind { + let def_id = match ty_to_check.kind() { ty::Array(..) => return Some("array"), ty::Slice(..) => return Some("slice"), ty::Adt(adt, _) => adt.did, @@ -1277,7 +1277,7 @@ pub fn must_use_attr(attrs: &[Attribute]) -> Option<&Attribute> { // Returns whether the type has #[must_use] attribute pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { - match ty.kind { + match ty.kind() { ty::Adt(ref adt, _) => must_use_attr(&cx.tcx.get_attrs(adt.did)).is_some(), ty::Foreign(ref did) => must_use_attr(&cx.tcx.get_attrs(*did)).is_some(), ty::Slice(ref ty) @@ -1409,9 +1409,9 @@ pub fn run_lints(cx: &LateContext<'_>, lints: &[&'static Lint], id: HirId) -> bo /// Returns true iff the given type is a primitive (a bool or char, any integer or floating-point /// number type, a str, or an array, slice, or tuple of those types). pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool { - match ty.kind { + match ty.kind() { ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => true, - ty::Ref(_, inner, _) if inner.kind == ty::Str => true, + ty::Ref(_, inner, _) if *inner.kind() == ty::Str => true, ty::Array(inner_type, _) | ty::Slice(inner_type) => is_recursively_primitive_type(inner_type), ty::Tuple(inner_types) => inner_types.types().all(is_recursively_primitive_type), _ => false, @@ -1423,24 +1423,23 @@ pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool { /// `is_recursively_primitive_type` function) and None otherwise. pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { let expr_type = cx.typeck_results().expr_ty_adjusted(expr); - let expr_kind = &expr_type.kind; + let expr_kind = expr_type.kind(); let is_primitive = match expr_kind { - ty::Slice(ref element_type) - | ty::Ref( - _, - ty::TyS { - kind: ty::Slice(ref element_type), - .. - }, - _, - ) => is_recursively_primitive_type(element_type), + ty::Slice(element_type) => is_recursively_primitive_type(element_type), + ty::Ref(_, inner_ty, _) if matches!(inner_ty.kind(), &ty::Slice(_)) => { + if let ty::Slice(element_type) = inner_ty.kind() { + is_recursively_primitive_type(element_type) + } else { + unreachable!() + } + } _ => false, }; if is_primitive { // if we have wrappers like Array, Slice or Tuple, print these // and get the type enclosed in the slice ref - match expr_type.peel_refs().walk().nth(1).unwrap().expect_ty().kind { + match expr_type.peel_refs().walk().nth(1).unwrap().expect_ty().kind() { ty::Slice(..) => return Some("slice".into()), ty::Array(..) => return Some("array".into()), ty::Tuple(..) => return Some("tuple".into()), diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index 84e907d7125d..149cceb39dd9 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -44,8 +44,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { // search for `&vec![_]` expressions where the adjusted type is `&[_]` if_chain! { - if let ty::Ref(_, ty, _) = cx.typeck_results().expr_ty_adjusted(expr).kind; - if let ty::Slice(..) = ty.kind; + if let ty::Ref(_, ty, _) = cx.typeck_results().expr_ty_adjusted(expr).kind(); + if let ty::Slice(..) = ty.kind(); if let ExprKind::AddrOf(BorrowKind::Ref, _, ref addressee) = expr.kind; if let Some(vec_args) = higher::vec_macro(cx, addressee); then { @@ -127,7 +127,7 @@ fn size_of(cx: &LateContext<'_>, expr: &Expr<'_>) -> u64 { /// Returns the item type of the vector (i.e., the `T` in `Vec`). fn vec_type(ty: Ty<'_>) -> Ty<'_> { - if let ty::Adt(_, substs) = ty.kind { + if let ty::Adt(_, substs) = ty.kind() { substs.type_at(0) } else { panic!("The type of `vec!` is a not a struct?"); From 1537485d50dc33f72a7716965a0e8c9a6f165768 Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Thu, 6 Aug 2020 17:49:46 +0200 Subject: [PATCH 0084/1222] ty.flags -> ty.flags() --- clippy_lints/src/non_copy_const.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index f1df634701dd..73eabd4207e7 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -128,7 +128,7 @@ fn verify_ty_bound<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, source: Source) { diag.span_label(const_kw_span, "make this a static item (maybe with lazy_static)"); }, Source::Assoc { ty: ty_span, .. } => { - if ty.flags.intersects(TypeFlags::HAS_FREE_LOCAL_NAMES) { + if ty.flags().intersects(TypeFlags::HAS_FREE_LOCAL_NAMES) { diag.span_label(ty_span, &format!("consider requiring `{}` to be `Copy`", ty)); } }, From c810e95b6257b9aff96ebba9fefc2ae6a8430a9e Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 8 Sep 2020 17:59:43 -0400 Subject: [PATCH 0085/1222] Adjust Clippy for CONST_ITEM_MUTATION lint We no longer lint assignments to const item fields in the `temporary_assignment` lint, since this is now covered by the `CONST_ITEM_MUTATION` lint. Additionally, we `#![allow(const_item_mutation)]` in the `borrow_interior_mutable_const.rs` test. Clippy UI tests are run with `-D warnings`, which seems to cause builtin lints to prevent Clippy lints from running. --- clippy_lints/src/temporary_assignment.rs | 4 +-- tests/ui/borrow_interior_mutable_const.rs | 1 + tests/ui/borrow_interior_mutable_const.stderr | 32 ++++++++--------- tests/ui/temporary_assignment.rs | 1 + tests/ui/temporary_assignment.stderr | 34 +++---------------- 5 files changed, 24 insertions(+), 48 deletions(-) diff --git a/clippy_lints/src/temporary_assignment.rs b/clippy_lints/src/temporary_assignment.rs index 1aeff1baa362..2b6ddadd4c11 100644 --- a/clippy_lints/src/temporary_assignment.rs +++ b/clippy_lints/src/temporary_assignment.rs @@ -1,5 +1,4 @@ use crate::utils::{is_adjusted, span_lint}; -use rustc_hir::def::{DefKind, Res}; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -22,10 +21,9 @@ declare_clippy_lint! { "assignments to temporaries" } -fn is_temporary(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { +fn is_temporary(_cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { match &expr.kind { ExprKind::Struct(..) | ExprKind::Tup(..) => true, - ExprKind::Path(qpath) => matches!(cx.qpath_res(qpath, expr.hir_id), Res::Def(DefKind::Const, ..)), _ => false, } } diff --git a/tests/ui/borrow_interior_mutable_const.rs b/tests/ui/borrow_interior_mutable_const.rs index a414832bcd36..39f875105485 100644 --- a/tests/ui/borrow_interior_mutable_const.rs +++ b/tests/ui/borrow_interior_mutable_const.rs @@ -1,5 +1,6 @@ #![warn(clippy::borrow_interior_mutable_const)] #![allow(clippy::declare_interior_mutable_const, clippy::ref_in_deref)] +#![allow(const_item_mutation)] use std::borrow::Cow; use std::cell::{Cell, UnsafeCell}; diff --git a/tests/ui/borrow_interior_mutable_const.stderr b/tests/ui/borrow_interior_mutable_const.stderr index 1e0b3e4d20a5..5800af7e960f 100644 --- a/tests/ui/borrow_interior_mutable_const.stderr +++ b/tests/ui/borrow_interior_mutable_const.stderr @@ -1,5 +1,5 @@ error: a `const` item with interior mutability should not be borrowed - --> $DIR/borrow_interior_mutable_const.rs:65:5 + --> $DIR/borrow_interior_mutable_const.rs:66:5 | LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability | ^^^^^^ @@ -8,7 +8,7 @@ LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> $DIR/borrow_interior_mutable_const.rs:66:16 + --> $DIR/borrow_interior_mutable_const.rs:67:16 | LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutability | ^^^^^^ @@ -16,7 +16,7 @@ LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutabi = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> $DIR/borrow_interior_mutable_const.rs:69:22 + --> $DIR/borrow_interior_mutable_const.rs:70:22 | LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability | ^^^^^^^^^ @@ -24,7 +24,7 @@ LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> $DIR/borrow_interior_mutable_const.rs:70:25 + --> $DIR/borrow_interior_mutable_const.rs:71:25 | LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability | ^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> $DIR/borrow_interior_mutable_const.rs:71:27 + --> $DIR/borrow_interior_mutable_const.rs:72:27 | LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability | ^^^^^^^^^ @@ -40,7 +40,7 @@ LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> $DIR/borrow_interior_mutable_const.rs:72:26 + --> $DIR/borrow_interior_mutable_const.rs:73:26 | LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability | ^^^^^^^^^ @@ -48,7 +48,7 @@ LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> $DIR/borrow_interior_mutable_const.rs:83:14 + --> $DIR/borrow_interior_mutable_const.rs:84:14 | LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability | ^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> $DIR/borrow_interior_mutable_const.rs:84:14 + --> $DIR/borrow_interior_mutable_const.rs:85:14 | LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability | ^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> $DIR/borrow_interior_mutable_const.rs:85:19 + --> $DIR/borrow_interior_mutable_const.rs:86:19 | LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability | ^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> $DIR/borrow_interior_mutable_const.rs:86:14 + --> $DIR/borrow_interior_mutable_const.rs:87:14 | LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability | ^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> $DIR/borrow_interior_mutable_const.rs:87:13 + --> $DIR/borrow_interior_mutable_const.rs:88:13 | LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mutability | ^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mu = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> $DIR/borrow_interior_mutable_const.rs:93:13 + --> $DIR/borrow_interior_mutable_const.rs:94:13 | LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability | ^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> $DIR/borrow_interior_mutable_const.rs:98:5 + --> $DIR/borrow_interior_mutable_const.rs:99:5 | LL | CELL.set(2); //~ ERROR interior mutability | ^^^^ @@ -104,7 +104,7 @@ LL | CELL.set(2); //~ ERROR interior mutability = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> $DIR/borrow_interior_mutable_const.rs:99:16 + --> $DIR/borrow_interior_mutable_const.rs:100:16 | LL | assert_eq!(CELL.get(), 6); //~ ERROR interior mutability | ^^^^ @@ -112,7 +112,7 @@ LL | assert_eq!(CELL.get(), 6); //~ ERROR interior mutability = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> $DIR/borrow_interior_mutable_const.rs:112:5 + --> $DIR/borrow_interior_mutable_const.rs:113:5 | LL | u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability | ^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL | u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> $DIR/borrow_interior_mutable_const.rs:113:16 + --> $DIR/borrow_interior_mutable_const.rs:114:16 | LL | assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR interior mutability | ^^^^^^^^^^^ diff --git a/tests/ui/temporary_assignment.rs b/tests/ui/temporary_assignment.rs index c6c315d5fab5..d6f56d40c5d4 100644 --- a/tests/ui/temporary_assignment.rs +++ b/tests/ui/temporary_assignment.rs @@ -1,4 +1,5 @@ #![warn(clippy::temporary_assignment)] +#![allow(const_item_mutation)] use std::ops::{Deref, DerefMut}; diff --git a/tests/ui/temporary_assignment.stderr b/tests/ui/temporary_assignment.stderr index 4efe2d4bb671..4cc32c79f05c 100644 --- a/tests/ui/temporary_assignment.stderr +++ b/tests/ui/temporary_assignment.stderr @@ -1,5 +1,5 @@ error: assignment to temporary - --> $DIR/temporary_assignment.rs:47:5 + --> $DIR/temporary_assignment.rs:48:5 | LL | Struct { field: 0 }.field = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | Struct { field: 0 }.field = 1; = note: `-D clippy::temporary-assignment` implied by `-D warnings` error: assignment to temporary - --> $DIR/temporary_assignment.rs:48:5 + --> $DIR/temporary_assignment.rs:49:5 | LL | / MultiStruct { LL | | structure: Struct { field: 0 }, @@ -17,40 +17,16 @@ LL | | .field = 1; | |______________^ error: assignment to temporary - --> $DIR/temporary_assignment.rs:53:5 + --> $DIR/temporary_assignment.rs:54:5 | LL | ArrayStruct { array: [0] }.array[0] = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: assignment to temporary - --> $DIR/temporary_assignment.rs:54:5 + --> $DIR/temporary_assignment.rs:55:5 | LL | (0, 0).0 = 1; | ^^^^^^^^^^^^ -error: assignment to temporary - --> $DIR/temporary_assignment.rs:56:5 - | -LL | A.0 = 2; - | ^^^^^^^ - -error: assignment to temporary - --> $DIR/temporary_assignment.rs:57:5 - | -LL | B.field = 2; - | ^^^^^^^^^^^ - -error: assignment to temporary - --> $DIR/temporary_assignment.rs:58:5 - | -LL | C.structure.field = 2; - | ^^^^^^^^^^^^^^^^^^^^^ - -error: assignment to temporary - --> $DIR/temporary_assignment.rs:59:5 - | -LL | D.array[0] = 2; - | ^^^^^^^^^^^^^^ - -error: aborting due to 8 previous errors +error: aborting due to 4 previous errors From b6f7d9f0543728340613f9dcb68042fbf61208cc Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Fri, 21 Aug 2020 22:11:41 -0400 Subject: [PATCH 0086/1222] Fully integrate token collection for additional AST structs This commit contains miscellaneous changes that don't fit into any of the other commits in this PR --- clippy_lints/src/enum_variants.rs | 4 ++-- clippy_lints/src/manual_non_exhaustive.rs | 4 ++-- clippy_lints/src/single_component_path_imports.rs | 2 +- clippy_lints/src/utils/ast_utils.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index a9294a87f15d..67a463538568 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -285,7 +285,7 @@ impl EarlyLintPass for EnumVariantNames { ); } } - if item.vis.node.is_pub() { + if item.vis.kind.is_pub() { let matching = partial_match(mod_camel, &item_camel); let rmatching = partial_rmatch(mod_camel, &item_camel); let nchars = mod_camel.chars().count(); @@ -316,7 +316,7 @@ impl EarlyLintPass for EnumVariantNames { } } if let ItemKind::Enum(ref def, _) = item.kind { - let lint = match item.vis.node { + let lint = match item.vis.kind { VisibilityKind::Public => PUB_ENUM_VARIANT_NAMES, _ => ENUM_VARIANT_NAMES, }; diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 4e49bdbdd21b..9c623821fddd 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -122,7 +122,7 @@ fn check_manual_non_exhaustive_enum(cx: &EarlyContext<'_>, item: &Item, variants fn check_manual_non_exhaustive_struct(cx: &EarlyContext<'_>, item: &Item, data: &VariantData) { fn is_private(field: &StructField) -> bool { - matches!(field.vis.node, VisibilityKind::Inherited) + matches!(field.vis.kind, VisibilityKind::Inherited) } fn is_non_exhaustive_marker(field: &StructField) -> bool { @@ -141,7 +141,7 @@ fn check_manual_non_exhaustive_struct(cx: &EarlyContext<'_>, item: &Item, data: let fields = data.fields(); let private_fields = fields.iter().filter(|f| is_private(f)).count(); - let public_fields = fields.iter().filter(|f| f.vis.node.is_pub()).count(); + let public_fields = fields.iter().filter(|f| f.vis.kind.is_pub()).count(); if_chain! { if private_fields == 1 && public_fields >= 1 && public_fields == fields.len() - 1; diff --git a/clippy_lints/src/single_component_path_imports.rs b/clippy_lints/src/single_component_path_imports.rs index 58bfd0bc553f..35b38eca14d1 100644 --- a/clippy_lints/src/single_component_path_imports.rs +++ b/clippy_lints/src/single_component_path_imports.rs @@ -41,7 +41,7 @@ impl EarlyLintPass for SingleComponentPathImports { if_chain! { if !in_macro(item.span); if cx.sess.opts.edition == Edition::Edition2018; - if !item.vis.node.is_pub(); + if !item.vis.kind.is_pub(); if let ItemKind::Use(use_tree) = &item.kind; if let segments = &use_tree.prefix.segments; if segments.len() == 1; diff --git a/clippy_lints/src/utils/ast_utils.rs b/clippy_lints/src/utils/ast_utils.rs index 3c3f8b26e3ac..4f0474c62cb6 100644 --- a/clippy_lints/src/utils/ast_utils.rs +++ b/clippy_lints/src/utils/ast_utils.rs @@ -392,7 +392,7 @@ pub fn eq_defaultness(l: Defaultness, r: Defaultness) -> bool { pub fn eq_vis(l: &Visibility, r: &Visibility) -> bool { use VisibilityKind::*; - match (&l.node, &r.node) { + match (&l.kind, &r.kind) { (Public, Public) | (Inherited, Inherited) | (Crate(_), Crate(_)) => true, (Restricted { path: l, .. }, Restricted { path: r, .. }) => eq_path(l, r), _ => false, From cc460b715890f0af4b53fd4a596271a338dc7a3d Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Mon, 14 Sep 2020 17:13:47 -0700 Subject: [PATCH 0087/1222] Add pass names to some common dataflow analyses --- clippy_lints/src/redundant_clone.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 57a45e628db6..1615f1923709 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -87,6 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone { let maybe_storage_live_result = MaybeStorageLive .into_engine(cx.tcx, mir, def_id.to_def_id()) + .pass_name("redundant_clone") .iterate_to_fixpoint() .into_results_cursor(mir); let mut possible_borrower = { From ea6a1ad666e379a7809a191d04f13cbcf7ba4d56 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 15 Sep 2020 10:21:40 +0000 Subject: [PATCH 0088/1222] Fix clippy hard-code slice::Iter path --- clippy_lints/src/utils/paths.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index 65320d6a0e0b..3b031a552e5c 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -106,7 +106,7 @@ pub const RWLOCK_WRITE_GUARD: [&str; 4] = ["std", "sync", "rwlock", "RwLockWrite pub const SERDE_DESERIALIZE: [&str; 2] = ["_serde", "Deserialize"]; pub const SERDE_DE_VISITOR: [&str; 3] = ["serde", "de", "Visitor"]; pub const SLICE_INTO_VEC: [&str; 4] = ["alloc", "slice", "", "into_vec"]; -pub const SLICE_ITER: [&str; 3] = ["core", "slice", "Iter"]; +pub const SLICE_ITER: [&str; 4] = ["core", "slice", "iter", "Iter"]; pub const STDERR: [&str; 4] = ["std", "io", "stdio", "stderr"]; pub const STDOUT: [&str; 4] = ["std", "io", "stdio", "stdout"]; pub const STD_CONVERT_IDENTITY: [&str; 3] = ["std", "convert", "identity"]; From 5ca3fb0a6b2c26478e3cb000b069a46df61db082 Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Sun, 20 Sep 2020 03:32:36 +0200 Subject: [PATCH 0089/1222] Update Clippy testcases Update the test `redundant_pattern_matching`: check if `is_ok` and `is_err` are suggested within const contexts. Also removes the `redundant_pattern_matching_const_result` test, as it is no longer needed. --- tests/ui/redundant_pattern_matching.fixed | 35 +++++------ tests/ui/redundant_pattern_matching.rs | 41 +++++++------ tests/ui/redundant_pattern_matching.stderr | 60 ++++++++++++++++--- ...undant_pattern_matching_const_result.fixed | 44 -------------- ...redundant_pattern_matching_const_result.rs | 50 ---------------- ...ndant_pattern_matching_const_result.stderr | 46 -------------- 6 files changed, 93 insertions(+), 183 deletions(-) delete mode 100644 tests/ui/redundant_pattern_matching_const_result.fixed delete mode 100644 tests/ui/redundant_pattern_matching_const_result.rs delete mode 100644 tests/ui/redundant_pattern_matching_const_result.stderr diff --git a/tests/ui/redundant_pattern_matching.fixed b/tests/ui/redundant_pattern_matching.fixed index adbff8af8d9c..08bfe7c78d38 100644 --- a/tests/ui/redundant_pattern_matching.fixed +++ b/tests/ui/redundant_pattern_matching.fixed @@ -77,6 +77,7 @@ fn main() { issue5504(); issue5697(); + issue6067(); let _ = if gen_opt().is_some() { 1 @@ -131,31 +132,14 @@ fn issue5504() { // None of these should be linted because none of the suggested methods // are `const fn` without toggling a feature. const fn issue5697() { - if let Ok(_) = Ok::(42) {} - - if let Err(_) = Err::(42) {} - if let Some(_) = Some(42) {} if let None = None::<()> {} - while let Ok(_) = Ok::(10) {} - - while let Err(_) = Ok::(10) {} - while let Some(_) = Some(42) {} while let None = None::<()> {} - match Ok::(42) { - Ok(_) => true, - Err(_) => false, - }; - - match Err::(42) { - Ok(_) => false, - Err(_) => true, - }; match Some(42) { Some(_) => true, None => false, @@ -166,3 +150,20 @@ const fn issue5697() { None => true, }; } + +// Methods that are unstable const should not be suggested within a const context, see issue #5697. +// However, in Rust 1.48.0 the methods `is_ok` and `is_err` of `Result` were stabilized as const, +// so the following should be linted. +const fn issue6067() { + if Ok::(42).is_ok() {} + + if Err::(42).is_err() {} + + while Ok::(10).is_ok() {} + + while Ok::(10).is_err() {} + + Ok::(42).is_ok(); + + Err::(42).is_err(); +} diff --git a/tests/ui/redundant_pattern_matching.rs b/tests/ui/redundant_pattern_matching.rs index 4c2870e7803c..c0660c6ac394 100644 --- a/tests/ui/redundant_pattern_matching.rs +++ b/tests/ui/redundant_pattern_matching.rs @@ -98,6 +98,7 @@ fn main() { issue5504(); issue5697(); + issue6067(); let _ = if let Some(_) = gen_opt() { 1 @@ -152,31 +153,14 @@ fn issue5504() { // None of these should be linted because none of the suggested methods // are `const fn` without toggling a feature. const fn issue5697() { - if let Ok(_) = Ok::(42) {} - - if let Err(_) = Err::(42) {} - if let Some(_) = Some(42) {} if let None = None::<()> {} - while let Ok(_) = Ok::(10) {} - - while let Err(_) = Ok::(10) {} - while let Some(_) = Some(42) {} while let None = None::<()> {} - match Ok::(42) { - Ok(_) => true, - Err(_) => false, - }; - - match Err::(42) { - Ok(_) => false, - Err(_) => true, - }; match Some(42) { Some(_) => true, None => false, @@ -187,3 +171,26 @@ const fn issue5697() { None => true, }; } + +// Methods that are unstable const should not be suggested within a const context, see issue #5697. +// However, in Rust 1.48.0 the methods `is_ok` and `is_err` of `Result` were stabilized as const, +// so the following should be linted. +const fn issue6067() { + if let Ok(_) = Ok::(42) {} + + if let Err(_) = Err::(42) {} + + while let Ok(_) = Ok::(10) {} + + while let Err(_) = Ok::(10) {} + + match Ok::(42) { + Ok(_) => true, + Err(_) => false, + }; + + match Err::(42) { + Ok(_) => false, + Err(_) => true, + }; +} diff --git a/tests/ui/redundant_pattern_matching.stderr b/tests/ui/redundant_pattern_matching.stderr index d3c9ceaa3d7c..efd2f9903ec9 100644 --- a/tests/ui/redundant_pattern_matching.stderr +++ b/tests/ui/redundant_pattern_matching.stderr @@ -149,52 +149,94 @@ LL | let x = if let Some(_) = opt { true } else { false }; | -------^^^^^^^------ help: try this: `if opt.is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:102:20 + --> $DIR/redundant_pattern_matching.rs:103:20 | LL | let _ = if let Some(_) = gen_opt() { | -------^^^^^^^------------ help: try this: `if gen_opt().is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:104:19 + --> $DIR/redundant_pattern_matching.rs:105:19 | LL | } else if let None = gen_opt() { | -------^^^^------------ help: try this: `if gen_opt().is_none()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:106:19 + --> $DIR/redundant_pattern_matching.rs:107:19 | LL | } else if let Ok(_) = gen_res() { | -------^^^^^------------ help: try this: `if gen_res().is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:108:19 + --> $DIR/redundant_pattern_matching.rs:109:19 | LL | } else if let Err(_) = gen_res() { | -------^^^^^^------------ help: try this: `if gen_res().is_err()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:141:19 + --> $DIR/redundant_pattern_matching.rs:142:19 | LL | while let Some(_) = r#try!(result_opt()) {} | ----------^^^^^^^----------------------- help: try this: `while r#try!(result_opt()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:142:16 + --> $DIR/redundant_pattern_matching.rs:143:16 | LL | if let Some(_) = r#try!(result_opt()) {} | -------^^^^^^^----------------------- help: try this: `if r#try!(result_opt()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:148:12 + --> $DIR/redundant_pattern_matching.rs:149:12 | LL | if let Some(_) = m!() {} | -------^^^^^^^------- help: try this: `if m!().is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:149:15 + --> $DIR/redundant_pattern_matching.rs:150:15 | LL | while let Some(_) = m!() {} | ----------^^^^^^^------- help: try this: `while m!().is_some()` -error: aborting due to 29 previous errors +error: redundant pattern matching, consider using `is_ok()` + --> $DIR/redundant_pattern_matching.rs:179:12 + | +LL | if let Ok(_) = Ok::(42) {} + | -------^^^^^--------------------- help: try this: `if Ok::(42).is_ok()` + +error: redundant pattern matching, consider using `is_err()` + --> $DIR/redundant_pattern_matching.rs:181:12 + | +LL | if let Err(_) = Err::(42) {} + | -------^^^^^^---------------------- help: try this: `if Err::(42).is_err()` + +error: redundant pattern matching, consider using `is_ok()` + --> $DIR/redundant_pattern_matching.rs:183:15 + | +LL | while let Ok(_) = Ok::(10) {} + | ----------^^^^^--------------------- help: try this: `while Ok::(10).is_ok()` + +error: redundant pattern matching, consider using `is_err()` + --> $DIR/redundant_pattern_matching.rs:185:15 + | +LL | while let Err(_) = Ok::(10) {} + | ----------^^^^^^--------------------- help: try this: `while Ok::(10).is_err()` + +error: redundant pattern matching, consider using `is_ok()` + --> $DIR/redundant_pattern_matching.rs:187:5 + | +LL | / match Ok::(42) { +LL | | Ok(_) => true, +LL | | Err(_) => false, +LL | | }; + | |_____^ help: try this: `Ok::(42).is_ok()` + +error: redundant pattern matching, consider using `is_err()` + --> $DIR/redundant_pattern_matching.rs:192:5 + | +LL | / match Err::(42) { +LL | | Ok(_) => false, +LL | | Err(_) => true, +LL | | }; + | |_____^ help: try this: `Err::(42).is_err()` + +error: aborting due to 35 previous errors diff --git a/tests/ui/redundant_pattern_matching_const_result.fixed b/tests/ui/redundant_pattern_matching_const_result.fixed deleted file mode 100644 index de3fe00d5fa6..000000000000 --- a/tests/ui/redundant_pattern_matching_const_result.fixed +++ /dev/null @@ -1,44 +0,0 @@ -// run-rustfix - -#![feature(const_result)] -#![warn(clippy::redundant_pattern_matching)] -#![allow(clippy::match_like_matches_macro, unused)] - -// Test that results are linted with the feature enabled. - -const fn issue_5697() { - if Ok::(42).is_ok() {} - - if Err::(42).is_err() {} - - while Ok::(10).is_ok() {} - - while Ok::(10).is_err() {} - - Ok::(42).is_ok(); - - Err::(42).is_err(); - - // These should not be linted until `const_option` is implemented. - // See https://github.com/rust-lang/rust/issues/67441 - - if let Some(_) = Some(42) {} - - if let None = None::<()> {} - - while let Some(_) = Some(42) {} - - while let None = None::<()> {} - - match Some(42) { - Some(_) => true, - None => false, - }; - - match None::<()> { - Some(_) => false, - None => true, - }; -} - -fn main() {} diff --git a/tests/ui/redundant_pattern_matching_const_result.rs b/tests/ui/redundant_pattern_matching_const_result.rs deleted file mode 100644 index b77969d53d92..000000000000 --- a/tests/ui/redundant_pattern_matching_const_result.rs +++ /dev/null @@ -1,50 +0,0 @@ -// run-rustfix - -#![feature(const_result)] -#![warn(clippy::redundant_pattern_matching)] -#![allow(clippy::match_like_matches_macro, unused)] - -// Test that results are linted with the feature enabled. - -const fn issue_5697() { - if let Ok(_) = Ok::(42) {} - - if let Err(_) = Err::(42) {} - - while let Ok(_) = Ok::(10) {} - - while let Err(_) = Ok::(10) {} - - match Ok::(42) { - Ok(_) => true, - Err(_) => false, - }; - - match Err::(42) { - Ok(_) => false, - Err(_) => true, - }; - - // These should not be linted until `const_option` is implemented. - // See https://github.com/rust-lang/rust/issues/67441 - - if let Some(_) = Some(42) {} - - if let None = None::<()> {} - - while let Some(_) = Some(42) {} - - while let None = None::<()> {} - - match Some(42) { - Some(_) => true, - None => false, - }; - - match None::<()> { - Some(_) => false, - None => true, - }; -} - -fn main() {} diff --git a/tests/ui/redundant_pattern_matching_const_result.stderr b/tests/ui/redundant_pattern_matching_const_result.stderr deleted file mode 100644 index 8ecd72158d33..000000000000 --- a/tests/ui/redundant_pattern_matching_const_result.stderr +++ /dev/null @@ -1,46 +0,0 @@ -error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_const_result.rs:10:12 - | -LL | if let Ok(_) = Ok::(42) {} - | -------^^^^^--------------------- help: try this: `if Ok::(42).is_ok()` - | - = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` - -error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_const_result.rs:12:12 - | -LL | if let Err(_) = Err::(42) {} - | -------^^^^^^---------------------- help: try this: `if Err::(42).is_err()` - -error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_const_result.rs:14:15 - | -LL | while let Ok(_) = Ok::(10) {} - | ----------^^^^^--------------------- help: try this: `while Ok::(10).is_ok()` - -error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_const_result.rs:16:15 - | -LL | while let Err(_) = Ok::(10) {} - | ----------^^^^^^--------------------- help: try this: `while Ok::(10).is_err()` - -error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_const_result.rs:18:5 - | -LL | / match Ok::(42) { -LL | | Ok(_) => true, -LL | | Err(_) => false, -LL | | }; - | |_____^ help: try this: `Ok::(42).is_ok()` - -error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_const_result.rs:23:5 - | -LL | / match Err::(42) { -LL | | Ok(_) => false, -LL | | Err(_) => true, -LL | | }; - | |_____^ help: try this: `Err::(42).is_err()` - -error: aborting due to 6 previous errors - From f160fb2c0e158726ffce54f22829a4d01d0e56a2 Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Sun, 20 Sep 2020 10:46:30 +0200 Subject: [PATCH 0090/1222] Remove `can_suggest` check for `is_ok` and `is_err`. `is_ok` and `is_err` are stabilized as const and can thus always be suggested. --- clippy_lints/src/matches.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index be879dfe28d7..d20662f1ef94 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -1469,10 +1469,10 @@ mod redundant_pattern_match { keyword: &'static str, ) { fn find_suggestion(cx: &LateContext<'_>, hir_id: HirId, path: &QPath<'_>) -> Option<&'static str> { - if match_qpath(path, &paths::RESULT_OK) && can_suggest(cx, hir_id, sym!(result_type), "is_ok") { + if match_qpath(path, &paths::RESULT_OK) { return Some("is_ok()"); } - if match_qpath(path, &paths::RESULT_ERR) && can_suggest(cx, hir_id, sym!(result_type), "is_err") { + if match_qpath(path, &paths::RESULT_ERR) { return Some("is_err()"); } if match_qpath(path, &paths::OPTION_SOME) && can_suggest(cx, hir_id, sym!(option_type), "is_some") { @@ -1562,8 +1562,8 @@ mod redundant_pattern_match { &paths::RESULT_ERR, "is_ok()", "is_err()", - || can_suggest(cx, hir_id, sym!(result_type), "is_ok"), - || can_suggest(cx, hir_id, sym!(result_type), "is_err"), + || true, + || true ) } else { None From 1abb5340507f8ccff6bc34ace1c499fafd0e8902 Mon Sep 17 00:00:00 2001 From: CDirkx Date: Sun, 20 Sep 2020 12:21:23 +0200 Subject: [PATCH 0091/1222] Update src/tools/clippy/clippy_lints/src/matches.rs Co-authored-by: Ralf Jung --- clippy_lints/src/matches.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index d20662f1ef94..e88ff070fb58 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -1563,7 +1563,7 @@ mod redundant_pattern_match { "is_ok()", "is_err()", || true, - || true + || true, ) } else { None From ad548f15e0c3309bf2fb1cbcfba32fb0d07701c9 Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Sun, 20 Sep 2020 23:59:34 +0200 Subject: [PATCH 0092/1222] Update Clippy testcases Update the test `redundant_pattern_matching`: check if `is_some` and `is_none` are suggested within const contexts. --- tests/ui/redundant_pattern_matching.fixed | 39 +++++------- tests/ui/redundant_pattern_matching.rs | 45 ++++++-------- tests/ui/redundant_pattern_matching.stderr | 72 +++++++++++++++++----- 3 files changed, 91 insertions(+), 65 deletions(-) diff --git a/tests/ui/redundant_pattern_matching.fixed b/tests/ui/redundant_pattern_matching.fixed index 08bfe7c78d38..8084fdefdc23 100644 --- a/tests/ui/redundant_pattern_matching.fixed +++ b/tests/ui/redundant_pattern_matching.fixed @@ -76,7 +76,6 @@ fn main() { takes_bool(x); issue5504(); - issue5697(); issue6067(); let _ = if gen_opt().is_some() { @@ -129,41 +128,31 @@ fn issue5504() { while m!().is_some() {} } -// None of these should be linted because none of the suggested methods -// are `const fn` without toggling a feature. -const fn issue5697() { - if let Some(_) = Some(42) {} - - if let None = None::<()> {} - - while let Some(_) = Some(42) {} - - while let None = None::<()> {} - - match Some(42) { - Some(_) => true, - None => false, - }; - - match None::<()> { - Some(_) => false, - None => true, - }; -} - // Methods that are unstable const should not be suggested within a const context, see issue #5697. -// However, in Rust 1.48.0 the methods `is_ok` and `is_err` of `Result` were stabilized as const, -// so the following should be linted. +// However, in Rust 1.48.0 the methods `is_ok` and `is_err` of `Result`, and `is_some` and `is_none` +// of `Option` were stabilized as const, so the following should be linted. const fn issue6067() { if Ok::(42).is_ok() {} if Err::(42).is_err() {} + if Some(42).is_some() {} + + if None::<()>.is_none() {} + while Ok::(10).is_ok() {} while Ok::(10).is_err() {} + while Some(42).is_some() {} + + while None::<()>.is_none() {} + Ok::(42).is_ok(); Err::(42).is_err(); + + Some(42).is_some(); + + None::<()>.is_none(); } diff --git a/tests/ui/redundant_pattern_matching.rs b/tests/ui/redundant_pattern_matching.rs index c0660c6ac394..48a32cb1c7b7 100644 --- a/tests/ui/redundant_pattern_matching.rs +++ b/tests/ui/redundant_pattern_matching.rs @@ -97,7 +97,6 @@ fn main() { takes_bool(x); issue5504(); - issue5697(); issue6067(); let _ = if let Some(_) = gen_opt() { @@ -150,40 +149,26 @@ fn issue5504() { while let Some(_) = m!() {} } -// None of these should be linted because none of the suggested methods -// are `const fn` without toggling a feature. -const fn issue5697() { - if let Some(_) = Some(42) {} - - if let None = None::<()> {} - - while let Some(_) = Some(42) {} - - while let None = None::<()> {} - - match Some(42) { - Some(_) => true, - None => false, - }; - - match None::<()> { - Some(_) => false, - None => true, - }; -} - // Methods that are unstable const should not be suggested within a const context, see issue #5697. -// However, in Rust 1.48.0 the methods `is_ok` and `is_err` of `Result` were stabilized as const, -// so the following should be linted. +// However, in Rust 1.48.0 the methods `is_ok` and `is_err` of `Result`, and `is_some` and `is_none` +// of `Option` were stabilized as const, so the following should be linted. const fn issue6067() { if let Ok(_) = Ok::(42) {} if let Err(_) = Err::(42) {} + if let Some(_) = Some(42) {} + + if let None = None::<()> {} + while let Ok(_) = Ok::(10) {} while let Err(_) = Ok::(10) {} + while let Some(_) = Some(42) {} + + while let None = None::<()> {} + match Ok::(42) { Ok(_) => true, Err(_) => false, @@ -193,4 +178,14 @@ const fn issue6067() { Ok(_) => false, Err(_) => true, }; + + match Some(42) { + Some(_) => true, + None => false, + }; + + match None::<()> { + Some(_) => false, + None => true, + }; } diff --git a/tests/ui/redundant_pattern_matching.stderr b/tests/ui/redundant_pattern_matching.stderr index efd2f9903ec9..17185217e895 100644 --- a/tests/ui/redundant_pattern_matching.stderr +++ b/tests/ui/redundant_pattern_matching.stderr @@ -149,79 +149,103 @@ LL | let x = if let Some(_) = opt { true } else { false }; | -------^^^^^^^------ help: try this: `if opt.is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:103:20 + --> $DIR/redundant_pattern_matching.rs:102:20 | LL | let _ = if let Some(_) = gen_opt() { | -------^^^^^^^------------ help: try this: `if gen_opt().is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:105:19 + --> $DIR/redundant_pattern_matching.rs:104:19 | LL | } else if let None = gen_opt() { | -------^^^^------------ help: try this: `if gen_opt().is_none()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:107:19 + --> $DIR/redundant_pattern_matching.rs:106:19 | LL | } else if let Ok(_) = gen_res() { | -------^^^^^------------ help: try this: `if gen_res().is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:109:19 + --> $DIR/redundant_pattern_matching.rs:108:19 | LL | } else if let Err(_) = gen_res() { | -------^^^^^^------------ help: try this: `if gen_res().is_err()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:142:19 + --> $DIR/redundant_pattern_matching.rs:141:19 | LL | while let Some(_) = r#try!(result_opt()) {} | ----------^^^^^^^----------------------- help: try this: `while r#try!(result_opt()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:143:16 + --> $DIR/redundant_pattern_matching.rs:142:16 | LL | if let Some(_) = r#try!(result_opt()) {} | -------^^^^^^^----------------------- help: try this: `if r#try!(result_opt()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:149:12 + --> $DIR/redundant_pattern_matching.rs:148:12 | LL | if let Some(_) = m!() {} | -------^^^^^^^------- help: try this: `if m!().is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:150:15 + --> $DIR/redundant_pattern_matching.rs:149:15 | LL | while let Some(_) = m!() {} | ----------^^^^^^^------- help: try this: `while m!().is_some()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:179:12 + --> $DIR/redundant_pattern_matching.rs:156:12 | LL | if let Ok(_) = Ok::(42) {} | -------^^^^^--------------------- help: try this: `if Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:181:12 + --> $DIR/redundant_pattern_matching.rs:158:12 | LL | if let Err(_) = Err::(42) {} | -------^^^^^^---------------------- help: try this: `if Err::(42).is_err()` +error: redundant pattern matching, consider using `is_some()` + --> $DIR/redundant_pattern_matching.rs:160:12 + | +LL | if let Some(_) = Some(42) {} + | -------^^^^^^^----------- help: try this: `if Some(42).is_some()` + +error: redundant pattern matching, consider using `is_none()` + --> $DIR/redundant_pattern_matching.rs:162:12 + | +LL | if let None = None::<()> {} + | -------^^^^------------- help: try this: `if None::<()>.is_none()` + error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:183:15 + --> $DIR/redundant_pattern_matching.rs:164:15 | LL | while let Ok(_) = Ok::(10) {} | ----------^^^^^--------------------- help: try this: `while Ok::(10).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:185:15 + --> $DIR/redundant_pattern_matching.rs:166:15 | LL | while let Err(_) = Ok::(10) {} | ----------^^^^^^--------------------- help: try this: `while Ok::(10).is_err()` +error: redundant pattern matching, consider using `is_some()` + --> $DIR/redundant_pattern_matching.rs:168:15 + | +LL | while let Some(_) = Some(42) {} + | ----------^^^^^^^----------- help: try this: `while Some(42).is_some()` + +error: redundant pattern matching, consider using `is_none()` + --> $DIR/redundant_pattern_matching.rs:170:15 + | +LL | while let None = None::<()> {} + | ----------^^^^------------- help: try this: `while None::<()>.is_none()` + error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:187:5 + --> $DIR/redundant_pattern_matching.rs:172:5 | LL | / match Ok::(42) { LL | | Ok(_) => true, @@ -230,7 +254,7 @@ LL | | }; | |_____^ help: try this: `Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:192:5 + --> $DIR/redundant_pattern_matching.rs:177:5 | LL | / match Err::(42) { LL | | Ok(_) => false, @@ -238,5 +262,23 @@ LL | | Err(_) => true, LL | | }; | |_____^ help: try this: `Err::(42).is_err()` -error: aborting due to 35 previous errors +error: redundant pattern matching, consider using `is_some()` + --> $DIR/redundant_pattern_matching.rs:182:5 + | +LL | / match Some(42) { +LL | | Some(_) => true, +LL | | None => false, +LL | | }; + | |_____^ help: try this: `Some(42).is_some()` + +error: redundant pattern matching, consider using `is_none()` + --> $DIR/redundant_pattern_matching.rs:187:5 + | +LL | / match None::<()> { +LL | | Some(_) => false, +LL | | None => true, +LL | | }; + | |_____^ help: try this: `None::<()>.is_none()` + +error: aborting due to 41 previous errors From 699c0e3fc43bf7ac8f2a1c16a7241bb2fb6185a6 Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Mon, 21 Sep 2020 00:00:33 +0200 Subject: [PATCH 0093/1222] Remove `can_suggest` from Clippy. Removes `can_suggest` from as it is no longer used. Reverts rust-clippy#5724. --- clippy_lints/src/matches.rs | 78 ++++++++----------------------------- 1 file changed, 16 insertions(+), 62 deletions(-) diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index db52c97475fa..819846ebc793 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -1440,15 +1440,12 @@ where mod redundant_pattern_match { use super::REDUNDANT_PATTERN_MATCHING; - use crate::utils::{in_constant, match_qpath, match_trait_method, paths, snippet, span_lint_and_then}; + use crate::utils::{match_qpath, match_trait_method, paths, snippet, span_lint_and_then}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; - use rustc_hir::{Arm, Expr, ExprKind, HirId, MatchSource, PatKind, QPath}; + use rustc_hir::{Arm, Expr, ExprKind, MatchSource, PatKind, QPath}; use rustc_lint::LateContext; - use rustc_middle::ty; - use rustc_mir::const_eval::is_const_fn; - use rustc_span::source_map::Symbol; pub fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Match(op, arms, ref match_source) = &expr.kind { @@ -1468,37 +1465,24 @@ mod redundant_pattern_match { arms: &[Arm<'_>], keyword: &'static str, ) { - fn find_suggestion(cx: &LateContext<'_>, hir_id: HirId, path: &QPath<'_>) -> Option<&'static str> { - if match_qpath(path, &paths::RESULT_OK) { - return Some("is_ok()"); - } - if match_qpath(path, &paths::RESULT_ERR) { - return Some("is_err()"); - } - if match_qpath(path, &paths::OPTION_SOME) && can_suggest(cx, hir_id, sym!(option_type), "is_some") { - return Some("is_some()"); - } - if match_qpath(path, &paths::OPTION_NONE) && can_suggest(cx, hir_id, sym!(option_type), "is_none") { - return Some("is_none()"); - } - None - } - - let hir_id = expr.hir_id; let good_method = match arms[0].pat.kind { PatKind::TupleStruct(ref path, ref patterns, _) if patterns.len() == 1 => { if let PatKind::Wild = patterns[0].kind { - find_suggestion(cx, hir_id, path) + if match_qpath(path, &paths::RESULT_OK) { + "is_ok()" + } else if match_qpath(path, &paths::RESULT_ERR) { + "is_err()" + } else if match_qpath(path, &paths::OPTION_SOME) { + "is_some()" + } else { + return; + } } else { - None + return; } }, - PatKind::Path(ref path) => find_suggestion(cx, hir_id, path), - _ => None, - }; - let good_method = match good_method { - Some(method) => method, - None => return, + PatKind::Path(ref path) if match_qpath(path, &paths::OPTION_NONE) => "is_none()", + _ => return, }; // check that `while_let_on_iterator` lint does not trigger @@ -1547,7 +1531,6 @@ mod redundant_pattern_match { if arms.len() == 2 { let node_pair = (&arms[0].pat.kind, &arms[1].pat.kind); - let hir_id = expr.hir_id; let found_good_method = match node_pair { ( PatKind::TupleStruct(ref path_left, ref patterns_left, _), @@ -1562,8 +1545,6 @@ mod redundant_pattern_match { &paths::RESULT_ERR, "is_ok()", "is_err()", - || true, - || true, ) } else { None @@ -1582,8 +1563,6 @@ mod redundant_pattern_match { &paths::OPTION_NONE, "is_some()", "is_none()", - || can_suggest(cx, hir_id, sym!(option_type), "is_some"), - || can_suggest(cx, hir_id, sym!(option_type), "is_none"), ) } else { None @@ -1616,7 +1595,6 @@ mod redundant_pattern_match { } } - #[allow(clippy::too_many_arguments)] fn find_good_method_for_match<'a>( arms: &[Arm<'_>], path_left: &QPath<'_>, @@ -1625,8 +1603,6 @@ mod redundant_pattern_match { expected_right: &[&str], should_be_left: &'a str, should_be_right: &'a str, - can_suggest_left: impl Fn() -> bool, - can_suggest_right: impl Fn() -> bool, ) -> Option<&'a str> { let body_node_pair = if match_qpath(path_left, expected_left) && match_qpath(path_right, expected_right) { (&(*arms[0].body).kind, &(*arms[1].body).kind) @@ -1638,35 +1614,13 @@ mod redundant_pattern_match { match body_node_pair { (ExprKind::Lit(ref lit_left), ExprKind::Lit(ref lit_right)) => match (&lit_left.node, &lit_right.node) { - (LitKind::Bool(true), LitKind::Bool(false)) if can_suggest_left() => Some(should_be_left), - (LitKind::Bool(false), LitKind::Bool(true)) if can_suggest_right() => Some(should_be_right), + (LitKind::Bool(true), LitKind::Bool(false)) => Some(should_be_left), + (LitKind::Bool(false), LitKind::Bool(true)) => Some(should_be_right), _ => None, }, _ => None, } } - - fn can_suggest(cx: &LateContext<'_>, hir_id: HirId, diag_item: Symbol, name: &str) -> bool { - if !in_constant(cx, hir_id) { - return true; - } - - // Avoid suggesting calls to non-`const fn`s in const contexts, see #5697. - cx.tcx - .get_diagnostic_item(diag_item) - .and_then(|def_id| { - cx.tcx.inherent_impls(def_id).iter().find_map(|imp| { - cx.tcx - .associated_items(*imp) - .in_definition_order() - .find_map(|item| match item.kind { - ty::AssocKind::Fn if item.ident.name.as_str() == name => Some(item.def_id), - _ => None, - }) - }) - }) - .map_or(false, |def_id| is_const_fn(cx.tcx, def_id)) - } } #[test] From 09fa0f3f312c81fcaea6eb3b4725e37eaf4a67dc Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Sat, 26 Sep 2020 16:08:24 +0200 Subject: [PATCH 0094/1222] Move `qualify_min_const_fn` out of rustc into clippy --- clippy_lints/src/lib.rs | 1 + clippy_lints/src/missing_const_for_fn.rs | 2 +- clippy_lints/src/utils/mod.rs | 1 + .../src/utils/qualify_min_const_fn.rs | 462 ++++++++++++++++++ 4 files changed, 465 insertions(+), 1 deletion(-) create mode 100644 clippy_lints/src/utils/qualify_min_const_fn.rs diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 58112ac8da5f..c3ff34e6e1ee 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -6,6 +6,7 @@ #![feature(concat_idents)] #![feature(crate_visibility_modifier)] #![feature(drain_filter)] +#![feature(in_band_lifetimes)] #![feature(or_patterns)] #![feature(rustc_private)] #![feature(stmt_expr_attributes)] diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 1ad184dfc460..e5f7cc511112 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, Constness, FnDecl, GenericParamKind, HirId}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; -use rustc_mir::transform::qualify_min_const_fn::is_min_const_fn; +use crate::utils::qualify_min_const_fn::is_min_const_fn; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Span; use rustc_typeck::hir_ty_to_ty; diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index ea52741b7cc4..96d9905027b6 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -20,6 +20,7 @@ pub mod paths; pub mod ptr; pub mod sugg; pub mod usage; +pub mod qualify_min_const_fn; pub use self::attrs::*; pub use self::diagnostics::*; diff --git a/clippy_lints/src/utils/qualify_min_const_fn.rs b/clippy_lints/src/utils/qualify_min_const_fn.rs new file mode 100644 index 000000000000..9fa9b0341b10 --- /dev/null +++ b/clippy_lints/src/utils/qualify_min_const_fn.rs @@ -0,0 +1,462 @@ +use rustc_hir as hir; +use rustc_hir::def_id::DefId; +use rustc_middle::mir::*; +use rustc_middle::ty::subst::GenericArgKind; +use rustc_middle::ty::{self, adjustment::PointerCast, Ty, TyCtxt}; +use rustc_span::symbol::{sym, Symbol}; +use rustc_span::Span; +use rustc_target::spec::abi::Abi::RustIntrinsic; +use std::borrow::Cow; + +type McfResult = Result<(), (Span, Cow<'static, str>)>; + +pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -> McfResult { + // Prevent const trait methods from being annotated as `stable`. + if tcx.features().staged_api { + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); + if rustc_mir::const_eval::is_parent_const_impl_raw(tcx, hir_id) { + return Err((body.span, "trait methods cannot be stable const fn".into())); + } + } + + let mut current = def_id; + loop { + let predicates = tcx.predicates_of(current); + for (predicate, _) in predicates.predicates { + match predicate.skip_binders() { + ty::PredicateAtom::RegionOutlives(_) + | ty::PredicateAtom::TypeOutlives(_) + | ty::PredicateAtom::WellFormed(_) + | ty::PredicateAtom::Projection(_) + | ty::PredicateAtom::ConstEvaluatable(..) + | ty::PredicateAtom::ConstEquate(..) + | ty::PredicateAtom::TypeWellFormedFromEnv(..) => continue, + ty::PredicateAtom::ObjectSafe(_) => { + panic!("object safe predicate on function: {:#?}", predicate) + } + ty::PredicateAtom::ClosureKind(..) => { + panic!("closure kind predicate on function: {:#?}", predicate) + } + ty::PredicateAtom::Subtype(_) => { + panic!("subtype predicate on function: {:#?}", predicate) + } + ty::PredicateAtom::Trait(pred, constness) => { + if Some(pred.def_id()) == tcx.lang_items().sized_trait() { + continue; + } + match pred.self_ty().kind() { + ty::Param(ref p) => { + // Allow `T: ?const Trait` + if constness == hir::Constness::NotConst + && feature_allowed(tcx, def_id, sym::const_trait_bound_opt_out) + { + continue; + } + + let generics = tcx.generics_of(current); + let def = generics.type_param(p, tcx); + let span = tcx.def_span(def.def_id); + return Err(( + span, + "trait bounds other than `Sized` \ + on const fn parameters are unstable" + .into(), + )); + } + // other kinds of bounds are either tautologies + // or cause errors in other passes + _ => continue, + } + } + } + } + match predicates.parent { + Some(parent) => current = parent, + None => break, + } + } + + for local in &body.local_decls { + check_ty(tcx, local.ty, local.source_info.span, def_id)?; + } + // impl trait is gone in MIR, so check the return type manually + check_ty( + tcx, + tcx.fn_sig(def_id).output().skip_binder(), + body.local_decls.iter().next().unwrap().source_info.span, + def_id, + )?; + + for bb in body.basic_blocks() { + check_terminator(tcx, body, def_id, bb.terminator())?; + for stmt in &bb.statements { + check_statement(tcx, body, def_id, stmt)?; + } + } + Ok(()) +} + +fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span, fn_def_id: DefId) -> McfResult { + for arg in ty.walk() { + let ty = match arg.unpack() { + GenericArgKind::Type(ty) => ty, + + // No constraints on lifetimes or constants, except potentially + // constants' types, but `walk` will get to them as well. + GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => continue, + }; + + match ty.kind() { + ty::Ref(_, _, hir::Mutability::Mut) => { + if !feature_allowed(tcx, fn_def_id, sym::const_mut_refs) { + return Err((span, "mutable references in const fn are unstable".into())); + } + } + ty::Opaque(..) => return Err((span, "`impl Trait` in const fn is unstable".into())), + ty::FnPtr(..) => { + if !tcx.const_fn_is_allowed_fn_ptr(fn_def_id) { + return Err((span, "function pointers in const fn are unstable".into())); + } + } + ty::Dynamic(preds, _) => { + for pred in preds.iter() { + match pred.skip_binder() { + ty::ExistentialPredicate::AutoTrait(_) + | ty::ExistentialPredicate::Projection(_) => { + return Err(( + span, + "trait bounds other than `Sized` \ + on const fn parameters are unstable" + .into(), + )); + } + ty::ExistentialPredicate::Trait(trait_ref) => { + if Some(trait_ref.def_id) != tcx.lang_items().sized_trait() { + return Err(( + span, + "trait bounds other than `Sized` \ + on const fn parameters are unstable" + .into(), + )); + } + } + } + } + } + _ => {} + } + } + Ok(()) +} + +fn check_rvalue( + tcx: TyCtxt<'tcx>, + body: &Body<'tcx>, + def_id: DefId, + rvalue: &Rvalue<'tcx>, + span: Span, +) -> McfResult { + match rvalue { + Rvalue::ThreadLocalRef(_) => { + Err((span, "cannot access thread local storage in const fn".into())) + } + Rvalue::Repeat(operand, _) | Rvalue::Use(operand) => { + check_operand(tcx, operand, span, def_id, body) + } + Rvalue::Len(place) + | Rvalue::Discriminant(place) + | Rvalue::Ref(_, _, place) + | Rvalue::AddressOf(_, place) => check_place(tcx, *place, span, def_id, body), + Rvalue::Cast(CastKind::Misc, operand, cast_ty) => { + use rustc_middle::ty::cast::CastTy; + let cast_in = CastTy::from_ty(operand.ty(body, tcx)).expect("bad input type for cast"); + let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast"); + match (cast_in, cast_out) { + (CastTy::Ptr(_) | CastTy::FnPtr, CastTy::Int(_)) => { + Err((span, "casting pointers to ints is unstable in const fn".into())) + } + _ => check_operand(tcx, operand, span, def_id, body), + } + } + Rvalue::Cast( + CastKind::Pointer(PointerCast::MutToConstPointer | PointerCast::ArrayToPointer), + operand, + _, + ) => check_operand(tcx, operand, span, def_id, body), + Rvalue::Cast( + CastKind::Pointer( + PointerCast::UnsafeFnPointer + | PointerCast::ClosureFnPointer(_) + | PointerCast::ReifyFnPointer, + ), + _, + _, + ) => Err((span, "function pointer casts are not allowed in const fn".into())), + Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), op, cast_ty) => { + let pointee_ty = if let Some(deref_ty) = cast_ty.builtin_deref(true) { + deref_ty.ty + } else { + // We cannot allow this for now. + return Err(( + span, + "unsizing casts are only allowed for references right now".into(), + )); + }; + let unsized_ty = tcx.struct_tail_erasing_lifetimes(pointee_ty, tcx.param_env(def_id)); + if let ty::Slice(_) | ty::Str = unsized_ty.kind() { + check_operand(tcx, op, span, def_id, body)?; + // Casting/coercing things to slices is fine. + Ok(()) + } else { + // We just can't allow trait objects until we have figured out trait method calls. + Err((span, "unsizing casts are not allowed in const fn".into())) + } + } + // binops are fine on integers + Rvalue::BinaryOp(_, lhs, rhs) | Rvalue::CheckedBinaryOp(_, lhs, rhs) => { + check_operand(tcx, lhs, span, def_id, body)?; + check_operand(tcx, rhs, span, def_id, body)?; + let ty = lhs.ty(body, tcx); + if ty.is_integral() || ty.is_bool() || ty.is_char() { + Ok(()) + } else { + Err((span, "only int, `bool` and `char` operations are stable in const fn".into())) + } + } + Rvalue::NullaryOp(NullOp::SizeOf, _) => Ok(()), + Rvalue::NullaryOp(NullOp::Box, _) => { + Err((span, "heap allocations are not allowed in const fn".into())) + } + Rvalue::UnaryOp(_, operand) => { + let ty = operand.ty(body, tcx); + if ty.is_integral() || ty.is_bool() { + check_operand(tcx, operand, span, def_id, body) + } else { + Err((span, "only int and `bool` operations are stable in const fn".into())) + } + } + Rvalue::Aggregate(_, operands) => { + for operand in operands { + check_operand(tcx, operand, span, def_id, body)?; + } + Ok(()) + } + } +} + +fn check_statement( + tcx: TyCtxt<'tcx>, + body: &Body<'tcx>, + def_id: DefId, + statement: &Statement<'tcx>, +) -> McfResult { + let span = statement.source_info.span; + match &statement.kind { + StatementKind::Assign(box (place, rval)) => { + check_place(tcx, *place, span, def_id, body)?; + check_rvalue(tcx, body, def_id, rval, span) + } + + StatementKind::FakeRead(_, place) => check_place(tcx, **place, span, def_id, body), + + // just an assignment + StatementKind::SetDiscriminant { place, .. } => { + check_place(tcx, **place, span, def_id, body) + } + + StatementKind::LlvmInlineAsm { .. } => { + Err((span, "cannot use inline assembly in const fn".into())) + } + + // These are all NOPs + StatementKind::StorageLive(_) + | StatementKind::StorageDead(_) + | StatementKind::Retag { .. } + | StatementKind::AscribeUserType(..) + | StatementKind::Coverage(..) + | StatementKind::Nop => Ok(()), + } +} + +fn check_operand( + tcx: TyCtxt<'tcx>, + operand: &Operand<'tcx>, + span: Span, + def_id: DefId, + body: &Body<'tcx>, +) -> McfResult { + match operand { + Operand::Move(place) | Operand::Copy(place) => check_place(tcx, *place, span, def_id, body), + Operand::Constant(c) => match c.check_static_ptr(tcx) { + Some(_) => Err((span, "cannot access `static` items in const fn".into())), + None => Ok(()), + }, + } +} + +fn check_place( + tcx: TyCtxt<'tcx>, + place: Place<'tcx>, + span: Span, + def_id: DefId, + body: &Body<'tcx>, +) -> McfResult { + let mut cursor = place.projection.as_ref(); + while let &[ref proj_base @ .., elem] = cursor { + cursor = proj_base; + match elem { + ProjectionElem::Field(..) => { + let base_ty = Place::ty_from(place.local, &proj_base, body, tcx).ty; + if let Some(def) = base_ty.ty_adt_def() { + // No union field accesses in `const fn` + if def.is_union() { + if !feature_allowed(tcx, def_id, sym::const_fn_union) { + return Err((span, "accessing union fields is unstable".into())); + } + } + } + } + ProjectionElem::ConstantIndex { .. } + | ProjectionElem::Downcast(..) + | ProjectionElem::Subslice { .. } + | ProjectionElem::Deref + | ProjectionElem::Index(_) => {} + } + } + + Ok(()) +} + +/// Returns `true` if the given feature gate is allowed within the function with the given `DefId`. +fn feature_allowed(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbol) -> bool { + // All features require that the corresponding gate be enabled, + // even if the function has `#[allow_internal_unstable(the_gate)]`. + if !tcx.features().enabled(feature_gate) { + return false; + } + + // If this crate is not using stability attributes, or this function is not claiming to be a + // stable `const fn`, that is all that is required. + if !tcx.features().staged_api || tcx.has_attr(def_id, sym::rustc_const_unstable) { + return true; + } + + // However, we cannot allow stable `const fn`s to use unstable features without an explicit + // opt-in via `allow_internal_unstable`. + rustc_mir::transform::check_consts::allow_internal_unstable(tcx, def_id, feature_gate) +} + +/// Returns `true` if the given library feature gate is allowed within the function with the given `DefId`. +pub fn lib_feature_allowed(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbol) -> bool { + // All features require that the corresponding gate be enabled, + // even if the function has `#[allow_internal_unstable(the_gate)]`. + if !tcx.features().declared_lib_features.iter().any(|&(sym, _)| sym == feature_gate) { + return false; + } + + // If this crate is not using stability attributes, or this function is not claiming to be a + // stable `const fn`, that is all that is required. + if !tcx.features().staged_api || tcx.has_attr(def_id, sym::rustc_const_unstable) { + return true; + } + + // However, we cannot allow stable `const fn`s to use unstable features without an explicit + // opt-in via `allow_internal_unstable`. + rustc_mir::transform::check_consts::allow_internal_unstable(tcx, def_id, feature_gate) +} + +fn check_terminator( + tcx: TyCtxt<'tcx>, + body: &'a Body<'tcx>, + def_id: DefId, + terminator: &Terminator<'tcx>, +) -> McfResult { + let span = terminator.source_info.span; + match &terminator.kind { + TerminatorKind::FalseEdge { .. } + | TerminatorKind::FalseUnwind { .. } + | TerminatorKind::Goto { .. } + | TerminatorKind::Return + | TerminatorKind::Resume + | TerminatorKind::Unreachable => Ok(()), + + TerminatorKind::Drop { place, .. } => check_place(tcx, *place, span, def_id, body), + TerminatorKind::DropAndReplace { place, value, .. } => { + check_place(tcx, *place, span, def_id, body)?; + check_operand(tcx, value, span, def_id, body) + } + + TerminatorKind::SwitchInt { discr, switch_ty: _, values: _, targets: _ } => { + check_operand(tcx, discr, span, def_id, body) + } + + TerminatorKind::Abort => Err((span, "abort is not stable in const fn".into())), + TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => { + Err((span, "const fn generators are unstable".into())) + } + + TerminatorKind::Call { + func, + args, + from_hir_call: _, + destination: _, + cleanup: _, + fn_span: _, + } => { + let fn_ty = func.ty(body, tcx); + if let ty::FnDef(fn_def_id, _) = *fn_ty.kind() { + // Allow unstable const if we opt in by using #[allow_internal_unstable] + // on function or macro declaration. + if !rustc_mir::const_eval::is_min_const_fn(tcx, fn_def_id) + && !rustc_mir::const_eval::is_unstable_const_fn(tcx, fn_def_id) + .map(|feature| { + span.allows_unstable(feature) + || lib_feature_allowed(tcx, def_id, feature) + }) + .unwrap_or(false) + { + return Err(( + span, + format!( + "can only call other `const fn` within a `const fn`, \ + but `{:?}` is not stable as `const fn`", + func, + ) + .into(), + )); + } + + // HACK: This is to "unstabilize" the `transmute` intrinsic + // within const fns. `transmute` is allowed in all other const contexts. + // This won't really scale to more intrinsics or functions. Let's allow const + // transmutes in const fn before we add more hacks to this. + if tcx.fn_sig(fn_def_id).abi() == RustIntrinsic + && tcx.item_name(fn_def_id) == sym::transmute + && !feature_allowed(tcx, def_id, sym::const_fn_transmute) + { + return Err(( + span, + "can only call `transmute` from const items, not `const fn`".into(), + )); + } + + check_operand(tcx, func, span, fn_def_id, body)?; + + for arg in args { + check_operand(tcx, arg, span, fn_def_id, body)?; + } + Ok(()) + } else { + Err((span, "can only call other const fns within const fn".into())) + } + } + + TerminatorKind::Assert { cond, expected: _, msg: _, target: _, cleanup: _ } => { + check_operand(tcx, cond, span, def_id, body) + } + + TerminatorKind::InlineAsm { .. } => { + Err((span, "cannot use inline assembly in const fn".into())) + } + } +} From 0bf90523ff1cebfb164310f1d4bd473d7c51987c Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Sat, 26 Sep 2020 16:23:56 +0200 Subject: [PATCH 0095/1222] Remove all unstable feature support in the `missing_const_for_fn` lint --- .../src/utils/qualify_min_const_fn.rs | 122 ++++-------------- 1 file changed, 25 insertions(+), 97 deletions(-) diff --git a/clippy_lints/src/utils/qualify_min_const_fn.rs b/clippy_lints/src/utils/qualify_min_const_fn.rs index 9fa9b0341b10..6809b1fa88d3 100644 --- a/clippy_lints/src/utils/qualify_min_const_fn.rs +++ b/clippy_lints/src/utils/qualify_min_const_fn.rs @@ -3,7 +3,7 @@ use rustc_hir::def_id::DefId; use rustc_middle::mir::*; use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::{self, adjustment::PointerCast, Ty, TyCtxt}; -use rustc_span::symbol::{sym, Symbol}; +use rustc_span::symbol::{sym}; use rustc_span::Span; use rustc_target::spec::abi::Abi::RustIntrinsic; use std::borrow::Cow; @@ -11,14 +11,6 @@ use std::borrow::Cow; type McfResult = Result<(), (Span, Cow<'static, str>)>; pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -> McfResult { - // Prevent const trait methods from being annotated as `stable`. - if tcx.features().staged_api { - let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); - if rustc_mir::const_eval::is_parent_const_impl_raw(tcx, hir_id) { - return Err((body.span, "trait methods cannot be stable const fn".into())); - } - } - let mut current = def_id; loop { let predicates = tcx.predicates_of(current); @@ -40,19 +32,12 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) - ty::PredicateAtom::Subtype(_) => { panic!("subtype predicate on function: {:#?}", predicate) } - ty::PredicateAtom::Trait(pred, constness) => { + ty::PredicateAtom::Trait(pred, _) => { if Some(pred.def_id()) == tcx.lang_items().sized_trait() { continue; } match pred.self_ty().kind() { ty::Param(ref p) => { - // Allow `T: ?const Trait` - if constness == hir::Constness::NotConst - && feature_allowed(tcx, def_id, sym::const_trait_bound_opt_out) - { - continue; - } - let generics = tcx.generics_of(current); let def = generics.type_param(p, tcx); let span = tcx.def_span(def.def_id); @@ -77,18 +62,17 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) - } for local in &body.local_decls { - check_ty(tcx, local.ty, local.source_info.span, def_id)?; + check_ty(tcx, local.ty, local.source_info.span)?; } // impl trait is gone in MIR, so check the return type manually check_ty( tcx, tcx.fn_sig(def_id).output().skip_binder(), body.local_decls.iter().next().unwrap().source_info.span, - def_id, )?; for bb in body.basic_blocks() { - check_terminator(tcx, body, def_id, bb.terminator())?; + check_terminator(tcx, body, bb.terminator())?; for stmt in &bb.statements { check_statement(tcx, body, def_id, stmt)?; } @@ -96,7 +80,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) - Ok(()) } -fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span, fn_def_id: DefId) -> McfResult { +fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult { for arg in ty.walk() { let ty = match arg.unpack() { GenericArgKind::Type(ty) => ty, @@ -108,15 +92,11 @@ fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span, fn_def_id: DefId) -> Mc match ty.kind() { ty::Ref(_, _, hir::Mutability::Mut) => { - if !feature_allowed(tcx, fn_def_id, sym::const_mut_refs) { return Err((span, "mutable references in const fn are unstable".into())); - } } ty::Opaque(..) => return Err((span, "`impl Trait` in const fn is unstable".into())), ty::FnPtr(..) => { - if !tcx.const_fn_is_allowed_fn_ptr(fn_def_id) { return Err((span, "function pointers in const fn are unstable".into())); - } } ty::Dynamic(preds, _) => { for pred in preds.iter() { @@ -161,12 +141,12 @@ fn check_rvalue( Err((span, "cannot access thread local storage in const fn".into())) } Rvalue::Repeat(operand, _) | Rvalue::Use(operand) => { - check_operand(tcx, operand, span, def_id, body) + check_operand(tcx, operand, span, body) } Rvalue::Len(place) | Rvalue::Discriminant(place) | Rvalue::Ref(_, _, place) - | Rvalue::AddressOf(_, place) => check_place(tcx, *place, span, def_id, body), + | Rvalue::AddressOf(_, place) => check_place(tcx, *place, span, body), Rvalue::Cast(CastKind::Misc, operand, cast_ty) => { use rustc_middle::ty::cast::CastTy; let cast_in = CastTy::from_ty(operand.ty(body, tcx)).expect("bad input type for cast"); @@ -175,14 +155,14 @@ fn check_rvalue( (CastTy::Ptr(_) | CastTy::FnPtr, CastTy::Int(_)) => { Err((span, "casting pointers to ints is unstable in const fn".into())) } - _ => check_operand(tcx, operand, span, def_id, body), + _ => check_operand(tcx, operand, span, body), } } Rvalue::Cast( CastKind::Pointer(PointerCast::MutToConstPointer | PointerCast::ArrayToPointer), operand, _, - ) => check_operand(tcx, operand, span, def_id, body), + ) => check_operand(tcx, operand, span, body), Rvalue::Cast( CastKind::Pointer( PointerCast::UnsafeFnPointer @@ -204,7 +184,7 @@ fn check_rvalue( }; let unsized_ty = tcx.struct_tail_erasing_lifetimes(pointee_ty, tcx.param_env(def_id)); if let ty::Slice(_) | ty::Str = unsized_ty.kind() { - check_operand(tcx, op, span, def_id, body)?; + check_operand(tcx, op, span, body)?; // Casting/coercing things to slices is fine. Ok(()) } else { @@ -214,8 +194,8 @@ fn check_rvalue( } // binops are fine on integers Rvalue::BinaryOp(_, lhs, rhs) | Rvalue::CheckedBinaryOp(_, lhs, rhs) => { - check_operand(tcx, lhs, span, def_id, body)?; - check_operand(tcx, rhs, span, def_id, body)?; + check_operand(tcx, lhs, span, body)?; + check_operand(tcx, rhs, span, body)?; let ty = lhs.ty(body, tcx); if ty.is_integral() || ty.is_bool() || ty.is_char() { Ok(()) @@ -230,14 +210,14 @@ fn check_rvalue( Rvalue::UnaryOp(_, operand) => { let ty = operand.ty(body, tcx); if ty.is_integral() || ty.is_bool() { - check_operand(tcx, operand, span, def_id, body) + check_operand(tcx, operand, span, body) } else { Err((span, "only int and `bool` operations are stable in const fn".into())) } } Rvalue::Aggregate(_, operands) => { for operand in operands { - check_operand(tcx, operand, span, def_id, body)?; + check_operand(tcx, operand, span, body)?; } Ok(()) } @@ -253,15 +233,15 @@ fn check_statement( let span = statement.source_info.span; match &statement.kind { StatementKind::Assign(box (place, rval)) => { - check_place(tcx, *place, span, def_id, body)?; + check_place(tcx, *place, span, body)?; check_rvalue(tcx, body, def_id, rval, span) } - StatementKind::FakeRead(_, place) => check_place(tcx, **place, span, def_id, body), + StatementKind::FakeRead(_, place) => check_place(tcx, **place, span, body), // just an assignment StatementKind::SetDiscriminant { place, .. } => { - check_place(tcx, **place, span, def_id, body) + check_place(tcx, **place, span, body) } StatementKind::LlvmInlineAsm { .. } => { @@ -282,11 +262,10 @@ fn check_operand( tcx: TyCtxt<'tcx>, operand: &Operand<'tcx>, span: Span, - def_id: DefId, body: &Body<'tcx>, ) -> McfResult { match operand { - Operand::Move(place) | Operand::Copy(place) => check_place(tcx, *place, span, def_id, body), + Operand::Move(place) | Operand::Copy(place) => check_place(tcx, *place, span, body), Operand::Constant(c) => match c.check_static_ptr(tcx) { Some(_) => Err((span, "cannot access `static` items in const fn".into())), None => Ok(()), @@ -298,7 +277,6 @@ fn check_place( tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, - def_id: DefId, body: &Body<'tcx>, ) -> McfResult { let mut cursor = place.projection.as_ref(); @@ -310,9 +288,7 @@ fn check_place( if let Some(def) = base_ty.ty_adt_def() { // No union field accesses in `const fn` if def.is_union() { - if !feature_allowed(tcx, def_id, sym::const_fn_union) { return Err((span, "accessing union fields is unstable".into())); - } } } } @@ -327,48 +303,9 @@ fn check_place( Ok(()) } -/// Returns `true` if the given feature gate is allowed within the function with the given `DefId`. -fn feature_allowed(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbol) -> bool { - // All features require that the corresponding gate be enabled, - // even if the function has `#[allow_internal_unstable(the_gate)]`. - if !tcx.features().enabled(feature_gate) { - return false; - } - - // If this crate is not using stability attributes, or this function is not claiming to be a - // stable `const fn`, that is all that is required. - if !tcx.features().staged_api || tcx.has_attr(def_id, sym::rustc_const_unstable) { - return true; - } - - // However, we cannot allow stable `const fn`s to use unstable features without an explicit - // opt-in via `allow_internal_unstable`. - rustc_mir::transform::check_consts::allow_internal_unstable(tcx, def_id, feature_gate) -} - -/// Returns `true` if the given library feature gate is allowed within the function with the given `DefId`. -pub fn lib_feature_allowed(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbol) -> bool { - // All features require that the corresponding gate be enabled, - // even if the function has `#[allow_internal_unstable(the_gate)]`. - if !tcx.features().declared_lib_features.iter().any(|&(sym, _)| sym == feature_gate) { - return false; - } - - // If this crate is not using stability attributes, or this function is not claiming to be a - // stable `const fn`, that is all that is required. - if !tcx.features().staged_api || tcx.has_attr(def_id, sym::rustc_const_unstable) { - return true; - } - - // However, we cannot allow stable `const fn`s to use unstable features without an explicit - // opt-in via `allow_internal_unstable`. - rustc_mir::transform::check_consts::allow_internal_unstable(tcx, def_id, feature_gate) -} - fn check_terminator( tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, - def_id: DefId, terminator: &Terminator<'tcx>, ) -> McfResult { let span = terminator.source_info.span; @@ -380,14 +317,14 @@ fn check_terminator( | TerminatorKind::Resume | TerminatorKind::Unreachable => Ok(()), - TerminatorKind::Drop { place, .. } => check_place(tcx, *place, span, def_id, body), + TerminatorKind::Drop { place, .. } => check_place(tcx, *place, span, body), TerminatorKind::DropAndReplace { place, value, .. } => { - check_place(tcx, *place, span, def_id, body)?; - check_operand(tcx, value, span, def_id, body) + check_place(tcx, *place, span, body)?; + check_operand(tcx, value, span, body) } TerminatorKind::SwitchInt { discr, switch_ty: _, values: _, targets: _ } => { - check_operand(tcx, discr, span, def_id, body) + check_operand(tcx, discr, span, body) } TerminatorKind::Abort => Err((span, "abort is not stable in const fn".into())), @@ -405,15 +342,7 @@ fn check_terminator( } => { let fn_ty = func.ty(body, tcx); if let ty::FnDef(fn_def_id, _) = *fn_ty.kind() { - // Allow unstable const if we opt in by using #[allow_internal_unstable] - // on function or macro declaration. if !rustc_mir::const_eval::is_min_const_fn(tcx, fn_def_id) - && !rustc_mir::const_eval::is_unstable_const_fn(tcx, fn_def_id) - .map(|feature| { - span.allows_unstable(feature) - || lib_feature_allowed(tcx, def_id, feature) - }) - .unwrap_or(false) { return Err(( span, @@ -432,7 +361,6 @@ fn check_terminator( // transmutes in const fn before we add more hacks to this. if tcx.fn_sig(fn_def_id).abi() == RustIntrinsic && tcx.item_name(fn_def_id) == sym::transmute - && !feature_allowed(tcx, def_id, sym::const_fn_transmute) { return Err(( span, @@ -440,10 +368,10 @@ fn check_terminator( )); } - check_operand(tcx, func, span, fn_def_id, body)?; + check_operand(tcx, func, span, body)?; for arg in args { - check_operand(tcx, arg, span, fn_def_id, body)?; + check_operand(tcx, arg, span, body)?; } Ok(()) } else { @@ -452,7 +380,7 @@ fn check_terminator( } TerminatorKind::Assert { cond, expected: _, msg: _, target: _, cleanup: _ } => { - check_operand(tcx, cond, span, def_id, body) + check_operand(tcx, cond, span, body) } TerminatorKind::InlineAsm { .. } => { From dfe805c90298c5097dd7765e3d3f70c91c8df0f7 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 8 Sep 2020 13:44:41 +0200 Subject: [PATCH 0096/1222] Add option to pass a custom codegen backend from a driver --- src/driver.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index 47315fa64cd8..f4f2259cefd5 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -357,7 +357,7 @@ pub fn main() { args.extend(vec!["--sysroot".into(), sys_root]); }; - return rustc_driver::run_compiler(&args, &mut DefaultCallbacks, None, None); + return rustc_driver::run_compiler(&args, &mut DefaultCallbacks, None, None, None); } if orig_args.iter().any(|a| a == "--version" || a == "-V") { @@ -420,6 +420,6 @@ pub fn main() { let mut default = DefaultCallbacks; let callbacks: &mut (dyn rustc_driver::Callbacks + Send) = if clippy_enabled { &mut clippy } else { &mut default }; - rustc_driver::run_compiler(&args, callbacks, None, None) + rustc_driver::run_compiler(&args, callbacks, None, None, None) })) } From 467e33dd28cb76cb44b1b5ae1e73fd55b466a668 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 2 Oct 2020 11:34:14 -0700 Subject: [PATCH 0097/1222] Deprecate clippy lint --- clippy_lints/src/deprecated_lints.rs | 9 ++++ clippy_lints/src/drop_bounds.rs | 73 ---------------------------- clippy_lints/src/lib.rs | 9 ++-- clippy_lints/src/utils/paths.rs | 1 - src/lintlist/mod.rs | 7 --- tests/ui/deprecated.rs | 1 + tests/ui/deprecated.stderr | 8 ++- tests/ui/drop_bounds.rs | 8 --- tests/ui/drop_bounds.stderr | 16 ------ 9 files changed, 21 insertions(+), 111 deletions(-) delete mode 100644 clippy_lints/src/drop_bounds.rs delete mode 100644 tests/ui/drop_bounds.rs delete mode 100644 tests/ui/drop_bounds.stderr diff --git a/clippy_lints/src/deprecated_lints.rs b/clippy_lints/src/deprecated_lints.rs index c17a0e833305..c5884361dff9 100644 --- a/clippy_lints/src/deprecated_lints.rs +++ b/clippy_lints/src/deprecated_lints.rs @@ -163,3 +163,12 @@ declare_deprecated_lint! { pub REGEX_MACRO, "the regex! macro has been removed from the regex crate in 2018" } + +declare_deprecated_lint! { + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** This lint has been uplifted to rustc and is now called + /// `drop_bounds`. + pub DROP_BOUNDS, + "this lint has been uplifted to rustc and is now called `drop_bounds`" +} diff --git a/clippy_lints/src/drop_bounds.rs b/clippy_lints/src/drop_bounds.rs deleted file mode 100644 index ec3b6afa6300..000000000000 --- a/clippy_lints/src/drop_bounds.rs +++ /dev/null @@ -1,73 +0,0 @@ -use crate::utils::{match_def_path, paths, span_lint}; -use if_chain::if_chain; -use rustc_hir::{GenericBound, GenericParam, WhereBoundPredicate, WherePredicate}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for generics with `std::ops::Drop` as bounds. - /// - /// **Why is this bad?** `Drop` bounds do not really accomplish anything. - /// A type may have compiler-generated drop glue without implementing the - /// `Drop` trait itself. The `Drop` trait also only has one method, - /// `Drop::drop`, and that function is by fiat not callable in user code. - /// So there is really no use case for using `Drop` in trait bounds. - /// - /// The most likely use case of a drop bound is to distinguish between types - /// that have destructors and types that don't. Combined with specialization, - /// a naive coder would write an implementation that assumed a type could be - /// trivially dropped, then write a specialization for `T: Drop` that actually - /// calls the destructor. Except that doing so is not correct; String, for - /// example, doesn't actually implement Drop, but because String contains a - /// Vec, assuming it can be trivially dropped will leak memory. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// fn foo() {} - /// ``` - /// Could be written as: - /// ```rust - /// fn foo() {} - /// ``` - pub DROP_BOUNDS, - correctness, - "bounds of the form `T: Drop` are useless" -} - -const DROP_BOUNDS_SUMMARY: &str = "bounds of the form `T: Drop` are useless, \ - use `std::mem::needs_drop` to detect if a type has drop glue"; - -declare_lint_pass!(DropBounds => [DROP_BOUNDS]); - -impl<'tcx> LateLintPass<'tcx> for DropBounds { - fn check_generic_param(&mut self, cx: &LateContext<'tcx>, p: &'tcx GenericParam<'_>) { - for bound in p.bounds.iter() { - lint_bound(cx, bound); - } - } - fn check_where_predicate(&mut self, cx: &LateContext<'tcx>, p: &'tcx WherePredicate<'_>) { - if let WherePredicate::BoundPredicate(WhereBoundPredicate { bounds, .. }) = p { - for bound in *bounds { - lint_bound(cx, bound); - } - } - } -} - -fn lint_bound<'tcx>(cx: &LateContext<'tcx>, bound: &'tcx GenericBound<'_>) { - if_chain! { - if let GenericBound::Trait(t, _) = bound; - if let Some(def_id) = t.trait_ref.path.res.opt_def_id(); - if match_def_path(cx, def_id, &paths::DROP_TRAIT); - then { - span_lint( - cx, - DROP_BOUNDS, - t.span, - DROP_BOUNDS_SUMMARY - ); - } - } -} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index c3ff34e6e1ee..70efdaeb9c66 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -179,7 +179,6 @@ mod derive; mod doc; mod double_comparison; mod double_parens; -mod drop_bounds; mod drop_forget_ref; mod duration_subsec; mod else_if_without_else; @@ -478,6 +477,10 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: "clippy::regex_macro", "the regex! macro has been removed from the regex crate in 2018", ); + store.register_removed( + "clippy::drop_bounds", + "this lint has been uplifted to rustc and is now called `drop_bounds`", + ); // end deprecated lints, do not remove this comment, it’s used in `update_lints` // begin register lints, do not remove this comment, it’s used in `update_lints` @@ -532,7 +535,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &doc::NEEDLESS_DOCTEST_MAIN, &double_comparison::DOUBLE_COMPARISONS, &double_parens::DOUBLE_PARENS, - &drop_bounds::DROP_BOUNDS, &drop_forget_ref::DROP_COPY, &drop_forget_ref::DROP_REF, &drop_forget_ref::FORGET_COPY, @@ -959,7 +961,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_late_pass(|| box strings::StringLitAsBytes); store.register_late_pass(|| box derive::Derive); store.register_late_pass(|| box types::CharLitAsU8); - store.register_late_pass(|| box drop_bounds::DropBounds); store.register_late_pass(|| box get_last_with_len::GetLastWithLen); store.register_late_pass(|| box drop_forget_ref::DropForgetRef); store.register_late_pass(|| box empty_enum::EmptyEnum); @@ -1282,7 +1283,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&doc::NEEDLESS_DOCTEST_MAIN), LintId::of(&double_comparison::DOUBLE_COMPARISONS), LintId::of(&double_parens::DOUBLE_PARENS), - LintId::of(&drop_bounds::DROP_BOUNDS), LintId::of(&drop_forget_ref::DROP_COPY), LintId::of(&drop_forget_ref::DROP_REF), LintId::of(&drop_forget_ref::FORGET_COPY), @@ -1714,7 +1714,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&copies::IF_SAME_THEN_ELSE), LintId::of(&derive::DERIVE_HASH_XOR_EQ), LintId::of(&derive::DERIVE_ORD_XOR_PARTIAL_ORD), - LintId::of(&drop_bounds::DROP_BOUNDS), LintId::of(&drop_forget_ref::DROP_COPY), LintId::of(&drop_forget_ref::DROP_REF), LintId::of(&drop_forget_ref::FORGET_COPY), diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index 1583afad208a..be837a61dc07 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -31,7 +31,6 @@ pub const DISPLAY_FMT_METHOD: [&str; 4] = ["core", "fmt", "Display", "fmt"]; pub const DISPLAY_TRAIT: [&str; 3] = ["core", "fmt", "Display"]; pub const DOUBLE_ENDED_ITERATOR: [&str; 4] = ["core", "iter", "traits", "DoubleEndedIterator"]; pub const DROP: [&str; 3] = ["core", "mem", "drop"]; -pub const DROP_TRAIT: [&str; 4] = ["core", "ops", "drop", "Drop"]; pub const DURATION: [&str; 3] = ["core", "time", "Duration"]; pub const EARLY_CONTEXT: [&str; 4] = ["rustc", "lint", "context", "EarlyContext"]; pub const EXIT: [&str; 3] = ["std", "process", "exit"]; diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 9603023ed067..f6d529de9a3a 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -423,13 +423,6 @@ pub static ref ALL_LINTS: Vec = vec![ deprecation: None, module: "double_parens", }, - Lint { - name: "drop_bounds", - group: "correctness", - desc: "bounds of the form `T: Drop` are useless", - deprecation: None, - module: "drop_bounds", - }, Lint { name: "drop_copy", group: "correctness", diff --git a/tests/ui/deprecated.rs b/tests/ui/deprecated.rs index 3eefb232780f..9e32fe36ece4 100644 --- a/tests/ui/deprecated.rs +++ b/tests/ui/deprecated.rs @@ -8,5 +8,6 @@ #[warn(clippy::into_iter_on_array)] #[warn(clippy::unused_label)] #[warn(clippy::regex_macro)] +#[warn(clippy::drop_bounds)] fn main() {} diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr index a80e2bf31feb..d3400a7be09f 100644 --- a/tests/ui/deprecated.stderr +++ b/tests/ui/deprecated.stderr @@ -60,11 +60,17 @@ error: lint `clippy::regex_macro` has been removed: `the regex! macro has been r LL | #[warn(clippy::regex_macro)] | ^^^^^^^^^^^^^^^^^^^ +error: lint `clippy::drop_bounds` has been removed: `this lint has been uplifted to rustc and is now called `drop_bounds`` + --> $DIR/deprecated.rs:11:8 + | +LL | #[warn(clippy::drop_bounds)] + | ^^^^^^^^^^^^^^^^^^^ + error: lint `clippy::str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon` --> $DIR/deprecated.rs:1:8 | LL | #[warn(clippy::str_to_string)] | ^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 11 previous errors +error: aborting due to 12 previous errors diff --git a/tests/ui/drop_bounds.rs b/tests/ui/drop_bounds.rs deleted file mode 100644 index 6d6a9dc07839..000000000000 --- a/tests/ui/drop_bounds.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![allow(unused)] -fn foo() {} -fn bar() -where - T: Drop, -{ -} -fn main() {} diff --git a/tests/ui/drop_bounds.stderr b/tests/ui/drop_bounds.stderr deleted file mode 100644 index 8208c0ed7e39..000000000000 --- a/tests/ui/drop_bounds.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: bounds of the form `T: Drop` are useless, use `std::mem::needs_drop` to detect if a type has drop glue - --> $DIR/drop_bounds.rs:2:11 - | -LL | fn foo() {} - | ^^^^ - | - = note: `#[deny(clippy::drop_bounds)]` on by default - -error: bounds of the form `T: Drop` are useless, use `std::mem::needs_drop` to detect if a type has drop glue - --> $DIR/drop_bounds.rs:5:8 - | -LL | T: Drop, - | ^^^^ - -error: aborting due to 2 previous errors - From f54080f7f958fef18a07954237e594d685fa1659 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 15 Jun 2020 14:17:35 -0400 Subject: [PATCH 0098/1222] Prevent forbid from being ignored if overriden at the same level. That is, this changes `#[forbid(foo)] #[allow(foo)]` from allowing foo to forbidding foo. --- tests/ui/attrs.rs | 1 - tests/ui/attrs.stderr | 16 ++++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/tests/ui/attrs.rs b/tests/ui/attrs.rs index 908d063729f4..32685038067d 100644 --- a/tests/ui/attrs.rs +++ b/tests/ui/attrs.rs @@ -3,7 +3,6 @@ // Test that the whole restriction group is not enabled #![warn(clippy::restriction)] #![deny(clippy::restriction)] -#![forbid(clippy::restriction)] #![allow(clippy::missing_docs_in_private_items, clippy::panic, clippy::unreachable)] #[inline(always)] diff --git a/tests/ui/attrs.stderr b/tests/ui/attrs.stderr index ef4b89eaa6de..4324984dd60e 100644 --- a/tests/ui/attrs.stderr +++ b/tests/ui/attrs.stderr @@ -1,5 +1,5 @@ error: you have declared `#[inline(always)]` on `test_attr_lint`. This is usually a bad idea - --> $DIR/attrs.rs:9:1 + --> $DIR/attrs.rs:8:1 | LL | #[inline(always)] | ^^^^^^^^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | #[inline(always)] = note: `-D clippy::inline-always` implied by `-D warnings` error: the since field must contain a semver-compliant version - --> $DIR/attrs.rs:29:14 + --> $DIR/attrs.rs:28:14 | LL | #[deprecated(since = "forever")] | ^^^^^^^^^^^^^^^^^ @@ -15,7 +15,7 @@ LL | #[deprecated(since = "forever")] = note: `-D clippy::deprecated-semver` implied by `-D warnings` error: the since field must contain a semver-compliant version - --> $DIR/attrs.rs:32:14 + --> $DIR/attrs.rs:31:14 | LL | #[deprecated(since = "1")] | ^^^^^^^^^^^ @@ -37,13 +37,5 @@ LL | #![deny(clippy::restriction)] | = help: try enabling only the lints you really need -error: restriction lints are not meant to be all enabled - --> $DIR/attrs.rs:6:11 - | -LL | #![forbid(clippy::restriction)] - | ^^^^^^^^^^^^^^^^^^^ - | - = help: try enabling only the lints you really need - -error: aborting due to 6 previous errors +error: aborting due to 5 previous errors From 644820b37af1fa6ecac890858da4718ba0fdce01 Mon Sep 17 00:00:00 2001 From: Robin Schoonover Date: Sun, 4 Oct 2020 15:53:37 -0600 Subject: [PATCH 0099/1222] Change clippy's Constant back to refcount clone byte strings --- clippy_lints/src/consts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 0000d39263ed..062c9bd2d9e6 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -155,7 +155,7 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option>) -> Constant { match *lit { LitKind::Str(ref is, _) => Constant::Str(is.to_string()), LitKind::Byte(b) => Constant::Int(u128::from(b)), - LitKind::ByteStr(ref s) => Constant::Binary(Lrc::from(s.as_slice())), + LitKind::ByteStr(ref s) => Constant::Binary(Lrc::clone(s)), LitKind::Char(c) => Constant::Char(c), LitKind::Int(n, _) => Constant::Int(n), LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty { From 1a9a92555d82465ef00b1a05a49d61598d828991 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Sun, 4 Oct 2020 15:23:20 -0700 Subject: [PATCH 0100/1222] clippy: `(Body, DefId)` -> `Body` --- clippy_lints/src/missing_const_for_fn.rs | 2 +- clippy_lints/src/redundant_clone.rs | 2 +- clippy_lints/src/utils/qualify_min_const_fn.rs | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index e5f7cc511112..80da04fb7de9 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -118,7 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { let mir = cx.tcx.optimized_mir(def_id); - if let Err((span, err)) = is_min_const_fn(cx.tcx, def_id.to_def_id(), &mir) { + if let Err((span, err)) = is_min_const_fn(cx.tcx, &mir) { if rustc_mir::const_eval::is_min_const_fn(cx.tcx, def_id.to_def_id()) { cx.tcx.sess.span_err(span, &err); } diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 4d20a819804d..b4502c668dcb 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -86,7 +86,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone { let mir = cx.tcx.optimized_mir(def_id.to_def_id()); let maybe_storage_live_result = MaybeStorageLive - .into_engine(cx.tcx, mir, def_id.to_def_id()) + .into_engine(cx.tcx, mir) .pass_name("redundant_clone") .iterate_to_fixpoint() .into_results_cursor(mir); diff --git a/clippy_lints/src/utils/qualify_min_const_fn.rs b/clippy_lints/src/utils/qualify_min_const_fn.rs index 6809b1fa88d3..19d890b4554a 100644 --- a/clippy_lints/src/utils/qualify_min_const_fn.rs +++ b/clippy_lints/src/utils/qualify_min_const_fn.rs @@ -10,7 +10,8 @@ use std::borrow::Cow; type McfResult = Result<(), (Span, Cow<'static, str>)>; -pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -> McfResult { +pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>) -> McfResult { + let def_id = body.source.def_id(); let mut current = def_id; loop { let predicates = tcx.predicates_of(current); From c9a2166775a46b64131b95fae002d904c79e6573 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Tue, 30 Jun 2020 22:41:57 +0100 Subject: [PATCH 0101/1222] Fix tools --- clippy_lints/src/future_not_send.rs | 15 +++++++++++---- clippy_lints/src/methods/mod.rs | 6 ++++-- clippy_lints/src/utils/mod.rs | 5 +++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 2ab257ca88e3..d2a322e1223c 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -3,6 +3,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty::subst::Subst; use rustc_middle::ty::{Opaque, PredicateAtom::Trait}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; @@ -62,9 +63,10 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { } let ret_ty = utils::return_ty(cx, hir_id); if let Opaque(id, subst) = *ret_ty.kind() { - let preds = cx.tcx.predicates_of(id).instantiate(cx.tcx, subst); + let preds = cx.tcx.explicit_item_bounds(id); let mut is_future = false; - for p in preds.predicates { + for &(p, _span) in preds { + let p = p.subst(cx.tcx, subst); if let Some(trait_ref) = p.to_opt_poly_trait_ref() { if Some(trait_ref.def_id()) == cx.tcx.lang_items().future_trait() { is_future = true; @@ -90,8 +92,13 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { |db| { cx.tcx.infer_ctxt().enter(|infcx| { for FulfillmentError { obligation, .. } in send_errors { - infcx.maybe_note_obligation_cause_for_async_await(db, &obligation); - if let Trait(trait_pred, _) = obligation.predicate.skip_binders() { + infcx.maybe_note_obligation_cause_for_async_await( + db, + &obligation, + ); + if let Trait(trait_pred, _) = + obligation.predicate.skip_binders() + { db.note(&format!( "`{}` doesn't implement `{}`", trait_pred.self_ty(), diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index dadd0f8ebb7c..e0651f9ab5d6 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1667,8 +1667,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods { // if return type is impl trait, check the associated types if let ty::Opaque(def_id, _) = *ret_ty.kind() { // one of the associated types must be Self - for &(predicate, _span) in cx.tcx.predicates_of(def_id).predicates { - if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() { + for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) { + if let ty::PredicateAtom::Projection(projection_predicate) = + predicate.skip_binders() + { // walk the associated type and check for Self if contains_ty(projection_predicate.ty, self_ty) { return; diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 96d9905027b6..247effde19b9 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1285,9 +1285,10 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { }, ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { - for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates { + for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { if let ty::PredicateAtom::Trait(trait_predicate, _) = predicate.skip_binders() { - if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() { + if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() + { return true; } } From 509e226269afd7453d343b82d70da8d29a8a41a4 Mon Sep 17 00:00:00 2001 From: Darshan Kathiriya Date: Wed, 7 Oct 2020 09:09:59 -0300 Subject: [PATCH 0102/1222] Replace run_compiler with RunCompiler builder pattern. RunCompiler::new takes non-optional params, and optional params can be set using set_*field_name* method. finally `run` will forward all fields to `run_compiler`. --- src/driver.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index f4f2259cefd5..377f6d224463 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -357,7 +357,7 @@ pub fn main() { args.extend(vec!["--sysroot".into(), sys_root]); }; - return rustc_driver::run_compiler(&args, &mut DefaultCallbacks, None, None, None); + return rustc_driver::RunCompiler::new(&args, &mut DefaultCallbacks).run(); } if orig_args.iter().any(|a| a == "--version" || a == "-V") { @@ -420,6 +420,6 @@ pub fn main() { let mut default = DefaultCallbacks; let callbacks: &mut (dyn rustc_driver::Callbacks + Send) = if clippy_enabled { &mut clippy } else { &mut default }; - rustc_driver::run_compiler(&args, callbacks, None, None, None) + rustc_driver::RunCompiler::new(&args, callbacks).run() })) } From ff1f23a14994b2b8c68a9385888f48f5ef79d617 Mon Sep 17 00:00:00 2001 From: hosseind75 Date: Sat, 19 Sep 2020 17:51:24 +0430 Subject: [PATCH 0103/1222] ICEs should print the top of the query stack --- src/driver.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index f4f2259cefd5..c88dffc88f42 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -274,12 +274,7 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { handler.note_without_error(¬e); } - // If backtraces are enabled, also print the query stack - let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0"); - - if backtrace { - TyCtxt::try_print_query_stack(&handler); - } + TyCtxt::try_print_query_stack(&handler, Some(2)); } fn toolchain_path(home: Option, toolchain: Option) -> Option { From a948642edaeffbc5d6586c35a58169b8f1a12f9a Mon Sep 17 00:00:00 2001 From: hosseind75 Date: Sat, 19 Sep 2020 18:37:58 +0430 Subject: [PATCH 0104/1222] run full query stack print just when RUST_BACKTRACE is set --- src/driver.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/driver.rs b/src/driver.rs index c88dffc88f42..0b324775b0d1 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -274,7 +274,10 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { handler.note_without_error(¬e); } - TyCtxt::try_print_query_stack(&handler, Some(2)); + // If backtraces are enabled, also print the query stack + let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0"); + + TyCtxt::try_print_query_stack(&handler, Some(2), Some(backtrace)); } fn toolchain_path(home: Option, toolchain: Option) -> Option { From 46f8c5a093d5e6abe12e65ce13d24c4e3f5e1cda Mon Sep 17 00:00:00 2001 From: hosseind75 Date: Fri, 25 Sep 2020 19:55:32 +0330 Subject: [PATCH 0105/1222] fix clippy custom_ice_message test --- tests/ui/custom_ice_message.stderr | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/ui/custom_ice_message.stderr b/tests/ui/custom_ice_message.stderr index a9a65a38c109..784ab9e5c707 100644 --- a/tests/ui/custom_ice_message.stderr +++ b/tests/ui/custom_ice_message.stderr @@ -9,3 +9,5 @@ note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy note: Clippy version: foo +query stack during panic: +we're just showing a limited slice of the query stack \ No newline at end of file From 3d1079061c478ade753aefc9675b81463b69c76f Mon Sep 17 00:00:00 2001 From: hosseind75 Date: Mon, 28 Sep 2020 22:07:31 +0330 Subject: [PATCH 0106/1222] add new line --- tests/ui/custom_ice_message.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/custom_ice_message.stderr b/tests/ui/custom_ice_message.stderr index 784ab9e5c707..87cdb7a8b99d 100644 --- a/tests/ui/custom_ice_message.stderr +++ b/tests/ui/custom_ice_message.stderr @@ -10,4 +10,4 @@ note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy note: Clippy version: foo query stack during panic: -we're just showing a limited slice of the query stack \ No newline at end of file +we're just showing a limited slice of the query stack From 828624a0e9c6138f2807e176ce5114f145961383 Mon Sep 17 00:00:00 2001 From: hosseind75 Date: Tue, 29 Sep 2020 18:14:07 +0330 Subject: [PATCH 0107/1222] rebase with master --- src/driver.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/driver.rs b/src/driver.rs index 0b324775b0d1..bf9110b43492 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -277,7 +277,9 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { // If backtraces are enabled, also print the query stack let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0"); - TyCtxt::try_print_query_stack(&handler, Some(2), Some(backtrace)); + let num_frames = if backtrace { None } else { Some(2) }; + + TyCtxt::try_print_query_stack(&handler, num_frames); } fn toolchain_path(home: Option, toolchain: Option) -> Option { From 078c9d34196795caa2065681e67291c8bf1e7344 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sat, 10 Oct 2020 17:36:04 +0200 Subject: [PATCH 0108/1222] Refactor how SwitchInt stores jump targets --- clippy_lints/src/utils/qualify_min_const_fn.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_lints/src/utils/qualify_min_const_fn.rs b/clippy_lints/src/utils/qualify_min_const_fn.rs index 1b4f20342729..7cb7d0a26b65 100644 --- a/clippy_lints/src/utils/qualify_min_const_fn.rs +++ b/clippy_lints/src/utils/qualify_min_const_fn.rs @@ -282,7 +282,6 @@ fn check_terminator(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, terminator: &Termin TerminatorKind::SwitchInt { discr, switch_ty: _, - values: _, targets: _, } => check_operand(tcx, discr, span, body), From b31c1db23fa05875ca72cda7e844ffa50f8af25f Mon Sep 17 00:00:00 2001 From: hosseind88 Date: Wed, 14 Oct 2020 18:19:26 +0330 Subject: [PATCH 0109/1222] fix stderr file of clippy/custom_ice_message test --- tests/ui/custom_ice_message.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/custom_ice_message.stderr b/tests/ui/custom_ice_message.stderr index 87cdb7a8b99d..a1b8e2ee162c 100644 --- a/tests/ui/custom_ice_message.stderr +++ b/tests/ui/custom_ice_message.stderr @@ -10,4 +10,4 @@ note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy note: Clippy version: foo query stack during panic: -we're just showing a limited slice of the query stack +end of query stack From e96e1986d8366c90c3080d27cbea5d9b233203de Mon Sep 17 00:00:00 2001 From: est31 Date: Wed, 14 Oct 2020 18:42:13 +0200 Subject: [PATCH 0110/1222] Remove rustc_session::config::Config The wrapper type led to tons of target.target across the compiler. Its ptr_width field isn't required any more, as target_pointer_width is already present in parsed form. --- clippy_lints/src/trivially_copy_pass_by_ref.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/trivially_copy_pass_by_ref.rs b/clippy_lints/src/trivially_copy_pass_by_ref.rs index 1f06d2dbe914..d92eb86fb2eb 100644 --- a/clippy_lints/src/trivially_copy_pass_by_ref.rs +++ b/clippy_lints/src/trivially_copy_pass_by_ref.rs @@ -9,10 +9,10 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId, ItemKind, MutTy, Mutability, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; -use rustc_session::config::Config as SessionConfig; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; use rustc_target::abi::LayoutOf; +use rustc_target::spec::Target; use rustc_target::spec::abi::Abi; declare_clippy_lint! { @@ -60,9 +60,9 @@ pub struct TriviallyCopyPassByRef { } impl<'tcx> TriviallyCopyPassByRef { - pub fn new(limit: Option, target: &SessionConfig) -> Self { + pub fn new(limit: Option, target: &Target) -> Self { let limit = limit.unwrap_or_else(|| { - let bit_width = u64::from(target.ptr_width); + let bit_width = u64::from(target.pointer_width); // Cap the calculated bit width at 32-bits to reduce // portability problems between 32 and 64-bit targets let bit_width = cmp::min(bit_width, 32); From 6cc5825f4531c6cd9ad141b7982d1343ce37ddf9 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 6 Oct 2020 18:51:31 -0300 Subject: [PATCH 0111/1222] Handle ExprKind::ConstBlock on clippy --- clippy_lints/src/loops.rs | 1 + clippy_lints/src/utils/author.rs | 5 +++++ clippy_lints/src/utils/eager_or_lazy.rs | 2 +- clippy_lints/src/utils/hir_utils.rs | 3 +++ clippy_lints/src/utils/inspector.rs | 5 +++++ clippy_lints/src/utils/sugg.rs | 2 ++ 6 files changed, 17 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 61b63597b163..4fdcaca8f603 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -742,6 +742,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { | ExprKind::Closure(_, _, _, _, _) | ExprKind::LlvmInlineAsm(_) | ExprKind::Path(_) + | ExprKind::ConstBlock(_) | ExprKind::Lit(_) | ExprKind::Err => NeverLoopResult::Otherwise, } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 6eda6d1fa834..89425437eeea 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -506,6 +506,11 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { println!(" if {}.len() == {};", fields_pat, fields.len()); println!(" // unimplemented: field checks"); }, + ExprKind::ConstBlock(_) => { + let value_pat = self.next("value"); + println!("Const({})", value_pat); + self.current = value_pat; + }, // FIXME: compute length (needs type info) ExprKind::Repeat(ref value, _) => { let value_pat = self.next("value"); diff --git a/clippy_lints/src/utils/eager_or_lazy.rs b/clippy_lints/src/utils/eager_or_lazy.rs index 6938d9971d96..27e9567740d1 100644 --- a/clippy_lints/src/utils/eager_or_lazy.rs +++ b/clippy_lints/src/utils/eager_or_lazy.rs @@ -23,7 +23,7 @@ use rustc_middle::hir::map::Map; /// This function is named so to stress that it isn't exhaustive and returns FNs. fn identify_some_pure_patterns(expr: &Expr<'_>) -> bool { match expr.kind { - ExprKind::Lit(..) | ExprKind::Path(..) | ExprKind::Field(..) => true, + ExprKind::Lit(..) | ExprKind::ConstBlock(..) | ExprKind::Path(..) | ExprKind::Field(..) => true, ExprKind::AddrOf(_, _, addr_of_expr) => identify_some_pure_patterns(addr_of_expr), ExprKind::Tup(tup_exprs) => tup_exprs.iter().all(|expr| identify_some_pure_patterns(expr)), ExprKind::Struct(_, fields, expr) => { diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index c7263f48965a..c9e639e8728f 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -559,6 +559,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_name(path.ident.name); self.hash_exprs(args); }, + ExprKind::ConstBlock(ref l_id) => { + self.hash_body(l_id.body); + }, ExprKind::Repeat(ref e, ref l_id) => { self.hash_expr(e); self.hash_body(l_id.body); diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 4701a3f26e6f..93bd82994466 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -338,6 +338,11 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { print_expr(cx, base, indent + 1); } }, + hir::ExprKind::ConstBlock(ref anon_const) => { + println!("{}ConstBlock", ind); + println!("{}anon_const:", ind); + print_expr(cx, &cx.tcx.hir().body(anon_const.body).value, indent + 1); + }, hir::ExprKind::Repeat(ref val, ref anon_const) => { println!("{}Repeat", ind); println!("{}value:", ind); diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index ec8b7e59b597..a2a1d109c9ac 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -110,6 +110,7 @@ impl<'a> Sugg<'a> { | hir::ExprKind::Index(..) | hir::ExprKind::InlineAsm(..) | hir::ExprKind::LlvmInlineAsm(..) + | hir::ExprKind::ConstBlock(..) | hir::ExprKind::Lit(..) | hir::ExprKind::Loop(..) | hir::ExprKind::MethodCall(..) @@ -157,6 +158,7 @@ impl<'a> Sugg<'a> { | ast::ExprKind::Index(..) | ast::ExprKind::InlineAsm(..) | ast::ExprKind::LlvmInlineAsm(..) + | ast::ExprKind::ConstBlock(..) | ast::ExprKind::Lit(..) | ast::ExprKind::Loop(..) | ast::ExprKind::MacCall(..) From 447dd565cbde8729000c0c55c128d9c631ac1e57 Mon Sep 17 00:00:00 2001 From: Jacob Hughes Date: Sat, 17 Oct 2020 13:45:40 -0400 Subject: [PATCH 0112/1222] Appease the almightly lord clippy, hallowed be thy name --- clippy_lints/src/utils/paths.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index 277da9d3f3a2..5e769c690a69 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -14,7 +14,7 @@ pub const BINARY_HEAP: [&str; 4] = ["alloc", "collections", "binary_heap", "Bina pub const BORROW_TRAIT: [&str; 3] = ["core", "borrow", "Borrow"]; pub const BOX: [&str; 3] = ["alloc", "boxed", "Box"]; pub const BTREEMAP: [&str; 5] = ["alloc", "collections", "btree", "map", "BTreeMap"]; -pub const BTREEMAP_ENTRY: [&str; 5] = ["alloc", "collections", "btree", "map", "Entry"]; +pub const BTREEMAP_ENTRY: [&str; 6] = ["alloc", "collections", "btree", "map", "entry", "Entry"]; pub const BTREESET: [&str; 5] = ["alloc", "collections", "btree", "set", "BTreeSet"]; pub const CLONE_TRAIT: [&str; 3] = ["core", "clone", "Clone"]; pub const CLONE_TRAIT_METHOD: [&str; 4] = ["core", "clone", "Clone", "clone"]; From a73f61631695fcff98c4522780b5b22078246c56 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 22 Oct 2020 13:23:14 +0100 Subject: [PATCH 0113/1222] Fix clippy tests --- tests/ui/auxiliary/proc_macro_attr.rs | 1 + tests/ui/auxiliary/proc_macro_derive.rs | 1 + tests/ui/crashes/auxiliary/proc_macro_crash.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/tests/ui/auxiliary/proc_macro_attr.rs b/tests/ui/auxiliary/proc_macro_attr.rs index de670cdfc31f..e370a98df1ac 100644 --- a/tests/ui/auxiliary/proc_macro_attr.rs +++ b/tests/ui/auxiliary/proc_macro_attr.rs @@ -3,6 +3,7 @@ #![crate_type = "proc-macro"] #![feature(repr128, proc_macro_hygiene, proc_macro_quote, box_patterns)] +#![allow(incomplete_features)] #![allow(clippy::useless_conversion)] extern crate proc_macro; diff --git a/tests/ui/auxiliary/proc_macro_derive.rs b/tests/ui/auxiliary/proc_macro_derive.rs index 3df8be6c2323..cd5a5ae0aa75 100644 --- a/tests/ui/auxiliary/proc_macro_derive.rs +++ b/tests/ui/auxiliary/proc_macro_derive.rs @@ -3,6 +3,7 @@ #![crate_type = "proc-macro"] #![feature(repr128, proc_macro_quote)] +#![allow(incomplete_features)] extern crate proc_macro; diff --git a/tests/ui/crashes/auxiliary/proc_macro_crash.rs b/tests/ui/crashes/auxiliary/proc_macro_crash.rs index 619d11cefc46..ed8e7a708a5e 100644 --- a/tests/ui/crashes/auxiliary/proc_macro_crash.rs +++ b/tests/ui/crashes/auxiliary/proc_macro_crash.rs @@ -6,6 +6,7 @@ // contain a proc-macro. #![feature(repr128)] +#![allow(incomplete_features)] #![crate_type = "proc-macro"] extern crate proc_macro; From 63825740731f686b78e15e92e99fdab920973bff Mon Sep 17 00:00:00 2001 From: Eduardo Broto Date: Fri, 23 Oct 2020 23:45:37 +0200 Subject: [PATCH 0114/1222] Remove duplicate import of `Target` --- clippy_lints/src/trivially_copy_pass_by_ref.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_lints/src/trivially_copy_pass_by_ref.rs b/clippy_lints/src/trivially_copy_pass_by_ref.rs index c2c86aa474ad..e90ea0fc200a 100644 --- a/clippy_lints/src/trivially_copy_pass_by_ref.rs +++ b/clippy_lints/src/trivially_copy_pass_by_ref.rs @@ -12,7 +12,6 @@ use rustc_middle::ty; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; use rustc_target::abi::LayoutOf; -use rustc_target::spec::Target; use rustc_target::spec::abi::Abi; use rustc_target::spec::Target; From e4eade29d615fe56c3cd2633fd2f1ee31ded8fc6 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Fri, 23 Oct 2020 18:17:00 -0400 Subject: [PATCH 0115/1222] Fix inconsistencies in handling of inert attributes on statements When the 'early' and 'late' visitors visit an attribute target, they activate any lint attributes (e.g. `#[allow]`) that apply to it. This can affect warnings emitted on sibiling attributes. For example, the following code does not produce an `unused_attributes` for `#[inline]`, since the sibiling `#[allow(unused_attributes)]` suppressed the warning. ```rust trait Foo { #[allow(unused_attributes)] #[inline] fn first(); #[inline] #[allow(unused_attributes)] fn second(); } ``` However, we do not do this for statements - instead, the lint attributes only become active when we visit the struct nested inside `StmtKind` (e.g. `Item`). Currently, this is difficult to observe due to another issue - the `HasAttrs` impl for `StmtKind` ignores attributes for `StmtKind::Item`. As a result, the `unused_doc_comments` lint will never see attributes on item statements. This commit makes two interrelated fixes to the handling of inert (non-proc-macro) attributes on statements: * The `HasAttr` impl for `StmtKind` now returns attributes for `StmtKind::Item`, treating it just like every other `StmtKind` variant. The only place relying on the old behavior was macro which has been updated to explicitly ignore attributes on item statements. This allows the `unused_doc_comments` lint to fire for item statements. * The `early` and `late` lint visitors now activate lint attributes when invoking the callback for `Stmt`. This ensures that a lint attribute (e.g. `#[allow(unused_doc_comments)]`) can be applied to sibiling attributes on an item statement. For now, the `unused_doc_comments` lint is explicitly disabled on item statements, which preserves the current behavior. The exact locatiosn where this lint should fire are being discussed in PR #78306 --- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/utils/inspector.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 89425437eeea..7250de3a41c0 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -130,7 +130,7 @@ impl<'tcx> LateLintPass<'tcx> for Author { } fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx hir::Stmt<'_>) { - if !has_attr(cx.sess(), stmt.kind.attrs()) { + if !has_attr(cx.sess(), stmt.kind.attrs(|id| cx.tcx.hir().item(id.id))) { return; } prelude(); diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 93bd82994466..4fbfb3be32cb 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -109,7 +109,7 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector { } fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx hir::Stmt<'_>) { - if !has_attr(cx.sess(), stmt.kind.attrs()) { + if !has_attr(cx.sess(), stmt.kind.attrs(|id| cx.tcx.hir().item(id.id))) { return; } match stmt.kind { From bc749cf2348847287f3da2af822e3d30470aa15d Mon Sep 17 00:00:00 2001 From: Nathan Whitaker Date: Tue, 22 Sep 2020 12:23:22 -0400 Subject: [PATCH 0116/1222] Remove lint from clippy --- .github/driver.sh | 6 ++-- clippy_lints/src/lib.rs | 3 -- clippy_lints/src/methods/mod.rs | 56 --------------------------------- clippy_lints/src/utils/paths.rs | 1 - src/lintlist/mod.rs | 7 ----- tests/ui/cstring.rs | 24 -------------- tests/ui/cstring.stderr | 46 --------------------------- 7 files changed, 3 insertions(+), 140 deletions(-) delete mode 100644 tests/ui/cstring.rs delete mode 100644 tests/ui/cstring.stderr diff --git a/.github/driver.sh b/.github/driver.sh index 2c17c4203ae5..fc4dca5042b2 100644 --- a/.github/driver.sh +++ b/.github/driver.sh @@ -22,9 +22,9 @@ unset CARGO_MANIFEST_DIR # Run a lint and make sure it produces the expected output. It's also expected to exit with code 1 # FIXME: How to match the clippy invocation in compile-test.rs? -./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/cstring.rs 2> cstring.stderr && exit 1 -sed -e "s,tests/ui,\$DIR," -e "/= help/d" cstring.stderr > normalized.stderr -diff normalized.stderr tests/ui/cstring.stderr +./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/cast.rs 2> cast.stderr && exit 1 +sed -e "s,tests/ui,\$DIR," -e "/= help/d" cast.stderr > normalized.stderr +diff normalized.stderr tests/ui/cast.stderr # make sure "clippy-driver --rustc --arg" and "rustc --arg" behave the same diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index d4d2f92a6a69..b5ca63cefec4 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -707,7 +707,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &methods::SKIP_WHILE_NEXT, &methods::STRING_EXTEND_CHARS, &methods::SUSPICIOUS_MAP, - &methods::TEMPORARY_CSTRING_AS_PTR, &methods::UNINIT_ASSUMED_INIT, &methods::UNNECESSARY_FILTER_MAP, &methods::UNNECESSARY_FOLD, @@ -1417,7 +1416,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&methods::SKIP_WHILE_NEXT), LintId::of(&methods::STRING_EXTEND_CHARS), LintId::of(&methods::SUSPICIOUS_MAP), - LintId::of(&methods::TEMPORARY_CSTRING_AS_PTR), LintId::of(&methods::UNINIT_ASSUMED_INIT), LintId::of(&methods::UNNECESSARY_FILTER_MAP), LintId::of(&methods::UNNECESSARY_FOLD), @@ -1765,7 +1763,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&mem_replace::MEM_REPLACE_WITH_UNINIT), LintId::of(&methods::CLONE_DOUBLE_REF), LintId::of(&methods::ITERATOR_STEP_BY_ZERO), - LintId::of(&methods::TEMPORARY_CSTRING_AS_PTR), LintId::of(&methods::UNINIT_ASSUMED_INIT), LintId::of(&methods::ZST_OFFSET), LintId::of(&minmax::MIN_MAX), diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index c0824bacbc73..d250bfd71e93 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -798,40 +798,6 @@ declare_clippy_lint! { "using a single-character str where a char could be used, e.g., `_.split(\"x\")`" } -declare_clippy_lint! { - /// **What it does:** Checks for getting the inner pointer of a temporary - /// `CString`. - /// - /// **Why is this bad?** The inner pointer of a `CString` is only valid as long - /// as the `CString` is alive. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # use std::ffi::CString; - /// # fn call_some_ffi_func(_: *const i8) {} - /// # - /// let c_str = CString::new("foo").unwrap().as_ptr(); - /// unsafe { - /// call_some_ffi_func(c_str); - /// } - /// ``` - /// Here `c_str` points to a freed address. The correct use would be: - /// ```rust - /// # use std::ffi::CString; - /// # fn call_some_ffi_func(_: *const i8) {} - /// # - /// let c_str = CString::new("foo").unwrap(); - /// unsafe { - /// call_some_ffi_func(c_str.as_ptr()); - /// } - /// ``` - pub TEMPORARY_CSTRING_AS_PTR, - correctness, - "getting the inner pointer of a temporary `CString`" -} - declare_clippy_lint! { /// **What it does:** Checks for calling `.step_by(0)` on iterators which panics. /// @@ -1406,7 +1372,6 @@ declare_lint_pass!(Methods => [ SINGLE_CHAR_PATTERN, SINGLE_CHAR_PUSH_STR, SEARCH_IS_SOME, - TEMPORARY_CSTRING_AS_PTR, FILTER_NEXT, SKIP_WHILE_NEXT, FILTER_MAP, @@ -1490,7 +1455,6 @@ impl<'tcx> LateLintPass<'tcx> for Methods { lint_search_is_some(cx, expr, "rposition", arg_lists[1], arg_lists[0], method_spans[1]) }, ["extend", ..] => lint_extend(cx, expr, arg_lists[0]), - ["as_ptr", "unwrap" | "expect"] => lint_cstring_as_ptr(cx, expr, &arg_lists[1][0], &arg_lists[0][0]), ["nth", "iter"] => lint_iter_nth(cx, expr, &arg_lists, false), ["nth", "iter_mut"] => lint_iter_nth(cx, expr, &arg_lists, true), ["nth", ..] => lint_iter_nth_zero(cx, expr, arg_lists[0]), @@ -2207,26 +2171,6 @@ fn lint_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_> } } -fn lint_cstring_as_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, source: &hir::Expr<'_>, unwrap: &hir::Expr<'_>) { - if_chain! { - let source_type = cx.typeck_results().expr_ty(source); - if let ty::Adt(def, substs) = source_type.kind(); - if cx.tcx.is_diagnostic_item(sym!(result_type), def.did); - if match_type(cx, substs.type_at(0), &paths::CSTRING); - then { - span_lint_and_then( - cx, - TEMPORARY_CSTRING_AS_PTR, - expr.span, - "you are getting the inner pointer of a temporary `CString`", - |diag| { - diag.note("that pointer will be invalid outside this expression"); - diag.span_help(unwrap.span, "assign the `CString` to a variable to extend its lifetime"); - }); - } - } -} - fn lint_iter_cloned_collect<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, iter_args: &'tcx [hir::Expr<'_>]) { if_chain! { if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym!(vec_type)); diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index 5e769c690a69..7566da80982a 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -21,7 +21,6 @@ pub const CLONE_TRAIT_METHOD: [&str; 4] = ["core", "clone", "Clone", "clone"]; pub const CMP_MAX: [&str; 3] = ["core", "cmp", "max"]; pub const CMP_MIN: [&str; 3] = ["core", "cmp", "min"]; pub const COW: [&str; 3] = ["alloc", "borrow", "Cow"]; -pub const CSTRING: [&str; 4] = ["std", "ffi", "c_str", "CString"]; pub const CSTRING_AS_C_STR: [&str; 5] = ["std", "ffi", "c_str", "CString", "as_c_str"]; pub const DEFAULT_TRAIT: [&str; 3] = ["core", "default", "Default"]; pub const DEFAULT_TRAIT_METHOD: [&str; 4] = ["core", "default", "Default", "default"]; diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 6301d623a2b1..dcbb8a6a31da 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -2258,13 +2258,6 @@ vec![ deprecation: None, module: "temporary_assignment", }, - Lint { - name: "temporary_cstring_as_ptr", - group: "correctness", - desc: "getting the inner pointer of a temporary `CString`", - deprecation: None, - module: "methods", - }, Lint { name: "to_digit_is_some", group: "style", diff --git a/tests/ui/cstring.rs b/tests/ui/cstring.rs deleted file mode 100644 index 6cdd6b4ff6e7..000000000000 --- a/tests/ui/cstring.rs +++ /dev/null @@ -1,24 +0,0 @@ -#![deny(clippy::temporary_cstring_as_ptr)] - -fn main() {} - -fn temporary_cstring() { - use std::ffi::CString; - - CString::new("foo").unwrap().as_ptr(); - CString::new("foo").expect("dummy").as_ptr(); -} - -mod issue4375 { - use std::ffi::CString; - use std::os::raw::c_char; - - extern "C" { - fn foo(data: *const c_char); - } - - pub fn bar(v: &[u8]) { - let cstr = CString::new(v); - unsafe { foo(cstr.unwrap().as_ptr()) } - } -} diff --git a/tests/ui/cstring.stderr b/tests/ui/cstring.stderr deleted file mode 100644 index 87cb29be5775..000000000000 --- a/tests/ui/cstring.stderr +++ /dev/null @@ -1,46 +0,0 @@ -error: you are getting the inner pointer of a temporary `CString` - --> $DIR/cstring.rs:8:5 - | -LL | CString::new("foo").unwrap().as_ptr(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/cstring.rs:1:9 - | -LL | #![deny(clippy::temporary_cstring_as_ptr)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: that pointer will be invalid outside this expression -help: assign the `CString` to a variable to extend its lifetime - --> $DIR/cstring.rs:8:5 - | -LL | CString::new("foo").unwrap().as_ptr(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: you are getting the inner pointer of a temporary `CString` - --> $DIR/cstring.rs:9:5 - | -LL | CString::new("foo").expect("dummy").as_ptr(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: that pointer will be invalid outside this expression -help: assign the `CString` to a variable to extend its lifetime - --> $DIR/cstring.rs:9:5 - | -LL | CString::new("foo").expect("dummy").as_ptr(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: you are getting the inner pointer of a temporary `CString` - --> $DIR/cstring.rs:22:22 - | -LL | unsafe { foo(cstr.unwrap().as_ptr()) } - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = note: that pointer will be invalid outside this expression -help: assign the `CString` to a variable to extend its lifetime - --> $DIR/cstring.rs:22:22 - | -LL | unsafe { foo(cstr.unwrap().as_ptr()) } - | ^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - From d55a694fbc4259acad2eb3da88a143c44c15ed79 Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Wed, 21 Oct 2020 14:27:32 +0200 Subject: [PATCH 0117/1222] TypeVisitor: use `ControlFlow` in clippy --- clippy_lints/src/lib.rs | 1 + clippy_lints/src/redundant_clone.rs | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 2d3749698460..e97fa543a093 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -11,6 +11,7 @@ #![feature(or_patterns)] #![feature(rustc_private)] #![feature(stmt_expr_attributes)] +#![feature(control_flow_enum)] #![recursion_limit = "512"] #![cfg_attr(feature = "deny-warnings", deny(warnings))] #![allow(clippy::missing_docs_in_private_items, clippy::must_use_candidate)] diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index b4502c668dcb..7f6627358a18 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -18,6 +18,7 @@ use rustc_mir::dataflow::{Analysis, AnalysisDomain, GenKill, GenKillAnalysis, Re use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::{BytePos, Span}; use std::convert::TryFrom; +use std::ops::ControlFlow; macro_rules! unwrap_or_continue { ($x:expr) => { @@ -517,7 +518,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { self.possible_borrower.add(borrowed.local, lhs); }, other => { - if !ContainsRegion.visit_ty(place.ty(&self.body.local_decls, self.cx.tcx).ty) { + if ContainsRegion.visit_ty(place.ty(&self.body.local_decls, self.cx.tcx).ty) == ControlFlow::CONTINUE { return; } rvalue_locals(other, |rhs| { @@ -539,7 +540,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { // If the call returns something with lifetimes, // let's conservatively assume the returned value contains lifetime of all the arguments. // For example, given `let y: Foo<'a> = foo(x)`, `y` is considered to be a possible borrower of `x`. - if !ContainsRegion.visit_ty(&self.body.local_decls[*dest].ty) { + if ContainsRegion.visit_ty(&self.body.local_decls[*dest].ty) == ControlFlow::CONTINUE { return; } @@ -558,8 +559,8 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { struct ContainsRegion; impl TypeVisitor<'_> for ContainsRegion { - fn visit_region(&mut self, _: ty::Region<'_>) -> bool { - true + fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow<(), ()> { + ControlFlow::BREAK } } From ae66dd1ec0414fe57563c0023229b289bc95ca5e Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Thu, 22 Oct 2020 10:20:24 +0200 Subject: [PATCH 0118/1222] Use `ControlFlow::is{break,continue}` --- clippy_lints/src/redundant_clone.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 7f6627358a18..ae9ac13d7e94 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -518,7 +518,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { self.possible_borrower.add(borrowed.local, lhs); }, other => { - if ContainsRegion.visit_ty(place.ty(&self.body.local_decls, self.cx.tcx).ty) == ControlFlow::CONTINUE { + if ContainsRegion.visit_ty(place.ty(&self.body.local_decls, self.cx.tcx).ty).is_continue() { return; } rvalue_locals(other, |rhs| { @@ -540,7 +540,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { // If the call returns something with lifetimes, // let's conservatively assume the returned value contains lifetime of all the arguments. // For example, given `let y: Foo<'a> = foo(x)`, `y` is considered to be a possible borrower of `x`. - if ContainsRegion.visit_ty(&self.body.local_decls[*dest].ty) == ControlFlow::CONTINUE { + if ContainsRegion.visit_ty(&self.body.local_decls[*dest].ty).is_continue() { return; } From 99457b15770ad139e0cb53caf865f1f8343fa1ea Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Sun, 25 Oct 2020 11:50:56 +0100 Subject: [PATCH 0119/1222] Remove implicit `Continue` type --- clippy_lints/src/redundant_clone.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index ae9ac13d7e94..ae3b0a037542 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -559,7 +559,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { struct ContainsRegion; impl TypeVisitor<'_> for ContainsRegion { - fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow<(), ()> { + fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow<()> { ControlFlow::BREAK } } From 173b8c0ec23096fe6c2d06a88e897c5b12de5b64 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Fri, 30 Oct 2020 21:41:16 -0400 Subject: [PATCH 0120/1222] Update Clippy path to `Lint` --- clippy_lints/src/utils/paths.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index cd72fdd61fd3..736a531eda65 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -59,7 +59,7 @@ pub const IO_WRITE: [&str; 3] = ["std", "io", "Write"]; pub const ITERATOR: [&str; 5] = ["core", "iter", "traits", "iterator", "Iterator"]; pub const LATE_CONTEXT: [&str; 2] = ["rustc_lint", "LateContext"]; pub const LINKED_LIST: [&str; 4] = ["alloc", "collections", "linked_list", "LinkedList"]; -pub const LINT: [&str; 3] = ["rustc_session", "lint", "Lint"]; +pub const LINT: [&str; 2] = ["rustc_lint_defs", "Lint"]; pub const MEM_DISCRIMINANT: [&str; 3] = ["core", "mem", "discriminant"]; pub const MEM_FORGET: [&str; 3] = ["core", "mem", "forget"]; pub const MEM_MANUALLY_DROP: [&str; 4] = ["core", "mem", "manually_drop", "ManuallyDrop"]; From 1149dd2c8253efbd7218cded0e1ddc46c870fec1 Mon Sep 17 00:00:00 2001 From: Dhruv Jauhar Date: Sun, 1 Nov 2020 02:15:22 -0500 Subject: [PATCH 0121/1222] Provide diagnostic suggestion in ExprUseVisitor Delegate The [Delegate trait](https://github.com/rust-lang/rust/blob/981346fc07dd5ef414c5b1b21999f7604cece006/compiler/rustc_typeck/src/expr_use_visitor.rs#L28-L38) currently use `PlaceWithHirId` which is composed of Hir `Place` and the corresponding expression id. Even though this is an accurate way of expressing how a Place is used, it can cause confusion during diagnostics. Eg: ``` let arr : [String; 5]; let [a, ...] = arr; ^^^ E1 ^^^ = ^^E2^^ ``` Here `arr` is moved because of the binding created E1. However, when we point to E1 in diagnostics with the message `arr` was moved, it can be confusing. Rather we would like to report E2 to the user. Closes: https://github.com/rust-lang/project-rfc-2229/issues/20 --- clippy_lints/src/escape.rs | 6 +++--- clippy_lints/src/loops.rs | 14 +++++++------- clippy_lints/src/needless_pass_by_value.rs | 6 +++--- clippy_lints/src/utils/usage.rs | 6 +++--- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 8b0229125738..eebf4a81a871 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -116,7 +116,7 @@ fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool { } impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { - fn consume(&mut self, cmt: &PlaceWithHirId<'tcx>, mode: ConsumeMode) { + fn consume(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, mode: ConsumeMode) { if cmt.place.projections.is_empty() { if let PlaceBase::Local(lid) = cmt.place.base { if let ConsumeMode::Move = mode { @@ -136,7 +136,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { } } - fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: ty::BorrowKind) { + fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) { if cmt.place.projections.is_empty() { if let PlaceBase::Local(lid) = cmt.place.base { self.set.remove(&lid); @@ -144,7 +144,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { } } - fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>) { + fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) { if cmt.place.projections.is_empty() { let map = &self.cx.tcx.hir(); if is_argument(*map, cmt.hir_id) { diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 4fdcaca8f603..7ea2d3d857b3 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -1694,28 +1694,28 @@ struct MutatePairDelegate<'a, 'tcx> { } impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> { - fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: ConsumeMode) {} + fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId, _: ConsumeMode) {} - fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, bk: ty::BorrowKind) { + fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: ty::BorrowKind) { if let ty::BorrowKind::MutBorrow = bk { if let PlaceBase::Local(id) = cmt.place.base { if Some(id) == self.hir_id_low { - self.span_low = Some(self.cx.tcx.hir().span(cmt.hir_id)) + self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id)) } if Some(id) == self.hir_id_high { - self.span_high = Some(self.cx.tcx.hir().span(cmt.hir_id)) + self.span_high = Some(self.cx.tcx.hir().span(diag_expr_id)) } } } } - fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>) { + fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) { if let PlaceBase::Local(id) = cmt.place.base { if Some(id) == self.hir_id_low { - self.span_low = Some(self.cx.tcx.hir().span(cmt.hir_id)) + self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id)) } if Some(id) == self.hir_id_high { - self.span_high = Some(self.cx.tcx.hir().span(cmt.hir_id)) + self.span_high = Some(self.cx.tcx.hir().span(diag_expr_id)) } } } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 7e933c674dd7..2423eb4e6e39 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -325,13 +325,13 @@ impl MovedVariablesCtxt { } impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt { - fn consume(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, mode: euv::ConsumeMode) { + fn consume(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, _: HirId, mode: euv::ConsumeMode) { if let euv::ConsumeMode::Move = mode { self.move_common(cmt); } } - fn borrow(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: ty::BorrowKind) {} + fn borrow(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {} - fn mutate(&mut self, _: &euv::PlaceWithHirId<'tcx>) {} + fn mutate(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId) {} } diff --git a/clippy_lints/src/utils/usage.rs b/clippy_lints/src/utils/usage.rs index ea1dc3be29ba..a15b8621365e 100644 --- a/clippy_lints/src/utils/usage.rs +++ b/clippy_lints/src/utils/usage.rs @@ -68,15 +68,15 @@ impl<'tcx> MutVarsDelegate { } impl<'tcx> Delegate<'tcx> for MutVarsDelegate { - fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: ConsumeMode) {} + fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId, _: ConsumeMode) {} - fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, bk: ty::BorrowKind) { + fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, bk: ty::BorrowKind) { if let ty::BorrowKind::MutBorrow = bk { self.update(&cmt) } } - fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>) { + fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) { self.update(&cmt) } } From 592aef8d162addc06e8f91fb8748ec6326fac580 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 3 Nov 2020 20:26:17 +0300 Subject: [PATCH 0122/1222] rustc_ast: Do not panic by default when visiting macro calls --- clippy_lints/src/non_expressive_names.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 603440c0f837..6b56380edf8c 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -149,9 +149,6 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for SimilarNamesNameVisitor<'a, 'tcx, 'b> { _ => walk_pat(self, pat), } } - fn visit_mac(&mut self, _mac: &MacCall) { - // do not check macs - } } #[must_use] @@ -356,9 +353,6 @@ impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> { fn visit_item(&mut self, _: &Item) { // do not recurse into inner items } - fn visit_mac(&mut self, _mac: &MacCall) { - // do not check macs - } } impl EarlyLintPass for NonExpressiveNames { From 667fc0ce01f4ec29ff81b82b3aca9735b9c89780 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 3 Nov 2020 20:34:57 +0300 Subject: [PATCH 0123/1222] rustc_ast: `visit_mac` -> `visit_mac_call` --- clippy_lints/src/non_expressive_names.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 6b56380edf8c..c5f38c1f0802 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -1,6 +1,6 @@ use crate::utils::{span_lint, span_lint_and_then}; use rustc_ast::ast::{ - Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Item, ItemKind, Local, MacCall, Pat, PatKind, + Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Item, ItemKind, Local, Pat, PatKind, }; use rustc_ast::visit::{walk_block, walk_expr, walk_pat, Visitor}; use rustc_lint::{EarlyContext, EarlyLintPass}; From 996cc2073a2e07d28cf1b00bb9ceecc8e905cc0e Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Sat, 26 Sep 2020 15:15:35 +0200 Subject: [PATCH 0124/1222] Split the "raw integer bytes" part out of `Scalar` --- clippy_lints/src/consts.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index c5e33b288a9c..b54d2654579f 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -8,8 +8,9 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, QPath, UnOp}; use rustc_lint::LateContext; use rustc_middle::ty::subst::{Subst, SubstsRef}; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt, ScalarInt}; use rustc_middle::{bug, span_bug}; +use rustc_middle::mir::interpret::Scalar; use rustc_span::symbol::Symbol; use std::cmp::Ordering::{self, Equal}; use std::convert::TryInto; @@ -500,21 +501,21 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { } pub fn miri_to_const(result: &ty::Const<'_>) -> Option { - use rustc_middle::mir::interpret::{ConstValue, Scalar}; + use rustc_middle::mir::interpret::{ConstValue}; match result.val { - ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data: d, .. })) => { + ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw(int))) => { match result.ty.kind() { - ty::Bool => Some(Constant::Bool(d == 1)), - ty::Uint(_) | ty::Int(_) => Some(Constant::Int(d)), + ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)), + ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.assert_bits(int.size()))), ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits( - d.try_into().expect("invalid f32 bit representation"), + int.try_into().expect("invalid f32 bit representation"), ))), ty::Float(FloatTy::F64) => Some(Constant::F64(f64::from_bits( - d.try_into().expect("invalid f64 bit representation"), + int.try_into().expect("invalid f64 bit representation"), ))), ty::RawPtr(type_and_mut) => { if let ty::Uint(_) = type_and_mut.ty.kind() { - return Some(Constant::RawPtr(d)); + return Some(Constant::RawPtr(int.assert_bits(int.size()))); } None }, From f24064d57893e8e359bb12efadefab10ccc5d57f Mon Sep 17 00:00:00 2001 From: oli Date: Sun, 1 Nov 2020 16:57:03 +0000 Subject: [PATCH 0125/1222] s/Scalar::Raw/Scalar::Int --- clippy_lints/src/consts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index b54d2654579f..c8bbc9ce2b02 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -503,7 +503,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { pub fn miri_to_const(result: &ty::Const<'_>) -> Option { use rustc_middle::mir::interpret::{ConstValue}; match result.val { - ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw(int))) => { + ty::ConstKind::Value(ConstValue::Scalar(Scalar::Int(int))) => { match result.ty.kind() { ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)), ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.assert_bits(int.size()))), From 9b633a2b774934eef68549b5b9e0b8f4599736c3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 5 Nov 2020 20:27:48 +0300 Subject: [PATCH 0126/1222] Do not collect tokens for doc comments --- clippy_lints/src/attrs.rs | 2 +- clippy_lints/src/utils/ast_utils.rs | 2 +- clippy_lints/src/utils/attrs.rs | 2 +- clippy_lints/src/utils/mod.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index a004abb58b83..55904a0ec0a8 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -588,7 +588,7 @@ 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 { + let attr_item = if let AttrKind::Normal(ref attr, _) = attr.kind { attr } else { return; diff --git a/clippy_lints/src/utils/ast_utils.rs b/clippy_lints/src/utils/ast_utils.rs index 0e9feef3746e..b68e33f101d2 100644 --- a/clippy_lints/src/utils/ast_utils.rs +++ b/clippy_lints/src/utils/ast_utils.rs @@ -509,7 +509,7 @@ pub fn eq_attr(l: &Attribute, r: &Attribute) -> bool { l.style == r.style && match (&l.kind, &r.kind) { (DocComment(l1, l2), DocComment(r1, r2)) => l1 == r1 && l2 == r2, - (Normal(l), Normal(r)) => eq_path(&l.path, &r.path) && eq_mac_args(&l.args, &r.args), + (Normal(l, _), Normal(r, _)) => eq_path(&l.path, &r.path) && eq_mac_args(&l.args, &r.args), _ => false, } } diff --git a/clippy_lints/src/utils/attrs.rs b/clippy_lints/src/utils/attrs.rs index a3975683cb30..e6d41341a55f 100644 --- a/clippy_lints/src/utils/attrs.rs +++ b/clippy_lints/src/utils/attrs.rs @@ -57,7 +57,7 @@ pub fn get_attr<'a>( name: &'static str, ) -> impl Iterator { attrs.iter().filter(move |attr| { - let attr = if let ast::AttrKind::Normal(ref attr) = attr.kind { + let attr = if let ast::AttrKind::Normal(ref attr, _) = attr.kind { attr } else { return false; diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 85e7f055e79d..0d43fd0392eb 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1349,7 +1349,7 @@ pub fn is_must_use_func_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { pub fn is_no_std_crate(krate: &Crate<'_>) -> bool { krate.item.attrs.iter().any(|attr| { - if let ast::AttrKind::Normal(ref attr) = attr.kind { + if let ast::AttrKind::Normal(ref attr, _) = attr.kind { attr.path == symbol::sym::no_std } else { false From b1b456a1790c4acb74ab550158b272c673f35c65 Mon Sep 17 00:00:00 2001 From: Ikko Ashimine Date: Wed, 11 Nov 2020 20:23:08 +0900 Subject: [PATCH 0127/1222] Fix typo in comment occurences -> occurrences --- clippy_lints/src/loops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 32c2562ee95b..5a4264f9b5c4 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -3089,7 +3089,7 @@ impl<'tcx> Visitor<'tcx> for IterFunctionVisitor { } } -/// Detect the occurences of calls to `iter` or `into_iter` for the +/// Detect the occurrences of calls to `iter` or `into_iter` for the /// given identifier fn detect_iter_and_into_iters<'tcx>(block: &'tcx Block<'tcx>, identifier: Ident) -> Option> { let mut visitor = IterFunctionVisitor { From ce41b5d1ed53d1c1a507f6463b47e08e26d14148 Mon Sep 17 00:00:00 2001 From: Fabian Zaiser Date: Sat, 7 Nov 2020 14:28:55 +0000 Subject: [PATCH 0128/1222] Implement destructuring assignment for structs and slices Co-authored-by: varkor --- clippy_lints/src/utils/ast_utils.rs | 11 ++++++++++- tests/ui/crashes/ice-6250.stderr | 29 ++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/utils/ast_utils.rs b/clippy_lints/src/utils/ast_utils.rs index 0e9feef3746e..7b65e664867f 100644 --- a/clippy_lints/src/utils/ast_utils.rs +++ b/clippy_lints/src/utils/ast_utils.rs @@ -107,6 +107,15 @@ pub fn eq_expr_opt(l: &Option>, r: &Option>) -> bool { both(l, r, |l, r| eq_expr(l, r)) } +pub fn eq_struct_rest(l: &StructRest, r: &StructRest) -> bool { + match (l, r) { + (StructRest::Base(lb), StructRest::Base(rb)) => eq_expr(lb, rb), + (StructRest::Rest(_), StructRest::Rest(_)) => true, + (StructRest::None, StructRest::None) => true, + _ => false, + } +} + pub fn eq_expr(l: &Expr, r: &Expr) -> bool { use ExprKind::*; if !over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)) { @@ -150,7 +159,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp), (MacCall(l), MacCall(r)) => eq_mac_call(l, r), (Struct(lp, lfs, lb), Struct(rp, rfs, rb)) => { - eq_path(lp, rp) && eq_expr_opt(lb, rb) && unordered_over(lfs, rfs, |l, r| eq_field(l, r)) + eq_path(lp, rp) && eq_struct_rest(lb, rb) && unordered_over(lfs, rfs, |l, r| eq_field(l, r)) }, _ => false, } diff --git a/tests/ui/crashes/ice-6250.stderr b/tests/ui/crashes/ice-6250.stderr index 8241dcd8feb7..c38727316cd4 100644 --- a/tests/ui/crashes/ice-6250.stderr +++ b/tests/ui/crashes/ice-6250.stderr @@ -1,3 +1,14 @@ +error[E0658]: destructuring assignments are unstable + --> $DIR/ice-6250.rs:12:25 + | +LL | Some(reference) = cache.data.get(key) { + | --------------- ^ + | | + | cannot assign to this expression + | + = note: see issue #71126 for more information + = help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable + error[E0601]: `main` function not found in crate `ice_6250` --> $DIR/ice-6250.rs:4:1 | @@ -10,18 +21,22 @@ LL | | } LL | | } | |_^ consider adding a `main` function to `$DIR/ice-6250.rs` +error[E0308]: mismatched types + --> $DIR/ice-6250.rs:12:14 + | +LL | Some(reference) = cache.data.get(key) { + | ^^^^^^^^^ + | | + | expected integer, found `&i32` + | help: consider dereferencing the borrow: `*reference` + error[E0308]: mismatched types --> $DIR/ice-6250.rs:12:9 | LL | Some(reference) = cache.data.get(key) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()` - | -help: you might have meant to use pattern matching - | -LL | let Some(reference) = cache.data.get(key) { - | ^^^ -error: aborting due to 2 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0308, E0601. +Some errors have detailed explanations: E0308, E0601, E0658. For more information about an error, try `rustc --explain E0308`. From c6ad6700e3e7d7bf1bc6e4d372141df3ba364bcd Mon Sep 17 00:00:00 2001 From: Vishnunarayan K I Date: Fri, 13 Nov 2020 17:11:13 +0530 Subject: [PATCH 0129/1222] update clippy test ouput --- tests/ui/crashes/ice-6252.stderr | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index 440973e24398..eaa5e6f51cb4 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -26,21 +26,7 @@ LL | const VAL: T; LL | impl TypeVal for Multiply where N: TypeVal {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation -error: any use of this value will cause an error - --> $DIR/ice-6252.rs:5:5 - | -LL | const VAL: T; - | ^^^^^^^^^^^^^ no MIR body is available for DefId(0:5 ~ ice_6252[317d]::TypeVal::VAL) - | - = note: `#[deny(const_err)]` on by default - -error[E0080]: evaluation of constant value failed - --> $DIR/ice-6252.rs:14:9 - | -LL | [1; >::VAL]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors - -error: aborting due to 5 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0046, E0080, E0412. +Some errors have detailed explanations: E0046, E0412. For more information about an error, try `rustc --explain E0046`. From 0cf16aaffc13e632899e7683eb6f7ecfbaa0a700 Mon Sep 17 00:00:00 2001 From: Fabian Zaiser Date: Wed, 11 Nov 2020 13:15:15 +0000 Subject: [PATCH 0130/1222] Add underscore expressions for destructuring assignments Co-authored-by: varkor --- clippy_lints/src/utils/sugg.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index 625120b880eb..1fcd41e4dbfe 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -170,6 +170,7 @@ impl<'a> Sugg<'a> { | ast::ExprKind::MacCall(..) | ast::ExprKind::MethodCall(..) | ast::ExprKind::Paren(..) + | ast::ExprKind::Underscore | ast::ExprKind::Path(..) | ast::ExprKind::Repeat(..) | ast::ExprKind::Ret(..) From fdf99ca5655e7f87dc2b4393692e98d850547757 Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Thu, 5 Nov 2020 17:30:39 +0100 Subject: [PATCH 0131/1222] Introduce `TypeVisitor::BreakTy` --- clippy_lints/src/redundant_clone.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index b4a9804fb25a..64b12980af66 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -563,7 +563,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { struct ContainsRegion; impl TypeVisitor<'_> for ContainsRegion { - fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow<()> { + fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow { ControlFlow::BREAK } } From e08820e70068f6e6e33cebe44fbb327c3884ca98 Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Sat, 14 Nov 2020 21:46:39 +0100 Subject: [PATCH 0132/1222] Set the default `BreakTy` to `!` --- clippy_lints/src/redundant_clone.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 64b12980af66..602facbe062a 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -563,6 +563,8 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { struct ContainsRegion; impl TypeVisitor<'_> for ContainsRegion { + type BreakTy = (); + fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow { ControlFlow::BREAK } From bc1414c421bf4a874ee772ce4b34fd0ef0285592 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Sat, 24 Oct 2020 02:21:27 +0200 Subject: [PATCH 0133/1222] clippy: fold by value --- clippy_lints/src/eval_order_dependence.rs | 2 +- clippy_lints/src/methods/mod.rs | 4 ++-- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/transmute.rs | 2 +- clippy_lints/src/unit_return_expecting_ord.rs | 8 ++++---- clippy_lints/src/use_self.rs | 2 +- clippy_lints/src/utils/mod.rs | 6 +++--- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index 4240147f498d..bc2b2904698c 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -141,7 +141,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { match typ.kind() { ty::FnDef(..) | ty::FnPtr(_) => { let sig = typ.fn_sig(self.cx.tcx); - if let ty::Never = self.cx.tcx.erase_late_bound_regions(&sig).output().kind() { + if let ty::Never = self.cx.tcx.erase_late_bound_regions(sig).output().kind() { self.report_diverging_sub_expr(e); } }, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 7186656f4e11..30f4c0c56d27 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1615,7 +1615,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { let method_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); let method_sig = cx.tcx.fn_sig(method_def_id); - let method_sig = cx.tcx.erase_late_bound_regions(&method_sig); + let method_sig = cx.tcx.erase_late_bound_regions(method_sig); let first_arg_ty = &method_sig.inputs().iter().next(); @@ -2681,7 +2681,7 @@ fn lint_map_flatten<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map ty::Closure(_, substs) => substs.as_closure().sig(), _ => map_closure_ty.fn_sig(cx.tcx), }; - let map_closure_return_ty = cx.tcx.erase_late_bound_regions(&map_closure_sig.output()); + let map_closure_return_ty = cx.tcx.erase_late_bound_regions(map_closure_sig.output()); is_type_diagnostic_item(cx, map_closure_return_ty, sym::option_type) }, _ => false, diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 4525b12689fa..9cceecc785a2 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -92,7 +92,7 @@ fn check_sig<'tcx>(cx: &LateContext<'tcx>, item_hir_id: hir::HirId, decl: &hir:: check_ty( cx, decl.output.span(), - cx.tcx.erase_late_bound_regions(&fn_sig.output()), + cx.tcx.erase_late_bound_regions(fn_sig.output()), ); } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 1d0e230c6a77..532c0266946b 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -141,7 +141,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { }; let fn_sig = cx.tcx.fn_sig(fn_def_id); - let fn_sig = cx.tcx.erase_late_bound_regions(&fn_sig); + let fn_sig = cx.tcx.erase_late_bound_regions(fn_sig); for (idx, ((input, &ty), arg)) in decl.inputs.iter().zip(fn_sig.inputs()).zip(body.params).enumerate() { // All spans generated from a proc-macro invocation are the same... diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 030650c3256c..f03facc235e2 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -115,7 +115,7 @@ impl<'tcx> PassByRefOrValue { let fn_def_id = cx.tcx.hir().local_def_id(hir_id); let fn_sig = cx.tcx.fn_sig(fn_def_id); - let fn_sig = cx.tcx.erase_late_bound_regions(&fn_sig); + let fn_sig = cx.tcx.erase_late_bound_regions(fn_sig); let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir().body(id)); diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 47c650ac27d4..b0909f731774 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -491,7 +491,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { Applicability::Unspecified, ); } else { - if (cx.tcx.erase_regions(&from_ty) != cx.tcx.erase_regions(&to_ty)) + if (cx.tcx.erase_regions(from_ty) != cx.tcx.erase_regions(to_ty)) && !const_context { span_lint_and_then( cx, diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 0d5a5017331b..ade5fff5ffc0 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -43,7 +43,7 @@ fn get_trait_predicates_for_trait_id<'tcx>( for (pred, _) in generics.predicates { if_chain! { if let PredicateAtom::Trait(poly_trait_pred, _) = pred.skip_binders(); - let trait_pred = cx.tcx.erase_late_bound_regions(&ty::Binder::bind(poly_trait_pred)); + let trait_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(poly_trait_pred)); if let Some(trait_def_id) = trait_id; if trait_def_id == trait_pred.trait_ref.def_id; then { @@ -61,7 +61,7 @@ fn get_projection_pred<'tcx>( ) -> Option> { generics.predicates.iter().find_map(|(proj_pred, _)| { if let ty::PredicateAtom::Projection(proj_pred) = proj_pred.skip_binders() { - let projection_pred = cx.tcx.erase_late_bound_regions(&ty::Binder::bind(proj_pred)); + let projection_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(proj_pred)); if projection_pred.projection_ty.substs == pred.trait_ref.substs { return Some(projection_pred); } @@ -81,7 +81,7 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve get_trait_predicates_for_trait_id(cx, generics, cx.tcx.lang_items().partial_ord_trait()); // Trying to call erase_late_bound_regions on fn_sig.inputs() gives the following error // The trait `rustc::ty::TypeFoldable<'_>` is not implemented for `&[&rustc::ty::TyS<'_>]` - let inputs_output = cx.tcx.erase_late_bound_regions(&fn_sig.inputs_and_output()); + let inputs_output = cx.tcx.erase_late_bound_regions(fn_sig.inputs_and_output()); inputs_output .iter() .rev() @@ -112,7 +112,7 @@ fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Spa if let ExprKind::Closure(_, _fn_decl, body_id, span, _) = arg.kind; if let ty::Closure(_def_id, substs) = &cx.typeck_results().node_type(arg.hir_id).kind(); let ret_ty = substs.as_closure().sig().output(); - let ty = cx.tcx.erase_late_bound_regions(&ret_ty); + let ty = cx.tcx.erase_late_bound_regions(ret_ty); if ty.is_unit(); then { if_chain! { diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 427a1b657731..5ac4797680bc 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -123,7 +123,7 @@ fn check_trait_method_impl_decl<'tcx>( .expect("impl method matches a trait method"); let trait_method_sig = cx.tcx.fn_sig(trait_method.def_id); - let trait_method_sig = cx.tcx.erase_late_bound_regions(&trait_method_sig); + let trait_method_sig = cx.tcx.erase_late_bound_regions(trait_method_sig); let output_hir_ty = if let FnRetTy::Return(ty) = &impl_decl.output { Some(&**ty) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 0d43fd0392eb..b027bfebacb6 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -363,7 +363,7 @@ pub fn implements_trait<'tcx>( if ty.has_infer_types() { return false; } - let ty = cx.tcx.erase_regions(&ty); + let ty = cx.tcx.erase_regions(ty); let ty_params = cx.tcx.mk_substs(ty_params.iter()); cx.tcx.type_implements_trait((trait_id, ty, ty_params, cx.param_env)) } @@ -887,7 +887,7 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option { pub fn return_ty<'tcx>(cx: &LateContext<'tcx>, fn_item: hir::HirId) -> Ty<'tcx> { let fn_def_id = cx.tcx.hir().local_def_id(fn_item); let ret_ty = cx.tcx.fn_sig(fn_def_id).output(); - cx.tcx.erase_late_bound_regions(&ret_ty) + cx.tcx.erase_late_bound_regions(ret_ty) } /// Walks into `ty` and returns `true` if any inner type is the same as `other_ty` @@ -1220,7 +1220,7 @@ pub fn match_function_call<'tcx>( pub fn is_normalizable<'tcx>(cx: &LateContext<'tcx>, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool { cx.tcx.infer_ctxt().enter(|infcx| { let cause = rustc_middle::traits::ObligationCause::dummy(); - infcx.at(&cause, param_env).normalize(&ty).is_ok() + infcx.at(&cause, param_env).normalize(ty).is_ok() }) } From 37ffd34f91a03118260650681b168b9660de6fb8 Mon Sep 17 00:00:00 2001 From: Camelid Date: Tue, 17 Nov 2020 12:16:15 -0800 Subject: [PATCH 0134/1222] Fix handling of panic calls This should make Clippy more resilient and will unblock #78343. This PR is made against rust-lang/rust to avoid the need for a subtree sync at @flip1995's suggestion in rust-lang/rust-clippy#6310. --- clippy_lints/src/assertions_on_constants.rs | 5 +-- clippy_lints/src/attrs.rs | 4 +- clippy_lints/src/fallible_impl_from.rs | 9 ++-- clippy_lints/src/implicit_return.rs | 9 +--- clippy_lints/src/panic_unimplemented.rs | 44 +++++++++--------- clippy_lints/src/utils/mod.rs | 20 ++++++++- clippy_lints/src/utils/paths.rs | 8 +++- tests/ui/panicking_macros.rs | 11 +++++ tests/ui/panicking_macros.stderr | 50 +++++++++++++++------ 9 files changed, 106 insertions(+), 54 deletions(-) diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index 982d5ecf8d02..a2ccb0369c4a 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -1,6 +1,5 @@ use crate::consts::{constant, Constant}; -use crate::utils::paths; -use crate::utils::{is_direct_expn_of, is_expn_of, match_function_call, snippet_opt, span_lint_and_help}; +use crate::utils::{is_direct_expn_of, is_expn_of, match_panic_call, snippet_opt, span_lint_and_help}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_hir::{Expr, ExprKind, PatKind, UnOp}; @@ -133,7 +132,7 @@ fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) if let ExprKind::Block(ref inner_block, _) = block_expr.kind; if let Some(begin_panic_call) = &inner_block.expr; // function call - if let Some(args) = match_function_call(cx, begin_panic_call, &paths::BEGIN_PANIC); + if let Some(args) = match_panic_call(cx, begin_panic_call); if args.len() == 1; // bind the second argument of the `assert!` macro if it exists if let panic_message = snippet_opt(cx, args[0].span); diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 55904a0ec0a8..57702dafa6a0 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -1,7 +1,7 @@ //! checks for attributes use crate::utils::{ - first_line_of_span, is_present_in_source, match_def_path, paths, snippet_opt, span_lint, span_lint_and_help, + first_line_of_span, is_present_in_source, match_panic_def_id, snippet_opt, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then, without_block_comments, }; use if_chain::if_chain; @@ -513,7 +513,7 @@ fn is_relevant_expr(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_> typeck_results .qpath_res(qpath, path_expr.hir_id) .opt_def_id() - .map_or(true, |fun_id| !match_def_path(cx, fun_id, &paths::BEGIN_PANIC)) + .map_or(true, |fun_id| !match_panic_def_id(cx, fun_id)) } else { true } diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index fe817fe94f2e..509a4a4e15f6 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -1,5 +1,7 @@ -use crate::utils::paths::{BEGIN_PANIC, BEGIN_PANIC_FMT, FROM_TRAIT}; -use crate::utils::{is_expn_of, is_type_diagnostic_item, match_def_path, method_chain_args, span_lint_and_then}; +use crate::utils::paths::FROM_TRAIT; +use crate::utils::{ + is_expn_of, is_type_diagnostic_item, match_def_path, match_panic_def_id, method_chain_args, span_lint_and_then, +}; use if_chain::if_chain; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; @@ -84,8 +86,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h if let ExprKind::Call(ref func_expr, _) = expr.kind; if let ExprKind::Path(QPath::Resolved(_, ref path)) = func_expr.kind; if let Some(path_def_id) = path.res.opt_def_id(); - if match_def_path(self.lcx, path_def_id, &BEGIN_PANIC) || - match_def_path(self.lcx, path_def_id, &BEGIN_PANIC_FMT); + if match_panic_def_id(self.lcx, path_def_id); if is_expn_of(expr.span, "unreachable").is_none(); then { self.result.push(expr.span); diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index 22c4fef32a32..ed7f3b9293db 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -1,8 +1,4 @@ -use crate::utils::{ - fn_has_unsatisfiable_preds, match_def_path, - paths::{BEGIN_PANIC, BEGIN_PANIC_FMT}, - snippet_opt, span_lint_and_then, -}; +use crate::utils::{fn_has_unsatisfiable_preds, match_panic_def_id, snippet_opt, span_lint_and_then}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; @@ -109,8 +105,7 @@ fn expr_match(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Path(qpath) = &expr.kind; if let Some(path_def_id) = cx.qpath_res(qpath, expr.hir_id).opt_def_id(); - if match_def_path(cx, path_def_id, &BEGIN_PANIC) || - match_def_path(cx, path_def_id, &BEGIN_PANIC_FMT); + if match_panic_def_id(cx, path_def_id); then { } else { lint(cx, expr.span, expr.span, LINT_RETURN) diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs index 6379dffd22e3..3d888fe73257 100644 --- a/clippy_lints/src/panic_unimplemented.rs +++ b/clippy_lints/src/panic_unimplemented.rs @@ -1,4 +1,4 @@ -use crate::utils::{is_direct_expn_of, is_expn_of, match_function_call, paths, span_lint}; +use crate::utils::{is_direct_expn_of, is_expn_of, match_panic_call, span_lint}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_hir::{Expr, ExprKind}; @@ -93,27 +93,27 @@ declare_lint_pass!(PanicUnimplemented => [PANIC_PARAMS, UNIMPLEMENTED, UNREACHAB impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if_chain! { - if let ExprKind::Block(ref block, _) = expr.kind; - if let Some(ref ex) = block.expr; - if let Some(params) = match_function_call(cx, ex, &paths::BEGIN_PANIC) - .or_else(|| match_function_call(cx, ex, &paths::BEGIN_PANIC_FMT)); - then { - let span = get_outer_span(expr); - if is_expn_of(expr.span, "unimplemented").is_some() { - span_lint(cx, UNIMPLEMENTED, span, - "`unimplemented` should not be present in production code"); - } else if is_expn_of(expr.span, "todo").is_some() { - span_lint(cx, TODO, span, - "`todo` should not be present in production code"); - } else if is_expn_of(expr.span, "unreachable").is_some() { - span_lint(cx, UNREACHABLE, span, - "`unreachable` should not be present in production code"); - } else if is_expn_of(expr.span, "panic").is_some() { - span_lint(cx, PANIC, span, - "`panic` should not be present in production code"); - match_panic(params, expr, cx); - } + if let Some(params) = match_panic_call(cx, expr) { + let span = get_outer_span(expr); + if is_expn_of(expr.span, "unimplemented").is_some() { + span_lint( + cx, + UNIMPLEMENTED, + span, + "`unimplemented` should not be present in production code", + ); + } else if is_expn_of(expr.span, "todo").is_some() { + span_lint(cx, TODO, span, "`todo` should not be present in production code"); + } else if is_expn_of(expr.span, "unreachable").is_some() { + span_lint( + cx, + UNREACHABLE, + span, + "`unreachable` should not be present in production code", + ); + } else if is_expn_of(expr.span, "panic").is_some() { + span_lint(cx, PANIC, span, "`panic` should not be present in production code"); + match_panic(params, expr, cx); } } } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 0d43fd0392eb..a68262d56c64 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1196,7 +1196,7 @@ pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option< /// Usage: /// /// ```rust,ignore -/// if let Some(args) = match_function_call(cx, begin_panic_call, &paths::BEGIN_PANIC); +/// if let Some(args) = match_function_call(cx, cmp_max_call, &paths::CMP_MAX); /// ``` pub fn match_function_call<'tcx>( cx: &LateContext<'tcx>, @@ -1231,6 +1231,24 @@ pub fn match_def_path<'tcx>(cx: &LateContext<'tcx>, did: DefId, syms: &[&str]) - cx.match_def_path(did, &syms) } +pub fn match_panic_call<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx [Expr<'tcx>]> { + match_function_call(cx, expr, &paths::BEGIN_PANIC) + .or_else(|| match_function_call(cx, expr, &paths::BEGIN_PANIC_FMT)) + .or_else(|| match_function_call(cx, expr, &paths::PANIC_ANY)) + .or_else(|| match_function_call(cx, expr, &paths::PANICKING_PANIC)) + .or_else(|| match_function_call(cx, expr, &paths::PANICKING_PANIC_FMT)) + .or_else(|| match_function_call(cx, expr, &paths::PANICKING_PANIC_STR)) +} + +pub fn match_panic_def_id(cx: &LateContext<'_>, did: DefId) -> bool { + match_def_path(cx, did, &paths::BEGIN_PANIC) + || match_def_path(cx, did, &paths::BEGIN_PANIC_FMT) + || match_def_path(cx, did, &paths::PANIC_ANY) + || match_def_path(cx, did, &paths::PANICKING_PANIC) + || match_def_path(cx, did, &paths::PANICKING_PANIC_FMT) + || match_def_path(cx, did, &paths::PANICKING_PANIC_STR) +} + /// Returns the list of condition expressions and the list of blocks in a /// sequence of `if/else`. /// E.g., this returns `([a, b], [c, d, e])` for the expression diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index 1ad8c6029860..8f5fbfd9f846 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -8,8 +8,8 @@ pub const ANY_TRAIT: [&str; 3] = ["std", "any", "Any"]; pub const ARC_PTR_EQ: [&str; 4] = ["alloc", "sync", "Arc", "ptr_eq"]; pub const ASMUT_TRAIT: [&str; 3] = ["core", "convert", "AsMut"]; pub const ASREF_TRAIT: [&str; 3] = ["core", "convert", "AsRef"]; -pub const BEGIN_PANIC: [&str; 3] = ["std", "panicking", "begin_panic"]; -pub const BEGIN_PANIC_FMT: [&str; 3] = ["std", "panicking", "begin_panic_fmt"]; +pub(super) const BEGIN_PANIC: [&str; 3] = ["std", "panicking", "begin_panic"]; +pub(super) const BEGIN_PANIC_FMT: [&str; 3] = ["std", "panicking", "begin_panic_fmt"]; pub const BINARY_HEAP: [&str; 4] = ["alloc", "collections", "binary_heap", "BinaryHeap"]; pub const BORROW_TRAIT: [&str; 3] = ["core", "borrow", "Borrow"]; pub const BOX: [&str; 3] = ["alloc", "boxed", "Box"]; @@ -78,6 +78,10 @@ pub const ORD: [&str; 3] = ["core", "cmp", "Ord"]; pub const OS_STRING: [&str; 4] = ["std", "ffi", "os_str", "OsString"]; pub const OS_STRING_AS_OS_STR: [&str; 5] = ["std", "ffi", "os_str", "OsString", "as_os_str"]; pub const OS_STR_TO_OS_STRING: [&str; 5] = ["std", "ffi", "os_str", "OsStr", "to_os_string"]; +pub(super) const PANICKING_PANIC: [&str; 3] = ["core", "panicking", "panic"]; +pub(super) const PANICKING_PANIC_FMT: [&str; 3] = ["core", "panicking", "panic_fmt"]; +pub(super) const PANICKING_PANIC_STR: [&str; 3] = ["core", "panicking", "panic_str"]; +pub(super) const PANIC_ANY: [&str; 3] = ["std", "panic", "panic_any"]; pub const PARKING_LOT_MUTEX_GUARD: [&str; 2] = ["parking_lot", "MutexGuard"]; pub const PARKING_LOT_RWLOCK_READ_GUARD: [&str; 2] = ["parking_lot", "RwLockReadGuard"]; pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 2] = ["parking_lot", "RwLockWriteGuard"]; diff --git a/tests/ui/panicking_macros.rs b/tests/ui/panicking_macros.rs index f91ccfaed743..77fcb8dfd02f 100644 --- a/tests/ui/panicking_macros.rs +++ b/tests/ui/panicking_macros.rs @@ -1,6 +1,8 @@ #![warn(clippy::unimplemented, clippy::unreachable, clippy::todo, clippy::panic)] #![allow(clippy::assertions_on_constants)] +extern crate core; + fn panic() { let a = 2; panic!(); @@ -33,9 +35,18 @@ fn unreachable() { let b = a + 2; } +fn core_versions() { + use core::{panic, todo, unimplemented, unreachable}; + panic!(); + todo!(); + unimplemented!(); + unreachable!(); +} + fn main() { panic(); todo(); unimplemented(); unreachable(); + core_versions(); } diff --git a/tests/ui/panicking_macros.stderr b/tests/ui/panicking_macros.stderr index 37c11d72a574..83234c0ed92c 100644 --- a/tests/ui/panicking_macros.stderr +++ b/tests/ui/panicking_macros.stderr @@ -1,5 +1,5 @@ error: `panic` should not be present in production code - --> $DIR/panicking_macros.rs:6:5 + --> $DIR/panicking_macros.rs:8:5 | LL | panic!(); | ^^^^^^^^^ @@ -7,7 +7,7 @@ LL | panic!(); = note: `-D clippy::panic` implied by `-D warnings` error: `panic` should not be present in production code - --> $DIR/panicking_macros.rs:7:5 + --> $DIR/panicking_macros.rs:9:5 | LL | panic!("message"); | ^^^^^^^^^^^^^^^^^^ @@ -15,7 +15,7 @@ LL | panic!("message"); = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `panic` should not be present in production code - --> $DIR/panicking_macros.rs:8:5 + --> $DIR/panicking_macros.rs:10:5 | LL | panic!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | panic!("{} {}", "panic with", "multiple arguments"); = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:14:5 + --> $DIR/panicking_macros.rs:16:5 | LL | todo!(); | ^^^^^^^^ @@ -31,19 +31,19 @@ LL | todo!(); = note: `-D clippy::todo` implied by `-D warnings` error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:15:5 + --> $DIR/panicking_macros.rs:17:5 | LL | todo!("message"); | ^^^^^^^^^^^^^^^^^ error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:16:5 + --> $DIR/panicking_macros.rs:18:5 | LL | todo!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:22:5 + --> $DIR/panicking_macros.rs:24:5 | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^^ @@ -51,19 +51,19 @@ LL | unimplemented!(); = note: `-D clippy::unimplemented` implied by `-D warnings` error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:23:5 + --> $DIR/panicking_macros.rs:25:5 | LL | unimplemented!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:24:5 + --> $DIR/panicking_macros.rs:26:5 | LL | unimplemented!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `unreachable` should not be present in production code - --> $DIR/panicking_macros.rs:30:5 + --> $DIR/panicking_macros.rs:32:5 | LL | unreachable!(); | ^^^^^^^^^^^^^^^ @@ -71,7 +71,7 @@ LL | unreachable!(); = note: `-D clippy::unreachable` implied by `-D warnings` error: `unreachable` should not be present in production code - --> $DIR/panicking_macros.rs:31:5 + --> $DIR/panicking_macros.rs:33:5 | LL | unreachable!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -79,10 +79,34 @@ LL | unreachable!("message"); = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `unreachable` should not be present in production code - --> $DIR/panicking_macros.rs:32:5 + --> $DIR/panicking_macros.rs:34:5 | LL | unreachable!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 12 previous errors +error: `panic` should not be present in production code + --> $DIR/panicking_macros.rs:40:5 + | +LL | panic!(); + | ^^^^^^^^^ + +error: `todo` should not be present in production code + --> $DIR/panicking_macros.rs:41:5 + | +LL | todo!(); + | ^^^^^^^^ + +error: `unimplemented` should not be present in production code + --> $DIR/panicking_macros.rs:42:5 + | +LL | unimplemented!(); + | ^^^^^^^^^^^^^^^^^ + +error: `unreachable` should not be present in production code + --> $DIR/panicking_macros.rs:43:5 + | +LL | unreachable!(); + | ^^^^^^^^^^^^^^^ + +error: aborting due to 16 previous errors From 2d90d10274d21a25cae8db7b1e0144d1ede85968 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Thu, 19 Nov 2020 18:13:32 +0100 Subject: [PATCH 0135/1222] Remove the clippy::panic-params lint. Rustc itself now warns for all cases that triggered this lint. --- clippy_lints/src/lib.rs | 3 -- clippy_lints/src/panic_unimplemented.rs | 46 ++----------------- tests/ui/panic.rs | 61 ------------------------- tests/ui/panic.stderr | 28 ------------ 4 files changed, 4 insertions(+), 134 deletions(-) delete mode 100644 tests/ui/panic.rs delete mode 100644 tests/ui/panic.stderr diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 126852df502e..19bf67d80c42 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -788,7 +788,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL, &panic_in_result_fn::PANIC_IN_RESULT_FN, &panic_unimplemented::PANIC, - &panic_unimplemented::PANIC_PARAMS, &panic_unimplemented::TODO, &panic_unimplemented::UNIMPLEMENTED, &panic_unimplemented::UNREACHABLE, @@ -1499,7 +1498,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&open_options::NONSENSICAL_OPEN_OPTIONS), LintId::of(&option_env_unwrap::OPTION_ENV_UNWRAP), LintId::of(&overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL), - LintId::of(&panic_unimplemented::PANIC_PARAMS), LintId::of(&partialeq_ne_impl::PARTIALEQ_NE_IMPL), LintId::of(&precedence::PRECEDENCE), LintId::of(&ptr::CMP_NULL), @@ -1666,7 +1664,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST), LintId::of(&non_expressive_names::JUST_UNDERSCORES_AND_DIGITS), LintId::of(&non_expressive_names::MANY_SINGLE_CHAR_NAMES), - LintId::of(&panic_unimplemented::PANIC_PARAMS), LintId::of(&ptr::CMP_NULL), LintId::of(&ptr::PTR_ARG), LintId::of(&ptr_eq::PTR_EQ), diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs index 3d888fe73257..8b10d0716471 100644 --- a/clippy_lints/src/panic_unimplemented.rs +++ b/clippy_lints/src/panic_unimplemented.rs @@ -1,30 +1,10 @@ -use crate::utils::{is_direct_expn_of, is_expn_of, match_panic_call, span_lint}; +use crate::utils::{is_expn_of, match_panic_call, span_lint}; use if_chain::if_chain; -use rustc_ast::ast::LitKind; -use rustc_hir::{Expr, ExprKind}; +use rustc_hir::Expr; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Span; -declare_clippy_lint! { - /// **What it does:** Checks for missing parameters in `panic!`. - /// - /// **Why is this bad?** Contrary to the `format!` family of macros, there are - /// two forms of `panic!`: if there are no parameters given, the first argument - /// is not a format string and used literally. So while `format!("{}")` will - /// fail to compile, `panic!("{}")` will not. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```no_run - /// panic!("This `panic!` is probably missing a parameter there: {}"); - /// ``` - pub PANIC_PARAMS, - style, - "missing parameters in `panic!` calls" -} - declare_clippy_lint! { /// **What it does:** Checks for usage of `panic!`. /// @@ -89,11 +69,11 @@ declare_clippy_lint! { "`unreachable!` should not be present in production code" } -declare_lint_pass!(PanicUnimplemented => [PANIC_PARAMS, UNIMPLEMENTED, UNREACHABLE, TODO, PANIC]); +declare_lint_pass!(PanicUnimplemented => [UNIMPLEMENTED, UNREACHABLE, TODO, PANIC]); impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let Some(params) = match_panic_call(cx, expr) { + if let Some(_) = match_panic_call(cx, expr) { let span = get_outer_span(expr); if is_expn_of(expr.span, "unimplemented").is_some() { span_lint( @@ -113,7 +93,6 @@ impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented { ); } else if is_expn_of(expr.span, "panic").is_some() { span_lint(cx, PANIC, span, "`panic` should not be present in production code"); - match_panic(params, expr, cx); } } } @@ -132,20 +111,3 @@ fn get_outer_span(expr: &Expr<'_>) -> Span { } } } - -fn match_panic(params: &[Expr<'_>], expr: &Expr<'_>, cx: &LateContext<'_>) { - if_chain! { - if let ExprKind::Lit(ref lit) = params[0].kind; - if is_direct_expn_of(expr.span, "panic").is_some(); - if let LitKind::Str(ref string, _) = lit.node; - let string = string.as_str().replace("{{", "").replace("}}", ""); - if let Some(par) = string.find('{'); - if string[par..].contains('}'); - if params[0].span.source_callee().is_none(); - if params[0].span.lo() != params[0].span.hi(); - then { - span_lint(cx, PANIC_PARAMS, params[0].span, - "you probably are missing some parameter in your format string"); - } - } -} diff --git a/tests/ui/panic.rs b/tests/ui/panic.rs deleted file mode 100644 index 6e004aa9a924..000000000000 --- a/tests/ui/panic.rs +++ /dev/null @@ -1,61 +0,0 @@ -#![warn(clippy::panic_params)] -#![allow(clippy::assertions_on_constants)] -fn missing() { - if true { - panic!("{}"); - } else if false { - panic!("{:?}"); - } else { - assert!(true, "here be missing values: {}"); - } - - panic!("{{{this}}}"); -} - -fn ok_single() { - panic!("foo bar"); -} - -fn ok_inner() { - // Test for #768 - assert!("foo bar".contains(&format!("foo {}", "bar"))); -} - -fn ok_multiple() { - panic!("{}", "This is {ok}"); -} - -fn ok_bracket() { - match 42 { - 1337 => panic!("{so is this"), - 666 => panic!("so is this}"), - _ => panic!("}so is that{"), - } -} - -const ONE: u32 = 1; - -fn ok_nomsg() { - assert!({ 1 == ONE }); - assert!(if 1 == ONE { ONE == 1 } else { false }); -} - -fn ok_escaped() { - panic!("{{ why should this not be ok? }}"); - panic!(" or {{ that ?"); - panic!(" or }} this ?"); - panic!(" {or {{ that ?"); - panic!(" }or }} this ?"); - panic!("{{ test }"); - panic!("{case }}"); -} - -fn main() { - missing(); - ok_single(); - ok_multiple(); - ok_bracket(); - ok_inner(); - ok_nomsg(); - ok_escaped(); -} diff --git a/tests/ui/panic.stderr b/tests/ui/panic.stderr deleted file mode 100644 index 1f8ff8ccf557..000000000000 --- a/tests/ui/panic.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: you probably are missing some parameter in your format string - --> $DIR/panic.rs:5:16 - | -LL | panic!("{}"); - | ^^^^ - | - = note: `-D clippy::panic-params` implied by `-D warnings` - -error: you probably are missing some parameter in your format string - --> $DIR/panic.rs:7:16 - | -LL | panic!("{:?}"); - | ^^^^^^ - -error: you probably are missing some parameter in your format string - --> $DIR/panic.rs:9:23 - | -LL | assert!(true, "here be missing values: {}"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: you probably are missing some parameter in your format string - --> $DIR/panic.rs:12:12 - | -LL | panic!("{{{this}}}"); - | ^^^^^^^^^^^^ - -error: aborting due to 4 previous errors - From 88db5c0afff247fc69988209f17009a1b1d86565 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Thu, 19 Nov 2020 19:47:25 +0100 Subject: [PATCH 0136/1222] Clippy: Match on assert!() expansions without an inner block. --- clippy_lints/src/assertions_on_constants.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index a2ccb0369c4a..a52f0997d439 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -129,8 +129,11 @@ fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) if let ExprKind::Block(ref block, _) = arms[0].body.kind; if block.stmts.is_empty(); if let Some(block_expr) = &block.expr; - if let ExprKind::Block(ref inner_block, _) = block_expr.kind; - if let Some(begin_panic_call) = &inner_block.expr; + // inner block is optional. unwarp it if it exists, or use the expression as is otherwise. + if let Some(begin_panic_call) = match block_expr.kind { + ExprKind::Block(ref inner_block, _) => &inner_block.expr, + _ => &block.expr, + }; // function call if let Some(args) = match_panic_call(cx, begin_panic_call); if args.len() == 1; From 38f3bd5ca53bff5fe8d350c66b4886e976697ef5 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sun, 22 Nov 2020 02:13:53 +0100 Subject: [PATCH 0137/1222] Thread `Constness` through selection --- clippy_lints/src/future_not_send.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index d2a322e1223c..f9697afe4052 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { for &(p, _span) in preds { let p = p.subst(cx.tcx, subst); if let Some(trait_ref) = p.to_opt_poly_trait_ref() { - if Some(trait_ref.def_id()) == cx.tcx.lang_items().future_trait() { + if Some(trait_ref.value.def_id()) == cx.tcx.lang_items().future_trait() { is_future = true; break; } From 399383c0d6330b1f9cceb8dc73f85365e7870df8 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 27 Oct 2020 13:10:31 +0000 Subject: [PATCH 0138/1222] Drop support for cloudabi targets --- clippy_lints/src/attrs.rs | 2 +- tests/ui/mismatched_target_os_non_unix.fixed | 5 +-- tests/ui/mismatched_target_os_non_unix.rs | 5 +-- tests/ui/mismatched_target_os_non_unix.stderr | 35 ++++++------------- 4 files changed, 13 insertions(+), 34 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 57702dafa6a0..9a667aa61b4f 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -40,7 +40,7 @@ static UNIX_SYSTEMS: &[&str] = &[ ]; // NOTE: windows is excluded from the list because it's also a valid target family. -static NON_UNIX_SYSTEMS: &[&str] = &["cloudabi", "hermit", "none", "wasi"]; +static NON_UNIX_SYSTEMS: &[&str] = &["hermit", "none", "wasi"]; declare_clippy_lint! { /// **What it does:** Checks for items annotated with `#[inline(always)]`, diff --git a/tests/ui/mismatched_target_os_non_unix.fixed b/tests/ui/mismatched_target_os_non_unix.fixed index 3ee77dcac31a..f219a570e7fc 100644 --- a/tests/ui/mismatched_target_os_non_unix.fixed +++ b/tests/ui/mismatched_target_os_non_unix.fixed @@ -3,9 +3,6 @@ #![warn(clippy::mismatched_target_os)] #![allow(unused)] -#[cfg(target_os = "cloudabi")] -fn cloudabi() {} - #[cfg(target_os = "hermit")] fn hermit() {} @@ -16,7 +13,7 @@ fn wasi() {} fn none() {} // list with conditions -#[cfg(all(not(any(windows, target_os = "cloudabi")), target_os = "wasi"))] +#[cfg(all(not(windows), target_os = "wasi"))] fn list() {} // windows is a valid target family, should be ignored diff --git a/tests/ui/mismatched_target_os_non_unix.rs b/tests/ui/mismatched_target_os_non_unix.rs index 9cc411418e4c..8a8ae756a4fc 100644 --- a/tests/ui/mismatched_target_os_non_unix.rs +++ b/tests/ui/mismatched_target_os_non_unix.rs @@ -3,9 +3,6 @@ #![warn(clippy::mismatched_target_os)] #![allow(unused)] -#[cfg(cloudabi)] -fn cloudabi() {} - #[cfg(hermit)] fn hermit() {} @@ -16,7 +13,7 @@ fn wasi() {} fn none() {} // list with conditions -#[cfg(all(not(any(windows, cloudabi)), wasi))] +#[cfg(all(not(windows), wasi))] fn list() {} // windows is a valid target family, should be ignored diff --git a/tests/ui/mismatched_target_os_non_unix.stderr b/tests/ui/mismatched_target_os_non_unix.stderr index 78fc27752d23..5f1b09083046 100644 --- a/tests/ui/mismatched_target_os_non_unix.stderr +++ b/tests/ui/mismatched_target_os_non_unix.stderr @@ -1,23 +1,15 @@ error: operating system used in target family position --> $DIR/mismatched_target_os_non_unix.rs:6:1 | -LL | #[cfg(cloudabi)] - | ^^^^^^--------^^ - | | - | help: try: `target_os = "cloudabi"` - | - = note: `-D clippy::mismatched-target-os` implied by `-D warnings` - -error: operating system used in target family position - --> $DIR/mismatched_target_os_non_unix.rs:9:1 - | LL | #[cfg(hermit)] | ^^^^^^------^^ | | | help: try: `target_os = "hermit"` + | + = note: `-D clippy::mismatched-target-os` implied by `-D warnings` error: operating system used in target family position - --> $DIR/mismatched_target_os_non_unix.rs:12:1 + --> $DIR/mismatched_target_os_non_unix.rs:9:1 | LL | #[cfg(wasi)] | ^^^^^^----^^ @@ -25,7 +17,7 @@ LL | #[cfg(wasi)] | help: try: `target_os = "wasi"` error: operating system used in target family position - --> $DIR/mismatched_target_os_non_unix.rs:15:1 + --> $DIR/mismatched_target_os_non_unix.rs:12:1 | LL | #[cfg(none)] | ^^^^^^----^^ @@ -33,19 +25,12 @@ LL | #[cfg(none)] | help: try: `target_os = "none"` error: operating system used in target family position - --> $DIR/mismatched_target_os_non_unix.rs:19:1 - | -LL | #[cfg(all(not(any(windows, cloudabi)), wasi))] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: try - | -LL | #[cfg(all(not(any(windows, target_os = "cloudabi")), wasi))] - | ^^^^^^^^^^^^^^^^^^^^^^ -help: try + --> $DIR/mismatched_target_os_non_unix.rs:16:1 | -LL | #[cfg(all(not(any(windows, cloudabi)), target_os = "wasi"))] - | ^^^^^^^^^^^^^^^^^^ +LL | #[cfg(all(not(windows), wasi))] + | ^^^^^^^^^^^^^^^^^^^^^^^^----^^^ + | | + | help: try: `target_os = "wasi"` -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors From 2b0dacac3fe1b7b36192b1eb09a5dc0d057eb429 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Mon, 23 Nov 2020 13:52:27 +0100 Subject: [PATCH 0139/1222] Fix ICE in utils::implements_trait This only happend when debug_assertions were enabled in rustc --- clippy_lints/src/utils/mod.rs | 3 +++ tests/ui/crashes/implements-trait.rs | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 tests/ui/crashes/implements-trait.rs diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 5bd64dcb541f..e9c71e23a670 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -365,6 +365,9 @@ pub fn implements_trait<'tcx>( return false; } let ty = cx.tcx.erase_regions(ty); + if ty.has_escaping_bound_vars() { + return false; + } let ty_params = cx.tcx.mk_substs(ty_params.iter()); cx.tcx.type_implements_trait((trait_id, ty, ty_params, cx.param_env)) } diff --git a/tests/ui/crashes/implements-trait.rs b/tests/ui/crashes/implements-trait.rs new file mode 100644 index 000000000000..4502b0147a83 --- /dev/null +++ b/tests/ui/crashes/implements-trait.rs @@ -0,0 +1,5 @@ +#[allow(clippy::needless_borrowed_reference)] +fn main() { + let mut v = Vec::::new(); + let _ = v.iter_mut().filter(|&ref a| a.is_empty()); +} From 953eb6d2a129eb8cba761ccaac661d65bef9db67 Mon Sep 17 00:00:00 2001 From: Camelid Date: Sat, 24 Oct 2020 18:35:46 -0700 Subject: [PATCH 0140/1222] Qualify `panic!` as `core::panic!` in non-built-in `core` macros Otherwise code like this #![no_implicit_prelude] fn main() { ::std::todo!(); ::std::unimplemented!(); } will fail to compile, which is unfortunate and presumably unintended. This changes many invocations of `panic!` in a `macro_rules!` definition to invocations of `$crate::panic!`, which makes the invocations hygienic. Note that this does not make the built-in macro `assert!` hygienic. --- tests/ui/logic_bug.rs | 2 +- tests/ui/nonminimal_bool.rs | 2 +- tests/ui/nonminimal_bool_methods.rs | 2 +- tests/ui/wildcard_enum_match_arm.fixed | 2 +- tests/ui/wildcard_enum_match_arm.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/ui/logic_bug.rs b/tests/ui/logic_bug.rs index b4163d776e73..a01c6ef99db9 100644 --- a/tests/ui/logic_bug.rs +++ b/tests/ui/logic_bug.rs @@ -1,4 +1,4 @@ -#![allow(unused, clippy::many_single_char_names)] +#![allow(unused, clippy::many_single_char_names, clippy::diverging_sub_expression)] #![warn(clippy::logic_bug)] fn main() { diff --git a/tests/ui/nonminimal_bool.rs b/tests/ui/nonminimal_bool.rs index 7ea154cb9b01..971be26278f3 100644 --- a/tests/ui/nonminimal_bool.rs +++ b/tests/ui/nonminimal_bool.rs @@ -1,4 +1,4 @@ -#![allow(unused, clippy::many_single_char_names)] +#![allow(unused, clippy::many_single_char_names, clippy::diverging_sub_expression)] #![warn(clippy::nonminimal_bool)] fn main() { diff --git a/tests/ui/nonminimal_bool_methods.rs b/tests/ui/nonminimal_bool_methods.rs index 4de48cd0879a..907587402908 100644 --- a/tests/ui/nonminimal_bool_methods.rs +++ b/tests/ui/nonminimal_bool_methods.rs @@ -1,4 +1,4 @@ -#![allow(unused, clippy::many_single_char_names)] +#![allow(unused, clippy::many_single_char_names, clippy::diverging_sub_expression)] #![warn(clippy::nonminimal_bool)] fn methods_with_negation() { diff --git a/tests/ui/wildcard_enum_match_arm.fixed b/tests/ui/wildcard_enum_match_arm.fixed index 4f8754a93012..b1e5742b7853 100644 --- a/tests/ui/wildcard_enum_match_arm.fixed +++ b/tests/ui/wildcard_enum_match_arm.fixed @@ -7,7 +7,7 @@ dead_code, clippy::single_match, clippy::wildcard_in_or_patterns, - clippy::unnested_or_patterns + clippy::unnested_or_patterns, clippy::diverging_sub_expression )] use std::io::ErrorKind; diff --git a/tests/ui/wildcard_enum_match_arm.rs b/tests/ui/wildcard_enum_match_arm.rs index 5e66644ceca0..cd3ec3ea8d26 100644 --- a/tests/ui/wildcard_enum_match_arm.rs +++ b/tests/ui/wildcard_enum_match_arm.rs @@ -7,7 +7,7 @@ dead_code, clippy::single_match, clippy::wildcard_in_or_patterns, - clippy::unnested_or_patterns + clippy::unnested_or_patterns, clippy::diverging_sub_expression )] use std::io::ErrorKind; From 15a5a25c9fb1694f1aa8f763aae6beda53bb58fc Mon Sep 17 00:00:00 2001 From: flip1995 Date: Wed, 7 Oct 2020 16:04:22 +0200 Subject: [PATCH 0141/1222] clippy: Let rustc handle describing lints --- src/driver.rs | 121 -------------------------------------------------- 1 file changed, 121 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index cc71cc66b925..ef31c72481a2 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -8,7 +8,6 @@ // FIXME: switch to something more ergonomic here, once available. // (Currently there is no way to opt into sysroot crates without `extern crate`.) -extern crate rustc_data_structures; extern crate rustc_driver; extern crate rustc_errors; extern crate rustc_interface; @@ -26,8 +25,6 @@ use std::panic; use std::path::{Path, PathBuf}; use std::process::{exit, Command}; -mod lintlist; - /// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If /// true, then return it. The parameter is assumed to be either `--arg=value` or `--arg value`. fn arg_value<'a, T: Deref>( @@ -92,113 +89,6 @@ impl rustc_driver::Callbacks for ClippyCallbacks { } } -#[allow(clippy::find_map, clippy::filter_map)] -fn describe_lints() { - use lintlist::{Level, Lint, ALL_LINTS, LINT_LEVELS}; - use rustc_data_structures::fx::FxHashSet; - - println!( - " -Available lint options: - -W Warn about - -A Allow - -D Deny - -F Forbid (deny and all attempts to override) - -" - ); - - let lint_level = |lint: &Lint| { - LINT_LEVELS - .iter() - .find(|level_mapping| level_mapping.0 == lint.group) - .map(|(_, level)| match level { - Level::Allow => "allow", - Level::Warn => "warn", - Level::Deny => "deny", - }) - .unwrap() - }; - - let mut lints: Vec<_> = ALL_LINTS.iter().collect(); - // The sort doesn't case-fold but it's doubtful we care. - lints.sort_by_cached_key(|x: &&Lint| (lint_level(x), x.name)); - - let max_lint_name_len = lints - .iter() - .map(|lint| lint.name.len()) - .map(|len| len + "clippy::".len()) - .max() - .unwrap_or(0); - - let padded = |x: &str| { - let mut s = " ".repeat(max_lint_name_len - x.chars().count()); - s.push_str(x); - s - }; - - let scoped = |x: &str| format!("clippy::{}", x); - - let lint_groups: FxHashSet<_> = lints.iter().map(|lint| lint.group).collect(); - - println!("Lint checks provided by clippy:\n"); - println!(" {} {:7.7} meaning", padded("name"), "default"); - println!(" {} {:7.7} -------", padded("----"), "-------"); - - let print_lints = |lints: &[&Lint]| { - for lint in lints { - let name = lint.name.replace("_", "-"); - println!( - " {} {:7.7} {}", - padded(&scoped(&name)), - lint_level(lint), - lint.desc - ); - } - println!("\n"); - }; - - print_lints(&lints); - - let max_group_name_len = std::cmp::max( - "clippy::all".len(), - lint_groups - .iter() - .map(|group| group.len()) - .map(|len| len + "clippy::".len()) - .max() - .unwrap_or(0), - ); - - let padded_group = |x: &str| { - let mut s = " ".repeat(max_group_name_len - x.chars().count()); - s.push_str(x); - s - }; - - println!("Lint groups provided by clippy:\n"); - println!(" {} sub-lints", padded_group("name")); - println!(" {} ---------", padded_group("----")); - println!(" {} the set of all clippy lints", padded_group("clippy::all")); - - let print_lint_groups = || { - for group in lint_groups { - let name = group.to_lowercase().replace("_", "-"); - let desc = lints - .iter() - .filter(|&lint| lint.group == group) - .map(|lint| lint.name) - .map(|name| name.replace("_", "-")) - .collect::>() - .join(", "); - println!(" {} {}", padded_group(&scoped(&name)), desc); - } - println!("\n"); - }; - - print_lint_groups(); -} - fn display_help() { println!( "\ @@ -379,17 +269,6 @@ pub fn main() { exit(0); } - let should_describe_lints = || { - let args: Vec<_> = env::args().collect(); - args.windows(2) - .any(|args| args[1] == "help" && matches!(args[0].as_str(), "-W" | "-A" | "-D" | "-F")) - }; - - if !wrapper_mode && should_describe_lints() { - describe_lints(); - exit(0); - } - // this conditional check for the --sysroot flag is there so users can call // `clippy_driver` directly // without having to pass --sysroot or anything From 784f3b3b73001f47063def7a7c7e6dfa2357e126 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Wed, 7 Oct 2020 16:05:13 +0200 Subject: [PATCH 0142/1222] clippy: Remove now obsolete lintlist module Also stop updating the lintlist module in clippy_dev update_lints --- clippy_dev/src/update_lints.rs | 15 +- src/lintlist/lint.rs | 27 - src/lintlist/mod.rs | 2942 -------------------------------- 3 files changed, 1 insertion(+), 2983 deletions(-) delete mode 100644 src/lintlist/lint.rs delete mode 100644 src/lintlist/mod.rs diff --git a/clippy_dev/src/update_lints.rs b/clippy_dev/src/update_lints.rs index 556b67e0b374..fcf093f8835d 100644 --- a/clippy_dev/src/update_lints.rs +++ b/clippy_dev/src/update_lints.rs @@ -22,20 +22,7 @@ pub fn run(update_mode: UpdateMode) { let usable_lint_count = round_to_fifty(usable_lints.len()); - let mut file_change = replace_region_in_file( - Path::new("src/lintlist/mod.rs"), - "begin lint list", - "end lint list", - false, - update_mode == UpdateMode::Change, - || { - format!("vec!{:#?}", sorted_usable_lints) - .lines() - .map(ToString::to_string) - .collect::>() - }, - ) - .changed; + let mut file_change = false; file_change |= replace_region_in_file( Path::new("README.md"), diff --git a/src/lintlist/lint.rs b/src/lintlist/lint.rs deleted file mode 100644 index c817d83b33ae..000000000000 --- a/src/lintlist/lint.rs +++ /dev/null @@ -1,27 +0,0 @@ -/// Lint data parsed from the Clippy source code. -#[derive(Clone, PartialEq, Debug)] -pub struct Lint { - pub name: &'static str, - pub group: &'static str, - pub desc: &'static str, - pub deprecation: Option<&'static str>, - pub module: &'static str, -} - -#[derive(PartialOrd, PartialEq, Ord, Eq)] -pub enum Level { - Allow, - Warn, - Deny, -} - -pub const LINT_LEVELS: [(&str, Level); 8] = [ - ("correctness", Level::Deny), - ("style", Level::Warn), - ("complexity", Level::Warn), - ("perf", Level::Warn), - ("restriction", Level::Allow), - ("pedantic", Level::Allow), - ("nursery", Level::Allow), - ("cargo", Level::Allow), -]; diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs deleted file mode 100644 index 1d906d20ad47..000000000000 --- a/src/lintlist/mod.rs +++ /dev/null @@ -1,2942 +0,0 @@ -//! This file is managed by `cargo dev update_lints`. Do not edit or format this file. - -use std::lazy::SyncLazy; - -pub mod lint; -pub use lint::Level; -pub use lint::Lint; -pub use lint::LINT_LEVELS; - -#[rustfmt::skip] -pub static ALL_LINTS: SyncLazy> = SyncLazy::new(|| { -// begin lint list, do not remove this comment, it’s used in `update_lints` -vec![ - Lint { - name: "absurd_extreme_comparisons", - group: "correctness", - desc: "a comparison with a maximum or minimum value that is always true or false", - deprecation: None, - module: "types", - }, - Lint { - name: "almost_swapped", - group: "correctness", - desc: "`foo = bar; bar = foo` sequence", - deprecation: None, - module: "swap", - }, - Lint { - name: "approx_constant", - group: "correctness", - desc: "the approximate of a known float constant (in `std::fXX::consts`)", - deprecation: None, - module: "approx_const", - }, - Lint { - name: "as_conversions", - group: "restriction", - desc: "using a potentially dangerous silent `as` conversion", - deprecation: None, - module: "as_conversions", - }, - Lint { - name: "assertions_on_constants", - group: "style", - desc: "`assert!(true)` / `assert!(false)` will be optimized out by the compiler, and should probably be replaced by a `panic!()` or `unreachable!()`", - deprecation: None, - module: "assertions_on_constants", - }, - Lint { - name: "assign_op_pattern", - group: "style", - desc: "assigning the result of an operation on a variable to that same variable", - deprecation: None, - module: "assign_ops", - }, - Lint { - name: "async_yields_async", - group: "correctness", - desc: "async blocks that return a type that can be awaited", - deprecation: None, - module: "async_yields_async", - }, - Lint { - name: "await_holding_lock", - group: "pedantic", - desc: "Inside an async function, holding a MutexGuard while calling await", - deprecation: None, - module: "await_holding_invalid", - }, - Lint { - name: "await_holding_refcell_ref", - group: "pedantic", - desc: "Inside an async function, holding a RefCell ref while calling await", - deprecation: None, - module: "await_holding_invalid", - }, - Lint { - name: "bad_bit_mask", - group: "correctness", - desc: "expressions of the form `_ & mask == select` that will only ever return `true` or `false`", - deprecation: None, - module: "bit_mask", - }, - Lint { - name: "bind_instead_of_map", - group: "complexity", - desc: "using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`", - deprecation: None, - module: "methods", - }, - Lint { - name: "blacklisted_name", - group: "style", - desc: "usage of a blacklisted/placeholder name", - deprecation: None, - module: "blacklisted_name", - }, - Lint { - name: "blanket_clippy_restriction_lints", - group: "style", - desc: "enabling the complete restriction group", - deprecation: None, - module: "attrs", - }, - Lint { - name: "blocks_in_if_conditions", - group: "style", - desc: "useless or complex blocks that can be eliminated in conditions", - deprecation: None, - module: "blocks_in_if_conditions", - }, - Lint { - name: "bool_comparison", - group: "complexity", - desc: "comparing a variable to a boolean, e.g., `if x == true` or `if x != true`", - deprecation: None, - module: "needless_bool", - }, - Lint { - name: "borrow_interior_mutable_const", - group: "style", - desc: "referencing `const` with interior mutability", - deprecation: None, - module: "non_copy_const", - }, - Lint { - name: "borrowed_box", - group: "complexity", - desc: "a borrow of a boxed type", - deprecation: None, - module: "types", - }, - Lint { - name: "box_vec", - group: "perf", - desc: "usage of `Box>`, vector elements are already on the heap", - deprecation: None, - module: "types", - }, - Lint { - name: "boxed_local", - group: "perf", - desc: "using `Box` where unnecessary", - deprecation: None, - module: "escape", - }, - Lint { - name: "builtin_type_shadow", - group: "style", - desc: "shadowing a builtin type", - deprecation: None, - module: "misc_early", - }, - Lint { - name: "cargo_common_metadata", - group: "cargo", - desc: "common metadata is defined in `Cargo.toml`", - deprecation: None, - module: "cargo_common_metadata", - }, - Lint { - name: "cast_lossless", - group: "pedantic", - desc: "casts using `as` that are known to be lossless, e.g., `x as u64` where `x: u8`", - deprecation: None, - module: "types", - }, - Lint { - name: "cast_possible_truncation", - group: "pedantic", - desc: "casts that may cause truncation of the value, e.g., `x as u8` where `x: u32`, or `x as i32` where `x: f32`", - deprecation: None, - module: "types", - }, - Lint { - name: "cast_possible_wrap", - group: "pedantic", - desc: "casts that may cause wrapping around the value, e.g., `x as i32` where `x: u32` and `x > i32::MAX`", - deprecation: None, - module: "types", - }, - Lint { - name: "cast_precision_loss", - group: "pedantic", - desc: "casts that cause loss of precision, e.g., `x as f32` where `x: u64`", - deprecation: None, - module: "types", - }, - Lint { - name: "cast_ptr_alignment", - group: "pedantic", - desc: "cast from a pointer to a more-strictly-aligned pointer", - deprecation: None, - module: "types", - }, - Lint { - name: "cast_ref_to_mut", - group: "correctness", - desc: "a cast of reference to a mutable pointer", - deprecation: None, - module: "types", - }, - Lint { - name: "cast_sign_loss", - group: "pedantic", - desc: "casts from signed types to unsigned types, e.g., `x as u32` where `x: i32`", - deprecation: None, - module: "types", - }, - Lint { - name: "char_lit_as_u8", - group: "complexity", - desc: "casting a character literal to `u8` truncates", - deprecation: None, - module: "types", - }, - Lint { - name: "chars_last_cmp", - group: "style", - desc: "using `.chars().last()` or `.chars().next_back()` to check if a string ends with a char", - deprecation: None, - module: "methods", - }, - Lint { - name: "chars_next_cmp", - group: "style", - desc: "using `.chars().next()` to check if a string starts with a char", - deprecation: None, - module: "methods", - }, - Lint { - name: "checked_conversions", - group: "pedantic", - desc: "`try_from` could replace manual bounds checking when casting", - deprecation: None, - module: "checked_conversions", - }, - Lint { - name: "clone_double_ref", - group: "correctness", - desc: "using `clone` on `&&T`", - deprecation: None, - module: "methods", - }, - Lint { - name: "clone_on_copy", - group: "complexity", - desc: "using `clone` on a `Copy` type", - deprecation: None, - module: "methods", - }, - Lint { - name: "clone_on_ref_ptr", - group: "restriction", - desc: "using \'clone\' on a ref-counted pointer", - deprecation: None, - module: "methods", - }, - Lint { - name: "cmp_nan", - group: "correctness", - desc: "comparisons to `NAN`, which will always return false, probably not intended", - deprecation: None, - module: "misc", - }, - Lint { - name: "cmp_null", - group: "style", - desc: "comparing a pointer to a null pointer, suggesting to use `.is_null()` instead.", - deprecation: None, - module: "ptr", - }, - Lint { - name: "cmp_owned", - group: "perf", - desc: "creating owned instances for comparing with others, e.g., `x == \"foo\".to_string()`", - deprecation: None, - module: "misc", - }, - Lint { - name: "cognitive_complexity", - group: "nursery", - desc: "functions that should be split up into multiple functions", - deprecation: None, - module: "cognitive_complexity", - }, - Lint { - name: "collapsible_if", - group: "style", - desc: "`if`s that can be collapsed (e.g., `if x { if y { ... } }` and `else { if x { ... } }`)", - deprecation: None, - module: "collapsible_if", - }, - Lint { - name: "comparison_chain", - group: "style", - desc: "`if`s that can be rewritten with `match` and `cmp`", - deprecation: None, - module: "comparison_chain", - }, - Lint { - name: "comparison_to_empty", - group: "style", - desc: "checking `x == \"\"` or `x == []` (or similar) when `.is_empty()` could be used instead", - deprecation: None, - module: "len_zero", - }, - Lint { - name: "copy_iterator", - group: "pedantic", - desc: "implementing `Iterator` on a `Copy` type", - deprecation: None, - module: "copy_iterator", - }, - Lint { - name: "create_dir", - group: "restriction", - desc: "calling `std::fs::create_dir` instead of `std::fs::create_dir_all`", - deprecation: None, - module: "create_dir", - }, - Lint { - name: "crosspointer_transmute", - group: "complexity", - desc: "transmutes that have to or from types that are a pointer to the other", - deprecation: None, - module: "transmute", - }, - Lint { - name: "dbg_macro", - group: "restriction", - desc: "`dbg!` macro is intended as a debugging tool", - deprecation: None, - module: "dbg_macro", - }, - Lint { - name: "debug_assert_with_mut_call", - group: "nursery", - desc: "mutable arguments in `debug_assert{,_ne,_eq}!`", - deprecation: None, - module: "mutable_debug_assertion", - }, - Lint { - name: "decimal_literal_representation", - group: "restriction", - desc: "using decimal representation when hexadecimal would be better", - deprecation: None, - module: "literal_representation", - }, - Lint { - name: "declare_interior_mutable_const", - group: "style", - desc: "declaring `const` with interior mutability", - deprecation: None, - module: "non_copy_const", - }, - Lint { - name: "default_trait_access", - group: "pedantic", - desc: "checks for literal calls to `Default::default()`", - deprecation: None, - module: "default", - }, - Lint { - name: "deprecated_cfg_attr", - group: "complexity", - desc: "usage of `cfg_attr(rustfmt)` instead of tool attributes", - deprecation: None, - module: "attrs", - }, - Lint { - name: "deprecated_semver", - group: "correctness", - desc: "use of `#[deprecated(since = \"x\")]` where x is not semver", - deprecation: None, - module: "attrs", - }, - Lint { - name: "deref_addrof", - group: "complexity", - desc: "use of `*&` or `*&mut` in an expression", - deprecation: None, - module: "reference", - }, - Lint { - name: "derive_hash_xor_eq", - group: "correctness", - desc: "deriving `Hash` but implementing `PartialEq` explicitly", - deprecation: None, - module: "derive", - }, - Lint { - name: "derive_ord_xor_partial_ord", - group: "correctness", - desc: "deriving `Ord` but implementing `PartialOrd` explicitly", - deprecation: None, - module: "derive", - }, - Lint { - name: "disallowed_method", - group: "nursery", - desc: "use of a disallowed method call", - deprecation: None, - module: "disallowed_method", - }, - Lint { - name: "diverging_sub_expression", - group: "complexity", - desc: "whether an expression contains a diverging sub expression", - deprecation: None, - module: "eval_order_dependence", - }, - Lint { - name: "doc_markdown", - group: "pedantic", - desc: "presence of `_`, `::` or camel-case outside backticks in documentation", - deprecation: None, - module: "doc", - }, - Lint { - name: "double_comparisons", - group: "complexity", - desc: "unnecessary double comparisons that can be simplified", - deprecation: None, - module: "double_comparison", - }, - Lint { - name: "double_must_use", - group: "style", - desc: "`#[must_use]` attribute on a `#[must_use]`-returning function / method", - deprecation: None, - module: "functions", - }, - Lint { - name: "double_neg", - group: "style", - desc: "`--x`, which is a double negation of `x` and not a pre-decrement as in C/C++", - deprecation: None, - module: "misc_early", - }, - Lint { - name: "double_parens", - group: "complexity", - desc: "Warn on unnecessary double parentheses", - deprecation: None, - module: "double_parens", - }, - Lint { - name: "drop_copy", - group: "correctness", - desc: "calls to `std::mem::drop` with a value that implements Copy", - deprecation: None, - module: "drop_forget_ref", - }, - Lint { - name: "drop_ref", - group: "correctness", - desc: "calls to `std::mem::drop` with a reference instead of an owned value", - deprecation: None, - module: "drop_forget_ref", - }, - Lint { - name: "duplicate_underscore_argument", - group: "style", - desc: "function arguments having names which only differ by an underscore", - deprecation: None, - module: "misc_early", - }, - Lint { - name: "duration_subsec", - group: "complexity", - desc: "checks for calculation of subsecond microseconds or milliseconds", - deprecation: None, - module: "duration_subsec", - }, - Lint { - name: "else_if_without_else", - group: "restriction", - desc: "`if` expression with an `else if`, but without a final `else` branch", - deprecation: None, - module: "else_if_without_else", - }, - Lint { - name: "empty_enum", - group: "pedantic", - desc: "enum with no variants", - deprecation: None, - module: "empty_enum", - }, - Lint { - name: "empty_line_after_outer_attr", - group: "nursery", - desc: "empty line after outer attribute", - deprecation: None, - module: "attrs", - }, - Lint { - name: "empty_loop", - group: "style", - desc: "empty `loop {}`, which should block or sleep", - deprecation: None, - module: "loops", - }, - Lint { - name: "enum_clike_unportable_variant", - group: "correctness", - desc: "C-like enums that are `repr(isize/usize)` and have values that don\'t fit into an `i32`", - deprecation: None, - module: "enum_clike", - }, - Lint { - name: "enum_glob_use", - group: "pedantic", - desc: "use items that import all variants of an enum", - deprecation: None, - module: "wildcard_imports", - }, - Lint { - name: "enum_variant_names", - group: "style", - desc: "enums where all variants share a prefix/postfix", - deprecation: None, - module: "enum_variants", - }, - Lint { - name: "eq_op", - group: "correctness", - desc: "equal operands on both sides of a comparison or bitwise combination (e.g., `x == x`)", - deprecation: None, - module: "eq_op", - }, - Lint { - name: "erasing_op", - group: "correctness", - desc: "using erasing operations, e.g., `x * 0` or `y & 0`", - deprecation: None, - module: "erasing_op", - }, - Lint { - name: "eval_order_dependence", - group: "complexity", - desc: "whether a variable read occurs before a write depends on sub-expression evaluation order", - deprecation: None, - module: "eval_order_dependence", - }, - Lint { - name: "excessive_precision", - group: "style", - desc: "excessive precision for float literal", - deprecation: None, - module: "float_literal", - }, - Lint { - name: "exit", - group: "restriction", - desc: "`std::process::exit` is called, terminating the program", - deprecation: None, - module: "exit", - }, - Lint { - name: "expect_fun_call", - group: "perf", - desc: "using any `expect` method with a function call", - deprecation: None, - module: "methods", - }, - Lint { - name: "expect_used", - group: "restriction", - desc: "using `.expect()` on `Result` or `Option`, which might be better handled", - deprecation: None, - module: "methods", - }, - Lint { - name: "expl_impl_clone_on_copy", - group: "pedantic", - desc: "implementing `Clone` explicitly on `Copy` types", - deprecation: None, - module: "derive", - }, - Lint { - name: "explicit_counter_loop", - group: "complexity", - desc: "for-looping with an explicit counter when `_.enumerate()` would do", - deprecation: None, - module: "loops", - }, - Lint { - name: "explicit_deref_methods", - group: "pedantic", - desc: "Explicit use of deref or deref_mut method while not in a method chain.", - deprecation: None, - module: "dereference", - }, - Lint { - name: "explicit_into_iter_loop", - group: "pedantic", - desc: "for-looping over `_.into_iter()` when `_` would do", - deprecation: None, - module: "loops", - }, - Lint { - name: "explicit_iter_loop", - group: "pedantic", - desc: "for-looping over `_.iter()` or `_.iter_mut()` when `&_` or `&mut _` would do", - deprecation: None, - module: "loops", - }, - Lint { - name: "explicit_write", - group: "complexity", - desc: "using the `write!()` family of functions instead of the `print!()` family of functions, when using the latter would work", - deprecation: None, - module: "explicit_write", - }, - Lint { - name: "extra_unused_lifetimes", - group: "complexity", - desc: "unused lifetimes in function definitions", - deprecation: None, - module: "lifetimes", - }, - Lint { - name: "fallible_impl_from", - group: "nursery", - desc: "Warn on impls of `From<..>` that contain `panic!()` or `unwrap()`", - deprecation: None, - module: "fallible_impl_from", - }, - Lint { - name: "field_reassign_with_default", - group: "style", - desc: "binding initialized with Default should have its fields set in the initializer", - deprecation: None, - module: "default", - }, - Lint { - name: "filetype_is_file", - group: "restriction", - desc: "`FileType::is_file` is not recommended to test for readable file type", - deprecation: None, - module: "methods", - }, - Lint { - name: "filter_map", - group: "pedantic", - desc: "using combinations of `filter`, `map`, `filter_map` and `flat_map` which can usually be written as a single method call", - deprecation: None, - module: "methods", - }, - Lint { - name: "filter_map_next", - group: "pedantic", - desc: "using combination of `filter_map` and `next` which can usually be written as a single method call", - deprecation: None, - module: "methods", - }, - Lint { - name: "filter_next", - group: "complexity", - desc: "using `filter(p).next()`, which is more succinctly expressed as `.find(p)`", - deprecation: None, - module: "methods", - }, - Lint { - name: "find_map", - group: "pedantic", - desc: "using a combination of `find` and `map` can usually be written as a single method call", - deprecation: None, - module: "methods", - }, - Lint { - name: "flat_map_identity", - group: "complexity", - desc: "call to `flat_map` where `flatten` is sufficient", - deprecation: None, - module: "methods", - }, - Lint { - name: "float_arithmetic", - group: "restriction", - desc: "any floating-point arithmetic statement", - deprecation: None, - module: "arithmetic", - }, - Lint { - name: "float_cmp", - group: "correctness", - desc: "using `==` or `!=` on float values instead of comparing difference with an epsilon", - deprecation: None, - module: "misc", - }, - Lint { - name: "float_cmp_const", - group: "restriction", - desc: "using `==` or `!=` on float constants instead of comparing difference with an epsilon", - deprecation: None, - module: "misc", - }, - Lint { - name: "float_equality_without_abs", - group: "correctness", - desc: "float equality check without `.abs()`", - deprecation: None, - module: "float_equality_without_abs", - }, - Lint { - name: "fn_address_comparisons", - group: "correctness", - desc: "comparison with an address of a function item", - deprecation: None, - module: "unnamed_address", - }, - Lint { - name: "fn_params_excessive_bools", - group: "pedantic", - desc: "using too many bools in function parameters", - deprecation: None, - module: "excessive_bools", - }, - Lint { - name: "fn_to_numeric_cast", - group: "style", - desc: "casting a function pointer to a numeric type other than usize", - deprecation: None, - module: "types", - }, - Lint { - name: "fn_to_numeric_cast_with_truncation", - group: "style", - desc: "casting a function pointer to a numeric type not wide enough to store the address", - deprecation: None, - module: "types", - }, - Lint { - name: "for_kv_map", - group: "style", - desc: "looping on a map using `iter` when `keys` or `values` would do", - deprecation: None, - module: "loops", - }, - Lint { - name: "for_loops_over_fallibles", - group: "correctness", - desc: "for-looping over an `Option` or a `Result`, which is more clearly expressed as an `if let`", - deprecation: None, - module: "loops", - }, - Lint { - name: "forget_copy", - group: "correctness", - desc: "calls to `std::mem::forget` with a value that implements Copy", - deprecation: None, - module: "drop_forget_ref", - }, - Lint { - name: "forget_ref", - group: "correctness", - desc: "calls to `std::mem::forget` with a reference instead of an owned value", - deprecation: None, - module: "drop_forget_ref", - }, - Lint { - name: "from_iter_instead_of_collect", - group: "style", - desc: "use `.collect()` instead of `::from_iter()`", - deprecation: None, - module: "methods", - }, - Lint { - name: "future_not_send", - group: "nursery", - desc: "public Futures must be Send", - deprecation: None, - module: "future_not_send", - }, - Lint { - name: "get_last_with_len", - group: "complexity", - desc: "Using `x.get(x.len() - 1)` when `x.last()` is correct and simpler", - deprecation: None, - module: "get_last_with_len", - }, - Lint { - name: "get_unwrap", - group: "restriction", - desc: "using `.get().unwrap()` or `.get_mut().unwrap()` when using `[]` would work instead", - deprecation: None, - module: "methods", - }, - Lint { - name: "identity_op", - group: "complexity", - desc: "using identity operations, e.g., `x + 0` or `y / 1`", - deprecation: None, - module: "identity_op", - }, - Lint { - name: "if_let_mutex", - group: "correctness", - desc: "locking a `Mutex` in an `if let` block can cause deadlocks", - deprecation: None, - module: "if_let_mutex", - }, - Lint { - name: "if_let_some_result", - group: "style", - desc: "usage of `ok()` in `if let Some(pat)` statements is unnecessary, match on `Ok(pat)` instead", - deprecation: None, - module: "if_let_some_result", - }, - Lint { - name: "if_not_else", - group: "pedantic", - desc: "`if` branches that could be swapped so no negation operation is necessary on the condition", - deprecation: None, - module: "if_not_else", - }, - Lint { - name: "if_same_then_else", - group: "correctness", - desc: "`if` with the same `then` and `else` blocks", - deprecation: None, - module: "copies", - }, - Lint { - name: "ifs_same_cond", - group: "correctness", - desc: "consecutive `if`s with the same condition", - deprecation: None, - module: "copies", - }, - Lint { - name: "implicit_hasher", - group: "pedantic", - desc: "missing generalization over different hashers", - deprecation: None, - module: "types", - }, - Lint { - name: "implicit_return", - group: "restriction", - desc: "use a return statement like `return expr` instead of an expression", - deprecation: None, - module: "implicit_return", - }, - Lint { - name: "implicit_saturating_sub", - group: "pedantic", - desc: "Perform saturating subtraction instead of implicitly checking lower bound of data type", - deprecation: None, - module: "implicit_saturating_sub", - }, - Lint { - name: "imprecise_flops", - group: "nursery", - desc: "usage of imprecise floating point operations", - deprecation: None, - module: "floating_point_arithmetic", - }, - Lint { - name: "inconsistent_digit_grouping", - group: "style", - desc: "integer literals with digits grouped inconsistently", - deprecation: None, - module: "literal_representation", - }, - Lint { - name: "indexing_slicing", - group: "restriction", - desc: "indexing/slicing usage", - deprecation: None, - module: "indexing_slicing", - }, - Lint { - name: "ineffective_bit_mask", - group: "correctness", - desc: "expressions where a bit mask will be rendered useless by a comparison, e.g., `(x | 1) > 2`", - deprecation: None, - module: "bit_mask", - }, - Lint { - name: "inefficient_to_string", - group: "pedantic", - desc: "using `to_string` on `&&T` where `T: ToString`", - deprecation: None, - module: "methods", - }, - Lint { - name: "infallible_destructuring_match", - group: "style", - desc: "a `match` statement with a single infallible arm instead of a `let`", - deprecation: None, - module: "matches", - }, - Lint { - name: "infinite_iter", - group: "correctness", - desc: "infinite iteration", - deprecation: None, - module: "infinite_iter", - }, - Lint { - name: "inherent_to_string", - group: "style", - desc: "type implements inherent method `to_string()`, but should instead implement the `Display` trait", - deprecation: None, - module: "inherent_to_string", - }, - Lint { - name: "inherent_to_string_shadow_display", - group: "correctness", - desc: "type implements inherent method `to_string()`, which gets shadowed by the implementation of the `Display` trait", - deprecation: None, - module: "inherent_to_string", - }, - Lint { - name: "inline_always", - group: "pedantic", - desc: "use of `#[inline(always)]`", - deprecation: None, - module: "attrs", - }, - Lint { - name: "inline_asm_x86_att_syntax", - group: "restriction", - desc: "prefer Intel x86 assembly syntax", - deprecation: None, - module: "asm_syntax", - }, - Lint { - name: "inline_asm_x86_intel_syntax", - group: "restriction", - desc: "prefer AT&T x86 assembly syntax", - deprecation: None, - module: "asm_syntax", - }, - Lint { - name: "inline_fn_without_body", - group: "correctness", - desc: "use of `#[inline]` on trait methods without bodies", - deprecation: None, - module: "inline_fn_without_body", - }, - Lint { - name: "int_plus_one", - group: "complexity", - desc: "instead of using `x >= y + 1`, use `x > y`", - deprecation: None, - module: "int_plus_one", - }, - Lint { - name: "integer_arithmetic", - group: "restriction", - desc: "any integer arithmetic expression which could overflow or panic", - deprecation: None, - module: "arithmetic", - }, - Lint { - name: "integer_division", - group: "restriction", - desc: "integer division may cause loss of precision", - deprecation: None, - module: "integer_division", - }, - Lint { - name: "into_iter_on_ref", - group: "style", - desc: "using `.into_iter()` on a reference", - deprecation: None, - module: "methods", - }, - Lint { - name: "invalid_atomic_ordering", - group: "correctness", - desc: "usage of invalid atomic ordering in atomic operations and memory fences", - deprecation: None, - module: "atomic_ordering", - }, - Lint { - name: "invalid_regex", - group: "correctness", - desc: "invalid regular expressions", - deprecation: None, - module: "regex", - }, - Lint { - name: "invalid_upcast_comparisons", - group: "pedantic", - desc: "a comparison involving an upcast which is always true or false", - deprecation: None, - module: "types", - }, - Lint { - name: "invisible_characters", - group: "correctness", - desc: "using an invisible character in a string literal, which is confusing", - deprecation: None, - module: "unicode", - }, - Lint { - name: "items_after_statements", - group: "pedantic", - desc: "blocks where an item comes after a statement", - deprecation: None, - module: "items_after_statements", - }, - Lint { - name: "iter_cloned_collect", - group: "style", - desc: "using `.cloned().collect()` on slice to create a `Vec`", - deprecation: None, - module: "methods", - }, - Lint { - name: "iter_next_loop", - group: "correctness", - desc: "for-looping over `_.next()` which is probably not intended", - deprecation: None, - module: "loops", - }, - Lint { - name: "iter_next_slice", - group: "style", - desc: "using `.iter().next()` on a sliced array, which can be shortened to just `.get()`", - deprecation: None, - module: "methods", - }, - Lint { - name: "iter_nth", - group: "perf", - desc: "using `.iter().nth()` on a standard library type with O(1) element access", - deprecation: None, - module: "methods", - }, - Lint { - name: "iter_nth_zero", - group: "style", - desc: "replace `iter.nth(0)` with `iter.next()`", - deprecation: None, - module: "methods", - }, - Lint { - name: "iter_skip_next", - group: "style", - desc: "using `.skip(x).next()` on an iterator", - deprecation: None, - module: "methods", - }, - Lint { - name: "iterator_step_by_zero", - group: "correctness", - desc: "using `Iterator::step_by(0)`, which will panic at runtime", - deprecation: None, - module: "methods", - }, - Lint { - name: "just_underscores_and_digits", - group: "style", - desc: "unclear name", - deprecation: None, - module: "non_expressive_names", - }, - Lint { - name: "large_const_arrays", - group: "perf", - desc: "large non-scalar const array may cause performance overhead", - deprecation: None, - module: "large_const_arrays", - }, - Lint { - name: "large_digit_groups", - group: "pedantic", - desc: "grouping digits into groups that are too large", - deprecation: None, - module: "literal_representation", - }, - Lint { - name: "large_enum_variant", - group: "perf", - desc: "large size difference between variants on an enum", - deprecation: None, - module: "large_enum_variant", - }, - Lint { - name: "large_stack_arrays", - group: "pedantic", - desc: "allocating large arrays on stack may cause stack overflow", - deprecation: None, - module: "large_stack_arrays", - }, - Lint { - name: "large_types_passed_by_value", - group: "pedantic", - desc: "functions taking large arguments by value", - deprecation: None, - module: "pass_by_ref_or_value", - }, - Lint { - name: "len_without_is_empty", - group: "style", - desc: "traits or impls with a public `len` method but no corresponding `is_empty` method", - deprecation: None, - module: "len_zero", - }, - Lint { - name: "len_zero", - group: "style", - desc: "checking `.len() == 0` or `.len() > 0` (or similar) when `.is_empty()` could be used instead", - deprecation: None, - module: "len_zero", - }, - Lint { - name: "let_and_return", - group: "style", - desc: "creating a let-binding and then immediately returning it like `let x = expr; x` at the end of a block", - deprecation: None, - module: "returns", - }, - Lint { - name: "let_underscore_drop", - group: "pedantic", - desc: "non-binding let on a type that implements `Drop`", - deprecation: None, - module: "let_underscore", - }, - Lint { - name: "let_underscore_lock", - group: "correctness", - desc: "non-binding let on a synchronization lock", - deprecation: None, - module: "let_underscore", - }, - Lint { - name: "let_underscore_must_use", - group: "restriction", - desc: "non-binding let on a `#[must_use]` expression", - deprecation: None, - module: "let_underscore", - }, - Lint { - name: "let_unit_value", - group: "pedantic", - desc: "creating a `let` binding to a value of unit type, which usually can\'t be used afterwards", - deprecation: None, - module: "types", - }, - Lint { - name: "linkedlist", - group: "pedantic", - desc: "usage of LinkedList, usually a vector is faster, or a more specialized data structure like a `VecDeque`", - deprecation: None, - module: "types", - }, - Lint { - name: "logic_bug", - group: "correctness", - desc: "boolean expressions that contain terminals which can be eliminated", - deprecation: None, - module: "booleans", - }, - Lint { - name: "lossy_float_literal", - group: "restriction", - desc: "lossy whole number float literals", - deprecation: None, - module: "float_literal", - }, - Lint { - name: "macro_use_imports", - group: "pedantic", - desc: "#[macro_use] is no longer needed", - deprecation: None, - module: "macro_use", - }, - Lint { - name: "main_recursion", - group: "style", - desc: "recursion using the entrypoint", - deprecation: None, - module: "main_recursion", - }, - Lint { - name: "manual_async_fn", - group: "style", - desc: "manual implementations of `async` functions can be simplified using the dedicated syntax", - deprecation: None, - module: "manual_async_fn", - }, - Lint { - name: "manual_memcpy", - group: "perf", - desc: "manually copying items between slices", - deprecation: None, - module: "loops", - }, - Lint { - name: "manual_non_exhaustive", - group: "style", - desc: "manual implementations of the non-exhaustive pattern can be simplified using #[non_exhaustive]", - deprecation: None, - module: "manual_non_exhaustive", - }, - Lint { - name: "manual_ok_or", - group: "pedantic", - desc: "finds patterns that can be encoded more concisely with `Option::ok_or`", - deprecation: None, - module: "manual_ok_or", - }, - Lint { - name: "manual_range_contains", - group: "style", - desc: "manually reimplementing {`Range`, `RangeInclusive`}`::contains`", - deprecation: None, - module: "ranges", - }, - Lint { - name: "manual_saturating_arithmetic", - group: "style", - desc: "`.chcked_add/sub(x).unwrap_or(MAX/MIN)`", - deprecation: None, - module: "methods", - }, - Lint { - name: "manual_strip", - group: "complexity", - desc: "suggests using `strip_{prefix,suffix}` over `str::{starts,ends}_with` and slicing", - deprecation: None, - module: "manual_strip", - }, - Lint { - name: "manual_swap", - group: "complexity", - desc: "manual swap of two variables", - deprecation: None, - module: "swap", - }, - Lint { - name: "manual_unwrap_or", - group: "complexity", - desc: "finds patterns that can be encoded more concisely with `Option::unwrap_or` or `Result::unwrap_or`", - deprecation: None, - module: "manual_unwrap_or", - }, - Lint { - name: "many_single_char_names", - group: "style", - desc: "too many single character bindings", - deprecation: None, - module: "non_expressive_names", - }, - Lint { - name: "map_clone", - group: "style", - desc: "using `iterator.map(|x| x.clone())`, or dereferencing closures for `Copy` types", - deprecation: None, - module: "map_clone", - }, - Lint { - name: "map_collect_result_unit", - group: "style", - desc: "using `.map(_).collect::()`, which can be replaced with `try_for_each`", - deprecation: None, - module: "methods", - }, - Lint { - name: "map_entry", - group: "perf", - desc: "use of `contains_key` followed by `insert` on a `HashMap` or `BTreeMap`", - deprecation: None, - module: "entry", - }, - Lint { - name: "map_err_ignore", - group: "pedantic", - desc: "`map_err` should not ignore the original error", - deprecation: None, - module: "map_err_ignore", - }, - Lint { - name: "map_flatten", - group: "pedantic", - desc: "using combinations of `flatten` and `map` which can usually be written as a single method call", - deprecation: None, - module: "methods", - }, - Lint { - name: "map_identity", - group: "complexity", - desc: "using iterator.map(|x| x)", - deprecation: None, - module: "map_identity", - }, - Lint { - name: "map_unwrap_or", - group: "pedantic", - desc: "using `.map(f).unwrap_or(a)` or `.map(f).unwrap_or_else(func)`, which are more succinctly expressed as `map_or(a, f)` or `map_or_else(a, f)`", - deprecation: None, - module: "methods", - }, - Lint { - name: "match_as_ref", - group: "complexity", - desc: "a `match` on an Option value instead of using `as_ref()` or `as_mut`", - deprecation: None, - module: "matches", - }, - Lint { - name: "match_bool", - group: "pedantic", - desc: "a `match` on a boolean expression instead of an `if..else` block", - deprecation: None, - module: "matches", - }, - Lint { - name: "match_like_matches_macro", - group: "style", - desc: "a match that could be written with the matches! macro", - deprecation: None, - module: "matches", - }, - Lint { - name: "match_on_vec_items", - group: "pedantic", - desc: "matching on vector elements can panic", - deprecation: None, - module: "match_on_vec_items", - }, - Lint { - name: "match_overlapping_arm", - group: "style", - desc: "a `match` with overlapping arms", - deprecation: None, - module: "matches", - }, - Lint { - name: "match_ref_pats", - group: "style", - desc: "a `match` or `if let` with all arms prefixed with `&` instead of deref-ing the match expression", - deprecation: None, - module: "matches", - }, - Lint { - name: "match_same_arms", - group: "pedantic", - desc: "`match` with identical arm bodies", - deprecation: None, - module: "matches", - }, - Lint { - name: "match_single_binding", - group: "complexity", - desc: "a match with a single binding instead of using `let` statement", - deprecation: None, - module: "matches", - }, - Lint { - name: "match_wild_err_arm", - group: "pedantic", - desc: "a `match` with `Err(_)` arm and take drastic actions", - deprecation: None, - module: "matches", - }, - Lint { - name: "match_wildcard_for_single_variants", - group: "pedantic", - desc: "a wildcard enum match for a single variant", - deprecation: None, - module: "matches", - }, - Lint { - name: "maybe_infinite_iter", - group: "pedantic", - desc: "possible infinite iteration", - deprecation: None, - module: "infinite_iter", - }, - Lint { - name: "mem_discriminant_non_enum", - group: "correctness", - desc: "calling `mem::descriminant` on non-enum type", - deprecation: None, - module: "mem_discriminant", - }, - Lint { - name: "mem_forget", - group: "restriction", - desc: "`mem::forget` usage on `Drop` types, likely to cause memory leaks", - deprecation: None, - module: "mem_forget", - }, - Lint { - name: "mem_replace_option_with_none", - group: "style", - desc: "replacing an `Option` with `None` instead of `take()`", - deprecation: None, - module: "mem_replace", - }, - Lint { - name: "mem_replace_with_default", - group: "style", - desc: "replacing a value of type `T` with `T::default()` instead of using `std::mem::take`", - deprecation: None, - module: "mem_replace", - }, - Lint { - name: "mem_replace_with_uninit", - group: "correctness", - desc: "`mem::replace(&mut _, mem::uninitialized())` or `mem::replace(&mut _, mem::zeroed())`", - deprecation: None, - module: "mem_replace", - }, - Lint { - name: "min_max", - group: "correctness", - desc: "`min(_, max(_, _))` (or vice versa) with bounds clamping the result to a constant", - deprecation: None, - module: "minmax", - }, - Lint { - name: "mismatched_target_os", - group: "correctness", - desc: "usage of `cfg(operating_system)` instead of `cfg(target_os = \"operating_system\")`", - deprecation: None, - module: "attrs", - }, - Lint { - name: "misrefactored_assign_op", - group: "complexity", - desc: "having a variable on both sides of an assign op", - deprecation: None, - module: "assign_ops", - }, - Lint { - name: "missing_const_for_fn", - group: "nursery", - desc: "Lint functions definitions that could be made `const fn`", - deprecation: None, - module: "missing_const_for_fn", - }, - Lint { - name: "missing_docs_in_private_items", - group: "restriction", - desc: "detects missing documentation for public and private members", - deprecation: None, - module: "missing_doc", - }, - Lint { - name: "missing_errors_doc", - group: "pedantic", - desc: "`pub fn` returns `Result` without `# Errors` in doc comment", - deprecation: None, - module: "doc", - }, - Lint { - name: "missing_inline_in_public_items", - group: "restriction", - desc: "detects missing `#[inline]` attribute for public callables (functions, trait methods, methods...)", - deprecation: None, - module: "missing_inline", - }, - Lint { - name: "missing_safety_doc", - group: "style", - desc: "`pub unsafe fn` without `# Safety` docs", - deprecation: None, - module: "doc", - }, - Lint { - name: "mistyped_literal_suffixes", - group: "correctness", - desc: "mistyped literal suffix", - deprecation: None, - module: "literal_representation", - }, - Lint { - name: "mixed_case_hex_literals", - group: "style", - desc: "hex literals whose letter digits are not consistently upper- or lowercased", - deprecation: None, - module: "misc_early", - }, - Lint { - name: "module_inception", - group: "style", - desc: "modules that have the same name as their parent module", - deprecation: None, - module: "enum_variants", - }, - Lint { - name: "module_name_repetitions", - group: "pedantic", - desc: "type names prefixed/postfixed with their containing module\'s name", - deprecation: None, - module: "enum_variants", - }, - Lint { - name: "modulo_arithmetic", - group: "restriction", - desc: "any modulo arithmetic statement", - deprecation: None, - module: "modulo_arithmetic", - }, - Lint { - name: "modulo_one", - group: "correctness", - desc: "taking a number modulo 1, which always returns 0", - deprecation: None, - module: "misc", - }, - Lint { - name: "multiple_crate_versions", - group: "cargo", - desc: "multiple versions of the same crate being used", - deprecation: None, - module: "multiple_crate_versions", - }, - Lint { - name: "multiple_inherent_impl", - group: "restriction", - desc: "Multiple inherent impl that could be grouped", - deprecation: None, - module: "inherent_impl", - }, - Lint { - name: "must_use_candidate", - group: "pedantic", - desc: "function or method that could take a `#[must_use]` attribute", - deprecation: None, - module: "functions", - }, - Lint { - name: "must_use_unit", - group: "style", - desc: "`#[must_use]` attribute on a unit-returning function / method", - deprecation: None, - module: "functions", - }, - Lint { - name: "mut_from_ref", - group: "correctness", - desc: "fns that create mutable refs from immutable ref args", - deprecation: None, - module: "ptr", - }, - Lint { - name: "mut_mut", - group: "pedantic", - desc: "usage of double-mut refs, e.g., `&mut &mut ...`", - deprecation: None, - module: "mut_mut", - }, - Lint { - name: "mut_mutex_lock", - group: "style", - desc: "`&mut Mutex::lock` does unnecessary locking", - deprecation: None, - module: "mut_mutex_lock", - }, - Lint { - name: "mut_range_bound", - group: "complexity", - desc: "for loop over a range where one of the bounds is a mutable variable", - deprecation: None, - module: "loops", - }, - Lint { - name: "mutable_key_type", - group: "correctness", - desc: "Check for mutable `Map`/`Set` key type", - deprecation: None, - module: "mut_key", - }, - Lint { - name: "mutex_atomic", - group: "perf", - desc: "using a mutex where an atomic value could be used instead", - deprecation: None, - module: "mutex_atomic", - }, - Lint { - name: "mutex_integer", - group: "nursery", - desc: "using a mutex for an integer type", - deprecation: None, - module: "mutex_atomic", - }, - Lint { - name: "naive_bytecount", - group: "perf", - desc: "use of naive `.filter(|&x| x == y).count()` to count byte values", - deprecation: None, - module: "bytecount", - }, - Lint { - name: "needless_arbitrary_self_type", - group: "complexity", - desc: "type of `self` parameter is already by default `Self`", - deprecation: None, - module: "needless_arbitrary_self_type", - }, - Lint { - name: "needless_bool", - group: "complexity", - desc: "if-statements with plain booleans in the then- and else-clause, e.g., `if p { true } else { false }`", - deprecation: None, - module: "needless_bool", - }, - Lint { - name: "needless_borrow", - group: "nursery", - desc: "taking a reference that is going to be automatically dereferenced", - deprecation: None, - module: "needless_borrow", - }, - Lint { - name: "needless_borrowed_reference", - group: "complexity", - desc: "taking a needless borrowed reference", - deprecation: None, - module: "needless_borrowed_ref", - }, - Lint { - name: "needless_collect", - group: "perf", - desc: "collecting an iterator when collect is not needed", - deprecation: None, - module: "loops", - }, - Lint { - name: "needless_continue", - group: "pedantic", - desc: "`continue` statements that can be replaced by a rearrangement of code", - deprecation: None, - module: "needless_continue", - }, - Lint { - name: "needless_doctest_main", - group: "style", - desc: "presence of `fn main() {` in code examples", - deprecation: None, - module: "doc", - }, - Lint { - name: "needless_lifetimes", - group: "complexity", - desc: "using explicit lifetimes for references in function arguments when elision rules would allow omitting them", - deprecation: None, - module: "lifetimes", - }, - Lint { - name: "needless_pass_by_value", - group: "pedantic", - desc: "functions taking arguments by value, but not consuming them in its body", - deprecation: None, - module: "needless_pass_by_value", - }, - Lint { - name: "needless_range_loop", - group: "style", - desc: "for-looping over a range of indices where an iterator over items would do", - deprecation: None, - module: "loops", - }, - Lint { - name: "needless_return", - group: "style", - desc: "using a return statement like `return expr;` where an expression would suffice", - deprecation: None, - module: "returns", - }, - Lint { - name: "needless_update", - group: "complexity", - desc: "using `Foo { ..base }` when there are no missing fields", - deprecation: None, - module: "needless_update", - }, - Lint { - name: "neg_cmp_op_on_partial_ord", - group: "complexity", - desc: "The use of negated comparison operators on partially ordered types may produce confusing code.", - deprecation: None, - module: "neg_cmp_op_on_partial_ord", - }, - Lint { - name: "neg_multiply", - group: "style", - desc: "multiplying integers with `-1`", - deprecation: None, - module: "neg_multiply", - }, - Lint { - name: "never_loop", - group: "correctness", - desc: "any loop that will always `break` or `return`", - deprecation: None, - module: "loops", - }, - Lint { - name: "new_ret_no_self", - group: "style", - desc: "not returning type containing `Self` in a `new` method", - deprecation: None, - module: "methods", - }, - Lint { - name: "new_without_default", - group: "style", - desc: "`fn new() -> Self` method without `Default` implementation", - deprecation: None, - module: "new_without_default", - }, - Lint { - name: "no_effect", - group: "complexity", - desc: "statements with no effect", - deprecation: None, - module: "no_effect", - }, - Lint { - name: "non_ascii_literal", - group: "pedantic", - desc: "using any literal non-ASCII chars in a string literal instead of using the `\\\\u` escape", - deprecation: None, - module: "unicode", - }, - Lint { - name: "nonminimal_bool", - group: "complexity", - desc: "boolean expressions that can be written more concisely", - deprecation: None, - module: "booleans", - }, - Lint { - name: "nonsensical_open_options", - group: "correctness", - desc: "nonsensical combination of options for opening a file", - deprecation: None, - module: "open_options", - }, - Lint { - name: "not_unsafe_ptr_arg_deref", - group: "correctness", - desc: "public functions dereferencing raw pointer arguments but not marked `unsafe`", - deprecation: None, - module: "functions", - }, - Lint { - name: "ok_expect", - group: "style", - desc: "using `ok().expect()`, which gives worse error messages than calling `expect` directly on the Result", - deprecation: None, - module: "methods", - }, - Lint { - name: "op_ref", - group: "style", - desc: "taking a reference to satisfy the type constraints on `==`", - deprecation: None, - module: "eq_op", - }, - Lint { - name: "option_as_ref_deref", - group: "complexity", - desc: "using `as_ref().map(Deref::deref)`, which is more succinctly expressed as `as_deref()`", - deprecation: None, - module: "methods", - }, - Lint { - name: "option_env_unwrap", - group: "correctness", - desc: "using `option_env!(...).unwrap()` to get environment variable", - deprecation: None, - module: "option_env_unwrap", - }, - Lint { - name: "option_if_let_else", - group: "pedantic", - desc: "reimplementation of Option::map_or", - deprecation: None, - module: "option_if_let_else", - }, - Lint { - name: "option_map_or_none", - group: "style", - desc: "using `Option.map_or(None, f)`, which is more succinctly expressed as `and_then(f)`", - deprecation: None, - module: "methods", - }, - Lint { - name: "option_map_unit_fn", - group: "complexity", - desc: "using `option.map(f)`, where `f` is a function or closure that returns `()`", - deprecation: None, - module: "map_unit_fn", - }, - Lint { - name: "option_option", - group: "pedantic", - desc: "usage of `Option>`", - deprecation: None, - module: "types", - }, - Lint { - name: "or_fun_call", - group: "perf", - desc: "using any `*or` method with a function call, which suggests `*or_else`", - deprecation: None, - module: "methods", - }, - Lint { - name: "out_of_bounds_indexing", - group: "correctness", - desc: "out of bounds constant indexing", - deprecation: None, - module: "indexing_slicing", - }, - Lint { - name: "overflow_check_conditional", - group: "complexity", - desc: "overflow checks inspired by C which are likely to panic", - deprecation: None, - module: "overflow_check_conditional", - }, - Lint { - name: "panic", - group: "restriction", - desc: "usage of the `panic!` macro", - deprecation: None, - module: "panic_unimplemented", - }, - Lint { - name: "panic_in_result_fn", - group: "restriction", - desc: "functions of type `Result<..>` that contain `panic!()`, `todo!()` or `unreachable()` or `unimplemented()` ", - deprecation: None, - module: "panic_in_result_fn", - }, - Lint { - name: "panicking_unwrap", - group: "correctness", - desc: "checks for calls of `unwrap[_err]()` that will always fail", - deprecation: None, - module: "unwrap", - }, - Lint { - name: "partialeq_ne_impl", - group: "complexity", - desc: "re-implementing `PartialEq::ne`", - deprecation: None, - module: "partialeq_ne_impl", - }, - Lint { - name: "path_buf_push_overwrite", - group: "nursery", - desc: "calling `push` with file system root on `PathBuf` can overwrite it", - deprecation: None, - module: "path_buf_push_overwrite", - }, - Lint { - name: "pattern_type_mismatch", - group: "restriction", - desc: "type of pattern does not match the expression type", - deprecation: None, - module: "pattern_type_mismatch", - }, - Lint { - name: "possible_missing_comma", - group: "correctness", - desc: "possible missing comma in array", - deprecation: None, - module: "formatting", - }, - Lint { - name: "precedence", - group: "complexity", - desc: "operations where precedence may be unclear", - deprecation: None, - module: "precedence", - }, - Lint { - name: "print_literal", - group: "style", - desc: "printing a literal with a format string", - deprecation: None, - module: "write", - }, - Lint { - name: "print_stdout", - group: "restriction", - desc: "printing on stdout", - deprecation: None, - module: "write", - }, - Lint { - name: "print_with_newline", - group: "style", - desc: "using `print!()` with a format string that ends in a single newline", - deprecation: None, - module: "write", - }, - Lint { - name: "println_empty_string", - group: "style", - desc: "using `println!(\"\")` with an empty string", - deprecation: None, - module: "write", - }, - Lint { - name: "ptr_arg", - group: "style", - desc: "fn arguments of the type `&Vec<...>` or `&String`, suggesting to use `&[...]` or `&str` instead, respectively", - deprecation: None, - module: "ptr", - }, - Lint { - name: "ptr_eq", - group: "style", - desc: "use `std::ptr::eq` when comparing raw pointers", - deprecation: None, - module: "ptr_eq", - }, - Lint { - name: "ptr_offset_with_cast", - group: "complexity", - desc: "unneeded pointer offset cast", - deprecation: None, - module: "ptr_offset_with_cast", - }, - Lint { - name: "pub_enum_variant_names", - group: "pedantic", - desc: "public enums where all variants share a prefix/postfix", - deprecation: None, - module: "enum_variants", - }, - Lint { - name: "question_mark", - group: "style", - desc: "checks for expressions that could be replaced by the question mark operator", - deprecation: None, - module: "question_mark", - }, - Lint { - name: "range_minus_one", - group: "pedantic", - desc: "`x..=(y-1)` reads better as `x..y`", - deprecation: None, - module: "ranges", - }, - Lint { - name: "range_plus_one", - group: "pedantic", - desc: "`x..(y+1)` reads better as `x..=y`", - deprecation: None, - module: "ranges", - }, - Lint { - name: "range_zip_with_len", - group: "complexity", - desc: "zipping iterator with a range when `enumerate()` would do", - deprecation: None, - module: "ranges", - }, - Lint { - name: "rc_buffer", - group: "restriction", - desc: "shared ownership of a buffer type", - deprecation: None, - module: "types", - }, - Lint { - name: "redundant_allocation", - group: "perf", - desc: "redundant allocation", - deprecation: None, - module: "types", - }, - Lint { - name: "redundant_clone", - group: "perf", - desc: "`clone()` of an owned value that is going to be dropped immediately", - deprecation: None, - module: "redundant_clone", - }, - Lint { - name: "redundant_closure", - group: "style", - desc: "redundant closures, i.e., `|a| foo(a)` (which can be written as just `foo`)", - deprecation: None, - module: "eta_reduction", - }, - Lint { - name: "redundant_closure_call", - group: "complexity", - desc: "throwaway closures called in the expression they are defined", - deprecation: None, - module: "redundant_closure_call", - }, - Lint { - name: "redundant_closure_for_method_calls", - group: "pedantic", - desc: "redundant closures for method calls", - deprecation: None, - module: "eta_reduction", - }, - Lint { - name: "redundant_field_names", - group: "style", - desc: "checks for fields in struct literals where shorthands could be used", - deprecation: None, - module: "redundant_field_names", - }, - Lint { - name: "redundant_pattern", - group: "style", - desc: "using `name @ _` in a pattern", - deprecation: None, - module: "misc_early", - }, - Lint { - name: "redundant_pattern_matching", - group: "style", - desc: "use the proper utility function avoiding an `if let`", - deprecation: None, - module: "matches", - }, - Lint { - name: "redundant_pub_crate", - group: "nursery", - desc: "Using `pub(crate)` visibility on items that are not crate visible due to the visibility of the module that contains them.", - deprecation: None, - module: "redundant_pub_crate", - }, - Lint { - name: "redundant_static_lifetimes", - group: "style", - desc: "Using explicit `\'static` lifetime for constants or statics when elision rules would allow omitting them.", - deprecation: None, - module: "redundant_static_lifetimes", - }, - Lint { - name: "ref_in_deref", - group: "complexity", - desc: "Use of reference in auto dereference expression.", - deprecation: None, - module: "reference", - }, - Lint { - name: "ref_option_ref", - group: "pedantic", - desc: "use `Option<&T>` instead of `&Option<&T>`", - deprecation: None, - module: "ref_option_ref", - }, - Lint { - name: "repeat_once", - group: "complexity", - desc: "using `.repeat(1)` instead of `String.clone()`, `str.to_string()` or `slice.to_vec()` ", - deprecation: None, - module: "repeat_once", - }, - Lint { - name: "rest_pat_in_fully_bound_structs", - group: "restriction", - desc: "a match on a struct that binds all fields but still uses the wildcard pattern", - deprecation: None, - module: "matches", - }, - Lint { - name: "result_map_or_into_option", - group: "style", - desc: "using `Result.map_or(None, Some)`, which is more succinctly expressed as `ok()`", - deprecation: None, - module: "methods", - }, - Lint { - name: "result_map_unit_fn", - group: "complexity", - desc: "using `result.map(f)`, where `f` is a function or closure that returns `()`", - deprecation: None, - module: "map_unit_fn", - }, - Lint { - name: "result_unit_err", - group: "style", - desc: "public function returning `Result` with an `Err` type of `()`", - deprecation: None, - module: "functions", - }, - Lint { - name: "reversed_empty_ranges", - group: "correctness", - desc: "reversing the limits of range expressions, resulting in empty ranges", - deprecation: None, - module: "ranges", - }, - Lint { - name: "same_functions_in_if_condition", - group: "pedantic", - desc: "consecutive `if`s with the same function call", - deprecation: None, - module: "copies", - }, - Lint { - name: "same_item_push", - group: "style", - desc: "the same item is pushed inside of a for loop", - deprecation: None, - module: "loops", - }, - Lint { - name: "search_is_some", - group: "complexity", - desc: "using an iterator or string search followed by `is_some()`, which is more succinctly expressed as a call to `any()` or `contains()`", - deprecation: None, - module: "methods", - }, - Lint { - name: "self_assignment", - group: "correctness", - desc: "explicit self-assignment", - deprecation: None, - module: "self_assignment", - }, - Lint { - name: "serde_api_misuse", - group: "correctness", - desc: "various things that will negatively affect your serde experience", - deprecation: None, - module: "serde_api", - }, - Lint { - name: "shadow_reuse", - group: "restriction", - desc: "rebinding a name to an expression that re-uses the original value, e.g., `let x = x + 1`", - deprecation: None, - module: "shadow", - }, - Lint { - name: "shadow_same", - group: "restriction", - desc: "rebinding a name to itself, e.g., `let mut x = &mut x`", - deprecation: None, - module: "shadow", - }, - Lint { - name: "shadow_unrelated", - group: "pedantic", - desc: "rebinding a name without even using the original value", - deprecation: None, - module: "shadow", - }, - Lint { - name: "short_circuit_statement", - group: "complexity", - desc: "using a short circuit boolean condition as a statement", - deprecation: None, - module: "misc", - }, - Lint { - name: "should_implement_trait", - group: "style", - desc: "defining a method that should be implementing a std trait", - deprecation: None, - module: "methods", - }, - Lint { - name: "similar_names", - group: "pedantic", - desc: "similarly named items and bindings", - deprecation: None, - module: "non_expressive_names", - }, - Lint { - name: "single_char_add_str", - group: "style", - desc: "`push_str()` or `insert_str()` used with a single-character string literal as parameter", - deprecation: None, - module: "methods", - }, - Lint { - name: "single_char_pattern", - group: "perf", - desc: "using a single-character str where a char could be used, e.g., `_.split(\"x\")`", - deprecation: None, - module: "methods", - }, - Lint { - name: "single_component_path_imports", - group: "style", - desc: "imports with single component path are redundant", - deprecation: None, - module: "single_component_path_imports", - }, - Lint { - name: "single_element_loop", - group: "complexity", - desc: "there is no reason to have a single element loop", - deprecation: None, - module: "loops", - }, - Lint { - name: "single_match", - group: "style", - desc: "a `match` statement with a single nontrivial arm (i.e., where the other arm is `_ => {}`) instead of `if let`", - deprecation: None, - module: "matches", - }, - Lint { - name: "single_match_else", - group: "pedantic", - desc: "a `match` statement with two arms where the second arm\'s pattern is a placeholder instead of a specific match pattern", - deprecation: None, - module: "matches", - }, - Lint { - name: "skip_while_next", - group: "complexity", - desc: "using `skip_while(p).next()`, which is more succinctly expressed as `.find(!p)`", - deprecation: None, - module: "methods", - }, - Lint { - name: "slow_vector_initialization", - group: "perf", - desc: "slow vector initialization", - deprecation: None, - module: "slow_vector_initialization", - }, - Lint { - name: "stable_sort_primitive", - group: "perf", - desc: "use of sort() when sort_unstable() is equivalent", - deprecation: None, - module: "stable_sort_primitive", - }, - Lint { - name: "string_add", - group: "restriction", - desc: "using `x + ..` where x is a `String` instead of `push_str()`", - deprecation: None, - module: "strings", - }, - Lint { - name: "string_add_assign", - group: "pedantic", - desc: "using `x = x + ..` where x is a `String` instead of `push_str()`", - deprecation: None, - module: "strings", - }, - Lint { - name: "string_extend_chars", - group: "style", - desc: "using `x.extend(s.chars())` where s is a `&str` or `String`", - deprecation: None, - module: "methods", - }, - Lint { - name: "string_from_utf8_as_bytes", - group: "complexity", - desc: "casting string slices to byte slices and back", - deprecation: None, - module: "strings", - }, - Lint { - name: "string_lit_as_bytes", - group: "nursery", - desc: "calling `as_bytes` on a string literal instead of using a byte string literal", - deprecation: None, - module: "strings", - }, - Lint { - name: "struct_excessive_bools", - group: "pedantic", - desc: "using too many bools in a struct", - deprecation: None, - module: "excessive_bools", - }, - Lint { - name: "suboptimal_flops", - group: "nursery", - desc: "usage of sub-optimal floating point operations", - deprecation: None, - module: "floating_point_arithmetic", - }, - Lint { - name: "suspicious_arithmetic_impl", - group: "correctness", - desc: "suspicious use of operators in impl of arithmetic trait", - deprecation: None, - module: "suspicious_trait_impl", - }, - Lint { - name: "suspicious_assignment_formatting", - group: "style", - desc: "suspicious formatting of `*=`, `-=` or `!=`", - deprecation: None, - module: "formatting", - }, - Lint { - name: "suspicious_else_formatting", - group: "style", - desc: "suspicious formatting of `else`", - deprecation: None, - module: "formatting", - }, - Lint { - name: "suspicious_map", - group: "complexity", - desc: "suspicious usage of map", - deprecation: None, - module: "methods", - }, - Lint { - name: "suspicious_op_assign_impl", - group: "correctness", - desc: "suspicious use of operators in impl of OpAssign trait", - deprecation: None, - module: "suspicious_trait_impl", - }, - Lint { - name: "suspicious_unary_op_formatting", - group: "style", - desc: "suspicious formatting of unary `-` or `!` on the RHS of a BinOp", - deprecation: None, - module: "formatting", - }, - Lint { - name: "tabs_in_doc_comments", - group: "style", - desc: "using tabs in doc comments is not recommended", - deprecation: None, - module: "tabs_in_doc_comments", - }, - Lint { - name: "temporary_assignment", - group: "complexity", - desc: "assignments to temporaries", - deprecation: None, - module: "temporary_assignment", - }, - Lint { - name: "to_digit_is_some", - group: "style", - desc: "`char.is_digit()` is clearer", - deprecation: None, - module: "to_digit_is_some", - }, - Lint { - name: "to_string_in_display", - group: "correctness", - desc: "`to_string` method used while implementing `Display` trait", - deprecation: None, - module: "to_string_in_display", - }, - Lint { - name: "todo", - group: "restriction", - desc: "`todo!` should not be present in production code", - deprecation: None, - module: "panic_unimplemented", - }, - Lint { - name: "too_many_arguments", - group: "complexity", - desc: "functions with too many arguments", - deprecation: None, - module: "functions", - }, - Lint { - name: "too_many_lines", - group: "pedantic", - desc: "functions with too many lines", - deprecation: None, - module: "functions", - }, - Lint { - name: "toplevel_ref_arg", - group: "style", - desc: "an entire binding declared as `ref`, in a function argument or a `let` statement", - deprecation: None, - module: "misc", - }, - Lint { - name: "trait_duplication_in_bounds", - group: "pedantic", - desc: "Check if the same trait bounds are specified twice during a function declaration", - deprecation: None, - module: "trait_bounds", - }, - Lint { - name: "transmute_bytes_to_str", - group: "complexity", - desc: "transmutes from a `&[u8]` to a `&str`", - deprecation: None, - module: "transmute", - }, - Lint { - name: "transmute_float_to_int", - group: "complexity", - desc: "transmutes from a float to an integer", - deprecation: None, - module: "transmute", - }, - Lint { - name: "transmute_int_to_bool", - group: "complexity", - desc: "transmutes from an integer to a `bool`", - deprecation: None, - module: "transmute", - }, - Lint { - name: "transmute_int_to_char", - group: "complexity", - desc: "transmutes from an integer to a `char`", - deprecation: None, - module: "transmute", - }, - Lint { - name: "transmute_int_to_float", - group: "complexity", - desc: "transmutes from an integer to a float", - deprecation: None, - module: "transmute", - }, - Lint { - name: "transmute_ptr_to_ptr", - group: "complexity", - desc: "transmutes from a pointer to a pointer / a reference to a reference", - deprecation: None, - module: "transmute", - }, - Lint { - name: "transmute_ptr_to_ref", - group: "complexity", - desc: "transmutes from a pointer to a reference type", - deprecation: None, - module: "transmute", - }, - Lint { - name: "transmutes_expressible_as_ptr_casts", - group: "complexity", - desc: "transmutes that could be a pointer cast", - deprecation: None, - module: "transmute", - }, - Lint { - name: "transmuting_null", - group: "correctness", - desc: "transmutes from a null pointer to a reference, which is undefined behavior", - deprecation: None, - module: "transmuting_null", - }, - Lint { - name: "trivial_regex", - group: "style", - desc: "trivial regular expressions", - deprecation: None, - module: "regex", - }, - Lint { - name: "trivially_copy_pass_by_ref", - group: "pedantic", - desc: "functions taking small copyable arguments by reference", - deprecation: None, - module: "pass_by_ref_or_value", - }, - Lint { - name: "try_err", - group: "style", - desc: "return errors explicitly rather than hiding them behind a `?`", - deprecation: None, - module: "try_err", - }, - Lint { - name: "type_complexity", - group: "complexity", - desc: "usage of very complex types that might be better factored into `type` definitions", - deprecation: None, - module: "types", - }, - Lint { - name: "type_repetition_in_bounds", - group: "pedantic", - desc: "Types are repeated unnecessary in trait bounds use `+` instead of using `T: _, T: _`", - deprecation: None, - module: "trait_bounds", - }, - Lint { - name: "undropped_manually_drops", - group: "correctness", - desc: "use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value", - deprecation: None, - module: "undropped_manually_drops", - }, - Lint { - name: "unicode_not_nfc", - group: "pedantic", - desc: "using a Unicode literal not in NFC normal form (see [Unicode tr15](http://www.unicode.org/reports/tr15/) for further information)", - deprecation: None, - module: "unicode", - }, - Lint { - name: "unimplemented", - group: "restriction", - desc: "`unimplemented!` should not be present in production code", - deprecation: None, - module: "panic_unimplemented", - }, - Lint { - name: "uninit_assumed_init", - group: "correctness", - desc: "`MaybeUninit::uninit().assume_init()`", - deprecation: None, - module: "methods", - }, - Lint { - name: "unit_arg", - group: "complexity", - desc: "passing unit to a function", - deprecation: None, - module: "types", - }, - Lint { - name: "unit_cmp", - group: "correctness", - desc: "comparing unit values", - deprecation: None, - module: "types", - }, - Lint { - name: "unit_return_expecting_ord", - group: "correctness", - desc: "fn arguments of type Fn(...) -> Ord returning the unit type ().", - deprecation: None, - module: "unit_return_expecting_ord", - }, - Lint { - name: "unknown_clippy_lints", - group: "style", - desc: "unknown_lints for scoped Clippy lints", - deprecation: None, - module: "attrs", - }, - Lint { - name: "unnecessary_cast", - group: "complexity", - desc: "cast to the same type, e.g., `x as i32` where `x: i32`", - deprecation: None, - module: "types", - }, - Lint { - name: "unnecessary_filter_map", - group: "complexity", - desc: "using `filter_map` when a more succinct alternative exists", - deprecation: None, - module: "methods", - }, - Lint { - name: "unnecessary_fold", - group: "style", - desc: "using `fold` when a more succinct alternative exists", - deprecation: None, - module: "methods", - }, - Lint { - name: "unnecessary_lazy_evaluations", - group: "style", - desc: "using unnecessary lazy evaluation, which can be replaced with simpler eager evaluation", - deprecation: None, - module: "methods", - }, - Lint { - name: "unnecessary_mut_passed", - group: "style", - desc: "an argument passed as a mutable reference although the callee only demands an immutable reference", - deprecation: None, - module: "mut_reference", - }, - Lint { - name: "unnecessary_operation", - group: "complexity", - desc: "outer expressions with no effect", - deprecation: None, - module: "no_effect", - }, - Lint { - name: "unnecessary_sort_by", - group: "complexity", - desc: "Use of `Vec::sort_by` when `Vec::sort_by_key` or `Vec::sort` would be clearer", - deprecation: None, - module: "unnecessary_sort_by", - }, - Lint { - name: "unnecessary_unwrap", - group: "complexity", - desc: "checks for calls of `unwrap[_err]()` that cannot fail", - deprecation: None, - module: "unwrap", - }, - Lint { - name: "unnecessary_wraps", - group: "complexity", - desc: "functions that only return `Ok` or `Some`", - deprecation: None, - module: "unnecessary_wraps", - }, - Lint { - name: "unneeded_field_pattern", - group: "restriction", - desc: "struct fields bound to a wildcard instead of using `..`", - deprecation: None, - module: "misc_early", - }, - Lint { - name: "unneeded_wildcard_pattern", - group: "complexity", - desc: "tuple patterns with a wildcard pattern (`_`) is next to a rest pattern (`..`)", - deprecation: None, - module: "misc_early", - }, - Lint { - name: "unnested_or_patterns", - group: "pedantic", - desc: "unnested or-patterns, e.g., `Foo(Bar) | Foo(Baz) instead of `Foo(Bar | Baz)`", - deprecation: None, - module: "unnested_or_patterns", - }, - Lint { - name: "unreachable", - group: "restriction", - desc: "`unreachable!` should not be present in production code", - deprecation: None, - module: "panic_unimplemented", - }, - Lint { - name: "unreadable_literal", - group: "pedantic", - desc: "long integer literal without underscores", - deprecation: None, - module: "literal_representation", - }, - Lint { - name: "unsafe_derive_deserialize", - group: "pedantic", - desc: "deriving `serde::Deserialize` on a type that has methods using `unsafe`", - deprecation: None, - module: "derive", - }, - Lint { - name: "unsafe_removed_from_name", - group: "style", - desc: "`unsafe` removed from API names on import", - deprecation: None, - module: "unsafe_removed_from_name", - }, - Lint { - name: "unseparated_literal_suffix", - group: "pedantic", - desc: "literals whose suffix is not separated by an underscore", - deprecation: None, - module: "misc_early", - }, - Lint { - name: "unsound_collection_transmute", - group: "correctness", - desc: "transmute between collections of layout-incompatible types", - deprecation: None, - module: "transmute", - }, - Lint { - name: "unused_io_amount", - group: "correctness", - desc: "unused written/read amount", - deprecation: None, - module: "unused_io_amount", - }, - Lint { - name: "unused_self", - group: "pedantic", - desc: "methods that contain a `self` argument but don\'t use it", - deprecation: None, - module: "unused_self", - }, - Lint { - name: "unused_unit", - group: "style", - desc: "needless unit expression", - deprecation: None, - module: "unused_unit", - }, - Lint { - name: "unusual_byte_groupings", - group: "style", - desc: "binary or hex literals that aren\'t grouped by four", - deprecation: None, - module: "literal_representation", - }, - Lint { - name: "unwrap_in_result", - group: "restriction", - desc: "functions of type `Result<..>` or `Option`<...> that contain `expect()` or `unwrap()`", - deprecation: None, - module: "unwrap_in_result", - }, - Lint { - name: "unwrap_used", - group: "restriction", - desc: "using `.unwrap()` on `Result` or `Option`, which should at least get a better message using `expect()`", - deprecation: None, - module: "methods", - }, - Lint { - name: "use_debug", - group: "restriction", - desc: "use of `Debug`-based formatting", - deprecation: None, - module: "write", - }, - Lint { - name: "use_self", - group: "nursery", - desc: "unnecessary structure name repetition whereas `Self` is applicable", - deprecation: None, - module: "use_self", - }, - Lint { - name: "used_underscore_binding", - group: "pedantic", - desc: "using a binding which is prefixed with an underscore", - deprecation: None, - module: "misc", - }, - Lint { - name: "useless_asref", - group: "complexity", - desc: "using `as_ref` where the types before and after the call are the same", - deprecation: None, - module: "methods", - }, - Lint { - name: "useless_attribute", - group: "correctness", - desc: "use of lint attributes on `extern crate` items", - deprecation: None, - module: "attrs", - }, - Lint { - name: "useless_conversion", - group: "complexity", - desc: "calls to `Into`, `TryInto`, `From`, `TryFrom`, or `IntoIter` which perform useless conversions to the same type", - deprecation: None, - module: "useless_conversion", - }, - Lint { - name: "useless_format", - group: "complexity", - desc: "useless use of `format!`", - deprecation: None, - module: "format", - }, - Lint { - name: "useless_let_if_seq", - group: "nursery", - desc: "unidiomatic `let mut` declaration followed by initialization in `if`", - deprecation: None, - module: "let_if_seq", - }, - Lint { - name: "useless_transmute", - group: "nursery", - desc: "transmutes that have the same to and from types or could be a cast/coercion", - deprecation: None, - module: "transmute", - }, - Lint { - name: "useless_vec", - group: "perf", - desc: "useless `vec!`", - deprecation: None, - module: "vec", - }, - Lint { - name: "vec_box", - group: "complexity", - desc: "usage of `Vec>` where T: Sized, vector elements are already on the heap", - deprecation: None, - module: "types", - }, - Lint { - name: "vec_resize_to_zero", - group: "correctness", - desc: "emptying a vector with `resize(0, an_int)` instead of `clear()` is probably an argument inversion mistake", - deprecation: None, - module: "vec_resize_to_zero", - }, - Lint { - name: "verbose_bit_mask", - group: "pedantic", - desc: "expressions where a bit mask is less readable than the corresponding method call", - deprecation: None, - module: "bit_mask", - }, - Lint { - name: "verbose_file_reads", - group: "restriction", - desc: "use of `File::read_to_end` or `File::read_to_string`", - deprecation: None, - module: "verbose_file_reads", - }, - Lint { - name: "vtable_address_comparisons", - group: "correctness", - desc: "comparison with an address of a trait vtable", - deprecation: None, - module: "unnamed_address", - }, - Lint { - name: "while_immutable_condition", - group: "correctness", - desc: "variables used within while expression are not mutated in the body", - deprecation: None, - module: "loops", - }, - Lint { - name: "while_let_loop", - group: "complexity", - desc: "`loop { if let { ... } else break }`, which can be written as a `while let` loop", - deprecation: None, - module: "loops", - }, - Lint { - name: "while_let_on_iterator", - group: "style", - desc: "using a while-let loop instead of a for loop on an iterator", - deprecation: None, - module: "loops", - }, - Lint { - name: "wildcard_dependencies", - group: "cargo", - desc: "wildcard dependencies being used", - deprecation: None, - module: "wildcard_dependencies", - }, - Lint { - name: "wildcard_enum_match_arm", - group: "restriction", - desc: "a wildcard enum match arm using `_`", - deprecation: None, - module: "matches", - }, - Lint { - name: "wildcard_imports", - group: "pedantic", - desc: "lint `use _::*` statements", - deprecation: None, - module: "wildcard_imports", - }, - Lint { - name: "wildcard_in_or_patterns", - group: "complexity", - desc: "a wildcard pattern used with others patterns in same match arm", - deprecation: None, - module: "matches", - }, - Lint { - name: "write_literal", - group: "style", - desc: "writing a literal with a format string", - deprecation: None, - module: "write", - }, - Lint { - name: "write_with_newline", - group: "style", - desc: "using `write!()` with a format string that ends in a single newline", - deprecation: None, - module: "write", - }, - Lint { - name: "writeln_empty_string", - group: "style", - desc: "using `writeln!(buf, \"\")` with an empty string", - deprecation: None, - module: "write", - }, - Lint { - name: "wrong_pub_self_convention", - group: "restriction", - desc: "defining a public method named with an established prefix (like \"into_\") that takes `self` with the wrong convention", - deprecation: None, - module: "methods", - }, - Lint { - name: "wrong_self_convention", - group: "style", - desc: "defining a method named with an established prefix (like \"into_\") that takes `self` with the wrong convention", - deprecation: None, - module: "methods", - }, - Lint { - name: "wrong_transmute", - group: "correctness", - desc: "transmutes that are confusing at best, undefined behaviour at worst and always useless", - deprecation: None, - module: "transmute", - }, - Lint { - name: "zero_divided_by_zero", - group: "complexity", - desc: "usage of `0.0 / 0.0` to obtain NaN instead of `f32::NAN` or `f64::NAN`", - deprecation: None, - module: "zero_div_zero", - }, - Lint { - name: "zero_prefixed_literal", - group: "complexity", - desc: "integer literals starting with `0`", - deprecation: None, - module: "misc_early", - }, - Lint { - name: "zero_ptr", - group: "style", - desc: "using `0 as *{const, mut} T`", - deprecation: None, - module: "misc", - }, - Lint { - name: "zst_offset", - group: "correctness", - desc: "Check for offset calculations on raw pointers to zero-sized types", - deprecation: None, - module: "methods", - }, -] -// end lint list, do not remove this comment, it’s used in `update_lints` -}); From 91f392b1388a68dfcb5880f19691ff0e76b37034 Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Thu, 12 Nov 2020 11:24:10 -0800 Subject: [PATCH 0143/1222] Move lev_distance to rustc_ast, make non-generic rustc_ast currently has a few dependencies on rustc_lexer. Ideally, an AST would not have any dependency its lexer, for minimizing unnecessarily design-time dependencies. Breaking this dependency would also have practical benefits, since modifying rustc_lexer would not trigger a rebuild of rustc_ast. This commit does not remove the rustc_ast --> rustc_lexer dependency, but it does remove one of the sources of this dependency, which is the code that handles fuzzy matching between symbol names for making suggestions in diagnostics. Since that code depends only on Symbol, it is easy to move it to rustc_span. It might even be best to move it to a separate crate, since other tools such as Cargo use the same algorithm, and have simply contain a duplicate of the code. This changes the signature of find_best_match_for_name so that it is no longer generic over its input. I checked the optimized binaries, and this function was duplicated at nearly every call site, because most call sites used short-lived iterator chains, generic over Map and such. But there's no good reason for a function like this to be generic, since all it does is immediately convert the generic input (the Iterator impl) to a concrete Vec. This has all of the costs of generics (duplicated method bodies) with no benefit. Changing find_best_match_for_name to be non-generic removed about 10KB of code from the optimized binary. I know it's a drop in the bucket, but we have to start reducing binary size, and beginning to tame over-use of generics is part of that. --- clippy_lints/src/attrs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 9a667aa61b4f..15505fd79f4a 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -5,7 +5,7 @@ use crate::utils::{ span_lint_and_sugg, span_lint_and_then, without_block_comments, }; use if_chain::if_chain; -use rustc_ast::util::lev_distance::find_best_match_for_name; +use rustc_span::lev_distance::find_best_match_for_name; use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem}; use rustc_errors::Applicability; use rustc_hir::{ @@ -427,7 +427,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_>, ident: &str, items: &[NestedMet .map(|l| Symbol::intern(&l.name_lower())) .collect::>(); let sugg = find_best_match_for_name( - symbols.iter(), + &symbols, Symbol::intern(&format!("clippy::{}", name_lower)), None, ); From df403a44952eefea35153fb531d424b06d25bb7a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 11 Nov 2020 22:40:09 +0100 Subject: [PATCH 0144/1222] Remove ForeignMod struct. --- clippy_lints/src/missing_doc.rs | 2 +- clippy_lints/src/missing_inline.rs | 2 +- clippy_lints/src/utils/inspector.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 009e3d8937e0..4678f6872f37 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { hir::ItemKind::Union(..) => "a union", hir::ItemKind::OpaqueTy(..) => "an existential type", hir::ItemKind::ExternCrate(..) - | hir::ItemKind::ForeignMod(..) + | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::GlobalAsm(..) | hir::ItemKind::Impl { .. } | hir::ItemKind::Use(..) => return, diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 53abe6086ea4..913d9daff46f 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -125,7 +125,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { | hir::ItemKind::Union(..) | hir::ItemKind::OpaqueTy(..) | hir::ItemKind::ExternCrate(..) - | hir::ItemKind::ForeignMod(..) + | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::Impl { .. } | hir::ItemKind::Use(..) => {}, }; diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 4fbfb3be32cb..8f0ef9150d45 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -395,7 +395,7 @@ fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) { println!("function of type {:#?}", item_ty); }, hir::ItemKind::Mod(..) => println!("module"), - hir::ItemKind::ForeignMod(ref fm) => println!("foreign module with abi: {}", fm.abi), + hir::ItemKind::ForeignMod { abi, .. } => println!("foreign module with abi: {}", abi), hir::ItemKind::GlobalAsm(ref asm) => println!("global asm: {:?}", asm), hir::ItemKind::TyAlias(..) => { println!("type alias for {:?}", cx.tcx.type_of(did)); From 256f91f97cb3018d08be1f7b4cf35345ee9725d7 Mon Sep 17 00:00:00 2001 From: Camelid Date: Sun, 22 Nov 2020 14:29:46 -0800 Subject: [PATCH 0145/1222] Update error to reflect that integer literals can have float suffixes For example, `1` is parsed as an integer literal, but it can be turned into a float with the suffix `f32`. Now the error calls them "numeric literals" and notes that you can add a float suffix since they can be either integers or floats. --- tests/ui/crashes/ice-3891.stderr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/crashes/ice-3891.stderr b/tests/ui/crashes/ice-3891.stderr index 5a285b0e7149..59469ec5891c 100644 --- a/tests/ui/crashes/ice-3891.stderr +++ b/tests/ui/crashes/ice-3891.stderr @@ -1,10 +1,10 @@ -error: invalid suffix `x` for integer literal +error: invalid suffix `x` for number literal --> $DIR/ice-3891.rs:2:5 | LL | 1x; | ^^ invalid suffix `x` | - = help: the suffix must be one of the integral types (`u32`, `isize`, etc) + = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) error: aborting due to previous error From bb7a6881ad10d445ddb4bd5f4137dfc88c2e50bc Mon Sep 17 00:00:00 2001 From: bstrie Date: Sat, 24 Oct 2020 19:21:40 -0400 Subject: [PATCH 0146/1222] Update tests to remove old numeric constants Part of #68490. Care has been taken to leave the old consts where appropriate, for testing backcompat regressions, module shadowing, etc. The intrinsics docs were accidentally referring to some methods on f64 as std::f64, which I changed due to being contrary with how we normally disambiguate the shadow module from the primitive. In one other place I changed std::u8 to std::ops since it was just testing path handling in macros. For places which have legitimate uses of the old consts, deprecated attributes have been optimistically inserted. Although currently unnecessary, they exist to emphasize to any future deprecation effort the necessity of these specific symbols and prevent them from being accidentally removed. --- tests/ui/float_cmp_const.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/float_cmp_const.rs b/tests/ui/float_cmp_const.rs index dfc025558a2f..263d9a7b92dd 100644 --- a/tests/ui/float_cmp_const.rs +++ b/tests/ui/float_cmp_const.rs @@ -48,7 +48,7 @@ fn main() { v != 1.0; const ZERO_ARRAY: [f32; 3] = [0.0, 0.0, 0.0]; - const ZERO_INF_ARRAY: [f32; 3] = [0.0, ::std::f32::INFINITY, ::std::f32::NEG_INFINITY]; + const ZERO_INF_ARRAY: [f32; 3] = [0.0, f32::INFINITY, f32::NEG_INFINITY]; const NON_ZERO_ARRAY: [f32; 3] = [0.0, 0.1, 0.2]; const NON_ZERO_ARRAY2: [f32; 3] = [0.2, 0.1, 0.0]; From 925f4edce3a9a08524f5061c9f1aff612c43d943 Mon Sep 17 00:00:00 2001 From: Vishnunarayan K I Date: Sat, 5 Dec 2020 20:21:21 +0530 Subject: [PATCH 0147/1222] fix clippy test --- tests/ui/crashes/used_underscore_binding_macro.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/ui/crashes/used_underscore_binding_macro.rs b/tests/ui/crashes/used_underscore_binding_macro.rs index 6d2124c12fe9..c57a45dc7aab 100644 --- a/tests/ui/crashes/used_underscore_binding_macro.rs +++ b/tests/ui/crashes/used_underscore_binding_macro.rs @@ -1,7 +1,6 @@ -#![allow(clippy::useless_attribute)] //issue #2910 +// edition:2018 -#[macro_use] -extern crate serde_derive; +use serde::Deserialize; /// Tests that we do not lint for unused underscores in a `MacroAttribute` /// expansion From 6fe433e491a54b8fb537411c697f09532885454a Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Fri, 13 Nov 2020 18:27:27 +0100 Subject: [PATCH 0148/1222] Implement lowering of if-let guards to MIR --- clippy_lints/src/utils/author.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 7250de3a41c0..135f289a2b3f 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -730,6 +730,7 @@ fn desugaring_name(des: hir::MatchSource) -> String { "MatchSource::IfLetDesugar {{ contains_else_clause: {} }}", contains_else_clause ), + hir::MatchSource::IfLetGuardDesugar => "MatchSource::IfLetGuardDesugar".to_string(), hir::MatchSource::IfDesugar { contains_else_clause } => format!( "MatchSource::IfDesugar {{ contains_else_clause: {} }}", contains_else_clause From 9e5be5954a4d0de9629205e6574f1eea67d895be Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Sun, 15 Nov 2020 22:51:02 +0100 Subject: [PATCH 0149/1222] Handle `Guard::IfLet` in clippy --- clippy_lints/src/shadow.rs | 4 ++++ clippy_lints/src/utils/author.rs | 12 ++++++++++++ clippy_lints/src/utils/hir_utils.rs | 4 +++- clippy_lints/src/utils/inspector.rs | 5 +++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 225fe58906f7..f83965926782 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -342,6 +342,10 @@ fn check_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, bindings: &mut if let Some(ref guard) = arm.guard { match guard { Guard::If(if_expr) => check_expr(cx, if_expr, bindings), + Guard::IfLet(guard_pat, guard_expr) => { + check_pat(cx, guard_pat, Some(*guard_expr), guard_pat.span, bindings); + check_expr(cx, guard_expr, bindings); + }, } } check_expr(cx, &arm.body, bindings); diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 135f289a2b3f..4249dbb4e651 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -372,6 +372,18 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { self.current = if_expr_pat; self.visit_expr(if_expr); }, + hir::Guard::IfLet(ref if_let_pat, ref if_let_expr) => { + let if_let_pat_pat = self.next("pat"); + let if_let_expr_pat = self.next("expr"); + println!( + " if let Guard::IfLet(ref {}, ref {}) = {};", + if_let_pat_pat, if_let_expr_pat, guard_pat + ); + self.current = if_let_expr_pat; + self.visit_expr(if_let_expr); + self.current = if_let_pat_pat; + self.visit_pat(if_let_pat); + }, } } self.current = format!("{}[{}].pat", arms_pat, i); diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index e4ad105c3513..b0099b4a7925 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -169,6 +169,8 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { fn eq_guard(&mut self, left: &Guard<'_>, right: &Guard<'_>) -> bool { match (left, right) { (Guard::If(l), Guard::If(r)) => self.eq_expr(l, r), + (Guard::IfLet(lp, le), Guard::IfLet(rp, re)) => self.eq_pat(lp, rp) && self.eq_expr(le, re), + _ => false, } } @@ -643,7 +645,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { pub fn hash_guard(&mut self, g: &Guard<'_>) { match g { - Guard::If(ref expr) => { + Guard::If(ref expr) | Guard::IfLet(_, ref expr) => { self.hash_expr(expr); }, } diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 8f0ef9150d45..0c93a12b9219 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -560,5 +560,10 @@ fn print_guard(cx: &LateContext<'_>, guard: &hir::Guard<'_>, indent: usize) { println!("{}If", ind); print_expr(cx, expr, indent + 1); }, + hir::Guard::IfLet(pat, expr) => { + println!("{}IfLet", ind); + print_pat(cx, pat, indent + 1); + print_expr(cx, expr, indent + 1); + }, } } From 96123ec7ff42b38810903ff5d35f0c8bf255c95f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Fri, 27 Nov 2020 00:00:00 +0000 Subject: [PATCH 0150/1222] Retain assembly operands span when lowering AST to HIR --- clippy_lints/src/loops.rs | 2 +- clippy_lints/src/utils/hir_utils.rs | 2 +- clippy_lints/src/utils/inspector.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 400148ab81dd..1bd96b2b4c89 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -768,7 +768,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { ExprKind::InlineAsm(ref asm) => asm .operands .iter() - .map(|o| match o { + .map(|(o, _)| match o { InlineAsmOperand::In { expr, .. } | InlineAsmOperand::InOut { expr, .. } | InlineAsmOperand::Const { expr } diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index d847d22275e8..d942d4e12b10 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -517,7 +517,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } asm.options.hash(&mut self.s); - for op in asm.operands { + for (op, _op_sp) in asm.operands { match op { InlineAsmOperand::In { reg, expr } => { reg.hash(&mut self.s); diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 8f0ef9150d45..323d87455388 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -293,7 +293,7 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { println!("{}template: {}", ind, InlineAsmTemplatePiece::to_string(asm.template)); println!("{}options: {:?}", ind, asm.options); println!("{}operands:", ind); - for op in asm.operands { + for (op, _op_sp) in asm.operands { match op { hir::InlineAsmOperand::In { expr, .. } | hir::InlineAsmOperand::InOut { expr, .. } From 8acdb8b7b7413642bc3209ec1aaa100a318ffe6d Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Fri, 11 Dec 2020 15:02:46 -0500 Subject: [PATCH 0151/1222] Move binder for dyn to each list item --- clippy_lints/src/utils/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 3a6b64c90e8f..0deaee3a944a 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1449,8 +1449,8 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { false }, ty::Dynamic(binder, _) => { - for predicate in binder.skip_binder().iter() { - if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate { + for predicate in binder.iter() { + if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() { if must_use_attr(&cx.tcx.get_attrs(trait_ref.def_id)).is_some() { return true; } From a0c485a71e77958e470bb653ed3f9538a96736f7 Mon Sep 17 00:00:00 2001 From: Rich Kadel Date: Mon, 14 Dec 2020 00:25:29 -0800 Subject: [PATCH 0152/1222] Improve warnings on incompatible options involving -Zinstrument-coverage Adds checks for: * `no_core` attribute * explicitly-enabled `legacy` symbol mangling * mir_opt_level > 1 (which enables inlining) I removed code from the `Inline` MIR pass that forcibly disabled inlining if `-Zinstrument-coverage` was set. The default `mir_opt_level` does not enable inlining anyway. But if the level is explicitly set and is greater than 1, I issue a warning. The new warnings show up in tests, which is much better for diagnosing potential option conflicts in these cases. --- src/driver.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index ef31c72481a2..9e5ae21f7026 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -41,7 +41,7 @@ fn arg_value<'a, T: Deref>( match arg.next().or_else(|| args.next()) { Some(v) if pred(v) => return Some(v), - _ => {}, + _ => {} } } None @@ -85,7 +85,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks { // run on the unoptimized MIR. On the other hand this results in some false negatives. If // MIR passes can be enabled / disabled separately, we should figure out, what passes to // use for Clippy. - config.opts.debugging_opts.mir_opt_level = 0; + config.opts.debugging_opts.mir_opt_level = Some(0); } } @@ -121,11 +121,12 @@ You can use tool lints to allow or deny lints from your code, eg.: const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust-clippy/issues/new"; -static ICE_HOOK: SyncLazy) + Sync + Send + 'static>> = SyncLazy::new(|| { - let hook = panic::take_hook(); - panic::set_hook(Box::new(|info| report_clippy_ice(info, BUG_REPORT_URL))); - hook -}); +static ICE_HOOK: SyncLazy) + Sync + Send + 'static>> = + SyncLazy::new(|| { + let hook = panic::take_hook(); + panic::set_hook(Box::new(|info| report_clippy_ice(info, BUG_REPORT_URL))); + hook + }); fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { // Invoke our ICE handler, which prints the actual panic message and optionally a backtrace @@ -257,14 +258,17 @@ pub fn main() { // Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument. // We're invoking the compiler programmatically, so we ignore this/ - let wrapper_mode = orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref()); + let wrapper_mode = + orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref()); if wrapper_mode { // we still want to be able to invoke it normally though orig_args.remove(1); } - if !wrapper_mode && (orig_args.iter().any(|a| a == "--help" || a == "-h") || orig_args.len() == 1) { + if !wrapper_mode + && (orig_args.iter().any(|a| a == "--help" || a == "-h") || orig_args.len() == 1) + { display_help(); exit(0); } @@ -285,13 +289,11 @@ pub fn main() { if clippy_enabled { args.extend(vec!["--cfg".into(), r#"feature="cargo-clippy""#.into()]); if let Ok(extra_args) = env::var("CLIPPY_ARGS") { - args.extend(extra_args.split("__CLIPPY_HACKERY__").filter_map(|s| { - if s.is_empty() { - None - } else { - Some(s.to_string()) - } - })); + args.extend( + extra_args + .split("__CLIPPY_HACKERY__") + .filter_map(|s| if s.is_empty() { None } else { Some(s.to_string()) }), + ); } } let mut clippy = ClippyCallbacks; From 544afaf982911bfc08ecd5454faa1aed4ed5ecc4 Mon Sep 17 00:00:00 2001 From: Rich Kadel Date: Mon, 14 Dec 2020 13:12:15 -0800 Subject: [PATCH 0153/1222] Convenience funcs for `some_option.unwrap_or(...)` This ensures consistent handling of default values for options that are None if not specified on the command line. --- src/driver.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver.rs b/src/driver.rs index 9e5ae21f7026..87dd19c5d4d0 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -85,7 +85,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks { // run on the unoptimized MIR. On the other hand this results in some false negatives. If // MIR passes can be enabled / disabled separately, we should figure out, what passes to // use for Clippy. - config.opts.debugging_opts.mir_opt_level = Some(0); + config.opts.debugging_opts.mir_opt_level = 0; } } From a852264e587fd12002286e325f0dffba3f304093 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Wed, 16 Dec 2020 22:36:14 -0500 Subject: [PATCH 0154/1222] More rebinds --- clippy_lints/src/await_holding_invalid.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index 58892024ce24..cfade9cbc469 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -99,7 +99,7 @@ impl LateLintPass<'_> for AwaitHolding { }; let def_id = cx.tcx.hir().body_owner_def_id(body_id); let typeck_results = cx.tcx.typeck(def_id); - check_interior_types(cx, &typeck_results.generator_interior_types, body.value.span); + check_interior_types(cx, &typeck_results.generator_interior_types.as_ref().skip_binder(), body.value.span); } } } From e173df21cea5ac0aed0256b706175eec255f860a Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Tue, 22 Dec 2020 19:17:59 +0100 Subject: [PATCH 0155/1222] Revert "Pass Clippy args also trough RUSTFLAGS" --- .cargo/config | 6 - .editorconfig | 19 - .gitattributes | 3 - .github/ISSUE_TEMPLATE/blank_issue.md | 4 - .github/ISSUE_TEMPLATE/bug_report.md | 47 - .github/ISSUE_TEMPLATE/config.yml | 5 - .github/ISSUE_TEMPLATE/ice.md | 53 - .github/ISSUE_TEMPLATE/new_lint.md | 35 - .github/PULL_REQUEST_TEMPLATE.md | 32 - .github/deploy.sh | 66 - .github/driver.sh | 39 - .github/workflows/clippy.yml | 82 - .github/workflows/clippy_bors.yml | 255 -- .github/workflows/clippy_dev.yml | 78 - .github/workflows/deploy.yml | 51 - .github/workflows/remark.yml | 55 - .gitignore | 37 - .remarkrc | 12 - CHANGELOG.md | 2176 --------- CODE_OF_CONDUCT.md | 70 - CONTRIBUTING.md | 345 -- COPYRIGHT | 7 - Cargo.toml | 56 - LICENSE-APACHE | 201 - LICENSE-MIT | 27 - README.md | 251 -- build.rs | 19 - clippy_dev/Cargo.toml | 17 - clippy_dev/src/bless.rs | 74 - clippy_dev/src/fmt.rs | 194 - clippy_dev/src/lib.rs | 545 --- clippy_dev/src/main.rs | 160 - clippy_dev/src/new_lint.rs | 219 - clippy_dev/src/ra_setup.rs | 100 - clippy_dev/src/serve.rs | 64 - clippy_dev/src/stderr_length_check.rs | 51 - clippy_dev/src/update_lints.rs | 149 - clippy_dummy/Cargo.toml | 17 - clippy_dummy/PUBLISH.md | 6 - clippy_dummy/build.rs | 42 - clippy_dummy/crates-readme.md | 9 - clippy_dummy/src/main.rs | 3 - clippy_lints/Cargo.toml | 41 - clippy_lints/README.md | 1 - clippy_lints/src/approx_const.rs | 117 - clippy_lints/src/arithmetic.rs | 168 - clippy_lints/src/as_conversions.rs | 58 - clippy_lints/src/asm_syntax.rs | 125 - clippy_lints/src/assertions_on_constants.rs | 154 - clippy_lints/src/assign_ops.rs | 263 -- clippy_lints/src/async_yields_async.rs | 86 - clippy_lints/src/atomic_ordering.rs | 229 - clippy_lints/src/attrs.rs | 717 --- clippy_lints/src/await_holding_invalid.rs | 149 - clippy_lints/src/bit_mask.rs | 326 -- clippy_lints/src/blacklisted_name.rs | 51 - clippy_lints/src/blocks_in_if_conditions.rs | 144 - clippy_lints/src/booleans.rs | 504 --- clippy_lints/src/bytecount.rs | 118 - clippy_lints/src/cargo_common_metadata.rs | 112 - clippy_lints/src/checked_conversions.rs | 360 -- clippy_lints/src/cognitive_complexity.rs | 163 - clippy_lints/src/collapsible_if.rs | 170 - clippy_lints/src/collapsible_match.rs | 172 - clippy_lints/src/comparison_chain.rs | 127 - clippy_lints/src/consts.rs | 576 --- clippy_lints/src/copies.rs | 209 - clippy_lints/src/copy_iterator.rs | 55 - clippy_lints/src/create_dir.rs | 51 - clippy_lints/src/dbg_macro.rs | 65 - clippy_lints/src/default.rs | 303 -- clippy_lints/src/deprecated_lints.rs | 168 - clippy_lints/src/dereference.rs | 109 - clippy_lints/src/derive.rs | 423 -- clippy_lints/src/disallowed_method.rs | 73 - clippy_lints/src/doc.rs | 611 --- clippy_lints/src/double_comparison.rs | 94 - clippy_lints/src/double_parens.rs | 76 - clippy_lints/src/drop_forget_ref.rs | 160 - clippy_lints/src/duration_subsec.rs | 71 - clippy_lints/src/else_if_without_else.rs | 72 - clippy_lints/src/empty_enum.rs | 60 - clippy_lints/src/entry.rs | 184 - clippy_lints/src/enum_clike.rs | 82 - clippy_lints/src/enum_variants.rs | 327 -- clippy_lints/src/eq_op.rs | 247 - clippy_lints/src/erasing_op.rs | 59 - clippy_lints/src/escape.rs | 174 - clippy_lints/src/eta_reduction.rs | 228 - clippy_lints/src/eval_order_dependence.rs | 364 -- clippy_lints/src/excessive_bools.rs | 176 - clippy_lints/src/exit.rs | 47 - clippy_lints/src/explicit_write.rs | 150 - clippy_lints/src/fallible_impl_from.rs | 148 - .../src/float_equality_without_abs.rs | 112 - clippy_lints/src/float_literal.rs | 182 - clippy_lints/src/floating_point_arithmetic.rs | 721 --- clippy_lints/src/format.rs | 205 - clippy_lints/src/formatting.rs | 314 -- clippy_lints/src/functions.rs | 738 --- clippy_lints/src/future_not_send.rs | 111 - clippy_lints/src/get_last_with_len.rs | 104 - clippy_lints/src/identity_op.rs | 100 - clippy_lints/src/if_let_mutex.rs | 157 - clippy_lints/src/if_let_some_result.rs | 72 - clippy_lints/src/if_not_else.rs | 83 - clippy_lints/src/implicit_return.rs | 144 - clippy_lints/src/implicit_saturating_sub.rs | 165 - clippy_lints/src/indexing_slicing.rs | 197 - clippy_lints/src/infinite_iter.rs | 254 -- clippy_lints/src/inherent_impl.rs | 94 - clippy_lints/src/inherent_to_string.rs | 157 - clippy_lints/src/inline_fn_without_body.rs | 58 - clippy_lints/src/int_plus_one.rs | 171 - clippy_lints/src/integer_division.rs | 59 - clippy_lints/src/items_after_statements.rs | 88 - clippy_lints/src/large_const_arrays.rs | 84 - clippy_lints/src/large_enum_variant.rs | 134 - clippy_lints/src/large_stack_arrays.rs | 68 - clippy_lints/src/len_zero.rs | 375 -- clippy_lints/src/let_if_seq.rs | 163 - clippy_lints/src/let_underscore.rs | 179 - clippy_lints/src/lib.rs | 2036 --------- clippy_lints/src/lifetimes.rs | 512 --- clippy_lints/src/literal_representation.rs | 497 -- clippy_lints/src/loops.rs | 3120 ------------- clippy_lints/src/macro_use.rs | 232 - clippy_lints/src/main_recursion.rs | 62 - clippy_lints/src/manual_async_fn.rs | 200 - clippy_lints/src/manual_non_exhaustive.rs | 194 - clippy_lints/src/manual_ok_or.rs | 100 - clippy_lints/src/manual_strip.rs | 264 -- clippy_lints/src/manual_unwrap_or.rs | 129 - clippy_lints/src/map_clone.rs | 157 - clippy_lints/src/map_err_ignore.rs | 147 - clippy_lints/src/map_identity.rs | 127 - clippy_lints/src/map_unit_fn.rs | 275 -- clippy_lints/src/match_on_vec_items.rs | 101 - clippy_lints/src/matches.rs | 1927 -------- clippy_lints/src/mem_discriminant.rs | 81 - clippy_lints/src/mem_forget.rs | 44 - clippy_lints/src/mem_replace.rs | 260 -- .../src/methods/bind_instead_of_map.rs | 193 - .../src/methods/inefficient_to_string.rs | 63 - .../methods/manual_saturating_arithmetic.rs | 175 - clippy_lints/src/methods/mod.rs | 4003 ----------------- .../src/methods/option_map_unwrap_or.rs | 135 - .../src/methods/unnecessary_filter_map.rs | 134 - .../src/methods/unnecessary_lazy_eval.rs | 65 - clippy_lints/src/minmax.rs | 123 - clippy_lints/src/misc.rs | 768 ---- clippy_lints/src/misc_early.rs | 568 --- clippy_lints/src/missing_const_for_fn.rs | 166 - clippy_lints/src/missing_doc.rs | 200 - clippy_lints/src/missing_inline.rs | 166 - clippy_lints/src/modulo_arithmetic.rs | 148 - clippy_lints/src/multiple_crate_versions.rs | 96 - clippy_lints/src/mut_key.rs | 127 - clippy_lints/src/mut_mut.rs | 114 - clippy_lints/src/mut_mutex_lock.rs | 68 - clippy_lints/src/mut_reference.rs | 88 - clippy_lints/src/mutable_debug_assertion.rs | 115 - clippy_lints/src/mutex_atomic.rs | 98 - .../src/needless_arbitrary_self_type.rs | 138 - clippy_lints/src/needless_bool.rs | 357 -- clippy_lints/src/needless_borrow.rs | 132 - clippy_lints/src/needless_borrowed_ref.rs | 92 - clippy_lints/src/needless_continue.rs | 463 -- clippy_lints/src/needless_pass_by_value.rs | 338 -- clippy_lints/src/needless_update.rs | 68 - clippy_lints/src/neg_cmp_op_on_partial_ord.rs | 91 - clippy_lints/src/neg_multiply.rs | 53 - clippy_lints/src/new_without_default.rs | 165 - clippy_lints/src/no_effect.rs | 178 - clippy_lints/src/non_copy_const.rs | 425 -- clippy_lints/src/non_expressive_names.rs | 419 -- clippy_lints/src/open_options.rs | 203 - clippy_lints/src/option_env_unwrap.rs | 55 - clippy_lints/src/option_if_let_else.rs | 217 - .../src/overflow_check_conditional.rs | 82 - clippy_lints/src/panic_in_result_fn.rs | 84 - clippy_lints/src/panic_unimplemented.rs | 108 - clippy_lints/src/partialeq_ne_impl.rs | 56 - clippy_lints/src/pass_by_ref_or_value.rs | 257 -- clippy_lints/src/path_buf_push_overwrite.rs | 71 - clippy_lints/src/pattern_type_mismatch.rs | 311 -- clippy_lints/src/precedence.rs | 159 - clippy_lints/src/ptr.rs | 329 -- clippy_lints/src/ptr_eq.rs | 96 - clippy_lints/src/ptr_offset_with_cast.rs | 151 - clippy_lints/src/question_mark.rs | 204 - clippy_lints/src/ranges.rs | 542 --- clippy_lints/src/redundant_clone.rs | 626 --- clippy_lints/src/redundant_closure_call.rs | 156 - clippy_lints/src/redundant_else.rs | 135 - clippy_lints/src/redundant_field_names.rs | 86 - clippy_lints/src/redundant_pub_crate.rs | 78 - .../src/redundant_static_lifetimes.rs | 119 - clippy_lints/src/ref_option_ref.rs | 67 - clippy_lints/src/reference.rs | 140 - clippy_lints/src/regex.rs | 209 - clippy_lints/src/repeat_once.rs | 83 - clippy_lints/src/returns.rs | 290 -- clippy_lints/src/self_assignment.rs | 51 - clippy_lints/src/serde_api.rs | 57 - clippy_lints/src/shadow.rs | 393 -- .../src/single_component_path_imports.rs | 62 - clippy_lints/src/size_of_in_element_count.rs | 145 - .../src/slow_vector_initialization.rs | 330 -- clippy_lints/src/stable_sort_primitive.rs | 132 - clippy_lints/src/strings.rs | 388 -- .../src/suspicious_operation_groupings.rs | 693 --- clippy_lints/src/suspicious_trait_impl.rs | 208 - clippy_lints/src/swap.rs | 263 -- clippy_lints/src/tabs_in_doc_comments.rs | 220 - clippy_lints/src/temporary_assignment.rs | 42 - clippy_lints/src/to_digit_is_some.rs | 94 - clippy_lints/src/to_string_in_display.rs | 122 - clippy_lints/src/trait_bounds.rs | 192 - clippy_lints/src/transmute.rs | 763 ---- clippy_lints/src/transmuting_null.rs | 88 - clippy_lints/src/try_err.rs | 190 - clippy_lints/src/types.rs | 2880 ------------ clippy_lints/src/undropped_manually_drops.rs | 50 - clippy_lints/src/unicode.rs | 134 - clippy_lints/src/unit_return_expecting_ord.rs | 177 - clippy_lints/src/unnamed_address.rs | 131 - clippy_lints/src/unnecessary_sort_by.rs | 274 -- clippy_lints/src/unnecessary_wraps.rs | 148 - clippy_lints/src/unnested_or_patterns.rs | 408 -- clippy_lints/src/unsafe_removed_from_name.rs | 78 - clippy_lints/src/unused_io_amount.rs | 92 - clippy_lints/src/unused_self.rs | 105 - clippy_lints/src/unused_unit.rs | 142 - clippy_lints/src/unwrap.rs | 234 - clippy_lints/src/unwrap_in_result.rs | 140 - clippy_lints/src/use_self.rs | 288 -- clippy_lints/src/useless_conversion.rs | 190 - clippy_lints/src/utils/ast_utils.rs | 547 --- .../src/utils/ast_utils/ident_iter.rs | 45 - clippy_lints/src/utils/attrs.rs | 149 - clippy_lints/src/utils/author.rs | 790 ---- clippy_lints/src/utils/camel_case.rs | 115 - clippy_lints/src/utils/comparisons.rs | 36 - clippy_lints/src/utils/conf.rs | 254 -- clippy_lints/src/utils/constants.rs | 13 - clippy_lints/src/utils/diagnostics.rs | 228 - clippy_lints/src/utils/eager_or_lazy.rs | 133 - clippy_lints/src/utils/higher.rs | 296 -- clippy_lints/src/utils/hir_utils.rs | 787 ---- clippy_lints/src/utils/inspector.rs | 569 --- clippy_lints/src/utils/internal_lints.rs | 920 ---- clippy_lints/src/utils/mod.rs | 1785 -------- clippy_lints/src/utils/numeric_literal.rs | 228 - clippy_lints/src/utils/paths.rs | 172 - clippy_lints/src/utils/ptr.rs | 87 - .../src/utils/qualify_min_const_fn.rs | 347 -- clippy_lints/src/utils/sugg.rs | 682 --- clippy_lints/src/utils/sym.rs | 6 - clippy_lints/src/utils/usage.rs | 230 - clippy_lints/src/utils/visitors.rs | 178 - clippy_lints/src/vec.rs | 135 - clippy_lints/src/vec_resize_to_zero.rs | 59 - clippy_lints/src/verbose_file_reads.rs | 86 - clippy_lints/src/wildcard_dependencies.rs | 57 - clippy_lints/src/wildcard_imports.rs | 211 - clippy_lints/src/write.rs | 554 --- clippy_lints/src/zero_div_zero.rs | 65 - clippy_lints/src/zero_sized_map_values.rs | 82 - clippy_workspace_tests/Cargo.toml | 7 - clippy_workspace_tests/build.rs | 7 - clippy_workspace_tests/path_dep/Cargo.toml | 3 - clippy_workspace_tests/path_dep/src/lib.rs | 6 - clippy_workspace_tests/src/main.rs | 3 - clippy_workspace_tests/subcrate/Cargo.toml | 6 - clippy_workspace_tests/subcrate/src/lib.rs | 1 - doc/adding_lints.md | 566 --- doc/backport.md | 71 - doc/basics.md | 96 - doc/changelog_update.md | 97 - doc/common_tools_writing_lints.md | 202 - doc/release.md | 109 - etc/relicense/RELICENSE_DOCUMENTATION.md | 69 - etc/relicense/contributors.txt | 232 - etc/relicense/relicense_comments.txt | 227 - mini-macro/Cargo.toml | 20 - mini-macro/src/lib.rs | 26 - rust-toolchain | 3 - rustc_tools_util/Cargo.toml | 16 - rustc_tools_util/LICENSE-APACHE | 1 - rustc_tools_util/LICENSE-MIT | 1 - rustc_tools_util/README.md | 62 - rustc_tools_util/src/lib.rs | 162 - rustfmt.toml | 6 - src/driver.rs | 375 -- src/main.rs | 315 -- tests/auxiliary/test_macro.rs | 11 - tests/cargo/mod.rs | 26 - tests/compile-test.rs | 269 -- tests/dogfood.rs | 150 - tests/fmt.rs | 36 - tests/integration.rs | 84 - tests/missing-test-files.rs | 56 - .../cargo_common_metadata/fail/Cargo.toml | 6 - .../cargo_common_metadata/fail/src/main.rs | 4 - .../fail/src/main.stderr | 18 - .../cargo_common_metadata/pass/Cargo.toml | 13 - .../cargo_common_metadata/pass/src/main.rs | 4 - .../5041_allow_dev_build/Cargo.toml | 19 - .../5041_allow_dev_build/src/main.rs | 4 - .../multiple_crate_versions/fail/Cargo.lock | 109 - .../multiple_crate_versions/fail/Cargo.toml | 10 - .../multiple_crate_versions/fail/src/main.rs | 4 - .../fail/src/main.stderr | 6 - .../multiple_crate_versions/pass/Cargo.toml | 10 - .../multiple_crate_versions/pass/src/main.rs | 4 - tests/ui-cargo/update-all-references.sh | 3 - .../wildcard_dependencies/fail/Cargo.toml | 9 - .../wildcard_dependencies/fail/src/main.rs | 4 - .../fail/src/main.stderr | 6 - .../wildcard_dependencies/pass/Cargo.toml | 9 - .../wildcard_dependencies/pass/src/main.rs | 4 - .../collapsible_span_lint_calls.fixed | 91 - .../collapsible_span_lint_calls.rs | 101 - .../collapsible_span_lint_calls.stderr | 49 - tests/ui-internal/custom_ice_message.rs | 10 - tests/ui-internal/custom_ice_message.stderr | 13 - tests/ui-internal/default_lint.rs | 27 - tests/ui-internal/default_lint.stderr | 21 - .../interning_defined_symbol.fixed | 33 - tests/ui-internal/interning_defined_symbol.rs | 33 - .../interning_defined_symbol.stderr | 27 - tests/ui-internal/invalid_paths.rs | 23 - tests/ui-internal/invalid_paths.stderr | 16 - tests/ui-internal/lint_without_lint_pass.rs | 44 - .../ui-internal/lint_without_lint_pass.stderr | 21 - tests/ui-internal/match_type_on_diag_item.rs | 50 - .../match_type_on_diag_item.stderr | 33 - tests/ui-internal/outer_expn_data.fixed | 28 - tests/ui-internal/outer_expn_data.rs | 28 - tests/ui-internal/outer_expn_data.stderr | 15 - tests/ui-toml/bad_toml/clippy.toml | 2 - tests/ui-toml/bad_toml/conf_bad_toml.rs | 3 - tests/ui-toml/bad_toml/conf_bad_toml.stderr | 4 - tests/ui-toml/bad_toml_type/clippy.toml | 1 - tests/ui-toml/bad_toml_type/conf_bad_type.rs | 4 - .../bad_toml_type/conf_bad_type.stderr | 4 - tests/ui-toml/conf_deprecated_key/clippy.toml | 6 - .../conf_deprecated_key.rs | 4 - .../conf_deprecated_key.stderr | 4 - .../fn_params_excessive_bools/clippy.toml | 1 - .../ui-toml/fn_params_excessive_bools/test.rs | 6 - .../fn_params_excessive_bools/test.stderr | 11 - tests/ui-toml/functions_maxlines/clippy.toml | 1 - tests/ui-toml/functions_maxlines/test.rs | 45 - tests/ui-toml/functions_maxlines/test.stderr | 23 - .../good_toml_no_false_negatives/clippy.toml | 3 - .../conf_no_false_negatives.rs | 3 - .../invalid_min_rust_version/clippy.toml | 1 - .../invalid_min_rust_version.rs | 3 - .../invalid_min_rust_version.stderr | 4 - .../lint_decimal_readability/clippy.toml | 1 - .../ui-toml/lint_decimal_readability/test.rs | 22 - .../lint_decimal_readability/test.stderr | 10 - tests/ui-toml/min_rust_version/clippy.toml | 1 - .../min_rust_version/min_rust_version.rs | 68 - .../struct_excessive_bools/clippy.toml | 1 - tests/ui-toml/struct_excessive_bools/test.rs | 9 - .../struct_excessive_bools/test.stderr | 13 - tests/ui-toml/toml_blacklist/clippy.toml | 1 - .../conf_french_blacklisted_name.rs | 20 - .../conf_french_blacklisted_name.stderr | 46 - .../toml_disallowed_method/clippy.toml | 1 - .../conf_disallowed_method.rs | 13 - .../conf_disallowed_method.stderr | 16 - tests/ui-toml/toml_trivially_copy/clippy.toml | 1 - tests/ui-toml/toml_trivially_copy/test.rs | 21 - tests/ui-toml/toml_trivially_copy/test.stderr | 20 - tests/ui-toml/toml_unknown_key/clippy.toml | 6 - .../toml_unknown_key/conf_unknown_key.rs | 3 - .../toml_unknown_key/conf_unknown_key.stderr | 4 - tests/ui-toml/update-all-references.sh | 3 - tests/ui-toml/vec_box_sized/clippy.toml | 1 - tests/ui-toml/vec_box_sized/test.rs | 15 - tests/ui-toml/vec_box_sized/test.stderr | 22 - .../zero_single_char_names/clippy.toml | 1 - .../zero_single_char_names.rs | 3 - tests/ui/absurd-extreme-comparisons.rs | 61 - tests/ui/absurd-extreme-comparisons.stderr | 147 - tests/ui/approx_const.rs | 60 - tests/ui/approx_const.stderr | 130 - tests/ui/as_conversions.rs | 19 - tests/ui/as_conversions.stderr | 27 - tests/ui/asm_syntax.rs | 31 - tests/ui/asm_syntax.stderr | 44 - tests/ui/assertions_on_constants.rs | 29 - tests/ui/assertions_on_constants.stderr | 84 - tests/ui/assign_ops.fixed | 21 - tests/ui/assign_ops.rs | 21 - tests/ui/assign_ops.stderr | 58 - tests/ui/assign_ops2.rs | 55 - tests/ui/assign_ops2.stderr | 146 - tests/ui/async_yields_async.fixed | 68 - tests/ui/async_yields_async.rs | 68 - tests/ui/async_yields_async.stderr | 96 - tests/ui/atomic_ordering_bool.rs | 25 - tests/ui/atomic_ordering_bool.stderr | 35 - tests/ui/atomic_ordering_exchange.rs | 45 - tests/ui/atomic_ordering_exchange.stderr | 131 - tests/ui/atomic_ordering_exchange_weak.rs | 47 - tests/ui/atomic_ordering_exchange_weak.stderr | 131 - tests/ui/atomic_ordering_fence.rs | 20 - tests/ui/atomic_ordering_fence.stderr | 19 - tests/ui/atomic_ordering_fetch_update.rs | 45 - tests/ui/atomic_ordering_fetch_update.stderr | 131 - tests/ui/atomic_ordering_int.rs | 86 - tests/ui/atomic_ordering_int.stderr | 163 - tests/ui/atomic_ordering_ptr.rs | 27 - tests/ui/atomic_ordering_ptr.stderr | 35 - tests/ui/atomic_ordering_uint.rs | 86 - tests/ui/atomic_ordering_uint.stderr | 163 - tests/ui/attrs.rs | 45 - tests/ui/attrs.stderr | 24 - tests/ui/author.rs | 4 - tests/ui/author.stdout | 14 - tests/ui/author/blocks.rs | 16 - tests/ui/author/blocks.stdout | 13 - tests/ui/author/call.rs | 4 - tests/ui/author/call.stdout | 16 - tests/ui/author/for_loop.rs | 8 - tests/ui/author/for_loop.stdout | 64 - tests/ui/author/if.rs | 10 - tests/ui/author/if.stdout | 31 - tests/ui/author/issue_3849.rs | 14 - tests/ui/author/issue_3849.stdout | 14 - tests/ui/author/matches.rs | 13 - tests/ui/author/matches.stdout | 33 - tests/ui/auxiliary/doc_unsafe_macros.rs | 8 - tests/ui/auxiliary/implicit_hasher_macros.rs | 6 - tests/ui/auxiliary/macro_rules.rs | 86 - tests/ui/auxiliary/macro_use_helper.rs | 60 - tests/ui/auxiliary/option_helpers.rs | 51 - tests/ui/auxiliary/proc_macro_attr.rs | 96 - tests/ui/auxiliary/proc_macro_derive.rs | 25 - tests/ui/auxiliary/use_self_macro.rs | 15 - tests/ui/auxiliary/wildcard_imports_helper.rs | 27 - tests/ui/await_holding_lock.rs | 65 - tests/ui/await_holding_lock.stderr | 63 - tests/ui/await_holding_refcell_ref.rs | 86 - tests/ui/await_holding_refcell_ref.stderr | 95 - tests/ui/bind_instead_of_map.fixed | 25 - tests/ui/bind_instead_of_map.rs | 25 - tests/ui/bind_instead_of_map.stderr | 26 - tests/ui/bind_instead_of_map_multipart.rs | 61 - tests/ui/bind_instead_of_map_multipart.stderr | 73 - tests/ui/bit_masks.rs | 63 - tests/ui/bit_masks.stderr | 110 - tests/ui/blacklisted_name.rs | 45 - tests/ui/blacklisted_name.stderr | 88 - tests/ui/blanket_clippy_restriction_lints.rs | 8 - .../blanket_clippy_restriction_lints.stderr | 27 - tests/ui/blocks_in_if_conditions.fixed | 74 - tests/ui/blocks_in_if_conditions.rs | 74 - tests/ui/blocks_in_if_conditions.stderr | 34 - tests/ui/blocks_in_if_conditions_closure.rs | 47 - .../ui/blocks_in_if_conditions_closure.stderr | 24 - tests/ui/bool_comparison.fixed | 167 - tests/ui/bool_comparison.rs | 167 - tests/ui/bool_comparison.stderr | 136 - tests/ui/borrow_box.rs | 115 - tests/ui/borrow_box.stderr | 68 - .../auxiliary/helper.rs | 16 - .../ui/borrow_interior_mutable_const/enums.rs | 101 - .../enums.stderr | 75 - .../borrow_interior_mutable_const/others.rs | 104 - .../others.stderr | 115 - .../borrow_interior_mutable_const/traits.rs | 202 - .../traits.stderr | 123 - tests/ui/box_vec.rs | 32 - tests/ui/box_vec.stderr | 11 - tests/ui/builtin-type-shadow.rs | 9 - tests/ui/builtin-type-shadow.stderr | 24 - tests/ui/bytecount.rs | 24 - tests/ui/bytecount.stderr | 26 - tests/ui/cast.rs | 95 - tests/ui/cast.stderr | 142 - tests/ui/cast_alignment.rs | 27 - tests/ui/cast_alignment.stderr | 16 - tests/ui/cast_lossless_float.fixed | 45 - tests/ui/cast_lossless_float.rs | 45 - tests/ui/cast_lossless_float.stderr | 70 - tests/ui/cast_lossless_integer.fixed | 47 - tests/ui/cast_lossless_integer.rs | 47 - tests/ui/cast_lossless_integer.stderr | 118 - tests/ui/cast_ref_to_mut.rs | 31 - tests/ui/cast_ref_to_mut.stderr | 22 - tests/ui/cast_size.rs | 35 - tests/ui/cast_size.stderr | 116 - tests/ui/cast_size_32bit.rs | 35 - tests/ui/cast_size_32bit.stderr | 132 - tests/ui/cfg_attr_rustfmt.fixed | 31 - tests/ui/cfg_attr_rustfmt.rs | 31 - tests/ui/cfg_attr_rustfmt.stderr | 16 - tests/ui/char_lit_as_u8.rs | 5 - tests/ui/char_lit_as_u8.stderr | 11 - tests/ui/char_lit_as_u8_suggestions.fixed | 10 - tests/ui/char_lit_as_u8_suggestions.rs | 10 - tests/ui/char_lit_as_u8_suggestions.stderr | 35 - tests/ui/checked_conversions.fixed | 76 - tests/ui/checked_conversions.rs | 76 - tests/ui/checked_conversions.stderr | 100 - .../ui/checked_unwrap/complex_conditionals.rs | 54 - .../complex_conditionals.stderr | 192 - .../complex_conditionals_nested.rs | 15 - .../complex_conditionals_nested.stderr | 31 - .../ui/checked_unwrap/simple_conditionals.rs | 80 - .../checked_unwrap/simple_conditionals.stderr | 131 - tests/ui/clone_on_copy.fixed | 40 - tests/ui/clone_on_copy.rs | 40 - tests/ui/clone_on_copy.stderr | 34 - tests/ui/clone_on_copy_impl.rs | 22 - tests/ui/clone_on_copy_mut.rs | 18 - tests/ui/cmp_nan.rs | 34 - tests/ui/cmp_nan.stderr | 148 - tests/ui/cmp_null.rs | 17 - tests/ui/cmp_null.stderr | 16 - .../ui/cmp_owned/asymmetric_partial_eq.fixed | 93 - tests/ui/cmp_owned/asymmetric_partial_eq.rs | 93 - .../ui/cmp_owned/asymmetric_partial_eq.stderr | 46 - tests/ui/cmp_owned/with_suggestion.fixed | 72 - tests/ui/cmp_owned/with_suggestion.rs | 72 - tests/ui/cmp_owned/with_suggestion.stderr | 40 - tests/ui/cmp_owned/without_suggestion.rs | 52 - tests/ui/cmp_owned/without_suggestion.stderr | 22 - tests/ui/cognitive_complexity.rs | 395 -- tests/ui/cognitive_complexity.stderr | 139 - tests/ui/cognitive_complexity_attr_used.rs | 15 - .../ui/cognitive_complexity_attr_used.stderr | 11 - tests/ui/collapsible_else_if.fixed | 66 - tests/ui/collapsible_else_if.rs | 80 - tests/ui/collapsible_else_if.stderr | 154 - tests/ui/collapsible_if.fixed | 141 - tests/ui/collapsible_if.rs | 157 - tests/ui/collapsible_if.stderr | 130 - tests/ui/collapsible_match.rs | 239 - tests/ui/collapsible_match.stderr | 179 - tests/ui/collapsible_match2.rs | 53 - tests/ui/collapsible_match2.stderr | 61 - tests/ui/comparison_chain.rs | 206 - tests/ui/comparison_chain.stderr | 97 - tests/ui/comparison_to_empty.fixed | 23 - tests/ui/comparison_to_empty.rs | 23 - tests/ui/comparison_to_empty.stderr | 28 - tests/ui/complex_types.rs | 60 - tests/ui/complex_types.stderr | 94 - tests/ui/copy_iterator.rs | 23 - tests/ui/copy_iterator.stderr | 17 - tests/ui/crashes/associated-constant-ice.rs | 13 - tests/ui/crashes/auxiliary/ice-4727-aux.rs | 9 - .../ui/crashes/auxiliary/proc_macro_crash.rs | 39 - tests/ui/crashes/auxiliary/use_self_macro.rs | 15 - tests/ui/crashes/cc_seme.rs | 27 - tests/ui/crashes/enum-glob-import-crate.rs | 6 - tests/ui/crashes/ice-1588.rs | 13 - tests/ui/crashes/ice-1782.rs | 26 - tests/ui/crashes/ice-1969.rs | 13 - tests/ui/crashes/ice-2499.rs | 26 - tests/ui/crashes/ice-2594.rs | 20 - tests/ui/crashes/ice-2727.rs | 7 - tests/ui/crashes/ice-2760.rs | 23 - tests/ui/crashes/ice-2774.rs | 27 - tests/ui/crashes/ice-2774.stderr | 10 - tests/ui/crashes/ice-2862.rs | 16 - tests/ui/crashes/ice-2865.rs | 16 - tests/ui/crashes/ice-3151.rs | 15 - tests/ui/crashes/ice-3462.rs | 23 - tests/ui/crashes/ice-360.rs | 12 - tests/ui/crashes/ice-360.stderr | 25 - tests/ui/crashes/ice-3717.rs | 10 - tests/ui/crashes/ice-3717.stderr | 22 - tests/ui/crashes/ice-3741.rs | 10 - tests/ui/crashes/ice-3747.rs | 17 - tests/ui/crashes/ice-3891.rs | 3 - tests/ui/crashes/ice-3891.stderr | 10 - tests/ui/crashes/ice-3969.rs | 51 - tests/ui/crashes/ice-3969.stderr | 22 - tests/ui/crashes/ice-4121.rs | 13 - tests/ui/crashes/ice-4545.rs | 14 - tests/ui/crashes/ice-4579.rs | 13 - tests/ui/crashes/ice-4671.rs | 21 - tests/ui/crashes/ice-4727.rs | 6 - tests/ui/crashes/ice-4760.rs | 9 - tests/ui/crashes/ice-4775.rs | 14 - tests/ui/crashes/ice-4968.rs | 20 - tests/ui/crashes/ice-5207.rs | 7 - tests/ui/crashes/ice-5223.rs | 18 - tests/ui/crashes/ice-5238.rs | 9 - tests/ui/crashes/ice-5389.rs | 13 - tests/ui/crashes/ice-5497.rs | 11 - tests/ui/crashes/ice-5579.rs | 17 - tests/ui/crashes/ice-5872.rs | 5 - tests/ui/crashes/ice-5872.stderr | 10 - tests/ui/crashes/ice-5944.rs | 13 - tests/ui/crashes/ice-6139.rs | 7 - tests/ui/crashes/ice-6153.rs | 9 - tests/ui/crashes/ice-6250.rs | 16 - tests/ui/crashes/ice-6250.stderr | 42 - tests/ui/crashes/ice-6251.rs | 6 - tests/ui/crashes/ice-6251.stderr | 43 - tests/ui/crashes/ice-6252.rs | 15 - tests/ui/crashes/ice-6252.stderr | 32 - tests/ui/crashes/ice-6254.rs | 15 - tests/ui/crashes/ice-6254.stderr | 12 - tests/ui/crashes/ice-6255.rs | 15 - tests/ui/crashes/ice-6255.stderr | 13 - tests/ui/crashes/ice-6256.rs | 13 - tests/ui/crashes/ice-6256.stderr | 18 - tests/ui/crashes/ice-6332.rs | 11 - tests/ui/crashes/ice-700.rs | 9 - tests/ui/crashes/ice_exacte_size.rs | 19 - tests/ui/crashes/if_same_then_else.rs | 16 - tests/ui/crashes/implements-trait.rs | 5 - tests/ui/crashes/inherent_impl.rs | 26 - tests/ui/crashes/issue-825.rs | 25 - tests/ui/crashes/issues_loop_mut_cond.rs | 28 - tests/ui/crashes/match_same_arms_const.rs | 18 - tests/ui/crashes/mut_mut_macro.rs | 34 - tests/ui/crashes/needless_borrow_fp.rs | 7 - .../crashes/needless_lifetimes_impl_trait.rs | 20 - .../needless_lifetimes_impl_trait.stderr | 14 - tests/ui/crashes/procedural_macro.rs | 11 - tests/ui/crashes/regressions.rs | 11 - tests/ui/crashes/returns.rs | 23 - tests/ui/crashes/shadow.rs | 6 - tests/ui/crashes/single-match-else.rs | 11 - tests/ui/crashes/third-party/clippy.toml | 3 - .../crashes/third-party/conf_allowlisted.rs | 1 - tests/ui/crashes/trivial_bounds.rs | 11 - .../crashes/used_underscore_binding_macro.rs | 18 - .../entrypoint_recursion.rs | 12 - .../entrypoint_recursion.stderr | 11 - .../no_std_main_recursion.rs | 33 - .../crate_level_checks/std_main_recursion.rs | 6 - .../std_main_recursion.stderr | 11 - tests/ui/create_dir.fixed | 17 - tests/ui/create_dir.rs | 17 - tests/ui/create_dir.stderr | 16 - tests/ui/dbg_macro.rs | 23 - tests/ui/dbg_macro.stderr | 80 - tests/ui/debug_assert_with_mut_call.rs | 133 - tests/ui/debug_assert_with_mut_call.stderr | 172 - tests/ui/decimal_literal_representation.fixed | 27 - tests/ui/decimal_literal_representation.rs | 27 - .../ui/decimal_literal_representation.stderr | 46 - .../declare_interior_mutable_const/enums.rs | 123 - .../enums.stderr | 89 - .../declare_interior_mutable_const/others.rs | 34 - .../others.stderr | 39 - .../declare_interior_mutable_const/traits.rs | 150 - .../traits.stderr | 75 - tests/ui/def_id_nocore.rs | 29 - tests/ui/def_id_nocore.stderr | 10 - tests/ui/default_trait_access.fixed | 106 - tests/ui/default_trait_access.rs | 106 - tests/ui/default_trait_access.stderr | 56 - tests/ui/deprecated.rs | 13 - tests/ui/deprecated.stderr | 76 - tests/ui/deprecated_old.rs | 5 - tests/ui/deprecated_old.stderr | 28 - tests/ui/deref_addrof.fixed | 63 - tests/ui/deref_addrof.rs | 63 - tests/ui/deref_addrof.stderr | 74 - tests/ui/deref_addrof_double_trigger.rs | 23 - tests/ui/deref_addrof_double_trigger.stderr | 22 - tests/ui/deref_addrof_macro.rs | 10 - tests/ui/dereference.fixed | 93 - tests/ui/dereference.rs | 93 - tests/ui/dereference.stderr | 70 - tests/ui/derive.rs | 74 - tests/ui/derive.stderr | 83 - tests/ui/derive_hash_xor_eq.rs | 54 - tests/ui/derive_hash_xor_eq.stderr | 67 - tests/ui/derive_ord_xor_partial_ord.rs | 69 - tests/ui/derive_ord_xor_partial_ord.stderr | 71 - tests/ui/diverging_sub_expression.rs | 42 - tests/ui/diverging_sub_expression.stderr | 40 - tests/ui/dlist.rs | 40 - tests/ui/dlist.stderr | 51 - tests/ui/doc.rs | 191 - tests/ui/doc.stderr | 190 - tests/ui/doc_errors.rs | 105 - tests/ui/doc_errors.stderr | 58 - tests/ui/doc_unsafe.rs | 100 - tests/ui/doc_unsafe.stderr | 47 - tests/ui/double_comparison.fixed | 30 - tests/ui/double_comparison.rs | 30 - tests/ui/double_comparison.stderr | 52 - tests/ui/double_must_use.rs | 28 - tests/ui/double_must_use.stderr | 27 - tests/ui/double_neg.rs | 7 - tests/ui/double_neg.stderr | 10 - tests/ui/double_parens.rs | 56 - tests/ui/double_parens.stderr | 40 - tests/ui/drop_forget_copy.rs | 66 - tests/ui/drop_forget_copy.stderr | 76 - tests/ui/drop_ref.rs | 74 - tests/ui/drop_ref.stderr | 111 - tests/ui/duplicate_underscore_argument.rs | 10 - tests/ui/duplicate_underscore_argument.stderr | 10 - tests/ui/duration_subsec.fixed | 29 - tests/ui/duration_subsec.rs | 29 - tests/ui/duration_subsec.stderr | 34 - tests/ui/else_if_without_else.rs | 58 - tests/ui/else_if_without_else.stderr | 27 - tests/ui/empty_enum.rs | 6 - tests/ui/empty_enum.stderr | 11 - tests/ui/empty_line_after_outer_attribute.rs | 113 - .../empty_line_after_outer_attribute.stderr | 54 - tests/ui/empty_loop.rs | 51 - tests/ui/empty_loop.stderr | 27 - tests/ui/empty_loop_no_std.rs | 27 - tests/ui/empty_loop_no_std.stderr | 19 - tests/ui/entry_fixable.fixed | 15 - tests/ui/entry_fixable.rs | 17 - tests/ui/entry_fixable.stderr | 12 - tests/ui/entry_unfixable.rs | 73 - tests/ui/entry_unfixable.stderr | 57 - tests/ui/enum_clike_unportable_variant.rs | 50 - tests/ui/enum_clike_unportable_variant.stderr | 58 - tests/ui/enum_glob_use.fixed | 30 - tests/ui/enum_glob_use.rs | 30 - tests/ui/enum_glob_use.stderr | 22 - tests/ui/enum_variants.rs | 136 - tests/ui/enum_variants.stderr | 101 - tests/ui/eprint_with_newline.rs | 49 - tests/ui/eprint_with_newline.stderr | 121 - tests/ui/eq_op.rs | 97 - tests/ui/eq_op.stderr | 174 - tests/ui/eq_op_macros.rs | 56 - tests/ui/eq_op_macros.stderr | 95 - tests/ui/erasing_op.rs | 9 - tests/ui/erasing_op.stderr | 22 - tests/ui/escape_analysis.rs | 184 - tests/ui/escape_analysis.stderr | 16 - tests/ui/eta.fixed | 204 - tests/ui/eta.rs | 204 - tests/ui/eta.stderr | 80 - tests/ui/eval_order_dependence.rs | 109 - tests/ui/eval_order_dependence.stderr | 51 - tests/ui/excessive_precision.fixed | 63 - tests/ui/excessive_precision.rs | 63 - tests/ui/excessive_precision.stderr | 112 - tests/ui/exit1.rs | 15 - tests/ui/exit1.stderr | 10 - tests/ui/exit2.rs | 13 - tests/ui/exit2.stderr | 10 - tests/ui/exit3.rs | 8 - tests/ui/expect.rs | 16 - tests/ui/expect.stderr | 19 - tests/ui/expect_fun_call.fixed | 94 - tests/ui/expect_fun_call.rs | 94 - tests/ui/expect_fun_call.stderr | 76 - tests/ui/explicit_counter_loop.rs | 160 - tests/ui/explicit_counter_loop.stderr | 46 - tests/ui/explicit_write.fixed | 51 - tests/ui/explicit_write.rs | 51 - tests/ui/explicit_write.stderr | 52 - tests/ui/explicit_write_non_rustfix.rs | 8 - tests/ui/explicit_write_non_rustfix.stderr | 10 - tests/ui/extra_unused_lifetimes.rs | 75 - tests/ui/extra_unused_lifetimes.stderr | 28 - tests/ui/fallible_impl_from.rs | 76 - tests/ui/fallible_impl_from.stderr | 93 - tests/ui/field_reassign_with_default.rs | 110 - tests/ui/field_reassign_with_default.stderr | 75 - tests/ui/filetype_is_file.rs | 23 - tests/ui/filetype_is_file.stderr | 27 - tests/ui/filter_map_next.rs | 17 - tests/ui/filter_map_next.stderr | 17 - tests/ui/filter_map_next_fixable.fixed | 10 - tests/ui/filter_map_next_fixable.rs | 10 - tests/ui/filter_map_next_fixable.stderr | 10 - tests/ui/filter_methods.rs | 25 - tests/ui/filter_methods.stderr | 47 - tests/ui/find_map.rs | 33 - tests/ui/find_map.stderr | 26 - tests/ui/float_arithmetic.rs | 52 - tests/ui/float_arithmetic.stderr | 106 - tests/ui/float_cmp.rs | 124 - tests/ui/float_cmp.stderr | 51 - tests/ui/float_cmp_const.rs | 62 - tests/ui/float_cmp_const.stderr | 67 - tests/ui/float_equality_without_abs.rs | 31 - tests/ui/float_equality_without_abs.stderr | 92 - tests/ui/floating_point_abs.fixed | 98 - tests/ui/floating_point_abs.rs | 126 - tests/ui/floating_point_abs.stderr | 80 - tests/ui/floating_point_exp.fixed | 18 - tests/ui/floating_point_exp.rs | 18 - tests/ui/floating_point_exp.stderr | 28 - tests/ui/floating_point_hypot.fixed | 14 - tests/ui/floating_point_hypot.rs | 14 - tests/ui/floating_point_hypot.stderr | 22 - tests/ui/floating_point_log.fixed | 58 - tests/ui/floating_point_log.rs | 58 - tests/ui/floating_point_log.stderr | 174 - tests/ui/floating_point_logbase.fixed | 16 - tests/ui/floating_point_logbase.rs | 16 - tests/ui/floating_point_logbase.stderr | 28 - tests/ui/floating_point_mul_add.fixed | 26 - tests/ui/floating_point_mul_add.rs | 26 - tests/ui/floating_point_mul_add.stderr | 64 - tests/ui/floating_point_powf.fixed | 42 - tests/ui/floating_point_powf.rs | 42 - tests/ui/floating_point_powf.stderr | 150 - tests/ui/floating_point_powi.fixed | 19 - tests/ui/floating_point_powi.rs | 19 - tests/ui/floating_point_powi.stderr | 40 - tests/ui/floating_point_rad.fixed | 13 - tests/ui/floating_point_rad.rs | 13 - tests/ui/floating_point_rad.stderr | 16 - tests/ui/fn_address_comparisons.rs | 20 - tests/ui/fn_address_comparisons.stderr | 16 - tests/ui/fn_params_excessive_bools.rs | 44 - tests/ui/fn_params_excessive_bools.stderr | 53 - tests/ui/fn_to_numeric_cast.rs | 55 - tests/ui/fn_to_numeric_cast.stderr | 144 - tests/ui/fn_to_numeric_cast_32bit.rs | 55 - tests/ui/fn_to_numeric_cast_32bit.stderr | 144 - tests/ui/for_kv_map.rs | 50 - tests/ui/for_kv_map.stderr | 58 - tests/ui/for_loop_fixable.fixed | 283 -- tests/ui/for_loop_fixable.rs | 283 -- tests/ui/for_loop_fixable.stderr | 96 - tests/ui/for_loop_unfixable.rs | 22 - tests/ui/for_loop_unfixable.stderr | 10 - tests/ui/for_loops_over_fallibles.rs | 57 - tests/ui/for_loops_over_fallibles.stderr | 71 - tests/ui/forget_ref.rs | 49 - tests/ui/forget_ref.stderr | 111 - tests/ui/format.fixed | 68 - tests/ui/format.rs | 70 - tests/ui/format.stderr | 91 - tests/ui/formatting.rs | 72 - tests/ui/formatting.stderr | 52 - tests/ui/from_iter_instead_of_collect.rs | 13 - tests/ui/from_iter_instead_of_collect.stderr | 16 - tests/ui/functions.rs | 104 - tests/ui/functions.stderr | 90 - tests/ui/functions_maxlines.rs | 163 - tests/ui/functions_maxlines.stderr | 16 - tests/ui/future_not_send.rs | 80 - tests/ui/future_not_send.stderr | 145 - tests/ui/get_last_with_len.fixed | 31 - tests/ui/get_last_with_len.rs | 31 - tests/ui/get_last_with_len.stderr | 10 - tests/ui/get_unwrap.fixed | 62 - tests/ui/get_unwrap.rs | 62 - tests/ui/get_unwrap.stderr | 86 - tests/ui/identity_op.rs | 41 - tests/ui/identity_op.stderr | 70 - tests/ui/if_let_mutex.rs | 42 - tests/ui/if_let_mutex.stderr | 29 - tests/ui/if_let_some_result.fixed | 35 - tests/ui/if_let_some_result.rs | 35 - tests/ui/if_let_some_result.stderr | 25 - tests/ui/if_not_else.rs | 19 - tests/ui/if_not_else.stderr | 27 - tests/ui/if_same_then_else.rs | 157 - tests/ui/if_same_then_else.stderr | 112 - tests/ui/if_same_then_else2.rs | 140 - tests/ui/if_same_then_else2.stderr | 125 - tests/ui/ifs_same_cond.rs | 46 - tests/ui/ifs_same_cond.stderr | 39 - tests/ui/impl.rs | 36 - tests/ui/impl.stderr | 35 - tests/ui/implicit_hasher.rs | 99 - tests/ui/implicit_hasher.stderr | 153 - tests/ui/implicit_return.fixed | 101 - tests/ui/implicit_return.rs | 101 - tests/ui/implicit_return.stderr | 70 - tests/ui/implicit_saturating_sub.fixed | 160 - tests/ui/implicit_saturating_sub.rs | 206 - tests/ui/implicit_saturating_sub.stderr | 188 - tests/ui/inconsistent_digit_grouping.fixed | 47 - tests/ui/inconsistent_digit_grouping.rs | 47 - tests/ui/inconsistent_digit_grouping.stderr | 70 - tests/ui/indexing_slicing_index.rs | 32 - tests/ui/indexing_slicing_index.stderr | 51 - tests/ui/indexing_slicing_slice.rs | 37 - tests/ui/indexing_slicing_slice.stderr | 125 - tests/ui/inefficient_to_string.fixed | 31 - tests/ui/inefficient_to_string.rs | 31 - tests/ui/inefficient_to_string.stderr | 55 - tests/ui/infallible_destructuring_match.fixed | 112 - tests/ui/infallible_destructuring_match.rs | 118 - .../ui/infallible_destructuring_match.stderr | 28 - tests/ui/infinite_iter.rs | 69 - tests/ui/infinite_iter.stderr | 109 - tests/ui/infinite_loop.rs | 206 - tests/ui/infinite_loop.stderr | 95 - tests/ui/inherent_to_string.rs | 96 - tests/ui/inherent_to_string.stderr | 28 - tests/ui/inline_fn_without_body.fixed | 17 - tests/ui/inline_fn_without_body.rs | 20 - tests/ui/inline_fn_without_body.stderr | 28 - tests/ui/int_plus_one.fixed | 17 - tests/ui/int_plus_one.rs | 17 - tests/ui/int_plus_one.stderr | 28 - tests/ui/integer_arithmetic.rs | 109 - tests/ui/integer_arithmetic.stderr | 169 - tests/ui/integer_division.rs | 9 - tests/ui/integer_division.stderr | 27 - tests/ui/into_iter_on_ref.fixed | 45 - tests/ui/into_iter_on_ref.rs | 45 - tests/ui/into_iter_on_ref.stderr | 166 - tests/ui/invalid_upcast_comparisons.rs | 85 - tests/ui/invalid_upcast_comparisons.stderr | 166 - tests/ui/issue-3145.rs | 3 - tests/ui/issue-3145.stderr | 8 - tests/ui/issue_2356.rs | 24 - tests/ui/issue_2356.stderr | 14 - tests/ui/issue_4266.rs | 37 - tests/ui/issue_4266.stderr | 16 - tests/ui/item_after_statement.rs | 52 - tests/ui/item_after_statement.stderr | 33 - tests/ui/iter_cloned_collect.fixed | 22 - tests/ui/iter_cloned_collect.rs | 25 - tests/ui/iter_cloned_collect.stderr | 26 - tests/ui/iter_next_slice.fixed | 24 - tests/ui/iter_next_slice.rs | 24 - tests/ui/iter_next_slice.stderr | 28 - tests/ui/iter_nth.rs | 56 - tests/ui/iter_nth.stderr | 59 - tests/ui/iter_nth_zero.fixed | 31 - tests/ui/iter_nth_zero.rs | 31 - tests/ui/iter_nth_zero.stderr | 22 - tests/ui/iter_skip_next.fixed | 22 - tests/ui/iter_skip_next.rs | 22 - tests/ui/iter_skip_next.stderr | 28 - tests/ui/iterator_step_by_zero.rs | 28 - tests/ui/iterator_step_by_zero.stderr | 46 - tests/ui/large_const_arrays.fixed | 37 - tests/ui/large_const_arrays.rs | 37 - tests/ui/large_const_arrays.stderr | 76 - tests/ui/large_digit_groups.fixed | 31 - tests/ui/large_digit_groups.rs | 31 - tests/ui/large_digit_groups.stderr | 48 - tests/ui/large_enum_variant.rs | 54 - tests/ui/large_enum_variant.stderr | 68 - tests/ui/large_stack_arrays.rs | 30 - tests/ui/large_stack_arrays.stderr | 35 - tests/ui/large_types_passed_by_value.rs | 66 - tests/ui/large_types_passed_by_value.stderr | 52 - tests/ui/len_without_is_empty.rs | 145 - tests/ui/len_without_is_empty.stderr | 54 - tests/ui/len_zero.fixed | 143 - tests/ui/len_zero.rs | 143 - tests/ui/len_zero.stderr | 88 - tests/ui/len_zero_ranges.fixed | 17 - tests/ui/len_zero_ranges.rs | 17 - tests/ui/len_zero_ranges.stderr | 16 - tests/ui/let_and_return.rs | 159 - tests/ui/let_and_return.stderr | 45 - tests/ui/let_if_seq.rs | 120 - tests/ui/let_if_seq.stderr | 50 - tests/ui/let_underscore_drop.rs | 19 - tests/ui/let_underscore_drop.stderr | 27 - tests/ui/let_underscore_lock.rs | 13 - tests/ui/let_underscore_lock.stderr | 51 - tests/ui/let_underscore_must_use.rs | 95 - tests/ui/let_underscore_must_use.stderr | 99 - tests/ui/let_unit.fixed | 63 - tests/ui/let_unit.rs | 63 - tests/ui/let_unit.stderr | 38 - tests/ui/literals.rs | 41 - tests/ui/literals.stderr | 87 - tests/ui/logic_bug.rs | 26 - tests/ui/logic_bug.stderr | 63 - tests/ui/lossy_float_literal.fixed | 35 - tests/ui/lossy_float_literal.rs | 35 - tests/ui/lossy_float_literal.stderr | 70 - tests/ui/macro_use_imports.fixed | 43 - tests/ui/macro_use_imports.rs | 43 - tests/ui/macro_use_imports.stderr | 28 - tests/ui/manual_async_fn.fixed | 111 - tests/ui/manual_async_fn.rs | 131 - tests/ui/manual_async_fn.stderr | 158 - tests/ui/manual_memcpy/with_loop_counters.rs | 88 - .../manual_memcpy/with_loop_counters.stderr | 111 - .../ui/manual_memcpy/without_loop_counters.rs | 125 - .../without_loop_counters.stderr | 115 - tests/ui/manual_non_exhaustive.rs | 137 - tests/ui/manual_non_exhaustive.stderr | 103 - tests/ui/manual_ok_or.fixed | 40 - tests/ui/manual_ok_or.rs | 44 - tests/ui/manual_ok_or.stderr | 41 - tests/ui/manual_saturating_arithmetic.fixed | 45 - tests/ui/manual_saturating_arithmetic.rs | 55 - tests/ui/manual_saturating_arithmetic.stderr | 163 - tests/ui/manual_strip.rs | 66 - tests/ui/manual_strip.stderr | 132 - tests/ui/manual_unwrap_or.fixed | 139 - tests/ui/manual_unwrap_or.rs | 178 - tests/ui/manual_unwrap_or.stderr | 145 - tests/ui/many_single_char_names.rs | 73 - tests/ui/many_single_char_names.stderr | 51 - tests/ui/map_clone.fixed | 63 - tests/ui/map_clone.rs | 63 - tests/ui/map_clone.stderr | 40 - tests/ui/map_collect_result_unit.fixed | 16 - tests/ui/map_collect_result_unit.rs | 16 - tests/ui/map_collect_result_unit.stderr | 16 - tests/ui/map_err.rs | 30 - tests/ui/map_err.stderr | 11 - tests/ui/map_flatten.fixed | 26 - tests/ui/map_flatten.rs | 26 - tests/ui/map_flatten.stderr | 40 - tests/ui/map_identity.fixed | 23 - tests/ui/map_identity.rs | 25 - tests/ui/map_identity.stderr | 37 - tests/ui/map_unit_fn.rs | 11 - tests/ui/map_unwrap_or.rs | 81 - tests/ui/map_unwrap_or.stderr | 146 - tests/ui/map_unwrap_or_fixable.fixed | 54 - tests/ui/map_unwrap_or_fixable.rs | 58 - tests/ui/map_unwrap_or_fixable.stderr | 22 - tests/ui/match_as_ref.fixed | 35 - tests/ui/match_as_ref.rs | 44 - tests/ui/match_as_ref.stderr | 33 - tests/ui/match_bool.rs | 55 - tests/ui/match_bool.stderr | 117 - tests/ui/match_expr_like_matches_macro.fixed | 102 - tests/ui/match_expr_like_matches_macro.rs | 122 - tests/ui/match_expr_like_matches_macro.stderr | 74 - tests/ui/match_on_vec_items.rs | 152 - tests/ui/match_on_vec_items.stderr | 52 - tests/ui/match_overlapping_arm.rs | 82 - tests/ui/match_overlapping_arm.stderr | 63 - tests/ui/match_ref_pats.rs | 74 - tests/ui/match_ref_pats.stderr | 91 - tests/ui/match_same_arms.rs | 56 - tests/ui/match_same_arms.stderr | 139 - tests/ui/match_same_arms2.rs | 140 - tests/ui/match_same_arms2.stderr | 158 - tests/ui/match_single_binding.fixed | 118 - tests/ui/match_single_binding.rs | 135 - tests/ui/match_single_binding.stderr | 182 - tests/ui/match_wild_err_arm.rs | 65 - tests/ui/match_wild_err_arm.stderr | 35 - .../match_wildcard_for_single_variants.fixed | 59 - .../ui/match_wildcard_for_single_variants.rs | 59 - .../match_wildcard_for_single_variants.stderr | 28 - tests/ui/mem_discriminant.fixed | 45 - tests/ui/mem_discriminant.rs | 45 - tests/ui/mem_discriminant.stderr | 94 - tests/ui/mem_discriminant_unfixable.rs | 16 - tests/ui/mem_discriminant_unfixable.stderr | 20 - tests/ui/mem_forget.rs | 23 - tests/ui/mem_forget.stderr | 22 - tests/ui/mem_replace.fixed | 30 - tests/ui/mem_replace.rs | 30 - tests/ui/mem_replace.stderr | 36 - tests/ui/mem_replace_macro.rs | 21 - tests/ui/mem_replace_macro.stderr | 14 - tests/ui/methods.rs | 138 - tests/ui/methods.stderr | 24 - tests/ui/methods_fixable.fixed | 11 - tests/ui/methods_fixable.rs | 11 - tests/ui/methods_fixable.stderr | 10 - tests/ui/min_max.rs | 65 - tests/ui/min_max.stderr | 82 - tests/ui/min_rust_version_attr.rs | 169 - tests/ui/min_rust_version_attr.stderr | 37 - tests/ui/min_rust_version_invalid_attr.rs | 4 - tests/ui/min_rust_version_invalid_attr.stderr | 8 - .../min_rust_version_multiple_inner_attr.rs | 11 - ...in_rust_version_multiple_inner_attr.stderr | 38 - tests/ui/min_rust_version_no_patch.rs | 14 - tests/ui/min_rust_version_outer_attr.rs | 4 - tests/ui/min_rust_version_outer_attr.stderr | 8 - tests/ui/mismatched_target_os_non_unix.fixed | 27 - tests/ui/mismatched_target_os_non_unix.rs | 27 - tests/ui/mismatched_target_os_non_unix.stderr | 36 - tests/ui/mismatched_target_os_unix.fixed | 62 - tests/ui/mismatched_target_os_unix.rs | 62 - tests/ui/mismatched_target_os_unix.stderr | 183 - tests/ui/missing-doc-crate-missing.rs | 3 - tests/ui/missing-doc-crate-missing.stderr | 12 - tests/ui/missing-doc-crate.rs | 5 - tests/ui/missing-doc-crate.stderr | 0 tests/ui/missing-doc-impl.rs | 87 - tests/ui/missing-doc-impl.stderr | 103 - tests/ui/missing-doc.rs | 102 - tests/ui/missing-doc.stderr | 159 - .../ui/missing_const_for_fn/cant_be_const.rs | 103 - .../missing_const_for_fn/cant_be_const.stderr | 0 .../ui/missing_const_for_fn/could_be_const.rs | 74 - .../could_be_const.stderr | 69 - tests/ui/missing_inline.rs | 66 - tests/ui/missing_inline.stderr | 40 - tests/ui/mistyped_literal_suffix.fixed | 29 - tests/ui/mistyped_literal_suffix.rs | 29 - tests/ui/mistyped_literal_suffix.stderr | 70 - tests/ui/module_inception.rs | 21 - tests/ui/module_inception.stderr | 20 - tests/ui/module_name_repetitions.rs | 26 - tests/ui/module_name_repetitions.stderr | 34 - tests/ui/modulo_arithmetic_float.rs | 36 - tests/ui/modulo_arithmetic_float.stderr | 83 - tests/ui/modulo_arithmetic_integral.rs | 90 - tests/ui/modulo_arithmetic_integral.stderr | 156 - tests/ui/modulo_arithmetic_integral_const.rs | 44 - .../modulo_arithmetic_integral_const.stderr | 156 - tests/ui/modulo_one.rs | 23 - tests/ui/modulo_one.stderr | 74 - tests/ui/must_use_candidates.fixed | 93 - tests/ui/must_use_candidates.rs | 93 - tests/ui/must_use_candidates.stderr | 34 - tests/ui/must_use_unit.fixed | 26 - tests/ui/must_use_unit.rs | 26 - tests/ui/must_use_unit.stderr | 28 - tests/ui/mut_from_ref.rs | 46 - tests/ui/mut_from_ref.stderr | 63 - tests/ui/mut_key.rs | 55 - tests/ui/mut_key.stderr | 28 - tests/ui/mut_mut.rs | 49 - tests/ui/mut_mut.stderr | 63 - tests/ui/mut_mutex_lock.fixed | 21 - tests/ui/mut_mutex_lock.rs | 21 - tests/ui/mut_mutex_lock.stderr | 10 - tests/ui/mut_range_bound.rs | 63 - tests/ui/mut_range_bound.stderr | 34 - tests/ui/mut_reference.rs | 43 - tests/ui/mut_reference.stderr | 22 - tests/ui/mutex_atomic.rs | 15 - tests/ui/mutex_atomic.stderr | 48 - tests/ui/needless_arbitrary_self_type.fixed | 69 - tests/ui/needless_arbitrary_self_type.rs | 69 - tests/ui/needless_arbitrary_self_type.stderr | 40 - .../needless_arbitrary_self_type_unfixable.rs | 45 - ...dless_arbitrary_self_type_unfixable.stderr | 10 - tests/ui/needless_bool/fixable.fixed | 98 - tests/ui/needless_bool/fixable.rs | 130 - tests/ui/needless_bool/fixable.stderr | 111 - tests/ui/needless_bool/simple.rs | 46 - tests/ui/needless_bool/simple.stderr | 44 - tests/ui/needless_borrow.fixed | 61 - tests/ui/needless_borrow.rs | 61 - tests/ui/needless_borrow.stderr | 28 - tests/ui/needless_borrowed_ref.fixed | 45 - tests/ui/needless_borrowed_ref.rs | 45 - tests/ui/needless_borrowed_ref.stderr | 10 - tests/ui/needless_collect.fixed | 21 - tests/ui/needless_collect.rs | 21 - tests/ui/needless_collect.stderr | 28 - tests/ui/needless_collect_indirect.rs | 45 - tests/ui/needless_collect_indirect.stderr | 68 - tests/ui/needless_continue.rs | 115 - tests/ui/needless_continue.stderr | 99 - tests/ui/needless_doc_main.rs | 140 - tests/ui/needless_doc_main.stderr | 28 - tests/ui/needless_lifetimes.rs | 371 -- tests/ui/needless_lifetimes.stderr | 154 - tests/ui/needless_pass_by_value.rs | 161 - tests/ui/needless_pass_by_value.stderr | 178 - tests/ui/needless_pass_by_value_proc_macro.rs | 21 - tests/ui/needless_range_loop.rs | 95 - tests/ui/needless_range_loop.stderr | 157 - tests/ui/needless_range_loop2.rs | 109 - tests/ui/needless_range_loop2.stderr | 91 - tests/ui/needless_return.fixed | 95 - tests/ui/needless_return.rs | 95 - tests/ui/needless_return.stderr | 88 - tests/ui/needless_update.rs | 25 - tests/ui/needless_update.stderr | 10 - tests/ui/neg_cmp_op_on_partial_ord.rs | 62 - tests/ui/neg_cmp_op_on_partial_ord.stderr | 28 - tests/ui/neg_multiply.rs | 35 - tests/ui/neg_multiply.stderr | 16 - tests/ui/never_loop.rs | 204 - tests/ui/never_loop.stderr | 100 - tests/ui/new_ret_no_self.rs | 342 -- tests/ui/new_ret_no_self.stderr | 80 - tests/ui/new_without_default.rs | 162 - tests/ui/new_without_default.stderr | 71 - tests/ui/no_effect.rs | 102 - tests/ui/no_effect.stderr | 154 - tests/ui/non_expressive_names.rs | 56 - tests/ui/non_expressive_names.stderr | 40 - tests/ui/non_expressive_names.stdout | 0 tests/ui/nonminimal_bool.rs | 52 - tests/ui/nonminimal_bool.stderr | 111 - tests/ui/nonminimal_bool_methods.rs | 110 - tests/ui/nonminimal_bool_methods.stderr | 82 - tests/ui/ok_expect.rs | 27 - tests/ui/ok_expect.stderr | 43 - tests/ui/op_ref.rs | 58 - tests/ui/op_ref.stderr | 22 - tests/ui/open_options.rs | 14 - tests/ui/open_options.stderr | 46 - tests/ui/option_as_ref_deref.fixed | 44 - tests/ui/option_as_ref_deref.rs | 47 - tests/ui/option_as_ref_deref.stderr | 110 - tests/ui/option_env_unwrap.rs | 23 - tests/ui/option_env_unwrap.stderr | 61 - tests/ui/option_if_let_else.fixed | 85 - tests/ui/option_if_let_else.rs | 108 - tests/ui/option_if_let_else.stderr | 163 - tests/ui/option_map_or_none.fixed | 16 - tests/ui/option_map_or_none.rs | 16 - tests/ui/option_map_or_none.stderr | 26 - tests/ui/option_map_unit_fn_fixable.fixed | 85 - tests/ui/option_map_unit_fn_fixable.rs | 85 - tests/ui/option_map_unit_fn_fixable.stderr | 148 - tests/ui/option_map_unit_fn_unfixable.rs | 39 - tests/ui/option_map_unit_fn_unfixable.stderr | 27 - tests/ui/option_option.rs | 86 - tests/ui/option_option.stderr | 68 - tests/ui/or_fun_call.fixed | 129 - tests/ui/or_fun_call.rs | 129 - tests/ui/or_fun_call.stderr | 106 - tests/ui/out_of_bounds_indexing/issue-3102.rs | 11 - .../out_of_bounds_indexing/issue-3102.stderr | 16 - tests/ui/out_of_bounds_indexing/simple.rs | 22 - tests/ui/out_of_bounds_indexing/simple.stderr | 40 - tests/ui/overflow_check_conditional.rs | 26 - tests/ui/overflow_check_conditional.stderr | 52 - tests/ui/panic_in_result_fn.rs | 71 - tests/ui/panic_in_result_fn.stderr | 105 - tests/ui/panic_in_result_fn_assertions.rs | 48 - tests/ui/panic_in_result_fn_assertions.stderr | 57 - .../ui/panic_in_result_fn_debug_assertions.rs | 48 - ...panic_in_result_fn_debug_assertions.stderr | 57 - tests/ui/panicking_macros.rs | 52 - tests/ui/panicking_macros.stderr | 112 - tests/ui/partialeq_ne_impl.rs | 26 - tests/ui/partialeq_ne_impl.stderr | 12 - tests/ui/path_buf_push_overwrite.fixed | 8 - tests/ui/path_buf_push_overwrite.rs | 8 - tests/ui/path_buf_push_overwrite.stderr | 10 - tests/ui/pattern_type_mismatch/mutability.rs | 40 - .../pattern_type_mismatch/mutability.stderr | 19 - .../pattern_alternatives.rs | 24 - .../pattern_alternatives.stderr | 27 - .../pattern_type_mismatch/pattern_structs.rs | 45 - .../pattern_structs.stderr | 67 - .../pattern_type_mismatch/pattern_tuples.rs | 57 - .../pattern_tuples.stderr | 83 - tests/ui/pattern_type_mismatch/syntax.rs | 146 - tests/ui/pattern_type_mismatch/syntax.stderr | 79 - tests/ui/patterns.fixed | 36 - tests/ui/patterns.rs | 36 - tests/ui/patterns.stderr | 22 - tests/ui/precedence.fixed | 61 - tests/ui/precedence.rs | 61 - tests/ui/precedence.stderr | 76 - tests/ui/print.rs | 35 - tests/ui/print.stderr | 54 - tests/ui/print_literal.rs | 38 - tests/ui/print_literal.stderr | 88 - tests/ui/print_stderr.rs | 8 - tests/ui/print_stderr.stderr | 16 - tests/ui/print_stdout_build_script.rs | 12 - tests/ui/print_with_newline.rs | 52 - tests/ui/print_with_newline.stderr | 121 - tests/ui/println_empty_string.fixed | 18 - tests/ui/println_empty_string.rs | 18 - tests/ui/println_empty_string.stderr | 28 - tests/ui/proc_macro.rs | 26 - tests/ui/proc_macro.stderr | 10 - tests/ui/ptr_arg.rs | 116 - tests/ui/ptr_arg.stderr | 89 - tests/ui/ptr_eq.fixed | 38 - tests/ui/ptr_eq.rs | 38 - tests/ui/ptr_eq.stderr | 16 - tests/ui/ptr_offset_with_cast.fixed | 20 - tests/ui/ptr_offset_with_cast.rs | 20 - tests/ui/ptr_offset_with_cast.stderr | 16 - tests/ui/question_mark.fixed | 126 - tests/ui/question_mark.rs | 156 - tests/ui/question_mark.stderr | 104 - tests/ui/range.rs | 16 - tests/ui/range.stderr | 10 - tests/ui/range_contains.fixed | 51 - tests/ui/range_contains.rs | 51 - tests/ui/range_contains.stderr | 88 - tests/ui/range_plus_minus_one.fixed | 42 - tests/ui/range_plus_minus_one.rs | 42 - tests/ui/range_plus_minus_one.stderr | 60 - tests/ui/rc_buffer.rs | 26 - tests/ui/rc_buffer.stderr | 52 - tests/ui/rc_buffer_arc.rs | 25 - tests/ui/rc_buffer_arc.stderr | 52 - tests/ui/rc_buffer_redefined_string.rs | 12 - tests/ui/rc_buffer_redefined_string.stderr | 0 tests/ui/redundant_allocation.fixed | 48 - tests/ui/redundant_allocation.rs | 48 - tests/ui/redundant_allocation.stderr | 52 - tests/ui/redundant_clone.fixed | 187 - tests/ui/redundant_clone.rs | 187 - tests/ui/redundant_clone.stderr | 171 - tests/ui/redundant_closure_call_early.rs | 19 - tests/ui/redundant_closure_call_early.stderr | 16 - tests/ui/redundant_closure_call_fixable.fixed | 8 - tests/ui/redundant_closure_call_fixable.rs | 8 - .../ui/redundant_closure_call_fixable.stderr | 10 - tests/ui/redundant_closure_call_late.rs | 39 - tests/ui/redundant_closure_call_late.stderr | 22 - tests/ui/redundant_else.rs | 154 - tests/ui/redundant_else.stderr | 80 - tests/ui/redundant_field_names.fixed | 71 - tests/ui/redundant_field_names.rs | 71 - tests/ui/redundant_field_names.stderr | 46 - .../redundant_pattern_matching_ipaddr.fixed | 73 - tests/ui/redundant_pattern_matching_ipaddr.rs | 91 - .../redundant_pattern_matching_ipaddr.stderr | 130 - .../redundant_pattern_matching_option.fixed | 76 - tests/ui/redundant_pattern_matching_option.rs | 91 - .../redundant_pattern_matching_option.stderr | 134 - .../ui/redundant_pattern_matching_poll.fixed | 70 - tests/ui/redundant_pattern_matching_poll.rs | 85 - .../ui/redundant_pattern_matching_poll.stderr | 128 - .../redundant_pattern_matching_result.fixed | 109 - tests/ui/redundant_pattern_matching_result.rs | 127 - .../redundant_pattern_matching_result.stderr | 154 - tests/ui/redundant_pub_crate.fixed | 107 - tests/ui/redundant_pub_crate.rs | 107 - tests/ui/redundant_pub_crate.stderr | 132 - tests/ui/redundant_static_lifetimes.fixed | 56 - tests/ui/redundant_static_lifetimes.rs | 56 - tests/ui/redundant_static_lifetimes.stderr | 100 - .../ui/redundant_static_lifetimes_multiple.rs | 13 - ...redundant_static_lifetimes_multiple.stderr | 64 - tests/ui/ref_option_ref.rs | 47 - tests/ui/ref_option_ref.stderr | 70 - tests/ui/regex.rs | 82 - tests/ui/regex.stderr | 171 - tests/ui/rename.fixed | 19 - tests/ui/rename.rs | 19 - tests/ui/rename.stderr | 34 - tests/ui/renamed_builtin_attr.fixed | 4 - tests/ui/renamed_builtin_attr.rs | 4 - tests/ui/renamed_builtin_attr.stderr | 8 - tests/ui/repeat_once.fixed | 16 - tests/ui/repeat_once.rs | 16 - tests/ui/repeat_once.stderr | 40 - tests/ui/repl_uninit.rs | 41 - tests/ui/repl_uninit.stderr | 30 - tests/ui/rest_pat_in_fully_bound_structs.rs | 42 - .../ui/rest_pat_in_fully_bound_structs.stderr | 27 - tests/ui/result_map_or_into_option.fixed | 19 - tests/ui/result_map_or_into_option.rs | 19 - tests/ui/result_map_or_into_option.stderr | 10 - tests/ui/result_map_unit_fn_fixable.fixed | 80 - tests/ui/result_map_unit_fn_fixable.rs | 80 - tests/ui/result_map_unit_fn_fixable.stderr | 140 - tests/ui/result_map_unit_fn_unfixable.rs | 46 - tests/ui/result_map_unit_fn_unfixable.stderr | 58 - tests/ui/result_unit_error.rs | 39 - tests/ui/result_unit_error.stderr | 35 - tests/ui/reversed_empty_ranges_fixable.fixed | 29 - tests/ui/reversed_empty_ranges_fixable.rs | 29 - tests/ui/reversed_empty_ranges_fixable.stderr | 47 - .../reversed_empty_ranges_loops_fixable.fixed | 57 - .../ui/reversed_empty_ranges_loops_fixable.rs | 57 - ...reversed_empty_ranges_loops_fixable.stderr | 69 - .../reversed_empty_ranges_loops_unfixable.rs | 11 - ...versed_empty_ranges_loops_unfixable.stderr | 16 - tests/ui/reversed_empty_ranges_unfixable.rs | 15 - .../ui/reversed_empty_ranges_unfixable.stderr | 22 - tests/ui/same_functions_in_if_condition.rs | 90 - .../ui/same_functions_in_if_condition.stderr | 75 - tests/ui/same_item_push.rs | 151 - tests/ui/same_item_push.stderr | 43 - tests/ui/search_is_some.rs | 38 - tests/ui/search_is_some.stderr | 39 - tests/ui/search_is_some_fixable.fixed | 35 - tests/ui/search_is_some_fixable.rs | 35 - tests/ui/search_is_some_fixable.stderr | 94 - tests/ui/self_assignment.rs | 67 - tests/ui/self_assignment.stderr | 70 - tests/ui/serde.rs | 47 - tests/ui/serde.stderr | 15 - tests/ui/shadow.rs | 54 - tests/ui/shadow.stderr | 138 - tests/ui/short_circuit_statement.fixed | 18 - tests/ui/short_circuit_statement.rs | 18 - tests/ui/short_circuit_statement.stderr | 22 - tests/ui/should_impl_trait/corner_cases.rs | 83 - tests/ui/should_impl_trait/method_list_1.rs | 87 - .../ui/should_impl_trait/method_list_1.stderr | 143 - tests/ui/should_impl_trait/method_list_2.rs | 88 - .../ui/should_impl_trait/method_list_2.stderr | 153 - tests/ui/similar_names.rs | 103 - tests/ui/similar_names.stderr | 107 - tests/ui/single_char_add_str.fixed | 45 - tests/ui/single_char_add_str.rs | 45 - tests/ui/single_char_add_str.stderr | 94 - tests/ui/single_char_pattern.fixed | 57 - tests/ui/single_char_pattern.rs | 57 - tests/ui/single_char_pattern.stderr | 184 - tests/ui/single_component_path_imports.fixed | 21 - tests/ui/single_component_path_imports.rs | 21 - tests/ui/single_component_path_imports.stderr | 10 - tests/ui/single_element_loop.fixed | 11 - tests/ui/single_element_loop.rs | 10 - tests/ui/single_element_loop.stderr | 19 - tests/ui/single_match.rs | 95 - tests/ui/single_match.stderr | 69 - tests/ui/single_match_else.rs | 86 - tests/ui/single_match_else.stderr | 63 - tests/ui/size_of_in_element_count.rs | 61 - tests/ui/size_of_in_element_count.stderr | 195 - tests/ui/skip_while_next.rs | 29 - tests/ui/skip_while_next.stderr | 23 - tests/ui/slow_vector_initialization.rs | 63 - tests/ui/slow_vector_initialization.stderr | 60 - tests/ui/stable_sort_primitive.fixed | 32 - tests/ui/stable_sort_primitive.rs | 32 - tests/ui/stable_sort_primitive.stderr | 46 - tests/ui/starts_ends_with.fixed | 46 - tests/ui/starts_ends_with.rs | 46 - tests/ui/starts_ends_with.stderr | 78 - tests/ui/str_to_string.rs | 7 - tests/ui/str_to_string.stderr | 19 - tests/ui/string_add.rs | 26 - tests/ui/string_add.stderr | 30 - tests/ui/string_add_assign.fixed | 21 - tests/ui/string_add_assign.rs | 21 - tests/ui/string_add_assign.stderr | 24 - tests/ui/string_extend.fixed | 32 - tests/ui/string_extend.rs | 32 - tests/ui/string_extend.stderr | 22 - tests/ui/string_from_utf8_as_bytes.fixed | 6 - tests/ui/string_from_utf8_as_bytes.rs | 6 - tests/ui/string_from_utf8_as_bytes.stderr | 10 - tests/ui/string_lit_as_bytes.fixed | 24 - tests/ui/string_lit_as_bytes.rs | 24 - tests/ui/string_lit_as_bytes.stderr | 28 - tests/ui/string_to_string.rs | 7 - tests/ui/string_to_string.stderr | 11 - tests/ui/struct_excessive_bools.rs | 44 - tests/ui/struct_excessive_bools.stderr | 29 - tests/ui/suspicious_arithmetic_impl.rs | 170 - tests/ui/suspicious_arithmetic_impl.stderr | 60 - tests/ui/suspicious_else_formatting.rs | 79 - tests/ui/suspicious_else_formatting.stderr | 77 - tests/ui/suspicious_map.rs | 5 - tests/ui/suspicious_map.stderr | 11 - tests/ui/suspicious_operation_groupings.rs | 207 - .../ui/suspicious_operation_groupings.stderr | 166 - tests/ui/suspicious_unary_op_formatting.rs | 23 - .../ui/suspicious_unary_op_formatting.stderr | 35 - tests/ui/swap.fixed | 83 - tests/ui/swap.rs | 95 - tests/ui/swap.stderr | 69 - tests/ui/tabs_in_doc_comments.fixed | 22 - tests/ui/tabs_in_doc_comments.rs | 22 - tests/ui/tabs_in_doc_comments.stderr | 52 - tests/ui/temporary_assignment.rs | 70 - tests/ui/temporary_assignment.stderr | 32 - tests/ui/to_digit_is_some.fixed | 11 - tests/ui/to_digit_is_some.rs | 11 - tests/ui/to_digit_is_some.stderr | 16 - tests/ui/to_string_in_display.rs | 69 - tests/ui/to_string_in_display.stderr | 10 - tests/ui/toplevel_ref_arg.fixed | 50 - tests/ui/toplevel_ref_arg.rs | 50 - tests/ui/toplevel_ref_arg.stderr | 45 - tests/ui/toplevel_ref_arg_non_rustfix.rs | 33 - tests/ui/toplevel_ref_arg_non_rustfix.stderr | 21 - tests/ui/trailing_zeros.rs | 10 - tests/ui/trailing_zeros.stderr | 16 - tests/ui/trait_duplication_in_bounds.rs | 31 - tests/ui/trait_duplication_in_bounds.stderr | 23 - tests/ui/transmute.rs | 112 - tests/ui/transmute.stderr | 158 - tests/ui/transmute_32bit.rs | 14 - tests/ui/transmute_32bit.stderr | 28 - tests/ui/transmute_64bit.rs | 10 - tests/ui/transmute_64bit.stderr | 16 - tests/ui/transmute_collection.rs | 47 - tests/ui/transmute_collection.stderr | 112 - tests/ui/transmute_float_to_int.rs | 26 - tests/ui/transmute_float_to_int.stderr | 40 - tests/ui/transmute_ptr_to_ptr.rs | 62 - tests/ui/transmute_ptr_to_ptr.stderr | 40 - tests/ui/transmute_ptr_to_ref.rs | 41 - tests/ui/transmute_ptr_to_ref.stderr | 64 - .../transmutes_expressible_as_ptr_casts.fixed | 78 - .../ui/transmutes_expressible_as_ptr_casts.rs | 78 - ...transmutes_expressible_as_ptr_casts.stderr | 56 - tests/ui/transmuting_null.rs | 30 - tests/ui/transmuting_null.stderr | 22 - tests/ui/trivially_copy_pass_by_ref.rs | 132 - tests/ui/trivially_copy_pass_by_ref.stderr | 110 - tests/ui/try_err.fixed | 162 - tests/ui/try_err.rs | 162 - tests/ui/try_err.stderr | 78 - tests/ui/ty_fn_sig.rs | 14 - tests/ui/type_repetition_in_bounds.rs | 72 - tests/ui/type_repetition_in_bounds.stderr | 23 - tests/ui/types.fixed | 15 - tests/ui/types.rs | 15 - tests/ui/types.stderr | 10 - tests/ui/undropped_manually_drops.rs | 26 - tests/ui/undropped_manually_drops.stderr | 19 - tests/ui/unicode.rs | 27 - tests/ui/unicode.stderr | 38 - tests/ui/uninit.rs | 22 - tests/ui/uninit.stderr | 16 - tests/ui/unit_arg.rs | 102 - tests/ui/unit_arg.stderr | 181 - tests/ui/unit_arg_empty_blocks.rs | 26 - tests/ui/unit_arg_empty_blocks.stderr | 45 - tests/ui/unit_cmp.rs | 57 - tests/ui/unit_cmp.stderr | 82 - tests/ui/unit_return_expecting_ord.rs | 36 - tests/ui/unit_return_expecting_ord.stderr | 39 - tests/ui/unknown_attribute.rs | 3 - tests/ui/unknown_attribute.stderr | 8 - tests/ui/unknown_clippy_lints.fixed | 18 - tests/ui/unknown_clippy_lints.rs | 18 - tests/ui/unknown_clippy_lints.stderr | 52 - tests/ui/unnecessary_cast.rs | 26 - tests/ui/unnecessary_cast.stderr | 22 - tests/ui/unnecessary_cast_fixable.fixed | 40 - tests/ui/unnecessary_cast_fixable.rs | 40 - tests/ui/unnecessary_cast_fixable.stderr | 106 - tests/ui/unnecessary_clone.rs | 110 - tests/ui/unnecessary_clone.stderr | 106 - tests/ui/unnecessary_filter_map.rs | 17 - tests/ui/unnecessary_filter_map.stderr | 38 - tests/ui/unnecessary_flat_map.fixed | 14 - tests/ui/unnecessary_flat_map.rs | 14 - tests/ui/unnecessary_flat_map.stderr | 16 - tests/ui/unnecessary_fold.fixed | 52 - tests/ui/unnecessary_fold.rs | 52 - tests/ui/unnecessary_fold.stderr | 40 - tests/ui/unnecessary_lazy_eval.fixed | 122 - tests/ui/unnecessary_lazy_eval.rs | 122 - tests/ui/unnecessary_lazy_eval.stderr | 196 - tests/ui/unnecessary_lazy_eval_unfixable.rs | 22 - .../ui/unnecessary_lazy_eval_unfixable.stderr | 22 - tests/ui/unnecessary_operation.fixed | 79 - tests/ui/unnecessary_operation.rs | 83 - tests/ui/unnecessary_operation.stderr | 128 - tests/ui/unnecessary_ref.fixed | 14 - tests/ui/unnecessary_ref.rs | 14 - tests/ui/unnecessary_ref.stderr | 14 - tests/ui/unnecessary_sort_by.fixed | 100 - tests/ui/unnecessary_sort_by.rs | 100 - tests/ui/unnecessary_sort_by.stderr | 76 - tests/ui/unnecessary_wraps.rs | 123 - tests/ui/unnecessary_wraps.stderr | 106 - tests/ui/unneeded_field_pattern.rs | 22 - tests/ui/unneeded_field_pattern.stderr | 19 - tests/ui/unneeded_wildcard_pattern.fixed | 45 - tests/ui/unneeded_wildcard_pattern.rs | 45 - tests/ui/unneeded_wildcard_pattern.stderr | 92 - tests/ui/unnested_or_patterns.fixed | 33 - tests/ui/unnested_or_patterns.rs | 33 - tests/ui/unnested_or_patterns.stderr | 179 - tests/ui/unnested_or_patterns2.fixed | 18 - tests/ui/unnested_or_patterns2.rs | 18 - tests/ui/unnested_or_patterns2.stderr | 91 - tests/ui/unnested_or_patterns3.rs | 6 - tests/ui/unreadable_literal.fixed | 45 - tests/ui/unreadable_literal.rs | 45 - tests/ui/unreadable_literal.stderr | 72 - tests/ui/unsafe_derive_deserialize.rs | 70 - tests/ui/unsafe_derive_deserialize.stderr | 39 - tests/ui/unsafe_removed_from_name.rs | 27 - tests/ui/unsafe_removed_from_name.stderr | 22 - tests/ui/unseparated_prefix_literals.fixed | 41 - tests/ui/unseparated_prefix_literals.rs | 41 - tests/ui/unseparated_prefix_literals.stderr | 63 - tests/ui/unused_io_amount.rs | 25 - tests/ui/unused_io_amount.stderr | 40 - tests/ui/unused_self.rs | 140 - tests/ui/unused_self.stderr | 75 - tests/ui/unused_unit.fixed | 81 - tests/ui/unused_unit.rs | 81 - tests/ui/unused_unit.stderr | 122 - tests/ui/unwrap.rs | 16 - tests/ui/unwrap.stderr | 19 - tests/ui/unwrap_in_result.rs | 44 - tests/ui/unwrap_in_result.stderr | 41 - tests/ui/unwrap_or.rs | 9 - tests/ui/unwrap_or.stderr | 16 - tests/ui/update-all-references.sh | 3 - tests/ui/use_self.fixed | 254 -- tests/ui/use_self.rs | 254 -- tests/ui/use_self.stderr | 164 - tests/ui/use_self_trait.fixed | 114 - tests/ui/use_self_trait.rs | 114 - tests/ui/use_self_trait.stderr | 94 - tests/ui/used_underscore_binding.rs | 119 - tests/ui/used_underscore_binding.stderr | 40 - tests/ui/useful_asref.rs | 13 - tests/ui/useless_asref.fixed | 135 - tests/ui/useless_asref.rs | 135 - tests/ui/useless_asref.stderr | 74 - tests/ui/useless_attribute.fixed | 69 - tests/ui/useless_attribute.rs | 69 - tests/ui/useless_attribute.stderr | 22 - tests/ui/useless_conversion.fixed | 73 - tests/ui/useless_conversion.rs | 73 - tests/ui/useless_conversion.stderr | 74 - tests/ui/useless_conversion_try.rs | 42 - tests/ui/useless_conversion_try.stderr | 79 - tests/ui/vec.fixed | 62 - tests/ui/vec.rs | 62 - tests/ui/vec.stderr | 40 - tests/ui/vec_box_sized.fixed | 52 - tests/ui/vec_box_sized.rs | 52 - tests/ui/vec_box_sized.stderr | 28 - tests/ui/vec_resize_to_zero.rs | 15 - tests/ui/vec_resize_to_zero.stderr | 13 - tests/ui/verbose_file_reads.rs | 28 - tests/ui/verbose_file_reads.stderr | 19 - tests/ui/vtable_address_comparisons.rs | 42 - tests/ui/vtable_address_comparisons.stderr | 83 - tests/ui/while_let_loop.rs | 119 - tests/ui/while_let_loop.stderr | 63 - tests/ui/while_let_on_iterator.fixed | 218 - tests/ui/while_let_on_iterator.rs | 218 - tests/ui/while_let_on_iterator.stderr | 46 - tests/ui/wild_in_or_pats.rs | 36 - tests/ui/wild_in_or_pats.stderr | 35 - tests/ui/wildcard_enum_match_arm.fixed | 103 - tests/ui/wildcard_enum_match_arm.rs | 103 - tests/ui/wildcard_enum_match_arm.stderr | 38 - tests/ui/wildcard_imports.fixed | 233 - tests/ui/wildcard_imports.rs | 234 - tests/ui/wildcard_imports.stderr | 126 - tests/ui/write_literal.rs | 43 - tests/ui/write_literal.stderr | 88 - tests/ui/write_with_newline.rs | 59 - tests/ui/write_with_newline.stderr | 125 - tests/ui/writeln_empty_string.fixed | 20 - tests/ui/writeln_empty_string.rs | 20 - tests/ui/writeln_empty_string.stderr | 16 - tests/ui/wrong_self_convention.rs | 139 - tests/ui/wrong_self_convention.stderr | 136 - tests/ui/zero_div_zero.rs | 13 - tests/ui/zero_div_zero.stderr | 61 - tests/ui/zero_offset.rs | 12 - tests/ui/zero_offset.stderr | 9 - tests/ui/zero_ptr.fixed | 14 - tests/ui/zero_ptr.rs | 14 - tests/ui/zero_ptr.stderr | 34 - tests/ui/zero_sized_btreemap_values.rs | 68 - tests/ui/zero_sized_btreemap_values.stderr | 107 - tests/ui/zero_sized_hashmap_values.rs | 68 - tests/ui/zero_sized_hashmap_values.stderr | 107 - tests/versioncheck.rs | 19 - triagebot.toml | 7 - util/cov.sh | 37 - util/export.py | 81 - util/fetch_prs_between.sh | 27 - util/gh-pages/index.html | 317 -- util/gh-pages/versions.html | 91 - util/lintlib.py | 114 - util/versions.py | 44 - 1666 files changed, 145886 deletions(-) delete mode 100644 .cargo/config delete mode 100644 .editorconfig delete mode 100644 .gitattributes delete mode 100644 .github/ISSUE_TEMPLATE/blank_issue.md delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md delete mode 100644 .github/ISSUE_TEMPLATE/config.yml delete mode 100644 .github/ISSUE_TEMPLATE/ice.md delete mode 100644 .github/ISSUE_TEMPLATE/new_lint.md delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/deploy.sh delete mode 100644 .github/driver.sh delete mode 100644 .github/workflows/clippy.yml delete mode 100644 .github/workflows/clippy_bors.yml delete mode 100644 .github/workflows/clippy_dev.yml delete mode 100644 .github/workflows/deploy.yml delete mode 100644 .github/workflows/remark.yml delete mode 100644 .gitignore delete mode 100644 .remarkrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 COPYRIGHT delete mode 100644 Cargo.toml delete mode 100644 LICENSE-APACHE delete mode 100644 LICENSE-MIT delete mode 100644 README.md delete mode 100644 build.rs delete mode 100644 clippy_dev/Cargo.toml delete mode 100644 clippy_dev/src/bless.rs delete mode 100644 clippy_dev/src/fmt.rs delete mode 100644 clippy_dev/src/lib.rs delete mode 100644 clippy_dev/src/main.rs delete mode 100644 clippy_dev/src/new_lint.rs delete mode 100644 clippy_dev/src/ra_setup.rs delete mode 100644 clippy_dev/src/serve.rs delete mode 100644 clippy_dev/src/stderr_length_check.rs delete mode 100644 clippy_dev/src/update_lints.rs delete mode 100644 clippy_dummy/Cargo.toml delete mode 100644 clippy_dummy/PUBLISH.md delete mode 100644 clippy_dummy/build.rs delete mode 100644 clippy_dummy/crates-readme.md delete mode 100644 clippy_dummy/src/main.rs delete mode 100644 clippy_lints/Cargo.toml delete mode 100644 clippy_lints/README.md delete mode 100644 clippy_lints/src/approx_const.rs delete mode 100644 clippy_lints/src/arithmetic.rs delete mode 100644 clippy_lints/src/as_conversions.rs delete mode 100644 clippy_lints/src/asm_syntax.rs delete mode 100644 clippy_lints/src/assertions_on_constants.rs delete mode 100644 clippy_lints/src/assign_ops.rs delete mode 100644 clippy_lints/src/async_yields_async.rs delete mode 100644 clippy_lints/src/atomic_ordering.rs delete mode 100644 clippy_lints/src/attrs.rs delete mode 100644 clippy_lints/src/await_holding_invalid.rs delete mode 100644 clippy_lints/src/bit_mask.rs delete mode 100644 clippy_lints/src/blacklisted_name.rs delete mode 100644 clippy_lints/src/blocks_in_if_conditions.rs delete mode 100644 clippy_lints/src/booleans.rs delete mode 100644 clippy_lints/src/bytecount.rs delete mode 100644 clippy_lints/src/cargo_common_metadata.rs delete mode 100644 clippy_lints/src/checked_conversions.rs delete mode 100644 clippy_lints/src/cognitive_complexity.rs delete mode 100644 clippy_lints/src/collapsible_if.rs delete mode 100644 clippy_lints/src/collapsible_match.rs delete mode 100644 clippy_lints/src/comparison_chain.rs delete mode 100644 clippy_lints/src/consts.rs delete mode 100644 clippy_lints/src/copies.rs delete mode 100644 clippy_lints/src/copy_iterator.rs delete mode 100644 clippy_lints/src/create_dir.rs delete mode 100644 clippy_lints/src/dbg_macro.rs delete mode 100644 clippy_lints/src/default.rs delete mode 100644 clippy_lints/src/deprecated_lints.rs delete mode 100644 clippy_lints/src/dereference.rs delete mode 100644 clippy_lints/src/derive.rs delete mode 100644 clippy_lints/src/disallowed_method.rs delete mode 100644 clippy_lints/src/doc.rs delete mode 100644 clippy_lints/src/double_comparison.rs delete mode 100644 clippy_lints/src/double_parens.rs delete mode 100644 clippy_lints/src/drop_forget_ref.rs delete mode 100644 clippy_lints/src/duration_subsec.rs delete mode 100644 clippy_lints/src/else_if_without_else.rs delete mode 100644 clippy_lints/src/empty_enum.rs delete mode 100644 clippy_lints/src/entry.rs delete mode 100644 clippy_lints/src/enum_clike.rs delete mode 100644 clippy_lints/src/enum_variants.rs delete mode 100644 clippy_lints/src/eq_op.rs delete mode 100644 clippy_lints/src/erasing_op.rs delete mode 100644 clippy_lints/src/escape.rs delete mode 100644 clippy_lints/src/eta_reduction.rs delete mode 100644 clippy_lints/src/eval_order_dependence.rs delete mode 100644 clippy_lints/src/excessive_bools.rs delete mode 100644 clippy_lints/src/exit.rs delete mode 100644 clippy_lints/src/explicit_write.rs delete mode 100644 clippy_lints/src/fallible_impl_from.rs delete mode 100644 clippy_lints/src/float_equality_without_abs.rs delete mode 100644 clippy_lints/src/float_literal.rs delete mode 100644 clippy_lints/src/floating_point_arithmetic.rs delete mode 100644 clippy_lints/src/format.rs delete mode 100644 clippy_lints/src/formatting.rs delete mode 100644 clippy_lints/src/functions.rs delete mode 100644 clippy_lints/src/future_not_send.rs delete mode 100644 clippy_lints/src/get_last_with_len.rs delete mode 100644 clippy_lints/src/identity_op.rs delete mode 100644 clippy_lints/src/if_let_mutex.rs delete mode 100644 clippy_lints/src/if_let_some_result.rs delete mode 100644 clippy_lints/src/if_not_else.rs delete mode 100644 clippy_lints/src/implicit_return.rs delete mode 100644 clippy_lints/src/implicit_saturating_sub.rs delete mode 100644 clippy_lints/src/indexing_slicing.rs delete mode 100644 clippy_lints/src/infinite_iter.rs delete mode 100644 clippy_lints/src/inherent_impl.rs delete mode 100644 clippy_lints/src/inherent_to_string.rs delete mode 100644 clippy_lints/src/inline_fn_without_body.rs delete mode 100644 clippy_lints/src/int_plus_one.rs delete mode 100644 clippy_lints/src/integer_division.rs delete mode 100644 clippy_lints/src/items_after_statements.rs delete mode 100644 clippy_lints/src/large_const_arrays.rs delete mode 100644 clippy_lints/src/large_enum_variant.rs delete mode 100644 clippy_lints/src/large_stack_arrays.rs delete mode 100644 clippy_lints/src/len_zero.rs delete mode 100644 clippy_lints/src/let_if_seq.rs delete mode 100644 clippy_lints/src/let_underscore.rs delete mode 100644 clippy_lints/src/lib.rs delete mode 100644 clippy_lints/src/lifetimes.rs delete mode 100644 clippy_lints/src/literal_representation.rs delete mode 100644 clippy_lints/src/loops.rs delete mode 100644 clippy_lints/src/macro_use.rs delete mode 100644 clippy_lints/src/main_recursion.rs delete mode 100644 clippy_lints/src/manual_async_fn.rs delete mode 100644 clippy_lints/src/manual_non_exhaustive.rs delete mode 100644 clippy_lints/src/manual_ok_or.rs delete mode 100644 clippy_lints/src/manual_strip.rs delete mode 100644 clippy_lints/src/manual_unwrap_or.rs delete mode 100644 clippy_lints/src/map_clone.rs delete mode 100644 clippy_lints/src/map_err_ignore.rs delete mode 100644 clippy_lints/src/map_identity.rs delete mode 100644 clippy_lints/src/map_unit_fn.rs delete mode 100644 clippy_lints/src/match_on_vec_items.rs delete mode 100644 clippy_lints/src/matches.rs delete mode 100644 clippy_lints/src/mem_discriminant.rs delete mode 100644 clippy_lints/src/mem_forget.rs delete mode 100644 clippy_lints/src/mem_replace.rs delete mode 100644 clippy_lints/src/methods/bind_instead_of_map.rs delete mode 100644 clippy_lints/src/methods/inefficient_to_string.rs delete mode 100644 clippy_lints/src/methods/manual_saturating_arithmetic.rs delete mode 100644 clippy_lints/src/methods/mod.rs delete mode 100644 clippy_lints/src/methods/option_map_unwrap_or.rs delete mode 100644 clippy_lints/src/methods/unnecessary_filter_map.rs delete mode 100644 clippy_lints/src/methods/unnecessary_lazy_eval.rs delete mode 100644 clippy_lints/src/minmax.rs delete mode 100644 clippy_lints/src/misc.rs delete mode 100644 clippy_lints/src/misc_early.rs delete mode 100644 clippy_lints/src/missing_const_for_fn.rs delete mode 100644 clippy_lints/src/missing_doc.rs delete mode 100644 clippy_lints/src/missing_inline.rs delete mode 100644 clippy_lints/src/modulo_arithmetic.rs delete mode 100644 clippy_lints/src/multiple_crate_versions.rs delete mode 100644 clippy_lints/src/mut_key.rs delete mode 100644 clippy_lints/src/mut_mut.rs delete mode 100644 clippy_lints/src/mut_mutex_lock.rs delete mode 100644 clippy_lints/src/mut_reference.rs delete mode 100644 clippy_lints/src/mutable_debug_assertion.rs delete mode 100644 clippy_lints/src/mutex_atomic.rs delete mode 100644 clippy_lints/src/needless_arbitrary_self_type.rs delete mode 100644 clippy_lints/src/needless_bool.rs delete mode 100644 clippy_lints/src/needless_borrow.rs delete mode 100644 clippy_lints/src/needless_borrowed_ref.rs delete mode 100644 clippy_lints/src/needless_continue.rs delete mode 100644 clippy_lints/src/needless_pass_by_value.rs delete mode 100644 clippy_lints/src/needless_update.rs delete mode 100644 clippy_lints/src/neg_cmp_op_on_partial_ord.rs delete mode 100644 clippy_lints/src/neg_multiply.rs delete mode 100644 clippy_lints/src/new_without_default.rs delete mode 100644 clippy_lints/src/no_effect.rs delete mode 100644 clippy_lints/src/non_copy_const.rs delete mode 100644 clippy_lints/src/non_expressive_names.rs delete mode 100644 clippy_lints/src/open_options.rs delete mode 100644 clippy_lints/src/option_env_unwrap.rs delete mode 100644 clippy_lints/src/option_if_let_else.rs delete mode 100644 clippy_lints/src/overflow_check_conditional.rs delete mode 100644 clippy_lints/src/panic_in_result_fn.rs delete mode 100644 clippy_lints/src/panic_unimplemented.rs delete mode 100644 clippy_lints/src/partialeq_ne_impl.rs delete mode 100644 clippy_lints/src/pass_by_ref_or_value.rs delete mode 100644 clippy_lints/src/path_buf_push_overwrite.rs delete mode 100644 clippy_lints/src/pattern_type_mismatch.rs delete mode 100644 clippy_lints/src/precedence.rs delete mode 100644 clippy_lints/src/ptr.rs delete mode 100644 clippy_lints/src/ptr_eq.rs delete mode 100644 clippy_lints/src/ptr_offset_with_cast.rs delete mode 100644 clippy_lints/src/question_mark.rs delete mode 100644 clippy_lints/src/ranges.rs delete mode 100644 clippy_lints/src/redundant_clone.rs delete mode 100644 clippy_lints/src/redundant_closure_call.rs delete mode 100644 clippy_lints/src/redundant_else.rs delete mode 100644 clippy_lints/src/redundant_field_names.rs delete mode 100644 clippy_lints/src/redundant_pub_crate.rs delete mode 100644 clippy_lints/src/redundant_static_lifetimes.rs delete mode 100644 clippy_lints/src/ref_option_ref.rs delete mode 100644 clippy_lints/src/reference.rs delete mode 100644 clippy_lints/src/regex.rs delete mode 100644 clippy_lints/src/repeat_once.rs delete mode 100644 clippy_lints/src/returns.rs delete mode 100644 clippy_lints/src/self_assignment.rs delete mode 100644 clippy_lints/src/serde_api.rs delete mode 100644 clippy_lints/src/shadow.rs delete mode 100644 clippy_lints/src/single_component_path_imports.rs delete mode 100644 clippy_lints/src/size_of_in_element_count.rs delete mode 100644 clippy_lints/src/slow_vector_initialization.rs delete mode 100644 clippy_lints/src/stable_sort_primitive.rs delete mode 100644 clippy_lints/src/strings.rs delete mode 100644 clippy_lints/src/suspicious_operation_groupings.rs delete mode 100644 clippy_lints/src/suspicious_trait_impl.rs delete mode 100644 clippy_lints/src/swap.rs delete mode 100644 clippy_lints/src/tabs_in_doc_comments.rs delete mode 100644 clippy_lints/src/temporary_assignment.rs delete mode 100644 clippy_lints/src/to_digit_is_some.rs delete mode 100644 clippy_lints/src/to_string_in_display.rs delete mode 100644 clippy_lints/src/trait_bounds.rs delete mode 100644 clippy_lints/src/transmute.rs delete mode 100644 clippy_lints/src/transmuting_null.rs delete mode 100644 clippy_lints/src/try_err.rs delete mode 100644 clippy_lints/src/types.rs delete mode 100644 clippy_lints/src/undropped_manually_drops.rs delete mode 100644 clippy_lints/src/unicode.rs delete mode 100644 clippy_lints/src/unit_return_expecting_ord.rs delete mode 100644 clippy_lints/src/unnamed_address.rs delete mode 100644 clippy_lints/src/unnecessary_sort_by.rs delete mode 100644 clippy_lints/src/unnecessary_wraps.rs delete mode 100644 clippy_lints/src/unnested_or_patterns.rs delete mode 100644 clippy_lints/src/unsafe_removed_from_name.rs delete mode 100644 clippy_lints/src/unused_io_amount.rs delete mode 100644 clippy_lints/src/unused_self.rs delete mode 100644 clippy_lints/src/unused_unit.rs delete mode 100644 clippy_lints/src/unwrap.rs delete mode 100644 clippy_lints/src/unwrap_in_result.rs delete mode 100644 clippy_lints/src/use_self.rs delete mode 100644 clippy_lints/src/useless_conversion.rs delete mode 100644 clippy_lints/src/utils/ast_utils.rs delete mode 100644 clippy_lints/src/utils/ast_utils/ident_iter.rs delete mode 100644 clippy_lints/src/utils/attrs.rs delete mode 100644 clippy_lints/src/utils/author.rs delete mode 100644 clippy_lints/src/utils/camel_case.rs delete mode 100644 clippy_lints/src/utils/comparisons.rs delete mode 100644 clippy_lints/src/utils/conf.rs delete mode 100644 clippy_lints/src/utils/constants.rs delete mode 100644 clippy_lints/src/utils/diagnostics.rs delete mode 100644 clippy_lints/src/utils/eager_or_lazy.rs delete mode 100644 clippy_lints/src/utils/higher.rs delete mode 100644 clippy_lints/src/utils/hir_utils.rs delete mode 100644 clippy_lints/src/utils/inspector.rs delete mode 100644 clippy_lints/src/utils/internal_lints.rs delete mode 100644 clippy_lints/src/utils/mod.rs delete mode 100644 clippy_lints/src/utils/numeric_literal.rs delete mode 100644 clippy_lints/src/utils/paths.rs delete mode 100644 clippy_lints/src/utils/ptr.rs delete mode 100644 clippy_lints/src/utils/qualify_min_const_fn.rs delete mode 100644 clippy_lints/src/utils/sugg.rs delete mode 100644 clippy_lints/src/utils/sym.rs delete mode 100644 clippy_lints/src/utils/usage.rs delete mode 100644 clippy_lints/src/utils/visitors.rs delete mode 100644 clippy_lints/src/vec.rs delete mode 100644 clippy_lints/src/vec_resize_to_zero.rs delete mode 100644 clippy_lints/src/verbose_file_reads.rs delete mode 100644 clippy_lints/src/wildcard_dependencies.rs delete mode 100644 clippy_lints/src/wildcard_imports.rs delete mode 100644 clippy_lints/src/write.rs delete mode 100644 clippy_lints/src/zero_div_zero.rs delete mode 100644 clippy_lints/src/zero_sized_map_values.rs delete mode 100644 clippy_workspace_tests/Cargo.toml delete mode 100644 clippy_workspace_tests/build.rs delete mode 100644 clippy_workspace_tests/path_dep/Cargo.toml delete mode 100644 clippy_workspace_tests/path_dep/src/lib.rs delete mode 100644 clippy_workspace_tests/src/main.rs delete mode 100644 clippy_workspace_tests/subcrate/Cargo.toml delete mode 100644 clippy_workspace_tests/subcrate/src/lib.rs delete mode 100644 doc/adding_lints.md delete mode 100644 doc/backport.md delete mode 100644 doc/basics.md delete mode 100644 doc/changelog_update.md delete mode 100644 doc/common_tools_writing_lints.md delete mode 100644 doc/release.md delete mode 100644 etc/relicense/RELICENSE_DOCUMENTATION.md delete mode 100644 etc/relicense/contributors.txt delete mode 100644 etc/relicense/relicense_comments.txt delete mode 100644 mini-macro/Cargo.toml delete mode 100644 mini-macro/src/lib.rs delete mode 100644 rust-toolchain delete mode 100644 rustc_tools_util/Cargo.toml delete mode 120000 rustc_tools_util/LICENSE-APACHE delete mode 120000 rustc_tools_util/LICENSE-MIT delete mode 100644 rustc_tools_util/README.md delete mode 100644 rustc_tools_util/src/lib.rs delete mode 100644 rustfmt.toml delete mode 100644 src/driver.rs delete mode 100644 src/main.rs delete mode 100644 tests/auxiliary/test_macro.rs delete mode 100644 tests/cargo/mod.rs delete mode 100644 tests/compile-test.rs delete mode 100644 tests/dogfood.rs delete mode 100644 tests/fmt.rs delete mode 100644 tests/integration.rs delete mode 100644 tests/missing-test-files.rs delete mode 100644 tests/ui-cargo/cargo_common_metadata/fail/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_common_metadata/fail/src/main.rs delete mode 100644 tests/ui-cargo/cargo_common_metadata/fail/src/main.stderr delete mode 100644 tests/ui-cargo/cargo_common_metadata/pass/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_common_metadata/pass/src/main.rs delete mode 100644 tests/ui-cargo/multiple_crate_versions/5041_allow_dev_build/Cargo.toml delete mode 100644 tests/ui-cargo/multiple_crate_versions/5041_allow_dev_build/src/main.rs delete mode 100644 tests/ui-cargo/multiple_crate_versions/fail/Cargo.lock delete mode 100644 tests/ui-cargo/multiple_crate_versions/fail/Cargo.toml delete mode 100644 tests/ui-cargo/multiple_crate_versions/fail/src/main.rs delete mode 100644 tests/ui-cargo/multiple_crate_versions/fail/src/main.stderr delete mode 100644 tests/ui-cargo/multiple_crate_versions/pass/Cargo.toml delete mode 100644 tests/ui-cargo/multiple_crate_versions/pass/src/main.rs delete mode 100755 tests/ui-cargo/update-all-references.sh delete mode 100644 tests/ui-cargo/wildcard_dependencies/fail/Cargo.toml delete mode 100644 tests/ui-cargo/wildcard_dependencies/fail/src/main.rs delete mode 100644 tests/ui-cargo/wildcard_dependencies/fail/src/main.stderr delete mode 100644 tests/ui-cargo/wildcard_dependencies/pass/Cargo.toml delete mode 100644 tests/ui-cargo/wildcard_dependencies/pass/src/main.rs delete mode 100644 tests/ui-internal/collapsible_span_lint_calls.fixed delete mode 100644 tests/ui-internal/collapsible_span_lint_calls.rs delete mode 100644 tests/ui-internal/collapsible_span_lint_calls.stderr delete mode 100644 tests/ui-internal/custom_ice_message.rs delete mode 100644 tests/ui-internal/custom_ice_message.stderr delete mode 100644 tests/ui-internal/default_lint.rs delete mode 100644 tests/ui-internal/default_lint.stderr delete mode 100644 tests/ui-internal/interning_defined_symbol.fixed delete mode 100644 tests/ui-internal/interning_defined_symbol.rs delete mode 100644 tests/ui-internal/interning_defined_symbol.stderr delete mode 100644 tests/ui-internal/invalid_paths.rs delete mode 100644 tests/ui-internal/invalid_paths.stderr delete mode 100644 tests/ui-internal/lint_without_lint_pass.rs delete mode 100644 tests/ui-internal/lint_without_lint_pass.stderr delete mode 100644 tests/ui-internal/match_type_on_diag_item.rs delete mode 100644 tests/ui-internal/match_type_on_diag_item.stderr delete mode 100644 tests/ui-internal/outer_expn_data.fixed delete mode 100644 tests/ui-internal/outer_expn_data.rs delete mode 100644 tests/ui-internal/outer_expn_data.stderr delete mode 100644 tests/ui-toml/bad_toml/clippy.toml delete mode 100644 tests/ui-toml/bad_toml/conf_bad_toml.rs delete mode 100644 tests/ui-toml/bad_toml/conf_bad_toml.stderr delete mode 100644 tests/ui-toml/bad_toml_type/clippy.toml delete mode 100644 tests/ui-toml/bad_toml_type/conf_bad_type.rs delete mode 100644 tests/ui-toml/bad_toml_type/conf_bad_type.stderr delete mode 100644 tests/ui-toml/conf_deprecated_key/clippy.toml delete mode 100644 tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs delete mode 100644 tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr delete mode 100644 tests/ui-toml/fn_params_excessive_bools/clippy.toml delete mode 100644 tests/ui-toml/fn_params_excessive_bools/test.rs delete mode 100644 tests/ui-toml/fn_params_excessive_bools/test.stderr delete mode 100644 tests/ui-toml/functions_maxlines/clippy.toml delete mode 100644 tests/ui-toml/functions_maxlines/test.rs delete mode 100644 tests/ui-toml/functions_maxlines/test.stderr delete mode 100644 tests/ui-toml/good_toml_no_false_negatives/clippy.toml delete mode 100644 tests/ui-toml/good_toml_no_false_negatives/conf_no_false_negatives.rs delete mode 100644 tests/ui-toml/invalid_min_rust_version/clippy.toml delete mode 100644 tests/ui-toml/invalid_min_rust_version/invalid_min_rust_version.rs delete mode 100644 tests/ui-toml/invalid_min_rust_version/invalid_min_rust_version.stderr delete mode 100644 tests/ui-toml/lint_decimal_readability/clippy.toml delete mode 100644 tests/ui-toml/lint_decimal_readability/test.rs delete mode 100644 tests/ui-toml/lint_decimal_readability/test.stderr delete mode 100644 tests/ui-toml/min_rust_version/clippy.toml delete mode 100644 tests/ui-toml/min_rust_version/min_rust_version.rs delete mode 100644 tests/ui-toml/struct_excessive_bools/clippy.toml delete mode 100644 tests/ui-toml/struct_excessive_bools/test.rs delete mode 100644 tests/ui-toml/struct_excessive_bools/test.stderr delete mode 100644 tests/ui-toml/toml_blacklist/clippy.toml delete mode 100644 tests/ui-toml/toml_blacklist/conf_french_blacklisted_name.rs delete mode 100644 tests/ui-toml/toml_blacklist/conf_french_blacklisted_name.stderr delete mode 100644 tests/ui-toml/toml_disallowed_method/clippy.toml delete mode 100644 tests/ui-toml/toml_disallowed_method/conf_disallowed_method.rs delete mode 100644 tests/ui-toml/toml_disallowed_method/conf_disallowed_method.stderr delete mode 100644 tests/ui-toml/toml_trivially_copy/clippy.toml delete mode 100644 tests/ui-toml/toml_trivially_copy/test.rs delete mode 100644 tests/ui-toml/toml_trivially_copy/test.stderr delete mode 100644 tests/ui-toml/toml_unknown_key/clippy.toml delete mode 100644 tests/ui-toml/toml_unknown_key/conf_unknown_key.rs delete mode 100644 tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr delete mode 100755 tests/ui-toml/update-all-references.sh delete mode 100644 tests/ui-toml/vec_box_sized/clippy.toml delete mode 100644 tests/ui-toml/vec_box_sized/test.rs delete mode 100644 tests/ui-toml/vec_box_sized/test.stderr delete mode 100644 tests/ui-toml/zero_single_char_names/clippy.toml delete mode 100644 tests/ui-toml/zero_single_char_names/zero_single_char_names.rs delete mode 100644 tests/ui/absurd-extreme-comparisons.rs delete mode 100644 tests/ui/absurd-extreme-comparisons.stderr delete mode 100644 tests/ui/approx_const.rs delete mode 100644 tests/ui/approx_const.stderr delete mode 100644 tests/ui/as_conversions.rs delete mode 100644 tests/ui/as_conversions.stderr delete mode 100644 tests/ui/asm_syntax.rs delete mode 100644 tests/ui/asm_syntax.stderr delete mode 100644 tests/ui/assertions_on_constants.rs delete mode 100644 tests/ui/assertions_on_constants.stderr delete mode 100644 tests/ui/assign_ops.fixed delete mode 100644 tests/ui/assign_ops.rs delete mode 100644 tests/ui/assign_ops.stderr delete mode 100644 tests/ui/assign_ops2.rs delete mode 100644 tests/ui/assign_ops2.stderr delete mode 100644 tests/ui/async_yields_async.fixed delete mode 100644 tests/ui/async_yields_async.rs delete mode 100644 tests/ui/async_yields_async.stderr delete mode 100644 tests/ui/atomic_ordering_bool.rs delete mode 100644 tests/ui/atomic_ordering_bool.stderr delete mode 100644 tests/ui/atomic_ordering_exchange.rs delete mode 100644 tests/ui/atomic_ordering_exchange.stderr delete mode 100644 tests/ui/atomic_ordering_exchange_weak.rs delete mode 100644 tests/ui/atomic_ordering_exchange_weak.stderr delete mode 100644 tests/ui/atomic_ordering_fence.rs delete mode 100644 tests/ui/atomic_ordering_fence.stderr delete mode 100644 tests/ui/atomic_ordering_fetch_update.rs delete mode 100644 tests/ui/atomic_ordering_fetch_update.stderr delete mode 100644 tests/ui/atomic_ordering_int.rs delete mode 100644 tests/ui/atomic_ordering_int.stderr delete mode 100644 tests/ui/atomic_ordering_ptr.rs delete mode 100644 tests/ui/atomic_ordering_ptr.stderr delete mode 100644 tests/ui/atomic_ordering_uint.rs delete mode 100644 tests/ui/atomic_ordering_uint.stderr delete mode 100644 tests/ui/attrs.rs delete mode 100644 tests/ui/attrs.stderr delete mode 100644 tests/ui/author.rs delete mode 100644 tests/ui/author.stdout delete mode 100644 tests/ui/author/blocks.rs delete mode 100644 tests/ui/author/blocks.stdout delete mode 100644 tests/ui/author/call.rs delete mode 100644 tests/ui/author/call.stdout delete mode 100644 tests/ui/author/for_loop.rs delete mode 100644 tests/ui/author/for_loop.stdout delete mode 100644 tests/ui/author/if.rs delete mode 100644 tests/ui/author/if.stdout delete mode 100644 tests/ui/author/issue_3849.rs delete mode 100644 tests/ui/author/issue_3849.stdout delete mode 100644 tests/ui/author/matches.rs delete mode 100644 tests/ui/author/matches.stdout delete mode 100644 tests/ui/auxiliary/doc_unsafe_macros.rs delete mode 100644 tests/ui/auxiliary/implicit_hasher_macros.rs delete mode 100644 tests/ui/auxiliary/macro_rules.rs delete mode 100644 tests/ui/auxiliary/macro_use_helper.rs delete mode 100644 tests/ui/auxiliary/option_helpers.rs delete mode 100644 tests/ui/auxiliary/proc_macro_attr.rs delete mode 100644 tests/ui/auxiliary/proc_macro_derive.rs delete mode 100644 tests/ui/auxiliary/use_self_macro.rs delete mode 100644 tests/ui/auxiliary/wildcard_imports_helper.rs delete mode 100644 tests/ui/await_holding_lock.rs delete mode 100644 tests/ui/await_holding_lock.stderr delete mode 100644 tests/ui/await_holding_refcell_ref.rs delete mode 100644 tests/ui/await_holding_refcell_ref.stderr delete mode 100644 tests/ui/bind_instead_of_map.fixed delete mode 100644 tests/ui/bind_instead_of_map.rs delete mode 100644 tests/ui/bind_instead_of_map.stderr delete mode 100644 tests/ui/bind_instead_of_map_multipart.rs delete mode 100644 tests/ui/bind_instead_of_map_multipart.stderr delete mode 100644 tests/ui/bit_masks.rs delete mode 100644 tests/ui/bit_masks.stderr delete mode 100644 tests/ui/blacklisted_name.rs delete mode 100644 tests/ui/blacklisted_name.stderr delete mode 100644 tests/ui/blanket_clippy_restriction_lints.rs delete mode 100644 tests/ui/blanket_clippy_restriction_lints.stderr delete mode 100644 tests/ui/blocks_in_if_conditions.fixed delete mode 100644 tests/ui/blocks_in_if_conditions.rs delete mode 100644 tests/ui/blocks_in_if_conditions.stderr delete mode 100644 tests/ui/blocks_in_if_conditions_closure.rs delete mode 100644 tests/ui/blocks_in_if_conditions_closure.stderr delete mode 100644 tests/ui/bool_comparison.fixed delete mode 100644 tests/ui/bool_comparison.rs delete mode 100644 tests/ui/bool_comparison.stderr delete mode 100644 tests/ui/borrow_box.rs delete mode 100644 tests/ui/borrow_box.stderr delete mode 100644 tests/ui/borrow_interior_mutable_const/auxiliary/helper.rs delete mode 100644 tests/ui/borrow_interior_mutable_const/enums.rs delete mode 100644 tests/ui/borrow_interior_mutable_const/enums.stderr delete mode 100644 tests/ui/borrow_interior_mutable_const/others.rs delete mode 100644 tests/ui/borrow_interior_mutable_const/others.stderr delete mode 100644 tests/ui/borrow_interior_mutable_const/traits.rs delete mode 100644 tests/ui/borrow_interior_mutable_const/traits.stderr delete mode 100644 tests/ui/box_vec.rs delete mode 100644 tests/ui/box_vec.stderr delete mode 100644 tests/ui/builtin-type-shadow.rs delete mode 100644 tests/ui/builtin-type-shadow.stderr delete mode 100644 tests/ui/bytecount.rs delete mode 100644 tests/ui/bytecount.stderr delete mode 100644 tests/ui/cast.rs delete mode 100644 tests/ui/cast.stderr delete mode 100644 tests/ui/cast_alignment.rs delete mode 100644 tests/ui/cast_alignment.stderr delete mode 100644 tests/ui/cast_lossless_float.fixed delete mode 100644 tests/ui/cast_lossless_float.rs delete mode 100644 tests/ui/cast_lossless_float.stderr delete mode 100644 tests/ui/cast_lossless_integer.fixed delete mode 100644 tests/ui/cast_lossless_integer.rs delete mode 100644 tests/ui/cast_lossless_integer.stderr delete mode 100644 tests/ui/cast_ref_to_mut.rs delete mode 100644 tests/ui/cast_ref_to_mut.stderr delete mode 100644 tests/ui/cast_size.rs delete mode 100644 tests/ui/cast_size.stderr delete mode 100644 tests/ui/cast_size_32bit.rs delete mode 100644 tests/ui/cast_size_32bit.stderr delete mode 100644 tests/ui/cfg_attr_rustfmt.fixed delete mode 100644 tests/ui/cfg_attr_rustfmt.rs delete mode 100644 tests/ui/cfg_attr_rustfmt.stderr delete mode 100644 tests/ui/char_lit_as_u8.rs delete mode 100644 tests/ui/char_lit_as_u8.stderr delete mode 100644 tests/ui/char_lit_as_u8_suggestions.fixed delete mode 100644 tests/ui/char_lit_as_u8_suggestions.rs delete mode 100644 tests/ui/char_lit_as_u8_suggestions.stderr delete mode 100644 tests/ui/checked_conversions.fixed delete mode 100644 tests/ui/checked_conversions.rs delete mode 100644 tests/ui/checked_conversions.stderr delete mode 100644 tests/ui/checked_unwrap/complex_conditionals.rs delete mode 100644 tests/ui/checked_unwrap/complex_conditionals.stderr delete mode 100644 tests/ui/checked_unwrap/complex_conditionals_nested.rs delete mode 100644 tests/ui/checked_unwrap/complex_conditionals_nested.stderr delete mode 100644 tests/ui/checked_unwrap/simple_conditionals.rs delete mode 100644 tests/ui/checked_unwrap/simple_conditionals.stderr delete mode 100644 tests/ui/clone_on_copy.fixed delete mode 100644 tests/ui/clone_on_copy.rs delete mode 100644 tests/ui/clone_on_copy.stderr delete mode 100644 tests/ui/clone_on_copy_impl.rs delete mode 100644 tests/ui/clone_on_copy_mut.rs delete mode 100644 tests/ui/cmp_nan.rs delete mode 100644 tests/ui/cmp_nan.stderr delete mode 100644 tests/ui/cmp_null.rs delete mode 100644 tests/ui/cmp_null.stderr delete mode 100644 tests/ui/cmp_owned/asymmetric_partial_eq.fixed delete mode 100644 tests/ui/cmp_owned/asymmetric_partial_eq.rs delete mode 100644 tests/ui/cmp_owned/asymmetric_partial_eq.stderr delete mode 100644 tests/ui/cmp_owned/with_suggestion.fixed delete mode 100644 tests/ui/cmp_owned/with_suggestion.rs delete mode 100644 tests/ui/cmp_owned/with_suggestion.stderr delete mode 100644 tests/ui/cmp_owned/without_suggestion.rs delete mode 100644 tests/ui/cmp_owned/without_suggestion.stderr delete mode 100644 tests/ui/cognitive_complexity.rs delete mode 100644 tests/ui/cognitive_complexity.stderr delete mode 100644 tests/ui/cognitive_complexity_attr_used.rs delete mode 100644 tests/ui/cognitive_complexity_attr_used.stderr delete mode 100644 tests/ui/collapsible_else_if.fixed delete mode 100644 tests/ui/collapsible_else_if.rs delete mode 100644 tests/ui/collapsible_else_if.stderr delete mode 100644 tests/ui/collapsible_if.fixed delete mode 100644 tests/ui/collapsible_if.rs delete mode 100644 tests/ui/collapsible_if.stderr delete mode 100644 tests/ui/collapsible_match.rs delete mode 100644 tests/ui/collapsible_match.stderr delete mode 100644 tests/ui/collapsible_match2.rs delete mode 100644 tests/ui/collapsible_match2.stderr delete mode 100644 tests/ui/comparison_chain.rs delete mode 100644 tests/ui/comparison_chain.stderr delete mode 100644 tests/ui/comparison_to_empty.fixed delete mode 100644 tests/ui/comparison_to_empty.rs delete mode 100644 tests/ui/comparison_to_empty.stderr delete mode 100644 tests/ui/complex_types.rs delete mode 100644 tests/ui/complex_types.stderr delete mode 100644 tests/ui/copy_iterator.rs delete mode 100644 tests/ui/copy_iterator.stderr delete mode 100644 tests/ui/crashes/associated-constant-ice.rs delete mode 100644 tests/ui/crashes/auxiliary/ice-4727-aux.rs delete mode 100644 tests/ui/crashes/auxiliary/proc_macro_crash.rs delete mode 100644 tests/ui/crashes/auxiliary/use_self_macro.rs delete mode 100644 tests/ui/crashes/cc_seme.rs delete mode 100644 tests/ui/crashes/enum-glob-import-crate.rs delete mode 100644 tests/ui/crashes/ice-1588.rs delete mode 100644 tests/ui/crashes/ice-1782.rs delete mode 100644 tests/ui/crashes/ice-1969.rs delete mode 100644 tests/ui/crashes/ice-2499.rs delete mode 100644 tests/ui/crashes/ice-2594.rs delete mode 100644 tests/ui/crashes/ice-2727.rs delete mode 100644 tests/ui/crashes/ice-2760.rs delete mode 100644 tests/ui/crashes/ice-2774.rs delete mode 100644 tests/ui/crashes/ice-2774.stderr delete mode 100644 tests/ui/crashes/ice-2862.rs delete mode 100644 tests/ui/crashes/ice-2865.rs delete mode 100644 tests/ui/crashes/ice-3151.rs delete mode 100644 tests/ui/crashes/ice-3462.rs delete mode 100644 tests/ui/crashes/ice-360.rs delete mode 100644 tests/ui/crashes/ice-360.stderr delete mode 100644 tests/ui/crashes/ice-3717.rs delete mode 100644 tests/ui/crashes/ice-3717.stderr delete mode 100644 tests/ui/crashes/ice-3741.rs delete mode 100644 tests/ui/crashes/ice-3747.rs delete mode 100644 tests/ui/crashes/ice-3891.rs delete mode 100644 tests/ui/crashes/ice-3891.stderr delete mode 100644 tests/ui/crashes/ice-3969.rs delete mode 100644 tests/ui/crashes/ice-3969.stderr delete mode 100644 tests/ui/crashes/ice-4121.rs delete mode 100644 tests/ui/crashes/ice-4545.rs delete mode 100644 tests/ui/crashes/ice-4579.rs delete mode 100644 tests/ui/crashes/ice-4671.rs delete mode 100644 tests/ui/crashes/ice-4727.rs delete mode 100644 tests/ui/crashes/ice-4760.rs delete mode 100644 tests/ui/crashes/ice-4775.rs delete mode 100644 tests/ui/crashes/ice-4968.rs delete mode 100644 tests/ui/crashes/ice-5207.rs delete mode 100644 tests/ui/crashes/ice-5223.rs delete mode 100644 tests/ui/crashes/ice-5238.rs delete mode 100644 tests/ui/crashes/ice-5389.rs delete mode 100644 tests/ui/crashes/ice-5497.rs delete mode 100644 tests/ui/crashes/ice-5579.rs delete mode 100644 tests/ui/crashes/ice-5872.rs delete mode 100644 tests/ui/crashes/ice-5872.stderr delete mode 100644 tests/ui/crashes/ice-5944.rs delete mode 100644 tests/ui/crashes/ice-6139.rs delete mode 100644 tests/ui/crashes/ice-6153.rs delete mode 100644 tests/ui/crashes/ice-6250.rs delete mode 100644 tests/ui/crashes/ice-6250.stderr delete mode 100644 tests/ui/crashes/ice-6251.rs delete mode 100644 tests/ui/crashes/ice-6251.stderr delete mode 100644 tests/ui/crashes/ice-6252.rs delete mode 100644 tests/ui/crashes/ice-6252.stderr delete mode 100644 tests/ui/crashes/ice-6254.rs delete mode 100644 tests/ui/crashes/ice-6254.stderr delete mode 100644 tests/ui/crashes/ice-6255.rs delete mode 100644 tests/ui/crashes/ice-6255.stderr delete mode 100644 tests/ui/crashes/ice-6256.rs delete mode 100644 tests/ui/crashes/ice-6256.stderr delete mode 100644 tests/ui/crashes/ice-6332.rs delete mode 100644 tests/ui/crashes/ice-700.rs delete mode 100644 tests/ui/crashes/ice_exacte_size.rs delete mode 100644 tests/ui/crashes/if_same_then_else.rs delete mode 100644 tests/ui/crashes/implements-trait.rs delete mode 100644 tests/ui/crashes/inherent_impl.rs delete mode 100644 tests/ui/crashes/issue-825.rs delete mode 100644 tests/ui/crashes/issues_loop_mut_cond.rs delete mode 100644 tests/ui/crashes/match_same_arms_const.rs delete mode 100644 tests/ui/crashes/mut_mut_macro.rs delete mode 100644 tests/ui/crashes/needless_borrow_fp.rs delete mode 100644 tests/ui/crashes/needless_lifetimes_impl_trait.rs delete mode 100644 tests/ui/crashes/needless_lifetimes_impl_trait.stderr delete mode 100644 tests/ui/crashes/procedural_macro.rs delete mode 100644 tests/ui/crashes/regressions.rs delete mode 100644 tests/ui/crashes/returns.rs delete mode 100644 tests/ui/crashes/shadow.rs delete mode 100644 tests/ui/crashes/single-match-else.rs delete mode 100644 tests/ui/crashes/third-party/clippy.toml delete mode 100644 tests/ui/crashes/third-party/conf_allowlisted.rs delete mode 100644 tests/ui/crashes/trivial_bounds.rs delete mode 100644 tests/ui/crashes/used_underscore_binding_macro.rs delete mode 100644 tests/ui/crate_level_checks/entrypoint_recursion.rs delete mode 100644 tests/ui/crate_level_checks/entrypoint_recursion.stderr delete mode 100644 tests/ui/crate_level_checks/no_std_main_recursion.rs delete mode 100644 tests/ui/crate_level_checks/std_main_recursion.rs delete mode 100644 tests/ui/crate_level_checks/std_main_recursion.stderr delete mode 100644 tests/ui/create_dir.fixed delete mode 100644 tests/ui/create_dir.rs delete mode 100644 tests/ui/create_dir.stderr delete mode 100644 tests/ui/dbg_macro.rs delete mode 100644 tests/ui/dbg_macro.stderr delete mode 100644 tests/ui/debug_assert_with_mut_call.rs delete mode 100644 tests/ui/debug_assert_with_mut_call.stderr delete mode 100644 tests/ui/decimal_literal_representation.fixed delete mode 100644 tests/ui/decimal_literal_representation.rs delete mode 100644 tests/ui/decimal_literal_representation.stderr delete mode 100644 tests/ui/declare_interior_mutable_const/enums.rs delete mode 100644 tests/ui/declare_interior_mutable_const/enums.stderr delete mode 100644 tests/ui/declare_interior_mutable_const/others.rs delete mode 100644 tests/ui/declare_interior_mutable_const/others.stderr delete mode 100644 tests/ui/declare_interior_mutable_const/traits.rs delete mode 100644 tests/ui/declare_interior_mutable_const/traits.stderr delete mode 100644 tests/ui/def_id_nocore.rs delete mode 100644 tests/ui/def_id_nocore.stderr delete mode 100644 tests/ui/default_trait_access.fixed delete mode 100644 tests/ui/default_trait_access.rs delete mode 100644 tests/ui/default_trait_access.stderr delete mode 100644 tests/ui/deprecated.rs delete mode 100644 tests/ui/deprecated.stderr delete mode 100644 tests/ui/deprecated_old.rs delete mode 100644 tests/ui/deprecated_old.stderr delete mode 100644 tests/ui/deref_addrof.fixed delete mode 100644 tests/ui/deref_addrof.rs delete mode 100644 tests/ui/deref_addrof.stderr delete mode 100644 tests/ui/deref_addrof_double_trigger.rs delete mode 100644 tests/ui/deref_addrof_double_trigger.stderr delete mode 100644 tests/ui/deref_addrof_macro.rs delete mode 100644 tests/ui/dereference.fixed delete mode 100644 tests/ui/dereference.rs delete mode 100644 tests/ui/dereference.stderr delete mode 100644 tests/ui/derive.rs delete mode 100644 tests/ui/derive.stderr delete mode 100644 tests/ui/derive_hash_xor_eq.rs delete mode 100644 tests/ui/derive_hash_xor_eq.stderr delete mode 100644 tests/ui/derive_ord_xor_partial_ord.rs delete mode 100644 tests/ui/derive_ord_xor_partial_ord.stderr delete mode 100644 tests/ui/diverging_sub_expression.rs delete mode 100644 tests/ui/diverging_sub_expression.stderr delete mode 100644 tests/ui/dlist.rs delete mode 100644 tests/ui/dlist.stderr delete mode 100644 tests/ui/doc.rs delete mode 100644 tests/ui/doc.stderr delete mode 100644 tests/ui/doc_errors.rs delete mode 100644 tests/ui/doc_errors.stderr delete mode 100644 tests/ui/doc_unsafe.rs delete mode 100644 tests/ui/doc_unsafe.stderr delete mode 100644 tests/ui/double_comparison.fixed delete mode 100644 tests/ui/double_comparison.rs delete mode 100644 tests/ui/double_comparison.stderr delete mode 100644 tests/ui/double_must_use.rs delete mode 100644 tests/ui/double_must_use.stderr delete mode 100644 tests/ui/double_neg.rs delete mode 100644 tests/ui/double_neg.stderr delete mode 100644 tests/ui/double_parens.rs delete mode 100644 tests/ui/double_parens.stderr delete mode 100644 tests/ui/drop_forget_copy.rs delete mode 100644 tests/ui/drop_forget_copy.stderr delete mode 100644 tests/ui/drop_ref.rs delete mode 100644 tests/ui/drop_ref.stderr delete mode 100644 tests/ui/duplicate_underscore_argument.rs delete mode 100644 tests/ui/duplicate_underscore_argument.stderr delete mode 100644 tests/ui/duration_subsec.fixed delete mode 100644 tests/ui/duration_subsec.rs delete mode 100644 tests/ui/duration_subsec.stderr delete mode 100644 tests/ui/else_if_without_else.rs delete mode 100644 tests/ui/else_if_without_else.stderr delete mode 100644 tests/ui/empty_enum.rs delete mode 100644 tests/ui/empty_enum.stderr delete mode 100644 tests/ui/empty_line_after_outer_attribute.rs delete mode 100644 tests/ui/empty_line_after_outer_attribute.stderr delete mode 100644 tests/ui/empty_loop.rs delete mode 100644 tests/ui/empty_loop.stderr delete mode 100644 tests/ui/empty_loop_no_std.rs delete mode 100644 tests/ui/empty_loop_no_std.stderr delete mode 100644 tests/ui/entry_fixable.fixed delete mode 100644 tests/ui/entry_fixable.rs delete mode 100644 tests/ui/entry_fixable.stderr delete mode 100644 tests/ui/entry_unfixable.rs delete mode 100644 tests/ui/entry_unfixable.stderr delete mode 100644 tests/ui/enum_clike_unportable_variant.rs delete mode 100644 tests/ui/enum_clike_unportable_variant.stderr delete mode 100644 tests/ui/enum_glob_use.fixed delete mode 100644 tests/ui/enum_glob_use.rs delete mode 100644 tests/ui/enum_glob_use.stderr delete mode 100644 tests/ui/enum_variants.rs delete mode 100644 tests/ui/enum_variants.stderr delete mode 100644 tests/ui/eprint_with_newline.rs delete mode 100644 tests/ui/eprint_with_newline.stderr delete mode 100644 tests/ui/eq_op.rs delete mode 100644 tests/ui/eq_op.stderr delete mode 100644 tests/ui/eq_op_macros.rs delete mode 100644 tests/ui/eq_op_macros.stderr delete mode 100644 tests/ui/erasing_op.rs delete mode 100644 tests/ui/erasing_op.stderr delete mode 100644 tests/ui/escape_analysis.rs delete mode 100644 tests/ui/escape_analysis.stderr delete mode 100644 tests/ui/eta.fixed delete mode 100644 tests/ui/eta.rs delete mode 100644 tests/ui/eta.stderr delete mode 100644 tests/ui/eval_order_dependence.rs delete mode 100644 tests/ui/eval_order_dependence.stderr delete mode 100644 tests/ui/excessive_precision.fixed delete mode 100644 tests/ui/excessive_precision.rs delete mode 100644 tests/ui/excessive_precision.stderr delete mode 100644 tests/ui/exit1.rs delete mode 100644 tests/ui/exit1.stderr delete mode 100644 tests/ui/exit2.rs delete mode 100644 tests/ui/exit2.stderr delete mode 100644 tests/ui/exit3.rs delete mode 100644 tests/ui/expect.rs delete mode 100644 tests/ui/expect.stderr delete mode 100644 tests/ui/expect_fun_call.fixed delete mode 100644 tests/ui/expect_fun_call.rs delete mode 100644 tests/ui/expect_fun_call.stderr delete mode 100644 tests/ui/explicit_counter_loop.rs delete mode 100644 tests/ui/explicit_counter_loop.stderr delete mode 100644 tests/ui/explicit_write.fixed delete mode 100644 tests/ui/explicit_write.rs delete mode 100644 tests/ui/explicit_write.stderr delete mode 100644 tests/ui/explicit_write_non_rustfix.rs delete mode 100644 tests/ui/explicit_write_non_rustfix.stderr delete mode 100644 tests/ui/extra_unused_lifetimes.rs delete mode 100644 tests/ui/extra_unused_lifetimes.stderr delete mode 100644 tests/ui/fallible_impl_from.rs delete mode 100644 tests/ui/fallible_impl_from.stderr delete mode 100644 tests/ui/field_reassign_with_default.rs delete mode 100644 tests/ui/field_reassign_with_default.stderr delete mode 100644 tests/ui/filetype_is_file.rs delete mode 100644 tests/ui/filetype_is_file.stderr delete mode 100644 tests/ui/filter_map_next.rs delete mode 100644 tests/ui/filter_map_next.stderr delete mode 100644 tests/ui/filter_map_next_fixable.fixed delete mode 100644 tests/ui/filter_map_next_fixable.rs delete mode 100644 tests/ui/filter_map_next_fixable.stderr delete mode 100644 tests/ui/filter_methods.rs delete mode 100644 tests/ui/filter_methods.stderr delete mode 100644 tests/ui/find_map.rs delete mode 100644 tests/ui/find_map.stderr delete mode 100644 tests/ui/float_arithmetic.rs delete mode 100644 tests/ui/float_arithmetic.stderr delete mode 100644 tests/ui/float_cmp.rs delete mode 100644 tests/ui/float_cmp.stderr delete mode 100644 tests/ui/float_cmp_const.rs delete mode 100644 tests/ui/float_cmp_const.stderr delete mode 100644 tests/ui/float_equality_without_abs.rs delete mode 100644 tests/ui/float_equality_without_abs.stderr delete mode 100644 tests/ui/floating_point_abs.fixed delete mode 100644 tests/ui/floating_point_abs.rs delete mode 100644 tests/ui/floating_point_abs.stderr delete mode 100644 tests/ui/floating_point_exp.fixed delete mode 100644 tests/ui/floating_point_exp.rs delete mode 100644 tests/ui/floating_point_exp.stderr delete mode 100644 tests/ui/floating_point_hypot.fixed delete mode 100644 tests/ui/floating_point_hypot.rs delete mode 100644 tests/ui/floating_point_hypot.stderr delete mode 100644 tests/ui/floating_point_log.fixed delete mode 100644 tests/ui/floating_point_log.rs delete mode 100644 tests/ui/floating_point_log.stderr delete mode 100644 tests/ui/floating_point_logbase.fixed delete mode 100644 tests/ui/floating_point_logbase.rs delete mode 100644 tests/ui/floating_point_logbase.stderr delete mode 100644 tests/ui/floating_point_mul_add.fixed delete mode 100644 tests/ui/floating_point_mul_add.rs delete mode 100644 tests/ui/floating_point_mul_add.stderr delete mode 100644 tests/ui/floating_point_powf.fixed delete mode 100644 tests/ui/floating_point_powf.rs delete mode 100644 tests/ui/floating_point_powf.stderr delete mode 100644 tests/ui/floating_point_powi.fixed delete mode 100644 tests/ui/floating_point_powi.rs delete mode 100644 tests/ui/floating_point_powi.stderr delete mode 100644 tests/ui/floating_point_rad.fixed delete mode 100644 tests/ui/floating_point_rad.rs delete mode 100644 tests/ui/floating_point_rad.stderr delete mode 100644 tests/ui/fn_address_comparisons.rs delete mode 100644 tests/ui/fn_address_comparisons.stderr delete mode 100644 tests/ui/fn_params_excessive_bools.rs delete mode 100644 tests/ui/fn_params_excessive_bools.stderr delete mode 100644 tests/ui/fn_to_numeric_cast.rs delete mode 100644 tests/ui/fn_to_numeric_cast.stderr delete mode 100644 tests/ui/fn_to_numeric_cast_32bit.rs delete mode 100644 tests/ui/fn_to_numeric_cast_32bit.stderr delete mode 100644 tests/ui/for_kv_map.rs delete mode 100644 tests/ui/for_kv_map.stderr delete mode 100644 tests/ui/for_loop_fixable.fixed delete mode 100644 tests/ui/for_loop_fixable.rs delete mode 100644 tests/ui/for_loop_fixable.stderr delete mode 100644 tests/ui/for_loop_unfixable.rs delete mode 100644 tests/ui/for_loop_unfixable.stderr delete mode 100644 tests/ui/for_loops_over_fallibles.rs delete mode 100644 tests/ui/for_loops_over_fallibles.stderr delete mode 100644 tests/ui/forget_ref.rs delete mode 100644 tests/ui/forget_ref.stderr delete mode 100644 tests/ui/format.fixed delete mode 100644 tests/ui/format.rs delete mode 100644 tests/ui/format.stderr delete mode 100644 tests/ui/formatting.rs delete mode 100644 tests/ui/formatting.stderr delete mode 100644 tests/ui/from_iter_instead_of_collect.rs delete mode 100644 tests/ui/from_iter_instead_of_collect.stderr delete mode 100644 tests/ui/functions.rs delete mode 100644 tests/ui/functions.stderr delete mode 100644 tests/ui/functions_maxlines.rs delete mode 100644 tests/ui/functions_maxlines.stderr delete mode 100644 tests/ui/future_not_send.rs delete mode 100644 tests/ui/future_not_send.stderr delete mode 100644 tests/ui/get_last_with_len.fixed delete mode 100644 tests/ui/get_last_with_len.rs delete mode 100644 tests/ui/get_last_with_len.stderr delete mode 100644 tests/ui/get_unwrap.fixed delete mode 100644 tests/ui/get_unwrap.rs delete mode 100644 tests/ui/get_unwrap.stderr delete mode 100644 tests/ui/identity_op.rs delete mode 100644 tests/ui/identity_op.stderr delete mode 100644 tests/ui/if_let_mutex.rs delete mode 100644 tests/ui/if_let_mutex.stderr delete mode 100644 tests/ui/if_let_some_result.fixed delete mode 100644 tests/ui/if_let_some_result.rs delete mode 100644 tests/ui/if_let_some_result.stderr delete mode 100644 tests/ui/if_not_else.rs delete mode 100644 tests/ui/if_not_else.stderr delete mode 100644 tests/ui/if_same_then_else.rs delete mode 100644 tests/ui/if_same_then_else.stderr delete mode 100644 tests/ui/if_same_then_else2.rs delete mode 100644 tests/ui/if_same_then_else2.stderr delete mode 100644 tests/ui/ifs_same_cond.rs delete mode 100644 tests/ui/ifs_same_cond.stderr delete mode 100644 tests/ui/impl.rs delete mode 100644 tests/ui/impl.stderr delete mode 100644 tests/ui/implicit_hasher.rs delete mode 100644 tests/ui/implicit_hasher.stderr delete mode 100644 tests/ui/implicit_return.fixed delete mode 100644 tests/ui/implicit_return.rs delete mode 100644 tests/ui/implicit_return.stderr delete mode 100644 tests/ui/implicit_saturating_sub.fixed delete mode 100644 tests/ui/implicit_saturating_sub.rs delete mode 100644 tests/ui/implicit_saturating_sub.stderr delete mode 100644 tests/ui/inconsistent_digit_grouping.fixed delete mode 100644 tests/ui/inconsistent_digit_grouping.rs delete mode 100644 tests/ui/inconsistent_digit_grouping.stderr delete mode 100644 tests/ui/indexing_slicing_index.rs delete mode 100644 tests/ui/indexing_slicing_index.stderr delete mode 100644 tests/ui/indexing_slicing_slice.rs delete mode 100644 tests/ui/indexing_slicing_slice.stderr delete mode 100644 tests/ui/inefficient_to_string.fixed delete mode 100644 tests/ui/inefficient_to_string.rs delete mode 100644 tests/ui/inefficient_to_string.stderr delete mode 100644 tests/ui/infallible_destructuring_match.fixed delete mode 100644 tests/ui/infallible_destructuring_match.rs delete mode 100644 tests/ui/infallible_destructuring_match.stderr delete mode 100644 tests/ui/infinite_iter.rs delete mode 100644 tests/ui/infinite_iter.stderr delete mode 100644 tests/ui/infinite_loop.rs delete mode 100644 tests/ui/infinite_loop.stderr delete mode 100644 tests/ui/inherent_to_string.rs delete mode 100644 tests/ui/inherent_to_string.stderr delete mode 100644 tests/ui/inline_fn_without_body.fixed delete mode 100644 tests/ui/inline_fn_without_body.rs delete mode 100644 tests/ui/inline_fn_without_body.stderr delete mode 100644 tests/ui/int_plus_one.fixed delete mode 100644 tests/ui/int_plus_one.rs delete mode 100644 tests/ui/int_plus_one.stderr delete mode 100644 tests/ui/integer_arithmetic.rs delete mode 100644 tests/ui/integer_arithmetic.stderr delete mode 100644 tests/ui/integer_division.rs delete mode 100644 tests/ui/integer_division.stderr delete mode 100644 tests/ui/into_iter_on_ref.fixed delete mode 100644 tests/ui/into_iter_on_ref.rs delete mode 100644 tests/ui/into_iter_on_ref.stderr delete mode 100644 tests/ui/invalid_upcast_comparisons.rs delete mode 100644 tests/ui/invalid_upcast_comparisons.stderr delete mode 100644 tests/ui/issue-3145.rs delete mode 100644 tests/ui/issue-3145.stderr delete mode 100644 tests/ui/issue_2356.rs delete mode 100644 tests/ui/issue_2356.stderr delete mode 100644 tests/ui/issue_4266.rs delete mode 100644 tests/ui/issue_4266.stderr delete mode 100644 tests/ui/item_after_statement.rs delete mode 100644 tests/ui/item_after_statement.stderr delete mode 100644 tests/ui/iter_cloned_collect.fixed delete mode 100644 tests/ui/iter_cloned_collect.rs delete mode 100644 tests/ui/iter_cloned_collect.stderr delete mode 100644 tests/ui/iter_next_slice.fixed delete mode 100644 tests/ui/iter_next_slice.rs delete mode 100644 tests/ui/iter_next_slice.stderr delete mode 100644 tests/ui/iter_nth.rs delete mode 100644 tests/ui/iter_nth.stderr delete mode 100644 tests/ui/iter_nth_zero.fixed delete mode 100644 tests/ui/iter_nth_zero.rs delete mode 100644 tests/ui/iter_nth_zero.stderr delete mode 100644 tests/ui/iter_skip_next.fixed delete mode 100644 tests/ui/iter_skip_next.rs delete mode 100644 tests/ui/iter_skip_next.stderr delete mode 100644 tests/ui/iterator_step_by_zero.rs delete mode 100644 tests/ui/iterator_step_by_zero.stderr delete mode 100644 tests/ui/large_const_arrays.fixed delete mode 100644 tests/ui/large_const_arrays.rs delete mode 100644 tests/ui/large_const_arrays.stderr delete mode 100644 tests/ui/large_digit_groups.fixed delete mode 100644 tests/ui/large_digit_groups.rs delete mode 100644 tests/ui/large_digit_groups.stderr delete mode 100644 tests/ui/large_enum_variant.rs delete mode 100644 tests/ui/large_enum_variant.stderr delete mode 100644 tests/ui/large_stack_arrays.rs delete mode 100644 tests/ui/large_stack_arrays.stderr delete mode 100644 tests/ui/large_types_passed_by_value.rs delete mode 100644 tests/ui/large_types_passed_by_value.stderr delete mode 100644 tests/ui/len_without_is_empty.rs delete mode 100644 tests/ui/len_without_is_empty.stderr delete mode 100644 tests/ui/len_zero.fixed delete mode 100644 tests/ui/len_zero.rs delete mode 100644 tests/ui/len_zero.stderr delete mode 100644 tests/ui/len_zero_ranges.fixed delete mode 100644 tests/ui/len_zero_ranges.rs delete mode 100644 tests/ui/len_zero_ranges.stderr delete mode 100644 tests/ui/let_and_return.rs delete mode 100644 tests/ui/let_and_return.stderr delete mode 100644 tests/ui/let_if_seq.rs delete mode 100644 tests/ui/let_if_seq.stderr delete mode 100644 tests/ui/let_underscore_drop.rs delete mode 100644 tests/ui/let_underscore_drop.stderr delete mode 100644 tests/ui/let_underscore_lock.rs delete mode 100644 tests/ui/let_underscore_lock.stderr delete mode 100644 tests/ui/let_underscore_must_use.rs delete mode 100644 tests/ui/let_underscore_must_use.stderr delete mode 100644 tests/ui/let_unit.fixed delete mode 100644 tests/ui/let_unit.rs delete mode 100644 tests/ui/let_unit.stderr delete mode 100644 tests/ui/literals.rs delete mode 100644 tests/ui/literals.stderr delete mode 100644 tests/ui/logic_bug.rs delete mode 100644 tests/ui/logic_bug.stderr delete mode 100644 tests/ui/lossy_float_literal.fixed delete mode 100644 tests/ui/lossy_float_literal.rs delete mode 100644 tests/ui/lossy_float_literal.stderr delete mode 100644 tests/ui/macro_use_imports.fixed delete mode 100644 tests/ui/macro_use_imports.rs delete mode 100644 tests/ui/macro_use_imports.stderr delete mode 100644 tests/ui/manual_async_fn.fixed delete mode 100644 tests/ui/manual_async_fn.rs delete mode 100644 tests/ui/manual_async_fn.stderr delete mode 100644 tests/ui/manual_memcpy/with_loop_counters.rs delete mode 100644 tests/ui/manual_memcpy/with_loop_counters.stderr delete mode 100644 tests/ui/manual_memcpy/without_loop_counters.rs delete mode 100644 tests/ui/manual_memcpy/without_loop_counters.stderr delete mode 100644 tests/ui/manual_non_exhaustive.rs delete mode 100644 tests/ui/manual_non_exhaustive.stderr delete mode 100644 tests/ui/manual_ok_or.fixed delete mode 100644 tests/ui/manual_ok_or.rs delete mode 100644 tests/ui/manual_ok_or.stderr delete mode 100644 tests/ui/manual_saturating_arithmetic.fixed delete mode 100644 tests/ui/manual_saturating_arithmetic.rs delete mode 100644 tests/ui/manual_saturating_arithmetic.stderr delete mode 100644 tests/ui/manual_strip.rs delete mode 100644 tests/ui/manual_strip.stderr delete mode 100644 tests/ui/manual_unwrap_or.fixed delete mode 100644 tests/ui/manual_unwrap_or.rs delete mode 100644 tests/ui/manual_unwrap_or.stderr delete mode 100644 tests/ui/many_single_char_names.rs delete mode 100644 tests/ui/many_single_char_names.stderr delete mode 100644 tests/ui/map_clone.fixed delete mode 100644 tests/ui/map_clone.rs delete mode 100644 tests/ui/map_clone.stderr delete mode 100644 tests/ui/map_collect_result_unit.fixed delete mode 100644 tests/ui/map_collect_result_unit.rs delete mode 100644 tests/ui/map_collect_result_unit.stderr delete mode 100644 tests/ui/map_err.rs delete mode 100644 tests/ui/map_err.stderr delete mode 100644 tests/ui/map_flatten.fixed delete mode 100644 tests/ui/map_flatten.rs delete mode 100644 tests/ui/map_flatten.stderr delete mode 100644 tests/ui/map_identity.fixed delete mode 100644 tests/ui/map_identity.rs delete mode 100644 tests/ui/map_identity.stderr delete mode 100644 tests/ui/map_unit_fn.rs delete mode 100644 tests/ui/map_unwrap_or.rs delete mode 100644 tests/ui/map_unwrap_or.stderr delete mode 100644 tests/ui/map_unwrap_or_fixable.fixed delete mode 100644 tests/ui/map_unwrap_or_fixable.rs delete mode 100644 tests/ui/map_unwrap_or_fixable.stderr delete mode 100644 tests/ui/match_as_ref.fixed delete mode 100644 tests/ui/match_as_ref.rs delete mode 100644 tests/ui/match_as_ref.stderr delete mode 100644 tests/ui/match_bool.rs delete mode 100644 tests/ui/match_bool.stderr delete mode 100644 tests/ui/match_expr_like_matches_macro.fixed delete mode 100644 tests/ui/match_expr_like_matches_macro.rs delete mode 100644 tests/ui/match_expr_like_matches_macro.stderr delete mode 100644 tests/ui/match_on_vec_items.rs delete mode 100644 tests/ui/match_on_vec_items.stderr delete mode 100644 tests/ui/match_overlapping_arm.rs delete mode 100644 tests/ui/match_overlapping_arm.stderr delete mode 100644 tests/ui/match_ref_pats.rs delete mode 100644 tests/ui/match_ref_pats.stderr delete mode 100644 tests/ui/match_same_arms.rs delete mode 100644 tests/ui/match_same_arms.stderr delete mode 100644 tests/ui/match_same_arms2.rs delete mode 100644 tests/ui/match_same_arms2.stderr delete mode 100644 tests/ui/match_single_binding.fixed delete mode 100644 tests/ui/match_single_binding.rs delete mode 100644 tests/ui/match_single_binding.stderr delete mode 100644 tests/ui/match_wild_err_arm.rs delete mode 100644 tests/ui/match_wild_err_arm.stderr delete mode 100644 tests/ui/match_wildcard_for_single_variants.fixed delete mode 100644 tests/ui/match_wildcard_for_single_variants.rs delete mode 100644 tests/ui/match_wildcard_for_single_variants.stderr delete mode 100644 tests/ui/mem_discriminant.fixed delete mode 100644 tests/ui/mem_discriminant.rs delete mode 100644 tests/ui/mem_discriminant.stderr delete mode 100644 tests/ui/mem_discriminant_unfixable.rs delete mode 100644 tests/ui/mem_discriminant_unfixable.stderr delete mode 100644 tests/ui/mem_forget.rs delete mode 100644 tests/ui/mem_forget.stderr delete mode 100644 tests/ui/mem_replace.fixed delete mode 100644 tests/ui/mem_replace.rs delete mode 100644 tests/ui/mem_replace.stderr delete mode 100644 tests/ui/mem_replace_macro.rs delete mode 100644 tests/ui/mem_replace_macro.stderr delete mode 100644 tests/ui/methods.rs delete mode 100644 tests/ui/methods.stderr delete mode 100644 tests/ui/methods_fixable.fixed delete mode 100644 tests/ui/methods_fixable.rs delete mode 100644 tests/ui/methods_fixable.stderr delete mode 100644 tests/ui/min_max.rs delete mode 100644 tests/ui/min_max.stderr delete mode 100644 tests/ui/min_rust_version_attr.rs delete mode 100644 tests/ui/min_rust_version_attr.stderr delete mode 100644 tests/ui/min_rust_version_invalid_attr.rs delete mode 100644 tests/ui/min_rust_version_invalid_attr.stderr delete mode 100644 tests/ui/min_rust_version_multiple_inner_attr.rs delete mode 100644 tests/ui/min_rust_version_multiple_inner_attr.stderr delete mode 100644 tests/ui/min_rust_version_no_patch.rs delete mode 100644 tests/ui/min_rust_version_outer_attr.rs delete mode 100644 tests/ui/min_rust_version_outer_attr.stderr delete mode 100644 tests/ui/mismatched_target_os_non_unix.fixed delete mode 100644 tests/ui/mismatched_target_os_non_unix.rs delete mode 100644 tests/ui/mismatched_target_os_non_unix.stderr delete mode 100644 tests/ui/mismatched_target_os_unix.fixed delete mode 100644 tests/ui/mismatched_target_os_unix.rs delete mode 100644 tests/ui/mismatched_target_os_unix.stderr delete mode 100644 tests/ui/missing-doc-crate-missing.rs delete mode 100644 tests/ui/missing-doc-crate-missing.stderr delete mode 100644 tests/ui/missing-doc-crate.rs delete mode 100644 tests/ui/missing-doc-crate.stderr delete mode 100644 tests/ui/missing-doc-impl.rs delete mode 100644 tests/ui/missing-doc-impl.stderr delete mode 100644 tests/ui/missing-doc.rs delete mode 100644 tests/ui/missing-doc.stderr delete mode 100644 tests/ui/missing_const_for_fn/cant_be_const.rs delete mode 100644 tests/ui/missing_const_for_fn/cant_be_const.stderr delete mode 100644 tests/ui/missing_const_for_fn/could_be_const.rs delete mode 100644 tests/ui/missing_const_for_fn/could_be_const.stderr delete mode 100644 tests/ui/missing_inline.rs delete mode 100644 tests/ui/missing_inline.stderr delete mode 100644 tests/ui/mistyped_literal_suffix.fixed delete mode 100644 tests/ui/mistyped_literal_suffix.rs delete mode 100644 tests/ui/mistyped_literal_suffix.stderr delete mode 100644 tests/ui/module_inception.rs delete mode 100644 tests/ui/module_inception.stderr delete mode 100644 tests/ui/module_name_repetitions.rs delete mode 100644 tests/ui/module_name_repetitions.stderr delete mode 100644 tests/ui/modulo_arithmetic_float.rs delete mode 100644 tests/ui/modulo_arithmetic_float.stderr delete mode 100644 tests/ui/modulo_arithmetic_integral.rs delete mode 100644 tests/ui/modulo_arithmetic_integral.stderr delete mode 100644 tests/ui/modulo_arithmetic_integral_const.rs delete mode 100644 tests/ui/modulo_arithmetic_integral_const.stderr delete mode 100644 tests/ui/modulo_one.rs delete mode 100644 tests/ui/modulo_one.stderr delete mode 100644 tests/ui/must_use_candidates.fixed delete mode 100644 tests/ui/must_use_candidates.rs delete mode 100644 tests/ui/must_use_candidates.stderr delete mode 100644 tests/ui/must_use_unit.fixed delete mode 100644 tests/ui/must_use_unit.rs delete mode 100644 tests/ui/must_use_unit.stderr delete mode 100644 tests/ui/mut_from_ref.rs delete mode 100644 tests/ui/mut_from_ref.stderr delete mode 100644 tests/ui/mut_key.rs delete mode 100644 tests/ui/mut_key.stderr delete mode 100644 tests/ui/mut_mut.rs delete mode 100644 tests/ui/mut_mut.stderr delete mode 100644 tests/ui/mut_mutex_lock.fixed delete mode 100644 tests/ui/mut_mutex_lock.rs delete mode 100644 tests/ui/mut_mutex_lock.stderr delete mode 100644 tests/ui/mut_range_bound.rs delete mode 100644 tests/ui/mut_range_bound.stderr delete mode 100644 tests/ui/mut_reference.rs delete mode 100644 tests/ui/mut_reference.stderr delete mode 100644 tests/ui/mutex_atomic.rs delete mode 100644 tests/ui/mutex_atomic.stderr delete mode 100644 tests/ui/needless_arbitrary_self_type.fixed delete mode 100644 tests/ui/needless_arbitrary_self_type.rs delete mode 100644 tests/ui/needless_arbitrary_self_type.stderr delete mode 100644 tests/ui/needless_arbitrary_self_type_unfixable.rs delete mode 100644 tests/ui/needless_arbitrary_self_type_unfixable.stderr delete mode 100644 tests/ui/needless_bool/fixable.fixed delete mode 100644 tests/ui/needless_bool/fixable.rs delete mode 100644 tests/ui/needless_bool/fixable.stderr delete mode 100644 tests/ui/needless_bool/simple.rs delete mode 100644 tests/ui/needless_bool/simple.stderr delete mode 100644 tests/ui/needless_borrow.fixed delete mode 100644 tests/ui/needless_borrow.rs delete mode 100644 tests/ui/needless_borrow.stderr delete mode 100644 tests/ui/needless_borrowed_ref.fixed delete mode 100644 tests/ui/needless_borrowed_ref.rs delete mode 100644 tests/ui/needless_borrowed_ref.stderr delete mode 100644 tests/ui/needless_collect.fixed delete mode 100644 tests/ui/needless_collect.rs delete mode 100644 tests/ui/needless_collect.stderr delete mode 100644 tests/ui/needless_collect_indirect.rs delete mode 100644 tests/ui/needless_collect_indirect.stderr delete mode 100644 tests/ui/needless_continue.rs delete mode 100644 tests/ui/needless_continue.stderr delete mode 100644 tests/ui/needless_doc_main.rs delete mode 100644 tests/ui/needless_doc_main.stderr delete mode 100644 tests/ui/needless_lifetimes.rs delete mode 100644 tests/ui/needless_lifetimes.stderr delete mode 100644 tests/ui/needless_pass_by_value.rs delete mode 100644 tests/ui/needless_pass_by_value.stderr delete mode 100644 tests/ui/needless_pass_by_value_proc_macro.rs delete mode 100644 tests/ui/needless_range_loop.rs delete mode 100644 tests/ui/needless_range_loop.stderr delete mode 100644 tests/ui/needless_range_loop2.rs delete mode 100644 tests/ui/needless_range_loop2.stderr delete mode 100644 tests/ui/needless_return.fixed delete mode 100644 tests/ui/needless_return.rs delete mode 100644 tests/ui/needless_return.stderr delete mode 100644 tests/ui/needless_update.rs delete mode 100644 tests/ui/needless_update.stderr delete mode 100644 tests/ui/neg_cmp_op_on_partial_ord.rs delete mode 100644 tests/ui/neg_cmp_op_on_partial_ord.stderr delete mode 100644 tests/ui/neg_multiply.rs delete mode 100644 tests/ui/neg_multiply.stderr delete mode 100644 tests/ui/never_loop.rs delete mode 100644 tests/ui/never_loop.stderr delete mode 100644 tests/ui/new_ret_no_self.rs delete mode 100644 tests/ui/new_ret_no_self.stderr delete mode 100644 tests/ui/new_without_default.rs delete mode 100644 tests/ui/new_without_default.stderr delete mode 100644 tests/ui/no_effect.rs delete mode 100644 tests/ui/no_effect.stderr delete mode 100644 tests/ui/non_expressive_names.rs delete mode 100644 tests/ui/non_expressive_names.stderr delete mode 100644 tests/ui/non_expressive_names.stdout delete mode 100644 tests/ui/nonminimal_bool.rs delete mode 100644 tests/ui/nonminimal_bool.stderr delete mode 100644 tests/ui/nonminimal_bool_methods.rs delete mode 100644 tests/ui/nonminimal_bool_methods.stderr delete mode 100644 tests/ui/ok_expect.rs delete mode 100644 tests/ui/ok_expect.stderr delete mode 100644 tests/ui/op_ref.rs delete mode 100644 tests/ui/op_ref.stderr delete mode 100644 tests/ui/open_options.rs delete mode 100644 tests/ui/open_options.stderr delete mode 100644 tests/ui/option_as_ref_deref.fixed delete mode 100644 tests/ui/option_as_ref_deref.rs delete mode 100644 tests/ui/option_as_ref_deref.stderr delete mode 100644 tests/ui/option_env_unwrap.rs delete mode 100644 tests/ui/option_env_unwrap.stderr delete mode 100644 tests/ui/option_if_let_else.fixed delete mode 100644 tests/ui/option_if_let_else.rs delete mode 100644 tests/ui/option_if_let_else.stderr delete mode 100644 tests/ui/option_map_or_none.fixed delete mode 100644 tests/ui/option_map_or_none.rs delete mode 100644 tests/ui/option_map_or_none.stderr delete mode 100644 tests/ui/option_map_unit_fn_fixable.fixed delete mode 100644 tests/ui/option_map_unit_fn_fixable.rs delete mode 100644 tests/ui/option_map_unit_fn_fixable.stderr delete mode 100644 tests/ui/option_map_unit_fn_unfixable.rs delete mode 100644 tests/ui/option_map_unit_fn_unfixable.stderr delete mode 100644 tests/ui/option_option.rs delete mode 100644 tests/ui/option_option.stderr delete mode 100644 tests/ui/or_fun_call.fixed delete mode 100644 tests/ui/or_fun_call.rs delete mode 100644 tests/ui/or_fun_call.stderr delete mode 100644 tests/ui/out_of_bounds_indexing/issue-3102.rs delete mode 100644 tests/ui/out_of_bounds_indexing/issue-3102.stderr delete mode 100644 tests/ui/out_of_bounds_indexing/simple.rs delete mode 100644 tests/ui/out_of_bounds_indexing/simple.stderr delete mode 100644 tests/ui/overflow_check_conditional.rs delete mode 100644 tests/ui/overflow_check_conditional.stderr delete mode 100644 tests/ui/panic_in_result_fn.rs delete mode 100644 tests/ui/panic_in_result_fn.stderr delete mode 100644 tests/ui/panic_in_result_fn_assertions.rs delete mode 100644 tests/ui/panic_in_result_fn_assertions.stderr delete mode 100644 tests/ui/panic_in_result_fn_debug_assertions.rs delete mode 100644 tests/ui/panic_in_result_fn_debug_assertions.stderr delete mode 100644 tests/ui/panicking_macros.rs delete mode 100644 tests/ui/panicking_macros.stderr delete mode 100644 tests/ui/partialeq_ne_impl.rs delete mode 100644 tests/ui/partialeq_ne_impl.stderr delete mode 100644 tests/ui/path_buf_push_overwrite.fixed delete mode 100644 tests/ui/path_buf_push_overwrite.rs delete mode 100644 tests/ui/path_buf_push_overwrite.stderr delete mode 100644 tests/ui/pattern_type_mismatch/mutability.rs delete mode 100644 tests/ui/pattern_type_mismatch/mutability.stderr delete mode 100644 tests/ui/pattern_type_mismatch/pattern_alternatives.rs delete mode 100644 tests/ui/pattern_type_mismatch/pattern_alternatives.stderr delete mode 100644 tests/ui/pattern_type_mismatch/pattern_structs.rs delete mode 100644 tests/ui/pattern_type_mismatch/pattern_structs.stderr delete mode 100644 tests/ui/pattern_type_mismatch/pattern_tuples.rs delete mode 100644 tests/ui/pattern_type_mismatch/pattern_tuples.stderr delete mode 100644 tests/ui/pattern_type_mismatch/syntax.rs delete mode 100644 tests/ui/pattern_type_mismatch/syntax.stderr delete mode 100644 tests/ui/patterns.fixed delete mode 100644 tests/ui/patterns.rs delete mode 100644 tests/ui/patterns.stderr delete mode 100644 tests/ui/precedence.fixed delete mode 100644 tests/ui/precedence.rs delete mode 100644 tests/ui/precedence.stderr delete mode 100644 tests/ui/print.rs delete mode 100644 tests/ui/print.stderr delete mode 100644 tests/ui/print_literal.rs delete mode 100644 tests/ui/print_literal.stderr delete mode 100644 tests/ui/print_stderr.rs delete mode 100644 tests/ui/print_stderr.stderr delete mode 100644 tests/ui/print_stdout_build_script.rs delete mode 100644 tests/ui/print_with_newline.rs delete mode 100644 tests/ui/print_with_newline.stderr delete mode 100644 tests/ui/println_empty_string.fixed delete mode 100644 tests/ui/println_empty_string.rs delete mode 100644 tests/ui/println_empty_string.stderr delete mode 100644 tests/ui/proc_macro.rs delete mode 100644 tests/ui/proc_macro.stderr delete mode 100644 tests/ui/ptr_arg.rs delete mode 100644 tests/ui/ptr_arg.stderr delete mode 100644 tests/ui/ptr_eq.fixed delete mode 100644 tests/ui/ptr_eq.rs delete mode 100644 tests/ui/ptr_eq.stderr delete mode 100644 tests/ui/ptr_offset_with_cast.fixed delete mode 100644 tests/ui/ptr_offset_with_cast.rs delete mode 100644 tests/ui/ptr_offset_with_cast.stderr delete mode 100644 tests/ui/question_mark.fixed delete mode 100644 tests/ui/question_mark.rs delete mode 100644 tests/ui/question_mark.stderr delete mode 100644 tests/ui/range.rs delete mode 100644 tests/ui/range.stderr delete mode 100644 tests/ui/range_contains.fixed delete mode 100644 tests/ui/range_contains.rs delete mode 100644 tests/ui/range_contains.stderr delete mode 100644 tests/ui/range_plus_minus_one.fixed delete mode 100644 tests/ui/range_plus_minus_one.rs delete mode 100644 tests/ui/range_plus_minus_one.stderr delete mode 100644 tests/ui/rc_buffer.rs delete mode 100644 tests/ui/rc_buffer.stderr delete mode 100644 tests/ui/rc_buffer_arc.rs delete mode 100644 tests/ui/rc_buffer_arc.stderr delete mode 100644 tests/ui/rc_buffer_redefined_string.rs delete mode 100644 tests/ui/rc_buffer_redefined_string.stderr delete mode 100644 tests/ui/redundant_allocation.fixed delete mode 100644 tests/ui/redundant_allocation.rs delete mode 100644 tests/ui/redundant_allocation.stderr delete mode 100644 tests/ui/redundant_clone.fixed delete mode 100644 tests/ui/redundant_clone.rs delete mode 100644 tests/ui/redundant_clone.stderr delete mode 100644 tests/ui/redundant_closure_call_early.rs delete mode 100644 tests/ui/redundant_closure_call_early.stderr delete mode 100644 tests/ui/redundant_closure_call_fixable.fixed delete mode 100644 tests/ui/redundant_closure_call_fixable.rs delete mode 100644 tests/ui/redundant_closure_call_fixable.stderr delete mode 100644 tests/ui/redundant_closure_call_late.rs delete mode 100644 tests/ui/redundant_closure_call_late.stderr delete mode 100644 tests/ui/redundant_else.rs delete mode 100644 tests/ui/redundant_else.stderr delete mode 100644 tests/ui/redundant_field_names.fixed delete mode 100644 tests/ui/redundant_field_names.rs delete mode 100644 tests/ui/redundant_field_names.stderr delete mode 100644 tests/ui/redundant_pattern_matching_ipaddr.fixed delete mode 100644 tests/ui/redundant_pattern_matching_ipaddr.rs delete mode 100644 tests/ui/redundant_pattern_matching_ipaddr.stderr delete mode 100644 tests/ui/redundant_pattern_matching_option.fixed delete mode 100644 tests/ui/redundant_pattern_matching_option.rs delete mode 100644 tests/ui/redundant_pattern_matching_option.stderr delete mode 100644 tests/ui/redundant_pattern_matching_poll.fixed delete mode 100644 tests/ui/redundant_pattern_matching_poll.rs delete mode 100644 tests/ui/redundant_pattern_matching_poll.stderr delete mode 100644 tests/ui/redundant_pattern_matching_result.fixed delete mode 100644 tests/ui/redundant_pattern_matching_result.rs delete mode 100644 tests/ui/redundant_pattern_matching_result.stderr delete mode 100644 tests/ui/redundant_pub_crate.fixed delete mode 100644 tests/ui/redundant_pub_crate.rs delete mode 100644 tests/ui/redundant_pub_crate.stderr delete mode 100644 tests/ui/redundant_static_lifetimes.fixed delete mode 100644 tests/ui/redundant_static_lifetimes.rs delete mode 100644 tests/ui/redundant_static_lifetimes.stderr delete mode 100644 tests/ui/redundant_static_lifetimes_multiple.rs delete mode 100644 tests/ui/redundant_static_lifetimes_multiple.stderr delete mode 100644 tests/ui/ref_option_ref.rs delete mode 100644 tests/ui/ref_option_ref.stderr delete mode 100644 tests/ui/regex.rs delete mode 100644 tests/ui/regex.stderr delete mode 100644 tests/ui/rename.fixed delete mode 100644 tests/ui/rename.rs delete mode 100644 tests/ui/rename.stderr delete mode 100644 tests/ui/renamed_builtin_attr.fixed delete mode 100644 tests/ui/renamed_builtin_attr.rs delete mode 100644 tests/ui/renamed_builtin_attr.stderr delete mode 100644 tests/ui/repeat_once.fixed delete mode 100644 tests/ui/repeat_once.rs delete mode 100644 tests/ui/repeat_once.stderr delete mode 100644 tests/ui/repl_uninit.rs delete mode 100644 tests/ui/repl_uninit.stderr delete mode 100644 tests/ui/rest_pat_in_fully_bound_structs.rs delete mode 100644 tests/ui/rest_pat_in_fully_bound_structs.stderr delete mode 100644 tests/ui/result_map_or_into_option.fixed delete mode 100644 tests/ui/result_map_or_into_option.rs delete mode 100644 tests/ui/result_map_or_into_option.stderr delete mode 100644 tests/ui/result_map_unit_fn_fixable.fixed delete mode 100644 tests/ui/result_map_unit_fn_fixable.rs delete mode 100644 tests/ui/result_map_unit_fn_fixable.stderr delete mode 100644 tests/ui/result_map_unit_fn_unfixable.rs delete mode 100644 tests/ui/result_map_unit_fn_unfixable.stderr delete mode 100644 tests/ui/result_unit_error.rs delete mode 100644 tests/ui/result_unit_error.stderr delete mode 100644 tests/ui/reversed_empty_ranges_fixable.fixed delete mode 100644 tests/ui/reversed_empty_ranges_fixable.rs delete mode 100644 tests/ui/reversed_empty_ranges_fixable.stderr delete mode 100644 tests/ui/reversed_empty_ranges_loops_fixable.fixed delete mode 100644 tests/ui/reversed_empty_ranges_loops_fixable.rs delete mode 100644 tests/ui/reversed_empty_ranges_loops_fixable.stderr delete mode 100644 tests/ui/reversed_empty_ranges_loops_unfixable.rs delete mode 100644 tests/ui/reversed_empty_ranges_loops_unfixable.stderr delete mode 100644 tests/ui/reversed_empty_ranges_unfixable.rs delete mode 100644 tests/ui/reversed_empty_ranges_unfixable.stderr delete mode 100644 tests/ui/same_functions_in_if_condition.rs delete mode 100644 tests/ui/same_functions_in_if_condition.stderr delete mode 100644 tests/ui/same_item_push.rs delete mode 100644 tests/ui/same_item_push.stderr delete mode 100644 tests/ui/search_is_some.rs delete mode 100644 tests/ui/search_is_some.stderr delete mode 100644 tests/ui/search_is_some_fixable.fixed delete mode 100644 tests/ui/search_is_some_fixable.rs delete mode 100644 tests/ui/search_is_some_fixable.stderr delete mode 100644 tests/ui/self_assignment.rs delete mode 100644 tests/ui/self_assignment.stderr delete mode 100644 tests/ui/serde.rs delete mode 100644 tests/ui/serde.stderr delete mode 100644 tests/ui/shadow.rs delete mode 100644 tests/ui/shadow.stderr delete mode 100644 tests/ui/short_circuit_statement.fixed delete mode 100644 tests/ui/short_circuit_statement.rs delete mode 100644 tests/ui/short_circuit_statement.stderr delete mode 100644 tests/ui/should_impl_trait/corner_cases.rs delete mode 100644 tests/ui/should_impl_trait/method_list_1.rs delete mode 100644 tests/ui/should_impl_trait/method_list_1.stderr delete mode 100644 tests/ui/should_impl_trait/method_list_2.rs delete mode 100644 tests/ui/should_impl_trait/method_list_2.stderr delete mode 100644 tests/ui/similar_names.rs delete mode 100644 tests/ui/similar_names.stderr delete mode 100644 tests/ui/single_char_add_str.fixed delete mode 100644 tests/ui/single_char_add_str.rs delete mode 100644 tests/ui/single_char_add_str.stderr delete mode 100644 tests/ui/single_char_pattern.fixed delete mode 100644 tests/ui/single_char_pattern.rs delete mode 100644 tests/ui/single_char_pattern.stderr delete mode 100644 tests/ui/single_component_path_imports.fixed delete mode 100644 tests/ui/single_component_path_imports.rs delete mode 100644 tests/ui/single_component_path_imports.stderr delete mode 100644 tests/ui/single_element_loop.fixed delete mode 100644 tests/ui/single_element_loop.rs delete mode 100644 tests/ui/single_element_loop.stderr delete mode 100644 tests/ui/single_match.rs delete mode 100644 tests/ui/single_match.stderr delete mode 100644 tests/ui/single_match_else.rs delete mode 100644 tests/ui/single_match_else.stderr delete mode 100644 tests/ui/size_of_in_element_count.rs delete mode 100644 tests/ui/size_of_in_element_count.stderr delete mode 100644 tests/ui/skip_while_next.rs delete mode 100644 tests/ui/skip_while_next.stderr delete mode 100644 tests/ui/slow_vector_initialization.rs delete mode 100644 tests/ui/slow_vector_initialization.stderr delete mode 100644 tests/ui/stable_sort_primitive.fixed delete mode 100644 tests/ui/stable_sort_primitive.rs delete mode 100644 tests/ui/stable_sort_primitive.stderr delete mode 100644 tests/ui/starts_ends_with.fixed delete mode 100644 tests/ui/starts_ends_with.rs delete mode 100644 tests/ui/starts_ends_with.stderr delete mode 100644 tests/ui/str_to_string.rs delete mode 100644 tests/ui/str_to_string.stderr delete mode 100644 tests/ui/string_add.rs delete mode 100644 tests/ui/string_add.stderr delete mode 100644 tests/ui/string_add_assign.fixed delete mode 100644 tests/ui/string_add_assign.rs delete mode 100644 tests/ui/string_add_assign.stderr delete mode 100644 tests/ui/string_extend.fixed delete mode 100644 tests/ui/string_extend.rs delete mode 100644 tests/ui/string_extend.stderr delete mode 100644 tests/ui/string_from_utf8_as_bytes.fixed delete mode 100644 tests/ui/string_from_utf8_as_bytes.rs delete mode 100644 tests/ui/string_from_utf8_as_bytes.stderr delete mode 100644 tests/ui/string_lit_as_bytes.fixed delete mode 100644 tests/ui/string_lit_as_bytes.rs delete mode 100644 tests/ui/string_lit_as_bytes.stderr delete mode 100644 tests/ui/string_to_string.rs delete mode 100644 tests/ui/string_to_string.stderr delete mode 100644 tests/ui/struct_excessive_bools.rs delete mode 100644 tests/ui/struct_excessive_bools.stderr delete mode 100644 tests/ui/suspicious_arithmetic_impl.rs delete mode 100644 tests/ui/suspicious_arithmetic_impl.stderr delete mode 100644 tests/ui/suspicious_else_formatting.rs delete mode 100644 tests/ui/suspicious_else_formatting.stderr delete mode 100644 tests/ui/suspicious_map.rs delete mode 100644 tests/ui/suspicious_map.stderr delete mode 100644 tests/ui/suspicious_operation_groupings.rs delete mode 100644 tests/ui/suspicious_operation_groupings.stderr delete mode 100644 tests/ui/suspicious_unary_op_formatting.rs delete mode 100644 tests/ui/suspicious_unary_op_formatting.stderr delete mode 100644 tests/ui/swap.fixed delete mode 100644 tests/ui/swap.rs delete mode 100644 tests/ui/swap.stderr delete mode 100644 tests/ui/tabs_in_doc_comments.fixed delete mode 100644 tests/ui/tabs_in_doc_comments.rs delete mode 100644 tests/ui/tabs_in_doc_comments.stderr delete mode 100644 tests/ui/temporary_assignment.rs delete mode 100644 tests/ui/temporary_assignment.stderr delete mode 100644 tests/ui/to_digit_is_some.fixed delete mode 100644 tests/ui/to_digit_is_some.rs delete mode 100644 tests/ui/to_digit_is_some.stderr delete mode 100644 tests/ui/to_string_in_display.rs delete mode 100644 tests/ui/to_string_in_display.stderr delete mode 100644 tests/ui/toplevel_ref_arg.fixed delete mode 100644 tests/ui/toplevel_ref_arg.rs delete mode 100644 tests/ui/toplevel_ref_arg.stderr delete mode 100644 tests/ui/toplevel_ref_arg_non_rustfix.rs delete mode 100644 tests/ui/toplevel_ref_arg_non_rustfix.stderr delete mode 100644 tests/ui/trailing_zeros.rs delete mode 100644 tests/ui/trailing_zeros.stderr delete mode 100644 tests/ui/trait_duplication_in_bounds.rs delete mode 100644 tests/ui/trait_duplication_in_bounds.stderr delete mode 100644 tests/ui/transmute.rs delete mode 100644 tests/ui/transmute.stderr delete mode 100644 tests/ui/transmute_32bit.rs delete mode 100644 tests/ui/transmute_32bit.stderr delete mode 100644 tests/ui/transmute_64bit.rs delete mode 100644 tests/ui/transmute_64bit.stderr delete mode 100644 tests/ui/transmute_collection.rs delete mode 100644 tests/ui/transmute_collection.stderr delete mode 100644 tests/ui/transmute_float_to_int.rs delete mode 100644 tests/ui/transmute_float_to_int.stderr delete mode 100644 tests/ui/transmute_ptr_to_ptr.rs delete mode 100644 tests/ui/transmute_ptr_to_ptr.stderr delete mode 100644 tests/ui/transmute_ptr_to_ref.rs delete mode 100644 tests/ui/transmute_ptr_to_ref.stderr delete mode 100644 tests/ui/transmutes_expressible_as_ptr_casts.fixed delete mode 100644 tests/ui/transmutes_expressible_as_ptr_casts.rs delete mode 100644 tests/ui/transmutes_expressible_as_ptr_casts.stderr delete mode 100644 tests/ui/transmuting_null.rs delete mode 100644 tests/ui/transmuting_null.stderr delete mode 100644 tests/ui/trivially_copy_pass_by_ref.rs delete mode 100644 tests/ui/trivially_copy_pass_by_ref.stderr delete mode 100644 tests/ui/try_err.fixed delete mode 100644 tests/ui/try_err.rs delete mode 100644 tests/ui/try_err.stderr delete mode 100644 tests/ui/ty_fn_sig.rs delete mode 100644 tests/ui/type_repetition_in_bounds.rs delete mode 100644 tests/ui/type_repetition_in_bounds.stderr delete mode 100644 tests/ui/types.fixed delete mode 100644 tests/ui/types.rs delete mode 100644 tests/ui/types.stderr delete mode 100644 tests/ui/undropped_manually_drops.rs delete mode 100644 tests/ui/undropped_manually_drops.stderr delete mode 100644 tests/ui/unicode.rs delete mode 100644 tests/ui/unicode.stderr delete mode 100644 tests/ui/uninit.rs delete mode 100644 tests/ui/uninit.stderr delete mode 100644 tests/ui/unit_arg.rs delete mode 100644 tests/ui/unit_arg.stderr delete mode 100644 tests/ui/unit_arg_empty_blocks.rs delete mode 100644 tests/ui/unit_arg_empty_blocks.stderr delete mode 100644 tests/ui/unit_cmp.rs delete mode 100644 tests/ui/unit_cmp.stderr delete mode 100644 tests/ui/unit_return_expecting_ord.rs delete mode 100644 tests/ui/unit_return_expecting_ord.stderr delete mode 100644 tests/ui/unknown_attribute.rs delete mode 100644 tests/ui/unknown_attribute.stderr delete mode 100644 tests/ui/unknown_clippy_lints.fixed delete mode 100644 tests/ui/unknown_clippy_lints.rs delete mode 100644 tests/ui/unknown_clippy_lints.stderr delete mode 100644 tests/ui/unnecessary_cast.rs delete mode 100644 tests/ui/unnecessary_cast.stderr delete mode 100644 tests/ui/unnecessary_cast_fixable.fixed delete mode 100644 tests/ui/unnecessary_cast_fixable.rs delete mode 100644 tests/ui/unnecessary_cast_fixable.stderr delete mode 100644 tests/ui/unnecessary_clone.rs delete mode 100644 tests/ui/unnecessary_clone.stderr delete mode 100644 tests/ui/unnecessary_filter_map.rs delete mode 100644 tests/ui/unnecessary_filter_map.stderr delete mode 100644 tests/ui/unnecessary_flat_map.fixed delete mode 100644 tests/ui/unnecessary_flat_map.rs delete mode 100644 tests/ui/unnecessary_flat_map.stderr delete mode 100644 tests/ui/unnecessary_fold.fixed delete mode 100644 tests/ui/unnecessary_fold.rs delete mode 100644 tests/ui/unnecessary_fold.stderr delete mode 100644 tests/ui/unnecessary_lazy_eval.fixed delete mode 100644 tests/ui/unnecessary_lazy_eval.rs delete mode 100644 tests/ui/unnecessary_lazy_eval.stderr delete mode 100644 tests/ui/unnecessary_lazy_eval_unfixable.rs delete mode 100644 tests/ui/unnecessary_lazy_eval_unfixable.stderr delete mode 100644 tests/ui/unnecessary_operation.fixed delete mode 100644 tests/ui/unnecessary_operation.rs delete mode 100644 tests/ui/unnecessary_operation.stderr delete mode 100644 tests/ui/unnecessary_ref.fixed delete mode 100644 tests/ui/unnecessary_ref.rs delete mode 100644 tests/ui/unnecessary_ref.stderr delete mode 100644 tests/ui/unnecessary_sort_by.fixed delete mode 100644 tests/ui/unnecessary_sort_by.rs delete mode 100644 tests/ui/unnecessary_sort_by.stderr delete mode 100644 tests/ui/unnecessary_wraps.rs delete mode 100644 tests/ui/unnecessary_wraps.stderr delete mode 100644 tests/ui/unneeded_field_pattern.rs delete mode 100644 tests/ui/unneeded_field_pattern.stderr delete mode 100644 tests/ui/unneeded_wildcard_pattern.fixed delete mode 100644 tests/ui/unneeded_wildcard_pattern.rs delete mode 100644 tests/ui/unneeded_wildcard_pattern.stderr delete mode 100644 tests/ui/unnested_or_patterns.fixed delete mode 100644 tests/ui/unnested_or_patterns.rs delete mode 100644 tests/ui/unnested_or_patterns.stderr delete mode 100644 tests/ui/unnested_or_patterns2.fixed delete mode 100644 tests/ui/unnested_or_patterns2.rs delete mode 100644 tests/ui/unnested_or_patterns2.stderr delete mode 100644 tests/ui/unnested_or_patterns3.rs delete mode 100644 tests/ui/unreadable_literal.fixed delete mode 100644 tests/ui/unreadable_literal.rs delete mode 100644 tests/ui/unreadable_literal.stderr delete mode 100644 tests/ui/unsafe_derive_deserialize.rs delete mode 100644 tests/ui/unsafe_derive_deserialize.stderr delete mode 100644 tests/ui/unsafe_removed_from_name.rs delete mode 100644 tests/ui/unsafe_removed_from_name.stderr delete mode 100644 tests/ui/unseparated_prefix_literals.fixed delete mode 100644 tests/ui/unseparated_prefix_literals.rs delete mode 100644 tests/ui/unseparated_prefix_literals.stderr delete mode 100644 tests/ui/unused_io_amount.rs delete mode 100644 tests/ui/unused_io_amount.stderr delete mode 100644 tests/ui/unused_self.rs delete mode 100644 tests/ui/unused_self.stderr delete mode 100644 tests/ui/unused_unit.fixed delete mode 100644 tests/ui/unused_unit.rs delete mode 100644 tests/ui/unused_unit.stderr delete mode 100644 tests/ui/unwrap.rs delete mode 100644 tests/ui/unwrap.stderr delete mode 100644 tests/ui/unwrap_in_result.rs delete mode 100644 tests/ui/unwrap_in_result.stderr delete mode 100644 tests/ui/unwrap_or.rs delete mode 100644 tests/ui/unwrap_or.stderr delete mode 100755 tests/ui/update-all-references.sh delete mode 100644 tests/ui/use_self.fixed delete mode 100644 tests/ui/use_self.rs delete mode 100644 tests/ui/use_self.stderr delete mode 100644 tests/ui/use_self_trait.fixed delete mode 100644 tests/ui/use_self_trait.rs delete mode 100644 tests/ui/use_self_trait.stderr delete mode 100644 tests/ui/used_underscore_binding.rs delete mode 100644 tests/ui/used_underscore_binding.stderr delete mode 100644 tests/ui/useful_asref.rs delete mode 100644 tests/ui/useless_asref.fixed delete mode 100644 tests/ui/useless_asref.rs delete mode 100644 tests/ui/useless_asref.stderr delete mode 100644 tests/ui/useless_attribute.fixed delete mode 100644 tests/ui/useless_attribute.rs delete mode 100644 tests/ui/useless_attribute.stderr delete mode 100644 tests/ui/useless_conversion.fixed delete mode 100644 tests/ui/useless_conversion.rs delete mode 100644 tests/ui/useless_conversion.stderr delete mode 100644 tests/ui/useless_conversion_try.rs delete mode 100644 tests/ui/useless_conversion_try.stderr delete mode 100644 tests/ui/vec.fixed delete mode 100644 tests/ui/vec.rs delete mode 100644 tests/ui/vec.stderr delete mode 100644 tests/ui/vec_box_sized.fixed delete mode 100644 tests/ui/vec_box_sized.rs delete mode 100644 tests/ui/vec_box_sized.stderr delete mode 100644 tests/ui/vec_resize_to_zero.rs delete mode 100644 tests/ui/vec_resize_to_zero.stderr delete mode 100644 tests/ui/verbose_file_reads.rs delete mode 100644 tests/ui/verbose_file_reads.stderr delete mode 100644 tests/ui/vtable_address_comparisons.rs delete mode 100644 tests/ui/vtable_address_comparisons.stderr delete mode 100644 tests/ui/while_let_loop.rs delete mode 100644 tests/ui/while_let_loop.stderr delete mode 100644 tests/ui/while_let_on_iterator.fixed delete mode 100644 tests/ui/while_let_on_iterator.rs delete mode 100644 tests/ui/while_let_on_iterator.stderr delete mode 100644 tests/ui/wild_in_or_pats.rs delete mode 100644 tests/ui/wild_in_or_pats.stderr delete mode 100644 tests/ui/wildcard_enum_match_arm.fixed delete mode 100644 tests/ui/wildcard_enum_match_arm.rs delete mode 100644 tests/ui/wildcard_enum_match_arm.stderr delete mode 100644 tests/ui/wildcard_imports.fixed delete mode 100644 tests/ui/wildcard_imports.rs delete mode 100644 tests/ui/wildcard_imports.stderr delete mode 100644 tests/ui/write_literal.rs delete mode 100644 tests/ui/write_literal.stderr delete mode 100644 tests/ui/write_with_newline.rs delete mode 100644 tests/ui/write_with_newline.stderr delete mode 100644 tests/ui/writeln_empty_string.fixed delete mode 100644 tests/ui/writeln_empty_string.rs delete mode 100644 tests/ui/writeln_empty_string.stderr delete mode 100644 tests/ui/wrong_self_convention.rs delete mode 100644 tests/ui/wrong_self_convention.stderr delete mode 100644 tests/ui/zero_div_zero.rs delete mode 100644 tests/ui/zero_div_zero.stderr delete mode 100644 tests/ui/zero_offset.rs delete mode 100644 tests/ui/zero_offset.stderr delete mode 100644 tests/ui/zero_ptr.fixed delete mode 100644 tests/ui/zero_ptr.rs delete mode 100644 tests/ui/zero_ptr.stderr delete mode 100644 tests/ui/zero_sized_btreemap_values.rs delete mode 100644 tests/ui/zero_sized_btreemap_values.stderr delete mode 100644 tests/ui/zero_sized_hashmap_values.rs delete mode 100644 tests/ui/zero_sized_hashmap_values.stderr delete mode 100644 tests/versioncheck.rs delete mode 100644 triagebot.toml delete mode 100755 util/cov.sh delete mode 100755 util/export.py delete mode 100755 util/fetch_prs_between.sh delete mode 100644 util/gh-pages/index.html delete mode 100644 util/gh-pages/versions.html delete mode 100644 util/lintlib.py delete mode 100755 util/versions.py diff --git a/.cargo/config b/.cargo/config deleted file mode 100644 index e70da43ab47a..000000000000 --- a/.cargo/config +++ /dev/null @@ -1,6 +0,0 @@ -[alias] -uitest = "test --test compile-test" -dev = "run --target-dir clippy_dev/target --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --" - -[build] -rustflags = ["-Zunstable-options"] diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index a13173544d80..000000000000 --- a/.editorconfig +++ /dev/null @@ -1,19 +0,0 @@ -# EditorConfig helps developers define and maintain consistent -# coding styles between different editors and IDEs -# editorconfig.org - -root = true - -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true -indent_style = space -indent_size = 4 - -[*.md] -trim_trailing_whitespace = false - -[*.yml] -indent_size = 2 diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 90cf33053c77..000000000000 --- a/.gitattributes +++ /dev/null @@ -1,3 +0,0 @@ -* text=auto eol=lf -*.rs text eol=lf whitespace=tab-in-indent,trailing-space,tabwidth=4 -*.fixed linguist-language=Rust diff --git a/.github/ISSUE_TEMPLATE/blank_issue.md b/.github/ISSUE_TEMPLATE/blank_issue.md deleted file mode 100644 index 9aef3ebe637a..000000000000 --- a/.github/ISSUE_TEMPLATE/blank_issue.md +++ /dev/null @@ -1,4 +0,0 @@ ---- -name: Blank Issue -about: Create a blank issue. ---- diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index d8f0c44148ca..000000000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,47 +0,0 @@ ---- -name: Bug Report -about: Create a bug report for Clippy -labels: L-bug ---- - - -I tried this code: - -```rust - -``` - -I expected to see this happen: *explanation* - -Instead, this happened: *explanation* - -### Meta - -- `cargo clippy -V`: e.g. clippy 0.0.212 (f455e46 2020-06-20) -- `rustc -Vv`: - ``` - rustc 1.46.0-nightly (f455e46ea 2020-06-20) - binary: rustc - commit-hash: f455e46eae1a227d735091091144601b467e1565 - commit-date: 2020-06-20 - host: x86_64-unknown-linux-gnu - release: 1.46.0-nightly - LLVM version: 10.0 - ``` - - -
Backtrace -

- - ``` - - ``` - -

-
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml deleted file mode 100644 index bd7dc0ac95c1..000000000000 --- a/.github/ISSUE_TEMPLATE/config.yml +++ /dev/null @@ -1,5 +0,0 @@ -blank_issues_enabled: true -contact_links: - - name: Rust Programming Language Forum - url: https://users.rust-lang.org - about: Please ask and answer questions about Rust here. diff --git a/.github/ISSUE_TEMPLATE/ice.md b/.github/ISSUE_TEMPLATE/ice.md deleted file mode 100644 index 3abe76bf2c49..000000000000 --- a/.github/ISSUE_TEMPLATE/ice.md +++ /dev/null @@ -1,53 +0,0 @@ ---- -name: Internal Compiler Error -about: Create a report for an internal compiler error in Clippy. -labels: L-bug, L-crash ---- - - -### Code - -```rust - -``` - -### Meta - -- `cargo clippy -V`: e.g. clippy 0.0.212 (f455e46 2020-06-20) -- `rustc -Vv`: - ``` - rustc 1.46.0-nightly (f455e46ea 2020-06-20) - binary: rustc - commit-hash: f455e46eae1a227d735091091144601b467e1565 - commit-date: 2020-06-20 - host: x86_64-unknown-linux-gnu - release: 1.46.0-nightly - LLVM version: 10.0 - ``` - -### Error output - -``` - -``` - - -
Backtrace -

- - ``` - - ``` - -

-
diff --git a/.github/ISSUE_TEMPLATE/new_lint.md b/.github/ISSUE_TEMPLATE/new_lint.md deleted file mode 100644 index 98fd0df685fd..000000000000 --- a/.github/ISSUE_TEMPLATE/new_lint.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -name: New lint suggestion -about: Suggest a new Clippy lint. -labels: L-lint ---- - -### What it does - -*What does this lint do?* - -### Categories (optional) - -- Kind: *See for list of lint kinds* - -*What is the advantage of the recommended code over the original code* - -For example: -- Remove bounce checking inserted by ... -- Remove the need to duplicating/storing/typo ... - -### Drawbacks - -None. - -### Example - -```rust - -``` - -Could be written as: - -```rust - -``` diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a3f114e0bb34..000000000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,32 +0,0 @@ -Thank you for making Clippy better! - -We're collecting our changelog from pull request descriptions. -If your PR only includes internal changes, you can just write -`changelog: none`. Otherwise, please write a short comment -explaining your change. - -If your PR fixes an issue, you can add "fixes #issue_number" into this -PR description. This way the issue will be automatically closed when -your PR is merged. - -If you added a new lint, here's a checklist for things that will be -checked during review or continuous integration. - -- \[ ] Followed [lint naming conventions][lint_naming] -- \[ ] Added passing UI tests (including committed `.stderr` file) -- \[ ] `cargo test` passes locally -- \[ ] Executed `cargo dev update_lints` -- \[ ] Added lint documentation -- \[ ] Run `cargo dev fmt` - -[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints - -Note that you can skip the above if you are just opening a WIP PR in -order to get feedback. - -Delete this line and everything above before opening your PR. - ---- - -*Please write a short comment explaining your change (or "none" for internal only changes)* -changelog: diff --git a/.github/deploy.sh b/.github/deploy.sh deleted file mode 100644 index e85e8874ba60..000000000000 --- a/.github/deploy.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash - -set -ex - -echo "Removing the current docs for master" -rm -rf out/master/ || exit 0 - -echo "Making the docs for master" -mkdir out/master/ -cp util/gh-pages/index.html out/master -python3 ./util/export.py out/master/lints.json - -if [[ -n $TAG_NAME ]]; then - echo "Save the doc for the current tag ($TAG_NAME) and point stable/ to it" - cp -r out/master "out/$TAG_NAME" - rm -f out/stable - ln -s "$TAG_NAME" out/stable -fi - -if [[ $BETA = "true" ]]; then - echo "Update documentation for the beta release" - cp -r out/master/* out/beta -fi - -# Generate version index that is shown as root index page -cp util/gh-pages/versions.html out/index.html - -echo "Making the versions.json file" -python3 ./util/versions.py out - -cd out -# Now let's go have some fun with the cloned repo -git config user.name "GHA CI" -git config user.email "gha@ci.invalid" - -if [[ -n $TAG_NAME ]]; then - # track files, so that the following check works - git add --intent-to-add "$TAG_NAME" - if git diff --exit-code --quiet -- $TAG_NAME/; then - echo "No changes to the output on this push; exiting." - exit 0 - fi - # Add the new dir - git add "$TAG_NAME" - # Update the symlink - git add stable - # Update versions file - git add versions.json - git commit -m "Add documentation for ${TAG_NAME} release: ${SHA}" -elif [[ $BETA = "true" ]]; then - if git diff --exit-code --quiet -- beta/; then - echo "No changes to the output on this push; exiting." - exit 0 - fi - git add beta - git commit -m "Automatic deploy to GitHub Pages (beta): ${SHA}" -else - if git diff --exit-code --quiet; then - echo "No changes to the output on this push; exiting." - exit 0 - fi - git add . - git commit -m "Automatic deploy to GitHub Pages: ${SHA}" -fi - -git push "$SSH_REPO" "$TARGET_BRANCH" diff --git a/.github/driver.sh b/.github/driver.sh deleted file mode 100644 index 6ff189fc8592..000000000000 --- a/.github/driver.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -set -ex - -# Check sysroot handling -sysroot=$(./target/debug/clippy-driver --print sysroot) -test "$sysroot" = "$(rustc --print sysroot)" - -if [[ ${OS} == "Windows" ]]; then - desired_sysroot=C:/tmp -else - desired_sysroot=/tmp -fi -sysroot=$(./target/debug/clippy-driver --sysroot $desired_sysroot --print sysroot) -test "$sysroot" = $desired_sysroot - -sysroot=$(SYSROOT=$desired_sysroot ./target/debug/clippy-driver --print sysroot) -test "$sysroot" = $desired_sysroot - -# Make sure this isn't set - clippy-driver should cope without it -unset CARGO_MANIFEST_DIR - -# Run a lint and make sure it produces the expected output. It's also expected to exit with code 1 -# FIXME: How to match the clippy invocation in compile-test.rs? -./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/double_neg.rs 2>double_neg.stderr && exit 1 -sed -e "s,tests/ui,\$DIR," -e "/= help/d" double_neg.stderr >normalized.stderr -diff -u normalized.stderr tests/ui/double_neg.stderr - -# make sure "clippy-driver --rustc --arg" and "rustc --arg" behave the same -SYSROOT=$(rustc --print sysroot) -diff -u <(LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver --rustc --version --verbose) <(rustc --version --verbose) - -echo "fn main() {}" >target/driver_test.rs -# we can't run 2 rustcs on the same file at the same time -CLIPPY=$(LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver ./target/driver_test.rs --rustc) -RUSTC=$(rustc ./target/driver_test.rs) -diff -u <($CLIPPY) <($RUSTC) - -# TODO: CLIPPY_CONF_DIR / CARGO_MANIFEST_DIR diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml deleted file mode 100644 index 530e60001f72..000000000000 --- a/.github/workflows/clippy.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: Clippy Test - -on: - push: - # Ignore bors branches, since they are covered by `clippy_bors.yml` - branches-ignore: - - auto - - try - # Don't run Clippy tests, when only textfiles were modified - paths-ignore: - - 'COPYRIGHT' - - 'LICENSE-*' - - '**.md' - - '**.txt' - pull_request: - # Don't run Clippy tests, when only textfiles were modified - paths-ignore: - - 'COPYRIGHT' - - 'LICENSE-*' - - '**.md' - - '**.txt' - -env: - RUST_BACKTRACE: 1 - CARGO_TARGET_DIR: '${{ github.workspace }}/target' - NO_FMT_TEST: 1 - -jobs: - base: - runs-on: ubuntu-latest - - steps: - # Setup - - uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master - with: - github_token: "${{ secrets.github_token }}" - - - name: Checkout - uses: actions/checkout@v2.3.3 - - - name: Install toolchain - run: rustup show active-toolchain - - # Run - - name: Set LD_LIBRARY_PATH (Linux) - run: | - SYSROOT=$(rustc --print sysroot) - echo "LD_LIBRARY_PATH=${SYSROOT}/lib${LD_LIBRARY_PATH+:${LD_LIBRARY_PATH}}" >> $GITHUB_ENV - - - name: Build - run: cargo build --features deny-warnings,internal-lints - - - name: Test - run: cargo test --features deny-warnings,internal-lints - - - name: Test clippy_lints - run: cargo test --features deny-warnings,internal-lints - working-directory: clippy_lints - - - name: Test rustc_tools_util - run: cargo test --features deny-warnings - working-directory: rustc_tools_util - - - name: Test clippy_dev - run: cargo test --features deny-warnings - working-directory: clippy_dev - - - name: Test cargo-clippy - run: ../target/debug/cargo-clippy - working-directory: clippy_workspace_tests - - - name: Test clippy-driver - run: bash .github/driver.sh - env: - OS: ${{ runner.os }} - - - name: Test cargo dev new lint - run: | - cargo dev new_lint --name new_early_pass --pass early - cargo dev new_lint --name new_late_pass --pass late - cargo check - git reset --hard HEAD diff --git a/.github/workflows/clippy_bors.yml b/.github/workflows/clippy_bors.yml deleted file mode 100644 index 5d846eb64c78..000000000000 --- a/.github/workflows/clippy_bors.yml +++ /dev/null @@ -1,255 +0,0 @@ -name: Clippy Test (bors) - -on: - push: - branches: - - auto - - try - -env: - RUST_BACKTRACE: 1 - CARGO_TARGET_DIR: '${{ github.workspace }}/target' - NO_FMT_TEST: 1 - -defaults: - run: - shell: bash - -jobs: - changelog: - runs-on: ubuntu-latest - - steps: - - uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master - with: - github_token: "${{ secrets.github_token }}" - - - name: Checkout - uses: actions/checkout@v2.3.3 - with: - ref: ${{ github.ref }} - - # Run - - name: Check Changelog - run: | - MESSAGE=$(git log --format=%B -n 1) - PR=$(echo "$MESSAGE" | grep -o "#[0-9]*" | head -1 | sed -e 's/^#//') - output=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -s "https://api.github.com/repos/rust-lang/rust-clippy/pulls/$PR" | \ - python -c "import sys, json; print(json.load(sys.stdin)['body'])" | \ - grep "^changelog: " | \ - sed "s/changelog: //g") - if [[ -z "$output" ]]; then - echo "ERROR: PR body must contain 'changelog: ...'" - exit 1 - elif [[ "$output" = "none" ]]; then - echo "WARNING: changelog is 'none'" - fi - env: - PYTHONIOENCODING: 'utf-8' - base: - needs: changelog - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - host: [x86_64-unknown-linux-gnu, i686-unknown-linux-gnu, x86_64-apple-darwin, x86_64-pc-windows-msvc] - exclude: - - os: ubuntu-latest - host: x86_64-apple-darwin - - os: ubuntu-latest - host: x86_64-pc-windows-msvc - - os: macos-latest - host: x86_64-unknown-linux-gnu - - os: macos-latest - host: i686-unknown-linux-gnu - - os: macos-latest - host: x86_64-pc-windows-msvc - - os: windows-latest - host: x86_64-unknown-linux-gnu - - os: windows-latest - host: i686-unknown-linux-gnu - - os: windows-latest - host: x86_64-apple-darwin - - runs-on: ${{ matrix.os }} - - steps: - # Setup - - uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master - with: - github_token: "${{ secrets.github_token }}" - - - name: Install dependencies (Linux-i686) - run: | - sudo dpkg --add-architecture i386 - sudo apt-get update - sudo apt-get install gcc-multilib libssl-dev:i386 libgit2-dev:i386 - if: matrix.host == 'i686-unknown-linux-gnu' - - - name: Checkout - uses: actions/checkout@v2.3.3 - - - name: Install toolchain - run: rustup show active-toolchain - - # Run - - name: Set LD_LIBRARY_PATH (Linux) - if: runner.os == 'Linux' - run: | - SYSROOT=$(rustc --print sysroot) - echo "LD_LIBRARY_PATH=${SYSROOT}/lib${LD_LIBRARY_PATH+:${LD_LIBRARY_PATH}}" >> $GITHUB_ENV - - name: Link rustc dylib (MacOS) - if: runner.os == 'macOS' - run: | - SYSROOT=$(rustc --print sysroot) - sudo mkdir -p /usr/local/lib - sudo find "${SYSROOT}/lib" -maxdepth 1 -name '*dylib' -exec ln -s {} /usr/local/lib \; - - name: Set PATH (Windows) - if: runner.os == 'Windows' - run: | - SYSROOT=$(rustc --print sysroot) - echo "$SYSROOT/bin" >> $GITHUB_PATH - - - name: Build - run: cargo build --features deny-warnings,internal-lints - - - name: Test - run: cargo test --features deny-warnings,internal-lints - - - name: Test clippy_lints - run: cargo test --features deny-warnings,internal-lints - working-directory: clippy_lints - - - name: Test rustc_tools_util - run: cargo test --features deny-warnings - working-directory: rustc_tools_util - - - name: Test clippy_dev - run: cargo test --features deny-warnings - working-directory: clippy_dev - - - name: Test cargo-clippy - run: ../target/debug/cargo-clippy - working-directory: clippy_workspace_tests - - - name: Test clippy-driver - run: bash .github/driver.sh - env: - OS: ${{ runner.os }} - - integration_build: - needs: changelog - runs-on: ubuntu-latest - - steps: - # Setup - - uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master - with: - github_token: "${{ secrets.github_token }}" - - - name: Checkout - uses: actions/checkout@v2.3.3 - - - name: Install toolchain - run: rustup show active-toolchain - - # Run - - name: Build Integration Test - run: cargo test --test integration --features integration --no-run - - # Upload - - name: Extract Binaries - run: | - DIR=$CARGO_TARGET_DIR/debug - rm $DIR/deps/integration-*.d - mv $DIR/deps/integration-* $DIR/integration - find $DIR ! -executable -o -type d ! -path $DIR | xargs rm -rf - rm -rf $CARGO_TARGET_DIR/release - - - name: Upload Binaries - uses: actions/upload-artifact@v1 - with: - name: target - path: target - - integration: - needs: integration_build - strategy: - fail-fast: false - max-parallel: 6 - matrix: - integration: - - 'rust-lang/cargo' - # FIXME: re-enable once fmt_macros is renamed in RLS - # - 'rust-lang/rls' - - 'rust-lang/chalk' - - 'rust-lang/rustfmt' - - 'Marwes/combine' - - 'Geal/nom' - - 'rust-lang/stdarch' - - 'serde-rs/serde' - # FIXME: chrono currently cannot be compiled with `--all-targets` - # - 'chronotope/chrono' - - 'hyperium/hyper' - - 'rust-random/rand' - - 'rust-lang/futures-rs' - - 'rust-itertools/itertools' - - 'rust-lang-nursery/failure' - - 'rust-lang/log' - - runs-on: ubuntu-latest - - steps: - # Setup - - uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master - with: - github_token: "${{ secrets.github_token }}" - - - name: Checkout - uses: actions/checkout@v2.3.3 - - - name: Install toolchain - run: rustup show active-toolchain - - # Download - - name: Download target dir - uses: actions/download-artifact@v1 - with: - name: target - path: target - - - name: Make Binaries Executable - run: chmod +x $CARGO_TARGET_DIR/debug/* - - # Run - - name: Test ${{ matrix.integration }} - run: | - RUSTUP_TOOLCHAIN="$(rustup show active-toolchain | grep -o -E "nightly-[0-9]{4}-[0-9]{2}-[0-9]{2}")" \ - $CARGO_TARGET_DIR/debug/integration - env: - INTEGRATION: ${{ matrix.integration }} - - # These jobs doesn't actually test anything, but they're only used to tell - # bors the build completed, as there is no practical way to detect when a - # workflow is successful listening to webhooks only. - # - # ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB! - - end-success: - name: bors test finished - if: github.event.pusher.name == 'bors' && success() - runs-on: ubuntu-latest - needs: [changelog, base, integration_build, integration] - - steps: - - name: Mark the job as successful - run: exit 0 - - end-failure: - name: bors test finished - if: github.event.pusher.name == 'bors' && (failure() || cancelled()) - runs-on: ubuntu-latest - needs: [changelog, base, integration_build, integration] - - steps: - - name: Mark the job as a failure - run: exit 1 diff --git a/.github/workflows/clippy_dev.yml b/.github/workflows/clippy_dev.yml deleted file mode 100644 index 95da775b7bc3..000000000000 --- a/.github/workflows/clippy_dev.yml +++ /dev/null @@ -1,78 +0,0 @@ -name: Clippy Dev Test - -on: - push: - branches: - - auto - - try - pull_request: - # Only run on paths, that get checked by the clippy_dev tool - paths: - - 'CHANGELOG.md' - - 'README.md' - - '**.stderr' - - '**.rs' - -env: - RUST_BACKTRACE: 1 - -jobs: - clippy_dev: - runs-on: ubuntu-latest - - steps: - # Setup - - name: Checkout - uses: actions/checkout@v2.3.3 - - - name: remove toolchain file - run: rm rust-toolchain - - - name: rust-toolchain - uses: actions-rs/toolchain@v1.0.6 - with: - toolchain: nightly - target: x86_64-unknown-linux-gnu - profile: minimal - components: rustfmt - default: true - - # Run - - name: Build - run: cargo build --features deny-warnings - working-directory: clippy_dev - - - name: Test limit_stderr_length - run: cargo dev limit_stderr_length - - - name: Test update_lints - run: cargo dev update_lints --check - - - name: Test fmt - run: cargo dev fmt --check - - # These jobs doesn't actually test anything, but they're only used to tell - # bors the build completed, as there is no practical way to detect when a - # workflow is successful listening to webhooks only. - # - # ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB! - - end-success: - name: bors dev test finished - if: github.event.pusher.name == 'bors' && success() - runs-on: ubuntu-latest - needs: [clippy_dev] - - steps: - - name: Mark the job as successful - run: exit 0 - - end-failure: - name: bors dev test finished - if: github.event.pusher.name == 'bors' && (failure() || cancelled()) - runs-on: ubuntu-latest - needs: [clippy_dev] - - steps: - - name: Mark the job as a failure - run: exit 1 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 15aeaf907dc6..000000000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: Deploy - -on: - push: - branches: - - master - - beta - tags: - - rust-1.** - -env: - TARGET_BRANCH: 'gh-pages' - SHA: '${{ github.sha }}' - SSH_REPO: 'git@github.com:${{ github.repository }}.git' - -jobs: - deploy: - runs-on: ubuntu-latest - if: github.repository == 'rust-lang/rust-clippy' - - steps: - # Setup - - name: Checkout - uses: actions/checkout@v2.3.3 - - - name: Checkout - uses: actions/checkout@v2.3.3 - with: - ref: ${{ env.TARGET_BRANCH }} - path: 'out' - - # Run - - name: Set tag name - if: startswith(github.ref, 'refs/tags/') - run: | - TAG=$(basename ${{ github.ref }}) - echo "TAG_NAME=$TAG" >> $GITHUB_ENV - - name: Set beta to true - if: github.ref == 'refs/heads/beta' - run: echo "BETA=true" >> $GITHUB_ENV - - - name: Use scripts and templates from master branch - run: | - git fetch --no-tags --prune --depth=1 origin master - git checkout origin/master -- .github/deploy.sh util/gh-pages/ util/*.py - - - name: Deploy - run: | - eval "$(ssh-agent -s)" - ssh-add - <<< "${{ secrets.DEPLOY_KEY }}" - bash .github/deploy.sh diff --git a/.github/workflows/remark.yml b/.github/workflows/remark.yml deleted file mode 100644 index 4f25a86b2e4d..000000000000 --- a/.github/workflows/remark.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: Remark - -on: - push: - branches: - - auto - - try - pull_request: - paths: - - '**.md' - -jobs: - remark: - runs-on: ubuntu-latest - - steps: - # Setup - - name: Checkout - uses: actions/checkout@v2.3.3 - - - name: Setup Node.js - uses: actions/setup-node@v1.4.4 - - - name: Install remark - run: npm install remark-cli remark-lint remark-lint-maximum-line-length remark-preset-lint-recommended - - # Run - - name: Check *.md files - run: git ls-files -z '*.md' | xargs -0 -n 1 -I {} ./node_modules/.bin/remark {} -u lint -f > /dev/null - - # These jobs doesn't actually test anything, but they're only used to tell - # bors the build completed, as there is no practical way to detect when a - # workflow is successful listening to webhooks only. - # - # ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB! - - end-success: - name: bors remark test finished - if: github.event.pusher.name == 'bors' && success() - runs-on: ubuntu-latest - needs: [remark] - - steps: - - name: Mark the job as successful - run: exit 0 - - end-failure: - name: bors remark test finished - if: github.event.pusher.name == 'bors' && (failure() || cancelled()) - runs-on: ubuntu-latest - needs: [remark] - - steps: - - name: Mark the job as a failure - run: exit 1 diff --git a/.gitignore b/.gitignore deleted file mode 100644 index adf5e8feddf4..000000000000 --- a/.gitignore +++ /dev/null @@ -1,37 +0,0 @@ -# Used by CI to be able to push: -/.github/deploy_key -out - -# Compiled files -*.o -*.d -*.so -*.rlib -*.dll -*.pyc -*.rmeta - -# Executables -*.exe - -# Generated by Cargo -*Cargo.lock -/target -/clippy_lints/target -/clippy_workspace_tests/target -/clippy_dev/target -/rustc_tools_util/target - -# Generated by dogfood -/target_recur/ - -# gh pages docs -util/gh-pages/lints.json - -# rustfmt backups -*.rs.bk - -helper.txt -*.iml -.vscode -.idea diff --git a/.remarkrc b/.remarkrc deleted file mode 100644 index 0ede7ac75cb6..000000000000 --- a/.remarkrc +++ /dev/null @@ -1,12 +0,0 @@ -{ - "plugins": [ - "remark-preset-lint-recommended", - ["remark-lint-list-item-indent", false], - ["remark-lint-no-literal-urls", false], - ["remark-lint-no-shortcut-reference-link", false], - ["remark-lint-maximum-line-length", 120] - ], - "settings": { - "commonmark": true - } -} diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index af3b1c1db2ae..000000000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,2176 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. -See [Changelog Update](doc/changelog_update.md) if you want to update this -document. - -## Unreleased / In Rust Nightly - -[b20d4c1...master](https://github.com/rust-lang/rust-clippy/compare/b20d4c1...master) - -## Rust 1.49 - -Current beta, release 2020-12-31 - -[e636b88...b20d4c1](https://github.com/rust-lang/rust-clippy/compare/e636b88...b20d4c1) - -### New Lints - -* [`field_reassign_with_default`] [#5911](https://github.com/rust-lang/rust-clippy/pull/5911) -* [`await_holding_refcell_ref`] [#6029](https://github.com/rust-lang/rust-clippy/pull/6029) -* [`disallowed_method`] [#6081](https://github.com/rust-lang/rust-clippy/pull/6081) -* [`inline_asm_x86_att_syntax`] [#6092](https://github.com/rust-lang/rust-clippy/pull/6092) -* [`inline_asm_x86_intel_syntax`] [#6092](https://github.com/rust-lang/rust-clippy/pull/6092) -* [`from_iter_instead_of_collect`] [#6101](https://github.com/rust-lang/rust-clippy/pull/6101) -* [`mut_mutex_lock`] [#6103](https://github.com/rust-lang/rust-clippy/pull/6103) -* [`single_element_loop`] [#6109](https://github.com/rust-lang/rust-clippy/pull/6109) -* [`manual_unwrap_or`] [#6123](https://github.com/rust-lang/rust-clippy/pull/6123) -* [`large_types_passed_by_value`] [#6135](https://github.com/rust-lang/rust-clippy/pull/6135) -* [`result_unit_err`] [#6157](https://github.com/rust-lang/rust-clippy/pull/6157) -* [`ref_option_ref`] [#6165](https://github.com/rust-lang/rust-clippy/pull/6165) -* [`manual_range_contains`] [#6177](https://github.com/rust-lang/rust-clippy/pull/6177) -* [`unusual_byte_groupings`] [#6183](https://github.com/rust-lang/rust-clippy/pull/6183) -* [`comparison_to_empty`] [#6226](https://github.com/rust-lang/rust-clippy/pull/6226) -* [`map_collect_result_unit`] [#6227](https://github.com/rust-lang/rust-clippy/pull/6227) -* [`manual_ok_or`] [#6233](https://github.com/rust-lang/rust-clippy/pull/6233) - -### Moves and Deprecations - -* Rename `single_char_push_str` to [`single_char_add_str`] - [#6037](https://github.com/rust-lang/rust-clippy/pull/6037) -* Rename `zero_width_space` to [`invisible_characters`] - [#6105](https://github.com/rust-lang/rust-clippy/pull/6105) -* Deprecate [`drop_bounds`] (uplifted) - [#6111](https://github.com/rust-lang/rust-clippy/pull/6111) -* Move [`string_lit_as_bytes`] to `nursery` - [#6117](https://github.com/rust-lang/rust-clippy/pull/6117) -* Move [`rc_buffer`] to `restriction` - [#6128](https://github.com/rust-lang/rust-clippy/pull/6128) - -### Enhancements - -* [`manual_memcpy`]: Also lint when there are loop counters (and produce a - reliable suggestion) - [#5727](https://github.com/rust-lang/rust-clippy/pull/5727) -* [`single_char_add_str`]: Also lint on `String::insert_str` - [#6037](https://github.com/rust-lang/rust-clippy/pull/6037) -* [`invisible_characters`]: Also lint the characters `\u{AD}` and `\u{2060}` - [#6105](https://github.com/rust-lang/rust-clippy/pull/6105) -* [`eq_op`]: Also lint on the `assert_*!` macro family - [#6167](https://github.com/rust-lang/rust-clippy/pull/6167) -* [`items_after_statements`]: Also lint in local macro expansions - [#6176](https://github.com/rust-lang/rust-clippy/pull/6176) -* [`unnecessary_cast`]: Also lint casts on integer and float literals - [#6187](https://github.com/rust-lang/rust-clippy/pull/6187) -* [`manual_unwrap_or`]: Also lint `Result::unwrap_or` - [#6190](https://github.com/rust-lang/rust-clippy/pull/6190) -* [`match_like_matches_macro`]: Also lint when `match` has more than two arms - [#6216](https://github.com/rust-lang/rust-clippy/pull/6216) -* [`integer_arithmetic`]: Better handle `/` an `%` operators - [#6229](https://github.com/rust-lang/rust-clippy/pull/6229) - -### False Positive Fixes - -* [`needless_lifetimes`]: Bail out if the function has a `where` clause with the - lifetime [#5978](https://github.com/rust-lang/rust-clippy/pull/5978) -* [`explicit_counter_loop`]: No longer lints, when loop counter is used after it - is incremented [#6076](https://github.com/rust-lang/rust-clippy/pull/6076) -* [`or_fun_call`]: Revert changes addressing the handling of `const fn` - [#6077](https://github.com/rust-lang/rust-clippy/pull/6077) -* [`needless_range_loop`]: No longer lints, when the iterable is used in the - range [#6102](https://github.com/rust-lang/rust-clippy/pull/6102) -* [`inconsistent_digit_grouping`]: Fix bug when using floating point exponent - [#6104](https://github.com/rust-lang/rust-clippy/pull/6104) -* [`mistyped_literal_suffixes`]: No longer lints on the fractional part of a - float (e.g. `713.32_64`) - [#6114](https://github.com/rust-lang/rust-clippy/pull/6114) -* [`invalid_regex`]: No longer lint on unicode characters within `bytes::Regex` - [#6132](https://github.com/rust-lang/rust-clippy/pull/6132) -* [`boxed_local`]: No longer lints on `extern fn` arguments - [#6133](https://github.com/rust-lang/rust-clippy/pull/6133) -* [`needless_lifetimes`]: Fix regression, where lifetime is used in `where` - clause [#6198](https://github.com/rust-lang/rust-clippy/pull/6198) - -### Suggestion Fixes/Improvements - -* [`unnecessary_sort_by`]: Avoid dereferencing the suggested closure parameter - [#6078](https://github.com/rust-lang/rust-clippy/pull/6078) -* [`needless_arbitrary_self_type`]: Correctly handle expanded code - [#6093](https://github.com/rust-lang/rust-clippy/pull/6093) -* [`useless_format`]: Preserve raw strings in suggestion - [#6151](https://github.com/rust-lang/rust-clippy/pull/6151) -* [`empty_loop`]: Suggest alternatives - [#6162](https://github.com/rust-lang/rust-clippy/pull/6162) -* [`borrowed_box`]: Correctly add parentheses in suggestion - [#6200](https://github.com/rust-lang/rust-clippy/pull/6200) -* [`unused_unit`]: Improve suggestion formatting - [#6247](https://github.com/rust-lang/rust-clippy/pull/6247) - -### Documentation Improvements - -* Some doc improvements: - * [`rc_buffer`] [#6090](https://github.com/rust-lang/rust-clippy/pull/6090) - * [`empty_loop`] [#6162](https://github.com/rust-lang/rust-clippy/pull/6162) -* [`doc_markdown`]: Document problematic link text style - [#6107](https://github.com/rust-lang/rust-clippy/pull/6107) - -## Rust 1.48 - -Current stable, released 2020-11-19 - -[09bd400...e636b88](https://github.com/rust-lang/rust-clippy/compare/09bd400...e636b88) - -### New lints - -* [`self_assignment`] [#5894](https://github.com/rust-lang/rust-clippy/pull/5894) -* [`unnecessary_lazy_evaluations`] [#5720](https://github.com/rust-lang/rust-clippy/pull/5720) -* [`manual_strip`] [#6038](https://github.com/rust-lang/rust-clippy/pull/6038) -* [`map_err_ignore`] [#5998](https://github.com/rust-lang/rust-clippy/pull/5998) -* [`rc_buffer`] [#6044](https://github.com/rust-lang/rust-clippy/pull/6044) -* [`to_string_in_display`] [#5831](https://github.com/rust-lang/rust-clippy/pull/5831) -* `single_char_push_str` [#5881](https://github.com/rust-lang/rust-clippy/pull/5881) - -### Moves and Deprecations - -* Downgrade [`verbose_bit_mask`] to pedantic - [#6036](https://github.com/rust-lang/rust-clippy/pull/6036) - -### Enhancements - -* Extend [`precedence`] to handle chains of methods combined with unary negation - [#5928](https://github.com/rust-lang/rust-clippy/pull/5928) -* [`useless_vec`]: add a configuration value for the maximum allowed size on the stack - [#5907](https://github.com/rust-lang/rust-clippy/pull/5907) -* [`suspicious_arithmetic_impl`]: extend to implementations of `BitAnd`, `BitOr`, `BitXor`, `Rem`, `Shl`, and `Shr` - [#5884](https://github.com/rust-lang/rust-clippy/pull/5884) -* [`invalid_atomic_ordering`]: detect misuse of `compare_exchange`, `compare_exchange_weak`, and `fetch_update` - [#6025](https://github.com/rust-lang/rust-clippy/pull/6025) -* Avoid [`redundant_pattern_matching`] triggering in macros - [#6069](https://github.com/rust-lang/rust-clippy/pull/6069) -* [`option_if_let_else`]: distinguish pure from impure `else` expressions - [#5937](https://github.com/rust-lang/rust-clippy/pull/5937) -* [`needless_doctest_main`]: parse doctests instead of using textual search - [#5912](https://github.com/rust-lang/rust-clippy/pull/5912) -* [`wildcard_imports`]: allow `prelude` to appear in any segment of an import - [#5929](https://github.com/rust-lang/rust-clippy/pull/5929) -* Re-enable [`len_zero`] for ranges now that `range_is_empty` is stable - [#5961](https://github.com/rust-lang/rust-clippy/pull/5961) -* [`option_as_ref_deref`]: catch fully-qualified calls to `Deref::deref` and `DerefMut::deref_mut` - [#5933](https://github.com/rust-lang/rust-clippy/pull/5933) - -### False Positive Fixes - -* [`useless_attribute`]: permit allowing [`wildcard_imports`] and [`enum_glob_use`] - [#5994](https://github.com/rust-lang/rust-clippy/pull/5994) -* [`transmute_ptr_to_ptr`]: avoid suggesting dereferencing raw pointers in const contexts - [#5999](https://github.com/rust-lang/rust-clippy/pull/5999) -* [`redundant_closure_call`]: take into account usages of the closure in nested functions and closures - [#5920](https://github.com/rust-lang/rust-clippy/pull/5920) -* Fix false positive in [`borrow_interior_mutable_const`] when referencing a field behind a pointer - [#5949](https://github.com/rust-lang/rust-clippy/pull/5949) -* [`doc_markdown`]: allow using "GraphQL" without backticks - [#5996](https://github.com/rust-lang/rust-clippy/pull/5996) -* [`to_string_in_display`]: avoid linting when calling `to_string()` on anything that is not `self` - [#5971](https://github.com/rust-lang/rust-clippy/pull/5971) -* [`indexing_slicing`] and [`out_of_bounds_indexing`] treat references to arrays as arrays - [#6034](https://github.com/rust-lang/rust-clippy/pull/6034) -* [`should_implement_trait`]: ignore methods with lifetime parameters - [#5725](https://github.com/rust-lang/rust-clippy/pull/5725) -* [`needless_return`]: avoid linting if a temporary borrows a local variable - [#5903](https://github.com/rust-lang/rust-clippy/pull/5903) -* Restrict [`unnecessary_sort_by`] to non-reference, Copy types - [#6006](https://github.com/rust-lang/rust-clippy/pull/6006) -* Avoid suggesting `from_bits`/`to_bits` in const contexts in [`transmute_int_to_float`] - [#5919](https://github.com/rust-lang/rust-clippy/pull/5919) -* [`declare_interior_mutable_const`] and [`borrow_interior_mutable_const`]: improve detection of interior mutable types - [#6046](https://github.com/rust-lang/rust-clippy/pull/6046) - -### Suggestion Fixes/Improvements - -* [`let_and_return`]: add a cast to the suggestion when the return expression has adjustments - [#5946](https://github.com/rust-lang/rust-clippy/pull/5946) -* [`useless_conversion`]: show the type in the error message - [#6035](https://github.com/rust-lang/rust-clippy/pull/6035) -* [`unnecessary_mut_passed`]: discriminate between functions and methods in the error message - [#5892](https://github.com/rust-lang/rust-clippy/pull/5892) -* [`float_cmp`] and [`float_cmp_const`]: change wording to make margin of error less ambiguous - [#6043](https://github.com/rust-lang/rust-clippy/pull/6043) -* [`default_trait_access`]: do not use unnecessary type parameters in the suggestion - [#5993](https://github.com/rust-lang/rust-clippy/pull/5993) -* [`collapsible_if`]: don't use expanded code in the suggestion - [#5992](https://github.com/rust-lang/rust-clippy/pull/5992) -* Do not suggest empty format strings in [`print_with_newline`] and [`write_with_newline`] - [#6042](https://github.com/rust-lang/rust-clippy/pull/6042) -* [`unit_arg`]: improve the readability of the suggestion - [#5931](https://github.com/rust-lang/rust-clippy/pull/5931) -* [`stable_sort_primitive`]: print the type that is being sorted in the lint message - [#5935](https://github.com/rust-lang/rust-clippy/pull/5935) -* Show line count and max lines in [`too_many_lines`] lint message - [#6009](https://github.com/rust-lang/rust-clippy/pull/6009) -* Keep parentheses in the suggestion of [`useless_conversion`] where applicable - [#5900](https://github.com/rust-lang/rust-clippy/pull/5900) -* [`option_map_unit_fn`] and [`result_map_unit_fn`]: print the unit type `()` explicitly - [#6024](https://github.com/rust-lang/rust-clippy/pull/6024) -* [`redundant_allocation`]: suggest replacing `Rc>` with `Rc` - [#5899](https://github.com/rust-lang/rust-clippy/pull/5899) -* Make lint messages adhere to rustc dev guide conventions - [#5893](https://github.com/rust-lang/rust-clippy/pull/5893) - -### ICE Fixes - -* Fix ICE in [`repeat_once`] - [#5948](https://github.com/rust-lang/rust-clippy/pull/5948) - -### Documentation Improvements - -* [`mutable_key_type`]: explain potential for false positives when the interior mutable type is not accessed in the `Hash` implementation - [#6019](https://github.com/rust-lang/rust-clippy/pull/6019) -* [`unnecessary_mut_passed`]: fix typo - [#5913](https://github.com/rust-lang/rust-clippy/pull/5913) -* Add example of false positive to [`ptr_arg`] docs. - [#5885](https://github.com/rust-lang/rust-clippy/pull/5885) -* [`box_vec`], [`vec_box`] and [`borrowed_box`]: add link to the documentation of `Box` - [#6023](https://github.com/rust-lang/rust-clippy/pull/6023) - -## Rust 1.47 - -Released 2020-10-08 - -[c2c07fa...09bd400](https://github.com/rust-lang/rust-clippy/compare/c2c07fa...09bd400) - -### New lints - -* [`derive_ord_xor_partial_ord`] [#5848](https://github.com/rust-lang/rust-clippy/pull/5848) -* [`trait_duplication_in_bounds`] [#5852](https://github.com/rust-lang/rust-clippy/pull/5852) -* [`map_identity`] [#5694](https://github.com/rust-lang/rust-clippy/pull/5694) -* [`unit_return_expecting_ord`] [#5737](https://github.com/rust-lang/rust-clippy/pull/5737) -* [`pattern_type_mismatch`] [#4841](https://github.com/rust-lang/rust-clippy/pull/4841) -* [`repeat_once`] [#5773](https://github.com/rust-lang/rust-clippy/pull/5773) -* [`same_item_push`] [#5825](https://github.com/rust-lang/rust-clippy/pull/5825) -* [`needless_arbitrary_self_type`] [#5869](https://github.com/rust-lang/rust-clippy/pull/5869) -* [`match_like_matches_macro`] [#5769](https://github.com/rust-lang/rust-clippy/pull/5769) -* [`stable_sort_primitive`] [#5809](https://github.com/rust-lang/rust-clippy/pull/5809) -* [`blanket_clippy_restriction_lints`] [#5750](https://github.com/rust-lang/rust-clippy/pull/5750) -* [`option_if_let_else`] [#5301](https://github.com/rust-lang/rust-clippy/pull/5301) - -### Moves and Deprecations - -* Deprecate [`regex_macro`] lint - [#5760](https://github.com/rust-lang/rust-clippy/pull/5760) -* Move [`range_minus_one`] to `pedantic` - [#5752](https://github.com/rust-lang/rust-clippy/pull/5752) - -### Enhancements - -* Improve [`needless_collect`] by catching `collect` calls followed by `iter` or `into_iter` calls - [#5837](https://github.com/rust-lang/rust-clippy/pull/5837) -* [`panic`], [`todo`], [`unimplemented`] and [`unreachable`] now detect calls with formatting - [#5811](https://github.com/rust-lang/rust-clippy/pull/5811) -* Detect more cases of [`suboptimal_flops`] and [`imprecise_flops`] - [#5443](https://github.com/rust-lang/rust-clippy/pull/5443) -* Handle asymmetrical implementations of `PartialEq` in [`cmp_owned`] - [#5701](https://github.com/rust-lang/rust-clippy/pull/5701) -* Make it possible to allow [`unsafe_derive_deserialize`] - [#5870](https://github.com/rust-lang/rust-clippy/pull/5870) -* Catch `ord.min(a).max(b)` where a < b in [`min_max`] - [#5871](https://github.com/rust-lang/rust-clippy/pull/5871) -* Make [`clone_on_copy`] suggestion machine applicable - [#5745](https://github.com/rust-lang/rust-clippy/pull/5745) -* Enable [`len_zero`] on ranges now that `is_empty` is stable on them - [#5961](https://github.com/rust-lang/rust-clippy/pull/5961) - -### False Positive Fixes - -* Avoid triggering [`or_fun_call`] with const fns that take no arguments - [#5889](https://github.com/rust-lang/rust-clippy/pull/5889) -* Fix [`redundant_closure_call`] false positive for closures that have multiple calls - [#5800](https://github.com/rust-lang/rust-clippy/pull/5800) -* Don't lint cases involving `ManuallyDrop` in [`redundant_clone`] - [#5824](https://github.com/rust-lang/rust-clippy/pull/5824) -* Treat a single expression the same as a single statement in the 2nd arm of a match in [`single_match_else`] - [#5771](https://github.com/rust-lang/rust-clippy/pull/5771) -* Don't trigger [`unnested_or_patterns`] if the feature `or_patterns` is not enabled - [#5758](https://github.com/rust-lang/rust-clippy/pull/5758) -* Avoid linting if key borrows in [`unnecessary_sort_by`] - [#5756](https://github.com/rust-lang/rust-clippy/pull/5756) -* Consider `Try` impl for `Poll` when generating suggestions in [`try_err`] - [#5857](https://github.com/rust-lang/rust-clippy/pull/5857) -* Take input lifetimes into account in `manual_async_fn` - [#5859](https://github.com/rust-lang/rust-clippy/pull/5859) -* Fix multiple false positives in [`type_repetition_in_bounds`] and add a configuration option - [#5761](https://github.com/rust-lang/rust-clippy/pull/5761) -* Limit the [`suspicious_arithmetic_impl`] lint to one binary operation - [#5820](https://github.com/rust-lang/rust-clippy/pull/5820) - -### Suggestion Fixes/Improvements - -* Improve readability of [`shadow_unrelated`] suggestion by truncating the RHS snippet - [#5788](https://github.com/rust-lang/rust-clippy/pull/5788) -* Suggest `filter_map` instead of `flat_map` when mapping to `Option` in [`map_flatten`] - [#5846](https://github.com/rust-lang/rust-clippy/pull/5846) -* Ensure suggestion is shown correctly for long method call chains in [`iter_nth_zero`] - [#5793](https://github.com/rust-lang/rust-clippy/pull/5793) -* Drop borrow operator in suggestions of [`redundant_pattern_matching`] - [#5815](https://github.com/rust-lang/rust-clippy/pull/5815) -* Add suggestion for [`iter_skip_next`] - [#5843](https://github.com/rust-lang/rust-clippy/pull/5843) -* Improve [`collapsible_if`] fix suggestion - [#5732](https://github.com/rust-lang/rust-clippy/pull/5732) - -### ICE Fixes - -* Fix ICE caused by [`needless_collect`] - [#5877](https://github.com/rust-lang/rust-clippy/pull/5877) -* Fix ICE caused by [`unnested_or_patterns`] - [#5784](https://github.com/rust-lang/rust-clippy/pull/5784) - -### Documentation Improvements - -* Fix grammar of [`await_holding_lock`] documentation - [#5748](https://github.com/rust-lang/rust-clippy/pull/5748) - -### Others - -* Make lints adhere to the rustc dev guide - [#5888](https://github.com/rust-lang/rust-clippy/pull/5888) - -## Rust 1.46 - -Released 2020-08-27 - -[7ea7cd1...c2c07fa](https://github.com/rust-lang/rust-clippy/compare/7ea7cd1...c2c07fa) - -### New lints - -* [`unnested_or_patterns`] [#5378](https://github.com/rust-lang/rust-clippy/pull/5378) -* [`iter_next_slice`] [#5597](https://github.com/rust-lang/rust-clippy/pull/5597) -* [`unnecessary_sort_by`] [#5623](https://github.com/rust-lang/rust-clippy/pull/5623) -* [`vec_resize_to_zero`] [#5637](https://github.com/rust-lang/rust-clippy/pull/5637) - -### Moves and Deprecations - -* Move [`cast_ptr_alignment`] to pedantic [#5667](https://github.com/rust-lang/rust-clippy/pull/5667) - -### Enhancements - -* Improve [`mem_replace_with_uninit`] lint [#5695](https://github.com/rust-lang/rust-clippy/pull/5695) - -### False Positive Fixes - -* [`len_zero`]: Avoid linting ranges when the `range_is_empty` feature is not enabled - [#5656](https://github.com/rust-lang/rust-clippy/pull/5656) -* [`let_and_return`]: Don't lint if a temporary borrow is involved - [#5680](https://github.com/rust-lang/rust-clippy/pull/5680) -* [`reversed_empty_ranges`]: Avoid linting `N..N` in for loop arguments in - [#5692](https://github.com/rust-lang/rust-clippy/pull/5692) -* [`if_same_then_else`]: Don't assume multiplication is always commutative - [#5702](https://github.com/rust-lang/rust-clippy/pull/5702) -* [`blacklisted_name`]: Remove `bar` from the default configuration - [#5712](https://github.com/rust-lang/rust-clippy/pull/5712) -* [`redundant_pattern_matching`]: Avoid suggesting non-`const fn` calls in const contexts - [#5724](https://github.com/rust-lang/rust-clippy/pull/5724) - -### Suggestion Fixes/Improvements - -* Fix suggestion of [`unit_arg`] lint, so that it suggest semantic equivalent code - [#4455](https://github.com/rust-lang/rust-clippy/pull/4455) -* Add auto applicable suggestion to [`macro_use_imports`] - [#5279](https://github.com/rust-lang/rust-clippy/pull/5279) - -### ICE Fixes - -* Fix ICE in the `consts` module of Clippy [#5709](https://github.com/rust-lang/rust-clippy/pull/5709) - -### Documentation Improvements - -* Improve code examples across multiple lints [#5664](https://github.com/rust-lang/rust-clippy/pull/5664) - -### Others - -* Introduce a `--rustc` flag to `clippy-driver`, which turns `clippy-driver` - into `rustc` and passes all the given arguments to `rustc`. This is especially - useful for tools that need the `rustc` version Clippy was compiled with, - instead of the Clippy version. E.g. `clippy-driver --rustc --version` will - print the output of `rustc --version`. - [#5178](https://github.com/rust-lang/rust-clippy/pull/5178) -* New issue templates now make it easier to complain if Clippy is too annoying - or not annoying enough! [#5735](https://github.com/rust-lang/rust-clippy/pull/5735) - -## Rust 1.45 - -Released 2020-07-16 - -[891e1a8...7ea7cd1](https://github.com/rust-lang/rust-clippy/compare/891e1a8...7ea7cd1) - -### New lints - -* [`match_wildcard_for_single_variants`] [#5582](https://github.com/rust-lang/rust-clippy/pull/5582) -* [`unsafe_derive_deserialize`] [#5493](https://github.com/rust-lang/rust-clippy/pull/5493) -* [`if_let_mutex`] [#5332](https://github.com/rust-lang/rust-clippy/pull/5332) -* [`mismatched_target_os`] [#5506](https://github.com/rust-lang/rust-clippy/pull/5506) -* [`await_holding_lock`] [#5439](https://github.com/rust-lang/rust-clippy/pull/5439) -* [`match_on_vec_items`] [#5522](https://github.com/rust-lang/rust-clippy/pull/5522) -* [`manual_async_fn`] [#5576](https://github.com/rust-lang/rust-clippy/pull/5576) -* [`reversed_empty_ranges`] [#5583](https://github.com/rust-lang/rust-clippy/pull/5583) -* [`manual_non_exhaustive`] [#5550](https://github.com/rust-lang/rust-clippy/pull/5550) - -### Moves and Deprecations - -* Downgrade [`match_bool`] to pedantic [#5408](https://github.com/rust-lang/rust-clippy/pull/5408) -* Downgrade [`match_wild_err_arm`] to pedantic and update help messages. [#5622](https://github.com/rust-lang/rust-clippy/pull/5622) -* Downgrade [`useless_let_if_seq`] to nursery. [#5599](https://github.com/rust-lang/rust-clippy/pull/5599) -* Generalize `option_and_then_some` and rename to [`bind_instead_of_map`]. [#5529](https://github.com/rust-lang/rust-clippy/pull/5529) -* Rename `identity_conversion` to [`useless_conversion`]. [#5568](https://github.com/rust-lang/rust-clippy/pull/5568) -* Merge `block_in_if_condition_expr` and `block_in_if_condition_stmt` into [`blocks_in_if_conditions`]. -[#5563](https://github.com/rust-lang/rust-clippy/pull/5563) -* Merge `option_map_unwrap_or`, `option_map_unwrap_or_else` and `result_map_unwrap_or_else` into [`map_unwrap_or`]. -[#5563](https://github.com/rust-lang/rust-clippy/pull/5563) -* Merge `option_unwrap_used` and `result_unwrap_used` into [`unwrap_used`]. -[#5563](https://github.com/rust-lang/rust-clippy/pull/5563) -* Merge `option_expect_used` and `result_expect_used` into [`expect_used`]. -[#5563](https://github.com/rust-lang/rust-clippy/pull/5563) -* Merge `for_loop_over_option` and `for_loop_over_result` into [`for_loops_over_fallibles`]. -[#5563](https://github.com/rust-lang/rust-clippy/pull/5563) - -### Enhancements - -* Avoid running cargo lints when not enabled to improve performance. [#5505](https://github.com/rust-lang/rust-clippy/pull/5505) -* Extend [`useless_conversion`] with `TryFrom` and `TryInto`. [#5631](https://github.com/rust-lang/rust-clippy/pull/5631) -* Lint also in type parameters and where clauses in [`unused_unit`]. [#5592](https://github.com/rust-lang/rust-clippy/pull/5592) -* Do not suggest deriving `Default` in [`new_without_default`]. [#5616](https://github.com/rust-lang/rust-clippy/pull/5616) - -### False Positive Fixes - -* [`while_let_on_iterator`] [#5525](https://github.com/rust-lang/rust-clippy/pull/5525) -* [`empty_line_after_outer_attr`] [#5609](https://github.com/rust-lang/rust-clippy/pull/5609) -* [`unnecessary_unwrap`] [#5558](https://github.com/rust-lang/rust-clippy/pull/5558) -* [`comparison_chain`] [#5596](https://github.com/rust-lang/rust-clippy/pull/5596) -* Don't trigger [`used_underscore_binding`] in await desugaring. [#5535](https://github.com/rust-lang/rust-clippy/pull/5535) -* Don't trigger [`borrowed_box`] on mutable references. [#5491](https://github.com/rust-lang/rust-clippy/pull/5491) -* Allow `1 << 0` in [`identity_op`]. [#5602](https://github.com/rust-lang/rust-clippy/pull/5602) -* Allow `use super::*;` glob imports in [`wildcard_imports`]. [#5564](https://github.com/rust-lang/rust-clippy/pull/5564) -* Whitelist more words in [`doc_markdown`]. [#5611](https://github.com/rust-lang/rust-clippy/pull/5611) -* Skip dev and build deps in [`multiple_crate_versions`]. [#5636](https://github.com/rust-lang/rust-clippy/pull/5636) -* Honor `allow` attribute on arguments in [`ptr_arg`]. [#5647](https://github.com/rust-lang/rust-clippy/pull/5647) -* Honor lint level attributes for [`redundant_field_names`], [`just_underscores_and_digits`], [`many_single_char_names`] -and [`similar_names`]. [#5651](https://github.com/rust-lang/rust-clippy/pull/5651) -* Ignore calls to `len` in [`or_fun_call`]. [#4429](https://github.com/rust-lang/rust-clippy/pull/4429) - -### Suggestion Improvements - -* Simplify suggestions in [`manual_memcpy`]. [#5536](https://github.com/rust-lang/rust-clippy/pull/5536) -* Fix suggestion in [`redundant_pattern_matching`] for macros. [#5511](https://github.com/rust-lang/rust-clippy/pull/5511) -* Avoid suggesting `copied()` for mutable references in [`map_clone`]. [#5530](https://github.com/rust-lang/rust-clippy/pull/5530) -* Improve help message for [`clone_double_ref`]. [#5547](https://github.com/rust-lang/rust-clippy/pull/5547) - -### ICE Fixes - -* Fix ICE caused in unwrap module. [#5590](https://github.com/rust-lang/rust-clippy/pull/5590) -* Fix ICE on rustc test issue-69020-assoc-const-arith-overflow.rs [#5499](https://github.com/rust-lang/rust-clippy/pull/5499) - -### Documentation - -* Clarify the documentation of [`unnecessary_mut_passed`]. [#5639](https://github.com/rust-lang/rust-clippy/pull/5639) -* Extend example for [`unneeded_field_pattern`]. [#5541](https://github.com/rust-lang/rust-clippy/pull/5541) - -## Rust 1.44 - -Released 2020-06-04 - -[204bb9b...891e1a8](https://github.com/rust-lang/rust-clippy/compare/204bb9b...891e1a8) - -### New lints - -* [`explicit_deref_methods`] [#5226](https://github.com/rust-lang/rust-clippy/pull/5226) -* [`implicit_saturating_sub`] [#5427](https://github.com/rust-lang/rust-clippy/pull/5427) -* [`macro_use_imports`] [#5230](https://github.com/rust-lang/rust-clippy/pull/5230) -* [`verbose_file_reads`] [#5272](https://github.com/rust-lang/rust-clippy/pull/5272) -* [`future_not_send`] [#5423](https://github.com/rust-lang/rust-clippy/pull/5423) -* [`redundant_pub_crate`] [#5319](https://github.com/rust-lang/rust-clippy/pull/5319) -* [`large_const_arrays`] [#5248](https://github.com/rust-lang/rust-clippy/pull/5248) -* [`result_map_or_into_option`] [#5415](https://github.com/rust-lang/rust-clippy/pull/5415) -* [`redundant_allocation`] [#5349](https://github.com/rust-lang/rust-clippy/pull/5349) -* [`fn_address_comparisons`] [#5294](https://github.com/rust-lang/rust-clippy/pull/5294) -* [`vtable_address_comparisons`] [#5294](https://github.com/rust-lang/rust-clippy/pull/5294) - - -### Moves and Deprecations - -* Deprecate [`replace_consts`] lint [#5380](https://github.com/rust-lang/rust-clippy/pull/5380) -* Move [`cognitive_complexity`] to nursery [#5428](https://github.com/rust-lang/rust-clippy/pull/5428) -* Move [`useless_transmute`] to nursery [#5364](https://github.com/rust-lang/rust-clippy/pull/5364) -* Downgrade [`inefficient_to_string`] to pedantic [#5412](https://github.com/rust-lang/rust-clippy/pull/5412) -* Downgrade [`option_option`] to pedantic [#5401](https://github.com/rust-lang/rust-clippy/pull/5401) -* Downgrade [`unreadable_literal`] to pedantic [#5419](https://github.com/rust-lang/rust-clippy/pull/5419) -* Downgrade [`let_unit_value`] to pedantic [#5409](https://github.com/rust-lang/rust-clippy/pull/5409) -* Downgrade [`trivially_copy_pass_by_ref`] to pedantic [#5410](https://github.com/rust-lang/rust-clippy/pull/5410) -* Downgrade [`implicit_hasher`] to pedantic [#5411](https://github.com/rust-lang/rust-clippy/pull/5411) - -### Enhancements - -* On _nightly_ you can now use `cargo clippy --fix -Z unstable-options` to - auto-fix lints that support this [#5363](https://github.com/rust-lang/rust-clippy/pull/5363) -* Make [`redundant_clone`] also trigger on cases where the cloned value is not - consumed. [#5304](https://github.com/rust-lang/rust-clippy/pull/5304) -* Expand [`integer_arithmetic`] to also disallow bit-shifting [#5430](https://github.com/rust-lang/rust-clippy/pull/5430) -* [`option_as_ref_deref`] now detects more deref cases [#5425](https://github.com/rust-lang/rust-clippy/pull/5425) -* [`large_enum_variant`] now report the sizes of the largest and second-largest variants [#5466](https://github.com/rust-lang/rust-clippy/pull/5466) -* [`bool_comparison`] now also checks for inequality comparisons that can be - written more concisely [#5365](https://github.com/rust-lang/rust-clippy/pull/5365) -* Expand [`clone_on_copy`] to work in method call arguments as well [#5441](https://github.com/rust-lang/rust-clippy/pull/5441) -* [`redundant_pattern_matching`] now also handles `while let` [#5483](https://github.com/rust-lang/rust-clippy/pull/5483) -* [`integer_arithmetic`] now also lints references of integers [#5329](https://github.com/rust-lang/rust-clippy/pull/5329) -* Expand [`float_cmp_const`] to also work on arrays [#5345](https://github.com/rust-lang/rust-clippy/pull/5345) -* Trigger [`map_flatten`] when map is called on an `Option` [#5473](https://github.com/rust-lang/rust-clippy/pull/5473) - -### False Positive Fixes - -* [`many_single_char_names`] [#5468](https://github.com/rust-lang/rust-clippy/pull/5468) -* [`should_implement_trait`] [#5437](https://github.com/rust-lang/rust-clippy/pull/5437) -* [`unused_self`] [#5387](https://github.com/rust-lang/rust-clippy/pull/5387) -* [`redundant_clone`] [#5453](https://github.com/rust-lang/rust-clippy/pull/5453) -* [`precedence`] [#5445](https://github.com/rust-lang/rust-clippy/pull/5445) -* [`suspicious_op_assign_impl`] [#5424](https://github.com/rust-lang/rust-clippy/pull/5424) -* [`needless_lifetimes`] [#5293](https://github.com/rust-lang/rust-clippy/pull/5293) -* [`redundant_pattern`] [#5287](https://github.com/rust-lang/rust-clippy/pull/5287) -* [`inconsistent_digit_grouping`] [#5451](https://github.com/rust-lang/rust-clippy/pull/5451) - - -### Suggestion Improvements - -* Improved [`question_mark`] lint suggestion so that it doesn't add redundant `as_ref()` [#5481](https://github.com/rust-lang/rust-clippy/pull/5481) -* Improve the suggested placeholder in [`option_map_unit_fn`] [#5292](https://github.com/rust-lang/rust-clippy/pull/5292) -* Improve suggestion for [`match_single_binding`] when triggered inside a closure [#5350](https://github.com/rust-lang/rust-clippy/pull/5350) - -### ICE Fixes - -* Handle the unstable `trivial_bounds` feature [#5296](https://github.com/rust-lang/rust-clippy/pull/5296) -* `shadow_*` lints [#5297](https://github.com/rust-lang/rust-clippy/pull/5297) - -### Documentation - -* Fix documentation generation for configurable lints [#5353](https://github.com/rust-lang/rust-clippy/pull/5353) -* Update documentation for [`new_ret_no_self`] [#5448](https://github.com/rust-lang/rust-clippy/pull/5448) -* The documentation for [`option_option`] now suggest using a tri-state enum [#5403](https://github.com/rust-lang/rust-clippy/pull/5403) -* Fix bit mask example in [`verbose_bit_mask`] documentation [#5454](https://github.com/rust-lang/rust-clippy/pull/5454) -* [`wildcard_imports`] documentation now mentions that `use ...::prelude::*` is - not linted [#5312](https://github.com/rust-lang/rust-clippy/pull/5312) - -## Rust 1.43 - -Released 2020-04-23 - -[4ee1206...204bb9b](https://github.com/rust-lang/rust-clippy/compare/4ee1206...204bb9b) - -### New lints - -* [`imprecise_flops`] [#4897](https://github.com/rust-lang/rust-clippy/pull/4897) -* [`suboptimal_flops`] [#4897](https://github.com/rust-lang/rust-clippy/pull/4897) -* [`wildcard_imports`] [#5029](https://github.com/rust-lang/rust-clippy/pull/5029) -* [`single_component_path_imports`] [#5058](https://github.com/rust-lang/rust-clippy/pull/5058) -* [`match_single_binding`] [#5061](https://github.com/rust-lang/rust-clippy/pull/5061) -* [`let_underscore_lock`] [#5101](https://github.com/rust-lang/rust-clippy/pull/5101) -* [`struct_excessive_bools`] [#5125](https://github.com/rust-lang/rust-clippy/pull/5125) -* [`fn_params_excessive_bools`] [#5125](https://github.com/rust-lang/rust-clippy/pull/5125) -* [`option_env_unwrap`] [#5148](https://github.com/rust-lang/rust-clippy/pull/5148) -* [`lossy_float_literal`] [#5202](https://github.com/rust-lang/rust-clippy/pull/5202) -* [`rest_pat_in_fully_bound_structs`] [#5258](https://github.com/rust-lang/rust-clippy/pull/5258) - -### Moves and Deprecations - -* Move [`unneeded_field_pattern`] to pedantic group [#5200](https://github.com/rust-lang/rust-clippy/pull/5200) - -### Enhancements - -* Make [`missing_errors_doc`] lint also trigger on `async` functions - [#5181](https://github.com/rust-lang/rust-clippy/pull/5181) -* Add more constants to [`approx_constant`] [#5193](https://github.com/rust-lang/rust-clippy/pull/5193) -* Extend [`question_mark`] lint [#5266](https://github.com/rust-lang/rust-clippy/pull/5266) - -### False Positive Fixes - -* [`use_debug`] [#5047](https://github.com/rust-lang/rust-clippy/pull/5047) -* [`unnecessary_unwrap`] [#5132](https://github.com/rust-lang/rust-clippy/pull/5132) -* [`zero_prefixed_literal`] [#5170](https://github.com/rust-lang/rust-clippy/pull/5170) -* [`missing_const_for_fn`] [#5216](https://github.com/rust-lang/rust-clippy/pull/5216) - -### Suggestion Improvements - -* Improve suggestion when blocks of code are suggested [#5134](https://github.com/rust-lang/rust-clippy/pull/5134) - -### ICE Fixes - -* `misc_early` lints [#5129](https://github.com/rust-lang/rust-clippy/pull/5129) -* [`missing_errors_doc`] [#5213](https://github.com/rust-lang/rust-clippy/pull/5213) -* Fix ICE when evaluating `usize`s [#5256](https://github.com/rust-lang/rust-clippy/pull/5256) - -### Documentation - -* Improve documentation of [`iter_nth_zero`] -* Add documentation pages for stable releases [#5171](https://github.com/rust-lang/rust-clippy/pull/5171) - -### Others - -* Clippy now completely runs on GitHub Actions [#5190](https://github.com/rust-lang/rust-clippy/pull/5190) - - -## Rust 1.42 - -Released 2020-03-12 - -[69f99e7...4ee1206](https://github.com/rust-lang/rust-clippy/compare/69f99e7...4ee1206) - -### New lints - -* [`filetype_is_file`] [#4543](https://github.com/rust-lang/rust-clippy/pull/4543) -* [`let_underscore_must_use`] [#4823](https://github.com/rust-lang/rust-clippy/pull/4823) -* [`modulo_arithmetic`] [#4867](https://github.com/rust-lang/rust-clippy/pull/4867) -* [`mem_replace_with_default`] [#4881](https://github.com/rust-lang/rust-clippy/pull/4881) -* [`mutable_key_type`] [#4885](https://github.com/rust-lang/rust-clippy/pull/4885) -* [`option_as_ref_deref`] [#4945](https://github.com/rust-lang/rust-clippy/pull/4945) -* [`wildcard_in_or_patterns`] [#4960](https://github.com/rust-lang/rust-clippy/pull/4960) -* [`iter_nth_zero`] [#4966](https://github.com/rust-lang/rust-clippy/pull/4966) -* [`invalid_atomic_ordering`] [#4999](https://github.com/rust-lang/rust-clippy/pull/4999) -* [`skip_while_next`] [#5067](https://github.com/rust-lang/rust-clippy/pull/5067) - -### Moves and Deprecations - -* Move [`transmute_float_to_int`] from nursery to complexity group - [#5015](https://github.com/rust-lang/rust-clippy/pull/5015) -* Move [`range_plus_one`] to pedantic group [#5057](https://github.com/rust-lang/rust-clippy/pull/5057) -* Move [`debug_assert_with_mut_call`] to nursery group [#5106](https://github.com/rust-lang/rust-clippy/pull/5106) -* Deprecate [`unused_label`] [#4930](https://github.com/rust-lang/rust-clippy/pull/4930) - -### Enhancements - -* Lint vectored IO in [`unused_io_amount`] [#5027](https://github.com/rust-lang/rust-clippy/pull/5027) -* Make [`vec_box`] configurable by adding a size threshold [#5081](https://github.com/rust-lang/rust-clippy/pull/5081) -* Also lint constants in [`cmp_nan`] [#4910](https://github.com/rust-lang/rust-clippy/pull/4910) -* Fix false negative in [`expect_fun_call`] [#4915](https://github.com/rust-lang/rust-clippy/pull/4915) -* Fix false negative in [`redundant_clone`] [#5017](https://github.com/rust-lang/rust-clippy/pull/5017) - -### False Positive Fixes - -* [`map_clone`] [#4937](https://github.com/rust-lang/rust-clippy/pull/4937) -* [`replace_consts`] [#4977](https://github.com/rust-lang/rust-clippy/pull/4977) -* [`let_and_return`] [#5008](https://github.com/rust-lang/rust-clippy/pull/5008) -* [`eq_op`] [#5079](https://github.com/rust-lang/rust-clippy/pull/5079) -* [`possible_missing_comma`] [#5083](https://github.com/rust-lang/rust-clippy/pull/5083) -* [`debug_assert_with_mut_call`] [#5106](https://github.com/rust-lang/rust-clippy/pull/5106) -* Don't trigger [`let_underscore_must_use`] in external macros - [#5082](https://github.com/rust-lang/rust-clippy/pull/5082) -* Don't trigger [`empty_loop`] in `no_std` crates [#5086](https://github.com/rust-lang/rust-clippy/pull/5086) - -### Suggestion Improvements - -* `option_map_unwrap_or` [#4634](https://github.com/rust-lang/rust-clippy/pull/4634) -* [`wildcard_enum_match_arm`] [#4934](https://github.com/rust-lang/rust-clippy/pull/4934) -* [`cognitive_complexity`] [#4935](https://github.com/rust-lang/rust-clippy/pull/4935) -* [`decimal_literal_representation`] [#4956](https://github.com/rust-lang/rust-clippy/pull/4956) -* [`unknown_clippy_lints`] [#4963](https://github.com/rust-lang/rust-clippy/pull/4963) -* [`explicit_into_iter_loop`] [#4978](https://github.com/rust-lang/rust-clippy/pull/4978) -* [`useless_attribute`] [#5022](https://github.com/rust-lang/rust-clippy/pull/5022) -* [`if_let_some_result`] [#5032](https://github.com/rust-lang/rust-clippy/pull/5032) - -### ICE fixes - -* [`unsound_collection_transmute`] [#4975](https://github.com/rust-lang/rust-clippy/pull/4975) - -### Documentation - -* Improve documentation of [`empty_enum`], [`replace_consts`], [`redundant_clone`], and [`iterator_step_by_zero`] - - -## Rust 1.41 - -Released 2020-01-30 - -[c8e3cfb...69f99e7](https://github.com/rust-lang/rust-clippy/compare/c8e3cfb...69f99e7) - -* New Lints: - * [`exit`] [#4697](https://github.com/rust-lang/rust-clippy/pull/4697) - * [`to_digit_is_some`] [#4801](https://github.com/rust-lang/rust-clippy/pull/4801) - * [`tabs_in_doc_comments`] [#4806](https://github.com/rust-lang/rust-clippy/pull/4806) - * [`large_stack_arrays`] [#4807](https://github.com/rust-lang/rust-clippy/pull/4807) - * [`same_functions_in_if_condition`] [#4814](https://github.com/rust-lang/rust-clippy/pull/4814) - * [`zst_offset`] [#4816](https://github.com/rust-lang/rust-clippy/pull/4816) - * [`as_conversions`] [#4821](https://github.com/rust-lang/rust-clippy/pull/4821) - * [`missing_errors_doc`] [#4884](https://github.com/rust-lang/rust-clippy/pull/4884) - * [`transmute_float_to_int`] [#4889](https://github.com/rust-lang/rust-clippy/pull/4889) -* Remove plugin interface, see - [Inside Rust Blog](https://blog.rust-lang.org/inside-rust/2019/11/04/Clippy-removes-plugin-interface.html) for - details [#4714](https://github.com/rust-lang/rust-clippy/pull/4714) -* Move [`use_self`] to nursery group [#4863](https://github.com/rust-lang/rust-clippy/pull/4863) -* Deprecate [`into_iter_on_array`] [#4788](https://github.com/rust-lang/rust-clippy/pull/4788) -* Expand [`string_lit_as_bytes`] to also trigger when literal has escapes - [#4808](https://github.com/rust-lang/rust-clippy/pull/4808) -* Fix false positive in `comparison_chain` [#4842](https://github.com/rust-lang/rust-clippy/pull/4842) -* Fix false positive in `while_immutable_condition` [#4730](https://github.com/rust-lang/rust-clippy/pull/4730) -* Fix false positive in `explicit_counter_loop` [#4803](https://github.com/rust-lang/rust-clippy/pull/4803) -* Fix false positive in `must_use_candidate` [#4794](https://github.com/rust-lang/rust-clippy/pull/4794) -* Fix false positive in `print_with_newline` and `write_with_newline` - [#4769](https://github.com/rust-lang/rust-clippy/pull/4769) -* Fix false positive in `derive_hash_xor_eq` [#4766](https://github.com/rust-lang/rust-clippy/pull/4766) -* Fix false positive in `missing_inline_in_public_items` [#4870](https://github.com/rust-lang/rust-clippy/pull/4870) -* Fix false positive in `string_add` [#4880](https://github.com/rust-lang/rust-clippy/pull/4880) -* Fix false positive in `float_arithmetic` [#4851](https://github.com/rust-lang/rust-clippy/pull/4851) -* Fix false positive in `cast_sign_loss` [#4883](https://github.com/rust-lang/rust-clippy/pull/4883) -* Fix false positive in `manual_swap` [#4877](https://github.com/rust-lang/rust-clippy/pull/4877) -* Fix ICEs occurring while checking some block expressions [#4772](https://github.com/rust-lang/rust-clippy/pull/4772) -* Fix ICE in `use_self` [#4776](https://github.com/rust-lang/rust-clippy/pull/4776) -* Fix ICEs related to `const_generics` [#4780](https://github.com/rust-lang/rust-clippy/pull/4780) -* Display help when running `clippy-driver` without arguments, instead of ICEing - [#4810](https://github.com/rust-lang/rust-clippy/pull/4810) -* Clippy has its own ICE message now [#4588](https://github.com/rust-lang/rust-clippy/pull/4588) -* Show deprecated lints in the documentation again [#4757](https://github.com/rust-lang/rust-clippy/pull/4757) -* Improve Documentation by adding positive examples to some lints - [#4832](https://github.com/rust-lang/rust-clippy/pull/4832) - -## Rust 1.40 - -Released 2019-12-19 - -[4e7e71b...c8e3cfb](https://github.com/rust-lang/rust-clippy/compare/4e7e71b...c8e3cfb) - -* New Lints: - * [`unneeded_wildcard_pattern`] [#4537](https://github.com/rust-lang/rust-clippy/pull/4537) - * [`needless_doctest_main`] [#4603](https://github.com/rust-lang/rust-clippy/pull/4603) - * [`suspicious_unary_op_formatting`] [#4615](https://github.com/rust-lang/rust-clippy/pull/4615) - * [`debug_assert_with_mut_call`] [#4680](https://github.com/rust-lang/rust-clippy/pull/4680) - * [`unused_self`] [#4619](https://github.com/rust-lang/rust-clippy/pull/4619) - * [`inefficient_to_string`] [#4683](https://github.com/rust-lang/rust-clippy/pull/4683) - * [`must_use_unit`] [#4560](https://github.com/rust-lang/rust-clippy/pull/4560) - * [`must_use_candidate`] [#4560](https://github.com/rust-lang/rust-clippy/pull/4560) - * [`double_must_use`] [#4560](https://github.com/rust-lang/rust-clippy/pull/4560) - * [`comparison_chain`] [#4569](https://github.com/rust-lang/rust-clippy/pull/4569) - * [`unsound_collection_transmute`] [#4592](https://github.com/rust-lang/rust-clippy/pull/4592) - * [`panic`] [#4657](https://github.com/rust-lang/rust-clippy/pull/4657) - * [`unreachable`] [#4657](https://github.com/rust-lang/rust-clippy/pull/4657) - * [`todo`] [#4657](https://github.com/rust-lang/rust-clippy/pull/4657) - * `option_expect_used` [#4657](https://github.com/rust-lang/rust-clippy/pull/4657) - * `result_expect_used` [#4657](https://github.com/rust-lang/rust-clippy/pull/4657) -* Move `redundant_clone` to perf group [#4509](https://github.com/rust-lang/rust-clippy/pull/4509) -* Move `manual_mul_add` to nursery group [#4736](https://github.com/rust-lang/rust-clippy/pull/4736) -* Expand `unit_cmp` to also work with `assert_eq!`, `debug_assert_eq!`, `assert_ne!` and `debug_assert_ne!` [#4613](https://github.com/rust-lang/rust-clippy/pull/4613) -* Expand `integer_arithmetic` to also detect mutating arithmetic like `+=` [#4585](https://github.com/rust-lang/rust-clippy/pull/4585) -* Fix false positive in `nonminimal_bool` [#4568](https://github.com/rust-lang/rust-clippy/pull/4568) -* Fix false positive in `missing_safety_doc` [#4611](https://github.com/rust-lang/rust-clippy/pull/4611) -* Fix false positive in `cast_sign_loss` [#4614](https://github.com/rust-lang/rust-clippy/pull/4614) -* Fix false positive in `redundant_clone` [#4509](https://github.com/rust-lang/rust-clippy/pull/4509) -* Fix false positive in `try_err` [#4721](https://github.com/rust-lang/rust-clippy/pull/4721) -* Fix false positive in `toplevel_ref_arg` [#4570](https://github.com/rust-lang/rust-clippy/pull/4570) -* Fix false positive in `multiple_inherent_impl` [#4593](https://github.com/rust-lang/rust-clippy/pull/4593) -* Improve more suggestions and tests in preparation for the unstable `cargo fix --clippy` [#4575](https://github.com/rust-lang/rust-clippy/pull/4575) -* Improve suggestion for `zero_ptr` [#4599](https://github.com/rust-lang/rust-clippy/pull/4599) -* Improve suggestion for `explicit_counter_loop` [#4691](https://github.com/rust-lang/rust-clippy/pull/4691) -* Improve suggestion for `mul_add` [#4602](https://github.com/rust-lang/rust-clippy/pull/4602) -* Improve suggestion for `assertions_on_constants` [#4635](https://github.com/rust-lang/rust-clippy/pull/4635) -* Fix ICE in `use_self` [#4671](https://github.com/rust-lang/rust-clippy/pull/4671) -* Fix ICE when encountering const casts [#4590](https://github.com/rust-lang/rust-clippy/pull/4590) - -## Rust 1.39 - -Released 2019-11-07 - -[3aea860...4e7e71b](https://github.com/rust-lang/rust-clippy/compare/3aea860...4e7e71b) - -* New Lints: - * [`uninit_assumed_init`] [#4479](https://github.com/rust-lang/rust-clippy/pull/4479) - * [`flat_map_identity`] [#4231](https://github.com/rust-lang/rust-clippy/pull/4231) - * [`missing_safety_doc`] [#4535](https://github.com/rust-lang/rust-clippy/pull/4535) - * [`mem_replace_with_uninit`] [#4511](https://github.com/rust-lang/rust-clippy/pull/4511) - * [`suspicious_map`] [#4394](https://github.com/rust-lang/rust-clippy/pull/4394) - * `option_and_then_some` [#4386](https://github.com/rust-lang/rust-clippy/pull/4386) - * [`manual_saturating_arithmetic`] [#4498](https://github.com/rust-lang/rust-clippy/pull/4498) -* Deprecate `unused_collect` lint. This is fully covered by rustc's `#[must_use]` on `collect` [#4348](https://github.com/rust-lang/rust-clippy/pull/4348) -* Move `type_repetition_in_bounds` to pedantic group [#4403](https://github.com/rust-lang/rust-clippy/pull/4403) -* Move `cast_lossless` to pedantic group [#4539](https://github.com/rust-lang/rust-clippy/pull/4539) -* `temporary_cstring_as_ptr` now catches more cases [#4425](https://github.com/rust-lang/rust-clippy/pull/4425) -* `use_self` now works in constructors, too [#4525](https://github.com/rust-lang/rust-clippy/pull/4525) -* `cargo_common_metadata` now checks for license files [#4518](https://github.com/rust-lang/rust-clippy/pull/4518) -* `cognitive_complexity` now includes the measured complexity in the warning message [#4469](https://github.com/rust-lang/rust-clippy/pull/4469) -* Fix false positives in `block_in_if_*` lints [#4458](https://github.com/rust-lang/rust-clippy/pull/4458) -* Fix false positive in `cast_lossless` [#4473](https://github.com/rust-lang/rust-clippy/pull/4473) -* Fix false positive in `clone_on_copy` [#4411](https://github.com/rust-lang/rust-clippy/pull/4411) -* Fix false positive in `deref_addrof` [#4487](https://github.com/rust-lang/rust-clippy/pull/4487) -* Fix false positive in `too_many_lines` [#4490](https://github.com/rust-lang/rust-clippy/pull/4490) -* Fix false positive in `new_ret_no_self` [#4365](https://github.com/rust-lang/rust-clippy/pull/4365) -* Fix false positive in `manual_swap` [#4478](https://github.com/rust-lang/rust-clippy/pull/4478) -* Fix false positive in `missing_const_for_fn` [#4450](https://github.com/rust-lang/rust-clippy/pull/4450) -* Fix false positive in `extra_unused_lifetimes` [#4477](https://github.com/rust-lang/rust-clippy/pull/4477) -* Fix false positive in `inherent_to_string` [#4460](https://github.com/rust-lang/rust-clippy/pull/4460) -* Fix false positive in `map_entry` [#4495](https://github.com/rust-lang/rust-clippy/pull/4495) -* Fix false positive in `unused_unit` [#4445](https://github.com/rust-lang/rust-clippy/pull/4445) -* Fix false positive in `redundant_pattern` [#4489](https://github.com/rust-lang/rust-clippy/pull/4489) -* Fix false positive in `wrong_self_convention` [#4369](https://github.com/rust-lang/rust-clippy/pull/4369) -* Improve various suggestions and tests in preparation for the unstable `cargo fix --clippy` [#4558](https://github.com/rust-lang/rust-clippy/pull/4558) -* Improve suggestions for `redundant_pattern_matching` [#4352](https://github.com/rust-lang/rust-clippy/pull/4352) -* Improve suggestions for `explicit_write` [#4544](https://github.com/rust-lang/rust-clippy/pull/4544) -* Improve suggestion for `or_fun_call` [#4522](https://github.com/rust-lang/rust-clippy/pull/4522) -* Improve suggestion for `match_as_ref` [#4446](https://github.com/rust-lang/rust-clippy/pull/4446) -* Improve suggestion for `unnecessary_fold_span` [#4382](https://github.com/rust-lang/rust-clippy/pull/4382) -* Add suggestions for `unseparated_literal_suffix` [#4401](https://github.com/rust-lang/rust-clippy/pull/4401) -* Add suggestions for `char_lit_as_u8` [#4418](https://github.com/rust-lang/rust-clippy/pull/4418) - -## Rust 1.38 - -Released 2019-09-26 - -[e3cb40e...3aea860](https://github.com/rust-lang/rust-clippy/compare/e3cb40e...3aea860) - -* New Lints: - * [`main_recursion`] [#4203](https://github.com/rust-lang/rust-clippy/pull/4203) - * [`inherent_to_string`] [#4259](https://github.com/rust-lang/rust-clippy/pull/4259) - * [`inherent_to_string_shadow_display`] [#4259](https://github.com/rust-lang/rust-clippy/pull/4259) - * [`type_repetition_in_bounds`] [#3766](https://github.com/rust-lang/rust-clippy/pull/3766) - * [`try_err`] [#4222](https://github.com/rust-lang/rust-clippy/pull/4222) -* Move `{unnnecessary,panicking}_unwrap` out of nursery [#4307](https://github.com/rust-lang/rust-clippy/pull/4307) -* Extend the `use_self` lint to suggest uses of `Self::Variant` [#4308](https://github.com/rust-lang/rust-clippy/pull/4308) -* Improve suggestion for needless return [#4262](https://github.com/rust-lang/rust-clippy/pull/4262) -* Add auto-fixable suggestion for `let_unit` [#4337](https://github.com/rust-lang/rust-clippy/pull/4337) -* Fix false positive in `pub_enum_variant_names` and `enum_variant_names` [#4345](https://github.com/rust-lang/rust-clippy/pull/4345) -* Fix false positive in `cast_ptr_alignment` [#4257](https://github.com/rust-lang/rust-clippy/pull/4257) -* Fix false positive in `string_lit_as_bytes` [#4233](https://github.com/rust-lang/rust-clippy/pull/4233) -* Fix false positive in `needless_lifetimes` [#4266](https://github.com/rust-lang/rust-clippy/pull/4266) -* Fix false positive in `float_cmp` [#4275](https://github.com/rust-lang/rust-clippy/pull/4275) -* Fix false positives in `needless_return` [#4274](https://github.com/rust-lang/rust-clippy/pull/4274) -* Fix false negative in `match_same_arms` [#4246](https://github.com/rust-lang/rust-clippy/pull/4246) -* Fix incorrect suggestion for `needless_bool` [#4335](https://github.com/rust-lang/rust-clippy/pull/4335) -* Improve suggestion for `cast_ptr_alignment` [#4257](https://github.com/rust-lang/rust-clippy/pull/4257) -* Improve suggestion for `single_char_literal` [#4361](https://github.com/rust-lang/rust-clippy/pull/4361) -* Improve suggestion for `len_zero` [#4314](https://github.com/rust-lang/rust-clippy/pull/4314) -* Fix ICE in `implicit_hasher` [#4268](https://github.com/rust-lang/rust-clippy/pull/4268) -* Fix allow bug in `trivially_copy_pass_by_ref` [#4250](https://github.com/rust-lang/rust-clippy/pull/4250) - -## Rust 1.37 - -Released 2019-08-15 - -[082cfa7...e3cb40e](https://github.com/rust-lang/rust-clippy/compare/082cfa7...e3cb40e) - -* New Lints: - * [`checked_conversions`] [#4088](https://github.com/rust-lang/rust-clippy/pull/4088) - * [`get_last_with_len`] [#3832](https://github.com/rust-lang/rust-clippy/pull/3832) - * [`integer_division`] [#4195](https://github.com/rust-lang/rust-clippy/pull/4195) -* Renamed Lint: `const_static_lifetime` is now called [`redundant_static_lifetimes`]. - The lint now covers statics in addition to consts [#4162](https://github.com/rust-lang/rust-clippy/pull/4162) -* [`match_same_arms`] now warns for all identical arms, instead of only the first one [#4102](https://github.com/rust-lang/rust-clippy/pull/4102) -* [`needless_return`] now works with void functions [#4220](https://github.com/rust-lang/rust-clippy/pull/4220) -* Fix false positive in [`redundant_closure`] [#4190](https://github.com/rust-lang/rust-clippy/pull/4190) -* Fix false positive in [`useless_attribute`] [#4107](https://github.com/rust-lang/rust-clippy/pull/4107) -* Fix incorrect suggestion for [`float_cmp`] [#4214](https://github.com/rust-lang/rust-clippy/pull/4214) -* Add suggestions for [`print_with_newline`] and [`write_with_newline`] [#4136](https://github.com/rust-lang/rust-clippy/pull/4136) -* Improve suggestions for `option_map_unwrap_or_else` and `result_map_unwrap_or_else` [#4164](https://github.com/rust-lang/rust-clippy/pull/4164) -* Improve suggestions for [`non_ascii_literal`] [#4119](https://github.com/rust-lang/rust-clippy/pull/4119) -* Improve diagnostics for [`let_and_return`] [#4137](https://github.com/rust-lang/rust-clippy/pull/4137) -* Improve diagnostics for [`trivially_copy_pass_by_ref`] [#4071](https://github.com/rust-lang/rust-clippy/pull/4071) -* Add macro check for [`unreadable_literal`] [#4099](https://github.com/rust-lang/rust-clippy/pull/4099) - -## Rust 1.36 - -Released 2019-07-04 - -[eb9f9b1...082cfa7](https://github.com/rust-lang/rust-clippy/compare/eb9f9b1...082cfa7) - -* New lints: [`find_map`], [`filter_map_next`] [#4039](https://github.com/rust-lang/rust-clippy/pull/4039) -* New lint: [`path_buf_push_overwrite`] [#3954](https://github.com/rust-lang/rust-clippy/pull/3954) -* Move `path_buf_push_overwrite` to the nursery [#4013](https://github.com/rust-lang/rust-clippy/pull/4013) -* Split [`redundant_closure`] into [`redundant_closure`] and [`redundant_closure_for_method_calls`] [#4110](https://github.com/rust-lang/rust-clippy/pull/4101) -* Allow allowing of [`toplevel_ref_arg`] lint [#4007](https://github.com/rust-lang/rust-clippy/pull/4007) -* Fix false negative in [`or_fun_call`] pertaining to nested constructors [#4084](https://github.com/rust-lang/rust-clippy/pull/4084) -* Fix false positive in [`or_fun_call`] pertaining to enum variant constructors [#4018](https://github.com/rust-lang/rust-clippy/pull/4018) -* Fix false positive in [`useless_let_if_seq`] pertaining to interior mutability [#4035](https://github.com/rust-lang/rust-clippy/pull/4035) -* Fix false positive in [`redundant_closure`] pertaining to non-function types [#4008](https://github.com/rust-lang/rust-clippy/pull/4008) -* Fix false positive in [`let_and_return`] pertaining to attributes on `let`s [#4024](https://github.com/rust-lang/rust-clippy/pull/4024) -* Fix false positive in [`module_name_repetitions`] lint pertaining to attributes [#4006](https://github.com/rust-lang/rust-clippy/pull/4006) -* Fix false positive on [`assertions_on_constants`] pertaining to `debug_assert!` [#3989](https://github.com/rust-lang/rust-clippy/pull/3989) -* Improve suggestion in [`map_clone`] to suggest `.copied()` where applicable [#3970](https://github.com/rust-lang/rust-clippy/pull/3970) [#4043](https://github.com/rust-lang/rust-clippy/pull/4043) -* Improve suggestion for [`search_is_some`] [#4049](https://github.com/rust-lang/rust-clippy/pull/4049) -* Improve suggestion applicability for [`naive_bytecount`] [#3984](https://github.com/rust-lang/rust-clippy/pull/3984) -* Improve suggestion applicability for [`while_let_loop`] [#3975](https://github.com/rust-lang/rust-clippy/pull/3975) -* Improve diagnostics for [`too_many_arguments`] [#4053](https://github.com/rust-lang/rust-clippy/pull/4053) -* Improve diagnostics for [`cast_lossless`] [#4021](https://github.com/rust-lang/rust-clippy/pull/4021) -* Deal with macro checks in desugarings better [#4082](https://github.com/rust-lang/rust-clippy/pull/4082) -* Add macro check for [`unnecessary_cast`] [#4026](https://github.com/rust-lang/rust-clippy/pull/4026) -* Remove [`approx_constant`]'s documentation's "Known problems" section. [#4027](https://github.com/rust-lang/rust-clippy/pull/4027) -* Fix ICE in [`suspicious_else_formatting`] [#3960](https://github.com/rust-lang/rust-clippy/pull/3960) -* Fix ICE in [`decimal_literal_representation`] [#3931](https://github.com/rust-lang/rust-clippy/pull/3931) - - -## Rust 1.35 - -Released 2019-05-20 - -[1fac380..37f5c1e](https://github.com/rust-lang/rust-clippy/compare/1fac380...37f5c1e) - -* New lint: [`drop_bounds`] to detect `T: Drop` bounds -* Split [`redundant_closure`] into [`redundant_closure`] and [`redundant_closure_for_method_calls`] [#4110](https://github.com/rust-lang/rust-clippy/pull/4101) -* Rename `cyclomatic_complexity` to [`cognitive_complexity`], start work on making lint more practical for Rust code -* Move [`get_unwrap`] to the restriction category -* Improve suggestions for [`iter_cloned_collect`] -* Improve suggestions for [`cast_lossless`] to suggest suffixed literals -* Fix false positives in [`print_with_newline`] and [`write_with_newline`] pertaining to raw strings -* Fix false positive in [`needless_range_loop`] pertaining to structs without a `.iter()` -* Fix false positive in [`bool_comparison`] pertaining to non-bool types -* Fix false positive in [`redundant_closure`] pertaining to differences in borrows -* Fix false positive in `option_map_unwrap_or` on non-copy types -* Fix false positives in [`missing_const_for_fn`] pertaining to macros and trait method impls -* Fix false positive in [`needless_pass_by_value`] pertaining to procedural macros -* Fix false positive in [`needless_continue`] pertaining to loop labels -* Fix false positive for [`boxed_local`] pertaining to arguments moved into closures -* Fix false positive for [`use_self`] in nested functions -* Fix suggestion for [`expect_fun_call`] (https://github.com/rust-lang/rust-clippy/pull/3846) -* Fix suggestion for [`explicit_counter_loop`] to deal with parenthesizing range variables -* Fix suggestion for [`single_char_pattern`] to correctly escape single quotes -* Avoid triggering [`redundant_closure`] in macros -* ICE fixes: [#3805](https://github.com/rust-lang/rust-clippy/pull/3805), [#3772](https://github.com/rust-lang/rust-clippy/pull/3772), [#3741](https://github.com/rust-lang/rust-clippy/pull/3741) - -## Rust 1.34 - -Released 2019-04-10 - -[1b89724...1fac380](https://github.com/rust-lang/rust-clippy/compare/1b89724...1fac380) - -* New lint: [`assertions_on_constants`] to detect for example `assert!(true)` -* New lint: [`dbg_macro`] to detect uses of the `dbg!` macro -* New lint: [`missing_const_for_fn`] that can suggest functions to be made `const` -* New lint: [`too_many_lines`] to detect functions with excessive LOC. It can be - configured using the `too-many-lines-threshold` configuration. -* New lint: [`wildcard_enum_match_arm`] to check for wildcard enum matches using `_` -* Expand `redundant_closure` to also work for methods (not only functions) -* Fix ICEs in `vec_box`, `needless_pass_by_value` and `implicit_hasher` -* Fix false positive in `cast_sign_loss` -* Fix false positive in `integer_arithmetic` -* Fix false positive in `unit_arg` -* Fix false positives in `implicit_return` -* Add suggestion to `explicit_write` -* Improve suggestions for `question_mark` lint -* Fix incorrect suggestion for `cast_lossless` -* Fix incorrect suggestion for `expect_fun_call` -* Fix incorrect suggestion for `needless_bool` -* Fix incorrect suggestion for `needless_range_loop` -* Fix incorrect suggestion for `use_self` -* Fix incorrect suggestion for `while_let_on_iterator` -* Clippy is now slightly easier to invoke in non-cargo contexts. See - [#3665][pull3665] for more details. -* We now have [improved documentation][adding_lints] on how to add new lints - -## Rust 1.33 - -Released 2019-02-26 - -[b2601be...1b89724](https://github.com/rust-lang/rust-clippy/compare/b2601be...1b89724) - -* New lints: [`implicit_return`], [`vec_box`], [`cast_ref_to_mut`] -* The `rust-clippy` repository is now part of the `rust-lang` org. -* Rename `stutter` to `module_name_repetitions` -* Merge `new_without_default_derive` into `new_without_default` lint -* Move `large_digit_groups` from `style` group to `pedantic` -* Expand `bool_comparison` to check for `<`, `<=`, `>`, `>=`, and `!=` - comparisons against booleans -* Expand `no_effect` to detect writes to constants such as `A_CONST.field = 2` -* Expand `redundant_clone` to work on struct fields -* Expand `suspicious_else_formatting` to detect `if .. {..} {..}` -* Expand `use_self` to work on tuple structs and also in local macros -* Fix ICE in `result_map_unit_fn` and `option_map_unit_fn` -* Fix false positives in `implicit_return` -* Fix false positives in `use_self` -* Fix false negative in `clone_on_copy` -* Fix false positive in `doc_markdown` -* Fix false positive in `empty_loop` -* Fix false positive in `if_same_then_else` -* Fix false positive in `infinite_iter` -* Fix false positive in `question_mark` -* Fix false positive in `useless_asref` -* Fix false positive in `wildcard_dependencies` -* Fix false positive in `write_with_newline` -* Add suggestion to `explicit_write` -* Improve suggestions for `question_mark` lint -* Fix incorrect suggestion for `get_unwrap` - -## Rust 1.32 - -Released 2019-01-17 - -[2e26fdc2...b2601be](https://github.com/rust-lang/rust-clippy/compare/2e26fdc2...b2601be) - -* New lints: [`slow_vector_initialization`], [`mem_discriminant_non_enum`], - [`redundant_clone`], [`wildcard_dependencies`], - [`into_iter_on_ref`], [`into_iter_on_array`], [`deprecated_cfg_attr`], - [`mem_discriminant_non_enum`], [`cargo_common_metadata`] -* Add support for `u128` and `i128` to integer related lints -* Add float support to `mistyped_literal_suffixes` -* Fix false positives in `use_self` -* Fix false positives in `missing_comma` -* Fix false positives in `new_ret_no_self` -* Fix false positives in `possible_missing_comma` -* Fix false positive in `integer_arithmetic` in constant items -* Fix false positive in `needless_borrow` -* Fix false positive in `out_of_bounds_indexing` -* Fix false positive in `new_without_default_derive` -* Fix false positive in `string_lit_as_bytes` -* Fix false negative in `out_of_bounds_indexing` -* Fix false negative in `use_self`. It will now also check existential types -* Fix incorrect suggestion for `redundant_closure_call` -* Fix various suggestions that contained expanded macros -* Fix `bool_comparison` triggering 3 times on on on the same code -* Expand `trivially_copy_pass_by_ref` to work on trait methods -* Improve suggestion for `needless_range_loop` -* Move `needless_pass_by_value` from `pedantic` group to `style` - -## Rust 1.31 - -Released 2018-12-06 - -[125907ad..2e26fdc2](https://github.com/rust-lang/rust-clippy/compare/125907ad..2e26fdc2) - -* Clippy has been relicensed under a dual MIT / Apache license. - See [#3093](https://github.com/rust-lang/rust-clippy/issues/3093) for more - information. -* With Rust 1.31, Clippy is no longer available via crates.io. The recommended - installation method is via `rustup component add clippy`. -* New lints: [`redundant_pattern_matching`], [`unnecessary_filter_map`], - [`unused_unit`], [`map_flatten`], [`mem_replace_option_with_none`] -* Fix ICE in `if_let_redundant_pattern_matching` -* Fix ICE in `needless_pass_by_value` when encountering a generic function - argument with a lifetime parameter -* Fix ICE in `needless_range_loop` -* Fix ICE in `single_char_pattern` when encountering a constant value -* Fix false positive in `assign_op_pattern` -* Fix false positive in `boxed_local` on trait implementations -* Fix false positive in `cmp_owned` -* Fix false positive in `collapsible_if` when conditionals have comments -* Fix false positive in `double_parens` -* Fix false positive in `excessive_precision` -* Fix false positive in `explicit_counter_loop` -* Fix false positive in `fn_to_numeric_cast_with_truncation` -* Fix false positive in `map_clone` -* Fix false positive in `new_ret_no_self` -* Fix false positive in `new_without_default` when `new` is unsafe -* Fix false positive in `type_complexity` when using extern types -* Fix false positive in `useless_format` -* Fix false positive in `wrong_self_convention` -* Fix incorrect suggestion for `excessive_precision` -* Fix incorrect suggestion for `expect_fun_call` -* Fix incorrect suggestion for `get_unwrap` -* Fix incorrect suggestion for `useless_format` -* `fn_to_numeric_cast_with_truncation` lint can be disabled again -* Improve suggestions for `manual_memcpy` -* Improve help message for `needless_lifetimes` - -## Rust 1.30 - -Released 2018-10-25 - -[14207503...125907ad](https://github.com/rust-lang/rust-clippy/compare/14207503...125907ad) - -* Deprecate `assign_ops` lint -* New lints: [`mistyped_literal_suffixes`], [`ptr_offset_with_cast`], - [`needless_collect`], [`copy_iterator`] -* `cargo clippy -V` now includes the Clippy commit hash of the Rust - Clippy component -* Fix ICE in `implicit_hasher` -* Fix ICE when encountering `println!("{}" a);` -* Fix ICE when encountering a macro call in match statements -* Fix false positive in `default_trait_access` -* Fix false positive in `trivially_copy_pass_by_ref` -* Fix false positive in `similar_names` -* Fix false positive in `redundant_field_name` -* Fix false positive in `expect_fun_call` -* Fix false negative in `identity_conversion` -* Fix false negative in `explicit_counter_loop` -* Fix `range_plus_one` suggestion and false negative -* `print_with_newline` / `write_with_newline`: don't warn about string with several `\n`s in them -* Fix `useless_attribute` to also whitelist `unused_extern_crates` -* Fix incorrect suggestion for `single_char_pattern` -* Improve suggestion for `identity_conversion` lint -* Move `explicit_iter_loop` and `explicit_into_iter_loop` from `style` group to `pedantic` -* Move `range_plus_one` and `range_minus_one` from `nursery` group to `complexity` -* Move `shadow_unrelated` from `restriction` group to `pedantic` -* Move `indexing_slicing` from `pedantic` group to `restriction` - -## Rust 1.29 - -Released 2018-09-13 - -[v0.0.212...14207503](https://github.com/rust-lang/rust-clippy/compare/v0.0.212...14207503) - -* :tada: :tada: **Rust 1.29 is the first stable Rust that includes a bundled Clippy** :tada: - :tada: - You can now run `rustup component add clippy-preview` and then `cargo - clippy` to run Clippy. This should put an end to the continuous nightly - upgrades for Clippy users. -* Clippy now follows the Rust versioning scheme instead of its own -* Fix ICE when encountering a `while let (..) = x.iter()` construct -* Fix false positives in `use_self` -* Fix false positive in `trivially_copy_pass_by_ref` -* Fix false positive in `useless_attribute` lint -* Fix false positive in `print_literal` -* Fix `use_self` regressions -* Improve lint message for `neg_cmp_op_on_partial_ord` -* Improve suggestion highlight for `single_char_pattern` -* Improve suggestions for various print/write macro lints -* Improve website header - -## 0.0.212 (2018-07-10) -* Rustup to *rustc 1.29.0-nightly (e06c87544 2018-07-06)* - -## 0.0.211 -* Rustup to *rustc 1.28.0-nightly (e3bf634e0 2018-06-28)* - -## 0.0.210 -* Rustup to *rustc 1.28.0-nightly (01cc982e9 2018-06-24)* - -## 0.0.209 -* Rustup to *rustc 1.28.0-nightly (523097979 2018-06-18)* - -## 0.0.208 -* Rustup to *rustc 1.28.0-nightly (86a8f1a63 2018-06-17)* - -## 0.0.207 -* Rustup to *rustc 1.28.0-nightly (2a0062974 2018-06-09)* - -## 0.0.206 -* Rustup to *rustc 1.28.0-nightly (5bf68db6e 2018-05-28)* - -## 0.0.205 -* Rustup to *rustc 1.28.0-nightly (990d8aa74 2018-05-25)* -* Rename `unused_lifetimes` to `extra_unused_lifetimes` because of naming conflict with new rustc lint - -## 0.0.204 -* Rustup to *rustc 1.28.0-nightly (71e87be38 2018-05-22)* - -## 0.0.203 -* Rustup to *rustc 1.28.0-nightly (a3085756e 2018-05-19)* -* Clippy attributes are now of the form `clippy::cyclomatic_complexity` instead of `clippy(cyclomatic_complexity)` - -## 0.0.202 -* Rustup to *rustc 1.28.0-nightly (952f344cd 2018-05-18)* - -## 0.0.201 -* Rustup to *rustc 1.27.0-nightly (2f2a11dfc 2018-05-16)* - -## 0.0.200 -* Rustup to *rustc 1.27.0-nightly (9fae15374 2018-05-13)* - -## 0.0.199 -* Rustup to *rustc 1.27.0-nightly (ff2ac35db 2018-05-12)* - -## 0.0.198 -* Rustup to *rustc 1.27.0-nightly (acd3871ba 2018-05-10)* - -## 0.0.197 -* Rustup to *rustc 1.27.0-nightly (428ea5f6b 2018-05-06)* - -## 0.0.196 -* Rustup to *rustc 1.27.0-nightly (e82261dfb 2018-05-03)* - -## 0.0.195 -* Rustup to *rustc 1.27.0-nightly (ac3c2288f 2018-04-18)* - -## 0.0.194 -* Rustup to *rustc 1.27.0-nightly (bd40cbbe1 2018-04-14)* -* New lints: [`cast_ptr_alignment`], [`transmute_ptr_to_ptr`], [`write_literal`], [`write_with_newline`], [`writeln_empty_string`] - -## 0.0.193 -* Rustup to *rustc 1.27.0-nightly (eeea94c11 2018-04-06)* - -## 0.0.192 -* Rustup to *rustc 1.27.0-nightly (fb44b4c0e 2018-04-04)* -* New lint: [`print_literal`] - -## 0.0.191 -* Rustup to *rustc 1.26.0-nightly (ae544ee1c 2018-03-29)* -* Lint audit; categorize lints as style, correctness, complexity, pedantic, nursery, restriction. - -## 0.0.190 -* Fix a bunch of intermittent cargo bugs - -## 0.0.189 -* Rustup to *rustc 1.26.0-nightly (5508b2714 2018-03-18)* - -## 0.0.188 -* Rustup to *rustc 1.26.0-nightly (392645394 2018-03-15)* -* New lint: [`while_immutable_condition`] - -## 0.0.187 -* Rustup to *rustc 1.26.0-nightly (322d7f7b9 2018-02-25)* -* New lints: [`redundant_field_names`], [`suspicious_arithmetic_impl`], [`suspicious_op_assign_impl`] - -## 0.0.186 -* Rustup to *rustc 1.25.0-nightly (0c6091fbd 2018-02-04)* -* Various false positive fixes - -## 0.0.185 -* Rustup to *rustc 1.25.0-nightly (56733bc9f 2018-02-01)* -* New lint: [`question_mark`] - -## 0.0.184 -* Rustup to *rustc 1.25.0-nightly (90eb44a58 2018-01-29)* -* New lints: [`double_comparisons`], [`empty_line_after_outer_attr`] - -## 0.0.183 -* Rustup to *rustc 1.25.0-nightly (21882aad7 2018-01-28)* -* New lint: [`misaligned_transmute`] - -## 0.0.182 -* Rustup to *rustc 1.25.0-nightly (a0dcecff9 2018-01-24)* -* New lint: [`decimal_literal_representation`] - -## 0.0.181 -* Rustup to *rustc 1.25.0-nightly (97520ccb1 2018-01-21)* -* New lints: [`else_if_without_else`], [`option_option`], [`unit_arg`], [`unnecessary_fold`] -* Removed `unit_expr` -* Various false positive fixes for [`needless_pass_by_value`] - -## 0.0.180 -* Rustup to *rustc 1.25.0-nightly (3f92e8d89 2018-01-14)* - -## 0.0.179 -* Rustup to *rustc 1.25.0-nightly (61452e506 2018-01-09)* - -## 0.0.178 -* Rustup to *rustc 1.25.0-nightly (ee220daca 2018-01-07)* - -## 0.0.177 -* Rustup to *rustc 1.24.0-nightly (250b49205 2017-12-21)* -* New lint: [`match_as_ref`] - -## 0.0.176 -* Rustup to *rustc 1.24.0-nightly (0077d128d 2017-12-14)* - -## 0.0.175 -* Rustup to *rustc 1.24.0-nightly (bb42071f6 2017-12-01)* - -## 0.0.174 -* Rustup to *rustc 1.23.0-nightly (63739ab7b 2017-11-21)* - -## 0.0.173 -* Rustup to *rustc 1.23.0-nightly (33374fa9d 2017-11-20)* - -## 0.0.172 -* Rustup to *rustc 1.23.0-nightly (d0f8e2913 2017-11-16)* - -## 0.0.171 -* Rustup to *rustc 1.23.0-nightly (ff0f5de3b 2017-11-14)* - -## 0.0.170 -* Rustup to *rustc 1.23.0-nightly (d6b06c63a 2017-11-09)* - -## 0.0.169 -* Rustup to *rustc 1.23.0-nightly (3b82e4c74 2017-11-05)* -* New lints: [`just_underscores_and_digits`], `result_map_unwrap_or_else`, [`transmute_bytes_to_str`] - -## 0.0.168 -* Rustup to *rustc 1.23.0-nightly (f0fe716db 2017-10-30)* - -## 0.0.167 -* Rustup to *rustc 1.23.0-nightly (90ef3372e 2017-10-29)* -* New lints: `const_static_lifetime`, [`erasing_op`], [`fallible_impl_from`], [`println_empty_string`], [`useless_asref`] - -## 0.0.166 -* Rustup to *rustc 1.22.0-nightly (b7960878b 2017-10-18)* -* New lints: [`explicit_write`], `identity_conversion`, [`implicit_hasher`], [`invalid_ref`], [`option_map_or_none`], - [`range_minus_one`], [`range_plus_one`], [`transmute_int_to_bool`], [`transmute_int_to_char`], - [`transmute_int_to_float`] - -## 0.0.165 -* Rust upgrade to rustc 1.22.0-nightly (0e6f4cf51 2017-09-27) -* New lint: [`mut_range_bound`] - -## 0.0.164 -* Update to *rustc 1.22.0-nightly (6c476ce46 2017-09-25)* -* New lint: [`int_plus_one`] - -## 0.0.163 -* Update to *rustc 1.22.0-nightly (14039a42a 2017-09-22)* - -## 0.0.162 -* Update to *rustc 1.22.0-nightly (0701b37d9 2017-09-18)* -* New lint: [`chars_last_cmp`] -* Improved suggestions for [`needless_borrow`], [`ptr_arg`], - -## 0.0.161 -* Update to *rustc 1.22.0-nightly (539f2083d 2017-09-13)* - -## 0.0.160 -* Update to *rustc 1.22.0-nightly (dd08c3070 2017-09-12)* - -## 0.0.159 -* Update to *rustc 1.22.0-nightly (eba374fb2 2017-09-11)* -* New lint: [`clone_on_ref_ptr`] - -## 0.0.158 -* New lint: [`manual_memcpy`] -* [`cast_lossless`] no longer has redundant parentheses in its suggestions -* Update to *rustc 1.22.0-nightly (dead08cb3 2017-09-08)* - -## 0.0.157 - 2017-09-04 -* Update to *rustc 1.22.0-nightly (981ce7d8d 2017-09-03)* -* New lint: `unit_expr` - -## 0.0.156 - 2017-09-03 -* Update to *rustc 1.22.0-nightly (744dd6c1d 2017-09-02)* - -## 0.0.155 -* Update to *rustc 1.21.0-nightly (c11f689d2 2017-08-29)* -* New lint: [`infinite_iter`], [`maybe_infinite_iter`], [`cast_lossless`] - -## 0.0.154 -* Update to *rustc 1.21.0-nightly (2c0558f63 2017-08-24)* -* Fix [`use_self`] triggering inside derives -* Add support for linting an entire workspace with `cargo clippy --all` -* New lint: [`naive_bytecount`] - -## 0.0.153 -* Update to *rustc 1.21.0-nightly (8c303ed87 2017-08-20)* -* New lint: [`use_self`] - -## 0.0.152 -* Update to *rustc 1.21.0-nightly (df511d554 2017-08-14)* - -## 0.0.151 -* Update to *rustc 1.21.0-nightly (13d94d5fa 2017-08-10)* - -## 0.0.150 -* Update to *rustc 1.21.0-nightly (215e0b10e 2017-08-08)* - -## 0.0.148 -* Update to *rustc 1.21.0-nightly (37c7d0ebb 2017-07-31)* -* New lints: [`unreadable_literal`], [`inconsistent_digit_grouping`], [`large_digit_groups`] - -## 0.0.147 -* Update to *rustc 1.21.0-nightly (aac223f4f 2017-07-30)* - -## 0.0.146 -* Update to *rustc 1.21.0-nightly (52a330969 2017-07-27)* -* Fixes false positives in `inline_always` -* Fixes false negatives in `panic_params` - -## 0.0.145 -* Update to *rustc 1.20.0-nightly (afe145d22 2017-07-23)* - -## 0.0.144 -* Update to *rustc 1.20.0-nightly (086eaa78e 2017-07-15)* - -## 0.0.143 -* Update to *rustc 1.20.0-nightly (d84693b93 2017-07-09)* -* Fix `cargo clippy` crashing on `dylib` projects -* Fix false positives around `nested_while_let` and `never_loop` - -## 0.0.142 -* Update to *rustc 1.20.0-nightly (067971139 2017-07-02)* - -## 0.0.141 -* Rewrite of the `doc_markdown` lint. -* Deprecated [`range_step_by_zero`] -* New lint: [`iterator_step_by_zero`] -* New lint: [`needless_borrowed_reference`] -* Update to *rustc 1.20.0-nightly (69c65d296 2017-06-28)* - -## 0.0.140 - 2017-06-16 -* Update to *rustc 1.19.0-nightly (258ae6dd9 2017-06-15)* - -## 0.0.139 — 2017-06-10 -* Update to *rustc 1.19.0-nightly (4bf5c99af 2017-06-10)* -* Fix bugs with for loop desugaring -* Check for [`AsRef`]/[`AsMut`] arguments in [`wrong_self_convention`] - -## 0.0.138 — 2017-06-05 -* Update to *rustc 1.19.0-nightly (0418fa9d3 2017-06-04)* - -## 0.0.137 — 2017-06-05 -* Update to *rustc 1.19.0-nightly (6684d176c 2017-06-03)* - -## 0.0.136 — 2017—05—26 -* Update to *rustc 1.19.0-nightly (557967766 2017-05-26)* - -## 0.0.135 — 2017—05—24 -* Update to *rustc 1.19.0-nightly (5b13bff52 2017-05-23)* - -## 0.0.134 — 2017—05—19 -* Update to *rustc 1.19.0-nightly (0ed1ec9f9 2017-05-18)* - -## 0.0.133 — 2017—05—14 -* Update to *rustc 1.19.0-nightly (826d8f385 2017-05-13)* - -## 0.0.132 — 2017—05—05 -* Fix various bugs and some ices - -## 0.0.131 — 2017—05—04 -* Update to *rustc 1.19.0-nightly (2d4ed8e0c 2017-05-03)* - -## 0.0.130 — 2017—05—03 -* Update to *rustc 1.19.0-nightly (6a5fc9eec 2017-05-02)* - -## 0.0.129 — 2017-05-01 -* Update to *rustc 1.19.0-nightly (06fb4d256 2017-04-30)* - -## 0.0.128 — 2017-04-28 -* Update to *rustc 1.18.0-nightly (94e884b63 2017-04-27)* - -## 0.0.127 — 2017-04-27 -* Update to *rustc 1.18.0-nightly (036983201 2017-04-26)* -* New lint: [`needless_continue`] - -## 0.0.126 — 2017-04-24 -* Update to *rustc 1.18.0-nightly (2bd4b5c6d 2017-04-23)* - -## 0.0.125 — 2017-04-19 -* Update to *rustc 1.18.0-nightly (9f2abadca 2017-04-18)* - -## 0.0.124 — 2017-04-16 -* Update to *rustc 1.18.0-nightly (d5cf1cb64 2017-04-15)* - -## 0.0.123 — 2017-04-07 -* Fix various false positives - -## 0.0.122 — 2017-04-07 -* Rustup to *rustc 1.18.0-nightly (91ae22a01 2017-04-05)* -* New lint: [`op_ref`] - -## 0.0.121 — 2017-03-21 -* Rustup to *rustc 1.17.0-nightly (134c4a0f0 2017-03-20)* - -## 0.0.120 — 2017-03-17 -* Rustup to *rustc 1.17.0-nightly (0aeb9c129 2017-03-15)* - -## 0.0.119 — 2017-03-13 -* Rustup to *rustc 1.17.0-nightly (824c9ebbd 2017-03-12)* - -## 0.0.118 — 2017-03-05 -* Rustup to *rustc 1.17.0-nightly (b1e31766d 2017-03-03)* - -## 0.0.117 — 2017-03-01 -* Rustup to *rustc 1.17.0-nightly (be760566c 2017-02-28)* - -## 0.0.116 — 2017-02-28 -* Fix `cargo clippy` on 64 bit windows systems - -## 0.0.115 — 2017-02-27 -* Rustup to *rustc 1.17.0-nightly (60a0edc6c 2017-02-26)* -* New lints: [`zero_ptr`], [`never_loop`], [`mut_from_ref`] - -## 0.0.114 — 2017-02-08 -* Rustup to *rustc 1.17.0-nightly (c49d10207 2017-02-07)* -* Tests are now ui tests (testing the exact output of rustc) - -## 0.0.113 — 2017-02-04 -* Rustup to *rustc 1.16.0-nightly (eedaa94e3 2017-02-02)* -* New lint: [`large_enum_variant`] -* `explicit_into_iter_loop` provides suggestions - -## 0.0.112 — 2017-01-27 -* Rustup to *rustc 1.16.0-nightly (df8debf6d 2017-01-25)* - -## 0.0.111 — 2017-01-21 -* Rustup to *rustc 1.16.0-nightly (a52da95ce 2017-01-20)* - -## 0.0.110 — 2017-01-20 -* Add badges and categories to `Cargo.toml` - -## 0.0.109 — 2017-01-19 -* Update to *rustc 1.16.0-nightly (c07a6ae77 2017-01-17)* - -## 0.0.108 — 2017-01-12 -* Update to *rustc 1.16.0-nightly (2782e8f8f 2017-01-12)* - -## 0.0.107 — 2017-01-11 -* Update regex dependency -* Fix FP when matching `&&mut` by `&ref` -* Reintroduce `for (_, x) in &mut hash_map` -> `for x in hash_map.values_mut()` -* New lints: [`unused_io_amount`], [`forget_ref`], [`short_circuit_statement`] - -## 0.0.106 — 2017-01-04 -* Fix FP introduced by rustup in [`wrong_self_convention`] - -## 0.0.105 — 2017-01-04 -* Update to *rustc 1.16.0-nightly (468227129 2017-01-03)* -* New lints: [`deref_addrof`], [`double_parens`], [`pub_enum_variant_names`] -* Fix suggestion in [`new_without_default`] -* FP fix in [`absurd_extreme_comparisons`] - -## 0.0.104 — 2016-12-15 -* Update to *rustc 1.15.0-nightly (8f02c429a 2016-12-15)* - -## 0.0.103 — 2016-11-25 -* Update to *rustc 1.15.0-nightly (d5814b03e 2016-11-23)* - -## 0.0.102 — 2016-11-24 -* Update to *rustc 1.15.0-nightly (3bf2be9ce 2016-11-22)* - -## 0.0.101 — 2016-11-23 -* Update to *rustc 1.15.0-nightly (7b3eeea22 2016-11-21)* -* New lint: [`string_extend_chars`] - -## 0.0.100 — 2016-11-20 -* Update to *rustc 1.15.0-nightly (ac635aa95 2016-11-18)* - -## 0.0.99 — 2016-11-18 -* Update to rustc 1.15.0-nightly (0ed951993 2016-11-14) -* New lint: [`get_unwrap`] - -## 0.0.98 — 2016-11-08 -* Fixes an issue due to a change in how cargo handles `--sysroot`, which broke `cargo clippy` - -## 0.0.97 — 2016-11-03 -* For convenience, `cargo clippy` defines a `cargo-clippy` feature. This was - previously added for a short time under the name `clippy` but removed for - compatibility. -* `cargo clippy --help` is more helping (and less helpful :smile:) -* Rustup to *rustc 1.14.0-nightly (5665bdf3e 2016-11-02)* -* New lints: [`if_let_redundant_pattern_matching`], [`partialeq_ne_impl`] - -## 0.0.96 — 2016-10-22 -* Rustup to *rustc 1.14.0-nightly (f09420685 2016-10-20)* -* New lint: [`iter_skip_next`] - -## 0.0.95 — 2016-10-06 -* Rustup to *rustc 1.14.0-nightly (3210fd5c2 2016-10-05)* - -## 0.0.94 — 2016-10-04 -* Fixes bustage on Windows due to forbidden directory name - -## 0.0.93 — 2016-10-03 -* Rustup to *rustc 1.14.0-nightly (144af3e97 2016-10-02)* -* `option_map_unwrap_or` and `option_map_unwrap_or_else` are now - allowed by default. -* New lint: [`explicit_into_iter_loop`] - -## 0.0.92 — 2016-09-30 -* Rustup to *rustc 1.14.0-nightly (289f3a4ca 2016-09-29)* - -## 0.0.91 — 2016-09-28 -* Rustup to *rustc 1.13.0-nightly (d0623cf7b 2016-09-26)* - -## 0.0.90 — 2016-09-09 -* Rustup to *rustc 1.13.0-nightly (f1f40f850 2016-09-09)* - -## 0.0.89 — 2016-09-06 -* Rustup to *rustc 1.13.0-nightly (cbe4de78e 2016-09-05)* - -## 0.0.88 — 2016-09-04 -* Rustup to *rustc 1.13.0-nightly (70598e04f 2016-09-03)* -* The following lints are not new but were only usable through the `clippy` - lint groups: [`filter_next`], `for_loop_over_option`, - `for_loop_over_result` and [`match_overlapping_arm`]. You should now be - able to `#[allow/deny]` them individually and they are available directly - through `cargo clippy`. - -## 0.0.87 — 2016-08-31 -* Rustup to *rustc 1.13.0-nightly (eac41469d 2016-08-30)* -* New lints: [`builtin_type_shadow`] -* Fix FP in [`zero_prefixed_literal`] and `0b`/`0o` - -## 0.0.86 — 2016-08-28 -* Rustup to *rustc 1.13.0-nightly (a23064af5 2016-08-27)* -* New lints: [`missing_docs_in_private_items`], [`zero_prefixed_literal`] - -## 0.0.85 — 2016-08-19 -* Fix ICE with [`useless_attribute`] -* [`useless_attribute`] ignores `unused_imports` on `use` statements - -## 0.0.84 — 2016-08-18 -* Rustup to *rustc 1.13.0-nightly (aef6971ca 2016-08-17)* - -## 0.0.83 — 2016-08-17 -* Rustup to *rustc 1.12.0-nightly (1bf5fa326 2016-08-16)* -* New lints: [`print_with_newline`], [`useless_attribute`] - -## 0.0.82 — 2016-08-17 -* Rustup to *rustc 1.12.0-nightly (197be89f3 2016-08-15)* -* New lint: [`module_inception`] - -## 0.0.81 — 2016-08-14 -* Rustup to *rustc 1.12.0-nightly (1deb02ea6 2016-08-12)* -* New lints: [`eval_order_dependence`], [`mixed_case_hex_literals`], [`unseparated_literal_suffix`] -* False positive fix in [`too_many_arguments`] -* Addition of functionality to [`needless_borrow`] -* Suggestions for [`clone_on_copy`] -* Bug fix in [`wrong_self_convention`] -* Doc improvements - -## 0.0.80 — 2016-07-31 -* Rustup to *rustc 1.12.0-nightly (1225e122f 2016-07-30)* -* New lints: [`misrefactored_assign_op`], [`serde_api_misuse`] - -## 0.0.79 — 2016-07-10 -* Rustup to *rustc 1.12.0-nightly (f93aaf84c 2016-07-09)* -* Major suggestions refactoring - -## 0.0.78 — 2016-07-02 -* Rustup to *rustc 1.11.0-nightly (01411937f 2016-07-01)* -* New lints: [`wrong_transmute`], [`double_neg`], [`filter_map`] -* For compatibility, `cargo clippy` does not defines the `clippy` feature - introduced in 0.0.76 anymore -* [`collapsible_if`] now considers `if let` - -## 0.0.77 — 2016-06-21 -* Rustup to *rustc 1.11.0-nightly (5522e678b 2016-06-20)* -* New lints: `stutter` and [`iter_nth`] - -## 0.0.76 — 2016-06-10 -* Rustup to *rustc 1.11.0-nightly (7d2f75a95 2016-06-09)* -* `cargo clippy` now automatically defines the `clippy` feature -* New lint: [`not_unsafe_ptr_arg_deref`] - -## 0.0.75 — 2016-06-08 -* Rustup to *rustc 1.11.0-nightly (763f9234b 2016-06-06)* - -## 0.0.74 — 2016-06-07 -* Fix bug with `cargo-clippy` JSON parsing -* Add the `CLIPPY_DISABLE_DOCS_LINKS` environment variable to deactivate the - “for further information visit *lint-link*” message. - -## 0.0.73 — 2016-06-05 -* Fix false positives in [`useless_let_if_seq`] - -## 0.0.72 — 2016-06-04 -* Fix false positives in [`useless_let_if_seq`] - -## 0.0.71 — 2016-05-31 -* Rustup to *rustc 1.11.0-nightly (a967611d8 2016-05-30)* -* New lint: [`useless_let_if_seq`] - -## 0.0.70 — 2016-05-28 -* Rustup to *rustc 1.10.0-nightly (7bddce693 2016-05-27)* -* [`invalid_regex`] and [`trivial_regex`] can now warn on `RegexSet::new`, - `RegexBuilder::new` and byte regexes - -## 0.0.69 — 2016-05-20 -* Rustup to *rustc 1.10.0-nightly (476fe6eef 2016-05-21)* -* [`used_underscore_binding`] has been made `Allow` temporarily - -## 0.0.68 — 2016-05-17 -* Rustup to *rustc 1.10.0-nightly (cd6a40017 2016-05-16)* -* New lint: [`unnecessary_operation`] - -## 0.0.67 — 2016-05-12 -* Rustup to *rustc 1.10.0-nightly (22ac88f1a 2016-05-11)* - -## 0.0.66 — 2016-05-11 -* New `cargo clippy` subcommand -* New lints: [`assign_op_pattern`], [`assign_ops`], [`needless_borrow`] - -## 0.0.65 — 2016-05-08 -* Rustup to *rustc 1.10.0-nightly (62e2b2fb7 2016-05-06)* -* New lints: [`float_arithmetic`], [`integer_arithmetic`] - -## 0.0.64 — 2016-04-26 -* Rustup to *rustc 1.10.0-nightly (645dd013a 2016-04-24)* -* New lints: [`temporary_cstring_as_ptr`], [`unsafe_removed_from_name`], and [`mem_forget`] - -## 0.0.63 — 2016-04-08 -* Rustup to *rustc 1.9.0-nightly (7979dd608 2016-04-07)* - -## 0.0.62 — 2016-04-07 -* Rustup to *rustc 1.9.0-nightly (bf5da36f1 2016-04-06)* - -## 0.0.61 — 2016-04-03 -* Rustup to *rustc 1.9.0-nightly (5ab11d72c 2016-04-02)* -* New lint: [`invalid_upcast_comparisons`] - -## 0.0.60 — 2016-04-01 -* Rustup to *rustc 1.9.0-nightly (e1195c24b 2016-03-31)* - -## 0.0.59 — 2016-03-31 -* Rustup to *rustc 1.9.0-nightly (30a3849f2 2016-03-30)* -* New lints: [`logic_bug`], [`nonminimal_bool`] -* Fixed: [`match_same_arms`] now ignores arms with guards -* Improved: [`useless_vec`] now warns on `for … in vec![…]` - -## 0.0.58 — 2016-03-27 -* Rustup to *rustc 1.9.0-nightly (d5a91e695 2016-03-26)* -* New lint: [`doc_markdown`] - -## 0.0.57 — 2016-03-27 -* Update to *rustc 1.9.0-nightly (a1e29daf1 2016-03-25)* -* Deprecated lints: [`str_to_string`], [`string_to_string`], [`unstable_as_slice`], [`unstable_as_mut_slice`] -* New lint: [`crosspointer_transmute`] - -## 0.0.56 — 2016-03-23 -* Update to *rustc 1.9.0-nightly (0dcc413e4 2016-03-22)* -* New lints: [`many_single_char_names`] and [`similar_names`] - -## 0.0.55 — 2016-03-21 -* Update to *rustc 1.9.0-nightly (02310fd31 2016-03-19)* - -## 0.0.54 — 2016-03-16 -* Update to *rustc 1.9.0-nightly (c66d2380a 2016-03-15)* - -## 0.0.53 — 2016-03-15 -* Add a [configuration file] - -## ~~0.0.52~~ - -## 0.0.51 — 2016-03-13 -* Add `str` to types considered by [`len_zero`] -* New lints: [`indexing_slicing`] - -## 0.0.50 — 2016-03-11 -* Update to *rustc 1.9.0-nightly (c9629d61c 2016-03-10)* - -## 0.0.49 — 2016-03-09 -* Update to *rustc 1.9.0-nightly (eabfc160f 2016-03-08)* -* New lints: [`overflow_check_conditional`], [`unused_label`], [`new_without_default`] - -## 0.0.48 — 2016-03-07 -* Fixed: ICE in [`needless_range_loop`] with globals - -## 0.0.47 — 2016-03-07 -* Update to *rustc 1.9.0-nightly (998a6720b 2016-03-07)* -* New lint: [`redundant_closure_call`] - -[`AsMut`]: https://doc.rust-lang.org/std/convert/trait.AsMut.html -[`AsRef`]: https://doc.rust-lang.org/std/convert/trait.AsRef.html -[configuration file]: ./rust-clippy#configuration -[pull3665]: https://github.com/rust-lang/rust-clippy/pull/3665 -[adding_lints]: https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md - - - -[`absurd_extreme_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#absurd_extreme_comparisons -[`almost_swapped`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_swapped -[`approx_constant`]: https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant -[`as_conversions`]: https://rust-lang.github.io/rust-clippy/master/index.html#as_conversions -[`assertions_on_constants`]: https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants -[`assign_op_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern -[`assign_ops`]: https://rust-lang.github.io/rust-clippy/master/index.html#assign_ops -[`async_yields_async`]: https://rust-lang.github.io/rust-clippy/master/index.html#async_yields_async -[`await_holding_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_lock -[`await_holding_refcell_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_refcell_ref -[`bad_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#bad_bit_mask -[`bind_instead_of_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#bind_instead_of_map -[`blacklisted_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name -[`blanket_clippy_restriction_lints`]: https://rust-lang.github.io/rust-clippy/master/index.html#blanket_clippy_restriction_lints -[`blocks_in_if_conditions`]: https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_if_conditions -[`bool_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison -[`borrow_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrow_interior_mutable_const -[`borrowed_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrowed_box -[`box_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#box_vec -[`boxed_local`]: https://rust-lang.github.io/rust-clippy/master/index.html#boxed_local -[`builtin_type_shadow`]: https://rust-lang.github.io/rust-clippy/master/index.html#builtin_type_shadow -[`cargo_common_metadata`]: https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata -[`cast_lossless`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless -[`cast_possible_truncation`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation -[`cast_possible_wrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap -[`cast_precision_loss`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_precision_loss -[`cast_ptr_alignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_ptr_alignment -[`cast_ref_to_mut`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_ref_to_mut -[`cast_sign_loss`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss -[`char_lit_as_u8`]: https://rust-lang.github.io/rust-clippy/master/index.html#char_lit_as_u8 -[`chars_last_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#chars_last_cmp -[`chars_next_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#chars_next_cmp -[`checked_conversions`]: https://rust-lang.github.io/rust-clippy/master/index.html#checked_conversions -[`clone_double_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_double_ref -[`clone_on_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy -[`clone_on_ref_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_ref_ptr -[`cmp_nan`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_nan -[`cmp_null`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_null -[`cmp_owned`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_owned -[`cognitive_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#cognitive_complexity -[`collapsible_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if -[`collapsible_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_match -[`comparison_chain`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_chain -[`comparison_to_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_to_empty -[`copy_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#copy_iterator -[`create_dir`]: https://rust-lang.github.io/rust-clippy/master/index.html#create_dir -[`crosspointer_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#crosspointer_transmute -[`dbg_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#dbg_macro -[`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_trait_access`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_trait_access -[`deprecated_cfg_attr`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_cfg_attr -[`deprecated_semver`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_semver -[`deref_addrof`]: https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof -[`derive_hash_xor_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq -[`derive_ord_xor_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord -[`disallowed_method`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_method -[`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression -[`doc_markdown`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown -[`double_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_comparisons -[`double_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_must_use -[`double_neg`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_neg -[`double_parens`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_parens -[`drop_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#drop_bounds -[`drop_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#drop_copy -[`drop_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#drop_ref -[`duplicate_underscore_argument`]: https://rust-lang.github.io/rust-clippy/master/index.html#duplicate_underscore_argument -[`duration_subsec`]: https://rust-lang.github.io/rust-clippy/master/index.html#duration_subsec -[`else_if_without_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else -[`empty_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_enum -[`empty_line_after_outer_attr`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_outer_attr -[`empty_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_loop -[`enum_clike_unportable_variant`]: https://rust-lang.github.io/rust-clippy/master/index.html#enum_clike_unportable_variant -[`enum_glob_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#enum_glob_use -[`enum_variant_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names -[`eq_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#eq_op -[`erasing_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#erasing_op -[`eval_order_dependence`]: https://rust-lang.github.io/rust-clippy/master/index.html#eval_order_dependence -[`excessive_precision`]: https://rust-lang.github.io/rust-clippy/master/index.html#excessive_precision -[`exit`]: https://rust-lang.github.io/rust-clippy/master/index.html#exit -[`expect_fun_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#expect_fun_call -[`expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#expect_used -[`expl_impl_clone_on_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#expl_impl_clone_on_copy -[`explicit_counter_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_counter_loop -[`explicit_deref_methods`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_deref_methods -[`explicit_into_iter_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_into_iter_loop -[`explicit_iter_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_iter_loop -[`explicit_write`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_write -[`extend_from_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#extend_from_slice -[`extra_unused_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes -[`fallible_impl_from`]: https://rust-lang.github.io/rust-clippy/master/index.html#fallible_impl_from -[`field_reassign_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default -[`filetype_is_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#filetype_is_file -[`filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map -[`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next -[`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next -[`find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#find_map -[`flat_map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#flat_map_identity -[`float_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_arithmetic -[`float_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp -[`float_cmp_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp_const -[`float_equality_without_abs`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_equality_without_abs -[`fn_address_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_address_comparisons -[`fn_params_excessive_bools`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_params_excessive_bools -[`fn_to_numeric_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_to_numeric_cast -[`fn_to_numeric_cast_with_truncation`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_to_numeric_cast_with_truncation -[`for_kv_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_kv_map -[`for_loops_over_fallibles`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loops_over_fallibles -[`forget_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_copy -[`forget_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_ref -[`from_iter_instead_of_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#from_iter_instead_of_collect -[`future_not_send`]: https://rust-lang.github.io/rust-clippy/master/index.html#future_not_send -[`get_last_with_len`]: https://rust-lang.github.io/rust-clippy/master/index.html#get_last_with_len -[`get_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#get_unwrap -[`identity_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#identity_op -[`if_let_mutex`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_let_mutex -[`if_let_redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_let_redundant_pattern_matching -[`if_let_some_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_let_some_result -[`if_not_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else -[`if_same_then_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else -[`ifs_same_cond`]: https://rust-lang.github.io/rust-clippy/master/index.html#ifs_same_cond -[`implicit_hasher`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_hasher -[`implicit_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_return -[`implicit_saturating_sub`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_sub -[`imprecise_flops`]: https://rust-lang.github.io/rust-clippy/master/index.html#imprecise_flops -[`inconsistent_digit_grouping`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_digit_grouping -[`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 -[`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 -[`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 -[`inline_always`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_always -[`inline_asm_x86_att_syntax`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_asm_x86_att_syntax -[`inline_asm_x86_intel_syntax`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_asm_x86_intel_syntax -[`inline_fn_without_body`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_fn_without_body -[`int_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#int_plus_one -[`integer_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_arithmetic -[`integer_division`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_division -[`into_iter_on_array`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_array -[`into_iter_on_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref -[`invalid_atomic_ordering`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_atomic_ordering -[`invalid_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_ref -[`invalid_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_regex -[`invalid_upcast_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_upcast_comparisons -[`invisible_characters`]: https://rust-lang.github.io/rust-clippy/master/index.html#invisible_characters -[`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements -[`iter_cloned_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_cloned_collect -[`iter_next_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_loop -[`iter_next_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_slice -[`iter_nth`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth -[`iter_nth_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth_zero -[`iter_skip_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_next -[`iterator_step_by_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iterator_step_by_zero -[`just_underscores_and_digits`]: https://rust-lang.github.io/rust-clippy/master/index.html#just_underscores_and_digits -[`large_const_arrays`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_const_arrays -[`large_digit_groups`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_digit_groups -[`large_enum_variant`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant -[`large_stack_arrays`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_stack_arrays -[`large_types_passed_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_types_passed_by_value -[`len_without_is_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty -[`len_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_zero -[`let_and_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return -[`let_underscore_drop`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_drop -[`let_underscore_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_lock -[`let_underscore_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_must_use -[`let_unit_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value -[`linkedlist`]: https://rust-lang.github.io/rust-clippy/master/index.html#linkedlist -[`logic_bug`]: https://rust-lang.github.io/rust-clippy/master/index.html#logic_bug -[`lossy_float_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#lossy_float_literal -[`macro_use_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#macro_use_imports -[`main_recursion`]: https://rust-lang.github.io/rust-clippy/master/index.html#main_recursion -[`manual_async_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_async_fn -[`manual_memcpy`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_memcpy -[`manual_non_exhaustive`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive -[`manual_ok_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_or -[`manual_range_contains`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains -[`manual_saturating_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic -[`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 -[`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 -[`map_entry`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_entry -[`map_err_ignore`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_err_ignore -[`map_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten -[`map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_identity -[`map_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or -[`match_as_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_as_ref -[`match_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_bool -[`match_like_matches_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro -[`match_on_vec_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_on_vec_items -[`match_overlapping_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_overlapping_arm -[`match_ref_pats`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_ref_pats -[`match_same_arms`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms -[`match_single_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_single_binding -[`match_wild_err_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_wild_err_arm -[`match_wildcard_for_single_variants`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_wildcard_for_single_variants -[`maybe_infinite_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#maybe_infinite_iter -[`mem_discriminant_non_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_discriminant_non_enum -[`mem_forget`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_forget -[`mem_replace_option_with_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_option_with_none -[`mem_replace_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default -[`mem_replace_with_uninit`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_uninit -[`min_max`]: https://rust-lang.github.io/rust-clippy/master/index.html#min_max -[`misaligned_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#misaligned_transmute -[`mismatched_target_os`]: https://rust-lang.github.io/rust-clippy/master/index.html#mismatched_target_os -[`misrefactored_assign_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#misrefactored_assign_op -[`missing_const_for_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn -[`missing_docs_in_private_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_docs_in_private_items -[`missing_errors_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc -[`missing_inline_in_public_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_inline_in_public_items -[`missing_safety_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_safety_doc -[`mistyped_literal_suffixes`]: https://rust-lang.github.io/rust-clippy/master/index.html#mistyped_literal_suffixes -[`mixed_case_hex_literals`]: https://rust-lang.github.io/rust-clippy/master/index.html#mixed_case_hex_literals -[`module_inception`]: https://rust-lang.github.io/rust-clippy/master/index.html#module_inception -[`module_name_repetitions`]: https://rust-lang.github.io/rust-clippy/master/index.html#module_name_repetitions -[`modulo_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#modulo_arithmetic -[`modulo_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#modulo_one -[`multiple_crate_versions`]: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_crate_versions -[`multiple_inherent_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_inherent_impl -[`must_use_candidate`]: https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate -[`must_use_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#must_use_unit -[`mut_from_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_from_ref -[`mut_mut`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_mut -[`mut_mutex_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_mutex_lock -[`mut_range_bound`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_range_bound -[`mutable_key_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#mutable_key_type -[`mutex_atomic`]: https://rust-lang.github.io/rust-clippy/master/index.html#mutex_atomic -[`mutex_integer`]: https://rust-lang.github.io/rust-clippy/master/index.html#mutex_integer -[`naive_bytecount`]: https://rust-lang.github.io/rust-clippy/master/index.html#naive_bytecount -[`needless_arbitrary_self_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_arbitrary_self_type -[`needless_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_bool -[`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 -[`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_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes -[`needless_pass_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value -[`needless_range_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop -[`needless_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_return -[`needless_update`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_update -[`neg_cmp_op_on_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#neg_cmp_op_on_partial_ord -[`neg_multiply`]: https://rust-lang.github.io/rust-clippy/master/index.html#neg_multiply -[`never_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#never_loop -[`new_ret_no_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_ret_no_self -[`new_without_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default -[`no_effect`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_effect -[`non_ascii_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_ascii_literal -[`nonminimal_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool -[`nonsensical_open_options`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonsensical_open_options -[`not_unsafe_ptr_arg_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref -[`ok_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#ok_expect -[`op_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#op_ref -[`option_as_ref_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref -[`option_env_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_env_unwrap -[`option_if_let_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_if_let_else -[`option_map_or_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_or_none -[`option_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unit_fn -[`option_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_option -[`or_fun_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call -[`out_of_bounds_indexing`]: https://rust-lang.github.io/rust-clippy/master/index.html#out_of_bounds_indexing -[`overflow_check_conditional`]: https://rust-lang.github.io/rust-clippy/master/index.html#overflow_check_conditional -[`panic`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic -[`panic_in_result_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_in_result_fn -[`panic_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_params -[`panicking_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#panicking_unwrap -[`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl -[`path_buf_push_overwrite`]: https://rust-lang.github.io/rust-clippy/master/index.html#path_buf_push_overwrite -[`pattern_type_mismatch`]: https://rust-lang.github.io/rust-clippy/master/index.html#pattern_type_mismatch -[`possible_missing_comma`]: https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma -[`precedence`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence -[`print_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_literal -[`print_stderr`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_stderr -[`print_stdout`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_stdout -[`print_with_newline`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_with_newline -[`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_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 -[`question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#question_mark -[`range_minus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_minus_one -[`range_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_plus_one -[`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 -[`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 -[`redundant_closure_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_call -[`redundant_closure_for_method_calls`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls -[`redundant_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else -[`redundant_field_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names -[`redundant_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern -[`redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching -[`redundant_pub_crate`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pub_crate -[`redundant_static_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes -[`ref_in_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_in_deref -[`ref_option_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_option_ref -[`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 -[`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts -[`rest_pat_in_fully_bound_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#rest_pat_in_fully_bound_structs -[`result_map_or_into_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_or_into_option -[`result_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unit_fn -[`result_unit_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_unit_err -[`reversed_empty_ranges`]: https://rust-lang.github.io/rust-clippy/master/index.html#reversed_empty_ranges -[`same_functions_in_if_condition`]: https://rust-lang.github.io/rust-clippy/master/index.html#same_functions_in_if_condition -[`same_item_push`]: https://rust-lang.github.io/rust-clippy/master/index.html#same_item_push -[`search_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#search_is_some -[`self_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#self_assignment -[`serde_api_misuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#serde_api_misuse -[`shadow_reuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_reuse -[`shadow_same`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_same -[`shadow_unrelated`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_unrelated -[`short_circuit_statement`]: https://rust-lang.github.io/rust-clippy/master/index.html#short_circuit_statement -[`should_assert_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_assert_eq -[`should_implement_trait`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait -[`similar_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#similar_names -[`single_char_add_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_add_str -[`single_char_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern -[`single_component_path_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports -[`single_element_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_element_loop -[`single_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match -[`single_match_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else -[`size_of_in_element_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#size_of_in_element_count -[`skip_while_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#skip_while_next -[`slow_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#slow_vector_initialization -[`stable_sort_primitive`]: https://rust-lang.github.io/rust-clippy/master/index.html#stable_sort_primitive -[`str_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#str_to_string -[`string_add`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_add -[`string_add_assign`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_add_assign -[`string_extend_chars`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_extend_chars -[`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 -[`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 -[`suspicious_assignment_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_assignment_formatting -[`suspicious_else_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_else_formatting -[`suspicious_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_map -[`suspicious_op_assign_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_op_assign_impl -[`suspicious_operation_groupings`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_operation_groupings -[`suspicious_unary_op_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_unary_op_formatting -[`tabs_in_doc_comments`]: https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments -[`temporary_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_assignment -[`temporary_cstring_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_cstring_as_ptr -[`to_digit_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_digit_is_some -[`to_string_in_display`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_string_in_display -[`todo`]: https://rust-lang.github.io/rust-clippy/master/index.html#todo -[`too_many_arguments`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments -[`too_many_lines`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_lines -[`toplevel_ref_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#toplevel_ref_arg -[`trait_duplication_in_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#trait_duplication_in_bounds -[`transmute_bytes_to_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_bytes_to_str -[`transmute_float_to_int`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_float_to_int -[`transmute_int_to_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_bool -[`transmute_int_to_char`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_char -[`transmute_int_to_float`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_float -[`transmute_ptr_to_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ptr -[`transmute_ptr_to_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ref -[`transmutes_expressible_as_ptr_casts`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmutes_expressible_as_ptr_casts -[`transmuting_null`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmuting_null -[`trivial_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#trivial_regex -[`trivially_copy_pass_by_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref -[`try_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#try_err -[`type_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity -[`type_repetition_in_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds -[`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 -[`uninit_assumed_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninit_assumed_init -[`unit_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg -[`unit_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_cmp -[`unit_return_expecting_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_return_expecting_ord -[`unknown_clippy_lints`]: https://rust-lang.github.io/rust-clippy/master/index.html#unknown_clippy_lints -[`unnecessary_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast -[`unnecessary_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_filter_map -[`unnecessary_fold`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_fold -[`unnecessary_lazy_evaluations`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations -[`unnecessary_mut_passed`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed -[`unnecessary_operation`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_operation -[`unnecessary_sort_by`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_sort_by -[`unnecessary_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_unwrap -[`unnecessary_wraps`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_wraps -[`unneeded_field_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_field_pattern -[`unneeded_wildcard_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_wildcard_pattern -[`unnested_or_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns -[`unreachable`]: https://rust-lang.github.io/rust-clippy/master/index.html#unreachable -[`unreadable_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#unreadable_literal -[`unsafe_derive_deserialize`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_derive_deserialize -[`unsafe_removed_from_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_removed_from_name -[`unsafe_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_vector_initialization -[`unseparated_literal_suffix`]: https://rust-lang.github.io/rust-clippy/master/index.html#unseparated_literal_suffix -[`unsound_collection_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsound_collection_transmute -[`unstable_as_mut_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#unstable_as_mut_slice -[`unstable_as_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#unstable_as_slice -[`unused_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_collect -[`unused_io_amount`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_io_amount -[`unused_label`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_label -[`unused_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_self -[`unused_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit -[`unusual_byte_groupings`]: https://rust-lang.github.io/rust-clippy/master/index.html#unusual_byte_groupings -[`unwrap_in_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_in_result -[`unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used -[`use_debug`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_debug -[`use_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_self -[`used_underscore_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding -[`useless_asref`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_asref -[`useless_attribute`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_attribute -[`useless_conversion`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion -[`useless_format`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_format -[`useless_let_if_seq`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_let_if_seq -[`useless_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_transmute -[`useless_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_vec -[`vec_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#vec_box -[`vec_resize_to_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#vec_resize_to_zero -[`verbose_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#verbose_bit_mask -[`verbose_file_reads`]: https://rust-lang.github.io/rust-clippy/master/index.html#verbose_file_reads -[`vtable_address_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#vtable_address_comparisons -[`while_immutable_condition`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_immutable_condition -[`while_let_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_loop -[`while_let_on_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_on_iterator -[`wildcard_dependencies`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_dependencies -[`wildcard_enum_match_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_enum_match_arm -[`wildcard_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports -[`wildcard_in_or_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_in_or_patterns -[`write_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#write_literal -[`write_with_newline`]: https://rust-lang.github.io/rust-clippy/master/index.html#write_with_newline -[`writeln_empty_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#writeln_empty_string -[`wrong_pub_self_convention`]: https://rust-lang.github.io/rust-clippy/master/index.html#wrong_pub_self_convention -[`wrong_self_convention`]: https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention -[`wrong_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#wrong_transmute -[`zero_divided_by_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_divided_by_zero -[`zero_prefixed_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_prefixed_literal -[`zero_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_ptr -[`zero_sized_map_values`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_sized_map_values -[`zst_offset`]: https://rust-lang.github.io/rust-clippy/master/index.html#zst_offset - diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index dec13e44a17f..000000000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,70 +0,0 @@ -# The Rust Code of Conduct - -A version of this document [can be found online](https://www.rust-lang.org/conduct.html). - -## Conduct - -**Contact**: [rust-mods@rust-lang.org](mailto:rust-mods@rust-lang.org) - -* We are committed to providing a friendly, safe and welcoming environment for all, regardless of level of experience, - gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, - religion, nationality, or other similar characteristic. -* On IRC, please avoid using overtly sexual nicknames or other nicknames that might detract from a friendly, safe and - welcoming environment for all. -* Please be kind and courteous. There's no need to be mean or rude. -* Respect that people have differences of opinion and that every design or implementation choice carries a trade-off and - numerous costs. There is seldom a right answer. -* Please keep unstructured critique to a minimum. If you have solid ideas you want to experiment with, make a fork and - see how it works. -* We will exclude you from interaction if you insult, demean or harass anyone. That is not welcome behavior. We - interpret the term "harassment" as including the definition in the Citizen - Code of Conduct; if you have any lack of clarity about what might be included in that concept, please read their - definition. In particular, we don't tolerate behavior that excludes people in socially marginalized groups. -* Private harassment is also unacceptable. No matter who you are, if you feel you have been or are being harassed or - made uncomfortable by a community member, please contact one of the channel ops or any of the [Rust moderation - team][mod_team] immediately. Whether you're a regular contributor or a newcomer, we care about making this community a - safe place for you and we've got your back. -* Likewise any spamming, trolling, flaming, baiting or other attention-stealing behavior is not welcome. - -## Moderation - - -These are the policies for upholding our community's standards of conduct. If you feel that a thread needs moderation, -please contact the [Rust moderation team][mod_team]. - -1. Remarks that violate the Rust standards of conduct, including hateful, hurtful, oppressive, or exclusionary remarks, - are not allowed. (Cursing is allowed, but never targeting another user, and never in a hateful manner.) -2. Remarks that moderators find inappropriate, whether listed in the code of conduct or not, are also not allowed. -3. Moderators will first respond to such remarks with a warning. -4. If the warning is unheeded, the user will be "kicked," i.e., kicked out of the communication channel to cool off. -5. If the user comes back and continues to make trouble, they will be banned, i.e., indefinitely excluded. -6. Moderators may choose at their discretion to un-ban the user if it was a first offense and they offer the offended - party a genuine apology. -7. If a moderator bans someone and you think it was unjustified, please take it up with that moderator, or with a - different moderator, **in private**. Complaints about bans in-channel are not allowed. -8. Moderators are held to a higher standard than other community members. If a moderator creates an inappropriate - situation, they should expect less leeway than others. - -In the Rust community we strive to go the extra step to look out for each other. Don't just aim to be technically -unimpeachable, try to be your best self. In particular, avoid flirting with offensive or sensitive issues, particularly -if they're off-topic; this all too often leads to unnecessary fights, hurt feelings, and damaged trust; worse, it can -drive people away from the community entirely. - -And if someone takes issue with something you said or did, resist the urge to be defensive. Just stop doing what it was -they complained about and apologize. Even if you feel you were misinterpreted or unfairly accused, chances are good -there was something you could've communicated better — remember that it's your responsibility to make your fellow -Rustaceans comfortable. Everyone wants to get along and we are all here first and foremost because we want to talk about -cool technology. You will find that people will be eager to assume good intent and forgive as long as you earn their -trust. - -The enforcement policies listed above apply to all official Rust venues; including official IRC channels (#rust, -#rust-internals, #rust-tools, #rust-libs, #rustc, #rust-beginners, #rust-docs, #rust-community, #rust-lang, and #cargo); -GitHub repositories under rust-lang, rust-lang-nursery, and rust-lang-deprecated; and all forums under rust-lang.org -(users.rust-lang.org, internals.rust-lang.org). For other projects adopting the Rust Code of Conduct, please contact the -maintainers of those projects for enforcement. If you wish to use this code of conduct for your own project, consider -explicitly mentioning your moderation policy or making a copy with your own moderation policy so as to avoid confusion. - -*Adapted from the [Node.js Policy on Trolling](http://blog.izs.me/post/30036893703/policy-on-trolling) as well as the -[Contributor Covenant v1.3.0](https://www.contributor-covenant.org/version/1/3/0/).* - -[mod_team]: https://www.rust-lang.org/team.html#Moderation-team diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 4cfeaa153a01..000000000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,345 +0,0 @@ -# Contributing to Clippy - -Hello fellow Rustacean! Great to see your interest in compiler internals and lints! - -**First**: if you're unsure or afraid of _anything_, just ask or submit the issue or pull request anyway. You won't be -yelled at for giving it your best effort. The worst that can happen is that you'll be politely asked to change -something. We appreciate any sort of contributions, and don't want a wall of rules to get in the way of that. - -Clippy welcomes contributions from everyone. There are many ways to contribute to Clippy and the following document -explains how you can contribute and how to get started. If you have any questions about contributing or need help with -anything, feel free to ask questions on issues or visit the `#clippy` on [Zulip]. - -All contributors are expected to follow the [Rust Code of Conduct]. - -- [Contributing to Clippy](#contributing-to-clippy) - - [Getting started](#getting-started) - - [High level approach](#high-level-approach) - - [Finding something to fix/improve](#finding-something-to-fiximprove) - - [Writing code](#writing-code) - - [Getting code-completion for rustc internals to work](#getting-code-completion-for-rustc-internals-to-work) - - [How Clippy works](#how-clippy-works) - - [Syncing changes between Clippy and `rust-lang/rust`](#syncing-changes-between-clippy-and-rust-langrust) - - [Patching git-subtree to work with big repos](#patching-git-subtree-to-work-with-big-repos) - - [Performing the sync from `rust-lang/rust` to Clippy](#performing-the-sync-from-rust-langrust-to-clippy) - - [Performing the sync from Clippy to `rust-lang/rust`](#performing-the-sync-from-clippy-to-rust-langrust) - - [Defining remotes](#defining-remotes) - - [Issue and PR triage](#issue-and-pr-triage) - - [Bors and Homu](#bors-and-homu) - - [Contributions](#contributions) - -[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/clippy -[Rust Code of Conduct]: https://www.rust-lang.org/policies/code-of-conduct - -## Getting started - -**Note: If this is your first time contributing to Clippy, you should -first read the [Basics docs](doc/basics.md).** - -### High level approach - -1. Find something to fix/improve -2. Change code (likely some file in `clippy_lints/src/`) -3. Follow the instructions in the [Basics docs](doc/basics.md) to get set up -4. Run `cargo test` in the root directory and wiggle code until it passes -5. Open a PR (also can be done after 2. if you run into problems) - -### Finding something to fix/improve - -All issues on Clippy are mentored, if you want help with a bug just ask -@Manishearth, @flip1995, @phansch or @yaahc. - -Some issues are easier than others. The [`good-first-issue`] label can be used to find the easy issues. -If you want to work on an issue, please leave a comment so that we can assign it to you! - -There are also some abandoned PRs, marked with [`S-inactive-closed`]. -Pretty often these PRs are nearly completed and just need some extra steps -(formatting, addressing review comments, ...) to be merged. If you want to -complete such a PR, please leave a comment in the PR and open a new one based -on it. - -Issues marked [`T-AST`] involve simple matching of the syntax tree structure, -and are generally easier than [`T-middle`] issues, which involve types -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]. -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]. - -[`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. -Note that [`E-medium`] issues may require some knowledge of Clippy internals or some -debugging to find the actual problem behind the issue. - -[`T-middle`] issues can be more involved and require verifying types. The [`ty`] module contains a -lot of methods that are useful, though one of the most useful would be `expr_ty` (gives the type of -an AST expression). `match_def_path()` in Clippy's `utils` module can also be useful. - -[`good-first-issue`]: https://github.com/rust-lang/rust-clippy/labels/good-first-issue -[`S-inactive-closed`]: https://github.com/rust-lang/rust-clippy/pulls?q=is%3Aclosed+label%3AS-inactive-closed -[`T-AST`]: https://github.com/rust-lang/rust-clippy/labels/T-AST -[`T-middle`]: https://github.com/rust-lang/rust-clippy/labels/T-middle -[`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 - -## Writing code - -Have a look at the [docs for writing lints][adding_lints] for more details. - -If you want to add a new lint or change existing ones apart from bugfixing, it's -also a good idea to give the [stability guarantees][rfc_stability] and -[lint categories][rfc_lint_cats] sections of the [Clippy 1.0 RFC][clippy_rfc] a -quick read. - -[adding_lints]: https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md -[clippy_rfc]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md -[rfc_stability]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#stability-guarantees -[rfc_lint_cats]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#lint-audit-and-categories - -## Getting code-completion for rustc internals to work - -Unfortunately, [`rust-analyzer`][ra_homepage] does not (yet?) understand how Clippy uses compiler-internals -using `extern crate` and it also needs to be able to read the source files of the rustc-compiler which are not -available via a `rustup` component at the time of writing. -To work around this, you need to have a copy of the [rustc-repo][rustc_repo] available which can be obtained via -`git clone https://github.com/rust-lang/rust/`. -Then you can run a `cargo dev` command to automatically make Clippy use the rustc-repo via path-dependencies -which rust-analyzer will be able to understand. -Run `cargo dev ra_setup --repo-path ` where `` is an absolute path to the rustc repo -you just cloned. -The command will add path-dependencies pointing towards rustc-crates inside the rustc repo to -Clippys `Cargo.toml`s and should allow rust-analyzer to understand most of the types that Clippy uses. -Just make sure to remove the dependencies again before finally making a pull request! - -[ra_homepage]: https://rust-analyzer.github.io/ -[rustc_repo]: https://github.com/rust-lang/rust/ - -## How Clippy works - -[`clippy_lints/src/lib.rs`][lint_crate_entry] imports all the different lint modules and registers in the [`LintStore`]. -For example, the [`else_if_without_else`][else_if_without_else] lint is registered like this: - -```rust -// ./clippy_lints/src/lib.rs - -// ... -pub mod else_if_without_else; -// ... - -pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) { - // ... - store.register_early_pass(|| box else_if_without_else::ElseIfWithoutElse); - // ... - - store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![ - // ... - LintId::of(&else_if_without_else::ELSE_IF_WITHOUT_ELSE), - // ... - ]); -} -``` - -The [`rustc_lint::LintStore`][`LintStore`] provides two methods to register lints: -[register_early_pass][reg_early_pass] and [register_late_pass][reg_late_pass]. Both take an object -that implements an [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass] respectively. This is done in -every single lint. It's worth noting that the majority of `clippy_lints/src/lib.rs` is autogenerated by `cargo dev -update_lints`. When you are writing your own lint, you can use that script to save you some time. - -```rust -// ./clippy_lints/src/else_if_without_else.rs - -use rustc_lint::{EarlyLintPass, EarlyContext}; - -// ... - -pub struct ElseIfWithoutElse; - -// ... - -impl EarlyLintPass for ElseIfWithoutElse { - // ... the functions needed, to make the lint work -} -``` - -The difference between `EarlyLintPass` and `LateLintPass` is that the methods of the `EarlyLintPass` trait only provide -AST information. The methods of the `LateLintPass` trait are executed after type checking and contain type information -via the `LateContext` parameter. - -That's why the `else_if_without_else` example uses the `register_early_pass` function. Because the -[actual lint logic][else_if_without_else] does not depend on any type information. - -[lint_crate_entry]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/lib.rs -[else_if_without_else]: https://github.com/rust-lang/rust-clippy/blob/4253aa7137cb7378acc96133c787e49a345c2b3c/clippy_lints/src/else_if_without_else.rs -[`LintStore`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LintStore.html -[reg_early_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LintStore.html#method.register_early_pass -[reg_late_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LintStore.html#method.register_late_pass -[early_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.EarlyLintPass.html -[late_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html - -## Syncing changes between Clippy and [`rust-lang/rust`] - -Clippy currently gets built with a pinned nightly version. - -In the `rust-lang/rust` repository, where rustc resides, there's a copy of Clippy -that compiler hackers modify from time to time to adapt to changes in the unstable -API of the compiler. - -We need to sync these changes back to this repository periodically, and the changes -made to this repository in the meantime also need to be synced to the `rust-lang/rust` repository. - -To avoid flooding the `rust-lang/rust` PR queue, this two-way sync process is done -in a bi-weekly basis if there's no urgent changes. This is done starting on the day of -the Rust stable release and then every other week. That way we guarantee that we keep -this repo up to date with the latest compiler API, and every feature in Clippy is available -for 2 weeks in nightly, before it can get to beta. For reference, the first sync -following this cadence was performed the 2020-08-27. - -This process is described in detail in the following sections. For general information -about `subtree`s in the Rust repository see [Rust's `CONTRIBUTING.md`][subtree]. - -### Patching git-subtree to work with big repos - -Currently there's a bug in `git-subtree` that prevents it from working properly -with the [`rust-lang/rust`] repo. There's an open PR to fix that, but it's stale. -Before continuing with the following steps, we need to manually apply that fix to -our local copy of `git-subtree`. - -You can get the patched version of `git-subtree` from [here][gitgitgadget-pr]. -Put this file under `/usr/lib/git-core` (taking a backup of the previous file) -and make sure it has the proper permissions: - -```bash -sudo cp --backup /path/to/patched/git-subtree.sh /usr/lib/git-core/git-subtree -sudo chmod --reference=/usr/lib/git-core/git-subtree~ /usr/lib/git-core/git-subtree -sudo chown --reference=/usr/lib/git-core/git-subtree~ /usr/lib/git-core/git-subtree -``` - -_Note:_ The first time running `git subtree push` a cache has to be built. This -involves going through the complete Clippy history once. For this you have to -increase the stack limit though, which you can do with `ulimit -s 60000`. -Make sure to run the `ulimit` command from the same session you call git subtree. - -_Note:_ If you are a Debian user, `dash` is the shell used by default for scripts instead of `sh`. -This shell has a hardcoded recursion limit set to 1000. In order to make this process work, -you need to force the script to run `bash` instead. You can do this by editing the first -line of the `git-subtree` script and changing `sh` to `bash`. - -### Performing the sync from [`rust-lang/rust`] to Clippy - -Here is a TL;DR version of the sync process (all of the following commands have -to be run inside the `rust` directory): - -1. Clone the [`rust-lang/rust`] repository or make sure it is up to date. -2. Checkout the commit from the latest available nightly. You can get it using `rustup check`. -3. Sync the changes to the rust-copy of Clippy to your Clippy fork: - ```bash - # Make sure to change `your-github-name` to your github name in the following command - git subtree push -P src/tools/clippy git@github.com:your-github-name/rust-clippy sync-from-rust - ``` - - _Note:_ This will directly push to the remote repository. You can also push - to your local copy by replacing the remote address with `/path/to/rust-clippy` - directory. - - _Note:_ Most of the time you have to create a merge commit in the - `rust-clippy` repo (this has to be done in the Clippy repo, not in the - rust-copy of Clippy): - ```bash - git fetch origin && git fetch upstream - git checkout sync-from-rust - git merge upstream/master - ``` -4. Open a PR to `rust-lang/rust-clippy` and wait for it to get merged (to - accelerate the process ping the `@rust-lang/clippy` team in your PR and/or - ~~annoy~~ ask them in the [Zulip] stream.) - -### Performing the sync from Clippy to [`rust-lang/rust`] - -All of the following commands have to be run inside the `rust` directory. - -1. Make sure Clippy itself is up-to-date by following the steps outlined in the previous -section if necessary. - -2. Sync the `rust-lang/rust-clippy` master to the rust-copy of Clippy: - ```bash - git checkout -b sync-from-clippy - git subtree pull -P src/tools/clippy https://github.com/rust-lang/rust-clippy master - ``` -3. Open a PR to [`rust-lang/rust`] - -### Defining remotes - -You may want to define remotes, so you don't have to type out the remote -addresses on every sync. You can do this with the following commands (these -commands still have to be run inside the `rust` directory): - -```bash -# Set clippy-upstream remote for pulls -$ git remote add clippy-upstream https://github.com/rust-lang/rust-clippy -# Make sure to not push to the upstream repo -$ git remote set-url --push clippy-upstream DISABLED -# Set clippy-origin remote to your fork for pushes -$ git remote add clippy-origin git@github.com:your-github-name/rust-clippy -# Set a local remote -$ git remote add clippy-local /path/to/rust-clippy -``` - -You can then sync with the remote names from above, e.g.: - -```bash -$ git subtree push -P src/tools/clippy clippy-local sync-from-rust -``` - -[gitgitgadget-pr]: https://github.com/gitgitgadget/git/pull/493 -[subtree]: https://rustc-dev-guide.rust-lang.org/contributing.html#external-dependencies-subtree -[`rust-lang/rust`]: https://github.com/rust-lang/rust - -## Issue and PR triage - -Clippy is following the [Rust triage procedure][triage] for issues and pull -requests. - -However, we are a smaller project with all contributors being volunteers -currently. Between writing new lints, fixing issues, reviewing pull requests and -responding to issues there may not always be enough time to stay on top of it -all. - -Our highest priority is fixing [crashes][l-crash] and [bugs][l-bug]. We don't -want Clippy to crash on your code and we want it to be as reliable as the -suggestions from Rust compiler errors. - -## Bors and Homu - -We use a bot powered by [Homu][homu] to help automate testing and landing of pull -requests in Clippy. The bot's username is @bors. - -You can find the Clippy bors queue [here][homu_queue]. - -If you have @bors permissions, you can find an overview of the available -commands [here][homu_instructions]. - -[triage]: https://forge.rust-lang.org/release/triage-procedure.html -[l-crash]: https://github.com/rust-lang/rust-clippy/labels/L-crash -[l-bug]: https://github.com/rust-lang/rust-clippy/labels/L-bug -[homu]: https://github.com/rust-lang/homu -[homu_instructions]: https://bors.rust-lang.org/ -[homu_queue]: https://bors.rust-lang.org/queue/clippy - -## Contributions - -Contributions to Clippy should be made in the form of GitHub pull requests. Each pull request will -be reviewed by a core contributor (someone with permission to land patches) and either landed in the -main tree or given feedback for changes that would be required. - -All code in this repository is under the [Apache-2.0] or the [MIT] license. - - - -[Apache-2.0]: https://www.apache.org/licenses/LICENSE-2.0 -[MIT]: https://opensource.org/licenses/MIT diff --git a/COPYRIGHT b/COPYRIGHT deleted file mode 100644 index 80d64472c70a..000000000000 --- a/COPYRIGHT +++ /dev/null @@ -1,7 +0,0 @@ -Copyright 2014-2020 The Rust Project Developers - -Licensed under the Apache License, Version 2.0 or the MIT license -, at your -option. All files in the project carrying such notice may not be -copied, modified, or distributed except according to those terms. diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index 7f9d22e594b9..000000000000 --- a/Cargo.toml +++ /dev/null @@ -1,56 +0,0 @@ -[package] -name = "clippy" -version = "0.0.212" -authors = [ - "Manish Goregaokar ", - "Andre Bogus ", - "Georg Brandl ", - "Martin Carton ", - "Oliver Schneider " -] -description = "A bunch of helpful lints to avoid common pitfalls in Rust" -repository = "https://github.com/rust-lang/rust-clippy" -readme = "README.md" -license = "MIT OR Apache-2.0" -keywords = ["clippy", "lint", "plugin"] -categories = ["development-tools", "development-tools::cargo-plugins"] -build = "build.rs" -edition = "2018" -publish = false - -[[bin]] -name = "cargo-clippy" -path = "src/main.rs" - -[[bin]] -name = "clippy-driver" -path = "src/driver.rs" - -[dependencies] -# begin automatic update -clippy_lints = { version = "0.0.212", path = "clippy_lints" } -# end automatic update -semver = "0.11" -rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util" } -tempfile = { version = "3.1.0", optional = true } - -[dev-dependencies] -cargo_metadata = "0.12" -compiletest_rs = { version = "0.5.0", features = ["tmp"] } -tester = "0.7" -clippy-mini-macro-test = { version = "0.2", path = "mini-macro" } -serde = { version = "1.0", features = ["derive"] } -derive-new = "0.5" - -# 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.0" - -[build-dependencies] -rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util" } - -[features] -deny-warnings = [] -integration = ["tempfile"] -internal-lints = ["clippy_lints/internal-lints"] diff --git a/LICENSE-APACHE b/LICENSE-APACHE deleted file mode 100644 index d821a4de2bed..000000000000 --- a/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright 2014-2020 The Rust Project Developers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/LICENSE-MIT b/LICENSE-MIT deleted file mode 100644 index b7c70dd4026d..000000000000 --- a/LICENSE-MIT +++ /dev/null @@ -1,27 +0,0 @@ -MIT License - -Copyright (c) 2014-2020 The Rust Project Developers - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md deleted file mode 100644 index dc931963726b..000000000000 --- a/README.md +++ /dev/null @@ -1,251 +0,0 @@ -# Clippy - -[![Clippy Test](https://github.com/rust-lang/rust-clippy/workflows/Clippy%20Test/badge.svg?branch=auto&event=push)](https://github.com/rust-lang/rust-clippy/actions?query=workflow%3A%22Clippy+Test%22+event%3Apush+branch%3Aauto) -[![License: MIT OR Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](#license) - -A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. - -[There are over 400 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) - -Lints are divided into categories, each with a default [lint level](https://doc.rust-lang.org/rustc/lints/levels.html). -You can choose how much Clippy is supposed to ~~annoy~~ help you by changing the lint level by category. - -Category | Description | Default level --- | -- | -- -`clippy::all` | all lints that are on by default (correctness, style, complexity, perf) | **warn/deny** -`clippy::correctness` | code that is outright wrong or very useless | **deny** -`clippy::style` | code that should be written in a more idiomatic way | **warn** -`clippy::complexity` | code that does something simple but in a complex way | **warn** -`clippy::perf` | code that can be written to run faster | **warn** -`clippy::pedantic` | lints which are rather strict or might have false positives | allow -`clippy::nursery` | new lints that are still under development | allow -`clippy::cargo` | lints for the cargo manifest | allow - -More to come, please [file an issue](https://github.com/rust-lang/rust-clippy/issues) if you have ideas! - -The [lint list](https://rust-lang.github.io/rust-clippy/master/index.html) also contains "restriction lints", which are -for things which are usually not considered "bad", but may be useful to turn on in specific cases. These should be used -very selectively, if at all. - -Table of contents: - -* [Usage instructions](#usage) -* [Configuration](#configuration) -* [Contributing](#contributing) -* [License](#license) - -## Usage - -Below are instructions on how to use Clippy as a subcommand, compiled from source -or in Travis CI. - -### As a cargo subcommand (`cargo clippy`) - -One way to use Clippy is by installing Clippy through rustup as a cargo -subcommand. - -#### Step 1: Install rustup - -You can install [rustup](https://rustup.rs/) on supported platforms. This will help -us install Clippy and its dependencies. - -If you already have rustup installed, update to ensure you have the latest -rustup and compiler: - -```terminal -rustup update -``` - -#### Step 2: Install Clippy - -Once you have rustup and the latest stable release (at least Rust 1.29) installed, run the following command: - -```terminal -rustup component add clippy -``` -If it says that it can't find the `clippy` component, please run `rustup self update`. - -#### Step 3: Run Clippy - -Now you can run Clippy by invoking the following command: - -```terminal -cargo clippy -``` - -#### Automatically applying Clippy suggestions - -Clippy can automatically apply some lint suggestions. -Note that this is still experimental and only supported on the nightly channel: - -```terminal -cargo clippy --fix -Z unstable-options -``` - -#### Workspaces - -All the usual workspace options should work with Clippy. For example the following command -will run Clippy on the `example` crate: - -```terminal -cargo clippy -p example -``` - -As with `cargo check`, this includes dependencies that are members of the workspace, like path dependencies. -If you want to run Clippy **only** on the given crate, use the `--no-deps` option like this: - -```terminal -cargo clippy -p example -- --no-deps -``` - -### Running Clippy from the command line without installing it - -To have cargo compile your crate with Clippy without Clippy installation -in your code, you can use: - -```terminal -cargo run --bin cargo-clippy --manifest-path=path_to_clippys_Cargo.toml -``` - -*Note:* Be sure that Clippy was compiled with the same version of rustc that cargo invokes here! - -### Travis CI - -You can add Clippy to Travis CI in the same way you use it locally: - -```yml -language: rust -rust: - - stable - - beta -before_script: - - rustup component add clippy -script: - - cargo clippy - # if you want the build job to fail when encountering warnings, use - - cargo clippy -- -D warnings - # in order to also check tests and non-default crate features, use - - cargo clippy --all-targets --all-features -- -D warnings - - cargo test - # etc. -``` - -If you are on nightly, It might happen that Clippy is not available for a certain nightly release. -In this case you can try to conditionally install Clippy from the Git repo. - -```yaml -language: rust -rust: - - nightly -before_script: - - rustup component add clippy --toolchain=nightly || cargo install --git https://github.com/rust-lang/rust-clippy/ --force clippy - # etc. -``` - -Note that adding `-D warnings` will cause your build to fail if **any** warnings are found in your code. -That includes warnings found by rustc (e.g. `dead_code`, etc.). If you want to avoid this and only cause -an error for Clippy warnings, use `#![deny(clippy::all)]` in your code or `-D clippy::all` on the command -line. (You can swap `clippy::all` with the specific lint category you are targeting.) - -## Configuration - -Some lints can be configured in a TOML file named `clippy.toml` or `.clippy.toml`. It contains a basic `variable = -value` mapping eg. - -```toml -blacklisted-names = ["toto", "tata", "titi"] -cognitive-complexity-threshold = 30 -``` - -See the [list of lints](https://rust-lang.github.io/rust-clippy/master/index.html) for more information about which -lints can be configured and the meaning of the variables. - -To deactivate the “for further information visit *lint-link*” message you can -define the `CLIPPY_DISABLE_DOCS_LINKS` environment variable. - -### Allowing/denying lints - -You can add options to your code to `allow`/`warn`/`deny` Clippy lints: - -* the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy::all)]`) - -* all lints using both the `clippy` and `clippy::pedantic` lint groups (`#![deny(clippy::all)]`, - `#![deny(clippy::pedantic)]`). Note that `clippy::pedantic` contains some very aggressive - lints prone to false positives. - -* only some lints (`#![deny(clippy::single_match, clippy::box_vec)]`, etc.) - -* `allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc. - -Note: `allow` means to suppress the lint for your code. With `warn` the lint -will only emit a warning, while with `deny` the lint will emit an error, when -triggering for your code. An error causes clippy to exit with an error code, so -is useful in scripts like CI/CD. - -If you do not want to include your lint levels in your code, you can globally -enable/disable lints by passing extra flags to Clippy during the run: - -To allow `lint_name`, run - -```terminal -cargo clippy -- -A clippy::lint_name -``` - -And to warn on `lint_name`, run - -```terminal -cargo clippy -- -W clippy::lint_name -``` - -This also works with lint groups. For example you -can run Clippy with warnings for all lints enabled: -```terminal -cargo clippy -- -W clippy::pedantic -``` - -If you care only about a single lint, you can allow all others and then explicitly warn on -the lint(s) you are interested in: -```terminal -cargo clippy -- -A clippy::all -W clippy::useless_format -W clippy::... -``` - -### Specifying the minimum supported Rust version - -Projects that intend to support old versions of Rust can disable lints pertaining to newer features by -specifying the minimum supported Rust version (MSRV) in the clippy configuration file. - -```toml -msrv = "1.30.0" -``` - -The MSRV can also be specified as an inner attribute, like below. - -```rust -#![feature(custom_inner_attributes)] -#![clippy::msrv = "1.30.0"] - -fn main() { - ... -} -``` - -You can also omit the patch version when specifying the MSRV, so `msrv = 1.30` -is equivalent to `msrv = 1.30.0`. - -Note: `custom_inner_attributes` is an unstable feature so it has to be enabled explicitly. - -Lints that recognize this configuration option can be found [here](https://rust-lang.github.io/rust-clippy/master/index.html#msrv) - -## Contributing - -If you want to contribute to Clippy, you can find more information in [CONTRIBUTING.md](https://github.com/rust-lang/rust-clippy/blob/master/CONTRIBUTING.md). - -## License - -Copyright 2014-2020 The Rust Project Developers - -Licensed under the Apache License, Version 2.0 or the MIT license -, at your -option. Files in the project may not be -copied, modified, or distributed except according to those terms. diff --git a/build.rs b/build.rs deleted file mode 100644 index 018375dbada8..000000000000 --- a/build.rs +++ /dev/null @@ -1,19 +0,0 @@ -fn main() { - // Forward the profile to the main compilation - println!("cargo:rustc-env=PROFILE={}", std::env::var("PROFILE").unwrap()); - // Don't rebuild even if nothing changed - println!("cargo:rerun-if-changed=build.rs"); - // forward git repo hashes we build at - println!( - "cargo:rustc-env=GIT_HASH={}", - rustc_tools_util::get_commit_hash().unwrap_or_default() - ); - println!( - "cargo:rustc-env=COMMIT_DATE={}", - rustc_tools_util::get_commit_date().unwrap_or_default() - ); - println!( - "cargo:rustc-env=RUSTC_RELEASE_CHANNEL={}", - rustc_tools_util::get_channel().unwrap_or_default() - ); -} diff --git a/clippy_dev/Cargo.toml b/clippy_dev/Cargo.toml deleted file mode 100644 index b8a4a20114bb..000000000000 --- a/clippy_dev/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "clippy_dev" -version = "0.0.1" -authors = ["Philipp Hansch "] -edition = "2018" - -[dependencies] -bytecount = "0.6" -clap = "2.33" -itertools = "0.9" -opener = "0.4" -regex = "1" -shell-escape = "0.1" -walkdir = "2" - -[features] -deny-warnings = [] diff --git a/clippy_dev/src/bless.rs b/clippy_dev/src/bless.rs deleted file mode 100644 index 645098e4cfcd..000000000000 --- a/clippy_dev/src/bless.rs +++ /dev/null @@ -1,74 +0,0 @@ -//! `bless` updates the reference files in the repo with changed output files -//! from the last test run. - -use std::env; -use std::ffi::OsStr; -use std::fs; -use std::lazy::SyncLazy; -use std::path::PathBuf; -use walkdir::WalkDir; - -use crate::clippy_project_root; - -// NOTE: this is duplicated with tests/cargo/mod.rs What to do? -pub static CARGO_TARGET_DIR: SyncLazy = SyncLazy::new(|| match env::var_os("CARGO_TARGET_DIR") { - Some(v) => v.into(), - None => env::current_dir().unwrap().join("target"), -}); - -pub fn bless() { - let test_dirs = [ - clippy_project_root().join("tests").join("ui"), - clippy_project_root().join("tests").join("ui-toml"), - clippy_project_root().join("tests").join("ui-cargo"), - ]; - for test_dir in &test_dirs { - WalkDir::new(test_dir) - .into_iter() - .filter_map(Result::ok) - .filter(|f| f.path().extension() == Some(OsStr::new("rs"))) - .for_each(|f| { - update_reference_file(f.path().with_extension("stdout")); - update_reference_file(f.path().with_extension("stderr")); - update_reference_file(f.path().with_extension("fixed")); - }); - } -} - -fn update_reference_file(reference_file_path: PathBuf) { - let test_output_path = build_dir().join(PathBuf::from(reference_file_path.file_name().unwrap())); - let relative_reference_file_path = reference_file_path.strip_prefix(clippy_project_root()).unwrap(); - - // If compiletest did not write any changes during the test run, - // we don't have to update anything - if !test_output_path.exists() { - return; - } - - let test_output_file = fs::read(&test_output_path).expect("Unable to read test output file"); - let reference_file = fs::read(&reference_file_path).unwrap_or_default(); - - if test_output_file != reference_file { - // If a test run caused an output file to change, update the reference file - println!("updating {}", &relative_reference_file_path.display()); - fs::copy(test_output_path, &reference_file_path).expect("Could not update reference file"); - - // We need to re-read the file now because it was potentially updated from copying - let reference_file = fs::read(&reference_file_path).unwrap_or_default(); - - if reference_file.is_empty() { - // If we copied over an empty output file, we remove the now empty reference file - println!("removing {}", &relative_reference_file_path.display()); - fs::remove_file(reference_file_path).expect("Could not remove reference file"); - } - } -} - -fn build_dir() -> PathBuf { - let profile = env::var("PROFILE").unwrap_or_else(|_| "debug".to_string()); - let mut path = PathBuf::new(); - path.push(CARGO_TARGET_DIR.clone()); - path.push(profile); - path.push("test_build_base"); - path -} diff --git a/clippy_dev/src/fmt.rs b/clippy_dev/src/fmt.rs deleted file mode 100644 index 6b528d219df2..000000000000 --- a/clippy_dev/src/fmt.rs +++ /dev/null @@ -1,194 +0,0 @@ -use crate::clippy_project_root; -use shell_escape::escape; -use std::ffi::OsStr; -use std::path::Path; -use std::process::{self, Command}; -use std::{fs, io}; -use walkdir::WalkDir; - -#[derive(Debug)] -pub enum CliError { - CommandFailed(String), - IoError(io::Error), - RustfmtNotInstalled, - WalkDirError(walkdir::Error), - RaSetupActive, -} - -impl From for CliError { - fn from(error: io::Error) -> Self { - Self::IoError(error) - } -} - -impl From for CliError { - fn from(error: walkdir::Error) -> Self { - Self::WalkDirError(error) - } -} - -struct FmtContext { - check: bool, - verbose: bool, -} - -// the "main" function of cargo dev fmt -pub fn run(check: bool, verbose: bool) { - fn try_run(context: &FmtContext) -> Result { - let mut success = true; - - let project_root = clippy_project_root(); - - // if we added a local rustc repo as path dependency to clippy for rust analyzer, we do NOT want to - // format because rustfmt would also format the entire rustc repo as it is a local - // dependency - if fs::read_to_string(project_root.join("Cargo.toml")) - .expect("Failed to read clippy Cargo.toml") - .contains(&"[target.'cfg(NOT_A_PLATFORM)'.dependencies]") - { - return Err(CliError::RaSetupActive); - } - - rustfmt_test(context)?; - - success &= cargo_fmt(context, project_root.as_path())?; - success &= cargo_fmt(context, &project_root.join("clippy_dev"))?; - success &= cargo_fmt(context, &project_root.join("rustc_tools_util"))?; - - for entry in WalkDir::new(project_root.join("tests")) { - let entry = entry?; - let path = entry.path(); - - if path.extension() != Some("rs".as_ref()) - || entry.file_name() == "ice-3891.rs" - // Avoid rustfmt bug rust-lang/rustfmt#1873 - || cfg!(windows) && entry.file_name() == "implicit_hasher.rs" - { - continue; - } - - success &= rustfmt(context, &path)?; - } - - Ok(success) - } - - fn output_err(err: CliError) { - match err { - CliError::CommandFailed(command) => { - eprintln!("error: A command failed! `{}`", command); - }, - CliError::IoError(err) => { - eprintln!("error: {}", err); - }, - CliError::RustfmtNotInstalled => { - eprintln!("error: rustfmt nightly is not installed."); - }, - CliError::WalkDirError(err) => { - eprintln!("error: {}", err); - }, - CliError::RaSetupActive => { - eprintln!( - "error: a local rustc repo is enabled as path dependency via `cargo dev ra_setup`. -Not formatting because that would format the local repo as well! -Please revert the changes to Cargo.tomls first." - ); - }, - } - } - - let context = FmtContext { check, verbose }; - let result = try_run(&context); - let code = match result { - Ok(true) => 0, - Ok(false) => { - eprintln!(); - eprintln!("Formatting check failed."); - eprintln!("Run `cargo dev fmt` to update formatting."); - 1 - }, - Err(err) => { - output_err(err); - 1 - }, - }; - process::exit(code); -} - -fn format_command(program: impl AsRef, dir: impl AsRef, args: &[impl AsRef]) -> String { - let arg_display: Vec<_> = args.iter().map(|a| escape(a.as_ref().to_string_lossy())).collect(); - - format!( - "cd {} && {} {}", - escape(dir.as_ref().to_string_lossy()), - escape(program.as_ref().to_string_lossy()), - arg_display.join(" ") - ) -} - -fn exec( - context: &FmtContext, - program: impl AsRef, - dir: impl AsRef, - args: &[impl AsRef], -) -> Result { - if context.verbose { - println!("{}", format_command(&program, &dir, args)); - } - - let mut child = Command::new(&program).current_dir(&dir).args(args.iter()).spawn()?; - let code = child.wait()?; - let success = code.success(); - - if !context.check && !success { - return Err(CliError::CommandFailed(format_command(&program, &dir, args))); - } - - Ok(success) -} - -fn cargo_fmt(context: &FmtContext, path: &Path) -> Result { - let mut args = vec!["+nightly", "fmt", "--all"]; - if context.check { - args.push("--"); - args.push("--check"); - } - let success = exec(context, "cargo", path, &args)?; - - Ok(success) -} - -fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> { - let program = "rustfmt"; - let dir = std::env::current_dir()?; - let args = &["+nightly", "--version"]; - - if context.verbose { - println!("{}", format_command(&program, &dir, args)); - } - - let output = Command::new(&program).current_dir(&dir).args(args.iter()).output()?; - - if output.status.success() { - Ok(()) - } else if std::str::from_utf8(&output.stderr) - .unwrap_or("") - .starts_with("error: 'rustfmt' is not installed") - { - Err(CliError::RustfmtNotInstalled) - } else { - Err(CliError::CommandFailed(format_command(&program, &dir, args))) - } -} - -fn rustfmt(context: &FmtContext, path: &Path) -> Result { - let mut args = vec!["+nightly".as_ref(), path.as_os_str()]; - if context.check { - args.push("--check".as_ref()); - } - let success = exec(context, "rustfmt", std::env::current_dir()?, &args)?; - if !success { - eprintln!("rustfmt failed on {}", path.display()); - } - Ok(success) -} diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs deleted file mode 100644 index 17cc08ee10fe..000000000000 --- a/clippy_dev/src/lib.rs +++ /dev/null @@ -1,545 +0,0 @@ -#![cfg_attr(feature = "deny-warnings", deny(warnings))] -#![feature(once_cell)] - -use itertools::Itertools; -use regex::Regex; -use std::collections::HashMap; -use std::ffi::OsStr; -use std::fs; -use std::lazy::SyncLazy; -use std::path::{Path, PathBuf}; -use walkdir::WalkDir; - -pub mod bless; -pub mod fmt; -pub mod new_lint; -pub mod ra_setup; -pub mod serve; -pub mod stderr_length_check; -pub mod update_lints; - -static DEC_CLIPPY_LINT_RE: SyncLazy = SyncLazy::new(|| { - Regex::new( - r#"(?x) - declare_clippy_lint!\s*[\{(] - (?:\s+///.*)* - \s+pub\s+(?P[A-Z_][A-Z_0-9]*)\s*,\s* - (?P[a-z_]+)\s*,\s* - "(?P(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})] -"#, - ) - .unwrap() -}); - -static DEC_DEPRECATED_LINT_RE: SyncLazy = SyncLazy::new(|| { - Regex::new( - r#"(?x) - declare_deprecated_lint!\s*[{(]\s* - (?:\s+///.*)* - \s+pub\s+(?P[A-Z_][A-Z_0-9]*)\s*,\s* - "(?P(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})] -"#, - ) - .unwrap() -}); -static NL_ESCAPE_RE: SyncLazy = SyncLazy::new(|| Regex::new(r#"\\\n\s*"#).unwrap()); - -pub static DOCS_LINK: &str = "https://rust-lang.github.io/rust-clippy/master/index.html"; - -/// Lint data parsed from the Clippy source code. -#[derive(Clone, PartialEq, Debug)] -pub struct Lint { - pub name: String, - pub group: String, - pub desc: String, - pub deprecation: Option, - pub module: String, -} - -impl Lint { - #[must_use] - pub fn new(name: &str, group: &str, desc: &str, deprecation: Option<&str>, module: &str) -> Self { - Self { - name: name.to_lowercase(), - group: group.to_string(), - desc: NL_ESCAPE_RE.replace(&desc.replace("\\\"", "\""), "").to_string(), - deprecation: deprecation.map(ToString::to_string), - module: module.to_string(), - } - } - - /// Returns all non-deprecated lints and non-internal lints - #[must_use] - pub fn usable_lints(lints: &[Self]) -> Vec { - lints - .iter() - .filter(|l| l.deprecation.is_none() && !l.group.starts_with("internal")) - .cloned() - .collect() - } - - /// Returns all internal lints (not `internal_warn` lints) - #[must_use] - pub fn internal_lints(lints: &[Self]) -> Vec { - lints.iter().filter(|l| l.group == "internal").cloned().collect() - } - - /// Returns all deprecated lints - #[must_use] - pub fn deprecated_lints(lints: &[Self]) -> Vec { - lints.iter().filter(|l| l.deprecation.is_some()).cloned().collect() - } - - /// Returns the lints in a `HashMap`, grouped by the different lint groups - #[must_use] - pub fn by_lint_group(lints: impl Iterator) -> HashMap> { - lints.map(|lint| (lint.group.to_string(), lint)).into_group_map() - } -} - -/// Generates the Vec items for `register_lint_group` calls in `clippy_lints/src/lib.rs`. -#[must_use] -pub fn gen_lint_group_list<'a>(lints: impl Iterator) -> Vec { - lints - .map(|l| format!(" LintId::of(&{}::{}),", l.module, l.name.to_uppercase())) - .sorted() - .collect::>() -} - -/// Generates the `pub mod module_name` list in `clippy_lints/src/lib.rs`. -#[must_use] -pub fn gen_modules_list<'a>(lints: impl Iterator) -> Vec { - lints - .map(|l| &l.module) - .unique() - .map(|module| format!("mod {};", module)) - .sorted() - .collect::>() -} - -/// Generates the list of lint links at the bottom of the README -#[must_use] -pub fn gen_changelog_lint_list<'a>(lints: impl Iterator) -> Vec { - lints - .sorted_by_key(|l| &l.name) - .map(|l| format!("[`{}`]: {}#{}", l.name, DOCS_LINK, l.name)) - .collect() -} - -/// Generates the `register_removed` code in `./clippy_lints/src/lib.rs`. -#[must_use] -pub fn gen_deprecated<'a>(lints: impl Iterator) -> Vec { - lints - .flat_map(|l| { - l.deprecation - .clone() - .map(|depr_text| { - vec![ - " store.register_removed(".to_string(), - format!(" \"clippy::{}\",", l.name), - format!(" \"{}\",", depr_text), - " );".to_string(), - ] - }) - .expect("only deprecated lints should be passed") - }) - .collect::>() -} - -#[must_use] -pub fn gen_register_lint_list<'a>( - internal_lints: impl Iterator, - usable_lints: impl Iterator, -) -> Vec { - let header = " store.register_lints(&[".to_string(); - let footer = " ]);".to_string(); - let internal_lints = internal_lints - .sorted_by_key(|l| format!(" &{}::{},", l.module, l.name.to_uppercase())) - .map(|l| { - format!( - " #[cfg(feature = \"internal-lints\")]\n &{}::{},", - l.module, - l.name.to_uppercase() - ) - }); - let other_lints = usable_lints - .sorted_by_key(|l| format!(" &{}::{},", l.module, l.name.to_uppercase())) - .map(|l| format!(" &{}::{},", l.module, l.name.to_uppercase())) - .sorted(); - let mut lint_list = vec![header]; - lint_list.extend(internal_lints); - lint_list.extend(other_lints); - lint_list.push(footer); - lint_list -} - -/// Gathers all files in `src/clippy_lints` and gathers all lints inside -pub fn gather_all() -> impl Iterator { - lint_files().flat_map(|f| gather_from_file(&f)) -} - -fn gather_from_file(dir_entry: &walkdir::DirEntry) -> impl Iterator { - let content = fs::read_to_string(dir_entry.path()).unwrap(); - let path = dir_entry.path(); - let filename = path.file_stem().unwrap(); - let path_buf = path.with_file_name(filename); - let mut rel_path = path_buf - .strip_prefix(clippy_project_root().join("clippy_lints/src")) - .expect("only files in `clippy_lints/src` should be looked at"); - // If the lints are stored in mod.rs, we get the module name from - // the containing directory: - if filename == "mod" { - rel_path = rel_path.parent().unwrap(); - } - - let module = rel_path - .components() - .map(|c| c.as_os_str().to_str().unwrap()) - .collect::>() - .join("::"); - - parse_contents(&content, &module) -} - -fn parse_contents(content: &str, module: &str) -> impl Iterator { - let lints = DEC_CLIPPY_LINT_RE - .captures_iter(content) - .map(|m| Lint::new(&m["name"], &m["cat"], &m["desc"], None, module)); - let deprecated = DEC_DEPRECATED_LINT_RE - .captures_iter(content) - .map(|m| Lint::new(&m["name"], "Deprecated", &m["desc"], Some(&m["desc"]), module)); - // Removing the `.collect::>().into_iter()` causes some lifetime issues due to the map - lints.chain(deprecated).collect::>().into_iter() -} - -/// Collects all .rs files in the `clippy_lints/src` directory -fn lint_files() -> impl Iterator { - // We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories. - // Otherwise we would not collect all the lints, for example in `clippy_lints/src/methods/`. - let path = clippy_project_root().join("clippy_lints/src"); - WalkDir::new(path) - .into_iter() - .filter_map(Result::ok) - .filter(|f| f.path().extension() == Some(OsStr::new("rs"))) -} - -/// Whether a file has had its text changed or not -#[derive(PartialEq, Debug)] -pub struct FileChange { - pub changed: bool, - pub new_lines: String, -} - -/// Replaces a region in a file delimited by two lines matching regexes. -/// -/// `path` is the relative path to the file on which you want to perform the replacement. -/// -/// See `replace_region_in_text` for documentation of the other options. -pub fn replace_region_in_file( - path: &Path, - start: &str, - end: &str, - replace_start: bool, - write_back: bool, - replacements: F, -) -> FileChange -where - F: FnOnce() -> Vec, -{ - let contents = fs::read_to_string(path).unwrap_or_else(|e| panic!("Cannot read from {}: {}", path.display(), e)); - let file_change = replace_region_in_text(&contents, start, end, replace_start, replacements); - - if write_back { - if let Err(e) = fs::write(path, file_change.new_lines.as_bytes()) { - panic!("Cannot write to {}: {}", path.display(), e); - } - } - file_change -} - -/// Replaces a region in a text delimited by two lines matching regexes. -/// -/// * `text` is the input text on which you want to perform the replacement -/// * `start` is a `&str` that describes the delimiter line before the region you want to replace. -/// As the `&str` will be converted to a `Regex`, this can contain regex syntax, too. -/// * `end` is a `&str` that describes the delimiter line until where the replacement should happen. -/// As the `&str` will be converted to a `Regex`, this can contain regex syntax, too. -/// * If `replace_start` is true, the `start` delimiter line is replaced as well. The `end` -/// delimiter line is never replaced. -/// * `replacements` is a closure that has to return a `Vec` which contains the new text. -/// -/// If you want to perform the replacement on files instead of already parsed text, -/// use `replace_region_in_file`. -/// -/// # Example -/// -/// ``` -/// let the_text = "replace_start\nsome text\nthat will be replaced\nreplace_end"; -/// let result = -/// clippy_dev::replace_region_in_text(the_text, "replace_start", "replace_end", false, || { -/// vec!["a different".to_string(), "text".to_string()] -/// }) -/// .new_lines; -/// assert_eq!("replace_start\na different\ntext\nreplace_end", result); -/// ``` -pub fn replace_region_in_text(text: &str, start: &str, end: &str, replace_start: bool, replacements: F) -> FileChange -where - F: FnOnce() -> Vec, -{ - let replace_it = replacements(); - let mut in_old_region = false; - let mut found = false; - let mut new_lines = vec![]; - let start = Regex::new(start).unwrap(); - let end = Regex::new(end).unwrap(); - - for line in text.lines() { - if in_old_region { - if end.is_match(line) { - in_old_region = false; - new_lines.extend(replace_it.clone()); - new_lines.push(line.to_string()); - } - } else if start.is_match(line) { - if !replace_start { - new_lines.push(line.to_string()); - } - in_old_region = true; - found = true; - } else { - new_lines.push(line.to_string()); - } - } - - if !found { - // This happens if the provided regex in `clippy_dev/src/main.rs` does not match in the - // given text or file. Most likely this is an error on the programmer's side and the Regex - // is incorrect. - eprintln!("error: regex \n{:?}\ndoesn't match. You may have to update it.", start); - std::process::exit(1); - } - - let mut new_lines = new_lines.join("\n"); - if text.ends_with('\n') { - new_lines.push('\n'); - } - let changed = new_lines != text; - FileChange { changed, new_lines } -} - -/// Returns the path to the Clippy project directory -#[must_use] -pub fn clippy_project_root() -> PathBuf { - let current_dir = std::env::current_dir().unwrap(); - for path in current_dir.ancestors() { - let result = std::fs::read_to_string(path.join("Cargo.toml")); - if let Err(err) = &result { - if err.kind() == std::io::ErrorKind::NotFound { - continue; - } - } - - let content = result.unwrap(); - if content.contains("[package]\nname = \"clippy\"") { - return path.to_path_buf(); - } - } - panic!("error: Can't determine root of project. Please run inside a Clippy working dir."); -} - -#[test] -fn test_parse_contents() { - let result: Vec = parse_contents( - r#" -declare_clippy_lint! { - pub PTR_ARG, - style, - "really long \ - text" -} - -declare_clippy_lint!{ - pub DOC_MARKDOWN, - pedantic, - "single line" -} - -/// some doc comment -declare_deprecated_lint! { - pub SHOULD_ASSERT_EQ, - "`assert!()` will be more flexible with RFC 2011" -} - "#, - "module_name", - ) - .collect(); - - let expected = vec![ - Lint::new("ptr_arg", "style", "really long text", None, "module_name"), - Lint::new("doc_markdown", "pedantic", "single line", None, "module_name"), - Lint::new( - "should_assert_eq", - "Deprecated", - "`assert!()` will be more flexible with RFC 2011", - Some("`assert!()` will be more flexible with RFC 2011"), - "module_name", - ), - ]; - assert_eq!(expected, result); -} - -#[test] -fn test_replace_region() { - let text = "\nabc\n123\n789\ndef\nghi"; - let expected = FileChange { - changed: true, - new_lines: "\nabc\nhello world\ndef\nghi".to_string(), - }; - let result = replace_region_in_text(text, r#"^\s*abc$"#, r#"^\s*def"#, false, || { - vec!["hello world".to_string()] - }); - assert_eq!(expected, result); -} - -#[test] -fn test_replace_region_with_start() { - let text = "\nabc\n123\n789\ndef\nghi"; - let expected = FileChange { - changed: true, - new_lines: "\nhello world\ndef\nghi".to_string(), - }; - let result = replace_region_in_text(text, r#"^\s*abc$"#, r#"^\s*def"#, true, || { - vec!["hello world".to_string()] - }); - assert_eq!(expected, result); -} - -#[test] -fn test_replace_region_no_changes() { - let text = "123\n456\n789"; - let expected = FileChange { - changed: false, - new_lines: "123\n456\n789".to_string(), - }; - let result = replace_region_in_text(text, r#"^\s*123$"#, r#"^\s*456"#, false, Vec::new); - assert_eq!(expected, result); -} - -#[test] -fn test_usable_lints() { - let lints = vec![ - Lint::new("should_assert_eq", "Deprecated", "abc", Some("Reason"), "module_name"), - Lint::new("should_assert_eq2", "Not Deprecated", "abc", None, "module_name"), - Lint::new("should_assert_eq2", "internal", "abc", None, "module_name"), - Lint::new("should_assert_eq2", "internal_style", "abc", None, "module_name"), - ]; - let expected = vec![Lint::new( - "should_assert_eq2", - "Not Deprecated", - "abc", - None, - "module_name", - )]; - assert_eq!(expected, Lint::usable_lints(&lints)); -} - -#[test] -fn test_by_lint_group() { - let lints = vec![ - Lint::new("should_assert_eq", "group1", "abc", None, "module_name"), - Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"), - Lint::new("incorrect_match", "group1", "abc", None, "module_name"), - ]; - let mut expected: HashMap> = HashMap::new(); - expected.insert( - "group1".to_string(), - vec![ - Lint::new("should_assert_eq", "group1", "abc", None, "module_name"), - Lint::new("incorrect_match", "group1", "abc", None, "module_name"), - ], - ); - expected.insert( - "group2".to_string(), - vec![Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")], - ); - assert_eq!(expected, Lint::by_lint_group(lints.into_iter())); -} - -#[test] -fn test_gen_changelog_lint_list() { - let lints = vec![ - Lint::new("should_assert_eq", "group1", "abc", None, "module_name"), - Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"), - ]; - let expected = vec![ - format!("[`should_assert_eq`]: {}#should_assert_eq", DOCS_LINK.to_string()), - format!("[`should_assert_eq2`]: {}#should_assert_eq2", DOCS_LINK.to_string()), - ]; - assert_eq!(expected, gen_changelog_lint_list(lints.iter())); -} - -#[test] -fn test_gen_deprecated() { - let lints = vec![ - Lint::new( - "should_assert_eq", - "group1", - "abc", - Some("has been superseded by should_assert_eq2"), - "module_name", - ), - Lint::new( - "another_deprecated", - "group2", - "abc", - Some("will be removed"), - "module_name", - ), - ]; - let expected: Vec = vec![ - " store.register_removed(", - " \"clippy::should_assert_eq\",", - " \"has been superseded by should_assert_eq2\",", - " );", - " store.register_removed(", - " \"clippy::another_deprecated\",", - " \"will be removed\",", - " );", - ] - .into_iter() - .map(String::from) - .collect(); - assert_eq!(expected, gen_deprecated(lints.iter())); -} - -#[test] -#[should_panic] -fn test_gen_deprecated_fail() { - let lints = vec![Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")]; - let _ = gen_deprecated(lints.iter()); -} - -#[test] -fn test_gen_modules_list() { - let lints = vec![ - Lint::new("should_assert_eq", "group1", "abc", None, "module_name"), - Lint::new("incorrect_stuff", "group3", "abc", None, "another_module"), - ]; - let expected = vec!["mod another_module;".to_string(), "mod module_name;".to_string()]; - assert_eq!(expected, gen_modules_list(lints.iter())); -} - -#[test] -fn test_gen_lint_group_list() { - let lints = vec![ - Lint::new("abc", "group1", "abc", None, "module_name"), - Lint::new("should_assert_eq", "group1", "abc", None, "module_name"), - Lint::new("internal", "internal_style", "abc", None, "module_name"), - ]; - let expected = vec![ - " LintId::of(&module_name::ABC),".to_string(), - " LintId::of(&module_name::INTERNAL),".to_string(), - " LintId::of(&module_name::SHOULD_ASSERT_EQ),".to_string(), - ]; - assert_eq!(expected, gen_lint_group_list(lints.iter())); -} diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs deleted file mode 100644 index 4fdae38e3ab7..000000000000 --- a/clippy_dev/src/main.rs +++ /dev/null @@ -1,160 +0,0 @@ -#![cfg_attr(feature = "deny-warnings", deny(warnings))] - -use clap::{App, Arg, ArgMatches, SubCommand}; -use clippy_dev::{bless, fmt, new_lint, ra_setup, serve, stderr_length_check, update_lints}; - -fn main() { - let matches = get_clap_config(); - - match matches.subcommand() { - ("bless", Some(_)) => { - bless::bless(); - }, - ("fmt", Some(matches)) => { - fmt::run(matches.is_present("check"), matches.is_present("verbose")); - }, - ("update_lints", Some(matches)) => { - if matches.is_present("print-only") { - update_lints::print_lints(); - } else if matches.is_present("check") { - update_lints::run(update_lints::UpdateMode::Check); - } else { - update_lints::run(update_lints::UpdateMode::Change); - } - }, - ("new_lint", Some(matches)) => { - match new_lint::create( - matches.value_of("pass"), - matches.value_of("name"), - matches.value_of("category"), - ) { - Ok(_) => update_lints::run(update_lints::UpdateMode::Change), - Err(e) => eprintln!("Unable to create lint: {}", e), - } - }, - ("limit_stderr_length", _) => { - stderr_length_check::check(); - }, - ("ra_setup", Some(matches)) => ra_setup::run(matches.value_of("rustc-repo-path")), - ("serve", Some(matches)) => { - let port = matches.value_of("port").unwrap().parse().unwrap(); - let lint = matches.value_of("lint"); - serve::run(port, lint); - }, - _ => {}, - } -} - -fn get_clap_config<'a>() -> ArgMatches<'a> { - App::new("Clippy developer tooling") - .subcommand(SubCommand::with_name("bless").about("bless the test output changes")) - .subcommand( - SubCommand::with_name("fmt") - .about("Run rustfmt on all projects and tests") - .arg( - Arg::with_name("check") - .long("check") - .help("Use the rustfmt --check option"), - ) - .arg( - Arg::with_name("verbose") - .short("v") - .long("verbose") - .help("Echo commands run"), - ), - ) - .subcommand( - SubCommand::with_name("update_lints") - .about("Updates lint registration and information from the source code") - .long_about( - "Makes sure that:\n \ - * 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 \ - * all lints are registered in the lint store", - ) - .arg(Arg::with_name("print-only").long("print-only").help( - "Print a table of lints to STDOUT. \ - This does not include deprecated and internal lints. \ - (Does not modify any files)", - )) - .arg( - Arg::with_name("check") - .long("check") - .help("Checks that `cargo dev update_lints` has been run. Used on CI."), - ), - ) - .subcommand( - SubCommand::with_name("new_lint") - .about("Create new lint and run `cargo dev update_lints`") - .arg( - Arg::with_name("pass") - .short("p") - .long("pass") - .help("Specify whether the lint runs during the early or late pass") - .takes_value(true) - .possible_values(&["early", "late"]) - .required(true), - ) - .arg( - Arg::with_name("name") - .short("n") - .long("name") - .help("Name of the new lint in snake case, ex: fn_too_long") - .takes_value(true) - .required(true), - ) - .arg( - Arg::with_name("category") - .short("c") - .long("category") - .help("What category the lint belongs to") - .default_value("nursery") - .possible_values(&[ - "style", - "correctness", - "complexity", - "perf", - "pedantic", - "restriction", - "cargo", - "nursery", - "internal", - "internal_warn", - ]) - .takes_value(true), - ), - ) - .subcommand( - SubCommand::with_name("limit_stderr_length") - .about("Ensures that stderr files do not grow longer than a certain amount of lines."), - ) - .subcommand( - SubCommand::with_name("ra_setup") - .about("Alter dependencies so rust-analyzer can find rustc internals") - .arg( - Arg::with_name("rustc-repo-path") - .long("repo-path") - .short("r") - .help("The path to a rustc repo that will be used for setting the dependencies") - .takes_value(true) - .value_name("path") - .required(true), - ), - ) - .subcommand( - SubCommand::with_name("serve") - .about("Launch a local 'ALL the Clippy Lints' website in a browser") - .arg( - Arg::with_name("port") - .long("port") - .short("p") - .help("Local port for the http server") - .default_value("8000") - .validator_os(serve::validate_port), - ) - .arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")), - ) - .get_matches() -} diff --git a/clippy_dev/src/new_lint.rs b/clippy_dev/src/new_lint.rs deleted file mode 100644 index d951ca0e6308..000000000000 --- a/clippy_dev/src/new_lint.rs +++ /dev/null @@ -1,219 +0,0 @@ -use crate::clippy_project_root; -use std::fs::{self, OpenOptions}; -use std::io::prelude::*; -use std::io::{self, ErrorKind}; -use std::path::{Path, PathBuf}; - -struct LintData<'a> { - pass: &'a str, - name: &'a str, - category: &'a str, - project_root: PathBuf, -} - -trait Context { - fn context>(self, text: C) -> Self; -} - -impl Context for io::Result { - fn context>(self, text: C) -> Self { - match self { - Ok(t) => Ok(t), - Err(e) => { - let message = format!("{}: {}", text.as_ref(), e); - Err(io::Error::new(ErrorKind::Other, message)) - }, - } - } -} - -/// Creates the files required to implement and test a new lint and runs `update_lints`. -/// -/// # Errors -/// -/// This function errors out if the files couldn't be created or written to. -pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str>) -> io::Result<()> { - let lint = LintData { - pass: pass.expect("`pass` argument is validated by clap"), - name: lint_name.expect("`name` argument is validated by clap"), - category: category.expect("`category` argument is validated by clap"), - project_root: clippy_project_root(), - }; - - create_lint(&lint).context("Unable to create lint implementation")?; - create_test(&lint).context("Unable to create a test for the new lint") -} - -fn create_lint(lint: &LintData) -> io::Result<()> { - let (pass_type, pass_lifetimes, pass_import, context_import) = match lint.pass { - "early" => ("EarlyLintPass", "", "use rustc_ast::ast::*;", "EarlyContext"), - "late" => ("LateLintPass", "<'_>", "use rustc_hir::*;", "LateContext"), - _ => { - unreachable!("`pass_type` should only ever be `early` or `late`!"); - }, - }; - - let camel_case_name = to_camel_case(lint.name); - let lint_contents = get_lint_file_contents( - pass_type, - pass_lifetimes, - lint.name, - &camel_case_name, - lint.category, - pass_import, - context_import, - ); - - let lint_path = format!("clippy_lints/src/{}.rs", lint.name); - write_file(lint.project_root.join(&lint_path), lint_contents.as_bytes()) -} - -fn create_test(lint: &LintData) -> io::Result<()> { - fn create_project_layout>(lint_name: &str, location: P, case: &str, hint: &str) -> io::Result<()> { - let mut path = location.into().join(case); - fs::create_dir(&path)?; - write_file(path.join("Cargo.toml"), get_manifest_contents(lint_name, hint))?; - - path.push("src"); - fs::create_dir(&path)?; - let header = format!("// compile-flags: --crate-name={}", lint_name); - write_file(path.join("main.rs"), get_test_file_contents(lint_name, Some(&header)))?; - - Ok(()) - } - - if lint.category == "cargo" { - let relative_test_dir = format!("tests/ui-cargo/{}", lint.name); - let test_dir = lint.project_root.join(relative_test_dir); - fs::create_dir(&test_dir)?; - - create_project_layout(lint.name, &test_dir, "fail", "Content that triggers the lint goes here")?; - create_project_layout(lint.name, &test_dir, "pass", "This file should not trigger the lint") - } else { - let test_path = format!("tests/ui/{}.rs", lint.name); - let test_contents = get_test_file_contents(lint.name, None); - write_file(lint.project_root.join(test_path), test_contents) - } -} - -fn write_file, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> { - fn inner(path: &Path, contents: &[u8]) -> io::Result<()> { - OpenOptions::new() - .write(true) - .create_new(true) - .open(path)? - .write_all(contents) - } - - inner(path.as_ref(), contents.as_ref()).context(format!("writing to file: {}", path.as_ref().display())) -} - -fn to_camel_case(name: &str) -> String { - name.split('_') - .map(|s| { - if s.is_empty() { - String::from("") - } else { - [&s[0..1].to_uppercase(), &s[1..]].concat() - } - }) - .collect() -} - -fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String { - let mut contents = format!( - "#![warn(clippy::{})] - -fn main() {{ - // test code goes here -}} -", - lint_name - ); - - if let Some(header) = header_commands { - contents = format!("{}\n{}", header, contents); - } - - contents -} - -fn get_manifest_contents(lint_name: &str, hint: &str) -> String { - format!( - r#" -# {} - -[package] -name = "{}" -version = "0.1.0" -publish = false - -[workspace] -"#, - hint, lint_name - ) -} - -fn get_lint_file_contents( - pass_type: &str, - pass_lifetimes: &str, - lint_name: &str, - camel_case_name: &str, - category: &str, - pass_import: &str, - context_import: &str, -) -> String { - format!( - "use rustc_lint::{{{type}, {context_import}}}; -use rustc_session::{{declare_lint_pass, declare_tool_lint}}; -{pass_import} - -declare_clippy_lint! {{ - /// **What it does:** - /// - /// **Why is this bad?** - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// // example code where clippy issues a warning - /// ``` - /// Use instead: - /// ```rust - /// // example code which does not raise clippy warning - /// ``` - pub {name_upper}, - {category}, - \"default lint description\" -}} - -declare_lint_pass!({name_camel} => [{name_upper}]); - -impl {type}{lifetimes} for {name_camel} {{}} -", - type=pass_type, - lifetimes=pass_lifetimes, - name_upper=lint_name.to_uppercase(), - name_camel=camel_case_name, - category=category, - pass_import=pass_import, - context_import=context_import - ) -} - -#[test] -fn test_camel_case() { - let s = "a_lint"; - let s2 = to_camel_case(s); - assert_eq!(s2, "ALint"); - - let name = "a_really_long_new_lint"; - let name2 = to_camel_case(name); - assert_eq!(name2, "AReallyLongNewLint"); - - let name3 = "lint__name"; - let name4 = to_camel_case(name3); - assert_eq!(name4, "LintName"); -} diff --git a/clippy_dev/src/ra_setup.rs b/clippy_dev/src/ra_setup.rs deleted file mode 100644 index 40bf4a9505a8..000000000000 --- a/clippy_dev/src/ra_setup.rs +++ /dev/null @@ -1,100 +0,0 @@ -#![allow(clippy::filter_map)] - -use std::fs; -use std::fs::File; -use std::io::prelude::*; -use std::path::PathBuf; - -// This module takes an absolute path to a rustc repo and alters the dependencies to point towards -// the respective rustc subcrates instead of using extern crate xyz. -// This allows rust analyzer to analyze rustc internals and show proper information inside clippy -// code. See https://github.com/rust-analyzer/rust-analyzer/issues/3517 and https://github.com/rust-lang/rust-clippy/issues/5514 for details - -pub fn run(rustc_path: Option<&str>) { - // we can unwrap here because the arg is required by clap - let rustc_path = PathBuf::from(rustc_path.unwrap()); - assert!(rustc_path.is_dir(), "path is not a directory"); - let rustc_source_basedir = rustc_path.join("compiler"); - assert!( - rustc_source_basedir.is_dir(), - "are you sure the path leads to a rustc repo?" - ); - - let clippy_root_manifest = fs::read_to_string("Cargo.toml").expect("failed to read ./Cargo.toml"); - let clippy_root_lib_rs = fs::read_to_string("src/driver.rs").expect("failed to read ./src/driver.rs"); - inject_deps_into_manifest( - &rustc_source_basedir, - "Cargo.toml", - &clippy_root_manifest, - &clippy_root_lib_rs, - ) - .expect("Failed to inject deps into ./Cargo.toml"); - - let clippy_lints_manifest = - fs::read_to_string("clippy_lints/Cargo.toml").expect("failed to read ./clippy_lints/Cargo.toml"); - let clippy_lints_lib_rs = - fs::read_to_string("clippy_lints/src/lib.rs").expect("failed to read ./clippy_lints/src/lib.rs"); - inject_deps_into_manifest( - &rustc_source_basedir, - "clippy_lints/Cargo.toml", - &clippy_lints_manifest, - &clippy_lints_lib_rs, - ) - .expect("Failed to inject deps into ./clippy_lints/Cargo.toml"); -} - -fn inject_deps_into_manifest( - rustc_source_dir: &PathBuf, - manifest_path: &str, - cargo_toml: &str, - lib_rs: &str, -) -> std::io::Result<()> { - // do not inject deps if we have aleady done so - if cargo_toml.contains("[target.'cfg(NOT_A_PLATFORM)'.dependencies]") { - eprintln!( - "cargo dev ra_setup: warning: deps already found inside {}, doing nothing.", - manifest_path - ); - return Ok(()); - } - - let extern_crates = lib_rs - .lines() - // get the deps - .filter(|line| line.starts_with("extern crate")) - // we have something like "extern crate foo;", we only care about the "foo" - // ↓ ↓ - // extern crate rustc_middle; - .map(|s| &s[13..(s.len() - 1)]); - - let new_deps = extern_crates.map(|dep| { - // format the dependencies that are going to be put inside the Cargo.toml - format!( - "{dep} = {{ path = \"{source_path}/{dep}\" }}\n", - dep = dep, - source_path = rustc_source_dir.display() - ) - }); - - // format a new [dependencies]-block with the new deps we need to inject - let mut all_deps = String::from("[target.'cfg(NOT_A_PLATFORM)'.dependencies]\n"); - new_deps.for_each(|dep_line| { - all_deps.push_str(&dep_line); - }); - all_deps.push_str("\n[dependencies]\n"); - - // replace "[dependencies]" with - // [dependencies] - // dep1 = { path = ... } - // dep2 = { path = ... } - // etc - let new_manifest = cargo_toml.replacen("[dependencies]\n", &all_deps, 1); - - // println!("{}", new_manifest); - let mut file = File::create(manifest_path)?; - file.write_all(new_manifest.as_bytes())?; - - println!("Dependency paths injected: {}", manifest_path); - - Ok(()) -} diff --git a/clippy_dev/src/serve.rs b/clippy_dev/src/serve.rs deleted file mode 100644 index a46c0e4d3f0a..000000000000 --- a/clippy_dev/src/serve.rs +++ /dev/null @@ -1,64 +0,0 @@ -use std::ffi::{OsStr, OsString}; -use std::path::Path; -use std::process::Command; -use std::thread; -use std::time::{Duration, SystemTime}; - -pub fn run(port: u16, lint: Option<&str>) -> ! { - let mut url = Some(match lint { - None => format!("http://localhost:{}", port), - Some(lint) => format!("http://localhost:{}/#{}", port, lint), - }); - - loop { - if mtime("util/gh-pages/lints.json") < mtime("clippy_lints/src") { - Command::new("python3") - .arg("util/export.py") - .spawn() - .unwrap() - .wait() - .unwrap(); - } - if let Some(url) = url.take() { - thread::spawn(move || { - Command::new("python3") - .arg("-m") - .arg("http.server") - .arg(port.to_string()) - .current_dir("util/gh-pages") - .spawn() - .unwrap(); - // Give some time for python to start - thread::sleep(Duration::from_millis(500)); - // Launch browser after first export.py has completed and http.server is up - let _ = opener::open(url); - }); - } - thread::sleep(Duration::from_millis(1000)); - } -} - -fn mtime(path: impl AsRef) -> SystemTime { - let path = path.as_ref(); - if path.is_dir() { - path.read_dir() - .into_iter() - .flatten() - .flatten() - .map(|entry| mtime(&entry.path())) - .max() - .unwrap_or(SystemTime::UNIX_EPOCH) - } else { - path.metadata() - .and_then(|metadata| metadata.modified()) - .unwrap_or(SystemTime::UNIX_EPOCH) - } -} - -#[allow(clippy::missing_errors_doc)] -pub fn validate_port(arg: &OsStr) -> Result<(), OsString> { - match arg.to_string_lossy().parse::() { - Ok(_port) => Ok(()), - Err(err) => Err(OsString::from(err.to_string())), - } -} diff --git a/clippy_dev/src/stderr_length_check.rs b/clippy_dev/src/stderr_length_check.rs deleted file mode 100644 index e02b6f7da5f7..000000000000 --- a/clippy_dev/src/stderr_length_check.rs +++ /dev/null @@ -1,51 +0,0 @@ -use crate::clippy_project_root; -use std::ffi::OsStr; -use std::fs; -use std::path::{Path, PathBuf}; -use walkdir::WalkDir; - -// The maximum length allowed for stderr files. -// -// We limit this because small files are easier to deal with than bigger files. -const LENGTH_LIMIT: usize = 200; - -pub fn check() { - let exceeding_files: Vec<_> = exceeding_stderr_files(); - - if !exceeding_files.is_empty() { - eprintln!("Error: stderr files exceeding limit of {} lines:", LENGTH_LIMIT); - for (path, count) in exceeding_files { - println!("{}: {}", path.display(), count); - } - std::process::exit(1); - } -} - -fn exceeding_stderr_files() -> Vec<(PathBuf, usize)> { - // We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories. - WalkDir::new(clippy_project_root().join("tests/ui")) - .into_iter() - .filter_map(Result::ok) - .filter(|f| !f.file_type().is_dir()) - .filter_map(|e| { - let p = e.into_path(); - let count = count_linenumbers(&p); - if p.extension() == Some(OsStr::new("stderr")) && count > LENGTH_LIMIT { - Some((p, count)) - } else { - None - } - }) - .collect() -} - -#[must_use] -fn count_linenumbers(filepath: &Path) -> usize { - match fs::read(filepath) { - Ok(content) => bytecount::count(&content, b'\n'), - Err(e) => { - eprintln!("Failed to read file: {}", e); - 0 - }, - } -} diff --git a/clippy_dev/src/update_lints.rs b/clippy_dev/src/update_lints.rs deleted file mode 100644 index edf6c5f57a49..000000000000 --- a/clippy_dev/src/update_lints.rs +++ /dev/null @@ -1,149 +0,0 @@ -use crate::{ - gather_all, gen_changelog_lint_list, gen_deprecated, gen_lint_group_list, gen_modules_list, gen_register_lint_list, - replace_region_in_file, Lint, DOCS_LINK, -}; -use std::path::Path; - -#[derive(Clone, Copy, PartialEq)] -pub enum UpdateMode { - Check, - Change, -} - -#[allow(clippy::too_many_lines)] -pub fn run(update_mode: UpdateMode) { - let lint_list: Vec = gather_all().collect(); - - let internal_lints = Lint::internal_lints(&lint_list); - let deprecated_lints = Lint::deprecated_lints(&lint_list); - let usable_lints = Lint::usable_lints(&lint_list); - let mut sorted_usable_lints = usable_lints.clone(); - sorted_usable_lints.sort_by_key(|lint| lint.name.clone()); - - let usable_lint_count = round_to_fifty(usable_lints.len()); - - let mut file_change = false; - - file_change |= replace_region_in_file( - Path::new("README.md"), - &format!( - r#"\[There are over \d+ lints included in this crate!\]\({}\)"#, - DOCS_LINK - ), - "", - true, - update_mode == UpdateMode::Change, - || { - vec![format!( - "[There are over {} lints included in this crate!]({})", - usable_lint_count, DOCS_LINK - )] - }, - ) - .changed; - - file_change |= replace_region_in_file( - Path::new("CHANGELOG.md"), - "", - "", - false, - update_mode == UpdateMode::Change, - || gen_changelog_lint_list(usable_lints.iter().chain(deprecated_lints.iter())), - ) - .changed; - - file_change |= replace_region_in_file( - Path::new("clippy_lints/src/lib.rs"), - "begin deprecated lints", - "end deprecated lints", - false, - update_mode == UpdateMode::Change, - || gen_deprecated(deprecated_lints.iter()), - ) - .changed; - - file_change |= replace_region_in_file( - Path::new("clippy_lints/src/lib.rs"), - "begin register lints", - "end register lints", - false, - update_mode == UpdateMode::Change, - || gen_register_lint_list(internal_lints.iter(), usable_lints.iter()), - ) - .changed; - - file_change |= replace_region_in_file( - Path::new("clippy_lints/src/lib.rs"), - "begin lints modules", - "end lints modules", - false, - update_mode == UpdateMode::Change, - || gen_modules_list(usable_lints.iter()), - ) - .changed; - - // Generate lists of lints in the clippy::all lint group - file_change |= replace_region_in_file( - Path::new("clippy_lints/src/lib.rs"), - r#"store.register_group\(true, "clippy::all""#, - r#"\]\);"#, - false, - update_mode == UpdateMode::Change, - || { - // clippy::all should only include the following lint groups: - let all_group_lints = usable_lints.iter().filter(|l| { - l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf" - }); - - gen_lint_group_list(all_group_lints) - }, - ) - .changed; - - // Generate the list of lints for all other lint groups - for (lint_group, lints) in Lint::by_lint_group(usable_lints.into_iter().chain(internal_lints)) { - file_change |= replace_region_in_file( - Path::new("clippy_lints/src/lib.rs"), - &format!("store.register_group\\(true, \"clippy::{}\"", lint_group), - r#"\]\);"#, - false, - update_mode == UpdateMode::Change, - || gen_lint_group_list(lints.iter()), - ) - .changed; - } - - if update_mode == UpdateMode::Check && file_change { - println!( - "Not all lints defined properly. \ - Please run `cargo dev update_lints` to make sure all lints are defined properly." - ); - std::process::exit(1); - } -} - -pub fn print_lints() { - let lint_list: Vec = gather_all().collect(); - let usable_lints = Lint::usable_lints(&lint_list); - let usable_lint_count = usable_lints.len(); - let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter()); - - for (lint_group, mut lints) in grouped_by_lint_group { - if lint_group == "Deprecated" { - continue; - } - println!("\n## {}", lint_group); - - lints.sort_by_key(|l| l.name.clone()); - - for lint in lints { - println!("* [{}]({}#{}) ({})", lint.name, DOCS_LINK, lint.name, lint.desc); - } - } - - println!("there are {} lints", usable_lint_count); -} - -fn round_to_fifty(count: usize) -> usize { - count / 50 * 50 -} diff --git a/clippy_dummy/Cargo.toml b/clippy_dummy/Cargo.toml deleted file mode 100644 index 7b11795fafdc..000000000000 --- a/clippy_dummy/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "clippy_dummy" # rename to clippy before publishing -version = "0.0.303" -authors = ["Manish Goregaokar "] -edition = "2018" -readme = "crates-readme.md" -description = "A bunch of helpful lints to avoid common pitfalls in Rust." -build = 'build.rs' - -repository = "https://github.com/rust-lang/rust-clippy" - -license = "MIT OR Apache-2.0" -keywords = ["clippy", "lint", "plugin"] -categories = ["development-tools", "development-tools::cargo-plugins"] - -[build-dependencies] -term = "0.6" diff --git a/clippy_dummy/PUBLISH.md b/clippy_dummy/PUBLISH.md deleted file mode 100644 index 8e420ec959a2..000000000000 --- a/clippy_dummy/PUBLISH.md +++ /dev/null @@ -1,6 +0,0 @@ -This is a dummy crate to publish to crates.io. It primarily exists to ensure -that folks trying to install clippy from crates.io get redirected to the -`rustup` technique. - -Before publishing, be sure to rename `clippy_dummy` to `clippy` in `Cargo.toml`, -it has a different name to avoid workspace issues. diff --git a/clippy_dummy/build.rs b/clippy_dummy/build.rs deleted file mode 100644 index 21af4f8244f4..000000000000 --- a/clippy_dummy/build.rs +++ /dev/null @@ -1,42 +0,0 @@ -use term::color::{GREEN, RED, WHITE}; -use term::{Attr, Error, Result}; - -fn main() { - if foo().is_err() { - eprintln!( - "error: Clippy is no longer available via crates.io\n\n\ - help: please run `rustup component add clippy` instead" - ); - } - std::process::exit(1); -} - -fn foo() -> Result<()> { - let mut t = term::stderr().ok_or(Error::NotSupported)?; - - t.attr(Attr::Bold)?; - t.fg(RED)?; - write!(t, "\nerror: ")?; - - t.reset()?; - t.fg(WHITE)?; - writeln!(t, "Clippy is no longer available via crates.io\n")?; - - t.attr(Attr::Bold)?; - t.fg(GREEN)?; - write!(t, "help: ")?; - - t.reset()?; - t.fg(WHITE)?; - write!(t, "please run `")?; - - t.attr(Attr::Bold)?; - write!(t, "rustup component add clippy")?; - - t.reset()?; - t.fg(WHITE)?; - writeln!(t, "` instead")?; - - t.reset()?; - Ok(()) -} diff --git a/clippy_dummy/crates-readme.md b/clippy_dummy/crates-readme.md deleted file mode 100644 index 0decae8b9103..000000000000 --- a/clippy_dummy/crates-readme.md +++ /dev/null @@ -1,9 +0,0 @@ -Installing clippy via crates.io is deprecated. Please use the following: - -```terminal -rustup component add clippy -``` - -on a Rust version 1.29 or later. You may need to run `rustup self update` if it complains about a missing clippy binary. - -See [the homepage](https://github.com/rust-lang/rust-clippy/#clippy) for more information diff --git a/clippy_dummy/src/main.rs b/clippy_dummy/src/main.rs deleted file mode 100644 index a118834f1fd4..000000000000 --- a/clippy_dummy/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - panic!("This shouldn't even compile") -} diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml deleted file mode 100644 index 7697eba650ac..000000000000 --- a/clippy_lints/Cargo.toml +++ /dev/null @@ -1,41 +0,0 @@ -[package] -name = "clippy_lints" -# begin automatic update -version = "0.0.212" -# end automatic update -authors = [ - "Manish Goregaokar ", - "Andre Bogus ", - "Georg Brandl ", - "Martin Carton " -] -description = "A bunch of helpful lints to avoid common pitfalls in Rust" -repository = "https://github.com/rust-lang/rust-clippy" -readme = "README.md" -license = "MIT OR Apache-2.0" -keywords = ["clippy", "lint", "plugin"] -edition = "2018" - -[dependencies] -cargo_metadata = "0.12" -if_chain = "1.0.0" -itertools = "0.9" -pulldown-cmark = { version = "0.8", default-features = false } -quine-mc_cluskey = "0.2.2" -regex-syntax = "0.6" -serde = { version = "1.0", features = ["derive"] } -smallvec = { version = "1", features = ["union"] } -toml = "0.5.3" -unicode-normalization = "0.1" -semver = "0.11" -rustc-semver="1.1.0" -# NOTE: cargo requires serde feat in its url dep -# see -url = { version = "2.1.0", features = ["serde"] } -quote = "1" -syn = { version = "1", features = ["full"] } - -[features] -deny-warnings = [] -# build clippy with internal lints enabled, off by default -internal-lints = [] diff --git a/clippy_lints/README.md b/clippy_lints/README.md deleted file mode 100644 index 513583b7e349..000000000000 --- a/clippy_lints/README.md +++ /dev/null @@ -1 +0,0 @@ -This crate contains Clippy lints. For the main crate, check [GitHub](https://github.com/rust-lang/rust-clippy). diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs deleted file mode 100644 index 1d511a86c909..000000000000 --- a/clippy_lints/src/approx_const.rs +++ /dev/null @@ -1,117 +0,0 @@ -use crate::utils::span_lint; -use rustc_ast::ast::{FloatTy, LitFloatType, LitKind}; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::symbol; -use std::f64::consts as f64; - -declare_clippy_lint! { - /// **What it does:** Checks for floating point literals that approximate - /// constants which are defined in - /// [`std::f32::consts`](https://doc.rust-lang.org/stable/std/f32/consts/#constants) - /// or - /// [`std::f64::consts`](https://doc.rust-lang.org/stable/std/f64/consts/#constants), - /// respectively, suggesting to use the predefined constant. - /// - /// **Why is this bad?** Usually, the definition in the standard library is more - /// precise than what people come up with. If you find that your definition is - /// actually more precise, please [file a Rust - /// issue](https://github.com/rust-lang/rust/issues). - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let x = 3.14; - /// let y = 1_f64 / x; - /// ``` - /// Use predefined constants instead: - /// ```rust - /// let x = std::f32::consts::PI; - /// let y = std::f64::consts::FRAC_1_PI; - /// ``` - pub APPROX_CONSTANT, - correctness, - "the approximate of a known float constant (in `std::fXX::consts`)" -} - -// Tuples are of the form (constant, name, min_digits) -const KNOWN_CONSTS: [(f64, &str, usize); 18] = [ - (f64::E, "E", 4), - (f64::FRAC_1_PI, "FRAC_1_PI", 4), - (f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5), - (f64::FRAC_2_PI, "FRAC_2_PI", 5), - (f64::FRAC_2_SQRT_PI, "FRAC_2_SQRT_PI", 5), - (f64::FRAC_PI_2, "FRAC_PI_2", 5), - (f64::FRAC_PI_3, "FRAC_PI_3", 5), - (f64::FRAC_PI_4, "FRAC_PI_4", 5), - (f64::FRAC_PI_6, "FRAC_PI_6", 5), - (f64::FRAC_PI_8, "FRAC_PI_8", 5), - (f64::LN_10, "LN_10", 5), - (f64::LN_2, "LN_2", 5), - (f64::LOG10_E, "LOG10_E", 5), - (f64::LOG2_E, "LOG2_E", 5), - (f64::LOG2_10, "LOG2_10", 5), - (f64::LOG10_2, "LOG10_2", 5), - (f64::PI, "PI", 3), - (f64::SQRT_2, "SQRT_2", 5), -]; - -declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]); - -impl<'tcx> LateLintPass<'tcx> for ApproxConstant { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if let ExprKind::Lit(lit) = &e.kind { - check_lit(cx, &lit.node, e); - } - } -} - -fn check_lit(cx: &LateContext<'_>, lit: &LitKind, e: &Expr<'_>) { - match *lit { - LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty { - FloatTy::F32 => check_known_consts(cx, e, s, "f32"), - FloatTy::F64 => check_known_consts(cx, e, s, "f64"), - }, - LitKind::Float(s, LitFloatType::Unsuffixed) => check_known_consts(cx, e, s, "f{32, 64}"), - _ => (), - } -} - -fn check_known_consts(cx: &LateContext<'_>, e: &Expr<'_>, s: symbol::Symbol, module: &str) { - let s = s.as_str(); - if s.parse::().is_ok() { - for &(constant, name, min_digits) in &KNOWN_CONSTS { - if is_approx_const(constant, &s, min_digits) { - span_lint( - cx, - APPROX_CONSTANT, - e.span, - &format!( - "approximate value of `{}::consts::{}` found. \ - Consider using it directly", - module, &name - ), - ); - return; - } - } - } -} - -/// Returns `false` if the number of significant figures in `value` are -/// less than `min_digits`; otherwise, returns true if `value` is equal -/// to `constant`, rounded to the number of digits present in `value`. -#[must_use] -fn is_approx_const(constant: f64, value: &str, min_digits: usize) -> bool { - if value.len() <= min_digits { - false - } else if constant.to_string().starts_with(value) { - // The value is a truncated constant - true - } else { - let round_const = format!("{:.*}", value.len() - 2, constant); - value == round_const - } -} diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs deleted file mode 100644 index 9861d8cfc4e5..000000000000 --- a/clippy_lints/src/arithmetic.rs +++ /dev/null @@ -1,168 +0,0 @@ -use crate::consts::constant_simple; -use crate::utils::span_lint; -use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for integer arithmetic operations which could overflow or panic. - /// - /// Specifically, checks for any operators (`+`, `-`, `*`, `<<`, etc) which are capable - /// of overflowing according to the [Rust - /// Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow), - /// or which can panic (`/`, `%`). No bounds analysis or sophisticated reasoning is - /// attempted. - /// - /// **Why is this bad?** Integer overflow will trigger a panic in debug builds or will wrap in - /// release mode. Division by zero will cause a panic in either mode. In some applications one - /// wants explicitly checked, wrapping or saturating arithmetic. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let a = 0; - /// a + 1; - /// ``` - pub INTEGER_ARITHMETIC, - restriction, - "any integer arithmetic expression which could overflow or panic" -} - -declare_clippy_lint! { - /// **What it does:** Checks for float arithmetic. - /// - /// **Why is this bad?** For some embedded systems or kernel development, it - /// can be useful to rule out floating-point numbers. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let a = 0.0; - /// a + 1.0; - /// ``` - pub FLOAT_ARITHMETIC, - restriction, - "any floating-point arithmetic statement" -} - -#[derive(Copy, Clone, Default)] -pub struct Arithmetic { - expr_span: Option, - /// This field is used to check whether expressions are constants, such as in enum discriminants - /// and consts - const_span: Option, -} - -impl_lint_pass!(Arithmetic => [INTEGER_ARITHMETIC, FLOAT_ARITHMETIC]); - -impl<'tcx> LateLintPass<'tcx> for Arithmetic { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - if self.expr_span.is_some() { - return; - } - - if let Some(span) = self.const_span { - if span.contains(expr.span) { - return; - } - } - match &expr.kind { - hir::ExprKind::Binary(op, l, r) | hir::ExprKind::AssignOp(op, l, r) => { - match op.node { - hir::BinOpKind::And - | hir::BinOpKind::Or - | hir::BinOpKind::BitAnd - | hir::BinOpKind::BitOr - | hir::BinOpKind::BitXor - | hir::BinOpKind::Eq - | hir::BinOpKind::Lt - | hir::BinOpKind::Le - | hir::BinOpKind::Ne - | hir::BinOpKind::Ge - | hir::BinOpKind::Gt => return, - _ => (), - } - - let (l_ty, r_ty) = (cx.typeck_results().expr_ty(l), cx.typeck_results().expr_ty(r)); - if l_ty.peel_refs().is_integral() && r_ty.peel_refs().is_integral() { - match op.node { - hir::BinOpKind::Div | hir::BinOpKind::Rem => match &r.kind { - hir::ExprKind::Lit(_lit) => (), - hir::ExprKind::Unary(hir::UnOp::UnNeg, expr) => { - if let hir::ExprKind::Lit(lit) = &expr.kind { - if let rustc_ast::ast::LitKind::Int(1, _) = lit.node { - span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected"); - self.expr_span = Some(expr.span); - } - } - }, - _ => { - span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected"); - self.expr_span = Some(expr.span); - }, - }, - _ => { - span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected"); - self.expr_span = Some(expr.span); - }, - } - } else if r_ty.peel_refs().is_floating_point() && r_ty.peel_refs().is_floating_point() { - span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected"); - self.expr_span = Some(expr.span); - } - }, - hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => { - let ty = cx.typeck_results().expr_ty(arg); - if constant_simple(cx, cx.typeck_results(), expr).is_none() { - if ty.is_integral() { - span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected"); - self.expr_span = Some(expr.span); - } else if ty.is_floating_point() { - span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected"); - self.expr_span = Some(expr.span); - } - } - }, - _ => (), - } - } - - fn check_expr_post(&mut self, _: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - if Some(expr.span) == self.expr_span { - self.expr_span = None; - } - } - - fn check_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { - let body_owner = cx.tcx.hir().body_owner(body.id()); - - match cx.tcx.hir().body_owner_kind(body_owner) { - hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const => { - let body_span = cx.tcx.hir().span(body_owner); - - if let Some(span) = self.const_span { - if span.contains(body_span) { - return; - } - } - self.const_span = Some(body_span); - }, - hir::BodyOwnerKind::Fn | hir::BodyOwnerKind::Closure => (), - } - } - - fn check_body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { - let body_owner = cx.tcx.hir().body_owner(body.id()); - let body_span = cx.tcx.hir().span(body_owner); - - if let Some(span) = self.const_span { - if span.contains(body_span) { - return; - } - } - self.const_span = None; - } -} diff --git a/clippy_lints/src/as_conversions.rs b/clippy_lints/src/as_conversions.rs deleted file mode 100644 index 0c8efd755146..000000000000 --- a/clippy_lints/src/as_conversions.rs +++ /dev/null @@ -1,58 +0,0 @@ -use rustc_ast::ast::{Expr, ExprKind}; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -use crate::utils::span_lint_and_help; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `as` conversions. - /// - /// **Why is this bad?** `as` conversions will perform many kinds of - /// conversions, including silently lossy conversions and dangerous coercions. - /// There are cases when it makes sense to use `as`, so the lint is - /// Allow by default. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// let a: u32; - /// ... - /// f(a as u16); - /// ``` - /// - /// Usually better represents the semantics you expect: - /// ```rust,ignore - /// f(a.try_into()?); - /// ``` - /// or - /// ```rust,ignore - /// f(a.try_into().expect("Unexpected u16 overflow in f")); - /// ``` - /// - pub AS_CONVERSIONS, - restriction, - "using a potentially dangerous silent `as` conversion" -} - -declare_lint_pass!(AsConversions => [AS_CONVERSIONS]); - -impl EarlyLintPass for AsConversions { - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - if in_external_macro(cx.sess(), expr.span) { - return; - } - - if let ExprKind::Cast(_, _) = expr.kind { - span_lint_and_help( - cx, - AS_CONVERSIONS, - expr.span, - "using a potentially dangerous silent `as` conversion", - None, - "consider using a safe wrapper for this conversion", - ); - } - } -} diff --git a/clippy_lints/src/asm_syntax.rs b/clippy_lints/src/asm_syntax.rs deleted file mode 100644 index ef1f1a14afca..000000000000 --- a/clippy_lints/src/asm_syntax.rs +++ /dev/null @@ -1,125 +0,0 @@ -use std::fmt; - -use crate::utils::span_lint_and_help; -use rustc_ast::ast::{Expr, ExprKind, InlineAsmOptions}; -use rustc_lint::{EarlyContext, EarlyLintPass, Lint}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -#[derive(Clone, Copy, PartialEq, Eq)] -enum AsmStyle { - Intel, - Att, -} - -impl fmt::Display for AsmStyle { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - AsmStyle::Intel => f.write_str("Intel"), - AsmStyle::Att => f.write_str("AT&T"), - } - } -} - -impl std::ops::Not for AsmStyle { - type Output = AsmStyle; - - fn not(self) -> AsmStyle { - match self { - AsmStyle::Intel => AsmStyle::Att, - AsmStyle::Att => AsmStyle::Intel, - } - } -} - -fn check_expr_asm_syntax(lint: &'static Lint, cx: &EarlyContext<'_>, expr: &Expr, check_for: AsmStyle) { - if let ExprKind::InlineAsm(ref inline_asm) = expr.kind { - let style = if inline_asm.options.contains(InlineAsmOptions::ATT_SYNTAX) { - AsmStyle::Att - } else { - AsmStyle::Intel - }; - - if style == check_for { - span_lint_and_help( - cx, - lint, - expr.span, - &format!("{} x86 assembly syntax used", style), - None, - &format!("use {} x86 assembly syntax", !style), - ); - } - } -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of Intel x86 assembly syntax. - /// - /// **Why is this bad?** The lint has been enabled to indicate a preference - /// for AT&T x86 assembly syntax. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust,no_run - /// # #![feature(asm)] - /// # unsafe { let ptr = "".as_ptr(); - /// asm!("lea {}, [{}]", lateout(reg) _, in(reg) ptr); - /// # } - /// ``` - /// Use instead: - /// ```rust,no_run - /// # #![feature(asm)] - /// # unsafe { let ptr = "".as_ptr(); - /// asm!("lea ({}), {}", in(reg) ptr, lateout(reg) _, options(att_syntax)); - /// # } - /// ``` - pub INLINE_ASM_X86_INTEL_SYNTAX, - restriction, - "prefer AT&T x86 assembly syntax" -} - -declare_lint_pass!(InlineAsmX86IntelSyntax => [INLINE_ASM_X86_INTEL_SYNTAX]); - -impl EarlyLintPass for InlineAsmX86IntelSyntax { - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - check_expr_asm_syntax(Self::get_lints()[0], cx, expr, AsmStyle::Intel); - } -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of AT&T x86 assembly syntax. - /// - /// **Why is this bad?** The lint has been enabled to indicate a preference - /// for Intel x86 assembly syntax. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust,no_run - /// # #![feature(asm)] - /// # unsafe { let ptr = "".as_ptr(); - /// asm!("lea ({}), {}", in(reg) ptr, lateout(reg) _, options(att_syntax)); - /// # } - /// ``` - /// Use instead: - /// ```rust,no_run - /// # #![feature(asm)] - /// # unsafe { let ptr = "".as_ptr(); - /// asm!("lea {}, [{}]", lateout(reg) _, in(reg) ptr); - /// # } - /// ``` - pub INLINE_ASM_X86_ATT_SYNTAX, - restriction, - "prefer Intel x86 assembly syntax" -} - -declare_lint_pass!(InlineAsmX86AttSyntax => [INLINE_ASM_X86_ATT_SYNTAX]); - -impl EarlyLintPass for InlineAsmX86AttSyntax { - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - check_expr_asm_syntax(Self::get_lints()[0], cx, expr, AsmStyle::Att); - } -} diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs deleted file mode 100644 index 62c73dbac48b..000000000000 --- a/clippy_lints/src/assertions_on_constants.rs +++ /dev/null @@ -1,154 +0,0 @@ -use crate::consts::{constant, Constant}; -use crate::utils::{is_direct_expn_of, is_expn_of, match_panic_call, snippet_opt, span_lint_and_help}; -use if_chain::if_chain; -use rustc_ast::ast::LitKind; -use rustc_hir::{Expr, ExprKind, PatKind, UnOp}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for `assert!(true)` and `assert!(false)` calls. - /// - /// **Why is this bad?** Will be optimized out by the compiler or should probably be replaced by a - /// `panic!()` or `unreachable!()` - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```rust,ignore - /// assert!(false) - /// assert!(true) - /// const B: bool = false; - /// assert!(B) - /// ``` - pub ASSERTIONS_ON_CONSTANTS, - style, - "`assert!(true)` / `assert!(false)` will be optimized out by the compiler, and should probably be replaced by a `panic!()` or `unreachable!()`" -} - -declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]); - -impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - let lint_true = |is_debug: bool| { - span_lint_and_help( - cx, - ASSERTIONS_ON_CONSTANTS, - e.span, - if is_debug { - "`debug_assert!(true)` will be optimized out by the compiler" - } else { - "`assert!(true)` will be optimized out by the compiler" - }, - None, - "remove it", - ); - }; - let lint_false_without_message = || { - span_lint_and_help( - cx, - ASSERTIONS_ON_CONSTANTS, - e.span, - "`assert!(false)` should probably be replaced", - None, - "use `panic!()` or `unreachable!()`", - ); - }; - let lint_false_with_message = |panic_message: String| { - span_lint_and_help( - cx, - ASSERTIONS_ON_CONSTANTS, - e.span, - &format!("`assert!(false, {})` should probably be replaced", panic_message), - None, - &format!("use `panic!({})` or `unreachable!({})`", panic_message, panic_message), - ) - }; - - if let Some(debug_assert_span) = is_expn_of(e.span, "debug_assert") { - if debug_assert_span.from_expansion() { - return; - } - if_chain! { - if let ExprKind::Unary(_, ref lit) = e.kind; - if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), lit); - if is_true; - then { - lint_true(true); - } - }; - } else if let Some(assert_span) = is_direct_expn_of(e.span, "assert") { - if assert_span.from_expansion() { - return; - } - if let Some(assert_match) = match_assert_with_message(&cx, e) { - match assert_match { - // matched assert but not message - AssertKind::WithoutMessage(false) => lint_false_without_message(), - AssertKind::WithoutMessage(true) | AssertKind::WithMessage(_, true) => lint_true(false), - AssertKind::WithMessage(panic_message, false) => lint_false_with_message(panic_message), - }; - } - } - } -} - -/// Result of calling `match_assert_with_message`. -enum AssertKind { - WithMessage(String, bool), - WithoutMessage(bool), -} - -/// Check if the expression matches -/// -/// ```rust,ignore -/// match { let _t = !c; _t } { -/// true => { -/// { -/// ::std::rt::begin_panic(message, _) -/// } -/// } -/// _ => { } -/// }; -/// ``` -/// -/// where `message` is any expression and `c` is a constant bool. -fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option { - if_chain! { - if let ExprKind::Match(ref expr, ref arms, _) = expr.kind; - // matches { let _t = expr; _t } - if let ExprKind::DropTemps(ref expr) = expr.kind; - if let ExprKind::Unary(UnOp::UnNot, ref expr) = expr.kind; - // bind the first argument of the `assert!` macro - if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), expr); - // arm 1 pattern - if let PatKind::Lit(ref lit_expr) = arms[0].pat.kind; - if let ExprKind::Lit(ref lit) = lit_expr.kind; - if let LitKind::Bool(true) = lit.node; - // arm 1 block - if let ExprKind::Block(ref block, _) = arms[0].body.kind; - if block.stmts.is_empty(); - if let Some(block_expr) = &block.expr; - // inner block is optional. unwrap it if it exists, or use the expression as is otherwise. - if let Some(begin_panic_call) = match block_expr.kind { - ExprKind::Block(ref inner_block, _) => &inner_block.expr, - _ => &block.expr, - }; - // function call - if let Some(args) = match_panic_call(cx, begin_panic_call); - if args.len() == 1; - // bind the second argument of the `assert!` macro if it exists - if let panic_message = snippet_opt(cx, args[0].span); - // second argument of begin_panic is irrelevant - // as is the second match arm - then { - // an empty message occurs when it was generated by the macro - // (and not passed by the user) - return panic_message - .filter(|msg| !msg.is_empty()) - .map(|msg| AssertKind::WithMessage(msg, is_true)) - .or(Some(AssertKind::WithoutMessage(is_true))); - } - } - None -} diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs deleted file mode 100644 index b3185b888401..000000000000 --- a/clippy_lints/src/assign_ops.rs +++ /dev/null @@ -1,263 +0,0 @@ -use crate::utils::{ - eq_expr_value, get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method, -}; -use crate::utils::{higher, sugg}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for `a = a op b` or `a = b commutative_op a` - /// patterns. - /// - /// **Why is this bad?** These can be written as the shorter `a op= b`. - /// - /// **Known problems:** While forbidden by the spec, `OpAssign` traits may have - /// implementations that differ from the regular `Op` impl. - /// - /// **Example:** - /// ```rust - /// let mut a = 5; - /// let b = 0; - /// // ... - /// // Bad - /// a = a + b; - /// - /// // Good - /// a += b; - /// ``` - pub ASSIGN_OP_PATTERN, - style, - "assigning the result of an operation on a variable to that same variable" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `a op= a op b` or `a op= b op a` patterns. - /// - /// **Why is this bad?** Most likely these are bugs where one meant to write `a - /// op= b`. - /// - /// **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 - /// written as `a = a op a op b` as it's less confusing. - /// - /// **Example:** - /// ```rust - /// let mut a = 5; - /// let b = 2; - /// // ... - /// a += a + b; - /// ``` - pub MISREFACTORED_ASSIGN_OP, - complexity, - "having a variable on both sides of an assign op" -} - -declare_lint_pass!(AssignOps => [ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP]); - -impl<'tcx> LateLintPass<'tcx> for AssignOps { - #[allow(clippy::too_many_lines)] - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - match &expr.kind { - hir::ExprKind::AssignOp(op, lhs, rhs) => { - if let hir::ExprKind::Binary(binop, l, r) = &rhs.kind { - if op.node != binop.node { - return; - } - // lhs op= l op r - if eq_expr_value(cx, lhs, l) { - lint_misrefactored_assign_op(cx, expr, *op, rhs, lhs, r); - } - // lhs op= l commutative_op r - if is_commutative(op.node) && eq_expr_value(cx, lhs, r) { - lint_misrefactored_assign_op(cx, expr, *op, rhs, lhs, l); - } - } - }, - hir::ExprKind::Assign(assignee, e, _) => { - if let hir::ExprKind::Binary(op, l, r) = &e.kind { - let lint = |assignee: &hir::Expr<'_>, rhs: &hir::Expr<'_>| { - let ty = cx.typeck_results().expr_ty(assignee); - let rty = cx.typeck_results().expr_ty(rhs); - macro_rules! ops { - ($op:expr, - $cx:expr, - $ty:expr, - $rty:expr, - $($trait_name:ident),+) => { - match $op { - $(hir::BinOpKind::$trait_name => { - let [krate, module] = crate::utils::paths::OPS_MODULE; - let path: [&str; 3] = [krate, module, concat!(stringify!($trait_name), "Assign")]; - let trait_id = if let Some(trait_id) = get_trait_def_id($cx, &path) { - trait_id - } else { - return; // useless if the trait doesn't exist - }; - // check that we are not inside an `impl AssignOp` of this exact operation - let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id); - if_chain! { - if let Some(trait_ref) = trait_ref_of_method(cx, parent_fn); - if trait_ref.path.res.def_id() == trait_id; - then { return; } - } - implements_trait($cx, $ty, trait_id, &[$rty]) - },)* - _ => false, - } - } - } - if ops!( - op.node, - cx, - ty, - rty.into(), - Add, - Sub, - Mul, - Div, - Rem, - And, - Or, - BitAnd, - BitOr, - BitXor, - Shr, - Shl - ) { - span_lint_and_then( - cx, - ASSIGN_OP_PATTERN, - expr.span, - "manual implementation of an assign operation", - |diag| { - if let (Some(snip_a), Some(snip_r)) = - (snippet_opt(cx, assignee.span), snippet_opt(cx, rhs.span)) - { - diag.span_suggestion( - expr.span, - "replace it with", - format!("{} {}= {}", snip_a, op.node.as_str(), snip_r), - Applicability::MachineApplicable, - ); - } - }, - ); - } - }; - - let mut visitor = ExprVisitor { - assignee, - counter: 0, - cx, - }; - - walk_expr(&mut visitor, e); - - if visitor.counter == 1 { - // a = a op b - if eq_expr_value(cx, assignee, l) { - lint(assignee, r); - } - // a = b commutative_op a - // Limited to primitive type as these ops are know to be commutative - if eq_expr_value(cx, assignee, r) && cx.typeck_results().expr_ty(assignee).is_primitive_ty() { - match op.node { - hir::BinOpKind::Add - | hir::BinOpKind::Mul - | hir::BinOpKind::And - | hir::BinOpKind::Or - | hir::BinOpKind::BitXor - | hir::BinOpKind::BitAnd - | hir::BinOpKind::BitOr => { - lint(assignee, l); - }, - _ => {}, - } - } - } - } - }, - _ => {}, - } - } -} - -fn lint_misrefactored_assign_op( - cx: &LateContext<'_>, - expr: &hir::Expr<'_>, - op: hir::BinOp, - rhs: &hir::Expr<'_>, - assignee: &hir::Expr<'_>, - rhs_other: &hir::Expr<'_>, -) { - span_lint_and_then( - cx, - MISREFACTORED_ASSIGN_OP, - expr.span, - "variable appears on both sides of an assignment operation", - |diag| { - if let (Some(snip_a), Some(snip_r)) = (snippet_opt(cx, assignee.span), snippet_opt(cx, rhs_other.span)) { - let a = &sugg::Sugg::hir(cx, assignee, ".."); - let r = &sugg::Sugg::hir(cx, rhs, ".."); - let long = format!("{} = {}", snip_a, sugg::make_binop(higher::binop(op.node), a, r)); - diag.span_suggestion( - expr.span, - &format!( - "Did you mean `{} = {} {} {}` or `{}`? Consider replacing it with", - snip_a, - snip_a, - op.node.as_str(), - snip_r, - long - ), - format!("{} {}= {}", snip_a, op.node.as_str(), snip_r), - Applicability::MaybeIncorrect, - ); - diag.span_suggestion( - expr.span, - "or", - long, - Applicability::MaybeIncorrect, // snippet - ); - } - }, - ); -} - -#[must_use] -fn is_commutative(op: hir::BinOpKind) -> bool { - use rustc_hir::BinOpKind::{ - Add, And, BitAnd, BitOr, BitXor, Div, Eq, Ge, Gt, Le, Lt, Mul, Ne, Or, Rem, Shl, Shr, Sub, - }; - match op { - Add | Mul | And | Or | BitXor | BitAnd | BitOr | Eq | Ne => true, - Sub | Div | Rem | Shl | Shr | Lt | Le | Ge | Gt => false, - } -} - -struct ExprVisitor<'a, 'tcx> { - assignee: &'a hir::Expr<'a>, - counter: u8, - cx: &'a LateContext<'tcx>, -} - -impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { - if eq_expr_value(self.cx, self.assignee, expr) { - self.counter += 1; - } - - walk_expr(self, expr); - } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} diff --git a/clippy_lints/src/async_yields_async.rs b/clippy_lints/src/async_yields_async.rs deleted file mode 100644 index 88d9d3b5a263..000000000000 --- a/clippy_lints/src/async_yields_async.rs +++ /dev/null @@ -1,86 +0,0 @@ -use crate::utils::{implements_trait, snippet, span_lint_and_then}; -use rustc_errors::Applicability; -use rustc_hir::{AsyncGeneratorKind, Body, BodyId, ExprKind, GeneratorKind, QPath}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for async blocks that yield values of types - /// that can themselves be awaited. - /// - /// **Why is this bad?** An await is likely missing. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// async fn foo() {} - /// - /// fn bar() { - /// let x = async { - /// foo() - /// }; - /// } - /// ``` - /// Use instead: - /// ```rust - /// async fn foo() {} - /// - /// fn bar() { - /// let x = async { - /// foo().await - /// }; - /// } - /// ``` - pub ASYNC_YIELDS_ASYNC, - correctness, - "async blocks that return a type that can be awaited" -} - -declare_lint_pass!(AsyncYieldsAsync => [ASYNC_YIELDS_ASYNC]); - -impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync { - fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) { - use AsyncGeneratorKind::{Block, Closure}; - // For functions, with explicitly defined types, don't warn. - // XXXkhuey maybe we should? - if let Some(GeneratorKind::Async(Block | Closure)) = body.generator_kind { - if let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait() { - let body_id = BodyId { - hir_id: body.value.hir_id, - }; - let def_id = cx.tcx.hir().body_owner_def_id(body_id); - let typeck_results = cx.tcx.typeck(def_id); - let expr_ty = typeck_results.expr_ty(&body.value); - - if implements_trait(cx, expr_ty, future_trait_def_id, &[]) { - let return_expr_span = match &body.value.kind { - // XXXkhuey there has to be a better way. - ExprKind::Block(block, _) => block.expr.map(|e| e.span), - ExprKind::Path(QPath::Resolved(_, path)) => Some(path.span), - _ => None, - }; - if let Some(return_expr_span) = return_expr_span { - span_lint_and_then( - cx, - ASYNC_YIELDS_ASYNC, - return_expr_span, - "an async construct yields a type which is itself awaitable", - |db| { - db.span_label(body.value.span, "outer async construct"); - db.span_label(return_expr_span, "awaitable value not awaited"); - db.span_suggestion( - return_expr_span, - "consider awaiting this value", - format!("{}.await", snippet(cx, return_expr_span, "..")), - Applicability::MaybeIncorrect, - ); - }, - ); - } - } - } - } - } -} diff --git a/clippy_lints/src/atomic_ordering.rs b/clippy_lints/src/atomic_ordering.rs deleted file mode 100644 index 703d8a6f62bb..000000000000 --- a/clippy_lints/src/atomic_ordering.rs +++ /dev/null @@ -1,229 +0,0 @@ -use crate::utils::{match_def_path, span_lint_and_help}; -use if_chain::if_chain; -use rustc_hir::def_id::DefId; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of invalid atomic - /// ordering in atomic loads/stores/exchanges/updates and - /// memory fences. - /// - /// **Why is this bad?** Using an invalid atomic ordering - /// will cause a panic at run-time. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,no_run - /// # use std::sync::atomic::{self, AtomicU8, Ordering}; - /// - /// let x = AtomicU8::new(0); - /// - /// // Bad: `Release` and `AcqRel` cannot be used for `load`. - /// let _ = x.load(Ordering::Release); - /// let _ = x.load(Ordering::AcqRel); - /// - /// // Bad: `Acquire` and `AcqRel` cannot be used for `store`. - /// x.store(1, Ordering::Acquire); - /// x.store(2, Ordering::AcqRel); - /// - /// // Bad: `Relaxed` cannot be used as a fence's ordering. - /// atomic::fence(Ordering::Relaxed); - /// atomic::compiler_fence(Ordering::Relaxed); - /// - /// // Bad: `Release` and `AcqRel` are both always invalid - /// // for the failure ordering (the last arg). - /// let _ = x.compare_exchange(1, 2, Ordering::SeqCst, Ordering::Release); - /// let _ = x.compare_exchange_weak(2, 3, Ordering::AcqRel, Ordering::AcqRel); - /// - /// // Bad: The failure ordering is not allowed to be - /// // stronger than the success order, and `SeqCst` is - /// // stronger than `Relaxed`. - /// let _ = x.fetch_update(Ordering::Relaxed, Ordering::SeqCst, |val| Some(val + val)); - /// ``` - pub INVALID_ATOMIC_ORDERING, - correctness, - "usage of invalid atomic ordering in atomic operations and memory fences" -} - -declare_lint_pass!(AtomicOrdering => [INVALID_ATOMIC_ORDERING]); - -const ATOMIC_TYPES: [&str; 12] = [ - "AtomicBool", - "AtomicI8", - "AtomicI16", - "AtomicI32", - "AtomicI64", - "AtomicIsize", - "AtomicPtr", - "AtomicU8", - "AtomicU16", - "AtomicU32", - "AtomicU64", - "AtomicUsize", -]; - -fn type_is_atomic(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.typeck_results().expr_ty(expr).kind() { - ATOMIC_TYPES - .iter() - .any(|ty| match_def_path(cx, did, &["core", "sync", "atomic", ty])) - } else { - false - } -} - -fn match_ordering_def_path(cx: &LateContext<'_>, did: DefId, orderings: &[&str]) -> bool { - orderings - .iter() - .any(|ordering| match_def_path(cx, did, &["core", "sync", "atomic", "Ordering", ordering])) -} - -fn check_atomic_load_store(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind; - let method = method_path.ident.name.as_str(); - if type_is_atomic(cx, &args[0]); - if method == "load" || method == "store"; - let ordering_arg = if method == "load" { &args[1] } else { &args[2] }; - if let ExprKind::Path(ref ordering_qpath) = ordering_arg.kind; - if let Some(ordering_def_id) = cx.qpath_res(ordering_qpath, ordering_arg.hir_id).opt_def_id(); - then { - if method == "load" && - match_ordering_def_path(cx, ordering_def_id, &["Release", "AcqRel"]) { - span_lint_and_help( - cx, - INVALID_ATOMIC_ORDERING, - ordering_arg.span, - "atomic loads cannot have `Release` and `AcqRel` ordering", - None, - "consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`" - ); - } else if method == "store" && - match_ordering_def_path(cx, ordering_def_id, &["Acquire", "AcqRel"]) { - span_lint_and_help( - cx, - INVALID_ATOMIC_ORDERING, - ordering_arg.span, - "atomic stores cannot have `Acquire` and `AcqRel` ordering", - None, - "consider using ordering modes `Release`, `SeqCst` or `Relaxed`" - ); - } - } - } -} - -fn check_memory_fence(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::Call(ref func, ref args) = expr.kind; - if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); - if ["fence", "compiler_fence"] - .iter() - .any(|func| match_def_path(cx, def_id, &["core", "sync", "atomic", func])); - if let ExprKind::Path(ref ordering_qpath) = &args[0].kind; - if let Some(ordering_def_id) = cx.qpath_res(ordering_qpath, args[0].hir_id).opt_def_id(); - if match_ordering_def_path(cx, ordering_def_id, &["Relaxed"]); - then { - span_lint_and_help( - cx, - INVALID_ATOMIC_ORDERING, - args[0].span, - "memory fences cannot have `Relaxed` ordering", - None, - "consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`" - ); - } - } -} - -fn opt_ordering_defid(cx: &LateContext<'_>, ord_arg: &Expr<'_>) -> Option { - if let ExprKind::Path(ref ord_qpath) = ord_arg.kind { - cx.qpath_res(ord_qpath, ord_arg.hir_id).opt_def_id() - } else { - None - } -} - -fn check_atomic_compare_exchange(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind; - let method = method_path.ident.name.as_str(); - if type_is_atomic(cx, &args[0]); - if method == "compare_exchange" || method == "compare_exchange_weak" || method == "fetch_update"; - let (success_order_arg, failure_order_arg) = if method == "fetch_update" { - (&args[1], &args[2]) - } else { - (&args[3], &args[4]) - }; - if let Some(fail_ordering_def_id) = opt_ordering_defid(cx, failure_order_arg); - then { - // Helper type holding on to some checking and error reporting data. Has - // - (success ordering name, - // - list of failure orderings forbidden by the success order, - // - suggestion message) - type OrdLintInfo = (&'static str, &'static [&'static str], &'static str); - let relaxed: OrdLintInfo = ("Relaxed", &["SeqCst", "Acquire"], "ordering mode `Relaxed`"); - let acquire: OrdLintInfo = ("Acquire", &["SeqCst"], "ordering modes `Acquire` or `Relaxed`"); - let seq_cst: OrdLintInfo = ("SeqCst", &[], "ordering modes `Acquire`, `SeqCst` or `Relaxed`"); - let release = ("Release", relaxed.1, relaxed.2); - let acqrel = ("AcqRel", acquire.1, acquire.2); - let search = [relaxed, acquire, seq_cst, release, acqrel]; - - let success_lint_info = opt_ordering_defid(cx, success_order_arg) - .and_then(|success_ord_def_id| -> Option { - search - .iter() - .find(|(ordering, ..)| { - match_def_path(cx, success_ord_def_id, - &["core", "sync", "atomic", "Ordering", ordering]) - }) - .copied() - }); - - if match_ordering_def_path(cx, fail_ordering_def_id, &["Release", "AcqRel"]) { - // If we don't know the success order is, use what we'd suggest - // if it were maximally permissive. - let suggested = success_lint_info.unwrap_or(seq_cst).2; - span_lint_and_help( - cx, - INVALID_ATOMIC_ORDERING, - failure_order_arg.span, - &format!( - "{}'s failure ordering may not be `Release` or `AcqRel`", - method, - ), - None, - &format!("consider using {} instead", suggested), - ); - } else if let Some((success_ord_name, bad_ords_given_success, suggested)) = success_lint_info { - if match_ordering_def_path(cx, fail_ordering_def_id, bad_ords_given_success) { - span_lint_and_help( - cx, - INVALID_ATOMIC_ORDERING, - failure_order_arg.span, - &format!( - "{}'s failure ordering may not be stronger than the success ordering of `{}`", - method, - success_ord_name, - ), - None, - &format!("consider using {} instead", suggested), - ); - } - } - } - } -} - -impl<'tcx> LateLintPass<'tcx> for AtomicOrdering { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - check_atomic_load_store(cx, expr); - check_memory_fence(cx, expr); - check_atomic_compare_exchange(cx, expr); - } -} diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs deleted file mode 100644 index 3edbe723922f..000000000000 --- a/clippy_lints/src/attrs.rs +++ /dev/null @@ -1,717 +0,0 @@ -//! checks for attributes - -use crate::utils::{ - first_line_of_span, is_present_in_source, match_panic_def_id, snippet_opt, span_lint, span_lint_and_help, - span_lint_and_sugg, span_lint_and_then, without_block_comments, -}; -use if_chain::if_chain; -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, -}; -use rustc_lint::{CheckLintNameResult, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::lev_distance::find_best_match_for_name; -use rustc_span::source_map::Span; -use rustc_span::sym; -use rustc_span::symbol::{Symbol, SymbolStr}; -use semver::Version; - -static UNIX_SYSTEMS: &[&str] = &[ - "android", - "dragonfly", - "emscripten", - "freebsd", - "fuchsia", - "haiku", - "illumos", - "ios", - "l4re", - "linux", - "macos", - "netbsd", - "openbsd", - "redox", - "solaris", - "vxworks", -]; - -// NOTE: windows is excluded from the list because it's also a valid target family. -static NON_UNIX_SYSTEMS: &[&str] = &["hermit", "none", "wasi"]; - -declare_clippy_lint! { - /// **What it does:** Checks for items annotated with `#[inline(always)]`, - /// unless the annotated function is empty or simply panics. - /// - /// **Why is this bad?** While there are valid uses of this annotation (and once - /// you know when to use it, by all means `allow` this lint), it's a common - /// newbie-mistake to pepper one's code with it. - /// - /// As a rule of thumb, before slapping `#[inline(always)]` on a function, - /// measure if that additional function call really affects your runtime profile - /// sufficiently to make up for the increase in compile time. - /// - /// **Known problems:** False positives, big time. This lint is meant to be - /// deactivated by everyone doing serious performance work. This means having - /// done the measurement. - /// - /// **Example:** - /// ```ignore - /// #[inline(always)] - /// fn not_quite_hot_code(..) { ... } - /// ``` - pub INLINE_ALWAYS, - pedantic, - "use of `#[inline(always)]`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `extern crate` and `use` items annotated with - /// lint attributes. - /// - /// This lint permits `#[allow(unused_imports)]`, `#[allow(deprecated)]`, - /// `#[allow(unreachable_pub)]`, `#[allow(clippy::wildcard_imports)]` and - /// `#[allow(clippy::enum_glob_use)]` on `use` items and `#[allow(unused_imports)]` on - /// `extern crate` items with a `#[macro_use]` attribute. - /// - /// **Why is this bad?** Lint attributes have no effect on crate imports. Most - /// likely a `!` was forgotten. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// // Bad - /// #[deny(dead_code)] - /// extern crate foo; - /// #[forbid(dead_code)] - /// use foo::bar; - /// - /// // Ok - /// #[allow(unused_imports)] - /// use foo::baz; - /// #[allow(unused_imports)] - /// #[macro_use] - /// extern crate baz; - /// ``` - pub USELESS_ATTRIBUTE, - correctness, - "use of lint attributes on `extern crate` items" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `#[deprecated]` annotations with a `since` - /// field that is not a valid semantic version. - /// - /// **Why is this bad?** For checking the version of the deprecation, it must be - /// a valid semver. Failing that, the contained information is useless. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// #[deprecated(since = "forever")] - /// fn something_else() { /* ... */ } - /// ``` - pub DEPRECATED_SEMVER, - correctness, - "use of `#[deprecated(since = \"x\")]` where x is not semver" -} - -declare_clippy_lint! { - /// **What it does:** Checks for empty lines after outer attributes - /// - /// **Why is this bad?** - /// Most likely the attribute was meant to be an inner attribute using a '!'. - /// If it was meant to be an outer attribute, then the following item - /// should not be separated by empty lines. - /// - /// **Known problems:** Can cause false positives. - /// - /// From the clippy side it's difficult to detect empty lines between an attributes and the - /// following item because empty lines and comments are not part of the AST. The parsing - /// currently works for basic cases but is not perfect. - /// - /// **Example:** - /// ```rust - /// // Good (as inner attribute) - /// #![allow(dead_code)] - /// - /// fn this_is_fine() { } - /// - /// // Bad - /// #[allow(dead_code)] - /// - /// fn not_quite_good_code() { } - /// - /// // Good (as outer attribute) - /// #[allow(dead_code)] - /// fn this_is_fine_too() { } - /// ``` - pub EMPTY_LINE_AFTER_OUTER_ATTR, - nursery, - "empty line after outer attribute" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `allow`/`warn`/`deny`/`forbid` attributes with scoped clippy - /// lints and if those lints exist in clippy. If there is an uppercase letter in the lint name - /// (not the tool name) and a lowercase version of this lint exists, it will suggest to lowercase - /// the lint name. - /// - /// **Why is this bad?** A lint attribute with a mistyped lint name won't have an effect. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// Bad: - /// ```rust - /// #![warn(if_not_els)] - /// #![deny(clippy::All)] - /// ``` - /// - /// Good: - /// ```rust - /// #![warn(if_not_else)] - /// #![deny(clippy::all)] - /// ``` - pub UNKNOWN_CLIPPY_LINTS, - style, - "unknown_lints for scoped Clippy lints" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `warn`/`deny`/`forbid` attributes targeting the whole clippy::restriction category. - /// - /// **Why is this bad?** Restriction lints sometimes are in contrast with other lints or even go against idiomatic rust. - /// These lints should only be enabled on a lint-by-lint basis and with careful consideration. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// Bad: - /// ```rust - /// #![deny(clippy::restriction)] - /// ``` - /// - /// Good: - /// ```rust - /// #![deny(clippy::as_conversions)] - /// ``` - pub BLANKET_CLIPPY_RESTRICTION_LINTS, - style, - "enabling the complete restriction group" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `#[cfg_attr(rustfmt, rustfmt_skip)]` and suggests to replace it - /// with `#[rustfmt::skip]`. - /// - /// **Why is this bad?** Since tool_attributes ([rust-lang/rust#44690](https://github.com/rust-lang/rust/issues/44690)) - /// are stable now, they should be used instead of the old `cfg_attr(rustfmt)` attributes. - /// - /// **Known problems:** This lint doesn't detect crate level inner attributes, because they get - /// processed before the PreExpansionPass lints get executed. See - /// [#3123](https://github.com/rust-lang/rust-clippy/pull/3123#issuecomment-422321765) - /// - /// **Example:** - /// - /// Bad: - /// ```rust - /// #[cfg_attr(rustfmt, rustfmt_skip)] - /// fn main() { } - /// ``` - /// - /// Good: - /// ```rust - /// #[rustfmt::skip] - /// fn main() { } - /// ``` - pub DEPRECATED_CFG_ATTR, - complexity, - "usage of `cfg_attr(rustfmt)` instead of tool attributes" -} - -declare_clippy_lint! { - /// **What it does:** Checks for cfg attributes having operating systems used in target family position. - /// - /// **Why is this bad?** The configuration option will not be recognised and the related item will not be included - /// by the conditional compilation engine. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// Bad: - /// ```rust - /// #[cfg(linux)] - /// fn conditional() { } - /// ``` - /// - /// Good: - /// ```rust - /// #[cfg(target_os = "linux")] - /// fn conditional() { } - /// ``` - /// - /// Or: - /// ```rust - /// #[cfg(unix)] - /// fn conditional() { } - /// ``` - /// Check the [Rust Reference](https://doc.rust-lang.org/reference/conditional-compilation.html#target_os) for more details. - pub MISMATCHED_TARGET_OS, - correctness, - "usage of `cfg(operating_system)` instead of `cfg(target_os = \"operating_system\")`" -} - -declare_lint_pass!(Attributes => [ - INLINE_ALWAYS, - DEPRECATED_SEMVER, - USELESS_ATTRIBUTE, - UNKNOWN_CLIPPY_LINTS, - BLANKET_CLIPPY_RESTRICTION_LINTS, -]); - -impl<'tcx> LateLintPass<'tcx> for Attributes { - fn check_attribute(&mut self, cx: &LateContext<'tcx>, attr: &'tcx Attribute) { - if let Some(items) = &attr.meta_item_list() { - if let Some(ident) = attr.ident() { - let ident = &*ident.as_str(); - match ident { - "allow" | "warn" | "deny" | "forbid" => { - check_clippy_lint_names(cx, ident, items); - }, - _ => {}, - } - if items.is_empty() || !attr.has_name(sym::deprecated) { - return; - } - for item in items { - if_chain! { - if let NestedMetaItem::MetaItem(mi) = &item; - if let MetaItemKind::NameValue(lit) = &mi.kind; - if mi.has_name(sym::since); - then { - check_semver(cx, item.span(), lit); - } - } - } - } - } - } - - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if is_relevant_item(cx, item) { - check_attrs(cx, item.span, item.ident.name, &item.attrs) - } - match item.kind { - ItemKind::ExternCrate(..) | ItemKind::Use(..) => { - let skip_unused_imports = item.attrs.iter().any(|attr| attr.has_name(sym::macro_use)); - - for attr in item.attrs { - if in_external_macro(cx.sess(), attr.span) { - return; - } - if let Some(lint_list) = &attr.meta_item_list() { - if let Some(ident) = attr.ident() { - match &*ident.as_str() { - "allow" | "warn" | "deny" | "forbid" => { - // permit `unused_imports`, `deprecated`, `unreachable_pub`, - // `clippy::wildcard_imports`, and `clippy::enum_glob_use` for `use` items - // and `unused_imports` for `extern crate` items with `macro_use` - for lint in lint_list { - match item.kind { - ItemKind::Use(..) => { - if is_word(lint, sym!(unused_imports)) - || is_word(lint, sym::deprecated) - || is_word(lint, sym!(unreachable_pub)) - || is_word(lint, sym!(unused)) - || extract_clippy_lint(lint) - .map_or(false, |s| s == "wildcard_imports") - || extract_clippy_lint(lint).map_or(false, |s| s == "enum_glob_use") - { - return; - } - }, - ItemKind::ExternCrate(..) => { - if is_word(lint, sym!(unused_imports)) && skip_unused_imports { - return; - } - if is_word(lint, sym!(unused_extern_crates)) { - return; - } - }, - _ => {}, - } - } - let line_span = first_line_of_span(cx, attr.span); - - if let Some(mut sugg) = snippet_opt(cx, line_span) { - if sugg.contains("#[") { - span_lint_and_then( - cx, - USELESS_ATTRIBUTE, - line_span, - "useless lint attribute", - |diag| { - sugg = sugg.replacen("#[", "#![", 1); - diag.span_suggestion( - line_span, - "if you just forgot a `!`, use", - sugg, - Applicability::MaybeIncorrect, - ); - }, - ); - } - } - }, - _ => {}, - } - } - } - } - }, - _ => {}, - } - } - - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { - if is_relevant_impl(cx, item) { - check_attrs(cx, item.span, item.ident.name, &item.attrs) - } - } - - fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { - if is_relevant_trait(cx, item) { - check_attrs(cx, item.span, item.ident.name, &item.attrs) - } - } -} - -/// Returns the lint name if it is clippy lint. -fn extract_clippy_lint(lint: &NestedMetaItem) -> Option { - if_chain! { - if let Some(meta_item) = lint.meta_item(); - if meta_item.path.segments.len() > 1; - if let tool_name = meta_item.path.segments[0].ident; - if tool_name.as_str() == "clippy"; - let lint_name = meta_item.path.segments.last().unwrap().ident.name; - then { - return Some(lint_name.as_str()); - } - } - None -} - -fn check_clippy_lint_names(cx: &LateContext<'_>, ident: &str, items: &[NestedMetaItem]) { - let lint_store = cx.lints(); - for lint in items { - if let Some(lint_name) = extract_clippy_lint(lint) { - if let CheckLintNameResult::Tool(Err((None, _))) = lint_store.check_lint_name(&lint_name, Some(sym::clippy)) - { - span_lint_and_then( - cx, - UNKNOWN_CLIPPY_LINTS, - lint.span(), - &format!("unknown clippy lint: clippy::{}", lint_name), - |diag| { - let name_lower = lint_name.to_lowercase(); - let symbols = lint_store - .get_lints() - .iter() - .map(|l| Symbol::intern(&l.name_lower())) - .collect::>(); - let sugg = find_best_match_for_name( - &symbols, - Symbol::intern(&format!("clippy::{}", name_lower)), - None, - ); - if lint_name.chars().any(char::is_uppercase) - && lint_store.find_lints(&format!("clippy::{}", name_lower)).is_ok() - { - diag.span_suggestion( - lint.span(), - "lowercase the lint name", - format!("clippy::{}", name_lower), - Applicability::MachineApplicable, - ); - } else if let Some(sugg) = sugg { - diag.span_suggestion( - lint.span(), - "did you mean", - sugg.to_string(), - Applicability::MachineApplicable, - ); - } - }, - ); - } else if lint_name == "restriction" && ident != "allow" { - span_lint_and_help( - cx, - BLANKET_CLIPPY_RESTRICTION_LINTS, - lint.span(), - "restriction lints are not meant to be all enabled", - None, - "try enabling only the lints you really need", - ); - } - } - } -} - -fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool { - if let ItemKind::Fn(_, _, eid) = item.kind { - is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value) - } else { - true - } -} - -fn is_relevant_impl(cx: &LateContext<'_>, item: &ImplItem<'_>) -> bool { - match item.kind { - ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value), - _ => false, - } -} - -fn is_relevant_trait(cx: &LateContext<'_>, item: &TraitItem<'_>) -> bool { - match item.kind { - TraitItemKind::Fn(_, TraitFn::Required(_)) => true, - TraitItemKind::Fn(_, TraitFn::Provided(eid)) => { - is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value) - }, - _ => false, - } -} - -fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>, block: &Block<'_>) -> bool { - block.stmts.first().map_or( - block - .expr - .as_ref() - .map_or(false, |e| is_relevant_expr(cx, typeck_results, e)), - |stmt| match &stmt.kind { - StmtKind::Local(_) => true, - StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, typeck_results, expr), - _ => false, - }, - ) -} - -fn is_relevant_expr(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>, expr: &Expr<'_>) -> bool { - match &expr.kind { - ExprKind::Block(block, _) => is_relevant_block(cx, typeck_results, block), - ExprKind::Ret(Some(e)) => is_relevant_expr(cx, typeck_results, e), - ExprKind::Ret(None) | ExprKind::Break(_, None) => false, - ExprKind::Call(path_expr, _) => { - if let ExprKind::Path(qpath) = &path_expr.kind { - typeck_results - .qpath_res(qpath, path_expr.hir_id) - .opt_def_id() - .map_or(true, |fun_id| !match_panic_def_id(cx, fun_id)) - } else { - true - } - }, - _ => true, - } -} - -fn check_attrs(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Attribute]) { - if span.from_expansion() { - return; - } - - for attr in attrs { - if let Some(values) = attr.meta_item_list() { - if values.len() != 1 || !attr.has_name(sym::inline) { - continue; - } - if is_word(&values[0], sym::always) { - span_lint( - cx, - INLINE_ALWAYS, - attr.span, - &format!( - "you have declared `#[inline(always)]` on `{}`. This is usually a bad idea", - name - ), - ); - } - } - } -} - -fn check_semver(cx: &LateContext<'_>, span: Span, lit: &Lit) { - if let LitKind::Str(is, _) = lit.kind { - if Version::parse(&is.as_str()).is_ok() { - return; - } - } - span_lint( - cx, - DEPRECATED_SEMVER, - span, - "the since field must contain a semver-compliant version", - ); -} - -fn is_word(nmi: &NestedMetaItem, expected: Symbol) -> bool { - if let NestedMetaItem::MetaItem(mi) = &nmi { - mi.is_word() && mi.has_name(expected) - } else { - false - } -} - -declare_lint_pass!(EarlyAttributes => [ - DEPRECATED_CFG_ATTR, - MISMATCHED_TARGET_OS, - EMPTY_LINE_AFTER_OUTER_ATTR, -]); - -impl EarlyLintPass for EarlyAttributes { - fn check_item(&mut self, cx: &EarlyContext<'_>, item: &rustc_ast::Item) { - check_empty_line_after_outer_attr(cx, item); - } - - fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) { - check_deprecated_cfg_attr(cx, attr); - check_mismatched_target_os(cx, attr); - } -} - -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 attr_item.args.inner_tokens().is_empty() || !is_present_in_source(cx, attr.span) { - return; - } - - let begin_of_attr_to_item = Span::new(attr.span.lo(), item.span.lo(), item.span.ctxt()); - let end_of_attr_to_item = Span::new(attr.span.hi(), item.span.lo(), item.span.ctxt()); - - if let Some(snippet) = snippet_opt(cx, end_of_attr_to_item) { - let lines = snippet.split('\n').collect::>(); - let lines = without_block_comments(lines); - - if lines.iter().filter(|l| l.trim().is_empty()).count() > 2 { - span_lint( - cx, - EMPTY_LINE_AFTER_OUTER_ATTR, - begin_of_attr_to_item, - "found an empty line after an outer attribute. \ - Perhaps you forgot to add a `!` to make it an inner attribute?", - ); - } - } - } - } -} - -fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute) { - if_chain! { - // check cfg_attr - if attr.has_name(sym::cfg_attr); - if let Some(items) = attr.meta_item_list(); - if items.len() == 2; - // check for `rustfmt` - if let Some(feature_item) = items[0].meta_item(); - if feature_item.has_name(sym::rustfmt); - // check for `rustfmt_skip` and `rustfmt::skip` - if let Some(skip_item) = &items[1].meta_item(); - if skip_item.has_name(sym!(rustfmt_skip)) || - skip_item.path.segments.last().expect("empty path in attribute").ident.name == sym!(skip); - // Only lint outer attributes, because custom inner attributes are unstable - // Tracking issue: https://github.com/rust-lang/rust/issues/54726 - if let AttrStyle::Outer = attr.style; - then { - span_lint_and_sugg( - cx, - DEPRECATED_CFG_ATTR, - attr.span, - "`cfg_attr` is deprecated for rustfmt and got replaced by tool attributes", - "use", - "#[rustfmt::skip]".to_string(), - Applicability::MachineApplicable, - ); - } - } -} - -fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) { - fn find_os(name: &str) -> Option<&'static str> { - UNIX_SYSTEMS - .iter() - .chain(NON_UNIX_SYSTEMS.iter()) - .find(|&&os| os == name) - .copied() - } - - fn is_unix(name: &str) -> bool { - UNIX_SYSTEMS.iter().any(|&os| os == name) - } - - fn find_mismatched_target_os(items: &[NestedMetaItem]) -> Vec<(&str, Span)> { - let mut mismatched = Vec::new(); - - for item in items { - if let NestedMetaItem::MetaItem(meta) = item { - match &meta.kind { - MetaItemKind::List(list) => { - mismatched.extend(find_mismatched_target_os(&list)); - }, - MetaItemKind::Word => { - if_chain! { - if let Some(ident) = meta.ident(); - if let Some(os) = find_os(&*ident.name.as_str()); - then { - mismatched.push((os, ident.span)); - } - } - }, - _ => {}, - } - } - } - - mismatched - } - - if_chain! { - if attr.has_name(sym::cfg); - if let Some(list) = attr.meta_item_list(); - let mismatched = find_mismatched_target_os(&list); - if !mismatched.is_empty(); - then { - let mess = "operating system used in target family position"; - - span_lint_and_then(cx, MISMATCHED_TARGET_OS, attr.span, &mess, |diag| { - // Avoid showing the unix suggestion multiple times in case - // we have more than one mismatch for unix-like systems - let mut unix_suggested = false; - - for (os, span) in mismatched { - let sugg = format!("target_os = \"{}\"", os); - diag.span_suggestion(span, "try", sugg, Applicability::MaybeIncorrect); - - if !unix_suggested && is_unix(os) { - diag.help("Did you mean `unix`?"); - unix_suggested = true; - } - } - }); - } - } -} diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs deleted file mode 100644 index f136aa4572a8..000000000000 --- a/clippy_lints/src/await_holding_invalid.rs +++ /dev/null @@ -1,149 +0,0 @@ -use crate::utils::{match_def_path, paths, span_lint_and_note}; -use rustc_hir::def_id::DefId; -use rustc_hir::{AsyncGeneratorKind, Body, BodyId, GeneratorKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::GeneratorInteriorTypeCause; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for calls to await while holding a - /// non-async-aware MutexGuard. - /// - /// **Why is this bad?** The Mutex types found in std::sync and parking_lot - /// are not designed to operate in an async context across await points. - /// - /// There are two potential solutions. One is to use an asynx-aware Mutex - /// type. Many asynchronous foundation crates provide such a Mutex type. The - /// other solution is to ensure the mutex is unlocked before calling await, - /// either by introducing a scope or an explicit call to Drop::drop. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust,ignore - /// use std::sync::Mutex; - /// - /// async fn foo(x: &Mutex) { - /// let guard = x.lock().unwrap(); - /// *guard += 1; - /// bar.await; - /// } - /// ``` - /// - /// Use instead: - /// ```rust,ignore - /// use std::sync::Mutex; - /// - /// async fn foo(x: &Mutex) { - /// { - /// let guard = x.lock().unwrap(); - /// *guard += 1; - /// } - /// bar.await; - /// } - /// ``` - pub AWAIT_HOLDING_LOCK, - pedantic, - "Inside an async function, holding a MutexGuard while calling await" -} - -declare_clippy_lint! { - /// **What it does:** Checks for calls to await while holding a - /// `RefCell` `Ref` or `RefMut`. - /// - /// **Why is this bad?** `RefCell` refs only check for exclusive mutable access - /// at runtime. Holding onto a `RefCell` ref across an `await` suspension point - /// risks panics from a mutable ref shared while other refs are outstanding. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust,ignore - /// use std::cell::RefCell; - /// - /// async fn foo(x: &RefCell) { - /// let mut y = x.borrow_mut(); - /// *y += 1; - /// bar.await; - /// } - /// ``` - /// - /// Use instead: - /// ```rust,ignore - /// use std::cell::RefCell; - /// - /// async fn foo(x: &RefCell) { - /// { - /// let mut y = x.borrow_mut(); - /// *y += 1; - /// } - /// bar.await; - /// } - /// ``` - pub AWAIT_HOLDING_REFCELL_REF, - pedantic, - "Inside an async function, holding a RefCell ref while calling await" -} - -declare_lint_pass!(AwaitHolding => [AWAIT_HOLDING_LOCK, AWAIT_HOLDING_REFCELL_REF]); - -impl LateLintPass<'_> for AwaitHolding { - fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { - use AsyncGeneratorKind::{Block, Closure, Fn}; - if let Some(GeneratorKind::Async(Block | Closure | Fn)) = body.generator_kind { - let body_id = BodyId { - hir_id: body.value.hir_id, - }; - let def_id = cx.tcx.hir().body_owner_def_id(body_id); - let typeck_results = cx.tcx.typeck(def_id); - check_interior_types( - cx, - &typeck_results.generator_interior_types.as_ref().skip_binder(), - body.value.span, - ); - } - } -} - -fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorTypeCause<'_>], span: Span) { - for ty_cause in ty_causes { - if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind() { - if is_mutex_guard(cx, adt.did) { - span_lint_and_note( - cx, - AWAIT_HOLDING_LOCK, - ty_cause.span, - "this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await.", - ty_cause.scope_span.or(Some(span)), - "these are all the await points this lock is held through", - ); - } - if is_refcell_ref(cx, adt.did) { - span_lint_and_note( - cx, - AWAIT_HOLDING_REFCELL_REF, - ty_cause.span, - "this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.", - ty_cause.scope_span.or(Some(span)), - "these are all the await points this ref is held through", - ); - } - } - } -} - -fn is_mutex_guard(cx: &LateContext<'_>, def_id: DefId) -> bool { - match_def_path(cx, def_id, &paths::MUTEX_GUARD) - || match_def_path(cx, def_id, &paths::RWLOCK_READ_GUARD) - || match_def_path(cx, def_id, &paths::RWLOCK_WRITE_GUARD) - || match_def_path(cx, def_id, &paths::PARKING_LOT_MUTEX_GUARD) - || match_def_path(cx, def_id, &paths::PARKING_LOT_RWLOCK_READ_GUARD) - || match_def_path(cx, def_id, &paths::PARKING_LOT_RWLOCK_WRITE_GUARD) -} - -fn is_refcell_ref(cx: &LateContext<'_>, def_id: DefId) -> bool { - match_def_path(cx, def_id, &paths::REFCELL_REF) || match_def_path(cx, def_id, &paths::REFCELL_REFMUT) -} diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs deleted file mode 100644 index a4ee54076ee9..000000000000 --- a/clippy_lints/src/bit_mask.rs +++ /dev/null @@ -1,326 +0,0 @@ -use crate::consts::{constant, Constant}; -use crate::utils::sugg::Sugg; -use crate::utils::{span_lint, span_lint_and_then}; -use if_chain::if_chain; -use rustc_ast::ast::LitKind; -use rustc_errors::Applicability; -use rustc_hir::{BinOpKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for incompatible bit masks in comparisons. - /// - /// The formula for detecting if an expression of the type `_ m - /// c` (where `` is one of {`&`, `|`} and `` is one of - /// {`!=`, `>=`, `>`, `!=`, `>=`, `>`}) can be determined from the following - /// table: - /// - /// |Comparison |Bit Op|Example |is always|Formula | - /// |------------|------|------------|---------|----------------------| - /// |`==` or `!=`| `&` |`x & 2 == 3`|`false` |`c & m != c` | - /// |`<` or `>=`| `&` |`x & 2 < 3` |`true` |`m < c` | - /// |`>` or `<=`| `&` |`x & 1 > 1` |`false` |`m <= c` | - /// |`==` or `!=`| `|` |`x | 1 == 0`|`false` |`c | m != c` | - /// |`<` or `>=`| `|` |`x | 1 < 1` |`false` |`m >= c` | - /// |`<=` or `>` | `|` |`x | 1 > 0` |`true` |`m > c` | - /// - /// **Why is this bad?** If the bits that the comparison cares about are always - /// set to zero or one by the bit mask, the comparison is constant `true` or - /// `false` (depending on mask, compared value, and operators). - /// - /// So the code is actively misleading, and the only reason someone would write - /// this intentionally is to win an underhanded Rust contest or create a - /// test-case for this lint. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let x = 1; - /// if (x & 1 == 2) { } - /// ``` - pub BAD_BIT_MASK, - correctness, - "expressions of the form `_ & mask == select` that will only ever return `true` or `false`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for bit masks in comparisons which can be removed - /// without changing the outcome. The basic structure can be seen in the - /// following table: - /// - /// |Comparison| Bit Op |Example |equals | - /// |----------|---------|-----------|-------| - /// |`>` / `<=`|`|` / `^`|`x | 2 > 3`|`x > 3`| - /// |`<` / `>=`|`|` / `^`|`x ^ 1 < 4`|`x < 4`| - /// - /// **Why is this bad?** Not equally evil as [`bad_bit_mask`](#bad_bit_mask), - /// but still a bit misleading, because the bit mask is ineffective. - /// - /// **Known problems:** False negatives: This lint will only match instances - /// where we have figured out the math (which is for a power-of-two compared - /// value). This means things like `x | 1 >= 7` (which would be better written - /// as `x >= 6`) will not be reported (but bit masks like this are fairly - /// uncommon). - /// - /// **Example:** - /// ```rust - /// # let x = 1; - /// if (x | 1 > 3) { } - /// ``` - pub INEFFECTIVE_BIT_MASK, - correctness, - "expressions where a bit mask will be rendered useless by a comparison, e.g., `(x | 1) > 2`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for bit masks that can be replaced by a call - /// to `trailing_zeros` - /// - /// **Why is this bad?** `x.trailing_zeros() > 4` is much clearer than `x & 15 - /// == 0` - /// - /// **Known problems:** llvm generates better code for `x & 15 == 0` on x86 - /// - /// **Example:** - /// ```rust - /// # let x = 1; - /// if x & 0b1111 == 0 { } - /// ``` - pub VERBOSE_BIT_MASK, - pedantic, - "expressions where a bit mask is less readable than the corresponding method call" -} - -#[derive(Copy, Clone)] -pub struct BitMask { - verbose_bit_mask_threshold: u64, -} - -impl BitMask { - #[must_use] - pub fn new(verbose_bit_mask_threshold: u64) -> Self { - Self { - verbose_bit_mask_threshold, - } - } -} - -impl_lint_pass!(BitMask => [BAD_BIT_MASK, INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK]); - -impl<'tcx> LateLintPass<'tcx> for BitMask { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if let ExprKind::Binary(cmp, left, right) = &e.kind { - if cmp.node.is_comparison() { - if let Some(cmp_opt) = fetch_int_literal(cx, right) { - check_compare(cx, left, cmp.node, cmp_opt, e.span) - } else if let Some(cmp_val) = fetch_int_literal(cx, left) { - check_compare(cx, right, invert_cmp(cmp.node), cmp_val, e.span) - } - } - } - 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| { - let sugg = Sugg::hir(cx, left1, "...").maybe_par(); - diag.span_suggestion( - e.span, - "try", - format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()), - Applicability::MaybeIncorrect, - ); - }); - } - } - } -} - -#[must_use] -fn invert_cmp(cmp: BinOpKind) -> BinOpKind { - match cmp { - BinOpKind::Eq => BinOpKind::Eq, - BinOpKind::Ne => BinOpKind::Ne, - BinOpKind::Lt => BinOpKind::Gt, - BinOpKind::Gt => BinOpKind::Lt, - BinOpKind::Le => BinOpKind::Ge, - BinOpKind::Ge => BinOpKind::Le, - _ => BinOpKind::Or, // Dummy - } -} - -fn check_compare(cx: &LateContext<'_>, bit_op: &Expr<'_>, cmp_op: BinOpKind, cmp_value: u128, span: Span) { - if let ExprKind::Binary(op, left, right) = &bit_op.kind { - if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr { - return; - } - fetch_int_literal(cx, right) - .or_else(|| fetch_int_literal(cx, left)) - .map_or((), |mask| check_bit_mask(cx, op.node, cmp_op, mask, cmp_value, span)) - } -} - -#[allow(clippy::too_many_lines)] -fn check_bit_mask( - cx: &LateContext<'_>, - bit_op: BinOpKind, - cmp_op: BinOpKind, - mask_value: u128, - cmp_value: u128, - span: Span, -) { - match cmp_op { - BinOpKind::Eq | BinOpKind::Ne => match bit_op { - BinOpKind::BitAnd => { - if mask_value & cmp_value != cmp_value { - if cmp_value != 0 { - span_lint( - cx, - BAD_BIT_MASK, - span, - &format!( - "incompatible bit mask: `_ & {}` can never be equal to `{}`", - mask_value, cmp_value - ), - ); - } - } else if mask_value == 0 { - span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero"); - } - }, - BinOpKind::BitOr => { - if mask_value | cmp_value != cmp_value { - span_lint( - cx, - BAD_BIT_MASK, - span, - &format!( - "incompatible bit mask: `_ | {}` can never be equal to `{}`", - mask_value, cmp_value - ), - ); - } - }, - _ => (), - }, - BinOpKind::Lt | BinOpKind::Ge => match bit_op { - BinOpKind::BitAnd => { - if mask_value < cmp_value { - span_lint( - cx, - BAD_BIT_MASK, - span, - &format!( - "incompatible bit mask: `_ & {}` will always be lower than `{}`", - mask_value, cmp_value - ), - ); - } else if mask_value == 0 { - span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero"); - } - }, - BinOpKind::BitOr => { - if mask_value >= cmp_value { - span_lint( - cx, - BAD_BIT_MASK, - span, - &format!( - "incompatible bit mask: `_ | {}` will never be lower than `{}`", - mask_value, cmp_value - ), - ); - } else { - check_ineffective_lt(cx, span, mask_value, cmp_value, "|"); - } - }, - BinOpKind::BitXor => check_ineffective_lt(cx, span, mask_value, cmp_value, "^"), - _ => (), - }, - BinOpKind::Le | BinOpKind::Gt => match bit_op { - BinOpKind::BitAnd => { - if mask_value <= cmp_value { - span_lint( - cx, - BAD_BIT_MASK, - span, - &format!( - "incompatible bit mask: `_ & {}` will never be higher than `{}`", - mask_value, cmp_value - ), - ); - } else if mask_value == 0 { - span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero"); - } - }, - BinOpKind::BitOr => { - if mask_value > cmp_value { - span_lint( - cx, - BAD_BIT_MASK, - span, - &format!( - "incompatible bit mask: `_ | {}` will always be higher than `{}`", - mask_value, cmp_value - ), - ); - } else { - check_ineffective_gt(cx, span, mask_value, cmp_value, "|"); - } - }, - BinOpKind::BitXor => check_ineffective_gt(cx, span, mask_value, cmp_value, "^"), - _ => (), - }, - _ => (), - } -} - -fn check_ineffective_lt(cx: &LateContext<'_>, span: Span, m: u128, c: u128, op: &str) { - if c.is_power_of_two() && m < c { - span_lint( - cx, - INEFFECTIVE_BIT_MASK, - span, - &format!( - "ineffective bit mask: `x {} {}` compared to `{}`, is the same as x compared directly", - op, m, c - ), - ); - } -} - -fn check_ineffective_gt(cx: &LateContext<'_>, span: Span, m: u128, c: u128, op: &str) { - if (c + 1).is_power_of_two() && m <= c { - span_lint( - cx, - INEFFECTIVE_BIT_MASK, - span, - &format!( - "ineffective bit mask: `x {} {}` compared to `{}`, is the same as x compared directly", - op, m, c - ), - ); - } -} - -fn fetch_int_literal(cx: &LateContext<'_>, lit: &Expr<'_>) -> Option { - match constant(cx, cx.typeck_results(), lit)?.0 { - Constant::Int(n) => Some(n), - _ => None, - } -} diff --git a/clippy_lints/src/blacklisted_name.rs b/clippy_lints/src/blacklisted_name.rs deleted file mode 100644 index 153870fb4165..000000000000 --- a/clippy_lints/src/blacklisted_name.rs +++ /dev/null @@ -1,51 +0,0 @@ -use crate::utils::span_lint; -use rustc_data_structures::fx::FxHashSet; -use rustc_hir::{Pat, PatKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of blacklisted names for variables, such - /// as `foo`. - /// - /// **Why is this bad?** These names are usually placeholder names and should be - /// avoided. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let foo = 3.14; - /// ``` - pub BLACKLISTED_NAME, - style, - "usage of a blacklisted/placeholder name" -} - -#[derive(Clone, Debug)] -pub struct BlacklistedName { - blacklist: FxHashSet, -} - -impl BlacklistedName { - pub fn new(blacklist: FxHashSet) -> Self { - Self { blacklist } - } -} - -impl_lint_pass!(BlacklistedName => [BLACKLISTED_NAME]); - -impl<'tcx> LateLintPass<'tcx> for BlacklistedName { - fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { - if let PatKind::Binding(.., ident, _) = pat.kind { - if self.blacklist.contains(&ident.name.to_string()) { - span_lint( - cx, - BLACKLISTED_NAME, - ident.span, - &format!("use of a blacklisted/placeholder name `{}`", ident.name), - ); - } - } - } -} diff --git a/clippy_lints/src/blocks_in_if_conditions.rs b/clippy_lints/src/blocks_in_if_conditions.rs deleted file mode 100644 index 736730d4084f..000000000000 --- a/clippy_lints/src/blocks_in_if_conditions.rs +++ /dev/null @@ -1,144 +0,0 @@ -use crate::utils::{differing_macro_contexts, higher, snippet_block_with_applicability, span_lint, span_lint_and_sugg}; -use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; -use rustc_hir::{BlockCheckMode, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; -use rustc_middle::lint::in_external_macro; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -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. - /// - /// **Known problems:** None. - /// - /// **Examples:** - /// ```rust - /// // Bad - /// if { true } { /* ... */ } - /// - /// // Good - /// if true { /* ... */ } - /// ``` - /// - /// // or - /// - /// ```rust - /// # fn somefunc() -> bool { true }; - /// // Bad - /// if { let x = somefunc(); x } { /* ... */ } - /// - /// // Good - /// let res = { let x = somefunc(); x }; - /// if res { /* ... */ } - /// ``` - pub BLOCKS_IN_IF_CONDITIONS, - style, - "useless or complex blocks that can be eliminated in conditions" -} - -declare_lint_pass!(BlocksInIfConditions => [BLOCKS_IN_IF_CONDITIONS]); - -struct ExVisitor<'a, 'tcx> { - found_block: Option<&'tcx Expr<'tcx>>, - cx: &'a LateContext<'tcx>, -} - -impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { - if let ExprKind::Closure(_, _, eid, _, _) = expr.kind { - let body = self.cx.tcx.hir().body(eid); - let ex = &body.value; - if matches!(ex.kind, ExprKind::Block(_, _)) && !body.value.span.from_expansion() { - self.found_block = Some(ex); - return; - } - } - walk_expr(self, expr); - } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -const BRACED_EXPR_MESSAGE: &str = "omit braces around single expression condition"; -const COMPLEX_BLOCK_MESSAGE: &str = "in an `if` condition, avoid complex blocks or closures with blocks; \ - instead, move the block or closure higher and bind it with a `let`"; - -impl<'tcx> LateLintPass<'tcx> for BlocksInIfConditions { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if in_external_macro(cx.sess(), expr.span) { - return; - } - if let Some((cond, _, _)) = higher::if_block(&expr) { - 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() || differing_macro_contexts(expr.span, ex.span) { - return; - } - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - BLOCKS_IN_IF_CONDITIONS, - cond.span, - BRACED_EXPR_MESSAGE, - "try", - format!( - "{}", - snippet_block_with_applicability( - cx, - ex.span, - "..", - Some(expr.span), - &mut applicability - ) - ), - applicability, - ); - } - } else { - let span = block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span); - if span.from_expansion() || differing_macro_contexts(expr.span, span) { - return; - } - // move block higher - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - BLOCKS_IN_IF_CONDITIONS, - expr.span.with_hi(cond.span.hi()), - COMPLEX_BLOCK_MESSAGE, - "try", - format!( - "let res = {}; if res", - snippet_block_with_applicability( - cx, - block.span, - "..", - Some(expr.span), - &mut applicability - ), - ), - applicability, - ); - } - } - } else { - let mut visitor = ExVisitor { found_block: None, cx }; - walk_expr(&mut visitor, cond); - if let Some(block) = visitor.found_block { - span_lint(cx, BLOCKS_IN_IF_CONDITIONS, block.span, COMPLEX_BLOCK_MESSAGE); - } - } - } - } -} diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs deleted file mode 100644 index 90bb0bd555f2..000000000000 --- a/clippy_lints/src/booleans.rs +++ /dev/null @@ -1,504 +0,0 @@ -use crate::utils::{ - eq_expr_value, get_trait_def_id, implements_trait, in_macro, is_type_diagnostic_item, paths, snippet_opt, - span_lint_and_sugg, span_lint_and_then, -}; -use if_chain::if_chain; -use rustc_ast::ast::LitKind; -use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_expr, FnKind, NestedVisitorMap, Visitor}; -use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, UnOp}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** Checks for boolean expressions that can be written more - /// concisely. - /// - /// **Why is this bad?** Readability of boolean expressions suffers from - /// unnecessary duplication. - /// - /// **Known problems:** Ignores short circuiting behavior of `||` and - /// `&&`. Ignores `|`, `&` and `^`. - /// - /// **Example:** - /// ```ignore - /// if a && true // should be: if a - /// if !(a == b) // should be: if a != b - /// ``` - pub NONMINIMAL_BOOL, - complexity, - "boolean expressions that can be written more concisely" -} - -declare_clippy_lint! { - /// **What it does:** Checks for boolean expressions that contain terminals that - /// can be eliminated. - /// - /// **Why is this bad?** This is most likely a logic bug. - /// - /// **Known problems:** Ignores short circuiting behavior. - /// - /// **Example:** - /// ```ignore - /// if a && b || a { ... } - /// ``` - /// The `b` is unnecessary, the expression is equivalent to `if a`. - pub LOGIC_BUG, - correctness, - "boolean expressions that contain terminals which can be eliminated" -} - -// For each pairs, both orders are considered. -const METHODS_WITH_NEGATION: [(&str, &str); 2] = [("is_some", "is_none"), ("is_err", "is_ok")]; - -declare_lint_pass!(NonminimalBool => [NONMINIMAL_BOOL, LOGIC_BUG]); - -impl<'tcx> LateLintPass<'tcx> for NonminimalBool { - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - _: FnKind<'tcx>, - _: &'tcx FnDecl<'_>, - body: &'tcx Body<'_>, - _: Span, - _: HirId, - ) { - NonminimalBoolVisitor { cx }.visit_body(body) - } -} - -struct NonminimalBoolVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, -} - -use quine_mc_cluskey::Bool; -struct Hir2Qmm<'a, 'tcx, 'v> { - terminals: Vec<&'v Expr<'v>>, - cx: &'a LateContext<'tcx>, -} - -impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> { - fn extract(&mut self, op: BinOpKind, a: &[&'v Expr<'_>], mut v: Vec) -> Result, String> { - for a in a { - if let ExprKind::Binary(binop, lhs, rhs) = &a.kind { - if binop.node == op { - v = self.extract(op, &[lhs, rhs], v)?; - continue; - } - } - v.push(self.run(a)?); - } - Ok(v) - } - - fn run(&mut self, e: &'v Expr<'_>) -> Result { - fn negate(bin_op_kind: BinOpKind) -> Option { - match bin_op_kind { - BinOpKind::Eq => Some(BinOpKind::Ne), - BinOpKind::Ne => Some(BinOpKind::Eq), - BinOpKind::Gt => Some(BinOpKind::Le), - BinOpKind::Ge => Some(BinOpKind::Lt), - BinOpKind::Lt => Some(BinOpKind::Ge), - BinOpKind::Le => Some(BinOpKind::Gt), - _ => None, - } - } - - // prevent folding of `cfg!` macros and the like - if !e.span.from_expansion() { - match &e.kind { - ExprKind::Unary(UnOp::UnNot, inner) => return Ok(Bool::Not(box self.run(inner)?)), - ExprKind::Binary(binop, lhs, rhs) => match &binop.node { - BinOpKind::Or => { - return Ok(Bool::Or(self.extract(BinOpKind::Or, &[lhs, rhs], Vec::new())?)); - }, - BinOpKind::And => { - return Ok(Bool::And(self.extract(BinOpKind::And, &[lhs, rhs], Vec::new())?)); - }, - _ => (), - }, - ExprKind::Lit(lit) => match lit.node { - LitKind::Bool(true) => return Ok(Bool::True), - LitKind::Bool(false) => return Ok(Bool::False), - _ => (), - }, - _ => (), - } - } - for (n, expr) in self.terminals.iter().enumerate() { - if eq_expr_value(self.cx, e, expr) { - #[allow(clippy::cast_possible_truncation)] - return Ok(Bool::Term(n as u8)); - } - - if_chain! { - if let ExprKind::Binary(e_binop, e_lhs, e_rhs) = &e.kind; - if implements_ord(self.cx, e_lhs); - if let ExprKind::Binary(expr_binop, expr_lhs, expr_rhs) = &expr.kind; - if negate(e_binop.node) == Some(expr_binop.node); - 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)] - 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)] - Ok(Bool::Term(n as u8)) - } else { - Err("too many literals".to_owned()) - } - } -} - -struct SuggestContext<'a, 'tcx, 'v> { - terminals: &'v [&'v Expr<'v>], - cx: &'a LateContext<'tcx>, - output: String, -} - -impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> { - fn recurse(&mut self, suggestion: &Bool) -> Option<()> { - use quine_mc_cluskey::Bool::{And, False, Not, Or, Term, True}; - match suggestion { - True => { - self.output.push_str("true"); - }, - False => { - self.output.push_str("false"); - }, - Not(inner) => match **inner { - And(_) | Or(_) => { - self.output.push('!'); - self.output.push('('); - self.recurse(inner); - self.output.push(')'); - }, - Term(n) => { - let terminal = self.terminals[n as usize]; - if let Some(str) = simplify_not(self.cx, terminal) { - self.output.push_str(&str) - } else { - self.output.push('!'); - let snip = snippet_opt(self.cx, terminal.span)?; - self.output.push_str(&snip); - } - }, - True | False | Not(_) => { - self.output.push('!'); - self.recurse(inner)?; - }, - }, - And(v) => { - for (index, inner) in v.iter().enumerate() { - if index > 0 { - self.output.push_str(" && "); - } - if let Or(_) = *inner { - self.output.push('('); - self.recurse(inner); - self.output.push(')'); - } else { - self.recurse(inner); - } - } - }, - Or(v) => { - for (index, inner) in v.iter().rev().enumerate() { - if index > 0 { - self.output.push_str(" || "); - } - self.recurse(inner); - } - }, - &Term(n) => { - let snip = snippet_opt(self.cx, self.terminals[n as usize].span)?; - self.output.push_str(&snip); - }, - } - Some(()) - } -} - -fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { - match &expr.kind { - ExprKind::Binary(binop, lhs, rhs) => { - if !implements_ord(cx, lhs) { - return None; - } - - match binop.node { - BinOpKind::Eq => Some(" != "), - BinOpKind::Ne => Some(" == "), - BinOpKind::Lt => Some(" >= "), - BinOpKind::Gt => Some(" <= "), - BinOpKind::Le => Some(" > "), - BinOpKind::Ge => Some(" < "), - _ => None, - } - .and_then(|op| { - Some(format!( - "{}{}{}", - snippet_opt(cx, lhs.span)?, - op, - snippet_opt(cx, rhs.span)? - )) - }) - }, - ExprKind::MethodCall(path, _, args, _) if args.len() == 1 => { - let type_of_receiver = cx.typeck_results().expr_ty(&args[0]); - if !is_type_diagnostic_item(cx, type_of_receiver, sym::option_type) - && !is_type_diagnostic_item(cx, type_of_receiver, sym::result_type) - { - return None; - } - METHODS_WITH_NEGATION - .iter() - .cloned() - .flat_map(|(a, b)| vec![(a, b), (b, a)]) - .find(|&(a, _)| { - let path: &str = &path.ident.name.as_str(); - a == path - }) - .and_then(|(_, neg_method)| Some(format!("{}.{}()", snippet_opt(cx, args[0].span)?, neg_method))) - }, - _ => None, - } -} - -fn suggest(cx: &LateContext<'_>, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String { - let mut suggest_context = SuggestContext { - terminals, - cx, - output: String::new(), - }; - suggest_context.recurse(suggestion); - suggest_context.output -} - -fn simple_negate(b: Bool) -> Bool { - use quine_mc_cluskey::Bool::{And, False, Not, Or, Term, True}; - match b { - True => False, - False => True, - t @ Term(_) => Not(Box::new(t)), - And(mut v) => { - for el in &mut v { - *el = simple_negate(::std::mem::replace(el, True)); - } - Or(v) - }, - Or(mut v) => { - for el in &mut v { - *el = simple_negate(::std::mem::replace(el, True)); - } - And(v) - }, - Not(inner) => *inner, - } -} - -#[derive(Default)] -struct Stats { - terminals: [usize; 32], - negations: usize, - ops: usize, -} - -fn terminal_stats(b: &Bool) -> Stats { - fn recurse(b: &Bool, stats: &mut Stats) { - match b { - True | False => stats.ops += 1, - Not(inner) => { - match **inner { - And(_) | Or(_) => stats.ops += 1, // brackets are also operations - _ => stats.negations += 1, - } - recurse(inner, stats); - }, - And(v) | Or(v) => { - stats.ops += v.len() - 1; - for inner in v { - recurse(inner, stats); - } - }, - &Term(n) => stats.terminals[n as usize] += 1, - } - } - use quine_mc_cluskey::Bool::{And, False, Not, Or, Term, True}; - let mut stats = Stats::default(); - recurse(b, &mut stats); - stats -} - -impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> { - fn bool_expr(&self, e: &'tcx Expr<'_>) { - let mut h2q = Hir2Qmm { - terminals: Vec::new(), - cx: self.cx, - }; - if let Ok(expr) = h2q.run(e) { - if h2q.terminals.len() > 8 { - // QMC has exponentially slow behavior as the number of terminals increases - // 8 is reasonable, it takes approximately 0.2 seconds. - // See #825 - return; - } - - let stats = terminal_stats(&expr); - let mut simplified = expr.simplify(); - for simple in Bool::Not(Box::new(expr)).simplify() { - match simple { - Bool::Not(_) | Bool::True | Bool::False => {}, - _ => simplified.push(Bool::Not(Box::new(simple.clone()))), - } - let simple_negated = simple_negate(simple); - if simplified.iter().any(|s| *s == simple_negated) { - continue; - } - simplified.push(simple_negated); - } - let mut improvements = Vec::with_capacity(simplified.len()); - 'simplified: for suggestion in &simplified { - let simplified_stats = terminal_stats(suggestion); - let mut improvement = false; - for i in 0..32 { - // ignore any "simplifications" that end up requiring a terminal more often - // than in the original expression - if stats.terminals[i] < simplified_stats.terminals[i] { - continue 'simplified; - } - if stats.terminals[i] != 0 && simplified_stats.terminals[i] == 0 { - span_lint_and_then( - self.cx, - LOGIC_BUG, - e.span, - "this boolean expression contains a logic bug", - |diag| { - diag.span_help( - h2q.terminals[i].span, - "this expression can be optimized out by applying boolean operations to the \ - outer expression", - ); - diag.span_suggestion( - e.span, - "it would look like the following", - suggest(self.cx, suggestion, &h2q.terminals), - // nonminimal_bool can produce minimal but - // not human readable expressions (#3141) - Applicability::Unspecified, - ); - }, - ); - // don't also lint `NONMINIMAL_BOOL` - return; - } - // if the number of occurrences of a terminal decreases or any of the stats - // decreases while none increases - improvement |= (stats.terminals[i] > simplified_stats.terminals[i]) - || (stats.negations > simplified_stats.negations && stats.ops == simplified_stats.ops) - || (stats.ops > simplified_stats.ops && stats.negations == simplified_stats.negations); - } - if improvement { - improvements.push(suggestion); - } - } - let nonminimal_bool_lint = |suggestions: Vec<_>| { - span_lint_and_then( - self.cx, - NONMINIMAL_BOOL, - e.span, - "this boolean expression can be simplified", - |diag| { - diag.span_suggestions( - e.span, - "try", - suggestions.into_iter(), - // nonminimal_bool can produce minimal but - // not human readable expressions (#3141) - Applicability::Unspecified, - ); - }, - ); - }; - if improvements.is_empty() { - let mut visitor = NotSimplificationVisitor { cx: self.cx }; - visitor.visit_expr(e); - } else { - nonminimal_bool_lint( - improvements - .into_iter() - .map(|suggestion| suggest(self.cx, suggestion, &h2q.terminals)) - .collect(), - ); - } - } - } -} - -impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, e: &'tcx Expr<'_>) { - if in_macro(e.span) { - return; - } - match &e.kind { - ExprKind::Binary(binop, _, _) if binop.node == BinOpKind::Or || binop.node == BinOpKind::And => { - self.bool_expr(e) - }, - ExprKind::Unary(UnOp::UnNot, inner) => { - if self.cx.typeck_results().node_types()[inner.hir_id].is_bool() { - self.bool_expr(e); - } else { - walk_expr(self, e); - } - }, - _ => walk_expr(self, e), - } - } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -fn implements_ord<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool { - let ty = cx.typeck_results().expr_ty(expr); - get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[])) -} - -struct NotSimplificationVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, -} - -impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if let ExprKind::Unary(UnOp::UnNot, inner) = &expr.kind { - if let Some(suggestion) = simplify_not(self.cx, inner) { - span_lint_and_sugg( - self.cx, - NONMINIMAL_BOOL, - expr.span, - "this boolean expression can be simplified", - "try", - suggestion, - Applicability::MachineApplicable, - ); - } - } - - walk_expr(self, expr); - } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs deleted file mode 100644 index 38a0e27c4cf5..000000000000 --- a/clippy_lints/src/bytecount.rs +++ /dev/null @@ -1,118 +0,0 @@ -use crate::utils::{ - contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability, span_lint_and_sugg, -}; -use if_chain::if_chain; -use rustc_ast::ast::UintTy; -use rustc_errors::Applicability; -use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, UnOp}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; -use rustc_span::Symbol; - -declare_clippy_lint! { - /// **What it does:** Checks for naive byte counts - /// - /// **Why is this bad?** The [`bytecount`](https://crates.io/crates/bytecount) - /// crate has methods to count your bytes faster, especially for large slices. - /// - /// **Known problems:** If you have predominantly small slices, the - /// `bytecount::count(..)` method may actually be slower. However, if you can - /// ensure that less than 2³²-1 matches arise, the `naive_count_32(..)` can be - /// faster in those cases. - /// - /// **Example:** - /// - /// ```rust - /// # let vec = vec![1_u8]; - /// &vec.iter().filter(|x| **x == 0u8).count(); // use bytecount::count instead - /// ``` - pub NAIVE_BYTECOUNT, - perf, - "use of naive `.filter(|&x| x == y).count()` to count byte values" -} - -declare_lint_pass!(ByteCount => [NAIVE_BYTECOUNT]); - -impl<'tcx> LateLintPass<'tcx> for ByteCount { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::MethodCall(ref count, _, ref count_args, _) = expr.kind; - if count.ident.name == sym!(count); - if count_args.len() == 1; - if let ExprKind::MethodCall(ref filter, _, ref filter_args, _) = count_args[0].kind; - if filter.ident.name == sym!(filter); - if filter_args.len() == 2; - if let ExprKind::Closure(_, _, body_id, _, _) = filter_args[1].kind; - then { - let body = cx.tcx.hir().body(body_id); - if_chain! { - if body.params.len() == 1; - if let Some(argname) = get_pat_name(&body.params[0].pat); - if let ExprKind::Binary(ref op, ref l, ref r) = body.value.kind; - if op.node == BinOpKind::Eq; - if match_type(cx, - cx.typeck_results().expr_ty(&filter_args[0]).peel_refs(), - &paths::SLICE_ITER); - then { - let needle = match get_path_name(l) { - Some(name) if check_arg(name, argname, r) => r, - _ => match get_path_name(r) { - Some(name) if check_arg(name, argname, l) => l, - _ => { return; } - } - }; - if ty::Uint(UintTy::U8) != *cx.typeck_results().expr_ty(needle).peel_refs().kind() { - return; - } - let haystack = if let ExprKind::MethodCall(ref path, _, ref args, _) = - filter_args[0].kind { - let p = path.ident.name; - if (p == sym::iter || p == sym!(iter_mut)) && args.len() == 1 { - &args[0] - } else { - &filter_args[0] - } - } else { - &filter_args[0] - }; - let mut applicability = Applicability::MaybeIncorrect; - span_lint_and_sugg( - cx, - NAIVE_BYTECOUNT, - expr.span, - "you appear to be counting bytes the naive way", - "consider using the bytecount crate", - format!("bytecount::count({}, {})", - snippet_with_applicability(cx, haystack.span, "..", &mut applicability), - snippet_with_applicability(cx, needle.span, "..", &mut applicability)), - applicability, - ); - } - }; - } - }; - } -} - -fn check_arg(name: Symbol, arg: Symbol, needle: &Expr<'_>) -> bool { - name == arg && !contains_name(name, needle) -} - -fn get_path_name(expr: &Expr<'_>) -> Option { - match expr.kind { - ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) | ExprKind::Unary(UnOp::UnDeref, ref e) => { - get_path_name(e) - }, - ExprKind::Block(ref b, _) => { - if b.stmts.is_empty() { - b.expr.as_ref().and_then(|p| get_path_name(p)) - } else { - None - } - }, - ExprKind::Path(ref qpath) => single_segment_path(qpath).map(|ps| ps.ident.name), - _ => None, - } -} diff --git a/clippy_lints/src/cargo_common_metadata.rs b/clippy_lints/src/cargo_common_metadata.rs deleted file mode 100644 index 0d294761af5a..000000000000 --- a/clippy_lints/src/cargo_common_metadata.rs +++ /dev/null @@ -1,112 +0,0 @@ -//! lint on missing cargo common metadata - -use std::path::PathBuf; - -use crate::utils::{run_lints, span_lint}; -use rustc_hir::{hir_id::CRATE_HIR_ID, Crate}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::DUMMY_SP; - -declare_clippy_lint! { - /// **What it does:** Checks to see if all common metadata is defined in - /// `Cargo.toml`. See: https://rust-lang-nursery.github.io/api-guidelines/documentation.html#cargotoml-includes-all-common-metadata-c-metadata - /// - /// **Why is this bad?** It will be more difficult for users to discover the - /// purpose of the crate, and key information related to it. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```toml - /// # This `Cargo.toml` is missing an authors field: - /// [package] - /// name = "clippy" - /// version = "0.0.212" - /// description = "A bunch of helpful lints to avoid common pitfalls in Rust" - /// repository = "https://github.com/rust-lang/rust-clippy" - /// readme = "README.md" - /// license = "MIT OR Apache-2.0" - /// keywords = ["clippy", "lint", "plugin"] - /// categories = ["development-tools", "development-tools::cargo-plugins"] - /// ``` - /// - /// Should include an authors field like: - /// - /// ```toml - /// # This `Cargo.toml` includes all common metadata - /// [package] - /// name = "clippy" - /// version = "0.0.212" - /// authors = ["Someone "] - /// description = "A bunch of helpful lints to avoid common pitfalls in Rust" - /// repository = "https://github.com/rust-lang/rust-clippy" - /// readme = "README.md" - /// license = "MIT OR Apache-2.0" - /// keywords = ["clippy", "lint", "plugin"] - /// categories = ["development-tools", "development-tools::cargo-plugins"] - /// ``` - pub CARGO_COMMON_METADATA, - cargo, - "common metadata is defined in `Cargo.toml`" -} - -fn missing_warning(cx: &LateContext<'_>, package: &cargo_metadata::Package, field: &str) { - let message = format!("package `{}` is missing `{}` metadata", package.name, field); - span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, &message); -} - -fn is_empty_str(value: &Option) -> bool { - value.as_ref().map_or(true, String::is_empty) -} - -fn is_empty_path(value: &Option) -> bool { - value.as_ref().and_then(|x| x.to_str()).map_or(true, str::is_empty) -} - -fn is_empty_vec(value: &[String]) -> bool { - // This works because empty iterators return true - value.iter().all(String::is_empty) -} - -declare_lint_pass!(CargoCommonMetadata => [CARGO_COMMON_METADATA]); - -impl LateLintPass<'_> for CargoCommonMetadata { - fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { - if !run_lints(cx, &[CARGO_COMMON_METADATA], CRATE_HIR_ID) { - return; - } - - let metadata = unwrap_cargo_metadata!(cx, CARGO_COMMON_METADATA, false); - - for package in metadata.packages { - if is_empty_vec(&package.authors) { - missing_warning(cx, &package, "package.authors"); - } - - if is_empty_str(&package.description) { - missing_warning(cx, &package, "package.description"); - } - - if is_empty_str(&package.license) && is_empty_path(&package.license_file) { - missing_warning(cx, &package, "either package.license or package.license_file"); - } - - if is_empty_str(&package.repository) { - missing_warning(cx, &package, "package.repository"); - } - - if is_empty_path(&package.readme) { - missing_warning(cx, &package, "package.readme"); - } - - if is_empty_vec(&package.keywords) { - missing_warning(cx, &package, "package.keywords"); - } - - if is_empty_vec(&package.categories) { - missing_warning(cx, &package, "package.categories"); - } - } - } -} diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs deleted file mode 100644 index 54bc69e058bc..000000000000 --- a/clippy_lints/src/checked_conversions.rs +++ /dev/null @@ -1,360 +0,0 @@ -//! lint on manually implemented checked conversions that could be transformed into `try_from` - -use if_chain::if_chain; -use rustc_ast::ast::LitKind; -use rustc_errors::Applicability; -use rustc_hir::{BinOp, BinOpKind, Expr, ExprKind, QPath, TyKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_semver::RustcVersion; -use rustc_session::{declare_tool_lint, impl_lint_pass}; - -use crate::utils::{meets_msrv, snippet_with_applicability, span_lint_and_sugg, SpanlessEq}; - -const CHECKED_CONVERSIONS_MSRV: RustcVersion = RustcVersion::new(1, 34, 0); - -declare_clippy_lint! { - /// **What it does:** Checks for explicit bounds checking when casting. - /// - /// **Why is this bad?** Reduces the readability of statements & is error prone. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let foo: u32 = 5; - /// # let _ = - /// foo <= i32::MAX as u32 - /// # ; - /// ``` - /// - /// Could be written: - /// - /// ```rust - /// # use std::convert::TryFrom; - /// # let foo = 1; - /// # let _ = - /// i32::try_from(foo).is_ok() - /// # ; - /// ``` - pub CHECKED_CONVERSIONS, - pedantic, - "`try_from` could replace manual bounds checking when casting" -} - -pub struct CheckedConversions { - msrv: Option, -} - -impl CheckedConversions { - #[must_use] - pub fn new(msrv: Option) -> Self { - Self { msrv } - } -} - -impl_lint_pass!(CheckedConversions => [CHECKED_CONVERSIONS]); - -impl<'tcx> LateLintPass<'tcx> for CheckedConversions { - fn check_expr(&mut self, cx: &LateContext<'_>, item: &Expr<'_>) { - if !meets_msrv(self.msrv.as_ref(), &CHECKED_CONVERSIONS_MSRV) { - return; - } - - let result = if_chain! { - if !in_external_macro(cx.sess(), item.span); - if let ExprKind::Binary(op, ref left, ref right) = &item.kind; - - then { - match op.node { - BinOpKind::Ge | BinOpKind::Le => single_check(item), - BinOpKind::And => double_check(cx, left, right), - _ => None, - } - } else { - None - } - }; - - if let Some(cv) = result { - if let Some(to_type) = cv.to_type { - let mut applicability = Applicability::MachineApplicable; - let snippet = snippet_with_applicability(cx, cv.expr_to_cast.span, "_", &mut applicability); - span_lint_and_sugg( - cx, - CHECKED_CONVERSIONS, - item.span, - "checked cast can be simplified", - "try", - format!("{}::try_from({}).is_ok()", to_type, snippet), - applicability, - ); - } - } - } - - extract_msrv_attr!(LateContext); -} - -/// Searches for a single check from unsigned to _ is done -/// todo: check for case signed -> larger unsigned == only x >= 0 -fn single_check<'tcx>(expr: &'tcx Expr<'tcx>) -> Option> { - check_upper_bound(expr).filter(|cv| cv.cvt == ConversionType::FromUnsigned) -} - -/// Searches for a combination of upper & lower bound checks -fn double_check<'a>(cx: &LateContext<'_>, left: &'a Expr<'_>, right: &'a Expr<'_>) -> Option> { - let upper_lower = |l, r| { - let upper = check_upper_bound(l); - let lower = check_lower_bound(r); - - upper.zip(lower).and_then(|(l, r)| l.combine(r, cx)) - }; - - upper_lower(left, right).or_else(|| upper_lower(right, left)) -} - -/// Contains the result of a tried conversion check -#[derive(Clone, Debug)] -struct Conversion<'a> { - cvt: ConversionType, - expr_to_cast: &'a Expr<'a>, - to_type: Option<&'a str>, -} - -/// The kind of conversion that is checked -#[derive(Copy, Clone, Debug, PartialEq)] -enum ConversionType { - SignedToUnsigned, - SignedToSigned, - FromUnsigned, -} - -impl<'a> Conversion<'a> { - /// Combine multiple conversions if the are compatible - pub fn combine(self, other: Self, cx: &LateContext<'_>) -> Option> { - if self.is_compatible(&other, cx) { - // Prefer a Conversion that contains a type-constraint - Some(if self.to_type.is_some() { self } else { other }) - } else { - None - } - } - - /// Checks if two conversions are compatible - /// same type of conversion, same 'castee' and same 'to type' - pub fn is_compatible(&self, other: &Self, cx: &LateContext<'_>) -> bool { - (self.cvt == other.cvt) - && (SpanlessEq::new(cx).eq_expr(self.expr_to_cast, other.expr_to_cast)) - && (self.has_compatible_to_type(other)) - } - - /// Checks if the to-type is the same (if there is a type constraint) - fn has_compatible_to_type(&self, other: &Self) -> bool { - match (self.to_type, other.to_type) { - (Some(l), Some(r)) => l == r, - _ => true, - } - } - - /// Try to construct a new conversion if the conversion type is valid - fn try_new(expr_to_cast: &'a Expr<'_>, from_type: &str, to_type: &'a str) -> Option> { - ConversionType::try_new(from_type, to_type).map(|cvt| Conversion { - cvt, - expr_to_cast, - to_type: Some(to_type), - }) - } - - /// Construct a new conversion without type constraint - fn new_any(expr_to_cast: &'a Expr<'_>) -> Conversion<'a> { - Conversion { - cvt: ConversionType::SignedToUnsigned, - expr_to_cast, - to_type: None, - } - } -} - -impl ConversionType { - /// Creates a conversion type if the type is allowed & conversion is valid - #[must_use] - fn try_new(from: &str, to: &str) -> Option { - if UINTS.contains(&from) { - Some(Self::FromUnsigned) - } else if SINTS.contains(&from) { - if UINTS.contains(&to) { - Some(Self::SignedToUnsigned) - } else if SINTS.contains(&to) { - Some(Self::SignedToSigned) - } else { - None - } - } else { - None - } - } -} - -/// Check for `expr <= (to_type::MAX as from_type)` -fn check_upper_bound<'tcx>(expr: &'tcx Expr<'tcx>) -> Option> { - if_chain! { - if let ExprKind::Binary(ref op, ref left, ref right) = &expr.kind; - if let Some((candidate, check)) = normalize_le_ge(op, left, right); - if let Some((from, to)) = get_types_from_cast(check, INTS, "max_value", "MAX"); - - then { - Conversion::try_new(candidate, from, to) - } else { - None - } - } -} - -/// Check for `expr >= 0|(to_type::MIN as from_type)` -fn check_lower_bound<'tcx>(expr: &'tcx Expr<'tcx>) -> Option> { - fn check_function<'a>(candidate: &'a Expr<'a>, check: &'a Expr<'a>) -> Option> { - (check_lower_bound_zero(candidate, check)).or_else(|| (check_lower_bound_min(candidate, check))) - } - - // First of we need a binary containing the expression & the cast - if let ExprKind::Binary(ref op, ref left, ref right) = &expr.kind { - normalize_le_ge(op, right, left).and_then(|(l, r)| check_function(l, r)) - } else { - None - } -} - -/// Check for `expr >= 0` -fn check_lower_bound_zero<'a>(candidate: &'a Expr<'_>, check: &'a Expr<'_>) -> Option> { - if_chain! { - if let ExprKind::Lit(ref lit) = &check.kind; - if let LitKind::Int(0, _) = &lit.node; - - then { - Some(Conversion::new_any(candidate)) - } else { - None - } - } -} - -/// Check for `expr >= (to_type::MIN as from_type)` -fn check_lower_bound_min<'a>(candidate: &'a Expr<'_>, check: &'a Expr<'_>) -> Option> { - if let Some((from, to)) = get_types_from_cast(check, SINTS, "min_value", "MIN") { - Conversion::try_new(candidate, from, to) - } else { - None - } -} - -/// Tries to extract the from- and to-type from a cast expression -fn get_types_from_cast<'a>( - expr: &'a Expr<'_>, - types: &'a [&str], - func: &'a str, - assoc_const: &'a str, -) -> Option<(&'a str, &'a str)> { - // `to_type::max_value() as from_type` - // or `to_type::MAX as from_type` - let call_from_cast: Option<(&Expr<'_>, &str)> = if_chain! { - // to_type::max_value(), from_type - if let ExprKind::Cast(ref limit, ref from_type) = &expr.kind; - if let TyKind::Path(ref from_type_path) = &from_type.kind; - if let Some(from_sym) = int_ty_to_sym(from_type_path); - - then { - Some((limit, from_sym)) - } else { - None - } - }; - - // `from_type::from(to_type::max_value())` - let limit_from: Option<(&Expr<'_>, &str)> = call_from_cast.or_else(|| { - if_chain! { - // `from_type::from, to_type::max_value()` - if let ExprKind::Call(ref from_func, ref args) = &expr.kind; - // `to_type::max_value()` - if args.len() == 1; - if let limit = &args[0]; - // `from_type::from` - if let ExprKind::Path(ref path) = &from_func.kind; - if let Some(from_sym) = get_implementing_type(path, INTS, "from"); - - then { - Some((limit, from_sym)) - } else { - None - } - } - }); - - if let Some((limit, from_type)) = limit_from { - match limit.kind { - // `from_type::from(_)` - ExprKind::Call(path, _) => { - if let ExprKind::Path(ref path) = path.kind { - // `to_type` - if let Some(to_type) = get_implementing_type(path, types, func) { - return Some((from_type, to_type)); - } - } - }, - // `to_type::MAX` - ExprKind::Path(ref path) => { - if let Some(to_type) = get_implementing_type(path, types, assoc_const) { - return Some((from_type, to_type)); - } - }, - _ => {}, - } - }; - None -} - -/// Gets the type which implements the called function -fn get_implementing_type<'a>(path: &QPath<'_>, candidates: &'a [&str], function: &str) -> Option<&'a str> { - if_chain! { - if let QPath::TypeRelative(ref ty, ref path) = &path; - if path.ident.name.as_str() == function; - if let TyKind::Path(QPath::Resolved(None, ref tp)) = &ty.kind; - if let [int] = &*tp.segments; - let name = &int.ident.name.as_str(); - - then { - candidates.iter().find(|c| name == *c).cloned() - } else { - None - } - } -} - -/// Gets the type as a string, if it is a supported integer -fn int_ty_to_sym<'tcx>(path: &QPath<'_>) -> Option<&'tcx str> { - if_chain! { - if let QPath::Resolved(_, ref path) = *path; - if let [ty] = &*path.segments; - let name = &ty.ident.name.as_str(); - - then { - INTS.iter().find(|c| name == *c).cloned() - } else { - None - } - } -} - -/// Will return the expressions as if they were expr1 <= expr2 -fn normalize_le_ge<'a>(op: &BinOp, left: &'a Expr<'a>, right: &'a Expr<'a>) -> Option<(&'a Expr<'a>, &'a Expr<'a>)> { - match op.node { - BinOpKind::Le => Some((left, right)), - BinOpKind::Ge => Some((right, left)), - _ => None, - } -} - -// Constants -const UINTS: &[&str] = &["u8", "u16", "u32", "u64", "usize"]; -const SINTS: &[&str] = &["i8", "i16", "i32", "i64", "isize"]; -const INTS: &[&str] = &["u8", "u16", "u32", "u64", "usize", "i8", "i16", "i32", "i64", "isize"]; diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs deleted file mode 100644 index b1bc2ec29e16..000000000000 --- a/clippy_lints/src/cognitive_complexity.rs +++ /dev/null @@ -1,163 +0,0 @@ -//! calculate cognitive complexity and warn about overly complex functions - -use rustc_ast::ast::Attribute; -use rustc_hir::intravisit::{walk_expr, FnKind, NestedVisitorMap, Visitor}; -use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; -use rustc_span::{sym, BytePos}; - -use crate::utils::{is_type_diagnostic_item, snippet_opt, span_lint_and_help, LimitStack}; - -declare_clippy_lint! { - /// **What it does:** Checks for methods with high cognitive complexity. - /// - /// **Why is this bad?** Methods of high cognitive complexity tend to be hard to - /// both read and maintain. Also LLVM will tend to optimize small methods better. - /// - /// **Known problems:** Sometimes it's hard to find a way to reduce the - /// complexity. - /// - /// **Example:** No. You'll see it when you get the warning. - pub COGNITIVE_COMPLEXITY, - nursery, - "functions that should be split up into multiple functions" -} - -pub struct CognitiveComplexity { - limit: LimitStack, -} - -impl CognitiveComplexity { - #[must_use] - pub fn new(limit: u64) -> Self { - Self { - limit: LimitStack::new(limit), - } - } -} - -impl_lint_pass!(CognitiveComplexity => [COGNITIVE_COMPLEXITY]); - -impl CognitiveComplexity { - #[allow(clippy::cast_possible_truncation)] - fn check<'tcx>( - &mut self, - cx: &LateContext<'tcx>, - kind: FnKind<'tcx>, - decl: &'tcx FnDecl<'_>, - body: &'tcx Body<'_>, - body_span: Span, - ) { - if body_span.from_expansion() { - return; - } - - let expr = &body.value; - - let mut helper = CCHelper { cc: 1, returns: 0 }; - helper.visit_expr(expr); - let CCHelper { cc, returns } = helper; - let ret_ty = cx.typeck_results().node_type(expr.hir_id); - let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym::result_type) { - returns - } else { - #[allow(clippy::integer_division)] - (returns / 2) - }; - - let mut rust_cc = cc; - // prevent degenerate cases where unreachable code contains `return` statements - if rust_cc >= ret_adjust { - rust_cc -= ret_adjust; - } - - if rust_cc > self.limit.limit() { - let fn_span = match kind { - FnKind::ItemFn(ident, _, _, _, _) | FnKind::Method(ident, _, _, _) => ident.span, - FnKind::Closure(_) => { - let header_span = body_span.with_hi(decl.output.span().lo()); - let pos = snippet_opt(cx, header_span).and_then(|snip| { - let low_offset = snip.find('|')?; - let high_offset = 1 + snip.get(low_offset + 1..)?.find('|')?; - let low = header_span.lo() + BytePos(low_offset as u32); - let high = low + BytePos(high_offset as u32 + 1); - - Some((low, high)) - }); - - if let Some((low, high)) = pos { - Span::new(low, high, header_span.ctxt()) - } else { - return; - } - }, - }; - - span_lint_and_help( - cx, - COGNITIVE_COMPLEXITY, - fn_span, - &format!( - "the function has a cognitive complexity of ({}/{})", - rust_cc, - self.limit.limit() - ), - None, - "you could split it up into multiple smaller functions", - ); - } - } -} - -impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity { - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - kind: FnKind<'tcx>, - decl: &'tcx FnDecl<'_>, - body: &'tcx Body<'_>, - span: Span, - hir_id: HirId, - ) { - let def_id = cx.tcx.hir().local_def_id(hir_id); - if !cx.tcx.has_attr(def_id.to_def_id(), sym::test) { - self.check(cx, kind, decl, body, span); - } - } - - fn enter_lint_attrs(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) { - self.limit.push_attrs(cx.sess(), attrs, "cognitive_complexity"); - } - fn exit_lint_attrs(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) { - self.limit.pop_attrs(cx.sess(), attrs, "cognitive_complexity"); - } -} - -struct CCHelper { - cc: u64, - returns: u64, -} - -impl<'tcx> Visitor<'tcx> for CCHelper { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, e: &'tcx Expr<'_>) { - walk_expr(self, e); - match e.kind { - ExprKind::Match(_, ref arms, _) => { - if arms.len() > 1 { - self.cc += 1; - } - self.cc += arms.iter().filter(|arm| arm.guard.is_some()).count() as u64; - }, - ExprKind::Ret(_) => self.returns += 1, - _ => {}, - } - } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs deleted file mode 100644 index 42bff564de03..000000000000 --- a/clippy_lints/src/collapsible_if.rs +++ /dev/null @@ -1,170 +0,0 @@ -//! Checks for if expressions that contain only an if expression. -//! -//! For example, the lint would catch: -//! -//! ```rust,ignore -//! if x { -//! if y { -//! println!("Hello world"); -//! } -//! } -//! ``` -//! -//! This lint is **warn** by default - -use if_chain::if_chain; -use rustc_ast::ast; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -use crate::utils::sugg::Sugg; -use crate::utils::{snippet_block, snippet_block_with_applicability, span_lint_and_sugg, span_lint_and_then}; -use rustc_errors::Applicability; - -declare_clippy_lint! { - /// **What it does:** Checks for nested `if` statements which can be collapsed - /// by `&&`-combining their conditions and for `else { if ... }` expressions - /// that - /// can be collapsed to `else if ...`. - /// - /// **Why is this bad?** Each `if`-statement adds one level of nesting, which - /// makes code look more complex than it really is. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// if x { - /// if y { - /// … - /// } - /// } - /// - /// // or - /// - /// if x { - /// … - /// } else { - /// if y { - /// … - /// } - /// } - /// ``` - /// - /// Should be written: - /// - /// ```rust.ignore - /// if x && y { - /// … - /// } - /// - /// // or - /// - /// if x { - /// … - /// } else if y { - /// … - /// } - /// ``` - pub COLLAPSIBLE_IF, - style, - "`if`s that can be collapsed (e.g., `if x { if y { ... } }` and `else { if x { ... } }`)" -} - -declare_lint_pass!(CollapsibleIf => [COLLAPSIBLE_IF]); - -impl EarlyLintPass for CollapsibleIf { - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { - if !expr.span.from_expansion() { - check_if(cx, expr) - } - } -} - -fn check_if(cx: &EarlyContext<'_>, expr: &ast::Expr) { - if let ast::ExprKind::If(check, then, else_) = &expr.kind { - if let Some(else_) = else_ { - check_collapsible_maybe_if_let(cx, else_); - } else if let ast::ExprKind::Let(..) = check.kind { - // Prevent triggering on `if let a = b { if c { .. } }`. - } else { - check_collapsible_no_if_let(cx, expr, check, then); - } - } -} - -fn block_starts_with_comment(cx: &EarlyContext<'_>, expr: &ast::Block) -> bool { - // We trim all opening braces and whitespaces and then check if the next string is a comment. - let trimmed_block_text = snippet_block(cx, expr.span, "..", None) - .trim_start_matches(|c: char| c.is_whitespace() || c == '{') - .to_owned(); - trimmed_block_text.starts_with("//") || trimmed_block_text.starts_with("/*") -} - -fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) { - if_chain! { - if let ast::ExprKind::Block(ref block, _) = else_.kind; - if !block_starts_with_comment(cx, block); - if let Some(else_) = expr_block(block); - if !else_.span.from_expansion(); - if let ast::ExprKind::If(..) = else_.kind; - then { - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - COLLAPSIBLE_IF, - block.span, - "this `else { if .. }` block can be collapsed", - "collapse nested if block", - snippet_block_with_applicability(cx, else_.span, "..", Some(block.span), &mut applicability).into_owned(), - applicability, - ); - } - } -} - -fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: &ast::Expr, then: &ast::Block) { - if_chain! { - if !block_starts_with_comment(cx, then); - if let Some(inner) = expr_block(then); - if let ast::ExprKind::If(ref check_inner, ref content, None) = inner.kind; - then { - if let ast::ExprKind::Let(..) = check_inner.kind { - // Prevent triggering on `if c { if let a = b { .. } }`. - return; - } - - if expr.span.ctxt() != inner.span.ctxt() { - return; - } - span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this `if` statement can be collapsed", |diag| { - let lhs = Sugg::ast(cx, check, ".."); - let rhs = Sugg::ast(cx, check_inner, ".."); - diag.span_suggestion( - expr.span, - "collapse nested if block", - format!( - "if {} {}", - lhs.and(&rhs), - snippet_block(cx, content.span, "..", Some(expr.span)), - ), - Applicability::MachineApplicable, // snippet - ); - }); - } - } -} - -/// If the block contains only one expression, return it. -fn expr_block(block: &ast::Block) -> Option<&ast::Expr> { - let mut it = block.stmts.iter(); - - if let (Some(stmt), None) = (it.next(), it.next()) { - match stmt.kind { - ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => Some(expr), - _ => None, - } - } else { - None - } -} diff --git a/clippy_lints/src/collapsible_match.rs b/clippy_lints/src/collapsible_match.rs deleted file mode 100644 index a34ba2d00a8c..000000000000 --- a/clippy_lints/src/collapsible_match.rs +++ /dev/null @@ -1,172 +0,0 @@ -use crate::utils::visitors::LocalUsedVisitor; -use crate::utils::{span_lint_and_then, SpanlessEq}; -use if_chain::if_chain; -use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; -use rustc_hir::{Arm, Expr, ExprKind, Guard, HirId, Pat, PatKind, QPath, StmtKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{DefIdTree, TyCtxt}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::{MultiSpan, Span}; - -declare_clippy_lint! { - /// **What it does:** Finds nested `match` or `if let` expressions where the patterns may be "collapsed" together - /// without adding any branches. - /// - /// Note that this lint is not intended to find _all_ cases where nested match patterns can be merged, but only - /// cases where merging would most likely make the code more readable. - /// - /// **Why is this bad?** It is unnecessarily verbose and complex. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// fn func(opt: Option>) { - /// let n = match opt { - /// Some(n) => match n { - /// Ok(n) => n, - /// _ => return, - /// } - /// None => return, - /// }; - /// } - /// ``` - /// Use instead: - /// ```rust - /// fn func(opt: Option>) { - /// let n = match opt { - /// Some(Ok(n)) => n, - /// _ => return, - /// }; - /// } - /// ``` - pub COLLAPSIBLE_MATCH, - style, - "Nested `match` or `if let` expressions where the patterns may be \"collapsed\" together." -} - -declare_lint_pass!(CollapsibleMatch => [COLLAPSIBLE_MATCH]); - -impl<'tcx> LateLintPass<'tcx> for CollapsibleMatch { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) { - if let ExprKind::Match(_expr, arms, _source) = expr.kind { - if let Some(wild_arm) = arms.iter().rfind(|arm| arm_is_wild_like(arm, cx.tcx)) { - for arm in arms { - check_arm(arm, wild_arm, cx); - } - } - } - } -} - -fn check_arm(arm: &Arm<'_>, wild_outer_arm: &Arm<'_>, cx: &LateContext<'_>) { - if_chain! { - let expr = strip_singleton_blocks(arm.body); - if let ExprKind::Match(expr_in, arms_inner, _) = expr.kind; - // the outer arm pattern and the inner match - if expr_in.span.ctxt() == arm.pat.span.ctxt(); - // there must be no more than two arms in the inner match for this lint - if arms_inner.len() == 2; - // no if guards on the inner match - if arms_inner.iter().all(|arm| arm.guard.is_none()); - // match expression must be a local binding - // match { .. } - if let ExprKind::Path(QPath::Resolved(None, path)) = expr_in.kind; - if let Res::Local(binding_id) = path.res; - // one of the branches must be "wild-like" - if let Some(wild_inner_arm_idx) = arms_inner.iter().rposition(|arm_inner| arm_is_wild_like(arm_inner, cx.tcx)); - let (wild_inner_arm, non_wild_inner_arm) = - (&arms_inner[wild_inner_arm_idx], &arms_inner[1 - wild_inner_arm_idx]); - if !pat_contains_or(non_wild_inner_arm.pat); - // the binding must come from the pattern of the containing match arm - // .... => match { .. } - if let Some(binding_span) = find_pat_binding(arm.pat, binding_id); - // the "wild-like" branches must be equal - if SpanlessEq::new(cx).eq_expr(wild_inner_arm.body, wild_outer_arm.body); - // the binding must not be used in the if guard - if !matches!(arm.guard, Some(Guard::If(guard)) if LocalUsedVisitor::new(binding_id).check_expr(guard)); - // ...or anywhere in the inner match - if !arms_inner.iter().any(|arm| LocalUsedVisitor::new(binding_id).check_arm(arm)); - then { - span_lint_and_then( - cx, - COLLAPSIBLE_MATCH, - expr.span, - "Unnecessary nested match", - |diag| { - let mut help_span = MultiSpan::from_spans(vec![binding_span, non_wild_inner_arm.pat.span]); - help_span.push_span_label(binding_span, "Replace this binding".into()); - help_span.push_span_label(non_wild_inner_arm.pat.span, "with this pattern".into()); - diag.span_help(help_span, "The outer pattern can be modified to include the inner pattern."); - }, - ); - } - } -} - -fn strip_singleton_blocks<'hir>(mut expr: &'hir Expr<'hir>) -> &'hir Expr<'hir> { - while let ExprKind::Block(block, _) = expr.kind { - match (block.stmts, block.expr) { - ([stmt], None) => match stmt.kind { - StmtKind::Expr(e) | StmtKind::Semi(e) => expr = e, - _ => break, - }, - ([], Some(e)) => expr = e, - _ => break, - } - } - expr -} - -/// A "wild-like" pattern is wild ("_") or `None`. -/// For this lint to apply, both the outer and inner match expressions -/// must have "wild-like" branches that can be combined. -fn arm_is_wild_like(arm: &Arm<'_>, tcx: TyCtxt<'_>) -> bool { - if arm.guard.is_some() { - return false; - } - match arm.pat.kind { - PatKind::Binding(..) | PatKind::Wild => true, - PatKind::Path(QPath::Resolved(None, path)) if is_none_ctor(path.res, tcx) => true, - _ => false, - } -} - -fn find_pat_binding(pat: &Pat<'_>, hir_id: HirId) -> Option { - let mut span = None; - pat.walk_short(|p| match &p.kind { - // ignore OR patterns - PatKind::Or(_) => false, - PatKind::Binding(_bm, _, _ident, _) => { - let found = p.hir_id == hir_id; - if found { - span = Some(p.span); - } - !found - }, - _ => true, - }); - span -} - -fn pat_contains_or(pat: &Pat<'_>) -> bool { - let mut result = false; - pat.walk(|p| { - let is_or = matches!(p.kind, PatKind::Or(_)); - result |= is_or; - !is_or - }); - result -} - -fn is_none_ctor(res: Res, tcx: TyCtxt<'_>) -> bool { - if let Some(none_id) = tcx.lang_items().option_none_variant() { - if let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const), id) = res { - if let Some(variant_id) = tcx.parent(id) { - return variant_id == none_id; - } - } - } - false -} diff --git a/clippy_lints/src/comparison_chain.rs b/clippy_lints/src/comparison_chain.rs deleted file mode 100644 index ae1143b2c50c..000000000000 --- a/clippy_lints/src/comparison_chain.rs +++ /dev/null @@ -1,127 +0,0 @@ -use crate::utils::{ - get_trait_def_id, if_sequence, implements_trait, parent_node_is_if_expr, paths, span_lint_and_help, SpanlessEq, -}; -use rustc_hir::{BinOpKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks comparison chains written with `if` that can be - /// rewritten with `match` and `cmp`. - /// - /// **Why is this bad?** `if` is not guaranteed to be exhaustive and conditionals can get - /// repetitive - /// - /// **Known problems:** The match statement may be slower due to the compiler - /// not inlining the call to cmp. See issue #5354 - /// - /// **Example:** - /// ```rust,ignore - /// # fn a() {} - /// # fn b() {} - /// # fn c() {} - /// fn f(x: u8, y: u8) { - /// if x > y { - /// a() - /// } else if x < y { - /// b() - /// } else { - /// c() - /// } - /// } - /// ``` - /// - /// Could be written: - /// - /// ```rust,ignore - /// use std::cmp::Ordering; - /// # fn a() {} - /// # fn b() {} - /// # fn c() {} - /// fn f(x: u8, y: u8) { - /// match x.cmp(&y) { - /// Ordering::Greater => a(), - /// Ordering::Less => b(), - /// Ordering::Equal => c() - /// } - /// } - /// ``` - pub COMPARISON_CHAIN, - style, - "`if`s that can be rewritten with `match` and `cmp`" -} - -declare_lint_pass!(ComparisonChain => [COMPARISON_CHAIN]); - -impl<'tcx> LateLintPass<'tcx> for ComparisonChain { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if expr.span.from_expansion() { - return; - } - - // We only care about the top-most `if` in the chain - if parent_node_is_if_expr(expr, cx) { - return; - } - - // Check that there exists at least one explicit else condition - let (conds, _) = if_sequence(expr); - if conds.len() < 2 { - return; - } - - for cond in conds.windows(2) { - if let ( - &ExprKind::Binary(ref kind1, ref lhs1, ref rhs1), - &ExprKind::Binary(ref kind2, ref lhs2, ref rhs2), - ) = (&cond[0].kind, &cond[1].kind) - { - if !kind_is_cmp(kind1.node) || !kind_is_cmp(kind2.node) { - return; - } - - // Check that both sets of operands are equal - let mut spanless_eq = SpanlessEq::new(cx); - let same_fixed_operands = spanless_eq.eq_expr(lhs1, lhs2) && spanless_eq.eq_expr(rhs1, rhs2); - let same_transposed_operands = spanless_eq.eq_expr(lhs1, rhs2) && spanless_eq.eq_expr(rhs1, lhs2); - - if !same_fixed_operands && !same_transposed_operands { - return; - } - - // Check that if the operation is the same, either it's not `==` or the operands are transposed - if kind1.node == kind2.node { - if kind1.node == BinOpKind::Eq { - return; - } - if !same_transposed_operands { - return; - } - } - - // Check that the type being compared implements `core::cmp::Ord` - let ty = cx.typeck_results().expr_ty(lhs1); - let is_ord = get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[])); - - if !is_ord { - return; - } - } else { - // We only care about comparison chains - return; - } - } - span_lint_and_help( - cx, - COMPARISON_CHAIN, - expr.span, - "`if` chain can be rewritten with `match`", - None, - "Consider rewriting the `if` chain to use `cmp` and `match`.", - ) - } -} - -fn kind_is_cmp(kind: BinOpKind) -> bool { - matches!(kind, BinOpKind::Lt | BinOpKind::Gt | BinOpKind::Eq) -} diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs deleted file mode 100644 index 0035ded9356c..000000000000 --- a/clippy_lints/src/consts.rs +++ /dev/null @@ -1,576 +0,0 @@ -#![allow(clippy::float_cmp)] - -use crate::utils::{clip, higher, sext, unsext}; -use if_chain::if_chain; -use rustc_ast::ast::{FloatTy, LitFloatType, LitKind}; -use rustc_data_structures::sync::Lrc; -use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, QPath, UnOp}; -use rustc_lint::LateContext; -use rustc_middle::mir::interpret::Scalar; -use rustc_middle::ty::subst::{Subst, SubstsRef}; -use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt}; -use rustc_middle::{bug, span_bug}; -use rustc_span::symbol::Symbol; -use std::cmp::Ordering::{self, Equal}; -use std::convert::TryInto; -use std::hash::{Hash, Hasher}; - -/// A `LitKind`-like enum to fold constant `Expr`s into. -#[derive(Debug, Clone)] -pub enum Constant { - /// A `String` (e.g., "abc"). - Str(String), - /// A binary string (e.g., `b"abc"`). - Binary(Lrc<[u8]>), - /// A single `char` (e.g., `'a'`). - Char(char), - /// An integer's bit representation. - Int(u128), - /// An `f32`. - F32(f32), - /// An `f64`. - F64(f64), - /// `true` or `false`. - Bool(bool), - /// An array of constants. - Vec(Vec), - /// Also an array, but with only one constant, repeated N times. - Repeat(Box, u64), - /// A tuple of constants. - Tuple(Vec), - /// A raw pointer. - RawPtr(u128), - /// A reference - Ref(Box), - /// A literal with syntax error. - Err(Symbol), -} - -impl PartialEq for Constant { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (&Self::Str(ref ls), &Self::Str(ref rs)) => ls == rs, - (&Self::Binary(ref l), &Self::Binary(ref r)) => l == r, - (&Self::Char(l), &Self::Char(r)) => l == r, - (&Self::Int(l), &Self::Int(r)) => l == r, - (&Self::F64(l), &Self::F64(r)) => { - // We want `Fw32 == FwAny` and `FwAny == Fw64`, and by transitivity we must have - // `Fw32 == Fw64`, so don’t compare them. - // `to_bits` is required to catch non-matching 0.0, -0.0, and NaNs. - l.to_bits() == r.to_bits() - }, - (&Self::F32(l), &Self::F32(r)) => { - // We want `Fw32 == FwAny` and `FwAny == Fw64`, and by transitivity we must have - // `Fw32 == Fw64`, so don’t compare them. - // `to_bits` is required to catch non-matching 0.0, -0.0, and NaNs. - f64::from(l).to_bits() == f64::from(r).to_bits() - }, - (&Self::Bool(l), &Self::Bool(r)) => l == r, - (&Self::Vec(ref l), &Self::Vec(ref r)) | (&Self::Tuple(ref l), &Self::Tuple(ref r)) => l == r, - (&Self::Repeat(ref lv, ref ls), &Self::Repeat(ref rv, ref rs)) => ls == rs && lv == rv, - (&Self::Ref(ref lb), &Self::Ref(ref rb)) => *lb == *rb, - // TODO: are there inter-type equalities? - _ => false, - } - } -} - -impl Hash for Constant { - fn hash(&self, state: &mut H) - where - H: Hasher, - { - std::mem::discriminant(self).hash(state); - match *self { - Self::Str(ref s) => { - s.hash(state); - }, - Self::Binary(ref b) => { - b.hash(state); - }, - Self::Char(c) => { - c.hash(state); - }, - Self::Int(i) => { - i.hash(state); - }, - Self::F32(f) => { - f64::from(f).to_bits().hash(state); - }, - Self::F64(f) => { - f.to_bits().hash(state); - }, - Self::Bool(b) => { - b.hash(state); - }, - Self::Vec(ref v) | Self::Tuple(ref v) => { - v.hash(state); - }, - Self::Repeat(ref c, l) => { - c.hash(state); - l.hash(state); - }, - Self::RawPtr(u) => { - u.hash(state); - }, - Self::Ref(ref r) => { - r.hash(state); - }, - Self::Err(ref s) => { - s.hash(state); - }, - } - } -} - -impl Constant { - pub fn partial_cmp(tcx: TyCtxt<'_>, cmp_type: Ty<'_>, left: &Self, right: &Self) -> Option { - match (left, right) { - (&Self::Str(ref ls), &Self::Str(ref rs)) => Some(ls.cmp(rs)), - (&Self::Char(ref l), &Self::Char(ref r)) => Some(l.cmp(r)), - (&Self::Int(l), &Self::Int(r)) => { - if let ty::Int(int_ty) = *cmp_type.kind() { - Some(sext(tcx, l, int_ty).cmp(&sext(tcx, r, int_ty))) - } else { - Some(l.cmp(&r)) - } - }, - (&Self::F64(l), &Self::F64(r)) => l.partial_cmp(&r), - (&Self::F32(l), &Self::F32(r)) => l.partial_cmp(&r), - (&Self::Bool(ref l), &Self::Bool(ref r)) => Some(l.cmp(r)), - (&Self::Tuple(ref l), &Self::Tuple(ref r)) | (&Self::Vec(ref l), &Self::Vec(ref r)) => l - .iter() - .zip(r.iter()) - .map(|(li, ri)| Self::partial_cmp(tcx, cmp_type, li, ri)) - .find(|r| r.map_or(true, |o| o != Ordering::Equal)) - .unwrap_or_else(|| Some(l.len().cmp(&r.len()))), - (&Self::Repeat(ref lv, ref ls), &Self::Repeat(ref rv, ref rs)) => { - match Self::partial_cmp(tcx, cmp_type, lv, rv) { - Some(Equal) => Some(ls.cmp(rs)), - x => x, - } - }, - (&Self::Ref(ref lb), &Self::Ref(ref rb)) => Self::partial_cmp(tcx, cmp_type, lb, rb), - // TODO: are there any useful inter-type orderings? - _ => None, - } - } -} - -/// Parses a `LitKind` to a `Constant`. -pub fn lit_to_constant(lit: &LitKind, ty: Option>) -> Constant { - match *lit { - LitKind::Str(ref is, _) => Constant::Str(is.to_string()), - LitKind::Byte(b) => Constant::Int(u128::from(b)), - LitKind::ByteStr(ref s) => Constant::Binary(Lrc::clone(s)), - LitKind::Char(c) => Constant::Char(c), - LitKind::Int(n, _) => Constant::Int(n), - LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty { - FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()), - FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()), - }, - LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind() { - ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()), - ty::Float(FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()), - _ => bug!(), - }, - LitKind::Bool(b) => Constant::Bool(b), - LitKind::Err(s) => Constant::Err(s), - } -} - -pub fn constant<'tcx>( - lcx: &LateContext<'tcx>, - typeck_results: &ty::TypeckResults<'tcx>, - e: &Expr<'_>, -) -> Option<(Constant, bool)> { - let mut cx = ConstEvalLateContext { - lcx, - typeck_results, - param_env: lcx.param_env, - needed_resolution: false, - substs: lcx.tcx.intern_substs(&[]), - }; - cx.expr(e).map(|cst| (cst, cx.needed_resolution)) -} - -pub fn constant_simple<'tcx>( - lcx: &LateContext<'tcx>, - typeck_results: &ty::TypeckResults<'tcx>, - e: &Expr<'_>, -) -> Option { - constant(lcx, typeck_results, e).and_then(|(cst, res)| if res { None } else { Some(cst) }) -} - -/// Creates a `ConstEvalLateContext` from the given `LateContext` and `TypeckResults`. -pub fn constant_context<'a, 'tcx>( - lcx: &'a LateContext<'tcx>, - typeck_results: &'a ty::TypeckResults<'tcx>, -) -> ConstEvalLateContext<'a, 'tcx> { - ConstEvalLateContext { - lcx, - typeck_results, - param_env: lcx.param_env, - needed_resolution: false, - substs: lcx.tcx.intern_substs(&[]), - } -} - -pub struct ConstEvalLateContext<'a, 'tcx> { - lcx: &'a LateContext<'tcx>, - typeck_results: &'a ty::TypeckResults<'tcx>, - param_env: ty::ParamEnv<'tcx>, - needed_resolution: bool, - substs: SubstsRef<'tcx>, -} - -impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { - /// Simple constant folding: Insert an expression, get a constant or none. - pub fn expr(&mut self, e: &Expr<'_>) -> Option { - if let Some((ref cond, ref then, otherwise)) = higher::if_block(&e) { - return self.ifthenelse(cond, then, otherwise); - } - match e.kind { - ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id, self.typeck_results.expr_ty(e)), - ExprKind::Block(ref block, _) => self.block(block), - ExprKind::Lit(ref lit) => Some(lit_to_constant(&lit.node, self.typeck_results.expr_ty_opt(e))), - ExprKind::Array(ref vec) => self.multi(vec).map(Constant::Vec), - ExprKind::Tup(ref tup) => self.multi(tup).map(Constant::Tuple), - ExprKind::Repeat(ref value, _) => { - let n = match self.typeck_results.expr_ty(e).kind() { - ty::Array(_, n) => n.try_eval_usize(self.lcx.tcx, self.lcx.param_env)?, - _ => span_bug!(e.span, "typeck error"), - }; - self.expr(value).map(|v| Constant::Repeat(Box::new(v), n)) - }, - ExprKind::Unary(op, ref operand) => self.expr(operand).and_then(|o| match op { - UnOp::UnNot => self.constant_not(&o, self.typeck_results.expr_ty(e)), - UnOp::UnNeg => self.constant_negate(&o, self.typeck_results.expr_ty(e)), - UnOp::UnDeref => Some(if let Constant::Ref(r) = o { *r } else { o }), - }), - ExprKind::Binary(op, ref left, ref right) => self.binop(op, left, right), - ExprKind::Call(ref callee, ref args) => { - // We only handle a few const functions for now. - if_chain! { - if args.is_empty(); - if let ExprKind::Path(qpath) = &callee.kind; - let res = self.typeck_results.qpath_res(qpath, callee.hir_id); - if let Some(def_id) = res.opt_def_id(); - let def_path: Vec<_> = self.lcx.get_def_path(def_id).into_iter().map(Symbol::as_str).collect(); - let def_path: Vec<&str> = def_path.iter().take(4).map(|s| &**s).collect(); - if let ["core", "num", int_impl, "max_value"] = *def_path; - then { - let value = match int_impl { - "" => i8::MAX as u128, - "" => i16::MAX as u128, - "" => i32::MAX as u128, - "" => i64::MAX as u128, - "" => i128::MAX as u128, - _ => return None, - }; - Some(Constant::Int(value)) - } - else { - None - } - } - }, - ExprKind::Index(ref arr, ref index) => self.index(arr, index), - ExprKind::AddrOf(_, _, ref inner) => self.expr(inner).map(|r| Constant::Ref(Box::new(r))), - // TODO: add other expressions. - _ => None, - } - } - - #[allow(clippy::cast_possible_wrap)] - fn constant_not(&self, o: &Constant, ty: Ty<'_>) -> Option { - use self::Constant::{Bool, Int}; - match *o { - Bool(b) => Some(Bool(!b)), - Int(value) => { - let value = !value; - match *ty.kind() { - ty::Int(ity) => Some(Int(unsext(self.lcx.tcx, value as i128, ity))), - ty::Uint(ity) => Some(Int(clip(self.lcx.tcx, value, ity))), - _ => None, - } - }, - _ => None, - } - } - - fn constant_negate(&self, o: &Constant, ty: Ty<'_>) -> Option { - use self::Constant::{Int, F32, F64}; - match *o { - Int(value) => { - let ity = match *ty.kind() { - ty::Int(ity) => ity, - _ => return None, - }; - // sign extend - let value = sext(self.lcx.tcx, value, ity); - let value = value.checked_neg()?; - // clear unused bits - Some(Int(unsext(self.lcx.tcx, value, ity))) - }, - F32(f) => Some(F32(-f)), - F64(f) => Some(F64(-f)), - _ => None, - } - } - - /// Create `Some(Vec![..])` of all constants, unless there is any - /// non-constant part. - fn multi(&mut self, vec: &[Expr<'_>]) -> Option> { - vec.iter().map(|elem| self.expr(elem)).collect::>() - } - - /// Lookup a possibly constant expression from a `ExprKind::Path`. - fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'tcx>) -> Option { - let res = self.typeck_results.qpath_res(qpath, id); - match res { - Res::Def(DefKind::Const | DefKind::AssocConst, def_id) => { - let substs = self.typeck_results.node_substs(id); - let substs = if self.substs.is_empty() { - substs - } else { - substs.subst(self.lcx.tcx, self.substs) - }; - - let result = self - .lcx - .tcx - .const_eval_resolve( - self.param_env, - ty::WithOptConstParam::unknown(def_id), - substs, - None, - None, - ) - .ok() - .map(|val| rustc_middle::ty::Const::from_value(self.lcx.tcx, val, ty))?; - let result = miri_to_const(&result); - if result.is_some() { - self.needed_resolution = true; - } - result - }, - // FIXME: cover all usable cases. - _ => None, - } - } - - fn index(&mut self, lhs: &'_ Expr<'_>, index: &'_ Expr<'_>) -> Option { - let lhs = self.expr(lhs); - let index = self.expr(index); - - match (lhs, index) { - (Some(Constant::Vec(vec)), Some(Constant::Int(index))) => match vec.get(index as usize) { - Some(Constant::F32(x)) => Some(Constant::F32(*x)), - Some(Constant::F64(x)) => Some(Constant::F64(*x)), - _ => None, - }, - (Some(Constant::Vec(vec)), _) => { - if !vec.is_empty() && vec.iter().all(|x| *x == vec[0]) { - match vec.get(0) { - Some(Constant::F32(x)) => Some(Constant::F32(*x)), - Some(Constant::F64(x)) => Some(Constant::F64(*x)), - _ => None, - } - } else { - None - } - }, - _ => None, - } - } - - /// A block can only yield a constant if it only has one constant expression. - fn block(&mut self, block: &Block<'_>) -> Option { - if block.stmts.is_empty() { - block.expr.as_ref().and_then(|b| self.expr(b)) - } else { - None - } - } - - fn ifthenelse(&mut self, cond: &Expr<'_>, then: &Expr<'_>, otherwise: Option<&Expr<'_>>) -> Option { - if let Some(Constant::Bool(b)) = self.expr(cond) { - if b { - self.expr(&*then) - } else { - otherwise.as_ref().and_then(|expr| self.expr(expr)) - } - } else { - None - } - } - - fn binop(&mut self, op: BinOp, left: &Expr<'_>, right: &Expr<'_>) -> Option { - let l = self.expr(left)?; - let r = self.expr(right); - match (l, r) { - (Constant::Int(l), Some(Constant::Int(r))) => match *self.typeck_results.expr_ty_opt(left)?.kind() { - ty::Int(ity) => { - let l = sext(self.lcx.tcx, l, ity); - let r = sext(self.lcx.tcx, r, ity); - let zext = |n: i128| Constant::Int(unsext(self.lcx.tcx, n, ity)); - match op.node { - BinOpKind::Add => l.checked_add(r).map(zext), - BinOpKind::Sub => l.checked_sub(r).map(zext), - BinOpKind::Mul => l.checked_mul(r).map(zext), - BinOpKind::Div if r != 0 => l.checked_div(r).map(zext), - BinOpKind::Rem if r != 0 => l.checked_rem(r).map(zext), - BinOpKind::Shr => l.checked_shr(r.try_into().expect("invalid shift")).map(zext), - BinOpKind::Shl => l.checked_shl(r.try_into().expect("invalid shift")).map(zext), - BinOpKind::BitXor => Some(zext(l ^ r)), - BinOpKind::BitOr => Some(zext(l | r)), - BinOpKind::BitAnd => Some(zext(l & r)), - BinOpKind::Eq => Some(Constant::Bool(l == r)), - BinOpKind::Ne => Some(Constant::Bool(l != r)), - BinOpKind::Lt => Some(Constant::Bool(l < r)), - BinOpKind::Le => Some(Constant::Bool(l <= r)), - BinOpKind::Ge => Some(Constant::Bool(l >= r)), - BinOpKind::Gt => Some(Constant::Bool(l > r)), - _ => None, - } - }, - ty::Uint(_) => match op.node { - BinOpKind::Add => l.checked_add(r).map(Constant::Int), - BinOpKind::Sub => l.checked_sub(r).map(Constant::Int), - BinOpKind::Mul => l.checked_mul(r).map(Constant::Int), - BinOpKind::Div => l.checked_div(r).map(Constant::Int), - BinOpKind::Rem => l.checked_rem(r).map(Constant::Int), - BinOpKind::Shr => l.checked_shr(r.try_into().expect("shift too large")).map(Constant::Int), - BinOpKind::Shl => l.checked_shl(r.try_into().expect("shift too large")).map(Constant::Int), - BinOpKind::BitXor => Some(Constant::Int(l ^ r)), - BinOpKind::BitOr => Some(Constant::Int(l | r)), - BinOpKind::BitAnd => Some(Constant::Int(l & r)), - BinOpKind::Eq => Some(Constant::Bool(l == r)), - BinOpKind::Ne => Some(Constant::Bool(l != r)), - BinOpKind::Lt => Some(Constant::Bool(l < r)), - BinOpKind::Le => Some(Constant::Bool(l <= r)), - BinOpKind::Ge => Some(Constant::Bool(l >= r)), - BinOpKind::Gt => Some(Constant::Bool(l > r)), - _ => None, - }, - _ => None, - }, - (Constant::F32(l), Some(Constant::F32(r))) => match op.node { - BinOpKind::Add => Some(Constant::F32(l + r)), - BinOpKind::Sub => Some(Constant::F32(l - r)), - BinOpKind::Mul => Some(Constant::F32(l * r)), - BinOpKind::Div => Some(Constant::F32(l / r)), - BinOpKind::Rem => Some(Constant::F32(l % r)), - BinOpKind::Eq => Some(Constant::Bool(l == r)), - BinOpKind::Ne => Some(Constant::Bool(l != r)), - BinOpKind::Lt => Some(Constant::Bool(l < r)), - BinOpKind::Le => Some(Constant::Bool(l <= r)), - BinOpKind::Ge => Some(Constant::Bool(l >= r)), - BinOpKind::Gt => Some(Constant::Bool(l > r)), - _ => None, - }, - (Constant::F64(l), Some(Constant::F64(r))) => match op.node { - BinOpKind::Add => Some(Constant::F64(l + r)), - BinOpKind::Sub => Some(Constant::F64(l - r)), - BinOpKind::Mul => Some(Constant::F64(l * r)), - BinOpKind::Div => Some(Constant::F64(l / r)), - BinOpKind::Rem => Some(Constant::F64(l % r)), - BinOpKind::Eq => Some(Constant::Bool(l == r)), - BinOpKind::Ne => Some(Constant::Bool(l != r)), - BinOpKind::Lt => Some(Constant::Bool(l < r)), - BinOpKind::Le => Some(Constant::Bool(l <= r)), - BinOpKind::Ge => Some(Constant::Bool(l >= r)), - BinOpKind::Gt => Some(Constant::Bool(l > r)), - _ => None, - }, - (l, r) => match (op.node, l, r) { - (BinOpKind::And, Constant::Bool(false), _) => Some(Constant::Bool(false)), - (BinOpKind::Or, Constant::Bool(true), _) => Some(Constant::Bool(true)), - (BinOpKind::And, Constant::Bool(true), Some(r)) | (BinOpKind::Or, Constant::Bool(false), Some(r)) => { - Some(r) - }, - (BinOpKind::BitXor, Constant::Bool(l), Some(Constant::Bool(r))) => Some(Constant::Bool(l ^ r)), - (BinOpKind::BitAnd, Constant::Bool(l), Some(Constant::Bool(r))) => Some(Constant::Bool(l & r)), - (BinOpKind::BitOr, Constant::Bool(l), Some(Constant::Bool(r))) => Some(Constant::Bool(l | r)), - _ => None, - }, - } - } -} - -pub fn miri_to_const(result: &ty::Const<'_>) -> Option { - use rustc_middle::mir::interpret::ConstValue; - match result.val { - ty::ConstKind::Value(ConstValue::Scalar(Scalar::Int(int))) => { - match result.ty.kind() { - ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)), - ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.assert_bits(int.size()))), - ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits( - int.try_into().expect("invalid f32 bit representation"), - ))), - ty::Float(FloatTy::F64) => Some(Constant::F64(f64::from_bits( - int.try_into().expect("invalid f64 bit representation"), - ))), - ty::RawPtr(type_and_mut) => { - if let ty::Uint(_) = type_and_mut.ty.kind() { - return Some(Constant::RawPtr(int.assert_bits(int.size()))); - } - None - }, - // FIXME: implement other conversions. - _ => None, - } - }, - ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => match result.ty.kind() { - ty::Ref(_, tam, _) => match tam.kind() { - ty::Str => String::from_utf8( - data.inspect_with_uninit_and_ptr_outside_interpreter(start..end) - .to_owned(), - ) - .ok() - .map(Constant::Str), - _ => None, - }, - _ => None, - }, - ty::ConstKind::Value(ConstValue::ByRef { alloc, offset: _ }) => match result.ty.kind() { - ty::Array(sub_type, len) => match sub_type.kind() { - ty::Float(FloatTy::F32) => match miri_to_const(len) { - Some(Constant::Int(len)) => alloc - .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * len as usize)) - .to_owned() - .chunks(4) - .map(|chunk| { - Some(Constant::F32(f32::from_le_bytes( - chunk.try_into().expect("this shouldn't happen"), - ))) - }) - .collect::>>() - .map(Constant::Vec), - _ => None, - }, - ty::Float(FloatTy::F64) => match miri_to_const(len) { - Some(Constant::Int(len)) => alloc - .inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * len as usize)) - .to_owned() - .chunks(8) - .map(|chunk| { - Some(Constant::F64(f64::from_le_bytes( - chunk.try_into().expect("this shouldn't happen"), - ))) - }) - .collect::>>() - .map(Constant::Vec), - _ => None, - }, - // FIXME: implement other array type conversions. - _ => None, - }, - _ => None, - }, - // FIXME: implement other conversions. - _ => None, - } -} diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs deleted file mode 100644 index 46ce92ea6d78..000000000000 --- a/clippy_lints/src/copies.rs +++ /dev/null @@ -1,209 +0,0 @@ -use crate::utils::{eq_expr_value, in_macro, search_same, SpanlessEq, SpanlessHash}; -use crate::utils::{get_parent_expr, higher, if_sequence, span_lint_and_note}; -use rustc_hir::{Block, Expr}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for consecutive `if`s with the same condition. - /// - /// **Why is this bad?** This is probably a copy & paste error. - /// - /// **Known problems:** Hopefully none. - /// - /// **Example:** - /// ```ignore - /// if a == b { - /// … - /// } else if a == b { - /// … - /// } - /// ``` - /// - /// Note that this lint ignores all conditions with a function call as it could - /// have side effects: - /// - /// ```ignore - /// if foo() { - /// … - /// } else if foo() { // not linted - /// … - /// } - /// ``` - pub IFS_SAME_COND, - correctness, - "consecutive `if`s with the same condition" -} - -declare_clippy_lint! { - /// **What it does:** Checks for consecutive `if`s with the same function call. - /// - /// **Why is this bad?** This is probably a copy & paste error. - /// Despite the fact that function can have side effects and `if` works as - /// intended, such an approach is implicit and can be considered a "code smell". - /// - /// **Known problems:** Hopefully none. - /// - /// **Example:** - /// ```ignore - /// if foo() == bar { - /// … - /// } else if foo() == bar { - /// … - /// } - /// ``` - /// - /// This probably should be: - /// ```ignore - /// if foo() == bar { - /// … - /// } else if foo() == baz { - /// … - /// } - /// ``` - /// - /// or if the original code was not a typo and called function mutates a state, - /// consider move the mutation out of the `if` condition to avoid similarity to - /// a copy & paste error: - /// - /// ```ignore - /// let first = foo(); - /// if first == bar { - /// … - /// } else { - /// let second = foo(); - /// if second == bar { - /// … - /// } - /// } - /// ``` - pub SAME_FUNCTIONS_IN_IF_CONDITION, - pedantic, - "consecutive `if`s with the same function call" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `if/else` with the same body as the *then* part - /// and the *else* part. - /// - /// **Why is this bad?** This is probably a copy & paste error. - /// - /// **Known problems:** Hopefully none. - /// - /// **Example:** - /// ```ignore - /// let foo = if … { - /// 42 - /// } else { - /// 42 - /// }; - /// ``` - pub IF_SAME_THEN_ELSE, - correctness, - "`if` with the same `then` and `else` blocks" -} - -declare_lint_pass!(CopyAndPaste => [IFS_SAME_COND, SAME_FUNCTIONS_IN_IF_CONDITION, IF_SAME_THEN_ELSE]); - -impl<'tcx> LateLintPass<'tcx> for CopyAndPaste { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if !expr.span.from_expansion() { - // skip ifs directly in else, it will be checked in the parent if - if let Some(expr) = get_parent_expr(cx, expr) { - if let Some((_, _, Some(ref else_expr))) = higher::if_block(&expr) { - if else_expr.hir_id == expr.hir_id { - return; - } - } - } - - let (conds, blocks) = if_sequence(expr); - lint_same_then_else(cx, &blocks); - lint_same_cond(cx, &conds); - lint_same_fns_in_if_cond(cx, &conds); - } - } -} - -/// Implementation of `IF_SAME_THEN_ELSE`. -fn lint_same_then_else(cx: &LateContext<'_>, blocks: &[&Block<'_>]) { - let eq: &dyn Fn(&&Block<'_>, &&Block<'_>) -> bool = - &|&lhs, &rhs| -> bool { SpanlessEq::new(cx).eq_block(lhs, rhs) }; - - if let Some((i, j)) = search_same_sequenced(blocks, eq) { - span_lint_and_note( - cx, - IF_SAME_THEN_ELSE, - j.span, - "this `if` has identical blocks", - Some(i.span), - "same as this", - ); - } -} - -/// Implementation of `IFS_SAME_COND`. -fn lint_same_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>]) { - let hash: &dyn Fn(&&Expr<'_>) -> u64 = &|expr| -> u64 { - let mut h = SpanlessHash::new(cx); - h.hash_expr(expr); - h.finish() - }; - - let eq: &dyn Fn(&&Expr<'_>, &&Expr<'_>) -> bool = &|&lhs, &rhs| -> bool { eq_expr_value(cx, lhs, rhs) }; - - for (i, j) in search_same(conds, hash, eq) { - span_lint_and_note( - cx, - IFS_SAME_COND, - j.span, - "this `if` has the same condition as a previous `if`", - Some(i.span), - "same as this", - ); - } -} - -/// Implementation of `SAME_FUNCTIONS_IN_IF_CONDITION`. -fn lint_same_fns_in_if_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>]) { - let hash: &dyn Fn(&&Expr<'_>) -> u64 = &|expr| -> u64 { - let mut h = SpanlessHash::new(cx); - h.hash_expr(expr); - h.finish() - }; - - let eq: &dyn Fn(&&Expr<'_>, &&Expr<'_>) -> bool = &|&lhs, &rhs| -> bool { - // Do not lint if any expr originates from a macro - if in_macro(lhs.span) || in_macro(rhs.span) { - return false; - } - // Do not spawn warning if `IFS_SAME_COND` already produced it. - if eq_expr_value(cx, lhs, rhs) { - return false; - } - SpanlessEq::new(cx).eq_expr(lhs, rhs) - }; - - for (i, j) in search_same(conds, hash, eq) { - span_lint_and_note( - cx, - SAME_FUNCTIONS_IN_IF_CONDITION, - j.span, - "this `if` has the same function call as a previous `if`", - Some(i.span), - "same as this", - ); - } -} - -fn search_same_sequenced(exprs: &[T], eq: Eq) -> Option<(&T, &T)> -where - Eq: Fn(&T, &T) -> bool, -{ - for win in exprs.windows(2) { - if eq(&win[0], &win[1]) { - return Some((&win[0], &win[1])); - } - } - None -} diff --git a/clippy_lints/src/copy_iterator.rs b/clippy_lints/src/copy_iterator.rs deleted file mode 100644 index 349402453226..000000000000 --- a/clippy_lints/src/copy_iterator.rs +++ /dev/null @@ -1,55 +0,0 @@ -use crate::utils::{is_copy, match_path, paths, span_lint_and_note}; -use rustc_hir::{Item, ItemKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for types that implement `Copy` as well as - /// `Iterator`. - /// - /// **Why is this bad?** Implicit copies can be confusing when working with - /// iterator combinators. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// #[derive(Copy, Clone)] - /// struct Countdown(u8); - /// - /// impl Iterator for Countdown { - /// // ... - /// } - /// - /// let a: Vec<_> = my_iterator.take(1).collect(); - /// let b: Vec<_> = my_iterator.collect(); - /// ``` - pub COPY_ITERATOR, - pedantic, - "implementing `Iterator` on a `Copy` type" -} - -declare_lint_pass!(CopyIterator => [COPY_ITERATOR]); - -impl<'tcx> LateLintPass<'tcx> for CopyIterator { - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Impl { - of_trait: Some(ref trait_ref), - .. - } = item.kind - { - let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id)); - - if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) { - span_lint_and_note( - cx, - COPY_ITERATOR, - item.span, - "you are implementing `Iterator` on a `Copy` type", - None, - "consider implementing `IntoIterator` instead", - ); - } - } - } -} diff --git a/clippy_lints/src/create_dir.rs b/clippy_lints/src/create_dir.rs deleted file mode 100644 index 200b6a565cc4..000000000000 --- a/clippy_lints/src/create_dir.rs +++ /dev/null @@ -1,51 +0,0 @@ -use crate::utils::{match_def_path, paths, snippet, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks usage of `std::fs::create_dir` and suggest using `std::fs::create_dir_all` instead. - /// - /// **Why is this bad?** Sometimes `std::fs::create_dir` is mistakenly chosen over `std::fs::create_dir_all`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// std::fs::create_dir("foo"); - /// ``` - /// Use instead: - /// ```rust - /// std::fs::create_dir_all("foo"); - /// ``` - pub CREATE_DIR, - restriction, - "calling `std::fs::create_dir` instead of `std::fs::create_dir_all`" -} - -declare_lint_pass!(CreateDir => [CREATE_DIR]); - -impl LateLintPass<'_> for CreateDir { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::Call(ref func, ref args) = expr.kind; - if let ExprKind::Path(ref path) = func.kind; - if let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id(); - if match_def_path(cx, def_id, &paths::STD_FS_CREATE_DIR); - then { - span_lint_and_sugg( - cx, - CREATE_DIR, - expr.span, - "calling `std::fs::create_dir` where there may be a better way", - "consider calling `std::fs::create_dir_all` instead", - format!("create_dir_all({})", snippet(cx, args[0].span, "..")), - Applicability::MaybeIncorrect, - ) - } - } - } -} diff --git a/clippy_lints/src/dbg_macro.rs b/clippy_lints/src/dbg_macro.rs deleted file mode 100644 index e513dcce64e5..000000000000 --- a/clippy_lints/src/dbg_macro.rs +++ /dev/null @@ -1,65 +0,0 @@ -use crate::utils::{snippet_opt, span_lint_and_help, span_lint_and_sugg}; -use rustc_ast::ast; -use rustc_ast::tokenstream::TokenStream; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of dbg!() macro. - /// - /// **Why is this bad?** `dbg!` macro is intended as a debugging tool. It - /// should not be in version control. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// // Bad - /// dbg!(true) - /// - /// // Good - /// true - /// ``` - pub DBG_MACRO, - restriction, - "`dbg!` macro is intended as a debugging tool" -} - -declare_lint_pass!(DbgMacro => [DBG_MACRO]); - -impl EarlyLintPass for DbgMacro { - fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::MacCall) { - if mac.path == sym!(dbg) { - if let Some(sugg) = tts_span(mac.args.inner_tokens()).and_then(|span| snippet_opt(cx, span)) { - span_lint_and_sugg( - cx, - DBG_MACRO, - mac.span(), - "`dbg!` macro is intended as a debugging tool", - "ensure to avoid having uses of it in version control", - sugg, - Applicability::MaybeIncorrect, - ); - } else { - span_lint_and_help( - cx, - DBG_MACRO, - mac.span(), - "`dbg!` macro is intended as a debugging tool", - None, - "ensure to avoid having uses of it in version control", - ); - } - } - } -} - -// Get span enclosing entire the token stream. -fn tts_span(tts: TokenStream) -> Option { - let mut cursor = tts.into_trees(); - let first = cursor.next()?.span(); - let span = cursor.last().map_or(first, |tree| first.to(tree.span())); - Some(span) -} diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs deleted file mode 100644 index f69f6f1412af..000000000000 --- a/clippy_lints/src/default.rs +++ /dev/null @@ -1,303 +0,0 @@ -use crate::utils::{any_parent_is_automatically_derived, contains_name, match_def_path, paths, qpath_res, snippet}; -use crate::utils::{span_lint_and_note, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_data_structures::fx::FxHashSet; -use rustc_errors::Applicability; -use rustc_hir::def::Res; -use rustc_hir::{Block, Expr, ExprKind, PatKind, QPath, Stmt, StmtKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, Adt, Ty}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::symbol::{Ident, Symbol}; -use rustc_span::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for literal calls to `Default::default()`. - /// - /// **Why is this bad?** It's more clear to the reader to use the name of the type whose default is - /// being gotten than the generic `Default`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// // Bad - /// let s: String = Default::default(); - /// - /// // Good - /// let s = String::default(); - /// ``` - pub DEFAULT_TRAIT_ACCESS, - pedantic, - "checks for literal calls to `Default::default()`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for immediate reassignment of fields initialized - /// with Default::default(). - /// - /// **Why is this bad?**It's more idiomatic to use the [functional update syntax](https://doc.rust-lang.org/reference/expressions/struct-expr.html#functional-update-syntax). - /// - /// **Known problems:** Assignments to patterns that are of tuple type are not linted. - /// - /// **Example:** - /// Bad: - /// ``` - /// # #[derive(Default)] - /// # struct A { i: i32 } - /// let mut a: A = Default::default(); - /// a.i = 42; - /// ``` - /// Use instead: - /// ``` - /// # #[derive(Default)] - /// # struct A { i: i32 } - /// let a = A { - /// i: 42, - /// .. Default::default() - /// }; - /// ``` - pub FIELD_REASSIGN_WITH_DEFAULT, - style, - "binding initialized with Default should have its fields set in the initializer" -} - -#[derive(Default)] -pub struct Default { - // Spans linted by `field_reassign_with_default`. - reassigned_linted: FxHashSet, -} - -impl_lint_pass!(Default => [DEFAULT_TRAIT_ACCESS, FIELD_REASSIGN_WITH_DEFAULT]); - -impl LateLintPass<'_> for Default { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if_chain! { - // Avoid cases already linted by `field_reassign_with_default` - if !self.reassigned_linted.contains(&expr.span); - if let ExprKind::Call(ref path, ..) = expr.kind; - if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id); - if let ExprKind::Path(ref qpath) = path.kind; - if let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id(); - if match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD); - // Detect and ignore ::default() because these calls do explicitly name the type. - if let QPath::Resolved(None, _path) = qpath; - then { - let expr_ty = cx.typeck_results().expr_ty(expr); - if let ty::Adt(def, ..) = expr_ty.kind() { - // TODO: Work out a way to put "whatever the imported way of referencing - // this type in this file" rather than a fully-qualified type. - let replacement = format!("{}::default()", cx.tcx.def_path_str(def.did)); - span_lint_and_sugg( - cx, - DEFAULT_TRAIT_ACCESS, - expr.span, - &format!("calling `{}` is more clear than this expression", replacement), - "try", - replacement, - Applicability::Unspecified, // First resolve the TODO above - ); - } - } - } - } - - fn check_block<'tcx>(&mut self, cx: &LateContext<'tcx>, block: &Block<'tcx>) { - // find all binding statements like `let mut _ = T::default()` where `T::default()` is the - // `default` method of the `Default` trait, and store statement index in current block being - // checked and the name of the bound variable - let binding_statements_using_default = enumerate_bindings_using_default(cx, block); - - // start from the `let mut _ = _::default();` and look at all the following - // statements, see if they re-assign the fields of the binding - for (stmt_idx, binding_name, binding_type, span) in binding_statements_using_default { - // the last statement of a block cannot trigger the lint - if stmt_idx == block.stmts.len() - 1 { - break; - } - - // find all "later statement"'s where the fields of the binding set as - // Default::default() get reassigned, unless the reassignment refers to the original binding - let mut first_assign = None; - let mut assigned_fields = Vec::new(); - let mut cancel_lint = false; - for consecutive_statement in &block.stmts[stmt_idx + 1..] { - // interrupt if the statement is a let binding (`Local`) that shadows the original - // binding - if stmt_shadows_binding(consecutive_statement, binding_name) { - break; - } - // find out if and which field was set by this `consecutive_statement` - else if let Some((field_ident, assign_rhs)) = - field_reassigned_by_stmt(consecutive_statement, binding_name) - { - // interrupt and cancel lint if assign_rhs references the original binding - if contains_name(binding_name, assign_rhs) { - cancel_lint = true; - break; - } - - // if the field was previously assigned, replace the assignment, otherwise insert the assignment - if let Some(prev) = assigned_fields - .iter_mut() - .find(|(field_name, _)| field_name == &field_ident.name) - { - *prev = (field_ident.name, assign_rhs); - } else { - assigned_fields.push((field_ident.name, assign_rhs)); - } - - // also set first instance of error for help message - if first_assign.is_none() { - first_assign = Some(consecutive_statement); - } - } - // interrupt also if no field was assigned, since we only want to look at consecutive statements - else { - break; - } - } - - // if there are incorrectly assigned fields, do a span_lint_and_note to suggest - // construction using `Ty { fields, ..Default::default() }` - if !assigned_fields.is_empty() && !cancel_lint { - // take the original assignment as span - let stmt = &block.stmts[stmt_idx]; - - if let StmtKind::Local(preceding_local) = &stmt.kind { - // filter out fields like `= Default::default()`, because the FRU already covers them - let assigned_fields = assigned_fields - .into_iter() - .filter(|(_, rhs)| !is_expr_default(rhs, cx)) - .collect::)>>(); - - // if all fields of the struct are not assigned, add `.. Default::default()` to the suggestion. - let ext_with_default = !fields_of_type(binding_type) - .iter() - .all(|field| assigned_fields.iter().any(|(a, _)| a == &field.name)); - - let field_list = assigned_fields - .into_iter() - .map(|(field, rhs)| { - // extract and store the assigned value for help message - let value_snippet = snippet(cx, rhs.span, ".."); - format!("{}: {}", field, value_snippet) - }) - .collect::>() - .join(", "); - - let sugg = if ext_with_default { - if field_list.is_empty() { - format!("{}::default()", binding_type) - } else { - format!("{} {{ {}, ..Default::default() }}", binding_type, field_list) - } - } else { - format!("{} {{ {} }}", binding_type, field_list) - }; - - // span lint once per statement that binds default - span_lint_and_note( - cx, - FIELD_REASSIGN_WITH_DEFAULT, - first_assign.unwrap().span, - "field assignment outside of initializer for an instance created with Default::default()", - Some(preceding_local.span), - &format!( - "consider initializing the variable with `{}` and removing relevant reassignments", - sugg - ), - ); - self.reassigned_linted.insert(span); - } - } - } - } -} - -/// Checks if the given expression is the `default` method belonging to the `Default` trait. -fn is_expr_default<'tcx>(expr: &'tcx Expr<'tcx>, cx: &LateContext<'tcx>) -> bool { - if_chain! { - if let ExprKind::Call(ref fn_expr, _) = &expr.kind; - if let ExprKind::Path(qpath) = &fn_expr.kind; - if let Res::Def(_, def_id) = qpath_res(cx, qpath, fn_expr.hir_id); - then { - // right hand side of assignment is `Default::default` - match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD) - } else { - false - } - } -} - -/// Returns the block indices, identifiers and types of bindings set as `Default::default()`, except -/// for when the pattern type is a tuple. -fn enumerate_bindings_using_default<'tcx>( - cx: &LateContext<'tcx>, - block: &Block<'tcx>, -) -> Vec<(usize, Symbol, Ty<'tcx>, Span)> { - block - .stmts - .iter() - .enumerate() - .filter_map(|(idx, stmt)| { - if_chain! { - // only take `let ...` statements - if let StmtKind::Local(ref local) = stmt.kind; - // only take bindings to identifiers - if let PatKind::Binding(_, _, ident, _) = local.pat.kind; - // that are not tuples - let ty = cx.typeck_results().pat_ty(local.pat); - if !matches!(ty.kind(), ty::Tuple(_)); - // only when assigning `... = Default::default()` - if let Some(ref expr) = local.init; - if is_expr_default(expr, cx); - then { - Some((idx, ident.name, ty, expr.span)) - } else { - None - } - } - }) - .collect() -} - -fn stmt_shadows_binding(this: &Stmt<'_>, shadowed: Symbol) -> bool { - if let StmtKind::Local(local) = &this.kind { - if let PatKind::Binding(_, _, ident, _) = local.pat.kind { - return ident.name == shadowed; - } - } - false -} - -/// Returns the reassigned field and the assigning expression (right-hand side of assign). -fn field_reassigned_by_stmt<'tcx>(this: &Stmt<'tcx>, binding_name: Symbol) -> Option<(Ident, &'tcx Expr<'tcx>)> { - if_chain! { - // only take assignments - if let StmtKind::Semi(ref later_expr) = this.kind; - if let ExprKind::Assign(ref assign_lhs, ref assign_rhs, _) = later_expr.kind; - // only take assignments to fields where the left-hand side field is a field of - // the same binding as the previous statement - if let ExprKind::Field(ref binding, field_ident) = assign_lhs.kind; - if let ExprKind::Path(QPath::Resolved(_, path)) = binding.kind; - if let Some(second_binding_name) = path.segments.last(); - if second_binding_name.ident.name == binding_name; - then { - Some((field_ident, assign_rhs)) - } else { - None - } - } -} - -/// Returns the vec of fields for a struct and an empty vec for non-struct ADTs. -fn fields_of_type(ty: Ty<'_>) -> Vec { - if let Adt(adt, _) = ty.kind() { - if adt.is_struct() { - let variant = &adt.non_enum_variant(); - return variant.fields.iter().map(|f| f.ident).collect(); - } - } - vec![] -} diff --git a/clippy_lints/src/deprecated_lints.rs b/clippy_lints/src/deprecated_lints.rs deleted file mode 100644 index bec0c9f93a0d..000000000000 --- a/clippy_lints/src/deprecated_lints.rs +++ /dev/null @@ -1,168 +0,0 @@ -macro_rules! declare_deprecated_lint { - (pub $name: ident, $_reason: expr) => { - declare_lint!(pub $name, Allow, "deprecated lint") - } -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** This used to check for `assert!(a == b)` and recommend - /// replacement with `assert_eq!(a, b)`, but this is no longer needed after RFC 2011. - pub SHOULD_ASSERT_EQ, - "`assert!()` will be more flexible with RFC 2011" -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** This used to check for `Vec::extend`, which was slower than - /// `Vec::extend_from_slice`. Thanks to specialization, this is no longer true. - pub EXTEND_FROM_SLICE, - "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice" -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** `Range::step_by(0)` used to be linted since it's - /// an infinite iterator, which is better expressed by `iter::repeat`, - /// but the method has been removed for `Iterator::step_by` which panics - /// if given a zero - pub RANGE_STEP_BY_ZERO, - "`iterator.step_by(0)` panics nowadays" -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** This used to check for `Vec::as_slice`, which was unstable with good - /// stable alternatives. `Vec::as_slice` has now been stabilized. - pub UNSTABLE_AS_SLICE, - "`Vec::as_slice` has been stabilized in 1.7" -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** This used to check for `Vec::as_mut_slice`, which was unstable with good - /// stable alternatives. `Vec::as_mut_slice` has now been stabilized. - pub UNSTABLE_AS_MUT_SLICE, - "`Vec::as_mut_slice` has been stabilized in 1.7" -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** This lint should never have applied to non-pointer types, as transmuting - /// between non-pointer types of differing alignment is well-defined behavior (it's semantically - /// equivalent to a memcpy). This lint has thus been refactored into two separate lints: - /// cast_ptr_alignment and transmute_ptr_to_ptr. - pub MISALIGNED_TRANSMUTE, - "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr" -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** This lint is too subjective, not having a good reason for being in clippy. - /// Additionally, compound assignment operators may be overloaded separately from their non-assigning - /// counterparts, so this lint may suggest a change in behavior or the code may not compile. - pub ASSIGN_OPS, - "using compound assignment operators (e.g., `+=`) is harmless" -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** The original rule will only lint for `if let`. After - /// making it support to lint `match`, naming as `if let` is not suitable for it. - /// So, this lint is deprecated. - pub IF_LET_REDUNDANT_PATTERN_MATCHING, - "this lint has been changed to redundant_pattern_matching" -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** This lint used to suggest replacing `let mut vec = - /// Vec::with_capacity(n); vec.set_len(n);` with `let vec = vec![0; n];`. The - /// replacement has very different performance characteristics so the lint is - /// deprecated. - pub UNSAFE_VECTOR_INITIALIZATION, - "the replacement suggested by this lint had substantially different behavior" -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** This lint has been superseded by the warn-by-default - /// `invalid_value` rustc lint. - pub INVALID_REF, - "superseded by rustc lint `invalid_value`" -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** This lint has been superseded by #[must_use] in rustc. - pub UNUSED_COLLECT, - "`collect` has been marked as #[must_use] in rustc and that covers all cases of this lint" -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** This lint has been uplifted to rustc and is now called - /// `array_into_iter`. - pub INTO_ITER_ON_ARRAY, - "this lint has been uplifted to rustc and is now called `array_into_iter`" -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** This lint has been uplifted to rustc and is now called - /// `unused_labels`. - pub UNUSED_LABEL, - "this lint has been uplifted to rustc and is now called `unused_labels`" -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** Associated-constants are now preferred. - pub REPLACE_CONSTS, - "associated-constants `MIN`/`MAX` of integers are preferred to `{min,max}_value()` and module constants" -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** The regex! macro does not exist anymore. - pub REGEX_MACRO, - "the regex! macro has been removed from the regex crate in 2018" -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** This lint has been uplifted to rustc and is now called - /// `drop_bounds`. - pub DROP_BOUNDS, - "this lint has been uplifted to rustc and is now called `drop_bounds`" -} - -declare_deprecated_lint! { - /// **What it does:** Nothing. This lint has been deprecated. - /// - /// **Deprecation reason:** This lint has been uplifted to rustc and is now called - /// `temporary_cstring_as_ptr`. - pub TEMPORARY_CSTRING_AS_PTR, - "this lint has been uplifted to rustc and is now called `temporary_cstring_as_ptr`" -} - -declare_deprecated_lint! { - pub PANIC_PARAMS, - "this lint has been uplifted to rustc and is now called `panic_fmt`" -} diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs deleted file mode 100644 index b5fb51af1c7f..000000000000 --- a/clippy_lints/src/dereference.rs +++ /dev/null @@ -1,109 +0,0 @@ -use crate::utils::{get_parent_expr, implements_trait, snippet, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_ast::util::parser::{ExprPrecedence, PREC_POSTFIX, PREC_PREFIX}; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for explicit `deref()` or `deref_mut()` method calls. - /// - /// **Why is this bad?** Dereferencing by `&*x` or `&mut *x` is clearer and more concise, - /// when not part of a method chain. - /// - /// **Example:** - /// ```rust - /// use std::ops::Deref; - /// let a: &mut String = &mut String::from("foo"); - /// let b: &str = a.deref(); - /// ``` - /// Could be written as: - /// ```rust - /// let a: &mut String = &mut String::from("foo"); - /// let b = &*a; - /// ``` - /// - /// This lint excludes - /// ```rust,ignore - /// let _ = d.unwrap().deref(); - /// ``` - pub EXPLICIT_DEREF_METHODS, - pedantic, - "Explicit use of deref or deref_mut method while not in a method chain." -} - -declare_lint_pass!(Dereferencing => [ - EXPLICIT_DEREF_METHODS -]); - -impl<'tcx> LateLintPass<'tcx> for Dereferencing { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if_chain! { - if !expr.span.from_expansion(); - if let ExprKind::MethodCall(ref method_name, _, ref args, _) = &expr.kind; - if args.len() == 1; - - then { - if let Some(parent_expr) = get_parent_expr(cx, expr) { - // Check if we have the whole call chain here - if let ExprKind::MethodCall(..) = parent_expr.kind { - return; - } - // Check for Expr that we don't want to be linted - let precedence = parent_expr.precedence(); - match precedence { - // Lint a Call is ok though - ExprPrecedence::Call | ExprPrecedence::AddrOf => (), - _ => { - if precedence.order() >= PREC_PREFIX && precedence.order() <= PREC_POSTFIX { - return; - } - } - } - } - let name = method_name.ident.as_str(); - lint_deref(cx, &*name, &args[0], args[0].span, expr.span); - } - } - } -} - -fn lint_deref(cx: &LateContext<'_>, method_name: &str, call_expr: &Expr<'_>, var_span: Span, expr_span: Span) { - match method_name { - "deref" => { - let impls_deref_trait = cx.tcx.lang_items().deref_trait().map_or(false, |id| { - implements_trait(cx, cx.typeck_results().expr_ty(&call_expr), id, &[]) - }); - if impls_deref_trait { - span_lint_and_sugg( - cx, - EXPLICIT_DEREF_METHODS, - expr_span, - "explicit deref method call", - "try this", - format!("&*{}", &snippet(cx, var_span, "..")), - Applicability::MachineApplicable, - ); - } - }, - "deref_mut" => { - let impls_deref_mut_trait = cx.tcx.lang_items().deref_mut_trait().map_or(false, |id| { - implements_trait(cx, cx.typeck_results().expr_ty(&call_expr), id, &[]) - }); - if impls_deref_mut_trait { - span_lint_and_sugg( - cx, - EXPLICIT_DEREF_METHODS, - expr_span, - "explicit deref_mut method call", - "try this", - format!("&mut *{}", &snippet(cx, var_span, "..")), - Applicability::MachineApplicable, - ); - } - }, - _ => (), - } -} diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs deleted file mode 100644 index c75efc6e99f8..000000000000 --- a/clippy_lints/src/derive.rs +++ /dev/null @@ -1,423 +0,0 @@ -use crate::utils::paths; -use crate::utils::{ - get_trait_def_id, is_allowed, is_automatically_derived, is_copy, match_def_path, match_path, span_lint_and_help, - span_lint_and_note, span_lint_and_then, -}; -use if_chain::if_chain; -use rustc_hir::def_id::DefId; -use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, NestedVisitorMap, Visitor}; -use rustc_hir::{ - BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, TraitRef, UnsafeSource, Unsafety, -}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; -use rustc_middle::ty::{self, Ty}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for deriving `Hash` but implementing `PartialEq` - /// explicitly or vice versa. - /// - /// **Why is this bad?** The implementation of these traits must agree (for - /// example for use with `HashMap`) so it’s probably a bad idea to use a - /// default-generated `Hash` implementation with an explicitly defined - /// `PartialEq`. In particular, the following must hold for any type: - /// - /// ```text - /// k1 == k2 ⇒ hash(k1) == hash(k2) - /// ``` - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// #[derive(Hash)] - /// struct Foo; - /// - /// impl PartialEq for Foo { - /// ... - /// } - /// ``` - pub DERIVE_HASH_XOR_EQ, - correctness, - "deriving `Hash` but implementing `PartialEq` explicitly" -} - -declare_clippy_lint! { - /// **What it does:** Checks for deriving `Ord` but implementing `PartialOrd` - /// explicitly or vice versa. - /// - /// **Why is this bad?** The implementation of these traits must agree (for - /// example for use with `sort`) so it’s probably a bad idea to use a - /// default-generated `Ord` implementation with an explicitly defined - /// `PartialOrd`. In particular, the following must hold for any type - /// implementing `Ord`: - /// - /// ```text - /// k1.cmp(&k2) == k1.partial_cmp(&k2).unwrap() - /// ``` - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust,ignore - /// #[derive(Ord, PartialEq, Eq)] - /// struct Foo; - /// - /// impl PartialOrd for Foo { - /// ... - /// } - /// ``` - /// Use instead: - /// ```rust,ignore - /// #[derive(PartialEq, Eq)] - /// struct Foo; - /// - /// impl PartialOrd for Foo { - /// fn partial_cmp(&self, other: &Foo) -> Option { - /// Some(self.cmp(other)) - /// } - /// } - /// - /// impl Ord for Foo { - /// ... - /// } - /// ``` - /// or, if you don't need a custom ordering: - /// ```rust,ignore - /// #[derive(Ord, PartialOrd, PartialEq, Eq)] - /// struct Foo; - /// ``` - pub DERIVE_ORD_XOR_PARTIAL_ORD, - correctness, - "deriving `Ord` but implementing `PartialOrd` explicitly" -} - -declare_clippy_lint! { - /// **What it does:** Checks for explicit `Clone` implementations for `Copy` - /// types. - /// - /// **Why is this bad?** To avoid surprising behaviour, these traits should - /// agree and the behaviour of `Copy` cannot be overridden. In almost all - /// situations a `Copy` type should have a `Clone` implementation that does - /// nothing more than copy the object, which is what `#[derive(Copy, Clone)]` - /// gets you. - /// - /// **Known problems:** Bounds of generic types are sometimes wrong: https://github.com/rust-lang/rust/issues/26925 - /// - /// **Example:** - /// ```rust,ignore - /// #[derive(Copy)] - /// struct Foo; - /// - /// impl Clone for Foo { - /// // .. - /// } - /// ``` - pub EXPL_IMPL_CLONE_ON_COPY, - pedantic, - "implementing `Clone` explicitly on `Copy` types" -} - -declare_clippy_lint! { - /// **What it does:** Checks for deriving `serde::Deserialize` on a type that - /// has methods using `unsafe`. - /// - /// **Why is this bad?** Deriving `serde::Deserialize` will create a constructor - /// that may violate invariants hold by another constructor. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust,ignore - /// use serde::Deserialize; - /// - /// #[derive(Deserialize)] - /// pub struct Foo { - /// // .. - /// } - /// - /// impl Foo { - /// pub fn new() -> Self { - /// // setup here .. - /// } - /// - /// pub unsafe fn parts() -> (&str, &str) { - /// // assumes invariants hold - /// } - /// } - /// ``` - pub UNSAFE_DERIVE_DESERIALIZE, - pedantic, - "deriving `serde::Deserialize` on a type that has methods using `unsafe`" -} - -declare_lint_pass!(Derive => [ - EXPL_IMPL_CLONE_ON_COPY, - DERIVE_HASH_XOR_EQ, - DERIVE_ORD_XOR_PARTIAL_ORD, - UNSAFE_DERIVE_DESERIALIZE -]); - -impl<'tcx> LateLintPass<'tcx> for Derive { - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Impl { - of_trait: Some(ref trait_ref), - .. - } = item.kind - { - let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id)); - let is_automatically_derived = is_automatically_derived(&*item.attrs); - - check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived); - check_ord_partial_ord(cx, item.span, trait_ref, ty, is_automatically_derived); - - if is_automatically_derived { - check_unsafe_derive_deserialize(cx, item, trait_ref, ty); - } else { - check_copy_clone(cx, item, trait_ref, ty); - } - } - } -} - -/// Implementation of the `DERIVE_HASH_XOR_EQ` lint. -fn check_hash_peq<'tcx>( - cx: &LateContext<'tcx>, - span: Span, - trait_ref: &TraitRef<'_>, - ty: Ty<'tcx>, - hash_is_automatically_derived: bool, -) { - if_chain! { - if let Some(peq_trait_def_id) = cx.tcx.lang_items().eq_trait(); - if let Some(def_id) = trait_ref.trait_def_id(); - if match_def_path(cx, def_id, &paths::HASH); - then { - // Look for the PartialEq implementations for `ty` - cx.tcx.for_each_relevant_impl(peq_trait_def_id, ty, |impl_id| { - let peq_is_automatically_derived = is_automatically_derived(&cx.tcx.get_attrs(impl_id)); - - if peq_is_automatically_derived == hash_is_automatically_derived { - return; - } - - let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation"); - - // Only care about `impl PartialEq for Foo` - // For `impl PartialEq for A, input_types is [A, B] - if trait_ref.substs.type_at(1) == ty { - let mess = if peq_is_automatically_derived { - "you are implementing `Hash` explicitly but have derived `PartialEq`" - } else { - "you are deriving `Hash` but have implemented `PartialEq` explicitly" - }; - - span_lint_and_then( - cx, - DERIVE_HASH_XOR_EQ, - span, - mess, - |diag| { - if let Some(local_def_id) = impl_id.as_local() { - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id); - diag.span_note( - cx.tcx.hir().span(hir_id), - "`PartialEq` implemented here" - ); - } - } - ); - } - }); - } - } -} - -/// Implementation of the `DERIVE_ORD_XOR_PARTIAL_ORD` lint. -fn check_ord_partial_ord<'tcx>( - cx: &LateContext<'tcx>, - span: Span, - trait_ref: &TraitRef<'_>, - ty: Ty<'tcx>, - ord_is_automatically_derived: bool, -) { - if_chain! { - if let Some(ord_trait_def_id) = get_trait_def_id(cx, &paths::ORD); - if let Some(partial_ord_trait_def_id) = cx.tcx.lang_items().partial_ord_trait(); - if let Some(def_id) = &trait_ref.trait_def_id(); - if *def_id == ord_trait_def_id; - then { - // Look for the PartialOrd implementations for `ty` - cx.tcx.for_each_relevant_impl(partial_ord_trait_def_id, ty, |impl_id| { - let partial_ord_is_automatically_derived = is_automatically_derived(&cx.tcx.get_attrs(impl_id)); - - if partial_ord_is_automatically_derived == ord_is_automatically_derived { - return; - } - - let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation"); - - // Only care about `impl PartialOrd for Foo` - // For `impl PartialOrd for A, input_types is [A, B] - if trait_ref.substs.type_at(1) == ty { - let mess = if partial_ord_is_automatically_derived { - "you are implementing `Ord` explicitly but have derived `PartialOrd`" - } else { - "you are deriving `Ord` but have implemented `PartialOrd` explicitly" - }; - - span_lint_and_then( - cx, - DERIVE_ORD_XOR_PARTIAL_ORD, - span, - mess, - |diag| { - if let Some(local_def_id) = impl_id.as_local() { - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id); - diag.span_note( - cx.tcx.hir().span(hir_id), - "`PartialOrd` implemented here" - ); - } - } - ); - } - }); - } - } -} - -/// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint. -fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &TraitRef<'_>, ty: Ty<'tcx>) { - if match_path(&trait_ref.path, &paths::CLONE_TRAIT) { - if !is_copy(cx, ty) { - return; - } - - match *ty.kind() { - ty::Adt(def, _) if def.is_union() => return, - - // Some types are not Clone by default but could be cloned “by hand” if necessary - ty::Adt(def, substs) => { - for variant in &def.variants { - for field in &variant.fields { - if let ty::FnDef(..) = field.ty(cx.tcx, substs).kind() { - return; - } - } - for subst in substs { - if let ty::subst::GenericArgKind::Type(subst) = subst.unpack() { - if let ty::Param(_) = subst.kind() { - return; - } - } - } - } - }, - _ => (), - } - - span_lint_and_note( - cx, - EXPL_IMPL_CLONE_ON_COPY, - item.span, - "you are implementing `Clone` explicitly on a `Copy` type", - Some(item.span), - "consider deriving `Clone` or removing `Copy`", - ); - } -} - -/// Implementation of the `UNSAFE_DERIVE_DESERIALIZE` lint. -fn check_unsafe_derive_deserialize<'tcx>( - cx: &LateContext<'tcx>, - item: &Item<'_>, - trait_ref: &TraitRef<'_>, - ty: Ty<'tcx>, -) { - fn item_from_def_id<'tcx>(cx: &LateContext<'tcx>, def_id: DefId) -> &'tcx Item<'tcx> { - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); - cx.tcx.hir().expect_item(hir_id) - } - - fn has_unsafe<'tcx>(cx: &LateContext<'tcx>, item: &'tcx Item<'_>) -> bool { - let mut visitor = UnsafeVisitor { cx, has_unsafe: false }; - walk_item(&mut visitor, item); - visitor.has_unsafe - } - - if_chain! { - if let Some(trait_def_id) = trait_ref.trait_def_id(); - if match_def_path(cx, trait_def_id, &paths::SERDE_DESERIALIZE); - 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 cx.tcx.inherent_impls(def.did) - .iter() - .map(|imp_did| item_from_def_id(cx, *imp_did)) - .any(|imp| has_unsafe(cx, imp)); - then { - span_lint_and_help( - cx, - UNSAFE_DERIVE_DESERIALIZE, - item.span, - "you are deriving `serde::Deserialize` on a type that has methods using `unsafe`", - None, - "consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html" - ); - } - } -} - -struct UnsafeVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - has_unsafe: bool, -} - -impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> { - type Map = Map<'tcx>; - - fn visit_fn(&mut self, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body_id: BodyId, span: Span, id: HirId) { - if self.has_unsafe { - return; - } - - if_chain! { - if let Some(header) = kind.header(); - if let Unsafety::Unsafe = header.unsafety; - then { - self.has_unsafe = true; - } - } - - walk_fn(self, kind, decl, body_id, span, id); - } - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if self.has_unsafe { - return; - } - - if let ExprKind::Block(block, _) = expr.kind { - match block.rules { - BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) - | BlockCheckMode::PushUnsafeBlock(UnsafeSource::UserProvided) - | BlockCheckMode::PopUnsafeBlock(UnsafeSource::UserProvided) => { - self.has_unsafe = true; - }, - _ => {}, - } - } - - walk_expr(self, expr); - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::All(self.cx.tcx.hir()) - } -} diff --git a/clippy_lints/src/disallowed_method.rs b/clippy_lints/src/disallowed_method.rs deleted file mode 100644 index 581c3242e374..000000000000 --- a/clippy_lints/src/disallowed_method.rs +++ /dev/null @@ -1,73 +0,0 @@ -use crate::utils::span_lint; - -use rustc_data_structures::fx::FxHashSet; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::Symbol; - -declare_clippy_lint! { - /// **What it does:** Lints for specific trait methods defined in clippy.toml - /// - /// **Why is this bad?** Some methods are undesirable in certain contexts, - /// and it would be beneficial to lint for them as needed. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust,ignore - /// // example code where clippy issues a warning - /// foo.bad_method(); // Foo::bad_method is disallowed in the configuration - /// ``` - /// Use instead: - /// ```rust,ignore - /// // example code which does not raise clippy warning - /// goodStruct.bad_method(); // GoodStruct::bad_method is not disallowed - /// ``` - pub DISALLOWED_METHOD, - nursery, - "use of a disallowed method call" -} - -#[derive(Clone, Debug)] -pub struct DisallowedMethod { - disallowed: FxHashSet>, -} - -impl DisallowedMethod { - pub fn new(disallowed: &FxHashSet) -> Self { - Self { - disallowed: disallowed - .iter() - .map(|s| s.split("::").map(|seg| Symbol::intern(seg)).collect::>()) - .collect(), - } - } -} - -impl_lint_pass!(DisallowedMethod => [DISALLOWED_METHOD]); - -impl<'tcx> LateLintPass<'tcx> for DisallowedMethod { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::MethodCall(_path, _, _args, _) = &expr.kind { - let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap(); - - let method_call = cx.get_def_path(def_id); - if self.disallowed.contains(&method_call) { - let method = method_call - .iter() - .map(|s| s.to_ident_string()) - .collect::>() - .join("::"); - - span_lint( - cx, - DISALLOWED_METHOD, - expr.span, - &format!("use of a disallowed method `{}`", method), - ); - } - } - } -} diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs deleted file mode 100644 index aba655327959..000000000000 --- a/clippy_lints/src/doc.rs +++ /dev/null @@ -1,611 +0,0 @@ -use crate::utils::{implements_trait, is_entrypoint_fn, is_type_diagnostic_item, return_ty, span_lint}; -use if_chain::if_chain; -use itertools::Itertools; -use rustc_ast::ast::{Async, AttrKind, Attribute, FnRetTy, ItemKind}; -use rustc_ast::token::CommentKind; -use rustc_data_structures::fx::FxHashSet; -use rustc_data_structures::sync::Lrc; -use rustc_errors::emitter::EmitterWriter; -use rustc_errors::Handler; -use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty; -use rustc_parse::maybe_new_parser_from_source_str; -use rustc_session::parse::ParseSess; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::edition::Edition; -use rustc_span::source_map::{BytePos, FilePathMapping, MultiSpan, SourceMap, Span}; -use rustc_span::{sym, FileName, Pos}; -use std::io; -use std::ops::Range; -use url::Url; - -declare_clippy_lint! { - /// **What it does:** Checks for the presence of `_`, `::` or camel-case words - /// outside ticks in documentation. - /// - /// **Why is this bad?** *Rustdoc* supports markdown formatting, `_`, `::` and - /// camel-case probably indicates some code which should be included between - /// ticks. `_` can also be used for emphasis in markdown, this lint tries to - /// consider that. - /// - /// **Known problems:** Lots of bad docs won’t be fixed, what the lint checks - /// for is limited, and there are still false positives. - /// - /// In addition, when writing documentation comments, including `[]` brackets - /// inside a link text would trip the parser. Therfore, documenting link with - /// `[`SmallVec<[T; INLINE_CAPACITY]>`]` and then [`SmallVec<[T; INLINE_CAPACITY]>`]: SmallVec - /// would fail. - /// - /// **Examples:** - /// ```rust - /// /// Do something with the foo_bar parameter. See also - /// /// that::other::module::foo. - /// // ^ `foo_bar` and `that::other::module::foo` should be ticked. - /// fn doit(foo_bar: usize) {} - /// ``` - /// - /// ```rust - /// // Link text with `[]` brackets should be written as following: - /// /// Consume the array and return the inner - /// /// [`SmallVec<[T; INLINE_CAPACITY]>`][SmallVec]. - /// /// [SmallVec]: SmallVec - /// fn main() {} - /// ``` - pub DOC_MARKDOWN, - pedantic, - "presence of `_`, `::` or camel-case outside backticks in documentation" -} - -declare_clippy_lint! { - /// **What it does:** Checks for the doc comments of publicly visible - /// unsafe functions and warns if there is no `# Safety` section. - /// - /// **Why is this bad?** Unsafe functions should document their safety - /// preconditions, so that users can be sure they are using them safely. - /// - /// **Known problems:** None. - /// - /// **Examples:** - /// ```rust - ///# type Universe = (); - /// /// This function should really be documented - /// pub unsafe fn start_apocalypse(u: &mut Universe) { - /// unimplemented!(); - /// } - /// ``` - /// - /// At least write a line about safety: - /// - /// ```rust - ///# type Universe = (); - /// /// # Safety - /// /// - /// /// This function should not be called before the horsemen are ready. - /// pub unsafe fn start_apocalypse(u: &mut Universe) { - /// unimplemented!(); - /// } - /// ``` - pub MISSING_SAFETY_DOC, - style, - "`pub unsafe fn` without `# Safety` docs" -} - -declare_clippy_lint! { - /// **What it does:** Checks the doc comments of publicly visible functions that - /// return a `Result` type and warns if there is no `# Errors` section. - /// - /// **Why is this bad?** Documenting the type of errors that can be returned from a - /// function can help callers write code to handle the errors appropriately. - /// - /// **Known problems:** None. - /// - /// **Examples:** - /// - /// Since the following function returns a `Result` it has an `# Errors` section in - /// its doc comment: - /// - /// ```rust - ///# use std::io; - /// /// # Errors - /// /// - /// /// Will return `Err` if `filename` does not exist or the user does not have - /// /// permission to read it. - /// pub fn read(filename: String) -> io::Result { - /// unimplemented!(); - /// } - /// ``` - pub MISSING_ERRORS_DOC, - pedantic, - "`pub fn` returns `Result` without `# Errors` in doc comment" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `fn main() { .. }` in doctests - /// - /// **Why is this bad?** The test can be shorter (and likely more readable) - /// if the `fn main()` is left implicit. - /// - /// **Known problems:** None. - /// - /// **Examples:** - /// ``````rust - /// /// An example of a doctest with a `main()` function - /// /// - /// /// # Examples - /// /// - /// /// ``` - /// /// fn main() { - /// /// // this needs not be in an `fn` - /// /// } - /// /// ``` - /// fn needless_main() { - /// unimplemented!(); - /// } - /// `````` - pub NEEDLESS_DOCTEST_MAIN, - style, - "presence of `fn main() {` in code examples" -} - -#[allow(clippy::module_name_repetitions)] -#[derive(Clone)] -pub struct DocMarkdown { - valid_idents: FxHashSet, - in_trait_impl: bool, -} - -impl DocMarkdown { - pub fn new(valid_idents: FxHashSet) -> Self { - Self { - valid_idents, - in_trait_impl: false, - } - } -} - -impl_lint_pass!(DocMarkdown => [DOC_MARKDOWN, MISSING_SAFETY_DOC, MISSING_ERRORS_DOC, NEEDLESS_DOCTEST_MAIN]); - -impl<'tcx> LateLintPass<'tcx> for DocMarkdown { - fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) { - check_attrs(cx, &self.valid_idents, &krate.item.attrs); - } - - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { - let headers = check_attrs(cx, &self.valid_idents, &item.attrs); - match item.kind { - hir::ItemKind::Fn(ref sig, _, body_id) => { - if !(is_entrypoint_fn(cx, cx.tcx.hir().local_def_id(item.hir_id).to_def_id()) - || in_external_macro(cx.tcx.sess, item.span)) - { - lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id)); - } - }, - hir::ItemKind::Impl { - of_trait: ref trait_ref, - .. - } => { - self.in_trait_impl = trait_ref.is_some(); - }, - _ => {}, - } - } - - fn check_item_post(&mut self, _cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { - if let hir::ItemKind::Impl { .. } = item.kind { - self.in_trait_impl = false; - } - } - - fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { - let headers = check_attrs(cx, &self.valid_idents, &item.attrs); - if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { - if !in_external_macro(cx.tcx.sess, item.span) { - lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, None); - } - } - } - - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { - let headers = check_attrs(cx, &self.valid_idents, &item.attrs); - if self.in_trait_impl || in_external_macro(cx.tcx.sess, item.span) { - return; - } - if let hir::ImplItemKind::Fn(ref sig, body_id) = item.kind { - lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id)); - } - } -} - -fn lint_for_missing_headers<'tcx>( - cx: &LateContext<'tcx>, - hir_id: hir::HirId, - span: impl Into + Copy, - sig: &hir::FnSig<'_>, - headers: DocHeaders, - body_id: Option, -) { - if !cx.access_levels.is_exported(hir_id) { - return; // Private functions do not require doc comments - } - if !headers.safety && sig.header.unsafety == hir::Unsafety::Unsafe { - span_lint( - cx, - MISSING_SAFETY_DOC, - span, - "unsafe function's docs miss `# Safety` section", - ); - } - if !headers.errors { - if is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::result_type) { - span_lint( - cx, - MISSING_ERRORS_DOC, - span, - "docs for function returning `Result` missing `# Errors` section", - ); - } else { - if_chain! { - if let Some(body_id) = body_id; - if let Some(future) = cx.tcx.lang_items().future_trait(); - let def_id = cx.tcx.hir().body_owner_def_id(body_id); - let mir = cx.tcx.optimized_mir(def_id.to_def_id()); - let ret_ty = mir.return_ty(); - if implements_trait(cx, ret_ty, future, &[]); - if let ty::Opaque(_, subs) = ret_ty.kind(); - if let Some(gen) = subs.types().next(); - if let ty::Generator(_, subs, _) = gen.kind(); - if is_type_diagnostic_item(cx, subs.as_generator().return_ty(), sym::result_type); - then { - span_lint( - cx, - MISSING_ERRORS_DOC, - span, - "docs for function returning `Result` missing `# Errors` section", - ); - } - } - } - } -} - -/// Cleanup documentation decoration. -/// -/// We can't use `rustc_ast::attr::AttributeMethods::with_desugared_doc` or -/// `rustc_ast::parse::lexer::comments::strip_doc_comment_decoration` because we -/// need to keep track of -/// the spans but this function is inspired from the later. -#[allow(clippy::cast_possible_truncation)] -#[must_use] -pub fn strip_doc_comment_decoration(doc: &str, comment_kind: CommentKind, span: Span) -> (String, Vec<(usize, Span)>) { - // one-line comments lose their prefix - if comment_kind == CommentKind::Line { - let mut doc = doc.to_owned(); - doc.push('\n'); - let len = doc.len(); - // +3 skips the opening delimiter - return (doc, vec![(len, span.with_lo(span.lo() + BytePos(3)))]); - } - - let mut sizes = vec![]; - let mut contains_initial_stars = false; - for line in doc.lines() { - let offset = line.as_ptr() as usize - doc.as_ptr() as usize; - debug_assert_eq!(offset as u32 as usize, offset); - contains_initial_stars |= line.trim_start().starts_with('*'); - // +1 adds the newline, +3 skips the opening delimiter - sizes.push((line.len() + 1, span.with_lo(span.lo() + BytePos(3 + offset as u32)))); - } - if !contains_initial_stars { - return (doc.to_string(), sizes); - } - // remove the initial '*'s if any - let mut no_stars = String::with_capacity(doc.len()); - for line in doc.lines() { - let mut chars = line.chars(); - while let Some(c) = chars.next() { - if c.is_whitespace() { - no_stars.push(c); - } else { - no_stars.push(if c == '*' { ' ' } else { c }); - break; - } - } - no_stars.push_str(chars.as_str()); - no_stars.push('\n'); - } - - (no_stars, sizes) -} - -#[derive(Copy, Clone)] -struct DocHeaders { - safety: bool, - errors: bool, -} - -fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &'a [Attribute]) -> DocHeaders { - let mut doc = String::new(); - let mut spans = vec![]; - - for attr in attrs { - if let AttrKind::DocComment(comment_kind, comment) = attr.kind { - let (comment, current_spans) = strip_doc_comment_decoration(&comment.as_str(), comment_kind, attr.span); - spans.extend_from_slice(¤t_spans); - doc.push_str(&comment); - } else if attr.has_name(sym::doc) { - // ignore mix of sugared and non-sugared doc - // don't trigger the safety or errors check - return DocHeaders { - safety: true, - errors: true, - }; - } - } - - let mut current = 0; - for &mut (ref mut offset, _) in &mut spans { - let offset_copy = *offset; - *offset = current; - current += offset_copy; - } - - if doc.is_empty() { - return DocHeaders { - safety: false, - errors: false, - }; - } - - let parser = pulldown_cmark::Parser::new(&doc).into_offset_iter(); - // Iterate over all `Events` and combine consecutive events into one - let events = parser.coalesce(|previous, current| { - use pulldown_cmark::Event::Text; - - let previous_range = previous.1; - let current_range = current.1; - - match (previous.0, current.0) { - (Text(previous), Text(current)) => { - let mut previous = previous.to_string(); - previous.push_str(¤t); - Ok((Text(previous.into()), previous_range)) - }, - (previous, current) => Err(((previous, previous_range), (current, current_range))), - } - }); - check_doc(cx, valid_idents, events, &spans) -} - -const RUST_CODE: &[&str] = &["rust", "no_run", "should_panic", "compile_fail"]; - -fn check_doc<'a, Events: Iterator, Range)>>( - cx: &LateContext<'_>, - valid_idents: &FxHashSet, - events: Events, - spans: &[(usize, Span)], -) -> DocHeaders { - // true if a safety header was found - use pulldown_cmark::CodeBlockKind; - use pulldown_cmark::Event::{ - Code, End, FootnoteReference, HardBreak, Html, Rule, SoftBreak, Start, TaskListMarker, Text, - }; - use pulldown_cmark::Tag::{CodeBlock, Heading, Link}; - - let mut headers = DocHeaders { - safety: false, - errors: false, - }; - let mut in_code = false; - let mut in_link = None; - let mut in_heading = false; - let mut is_rust = false; - let mut edition = None; - for (event, range) in events { - match event { - Start(CodeBlock(ref kind)) => { - in_code = true; - if let CodeBlockKind::Fenced(lang) = kind { - for item in lang.split(',') { - if item == "ignore" { - is_rust = false; - break; - } - if let Some(stripped) = item.strip_prefix("edition") { - is_rust = true; - edition = stripped.parse::().ok(); - } else if item.is_empty() || RUST_CODE.contains(&item) { - is_rust = true; - } - } - } - }, - End(CodeBlock(_)) => { - in_code = false; - is_rust = false; - }, - Start(Link(_, url, _)) => in_link = Some(url), - End(Link(..)) => in_link = None, - Start(Heading(_)) => in_heading = true, - End(Heading(_)) => in_heading = false, - Start(_tag) | End(_tag) => (), // We don't care about other tags - Html(_html) => (), // HTML is weird, just ignore it - SoftBreak | HardBreak | TaskListMarker(_) | Code(_) | Rule => (), - FootnoteReference(text) | Text(text) => { - if Some(&text) == in_link.as_ref() { - // Probably a link of the form `` - // Which are represented as a link to "http://example.com" with - // text "http://example.com" by pulldown-cmark - continue; - } - headers.safety |= in_heading && text.trim() == "Safety"; - headers.errors |= in_heading && text.trim() == "Errors"; - let index = match spans.binary_search_by(|c| c.0.cmp(&range.start)) { - Ok(o) => o, - Err(e) => e - 1, - }; - let (begin, span) = spans[index]; - if in_code { - if is_rust { - let edition = edition.unwrap_or_else(|| cx.tcx.sess.edition()); - check_code(cx, &text, edition, span); - } - } else { - // Adjust for the beginning of the current `Event` - let span = span.with_lo(span.lo() + BytePos::from_usize(range.start - begin)); - - check_text(cx, valid_idents, &text, span); - } - }, - } - } - headers -} - -fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { - fn has_needless_main(code: &str, edition: Edition) -> bool { - rustc_driver::catch_fatal_errors(|| { - rustc_span::with_session_globals(edition, || { - let filename = FileName::anon_source_code(code); - - let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let emitter = EmitterWriter::new(box io::sink(), None, false, false, false, None, false); - 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()) { - Ok(p) => p, - Err(errs) => { - for mut err in errs { - err.cancel(); - } - return false; - }, - }; - - let mut relevant_main_found = false; - loop { - match parser.parse_item() { - Ok(Some(item)) => match &item.kind { - // Tests with one of these items are ignored - ItemKind::Static(..) - | ItemKind::Const(..) - | ItemKind::ExternCrate(..) - | ItemKind::ForeignMod(..) => return false, - // We found a main function ... - ItemKind::Fn(_, sig, _, Some(block)) if item.ident.name == sym::main => { - let is_async = matches!(sig.header.asyncness, Async::Yes { .. }); - let returns_nothing = match &sig.decl.output { - FnRetTy::Default(..) => true, - FnRetTy::Ty(ty) if ty.kind.is_unit() => true, - _ => false, - }; - - if returns_nothing && !is_async && !block.stmts.is_empty() { - // This main function should be linted, but only if there are no other functions - relevant_main_found = true; - } else { - // This main function should not be linted, we're done - return false; - } - }, - // Another function was found; this case is ignored too - ItemKind::Fn(..) => return false, - _ => {}, - }, - Ok(None) => break, - Err(mut e) => { - e.cancel(); - return false; - }, - } - } - - relevant_main_found - }) - }) - .ok() - .unwrap_or_default() - } - - if has_needless_main(text, edition) { - span_lint(cx, NEEDLESS_DOCTEST_MAIN, span, "needless `fn main` in doctest"); - } -} - -fn check_text(cx: &LateContext<'_>, valid_idents: &FxHashSet, text: &str, span: Span) { - for word in text.split(|c: char| c.is_whitespace() || c == '\'') { - // Trim punctuation as in `some comment (see foo::bar).` - // ^^ - // Or even as in `_foo bar_` which is emphasized. - let word = word.trim_matches(|c: char| !c.is_alphanumeric()); - - if valid_idents.contains(word) { - continue; - } - - // Adjust for the current word - let offset = word.as_ptr() as usize - text.as_ptr() as usize; - let span = Span::new( - span.lo() + BytePos::from_usize(offset), - span.lo() + BytePos::from_usize(offset + word.len()), - span.ctxt(), - ); - - check_word(cx, word, span); - } -} - -fn check_word(cx: &LateContext<'_>, word: &str, span: Span) { - /// Checks if a string is camel-case, i.e., contains at least two uppercase - /// letters (`Clippy` is ok) and one lower-case letter (`NASA` is ok). - /// Plurals are also excluded (`IDs` is ok). - fn is_camel_case(s: &str) -> bool { - if s.starts_with(|c: char| c.is_digit(10)) { - return false; - } - - let s = s.strip_suffix('s').unwrap_or(s); - - s.chars().all(char::is_alphanumeric) - && s.chars().filter(|&c| c.is_uppercase()).take(2).count() > 1 - && s.chars().filter(|&c| c.is_lowercase()).take(1).count() > 0 - } - - fn has_underscore(s: &str) -> bool { - s != "_" && !s.contains("\\_") && s.contains('_') - } - - fn has_hyphen(s: &str) -> bool { - s != "-" && s.contains('-') - } - - if let Ok(url) = Url::parse(word) { - // try to get around the fact that `foo::bar` parses as a valid URL - if !url.cannot_be_a_base() { - span_lint( - cx, - DOC_MARKDOWN, - span, - "you should put bare URLs between `<`/`>` or make a proper Markdown link", - ); - - return; - } - } - - // We assume that mixed-case words are not meant to be put inside bacticks. (Issue #2343) - if has_underscore(word) && has_hyphen(word) { - return; - } - - if has_underscore(word) || word.contains("::") || is_camel_case(word) { - span_lint( - cx, - DOC_MARKDOWN, - span, - &format!("you should put `{}` between ticks in the documentation", word), - ); - } -} diff --git a/clippy_lints/src/double_comparison.rs b/clippy_lints/src/double_comparison.rs deleted file mode 100644 index 19f56195ec1b..000000000000 --- a/clippy_lints/src/double_comparison.rs +++ /dev/null @@ -1,94 +0,0 @@ -//! Lint on unnecessary double comparisons. Some examples: - -use rustc_errors::Applicability; -use rustc_hir::{BinOpKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; - -use crate::utils::{eq_expr_value, snippet_with_applicability, span_lint_and_sugg}; - -declare_clippy_lint! { - /// **What it does:** Checks for double comparisons that could be simplified to a single expression. - /// - /// - /// **Why is this bad?** Readability. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let x = 1; - /// # let y = 2; - /// if x == y || x < y {} - /// ``` - /// - /// Could be written as: - /// - /// ```rust - /// # let x = 1; - /// # let y = 2; - /// if x <= y {} - /// ``` - pub DOUBLE_COMPARISONS, - complexity, - "unnecessary double comparisons that can be simplified" -} - -declare_lint_pass!(DoubleComparisons => [DOUBLE_COMPARISONS]); - -impl<'tcx> DoubleComparisons { - #[allow(clippy::similar_names)] - fn check_binop(cx: &LateContext<'tcx>, op: BinOpKind, lhs: &'tcx Expr<'_>, rhs: &'tcx Expr<'_>, span: Span) { - let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (&lhs.kind, &rhs.kind) { - (ExprKind::Binary(lb, llhs, lrhs), ExprKind::Binary(rb, rlhs, rrhs)) => { - (lb.node, llhs, lrhs, rb.node, rlhs, rrhs) - }, - _ => return, - }; - if !(eq_expr_value(cx, &llhs, &rlhs) && eq_expr_value(cx, &lrhs, &rrhs)) { - return; - } - macro_rules! lint_double_comparison { - ($op:tt) => {{ - let mut applicability = Applicability::MachineApplicable; - let lhs_str = snippet_with_applicability(cx, llhs.span, "", &mut applicability); - let rhs_str = snippet_with_applicability(cx, lrhs.span, "", &mut applicability); - let sugg = format!("{} {} {}", lhs_str, stringify!($op), rhs_str); - span_lint_and_sugg( - cx, - DOUBLE_COMPARISONS, - span, - "this binary expression can be simplified", - "try", - sugg, - applicability, - ); - }}; - } - #[rustfmt::skip] - match (op, lkind, rkind) { - (BinOpKind::Or, BinOpKind::Eq, BinOpKind::Lt) | (BinOpKind::Or, BinOpKind::Lt, BinOpKind::Eq) => { - lint_double_comparison!(<=) - }, - (BinOpKind::Or, BinOpKind::Eq, BinOpKind::Gt) | (BinOpKind::Or, BinOpKind::Gt, BinOpKind::Eq) => { - lint_double_comparison!(>=) - }, - (BinOpKind::Or, BinOpKind::Lt, BinOpKind::Gt) | (BinOpKind::Or, BinOpKind::Gt, BinOpKind::Lt) => { - lint_double_comparison!(!=) - }, - (BinOpKind::And, BinOpKind::Le, BinOpKind::Ge) | (BinOpKind::And, BinOpKind::Ge, BinOpKind::Le) => { - lint_double_comparison!(==) - }, - _ => (), - }; - } -} - -impl<'tcx> LateLintPass<'tcx> for DoubleComparisons { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = expr.kind { - Self::check_binop(cx, kind.node, lhs, rhs, expr.span); - } - } -} diff --git a/clippy_lints/src/double_parens.rs b/clippy_lints/src/double_parens.rs deleted file mode 100644 index abbcaf43f415..000000000000 --- a/clippy_lints/src/double_parens.rs +++ /dev/null @@ -1,76 +0,0 @@ -use crate::utils::span_lint; -use rustc_ast::ast::{Expr, ExprKind}; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for unnecessary double parentheses. - /// - /// **Why is this bad?** This makes code harder to read and might indicate a - /// mistake. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// // Bad - /// fn simple_double_parens() -> i32 { - /// ((0)) - /// } - /// - /// // Good - /// fn simple_no_parens() -> i32 { - /// 0 - /// } - /// - /// // or - /// - /// # fn foo(bar: usize) {} - /// // Bad - /// foo((0)); - /// - /// // Good - /// foo(0); - /// ``` - pub DOUBLE_PARENS, - complexity, - "Warn on unnecessary double parentheses" -} - -declare_lint_pass!(DoubleParens => [DOUBLE_PARENS]); - -impl EarlyLintPass for DoubleParens { - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - if expr.span.from_expansion() { - return; - } - - let msg: &str = "consider removing unnecessary double parentheses"; - - match expr.kind { - ExprKind::Paren(ref in_paren) => match in_paren.kind { - ExprKind::Paren(_) | ExprKind::Tup(_) => { - span_lint(cx, DOUBLE_PARENS, expr.span, &msg); - }, - _ => {}, - }, - ExprKind::Call(_, ref params) => { - if params.len() == 1 { - let param = ¶ms[0]; - if let ExprKind::Paren(_) = param.kind { - span_lint(cx, DOUBLE_PARENS, param.span, &msg); - } - } - }, - ExprKind::MethodCall(_, ref params, _) => { - if params.len() == 2 { - let param = ¶ms[1]; - if let ExprKind::Paren(_) = param.kind { - span_lint(cx, DOUBLE_PARENS, param.span, &msg); - } - } - }, - _ => {}, - } - } -} diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs deleted file mode 100644 index cf528d189b4b..000000000000 --- a/clippy_lints/src/drop_forget_ref.rs +++ /dev/null @@ -1,160 +0,0 @@ -use crate::utils::{is_copy, match_def_path, paths, qpath_res, span_lint_and_note}; -use if_chain::if_chain; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for calls to `std::mem::drop` with a reference - /// instead of an owned value. - /// - /// **Why is this bad?** Calling `drop` on a reference will only drop the - /// reference itself, which is a no-op. It will not call the `drop` method (from - /// the `Drop` trait implementation) on the underlying referenced value, which - /// is likely what was intended. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// let mut lock_guard = mutex.lock(); - /// std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex - /// // still locked - /// operation_that_requires_mutex_to_be_unlocked(); - /// ``` - pub DROP_REF, - correctness, - "calls to `std::mem::drop` with a reference instead of an owned value" -} - -declare_clippy_lint! { - /// **What it does:** Checks for calls to `std::mem::forget` with a reference - /// instead of an owned value. - /// - /// **Why is this bad?** Calling `forget` on a reference will only forget the - /// reference itself, which is a no-op. It will not forget the underlying - /// referenced - /// value, which is likely what was intended. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let x = Box::new(1); - /// std::mem::forget(&x) // Should have been forget(x), x will still be dropped - /// ``` - pub FORGET_REF, - correctness, - "calls to `std::mem::forget` with a reference instead of an owned value" -} - -declare_clippy_lint! { - /// **What it does:** Checks for calls to `std::mem::drop` with a value - /// that derives the Copy trait - /// - /// **Why is this bad?** Calling `std::mem::drop` [does nothing for types that - /// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html), since the - /// value will be copied and moved into the function on invocation. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let x: i32 = 42; // i32 implements Copy - /// std::mem::drop(x) // A copy of x is passed to the function, leaving the - /// // original unaffected - /// ``` - pub DROP_COPY, - correctness, - "calls to `std::mem::drop` with a value that implements Copy" -} - -declare_clippy_lint! { - /// **What it does:** Checks for calls to `std::mem::forget` with a value that - /// derives the Copy trait - /// - /// **Why is this bad?** Calling `std::mem::forget` [does nothing for types that - /// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the - /// value will be copied and moved into the function on invocation. - /// - /// An alternative, but also valid, explanation is that Copy types do not - /// implement - /// the Drop trait, which means they have no destructors. Without a destructor, - /// there - /// is nothing for `std::mem::forget` to ignore. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let x: i32 = 42; // i32 implements Copy - /// std::mem::forget(x) // A copy of x is passed to the function, leaving the - /// // original unaffected - /// ``` - pub FORGET_COPY, - correctness, - "calls to `std::mem::forget` with a value that implements Copy" -} - -const DROP_REF_SUMMARY: &str = "calls to `std::mem::drop` with a reference instead of an owned value. \ - Dropping a reference does nothing."; -const FORGET_REF_SUMMARY: &str = "calls to `std::mem::forget` with a reference instead of an owned value. \ - Forgetting a reference does nothing."; -const DROP_COPY_SUMMARY: &str = "calls to `std::mem::drop` with a value that implements `Copy`. \ - Dropping a copy leaves the original intact."; -const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements `Copy`. \ - Forgetting a copy leaves the original intact."; - -declare_lint_pass!(DropForgetRef => [DROP_REF, FORGET_REF, DROP_COPY, FORGET_COPY]); - -impl<'tcx> LateLintPass<'tcx> for DropForgetRef { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if_chain! { - if let ExprKind::Call(ref path, ref args) = expr.kind; - if let ExprKind::Path(ref qpath) = path.kind; - if args.len() == 1; - if let Some(def_id) = qpath_res(cx, qpath, path.hir_id).opt_def_id(); - then { - let lint; - let msg; - let arg = &args[0]; - let arg_ty = cx.typeck_results().expr_ty(arg); - - if let ty::Ref(..) = arg_ty.kind() { - if match_def_path(cx, def_id, &paths::DROP) { - lint = DROP_REF; - msg = DROP_REF_SUMMARY.to_string(); - } else if match_def_path(cx, def_id, &paths::MEM_FORGET) { - lint = FORGET_REF; - msg = FORGET_REF_SUMMARY.to_string(); - } else { - return; - } - span_lint_and_note(cx, - lint, - expr.span, - &msg, - Some(arg.span), - &format!("argument has type `{}`", arg_ty)); - } else if is_copy(cx, arg_ty) { - if match_def_path(cx, def_id, &paths::DROP) { - lint = DROP_COPY; - msg = DROP_COPY_SUMMARY.to_string(); - } else if match_def_path(cx, def_id, &paths::MEM_FORGET) { - lint = FORGET_COPY; - msg = FORGET_COPY_SUMMARY.to_string(); - } else { - return; - } - span_lint_and_note(cx, - lint, - expr.span, - &msg, - Some(arg.span), - &format!("argument has type {}", arg_ty)); - } - } - } - } -} diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs deleted file mode 100644 index c0529a34cc41..000000000000 --- a/clippy_lints/src/duration_subsec.rs +++ /dev/null @@ -1,71 +0,0 @@ -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{BinOpKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Spanned; - -use crate::consts::{constant, Constant}; -use crate::utils::paths; -use crate::utils::{match_type, snippet_with_applicability, span_lint_and_sugg}; - -declare_clippy_lint! { - /// **What it does:** Checks for calculation of subsecond microseconds or milliseconds - /// from other `Duration` methods. - /// - /// **Why is this bad?** It's more concise to call `Duration::subsec_micros()` or - /// `Duration::subsec_millis()` than to calculate them. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # use std::time::Duration; - /// let dur = Duration::new(5, 0); - /// - /// // Bad - /// let _micros = dur.subsec_nanos() / 1_000; - /// let _millis = dur.subsec_nanos() / 1_000_000; - /// - /// // Good - /// let _micros = dur.subsec_micros(); - /// let _millis = dur.subsec_millis(); - /// ``` - pub DURATION_SUBSEC, - complexity, - "checks for calculation of subsecond microseconds or milliseconds" -} - -declare_lint_pass!(DurationSubsec => [DURATION_SUBSEC]); - -impl<'tcx> LateLintPass<'tcx> for DurationSubsec { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if_chain! { - if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, ref left, ref right) = expr.kind; - if let ExprKind::MethodCall(ref method_path, _ , ref args, _) = left.kind; - if match_type(cx, cx.typeck_results().expr_ty(&args[0]).peel_refs(), &paths::DURATION); - if let Some((Constant::Int(divisor), _)) = constant(cx, cx.typeck_results(), right); - then { - let suggested_fn = match (method_path.ident.as_str().as_ref(), divisor) { - ("subsec_micros", 1_000) | ("subsec_nanos", 1_000_000) => "subsec_millis", - ("subsec_nanos", 1_000) => "subsec_micros", - _ => return, - }; - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - DURATION_SUBSEC, - expr.span, - &format!("calling `{}()` is more concise than this calculation", suggested_fn), - "try", - format!( - "{}.{}()", - snippet_with_applicability(cx, args[0].span, "_", &mut applicability), - suggested_fn - ), - applicability, - ); - } - } - } -} diff --git a/clippy_lints/src/else_if_without_else.rs b/clippy_lints/src/else_if_without_else.rs deleted file mode 100644 index 95123e6ff6fe..000000000000 --- a/clippy_lints/src/else_if_without_else.rs +++ /dev/null @@ -1,72 +0,0 @@ -//! Lint on if expressions with an else if, but without a final else branch. - -use rustc_ast::ast::{Expr, ExprKind}; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -use crate::utils::span_lint_and_help; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of if expressions with an `else if` branch, - /// but without a final `else` branch. - /// - /// **Why is this bad?** Some coding guidelines require this (e.g., MISRA-C:2004 Rule 14.10). - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # fn a() {} - /// # fn b() {} - /// # let x: i32 = 1; - /// if x.is_positive() { - /// a(); - /// } else if x.is_negative() { - /// b(); - /// } - /// ``` - /// - /// Could be written: - /// - /// ```rust - /// # fn a() {} - /// # fn b() {} - /// # let x: i32 = 1; - /// if x.is_positive() { - /// a(); - /// } else if x.is_negative() { - /// b(); - /// } else { - /// // We don't care about zero. - /// } - /// ``` - pub ELSE_IF_WITHOUT_ELSE, - restriction, - "`if` expression with an `else if`, but without a final `else` branch" -} - -declare_lint_pass!(ElseIfWithoutElse => [ELSE_IF_WITHOUT_ELSE]); - -impl EarlyLintPass for ElseIfWithoutElse { - fn check_expr(&mut self, cx: &EarlyContext<'_>, mut item: &Expr) { - if in_external_macro(cx.sess(), item.span) { - return; - } - - while let ExprKind::If(_, _, Some(ref els)) = item.kind { - if let ExprKind::If(_, _, None) = els.kind { - span_lint_and_help( - cx, - ELSE_IF_WITHOUT_ELSE, - els.span, - "`if` expression with an `else if`, but without a final `else`", - None, - "add an `else` block here", - ); - } - - item = els; - } - } -} diff --git a/clippy_lints/src/empty_enum.rs b/clippy_lints/src/empty_enum.rs deleted file mode 100644 index a249117d182f..000000000000 --- a/clippy_lints/src/empty_enum.rs +++ /dev/null @@ -1,60 +0,0 @@ -//! lint when there is an enum with no variants - -use crate::utils::span_lint_and_help; -use rustc_hir::{Item, ItemKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for `enum`s with no variants. - /// - /// **Why is this bad?** If you want to introduce a type which - /// can't be instantiated, you should use `!` (the never type), - /// or a wrapper around it, because `!` has more extensive - /// compiler support (type inference, etc...) and wrappers - /// around it are the conventional way to define an uninhabited type. - /// For further information visit [never type documentation](https://doc.rust-lang.org/std/primitive.never.html) - /// - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// Bad: - /// ```rust - /// enum Test {} - /// ``` - /// - /// Good: - /// ```rust - /// #![feature(never_type)] - /// - /// struct Test(!); - /// ``` - pub EMPTY_ENUM, - pedantic, - "enum with no variants" -} - -declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]); - -impl<'tcx> LateLintPass<'tcx> for EmptyEnum { - fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { - let did = cx.tcx.hir().local_def_id(item.hir_id); - if let ItemKind::Enum(..) = item.kind { - let ty = cx.tcx.type_of(did); - let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); - if adt.variants.is_empty() { - span_lint_and_help( - cx, - EMPTY_ENUM, - item.span, - "enum with no variants", - None, - "consider using the uninhabited type `!` (never type) or a wrapper \ - around it to introduce a type which can't be instantiated", - ); - } - } - } -} diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs deleted file mode 100644 index 35a5d00f4aa5..000000000000 --- a/clippy_lints/src/entry.rs +++ /dev/null @@ -1,184 +0,0 @@ -use crate::utils::SpanlessEq; -use crate::utils::{get_item_name, higher, is_type_diagnostic_item, match_type, paths, snippet, snippet_opt}; -use crate::utils::{snippet_with_applicability, span_lint_and_then}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; -use rustc_hir::{BorrowKind, Expr, ExprKind, UnOp}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for uses of `contains_key` + `insert` on `HashMap` - /// or `BTreeMap`. - /// - /// **Why is this bad?** Using `entry` is more efficient. - /// - /// **Known problems:** Some false negatives, eg.: - /// ```rust - /// # use std::collections::HashMap; - /// # let mut map = HashMap::new(); - /// # let v = 1; - /// # let k = 1; - /// if !map.contains_key(&k) { - /// map.insert(k.clone(), v); - /// } - /// ``` - /// - /// **Example:** - /// ```rust - /// # use std::collections::HashMap; - /// # let mut map = HashMap::new(); - /// # let k = 1; - /// # let v = 1; - /// if !map.contains_key(&k) { - /// map.insert(k, v); - /// } - /// ``` - /// can both be rewritten as: - /// ```rust - /// # use std::collections::HashMap; - /// # let mut map = HashMap::new(); - /// # let k = 1; - /// # let v = 1; - /// map.entry(k).or_insert(v); - /// ``` - pub MAP_ENTRY, - perf, - "use of `contains_key` followed by `insert` on a `HashMap` or `BTreeMap`" -} - -declare_lint_pass!(HashMapPass => [MAP_ENTRY]); - -impl<'tcx> LateLintPass<'tcx> for HashMapPass { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let Some((ref check, ref then_block, ref else_block)) = higher::if_block(&expr) { - if let ExprKind::Unary(UnOp::UnNot, ref check) = check.kind { - if let Some((ty, map, key)) = check_cond(cx, check) { - // in case of `if !m.contains_key(&k) { m.insert(k, v); }` - // we can give a better error message - let sole_expr = { - else_block.is_none() - && if let ExprKind::Block(ref then_block, _) = then_block.kind { - (then_block.expr.is_some() as usize) + then_block.stmts.len() == 1 - } else { - true - } - // XXXManishearth we can also check for if/else blocks containing `None`. - }; - - let mut visitor = InsertVisitor { - cx, - span: expr.span, - ty, - map, - key, - sole_expr, - }; - - walk_expr(&mut visitor, &**then_block); - } - } else if let Some(ref else_block) = *else_block { - if let Some((ty, map, key)) = check_cond(cx, check) { - let mut visitor = InsertVisitor { - cx, - span: expr.span, - ty, - map, - key, - sole_expr: false, - }; - - walk_expr(&mut visitor, else_block); - } - } - } - } -} - -fn check_cond<'a>(cx: &LateContext<'_>, check: &'a Expr<'a>) -> Option<(&'static str, &'a Expr<'a>, &'a Expr<'a>)> { - if_chain! { - if let ExprKind::MethodCall(ref path, _, ref params, _) = check.kind; - if params.len() >= 2; - if path.ident.name == sym!(contains_key); - if let ExprKind::AddrOf(BorrowKind::Ref, _, ref key) = params[1].kind; - then { - let map = ¶ms[0]; - let obj_ty = cx.typeck_results().expr_ty(map).peel_refs(); - - return if match_type(cx, obj_ty, &paths::BTREEMAP) { - Some(("BTreeMap", map, key)) - } - else if is_type_diagnostic_item(cx, obj_ty, sym!(hashmap_type)) { - Some(("HashMap", map, key)) - } - else { - None - }; - } - } - - None -} - -struct InsertVisitor<'a, 'tcx, 'b> { - cx: &'a LateContext<'tcx>, - span: Span, - ty: &'static str, - map: &'b Expr<'b>, - key: &'b Expr<'b>, - sole_expr: bool, -} - -impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if_chain! { - if let ExprKind::MethodCall(ref path, _, ref params, _) = expr.kind; - if params.len() == 3; - if path.ident.name == sym!(insert); - if get_item_name(self.cx, self.map) == get_item_name(self.cx, ¶ms[0]); - if SpanlessEq::new(self.cx).eq_expr(self.key, ¶ms[1]); - if snippet_opt(self.cx, self.map.span) == snippet_opt(self.cx, params[0].span); - then { - span_lint_and_then(self.cx, MAP_ENTRY, self.span, - &format!("usage of `contains_key` followed by `insert` on a `{}`", self.ty), |diag| { - if self.sole_expr { - let mut app = Applicability::MachineApplicable; - let help = format!("{}.entry({}).or_insert({});", - snippet_with_applicability(self.cx, self.map.span, "map", &mut app), - snippet_with_applicability(self.cx, params[1].span, "..", &mut app), - snippet_with_applicability(self.cx, params[2].span, "..", &mut app)); - - diag.span_suggestion( - self.span, - "consider using", - help, - Applicability::MachineApplicable, // snippet - ); - } - else { - let help = format!("consider using `{}.entry({})`", - snippet(self.cx, self.map.span, "map"), - snippet(self.cx, params[1].span, "..")); - - diag.span_label( - self.span, - &help, - ); - } - }); - } - } - - if !self.sole_expr { - walk_expr(self, expr); - } - } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs deleted file mode 100644 index fb80f48a9ccf..000000000000 --- a/clippy_lints/src/enum_clike.rs +++ /dev/null @@ -1,82 +0,0 @@ -//! lint on C-like enums that are `repr(isize/usize)` and have values that -//! don't fit into an `i32` - -use crate::consts::{miri_to_const, Constant}; -use crate::utils::span_lint; -use rustc_ast::ast::{IntTy, UintTy}; -use rustc_hir::{Item, ItemKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_middle::ty::util::IntTypeExt; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use std::convert::TryFrom; - -declare_clippy_lint! { - /// **What it does:** Checks for C-like enumerations that are - /// `repr(isize/usize)` and have values that don't fit into an `i32`. - /// - /// **Why is this bad?** This will truncate the variant value on 32 bit - /// architectures, but works fine on 64 bit. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # #[cfg(target_pointer_width = "64")] - /// #[repr(usize)] - /// enum NonPortable { - /// X = 0x1_0000_0000, - /// Y = 0, - /// } - /// ``` - pub ENUM_CLIKE_UNPORTABLE_VARIANT, - correctness, - "C-like enums that are `repr(isize/usize)` and have values that don't fit into an `i32`" -} - -declare_lint_pass!(UnportableVariant => [ENUM_CLIKE_UNPORTABLE_VARIANT]); - -impl<'tcx> LateLintPass<'tcx> for UnportableVariant { - #[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::cast_sign_loss)] - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if cx.tcx.data_layout.pointer_size.bits() != 64 { - return; - } - if let ItemKind::Enum(def, _) = &item.kind { - for var in def.variants { - if let Some(anon_const) = &var.disr_expr { - let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body); - let mut ty = cx.tcx.type_of(def_id.to_def_id()); - let constant = cx - .tcx - .const_eval_poly(def_id.to_def_id()) - .ok() - .map(|val| rustc_middle::ty::Const::from_value(cx.tcx, val, ty)); - if let Some(Constant::Int(val)) = constant.and_then(miri_to_const) { - if let ty::Adt(adt, _) = ty.kind() { - if adt.is_enum() { - ty = adt.repr.discr_type().to_ty(cx.tcx); - } - } - match ty.kind() { - ty::Int(IntTy::Isize) => { - let val = ((val as i128) << 64) >> 64; - if i32::try_from(val).is_ok() { - continue; - } - }, - ty::Uint(UintTy::Usize) if val > u128::from(u32::MAX) => {}, - _ => continue, - } - span_lint( - cx, - ENUM_CLIKE_UNPORTABLE_VARIANT, - var.span, - "C-like enum variant discriminant is not portable to 32-bit targets", - ); - }; - } - } - } - } -} diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs deleted file mode 100644 index 67a463538568..000000000000 --- a/clippy_lints/src/enum_variants.rs +++ /dev/null @@ -1,327 +0,0 @@ -//! lint on enum variants that are prefixed or suffixed by the same characters - -use crate::utils::{camel_case, is_present_in_source}; -use crate::utils::{span_lint, span_lint_and_help}; -use rustc_ast::ast::{EnumDef, Item, ItemKind, VisibilityKind}; -use rustc_lint::{EarlyContext, EarlyLintPass, Lint}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; -use rustc_span::symbol::Symbol; - -declare_clippy_lint! { - /// **What it does:** Detects enumeration variants that are prefixed or suffixed - /// by the same characters. - /// - /// **Why is this bad?** Enumeration variant names should specify their variant, - /// not repeat the enumeration name. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// enum Cake { - /// BlackForestCake, - /// HummingbirdCake, - /// BattenbergCake, - /// } - /// ``` - /// Could be written as: - /// ```rust - /// enum Cake { - /// BlackForest, - /// Hummingbird, - /// Battenberg, - /// } - /// ``` - pub ENUM_VARIANT_NAMES, - style, - "enums where all variants share a prefix/postfix" -} - -declare_clippy_lint! { - /// **What it does:** Detects public enumeration variants that are - /// prefixed or suffixed by the same characters. - /// - /// **Why is this bad?** Public enumeration variant names should specify their variant, - /// not repeat the enumeration name. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// pub enum Cake { - /// BlackForestCake, - /// HummingbirdCake, - /// BattenbergCake, - /// } - /// ``` - /// Could be written as: - /// ```rust - /// pub enum Cake { - /// BlackForest, - /// Hummingbird, - /// Battenberg, - /// } - /// ``` - pub PUB_ENUM_VARIANT_NAMES, - pedantic, - "public enums where all variants share a prefix/postfix" -} - -declare_clippy_lint! { - /// **What it does:** Detects type names that are prefixed or suffixed by the - /// containing module's name. - /// - /// **Why is this bad?** It requires the user to type the module name twice. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// mod cake { - /// struct BlackForestCake; - /// } - /// ``` - /// Could be written as: - /// ```rust - /// mod cake { - /// struct BlackForest; - /// } - /// ``` - pub MODULE_NAME_REPETITIONS, - pedantic, - "type names prefixed/postfixed with their containing module's name" -} - -declare_clippy_lint! { - /// **What it does:** Checks for modules that have the same name as their - /// parent module - /// - /// **Why is this bad?** A typical beginner mistake is to have `mod foo;` and - /// again `mod foo { .. - /// }` in `foo.rs`. - /// The expectation is that items inside the inner `mod foo { .. }` are then - /// available - /// through `foo::x`, but they are only available through - /// `foo::foo::x`. - /// If this is done on purpose, it would be better to choose a more - /// representative module name. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// // lib.rs - /// mod foo; - /// // foo.rs - /// mod foo { - /// ... - /// } - /// ``` - pub MODULE_INCEPTION, - style, - "modules that have the same name as their parent module" -} - -pub struct EnumVariantNames { - modules: Vec<(Symbol, String)>, - threshold: u64, -} - -impl EnumVariantNames { - #[must_use] - pub fn new(threshold: u64) -> Self { - Self { - modules: Vec::new(), - threshold, - } - } -} - -impl_lint_pass!(EnumVariantNames => [ - ENUM_VARIANT_NAMES, - PUB_ENUM_VARIANT_NAMES, - MODULE_NAME_REPETITIONS, - MODULE_INCEPTION -]); - -/// Returns the number of chars that match from the start -#[must_use] -fn partial_match(pre: &str, name: &str) -> usize { - let mut name_iter = name.chars(); - let _ = name_iter.next_back(); // make sure the name is never fully matched - pre.chars().zip(name_iter).take_while(|&(l, r)| l == r).count() -} - -/// Returns the number of chars that match from the end -#[must_use] -fn partial_rmatch(post: &str, name: &str) -> usize { - let mut name_iter = name.chars(); - let _ = name_iter.next(); // make sure the name is never fully matched - post.chars() - .rev() - .zip(name_iter.rev()) - .take_while(|&(l, r)| l == r) - .count() -} - -fn check_variant( - cx: &EarlyContext<'_>, - threshold: u64, - def: &EnumDef, - item_name: &str, - item_name_chars: usize, - span: Span, - lint: &'static Lint, -) { - if (def.variants.len() as u64) < threshold { - return; - } - for var in &def.variants { - let name = var.ident.name.as_str(); - if partial_match(item_name, &name) == item_name_chars - && name.chars().nth(item_name_chars).map_or(false, |c| !c.is_lowercase()) - && name.chars().nth(item_name_chars + 1).map_or(false, |c| !c.is_numeric()) - { - span_lint(cx, lint, var.span, "variant name starts with the enum's name"); - } - if partial_rmatch(item_name, &name) == item_name_chars { - span_lint(cx, lint, var.span, "variant name ends with the enum's name"); - } - } - let first = &def.variants[0].ident.name.as_str(); - let mut pre = &first[..camel_case::until(&*first)]; - let mut post = &first[camel_case::from(&*first)..]; - for var in &def.variants { - let name = var.ident.name.as_str(); - - let pre_match = partial_match(pre, &name); - pre = &pre[..pre_match]; - let pre_camel = camel_case::until(pre); - pre = &pre[..pre_camel]; - while let Some((next, last)) = name[pre.len()..].chars().zip(pre.chars().rev()).next() { - if next.is_numeric() { - return; - } - if next.is_lowercase() { - let last = pre.len() - last.len_utf8(); - let last_camel = camel_case::until(&pre[..last]); - pre = &pre[..last_camel]; - } else { - break; - } - } - - let post_match = partial_rmatch(post, &name); - let post_end = post.len() - post_match; - post = &post[post_end..]; - let post_camel = camel_case::from(post); - post = &post[post_camel..]; - } - let (what, value) = match (pre.is_empty(), post.is_empty()) { - (true, true) => return, - (false, _) => ("pre", pre), - (true, false) => ("post", post), - }; - span_lint_and_help( - cx, - lint, - span, - &format!("all variants have the same {}fix: `{}`", what, value), - None, - &format!( - "remove the {}fixes and use full paths to \ - the variants instead of glob imports", - what - ), - ); -} - -#[must_use] -fn to_camel_case(item_name: &str) -> String { - let mut s = String::new(); - let mut up = true; - for c in item_name.chars() { - if c.is_uppercase() { - // we only turn snake case text into CamelCase - return item_name.to_string(); - } - if c == '_' { - up = true; - continue; - } - if up { - up = false; - s.extend(c.to_uppercase()); - } else { - s.push(c); - } - } - s -} - -impl EarlyLintPass for EnumVariantNames { - fn check_item_post(&mut self, _cx: &EarlyContext<'_>, _item: &Item) { - let last = self.modules.pop(); - assert!(last.is_some()); - } - - #[allow(clippy::similar_names)] - fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { - let item_name = item.ident.name.as_str(); - let item_name_chars = item_name.chars().count(); - let item_camel = to_camel_case(&item_name); - if !item.span.from_expansion() && is_present_in_source(cx, item.span) { - if let Some(&(ref mod_name, ref mod_camel)) = self.modules.last() { - // constants don't have surrounding modules - if !mod_camel.is_empty() { - if mod_name == &item.ident.name { - if let ItemKind::Mod(..) = item.kind { - span_lint( - cx, - MODULE_INCEPTION, - item.span, - "module has the same name as its containing module", - ); - } - } - if item.vis.kind.is_pub() { - let matching = partial_match(mod_camel, &item_camel); - let rmatching = partial_rmatch(mod_camel, &item_camel); - let nchars = mod_camel.chars().count(); - - let is_word_beginning = |c: char| c == '_' || c.is_uppercase() || c.is_numeric(); - - if matching == nchars { - match item_camel.chars().nth(nchars) { - Some(c) if is_word_beginning(c) => span_lint( - cx, - MODULE_NAME_REPETITIONS, - item.span, - "item name starts with its containing module's name", - ), - _ => (), - } - } - if rmatching == nchars { - span_lint( - cx, - MODULE_NAME_REPETITIONS, - item.span, - "item name ends with its containing module's name", - ); - } - } - } - } - } - if let ItemKind::Enum(ref def, _) = item.kind { - let lint = match item.vis.kind { - VisibilityKind::Public => PUB_ENUM_VARIANT_NAMES, - _ => ENUM_VARIANT_NAMES, - }; - check_variant(cx, self.threshold, def, &item_name, item_name_chars, item.span, lint); - } - self.modules.push((item.ident.name, item_camel)); - } -} diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs deleted file mode 100644 index 6308f6e2e7e9..000000000000 --- a/clippy_lints/src/eq_op.rs +++ /dev/null @@ -1,247 +0,0 @@ -use crate::utils::{ - ast_utils::is_useless_with_eq_exprs, eq_expr_value, higher, implements_trait, in_macro, is_copy, is_expn_of, - multispan_sugg, snippet, span_lint, span_lint_and_then, -}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, StmtKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for equal operands to comparison, logical and - /// bitwise, difference and division binary operators (`==`, `>`, etc., `&&`, - /// `||`, `&`, `|`, `^`, `-` and `/`). - /// - /// **Why is this bad?** This is usually just a typo or a copy and paste error. - /// - /// **Known problems:** False negatives: We had some false positives regarding - /// calls (notably [racer](https://github.com/phildawes/racer) had one instance - /// of `x.pop() && x.pop()`), so we removed matching any function or method - /// calls. We may introduce a list of known pure functions in the future. - /// - /// **Example:** - /// ```rust - /// # let x = 1; - /// if x + 1 == x + 1 {} - /// ``` - /// or - /// ```rust - /// # let a = 3; - /// # let b = 4; - /// assert_eq!(a, a); - /// ``` - pub EQ_OP, - correctness, - "equal operands on both sides of a comparison or bitwise combination (e.g., `x == x`)" -} - -declare_clippy_lint! { - /// **What it does:** Checks for arguments to `==` which have their address - /// taken to satisfy a bound - /// and suggests to dereference the other argument instead - /// - /// **Why is this bad?** It is more idiomatic to dereference the other argument. - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```ignore - /// // Bad - /// &x == y - /// - /// // Good - /// x == *y - /// ``` - pub OP_REF, - style, - "taking a reference to satisfy the type constraints on `==`" -} - -declare_lint_pass!(EqOp => [EQ_OP, OP_REF]); - -const ASSERT_MACRO_NAMES: [&str; 4] = ["assert_eq", "assert_ne", "debug_assert_eq", "debug_assert_ne"]; - -impl<'tcx> LateLintPass<'tcx> for EqOp { - #[allow(clippy::similar_names, clippy::too_many_lines)] - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if let ExprKind::Block(ref block, _) = e.kind { - for stmt in block.stmts { - for amn in &ASSERT_MACRO_NAMES { - if_chain! { - if is_expn_of(stmt.span, amn).is_some(); - if let StmtKind::Semi(ref matchexpr) = stmt.kind; - if let Some(macro_args) = higher::extract_assert_macro_args(matchexpr); - if macro_args.len() == 2; - let (lhs, rhs) = (macro_args[0], macro_args[1]); - if eq_expr_value(cx, lhs, rhs); - - then { - span_lint( - cx, - EQ_OP, - lhs.span.to(rhs.span), - &format!("identical args used in this `{}!` macro call", amn), - ); - } - } - } - } - } - if let ExprKind::Binary(op, ref left, ref right) = e.kind { - if e.span.from_expansion() { - return; - } - let macro_with_not_op = |expr_kind: &ExprKind<'_>| { - if let ExprKind::Unary(_, ref expr) = *expr_kind { - in_macro(expr.span) - } else { - false - } - }; - if macro_with_not_op(&left.kind) || macro_with_not_op(&right.kind) { - return; - } - if is_useless_with_eq_exprs(higher::binop(op.node)) && eq_expr_value(cx, left, right) { - span_lint( - cx, - EQ_OP, - e.span, - &format!("equal expressions as operands to `{}`", op.node.as_str()), - ); - return; - } - let (trait_id, requires_ref) = match op.node { - BinOpKind::Add => (cx.tcx.lang_items().add_trait(), false), - BinOpKind::Sub => (cx.tcx.lang_items().sub_trait(), false), - BinOpKind::Mul => (cx.tcx.lang_items().mul_trait(), false), - BinOpKind::Div => (cx.tcx.lang_items().div_trait(), false), - BinOpKind::Rem => (cx.tcx.lang_items().rem_trait(), false), - // don't lint short circuiting ops - BinOpKind::And | BinOpKind::Or => return, - BinOpKind::BitXor => (cx.tcx.lang_items().bitxor_trait(), false), - BinOpKind::BitAnd => (cx.tcx.lang_items().bitand_trait(), false), - BinOpKind::BitOr => (cx.tcx.lang_items().bitor_trait(), false), - BinOpKind::Shl => (cx.tcx.lang_items().shl_trait(), false), - BinOpKind::Shr => (cx.tcx.lang_items().shr_trait(), false), - BinOpKind::Ne | BinOpKind::Eq => (cx.tcx.lang_items().eq_trait(), true), - BinOpKind::Lt | BinOpKind::Le | BinOpKind::Ge | BinOpKind::Gt => { - (cx.tcx.lang_items().partial_ord_trait(), true) - }, - }; - if let Some(trait_id) = trait_id { - #[allow(clippy::match_same_arms)] - match (&left.kind, &right.kind) { - // do not suggest to dereference literals - (&ExprKind::Lit(..), _) | (_, &ExprKind::Lit(..)) => {}, - // &foo == &bar - (&ExprKind::AddrOf(BorrowKind::Ref, _, ref l), &ExprKind::AddrOf(BorrowKind::Ref, _, ref r)) => { - let lty = cx.typeck_results().expr_ty(l); - let rty = cx.typeck_results().expr_ty(r); - let lcpy = is_copy(cx, lty); - let rcpy = is_copy(cx, rty); - // either operator autorefs or both args are copyable - if (requires_ref || (lcpy && rcpy)) && implements_trait(cx, lty, trait_id, &[rty.into()]) { - span_lint_and_then( - cx, - OP_REF, - e.span, - "needlessly taken reference of both operands", - |diag| { - let lsnip = snippet(cx, l.span, "...").to_string(); - let rsnip = snippet(cx, r.span, "...").to_string(); - multispan_sugg( - diag, - "use the values directly", - vec![(left.span, lsnip), (right.span, rsnip)], - ); - }, - ) - } else if lcpy - && !rcpy - && implements_trait(cx, lty, trait_id, &[cx.typeck_results().expr_ty(right).into()]) - { - span_lint_and_then( - cx, - OP_REF, - e.span, - "needlessly taken reference of left operand", - |diag| { - let lsnip = snippet(cx, l.span, "...").to_string(); - diag.span_suggestion( - left.span, - "use the left value directly", - lsnip, - Applicability::MaybeIncorrect, // FIXME #2597 - ); - }, - ) - } else if !lcpy - && rcpy - && implements_trait(cx, cx.typeck_results().expr_ty(left), trait_id, &[rty.into()]) - { - span_lint_and_then( - cx, - OP_REF, - e.span, - "needlessly taken reference of right operand", - |diag| { - let rsnip = snippet(cx, r.span, "...").to_string(); - diag.span_suggestion( - right.span, - "use the right value directly", - rsnip, - Applicability::MaybeIncorrect, // FIXME #2597 - ); - }, - ) - } - }, - // &foo == bar - (&ExprKind::AddrOf(BorrowKind::Ref, _, ref l), _) => { - let lty = cx.typeck_results().expr_ty(l); - let lcpy = is_copy(cx, lty); - if (requires_ref || lcpy) - && implements_trait(cx, lty, trait_id, &[cx.typeck_results().expr_ty(right).into()]) - { - span_lint_and_then( - cx, - OP_REF, - e.span, - "needlessly taken reference of left operand", - |diag| { - let lsnip = snippet(cx, l.span, "...").to_string(); - diag.span_suggestion( - left.span, - "use the left value directly", - lsnip, - Applicability::MaybeIncorrect, // FIXME #2597 - ); - }, - ) - } - }, - // foo == &bar - (_, &ExprKind::AddrOf(BorrowKind::Ref, _, ref r)) => { - let rty = cx.typeck_results().expr_ty(r); - let rcpy = is_copy(cx, rty); - if (requires_ref || rcpy) - && implements_trait(cx, cx.typeck_results().expr_ty(left), trait_id, &[rty.into()]) - { - span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |diag| { - let rsnip = snippet(cx, r.span, "...").to_string(); - diag.span_suggestion( - right.span, - "use the right value directly", - rsnip, - Applicability::MaybeIncorrect, // FIXME #2597 - ); - }) - } - }, - _ => {}, - } - } - } - } -} diff --git a/clippy_lints/src/erasing_op.rs b/clippy_lints/src/erasing_op.rs deleted file mode 100644 index dbd1ff514f0e..000000000000 --- a/clippy_lints/src/erasing_op.rs +++ /dev/null @@ -1,59 +0,0 @@ -use rustc_hir::{BinOpKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; - -use crate::consts::{constant_simple, Constant}; -use crate::utils::span_lint; - -declare_clippy_lint! { - /// **What it does:** Checks for erasing operations, e.g., `x * 0`. - /// - /// **Why is this bad?** The whole expression can be replaced by zero. - /// This is most likely not the intended outcome and should probably be - /// corrected - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let x = 1; - /// 0 / x; - /// 0 * x; - /// x & 0; - /// ``` - pub ERASING_OP, - correctness, - "using erasing operations, e.g., `x * 0` or `y & 0`" -} - -declare_lint_pass!(ErasingOp => [ERASING_OP]); - -impl<'tcx> LateLintPass<'tcx> for ErasingOp { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if e.span.from_expansion() { - return; - } - if let ExprKind::Binary(ref cmp, ref left, ref right) = e.kind { - match cmp.node { - BinOpKind::Mul | BinOpKind::BitAnd => { - check(cx, left, e.span); - check(cx, right, e.span); - }, - BinOpKind::Div => check(cx, left, e.span), - _ => (), - } - } - } -} - -fn check(cx: &LateContext<'_>, e: &Expr<'_>, span: Span) { - if let Some(Constant::Int(0)) = constant_simple(cx, cx.typeck_results(), e) { - span_lint( - cx, - ERASING_OP, - span, - "this operation will always return zero. This is likely not the intended outcome", - ); - } -} diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs deleted file mode 100644 index d2dcb3e5c464..000000000000 --- a/clippy_lints/src/escape.rs +++ /dev/null @@ -1,174 +0,0 @@ -use rustc_hir::intravisit; -use rustc_hir::{self, Body, FnDecl, HirId, HirIdSet, ItemKind, Node}; -use rustc_infer::infer::TyCtxtInferExt; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, Ty}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; -use rustc_target::abi::LayoutOf; -use rustc_target::spec::abi::Abi; -use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; - -use crate::utils::span_lint; - -#[derive(Copy, Clone)] -pub struct BoxedLocal { - pub too_large_for_stack: u64, -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `Box` where an unboxed `T` would - /// work fine. - /// - /// **Why is this bad?** This is an unnecessary allocation, and bad for - /// performance. It is only necessary to allocate if you wish to move the box - /// into something. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # fn foo(bar: usize) {} - /// // Bad - /// let x = Box::new(1); - /// foo(*x); - /// println!("{}", *x); - /// - /// // Good - /// let x = 1; - /// foo(x); - /// println!("{}", x); - /// ``` - pub BOXED_LOCAL, - perf, - "using `Box` where unnecessary" -} - -fn is_non_trait_box(ty: Ty<'_>) -> bool { - ty.is_box() && !ty.boxed_ty().is_trait() -} - -struct EscapeDelegate<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - set: HirIdSet, - too_large_for_stack: u64, -} - -impl_lint_pass!(BoxedLocal => [BOXED_LOCAL]); - -impl<'tcx> LateLintPass<'tcx> for BoxedLocal { - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - fn_kind: intravisit::FnKind<'tcx>, - _: &'tcx FnDecl<'_>, - body: &'tcx Body<'_>, - _: Span, - hir_id: HirId, - ) { - if let Some(header) = fn_kind.header() { - if header.abi != Abi::Rust { - return; - } - } - - // If the method is an impl for a trait, don't warn. - let parent_id = cx.tcx.hir().get_parent_item(hir_id); - let parent_node = cx.tcx.hir().find(parent_id); - - if let Some(Node::Item(item)) = parent_node { - if let ItemKind::Impl { of_trait: Some(_), .. } = item.kind { - return; - } - } - - let mut v = EscapeDelegate { - cx, - set: HirIdSet::default(), - too_large_for_stack: self.too_large_for_stack, - }; - - let fn_def_id = cx.tcx.hir().local_def_id(hir_id); - cx.tcx.infer_ctxt().enter(|infcx| { - ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body); - }); - - for node in v.set { - span_lint( - cx, - BOXED_LOCAL, - cx.tcx.hir().span(node), - "local variable doesn't need to be boxed here", - ); - } - } -} - -// TODO: Replace with Map::is_argument(..) when it's fixed -fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool { - match map.find(id) { - Some(Node::Binding(_)) => (), - _ => return false, - } - - matches!(map.find(map.get_parent_node(id)), Some(Node::Param(_))) -} - -impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { - fn consume(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, mode: ConsumeMode) { - if cmt.place.projections.is_empty() { - if let PlaceBase::Local(lid) = cmt.place.base { - if let ConsumeMode::Move = mode { - // moved out or in. clearly can't be localized - self.set.remove(&lid); - } - let map = &self.cx.tcx.hir(); - if let Some(Node::Binding(_)) = map.find(cmt.hir_id) { - if self.set.contains(&lid) { - // let y = x where x is known - // remove x, insert y - self.set.insert(cmt.hir_id); - self.set.remove(&lid); - } - } - } - } - } - - fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) { - if cmt.place.projections.is_empty() { - if let PlaceBase::Local(lid) = cmt.place.base { - self.set.remove(&lid); - } - } - } - - fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) { - if cmt.place.projections.is_empty() { - let map = &self.cx.tcx.hir(); - if is_argument(*map, cmt.hir_id) { - // Skip closure arguments - let parent_id = map.get_parent_node(cmt.hir_id); - if let Some(Node::Expr(..)) = map.find(map.get_parent_node(parent_id)) { - return; - } - - if is_non_trait_box(cmt.place.ty()) && !self.is_large_box(cmt.place.ty()) { - self.set.insert(cmt.hir_id); - } - return; - } - } - } -} - -impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> { - fn is_large_box(&self, ty: Ty<'tcx>) -> bool { - // Large types need to be boxed to avoid stack overflows. - if ty.is_box() { - self.cx.layout_of(ty.boxed_ty()).map_or(0, |l| l.size.bytes()) > self.too_large_for_stack - } else { - false - } - } -} diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs deleted file mode 100644 index 53df3abbf543..000000000000 --- a/clippy_lints/src/eta_reduction.rs +++ /dev/null @@ -1,228 +0,0 @@ -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_session::{declare_lint_pass, declare_tool_lint}; - -use crate::utils::{ - implements_trait, is_adjusted, iter_input_pats, snippet_opt, span_lint_and_sugg, span_lint_and_then, - type_is_unsafe_function, -}; - -declare_clippy_lint! { - /// **What it does:** Checks for closures which just call another function where - /// the function can be called directly. `unsafe` functions or calls where types - /// get adjusted are ignored. - /// - /// **Why is this bad?** Needlessly creating a closure adds code for no benefit - /// and gives the optimizer more work. - /// - /// **Known problems:** If creating the closure inside the closure has a side- - /// effect then moving the closure creation out will change when that side- - /// effect runs. - /// See rust-lang/rust-clippy#1439 for more details. - /// - /// **Example:** - /// ```rust,ignore - /// // Bad - /// xs.map(|x| foo(x)) - /// - /// // Good - /// xs.map(foo) - /// ``` - /// where `foo(_)` is a plain function that takes the exact argument type of - /// `x`. - pub REDUNDANT_CLOSURE, - style, - "redundant closures, i.e., `|a| foo(a)` (which can be written as just `foo`)" -} - -declare_clippy_lint! { - /// **What it does:** Checks for closures which only invoke a method on the closure - /// argument and can be replaced by referencing the method directly. - /// - /// **Why is this bad?** It's unnecessary to create the closure. - /// - /// **Known problems:** rust-lang/rust-clippy#3071, rust-lang/rust-clippy#4002, - /// rust-lang/rust-clippy#3942 - /// - /// - /// **Example:** - /// ```rust,ignore - /// Some('a').map(|s| s.to_uppercase()); - /// ``` - /// may be rewritten as - /// ```rust,ignore - /// Some('a').map(char::to_uppercase); - /// ``` - pub REDUNDANT_CLOSURE_FOR_METHOD_CALLS, - pedantic, - "redundant closures for method calls" -} - -declare_lint_pass!(EtaReduction => [REDUNDANT_CLOSURE, REDUNDANT_CLOSURE_FOR_METHOD_CALLS]); - -impl<'tcx> LateLintPass<'tcx> for EtaReduction { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if in_external_macro(cx.sess(), expr.span) { - return; - } - - match expr.kind { - ExprKind::Call(_, args) | ExprKind::MethodCall(_, _, args, _) => { - for arg in args { - check_closure(cx, arg) - } - }, - _ => (), - } - } -} - -fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) { - if let ExprKind::Closure(_, ref decl, eid, _, _) = expr.kind { - let body = cx.tcx.hir().body(eid); - let ex = &body.value; - - if_chain!( - if let ExprKind::Call(ref caller, ref args) = ex.kind; - - if let ExprKind::Path(_) = caller.kind; - - // Not the same number of arguments, there is no way the closure is the same as the function return; - if args.len() == decl.inputs.len(); - - // Are the expression or the arguments type-adjusted? Then we need the closure - if !(is_adjusted(cx, ex) || args.iter().any(|arg| is_adjusted(cx, arg))); - - let fn_ty = cx.typeck_results().expr_ty(caller); - - if matches!(fn_ty.kind(), ty::FnDef(_, _) | ty::FnPtr(_) | ty::Closure(_, _)); - - if !type_is_unsafe_function(cx, fn_ty); - - if compare_inputs(&mut iter_input_pats(decl, body), &mut args.iter()); - - then { - span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |diag| { - if let Some(snippet) = snippet_opt(cx, caller.span) { - diag.span_suggestion( - expr.span, - "remove closure as shown", - snippet, - Applicability::MachineApplicable, - ); - } - }); - } - ); - - if_chain!( - if let ExprKind::MethodCall(ref path, _, ref args, _) = ex.kind; - - // Not the same number of arguments, there is no way the closure is the same as the function return; - if args.len() == decl.inputs.len(); - - // Are the expression or the arguments type-adjusted? Then we need the closure - if !(is_adjusted(cx, ex) || args.iter().skip(1).any(|arg| is_adjusted(cx, arg))); - - let method_def_id = cx.typeck_results().type_dependent_def_id(ex.hir_id).unwrap(); - if !type_is_unsafe_function(cx, cx.tcx.type_of(method_def_id)); - - if compare_inputs(&mut iter_input_pats(decl, body), &mut args.iter()); - - if let Some(name) = get_ufcs_type_name(cx, method_def_id, &args[0]); - - then { - span_lint_and_sugg( - cx, - REDUNDANT_CLOSURE_FOR_METHOD_CALLS, - expr.span, - "redundant closure found", - "remove closure as shown", - format!("{}::{}", name, path.ident.name), - Applicability::MachineApplicable, - ); - } - ); - } -} - -/// Tries to determine the type for universal function call to be used instead of the closure -fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: def_id::DefId, self_arg: &Expr<'_>) -> Option { - let expected_type_of_self = &cx.tcx.fn_sig(method_def_id).inputs_and_output().skip_binder()[0]; - let actual_type_of_self = &cx.typeck_results().node_type(self_arg.hir_id); - - if let Some(trait_id) = cx.tcx.trait_of_item(method_def_id) { - if match_borrow_depth(expected_type_of_self, &actual_type_of_self) - && implements_trait(cx, actual_type_of_self, trait_id, &[]) - { - return Some(cx.tcx.def_path_str(trait_id)); - } - } - - cx.tcx.impl_of_method(method_def_id).and_then(|_| { - //a type may implicitly implement other type's methods (e.g. Deref) - if match_types(expected_type_of_self, &actual_type_of_self) { - return Some(get_type_name(cx, &actual_type_of_self)); - } - None - }) -} - -fn match_borrow_depth(lhs: Ty<'_>, rhs: Ty<'_>) -> bool { - match (&lhs.kind(), &rhs.kind()) { - (ty::Ref(_, t1, mut1), ty::Ref(_, t2, mut2)) => mut1 == mut2 && match_borrow_depth(&t1, &t2), - (l, r) => !matches!((l, r), (ty::Ref(_, _, _), _) | (_, ty::Ref(_, _, _))), - } -} - -fn match_types(lhs: Ty<'_>, rhs: Ty<'_>) -> bool { - match (&lhs.kind(), &rhs.kind()) { - (ty::Bool, ty::Bool) - | (ty::Char, ty::Char) - | (ty::Int(_), ty::Int(_)) - | (ty::Uint(_), ty::Uint(_)) - | (ty::Str, ty::Str) => true, - (ty::Ref(_, t1, mut1), ty::Ref(_, t2, mut2)) => mut1 == mut2 && match_types(t1, t2), - (ty::Array(t1, _), ty::Array(t2, _)) | (ty::Slice(t1), ty::Slice(t2)) => match_types(t1, t2), - (ty::Adt(def1, _), ty::Adt(def2, _)) => def1 == def2, - (_, _) => false, - } -} - -fn get_type_name(cx: &LateContext<'_>, ty: Ty<'_>) -> String { - match ty.kind() { - ty::Adt(t, _) => cx.tcx.def_path_str(t.did), - ty::Ref(_, r, _) => get_type_name(cx, &r), - _ => ty.to_string(), - } -} - -fn compare_inputs( - closure_inputs: &mut dyn Iterator>, - call_args: &mut dyn Iterator>, -) -> bool { - for (closure_input, function_arg) in closure_inputs.zip(call_args) { - if let PatKind::Binding(_, _, ident, _) = closure_input.pat.kind { - // XXXManishearth Should I be checking the binding mode here? - if let ExprKind::Path(QPath::Resolved(None, ref p)) = function_arg.kind { - if p.segments.len() != 1 { - // If it's a proper path, it can't be a local variable - return false; - } - if p.segments[0].ident.name != ident.name { - // The two idents should be the same - return false; - } - } else { - return false; - } - } else { - return false; - } - } - true -} diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs deleted file mode 100644 index bc2b2904698c..000000000000 --- a/clippy_lints/src/eval_order_dependence.rs +++ /dev/null @@ -1,364 +0,0 @@ -use crate::utils::{get_parent_expr, span_lint, span_lint_and_note}; -use if_chain::if_chain; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; -use rustc_hir::{def, BinOpKind, Block, Expr, ExprKind, Guard, HirId, Local, Node, QPath, Stmt, StmtKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for a read and a write to the same variable where - /// whether the read occurs before or after the write depends on the evaluation - /// order of sub-expressions. - /// - /// **Why is this bad?** It is often confusing to read. In addition, the - /// sub-expression evaluation order for Rust is not well documented. - /// - /// **Known problems:** Code which intentionally depends on the evaluation - /// order, or which is correct for any evaluation order. - /// - /// **Example:** - /// ```rust - /// let mut x = 0; - /// - /// // Bad - /// let a = { - /// x = 1; - /// 1 - /// } + x; - /// // Unclear whether a is 1 or 2. - /// - /// // Good - /// let tmp = { - /// x = 1; - /// 1 - /// }; - /// let a = tmp + x; - /// ``` - pub EVAL_ORDER_DEPENDENCE, - complexity, - "whether a variable read occurs before a write depends on sub-expression evaluation order" -} - -declare_clippy_lint! { - /// **What it does:** Checks for diverging calls that are not match arms or - /// statements. - /// - /// **Why is this bad?** It is often confusing to read. In addition, the - /// sub-expression evaluation order for Rust is not well documented. - /// - /// **Known problems:** Someone might want to use `some_bool || panic!()` as a - /// shorthand. - /// - /// **Example:** - /// ```rust,no_run - /// # fn b() -> bool { true } - /// # fn c() -> bool { true } - /// let a = b() || panic!() || c(); - /// // `c()` is dead, `panic!()` is only called if `b()` returns `false` - /// let x = (a, b, c, panic!()); - /// // can simply be replaced by `panic!()` - /// ``` - pub DIVERGING_SUB_EXPRESSION, - complexity, - "whether an expression contains a diverging sub expression" -} - -declare_lint_pass!(EvalOrderDependence => [EVAL_ORDER_DEPENDENCE, DIVERGING_SUB_EXPRESSION]); - -impl<'tcx> LateLintPass<'tcx> for EvalOrderDependence { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - // Find a write to a local variable. - match expr.kind { - ExprKind::Assign(ref lhs, ..) | ExprKind::AssignOp(_, ref lhs, _) => { - if let ExprKind::Path(ref qpath) = lhs.kind { - if let QPath::Resolved(_, ref path) = *qpath { - if path.segments.len() == 1 { - if let def::Res::Local(var) = cx.qpath_res(qpath, lhs.hir_id) { - let mut visitor = ReadVisitor { - cx, - var, - write_expr: expr, - last_expr: expr, - }; - check_for_unsequenced_reads(&mut visitor); - } - } - } - } - }, - _ => {}, - } - } - fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { - match stmt.kind { - StmtKind::Local(ref local) => { - if let Local { init: Some(ref e), .. } = **local { - DivergenceVisitor { cx }.visit_expr(e); - } - }, - StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => DivergenceVisitor { cx }.maybe_walk_expr(e), - StmtKind::Item(..) => {}, - } - } -} - -struct DivergenceVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, -} - -impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> { - fn maybe_walk_expr(&mut self, e: &'tcx Expr<'_>) { - match e.kind { - ExprKind::Closure(..) => {}, - ExprKind::Match(ref e, arms, _) => { - self.visit_expr(e); - for arm in arms { - if let Some(Guard::If(if_expr)) = arm.guard { - self.visit_expr(if_expr) - } - // make sure top level arm expressions aren't linted - self.maybe_walk_expr(&*arm.body); - } - }, - _ => walk_expr(self, e), - } - } - fn report_diverging_sub_expr(&mut self, e: &Expr<'_>) { - span_lint(self.cx, DIVERGING_SUB_EXPRESSION, e.span, "sub-expression diverges"); - } -} - -impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, e: &'tcx Expr<'_>) { - match e.kind { - ExprKind::Continue(_) | ExprKind::Break(_, _) | ExprKind::Ret(_) => self.report_diverging_sub_expr(e), - ExprKind::Call(ref func, _) => { - let typ = self.cx.typeck_results().expr_ty(func); - match typ.kind() { - ty::FnDef(..) | ty::FnPtr(_) => { - let sig = typ.fn_sig(self.cx.tcx); - if let ty::Never = self.cx.tcx.erase_late_bound_regions(sig).output().kind() { - self.report_diverging_sub_expr(e); - } - }, - _ => {}, - } - }, - ExprKind::MethodCall(..) => { - let borrowed_table = self.cx.typeck_results(); - if borrowed_table.expr_ty(e).is_never() { - self.report_diverging_sub_expr(e); - } - }, - _ => { - // do not lint expressions referencing objects of type `!`, as that required a - // diverging expression - // to begin with - }, - } - self.maybe_walk_expr(e); - } - fn visit_block(&mut self, _: &'tcx Block<'_>) { - // don't continue over blocks, LateLintPass already does that - } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -/// Walks up the AST from the given write expression (`vis.write_expr`) looking -/// for reads to the same variable that are unsequenced relative to the write. -/// -/// This means reads for which there is a common ancestor between the read and -/// the write such that -/// -/// * evaluating the ancestor necessarily evaluates both the read and the write (for example, `&x` -/// and `|| x = 1` don't necessarily evaluate `x`), and -/// -/// * which one is evaluated first depends on the order of sub-expression evaluation. Blocks, `if`s, -/// loops, `match`es, and the short-circuiting logical operators are considered to have a defined -/// evaluation order. -/// -/// When such a read is found, the lint is triggered. -fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) { - let map = &vis.cx.tcx.hir(); - let mut cur_id = vis.write_expr.hir_id; - loop { - let parent_id = map.get_parent_node(cur_id); - if parent_id == cur_id { - break; - } - let parent_node = match map.find(parent_id) { - Some(parent) => parent, - None => break, - }; - - let stop_early = match parent_node { - Node::Expr(expr) => check_expr(vis, expr), - Node::Stmt(stmt) => check_stmt(vis, stmt), - Node::Item(_) => { - // We reached the top of the function, stop. - break; - }, - _ => StopEarly::KeepGoing, - }; - match stop_early { - StopEarly::Stop => break, - StopEarly::KeepGoing => {}, - } - - cur_id = parent_id; - } -} - -/// Whether to stop early for the loop in `check_for_unsequenced_reads`. (If -/// `check_expr` weren't an independent function, this would be unnecessary and -/// we could just use `break`). -enum StopEarly { - KeepGoing, - Stop, -} - -fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr<'_>) -> StopEarly { - if expr.hir_id == vis.last_expr.hir_id { - return StopEarly::KeepGoing; - } - - match expr.kind { - ExprKind::Array(_) - | ExprKind::Tup(_) - | ExprKind::MethodCall(..) - | ExprKind::Call(_, _) - | ExprKind::Assign(..) - | ExprKind::Index(_, _) - | ExprKind::Repeat(_, _) - | ExprKind::Struct(_, _, _) => { - walk_expr(vis, expr); - }, - ExprKind::Binary(op, _, _) | ExprKind::AssignOp(op, _, _) => { - if op.node == BinOpKind::And || op.node == BinOpKind::Or { - // x && y and x || y always evaluate x first, so these are - // strictly sequenced. - } else { - walk_expr(vis, expr); - } - }, - ExprKind::Closure(_, _, _, _, _) => { - // Either - // - // * `var` is defined in the closure body, in which case we've reached the top of the enclosing - // function and can stop, or - // - // * `var` is captured by the closure, in which case, because evaluating a closure does not evaluate - // its body, we don't necessarily have a write, so we need to stop to avoid generating false - // positives. - // - // This is also the only place we need to stop early (grrr). - return StopEarly::Stop; - }, - // All other expressions either have only one child or strictly - // sequence the evaluation order of their sub-expressions. - _ => {}, - } - - vis.last_expr = expr; - - StopEarly::KeepGoing -} - -fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt<'_>) -> StopEarly { - match stmt.kind { - StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => check_expr(vis, expr), - // If the declaration is of a local variable, check its initializer - // expression if it has one. Otherwise, keep going. - StmtKind::Local(ref local) => local - .init - .as_ref() - .map_or(StopEarly::KeepGoing, |expr| check_expr(vis, expr)), - _ => StopEarly::KeepGoing, - } -} - -/// A visitor that looks for reads from a variable. -struct ReadVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - /// The ID of the variable we're looking for. - var: HirId, - /// The expressions where the write to the variable occurred (for reporting - /// in the lint). - write_expr: &'tcx Expr<'tcx>, - /// The last (highest in the AST) expression we've checked, so we know not - /// to recheck it. - last_expr: &'tcx Expr<'tcx>, -} - -impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if expr.hir_id == self.last_expr.hir_id { - return; - } - - match expr.kind { - ExprKind::Path(ref qpath) => { - if_chain! { - if let QPath::Resolved(None, ref path) = *qpath; - if path.segments.len() == 1; - if let def::Res::Local(local_id) = self.cx.qpath_res(qpath, expr.hir_id); - if local_id == self.var; - // Check that this is a read, not a write. - if !is_in_assignment_position(self.cx, expr); - then { - span_lint_and_note( - self.cx, - EVAL_ORDER_DEPENDENCE, - expr.span, - "unsequenced read of a variable", - Some(self.write_expr.span), - "whether read occurs before this write depends on evaluation order" - ); - } - } - } - // We're about to descend a closure. Since we don't know when (or - // if) the closure will be evaluated, any reads in it might not - // occur here (or ever). Like above, bail to avoid false positives. - ExprKind::Closure(_, _, _, _, _) | - - // We want to avoid a false positive when a variable name occurs - // only to have its address taken, so we stop here. Technically, - // this misses some weird cases, eg. - // - // ```rust - // let mut x = 0; - // let a = foo(&{x = 1; x}, x); - // ``` - // - // TODO: fix this - ExprKind::AddrOf(_, _, _) => { - return; - } - _ => {} - } - - walk_expr(self, expr); - } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -/// Returns `true` if `expr` is the LHS of an assignment, like `expr = ...`. -fn is_in_assignment_position(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - if let Some(parent) = get_parent_expr(cx, expr) { - if let ExprKind::Assign(ref lhs, ..) = parent.kind { - return lhs.hir_id == expr.hir_id; - } - } - false -} diff --git a/clippy_lints/src/excessive_bools.rs b/clippy_lints/src/excessive_bools.rs deleted file mode 100644 index 82ca4baacb7a..000000000000 --- a/clippy_lints/src/excessive_bools.rs +++ /dev/null @@ -1,176 +0,0 @@ -use crate::utils::{attr_by_name, in_macro, match_path_ast, span_lint_and_help}; -use rustc_ast::ast::{AssocItemKind, Extern, FnSig, Item, ItemKind, Ty, TyKind}; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::Span; - -use std::convert::TryInto; - -declare_clippy_lint! { - /// **What it does:** Checks for excessive - /// use of bools in structs. - /// - /// **Why is this bad?** Excessive bools in a struct - /// is often a sign that it's used as a state machine, - /// which is much better implemented as an enum. - /// If it's not the case, excessive bools usually benefit - /// from refactoring into two-variant enums for better - /// readability and API. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// Bad: - /// ```rust - /// struct S { - /// is_pending: bool, - /// is_processing: bool, - /// is_finished: bool, - /// } - /// ``` - /// - /// Good: - /// ```rust - /// enum S { - /// Pending, - /// Processing, - /// Finished, - /// } - /// ``` - pub STRUCT_EXCESSIVE_BOOLS, - pedantic, - "using too many bools in a struct" -} - -declare_clippy_lint! { - /// **What it does:** Checks for excessive use of - /// bools in function definitions. - /// - /// **Why is this bad?** Calls to such functions - /// are confusing and error prone, because it's - /// hard to remember argument order and you have - /// no type system support to back you up. Using - /// two-variant enums instead of bools often makes - /// API easier to use. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// Bad: - /// ```rust,ignore - /// fn f(is_round: bool, is_hot: bool) { ... } - /// ``` - /// - /// Good: - /// ```rust,ignore - /// enum Shape { - /// Round, - /// Spiky, - /// } - /// - /// enum Temperature { - /// Hot, - /// IceCold, - /// } - /// - /// fn f(shape: Shape, temperature: Temperature) { ... } - /// ``` - pub FN_PARAMS_EXCESSIVE_BOOLS, - pedantic, - "using too many bools in function parameters" -} - -pub struct ExcessiveBools { - max_struct_bools: u64, - max_fn_params_bools: u64, -} - -impl ExcessiveBools { - #[must_use] - pub fn new(max_struct_bools: u64, max_fn_params_bools: u64) -> Self { - Self { - max_struct_bools, - max_fn_params_bools, - } - } - - fn check_fn_sig(&self, cx: &EarlyContext<'_>, fn_sig: &FnSig, span: Span) { - match fn_sig.header.ext { - Extern::Implicit | Extern::Explicit(_) => return, - Extern::None => (), - } - - let fn_sig_bools = fn_sig - .decl - .inputs - .iter() - .filter(|param| is_bool_ty(¶m.ty)) - .count() - .try_into() - .unwrap(); - if self.max_fn_params_bools < fn_sig_bools { - span_lint_and_help( - cx, - FN_PARAMS_EXCESSIVE_BOOLS, - span, - &format!("more than {} bools in function parameters", self.max_fn_params_bools), - None, - "consider refactoring bools into two-variant enums", - ); - } - } -} - -impl_lint_pass!(ExcessiveBools => [STRUCT_EXCESSIVE_BOOLS, FN_PARAMS_EXCESSIVE_BOOLS]); - -fn is_bool_ty(ty: &Ty) -> bool { - if let TyKind::Path(None, path) = &ty.kind { - return match_path_ast(path, &["bool"]); - } - false -} - -impl EarlyLintPass for ExcessiveBools { - fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { - if in_macro(item.span) { - return; - } - match &item.kind { - ItemKind::Struct(variant_data, _) => { - if attr_by_name(&item.attrs, "repr").is_some() { - return; - } - - let struct_bools = variant_data - .fields() - .iter() - .filter(|field| is_bool_ty(&field.ty)) - .count() - .try_into() - .unwrap(); - if self.max_struct_bools < struct_bools { - span_lint_and_help( - cx, - STRUCT_EXCESSIVE_BOOLS, - item.span, - &format!("more than {} bools in a struct", self.max_struct_bools), - None, - "consider using a state machine or refactoring bools into two-variant enums", - ); - } - }, - ItemKind::Impl { - of_trait: None, items, .. - } - | ItemKind::Trait(_, _, _, _, items) => { - for item in items { - if let AssocItemKind::Fn(_, fn_sig, _, _) = &item.kind { - self.check_fn_sig(cx, fn_sig, item.span); - } - } - }, - ItemKind::Fn(_, fn_sig, _, _) => self.check_fn_sig(cx, fn_sig, item.span), - _ => (), - } - } -} diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs deleted file mode 100644 index 7337d98c8be3..000000000000 --- a/clippy_lints/src/exit.rs +++ /dev/null @@ -1,47 +0,0 @@ -use crate::utils::{is_entrypoint_fn, match_def_path, paths, qpath_res, span_lint}; -use if_chain::if_chain; -use rustc_hir::{Expr, ExprKind, Item, ItemKind, Node}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** `exit()` terminates the program and doesn't provide a - /// stack trace. - /// - /// **Why is this bad?** Ideally a program is terminated by finishing - /// the main function. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// std::process::exit(0) - /// ``` - pub EXIT, - restriction, - "`std::process::exit` is called, terminating the program" -} - -declare_lint_pass!(Exit => [EXIT]); - -impl<'tcx> LateLintPass<'tcx> for Exit { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if_chain! { - if let ExprKind::Call(ref path_expr, ref _args) = e.kind; - if let ExprKind::Path(ref path) = path_expr.kind; - if let Some(def_id) = qpath_res(cx, path, path_expr.hir_id).opt_def_id(); - if match_def_path(cx, def_id, &paths::EXIT); - then { - let parent = cx.tcx.hir().get_parent_item(e.hir_id); - if let Some(Node::Item(Item{kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find(parent) { - // If the next item up is a function we check if it is an entry point - // and only then emit a linter warning - let def_id = cx.tcx.hir().local_def_id(parent); - if !is_entrypoint_fn(cx, def_id.to_def_id()) { - span_lint(cx, EXIT, e.span, "usage of `process::exit`"); - } - } - } - } - } -} diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs deleted file mode 100644 index f8038d06e503..000000000000 --- a/clippy_lints/src/explicit_write.rs +++ /dev/null @@ -1,150 +0,0 @@ -use crate::utils::{is_expn_of, match_function_call, paths, span_lint, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_ast::ast::LitKind; -use rustc_errors::Applicability; -use rustc_hir::{BorrowKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `write!()` / `writeln()!` which can be - /// replaced with `(e)print!()` / `(e)println!()` - /// - /// **Why is this bad?** Using `(e)println! is clearer and more concise - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # use std::io::Write; - /// # let bar = "furchtbar"; - /// // this would be clearer as `eprintln!("foo: {:?}", bar);` - /// writeln!(&mut std::io::stderr(), "foo: {:?}", bar).unwrap(); - /// ``` - pub EXPLICIT_WRITE, - complexity, - "using the `write!()` family of functions instead of the `print!()` family of functions, when using the latter would work" -} - -declare_lint_pass!(ExplicitWrite => [EXPLICIT_WRITE]); - -impl<'tcx> LateLintPass<'tcx> for ExplicitWrite { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if_chain! { - // match call to unwrap - if let ExprKind::MethodCall(ref unwrap_fun, _, ref unwrap_args, _) = expr.kind; - if unwrap_fun.ident.name == sym::unwrap; - // match call to write_fmt - if !unwrap_args.is_empty(); - if let ExprKind::MethodCall(ref write_fun, _, write_args, _) = - unwrap_args[0].kind; - if write_fun.ident.name == sym!(write_fmt); - // match calls to std::io::stdout() / std::io::stderr () - if !write_args.is_empty(); - if let Some(dest_name) = if match_function_call(cx, &write_args[0], &paths::STDOUT).is_some() { - Some("stdout") - } else if match_function_call(cx, &write_args[0], &paths::STDERR).is_some() { - Some("stderr") - } else { - None - }; - then { - let write_span = unwrap_args[0].span; - let calling_macro = - // ordering is important here, since `writeln!` uses `write!` internally - if is_expn_of(write_span, "writeln").is_some() { - Some("writeln") - } else if is_expn_of(write_span, "write").is_some() { - Some("write") - } else { - None - }; - let prefix = if dest_name == "stderr" { - "e" - } else { - "" - }; - - // We need to remove the last trailing newline from the string because the - // underlying `fmt::write` function doesn't know whether `println!` or `print!` was - // used. - if let Some(mut write_output) = write_output_string(write_args) { - if write_output.ends_with('\n') { - write_output.pop(); - } - - if let Some(macro_name) = calling_macro { - span_lint_and_sugg( - cx, - EXPLICIT_WRITE, - expr.span, - &format!( - "use of `{}!({}(), ...).unwrap()`", - macro_name, - dest_name - ), - "try this", - format!("{}{}!(\"{}\")", prefix, macro_name.replace("write", "print"), write_output.escape_default()), - Applicability::MachineApplicable - ); - } else { - span_lint_and_sugg( - cx, - EXPLICIT_WRITE, - expr.span, - &format!("use of `{}().write_fmt(...).unwrap()`", dest_name), - "try this", - format!("{}print!(\"{}\")", prefix, write_output.escape_default()), - Applicability::MachineApplicable - ); - } - } else { - // We don't have a proper suggestion - if let Some(macro_name) = calling_macro { - span_lint( - cx, - EXPLICIT_WRITE, - expr.span, - &format!( - "use of `{}!({}(), ...).unwrap()`. Consider using `{}{}!` instead", - macro_name, - dest_name, - prefix, - macro_name.replace("write", "print") - ) - ); - } else { - span_lint( - cx, - EXPLICIT_WRITE, - expr.span, - &format!("use of `{}().write_fmt(...).unwrap()`. Consider using `{}print!` instead", dest_name, prefix), - ); - } - } - - } - } - } -} - -// Extract the output string from the given `write_args`. -fn write_output_string(write_args: &[Expr<'_>]) -> Option { - if_chain! { - // Obtain the string that should be printed - if write_args.len() > 1; - if let ExprKind::Call(_, ref output_args) = write_args[1].kind; - if !output_args.is_empty(); - if let ExprKind::AddrOf(BorrowKind::Ref, _, ref output_string_expr) = output_args[0].kind; - if let ExprKind::Array(ref string_exprs) = output_string_expr.kind; - // we only want to provide an automatic suggestion for simple (non-format) strings - if string_exprs.len() == 1; - if let ExprKind::Lit(ref lit) = string_exprs[0].kind; - if let LitKind::Str(ref write_output, _) = lit.node; - then { - return Some(write_output.to_string()) - } - } - None -} diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs deleted file mode 100644 index 509a4a4e15f6..000000000000 --- a/clippy_lints/src/fallible_impl_from.rs +++ /dev/null @@ -1,148 +0,0 @@ -use crate::utils::paths::FROM_TRAIT; -use crate::utils::{ - is_expn_of, is_type_diagnostic_item, match_def_path, match_panic_def_id, method_chain_args, span_lint_and_then, -}; -use if_chain::if_chain; -use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::{sym, Span}; - -declare_clippy_lint! { - /// **What it does:** Checks for impls of `From<..>` that contain `panic!()` or `unwrap()` - /// - /// **Why is this bad?** `TryFrom` should be used if there's a possibility of failure. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// struct Foo(i32); - /// - /// // Bad - /// impl From for Foo { - /// fn from(s: String) -> Self { - /// Foo(s.parse().unwrap()) - /// } - /// } - /// ``` - /// - /// ```rust - /// // Good - /// struct Foo(i32); - /// - /// use std::convert::TryFrom; - /// impl TryFrom for Foo { - /// type Error = (); - /// fn try_from(s: String) -> Result { - /// if let Ok(parsed) = s.parse() { - /// Ok(Foo(parsed)) - /// } else { - /// Err(()) - /// } - /// } - /// } - /// ``` - pub FALLIBLE_IMPL_FROM, - nursery, - "Warn on impls of `From<..>` that contain `panic!()` or `unwrap()`" -} - -declare_lint_pass!(FallibleImplFrom => [FALLIBLE_IMPL_FROM]); - -impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom { - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { - // check for `impl From for ..` - let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id); - if_chain! { - if let hir::ItemKind::Impl{ items: impl_items, .. } = item.kind; - if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id); - if match_def_path(cx, impl_trait_ref.def_id, &FROM_TRAIT); - then { - lint_impl_body(cx, item.span, impl_items); - } - } - } -} - -fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[hir::ImplItemRef<'_>]) { - use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; - use rustc_hir::{Expr, ExprKind, ImplItemKind, QPath}; - - struct FindPanicUnwrap<'a, 'tcx> { - lcx: &'a LateContext<'tcx>, - typeck_results: &'tcx ty::TypeckResults<'tcx>, - result: Vec, - } - - impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - // check for `begin_panic` - if_chain! { - if let ExprKind::Call(ref func_expr, _) = expr.kind; - if let ExprKind::Path(QPath::Resolved(_, ref path)) = func_expr.kind; - if let Some(path_def_id) = path.res.opt_def_id(); - if match_panic_def_id(self.lcx, path_def_id); - if is_expn_of(expr.span, "unreachable").is_none(); - then { - self.result.push(expr.span); - } - } - - // check for `unwrap` - if let Some(arglists) = method_chain_args(expr, &["unwrap"]) { - let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); - if is_type_diagnostic_item(self.lcx, reciever_ty, sym::option_type) - || is_type_diagnostic_item(self.lcx, reciever_ty, sym::result_type) - { - self.result.push(expr.span); - } - } - - // and check sub-expressions - intravisit::walk_expr(self, expr); - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } - } - - for impl_item in impl_items { - if_chain! { - if impl_item.ident.name == sym::from; - if let ImplItemKind::Fn(_, body_id) = - cx.tcx.hir().impl_item(impl_item.id).kind; - then { - // check the body for `begin_panic` or `unwrap` - let body = cx.tcx.hir().body(body_id); - let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.id.hir_id); - let mut fpu = FindPanicUnwrap { - lcx: cx, - typeck_results: cx.tcx.typeck(impl_item_def_id), - result: Vec::new(), - }; - fpu.visit_expr(&body.value); - - // if we've found one, lint - if !fpu.result.is_empty() { - span_lint_and_then( - cx, - FALLIBLE_IMPL_FROM, - impl_span, - "consider implementing `TryFrom` instead", - move |diag| { - diag.help( - "`From` is intended for infallible conversions only. \ - Use `TryFrom` if there's a possibility for the conversion to fail."); - diag.span_note(fpu.result, "potential failure(s)"); - }); - } - } - } - } -} diff --git a/clippy_lints/src/float_equality_without_abs.rs b/clippy_lints/src/float_equality_without_abs.rs deleted file mode 100644 index c1c08597ee67..000000000000 --- a/clippy_lints/src/float_equality_without_abs.rs +++ /dev/null @@ -1,112 +0,0 @@ -use crate::utils::{match_def_path, paths, span_lint_and_then, sugg}; -use if_chain::if_chain; -use rustc_ast::util::parser::AssocOp; -use rustc_errors::Applicability; -use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{BinOpKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Spanned; - -declare_clippy_lint! { - /// **What it does:** Checks for statements of the form `(a - b) < f32::EPSILON` or - /// `(a - b) < f64::EPSILON`. Notes the missing `.abs()`. - /// - /// **Why is this bad?** The code without `.abs()` is more likely to have a bug. - /// - /// **Known problems:** If the user can ensure that b is larger than a, the `.abs()` is - /// technically unneccessary. However, it will make the code more robust and doesn't have any - /// large performance implications. If the abs call was deliberately left out for performance - /// reasons, it is probably better to state this explicitly in the code, which then can be done - /// with an allow. - /// - /// **Example:** - /// - /// ```rust - /// pub fn is_roughly_equal(a: f32, b: f32) -> bool { - /// (a - b) < f32::EPSILON - /// } - /// ``` - /// Use instead: - /// ```rust - /// pub fn is_roughly_equal(a: f32, b: f32) -> bool { - /// (a - b).abs() < f32::EPSILON - /// } - /// ``` - pub FLOAT_EQUALITY_WITHOUT_ABS, - correctness, - "float equality check without `.abs()`" -} - -declare_lint_pass!(FloatEqualityWithoutAbs => [FLOAT_EQUALITY_WITHOUT_ABS]); - -impl<'tcx> LateLintPass<'tcx> for FloatEqualityWithoutAbs { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - let lhs; - let rhs; - - // check if expr is a binary expression with a lt or gt operator - if let ExprKind::Binary(op, ref left, ref right) = expr.kind { - match op.node { - BinOpKind::Lt => { - lhs = left; - rhs = right; - }, - BinOpKind::Gt => { - lhs = right; - rhs = left; - }, - _ => return, - }; - } else { - return; - } - - if_chain! { - - // left hand side is a substraction - if let ExprKind::Binary( - Spanned { - node: BinOpKind::Sub, - .. - }, - val_l, - val_r, - ) = lhs.kind; - - // right hand side matches either f32::EPSILON or f64::EPSILON - if let ExprKind::Path(ref epsilon_path) = rhs.kind; - if let Res::Def(DefKind::AssocConst, def_id) = cx.qpath_res(epsilon_path, rhs.hir_id); - if match_def_path(cx, def_id, &paths::F32_EPSILON) || match_def_path(cx, def_id, &paths::F64_EPSILON); - - // values of the substractions on the left hand side are of the type float - let t_val_l = cx.typeck_results().expr_ty(val_l); - let t_val_r = cx.typeck_results().expr_ty(val_r); - if let ty::Float(_) = t_val_l.kind(); - if let ty::Float(_) = t_val_r.kind(); - - then { - let sug_l = sugg::Sugg::hir(cx, &val_l, ".."); - let sug_r = sugg::Sugg::hir(cx, &val_r, ".."); - // format the suggestion - let suggestion = format!("{}.abs()", sugg::make_assoc(AssocOp::Subtract, &sug_l, &sug_r).maybe_par()); - // spans the lint - span_lint_and_then( - cx, - FLOAT_EQUALITY_WITHOUT_ABS, - expr.span, - "float equality check without `.abs()`", - | diag | { - diag.span_suggestion( - lhs.span, - "add `.abs()`", - suggestion, - Applicability::MaybeIncorrect, - ); - } - ); - } - } - } -} diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs deleted file mode 100644 index 1fe4461533b3..000000000000 --- a/clippy_lints/src/float_literal.rs +++ /dev/null @@ -1,182 +0,0 @@ -use crate::utils::{numeric_literal, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_ast::ast::{FloatTy, LitFloatType, LitKind}; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use std::fmt; - -declare_clippy_lint! { - /// **What it does:** Checks for float literals with a precision greater - /// than that supported by the underlying type. - /// - /// **Why is this bad?** Rust will truncate the literal silently. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// // Bad - /// let v: f32 = 0.123_456_789_9; - /// println!("{}", v); // 0.123_456_789 - /// - /// // Good - /// let v: f64 = 0.123_456_789_9; - /// println!("{}", v); // 0.123_456_789_9 - /// ``` - pub EXCESSIVE_PRECISION, - style, - "excessive precision for float literal" -} - -declare_clippy_lint! { - /// **What it does:** Checks for whole number float literals that - /// cannot be represented as the underlying type without loss. - /// - /// **Why is this bad?** Rust will silently lose precision during - /// conversion to a float. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// // Bad - /// let _: f32 = 16_777_217.0; // 16_777_216.0 - /// - /// // Good - /// let _: f32 = 16_777_216.0; - /// let _: f64 = 16_777_217.0; - /// ``` - pub LOSSY_FLOAT_LITERAL, - restriction, - "lossy whole number float literals" -} - -declare_lint_pass!(FloatLiteral => [EXCESSIVE_PRECISION, LOSSY_FLOAT_LITERAL]); - -impl<'tcx> LateLintPass<'tcx> for FloatLiteral { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - if_chain! { - let ty = cx.typeck_results().expr_ty(expr); - if let ty::Float(fty) = *ty.kind(); - if let hir::ExprKind::Lit(ref lit) = expr.kind; - if let LitKind::Float(sym, lit_float_ty) = lit.node; - then { - let sym_str = sym.as_str(); - let formatter = FloatFormat::new(&sym_str); - // Try to bail out if the float is for sure fine. - // If its within the 2 decimal digits of being out of precision we - // check if the parsed representation is the same as the string - // since we'll need the truncated string anyway. - let digits = count_digits(&sym_str); - let max = max_digits(fty); - let type_suffix = match lit_float_ty { - LitFloatType::Suffixed(FloatTy::F32) => Some("f32"), - LitFloatType::Suffixed(FloatTy::F64) => Some("f64"), - LitFloatType::Unsuffixed => None - }; - let (is_whole, mut float_str) = match fty { - FloatTy::F32 => { - let value = sym_str.parse::().unwrap(); - - (value.fract() == 0.0, formatter.format(value)) - }, - FloatTy::F64 => { - let value = sym_str.parse::().unwrap(); - - (value.fract() == 0.0, formatter.format(value)) - }, - }; - - if is_whole && !sym_str.contains(|c| c == 'e' || c == 'E') { - // Normalize the literal by stripping the fractional portion - if sym_str.split('.').next().unwrap() != float_str { - // If the type suffix is missing the suggestion would be - // incorrectly interpreted as an integer so adding a `.0` - // suffix to prevent that. - if type_suffix.is_none() { - float_str.push_str(".0"); - } - - span_lint_and_sugg( - cx, - LOSSY_FLOAT_LITERAL, - expr.span, - "literal cannot be represented as the underlying type without loss of precision", - "consider changing the type or replacing it with", - numeric_literal::format(&float_str, type_suffix, true), - Applicability::MachineApplicable, - ); - } - } else if digits > max as usize && sym_str != float_str { - span_lint_and_sugg( - cx, - EXCESSIVE_PRECISION, - expr.span, - "float has excessive precision", - "consider changing the type or truncating it to", - numeric_literal::format(&float_str, type_suffix, true), - Applicability::MachineApplicable, - ); - } - } - } - } -} - -#[must_use] -fn max_digits(fty: FloatTy) -> u32 { - match fty { - FloatTy::F32 => f32::DIGITS, - FloatTy::F64 => f64::DIGITS, - } -} - -/// Counts the digits excluding leading zeros -#[must_use] -fn count_digits(s: &str) -> usize { - // Note that s does not contain the f32/64 suffix, and underscores have been stripped - s.chars() - .filter(|c| *c != '-' && *c != '.') - .take_while(|c| *c != 'e' && *c != 'E') - .fold(0, |count, c| { - // leading zeros - if c == '0' && count == 0 { - count - } else { - count + 1 - } - }) -} - -enum FloatFormat { - LowerExp, - UpperExp, - Normal, -} -impl FloatFormat { - #[must_use] - fn new(s: &str) -> Self { - s.chars() - .find_map(|x| match x { - 'e' => Some(Self::LowerExp), - 'E' => Some(Self::UpperExp), - _ => None, - }) - .unwrap_or(Self::Normal) - } - fn format(&self, f: T) -> String - where - T: fmt::UpperExp + fmt::LowerExp + fmt::Display, - { - match self { - Self::LowerExp => format!("{:e}", f), - Self::UpperExp => format!("{:E}", f), - Self::Normal => format!("{}", f), - } - } -} diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs deleted file mode 100644 index 18fea8b34bfd..000000000000 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ /dev/null @@ -1,721 +0,0 @@ -use crate::consts::{ - constant, constant_simple, Constant, - Constant::{Int, F32, F64}, -}; -use crate::utils::{eq_expr_value, get_parent_expr, higher, numeric_literal, span_lint_and_sugg, sugg}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{BinOpKind, Expr, ExprKind, PathSegment, UnOp}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Spanned; - -use rustc_ast::ast; -use std::f32::consts as f32_consts; -use std::f64::consts as f64_consts; -use sugg::Sugg; - -declare_clippy_lint! { - /// **What it does:** Looks for floating-point expressions that - /// can be expressed using built-in methods to improve accuracy - /// at the cost of performance. - /// - /// **Why is this bad?** Negatively impacts accuracy. - /// - /// **Known problems:** None - /// - /// **Example:** - /// - /// ```rust - /// let a = 3f32; - /// let _ = a.powf(1.0 / 3.0); - /// let _ = (1.0 + a).ln(); - /// let _ = a.exp() - 1.0; - /// ``` - /// - /// is better expressed as - /// - /// ```rust - /// let a = 3f32; - /// let _ = a.cbrt(); - /// let _ = a.ln_1p(); - /// let _ = a.exp_m1(); - /// ``` - pub IMPRECISE_FLOPS, - nursery, - "usage of imprecise floating point operations" -} - -declare_clippy_lint! { - /// **What it does:** Looks for floating-point expressions that - /// can be expressed using built-in methods to improve both - /// accuracy and performance. - /// - /// **Why is this bad?** Negatively impacts accuracy and performance. - /// - /// **Known problems:** None - /// - /// **Example:** - /// - /// ```rust - /// use std::f32::consts::E; - /// - /// let a = 3f32; - /// let _ = (2f32).powf(a); - /// let _ = E.powf(a); - /// let _ = a.powf(1.0 / 2.0); - /// let _ = a.log(2.0); - /// let _ = a.log(10.0); - /// let _ = a.log(E); - /// let _ = a.powf(2.0); - /// let _ = a * 2.0 + 4.0; - /// let _ = if a < 0.0 { - /// -a - /// } else { - /// a - /// }; - /// let _ = if a < 0.0 { - /// a - /// } else { - /// -a - /// }; - /// ``` - /// - /// is better expressed as - /// - /// ```rust - /// use std::f32::consts::E; - /// - /// let a = 3f32; - /// let _ = a.exp2(); - /// let _ = a.exp(); - /// let _ = a.sqrt(); - /// let _ = a.log2(); - /// let _ = a.log10(); - /// let _ = a.ln(); - /// let _ = a.powi(2); - /// let _ = a.mul_add(2.0, 4.0); - /// let _ = a.abs(); - /// let _ = -a.abs(); - /// ``` - pub SUBOPTIMAL_FLOPS, - nursery, - "usage of sub-optimal floating point operations" -} - -declare_lint_pass!(FloatingPointArithmetic => [ - IMPRECISE_FLOPS, - SUBOPTIMAL_FLOPS -]); - -// Returns the specialized log method for a given base if base is constant -// and is one of 2, 10 and e -fn get_specialized_log_method(cx: &LateContext<'_>, base: &Expr<'_>) -> Option<&'static str> { - if let Some((value, _)) = constant(cx, cx.typeck_results(), base) { - if F32(2.0) == value || F64(2.0) == value { - return Some("log2"); - } else if F32(10.0) == value || F64(10.0) == value { - return Some("log10"); - } else if F32(f32_consts::E) == value || F64(f64_consts::E) == value { - return Some("ln"); - } - } - - None -} - -// Adds type suffixes and parenthesis to method receivers if necessary -fn prepare_receiver_sugg<'a>(cx: &LateContext<'_>, mut expr: &'a Expr<'a>) -> Sugg<'a> { - let mut suggestion = Sugg::hir(cx, expr, ".."); - - if let ExprKind::Unary(UnOp::UnNeg, inner_expr) = &expr.kind { - expr = &inner_expr; - } - - if_chain! { - // if the expression is a float literal and it is unsuffixed then - // add a suffix so the suggestion is valid and unambiguous - if let ty::Float(float_ty) = cx.typeck_results().expr_ty(expr).kind(); - if let ExprKind::Lit(lit) = &expr.kind; - if let ast::LitKind::Float(sym, ast::LitFloatType::Unsuffixed) = lit.node; - then { - let op = format!( - "{}{}{}", - suggestion, - // Check for float literals without numbers following the decimal - // separator such as `2.` and adds a trailing zero - if sym.as_str().ends_with('.') { - "0" - } else { - "" - }, - float_ty.name_str() - ).into(); - - suggestion = match suggestion { - Sugg::MaybeParen(_) => Sugg::MaybeParen(op), - _ => Sugg::NonParen(op) - }; - } - } - - suggestion.maybe_par() -} - -fn check_log_base(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { - if let Some(method) = get_specialized_log_method(cx, &args[1]) { - span_lint_and_sugg( - cx, - SUBOPTIMAL_FLOPS, - expr.span, - "logarithm for bases 2, 10 and e can be computed more accurately", - "consider using", - format!("{}.{}()", Sugg::hir(cx, &args[0], ".."), method), - Applicability::MachineApplicable, - ); - } -} - -// TODO: Lint expressions of the form `(x + y).ln()` where y > 1 and -// suggest usage of `(x + (y - 1)).ln_1p()` instead -fn check_ln1p(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { - if let ExprKind::Binary( - Spanned { - node: BinOpKind::Add, .. - }, - lhs, - rhs, - ) = &args[0].kind - { - let recv = match ( - constant(cx, cx.typeck_results(), lhs), - constant(cx, cx.typeck_results(), rhs), - ) { - (Some((value, _)), _) if F32(1.0) == value || F64(1.0) == value => rhs, - (_, Some((value, _))) if F32(1.0) == value || F64(1.0) == value => lhs, - _ => return, - }; - - span_lint_and_sugg( - cx, - IMPRECISE_FLOPS, - expr.span, - "ln(1 + x) can be computed more accurately", - "consider using", - format!("{}.ln_1p()", prepare_receiver_sugg(cx, recv)), - Applicability::MachineApplicable, - ); - } -} - -// Returns an integer if the float constant is a whole number and it can be -// converted to an integer without loss of precision. For now we only check -// ranges [-16777215, 16777216) for type f32 as whole number floats outside -// this range are lossy and ambiguous. -#[allow(clippy::cast_possible_truncation)] -fn get_integer_from_float_constant(value: &Constant) -> Option { - match value { - F32(num) if num.fract() == 0.0 => { - if (-16_777_215.0..16_777_216.0).contains(num) { - Some(num.round() as i32) - } else { - None - } - }, - F64(num) if num.fract() == 0.0 => { - if (-2_147_483_648.0..2_147_483_648.0).contains(num) { - Some(num.round() as i32) - } else { - None - } - }, - _ => None, - } -} - -fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { - // Check receiver - if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[0]) { - let method = if F32(f32_consts::E) == value || F64(f64_consts::E) == value { - "exp" - } else if F32(2.0) == value || F64(2.0) == value { - "exp2" - } else { - return; - }; - - span_lint_and_sugg( - cx, - SUBOPTIMAL_FLOPS, - expr.span, - "exponent for bases 2 and e can be computed more accurately", - "consider using", - format!("{}.{}()", prepare_receiver_sugg(cx, &args[1]), method), - Applicability::MachineApplicable, - ); - } - - // Check argument - if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[1]) { - let (lint, help, suggestion) = if F32(1.0 / 2.0) == value || F64(1.0 / 2.0) == value { - ( - SUBOPTIMAL_FLOPS, - "square-root of a number can be computed more efficiently and accurately", - format!("{}.sqrt()", Sugg::hir(cx, &args[0], "..")), - ) - } else if F32(1.0 / 3.0) == value || F64(1.0 / 3.0) == value { - ( - IMPRECISE_FLOPS, - "cube-root of a number can be computed more accurately", - format!("{}.cbrt()", Sugg::hir(cx, &args[0], "..")), - ) - } else if let Some(exponent) = get_integer_from_float_constant(&value) { - ( - SUBOPTIMAL_FLOPS, - "exponentiation with integer powers can be computed more efficiently", - format!( - "{}.powi({})", - Sugg::hir(cx, &args[0], ".."), - numeric_literal::format(&exponent.to_string(), None, false) - ), - ) - } else { - return; - }; - - span_lint_and_sugg( - cx, - lint, - expr.span, - help, - "consider using", - suggestion, - Applicability::MachineApplicable, - ); - } -} - -fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { - if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[1]) { - if value == Int(2) { - if let Some(parent) = get_parent_expr(cx, expr) { - if let Some(grandparent) = get_parent_expr(cx, parent) { - if let ExprKind::MethodCall(PathSegment { ident: method_name, .. }, _, args, _) = grandparent.kind { - if method_name.as_str() == "sqrt" && detect_hypot(cx, args).is_some() { - return; - } - } - } - - if let ExprKind::Binary( - Spanned { - node: BinOpKind::Add, .. - }, - ref lhs, - ref rhs, - ) = parent.kind - { - let other_addend = if lhs.hir_id == expr.hir_id { rhs } else { lhs }; - - span_lint_and_sugg( - cx, - SUBOPTIMAL_FLOPS, - parent.span, - "square can be computed more efficiently", - "consider using", - format!( - "{}.mul_add({}, {})", - Sugg::hir(cx, &args[0], ".."), - Sugg::hir(cx, &args[0], ".."), - Sugg::hir(cx, &other_addend, ".."), - ), - Applicability::MachineApplicable, - ); - - return; - } - } - - span_lint_and_sugg( - cx, - SUBOPTIMAL_FLOPS, - expr.span, - "square can be computed more efficiently", - "consider using", - format!("{} * {}", Sugg::hir(cx, &args[0], ".."), Sugg::hir(cx, &args[0], "..")), - Applicability::MachineApplicable, - ); - } - } -} - -fn detect_hypot(cx: &LateContext<'_>, args: &[Expr<'_>]) -> Option { - if let ExprKind::Binary( - Spanned { - node: BinOpKind::Add, .. - }, - ref add_lhs, - ref add_rhs, - ) = args[0].kind - { - // check if expression of the form x * x + y * y - if_chain! { - if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, ref lmul_lhs, ref lmul_rhs) = add_lhs.kind; - if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, ref rmul_lhs, ref rmul_rhs) = add_rhs.kind; - if eq_expr_value(cx, lmul_lhs, lmul_rhs); - if eq_expr_value(cx, rmul_lhs, rmul_rhs); - then { - return Some(format!("{}.hypot({})", Sugg::hir(cx, &lmul_lhs, ".."), Sugg::hir(cx, &rmul_lhs, ".."))); - } - } - - // check if expression of the form x.powi(2) + y.powi(2) - if_chain! { - if let ExprKind::MethodCall( - PathSegment { ident: lmethod_name, .. }, - ref _lspan, - ref largs, - _ - ) = add_lhs.kind; - if let ExprKind::MethodCall( - PathSegment { ident: rmethod_name, .. }, - ref _rspan, - ref rargs, - _ - ) = add_rhs.kind; - if lmethod_name.as_str() == "powi" && rmethod_name.as_str() == "powi"; - if let Some((lvalue, _)) = constant(cx, cx.typeck_results(), &largs[1]); - if let Some((rvalue, _)) = constant(cx, cx.typeck_results(), &rargs[1]); - if Int(2) == lvalue && Int(2) == rvalue; - then { - return Some(format!("{}.hypot({})", Sugg::hir(cx, &largs[0], ".."), Sugg::hir(cx, &rargs[0], ".."))); - } - } - } - - None -} - -fn check_hypot(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { - if let Some(message) = detect_hypot(cx, args) { - span_lint_and_sugg( - cx, - IMPRECISE_FLOPS, - expr.span, - "hypotenuse can be computed more accurately", - "consider using", - message, - Applicability::MachineApplicable, - ); - } -} - -// TODO: Lint expressions of the form `x.exp() - y` where y > 1 -// and suggest usage of `x.exp_m1() - (y - 1)` instead -fn check_expm1(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::Binary(Spanned { node: BinOpKind::Sub, .. }, ref lhs, ref rhs) = expr.kind; - if cx.typeck_results().expr_ty(lhs).is_floating_point(); - if let Some((value, _)) = constant(cx, cx.typeck_results(), rhs); - if F32(1.0) == value || F64(1.0) == value; - if let ExprKind::MethodCall(ref path, _, ref method_args, _) = lhs.kind; - if cx.typeck_results().expr_ty(&method_args[0]).is_floating_point(); - if path.ident.name.as_str() == "exp"; - then { - span_lint_and_sugg( - cx, - IMPRECISE_FLOPS, - expr.span, - "(e.pow(x) - 1) can be computed more accurately", - "consider using", - format!( - "{}.exp_m1()", - Sugg::hir(cx, &method_args[0], "..") - ), - Applicability::MachineApplicable, - ); - } - } -} - -fn is_float_mul_expr<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(&'a Expr<'a>, &'a Expr<'a>)> { - if_chain! { - if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, ref lhs, ref rhs) = &expr.kind; - if cx.typeck_results().expr_ty(lhs).is_floating_point(); - if cx.typeck_results().expr_ty(rhs).is_floating_point(); - then { - return Some((lhs, rhs)); - } - } - - None -} - -// TODO: Fix rust-lang/rust-clippy#4735 -fn check_mul_add(cx: &LateContext<'_>, expr: &Expr<'_>) { - if let ExprKind::Binary( - Spanned { - node: BinOpKind::Add, .. - }, - lhs, - rhs, - ) = &expr.kind - { - if let Some(parent) = get_parent_expr(cx, expr) { - if let ExprKind::MethodCall(PathSegment { ident: method_name, .. }, _, args, _) = parent.kind { - if method_name.as_str() == "sqrt" && detect_hypot(cx, args).is_some() { - return; - } - } - } - - let (recv, arg1, arg2) = if let Some((inner_lhs, inner_rhs)) = is_float_mul_expr(cx, lhs) { - (inner_lhs, inner_rhs, rhs) - } else if let Some((inner_lhs, inner_rhs)) = is_float_mul_expr(cx, rhs) { - (inner_lhs, inner_rhs, lhs) - } else { - return; - }; - - span_lint_and_sugg( - cx, - SUBOPTIMAL_FLOPS, - expr.span, - "multiply and add expressions can be calculated more efficiently and accurately", - "consider using", - format!( - "{}.mul_add({}, {})", - prepare_receiver_sugg(cx, recv), - Sugg::hir(cx, arg1, ".."), - Sugg::hir(cx, arg2, ".."), - ), - Applicability::MachineApplicable, - ); - } -} - -/// Returns true iff expr is an expression which tests whether or not -/// test is positive or an expression which tests whether or not test -/// is nonnegative. -/// Used for check-custom-abs function below -fn is_testing_positive(cx: &LateContext<'_>, expr: &Expr<'_>, test: &Expr<'_>) -> bool { - if let ExprKind::Binary(Spanned { node: op, .. }, left, right) = expr.kind { - match op { - BinOpKind::Gt | BinOpKind::Ge => is_zero(cx, right) && eq_expr_value(cx, left, test), - BinOpKind::Lt | BinOpKind::Le => is_zero(cx, left) && eq_expr_value(cx, right, test), - _ => false, - } - } else { - false - } -} - -/// See [`is_testing_positive`] -fn is_testing_negative(cx: &LateContext<'_>, expr: &Expr<'_>, test: &Expr<'_>) -> bool { - if let ExprKind::Binary(Spanned { node: op, .. }, left, right) = expr.kind { - match op { - BinOpKind::Gt | BinOpKind::Ge => is_zero(cx, left) && eq_expr_value(cx, right, test), - BinOpKind::Lt | BinOpKind::Le => is_zero(cx, right) && eq_expr_value(cx, left, test), - _ => false, - } - } else { - false - } -} - -/// Returns true iff expr is some zero literal -fn is_zero(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - match constant_simple(cx, cx.typeck_results(), expr) { - Some(Constant::Int(i)) => i == 0, - Some(Constant::F32(f)) => f == 0.0, - Some(Constant::F64(f)) => f == 0.0, - _ => false, - } -} - -/// If the two expressions are negations of each other, then it returns -/// a tuple, in which the first element is true iff expr1 is the -/// positive expressions, and the second element is the positive -/// one of the two expressions -/// If the two expressions are not negations of each other, then it -/// returns None. -fn are_negated<'a>(cx: &LateContext<'_>, expr1: &'a Expr<'a>, expr2: &'a Expr<'a>) -> Option<(bool, &'a Expr<'a>)> { - if let ExprKind::Unary(UnOp::UnNeg, expr1_negated) = &expr1.kind { - if eq_expr_value(cx, expr1_negated, expr2) { - return Some((false, expr2)); - } - } - if let ExprKind::Unary(UnOp::UnNeg, expr2_negated) = &expr2.kind { - if eq_expr_value(cx, expr1, expr2_negated) { - return Some((true, expr1)); - } - } - None -} - -fn check_custom_abs(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let Some((cond, body, Some(else_body))) = higher::if_block(&expr); - if let ExprKind::Block(block, _) = body.kind; - if block.stmts.is_empty(); - if let Some(if_body_expr) = block.expr; - if let ExprKind::Block(else_block, _) = else_body.kind; - if else_block.stmts.is_empty(); - if let Some(else_body_expr) = else_block.expr; - if let Some((if_expr_positive, body)) = are_negated(cx, if_body_expr, else_body_expr); - then { - let positive_abs_sugg = ( - "manual implementation of `abs` method", - format!("{}.abs()", Sugg::hir(cx, body, "..")), - ); - let negative_abs_sugg = ( - "manual implementation of negation of `abs` method", - format!("-{}.abs()", Sugg::hir(cx, body, "..")), - ); - let sugg = if is_testing_positive(cx, cond, body) { - if if_expr_positive { - positive_abs_sugg - } else { - negative_abs_sugg - } - } else if is_testing_negative(cx, cond, body) { - if if_expr_positive { - negative_abs_sugg - } else { - positive_abs_sugg - } - } else { - return; - }; - span_lint_and_sugg( - cx, - SUBOPTIMAL_FLOPS, - expr.span, - sugg.0, - "try", - sugg.1, - Applicability::MachineApplicable, - ); - } - } -} - -fn are_same_base_logs(cx: &LateContext<'_>, expr_a: &Expr<'_>, expr_b: &Expr<'_>) -> bool { - if_chain! { - if let ExprKind::MethodCall(PathSegment { ident: method_name_a, .. }, _, ref args_a, _) = expr_a.kind; - if let ExprKind::MethodCall(PathSegment { ident: method_name_b, .. }, _, ref args_b, _) = expr_b.kind; - then { - return method_name_a.as_str() == method_name_b.as_str() && - args_a.len() == args_b.len() && - ( - ["ln", "log2", "log10"].contains(&&*method_name_a.as_str()) || - method_name_a.as_str() == "log" && args_a.len() == 2 && eq_expr_value(cx, &args_a[1], &args_b[1]) - ); - } - } - - false -} - -fn check_log_division(cx: &LateContext<'_>, expr: &Expr<'_>) { - // check if expression of the form x.logN() / y.logN() - if_chain! { - if let ExprKind::Binary( - Spanned { - node: BinOpKind::Div, .. - }, - lhs, - rhs, - ) = &expr.kind; - if are_same_base_logs(cx, lhs, rhs); - if let ExprKind::MethodCall(_, _, ref largs, _) = lhs.kind; - if let ExprKind::MethodCall(_, _, ref rargs, _) = rhs.kind; - then { - span_lint_and_sugg( - cx, - SUBOPTIMAL_FLOPS, - expr.span, - "log base can be expressed more clearly", - "consider using", - format!("{}.log({})", Sugg::hir(cx, &largs[0], ".."), Sugg::hir(cx, &rargs[0], ".."),), - Applicability::MachineApplicable, - ); - } - } -} - -fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::Binary( - Spanned { - node: BinOpKind::Div, .. - }, - div_lhs, - div_rhs, - ) = &expr.kind; - if let ExprKind::Binary( - Spanned { - node: BinOpKind::Mul, .. - }, - mul_lhs, - mul_rhs, - ) = &div_lhs.kind; - if let Some((rvalue, _)) = constant(cx, cx.typeck_results(), div_rhs); - if let Some((lvalue, _)) = constant(cx, cx.typeck_results(), mul_rhs); - then { - // TODO: also check for constant values near PI/180 or 180/PI - if (F32(f32_consts::PI) == rvalue || F64(f64_consts::PI) == rvalue) && - (F32(180_f32) == lvalue || F64(180_f64) == lvalue) - { - span_lint_and_sugg( - cx, - SUBOPTIMAL_FLOPS, - expr.span, - "conversion to degrees can be done more accurately", - "consider using", - format!("{}.to_degrees()", Sugg::hir(cx, &mul_lhs, "..")), - Applicability::MachineApplicable, - ); - } else if - (F32(180_f32) == rvalue || F64(180_f64) == rvalue) && - (F32(f32_consts::PI) == lvalue || F64(f64_consts::PI) == lvalue) - { - span_lint_and_sugg( - cx, - SUBOPTIMAL_FLOPS, - expr.span, - "conversion to radians can be done more accurately", - "consider using", - format!("{}.to_radians()", Sugg::hir(cx, &mul_lhs, "..")), - Applicability::MachineApplicable, - ); - } - } - } -} - -impl<'tcx> LateLintPass<'tcx> for FloatingPointArithmetic { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::MethodCall(ref path, _, args, _) = &expr.kind { - let recv_ty = cx.typeck_results().expr_ty(&args[0]); - - if recv_ty.is_floating_point() { - match &*path.ident.name.as_str() { - "ln" => check_ln1p(cx, expr, args), - "log" => check_log_base(cx, expr, args), - "powf" => check_powf(cx, expr, args), - "powi" => check_powi(cx, expr, args), - "sqrt" => check_hypot(cx, expr, args), - _ => {}, - } - } - } else { - check_expm1(cx, expr); - check_mul_add(cx, expr); - check_custom_abs(cx, expr); - check_log_division(cx, expr); - check_radians(cx, expr); - } - } -} diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs deleted file mode 100644 index 8e41e0e34daf..000000000000 --- a/clippy_lints/src/format.rs +++ /dev/null @@ -1,205 +0,0 @@ -use crate::utils::paths; -use crate::utils::{ - is_expn_of, is_type_diagnostic_item, last_path_segment, match_def_path, match_function_call, snippet, snippet_opt, - span_lint_and_then, -}; -use if_chain::if_chain; -use rustc_ast::ast::LitKind; -use rustc_errors::Applicability; -use rustc_hir::{Arm, BorrowKind, Expr, ExprKind, MatchSource, PatKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** Checks for the use of `format!("string literal with no - /// argument")` and `format!("{}", foo)` where `foo` is a string. - /// - /// **Why is this bad?** There is no point of doing that. `format!("foo")` can - /// be replaced by `"foo".to_owned()` if you really need a `String`. The even - /// worse `&format!("foo")` is often encountered in the wild. `format!("{}", - /// foo)` can be replaced by `foo.clone()` if `foo: String` or `foo.to_owned()` - /// if `foo: &str`. - /// - /// **Known problems:** None. - /// - /// **Examples:** - /// ```rust - /// - /// // Bad - /// # let foo = "foo"; - /// format!("{}", foo); - /// - /// // Good - /// format!("foo"); - /// ``` - pub USELESS_FORMAT, - complexity, - "useless use of `format!`" -} - -declare_lint_pass!(UselessFormat => [USELESS_FORMAT]); - -impl<'tcx> LateLintPass<'tcx> for UselessFormat { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - let span = match is_expn_of(expr.span, "format") { - Some(s) if !s.from_expansion() => s, - _ => return, - }; - - // Operate on the only argument of `alloc::fmt::format`. - if let Some(sugg) = on_new_v1(cx, expr) { - span_useless_format(cx, span, "consider using `.to_string()`", sugg); - } else if let Some(sugg) = on_new_v1_fmt(cx, expr) { - span_useless_format(cx, span, "consider using `.to_string()`", sugg); - } - } -} - -fn span_useless_format(cx: &T, span: Span, help: &str, mut sugg: String) { - let to_replace = span.source_callsite(); - - // The callsite span contains the statement semicolon for some reason. - let snippet = snippet(cx, to_replace, ".."); - if snippet.ends_with(';') { - sugg.push(';'); - } - - span_lint_and_then(cx, USELESS_FORMAT, span, "useless use of `format!`", |diag| { - diag.span_suggestion( - to_replace, - help, - sugg, - Applicability::MachineApplicable, // snippet - ); - }); -} - -fn on_argumentv1_new<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arms: &'tcx [Arm<'_>]) -> Option { - if_chain! { - if let ExprKind::AddrOf(BorrowKind::Ref, _, ref format_args) = expr.kind; - if let ExprKind::Array(ref elems) = arms[0].body.kind; - if elems.len() == 1; - if let Some(args) = match_function_call(cx, &elems[0], &paths::FMT_ARGUMENTV1_NEW); - // matches `core::fmt::Display::fmt` - if args.len() == 2; - if let ExprKind::Path(ref qpath) = args[1].kind; - if let Some(did) = cx.qpath_res(qpath, args[1].hir_id).opt_def_id(); - if match_def_path(cx, did, &paths::DISPLAY_FMT_METHOD); - // check `(arg0,)` in match block - if let PatKind::Tuple(ref pats, None) = arms[0].pat.kind; - if pats.len() == 1; - then { - let ty = cx.typeck_results().pat_ty(&pats[0]).peel_refs(); - if *ty.kind() != rustc_middle::ty::Str && !is_type_diagnostic_item(cx, ty, sym::string_type) { - return None; - } - if let ExprKind::Lit(ref lit) = format_args.kind { - if let LitKind::Str(ref s, _) = lit.node { - return Some(format!("{:?}.to_string()", s.as_str())); - } - } else { - let snip = snippet(cx, format_args.span, ""); - if let ExprKind::MethodCall(ref path, _, _, _) = format_args.kind { - if path.ident.name == sym!(to_string) { - return Some(format!("{}", snip)); - } - } else if let ExprKind::Binary(..) = format_args.kind { - return Some(format!("{}", snip)); - } - return Some(format!("{}.to_string()", snip)); - } - } - } - None -} - -fn on_new_v1<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option { - if_chain! { - if let Some(args) = match_function_call(cx, expr, &paths::FMT_ARGUMENTS_NEW_V1); - if args.len() == 2; - // Argument 1 in `new_v1()` - if let ExprKind::AddrOf(BorrowKind::Ref, _, ref arr) = args[0].kind; - if let ExprKind::Array(ref pieces) = arr.kind; - if pieces.len() == 1; - if let ExprKind::Lit(ref lit) = pieces[0].kind; - if let LitKind::Str(ref s, _) = lit.node; - // Argument 2 in `new_v1()` - if let ExprKind::AddrOf(BorrowKind::Ref, _, ref arg1) = args[1].kind; - if let ExprKind::Match(ref matchee, ref arms, MatchSource::Normal) = arg1.kind; - if arms.len() == 1; - if let ExprKind::Tup(ref tup) = matchee.kind; - then { - // `format!("foo")` expansion contains `match () { () => [], }` - if tup.is_empty() { - if let Some(s_src) = snippet_opt(cx, lit.span) { - // Simulate macro expansion, converting {{ and }} to { and }. - let s_expand = s_src.replace("{{", "{").replace("}}", "}"); - return Some(format!("{}.to_string()", s_expand)) - } - } else if s.as_str().is_empty() { - return on_argumentv1_new(cx, &tup[0], arms); - } - } - } - None -} - -fn on_new_v1_fmt<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option { - if_chain! { - if let Some(args) = match_function_call(cx, expr, &paths::FMT_ARGUMENTS_NEW_V1_FORMATTED); - if args.len() == 3; - if check_unformatted(&args[2]); - // Argument 1 in `new_v1_formatted()` - if let ExprKind::AddrOf(BorrowKind::Ref, _, ref arr) = args[0].kind; - if let ExprKind::Array(ref pieces) = arr.kind; - if pieces.len() == 1; - if let ExprKind::Lit(ref lit) = pieces[0].kind; - if let LitKind::Str(..) = lit.node; - // Argument 2 in `new_v1_formatted()` - if let ExprKind::AddrOf(BorrowKind::Ref, _, ref arg1) = args[1].kind; - if let ExprKind::Match(ref matchee, ref arms, MatchSource::Normal) = arg1.kind; - if arms.len() == 1; - if let ExprKind::Tup(ref tup) = matchee.kind; - then { - return on_argumentv1_new(cx, &tup[0], arms); - } - } - None -} - -/// Checks if the expression matches -/// ```rust,ignore -/// &[_ { -/// format: _ { -/// width: _::Implied, -/// precision: _::Implied, -/// ... -/// }, -/// ..., -/// }] -/// ``` -fn check_unformatted(expr: &Expr<'_>) -> bool { - if_chain! { - if let ExprKind::AddrOf(BorrowKind::Ref, _, ref expr) = expr.kind; - if let ExprKind::Array(ref exprs) = expr.kind; - if exprs.len() == 1; - // struct `core::fmt::rt::v1::Argument` - if let ExprKind::Struct(_, ref fields, _) = exprs[0].kind; - if let Some(format_field) = fields.iter().find(|f| f.ident.name == sym::format); - // struct `core::fmt::rt::v1::FormatSpec` - if let ExprKind::Struct(_, ref fields, _) = format_field.expr.kind; - if let Some(precision_field) = fields.iter().find(|f| f.ident.name == sym::precision); - if let ExprKind::Path(ref precision_path) = precision_field.expr.kind; - if last_path_segment(precision_path).ident.name == sym::Implied; - if let Some(width_field) = fields.iter().find(|f| f.ident.name == sym::width); - if let ExprKind::Path(ref width_qpath) = width_field.expr.kind; - if last_path_segment(width_qpath).ident.name == sym::Implied; - then { - return true; - } - } - - false -} diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs deleted file mode 100644 index 1bd16e6cce53..000000000000 --- a/clippy_lints/src/formatting.rs +++ /dev/null @@ -1,314 +0,0 @@ -use crate::utils::{differing_macro_contexts, snippet_opt, span_lint_and_help, span_lint_and_note}; -use if_chain::if_chain; -use rustc_ast::ast::{BinOpKind, Block, Expr, ExprKind, StmtKind, UnOp}; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_middle::lint::in_external_macro; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for use of the non-existent `=*`, `=!` and `=-` - /// operators. - /// - /// **Why is this bad?** This is either a typo of `*=`, `!=` or `-=` or - /// confusing. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// a =- 42; // confusing, should it be `a -= 42` or `a = -42`? - /// ``` - pub SUSPICIOUS_ASSIGNMENT_FORMATTING, - style, - "suspicious formatting of `*=`, `-=` or `!=`" -} - -declare_clippy_lint! { - /// **What it does:** Checks the formatting of a unary operator on the right hand side - /// of a binary operator. It lints if there is no space between the binary and unary operators, - /// but there is a space between the unary and its operand. - /// - /// **Why is this bad?** This is either a typo in the binary operator or confusing. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// if foo <- 30 { // this should be `foo < -30` but looks like a different operator - /// } - /// - /// if foo &&! bar { // this should be `foo && !bar` but looks like a different operator - /// } - /// ``` - pub SUSPICIOUS_UNARY_OP_FORMATTING, - style, - "suspicious formatting of unary `-` or `!` on the RHS of a BinOp" -} - -declare_clippy_lint! { - /// **What it does:** Checks for formatting of `else`. It lints if the `else` - /// is followed immediately by a newline or the `else` seems to be missing. - /// - /// **Why is this bad?** This is probably some refactoring remnant, even if the - /// code is correct, it might look confusing. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// if foo { - /// } { // looks like an `else` is missing here - /// } - /// - /// if foo { - /// } if bar { // looks like an `else` is missing here - /// } - /// - /// if foo { - /// } else - /// - /// { // this is the `else` block of the previous `if`, but should it be? - /// } - /// - /// if foo { - /// } else - /// - /// if bar { // this is the `else` block of the previous `if`, but should it be? - /// } - /// ``` - pub SUSPICIOUS_ELSE_FORMATTING, - style, - "suspicious formatting of `else`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for possible missing comma in an array. It lints if - /// an array element is a binary operator expression and it lies on two lines. - /// - /// **Why is this bad?** This could lead to unexpected results. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// let a = &[ - /// -1, -2, -3 // <= no comma here - /// -4, -5, -6 - /// ]; - /// ``` - pub POSSIBLE_MISSING_COMMA, - correctness, - "possible missing comma in array" -} - -declare_lint_pass!(Formatting => [ - SUSPICIOUS_ASSIGNMENT_FORMATTING, - SUSPICIOUS_UNARY_OP_FORMATTING, - SUSPICIOUS_ELSE_FORMATTING, - POSSIBLE_MISSING_COMMA -]); - -impl EarlyLintPass for Formatting { - fn check_block(&mut self, cx: &EarlyContext<'_>, block: &Block) { - for w in block.stmts.windows(2) { - if let (StmtKind::Expr(first), StmtKind::Expr(second) | StmtKind::Semi(second)) = (&w[0].kind, &w[1].kind) { - check_missing_else(cx, first, second); - } - } - } - - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - check_assign(cx, expr); - check_unop(cx, expr); - check_else(cx, expr); - check_array(cx, expr); - } -} - -/// Implementation of the `SUSPICIOUS_ASSIGNMENT_FORMATTING` lint. -fn check_assign(cx: &EarlyContext<'_>, expr: &Expr) { - if let ExprKind::Assign(ref lhs, ref rhs, _) = expr.kind { - if !differing_macro_contexts(lhs.span, rhs.span) && !lhs.span.from_expansion() { - let eq_span = lhs.span.between(rhs.span); - if let ExprKind::Unary(op, ref sub_rhs) = rhs.kind { - if let Some(eq_snippet) = snippet_opt(cx, eq_span) { - let op = UnOp::to_string(op); - let eqop_span = lhs.span.between(sub_rhs.span); - if eq_snippet.ends_with('=') { - span_lint_and_note( - cx, - SUSPICIOUS_ASSIGNMENT_FORMATTING, - eqop_span, - &format!( - "this looks like you are trying to use `.. {op}= ..`, but you \ - really are doing `.. = ({op} ..)`", - op = op - ), - None, - &format!("to remove this lint, use either `{op}=` or `= {op}`", op = op), - ); - } - } - } - } - } -} - -/// Implementation of the `SUSPICIOUS_UNARY_OP_FORMATTING` lint. -fn check_unop(cx: &EarlyContext<'_>, expr: &Expr) { - if_chain! { - if let ExprKind::Binary(ref binop, ref lhs, ref rhs) = expr.kind; - if !differing_macro_contexts(lhs.span, rhs.span) && !lhs.span.from_expansion(); - // span between BinOp LHS and RHS - let binop_span = lhs.span.between(rhs.span); - // if RHS is a UnOp - if let ExprKind::Unary(op, ref un_rhs) = rhs.kind; - // from UnOp operator to UnOp operand - let unop_operand_span = rhs.span.until(un_rhs.span); - if let Some(binop_snippet) = snippet_opt(cx, binop_span); - if let Some(unop_operand_snippet) = snippet_opt(cx, unop_operand_span); - let binop_str = BinOpKind::to_string(&binop.node); - // no space after BinOp operator and space after UnOp operator - if binop_snippet.ends_with(binop_str) && unop_operand_snippet.ends_with(' '); - then { - let unop_str = UnOp::to_string(op); - let eqop_span = lhs.span.between(un_rhs.span); - span_lint_and_help( - cx, - SUSPICIOUS_UNARY_OP_FORMATTING, - eqop_span, - &format!( - "by not having a space between `{binop}` and `{unop}` it looks like \ - `{binop}{unop}` is a single operator", - binop = binop_str, - unop = unop_str - ), - None, - &format!( - "put a space between `{binop}` and `{unop}` and remove the space after `{unop}`", - binop = binop_str, - unop = unop_str - ), - ); - } - } -} - -/// Implementation of the `SUSPICIOUS_ELSE_FORMATTING` lint for weird `else`. -fn check_else(cx: &EarlyContext<'_>, expr: &Expr) { - if_chain! { - if let ExprKind::If(_, then, Some(else_)) = &expr.kind; - if is_block(else_) || is_if(else_); - if !differing_macro_contexts(then.span, else_.span); - if !then.span.from_expansion() && !in_external_macro(cx.sess, expr.span); - - // workaround for rust-lang/rust#43081 - if expr.span.lo().0 != 0 && expr.span.hi().0 != 0; - - // this will be a span from the closing ‘}’ of the “then” block (excluding) to - // the “if” of the “else if” block (excluding) - let else_span = then.span.between(else_.span); - - // the snippet should look like " else \n " with maybe comments anywhere - // it’s bad when there is a ‘\n’ after the “else” - if let Some(else_snippet) = snippet_opt(cx, else_span); - if let Some(else_pos) = else_snippet.find("else"); - if else_snippet[else_pos..].contains('\n'); - let else_desc = if is_if(else_) { "if" } else { "{..}" }; - - then { - span_lint_and_note( - cx, - SUSPICIOUS_ELSE_FORMATTING, - else_span, - &format!("this is an `else {}` but the formatting might hide it", else_desc), - None, - &format!( - "to remove this lint, remove the `else` or remove the new line between \ - `else` and `{}`", - else_desc, - ), - ); - } - } -} - -#[must_use] -fn has_unary_equivalent(bin_op: BinOpKind) -> bool { - // &, *, - - bin_op == BinOpKind::And || bin_op == BinOpKind::Mul || bin_op == BinOpKind::Sub -} - -fn indentation(cx: &EarlyContext<'_>, span: Span) -> usize { - cx.sess.source_map().lookup_char_pos(span.lo()).col.0 -} - -/// Implementation of the `POSSIBLE_MISSING_COMMA` lint for array -fn check_array(cx: &EarlyContext<'_>, expr: &Expr) { - if let ExprKind::Array(ref array) = expr.kind { - for element in array { - if_chain! { - if let ExprKind::Binary(ref op, ref lhs, _) = element.kind; - if has_unary_equivalent(op.node) && !differing_macro_contexts(lhs.span, op.span); - let space_span = lhs.span.between(op.span); - if let Some(space_snippet) = snippet_opt(cx, space_span); - let lint_span = lhs.span.with_lo(lhs.span.hi()); - if space_snippet.contains('\n'); - if indentation(cx, op.span) <= indentation(cx, lhs.span); - then { - span_lint_and_note( - cx, - POSSIBLE_MISSING_COMMA, - lint_span, - "possibly missing a comma here", - None, - "to remove this lint, add a comma or write the expr in a single line", - ); - } - } - } - } -} - -fn check_missing_else(cx: &EarlyContext<'_>, first: &Expr, second: &Expr) { - if !differing_macro_contexts(first.span, second.span) - && !first.span.from_expansion() - && is_if(first) - && (is_block(second) || is_if(second)) - { - // where the else would be - let else_span = first.span.between(second.span); - - if let Some(else_snippet) = snippet_opt(cx, else_span) { - if !else_snippet.contains('\n') { - let (looks_like, next_thing) = if is_if(second) { - ("an `else if`", "the second `if`") - } else { - ("an `else {..}`", "the next block") - }; - - span_lint_and_note( - cx, - SUSPICIOUS_ELSE_FORMATTING, - else_span, - &format!("this looks like {} but the `else` is missing", looks_like), - None, - &format!( - "to remove this lint, add the missing `else` or add a new line before {}", - next_thing, - ), - ); - } - } - } -} - -fn is_block(expr: &Expr) -> bool { - matches!(expr.kind, ExprKind::Block(..)) -} - -/// Check if the expression is an `if` or `if let` -fn is_if(expr: &Expr) -> bool { - matches!(expr.kind, ExprKind::If(..)) -} diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs deleted file mode 100644 index fd93548b55c6..000000000000 --- a/clippy_lints/src/functions.rs +++ /dev/null @@ -1,738 +0,0 @@ -use crate::utils::{ - attr_by_name, attrs::is_proc_macro, is_must_use_ty, is_trait_impl_item, is_type_diagnostic_item, iter_input_pats, - last_path_segment, match_def_path, must_use_attr, qpath_res, return_ty, snippet, snippet_opt, span_lint, - span_lint_and_help, span_lint_and_then, trait_ref_of_method, type_is_unsafe_function, -}; -use if_chain::if_chain; -use rustc_ast::ast::Attribute; -use rustc_data_structures::fx::FxHashSet; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_hir::intravisit; -use rustc_hir::{def::Res, def_id::DefId}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, Ty}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; -use rustc_span::sym; -use rustc_target::spec::abi::Abi; -use rustc_typeck::hir_ty_to_ty; - -declare_clippy_lint! { - /// **What it does:** Checks for functions with too many parameters. - /// - /// **Why is this bad?** Functions with lots of parameters are considered bad - /// style and reduce readability (“what does the 5th parameter mean?”). Consider - /// grouping some parameters into a new type. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # struct Color; - /// fn foo(x: u32, y: u32, name: &str, c: Color, w: f32, h: f32, a: f32, b: f32) { - /// // .. - /// } - /// ``` - pub TOO_MANY_ARGUMENTS, - complexity, - "functions with too many arguments" -} - -declare_clippy_lint! { - /// **What it does:** Checks for functions with a large amount of lines. - /// - /// **Why is this bad?** Functions with a lot of lines are harder to understand - /// due to having to look at a larger amount of code to understand what the - /// function is doing. Consider splitting the body of the function into - /// multiple functions. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// fn im_too_long() { - /// println!(""); - /// // ... 100 more LoC - /// println!(""); - /// } - /// ``` - pub TOO_MANY_LINES, - pedantic, - "functions with too many lines" -} - -declare_clippy_lint! { - /// **What it does:** Checks for public functions that dereference raw pointer - /// arguments but are not marked unsafe. - /// - /// **Why is this bad?** The function should probably be marked `unsafe`, since - /// for an arbitrary raw pointer, there is no way of telling for sure if it is - /// valid. - /// - /// **Known problems:** - /// - /// * It does not check functions recursively so if the pointer is passed to a - /// private non-`unsafe` function which does the dereferencing, the lint won't - /// trigger. - /// * It only checks for arguments whose type are raw pointers, not raw pointers - /// got from an argument in some other way (`fn foo(bar: &[*const u8])` or - /// `some_argument.get_raw_ptr()`). - /// - /// **Example:** - /// ```rust,ignore - /// // Bad - /// pub fn foo(x: *const u8) { - /// println!("{}", unsafe { *x }); - /// } - /// - /// // Good - /// pub unsafe fn foo(x: *const u8) { - /// println!("{}", unsafe { *x }); - /// } - /// ``` - pub NOT_UNSAFE_PTR_ARG_DEREF, - correctness, - "public functions dereferencing raw pointer arguments but not marked `unsafe`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for a [`#[must_use]`] attribute on - /// unit-returning functions and methods. - /// - /// [`#[must_use]`]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute - /// - /// **Why is this bad?** Unit values are useless. The attribute is likely - /// a remnant of a refactoring that removed the return type. - /// - /// **Known problems:** None. - /// - /// **Examples:** - /// ```rust - /// #[must_use] - /// fn useless() { } - /// ``` - pub MUST_USE_UNIT, - style, - "`#[must_use]` attribute on a unit-returning function / method" -} - -declare_clippy_lint! { - /// **What it does:** Checks for a [`#[must_use]`] attribute without - /// further information on functions and methods that return a type already - /// marked as `#[must_use]`. - /// - /// [`#[must_use]`]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute - /// - /// **Why is this bad?** The attribute isn't needed. Not using the result - /// will already be reported. Alternatively, one can add some text to the - /// attribute to improve the lint message. - /// - /// **Known problems:** None. - /// - /// **Examples:** - /// ```rust - /// #[must_use] - /// fn double_must_use() -> Result<(), ()> { - /// unimplemented!(); - /// } - /// ``` - pub DOUBLE_MUST_USE, - style, - "`#[must_use]` attribute on a `#[must_use]`-returning function / method" -} - -declare_clippy_lint! { - /// **What it does:** Checks for public functions that have no - /// [`#[must_use]`] attribute, but return something not already marked - /// must-use, have no mutable arg and mutate no statics. - /// - /// [`#[must_use]`]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute - /// - /// **Why is this bad?** Not bad at all, this lint just shows places where - /// you could add the attribute. - /// - /// **Known problems:** The lint only checks the arguments for mutable - /// types without looking if they are actually changed. On the other hand, - /// it also ignores a broad range of potentially interesting side effects, - /// because we cannot decide whether the programmer intends the function to - /// be called for the side effect or the result. Expect many false - /// positives. At least we don't lint if the result type is unit or already - /// `#[must_use]`. - /// - /// **Examples:** - /// ```rust - /// // this could be annotated with `#[must_use]`. - /// fn id(t: T) -> T { t } - /// ``` - pub MUST_USE_CANDIDATE, - pedantic, - "function or method that could take a `#[must_use]` attribute" -} - -declare_clippy_lint! { - /// **What it does:** Checks for public functions that return a `Result` - /// with an `Err` type of `()`. It suggests using a custom type that - /// implements [`std::error::Error`]. - /// - /// **Why is this bad?** Unit does not implement `Error` and carries no - /// further information about what went wrong. - /// - /// **Known problems:** Of course, this lint assumes that `Result` is used - /// for a fallible operation (which is after all the intended use). However - /// code may opt to (mis)use it as a basic two-variant-enum. In that case, - /// the suggestion is misguided, and the code should use a custom enum - /// instead. - /// - /// **Examples:** - /// ```rust - /// pub fn read_u8() -> Result { Err(()) } - /// ``` - /// should become - /// ```rust,should_panic - /// use std::fmt; - /// - /// #[derive(Debug)] - /// pub struct EndOfStream; - /// - /// impl fmt::Display for EndOfStream { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// write!(f, "End of Stream") - /// } - /// } - /// - /// impl std::error::Error for EndOfStream { } - /// - /// pub fn read_u8() -> Result { Err(EndOfStream) } - ///# fn main() { - ///# read_u8().unwrap(); - ///# } - /// ``` - /// - /// Note that there are crates that simplify creating the error type, e.g. - /// [`thiserror`](https://docs.rs/thiserror). - pub RESULT_UNIT_ERR, - style, - "public function returning `Result` with an `Err` type of `()`" -} - -#[derive(Copy, Clone)] -pub struct Functions { - threshold: u64, - max_lines: u64, -} - -impl Functions { - pub fn new(threshold: u64, max_lines: u64) -> Self { - Self { threshold, max_lines } - } -} - -impl_lint_pass!(Functions => [ - TOO_MANY_ARGUMENTS, - TOO_MANY_LINES, - NOT_UNSAFE_PTR_ARG_DEREF, - MUST_USE_UNIT, - DOUBLE_MUST_USE, - MUST_USE_CANDIDATE, - RESULT_UNIT_ERR, -]); - -impl<'tcx> LateLintPass<'tcx> for Functions { - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - kind: intravisit::FnKind<'tcx>, - decl: &'tcx hir::FnDecl<'_>, - body: &'tcx hir::Body<'_>, - span: Span, - hir_id: hir::HirId, - ) { - let unsafety = match kind { - intravisit::FnKind::ItemFn(_, _, hir::FnHeader { unsafety, .. }, _, _) => unsafety, - intravisit::FnKind::Method(_, sig, _, _) => sig.header.unsafety, - intravisit::FnKind::Closure(_) => return, - }; - - // don't warn for implementations, it's not their fault - if !is_trait_impl_item(cx, hir_id) { - // don't lint extern functions decls, it's not their fault either - match kind { - intravisit::FnKind::Method( - _, - &hir::FnSig { - header: hir::FnHeader { abi: Abi::Rust, .. }, - .. - }, - _, - _, - ) - | intravisit::FnKind::ItemFn(_, _, hir::FnHeader { abi: Abi::Rust, .. }, _, _) => { - self.check_arg_number(cx, decl, span.with_hi(decl.output.span().hi())) - }, - _ => {}, - } - } - - Self::check_raw_ptr(cx, unsafety, decl, body, hir_id); - self.check_line_number(cx, span, body); - } - - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { - let attr = must_use_attr(&item.attrs); - if let hir::ItemKind::Fn(ref sig, ref _generics, ref body_id) = item.kind { - let is_public = cx.access_levels.is_exported(item.hir_id); - let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); - if is_public { - check_result_unit_err(cx, &sig.decl, item.span, fn_header_span); - } - if let Some(attr) = attr { - check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr); - return; - } - if is_public && !is_proc_macro(cx.sess(), &item.attrs) && attr_by_name(&item.attrs, "no_mangle").is_none() { - check_must_use_candidate( - cx, - &sig.decl, - cx.tcx.hir().body(*body_id), - item.span, - item.hir_id, - item.span.with_hi(sig.decl.output.span().hi()), - "this function could have a `#[must_use]` attribute", - ); - } - } - } - - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { - if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind { - let is_public = cx.access_levels.is_exported(item.hir_id); - let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); - if is_public && trait_ref_of_method(cx, item.hir_id).is_none() { - check_result_unit_err(cx, &sig.decl, item.span, fn_header_span); - } - let attr = must_use_attr(&item.attrs); - if let Some(attr) = attr { - check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr); - } else if is_public - && !is_proc_macro(cx.sess(), &item.attrs) - && trait_ref_of_method(cx, item.hir_id).is_none() - { - check_must_use_candidate( - cx, - &sig.decl, - cx.tcx.hir().body(*body_id), - item.span, - item.hir_id, - item.span.with_hi(sig.decl.output.span().hi()), - "this method could have a `#[must_use]` attribute", - ); - } - } - } - - fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { - if let hir::TraitItemKind::Fn(ref sig, ref eid) = item.kind { - // don't lint extern functions decls, it's not their fault - if sig.header.abi == Abi::Rust { - self.check_arg_number(cx, &sig.decl, item.span.with_hi(sig.decl.output.span().hi())); - } - let is_public = cx.access_levels.is_exported(item.hir_id); - let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); - if is_public { - check_result_unit_err(cx, &sig.decl, item.span, fn_header_span); - } - - let attr = must_use_attr(&item.attrs); - if let Some(attr) = attr { - check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr); - } - if let hir::TraitFn::Provided(eid) = *eid { - let body = cx.tcx.hir().body(eid); - Self::check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id); - - if attr.is_none() && is_public && !is_proc_macro(cx.sess(), &item.attrs) { - check_must_use_candidate( - cx, - &sig.decl, - body, - item.span, - item.hir_id, - item.span.with_hi(sig.decl.output.span().hi()), - "this method could have a `#[must_use]` attribute", - ); - } - } - } - } -} - -impl<'tcx> Functions { - fn check_arg_number(self, cx: &LateContext<'_>, decl: &hir::FnDecl<'_>, fn_span: Span) { - let args = decl.inputs.len() as u64; - if args > self.threshold { - span_lint( - cx, - TOO_MANY_ARGUMENTS, - fn_span, - &format!("this function has too many arguments ({}/{})", args, self.threshold), - ); - } - } - - fn check_line_number(self, cx: &LateContext<'_>, span: Span, body: &'tcx hir::Body<'_>) { - if in_external_macro(cx.sess(), span) { - return; - } - - let code_snippet = snippet(cx, body.value.span, ".."); - let mut line_count: u64 = 0; - let mut in_comment = false; - let mut code_in_line; - - // Skip the surrounding function decl. - let start_brace_idx = code_snippet.find('{').map_or(0, |i| i + 1); - let end_brace_idx = code_snippet.rfind('}').unwrap_or_else(|| code_snippet.len()); - let function_lines = code_snippet[start_brace_idx..end_brace_idx].lines(); - - for mut line in function_lines { - code_in_line = false; - loop { - line = line.trim_start(); - if line.is_empty() { - break; - } - if in_comment { - if let Some(i) = line.find("*/") { - line = &line[i + 2..]; - in_comment = false; - continue; - } - } else { - let multi_idx = line.find("/*").unwrap_or_else(|| line.len()); - let single_idx = line.find("//").unwrap_or_else(|| line.len()); - code_in_line |= multi_idx > 0 && single_idx > 0; - // Implies multi_idx is below line.len() - if multi_idx < single_idx { - line = &line[multi_idx + 2..]; - in_comment = true; - continue; - } - } - break; - } - if code_in_line { - line_count += 1; - } - } - - if line_count > self.max_lines { - span_lint( - cx, - TOO_MANY_LINES, - span, - &format!("this function has too many lines ({}/{})", line_count, self.max_lines), - ) - } - } - - fn check_raw_ptr( - cx: &LateContext<'tcx>, - unsafety: hir::Unsafety, - decl: &'tcx hir::FnDecl<'_>, - body: &'tcx hir::Body<'_>, - hir_id: hir::HirId, - ) { - let expr = &body.value; - if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(hir_id) { - let raw_ptrs = iter_input_pats(decl, body) - .zip(decl.inputs.iter()) - .filter_map(|(arg, ty)| raw_ptr_arg(arg, ty)) - .collect::>(); - - if !raw_ptrs.is_empty() { - let typeck_results = cx.tcx.typeck_body(body.id()); - let mut v = DerefVisitor { - cx, - ptrs: raw_ptrs, - typeck_results, - }; - - intravisit::walk_expr(&mut v, expr); - } - } - } -} - -fn check_result_unit_err(cx: &LateContext<'_>, decl: &hir::FnDecl<'_>, item_span: Span, fn_header_span: Span) { - if_chain! { - if !in_external_macro(cx.sess(), item_span); - if let hir::FnRetTy::Return(ref ty) = decl.output; - if let hir::TyKind::Path(ref qpath) = ty.kind; - if is_type_diagnostic_item(cx, hir_ty_to_ty(cx.tcx, ty), sym::result_type); - if let Some(ref args) = last_path_segment(qpath).args; - if let [_, hir::GenericArg::Type(ref err_ty)] = args.args; - if let hir::TyKind::Tup(t) = err_ty.kind; - if t.is_empty(); - then { - span_lint_and_help( - cx, - RESULT_UNIT_ERR, - fn_header_span, - "this returns a `Result<_, ()>", - None, - "use a custom Error type instead", - ); - } - } -} - -fn check_needless_must_use( - cx: &LateContext<'_>, - decl: &hir::FnDecl<'_>, - item_id: hir::HirId, - item_span: Span, - fn_header_span: Span, - attr: &Attribute, -) { - if in_external_macro(cx.sess(), item_span) { - return; - } - if returns_unit(decl) { - span_lint_and_then( - cx, - MUST_USE_UNIT, - fn_header_span, - "this unit-returning function has a `#[must_use]` attribute", - |diag| { - diag.span_suggestion( - attr.span, - "remove the attribute", - "".into(), - Applicability::MachineApplicable, - ); - }, - ); - } else if !attr.is_value_str() && is_must_use_ty(cx, return_ty(cx, item_id)) { - span_lint_and_help( - cx, - DOUBLE_MUST_USE, - fn_header_span, - "this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]`", - None, - "either add some descriptive text or remove the attribute", - ); - } -} - -fn check_must_use_candidate<'tcx>( - cx: &LateContext<'tcx>, - decl: &'tcx hir::FnDecl<'_>, - body: &'tcx hir::Body<'_>, - item_span: Span, - item_id: hir::HirId, - fn_span: Span, - msg: &str, -) { - if has_mutable_arg(cx, body) - || mutates_static(cx, body) - || in_external_macro(cx.sess(), item_span) - || returns_unit(decl) - || !cx.access_levels.is_exported(item_id) - || is_must_use_ty(cx, return_ty(cx, item_id)) - { - return; - } - span_lint_and_then(cx, MUST_USE_CANDIDATE, fn_span, msg, |diag| { - if let Some(snippet) = snippet_opt(cx, fn_span) { - diag.span_suggestion( - fn_span, - "add the attribute", - format!("#[must_use] {}", snippet), - Applicability::MachineApplicable, - ); - } - }); -} - -fn returns_unit(decl: &hir::FnDecl<'_>) -> bool { - match decl.output { - hir::FnRetTy::DefaultReturn(_) => true, - hir::FnRetTy::Return(ref ty) => match ty.kind { - hir::TyKind::Tup(ref tys) => tys.is_empty(), - hir::TyKind::Never => true, - _ => false, - }, - } -} - -fn has_mutable_arg(cx: &LateContext<'_>, body: &hir::Body<'_>) -> bool { - let mut tys = FxHashSet::default(); - body.params.iter().any(|param| is_mutable_pat(cx, ¶m.pat, &mut tys)) -} - -fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut FxHashSet) -> bool { - if let hir::PatKind::Wild = pat.kind { - return false; // ignore `_` patterns - } - if cx.tcx.has_typeck_results(pat.hir_id.owner.to_def_id()) { - is_mutable_ty(cx, &cx.tcx.typeck(pat.hir_id.owner).pat_ty(pat), pat.span, tys) - } else { - false - } -} - -static KNOWN_WRAPPER_TYS: &[&[&str]] = &[&["alloc", "rc", "Rc"], &["std", "sync", "Arc"]]; - -fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, tys: &mut FxHashSet) -> bool { - match *ty.kind() { - // primitive types are never mutable - ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false, - ty::Adt(ref adt, ref substs) => { - tys.insert(adt.did) && !ty.is_freeze(cx.tcx.at(span), cx.param_env) - || KNOWN_WRAPPER_TYS.iter().any(|path| match_def_path(cx, adt.did, path)) - && substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)) - }, - ty::Tuple(ref substs) => substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)), - ty::Array(ty, _) | ty::Slice(ty) => is_mutable_ty(cx, ty, span, tys), - ty::RawPtr(ty::TypeAndMut { ty, mutbl }) | ty::Ref(_, ty, mutbl) => { - mutbl == hir::Mutability::Mut || is_mutable_ty(cx, ty, span, tys) - }, - // calling something constitutes a side effect, so return true on all callables - // also never calls need not be used, so return true for them, too - _ => true, - } -} - -fn raw_ptr_arg(arg: &hir::Param<'_>, ty: &hir::Ty<'_>) -> Option { - if let (&hir::PatKind::Binding(_, id, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.kind, &ty.kind) { - Some(id) - } else { - None - } -} - -struct DerefVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - ptrs: FxHashSet, - typeck_results: &'a ty::TypeckResults<'tcx>, -} - -impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { - match expr.kind { - hir::ExprKind::Call(ref f, args) => { - let ty = self.typeck_results.expr_ty(f); - - if type_is_unsafe_function(self.cx, ty) { - for arg in args { - self.check_arg(arg); - } - } - }, - hir::ExprKind::MethodCall(_, _, args, _) => { - let def_id = self.typeck_results.type_dependent_def_id(expr.hir_id).unwrap(); - let base_type = self.cx.tcx.type_of(def_id); - - if type_is_unsafe_function(self.cx, base_type) { - for arg in args { - self.check_arg(arg); - } - } - }, - hir::ExprKind::Unary(hir::UnOp::UnDeref, ref ptr) => self.check_arg(ptr), - _ => (), - } - - intravisit::walk_expr(self, expr); - } - - fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap { - intravisit::NestedVisitorMap::None - } -} - -impl<'a, 'tcx> DerefVisitor<'a, 'tcx> { - fn check_arg(&self, ptr: &hir::Expr<'_>) { - if let hir::ExprKind::Path(ref qpath) = ptr.kind { - if let Res::Local(id) = qpath_res(self.cx, qpath, ptr.hir_id) { - if self.ptrs.contains(&id) { - span_lint( - self.cx, - NOT_UNSAFE_PTR_ARG_DEREF, - ptr.span, - "this public function dereferences a raw pointer but is not marked `unsafe`", - ); - } - } - } - } -} - -struct StaticMutVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - mutates_static: bool, -} - -impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { - use hir::ExprKind::{AddrOf, Assign, AssignOp, Call, MethodCall}; - - if self.mutates_static { - return; - } - match expr.kind { - Call(_, args) | MethodCall(_, _, args, _) => { - let mut tys = FxHashSet::default(); - for arg in args { - if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id()) - && is_mutable_ty( - self.cx, - self.cx.tcx.typeck(arg.hir_id.owner).expr_ty(arg), - arg.span, - &mut tys, - ) - && is_mutated_static(self.cx, arg) - { - self.mutates_static = true; - return; - } - tys.clear(); - } - }, - Assign(ref target, ..) | AssignOp(_, ref target, _) | AddrOf(_, hir::Mutability::Mut, ref target) => { - self.mutates_static |= is_mutated_static(self.cx, target) - }, - _ => {}, - } - } - - fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap { - intravisit::NestedVisitorMap::None - } -} - -fn is_mutated_static(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> bool { - use hir::ExprKind::{Field, Index, Path}; - - match e.kind { - Path(ref qpath) => !matches!(qpath_res(cx, qpath, e.hir_id), Res::Local(_)), - Field(ref inner, _) | Index(ref inner, _) => is_mutated_static(cx, inner), - _ => false, - } -} - -fn mutates_static<'tcx>(cx: &LateContext<'tcx>, body: &'tcx hir::Body<'_>) -> bool { - let mut v = StaticMutVisitor { - cx, - mutates_static: false, - }; - intravisit::walk_expr(&mut v, &body.value); - v.mutates_static -} diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs deleted file mode 100644 index eb5857348fd3..000000000000 --- a/clippy_lints/src/future_not_send.rs +++ /dev/null @@ -1,111 +0,0 @@ -use crate::utils; -use rustc_hir::intravisit::FnKind; -use rustc_hir::{Body, FnDecl, HirId}; -use rustc_infer::infer::TyCtxtInferExt; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::subst::Subst; -use rustc_middle::ty::{Opaque, PredicateAtom::Trait}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::{sym, Span}; -use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt; -use rustc_trait_selection::traits::{self, FulfillmentError, TraitEngine}; - -declare_clippy_lint! { - /// **What it does:** This lint requires Future implementations returned from - /// functions and methods to implement the `Send` marker trait. It is mostly - /// used by library authors (public and internal) that target an audience where - /// multithreaded executors are likely to be used for running these Futures. - /// - /// **Why is this bad?** A Future implementation captures some state that it - /// needs to eventually produce its final value. When targeting a multithreaded - /// executor (which is the norm on non-embedded devices) this means that this - /// state may need to be transported to other threads, in other words the - /// whole Future needs to implement the `Send` marker trait. If it does not, - /// then the resulting Future cannot be submitted to a thread pool in the - /// end user’s code. - /// - /// Especially for generic functions it can be confusing to leave the - /// discovery of this problem to the end user: the reported error location - /// will be far from its cause and can in many cases not even be fixed without - /// modifying the library where the offending Future implementation is - /// produced. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// async fn not_send(bytes: std::rc::Rc<[u8]>) {} - /// ``` - /// Use instead: - /// ```rust - /// async fn is_send(bytes: std::sync::Arc<[u8]>) {} - /// ``` - pub FUTURE_NOT_SEND, - nursery, - "public Futures must be Send" -} - -declare_lint_pass!(FutureNotSend => [FUTURE_NOT_SEND]); - -impl<'tcx> LateLintPass<'tcx> for FutureNotSend { - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - kind: FnKind<'tcx>, - decl: &'tcx FnDecl<'tcx>, - _: &'tcx Body<'tcx>, - _: Span, - hir_id: HirId, - ) { - if let FnKind::Closure(_) = kind { - return; - } - let ret_ty = utils::return_ty(cx, hir_id); - if let Opaque(id, subst) = *ret_ty.kind() { - let preds = cx.tcx.explicit_item_bounds(id); - let mut is_future = false; - for &(p, _span) in preds { - let p = p.subst(cx.tcx, subst); - if let Some(trait_ref) = p.to_opt_poly_trait_ref() { - if Some(trait_ref.value.def_id()) == cx.tcx.lang_items().future_trait() { - is_future = true; - break; - } - } - } - if is_future { - let send_trait = cx.tcx.get_diagnostic_item(sym::send_trait).unwrap(); - let span = decl.output.span(); - let send_result = cx.tcx.infer_ctxt().enter(|infcx| { - let cause = traits::ObligationCause::misc(span, hir_id); - let mut fulfillment_cx = traits::FulfillmentContext::new(); - fulfillment_cx.register_bound(&infcx, cx.param_env, ret_ty, send_trait, cause); - fulfillment_cx.select_all_or_error(&infcx) - }); - if let Err(send_errors) = send_result { - utils::span_lint_and_then( - cx, - FUTURE_NOT_SEND, - span, - "future cannot be sent between threads safely", - |db| { - cx.tcx.infer_ctxt().enter(|infcx| { - for FulfillmentError { obligation, .. } in send_errors { - infcx.maybe_note_obligation_cause_for_async_await(db, &obligation); - if let Trait(trait_pred, _) = obligation.predicate.skip_binders() { - db.note(&format!( - "`{}` doesn't implement `{}`", - trait_pred.self_ty(), - trait_pred.trait_ref.print_only_trait_path(), - )); - } - } - }) - }, - ); - } - } - } - } -} diff --git a/clippy_lints/src/get_last_with_len.rs b/clippy_lints/src/get_last_with_len.rs deleted file mode 100644 index cdd8a42e7cd1..000000000000 --- a/clippy_lints/src/get_last_with_len.rs +++ /dev/null @@ -1,104 +0,0 @@ -//! lint on using `x.get(x.len() - 1)` instead of `x.last()` - -use crate::utils::{is_type_diagnostic_item, snippet_with_applicability, span_lint_and_sugg, SpanlessEq}; -use if_chain::if_chain; -use rustc_ast::ast::LitKind; -use rustc_errors::Applicability; -use rustc_hir::{BinOpKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Spanned; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** Checks for using `x.get(x.len() - 1)` instead of - /// `x.last()`. - /// - /// **Why is this bad?** Using `x.last()` is easier to read and has the same - /// result. - /// - /// Note that using `x[x.len() - 1]` is semantically different from - /// `x.last()`. Indexing into the array will panic on out-of-bounds - /// accesses, while `x.get()` and `x.last()` will return `None`. - /// - /// There is another lint (get_unwrap) that covers the case of using - /// `x.get(index).unwrap()` instead of `x[index]`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// // Bad - /// let x = vec![2, 3, 5]; - /// let last_element = x.get(x.len() - 1); - /// - /// // Good - /// let x = vec![2, 3, 5]; - /// let last_element = x.last(); - /// ``` - pub GET_LAST_WITH_LEN, - complexity, - "Using `x.get(x.len() - 1)` when `x.last()` is correct and simpler" -} - -declare_lint_pass!(GetLastWithLen => [GET_LAST_WITH_LEN]); - -impl<'tcx> LateLintPass<'tcx> for GetLastWithLen { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if_chain! { - // Is a method call - if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; - - // Method name is "get" - if path.ident.name == sym!(get); - - // Argument 0 (the struct we're calling the method on) is a vector - if let Some(struct_calling_on) = args.get(0); - let struct_ty = cx.typeck_results().expr_ty(struct_calling_on); - if is_type_diagnostic_item(cx, struct_ty, sym::vec_type); - - // Argument to "get" is a subtraction - if let Some(get_index_arg) = args.get(1); - if let ExprKind::Binary( - Spanned { - node: BinOpKind::Sub, - .. - }, - lhs, - rhs, - ) = &get_index_arg.kind; - - // LHS of subtraction is "x.len()" - if let ExprKind::MethodCall(arg_lhs_path, _, lhs_args, _) = &lhs.kind; - if arg_lhs_path.ident.name == sym!(len); - if let Some(arg_lhs_struct) = lhs_args.get(0); - - // The two vectors referenced (x in x.get(...) and in x.len()) - if SpanlessEq::new(cx).eq_expr(struct_calling_on, arg_lhs_struct); - - // RHS of subtraction is 1 - if let ExprKind::Lit(rhs_lit) = &rhs.kind; - if let LitKind::Int(1, ..) = rhs_lit.node; - - then { - let mut applicability = Applicability::MachineApplicable; - let vec_name = snippet_with_applicability( - cx, - struct_calling_on.span, "vec", - &mut applicability, - ); - - span_lint_and_sugg( - cx, - GET_LAST_WITH_LEN, - expr.span, - &format!("accessing last element with `{0}.get({0}.len() - 1)`", vec_name), - "try", - format!("{}.last()", vec_name), - applicability, - ); - } - } - } -} diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs deleted file mode 100644 index 8501d3477020..000000000000 --- a/clippy_lints/src/identity_op.rs +++ /dev/null @@ -1,100 +0,0 @@ -use if_chain::if_chain; -use rustc_hir::{BinOp, BinOpKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; - -use crate::consts::{constant_simple, Constant}; -use crate::utils::{clip, snippet, span_lint, unsext}; - -declare_clippy_lint! { - /// **What it does:** Checks for identity operations, e.g., `x + 0`. - /// - /// **Why is this bad?** This code can be removed without changing the - /// meaning. So it just obscures what's going on. Delete it mercilessly. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let x = 1; - /// x / 1 + 0 * 1 - 0 | 0; - /// ``` - pub IDENTITY_OP, - complexity, - "using identity operations, e.g., `x + 0` or `y / 1`" -} - -declare_lint_pass!(IdentityOp => [IDENTITY_OP]); - -impl<'tcx> LateLintPass<'tcx> for IdentityOp { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if e.span.from_expansion() { - return; - } - if let ExprKind::Binary(cmp, ref left, ref right) = e.kind { - if is_allowed(cx, cmp, left, right) { - return; - } - match cmp.node { - BinOpKind::Add | BinOpKind::BitOr | BinOpKind::BitXor => { - check(cx, left, 0, e.span, right.span); - check(cx, right, 0, e.span, left.span); - }, - BinOpKind::Shl | BinOpKind::Shr | BinOpKind::Sub => check(cx, right, 0, e.span, left.span), - BinOpKind::Mul => { - check(cx, left, 1, e.span, right.span); - check(cx, right, 1, e.span, left.span); - }, - BinOpKind::Div => check(cx, right, 1, e.span, left.span), - BinOpKind::BitAnd => { - check(cx, left, -1, e.span, right.span); - check(cx, right, -1, e.span, left.span); - }, - _ => (), - } - } - } -} - -fn is_allowed(cx: &LateContext<'_>, cmp: BinOp, left: &Expr<'_>, right: &Expr<'_>) -> bool { - // `1 << 0` is a common pattern in bit manipulation code - if_chain! { - if let BinOpKind::Shl = cmp.node; - if let Some(Constant::Int(0)) = constant_simple(cx, cx.typeck_results(), right); - if let Some(Constant::Int(1)) = constant_simple(cx, cx.typeck_results(), left); - then { - return true; - } - } - - false -} - -#[allow(clippy::cast_possible_wrap)] -fn check(cx: &LateContext<'_>, e: &Expr<'_>, m: i8, span: Span, arg: Span) { - if let Some(Constant::Int(v)) = constant_simple(cx, cx.typeck_results(), e) { - let check = match *cx.typeck_results().expr_ty(e).kind() { - ty::Int(ity) => unsext(cx.tcx, -1_i128, ity), - ty::Uint(uty) => clip(cx.tcx, !0, uty), - _ => return, - }; - if match m { - 0 => v == 0, - -1 => v == check, - 1 => v == 1, - _ => unreachable!(), - } { - span_lint( - cx, - IDENTITY_OP, - span, - &format!( - "the operation is ineffective. Consider reducing it to `{}`", - snippet(cx, arg, "..") - ), - ); - } - } -} diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs deleted file mode 100644 index 2e55094d90c6..000000000000 --- a/clippy_lints/src/if_let_mutex.rs +++ /dev/null @@ -1,157 +0,0 @@ -use crate::utils::{is_type_diagnostic_item, span_lint_and_help, SpanlessEq}; -use if_chain::if_chain; -use rustc_hir::intravisit::{self as visit, NestedVisitorMap, Visitor}; -use rustc_hir::{Expr, ExprKind, MatchSource}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for `Mutex::lock` calls in `if let` expression - /// with lock calls in any of the else blocks. - /// - /// **Why is this bad?** The Mutex lock remains held for the whole - /// `if let ... else` block and deadlocks. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust,ignore - /// if let Ok(thing) = mutex.lock() { - /// do_thing(); - /// } else { - /// mutex.lock(); - /// } - /// ``` - /// Should be written - /// ```rust,ignore - /// let locked = mutex.lock(); - /// if let Ok(thing) = locked { - /// do_thing(thing); - /// } else { - /// use_locked(locked); - /// } - /// ``` - pub IF_LET_MUTEX, - correctness, - "locking a `Mutex` in an `if let` block can cause deadlocks" -} - -declare_lint_pass!(IfLetMutex => [IF_LET_MUTEX]); - -impl<'tcx> LateLintPass<'tcx> for IfLetMutex { - fn check_expr(&mut self, cx: &LateContext<'tcx>, ex: &'tcx Expr<'tcx>) { - let mut arm_visit = ArmVisitor { - mutex_lock_called: false, - found_mutex: None, - cx, - }; - let mut op_visit = OppVisitor { - mutex_lock_called: false, - found_mutex: None, - cx, - }; - if let ExprKind::Match( - ref op, - ref arms, - MatchSource::IfLetDesugar { - contains_else_clause: true, - }, - ) = ex.kind - { - op_visit.visit_expr(op); - if op_visit.mutex_lock_called { - for arm in *arms { - arm_visit.visit_arm(arm); - } - - if arm_visit.mutex_lock_called && arm_visit.same_mutex(cx, op_visit.found_mutex.unwrap()) { - span_lint_and_help( - cx, - IF_LET_MUTEX, - ex.span, - "calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock", - None, - "move the lock call outside of the `if let ...` expression", - ); - } - } - } - } -} - -/// Checks if `Mutex::lock` is called in the `if let _ = expr. -pub struct OppVisitor<'a, 'tcx> { - mutex_lock_called: bool, - found_mutex: Option<&'tcx Expr<'tcx>>, - cx: &'a LateContext<'tcx>, -} - -impl<'tcx> Visitor<'tcx> for OppVisitor<'_, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if_chain! { - if let Some(mutex) = is_mutex_lock_call(self.cx, expr); - then { - self.found_mutex = Some(mutex); - self.mutex_lock_called = true; - return; - } - } - visit::walk_expr(self, expr); - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -/// Checks if `Mutex::lock` is called in any of the branches. -pub struct ArmVisitor<'a, 'tcx> { - mutex_lock_called: bool, - found_mutex: Option<&'tcx Expr<'tcx>>, - cx: &'a LateContext<'tcx>, -} - -impl<'tcx> Visitor<'tcx> for ArmVisitor<'_, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { - if_chain! { - if let Some(mutex) = is_mutex_lock_call(self.cx, expr); - then { - self.found_mutex = Some(mutex); - self.mutex_lock_called = true; - return; - } - } - visit::walk_expr(self, expr); - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -impl<'tcx, 'l> ArmVisitor<'tcx, 'l> { - fn same_mutex(&self, cx: &LateContext<'_>, op_mutex: &Expr<'_>) -> bool { - self.found_mutex - .map_or(false, |arm_mutex| SpanlessEq::new(cx).eq_expr(op_mutex, arm_mutex)) - } -} - -fn is_mutex_lock_call<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { - if_chain! { - if let ExprKind::MethodCall(path, _span, args, _) = &expr.kind; - if path.ident.to_string() == "lock"; - let ty = cx.typeck_results().expr_ty(&args[0]); - if is_type_diagnostic_item(cx, ty, sym!(mutex_type)); - then { - Some(&args[0]) - } else { - None - } - } -} diff --git a/clippy_lints/src/if_let_some_result.rs b/clippy_lints/src/if_let_some_result.rs deleted file mode 100644 index 1194bd7e55e2..000000000000 --- a/clippy_lints/src/if_let_some_result.rs +++ /dev/null @@ -1,72 +0,0 @@ -use crate::utils::{is_type_diagnostic_item, method_chain_args, snippet_with_applicability, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, MatchSource, PatKind, QPath}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:*** Checks for unnecessary `ok()` in if let. - /// - /// **Why is this bad?** Calling `ok()` in if let is unnecessary, instead match - /// on `Ok(pat)` - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// for i in iter { - /// if let Some(value) = i.parse().ok() { - /// vec.push(value) - /// } - /// } - /// ``` - /// Could be written: - /// - /// ```ignore - /// for i in iter { - /// if let Ok(value) = i.parse() { - /// vec.push(value) - /// } - /// } - /// ``` - pub IF_LET_SOME_RESULT, - style, - "usage of `ok()` in `if let Some(pat)` statements is unnecessary, match on `Ok(pat)` instead" -} - -declare_lint_pass!(OkIfLet => [IF_LET_SOME_RESULT]); - -impl<'tcx> LateLintPass<'tcx> for OkIfLet { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if_chain! { //begin checking variables - if let ExprKind::Match(ref op, ref body, MatchSource::IfLetDesugar { .. }) = expr.kind; //test if expr is if let - if let ExprKind::MethodCall(_, ok_span, ref result_types, _) = op.kind; //check is expr.ok() has type Result.ok(, _) - if let PatKind::TupleStruct(QPath::Resolved(_, ref x), ref y, _) = body[0].pat.kind; //get operation - if method_chain_args(op, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized; - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&result_types[0]), sym::result_type); - if rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(x, false)) == "Some"; - - then { - let mut applicability = Applicability::MachineApplicable; - let some_expr_string = snippet_with_applicability(cx, y[0].span, "", &mut applicability); - let trimmed_ok = snippet_with_applicability(cx, op.span.until(ok_span), "", &mut applicability); - let sugg = format!( - "if let Ok({}) = {}", - some_expr_string, - trimmed_ok.trim().trim_end_matches('.'), - ); - span_lint_and_sugg( - cx, - IF_LET_SOME_RESULT, - expr.span.with_hi(op.span.hi()), - "matching on `Some` with `ok()` is redundant", - &format!("consider matching on `Ok({})` and removing the call to `ok` instead", some_expr_string), - sugg, - applicability, - ); - } - } - } -} diff --git a/clippy_lints/src/if_not_else.rs b/clippy_lints/src/if_not_else.rs deleted file mode 100644 index b86d2e766566..000000000000 --- a/clippy_lints/src/if_not_else.rs +++ /dev/null @@ -1,83 +0,0 @@ -//! lint on if branches that could be swapped so no `!` operation is necessary -//! on the condition - -use rustc_ast::ast::{BinOpKind, Expr, ExprKind, UnOp}; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -use crate::utils::span_lint_and_help; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `!` or `!=` in an if condition with an - /// else branch. - /// - /// **Why is this bad?** Negations reduce the readability of statements. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let v: Vec = vec![]; - /// # fn a() {} - /// # fn b() {} - /// if !v.is_empty() { - /// a() - /// } else { - /// b() - /// } - /// ``` - /// - /// Could be written: - /// - /// ```rust - /// # let v: Vec = vec![]; - /// # fn a() {} - /// # fn b() {} - /// if v.is_empty() { - /// b() - /// } else { - /// a() - /// } - /// ``` - pub IF_NOT_ELSE, - pedantic, - "`if` branches that could be swapped so no negation operation is necessary on the condition" -} - -declare_lint_pass!(IfNotElse => [IF_NOT_ELSE]); - -impl EarlyLintPass for IfNotElse { - fn check_expr(&mut self, cx: &EarlyContext<'_>, item: &Expr) { - if in_external_macro(cx.sess(), item.span) { - return; - } - if let ExprKind::If(ref cond, _, Some(ref els)) = item.kind { - if let ExprKind::Block(..) = els.kind { - match cond.kind { - ExprKind::Unary(UnOp::Not, _) => { - span_lint_and_help( - cx, - IF_NOT_ELSE, - item.span, - "unnecessary boolean `not` operation", - None, - "remove the `!` and swap the blocks of the `if`/`else`", - ); - }, - ExprKind::Binary(ref kind, _, _) if kind.node == BinOpKind::Ne => { - span_lint_and_help( - cx, - IF_NOT_ELSE, - item.span, - "unnecessary `!=` operation", - None, - "change to `==` and swap the blocks of the `if`/`else`", - ); - }, - _ => (), - } - } - } - } -} diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs deleted file mode 100644 index 03e95c9e27f6..000000000000 --- a/clippy_lints/src/implicit_return.rs +++ /dev/null @@ -1,144 +0,0 @@ -use crate::utils::{fn_has_unsatisfiable_preds, match_panic_def_id, snippet_opt, span_lint_and_then}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::intravisit::FnKind; -use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, MatchSource, StmtKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for missing return statements at the end of a block. - /// - /// **Why is this bad?** Actually omitting the return keyword is idiomatic Rust code. Programmers - /// coming from other languages might prefer the expressiveness of `return`. It's possible to miss - /// the last returning statement because the only difference is a missing `;`. Especially in bigger - /// code with multiple return paths having a `return` keyword makes it easier to find the - /// corresponding statements. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// fn foo(x: usize) -> usize { - /// x - /// } - /// ``` - /// add return - /// ```rust - /// fn foo(x: usize) -> usize { - /// return x; - /// } - /// ``` - pub IMPLICIT_RETURN, - restriction, - "use a return statement like `return expr` instead of an expression" -} - -declare_lint_pass!(ImplicitReturn => [IMPLICIT_RETURN]); - -static LINT_BREAK: &str = "change `break` to `return` as shown"; -static LINT_RETURN: &str = "add `return` as shown"; - -fn lint(cx: &LateContext<'_>, outer_span: Span, inner_span: Span, msg: &str) { - let outer_span = outer_span.source_callsite(); - let inner_span = inner_span.source_callsite(); - - span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing `return` statement", |diag| { - if let Some(snippet) = snippet_opt(cx, inner_span) { - diag.span_suggestion( - outer_span, - msg, - format!("return {}", snippet), - Applicability::MachineApplicable, - ); - } - }); -} - -fn expr_match(cx: &LateContext<'_>, expr: &Expr<'_>) { - match expr.kind { - // loops could be using `break` instead of `return` - ExprKind::Block(block, ..) | ExprKind::Loop(block, ..) => { - if let Some(expr) = &block.expr { - expr_match(cx, expr); - } - // only needed in the case of `break` with `;` at the end - else if let Some(stmt) = block.stmts.last() { - if_chain! { - if let StmtKind::Semi(expr, ..) = &stmt.kind; - // make sure it's a break, otherwise we want to skip - if let ExprKind::Break(.., Some(break_expr)) = &expr.kind; - then { - lint(cx, expr.span, break_expr.span, LINT_BREAK); - } - } - } - }, - // use `return` instead of `break` - ExprKind::Break(.., break_expr) => { - if let Some(break_expr) = break_expr { - lint(cx, expr.span, break_expr.span, LINT_BREAK); - } - }, - ExprKind::Match(.., arms, source) => { - let check_all_arms = match source { - MatchSource::IfLetDesugar { - contains_else_clause: has_else, - } => has_else, - _ => true, - }; - - if check_all_arms { - for arm in arms { - expr_match(cx, &arm.body); - } - } else { - expr_match(cx, &arms.first().expect("`if let` doesn't have a single arm").body); - } - }, - // skip if it already has a return statement - ExprKind::Ret(..) => (), - // make sure it's not a call that panics - ExprKind::Call(expr, ..) => { - if_chain! { - if let ExprKind::Path(qpath) = &expr.kind; - if let Some(path_def_id) = cx.qpath_res(qpath, expr.hir_id).opt_def_id(); - if match_panic_def_id(cx, path_def_id); - then { } - else { - lint(cx, expr.span, expr.span, LINT_RETURN) - } - } - }, - // everything else is missing `return` - _ => lint(cx, expr.span, expr.span, LINT_RETURN), - } -} - -impl<'tcx> LateLintPass<'tcx> for ImplicitReturn { - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - _: FnKind<'tcx>, - _: &'tcx FnDecl<'_>, - body: &'tcx Body<'_>, - span: Span, - _: HirId, - ) { - let def_id = cx.tcx.hir().body_owner_def_id(body.id()); - - // Building MIR for `fn`s with unsatisfiable preds results in ICE. - if fn_has_unsatisfiable_preds(cx, def_id.to_def_id()) { - return; - } - - let mir = cx.tcx.optimized_mir(def_id.to_def_id()); - - // checking return type through MIR, HIR is not able to determine inferred closure return types - // make sure it's not a macro - if !mir.return_ty().is_unit() && !span.from_expansion() { - expr_match(cx, &body.value); - } - } -} diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs deleted file mode 100644 index 3a01acd8fdc9..000000000000 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ /dev/null @@ -1,165 +0,0 @@ -use crate::utils::{higher, in_macro, match_qpath, span_lint_and_sugg, SpanlessEq}; -use if_chain::if_chain; -use rustc_ast::ast::LitKind; -use rustc_errors::Applicability; -use rustc_hir::{BinOpKind, Expr, ExprKind, QPath, StmtKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for implicit saturating subtraction. - /// - /// **Why is this bad?** Simplicity and readability. Instead we can easily use an builtin function. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// let end: u32 = 10; - /// let start: u32 = 5; - /// - /// let mut i: u32 = end - start; - /// - /// // Bad - /// if i != 0 { - /// i -= 1; - /// } - /// - /// // Good - /// i = i.saturating_sub(1); - /// ``` - pub IMPLICIT_SATURATING_SUB, - pedantic, - "Perform saturating subtraction instead of implicitly checking lower bound of data type" -} - -declare_lint_pass!(ImplicitSaturatingSub => [IMPLICIT_SATURATING_SUB]); - -impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - if in_macro(expr.span) { - return; - } - if_chain! { - if let Some((ref cond, ref then, None)) = higher::if_block(&expr); - - // Check if the conditional expression is a binary operation - if let ExprKind::Binary(ref cond_op, ref cond_left, ref cond_right) = cond.kind; - - // Ensure that the binary operator is >, != and < - if BinOpKind::Ne == cond_op.node || BinOpKind::Gt == cond_op.node || BinOpKind::Lt == cond_op.node; - - // Check if the true condition block has only one statement - if let ExprKind::Block(ref block, _) = then.kind; - if block.stmts.len() == 1 && block.expr.is_none(); - - // Check if assign operation is done - if let StmtKind::Semi(ref e) = block.stmts[0].kind; - if let Some(target) = subtracts_one(cx, e); - - // Extracting out the variable name - if let ExprKind::Path(QPath::Resolved(_, ref ares_path)) = target.kind; - - then { - // Handle symmetric conditions in the if statement - let (cond_var, cond_num_val) = if SpanlessEq::new(cx).eq_expr(cond_left, target) { - if BinOpKind::Gt == cond_op.node || BinOpKind::Ne == cond_op.node { - (cond_left, cond_right) - } else { - return; - } - } else if SpanlessEq::new(cx).eq_expr(cond_right, target) { - if BinOpKind::Lt == cond_op.node || BinOpKind::Ne == cond_op.node { - (cond_right, cond_left) - } else { - return; - } - } else { - return; - }; - - // Check if the variable in the condition statement is an integer - if !cx.typeck_results().expr_ty(cond_var).is_integral() { - return; - } - - // Get the variable name - let var_name = ares_path.segments[0].ident.name.as_str(); - const INT_TYPES: [&str; 5] = ["i8", "i16", "i32", "i64", "i128"]; - - match cond_num_val.kind { - ExprKind::Lit(ref cond_lit) => { - // Check if the constant is zero - if let LitKind::Int(0, _) = cond_lit.node { - if cx.typeck_results().expr_ty(cond_left).is_signed() { - } else { - print_lint_and_sugg(cx, &var_name, expr); - }; - } - }, - ExprKind::Path(ref cond_num_path) => { - if INT_TYPES.iter().any(|int_type| match_qpath(cond_num_path, &[int_type, "MIN"])) { - print_lint_and_sugg(cx, &var_name, expr); - }; - }, - ExprKind::Call(ref func, _) => { - if let ExprKind::Path(ref cond_num_path) = func.kind { - if INT_TYPES.iter().any(|int_type| match_qpath(cond_num_path, &[int_type, "min_value"])) { - print_lint_and_sugg(cx, &var_name, expr); - } - }; - }, - _ => (), - } - } - } - } -} - -fn subtracts_one<'a>(cx: &LateContext<'_>, expr: &Expr<'a>) -> Option<&'a Expr<'a>> { - match expr.kind { - ExprKind::AssignOp(ref op1, ref target, ref value) => { - if_chain! { - if BinOpKind::Sub == op1.node; - // Check if literal being subtracted is one - if let ExprKind::Lit(ref lit1) = value.kind; - if let LitKind::Int(1, _) = lit1.node; - then { - Some(target) - } else { - None - } - } - }, - ExprKind::Assign(ref target, ref value, _) => { - if_chain! { - if let ExprKind::Binary(ref op1, ref left1, ref right1) = value.kind; - if BinOpKind::Sub == op1.node; - - if SpanlessEq::new(cx).eq_expr(left1, target); - - if let ExprKind::Lit(ref lit1) = right1.kind; - if let LitKind::Int(1, _) = lit1.node; - then { - Some(target) - } else { - None - } - } - }, - _ => None, - } -} - -fn print_lint_and_sugg(cx: &LateContext<'_>, var_name: &str, expr: &Expr<'_>) { - span_lint_and_sugg( - cx, - IMPLICIT_SATURATING_SUB, - expr.span, - "implicitly performing saturating subtraction", - "try", - format!("{} = {}.saturating_sub({});", var_name, var_name, '1'), - Applicability::MachineApplicable, - ); -} diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs deleted file mode 100644 index 741195f3b10d..000000000000 --- a/clippy_lints/src/indexing_slicing.rs +++ /dev/null @@ -1,197 +0,0 @@ -//! lint on indexing and slicing operations - -use crate::consts::{constant, Constant}; -use crate::utils::{higher, span_lint, span_lint_and_help}; -use rustc_ast::ast::RangeLimits; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for out of bounds array indexing with a constant - /// index. - /// - /// **Why is this bad?** This will always panic at runtime. - /// - /// **Known problems:** Hopefully none. - /// - /// **Example:** - /// ```no_run - /// # #![allow(const_err)] - /// let x = [1, 2, 3, 4]; - /// - /// // Bad - /// x[9]; - /// &x[2..9]; - /// - /// // Good - /// x[0]; - /// x[3]; - /// ``` - pub OUT_OF_BOUNDS_INDEXING, - correctness, - "out of bounds constant indexing" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of indexing or slicing. Arrays are special cases, this lint - /// does report on arrays if we can tell that slicing operations are in bounds and does not - /// lint on constant `usize` indexing on arrays because that is handled by rustc's `const_err` lint. - /// - /// **Why is this bad?** Indexing and slicing can panic at runtime and there are - /// safe alternatives. - /// - /// **Known problems:** Hopefully none. - /// - /// **Example:** - /// ```rust,no_run - /// // Vector - /// let x = vec![0; 5]; - /// - /// // Bad - /// x[2]; - /// &x[2..100]; - /// &x[2..]; - /// &x[..100]; - /// - /// // Good - /// x.get(2); - /// x.get(2..100); - /// x.get(2..); - /// x.get(..100); - /// - /// // Array - /// let y = [0, 1, 2, 3]; - /// - /// // Bad - /// &y[10..100]; - /// &y[10..]; - /// &y[..100]; - /// - /// // Good - /// &y[2..]; - /// &y[..2]; - /// &y[0..3]; - /// y.get(10); - /// y.get(10..100); - /// y.get(10..); - /// y.get(..100); - /// ``` - pub INDEXING_SLICING, - restriction, - "indexing/slicing usage" -} - -declare_lint_pass!(IndexingSlicing => [INDEXING_SLICING, OUT_OF_BOUNDS_INDEXING]); - -impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Index(ref array, ref index) = &expr.kind { - let ty = cx.typeck_results().expr_ty(array).peel_refs(); - if let Some(range) = higher::range(index) { - // Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..] - if let ty::Array(_, s) = ty.kind() { - let size: u128 = if let Some(size) = s.try_eval_usize(cx.tcx, cx.param_env) { - size.into() - } else { - return; - }; - - let const_range = to_const_range(cx, range, size); - - if let (Some(start), _) = const_range { - if start > size { - span_lint( - cx, - OUT_OF_BOUNDS_INDEXING, - range.start.map_or(expr.span, |start| start.span), - "range is out of bounds", - ); - return; - } - } - - if let (_, Some(end)) = const_range { - if end > size { - span_lint( - cx, - OUT_OF_BOUNDS_INDEXING, - range.end.map_or(expr.span, |end| end.span), - "range is out of bounds", - ); - return; - } - } - - if let (Some(_), Some(_)) = const_range { - // early return because both start and end are constants - // and we have proven above that they are in bounds - return; - } - } - - let help_msg = match (range.start, range.end) { - (None, Some(_)) => "Consider using `.get(..n)`or `.get_mut(..n)` instead", - (Some(_), None) => "Consider using `.get(n..)` or .get_mut(n..)` instead", - (Some(_), Some(_)) => "Consider using `.get(n..m)` or `.get_mut(n..m)` instead", - (None, None) => return, // [..] is ok. - }; - - span_lint_and_help(cx, INDEXING_SLICING, expr.span, "slicing may panic.", None, help_msg); - } else { - // Catchall non-range index, i.e., [n] or [n << m] - if let ty::Array(..) = ty.kind() { - // Index is a constant uint. - if let Some(..) = constant(cx, cx.typeck_results(), index) { - // Let rustc's `const_err` lint handle constant `usize` indexing on arrays. - return; - } - } - - span_lint_and_help( - cx, - INDEXING_SLICING, - expr.span, - "indexing may panic.", - None, - "Consider using `.get(n)` or `.get_mut(n)` instead", - ); - } - } - } -} - -/// Returns a tuple of options with the start and end (exclusive) values of -/// the range. If the start or end is not constant, None is returned. -fn to_const_range<'tcx>( - cx: &LateContext<'tcx>, - range: higher::Range<'_>, - array_size: u128, -) -> (Option, Option) { - let s = range - .start - .map(|expr| constant(cx, cx.typeck_results(), expr).map(|(c, _)| c)); - let start = match s { - Some(Some(Constant::Int(x))) => Some(x), - Some(_) => None, - None => Some(0), - }; - - let e = range - .end - .map(|expr| constant(cx, cx.typeck_results(), expr).map(|(c, _)| c)); - let end = match e { - Some(Some(Constant::Int(x))) => { - if range.limits == RangeLimits::Closed { - Some(x + 1) - } else { - Some(x) - } - }, - Some(_) => None, - None => Some(array_size), - }; - - (start, end) -} diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs deleted file mode 100644 index 129abd7d8974..000000000000 --- a/clippy_lints/src/infinite_iter.rs +++ /dev/null @@ -1,254 +0,0 @@ -use rustc_hir::{BorrowKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -use crate::utils::{get_trait_def_id, higher, implements_trait, match_qpath, match_type, paths, span_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for iteration that is guaranteed to be infinite. - /// - /// **Why is this bad?** While there may be places where this is acceptable - /// (e.g., in event streams), in most cases this is simply an error. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```no_run - /// use std::iter; - /// - /// iter::repeat(1_u8).collect::>(); - /// ``` - pub INFINITE_ITER, - correctness, - "infinite iteration" -} - -declare_clippy_lint! { - /// **What it does:** Checks for iteration that may be infinite. - /// - /// **Why is this bad?** While there may be places where this is acceptable - /// (e.g., in event streams), in most cases this is simply an error. - /// - /// **Known problems:** The code may have a condition to stop iteration, but - /// this lint is not clever enough to analyze it. - /// - /// **Example:** - /// ```rust - /// let infinite_iter = 0..; - /// [0..].iter().zip(infinite_iter.take_while(|x| *x > 5)); - /// ``` - pub MAYBE_INFINITE_ITER, - pedantic, - "possible infinite iteration" -} - -declare_lint_pass!(InfiniteIter => [INFINITE_ITER, MAYBE_INFINITE_ITER]); - -impl<'tcx> LateLintPass<'tcx> for InfiniteIter { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - let (lint, msg) = match complete_infinite_iter(cx, expr) { - Infinite => (INFINITE_ITER, "infinite iteration detected"), - MaybeInfinite => (MAYBE_INFINITE_ITER, "possible infinite iteration detected"), - Finite => { - return; - }, - }; - span_lint(cx, lint, expr.span, msg) - } -} - -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -enum Finiteness { - Infinite, - MaybeInfinite, - Finite, -} - -use self::Finiteness::{Finite, Infinite, MaybeInfinite}; - -impl Finiteness { - #[must_use] - fn and(self, b: Self) -> Self { - match (self, b) { - (Finite, _) | (_, Finite) => Finite, - (MaybeInfinite, _) | (_, MaybeInfinite) => MaybeInfinite, - _ => Infinite, - } - } - - #[must_use] - fn or(self, b: Self) -> Self { - match (self, b) { - (Infinite, _) | (_, Infinite) => Infinite, - (MaybeInfinite, _) | (_, MaybeInfinite) => MaybeInfinite, - _ => Finite, - } - } -} - -impl From for Finiteness { - #[must_use] - fn from(b: bool) -> Self { - if b { - Infinite - } else { - Finite - } - } -} - -/// This tells us what to look for to know if the iterator returned by -/// this method is infinite -#[derive(Copy, Clone)] -enum Heuristic { - /// infinite no matter what - Always, - /// infinite if the first argument is - First, - /// infinite if any of the supplied arguments is - Any, - /// infinite if all of the supplied arguments are - All, -} - -use self::Heuristic::{All, Always, Any, First}; - -/// a slice of (method name, number of args, heuristic, bounds) tuples -/// that will be used to determine whether the method in question -/// returns an infinite or possibly infinite iterator. The finiteness -/// is an upper bound, e.g., some methods can return a possibly -/// infinite iterator at worst, e.g., `take_while`. -const HEURISTICS: [(&str, usize, Heuristic, Finiteness); 19] = [ - ("zip", 2, All, Infinite), - ("chain", 2, Any, Infinite), - ("cycle", 1, Always, Infinite), - ("map", 2, First, Infinite), - ("by_ref", 1, First, Infinite), - ("cloned", 1, First, Infinite), - ("rev", 1, First, Infinite), - ("inspect", 1, First, Infinite), - ("enumerate", 1, First, Infinite), - ("peekable", 2, First, Infinite), - ("fuse", 1, First, Infinite), - ("skip", 2, First, Infinite), - ("skip_while", 1, First, Infinite), - ("filter", 2, First, Infinite), - ("filter_map", 2, First, Infinite), - ("flat_map", 2, First, Infinite), - ("unzip", 1, First, Infinite), - ("take_while", 2, First, MaybeInfinite), - ("scan", 3, First, MaybeInfinite), -]; - -fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { - match expr.kind { - ExprKind::MethodCall(ref method, _, ref args, _) => { - for &(name, len, heuristic, cap) in &HEURISTICS { - if method.ident.name.as_str() == name && args.len() == len { - return (match heuristic { - Always => Infinite, - First => is_infinite(cx, &args[0]), - Any => is_infinite(cx, &args[0]).or(is_infinite(cx, &args[1])), - All => is_infinite(cx, &args[0]).and(is_infinite(cx, &args[1])), - }) - .and(cap); - } - } - if method.ident.name == sym!(flat_map) && args.len() == 2 { - if let ExprKind::Closure(_, _, body_id, _, _) = args[1].kind { - let body = cx.tcx.hir().body(body_id); - return is_infinite(cx, &body.value); - } - } - Finite - }, - ExprKind::Block(ref block, _) => block.expr.as_ref().map_or(Finite, |e| is_infinite(cx, e)), - ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) => is_infinite(cx, e), - ExprKind::Call(ref path, _) => { - if let ExprKind::Path(ref qpath) = path.kind { - match_qpath(qpath, &paths::REPEAT).into() - } else { - Finite - } - }, - ExprKind::Struct(..) => higher::range(expr).map_or(false, |r| r.end.is_none()).into(), - _ => Finite, - } -} - -/// the names and argument lengths of methods that *may* exhaust their -/// iterators -const POSSIBLY_COMPLETING_METHODS: [(&str, usize); 6] = [ - ("find", 2), - ("rfind", 2), - ("position", 2), - ("rposition", 2), - ("any", 2), - ("all", 2), -]; - -/// the names and argument lengths of methods that *always* exhaust -/// their iterators -const COMPLETING_METHODS: [(&str, usize); 12] = [ - ("count", 1), - ("fold", 3), - ("for_each", 2), - ("partition", 2), - ("max", 1), - ("max_by", 2), - ("max_by_key", 2), - ("min", 1), - ("min_by", 2), - ("min_by_key", 2), - ("sum", 1), - ("product", 1), -]; - -/// the paths of types that are known to be infinitely allocating -const INFINITE_COLLECTORS: [&[&str]; 8] = [ - &paths::BINARY_HEAP, - &paths::BTREEMAP, - &paths::BTREESET, - &paths::HASHMAP, - &paths::HASHSET, - &paths::LINKED_LIST, - &paths::VEC, - &paths::VEC_DEQUE, -]; - -fn complete_infinite_iter(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { - match expr.kind { - ExprKind::MethodCall(ref method, _, ref args, _) => { - for &(name, len) in &COMPLETING_METHODS { - if method.ident.name.as_str() == name && args.len() == len { - return is_infinite(cx, &args[0]); - } - } - for &(name, len) in &POSSIBLY_COMPLETING_METHODS { - if method.ident.name.as_str() == name && args.len() == len { - return MaybeInfinite.and(is_infinite(cx, &args[0])); - } - } - if method.ident.name == sym!(last) && args.len() == 1 { - let not_double_ended = get_trait_def_id(cx, &paths::DOUBLE_ENDED_ITERATOR).map_or(false, |id| { - !implements_trait(cx, cx.typeck_results().expr_ty(&args[0]), id, &[]) - }); - if not_double_ended { - return is_infinite(cx, &args[0]); - } - } else if method.ident.name == sym!(collect) { - let ty = cx.typeck_results().expr_ty(expr); - if INFINITE_COLLECTORS.iter().any(|path| match_type(cx, ty, path)) { - return is_infinite(cx, &args[0]); - } - } - }, - ExprKind::Binary(op, ref l, ref r) => { - if op.node.is_comparison() { - return is_infinite(cx, l).and(is_infinite(cx, r)).and(MaybeInfinite); - } - }, // TODO: ExprKind::Loop + Match - _ => (), - } - Finite -} diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs deleted file mode 100644 index 4e6bb6047854..000000000000 --- a/clippy_lints/src/inherent_impl.rs +++ /dev/null @@ -1,94 +0,0 @@ -//! lint on inherent implementations - -use crate::utils::{in_macro, span_lint_and_then}; -use rustc_data_structures::fx::FxHashMap; -use rustc_hir::{def_id, Crate, Item, ItemKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for multiple inherent implementations of a struct - /// - /// **Why is this bad?** Splitting the implementation of a type makes the code harder to navigate. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// struct X; - /// impl X { - /// fn one() {} - /// } - /// impl X { - /// fn other() {} - /// } - /// ``` - /// - /// Could be written: - /// - /// ```rust - /// struct X; - /// impl X { - /// fn one() {} - /// fn other() {} - /// } - /// ``` - pub MULTIPLE_INHERENT_IMPL, - restriction, - "Multiple inherent impl that could be grouped" -} - -#[allow(clippy::module_name_repetitions)] -#[derive(Default)] -pub struct MultipleInherentImpl { - impls: FxHashMap, -} - -impl_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]); - -impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { - fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Impl { - ref generics, - of_trait: None, - .. - } = item.kind - { - // Remember for each inherent implementation encountered its span and generics - // but filter out implementations that have generic params (type or lifetime) - // or are derived from a macro - if !in_macro(item.span) && generics.params.is_empty() { - self.impls.insert(item.hir_id.owner.to_def_id(), item.span); - } - } - } - - fn check_crate_post(&mut self, cx: &LateContext<'tcx>, krate: &'tcx Crate<'_>) { - if let Some(item) = krate.items.values().next() { - // Retrieve all inherent implementations from the crate, grouped by type - for impls in cx - .tcx - .crate_inherent_impls(item.hir_id.owner.to_def_id().krate) - .inherent_impls - .values() - { - // Filter out implementations that have generic params (type or lifetime) - let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def)); - if let Some(initial_span) = impl_spans.next() { - impl_spans.for_each(|additional_span| { - span_lint_and_then( - cx, - MULTIPLE_INHERENT_IMPL, - *additional_span, - "multiple implementations of this structure", - |diag| { - diag.span_note(*initial_span, "first implementation here"); - }, - ) - }) - } - } - } - } -} diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs deleted file mode 100644 index b723d06a6881..000000000000 --- a/clippy_lints/src/inherent_to_string.rs +++ /dev/null @@ -1,157 +0,0 @@ -use if_chain::if_chain; -use rustc_hir::{ImplItem, ImplItemKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; - -use crate::utils::{ - get_trait_def_id, implements_trait, is_type_diagnostic_item, paths, return_ty, span_lint_and_help, - trait_ref_of_method, -}; - -declare_clippy_lint! { - /// **What it does:** Checks for the definition of inherent methods with a signature of `to_string(&self) -> String`. - /// - /// **Why is this bad?** This method is also implicitly defined if a type implements the `Display` trait. As the functionality of `Display` is much more versatile, it should be preferred. - /// - /// **Known problems:** None - /// - /// ** Example:** - /// - /// ```rust - /// // Bad - /// pub struct A; - /// - /// impl A { - /// pub fn to_string(&self) -> String { - /// "I am A".to_string() - /// } - /// } - /// ``` - /// - /// ```rust - /// // Good - /// use std::fmt; - /// - /// pub struct A; - /// - /// impl fmt::Display for A { - /// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - /// write!(f, "I am A") - /// } - /// } - /// ``` - pub INHERENT_TO_STRING, - style, - "type implements inherent method `to_string()`, but should instead implement the `Display` trait" -} - -declare_clippy_lint! { - /// **What it does:** Checks for the definition of inherent methods with a signature of `to_string(&self) -> String` and if the type implementing this method also implements the `Display` trait. - /// - /// **Why is this bad?** This method is also implicitly defined if a type implements the `Display` trait. The less versatile inherent method will then shadow the implementation introduced by `Display`. - /// - /// **Known problems:** None - /// - /// ** Example:** - /// - /// ```rust - /// // Bad - /// use std::fmt; - /// - /// pub struct A; - /// - /// impl A { - /// pub fn to_string(&self) -> String { - /// "I am A".to_string() - /// } - /// } - /// - /// impl fmt::Display for A { - /// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - /// write!(f, "I am A, too") - /// } - /// } - /// ``` - /// - /// ```rust - /// // Good - /// use std::fmt; - /// - /// pub struct A; - /// - /// impl fmt::Display for A { - /// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - /// write!(f, "I am A") - /// } - /// } - /// ``` - pub INHERENT_TO_STRING_SHADOW_DISPLAY, - correctness, - "type implements inherent method `to_string()`, which gets shadowed by the implementation of the `Display` trait" -} - -declare_lint_pass!(InherentToString => [INHERENT_TO_STRING, INHERENT_TO_STRING_SHADOW_DISPLAY]); - -impl<'tcx> LateLintPass<'tcx> for InherentToString { - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { - if impl_item.span.from_expansion() { - return; - } - - if_chain! { - // Check if item is a method, called to_string and has a parameter 'self' - if let ImplItemKind::Fn(ref signature, _) = impl_item.kind; - if impl_item.ident.name.as_str() == "to_string"; - let decl = &signature.decl; - if decl.implicit_self.has_implicit_self(); - if decl.inputs.len() == 1; - - // Check if return type is String - if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::string_type); - - // Filters instances of to_string which are required by a trait - if trait_ref_of_method(cx, impl_item.hir_id).is_none(); - - then { - show_lint(cx, impl_item); - } - } - } -} - -fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) { - let display_trait_id = get_trait_def_id(cx, &paths::DISPLAY_TRAIT).expect("Failed to get trait ID of `Display`!"); - - // Get the real type of 'self' - let fn_def_id = cx.tcx.hir().local_def_id(item.hir_id); - let self_type = cx.tcx.fn_sig(fn_def_id).input(0); - let self_type = self_type.skip_binder().peel_refs(); - - // Emit either a warning or an error - if implements_trait(cx, self_type, display_trait_id, &[]) { - span_lint_and_help( - cx, - INHERENT_TO_STRING_SHADOW_DISPLAY, - item.span, - &format!( - "type `{}` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display`", - self_type.to_string() - ), - None, - &format!("remove the inherent method from type `{}`", self_type.to_string()) - ); - } else { - span_lint_and_help( - cx, - INHERENT_TO_STRING, - item.span, - &format!( - "implementation of inherent method `to_string(&self) -> String` for type `{}`", - self_type.to_string() - ), - None, - &format!("implement trait `Display` for type `{}` instead", self_type.to_string()), - ); - } -} diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs deleted file mode 100644 index d1c3fdc71461..000000000000 --- a/clippy_lints/src/inline_fn_without_body.rs +++ /dev/null @@ -1,58 +0,0 @@ -//! checks for `#[inline]` on trait methods without bodies - -use crate::utils::span_lint_and_then; -use crate::utils::sugg::DiagnosticBuilderExt; -use rustc_ast::ast::Attribute; -use rustc_errors::Applicability; -use rustc_hir::{TraitFn, TraitItem, TraitItemKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::{sym, Symbol}; - -declare_clippy_lint! { - /// **What it does:** Checks for `#[inline]` on trait methods without bodies - /// - /// **Why is this bad?** Only implementations of trait methods may be inlined. - /// The inline attribute is ignored for trait methods without bodies. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// trait Animal { - /// #[inline] - /// fn name(&self) -> &'static str; - /// } - /// ``` - pub INLINE_FN_WITHOUT_BODY, - correctness, - "use of `#[inline]` on trait methods without bodies" -} - -declare_lint_pass!(InlineFnWithoutBody => [INLINE_FN_WITHOUT_BODY]); - -impl<'tcx> LateLintPass<'tcx> for InlineFnWithoutBody { - fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { - if let TraitItemKind::Fn(_, TraitFn::Required(_)) = item.kind { - check_attrs(cx, item.ident.name, &item.attrs); - } - } -} - -fn check_attrs(cx: &LateContext<'_>, name: Symbol, attrs: &[Attribute]) { - for attr in attrs { - if !attr.has_name(sym::inline) { - continue; - } - - span_lint_and_then( - cx, - INLINE_FN_WITHOUT_BODY, - attr.span, - &format!("use of `#[inline]` on trait method `{}` which has no body", name), - |diag| { - diag.suggest_remove_item(cx, attr.span, "remove", Applicability::MachineApplicable); - }, - ); - } -} diff --git a/clippy_lints/src/int_plus_one.rs b/clippy_lints/src/int_plus_one.rs deleted file mode 100644 index c629ee05ab97..000000000000 --- a/clippy_lints/src/int_plus_one.rs +++ /dev/null @@ -1,171 +0,0 @@ -//! lint on blocks unnecessarily using >= with a + 1 or - 1 - -use rustc_ast::ast::{BinOpKind, Expr, ExprKind, Lit, LitKind}; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -use crate::utils::{snippet_opt, span_lint_and_sugg}; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `x >= y + 1` or `x - 1 >= y` (and `<=`) in a block - /// - /// **Why is this bad?** Readability -- better to use `> y` instead of `>= y + 1`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let x = 1; - /// # let y = 1; - /// if x >= y + 1 {} - /// ``` - /// - /// Could be written as: - /// - /// ```rust - /// # let x = 1; - /// # let y = 1; - /// if x > y {} - /// ``` - pub INT_PLUS_ONE, - complexity, - "instead of using `x >= y + 1`, use `x > y`" -} - -declare_lint_pass!(IntPlusOne => [INT_PLUS_ONE]); - -// cases: -// BinOpKind::Ge -// x >= y + 1 -// x - 1 >= y -// -// BinOpKind::Le -// x + 1 <= y -// x <= y - 1 - -#[derive(Copy, Clone)] -enum Side { - LHS, - RHS, -} - -impl IntPlusOne { - #[allow(clippy::cast_sign_loss)] - fn check_lit(lit: &Lit, target_value: i128) -> bool { - if let LitKind::Int(value, ..) = lit.kind { - return value == (target_value as u128); - } - false - } - - fn check_binop(cx: &EarlyContext<'_>, binop: BinOpKind, lhs: &Expr, rhs: &Expr) -> Option { - match (binop, &lhs.kind, &rhs.kind) { - // case where `x - 1 >= ...` or `-1 + x >= ...` - (BinOpKind::Ge, &ExprKind::Binary(ref lhskind, ref lhslhs, ref lhsrhs), _) => { - match (lhskind.node, &lhslhs.kind, &lhsrhs.kind) { - // `-1 + x` - (BinOpKind::Add, &ExprKind::Lit(ref lit), _) if Self::check_lit(lit, -1) => { - Self::generate_recommendation(cx, binop, lhsrhs, rhs, Side::LHS) - }, - // `x - 1` - (BinOpKind::Sub, _, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 1) => { - Self::generate_recommendation(cx, binop, lhslhs, rhs, Side::LHS) - }, - _ => None, - } - }, - // case where `... >= y + 1` or `... >= 1 + y` - (BinOpKind::Ge, _, &ExprKind::Binary(ref rhskind, ref rhslhs, ref rhsrhs)) - if rhskind.node == BinOpKind::Add => - { - match (&rhslhs.kind, &rhsrhs.kind) { - // `y + 1` and `1 + y` - (&ExprKind::Lit(ref lit), _) if Self::check_lit(lit, 1) => { - Self::generate_recommendation(cx, binop, rhsrhs, lhs, Side::RHS) - }, - (_, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 1) => { - Self::generate_recommendation(cx, binop, rhslhs, lhs, Side::RHS) - }, - _ => None, - } - } - // case where `x + 1 <= ...` or `1 + x <= ...` - (BinOpKind::Le, &ExprKind::Binary(ref lhskind, ref lhslhs, ref lhsrhs), _) - if lhskind.node == BinOpKind::Add => - { - match (&lhslhs.kind, &lhsrhs.kind) { - // `1 + x` and `x + 1` - (&ExprKind::Lit(ref lit), _) if Self::check_lit(lit, 1) => { - Self::generate_recommendation(cx, binop, lhsrhs, rhs, Side::LHS) - }, - (_, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 1) => { - Self::generate_recommendation(cx, binop, lhslhs, rhs, Side::LHS) - }, - _ => None, - } - } - // case where `... >= y - 1` or `... >= -1 + y` - (BinOpKind::Le, _, &ExprKind::Binary(ref rhskind, ref rhslhs, ref rhsrhs)) => { - match (rhskind.node, &rhslhs.kind, &rhsrhs.kind) { - // `-1 + y` - (BinOpKind::Add, &ExprKind::Lit(ref lit), _) if Self::check_lit(lit, -1) => { - Self::generate_recommendation(cx, binop, rhsrhs, lhs, Side::RHS) - }, - // `y - 1` - (BinOpKind::Sub, _, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 1) => { - Self::generate_recommendation(cx, binop, rhslhs, lhs, Side::RHS) - }, - _ => None, - } - }, - _ => None, - } - } - - fn generate_recommendation( - cx: &EarlyContext<'_>, - binop: BinOpKind, - node: &Expr, - other_side: &Expr, - side: Side, - ) -> Option { - let binop_string = match binop { - BinOpKind::Ge => ">", - BinOpKind::Le => "<", - _ => return None, - }; - if let Some(snippet) = snippet_opt(cx, node.span) { - if let Some(other_side_snippet) = snippet_opt(cx, other_side.span) { - let rec = match side { - Side::LHS => Some(format!("{} {} {}", snippet, binop_string, other_side_snippet)), - Side::RHS => Some(format!("{} {} {}", other_side_snippet, binop_string, snippet)), - }; - return rec; - } - } - None - } - - fn emit_warning(cx: &EarlyContext<'_>, block: &Expr, recommendation: String) { - span_lint_and_sugg( - cx, - INT_PLUS_ONE, - block.span, - "unnecessary `>= y + 1` or `x - 1 >=`", - "change it to", - recommendation, - Applicability::MachineApplicable, // snippet - ); - } -} - -impl EarlyLintPass for IntPlusOne { - fn check_expr(&mut self, cx: &EarlyContext<'_>, item: &Expr) { - if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = item.kind { - if let Some(rec) = Self::check_binop(cx, kind.node, lhs, rhs) { - Self::emit_warning(cx, item, rec); - } - } - } -} diff --git a/clippy_lints/src/integer_division.rs b/clippy_lints/src/integer_division.rs deleted file mode 100644 index 31181c10d23d..000000000000 --- a/clippy_lints/src/integer_division.rs +++ /dev/null @@ -1,59 +0,0 @@ -use crate::utils::span_lint_and_help; -use if_chain::if_chain; -use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for division of integers - /// - /// **Why is this bad?** When outside of some very specific algorithms, - /// integer division is very often a mistake because it discards the - /// remainder. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// // Bad - /// let x = 3 / 2; - /// println!("{}", x); - /// - /// // Good - /// let x = 3f32 / 2f32; - /// println!("{}", x); - /// ``` - pub INTEGER_DIVISION, - restriction, - "integer division may cause loss of precision" -} - -declare_lint_pass!(IntegerDivision => [INTEGER_DIVISION]); - -impl<'tcx> LateLintPass<'tcx> for IntegerDivision { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - if is_integer_division(cx, expr) { - span_lint_and_help( - cx, - INTEGER_DIVISION, - expr.span, - "integer division", - None, - "division of integers may cause loss of precision. consider using floats.", - ); - } - } -} - -fn is_integer_division<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) -> bool { - if_chain! { - if let hir::ExprKind::Binary(binop, left, right) = &expr.kind; - if let hir::BinOpKind::Div = &binop.node; - then { - let (left_ty, right_ty) = (cx.typeck_results().expr_ty(left), cx.typeck_results().expr_ty(right)); - return left_ty.is_integral() && right_ty.is_integral(); - } - } - - false -} diff --git a/clippy_lints/src/items_after_statements.rs b/clippy_lints/src/items_after_statements.rs deleted file mode 100644 index 0927d218446d..000000000000 --- a/clippy_lints/src/items_after_statements.rs +++ /dev/null @@ -1,88 +0,0 @@ -//! lint when items are used after statements - -use crate::utils::span_lint; -use rustc_ast::ast::{Block, ItemKind, StmtKind}; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for items declared after some statement in a block. - /// - /// **Why is this bad?** Items live for the entire scope they are declared - /// in. But statements are processed in order. This might cause confusion as - /// it's hard to figure out which item is meant in a statement. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// // Bad - /// fn foo() { - /// println!("cake"); - /// } - /// - /// fn main() { - /// foo(); // prints "foo" - /// fn foo() { - /// println!("foo"); - /// } - /// foo(); // prints "foo" - /// } - /// ``` - /// - /// ```rust - /// // Good - /// fn foo() { - /// println!("cake"); - /// } - /// - /// fn main() { - /// fn foo() { - /// println!("foo"); - /// } - /// foo(); // prints "foo" - /// foo(); // prints "foo" - /// } - /// ``` - pub ITEMS_AFTER_STATEMENTS, - pedantic, - "blocks where an item comes after a statement" -} - -declare_lint_pass!(ItemsAfterStatements => [ITEMS_AFTER_STATEMENTS]); - -impl EarlyLintPass for ItemsAfterStatements { - fn check_block(&mut self, cx: &EarlyContext<'_>, item: &Block) { - if in_external_macro(cx.sess(), item.span) { - return; - } - - // skip initial items and trailing semicolons - let stmts = item - .stmts - .iter() - .map(|stmt| &stmt.kind) - .skip_while(|s| matches!(**s, StmtKind::Item(..) | StmtKind::Empty)); - - // lint on all further items - for stmt in stmts { - if let StmtKind::Item(ref it) = *stmt { - if in_external_macro(cx.sess(), it.span) { - return; - } - if let ItemKind::MacroDef(..) = it.kind { - // do not lint `macro_rules`, but continue processing further statements - continue; - } - span_lint( - cx, - ITEMS_AFTER_STATEMENTS, - it.span, - "adding items after statements is confusing, since items exist from the \ - start of the scope", - ); - } - } - } -} diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs deleted file mode 100644 index a76595ed0897..000000000000 --- a/clippy_lints/src/large_const_arrays.rs +++ /dev/null @@ -1,84 +0,0 @@ -use crate::rustc_target::abi::LayoutOf; -use crate::utils::span_lint_and_then; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{Item, ItemKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::mir::interpret::ConstValue; -use rustc_middle::ty::{self, ConstKind}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::{BytePos, Pos, Span}; -use rustc_typeck::hir_ty_to_ty; - -declare_clippy_lint! { - /// **What it does:** Checks for large `const` arrays that should - /// be defined as `static` instead. - /// - /// **Why is this bad?** Performance: const variables are inlined upon use. - /// Static items result in only one instance and has a fixed location in memory. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// // Bad - /// pub const a = [0u32; 1_000_000]; - /// - /// // Good - /// pub static a = [0u32; 1_000_000]; - /// ``` - pub LARGE_CONST_ARRAYS, - perf, - "large non-scalar const array may cause performance overhead" -} - -pub struct LargeConstArrays { - maximum_allowed_size: u64, -} - -impl LargeConstArrays { - #[must_use] - pub fn new(maximum_allowed_size: u64) -> Self { - Self { maximum_allowed_size } - } -} - -impl_lint_pass!(LargeConstArrays => [LARGE_CONST_ARRAYS]); - -impl<'tcx> LateLintPass<'tcx> for LargeConstArrays { - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if_chain! { - if !item.span.from_expansion(); - if let ItemKind::Const(hir_ty, _) = &item.kind; - let ty = hir_ty_to_ty(cx.tcx, hir_ty); - if let ty::Array(element_type, cst) = ty.kind(); - if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val; - if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx); - if let Ok(element_size) = cx.layout_of(element_type).map(|l| l.size.bytes()); - if self.maximum_allowed_size < element_count * element_size; - - then { - let hi_pos = item.ident.span.lo() - BytePos::from_usize(1); - let sugg_span = Span::new( - hi_pos - BytePos::from_usize("const".len()), - hi_pos, - item.span.ctxt(), - ); - span_lint_and_then( - cx, - LARGE_CONST_ARRAYS, - item.span, - "large array defined as const", - |diag| { - diag.span_suggestion( - sugg_span, - "make this a static item", - "static".to_string(), - Applicability::MachineApplicable, - ); - } - ); - } - } - } -} diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs deleted file mode 100644 index 3c7880d74ee6..000000000000 --- a/clippy_lints/src/large_enum_variant.rs +++ /dev/null @@ -1,134 +0,0 @@ -//! lint when there is a large size difference between variants on an enum - -use crate::utils::{snippet_opt, span_lint_and_then}; -use rustc_errors::Applicability; -use rustc_hir::{Item, ItemKind, VariantData}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_target::abi::LayoutOf; - -declare_clippy_lint! { - /// **What it does:** Checks for large size differences between variants on - /// `enum`s. - /// - /// **Why is this bad?** Enum size is bounded by the largest variant. Having a - /// large variant can penalize the memory layout of that enum. - /// - /// **Known problems:** This lint obviously cannot take the distribution of - /// variants in your running program into account. It is possible that the - /// smaller variants make up less than 1% of all instances, in which case - /// the overhead is negligible and the boxing is counter-productive. Always - /// measure the change this lint suggests. - /// - /// **Example:** - /// - /// ```rust - /// // Bad - /// enum Test { - /// A(i32), - /// B([i32; 8000]), - /// } - /// - /// // Possibly better - /// enum Test2 { - /// A(i32), - /// B(Box<[i32; 8000]>), - /// } - /// ``` - pub LARGE_ENUM_VARIANT, - perf, - "large size difference between variants on an enum" -} - -#[derive(Copy, Clone)] -pub struct LargeEnumVariant { - maximum_size_difference_allowed: u64, -} - -impl LargeEnumVariant { - #[must_use] - pub fn new(maximum_size_difference_allowed: u64) -> Self { - Self { - maximum_size_difference_allowed, - } - } -} - -impl_lint_pass!(LargeEnumVariant => [LARGE_ENUM_VARIANT]); - -impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant { - fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { - let did = cx.tcx.hir().local_def_id(item.hir_id); - if let ItemKind::Enum(ref def, _) = item.kind { - let ty = cx.tcx.type_of(did); - let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); - - let mut largest_variant: Option<(_, _)> = None; - let mut second_variant: Option<(_, _)> = None; - - for (i, variant) in adt.variants.iter().enumerate() { - let size: u64 = variant - .fields - .iter() - .filter_map(|f| { - let ty = cx.tcx.type_of(f.did); - // don't count generics by filtering out everything - // that does not have a layout - cx.layout_of(ty).ok().map(|l| l.size.bytes()) - }) - .sum(); - - let grouped = (size, (i, variant)); - - if grouped.0 >= largest_variant.map_or(0, |x| x.0) { - second_variant = largest_variant; - largest_variant = Some(grouped); - } - } - - if let (Some(largest), Some(second)) = (largest_variant, second_variant) { - let difference = largest.0 - second.0; - - if difference > self.maximum_size_difference_allowed { - let (i, variant) = largest.1; - - let help_text = "consider boxing the large fields to reduce the total size of the enum"; - span_lint_and_then( - cx, - LARGE_ENUM_VARIANT, - def.variants[i].span, - "large size difference between variants", - |diag| { - diag.span_label( - def.variants[(largest.1).0].span, - &format!("this variant is {} bytes", largest.0), - ); - diag.span_note( - def.variants[(second.1).0].span, - &format!("and the second-largest variant is {} bytes:", second.0), - ); - if variant.fields.len() == 1 { - let span = match def.variants[i].data { - VariantData::Struct(ref fields, ..) | VariantData::Tuple(ref fields, ..) => { - fields[0].ty.span - }, - VariantData::Unit(..) => unreachable!(), - }; - if let Some(snip) = snippet_opt(cx, span) { - diag.span_suggestion( - span, - help_text, - format!("Box<{}>", snip), - Applicability::MaybeIncorrect, - ); - return; - } - } - diag.span_help(def.variants[i].span, help_text); - }, - ); - } - } - } - } -} diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs deleted file mode 100644 index 9a448ab12568..000000000000 --- a/clippy_lints/src/large_stack_arrays.rs +++ /dev/null @@ -1,68 +0,0 @@ -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::mir::interpret::ConstValue; -use rustc_middle::ty::{self, ConstKind}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; - -use if_chain::if_chain; - -use crate::rustc_target::abi::LayoutOf; -use crate::utils::{snippet, span_lint_and_help}; - -declare_clippy_lint! { - /// **What it does:** Checks for local arrays that may be too large. - /// - /// **Why is this bad?** Large local arrays may cause stack overflow. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// let a = [0u32; 1_000_000]; - /// ``` - pub LARGE_STACK_ARRAYS, - pedantic, - "allocating large arrays on stack may cause stack overflow" -} - -pub struct LargeStackArrays { - maximum_allowed_size: u64, -} - -impl LargeStackArrays { - #[must_use] - pub fn new(maximum_allowed_size: u64) -> Self { - Self { maximum_allowed_size } - } -} - -impl_lint_pass!(LargeStackArrays => [LARGE_STACK_ARRAYS]); - -impl<'tcx> LateLintPass<'tcx> for LargeStackArrays { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::Repeat(_, _) = expr.kind; - if let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind(); - if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val; - if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx); - if let Ok(element_size) = cx.layout_of(element_type).map(|l| l.size.bytes()); - if self.maximum_allowed_size < element_count * element_size; - then { - span_lint_and_help( - cx, - LARGE_STACK_ARRAYS, - expr.span, - &format!( - "allocating a local array larger than {} bytes", - self.maximum_allowed_size - ), - None, - &format!( - "consider allocating on the heap with `vec!{}.into_boxed_slice()`", - snippet(cx, expr.span, "[...]") - ), - ); - } - } - } -} diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs deleted file mode 100644 index 6fe533510904..000000000000 --- a/clippy_lints/src/len_zero.rs +++ /dev/null @@ -1,375 +0,0 @@ -use crate::utils::{get_item_name, snippet_with_applicability, span_lint, span_lint_and_sugg}; -use rustc_ast::ast::LitKind; -use rustc_data_structures::fx::FxHashSet; -use rustc_errors::Applicability; -use rustc_hir::def_id::DefId; -use rustc_hir::{AssocItemKind, BinOpKind, Expr, ExprKind, ImplItemRef, Item, ItemKind, TraitItemRef}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::{Span, Spanned, Symbol}; - -declare_clippy_lint! { - /// **What it does:** Checks for getting the length of something via `.len()` - /// just to compare to zero, and suggests using `.is_empty()` where applicable. - /// - /// **Why is this bad?** Some structures can answer `.is_empty()` much faster - /// than calculating their length. So it is good to get into the habit of using - /// `.is_empty()`, and having it is cheap. - /// Besides, it makes the intent clearer than a manual comparison in some contexts. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// if x.len() == 0 { - /// .. - /// } - /// if y.len() != 0 { - /// .. - /// } - /// ``` - /// instead use - /// ```ignore - /// if x.is_empty() { - /// .. - /// } - /// if !y.is_empty() { - /// .. - /// } - /// ``` - pub LEN_ZERO, - style, - "checking `.len() == 0` or `.len() > 0` (or similar) when `.is_empty()` could be used instead" -} - -declare_clippy_lint! { - /// **What it does:** Checks for items that implement `.len()` but not - /// `.is_empty()`. - /// - /// **Why is this bad?** It is good custom to have both methods, because for - /// some data structures, asking about the length will be a costly operation, - /// whereas `.is_empty()` can usually answer in constant time. Also it used to - /// lead to false positives on the [`len_zero`](#len_zero) lint – currently that - /// lint will ignore such entities. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// impl X { - /// pub fn len(&self) -> usize { - /// .. - /// } - /// } - /// ``` - pub LEN_WITHOUT_IS_EMPTY, - style, - "traits or impls with a public `len` method but no corresponding `is_empty` method" -} - -declare_clippy_lint! { - /// **What it does:** Checks for comparing to an empty slice such as `""` or `[]`, - /// and suggests using `.is_empty()` where applicable. - /// - /// **Why is this bad?** Some structures can answer `.is_empty()` much faster - /// than checking for equality. So it is good to get into the habit of using - /// `.is_empty()`, and having it is cheap. - /// Besides, it makes the intent clearer than a manual comparison in some contexts. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```ignore - /// if s == "" { - /// .. - /// } - /// - /// if arr == [] { - /// .. - /// } - /// ``` - /// Use instead: - /// ```ignore - /// if s.is_empty() { - /// .. - /// } - /// - /// if arr.is_empty() { - /// .. - /// } - /// ``` - pub COMPARISON_TO_EMPTY, - style, - "checking `x == \"\"` or `x == []` (or similar) when `.is_empty()` could be used instead" -} - -declare_lint_pass!(LenZero => [LEN_ZERO, LEN_WITHOUT_IS_EMPTY, COMPARISON_TO_EMPTY]); - -impl<'tcx> LateLintPass<'tcx> for LenZero { - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if item.span.from_expansion() { - return; - } - - match item.kind { - ItemKind::Trait(_, _, _, _, ref trait_items) => check_trait_items(cx, item, trait_items), - ItemKind::Impl { - of_trait: None, - items: ref impl_items, - .. - } => check_impl_items(cx, item, impl_items), - _ => (), - } - } - - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if expr.span.from_expansion() { - return; - } - - if let ExprKind::Binary(Spanned { node: cmp, .. }, ref left, ref right) = expr.kind { - match cmp { - BinOpKind::Eq => { - check_cmp(cx, expr.span, left, right, "", 0); // len == 0 - check_cmp(cx, expr.span, right, left, "", 0); // 0 == len - }, - BinOpKind::Ne => { - check_cmp(cx, expr.span, left, right, "!", 0); // len != 0 - check_cmp(cx, expr.span, right, left, "!", 0); // 0 != len - }, - BinOpKind::Gt => { - check_cmp(cx, expr.span, left, right, "!", 0); // len > 0 - check_cmp(cx, expr.span, right, left, "", 1); // 1 > len - }, - BinOpKind::Lt => { - check_cmp(cx, expr.span, left, right, "", 1); // len < 1 - check_cmp(cx, expr.span, right, left, "!", 0); // 0 < len - }, - BinOpKind::Ge => check_cmp(cx, expr.span, left, right, "!", 1), // len >= 1 - BinOpKind::Le => check_cmp(cx, expr.span, right, left, "!", 1), // 1 <= len - _ => (), - } - } - } -} - -fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items: &[TraitItemRef]) { - fn is_named_self(cx: &LateContext<'_>, item: &TraitItemRef, name: &str) -> bool { - item.ident.name.as_str() == name - && if let AssocItemKind::Fn { has_self } = item.kind { - has_self && { - let did = cx.tcx.hir().local_def_id(item.id.hir_id); - cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1 - } - } else { - false - } - } - - // fill the set with current and super traits - fn fill_trait_set(traitt: DefId, set: &mut FxHashSet, cx: &LateContext<'_>) { - if set.insert(traitt) { - for supertrait in rustc_trait_selection::traits::supertrait_def_ids(cx.tcx, traitt) { - fill_trait_set(supertrait, set, cx); - } - } - } - - if cx.access_levels.is_exported(visited_trait.hir_id) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) { - let mut current_and_super_traits = FxHashSet::default(); - let visited_trait_def_id = cx.tcx.hir().local_def_id(visited_trait.hir_id); - fill_trait_set(visited_trait_def_id.to_def_id(), &mut current_and_super_traits, cx); - - let is_empty_method_found = current_and_super_traits - .iter() - .flat_map(|&i| cx.tcx.associated_items(i).in_definition_order()) - .any(|i| { - i.kind == ty::AssocKind::Fn - && i.fn_has_self_parameter - && i.ident.name == sym!(is_empty) - && cx.tcx.fn_sig(i.def_id).inputs().skip_binder().len() == 1 - }); - - if !is_empty_method_found { - span_lint( - cx, - LEN_WITHOUT_IS_EMPTY, - visited_trait.span, - &format!( - "trait `{}` has a `len` method but no (possibly inherited) `is_empty` method", - visited_trait.ident.name - ), - ); - } - } -} - -fn check_impl_items(cx: &LateContext<'_>, item: &Item<'_>, impl_items: &[ImplItemRef<'_>]) { - fn is_named_self(cx: &LateContext<'_>, item: &ImplItemRef<'_>, name: &str) -> bool { - item.ident.name.as_str() == name - && if let AssocItemKind::Fn { has_self } = item.kind { - has_self && { - let did = cx.tcx.hir().local_def_id(item.id.hir_id); - cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1 - } - } else { - false - } - } - - let is_empty = if let Some(is_empty) = impl_items.iter().find(|i| is_named_self(cx, i, "is_empty")) { - if cx.access_levels.is_exported(is_empty.id.hir_id) { - return; - } - "a private" - } else { - "no corresponding" - }; - - if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) { - if cx.access_levels.is_exported(i.id.hir_id) { - let def_id = cx.tcx.hir().local_def_id(item.hir_id); - let ty = cx.tcx.type_of(def_id); - - span_lint( - cx, - LEN_WITHOUT_IS_EMPTY, - item.span, - &format!( - "item `{}` has a public `len` method but {} `is_empty` method", - ty, is_empty - ), - ); - } - } -} - -fn check_cmp(cx: &LateContext<'_>, span: Span, method: &Expr<'_>, lit: &Expr<'_>, op: &str, compare_to: u32) { - if let (&ExprKind::MethodCall(ref method_path, _, ref args, _), &ExprKind::Lit(ref lit)) = (&method.kind, &lit.kind) - { - // check if we are in an is_empty() method - if let Some(name) = get_item_name(cx, method) { - if name.as_str() == "is_empty" { - return; - } - } - - check_len(cx, span, method_path.ident.name, args, &lit.node, op, compare_to) - } else { - check_empty_expr(cx, span, method, lit, op) - } -} - -fn check_len( - cx: &LateContext<'_>, - span: Span, - method_name: Symbol, - args: &[Expr<'_>], - lit: &LitKind, - op: &str, - compare_to: u32, -) { - if let LitKind::Int(lit, _) = *lit { - // check if length is compared to the specified number - if lit != u128::from(compare_to) { - return; - } - - if method_name.as_str() == "len" && args.len() == 1 && has_is_empty(cx, &args[0]) { - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - LEN_ZERO, - span, - &format!("length comparison to {}", if compare_to == 0 { "zero" } else { "one" }), - &format!("using `{}is_empty` is clearer and more explicit", op), - format!( - "{}{}.is_empty()", - op, - snippet_with_applicability(cx, args[0].span, "_", &mut applicability) - ), - applicability, - ); - } - } -} - -fn check_empty_expr(cx: &LateContext<'_>, span: Span, lit1: &Expr<'_>, lit2: &Expr<'_>, op: &str) { - if (is_empty_array(lit2) || is_empty_string(lit2)) && has_is_empty(cx, lit1) { - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - COMPARISON_TO_EMPTY, - span, - "comparison to empty slice", - &format!("using `{}is_empty` is clearer and more explicit", op), - format!( - "{}{}.is_empty()", - op, - snippet_with_applicability(cx, lit1.span, "_", &mut applicability) - ), - applicability, - ); - } -} - -fn is_empty_string(expr: &Expr<'_>) -> bool { - if let ExprKind::Lit(ref lit) = expr.kind { - if let LitKind::Str(lit, _) = lit.node { - let lit = lit.as_str(); - return lit == ""; - } - } - false -} - -fn is_empty_array(expr: &Expr<'_>) -> bool { - if let ExprKind::Array(ref arr) = expr.kind { - return arr.is_empty(); - } - false -} - -/// Checks if this type has an `is_empty` method. -fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - /// Gets an `AssocItem` and return true if it matches `is_empty(self)`. - fn is_is_empty(cx: &LateContext<'_>, item: &ty::AssocItem) -> bool { - if let ty::AssocKind::Fn = item.kind { - if item.ident.name.as_str() == "is_empty" { - let sig = cx.tcx.fn_sig(item.def_id); - let ty = sig.skip_binder(); - ty.inputs().len() == 1 - } else { - false - } - } else { - false - } - } - - /// Checks the inherent impl's items for an `is_empty(self)` method. - fn has_is_empty_impl(cx: &LateContext<'_>, id: DefId) -> bool { - cx.tcx.inherent_impls(id).iter().any(|imp| { - cx.tcx - .associated_items(*imp) - .in_definition_order() - .any(|item| is_is_empty(cx, &item)) - }) - } - - let ty = &cx.typeck_results().expr_ty(expr).peel_refs(); - match ty.kind() { - ty::Dynamic(ref tt, ..) => tt.principal().map_or(false, |principal| { - cx.tcx - .associated_items(principal.def_id()) - .in_definition_order() - .any(|item| is_is_empty(cx, &item)) - }), - ty::Projection(ref proj) => has_is_empty_impl(cx, proj.item_def_id), - ty::Adt(id, _) => has_is_empty_impl(cx, id.did), - ty::Array(..) | ty::Slice(..) | ty::Str => true, - _ => false, - } -} diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs deleted file mode 100644 index 0d2d95324c4f..000000000000 --- a/clippy_lints/src/let_if_seq.rs +++ /dev/null @@ -1,163 +0,0 @@ -use crate::utils::visitors::LocalUsedVisitor; -use crate::utils::{higher, qpath_res, snippet, span_lint_and_then}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_hir::def::Res; -use rustc_hir::BindingAnnotation; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for variable declarations immediately followed by a - /// conditional affectation. - /// - /// **Why is this bad?** This is not idiomatic Rust. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// let foo; - /// - /// if bar() { - /// foo = 42; - /// } else { - /// foo = 0; - /// } - /// - /// let mut baz = None; - /// - /// if bar() { - /// baz = Some(42); - /// } - /// ``` - /// - /// should be written - /// - /// ```rust,ignore - /// let foo = if bar() { - /// 42 - /// } else { - /// 0 - /// }; - /// - /// let baz = if bar() { - /// Some(42) - /// } else { - /// None - /// }; - /// ``` - pub USELESS_LET_IF_SEQ, - nursery, - "unidiomatic `let mut` declaration followed by initialization in `if`" -} - -declare_lint_pass!(LetIfSeq => [USELESS_LET_IF_SEQ]); - -impl<'tcx> LateLintPass<'tcx> for LetIfSeq { - fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx hir::Block<'_>) { - let mut it = block.stmts.iter().peekable(); - while let Some(stmt) = it.next() { - if_chain! { - if let Some(expr) = it.peek(); - if let hir::StmtKind::Local(ref local) = stmt.kind; - if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.kind; - if let hir::StmtKind::Expr(ref if_) = expr.kind; - if let Some((ref cond, ref then, ref else_)) = higher::if_block(&if_); - if !LocalUsedVisitor::new(canonical_id).check_expr(cond); - if let hir::ExprKind::Block(ref then, _) = then.kind; - if let Some(value) = check_assign(cx, canonical_id, &*then); - if !LocalUsedVisitor::new(canonical_id).check_expr(value); - then { - let span = stmt.span.to(if_.span); - - let has_interior_mutability = !cx.typeck_results().node_type(canonical_id).is_freeze( - cx.tcx.at(span), - cx.param_env, - ); - if has_interior_mutability { return; } - - let (default_multi_stmts, default) = if let Some(ref else_) = *else_ { - if let hir::ExprKind::Block(ref else_, _) = else_.kind { - if let Some(default) = check_assign(cx, canonical_id, else_) { - (else_.stmts.len() > 1, default) - } else if let Some(ref default) = local.init { - (true, &**default) - } else { - continue; - } - } else { - continue; - } - } else if let Some(ref default) = local.init { - (false, &**default) - } else { - continue; - }; - - let mutability = match mode { - BindingAnnotation::RefMut | BindingAnnotation::Mutable => " ", - _ => "", - }; - - // FIXME: this should not suggest `mut` if we can detect that the variable is not - // use mutably after the `if` - - let sug = format!( - "let {mut}{name} = if {cond} {{{then} {value} }} else {{{else} {default} }};", - mut=mutability, - name=ident.name, - cond=snippet(cx, cond.span, "_"), - then=if then.stmts.len() > 1 { " ..;" } else { "" }, - else=if default_multi_stmts { " ..;" } else { "" }, - value=snippet(cx, value.span, ""), - default=snippet(cx, default.span, ""), - ); - span_lint_and_then(cx, - USELESS_LET_IF_SEQ, - span, - "`if _ { .. } else { .. }` is an expression", - |diag| { - diag.span_suggestion( - span, - "it is more idiomatic to write", - sug, - Applicability::HasPlaceholders, - ); - if !mutability.is_empty() { - diag.note("you might not need `mut` at all"); - } - }); - } - } - } - } -} - -fn check_assign<'tcx>( - cx: &LateContext<'tcx>, - decl: hir::HirId, - block: &'tcx hir::Block<'_>, -) -> Option<&'tcx hir::Expr<'tcx>> { - if_chain! { - if block.expr.is_none(); - if let Some(expr) = block.stmts.iter().last(); - if let hir::StmtKind::Semi(ref expr) = expr.kind; - if let hir::ExprKind::Assign(ref var, ref value, _) = expr.kind; - if let hir::ExprKind::Path(ref qpath) = var.kind; - if let Res::Local(local_id) = qpath_res(cx, qpath, var.hir_id); - if decl == local_id; - then { - let mut v = LocalUsedVisitor::new(decl); - - if block.stmts.iter().take(block.stmts.len()-1).any(|stmt| v.check_stmt(stmt)) { - return None; - } - - return Some(value); - } - } - - None -} diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs deleted file mode 100644 index 6a5a77f8690a..000000000000 --- a/clippy_lints/src/let_underscore.rs +++ /dev/null @@ -1,179 +0,0 @@ -use if_chain::if_chain; -use rustc_hir::{Local, PatKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::subst::GenericArgKind; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -use crate::utils::{implements_trait, is_must_use_func_call, is_must_use_ty, match_type, paths, span_lint_and_help}; - -declare_clippy_lint! { - /// **What it does:** Checks for `let _ = ` - /// where expr is #[must_use] - /// - /// **Why is this bad?** It's better to explicitly - /// handle the value of a #[must_use] expr - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// fn f() -> Result { - /// Ok(0) - /// } - /// - /// let _ = f(); - /// // is_ok() is marked #[must_use] - /// let _ = f().is_ok(); - /// ``` - pub LET_UNDERSCORE_MUST_USE, - restriction, - "non-binding let on a `#[must_use]` expression" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `let _ = sync_lock` - /// - /// **Why is this bad?** This statement immediately drops the lock instead of - /// extending its lifetime to the end of the scope, which is often not intended. - /// To extend lock lifetime to the end of the scope, use an underscore-prefixed - /// name instead (i.e. _lock). If you want to explicitly drop the lock, - /// `std::mem::drop` conveys your intention better and is less error-prone. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// Bad: - /// ```rust,ignore - /// let _ = mutex.lock(); - /// ``` - /// - /// Good: - /// ```rust,ignore - /// let _lock = mutex.lock(); - /// ``` - pub LET_UNDERSCORE_LOCK, - correctness, - "non-binding let on a synchronization lock" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `let _ = ` - /// where expr has a type that implements `Drop` - /// - /// **Why is this bad?** This statement immediately drops the initializer - /// expression instead of extending its lifetime to the end of the scope, which - /// is often not intended. To extend the expression's lifetime to the end of the - /// scope, use an underscore-prefixed name instead (i.e. _var). If you want to - /// explicitly drop the expression, `std::mem::drop` conveys your intention - /// better and is less error-prone. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// Bad: - /// ```rust,ignore - /// struct Droppable; - /// impl Drop for Droppable { - /// fn drop(&mut self) {} - /// } - /// { - /// let _ = Droppable; - /// // ^ dropped here - /// /* more code */ - /// } - /// ``` - /// - /// Good: - /// ```rust,ignore - /// { - /// let _droppable = Droppable; - /// /* more code */ - /// // dropped at end of scope - /// } - /// ``` - pub LET_UNDERSCORE_DROP, - pedantic, - "non-binding let on a type that implements `Drop`" -} - -declare_lint_pass!(LetUnderscore => [LET_UNDERSCORE_MUST_USE, LET_UNDERSCORE_LOCK, LET_UNDERSCORE_DROP]); - -const SYNC_GUARD_PATHS: [&[&str]; 3] = [ - &paths::MUTEX_GUARD, - &paths::RWLOCK_READ_GUARD, - &paths::RWLOCK_WRITE_GUARD, -]; - -impl<'tcx> LateLintPass<'tcx> for LetUnderscore { - fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) { - if in_external_macro(cx.tcx.sess, local.span) { - return; - } - - if_chain! { - if let PatKind::Wild = local.pat.kind; - if let Some(ref init) = local.init; - then { - let init_ty = cx.typeck_results().expr_ty(init); - let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() { - GenericArgKind::Type(inner_ty) => { - SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path)) - }, - - GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false, - }); - let implements_drop = cx.tcx.lang_items().drop_trait().map_or(false, |drop_trait| - init_ty.walk().any(|inner| match inner.unpack() { - GenericArgKind::Type(inner_ty) => { - implements_trait(cx, inner_ty, drop_trait, &[]) - }, - - GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false, - }) - ); - if contains_sync_guard { - span_lint_and_help( - cx, - LET_UNDERSCORE_LOCK, - local.span, - "non-binding let on a synchronization lock", - None, - "consider using an underscore-prefixed named \ - binding or dropping explicitly with `std::mem::drop`" - ) - } else if implements_drop { - span_lint_and_help( - cx, - LET_UNDERSCORE_DROP, - local.span, - "non-binding `let` on a type that implements `Drop`", - None, - "consider using an underscore-prefixed named \ - binding or dropping explicitly with `std::mem::drop`" - ) - } else if is_must_use_ty(cx, cx.typeck_results().expr_ty(init)) { - span_lint_and_help( - cx, - LET_UNDERSCORE_MUST_USE, - local.span, - "non-binding let on an expression with `#[must_use]` type", - None, - "consider explicitly using expression value" - ) - } else if is_must_use_func_call(cx, init) { - span_lint_and_help( - cx, - LET_UNDERSCORE_MUST_USE, - local.span, - "non-binding let on a result of a `#[must_use]` function", - None, - "consider explicitly using function result" - ) - } - } - } - } -} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs deleted file mode 100644 index 02ba422a2f5b..000000000000 --- a/clippy_lints/src/lib.rs +++ /dev/null @@ -1,2036 +0,0 @@ -// error-pattern:cargo-clippy - -#![feature(bindings_after_at)] -#![feature(box_patterns)] -#![feature(box_syntax)] -#![feature(concat_idents)] -#![feature(crate_visibility_modifier)] -#![feature(drain_filter)] -#![feature(in_band_lifetimes)] -#![feature(once_cell)] -#![feature(or_patterns)] -#![feature(rustc_private)] -#![feature(stmt_expr_attributes)] -#![feature(control_flow_enum)] -#![recursion_limit = "512"] -#![cfg_attr(feature = "deny-warnings", deny(warnings))] -#![allow(clippy::missing_docs_in_private_items, clippy::must_use_candidate)] -#![warn(trivial_casts, trivial_numeric_casts)] -// warn on lints, that are included in `rust-lang/rust`s bootstrap -#![warn(rust_2018_idioms, unused_lifetimes)] -// warn on rustc internal lints -#![deny(rustc::internal)] - -// FIXME: switch to something more ergonomic here, once available. -// (Currently there is no way to opt into sysroot crates without `extern crate`.) -extern crate rustc_ast; -extern crate rustc_ast_pretty; -extern crate rustc_attr; -extern crate rustc_data_structures; -extern crate rustc_driver; -extern crate rustc_errors; -extern crate rustc_hir; -extern crate rustc_hir_pretty; -extern crate rustc_index; -extern crate rustc_infer; -extern crate rustc_lexer; -extern crate rustc_lint; -extern crate rustc_middle; -extern crate rustc_mir; -extern crate rustc_parse; -extern crate rustc_parse_format; -extern crate rustc_session; -extern crate rustc_span; -extern crate rustc_target; -extern crate rustc_trait_selection; -extern crate rustc_typeck; - -use crate::utils::parse_msrv; -use rustc_data_structures::fx::FxHashSet; -use rustc_lint::LintId; -use rustc_session::Session; - -/// Macro used to declare a Clippy lint. -/// -/// Every lint declaration consists of 4 parts: -/// -/// 1. The documentation, which is used for the website -/// 2. The `LINT_NAME`. See [lint naming][lint_naming] on lint naming conventions. -/// 3. The `lint_level`, which is a mapping from *one* of our lint groups to `Allow`, `Warn` or -/// `Deny`. The lint level here has nothing to do with what lint groups the lint is a part of. -/// 4. The `description` that contains a short explanation on what's wrong with code where the -/// lint is triggered. -/// -/// Currently the categories `style`, `correctness`, `complexity` and `perf` are enabled by default. -/// As said in the README.md of this repository, if the lint level mapping changes, please update -/// README.md. -/// -/// # Example -/// -/// ``` -/// #![feature(rustc_private)] -/// extern crate rustc_session; -/// use rustc_session::declare_tool_lint; -/// use clippy_lints::declare_clippy_lint; -/// -/// declare_clippy_lint! { -/// /// **What it does:** Checks for ... (describe what the lint matches). -/// /// -/// /// **Why is this bad?** Supply the reason for linting the code. -/// /// -/// /// **Known problems:** None. (Or describe where it could go wrong.) -/// /// -/// /// **Example:** -/// /// -/// /// ```rust -/// /// // Bad -/// /// Insert a short example of code that triggers the lint -/// /// -/// /// // Good -/// /// Insert a short example of improved code that doesn't trigger the lint -/// /// ``` -/// pub LINT_NAME, -/// pedantic, -/// "description" -/// } -/// ``` -/// [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints -#[macro_export] -macro_rules! declare_clippy_lint { - { $(#[$attr:meta])* pub $name:tt, style, $description:tt } => { - declare_tool_lint! { - $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true - } - }; - { $(#[$attr:meta])* pub $name:tt, correctness, $description:tt } => { - declare_tool_lint! { - $(#[$attr])* pub clippy::$name, Deny, $description, report_in_external_macro: true - } - }; - { $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => { - declare_tool_lint! { - $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true - } - }; - { $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => { - declare_tool_lint! { - $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true - } - }; - { $(#[$attr:meta])* pub $name:tt, pedantic, $description:tt } => { - declare_tool_lint! { - $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true - } - }; - { $(#[$attr:meta])* pub $name:tt, restriction, $description:tt } => { - declare_tool_lint! { - $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true - } - }; - { $(#[$attr:meta])* pub $name:tt, cargo, $description:tt } => { - declare_tool_lint! { - $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true - } - }; - { $(#[$attr:meta])* pub $name:tt, nursery, $description:tt } => { - declare_tool_lint! { - $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true - } - }; - { $(#[$attr:meta])* pub $name:tt, internal, $description:tt } => { - declare_tool_lint! { - $(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true - } - }; - { $(#[$attr:meta])* pub $name:tt, internal_warn, $description:tt } => { - declare_tool_lint! { - $(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true - } - }; -} - -mod consts; -#[macro_use] -mod utils; - -// begin lints modules, do not remove this comment, it’s used in `update_lints` -mod approx_const; -mod arithmetic; -mod as_conversions; -mod asm_syntax; -mod assertions_on_constants; -mod assign_ops; -mod async_yields_async; -mod atomic_ordering; -mod attrs; -mod await_holding_invalid; -mod bit_mask; -mod blacklisted_name; -mod blocks_in_if_conditions; -mod booleans; -mod bytecount; -mod cargo_common_metadata; -mod checked_conversions; -mod cognitive_complexity; -mod collapsible_if; -mod collapsible_match; -mod comparison_chain; -mod copies; -mod copy_iterator; -mod create_dir; -mod dbg_macro; -mod default; -mod dereference; -mod derive; -mod disallowed_method; -mod doc; -mod double_comparison; -mod double_parens; -mod drop_forget_ref; -mod duration_subsec; -mod else_if_without_else; -mod empty_enum; -mod entry; -mod enum_clike; -mod enum_variants; -mod eq_op; -mod erasing_op; -mod escape; -mod eta_reduction; -mod eval_order_dependence; -mod excessive_bools; -mod exit; -mod explicit_write; -mod fallible_impl_from; -mod float_equality_without_abs; -mod float_literal; -mod floating_point_arithmetic; -mod format; -mod formatting; -mod functions; -mod future_not_send; -mod get_last_with_len; -mod identity_op; -mod if_let_mutex; -mod if_let_some_result; -mod if_not_else; -mod implicit_return; -mod implicit_saturating_sub; -mod indexing_slicing; -mod infinite_iter; -mod inherent_impl; -mod inherent_to_string; -mod inline_fn_without_body; -mod int_plus_one; -mod integer_division; -mod items_after_statements; -mod large_const_arrays; -mod large_enum_variant; -mod large_stack_arrays; -mod len_zero; -mod let_if_seq; -mod let_underscore; -mod lifetimes; -mod literal_representation; -mod loops; -mod macro_use; -mod main_recursion; -mod manual_async_fn; -mod manual_non_exhaustive; -mod manual_ok_or; -mod manual_strip; -mod manual_unwrap_or; -mod map_clone; -mod map_err_ignore; -mod map_identity; -mod map_unit_fn; -mod match_on_vec_items; -mod matches; -mod mem_discriminant; -mod mem_forget; -mod mem_replace; -mod methods; -mod minmax; -mod misc; -mod misc_early; -mod missing_const_for_fn; -mod missing_doc; -mod missing_inline; -mod modulo_arithmetic; -mod multiple_crate_versions; -mod mut_key; -mod mut_mut; -mod mut_mutex_lock; -mod mut_reference; -mod mutable_debug_assertion; -mod mutex_atomic; -mod needless_arbitrary_self_type; -mod needless_bool; -mod needless_borrow; -mod needless_borrowed_ref; -mod needless_continue; -mod needless_pass_by_value; -mod needless_update; -mod neg_cmp_op_on_partial_ord; -mod neg_multiply; -mod new_without_default; -mod no_effect; -mod non_copy_const; -mod non_expressive_names; -mod open_options; -mod option_env_unwrap; -mod option_if_let_else; -mod overflow_check_conditional; -mod panic_in_result_fn; -mod panic_unimplemented; -mod partialeq_ne_impl; -mod pass_by_ref_or_value; -mod path_buf_push_overwrite; -mod pattern_type_mismatch; -mod precedence; -mod ptr; -mod ptr_eq; -mod ptr_offset_with_cast; -mod question_mark; -mod ranges; -mod redundant_clone; -mod redundant_closure_call; -mod redundant_else; -mod redundant_field_names; -mod redundant_pub_crate; -mod redundant_static_lifetimes; -mod ref_option_ref; -mod reference; -mod regex; -mod repeat_once; -mod returns; -mod self_assignment; -mod serde_api; -mod shadow; -mod single_component_path_imports; -mod size_of_in_element_count; -mod slow_vector_initialization; -mod stable_sort_primitive; -mod strings; -mod suspicious_operation_groupings; -mod suspicious_trait_impl; -mod swap; -mod tabs_in_doc_comments; -mod temporary_assignment; -mod to_digit_is_some; -mod to_string_in_display; -mod trait_bounds; -mod transmute; -mod transmuting_null; -mod try_err; -mod types; -mod undropped_manually_drops; -mod unicode; -mod unit_return_expecting_ord; -mod unnamed_address; -mod unnecessary_sort_by; -mod unnecessary_wraps; -mod unnested_or_patterns; -mod unsafe_removed_from_name; -mod unused_io_amount; -mod unused_self; -mod unused_unit; -mod unwrap; -mod unwrap_in_result; -mod use_self; -mod useless_conversion; -mod vec; -mod vec_resize_to_zero; -mod verbose_file_reads; -mod wildcard_dependencies; -mod wildcard_imports; -mod write; -mod zero_div_zero; -mod zero_sized_map_values; -// end lints modules, do not remove this comment, it’s used in `update_lints` - -pub use crate::utils::conf::Conf; - -/// Register all pre expansion lints -/// -/// Pre-expansion lints run before any macro expansion has happened. -/// -/// Note that due to the architecture of the compiler, currently `cfg_attr` attributes on crate -/// level (i.e `#![cfg_attr(...)]`) will still be expanded even when using a pre-expansion pass. -/// -/// Used in `./src/driver.rs`. -pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore) { - store.register_pre_expansion_pass(|| box write::Write::default()); - store.register_pre_expansion_pass(|| box attrs::EarlyAttributes); - store.register_pre_expansion_pass(|| box dbg_macro::DbgMacro); -} - -#[doc(hidden)] -pub fn read_conf(args: &[rustc_ast::NestedMetaItem], sess: &Session) -> Conf { - use std::path::Path; - match utils::conf::file_from_args(args) { - Ok(file_name) => { - // if the user specified a file, it must exist, otherwise default to `clippy.toml` but - // do not require the file to exist - let file_name = match file_name { - Some(file_name) => file_name, - None => match utils::conf::lookup_conf_file() { - Ok(Some(path)) => path, - Ok(None) => return Conf::default(), - Err(error) => { - sess.struct_err(&format!("error finding Clippy's configuration file: {}", error)) - .emit(); - return Conf::default(); - }, - }, - }; - - let file_name = if file_name.is_relative() { - sess.local_crate_source_file - .as_deref() - .and_then(Path::parent) - .unwrap_or_else(|| Path::new("")) - .join(file_name) - } else { - file_name - }; - - let (conf, errors) = utils::conf::read(&file_name); - - // all conf errors are non-fatal, we just use the default conf in case of error - for error in errors { - sess.struct_err(&format!( - "error reading Clippy's configuration file `{}`: {}", - file_name.display(), - error - )) - .emit(); - } - - conf - }, - Err((err, span)) => { - sess.struct_span_err(span, err) - .span_note(span, "Clippy will use default configuration") - .emit(); - Conf::default() - }, - } -} - -/// Register all lints and lint groups with the rustc plugin registry -/// -/// Used in `./src/driver.rs`. -#[allow(clippy::too_many_lines)] -#[rustfmt::skip] -pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) { - register_removed_non_tool_lints(store); - - // begin deprecated lints, do not remove this comment, it’s used in `update_lints` - store.register_removed( - "clippy::should_assert_eq", - "`assert!()` will be more flexible with RFC 2011", - ); - store.register_removed( - "clippy::extend_from_slice", - "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice", - ); - store.register_removed( - "clippy::range_step_by_zero", - "`iterator.step_by(0)` panics nowadays", - ); - store.register_removed( - "clippy::unstable_as_slice", - "`Vec::as_slice` has been stabilized in 1.7", - ); - store.register_removed( - "clippy::unstable_as_mut_slice", - "`Vec::as_mut_slice` has been stabilized in 1.7", - ); - store.register_removed( - "clippy::misaligned_transmute", - "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr", - ); - store.register_removed( - "clippy::assign_ops", - "using compound assignment operators (e.g., `+=`) is harmless", - ); - store.register_removed( - "clippy::if_let_redundant_pattern_matching", - "this lint has been changed to redundant_pattern_matching", - ); - store.register_removed( - "clippy::unsafe_vector_initialization", - "the replacement suggested by this lint had substantially different behavior", - ); - store.register_removed( - "clippy::invalid_ref", - "superseded by rustc lint `invalid_value`", - ); - store.register_removed( - "clippy::unused_collect", - "`collect` has been marked as #[must_use] in rustc and that covers all cases of this lint", - ); - store.register_removed( - "clippy::into_iter_on_array", - "this lint has been uplifted to rustc and is now called `array_into_iter`", - ); - store.register_removed( - "clippy::unused_label", - "this lint has been uplifted to rustc and is now called `unused_labels`", - ); - store.register_removed( - "clippy::replace_consts", - "associated-constants `MIN`/`MAX` of integers are preferred to `{min,max}_value()` and module constants", - ); - store.register_removed( - "clippy::regex_macro", - "the regex! macro has been removed from the regex crate in 2018", - ); - store.register_removed( - "clippy::drop_bounds", - "this lint has been uplifted to rustc and is now called `drop_bounds`", - ); - store.register_removed( - "clippy::temporary_cstring_as_ptr", - "this lint has been uplifted to rustc and is now called `temporary_cstring_as_ptr`", - ); - store.register_removed( - "clippy::panic_params", - "this lint has been uplifted to rustc and is now called `panic_fmt`", - ); - // end deprecated lints, do not remove this comment, it’s used in `update_lints` - - // begin register lints, do not remove this comment, it’s used in `update_lints` - store.register_lints(&[ - #[cfg(feature = "internal-lints")] - &utils::internal_lints::CLIPPY_LINTS_INTERNAL, - #[cfg(feature = "internal-lints")] - &utils::internal_lints::COLLAPSIBLE_SPAN_LINT_CALLS, - #[cfg(feature = "internal-lints")] - &utils::internal_lints::COMPILER_LINT_FUNCTIONS, - #[cfg(feature = "internal-lints")] - &utils::internal_lints::DEFAULT_LINT, - #[cfg(feature = "internal-lints")] - &utils::internal_lints::INTERNING_DEFINED_SYMBOL, - #[cfg(feature = "internal-lints")] - &utils::internal_lints::INVALID_PATHS, - #[cfg(feature = "internal-lints")] - &utils::internal_lints::LINT_WITHOUT_LINT_PASS, - #[cfg(feature = "internal-lints")] - &utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM, - #[cfg(feature = "internal-lints")] - &utils::internal_lints::OUTER_EXPN_EXPN_DATA, - #[cfg(feature = "internal-lints")] - &utils::internal_lints::PRODUCE_ICE, - &approx_const::APPROX_CONSTANT, - &arithmetic::FLOAT_ARITHMETIC, - &arithmetic::INTEGER_ARITHMETIC, - &as_conversions::AS_CONVERSIONS, - &asm_syntax::INLINE_ASM_X86_ATT_SYNTAX, - &asm_syntax::INLINE_ASM_X86_INTEL_SYNTAX, - &assertions_on_constants::ASSERTIONS_ON_CONSTANTS, - &assign_ops::ASSIGN_OP_PATTERN, - &assign_ops::MISREFACTORED_ASSIGN_OP, - &async_yields_async::ASYNC_YIELDS_ASYNC, - &atomic_ordering::INVALID_ATOMIC_ORDERING, - &attrs::BLANKET_CLIPPY_RESTRICTION_LINTS, - &attrs::DEPRECATED_CFG_ATTR, - &attrs::DEPRECATED_SEMVER, - &attrs::EMPTY_LINE_AFTER_OUTER_ATTR, - &attrs::INLINE_ALWAYS, - &attrs::MISMATCHED_TARGET_OS, - &attrs::UNKNOWN_CLIPPY_LINTS, - &attrs::USELESS_ATTRIBUTE, - &await_holding_invalid::AWAIT_HOLDING_LOCK, - &await_holding_invalid::AWAIT_HOLDING_REFCELL_REF, - &bit_mask::BAD_BIT_MASK, - &bit_mask::INEFFECTIVE_BIT_MASK, - &bit_mask::VERBOSE_BIT_MASK, - &blacklisted_name::BLACKLISTED_NAME, - &blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS, - &booleans::LOGIC_BUG, - &booleans::NONMINIMAL_BOOL, - &bytecount::NAIVE_BYTECOUNT, - &cargo_common_metadata::CARGO_COMMON_METADATA, - &checked_conversions::CHECKED_CONVERSIONS, - &cognitive_complexity::COGNITIVE_COMPLEXITY, - &collapsible_if::COLLAPSIBLE_IF, - &collapsible_match::COLLAPSIBLE_MATCH, - &comparison_chain::COMPARISON_CHAIN, - &copies::IFS_SAME_COND, - &copies::IF_SAME_THEN_ELSE, - &copies::SAME_FUNCTIONS_IN_IF_CONDITION, - ©_iterator::COPY_ITERATOR, - &create_dir::CREATE_DIR, - &dbg_macro::DBG_MACRO, - &default::DEFAULT_TRAIT_ACCESS, - &default::FIELD_REASSIGN_WITH_DEFAULT, - &dereference::EXPLICIT_DEREF_METHODS, - &derive::DERIVE_HASH_XOR_EQ, - &derive::DERIVE_ORD_XOR_PARTIAL_ORD, - &derive::EXPL_IMPL_CLONE_ON_COPY, - &derive::UNSAFE_DERIVE_DESERIALIZE, - &disallowed_method::DISALLOWED_METHOD, - &doc::DOC_MARKDOWN, - &doc::MISSING_ERRORS_DOC, - &doc::MISSING_SAFETY_DOC, - &doc::NEEDLESS_DOCTEST_MAIN, - &double_comparison::DOUBLE_COMPARISONS, - &double_parens::DOUBLE_PARENS, - &drop_forget_ref::DROP_COPY, - &drop_forget_ref::DROP_REF, - &drop_forget_ref::FORGET_COPY, - &drop_forget_ref::FORGET_REF, - &duration_subsec::DURATION_SUBSEC, - &else_if_without_else::ELSE_IF_WITHOUT_ELSE, - &empty_enum::EMPTY_ENUM, - &entry::MAP_ENTRY, - &enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT, - &enum_variants::ENUM_VARIANT_NAMES, - &enum_variants::MODULE_INCEPTION, - &enum_variants::MODULE_NAME_REPETITIONS, - &enum_variants::PUB_ENUM_VARIANT_NAMES, - &eq_op::EQ_OP, - &eq_op::OP_REF, - &erasing_op::ERASING_OP, - &escape::BOXED_LOCAL, - &eta_reduction::REDUNDANT_CLOSURE, - &eta_reduction::REDUNDANT_CLOSURE_FOR_METHOD_CALLS, - &eval_order_dependence::DIVERGING_SUB_EXPRESSION, - &eval_order_dependence::EVAL_ORDER_DEPENDENCE, - &excessive_bools::FN_PARAMS_EXCESSIVE_BOOLS, - &excessive_bools::STRUCT_EXCESSIVE_BOOLS, - &exit::EXIT, - &explicit_write::EXPLICIT_WRITE, - &fallible_impl_from::FALLIBLE_IMPL_FROM, - &float_equality_without_abs::FLOAT_EQUALITY_WITHOUT_ABS, - &float_literal::EXCESSIVE_PRECISION, - &float_literal::LOSSY_FLOAT_LITERAL, - &floating_point_arithmetic::IMPRECISE_FLOPS, - &floating_point_arithmetic::SUBOPTIMAL_FLOPS, - &format::USELESS_FORMAT, - &formatting::POSSIBLE_MISSING_COMMA, - &formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING, - &formatting::SUSPICIOUS_ELSE_FORMATTING, - &formatting::SUSPICIOUS_UNARY_OP_FORMATTING, - &functions::DOUBLE_MUST_USE, - &functions::MUST_USE_CANDIDATE, - &functions::MUST_USE_UNIT, - &functions::NOT_UNSAFE_PTR_ARG_DEREF, - &functions::RESULT_UNIT_ERR, - &functions::TOO_MANY_ARGUMENTS, - &functions::TOO_MANY_LINES, - &future_not_send::FUTURE_NOT_SEND, - &get_last_with_len::GET_LAST_WITH_LEN, - &identity_op::IDENTITY_OP, - &if_let_mutex::IF_LET_MUTEX, - &if_let_some_result::IF_LET_SOME_RESULT, - &if_not_else::IF_NOT_ELSE, - &implicit_return::IMPLICIT_RETURN, - &implicit_saturating_sub::IMPLICIT_SATURATING_SUB, - &indexing_slicing::INDEXING_SLICING, - &indexing_slicing::OUT_OF_BOUNDS_INDEXING, - &infinite_iter::INFINITE_ITER, - &infinite_iter::MAYBE_INFINITE_ITER, - &inherent_impl::MULTIPLE_INHERENT_IMPL, - &inherent_to_string::INHERENT_TO_STRING, - &inherent_to_string::INHERENT_TO_STRING_SHADOW_DISPLAY, - &inline_fn_without_body::INLINE_FN_WITHOUT_BODY, - &int_plus_one::INT_PLUS_ONE, - &integer_division::INTEGER_DIVISION, - &items_after_statements::ITEMS_AFTER_STATEMENTS, - &large_const_arrays::LARGE_CONST_ARRAYS, - &large_enum_variant::LARGE_ENUM_VARIANT, - &large_stack_arrays::LARGE_STACK_ARRAYS, - &len_zero::COMPARISON_TO_EMPTY, - &len_zero::LEN_WITHOUT_IS_EMPTY, - &len_zero::LEN_ZERO, - &let_if_seq::USELESS_LET_IF_SEQ, - &let_underscore::LET_UNDERSCORE_DROP, - &let_underscore::LET_UNDERSCORE_LOCK, - &let_underscore::LET_UNDERSCORE_MUST_USE, - &lifetimes::EXTRA_UNUSED_LIFETIMES, - &lifetimes::NEEDLESS_LIFETIMES, - &literal_representation::DECIMAL_LITERAL_REPRESENTATION, - &literal_representation::INCONSISTENT_DIGIT_GROUPING, - &literal_representation::LARGE_DIGIT_GROUPS, - &literal_representation::MISTYPED_LITERAL_SUFFIXES, - &literal_representation::UNREADABLE_LITERAL, - &literal_representation::UNUSUAL_BYTE_GROUPINGS, - &loops::EMPTY_LOOP, - &loops::EXPLICIT_COUNTER_LOOP, - &loops::EXPLICIT_INTO_ITER_LOOP, - &loops::EXPLICIT_ITER_LOOP, - &loops::FOR_KV_MAP, - &loops::FOR_LOOPS_OVER_FALLIBLES, - &loops::ITER_NEXT_LOOP, - &loops::MANUAL_MEMCPY, - &loops::MUT_RANGE_BOUND, - &loops::NEEDLESS_COLLECT, - &loops::NEEDLESS_RANGE_LOOP, - &loops::NEVER_LOOP, - &loops::SAME_ITEM_PUSH, - &loops::SINGLE_ELEMENT_LOOP, - &loops::WHILE_IMMUTABLE_CONDITION, - &loops::WHILE_LET_LOOP, - &loops::WHILE_LET_ON_ITERATOR, - ¯o_use::MACRO_USE_IMPORTS, - &main_recursion::MAIN_RECURSION, - &manual_async_fn::MANUAL_ASYNC_FN, - &manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE, - &manual_ok_or::MANUAL_OK_OR, - &manual_strip::MANUAL_STRIP, - &manual_unwrap_or::MANUAL_UNWRAP_OR, - &map_clone::MAP_CLONE, - &map_err_ignore::MAP_ERR_IGNORE, - &map_identity::MAP_IDENTITY, - &map_unit_fn::OPTION_MAP_UNIT_FN, - &map_unit_fn::RESULT_MAP_UNIT_FN, - &match_on_vec_items::MATCH_ON_VEC_ITEMS, - &matches::INFALLIBLE_DESTRUCTURING_MATCH, - &matches::MATCH_AS_REF, - &matches::MATCH_BOOL, - &matches::MATCH_LIKE_MATCHES_MACRO, - &matches::MATCH_OVERLAPPING_ARM, - &matches::MATCH_REF_PATS, - &matches::MATCH_SAME_ARMS, - &matches::MATCH_SINGLE_BINDING, - &matches::MATCH_WILDCARD_FOR_SINGLE_VARIANTS, - &matches::MATCH_WILD_ERR_ARM, - &matches::REDUNDANT_PATTERN_MATCHING, - &matches::REST_PAT_IN_FULLY_BOUND_STRUCTS, - &matches::SINGLE_MATCH, - &matches::SINGLE_MATCH_ELSE, - &matches::WILDCARD_ENUM_MATCH_ARM, - &matches::WILDCARD_IN_OR_PATTERNS, - &mem_discriminant::MEM_DISCRIMINANT_NON_ENUM, - &mem_forget::MEM_FORGET, - &mem_replace::MEM_REPLACE_OPTION_WITH_NONE, - &mem_replace::MEM_REPLACE_WITH_DEFAULT, - &mem_replace::MEM_REPLACE_WITH_UNINIT, - &methods::BIND_INSTEAD_OF_MAP, - &methods::CHARS_LAST_CMP, - &methods::CHARS_NEXT_CMP, - &methods::CLONE_DOUBLE_REF, - &methods::CLONE_ON_COPY, - &methods::CLONE_ON_REF_PTR, - &methods::EXPECT_FUN_CALL, - &methods::EXPECT_USED, - &methods::FILETYPE_IS_FILE, - &methods::FILTER_MAP, - &methods::FILTER_MAP_NEXT, - &methods::FILTER_NEXT, - &methods::FIND_MAP, - &methods::FLAT_MAP_IDENTITY, - &methods::FROM_ITER_INSTEAD_OF_COLLECT, - &methods::GET_UNWRAP, - &methods::INEFFICIENT_TO_STRING, - &methods::INTO_ITER_ON_REF, - &methods::ITERATOR_STEP_BY_ZERO, - &methods::ITER_CLONED_COLLECT, - &methods::ITER_NEXT_SLICE, - &methods::ITER_NTH, - &methods::ITER_NTH_ZERO, - &methods::ITER_SKIP_NEXT, - &methods::MANUAL_SATURATING_ARITHMETIC, - &methods::MAP_COLLECT_RESULT_UNIT, - &methods::MAP_FLATTEN, - &methods::MAP_UNWRAP_OR, - &methods::NEW_RET_NO_SELF, - &methods::OK_EXPECT, - &methods::OPTION_AS_REF_DEREF, - &methods::OPTION_MAP_OR_NONE, - &methods::OR_FUN_CALL, - &methods::RESULT_MAP_OR_INTO_OPTION, - &methods::SEARCH_IS_SOME, - &methods::SHOULD_IMPLEMENT_TRAIT, - &methods::SINGLE_CHAR_ADD_STR, - &methods::SINGLE_CHAR_PATTERN, - &methods::SKIP_WHILE_NEXT, - &methods::STRING_EXTEND_CHARS, - &methods::SUSPICIOUS_MAP, - &methods::UNINIT_ASSUMED_INIT, - &methods::UNNECESSARY_FILTER_MAP, - &methods::UNNECESSARY_FOLD, - &methods::UNNECESSARY_LAZY_EVALUATIONS, - &methods::UNWRAP_USED, - &methods::USELESS_ASREF, - &methods::WRONG_PUB_SELF_CONVENTION, - &methods::WRONG_SELF_CONVENTION, - &methods::ZST_OFFSET, - &minmax::MIN_MAX, - &misc::CMP_NAN, - &misc::CMP_OWNED, - &misc::FLOAT_CMP, - &misc::FLOAT_CMP_CONST, - &misc::MODULO_ONE, - &misc::SHORT_CIRCUIT_STATEMENT, - &misc::TOPLEVEL_REF_ARG, - &misc::USED_UNDERSCORE_BINDING, - &misc::ZERO_PTR, - &misc_early::BUILTIN_TYPE_SHADOW, - &misc_early::DOUBLE_NEG, - &misc_early::DUPLICATE_UNDERSCORE_ARGUMENT, - &misc_early::MIXED_CASE_HEX_LITERALS, - &misc_early::REDUNDANT_PATTERN, - &misc_early::UNNEEDED_FIELD_PATTERN, - &misc_early::UNNEEDED_WILDCARD_PATTERN, - &misc_early::UNSEPARATED_LITERAL_SUFFIX, - &misc_early::ZERO_PREFIXED_LITERAL, - &missing_const_for_fn::MISSING_CONST_FOR_FN, - &missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS, - &missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS, - &modulo_arithmetic::MODULO_ARITHMETIC, - &multiple_crate_versions::MULTIPLE_CRATE_VERSIONS, - &mut_key::MUTABLE_KEY_TYPE, - &mut_mut::MUT_MUT, - &mut_mutex_lock::MUT_MUTEX_LOCK, - &mut_reference::UNNECESSARY_MUT_PASSED, - &mutable_debug_assertion::DEBUG_ASSERT_WITH_MUT_CALL, - &mutex_atomic::MUTEX_ATOMIC, - &mutex_atomic::MUTEX_INTEGER, - &needless_arbitrary_self_type::NEEDLESS_ARBITRARY_SELF_TYPE, - &needless_bool::BOOL_COMPARISON, - &needless_bool::NEEDLESS_BOOL, - &needless_borrow::NEEDLESS_BORROW, - &needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE, - &needless_continue::NEEDLESS_CONTINUE, - &needless_pass_by_value::NEEDLESS_PASS_BY_VALUE, - &needless_update::NEEDLESS_UPDATE, - &neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD, - &neg_multiply::NEG_MULTIPLY, - &new_without_default::NEW_WITHOUT_DEFAULT, - &no_effect::NO_EFFECT, - &no_effect::UNNECESSARY_OPERATION, - &non_copy_const::BORROW_INTERIOR_MUTABLE_CONST, - &non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST, - &non_expressive_names::JUST_UNDERSCORES_AND_DIGITS, - &non_expressive_names::MANY_SINGLE_CHAR_NAMES, - &non_expressive_names::SIMILAR_NAMES, - &open_options::NONSENSICAL_OPEN_OPTIONS, - &option_env_unwrap::OPTION_ENV_UNWRAP, - &option_if_let_else::OPTION_IF_LET_ELSE, - &overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL, - &panic_in_result_fn::PANIC_IN_RESULT_FN, - &panic_unimplemented::PANIC, - &panic_unimplemented::TODO, - &panic_unimplemented::UNIMPLEMENTED, - &panic_unimplemented::UNREACHABLE, - &partialeq_ne_impl::PARTIALEQ_NE_IMPL, - &pass_by_ref_or_value::LARGE_TYPES_PASSED_BY_VALUE, - &pass_by_ref_or_value::TRIVIALLY_COPY_PASS_BY_REF, - &path_buf_push_overwrite::PATH_BUF_PUSH_OVERWRITE, - &pattern_type_mismatch::PATTERN_TYPE_MISMATCH, - &precedence::PRECEDENCE, - &ptr::CMP_NULL, - &ptr::MUT_FROM_REF, - &ptr::PTR_ARG, - &ptr_eq::PTR_EQ, - &ptr_offset_with_cast::PTR_OFFSET_WITH_CAST, - &question_mark::QUESTION_MARK, - &ranges::MANUAL_RANGE_CONTAINS, - &ranges::RANGE_MINUS_ONE, - &ranges::RANGE_PLUS_ONE, - &ranges::RANGE_ZIP_WITH_LEN, - &ranges::REVERSED_EMPTY_RANGES, - &redundant_clone::REDUNDANT_CLONE, - &redundant_closure_call::REDUNDANT_CLOSURE_CALL, - &redundant_else::REDUNDANT_ELSE, - &redundant_field_names::REDUNDANT_FIELD_NAMES, - &redundant_pub_crate::REDUNDANT_PUB_CRATE, - &redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES, - &ref_option_ref::REF_OPTION_REF, - &reference::DEREF_ADDROF, - &reference::REF_IN_DEREF, - ®ex::INVALID_REGEX, - ®ex::TRIVIAL_REGEX, - &repeat_once::REPEAT_ONCE, - &returns::LET_AND_RETURN, - &returns::NEEDLESS_RETURN, - &self_assignment::SELF_ASSIGNMENT, - &serde_api::SERDE_API_MISUSE, - &shadow::SHADOW_REUSE, - &shadow::SHADOW_SAME, - &shadow::SHADOW_UNRELATED, - &single_component_path_imports::SINGLE_COMPONENT_PATH_IMPORTS, - &size_of_in_element_count::SIZE_OF_IN_ELEMENT_COUNT, - &slow_vector_initialization::SLOW_VECTOR_INITIALIZATION, - &stable_sort_primitive::STABLE_SORT_PRIMITIVE, - &strings::STRING_ADD, - &strings::STRING_ADD_ASSIGN, - &strings::STRING_FROM_UTF8_AS_BYTES, - &strings::STRING_LIT_AS_BYTES, - &strings::STRING_TO_STRING, - &strings::STR_TO_STRING, - &suspicious_operation_groupings::SUSPICIOUS_OPERATION_GROUPINGS, - &suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL, - &suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL, - &swap::ALMOST_SWAPPED, - &swap::MANUAL_SWAP, - &tabs_in_doc_comments::TABS_IN_DOC_COMMENTS, - &temporary_assignment::TEMPORARY_ASSIGNMENT, - &to_digit_is_some::TO_DIGIT_IS_SOME, - &to_string_in_display::TO_STRING_IN_DISPLAY, - &trait_bounds::TRAIT_DUPLICATION_IN_BOUNDS, - &trait_bounds::TYPE_REPETITION_IN_BOUNDS, - &transmute::CROSSPOINTER_TRANSMUTE, - &transmute::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, - &transmute::TRANSMUTE_BYTES_TO_STR, - &transmute::TRANSMUTE_FLOAT_TO_INT, - &transmute::TRANSMUTE_INT_TO_BOOL, - &transmute::TRANSMUTE_INT_TO_CHAR, - &transmute::TRANSMUTE_INT_TO_FLOAT, - &transmute::TRANSMUTE_PTR_TO_PTR, - &transmute::TRANSMUTE_PTR_TO_REF, - &transmute::UNSOUND_COLLECTION_TRANSMUTE, - &transmute::USELESS_TRANSMUTE, - &transmute::WRONG_TRANSMUTE, - &transmuting_null::TRANSMUTING_NULL, - &try_err::TRY_ERR, - &types::ABSURD_EXTREME_COMPARISONS, - &types::BORROWED_BOX, - &types::BOX_VEC, - &types::CAST_LOSSLESS, - &types::CAST_POSSIBLE_TRUNCATION, - &types::CAST_POSSIBLE_WRAP, - &types::CAST_PRECISION_LOSS, - &types::CAST_PTR_ALIGNMENT, - &types::CAST_REF_TO_MUT, - &types::CAST_SIGN_LOSS, - &types::CHAR_LIT_AS_U8, - &types::FN_TO_NUMERIC_CAST, - &types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION, - &types::IMPLICIT_HASHER, - &types::INVALID_UPCAST_COMPARISONS, - &types::LET_UNIT_VALUE, - &types::LINKEDLIST, - &types::OPTION_OPTION, - &types::RC_BUFFER, - &types::REDUNDANT_ALLOCATION, - &types::TYPE_COMPLEXITY, - &types::UNIT_ARG, - &types::UNIT_CMP, - &types::UNNECESSARY_CAST, - &types::VEC_BOX, - &undropped_manually_drops::UNDROPPED_MANUALLY_DROPS, - &unicode::INVISIBLE_CHARACTERS, - &unicode::NON_ASCII_LITERAL, - &unicode::UNICODE_NOT_NFC, - &unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD, - &unnamed_address::FN_ADDRESS_COMPARISONS, - &unnamed_address::VTABLE_ADDRESS_COMPARISONS, - &unnecessary_sort_by::UNNECESSARY_SORT_BY, - &unnecessary_wraps::UNNECESSARY_WRAPS, - &unnested_or_patterns::UNNESTED_OR_PATTERNS, - &unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME, - &unused_io_amount::UNUSED_IO_AMOUNT, - &unused_self::UNUSED_SELF, - &unused_unit::UNUSED_UNIT, - &unwrap::PANICKING_UNWRAP, - &unwrap::UNNECESSARY_UNWRAP, - &unwrap_in_result::UNWRAP_IN_RESULT, - &use_self::USE_SELF, - &useless_conversion::USELESS_CONVERSION, - &vec::USELESS_VEC, - &vec_resize_to_zero::VEC_RESIZE_TO_ZERO, - &verbose_file_reads::VERBOSE_FILE_READS, - &wildcard_dependencies::WILDCARD_DEPENDENCIES, - &wildcard_imports::ENUM_GLOB_USE, - &wildcard_imports::WILDCARD_IMPORTS, - &write::PRINTLN_EMPTY_STRING, - &write::PRINT_LITERAL, - &write::PRINT_STDERR, - &write::PRINT_STDOUT, - &write::PRINT_WITH_NEWLINE, - &write::USE_DEBUG, - &write::WRITELN_EMPTY_STRING, - &write::WRITE_LITERAL, - &write::WRITE_WITH_NEWLINE, - &zero_div_zero::ZERO_DIVIDED_BY_ZERO, - &zero_sized_map_values::ZERO_SIZED_MAP_VALUES, - ]); - // end register lints, do not remove this comment, it’s used in `update_lints` - - // all the internal lints - #[cfg(feature = "internal-lints")] - { - store.register_early_pass(|| box utils::internal_lints::ClippyLintsInternal); - store.register_early_pass(|| box utils::internal_lints::ProduceIce); - store.register_late_pass(|| box utils::inspector::DeepCodeInspector); - store.register_late_pass(|| box utils::internal_lints::CollapsibleCalls); - store.register_late_pass(|| box utils::internal_lints::CompilerLintFunctions::new()); - store.register_late_pass(|| box utils::internal_lints::InvalidPaths); - store.register_late_pass(|| box utils::internal_lints::InterningDefinedSymbol::default()); - store.register_late_pass(|| box utils::internal_lints::LintWithoutLintPass::default()); - store.register_late_pass(|| box utils::internal_lints::MatchTypeOnDiagItem); - store.register_late_pass(|| box utils::internal_lints::OuterExpnDataPass); - } - store.register_late_pass(|| box utils::author::Author); - store.register_late_pass(|| box await_holding_invalid::AwaitHolding); - store.register_late_pass(|| box serde_api::SerdeAPI); - let vec_box_size_threshold = conf.vec_box_size_threshold; - store.register_late_pass(move || box types::Types::new(vec_box_size_threshold)); - store.register_late_pass(|| box booleans::NonminimalBool); - store.register_late_pass(|| box eq_op::EqOp); - store.register_late_pass(|| box enum_clike::UnportableVariant); - store.register_late_pass(|| box float_literal::FloatLiteral); - let verbose_bit_mask_threshold = conf.verbose_bit_mask_threshold; - store.register_late_pass(move || box bit_mask::BitMask::new(verbose_bit_mask_threshold)); - store.register_late_pass(|| box ptr::Ptr); - store.register_late_pass(|| box ptr_eq::PtrEq); - store.register_late_pass(|| box needless_bool::NeedlessBool); - store.register_late_pass(|| box needless_bool::BoolComparison); - store.register_late_pass(|| box approx_const::ApproxConstant); - store.register_late_pass(|| box misc::MiscLints); - store.register_late_pass(|| box eta_reduction::EtaReduction); - store.register_late_pass(|| box identity_op::IdentityOp); - store.register_late_pass(|| box erasing_op::ErasingOp); - store.register_late_pass(|| box mut_mut::MutMut); - store.register_late_pass(|| box mut_reference::UnnecessaryMutPassed); - store.register_late_pass(|| box len_zero::LenZero); - store.register_late_pass(|| box attrs::Attributes); - store.register_late_pass(|| box blocks_in_if_conditions::BlocksInIfConditions); - store.register_late_pass(|| box collapsible_match::CollapsibleMatch); - store.register_late_pass(|| box unicode::Unicode); - store.register_late_pass(|| box unit_return_expecting_ord::UnitReturnExpectingOrd); - store.register_late_pass(|| box strings::StringAdd); - store.register_late_pass(|| box implicit_return::ImplicitReturn); - store.register_late_pass(|| box implicit_saturating_sub::ImplicitSaturatingSub); - - let msrv = conf.msrv.as_ref().and_then(|s| { - parse_msrv(s, None, None).or_else(|| { - sess.err(&format!("error reading Clippy's configuration file. `{}` is not a valid Rust version", s)); - None - }) - }); - - store.register_late_pass(move || box methods::Methods::new(msrv)); - store.register_late_pass(move || box matches::Matches::new(msrv)); - store.register_early_pass(move || box manual_non_exhaustive::ManualNonExhaustive::new(msrv)); - store.register_late_pass(move || box manual_strip::ManualStrip::new(msrv)); - store.register_early_pass(move || box redundant_static_lifetimes::RedundantStaticLifetimes::new(msrv)); - store.register_early_pass(move || box redundant_field_names::RedundantFieldNames::new(msrv)); - store.register_late_pass(move || box checked_conversions::CheckedConversions::new(msrv)); - store.register_late_pass(move || box mem_replace::MemReplace::new(msrv)); - store.register_late_pass(move || box ranges::Ranges::new(msrv)); - store.register_late_pass(move || box use_self::UseSelf::new(msrv)); - store.register_late_pass(move || box missing_const_for_fn::MissingConstForFn::new(msrv)); - - store.register_late_pass(|| box size_of_in_element_count::SizeOfInElementCount); - store.register_late_pass(|| box map_clone::MapClone); - store.register_late_pass(|| box map_err_ignore::MapErrIgnore); - store.register_late_pass(|| box shadow::Shadow); - store.register_late_pass(|| box types::LetUnitValue); - store.register_late_pass(|| box types::UnitCmp); - store.register_late_pass(|| box loops::Loops); - store.register_late_pass(|| box main_recursion::MainRecursion::default()); - store.register_late_pass(|| box lifetimes::Lifetimes); - store.register_late_pass(|| box entry::HashMapPass); - store.register_late_pass(|| box types::Casts); - let type_complexity_threshold = conf.type_complexity_threshold; - store.register_late_pass(move || box types::TypeComplexity::new(type_complexity_threshold)); - store.register_late_pass(|| box minmax::MinMaxPass); - store.register_late_pass(|| box open_options::OpenOptions); - store.register_late_pass(|| box zero_div_zero::ZeroDiv); - store.register_late_pass(|| box mutex_atomic::Mutex); - store.register_late_pass(|| box needless_update::NeedlessUpdate); - store.register_late_pass(|| box needless_borrow::NeedlessBorrow::default()); - store.register_late_pass(|| box needless_borrowed_ref::NeedlessBorrowedRef); - store.register_late_pass(|| box no_effect::NoEffect); - store.register_late_pass(|| box temporary_assignment::TemporaryAssignment); - store.register_late_pass(|| box transmute::Transmute); - let cognitive_complexity_threshold = conf.cognitive_complexity_threshold; - store.register_late_pass(move || box cognitive_complexity::CognitiveComplexity::new(cognitive_complexity_threshold)); - let too_large_for_stack = conf.too_large_for_stack; - store.register_late_pass(move || box escape::BoxedLocal{too_large_for_stack}); - store.register_late_pass(move || box vec::UselessVec{too_large_for_stack}); - store.register_late_pass(|| box panic_unimplemented::PanicUnimplemented); - store.register_late_pass(|| box strings::StringLitAsBytes); - store.register_late_pass(|| box derive::Derive); - store.register_late_pass(|| box types::CharLitAsU8); - store.register_late_pass(|| box get_last_with_len::GetLastWithLen); - store.register_late_pass(|| box drop_forget_ref::DropForgetRef); - store.register_late_pass(|| box empty_enum::EmptyEnum); - store.register_late_pass(|| box types::AbsurdExtremeComparisons); - store.register_late_pass(|| box types::InvalidUpcastComparisons); - store.register_late_pass(|| box regex::Regex::default()); - store.register_late_pass(|| box copies::CopyAndPaste); - store.register_late_pass(|| box copy_iterator::CopyIterator); - store.register_late_pass(|| box format::UselessFormat); - store.register_late_pass(|| box swap::Swap); - store.register_late_pass(|| box overflow_check_conditional::OverflowCheckConditional); - store.register_late_pass(|| box new_without_default::NewWithoutDefault::default()); - let blacklisted_names = conf.blacklisted_names.iter().cloned().collect::>(); - store.register_late_pass(move || box blacklisted_name::BlacklistedName::new(blacklisted_names.clone())); - let too_many_arguments_threshold1 = conf.too_many_arguments_threshold; - let too_many_lines_threshold2 = conf.too_many_lines_threshold; - store.register_late_pass(move || box functions::Functions::new(too_many_arguments_threshold1, too_many_lines_threshold2)); - let doc_valid_idents = conf.doc_valid_idents.iter().cloned().collect::>(); - store.register_late_pass(move || box doc::DocMarkdown::new(doc_valid_idents.clone())); - store.register_late_pass(|| box neg_multiply::NegMultiply); - store.register_late_pass(|| box mem_discriminant::MemDiscriminant); - store.register_late_pass(|| box mem_forget::MemForget); - store.register_late_pass(|| box arithmetic::Arithmetic::default()); - store.register_late_pass(|| box assign_ops::AssignOps); - store.register_late_pass(|| box let_if_seq::LetIfSeq); - store.register_late_pass(|| box eval_order_dependence::EvalOrderDependence); - store.register_late_pass(|| box missing_doc::MissingDoc::new()); - store.register_late_pass(|| box missing_inline::MissingInline); - store.register_late_pass(|| box if_let_some_result::OkIfLet); - store.register_late_pass(|| box partialeq_ne_impl::PartialEqNeImpl); - store.register_late_pass(|| box unused_io_amount::UnusedIoAmount); - let enum_variant_size_threshold = conf.enum_variant_size_threshold; - store.register_late_pass(move || box large_enum_variant::LargeEnumVariant::new(enum_variant_size_threshold)); - store.register_late_pass(|| box explicit_write::ExplicitWrite); - store.register_late_pass(|| box needless_pass_by_value::NeedlessPassByValue); - let pass_by_ref_or_value = pass_by_ref_or_value::PassByRefOrValue::new( - conf.trivial_copy_size_limit, - conf.pass_by_value_size_limit, - &sess.target, - ); - store.register_late_pass(move || box pass_by_ref_or_value); - store.register_late_pass(|| box ref_option_ref::RefOptionRef); - store.register_late_pass(|| box try_err::TryErr); - store.register_late_pass(|| box bytecount::ByteCount); - store.register_late_pass(|| box infinite_iter::InfiniteIter); - store.register_late_pass(|| box inline_fn_without_body::InlineFnWithoutBody); - store.register_late_pass(|| box useless_conversion::UselessConversion::default()); - store.register_late_pass(|| box types::ImplicitHasher); - store.register_late_pass(|| box fallible_impl_from::FallibleImplFrom); - store.register_late_pass(|| box types::UnitArg); - store.register_late_pass(|| box double_comparison::DoubleComparisons); - store.register_late_pass(|| box question_mark::QuestionMark); - store.register_early_pass(|| box suspicious_operation_groupings::SuspiciousOperationGroupings); - store.register_late_pass(|| box suspicious_trait_impl::SuspiciousImpl); - store.register_late_pass(|| box map_unit_fn::MapUnit); - store.register_late_pass(|| box inherent_impl::MultipleInherentImpl::default()); - store.register_late_pass(|| box neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd); - store.register_late_pass(|| box unwrap::Unwrap); - store.register_late_pass(|| box duration_subsec::DurationSubsec); - store.register_late_pass(|| box indexing_slicing::IndexingSlicing); - store.register_late_pass(|| box non_copy_const::NonCopyConst); - store.register_late_pass(|| box ptr_offset_with_cast::PtrOffsetWithCast); - store.register_late_pass(|| box redundant_clone::RedundantClone); - store.register_late_pass(|| box slow_vector_initialization::SlowVectorInit); - store.register_late_pass(|| box unnecessary_sort_by::UnnecessarySortBy); - store.register_late_pass(|| box unnecessary_wraps::UnnecessaryWraps); - store.register_late_pass(|| box types::RefToMut); - store.register_late_pass(|| box assertions_on_constants::AssertionsOnConstants); - store.register_late_pass(|| box transmuting_null::TransmutingNull); - store.register_late_pass(|| box path_buf_push_overwrite::PathBufPushOverwrite); - store.register_late_pass(|| box integer_division::IntegerDivision); - store.register_late_pass(|| box inherent_to_string::InherentToString); - let max_trait_bounds = conf.max_trait_bounds; - store.register_late_pass(move || box trait_bounds::TraitBounds::new(max_trait_bounds)); - store.register_late_pass(|| box comparison_chain::ComparisonChain); - store.register_late_pass(|| box mut_key::MutableKeyType); - store.register_late_pass(|| box modulo_arithmetic::ModuloArithmetic); - store.register_early_pass(|| box reference::DerefAddrOf); - store.register_early_pass(|| box reference::RefInDeref); - store.register_early_pass(|| box double_parens::DoubleParens); - store.register_late_pass(|| box to_string_in_display::ToStringInDisplay::new()); - store.register_early_pass(|| box unsafe_removed_from_name::UnsafeNameRemoval); - store.register_early_pass(|| box if_not_else::IfNotElse); - store.register_early_pass(|| box else_if_without_else::ElseIfWithoutElse); - store.register_early_pass(|| box int_plus_one::IntPlusOne); - store.register_early_pass(|| box formatting::Formatting); - store.register_early_pass(|| box misc_early::MiscEarlyLints); - store.register_early_pass(|| box redundant_closure_call::RedundantClosureCall); - store.register_late_pass(|| box redundant_closure_call::RedundantClosureCall); - store.register_early_pass(|| box unused_unit::UnusedUnit); - store.register_late_pass(|| box returns::Return); - store.register_early_pass(|| box collapsible_if::CollapsibleIf); - store.register_early_pass(|| box items_after_statements::ItemsAfterStatements); - store.register_early_pass(|| box precedence::Precedence); - store.register_early_pass(|| box needless_continue::NeedlessContinue); - store.register_early_pass(|| box redundant_else::RedundantElse); - store.register_late_pass(|| box create_dir::CreateDir); - store.register_early_pass(|| box needless_arbitrary_self_type::NeedlessArbitrarySelfType); - store.register_late_pass(|| box cargo_common_metadata::CargoCommonMetadata); - store.register_late_pass(|| box multiple_crate_versions::MultipleCrateVersions); - store.register_late_pass(|| box wildcard_dependencies::WildcardDependencies); - let literal_representation_lint_fraction_readability = conf.unreadable_literal_lint_fractions; - store.register_early_pass(move || box literal_representation::LiteralDigitGrouping::new(literal_representation_lint_fraction_readability)); - let literal_representation_threshold = conf.literal_representation_threshold; - store.register_early_pass(move || box literal_representation::DecimalLiteralRepresentation::new(literal_representation_threshold)); - let enum_variant_name_threshold = conf.enum_variant_name_threshold; - store.register_early_pass(move || box enum_variants::EnumVariantNames::new(enum_variant_name_threshold)); - store.register_early_pass(|| box tabs_in_doc_comments::TabsInDocComments); - store.register_late_pass(|| box default::Default::default()); - store.register_late_pass(|| box unused_self::UnusedSelf); - store.register_late_pass(|| box mutable_debug_assertion::DebugAssertWithMutCall); - store.register_late_pass(|| box exit::Exit); - store.register_late_pass(|| box to_digit_is_some::ToDigitIsSome); - let array_size_threshold = conf.array_size_threshold; - store.register_late_pass(move || box large_stack_arrays::LargeStackArrays::new(array_size_threshold)); - store.register_late_pass(move || box large_const_arrays::LargeConstArrays::new(array_size_threshold)); - store.register_late_pass(|| box floating_point_arithmetic::FloatingPointArithmetic); - store.register_early_pass(|| box as_conversions::AsConversions); - store.register_late_pass(|| box let_underscore::LetUnderscore); - store.register_late_pass(|| box atomic_ordering::AtomicOrdering); - store.register_early_pass(|| box single_component_path_imports::SingleComponentPathImports); - let max_fn_params_bools = conf.max_fn_params_bools; - let max_struct_bools = conf.max_struct_bools; - store.register_early_pass(move || box excessive_bools::ExcessiveBools::new(max_struct_bools, max_fn_params_bools)); - store.register_early_pass(|| box option_env_unwrap::OptionEnvUnwrap); - let warn_on_all_wildcard_imports = conf.warn_on_all_wildcard_imports; - store.register_late_pass(move || box wildcard_imports::WildcardImports::new(warn_on_all_wildcard_imports)); - store.register_late_pass(|| box verbose_file_reads::VerboseFileReads); - store.register_late_pass(|| box redundant_pub_crate::RedundantPubCrate::default()); - store.register_late_pass(|| box unnamed_address::UnnamedAddress); - store.register_late_pass(|| box dereference::Dereferencing); - store.register_late_pass(|| box option_if_let_else::OptionIfLetElse); - store.register_late_pass(|| box future_not_send::FutureNotSend); - store.register_late_pass(|| box if_let_mutex::IfLetMutex); - store.register_late_pass(|| box mut_mutex_lock::MutMutexLock); - store.register_late_pass(|| box match_on_vec_items::MatchOnVecItems); - store.register_late_pass(|| box manual_async_fn::ManualAsyncFn); - store.register_late_pass(|| box vec_resize_to_zero::VecResizeToZero); - store.register_late_pass(|| box panic_in_result_fn::PanicInResultFn); - let single_char_binding_names_threshold = conf.single_char_binding_names_threshold; - store.register_early_pass(move || box non_expressive_names::NonExpressiveNames { - single_char_binding_names_threshold, - }); - store.register_early_pass(|| box unnested_or_patterns::UnnestedOrPatterns); - store.register_late_pass(|| box macro_use::MacroUseImports::default()); - store.register_late_pass(|| box map_identity::MapIdentity); - store.register_late_pass(|| box pattern_type_mismatch::PatternTypeMismatch); - store.register_late_pass(|| box stable_sort_primitive::StableSortPrimitive); - store.register_late_pass(|| box repeat_once::RepeatOnce); - store.register_late_pass(|| box unwrap_in_result::UnwrapInResult); - store.register_late_pass(|| box self_assignment::SelfAssignment); - store.register_late_pass(|| box manual_unwrap_or::ManualUnwrapOr); - store.register_late_pass(|| box manual_ok_or::ManualOkOr); - store.register_late_pass(|| box float_equality_without_abs::FloatEqualityWithoutAbs); - store.register_late_pass(|| box async_yields_async::AsyncYieldsAsync); - let disallowed_methods = conf.disallowed_methods.iter().cloned().collect::>(); - store.register_late_pass(move || box disallowed_method::DisallowedMethod::new(&disallowed_methods)); - store.register_early_pass(|| box asm_syntax::InlineAsmX86AttSyntax); - store.register_early_pass(|| box asm_syntax::InlineAsmX86IntelSyntax); - store.register_late_pass(|| box undropped_manually_drops::UndroppedManuallyDrops); - store.register_late_pass(|| box strings::StrToString); - store.register_late_pass(|| box strings::StringToString); - store.register_late_pass(|| box zero_sized_map_values::ZeroSizedMapValues); - - store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![ - LintId::of(&arithmetic::FLOAT_ARITHMETIC), - LintId::of(&arithmetic::INTEGER_ARITHMETIC), - LintId::of(&as_conversions::AS_CONVERSIONS), - LintId::of(&asm_syntax::INLINE_ASM_X86_ATT_SYNTAX), - LintId::of(&asm_syntax::INLINE_ASM_X86_INTEL_SYNTAX), - LintId::of(&create_dir::CREATE_DIR), - LintId::of(&dbg_macro::DBG_MACRO), - LintId::of(&else_if_without_else::ELSE_IF_WITHOUT_ELSE), - LintId::of(&exit::EXIT), - LintId::of(&float_literal::LOSSY_FLOAT_LITERAL), - LintId::of(&implicit_return::IMPLICIT_RETURN), - LintId::of(&indexing_slicing::INDEXING_SLICING), - LintId::of(&inherent_impl::MULTIPLE_INHERENT_IMPL), - LintId::of(&integer_division::INTEGER_DIVISION), - LintId::of(&let_underscore::LET_UNDERSCORE_MUST_USE), - LintId::of(&literal_representation::DECIMAL_LITERAL_REPRESENTATION), - LintId::of(&map_err_ignore::MAP_ERR_IGNORE), - LintId::of(&matches::REST_PAT_IN_FULLY_BOUND_STRUCTS), - LintId::of(&matches::WILDCARD_ENUM_MATCH_ARM), - LintId::of(&mem_forget::MEM_FORGET), - LintId::of(&methods::CLONE_ON_REF_PTR), - LintId::of(&methods::EXPECT_USED), - LintId::of(&methods::FILETYPE_IS_FILE), - LintId::of(&methods::GET_UNWRAP), - LintId::of(&methods::UNWRAP_USED), - LintId::of(&methods::WRONG_PUB_SELF_CONVENTION), - LintId::of(&misc::FLOAT_CMP_CONST), - LintId::of(&misc_early::UNNEEDED_FIELD_PATTERN), - LintId::of(&missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS), - LintId::of(&missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS), - LintId::of(&modulo_arithmetic::MODULO_ARITHMETIC), - LintId::of(&panic_in_result_fn::PANIC_IN_RESULT_FN), - LintId::of(&panic_unimplemented::PANIC), - LintId::of(&panic_unimplemented::TODO), - LintId::of(&panic_unimplemented::UNIMPLEMENTED), - LintId::of(&panic_unimplemented::UNREACHABLE), - LintId::of(&pattern_type_mismatch::PATTERN_TYPE_MISMATCH), - LintId::of(&shadow::SHADOW_REUSE), - LintId::of(&shadow::SHADOW_SAME), - LintId::of(&strings::STRING_ADD), - LintId::of(&strings::STRING_TO_STRING), - LintId::of(&strings::STR_TO_STRING), - LintId::of(&types::RC_BUFFER), - LintId::of(&unwrap_in_result::UNWRAP_IN_RESULT), - LintId::of(&verbose_file_reads::VERBOSE_FILE_READS), - LintId::of(&write::PRINT_STDERR), - LintId::of(&write::PRINT_STDOUT), - LintId::of(&write::USE_DEBUG), - ]); - - store.register_group(true, "clippy::pedantic", Some("clippy_pedantic"), vec![ - LintId::of(&attrs::INLINE_ALWAYS), - LintId::of(&await_holding_invalid::AWAIT_HOLDING_LOCK), - LintId::of(&await_holding_invalid::AWAIT_HOLDING_REFCELL_REF), - LintId::of(&bit_mask::VERBOSE_BIT_MASK), - LintId::of(&checked_conversions::CHECKED_CONVERSIONS), - LintId::of(&copies::SAME_FUNCTIONS_IN_IF_CONDITION), - LintId::of(©_iterator::COPY_ITERATOR), - LintId::of(&default::DEFAULT_TRAIT_ACCESS), - LintId::of(&dereference::EXPLICIT_DEREF_METHODS), - LintId::of(&derive::EXPL_IMPL_CLONE_ON_COPY), - LintId::of(&derive::UNSAFE_DERIVE_DESERIALIZE), - LintId::of(&doc::DOC_MARKDOWN), - LintId::of(&doc::MISSING_ERRORS_DOC), - LintId::of(&empty_enum::EMPTY_ENUM), - LintId::of(&enum_variants::MODULE_NAME_REPETITIONS), - LintId::of(&enum_variants::PUB_ENUM_VARIANT_NAMES), - LintId::of(&eta_reduction::REDUNDANT_CLOSURE_FOR_METHOD_CALLS), - LintId::of(&excessive_bools::FN_PARAMS_EXCESSIVE_BOOLS), - LintId::of(&excessive_bools::STRUCT_EXCESSIVE_BOOLS), - LintId::of(&functions::MUST_USE_CANDIDATE), - LintId::of(&functions::TOO_MANY_LINES), - LintId::of(&if_not_else::IF_NOT_ELSE), - LintId::of(&implicit_saturating_sub::IMPLICIT_SATURATING_SUB), - LintId::of(&infinite_iter::MAYBE_INFINITE_ITER), - LintId::of(&items_after_statements::ITEMS_AFTER_STATEMENTS), - LintId::of(&large_stack_arrays::LARGE_STACK_ARRAYS), - LintId::of(&let_underscore::LET_UNDERSCORE_DROP), - LintId::of(&literal_representation::LARGE_DIGIT_GROUPS), - LintId::of(&literal_representation::UNREADABLE_LITERAL), - LintId::of(&loops::EXPLICIT_INTO_ITER_LOOP), - LintId::of(&loops::EXPLICIT_ITER_LOOP), - LintId::of(¯o_use::MACRO_USE_IMPORTS), - LintId::of(&manual_ok_or::MANUAL_OK_OR), - LintId::of(&match_on_vec_items::MATCH_ON_VEC_ITEMS), - LintId::of(&matches::MATCH_BOOL), - LintId::of(&matches::MATCH_SAME_ARMS), - LintId::of(&matches::MATCH_WILDCARD_FOR_SINGLE_VARIANTS), - LintId::of(&matches::MATCH_WILD_ERR_ARM), - LintId::of(&matches::SINGLE_MATCH_ELSE), - LintId::of(&methods::FILTER_MAP), - LintId::of(&methods::FILTER_MAP_NEXT), - LintId::of(&methods::FIND_MAP), - LintId::of(&methods::INEFFICIENT_TO_STRING), - LintId::of(&methods::MAP_FLATTEN), - LintId::of(&methods::MAP_UNWRAP_OR), - LintId::of(&misc::USED_UNDERSCORE_BINDING), - LintId::of(&misc_early::UNSEPARATED_LITERAL_SUFFIX), - LintId::of(&mut_mut::MUT_MUT), - LintId::of(&needless_continue::NEEDLESS_CONTINUE), - LintId::of(&needless_pass_by_value::NEEDLESS_PASS_BY_VALUE), - LintId::of(&non_expressive_names::SIMILAR_NAMES), - LintId::of(&option_if_let_else::OPTION_IF_LET_ELSE), - LintId::of(&pass_by_ref_or_value::LARGE_TYPES_PASSED_BY_VALUE), - LintId::of(&pass_by_ref_or_value::TRIVIALLY_COPY_PASS_BY_REF), - LintId::of(&ranges::RANGE_MINUS_ONE), - LintId::of(&ranges::RANGE_PLUS_ONE), - LintId::of(&redundant_else::REDUNDANT_ELSE), - LintId::of(&ref_option_ref::REF_OPTION_REF), - LintId::of(&shadow::SHADOW_UNRELATED), - LintId::of(&strings::STRING_ADD_ASSIGN), - LintId::of(&trait_bounds::TRAIT_DUPLICATION_IN_BOUNDS), - LintId::of(&trait_bounds::TYPE_REPETITION_IN_BOUNDS), - LintId::of(&types::CAST_LOSSLESS), - LintId::of(&types::CAST_POSSIBLE_TRUNCATION), - LintId::of(&types::CAST_POSSIBLE_WRAP), - LintId::of(&types::CAST_PRECISION_LOSS), - LintId::of(&types::CAST_PTR_ALIGNMENT), - LintId::of(&types::CAST_SIGN_LOSS), - LintId::of(&types::IMPLICIT_HASHER), - LintId::of(&types::INVALID_UPCAST_COMPARISONS), - LintId::of(&types::LET_UNIT_VALUE), - LintId::of(&types::LINKEDLIST), - LintId::of(&types::OPTION_OPTION), - LintId::of(&unicode::NON_ASCII_LITERAL), - LintId::of(&unicode::UNICODE_NOT_NFC), - LintId::of(&unnested_or_patterns::UNNESTED_OR_PATTERNS), - LintId::of(&unused_self::UNUSED_SELF), - LintId::of(&wildcard_imports::ENUM_GLOB_USE), - LintId::of(&wildcard_imports::WILDCARD_IMPORTS), - LintId::of(&zero_sized_map_values::ZERO_SIZED_MAP_VALUES), - ]); - - #[cfg(feature = "internal-lints")] - store.register_group(true, "clippy::internal", Some("clippy_internal"), vec![ - LintId::of(&utils::internal_lints::CLIPPY_LINTS_INTERNAL), - LintId::of(&utils::internal_lints::COLLAPSIBLE_SPAN_LINT_CALLS), - LintId::of(&utils::internal_lints::COMPILER_LINT_FUNCTIONS), - LintId::of(&utils::internal_lints::DEFAULT_LINT), - LintId::of(&utils::internal_lints::INTERNING_DEFINED_SYMBOL), - LintId::of(&utils::internal_lints::INVALID_PATHS), - LintId::of(&utils::internal_lints::LINT_WITHOUT_LINT_PASS), - LintId::of(&utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM), - LintId::of(&utils::internal_lints::OUTER_EXPN_EXPN_DATA), - LintId::of(&utils::internal_lints::PRODUCE_ICE), - ]); - - store.register_group(true, "clippy::all", Some("clippy"), vec![ - LintId::of(&approx_const::APPROX_CONSTANT), - LintId::of(&assertions_on_constants::ASSERTIONS_ON_CONSTANTS), - LintId::of(&assign_ops::ASSIGN_OP_PATTERN), - LintId::of(&assign_ops::MISREFACTORED_ASSIGN_OP), - LintId::of(&async_yields_async::ASYNC_YIELDS_ASYNC), - LintId::of(&atomic_ordering::INVALID_ATOMIC_ORDERING), - LintId::of(&attrs::BLANKET_CLIPPY_RESTRICTION_LINTS), - LintId::of(&attrs::DEPRECATED_CFG_ATTR), - LintId::of(&attrs::DEPRECATED_SEMVER), - LintId::of(&attrs::MISMATCHED_TARGET_OS), - LintId::of(&attrs::UNKNOWN_CLIPPY_LINTS), - LintId::of(&attrs::USELESS_ATTRIBUTE), - LintId::of(&bit_mask::BAD_BIT_MASK), - LintId::of(&bit_mask::INEFFECTIVE_BIT_MASK), - LintId::of(&blacklisted_name::BLACKLISTED_NAME), - LintId::of(&blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS), - LintId::of(&booleans::LOGIC_BUG), - LintId::of(&booleans::NONMINIMAL_BOOL), - LintId::of(&bytecount::NAIVE_BYTECOUNT), - LintId::of(&collapsible_if::COLLAPSIBLE_IF), - LintId::of(&collapsible_match::COLLAPSIBLE_MATCH), - LintId::of(&comparison_chain::COMPARISON_CHAIN), - LintId::of(&copies::IFS_SAME_COND), - LintId::of(&copies::IF_SAME_THEN_ELSE), - LintId::of(&default::FIELD_REASSIGN_WITH_DEFAULT), - LintId::of(&derive::DERIVE_HASH_XOR_EQ), - LintId::of(&derive::DERIVE_ORD_XOR_PARTIAL_ORD), - LintId::of(&doc::MISSING_SAFETY_DOC), - LintId::of(&doc::NEEDLESS_DOCTEST_MAIN), - LintId::of(&double_comparison::DOUBLE_COMPARISONS), - LintId::of(&double_parens::DOUBLE_PARENS), - LintId::of(&drop_forget_ref::DROP_COPY), - LintId::of(&drop_forget_ref::DROP_REF), - LintId::of(&drop_forget_ref::FORGET_COPY), - LintId::of(&drop_forget_ref::FORGET_REF), - LintId::of(&duration_subsec::DURATION_SUBSEC), - LintId::of(&entry::MAP_ENTRY), - LintId::of(&enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT), - LintId::of(&enum_variants::ENUM_VARIANT_NAMES), - LintId::of(&enum_variants::MODULE_INCEPTION), - LintId::of(&eq_op::EQ_OP), - LintId::of(&eq_op::OP_REF), - LintId::of(&erasing_op::ERASING_OP), - LintId::of(&escape::BOXED_LOCAL), - LintId::of(&eta_reduction::REDUNDANT_CLOSURE), - LintId::of(&eval_order_dependence::DIVERGING_SUB_EXPRESSION), - LintId::of(&eval_order_dependence::EVAL_ORDER_DEPENDENCE), - LintId::of(&explicit_write::EXPLICIT_WRITE), - LintId::of(&float_equality_without_abs::FLOAT_EQUALITY_WITHOUT_ABS), - LintId::of(&float_literal::EXCESSIVE_PRECISION), - LintId::of(&format::USELESS_FORMAT), - LintId::of(&formatting::POSSIBLE_MISSING_COMMA), - LintId::of(&formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING), - LintId::of(&formatting::SUSPICIOUS_ELSE_FORMATTING), - LintId::of(&formatting::SUSPICIOUS_UNARY_OP_FORMATTING), - LintId::of(&functions::DOUBLE_MUST_USE), - LintId::of(&functions::MUST_USE_UNIT), - LintId::of(&functions::NOT_UNSAFE_PTR_ARG_DEREF), - LintId::of(&functions::RESULT_UNIT_ERR), - LintId::of(&functions::TOO_MANY_ARGUMENTS), - LintId::of(&get_last_with_len::GET_LAST_WITH_LEN), - LintId::of(&identity_op::IDENTITY_OP), - LintId::of(&if_let_mutex::IF_LET_MUTEX), - LintId::of(&if_let_some_result::IF_LET_SOME_RESULT), - LintId::of(&indexing_slicing::OUT_OF_BOUNDS_INDEXING), - LintId::of(&infinite_iter::INFINITE_ITER), - LintId::of(&inherent_to_string::INHERENT_TO_STRING), - LintId::of(&inherent_to_string::INHERENT_TO_STRING_SHADOW_DISPLAY), - LintId::of(&inline_fn_without_body::INLINE_FN_WITHOUT_BODY), - LintId::of(&int_plus_one::INT_PLUS_ONE), - LintId::of(&large_const_arrays::LARGE_CONST_ARRAYS), - LintId::of(&large_enum_variant::LARGE_ENUM_VARIANT), - LintId::of(&len_zero::COMPARISON_TO_EMPTY), - LintId::of(&len_zero::LEN_WITHOUT_IS_EMPTY), - LintId::of(&len_zero::LEN_ZERO), - LintId::of(&let_underscore::LET_UNDERSCORE_LOCK), - LintId::of(&lifetimes::EXTRA_UNUSED_LIFETIMES), - LintId::of(&lifetimes::NEEDLESS_LIFETIMES), - LintId::of(&literal_representation::INCONSISTENT_DIGIT_GROUPING), - LintId::of(&literal_representation::MISTYPED_LITERAL_SUFFIXES), - LintId::of(&literal_representation::UNUSUAL_BYTE_GROUPINGS), - LintId::of(&loops::EMPTY_LOOP), - LintId::of(&loops::EXPLICIT_COUNTER_LOOP), - LintId::of(&loops::FOR_KV_MAP), - LintId::of(&loops::FOR_LOOPS_OVER_FALLIBLES), - LintId::of(&loops::ITER_NEXT_LOOP), - LintId::of(&loops::MANUAL_MEMCPY), - LintId::of(&loops::MUT_RANGE_BOUND), - LintId::of(&loops::NEEDLESS_COLLECT), - LintId::of(&loops::NEEDLESS_RANGE_LOOP), - LintId::of(&loops::NEVER_LOOP), - LintId::of(&loops::SAME_ITEM_PUSH), - LintId::of(&loops::SINGLE_ELEMENT_LOOP), - LintId::of(&loops::WHILE_IMMUTABLE_CONDITION), - LintId::of(&loops::WHILE_LET_LOOP), - LintId::of(&loops::WHILE_LET_ON_ITERATOR), - LintId::of(&main_recursion::MAIN_RECURSION), - LintId::of(&manual_async_fn::MANUAL_ASYNC_FN), - LintId::of(&manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE), - LintId::of(&manual_strip::MANUAL_STRIP), - LintId::of(&manual_unwrap_or::MANUAL_UNWRAP_OR), - LintId::of(&map_clone::MAP_CLONE), - LintId::of(&map_identity::MAP_IDENTITY), - LintId::of(&map_unit_fn::OPTION_MAP_UNIT_FN), - LintId::of(&map_unit_fn::RESULT_MAP_UNIT_FN), - LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH), - LintId::of(&matches::MATCH_AS_REF), - LintId::of(&matches::MATCH_LIKE_MATCHES_MACRO), - LintId::of(&matches::MATCH_OVERLAPPING_ARM), - LintId::of(&matches::MATCH_REF_PATS), - LintId::of(&matches::MATCH_SINGLE_BINDING), - LintId::of(&matches::REDUNDANT_PATTERN_MATCHING), - LintId::of(&matches::SINGLE_MATCH), - LintId::of(&matches::WILDCARD_IN_OR_PATTERNS), - LintId::of(&mem_discriminant::MEM_DISCRIMINANT_NON_ENUM), - LintId::of(&mem_replace::MEM_REPLACE_OPTION_WITH_NONE), - LintId::of(&mem_replace::MEM_REPLACE_WITH_DEFAULT), - LintId::of(&mem_replace::MEM_REPLACE_WITH_UNINIT), - LintId::of(&methods::BIND_INSTEAD_OF_MAP), - LintId::of(&methods::CHARS_LAST_CMP), - LintId::of(&methods::CHARS_NEXT_CMP), - LintId::of(&methods::CLONE_DOUBLE_REF), - LintId::of(&methods::CLONE_ON_COPY), - LintId::of(&methods::EXPECT_FUN_CALL), - LintId::of(&methods::FILTER_NEXT), - LintId::of(&methods::FLAT_MAP_IDENTITY), - LintId::of(&methods::FROM_ITER_INSTEAD_OF_COLLECT), - LintId::of(&methods::INTO_ITER_ON_REF), - LintId::of(&methods::ITERATOR_STEP_BY_ZERO), - LintId::of(&methods::ITER_CLONED_COLLECT), - LintId::of(&methods::ITER_NEXT_SLICE), - LintId::of(&methods::ITER_NTH), - LintId::of(&methods::ITER_NTH_ZERO), - LintId::of(&methods::ITER_SKIP_NEXT), - LintId::of(&methods::MANUAL_SATURATING_ARITHMETIC), - LintId::of(&methods::MAP_COLLECT_RESULT_UNIT), - LintId::of(&methods::NEW_RET_NO_SELF), - LintId::of(&methods::OK_EXPECT), - LintId::of(&methods::OPTION_AS_REF_DEREF), - LintId::of(&methods::OPTION_MAP_OR_NONE), - LintId::of(&methods::OR_FUN_CALL), - LintId::of(&methods::RESULT_MAP_OR_INTO_OPTION), - LintId::of(&methods::SEARCH_IS_SOME), - LintId::of(&methods::SHOULD_IMPLEMENT_TRAIT), - LintId::of(&methods::SINGLE_CHAR_ADD_STR), - LintId::of(&methods::SINGLE_CHAR_PATTERN), - LintId::of(&methods::SKIP_WHILE_NEXT), - LintId::of(&methods::STRING_EXTEND_CHARS), - LintId::of(&methods::SUSPICIOUS_MAP), - LintId::of(&methods::UNINIT_ASSUMED_INIT), - LintId::of(&methods::UNNECESSARY_FILTER_MAP), - LintId::of(&methods::UNNECESSARY_FOLD), - LintId::of(&methods::UNNECESSARY_LAZY_EVALUATIONS), - LintId::of(&methods::USELESS_ASREF), - LintId::of(&methods::WRONG_SELF_CONVENTION), - LintId::of(&methods::ZST_OFFSET), - LintId::of(&minmax::MIN_MAX), - LintId::of(&misc::CMP_NAN), - LintId::of(&misc::CMP_OWNED), - LintId::of(&misc::FLOAT_CMP), - LintId::of(&misc::MODULO_ONE), - LintId::of(&misc::SHORT_CIRCUIT_STATEMENT), - LintId::of(&misc::TOPLEVEL_REF_ARG), - LintId::of(&misc::ZERO_PTR), - LintId::of(&misc_early::BUILTIN_TYPE_SHADOW), - LintId::of(&misc_early::DOUBLE_NEG), - LintId::of(&misc_early::DUPLICATE_UNDERSCORE_ARGUMENT), - LintId::of(&misc_early::MIXED_CASE_HEX_LITERALS), - LintId::of(&misc_early::REDUNDANT_PATTERN), - LintId::of(&misc_early::UNNEEDED_WILDCARD_PATTERN), - LintId::of(&misc_early::ZERO_PREFIXED_LITERAL), - LintId::of(&mut_key::MUTABLE_KEY_TYPE), - LintId::of(&mut_mutex_lock::MUT_MUTEX_LOCK), - LintId::of(&mut_reference::UNNECESSARY_MUT_PASSED), - LintId::of(&mutex_atomic::MUTEX_ATOMIC), - LintId::of(&needless_arbitrary_self_type::NEEDLESS_ARBITRARY_SELF_TYPE), - LintId::of(&needless_bool::BOOL_COMPARISON), - LintId::of(&needless_bool::NEEDLESS_BOOL), - LintId::of(&needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE), - LintId::of(&needless_update::NEEDLESS_UPDATE), - LintId::of(&neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD), - LintId::of(&neg_multiply::NEG_MULTIPLY), - LintId::of(&new_without_default::NEW_WITHOUT_DEFAULT), - LintId::of(&no_effect::NO_EFFECT), - LintId::of(&no_effect::UNNECESSARY_OPERATION), - LintId::of(&non_copy_const::BORROW_INTERIOR_MUTABLE_CONST), - LintId::of(&non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST), - LintId::of(&non_expressive_names::JUST_UNDERSCORES_AND_DIGITS), - LintId::of(&non_expressive_names::MANY_SINGLE_CHAR_NAMES), - LintId::of(&open_options::NONSENSICAL_OPEN_OPTIONS), - LintId::of(&option_env_unwrap::OPTION_ENV_UNWRAP), - LintId::of(&overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL), - LintId::of(&partialeq_ne_impl::PARTIALEQ_NE_IMPL), - LintId::of(&precedence::PRECEDENCE), - LintId::of(&ptr::CMP_NULL), - LintId::of(&ptr::MUT_FROM_REF), - LintId::of(&ptr::PTR_ARG), - LintId::of(&ptr_eq::PTR_EQ), - LintId::of(&ptr_offset_with_cast::PTR_OFFSET_WITH_CAST), - LintId::of(&question_mark::QUESTION_MARK), - LintId::of(&ranges::MANUAL_RANGE_CONTAINS), - LintId::of(&ranges::RANGE_ZIP_WITH_LEN), - LintId::of(&ranges::REVERSED_EMPTY_RANGES), - LintId::of(&redundant_clone::REDUNDANT_CLONE), - LintId::of(&redundant_closure_call::REDUNDANT_CLOSURE_CALL), - LintId::of(&redundant_field_names::REDUNDANT_FIELD_NAMES), - LintId::of(&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES), - LintId::of(&reference::DEREF_ADDROF), - LintId::of(&reference::REF_IN_DEREF), - LintId::of(®ex::INVALID_REGEX), - LintId::of(®ex::TRIVIAL_REGEX), - LintId::of(&repeat_once::REPEAT_ONCE), - LintId::of(&returns::LET_AND_RETURN), - LintId::of(&returns::NEEDLESS_RETURN), - LintId::of(&self_assignment::SELF_ASSIGNMENT), - LintId::of(&serde_api::SERDE_API_MISUSE), - LintId::of(&single_component_path_imports::SINGLE_COMPONENT_PATH_IMPORTS), - LintId::of(&size_of_in_element_count::SIZE_OF_IN_ELEMENT_COUNT), - LintId::of(&slow_vector_initialization::SLOW_VECTOR_INITIALIZATION), - LintId::of(&stable_sort_primitive::STABLE_SORT_PRIMITIVE), - LintId::of(&strings::STRING_FROM_UTF8_AS_BYTES), - LintId::of(&suspicious_operation_groupings::SUSPICIOUS_OPERATION_GROUPINGS), - LintId::of(&suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL), - LintId::of(&suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL), - LintId::of(&swap::ALMOST_SWAPPED), - LintId::of(&swap::MANUAL_SWAP), - LintId::of(&tabs_in_doc_comments::TABS_IN_DOC_COMMENTS), - LintId::of(&temporary_assignment::TEMPORARY_ASSIGNMENT), - LintId::of(&to_digit_is_some::TO_DIGIT_IS_SOME), - LintId::of(&to_string_in_display::TO_STRING_IN_DISPLAY), - LintId::of(&transmute::CROSSPOINTER_TRANSMUTE), - LintId::of(&transmute::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS), - LintId::of(&transmute::TRANSMUTE_BYTES_TO_STR), - LintId::of(&transmute::TRANSMUTE_FLOAT_TO_INT), - LintId::of(&transmute::TRANSMUTE_INT_TO_BOOL), - LintId::of(&transmute::TRANSMUTE_INT_TO_CHAR), - LintId::of(&transmute::TRANSMUTE_INT_TO_FLOAT), - LintId::of(&transmute::TRANSMUTE_PTR_TO_PTR), - LintId::of(&transmute::TRANSMUTE_PTR_TO_REF), - LintId::of(&transmute::UNSOUND_COLLECTION_TRANSMUTE), - LintId::of(&transmute::WRONG_TRANSMUTE), - LintId::of(&transmuting_null::TRANSMUTING_NULL), - LintId::of(&try_err::TRY_ERR), - LintId::of(&types::ABSURD_EXTREME_COMPARISONS), - LintId::of(&types::BORROWED_BOX), - LintId::of(&types::BOX_VEC), - LintId::of(&types::CAST_REF_TO_MUT), - LintId::of(&types::CHAR_LIT_AS_U8), - LintId::of(&types::FN_TO_NUMERIC_CAST), - LintId::of(&types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION), - LintId::of(&types::REDUNDANT_ALLOCATION), - LintId::of(&types::TYPE_COMPLEXITY), - LintId::of(&types::UNIT_ARG), - LintId::of(&types::UNIT_CMP), - LintId::of(&types::UNNECESSARY_CAST), - LintId::of(&types::VEC_BOX), - LintId::of(&undropped_manually_drops::UNDROPPED_MANUALLY_DROPS), - LintId::of(&unicode::INVISIBLE_CHARACTERS), - LintId::of(&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD), - LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS), - LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS), - LintId::of(&unnecessary_sort_by::UNNECESSARY_SORT_BY), - LintId::of(&unnecessary_wraps::UNNECESSARY_WRAPS), - LintId::of(&unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME), - LintId::of(&unused_io_amount::UNUSED_IO_AMOUNT), - LintId::of(&unused_unit::UNUSED_UNIT), - LintId::of(&unwrap::PANICKING_UNWRAP), - LintId::of(&unwrap::UNNECESSARY_UNWRAP), - LintId::of(&useless_conversion::USELESS_CONVERSION), - LintId::of(&vec::USELESS_VEC), - LintId::of(&vec_resize_to_zero::VEC_RESIZE_TO_ZERO), - LintId::of(&write::PRINTLN_EMPTY_STRING), - LintId::of(&write::PRINT_LITERAL), - LintId::of(&write::PRINT_WITH_NEWLINE), - LintId::of(&write::WRITELN_EMPTY_STRING), - LintId::of(&write::WRITE_LITERAL), - LintId::of(&write::WRITE_WITH_NEWLINE), - LintId::of(&zero_div_zero::ZERO_DIVIDED_BY_ZERO), - ]); - - store.register_group(true, "clippy::style", Some("clippy_style"), vec![ - LintId::of(&assertions_on_constants::ASSERTIONS_ON_CONSTANTS), - LintId::of(&assign_ops::ASSIGN_OP_PATTERN), - LintId::of(&attrs::BLANKET_CLIPPY_RESTRICTION_LINTS), - LintId::of(&attrs::UNKNOWN_CLIPPY_LINTS), - LintId::of(&blacklisted_name::BLACKLISTED_NAME), - LintId::of(&blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS), - LintId::of(&collapsible_if::COLLAPSIBLE_IF), - LintId::of(&collapsible_match::COLLAPSIBLE_MATCH), - LintId::of(&comparison_chain::COMPARISON_CHAIN), - LintId::of(&default::FIELD_REASSIGN_WITH_DEFAULT), - LintId::of(&doc::MISSING_SAFETY_DOC), - LintId::of(&doc::NEEDLESS_DOCTEST_MAIN), - LintId::of(&enum_variants::ENUM_VARIANT_NAMES), - LintId::of(&enum_variants::MODULE_INCEPTION), - LintId::of(&eq_op::OP_REF), - LintId::of(&eta_reduction::REDUNDANT_CLOSURE), - LintId::of(&float_literal::EXCESSIVE_PRECISION), - LintId::of(&formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING), - LintId::of(&formatting::SUSPICIOUS_ELSE_FORMATTING), - LintId::of(&formatting::SUSPICIOUS_UNARY_OP_FORMATTING), - LintId::of(&functions::DOUBLE_MUST_USE), - LintId::of(&functions::MUST_USE_UNIT), - LintId::of(&functions::RESULT_UNIT_ERR), - LintId::of(&if_let_some_result::IF_LET_SOME_RESULT), - LintId::of(&inherent_to_string::INHERENT_TO_STRING), - LintId::of(&len_zero::COMPARISON_TO_EMPTY), - LintId::of(&len_zero::LEN_WITHOUT_IS_EMPTY), - LintId::of(&len_zero::LEN_ZERO), - LintId::of(&literal_representation::INCONSISTENT_DIGIT_GROUPING), - LintId::of(&literal_representation::UNUSUAL_BYTE_GROUPINGS), - LintId::of(&loops::EMPTY_LOOP), - LintId::of(&loops::FOR_KV_MAP), - LintId::of(&loops::NEEDLESS_RANGE_LOOP), - LintId::of(&loops::SAME_ITEM_PUSH), - LintId::of(&loops::WHILE_LET_ON_ITERATOR), - LintId::of(&main_recursion::MAIN_RECURSION), - LintId::of(&manual_async_fn::MANUAL_ASYNC_FN), - LintId::of(&manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE), - LintId::of(&map_clone::MAP_CLONE), - LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH), - LintId::of(&matches::MATCH_LIKE_MATCHES_MACRO), - LintId::of(&matches::MATCH_OVERLAPPING_ARM), - LintId::of(&matches::MATCH_REF_PATS), - LintId::of(&matches::REDUNDANT_PATTERN_MATCHING), - LintId::of(&matches::SINGLE_MATCH), - LintId::of(&mem_replace::MEM_REPLACE_OPTION_WITH_NONE), - LintId::of(&mem_replace::MEM_REPLACE_WITH_DEFAULT), - LintId::of(&methods::CHARS_LAST_CMP), - LintId::of(&methods::CHARS_NEXT_CMP), - LintId::of(&methods::FROM_ITER_INSTEAD_OF_COLLECT), - LintId::of(&methods::INTO_ITER_ON_REF), - LintId::of(&methods::ITER_CLONED_COLLECT), - LintId::of(&methods::ITER_NEXT_SLICE), - LintId::of(&methods::ITER_NTH_ZERO), - LintId::of(&methods::ITER_SKIP_NEXT), - LintId::of(&methods::MANUAL_SATURATING_ARITHMETIC), - LintId::of(&methods::MAP_COLLECT_RESULT_UNIT), - LintId::of(&methods::NEW_RET_NO_SELF), - LintId::of(&methods::OK_EXPECT), - LintId::of(&methods::OPTION_MAP_OR_NONE), - LintId::of(&methods::RESULT_MAP_OR_INTO_OPTION), - LintId::of(&methods::SHOULD_IMPLEMENT_TRAIT), - LintId::of(&methods::SINGLE_CHAR_ADD_STR), - LintId::of(&methods::STRING_EXTEND_CHARS), - LintId::of(&methods::UNNECESSARY_FOLD), - LintId::of(&methods::UNNECESSARY_LAZY_EVALUATIONS), - LintId::of(&methods::WRONG_SELF_CONVENTION), - LintId::of(&misc::TOPLEVEL_REF_ARG), - LintId::of(&misc::ZERO_PTR), - LintId::of(&misc_early::BUILTIN_TYPE_SHADOW), - LintId::of(&misc_early::DOUBLE_NEG), - LintId::of(&misc_early::DUPLICATE_UNDERSCORE_ARGUMENT), - LintId::of(&misc_early::MIXED_CASE_HEX_LITERALS), - LintId::of(&misc_early::REDUNDANT_PATTERN), - LintId::of(&mut_mutex_lock::MUT_MUTEX_LOCK), - LintId::of(&mut_reference::UNNECESSARY_MUT_PASSED), - LintId::of(&neg_multiply::NEG_MULTIPLY), - LintId::of(&new_without_default::NEW_WITHOUT_DEFAULT), - LintId::of(&non_copy_const::BORROW_INTERIOR_MUTABLE_CONST), - LintId::of(&non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST), - LintId::of(&non_expressive_names::JUST_UNDERSCORES_AND_DIGITS), - LintId::of(&non_expressive_names::MANY_SINGLE_CHAR_NAMES), - LintId::of(&ptr::CMP_NULL), - LintId::of(&ptr::PTR_ARG), - LintId::of(&ptr_eq::PTR_EQ), - LintId::of(&question_mark::QUESTION_MARK), - LintId::of(&ranges::MANUAL_RANGE_CONTAINS), - LintId::of(&redundant_field_names::REDUNDANT_FIELD_NAMES), - LintId::of(&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES), - LintId::of(®ex::TRIVIAL_REGEX), - LintId::of(&returns::LET_AND_RETURN), - LintId::of(&returns::NEEDLESS_RETURN), - LintId::of(&single_component_path_imports::SINGLE_COMPONENT_PATH_IMPORTS), - LintId::of(&suspicious_operation_groupings::SUSPICIOUS_OPERATION_GROUPINGS), - LintId::of(&tabs_in_doc_comments::TABS_IN_DOC_COMMENTS), - LintId::of(&to_digit_is_some::TO_DIGIT_IS_SOME), - LintId::of(&try_err::TRY_ERR), - LintId::of(&types::FN_TO_NUMERIC_CAST), - LintId::of(&types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION), - LintId::of(&unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME), - LintId::of(&unused_unit::UNUSED_UNIT), - LintId::of(&write::PRINTLN_EMPTY_STRING), - LintId::of(&write::PRINT_LITERAL), - LintId::of(&write::PRINT_WITH_NEWLINE), - LintId::of(&write::WRITELN_EMPTY_STRING), - LintId::of(&write::WRITE_LITERAL), - LintId::of(&write::WRITE_WITH_NEWLINE), - ]); - - store.register_group(true, "clippy::complexity", Some("clippy_complexity"), vec![ - LintId::of(&assign_ops::MISREFACTORED_ASSIGN_OP), - LintId::of(&attrs::DEPRECATED_CFG_ATTR), - LintId::of(&booleans::NONMINIMAL_BOOL), - LintId::of(&double_comparison::DOUBLE_COMPARISONS), - LintId::of(&double_parens::DOUBLE_PARENS), - LintId::of(&duration_subsec::DURATION_SUBSEC), - LintId::of(&eval_order_dependence::DIVERGING_SUB_EXPRESSION), - LintId::of(&eval_order_dependence::EVAL_ORDER_DEPENDENCE), - LintId::of(&explicit_write::EXPLICIT_WRITE), - LintId::of(&format::USELESS_FORMAT), - LintId::of(&functions::TOO_MANY_ARGUMENTS), - LintId::of(&get_last_with_len::GET_LAST_WITH_LEN), - LintId::of(&identity_op::IDENTITY_OP), - LintId::of(&int_plus_one::INT_PLUS_ONE), - LintId::of(&lifetimes::EXTRA_UNUSED_LIFETIMES), - LintId::of(&lifetimes::NEEDLESS_LIFETIMES), - LintId::of(&loops::EXPLICIT_COUNTER_LOOP), - LintId::of(&loops::MUT_RANGE_BOUND), - LintId::of(&loops::SINGLE_ELEMENT_LOOP), - LintId::of(&loops::WHILE_LET_LOOP), - LintId::of(&manual_strip::MANUAL_STRIP), - LintId::of(&manual_unwrap_or::MANUAL_UNWRAP_OR), - LintId::of(&map_identity::MAP_IDENTITY), - LintId::of(&map_unit_fn::OPTION_MAP_UNIT_FN), - LintId::of(&map_unit_fn::RESULT_MAP_UNIT_FN), - LintId::of(&matches::MATCH_AS_REF), - LintId::of(&matches::MATCH_SINGLE_BINDING), - LintId::of(&matches::WILDCARD_IN_OR_PATTERNS), - LintId::of(&methods::BIND_INSTEAD_OF_MAP), - LintId::of(&methods::CLONE_ON_COPY), - LintId::of(&methods::FILTER_NEXT), - LintId::of(&methods::FLAT_MAP_IDENTITY), - LintId::of(&methods::OPTION_AS_REF_DEREF), - LintId::of(&methods::SEARCH_IS_SOME), - LintId::of(&methods::SKIP_WHILE_NEXT), - LintId::of(&methods::SUSPICIOUS_MAP), - LintId::of(&methods::UNNECESSARY_FILTER_MAP), - LintId::of(&methods::USELESS_ASREF), - LintId::of(&misc::SHORT_CIRCUIT_STATEMENT), - LintId::of(&misc_early::UNNEEDED_WILDCARD_PATTERN), - LintId::of(&misc_early::ZERO_PREFIXED_LITERAL), - LintId::of(&needless_arbitrary_self_type::NEEDLESS_ARBITRARY_SELF_TYPE), - LintId::of(&needless_bool::BOOL_COMPARISON), - LintId::of(&needless_bool::NEEDLESS_BOOL), - LintId::of(&needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE), - LintId::of(&needless_update::NEEDLESS_UPDATE), - LintId::of(&neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD), - LintId::of(&no_effect::NO_EFFECT), - LintId::of(&no_effect::UNNECESSARY_OPERATION), - LintId::of(&overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL), - LintId::of(&partialeq_ne_impl::PARTIALEQ_NE_IMPL), - LintId::of(&precedence::PRECEDENCE), - LintId::of(&ptr_offset_with_cast::PTR_OFFSET_WITH_CAST), - LintId::of(&ranges::RANGE_ZIP_WITH_LEN), - LintId::of(&redundant_closure_call::REDUNDANT_CLOSURE_CALL), - LintId::of(&reference::DEREF_ADDROF), - LintId::of(&reference::REF_IN_DEREF), - LintId::of(&repeat_once::REPEAT_ONCE), - LintId::of(&strings::STRING_FROM_UTF8_AS_BYTES), - LintId::of(&swap::MANUAL_SWAP), - LintId::of(&temporary_assignment::TEMPORARY_ASSIGNMENT), - LintId::of(&transmute::CROSSPOINTER_TRANSMUTE), - LintId::of(&transmute::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS), - LintId::of(&transmute::TRANSMUTE_BYTES_TO_STR), - LintId::of(&transmute::TRANSMUTE_FLOAT_TO_INT), - LintId::of(&transmute::TRANSMUTE_INT_TO_BOOL), - LintId::of(&transmute::TRANSMUTE_INT_TO_CHAR), - LintId::of(&transmute::TRANSMUTE_INT_TO_FLOAT), - LintId::of(&transmute::TRANSMUTE_PTR_TO_PTR), - LintId::of(&transmute::TRANSMUTE_PTR_TO_REF), - LintId::of(&types::BORROWED_BOX), - LintId::of(&types::CHAR_LIT_AS_U8), - LintId::of(&types::TYPE_COMPLEXITY), - LintId::of(&types::UNIT_ARG), - LintId::of(&types::UNNECESSARY_CAST), - LintId::of(&types::VEC_BOX), - LintId::of(&unnecessary_sort_by::UNNECESSARY_SORT_BY), - LintId::of(&unnecessary_wraps::UNNECESSARY_WRAPS), - LintId::of(&unwrap::UNNECESSARY_UNWRAP), - LintId::of(&useless_conversion::USELESS_CONVERSION), - LintId::of(&zero_div_zero::ZERO_DIVIDED_BY_ZERO), - ]); - - store.register_group(true, "clippy::correctness", Some("clippy_correctness"), vec![ - LintId::of(&approx_const::APPROX_CONSTANT), - LintId::of(&async_yields_async::ASYNC_YIELDS_ASYNC), - LintId::of(&atomic_ordering::INVALID_ATOMIC_ORDERING), - LintId::of(&attrs::DEPRECATED_SEMVER), - LintId::of(&attrs::MISMATCHED_TARGET_OS), - LintId::of(&attrs::USELESS_ATTRIBUTE), - LintId::of(&bit_mask::BAD_BIT_MASK), - LintId::of(&bit_mask::INEFFECTIVE_BIT_MASK), - LintId::of(&booleans::LOGIC_BUG), - LintId::of(&copies::IFS_SAME_COND), - LintId::of(&copies::IF_SAME_THEN_ELSE), - LintId::of(&derive::DERIVE_HASH_XOR_EQ), - LintId::of(&derive::DERIVE_ORD_XOR_PARTIAL_ORD), - LintId::of(&drop_forget_ref::DROP_COPY), - LintId::of(&drop_forget_ref::DROP_REF), - LintId::of(&drop_forget_ref::FORGET_COPY), - LintId::of(&drop_forget_ref::FORGET_REF), - LintId::of(&enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT), - LintId::of(&eq_op::EQ_OP), - LintId::of(&erasing_op::ERASING_OP), - LintId::of(&float_equality_without_abs::FLOAT_EQUALITY_WITHOUT_ABS), - LintId::of(&formatting::POSSIBLE_MISSING_COMMA), - LintId::of(&functions::NOT_UNSAFE_PTR_ARG_DEREF), - LintId::of(&if_let_mutex::IF_LET_MUTEX), - LintId::of(&indexing_slicing::OUT_OF_BOUNDS_INDEXING), - LintId::of(&infinite_iter::INFINITE_ITER), - LintId::of(&inherent_to_string::INHERENT_TO_STRING_SHADOW_DISPLAY), - LintId::of(&inline_fn_without_body::INLINE_FN_WITHOUT_BODY), - LintId::of(&let_underscore::LET_UNDERSCORE_LOCK), - LintId::of(&literal_representation::MISTYPED_LITERAL_SUFFIXES), - LintId::of(&loops::FOR_LOOPS_OVER_FALLIBLES), - LintId::of(&loops::ITER_NEXT_LOOP), - LintId::of(&loops::NEVER_LOOP), - LintId::of(&loops::WHILE_IMMUTABLE_CONDITION), - LintId::of(&mem_discriminant::MEM_DISCRIMINANT_NON_ENUM), - LintId::of(&mem_replace::MEM_REPLACE_WITH_UNINIT), - LintId::of(&methods::CLONE_DOUBLE_REF), - LintId::of(&methods::ITERATOR_STEP_BY_ZERO), - LintId::of(&methods::UNINIT_ASSUMED_INIT), - LintId::of(&methods::ZST_OFFSET), - LintId::of(&minmax::MIN_MAX), - LintId::of(&misc::CMP_NAN), - LintId::of(&misc::FLOAT_CMP), - LintId::of(&misc::MODULO_ONE), - LintId::of(&mut_key::MUTABLE_KEY_TYPE), - LintId::of(&open_options::NONSENSICAL_OPEN_OPTIONS), - LintId::of(&option_env_unwrap::OPTION_ENV_UNWRAP), - LintId::of(&ptr::MUT_FROM_REF), - LintId::of(&ranges::REVERSED_EMPTY_RANGES), - LintId::of(®ex::INVALID_REGEX), - LintId::of(&self_assignment::SELF_ASSIGNMENT), - LintId::of(&serde_api::SERDE_API_MISUSE), - LintId::of(&size_of_in_element_count::SIZE_OF_IN_ELEMENT_COUNT), - LintId::of(&suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL), - LintId::of(&suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL), - LintId::of(&swap::ALMOST_SWAPPED), - LintId::of(&to_string_in_display::TO_STRING_IN_DISPLAY), - LintId::of(&transmute::UNSOUND_COLLECTION_TRANSMUTE), - LintId::of(&transmute::WRONG_TRANSMUTE), - LintId::of(&transmuting_null::TRANSMUTING_NULL), - LintId::of(&types::ABSURD_EXTREME_COMPARISONS), - LintId::of(&types::CAST_REF_TO_MUT), - LintId::of(&types::UNIT_CMP), - LintId::of(&undropped_manually_drops::UNDROPPED_MANUALLY_DROPS), - LintId::of(&unicode::INVISIBLE_CHARACTERS), - LintId::of(&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD), - LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS), - LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS), - LintId::of(&unused_io_amount::UNUSED_IO_AMOUNT), - LintId::of(&unwrap::PANICKING_UNWRAP), - LintId::of(&vec_resize_to_zero::VEC_RESIZE_TO_ZERO), - ]); - - store.register_group(true, "clippy::perf", Some("clippy_perf"), vec![ - LintId::of(&bytecount::NAIVE_BYTECOUNT), - LintId::of(&entry::MAP_ENTRY), - LintId::of(&escape::BOXED_LOCAL), - LintId::of(&large_const_arrays::LARGE_CONST_ARRAYS), - LintId::of(&large_enum_variant::LARGE_ENUM_VARIANT), - LintId::of(&loops::MANUAL_MEMCPY), - LintId::of(&loops::NEEDLESS_COLLECT), - LintId::of(&methods::EXPECT_FUN_CALL), - LintId::of(&methods::ITER_NTH), - LintId::of(&methods::OR_FUN_CALL), - LintId::of(&methods::SINGLE_CHAR_PATTERN), - LintId::of(&misc::CMP_OWNED), - LintId::of(&mutex_atomic::MUTEX_ATOMIC), - LintId::of(&redundant_clone::REDUNDANT_CLONE), - LintId::of(&slow_vector_initialization::SLOW_VECTOR_INITIALIZATION), - LintId::of(&stable_sort_primitive::STABLE_SORT_PRIMITIVE), - LintId::of(&types::BOX_VEC), - LintId::of(&types::REDUNDANT_ALLOCATION), - LintId::of(&vec::USELESS_VEC), - ]); - - store.register_group(true, "clippy::cargo", Some("clippy_cargo"), vec![ - LintId::of(&cargo_common_metadata::CARGO_COMMON_METADATA), - LintId::of(&multiple_crate_versions::MULTIPLE_CRATE_VERSIONS), - LintId::of(&wildcard_dependencies::WILDCARD_DEPENDENCIES), - ]); - - store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![ - LintId::of(&attrs::EMPTY_LINE_AFTER_OUTER_ATTR), - LintId::of(&cognitive_complexity::COGNITIVE_COMPLEXITY), - LintId::of(&disallowed_method::DISALLOWED_METHOD), - LintId::of(&fallible_impl_from::FALLIBLE_IMPL_FROM), - LintId::of(&floating_point_arithmetic::IMPRECISE_FLOPS), - LintId::of(&floating_point_arithmetic::SUBOPTIMAL_FLOPS), - LintId::of(&future_not_send::FUTURE_NOT_SEND), - LintId::of(&let_if_seq::USELESS_LET_IF_SEQ), - LintId::of(&missing_const_for_fn::MISSING_CONST_FOR_FN), - LintId::of(&mutable_debug_assertion::DEBUG_ASSERT_WITH_MUT_CALL), - LintId::of(&mutex_atomic::MUTEX_INTEGER), - LintId::of(&needless_borrow::NEEDLESS_BORROW), - LintId::of(&path_buf_push_overwrite::PATH_BUF_PUSH_OVERWRITE), - LintId::of(&redundant_pub_crate::REDUNDANT_PUB_CRATE), - LintId::of(&strings::STRING_LIT_AS_BYTES), - LintId::of(&transmute::USELESS_TRANSMUTE), - LintId::of(&use_self::USE_SELF), - ]); -} - -#[rustfmt::skip] -fn register_removed_non_tool_lints(store: &mut rustc_lint::LintStore) { - store.register_removed( - "should_assert_eq", - "`assert!()` will be more flexible with RFC 2011", - ); - store.register_removed( - "extend_from_slice", - "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice", - ); - store.register_removed( - "range_step_by_zero", - "`iterator.step_by(0)` panics nowadays", - ); - store.register_removed( - "unstable_as_slice", - "`Vec::as_slice` has been stabilized in 1.7", - ); - store.register_removed( - "unstable_as_mut_slice", - "`Vec::as_mut_slice` has been stabilized in 1.7", - ); - store.register_removed( - "misaligned_transmute", - "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr", - ); - store.register_removed( - "assign_ops", - "using compound assignment operators (e.g., `+=`) is harmless", - ); - store.register_removed( - "if_let_redundant_pattern_matching", - "this lint has been changed to redundant_pattern_matching", - ); - store.register_removed( - "unsafe_vector_initialization", - "the replacement suggested by this lint had substantially different behavior", - ); - store.register_removed( - "reverse_range_loop", - "this lint is now included in reversed_empty_ranges", - ); -} - -/// Register renamed lints. -/// -/// Used in `./src/driver.rs`. -pub fn register_renamed(ls: &mut rustc_lint::LintStore) { - ls.register_renamed("clippy::stutter", "clippy::module_name_repetitions"); - ls.register_renamed("clippy::new_without_default_derive", "clippy::new_without_default"); - ls.register_renamed("clippy::cyclomatic_complexity", "clippy::cognitive_complexity"); - ls.register_renamed("clippy::const_static_lifetime", "clippy::redundant_static_lifetimes"); - ls.register_renamed("clippy::option_and_then_some", "clippy::bind_instead_of_map"); - ls.register_renamed("clippy::block_in_if_condition_expr", "clippy::blocks_in_if_conditions"); - ls.register_renamed("clippy::block_in_if_condition_stmt", "clippy::blocks_in_if_conditions"); - ls.register_renamed("clippy::option_map_unwrap_or", "clippy::map_unwrap_or"); - ls.register_renamed("clippy::option_map_unwrap_or_else", "clippy::map_unwrap_or"); - ls.register_renamed("clippy::result_map_unwrap_or_else", "clippy::map_unwrap_or"); - ls.register_renamed("clippy::option_unwrap_used", "clippy::unwrap_used"); - ls.register_renamed("clippy::result_unwrap_used", "clippy::unwrap_used"); - ls.register_renamed("clippy::option_expect_used", "clippy::expect_used"); - ls.register_renamed("clippy::result_expect_used", "clippy::expect_used"); - ls.register_renamed("clippy::for_loop_over_option", "clippy::for_loops_over_fallibles"); - ls.register_renamed("clippy::for_loop_over_result", "clippy::for_loops_over_fallibles"); - ls.register_renamed("clippy::identity_conversion", "clippy::useless_conversion"); - ls.register_renamed("clippy::zero_width_space", "clippy::invisible_characters"); - ls.register_renamed("clippy::single_char_push_str", "clippy::single_char_add_str"); -} - -// only exists to let the dogfood integration test works. -// Don't run clippy as an executable directly -#[allow(dead_code)] -fn main() { - panic!("Please use the cargo-clippy executable"); -} diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs deleted file mode 100644 index 4d737b3f49b0..000000000000 --- a/clippy_lints/src/lifetimes.rs +++ /dev/null @@ -1,512 +0,0 @@ -use crate::utils::paths; -use crate::utils::{get_trait_def_id, in_macro, span_lint, trait_ref_of_method}; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_hir::intravisit::{ - walk_fn_decl, walk_generic_param, walk_generics, walk_item, walk_param_bound, walk_poly_trait_ref, walk_ty, - NestedVisitorMap, Visitor, -}; -use rustc_hir::FnRetTy::Return; -use rustc_hir::{ - BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, ImplItem, - ImplItemKind, Item, ItemKind, Lifetime, LifetimeName, ParamName, PolyTraitRef, TraitBoundModifier, TraitFn, - TraitItem, TraitItemKind, Ty, TyKind, WhereClause, WherePredicate, -}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::symbol::{kw, Symbol}; - -declare_clippy_lint! { - /// **What it does:** Checks for lifetime annotations which can be removed by - /// relying on lifetime elision. - /// - /// **Why is this bad?** The additional lifetimes make the code look more - /// complicated, while there is nothing out of the ordinary going on. Removing - /// them leads to more readable code. - /// - /// **Known problems:** - /// - We bail out if the function has a `where` clause where lifetimes - /// are mentioned due to potenial false positives. - /// - Lifetime bounds such as `impl Foo + 'a` and `T: 'a` must be elided with the - /// placeholder notation `'_` because the fully elided notation leaves the type bound to `'static`. - /// - /// **Example:** - /// ```rust - /// // Bad: unnecessary lifetime annotations - /// fn in_and_out<'a>(x: &'a u8, y: u8) -> &'a u8 { - /// x - /// } - /// - /// // Good - /// fn elided(x: &u8, y: u8) -> &u8 { - /// x - /// } - /// ``` - pub NEEDLESS_LIFETIMES, - complexity, - "using explicit lifetimes for references in function arguments when elision rules \ - would allow omitting them" -} - -declare_clippy_lint! { - /// **What it does:** Checks for lifetimes in generics that are never used - /// anywhere else. - /// - /// **Why is this bad?** The additional lifetimes make the code look more - /// complicated, while there is nothing out of the ordinary going on. Removing - /// them leads to more readable code. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// // Bad: unnecessary lifetimes - /// fn unused_lifetime<'a>(x: u8) { - /// // .. - /// } - /// - /// // Good - /// fn no_lifetime(x: u8) { - /// // ... - /// } - /// ``` - pub EXTRA_UNUSED_LIFETIMES, - complexity, - "unused lifetimes in function definitions" -} - -declare_lint_pass!(Lifetimes => [NEEDLESS_LIFETIMES, EXTRA_UNUSED_LIFETIMES]); - -impl<'tcx> LateLintPass<'tcx> for Lifetimes { - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Fn(ref sig, ref generics, id) = item.kind { - check_fn_inner(cx, &sig.decl, Some(id), generics, item.span, true); - } - } - - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { - if let ImplItemKind::Fn(ref sig, id) = item.kind { - let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id).is_none(); - check_fn_inner( - cx, - &sig.decl, - Some(id), - &item.generics, - item.span, - report_extra_lifetimes, - ); - } - } - - fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { - if let TraitItemKind::Fn(ref sig, ref body) = item.kind { - let body = match *body { - TraitFn::Required(_) => None, - TraitFn::Provided(id) => Some(id), - }; - check_fn_inner(cx, &sig.decl, body, &item.generics, item.span, true); - } - } -} - -/// The lifetime of a &-reference. -#[derive(PartialEq, Eq, Hash, Debug, Clone)] -enum RefLt { - Unnamed, - Static, - Named(Symbol), -} - -fn check_fn_inner<'tcx>( - cx: &LateContext<'tcx>, - decl: &'tcx FnDecl<'_>, - body: Option, - generics: &'tcx Generics<'_>, - span: Span, - report_extra_lifetimes: bool, -) { - if in_macro(span) || has_where_lifetimes(cx, &generics.where_clause) { - return; - } - - let types = generics - .params - .iter() - .filter(|param| matches!(param.kind, GenericParamKind::Type { .. })); - for typ in types { - for bound in typ.bounds { - let mut visitor = RefVisitor::new(cx); - walk_param_bound(&mut visitor, bound); - if visitor.lts.iter().any(|lt| matches!(lt, RefLt::Named(_))) { - return; - } - if let GenericBound::Trait(ref trait_ref, _) = *bound { - let params = &trait_ref - .trait_ref - .path - .segments - .last() - .expect("a path must have at least one segment") - .args; - if let Some(ref params) = *params { - let lifetimes = params.args.iter().filter_map(|arg| match arg { - GenericArg::Lifetime(lt) => Some(lt), - _ => None, - }); - for bound in lifetimes { - if bound.name != LifetimeName::Static && !bound.is_elided() { - return; - } - } - } - } - } - } - if could_use_elision(cx, decl, body, &generics.params) { - span_lint( - cx, - NEEDLESS_LIFETIMES, - span.with_hi(decl.output.span().hi()), - "explicit lifetimes given in parameter types where they could be elided \ - (or replaced with `'_` if needed by type declaration)", - ); - } - if report_extra_lifetimes { - self::report_extra_lifetimes(cx, decl, generics); - } -} - -fn could_use_elision<'tcx>( - cx: &LateContext<'tcx>, - func: &'tcx FnDecl<'_>, - body: Option, - named_generics: &'tcx [GenericParam<'_>], -) -> bool { - // There are two scenarios where elision works: - // * no output references, all input references have different LT - // * output references, exactly one input reference with same LT - // All lifetimes must be unnamed, 'static or defined without bounds on the - // level of the current item. - - // check named LTs - let allowed_lts = allowed_lts_from(named_generics); - - // these will collect all the lifetimes for references in arg/return types - let mut input_visitor = RefVisitor::new(cx); - let mut output_visitor = RefVisitor::new(cx); - - // extract lifetimes in input argument types - for arg in func.inputs { - input_visitor.visit_ty(arg); - } - // extract lifetimes in output type - if let Return(ref ty) = func.output { - output_visitor.visit_ty(ty); - } - for lt in named_generics { - input_visitor.visit_generic_param(lt) - } - - if input_visitor.abort() || output_visitor.abort() { - return false; - } - - if allowed_lts - .intersection( - &input_visitor - .nested_elision_site_lts - .iter() - .chain(output_visitor.nested_elision_site_lts.iter()) - .cloned() - .filter(|v| matches!(v, RefLt::Named(_))) - .collect(), - ) - .next() - .is_some() - { - return false; - } - - let input_lts = input_visitor.lts; - let output_lts = output_visitor.lts; - - if let Some(body_id) = body { - let mut checker = BodyLifetimeChecker { - lifetimes_used_in_body: false, - }; - checker.visit_expr(&cx.tcx.hir().body(body_id).value); - if checker.lifetimes_used_in_body { - return false; - } - } - - // check for lifetimes from higher scopes - for lt in input_lts.iter().chain(output_lts.iter()) { - if !allowed_lts.contains(lt) { - return false; - } - } - - // no input lifetimes? easy case! - if input_lts.is_empty() { - false - } else if output_lts.is_empty() { - // no output lifetimes, check distinctness of input lifetimes - - // only unnamed and static, ok - let unnamed_and_static = input_lts.iter().all(|lt| *lt == RefLt::Unnamed || *lt == RefLt::Static); - if unnamed_and_static { - return false; - } - // we have no output reference, so we only need all distinct lifetimes - input_lts.len() == unique_lifetimes(&input_lts) - } else { - // we have output references, so we need one input reference, - // and all output lifetimes must be the same - if unique_lifetimes(&output_lts) > 1 { - return false; - } - if input_lts.len() == 1 { - match (&input_lts[0], &output_lts[0]) { - (&RefLt::Named(n1), &RefLt::Named(n2)) if n1 == n2 => true, - (&RefLt::Named(_), &RefLt::Unnamed) => true, - _ => false, /* already elided, different named lifetimes - * or something static going on */ - } - } else { - false - } - } -} - -fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxHashSet { - let mut allowed_lts = FxHashSet::default(); - for par in named_generics.iter() { - if let GenericParamKind::Lifetime { .. } = par.kind { - if par.bounds.is_empty() { - allowed_lts.insert(RefLt::Named(par.name.ident().name)); - } - } - } - allowed_lts.insert(RefLt::Unnamed); - allowed_lts.insert(RefLt::Static); - allowed_lts -} - -/// Number of unique lifetimes in the given vector. -#[must_use] -fn unique_lifetimes(lts: &[RefLt]) -> usize { - lts.iter().collect::>().len() -} - -const CLOSURE_TRAIT_BOUNDS: [&[&str]; 3] = [&paths::FN, &paths::FN_MUT, &paths::FN_ONCE]; - -/// A visitor usable for `rustc_front::visit::walk_ty()`. -struct RefVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - lts: Vec, - nested_elision_site_lts: Vec, - unelided_trait_object_lifetime: bool, -} - -impl<'a, 'tcx> RefVisitor<'a, 'tcx> { - fn new(cx: &'a LateContext<'tcx>) -> Self { - Self { - cx, - lts: Vec::new(), - nested_elision_site_lts: Vec::new(), - unelided_trait_object_lifetime: false, - } - } - - fn record(&mut self, lifetime: &Option) { - if let Some(ref lt) = *lifetime { - if lt.name == LifetimeName::Static { - self.lts.push(RefLt::Static); - } else if let LifetimeName::Param(ParamName::Fresh(_)) = lt.name { - // Fresh lifetimes generated should be ignored. - } else if lt.is_elided() { - self.lts.push(RefLt::Unnamed); - } else { - self.lts.push(RefLt::Named(lt.name.ident().name)); - } - } else { - self.lts.push(RefLt::Unnamed); - } - } - - fn all_lts(&self) -> Vec { - self.lts - .iter() - .chain(self.nested_elision_site_lts.iter()) - .cloned() - .collect::>() - } - - fn abort(&self) -> bool { - self.unelided_trait_object_lifetime - } -} - -impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - // for lifetimes as parameters of generics - fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { - self.record(&Some(*lifetime)); - } - - fn visit_poly_trait_ref(&mut self, poly_tref: &'tcx PolyTraitRef<'tcx>, tbm: TraitBoundModifier) { - let trait_ref = &poly_tref.trait_ref; - if CLOSURE_TRAIT_BOUNDS - .iter() - .any(|trait_path| trait_ref.trait_def_id() == get_trait_def_id(self.cx, trait_path)) - { - let mut sub_visitor = RefVisitor::new(self.cx); - sub_visitor.visit_trait_ref(trait_ref); - self.nested_elision_site_lts.append(&mut sub_visitor.all_lts()); - } else { - walk_poly_trait_ref(self, poly_tref, tbm); - } - } - - fn visit_ty(&mut self, ty: &'tcx Ty<'_>) { - match ty.kind { - TyKind::OpaqueDef(item, _) => { - let map = self.cx.tcx.hir(); - let item = map.expect_item(item.id); - walk_item(self, item); - walk_ty(self, ty); - }, - TyKind::BareFn(&BareFnTy { decl, .. }) => { - let mut sub_visitor = RefVisitor::new(self.cx); - sub_visitor.visit_fn_decl(decl); - self.nested_elision_site_lts.append(&mut sub_visitor.all_lts()); - return; - }, - TyKind::TraitObject(bounds, ref lt) => { - if !lt.is_elided() { - self.unelided_trait_object_lifetime = true; - } - for bound in bounds { - self.visit_poly_trait_ref(bound, TraitBoundModifier::None); - } - return; - }, - _ => (), - } - walk_ty(self, ty); - } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -/// Are any lifetimes mentioned in the `where` clause? If so, we don't try to -/// reason about elision. -fn has_where_lifetimes<'tcx>(cx: &LateContext<'tcx>, where_clause: &'tcx WhereClause<'_>) -> bool { - for predicate in where_clause.predicates { - match *predicate { - WherePredicate::RegionPredicate(..) => return true, - WherePredicate::BoundPredicate(ref pred) => { - // a predicate like F: Trait or F: for<'a> Trait<'a> - let mut visitor = RefVisitor::new(cx); - // walk the type F, it may not contain LT refs - walk_ty(&mut visitor, &pred.bounded_ty); - if !visitor.all_lts().is_empty() { - return true; - } - // if the bounds define new lifetimes, they are fine to occur - let allowed_lts = allowed_lts_from(&pred.bound_generic_params); - // now walk the bounds - for bound in pred.bounds.iter() { - walk_param_bound(&mut visitor, bound); - } - // and check that all lifetimes are allowed - if visitor.all_lts().iter().any(|it| !allowed_lts.contains(it)) { - return true; - } - }, - WherePredicate::EqPredicate(ref pred) => { - let mut visitor = RefVisitor::new(cx); - walk_ty(&mut visitor, &pred.lhs_ty); - walk_ty(&mut visitor, &pred.rhs_ty); - if !visitor.lts.is_empty() { - return true; - } - }, - } - } - false -} - -struct LifetimeChecker { - map: FxHashMap, -} - -impl<'tcx> Visitor<'tcx> for LifetimeChecker { - type Map = Map<'tcx>; - - // for lifetimes as parameters of generics - fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { - self.map.remove(&lifetime.name.ident().name); - } - - fn visit_generic_param(&mut self, param: &'tcx GenericParam<'_>) { - // don't actually visit `<'a>` or `<'a: 'b>` - // we've already visited the `'a` declarations and - // don't want to spuriously remove them - // `'b` in `'a: 'b` is useless unless used elsewhere in - // a non-lifetime bound - if let GenericParamKind::Type { .. } = param.kind { - walk_generic_param(self, param) - } - } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -fn report_extra_lifetimes<'tcx>(cx: &LateContext<'tcx>, func: &'tcx FnDecl<'_>, generics: &'tcx Generics<'_>) { - let hs = generics - .params - .iter() - .filter_map(|par| match par.kind { - GenericParamKind::Lifetime { .. } => Some((par.name.ident().name, par.span)), - _ => None, - }) - .collect(); - let mut checker = LifetimeChecker { map: hs }; - - walk_generics(&mut checker, generics); - walk_fn_decl(&mut checker, func); - - for &v in checker.map.values() { - span_lint( - cx, - EXTRA_UNUSED_LIFETIMES, - v, - "this lifetime isn't used in the function definition", - ); - } -} - -struct BodyLifetimeChecker { - lifetimes_used_in_body: bool, -} - -impl<'tcx> Visitor<'tcx> for BodyLifetimeChecker { - type Map = Map<'tcx>; - - // for lifetimes as parameters of generics - fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { - if lifetime.name.ident().name != kw::Invalid && lifetime.name.ident().name != kw::StaticLifetime { - self.lifetimes_used_in_body = true; - } - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs deleted file mode 100644 index 87a957a9bd24..000000000000 --- a/clippy_lints/src/literal_representation.rs +++ /dev/null @@ -1,497 +0,0 @@ -//! Lints concerned with the grouping of digits with underscores in integral or -//! floating-point literal expressions. - -use crate::utils::{ - in_macro, - numeric_literal::{NumericLiteral, Radix}, - snippet_opt, span_lint_and_sugg, -}; -use if_chain::if_chain; -use rustc_ast::ast::{Expr, ExprKind, Lit, LitKind}; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_session::{declare_tool_lint, impl_lint_pass}; - -declare_clippy_lint! { - /// **What it does:** Warns if a long integral or floating-point constant does - /// not contain underscores. - /// - /// **Why is this bad?** Reading long numbers is difficult without separators. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// // Bad - /// let x: u64 = 61864918973511; - /// - /// // Good - /// let x: u64 = 61_864_918_973_511; - /// ``` - pub UNREADABLE_LITERAL, - pedantic, - "long literal without underscores" -} - -declare_clippy_lint! { - /// **What it does:** Warns for mistyped suffix in literals - /// - /// **Why is this bad?** This is most probably a typo - /// - /// **Known problems:** - /// - Recommends a signed suffix, even though the number might be too big and an unsigned - /// suffix is required - /// - Does not match on `_127` since that is a valid grouping for decimal and octal numbers - /// - /// **Example:** - /// - /// ```rust - /// // Probably mistyped - /// 2_32; - /// - /// // Good - /// 2_i32; - /// ``` - pub MISTYPED_LITERAL_SUFFIXES, - correctness, - "mistyped literal suffix" -} - -declare_clippy_lint! { - /// **What it does:** Warns if an integral or floating-point constant is - /// grouped inconsistently with underscores. - /// - /// **Why is this bad?** Readers may incorrectly interpret inconsistently - /// grouped digits. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// // Bad - /// let x: u64 = 618_64_9189_73_511; - /// - /// // Good - /// let x: u64 = 61_864_918_973_511; - /// ``` - pub INCONSISTENT_DIGIT_GROUPING, - style, - "integer literals with digits grouped inconsistently" -} - -declare_clippy_lint! { - /// **What it does:** Warns if hexadecimal or binary literals are not grouped - /// by nibble or byte. - /// - /// **Why is this bad?** Negatively impacts readability. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// let x: u32 = 0xFFF_FFF; - /// let y: u8 = 0b01_011_101; - /// ``` - pub UNUSUAL_BYTE_GROUPINGS, - style, - "binary or hex literals that aren't grouped by four" -} - -declare_clippy_lint! { - /// **What it does:** Warns if the digits of an integral or floating-point - /// constant are grouped into groups that - /// are too large. - /// - /// **Why is this bad?** Negatively impacts readability. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// let x: u64 = 6186491_8973511; - /// ``` - pub LARGE_DIGIT_GROUPS, - pedantic, - "grouping digits into groups that are too large" -} - -declare_clippy_lint! { - /// **What it does:** Warns if there is a better representation for a numeric literal. - /// - /// **Why is this bad?** Especially for big powers of 2 a hexadecimal representation is more - /// readable than a decimal representation. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// `255` => `0xFF` - /// `65_535` => `0xFFFF` - /// `4_042_322_160` => `0xF0F0_F0F0` - pub DECIMAL_LITERAL_REPRESENTATION, - restriction, - "using decimal representation when hexadecimal would be better" -} - -enum WarningType { - UnreadableLiteral, - InconsistentDigitGrouping, - LargeDigitGroups, - DecimalRepresentation, - MistypedLiteralSuffix, - UnusualByteGroupings, -} - -impl WarningType { - fn display(&self, suggested_format: String, cx: &EarlyContext<'_>, span: rustc_span::Span) { - match self { - Self::MistypedLiteralSuffix => span_lint_and_sugg( - cx, - MISTYPED_LITERAL_SUFFIXES, - span, - "mistyped literal suffix", - "did you mean to write", - suggested_format, - Applicability::MaybeIncorrect, - ), - Self::UnreadableLiteral => span_lint_and_sugg( - cx, - UNREADABLE_LITERAL, - span, - "long literal lacking separators", - "consider", - suggested_format, - Applicability::MachineApplicable, - ), - Self::LargeDigitGroups => span_lint_and_sugg( - cx, - LARGE_DIGIT_GROUPS, - span, - "digit groups should be smaller", - "consider", - suggested_format, - Applicability::MachineApplicable, - ), - Self::InconsistentDigitGrouping => span_lint_and_sugg( - cx, - INCONSISTENT_DIGIT_GROUPING, - span, - "digits grouped inconsistently by underscores", - "consider", - suggested_format, - Applicability::MachineApplicable, - ), - Self::DecimalRepresentation => span_lint_and_sugg( - cx, - DECIMAL_LITERAL_REPRESENTATION, - span, - "integer literal has a better hexadecimal representation", - "consider", - suggested_format, - Applicability::MachineApplicable, - ), - Self::UnusualByteGroupings => span_lint_and_sugg( - cx, - UNUSUAL_BYTE_GROUPINGS, - span, - "digits of hex or binary literal not grouped by four", - "consider", - suggested_format, - Applicability::MachineApplicable, - ), - }; - } -} - -#[allow(clippy::module_name_repetitions)] -#[derive(Copy, Clone)] -pub struct LiteralDigitGrouping { - lint_fraction_readability: bool, -} - -impl_lint_pass!(LiteralDigitGrouping => [ - UNREADABLE_LITERAL, - INCONSISTENT_DIGIT_GROUPING, - LARGE_DIGIT_GROUPS, - MISTYPED_LITERAL_SUFFIXES, - UNUSUAL_BYTE_GROUPINGS, -]); - -impl EarlyLintPass for LiteralDigitGrouping { - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - if in_external_macro(cx.sess(), expr.span) { - return; - } - - if let ExprKind::Lit(ref lit) = expr.kind { - self.check_lit(cx, lit) - } - } -} - -// Length of each UUID hyphenated group in hex digits. -const UUID_GROUP_LENS: [usize; 5] = [8, 4, 4, 4, 12]; - -impl LiteralDigitGrouping { - pub fn new(lint_fraction_readability: bool) -> Self { - Self { - lint_fraction_readability, - } - } - - fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) { - if_chain! { - if let Some(src) = snippet_opt(cx, lit.span); - if let Some(mut num_lit) = NumericLiteral::from_lit(&src, &lit); - then { - if !Self::check_for_mistyped_suffix(cx, lit.span, &mut num_lit) { - return; - } - - if Self::is_literal_uuid_formatted(&mut num_lit) { - return; - } - - let result = (|| { - - let integral_group_size = Self::get_group_size(num_lit.integer.split('_'), num_lit.radix, true)?; - if let Some(fraction) = num_lit.fraction { - let fractional_group_size = Self::get_group_size( - fraction.rsplit('_'), - num_lit.radix, - self.lint_fraction_readability)?; - - let consistent = Self::parts_consistent(integral_group_size, - fractional_group_size, - num_lit.integer.len(), - fraction.len()); - if !consistent { - return Err(WarningType::InconsistentDigitGrouping); - }; - } - - Ok(()) - })(); - - - if let Err(warning_type) = result { - let should_warn = match warning_type { - | WarningType::UnreadableLiteral - | WarningType::InconsistentDigitGrouping - | WarningType::UnusualByteGroupings - | WarningType::LargeDigitGroups => { - !in_macro(lit.span) - } - WarningType::DecimalRepresentation | WarningType::MistypedLiteralSuffix => { - true - } - }; - if should_warn { - warning_type.display(num_lit.format(), cx, lit.span) - } - } - } - } - } - - // Returns `false` if the check fails - fn check_for_mistyped_suffix( - cx: &EarlyContext<'_>, - span: rustc_span::Span, - num_lit: &mut NumericLiteral<'_>, - ) -> bool { - if num_lit.suffix.is_some() { - return true; - } - - let (part, mistyped_suffixes, missing_char) = if let Some((_, exponent)) = &mut num_lit.exponent { - (exponent, &["32", "64"][..], 'f') - } else if num_lit.fraction.is_some() { - (&mut num_lit.integer, &["32", "64"][..], 'f') - } else { - (&mut num_lit.integer, &["8", "16", "32", "64"][..], 'i') - }; - - let mut split = part.rsplit('_'); - let last_group = split.next().expect("At least one group"); - if split.next().is_some() && mistyped_suffixes.contains(&last_group) { - *part = &part[..part.len() - last_group.len()]; - let mut sugg = num_lit.format(); - sugg.push('_'); - sugg.push(missing_char); - sugg.push_str(last_group); - WarningType::MistypedLiteralSuffix.display(sugg, cx, span); - false - } else { - true - } - } - - /// Checks whether the numeric literal matches the formatting of a UUID. - /// - /// Returns `true` if the radix is hexadecimal, and the groups match the - /// UUID format of 8-4-4-4-12. - fn is_literal_uuid_formatted(num_lit: &mut NumericLiteral<'_>) -> bool { - if num_lit.radix != Radix::Hexadecimal { - return false; - } - - // UUIDs should not have a fraction - if num_lit.fraction.is_some() { - return false; - } - - let group_sizes: Vec = num_lit.integer.split('_').map(str::len).collect(); - if UUID_GROUP_LENS.len() == group_sizes.len() { - UUID_GROUP_LENS.iter().zip(&group_sizes).all(|(&a, &b)| a == b) - } else { - false - } - } - - /// Given the sizes of the digit groups of both integral and fractional - /// parts, and the length - /// of both parts, determine if the digits have been grouped consistently. - #[must_use] - fn parts_consistent( - int_group_size: Option, - frac_group_size: Option, - int_size: usize, - frac_size: usize, - ) -> bool { - match (int_group_size, frac_group_size) { - // No groups on either side of decimal point - trivially consistent. - (None, None) => true, - // Integral part has grouped digits, fractional part does not. - (Some(int_group_size), None) => frac_size <= int_group_size, - // Fractional part has grouped digits, integral part does not. - (None, Some(frac_group_size)) => int_size <= frac_group_size, - // Both parts have grouped digits. Groups should be the same size. - (Some(int_group_size), Some(frac_group_size)) => int_group_size == frac_group_size, - } - } - - /// Returns the size of the digit groups (or None if ungrouped) if successful, - /// otherwise returns a `WarningType` for linting. - fn get_group_size<'a>( - groups: impl Iterator, - radix: Radix, - lint_unreadable: bool, - ) -> Result, WarningType> { - let mut groups = groups.map(str::len); - - let first = groups.next().expect("At least one group"); - - if (radix == Radix::Binary || radix == Radix::Hexadecimal) && groups.any(|i| i != 4 && i != 2) { - return Err(WarningType::UnusualByteGroupings); - } - - if let Some(second) = groups.next() { - if !groups.all(|x| x == second) || first > second { - Err(WarningType::InconsistentDigitGrouping) - } else if second > 4 { - Err(WarningType::LargeDigitGroups) - } else { - Ok(Some(second)) - } - } else if first > 5 && lint_unreadable { - Err(WarningType::UnreadableLiteral) - } else { - Ok(None) - } - } -} - -#[allow(clippy::module_name_repetitions)] -#[derive(Copy, Clone)] -pub struct DecimalLiteralRepresentation { - threshold: u64, -} - -impl_lint_pass!(DecimalLiteralRepresentation => [DECIMAL_LITERAL_REPRESENTATION]); - -impl EarlyLintPass for DecimalLiteralRepresentation { - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - if in_external_macro(cx.sess(), expr.span) { - return; - } - - if let ExprKind::Lit(ref lit) = expr.kind { - self.check_lit(cx, lit) - } - } -} - -impl DecimalLiteralRepresentation { - #[must_use] - pub fn new(threshold: u64) -> Self { - Self { threshold } - } - fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) { - // Lint integral literals. - if_chain! { - if let LitKind::Int(val, _) = lit.kind; - if let Some(src) = snippet_opt(cx, lit.span); - if let Some(num_lit) = NumericLiteral::from_lit(&src, &lit); - if num_lit.radix == Radix::Decimal; - if val >= u128::from(self.threshold); - then { - let hex = format!("{:#X}", val); - let num_lit = NumericLiteral::new(&hex, num_lit.suffix, false); - let _ = Self::do_lint(num_lit.integer).map_err(|warning_type| { - warning_type.display(num_lit.format(), cx, lit.span) - }); - } - } - } - - fn do_lint(digits: &str) -> Result<(), WarningType> { - if digits.len() == 1 { - // Lint for 1 digit literals, if someone really sets the threshold that low - if digits == "1" - || digits == "2" - || digits == "4" - || digits == "8" - || digits == "3" - || digits == "7" - || digits == "F" - { - return Err(WarningType::DecimalRepresentation); - } - } else if digits.len() < 4 { - // Lint for Literals with a hex-representation of 2 or 3 digits - let f = &digits[0..1]; // first digit - let s = &digits[1..]; // suffix - - // Powers of 2 - if ((f.eq("1") || f.eq("2") || f.eq("4") || f.eq("8")) && s.chars().all(|c| c == '0')) - // Powers of 2 minus 1 - || ((f.eq("1") || f.eq("3") || f.eq("7") || f.eq("F")) && s.chars().all(|c| c == 'F')) - { - return Err(WarningType::DecimalRepresentation); - } - } else { - // Lint for Literals with a hex-representation of 4 digits or more - let f = &digits[0..1]; // first digit - let m = &digits[1..digits.len() - 1]; // middle digits, except last - let s = &digits[1..]; // suffix - - // Powers of 2 with a margin of +15/-16 - if ((f.eq("1") || f.eq("2") || f.eq("4") || f.eq("8")) && m.chars().all(|c| c == '0')) - || ((f.eq("1") || f.eq("3") || f.eq("7") || f.eq("F")) && m.chars().all(|c| c == 'F')) - // Lint for representations with only 0s and Fs, while allowing 7 as the first - // digit - || ((f.eq("7") || f.eq("F")) && s.chars().all(|c| c == '0' || c == 'F')) - { - return Err(WarningType::DecimalRepresentation); - } - } - - Ok(()) - } -} diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs deleted file mode 100644 index 1bd96b2b4c89..000000000000 --- a/clippy_lints/src/loops.rs +++ /dev/null @@ -1,3120 +0,0 @@ -use crate::consts::constant; -use crate::utils::paths; -use crate::utils::sugg::Sugg; -use crate::utils::usage::{is_unused, mutated_variables}; -use crate::utils::visitors::LocalUsedVisitor; -use crate::utils::{ - contains_name, get_enclosing_block, get_parent_expr, get_trait_def_id, has_iter_method, higher, implements_trait, - indent_of, is_in_panic_handler, is_integer_const, is_no_std_crate, is_refutable, is_type_diagnostic_item, - last_path_segment, match_trait_method, match_type, match_var, multispan_sugg, qpath_res, single_segment_path, - snippet, snippet_with_applicability, snippet_with_macro_callsite, span_lint, span_lint_and_help, - span_lint_and_sugg, span_lint_and_then, sugg, SpanlessEq, -}; -use if_chain::if_chain; -use rustc_ast::ast; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_errors::Applicability; -use rustc_hir::def::{DefKind, Res}; -use rustc_hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor}; -use rustc_hir::{ - def_id, BinOpKind, BindingAnnotation, Block, BorrowKind, Expr, ExprKind, GenericArg, HirId, InlineAsmOperand, - Local, LoopSource, MatchSource, Mutability, Node, Pat, PatKind, QPath, Stmt, StmtKind, -}; -use rustc_infer::infer::TyCtxtInferExt; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; -use rustc_middle::lint::in_external_macro; -use rustc_middle::middle::region; -use rustc_middle::ty::{self, Ty, TyS}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::symbol::{sym, Ident, Symbol}; -use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; -use std::iter::{once, Iterator}; -use std::mem; - -declare_clippy_lint! { - /// **What it does:** Checks for for-loops that manually copy items between - /// slices that could be optimized by having a memcpy. - /// - /// **Why is this bad?** It is not as fast as a memcpy. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let src = vec![1]; - /// # let mut dst = vec![0; 65]; - /// for i in 0..src.len() { - /// dst[i + 64] = src[i]; - /// } - /// ``` - /// Could be written as: - /// ```rust - /// # let src = vec![1]; - /// # let mut dst = vec![0; 65]; - /// dst[64..(src.len() + 64)].clone_from_slice(&src[..]); - /// ``` - pub MANUAL_MEMCPY, - perf, - "manually copying items between slices" -} - -declare_clippy_lint! { - /// **What it does:** Checks for looping over the range of `0..len` of some - /// collection just to get the values by index. - /// - /// **Why is this bad?** Just iterating the collection itself makes the intent - /// more clear and is probably faster. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let vec = vec!['a', 'b', 'c']; - /// for i in 0..vec.len() { - /// println!("{}", vec[i]); - /// } - /// ``` - /// Could be written as: - /// ```rust - /// let vec = vec!['a', 'b', 'c']; - /// for i in vec { - /// println!("{}", i); - /// } - /// ``` - pub NEEDLESS_RANGE_LOOP, - style, - "for-looping over a range of indices where an iterator over items would do" -} - -declare_clippy_lint! { - /// **What it does:** Checks for loops on `x.iter()` where `&x` will do, and - /// suggests the latter. - /// - /// **Why is this bad?** Readability. - /// - /// **Known problems:** False negatives. We currently only warn on some known - /// types. - /// - /// **Example:** - /// ```rust - /// // with `y` a `Vec` or slice: - /// # let y = vec![1]; - /// for x in y.iter() { - /// // .. - /// } - /// ``` - /// can be rewritten to - /// ```rust - /// # let y = vec![1]; - /// for x in &y { - /// // .. - /// } - /// ``` - pub EXPLICIT_ITER_LOOP, - pedantic, - "for-looping over `_.iter()` or `_.iter_mut()` when `&_` or `&mut _` would do" -} - -declare_clippy_lint! { - /// **What it does:** Checks for loops on `y.into_iter()` where `y` will do, and - /// suggests the latter. - /// - /// **Why is this bad?** Readability. - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```rust - /// # let y = vec![1]; - /// // with `y` a `Vec` or slice: - /// for x in y.into_iter() { - /// // .. - /// } - /// ``` - /// can be rewritten to - /// ```rust - /// # let y = vec![1]; - /// for x in y { - /// // .. - /// } - /// ``` - pub EXPLICIT_INTO_ITER_LOOP, - pedantic, - "for-looping over `_.into_iter()` when `_` would do" -} - -declare_clippy_lint! { - /// **What it does:** Checks for loops on `x.next()`. - /// - /// **Why is this bad?** `next()` returns either `Some(value)` if there was a - /// value, or `None` otherwise. The insidious thing is that `Option<_>` - /// implements `IntoIterator`, so that possibly one value will be iterated, - /// leading to some hard to find bugs. No one will want to write such code - /// [except to win an Underhanded Rust - /// Contest](https://www.reddit.com/r/rust/comments/3hb0wm/underhanded_rust_contest/cu5yuhr). - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// for x in y.next() { - /// .. - /// } - /// ``` - pub ITER_NEXT_LOOP, - correctness, - "for-looping over `_.next()` which is probably not intended" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `for` loops over `Option` or `Result` values. - /// - /// **Why is this bad?** Readability. This is more clearly expressed as an `if - /// let`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let opt = Some(1); - /// - /// // Bad - /// for x in opt { - /// // .. - /// } - /// - /// // Good - /// if let Some(x) = opt { - /// // .. - /// } - /// ``` - /// - /// // or - /// - /// ```rust - /// # let res: Result = Ok(1); - /// - /// // Bad - /// for x in &res { - /// // .. - /// } - /// - /// // Good - /// if let Ok(x) = res { - /// // .. - /// } - /// ``` - pub FOR_LOOPS_OVER_FALLIBLES, - correctness, - "for-looping over an `Option` or a `Result`, which is more clearly expressed as an `if let`" -} - -declare_clippy_lint! { - /// **What it does:** Detects `loop + match` combinations that are easier - /// written as a `while let` loop. - /// - /// **Why is this bad?** The `while let` loop is usually shorter and more - /// readable. - /// - /// **Known problems:** Sometimes the wrong binding is displayed (#383). - /// - /// **Example:** - /// ```rust,no_run - /// # let y = Some(1); - /// loop { - /// let x = match y { - /// Some(x) => x, - /// None => break, - /// }; - /// // .. do something with x - /// } - /// // is easier written as - /// while let Some(x) = y { - /// // .. do something with x - /// }; - /// ``` - pub WHILE_LET_LOOP, - complexity, - "`loop { if let { ... } else break }`, which can be written as a `while let` loop" -} - -declare_clippy_lint! { - /// **What it does:** Checks for functions collecting an iterator when collect - /// is not needed. - /// - /// **Why is this bad?** `collect` causes the allocation of a new data structure, - /// when this allocation may not be needed. - /// - /// **Known problems:** - /// None - /// - /// **Example:** - /// ```rust - /// # let iterator = vec![1].into_iter(); - /// let len = iterator.clone().collect::>().len(); - /// // should be - /// let len = iterator.count(); - /// ``` - pub NEEDLESS_COLLECT, - perf, - "collecting an iterator when collect is not needed" -} - -declare_clippy_lint! { - /// **What it does:** Checks `for` loops over slices with an explicit counter - /// and suggests the use of `.enumerate()`. - /// - /// **Why is it bad?** Using `.enumerate()` makes the intent more clear, - /// declutters the code and may be faster in some instances. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let v = vec![1]; - /// # fn bar(bar: usize, baz: usize) {} - /// let mut i = 0; - /// for item in &v { - /// bar(i, *item); - /// i += 1; - /// } - /// ``` - /// Could be written as - /// ```rust - /// # let v = vec![1]; - /// # fn bar(bar: usize, baz: usize) {} - /// for (i, item) in v.iter().enumerate() { bar(i, *item); } - /// ``` - pub EXPLICIT_COUNTER_LOOP, - complexity, - "for-looping with an explicit counter when `_.enumerate()` would do" -} - -declare_clippy_lint! { - /// **What it does:** Checks for empty `loop` expressions. - /// - /// **Why is this bad?** These busy loops burn CPU cycles without doing - /// anything. It is _almost always_ a better idea to `panic!` than to have - /// a busy loop. - /// - /// If panicking isn't possible, think of the environment and either: - /// - block on something - /// - sleep the thread for some microseconds - /// - yield or pause the thread - /// - /// For `std` targets, this can be done with - /// [`std::thread::sleep`](https://doc.rust-lang.org/std/thread/fn.sleep.html) - /// or [`std::thread::yield_now`](https://doc.rust-lang.org/std/thread/fn.yield_now.html). - /// - /// For `no_std` targets, doing this is more complicated, especially because - /// `#[panic_handler]`s can't panic. To stop/pause the thread, you will - /// probably need to invoke some target-specific intrinsic. Examples include: - /// - [`x86_64::instructions::hlt`](https://docs.rs/x86_64/0.12.2/x86_64/instructions/fn.hlt.html) - /// - [`cortex_m::asm::wfi`](https://docs.rs/cortex-m/0.6.3/cortex_m/asm/fn.wfi.html) - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```no_run - /// loop {} - /// ``` - pub EMPTY_LOOP, - style, - "empty `loop {}`, which should block or sleep" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `while let` expressions on iterators. - /// - /// **Why is this bad?** Readability. A simple `for` loop is shorter and conveys - /// the intent better. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// while let Some(val) = iter() { - /// .. - /// } - /// ``` - pub WHILE_LET_ON_ITERATOR, - style, - "using a while-let loop instead of a for loop on an iterator" -} - -declare_clippy_lint! { - /// **What it does:** Checks for iterating a map (`HashMap` or `BTreeMap`) and - /// ignoring either the keys or values. - /// - /// **Why is this bad?** Readability. There are `keys` and `values` methods that - /// can be used to express that don't need the values or keys. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// for (k, _) in &map { - /// .. - /// } - /// ``` - /// - /// could be replaced by - /// - /// ```ignore - /// for k in map.keys() { - /// .. - /// } - /// ``` - pub FOR_KV_MAP, - style, - "looping on a map using `iter` when `keys` or `values` would do" -} - -declare_clippy_lint! { - /// **What it does:** Checks for loops that will always `break`, `return` or - /// `continue` an outer loop. - /// - /// **Why is this bad?** This loop never loops, all it does is obfuscating the - /// code. - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```rust - /// loop { - /// ..; - /// break; - /// } - /// ``` - pub NEVER_LOOP, - correctness, - "any loop that will always `break` or `return`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for loops which have a range bound that is a mutable variable - /// - /// **Why is this bad?** One might think that modifying the mutable variable changes the loop bounds - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```rust - /// let mut foo = 42; - /// for i in 0..foo { - /// foo -= 1; - /// println!("{}", i); // prints numbers from 0 to 42, not 0 to 21 - /// } - /// ``` - pub MUT_RANGE_BOUND, - complexity, - "for loop over a range where one of the bounds is a mutable variable" -} - -declare_clippy_lint! { - /// **What it does:** Checks whether variables used within while loop condition - /// can be (and are) mutated in the body. - /// - /// **Why is this bad?** If the condition is unchanged, entering the body of the loop - /// will lead to an infinite loop. - /// - /// **Known problems:** If the `while`-loop is in a closure, the check for mutation of the - /// condition variables in the body can cause false negatives. For example when only `Upvar` `a` is - /// in the condition and only `Upvar` `b` gets mutated in the body, the lint will not trigger. - /// - /// **Example:** - /// ```rust - /// let i = 0; - /// while i > 10 { - /// println!("let me loop forever!"); - /// } - /// ``` - pub WHILE_IMMUTABLE_CONDITION, - correctness, - "variables used within while expression are not mutated in the body" -} - -declare_clippy_lint! { - /// **What it does:** Checks whether a for loop is being used to push a constant - /// value into a Vec. - /// - /// **Why is this bad?** This kind of operation can be expressed more succinctly with - /// `vec![item;SIZE]` or `vec.resize(NEW_SIZE, item)` and using these alternatives may also - /// have better performance. - /// **Known problems:** None - /// - /// **Example:** - /// ```rust - /// let item1 = 2; - /// let item2 = 3; - /// let mut vec: Vec = Vec::new(); - /// for _ in 0..20 { - /// vec.push(item1); - /// } - /// for _ in 0..30 { - /// vec.push(item2); - /// } - /// ``` - /// could be written as - /// ```rust - /// let item1 = 2; - /// let item2 = 3; - /// let mut vec: Vec = vec![item1; 20]; - /// vec.resize(20 + 30, item2); - /// ``` - pub SAME_ITEM_PUSH, - style, - "the same item is pushed inside of a for loop" -} - -declare_clippy_lint! { - /// **What it does:** Checks whether a for loop has a single element. - /// - /// **Why is this bad?** There is no reason to have a loop of a - /// single element. - /// **Known problems:** None - /// - /// **Example:** - /// ```rust - /// let item1 = 2; - /// for item in &[item1] { - /// println!("{}", item); - /// } - /// ``` - /// could be written as - /// ```rust - /// let item1 = 2; - /// let item = &item1; - /// println!("{}", item); - /// ``` - pub SINGLE_ELEMENT_LOOP, - complexity, - "there is no reason to have a single element loop" -} - -declare_lint_pass!(Loops => [ - MANUAL_MEMCPY, - NEEDLESS_RANGE_LOOP, - EXPLICIT_ITER_LOOP, - EXPLICIT_INTO_ITER_LOOP, - ITER_NEXT_LOOP, - FOR_LOOPS_OVER_FALLIBLES, - WHILE_LET_LOOP, - NEEDLESS_COLLECT, - EXPLICIT_COUNTER_LOOP, - EMPTY_LOOP, - WHILE_LET_ON_ITERATOR, - FOR_KV_MAP, - NEVER_LOOP, - MUT_RANGE_BOUND, - WHILE_IMMUTABLE_CONDITION, - SAME_ITEM_PUSH, - SINGLE_ELEMENT_LOOP, -]); - -impl<'tcx> LateLintPass<'tcx> for Loops { - #[allow(clippy::too_many_lines)] - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let Some((pat, arg, body)) = higher::for_loop(expr) { - // we don't want to check expanded macros - // this check is not at the top of the function - // since higher::for_loop expressions are marked as expansions - if body.span.from_expansion() { - return; - } - check_for_loop(cx, pat, arg, body, expr); - } - - // we don't want to check expanded macros - if expr.span.from_expansion() { - return; - } - - // check for never_loop - if let ExprKind::Loop(ref block, _, _) = expr.kind { - match never_loop_block(block, expr.hir_id) { - NeverLoopResult::AlwaysBreak => span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually loops"), - NeverLoopResult::MayContinueMainLoop | NeverLoopResult::Otherwise => (), - } - } - - // check for `loop { if let {} else break }` that could be `while let` - // (also matches an explicit "match" instead of "if let") - // (even if the "match" or "if let" is used for declaration) - if let ExprKind::Loop(ref block, _, LoopSource::Loop) = expr.kind { - // also check for empty `loop {}` statements, skipping those in #[panic_handler] - if block.stmts.is_empty() && block.expr.is_none() && !is_in_panic_handler(cx, expr) { - let msg = "empty `loop {}` wastes CPU cycles"; - let help = if is_no_std_crate(cx.tcx.hir().krate()) { - "you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body" - } else { - "you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body" - }; - span_lint_and_help(cx, EMPTY_LOOP, expr.span, msg, None, help); - } - - // extract the expression from the first statement (if any) in a block - let inner_stmt_expr = extract_expr_from_first_stmt(block); - // or extract the first expression (if any) from the block - if let Some(inner) = inner_stmt_expr.or_else(|| extract_first_expr(block)) { - if let ExprKind::Match(ref matchexpr, ref arms, ref source) = inner.kind { - // ensure "if let" compatible match structure - match *source { - MatchSource::Normal | MatchSource::IfLetDesugar { .. } => { - if arms.len() == 2 - && arms[0].guard.is_none() - && arms[1].guard.is_none() - && is_simple_break_expr(&arms[1].body) - { - if in_external_macro(cx.sess(), expr.span) { - return; - } - - // NOTE: we used to build a body here instead of using - // ellipsis, this was removed because: - // 1) it was ugly with big bodies; - // 2) it was not indented properly; - // 3) it wasn’t very smart (see #675). - let mut applicability = Applicability::HasPlaceholders; - span_lint_and_sugg( - cx, - WHILE_LET_LOOP, - expr.span, - "this loop could be written as a `while let` loop", - "try", - format!( - "while let {} = {} {{ .. }}", - snippet_with_applicability(cx, arms[0].pat.span, "..", &mut applicability), - snippet_with_applicability(cx, matchexpr.span, "..", &mut applicability), - ), - applicability, - ); - } - }, - _ => (), - } - } - } - } - if let ExprKind::Match(ref match_expr, ref arms, MatchSource::WhileLetDesugar) = expr.kind { - let pat = &arms[0].pat.kind; - if let ( - &PatKind::TupleStruct(ref qpath, ref pat_args, _), - &ExprKind::MethodCall(ref method_path, _, ref method_args, _), - ) = (pat, &match_expr.kind) - { - let iter_expr = &method_args[0]; - - // Don't lint when the iterator is recreated on every iteration - if_chain! { - if let ExprKind::MethodCall(..) | ExprKind::Call(..) = iter_expr.kind; - if let Some(iter_def_id) = get_trait_def_id(cx, &paths::ITERATOR); - if implements_trait(cx, cx.typeck_results().expr_ty(iter_expr), iter_def_id, &[]); - then { - return; - } - } - - let lhs_constructor = last_path_segment(qpath); - if method_path.ident.name == sym::next - && match_trait_method(cx, match_expr, &paths::ITERATOR) - && lhs_constructor.ident.name == sym::Some - && (pat_args.is_empty() - || !is_refutable(cx, &pat_args[0]) - && !is_used_inside(cx, iter_expr, &arms[0].body) - && !is_iterator_used_after_while_let(cx, iter_expr) - && !is_nested(cx, expr, &method_args[0])) - { - let mut applicability = Applicability::MachineApplicable; - let iterator = snippet_with_applicability(cx, method_args[0].span, "_", &mut applicability); - let loop_var = if pat_args.is_empty() { - "_".to_string() - } else { - snippet_with_applicability(cx, pat_args[0].span, "_", &mut applicability).into_owned() - }; - span_lint_and_sugg( - cx, - WHILE_LET_ON_ITERATOR, - expr.span.with_hi(match_expr.span.hi()), - "this loop could be written as a `for` loop", - "try", - format!("for {} in {}", loop_var, iterator), - applicability, - ); - } - } - } - - if let Some((cond, body)) = higher::while_loop(&expr) { - check_infinite_loop(cx, cond, body); - } - - check_needless_collect(expr, cx); - } -} - -enum NeverLoopResult { - // A break/return always get triggered but not necessarily for the main loop. - AlwaysBreak, - // A continue may occur for the main loop. - MayContinueMainLoop, - Otherwise, -} - -#[must_use] -fn absorb_break(arg: &NeverLoopResult) -> NeverLoopResult { - match *arg { - NeverLoopResult::AlwaysBreak | NeverLoopResult::Otherwise => NeverLoopResult::Otherwise, - NeverLoopResult::MayContinueMainLoop => NeverLoopResult::MayContinueMainLoop, - } -} - -// Combine two results for parts that are called in order. -#[must_use] -fn combine_seq(first: NeverLoopResult, second: NeverLoopResult) -> NeverLoopResult { - match first { - NeverLoopResult::AlwaysBreak | NeverLoopResult::MayContinueMainLoop => first, - NeverLoopResult::Otherwise => second, - } -} - -// Combine two results where both parts are called but not necessarily in order. -#[must_use] -fn combine_both(left: NeverLoopResult, right: NeverLoopResult) -> NeverLoopResult { - match (left, right) { - (NeverLoopResult::MayContinueMainLoop, _) | (_, NeverLoopResult::MayContinueMainLoop) => { - NeverLoopResult::MayContinueMainLoop - }, - (NeverLoopResult::AlwaysBreak, _) | (_, NeverLoopResult::AlwaysBreak) => NeverLoopResult::AlwaysBreak, - (NeverLoopResult::Otherwise, NeverLoopResult::Otherwise) => NeverLoopResult::Otherwise, - } -} - -// Combine two results where only one of the part may have been executed. -#[must_use] -fn combine_branches(b1: NeverLoopResult, b2: NeverLoopResult) -> NeverLoopResult { - match (b1, b2) { - (NeverLoopResult::AlwaysBreak, NeverLoopResult::AlwaysBreak) => NeverLoopResult::AlwaysBreak, - (NeverLoopResult::MayContinueMainLoop, _) | (_, NeverLoopResult::MayContinueMainLoop) => { - NeverLoopResult::MayContinueMainLoop - }, - (NeverLoopResult::Otherwise, _) | (_, NeverLoopResult::Otherwise) => NeverLoopResult::Otherwise, - } -} - -fn never_loop_block(block: &Block<'_>, main_loop_id: HirId) -> NeverLoopResult { - let stmts = block.stmts.iter().map(stmt_to_expr); - let expr = once(block.expr.as_deref()); - let mut iter = stmts.chain(expr).filter_map(|e| e); - never_loop_expr_seq(&mut iter, main_loop_id) -} - -fn stmt_to_expr<'tcx>(stmt: &Stmt<'tcx>) -> Option<&'tcx Expr<'tcx>> { - match stmt.kind { - StmtKind::Semi(ref e, ..) | StmtKind::Expr(ref e, ..) => Some(e), - StmtKind::Local(ref local) => local.init.as_deref(), - _ => None, - } -} - -fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { - match expr.kind { - ExprKind::Box(ref e) - | ExprKind::Unary(_, ref e) - | ExprKind::Cast(ref e, _) - | ExprKind::Type(ref e, _) - | ExprKind::Field(ref e, _) - | ExprKind::AddrOf(_, _, ref e) - | ExprKind::Struct(_, _, Some(ref e)) - | ExprKind::Repeat(ref e, _) - | ExprKind::DropTemps(ref e) => never_loop_expr(e, main_loop_id), - ExprKind::Array(ref es) | ExprKind::MethodCall(_, _, ref es, _) | ExprKind::Tup(ref es) => { - never_loop_expr_all(&mut es.iter(), main_loop_id) - }, - ExprKind::Call(ref e, ref es) => never_loop_expr_all(&mut once(&**e).chain(es.iter()), main_loop_id), - ExprKind::Binary(_, ref e1, ref e2) - | ExprKind::Assign(ref e1, ref e2, _) - | ExprKind::AssignOp(_, ref e1, ref e2) - | ExprKind::Index(ref e1, ref e2) => never_loop_expr_all(&mut [&**e1, &**e2].iter().cloned(), main_loop_id), - ExprKind::Loop(ref b, _, _) => { - // Break can come from the inner loop so remove them. - absorb_break(&never_loop_block(b, main_loop_id)) - }, - ExprKind::Match(ref e, ref arms, _) => { - let e = never_loop_expr(e, main_loop_id); - if arms.is_empty() { - e - } else { - let arms = never_loop_expr_branch(&mut arms.iter().map(|a| &*a.body), main_loop_id); - combine_seq(e, arms) - } - }, - ExprKind::Block(ref b, _) => never_loop_block(b, main_loop_id), - ExprKind::Continue(d) => { - let id = d - .target_id - .expect("target ID can only be missing in the presence of compilation errors"); - if id == main_loop_id { - NeverLoopResult::MayContinueMainLoop - } else { - NeverLoopResult::AlwaysBreak - } - }, - ExprKind::Break(_, ref e) | ExprKind::Ret(ref e) => e.as_ref().map_or(NeverLoopResult::AlwaysBreak, |e| { - combine_seq(never_loop_expr(e, main_loop_id), NeverLoopResult::AlwaysBreak) - }), - ExprKind::InlineAsm(ref asm) => asm - .operands - .iter() - .map(|(o, _)| match o { - InlineAsmOperand::In { expr, .. } - | InlineAsmOperand::InOut { expr, .. } - | InlineAsmOperand::Const { expr } - | InlineAsmOperand::Sym { expr } => never_loop_expr(expr, main_loop_id), - InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter(), main_loop_id), - InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { - never_loop_expr_all(&mut once(in_expr).chain(out_expr.iter()), main_loop_id) - }, - }) - .fold(NeverLoopResult::Otherwise, combine_both), - ExprKind::Struct(_, _, None) - | ExprKind::Yield(_, _) - | ExprKind::Closure(_, _, _, _, _) - | ExprKind::LlvmInlineAsm(_) - | ExprKind::Path(_) - | ExprKind::ConstBlock(_) - | ExprKind::Lit(_) - | ExprKind::Err => NeverLoopResult::Otherwise, - } -} - -fn never_loop_expr_seq<'a, T: Iterator>>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult { - es.map(|e| never_loop_expr(e, main_loop_id)) - .fold(NeverLoopResult::Otherwise, combine_seq) -} - -fn never_loop_expr_all<'a, T: Iterator>>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult { - es.map(|e| never_loop_expr(e, main_loop_id)) - .fold(NeverLoopResult::Otherwise, combine_both) -} - -fn never_loop_expr_branch<'a, T: Iterator>>(e: &mut T, main_loop_id: HirId) -> NeverLoopResult { - e.map(|e| never_loop_expr(e, main_loop_id)) - .fold(NeverLoopResult::AlwaysBreak, combine_branches) -} - -fn check_for_loop<'tcx>( - cx: &LateContext<'tcx>, - pat: &'tcx Pat<'_>, - arg: &'tcx Expr<'_>, - body: &'tcx Expr<'_>, - expr: &'tcx Expr<'_>, -) { - let is_manual_memcpy_triggered = detect_manual_memcpy(cx, pat, arg, body, expr); - if !is_manual_memcpy_triggered { - check_for_loop_range(cx, pat, arg, body, expr); - check_for_loop_explicit_counter(cx, pat, arg, body, expr); - } - check_for_loop_arg(cx, pat, arg, expr); - check_for_loop_over_map_kv(cx, pat, arg, body, expr); - check_for_mut_range_bound(cx, arg, body); - check_for_single_element_loop(cx, pat, arg, body, expr); - detect_same_item_push(cx, pat, arg, body, expr); -} - -// this function assumes the given expression is a `for` loop. -fn get_span_of_entire_for_loop(expr: &Expr<'_>) -> Span { - // for some reason this is the only way to get the `Span` - // of the entire `for` loop - if let ExprKind::Match(_, arms, _) = &expr.kind { - arms[0].body.span - } else { - unreachable!() - } -} - -fn same_var<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, var: HirId) -> bool { - if_chain! { - if let ExprKind::Path(qpath) = &expr.kind; - if let QPath::Resolved(None, path) = qpath; - if path.segments.len() == 1; - if let Res::Local(local_id) = qpath_res(cx, qpath, expr.hir_id); - then { - // our variable! - local_id == var - } else { - false - } - } -} - -/// a wrapper of `Sugg`. Besides what `Sugg` do, this removes unnecessary `0`; -/// and also, it avoids subtracting a variable from the same one by replacing it with `0`. -/// it exists for the convenience of the overloaded operators while normal functions can do the -/// same. -#[derive(Clone)] -struct MinifyingSugg<'a>(Sugg<'a>); - -impl<'a> MinifyingSugg<'a> { - fn as_str(&self) -> &str { - let Sugg::NonParen(s) | Sugg::MaybeParen(s) | Sugg::BinOp(_, s) = &self.0; - s.as_ref() - } - - fn into_sugg(self) -> Sugg<'a> { - self.0 - } -} - -impl<'a> From> for MinifyingSugg<'a> { - fn from(sugg: Sugg<'a>) -> Self { - Self(sugg) - } -} - -impl std::ops::Add for &MinifyingSugg<'static> { - type Output = MinifyingSugg<'static>; - fn add(self, rhs: &MinifyingSugg<'static>) -> MinifyingSugg<'static> { - match (self.as_str(), rhs.as_str()) { - ("0", _) => rhs.clone(), - (_, "0") => self.clone(), - (_, _) => (&self.0 + &rhs.0).into(), - } - } -} - -impl std::ops::Sub for &MinifyingSugg<'static> { - type Output = MinifyingSugg<'static>; - fn sub(self, rhs: &MinifyingSugg<'static>) -> MinifyingSugg<'static> { - match (self.as_str(), rhs.as_str()) { - (_, "0") => self.clone(), - ("0", _) => (-rhs.0.clone()).into(), - (x, y) if x == y => sugg::ZERO.into(), - (_, _) => (&self.0 - &rhs.0).into(), - } - } -} - -impl std::ops::Add<&MinifyingSugg<'static>> for MinifyingSugg<'static> { - type Output = MinifyingSugg<'static>; - fn add(self, rhs: &MinifyingSugg<'static>) -> MinifyingSugg<'static> { - match (self.as_str(), rhs.as_str()) { - ("0", _) => rhs.clone(), - (_, "0") => self, - (_, _) => (self.0 + &rhs.0).into(), - } - } -} - -impl std::ops::Sub<&MinifyingSugg<'static>> for MinifyingSugg<'static> { - type Output = MinifyingSugg<'static>; - fn sub(self, rhs: &MinifyingSugg<'static>) -> MinifyingSugg<'static> { - match (self.as_str(), rhs.as_str()) { - (_, "0") => self, - ("0", _) => (-rhs.0.clone()).into(), - (x, y) if x == y => sugg::ZERO.into(), - (_, _) => (self.0 - &rhs.0).into(), - } - } -} - -/// a wrapper around `MinifyingSugg`, which carries a operator like currying -/// so that the suggested code become more efficient (e.g. `foo + -bar` `foo - bar`). -struct Offset { - value: MinifyingSugg<'static>, - sign: OffsetSign, -} - -#[derive(Clone, Copy)] -enum OffsetSign { - Positive, - Negative, -} - -impl Offset { - fn negative(value: Sugg<'static>) -> Self { - Self { - value: value.into(), - sign: OffsetSign::Negative, - } - } - - fn positive(value: Sugg<'static>) -> Self { - Self { - value: value.into(), - sign: OffsetSign::Positive, - } - } - - fn empty() -> Self { - Self::positive(sugg::ZERO) - } -} - -fn apply_offset(lhs: &MinifyingSugg<'static>, rhs: &Offset) -> MinifyingSugg<'static> { - match rhs.sign { - OffsetSign::Positive => lhs + &rhs.value, - OffsetSign::Negative => lhs - &rhs.value, - } -} - -#[derive(Debug, Clone, Copy)] -enum StartKind<'hir> { - Range, - Counter { initializer: &'hir Expr<'hir> }, -} - -struct IndexExpr<'hir> { - base: &'hir Expr<'hir>, - idx: StartKind<'hir>, - idx_offset: Offset, -} - -struct Start<'hir> { - id: HirId, - kind: StartKind<'hir>, -} - -fn is_slice_like<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'_>) -> bool { - let is_slice = match ty.kind() { - ty::Ref(_, subty, _) => is_slice_like(cx, subty), - ty::Slice(..) | ty::Array(..) => true, - _ => false, - }; - - is_slice || is_type_diagnostic_item(cx, ty, sym::vec_type) || is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) -} - -fn fetch_cloned_expr<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { - if_chain! { - if let ExprKind::MethodCall(method, _, args, _) = expr.kind; - if method.ident.name == sym::clone; - if args.len() == 1; - if let Some(arg) = args.get(0); - then { arg } else { expr } - } -} - -fn get_details_from_idx<'tcx>( - cx: &LateContext<'tcx>, - idx: &Expr<'_>, - starts: &[Start<'tcx>], -) -> Option<(StartKind<'tcx>, Offset)> { - fn get_start<'tcx>(cx: &LateContext<'tcx>, e: &Expr<'_>, starts: &[Start<'tcx>]) -> Option> { - starts.iter().find_map(|start| { - if same_var(cx, e, start.id) { - Some(start.kind) - } else { - None - } - }) - } - - fn get_offset<'tcx>(cx: &LateContext<'tcx>, e: &Expr<'_>, starts: &[Start<'tcx>]) -> Option> { - match &e.kind { - ExprKind::Lit(l) => match l.node { - ast::LitKind::Int(x, _ty) => Some(Sugg::NonParen(x.to_string().into())), - _ => None, - }, - ExprKind::Path(..) if get_start(cx, e, starts).is_none() => Some(Sugg::hir(cx, e, "???")), - _ => None, - } - } - - match idx.kind { - ExprKind::Binary(op, lhs, rhs) => match op.node { - BinOpKind::Add => { - let offset_opt = get_start(cx, lhs, starts) - .and_then(|s| get_offset(cx, rhs, starts).map(|o| (s, o))) - .or_else(|| get_start(cx, rhs, starts).and_then(|s| get_offset(cx, lhs, starts).map(|o| (s, o)))); - - offset_opt.map(|(s, o)| (s, Offset::positive(o))) - }, - BinOpKind::Sub => { - get_start(cx, lhs, starts).and_then(|s| get_offset(cx, rhs, starts).map(|o| (s, Offset::negative(o)))) - }, - _ => None, - }, - ExprKind::Path(..) => get_start(cx, idx, starts).map(|s| (s, Offset::empty())), - _ => None, - } -} - -fn get_assignment<'tcx>(e: &'tcx Expr<'tcx>) -> Option<(&'tcx Expr<'tcx>, &'tcx Expr<'tcx>)> { - if let ExprKind::Assign(lhs, rhs, _) = e.kind { - Some((lhs, rhs)) - } else { - None - } -} - -/// Get assignments from the given block. -/// The returned iterator yields `None` if no assignment expressions are there, -/// filtering out the increments of the given whitelisted loop counters; -/// because its job is to make sure there's nothing other than assignments and the increments. -fn get_assignments<'a: 'c, 'tcx: 'c, 'c>( - cx: &'a LateContext<'tcx>, - Block { stmts, expr, .. }: &'tcx Block<'tcx>, - loop_counters: &'c [Start<'tcx>], -) -> impl Iterator, &'tcx Expr<'tcx>)>> + 'c { - // As the `filter` and `map` below do different things, I think putting together - // just increases complexity. (cc #3188 and #4193) - #[allow(clippy::filter_map)] - stmts - .iter() - .filter_map(move |stmt| match stmt.kind { - StmtKind::Local(..) | StmtKind::Item(..) => None, - StmtKind::Expr(e) | StmtKind::Semi(e) => Some(e), - }) - .chain((*expr).into_iter()) - .filter(move |e| { - if let ExprKind::AssignOp(_, place, _) = e.kind { - !loop_counters - .iter() - // skip the first item which should be `StartKind::Range` - // this makes it possible to use the slice with `StartKind::Range` in the same iterator loop. - .skip(1) - .any(|counter| same_var(cx, place, counter.id)) - } else { - true - } - }) - .map(get_assignment) -} - -fn get_loop_counters<'a, 'tcx>( - cx: &'a LateContext<'tcx>, - body: &'tcx Block<'tcx>, - expr: &'tcx Expr<'_>, -) -> Option> + 'a> { - // Look for variables that are incremented once per loop iteration. - let mut increment_visitor = IncrementVisitor::new(cx); - walk_block(&mut increment_visitor, body); - - // For each candidate, check the parent block to see if - // it's initialized to zero at the start of the loop. - get_enclosing_block(&cx, expr.hir_id).and_then(|block| { - increment_visitor - .into_results() - .filter_map(move |var_id| { - let mut initialize_visitor = InitializeVisitor::new(cx, expr, var_id); - walk_block(&mut initialize_visitor, block); - - initialize_visitor.get_result().map(|(_, initializer)| Start { - id: var_id, - kind: StartKind::Counter { initializer }, - }) - }) - .into() - }) -} - -fn build_manual_memcpy_suggestion<'tcx>( - cx: &LateContext<'tcx>, - start: &Expr<'_>, - end: &Expr<'_>, - limits: ast::RangeLimits, - dst: &IndexExpr<'_>, - src: &IndexExpr<'_>, -) -> String { - fn print_offset(offset: MinifyingSugg<'static>) -> MinifyingSugg<'static> { - if offset.as_str() == "0" { - sugg::EMPTY.into() - } else { - offset - } - } - - let print_limit = |end: &Expr<'_>, end_str: &str, base: &Expr<'_>, sugg: MinifyingSugg<'static>| { - if_chain! { - if let ExprKind::MethodCall(method, _, len_args, _) = end.kind; - if method.ident.name == sym!(len); - if len_args.len() == 1; - if let Some(arg) = len_args.get(0); - if var_def_id(cx, arg) == var_def_id(cx, base); - then { - if sugg.as_str() == end_str { - sugg::EMPTY.into() - } else { - sugg - } - } else { - match limits { - ast::RangeLimits::Closed => { - sugg + &sugg::ONE.into() - }, - ast::RangeLimits::HalfOpen => sugg, - } - } - } - }; - - let start_str = Sugg::hir(cx, start, "").into(); - let end_str: MinifyingSugg<'_> = Sugg::hir(cx, end, "").into(); - - let print_offset_and_limit = |idx_expr: &IndexExpr<'_>| match idx_expr.idx { - StartKind::Range => ( - print_offset(apply_offset(&start_str, &idx_expr.idx_offset)).into_sugg(), - print_limit( - end, - end_str.as_str(), - idx_expr.base, - apply_offset(&end_str, &idx_expr.idx_offset), - ) - .into_sugg(), - ), - StartKind::Counter { initializer } => { - let counter_start = Sugg::hir(cx, initializer, "").into(); - ( - print_offset(apply_offset(&counter_start, &idx_expr.idx_offset)).into_sugg(), - print_limit( - end, - end_str.as_str(), - idx_expr.base, - apply_offset(&end_str, &idx_expr.idx_offset) + &counter_start - &start_str, - ) - .into_sugg(), - ) - }, - }; - - let (dst_offset, dst_limit) = print_offset_and_limit(&dst); - let (src_offset, src_limit) = print_offset_and_limit(&src); - - let dst_base_str = snippet(cx, dst.base.span, "???"); - let src_base_str = snippet(cx, src.base.span, "???"); - - let dst = if dst_offset == sugg::EMPTY && dst_limit == sugg::EMPTY { - dst_base_str - } else { - format!( - "{}[{}..{}]", - dst_base_str, - dst_offset.maybe_par(), - dst_limit.maybe_par() - ) - .into() - }; - - format!( - "{}.clone_from_slice(&{}[{}..{}]);", - dst, - src_base_str, - src_offset.maybe_par(), - src_limit.maybe_par() - ) -} - -/// Checks for for loops that sequentially copy items from one slice-like -/// object to another. -fn detect_manual_memcpy<'tcx>( - cx: &LateContext<'tcx>, - pat: &'tcx Pat<'_>, - arg: &'tcx Expr<'_>, - body: &'tcx Expr<'_>, - expr: &'tcx Expr<'_>, -) -> bool { - if let Some(higher::Range { - start: Some(start), - end: Some(end), - limits, - }) = higher::range(arg) - { - // the var must be a single name - if let PatKind::Binding(_, canonical_id, _, _) = pat.kind { - let mut starts = vec![Start { - id: canonical_id, - kind: StartKind::Range, - }]; - - // This is one of few ways to return different iterators - // derived from: https://stackoverflow.com/questions/29760668/conditionally-iterate-over-one-of-several-possible-iterators/52064434#52064434 - let mut iter_a = None; - let mut iter_b = None; - - if let ExprKind::Block(block, _) = body.kind { - if let Some(loop_counters) = get_loop_counters(cx, block, expr) { - starts.extend(loop_counters); - } - iter_a = Some(get_assignments(cx, block, &starts)); - } else { - iter_b = Some(get_assignment(body)); - } - - let assignments = iter_a.into_iter().flatten().chain(iter_b.into_iter()); - - let big_sugg = assignments - // The only statements in the for loops can be indexed assignments from - // indexed retrievals (except increments of loop counters). - .map(|o| { - o.and_then(|(lhs, rhs)| { - let rhs = fetch_cloned_expr(rhs); - if_chain! { - if let ExprKind::Index(base_left, idx_left) = lhs.kind; - if let ExprKind::Index(base_right, idx_right) = rhs.kind; - if is_slice_like(cx, cx.typeck_results().expr_ty(base_left)) - && is_slice_like(cx, cx.typeck_results().expr_ty(base_right)); - if let Some((start_left, offset_left)) = get_details_from_idx(cx, &idx_left, &starts); - if let Some((start_right, offset_right)) = get_details_from_idx(cx, &idx_right, &starts); - - // Source and destination must be different - if var_def_id(cx, base_left) != var_def_id(cx, base_right); - then { - Some((IndexExpr { base: base_left, idx: start_left, idx_offset: offset_left }, - IndexExpr { base: base_right, idx: start_right, idx_offset: offset_right })) - } else { - None - } - } - }) - }) - .map(|o| o.map(|(dst, src)| build_manual_memcpy_suggestion(cx, start, end, limits, &dst, &src))) - .collect::>>() - .filter(|v| !v.is_empty()) - .map(|v| v.join("\n ")); - - if let Some(big_sugg) = big_sugg { - span_lint_and_sugg( - cx, - MANUAL_MEMCPY, - get_span_of_entire_for_loop(expr), - "it looks like you're manually copying between slices", - "try replacing the loop by", - big_sugg, - Applicability::Unspecified, - ); - return true; - } - } - } - false -} - -// Scans the body of the for loop and determines whether lint should be given -struct SameItemPushVisitor<'a, 'tcx> { - should_lint: bool, - // this field holds the last vec push operation visited, which should be the only push seen - vec_push: Option<(&'tcx Expr<'tcx>, &'tcx Expr<'tcx>)>, - cx: &'a LateContext<'tcx>, -} - -impl<'a, 'tcx> Visitor<'tcx> for SameItemPushVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - match &expr.kind { - // Non-determinism may occur ... don't give a lint - ExprKind::Loop(_, _, _) | ExprKind::Match(_, _, _) => self.should_lint = false, - ExprKind::Block(block, _) => self.visit_block(block), - _ => {}, - } - } - - fn visit_block(&mut self, b: &'tcx Block<'_>) { - for stmt in b.stmts.iter() { - self.visit_stmt(stmt); - } - } - - fn visit_stmt(&mut self, s: &'tcx Stmt<'_>) { - let vec_push_option = get_vec_push(self.cx, s); - if vec_push_option.is_none() { - // Current statement is not a push so visit inside - match &s.kind { - StmtKind::Expr(expr) | StmtKind::Semi(expr) => self.visit_expr(&expr), - _ => {}, - } - } else { - // Current statement is a push ...check whether another - // push had been previously done - if self.vec_push.is_none() { - self.vec_push = vec_push_option; - } else { - // There are multiple pushes ... don't lint - self.should_lint = false; - } - } - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -// Given some statement, determine if that statement is a push on a Vec. If it is, return -// the Vec being pushed into and the item being pushed -fn get_vec_push<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) -> Option<(&'tcx Expr<'tcx>, &'tcx Expr<'tcx>)> { - if_chain! { - // Extract method being called - if let StmtKind::Semi(semi_stmt) = &stmt.kind; - if let ExprKind::MethodCall(path, _, args, _) = &semi_stmt.kind; - // Figure out the parameters for the method call - if let Some(self_expr) = args.get(0); - if let Some(pushed_item) = args.get(1); - // Check that the method being called is push() on a Vec - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(self_expr), sym::vec_type); - if path.ident.name.as_str() == "push"; - then { - return Some((self_expr, pushed_item)) - } - } - None -} - -/// Detects for loop pushing the same item into a Vec -fn detect_same_item_push<'tcx>( - cx: &LateContext<'tcx>, - pat: &'tcx Pat<'_>, - _: &'tcx Expr<'_>, - body: &'tcx Expr<'_>, - _: &'tcx Expr<'_>, -) { - fn emit_lint(cx: &LateContext<'_>, vec: &Expr<'_>, pushed_item: &Expr<'_>) { - let vec_str = snippet_with_macro_callsite(cx, vec.span, ""); - let item_str = snippet_with_macro_callsite(cx, pushed_item.span, ""); - - span_lint_and_help( - cx, - SAME_ITEM_PUSH, - vec.span, - "it looks like the same item is being pushed into this Vec", - None, - &format!( - "try using vec![{};SIZE] or {}.resize(NEW_SIZE, {})", - item_str, vec_str, item_str - ), - ) - } - - if !matches!(pat.kind, PatKind::Wild) { - return; - } - - // Determine whether it is safe to lint the body - let mut same_item_push_visitor = SameItemPushVisitor { - should_lint: true, - vec_push: None, - cx, - }; - walk_expr(&mut same_item_push_visitor, body); - if same_item_push_visitor.should_lint { - if let Some((vec, pushed_item)) = same_item_push_visitor.vec_push { - let vec_ty = cx.typeck_results().expr_ty(vec); - let ty = vec_ty.walk().nth(1).unwrap().expect_ty(); - if cx - .tcx - .lang_items() - .clone_trait() - .map_or(false, |id| implements_trait(cx, ty, id, &[])) - { - // Make sure that the push does not involve possibly mutating values - match pushed_item.kind { - ExprKind::Path(ref qpath) => { - match qpath_res(cx, qpath, pushed_item.hir_id) { - // immutable bindings that are initialized with literal or constant - Res::Local(hir_id) => { - if_chain! { - let node = cx.tcx.hir().get(hir_id); - if let Node::Binding(pat) = node; - if let PatKind::Binding(bind_ann, ..) = pat.kind; - if !matches!(bind_ann, BindingAnnotation::RefMut | BindingAnnotation::Mutable); - let parent_node = cx.tcx.hir().get_parent_node(hir_id); - if let Some(Node::Local(parent_let_expr)) = cx.tcx.hir().find(parent_node); - if let Some(init) = parent_let_expr.init; - then { - match init.kind { - // immutable bindings that are initialized with literal - ExprKind::Lit(..) => emit_lint(cx, vec, pushed_item), - // immutable bindings that are initialized with constant - ExprKind::Path(ref path) => { - if let Res::Def(DefKind::Const, ..) = qpath_res(cx, path, init.hir_id) { - emit_lint(cx, vec, pushed_item); - } - } - _ => {}, - } - } - } - }, - // constant - Res::Def(DefKind::Const, ..) => emit_lint(cx, vec, pushed_item), - _ => {}, - } - }, - ExprKind::Lit(..) => emit_lint(cx, vec, pushed_item), - _ => {}, - } - } - } - } -} - -/// Checks for looping over a range and then indexing a sequence with it. -/// The iteratee must be a range literal. -#[allow(clippy::too_many_lines)] -fn check_for_loop_range<'tcx>( - cx: &LateContext<'tcx>, - pat: &'tcx Pat<'_>, - arg: &'tcx Expr<'_>, - body: &'tcx Expr<'_>, - expr: &'tcx Expr<'_>, -) { - if let Some(higher::Range { - start: Some(start), - ref end, - limits, - }) = higher::range(arg) - { - // the var must be a single name - if let PatKind::Binding(_, canonical_id, ident, _) = pat.kind { - let mut visitor = VarVisitor { - cx, - var: canonical_id, - indexed_mut: FxHashSet::default(), - indexed_indirectly: FxHashMap::default(), - indexed_directly: FxHashMap::default(), - referenced: FxHashSet::default(), - nonindex: false, - prefer_mutable: false, - }; - walk_expr(&mut visitor, body); - - // linting condition: we only indexed one variable, and indexed it directly - if visitor.indexed_indirectly.is_empty() && visitor.indexed_directly.len() == 1 { - let (indexed, (indexed_extent, indexed_ty)) = visitor - .indexed_directly - .into_iter() - .next() - .expect("already checked that we have exactly 1 element"); - - // ensure that the indexed variable was declared before the loop, see #601 - if let Some(indexed_extent) = indexed_extent { - let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id); - let parent_def_id = cx.tcx.hir().local_def_id(parent_id); - let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id); - let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id); - if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) { - return; - } - } - - // don't lint if the container that is indexed does not have .iter() method - let has_iter = has_iter_method(cx, indexed_ty); - if has_iter.is_none() { - return; - } - - // don't lint if the container that is indexed into is also used without - // indexing - if visitor.referenced.contains(&indexed) { - return; - } - - let starts_at_zero = is_integer_const(cx, start, 0); - - let skip = if starts_at_zero { - String::new() - } else if visitor.indexed_mut.contains(&indexed) && contains_name(indexed, start) { - return; - } else { - format!(".skip({})", snippet(cx, start.span, "..")) - }; - - let mut end_is_start_plus_val = false; - - let take = if let Some(end) = *end { - let mut take_expr = end; - - if let ExprKind::Binary(ref op, ref left, ref right) = end.kind { - if let BinOpKind::Add = op.node { - let start_equal_left = SpanlessEq::new(cx).eq_expr(start, left); - let start_equal_right = SpanlessEq::new(cx).eq_expr(start, right); - - if start_equal_left { - take_expr = right; - } else if start_equal_right { - take_expr = left; - } - - end_is_start_plus_val = start_equal_left | start_equal_right; - } - } - - if is_len_call(end, indexed) || is_end_eq_array_len(cx, end, limits, indexed_ty) { - String::new() - } else if visitor.indexed_mut.contains(&indexed) && contains_name(indexed, take_expr) { - return; - } else { - match limits { - ast::RangeLimits::Closed => { - let take_expr = sugg::Sugg::hir(cx, take_expr, ""); - format!(".take({})", take_expr + sugg::ONE) - }, - ast::RangeLimits::HalfOpen => format!(".take({})", snippet(cx, take_expr.span, "..")), - } - } - } else { - String::new() - }; - - let (ref_mut, method) = if visitor.indexed_mut.contains(&indexed) { - ("mut ", "iter_mut") - } else { - ("", "iter") - }; - - let take_is_empty = take.is_empty(); - let mut method_1 = take; - let mut method_2 = skip; - - if end_is_start_plus_val { - mem::swap(&mut method_1, &mut method_2); - } - - if visitor.nonindex { - span_lint_and_then( - cx, - NEEDLESS_RANGE_LOOP, - expr.span, - &format!("the loop variable `{}` is used to index `{}`", ident.name, indexed), - |diag| { - multispan_sugg( - diag, - "consider using an iterator", - vec![ - (pat.span, format!("({}, )", ident.name)), - ( - arg.span, - format!("{}.{}().enumerate(){}{}", indexed, method, method_1, method_2), - ), - ], - ); - }, - ); - } else { - let repl = if starts_at_zero && take_is_empty { - format!("&{}{}", ref_mut, indexed) - } else { - format!("{}.{}(){}{}", indexed, method, method_1, method_2) - }; - - span_lint_and_then( - cx, - NEEDLESS_RANGE_LOOP, - expr.span, - &format!( - "the loop variable `{}` is only used to index `{}`.", - ident.name, indexed - ), - |diag| { - multispan_sugg( - diag, - "consider using an iterator", - vec![(pat.span, "".to_string()), (arg.span, repl)], - ); - }, - ); - } - } - } - } -} - -fn is_len_call(expr: &Expr<'_>, var: Symbol) -> bool { - if_chain! { - if let ExprKind::MethodCall(ref method, _, ref len_args, _) = expr.kind; - if len_args.len() == 1; - if method.ident.name == sym!(len); - if let ExprKind::Path(QPath::Resolved(_, ref path)) = len_args[0].kind; - if path.segments.len() == 1; - if path.segments[0].ident.name == var; - then { - return true; - } - } - - false -} - -fn is_end_eq_array_len<'tcx>( - cx: &LateContext<'tcx>, - end: &Expr<'_>, - limits: ast::RangeLimits, - indexed_ty: Ty<'tcx>, -) -> bool { - if_chain! { - if let ExprKind::Lit(ref lit) = end.kind; - if let ast::LitKind::Int(end_int, _) = lit.node; - if let ty::Array(_, arr_len_const) = indexed_ty.kind(); - if let Some(arr_len) = arr_len_const.try_eval_usize(cx.tcx, cx.param_env); - then { - return match limits { - ast::RangeLimits::Closed => end_int + 1 >= arr_len.into(), - ast::RangeLimits::HalfOpen => end_int >= arr_len.into(), - }; - } - } - - false -} - -fn lint_iter_method(cx: &LateContext<'_>, args: &[Expr<'_>], arg: &Expr<'_>, method_name: &str) { - let mut applicability = Applicability::MachineApplicable; - let object = snippet_with_applicability(cx, args[0].span, "_", &mut applicability); - let muta = if method_name == "iter_mut" { "mut " } else { "" }; - span_lint_and_sugg( - cx, - EXPLICIT_ITER_LOOP, - arg.span, - "it is more concise to loop over references to containers instead of using explicit \ - iteration methods", - "to write this more concisely, try", - format!("&{}{}", muta, object), - applicability, - ) -} - -fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, expr: &Expr<'_>) { - let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used - if let ExprKind::MethodCall(ref method, _, ref args, _) = arg.kind { - // just the receiver, no arguments - if args.len() == 1 { - let method_name = &*method.ident.as_str(); - // check for looping over x.iter() or x.iter_mut(), could use &x or &mut x - if method_name == "iter" || method_name == "iter_mut" { - if is_ref_iterable_type(cx, &args[0]) { - lint_iter_method(cx, args, arg, method_name); - } - } else if method_name == "into_iter" && match_trait_method(cx, arg, &paths::INTO_ITERATOR) { - let receiver_ty = cx.typeck_results().expr_ty(&args[0]); - let receiver_ty_adjusted = cx.typeck_results().expr_ty_adjusted(&args[0]); - if TyS::same_type(receiver_ty, receiver_ty_adjusted) { - let mut applicability = Applicability::MachineApplicable; - let object = snippet_with_applicability(cx, args[0].span, "_", &mut applicability); - span_lint_and_sugg( - cx, - EXPLICIT_INTO_ITER_LOOP, - arg.span, - "it is more concise to loop over containers instead of using explicit \ - iteration methods", - "to write this more concisely, try", - object.to_string(), - applicability, - ); - } else { - let ref_receiver_ty = cx.tcx.mk_ref( - cx.tcx.lifetimes.re_erased, - ty::TypeAndMut { - ty: receiver_ty, - mutbl: Mutability::Not, - }, - ); - if TyS::same_type(receiver_ty_adjusted, ref_receiver_ty) { - lint_iter_method(cx, args, arg, method_name) - } - } - } else if method_name == "next" && match_trait_method(cx, arg, &paths::ITERATOR) { - span_lint( - cx, - ITER_NEXT_LOOP, - expr.span, - "you are iterating over `Iterator::next()` which is an Option; this will compile but is \ - probably not what you want", - ); - next_loop_linted = true; - } - } - } - if !next_loop_linted { - check_arg_type(cx, pat, arg); - } -} - -/// Checks for `for` loops over `Option`s and `Result`s. -fn check_arg_type(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) { - let ty = cx.typeck_results().expr_ty(arg); - if is_type_diagnostic_item(cx, ty, sym::option_type) { - span_lint_and_help( - cx, - FOR_LOOPS_OVER_FALLIBLES, - arg.span, - &format!( - "for loop over `{0}`, which is an `Option`. This is more readably written as an \ - `if let` statement.", - snippet(cx, arg.span, "_") - ), - None, - &format!( - "consider replacing `for {0} in {1}` with `if let Some({0}) = {1}`", - snippet(cx, pat.span, "_"), - snippet(cx, arg.span, "_") - ), - ); - } else if is_type_diagnostic_item(cx, ty, sym::result_type) { - span_lint_and_help( - cx, - FOR_LOOPS_OVER_FALLIBLES, - arg.span, - &format!( - "for loop over `{0}`, which is a `Result`. This is more readably written as an \ - `if let` statement.", - snippet(cx, arg.span, "_") - ), - None, - &format!( - "consider replacing `for {0} in {1}` with `if let Ok({0}) = {1}`", - snippet(cx, pat.span, "_"), - snippet(cx, arg.span, "_") - ), - ); - } -} - -// To trigger the EXPLICIT_COUNTER_LOOP lint, a variable must be -// incremented exactly once in the loop body, and initialized to zero -// at the start of the loop. -fn check_for_loop_explicit_counter<'tcx>( - cx: &LateContext<'tcx>, - pat: &'tcx Pat<'_>, - arg: &'tcx Expr<'_>, - body: &'tcx Expr<'_>, - expr: &'tcx Expr<'_>, -) { - // Look for variables that are incremented once per loop iteration. - let mut increment_visitor = IncrementVisitor::new(cx); - walk_expr(&mut increment_visitor, body); - - // For each candidate, check the parent block to see if - // it's initialized to zero at the start of the loop. - if let Some(block) = get_enclosing_block(&cx, expr.hir_id) { - for id in increment_visitor.into_results() { - let mut initialize_visitor = InitializeVisitor::new(cx, expr, id); - walk_block(&mut initialize_visitor, block); - - if_chain! { - if let Some((name, initializer)) = initialize_visitor.get_result(); - if is_integer_const(cx, initializer, 0); - then { - let mut applicability = Applicability::MachineApplicable; - - let for_span = get_span_of_entire_for_loop(expr); - - span_lint_and_sugg( - cx, - EXPLICIT_COUNTER_LOOP, - for_span.with_hi(arg.span.hi()), - &format!("the variable `{}` is used as a loop counter.", name), - "consider using", - format!( - "for ({}, {}) in {}.enumerate()", - name, - snippet_with_applicability(cx, pat.span, "item", &mut applicability), - make_iterator_snippet(cx, arg, &mut applicability), - ), - applicability, - ); - } - } - } - } -} - -/// If `arg` was the argument to a `for` loop, return the "cleanest" way of writing the -/// actual `Iterator` that the loop uses. -fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic_ref: &mut Applicability) -> String { - let impls_iterator = get_trait_def_id(cx, &paths::ITERATOR).map_or(false, |id| { - implements_trait(cx, cx.typeck_results().expr_ty(arg), id, &[]) - }); - if impls_iterator { - format!( - "{}", - sugg::Sugg::hir_with_applicability(cx, arg, "_", applic_ref).maybe_par() - ) - } else { - // (&x).into_iter() ==> x.iter() - // (&mut x).into_iter() ==> x.iter_mut() - match &arg.kind { - ExprKind::AddrOf(BorrowKind::Ref, mutability, arg_inner) - if has_iter_method(cx, cx.typeck_results().expr_ty(&arg_inner)).is_some() => - { - let meth_name = match mutability { - Mutability::Mut => "iter_mut", - Mutability::Not => "iter", - }; - format!( - "{}.{}()", - sugg::Sugg::hir_with_applicability(cx, &arg_inner, "_", applic_ref).maybe_par(), - meth_name, - ) - } - _ => format!( - "{}.into_iter()", - sugg::Sugg::hir_with_applicability(cx, arg, "_", applic_ref).maybe_par() - ), - } - } -} - -/// Checks for the `FOR_KV_MAP` lint. -fn check_for_loop_over_map_kv<'tcx>( - cx: &LateContext<'tcx>, - pat: &'tcx Pat<'_>, - arg: &'tcx Expr<'_>, - body: &'tcx Expr<'_>, - expr: &'tcx Expr<'_>, -) { - let pat_span = pat.span; - - if let PatKind::Tuple(ref pat, _) = pat.kind { - if pat.len() == 2 { - let arg_span = arg.span; - let (new_pat_span, kind, ty, mutbl) = match *cx.typeck_results().expr_ty(arg).kind() { - ty::Ref(_, ty, mutbl) => match (&pat[0].kind, &pat[1].kind) { - (key, _) if pat_is_wild(key, body) => (pat[1].span, "value", ty, mutbl), - (_, value) if pat_is_wild(value, body) => (pat[0].span, "key", ty, Mutability::Not), - _ => return, - }, - _ => return, - }; - let mutbl = match mutbl { - Mutability::Not => "", - Mutability::Mut => "_mut", - }; - let arg = match arg.kind { - ExprKind::AddrOf(BorrowKind::Ref, _, ref expr) => &**expr, - _ => arg, - }; - - if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) || match_type(cx, ty, &paths::BTREEMAP) { - span_lint_and_then( - cx, - FOR_KV_MAP, - expr.span, - &format!("you seem to want to iterate on a map's {}s", kind), - |diag| { - let map = sugg::Sugg::hir(cx, arg, "map"); - multispan_sugg( - diag, - "use the corresponding method", - vec![ - (pat_span, snippet(cx, new_pat_span, kind).into_owned()), - (arg_span, format!("{}.{}s{}()", map.maybe_par(), kind, mutbl)), - ], - ); - }, - ); - } - } - } -} - -fn check_for_single_element_loop<'tcx>( - cx: &LateContext<'tcx>, - pat: &'tcx Pat<'_>, - arg: &'tcx Expr<'_>, - body: &'tcx Expr<'_>, - expr: &'tcx Expr<'_>, -) { - if_chain! { - if let ExprKind::AddrOf(BorrowKind::Ref, _, ref arg_expr) = arg.kind; - if let PatKind::Binding(.., target, _) = pat.kind; - if let ExprKind::Array([arg_expression]) = arg_expr.kind; - if let ExprKind::Path(ref list_item) = arg_expression.kind; - if let Some(list_item_name) = single_segment_path(list_item).map(|ps| ps.ident.name); - if let ExprKind::Block(ref block, _) = body.kind; - if !block.stmts.is_empty(); - - then { - let for_span = get_span_of_entire_for_loop(expr); - let mut block_str = snippet(cx, block.span, "..").into_owned(); - block_str.remove(0); - block_str.pop(); - - - span_lint_and_sugg( - cx, - SINGLE_ELEMENT_LOOP, - for_span, - "for loop over a single element", - "try", - format!("{{\n{}let {} = &{};{}}}", " ".repeat(indent_of(cx, block.stmts[0].span).unwrap_or(0)), target.name, list_item_name, block_str), - Applicability::MachineApplicable - ) - } - } -} - -struct MutatePairDelegate<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - hir_id_low: Option, - hir_id_high: Option, - span_low: Option, - span_high: Option, -} - -impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> { - fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId, _: ConsumeMode) {} - - fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: ty::BorrowKind) { - if let ty::BorrowKind::MutBorrow = bk { - if let PlaceBase::Local(id) = cmt.place.base { - if Some(id) == self.hir_id_low { - self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id)) - } - if Some(id) == self.hir_id_high { - self.span_high = Some(self.cx.tcx.hir().span(diag_expr_id)) - } - } - } - } - - fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) { - if let PlaceBase::Local(id) = cmt.place.base { - if Some(id) == self.hir_id_low { - self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id)) - } - if Some(id) == self.hir_id_high { - self.span_high = Some(self.cx.tcx.hir().span(diag_expr_id)) - } - } - } -} - -impl MutatePairDelegate<'_, '_> { - fn mutation_span(&self) -> (Option, Option) { - (self.span_low, self.span_high) - } -} - -fn check_for_mut_range_bound(cx: &LateContext<'_>, arg: &Expr<'_>, body: &Expr<'_>) { - if let Some(higher::Range { - start: Some(start), - end: Some(end), - .. - }) = higher::range(arg) - { - let mut_ids = vec![check_for_mutability(cx, start), check_for_mutability(cx, end)]; - if mut_ids[0].is_some() || mut_ids[1].is_some() { - let (span_low, span_high) = check_for_mutation(cx, body, &mut_ids); - mut_warn_with_span(cx, span_low); - mut_warn_with_span(cx, span_high); - } - } -} - -fn mut_warn_with_span(cx: &LateContext<'_>, span: Option) { - if let Some(sp) = span { - span_lint( - cx, - MUT_RANGE_BOUND, - sp, - "attempt to mutate range bound within loop; note that the range of the loop is unchanged", - ); - } -} - -fn check_for_mutability(cx: &LateContext<'_>, bound: &Expr<'_>) -> Option { - if_chain! { - if let ExprKind::Path(ref qpath) = bound.kind; - if let QPath::Resolved(None, _) = *qpath; - then { - let res = qpath_res(cx, qpath, bound.hir_id); - if let Res::Local(hir_id) = res { - let node_str = cx.tcx.hir().get(hir_id); - if_chain! { - if let Node::Binding(pat) = node_str; - if let PatKind::Binding(BindingAnnotation::Mutable, ..) = pat.kind; - then { - return Some(hir_id); - } - } - } - } - } - None -} - -fn check_for_mutation<'tcx>( - cx: &LateContext<'tcx>, - body: &Expr<'_>, - bound_ids: &[Option], -) -> (Option, Option) { - let mut delegate = MutatePairDelegate { - cx, - hir_id_low: bound_ids[0], - hir_id_high: bound_ids[1], - span_low: None, - span_high: None, - }; - cx.tcx.infer_ctxt().enter(|infcx| { - ExprUseVisitor::new( - &mut delegate, - &infcx, - body.hir_id.owner, - cx.param_env, - cx.typeck_results(), - ) - .walk_expr(body); - }); - delegate.mutation_span() -} - -/// Returns `true` if the pattern is a `PatWild` or an ident prefixed with `_`. -fn pat_is_wild<'tcx>(pat: &'tcx PatKind<'_>, body: &'tcx Expr<'_>) -> bool { - match *pat { - PatKind::Wild => true, - PatKind::Binding(.., ident, None) if ident.as_str().starts_with('_') => is_unused(&ident, body), - _ => false, - } -} - -struct VarVisitor<'a, 'tcx> { - /// context reference - cx: &'a LateContext<'tcx>, - /// var name to look for as index - var: HirId, - /// indexed variables that are used mutably - indexed_mut: FxHashSet, - /// indirectly indexed variables (`v[(i + 4) % N]`), the extend is `None` for global - indexed_indirectly: FxHashMap>, - /// subset of `indexed` of vars that are indexed directly: `v[i]` - /// this will not contain cases like `v[calc_index(i)]` or `v[(i + 4) % N]` - indexed_directly: FxHashMap, Ty<'tcx>)>, - /// Any names that are used outside an index operation. - /// Used to detect things like `&mut vec` used together with `vec[i]` - referenced: FxHashSet, - /// has the loop variable been used in expressions other than the index of - /// an index op? - nonindex: bool, - /// Whether we are inside the `$` in `&mut $` or `$ = foo` or `$.bar`, where bar - /// takes `&mut self` - prefer_mutable: bool, -} - -impl<'a, 'tcx> VarVisitor<'a, 'tcx> { - fn check(&mut self, idx: &'tcx Expr<'_>, seqexpr: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) -> bool { - if_chain! { - // the indexed container is referenced by a name - if let ExprKind::Path(ref seqpath) = seqexpr.kind; - if let QPath::Resolved(None, ref seqvar) = *seqpath; - if seqvar.segments.len() == 1; - then { - let index_used_directly = same_var(self.cx, idx, self.var); - let indexed_indirectly = { - let mut used_visitor = LocalUsedVisitor::new(self.var); - walk_expr(&mut used_visitor, idx); - used_visitor.used - }; - - if indexed_indirectly || index_used_directly { - if self.prefer_mutable { - self.indexed_mut.insert(seqvar.segments[0].ident.name); - } - let res = qpath_res(self.cx, seqpath, seqexpr.hir_id); - match res { - Res::Local(hir_id) => { - let parent_id = self.cx.tcx.hir().get_parent_item(expr.hir_id); - let parent_def_id = self.cx.tcx.hir().local_def_id(parent_id); - let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id); - if indexed_indirectly { - self.indexed_indirectly.insert(seqvar.segments[0].ident.name, Some(extent)); - } - if index_used_directly { - self.indexed_directly.insert( - seqvar.segments[0].ident.name, - (Some(extent), self.cx.typeck_results().node_type(seqexpr.hir_id)), - ); - } - return false; // no need to walk further *on the variable* - } - Res::Def(DefKind::Static | DefKind::Const, ..) => { - if indexed_indirectly { - self.indexed_indirectly.insert(seqvar.segments[0].ident.name, None); - } - if index_used_directly { - self.indexed_directly.insert( - seqvar.segments[0].ident.name, - (None, self.cx.typeck_results().node_type(seqexpr.hir_id)), - ); - } - return false; // no need to walk further *on the variable* - } - _ => (), - } - } - } - } - true - } -} - -impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if_chain! { - // a range index op - if let ExprKind::MethodCall(ref meth, _, ref args, _) = expr.kind; - if (meth.ident.name == sym::index && match_trait_method(self.cx, expr, &paths::INDEX)) - || (meth.ident.name == sym::index_mut && match_trait_method(self.cx, expr, &paths::INDEX_MUT)); - if !self.check(&args[1], &args[0], expr); - then { return } - } - - if_chain! { - // an index op - if let ExprKind::Index(ref seqexpr, ref idx) = expr.kind; - if !self.check(idx, seqexpr, expr); - then { return } - } - - if_chain! { - // directly using a variable - if let ExprKind::Path(ref qpath) = expr.kind; - if let QPath::Resolved(None, ref path) = *qpath; - if path.segments.len() == 1; - then { - if let Res::Local(local_id) = qpath_res(self.cx, qpath, expr.hir_id) { - if local_id == self.var { - self.nonindex = true; - } else { - // not the correct variable, but still a variable - self.referenced.insert(path.segments[0].ident.name); - } - } - } - } - - let old = self.prefer_mutable; - match expr.kind { - ExprKind::AssignOp(_, ref lhs, ref rhs) | ExprKind::Assign(ref lhs, ref rhs, _) => { - self.prefer_mutable = true; - self.visit_expr(lhs); - self.prefer_mutable = false; - self.visit_expr(rhs); - }, - ExprKind::AddrOf(BorrowKind::Ref, mutbl, ref expr) => { - if mutbl == Mutability::Mut { - self.prefer_mutable = true; - } - self.visit_expr(expr); - }, - ExprKind::Call(ref f, args) => { - self.visit_expr(f); - for expr in args { - let ty = self.cx.typeck_results().expr_ty_adjusted(expr); - self.prefer_mutable = false; - if let ty::Ref(_, _, mutbl) = *ty.kind() { - if mutbl == Mutability::Mut { - self.prefer_mutable = true; - } - } - self.visit_expr(expr); - } - }, - ExprKind::MethodCall(_, _, args, _) => { - let def_id = self.cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap(); - for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) { - self.prefer_mutable = false; - if let ty::Ref(_, _, mutbl) = *ty.kind() { - if mutbl == Mutability::Mut { - self.prefer_mutable = true; - } - } - self.visit_expr(expr); - } - }, - ExprKind::Closure(_, _, body_id, ..) => { - let body = self.cx.tcx.hir().body(body_id); - self.visit_expr(&body.value); - }, - _ => walk_expr(self, expr), - } - self.prefer_mutable = old; - } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -fn is_used_inside<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, container: &'tcx Expr<'_>) -> bool { - let def_id = match var_def_id(cx, expr) { - Some(id) => id, - None => return false, - }; - if let Some(used_mutably) = mutated_variables(container, cx) { - if used_mutably.contains(&def_id) { - return true; - } - } - false -} - -fn is_iterator_used_after_while_let<'tcx>(cx: &LateContext<'tcx>, iter_expr: &'tcx Expr<'_>) -> bool { - let def_id = match var_def_id(cx, iter_expr) { - Some(id) => id, - None => return false, - }; - let mut visitor = VarUsedAfterLoopVisitor { - cx, - def_id, - iter_expr_id: iter_expr.hir_id, - past_while_let: false, - var_used_after_while_let: false, - }; - if let Some(enclosing_block) = get_enclosing_block(cx, def_id) { - walk_block(&mut visitor, enclosing_block); - } - visitor.var_used_after_while_let -} - -struct VarUsedAfterLoopVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - def_id: HirId, - iter_expr_id: HirId, - past_while_let: bool, - var_used_after_while_let: bool, -} - -impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if self.past_while_let { - if Some(self.def_id) == var_def_id(self.cx, expr) { - self.var_used_after_while_let = true; - } - } else if self.iter_expr_id == expr.hir_id { - self.past_while_let = true; - } - walk_expr(self, expr); - } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -/// Returns `true` if the type of expr is one that provides `IntoIterator` impls -/// for `&T` and `&mut T`, such as `Vec`. -#[rustfmt::skip] -fn is_ref_iterable_type(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { - // no walk_ptrs_ty: calling iter() on a reference can make sense because it - // will allow further borrows afterwards - let ty = cx.typeck_results().expr_ty(e); - is_iterable_array(ty, cx) || - is_type_diagnostic_item(cx, ty, sym::vec_type) || - match_type(cx, ty, &paths::LINKED_LIST) || - is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) || - is_type_diagnostic_item(cx, ty, sym!(hashset_type)) || - is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) || - match_type(cx, ty, &paths::BINARY_HEAP) || - match_type(cx, ty, &paths::BTREEMAP) || - match_type(cx, ty, &paths::BTREESET) -} - -fn is_iterable_array<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool { - // IntoIterator is currently only implemented for array sizes <= 32 in rustc - match ty.kind() { - ty::Array(_, n) => n - .try_eval_usize(cx.tcx, cx.param_env) - .map_or(false, |val| (0..=32).contains(&val)), - _ => false, - } -} - -/// If a block begins with a statement (possibly a `let` binding) and has an -/// expression, return it. -fn extract_expr_from_first_stmt<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<'tcx>> { - if block.stmts.is_empty() { - return None; - } - if let StmtKind::Local(ref local) = block.stmts[0].kind { - local.init //.map(|expr| expr) - } else { - None - } -} - -/// If a block begins with an expression (with or without semicolon), return it. -fn extract_first_expr<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<'tcx>> { - match block.expr { - Some(ref expr) if block.stmts.is_empty() => Some(expr), - None if !block.stmts.is_empty() => match block.stmts[0].kind { - StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => Some(expr), - StmtKind::Local(..) | StmtKind::Item(..) => None, - }, - _ => None, - } -} - -/// Returns `true` if expr contains a single break expr without destination label -/// and -/// passed expression. The expression may be within a block. -fn is_simple_break_expr(expr: &Expr<'_>) -> bool { - match expr.kind { - ExprKind::Break(dest, ref passed_expr) if dest.label.is_none() && passed_expr.is_none() => true, - ExprKind::Block(ref b, _) => extract_first_expr(b).map_or(false, |subexpr| is_simple_break_expr(subexpr)), - _ => false, - } -} - -#[derive(Debug, PartialEq)] -enum IncrementVisitorVarState { - Initial, // Not examined yet - IncrOnce, // Incremented exactly once, may be a loop counter - DontWarn, -} - -/// Scan a for loop for variables that are incremented exactly once and not used after that. -struct IncrementVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, // context reference - states: FxHashMap, // incremented variables - depth: u32, // depth of conditional expressions - done: bool, -} - -impl<'a, 'tcx> IncrementVisitor<'a, 'tcx> { - fn new(cx: &'a LateContext<'tcx>) -> Self { - Self { - cx, - states: FxHashMap::default(), - depth: 0, - done: false, - } - } - - fn into_results(self) -> impl Iterator { - self.states.into_iter().filter_map(|(id, state)| { - if state == IncrementVisitorVarState::IncrOnce { - Some(id) - } else { - None - } - }) - } -} - -impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if self.done { - return; - } - - // If node is a variable - if let Some(def_id) = var_def_id(self.cx, expr) { - if let Some(parent) = get_parent_expr(self.cx, expr) { - let state = self.states.entry(def_id).or_insert(IncrementVisitorVarState::Initial); - if *state == IncrementVisitorVarState::IncrOnce { - *state = IncrementVisitorVarState::DontWarn; - return; - } - - match parent.kind { - ExprKind::AssignOp(op, ref lhs, ref rhs) => { - if lhs.hir_id == expr.hir_id { - *state = if op.node == BinOpKind::Add - && is_integer_const(self.cx, rhs, 1) - && *state == IncrementVisitorVarState::Initial - && self.depth == 0 - { - IncrementVisitorVarState::IncrOnce - } else { - // Assigned some other value or assigned multiple times - IncrementVisitorVarState::DontWarn - }; - } - }, - ExprKind::Assign(ref lhs, _, _) if lhs.hir_id == expr.hir_id => { - *state = IncrementVisitorVarState::DontWarn - }, - ExprKind::AddrOf(BorrowKind::Ref, mutability, _) if mutability == Mutability::Mut => { - *state = IncrementVisitorVarState::DontWarn - }, - _ => (), - } - } - - walk_expr(self, expr); - } else if is_loop(expr) || is_conditional(expr) { - self.depth += 1; - walk_expr(self, expr); - self.depth -= 1; - } else if let ExprKind::Continue(_) = expr.kind { - self.done = true; - } else { - walk_expr(self, expr); - } - } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -enum InitializeVisitorState<'hir> { - Initial, // Not examined yet - Declared(Symbol), // Declared but not (yet) initialized - Initialized { - name: Symbol, - initializer: &'hir Expr<'hir>, - }, - DontWarn, -} - -/// Checks whether a variable is initialized at the start of a loop and not modified -/// and used after the loop. -struct InitializeVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, // context reference - end_expr: &'tcx Expr<'tcx>, // the for loop. Stop scanning here. - var_id: HirId, - state: InitializeVisitorState<'tcx>, - depth: u32, // depth of conditional expressions - past_loop: bool, -} - -impl<'a, 'tcx> InitializeVisitor<'a, 'tcx> { - fn new(cx: &'a LateContext<'tcx>, end_expr: &'tcx Expr<'tcx>, var_id: HirId) -> Self { - Self { - cx, - end_expr, - var_id, - state: InitializeVisitorState::Initial, - depth: 0, - past_loop: false, - } - } - - fn get_result(&self) -> Option<(Symbol, &'tcx Expr<'tcx>)> { - if let InitializeVisitorState::Initialized { name, initializer } = self.state { - Some((name, initializer)) - } else { - None - } - } -} - -impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { - // Look for declarations of the variable - if_chain! { - if let StmtKind::Local(ref local) = stmt.kind; - if local.pat.hir_id == self.var_id; - if let PatKind::Binding(.., ident, _) = local.pat.kind; - then { - self.state = local.init.map_or(InitializeVisitorState::Declared(ident.name), |init| { - InitializeVisitorState::Initialized { - initializer: init, - name: ident.name, - } - }) - } - } - walk_stmt(self, stmt); - } - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if matches!(self.state, InitializeVisitorState::DontWarn) { - return; - } - if expr.hir_id == self.end_expr.hir_id { - self.past_loop = true; - return; - } - // No need to visit expressions before the variable is - // declared - if matches!(self.state, InitializeVisitorState::Initial) { - return; - } - - // If node is the desired variable, see how it's used - if var_def_id(self.cx, expr) == Some(self.var_id) { - if self.past_loop { - self.state = InitializeVisitorState::DontWarn; - return; - } - - if let Some(parent) = get_parent_expr(self.cx, expr) { - match parent.kind { - ExprKind::AssignOp(_, ref lhs, _) if lhs.hir_id == expr.hir_id => { - self.state = InitializeVisitorState::DontWarn; - }, - ExprKind::Assign(ref lhs, ref rhs, _) if lhs.hir_id == expr.hir_id => { - self.state = if_chain! { - if self.depth == 0; - if let InitializeVisitorState::Declared(name) - | InitializeVisitorState::Initialized { name, ..} = self.state; - then { - InitializeVisitorState::Initialized { initializer: rhs, name } - } else { - InitializeVisitorState::DontWarn - } - } - }, - ExprKind::AddrOf(BorrowKind::Ref, mutability, _) if mutability == Mutability::Mut => { - self.state = InitializeVisitorState::DontWarn - }, - _ => (), - } - } - - walk_expr(self, expr); - } else if !self.past_loop && is_loop(expr) { - self.state = InitializeVisitorState::DontWarn; - } else if is_conditional(expr) { - self.depth += 1; - walk_expr(self, expr); - self.depth -= 1; - } else { - walk_expr(self, expr); - } - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) - } -} - -fn var_def_id(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { - if let ExprKind::Path(ref qpath) = expr.kind { - let path_res = qpath_res(cx, qpath, expr.hir_id); - if let Res::Local(hir_id) = path_res { - return Some(hir_id); - } - } - None -} - -fn is_loop(expr: &Expr<'_>) -> bool { - matches!(expr.kind, ExprKind::Loop(..)) -} - -fn is_conditional(expr: &Expr<'_>) -> bool { - matches!(expr.kind, ExprKind::Match(..)) -} - -fn is_nested(cx: &LateContext<'_>, match_expr: &Expr<'_>, iter_expr: &Expr<'_>) -> bool { - if_chain! { - if let Some(loop_block) = get_enclosing_block(cx, match_expr.hir_id); - let parent_node = cx.tcx.hir().get_parent_node(loop_block.hir_id); - if let Some(Node::Expr(loop_expr)) = cx.tcx.hir().find(parent_node); - then { - return is_loop_nested(cx, loop_expr, iter_expr) - } - } - false -} - -fn is_loop_nested(cx: &LateContext<'_>, loop_expr: &Expr<'_>, iter_expr: &Expr<'_>) -> bool { - let mut id = loop_expr.hir_id; - let iter_name = if let Some(name) = path_name(iter_expr) { - name - } else { - return true; - }; - loop { - let parent = cx.tcx.hir().get_parent_node(id); - if parent == id { - return false; - } - match cx.tcx.hir().find(parent) { - Some(Node::Expr(expr)) => { - if let ExprKind::Loop(..) = expr.kind { - return true; - }; - }, - Some(Node::Block(block)) => { - let mut block_visitor = LoopNestVisitor { - hir_id: id, - iterator: iter_name, - nesting: Unknown, - }; - walk_block(&mut block_visitor, block); - if block_visitor.nesting == RuledOut { - return false; - } - }, - Some(Node::Stmt(_)) => (), - _ => { - return false; - }, - } - id = parent; - } -} - -#[derive(PartialEq, Eq)] -enum Nesting { - Unknown, // no nesting detected yet - RuledOut, // the iterator is initialized or assigned within scope - LookFurther, // no nesting detected, no further walk required -} - -use self::Nesting::{LookFurther, RuledOut, Unknown}; - -struct LoopNestVisitor { - hir_id: HirId, - iterator: Symbol, - nesting: Nesting, -} - -impl<'tcx> Visitor<'tcx> for LoopNestVisitor { - type Map = Map<'tcx>; - - fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { - if stmt.hir_id == self.hir_id { - self.nesting = LookFurther; - } else if self.nesting == Unknown { - walk_stmt(self, stmt); - } - } - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if self.nesting != Unknown { - return; - } - if expr.hir_id == self.hir_id { - self.nesting = LookFurther; - return; - } - match expr.kind { - ExprKind::Assign(ref path, _, _) | ExprKind::AssignOp(_, ref path, _) => { - if match_var(path, self.iterator) { - self.nesting = RuledOut; - } - }, - _ => walk_expr(self, expr), - } - } - - fn visit_pat(&mut self, pat: &'tcx Pat<'_>) { - if self.nesting != Unknown { - return; - } - if let PatKind::Binding(.., span_name, _) = pat.kind { - if self.iterator == span_name.name { - self.nesting = RuledOut; - return; - } - } - walk_pat(self, pat) - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -fn path_name(e: &Expr<'_>) -> Option { - if let ExprKind::Path(QPath::Resolved(_, ref path)) = e.kind { - let segments = &path.segments; - if segments.len() == 1 { - return Some(segments[0].ident.name); - } - }; - None -} - -fn check_infinite_loop<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) { - if constant(cx, cx.typeck_results(), cond).is_some() { - // A pure constant condition (e.g., `while false`) is not linted. - return; - } - - let mut var_visitor = VarCollectorVisitor { - cx, - ids: FxHashSet::default(), - def_ids: FxHashMap::default(), - skip: false, - }; - var_visitor.visit_expr(cond); - if var_visitor.skip { - return; - } - let used_in_condition = &var_visitor.ids; - let no_cond_variable_mutated = if let Some(used_mutably) = mutated_variables(expr, cx) { - used_in_condition.is_disjoint(&used_mutably) - } else { - return; - }; - let mutable_static_in_cond = var_visitor.def_ids.iter().any(|(_, v)| *v); - - let mut has_break_or_return_visitor = HasBreakOrReturnVisitor { - has_break_or_return: false, - }; - has_break_or_return_visitor.visit_expr(expr); - let has_break_or_return = has_break_or_return_visitor.has_break_or_return; - - if no_cond_variable_mutated && !mutable_static_in_cond { - span_lint_and_then( - cx, - WHILE_IMMUTABLE_CONDITION, - cond.span, - "variables in the condition are not mutated in the loop body", - |diag| { - diag.note("this may lead to an infinite or to a never running loop"); - - if has_break_or_return { - diag.note("this loop contains `return`s or `break`s"); - diag.help("rewrite it as `if cond { loop { } }`"); - } - }, - ); - } -} - -struct HasBreakOrReturnVisitor { - has_break_or_return: bool, -} - -impl<'tcx> Visitor<'tcx> for HasBreakOrReturnVisitor { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if self.has_break_or_return { - return; - } - - match expr.kind { - ExprKind::Ret(_) | ExprKind::Break(_, _) => { - self.has_break_or_return = true; - return; - }, - _ => {}, - } - - walk_expr(self, expr); - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -/// Collects the set of variables in an expression -/// Stops analysis if a function call is found -/// Note: In some cases such as `self`, there are no mutable annotation, -/// All variables definition IDs are collected -struct VarCollectorVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - ids: FxHashSet, - def_ids: FxHashMap, - skip: bool, -} - -impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> { - fn insert_def_id(&mut self, ex: &'tcx Expr<'_>) { - if_chain! { - if let ExprKind::Path(ref qpath) = ex.kind; - if let QPath::Resolved(None, _) = *qpath; - let res = qpath_res(self.cx, qpath, ex.hir_id); - then { - match res { - Res::Local(hir_id) => { - self.ids.insert(hir_id); - }, - Res::Def(DefKind::Static, def_id) => { - let mutable = self.cx.tcx.is_mutable_static(def_id); - self.def_ids.insert(def_id, mutable); - }, - _ => {}, - } - } - } - } -} - -impl<'a, 'tcx> Visitor<'tcx> for VarCollectorVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, ex: &'tcx Expr<'_>) { - match ex.kind { - ExprKind::Path(_) => self.insert_def_id(ex), - // If there is any function/method call… we just stop analysis - ExprKind::Call(..) | ExprKind::MethodCall(..) => self.skip = true, - - _ => walk_expr(self, ex), - } - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -const NEEDLESS_COLLECT_MSG: &str = "avoid using `collect()` when not needed"; - -fn check_needless_collect<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) { - check_needless_collect_direct_usage(expr, cx); - check_needless_collect_indirect_usage(expr, cx); -} -fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) { - if_chain! { - if let ExprKind::MethodCall(ref method, _, ref args, _) = expr.kind; - if let ExprKind::MethodCall(ref chain_method, _, _, _) = args[0].kind; - if chain_method.ident.name == sym!(collect) && match_trait_method(cx, &args[0], &paths::ITERATOR); - if let Some(ref generic_args) = chain_method.args; - if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0); - then { - let ty = cx.typeck_results().node_type(ty.hir_id); - if is_type_diagnostic_item(cx, ty, sym::vec_type) || - is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) || - match_type(cx, ty, &paths::BTREEMAP) || - is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) { - if method.ident.name == sym!(len) { - let span = shorten_needless_collect_span(expr); - span_lint_and_sugg( - cx, - NEEDLESS_COLLECT, - span, - NEEDLESS_COLLECT_MSG, - "replace with", - "count()".to_string(), - Applicability::MachineApplicable, - ); - } - if method.ident.name == sym!(is_empty) { - let span = shorten_needless_collect_span(expr); - span_lint_and_sugg( - cx, - NEEDLESS_COLLECT, - span, - NEEDLESS_COLLECT_MSG, - "replace with", - "next().is_none()".to_string(), - Applicability::MachineApplicable, - ); - } - if method.ident.name == sym!(contains) { - let contains_arg = snippet(cx, args[1].span, "??"); - let span = shorten_needless_collect_span(expr); - span_lint_and_then( - cx, - NEEDLESS_COLLECT, - span, - NEEDLESS_COLLECT_MSG, - |diag| { - let (arg, pred) = contains_arg - .strip_prefix('&') - .map_or(("&x", &*contains_arg), |s| ("x", s)); - diag.span_suggestion( - span, - "replace with", - format!( - "any(|{}| x == {})", - arg, pred - ), - Applicability::MachineApplicable, - ); - } - ); - } - } - } - } -} - -fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) { - if let ExprKind::Block(ref block, _) = expr.kind { - for ref stmt in block.stmts { - if_chain! { - if let StmtKind::Local( - Local { pat: Pat { hir_id: pat_id, kind: PatKind::Binding(_, _, ident, .. ), .. }, - init: Some(ref init_expr), .. } - ) = stmt.kind; - if let ExprKind::MethodCall(ref method_name, _, &[ref iter_source], ..) = init_expr.kind; - if method_name.ident.name == sym!(collect) && match_trait_method(cx, &init_expr, &paths::ITERATOR); - if let Some(ref generic_args) = method_name.args; - if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0); - if let ty = cx.typeck_results().node_type(ty.hir_id); - if is_type_diagnostic_item(cx, ty, sym::vec_type) || - is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) || - match_type(cx, ty, &paths::LINKED_LIST); - if let Some(iter_calls) = detect_iter_and_into_iters(block, *ident); - if iter_calls.len() == 1; - then { - let mut used_count_visitor = UsedCountVisitor { - cx, - id: *pat_id, - count: 0, - }; - walk_block(&mut used_count_visitor, block); - if used_count_visitor.count > 1 { - return; - } - - // Suggest replacing iter_call with iter_replacement, and removing stmt - let iter_call = &iter_calls[0]; - span_lint_and_then( - cx, - NEEDLESS_COLLECT, - stmt.span.until(iter_call.span), - NEEDLESS_COLLECT_MSG, - |diag| { - let iter_replacement = format!("{}{}", Sugg::hir(cx, iter_source, ".."), iter_call.get_iter_method(cx)); - diag.multipart_suggestion( - iter_call.get_suggestion_text(), - vec![ - (stmt.span, String::new()), - (iter_call.span, iter_replacement) - ], - Applicability::MachineApplicable,// MaybeIncorrect, - ).emit(); - }, - ); - } - } - } - } -} - -struct IterFunction { - func: IterFunctionKind, - span: Span, -} -impl IterFunction { - fn get_iter_method(&self, cx: &LateContext<'_>) -> String { - match &self.func { - IterFunctionKind::IntoIter => String::new(), - IterFunctionKind::Len => String::from(".count()"), - IterFunctionKind::IsEmpty => String::from(".next().is_none()"), - IterFunctionKind::Contains(span) => { - let s = snippet(cx, *span, ".."); - if let Some(stripped) = s.strip_prefix('&') { - format!(".any(|x| x == {})", stripped) - } else { - format!(".any(|x| x == *{})", s) - } - }, - } - } - fn get_suggestion_text(&self) -> &'static str { - match &self.func { - IterFunctionKind::IntoIter => { - "Use the original Iterator instead of collecting it and then producing a new one" - }, - IterFunctionKind::Len => { - "Take the original Iterator's count instead of collecting it and finding the length" - }, - IterFunctionKind::IsEmpty => { - "Check if the original Iterator has anything instead of collecting it and seeing if it's empty" - }, - IterFunctionKind::Contains(_) => { - "Check if the original Iterator contains an element instead of collecting then checking" - }, - } - } -} -enum IterFunctionKind { - IntoIter, - Len, - IsEmpty, - Contains(Span), -} - -struct IterFunctionVisitor { - uses: Vec, - seen_other: bool, - target: Ident, -} -impl<'tcx> Visitor<'tcx> for IterFunctionVisitor { - fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { - // Check function calls on our collection - if_chain! { - if let ExprKind::MethodCall(method_name, _, ref args, _) = &expr.kind; - if let Some(Expr { kind: ExprKind::Path(QPath::Resolved(_, ref path)), .. }) = args.get(0); - if let &[name] = &path.segments; - if name.ident == self.target; - then { - let len = sym!(len); - let is_empty = sym!(is_empty); - let contains = sym!(contains); - match method_name.ident.name { - sym::into_iter => self.uses.push( - IterFunction { func: IterFunctionKind::IntoIter, span: expr.span } - ), - name if name == len => self.uses.push( - IterFunction { func: IterFunctionKind::Len, span: expr.span } - ), - name if name == is_empty => self.uses.push( - IterFunction { func: IterFunctionKind::IsEmpty, span: expr.span } - ), - name if name == contains => self.uses.push( - IterFunction { func: IterFunctionKind::Contains(args[1].span), span: expr.span } - ), - _ => self.seen_other = true, - } - return - } - } - // Check if the collection is used for anything else - if_chain! { - if let Expr { kind: ExprKind::Path(QPath::Resolved(_, ref path)), .. } = expr; - if let &[name] = &path.segments; - if name.ident == self.target; - then { - self.seen_other = true; - } else { - walk_expr(self, expr); - } - } - } - - type Map = Map<'tcx>; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -struct UsedCountVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - id: HirId, - count: usize, -} - -impl<'a, 'tcx> Visitor<'tcx> for UsedCountVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if same_var(self.cx, expr, self.id) { - self.count += 1; - } else { - walk_expr(self, expr); - } - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) - } -} - -/// Detect the occurrences of calls to `iter` or `into_iter` for the -/// given identifier -fn detect_iter_and_into_iters<'tcx>(block: &'tcx Block<'tcx>, identifier: Ident) -> Option> { - let mut visitor = IterFunctionVisitor { - uses: Vec::new(), - target: identifier, - seen_other: false, - }; - visitor.visit_block(block); - if visitor.seen_other { - None - } else { - Some(visitor.uses) - } -} - -fn shorten_needless_collect_span(expr: &Expr<'_>) -> Span { - if_chain! { - if let ExprKind::MethodCall(.., args, _) = &expr.kind; - if let ExprKind::MethodCall(_, span, ..) = &args[0].kind; - then { - return expr.span.with_lo(span.lo()); - } - } - unreachable!(); -} diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs deleted file mode 100644 index b4b4b3dc18d5..000000000000 --- a/clippy_lints/src/macro_use.rs +++ /dev/null @@ -1,232 +0,0 @@ -use crate::utils::{in_macro, snippet, span_lint_and_sugg}; -use hir::def::{DefKind, Res}; -use if_chain::if_chain; -use rustc_ast::ast; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::{edition::Edition, Span}; - -declare_clippy_lint! { - /// **What it does:** Checks for `#[macro_use] use...`. - /// - /// **Why is this bad?** Since the Rust 2018 edition you can import - /// macro's directly, this is considered idiomatic. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// #[macro_use] - /// use some_macro; - /// ``` - pub MACRO_USE_IMPORTS, - pedantic, - "#[macro_use] is no longer needed" -} - -const BRACKETS: &[char] = &['<', '>']; - -#[derive(Clone, Debug, PartialEq, Eq)] -struct PathAndSpan { - path: String, - span: Span, -} - -/// `MacroRefData` includes the name of the macro -/// and the path from `SourceMap::span_to_filename`. -#[derive(Debug, Clone)] -pub struct MacroRefData { - name: String, - path: String, -} - -impl MacroRefData { - pub fn new(name: String, callee: Span, cx: &LateContext<'_>) -> Self { - let mut path = cx.sess().source_map().span_to_filename(callee).to_string(); - - // std lib paths are <::std::module::file type> - // so remove brackets, space and type. - if path.contains('<') { - path = path.replace(BRACKETS, ""); - } - if path.contains(' ') { - path = path.split(' ').next().unwrap().to_string(); - } - Self { name, path } - } -} - -#[derive(Default)] -#[allow(clippy::module_name_repetitions)] -pub struct MacroUseImports { - /// the actual import path used and the span of the attribute above it. - imports: Vec<(String, Span)>, - /// the span of the macro reference, kept to ensure only one reference is used per macro call. - collected: FxHashSet, - mac_refs: Vec, -} - -impl_lint_pass!(MacroUseImports => [MACRO_USE_IMPORTS]); - -impl MacroUseImports { - fn push_unique_macro(&mut self, cx: &LateContext<'_>, span: Span) { - let call_site = span.source_callsite(); - let name = snippet(cx, cx.sess().source_map().span_until_char(call_site, '!'), "_"); - if let Some(callee) = span.source_callee() { - if !self.collected.contains(&call_site) { - let name = if name.contains("::") { - name.split("::").last().unwrap().to_string() - } else { - name.to_string() - }; - - self.mac_refs.push(MacroRefData::new(name, callee.def_site, cx)); - self.collected.insert(call_site); - } - } - } - - fn push_unique_macro_pat_ty(&mut self, cx: &LateContext<'_>, span: Span) { - let call_site = span.source_callsite(); - let name = snippet(cx, cx.sess().source_map().span_until_char(call_site, '!'), "_"); - if let Some(callee) = span.source_callee() { - if !self.collected.contains(&call_site) { - self.mac_refs - .push(MacroRefData::new(name.to_string(), callee.def_site, cx)); - self.collected.insert(call_site); - } - } - } -} - -impl<'tcx> LateLintPass<'tcx> for MacroUseImports { - fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) { - if_chain! { - if cx.sess().opts.edition == Edition::Edition2018; - if let hir::ItemKind::Use(path, _kind) = &item.kind; - if let Some(mac_attr) = item - .attrs - .iter() - .find(|attr| attr.ident().map(|s| s.to_string()) == Some("macro_use".to_string())); - if let Res::Def(DefKind::Mod, id) = path.res; - then { - for kid in cx.tcx.item_children(id).iter() { - if let Res::Def(DefKind::Macro(_mac_type), mac_id) = kid.res { - let span = mac_attr.span; - let def_path = cx.tcx.def_path_str(mac_id); - self.imports.push((def_path, span)); - } - } - } else { - if in_macro(item.span) { - self.push_unique_macro_pat_ty(cx, item.span); - } - } - } - } - fn check_attribute(&mut self, cx: &LateContext<'_>, attr: &ast::Attribute) { - if in_macro(attr.span) { - self.push_unique_macro(cx, attr.span); - } - } - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) { - if in_macro(expr.span) { - self.push_unique_macro(cx, expr.span); - } - } - fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &hir::Stmt<'_>) { - if in_macro(stmt.span) { - self.push_unique_macro(cx, stmt.span); - } - } - fn check_pat(&mut self, cx: &LateContext<'_>, pat: &hir::Pat<'_>) { - if in_macro(pat.span) { - self.push_unique_macro_pat_ty(cx, pat.span); - } - } - fn check_ty(&mut self, cx: &LateContext<'_>, ty: &hir::Ty<'_>) { - if in_macro(ty.span) { - self.push_unique_macro_pat_ty(cx, ty.span); - } - } - #[allow(clippy::too_many_lines)] - fn check_crate_post(&mut self, cx: &LateContext<'_>, _krate: &hir::Crate<'_>) { - let mut used = FxHashMap::default(); - let mut check_dup = vec![]; - for (import, span) in &self.imports { - let found_idx = self.mac_refs.iter().position(|mac| import.ends_with(&mac.name)); - - if let Some(idx) = found_idx { - let _ = self.mac_refs.remove(idx); - let seg = import.split("::").collect::>(); - - match seg.as_slice() { - // an empty path is impossible - // a path should always consist of 2 or more segments - [] | [_] => return, - [root, item] => { - if !check_dup.contains(&(*item).to_string()) { - used.entry(((*root).to_string(), span)) - .or_insert_with(Vec::new) - .push((*item).to_string()); - check_dup.push((*item).to_string()); - } - }, - [root, rest @ ..] => { - if rest.iter().all(|item| !check_dup.contains(&(*item).to_string())) { - let filtered = rest - .iter() - .filter_map(|item| { - if check_dup.contains(&(*item).to_string()) { - None - } else { - Some((*item).to_string()) - } - }) - .collect::>(); - used.entry(((*root).to_string(), span)) - .or_insert_with(Vec::new) - .push(filtered.join("::")); - check_dup.extend(filtered); - } else { - let rest = rest.to_vec(); - used.entry(((*root).to_string(), span)) - .or_insert_with(Vec::new) - .push(rest.join("::")); - check_dup.extend(rest.iter().map(ToString::to_string)); - } - }, - } - } - } - - let mut suggestions = vec![]; - for ((root, span), path) in used { - if path.len() == 1 { - suggestions.push((span, format!("{}::{}", root, path[0]))) - } else { - suggestions.push((span, format!("{}::{{{}}}", root, path.join(", ")))) - } - } - - // If mac_refs is not empty we have encountered an import we could not handle - // such as `std::prelude::v1::foo` or some other macro that expands to an import. - if self.mac_refs.is_empty() { - for (span, import) in suggestions { - let help = format!("use {};", import); - span_lint_and_sugg( - cx, - MACRO_USE_IMPORTS, - *span, - "`macro_use` attributes are no longer needed in the Rust 2018 edition", - "remove the attribute and import the macro directly, try", - help, - Applicability::MaybeIncorrect, - ) - } - } - } -} diff --git a/clippy_lints/src/main_recursion.rs b/clippy_lints/src/main_recursion.rs deleted file mode 100644 index eceae706e4fc..000000000000 --- a/clippy_lints/src/main_recursion.rs +++ /dev/null @@ -1,62 +0,0 @@ -use rustc_hir::{Crate, Expr, ExprKind, QPath}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; - -use crate::utils::{is_entrypoint_fn, is_no_std_crate, snippet, span_lint_and_help}; -use if_chain::if_chain; - -declare_clippy_lint! { - /// **What it does:** Checks for recursion using the entrypoint. - /// - /// **Why is this bad?** Apart from special setups (which we could detect following attributes like #![no_std]), - /// recursing into main() seems like an unintuitive antipattern we should be able to detect. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```no_run - /// fn main() { - /// main(); - /// } - /// ``` - pub MAIN_RECURSION, - style, - "recursion using the entrypoint" -} - -#[derive(Default)] -pub struct MainRecursion { - has_no_std_attr: bool, -} - -impl_lint_pass!(MainRecursion => [MAIN_RECURSION]); - -impl LateLintPass<'_> for MainRecursion { - fn check_crate(&mut self, _: &LateContext<'_>, krate: &Crate<'_>) { - self.has_no_std_attr = is_no_std_crate(krate); - } - - fn check_expr_post(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - if self.has_no_std_attr { - return; - } - - if_chain! { - if let ExprKind::Call(func, _) = &expr.kind; - if let ExprKind::Path(path) = &func.kind; - if let QPath::Resolved(_, path) = &path; - if let Some(def_id) = path.res.opt_def_id(); - if is_entrypoint_fn(cx, def_id); - then { - span_lint_and_help( - cx, - MAIN_RECURSION, - func.span, - &format!("recursing into entrypoint `{}`", snippet(cx, func.span, "main")), - None, - "consider using another function for this recursion" - ) - } - } - } -} diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs deleted file mode 100644 index 7b3b450ef93e..000000000000 --- a/clippy_lints/src/manual_async_fn.rs +++ /dev/null @@ -1,200 +0,0 @@ -use crate::utils::paths::FUTURE_FROM_GENERATOR; -use crate::utils::{match_function_call, position_before_rarrow, snippet_block, snippet_opt, span_lint_and_then}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::intravisit::FnKind; -use rustc_hir::{ - AsyncGeneratorKind, Block, Body, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound, HirId, - IsAsync, ItemKind, LifetimeName, TraitRef, Ty, TyKind, TypeBindingKind, -}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::Span; - -declare_clippy_lint! { - /// **What it does:** It checks for manual implementations of `async` functions. - /// - /// **Why is this bad?** It's more idiomatic to use the dedicated syntax. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// use std::future::Future; - /// - /// fn foo() -> impl Future { async { 42 } } - /// ``` - /// Use instead: - /// ```rust - /// async fn foo() -> i32 { 42 } - /// ``` - pub MANUAL_ASYNC_FN, - style, - "manual implementations of `async` functions can be simplified using the dedicated syntax" -} - -declare_lint_pass!(ManualAsyncFn => [MANUAL_ASYNC_FN]); - -impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn { - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - kind: FnKind<'tcx>, - decl: &'tcx FnDecl<'_>, - body: &'tcx Body<'_>, - span: Span, - _: HirId, - ) { - if_chain! { - if let Some(header) = kind.header(); - if let IsAsync::NotAsync = header.asyncness; - // Check that this function returns `impl Future` - if let FnRetTy::Return(ret_ty) = decl.output; - if let Some((trait_ref, output_lifetimes)) = future_trait_ref(cx, ret_ty); - if let Some(output) = future_output_ty(trait_ref); - if captures_all_lifetimes(decl.inputs, &output_lifetimes); - // Check that the body of the function consists of one async block - if let ExprKind::Block(block, _) = body.value.kind; - if block.stmts.is_empty(); - if let Some(closure_body) = desugared_async_block(cx, block); - then { - let header_span = span.with_hi(ret_ty.span.hi()); - - span_lint_and_then( - cx, - MANUAL_ASYNC_FN, - header_span, - "this function can be simplified using the `async fn` syntax", - |diag| { - if_chain! { - if let Some(header_snip) = snippet_opt(cx, header_span); - if let Some(ret_pos) = position_before_rarrow(header_snip.clone()); - if let Some((ret_sugg, ret_snip)) = suggested_ret(cx, output); - then { - let help = format!("make the function `async` and {}", ret_sugg); - diag.span_suggestion( - header_span, - &help, - format!("async {}{}", &header_snip[..ret_pos], ret_snip), - Applicability::MachineApplicable - ); - - let body_snip = snippet_block(cx, closure_body.value.span, "..", Some(block.span)); - diag.span_suggestion( - block.span, - "move the body of the async block to the enclosing function", - body_snip.to_string(), - Applicability::MachineApplicable - ); - } - } - }, - ); - } - } - } -} - -fn future_trait_ref<'tcx>( - cx: &LateContext<'tcx>, - ty: &'tcx Ty<'tcx>, -) -> Option<(&'tcx TraitRef<'tcx>, Vec)> { - if_chain! { - if let TyKind::OpaqueDef(item_id, bounds) = ty.kind; - let item = cx.tcx.hir().item(item_id.id); - if let ItemKind::OpaqueTy(opaque) = &item.kind; - if let Some(trait_ref) = opaque.bounds.iter().find_map(|bound| { - if let GenericBound::Trait(poly, _) = bound { - Some(&poly.trait_ref) - } else { - None - } - }); - if trait_ref.trait_def_id() == cx.tcx.lang_items().future_trait(); - then { - let output_lifetimes = bounds - .iter() - .filter_map(|bound| { - if let GenericArg::Lifetime(lt) = bound { - Some(lt.name) - } else { - None - } - }) - .collect(); - - return Some((trait_ref, output_lifetimes)); - } - } - - None -} - -fn future_output_ty<'tcx>(trait_ref: &'tcx TraitRef<'tcx>) -> Option<&'tcx Ty<'tcx>> { - if_chain! { - if let Some(segment) = trait_ref.path.segments.last(); - if let Some(args) = segment.args; - if args.bindings.len() == 1; - let binding = &args.bindings[0]; - if binding.ident.as_str() == "Output"; - if let TypeBindingKind::Equality{ty: output} = binding.kind; - then { - return Some(output) - } - } - - None -} - -fn captures_all_lifetimes(inputs: &[Ty<'_>], output_lifetimes: &[LifetimeName]) -> bool { - let input_lifetimes: Vec = inputs - .iter() - .filter_map(|ty| { - if let TyKind::Rptr(lt, _) = ty.kind { - Some(lt.name) - } else { - None - } - }) - .collect(); - - // The lint should trigger in one of these cases: - // - There are no input lifetimes - // - There's only one output lifetime bound using `+ '_` - // - All input lifetimes are explicitly bound to the output - input_lifetimes.is_empty() - || (output_lifetimes.len() == 1 && matches!(output_lifetimes[0], LifetimeName::Underscore)) - || input_lifetimes - .iter() - .all(|in_lt| output_lifetimes.iter().any(|out_lt| in_lt == out_lt)) -} - -fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) -> Option<&'tcx Body<'tcx>> { - if_chain! { - if let Some(block_expr) = block.expr; - if let Some(args) = match_function_call(cx, block_expr, &FUTURE_FROM_GENERATOR); - if args.len() == 1; - if let Expr{kind: ExprKind::Closure(_, _, body_id, ..), ..} = args[0]; - let closure_body = cx.tcx.hir().body(body_id); - if let Some(GeneratorKind::Async(AsyncGeneratorKind::Block)) = closure_body.generator_kind; - then { - return Some(closure_body); - } - } - - None -} - -fn suggested_ret(cx: &LateContext<'_>, output: &Ty<'_>) -> Option<(&'static str, String)> { - match output.kind { - TyKind::Tup(tys) if tys.is_empty() => { - let sugg = "remove the return type"; - Some((sugg, "".into())) - }, - _ => { - let sugg = "return the output of the future directly"; - snippet_opt(cx, output.span).map(|snip| (sugg, format!(" -> {}", snip))) - }, - } -} diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs deleted file mode 100644 index 91849e748878..000000000000 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ /dev/null @@ -1,194 +0,0 @@ -use crate::utils::{meets_msrv, snippet_opt, span_lint_and_then}; -use if_chain::if_chain; -use rustc_ast::ast::{Attribute, Item, ItemKind, StructField, Variant, VariantData, VisibilityKind}; -use rustc_attr as attr; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_semver::RustcVersion; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::{sym, Span}; - -const MANUAL_NON_EXHAUSTIVE_MSRV: RustcVersion = RustcVersion::new(1, 40, 0); - -declare_clippy_lint! { - /// **What it does:** Checks for manual implementations of the non-exhaustive pattern. - /// - /// **Why is this bad?** Using the #[non_exhaustive] attribute expresses better the intent - /// and allows possible optimizations when applied to enums. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// struct S { - /// pub a: i32, - /// pub b: i32, - /// _c: (), - /// } - /// - /// enum E { - /// A, - /// B, - /// #[doc(hidden)] - /// _C, - /// } - /// - /// struct T(pub i32, pub i32, ()); - /// ``` - /// Use instead: - /// ```rust - /// #[non_exhaustive] - /// struct S { - /// pub a: i32, - /// pub b: i32, - /// } - /// - /// #[non_exhaustive] - /// enum E { - /// A, - /// B, - /// } - /// - /// #[non_exhaustive] - /// struct T(pub i32, pub i32); - /// ``` - pub MANUAL_NON_EXHAUSTIVE, - style, - "manual implementations of the non-exhaustive pattern can be simplified using #[non_exhaustive]" -} - -#[derive(Clone)] -pub struct ManualNonExhaustive { - msrv: Option, -} - -impl ManualNonExhaustive { - #[must_use] - pub fn new(msrv: Option) -> Self { - Self { msrv } - } -} - -impl_lint_pass!(ManualNonExhaustive => [MANUAL_NON_EXHAUSTIVE]); - -impl EarlyLintPass for ManualNonExhaustive { - fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { - if !meets_msrv(self.msrv.as_ref(), &MANUAL_NON_EXHAUSTIVE_MSRV) { - return; - } - - match &item.kind { - ItemKind::Enum(def, _) => { - check_manual_non_exhaustive_enum(cx, item, &def.variants); - }, - ItemKind::Struct(variant_data, _) => { - if let VariantData::Unit(..) = variant_data { - return; - } - - check_manual_non_exhaustive_struct(cx, item, variant_data); - }, - _ => {}, - } - } - - extract_msrv_attr!(EarlyContext); -} - -fn check_manual_non_exhaustive_enum(cx: &EarlyContext<'_>, item: &Item, variants: &[Variant]) { - fn is_non_exhaustive_marker(variant: &Variant) -> bool { - matches!(variant.data, VariantData::Unit(_)) - && variant.ident.as_str().starts_with('_') - && variant.attrs.iter().any(|a| is_doc_hidden(a)) - } - - fn is_doc_hidden(attr: &Attribute) -> bool { - attr.has_name(sym::doc) - && match attr.meta_item_list() { - Some(l) => attr::list_contains_name(&l, sym::hidden), - None => false, - } - } - - if_chain! { - let mut markers = variants.iter().filter(|v| is_non_exhaustive_marker(v)); - if let Some(marker) = markers.next(); - if markers.count() == 0 && variants.len() > 1; - then { - span_lint_and_then( - cx, - MANUAL_NON_EXHAUSTIVE, - item.span, - "this seems like a manual implementation of the non-exhaustive pattern", - |diag| { - if_chain! { - if !item.attrs.iter().any(|attr| attr.has_name(sym::non_exhaustive)); - let header_span = cx.sess.source_map().span_until_char(item.span, '{'); - if let Some(snippet) = snippet_opt(cx, header_span); - then { - diag.span_suggestion( - header_span, - "add the attribute", - format!("#[non_exhaustive] {}", snippet), - Applicability::Unspecified, - ); - } - } - diag.span_help(marker.span, "remove this variant"); - }); - } - } -} - -fn check_manual_non_exhaustive_struct(cx: &EarlyContext<'_>, item: &Item, data: &VariantData) { - fn is_private(field: &StructField) -> bool { - matches!(field.vis.kind, VisibilityKind::Inherited) - } - - fn is_non_exhaustive_marker(field: &StructField) -> bool { - is_private(field) && field.ty.kind.is_unit() && field.ident.map_or(true, |n| n.as_str().starts_with('_')) - } - - fn find_header_span(cx: &EarlyContext<'_>, item: &Item, data: &VariantData) -> Span { - let delimiter = match data { - VariantData::Struct(..) => '{', - VariantData::Tuple(..) => '(', - VariantData::Unit(_) => unreachable!("`VariantData::Unit` is already handled above"), - }; - - cx.sess.source_map().span_until_char(item.span, delimiter) - } - - let fields = data.fields(); - let private_fields = fields.iter().filter(|f| is_private(f)).count(); - let public_fields = fields.iter().filter(|f| f.vis.kind.is_pub()).count(); - - if_chain! { - if private_fields == 1 && public_fields >= 1 && public_fields == fields.len() - 1; - if let Some(marker) = fields.iter().find(|f| is_non_exhaustive_marker(f)); - then { - span_lint_and_then( - cx, - MANUAL_NON_EXHAUSTIVE, - item.span, - "this seems like a manual implementation of the non-exhaustive pattern", - |diag| { - if_chain! { - if !item.attrs.iter().any(|attr| attr.has_name(sym::non_exhaustive)); - let header_span = find_header_span(cx, item, data); - if let Some(snippet) = snippet_opt(cx, header_span); - then { - diag.span_suggestion( - header_span, - "add the attribute", - format!("#[non_exhaustive] {}", snippet), - Applicability::Unspecified, - ); - } - } - diag.span_help(marker.span, "remove this field"); - }); - } - } -} diff --git a/clippy_lints/src/manual_ok_or.rs b/clippy_lints/src/manual_ok_or.rs deleted file mode 100644 index b97d97ea1a5e..000000000000 --- a/clippy_lints/src/manual_ok_or.rs +++ /dev/null @@ -1,100 +0,0 @@ -use crate::utils::{ - indent_of, is_type_diagnostic_item, match_qpath, paths, reindent_multiline, snippet_opt, span_lint_and_sugg, -}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{def, Expr, ExprKind, PatKind, QPath}; -use rustc_lint::LintContext; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::lint::in_external_macro; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::symbol::sym; - -declare_clippy_lint! { - /// **What it does:** - /// Finds patterns that reimplement `Option::ok_or`. - /// - /// **Why is this bad?** - /// Concise code helps focusing on behavior instead of boilerplate. - /// - /// **Known problems:** None. - /// - /// **Examples:** - /// ```rust - /// let foo: Option = None; - /// foo.map_or(Err("error"), |v| Ok(v)); - /// - /// let foo: Option = None; - /// foo.map_or(Err("error"), |v| Ok(v)); - /// ``` - /// - /// Use instead: - /// ```rust - /// let foo: Option = None; - /// foo.ok_or("error"); - /// ``` - pub MANUAL_OK_OR, - pedantic, - "finds patterns that can be encoded more concisely with `Option::ok_or`" -} - -declare_lint_pass!(ManualOkOr => [MANUAL_OK_OR]); - -impl LateLintPass<'_> for ManualOkOr { - fn check_expr(&mut self, cx: &LateContext<'tcx>, scrutinee: &'tcx Expr<'tcx>) { - if in_external_macro(cx.sess(), scrutinee.span) { - return; - } - - if_chain! { - if let ExprKind::MethodCall(method_segment, _, args, _) = scrutinee.kind; - if method_segment.ident.name == sym!(map_or); - if args.len() == 3; - let method_receiver = &args[0]; - let ty = cx.typeck_results().expr_ty(method_receiver); - if is_type_diagnostic_item(cx, ty, sym::option_type); - let or_expr = &args[1]; - if is_ok_wrapping(cx, &args[2]); - if let ExprKind::Call(Expr { kind: ExprKind::Path(err_path), .. }, &[ref err_arg]) = or_expr.kind; - if match_qpath(err_path, &paths::RESULT_ERR); - if let Some(method_receiver_snippet) = snippet_opt(cx, method_receiver.span); - if let Some(err_arg_snippet) = snippet_opt(cx, err_arg.span); - if let Some(indent) = indent_of(cx, scrutinee.span); - then { - let reindented_err_arg_snippet = - reindent_multiline(err_arg_snippet.into(), true, Some(indent + 4)); - span_lint_and_sugg( - cx, - MANUAL_OK_OR, - scrutinee.span, - "this pattern reimplements `Option::ok_or`", - "replace with", - format!( - "{}.ok_or({})", - method_receiver_snippet, - reindented_err_arg_snippet - ), - Applicability::MachineApplicable, - ); - } - } - } -} - -fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool { - if let ExprKind::Path(ref qpath) = map_expr.kind { - if match_qpath(qpath, &paths::RESULT_OK) { - return true; - } - } - if_chain! { - if let ExprKind::Closure(_, _, body_id, ..) = map_expr.kind; - let body = cx.tcx.hir().body(body_id); - if let PatKind::Binding(_, param_id, ..) = body.params[0].pat.kind; - if let ExprKind::Call(Expr { kind: ExprKind::Path(ok_path), .. }, &[ref ok_arg]) = body.value.kind; - if match_qpath(ok_path, &paths::RESULT_OK); - if let ExprKind::Path(QPath::Resolved(_, ok_arg_path)) = ok_arg.kind; - if let def::Res::Local(ok_arg_path_id) = ok_arg_path.res; - then { param_id == ok_arg_path_id } else { false } - } -} diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs deleted file mode 100644 index 3c4368a3545a..000000000000 --- a/clippy_lints/src/manual_strip.rs +++ /dev/null @@ -1,264 +0,0 @@ -use crate::consts::{constant, Constant}; -use crate::utils::usage::mutated_variables; -use crate::utils::{ - eq_expr_value, higher, match_def_path, meets_msrv, multispan_sugg, paths, qpath_res, snippet, span_lint_and_then, -}; - -use if_chain::if_chain; -use rustc_ast::ast::LitKind; -use rustc_hir::def::Res; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; -use rustc_hir::BinOpKind; -use rustc_hir::{BorrowKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; -use rustc_middle::ty; -use rustc_semver::RustcVersion; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Spanned; -use rustc_span::Span; - -const MANUAL_STRIP_MSRV: RustcVersion = RustcVersion::new(1, 45, 0); - -declare_clippy_lint! { - /// **What it does:** - /// Suggests using `strip_{prefix,suffix}` over `str::{starts,ends}_with` and slicing using - /// the pattern's length. - /// - /// **Why is this bad?** - /// Using `str:strip_{prefix,suffix}` is safer and may have better performance as there is no - /// slicing which may panic and the compiler does not need to insert this panic code. It is - /// also sometimes more readable as it removes the need for duplicating or storing the pattern - /// used by `str::{starts,ends}_with` and in the slicing. - /// - /// **Known problems:** - /// None. - /// - /// **Example:** - /// - /// ```rust - /// let s = "hello, world!"; - /// if s.starts_with("hello, ") { - /// assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!"); - /// } - /// ``` - /// Use instead: - /// ```rust - /// let s = "hello, world!"; - /// if let Some(end) = s.strip_prefix("hello, ") { - /// assert_eq!(end.to_uppercase(), "WORLD!"); - /// } - /// ``` - pub MANUAL_STRIP, - complexity, - "suggests using `strip_{prefix,suffix}` over `str::{starts,ends}_with` and slicing" -} - -pub struct ManualStrip { - msrv: Option, -} - -impl ManualStrip { - #[must_use] - pub fn new(msrv: Option) -> Self { - Self { msrv } - } -} - -impl_lint_pass!(ManualStrip => [MANUAL_STRIP]); - -#[derive(Clone, Copy, Debug, Eq, PartialEq)] -enum StripKind { - Prefix, - Suffix, -} - -impl<'tcx> LateLintPass<'tcx> for ManualStrip { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if !meets_msrv(self.msrv.as_ref(), &MANUAL_STRIP_MSRV) { - return; - } - - if_chain! { - if let Some((cond, then, _)) = higher::if_block(&expr); - if let ExprKind::MethodCall(_, _, [target_arg, pattern], _) = cond.kind; - if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(cond.hir_id); - if let ExprKind::Path(target_path) = &target_arg.kind; - then { - let strip_kind = if match_def_path(cx, method_def_id, &paths::STR_STARTS_WITH) { - StripKind::Prefix - } else if match_def_path(cx, method_def_id, &paths::STR_ENDS_WITH) { - StripKind::Suffix - } else { - return; - }; - let target_res = qpath_res(cx, &target_path, target_arg.hir_id); - if target_res == Res::Err { - return; - }; - - if_chain! { - if let Res::Local(hir_id) = target_res; - if let Some(used_mutably) = mutated_variables(then, cx); - if used_mutably.contains(&hir_id); - then { - return; - } - } - - let strippings = find_stripping(cx, strip_kind, target_res, pattern, then); - if !strippings.is_empty() { - - let kind_word = match strip_kind { - StripKind::Prefix => "prefix", - StripKind::Suffix => "suffix", - }; - - let test_span = expr.span.until(then.span); - span_lint_and_then(cx, MANUAL_STRIP, strippings[0], &format!("stripping a {} manually", kind_word), |diag| { - diag.span_note(test_span, &format!("the {} was tested here", kind_word)); - multispan_sugg( - diag, - &format!("try using the `strip_{}` method", kind_word), - vec![(test_span, - format!("if let Some() = {}.strip_{}({}) ", - snippet(cx, target_arg.span, ".."), - kind_word, - snippet(cx, pattern.span, "..")))] - .into_iter().chain(strippings.into_iter().map(|span| (span, "".into()))), - ) - }); - } - } - } - } - - extract_msrv_attr!(LateContext); -} - -// Returns `Some(arg)` if `expr` matches `arg.len()` and `None` otherwise. -fn len_arg<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { - if_chain! { - if let ExprKind::MethodCall(_, _, [arg], _) = expr.kind; - if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); - if match_def_path(cx, method_def_id, &paths::STR_LEN); - then { - Some(arg) - } else { - None - } - } -} - -// Returns the length of the `expr` if it's a constant string or char. -fn constant_length(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { - let (value, _) = constant(cx, cx.typeck_results(), expr)?; - match value { - Constant::Str(value) => Some(value.len() as u128), - Constant::Char(value) => Some(value.len_utf8() as u128), - _ => None, - } -} - -// Tests if `expr` equals the length of the pattern. -fn eq_pattern_length<'tcx>(cx: &LateContext<'tcx>, pattern: &Expr<'_>, expr: &'tcx Expr<'_>) -> bool { - if let ExprKind::Lit(Spanned { - node: LitKind::Int(n, _), - .. - }) = expr.kind - { - constant_length(cx, pattern).map_or(false, |length| length == n) - } else { - len_arg(cx, expr).map_or(false, |arg| eq_expr_value(cx, pattern, arg)) - } -} - -// Tests if `expr` is a `&str`. -fn is_ref_str(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - match cx.typeck_results().expr_ty_adjusted(&expr).kind() { - ty::Ref(_, ty, _) => ty.is_str(), - _ => false, - } -} - -// Removes the outer `AddrOf` expression if needed. -fn peel_ref<'a>(expr: &'a Expr<'_>) -> &'a Expr<'a> { - if let ExprKind::AddrOf(BorrowKind::Ref, _, unref) = &expr.kind { - unref - } else { - expr - } -} - -// Find expressions where `target` is stripped using the length of `pattern`. -// We'll suggest replacing these expressions with the result of the `strip_{prefix,suffix}` -// method. -fn find_stripping<'tcx>( - cx: &LateContext<'tcx>, - strip_kind: StripKind, - target: Res, - pattern: &'tcx Expr<'_>, - expr: &'tcx Expr<'_>, -) -> Vec { - struct StrippingFinder<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - strip_kind: StripKind, - target: Res, - pattern: &'tcx Expr<'tcx>, - results: Vec, - } - - impl<'a, 'tcx> Visitor<'tcx> for StrippingFinder<'a, 'tcx> { - type Map = Map<'tcx>; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } - - fn visit_expr(&mut self, ex: &'tcx Expr<'_>) { - if_chain! { - if is_ref_str(self.cx, ex); - let unref = peel_ref(ex); - if let ExprKind::Index(indexed, index) = &unref.kind; - if let Some(higher::Range { start, end, .. }) = higher::range(index); - if let ExprKind::Path(path) = &indexed.kind; - if qpath_res(self.cx, path, ex.hir_id) == self.target; - then { - match (self.strip_kind, start, end) { - (StripKind::Prefix, Some(start), None) => { - if eq_pattern_length(self.cx, self.pattern, start) { - self.results.push(ex.span); - return; - } - }, - (StripKind::Suffix, None, Some(end)) => { - if_chain! { - if let ExprKind::Binary(Spanned { node: BinOpKind::Sub, .. }, left, right) = end.kind; - if let Some(left_arg) = len_arg(self.cx, left); - if let ExprKind::Path(left_path) = &left_arg.kind; - if qpath_res(self.cx, left_path, left_arg.hir_id) == self.target; - if eq_pattern_length(self.cx, self.pattern, right); - then { - self.results.push(ex.span); - return; - } - } - }, - _ => {} - } - } - } - - walk_expr(self, ex); - } - } - - let mut finder = StrippingFinder { - cx, - strip_kind, - target, - pattern, - results: vec![], - }; - walk_expr(&mut finder, expr); - finder.results -} diff --git a/clippy_lints/src/manual_unwrap_or.rs b/clippy_lints/src/manual_unwrap_or.rs deleted file mode 100644 index 9e2c6c7f231d..000000000000 --- a/clippy_lints/src/manual_unwrap_or.rs +++ /dev/null @@ -1,129 +0,0 @@ -use crate::consts::constant_simple; -use crate::utils; -use crate::utils::sugg; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{def, Arm, Expr, ExprKind, Pat, PatKind, QPath}; -use rustc_lint::LintContext; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::lint::in_external_macro; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** - /// Finds patterns that reimplement `Option::unwrap_or` or `Result::unwrap_or`. - /// - /// **Why is this bad?** - /// Concise code helps focusing on behavior instead of boilerplate. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let foo: Option = None; - /// match foo { - /// Some(v) => v, - /// None => 1, - /// }; - /// ``` - /// - /// Use instead: - /// ```rust - /// let foo: Option = None; - /// foo.unwrap_or(1); - /// ``` - pub MANUAL_UNWRAP_OR, - complexity, - "finds patterns that can be encoded more concisely with `Option::unwrap_or` or `Result::unwrap_or`" -} - -declare_lint_pass!(ManualUnwrapOr => [MANUAL_UNWRAP_OR]); - -impl LateLintPass<'_> for ManualUnwrapOr { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - if in_external_macro(cx.sess(), expr.span) { - return; - } - lint_manual_unwrap_or(cx, expr); - } -} - -#[derive(Copy, Clone)] -enum Case { - Option, - Result, -} - -impl Case { - fn unwrap_fn_path(&self) -> &str { - match self { - Case::Option => "Option::unwrap_or", - Case::Result => "Result::unwrap_or", - } - } -} - -fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - fn applicable_or_arm<'a>(arms: &'a [Arm<'a>]) -> Option<&'a Arm<'a>> { - if_chain! { - if arms.len() == 2; - if arms.iter().all(|arm| arm.guard.is_none()); - if let Some((idx, or_arm)) = arms.iter().enumerate().find(|(_, arm)| - match arm.pat.kind { - PatKind::Path(ref some_qpath) => - utils::match_qpath(some_qpath, &utils::paths::OPTION_NONE), - PatKind::TupleStruct(ref err_qpath, &[Pat { kind: PatKind::Wild, .. }], _) => - utils::match_qpath(err_qpath, &utils::paths::RESULT_ERR), - _ => false, - } - ); - let unwrap_arm = &arms[1 - idx]; - if let PatKind::TupleStruct(ref unwrap_qpath, &[unwrap_pat], _) = unwrap_arm.pat.kind; - if utils::match_qpath(unwrap_qpath, &utils::paths::OPTION_SOME) - || utils::match_qpath(unwrap_qpath, &utils::paths::RESULT_OK); - if let PatKind::Binding(_, binding_hir_id, ..) = unwrap_pat.kind; - if let ExprKind::Path(QPath::Resolved(_, body_path)) = unwrap_arm.body.kind; - if let def::Res::Local(body_path_hir_id) = body_path.res; - if body_path_hir_id == binding_hir_id; - if !utils::usage::contains_return_break_continue_macro(or_arm.body); - then { - Some(or_arm) - } else { - None - } - } - } - - if_chain! { - if let ExprKind::Match(scrutinee, match_arms, _) = expr.kind; - let ty = cx.typeck_results().expr_ty(scrutinee); - if let Some(case) = if utils::is_type_diagnostic_item(cx, ty, sym::option_type) { - Some(Case::Option) - } else if utils::is_type_diagnostic_item(cx, ty, sym::result_type) { - Some(Case::Result) - } else { - None - }; - if let Some(or_arm) = applicable_or_arm(match_arms); - if let Some(or_body_snippet) = utils::snippet_opt(cx, or_arm.body.span); - if let Some(indent) = utils::indent_of(cx, expr.span); - if constant_simple(cx, cx.typeck_results(), or_arm.body).is_some(); - then { - let reindented_or_body = - utils::reindent_multiline(or_body_snippet.into(), true, Some(indent)); - utils::span_lint_and_sugg( - cx, - MANUAL_UNWRAP_OR, expr.span, - &format!("this pattern reimplements `{}`", case.unwrap_fn_path()), - "replace with", - format!( - "{}.unwrap_or({})", - sugg::Sugg::hir(cx, scrutinee, "..").maybe_par(), - reindented_or_body, - ), - Applicability::MachineApplicable, - ); - } - } -} diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs deleted file mode 100644 index 220240acb7aa..000000000000 --- a/clippy_lints/src/map_clone.rs +++ /dev/null @@ -1,157 +0,0 @@ -use crate::utils::paths; -use crate::utils::{ - is_copy, is_type_diagnostic_item, match_trait_method, remove_blocks, snippet_with_applicability, span_lint_and_sugg, -}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::mir::Mutability; -use rustc_middle::ty; -use rustc_middle::ty::adjustment::Adjust; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::symbol::Ident; -use rustc_span::{sym, Span}; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `map(|x| x.clone())` or - /// dereferencing closures for `Copy` types, on `Iterator` or `Option`, - /// and suggests `cloned()` or `copied()` instead - /// - /// **Why is this bad?** Readability, this can be written more concisely - /// - /// **Known problems:** None - /// - /// **Example:** - /// - /// ```rust - /// let x = vec![42, 43]; - /// let y = x.iter(); - /// let z = y.map(|i| *i); - /// ``` - /// - /// The correct use would be: - /// - /// ```rust - /// let x = vec![42, 43]; - /// let y = x.iter(); - /// let z = y.cloned(); - /// ``` - pub MAP_CLONE, - style, - "using `iterator.map(|x| x.clone())`, or dereferencing closures for `Copy` types" -} - -declare_lint_pass!(MapClone => [MAP_CLONE]); - -impl<'tcx> LateLintPass<'tcx> for MapClone { - fn check_expr(&mut self, cx: &LateContext<'_>, e: &hir::Expr<'_>) { - if e.span.from_expansion() { - return; - } - - if_chain! { - if let hir::ExprKind::MethodCall(ref method, _, ref args, _) = e.kind; - if args.len() == 2; - if method.ident.as_str() == "map"; - let ty = cx.typeck_results().expr_ty(&args[0]); - if is_type_diagnostic_item(cx, ty, sym::option_type) || match_trait_method(cx, e, &paths::ITERATOR); - if let hir::ExprKind::Closure(_, _, body_id, _, _) = args[1].kind; - let closure_body = cx.tcx.hir().body(body_id); - let closure_expr = remove_blocks(&closure_body.value); - then { - match closure_body.params[0].pat.kind { - hir::PatKind::Ref(ref inner, hir::Mutability::Not) => if let hir::PatKind::Binding( - hir::BindingAnnotation::Unannotated, .., name, None - ) = inner.kind { - if ident_eq(name, closure_expr) { - lint(cx, e.span, args[0].span, true); - } - }, - hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, .., name, None) => { - match closure_expr.kind { - hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner) => { - if ident_eq(name, inner) { - if let ty::Ref(.., Mutability::Not) = cx.typeck_results().expr_ty(inner).kind() { - lint(cx, e.span, args[0].span, true); - } - } - }, - hir::ExprKind::MethodCall(ref method, _, [obj], _) => if_chain! { - if ident_eq(name, obj) && method.ident.name == sym::clone; - if match_trait_method(cx, closure_expr, &paths::CLONE_TRAIT); - // no autoderefs - if !cx.typeck_results().expr_adjustments(obj).iter() - .any(|a| matches!(a.kind, Adjust::Deref(Some(..)))); - then { - let obj_ty = cx.typeck_results().expr_ty(obj); - if let ty::Ref(_, ty, mutability) = obj_ty.kind() { - if matches!(mutability, Mutability::Not) { - let copy = is_copy(cx, ty); - lint(cx, e.span, args[0].span, copy); - } - } else { - lint_needless_cloning(cx, e.span, args[0].span); - } - } - }, - _ => {}, - } - }, - _ => {}, - } - } - } - } -} - -fn ident_eq(name: Ident, path: &hir::Expr<'_>) -> bool { - if let hir::ExprKind::Path(hir::QPath::Resolved(None, ref path)) = path.kind { - path.segments.len() == 1 && path.segments[0].ident == name - } else { - false - } -} - -fn lint_needless_cloning(cx: &LateContext<'_>, root: Span, receiver: Span) { - span_lint_and_sugg( - cx, - MAP_CLONE, - root.trim_start(receiver).unwrap(), - "you are needlessly cloning iterator elements", - "remove the `map` call", - String::new(), - Applicability::MachineApplicable, - ) -} - -fn lint(cx: &LateContext<'_>, replace: Span, root: Span, copied: bool) { - let mut applicability = Applicability::MachineApplicable; - if copied { - span_lint_and_sugg( - cx, - MAP_CLONE, - replace, - "you are using an explicit closure for copying elements", - "consider calling the dedicated `copied` method", - format!( - "{}.copied()", - snippet_with_applicability(cx, root, "..", &mut applicability) - ), - applicability, - ) - } else { - span_lint_and_sugg( - cx, - MAP_CLONE, - replace, - "you are using an explicit closure for cloning elements", - "consider calling the dedicated `cloned` method", - format!( - "{}.cloned()", - snippet_with_applicability(cx, root, "..", &mut applicability) - ), - applicability, - ) - } -} diff --git a/clippy_lints/src/map_err_ignore.rs b/clippy_lints/src/map_err_ignore.rs deleted file mode 100644 index f3c0515b9bcd..000000000000 --- a/clippy_lints/src/map_err_ignore.rs +++ /dev/null @@ -1,147 +0,0 @@ -use crate::utils::span_lint_and_help; - -use rustc_hir::{CaptureBy, Expr, ExprKind, PatKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for instances of `map_err(|_| Some::Enum)` - /// - /// **Why is this bad?** This map_err throws away the original error rather than allowing the enum to contain and report the cause of the error - /// - /// **Known problems:** None. - /// - /// **Example:** - /// Before: - /// ```rust - /// use std::fmt; - /// - /// #[derive(Debug)] - /// enum Error { - /// Indivisible, - /// Remainder(u8), - /// } - /// - /// impl fmt::Display for Error { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// match self { - /// Error::Indivisible => write!(f, "could not divide input by three"), - /// Error::Remainder(remainder) => write!( - /// f, - /// "input is not divisible by three, remainder = {}", - /// remainder - /// ), - /// } - /// } - /// } - /// - /// impl std::error::Error for Error {} - /// - /// fn divisible_by_3(input: &str) -> Result<(), Error> { - /// input - /// .parse::() - /// .map_err(|_| Error::Indivisible) - /// .map(|v| v % 3) - /// .and_then(|remainder| { - /// if remainder == 0 { - /// Ok(()) - /// } else { - /// Err(Error::Remainder(remainder as u8)) - /// } - /// }) - /// } - /// ``` - /// - /// After: - /// ```rust - /// use std::{fmt, num::ParseIntError}; - /// - /// #[derive(Debug)] - /// enum Error { - /// Indivisible(ParseIntError), - /// Remainder(u8), - /// } - /// - /// impl fmt::Display for Error { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// match self { - /// Error::Indivisible(_) => write!(f, "could not divide input by three"), - /// Error::Remainder(remainder) => write!( - /// f, - /// "input is not divisible by three, remainder = {}", - /// remainder - /// ), - /// } - /// } - /// } - /// - /// impl std::error::Error for Error { - /// fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - /// match self { - /// Error::Indivisible(source) => Some(source), - /// _ => None, - /// } - /// } - /// } - /// - /// fn divisible_by_3(input: &str) -> Result<(), Error> { - /// input - /// .parse::() - /// .map_err(Error::Indivisible) - /// .map(|v| v % 3) - /// .and_then(|remainder| { - /// if remainder == 0 { - /// Ok(()) - /// } else { - /// Err(Error::Remainder(remainder as u8)) - /// } - /// }) - /// } - /// ``` - pub MAP_ERR_IGNORE, - restriction, - "`map_err` should not ignore the original error" -} - -declare_lint_pass!(MapErrIgnore => [MAP_ERR_IGNORE]); - -impl<'tcx> LateLintPass<'tcx> for MapErrIgnore { - // do not try to lint if this is from a macro or desugaring - fn check_expr(&mut self, cx: &LateContext<'_>, e: &Expr<'_>) { - if e.span.from_expansion() { - return; - } - - // check if this is a method call (e.g. x.foo()) - if let ExprKind::MethodCall(ref method, _t_span, ref args, _) = e.kind { - // only work if the method name is `map_err` and there are only 2 arguments (e.g. x.map_err(|_|[1] - // Enum::Variant[2])) - if method.ident.as_str() == "map_err" && args.len() == 2 { - // make sure the first argument is a closure, and grab the CaptureRef, body_id, and body_span fields - if let ExprKind::Closure(capture, _, body_id, body_span, _) = args[1].kind { - // check if this is by Reference (meaning there's no move statement) - if capture == CaptureBy::Ref { - // Get the closure body to check the parameters and values - let closure_body = cx.tcx.hir().body(body_id); - // make sure there's only one parameter (`|_|`) - if closure_body.params.len() == 1 { - // make sure that parameter is the wild token (`_`) - if let PatKind::Wild = closure_body.params[0].pat.kind { - // span the area of the closure capture and warn that the - // original error will be thrown away - span_lint_and_help( - cx, - MAP_ERR_IGNORE, - body_span, - "`map_err(|_|...` wildcard pattern discards the original error", - None, - "Consider storing the original error as a source in the new error, or silence this warning using an ignored identifier (`.map_err(|_foo| ...`)", - ); - } - } - } - } - } - } - } -} diff --git a/clippy_lints/src/map_identity.rs b/clippy_lints/src/map_identity.rs deleted file mode 100644 index 6b782385a38d..000000000000 --- a/clippy_lints/src/map_identity.rs +++ /dev/null @@ -1,127 +0,0 @@ -use crate::utils::{ - is_adjusted, is_type_diagnostic_item, match_path, match_trait_method, match_var, paths, remove_blocks, - span_lint_and_sugg, -}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{Body, Expr, ExprKind, Pat, PatKind, QPath, StmtKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** Checks for instances of `map(f)` where `f` is the identity function. - /// - /// **Why is this bad?** It can be written more concisely without the call to `map`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// let x = [1, 2, 3]; - /// let y: Vec<_> = x.iter().map(|x| x).map(|x| 2*x).collect(); - /// ``` - /// Use instead: - /// ```rust - /// let x = [1, 2, 3]; - /// let y: Vec<_> = x.iter().map(|x| 2*x).collect(); - /// ``` - pub MAP_IDENTITY, - complexity, - "using iterator.map(|x| x)" -} - -declare_lint_pass!(MapIdentity => [MAP_IDENTITY]); - -impl<'tcx> LateLintPass<'tcx> for MapIdentity { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - if expr.span.from_expansion() { - return; - } - - if_chain! { - if let Some([caller, func]) = get_map_argument(cx, expr); - if is_expr_identity_function(cx, func); - then { - span_lint_and_sugg( - cx, - MAP_IDENTITY, - expr.span.trim_start(caller.span).unwrap(), - "unnecessary map of the identity function", - "remove the call to `map`", - String::new(), - Applicability::MachineApplicable - ) - } - } - } -} - -/// Returns the arguments passed into map() if the expression is a method call to -/// map(). Otherwise, returns None. -fn get_map_argument<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<&'a [Expr<'a>]> { - if_chain! { - if let ExprKind::MethodCall(ref method, _, ref args, _) = expr.kind; - if args.len() == 2 && method.ident.as_str() == "map"; - let caller_ty = cx.typeck_results().expr_ty(&args[0]); - if match_trait_method(cx, expr, &paths::ITERATOR) - || is_type_diagnostic_item(cx, caller_ty, sym::result_type) - || is_type_diagnostic_item(cx, caller_ty, sym::option_type); - then { - Some(args) - } else { - None - } - } -} - -/// Checks if an expression represents the identity function -/// Only examines closures and `std::convert::identity` -fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - match expr.kind { - ExprKind::Closure(_, _, body_id, _, _) => is_body_identity_function(cx, cx.tcx.hir().body(body_id)), - ExprKind::Path(QPath::Resolved(_, ref path)) => match_path(path, &paths::STD_CONVERT_IDENTITY), - _ => false, - } -} - -/// Checks if a function's body represents the identity function -/// Looks for bodies of the form `|x| x`, `|x| return x`, `|x| { return x }` or `|x| { -/// return x; }` -fn is_body_identity_function(cx: &LateContext<'_>, func: &Body<'_>) -> bool { - let params = func.params; - let body = remove_blocks(&func.value); - - // if there's less/more than one parameter, then it is not the identity function - if params.len() != 1 { - return false; - } - - match body.kind { - ExprKind::Path(QPath::Resolved(None, _)) => match_expr_param(cx, body, params[0].pat), - ExprKind::Ret(Some(ref ret_val)) => match_expr_param(cx, ret_val, params[0].pat), - ExprKind::Block(ref block, _) => { - if_chain! { - if block.stmts.len() == 1; - if let StmtKind::Semi(ref expr) | StmtKind::Expr(ref expr) = block.stmts[0].kind; - if let ExprKind::Ret(Some(ref ret_val)) = expr.kind; - then { - match_expr_param(cx, ret_val, params[0].pat) - } else { - false - } - } - }, - _ => false, - } -} - -/// Returns true iff an expression returns the same thing as a parameter's pattern -fn match_expr_param(cx: &LateContext<'_>, expr: &Expr<'_>, pat: &Pat<'_>) -> bool { - if let PatKind::Binding(_, _, ident, _) = pat.kind { - match_var(expr, ident.name) && !(cx.typeck_results().hir_owner == expr.hir_id.owner && is_adjusted(cx, expr)) - } else { - false - } -} diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs deleted file mode 100644 index e50d11a4d717..000000000000 --- a/clippy_lints/src/map_unit_fn.rs +++ /dev/null @@ -1,275 +0,0 @@ -use crate::utils::{is_type_diagnostic_item, iter_input_pats, method_chain_args, snippet, span_lint_and_then}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, Ty}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `option.map(f)` where f is a function - /// or closure that returns the unit type `()`. - /// - /// **Why is this bad?** Readability, this can be written more clearly with - /// an if let statement - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// # fn do_stuff() -> Option { Some(String::new()) } - /// # fn log_err_msg(foo: String) -> Option { Some(foo) } - /// # fn format_msg(foo: String) -> String { String::new() } - /// let x: Option = do_stuff(); - /// x.map(log_err_msg); - /// # let x: Option = do_stuff(); - /// x.map(|msg| log_err_msg(format_msg(msg))); - /// ``` - /// - /// The correct use would be: - /// - /// ```rust - /// # fn do_stuff() -> Option { Some(String::new()) } - /// # fn log_err_msg(foo: String) -> Option { Some(foo) } - /// # fn format_msg(foo: String) -> String { String::new() } - /// let x: Option = do_stuff(); - /// if let Some(msg) = x { - /// log_err_msg(msg); - /// } - /// - /// # let x: Option = do_stuff(); - /// if let Some(msg) = x { - /// log_err_msg(format_msg(msg)); - /// } - /// ``` - pub OPTION_MAP_UNIT_FN, - complexity, - "using `option.map(f)`, where `f` is a function or closure that returns `()`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `result.map(f)` where f is a function - /// or closure that returns the unit type `()`. - /// - /// **Why is this bad?** Readability, this can be written more clearly with - /// an if let statement - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// # fn do_stuff() -> Result { Ok(String::new()) } - /// # fn log_err_msg(foo: String) -> Result { Ok(foo) } - /// # fn format_msg(foo: String) -> String { String::new() } - /// let x: Result = do_stuff(); - /// x.map(log_err_msg); - /// # let x: Result = do_stuff(); - /// x.map(|msg| log_err_msg(format_msg(msg))); - /// ``` - /// - /// The correct use would be: - /// - /// ```rust - /// # fn do_stuff() -> Result { Ok(String::new()) } - /// # fn log_err_msg(foo: String) -> Result { Ok(foo) } - /// # fn format_msg(foo: String) -> String { String::new() } - /// let x: Result = do_stuff(); - /// if let Ok(msg) = x { - /// log_err_msg(msg); - /// }; - /// # let x: Result = do_stuff(); - /// if let Ok(msg) = x { - /// log_err_msg(format_msg(msg)); - /// }; - /// ``` - pub RESULT_MAP_UNIT_FN, - complexity, - "using `result.map(f)`, where `f` is a function or closure that returns `()`" -} - -declare_lint_pass!(MapUnit => [OPTION_MAP_UNIT_FN, RESULT_MAP_UNIT_FN]); - -fn is_unit_type(ty: Ty<'_>) -> bool { - match ty.kind() { - ty::Tuple(slice) => slice.is_empty(), - ty::Never => true, - _ => false, - } -} - -fn is_unit_function(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { - let ty = cx.typeck_results().expr_ty(expr); - - if let ty::FnDef(id, _) = *ty.kind() { - if let Some(fn_type) = cx.tcx.fn_sig(id).no_bound_vars() { - return is_unit_type(fn_type.output()); - } - } - false -} - -fn is_unit_expression(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { - is_unit_type(cx.typeck_results().expr_ty(expr)) -} - -/// The expression inside a closure may or may not have surrounding braces and -/// semicolons, which causes problems when generating a suggestion. Given an -/// expression that evaluates to '()' or '!', recursively remove useless braces -/// and semi-colons until is suitable for including in the suggestion template -fn reduce_unit_expression<'a>(cx: &LateContext<'_>, expr: &'a hir::Expr<'_>) -> Option { - if !is_unit_expression(cx, expr) { - return None; - } - - match expr.kind { - hir::ExprKind::Call(_, _) | hir::ExprKind::MethodCall(_, _, _, _) => { - // Calls can't be reduced any more - Some(expr.span) - }, - hir::ExprKind::Block(ref block, _) => { - match (&block.stmts[..], block.expr.as_ref()) { - (&[], Some(inner_expr)) => { - // If block only contains an expression, - // reduce `{ X }` to `X` - reduce_unit_expression(cx, inner_expr) - }, - (&[ref inner_stmt], None) => { - // If block only contains statements, - // reduce `{ X; }` to `X` or `X;` - match inner_stmt.kind { - hir::StmtKind::Local(ref local) => Some(local.span), - hir::StmtKind::Expr(ref e) => Some(e.span), - hir::StmtKind::Semi(..) => Some(inner_stmt.span), - hir::StmtKind::Item(..) => None, - } - }, - _ => { - // For closures that contain multiple statements - // it's difficult to get a correct suggestion span - // for all cases (multi-line closures specifically) - // - // We do not attempt to build a suggestion for those right now. - None - }, - } - }, - _ => None, - } -} - -fn unit_closure<'tcx>( - cx: &LateContext<'tcx>, - expr: &hir::Expr<'_>, -) -> Option<(&'tcx hir::Param<'tcx>, &'tcx hir::Expr<'tcx>)> { - if let hir::ExprKind::Closure(_, ref decl, inner_expr_id, _, _) = expr.kind { - let body = cx.tcx.hir().body(inner_expr_id); - let body_expr = &body.value; - - if_chain! { - if decl.inputs.len() == 1; - if is_unit_expression(cx, body_expr); - if let Some(binding) = iter_input_pats(&decl, body).next(); - then { - return Some((binding, body_expr)); - } - } - } - None -} - -/// Builds a name for the let binding variable (`var_arg`) -/// -/// `x.field` => `x_field` -/// `y` => `_y` -/// -/// Anything else will return `a`. -fn let_binding_name(cx: &LateContext<'_>, var_arg: &hir::Expr<'_>) -> String { - match &var_arg.kind { - hir::ExprKind::Field(_, _) => snippet(cx, var_arg.span, "_").replace(".", "_"), - hir::ExprKind::Path(_) => format!("_{}", snippet(cx, var_arg.span, "")), - _ => "a".to_string(), - } -} - -#[must_use] -fn suggestion_msg(function_type: &str, map_type: &str) -> String { - format!( - "called `map(f)` on an `{0}` value where `f` is a {1} that returns the unit type `()`", - map_type, function_type - ) -} - -fn lint_map_unit_fn(cx: &LateContext<'_>, stmt: &hir::Stmt<'_>, expr: &hir::Expr<'_>, map_args: &[hir::Expr<'_>]) { - let var_arg = &map_args[0]; - - let (map_type, variant, lint) = - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(var_arg), sym::option_type) { - ("Option", "Some", OPTION_MAP_UNIT_FN) - } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(var_arg), sym::result_type) { - ("Result", "Ok", RESULT_MAP_UNIT_FN) - } else { - return; - }; - let fn_arg = &map_args[1]; - - if is_unit_function(cx, fn_arg) { - let msg = suggestion_msg("function", map_type); - let suggestion = format!( - "if let {0}({binding}) = {1} {{ {2}({binding}) }}", - variant, - snippet(cx, var_arg.span, "_"), - snippet(cx, fn_arg.span, "_"), - binding = let_binding_name(cx, var_arg) - ); - - span_lint_and_then(cx, lint, expr.span, &msg, |diag| { - diag.span_suggestion(stmt.span, "try this", suggestion, Applicability::MachineApplicable); - }); - } else if let Some((binding, closure_expr)) = unit_closure(cx, fn_arg) { - let msg = suggestion_msg("closure", map_type); - - span_lint_and_then(cx, lint, expr.span, &msg, |diag| { - if let Some(reduced_expr_span) = reduce_unit_expression(cx, closure_expr) { - let suggestion = format!( - "if let {0}({1}) = {2} {{ {3} }}", - variant, - snippet(cx, binding.pat.span, "_"), - snippet(cx, var_arg.span, "_"), - snippet(cx, reduced_expr_span, "_") - ); - diag.span_suggestion( - stmt.span, - "try this", - suggestion, - Applicability::MachineApplicable, // snippet - ); - } else { - let suggestion = format!( - "if let {0}({1}) = {2} {{ ... }}", - variant, - snippet(cx, binding.pat.span, "_"), - snippet(cx, var_arg.span, "_"), - ); - diag.span_suggestion(stmt.span, "try this", suggestion, Applicability::HasPlaceholders); - } - }); - } -} - -impl<'tcx> LateLintPass<'tcx> for MapUnit { - fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &hir::Stmt<'_>) { - if stmt.span.from_expansion() { - return; - } - - if let hir::StmtKind::Semi(ref expr) = stmt.kind { - if let Some(arglists) = method_chain_args(expr, &["map"]) { - lint_map_unit_fn(cx, stmt, expr, arglists[0]); - } - } - } -} diff --git a/clippy_lints/src/match_on_vec_items.rs b/clippy_lints/src/match_on_vec_items.rs deleted file mode 100644 index 086dae9422f9..000000000000 --- a/clippy_lints/src/match_on_vec_items.rs +++ /dev/null @@ -1,101 +0,0 @@ -use crate::utils::{is_type_diagnostic_item, is_type_lang_item, snippet, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, LangItem, MatchSource}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** Checks for `match vec[idx]` or `match vec[n..m]`. - /// - /// **Why is this bad?** This can panic at runtime. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust, no_run - /// let arr = vec![0, 1, 2, 3]; - /// let idx = 1; - /// - /// // Bad - /// match arr[idx] { - /// 0 => println!("{}", 0), - /// 1 => println!("{}", 3), - /// _ => {}, - /// } - /// ``` - /// Use instead: - /// ```rust, no_run - /// let arr = vec![0, 1, 2, 3]; - /// let idx = 1; - /// - /// // Good - /// match arr.get(idx) { - /// Some(0) => println!("{}", 0), - /// Some(1) => println!("{}", 3), - /// _ => {}, - /// } - /// ``` - pub MATCH_ON_VEC_ITEMS, - pedantic, - "matching on vector elements can panic" -} - -declare_lint_pass!(MatchOnVecItems => [MATCH_ON_VEC_ITEMS]); - -impl<'tcx> LateLintPass<'tcx> for MatchOnVecItems { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - if_chain! { - if !in_external_macro(cx.sess(), expr.span); - if let ExprKind::Match(ref match_expr, _, MatchSource::Normal) = expr.kind; - if let Some(idx_expr) = is_vec_indexing(cx, match_expr); - if let ExprKind::Index(vec, idx) = idx_expr.kind; - - then { - // FIXME: could be improved to suggest surrounding every pattern with Some(_), - // but only when `or_patterns` are stabilized. - span_lint_and_sugg( - cx, - MATCH_ON_VEC_ITEMS, - match_expr.span, - "indexing into a vector may panic", - "try this", - format!( - "{}.get({})", - snippet(cx, vec.span, ".."), - snippet(cx, idx.span, "..") - ), - Applicability::MaybeIncorrect - ); - } - } - } -} - -fn is_vec_indexing<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { - if_chain! { - if let ExprKind::Index(ref array, ref index) = expr.kind; - if is_vector(cx, array); - if !is_full_range(cx, index); - - then { - return Some(expr); - } - } - - None -} - -fn is_vector(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - let ty = cx.typeck_results().expr_ty(expr); - let ty = ty.peel_refs(); - is_type_diagnostic_item(cx, ty, sym::vec_type) -} - -fn is_full_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - let ty = cx.typeck_results().expr_ty(expr); - let ty = ty.peel_refs(); - is_type_lang_item(cx, ty, LangItem::RangeFull) -} diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs deleted file mode 100644 index 04b35835c6b8..000000000000 --- a/clippy_lints/src/matches.rs +++ /dev/null @@ -1,1927 +0,0 @@ -use crate::consts::{constant, miri_to_const, Constant}; -use crate::utils::sugg::Sugg; -use crate::utils::usage::is_unused; -use crate::utils::{ - expr_block, get_arg_name, get_parent_expr, in_macro, indent_of, is_allowed, is_expn_of, is_refutable, - is_type_diagnostic_item, is_wild, match_qpath, match_type, match_var, meets_msrv, multispan_sugg, remove_blocks, - snippet, snippet_block, snippet_opt, snippet_with_applicability, span_lint_and_help, span_lint_and_note, - span_lint_and_sugg, span_lint_and_then, -}; -use crate::utils::{paths, search_same, SpanlessEq, SpanlessHash}; -use if_chain::if_chain; -use rustc_ast::ast::LitKind; -use rustc_data_structures::fx::FxHashMap; -use rustc_errors::Applicability; -use rustc_hir::def::CtorKind; -use rustc_hir::{ - Arm, BindingAnnotation, Block, BorrowKind, Expr, ExprKind, Guard, Local, MatchSource, Mutability, Node, Pat, - PatKind, QPath, RangeEnd, -}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, Ty, TyS}; -use rustc_semver::RustcVersion; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::{Span, Spanned}; -use rustc_span::{sym, Symbol}; -use std::cmp::Ordering; -use std::collections::hash_map::Entry; -use std::collections::Bound; - -declare_clippy_lint! { - /// **What it does:** Checks for matches with a single arm where an `if let` - /// will usually suffice. - /// - /// **Why is this bad?** Just readability – `if let` nests less than a `match`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # fn bar(stool: &str) {} - /// # let x = Some("abc"); - /// // Bad - /// match x { - /// Some(ref foo) => bar(foo), - /// _ => (), - /// } - /// - /// // Good - /// if let Some(ref foo) = x { - /// bar(foo); - /// } - /// ``` - pub SINGLE_MATCH, - style, - "a `match` statement with a single nontrivial arm (i.e., where the other arm is `_ => {}`) instead of `if let`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for matches with two arms where an `if let else` will - /// usually suffice. - /// - /// **Why is this bad?** Just readability – `if let` nests less than a `match`. - /// - /// **Known problems:** Personal style preferences may differ. - /// - /// **Example:** - /// - /// Using `match`: - /// - /// ```rust - /// # fn bar(foo: &usize) {} - /// # let other_ref: usize = 1; - /// # let x: Option<&usize> = Some(&1); - /// match x { - /// Some(ref foo) => bar(foo), - /// _ => bar(&other_ref), - /// } - /// ``` - /// - /// Using `if let` with `else`: - /// - /// ```rust - /// # fn bar(foo: &usize) {} - /// # let other_ref: usize = 1; - /// # let x: Option<&usize> = Some(&1); - /// if let Some(ref foo) = x { - /// bar(foo); - /// } else { - /// bar(&other_ref); - /// } - /// ``` - pub SINGLE_MATCH_ELSE, - pedantic, - "a `match` statement with two arms where the second arm's pattern is a placeholder instead of a specific match pattern" -} - -declare_clippy_lint! { - /// **What it does:** Checks for matches where all arms match a reference, - /// suggesting to remove the reference and deref the matched expression - /// instead. It also checks for `if let &foo = bar` blocks. - /// - /// **Why is this bad?** It just makes the code less readable. That reference - /// destructuring adds nothing to the code. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// // Bad - /// match x { - /// &A(ref y) => foo(y), - /// &B => bar(), - /// _ => frob(&x), - /// } - /// - /// // Good - /// match *x { - /// A(ref y) => foo(y), - /// B => bar(), - /// _ => frob(x), - /// } - /// ``` - pub MATCH_REF_PATS, - style, - "a `match` or `if let` with all arms prefixed with `&` instead of deref-ing the match expression" -} - -declare_clippy_lint! { - /// **What it does:** Checks for matches where match expression is a `bool`. It - /// suggests to replace the expression with an `if...else` block. - /// - /// **Why is this bad?** It makes the code less readable. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # fn foo() {} - /// # fn bar() {} - /// let condition: bool = true; - /// match condition { - /// true => foo(), - /// false => bar(), - /// } - /// ``` - /// Use if/else instead: - /// ```rust - /// # fn foo() {} - /// # fn bar() {} - /// let condition: bool = true; - /// if condition { - /// foo(); - /// } else { - /// bar(); - /// } - /// ``` - pub MATCH_BOOL, - pedantic, - "a `match` on a boolean expression instead of an `if..else` block" -} - -declare_clippy_lint! { - /// **What it does:** Checks for overlapping match arms. - /// - /// **Why is this bad?** It is likely to be an error and if not, makes the code - /// less obvious. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let x = 5; - /// match x { - /// 1...10 => println!("1 ... 10"), - /// 5...15 => println!("5 ... 15"), - /// _ => (), - /// } - /// ``` - pub MATCH_OVERLAPPING_ARM, - style, - "a `match` with overlapping arms" -} - -declare_clippy_lint! { - /// **What it does:** Checks for arm which matches all errors with `Err(_)` - /// and take drastic actions like `panic!`. - /// - /// **Why is this bad?** It is generally a bad practice, similar to - /// catching all exceptions in java with `catch(Exception)` - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let x: Result = Ok(3); - /// match x { - /// Ok(_) => println!("ok"), - /// Err(_) => panic!("err"), - /// } - /// ``` - pub MATCH_WILD_ERR_ARM, - pedantic, - "a `match` with `Err(_)` arm and take drastic actions" -} - -declare_clippy_lint! { - /// **What it does:** Checks for match which is used to add a reference to an - /// `Option` value. - /// - /// **Why is this bad?** Using `as_ref()` or `as_mut()` instead is shorter. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let x: Option<()> = None; - /// - /// // Bad - /// let r: Option<&()> = match x { - /// None => None, - /// Some(ref v) => Some(v), - /// }; - /// - /// // Good - /// let r: Option<&()> = x.as_ref(); - /// ``` - pub MATCH_AS_REF, - complexity, - "a `match` on an Option value instead of using `as_ref()` or `as_mut`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for wildcard enum matches using `_`. - /// - /// **Why is this bad?** New enum variants added by library updates can be missed. - /// - /// **Known problems:** Suggested replacements may be incorrect if guards exhaustively cover some - /// variants, and also may not use correct path to enum if it's not present in the current scope. - /// - /// **Example:** - /// ```rust - /// # enum Foo { A(usize), B(usize) } - /// # let x = Foo::B(1); - /// // Bad - /// match x { - /// Foo::A(_) => {}, - /// _ => {}, - /// } - /// - /// // Good - /// match x { - /// Foo::A(_) => {}, - /// Foo::B(_) => {}, - /// } - /// ``` - pub WILDCARD_ENUM_MATCH_ARM, - restriction, - "a wildcard enum match arm using `_`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for wildcard enum matches for a single variant. - /// - /// **Why is this bad?** New enum variants added by library updates can be missed. - /// - /// **Known problems:** Suggested replacements may not use correct path to enum - /// if it's not present in the current scope. - /// - /// **Example:** - /// - /// ```rust - /// # enum Foo { A, B, C } - /// # let x = Foo::B; - /// // Bad - /// match x { - /// Foo::A => {}, - /// Foo::B => {}, - /// _ => {}, - /// } - /// - /// // Good - /// match x { - /// Foo::A => {}, - /// Foo::B => {}, - /// Foo::C => {}, - /// } - /// ``` - pub MATCH_WILDCARD_FOR_SINGLE_VARIANTS, - pedantic, - "a wildcard enum match for a single variant" -} - -declare_clippy_lint! { - /// **What it does:** Checks for wildcard pattern used with others patterns in same match arm. - /// - /// **Why is this bad?** Wildcard pattern already covers any other pattern as it will match anyway. - /// It makes the code less readable, especially to spot wildcard pattern use in match arm. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// // Bad - /// match "foo" { - /// "a" => {}, - /// "bar" | _ => {}, - /// } - /// - /// // Good - /// match "foo" { - /// "a" => {}, - /// _ => {}, - /// } - /// ``` - pub WILDCARD_IN_OR_PATTERNS, - complexity, - "a wildcard pattern used with others patterns in same match arm" -} - -declare_clippy_lint! { - /// **What it does:** Checks for matches being used to destructure a single-variant enum - /// or tuple struct where a `let` will suffice. - /// - /// **Why is this bad?** Just readability – `let` doesn't nest, whereas a `match` does. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// enum Wrapper { - /// Data(i32), - /// } - /// - /// let wrapper = Wrapper::Data(42); - /// - /// let data = match wrapper { - /// Wrapper::Data(i) => i, - /// }; - /// ``` - /// - /// The correct use would be: - /// ```rust - /// enum Wrapper { - /// Data(i32), - /// } - /// - /// let wrapper = Wrapper::Data(42); - /// let Wrapper::Data(data) = wrapper; - /// ``` - pub INFALLIBLE_DESTRUCTURING_MATCH, - style, - "a `match` statement with a single infallible arm instead of a `let`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for useless match that binds to only one value. - /// - /// **Why is this bad?** Readability and needless complexity. - /// - /// **Known problems:** Suggested replacements may be incorrect when `match` - /// is actually binding temporary value, bringing a 'dropped while borrowed' error. - /// - /// **Example:** - /// ```rust - /// # let a = 1; - /// # let b = 2; - /// - /// // Bad - /// match (a, b) { - /// (c, d) => { - /// // useless match - /// } - /// } - /// - /// // Good - /// let (c, d) = (a, b); - /// ``` - pub MATCH_SINGLE_BINDING, - complexity, - "a match with a single binding instead of using `let` statement" -} - -declare_clippy_lint! { - /// **What it does:** Checks for unnecessary '..' pattern binding on struct when all fields are explicitly matched. - /// - /// **Why is this bad?** Correctness and readability. It's like having a wildcard pattern after - /// matching all enum variants explicitly. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # struct A { a: i32 } - /// let a = A { a: 5 }; - /// - /// // Bad - /// match a { - /// A { a: 5, .. } => {}, - /// _ => {}, - /// } - /// - /// // Good - /// match a { - /// A { a: 5 } => {}, - /// _ => {}, - /// } - /// ``` - pub REST_PAT_IN_FULLY_BOUND_STRUCTS, - restriction, - "a match on a struct that binds all fields but still uses the wildcard pattern" -} - -declare_clippy_lint! { - /// **What it does:** Lint for redundant pattern matching over `Result`, `Option`, - /// `std::task::Poll` or `std::net::IpAddr` - /// - /// **Why is this bad?** It's more concise and clear to just use the proper - /// utility function - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// # use std::task::Poll; - /// # use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; - /// if let Ok(_) = Ok::(42) {} - /// if let Err(_) = Err::(42) {} - /// if let None = None::<()> {} - /// if let Some(_) = Some(42) {} - /// if let Poll::Pending = Poll::Pending::<()> {} - /// if let Poll::Ready(_) = Poll::Ready(42) {} - /// if let IpAddr::V4(_) = IpAddr::V4(Ipv4Addr::LOCALHOST) {} - /// if let IpAddr::V6(_) = IpAddr::V6(Ipv6Addr::LOCALHOST) {} - /// match Ok::(42) { - /// Ok(_) => true, - /// Err(_) => false, - /// }; - /// ``` - /// - /// The more idiomatic use would be: - /// - /// ```rust - /// # use std::task::Poll; - /// # use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; - /// if Ok::(42).is_ok() {} - /// if Err::(42).is_err() {} - /// if None::<()>.is_none() {} - /// if Some(42).is_some() {} - /// if Poll::Pending::<()>.is_pending() {} - /// if Poll::Ready(42).is_ready() {} - /// if IpAddr::V4(Ipv4Addr::LOCALHOST).is_ipv4() {} - /// if IpAddr::V6(Ipv6Addr::LOCALHOST).is_ipv6() {} - /// Ok::(42).is_ok(); - /// ``` - pub REDUNDANT_PATTERN_MATCHING, - style, - "use the proper utility function avoiding an `if let`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `match` or `if let` expressions producing a - /// `bool` that could be written using `matches!` - /// - /// **Why is this bad?** Readability and needless complexity. - /// - /// **Known problems:** This lint falsely triggers, if there are arms with - /// `cfg` attributes that remove an arm evaluating to `false`. - /// - /// **Example:** - /// ```rust - /// let x = Some(5); - /// - /// // Bad - /// let a = match x { - /// Some(0) => true, - /// _ => false, - /// }; - /// - /// let a = if let Some(0) = x { - /// true - /// } else { - /// false - /// }; - /// - /// // Good - /// let a = matches!(x, Some(0)); - /// ``` - pub MATCH_LIKE_MATCHES_MACRO, - style, - "a match that could be written with the matches! macro" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `match` with identical arm bodies. - /// - /// **Why is this bad?** This is probably a copy & paste error. If arm bodies - /// are the same on purpose, you can factor them - /// [using `|`](https://doc.rust-lang.org/book/patterns.html#multiple-patterns). - /// - /// **Known problems:** False positive possible with order dependent `match` - /// (see issue - /// [#860](https://github.com/rust-lang/rust-clippy/issues/860)). - /// - /// **Example:** - /// ```rust,ignore - /// match foo { - /// Bar => bar(), - /// Quz => quz(), - /// Baz => bar(), // <= oops - /// } - /// ``` - /// - /// This should probably be - /// ```rust,ignore - /// match foo { - /// Bar => bar(), - /// Quz => quz(), - /// Baz => baz(), // <= fixed - /// } - /// ``` - /// - /// or if the original code was not a typo: - /// ```rust,ignore - /// match foo { - /// Bar | Baz => bar(), // <= shows the intent better - /// Quz => quz(), - /// } - /// ``` - pub MATCH_SAME_ARMS, - pedantic, - "`match` with identical arm bodies" -} - -#[derive(Default)] -pub struct Matches { - msrv: Option, - infallible_destructuring_match_linted: bool, -} - -impl Matches { - #[must_use] - pub fn new(msrv: Option) -> Self { - Self { - msrv, - ..Matches::default() - } - } -} - -impl_lint_pass!(Matches => [ - SINGLE_MATCH, - MATCH_REF_PATS, - MATCH_BOOL, - SINGLE_MATCH_ELSE, - MATCH_OVERLAPPING_ARM, - MATCH_WILD_ERR_ARM, - MATCH_AS_REF, - WILDCARD_ENUM_MATCH_ARM, - MATCH_WILDCARD_FOR_SINGLE_VARIANTS, - WILDCARD_IN_OR_PATTERNS, - MATCH_SINGLE_BINDING, - INFALLIBLE_DESTRUCTURING_MATCH, - REST_PAT_IN_FULLY_BOUND_STRUCTS, - REDUNDANT_PATTERN_MATCHING, - MATCH_LIKE_MATCHES_MACRO, - MATCH_SAME_ARMS, -]); - -const MATCH_LIKE_MATCHES_MACRO_MSRV: RustcVersion = RustcVersion::new(1, 42, 0); - -impl<'tcx> LateLintPass<'tcx> for Matches { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if in_external_macro(cx.sess(), expr.span) || in_macro(expr.span) { - return; - } - - redundant_pattern_match::check(cx, expr); - - if meets_msrv(self.msrv.as_ref(), &MATCH_LIKE_MATCHES_MACRO_MSRV) { - if !check_match_like_matches(cx, expr) { - lint_match_arms(cx, expr); - } - } else { - lint_match_arms(cx, expr); - } - - if let ExprKind::Match(ref ex, ref arms, MatchSource::Normal) = expr.kind { - check_single_match(cx, ex, arms, expr); - check_match_bool(cx, ex, arms, expr); - check_overlapping_arms(cx, ex, arms); - check_wild_err_arm(cx, ex, arms); - check_wild_enum_match(cx, ex, arms); - check_match_as_ref(cx, ex, arms, expr); - check_wild_in_or_pats(cx, arms); - - if self.infallible_destructuring_match_linted { - self.infallible_destructuring_match_linted = false; - } else { - check_match_single_binding(cx, ex, arms, expr); - } - } - if let ExprKind::Match(ref ex, ref arms, _) = expr.kind { - check_match_ref_pats(cx, ex, arms, expr); - } - } - - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'_>) { - if_chain! { - if !in_external_macro(cx.sess(), local.span); - if !in_macro(local.span); - if let Some(ref expr) = local.init; - if let ExprKind::Match(ref target, ref arms, MatchSource::Normal) = expr.kind; - if arms.len() == 1 && arms[0].guard.is_none(); - if let PatKind::TupleStruct( - QPath::Resolved(None, ref variant_name), ref args, _) = arms[0].pat.kind; - if args.len() == 1; - if let Some(arg) = get_arg_name(&args[0]); - let body = remove_blocks(&arms[0].body); - if match_var(body, arg); - - then { - let mut applicability = Applicability::MachineApplicable; - self.infallible_destructuring_match_linted = true; - span_lint_and_sugg( - cx, - INFALLIBLE_DESTRUCTURING_MATCH, - local.span, - "you seem to be trying to use `match` to destructure a single infallible pattern. \ - Consider using `let`", - "try this", - format!( - "let {}({}) = {};", - snippet_with_applicability(cx, variant_name.span, "..", &mut applicability), - snippet_with_applicability(cx, local.pat.span, "..", &mut applicability), - snippet_with_applicability(cx, target.span, "..", &mut applicability), - ), - applicability, - ); - } - } - } - - fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { - if_chain! { - if !in_external_macro(cx.sess(), pat.span); - if !in_macro(pat.span); - if let PatKind::Struct(QPath::Resolved(_, ref path), fields, true) = pat.kind; - if let Some(def_id) = path.res.opt_def_id(); - let ty = cx.tcx.type_of(def_id); - if let ty::Adt(def, _) = ty.kind(); - if def.is_struct() || def.is_union(); - if fields.len() == def.non_enum_variant().fields.len(); - - then { - span_lint_and_help( - cx, - REST_PAT_IN_FULLY_BOUND_STRUCTS, - pat.span, - "unnecessary use of `..` pattern in struct binding. All fields were already bound", - None, - "consider removing `..` from this binding", - ); - } - } - } - - extract_msrv_attr!(LateContext); -} - -#[rustfmt::skip] -fn check_single_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { - if arms.len() == 2 && arms[0].guard.is_none() && arms[1].guard.is_none() { - if in_macro(expr.span) { - // Don't lint match expressions present in - // macro_rules! block - return; - } - if let PatKind::Or(..) = arms[0].pat.kind { - // don't lint for or patterns for now, this makes - // the lint noisy in unnecessary situations - return; - } - let els = arms[1].body; - let els = if is_unit_expr(remove_blocks(els)) { - None - } else if let ExprKind::Block(Block { stmts, expr: block_expr, .. }, _) = els.kind { - if stmts.len() == 1 && block_expr.is_none() || stmts.is_empty() && block_expr.is_some() { - // single statement/expr "else" block, don't lint - return; - } - // block with 2+ statements or 1 expr and 1+ statement - Some(els) - } else { - // not a block, don't lint - return; - }; - - let ty = cx.typeck_results().expr_ty(ex); - if *ty.kind() != ty::Bool || is_allowed(cx, MATCH_BOOL, ex.hir_id) { - check_single_match_single_pattern(cx, ex, arms, expr, els); - check_single_match_opt_like(cx, ex, arms, expr, ty, els); - } - } -} - -fn check_single_match_single_pattern( - cx: &LateContext<'_>, - ex: &Expr<'_>, - arms: &[Arm<'_>], - expr: &Expr<'_>, - els: Option<&Expr<'_>>, -) { - if is_wild(&arms[1].pat) { - report_single_match_single_pattern(cx, ex, arms, expr, els); - } -} - -fn report_single_match_single_pattern( - cx: &LateContext<'_>, - ex: &Expr<'_>, - arms: &[Arm<'_>], - expr: &Expr<'_>, - els: Option<&Expr<'_>>, -) { - let lint = if els.is_some() { SINGLE_MATCH_ELSE } else { SINGLE_MATCH }; - let els_str = els.map_or(String::new(), |els| { - format!(" else {}", expr_block(cx, els, None, "..", Some(expr.span))) - }); - span_lint_and_sugg( - cx, - lint, - expr.span, - "you seem to be trying to use match for destructuring a single pattern. Consider using `if \ - let`", - "try this", - format!( - "if let {} = {} {}{}", - snippet(cx, arms[0].pat.span, ".."), - snippet(cx, ex.span, ".."), - expr_block(cx, &arms[0].body, None, "..", Some(expr.span)), - els_str, - ), - Applicability::HasPlaceholders, - ); -} - -fn check_single_match_opt_like( - cx: &LateContext<'_>, - ex: &Expr<'_>, - arms: &[Arm<'_>], - expr: &Expr<'_>, - ty: Ty<'_>, - els: Option<&Expr<'_>>, -) { - // list of candidate `Enum`s we know will never get any more members - let candidates = &[ - (&paths::COW, "Borrowed"), - (&paths::COW, "Cow::Borrowed"), - (&paths::COW, "Cow::Owned"), - (&paths::COW, "Owned"), - (&paths::OPTION, "None"), - (&paths::RESULT, "Err"), - (&paths::RESULT, "Ok"), - ]; - - let path = match arms[1].pat.kind { - PatKind::TupleStruct(ref path, ref inner, _) => { - // Contains any non wildcard patterns (e.g., `Err(err)`)? - if !inner.iter().all(is_wild) { - return; - } - rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false)) - }, - PatKind::Binding(BindingAnnotation::Unannotated, .., ident, None) => ident.to_string(), - PatKind::Path(ref path) => { - rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false)) - }, - _ => return, - }; - - for &(ty_path, pat_path) in candidates { - if path == *pat_path && match_type(cx, ty, ty_path) { - report_single_match_single_pattern(cx, ex, arms, expr, els); - } - } -} - -fn check_match_bool(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { - // Type of expression is `bool`. - if *cx.typeck_results().expr_ty(ex).kind() == ty::Bool { - span_lint_and_then( - cx, - MATCH_BOOL, - expr.span, - "you seem to be trying to match on a boolean expression", - move |diag| { - if arms.len() == 2 { - // no guards - let exprs = if let PatKind::Lit(ref arm_bool) = arms[0].pat.kind { - if let ExprKind::Lit(ref lit) = arm_bool.kind { - match lit.node { - LitKind::Bool(true) => Some((&*arms[0].body, &*arms[1].body)), - LitKind::Bool(false) => Some((&*arms[1].body, &*arms[0].body)), - _ => None, - } - } else { - None - } - } else { - None - }; - - if let Some((true_expr, false_expr)) = exprs { - let sugg = match (is_unit_expr(true_expr), is_unit_expr(false_expr)) { - (false, false) => Some(format!( - "if {} {} else {}", - snippet(cx, ex.span, "b"), - expr_block(cx, true_expr, None, "..", Some(expr.span)), - expr_block(cx, false_expr, None, "..", Some(expr.span)) - )), - (false, true) => Some(format!( - "if {} {}", - snippet(cx, ex.span, "b"), - expr_block(cx, true_expr, None, "..", Some(expr.span)) - )), - (true, false) => { - let test = Sugg::hir(cx, ex, ".."); - Some(format!( - "if {} {}", - !test, - expr_block(cx, false_expr, None, "..", Some(expr.span)) - )) - }, - (true, true) => None, - }; - - if let Some(sugg) = sugg { - diag.span_suggestion( - expr.span, - "consider using an `if`/`else` expression", - sugg, - Applicability::HasPlaceholders, - ); - } - } - } - }, - ); - } -} - -fn check_overlapping_arms<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'_>, arms: &'tcx [Arm<'_>]) { - if arms.len() >= 2 && cx.typeck_results().expr_ty(ex).is_integral() { - let ranges = all_ranges(cx, arms, cx.typeck_results().expr_ty(ex)); - let type_ranges = type_ranges(&ranges); - if !type_ranges.is_empty() { - if let Some((start, end)) = overlapping(&type_ranges) { - span_lint_and_note( - cx, - MATCH_OVERLAPPING_ARM, - start.span, - "some ranges overlap", - Some(end.span), - "overlaps with this", - ); - } - } - } -} - -fn check_wild_err_arm(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { - let ex_ty = cx.typeck_results().expr_ty(ex).peel_refs(); - if is_type_diagnostic_item(cx, ex_ty, sym::result_type) { - for arm in arms { - if let PatKind::TupleStruct(ref path, ref inner, _) = arm.pat.kind { - let path_str = rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false)); - if path_str == "Err" { - let mut matching_wild = inner.iter().any(is_wild); - let mut ident_bind_name = String::from("_"); - if !matching_wild { - // Looking for unused bindings (i.e.: `_e`) - inner.iter().for_each(|pat| { - if let PatKind::Binding(.., ident, None) = &pat.kind { - if ident.as_str().starts_with('_') && is_unused(ident, arm.body) { - ident_bind_name = (&ident.name.as_str()).to_string(); - matching_wild = true; - } - } - }); - } - if_chain! { - if matching_wild; - if let ExprKind::Block(ref block, _) = arm.body.kind; - if is_panic_block(block); - then { - // `Err(_)` or `Err(_e)` arm with `panic!` found - span_lint_and_note(cx, - MATCH_WILD_ERR_ARM, - arm.pat.span, - &format!("`Err({})` matches all errors", &ident_bind_name), - None, - "match each error separately or use the error output, or use `.except(msg)` if the error case is unreachable", - ); - } - } - } - } - } - } -} - -fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { - let ty = cx.typeck_results().expr_ty(ex); - if !ty.is_enum() { - // If there isn't a nice closed set of possible values that can be conveniently enumerated, - // don't complain about not enumerating the mall. - return; - } - - // First pass - check for violation, but don't do much book-keeping because this is hopefully - // the uncommon case, and the book-keeping is slightly expensive. - let mut wildcard_span = None; - let mut wildcard_ident = None; - for arm in arms { - if let PatKind::Wild = arm.pat.kind { - wildcard_span = Some(arm.pat.span); - } else if let PatKind::Binding(_, _, ident, None) = arm.pat.kind { - wildcard_span = Some(arm.pat.span); - wildcard_ident = Some(ident); - } - } - - if let Some(wildcard_span) = wildcard_span { - // Accumulate the variants which should be put in place of the wildcard because they're not - // already covered. - - let mut missing_variants = vec![]; - if let ty::Adt(def, _) = ty.kind() { - for variant in &def.variants { - missing_variants.push(variant); - } - } - - for arm in arms { - if arm.guard.is_some() { - // Guards mean that this case probably isn't exhaustively covered. Technically - // this is incorrect, as we should really check whether each variant is exhaustively - // covered by the set of guards that cover it, but that's really hard to do. - continue; - } - if let PatKind::Path(ref path) = arm.pat.kind { - if let QPath::Resolved(_, p) = path { - missing_variants.retain(|e| e.ctor_def_id != Some(p.res.def_id())); - } - } else if let PatKind::TupleStruct(QPath::Resolved(_, p), ref patterns, ..) = arm.pat.kind { - // Some simple checks for exhaustive patterns. - // There is a room for improvements to detect more cases, - // but it can be more expensive to do so. - let is_pattern_exhaustive = - |pat: &&Pat<'_>| matches!(pat.kind, PatKind::Wild | PatKind::Binding(.., None)); - if patterns.iter().all(is_pattern_exhaustive) { - missing_variants.retain(|e| e.ctor_def_id != Some(p.res.def_id())); - } - } - } - - let mut suggestion: Vec = missing_variants - .iter() - .map(|v| { - let suffix = match v.ctor_kind { - CtorKind::Fn => "(..)", - CtorKind::Const | CtorKind::Fictive => "", - }; - let ident_str = if let Some(ident) = wildcard_ident { - format!("{} @ ", ident.name) - } else { - String::new() - }; - // This path assumes that the enum type is imported into scope. - format!("{}{}{}", ident_str, cx.tcx.def_path_str(v.def_id), suffix) - }) - .collect(); - - if suggestion.is_empty() { - return; - } - - let mut message = "wildcard match will miss any future added variants"; - - if let ty::Adt(def, _) = ty.kind() { - if def.is_variant_list_non_exhaustive() { - message = "match on non-exhaustive enum doesn't explicitly match all known variants"; - suggestion.push(String::from("_")); - } - } - - if suggestion.len() == 1 { - // No need to check for non-exhaustive enum as in that case len would be greater than 1 - span_lint_and_sugg( - cx, - MATCH_WILDCARD_FOR_SINGLE_VARIANTS, - wildcard_span, - message, - "try this", - suggestion[0].clone(), - Applicability::MaybeIncorrect, - ) - }; - - span_lint_and_sugg( - cx, - WILDCARD_ENUM_MATCH_ARM, - wildcard_span, - message, - "try this", - suggestion.join(" | "), - Applicability::MaybeIncorrect, - ) - } -} - -// If the block contains only a `panic!` macro (as expression or statement) -fn is_panic_block(block: &Block<'_>) -> bool { - match (&block.expr, block.stmts.len(), block.stmts.first()) { - (&Some(ref exp), 0, _) => { - is_expn_of(exp.span, "panic").is_some() && is_expn_of(exp.span, "unreachable").is_none() - }, - (&None, 1, Some(stmt)) => { - is_expn_of(stmt.span, "panic").is_some() && is_expn_of(stmt.span, "unreachable").is_none() - }, - _ => false, - } -} - -fn check_match_ref_pats(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { - if has_only_ref_pats(arms) { - let mut suggs = Vec::with_capacity(arms.len() + 1); - let (title, msg) = if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = ex.kind { - let span = ex.span.source_callsite(); - suggs.push((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string())); - ( - "you don't need to add `&` to both the expression and the patterns", - "try", - ) - } else { - let span = ex.span.source_callsite(); - suggs.push((span, Sugg::hir_with_macro_callsite(cx, ex, "..").deref().to_string())); - ( - "you don't need to add `&` to all patterns", - "instead of prefixing all patterns with `&`, you can dereference the expression", - ) - }; - - suggs.extend(arms.iter().filter_map(|a| { - if let PatKind::Ref(ref refp, _) = a.pat.kind { - Some((a.pat.span, snippet(cx, refp.span, "..").to_string())) - } else { - None - } - })); - - span_lint_and_then(cx, MATCH_REF_PATS, expr.span, title, |diag| { - if !expr.span.from_expansion() { - multispan_sugg(diag, msg, suggs); - } - }); - } -} - -fn check_match_as_ref(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { - if arms.len() == 2 && arms[0].guard.is_none() && arms[1].guard.is_none() { - let arm_ref: Option = if is_none_arm(&arms[0]) { - is_ref_some_arm(&arms[1]) - } else if is_none_arm(&arms[1]) { - is_ref_some_arm(&arms[0]) - } else { - None - }; - if let Some(rb) = arm_ref { - let suggestion = if rb == BindingAnnotation::Ref { - "as_ref" - } else { - "as_mut" - }; - - let output_ty = cx.typeck_results().expr_ty(expr); - let input_ty = cx.typeck_results().expr_ty(ex); - - let cast = if_chain! { - if let ty::Adt(_, substs) = input_ty.kind(); - let input_ty = substs.type_at(0); - if let ty::Adt(_, substs) = output_ty.kind(); - let output_ty = substs.type_at(0); - if let ty::Ref(_, output_ty, _) = *output_ty.kind(); - if input_ty != output_ty; - then { - ".map(|x| x as _)" - } else { - "" - } - }; - - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - MATCH_AS_REF, - expr.span, - &format!("use `{}()` instead", suggestion), - "try this", - format!( - "{}.{}(){}", - snippet_with_applicability(cx, ex.span, "_", &mut applicability), - suggestion, - cast, - ), - applicability, - ) - } - } -} - -fn check_wild_in_or_pats(cx: &LateContext<'_>, arms: &[Arm<'_>]) { - for arm in arms { - if let PatKind::Or(ref fields) = arm.pat.kind { - // look for multiple fields in this arm that contains at least one Wild pattern - if fields.len() > 1 && fields.iter().any(is_wild) { - span_lint_and_help( - cx, - WILDCARD_IN_OR_PATTERNS, - arm.pat.span, - "wildcard pattern covers any other pattern as it will match anyway.", - None, - "Consider handling `_` separately.", - ); - } - } - } -} - -/// Lint a `match` or `if let .. { .. } else { .. }` expr that could be replaced by `matches!` -fn check_match_like_matches<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool { - if let ExprKind::Match(ex, arms, ref match_source) = &expr.kind { - match match_source { - MatchSource::Normal => find_matches_sugg(cx, ex, arms, expr, false), - MatchSource::IfLetDesugar { .. } => find_matches_sugg(cx, ex, arms, expr, true), - _ => false, - } - } else { - false - } -} - -/// Lint a `match` or desugared `if let` for replacement by `matches!` -fn find_matches_sugg(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>, desugared: bool) -> bool { - if_chain! { - if arms.len() >= 2; - if cx.typeck_results().expr_ty(expr).is_bool(); - if let Some((b1_arm, b0_arms)) = arms.split_last(); - if let Some(b0) = find_bool_lit(&b0_arms[0].body.kind, desugared); - if let Some(b1) = find_bool_lit(&b1_arm.body.kind, desugared); - if is_wild(&b1_arm.pat); - if b0 != b1; - let if_guard = &b0_arms[0].guard; - if if_guard.is_none() || b0_arms.len() == 1; - if b0_arms[0].attrs.is_empty(); - if b0_arms[1..].iter() - .all(|arm| { - find_bool_lit(&arm.body.kind, desugared).map_or(false, |b| b == b0) && - arm.guard.is_none() && arm.attrs.is_empty() - }); - then { - // The suggestion may be incorrect, because some arms can have `cfg` attributes - // evaluated into `false` and so such arms will be stripped before. - let mut applicability = Applicability::MaybeIncorrect; - let pat = { - use itertools::Itertools as _; - b0_arms.iter() - .map(|arm| snippet_with_applicability(cx, arm.pat.span, "..", &mut applicability)) - .join(" | ") - }; - let pat_and_guard = if let Some(Guard::If(g)) = if_guard { - format!("{} if {}", pat, snippet_with_applicability(cx, g.span, "..", &mut applicability)) - } else { - pat - }; - span_lint_and_sugg( - cx, - MATCH_LIKE_MATCHES_MACRO, - expr.span, - &format!("{} expression looks like `matches!` macro", if desugared { "if let .. else" } else { "match" }), - "try this", - format!( - "{}matches!({}, {})", - if b0 { "" } else { "!" }, - snippet_with_applicability(cx, ex.span, "..", &mut applicability), - pat_and_guard, - ), - applicability, - ); - true - } else { - false - } - } -} - -/// Extract a `bool` or `{ bool }` -fn find_bool_lit(ex: &ExprKind<'_>, desugared: bool) -> Option { - match ex { - ExprKind::Lit(Spanned { - node: LitKind::Bool(b), .. - }) => Some(*b), - ExprKind::Block( - rustc_hir::Block { - stmts: &[], - expr: Some(exp), - .. - }, - _, - ) if desugared => { - if let ExprKind::Lit(Spanned { - node: LitKind::Bool(b), .. - }) = exp.kind - { - Some(b) - } else { - None - } - }, - _ => None, - } -} - -fn check_match_single_binding<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], expr: &Expr<'_>) { - if in_macro(expr.span) || arms.len() != 1 || is_refutable(cx, arms[0].pat) { - return; - } - - // HACK: - // This is a hack to deal with arms that are excluded by macros like `#[cfg]`. It is only used here - // to prevent false positives as there is currently no better way to detect if code was excluded by - // a macro. See PR #6435 - if_chain! { - if let Some(match_snippet) = snippet_opt(cx, expr.span); - if let Some(arm_snippet) = snippet_opt(cx, arms[0].span); - if let Some(ex_snippet) = snippet_opt(cx, ex.span); - let rest_snippet = match_snippet.replace(&arm_snippet, "").replace(&ex_snippet, ""); - if rest_snippet.contains("=>"); - then { - // The code it self contains another thick arrow "=>" - // -> Either another arm or a comment - return; - } - } - - let matched_vars = ex.span; - let bind_names = arms[0].pat.span; - let match_body = remove_blocks(&arms[0].body); - let mut snippet_body = if match_body.span.from_expansion() { - Sugg::hir_with_macro_callsite(cx, match_body, "..").to_string() - } else { - snippet_block(cx, match_body.span, "..", Some(expr.span)).to_string() - }; - - // Do we need to add ';' to suggestion ? - match match_body.kind { - ExprKind::Block(block, _) => { - // macro + expr_ty(body) == () - if block.span.from_expansion() && cx.typeck_results().expr_ty(&match_body).is_unit() { - snippet_body.push(';'); - } - }, - _ => { - // expr_ty(body) == () - if cx.typeck_results().expr_ty(&match_body).is_unit() { - snippet_body.push(';'); - } - }, - } - - let mut applicability = Applicability::MaybeIncorrect; - match arms[0].pat.kind { - PatKind::Binding(..) | PatKind::Tuple(_, _) | PatKind::Struct(..) => { - // If this match is in a local (`let`) stmt - let (target_span, sugg) = if let Some(parent_let_node) = opt_parent_let(cx, ex) { - ( - parent_let_node.span, - format!( - "let {} = {};\n{}let {} = {};", - snippet_with_applicability(cx, bind_names, "..", &mut applicability), - snippet_with_applicability(cx, matched_vars, "..", &mut applicability), - " ".repeat(indent_of(cx, expr.span).unwrap_or(0)), - snippet_with_applicability(cx, parent_let_node.pat.span, "..", &mut applicability), - snippet_body - ), - ) - } else { - // If we are in closure, we need curly braces around suggestion - let mut indent = " ".repeat(indent_of(cx, ex.span).unwrap_or(0)); - let (mut cbrace_start, mut cbrace_end) = ("".to_string(), "".to_string()); - if let Some(parent_expr) = get_parent_expr(cx, expr) { - if let ExprKind::Closure(..) = parent_expr.kind { - cbrace_end = format!("\n{}}}", indent); - // Fix body indent due to the closure - indent = " ".repeat(indent_of(cx, bind_names).unwrap_or(0)); - cbrace_start = format!("{{\n{}", indent); - } - }; - ( - expr.span, - format!( - "{}let {} = {};\n{}{}{}", - cbrace_start, - snippet_with_applicability(cx, bind_names, "..", &mut applicability), - snippet_with_applicability(cx, matched_vars, "..", &mut applicability), - indent, - snippet_body, - cbrace_end - ), - ) - }; - span_lint_and_sugg( - cx, - MATCH_SINGLE_BINDING, - target_span, - "this match could be written as a `let` statement", - "consider using `let` statement", - sugg, - applicability, - ); - }, - PatKind::Wild => { - span_lint_and_sugg( - cx, - MATCH_SINGLE_BINDING, - expr.span, - "this match could be replaced by its body itself", - "consider using the match body instead", - snippet_body, - Applicability::MachineApplicable, - ); - }, - _ => (), - } -} - -/// Returns true if the `ex` match expression is in a local (`let`) statement -fn opt_parent_let<'a>(cx: &LateContext<'a>, ex: &Expr<'a>) -> Option<&'a Local<'a>> { - if_chain! { - let map = &cx.tcx.hir(); - if let Some(Node::Expr(parent_arm_expr)) = map.find(map.get_parent_node(ex.hir_id)); - if let Some(Node::Local(parent_let_expr)) = map.find(map.get_parent_node(parent_arm_expr.hir_id)); - then { - return Some(parent_let_expr); - } - } - None -} - -/// Gets all arms that are unbounded `PatRange`s. -fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>) -> Vec> { - arms.iter() - .flat_map(|arm| { - if let Arm { - ref pat, guard: None, .. - } = *arm - { - if let PatKind::Range(ref lhs, ref rhs, range_end) = pat.kind { - let lhs = match lhs { - Some(lhs) => constant(cx, cx.typeck_results(), lhs)?.0, - None => miri_to_const(ty.numeric_min_val(cx.tcx)?)?, - }; - let rhs = match rhs { - Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0, - None => miri_to_const(ty.numeric_max_val(cx.tcx)?)?, - }; - let rhs = match range_end { - RangeEnd::Included => Bound::Included(rhs), - RangeEnd::Excluded => Bound::Excluded(rhs), - }; - return Some(SpannedRange { - span: pat.span, - node: (lhs, rhs), - }); - } - - if let PatKind::Lit(ref value) = pat.kind { - let value = constant(cx, cx.typeck_results(), value)?.0; - return Some(SpannedRange { - span: pat.span, - node: (value.clone(), Bound::Included(value)), - }); - } - } - None - }) - .collect() -} - -#[derive(Debug, Eq, PartialEq)] -pub struct SpannedRange { - pub span: Span, - pub node: (T, Bound), -} - -type TypedRanges = Vec>; - -/// Gets all `Int` ranges or all `Uint` ranges. Mixed types are an error anyway -/// and other types than -/// `Uint` and `Int` probably don't make sense. -fn type_ranges(ranges: &[SpannedRange]) -> TypedRanges { - ranges - .iter() - .filter_map(|range| match range.node { - (Constant::Int(start), Bound::Included(Constant::Int(end))) => Some(SpannedRange { - span: range.span, - node: (start, Bound::Included(end)), - }), - (Constant::Int(start), Bound::Excluded(Constant::Int(end))) => Some(SpannedRange { - span: range.span, - node: (start, Bound::Excluded(end)), - }), - (Constant::Int(start), Bound::Unbounded) => Some(SpannedRange { - span: range.span, - node: (start, Bound::Unbounded), - }), - _ => None, - }) - .collect() -} - -fn is_unit_expr(expr: &Expr<'_>) -> bool { - match expr.kind { - ExprKind::Tup(ref v) if v.is_empty() => true, - ExprKind::Block(ref b, _) if b.stmts.is_empty() && b.expr.is_none() => true, - _ => false, - } -} - -// Checks if arm has the form `None => None` -fn is_none_arm(arm: &Arm<'_>) -> bool { - matches!(arm.pat.kind, PatKind::Path(ref path) if match_qpath(path, &paths::OPTION_NONE)) -} - -// Checks if arm has the form `Some(ref v) => Some(v)` (checks for `ref` and `ref mut`) -fn is_ref_some_arm(arm: &Arm<'_>) -> Option { - if_chain! { - if let PatKind::TupleStruct(ref path, ref pats, _) = arm.pat.kind; - if pats.len() == 1 && match_qpath(path, &paths::OPTION_SOME); - if let PatKind::Binding(rb, .., ident, _) = pats[0].kind; - if rb == BindingAnnotation::Ref || rb == BindingAnnotation::RefMut; - if let ExprKind::Call(ref e, ref args) = remove_blocks(&arm.body).kind; - if let ExprKind::Path(ref some_path) = e.kind; - if match_qpath(some_path, &paths::OPTION_SOME) && args.len() == 1; - if let ExprKind::Path(QPath::Resolved(_, ref path2)) = args[0].kind; - if path2.segments.len() == 1 && ident.name == path2.segments[0].ident.name; - then { - return Some(rb) - } - } - None -} - -fn has_only_ref_pats(arms: &[Arm<'_>]) -> bool { - let mapped = arms - .iter() - .map(|a| { - match a.pat.kind { - PatKind::Ref(..) => Some(true), // &-patterns - PatKind::Wild => Some(false), // an "anything" wildcard is also fine - _ => None, // any other pattern is not fine - } - }) - .collect::>>(); - // look for Some(v) where there's at least one true element - mapped.map_or(false, |v| v.iter().any(|el| *el)) -} - -pub fn overlapping(ranges: &[SpannedRange]) -> Option<(&SpannedRange, &SpannedRange)> -where - T: Copy + Ord, -{ - #[derive(Copy, Clone, Debug, Eq, PartialEq)] - enum Kind<'a, T> { - Start(T, &'a SpannedRange), - End(Bound, &'a SpannedRange), - } - - impl<'a, T: Copy> Kind<'a, T> { - fn range(&self) -> &'a SpannedRange { - match *self { - Kind::Start(_, r) | Kind::End(_, r) => r, - } - } - - fn value(self) -> Bound { - match self { - Kind::Start(t, _) => Bound::Included(t), - Kind::End(t, _) => t, - } - } - } - - impl<'a, T: Copy + Ord> PartialOrd for Kind<'a, T> { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } - } - - impl<'a, T: Copy + Ord> Ord for Kind<'a, T> { - fn cmp(&self, other: &Self) -> Ordering { - match (self.value(), other.value()) { - (Bound::Included(a), Bound::Included(b)) | (Bound::Excluded(a), Bound::Excluded(b)) => a.cmp(&b), - // Range patterns cannot be unbounded (yet) - (Bound::Unbounded, _) | (_, Bound::Unbounded) => unimplemented!(), - (Bound::Included(a), Bound::Excluded(b)) => match a.cmp(&b) { - Ordering::Equal => Ordering::Greater, - other => other, - }, - (Bound::Excluded(a), Bound::Included(b)) => match a.cmp(&b) { - Ordering::Equal => Ordering::Less, - other => other, - }, - } - } - } - - let mut values = Vec::with_capacity(2 * ranges.len()); - - for r in ranges { - values.push(Kind::Start(r.node.0, r)); - values.push(Kind::End(r.node.1, r)); - } - - values.sort(); - - for (a, b) in values.iter().zip(values.iter().skip(1)) { - match (a, b) { - (&Kind::Start(_, ra), &Kind::End(_, rb)) => { - if ra.node != rb.node { - return Some((ra, rb)); - } - }, - (&Kind::End(a, _), &Kind::Start(b, _)) if a != Bound::Included(b) => (), - _ => return Some((a.range(), b.range())), - } - } - - None -} - -mod redundant_pattern_match { - use super::REDUNDANT_PATTERN_MATCHING; - use crate::utils::{match_qpath, match_trait_method, paths, snippet, span_lint_and_then}; - use if_chain::if_chain; - use rustc_ast::ast::LitKind; - use rustc_errors::Applicability; - use rustc_hir::{Arm, Expr, ExprKind, MatchSource, PatKind, QPath}; - use rustc_lint::LateContext; - use rustc_span::sym; - - pub fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Match(op, arms, ref match_source) = &expr.kind { - match match_source { - MatchSource::Normal => find_sugg_for_match(cx, expr, op, arms), - MatchSource::IfLetDesugar { .. } => find_sugg_for_if_let(cx, expr, op, arms, "if"), - MatchSource::WhileLetDesugar => find_sugg_for_if_let(cx, expr, op, arms, "while"), - _ => {}, - } - } - } - - fn find_sugg_for_if_let<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx Expr<'_>, - op: &Expr<'_>, - arms: &[Arm<'_>], - keyword: &'static str, - ) { - let good_method = match arms[0].pat.kind { - PatKind::TupleStruct(ref path, ref patterns, _) if patterns.len() == 1 => { - if let PatKind::Wild = patterns[0].kind { - if match_qpath(path, &paths::RESULT_OK) { - "is_ok()" - } else if match_qpath(path, &paths::RESULT_ERR) { - "is_err()" - } else if match_qpath(path, &paths::OPTION_SOME) { - "is_some()" - } else if match_qpath(path, &paths::POLL_READY) { - "is_ready()" - } else if match_qpath(path, &paths::IPADDR_V4) { - "is_ipv4()" - } else if match_qpath(path, &paths::IPADDR_V6) { - "is_ipv6()" - } else { - return; - } - } else { - return; - } - }, - PatKind::Path(ref path) => { - if match_qpath(path, &paths::OPTION_NONE) { - "is_none()" - } else if match_qpath(path, &paths::POLL_PENDING) { - "is_pending()" - } else { - return; - } - }, - _ => return, - }; - - // check that `while_let_on_iterator` lint does not trigger - if_chain! { - if keyword == "while"; - if let ExprKind::MethodCall(method_path, _, _, _) = op.kind; - if method_path.ident.name == sym::next; - if match_trait_method(cx, op, &paths::ITERATOR); - then { - return; - } - } - - let result_expr = match &op.kind { - ExprKind::AddrOf(_, _, borrowed) => borrowed, - _ => op, - }; - span_lint_and_then( - cx, - REDUNDANT_PATTERN_MATCHING, - arms[0].pat.span, - &format!("redundant pattern matching, consider using `{}`", good_method), - |diag| { - // while let ... = ... { ... } - // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - let expr_span = expr.span; - - // while let ... = ... { ... } - // ^^^ - let op_span = result_expr.span.source_callsite(); - - // while let ... = ... { ... } - // ^^^^^^^^^^^^^^^^^^^ - let span = expr_span.until(op_span.shrink_to_hi()); - diag.span_suggestion( - span, - "try this", - format!("{} {}.{}", keyword, snippet(cx, op_span, "_"), good_method), - Applicability::MachineApplicable, // snippet - ); - }, - ); - } - - fn find_sugg_for_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op: &Expr<'_>, arms: &[Arm<'_>]) { - if arms.len() == 2 { - let node_pair = (&arms[0].pat.kind, &arms[1].pat.kind); - - let found_good_method = match node_pair { - ( - PatKind::TupleStruct(ref path_left, ref patterns_left, _), - PatKind::TupleStruct(ref path_right, ref patterns_right, _), - ) if patterns_left.len() == 1 && patterns_right.len() == 1 => { - if let (PatKind::Wild, PatKind::Wild) = (&patterns_left[0].kind, &patterns_right[0].kind) { - find_good_method_for_match( - arms, - path_left, - path_right, - &paths::RESULT_OK, - &paths::RESULT_ERR, - "is_ok()", - "is_err()", - ) - .or_else(|| { - find_good_method_for_match( - arms, - path_left, - path_right, - &paths::IPADDR_V4, - &paths::IPADDR_V6, - "is_ipv4()", - "is_ipv6()", - ) - }) - } else { - None - } - }, - (PatKind::TupleStruct(ref path_left, ref patterns, _), PatKind::Path(ref path_right)) - | (PatKind::Path(ref path_left), PatKind::TupleStruct(ref path_right, ref patterns, _)) - if patterns.len() == 1 => - { - if let PatKind::Wild = patterns[0].kind { - find_good_method_for_match( - arms, - path_left, - path_right, - &paths::OPTION_SOME, - &paths::OPTION_NONE, - "is_some()", - "is_none()", - ) - .or_else(|| { - find_good_method_for_match( - arms, - path_left, - path_right, - &paths::POLL_READY, - &paths::POLL_PENDING, - "is_ready()", - "is_pending()", - ) - }) - } else { - None - } - }, - _ => None, - }; - - if let Some(good_method) = found_good_method { - let span = expr.span.to(op.span); - let result_expr = match &op.kind { - ExprKind::AddrOf(_, _, borrowed) => borrowed, - _ => op, - }; - span_lint_and_then( - cx, - REDUNDANT_PATTERN_MATCHING, - expr.span, - &format!("redundant pattern matching, consider using `{}`", good_method), - |diag| { - diag.span_suggestion( - span, - "try this", - format!("{}.{}", snippet(cx, result_expr.span, "_"), good_method), - Applicability::MaybeIncorrect, // snippet - ); - }, - ); - } - } - } - - fn find_good_method_for_match<'a>( - arms: &[Arm<'_>], - path_left: &QPath<'_>, - path_right: &QPath<'_>, - expected_left: &[&str], - expected_right: &[&str], - should_be_left: &'a str, - should_be_right: &'a str, - ) -> Option<&'a str> { - let body_node_pair = if match_qpath(path_left, expected_left) && match_qpath(path_right, expected_right) { - (&(*arms[0].body).kind, &(*arms[1].body).kind) - } else if match_qpath(path_right, expected_left) && match_qpath(path_left, expected_right) { - (&(*arms[1].body).kind, &(*arms[0].body).kind) - } else { - return None; - }; - - match body_node_pair { - (ExprKind::Lit(ref lit_left), ExprKind::Lit(ref lit_right)) => match (&lit_left.node, &lit_right.node) { - (LitKind::Bool(true), LitKind::Bool(false)) => Some(should_be_left), - (LitKind::Bool(false), LitKind::Bool(true)) => Some(should_be_right), - _ => None, - }, - _ => None, - } - } -} - -#[test] -fn test_overlapping() { - use rustc_span::source_map::DUMMY_SP; - - let sp = |s, e| SpannedRange { - span: DUMMY_SP, - node: (s, e), - }; - - assert_eq!(None, overlapping::(&[])); - assert_eq!(None, overlapping(&[sp(1, Bound::Included(4))])); - assert_eq!( - None, - overlapping(&[sp(1, Bound::Included(4)), sp(5, Bound::Included(6))]) - ); - assert_eq!( - None, - overlapping(&[ - sp(1, Bound::Included(4)), - sp(5, Bound::Included(6)), - sp(10, Bound::Included(11)) - ],) - ); - assert_eq!( - Some((&sp(1, Bound::Included(4)), &sp(3, Bound::Included(6)))), - overlapping(&[sp(1, Bound::Included(4)), sp(3, Bound::Included(6))]) - ); - assert_eq!( - Some((&sp(5, Bound::Included(6)), &sp(6, Bound::Included(11)))), - overlapping(&[ - sp(1, Bound::Included(4)), - sp(5, Bound::Included(6)), - sp(6, Bound::Included(11)) - ],) - ); -} - -/// Implementation of `MATCH_SAME_ARMS`. -fn lint_match_arms<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) { - fn same_bindings<'tcx>(lhs: &FxHashMap>, rhs: &FxHashMap>) -> bool { - lhs.len() == rhs.len() - && lhs - .iter() - .all(|(name, l_ty)| rhs.get(name).map_or(false, |r_ty| TyS::same_type(l_ty, r_ty))) - } - - if let ExprKind::Match(_, ref arms, MatchSource::Normal) = expr.kind { - let hash = |&(_, arm): &(usize, &Arm<'_>)| -> u64 { - let mut h = SpanlessHash::new(cx); - h.hash_expr(&arm.body); - h.finish() - }; - - let eq = |&(lindex, lhs): &(usize, &Arm<'_>), &(rindex, rhs): &(usize, &Arm<'_>)| -> bool { - let min_index = usize::min(lindex, rindex); - let max_index = usize::max(lindex, rindex); - - // Arms with a guard are ignored, those can’t always be merged together - // This is also the case for arms in-between each there is an arm with a guard - (min_index..=max_index).all(|index| arms[index].guard.is_none()) && - SpanlessEq::new(cx).eq_expr(&lhs.body, &rhs.body) && - // all patterns should have the same bindings - same_bindings(&bindings(cx, &lhs.pat), &bindings(cx, &rhs.pat)) - }; - - let indexed_arms: Vec<(usize, &Arm<'_>)> = arms.iter().enumerate().collect(); - for (&(_, i), &(_, j)) in search_same(&indexed_arms, hash, eq) { - span_lint_and_then( - cx, - MATCH_SAME_ARMS, - j.body.span, - "this `match` has identical arm bodies", - |diag| { - diag.span_note(i.body.span, "same as this"); - - // Note: this does not use `span_suggestion` on purpose: - // there is no clean way - // to remove the other arm. Building a span and suggest to replace it to "" - // makes an even more confusing error message. Also in order not to make up a - // span for the whole pattern, the suggestion is only shown when there is only - // one pattern. The user should know about `|` if they are already using it… - - let lhs = snippet(cx, i.pat.span, ""); - let rhs = snippet(cx, j.pat.span, ""); - - if let PatKind::Wild = j.pat.kind { - // if the last arm is _, then i could be integrated into _ - // note that i.pat cannot be _, because that would mean that we're - // hiding all the subsequent arms, and rust won't compile - diag.span_note( - i.body.span, - &format!( - "`{}` has the same arm body as the `_` wildcard, consider removing it", - lhs - ), - ); - } else { - diag.span_help(i.pat.span, &format!("consider refactoring into `{} | {}`", lhs, rhs)); - } - }, - ); - } - } -} - -/// Returns the list of bindings in a pattern. -fn bindings<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'_>) -> FxHashMap> { - fn bindings_impl<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'_>, map: &mut FxHashMap>) { - match pat.kind { - PatKind::Box(ref pat) | PatKind::Ref(ref pat, _) => bindings_impl(cx, pat, map), - PatKind::TupleStruct(_, pats, _) => { - for pat in pats { - bindings_impl(cx, pat, map); - } - }, - PatKind::Binding(.., ident, ref as_pat) => { - if let Entry::Vacant(v) = map.entry(ident.name) { - v.insert(cx.typeck_results().pat_ty(pat)); - } - if let Some(ref as_pat) = *as_pat { - bindings_impl(cx, as_pat, map); - } - }, - PatKind::Or(fields) | PatKind::Tuple(fields, _) => { - for pat in fields { - bindings_impl(cx, pat, map); - } - }, - PatKind::Struct(_, fields, _) => { - for pat in fields { - bindings_impl(cx, &pat.pat, map); - } - }, - PatKind::Slice(lhs, ref mid, rhs) => { - for pat in lhs { - bindings_impl(cx, pat, map); - } - if let Some(ref mid) = *mid { - bindings_impl(cx, mid, map); - } - for pat in rhs { - bindings_impl(cx, pat, map); - } - }, - PatKind::Lit(..) | PatKind::Range(..) | PatKind::Wild | PatKind::Path(..) => (), - } - } - - let mut result = FxHashMap::default(); - bindings_impl(cx, pat, &mut result); - result -} diff --git a/clippy_lints/src/mem_discriminant.rs b/clippy_lints/src/mem_discriminant.rs deleted file mode 100644 index c71c2ee7d70a..000000000000 --- a/clippy_lints/src/mem_discriminant.rs +++ /dev/null @@ -1,81 +0,0 @@ -use crate::utils::{match_def_path, paths, snippet, span_lint_and_then, walk_ptrs_ty_depth}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{BorrowKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -use std::iter; - -declare_clippy_lint! { - /// **What it does:** Checks for calls of `mem::discriminant()` on a non-enum type. - /// - /// **Why is this bad?** The value of `mem::discriminant()` on non-enum types - /// is unspecified. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// use std::mem; - /// - /// mem::discriminant(&"hello"); - /// mem::discriminant(&&Some(2)); - /// ``` - pub MEM_DISCRIMINANT_NON_ENUM, - correctness, - "calling `mem::descriminant` on non-enum type" -} - -declare_lint_pass!(MemDiscriminant => [MEM_DISCRIMINANT_NON_ENUM]); - -impl<'tcx> LateLintPass<'tcx> for MemDiscriminant { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if_chain! { - if let ExprKind::Call(ref func, ref func_args) = expr.kind; - // is `mem::discriminant` - if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); - if match_def_path(cx, def_id, &paths::MEM_DISCRIMINANT); - // type is non-enum - let ty_param = cx.typeck_results().node_substs(func.hir_id).type_at(0); - if !ty_param.is_enum(); - - then { - span_lint_and_then( - cx, - MEM_DISCRIMINANT_NON_ENUM, - expr.span, - &format!("calling `mem::discriminant` on non-enum type `{}`", ty_param), - |diag| { - // if this is a reference to an enum, suggest dereferencing - let (base_ty, ptr_depth) = walk_ptrs_ty_depth(ty_param); - if ptr_depth >= 1 && base_ty.is_enum() { - let param = &func_args[0]; - - // cancel out '&'s first - let mut derefs_needed = ptr_depth; - let mut cur_expr = param; - while derefs_needed > 0 { - if let ExprKind::AddrOf(BorrowKind::Ref, _, ref inner_expr) = cur_expr.kind { - derefs_needed -= 1; - cur_expr = inner_expr; - } else { - break; - } - } - - let derefs: String = iter::repeat('*').take(derefs_needed).collect(); - diag.span_suggestion( - param.span, - "try dereferencing", - format!("{}{}", derefs, snippet(cx, cur_expr.span, "")), - Applicability::MachineApplicable, - ); - } - }, - ) - } - } - } -} diff --git a/clippy_lints/src/mem_forget.rs b/clippy_lints/src/mem_forget.rs deleted file mode 100644 index 8c6fd10f98a1..000000000000 --- a/clippy_lints/src/mem_forget.rs +++ /dev/null @@ -1,44 +0,0 @@ -use crate::utils::{match_def_path, paths, qpath_res, span_lint}; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `std::mem::forget(t)` where `t` is - /// `Drop`. - /// - /// **Why is this bad?** `std::mem::forget(t)` prevents `t` from running its - /// destructor, possibly causing leaks. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # use std::mem; - /// # use std::rc::Rc; - /// mem::forget(Rc::new(55)) - /// ``` - pub MEM_FORGET, - restriction, - "`mem::forget` usage on `Drop` types, likely to cause memory leaks" -} - -declare_lint_pass!(MemForget => [MEM_FORGET]); - -impl<'tcx> LateLintPass<'tcx> for MemForget { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if let ExprKind::Call(ref path_expr, ref args) = e.kind { - if let ExprKind::Path(ref qpath) = path_expr.kind { - if let Some(def_id) = qpath_res(cx, qpath, path_expr.hir_id).opt_def_id() { - if match_def_path(cx, def_id, &paths::MEM_FORGET) { - let forgot_ty = cx.typeck_results().expr_ty(&args[0]); - - if forgot_ty.ty_adt_def().map_or(false, |def| def.has_dtor(cx.tcx)) { - span_lint(cx, MEM_FORGET, e.span, "usage of `mem::forget` on `Drop` type"); - } - } - } - } - } - } -} diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs deleted file mode 100644 index 19087b020771..000000000000 --- a/clippy_lints/src/mem_replace.rs +++ /dev/null @@ -1,260 +0,0 @@ -use crate::utils::{ - in_macro, match_def_path, match_qpath, meets_msrv, paths, snippet, snippet_with_applicability, span_lint_and_help, - span_lint_and_sugg, span_lint_and_then, -}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, QPath}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_semver::RustcVersion; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; -use rustc_span::symbol::sym; - -declare_clippy_lint! { - /// **What it does:** Checks for `mem::replace()` on an `Option` with - /// `None`. - /// - /// **Why is this bad?** `Option` already has the method `take()` for - /// taking its current value (Some(..) or None) and replacing it with - /// `None`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// use std::mem; - /// - /// let mut an_option = Some(0); - /// let replaced = mem::replace(&mut an_option, None); - /// ``` - /// Is better expressed with: - /// ```rust - /// let mut an_option = Some(0); - /// let taken = an_option.take(); - /// ``` - pub MEM_REPLACE_OPTION_WITH_NONE, - style, - "replacing an `Option` with `None` instead of `take()`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `mem::replace(&mut _, mem::uninitialized())` - /// and `mem::replace(&mut _, mem::zeroed())`. - /// - /// **Why is this bad?** This will lead to undefined behavior even if the - /// value is overwritten later, because the uninitialized value may be - /// observed in the case of a panic. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ``` - /// use std::mem; - ///# fn may_panic(v: Vec) -> Vec { v } - /// - /// #[allow(deprecated, invalid_value)] - /// fn myfunc (v: &mut Vec) { - /// let taken_v = unsafe { mem::replace(v, mem::uninitialized()) }; - /// let new_v = may_panic(taken_v); // undefined behavior on panic - /// mem::forget(mem::replace(v, new_v)); - /// } - /// ``` - /// - /// The [take_mut](https://docs.rs/take_mut) crate offers a sound solution, - /// at the cost of either lazily creating a replacement value or aborting - /// on panic, to ensure that the uninitialized value cannot be observed. - pub MEM_REPLACE_WITH_UNINIT, - correctness, - "`mem::replace(&mut _, mem::uninitialized())` or `mem::replace(&mut _, mem::zeroed())`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `std::mem::replace` on a value of type - /// `T` with `T::default()`. - /// - /// **Why is this bad?** `std::mem` module already has the method `take` to - /// take the current value and replace it with the default value of that type. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let mut text = String::from("foo"); - /// let replaced = std::mem::replace(&mut text, String::default()); - /// ``` - /// Is better expressed with: - /// ```rust - /// let mut text = String::from("foo"); - /// let taken = std::mem::take(&mut text); - /// ``` - pub MEM_REPLACE_WITH_DEFAULT, - style, - "replacing a value of type `T` with `T::default()` instead of using `std::mem::take`" -} - -impl_lint_pass!(MemReplace => - [MEM_REPLACE_OPTION_WITH_NONE, MEM_REPLACE_WITH_UNINIT, MEM_REPLACE_WITH_DEFAULT]); - -fn check_replace_option_with_none(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { - if let ExprKind::Path(ref replacement_qpath) = src.kind { - // Check that second argument is `Option::None` - if match_qpath(replacement_qpath, &paths::OPTION_NONE) { - // Since this is a late pass (already type-checked), - // and we already know that the second argument is an - // `Option`, we do not need to check the first - // argument's type. All that's left is to get - // replacee's path. - let replaced_path = match dest.kind { - ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, ref replaced) => { - if let ExprKind::Path(QPath::Resolved(None, ref replaced_path)) = replaced.kind { - replaced_path - } else { - return; - } - }, - ExprKind::Path(QPath::Resolved(None, ref replaced_path)) => replaced_path, - _ => return, - }; - - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - MEM_REPLACE_OPTION_WITH_NONE, - expr_span, - "replacing an `Option` with `None`", - "consider `Option::take()` instead", - format!( - "{}.take()", - snippet_with_applicability(cx, replaced_path.span, "", &mut applicability) - ), - applicability, - ); - } - } -} - -fn check_replace_with_uninit(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { - if_chain! { - // check if replacement is mem::MaybeUninit::uninit().assume_init() - if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(src.hir_id); - if cx.tcx.is_diagnostic_item(sym::assume_init, method_def_id); - then { - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - MEM_REPLACE_WITH_UNINIT, - expr_span, - "replacing with `mem::MaybeUninit::uninit().assume_init()`", - "consider using", - format!( - "std::ptr::read({})", - snippet_with_applicability(cx, dest.span, "", &mut applicability) - ), - applicability, - ); - return; - } - } - - if_chain! { - if let ExprKind::Call(ref repl_func, ref repl_args) = src.kind; - if repl_args.is_empty(); - if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; - if let Some(repl_def_id) = cx.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); - then { - if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, repl_def_id) { - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - MEM_REPLACE_WITH_UNINIT, - expr_span, - "replacing with `mem::uninitialized()`", - "consider using", - format!( - "std::ptr::read({})", - snippet_with_applicability(cx, dest.span, "", &mut applicability) - ), - applicability, - ); - } else if cx.tcx.is_diagnostic_item(sym::mem_zeroed, repl_def_id) && - !cx.typeck_results().expr_ty(src).is_primitive() { - span_lint_and_help( - cx, - MEM_REPLACE_WITH_UNINIT, - expr_span, - "replacing with `mem::zeroed()`", - None, - "consider using a default value or the `take_mut` crate instead", - ); - } - } - } -} - -fn check_replace_with_default(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { - if let ExprKind::Call(ref repl_func, _) = src.kind { - if_chain! { - if !in_external_macro(cx.tcx.sess, expr_span); - if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; - if let Some(repl_def_id) = cx.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); - if match_def_path(cx, repl_def_id, &paths::DEFAULT_TRAIT_METHOD); - then { - span_lint_and_then( - cx, - MEM_REPLACE_WITH_DEFAULT, - expr_span, - "replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`", - |diag| { - if !in_macro(expr_span) { - let suggestion = format!("std::mem::take({})", snippet(cx, dest.span, "")); - - diag.span_suggestion( - expr_span, - "consider using", - suggestion, - Applicability::MachineApplicable - ); - } - } - ); - } - } - } -} - -const MEM_REPLACE_WITH_DEFAULT_MSRV: RustcVersion = RustcVersion::new(1, 40, 0); - -pub struct MemReplace { - msrv: Option, -} - -impl MemReplace { - #[must_use] - pub fn new(msrv: Option) -> Self { - Self { msrv } - } -} - -impl<'tcx> LateLintPass<'tcx> for MemReplace { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if_chain! { - // Check that `expr` is a call to `mem::replace()` - if let ExprKind::Call(ref func, ref func_args) = expr.kind; - if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); - if match_def_path(cx, def_id, &paths::MEM_REPLACE); - if let [dest, src] = &**func_args; - then { - check_replace_option_with_none(cx, src, dest, expr.span); - check_replace_with_uninit(cx, src, dest, expr.span); - if meets_msrv(self.msrv.as_ref(), &MEM_REPLACE_WITH_DEFAULT_MSRV) { - check_replace_with_default(cx, src, dest, expr.span); - } - } - } - } - extract_msrv_attr!(LateContext); -} diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs deleted file mode 100644 index 540a1484a855..000000000000 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ /dev/null @@ -1,193 +0,0 @@ -use super::{contains_return, BIND_INSTEAD_OF_MAP}; -use crate::utils::{ - in_macro, match_qpath, match_type, method_calls, multispan_sugg_with_applicability, paths, remove_blocks, snippet, - snippet_with_macro_callsite, span_lint_and_sugg, span_lint_and_then, visitors::find_all_ret_expressions, -}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_lint::LateContext; -use rustc_span::Span; - -pub(crate) struct OptionAndThenSome; - -impl BindInsteadOfMap for OptionAndThenSome { - const TYPE_NAME: &'static str = "Option"; - const TYPE_QPATH: &'static [&'static str] = &paths::OPTION; - - const BAD_METHOD_NAME: &'static str = "and_then"; - const BAD_VARIANT_NAME: &'static str = "Some"; - const BAD_VARIANT_QPATH: &'static [&'static str] = &paths::OPTION_SOME; - - const GOOD_METHOD_NAME: &'static str = "map"; -} - -pub(crate) struct ResultAndThenOk; - -impl BindInsteadOfMap for ResultAndThenOk { - const TYPE_NAME: &'static str = "Result"; - const TYPE_QPATH: &'static [&'static str] = &paths::RESULT; - - const BAD_METHOD_NAME: &'static str = "and_then"; - const BAD_VARIANT_NAME: &'static str = "Ok"; - const BAD_VARIANT_QPATH: &'static [&'static str] = &paths::RESULT_OK; - - const GOOD_METHOD_NAME: &'static str = "map"; -} - -pub(crate) struct ResultOrElseErrInfo; - -impl BindInsteadOfMap for ResultOrElseErrInfo { - const TYPE_NAME: &'static str = "Result"; - const TYPE_QPATH: &'static [&'static str] = &paths::RESULT; - - const BAD_METHOD_NAME: &'static str = "or_else"; - const BAD_VARIANT_NAME: &'static str = "Err"; - const BAD_VARIANT_QPATH: &'static [&'static str] = &paths::RESULT_ERR; - - const GOOD_METHOD_NAME: &'static str = "map_err"; -} - -pub(crate) trait BindInsteadOfMap { - const TYPE_NAME: &'static str; - const TYPE_QPATH: &'static [&'static str]; - - const BAD_METHOD_NAME: &'static str; - const BAD_VARIANT_NAME: &'static str; - const BAD_VARIANT_QPATH: &'static [&'static str]; - - const GOOD_METHOD_NAME: &'static str; - - fn no_op_msg() -> String { - format!( - "using `{}.{}({})`, which is a no-op", - Self::TYPE_NAME, - Self::BAD_METHOD_NAME, - Self::BAD_VARIANT_NAME - ) - } - - fn lint_msg() -> String { - format!( - "using `{}.{}(|x| {}(y))`, which is more succinctly expressed as `{}(|x| y)`", - Self::TYPE_NAME, - Self::BAD_METHOD_NAME, - Self::BAD_VARIANT_NAME, - Self::GOOD_METHOD_NAME - ) - } - - fn lint_closure_autofixable( - cx: &LateContext<'_>, - expr: &hir::Expr<'_>, - args: &[hir::Expr<'_>], - closure_expr: &hir::Expr<'_>, - closure_args_span: Span, - ) -> bool { - if_chain! { - if let hir::ExprKind::Call(ref some_expr, ref some_args) = closure_expr.kind; - if let hir::ExprKind::Path(ref qpath) = some_expr.kind; - if match_qpath(qpath, Self::BAD_VARIANT_QPATH); - if some_args.len() == 1; - then { - let inner_expr = &some_args[0]; - - if contains_return(inner_expr) { - return false; - } - - let some_inner_snip = if inner_expr.span.from_expansion() { - snippet_with_macro_callsite(cx, inner_expr.span, "_") - } else { - snippet(cx, inner_expr.span, "_") - }; - - let closure_args_snip = snippet(cx, closure_args_span, ".."); - let option_snip = snippet(cx, args[0].span, ".."); - let note = format!("{}.{}({} {})", option_snip, Self::GOOD_METHOD_NAME, closure_args_snip, some_inner_snip); - span_lint_and_sugg( - cx, - BIND_INSTEAD_OF_MAP, - expr.span, - Self::lint_msg().as_ref(), - "try this", - note, - Applicability::MachineApplicable, - ); - true - } else { - false - } - } - } - - fn lint_closure(cx: &LateContext<'_>, expr: &hir::Expr<'_>, closure_expr: &hir::Expr<'_>) -> bool { - let mut suggs = Vec::new(); - let can_sugg: bool = find_all_ret_expressions(cx, closure_expr, |ret_expr| { - if_chain! { - if !in_macro(ret_expr.span); - if let hir::ExprKind::Call(ref func_path, ref args) = ret_expr.kind; - if let hir::ExprKind::Path(ref qpath) = func_path.kind; - if match_qpath(qpath, Self::BAD_VARIANT_QPATH); - if args.len() == 1; - if !contains_return(&args[0]); - then { - suggs.push((ret_expr.span, args[0].span.source_callsite())); - true - } else { - false - } - } - }); - - if can_sugg { - span_lint_and_then(cx, BIND_INSTEAD_OF_MAP, expr.span, Self::lint_msg().as_ref(), |diag| { - multispan_sugg_with_applicability( - diag, - "try this", - Applicability::MachineApplicable, - std::iter::once((*method_calls(expr, 1).2.get(0).unwrap(), Self::GOOD_METHOD_NAME.into())).chain( - suggs - .into_iter() - .map(|(span1, span2)| (span1, snippet(cx, span2, "_").into())), - ), - ) - }); - } - can_sugg - } - - /// Lint use of `_.and_then(|x| Some(y))` for `Option`s - fn lint(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) -> bool { - if !match_type(cx, cx.typeck_results().expr_ty(&args[0]), Self::TYPE_QPATH) { - return false; - } - - match args[1].kind { - hir::ExprKind::Closure(_, _, body_id, closure_args_span, _) => { - let closure_body = cx.tcx.hir().body(body_id); - let closure_expr = remove_blocks(&closure_body.value); - - if Self::lint_closure_autofixable(cx, expr, args, closure_expr, closure_args_span) { - true - } else { - Self::lint_closure(cx, expr, closure_expr) - } - }, - // `_.and_then(Some)` case, which is no-op. - hir::ExprKind::Path(ref qpath) if match_qpath(qpath, Self::BAD_VARIANT_QPATH) => { - span_lint_and_sugg( - cx, - BIND_INSTEAD_OF_MAP, - expr.span, - Self::no_op_msg().as_ref(), - "use the expression directly", - snippet(cx, args[0].span, "..").into(), - Applicability::MachineApplicable, - ); - true - }, - _ => false, - } - } -} diff --git a/clippy_lints/src/methods/inefficient_to_string.rs b/clippy_lints/src/methods/inefficient_to_string.rs deleted file mode 100644 index c83b6f2c3296..000000000000 --- a/clippy_lints/src/methods/inefficient_to_string.rs +++ /dev/null @@ -1,63 +0,0 @@ -use super::INEFFICIENT_TO_STRING; -use crate::utils::{ - is_type_diagnostic_item, match_def_path, paths, snippet_with_applicability, span_lint_and_then, walk_ptrs_ty_depth, -}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty}; -use rustc_span::sym; - -/// Checks for the `INEFFICIENT_TO_STRING` lint -pub fn lint<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'tcx>) { - if_chain! { - if let Some(to_string_meth_did) = cx.typeck_results().type_dependent_def_id(expr.hir_id); - if match_def_path(cx, to_string_meth_did, &paths::TO_STRING_METHOD); - if let Some(substs) = cx.typeck_results().node_substs_opt(expr.hir_id); - let self_ty = substs.type_at(0); - let (deref_self_ty, deref_count) = walk_ptrs_ty_depth(self_ty); - if deref_count >= 1; - if specializes_tostring(cx, deref_self_ty); - then { - span_lint_and_then( - cx, - INEFFICIENT_TO_STRING, - expr.span, - &format!("calling `to_string` on `{}`", arg_ty), - |diag| { - diag.help(&format!( - "`{}` implements `ToString` through a slower blanket impl, but `{}` has a fast specialization of `ToString`", - self_ty, deref_self_ty - )); - let mut applicability = Applicability::MachineApplicable; - let arg_snippet = snippet_with_applicability(cx, arg.span, "..", &mut applicability); - diag.span_suggestion( - expr.span, - "try dereferencing the receiver", - format!("({}{}).to_string()", "*".repeat(deref_count), arg_snippet), - applicability, - ); - }, - ); - } - } -} - -/// Returns whether `ty` specializes `ToString`. -/// Currently, these are `str`, `String`, and `Cow<'_, str>`. -fn specializes_tostring(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { - if let ty::Str = ty.kind() { - return true; - } - - if is_type_diagnostic_item(cx, ty, sym::string_type) { - return true; - } - - if let ty::Adt(adt, substs) = ty.kind() { - match_def_path(cx, adt.did, &paths::COW) && substs.type_at(1).is_str() - } else { - false - } -} diff --git a/clippy_lints/src/methods/manual_saturating_arithmetic.rs b/clippy_lints/src/methods/manual_saturating_arithmetic.rs deleted file mode 100644 index 44c974b9d985..000000000000 --- a/clippy_lints/src/methods/manual_saturating_arithmetic.rs +++ /dev/null @@ -1,175 +0,0 @@ -use crate::utils::{match_qpath, snippet_with_applicability, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_ast::ast; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_lint::LateContext; -use rustc_target::abi::LayoutOf; - -pub fn lint(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[&[hir::Expr<'_>]], arith: &str) { - let unwrap_arg = &args[0][1]; - let arith_lhs = &args[1][0]; - let arith_rhs = &args[1][1]; - - let ty = cx.typeck_results().expr_ty(arith_lhs); - if !ty.is_integral() { - return; - } - - let mm = if let Some(mm) = is_min_or_max(cx, unwrap_arg) { - mm - } else { - return; - }; - - if ty.is_signed() { - use self::{ - MinMax::{Max, Min}, - Sign::{Neg, Pos}, - }; - - let sign = if let Some(sign) = lit_sign(arith_rhs) { - sign - } else { - return; - }; - - match (arith, sign, mm) { - ("add", Pos, Max) | ("add", Neg, Min) | ("sub", Neg, Max) | ("sub", Pos, Min) => (), - // "mul" is omitted because lhs can be negative. - _ => return, - } - - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - super::MANUAL_SATURATING_ARITHMETIC, - expr.span, - "manual saturating arithmetic", - &format!("try using `saturating_{}`", arith), - format!( - "{}.saturating_{}({})", - snippet_with_applicability(cx, arith_lhs.span, "..", &mut applicability), - arith, - snippet_with_applicability(cx, arith_rhs.span, "..", &mut applicability), - ), - applicability, - ); - } else { - match (mm, arith) { - (MinMax::Max, "add" | "mul") | (MinMax::Min, "sub") => (), - _ => return, - } - - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - super::MANUAL_SATURATING_ARITHMETIC, - expr.span, - "manual saturating arithmetic", - &format!("try using `saturating_{}`", arith), - format!( - "{}.saturating_{}({})", - snippet_with_applicability(cx, arith_lhs.span, "..", &mut applicability), - arith, - snippet_with_applicability(cx, arith_rhs.span, "..", &mut applicability), - ), - applicability, - ); - } -} - -#[derive(PartialEq, Eq)] -enum MinMax { - Min, - Max, -} - -fn is_min_or_max<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>) -> Option { - // `T::max_value()` `T::min_value()` inherent methods - if_chain! { - if let hir::ExprKind::Call(func, args) = &expr.kind; - if args.is_empty(); - if let hir::ExprKind::Path(hir::QPath::TypeRelative(_, segment)) = &func.kind; - then { - match &*segment.ident.as_str() { - "max_value" => return Some(MinMax::Max), - "min_value" => return Some(MinMax::Min), - _ => {} - } - } - } - - let ty = cx.typeck_results().expr_ty(expr); - let ty_str = ty.to_string(); - - // `std::T::MAX` `std::T::MIN` constants - if let hir::ExprKind::Path(path) = &expr.kind { - if match_qpath(path, &["core", &ty_str, "MAX"][..]) { - return Some(MinMax::Max); - } - - if match_qpath(path, &["core", &ty_str, "MIN"][..]) { - return Some(MinMax::Min); - } - } - - // Literals - let bits = cx.layout_of(ty).unwrap().size.bits(); - let (minval, maxval): (u128, u128) = if ty.is_signed() { - let minval = 1 << (bits - 1); - let mut maxval = !(1 << (bits - 1)); - if bits != 128 { - maxval &= (1 << bits) - 1; - } - (minval, maxval) - } else { - (0, if bits == 128 { !0 } else { (1 << bits) - 1 }) - }; - - let check_lit = |expr: &hir::Expr<'_>, check_min: bool| { - if let hir::ExprKind::Lit(lit) = &expr.kind { - if let ast::LitKind::Int(value, _) = lit.node { - if value == maxval { - return Some(MinMax::Max); - } - - if check_min && value == minval { - return Some(MinMax::Min); - } - } - } - - None - }; - - if let r @ Some(_) = check_lit(expr, !ty.is_signed()) { - return r; - } - - if ty.is_signed() { - if let hir::ExprKind::Unary(hir::UnOp::UnNeg, val) = &expr.kind { - return check_lit(val, true); - } - } - - None -} - -#[derive(PartialEq, Eq)] -enum Sign { - Pos, - Neg, -} - -fn lit_sign(expr: &hir::Expr<'_>) -> Option { - if let hir::ExprKind::Unary(hir::UnOp::UnNeg, inner) = &expr.kind { - if let hir::ExprKind::Lit(..) = &inner.kind { - return Some(Sign::Neg); - } - } else if let hir::ExprKind::Lit(..) = &expr.kind { - return Some(Sign::Pos); - } - - None -} diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs deleted file mode 100644 index e99fe1b97ff6..000000000000 --- a/clippy_lints/src/methods/mod.rs +++ /dev/null @@ -1,4003 +0,0 @@ -mod bind_instead_of_map; -mod inefficient_to_string; -mod manual_saturating_arithmetic; -mod option_map_unwrap_or; -mod unnecessary_filter_map; -mod unnecessary_lazy_eval; - -use std::borrow::Cow; -use std::fmt; -use std::iter; - -use bind_instead_of_map::BindInsteadOfMap; -use if_chain::if_chain; -use rustc_ast::ast; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_hir::{TraitItem, TraitItemKind}; -use rustc_lint::{LateContext, LateLintPass, Lint, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, TraitRef, Ty, TyS}; -use rustc_semver::RustcVersion; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; -use rustc_span::symbol::{sym, SymbolStr}; -use rustc_typeck::hir_ty_to_ty; - -use crate::consts::{constant, Constant}; -use crate::utils::eager_or_lazy::is_lazyness_candidate; -use crate::utils::usage::mutated_variables; -use crate::utils::{ - contains_return, contains_ty, get_arg_name, get_parent_expr, get_trait_def_id, has_iter_method, higher, - implements_trait, in_macro, is_copy, is_expn_of, is_type_diagnostic_item, iter_input_pats, last_path_segment, - match_def_path, match_qpath, match_trait_method, match_type, match_var, meets_msrv, method_calls, - method_chain_args, paths, remove_blocks, return_ty, single_segment_path, snippet, snippet_with_applicability, - snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then, sugg, - walk_ptrs_ty_depth, SpanlessEq, -}; - -declare_clippy_lint! { - /// **What it does:** Checks for `.unwrap()` calls on `Option`s and on `Result`s. - /// - /// **Why is this bad?** It is better to handle the `None` or `Err` case, - /// or at least call `.expect(_)` with a more helpful message. Still, for a lot of - /// quick-and-dirty code, `unwrap` is a good choice, which is why this lint is - /// `Allow` by default. - /// - /// `result.unwrap()` will let the thread panic on `Err` values. - /// Normally, you want to implement more sophisticated error handling, - /// and propagate errors upwards with `?` operator. - /// - /// Even if you want to panic on errors, not all `Error`s implement good - /// messages on display. Therefore, it may be beneficial to look at the places - /// where they may get displayed. Activate this lint to do just that. - /// - /// **Known problems:** None. - /// - /// **Examples:** - /// ```rust - /// # let opt = Some(1); - /// - /// // Bad - /// opt.unwrap(); - /// - /// // Good - /// opt.expect("more helpful message"); - /// ``` - /// - /// // or - /// - /// ```rust - /// # let res: Result = Ok(1); - /// - /// // Bad - /// res.unwrap(); - /// - /// // Good - /// res.expect("more helpful message"); - /// ``` - pub UNWRAP_USED, - restriction, - "using `.unwrap()` on `Result` or `Option`, which should at least get a better message using `expect()`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `.expect()` calls on `Option`s and `Result`s. - /// - /// **Why is this bad?** Usually it is better to handle the `None` or `Err` case. - /// Still, for a lot of quick-and-dirty code, `expect` is a good choice, which is why - /// this lint is `Allow` by default. - /// - /// `result.expect()` will let the thread panic on `Err` - /// values. Normally, you want to implement more sophisticated error handling, - /// and propagate errors upwards with `?` operator. - /// - /// **Known problems:** None. - /// - /// **Examples:** - /// ```rust,ignore - /// # let opt = Some(1); - /// - /// // Bad - /// opt.expect("one"); - /// - /// // Good - /// let opt = Some(1); - /// opt?; - /// ``` - /// - /// // or - /// - /// ```rust - /// # let res: Result = Ok(1); - /// - /// // Bad - /// res.expect("one"); - /// - /// // Good - /// res?; - /// # Ok::<(), ()>(()) - /// ``` - pub EXPECT_USED, - restriction, - "using `.expect()` on `Result` or `Option`, which might be better handled" -} - -declare_clippy_lint! { - /// **What it does:** Checks for methods that should live in a trait - /// implementation of a `std` trait (see [llogiq's blog - /// post](http://llogiq.github.io/2015/07/30/traits.html) for further - /// information) instead of an inherent implementation. - /// - /// **Why is this bad?** Implementing the traits improve ergonomics for users of - /// the code, often with very little cost. Also people seeing a `mul(...)` - /// method - /// may expect `*` to work equally, so you should have good reason to disappoint - /// them. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// struct X; - /// impl X { - /// fn add(&self, other: &X) -> X { - /// // .. - /// # X - /// } - /// } - /// ``` - pub SHOULD_IMPLEMENT_TRAIT, - style, - "defining a method that should be implementing a std trait" -} - -declare_clippy_lint! { - /// **What it does:** Checks for methods with certain name prefixes and which - /// doesn't match how self is taken. The actual rules are: - /// - /// |Prefix |`self` taken | - /// |-------|----------------------| - /// |`as_` |`&self` or `&mut self`| - /// |`from_`| none | - /// |`into_`|`self` | - /// |`is_` |`&self` or none | - /// |`to_` |`&self` | - /// - /// **Why is this bad?** Consistency breeds readability. If you follow the - /// conventions, your users won't be surprised that they, e.g., need to supply a - /// mutable reference to a `as_..` function. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # struct X; - /// impl X { - /// fn as_str(self) -> &'static str { - /// // .. - /// # "" - /// } - /// } - /// ``` - pub WRONG_SELF_CONVENTION, - style, - "defining a method named with an established prefix (like \"into_\") that takes `self` with the wrong convention" -} - -declare_clippy_lint! { - /// **What it does:** This is the same as - /// [`wrong_self_convention`](#wrong_self_convention), but for public items. - /// - /// **Why is this bad?** See [`wrong_self_convention`](#wrong_self_convention). - /// - /// **Known problems:** Actually *renaming* the function may break clients if - /// the function is part of the public interface. In that case, be mindful of - /// the stability guarantees you've given your users. - /// - /// **Example:** - /// ```rust - /// # struct X; - /// impl<'a> X { - /// pub fn as_str(self) -> &'a str { - /// "foo" - /// } - /// } - /// ``` - pub WRONG_PUB_SELF_CONVENTION, - restriction, - "defining a public method named with an established prefix (like \"into_\") that takes `self` with the wrong convention" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `ok().expect(..)`. - /// - /// **Why is this bad?** Because you usually call `expect()` on the `Result` - /// directly to get a better error message. - /// - /// **Known problems:** The error type needs to implement `Debug` - /// - /// **Example:** - /// ```rust - /// # let x = Ok::<_, ()>(()); - /// - /// // Bad - /// x.ok().expect("why did I do this again?"); - /// - /// // Good - /// x.expect("why did I do this again?"); - /// ``` - pub OK_EXPECT, - style, - "using `ok().expect()`, which gives worse error messages than calling `expect` directly on the Result" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `option.map(_).unwrap_or(_)` or `option.map(_).unwrap_or_else(_)` or - /// `result.map(_).unwrap_or_else(_)`. - /// - /// **Why is this bad?** Readability, these can be written more concisely (resp.) as - /// `option.map_or(_, _)`, `option.map_or_else(_, _)` and `result.map_or_else(_, _)`. - /// - /// **Known problems:** The order of the arguments is not in execution order - /// - /// **Examples:** - /// ```rust - /// # let x = Some(1); - /// - /// // Bad - /// x.map(|a| a + 1).unwrap_or(0); - /// - /// // Good - /// x.map_or(0, |a| a + 1); - /// ``` - /// - /// // or - /// - /// ```rust - /// # let x: Result = Ok(1); - /// # fn some_function(foo: ()) -> usize { 1 } - /// - /// // Bad - /// x.map(|a| a + 1).unwrap_or_else(some_function); - /// - /// // Good - /// x.map_or_else(some_function, |a| a + 1); - /// ``` - pub MAP_UNWRAP_OR, - pedantic, - "using `.map(f).unwrap_or(a)` or `.map(f).unwrap_or_else(func)`, which are more succinctly expressed as `map_or(a, f)` or `map_or_else(a, f)`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.map_or(None, _)`. - /// - /// **Why is this bad?** Readability, this can be written more concisely as - /// `_.and_then(_)`. - /// - /// **Known problems:** The order of the arguments is not in execution order. - /// - /// **Example:** - /// ```rust - /// # let opt = Some(1); - /// - /// // Bad - /// opt.map_or(None, |a| Some(a + 1)); - /// - /// // Good - /// opt.and_then(|a| Some(a + 1)); - /// ``` - pub OPTION_MAP_OR_NONE, - style, - "using `Option.map_or(None, f)`, which is more succinctly expressed as `and_then(f)`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.map_or(None, Some)`. - /// - /// **Why is this bad?** Readability, this can be written more concisely as - /// `_.ok()`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// Bad: - /// ```rust - /// # let r: Result = Ok(1); - /// assert_eq!(Some(1), r.map_or(None, Some)); - /// ``` - /// - /// Good: - /// ```rust - /// # let r: Result = Ok(1); - /// assert_eq!(Some(1), r.ok()); - /// ``` - pub RESULT_MAP_OR_INTO_OPTION, - style, - "using `Result.map_or(None, Some)`, which is more succinctly expressed as `ok()`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.and_then(|x| Some(y))`, `_.and_then(|x| Ok(y))` or - /// `_.or_else(|x| Err(y))`. - /// - /// **Why is this bad?** Readability, this can be written more concisely as - /// `_.map(|x| y)` or `_.map_err(|x| y)`. - /// - /// **Known problems:** None - /// - /// **Example:** - /// - /// ```rust - /// # fn opt() -> Option<&'static str> { Some("42") } - /// # fn res() -> Result<&'static str, &'static str> { Ok("42") } - /// let _ = opt().and_then(|s| Some(s.len())); - /// let _ = res().and_then(|s| if s.len() == 42 { Ok(10) } else { Ok(20) }); - /// let _ = res().or_else(|s| if s.len() == 42 { Err(10) } else { Err(20) }); - /// ``` - /// - /// The correct use would be: - /// - /// ```rust - /// # fn opt() -> Option<&'static str> { Some("42") } - /// # fn res() -> Result<&'static str, &'static str> { Ok("42") } - /// let _ = opt().map(|s| s.len()); - /// let _ = res().map(|s| if s.len() == 42 { 10 } else { 20 }); - /// let _ = res().map_err(|s| if s.len() == 42 { 10 } else { 20 }); - /// ``` - pub BIND_INSTEAD_OF_MAP, - complexity, - "using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.filter(_).next()`. - /// - /// **Why is this bad?** Readability, this can be written more concisely as - /// `_.find(_)`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let vec = vec![1]; - /// vec.iter().filter(|x| **x == 0).next(); - /// ``` - /// Could be written as - /// ```rust - /// # let vec = vec![1]; - /// vec.iter().find(|x| **x == 0); - /// ``` - pub FILTER_NEXT, - complexity, - "using `filter(p).next()`, which is more succinctly expressed as `.find(p)`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.skip_while(condition).next()`. - /// - /// **Why is this bad?** Readability, this can be written more concisely as - /// `_.find(!condition)`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let vec = vec![1]; - /// vec.iter().skip_while(|x| **x == 0).next(); - /// ``` - /// Could be written as - /// ```rust - /// # let vec = vec![1]; - /// vec.iter().find(|x| **x != 0); - /// ``` - pub SKIP_WHILE_NEXT, - complexity, - "using `skip_while(p).next()`, which is more succinctly expressed as `.find(!p)`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.map(_).flatten(_)`, - /// - /// **Why is this bad?** Readability, this can be written more concisely as - /// `_.flat_map(_)` - /// - /// **Known problems:** - /// - /// **Example:** - /// ```rust - /// let vec = vec![vec![1]]; - /// - /// // Bad - /// vec.iter().map(|x| x.iter()).flatten(); - /// - /// // Good - /// vec.iter().flat_map(|x| x.iter()); - /// ``` - pub MAP_FLATTEN, - pedantic, - "using combinations of `flatten` and `map` which can usually be written as a single method call" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.filter(_).map(_)`, - /// `_.filter(_).flat_map(_)`, `_.filter_map(_).flat_map(_)` and similar. - /// - /// **Why is this bad?** Readability, this can be written more concisely as - /// `_.filter_map(_)`. - /// - /// **Known problems:** Often requires a condition + Option/Iterator creation - /// inside the closure. - /// - /// **Example:** - /// ```rust - /// let vec = vec![1]; - /// - /// // Bad - /// vec.iter().filter(|x| **x == 0).map(|x| *x * 2); - /// - /// // Good - /// vec.iter().filter_map(|x| if *x == 0 { - /// Some(*x * 2) - /// } else { - /// None - /// }); - /// ``` - pub FILTER_MAP, - pedantic, - "using combinations of `filter`, `map`, `filter_map` and `flat_map` which can usually be written as a single method call" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.filter_map(_).next()`. - /// - /// **Why is this bad?** Readability, this can be written more concisely as - /// `_.find_map(_)`. - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```rust - /// (0..3).filter_map(|x| if x == 2 { Some(x) } else { None }).next(); - /// ``` - /// Can be written as - /// - /// ```rust - /// (0..3).find_map(|x| if x == 2 { Some(x) } else { None }); - /// ``` - pub FILTER_MAP_NEXT, - pedantic, - "using combination of `filter_map` and `next` which can usually be written as a single method call" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `flat_map(|x| x)`. - /// - /// **Why is this bad?** Readability, this can be written more concisely by using `flatten`. - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```rust - /// # let iter = vec![vec![0]].into_iter(); - /// iter.flat_map(|x| x); - /// ``` - /// Can be written as - /// ```rust - /// # let iter = vec![vec![0]].into_iter(); - /// iter.flatten(); - /// ``` - pub FLAT_MAP_IDENTITY, - complexity, - "call to `flat_map` where `flatten` is sufficient" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.find(_).map(_)`. - /// - /// **Why is this bad?** Readability, this can be written more concisely as - /// `_.find_map(_)`. - /// - /// **Known problems:** Often requires a condition + Option/Iterator creation - /// inside the closure. - /// - /// **Example:** - /// ```rust - /// (0..3).find(|x| *x == 2).map(|x| x * 2); - /// ``` - /// Can be written as - /// ```rust - /// (0..3).find_map(|x| if x == 2 { Some(x * 2) } else { None }); - /// ``` - pub FIND_MAP, - pedantic, - "using a combination of `find` and `map` can usually be written as a single method call" -} - -declare_clippy_lint! { - /// **What it does:** Checks for an iterator or string search (such as `find()`, - /// `position()`, or `rposition()`) followed by a call to `is_some()`. - /// - /// **Why is this bad?** Readability, this can be written more concisely as - /// `_.any(_)` or `_.contains(_)`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let vec = vec![1]; - /// vec.iter().find(|x| **x == 0).is_some(); - /// ``` - /// Could be written as - /// ```rust - /// # let vec = vec![1]; - /// vec.iter().any(|x| *x == 0); - /// ``` - pub SEARCH_IS_SOME, - complexity, - "using an iterator or string search followed by `is_some()`, which is more succinctly expressed as a call to `any()` or `contains()`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `.chars().next()` on a `str` to check - /// if it starts with a given char. - /// - /// **Why is this bad?** Readability, this can be written more concisely as - /// `_.starts_with(_)`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let name = "foo"; - /// if name.chars().next() == Some('_') {}; - /// ``` - /// Could be written as - /// ```rust - /// let name = "foo"; - /// if name.starts_with('_') {}; - /// ``` - pub CHARS_NEXT_CMP, - style, - "using `.chars().next()` to check if a string starts with a char" -} - -declare_clippy_lint! { - /// **What it does:** Checks for calls to `.or(foo(..))`, `.unwrap_or(foo(..))`, - /// etc., and suggests to use `or_else`, `unwrap_or_else`, etc., or - /// `unwrap_or_default` instead. - /// - /// **Why is this bad?** The function will always be called and potentially - /// allocate an object acting as the default. - /// - /// **Known problems:** If the function has side-effects, not calling it will - /// change the semantic of the program, but you shouldn't rely on that anyway. - /// - /// **Example:** - /// ```rust - /// # let foo = Some(String::new()); - /// foo.unwrap_or(String::new()); - /// ``` - /// this can instead be written: - /// ```rust - /// # let foo = Some(String::new()); - /// foo.unwrap_or_else(String::new); - /// ``` - /// or - /// ```rust - /// # let foo = Some(String::new()); - /// foo.unwrap_or_default(); - /// ``` - pub OR_FUN_CALL, - perf, - "using any `*or` method with a function call, which suggests `*or_else`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for calls to `.expect(&format!(...))`, `.expect(foo(..))`, - /// etc., and suggests to use `unwrap_or_else` instead - /// - /// **Why is this bad?** The function will always be called. - /// - /// **Known problems:** If the function has side-effects, not calling it will - /// change the semantics of the program, but you shouldn't rely on that anyway. - /// - /// **Example:** - /// ```rust - /// # let foo = Some(String::new()); - /// # let err_code = "418"; - /// # let err_msg = "I'm a teapot"; - /// foo.expect(&format!("Err {}: {}", err_code, err_msg)); - /// ``` - /// or - /// ```rust - /// # let foo = Some(String::new()); - /// # let err_code = "418"; - /// # let err_msg = "I'm a teapot"; - /// foo.expect(format!("Err {}: {}", err_code, err_msg).as_str()); - /// ``` - /// this can instead be written: - /// ```rust - /// # let foo = Some(String::new()); - /// # let err_code = "418"; - /// # let err_msg = "I'm a teapot"; - /// foo.unwrap_or_else(|| panic!("Err {}: {}", err_code, err_msg)); - /// ``` - pub EXPECT_FUN_CALL, - perf, - "using any `expect` method with a function call" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `.clone()` on a `Copy` type. - /// - /// **Why is this bad?** The only reason `Copy` types implement `Clone` is for - /// generics, not for using the `clone` method on a concrete type. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// 42u64.clone(); - /// ``` - pub CLONE_ON_COPY, - complexity, - "using `clone` on a `Copy` type" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `.clone()` on a ref-counted pointer, - /// (`Rc`, `Arc`, `rc::Weak`, or `sync::Weak`), and suggests calling Clone via unified - /// function syntax instead (e.g., `Rc::clone(foo)`). - /// - /// **Why is this bad?** Calling '.clone()' on an Rc, Arc, or Weak - /// can obscure the fact that only the pointer is being cloned, not the underlying - /// data. - /// - /// **Example:** - /// ```rust - /// # use std::rc::Rc; - /// let x = Rc::new(1); - /// - /// // Bad - /// x.clone(); - /// - /// // Good - /// Rc::clone(&x); - /// ``` - pub CLONE_ON_REF_PTR, - restriction, - "using 'clone' on a ref-counted pointer" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `.clone()` on an `&&T`. - /// - /// **Why is this bad?** Cloning an `&&T` copies the inner `&T`, instead of - /// cloning the underlying `T`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// fn main() { - /// let x = vec![1]; - /// let y = &&x; - /// let z = y.clone(); - /// println!("{:p} {:p}", *y, z); // prints out the same pointer - /// } - /// ``` - pub CLONE_DOUBLE_REF, - correctness, - "using `clone` on `&&T`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `.to_string()` on an `&&T` where - /// `T` implements `ToString` directly (like `&&str` or `&&String`). - /// - /// **Why is this bad?** This bypasses the specialized implementation of - /// `ToString` and instead goes through the more expensive string formatting - /// facilities. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// // Generic implementation for `T: Display` is used (slow) - /// ["foo", "bar"].iter().map(|s| s.to_string()); - /// - /// // OK, the specialized impl is used - /// ["foo", "bar"].iter().map(|&s| s.to_string()); - /// ``` - pub INEFFICIENT_TO_STRING, - pedantic, - "using `to_string` on `&&T` where `T: ToString`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `new` not returning a type that contains `Self`. - /// - /// **Why is this bad?** As a convention, `new` methods are used to make a new - /// instance of a type. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// In an impl block: - /// ```rust - /// # struct Foo; - /// # struct NotAFoo; - /// impl Foo { - /// fn new() -> NotAFoo { - /// # NotAFoo - /// } - /// } - /// ``` - /// - /// ```rust - /// # struct Foo; - /// struct Bar(Foo); - /// impl Foo { - /// // Bad. The type name must contain `Self` - /// fn new() -> Bar { - /// # Bar(Foo) - /// } - /// } - /// ``` - /// - /// ```rust - /// # struct Foo; - /// # struct FooError; - /// impl Foo { - /// // Good. Return type contains `Self` - /// fn new() -> Result { - /// # Ok(Foo) - /// } - /// } - /// ``` - /// - /// Or in a trait definition: - /// ```rust - /// pub trait Trait { - /// // Bad. The type name must contain `Self` - /// fn new(); - /// } - /// ``` - /// - /// ```rust - /// pub trait Trait { - /// // Good. Return type contains `Self` - /// fn new() -> Self; - /// } - /// ``` - pub NEW_RET_NO_SELF, - style, - "not returning type containing `Self` in a `new` method" -} - -declare_clippy_lint! { - /// **What it does:** Checks for string methods that receive a single-character - /// `str` as an argument, e.g., `_.split("x")`. - /// - /// **Why is this bad?** Performing these methods using a `char` is faster than - /// using a `str`. - /// - /// **Known problems:** Does not catch multi-byte unicode characters. - /// - /// **Example:** - /// ```rust,ignore - /// // Bad - /// _.split("x"); - /// - /// // Good - /// _.split('x'); - pub SINGLE_CHAR_PATTERN, - perf, - "using a single-character str where a char could be used, e.g., `_.split(\"x\")`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for calling `.step_by(0)` on iterators which panics. - /// - /// **Why is this bad?** This very much looks like an oversight. Use `panic!()` instead if you - /// actually intend to panic. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,should_panic - /// for x in (0..100).step_by(0) { - /// //.. - /// } - /// ``` - pub ITERATOR_STEP_BY_ZERO, - correctness, - "using `Iterator::step_by(0)`, which will panic at runtime" -} - -declare_clippy_lint! { - /// **What it does:** Checks for the use of `iter.nth(0)`. - /// - /// **Why is this bad?** `iter.next()` is equivalent to - /// `iter.nth(0)`, as they both consume the next element, - /// but is more readable. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// # use std::collections::HashSet; - /// // Bad - /// # let mut s = HashSet::new(); - /// # s.insert(1); - /// let x = s.iter().nth(0); - /// - /// // Good - /// # let mut s = HashSet::new(); - /// # s.insert(1); - /// let x = s.iter().next(); - /// ``` - pub ITER_NTH_ZERO, - style, - "replace `iter.nth(0)` with `iter.next()`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for use of `.iter().nth()` (and the related - /// `.iter_mut().nth()`) on standard library types with O(1) element access. - /// - /// **Why is this bad?** `.get()` and `.get_mut()` are more efficient and more - /// readable. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let some_vec = vec![0, 1, 2, 3]; - /// let bad_vec = some_vec.iter().nth(3); - /// let bad_slice = &some_vec[..].iter().nth(3); - /// ``` - /// The correct use would be: - /// ```rust - /// let some_vec = vec![0, 1, 2, 3]; - /// let bad_vec = some_vec.get(3); - /// let bad_slice = &some_vec[..].get(3); - /// ``` - pub ITER_NTH, - perf, - "using `.iter().nth()` on a standard library type with O(1) element access" -} - -declare_clippy_lint! { - /// **What it does:** Checks for use of `.skip(x).next()` on iterators. - /// - /// **Why is this bad?** `.nth(x)` is cleaner - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let some_vec = vec![0, 1, 2, 3]; - /// let bad_vec = some_vec.iter().skip(3).next(); - /// let bad_slice = &some_vec[..].iter().skip(3).next(); - /// ``` - /// The correct use would be: - /// ```rust - /// let some_vec = vec![0, 1, 2, 3]; - /// let bad_vec = some_vec.iter().nth(3); - /// let bad_slice = &some_vec[..].iter().nth(3); - /// ``` - pub ITER_SKIP_NEXT, - style, - "using `.skip(x).next()` on an iterator" -} - -declare_clippy_lint! { - /// **What it does:** Checks for use of `.get().unwrap()` (or - /// `.get_mut().unwrap`) on a standard library type which implements `Index` - /// - /// **Why is this bad?** Using the Index trait (`[]`) is more clear and more - /// concise. - /// - /// **Known problems:** Not a replacement for error handling: Using either - /// `.unwrap()` or the Index trait (`[]`) carries the risk of causing a `panic` - /// if the value being accessed is `None`. If the use of `.get().unwrap()` is a - /// temporary placeholder for dealing with the `Option` type, then this does - /// not mitigate the need for error handling. If there is a chance that `.get()` - /// will be `None` in your program, then it is advisable that the `None` case - /// is handled in a future refactor instead of using `.unwrap()` or the Index - /// trait. - /// - /// **Example:** - /// ```rust - /// let mut some_vec = vec![0, 1, 2, 3]; - /// let last = some_vec.get(3).unwrap(); - /// *some_vec.get_mut(0).unwrap() = 1; - /// ``` - /// The correct use would be: - /// ```rust - /// let mut some_vec = vec![0, 1, 2, 3]; - /// let last = some_vec[3]; - /// some_vec[0] = 1; - /// ``` - pub GET_UNWRAP, - restriction, - "using `.get().unwrap()` or `.get_mut().unwrap()` when using `[]` would work instead" -} - -declare_clippy_lint! { - /// **What it does:** Checks for the use of `.extend(s.chars())` where s is a - /// `&str` or `String`. - /// - /// **Why is this bad?** `.push_str(s)` is clearer - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let abc = "abc"; - /// let def = String::from("def"); - /// let mut s = String::new(); - /// s.extend(abc.chars()); - /// s.extend(def.chars()); - /// ``` - /// The correct use would be: - /// ```rust - /// let abc = "abc"; - /// let def = String::from("def"); - /// let mut s = String::new(); - /// s.push_str(abc); - /// s.push_str(&def); - /// ``` - pub STRING_EXTEND_CHARS, - style, - "using `x.extend(s.chars())` where s is a `&str` or `String`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for the use of `.cloned().collect()` on slice to - /// create a `Vec`. - /// - /// **Why is this bad?** `.to_vec()` is clearer - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let s = [1, 2, 3, 4, 5]; - /// let s2: Vec = s[..].iter().cloned().collect(); - /// ``` - /// The better use would be: - /// ```rust - /// let s = [1, 2, 3, 4, 5]; - /// let s2: Vec = s.to_vec(); - /// ``` - pub ITER_CLONED_COLLECT, - style, - "using `.cloned().collect()` on slice to create a `Vec`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.chars().last()` or - /// `_.chars().next_back()` on a `str` to check if it ends with a given char. - /// - /// **Why is this bad?** Readability, this can be written more concisely as - /// `_.ends_with(_)`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let name = "_"; - /// - /// // Bad - /// name.chars().last() == Some('_') || name.chars().next_back() == Some('-'); - /// - /// // Good - /// name.ends_with('_') || name.ends_with('-'); - /// ``` - pub CHARS_LAST_CMP, - style, - "using `.chars().last()` or `.chars().next_back()` to check if a string ends with a char" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `.as_ref()` or `.as_mut()` where the - /// types before and after the call are the same. - /// - /// **Why is this bad?** The call is unnecessary. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # fn do_stuff(x: &[i32]) {} - /// let x: &[i32] = &[1, 2, 3, 4, 5]; - /// do_stuff(x.as_ref()); - /// ``` - /// The correct use would be: - /// ```rust - /// # fn do_stuff(x: &[i32]) {} - /// let x: &[i32] = &[1, 2, 3, 4, 5]; - /// do_stuff(x); - /// ``` - pub USELESS_ASREF, - complexity, - "using `as_ref` where the types before and after the call are the same" -} - -declare_clippy_lint! { - /// **What it does:** Checks for using `fold` when a more succinct alternative exists. - /// Specifically, this checks for `fold`s which could be replaced by `any`, `all`, - /// `sum` or `product`. - /// - /// **Why is this bad?** Readability. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let _ = (0..3).fold(false, |acc, x| acc || x > 2); - /// ``` - /// This could be written as: - /// ```rust - /// let _ = (0..3).any(|x| x > 2); - /// ``` - pub UNNECESSARY_FOLD, - style, - "using `fold` when a more succinct alternative exists" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `filter_map` calls which could be replaced by `filter` or `map`. - /// More specifically it checks if the closure provided is only performing one of the - /// filter or map operations and suggests the appropriate option. - /// - /// **Why is this bad?** Complexity. The intent is also clearer if only a single - /// operation is being performed. - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```rust - /// let _ = (0..3).filter_map(|x| if x > 2 { Some(x) } else { None }); - /// - /// // As there is no transformation of the argument this could be written as: - /// let _ = (0..3).filter(|&x| x > 2); - /// ``` - /// - /// ```rust - /// let _ = (0..4).filter_map(|x| Some(x + 1)); - /// - /// // As there is no conditional check on the argument this could be written as: - /// let _ = (0..4).map(|x| x + 1); - /// ``` - pub UNNECESSARY_FILTER_MAP, - complexity, - "using `filter_map` when a more succinct alternative exists" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `into_iter` calls on references which should be replaced by `iter` - /// or `iter_mut`. - /// - /// **Why is this bad?** Readability. Calling `into_iter` on a reference will not move out its - /// content into the resulting iterator, which is confusing. It is better just call `iter` or - /// `iter_mut` directly. - /// - /// **Known problems:** None - /// - /// **Example:** - /// - /// ```rust - /// // Bad - /// let _ = (&vec![3, 4, 5]).into_iter(); - /// - /// // Good - /// let _ = (&vec![3, 4, 5]).iter(); - /// ``` - pub INTO_ITER_ON_REF, - style, - "using `.into_iter()` on a reference" -} - -declare_clippy_lint! { - /// **What it does:** Checks for calls to `map` followed by a `count`. - /// - /// **Why is this bad?** It looks suspicious. Maybe `map` was confused with `filter`. - /// If the `map` call is intentional, this should be rewritten. Or, if you intend to - /// drive the iterator to completion, you can just use `for_each` instead. - /// - /// **Known problems:** None - /// - /// **Example:** - /// - /// ```rust - /// let _ = (0..3).map(|x| x + 2).count(); - /// ``` - pub SUSPICIOUS_MAP, - complexity, - "suspicious usage of map" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `MaybeUninit::uninit().assume_init()`. - /// - /// **Why is this bad?** For most types, this is undefined behavior. - /// - /// **Known problems:** For now, we accept empty tuples and tuples / arrays - /// of `MaybeUninit`. There may be other types that allow uninitialized - /// data, but those are not yet rigorously defined. - /// - /// **Example:** - /// - /// ```rust - /// // Beware the UB - /// use std::mem::MaybeUninit; - /// - /// let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; - /// ``` - /// - /// Note that the following is OK: - /// - /// ```rust - /// use std::mem::MaybeUninit; - /// - /// let _: [MaybeUninit; 5] = unsafe { - /// MaybeUninit::uninit().assume_init() - /// }; - /// ``` - pub UNINIT_ASSUMED_INIT, - correctness, - "`MaybeUninit::uninit().assume_init()`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `.checked_add/sub(x).unwrap_or(MAX/MIN)`. - /// - /// **Why is this bad?** These can be written simply with `saturating_add/sub` methods. - /// - /// **Example:** - /// - /// ```rust - /// # let y: u32 = 0; - /// # let x: u32 = 100; - /// let add = x.checked_add(y).unwrap_or(u32::MAX); - /// let sub = x.checked_sub(y).unwrap_or(u32::MIN); - /// ``` - /// - /// can be written using dedicated methods for saturating addition/subtraction as: - /// - /// ```rust - /// # let y: u32 = 0; - /// # let x: u32 = 100; - /// let add = x.saturating_add(y); - /// let sub = x.saturating_sub(y); - /// ``` - pub MANUAL_SATURATING_ARITHMETIC, - style, - "`.chcked_add/sub(x).unwrap_or(MAX/MIN)`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `offset(_)`, `wrapping_`{`add`, `sub`}, etc. on raw pointers to - /// zero-sized types - /// - /// **Why is this bad?** This is a no-op, and likely unintended - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```rust - /// unsafe { (&() as *const ()).offset(1) }; - /// ``` - pub ZST_OFFSET, - correctness, - "Check for offset calculations on raw pointers to zero-sized types" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `FileType::is_file()`. - /// - /// **Why is this bad?** When people testing a file type with `FileType::is_file` - /// they are testing whether a path is something they can get bytes from. But - /// `is_file` doesn't cover special file types in unix-like systems, and doesn't cover - /// symlink in windows. Using `!FileType::is_dir()` is a better way to that intention. - /// - /// **Example:** - /// - /// ```rust - /// # || { - /// let metadata = std::fs::metadata("foo.txt")?; - /// let filetype = metadata.file_type(); - /// - /// if filetype.is_file() { - /// // read file - /// } - /// # Ok::<_, std::io::Error>(()) - /// # }; - /// ``` - /// - /// should be written as: - /// - /// ```rust - /// # || { - /// let metadata = std::fs::metadata("foo.txt")?; - /// let filetype = metadata.file_type(); - /// - /// if !filetype.is_dir() { - /// // read file - /// } - /// # Ok::<_, std::io::Error>(()) - /// # }; - /// ``` - pub FILETYPE_IS_FILE, - restriction, - "`FileType::is_file` is not recommended to test for readable file type" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.as_ref().map(Deref::deref)` or it's aliases (such as String::as_str). - /// - /// **Why is this bad?** Readability, this can be written more concisely as - /// `_.as_deref()`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let opt = Some("".to_string()); - /// opt.as_ref().map(String::as_str) - /// # ; - /// ``` - /// Can be written as - /// ```rust - /// # let opt = Some("".to_string()); - /// opt.as_deref() - /// # ; - /// ``` - pub OPTION_AS_REF_DEREF, - complexity, - "using `as_ref().map(Deref::deref)`, which is more succinctly expressed as `as_deref()`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `iter().next()` on a Slice or an Array - /// - /// **Why is this bad?** These can be shortened into `.get()` - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let a = [1, 2, 3]; - /// # let b = vec![1, 2, 3]; - /// a[2..].iter().next(); - /// b.iter().next(); - /// ``` - /// should be written as: - /// ```rust - /// # let a = [1, 2, 3]; - /// # let b = vec![1, 2, 3]; - /// a.get(2); - /// b.get(0); - /// ``` - pub ITER_NEXT_SLICE, - style, - "using `.iter().next()` on a sliced array, which can be shortened to just `.get()`" -} - -declare_clippy_lint! { - /// **What it does:** Warns when using `push_str`/`insert_str` with a single-character string literal - /// where `push`/`insert` with a `char` would work fine. - /// - /// **Why is this bad?** It's less clear that we are pushing a single character. - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```rust - /// let mut string = String::new(); - /// string.insert_str(0, "R"); - /// string.push_str("R"); - /// ``` - /// Could be written as - /// ```rust - /// let mut string = String::new(); - /// string.insert(0, 'R'); - /// string.push('R'); - /// ``` - pub SINGLE_CHAR_ADD_STR, - style, - "`push_str()` or `insert_str()` used with a single-character string literal as parameter" -} - -declare_clippy_lint! { - /// **What it does:** As the counterpart to `or_fun_call`, this lint looks for unnecessary - /// lazily evaluated closures on `Option` and `Result`. - /// - /// This lint suggests changing the following functions, when eager evaluation results in - /// simpler code: - /// - `unwrap_or_else` to `unwrap_or` - /// - `and_then` to `and` - /// - `or_else` to `or` - /// - `get_or_insert_with` to `get_or_insert` - /// - `ok_or_else` to `ok_or` - /// - /// **Why is this bad?** Using eager evaluation is shorter and simpler in some cases. - /// - /// **Known problems:** It is possible, but not recommended for `Deref` and `Index` to have - /// side effects. Eagerly evaluating them can change the semantics of the program. - /// - /// **Example:** - /// - /// ```rust - /// // example code where clippy issues a warning - /// let opt: Option = None; - /// - /// opt.unwrap_or_else(|| 42); - /// ``` - /// Use instead: - /// ```rust - /// let opt: Option = None; - /// - /// opt.unwrap_or(42); - /// ``` - pub UNNECESSARY_LAZY_EVALUATIONS, - style, - "using unnecessary lazy evaluation, which can be replaced with simpler eager evaluation" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `_.map(_).collect::()`. - /// - /// **Why is this bad?** Using `try_for_each` instead is more readable and idiomatic. - /// - /// **Known problems:** None - /// - /// **Example:** - /// - /// ```rust - /// (0..3).map(|t| Err(t)).collect::>(); - /// ``` - /// Use instead: - /// ```rust - /// (0..3).try_for_each(|t| Err(t)); - /// ``` - pub MAP_COLLECT_RESULT_UNIT, - style, - "using `.map(_).collect::()`, which can be replaced with `try_for_each`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `from_iter()` function calls on types that implement the `FromIterator` - /// trait. - /// - /// **Why is this bad?** It is recommended style to use collect. See - /// [FromIterator documentation](https://doc.rust-lang.org/std/iter/trait.FromIterator.html) - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// use std::iter::FromIterator; - /// - /// let five_fives = std::iter::repeat(5).take(5); - /// - /// let v = Vec::from_iter(five_fives); - /// - /// assert_eq!(v, vec![5, 5, 5, 5, 5]); - /// ``` - /// Use instead: - /// ```rust - /// let five_fives = std::iter::repeat(5).take(5); - /// - /// let v: Vec = five_fives.collect(); - /// - /// assert_eq!(v, vec![5, 5, 5, 5, 5]); - /// ``` - pub FROM_ITER_INSTEAD_OF_COLLECT, - style, - "use `.collect()` instead of `::from_iter()`" -} - -pub struct Methods { - msrv: Option, -} - -impl Methods { - #[must_use] - pub fn new(msrv: Option) -> Self { - Self { msrv } - } -} - -impl_lint_pass!(Methods => [ - UNWRAP_USED, - EXPECT_USED, - SHOULD_IMPLEMENT_TRAIT, - WRONG_SELF_CONVENTION, - WRONG_PUB_SELF_CONVENTION, - OK_EXPECT, - MAP_UNWRAP_OR, - RESULT_MAP_OR_INTO_OPTION, - OPTION_MAP_OR_NONE, - BIND_INSTEAD_OF_MAP, - OR_FUN_CALL, - EXPECT_FUN_CALL, - CHARS_NEXT_CMP, - CHARS_LAST_CMP, - CLONE_ON_COPY, - CLONE_ON_REF_PTR, - CLONE_DOUBLE_REF, - INEFFICIENT_TO_STRING, - NEW_RET_NO_SELF, - SINGLE_CHAR_PATTERN, - SINGLE_CHAR_ADD_STR, - SEARCH_IS_SOME, - FILTER_NEXT, - SKIP_WHILE_NEXT, - FILTER_MAP, - FILTER_MAP_NEXT, - FLAT_MAP_IDENTITY, - FIND_MAP, - MAP_FLATTEN, - ITERATOR_STEP_BY_ZERO, - ITER_NEXT_SLICE, - ITER_NTH, - ITER_NTH_ZERO, - ITER_SKIP_NEXT, - GET_UNWRAP, - STRING_EXTEND_CHARS, - ITER_CLONED_COLLECT, - USELESS_ASREF, - UNNECESSARY_FOLD, - UNNECESSARY_FILTER_MAP, - INTO_ITER_ON_REF, - SUSPICIOUS_MAP, - UNINIT_ASSUMED_INIT, - MANUAL_SATURATING_ARITHMETIC, - ZST_OFFSET, - FILETYPE_IS_FILE, - OPTION_AS_REF_DEREF, - UNNECESSARY_LAZY_EVALUATIONS, - MAP_COLLECT_RESULT_UNIT, - FROM_ITER_INSTEAD_OF_COLLECT, -]); - -impl<'tcx> LateLintPass<'tcx> for Methods { - #[allow(clippy::too_many_lines)] - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - if in_macro(expr.span) { - return; - } - - let (method_names, arg_lists, method_spans) = method_calls(expr, 2); - let method_names: Vec = method_names.iter().map(|s| s.as_str()).collect(); - let method_names: Vec<&str> = method_names.iter().map(|s| &**s).collect(); - - match method_names.as_slice() { - ["unwrap", "get"] => lint_get_unwrap(cx, expr, arg_lists[1], false), - ["unwrap", "get_mut"] => lint_get_unwrap(cx, expr, arg_lists[1], true), - ["unwrap", ..] => lint_unwrap(cx, expr, arg_lists[0]), - ["expect", "ok"] => lint_ok_expect(cx, expr, arg_lists[1]), - ["expect", ..] => lint_expect(cx, expr, arg_lists[0]), - ["unwrap_or", "map"] => option_map_unwrap_or::lint(cx, expr, arg_lists[1], arg_lists[0], method_spans[1]), - ["unwrap_or_else", "map"] => { - if !lint_map_unwrap_or_else(cx, expr, arg_lists[1], arg_lists[0], self.msrv.as_ref()) { - unnecessary_lazy_eval::lint(cx, expr, arg_lists[0], "unwrap_or"); - } - }, - ["map_or", ..] => lint_map_or_none(cx, expr, arg_lists[0]), - ["and_then", ..] => { - let biom_option_linted = bind_instead_of_map::OptionAndThenSome::lint(cx, expr, arg_lists[0]); - let biom_result_linted = bind_instead_of_map::ResultAndThenOk::lint(cx, expr, arg_lists[0]); - if !biom_option_linted && !biom_result_linted { - unnecessary_lazy_eval::lint(cx, expr, arg_lists[0], "and"); - } - }, - ["or_else", ..] => { - if !bind_instead_of_map::ResultOrElseErrInfo::lint(cx, expr, arg_lists[0]) { - unnecessary_lazy_eval::lint(cx, expr, arg_lists[0], "or"); - } - }, - ["next", "filter"] => lint_filter_next(cx, expr, arg_lists[1]), - ["next", "skip_while"] => lint_skip_while_next(cx, expr, arg_lists[1]), - ["next", "iter"] => lint_iter_next(cx, expr, arg_lists[1]), - ["map", "filter"] => lint_filter_map(cx, expr, arg_lists[1], arg_lists[0]), - ["map", "filter_map"] => lint_filter_map_map(cx, expr, arg_lists[1], arg_lists[0]), - ["next", "filter_map"] => lint_filter_map_next(cx, expr, arg_lists[1], self.msrv.as_ref()), - ["map", "find"] => lint_find_map(cx, expr, arg_lists[1], arg_lists[0]), - ["flat_map", "filter"] => lint_filter_flat_map(cx, expr, arg_lists[1], arg_lists[0]), - ["flat_map", "filter_map"] => lint_filter_map_flat_map(cx, expr, arg_lists[1], arg_lists[0]), - ["flat_map", ..] => lint_flat_map_identity(cx, expr, arg_lists[0], method_spans[0]), - ["flatten", "map"] => lint_map_flatten(cx, expr, arg_lists[1]), - ["is_some", "find"] => lint_search_is_some(cx, expr, "find", arg_lists[1], arg_lists[0], method_spans[1]), - ["is_some", "position"] => { - lint_search_is_some(cx, expr, "position", arg_lists[1], arg_lists[0], method_spans[1]) - }, - ["is_some", "rposition"] => { - lint_search_is_some(cx, expr, "rposition", arg_lists[1], arg_lists[0], method_spans[1]) - }, - ["extend", ..] => lint_extend(cx, expr, arg_lists[0]), - ["nth", "iter"] => lint_iter_nth(cx, expr, &arg_lists, false), - ["nth", "iter_mut"] => lint_iter_nth(cx, expr, &arg_lists, true), - ["nth", ..] => lint_iter_nth_zero(cx, expr, arg_lists[0]), - ["step_by", ..] => lint_step_by(cx, expr, arg_lists[0]), - ["next", "skip"] => lint_iter_skip_next(cx, expr, arg_lists[1]), - ["collect", "cloned"] => lint_iter_cloned_collect(cx, expr, arg_lists[1]), - ["as_ref"] => lint_asref(cx, expr, "as_ref", arg_lists[0]), - ["as_mut"] => lint_asref(cx, expr, "as_mut", arg_lists[0]), - ["fold", ..] => lint_unnecessary_fold(cx, expr, arg_lists[0], method_spans[0]), - ["filter_map", ..] => unnecessary_filter_map::lint(cx, expr, arg_lists[0]), - ["count", "map"] => lint_suspicious_map(cx, expr), - ["assume_init"] => lint_maybe_uninit(cx, &arg_lists[0][0], expr), - ["unwrap_or", arith @ ("checked_add" | "checked_sub" | "checked_mul")] => { - manual_saturating_arithmetic::lint(cx, expr, &arg_lists, &arith["checked_".len()..]) - }, - ["add" | "offset" | "sub" | "wrapping_offset" | "wrapping_add" | "wrapping_sub"] => { - check_pointer_offset(cx, expr, arg_lists[0]) - }, - ["is_file", ..] => lint_filetype_is_file(cx, expr, arg_lists[0]), - ["map", "as_ref"] => { - lint_option_as_ref_deref(cx, expr, arg_lists[1], arg_lists[0], false, self.msrv.as_ref()) - }, - ["map", "as_mut"] => { - lint_option_as_ref_deref(cx, expr, arg_lists[1], arg_lists[0], true, self.msrv.as_ref()) - }, - ["unwrap_or_else", ..] => unnecessary_lazy_eval::lint(cx, expr, arg_lists[0], "unwrap_or"), - ["get_or_insert_with", ..] => unnecessary_lazy_eval::lint(cx, expr, arg_lists[0], "get_or_insert"), - ["ok_or_else", ..] => unnecessary_lazy_eval::lint(cx, expr, arg_lists[0], "ok_or"), - ["collect", "map"] => lint_map_collect(cx, expr, arg_lists[1], arg_lists[0]), - _ => {}, - } - - match expr.kind { - hir::ExprKind::Call(ref func, ref args) => { - if let hir::ExprKind::Path(path) = &func.kind { - if match_qpath(path, &["from_iter"]) { - lint_from_iter(cx, expr, args); - } - } - }, - hir::ExprKind::MethodCall(ref method_call, ref method_span, ref args, _) => { - lint_or_fun_call(cx, expr, *method_span, &method_call.ident.as_str(), args); - lint_expect_fun_call(cx, expr, *method_span, &method_call.ident.as_str(), args); - - let self_ty = cx.typeck_results().expr_ty_adjusted(&args[0]); - if args.len() == 1 && method_call.ident.name == sym::clone { - lint_clone_on_copy(cx, expr, &args[0], self_ty); - lint_clone_on_ref_ptr(cx, expr, &args[0]); - } - if args.len() == 1 && method_call.ident.name == sym!(to_string) { - inefficient_to_string::lint(cx, expr, &args[0], self_ty); - } - - if let Some(fn_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) { - if match_def_path(cx, fn_def_id, &paths::PUSH_STR) { - lint_single_char_push_string(cx, expr, args); - } else if match_def_path(cx, fn_def_id, &paths::INSERT_STR) { - lint_single_char_insert_string(cx, expr, args); - } - } - - match self_ty.kind() { - ty::Ref(_, ty, _) if *ty.kind() == ty::Str => { - for &(method, pos) in &PATTERN_METHODS { - if method_call.ident.name.as_str() == method && args.len() > pos { - lint_single_char_pattern(cx, expr, &args[pos]); - } - } - }, - ty::Ref(..) if method_call.ident.name == sym::into_iter => { - lint_into_iter(cx, expr, self_ty, *method_span); - }, - _ => (), - } - }, - hir::ExprKind::Binary(op, ref lhs, ref rhs) - if op.node == hir::BinOpKind::Eq || op.node == hir::BinOpKind::Ne => - { - let mut info = BinaryExprInfo { - expr, - chain: lhs, - other: rhs, - eq: op.node == hir::BinOpKind::Eq, - }; - lint_binary_expr_with_method_call(cx, &mut info); - } - _ => (), - } - } - - #[allow(clippy::too_many_lines)] - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { - if in_external_macro(cx.sess(), impl_item.span) { - return; - } - let name = impl_item.ident.name.as_str(); - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id); - let item = cx.tcx.hir().expect_item(parent); - let def_id = cx.tcx.hir().local_def_id(item.hir_id); - let self_ty = cx.tcx.type_of(def_id); - - // if this impl block implements a trait, lint in trait definition instead - if let hir::ItemKind::Impl { of_trait: Some(_), .. } = item.kind { - return; - } - - if_chain! { - if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind; - if let Some(first_arg) = iter_input_pats(&sig.decl, cx.tcx.hir().body(id)).next(); - - let method_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); - let method_sig = cx.tcx.fn_sig(method_def_id); - let method_sig = cx.tcx.erase_late_bound_regions(method_sig); - - let first_arg_ty = &method_sig.inputs().iter().next(); - - // check conventions w.r.t. conversion method names and predicates - if let Some(first_arg_ty) = first_arg_ty; - - then { - if cx.access_levels.is_exported(impl_item.hir_id) { - // check missing trait implementations - for method_config in &TRAIT_METHODS { - if name == method_config.method_name && - sig.decl.inputs.len() == method_config.param_count && - method_config.output_type.matches(cx, &sig.decl.output) && - method_config.self_kind.matches(cx, self_ty, first_arg_ty) && - fn_header_equals(method_config.fn_header, sig.header) && - method_config.lifetime_param_cond(&impl_item) - { - span_lint_and_help( - cx, - SHOULD_IMPLEMENT_TRAIT, - impl_item.span, - &format!( - "method `{}` can be confused for the standard trait method `{}::{}`", - method_config.method_name, - method_config.trait_name, - method_config.method_name - ), - None, - &format!( - "consider implementing the trait `{}` or choosing a less ambiguous method name", - method_config.trait_name - ) - ); - } - } - } - - lint_wrong_self_convention( - cx, - &name, - item.vis.node.is_pub(), - self_ty, - first_arg_ty, - first_arg.pat.span - ); - } - } - - if let hir::ImplItemKind::Fn(_, _) = impl_item.kind { - let ret_ty = return_ty(cx, impl_item.hir_id); - - // walk the return type and check for Self (this does not check associated types) - if contains_ty(ret_ty, self_ty) { - return; - } - - // if return type is impl trait, check the associated types - if let ty::Opaque(def_id, _) = *ret_ty.kind() { - // one of the associated types must be Self - for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) { - if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() { - // walk the associated type and check for Self - if contains_ty(projection_predicate.ty, self_ty) { - return; - } - } - } - } - - if name == "new" && !TyS::same_type(ret_ty, self_ty) { - span_lint( - cx, - NEW_RET_NO_SELF, - impl_item.span, - "methods called `new` usually return `Self`", - ); - } - } - } - - fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { - if in_external_macro(cx.tcx.sess, item.span) { - return; - } - - if_chain! { - if let TraitItemKind::Fn(ref sig, _) = item.kind; - if let Some(first_arg_ty) = sig.decl.inputs.iter().next(); - let first_arg_span = first_arg_ty.span; - let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty); - let self_ty = TraitRef::identity(cx.tcx, item.hir_id.owner.to_def_id()).self_ty(); - - then { - lint_wrong_self_convention(cx, &item.ident.name.as_str(), false, self_ty, first_arg_ty, first_arg_span); - } - } - - if_chain! { - if item.ident.name == sym::new; - if let TraitItemKind::Fn(_, _) = item.kind; - let ret_ty = return_ty(cx, item.hir_id); - let self_ty = TraitRef::identity(cx.tcx, item.hir_id.owner.to_def_id()).self_ty(); - if !contains_ty(ret_ty, self_ty); - - then { - span_lint( - cx, - NEW_RET_NO_SELF, - item.span, - "methods called `new` usually return `Self`", - ); - } - } - } - - extract_msrv_attr!(LateContext); -} - -fn lint_wrong_self_convention<'tcx>( - cx: &LateContext<'tcx>, - item_name: &str, - is_pub: bool, - self_ty: &'tcx TyS<'tcx>, - first_arg_ty: &'tcx TyS<'tcx>, - first_arg_span: Span, -) { - let lint = if is_pub { - WRONG_PUB_SELF_CONVENTION - } else { - WRONG_SELF_CONVENTION - }; - if let Some((ref conv, self_kinds)) = &CONVENTIONS.iter().find(|(ref conv, _)| conv.check(item_name)) { - if !self_kinds.iter().any(|k| k.matches(cx, self_ty, first_arg_ty)) { - span_lint( - cx, - lint, - first_arg_span, - &format!( - "methods called `{}` usually take {}; consider choosing a less ambiguous name", - conv, - &self_kinds - .iter() - .map(|k| k.description()) - .collect::>() - .join(" or ") - ), - ); - } - } -} - -/// Checks for the `OR_FUN_CALL` lint. -#[allow(clippy::too_many_lines)] -fn lint_or_fun_call<'tcx>( - cx: &LateContext<'tcx>, - expr: &hir::Expr<'_>, - method_span: Span, - name: &str, - args: &'tcx [hir::Expr<'_>], -) { - /// Checks for `unwrap_or(T::new())` or `unwrap_or(T::default())`. - fn check_unwrap_or_default( - cx: &LateContext<'_>, - name: &str, - fun: &hir::Expr<'_>, - self_expr: &hir::Expr<'_>, - arg: &hir::Expr<'_>, - or_has_args: bool, - span: Span, - ) -> bool { - if_chain! { - if !or_has_args; - if name == "unwrap_or"; - if let hir::ExprKind::Path(ref qpath) = fun.kind; - let path = &*last_path_segment(qpath).ident.as_str(); - if ["default", "new"].contains(&path); - let arg_ty = cx.typeck_results().expr_ty(arg); - if let Some(default_trait_id) = get_trait_def_id(cx, &paths::DEFAULT_TRAIT); - if implements_trait(cx, arg_ty, default_trait_id, &[]); - - then { - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - OR_FUN_CALL, - span, - &format!("use of `{}` followed by a call to `{}`", name, path), - "try this", - format!( - "{}.unwrap_or_default()", - snippet_with_applicability(cx, self_expr.span, "..", &mut applicability) - ), - applicability, - ); - - true - } else { - false - } - } - } - - /// Checks for `*or(foo())`. - #[allow(clippy::too_many_arguments)] - fn check_general_case<'tcx>( - cx: &LateContext<'tcx>, - name: &str, - method_span: Span, - self_expr: &hir::Expr<'_>, - arg: &'tcx hir::Expr<'_>, - span: Span, - // None if lambda is required - fun_span: Option, - ) { - // (path, fn_has_argument, methods, suffix) - static KNOW_TYPES: [(&[&str], bool, &[&str], &str); 4] = [ - (&paths::BTREEMAP_ENTRY, false, &["or_insert"], "with"), - (&paths::HASHMAP_ENTRY, false, &["or_insert"], "with"), - (&paths::OPTION, false, &["map_or", "ok_or", "or", "unwrap_or"], "else"), - (&paths::RESULT, true, &["or", "unwrap_or"], "else"), - ]; - - if let hir::ExprKind::MethodCall(ref path, _, ref args, _) = &arg.kind { - if path.ident.as_str() == "len" { - let ty = cx.typeck_results().expr_ty(&args[0]).peel_refs(); - - match ty.kind() { - ty::Slice(_) | ty::Array(_, _) => return, - _ => (), - } - - if is_type_diagnostic_item(cx, ty, sym::vec_type) { - return; - } - } - } - - if_chain! { - if KNOW_TYPES.iter().any(|k| k.2.contains(&name)); - - if is_lazyness_candidate(cx, arg); - if !contains_return(&arg); - - let self_ty = cx.typeck_results().expr_ty(self_expr); - - if let Some(&(_, fn_has_arguments, poss, suffix)) = - KNOW_TYPES.iter().find(|&&i| match_type(cx, self_ty, i.0)); - - if poss.contains(&name); - - then { - let sugg: Cow<'_, str> = { - let (snippet_span, use_lambda) = match (fn_has_arguments, fun_span) { - (false, Some(fun_span)) => (fun_span, false), - _ => (arg.span, true), - }; - let snippet = snippet_with_macro_callsite(cx, snippet_span, ".."); - if use_lambda { - let l_arg = if fn_has_arguments { "_" } else { "" }; - format!("|{}| {}", l_arg, snippet).into() - } else { - snippet - } - }; - let span_replace_word = method_span.with_hi(span.hi()); - span_lint_and_sugg( - cx, - OR_FUN_CALL, - span_replace_word, - &format!("use of `{}` followed by a function call", name), - "try this", - format!("{}_{}({})", name, suffix, sugg), - Applicability::HasPlaceholders, - ); - } - } - } - - if args.len() == 2 { - match args[1].kind { - hir::ExprKind::Call(ref fun, ref or_args) => { - let or_has_args = !or_args.is_empty(); - if !check_unwrap_or_default(cx, name, fun, &args[0], &args[1], or_has_args, expr.span) { - let fun_span = if or_has_args { None } else { Some(fun.span) }; - check_general_case(cx, name, method_span, &args[0], &args[1], expr.span, fun_span); - } - }, - hir::ExprKind::Index(..) | hir::ExprKind::MethodCall(..) => { - check_general_case(cx, name, method_span, &args[0], &args[1], expr.span, None); - }, - _ => {}, - } - } -} - -/// Checks for the `EXPECT_FUN_CALL` lint. -#[allow(clippy::too_many_lines)] -fn lint_expect_fun_call( - cx: &LateContext<'_>, - expr: &hir::Expr<'_>, - method_span: Span, - name: &str, - args: &[hir::Expr<'_>], -) { - // Strip `&`, `as_ref()` and `as_str()` off `arg` until we're left with either a `String` or - // `&str` - fn get_arg_root<'a>(cx: &LateContext<'_>, arg: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> { - let mut arg_root = arg; - loop { - arg_root = match &arg_root.kind { - hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, expr) => expr, - hir::ExprKind::MethodCall(method_name, _, call_args, _) => { - if call_args.len() == 1 - && (method_name.ident.name == sym::as_str || method_name.ident.name == sym!(as_ref)) - && { - let arg_type = cx.typeck_results().expr_ty(&call_args[0]); - let base_type = arg_type.peel_refs(); - *base_type.kind() == ty::Str || is_type_diagnostic_item(cx, base_type, sym::string_type) - } - { - &call_args[0] - } else { - break; - } - }, - _ => break, - }; - } - arg_root - } - - // Only `&'static str` or `String` can be used directly in the `panic!`. Other types should be - // converted to string. - fn requires_to_string(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool { - let arg_ty = cx.typeck_results().expr_ty(arg); - if is_type_diagnostic_item(cx, arg_ty, sym::string_type) { - return false; - } - if let ty::Ref(_, ty, ..) = arg_ty.kind() { - if *ty.kind() == ty::Str && can_be_static_str(cx, arg) { - return false; - } - }; - true - } - - // Check if an expression could have type `&'static str`, knowing that it - // has type `&str` for some lifetime. - fn can_be_static_str(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool { - match arg.kind { - hir::ExprKind::Lit(_) => true, - hir::ExprKind::Call(fun, _) => { - if let hir::ExprKind::Path(ref p) = fun.kind { - match cx.qpath_res(p, fun.hir_id) { - hir::def::Res::Def(hir::def::DefKind::Fn | hir::def::DefKind::AssocFn, def_id) => matches!( - cx.tcx.fn_sig(def_id).output().skip_binder().kind(), - ty::Ref(ty::ReStatic, ..) - ), - _ => false, - } - } else { - false - } - }, - hir::ExprKind::MethodCall(..) => { - cx.typeck_results() - .type_dependent_def_id(arg.hir_id) - .map_or(false, |method_id| { - matches!( - cx.tcx.fn_sig(method_id).output().skip_binder().kind(), - ty::Ref(ty::ReStatic, ..) - ) - }) - }, - hir::ExprKind::Path(ref p) => matches!( - cx.qpath_res(p, arg.hir_id), - hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static, _) - ), - _ => false, - } - } - - fn generate_format_arg_snippet( - cx: &LateContext<'_>, - a: &hir::Expr<'_>, - applicability: &mut Applicability, - ) -> Vec { - if_chain! { - if let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, ref format_arg) = a.kind; - if let hir::ExprKind::Match(ref format_arg_expr, _, _) = format_arg.kind; - if let hir::ExprKind::Tup(ref format_arg_expr_tup) = format_arg_expr.kind; - - then { - format_arg_expr_tup - .iter() - .map(|a| snippet_with_applicability(cx, a.span, "..", applicability).into_owned()) - .collect() - } else { - unreachable!() - } - } - } - - fn is_call(node: &hir::ExprKind<'_>) -> bool { - match node { - hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, expr) => { - is_call(&expr.kind) - }, - hir::ExprKind::Call(..) - | hir::ExprKind::MethodCall(..) - // These variants are debatable or require further examination - | hir::ExprKind::Match(..) - | hir::ExprKind::Block{ .. } => true, - _ => false, - } - } - - if args.len() != 2 || name != "expect" || !is_call(&args[1].kind) { - return; - } - - let receiver_type = cx.typeck_results().expr_ty_adjusted(&args[0]); - let closure_args = if is_type_diagnostic_item(cx, receiver_type, sym::option_type) { - "||" - } else if is_type_diagnostic_item(cx, receiver_type, sym::result_type) { - "|_|" - } else { - return; - }; - - let arg_root = get_arg_root(cx, &args[1]); - - let span_replace_word = method_span.with_hi(expr.span.hi()); - - let mut applicability = Applicability::MachineApplicable; - - //Special handling for `format!` as arg_root - if_chain! { - if let hir::ExprKind::Block(block, None) = &arg_root.kind; - if block.stmts.len() == 1; - if let hir::StmtKind::Local(local) = &block.stmts[0].kind; - if let Some(arg_root) = &local.init; - if let hir::ExprKind::Call(ref inner_fun, ref inner_args) = arg_root.kind; - if is_expn_of(inner_fun.span, "format").is_some() && inner_args.len() == 1; - if let hir::ExprKind::Call(_, format_args) = &inner_args[0].kind; - then { - let fmt_spec = &format_args[0]; - let fmt_args = &format_args[1]; - - let mut args = vec![snippet(cx, fmt_spec.span, "..").into_owned()]; - - args.extend(generate_format_arg_snippet(cx, fmt_args, &mut applicability)); - - let sugg = args.join(", "); - - span_lint_and_sugg( - cx, - EXPECT_FUN_CALL, - span_replace_word, - &format!("use of `{}` followed by a function call", name), - "try this", - format!("unwrap_or_else({} panic!({}))", closure_args, sugg), - applicability, - ); - - return; - } - } - - let mut arg_root_snippet: Cow<'_, _> = snippet_with_applicability(cx, arg_root.span, "..", &mut applicability); - if requires_to_string(cx, arg_root) { - arg_root_snippet.to_mut().push_str(".to_string()"); - } - - span_lint_and_sugg( - cx, - EXPECT_FUN_CALL, - span_replace_word, - &format!("use of `{}` followed by a function call", name), - "try this", - format!("unwrap_or_else({} {{ panic!({}) }})", closure_args, arg_root_snippet), - applicability, - ); -} - -/// Checks for the `CLONE_ON_COPY` lint. -fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'_>) { - let ty = cx.typeck_results().expr_ty(expr); - if let ty::Ref(_, inner, _) = arg_ty.kind() { - if let ty::Ref(_, innermost, _) = inner.kind() { - span_lint_and_then( - cx, - CLONE_DOUBLE_REF, - expr.span, - &format!( - "using `clone` on a double-reference; \ - this will copy the reference of type `{}` instead of cloning the inner type", - ty - ), - |diag| { - if let Some(snip) = sugg::Sugg::hir_opt(cx, arg) { - let mut ty = innermost; - let mut n = 0; - while let ty::Ref(_, inner, _) = ty.kind() { - ty = inner; - n += 1; - } - let refs: String = iter::repeat('&').take(n + 1).collect(); - let derefs: String = iter::repeat('*').take(n).collect(); - let explicit = format!("<{}{}>::clone({})", refs, ty, snip); - diag.span_suggestion( - expr.span, - "try dereferencing it", - format!("{}({}{}).clone()", refs, derefs, snip.deref()), - Applicability::MaybeIncorrect, - ); - diag.span_suggestion( - expr.span, - "or try being explicit if you are sure, that you want to clone a reference", - explicit, - Applicability::MaybeIncorrect, - ); - } - }, - ); - return; // don't report clone_on_copy - } - } - - if is_copy(cx, ty) { - let snip; - if let Some(snippet) = sugg::Sugg::hir_opt(cx, arg) { - let parent = cx.tcx.hir().get_parent_node(expr.hir_id); - match &cx.tcx.hir().get(parent) { - hir::Node::Expr(parent) => match parent.kind { - // &*x is a nop, &x.clone() is not - hir::ExprKind::AddrOf(..) => return, - // (*x).func() is useless, x.clone().func() can work in case func borrows mutably - hir::ExprKind::MethodCall(_, _, parent_args, _) if expr.hir_id == parent_args[0].hir_id => { - return; - }, - - _ => {}, - }, - hir::Node::Stmt(stmt) => { - if let hir::StmtKind::Local(ref loc) = stmt.kind { - if let hir::PatKind::Ref(..) = loc.pat.kind { - // let ref y = *x borrows x, let ref y = x.clone() does not - return; - } - } - }, - _ => {}, - } - - // x.clone() might have dereferenced x, possibly through Deref impls - if cx.typeck_results().expr_ty(arg) == ty { - snip = Some(("try removing the `clone` call", format!("{}", snippet))); - } else { - let deref_count = cx - .typeck_results() - .expr_adjustments(arg) - .iter() - .filter(|adj| matches!(adj.kind, ty::adjustment::Adjust::Deref(_))) - .count(); - let derefs: String = iter::repeat('*').take(deref_count).collect(); - snip = Some(("try dereferencing it", format!("{}{}", derefs, snippet))); - } - } else { - snip = None; - } - span_lint_and_then( - cx, - CLONE_ON_COPY, - expr.span, - &format!("using `clone` on type `{}` which implements the `Copy` trait", ty), - |diag| { - if let Some((text, snip)) = snip { - diag.span_suggestion(expr.span, text, snip, Applicability::MachineApplicable); - } - }, - ); - } -} - -fn lint_clone_on_ref_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>) { - let obj_ty = cx.typeck_results().expr_ty(arg).peel_refs(); - - if let ty::Adt(_, subst) = obj_ty.kind() { - let caller_type = if is_type_diagnostic_item(cx, obj_ty, sym::Rc) { - "Rc" - } else if is_type_diagnostic_item(cx, obj_ty, sym::Arc) { - "Arc" - } else if match_type(cx, obj_ty, &paths::WEAK_RC) || match_type(cx, obj_ty, &paths::WEAK_ARC) { - "Weak" - } else { - return; - }; - - let snippet = snippet_with_macro_callsite(cx, arg.span, ".."); - - span_lint_and_sugg( - cx, - CLONE_ON_REF_PTR, - expr.span, - "using `.clone()` on a ref-counted pointer", - "try this", - format!("{}::<{}>::clone(&{})", caller_type, subst.type_at(0), snippet), - Applicability::Unspecified, // Sometimes unnecessary ::<_> after Rc/Arc/Weak - ); - } -} - -fn lint_string_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - let arg = &args[1]; - if let Some(arglists) = method_chain_args(arg, &["chars"]) { - let target = &arglists[0][0]; - let self_ty = cx.typeck_results().expr_ty(target).peel_refs(); - let ref_str = if *self_ty.kind() == ty::Str { - "" - } else if is_type_diagnostic_item(cx, self_ty, sym::string_type) { - "&" - } else { - return; - }; - - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - STRING_EXTEND_CHARS, - expr.span, - "calling `.extend(_.chars())`", - "try this", - format!( - "{}.push_str({}{})", - snippet_with_applicability(cx, args[0].span, "..", &mut applicability), - ref_str, - snippet_with_applicability(cx, target.span, "..", &mut applicability) - ), - applicability, - ); - } -} - -fn lint_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - let obj_ty = cx.typeck_results().expr_ty(&args[0]).peel_refs(); - if is_type_diagnostic_item(cx, obj_ty, sym::string_type) { - lint_string_extend(cx, expr, args); - } -} - -fn lint_iter_cloned_collect<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, iter_args: &'tcx [hir::Expr<'_>]) { - if_chain! { - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::vec_type); - if let Some(slice) = derefs_to_slice(cx, &iter_args[0], cx.typeck_results().expr_ty(&iter_args[0])); - if let Some(to_replace) = expr.span.trim_start(slice.span.source_callsite()); - - then { - span_lint_and_sugg( - cx, - ITER_CLONED_COLLECT, - to_replace, - "called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and \ - more readable", - "try", - ".to_vec()".to_string(), - Applicability::MachineApplicable, - ); - } - } -} - -fn lint_unnecessary_fold(cx: &LateContext<'_>, expr: &hir::Expr<'_>, fold_args: &[hir::Expr<'_>], fold_span: Span) { - fn check_fold_with_op( - cx: &LateContext<'_>, - expr: &hir::Expr<'_>, - fold_args: &[hir::Expr<'_>], - fold_span: Span, - op: hir::BinOpKind, - replacement_method_name: &str, - replacement_has_args: bool, - ) { - if_chain! { - // Extract the body of the closure passed to fold - if let hir::ExprKind::Closure(_, _, body_id, _, _) = fold_args[2].kind; - let closure_body = cx.tcx.hir().body(body_id); - let closure_expr = remove_blocks(&closure_body.value); - - // Check if the closure body is of the form `acc some_expr(x)` - if let hir::ExprKind::Binary(ref bin_op, ref left_expr, ref right_expr) = closure_expr.kind; - if bin_op.node == op; - - // Extract the names of the two arguments to the closure - if let Some(first_arg_ident) = get_arg_name(&closure_body.params[0].pat); - if let Some(second_arg_ident) = get_arg_name(&closure_body.params[1].pat); - - if match_var(&*left_expr, first_arg_ident); - if replacement_has_args || match_var(&*right_expr, second_arg_ident); - - then { - let mut applicability = Applicability::MachineApplicable; - let sugg = if replacement_has_args { - format!( - "{replacement}(|{s}| {r})", - replacement = replacement_method_name, - s = second_arg_ident, - r = snippet_with_applicability(cx, right_expr.span, "EXPR", &mut applicability), - ) - } else { - format!( - "{replacement}()", - replacement = replacement_method_name, - ) - }; - - span_lint_and_sugg( - cx, - UNNECESSARY_FOLD, - fold_span.with_hi(expr.span.hi()), - // TODO #2371 don't suggest e.g., .any(|x| f(x)) if we can suggest .any(f) - "this `.fold` can be written more succinctly using another method", - "try", - sugg, - applicability, - ); - } - } - } - - // Check that this is a call to Iterator::fold rather than just some function called fold - if !match_trait_method(cx, expr, &paths::ITERATOR) { - return; - } - - assert!( - fold_args.len() == 3, - "Expected fold_args to have three entries - the receiver, the initial value and the closure" - ); - - // Check if the first argument to .fold is a suitable literal - if let hir::ExprKind::Lit(ref lit) = fold_args[1].kind { - match lit.node { - ast::LitKind::Bool(false) => { - check_fold_with_op(cx, expr, fold_args, fold_span, hir::BinOpKind::Or, "any", true) - }, - ast::LitKind::Bool(true) => { - check_fold_with_op(cx, expr, fold_args, fold_span, hir::BinOpKind::And, "all", true) - }, - ast::LitKind::Int(0, _) => { - check_fold_with_op(cx, expr, fold_args, fold_span, hir::BinOpKind::Add, "sum", false) - }, - ast::LitKind::Int(1, _) => { - check_fold_with_op(cx, expr, fold_args, fold_span, hir::BinOpKind::Mul, "product", false) - }, - _ => (), - } - } -} - -fn lint_step_by<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, args: &'tcx [hir::Expr<'_>]) { - if match_trait_method(cx, expr, &paths::ITERATOR) { - if let Some((Constant::Int(0), _)) = constant(cx, cx.typeck_results(), &args[1]) { - span_lint( - cx, - ITERATOR_STEP_BY_ZERO, - expr.span, - "Iterator::step_by(0) will panic at runtime", - ); - } - } -} - -fn lint_iter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, iter_args: &'tcx [hir::Expr<'_>]) { - let caller_expr = &iter_args[0]; - - // Skip lint if the `iter().next()` expression is a for loop argument, - // since it is already covered by `&loops::ITER_NEXT_LOOP` - let mut parent_expr_opt = get_parent_expr(cx, expr); - while let Some(parent_expr) = parent_expr_opt { - if higher::for_loop(parent_expr).is_some() { - return; - } - parent_expr_opt = get_parent_expr(cx, parent_expr); - } - - if derefs_to_slice(cx, caller_expr, cx.typeck_results().expr_ty(caller_expr)).is_some() { - // caller is a Slice - if_chain! { - if let hir::ExprKind::Index(ref caller_var, ref index_expr) = &caller_expr.kind; - if let Some(higher::Range { start: Some(start_expr), end: None, limits: ast::RangeLimits::HalfOpen }) - = higher::range(index_expr); - if let hir::ExprKind::Lit(ref start_lit) = &start_expr.kind; - if let ast::LitKind::Int(start_idx, _) = start_lit.node; - then { - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - ITER_NEXT_SLICE, - expr.span, - "using `.iter().next()` on a Slice without end index", - "try calling", - format!("{}.get({})", snippet_with_applicability(cx, caller_var.span, "..", &mut applicability), start_idx), - applicability, - ); - } - } - } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(caller_expr), sym::vec_type) - || matches!( - &cx.typeck_results().expr_ty(caller_expr).peel_refs().kind(), - ty::Array(_, _) - ) - { - // caller is a Vec or an Array - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - ITER_NEXT_SLICE, - expr.span, - "using `.iter().next()` on an array", - "try calling", - format!( - "{}.get(0)", - snippet_with_applicability(cx, caller_expr.span, "..", &mut applicability) - ), - applicability, - ); - } -} - -fn lint_iter_nth<'tcx>( - cx: &LateContext<'tcx>, - expr: &hir::Expr<'_>, - nth_and_iter_args: &[&'tcx [hir::Expr<'tcx>]], - is_mut: bool, -) { - let iter_args = nth_and_iter_args[1]; - let mut_str = if is_mut { "_mut" } else { "" }; - let caller_type = if derefs_to_slice(cx, &iter_args[0], cx.typeck_results().expr_ty(&iter_args[0])).is_some() { - "slice" - } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&iter_args[0]), sym::vec_type) { - "Vec" - } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&iter_args[0]), sym!(vecdeque_type)) { - "VecDeque" - } else { - let nth_args = nth_and_iter_args[0]; - lint_iter_nth_zero(cx, expr, &nth_args); - return; // caller is not a type that we want to lint - }; - - span_lint_and_help( - cx, - ITER_NTH, - expr.span, - &format!("called `.iter{0}().nth()` on a {1}", mut_str, caller_type), - None, - &format!("calling `.get{}()` is both faster and more readable", mut_str), - ); -} - -fn lint_iter_nth_zero<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, nth_args: &'tcx [hir::Expr<'_>]) { - if_chain! { - if match_trait_method(cx, expr, &paths::ITERATOR); - if let Some((Constant::Int(0), _)) = constant(cx, cx.typeck_results(), &nth_args[1]); - then { - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - ITER_NTH_ZERO, - expr.span, - "called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent", - "try calling `.next()` instead of `.nth(0)`", - format!("{}.next()", snippet_with_applicability(cx, nth_args[0].span, "..", &mut applicability)), - applicability, - ); - } - } -} - -fn lint_get_unwrap<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, get_args: &'tcx [hir::Expr<'_>], is_mut: bool) { - // Note: we don't want to lint `get_mut().unwrap` for `HashMap` or `BTreeMap`, - // because they do not implement `IndexMut` - let mut applicability = Applicability::MachineApplicable; - let expr_ty = cx.typeck_results().expr_ty(&get_args[0]); - let get_args_str = if get_args.len() > 1 { - snippet_with_applicability(cx, get_args[1].span, "..", &mut applicability) - } else { - return; // not linting on a .get().unwrap() chain or variant - }; - let mut needs_ref; - let caller_type = if derefs_to_slice(cx, &get_args[0], expr_ty).is_some() { - needs_ref = get_args_str.parse::().is_ok(); - "slice" - } else if is_type_diagnostic_item(cx, expr_ty, sym::vec_type) { - needs_ref = get_args_str.parse::().is_ok(); - "Vec" - } else if is_type_diagnostic_item(cx, expr_ty, sym!(vecdeque_type)) { - needs_ref = get_args_str.parse::().is_ok(); - "VecDeque" - } else if !is_mut && is_type_diagnostic_item(cx, expr_ty, sym!(hashmap_type)) { - needs_ref = true; - "HashMap" - } else if !is_mut && match_type(cx, expr_ty, &paths::BTREEMAP) { - needs_ref = true; - "BTreeMap" - } else { - return; // caller is not a type that we want to lint - }; - - let mut span = expr.span; - - // Handle the case where the result is immediately dereferenced - // by not requiring ref and pulling the dereference into the - // suggestion. - if_chain! { - if needs_ref; - if let Some(parent) = get_parent_expr(cx, expr); - if let hir::ExprKind::Unary(hir::UnOp::UnDeref, _) = parent.kind; - then { - needs_ref = false; - span = parent.span; - } - } - - let mut_str = if is_mut { "_mut" } else { "" }; - let borrow_str = if !needs_ref { - "" - } else if is_mut { - "&mut " - } else { - "&" - }; - - span_lint_and_sugg( - cx, - GET_UNWRAP, - span, - &format!( - "called `.get{0}().unwrap()` on a {1}. Using `[]` is more clear and more concise", - mut_str, caller_type - ), - "try this", - format!( - "{}{}[{}]", - borrow_str, - snippet_with_applicability(cx, get_args[0].span, "..", &mut applicability), - get_args_str - ), - applicability, - ); -} - -fn lint_iter_skip_next(cx: &LateContext<'_>, expr: &hir::Expr<'_>, skip_args: &[hir::Expr<'_>]) { - // lint if caller of skip is an Iterator - if match_trait_method(cx, expr, &paths::ITERATOR) { - if let [caller, n] = skip_args { - let hint = format!(".nth({})", snippet(cx, n.span, "..")); - span_lint_and_sugg( - cx, - ITER_SKIP_NEXT, - expr.span.trim_start(caller.span).unwrap(), - "called `skip(..).next()` on an iterator", - "use `nth` instead", - hint, - Applicability::MachineApplicable, - ); - } - } -} - -fn derefs_to_slice<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx hir::Expr<'tcx>, - ty: Ty<'tcx>, -) -> Option<&'tcx hir::Expr<'tcx>> { - fn may_slice<'a>(cx: &LateContext<'a>, ty: Ty<'a>) -> bool { - match ty.kind() { - ty::Slice(_) => true, - ty::Adt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()), - ty::Adt(..) => is_type_diagnostic_item(cx, ty, sym::vec_type), - ty::Array(_, size) => size - .try_eval_usize(cx.tcx, cx.param_env) - .map_or(false, |size| size < 32), - ty::Ref(_, inner, _) => may_slice(cx, inner), - _ => false, - } - } - - if let hir::ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind { - if path.ident.name == sym::iter && may_slice(cx, cx.typeck_results().expr_ty(&args[0])) { - Some(&args[0]) - } else { - None - } - } else { - match ty.kind() { - ty::Slice(_) => Some(expr), - ty::Adt(def, _) if def.is_box() && may_slice(cx, ty.boxed_ty()) => Some(expr), - ty::Ref(_, inner, _) => { - if may_slice(cx, inner) { - Some(expr) - } else { - None - } - }, - _ => None, - } - } -} - -/// lint use of `unwrap()` for `Option`s and `Result`s -fn lint_unwrap(cx: &LateContext<'_>, expr: &hir::Expr<'_>, unwrap_args: &[hir::Expr<'_>]) { - let obj_ty = cx.typeck_results().expr_ty(&unwrap_args[0]).peel_refs(); - - let mess = if is_type_diagnostic_item(cx, obj_ty, sym::option_type) { - Some((UNWRAP_USED, "an Option", "None")) - } else if is_type_diagnostic_item(cx, obj_ty, sym::result_type) { - Some((UNWRAP_USED, "a Result", "Err")) - } else { - None - }; - - if let Some((lint, kind, none_value)) = mess { - span_lint_and_help( - cx, - lint, - expr.span, - &format!("used `unwrap()` on `{}` value", kind,), - None, - &format!( - "if you don't want to handle the `{}` case gracefully, consider \ - using `expect()` to provide a better panic message", - none_value, - ), - ); - } -} - -/// lint use of `expect()` for `Option`s and `Result`s -fn lint_expect(cx: &LateContext<'_>, expr: &hir::Expr<'_>, expect_args: &[hir::Expr<'_>]) { - let obj_ty = cx.typeck_results().expr_ty(&expect_args[0]).peel_refs(); - - let mess = if is_type_diagnostic_item(cx, obj_ty, sym::option_type) { - Some((EXPECT_USED, "an Option", "None")) - } else if is_type_diagnostic_item(cx, obj_ty, sym::result_type) { - Some((EXPECT_USED, "a Result", "Err")) - } else { - None - }; - - if let Some((lint, kind, none_value)) = mess { - span_lint_and_help( - cx, - lint, - expr.span, - &format!("used `expect()` on `{}` value", kind,), - None, - &format!("if this value is an `{}`, it will panic", none_value,), - ); - } -} - -/// lint use of `ok().expect()` for `Result`s -fn lint_ok_expect(cx: &LateContext<'_>, expr: &hir::Expr<'_>, ok_args: &[hir::Expr<'_>]) { - if_chain! { - // lint if the caller of `ok()` is a `Result` - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&ok_args[0]), sym::result_type); - let result_type = cx.typeck_results().expr_ty(&ok_args[0]); - if let Some(error_type) = get_error_type(cx, result_type); - if has_debug_impl(error_type, cx); - - then { - span_lint_and_help( - cx, - OK_EXPECT, - expr.span, - "called `ok().expect()` on a `Result` value", - None, - "you can call `expect()` directly on the `Result`", - ); - } - } -} - -/// lint use of `map().flatten()` for `Iterators` and 'Options' -fn lint_map_flatten<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map_args: &'tcx [hir::Expr<'_>]) { - // lint if caller of `.map().flatten()` is an Iterator - if match_trait_method(cx, expr, &paths::ITERATOR) { - let map_closure_ty = cx.typeck_results().expr_ty(&map_args[1]); - let is_map_to_option = match map_closure_ty.kind() { - ty::Closure(_, _) | ty::FnDef(_, _) | ty::FnPtr(_) => { - let map_closure_sig = match map_closure_ty.kind() { - ty::Closure(_, substs) => substs.as_closure().sig(), - _ => map_closure_ty.fn_sig(cx.tcx), - }; - let map_closure_return_ty = cx.tcx.erase_late_bound_regions(map_closure_sig.output()); - is_type_diagnostic_item(cx, map_closure_return_ty, sym::option_type) - }, - _ => false, - }; - - let method_to_use = if is_map_to_option { - // `(...).map(...)` has type `impl Iterator> - "filter_map" - } else { - // `(...).map(...)` has type `impl Iterator> - "flat_map" - }; - let func_snippet = snippet(cx, map_args[1].span, ".."); - let hint = format!(".{0}({1})", method_to_use, func_snippet); - span_lint_and_sugg( - cx, - MAP_FLATTEN, - expr.span.with_lo(map_args[0].span.hi()), - "called `map(..).flatten()` on an `Iterator`", - &format!("try using `{}` instead", method_to_use), - hint, - Applicability::MachineApplicable, - ); - } - - // lint if caller of `.map().flatten()` is an Option - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_args[0]), sym::option_type) { - let func_snippet = snippet(cx, map_args[1].span, ".."); - let hint = format!(".and_then({})", func_snippet); - span_lint_and_sugg( - cx, - MAP_FLATTEN, - expr.span.with_lo(map_args[0].span.hi()), - "called `map(..).flatten()` on an `Option`", - "try using `and_then` instead", - hint, - Applicability::MachineApplicable, - ); - } -} - -const MAP_UNWRAP_OR_MSRV: RustcVersion = RustcVersion::new(1, 41, 0); - -/// lint use of `map().unwrap_or_else()` for `Option`s and `Result`s -/// Return true if lint triggered -fn lint_map_unwrap_or_else<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx hir::Expr<'_>, - map_args: &'tcx [hir::Expr<'_>], - unwrap_args: &'tcx [hir::Expr<'_>], - msrv: Option<&RustcVersion>, -) -> bool { - if !meets_msrv(msrv, &MAP_UNWRAP_OR_MSRV) { - return false; - } - // lint if the caller of `map()` is an `Option` - let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_args[0]), sym::option_type); - let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_args[0]), sym::result_type); - - if is_option || is_result { - // Don't make a suggestion that may fail to compile due to mutably borrowing - // the same variable twice. - let map_mutated_vars = mutated_variables(&map_args[0], cx); - let unwrap_mutated_vars = mutated_variables(&unwrap_args[1], cx); - if let (Some(map_mutated_vars), Some(unwrap_mutated_vars)) = (map_mutated_vars, unwrap_mutated_vars) { - if map_mutated_vars.intersection(&unwrap_mutated_vars).next().is_some() { - return false; - } - } else { - return false; - } - - // lint message - let msg = if is_option { - "called `map().unwrap_or_else()` on an `Option` value. This can be done more directly by calling \ - `map_or_else(, )` instead" - } else { - "called `map().unwrap_or_else()` on a `Result` value. This can be done more directly by calling \ - `.map_or_else(, )` instead" - }; - // get snippets for args to map() and unwrap_or_else() - let map_snippet = snippet(cx, map_args[1].span, ".."); - let unwrap_snippet = snippet(cx, unwrap_args[1].span, ".."); - // lint, with note if neither arg is > 1 line and both map() and - // unwrap_or_else() have the same span - let multiline = map_snippet.lines().count() > 1 || unwrap_snippet.lines().count() > 1; - let same_span = map_args[1].span.ctxt() == unwrap_args[1].span.ctxt(); - if same_span && !multiline { - let var_snippet = snippet(cx, map_args[0].span, ".."); - span_lint_and_sugg( - cx, - MAP_UNWRAP_OR, - expr.span, - msg, - "try this", - format!("{}.map_or_else({}, {})", var_snippet, unwrap_snippet, map_snippet), - Applicability::MachineApplicable, - ); - return true; - } else if same_span && multiline { - span_lint(cx, MAP_UNWRAP_OR, expr.span, msg); - return true; - } - } - - false -} - -/// lint use of `_.map_or(None, _)` for `Option`s and `Result`s -fn lint_map_or_none<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map_or_args: &'tcx [hir::Expr<'_>]) { - let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_or_args[0]), sym::option_type); - let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_or_args[0]), sym::result_type); - - // There are two variants of this `map_or` lint: - // (1) using `map_or` as an adapter from `Result` to `Option` - // (2) using `map_or` as a combinator instead of `and_then` - // - // (For this lint) we don't care if any other type calls `map_or` - if !is_option && !is_result { - return; - } - - let (lint_name, msg, instead, hint) = { - let default_arg_is_none = if let hir::ExprKind::Path(ref qpath) = map_or_args[1].kind { - match_qpath(qpath, &paths::OPTION_NONE) - } else { - return; - }; - - if !default_arg_is_none { - // nothing to lint! - return; - } - - let f_arg_is_some = if let hir::ExprKind::Path(ref qpath) = map_or_args[2].kind { - match_qpath(qpath, &paths::OPTION_SOME) - } else { - false - }; - - if is_option { - let self_snippet = snippet(cx, map_or_args[0].span, ".."); - let func_snippet = snippet(cx, map_or_args[2].span, ".."); - let msg = "called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling \ - `and_then(..)` instead"; - ( - OPTION_MAP_OR_NONE, - msg, - "try using `and_then` instead", - format!("{0}.and_then({1})", self_snippet, func_snippet), - ) - } else if f_arg_is_some { - let msg = "called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling \ - `ok()` instead"; - let self_snippet = snippet(cx, map_or_args[0].span, ".."); - ( - RESULT_MAP_OR_INTO_OPTION, - msg, - "try using `ok` instead", - format!("{0}.ok()", self_snippet), - ) - } else { - // nothing to lint! - return; - } - }; - - span_lint_and_sugg( - cx, - lint_name, - expr.span, - msg, - instead, - hint, - Applicability::MachineApplicable, - ); -} - -/// lint use of `filter().next()` for `Iterators` -fn lint_filter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, filter_args: &'tcx [hir::Expr<'_>]) { - // lint if caller of `.filter().next()` is an Iterator - if match_trait_method(cx, expr, &paths::ITERATOR) { - let msg = "called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling \ - `.find(..)` instead."; - let filter_snippet = snippet(cx, filter_args[1].span, ".."); - if filter_snippet.lines().count() <= 1 { - let iter_snippet = snippet(cx, filter_args[0].span, ".."); - // add note if not multi-line - span_lint_and_sugg( - cx, - FILTER_NEXT, - expr.span, - msg, - "try this", - format!("{}.find({})", iter_snippet, filter_snippet), - Applicability::MachineApplicable, - ); - } else { - span_lint(cx, FILTER_NEXT, expr.span, msg); - } - } -} - -/// lint use of `skip_while().next()` for `Iterators` -fn lint_skip_while_next<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx hir::Expr<'_>, - _skip_while_args: &'tcx [hir::Expr<'_>], -) { - // lint if caller of `.skip_while().next()` is an Iterator - if match_trait_method(cx, expr, &paths::ITERATOR) { - span_lint_and_help( - cx, - SKIP_WHILE_NEXT, - expr.span, - "called `skip_while(

).next()` on an `Iterator`", - None, - "this is more succinctly expressed by calling `.find(!

)` instead", - ); - } -} - -/// lint use of `filter().map()` for `Iterators` -fn lint_filter_map<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx hir::Expr<'_>, - _filter_args: &'tcx [hir::Expr<'_>], - _map_args: &'tcx [hir::Expr<'_>], -) { - // lint if caller of `.filter().map()` is an Iterator - if match_trait_method(cx, expr, &paths::ITERATOR) { - let msg = "called `filter(..).map(..)` on an `Iterator`"; - let hint = "this is more succinctly expressed by calling `.filter_map(..)` instead"; - span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint); - } -} - -const FILTER_MAP_NEXT_MSRV: RustcVersion = RustcVersion::new(1, 30, 0); - -/// lint use of `filter_map().next()` for `Iterators` -fn lint_filter_map_next<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx hir::Expr<'_>, - filter_args: &'tcx [hir::Expr<'_>], - msrv: Option<&RustcVersion>, -) { - if match_trait_method(cx, expr, &paths::ITERATOR) { - if !meets_msrv(msrv, &FILTER_MAP_NEXT_MSRV) { - return; - } - - let msg = "called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling \ - `.find_map(..)` instead."; - let filter_snippet = snippet(cx, filter_args[1].span, ".."); - if filter_snippet.lines().count() <= 1 { - let iter_snippet = snippet(cx, filter_args[0].span, ".."); - span_lint_and_sugg( - cx, - FILTER_MAP_NEXT, - expr.span, - msg, - "try this", - format!("{}.find_map({})", iter_snippet, filter_snippet), - Applicability::MachineApplicable, - ); - } else { - span_lint(cx, FILTER_MAP_NEXT, expr.span, msg); - } - } -} - -/// lint use of `find().map()` for `Iterators` -fn lint_find_map<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx hir::Expr<'_>, - _find_args: &'tcx [hir::Expr<'_>], - map_args: &'tcx [hir::Expr<'_>], -) { - // lint if caller of `.filter().map()` is an Iterator - if match_trait_method(cx, &map_args[0], &paths::ITERATOR) { - let msg = "called `find(..).map(..)` on an `Iterator`"; - let hint = "this is more succinctly expressed by calling `.find_map(..)` instead"; - span_lint_and_help(cx, FIND_MAP, expr.span, msg, None, hint); - } -} - -/// lint use of `filter_map().map()` for `Iterators` -fn lint_filter_map_map<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx hir::Expr<'_>, - _filter_args: &'tcx [hir::Expr<'_>], - _map_args: &'tcx [hir::Expr<'_>], -) { - // lint if caller of `.filter().map()` is an Iterator - if match_trait_method(cx, expr, &paths::ITERATOR) { - let msg = "called `filter_map(..).map(..)` on an `Iterator`"; - let hint = "this is more succinctly expressed by only calling `.filter_map(..)` instead"; - span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint); - } -} - -/// lint use of `filter().flat_map()` for `Iterators` -fn lint_filter_flat_map<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx hir::Expr<'_>, - _filter_args: &'tcx [hir::Expr<'_>], - _map_args: &'tcx [hir::Expr<'_>], -) { - // lint if caller of `.filter().flat_map()` is an Iterator - if match_trait_method(cx, expr, &paths::ITERATOR) { - let msg = "called `filter(..).flat_map(..)` on an `Iterator`"; - let hint = "this is more succinctly expressed by calling `.flat_map(..)` \ - and filtering by returning `iter::empty()`"; - span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint); - } -} - -/// lint use of `filter_map().flat_map()` for `Iterators` -fn lint_filter_map_flat_map<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx hir::Expr<'_>, - _filter_args: &'tcx [hir::Expr<'_>], - _map_args: &'tcx [hir::Expr<'_>], -) { - // lint if caller of `.filter_map().flat_map()` is an Iterator - if match_trait_method(cx, expr, &paths::ITERATOR) { - let msg = "called `filter_map(..).flat_map(..)` on an `Iterator`"; - let hint = "this is more succinctly expressed by calling `.flat_map(..)` \ - and filtering by returning `iter::empty()`"; - span_lint_and_help(cx, FILTER_MAP, expr.span, msg, None, hint); - } -} - -/// lint use of `flat_map` for `Iterators` where `flatten` would be sufficient -fn lint_flat_map_identity<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx hir::Expr<'_>, - flat_map_args: &'tcx [hir::Expr<'_>], - flat_map_span: Span, -) { - if match_trait_method(cx, expr, &paths::ITERATOR) { - let arg_node = &flat_map_args[1].kind; - - let apply_lint = |message: &str| { - span_lint_and_sugg( - cx, - FLAT_MAP_IDENTITY, - flat_map_span.with_hi(expr.span.hi()), - message, - "try", - "flatten()".to_string(), - Applicability::MachineApplicable, - ); - }; - - if_chain! { - if let hir::ExprKind::Closure(_, _, body_id, _, _) = arg_node; - let body = cx.tcx.hir().body(*body_id); - - if let hir::PatKind::Binding(_, _, binding_ident, _) = body.params[0].pat.kind; - if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = body.value.kind; - - if path.segments.len() == 1; - if path.segments[0].ident.as_str() == binding_ident.as_str(); - - then { - apply_lint("called `flat_map(|x| x)` on an `Iterator`"); - } - } - - if_chain! { - if let hir::ExprKind::Path(ref qpath) = arg_node; - - if match_qpath(qpath, &paths::STD_CONVERT_IDENTITY); - - then { - apply_lint("called `flat_map(std::convert::identity)` on an `Iterator`"); - } - } - } -} - -/// lint searching an Iterator followed by `is_some()` -/// or calling `find()` on a string followed by `is_some()` -fn lint_search_is_some<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx hir::Expr<'_>, - search_method: &str, - search_args: &'tcx [hir::Expr<'_>], - is_some_args: &'tcx [hir::Expr<'_>], - method_span: Span, -) { - // lint if caller of search is an Iterator - if match_trait_method(cx, &is_some_args[0], &paths::ITERATOR) { - let msg = format!( - "called `is_some()` after searching an `Iterator` with `{}`", - search_method - ); - let hint = "this is more succinctly expressed by calling `any()`"; - let search_snippet = snippet(cx, search_args[1].span, ".."); - if search_snippet.lines().count() <= 1 { - // suggest `any(|x| ..)` instead of `any(|&x| ..)` for `find(|&x| ..).is_some()` - // suggest `any(|..| *..)` instead of `any(|..| **..)` for `find(|..| **..).is_some()` - let any_search_snippet = if_chain! { - if search_method == "find"; - if let hir::ExprKind::Closure(_, _, body_id, ..) = search_args[1].kind; - let closure_body = cx.tcx.hir().body(body_id); - if let Some(closure_arg) = closure_body.params.get(0); - then { - if let hir::PatKind::Ref(..) = closure_arg.pat.kind { - Some(search_snippet.replacen('&', "", 1)) - } else if let Some(name) = get_arg_name(&closure_arg.pat) { - Some(search_snippet.replace(&format!("*{}", name), &name.as_str())) - } else { - None - } - } else { - None - } - }; - // add note if not multi-line - span_lint_and_sugg( - cx, - SEARCH_IS_SOME, - method_span.with_hi(expr.span.hi()), - &msg, - "use `any()` instead", - format!( - "any({})", - any_search_snippet.as_ref().map_or(&*search_snippet, String::as_str) - ), - Applicability::MachineApplicable, - ); - } else { - span_lint_and_help(cx, SEARCH_IS_SOME, expr.span, &msg, None, hint); - } - } - // lint if `find()` is called by `String` or `&str` - else if search_method == "find" { - let is_string_or_str_slice = |e| { - let self_ty = cx.typeck_results().expr_ty(e).peel_refs(); - if is_type_diagnostic_item(cx, self_ty, sym::string_type) { - true - } else { - *self_ty.kind() == ty::Str - } - }; - if_chain! { - if is_string_or_str_slice(&search_args[0]); - if is_string_or_str_slice(&search_args[1]); - then { - let msg = "called `is_some()` after calling `find()` on a string"; - let mut applicability = Applicability::MachineApplicable; - let find_arg = snippet_with_applicability(cx, search_args[1].span, "..", &mut applicability); - span_lint_and_sugg( - cx, - SEARCH_IS_SOME, - method_span.with_hi(expr.span.hi()), - msg, - "use `contains()` instead", - format!("contains({})", find_arg), - applicability, - ); - } - } - } -} - -/// Used for `lint_binary_expr_with_method_call`. -#[derive(Copy, Clone)] -struct BinaryExprInfo<'a> { - expr: &'a hir::Expr<'a>, - chain: &'a hir::Expr<'a>, - other: &'a hir::Expr<'a>, - eq: bool, -} - -/// Checks for the `CHARS_NEXT_CMP` and `CHARS_LAST_CMP` lints. -fn lint_binary_expr_with_method_call(cx: &LateContext<'_>, info: &mut BinaryExprInfo<'_>) { - macro_rules! lint_with_both_lhs_and_rhs { - ($func:ident, $cx:expr, $info:ident) => { - if !$func($cx, $info) { - ::std::mem::swap(&mut $info.chain, &mut $info.other); - if $func($cx, $info) { - return; - } - } - }; - } - - lint_with_both_lhs_and_rhs!(lint_chars_next_cmp, cx, info); - lint_with_both_lhs_and_rhs!(lint_chars_last_cmp, cx, info); - lint_with_both_lhs_and_rhs!(lint_chars_next_cmp_with_unwrap, cx, info); - lint_with_both_lhs_and_rhs!(lint_chars_last_cmp_with_unwrap, cx, info); -} - -/// Wrapper fn for `CHARS_NEXT_CMP` and `CHARS_LAST_CMP` lints. -fn lint_chars_cmp( - cx: &LateContext<'_>, - info: &BinaryExprInfo<'_>, - chain_methods: &[&str], - lint: &'static Lint, - suggest: &str, -) -> bool { - if_chain! { - if let Some(args) = method_chain_args(info.chain, chain_methods); - if let hir::ExprKind::Call(ref fun, ref arg_char) = info.other.kind; - if arg_char.len() == 1; - if let hir::ExprKind::Path(ref qpath) = fun.kind; - if let Some(segment) = single_segment_path(qpath); - if segment.ident.name == sym::Some; - then { - let mut applicability = Applicability::MachineApplicable; - let self_ty = cx.typeck_results().expr_ty_adjusted(&args[0][0]).peel_refs(); - - if *self_ty.kind() != ty::Str { - return false; - } - - span_lint_and_sugg( - cx, - lint, - info.expr.span, - &format!("you should use the `{}` method", suggest), - "like this", - format!("{}{}.{}({})", - if info.eq { "" } else { "!" }, - snippet_with_applicability(cx, args[0][0].span, "..", &mut applicability), - suggest, - snippet_with_applicability(cx, arg_char[0].span, "..", &mut applicability)), - applicability, - ); - - return true; - } - } - - false -} - -/// Checks for the `CHARS_NEXT_CMP` lint. -fn lint_chars_next_cmp<'tcx>(cx: &LateContext<'tcx>, info: &BinaryExprInfo<'_>) -> bool { - lint_chars_cmp(cx, info, &["chars", "next"], CHARS_NEXT_CMP, "starts_with") -} - -/// Checks for the `CHARS_LAST_CMP` lint. -fn lint_chars_last_cmp<'tcx>(cx: &LateContext<'tcx>, info: &BinaryExprInfo<'_>) -> bool { - if lint_chars_cmp(cx, info, &["chars", "last"], CHARS_LAST_CMP, "ends_with") { - true - } else { - lint_chars_cmp(cx, info, &["chars", "next_back"], CHARS_LAST_CMP, "ends_with") - } -} - -/// Wrapper fn for `CHARS_NEXT_CMP` and `CHARS_LAST_CMP` lints with `unwrap()`. -fn lint_chars_cmp_with_unwrap<'tcx>( - cx: &LateContext<'tcx>, - info: &BinaryExprInfo<'_>, - chain_methods: &[&str], - lint: &'static Lint, - suggest: &str, -) -> bool { - if_chain! { - if let Some(args) = method_chain_args(info.chain, chain_methods); - if let hir::ExprKind::Lit(ref lit) = info.other.kind; - if let ast::LitKind::Char(c) = lit.node; - then { - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - lint, - info.expr.span, - &format!("you should use the `{}` method", suggest), - "like this", - format!("{}{}.{}('{}')", - if info.eq { "" } else { "!" }, - snippet_with_applicability(cx, args[0][0].span, "..", &mut applicability), - suggest, - c), - applicability, - ); - - true - } else { - false - } - } -} - -/// Checks for the `CHARS_NEXT_CMP` lint with `unwrap()`. -fn lint_chars_next_cmp_with_unwrap<'tcx>(cx: &LateContext<'tcx>, info: &BinaryExprInfo<'_>) -> bool { - lint_chars_cmp_with_unwrap(cx, info, &["chars", "next", "unwrap"], CHARS_NEXT_CMP, "starts_with") -} - -/// Checks for the `CHARS_LAST_CMP` lint with `unwrap()`. -fn lint_chars_last_cmp_with_unwrap<'tcx>(cx: &LateContext<'tcx>, info: &BinaryExprInfo<'_>) -> bool { - if lint_chars_cmp_with_unwrap(cx, info, &["chars", "last", "unwrap"], CHARS_LAST_CMP, "ends_with") { - true - } else { - lint_chars_cmp_with_unwrap(cx, info, &["chars", "next_back", "unwrap"], CHARS_LAST_CMP, "ends_with") - } -} - -fn get_hint_if_single_char_arg( - cx: &LateContext<'_>, - arg: &hir::Expr<'_>, - applicability: &mut Applicability, -) -> Option { - if_chain! { - if let hir::ExprKind::Lit(lit) = &arg.kind; - if let ast::LitKind::Str(r, style) = lit.node; - let string = r.as_str(); - if string.chars().count() == 1; - then { - let snip = snippet_with_applicability(cx, arg.span, &string, applicability); - let ch = if let ast::StrStyle::Raw(nhash) = style { - let nhash = nhash as usize; - // for raw string: r##"a"## - &snip[(nhash + 2)..(snip.len() - 1 - nhash)] - } else { - // for regular string: "a" - &snip[1..(snip.len() - 1)] - }; - let hint = format!("'{}'", if ch == "'" { "\\'" } else { ch }); - Some(hint) - } else { - None - } - } -} - -/// lint for length-1 `str`s for methods in `PATTERN_METHODS` -fn lint_single_char_pattern(cx: &LateContext<'_>, _expr: &hir::Expr<'_>, arg: &hir::Expr<'_>) { - let mut applicability = Applicability::MachineApplicable; - if let Some(hint) = get_hint_if_single_char_arg(cx, arg, &mut applicability) { - span_lint_and_sugg( - cx, - SINGLE_CHAR_PATTERN, - arg.span, - "single-character string constant used as pattern", - "try using a `char` instead", - hint, - applicability, - ); - } -} - -/// lint for length-1 `str`s as argument for `push_str` -fn lint_single_char_push_string(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - let mut applicability = Applicability::MachineApplicable; - if let Some(extension_string) = get_hint_if_single_char_arg(cx, &args[1], &mut applicability) { - let base_string_snippet = - snippet_with_applicability(cx, args[0].span.source_callsite(), "..", &mut applicability); - let sugg = format!("{}.push({})", base_string_snippet, extension_string); - span_lint_and_sugg( - cx, - SINGLE_CHAR_ADD_STR, - expr.span, - "calling `push_str()` using a single-character string literal", - "consider using `push` with a character literal", - sugg, - applicability, - ); - } -} - -/// lint for length-1 `str`s as argument for `insert_str` -fn lint_single_char_insert_string(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - let mut applicability = Applicability::MachineApplicable; - if let Some(extension_string) = get_hint_if_single_char_arg(cx, &args[2], &mut applicability) { - let base_string_snippet = - snippet_with_applicability(cx, args[0].span.source_callsite(), "_", &mut applicability); - let pos_arg = snippet_with_applicability(cx, args[1].span, "..", &mut applicability); - let sugg = format!("{}.insert({}, {})", base_string_snippet, pos_arg, extension_string); - span_lint_and_sugg( - cx, - SINGLE_CHAR_ADD_STR, - expr.span, - "calling `insert_str()` using a single-character string literal", - "consider using `insert` with a character literal", - sugg, - applicability, - ); - } -} - -/// Checks for the `USELESS_ASREF` lint. -fn lint_asref(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str, as_ref_args: &[hir::Expr<'_>]) { - // when we get here, we've already checked that the call name is "as_ref" or "as_mut" - // check if the call is to the actual `AsRef` or `AsMut` trait - if match_trait_method(cx, expr, &paths::ASREF_TRAIT) || match_trait_method(cx, expr, &paths::ASMUT_TRAIT) { - // check if the type after `as_ref` or `as_mut` is the same as before - let recvr = &as_ref_args[0]; - let rcv_ty = cx.typeck_results().expr_ty(recvr); - let res_ty = cx.typeck_results().expr_ty(expr); - let (base_res_ty, res_depth) = walk_ptrs_ty_depth(res_ty); - let (base_rcv_ty, rcv_depth) = walk_ptrs_ty_depth(rcv_ty); - if base_rcv_ty == base_res_ty && rcv_depth >= res_depth { - // allow the `as_ref` or `as_mut` if it is followed by another method call - if_chain! { - if let Some(parent) = get_parent_expr(cx, expr); - if let hir::ExprKind::MethodCall(_, ref span, _, _) = parent.kind; - if span != &expr.span; - then { - return; - } - } - - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - USELESS_ASREF, - expr.span, - &format!("this call to `{}` does nothing", call_name), - "try this", - snippet_with_applicability(cx, recvr.span, "..", &mut applicability).to_string(), - applicability, - ); - } - } -} - -fn ty_has_iter_method(cx: &LateContext<'_>, self_ref_ty: Ty<'_>) -> Option<(&'static str, &'static str)> { - has_iter_method(cx, self_ref_ty).map(|ty_name| { - let mutbl = match self_ref_ty.kind() { - ty::Ref(_, _, mutbl) => mutbl, - _ => unreachable!(), - }; - let method_name = match mutbl { - hir::Mutability::Not => "iter", - hir::Mutability::Mut => "iter_mut", - }; - (ty_name, method_name) - }) -} - -fn lint_into_iter(cx: &LateContext<'_>, expr: &hir::Expr<'_>, self_ref_ty: Ty<'_>, method_span: Span) { - if !match_trait_method(cx, expr, &paths::INTO_ITERATOR) { - return; - } - if let Some((kind, method_name)) = ty_has_iter_method(cx, self_ref_ty) { - span_lint_and_sugg( - cx, - INTO_ITER_ON_REF, - method_span, - &format!( - "this `.into_iter()` call is equivalent to `.{}()` and will not consume the `{}`", - method_name, kind, - ), - "call directly", - method_name.to_string(), - Applicability::MachineApplicable, - ); - } -} - -/// lint for `MaybeUninit::uninit().assume_init()` (we already have the latter) -fn lint_maybe_uninit(cx: &LateContext<'_>, expr: &hir::Expr<'_>, outer: &hir::Expr<'_>) { - if_chain! { - if let hir::ExprKind::Call(ref callee, ref args) = expr.kind; - if args.is_empty(); - if let hir::ExprKind::Path(ref path) = callee.kind; - if match_qpath(path, &paths::MEM_MAYBEUNINIT_UNINIT); - if !is_maybe_uninit_ty_valid(cx, cx.typeck_results().expr_ty_adjusted(outer)); - then { - span_lint( - cx, - UNINIT_ASSUMED_INIT, - outer.span, - "this call for this type may be undefined behavior" - ); - } - } -} - -fn is_maybe_uninit_ty_valid(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { - match ty.kind() { - ty::Array(ref component, _) => is_maybe_uninit_ty_valid(cx, component), - ty::Tuple(ref types) => types.types().all(|ty| is_maybe_uninit_ty_valid(cx, ty)), - ty::Adt(ref adt, _) => match_def_path(cx, adt.did, &paths::MEM_MAYBEUNINIT), - _ => false, - } -} - -fn lint_suspicious_map(cx: &LateContext<'_>, expr: &hir::Expr<'_>) { - span_lint_and_help( - cx, - SUSPICIOUS_MAP, - expr.span, - "this call to `map()` won't have an effect on the call to `count()`", - None, - "make sure you did not confuse `map` with `filter` or `for_each`", - ); -} - -const OPTION_AS_REF_DEREF_MSRV: RustcVersion = RustcVersion::new(1, 40, 0); - -/// lint use of `_.as_ref().map(Deref::deref)` for `Option`s -fn lint_option_as_ref_deref<'tcx>( - cx: &LateContext<'tcx>, - expr: &hir::Expr<'_>, - as_ref_args: &[hir::Expr<'_>], - map_args: &[hir::Expr<'_>], - is_mut: bool, - msrv: Option<&RustcVersion>, -) { - if !meets_msrv(msrv, &OPTION_AS_REF_DEREF_MSRV) { - return; - } - - let same_mutability = |m| (is_mut && m == &hir::Mutability::Mut) || (!is_mut && m == &hir::Mutability::Not); - - let option_ty = cx.typeck_results().expr_ty(&as_ref_args[0]); - if !is_type_diagnostic_item(cx, option_ty, sym::option_type) { - return; - } - - let deref_aliases: [&[&str]; 9] = [ - &paths::DEREF_TRAIT_METHOD, - &paths::DEREF_MUT_TRAIT_METHOD, - &paths::CSTRING_AS_C_STR, - &paths::OS_STRING_AS_OS_STR, - &paths::PATH_BUF_AS_PATH, - &paths::STRING_AS_STR, - &paths::STRING_AS_MUT_STR, - &paths::VEC_AS_SLICE, - &paths::VEC_AS_MUT_SLICE, - ]; - - let is_deref = match map_args[1].kind { - hir::ExprKind::Path(ref expr_qpath) => cx - .qpath_res(expr_qpath, map_args[1].hir_id) - .opt_def_id() - .map_or(false, |fun_def_id| { - deref_aliases.iter().any(|path| match_def_path(cx, fun_def_id, path)) - }), - hir::ExprKind::Closure(_, _, body_id, _, _) => { - let closure_body = cx.tcx.hir().body(body_id); - let closure_expr = remove_blocks(&closure_body.value); - - match &closure_expr.kind { - hir::ExprKind::MethodCall(_, _, args, _) => { - if_chain! { - if args.len() == 1; - if let hir::ExprKind::Path(qpath) = &args[0].kind; - if let hir::def::Res::Local(local_id) = cx.qpath_res(qpath, args[0].hir_id); - if closure_body.params[0].pat.hir_id == local_id; - let adj = cx - .typeck_results() - .expr_adjustments(&args[0]) - .iter() - .map(|x| &x.kind) - .collect::>(); - if let [ty::adjustment::Adjust::Deref(None), ty::adjustment::Adjust::Borrow(_)] = *adj; - then { - let method_did = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id).unwrap(); - deref_aliases.iter().any(|path| match_def_path(cx, method_did, path)) - } else { - false - } - } - }, - hir::ExprKind::AddrOf(hir::BorrowKind::Ref, m, ref inner) if same_mutability(m) => { - if_chain! { - if let hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner1) = inner.kind; - if let hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner2) = inner1.kind; - if let hir::ExprKind::Path(ref qpath) = inner2.kind; - if let hir::def::Res::Local(local_id) = cx.qpath_res(qpath, inner2.hir_id); - then { - closure_body.params[0].pat.hir_id == local_id - } else { - false - } - } - }, - _ => false, - } - }, - _ => false, - }; - - if is_deref { - let current_method = if is_mut { - format!(".as_mut().map({})", snippet(cx, map_args[1].span, "..")) - } else { - format!(".as_ref().map({})", snippet(cx, map_args[1].span, "..")) - }; - let method_hint = if is_mut { "as_deref_mut" } else { "as_deref" }; - let hint = format!("{}.{}()", snippet(cx, as_ref_args[0].span, ".."), method_hint); - let suggestion = format!("try using {} instead", method_hint); - - let msg = format!( - "called `{0}` on an Option value. This can be done more directly \ - by calling `{1}` instead", - current_method, hint - ); - span_lint_and_sugg( - cx, - OPTION_AS_REF_DEREF, - expr.span, - &msg, - &suggestion, - hint, - Applicability::MachineApplicable, - ); - } -} - -fn lint_map_collect( - cx: &LateContext<'_>, - expr: &hir::Expr<'_>, - map_args: &[hir::Expr<'_>], - collect_args: &[hir::Expr<'_>], -) { - if_chain! { - // called on Iterator - if let [map_expr] = collect_args; - if match_trait_method(cx, map_expr, &paths::ITERATOR); - // return of collect `Result<(),_>` - let collect_ret_ty = cx.typeck_results().expr_ty(expr); - if is_type_diagnostic_item(cx, collect_ret_ty, sym::result_type); - if let ty::Adt(_, substs) = collect_ret_ty.kind(); - if let Some(result_t) = substs.types().next(); - if result_t.is_unit(); - // get parts for snippet - if let [iter, map_fn] = map_args; - then { - span_lint_and_sugg( - cx, - MAP_COLLECT_RESULT_UNIT, - expr.span, - "`.map().collect()` can be replaced with `.try_for_each()`", - "try this", - format!( - "{}.try_for_each({})", - snippet(cx, iter.span, ".."), - snippet(cx, map_fn.span, "..") - ), - Applicability::MachineApplicable, - ); - } - } -} - -/// Given a `Result` type, return its error type (`E`). -fn get_error_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option> { - match ty.kind() { - ty::Adt(_, substs) if is_type_diagnostic_item(cx, ty, sym::result_type) => substs.types().nth(1), - _ => None, - } -} - -/// This checks whether a given type is known to implement Debug. -fn has_debug_impl<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool { - cx.tcx - .get_diagnostic_item(sym::debug_trait) - .map_or(false, |debug| implements_trait(cx, ty, debug, &[])) -} - -enum Convention { - Eq(&'static str), - StartsWith(&'static str), -} - -#[rustfmt::skip] -const CONVENTIONS: [(Convention, &[SelfKind]); 7] = [ - (Convention::Eq("new"), &[SelfKind::No]), - (Convention::StartsWith("as_"), &[SelfKind::Ref, SelfKind::RefMut]), - (Convention::StartsWith("from_"), &[SelfKind::No]), - (Convention::StartsWith("into_"), &[SelfKind::Value]), - (Convention::StartsWith("is_"), &[SelfKind::Ref, SelfKind::No]), - (Convention::Eq("to_mut"), &[SelfKind::RefMut]), - (Convention::StartsWith("to_"), &[SelfKind::Ref]), -]; - -const FN_HEADER: hir::FnHeader = hir::FnHeader { - unsafety: hir::Unsafety::Normal, - constness: hir::Constness::NotConst, - asyncness: hir::IsAsync::NotAsync, - abi: rustc_target::spec::abi::Abi::Rust, -}; - -struct ShouldImplTraitCase { - trait_name: &'static str, - method_name: &'static str, - param_count: usize, - fn_header: hir::FnHeader, - // implicit self kind expected (none, self, &self, ...) - self_kind: SelfKind, - // checks against the output type - output_type: OutType, - // certain methods with explicit lifetimes can't implement the equivalent trait method - lint_explicit_lifetime: bool, -} -impl ShouldImplTraitCase { - const fn new( - trait_name: &'static str, - method_name: &'static str, - param_count: usize, - fn_header: hir::FnHeader, - self_kind: SelfKind, - output_type: OutType, - lint_explicit_lifetime: bool, - ) -> ShouldImplTraitCase { - ShouldImplTraitCase { - trait_name, - method_name, - param_count, - fn_header, - self_kind, - output_type, - lint_explicit_lifetime, - } - } - - fn lifetime_param_cond(&self, impl_item: &hir::ImplItem<'_>) -> bool { - self.lint_explicit_lifetime - || !impl_item.generics.params.iter().any(|p| { - matches!( - p.kind, - hir::GenericParamKind::Lifetime { - kind: hir::LifetimeParamKind::Explicit - } - ) - }) - } -} - -#[rustfmt::skip] -const TRAIT_METHODS: [ShouldImplTraitCase; 30] = [ - ShouldImplTraitCase::new("std::ops::Add", "add", 2, FN_HEADER, SelfKind::Value, OutType::Any, true), - ShouldImplTraitCase::new("std::convert::AsMut", "as_mut", 1, FN_HEADER, SelfKind::RefMut, OutType::Ref, true), - ShouldImplTraitCase::new("std::convert::AsRef", "as_ref", 1, FN_HEADER, SelfKind::Ref, OutType::Ref, true), - ShouldImplTraitCase::new("std::ops::BitAnd", "bitand", 2, FN_HEADER, SelfKind::Value, OutType::Any, true), - ShouldImplTraitCase::new("std::ops::BitOr", "bitor", 2, FN_HEADER, SelfKind::Value, OutType::Any, true), - ShouldImplTraitCase::new("std::ops::BitXor", "bitxor", 2, FN_HEADER, SelfKind::Value, OutType::Any, true), - ShouldImplTraitCase::new("std::borrow::Borrow", "borrow", 1, FN_HEADER, SelfKind::Ref, OutType::Ref, true), - ShouldImplTraitCase::new("std::borrow::BorrowMut", "borrow_mut", 1, FN_HEADER, SelfKind::RefMut, OutType::Ref, true), - ShouldImplTraitCase::new("std::clone::Clone", "clone", 1, FN_HEADER, SelfKind::Ref, OutType::Any, true), - ShouldImplTraitCase::new("std::cmp::Ord", "cmp", 2, FN_HEADER, SelfKind::Ref, OutType::Any, true), - // FIXME: default doesn't work - ShouldImplTraitCase::new("std::default::Default", "default", 0, FN_HEADER, SelfKind::No, OutType::Any, true), - ShouldImplTraitCase::new("std::ops::Deref", "deref", 1, FN_HEADER, SelfKind::Ref, OutType::Ref, true), - ShouldImplTraitCase::new("std::ops::DerefMut", "deref_mut", 1, FN_HEADER, SelfKind::RefMut, OutType::Ref, true), - ShouldImplTraitCase::new("std::ops::Div", "div", 2, FN_HEADER, SelfKind::Value, OutType::Any, true), - ShouldImplTraitCase::new("std::ops::Drop", "drop", 1, FN_HEADER, SelfKind::RefMut, OutType::Unit, true), - ShouldImplTraitCase::new("std::cmp::PartialEq", "eq", 2, FN_HEADER, SelfKind::Ref, OutType::Bool, true), - ShouldImplTraitCase::new("std::iter::FromIterator", "from_iter", 1, FN_HEADER, SelfKind::No, OutType::Any, true), - ShouldImplTraitCase::new("std::str::FromStr", "from_str", 1, FN_HEADER, SelfKind::No, OutType::Any, true), - ShouldImplTraitCase::new("std::hash::Hash", "hash", 2, FN_HEADER, SelfKind::Ref, OutType::Unit, true), - ShouldImplTraitCase::new("std::ops::Index", "index", 2, FN_HEADER, SelfKind::Ref, OutType::Ref, true), - ShouldImplTraitCase::new("std::ops::IndexMut", "index_mut", 2, FN_HEADER, SelfKind::RefMut, OutType::Ref, true), - ShouldImplTraitCase::new("std::iter::IntoIterator", "into_iter", 1, FN_HEADER, SelfKind::Value, OutType::Any, true), - ShouldImplTraitCase::new("std::ops::Mul", "mul", 2, FN_HEADER, SelfKind::Value, OutType::Any, true), - ShouldImplTraitCase::new("std::ops::Neg", "neg", 1, FN_HEADER, SelfKind::Value, OutType::Any, true), - ShouldImplTraitCase::new("std::iter::Iterator", "next", 1, FN_HEADER, SelfKind::RefMut, OutType::Any, false), - ShouldImplTraitCase::new("std::ops::Not", "not", 1, FN_HEADER, SelfKind::Value, OutType::Any, true), - ShouldImplTraitCase::new("std::ops::Rem", "rem", 2, FN_HEADER, SelfKind::Value, OutType::Any, true), - ShouldImplTraitCase::new("std::ops::Shl", "shl", 2, FN_HEADER, SelfKind::Value, OutType::Any, true), - ShouldImplTraitCase::new("std::ops::Shr", "shr", 2, FN_HEADER, SelfKind::Value, OutType::Any, true), - ShouldImplTraitCase::new("std::ops::Sub", "sub", 2, FN_HEADER, SelfKind::Value, OutType::Any, true), -]; - -#[rustfmt::skip] -const PATTERN_METHODS: [(&str, usize); 17] = [ - ("contains", 1), - ("starts_with", 1), - ("ends_with", 1), - ("find", 1), - ("rfind", 1), - ("split", 1), - ("rsplit", 1), - ("split_terminator", 1), - ("rsplit_terminator", 1), - ("splitn", 2), - ("rsplitn", 2), - ("matches", 1), - ("rmatches", 1), - ("match_indices", 1), - ("rmatch_indices", 1), - ("trim_start_matches", 1), - ("trim_end_matches", 1), -]; - -#[derive(Clone, Copy, PartialEq, Debug)] -enum SelfKind { - Value, - Ref, - RefMut, - No, -} - -impl SelfKind { - fn matches<'a>(self, cx: &LateContext<'a>, parent_ty: Ty<'a>, ty: Ty<'a>) -> bool { - fn matches_value<'a>(cx: &LateContext<'a>, parent_ty: Ty<'_>, ty: Ty<'_>) -> bool { - if ty == parent_ty { - true - } else if ty.is_box() { - ty.boxed_ty() == parent_ty - } else if is_type_diagnostic_item(cx, ty, sym::Rc) || is_type_diagnostic_item(cx, ty, sym::Arc) { - if let ty::Adt(_, substs) = ty.kind() { - substs.types().next().map_or(false, |t| t == parent_ty) - } else { - false - } - } else { - false - } - } - - fn matches_ref<'a>(cx: &LateContext<'a>, mutability: hir::Mutability, parent_ty: Ty<'a>, ty: Ty<'a>) -> bool { - if let ty::Ref(_, t, m) = *ty.kind() { - return m == mutability && t == parent_ty; - } - - let trait_path = match mutability { - hir::Mutability::Not => &paths::ASREF_TRAIT, - hir::Mutability::Mut => &paths::ASMUT_TRAIT, - }; - - let trait_def_id = match get_trait_def_id(cx, trait_path) { - Some(did) => did, - None => return false, - }; - implements_trait(cx, ty, trait_def_id, &[parent_ty.into()]) - } - - match self { - Self::Value => matches_value(cx, parent_ty, ty), - Self::Ref => matches_ref(cx, hir::Mutability::Not, parent_ty, ty) || ty == parent_ty && is_copy(cx, ty), - Self::RefMut => matches_ref(cx, hir::Mutability::Mut, parent_ty, ty), - Self::No => ty != parent_ty, - } - } - - #[must_use] - fn description(self) -> &'static str { - match self { - Self::Value => "self by value", - Self::Ref => "self by reference", - Self::RefMut => "self by mutable reference", - Self::No => "no self", - } - } -} - -impl Convention { - #[must_use] - fn check(&self, other: &str) -> bool { - match *self { - Self::Eq(this) => this == other, - Self::StartsWith(this) => other.starts_with(this) && this != other, - } - } -} - -impl fmt::Display for Convention { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - match *self { - Self::Eq(this) => this.fmt(f), - Self::StartsWith(this) => this.fmt(f).and_then(|_| '*'.fmt(f)), - } - } -} - -#[derive(Clone, Copy)] -enum OutType { - Unit, - Bool, - Any, - Ref, -} - -impl OutType { - fn matches(self, cx: &LateContext<'_>, ty: &hir::FnRetTy<'_>) -> bool { - let is_unit = |ty: &hir::Ty<'_>| SpanlessEq::new(cx).eq_ty_kind(&ty.kind, &hir::TyKind::Tup(&[])); - match (self, ty) { - (Self::Unit, &hir::FnRetTy::DefaultReturn(_)) => true, - (Self::Unit, &hir::FnRetTy::Return(ref ty)) if is_unit(ty) => true, - (Self::Bool, &hir::FnRetTy::Return(ref ty)) if is_bool(ty) => true, - (Self::Any, &hir::FnRetTy::Return(ref ty)) if !is_unit(ty) => true, - (Self::Ref, &hir::FnRetTy::Return(ref ty)) => matches!(ty.kind, hir::TyKind::Rptr(_, _)), - _ => false, - } - } -} - -fn is_bool(ty: &hir::Ty<'_>) -> bool { - if let hir::TyKind::Path(ref p) = ty.kind { - match_qpath(p, &["bool"]) - } else { - false - } -} - -fn check_pointer_offset(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - if_chain! { - if args.len() == 2; - if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.typeck_results().expr_ty(&args[0]).kind(); - if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty)); - if layout.is_zst(); - then { - span_lint(cx, ZST_OFFSET, expr.span, "offset calculation on zero-sized value"); - } - } -} - -fn lint_filetype_is_file(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - let ty = cx.typeck_results().expr_ty(&args[0]); - - if !match_type(cx, ty, &paths::FILE_TYPE) { - return; - } - - let span: Span; - let verb: &str; - let lint_unary: &str; - let help_unary: &str; - if_chain! { - if let Some(parent) = get_parent_expr(cx, expr); - if let hir::ExprKind::Unary(op, _) = parent.kind; - if op == hir::UnOp::UnNot; - then { - lint_unary = "!"; - verb = "denies"; - help_unary = ""; - span = parent.span; - } else { - lint_unary = ""; - verb = "covers"; - help_unary = "!"; - span = expr.span; - } - } - let lint_msg = format!("`{}FileType::is_file()` only {} regular files", lint_unary, verb); - let help_msg = format!("use `{}FileType::is_dir()` instead", help_unary); - span_lint_and_help(cx, FILETYPE_IS_FILE, span, &lint_msg, None, &help_msg); -} - -fn lint_from_iter(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - let ty = cx.typeck_results().expr_ty(expr); - let arg_ty = cx.typeck_results().expr_ty(&args[0]); - - if_chain! { - if let Some(from_iter_id) = get_trait_def_id(cx, &paths::FROM_ITERATOR); - if let Some(iter_id) = get_trait_def_id(cx, &paths::ITERATOR); - - if implements_trait(cx, ty, from_iter_id, &[]) && implements_trait(cx, arg_ty, iter_id, &[]); - then { - // `expr` implements `FromIterator` trait - let iter_expr = snippet(cx, args[0].span, ".."); - span_lint_and_sugg( - cx, - FROM_ITER_INSTEAD_OF_COLLECT, - expr.span, - "usage of `FromIterator::from_iter`", - "use `.collect()` instead of `::from_iter()`", - format!("{}.collect()", iter_expr), - Applicability::MaybeIncorrect, - ); - } - } -} - -fn fn_header_equals(expected: hir::FnHeader, actual: hir::FnHeader) -> bool { - expected.constness == actual.constness - && expected.unsafety == actual.unsafety - && expected.asyncness == actual.asyncness -} diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs deleted file mode 100644 index 7763fd5f113f..000000000000 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ /dev/null @@ -1,135 +0,0 @@ -use crate::utils::{differing_macro_contexts, snippet_with_applicability, span_lint_and_then}; -use crate::utils::{is_copy, is_type_diagnostic_item}; -use rustc_data_structures::fx::FxHashSet; -use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_path, NestedVisitorMap, Visitor}; -use rustc_hir::{self, HirId, Path}; -use rustc_lint::LateContext; -use rustc_middle::hir::map::Map; -use rustc_span::source_map::Span; -use rustc_span::{sym, Symbol}; - -use super::MAP_UNWRAP_OR; - -/// lint use of `map().unwrap_or()` for `Option`s -pub(super) fn lint<'tcx>( - cx: &LateContext<'tcx>, - expr: &rustc_hir::Expr<'_>, - map_args: &'tcx [rustc_hir::Expr<'_>], - unwrap_args: &'tcx [rustc_hir::Expr<'_>], - map_span: Span, -) { - // lint if the caller of `map()` is an `Option` - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_args[0]), sym::option_type) { - if !is_copy(cx, cx.typeck_results().expr_ty(&unwrap_args[1])) { - // Do not lint if the `map` argument uses identifiers in the `map` - // argument that are also used in the `unwrap_or` argument - - let mut unwrap_visitor = UnwrapVisitor { - cx, - identifiers: FxHashSet::default(), - }; - unwrap_visitor.visit_expr(&unwrap_args[1]); - - let mut map_expr_visitor = MapExprVisitor { - cx, - identifiers: unwrap_visitor.identifiers, - found_identifier: false, - }; - map_expr_visitor.visit_expr(&map_args[1]); - - if map_expr_visitor.found_identifier { - return; - } - } - - if differing_macro_contexts(unwrap_args[1].span, map_span) { - return; - } - - let mut applicability = Applicability::MachineApplicable; - // get snippet for unwrap_or() - let unwrap_snippet = snippet_with_applicability(cx, unwrap_args[1].span, "..", &mut applicability); - // lint message - // comparing the snippet from source to raw text ("None") below is safe - // because we already have checked the type. - let arg = if unwrap_snippet == "None" { "None" } else { "" }; - let unwrap_snippet_none = unwrap_snippet == "None"; - let suggest = if unwrap_snippet_none { - "and_then()" - } else { - "map_or(, )" - }; - let msg = &format!( - "called `map().unwrap_or({})` on an `Option` value. \ - This can be done more directly by calling `{}` instead", - arg, suggest - ); - - span_lint_and_then(cx, MAP_UNWRAP_OR, expr.span, msg, |diag| { - let map_arg_span = map_args[1].span; - - let mut suggestion = vec![ - ( - map_span, - String::from(if unwrap_snippet_none { "and_then" } else { "map_or" }), - ), - (expr.span.with_lo(unwrap_args[0].span.hi()), String::from("")), - ]; - - if !unwrap_snippet_none { - suggestion.push((map_arg_span.with_hi(map_arg_span.lo()), format!("{}, ", unwrap_snippet))); - } - - diag.multipart_suggestion(&format!("use `{}` instead", suggest), suggestion, applicability); - }); - } -} - -struct UnwrapVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - identifiers: FxHashSet, -} - -impl<'a, 'tcx> Visitor<'tcx> for UnwrapVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) { - self.identifiers.insert(ident(path)); - walk_path(self, path); - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::All(self.cx.tcx.hir()) - } -} - -struct MapExprVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - identifiers: FxHashSet, - found_identifier: bool, -} - -impl<'a, 'tcx> Visitor<'tcx> for MapExprVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) { - if self.identifiers.contains(&ident(path)) { - self.found_identifier = true; - return; - } - walk_path(self, path); - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::All(self.cx.tcx.hir()) - } -} - -fn ident(path: &Path<'_>) -> Symbol { - path.segments - .last() - .expect("segments should be composed of at least 1 element") - .ident - .name -} diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs deleted file mode 100644 index d082a88cd2db..000000000000 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ /dev/null @@ -1,134 +0,0 @@ -use crate::utils::paths; -use crate::utils::usage::mutated_variables; -use crate::utils::{match_qpath, match_trait_method, span_lint}; -use rustc_hir as hir; -use rustc_hir::def::Res; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; -use rustc_lint::LateContext; -use rustc_middle::hir::map::Map; - -use if_chain::if_chain; - -use super::UNNECESSARY_FILTER_MAP; - -pub(super) fn lint(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - if !match_trait_method(cx, expr, &paths::ITERATOR) { - return; - } - - if let hir::ExprKind::Closure(_, _, body_id, ..) = args[1].kind { - let body = cx.tcx.hir().body(body_id); - let arg_id = body.params[0].pat.hir_id; - let mutates_arg = - mutated_variables(&body.value, cx).map_or(true, |used_mutably| used_mutably.contains(&arg_id)); - - let (mut found_mapping, mut found_filtering) = check_expression(&cx, arg_id, &body.value); - - let mut return_visitor = ReturnVisitor::new(&cx, arg_id); - return_visitor.visit_expr(&body.value); - found_mapping |= return_visitor.found_mapping; - found_filtering |= return_visitor.found_filtering; - - if !found_filtering { - span_lint( - cx, - UNNECESSARY_FILTER_MAP, - expr.span, - "this `.filter_map` can be written more simply using `.map`", - ); - return; - } - - if !found_mapping && !mutates_arg { - span_lint( - cx, - UNNECESSARY_FILTER_MAP, - expr.span, - "this `.filter_map` can be written more simply using `.filter`", - ); - return; - } - } -} - -// returns (found_mapping, found_filtering) -fn check_expression<'tcx>(cx: &LateContext<'tcx>, arg_id: hir::HirId, expr: &'tcx hir::Expr<'_>) -> (bool, bool) { - match &expr.kind { - hir::ExprKind::Call(ref func, ref args) => { - if_chain! { - if let hir::ExprKind::Path(ref path) = func.kind; - then { - if match_qpath(path, &paths::OPTION_SOME) { - if_chain! { - if let hir::ExprKind::Path(path) = &args[0].kind; - if let Res::Local(ref local) = cx.qpath_res(path, args[0].hir_id); - then { - if arg_id == *local { - return (false, false) - } - } - } - return (true, false); - } - // We don't know. It might do anything. - return (true, true); - } - } - (true, true) - }, - hir::ExprKind::Block(ref block, _) => block - .expr - .as_ref() - .map_or((false, false), |expr| check_expression(cx, arg_id, &expr)), - hir::ExprKind::Match(_, arms, _) => { - let mut found_mapping = false; - let mut found_filtering = false; - for arm in *arms { - let (m, f) = check_expression(cx, arg_id, &arm.body); - found_mapping |= m; - found_filtering |= f; - } - (found_mapping, found_filtering) - }, - hir::ExprKind::Path(path) if match_qpath(path, &paths::OPTION_NONE) => (false, true), - _ => (true, true), - } -} - -struct ReturnVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - arg_id: hir::HirId, - // Found a non-None return that isn't Some(input) - found_mapping: bool, - // Found a return that isn't Some - found_filtering: bool, -} - -impl<'a, 'tcx> ReturnVisitor<'a, 'tcx> { - fn new(cx: &'a LateContext<'tcx>, arg_id: hir::HirId) -> ReturnVisitor<'a, 'tcx> { - ReturnVisitor { - cx, - arg_id, - found_mapping: false, - found_filtering: false, - } - } -} - -impl<'a, 'tcx> Visitor<'tcx> for ReturnVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { - if let hir::ExprKind::Ret(Some(expr)) = &expr.kind { - let (found_mapping, found_filtering) = check_expression(self.cx, self.arg_id, expr); - self.found_mapping |= found_mapping; - self.found_filtering |= found_filtering; - } else { - walk_expr(self, expr); - } - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} diff --git a/clippy_lints/src/methods/unnecessary_lazy_eval.rs b/clippy_lints/src/methods/unnecessary_lazy_eval.rs deleted file mode 100644 index a867bdb326d7..000000000000 --- a/clippy_lints/src/methods/unnecessary_lazy_eval.rs +++ /dev/null @@ -1,65 +0,0 @@ -use crate::utils::{eager_or_lazy, usage}; -use crate::utils::{is_type_diagnostic_item, snippet, span_lint_and_sugg}; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_lint::LateContext; -use rustc_span::sym; - -use super::UNNECESSARY_LAZY_EVALUATIONS; - -/// lint use of `_else(simple closure)` for `Option`s and `Result`s that can be -/// replaced with `(return value of simple closure)` -pub(super) fn lint<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx hir::Expr<'_>, - args: &'tcx [hir::Expr<'_>], - simplify_using: &str, -) { - let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&args[0]), sym::option_type); - let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&args[0]), sym::result_type); - - if is_option || is_result { - if let hir::ExprKind::Closure(_, _, eid, _, _) = args[1].kind { - let body = cx.tcx.hir().body(eid); - let body_expr = &body.value; - - if usage::BindingUsageFinder::are_params_used(cx, body) { - return; - } - - if eager_or_lazy::is_eagerness_candidate(cx, body_expr) { - let msg = if is_option { - "unnecessary closure used to substitute value for `Option::None`" - } else { - "unnecessary closure used to substitute value for `Result::Err`" - }; - let applicability = if body - .params - .iter() - // bindings are checked to be unused above - .all(|param| matches!(param.pat.kind, hir::PatKind::Binding(..) | hir::PatKind::Wild)) - { - Applicability::MachineApplicable - } else { - // replacing the lambda may break type inference - Applicability::MaybeIncorrect - }; - - span_lint_and_sugg( - cx, - UNNECESSARY_LAZY_EVALUATIONS, - expr.span, - msg, - &format!("Use `{}` instead", simplify_using), - format!( - "{0}.{1}({2})", - snippet(cx, args[0].span, ".."), - simplify_using, - snippet(cx, body_expr.span, ".."), - ), - applicability, - ); - } - } - } -} diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs deleted file mode 100644 index 004dd50a31be..000000000000 --- a/clippy_lints/src/minmax.rs +++ /dev/null @@ -1,123 +0,0 @@ -use crate::consts::{constant_simple, Constant}; -use crate::utils::{match_def_path, match_trait_method, paths, span_lint}; -use if_chain::if_chain; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use std::cmp::Ordering; - -declare_clippy_lint! { - /// **What it does:** Checks for expressions where `std::cmp::min` and `max` are - /// used to clamp values, but switched so that the result is constant. - /// - /// **Why is this bad?** This is in all probability not the intended outcome. At - /// the least it hurts readability of the code. - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```ignore - /// min(0, max(100, x)) - /// ``` - /// or - /// ```ignore - /// x.max(100).min(0) - /// ``` - /// It will always be equal to `0`. Probably the author meant to clamp the value - /// between 0 and 100, but has erroneously swapped `min` and `max`. - pub MIN_MAX, - correctness, - "`min(_, max(_, _))` (or vice versa) with bounds clamping the result to a constant" -} - -declare_lint_pass!(MinMaxPass => [MIN_MAX]); - -impl<'tcx> LateLintPass<'tcx> for MinMaxPass { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let Some((outer_max, outer_c, oe)) = min_max(cx, expr) { - if let Some((inner_max, inner_c, ie)) = min_max(cx, oe) { - if outer_max == inner_max { - return; - } - match ( - outer_max, - Constant::partial_cmp(cx.tcx, cx.typeck_results().expr_ty(ie), &outer_c, &inner_c), - ) { - (_, None) | (MinMax::Max, Some(Ordering::Less)) | (MinMax::Min, Some(Ordering::Greater)) => (), - _ => { - span_lint( - cx, - MIN_MAX, - expr.span, - "this `min`/`max` combination leads to constant result", - ); - }, - } - } - } - } -} - -#[derive(PartialEq, Eq, Debug, Clone, Copy)] -enum MinMax { - Min, - Max, -} - -fn min_max<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(MinMax, Constant, &'a Expr<'a>)> { - match expr.kind { - ExprKind::Call(ref path, ref args) => { - if let ExprKind::Path(ref qpath) = path.kind { - cx.typeck_results() - .qpath_res(qpath, path.hir_id) - .opt_def_id() - .and_then(|def_id| { - if match_def_path(cx, def_id, &paths::CMP_MIN) { - fetch_const(cx, args, MinMax::Min) - } else if match_def_path(cx, def_id, &paths::CMP_MAX) { - fetch_const(cx, args, MinMax::Max) - } else { - None - } - }) - } else { - None - } - }, - ExprKind::MethodCall(ref path, _, ref args, _) => { - if_chain! { - if let [obj, _] = args; - if cx.typeck_results().expr_ty(obj).is_floating_point() || match_trait_method(cx, expr, &paths::ORD); - then { - if path.ident.as_str() == sym!(max).as_str() { - fetch_const(cx, args, MinMax::Max) - } else if path.ident.as_str() == sym!(min).as_str() { - fetch_const(cx, args, MinMax::Min) - } else { - None - } - } else { - None - } - } - }, - _ => None, - } -} - -fn fetch_const<'a>(cx: &LateContext<'_>, args: &'a [Expr<'a>], m: MinMax) -> Option<(MinMax, Constant, &'a Expr<'a>)> { - if args.len() != 2 { - return None; - } - constant_simple(cx, cx.typeck_results(), &args[0]).map_or_else( - || constant_simple(cx, cx.typeck_results(), &args[1]).map(|c| (m, c, &args[0])), - |c| { - if constant_simple(cx, cx.typeck_results(), &args[1]).is_none() { - // otherwise ignore - Some((m, c, &args[1])) - } else { - None - } - }, - ) -} diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs deleted file mode 100644 index 0512d74c7b1c..000000000000 --- a/clippy_lints/src/misc.rs +++ /dev/null @@ -1,768 +0,0 @@ -use if_chain::if_chain; -use rustc_ast::ast::LitKind; -use rustc_errors::Applicability; -use rustc_hir::intravisit::FnKind; -use rustc_hir::{ - self as hir, def, BinOpKind, BindingAnnotation, Body, Expr, ExprKind, FnDecl, HirId, Mutability, PatKind, Stmt, - StmtKind, TyKind, UnOp, -}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, Ty}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::hygiene::DesugaringKind; -use rustc_span::source_map::{ExpnKind, Span}; - -use crate::consts::{constant, Constant}; -use crate::utils::sugg::Sugg; -use crate::utils::{ - get_item_name, get_parent_expr, higher, implements_trait, in_constant, is_integer_const, iter_input_pats, - last_path_segment, match_qpath, match_trait_method, paths, snippet, snippet_opt, span_lint, span_lint_and_sugg, - span_lint_and_then, span_lint_hir_and_then, unsext, SpanlessEq, -}; - -declare_clippy_lint! { - /// **What it does:** Checks for function arguments and let bindings denoted as - /// `ref`. - /// - /// **Why is this bad?** The `ref` declaration makes the function take an owned - /// value, but turns the argument into a reference (which means that the value - /// is destroyed when exiting the function). This adds not much value: either - /// take a reference type, or take an owned value and create references in the - /// body. - /// - /// For let bindings, `let x = &foo;` is preferred over `let ref x = foo`. The - /// type of `x` is more obvious with the former. - /// - /// **Known problems:** If the argument is dereferenced within the function, - /// removing the `ref` will lead to errors. This can be fixed by removing the - /// dereferences, e.g., changing `*x` to `x` within the function. - /// - /// **Example:** - /// ```rust,ignore - /// // Bad - /// fn foo(ref x: u8) -> bool { - /// true - /// } - /// - /// // Good - /// fn foo(x: &u8) -> bool { - /// true - /// } - /// ``` - pub TOPLEVEL_REF_ARG, - style, - "an entire binding declared as `ref`, in a function argument or a `let` statement" -} - -declare_clippy_lint! { - /// **What it does:** Checks for comparisons to NaN. - /// - /// **Why is this bad?** NaN does not compare meaningfully to anything – not - /// even itself – so those comparisons are simply wrong. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let x = 1.0; - /// - /// // Bad - /// if x == f32::NAN { } - /// - /// // Good - /// if x.is_nan() { } - /// ``` - pub CMP_NAN, - correctness, - "comparisons to `NAN`, which will always return false, probably not intended" -} - -declare_clippy_lint! { - /// **What it does:** Checks for (in-)equality comparisons on floating-point - /// values (apart from zero), except in functions called `*eq*` (which probably - /// implement equality for a type involving floats). - /// - /// **Why is this bad?** Floating point calculations are usually imprecise, so - /// asking if two values are *exactly* equal is asking for trouble. For a good - /// guide on what to do, see [the floating point - /// guide](http://www.floating-point-gui.de/errors/comparison). - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let x = 1.2331f64; - /// let y = 1.2332f64; - /// - /// // Bad - /// if y == 1.23f64 { } - /// if y != x {} // where both are floats - /// - /// // Good - /// let error_margin = f64::EPSILON; // Use an epsilon for comparison - /// // Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead. - /// // let error_margin = std::f64::EPSILON; - /// if (y - 1.23f64).abs() < error_margin { } - /// if (y - x).abs() > error_margin { } - /// ``` - pub FLOAT_CMP, - correctness, - "using `==` or `!=` on float values instead of comparing difference with an epsilon" -} - -declare_clippy_lint! { - /// **What it does:** Checks for conversions to owned values just for the sake - /// of a comparison. - /// - /// **Why is this bad?** The comparison can operate on a reference, so creating - /// an owned value effectively throws it away directly afterwards, which is - /// needlessly consuming code and heap space. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let x = "foo"; - /// # let y = String::from("foo"); - /// if x.to_owned() == y {} - /// ``` - /// Could be written as - /// ```rust - /// # let x = "foo"; - /// # let y = String::from("foo"); - /// if x == y {} - /// ``` - pub CMP_OWNED, - perf, - "creating owned instances for comparing with others, e.g., `x == \"foo\".to_string()`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for getting the remainder of a division by one or minus - /// one. - /// - /// **Why is this bad?** The result for a divisor of one can only ever be zero; for - /// minus one it can cause panic/overflow (if the left operand is the minimal value of - /// the respective integer type) or results in zero. No one will write such code - /// deliberately, unless trying to win an Underhanded Rust Contest. Even for that - /// contest, it's probably a bad idea. Use something more underhanded. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let x = 1; - /// let a = x % 1; - /// let a = x % -1; - /// ``` - pub MODULO_ONE, - correctness, - "taking a number modulo +/-1, which can either panic/overflow or always returns 0" -} - -declare_clippy_lint! { - /// **What it does:** Checks for the use of bindings with a single leading - /// underscore. - /// - /// **Why is this bad?** A single leading underscore is usually used to indicate - /// that a binding will not be used. Using such a binding breaks this - /// expectation. - /// - /// **Known problems:** The lint does not work properly with desugaring and - /// macro, it has been allowed in the mean time. - /// - /// **Example:** - /// ```rust - /// let _x = 0; - /// let y = _x + 1; // Here we are using `_x`, even though it has a leading - /// // underscore. We should rename `_x` to `x` - /// ``` - pub USED_UNDERSCORE_BINDING, - pedantic, - "using a binding which is prefixed with an underscore" -} - -declare_clippy_lint! { - /// **What it does:** Checks for the use of short circuit boolean conditions as - /// a - /// statement. - /// - /// **Why is this bad?** Using a short circuit boolean condition as a statement - /// may hide the fact that the second part is executed or not depending on the - /// outcome of the first part. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// f() && g(); // We should write `if f() { g(); }`. - /// ``` - pub SHORT_CIRCUIT_STATEMENT, - complexity, - "using a short circuit boolean condition as a statement" -} - -declare_clippy_lint! { - /// **What it does:** Catch casts from `0` to some pointer type - /// - /// **Why is this bad?** This generally means `null` and is better expressed as - /// {`std`, `core`}`::ptr::`{`null`, `null_mut`}. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// // Bad - /// let a = 0 as *const u32; - /// - /// // Good - /// let a = std::ptr::null::(); - /// ``` - pub ZERO_PTR, - style, - "using `0 as *{const, mut} T`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for (in-)equality comparisons on floating-point - /// value and constant, except in functions called `*eq*` (which probably - /// implement equality for a type involving floats). - /// - /// **Why is this bad?** Floating point calculations are usually imprecise, so - /// asking if two values are *exactly* equal is asking for trouble. For a good - /// guide on what to do, see [the floating point - /// guide](http://www.floating-point-gui.de/errors/comparison). - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let x: f64 = 1.0; - /// const ONE: f64 = 1.00; - /// - /// // Bad - /// if x == ONE { } // where both are floats - /// - /// // Good - /// let error_margin = f64::EPSILON; // Use an epsilon for comparison - /// // Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead. - /// // let error_margin = std::f64::EPSILON; - /// if (x - ONE).abs() < error_margin { } - /// ``` - pub FLOAT_CMP_CONST, - restriction, - "using `==` or `!=` on float constants instead of comparing difference with an epsilon" -} - -declare_lint_pass!(MiscLints => [ - TOPLEVEL_REF_ARG, - CMP_NAN, - FLOAT_CMP, - CMP_OWNED, - MODULO_ONE, - USED_UNDERSCORE_BINDING, - SHORT_CIRCUIT_STATEMENT, - ZERO_PTR, - FLOAT_CMP_CONST -]); - -impl<'tcx> LateLintPass<'tcx> for MiscLints { - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - k: FnKind<'tcx>, - decl: &'tcx FnDecl<'_>, - body: &'tcx Body<'_>, - span: Span, - _: HirId, - ) { - if let FnKind::Closure(_) = k { - // Does not apply to closures - return; - } - if in_external_macro(cx.tcx.sess, span) { - return; - } - for arg in iter_input_pats(decl, body) { - if let PatKind::Binding(BindingAnnotation::Ref | BindingAnnotation::RefMut, ..) = arg.pat.kind { - span_lint( - cx, - TOPLEVEL_REF_ARG, - arg.pat.span, - "`ref` directly on a function argument is ignored. \ - Consider using a reference type instead.", - ); - } - } - } - - fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { - if_chain! { - if !in_external_macro(cx.tcx.sess, stmt.span); - if let StmtKind::Local(ref local) = stmt.kind; - if let PatKind::Binding(an, .., name, None) = local.pat.kind; - if let Some(ref init) = local.init; - if !higher::is_from_for_desugar(local); - then { - if an == BindingAnnotation::Ref || an == BindingAnnotation::RefMut { - // use the macro callsite when the init span (but not the whole local span) - // comes from an expansion like `vec![1, 2, 3]` in `let ref _ = vec![1, 2, 3];` - let sugg_init = if init.span.from_expansion() && !local.span.from_expansion() { - Sugg::hir_with_macro_callsite(cx, init, "..") - } else { - Sugg::hir(cx, init, "..") - }; - let (mutopt, initref) = if an == BindingAnnotation::RefMut { - ("mut ", sugg_init.mut_addr()) - } else { - ("", sugg_init.addr()) - }; - let tyopt = if let Some(ref ty) = local.ty { - format!(": &{mutopt}{ty}", mutopt=mutopt, ty=snippet(cx, ty.span, "..")) - } else { - String::new() - }; - span_lint_hir_and_then( - cx, - TOPLEVEL_REF_ARG, - init.hir_id, - local.pat.span, - "`ref` on an entire `let` pattern is discouraged, take a reference with `&` instead", - |diag| { - diag.span_suggestion( - stmt.span, - "try", - format!( - "let {name}{tyopt} = {initref};", - name=snippet(cx, name.span, ".."), - tyopt=tyopt, - initref=initref, - ), - Applicability::MachineApplicable, - ); - } - ); - } - } - }; - if_chain! { - if let StmtKind::Semi(ref expr) = stmt.kind; - if let ExprKind::Binary(ref binop, ref a, ref b) = expr.kind; - if binop.node == BinOpKind::And || binop.node == BinOpKind::Or; - if let Some(sugg) = Sugg::hir_opt(cx, a); - then { - span_lint_and_then(cx, - SHORT_CIRCUIT_STATEMENT, - stmt.span, - "boolean short circuit operator in statement may be clearer using an explicit test", - |diag| { - let sugg = if binop.node == BinOpKind::Or { !sugg } else { sugg }; - diag.span_suggestion( - stmt.span, - "replace it with", - format!( - "if {} {{ {}; }}", - sugg, - &snippet(cx, b.span, ".."), - ), - Applicability::MachineApplicable, // snippet - ); - }); - } - }; - } - - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - match expr.kind { - ExprKind::Cast(ref e, ref ty) => { - check_cast(cx, expr.span, e, ty); - return; - }, - ExprKind::Binary(ref cmp, ref left, ref right) => { - check_binary(cx, expr, cmp, left, right); - return; - }, - _ => {}, - } - if in_attributes_expansion(expr) || expr.span.is_desugaring(DesugaringKind::Await) { - // Don't lint things expanded by #[derive(...)], etc or `await` desugaring - return; - } - let binding = match expr.kind { - ExprKind::Path(ref qpath) if !matches!(qpath, hir::QPath::LangItem(..)) => { - let binding = last_path_segment(qpath).ident.as_str(); - if binding.starts_with('_') && - !binding.starts_with("__") && - binding != "_result" && // FIXME: #944 - is_used(cx, expr) && - // don't lint if the declaration is in a macro - non_macro_local(cx, cx.qpath_res(qpath, expr.hir_id)) - { - Some(binding) - } else { - None - } - }, - ExprKind::Field(_, ident) => { - let name = ident.as_str(); - if name.starts_with('_') && !name.starts_with("__") { - Some(name) - } else { - None - } - }, - _ => None, - }; - if let Some(binding) = binding { - span_lint( - cx, - USED_UNDERSCORE_BINDING, - expr.span, - &format!( - "used binding `{}` which is prefixed with an underscore. A leading \ - underscore signals that a binding will not be used.", - binding - ), - ); - } - } -} - -fn get_lint_and_message( - is_comparing_constants: bool, - is_comparing_arrays: bool, -) -> (&'static rustc_lint::Lint, &'static str) { - if is_comparing_constants { - ( - FLOAT_CMP_CONST, - if is_comparing_arrays { - "strict comparison of `f32` or `f64` constant arrays" - } else { - "strict comparison of `f32` or `f64` constant" - }, - ) - } else { - ( - FLOAT_CMP, - if is_comparing_arrays { - "strict comparison of `f32` or `f64` arrays" - } else { - "strict comparison of `f32` or `f64`" - }, - ) - } -} - -fn check_nan(cx: &LateContext<'_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) { - if_chain! { - if !in_constant(cx, cmp_expr.hir_id); - if let Some((value, _)) = constant(cx, cx.typeck_results(), expr); - then { - let needs_lint = match value { - Constant::F32(num) => num.is_nan(), - Constant::F64(num) => num.is_nan(), - _ => false, - }; - - if needs_lint { - span_lint( - cx, - CMP_NAN, - cmp_expr.span, - "doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead", - ); - } - } - } -} - -fn is_named_constant<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool { - if let Some((_, res)) = constant(cx, cx.typeck_results(), expr) { - res - } else { - false - } -} - -fn is_allowed<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool { - match constant(cx, cx.typeck_results(), expr) { - Some((Constant::F32(f), _)) => f == 0.0 || f.is_infinite(), - Some((Constant::F64(f), _)) => f == 0.0 || f.is_infinite(), - Some((Constant::Vec(vec), _)) => vec.iter().all(|f| match f { - Constant::F32(f) => *f == 0.0 || (*f).is_infinite(), - Constant::F64(f) => *f == 0.0 || (*f).is_infinite(), - _ => false, - }), - _ => false, - } -} - -// Return true if `expr` is the result of `signum()` invoked on a float value. -fn is_signum(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - // The negation of a signum is still a signum - if let ExprKind::Unary(UnOp::UnNeg, ref child_expr) = expr.kind { - return is_signum(cx, &child_expr); - } - - if_chain! { - if let ExprKind::MethodCall(ref method_name, _, ref expressions, _) = expr.kind; - if sym!(signum) == method_name.ident.name; - // Check that the receiver of the signum() is a float (expressions[0] is the receiver of - // the method call) - then { - return is_float(cx, &expressions[0]); - } - } - false -} - -fn is_float(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - let value = &cx.typeck_results().expr_ty(expr).peel_refs().kind(); - - if let ty::Array(arr_ty, _) = value { - return matches!(arr_ty.kind(), ty::Float(_)); - }; - - matches!(value, ty::Float(_)) -} - -fn is_array(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - matches!(&cx.typeck_results().expr_ty(expr).peel_refs().kind(), ty::Array(_, _)) -} - -fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool) { - #[derive(Default)] - struct EqImpl { - ty_eq_other: bool, - other_eq_ty: bool, - } - - impl EqImpl { - fn is_implemented(&self) -> bool { - self.ty_eq_other || self.other_eq_ty - } - } - - fn symmetric_partial_eq<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, other: Ty<'tcx>) -> Option { - cx.tcx.lang_items().eq_trait().map(|def_id| EqImpl { - ty_eq_other: implements_trait(cx, ty, def_id, &[other.into()]), - other_eq_ty: implements_trait(cx, other, def_id, &[ty.into()]), - }) - } - - let (arg_ty, snip) = match expr.kind { - ExprKind::MethodCall(.., ref args, _) if args.len() == 1 => { - if match_trait_method(cx, expr, &paths::TO_STRING) || match_trait_method(cx, expr, &paths::TO_OWNED) { - (cx.typeck_results().expr_ty(&args[0]), snippet(cx, args[0].span, "..")) - } else { - return; - } - }, - ExprKind::Call(ref path, ref v) if v.len() == 1 => { - if let ExprKind::Path(ref path) = path.kind { - if match_qpath(path, &["String", "from_str"]) || match_qpath(path, &["String", "from"]) { - (cx.typeck_results().expr_ty(&v[0]), snippet(cx, v[0].span, "..")) - } else { - return; - } - } else { - return; - } - }, - _ => return, - }; - - let other_ty = cx.typeck_results().expr_ty(other); - - let without_deref = symmetric_partial_eq(cx, arg_ty, other_ty).unwrap_or_default(); - let with_deref = arg_ty - .builtin_deref(true) - .and_then(|tam| symmetric_partial_eq(cx, tam.ty, other_ty)) - .unwrap_or_default(); - - if !with_deref.is_implemented() && !without_deref.is_implemented() { - return; - } - - let other_gets_derefed = matches!(other.kind, ExprKind::Unary(UnOp::UnDeref, _)); - - let lint_span = if other_gets_derefed { - expr.span.to(other.span) - } else { - expr.span - }; - - span_lint_and_then( - cx, - CMP_OWNED, - lint_span, - "this creates an owned instance just for comparison", - |diag| { - // This also catches `PartialEq` implementations that call `to_owned`. - if other_gets_derefed { - diag.span_label(lint_span, "try implementing the comparison without allocating"); - return; - } - - let expr_snip; - let eq_impl; - if with_deref.is_implemented() { - expr_snip = format!("*{}", snip); - eq_impl = with_deref; - } else { - expr_snip = snip.to_string(); - eq_impl = without_deref; - }; - - let span; - let hint; - if (eq_impl.ty_eq_other && left) || (eq_impl.other_eq_ty && !left) { - span = expr.span; - hint = expr_snip; - } else { - span = expr.span.to(other.span); - if eq_impl.ty_eq_other { - hint = format!("{} == {}", expr_snip, snippet(cx, other.span, "..")); - } else { - hint = format!("{} == {}", snippet(cx, other.span, ".."), expr_snip); - } - } - - diag.span_suggestion( - span, - "try", - hint, - Applicability::MachineApplicable, // snippet - ); - }, - ); -} - -/// Heuristic to see if an expression is used. Should be compatible with -/// `unused_variables`'s idea -/// of what it means for an expression to be "used". -fn is_used(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - get_parent_expr(cx, expr).map_or(true, |parent| match parent.kind { - ExprKind::Assign(_, ref rhs, _) | ExprKind::AssignOp(_, _, ref rhs) => SpanlessEq::new(cx).eq_expr(rhs, expr), - _ => is_used(cx, parent), - }) -} - -/// Tests whether an expression is in a macro expansion (e.g., something -/// generated by `#[derive(...)]` or the like). -fn in_attributes_expansion(expr: &Expr<'_>) -> bool { - use rustc_span::hygiene::MacroKind; - if expr.span.from_expansion() { - let data = expr.span.ctxt().outer_expn_data(); - matches!(data.kind, ExpnKind::Macro(MacroKind::Attr, _)) - } else { - false - } -} - -/// Tests whether `res` is a variable defined outside a macro. -fn non_macro_local(cx: &LateContext<'_>, res: def::Res) -> bool { - if let def::Res::Local(id) = res { - !cx.tcx.hir().span(id).from_expansion() - } else { - false - } -} - -fn check_cast(cx: &LateContext<'_>, span: Span, e: &Expr<'_>, ty: &hir::Ty<'_>) { - if_chain! { - if let TyKind::Ptr(ref mut_ty) = ty.kind; - if let ExprKind::Lit(ref lit) = e.kind; - if let LitKind::Int(0, _) = lit.node; - if !in_constant(cx, e.hir_id); - then { - let (msg, sugg_fn) = match mut_ty.mutbl { - Mutability::Mut => ("`0 as *mut _` detected", "std::ptr::null_mut"), - Mutability::Not => ("`0 as *const _` detected", "std::ptr::null"), - }; - - let (sugg, appl) = if let TyKind::Infer = mut_ty.ty.kind { - (format!("{}()", sugg_fn), Applicability::MachineApplicable) - } else if let Some(mut_ty_snip) = snippet_opt(cx, mut_ty.ty.span) { - (format!("{}::<{}>()", sugg_fn, mut_ty_snip), Applicability::MachineApplicable) - } else { - // `MaybeIncorrect` as type inference may not work with the suggested code - (format!("{}()", sugg_fn), Applicability::MaybeIncorrect) - }; - span_lint_and_sugg(cx, ZERO_PTR, span, msg, "try", sugg, appl); - } - } -} - -fn check_binary( - cx: &LateContext<'a>, - expr: &Expr<'_>, - cmp: &rustc_span::source_map::Spanned, - left: &'a Expr<'_>, - right: &'a Expr<'_>, -) { - let op = cmp.node; - if op.is_comparison() { - check_nan(cx, left, expr); - check_nan(cx, right, expr); - check_to_owned(cx, left, right, true); - check_to_owned(cx, right, left, false); - } - if (op == BinOpKind::Eq || op == BinOpKind::Ne) && (is_float(cx, left) || is_float(cx, right)) { - if is_allowed(cx, left) || is_allowed(cx, right) { - return; - } - - // Allow comparing the results of signum() - if is_signum(cx, left) && is_signum(cx, right) { - return; - } - - if let Some(name) = get_item_name(cx, expr) { - let name = name.as_str(); - if name == "eq" || name == "ne" || name == "is_nan" || name.starts_with("eq_") || name.ends_with("_eq") { - return; - } - } - let is_comparing_arrays = is_array(cx, left) || is_array(cx, right); - let (lint, msg) = get_lint_and_message( - is_named_constant(cx, left) || is_named_constant(cx, right), - is_comparing_arrays, - ); - span_lint_and_then(cx, lint, expr.span, msg, |diag| { - let lhs = Sugg::hir(cx, left, ".."); - let rhs = Sugg::hir(cx, right, ".."); - - if !is_comparing_arrays { - diag.span_suggestion( - expr.span, - "consider comparing them within some margin of error", - format!( - "({}).abs() {} error_margin", - lhs - rhs, - if op == BinOpKind::Eq { '<' } else { '>' } - ), - Applicability::HasPlaceholders, // snippet - ); - } - diag.note("`f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`"); - }); - } else if op == BinOpKind::Rem { - if is_integer_const(cx, right, 1) { - span_lint(cx, MODULO_ONE, expr.span, "any number modulo 1 will be 0"); - } - - if let ty::Int(ity) = cx.typeck_results().expr_ty(right).kind() { - if is_integer_const(cx, right, unsext(cx.tcx, -1, *ity)) { - span_lint( - cx, - MODULO_ONE, - expr.span, - "any number modulo -1 will panic/overflow or result in 0", - ); - } - }; - } -} diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs deleted file mode 100644 index 5bc45c87874b..000000000000 --- a/clippy_lints/src/misc_early.rs +++ /dev/null @@ -1,568 +0,0 @@ -use crate::utils::{constants, snippet_opt, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then}; -use rustc_ast::ast::{ - BindingMode, Expr, ExprKind, GenericParamKind, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability, - NodeId, Pat, PatKind, UnOp, -}; -use rustc_ast::visit::FnKind; -use rustc_data_structures::fx::FxHashMap; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for structure field patterns bound to wildcards. - /// - /// **Why is this bad?** Using `..` instead is shorter and leaves the focus on - /// the fields that are actually bound. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # struct Foo { - /// # a: i32, - /// # b: i32, - /// # c: i32, - /// # } - /// let f = Foo { a: 0, b: 0, c: 0 }; - /// - /// // Bad - /// match f { - /// Foo { a: _, b: 0, .. } => {}, - /// Foo { a: _, b: _, c: _ } => {}, - /// } - /// - /// // Good - /// match f { - /// Foo { b: 0, .. } => {}, - /// Foo { .. } => {}, - /// } - /// ``` - pub UNNEEDED_FIELD_PATTERN, - restriction, - "struct fields bound to a wildcard instead of using `..`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for function arguments having the similar names - /// differing by an underscore. - /// - /// **Why is this bad?** It affects code readability. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// // Bad - /// fn foo(a: i32, _a: i32) {} - /// - /// // Good - /// fn bar(a: i32, _b: i32) {} - /// ``` - pub DUPLICATE_UNDERSCORE_ARGUMENT, - style, - "function arguments having names which only differ by an underscore" -} - -declare_clippy_lint! { - /// **What it does:** Detects expressions of the form `--x`. - /// - /// **Why is this bad?** It can mislead C/C++ programmers to think `x` was - /// decremented. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let mut x = 3; - /// --x; - /// ``` - pub DOUBLE_NEG, - style, - "`--x`, which is a double negation of `x` and not a pre-decrement as in C/C++" -} - -declare_clippy_lint! { - /// **What it does:** Warns on hexadecimal literals with mixed-case letter - /// digits. - /// - /// **Why is this bad?** It looks confusing. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// // Bad - /// let y = 0x1a9BAcD; - /// - /// // Good - /// let y = 0x1A9BACD; - /// ``` - pub MIXED_CASE_HEX_LITERALS, - style, - "hex literals whose letter digits are not consistently upper- or lowercased" -} - -declare_clippy_lint! { - /// **What it does:** Warns if literal suffixes are not separated by an - /// underscore. - /// - /// **Why is this bad?** It is much less readable. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// // Bad - /// let y = 123832i32; - /// - /// // Good - /// let y = 123832_i32; - /// ``` - pub UNSEPARATED_LITERAL_SUFFIX, - pedantic, - "literals whose suffix is not separated by an underscore" -} - -declare_clippy_lint! { - /// **What it does:** Warns if an integral constant literal starts with `0`. - /// - /// **Why is this bad?** In some languages (including the infamous C language - /// and most of its - /// family), this marks an octal constant. In Rust however, this is a decimal - /// constant. This could - /// be confusing for both the writer and a reader of the constant. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// In Rust: - /// ```rust - /// fn main() { - /// let a = 0123; - /// println!("{}", a); - /// } - /// ``` - /// - /// prints `123`, while in C: - /// - /// ```c - /// #include - /// - /// int main() { - /// int a = 0123; - /// printf("%d\n", a); - /// } - /// ``` - /// - /// prints `83` (as `83 == 0o123` while `123 == 0o173`). - pub ZERO_PREFIXED_LITERAL, - complexity, - "integer literals starting with `0`" -} - -declare_clippy_lint! { - /// **What it does:** Warns if a generic shadows a built-in type. - /// - /// **Why is this bad?** This gives surprising type errors. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```ignore - /// impl Foo { - /// fn impl_func(&self) -> u32 { - /// 42 - /// } - /// } - /// ``` - pub BUILTIN_TYPE_SHADOW, - style, - "shadowing a builtin type" -} - -declare_clippy_lint! { - /// **What it does:** Checks for patterns in the form `name @ _`. - /// - /// **Why is this bad?** It's almost always more readable to just use direct - /// bindings. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let v = Some("abc"); - /// - /// // Bad - /// match v { - /// Some(x) => (), - /// y @ _ => (), - /// } - /// - /// // Good - /// match v { - /// Some(x) => (), - /// y => (), - /// } - /// ``` - pub REDUNDANT_PATTERN, - style, - "using `name @ _` in a pattern" -} - -declare_clippy_lint! { - /// **What it does:** Checks for tuple patterns with a wildcard - /// pattern (`_`) is next to a rest pattern (`..`). - /// - /// _NOTE_: While `_, ..` means there is at least one element left, `..` - /// means there are 0 or more elements left. This can make a difference - /// when refactoring, but shouldn't result in errors in the refactored code, - /// since the wildcard pattern isn't used anyway. - /// **Why is this bad?** The wildcard pattern is unneeded as the rest pattern - /// can match that element as well. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # struct TupleStruct(u32, u32, u32); - /// # let t = TupleStruct(1, 2, 3); - /// // Bad - /// match t { - /// TupleStruct(0, .., _) => (), - /// _ => (), - /// } - /// - /// // Good - /// match t { - /// TupleStruct(0, ..) => (), - /// _ => (), - /// } - /// ``` - pub UNNEEDED_WILDCARD_PATTERN, - complexity, - "tuple patterns with a wildcard pattern (`_`) is next to a rest pattern (`..`)" -} - -declare_lint_pass!(MiscEarlyLints => [ - UNNEEDED_FIELD_PATTERN, - DUPLICATE_UNDERSCORE_ARGUMENT, - DOUBLE_NEG, - MIXED_CASE_HEX_LITERALS, - UNSEPARATED_LITERAL_SUFFIX, - ZERO_PREFIXED_LITERAL, - BUILTIN_TYPE_SHADOW, - REDUNDANT_PATTERN, - UNNEEDED_WILDCARD_PATTERN, -]); - -impl EarlyLintPass for MiscEarlyLints { - fn check_generics(&mut self, cx: &EarlyContext<'_>, gen: &Generics) { - for param in &gen.params { - if let GenericParamKind::Type { .. } = param.kind { - let name = param.ident.as_str(); - if constants::BUILTIN_TYPES.contains(&&*name) { - span_lint( - cx, - BUILTIN_TYPE_SHADOW, - param.ident.span, - &format!("this generic shadows the built-in type `{}`", name), - ); - } - } - } - } - - fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &Pat) { - if let PatKind::Struct(ref npat, ref pfields, _) = pat.kind { - let mut wilds = 0; - let type_name = npat - .segments - .last() - .expect("A path must have at least one segment") - .ident - .name; - - for field in pfields { - if let PatKind::Wild = field.pat.kind { - wilds += 1; - } - } - if !pfields.is_empty() && wilds == pfields.len() { - span_lint_and_help( - cx, - UNNEEDED_FIELD_PATTERN, - pat.span, - "all the struct fields are matched to a wildcard pattern, consider using `..`", - None, - &format!("try with `{} {{ .. }}` instead", type_name), - ); - return; - } - if wilds > 0 { - for field in pfields { - if let PatKind::Wild = field.pat.kind { - wilds -= 1; - if wilds > 0 { - span_lint( - cx, - UNNEEDED_FIELD_PATTERN, - field.span, - "you matched a field with a wildcard pattern, consider using `..` instead", - ); - } else { - let mut normal = vec![]; - - for field in pfields { - match field.pat.kind { - PatKind::Wild => {}, - _ => { - if let Ok(n) = cx.sess().source_map().span_to_snippet(field.span) { - normal.push(n); - } - }, - } - } - - span_lint_and_help( - cx, - UNNEEDED_FIELD_PATTERN, - field.span, - "you matched a field with a wildcard pattern, consider using `..` \ - instead", - None, - &format!("try with `{} {{ {}, .. }}`", type_name, normal[..].join(", ")), - ); - } - } - } - } - } - - if let PatKind::Ident(left, ident, Some(ref right)) = pat.kind { - let left_binding = match left { - BindingMode::ByRef(Mutability::Mut) => "ref mut ", - BindingMode::ByRef(Mutability::Not) => "ref ", - BindingMode::ByValue(..) => "", - }; - - if let PatKind::Wild = right.kind { - span_lint_and_sugg( - cx, - REDUNDANT_PATTERN, - pat.span, - &format!( - "the `{} @ _` pattern can be written as just `{}`", - ident.name, ident.name, - ), - "try", - format!("{}{}", left_binding, ident.name), - Applicability::MachineApplicable, - ); - } - } - - check_unneeded_wildcard_pattern(cx, pat); - } - - fn check_fn(&mut self, cx: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: Span, _: NodeId) { - let mut registered_names: FxHashMap = FxHashMap::default(); - - for arg in &fn_kind.decl().inputs { - if let PatKind::Ident(_, ident, None) = arg.pat.kind { - let arg_name = ident.to_string(); - - if let Some(arg_name) = arg_name.strip_prefix('_') { - if let Some(correspondence) = registered_names.get(arg_name) { - span_lint( - cx, - DUPLICATE_UNDERSCORE_ARGUMENT, - *correspondence, - &format!( - "`{}` already exists, having another argument having almost the same \ - name makes code comprehension and documentation more difficult", - arg_name - ), - ); - } - } else { - registered_names.insert(arg_name, arg.pat.span); - } - } - } - } - - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - if in_external_macro(cx.sess(), expr.span) { - return; - } - match expr.kind { - ExprKind::Unary(UnOp::Neg, ref inner) => { - if let ExprKind::Unary(UnOp::Neg, _) = inner.kind { - span_lint( - cx, - DOUBLE_NEG, - expr.span, - "`--x` could be misinterpreted as pre-decrement by C programmers, is usually a no-op", - ); - } - }, - ExprKind::Lit(ref lit) => Self::check_lit(cx, lit), - _ => (), - } - } -} - -impl MiscEarlyLints { - fn check_lit(cx: &EarlyContext<'_>, lit: &Lit) { - // We test if first character in snippet is a number, because the snippet could be an expansion - // from a built-in macro like `line!()` or a proc-macro like `#[wasm_bindgen]`. - // Note that this check also covers special case that `line!()` is eagerly expanded by compiler. - // See for a regression. - // FIXME: Find a better way to detect those cases. - let lit_snip = match snippet_opt(cx, lit.span) { - Some(snip) if snip.chars().next().map_or(false, |c| c.is_digit(10)) => snip, - _ => return, - }; - - if let LitKind::Int(value, lit_int_type) = lit.kind { - let suffix = match lit_int_type { - LitIntType::Signed(ty) => ty.name_str(), - LitIntType::Unsigned(ty) => ty.name_str(), - LitIntType::Unsuffixed => "", - }; - - let maybe_last_sep_idx = if let Some(val) = lit_snip.len().checked_sub(suffix.len() + 1) { - val - } else { - return; // It's useless so shouldn't lint. - }; - // Do not lint when literal is unsuffixed. - if !suffix.is_empty() && lit_snip.as_bytes()[maybe_last_sep_idx] != b'_' { - span_lint_and_sugg( - cx, - UNSEPARATED_LITERAL_SUFFIX, - lit.span, - "integer type suffix should be separated by an underscore", - "add an underscore", - format!("{}_{}", &lit_snip[..=maybe_last_sep_idx], suffix), - Applicability::MachineApplicable, - ); - } - - if lit_snip.starts_with("0x") { - if maybe_last_sep_idx <= 2 { - // It's meaningless or causes range error. - return; - } - let mut seen = (false, false); - for ch in lit_snip.as_bytes()[2..=maybe_last_sep_idx].iter() { - match ch { - b'a'..=b'f' => seen.0 = true, - b'A'..=b'F' => seen.1 = true, - _ => {}, - } - if seen.0 && seen.1 { - span_lint( - cx, - MIXED_CASE_HEX_LITERALS, - lit.span, - "inconsistent casing in hexadecimal literal", - ); - break; - } - } - } else if lit_snip.starts_with("0b") || lit_snip.starts_with("0o") { - /* nothing to do */ - } else if value != 0 && lit_snip.starts_with('0') { - span_lint_and_then( - cx, - ZERO_PREFIXED_LITERAL, - lit.span, - "this is a decimal constant", - |diag| { - diag.span_suggestion( - lit.span, - "if you mean to use a decimal constant, remove the `0` to avoid confusion", - lit_snip.trim_start_matches(|c| c == '_' || c == '0').to_string(), - Applicability::MaybeIncorrect, - ); - diag.span_suggestion( - lit.span, - "if you mean to use an octal constant, use `0o`", - format!("0o{}", lit_snip.trim_start_matches(|c| c == '_' || c == '0')), - Applicability::MaybeIncorrect, - ); - }, - ); - } - } else if let LitKind::Float(_, LitFloatType::Suffixed(float_ty)) = lit.kind { - let suffix = float_ty.name_str(); - let maybe_last_sep_idx = if let Some(val) = lit_snip.len().checked_sub(suffix.len() + 1) { - val - } else { - return; // It's useless so shouldn't lint. - }; - if lit_snip.as_bytes()[maybe_last_sep_idx] != b'_' { - span_lint_and_sugg( - cx, - UNSEPARATED_LITERAL_SUFFIX, - lit.span, - "float type suffix should be separated by an underscore", - "add an underscore", - format!("{}_{}", &lit_snip[..=maybe_last_sep_idx], suffix), - Applicability::MachineApplicable, - ); - } - } - } -} - -fn check_unneeded_wildcard_pattern(cx: &EarlyContext<'_>, pat: &Pat) { - if let PatKind::TupleStruct(_, ref patterns) | PatKind::Tuple(ref patterns) = pat.kind { - fn span_lint(cx: &EarlyContext<'_>, span: Span, only_one: bool) { - span_lint_and_sugg( - cx, - UNNEEDED_WILDCARD_PATTERN, - span, - if only_one { - "this pattern is unneeded as the `..` pattern can match that element" - } else { - "these patterns are unneeded as the `..` pattern can match those elements" - }, - if only_one { "remove it" } else { "remove them" }, - "".to_string(), - Applicability::MachineApplicable, - ); - } - - if let Some(rest_index) = patterns.iter().position(|pat| pat.is_rest()) { - if let Some((left_index, left_pat)) = patterns[..rest_index] - .iter() - .rev() - .take_while(|pat| matches!(pat.kind, PatKind::Wild)) - .enumerate() - .last() - { - span_lint(cx, left_pat.span.until(patterns[rest_index].span), left_index == 0); - } - - if let Some((right_index, right_pat)) = patterns[rest_index + 1..] - .iter() - .take_while(|pat| matches!(pat.kind, PatKind::Wild)) - .enumerate() - .last() - { - span_lint( - cx, - patterns[rest_index].span.shrink_to_hi().to(right_pat.span), - right_index == 0, - ); - } - } - } -} diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs deleted file mode 100644 index 6ebeaced62a3..000000000000 --- a/clippy_lints/src/missing_const_for_fn.rs +++ /dev/null @@ -1,166 +0,0 @@ -use crate::utils::qualify_min_const_fn::is_min_const_fn; -use crate::utils::{ - fn_has_unsatisfiable_preds, has_drop, is_entrypoint_fn, meets_msrv, span_lint, trait_ref_of_method, -}; -use rustc_hir as hir; -use rustc_hir::intravisit::FnKind; -use rustc_hir::{Body, Constness, FnDecl, GenericParamKind, HirId}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_semver::RustcVersion; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::Span; -use rustc_typeck::hir_ty_to_ty; - -const MISSING_CONST_FOR_FN_MSRV: RustcVersion = RustcVersion::new(1, 37, 0); - -declare_clippy_lint! { - /// **What it does:** - /// - /// Suggests the use of `const` in functions and methods where possible. - /// - /// **Why is this bad?** - /// - /// Not having the function const prevents callers of the function from being const as well. - /// - /// **Known problems:** - /// - /// Const functions are currently still being worked on, with some features only being available - /// on nightly. This lint does not consider all edge cases currently and the suggestions may be - /// incorrect if you are using this lint on stable. - /// - /// Also, the lint only runs one pass over the code. Consider these two non-const functions: - /// - /// ```rust - /// fn a() -> i32 { - /// 0 - /// } - /// fn b() -> i32 { - /// a() - /// } - /// ``` - /// - /// When running Clippy, the lint will only suggest to make `a` const, because `b` at this time - /// can't be const as it calls a non-const function. Making `a` const and running Clippy again, - /// will suggest to make `b` const, too. - /// - /// **Example:** - /// - /// ```rust - /// # struct Foo { - /// # random_number: usize, - /// # } - /// # impl Foo { - /// fn new() -> Self { - /// Self { random_number: 42 } - /// } - /// # } - /// ``` - /// - /// Could be a const fn: - /// - /// ```rust - /// # struct Foo { - /// # random_number: usize, - /// # } - /// # impl Foo { - /// const fn new() -> Self { - /// Self { random_number: 42 } - /// } - /// # } - /// ``` - pub MISSING_CONST_FOR_FN, - nursery, - "Lint functions definitions that could be made `const fn`" -} - -impl_lint_pass!(MissingConstForFn => [MISSING_CONST_FOR_FN]); - -pub struct MissingConstForFn { - msrv: Option, -} - -impl MissingConstForFn { - #[must_use] - pub fn new(msrv: Option) -> Self { - Self { msrv } - } -} - -impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { - fn check_fn( - &mut self, - cx: &LateContext<'_>, - kind: FnKind<'_>, - _: &FnDecl<'_>, - _: &Body<'_>, - span: Span, - hir_id: HirId, - ) { - if !meets_msrv(self.msrv.as_ref(), &MISSING_CONST_FOR_FN_MSRV) { - return; - } - - let def_id = cx.tcx.hir().local_def_id(hir_id); - - if in_external_macro(cx.tcx.sess, span) || is_entrypoint_fn(cx, def_id.to_def_id()) { - return; - } - - // Building MIR for `fn`s with unsatisfiable preds results in ICE. - if fn_has_unsatisfiable_preds(cx, def_id.to_def_id()) { - return; - } - - // Perform some preliminary checks that rule out constness on the Clippy side. This way we - // can skip the actual const check and return early. - match kind { - FnKind::ItemFn(_, generics, header, ..) => { - let has_const_generic_params = generics - .params - .iter() - .any(|param| matches!(param.kind, GenericParamKind::Const { .. })); - - if already_const(header) || has_const_generic_params { - return; - } - }, - FnKind::Method(_, sig, ..) => { - if trait_ref_of_method(cx, hir_id).is_some() - || already_const(sig.header) - || method_accepts_dropable(cx, sig.decl.inputs) - { - return; - } - }, - FnKind::Closure(..) => return, - } - - let mir = cx.tcx.optimized_mir(def_id); - - if let Err((span, err)) = is_min_const_fn(cx.tcx, &mir) { - if rustc_mir::const_eval::is_min_const_fn(cx.tcx, def_id.to_def_id()) { - cx.tcx.sess.span_err(span, &err); - } - } else { - span_lint(cx, MISSING_CONST_FOR_FN, span, "this could be a `const fn`"); - } - } - extract_msrv_attr!(LateContext); -} - -/// Returns true if any of the method parameters is a type that implements `Drop`. The method -/// can't be made const then, because `drop` can't be const-evaluated. -fn method_accepts_dropable(cx: &LateContext<'_>, param_tys: &[hir::Ty<'_>]) -> bool { - // If any of the params are droppable, return true - param_tys.iter().any(|hir_ty| { - let ty_ty = hir_ty_to_ty(cx.tcx, hir_ty); - has_drop(cx, ty_ty) - }) -} - -// We don't have to lint on something that's already `const` -#[must_use] -fn already_const(header: hir::FnHeader) -> bool { - header.constness == Constness::Const -} diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs deleted file mode 100644 index 27f1074a0dd8..000000000000 --- a/clippy_lints/src/missing_doc.rs +++ /dev/null @@ -1,200 +0,0 @@ -// Note: More specifically this lint is largely inspired (aka copied) from -// *rustc*'s -// [`missing_doc`]. -// -// [`missing_doc`]: https://github.com/rust-lang/rust/blob/cf9cf7c923eb01146971429044f216a3ca905e06/compiler/rustc_lint/src/builtin.rs#L415 -// - -use crate::utils::span_lint; -use if_chain::if_chain; -use rustc_ast::ast::{self, MetaItem, MetaItemKind}; -use rustc_ast::attr; -use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::ty; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** Warns if there is missing doc for any documentable item - /// (public or private). - /// - /// **Why is this bad?** Doc is good. *rustc* has a `MISSING_DOCS` - /// allowed-by-default lint for - /// public members, but has no way to enforce documentation of private items. - /// This lint fixes that. - /// - /// **Known problems:** None. - pub MISSING_DOCS_IN_PRIVATE_ITEMS, - restriction, - "detects missing documentation for public and private members" -} - -pub struct MissingDoc { - /// Stack of whether #[doc(hidden)] is set - /// at each level which has lint attributes. - doc_hidden_stack: Vec, -} - -impl Default for MissingDoc { - #[must_use] - fn default() -> Self { - Self::new() - } -} - -impl MissingDoc { - #[must_use] - pub fn new() -> Self { - Self { - doc_hidden_stack: vec![false], - } - } - - fn doc_hidden(&self) -> bool { - *self.doc_hidden_stack.last().expect("empty doc_hidden_stack") - } - - fn has_include(meta: Option) -> bool { - if_chain! { - if let Some(meta) = meta; - if let MetaItemKind::List(list) = meta.kind; - if let Some(meta) = list.get(0); - if let Some(name) = meta.ident(); - then { - name.as_str() == "include" - } else { - false - } - } - } - - fn check_missing_docs_attrs( - &self, - cx: &LateContext<'_>, - attrs: &[ast::Attribute], - sp: Span, - article: &'static str, - desc: &'static str, - ) { - // If we're building a test harness, then warning about - // documentation is probably not really relevant right now. - if cx.sess().opts.test { - return; - } - - // `#[doc(hidden)]` disables missing_docs check. - if self.doc_hidden() { - return; - } - - if sp.from_expansion() { - return; - } - - let has_doc = attrs - .iter() - .any(|a| a.is_doc_comment() || a.doc_str().is_some() || a.is_value_str() || Self::has_include(a.meta())); - if !has_doc { - span_lint( - cx, - MISSING_DOCS_IN_PRIVATE_ITEMS, - sp, - &format!("missing documentation for {} {}", article, desc), - ); - } - } -} - -impl_lint_pass!(MissingDoc => [MISSING_DOCS_IN_PRIVATE_ITEMS]); - -impl<'tcx> LateLintPass<'tcx> for MissingDoc { - fn enter_lint_attrs(&mut self, _: &LateContext<'tcx>, attrs: &'tcx [ast::Attribute]) { - let doc_hidden = self.doc_hidden() - || attrs.iter().any(|attr| { - attr.has_name(sym::doc) - && match attr.meta_item_list() { - None => false, - Some(l) => attr::list_contains_name(&l[..], sym::hidden), - } - }); - self.doc_hidden_stack.push(doc_hidden); - } - - fn exit_lint_attrs(&mut self, _: &LateContext<'tcx>, _: &'tcx [ast::Attribute]) { - self.doc_hidden_stack.pop().expect("empty doc_hidden_stack"); - } - - fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) { - self.check_missing_docs_attrs(cx, &krate.item.attrs, krate.item.span, "the", "crate"); - } - - fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) { - match it.kind { - hir::ItemKind::Fn(..) => { - // ignore main() - if it.ident.name == sym::main { - let def_id = it.hir_id.owner; - let def_key = cx.tcx.hir().def_key(def_id); - if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) { - return; - } - } - }, - hir::ItemKind::Const(..) - | hir::ItemKind::Enum(..) - | hir::ItemKind::Mod(..) - | hir::ItemKind::Static(..) - | hir::ItemKind::Struct(..) - | hir::ItemKind::Trait(..) - | hir::ItemKind::TraitAlias(..) - | hir::ItemKind::TyAlias(..) - | hir::ItemKind::Union(..) - | hir::ItemKind::OpaqueTy(..) => {}, - hir::ItemKind::ExternCrate(..) - | hir::ItemKind::ForeignMod { .. } - | hir::ItemKind::GlobalAsm(..) - | hir::ItemKind::Impl { .. } - | hir::ItemKind::Use(..) => return, - }; - - let def_id = cx.tcx.hir().local_def_id(it.hir_id); - let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id()); - - self.check_missing_docs_attrs(cx, &it.attrs, it.span, article, desc); - } - - fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) { - let def_id = cx.tcx.hir().local_def_id(trait_item.hir_id); - let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id()); - - self.check_missing_docs_attrs(cx, &trait_item.attrs, trait_item.span, article, desc); - } - - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { - // If the method is an impl for a trait, don't doc. - let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); - match cx.tcx.associated_item(def_id).container { - ty::TraitContainer(_) => return, - ty::ImplContainer(cid) => { - if cx.tcx.impl_trait_ref(cid).is_some() { - return; - } - }, - } - - let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id()); - self.check_missing_docs_attrs(cx, &impl_item.attrs, impl_item.span, article, desc); - } - - fn check_struct_field(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::StructField<'_>) { - if !sf.is_positional() { - self.check_missing_docs_attrs(cx, &sf.attrs, sf.span, "a", "struct field"); - } - } - - fn check_variant(&mut self, cx: &LateContext<'tcx>, v: &'tcx hir::Variant<'_>) { - self.check_missing_docs_attrs(cx, &v.attrs, v.span, "a", "variant"); - } -} diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs deleted file mode 100644 index 913d9daff46f..000000000000 --- a/clippy_lints/src/missing_inline.rs +++ /dev/null @@ -1,166 +0,0 @@ -use crate::utils::span_lint; -use rustc_ast::ast; -use rustc_hir as hir; -use rustc_lint::{self, LateContext, LateLintPass, LintContext}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** it lints if an exported function, method, trait method with default impl, - /// or trait method impl is not `#[inline]`. - /// - /// **Why is this bad?** In general, it is not. Functions can be inlined across - /// crates when that's profitable as long as any form of LTO is used. When LTO is disabled, - /// functions that are not `#[inline]` cannot be inlined across crates. Certain types of crates - /// might intend for most of the methods in their public API to be able to be inlined across - /// crates even when LTO is disabled. For these types of crates, enabling this lint might make - /// sense. It allows the crate to require all exported methods to be `#[inline]` by default, and - /// then opt out for specific methods where this might not make sense. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// pub fn foo() {} // missing #[inline] - /// fn ok() {} // ok - /// #[inline] pub fn bar() {} // ok - /// #[inline(always)] pub fn baz() {} // ok - /// - /// pub trait Bar { - /// fn bar(); // ok - /// fn def_bar() {} // missing #[inline] - /// } - /// - /// struct Baz; - /// impl Baz { - /// fn private() {} // ok - /// } - /// - /// impl Bar for Baz { - /// fn bar() {} // ok - Baz is not exported - /// } - /// - /// pub struct PubBaz; - /// impl PubBaz { - /// fn private() {} // ok - /// pub fn not_ptrivate() {} // missing #[inline] - /// } - /// - /// impl Bar for PubBaz { - /// fn bar() {} // missing #[inline] - /// fn def_bar() {} // missing #[inline] - /// } - /// ``` - pub MISSING_INLINE_IN_PUBLIC_ITEMS, - restriction, - "detects missing `#[inline]` attribute for public callables (functions, trait methods, methods...)" -} - -fn check_missing_inline_attrs(cx: &LateContext<'_>, attrs: &[ast::Attribute], sp: Span, desc: &'static str) { - let has_inline = attrs.iter().any(|a| a.has_name(sym::inline)); - if !has_inline { - span_lint( - cx, - MISSING_INLINE_IN_PUBLIC_ITEMS, - sp, - &format!("missing `#[inline]` for {}", desc), - ); - } -} - -fn is_executable(cx: &LateContext<'_>) -> bool { - use rustc_session::config::CrateType; - - cx.tcx - .sess - .crate_types() - .iter() - .any(|t: &CrateType| matches!(t, CrateType::Executable)) -} - -declare_lint_pass!(MissingInline => [MISSING_INLINE_IN_PUBLIC_ITEMS]); - -impl<'tcx> LateLintPass<'tcx> for MissingInline { - fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) { - if rustc_middle::lint::in_external_macro(cx.sess(), it.span) || is_executable(cx) { - return; - } - - if !cx.access_levels.is_exported(it.hir_id) { - return; - } - match it.kind { - hir::ItemKind::Fn(..) => { - let desc = "a function"; - check_missing_inline_attrs(cx, &it.attrs, it.span, desc); - }, - hir::ItemKind::Trait(ref _is_auto, ref _unsafe, ref _generics, ref _bounds, trait_items) => { - // note: we need to check if the trait is exported so we can't use - // `LateLintPass::check_trait_item` here. - for tit in trait_items { - let tit_ = cx.tcx.hir().trait_item(tit.id); - match tit_.kind { - hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => {}, - hir::TraitItemKind::Fn(..) => { - if tit.defaultness.has_value() { - // trait method with default body needs inline in case - // an impl is not provided - let desc = "a default trait method"; - let item = cx.tcx.hir().expect_trait_item(tit.id.hir_id); - check_missing_inline_attrs(cx, &item.attrs, item.span, desc); - } - }, - } - } - }, - hir::ItemKind::Const(..) - | hir::ItemKind::Enum(..) - | hir::ItemKind::Mod(..) - | hir::ItemKind::Static(..) - | hir::ItemKind::Struct(..) - | hir::ItemKind::TraitAlias(..) - | hir::ItemKind::GlobalAsm(..) - | hir::ItemKind::TyAlias(..) - | hir::ItemKind::Union(..) - | hir::ItemKind::OpaqueTy(..) - | hir::ItemKind::ExternCrate(..) - | hir::ItemKind::ForeignMod { .. } - | hir::ItemKind::Impl { .. } - | hir::ItemKind::Use(..) => {}, - }; - } - - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { - use rustc_middle::ty::{ImplContainer, TraitContainer}; - if rustc_middle::lint::in_external_macro(cx.sess(), impl_item.span) || is_executable(cx) { - return; - } - - // If the item being implemented is not exported, then we don't need #[inline] - if !cx.access_levels.is_exported(impl_item.hir_id) { - return; - } - - let desc = match impl_item.kind { - hir::ImplItemKind::Fn(..) => "a method", - hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) => return, - }; - - let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); - let trait_def_id = match cx.tcx.associated_item(def_id).container { - TraitContainer(cid) => Some(cid), - ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id), - }; - - if let Some(trait_def_id) = trait_def_id { - if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.hir_id) { - // If a trait is being implemented for an item, and the - // trait is not exported, we don't need #[inline] - return; - } - } - - check_missing_inline_attrs(cx, &impl_item.attrs, impl_item.span, desc); - } -} diff --git a/clippy_lints/src/modulo_arithmetic.rs b/clippy_lints/src/modulo_arithmetic.rs deleted file mode 100644 index da3ae1d652f6..000000000000 --- a/clippy_lints/src/modulo_arithmetic.rs +++ /dev/null @@ -1,148 +0,0 @@ -use crate::consts::{constant, Constant}; -use crate::utils::{sext, span_lint_and_then}; -use if_chain::if_chain; -use rustc_hir::{BinOpKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use std::fmt::Display; - -declare_clippy_lint! { - /// **What it does:** Checks for modulo arithmetic. - /// - /// **Why is this bad?** The results of modulo (%) operation might differ - /// depending on the language, when negative numbers are involved. - /// If you interop with different languages it might be beneficial - /// to double check all places that use modulo arithmetic. - /// - /// For example, in Rust `17 % -3 = 2`, but in Python `17 % -3 = -1`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let x = -17 % 3; - /// ``` - pub MODULO_ARITHMETIC, - restriction, - "any modulo arithmetic statement" -} - -declare_lint_pass!(ModuloArithmetic => [MODULO_ARITHMETIC]); - -struct OperandInfo { - string_representation: Option, - is_negative: bool, - is_integral: bool, -} - -fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { - match constant(cx, cx.typeck_results(), operand) { - Some((Constant::Int(v), _)) => match *cx.typeck_results().expr_ty(expr).kind() { - ty::Int(ity) => { - let value = sext(cx.tcx, v, ity); - return Some(OperandInfo { - string_representation: Some(value.to_string()), - is_negative: value < 0, - is_integral: true, - }); - }, - ty::Uint(_) => { - return Some(OperandInfo { - string_representation: None, - is_negative: false, - is_integral: true, - }); - }, - _ => {}, - }, - Some((Constant::F32(f), _)) => { - return Some(floating_point_operand_info(&f)); - }, - Some((Constant::F64(f), _)) => { - return Some(floating_point_operand_info(&f)); - }, - _ => {}, - } - None -} - -fn floating_point_operand_info>(f: &T) -> OperandInfo { - OperandInfo { - string_representation: Some(format!("{:.3}", *f)), - is_negative: *f < 0.0.into(), - is_integral: false, - } -} - -fn might_have_negative_value(t: &ty::TyS<'_>) -> bool { - t.is_signed() || t.is_floating_point() -} - -fn check_const_operands<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx Expr<'_>, - lhs_operand: &OperandInfo, - rhs_operand: &OperandInfo, -) { - if lhs_operand.is_negative ^ rhs_operand.is_negative { - span_lint_and_then( - cx, - MODULO_ARITHMETIC, - expr.span, - &format!( - "you are using modulo operator on constants with different signs: `{} % {}`", - lhs_operand.string_representation.as_ref().unwrap(), - rhs_operand.string_representation.as_ref().unwrap() - ), - |diag| { - diag.note("double check for expected result especially when interoperating with different languages"); - if lhs_operand.is_integral { - diag.note("or consider using `rem_euclid` or similar function"); - } - }, - ); - } -} - -fn check_non_const_operands<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, operand: &Expr<'_>) { - let operand_type = cx.typeck_results().expr_ty(operand); - if might_have_negative_value(operand_type) { - span_lint_and_then( - cx, - MODULO_ARITHMETIC, - expr.span, - "you are using modulo operator on types that might have different signs", - |diag| { - diag.note("double check for expected result especially when interoperating with different languages"); - if operand_type.is_integral() { - diag.note("or consider using `rem_euclid` or similar function"); - } - }, - ); - } -} - -impl<'tcx> LateLintPass<'tcx> for ModuloArithmetic { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - match &expr.kind { - ExprKind::Binary(op, lhs, rhs) | ExprKind::AssignOp(op, lhs, rhs) => { - if let BinOpKind::Rem = op.node { - let lhs_operand = analyze_operand(lhs, cx, expr); - let rhs_operand = analyze_operand(rhs, cx, expr); - if_chain! { - if let Some(lhs_operand) = lhs_operand; - if let Some(rhs_operand) = rhs_operand; - then { - check_const_operands(cx, expr, &lhs_operand, &rhs_operand); - } - else { - check_non_const_operands(cx, expr, lhs); - } - } - }; - }, - _ => {}, - } - } -} diff --git a/clippy_lints/src/multiple_crate_versions.rs b/clippy_lints/src/multiple_crate_versions.rs deleted file mode 100644 index c1773cef7a8b..000000000000 --- a/clippy_lints/src/multiple_crate_versions.rs +++ /dev/null @@ -1,96 +0,0 @@ -//! lint on multiple versions of a crate being used - -use crate::utils::{run_lints, span_lint}; -use rustc_hir::def_id::LOCAL_CRATE; -use rustc_hir::{Crate, CRATE_HIR_ID}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::DUMMY_SP; - -use cargo_metadata::{DependencyKind, Node, Package, PackageId}; -use if_chain::if_chain; -use itertools::Itertools; - -declare_clippy_lint! { - /// **What it does:** Checks to see if multiple versions of a crate are being - /// used. - /// - /// **Why is this bad?** This bloats the size of targets, and can lead to - /// confusing error messages when structs or traits are used interchangeably - /// between different versions of a crate. - /// - /// **Known problems:** Because this can be caused purely by the dependencies - /// themselves, it's not always possible to fix this issue. - /// - /// **Example:** - /// ```toml - /// # This will pull in both winapi v0.3.x and v0.2.x, triggering a warning. - /// [dependencies] - /// ctrlc = "=3.1.0" - /// ansi_term = "=0.11.0" - /// ``` - pub MULTIPLE_CRATE_VERSIONS, - cargo, - "multiple versions of the same crate being used" -} - -declare_lint_pass!(MultipleCrateVersions => [MULTIPLE_CRATE_VERSIONS]); - -impl LateLintPass<'_> for MultipleCrateVersions { - fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { - if !run_lints(cx, &[MULTIPLE_CRATE_VERSIONS], CRATE_HIR_ID) { - return; - } - - let metadata = unwrap_cargo_metadata!(cx, MULTIPLE_CRATE_VERSIONS, true); - let local_name = cx.tcx.crate_name(LOCAL_CRATE).as_str(); - let mut packages = metadata.packages; - packages.sort_by(|a, b| a.name.cmp(&b.name)); - - if_chain! { - if let Some(resolve) = &metadata.resolve; - if let Some(local_id) = packages - .iter() - .find_map(|p| if p.name == *local_name { Some(&p.id) } else { None }); - then { - for (name, group) in &packages.iter().group_by(|p| p.name.clone()) { - let group: Vec<&Package> = group.collect(); - - if group.len() <= 1 { - continue; - } - - if group.iter().all(|p| is_normal_dep(&resolve.nodes, local_id, &p.id)) { - let mut versions: Vec<_> = group.into_iter().map(|p| &p.version).collect(); - versions.sort(); - let versions = versions.iter().join(", "); - - span_lint( - cx, - MULTIPLE_CRATE_VERSIONS, - DUMMY_SP, - &format!("multiple versions for dependency `{}`: {}", name, versions), - ); - } - } - } - } - } -} - -fn is_normal_dep(nodes: &[Node], local_id: &PackageId, dep_id: &PackageId) -> bool { - fn depends_on(node: &Node, dep_id: &PackageId) -> bool { - node.deps.iter().any(|dep| { - dep.pkg == *dep_id - && dep - .dep_kinds - .iter() - .any(|info| matches!(info.kind, DependencyKind::Normal)) - }) - } - - nodes - .iter() - .filter(|node| depends_on(node, dep_id)) - .any(|node| node.id == *local_id || is_normal_dep(nodes, local_id, &node.id)) -} diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs deleted file mode 100644 index 11044e0c2fb4..000000000000 --- a/clippy_lints/src/mut_key.rs +++ /dev/null @@ -1,127 +0,0 @@ -use crate::utils::{match_def_path, paths, span_lint, trait_ref_of_method}; -use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::TypeFoldable; -use rustc_middle::ty::{Adt, Array, RawPtr, Ref, Slice, Tuple, Ty, TypeAndMut}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for sets/maps with mutable key types. - /// - /// **Why is this bad?** All of `HashMap`, `HashSet`, `BTreeMap` and - /// `BtreeSet` rely on either the hash or the order of keys be unchanging, - /// so having types with interior mutability is a bad idea. - /// - /// **Known problems:** It's correct to use a struct, that contains interior mutability - /// as a key, when its `Hash` implementation doesn't access any of the interior mutable types. - /// However, this lint is unable to recognize this, so it causes a false positive in theses cases. - /// The `bytes` crate is a great example of this. - /// - /// **Example:** - /// ```rust - /// use std::cmp::{PartialEq, Eq}; - /// use std::collections::HashSet; - /// use std::hash::{Hash, Hasher}; - /// use std::sync::atomic::AtomicUsize; - ///# #[allow(unused)] - /// - /// struct Bad(AtomicUsize); - /// impl PartialEq for Bad { - /// fn eq(&self, rhs: &Self) -> bool { - /// .. - /// ; unimplemented!(); - /// } - /// } - /// - /// impl Eq for Bad {} - /// - /// impl Hash for Bad { - /// fn hash(&self, h: &mut H) { - /// .. - /// ; unimplemented!(); - /// } - /// } - /// - /// fn main() { - /// let _: HashSet = HashSet::new(); - /// } - /// ``` - pub MUTABLE_KEY_TYPE, - correctness, - "Check for mutable `Map`/`Set` key type" -} - -declare_lint_pass!(MutableKeyType => [ MUTABLE_KEY_TYPE ]); - -impl<'tcx> LateLintPass<'tcx> for MutableKeyType { - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) { - if let hir::ItemKind::Fn(ref sig, ..) = item.kind { - check_sig(cx, item.hir_id, &sig.decl); - } - } - - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'tcx>) { - if let hir::ImplItemKind::Fn(ref sig, ..) = item.kind { - if trait_ref_of_method(cx, item.hir_id).is_none() { - check_sig(cx, item.hir_id, &sig.decl); - } - } - } - - fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'tcx>) { - if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { - check_sig(cx, item.hir_id, &sig.decl); - } - } - - fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::Local<'_>) { - if let hir::PatKind::Wild = local.pat.kind { - return; - } - check_ty(cx, local.span, cx.typeck_results().pat_ty(&*local.pat)); - } -} - -fn check_sig<'tcx>(cx: &LateContext<'tcx>, item_hir_id: hir::HirId, decl: &hir::FnDecl<'_>) { - let fn_def_id = cx.tcx.hir().local_def_id(item_hir_id); - let fn_sig = cx.tcx.fn_sig(fn_def_id); - for (hir_ty, ty) in decl.inputs.iter().zip(fn_sig.inputs().skip_binder().iter()) { - check_ty(cx, hir_ty.span, ty); - } - check_ty(cx, decl.output.span(), cx.tcx.erase_late_bound_regions(fn_sig.output())); -} - -// We want to lint 1. sets or maps with 2. not immutable key types and 3. no unerased -// generics (because the compiler cannot ensure immutability for unknown types). -fn check_ty<'tcx>(cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) { - let ty = ty.peel_refs(); - if let Adt(def, substs) = ty.kind() { - if [&paths::HASHMAP, &paths::BTREEMAP, &paths::HASHSET, &paths::BTREESET] - .iter() - .any(|path| match_def_path(cx, def.did, &**path)) - && is_mutable_type(cx, substs.type_at(0), span) - { - span_lint(cx, MUTABLE_KEY_TYPE, span, "mutable key type"); - } - } -} - -fn is_mutable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span) -> bool { - match *ty.kind() { - RawPtr(TypeAndMut { ty: inner_ty, mutbl }) | Ref(_, inner_ty, mutbl) => { - mutbl == hir::Mutability::Mut || is_mutable_type(cx, inner_ty, span) - }, - Slice(inner_ty) => is_mutable_type(cx, inner_ty, span), - Array(inner_ty, size) => { - size.try_eval_usize(cx.tcx, cx.param_env).map_or(true, |u| u != 0) && is_mutable_type(cx, inner_ty, span) - }, - Tuple(..) => ty.tuple_fields().any(|ty| is_mutable_type(cx, ty, span)), - Adt(..) => { - cx.tcx.layout_of(cx.param_env.and(ty)).is_ok() - && !ty.has_escaping_bound_vars() - && !ty.is_freeze(cx.tcx.at(span), cx.param_env) - }, - _ => false, - } -} diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs deleted file mode 100644 index 2f3cdb894f01..000000000000 --- a/clippy_lints/src/mut_mut.rs +++ /dev/null @@ -1,114 +0,0 @@ -use crate::utils::{higher, span_lint}; -use rustc_hir as hir; -use rustc_hir::intravisit; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for instances of `mut mut` references. - /// - /// **Why is this bad?** Multiple `mut`s don't add anything meaningful to the - /// source. This is either a copy'n'paste error, or it shows a fundamental - /// misunderstanding of references. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let mut y = 1; - /// let x = &mut &mut y; - /// ``` - pub MUT_MUT, - pedantic, - "usage of double-mut refs, e.g., `&mut &mut ...`" -} - -declare_lint_pass!(MutMut => [MUT_MUT]); - -impl<'tcx> LateLintPass<'tcx> for MutMut { - fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx hir::Block<'_>) { - intravisit::walk_block(&mut MutVisitor { cx }, block); - } - - fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'_>) { - use rustc_hir::intravisit::Visitor; - - MutVisitor { cx }.visit_ty(ty); - } -} - -pub struct MutVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, -} - -impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { - if in_external_macro(self.cx.sess(), expr.span) { - return; - } - - if let Some((_, arg, body)) = higher::for_loop(expr) { - // A `for` loop lowers to: - // ```rust - // match ::std::iter::Iterator::next(&mut iter) { - // // ^^^^ - // ``` - // Let's ignore the generated code. - intravisit::walk_expr(self, arg); - intravisit::walk_expr(self, body); - } else if let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, ref e) = expr.kind { - if let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, _) = e.kind { - span_lint( - self.cx, - MUT_MUT, - expr.span, - "generally you want to avoid `&mut &mut _` if possible", - ); - } else if let ty::Ref(_, _, hir::Mutability::Mut) = self.cx.typeck_results().expr_ty(e).kind() { - span_lint( - self.cx, - MUT_MUT, - expr.span, - "this expression mutably borrows a mutable reference. Consider reborrowing", - ); - } - } - } - - fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) { - if let hir::TyKind::Rptr( - _, - hir::MutTy { - ty: ref pty, - mutbl: hir::Mutability::Mut, - }, - ) = ty.kind - { - if let hir::TyKind::Rptr( - _, - hir::MutTy { - mutbl: hir::Mutability::Mut, - .. - }, - ) = pty.kind - { - span_lint( - self.cx, - MUT_MUT, - ty.span, - "generally you want to avoid `&mut &mut _` if possible", - ); - } - } - - intravisit::walk_ty(self, ty); - } - fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap { - intravisit::NestedVisitorMap::None - } -} diff --git a/clippy_lints/src/mut_mutex_lock.rs b/clippy_lints/src/mut_mutex_lock.rs deleted file mode 100644 index df1cecb328cb..000000000000 --- a/clippy_lints/src/mut_mutex_lock.rs +++ /dev/null @@ -1,68 +0,0 @@ -use crate::utils::{is_type_diagnostic_item, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, Mutability}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for `&mut Mutex::lock` calls - /// - /// **Why is this bad?** `Mutex::lock` is less efficient than - /// calling `Mutex::get_mut`. In addition you also have a statically - /// guarantee that the mutex isn't locked, instead of just a runtime - /// guarantee. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// use std::sync::{Arc, Mutex}; - /// - /// let mut value_rc = Arc::new(Mutex::new(42_u8)); - /// let value_mutex = Arc::get_mut(&mut value_rc).unwrap(); - /// - /// let mut value = value_mutex.lock().unwrap(); - /// *value += 1; - /// ``` - /// Use instead: - /// ```rust - /// use std::sync::{Arc, Mutex}; - /// - /// let mut value_rc = Arc::new(Mutex::new(42_u8)); - /// let value_mutex = Arc::get_mut(&mut value_rc).unwrap(); - /// - /// let value = value_mutex.get_mut().unwrap(); - /// *value += 1; - /// ``` - pub MUT_MUTEX_LOCK, - style, - "`&mut Mutex::lock` does unnecessary locking" -} - -declare_lint_pass!(MutMutexLock => [MUT_MUTEX_LOCK]); - -impl<'tcx> LateLintPass<'tcx> for MutMutexLock { - fn check_expr(&mut self, cx: &LateContext<'tcx>, ex: &'tcx Expr<'tcx>) { - if_chain! { - if let ExprKind::MethodCall(path, method_span, args, _) = &ex.kind; - if path.ident.name == sym!(lock); - let ty = cx.typeck_results().expr_ty(&args[0]); - if let ty::Ref(_, inner_ty, Mutability::Mut) = ty.kind(); - if is_type_diagnostic_item(cx, inner_ty, sym!(mutex_type)); - then { - span_lint_and_sugg( - cx, - MUT_MUTEX_LOCK, - *method_span, - "calling `&mut Mutex::lock` unnecessarily locks an exclusive (mutable) reference", - "change this to", - "get_mut".to_owned(), - Applicability::MaybeIncorrect, - ); - } - } - } -} diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs deleted file mode 100644 index 3f0b765df156..000000000000 --- a/clippy_lints/src/mut_reference.rs +++ /dev/null @@ -1,88 +0,0 @@ -use crate::utils::span_lint; -use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::subst::Subst; -use rustc_middle::ty::{self, Ty}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Detects passing a mutable reference to a function that only - /// requires an immutable reference. - /// - /// **Why is this bad?** The mutable reference rules out all other references to - /// the value. Also the code misleads about the intent of the call site. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// // Bad - /// my_vec.push(&mut value) - /// - /// // Good - /// my_vec.push(&value) - /// ``` - pub UNNECESSARY_MUT_PASSED, - style, - "an argument passed as a mutable reference although the callee only demands an immutable reference" -} - -declare_lint_pass!(UnnecessaryMutPassed => [UNNECESSARY_MUT_PASSED]); - -impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - match e.kind { - ExprKind::Call(ref fn_expr, ref arguments) => { - if let ExprKind::Path(ref path) = fn_expr.kind { - check_arguments( - cx, - arguments, - cx.typeck_results().expr_ty(fn_expr), - &rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false)), - "function", - ); - } - }, - ExprKind::MethodCall(ref path, _, ref arguments, _) => { - let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap(); - let substs = cx.typeck_results().node_substs(e.hir_id); - let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs); - check_arguments(cx, arguments, method_type, &path.ident.as_str(), "method") - }, - _ => (), - } - } -} - -fn check_arguments<'tcx>( - cx: &LateContext<'tcx>, - arguments: &[Expr<'_>], - type_definition: Ty<'tcx>, - name: &str, - fn_kind: &str, -) { - match type_definition.kind() { - ty::FnDef(..) | ty::FnPtr(_) => { - let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs(); - for (argument, parameter) in arguments.iter().zip(parameters.iter()) { - match parameter.kind() { - ty::Ref(_, _, Mutability::Not) - | ty::RawPtr(ty::TypeAndMut { - mutbl: Mutability::Not, .. - }) => { - if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, _) = argument.kind { - span_lint( - cx, - UNNECESSARY_MUT_PASSED, - argument.span, - &format!("the {} `{}` doesn't need a mutable reference", fn_kind, name), - ); - } - }, - _ => (), - } - } - }, - _ => (), - } -} diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs deleted file mode 100644 index 76417aa7ed09..000000000000 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ /dev/null @@ -1,115 +0,0 @@ -use crate::utils::{higher, is_direct_expn_of, span_lint}; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; -use rustc_hir::{BorrowKind, Expr, ExprKind, MatchSource, Mutability}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for function/method calls with a mutable - /// parameter in `debug_assert!`, `debug_assert_eq!` and `debug_assert_ne!` macros. - /// - /// **Why is this bad?** In release builds `debug_assert!` macros are optimized out by the - /// compiler. - /// Therefore mutating something in a `debug_assert!` macro results in different behaviour - /// between a release and debug build. - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```rust,ignore - /// debug_assert_eq!(vec![3].pop(), Some(3)); - /// // or - /// fn take_a_mut_parameter(_: &mut u32) -> bool { unimplemented!() } - /// debug_assert!(take_a_mut_parameter(&mut 5)); - /// ``` - pub DEBUG_ASSERT_WITH_MUT_CALL, - nursery, - "mutable arguments in `debug_assert{,_ne,_eq}!`" -} - -declare_lint_pass!(DebugAssertWithMutCall => [DEBUG_ASSERT_WITH_MUT_CALL]); - -const DEBUG_MACRO_NAMES: [&str; 3] = ["debug_assert", "debug_assert_eq", "debug_assert_ne"]; - -impl<'tcx> LateLintPass<'tcx> for DebugAssertWithMutCall { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - for dmn in &DEBUG_MACRO_NAMES { - if is_direct_expn_of(e.span, dmn).is_some() { - if let Some(macro_args) = higher::extract_assert_macro_args(e) { - for arg in macro_args { - let mut visitor = MutArgVisitor::new(cx); - visitor.visit_expr(arg); - if let Some(span) = visitor.expr_span() { - span_lint( - cx, - DEBUG_ASSERT_WITH_MUT_CALL, - span, - &format!("do not call a function with mutable arguments inside of `{}!`", dmn), - ); - } - } - } - } - } - } -} - -struct MutArgVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - expr_span: Option, - found: bool, -} - -impl<'a, 'tcx> MutArgVisitor<'a, 'tcx> { - fn new(cx: &'a LateContext<'tcx>) -> Self { - Self { - cx, - expr_span: None, - found: false, - } - } - - fn expr_span(&self) -> Option { - if self.found { - self.expr_span - } else { - None - } - } -} - -impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - match expr.kind { - ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, _) => { - self.found = true; - return; - }, - ExprKind::Path(_) => { - if let Some(adj) = self.cx.typeck_results().adjustments().get(expr.hir_id) { - if adj - .iter() - .any(|a| matches!(a.target.kind(), ty::Ref(_, _, Mutability::Mut))) - { - self.found = true; - return; - } - } - }, - // Don't check await desugars - ExprKind::Match(_, _, MatchSource::AwaitDesugar) => return, - _ if !self.found => self.expr_span = Some(expr.span), - _ => return, - } - walk_expr(self, expr) - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) - } -} diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs deleted file mode 100644 index ea986874291e..000000000000 --- a/clippy_lints/src/mutex_atomic.rs +++ /dev/null @@ -1,98 +0,0 @@ -//! Checks for uses of mutex where an atomic value could be used -//! -//! This lint is **warn** by default - -use crate::utils::{is_type_diagnostic_item, span_lint}; -use rustc_ast::ast; -use rustc_hir::Expr; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, Ty}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for usages of `Mutex` where an atomic will do. - /// - /// **Why is this bad?** Using a mutex just to make access to a plain bool or - /// reference sequential is shooting flies with cannons. - /// `std::sync::atomic::AtomicBool` and `std::sync::atomic::AtomicPtr` are leaner and - /// faster. - /// - /// **Known problems:** This lint cannot detect if the mutex is actually used - /// for waiting before a critical section. - /// - /// **Example:** - /// ```rust - /// # let y = true; - /// - /// // Bad - /// # use std::sync::Mutex; - /// let x = Mutex::new(&y); - /// - /// // Good - /// # use std::sync::atomic::AtomicBool; - /// let x = AtomicBool::new(y); - /// ``` - pub MUTEX_ATOMIC, - perf, - "using a mutex where an atomic value could be used instead" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usages of `Mutex` where `X` is an integral - /// type. - /// - /// **Why is this bad?** Using a mutex just to make access to a plain integer - /// sequential is - /// shooting flies with cannons. `std::sync::atomic::AtomicUsize` is leaner and faster. - /// - /// **Known problems:** This lint cannot detect if the mutex is actually used - /// for waiting before a critical section. - /// - /// **Example:** - /// ```rust - /// # use std::sync::Mutex; - /// let x = Mutex::new(0usize); - /// - /// // Good - /// # use std::sync::atomic::AtomicUsize; - /// let x = AtomicUsize::new(0usize); - /// ``` - pub MUTEX_INTEGER, - nursery, - "using a mutex for an integer type" -} - -declare_lint_pass!(Mutex => [MUTEX_ATOMIC, MUTEX_INTEGER]); - -impl<'tcx> LateLintPass<'tcx> for Mutex { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - let ty = cx.typeck_results().expr_ty(expr); - if let ty::Adt(_, subst) = ty.kind() { - if is_type_diagnostic_item(cx, ty, sym!(mutex_type)) { - let mutex_param = subst.type_at(0); - if let Some(atomic_name) = get_atomic_name(mutex_param) { - let msg = format!( - "consider using an `{}` instead of a `Mutex` here; if you just want the locking \ - behavior and not the internal type, consider using `Mutex<()>`", - atomic_name - ); - match *mutex_param.kind() { - ty::Uint(t) if t != ast::UintTy::Usize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg), - ty::Int(t) if t != ast::IntTy::Isize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg), - _ => span_lint(cx, MUTEX_ATOMIC, expr.span, &msg), - }; - } - } - } - } -} - -fn get_atomic_name(ty: Ty<'_>) -> Option<&'static str> { - match ty.kind() { - ty::Bool => Some("AtomicBool"), - ty::Uint(_) => Some("AtomicUsize"), - ty::Int(_) => Some("AtomicIsize"), - ty::RawPtr(_) => Some("AtomicPtr"), - _ => None, - } -} diff --git a/clippy_lints/src/needless_arbitrary_self_type.rs b/clippy_lints/src/needless_arbitrary_self_type.rs deleted file mode 100644 index 7687962bdd9b..000000000000 --- a/clippy_lints/src/needless_arbitrary_self_type.rs +++ /dev/null @@ -1,138 +0,0 @@ -use crate::utils::{in_macro, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_ast::ast::{BindingMode, Lifetime, Mutability, Param, PatKind, Path, TyKind}; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::symbol::kw; -use rustc_span::Span; - -declare_clippy_lint! { - /// **What it does:** The lint checks for `self` in fn parameters that - /// specify the `Self`-type explicitly - /// **Why is this bad?** Increases the amount and decreases the readability of code - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```rust - /// enum ValType { - /// I32, - /// I64, - /// F32, - /// F64, - /// } - /// - /// impl ValType { - /// pub fn bytes(self: Self) -> usize { - /// match self { - /// Self::I32 | Self::F32 => 4, - /// Self::I64 | Self::F64 => 8, - /// } - /// } - /// } - /// ``` - /// - /// Could be rewritten as - /// - /// ```rust - /// enum ValType { - /// I32, - /// I64, - /// F32, - /// F64, - /// } - /// - /// impl ValType { - /// pub fn bytes(self) -> usize { - /// match self { - /// Self::I32 | Self::F32 => 4, - /// Self::I64 | Self::F64 => 8, - /// } - /// } - /// } - /// ``` - pub NEEDLESS_ARBITRARY_SELF_TYPE, - complexity, - "type of `self` parameter is already by default `Self`" -} - -declare_lint_pass!(NeedlessArbitrarySelfType => [NEEDLESS_ARBITRARY_SELF_TYPE]); - -enum Mode { - Ref(Option), - Value, -} - -fn check_param_inner(cx: &EarlyContext<'_>, path: &Path, span: Span, binding_mode: &Mode, mutbl: Mutability) { - if_chain! { - if let [segment] = &path.segments[..]; - if segment.ident.name == kw::SelfUpper; - then { - // In case we have a named lifetime, we check if the name comes from expansion. - // If it does, at this point we know the rest of the parameter was written by the user, - // so let them decide what the name of the lifetime should be. - // See #6089 for more details. - let mut applicability = Applicability::MachineApplicable; - let self_param = match (binding_mode, mutbl) { - (Mode::Ref(None), Mutability::Mut) => "&mut self".to_string(), - (Mode::Ref(Some(lifetime)), Mutability::Mut) => { - if in_macro(lifetime.ident.span) { - applicability = Applicability::HasPlaceholders; - "&'_ mut self".to_string() - } else { - format!("&{} mut self", &lifetime.ident.name) - } - }, - (Mode::Ref(None), Mutability::Not) => "&self".to_string(), - (Mode::Ref(Some(lifetime)), Mutability::Not) => { - if in_macro(lifetime.ident.span) { - applicability = Applicability::HasPlaceholders; - "&'_ self".to_string() - } else { - format!("&{} self", &lifetime.ident.name) - } - }, - (Mode::Value, Mutability::Mut) => "mut self".to_string(), - (Mode::Value, Mutability::Not) => "self".to_string(), - }; - - span_lint_and_sugg( - cx, - NEEDLESS_ARBITRARY_SELF_TYPE, - span, - "the type of the `self` parameter does not need to be arbitrary", - "consider to change this parameter to", - self_param, - applicability, - ) - } - } -} - -impl EarlyLintPass for NeedlessArbitrarySelfType { - fn check_param(&mut self, cx: &EarlyContext<'_>, p: &Param) { - // Bail out if the parameter it's not a receiver or was not written by the user - if !p.is_self() || in_macro(p.span) { - return; - } - - match &p.ty.kind { - TyKind::Path(None, path) => { - if let PatKind::Ident(BindingMode::ByValue(mutbl), _, _) = p.pat.kind { - check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Value, mutbl) - } - }, - TyKind::Rptr(lifetime, mut_ty) => { - if_chain! { - if let TyKind::Path(None, path) = &mut_ty.ty.kind; - if let PatKind::Ident(BindingMode::ByValue(Mutability::Not), _, _) = p.pat.kind; - then { - check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Ref(*lifetime), mut_ty.mutbl) - } - } - }, - _ => {}, - } - } -} diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs deleted file mode 100644 index 42f97b2ac497..000000000000 --- a/clippy_lints/src/needless_bool.rs +++ /dev/null @@ -1,357 +0,0 @@ -//! Checks for needless boolean results of if-else expressions -//! -//! This lint is **warn** by default - -use crate::utils::sugg::Sugg; -use crate::utils::{ - higher, is_expn_of, parent_node_is_if_expr, snippet_with_applicability, span_lint, span_lint_and_sugg, -}; -use rustc_ast::ast::LitKind; -use rustc_errors::Applicability; -use rustc_hir::{BinOpKind, Block, Expr, ExprKind, StmtKind, UnOp}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Spanned; -use rustc_span::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for expressions of the form `if c { true } else { - /// false }` (or vice versa) and suggests using the condition directly. - /// - /// **Why is this bad?** Redundant code. - /// - /// **Known problems:** Maybe false positives: Sometimes, the two branches are - /// painstakingly documented (which we, of course, do not detect), so they *may* - /// have some value. Even then, the documentation can be rewritten to match the - /// shorter code. - /// - /// **Example:** - /// ```rust,ignore - /// if x { - /// false - /// } else { - /// true - /// } - /// ``` - /// Could be written as - /// ```rust,ignore - /// !x - /// ``` - pub NEEDLESS_BOOL, - complexity, - "if-statements with plain booleans in the then- and else-clause, e.g., `if p { true } else { false }`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for expressions of the form `x == true`, - /// `x != true` and order comparisons such as `x < true` (or vice versa) and - /// suggest using the variable directly. - /// - /// **Why is this bad?** Unnecessary code. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// if x == true {} - /// if y == false {} - /// ``` - /// use `x` directly: - /// ```rust,ignore - /// if x {} - /// if !y {} - /// ``` - pub BOOL_COMPARISON, - complexity, - "comparing a variable to a boolean, e.g., `if x == true` or `if x != true`" -} - -declare_lint_pass!(NeedlessBool => [NEEDLESS_BOOL]); - -impl<'tcx> LateLintPass<'tcx> for NeedlessBool { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - use self::Expression::{Bool, RetBool}; - if let Some((ref pred, ref then_block, Some(ref else_expr))) = higher::if_block(&e) { - let reduce = |ret, not| { - let mut applicability = Applicability::MachineApplicable; - let snip = Sugg::hir_with_applicability(cx, pred, "", &mut applicability); - let mut snip = if not { !snip } else { snip }; - - if ret { - snip = snip.make_return(); - } - - if parent_node_is_if_expr(&e, &cx) { - snip = snip.blockify() - } - - span_lint_and_sugg( - cx, - NEEDLESS_BOOL, - e.span, - "this if-then-else expression returns a bool literal", - "you can reduce it to", - snip.to_string(), - applicability, - ); - }; - if let ExprKind::Block(ref then_block, _) = then_block.kind { - match (fetch_bool_block(then_block), fetch_bool_expr(else_expr)) { - (RetBool(true), RetBool(true)) | (Bool(true), Bool(true)) => { - span_lint( - cx, - NEEDLESS_BOOL, - e.span, - "this if-then-else expression will always return true", - ); - }, - (RetBool(false), RetBool(false)) | (Bool(false), Bool(false)) => { - span_lint( - cx, - NEEDLESS_BOOL, - e.span, - "this if-then-else expression will always return false", - ); - }, - (RetBool(true), RetBool(false)) => reduce(true, false), - (Bool(true), Bool(false)) => reduce(false, false), - (RetBool(false), RetBool(true)) => reduce(true, true), - (Bool(false), Bool(true)) => reduce(false, true), - _ => (), - } - } else { - panic!("IfExpr `then` node is not an `ExprKind::Block`"); - } - } - } -} - -declare_lint_pass!(BoolComparison => [BOOL_COMPARISON]); - -impl<'tcx> LateLintPass<'tcx> for BoolComparison { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if e.span.from_expansion() { - return; - } - - if let ExprKind::Binary(Spanned { node, .. }, ..) = e.kind { - let ignore_case = None::<(fn(_) -> _, &str)>; - let ignore_no_literal = None::<(fn(_, _) -> _, &str)>; - match node { - BinOpKind::Eq => { - let true_case = Some((|h| h, "equality checks against true are unnecessary")); - let false_case = Some(( - |h: Sugg<'_>| !h, - "equality checks against false can be replaced by a negation", - )); - check_comparison(cx, e, true_case, false_case, true_case, false_case, ignore_no_literal) - }, - BinOpKind::Ne => { - let true_case = Some(( - |h: Sugg<'_>| !h, - "inequality checks against true can be replaced by a negation", - )); - let false_case = Some((|h| h, "inequality checks against false are unnecessary")); - check_comparison(cx, e, true_case, false_case, true_case, false_case, ignore_no_literal) - }, - BinOpKind::Lt => check_comparison( - cx, - e, - ignore_case, - Some((|h| h, "greater than checks against false are unnecessary")), - Some(( - |h: Sugg<'_>| !h, - "less than comparison against true can be replaced by a negation", - )), - ignore_case, - Some(( - |l: Sugg<'_>, r: Sugg<'_>| (!l).bit_and(&r), - "order comparisons between booleans can be simplified", - )), - ), - BinOpKind::Gt => check_comparison( - cx, - e, - Some(( - |h: Sugg<'_>| !h, - "less than comparison against true can be replaced by a negation", - )), - ignore_case, - ignore_case, - Some((|h| h, "greater than checks against false are unnecessary")), - Some(( - |l: Sugg<'_>, r: Sugg<'_>| l.bit_and(&(!r)), - "order comparisons between booleans can be simplified", - )), - ), - _ => (), - } - } - } -} - -struct ExpressionInfoWithSpan { - one_side_is_unary_not: bool, - left_span: Span, - right_span: Span, -} - -fn is_unary_not(e: &Expr<'_>) -> (bool, Span) { - if let ExprKind::Unary(UnOp::UnNot, operand) = e.kind { - return (true, operand.span); - } - (false, e.span) -} - -fn one_side_is_unary_not<'tcx>(left_side: &'tcx Expr<'_>, right_side: &'tcx Expr<'_>) -> ExpressionInfoWithSpan { - let left = is_unary_not(left_side); - let right = is_unary_not(right_side); - - ExpressionInfoWithSpan { - one_side_is_unary_not: left.0 != right.0, - left_span: left.1, - right_span: right.1, - } -} - -fn check_comparison<'a, 'tcx>( - cx: &LateContext<'tcx>, - e: &'tcx Expr<'_>, - left_true: Option<(impl FnOnce(Sugg<'a>) -> Sugg<'a>, &str)>, - left_false: Option<(impl FnOnce(Sugg<'a>) -> Sugg<'a>, &str)>, - right_true: Option<(impl FnOnce(Sugg<'a>) -> Sugg<'a>, &str)>, - right_false: Option<(impl FnOnce(Sugg<'a>) -> Sugg<'a>, &str)>, - no_literal: Option<(impl FnOnce(Sugg<'a>, Sugg<'a>) -> Sugg<'a>, &str)>, -) { - use self::Expression::{Bool, Other}; - - if let ExprKind::Binary(op, ref left_side, ref right_side) = e.kind { - let (l_ty, r_ty) = ( - cx.typeck_results().expr_ty(left_side), - cx.typeck_results().expr_ty(right_side), - ); - if is_expn_of(left_side.span, "cfg").is_some() || is_expn_of(right_side.span, "cfg").is_some() { - return; - } - if l_ty.is_bool() && r_ty.is_bool() { - let mut applicability = Applicability::MachineApplicable; - - if let BinOpKind::Eq = op.node { - let expression_info = one_side_is_unary_not(&left_side, &right_side); - if expression_info.one_side_is_unary_not { - span_lint_and_sugg( - cx, - BOOL_COMPARISON, - e.span, - "this comparison might be written more concisely", - "try simplifying it as shown", - format!( - "{} != {}", - snippet_with_applicability(cx, expression_info.left_span, "..", &mut applicability), - snippet_with_applicability(cx, expression_info.right_span, "..", &mut applicability) - ), - applicability, - ) - } - } - - match (fetch_bool_expr(left_side), fetch_bool_expr(right_side)) { - (Bool(true), Other) => left_true.map_or((), |(h, m)| { - suggest_bool_comparison(cx, e, right_side, applicability, m, h) - }), - (Other, Bool(true)) => right_true.map_or((), |(h, m)| { - suggest_bool_comparison(cx, e, left_side, applicability, m, h) - }), - (Bool(false), Other) => left_false.map_or((), |(h, m)| { - suggest_bool_comparison(cx, e, right_side, applicability, m, h) - }), - (Other, Bool(false)) => right_false.map_or((), |(h, m)| { - suggest_bool_comparison(cx, e, left_side, applicability, m, h) - }), - (Other, Other) => no_literal.map_or((), |(h, m)| { - let left_side = Sugg::hir_with_applicability(cx, left_side, "..", &mut applicability); - let right_side = Sugg::hir_with_applicability(cx, right_side, "..", &mut applicability); - span_lint_and_sugg( - cx, - BOOL_COMPARISON, - e.span, - m, - "try simplifying it as shown", - h(left_side, right_side).to_string(), - applicability, - ) - }), - _ => (), - } - } - } -} - -fn suggest_bool_comparison<'a, 'tcx>( - cx: &LateContext<'tcx>, - e: &'tcx Expr<'_>, - expr: &Expr<'_>, - mut applicability: Applicability, - message: &str, - conv_hint: impl FnOnce(Sugg<'a>) -> Sugg<'a>, -) { - let hint = if expr.span.from_expansion() { - if applicability != Applicability::Unspecified { - applicability = Applicability::MaybeIncorrect; - } - Sugg::hir_with_macro_callsite(cx, expr, "..") - } else { - Sugg::hir_with_applicability(cx, expr, "..", &mut applicability) - }; - span_lint_and_sugg( - cx, - BOOL_COMPARISON, - e.span, - message, - "try simplifying it as shown", - conv_hint(hint).to_string(), - applicability, - ); -} - -enum Expression { - Bool(bool), - RetBool(bool), - Other, -} - -fn fetch_bool_block(block: &Block<'_>) -> Expression { - match (&*block.stmts, block.expr.as_ref()) { - (&[], Some(e)) => fetch_bool_expr(&**e), - (&[ref e], None) => { - if let StmtKind::Semi(ref e) = e.kind { - if let ExprKind::Ret(_) = e.kind { - fetch_bool_expr(&**e) - } else { - Expression::Other - } - } else { - Expression::Other - } - }, - _ => Expression::Other, - } -} - -fn fetch_bool_expr(expr: &Expr<'_>) -> Expression { - match expr.kind { - ExprKind::Block(ref block, _) => fetch_bool_block(block), - ExprKind::Lit(ref lit_ptr) => { - if let LitKind::Bool(value) = lit_ptr.node { - Expression::Bool(value) - } else { - Expression::Other - } - }, - ExprKind::Ret(Some(ref expr)) => match fetch_bool_expr(expr) { - Expression::Bool(value) => Expression::RetBool(value), - _ => Expression::Other, - }, - _ => Expression::Other, - } -} diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs deleted file mode 100644 index bff53eb8ccad..000000000000 --- a/clippy_lints/src/needless_borrow.rs +++ /dev/null @@ -1,132 +0,0 @@ -//! Checks for needless address of operations (`&`) -//! -//! This lint is **warn** by default - -use crate::utils::{snippet_opt, span_lint_and_then}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{BindingAnnotation, BorrowKind, Expr, ExprKind, HirId, Item, Mutability, Pat, PatKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_middle::ty::adjustment::{Adjust, Adjustment}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** Checks for address of operations (`&`) that are going to - /// be dereferenced immediately by the compiler. - /// - /// **Why is this bad?** Suggests that the receiver of the expression borrows - /// the expression. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// // Bad - /// let x: &i32 = &&&&&&5; - /// - /// // Good - /// let x: &i32 = &5; - /// ``` - pub NEEDLESS_BORROW, - nursery, - "taking a reference that is going to be automatically dereferenced" -} - -#[derive(Default)] -pub struct NeedlessBorrow { - derived_item: Option, -} - -impl_lint_pass!(NeedlessBorrow => [NEEDLESS_BORROW]); - -impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if e.span.from_expansion() || self.derived_item.is_some() { - return; - } - if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = e.kind { - if let ty::Ref(_, ty, _) = cx.typeck_results().expr_ty(inner).kind() { - for adj3 in cx.typeck_results().expr_adjustments(e).windows(3) { - if let [Adjustment { - kind: Adjust::Deref(_), .. - }, Adjustment { - kind: Adjust::Deref(_), .. - }, Adjustment { - kind: Adjust::Borrow(_), - .. - }] = *adj3 - { - span_lint_and_then( - cx, - NEEDLESS_BORROW, - e.span, - &format!( - "this expression borrows a reference (`&{}`) that is immediately dereferenced \ - by the compiler", - ty - ), - |diag| { - if let Some(snippet) = snippet_opt(cx, inner.span) { - diag.span_suggestion( - e.span, - "change this to", - snippet, - Applicability::MachineApplicable, - ); - } - }, - ); - } - } - } - } - } - fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { - if pat.span.from_expansion() || self.derived_item.is_some() { - return; - } - if_chain! { - if let PatKind::Binding(BindingAnnotation::Ref, .., name, _) = pat.kind; - if let ty::Ref(_, tam, mutbl) = *cx.typeck_results().pat_ty(pat).kind(); - if mutbl == Mutability::Not; - if let ty::Ref(_, _, mutbl) = *tam.kind(); - // only lint immutable refs, because borrowed `&mut T` cannot be moved out - if mutbl == Mutability::Not; - then { - span_lint_and_then( - cx, - NEEDLESS_BORROW, - pat.span, - "this pattern creates a reference to a reference", - |diag| { - if let Some(snippet) = snippet_opt(cx, name.span) { - diag.span_suggestion( - pat.span, - "change this to", - snippet, - Applicability::MachineApplicable, - ); - } - } - ) - } - } - } - - fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if item.attrs.iter().any(|a| a.has_name(sym::automatically_derived)) { - debug_assert!(self.derived_item.is_none()); - self.derived_item = Some(item.hir_id); - } - } - - fn check_item_post(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let Some(id) = self.derived_item { - if item.hir_id == id { - self.derived_item = None; - } - } - } -} diff --git a/clippy_lints/src/needless_borrowed_ref.rs b/clippy_lints/src/needless_borrowed_ref.rs deleted file mode 100644 index 85184fdea477..000000000000 --- a/clippy_lints/src/needless_borrowed_ref.rs +++ /dev/null @@ -1,92 +0,0 @@ -//! Checks for useless borrowed references. -//! -//! This lint is **warn** by default - -use crate::utils::{snippet_with_applicability, span_lint_and_then}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{BindingAnnotation, Mutability, Node, Pat, PatKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for useless borrowed references. - /// - /// **Why is this bad?** It is mostly useless and make the code look more - /// complex than it - /// actually is. - /// - /// **Known problems:** It seems that the `&ref` pattern is sometimes useful. - /// For instance in the following snippet: - /// ```rust,ignore - /// enum Animal { - /// Cat(u64), - /// Dog(u64), - /// } - /// - /// fn foo(a: &Animal, b: &Animal) { - /// match (a, b) { - /// (&Animal::Cat(v), k) | (k, &Animal::Cat(v)) => (), // lifetime mismatch error - /// (&Animal::Dog(ref c), &Animal::Dog(_)) => () - /// } - /// } - /// ``` - /// There is a lifetime mismatch error for `k` (indeed a and b have distinct - /// lifetime). - /// This can be fixed by using the `&ref` pattern. - /// However, the code can also be fixed by much cleaner ways - /// - /// **Example:** - /// ```rust - /// let mut v = Vec::::new(); - /// let _ = v.iter_mut().filter(|&ref a| a.is_empty()); - /// ``` - /// This closure takes a reference on something that has been matched as a - /// reference and - /// de-referenced. - /// As such, it could just be |a| a.is_empty() - pub NEEDLESS_BORROWED_REFERENCE, - complexity, - "taking a needless borrowed reference" -} - -declare_lint_pass!(NeedlessBorrowedRef => [NEEDLESS_BORROWED_REFERENCE]); - -impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowedRef { - fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { - if pat.span.from_expansion() { - // OK, simple enough, lints doesn't check in macro. - return; - } - - if_chain! { - // Only lint immutable refs, because `&mut ref T` may be useful. - if let PatKind::Ref(ref sub_pat, Mutability::Not) = pat.kind; - - // Check sub_pat got a `ref` keyword (excluding `ref mut`). - if let PatKind::Binding(BindingAnnotation::Ref, .., spanned_name, _) = sub_pat.kind; - let parent_id = cx.tcx.hir().get_parent_node(pat.hir_id); - if let Some(parent_node) = cx.tcx.hir().find(parent_id); - then { - // do not recurse within patterns, as they may have other references - // XXXManishearth we can relax this constraint if we only check patterns - // with a single ref pattern inside them - if let Node::Pat(_) = parent_node { - return; - } - let mut applicability = Applicability::MachineApplicable; - span_lint_and_then(cx, NEEDLESS_BORROWED_REFERENCE, pat.span, - "this pattern takes a reference on something that is being de-referenced", - |diag| { - let hint = snippet_with_applicability(cx, spanned_name.span, "..", &mut applicability).into_owned(); - diag.span_suggestion( - pat.span, - "try removing the `&ref` part and just keep", - hint, - applicability, - ); - }); - } - } - } -} diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs deleted file mode 100644 index a971d041ca66..000000000000 --- a/clippy_lints/src/needless_continue.rs +++ /dev/null @@ -1,463 +0,0 @@ -//! Checks for continue statements in loops that are redundant. -//! -//! For example, the lint would catch -//! -//! ```rust -//! let mut a = 1; -//! let x = true; -//! -//! while a < 5 { -//! a = 6; -//! if x { -//! // ... -//! } else { -//! continue; -//! } -//! println!("Hello, world"); -//! } -//! ``` -//! -//! And suggest something like this: -//! -//! ```rust -//! let mut a = 1; -//! let x = true; -//! -//! while a < 5 { -//! a = 6; -//! if x { -//! // ... -//! println!("Hello, world"); -//! } -//! } -//! ``` -//! -//! This lint is **warn** by default. -use rustc_ast::ast; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::{original_sp, DUMMY_SP}; -use rustc_span::Span; - -use crate::utils::{indent_of, snippet, snippet_block, span_lint_and_help}; - -declare_clippy_lint! { - /// **What it does:** The lint checks for `if`-statements appearing in loops - /// that contain a `continue` statement in either their main blocks or their - /// `else`-blocks, when omitting the `else`-block possibly with some - /// rearrangement of code can make the code easier to understand. - /// - /// **Why is this bad?** Having explicit `else` blocks for `if` statements - /// containing `continue` in their THEN branch adds unnecessary branching and - /// nesting to the code. Having an else block containing just `continue` can - /// also be better written by grouping the statements following the whole `if` - /// statement within the THEN block and omitting the else block completely. - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```rust - /// # fn condition() -> bool { false } - /// # fn update_condition() {} - /// # let x = false; - /// while condition() { - /// update_condition(); - /// if x { - /// // ... - /// } else { - /// continue; - /// } - /// println!("Hello, world"); - /// } - /// ``` - /// - /// Could be rewritten as - /// - /// ```rust - /// # fn condition() -> bool { false } - /// # fn update_condition() {} - /// # let x = false; - /// while condition() { - /// update_condition(); - /// if x { - /// // ... - /// println!("Hello, world"); - /// } - /// } - /// ``` - /// - /// As another example, the following code - /// - /// ```rust - /// # fn waiting() -> bool { false } - /// loop { - /// if waiting() { - /// continue; - /// } else { - /// // Do something useful - /// } - /// # break; - /// } - /// ``` - /// Could be rewritten as - /// - /// ```rust - /// # fn waiting() -> bool { false } - /// loop { - /// if waiting() { - /// continue; - /// } - /// // Do something useful - /// # break; - /// } - /// ``` - pub NEEDLESS_CONTINUE, - pedantic, - "`continue` statements that can be replaced by a rearrangement of code" -} - -declare_lint_pass!(NeedlessContinue => [NEEDLESS_CONTINUE]); - -impl EarlyLintPass for NeedlessContinue { - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { - if !expr.span.from_expansion() { - check_and_warn(cx, expr); - } - } -} - -/* This lint has to mainly deal with two cases of needless continue - * statements. */ -// Case 1 [Continue inside else block]: -// -// loop { -// // region A -// if cond { -// // region B -// } else { -// continue; -// } -// // region C -// } -// -// This code can better be written as follows: -// -// loop { -// // region A -// if cond { -// // region B -// // region C -// } -// } -// -// Case 2 [Continue inside then block]: -// -// loop { -// // region A -// if cond { -// continue; -// // potentially more code here. -// } else { -// // region B -// } -// // region C -// } -// -// -// This snippet can be refactored to: -// -// loop { -// // region A -// if !cond { -// // region B -// // region C -// } -// } -// - -/// Given an expression, returns true if either of the following is true -/// -/// - The expression is a `continue` node. -/// - The expression node is a block with the first statement being a -/// `continue`. -fn needless_continue_in_else(else_expr: &ast::Expr, label: Option<&ast::Label>) -> bool { - match else_expr.kind { - ast::ExprKind::Block(ref else_block, _) => is_first_block_stmt_continue(else_block, label), - ast::ExprKind::Continue(l) => compare_labels(label, l.as_ref()), - _ => false, - } -} - -fn is_first_block_stmt_continue(block: &ast::Block, label: Option<&ast::Label>) -> bool { - block.stmts.get(0).map_or(false, |stmt| match stmt.kind { - ast::StmtKind::Semi(ref e) | ast::StmtKind::Expr(ref e) => { - if let ast::ExprKind::Continue(ref l) = e.kind { - compare_labels(label, l.as_ref()) - } else { - false - } - }, - _ => false, - }) -} - -/// If the `continue` has a label, check it matches the label of the loop. -fn compare_labels(loop_label: Option<&ast::Label>, continue_label: Option<&ast::Label>) -> bool { - match (loop_label, continue_label) { - // `loop { continue; }` or `'a loop { continue; }` - (_, None) => true, - // `loop { continue 'a; }` - (None, _) => false, - // `'a loop { continue 'a; }` or `'a loop { continue 'b; }` - (Some(x), Some(y)) => x.ident == y.ident, - } -} - -/// If `expr` is a loop expression (while/while let/for/loop), calls `func` with -/// the AST object representing the loop block of `expr`. -fn with_loop_block(expr: &ast::Expr, mut func: F) -where - F: FnMut(&ast::Block, Option<&ast::Label>), -{ - if let ast::ExprKind::While(_, loop_block, label) - | ast::ExprKind::ForLoop(_, _, loop_block, label) - | ast::ExprKind::Loop(loop_block, label) = &expr.kind - { - func(loop_block, label.as_ref()); - } -} - -/// If `stmt` is an if expression node with an `else` branch, calls func with -/// the -/// following: -/// -/// - The `if` expression itself, -/// - The `if` condition expression, -/// - The `then` block, and -/// - The `else` expression. -fn with_if_expr(stmt: &ast::Stmt, mut func: F) -where - F: FnMut(&ast::Expr, &ast::Expr, &ast::Block, &ast::Expr), -{ - match stmt.kind { - ast::StmtKind::Semi(ref e) | ast::StmtKind::Expr(ref e) => { - if let ast::ExprKind::If(ref cond, ref if_block, Some(ref else_expr)) = e.kind { - func(e, cond, if_block, else_expr); - } - }, - _ => {}, - } -} - -/// A type to distinguish between the two distinct cases this lint handles. -#[derive(Copy, Clone, Debug)] -enum LintType { - ContinueInsideElseBlock, - ContinueInsideThenBlock, -} - -/// Data we pass around for construction of help messages. -struct LintData<'a> { - /// The `if` expression encountered in the above loop. - if_expr: &'a ast::Expr, - /// The condition expression for the above `if`. - if_cond: &'a ast::Expr, - /// The `then` block of the `if` statement. - if_block: &'a ast::Block, - /// The `else` block of the `if` statement. - /// Note that we only work with `if` exprs that have an `else` branch. - else_expr: &'a ast::Expr, - /// The 0-based index of the `if` statement in the containing loop block. - stmt_idx: usize, - /// The statements of the loop block. - block_stmts: &'a [ast::Stmt], -} - -const MSG_REDUNDANT_ELSE_BLOCK: &str = "this `else` block is redundant"; - -const MSG_ELSE_BLOCK_NOT_NEEDED: &str = "there is no need for an explicit `else` block for this `if` \ - expression"; - -const DROP_ELSE_BLOCK_AND_MERGE_MSG: &str = "consider dropping the `else` clause and merging the code that \ - follows (in the loop) with the `if` block"; - -const DROP_ELSE_BLOCK_MSG: &str = "consider dropping the `else` clause"; - -fn emit_warning<'a>(cx: &EarlyContext<'_>, data: &'a LintData<'_>, header: &str, typ: LintType) { - // snip is the whole *help* message that appears after the warning. - // message is the warning message. - // expr is the expression which the lint warning message refers to. - let (snip, message, expr) = match typ { - LintType::ContinueInsideElseBlock => ( - suggestion_snippet_for_continue_inside_else(cx, data), - MSG_REDUNDANT_ELSE_BLOCK, - data.else_expr, - ), - LintType::ContinueInsideThenBlock => ( - suggestion_snippet_for_continue_inside_if(cx, data), - MSG_ELSE_BLOCK_NOT_NEEDED, - data.if_expr, - ), - }; - span_lint_and_help( - cx, - NEEDLESS_CONTINUE, - expr.span, - message, - None, - &format!("{}\n{}", header, snip), - ); -} - -fn suggestion_snippet_for_continue_inside_if<'a>(cx: &EarlyContext<'_>, data: &'a LintData<'_>) -> String { - let cond_code = snippet(cx, data.if_cond.span, ".."); - - let continue_code = snippet_block(cx, data.if_block.span, "..", Some(data.if_expr.span)); - - let else_code = snippet_block(cx, data.else_expr.span, "..", Some(data.if_expr.span)); - - let indent_if = indent_of(cx, data.if_expr.span).unwrap_or(0); - format!( - "{indent}if {} {}\n{indent}{}", - cond_code, - continue_code, - else_code, - indent = " ".repeat(indent_if), - ) -} - -fn suggestion_snippet_for_continue_inside_else<'a>(cx: &EarlyContext<'_>, data: &'a LintData<'_>) -> String { - let cond_code = snippet(cx, data.if_cond.span, ".."); - - // Region B - let block_code = erode_from_back(&snippet_block(cx, data.if_block.span, "..", Some(data.if_expr.span))); - - // Region C - // These is the code in the loop block that follows the if/else construction - // we are complaining about. We want to pull all of this code into the - // `then` block of the `if` statement. - let indent = span_of_first_expr_in_block(data.if_block) - .and_then(|span| indent_of(cx, span)) - .unwrap_or(0); - let to_annex = data.block_stmts[data.stmt_idx + 1..] - .iter() - .map(|stmt| original_sp(stmt.span, DUMMY_SP)) - .map(|span| { - let snip = snippet_block(cx, span, "..", None).into_owned(); - snip.lines() - .map(|line| format!("{}{}", " ".repeat(indent), line)) - .collect::>() - .join("\n") - }) - .collect::>() - .join("\n"); - - let indent_if = indent_of(cx, data.if_expr.span).unwrap_or(0); - format!( - "{indent_if}if {} {}\n{indent}// merged code follows:\n{}\n{indent_if}}}", - cond_code, - block_code, - to_annex, - indent = " ".repeat(indent), - indent_if = " ".repeat(indent_if), - ) -} - -fn check_and_warn<'a>(cx: &EarlyContext<'_>, expr: &'a ast::Expr) { - with_loop_block(expr, |loop_block, label| { - for (i, stmt) in loop_block.stmts.iter().enumerate() { - with_if_expr(stmt, |if_expr, cond, then_block, else_expr| { - let data = &LintData { - stmt_idx: i, - if_expr, - if_cond: cond, - if_block: then_block, - else_expr, - block_stmts: &loop_block.stmts, - }; - if needless_continue_in_else(else_expr, label) { - emit_warning( - cx, - data, - DROP_ELSE_BLOCK_AND_MERGE_MSG, - LintType::ContinueInsideElseBlock, - ); - } else if is_first_block_stmt_continue(then_block, label) { - emit_warning(cx, data, DROP_ELSE_BLOCK_MSG, LintType::ContinueInsideThenBlock); - } - }); - } - }); -} - -/// Eats at `s` from the end till a closing brace `}` is encountered, and then continues eating -/// till a non-whitespace character is found. e.g., the string. If no closing `}` is present, the -/// string will be preserved. -/// -/// ```rust -/// { -/// let x = 5; -/// } -/// ``` -/// -/// is transformed to -/// -/// ```ignore -/// { -/// let x = 5; -/// ``` -#[must_use] -fn erode_from_back(s: &str) -> String { - let mut ret = s.to_string(); - while ret.pop().map_or(false, |c| c != '}') {} - while let Some(c) = ret.pop() { - if !c.is_whitespace() { - ret.push(c); - break; - } - } - if ret.is_empty() { - s.to_string() - } else { - ret - } -} - -fn span_of_first_expr_in_block(block: &ast::Block) -> Option { - block.stmts.get(0).map(|stmt| stmt.span) -} - -#[cfg(test)] -mod test { - use super::erode_from_back; - - #[test] - #[rustfmt::skip] - fn test_erode_from_back() { - let input = "\ -{ - let x = 5; - let y = format!(\"{}\", 42); -}"; - - let expected = "\ -{ - let x = 5; - let y = format!(\"{}\", 42);"; - - let got = erode_from_back(input); - assert_eq!(expected, got); - } - - #[test] - #[rustfmt::skip] - fn test_erode_from_back_no_brace() { - let input = "\ -let x = 5; -let y = something(); -"; - let expected = input; - let got = erode_from_back(input); - assert_eq!(expected, got); - } -} diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs deleted file mode 100644 index 5043b7b1fc3c..000000000000 --- a/clippy_lints/src/needless_pass_by_value.rs +++ /dev/null @@ -1,338 +0,0 @@ -use crate::utils::ptr::get_spans; -use crate::utils::{ - get_trait_def_id, implements_trait, is_copy, is_self, is_type_diagnostic_item, multispan_sugg, paths, snippet, - snippet_opt, span_lint_and_then, -}; -use if_chain::if_chain; -use rustc_ast::ast::Attribute; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_errors::{Applicability, DiagnosticBuilder}; -use rustc_hir::intravisit::FnKind; -use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, ItemKind, Node, PatKind, QPath, TyKind}; -use rustc_infer::infer::TyCtxtInferExt; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, TypeFoldable}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::{sym, Span}; -use rustc_target::spec::abi::Abi; -use rustc_trait_selection::traits; -use rustc_trait_selection::traits::misc::can_type_implement_copy; -use rustc_typeck::expr_use_visitor as euv; -use std::borrow::Cow; - -declare_clippy_lint! { - /// **What it does:** Checks for functions taking arguments by value, but not - /// consuming them in its - /// body. - /// - /// **Why is this bad?** Taking arguments by reference is more flexible and can - /// sometimes avoid - /// unnecessary allocations. - /// - /// **Known problems:** - /// * This lint suggests taking an argument by reference, - /// however sometimes it is better to let users decide the argument type - /// (by using `Borrow` trait, for example), depending on how the function is used. - /// - /// **Example:** - /// ```rust - /// fn foo(v: Vec) { - /// assert_eq!(v.len(), 42); - /// } - /// ``` - /// should be - /// ```rust - /// fn foo(v: &[i32]) { - /// assert_eq!(v.len(), 42); - /// } - /// ``` - pub NEEDLESS_PASS_BY_VALUE, - pedantic, - "functions taking arguments by value, but not consuming them in its body" -} - -declare_lint_pass!(NeedlessPassByValue => [NEEDLESS_PASS_BY_VALUE]); - -macro_rules! need { - ($e: expr) => { - if let Some(x) = $e { - x - } else { - return; - } - }; -} - -impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { - #[allow(clippy::too_many_lines)] - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - kind: FnKind<'tcx>, - decl: &'tcx FnDecl<'_>, - body: &'tcx Body<'_>, - span: Span, - hir_id: HirId, - ) { - if span.from_expansion() { - return; - } - - match kind { - FnKind::ItemFn(.., header, _, attrs) => { - if header.abi != Abi::Rust || requires_exact_signature(attrs) { - return; - } - }, - FnKind::Method(..) => (), - FnKind::Closure(..) => return, - } - - // Exclude non-inherent impls - if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { - if matches!( - item.kind, - ItemKind::Impl { of_trait: Some(_), .. } | ItemKind::Trait(..) - ) { - return; - } - } - - // Allow `Borrow` or functions to be taken by value - let borrow_trait = need!(get_trait_def_id(cx, &paths::BORROW_TRAIT)); - let allowed_traits = [ - need!(cx.tcx.lang_items().fn_trait()), - need!(cx.tcx.lang_items().fn_once_trait()), - need!(cx.tcx.lang_items().fn_mut_trait()), - need!(get_trait_def_id(cx, &paths::RANGE_ARGUMENT_TRAIT)), - ]; - - let sized_trait = need!(cx.tcx.lang_items().sized_trait()); - - let fn_def_id = cx.tcx.hir().local_def_id(hir_id); - - let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds().iter()) - .filter(|p| !p.is_global()) - .filter_map(|obligation| { - // Note that we do not want to deal with qualified predicates here. - if let ty::PredicateKind::Atom(ty::PredicateAtom::Trait(pred, _)) = obligation.predicate.kind() { - if pred.def_id() == sized_trait { - return None; - } - Some(pred) - } else { - None - } - }) - .collect::>(); - - // Collect moved variables and spans which will need dereferencings from the - // function body. - let MovedVariablesCtxt { - moved_vars, - spans_need_deref, - .. - } = { - let mut ctx = MovedVariablesCtxt::default(); - cx.tcx.infer_ctxt().enter(|infcx| { - euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()) - .consume_body(body); - }); - ctx - }; - - let fn_sig = cx.tcx.fn_sig(fn_def_id); - let fn_sig = cx.tcx.erase_late_bound_regions(fn_sig); - - for (idx, ((input, &ty), arg)) in decl.inputs.iter().zip(fn_sig.inputs()).zip(body.params).enumerate() { - // All spans generated from a proc-macro invocation are the same... - if span == input.span { - return; - } - - // Ignore `self`s. - if idx == 0 { - if let PatKind::Binding(.., ident, _) = arg.pat.kind { - if ident.as_str() == "self" { - continue; - } - } - } - - // - // * Exclude a type that is specifically bounded by `Borrow`. - // * Exclude a type whose reference also fulfills its bound. (e.g., `std::convert::AsRef`, - // `serde::Serialize`) - let (implements_borrow_trait, all_borrowable_trait) = { - let preds = preds.iter().filter(|t| t.self_ty() == ty).collect::>(); - - ( - preds.iter().any(|t| t.def_id() == borrow_trait), - !preds.is_empty() && { - let ty_empty_region = cx.tcx.mk_imm_ref(cx.tcx.lifetimes.re_root_empty, ty); - preds.iter().all(|t| { - let ty_params = t.trait_ref.substs.iter().skip(1).collect::>(); - implements_trait(cx, ty_empty_region, t.def_id(), &ty_params) - }) - }, - ) - }; - - if_chain! { - if !is_self(arg); - if !ty.is_mutable_ptr(); - if !is_copy(cx, ty); - if !allowed_traits.iter().any(|&t| implements_trait(cx, ty, t, &[])); - if !implements_borrow_trait; - if !all_borrowable_trait; - - if let PatKind::Binding(mode, canonical_id, ..) = arg.pat.kind; - if !moved_vars.contains(&canonical_id); - then { - if mode == BindingAnnotation::Mutable || mode == BindingAnnotation::RefMut { - continue; - } - - // Dereference suggestion - let sugg = |diag: &mut DiagnosticBuilder<'_>| { - if let ty::Adt(def, ..) = ty.kind() { - if let Some(span) = cx.tcx.hir().span_if_local(def.did) { - if can_type_implement_copy(cx.tcx, cx.param_env, ty).is_ok() { - diag.span_help(span, "consider marking this type as `Copy`"); - } - } - } - - let deref_span = spans_need_deref.get(&canonical_id); - if_chain! { - if is_type_diagnostic_item(cx, ty, sym::vec_type); - if let Some(clone_spans) = - get_spans(cx, Some(body.id()), idx, &[("clone", ".to_owned()")]); - if let TyKind::Path(QPath::Resolved(_, ref path)) = input.kind; - if let Some(elem_ty) = path.segments.iter() - .find(|seg| seg.ident.name == sym::Vec) - .and_then(|ps| ps.args.as_ref()) - .map(|params| params.args.iter().find_map(|arg| match arg { - GenericArg::Type(ty) => Some(ty), - _ => None, - }).unwrap()); - then { - let slice_ty = format!("&[{}]", snippet(cx, elem_ty.span, "_")); - diag.span_suggestion( - input.span, - "consider changing the type to", - slice_ty, - Applicability::Unspecified, - ); - - for (span, suggestion) in clone_spans { - diag.span_suggestion( - span, - &snippet_opt(cx, span) - .map_or( - "change the call to".into(), - |x| Cow::from(format!("change `{}` to", x)), - ), - suggestion.into(), - Applicability::Unspecified, - ); - } - - // cannot be destructured, no need for `*` suggestion - assert!(deref_span.is_none()); - return; - } - } - - if is_type_diagnostic_item(cx, ty, sym::string_type) { - if let Some(clone_spans) = - get_spans(cx, Some(body.id()), idx, &[("clone", ".to_string()"), ("as_str", "")]) { - diag.span_suggestion( - input.span, - "consider changing the type to", - "&str".to_string(), - Applicability::Unspecified, - ); - - for (span, suggestion) in clone_spans { - diag.span_suggestion( - span, - &snippet_opt(cx, span) - .map_or( - "change the call to".into(), - |x| Cow::from(format!("change `{}` to", x)) - ), - suggestion.into(), - Applicability::Unspecified, - ); - } - - assert!(deref_span.is_none()); - return; - } - } - - let mut spans = vec![(input.span, format!("&{}", snippet(cx, input.span, "_")))]; - - // Suggests adding `*` to dereference the added reference. - if let Some(deref_span) = deref_span { - spans.extend( - deref_span - .iter() - .cloned() - .map(|span| (span, format!("*{}", snippet(cx, span, "")))), - ); - spans.sort_by_key(|&(span, _)| span); - } - multispan_sugg(diag, "consider taking a reference instead", spans); - }; - - span_lint_and_then( - cx, - NEEDLESS_PASS_BY_VALUE, - input.span, - "this argument is passed by value, but not consumed in the function body", - sugg, - ); - } - } - } - } -} - -/// Functions marked with these attributes must have the exact signature. -fn requires_exact_signature(attrs: &[Attribute]) -> bool { - attrs.iter().any(|attr| { - [sym::proc_macro, sym::proc_macro_attribute, sym::proc_macro_derive] - .iter() - .any(|&allow| attr.has_name(allow)) - }) -} - -#[derive(Default)] -struct MovedVariablesCtxt { - moved_vars: FxHashSet, - /// Spans which need to be prefixed with `*` for dereferencing the - /// suggested additional reference. - spans_need_deref: FxHashMap>, -} - -impl MovedVariablesCtxt { - fn move_common(&mut self, cmt: &euv::PlaceWithHirId<'_>) { - if let euv::PlaceBase::Local(vid) = cmt.place.base { - self.moved_vars.insert(vid); - } - } -} - -impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt { - fn consume(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, _: HirId, mode: euv::ConsumeMode) { - if let euv::ConsumeMode::Move = mode { - self.move_common(cmt); - } - } - - fn borrow(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {} - - fn mutate(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId) {} -} diff --git a/clippy_lints/src/needless_update.rs b/clippy_lints/src/needless_update.rs deleted file mode 100644 index 41cf541ecf5e..000000000000 --- a/clippy_lints/src/needless_update.rs +++ /dev/null @@ -1,68 +0,0 @@ -use crate::utils::span_lint; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for needlessly including a base struct on update - /// when all fields are changed anyway. - /// - /// This lint is not applied to structs marked with - /// [non_exhaustive](https://doc.rust-lang.org/reference/attributes/type_system.html). - /// - /// **Why is this bad?** This will cost resources (because the base has to be - /// somewhere), and make the code less readable. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # struct Point { - /// # x: i32, - /// # y: i32, - /// # z: i32, - /// # } - /// # let zero_point = Point { x: 0, y: 0, z: 0 }; - /// - /// // Bad - /// Point { - /// x: 1, - /// y: 1, - /// z: 1, - /// ..zero_point - /// }; - /// - /// // Ok - /// Point { - /// x: 1, - /// y: 1, - /// ..zero_point - /// }; - /// ``` - pub NEEDLESS_UPDATE, - complexity, - "using `Foo { ..base }` when there are no missing fields" -} - -declare_lint_pass!(NeedlessUpdate => [NEEDLESS_UPDATE]); - -impl<'tcx> LateLintPass<'tcx> for NeedlessUpdate { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Struct(_, ref fields, Some(ref base)) = expr.kind { - let ty = cx.typeck_results().expr_ty(expr); - if let ty::Adt(def, _) = ty.kind() { - if fields.len() == def.non_enum_variant().fields.len() - && !def.variants[0_usize.into()].is_field_list_non_exhaustive() - { - span_lint( - cx, - NEEDLESS_UPDATE, - base.span, - "struct update has no effect, all the fields in the struct have already been specified", - ); - } - } - } - } -} diff --git a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs deleted file mode 100644 index 4fb899125e8a..000000000000 --- a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ /dev/null @@ -1,91 +0,0 @@ -use if_chain::if_chain; -use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -use crate::utils::{self, paths, span_lint}; - -declare_clippy_lint! { - /// **What it does:** - /// Checks for the usage of negated comparison operators on types which only implement - /// `PartialOrd` (e.g., `f64`). - /// - /// **Why is this bad?** - /// These operators make it easy to forget that the underlying types actually allow not only three - /// potential Orderings (Less, Equal, Greater) but also a fourth one (Uncomparable). This is - /// especially easy to miss if the operator based comparison result is negated. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// use std::cmp::Ordering; - /// - /// // Bad - /// let a = 1.0; - /// let b = f64::NAN; - /// - /// let _not_less_or_equal = !(a <= b); - /// - /// // Good - /// let a = 1.0; - /// let b = f64::NAN; - /// - /// let _not_less_or_equal = match a.partial_cmp(&b) { - /// None | Some(Ordering::Greater) => true, - /// _ => false, - /// }; - /// ``` - pub NEG_CMP_OP_ON_PARTIAL_ORD, - complexity, - "The use of negated comparison operators on partially ordered types may produce confusing code." -} - -declare_lint_pass!(NoNegCompOpForPartialOrd => [NEG_CMP_OP_ON_PARTIAL_ORD]); - -impl<'tcx> LateLintPass<'tcx> for NoNegCompOpForPartialOrd { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if_chain! { - - if !in_external_macro(cx.sess(), expr.span); - if let ExprKind::Unary(UnOp::UnNot, ref inner) = expr.kind; - if let ExprKind::Binary(ref op, ref left, _) = inner.kind; - if let BinOpKind::Le | BinOpKind::Ge | BinOpKind::Lt | BinOpKind::Gt = op.node; - - then { - - let ty = cx.typeck_results().expr_ty(left); - - let implements_ord = { - if let Some(id) = utils::get_trait_def_id(cx, &paths::ORD) { - utils::implements_trait(cx, ty, id, &[]) - } else { - return; - } - }; - - let implements_partial_ord = { - if let Some(id) = cx.tcx.lang_items().partial_ord_trait() { - utils::implements_trait(cx, ty, id, &[]) - } else { - return; - } - }; - - if implements_partial_ord && !implements_ord { - span_lint( - cx, - NEG_CMP_OP_ON_PARTIAL_ORD, - expr.span, - "the use of negated comparison operators on partially ordered \ - types produces code that is hard to read and refactor, please \ - consider using the `partial_cmp` method instead, to make it \ - clear that the two values could be incomparable" - ) - } - } - } - } -} diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs deleted file mode 100644 index aa550510867f..000000000000 --- a/clippy_lints/src/neg_multiply.rs +++ /dev/null @@ -1,53 +0,0 @@ -use if_chain::if_chain; -use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; - -use crate::consts::{self, Constant}; -use crate::utils::span_lint; - -declare_clippy_lint! { - /// **What it does:** Checks for multiplication by -1 as a form of negation. - /// - /// **Why is this bad?** It's more readable to just negate. - /// - /// **Known problems:** This only catches integers (for now). - /// - /// **Example:** - /// ```ignore - /// x * -1 - /// ``` - pub NEG_MULTIPLY, - style, - "multiplying integers with `-1`" -} - -declare_lint_pass!(NegMultiply => [NEG_MULTIPLY]); - -#[allow(clippy::match_same_arms)] -impl<'tcx> LateLintPass<'tcx> for NegMultiply { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if let ExprKind::Binary(ref op, ref left, ref right) = e.kind { - if BinOpKind::Mul == op.node { - match (&left.kind, &right.kind) { - (&ExprKind::Unary(..), &ExprKind::Unary(..)) => {}, - (&ExprKind::Unary(UnOp::UnNeg, ref lit), _) => check_mul(cx, e.span, lit, right), - (_, &ExprKind::Unary(UnOp::UnNeg, ref lit)) => check_mul(cx, e.span, lit, left), - _ => {}, - } - } - } - } -} - -fn check_mul(cx: &LateContext<'_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_>) { - if_chain! { - if let ExprKind::Lit(ref l) = lit.kind; - if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.typeck_results().expr_ty_opt(lit)); - if cx.typeck_results().expr_ty(exp).is_integral(); - then { - span_lint(cx, NEG_MULTIPLY, span, "negation by multiplying with `-1`"); - } - } -} diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs deleted file mode 100644 index 68fdd0eb269e..000000000000 --- a/clippy_lints/src/new_without_default.rs +++ /dev/null @@ -1,165 +0,0 @@ -use crate::utils::paths; -use crate::utils::sugg::DiagnosticBuilderExt; -use crate::utils::{get_trait_def_id, return_ty, span_lint_hir_and_then}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_hir::HirIdSet; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{Ty, TyS}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** Checks for types with a `fn new() -> Self` method and no - /// implementation of - /// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html). - /// - /// **Why is this bad?** The user might expect to be able to use - /// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html) as the - /// type can be constructed without arguments. - /// - /// **Known problems:** Hopefully none. - /// - /// **Example:** - /// - /// ```ignore - /// struct Foo(Bar); - /// - /// impl Foo { - /// fn new() -> Self { - /// Foo(Bar::new()) - /// } - /// } - /// ``` - /// - /// To fix the lint, add a `Default` implementation that delegates to `new`: - /// - /// ```ignore - /// struct Foo(Bar); - /// - /// impl Default for Foo { - /// fn default() -> Self { - /// Foo::new() - /// } - /// } - /// ``` - pub NEW_WITHOUT_DEFAULT, - style, - "`fn new() -> Self` method without `Default` implementation" -} - -#[derive(Clone, Default)] -pub struct NewWithoutDefault { - impling_types: Option, -} - -impl_lint_pass!(NewWithoutDefault => [NEW_WITHOUT_DEFAULT]); - -impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { - #[allow(clippy::too_many_lines)] - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { - if let hir::ItemKind::Impl { - of_trait: None, items, .. - } = item.kind - { - for assoc_item in items { - if let hir::AssocItemKind::Fn { has_self: false } = assoc_item.kind { - let impl_item = cx.tcx.hir().impl_item(assoc_item.id); - if in_external_macro(cx.sess(), impl_item.span) { - return; - } - if let hir::ImplItemKind::Fn(ref sig, _) = impl_item.kind { - let name = impl_item.ident.name; - let id = impl_item.hir_id; - if sig.header.constness == hir::Constness::Const { - // can't be implemented by default - return; - } - if sig.header.unsafety == hir::Unsafety::Unsafe { - // can't be implemented for unsafe new - return; - } - if impl_item - .generics - .params - .iter() - .any(|gen| matches!(gen.kind, hir::GenericParamKind::Type { .. })) - { - // when the result of `new()` depends on a type parameter we should not require - // an - // impl of `Default` - return; - } - if sig.decl.inputs.is_empty() && name == sym::new && cx.access_levels.is_reachable(id) { - let self_def_id = cx.tcx.hir().local_def_id(cx.tcx.hir().get_parent_item(id)); - let self_ty = cx.tcx.type_of(self_def_id); - if_chain! { - if TyS::same_type(self_ty, return_ty(cx, id)); - if let Some(default_trait_id) = get_trait_def_id(cx, &paths::DEFAULT_TRAIT); - then { - if self.impling_types.is_none() { - let mut impls = HirIdSet::default(); - cx.tcx.for_each_impl(default_trait_id, |d| { - if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() { - if let Some(local_def_id) = ty_def.did.as_local() { - impls.insert(cx.tcx.hir().local_def_id_to_hir_id(local_def_id)); - } - } - }); - self.impling_types = Some(impls); - } - - // Check if a Default implementation exists for the Self type, regardless of - // generics - if_chain! { - if let Some(ref impling_types) = self.impling_types; - if let Some(self_def) = cx.tcx.type_of(self_def_id).ty_adt_def(); - if let Some(self_local_did) = self_def.did.as_local(); - then { - let self_id = cx.tcx.hir().local_def_id_to_hir_id(self_local_did); - if impling_types.contains(&self_id) { - return; - } - } - } - - span_lint_hir_and_then( - cx, - NEW_WITHOUT_DEFAULT, - id, - impl_item.span, - &format!( - "you should consider adding a `Default` implementation for `{}`", - self_ty - ), - |diag| { - diag.suggest_prepend_item( - cx, - item.span, - "try this", - &create_new_without_default_suggest_msg(self_ty), - Applicability::MaybeIncorrect, - ); - }, - ); - } - } - } - } - } - } - } - } -} - -fn create_new_without_default_suggest_msg(ty: Ty<'_>) -> String { - #[rustfmt::skip] - format!( -"impl Default for {} {{ - fn default() -> Self {{ - Self::new() - }} -}}", ty) -} diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs deleted file mode 100644 index b1b5b3439a0e..000000000000 --- a/clippy_lints/src/no_effect.rs +++ /dev/null @@ -1,178 +0,0 @@ -use crate::utils::{has_drop, qpath_res, snippet_opt, span_lint, span_lint_and_sugg}; -use rustc_errors::Applicability; -use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{BinOpKind, BlockCheckMode, Expr, ExprKind, Stmt, StmtKind, UnsafeSource}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use std::ops::Deref; - -declare_clippy_lint! { - /// **What it does:** Checks for statements which have no effect. - /// - /// **Why is this bad?** Similar to dead code, these statements are actually - /// executed. However, as they have no effect, all they do is make the code less - /// readable. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// 0; - /// ``` - pub NO_EFFECT, - complexity, - "statements with no effect" -} - -declare_clippy_lint! { - /// **What it does:** Checks for expression statements that can be reduced to a - /// sub-expression. - /// - /// **Why is this bad?** Expressions by themselves often have no side-effects. - /// Having such expressions reduces readability. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// compute_array()[0]; - /// ``` - pub UNNECESSARY_OPERATION, - complexity, - "outer expressions with no effect" -} - -fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - if expr.span.from_expansion() { - return false; - } - match expr.kind { - ExprKind::Lit(..) | ExprKind::Closure(..) => true, - ExprKind::Path(..) => !has_drop(cx, cx.typeck_results().expr_ty(expr)), - ExprKind::Index(ref a, ref b) | ExprKind::Binary(_, ref a, ref b) => { - has_no_effect(cx, a) && has_no_effect(cx, b) - }, - ExprKind::Array(ref v) | ExprKind::Tup(ref v) => v.iter().all(|val| has_no_effect(cx, val)), - ExprKind::Repeat(ref inner, _) - | ExprKind::Cast(ref inner, _) - | ExprKind::Type(ref inner, _) - | ExprKind::Unary(_, ref inner) - | ExprKind::Field(ref inner, _) - | ExprKind::AddrOf(_, _, ref inner) - | ExprKind::Box(ref inner) => has_no_effect(cx, inner), - ExprKind::Struct(_, ref fields, ref base) => { - !has_drop(cx, cx.typeck_results().expr_ty(expr)) - && fields.iter().all(|field| has_no_effect(cx, &field.expr)) - && base.as_ref().map_or(true, |base| has_no_effect(cx, base)) - }, - ExprKind::Call(ref callee, ref args) => { - if let ExprKind::Path(ref qpath) = callee.kind { - let res = qpath_res(cx, qpath, callee.hir_id); - match res { - Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..) => { - !has_drop(cx, cx.typeck_results().expr_ty(expr)) - && args.iter().all(|arg| has_no_effect(cx, arg)) - }, - _ => false, - } - } else { - false - } - }, - ExprKind::Block(ref block, _) => { - block.stmts.is_empty() && block.expr.as_ref().map_or(false, |expr| has_no_effect(cx, expr)) - }, - _ => false, - } -} - -declare_lint_pass!(NoEffect => [NO_EFFECT, UNNECESSARY_OPERATION]); - -impl<'tcx> LateLintPass<'tcx> for NoEffect { - fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { - if let StmtKind::Semi(ref expr) = stmt.kind { - if has_no_effect(cx, expr) { - span_lint(cx, NO_EFFECT, stmt.span, "statement with no effect"); - } else if let Some(reduced) = reduce_expression(cx, expr) { - let mut snippet = String::new(); - for e in reduced { - if e.span.from_expansion() { - return; - } - if let Some(snip) = snippet_opt(cx, e.span) { - snippet.push_str(&snip); - snippet.push(';'); - } else { - return; - } - } - span_lint_and_sugg( - cx, - UNNECESSARY_OPERATION, - stmt.span, - "statement can be reduced", - "replace it with", - snippet, - Applicability::MachineApplicable, - ); - } - } - } -} - -fn reduce_expression<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option>> { - if expr.span.from_expansion() { - return None; - } - match expr.kind { - ExprKind::Index(ref a, ref b) => Some(vec![&**a, &**b]), - ExprKind::Binary(ref binop, ref a, ref b) if binop.node != BinOpKind::And && binop.node != BinOpKind::Or => { - Some(vec![&**a, &**b]) - }, - ExprKind::Array(ref v) | ExprKind::Tup(ref v) => Some(v.iter().collect()), - ExprKind::Repeat(ref inner, _) - | ExprKind::Cast(ref inner, _) - | ExprKind::Type(ref inner, _) - | ExprKind::Unary(_, ref inner) - | ExprKind::Field(ref inner, _) - | ExprKind::AddrOf(_, _, ref inner) - | ExprKind::Box(ref inner) => reduce_expression(cx, inner).or_else(|| Some(vec![inner])), - ExprKind::Struct(_, ref fields, ref base) => { - if has_drop(cx, cx.typeck_results().expr_ty(expr)) { - None - } else { - Some(fields.iter().map(|f| &f.expr).chain(base).map(Deref::deref).collect()) - } - }, - ExprKind::Call(ref callee, ref args) => { - if let ExprKind::Path(ref qpath) = callee.kind { - let res = qpath_res(cx, qpath, callee.hir_id); - match res { - Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..) - if !has_drop(cx, cx.typeck_results().expr_ty(expr)) => - { - Some(args.iter().collect()) - }, - _ => None, - } - } else { - None - } - }, - ExprKind::Block(ref block, _) => { - if block.stmts.is_empty() { - block.expr.as_ref().and_then(|e| { - match block.rules { - BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) => None, - BlockCheckMode::DefaultBlock => Some(vec![&**e]), - // in case of compiler-inserted signaling blocks - _ => reduce_expression(cx, e), - } - }) - } else { - None - } - }, - _ => None, - } -} diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs deleted file mode 100644 index 6b0d198edcff..000000000000 --- a/clippy_lints/src/non_copy_const.rs +++ /dev/null @@ -1,425 +0,0 @@ -//! Checks for uses of const which the type is not `Freeze` (`Cell`-free). -//! -//! This lint is **warn** by default. - -use std::ptr; - -use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::DefId; -use rustc_hir::{ - BodyId, Expr, ExprKind, HirId, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind, UnOp, -}; -use rustc_infer::traits::specialization_graph; -use rustc_lint::{LateContext, LateLintPass, Lint}; -use rustc_middle::mir::interpret::{ConstValue, ErrorHandled}; -use rustc_middle::ty::adjustment::Adjust; -use rustc_middle::ty::{self, AssocKind, Const, Ty}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::{InnerSpan, Span, DUMMY_SP}; -use rustc_typeck::hir_ty_to_ty; - -use crate::utils::{in_constant, qpath_res, span_lint_and_then}; -use if_chain::if_chain; - -// FIXME: this is a correctness problem but there's no suitable -// warn-by-default category. -declare_clippy_lint! { - /// **What it does:** Checks for declaration of `const` items which is interior - /// mutable (e.g., contains a `Cell`, `Mutex`, `AtomicXxxx`, etc.). - /// - /// **Why is this bad?** Consts are copied everywhere they are referenced, i.e., - /// every time you refer to the const a fresh instance of the `Cell` or `Mutex` - /// or `AtomicXxxx` will be created, which defeats the whole purpose of using - /// these types in the first place. - /// - /// The `const` should better be replaced by a `static` item if a global - /// variable is wanted, or replaced by a `const fn` if a constructor is wanted. - /// - /// **Known problems:** A "non-constant" const item is a legacy way to supply an - /// initialized value to downstream `static` items (e.g., the - /// `std::sync::ONCE_INIT` constant). In this case the use of `const` is legit, - /// and this lint should be suppressed. - /// - /// Even though the lint avoids triggering on a constant whose type has enums that have variants - /// with interior mutability, and its value uses non interior mutable variants (see - /// [#3962](https://github.com/rust-lang/rust-clippy/issues/3962) and - /// [#3825](https://github.com/rust-lang/rust-clippy/issues/3825) for examples); - /// it complains about associated constants without default values only based on its types; - /// which might not be preferable. - /// There're other enums plus associated constants cases that the lint cannot handle. - /// - /// Types that have underlying or potential interior mutability trigger the lint whether - /// the interior mutable field is used or not. See issues - /// [#5812](https://github.com/rust-lang/rust-clippy/issues/5812) and - /// - /// **Example:** - /// ```rust - /// use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; - /// - /// // Bad. - /// const CONST_ATOM: AtomicUsize = AtomicUsize::new(12); - /// CONST_ATOM.store(6, SeqCst); // the content of the atomic is unchanged - /// assert_eq!(CONST_ATOM.load(SeqCst), 12); // because the CONST_ATOM in these lines are distinct - /// - /// // Good. - /// static STATIC_ATOM: AtomicUsize = AtomicUsize::new(15); - /// STATIC_ATOM.store(9, SeqCst); - /// assert_eq!(STATIC_ATOM.load(SeqCst), 9); // use a `static` item to refer to the same instance - /// ``` - pub DECLARE_INTERIOR_MUTABLE_CONST, - style, - "declaring `const` with interior mutability" -} - -// FIXME: this is a correctness problem but there's no suitable -// warn-by-default category. -declare_clippy_lint! { - /// **What it does:** Checks if `const` items which is interior mutable (e.g., - /// contains a `Cell`, `Mutex`, `AtomicXxxx`, etc.) has been borrowed directly. - /// - /// **Why is this bad?** Consts are copied everywhere they are referenced, i.e., - /// every time you refer to the const a fresh instance of the `Cell` or `Mutex` - /// or `AtomicXxxx` will be created, which defeats the whole purpose of using - /// these types in the first place. - /// - /// The `const` value should be stored inside a `static` item. - /// - /// **Known problems:** When an enum has variants with interior mutability, use of its non - /// interior mutable variants can generate false positives. See issue - /// [#3962](https://github.com/rust-lang/rust-clippy/issues/3962) - /// - /// Types that have underlying or potential interior mutability trigger the lint whether - /// the interior mutable field is used or not. See issues - /// [#5812](https://github.com/rust-lang/rust-clippy/issues/5812) and - /// [#3825](https://github.com/rust-lang/rust-clippy/issues/3825) - /// - /// **Example:** - /// ```rust - /// use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; - /// const CONST_ATOM: AtomicUsize = AtomicUsize::new(12); - /// - /// // Bad. - /// CONST_ATOM.store(6, SeqCst); // the content of the atomic is unchanged - /// assert_eq!(CONST_ATOM.load(SeqCst), 12); // because the CONST_ATOM in these lines are distinct - /// - /// // Good. - /// static STATIC_ATOM: AtomicUsize = CONST_ATOM; - /// STATIC_ATOM.store(9, SeqCst); - /// assert_eq!(STATIC_ATOM.load(SeqCst), 9); // use a `static` item to refer to the same instance - /// ``` - pub BORROW_INTERIOR_MUTABLE_CONST, - style, - "referencing `const` with interior mutability" -} - -fn is_unfrozen<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { - // Ignore types whose layout is unknown since `is_freeze` reports every generic types as `!Freeze`, - // making it indistinguishable from `UnsafeCell`. i.e. it isn't a tool to prove a type is - // 'unfrozen'. However, this code causes a false negative in which - // a type contains a layout-unknown type, but also a unsafe cell like `const CELL: Cell`. - // Yet, it's better than `ty.has_type_flags(TypeFlags::HAS_TY_PARAM | TypeFlags::HAS_PROJECTION)` - // since it works when a pointer indirection involves (`Cell<*const T>`). - // Making up a `ParamEnv` where every generic params and assoc types are `Freeze`is another option; - // but I'm not sure whether it's a decent way, if possible. - cx.tcx.layout_of(cx.param_env.and(ty)).is_ok() && !ty.is_freeze(cx.tcx.at(DUMMY_SP), cx.param_env) -} - -fn is_value_unfrozen_raw<'tcx>( - cx: &LateContext<'tcx>, - result: Result, ErrorHandled>, - ty: Ty<'tcx>, -) -> bool { - fn inner<'tcx>(cx: &LateContext<'tcx>, val: &'tcx Const<'tcx>) -> bool { - match val.ty.kind() { - // the fact that we have to dig into every structs to search enums - // leads us to the point checking `UnsafeCell` directly is the only option. - ty::Adt(ty_def, ..) if Some(ty_def.did) == cx.tcx.lang_items().unsafe_cell_type() => true, - ty::Array(..) | ty::Adt(..) | ty::Tuple(..) => { - let val = cx.tcx.destructure_const(cx.param_env.and(val)); - val.fields.iter().any(|field| inner(cx, field)) - }, - _ => false, - } - } - - result.map_or_else( - |err| { - // Consider `TooGeneric` cases as being unfrozen. - // This causes a false positive where an assoc const whose type is unfrozen - // have a value that is a frozen variant with a generic param (an example is - // `declare_interior_mutable_const::enums::BothOfCellAndGeneric::GENERIC_VARIANT`). - // However, it prevents a number of false negatives that is, I think, important: - // 1. assoc consts in trait defs referring to consts of themselves - // (an example is `declare_interior_mutable_const::traits::ConcreteTypes::ANOTHER_ATOMIC`). - // 2. a path expr referring to assoc consts whose type is doesn't have - // any frozen variants in trait defs (i.e. without substitute for `Self`). - // (e.g. borrowing `borrow_interior_mutable_const::trait::ConcreteTypes::ATOMIC`) - // 3. similar to the false positive above; - // but the value is an unfrozen variant, or the type has no enums. (An example is - // `declare_interior_mutable_const::enums::BothOfCellAndGeneric::UNFROZEN_VARIANT` - // and `declare_interior_mutable_const::enums::BothOfCellAndGeneric::NO_ENUM`). - // One might be able to prevent these FNs correctly, and replace this with `false`; - // e.g. implementing `has_frozen_variant` described above, and not running this function - // when the type doesn't have any frozen variants would be the 'correct' way for the 2nd - // case (that actually removes another suboptimal behavior (I won't say 'false positive') where, - // similar to 2., but with the a frozen variant) (e.g. borrowing - // `borrow_interior_mutable_const::enums::AssocConsts::TO_BE_FROZEN_VARIANT`). - // I chose this way because unfrozen enums as assoc consts are rare (or, hopefully, none). - err == ErrorHandled::TooGeneric - }, - |val| inner(cx, Const::from_value(cx.tcx, val, ty)), - ) -} - -fn is_value_unfrozen_poly<'tcx>(cx: &LateContext<'tcx>, body_id: BodyId, ty: Ty<'tcx>) -> bool { - let result = cx.tcx.const_eval_poly(body_id.hir_id.owner.to_def_id()); - is_value_unfrozen_raw(cx, result, ty) -} - -fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: DefId, ty: Ty<'tcx>) -> bool { - let substs = cx.typeck_results().node_substs(hir_id); - - let result = cx - .tcx - .const_eval_resolve(cx.param_env, ty::WithOptConstParam::unknown(def_id), substs, None, None); - is_value_unfrozen_raw(cx, result, ty) -} - -#[derive(Copy, Clone)] -enum Source { - Item { item: Span }, - Assoc { item: Span }, - Expr { expr: Span }, -} - -impl Source { - #[must_use] - fn lint(&self) -> (&'static Lint, &'static str, Span) { - match self { - Self::Item { item } | Self::Assoc { item, .. } => ( - DECLARE_INTERIOR_MUTABLE_CONST, - "a `const` item should never be interior mutable", - *item, - ), - Self::Expr { expr } => ( - BORROW_INTERIOR_MUTABLE_CONST, - "a `const` item with interior mutability should not be borrowed", - *expr, - ), - } - } -} - -fn lint(cx: &LateContext<'_>, source: Source) { - let (lint, msg, span) = source.lint(); - span_lint_and_then(cx, lint, span, msg, |diag| { - if span.from_expansion() { - return; // Don't give suggestions into macros. - } - match source { - Source::Item { .. } => { - let const_kw_span = span.from_inner(InnerSpan::new(0, 5)); - diag.span_label(const_kw_span, "make this a static item (maybe with lazy_static)"); - }, - Source::Assoc { .. } => (), - Source::Expr { .. } => { - diag.help("assign this const to a local or static variable, and use the variable here"); - }, - } - }); -} - -declare_lint_pass!(NonCopyConst => [DECLARE_INTERIOR_MUTABLE_CONST, BORROW_INTERIOR_MUTABLE_CONST]); - -impl<'tcx> LateLintPass<'tcx> for NonCopyConst { - fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx Item<'_>) { - if let ItemKind::Const(hir_ty, body_id) = it.kind { - let ty = hir_ty_to_ty(cx.tcx, hir_ty); - - if is_unfrozen(cx, ty) && is_value_unfrozen_poly(cx, body_id, ty) { - lint(cx, Source::Item { item: it.span }); - } - } - } - - fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx TraitItem<'_>) { - if let TraitItemKind::Const(hir_ty, body_id_opt) = &trait_item.kind { - let ty = hir_ty_to_ty(cx.tcx, hir_ty); - - // Normalize assoc types because ones originated from generic params - // bounded other traits could have their bound. - let normalized = cx.tcx.normalize_erasing_regions(cx.param_env, ty); - if is_unfrozen(cx, normalized) - // When there's no default value, lint it only according to its type; - // in other words, lint consts whose value *could* be unfrozen, not definitely is. - // This feels inconsistent with how the lint treats generic types, - // which avoids linting types which potentially become unfrozen. - // One could check whether a unfrozen type have a *frozen variant* - // (like `body_id_opt.map_or_else(|| !has_frozen_variant(...), ...)`), - // and do the same as the case of generic types at impl items. - // Note that it isn't sufficient to check if it has an enum - // since all of that enum's variants can be unfrozen: - // i.e. having an enum doesn't necessary mean a type has a frozen variant. - // And, implementing it isn't a trivial task; it'll probably end up - // re-implementing the trait predicate evaluation specific to `Freeze`. - && body_id_opt.map_or(true, |body_id| is_value_unfrozen_poly(cx, body_id, normalized)) - { - lint(cx, Source::Assoc { item: trait_item.span }); - } - } - } - - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { - if let ImplItemKind::Const(hir_ty, body_id) = &impl_item.kind { - let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id); - let item = cx.tcx.hir().expect_item(item_hir_id); - - match &item.kind { - ItemKind::Impl { - of_trait: Some(of_trait_ref), - .. - } => { - if_chain! { - // Lint a trait impl item only when the definition is a generic type, - // assuming a assoc const is not meant to be a interior mutable type. - if let Some(of_trait_def_id) = of_trait_ref.trait_def_id(); - if let Some(of_assoc_item) = specialization_graph::Node::Trait(of_trait_def_id) - .item(cx.tcx, impl_item.ident, AssocKind::Const, of_trait_def_id); - if cx - .tcx - .layout_of(cx.tcx.param_env(of_trait_def_id).and( - // Normalize assoc types because ones originated from generic params - // bounded other traits could have their bound at the trait defs; - // and, in that case, the definition is *not* generic. - cx.tcx.normalize_erasing_regions( - cx.tcx.param_env(of_trait_def_id), - cx.tcx.type_of(of_assoc_item.def_id), - ), - )) - .is_err(); - // If there were a function like `has_frozen_variant` described above, - // we should use here as a frozen variant is a potential to be frozen - // similar to unknown layouts. - // e.g. `layout_of(...).is_err() || has_frozen_variant(...);` - then { - let ty = hir_ty_to_ty(cx.tcx, hir_ty); - let normalized = cx.tcx.normalize_erasing_regions(cx.param_env, ty); - if is_unfrozen(cx, normalized) - && is_value_unfrozen_poly(cx, *body_id, normalized) - { - lint( - cx, - Source::Assoc { - item: impl_item.span, - }, - ); - } - } - } - }, - ItemKind::Impl { of_trait: None, .. } => { - let ty = hir_ty_to_ty(cx.tcx, hir_ty); - // Normalize assoc types originated from generic params. - let normalized = cx.tcx.normalize_erasing_regions(cx.param_env, ty); - - if is_unfrozen(cx, ty) && is_value_unfrozen_poly(cx, *body_id, normalized) { - lint(cx, Source::Assoc { item: impl_item.span }); - } - }, - _ => (), - } - } - } - - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Path(qpath) = &expr.kind { - // Only lint if we use the const item inside a function. - if in_constant(cx, expr.hir_id) { - return; - } - - // Make sure it is a const item. - let item_def_id = match qpath_res(cx, qpath, expr.hir_id) { - Res::Def(DefKind::Const | DefKind::AssocConst, did) => did, - _ => return, - }; - - // Climb up to resolve any field access and explicit referencing. - let mut cur_expr = expr; - let mut dereferenced_expr = expr; - let mut needs_check_adjustment = true; - loop { - let parent_id = cx.tcx.hir().get_parent_node(cur_expr.hir_id); - if parent_id == cur_expr.hir_id { - break; - } - if let Some(Node::Expr(parent_expr)) = cx.tcx.hir().find(parent_id) { - match &parent_expr.kind { - ExprKind::AddrOf(..) => { - // `&e` => `e` must be referenced. - needs_check_adjustment = false; - }, - ExprKind::Field(..) => { - needs_check_adjustment = true; - - // Check whether implicit dereferences happened; - // if so, no need to go further up - // because of the same reason as the `ExprKind::Unary` case. - if cx - .typeck_results() - .expr_adjustments(dereferenced_expr) - .iter() - .any(|adj| matches!(adj.kind, Adjust::Deref(_))) - { - break; - } - - dereferenced_expr = parent_expr; - }, - ExprKind::Index(e, _) if ptr::eq(&**e, cur_expr) => { - // `e[i]` => desugared to `*Index::index(&e, i)`, - // meaning `e` must be referenced. - // no need to go further up since a method call is involved now. - needs_check_adjustment = false; - break; - }, - ExprKind::Unary(UnOp::UnDeref, _) => { - // `*e` => desugared to `*Deref::deref(&e)`, - // meaning `e` must be referenced. - // no need to go further up since a method call is involved now. - needs_check_adjustment = false; - break; - }, - _ => break, - } - cur_expr = parent_expr; - } else { - break; - } - } - - let ty = if needs_check_adjustment { - let adjustments = cx.typeck_results().expr_adjustments(dereferenced_expr); - if let Some(i) = adjustments - .iter() - .position(|adj| matches!(adj.kind, Adjust::Borrow(_) | Adjust::Deref(_))) - { - if i == 0 { - cx.typeck_results().expr_ty(dereferenced_expr) - } else { - adjustments[i - 1].target - } - } else { - // No borrow adjustments means the entire const is moved. - return; - } - } else { - cx.typeck_results().expr_ty(dereferenced_expr) - }; - - if is_unfrozen(cx, ty) && is_value_unfrozen_expr(cx, expr.hir_id, item_def_id, ty) { - lint(cx, Source::Expr { expr: expr.span }); - } - } - } -} diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs deleted file mode 100644 index 446426b3e611..000000000000 --- a/clippy_lints/src/non_expressive_names.rs +++ /dev/null @@ -1,419 +0,0 @@ -use crate::utils::{span_lint, span_lint_and_then}; -use rustc_ast::ast::{Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Item, ItemKind, Local, Pat, PatKind}; -use rustc_ast::visit::{walk_block, walk_expr, walk_pat, Visitor}; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_middle::lint::in_external_macro; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; -use rustc_span::sym; -use rustc_span::symbol::{Ident, Symbol}; -use std::cmp::Ordering; - -declare_clippy_lint! { - /// **What it does:** Checks for names that are very similar and thus confusing. - /// - /// **Why is this bad?** It's hard to distinguish between names that differ only - /// by a single character. - /// - /// **Known problems:** None? - /// - /// **Example:** - /// ```ignore - /// let checked_exp = something; - /// let checked_expr = something_else; - /// ``` - pub SIMILAR_NAMES, - pedantic, - "similarly named items and bindings" -} - -declare_clippy_lint! { - /// **What it does:** Checks for too many variables whose name consists of a - /// single character. - /// - /// **Why is this bad?** It's hard to memorize what a variable means without a - /// descriptive name. - /// - /// **Known problems:** None? - /// - /// **Example:** - /// ```ignore - /// let (a, b, c, d, e, f, g) = (...); - /// ``` - pub MANY_SINGLE_CHAR_NAMES, - style, - "too many single character bindings" -} - -declare_clippy_lint! { - /// **What it does:** Checks if you have variables whose name consists of just - /// underscores and digits. - /// - /// **Why is this bad?** It's hard to memorize what a variable means without a - /// descriptive name. - /// - /// **Known problems:** None? - /// - /// **Example:** - /// ```rust - /// let _1 = 1; - /// let ___1 = 1; - /// let __1___2 = 11; - /// ``` - pub JUST_UNDERSCORES_AND_DIGITS, - style, - "unclear name" -} - -#[derive(Copy, Clone)] -pub struct NonExpressiveNames { - pub single_char_binding_names_threshold: u64, -} - -impl_lint_pass!(NonExpressiveNames => [SIMILAR_NAMES, MANY_SINGLE_CHAR_NAMES, JUST_UNDERSCORES_AND_DIGITS]); - -struct ExistingName { - interned: Symbol, - span: Span, - len: usize, - exemptions: &'static [&'static str], -} - -struct SimilarNamesLocalVisitor<'a, 'tcx> { - names: Vec, - cx: &'a EarlyContext<'tcx>, - lint: &'a NonExpressiveNames, - - /// A stack of scopes containing the single-character bindings in each scope. - single_char_names: Vec>, -} - -impl<'a, 'tcx> SimilarNamesLocalVisitor<'a, 'tcx> { - fn check_single_char_names(&self) { - let num_single_char_names = self.single_char_names.iter().flatten().count(); - let threshold = self.lint.single_char_binding_names_threshold; - if num_single_char_names as u64 > threshold { - let span = self - .single_char_names - .iter() - .flatten() - .map(|ident| ident.span) - .collect::>(); - span_lint( - self.cx, - MANY_SINGLE_CHAR_NAMES, - span, - &format!( - "{} bindings with single-character names in scope", - num_single_char_names - ), - ); - } - } -} - -// this list contains lists of names that are allowed to be similar -// the assumption is that no name is ever contained in multiple lists. -#[rustfmt::skip] -const ALLOWED_TO_BE_SIMILAR: &[&[&str]] = &[ - &["parsed", "parser"], - &["lhs", "rhs"], - &["tx", "rx"], - &["set", "get"], - &["args", "arms"], - &["qpath", "path"], - &["lit", "lint"], -]; - -struct SimilarNamesNameVisitor<'a, 'tcx, 'b>(&'b mut SimilarNamesLocalVisitor<'a, 'tcx>); - -impl<'a, 'tcx, 'b> Visitor<'tcx> for SimilarNamesNameVisitor<'a, 'tcx, 'b> { - fn visit_pat(&mut self, pat: &'tcx Pat) { - match pat.kind { - PatKind::Ident(_, ident, _) => { - if !pat.span.from_expansion() { - self.check_ident(ident); - } - }, - PatKind::Struct(_, ref fields, _) => { - for field in fields { - if !field.is_shorthand { - self.visit_pat(&field.pat); - } - } - }, - // just go through the first pattern, as either all patterns - // bind the same bindings or rustc would have errored much earlier - PatKind::Or(ref pats) => self.visit_pat(&pats[0]), - _ => walk_pat(self, pat), - } - } -} - -#[must_use] -fn get_exemptions(interned_name: &str) -> Option<&'static [&'static str]> { - for &list in ALLOWED_TO_BE_SIMILAR { - if allowed_to_be_similar(interned_name, list) { - return Some(list); - } - } - None -} - -#[must_use] -fn allowed_to_be_similar(interned_name: &str, list: &[&str]) -> bool { - list.iter() - .any(|&name| interned_name.starts_with(name) || interned_name.ends_with(name)) -} - -impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> { - fn check_short_ident(&mut self, ident: Ident) { - // Ignore shadowing - if self - .0 - .single_char_names - .iter() - .flatten() - .any(|id| id.name == ident.name) - { - return; - } - - if let Some(scope) = &mut self.0.single_char_names.last_mut() { - scope.push(ident); - } - } - - #[allow(clippy::too_many_lines)] - fn check_ident(&mut self, ident: Ident) { - let interned_name = ident.name.as_str(); - if interned_name.chars().any(char::is_uppercase) { - return; - } - if interned_name.chars().all(|c| c.is_digit(10) || c == '_') { - span_lint( - self.0.cx, - JUST_UNDERSCORES_AND_DIGITS, - ident.span, - "consider choosing a more descriptive name", - ); - return; - } - let count = interned_name.chars().count(); - if count < 3 { - if count == 1 { - self.check_short_ident(ident); - } - return; - } - for existing_name in &self.0.names { - if allowed_to_be_similar(&interned_name, existing_name.exemptions) { - continue; - } - let mut split_at = None; - match existing_name.len.cmp(&count) { - Ordering::Greater => { - if existing_name.len - count != 1 - || levenstein_not_1(&interned_name, &existing_name.interned.as_str()) - { - continue; - } - }, - Ordering::Less => { - if count - existing_name.len != 1 - || levenstein_not_1(&existing_name.interned.as_str(), &interned_name) - { - continue; - } - }, - Ordering::Equal => { - let mut interned_chars = interned_name.chars(); - let interned_str = existing_name.interned.as_str(); - let mut existing_chars = interned_str.chars(); - let first_i = interned_chars.next().expect("we know we have at least one char"); - let first_e = existing_chars.next().expect("we know we have at least one char"); - let eq_or_numeric = |(a, b): (char, char)| a == b || a.is_numeric() && b.is_numeric(); - - if eq_or_numeric((first_i, first_e)) { - let last_i = interned_chars.next_back().expect("we know we have at least two chars"); - let last_e = existing_chars.next_back().expect("we know we have at least two chars"); - if eq_or_numeric((last_i, last_e)) { - if interned_chars - .zip(existing_chars) - .filter(|&ie| !eq_or_numeric(ie)) - .count() - != 1 - { - continue; - } - } else { - let second_last_i = interned_chars - .next_back() - .expect("we know we have at least three chars"); - let second_last_e = existing_chars - .next_back() - .expect("we know we have at least three chars"); - if !eq_or_numeric((second_last_i, second_last_e)) - || second_last_i == '_' - || !interned_chars.zip(existing_chars).all(eq_or_numeric) - { - // allowed similarity foo_x, foo_y - // or too many chars differ (foo_x, boo_y) or (foox, booy) - continue; - } - split_at = interned_name.char_indices().rev().next().map(|(i, _)| i); - } - } else { - let second_i = interned_chars.next().expect("we know we have at least two chars"); - let second_e = existing_chars.next().expect("we know we have at least two chars"); - if !eq_or_numeric((second_i, second_e)) - || second_i == '_' - || !interned_chars.zip(existing_chars).all(eq_or_numeric) - { - // allowed similarity x_foo, y_foo - // or too many chars differ (x_foo, y_boo) or (xfoo, yboo) - continue; - } - split_at = interned_name.chars().next().map(char::len_utf8); - } - }, - } - span_lint_and_then( - self.0.cx, - SIMILAR_NAMES, - ident.span, - "binding's name is too similar to existing binding", - |diag| { - diag.span_note(existing_name.span, "existing binding defined here"); - if let Some(split) = split_at { - diag.span_help( - ident.span, - &format!( - "separate the discriminating character by an \ - underscore like: `{}_{}`", - &interned_name[..split], - &interned_name[split..] - ), - ); - } - }, - ); - return; - } - self.0.names.push(ExistingName { - exemptions: get_exemptions(&interned_name).unwrap_or(&[]), - interned: ident.name, - span: ident.span, - len: count, - }); - } -} - -impl<'a, 'b> SimilarNamesLocalVisitor<'a, 'b> { - /// ensure scoping rules work - fn apply Fn(&'c mut Self)>(&mut self, f: F) { - let n = self.names.len(); - let single_char_count = self.single_char_names.len(); - f(self); - self.names.truncate(n); - self.single_char_names.truncate(single_char_count); - } -} - -impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> { - fn visit_local(&mut self, local: &'tcx Local) { - if let Some(ref init) = local.init { - self.apply(|this| walk_expr(this, &**init)); - } - // add the pattern after the expression because the bindings aren't available - // yet in the init - // expression - SimilarNamesNameVisitor(self).visit_pat(&*local.pat); - } - fn visit_block(&mut self, blk: &'tcx Block) { - self.single_char_names.push(vec![]); - - self.apply(|this| walk_block(this, blk)); - - self.check_single_char_names(); - self.single_char_names.pop(); - } - fn visit_arm(&mut self, arm: &'tcx Arm) { - self.single_char_names.push(vec![]); - - self.apply(|this| { - SimilarNamesNameVisitor(this).visit_pat(&arm.pat); - this.apply(|this| walk_expr(this, &arm.body)); - }); - - self.check_single_char_names(); - self.single_char_names.pop(); - } - fn visit_item(&mut self, _: &Item) { - // do not recurse into inner items - } -} - -impl EarlyLintPass for NonExpressiveNames { - fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { - if in_external_macro(cx.sess, item.span) { - return; - } - - if let ItemKind::Fn(_, ref sig, _, Some(ref blk)) = item.kind { - do_check(self, cx, &item.attrs, &sig.decl, blk); - } - } - - fn check_impl_item(&mut self, cx: &EarlyContext<'_>, item: &AssocItem) { - if in_external_macro(cx.sess, item.span) { - return; - } - - if let AssocItemKind::Fn(_, ref sig, _, Some(ref blk)) = item.kind { - do_check(self, cx, &item.attrs, &sig.decl, blk); - } - } -} - -fn do_check(lint: &mut NonExpressiveNames, cx: &EarlyContext<'_>, attrs: &[Attribute], decl: &FnDecl, blk: &Block) { - if !attrs.iter().any(|attr| attr.has_name(sym::test)) { - let mut visitor = SimilarNamesLocalVisitor { - names: Vec::new(), - cx, - lint, - single_char_names: vec![vec![]], - }; - - // initialize with function arguments - for arg in &decl.inputs { - SimilarNamesNameVisitor(&mut visitor).visit_pat(&arg.pat); - } - // walk all other bindings - walk_block(&mut visitor, blk); - - visitor.check_single_char_names(); - } -} - -/// Precondition: `a_name.chars().count() < b_name.chars().count()`. -#[must_use] -fn levenstein_not_1(a_name: &str, b_name: &str) -> bool { - debug_assert!(a_name.chars().count() < b_name.chars().count()); - let mut a_chars = a_name.chars(); - let mut b_chars = b_name.chars(); - while let (Some(a), Some(b)) = (a_chars.next(), b_chars.next()) { - if a == b { - continue; - } - if let Some(b2) = b_chars.next() { - // check if there's just one character inserted - return a != b2 || a_chars.ne(b_chars); - } - // tuple - // ntuple - return true; - } - // for item in items - true -} diff --git a/clippy_lints/src/open_options.rs b/clippy_lints/src/open_options.rs deleted file mode 100644 index 73a99a3a2f87..000000000000 --- a/clippy_lints/src/open_options.rs +++ /dev/null @@ -1,203 +0,0 @@ -use crate::utils::{match_type, paths, span_lint}; -use rustc_ast::ast::LitKind; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::{Span, Spanned}; - -declare_clippy_lint! { - /// **What it does:** Checks for duplicate open options as well as combinations - /// that make no sense. - /// - /// **Why is this bad?** In the best case, the code will be harder to read than - /// necessary. I don't know the worst case. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// use std::fs::OpenOptions; - /// - /// OpenOptions::new().read(true).truncate(true); - /// ``` - pub NONSENSICAL_OPEN_OPTIONS, - correctness, - "nonsensical combination of options for opening a file" -} - -declare_lint_pass!(OpenOptions => [NONSENSICAL_OPEN_OPTIONS]); - -impl<'tcx> LateLintPass<'tcx> for OpenOptions { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if let ExprKind::MethodCall(ref path, _, ref arguments, _) = e.kind { - let obj_ty = cx.typeck_results().expr_ty(&arguments[0]).peel_refs(); - if path.ident.name == sym!(open) && match_type(cx, obj_ty, &paths::OPEN_OPTIONS) { - let mut options = Vec::new(); - get_open_options(cx, &arguments[0], &mut options); - check_open_options(cx, &options, e.span); - } - } - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -enum Argument { - True, - False, - Unknown, -} - -#[derive(Debug)] -enum OpenOption { - Write, - Read, - Truncate, - Create, - Append, -} - -fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec<(OpenOption, Argument)>) { - if let ExprKind::MethodCall(ref path, _, ref arguments, _) = argument.kind { - let obj_ty = cx.typeck_results().expr_ty(&arguments[0]).peel_refs(); - - // Only proceed if this is a call on some object of type std::fs::OpenOptions - if match_type(cx, obj_ty, &paths::OPEN_OPTIONS) && arguments.len() >= 2 { - let argument_option = match arguments[1].kind { - ExprKind::Lit(ref span) => { - if let Spanned { - node: LitKind::Bool(lit), - .. - } = *span - { - if lit { - Argument::True - } else { - Argument::False - } - } else { - return; // The function is called with a literal - // which is not a boolean literal. This is theoretically - // possible, but not very likely. - } - }, - _ => Argument::Unknown, - }; - - match &*path.ident.as_str() { - "create" => { - options.push((OpenOption::Create, argument_option)); - }, - "append" => { - options.push((OpenOption::Append, argument_option)); - }, - "truncate" => { - options.push((OpenOption::Truncate, argument_option)); - }, - "read" => { - options.push((OpenOption::Read, argument_option)); - }, - "write" => { - options.push((OpenOption::Write, argument_option)); - }, - _ => (), - } - - get_open_options(cx, &arguments[0], options); - } - } -} - -fn check_open_options(cx: &LateContext<'_>, options: &[(OpenOption, Argument)], span: Span) { - let (mut create, mut append, mut truncate, mut read, mut write) = (false, false, false, false, false); - let (mut create_arg, mut append_arg, mut truncate_arg, mut read_arg, mut write_arg) = - (false, false, false, false, false); - // This code is almost duplicated (oh, the irony), but I haven't found a way to - // unify it. - - for option in options { - match *option { - (OpenOption::Create, arg) => { - if create { - span_lint( - cx, - NONSENSICAL_OPEN_OPTIONS, - span, - "the method `create` is called more than once", - ); - } else { - create = true - } - create_arg = create_arg || (arg == Argument::True); - }, - (OpenOption::Append, arg) => { - if append { - span_lint( - cx, - NONSENSICAL_OPEN_OPTIONS, - span, - "the method `append` is called more than once", - ); - } else { - append = true - } - append_arg = append_arg || (arg == Argument::True); - }, - (OpenOption::Truncate, arg) => { - if truncate { - span_lint( - cx, - NONSENSICAL_OPEN_OPTIONS, - span, - "the method `truncate` is called more than once", - ); - } else { - truncate = true - } - truncate_arg = truncate_arg || (arg == Argument::True); - }, - (OpenOption::Read, arg) => { - if read { - span_lint( - cx, - NONSENSICAL_OPEN_OPTIONS, - span, - "the method `read` is called more than once", - ); - } else { - read = true - } - read_arg = read_arg || (arg == Argument::True); - }, - (OpenOption::Write, arg) => { - if write { - span_lint( - cx, - NONSENSICAL_OPEN_OPTIONS, - span, - "the method `write` is called more than once", - ); - } else { - write = true - } - write_arg = write_arg || (arg == Argument::True); - }, - } - } - - if read && truncate && read_arg && truncate_arg && !(write && write_arg) { - span_lint( - cx, - NONSENSICAL_OPEN_OPTIONS, - span, - "file opened with `truncate` and `read`", - ); - } - if append && truncate && append_arg && truncate_arg { - span_lint( - cx, - NONSENSICAL_OPEN_OPTIONS, - span, - "file opened with `append` and `truncate`", - ); - } -} diff --git a/clippy_lints/src/option_env_unwrap.rs b/clippy_lints/src/option_env_unwrap.rs deleted file mode 100644 index fd653044a1bc..000000000000 --- a/clippy_lints/src/option_env_unwrap.rs +++ /dev/null @@ -1,55 +0,0 @@ -use crate::utils::{is_direct_expn_of, span_lint_and_help}; -use if_chain::if_chain; -use rustc_ast::ast::{Expr, ExprKind}; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `option_env!(...).unwrap()` and - /// suggests usage of the `env!` macro. - /// - /// **Why is this bad?** Unwrapping the result of `option_env!` will panic - /// at run-time if the environment variable doesn't exist, whereas `env!` - /// catches it at compile-time. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust,no_run - /// let _ = option_env!("HOME").unwrap(); - /// ``` - /// - /// Is better expressed as: - /// - /// ```rust,no_run - /// let _ = env!("HOME"); - /// ``` - pub OPTION_ENV_UNWRAP, - correctness, - "using `option_env!(...).unwrap()` to get environment variable" -} - -declare_lint_pass!(OptionEnvUnwrap => [OPTION_ENV_UNWRAP]); - -impl EarlyLintPass for OptionEnvUnwrap { - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - if_chain! { - if let ExprKind::MethodCall(path_segment, args, _) = &expr.kind; - let method_name = path_segment.ident.as_str(); - if method_name == "expect" || method_name == "unwrap"; - if let ExprKind::Call(caller, _) = &args[0].kind; - if is_direct_expn_of(caller.span, "option_env").is_some(); - then { - span_lint_and_help( - cx, - OPTION_ENV_UNWRAP, - expr.span, - "this will panic at run-time if the environment variable doesn't exist at compile-time", - None, - "consider using the `env!` macro instead" - ); - } - } - } -} diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs deleted file mode 100644 index 681dbce97697..000000000000 --- a/clippy_lints/src/option_if_let_else.rs +++ /dev/null @@ -1,217 +0,0 @@ -use crate::utils; -use crate::utils::eager_or_lazy; -use crate::utils::sugg::Sugg; -use crate::utils::{is_type_diagnostic_item, paths, span_lint_and_sugg}; -use if_chain::if_chain; - -use rustc_errors::Applicability; -use rustc_hir::{Arm, BindingAnnotation, Block, Expr, ExprKind, MatchSource, Mutability, PatKind, UnOp}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** - /// Lints usage of `if let Some(v) = ... { y } else { x }` which is more - /// idiomatically done with `Option::map_or` (if the else bit is a pure - /// expression) or `Option::map_or_else` (if the else bit is an impure - /// expression). - /// - /// **Why is this bad?** - /// Using the dedicated functions of the Option type is clearer and - /// more concise than an `if let` expression. - /// - /// **Known problems:** - /// This lint uses a deliberately conservative metric for checking - /// if the inside of either body contains breaks or continues which will - /// cause it to not suggest a fix if either block contains a loop with - /// continues or breaks contained within the loop. - /// - /// **Example:** - /// - /// ```rust - /// # let optional: Option = Some(0); - /// # fn do_complicated_function() -> u32 { 5 }; - /// let _ = if let Some(foo) = optional { - /// foo - /// } else { - /// 5 - /// }; - /// let _ = if let Some(foo) = optional { - /// foo - /// } else { - /// let y = do_complicated_function(); - /// y*y - /// }; - /// ``` - /// - /// should be - /// - /// ```rust - /// # let optional: Option = Some(0); - /// # fn do_complicated_function() -> u32 { 5 }; - /// let _ = optional.map_or(5, |foo| foo); - /// let _ = optional.map_or_else(||{ - /// let y = do_complicated_function(); - /// y*y - /// }, |foo| foo); - /// ``` - pub OPTION_IF_LET_ELSE, - pedantic, - "reimplementation of Option::map_or" -} - -declare_lint_pass!(OptionIfLetElse => [OPTION_IF_LET_ELSE]); - -/// Returns true iff the given expression is the result of calling `Result::ok` -fn is_result_ok(cx: &LateContext<'_>, expr: &'_ Expr<'_>) -> bool { - if let ExprKind::MethodCall(ref path, _, &[ref receiver], _) = &expr.kind { - path.ident.name.to_ident_string() == "ok" - && is_type_diagnostic_item(cx, &cx.typeck_results().expr_ty(&receiver), sym::result_type) - } else { - false - } -} - -/// A struct containing information about occurrences of the -/// `if let Some(..) = .. else` construct that this lint detects. -struct OptionIfLetElseOccurence { - option: String, - method_sugg: String, - some_expr: String, - none_expr: String, - wrap_braces: bool, -} - -/// Extracts the body of a given arm. If the arm contains only an expression, -/// then it returns the expression. Otherwise, it returns the entire block -fn extract_body_from_arm<'a>(arm: &'a Arm<'a>) -> Option<&'a Expr<'a>> { - if let ExprKind::Block( - Block { - stmts: statements, - expr: Some(expr), - .. - }, - _, - ) = &arm.body.kind - { - if let [] = statements { - Some(&expr) - } else { - Some(&arm.body) - } - } else { - None - } -} - -/// If this is the else body of an if/else expression, then we need to wrap -/// it in curly braces. Otherwise, we don't. -fn should_wrap_in_braces(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - utils::get_enclosing_block(cx, expr.hir_id).map_or(false, |parent| { - if let Some(Expr { - kind: - ExprKind::Match( - _, - arms, - MatchSource::IfDesugar { - contains_else_clause: true, - } - | MatchSource::IfLetDesugar { - contains_else_clause: true, - }, - ), - .. - }) = parent.expr - { - expr.hir_id == arms[1].body.hir_id - } else { - false - } - }) -} - -fn format_option_in_sugg(cx: &LateContext<'_>, cond_expr: &Expr<'_>, as_ref: bool, as_mut: bool) -> String { - format!( - "{}{}", - Sugg::hir(cx, cond_expr, "..").maybe_par(), - if as_mut { - ".as_mut()" - } else if as_ref { - ".as_ref()" - } else { - "" - } - ) -} - -/// If this expression is the option if let/else construct we're detecting, then -/// this function returns an `OptionIfLetElseOccurence` struct with details if -/// this construct is found, or None if this construct is not found. -fn detect_option_if_let_else<'tcx>( - cx: &'_ LateContext<'tcx>, - expr: &'_ Expr<'tcx>, -) -> Option { - if_chain! { - if !utils::in_macro(expr.span); // Don't lint macros, because it behaves weirdly - if let ExprKind::Match(cond_expr, arms, MatchSource::IfLetDesugar{contains_else_clause: true}) = &expr.kind; - if arms.len() == 2; - if !is_result_ok(cx, cond_expr); // Don't lint on Result::ok because a different lint does it already - if let PatKind::TupleStruct(struct_qpath, &[inner_pat], _) = &arms[0].pat.kind; - if utils::match_qpath(struct_qpath, &paths::OPTION_SOME); - if let PatKind::Binding(bind_annotation, _, id, _) = &inner_pat.kind; - if !utils::usage::contains_return_break_continue_macro(arms[0].body); - if !utils::usage::contains_return_break_continue_macro(arms[1].body); - then { - let capture_mut = if bind_annotation == &BindingAnnotation::Mutable { "mut " } else { "" }; - let some_body = extract_body_from_arm(&arms[0])?; - let none_body = extract_body_from_arm(&arms[1])?; - let method_sugg = if eager_or_lazy::is_eagerness_candidate(cx, none_body) { "map_or" } else { "map_or_else" }; - let capture_name = id.name.to_ident_string(); - let wrap_braces = should_wrap_in_braces(cx, expr); - let (as_ref, as_mut) = match &cond_expr.kind { - ExprKind::AddrOf(_, Mutability::Not, _) => (true, false), - ExprKind::AddrOf(_, Mutability::Mut, _) => (false, true), - _ => (bind_annotation == &BindingAnnotation::Ref, bind_annotation == &BindingAnnotation::RefMut), - }; - let cond_expr = match &cond_expr.kind { - // Pointer dereferencing happens automatically, so we can omit it in the suggestion - ExprKind::Unary(UnOp::UnDeref, expr) | ExprKind::AddrOf(_, _, expr) => expr, - _ => cond_expr, - }; - Some(OptionIfLetElseOccurence { - option: format_option_in_sugg(cx, cond_expr, as_ref, as_mut), - method_sugg: method_sugg.to_string(), - some_expr: format!("|{}{}| {}", capture_mut, capture_name, Sugg::hir(cx, some_body, "..")), - none_expr: format!("{}{}", if method_sugg == "map_or" { "" } else { "|| " }, Sugg::hir(cx, none_body, "..")), - wrap_braces, - }) - } else { - None - } - } -} - -impl<'tcx> LateLintPass<'tcx> for OptionIfLetElse { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) { - if let Some(detection) = detect_option_if_let_else(cx, expr) { - span_lint_and_sugg( - cx, - OPTION_IF_LET_ELSE, - expr.span, - format!("use Option::{} instead of an if let/else", detection.method_sugg).as_str(), - "try", - format!( - "{}{}.{}({}, {}){}", - if detection.wrap_braces { "{ " } else { "" }, - detection.option, - detection.method_sugg, - detection.none_expr, - detection.some_expr, - if detection.wrap_braces { " }" } else { "" }, - ), - Applicability::MaybeIncorrect, - ); - } - } -} diff --git a/clippy_lints/src/overflow_check_conditional.rs b/clippy_lints/src/overflow_check_conditional.rs deleted file mode 100644 index 3c041bac234a..000000000000 --- a/clippy_lints/src/overflow_check_conditional.rs +++ /dev/null @@ -1,82 +0,0 @@ -use crate::utils::{span_lint, SpanlessEq}; -use if_chain::if_chain; -use rustc_hir::{BinOpKind, Expr, ExprKind, QPath}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Detects classic underflow/overflow checks. - /// - /// **Why is this bad?** Most classic C underflow/overflow checks will fail in - /// Rust. Users can use functions like `overflowing_*` and `wrapping_*` instead. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let a = 1; - /// # let b = 2; - /// a + b < a; - /// ``` - pub OVERFLOW_CHECK_CONDITIONAL, - complexity, - "overflow checks inspired by C which are likely to panic" -} - -declare_lint_pass!(OverflowCheckConditional => [OVERFLOW_CHECK_CONDITIONAL]); - -impl<'tcx> LateLintPass<'tcx> for OverflowCheckConditional { - // a + b < a, a > a + b, a < a - b, a - b > a - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - let eq = |l, r| SpanlessEq::new(cx).eq_path_segment(l, r); - if_chain! { - if let ExprKind::Binary(ref op, ref first, ref second) = expr.kind; - if let ExprKind::Binary(ref op2, ref ident1, ref ident2) = first.kind; - if let ExprKind::Path(QPath::Resolved(_, ref path1)) = ident1.kind; - if let ExprKind::Path(QPath::Resolved(_, ref path2)) = ident2.kind; - if let ExprKind::Path(QPath::Resolved(_, ref path3)) = second.kind; - if eq(&path1.segments[0], &path3.segments[0]) || eq(&path2.segments[0], &path3.segments[0]); - if cx.typeck_results().expr_ty(ident1).is_integral(); - if cx.typeck_results().expr_ty(ident2).is_integral(); - then { - if let BinOpKind::Lt = op.node { - if let BinOpKind::Add = op2.node { - span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span, - "you are trying to use classic C overflow conditions that will fail in Rust"); - } - } - if let BinOpKind::Gt = op.node { - if let BinOpKind::Sub = op2.node { - span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span, - "you are trying to use classic C underflow conditions that will fail in Rust"); - } - } - } - } - - if_chain! { - if let ExprKind::Binary(ref op, ref first, ref second) = expr.kind; - if let ExprKind::Binary(ref op2, ref ident1, ref ident2) = second.kind; - if let ExprKind::Path(QPath::Resolved(_, ref path1)) = ident1.kind; - if let ExprKind::Path(QPath::Resolved(_, ref path2)) = ident2.kind; - if let ExprKind::Path(QPath::Resolved(_, ref path3)) = first.kind; - if eq(&path1.segments[0], &path3.segments[0]) || eq(&path2.segments[0], &path3.segments[0]); - if cx.typeck_results().expr_ty(ident1).is_integral(); - if cx.typeck_results().expr_ty(ident2).is_integral(); - then { - if let BinOpKind::Gt = op.node { - if let BinOpKind::Add = op2.node { - span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span, - "you are trying to use classic C overflow conditions that will fail in Rust"); - } - } - if let BinOpKind::Lt = op.node { - if let BinOpKind::Sub = op2.node { - span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span, - "you are trying to use classic C underflow conditions that will fail in Rust"); - } - } - } - } - } -} diff --git a/clippy_lints/src/panic_in_result_fn.rs b/clippy_lints/src/panic_in_result_fn.rs deleted file mode 100644 index 37e2b50def17..000000000000 --- a/clippy_lints/src/panic_in_result_fn.rs +++ /dev/null @@ -1,84 +0,0 @@ -use crate::utils::{find_macro_calls, is_type_diagnostic_item, return_ty, span_lint_and_then}; -use rustc_hir as hir; -use rustc_hir::intravisit::FnKind; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::{sym, Span}; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `panic!`, `unimplemented!`, `todo!`, `unreachable!` or assertions in a function of type result. - /// - /// **Why is this bad?** For some codebases, it is desirable for functions of type result to return an error instead of crashing. Hence panicking macros should be avoided. - /// - /// **Known problems:** Functions called from a function returning a `Result` may invoke a panicking macro. This is not checked. - /// - /// **Example:** - /// - /// ```rust - /// fn result_with_panic() -> Result - /// { - /// panic!("error"); - /// } - /// ``` - /// Use instead: - /// ```rust - /// fn result_without_panic() -> Result { - /// Err(String::from("error")) - /// } - /// ``` - pub PANIC_IN_RESULT_FN, - restriction, - "functions of type `Result<..>` that contain `panic!()`, `todo!()`, `unreachable()`, `unimplemented()` or assertion" -} - -declare_lint_pass!(PanicInResultFn => [PANIC_IN_RESULT_FN]); - -impl<'tcx> LateLintPass<'tcx> for PanicInResultFn { - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - fn_kind: FnKind<'tcx>, - _: &'tcx hir::FnDecl<'tcx>, - body: &'tcx hir::Body<'tcx>, - span: Span, - hir_id: hir::HirId, - ) { - if !matches!(fn_kind, FnKind::Closure(_)) - && is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::result_type) - { - lint_impl_body(cx, span, body); - } - } -} - -fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, body: &'tcx hir::Body<'tcx>) { - let panics = find_macro_calls( - &[ - "unimplemented", - "unreachable", - "panic", - "todo", - "assert", - "assert_eq", - "assert_ne", - "debug_assert", - "debug_assert_eq", - "debug_assert_ne", - ], - body, - ); - if !panics.is_empty() { - span_lint_and_then( - cx, - PANIC_IN_RESULT_FN, - impl_span, - "used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`", - move |diag| { - diag.help( - "`unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing", - ); - diag.span_note(panics, "return Err() instead of panicking"); - }, - ); - } -} diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs deleted file mode 100644 index 359620cc0797..000000000000 --- a/clippy_lints/src/panic_unimplemented.rs +++ /dev/null @@ -1,108 +0,0 @@ -use crate::utils::{is_expn_of, match_panic_call, span_lint}; -use if_chain::if_chain; -use rustc_hir::Expr; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `panic!`. - /// - /// **Why is this bad?** `panic!` will stop the execution of the executable - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```no_run - /// panic!("even with a good reason"); - /// ``` - pub PANIC, - restriction, - "usage of the `panic!` macro" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `unimplemented!`. - /// - /// **Why is this bad?** This macro should not be present in production code - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```no_run - /// unimplemented!(); - /// ``` - pub UNIMPLEMENTED, - restriction, - "`unimplemented!` should not be present in production code" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `todo!`. - /// - /// **Why is this bad?** This macro should not be present in production code - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```no_run - /// todo!(); - /// ``` - pub TODO, - restriction, - "`todo!` should not be present in production code" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `unreachable!`. - /// - /// **Why is this bad?** This macro can cause code to panic - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```no_run - /// unreachable!(); - /// ``` - pub UNREACHABLE, - restriction, - "usage of the `unreachable!` macro" -} - -declare_lint_pass!(PanicUnimplemented => [UNIMPLEMENTED, UNREACHABLE, TODO, PANIC]); - -impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if match_panic_call(cx, expr).is_some() { - let span = get_outer_span(expr); - if is_expn_of(expr.span, "unimplemented").is_some() { - span_lint( - cx, - UNIMPLEMENTED, - span, - "`unimplemented` should not be present in production code", - ); - } else if is_expn_of(expr.span, "todo").is_some() { - span_lint(cx, TODO, span, "`todo` should not be present in production code"); - } else if is_expn_of(expr.span, "unreachable").is_some() { - span_lint(cx, UNREACHABLE, span, "usage of the `unreachable!` macro"); - } else if is_expn_of(expr.span, "panic").is_some() { - span_lint(cx, PANIC, span, "`panic` should not be present in production code"); - } - } - } -} - -fn get_outer_span(expr: &Expr<'_>) -> Span { - if_chain! { - if expr.span.from_expansion(); - let first = expr.span.ctxt().outer_expn_data(); - if first.call_site.from_expansion(); - let second = first.call_site.ctxt().outer_expn_data(); - then { - second.call_site - } else { - expr.span - } - } -} diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs deleted file mode 100644 index ceecc8dbc06f..000000000000 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ /dev/null @@ -1,56 +0,0 @@ -use crate::utils::{is_automatically_derived, span_lint_hir}; -use if_chain::if_chain; -use rustc_hir::{Item, ItemKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** Checks for manual re-implementations of `PartialEq::ne`. - /// - /// **Why is this bad?** `PartialEq::ne` is required to always return the - /// negated result of `PartialEq::eq`, which is exactly what the default - /// implementation does. Therefore, there should never be any need to - /// re-implement it. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// struct Foo; - /// - /// impl PartialEq for Foo { - /// fn eq(&self, other: &Foo) -> bool { true } - /// fn ne(&self, other: &Foo) -> bool { !(self == other) } - /// } - /// ``` - pub PARTIALEQ_NE_IMPL, - complexity, - "re-implementing `PartialEq::ne`" -} - -declare_lint_pass!(PartialEqNeImpl => [PARTIALEQ_NE_IMPL]); - -impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl { - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if_chain! { - if let ItemKind::Impl{ of_trait: Some(ref trait_ref), items: impl_items, .. } = item.kind; - if !is_automatically_derived(&*item.attrs); - if let Some(eq_trait) = cx.tcx.lang_items().eq_trait(); - if trait_ref.path.res.def_id() == eq_trait; - then { - for impl_item in impl_items { - if impl_item.ident.name == sym::ne { - span_lint_hir( - cx, - PARTIALEQ_NE_IMPL, - impl_item.id.hir_id, - impl_item.span, - "re-implementing `PartialEq::ne` is unnecessary", - ); - } - } - } - }; - } -} diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs deleted file mode 100644 index 6a17d654ac94..000000000000 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ /dev/null @@ -1,257 +0,0 @@ -use std::cmp; - -use crate::utils::{is_copy, is_self_ty, snippet, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_ast::attr; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_hir::intravisit::FnKind; -use rustc_hir::{BindingAnnotation, Body, FnDecl, HirId, ItemKind, MutTy, Mutability, Node, PatKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::{sym, Span}; -use rustc_target::abi::LayoutOf; -use rustc_target::spec::abi::Abi; -use rustc_target::spec::Target; - -declare_clippy_lint! { - /// **What it does:** Checks for functions taking arguments by reference, where - /// the argument type is `Copy` and small enough to be more efficient to always - /// pass by value. - /// - /// **Why is this bad?** In many calling conventions instances of structs will - /// be passed through registers if they fit into two or less general purpose - /// registers. - /// - /// **Known problems:** This lint is target register size dependent, it is - /// limited to 32-bit to try and reduce portability problems between 32 and - /// 64-bit, but if you are compiling for 8 or 16-bit targets then the limit - /// will be different. - /// - /// The configuration option `trivial_copy_size_limit` can be set to override - /// this limit for a project. - /// - /// This lint attempts to allow passing arguments by reference if a reference - /// to that argument is returned. This is implemented by comparing the lifetime - /// of the argument and return value for equality. However, this can cause - /// false positives in cases involving multiple lifetimes that are bounded by - /// each other. - /// - /// **Example:** - /// - /// ```rust - /// // Bad - /// fn foo(v: &u32) {} - /// ``` - /// - /// ```rust - /// // Better - /// fn foo(v: u32) {} - /// ``` - pub TRIVIALLY_COPY_PASS_BY_REF, - pedantic, - "functions taking small copyable arguments by reference" -} - -declare_clippy_lint! { - /// **What it does:** Checks for functions taking arguments by value, where - /// the argument type is `Copy` and large enough to be worth considering - /// passing by reference. Does not trigger if the function is being exported, - /// because that might induce API breakage, if the parameter is declared as mutable, - /// or if the argument is a `self`. - /// - /// **Why is this bad?** Arguments passed by value might result in an unnecessary - /// shallow copy, taking up more space in the stack and requiring a call to - /// `memcpy`, which which can be expensive. - /// - /// **Example:** - /// - /// ```rust - /// #[derive(Clone, Copy)] - /// struct TooLarge([u8; 2048]); - /// - /// // Bad - /// fn foo(v: TooLarge) {} - /// ``` - /// ```rust - /// #[derive(Clone, Copy)] - /// struct TooLarge([u8; 2048]); - /// - /// // Good - /// fn foo(v: &TooLarge) {} - /// ``` - pub LARGE_TYPES_PASSED_BY_VALUE, - pedantic, - "functions taking large arguments by value" -} - -#[derive(Copy, Clone)] -pub struct PassByRefOrValue { - ref_min_size: u64, - value_max_size: u64, -} - -impl<'tcx> PassByRefOrValue { - pub fn new(ref_min_size: Option, value_max_size: u64, target: &Target) -> Self { - let ref_min_size = ref_min_size.unwrap_or_else(|| { - let bit_width = u64::from(target.pointer_width); - // Cap the calculated bit width at 32-bits to reduce - // portability problems between 32 and 64-bit targets - let bit_width = cmp::min(bit_width, 32); - #[allow(clippy::integer_division)] - let byte_width = bit_width / 8; - // Use a limit of 2 times the register byte width - byte_width * 2 - }); - - Self { - ref_min_size, - value_max_size, - } - } - - fn check_poly_fn(&mut self, cx: &LateContext<'tcx>, hir_id: HirId, decl: &FnDecl<'_>, span: Option) { - let fn_def_id = cx.tcx.hir().local_def_id(hir_id); - - let fn_sig = cx.tcx.fn_sig(fn_def_id); - let fn_sig = cx.tcx.erase_late_bound_regions(fn_sig); - - let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir().body(id)); - - for (index, (input, &ty)) in decl.inputs.iter().zip(fn_sig.inputs()).enumerate() { - // All spans generated from a proc-macro invocation are the same... - match span { - Some(s) if s == input.span => return, - _ => (), - } - - match ty.kind() { - ty::Ref(input_lt, ty, Mutability::Not) => { - // Use lifetimes to determine if we're returning a reference to the - // argument. In that case we can't switch to pass-by-value as the - // argument will not live long enough. - let output_lts = match *fn_sig.output().kind() { - ty::Ref(output_lt, _, _) => vec![output_lt], - ty::Adt(_, substs) => substs.regions().collect(), - _ => vec![], - }; - - if_chain! { - if !output_lts.contains(&input_lt); - if is_copy(cx, ty); - if let Some(size) = cx.layout_of(ty).ok().map(|l| l.size.bytes()); - if size <= self.ref_min_size; - if let hir::TyKind::Rptr(_, MutTy { ty: ref decl_ty, .. }) = input.kind; - then { - let value_type = if is_self_ty(decl_ty) { - "self".into() - } else { - snippet(cx, decl_ty.span, "_").into() - }; - span_lint_and_sugg( - cx, - TRIVIALLY_COPY_PASS_BY_REF, - input.span, - &format!("this argument ({} byte) is passed by reference, but would be more efficient if passed by value (limit: {} byte)", size, self.ref_min_size), - "consider passing by value instead", - value_type, - Applicability::Unspecified, - ); - } - } - }, - - ty::Adt(_, _) | ty::Array(_, _) | ty::Tuple(_) => { - // if function has a body and parameter is annotated with mut, ignore - if let Some(param) = fn_body.and_then(|body| body.params.get(index)) { - match param.pat.kind { - PatKind::Binding(BindingAnnotation::Unannotated, _, _, _) => {}, - _ => continue, - } - } - - if_chain! { - if !cx.access_levels.is_exported(hir_id); - if is_copy(cx, ty); - if !is_self_ty(input); - if let Some(size) = cx.layout_of(ty).ok().map(|l| l.size.bytes()); - if size > self.value_max_size; - then { - span_lint_and_sugg( - cx, - LARGE_TYPES_PASSED_BY_VALUE, - input.span, - &format!("this argument ({} byte) is passed by value, but might be more efficient if passed by reference (limit: {} byte)", size, self.value_max_size), - "consider passing by reference instead", - format!("&{}", snippet(cx, input.span, "_")), - Applicability::MaybeIncorrect, - ); - } - } - }, - - _ => {}, - } - } - } -} - -impl_lint_pass!(PassByRefOrValue => [TRIVIALLY_COPY_PASS_BY_REF, LARGE_TYPES_PASSED_BY_VALUE]); - -impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { - fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { - if item.span.from_expansion() { - return; - } - - if let hir::TraitItemKind::Fn(method_sig, _) = &item.kind { - self.check_poly_fn(cx, item.hir_id, &*method_sig.decl, None); - } - } - - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - kind: FnKind<'tcx>, - decl: &'tcx FnDecl<'_>, - _body: &'tcx Body<'_>, - span: Span, - hir_id: HirId, - ) { - if span.from_expansion() { - return; - } - - match kind { - FnKind::ItemFn(.., header, _, attrs) => { - if header.abi != Abi::Rust { - return; - } - for a in attrs { - if let Some(meta_items) = a.meta_item_list() { - if a.has_name(sym::proc_macro_derive) - || (a.has_name(sym::inline) && attr::list_contains_name(&meta_items, sym::always)) - { - return; - } - } - } - }, - FnKind::Method(..) => (), - FnKind::Closure(..) => return, - } - - // Exclude non-inherent impls - if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { - if matches!( - item.kind, - ItemKind::Impl { of_trait: Some(_), .. } | ItemKind::Trait(..) - ) { - return; - } - } - - self.check_poly_fn(cx, hir_id, decl, Some(span)); - } -} diff --git a/clippy_lints/src/path_buf_push_overwrite.rs b/clippy_lints/src/path_buf_push_overwrite.rs deleted file mode 100644 index 6eeb031d383c..000000000000 --- a/clippy_lints/src/path_buf_push_overwrite.rs +++ /dev/null @@ -1,71 +0,0 @@ -use crate::utils::{match_type, paths, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_ast::ast::LitKind; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use std::path::{Component, Path}; - -declare_clippy_lint! { - /// **What it does:*** Checks for [push](https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.push) - /// calls on `PathBuf` that can cause overwrites. - /// - /// **Why is this bad?** Calling `push` with a root path at the start can overwrite the - /// previous defined path. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// use std::path::PathBuf; - /// - /// let mut x = PathBuf::from("/foo"); - /// x.push("/bar"); - /// assert_eq!(x, PathBuf::from("/bar")); - /// ``` - /// Could be written: - /// - /// ```rust - /// use std::path::PathBuf; - /// - /// let mut x = PathBuf::from("/foo"); - /// x.push("bar"); - /// assert_eq!(x, PathBuf::from("/foo/bar")); - /// ``` - pub PATH_BUF_PUSH_OVERWRITE, - nursery, - "calling `push` with file system root on `PathBuf` can overwrite it" -} - -declare_lint_pass!(PathBufPushOverwrite => [PATH_BUF_PUSH_OVERWRITE]); - -impl<'tcx> LateLintPass<'tcx> for PathBufPushOverwrite { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if_chain! { - if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; - if path.ident.name == sym!(push); - if args.len() == 2; - if match_type(cx, cx.typeck_results().expr_ty(&args[0]).peel_refs(), &paths::PATH_BUF); - if let Some(get_index_arg) = args.get(1); - if let ExprKind::Lit(ref lit) = get_index_arg.kind; - if let LitKind::Str(ref path_lit, _) = lit.node; - if let pushed_path = Path::new(&*path_lit.as_str()); - if let Some(pushed_path_lit) = pushed_path.to_str(); - if pushed_path.has_root(); - if let Some(root) = pushed_path.components().next(); - if root == Component::RootDir; - then { - span_lint_and_sugg( - cx, - PATH_BUF_PUSH_OVERWRITE, - lit.span, - "calling `push` with '/' or '\\' (file system root) will overwrite the previous path definition", - "try", - format!("\"{}\"", pushed_path_lit.trim_start_matches(|c| c == '/' || c == '\\')), - Applicability::MachineApplicable, - ); - } - } - } -} diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs deleted file mode 100644 index 5539331d0460..000000000000 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ /dev/null @@ -1,311 +0,0 @@ -use crate::utils::{last_path_segment, span_lint_and_help}; -use rustc_hir::{ - intravisit, Body, Expr, ExprKind, FieldPat, FnDecl, HirId, LocalSource, MatchSource, Mutability, Pat, PatKind, - QPath, Stmt, StmtKind, -}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::subst::SubstsRef; -use rustc_middle::ty::{AdtDef, FieldDef, Ty, TyKind, VariantDef}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for patterns that aren't exact representations of the types - /// they are applied to. - /// - /// To satisfy this lint, you will have to adjust either the expression that is matched - /// against or the pattern itself, as well as the bindings that are introduced by the - /// adjusted patterns. For matching you will have to either dereference the expression - /// with the `*` operator, or amend the patterns to explicitly match against `&` - /// or `&mut ` depending on the reference mutability. For the bindings you need - /// to use the inverse. You can leave them as plain bindings if you wish for the value - /// to be copied, but you must use `ref mut ` or `ref ` to construct - /// a reference into the matched structure. - /// - /// If you are looking for a way to learn about ownership semantics in more detail, it - /// is recommended to look at IDE options available to you to highlight types, lifetimes - /// and reference semantics in your code. The available tooling would expose these things - /// in a general way even outside of the various pattern matching mechanics. Of course - /// this lint can still be used to highlight areas of interest and ensure a good understanding - /// of ownership semantics. - /// - /// **Why is this bad?** It isn't bad in general. But in some contexts it can be desirable - /// because it increases ownership hints in the code, and will guard against some changes - /// in ownership. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// This example shows the basic adjustments necessary to satisfy the lint. Note how - /// the matched expression is explicitly dereferenced with `*` and the `inner` variable - /// is bound to a shared borrow via `ref inner`. - /// - /// ```rust,ignore - /// // Bad - /// let value = &Some(Box::new(23)); - /// match value { - /// Some(inner) => println!("{}", inner), - /// None => println!("none"), - /// } - /// - /// // Good - /// let value = &Some(Box::new(23)); - /// match *value { - /// Some(ref inner) => println!("{}", inner), - /// None => println!("none"), - /// } - /// ``` - /// - /// The following example demonstrates one of the advantages of the more verbose style. - /// Note how the second version uses `ref mut a` to explicitly declare `a` a shared mutable - /// borrow, while `b` is simply taken by value. This ensures that the loop body cannot - /// accidentally modify the wrong part of the structure. - /// - /// ```rust,ignore - /// // Bad - /// let mut values = vec![(2, 3), (3, 4)]; - /// for (a, b) in &mut values { - /// *a += *b; - /// } - /// - /// // Good - /// let mut values = vec![(2, 3), (3, 4)]; - /// for &mut (ref mut a, b) in &mut values { - /// *a += b; - /// } - /// ``` - pub PATTERN_TYPE_MISMATCH, - restriction, - "type of pattern does not match the expression type" -} - -declare_lint_pass!(PatternTypeMismatch => [PATTERN_TYPE_MISMATCH]); - -impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch { - fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { - if let StmtKind::Local(ref local) = stmt.kind { - if let Some(init) = &local.init { - if let Some(init_ty) = cx.typeck_results().node_type_opt(init.hir_id) { - let pat = &local.pat; - if in_external_macro(cx.sess(), pat.span) { - return; - } - let deref_possible = match local.source { - LocalSource::Normal => DerefPossible::Possible, - _ => DerefPossible::Impossible, - }; - apply_lint(cx, pat, init_ty, deref_possible); - } - } - } - } - - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Match(ref expr, arms, source) = expr.kind { - match source { - MatchSource::Normal | MatchSource::IfLetDesugar { .. } | MatchSource::WhileLetDesugar => { - if let Some(expr_ty) = cx.typeck_results().node_type_opt(expr.hir_id) { - 'pattern_checks: for arm in arms { - let pat = &arm.pat; - if in_external_macro(cx.sess(), pat.span) { - continue 'pattern_checks; - } - if apply_lint(cx, pat, expr_ty, DerefPossible::Possible) { - break 'pattern_checks; - } - } - } - }, - _ => (), - } - } - } - - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - _: intravisit::FnKind<'tcx>, - _: &'tcx FnDecl<'_>, - body: &'tcx Body<'_>, - _: Span, - hir_id: HirId, - ) { - if let Some(fn_sig) = cx.typeck_results().liberated_fn_sigs().get(hir_id) { - for (param, ty) in body.params.iter().zip(fn_sig.inputs().iter()) { - apply_lint(cx, ¶m.pat, ty, DerefPossible::Impossible); - } - } - } -} - -#[derive(Debug, Clone, Copy)] -enum DerefPossible { - Possible, - Impossible, -} - -fn apply_lint<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'_>, expr_ty: Ty<'tcx>, deref_possible: DerefPossible) -> bool { - let maybe_mismatch = find_first_mismatch(cx, pat, expr_ty, Level::Top); - if let Some((span, mutability, level)) = maybe_mismatch { - span_lint_and_help( - cx, - PATTERN_TYPE_MISMATCH, - span, - "type of pattern does not match the expression type", - None, - &format!( - "{}explicitly match against a `{}` pattern and adjust the enclosed variable bindings", - match (deref_possible, level) { - (DerefPossible::Possible, Level::Top) => "use `*` to dereference the match expression or ", - _ => "", - }, - match mutability { - Mutability::Mut => "&mut _", - Mutability::Not => "&_", - }, - ), - ); - true - } else { - false - } -} - -#[derive(Debug, Copy, Clone)] -enum Level { - Top, - Lower, -} - -#[allow(rustc::usage_of_ty_tykind)] -fn find_first_mismatch<'tcx>( - cx: &LateContext<'tcx>, - pat: &Pat<'_>, - ty: Ty<'tcx>, - level: Level, -) -> Option<(Span, Mutability, Level)> { - if let PatKind::Ref(ref sub_pat, _) = pat.kind { - if let TyKind::Ref(_, sub_ty, _) = ty.kind() { - return find_first_mismatch(cx, sub_pat, sub_ty, Level::Lower); - } - } - - if let TyKind::Ref(_, _, mutability) = *ty.kind() { - if is_non_ref_pattern(&pat.kind) { - return Some((pat.span, mutability, level)); - } - } - - if let PatKind::Struct(ref qpath, ref field_pats, _) = pat.kind { - if let TyKind::Adt(ref adt_def, ref substs_ref) = ty.kind() { - if let Some(variant) = get_variant(adt_def, qpath) { - let field_defs = &variant.fields; - return find_first_mismatch_in_struct(cx, field_pats, field_defs, substs_ref); - } - } - } - - if let PatKind::TupleStruct(ref qpath, ref pats, _) = pat.kind { - if let TyKind::Adt(ref adt_def, ref substs_ref) = ty.kind() { - if let Some(variant) = get_variant(adt_def, qpath) { - let field_defs = &variant.fields; - let ty_iter = field_defs.iter().map(|field_def| field_def.ty(cx.tcx, substs_ref)); - return find_first_mismatch_in_tuple(cx, pats, ty_iter); - } - } - } - - if let PatKind::Tuple(ref pats, _) = pat.kind { - if let TyKind::Tuple(..) = ty.kind() { - return find_first_mismatch_in_tuple(cx, pats, ty.tuple_fields()); - } - } - - if let PatKind::Or(sub_pats) = pat.kind { - for pat in sub_pats { - let maybe_mismatch = find_first_mismatch(cx, pat, ty, level); - if let Some(mismatch) = maybe_mismatch { - return Some(mismatch); - } - } - } - - None -} - -fn get_variant<'a>(adt_def: &'a AdtDef, qpath: &QPath<'_>) -> Option<&'a VariantDef> { - if adt_def.is_struct() { - if let Some(variant) = adt_def.variants.iter().next() { - return Some(variant); - } - } - - if adt_def.is_enum() { - let pat_ident = last_path_segment(qpath).ident; - for variant in &adt_def.variants { - if variant.ident == pat_ident { - return Some(variant); - } - } - } - - None -} - -fn find_first_mismatch_in_tuple<'tcx, I>( - cx: &LateContext<'tcx>, - pats: &[&Pat<'_>], - ty_iter_src: I, -) -> Option<(Span, Mutability, Level)> -where - I: IntoIterator>, -{ - let mut field_tys = ty_iter_src.into_iter(); - 'fields: for pat in pats { - let field_ty = if let Some(ty) = field_tys.next() { - ty - } else { - break 'fields; - }; - - let maybe_mismatch = find_first_mismatch(cx, pat, field_ty, Level::Lower); - if let Some(mismatch) = maybe_mismatch { - return Some(mismatch); - } - } - - None -} - -fn find_first_mismatch_in_struct<'tcx>( - cx: &LateContext<'tcx>, - field_pats: &[FieldPat<'_>], - field_defs: &[FieldDef], - substs_ref: SubstsRef<'tcx>, -) -> Option<(Span, Mutability, Level)> { - for field_pat in field_pats { - 'definitions: for field_def in field_defs { - if field_pat.ident == field_def.ident { - let field_ty = field_def.ty(cx.tcx, substs_ref); - let pat = &field_pat.pat; - let maybe_mismatch = find_first_mismatch(cx, pat, field_ty, Level::Lower); - if let Some(mismatch) = maybe_mismatch { - return Some(mismatch); - } - break 'definitions; - } - } - } - - None -} - -fn is_non_ref_pattern(pat_kind: &PatKind<'_>) -> bool { - match pat_kind { - PatKind::Struct(..) | PatKind::Tuple(..) | PatKind::TupleStruct(..) | PatKind::Path(..) => true, - PatKind::Or(sub_pats) => sub_pats.iter().any(|pat| is_non_ref_pattern(&pat.kind)), - _ => false, - } -} diff --git a/clippy_lints/src/precedence.rs b/clippy_lints/src/precedence.rs deleted file mode 100644 index c9d18c3cb728..000000000000 --- a/clippy_lints/src/precedence.rs +++ /dev/null @@ -1,159 +0,0 @@ -use crate::utils::{snippet_with_applicability, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_ast::ast::{BinOpKind, Expr, ExprKind, LitKind, UnOp}; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Spanned; - -const ALLOWED_ODD_FUNCTIONS: [&str; 14] = [ - "asin", - "asinh", - "atan", - "atanh", - "cbrt", - "fract", - "round", - "signum", - "sin", - "sinh", - "tan", - "tanh", - "to_degrees", - "to_radians", -]; - -declare_clippy_lint! { - /// **What it does:** Checks for operations where precedence may be unclear - /// and suggests to add parentheses. Currently it catches the following: - /// * mixed usage of arithmetic and bit shifting/combining operators without - /// parentheses - /// * a "negative" numeric literal (which is really a unary `-` followed by a - /// numeric literal) - /// followed by a method call - /// - /// **Why is this bad?** Not everyone knows the precedence of those operators by - /// heart, so expressions like these may trip others trying to reason about the - /// code. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// * `1 << 2 + 3` equals 32, while `(1 << 2) + 3` equals 7 - /// * `-1i32.abs()` equals -1, while `(-1i32).abs()` equals 1 - pub PRECEDENCE, - complexity, - "operations where precedence may be unclear" -} - -declare_lint_pass!(Precedence => [PRECEDENCE]); - -impl EarlyLintPass for Precedence { - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - if expr.span.from_expansion() { - return; - } - - if let ExprKind::Binary(Spanned { node: op, .. }, ref left, ref right) = expr.kind { - let span_sugg = |expr: &Expr, sugg, appl| { - span_lint_and_sugg( - cx, - PRECEDENCE, - expr.span, - "operator precedence can trip the unwary", - "consider parenthesizing your expression", - sugg, - appl, - ); - }; - - if !is_bit_op(op) { - return; - } - let mut applicability = Applicability::MachineApplicable; - match (is_arith_expr(left), is_arith_expr(right)) { - (true, true) => { - let sugg = format!( - "({}) {} ({})", - snippet_with_applicability(cx, left.span, "..", &mut applicability), - op.to_string(), - snippet_with_applicability(cx, right.span, "..", &mut applicability) - ); - span_sugg(expr, sugg, applicability); - }, - (true, false) => { - let sugg = format!( - "({}) {} {}", - snippet_with_applicability(cx, left.span, "..", &mut applicability), - op.to_string(), - snippet_with_applicability(cx, right.span, "..", &mut applicability) - ); - span_sugg(expr, sugg, applicability); - }, - (false, true) => { - let sugg = format!( - "{} {} ({})", - snippet_with_applicability(cx, left.span, "..", &mut applicability), - op.to_string(), - snippet_with_applicability(cx, right.span, "..", &mut applicability) - ); - span_sugg(expr, sugg, applicability); - }, - (false, false) => (), - } - } - - if let ExprKind::Unary(UnOp::Neg, operand) = &expr.kind { - let mut arg = operand; - - let mut all_odd = true; - while let ExprKind::MethodCall(path_segment, args, _) = &arg.kind { - let path_segment_str = path_segment.ident.name.as_str(); - all_odd &= ALLOWED_ODD_FUNCTIONS - .iter() - .any(|odd_function| **odd_function == *path_segment_str); - arg = args.first().expect("A method always has a receiver."); - } - - if_chain! { - if !all_odd; - if let ExprKind::Lit(lit) = &arg.kind; - if let LitKind::Int(..) | LitKind::Float(..) = &lit.kind; - then { - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - PRECEDENCE, - expr.span, - "unary minus has lower precedence than method call", - "consider adding parentheses to clarify your intent", - format!( - "-({})", - snippet_with_applicability(cx, operand.span, "..", &mut applicability) - ), - applicability, - ); - } - } - } - } -} - -fn is_arith_expr(expr: &Expr) -> bool { - match expr.kind { - ExprKind::Binary(Spanned { node: op, .. }, _, _) => is_arith_op(op), - _ => false, - } -} - -#[must_use] -fn is_bit_op(op: BinOpKind) -> bool { - use rustc_ast::ast::BinOpKind::{BitAnd, BitOr, BitXor, Shl, Shr}; - matches!(op, BitXor | BitAnd | BitOr | Shl | Shr) -} - -#[must_use] -fn is_arith_op(op: BinOpKind) -> bool { - use rustc_ast::ast::BinOpKind::{Add, Div, Mul, Rem, Sub}; - matches!(op, Add | Sub | Mul | Div | Rem) -} diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs deleted file mode 100644 index dcb643a28aeb..000000000000 --- a/clippy_lints/src/ptr.rs +++ /dev/null @@ -1,329 +0,0 @@ -//! Checks for usage of `&Vec[_]` and `&String`. - -use crate::utils::ptr::get_spans; -use crate::utils::{ - is_allowed, is_type_diagnostic_item, match_qpath, match_type, paths, snippet_opt, span_lint, span_lint_and_sugg, - span_lint_and_then, walk_ptrs_hir_ty, -}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{ - BinOpKind, BodyId, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, HirId, ImplItem, ImplItemKind, Item, ItemKind, - Lifetime, MutTy, Mutability, Node, PathSegment, QPath, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, -}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::{sym, MultiSpan}; -use std::borrow::Cow; - -declare_clippy_lint! { - /// **What it does:** This lint checks for function arguments of type `&String` - /// or `&Vec` unless the references are mutable. It will also suggest you - /// replace `.clone()` calls with the appropriate `.to_owned()`/`to_string()` - /// calls. - /// - /// **Why is this bad?** Requiring the argument to be of the specific size - /// makes the function less useful for no benefit; slices in the form of `&[T]` - /// or `&str` usually suffice and can be obtained from other types, too. - /// - /// **Known problems:** The lint does not follow data. So if you have an - /// argument `x` and write `let y = x; y.clone()` the lint will not suggest - /// changing that `.clone()` to `.to_owned()`. - /// - /// Other functions called from this function taking a `&String` or `&Vec` - /// argument may also fail to compile if you change the argument. Applying - /// this lint on them will fix the problem, but they may be in other crates. - /// - /// One notable example of a function that may cause issues, and which cannot - /// easily be changed due to being in the standard library is `Vec::contains`. - /// when called on a `Vec>`. If a `&Vec` is passed to that method then - /// it will compile, but if a `&[T]` is passed then it will not compile. - /// - /// ```ignore - /// fn cannot_take_a_slice(v: &Vec) -> bool { - /// let vec_of_vecs: Vec> = some_other_fn(); - /// - /// vec_of_vecs.contains(v) - /// } - /// ``` - /// - /// Also there may be `fn(&Vec)`-typed references pointing to your function. - /// If you have them, you will get a compiler error after applying this lint's - /// suggestions. You then have the choice to undo your changes or change the - /// type of the reference. - /// - /// Note that if the function is part of your public interface, there may be - /// other crates referencing it, of which you may not be aware. Carefully - /// deprecate the function before applying the lint suggestions in this case. - /// - /// **Example:** - /// ```ignore - /// // Bad - /// fn foo(&Vec) { .. } - /// - /// // Good - /// fn foo(&[u32]) { .. } - /// ``` - pub PTR_ARG, - style, - "fn arguments of the type `&Vec<...>` or `&String`, suggesting to use `&[...]` or `&str` instead, respectively" -} - -declare_clippy_lint! { - /// **What it does:** This lint checks for equality comparisons with `ptr::null` - /// - /// **Why is this bad?** It's easier and more readable to use the inherent - /// `.is_null()` - /// method instead - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// // Bad - /// if x == ptr::null { - /// .. - /// } - /// - /// // Good - /// if x.is_null() { - /// .. - /// } - /// ``` - pub CMP_NULL, - style, - "comparing a pointer to a null pointer, suggesting to use `.is_null()` instead." -} - -declare_clippy_lint! { - /// **What it does:** This lint checks for functions that take immutable - /// references and return mutable ones. - /// - /// **Why is this bad?** This is trivially unsound, as one can create two - /// mutable references from the same (immutable!) source. - /// This [error](https://github.com/rust-lang/rust/issues/39465) - /// actually lead to an interim Rust release 1.15.1. - /// - /// **Known problems:** To be on the conservative side, if there's at least one - /// mutable reference with the output lifetime, this lint will not trigger. - /// In practice, this case is unlikely anyway. - /// - /// **Example:** - /// ```ignore - /// fn foo(&Foo) -> &mut Bar { .. } - /// ``` - pub MUT_FROM_REF, - correctness, - "fns that create mutable refs from immutable ref args" -} - -declare_lint_pass!(Ptr => [PTR_ARG, CMP_NULL, MUT_FROM_REF]); - -impl<'tcx> LateLintPass<'tcx> for Ptr { - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Fn(ref sig, _, body_id) = item.kind { - check_fn(cx, &sig.decl, item.hir_id, Some(body_id)); - } - } - - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { - if let ImplItemKind::Fn(ref sig, body_id) = item.kind { - let parent_item = cx.tcx.hir().get_parent_item(item.hir_id); - if let Some(Node::Item(it)) = cx.tcx.hir().find(parent_item) { - if let ItemKind::Impl { of_trait: Some(_), .. } = it.kind { - return; // ignore trait impls - } - } - check_fn(cx, &sig.decl, item.hir_id, Some(body_id)); - } - } - - fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { - if let TraitItemKind::Fn(ref sig, ref trait_method) = item.kind { - let body_id = if let TraitFn::Provided(b) = *trait_method { - Some(b) - } else { - None - }; - check_fn(cx, &sig.decl, item.hir_id, body_id); - } - } - - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Binary(ref op, ref l, ref r) = expr.kind { - if (op.node == BinOpKind::Eq || op.node == BinOpKind::Ne) && (is_null_path(l) || is_null_path(r)) { - span_lint( - cx, - CMP_NULL, - expr.span, - "comparing with null is better expressed by the `.is_null()` method", - ); - } - } - } -} - -#[allow(clippy::too_many_lines)] -fn check_fn(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_id: Option) { - let fn_def_id = cx.tcx.hir().local_def_id(fn_id); - let sig = cx.tcx.fn_sig(fn_def_id); - let fn_ty = sig.skip_binder(); - let body = opt_body_id.map(|id| cx.tcx.hir().body(id)); - - for (idx, (arg, ty)) in decl.inputs.iter().zip(fn_ty.inputs()).enumerate() { - // Honor the allow attribute on parameters. See issue 5644. - if let Some(body) = &body { - if is_allowed(cx, PTR_ARG, body.params[idx].hir_id) { - continue; - } - } - - if let ty::Ref(_, ty, Mutability::Not) = ty.kind() { - if is_type_diagnostic_item(cx, ty, sym::vec_type) { - let mut ty_snippet = None; - if_chain! { - if let TyKind::Path(QPath::Resolved(_, ref path)) = walk_ptrs_hir_ty(arg).kind; - if let Some(&PathSegment{args: Some(ref parameters), ..}) = path.segments.last(); - then { - let types: Vec<_> = parameters.args.iter().filter_map(|arg| match arg { - GenericArg::Type(ty) => Some(ty), - _ => None, - }).collect(); - if types.len() == 1 { - ty_snippet = snippet_opt(cx, types[0].span); - } - } - }; - if let Some(spans) = get_spans(cx, opt_body_id, idx, &[("clone", ".to_owned()")]) { - span_lint_and_then( - cx, - PTR_ARG, - arg.span, - "writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used \ - with non-Vec-based slices.", - |diag| { - if let Some(ref snippet) = ty_snippet { - diag.span_suggestion( - arg.span, - "change this to", - format!("&[{}]", snippet), - Applicability::Unspecified, - ); - } - for (clonespan, suggestion) in spans { - diag.span_suggestion( - clonespan, - &snippet_opt(cx, clonespan).map_or("change the call to".into(), |x| { - Cow::Owned(format!("change `{}` to", x)) - }), - suggestion.into(), - Applicability::Unspecified, - ); - } - }, - ); - } - } else if is_type_diagnostic_item(cx, ty, sym::string_type) { - if let Some(spans) = get_spans(cx, opt_body_id, idx, &[("clone", ".to_string()"), ("as_str", "")]) { - span_lint_and_then( - cx, - PTR_ARG, - arg.span, - "writing `&String` instead of `&str` involves a new object where a slice will do.", - |diag| { - diag.span_suggestion(arg.span, "change this to", "&str".into(), Applicability::Unspecified); - for (clonespan, suggestion) in spans { - diag.span_suggestion_short( - clonespan, - &snippet_opt(cx, clonespan).map_or("change the call to".into(), |x| { - Cow::Owned(format!("change `{}` to", x)) - }), - suggestion.into(), - Applicability::Unspecified, - ); - } - }, - ); - } - } else if match_type(cx, ty, &paths::COW) { - if_chain! { - if let TyKind::Rptr(_, MutTy { ref ty, ..} ) = arg.kind; - if let TyKind::Path(ref path) = ty.kind; - if let QPath::Resolved(None, ref pp) = *path; - if let [ref bx] = *pp.segments; - if let Some(ref params) = bx.args; - if !params.parenthesized; - if let Some(inner) = params.args.iter().find_map(|arg| match arg { - GenericArg::Type(ty) => Some(ty), - _ => None, - }); - then { - let replacement = snippet_opt(cx, inner.span); - if let Some(r) = replacement { - span_lint_and_sugg( - cx, - PTR_ARG, - arg.span, - "using a reference to `Cow` is not recommended.", - "change this to", - "&".to_owned() + &r, - Applicability::Unspecified, - ); - } - } - } - } - } - } - - if let FnRetTy::Return(ref ty) = decl.output { - if let Some((out, Mutability::Mut, _)) = get_rptr_lm(ty) { - let mut immutables = vec![]; - for (_, ref mutbl, ref argspan) in decl - .inputs - .iter() - .filter_map(|ty| get_rptr_lm(ty)) - .filter(|&(lt, _, _)| lt.name == out.name) - { - if *mutbl == Mutability::Mut { - return; - } - immutables.push(*argspan); - } - if immutables.is_empty() { - return; - } - span_lint_and_then( - cx, - MUT_FROM_REF, - ty.span, - "mutable borrow from immutable input(s)", - |diag| { - let ms = MultiSpan::from_spans(immutables); - diag.span_note(ms, "immutable borrow here"); - }, - ); - } - } -} - -fn get_rptr_lm<'tcx>(ty: &'tcx Ty<'tcx>) -> Option<(&'tcx Lifetime, Mutability, Span)> { - if let TyKind::Rptr(ref lt, ref m) = ty.kind { - Some((lt, m.mutbl, ty.span)) - } else { - None - } -} - -fn is_null_path(expr: &Expr<'_>) -> bool { - if let ExprKind::Call(ref pathexp, ref args) = expr.kind { - if args.is_empty() { - if let ExprKind::Path(ref path) = pathexp.kind { - return match_qpath(path, &paths::PTR_NULL) || match_qpath(path, &paths::PTR_NULL_MUT); - } - } - } - false -} diff --git a/clippy_lints/src/ptr_eq.rs b/clippy_lints/src/ptr_eq.rs deleted file mode 100644 index 3be792ce5e4f..000000000000 --- a/clippy_lints/src/ptr_eq.rs +++ /dev/null @@ -1,96 +0,0 @@ -use crate::utils; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{BinOpKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Use `std::ptr::eq` when applicable - /// - /// **Why is this bad?** `ptr::eq` can be used to compare `&T` references - /// (which coerce to `*const T` implicitly) by their address rather than - /// comparing the values they point to. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// let a = &[1, 2, 3]; - /// let b = &[1, 2, 3]; - /// - /// assert!(a as *const _ as usize == b as *const _ as usize); - /// ``` - /// Use instead: - /// ```rust - /// let a = &[1, 2, 3]; - /// let b = &[1, 2, 3]; - /// - /// assert!(std::ptr::eq(a, b)); - /// ``` - pub PTR_EQ, - style, - "use `std::ptr::eq` when comparing raw pointers" -} - -declare_lint_pass!(PtrEq => [PTR_EQ]); - -static LINT_MSG: &str = "use `std::ptr::eq` when comparing raw pointers"; - -impl LateLintPass<'_> for PtrEq { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if utils::in_macro(expr.span) { - return; - } - - if let ExprKind::Binary(ref op, ref left, ref right) = expr.kind { - if BinOpKind::Eq == op.node { - let (left, right) = match (expr_as_cast_to_usize(cx, left), expr_as_cast_to_usize(cx, right)) { - (Some(lhs), Some(rhs)) => (lhs, rhs), - _ => (&**left, &**right), - }; - - if_chain! { - if let Some(left_var) = expr_as_cast_to_raw_pointer(cx, left); - if let Some(right_var) = expr_as_cast_to_raw_pointer(cx, right); - if let Some(left_snip) = utils::snippet_opt(cx, left_var.span); - if let Some(right_snip) = utils::snippet_opt(cx, right_var.span); - then { - utils::span_lint_and_sugg( - cx, - PTR_EQ, - expr.span, - LINT_MSG, - "try", - format!("std::ptr::eq({}, {})", left_snip, right_snip), - Applicability::MachineApplicable, - ); - } - } - } - } - } -} - -// If the given expression is a cast to an usize, return the lhs of the cast -// E.g., `foo as *const _ as usize` returns `foo as *const _`. -fn expr_as_cast_to_usize<'tcx>(cx: &LateContext<'tcx>, cast_expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { - if cx.typeck_results().expr_ty(cast_expr) == cx.tcx.types.usize { - if let ExprKind::Cast(ref expr, _) = cast_expr.kind { - return Some(expr); - } - } - None -} - -// If the given expression is a cast to a `*const` pointer, return the lhs of the cast -// E.g., `foo as *const _` returns `foo`. -fn expr_as_cast_to_raw_pointer<'tcx>(cx: &LateContext<'tcx>, cast_expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { - if cx.typeck_results().expr_ty(cast_expr).is_unsafe_ptr() { - if let ExprKind::Cast(ref expr, _) = cast_expr.kind { - return Some(expr); - } - } - None -} diff --git a/clippy_lints/src/ptr_offset_with_cast.rs b/clippy_lints/src/ptr_offset_with_cast.rs deleted file mode 100644 index e0996804a593..000000000000 --- a/clippy_lints/src/ptr_offset_with_cast.rs +++ /dev/null @@ -1,151 +0,0 @@ -use crate::utils::{snippet_opt, span_lint, span_lint_and_sugg}; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; -use std::fmt; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of the `offset` pointer method with a `usize` casted to an - /// `isize`. - /// - /// **Why is this bad?** If we’re always increasing the pointer address, we can avoid the numeric - /// cast by using the `add` method instead. - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```rust - /// let vec = vec![b'a', b'b', b'c']; - /// let ptr = vec.as_ptr(); - /// let offset = 1_usize; - /// - /// unsafe { - /// ptr.offset(offset as isize); - /// } - /// ``` - /// - /// Could be written: - /// - /// ```rust - /// let vec = vec![b'a', b'b', b'c']; - /// let ptr = vec.as_ptr(); - /// let offset = 1_usize; - /// - /// unsafe { - /// ptr.add(offset); - /// } - /// ``` - pub PTR_OFFSET_WITH_CAST, - complexity, - "unneeded pointer offset cast" -} - -declare_lint_pass!(PtrOffsetWithCast => [PTR_OFFSET_WITH_CAST]); - -impl<'tcx> LateLintPass<'tcx> for PtrOffsetWithCast { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - // Check if the expressions is a ptr.offset or ptr.wrapping_offset method call - let (receiver_expr, arg_expr, method) = match expr_as_ptr_offset_call(cx, expr) { - Some(call_arg) => call_arg, - None => return, - }; - - // Check if the argument to the method call is a cast from usize - let cast_lhs_expr = match expr_as_cast_from_usize(cx, arg_expr) { - Some(cast_lhs_expr) => cast_lhs_expr, - None => return, - }; - - let msg = format!("use of `{}` with a `usize` casted to an `isize`", method); - if let Some(sugg) = build_suggestion(cx, method, receiver_expr, cast_lhs_expr) { - span_lint_and_sugg( - cx, - PTR_OFFSET_WITH_CAST, - expr.span, - &msg, - "try", - sugg, - Applicability::MachineApplicable, - ); - } else { - span_lint(cx, PTR_OFFSET_WITH_CAST, expr.span, &msg); - } - } -} - -// If the given expression is a cast from a usize, return the lhs of the cast -fn expr_as_cast_from_usize<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { - if let ExprKind::Cast(ref cast_lhs_expr, _) = expr.kind { - if is_expr_ty_usize(cx, &cast_lhs_expr) { - return Some(cast_lhs_expr); - } - } - None -} - -// If the given expression is a ptr::offset or ptr::wrapping_offset method call, return the -// receiver, the arg of the method call, and the method. -fn expr_as_ptr_offset_call<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx Expr<'_>, -) -> Option<(&'tcx Expr<'tcx>, &'tcx Expr<'tcx>, Method)> { - if let ExprKind::MethodCall(ref path_segment, _, ref args, _) = expr.kind { - if is_expr_ty_raw_ptr(cx, &args[0]) { - if path_segment.ident.name == sym::offset { - return Some((&args[0], &args[1], Method::Offset)); - } - if path_segment.ident.name == sym!(wrapping_offset) { - return Some((&args[0], &args[1], Method::WrappingOffset)); - } - } - } - None -} - -// Is the type of the expression a usize? -fn is_expr_ty_usize<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool { - cx.typeck_results().expr_ty(expr) == cx.tcx.types.usize -} - -// Is the type of the expression a raw pointer? -fn is_expr_ty_raw_ptr<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool { - cx.typeck_results().expr_ty(expr).is_unsafe_ptr() -} - -fn build_suggestion<'tcx>( - cx: &LateContext<'tcx>, - method: Method, - receiver_expr: &Expr<'_>, - cast_lhs_expr: &Expr<'_>, -) -> Option { - let receiver = snippet_opt(cx, receiver_expr.span)?; - let cast_lhs = snippet_opt(cx, cast_lhs_expr.span)?; - Some(format!("{}.{}({})", receiver, method.suggestion(), cast_lhs)) -} - -#[derive(Copy, Clone)] -enum Method { - Offset, - WrappingOffset, -} - -impl Method { - #[must_use] - fn suggestion(self) -> &'static str { - match self { - Self::Offset => "add", - Self::WrappingOffset => "wrapping_add", - } - } -} - -impl fmt::Display for Method { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::Offset => write!(f, "offset"), - Self::WrappingOffset => write!(f, "wrapping_offset"), - } - } -} diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs deleted file mode 100644 index b91233ac5828..000000000000 --- a/clippy_lints/src/question_mark.rs +++ /dev/null @@ -1,204 +0,0 @@ -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{def, BindingAnnotation, Block, Expr, ExprKind, MatchSource, PatKind, StmtKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; - -use crate::utils::sugg::Sugg; -use crate::utils::{ - eq_expr_value, higher, is_type_diagnostic_item, match_def_path, match_qpath, paths, snippet_with_applicability, - span_lint_and_sugg, -}; - -declare_clippy_lint! { - /// **What it does:** Checks for expressions that could be replaced by the question mark operator. - /// - /// **Why is this bad?** Question mark usage is more idiomatic. - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```ignore - /// if option.is_none() { - /// return None; - /// } - /// ``` - /// - /// Could be written: - /// - /// ```ignore - /// option?; - /// ``` - pub QUESTION_MARK, - style, - "checks for expressions that could be replaced by the question mark operator" -} - -declare_lint_pass!(QuestionMark => [QUESTION_MARK]); - -impl QuestionMark { - /// Checks if the given expression on the given context matches the following structure: - /// - /// ```ignore - /// if option.is_none() { - /// return None; - /// } - /// ``` - /// - /// If it matches, it will suggest to use the question mark operator instead - fn check_is_none_and_early_return_none(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let Some((if_expr, body, else_)) = higher::if_block(&expr); - if let ExprKind::MethodCall(segment, _, args, _) = &if_expr.kind; - if segment.ident.name == sym!(is_none); - if Self::expression_returns_none(cx, body); - if let Some(subject) = args.get(0); - if Self::is_option(cx, subject); - - then { - let mut applicability = Applicability::MachineApplicable; - let receiver_str = &Sugg::hir_with_applicability(cx, subject, "..", &mut applicability); - let mut replacement: Option = None; - if let Some(else_) = else_ { - if_chain! { - if let ExprKind::Block(block, None) = &else_.kind; - if block.stmts.is_empty(); - if let Some(block_expr) = &block.expr; - if eq_expr_value(cx, subject, block_expr); - then { - replacement = Some(format!("Some({}?)", receiver_str)); - } - } - } else if Self::moves_by_default(cx, subject) - && !matches!(subject.kind, ExprKind::Call(..) | ExprKind::MethodCall(..)) - { - replacement = Some(format!("{}.as_ref()?;", receiver_str)); - } else { - replacement = Some(format!("{}?;", receiver_str)); - } - - if let Some(replacement_str) = replacement { - span_lint_and_sugg( - cx, - QUESTION_MARK, - expr.span, - "this block may be rewritten with the `?` operator", - "replace it with", - replacement_str, - applicability, - ) - } - } - } - } - - fn check_if_let_some_and_early_return_none(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::Match(subject, arms, source) = &expr.kind; - if *source == MatchSource::IfLetDesugar { contains_else_clause: true }; - if Self::is_option(cx, subject); - - if let PatKind::TupleStruct(path1, fields, None) = &arms[0].pat.kind; - if match_qpath(path1, &["Some"]); - if let PatKind::Binding(annot, _, bind, _) = &fields[0].kind; - let by_ref = matches!(annot, BindingAnnotation::Ref | BindingAnnotation::RefMut); - - if let ExprKind::Block(block, None) = &arms[0].body.kind; - if block.stmts.is_empty(); - if let Some(trailing_expr) = &block.expr; - if let ExprKind::Path(path) = &trailing_expr.kind; - if match_qpath(path, &[&bind.as_str()]); - - if let PatKind::Wild = arms[1].pat.kind; - if Self::expression_returns_none(cx, arms[1].body); - then { - let mut applicability = Applicability::MachineApplicable; - let receiver_str = snippet_with_applicability(cx, subject.span, "..", &mut applicability); - let replacement = format!( - "{}{}?", - receiver_str, - if by_ref { ".as_ref()" } else { "" }, - ); - - span_lint_and_sugg( - cx, - QUESTION_MARK, - expr.span, - "this if-let-else may be rewritten with the `?` operator", - "replace it with", - replacement, - applicability, - ) - } - } - } - - fn moves_by_default(cx: &LateContext<'_>, expression: &Expr<'_>) -> bool { - let expr_ty = cx.typeck_results().expr_ty(expression); - - !expr_ty.is_copy_modulo_regions(cx.tcx.at(expression.span), cx.param_env) - } - - fn is_option(cx: &LateContext<'_>, expression: &Expr<'_>) -> bool { - let expr_ty = cx.typeck_results().expr_ty(expression); - - is_type_diagnostic_item(cx, expr_ty, sym::option_type) - } - - fn expression_returns_none(cx: &LateContext<'_>, expression: &Expr<'_>) -> bool { - match expression.kind { - ExprKind::Block(ref block, _) => { - if let Some(return_expression) = Self::return_expression(block) { - return Self::expression_returns_none(cx, &return_expression); - } - - false - }, - ExprKind::Ret(Some(ref expr)) => Self::expression_returns_none(cx, expr), - ExprKind::Path(ref qp) => { - if let Res::Def(DefKind::Ctor(def::CtorOf::Variant, def::CtorKind::Const), def_id) = - cx.qpath_res(qp, expression.hir_id) - { - return match_def_path(cx, def_id, &paths::OPTION_NONE); - } - - false - }, - _ => false, - } - } - - fn return_expression<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<'tcx>> { - // Check if last expression is a return statement. Then, return the expression - if_chain! { - if block.stmts.len() == 1; - if let Some(expr) = block.stmts.iter().last(); - if let StmtKind::Semi(ref expr) = expr.kind; - if let ExprKind::Ret(Some(ret_expr)) = expr.kind; - - then { - return Some(ret_expr); - } - } - - // Check for `return` without a semicolon. - if_chain! { - if block.stmts.is_empty(); - if let Some(ExprKind::Ret(Some(ret_expr))) = block.expr.as_ref().map(|e| &e.kind); - then { - return Some(ret_expr); - } - } - - None - } -} - -impl<'tcx> LateLintPass<'tcx> for QuestionMark { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - Self::check_is_none_and_early_return_none(cx, expr); - Self::check_if_let_some_and_early_return_none(cx, expr); - } -} diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs deleted file mode 100644 index 3e454eecd970..000000000000 --- a/clippy_lints/src/ranges.rs +++ /dev/null @@ -1,542 +0,0 @@ -use crate::consts::{constant, Constant}; -use if_chain::if_chain; -use rustc_ast::ast::RangeLimits; -use rustc_errors::Applicability; -use rustc_hir::{BinOpKind, Expr, ExprKind, PathSegment, QPath}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::ty; -use rustc_semver::RustcVersion; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::{Span, Spanned}; -use rustc_span::sym; -use rustc_span::symbol::Ident; -use std::cmp::Ordering; - -use crate::utils::sugg::Sugg; -use crate::utils::{ - get_parent_expr, in_constant, is_integer_const, meets_msrv, single_segment_path, snippet, snippet_opt, - snippet_with_applicability, span_lint, span_lint_and_sugg, span_lint_and_then, -}; -use crate::utils::{higher, SpanlessEq}; - -declare_clippy_lint! { - /// **What it does:** Checks for zipping a collection with the range of - /// `0.._.len()`. - /// - /// **Why is this bad?** The code is better expressed with `.enumerate()`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let x = vec![1]; - /// x.iter().zip(0..x.len()); - /// ``` - /// Could be written as - /// ```rust - /// # let x = vec![1]; - /// x.iter().enumerate(); - /// ``` - pub RANGE_ZIP_WITH_LEN, - complexity, - "zipping iterator with a range when `enumerate()` would do" -} - -declare_clippy_lint! { - /// **What it does:** Checks for exclusive ranges where 1 is added to the - /// upper bound, e.g., `x..(y+1)`. - /// - /// **Why is this bad?** The code is more readable with an inclusive range - /// like `x..=y`. - /// - /// **Known problems:** Will add unnecessary pair of parentheses when the - /// expression is not wrapped in a pair but starts with a opening parenthesis - /// and ends with a closing one. - /// I.e., `let _ = (f()+1)..(f()+1)` results in `let _ = ((f()+1)..=f())`. - /// - /// Also in many cases, inclusive ranges are still slower to run than - /// exclusive ranges, because they essentially add an extra branch that - /// LLVM may fail to hoist out of the loop. - /// - /// This will cause a warning that cannot be fixed if the consumer of the - /// range only accepts a specific range type, instead of the generic - /// `RangeBounds` trait - /// ([#3307](https://github.com/rust-lang/rust-clippy/issues/3307)). - /// - /// **Example:** - /// ```rust,ignore - /// for x..(y+1) { .. } - /// ``` - /// Could be written as - /// ```rust,ignore - /// for x..=y { .. } - /// ``` - pub RANGE_PLUS_ONE, - pedantic, - "`x..(y+1)` reads better as `x..=y`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for inclusive ranges where 1 is subtracted from - /// the upper bound, e.g., `x..=(y-1)`. - /// - /// **Why is this bad?** The code is more readable with an exclusive range - /// like `x..y`. - /// - /// **Known problems:** This will cause a warning that cannot be fixed if - /// the consumer of the range only accepts a specific range type, instead of - /// the generic `RangeBounds` trait - /// ([#3307](https://github.com/rust-lang/rust-clippy/issues/3307)). - /// - /// **Example:** - /// ```rust,ignore - /// for x..=(y-1) { .. } - /// ``` - /// Could be written as - /// ```rust,ignore - /// for x..y { .. } - /// ``` - pub RANGE_MINUS_ONE, - pedantic, - "`x..=(y-1)` reads better as `x..y`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for range expressions `x..y` where both `x` and `y` - /// are constant and `x` is greater or equal to `y`. - /// - /// **Why is this bad?** Empty ranges yield no values so iterating them is a no-op. - /// Moreover, trying to use a reversed range to index a slice will panic at run-time. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust,no_run - /// fn main() { - /// (10..=0).for_each(|x| println!("{}", x)); - /// - /// let arr = [1, 2, 3, 4, 5]; - /// let sub = &arr[3..1]; - /// } - /// ``` - /// Use instead: - /// ```rust - /// fn main() { - /// (0..=10).rev().for_each(|x| println!("{}", x)); - /// - /// let arr = [1, 2, 3, 4, 5]; - /// let sub = &arr[1..3]; - /// } - /// ``` - pub REVERSED_EMPTY_RANGES, - correctness, - "reversing the limits of range expressions, resulting in empty ranges" -} - -declare_clippy_lint! { - /// **What it does:** Checks for expressions like `x >= 3 && x < 8` that could - /// be more readably expressed as `(3..8).contains(x)`. - /// - /// **Why is this bad?** `contains` expresses the intent better and has less - /// failure modes (such as fencepost errors or using `||` instead of `&&`). - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// // given - /// let x = 6; - /// - /// assert!(x >= 3 && x < 8); - /// ``` - /// Use instead: - /// ```rust - ///# let x = 6; - /// assert!((3..8).contains(&x)); - /// ``` - pub MANUAL_RANGE_CONTAINS, - style, - "manually reimplementing {`Range`, `RangeInclusive`}`::contains`" -} - -const MANUAL_RANGE_CONTAINS_MSRV: RustcVersion = RustcVersion::new(1, 35, 0); - -pub struct Ranges { - msrv: Option, -} - -impl Ranges { - #[must_use] - pub fn new(msrv: Option) -> Self { - Self { msrv } - } -} - -impl_lint_pass!(Ranges => [ - RANGE_ZIP_WITH_LEN, - RANGE_PLUS_ONE, - RANGE_MINUS_ONE, - REVERSED_EMPTY_RANGES, - MANUAL_RANGE_CONTAINS, -]); - -impl<'tcx> LateLintPass<'tcx> for Ranges { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - match expr.kind { - ExprKind::MethodCall(ref path, _, ref args, _) => { - check_range_zip_with_len(cx, path, args, expr.span); - }, - ExprKind::Binary(ref op, ref l, ref r) => { - if meets_msrv(self.msrv.as_ref(), &MANUAL_RANGE_CONTAINS_MSRV) { - check_possible_range_contains(cx, op.node, l, r, expr); - } - }, - _ => {}, - } - - check_exclusive_range_plus_one(cx, expr); - check_inclusive_range_minus_one(cx, expr); - check_reversed_empty_range(cx, expr); - } - extract_msrv_attr!(LateContext); -} - -fn check_possible_range_contains(cx: &LateContext<'_>, op: BinOpKind, l: &Expr<'_>, r: &Expr<'_>, expr: &Expr<'_>) { - if in_constant(cx, expr.hir_id) { - return; - } - - let span = expr.span; - let combine_and = match op { - BinOpKind::And | BinOpKind::BitAnd => true, - BinOpKind::Or | BinOpKind::BitOr => false, - _ => return, - }; - // value, name, order (higher/lower), inclusiveness - if let (Some((lval, lname, name_span, lval_span, lord, linc)), Some((rval, rname, _, rval_span, rord, rinc))) = - (check_range_bounds(cx, l), check_range_bounds(cx, r)) - { - // we only lint comparisons on the same name and with different - // direction - if lname != rname || lord == rord { - return; - } - let ord = Constant::partial_cmp(cx.tcx, cx.typeck_results().expr_ty(l), &lval, &rval); - if combine_and && ord == Some(rord) { - // order lower bound and upper bound - let (l_span, u_span, l_inc, u_inc) = if rord == Ordering::Less { - (lval_span, rval_span, linc, rinc) - } else { - (rval_span, lval_span, rinc, linc) - }; - // we only lint inclusive lower bounds - if !l_inc { - return; - } - let (range_type, range_op) = if u_inc { - ("RangeInclusive", "..=") - } else { - ("Range", "..") - }; - let mut applicability = Applicability::MachineApplicable; - let name = snippet_with_applicability(cx, name_span, "_", &mut applicability); - let lo = snippet_with_applicability(cx, l_span, "_", &mut applicability); - let hi = snippet_with_applicability(cx, u_span, "_", &mut applicability); - let space = if lo.ends_with('.') { " " } else { "" }; - span_lint_and_sugg( - cx, - MANUAL_RANGE_CONTAINS, - span, - &format!("manual `{}::contains` implementation", range_type), - "use", - format!("({}{}{}{}).contains(&{})", lo, space, range_op, hi, name), - applicability, - ); - } else if !combine_and && ord == Some(lord) { - // `!_.contains(_)` - // order lower bound and upper bound - let (l_span, u_span, l_inc, u_inc) = if lord == Ordering::Less { - (lval_span, rval_span, linc, rinc) - } else { - (rval_span, lval_span, rinc, linc) - }; - if l_inc { - return; - } - let (range_type, range_op) = if u_inc { - ("Range", "..") - } else { - ("RangeInclusive", "..=") - }; - let mut applicability = Applicability::MachineApplicable; - let name = snippet_with_applicability(cx, name_span, "_", &mut applicability); - let lo = snippet_with_applicability(cx, l_span, "_", &mut applicability); - let hi = snippet_with_applicability(cx, u_span, "_", &mut applicability); - let space = if lo.ends_with('.') { " " } else { "" }; - span_lint_and_sugg( - cx, - MANUAL_RANGE_CONTAINS, - span, - &format!("manual `!{}::contains` implementation", range_type), - "use", - format!("!({}{}{}{}).contains(&{})", lo, space, range_op, hi, name), - applicability, - ); - } - } -} - -fn check_range_bounds(cx: &LateContext<'_>, ex: &Expr<'_>) -> Option<(Constant, Ident, Span, Span, Ordering, bool)> { - if let ExprKind::Binary(ref op, ref l, ref r) = ex.kind { - let (inclusive, ordering) = match op.node { - BinOpKind::Gt => (false, Ordering::Greater), - BinOpKind::Ge => (true, Ordering::Greater), - BinOpKind::Lt => (false, Ordering::Less), - BinOpKind::Le => (true, Ordering::Less), - _ => return None, - }; - if let Some(id) = match_ident(l) { - if let Some((c, _)) = constant(cx, cx.typeck_results(), r) { - return Some((c, id, l.span, r.span, ordering, inclusive)); - } - } else if let Some(id) = match_ident(r) { - if let Some((c, _)) = constant(cx, cx.typeck_results(), l) { - return Some((c, id, r.span, l.span, ordering.reverse(), inclusive)); - } - } - } - None -} - -fn match_ident(e: &Expr<'_>) -> Option { - if let ExprKind::Path(ref qpath) = e.kind { - if let Some(seg) = single_segment_path(qpath) { - if seg.args.is_none() { - return Some(seg.ident); - } - } - } - None -} - -fn check_range_zip_with_len(cx: &LateContext<'_>, path: &PathSegment<'_>, args: &[Expr<'_>], span: Span) { - let name = path.ident.as_str(); - if name == "zip" && args.len() == 2 { - let iter = &args[0].kind; - let zip_arg = &args[1]; - if_chain! { - // `.iter()` call - if let ExprKind::MethodCall(ref iter_path, _, ref iter_args, _) = *iter; - if iter_path.ident.name == sym::iter; - // range expression in `.zip()` call: `0..x.len()` - if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::range(zip_arg); - if is_integer_const(cx, start, 0); - // `.len()` call - if let ExprKind::MethodCall(ref len_path, _, ref len_args, _) = end.kind; - if len_path.ident.name == sym!(len) && len_args.len() == 1; - // `.iter()` and `.len()` called on same `Path` - if let ExprKind::Path(QPath::Resolved(_, ref iter_path)) = iter_args[0].kind; - if let ExprKind::Path(QPath::Resolved(_, ref len_path)) = len_args[0].kind; - if SpanlessEq::new(cx).eq_path_segments(&iter_path.segments, &len_path.segments); - then { - span_lint(cx, - RANGE_ZIP_WITH_LEN, - span, - &format!("it is more idiomatic to use `{}.iter().enumerate()`", - snippet(cx, iter_args[0].span, "_")) - ); - } - } - } -} - -// exclusive range plus one: `x..(y+1)` -fn check_exclusive_range_plus_one(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let Some(higher::Range { - start, - end: Some(end), - limits: RangeLimits::HalfOpen - }) = higher::range(expr); - if let Some(y) = y_plus_one(cx, end); - then { - let span = if expr.span.from_expansion() { - expr.span - .ctxt() - .outer_expn_data() - .call_site - } else { - expr.span - }; - span_lint_and_then( - cx, - RANGE_PLUS_ONE, - span, - "an inclusive range would be more readable", - |diag| { - let start = start.map_or(String::new(), |x| Sugg::hir(cx, x, "x").to_string()); - let end = Sugg::hir(cx, y, "y"); - if let Some(is_wrapped) = &snippet_opt(cx, span) { - if is_wrapped.starts_with('(') && is_wrapped.ends_with(')') { - diag.span_suggestion( - span, - "use", - format!("({}..={})", start, end), - Applicability::MaybeIncorrect, - ); - } else { - diag.span_suggestion( - span, - "use", - format!("{}..={}", start, end), - Applicability::MachineApplicable, // snippet - ); - } - } - }, - ); - } - } -} - -// inclusive range minus one: `x..=(y-1)` -fn check_inclusive_range_minus_one(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let Some(higher::Range { start, end: Some(end), limits: RangeLimits::Closed }) = higher::range(expr); - if let Some(y) = y_minus_one(cx, end); - then { - span_lint_and_then( - cx, - RANGE_MINUS_ONE, - expr.span, - "an exclusive range would be more readable", - |diag| { - let start = start.map_or(String::new(), |x| Sugg::hir(cx, x, "x").to_string()); - let end = Sugg::hir(cx, y, "y"); - diag.span_suggestion( - expr.span, - "use", - format!("{}..{}", start, end), - Applicability::MachineApplicable, // snippet - ); - }, - ); - } - } -} - -fn check_reversed_empty_range(cx: &LateContext<'_>, expr: &Expr<'_>) { - fn inside_indexing_expr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - matches!( - get_parent_expr(cx, expr), - Some(Expr { - kind: ExprKind::Index(..), - .. - }) - ) - } - - fn is_for_loop_arg(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - let mut cur_expr = expr; - while let Some(parent_expr) = get_parent_expr(cx, cur_expr) { - match higher::for_loop(parent_expr) { - Some((_, args, _)) if args.hir_id == expr.hir_id => return true, - _ => cur_expr = parent_expr, - } - } - - false - } - - fn is_empty_range(limits: RangeLimits, ordering: Ordering) -> bool { - match limits { - RangeLimits::HalfOpen => ordering != Ordering::Less, - RangeLimits::Closed => ordering == Ordering::Greater, - } - } - - if_chain! { - if let Some(higher::Range { start: Some(start), end: Some(end), limits }) = higher::range(expr); - let ty = cx.typeck_results().expr_ty(start); - if let ty::Int(_) | ty::Uint(_) = ty.kind(); - if let Some((start_idx, _)) = constant(cx, cx.typeck_results(), start); - if let Some((end_idx, _)) = constant(cx, cx.typeck_results(), end); - if let Some(ordering) = Constant::partial_cmp(cx.tcx, ty, &start_idx, &end_idx); - if is_empty_range(limits, ordering); - then { - if inside_indexing_expr(cx, expr) { - // Avoid linting `N..N` as it has proven to be useful, see #5689 and #5628 ... - if ordering != Ordering::Equal { - span_lint( - cx, - REVERSED_EMPTY_RANGES, - expr.span, - "this range is reversed and using it to index a slice will panic at run-time", - ); - } - // ... except in for loop arguments for backwards compatibility with `reverse_range_loop` - } else if ordering != Ordering::Equal || is_for_loop_arg(cx, expr) { - span_lint_and_then( - cx, - REVERSED_EMPTY_RANGES, - expr.span, - "this range is empty so it will yield no values", - |diag| { - if ordering != Ordering::Equal { - let start_snippet = snippet(cx, start.span, "_"); - let end_snippet = snippet(cx, end.span, "_"); - let dots = match limits { - RangeLimits::HalfOpen => "..", - RangeLimits::Closed => "..=" - }; - - diag.span_suggestion( - expr.span, - "consider using the following if you are attempting to iterate over this \ - range in reverse", - format!("({}{}{}).rev()", end_snippet, dots, start_snippet), - Applicability::MaybeIncorrect, - ); - } - }, - ); - } - } - } -} - -fn y_plus_one<'t>(cx: &LateContext<'_>, expr: &'t Expr<'_>) -> Option<&'t Expr<'t>> { - match expr.kind { - ExprKind::Binary( - Spanned { - node: BinOpKind::Add, .. - }, - ref lhs, - ref rhs, - ) => { - if is_integer_const(cx, lhs, 1) { - Some(rhs) - } else if is_integer_const(cx, rhs, 1) { - Some(lhs) - } else { - None - } - }, - _ => None, - } -} - -fn y_minus_one<'t>(cx: &LateContext<'_>, expr: &'t Expr<'_>) -> Option<&'t Expr<'t>> { - match expr.kind { - ExprKind::Binary( - Spanned { - node: BinOpKind::Sub, .. - }, - ref lhs, - ref rhs, - ) if is_integer_const(cx, rhs, 1) => Some(lhs), - _ => None, - } -} diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs deleted file mode 100644 index 06adbb523d70..000000000000 --- a/clippy_lints/src/redundant_clone.rs +++ /dev/null @@ -1,626 +0,0 @@ -use crate::utils::{ - fn_has_unsatisfiable_preds, has_drop, is_copy, is_type_diagnostic_item, match_def_path, match_type, paths, - snippet_opt, span_lint_hir, span_lint_hir_and_then, walk_ptrs_ty_depth, -}; -use if_chain::if_chain; -use rustc_data_structures::{fx::FxHashMap, transitive_relation::TransitiveRelation}; -use rustc_errors::Applicability; -use rustc_hir::intravisit::FnKind; -use rustc_hir::{def_id, Body, FnDecl, HirId}; -use rustc_index::bit_set::{BitSet, HybridBitSet}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::mir::{ - self, traversal, - visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor as _}, -}; -use rustc_middle::ty::{self, fold::TypeVisitor, Ty}; -use rustc_mir::dataflow::{Analysis, AnalysisDomain, GenKill, GenKillAnalysis, ResultsCursor}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::{BytePos, Span}; -use rustc_span::sym; -use std::convert::TryFrom; -use std::ops::ControlFlow; - -macro_rules! unwrap_or_continue { - ($x:expr) => { - match $x { - Some(x) => x, - None => continue, - } - }; -} - -declare_clippy_lint! { - /// **What it does:** Checks for a redundant `clone()` (and its relatives) which clones an owned - /// value that is going to be dropped without further use. - /// - /// **Why is this bad?** It is not always possible for the compiler to eliminate useless - /// allocations and deallocations generated by redundant `clone()`s. - /// - /// **Known problems:** - /// - /// False-negatives: analysis performed by this lint is conservative and limited. - /// - /// **Example:** - /// ```rust - /// # use std::path::Path; - /// # #[derive(Clone)] - /// # struct Foo; - /// # impl Foo { - /// # fn new() -> Self { Foo {} } - /// # } - /// # fn call(x: Foo) {} - /// { - /// let x = Foo::new(); - /// call(x.clone()); - /// call(x.clone()); // this can just pass `x` - /// } - /// - /// ["lorem", "ipsum"].join(" ").to_string(); - /// - /// Path::new("/a/b").join("c").to_path_buf(); - /// ``` - pub REDUNDANT_CLONE, - perf, - "`clone()` of an owned value that is going to be dropped immediately" -} - -declare_lint_pass!(RedundantClone => [REDUNDANT_CLONE]); - -impl<'tcx> LateLintPass<'tcx> for RedundantClone { - #[allow(clippy::too_many_lines)] - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - _: FnKind<'tcx>, - _: &'tcx FnDecl<'_>, - body: &'tcx Body<'_>, - _: Span, - _: HirId, - ) { - let def_id = cx.tcx.hir().body_owner_def_id(body.id()); - - // Building MIR for `fn`s with unsatisfiable preds results in ICE. - if fn_has_unsatisfiable_preds(cx, def_id.to_def_id()) { - return; - } - - let mir = cx.tcx.optimized_mir(def_id.to_def_id()); - - let maybe_storage_live_result = MaybeStorageLive - .into_engine(cx.tcx, mir) - .pass_name("redundant_clone") - .iterate_to_fixpoint() - .into_results_cursor(mir); - let mut possible_borrower = { - let mut vis = PossibleBorrowerVisitor::new(cx, mir); - vis.visit_body(&mir); - vis.into_map(cx, maybe_storage_live_result) - }; - - for (bb, bbdata) in mir.basic_blocks().iter_enumerated() { - let terminator = bbdata.terminator(); - - if terminator.source_info.span.from_expansion() { - continue; - } - - // Give up on loops - if terminator.successors().any(|s| *s == bb) { - continue; - } - - let (fn_def_id, arg, arg_ty, clone_ret) = - unwrap_or_continue!(is_call_with_ref_arg(cx, mir, &terminator.kind)); - - let from_borrow = match_def_path(cx, fn_def_id, &paths::CLONE_TRAIT_METHOD) - || match_def_path(cx, fn_def_id, &paths::TO_OWNED_METHOD) - || (match_def_path(cx, fn_def_id, &paths::TO_STRING_METHOD) - && is_type_diagnostic_item(cx, arg_ty, sym::string_type)); - - let from_deref = !from_borrow - && (match_def_path(cx, fn_def_id, &paths::PATH_TO_PATH_BUF) - || match_def_path(cx, fn_def_id, &paths::OS_STR_TO_OS_STRING)); - - if !from_borrow && !from_deref { - continue; - } - - if let ty::Adt(ref def, _) = arg_ty.kind() { - if match_def_path(cx, def.did, &paths::MEM_MANUALLY_DROP) { - continue; - } - } - - // `{ cloned = &arg; clone(move cloned); }` or `{ cloned = &arg; to_path_buf(cloned); }` - let (cloned, cannot_move_out) = unwrap_or_continue!(find_stmt_assigns_to(cx, mir, arg, from_borrow, bb)); - - let loc = mir::Location { - block: bb, - statement_index: bbdata.statements.len(), - }; - - // `Local` to be cloned, and a local of `clone` call's destination - let (local, ret_local) = if from_borrow { - // `res = clone(arg)` can be turned into `res = move arg;` - // if `arg` is the only borrow of `cloned` at this point. - - if cannot_move_out || !possible_borrower.only_borrowers(&[arg], cloned, loc) { - continue; - } - - (cloned, clone_ret) - } else { - // `arg` is a reference as it is `.deref()`ed in the previous block. - // Look into the predecessor block and find out the source of deref. - - let ps = &mir.predecessors()[bb]; - if ps.len() != 1 { - continue; - } - let pred_terminator = mir[ps[0]].terminator(); - - // receiver of the `deref()` call - let (pred_arg, deref_clone_ret) = if_chain! { - if let Some((pred_fn_def_id, pred_arg, pred_arg_ty, res)) = - is_call_with_ref_arg(cx, mir, &pred_terminator.kind); - if res == cloned; - if match_def_path(cx, pred_fn_def_id, &paths::DEREF_TRAIT_METHOD); - if match_type(cx, pred_arg_ty, &paths::PATH_BUF) - || match_type(cx, pred_arg_ty, &paths::OS_STRING); - then { - (pred_arg, res) - } else { - continue; - } - }; - - let (local, cannot_move_out) = - unwrap_or_continue!(find_stmt_assigns_to(cx, mir, pred_arg, true, ps[0])); - let loc = mir::Location { - block: bb, - statement_index: mir.basic_blocks()[bb].statements.len(), - }; - - // This can be turned into `res = move local` if `arg` and `cloned` are not borrowed - // at the last statement: - // - // ``` - // pred_arg = &local; - // cloned = deref(pred_arg); - // arg = &cloned; - // StorageDead(pred_arg); - // res = to_path_buf(cloned); - // ``` - if cannot_move_out || !possible_borrower.only_borrowers(&[arg, cloned], local, loc) { - continue; - } - - (local, deref_clone_ret) - }; - - let is_temp = mir.local_kind(ret_local) == mir::LocalKind::Temp; - - // 1. `local` can be moved out if it is not used later. - // 2. If `ret_local` is a temporary and is neither consumed nor mutated, we can remove this `clone` - // call anyway. - let (used, consumed_or_mutated) = traversal::ReversePostorder::new(&mir, bb).skip(1).fold( - (false, !is_temp), - |(used, consumed), (tbb, tdata)| { - // Short-circuit - if (used && consumed) || - // Give up on loops - tdata.terminator().successors().any(|s| *s == bb) - { - return (true, true); - } - - let mut vis = LocalUseVisitor { - used: (local, false), - consumed_or_mutated: (ret_local, false), - }; - vis.visit_basic_block_data(tbb, tdata); - (used || vis.used.1, consumed || vis.consumed_or_mutated.1) - }, - ); - - if !used || !consumed_or_mutated { - let span = terminator.source_info.span; - let scope = terminator.source_info.scope; - let node = mir.source_scopes[scope] - .local_data - .as_ref() - .assert_crate_local() - .lint_root; - - if_chain! { - if let Some(snip) = snippet_opt(cx, span); - if let Some(dot) = snip.rfind('.'); - then { - let sugg_span = span.with_lo( - span.lo() + BytePos(u32::try_from(dot).unwrap()) - ); - let mut app = Applicability::MaybeIncorrect; - - let call_snip = &snip[dot + 1..]; - // Machine applicable when `call_snip` looks like `foobar()` - if let Some(call_snip) = call_snip.strip_suffix("()").map(str::trim) { - if call_snip.as_bytes().iter().all(|b| b.is_ascii_alphabetic() || *b == b'_') { - app = Applicability::MachineApplicable; - } - } - - span_lint_hir_and_then(cx, REDUNDANT_CLONE, node, sugg_span, "redundant clone", |diag| { - diag.span_suggestion( - sugg_span, - "remove this", - String::new(), - app, - ); - if used { - diag.span_note( - span, - "cloned value is neither consumed nor mutated", - ); - } else { - diag.span_note( - span.with_hi(span.lo() + BytePos(u32::try_from(dot).unwrap())), - "this value is dropped without further use", - ); - } - }); - } else { - span_lint_hir(cx, REDUNDANT_CLONE, node, span, "redundant clone"); - } - } - } - } - } -} - -/// If `kind` is `y = func(x: &T)` where `T: !Copy`, returns `(DefId of func, x, T, y)`. -fn is_call_with_ref_arg<'tcx>( - cx: &LateContext<'tcx>, - mir: &'tcx mir::Body<'tcx>, - kind: &'tcx mir::TerminatorKind<'tcx>, -) -> Option<(def_id::DefId, mir::Local, Ty<'tcx>, mir::Local)> { - if_chain! { - if let mir::TerminatorKind::Call { func, args, destination, .. } = kind; - if args.len() == 1; - if let mir::Operand::Move(mir::Place { local, .. }) = &args[0]; - if let ty::FnDef(def_id, _) = *func.ty(&*mir, cx.tcx).kind(); - if let (inner_ty, 1) = walk_ptrs_ty_depth(args[0].ty(&*mir, cx.tcx)); - if !is_copy(cx, inner_ty); - then { - Some((def_id, *local, inner_ty, destination.as_ref().map(|(dest, _)| dest)?.as_local()?)) - } else { - None - } - } -} - -type CannotMoveOut = bool; - -/// Finds the first `to = (&)from`, and returns -/// ``Some((from, whether `from` cannot be moved out))``. -fn find_stmt_assigns_to<'tcx>( - cx: &LateContext<'tcx>, - mir: &mir::Body<'tcx>, - to_local: mir::Local, - by_ref: bool, - bb: mir::BasicBlock, -) -> Option<(mir::Local, CannotMoveOut)> { - let rvalue = mir.basic_blocks()[bb].statements.iter().rev().find_map(|stmt| { - if let mir::StatementKind::Assign(box (mir::Place { local, .. }, v)) = &stmt.kind { - return if *local == to_local { Some(v) } else { None }; - } - - None - })?; - - match (by_ref, &*rvalue) { - (true, mir::Rvalue::Ref(_, _, place)) | (false, mir::Rvalue::Use(mir::Operand::Copy(place))) => { - Some(base_local_and_movability(cx, mir, *place)) - }, - (false, mir::Rvalue::Ref(_, _, place)) => { - if let [mir::ProjectionElem::Deref] = place.as_ref().projection { - Some(base_local_and_movability(cx, mir, *place)) - } else { - None - } - }, - _ => None, - } -} - -/// Extracts and returns the undermost base `Local` of given `place`. Returns `place` itself -/// if it is already a `Local`. -/// -/// Also reports whether given `place` cannot be moved out. -fn base_local_and_movability<'tcx>( - cx: &LateContext<'tcx>, - mir: &mir::Body<'tcx>, - place: mir::Place<'tcx>, -) -> (mir::Local, CannotMoveOut) { - use rustc_middle::mir::PlaceRef; - - // Dereference. You cannot move things out from a borrowed value. - let mut deref = false; - // Accessing a field of an ADT that has `Drop`. Moving the field out will cause E0509. - let mut field = false; - // If projection is a slice index then clone can be removed only if the - // underlying type implements Copy - let mut slice = false; - - let PlaceRef { local, mut projection } = place.as_ref(); - while let [base @ .., elem] = projection { - projection = base; - deref |= matches!(elem, mir::ProjectionElem::Deref); - field |= matches!(elem, mir::ProjectionElem::Field(..)) - && has_drop(cx, mir::Place::ty_from(local, projection, &mir.local_decls, cx.tcx).ty); - slice |= matches!(elem, mir::ProjectionElem::Index(..)) - && !is_copy(cx, mir::Place::ty_from(local, projection, &mir.local_decls, cx.tcx).ty); - } - - (local, deref || field || slice) -} - -struct LocalUseVisitor { - used: (mir::Local, bool), - consumed_or_mutated: (mir::Local, bool), -} - -impl<'tcx> mir::visit::Visitor<'tcx> for LocalUseVisitor { - fn visit_basic_block_data(&mut self, block: mir::BasicBlock, data: &mir::BasicBlockData<'tcx>) { - let statements = &data.statements; - for (statement_index, statement) in statements.iter().enumerate() { - self.visit_statement(statement, mir::Location { block, statement_index }); - } - - self.visit_terminator( - data.terminator(), - mir::Location { - block, - statement_index: statements.len(), - }, - ); - } - - fn visit_place(&mut self, place: &mir::Place<'tcx>, ctx: PlaceContext, _: mir::Location) { - let local = place.local; - - if local == self.used.0 - && !matches!( - ctx, - PlaceContext::MutatingUse(MutatingUseContext::Drop) | PlaceContext::NonUse(_) - ) - { - self.used.1 = true; - } - - if local == self.consumed_or_mutated.0 { - match ctx { - PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) - | PlaceContext::MutatingUse(MutatingUseContext::Borrow) => { - self.consumed_or_mutated.1 = true; - }, - _ => {}, - } - } - } -} - -/// Determines liveness of each local purely based on `StorageLive`/`Dead`. -#[derive(Copy, Clone)] -struct MaybeStorageLive; - -impl<'tcx> AnalysisDomain<'tcx> for MaybeStorageLive { - type Domain = BitSet; - const NAME: &'static str = "maybe_storage_live"; - - fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain { - // bottom = dead - BitSet::new_empty(body.local_decls.len()) - } - - fn initialize_start_block(&self, body: &mir::Body<'tcx>, state: &mut Self::Domain) { - for arg in body.args_iter() { - state.insert(arg); - } - } -} - -impl<'tcx> GenKillAnalysis<'tcx> for MaybeStorageLive { - type Idx = mir::Local; - - fn statement_effect(&self, trans: &mut impl GenKill, stmt: &mir::Statement<'tcx>, _: mir::Location) { - match stmt.kind { - mir::StatementKind::StorageLive(l) => trans.gen(l), - mir::StatementKind::StorageDead(l) => trans.kill(l), - _ => (), - } - } - - fn terminator_effect( - &self, - _trans: &mut impl GenKill, - _terminator: &mir::Terminator<'tcx>, - _loc: mir::Location, - ) { - } - - fn call_return_effect( - &self, - _in_out: &mut impl GenKill, - _block: mir::BasicBlock, - _func: &mir::Operand<'tcx>, - _args: &[mir::Operand<'tcx>], - _return_place: mir::Place<'tcx>, - ) { - // Nothing to do when a call returns successfully - } -} - -/// Collects the possible borrowers of each local. -/// For example, `b = &a; c = &a;` will make `b` and (transitively) `c` -/// possible borrowers of `a`. -struct PossibleBorrowerVisitor<'a, 'tcx> { - possible_borrower: TransitiveRelation, - body: &'a mir::Body<'tcx>, - cx: &'a LateContext<'tcx>, -} - -impl<'a, 'tcx> PossibleBorrowerVisitor<'a, 'tcx> { - fn new(cx: &'a LateContext<'tcx>, body: &'a mir::Body<'tcx>) -> Self { - Self { - possible_borrower: TransitiveRelation::default(), - cx, - body, - } - } - - fn into_map( - self, - cx: &LateContext<'tcx>, - maybe_live: ResultsCursor<'tcx, 'tcx, MaybeStorageLive>, - ) -> PossibleBorrowerMap<'a, 'tcx> { - let mut map = FxHashMap::default(); - for row in (1..self.body.local_decls.len()).map(mir::Local::from_usize) { - if is_copy(cx, self.body.local_decls[row].ty) { - continue; - } - - let borrowers = self.possible_borrower.reachable_from(&row); - if !borrowers.is_empty() { - let mut bs = HybridBitSet::new_empty(self.body.local_decls.len()); - for &c in borrowers { - if c != mir::Local::from_usize(0) { - bs.insert(c); - } - } - - if !bs.is_empty() { - map.insert(row, bs); - } - } - } - - let bs = BitSet::new_empty(self.body.local_decls.len()); - PossibleBorrowerMap { - map, - maybe_live, - bitset: (bs.clone(), bs), - } - } -} - -impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { - fn visit_assign(&mut self, place: &mir::Place<'tcx>, rvalue: &mir::Rvalue<'_>, _location: mir::Location) { - let lhs = place.local; - match rvalue { - mir::Rvalue::Ref(_, _, borrowed) => { - self.possible_borrower.add(borrowed.local, lhs); - }, - other => { - if ContainsRegion - .visit_ty(place.ty(&self.body.local_decls, self.cx.tcx).ty) - .is_continue() - { - return; - } - rvalue_locals(other, |rhs| { - if lhs != rhs { - self.possible_borrower.add(rhs, lhs); - } - }); - }, - } - } - - fn visit_terminator(&mut self, terminator: &mir::Terminator<'_>, _loc: mir::Location) { - if let mir::TerminatorKind::Call { - args, - destination: Some((mir::Place { local: dest, .. }, _)), - .. - } = &terminator.kind - { - // If the call returns something with lifetimes, - // let's conservatively assume the returned value contains lifetime of all the arguments. - // For example, given `let y: Foo<'a> = foo(x)`, `y` is considered to be a possible borrower of `x`. - if ContainsRegion.visit_ty(&self.body.local_decls[*dest].ty).is_continue() { - return; - } - - for op in args { - match op { - mir::Operand::Copy(p) | mir::Operand::Move(p) => { - self.possible_borrower.add(p.local, *dest); - }, - _ => (), - } - } - } - } -} - -struct ContainsRegion; - -impl TypeVisitor<'_> for ContainsRegion { - type BreakTy = (); - - fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow { - ControlFlow::BREAK - } -} - -fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) { - use rustc_middle::mir::Rvalue::{Aggregate, BinaryOp, Cast, CheckedBinaryOp, Repeat, UnaryOp, Use}; - - let mut visit_op = |op: &mir::Operand<'_>| match op { - mir::Operand::Copy(p) | mir::Operand::Move(p) => visit(p.local), - _ => (), - }; - - match rvalue { - Use(op) | Repeat(op, _) | Cast(_, op, _) | UnaryOp(_, op) => visit_op(op), - Aggregate(_, ops) => ops.iter().for_each(visit_op), - BinaryOp(_, lhs, rhs) | CheckedBinaryOp(_, lhs, rhs) => { - visit_op(lhs); - visit_op(rhs); - }, - _ => (), - } -} - -/// Result of `PossibleBorrowerVisitor`. -struct PossibleBorrowerMap<'a, 'tcx> { - /// Mapping `Local -> its possible borrowers` - map: FxHashMap>, - maybe_live: ResultsCursor<'a, 'tcx, MaybeStorageLive>, - // Caches to avoid allocation of `BitSet` on every query - bitset: (BitSet, BitSet), -} - -impl PossibleBorrowerMap<'_, '_> { - /// Returns true if the set of borrowers of `borrowed` living at `at` matches with `borrowers`. - fn only_borrowers(&mut self, borrowers: &[mir::Local], borrowed: mir::Local, at: mir::Location) -> bool { - self.maybe_live.seek_after_primary_effect(at); - - self.bitset.0.clear(); - let maybe_live = &mut self.maybe_live; - if let Some(bitset) = self.map.get(&borrowed) { - for b in bitset.iter().filter(move |b| maybe_live.contains(*b)) { - self.bitset.0.insert(b); - } - } else { - return false; - } - - self.bitset.1.clear(); - for b in borrowers { - self.bitset.1.insert(*b); - } - - self.bitset.0 == self.bitset.1 - } -} diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs deleted file mode 100644 index f398b3fff25a..000000000000 --- a/clippy_lints/src/redundant_closure_call.rs +++ /dev/null @@ -1,156 +0,0 @@ -use crate::utils::{snippet_with_applicability, span_lint, span_lint_and_then}; -use if_chain::if_chain; -use rustc_ast::ast; -use rustc_ast::visit as ast_visit; -use rustc_ast::visit::Visitor as AstVisitor; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_hir::intravisit as hir_visit; -use rustc_hir::intravisit::Visitor as HirVisitor; -use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; -use rustc_middle::lint::in_external_macro; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Detects closures called in the same expression where they - /// are defined. - /// - /// **Why is this bad?** It is unnecessarily adding to the expression's - /// complexity. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// // Bad - /// let a = (|| 42)() - /// - /// // Good - /// let a = 42 - /// ``` - pub REDUNDANT_CLOSURE_CALL, - complexity, - "throwaway closures called in the expression they are defined" -} - -declare_lint_pass!(RedundantClosureCall => [REDUNDANT_CLOSURE_CALL]); - -// Used to find `return` statements or equivalents e.g., `?` -struct ReturnVisitor { - found_return: bool, -} - -impl ReturnVisitor { - #[must_use] - fn new() -> Self { - Self { found_return: false } - } -} - -impl<'ast> ast_visit::Visitor<'ast> for ReturnVisitor { - fn visit_expr(&mut self, ex: &'ast ast::Expr) { - if let ast::ExprKind::Ret(_) = ex.kind { - self.found_return = true; - } else if let ast::ExprKind::Try(_) = ex.kind { - self.found_return = true; - } - - ast_visit::walk_expr(self, ex) - } -} - -impl EarlyLintPass for RedundantClosureCall { - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { - if in_external_macro(cx.sess(), expr.span) { - return; - } - if_chain! { - if let ast::ExprKind::Call(ref paren, _) = expr.kind; - if let ast::ExprKind::Paren(ref closure) = paren.kind; - if let ast::ExprKind::Closure(_, _, _, ref decl, ref block, _) = closure.kind; - then { - let mut visitor = ReturnVisitor::new(); - visitor.visit_expr(block); - if !visitor.found_return { - span_lint_and_then( - cx, - REDUNDANT_CLOSURE_CALL, - expr.span, - "try not to call a closure in the expression where it is declared", - |diag| { - if decl.inputs.is_empty() { - let mut app = Applicability::MachineApplicable; - let hint = - snippet_with_applicability(cx, block.span, "..", &mut app).into_owned(); - diag.span_suggestion(expr.span, "try doing something like", hint, app); - } - }, - ); - } - } - } - } -} - -impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { - fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx hir::Block<'_>) { - fn count_closure_usage<'a, 'tcx>( - cx: &'a LateContext<'tcx>, - block: &'tcx hir::Block<'_>, - path: &'tcx hir::Path<'tcx>, - ) -> usize { - struct ClosureUsageCount<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - path: &'tcx hir::Path<'tcx>, - count: usize, - } - impl<'a, 'tcx> hir_visit::Visitor<'tcx> for ClosureUsageCount<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { - if_chain! { - if let hir::ExprKind::Call(ref closure, _) = expr.kind; - if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = closure.kind; - if self.path.segments[0].ident == path.segments[0].ident - && self.path.res == path.res; - then { - self.count += 1; - } - } - hir_visit::walk_expr(self, expr); - } - - fn nested_visit_map(&mut self) -> hir_visit::NestedVisitorMap { - hir_visit::NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) - } - } - let mut closure_usage_count = ClosureUsageCount { cx, path, count: 0 }; - closure_usage_count.visit_block(block); - closure_usage_count.count - } - - for w in block.stmts.windows(2) { - if_chain! { - if let hir::StmtKind::Local(ref local) = w[0].kind; - if let Option::Some(ref t) = local.init; - if let hir::ExprKind::Closure(..) = t.kind; - if let hir::PatKind::Binding(_, _, ident, _) = local.pat.kind; - if let hir::StmtKind::Semi(ref second) = w[1].kind; - if let hir::ExprKind::Assign(_, ref call, _) = second.kind; - if let hir::ExprKind::Call(ref closure, _) = call.kind; - if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = closure.kind; - if ident == path.segments[0].ident; - if count_closure_usage(cx, block, path) == 1; - then { - span_lint( - cx, - REDUNDANT_CLOSURE_CALL, - second.span, - "closure called just once immediately after it was declared", - ); - } - } - } - } -} diff --git a/clippy_lints/src/redundant_else.rs b/clippy_lints/src/redundant_else.rs deleted file mode 100644 index 3d585cd27a3d..000000000000 --- a/clippy_lints/src/redundant_else.rs +++ /dev/null @@ -1,135 +0,0 @@ -use crate::utils::span_lint_and_help; -use rustc_ast::ast::{Block, Expr, ExprKind, Stmt, StmtKind}; -use rustc_ast::visit::{walk_expr, Visitor}; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_middle::lint::in_external_macro; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for `else` blocks that can be removed without changing semantics. - /// - /// **Why is this bad?** The `else` block adds unnecessary indentation and verbosity. - /// - /// **Known problems:** Some may prefer to keep the `else` block for clarity. - /// - /// **Example:** - /// - /// ```rust - /// fn my_func(count: u32) { - /// if count == 0 { - /// print!("Nothing to do"); - /// return; - /// } else { - /// print!("Moving on..."); - /// } - /// } - /// ``` - /// Use instead: - /// ```rust - /// fn my_func(count: u32) { - /// if count == 0 { - /// print!("Nothing to do"); - /// return; - /// } - /// print!("Moving on..."); - /// } - /// ``` - pub REDUNDANT_ELSE, - pedantic, - "`else` branch that can be removed without changing semantics" -} - -declare_lint_pass!(RedundantElse => [REDUNDANT_ELSE]); - -impl EarlyLintPass for RedundantElse { - fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &Stmt) { - if in_external_macro(cx.sess, stmt.span) { - return; - } - // Only look at expressions that are a whole statement - let expr: &Expr = match &stmt.kind { - StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr, - _ => return, - }; - // if else - let (mut then, mut els): (&Block, &Expr) = match &expr.kind { - ExprKind::If(_, then, Some(els)) => (then, els), - _ => return, - }; - loop { - if !BreakVisitor::default().check_block(then) { - // then block does not always break - return; - } - match &els.kind { - // else if else - ExprKind::If(_, next_then, Some(next_els)) => { - then = next_then; - els = next_els; - continue; - }, - // else if without else - ExprKind::If(..) => return, - // done - _ => break, - } - } - span_lint_and_help( - cx, - REDUNDANT_ELSE, - els.span, - "redundant else block", - None, - "remove the `else` block and move the contents out", - ); - } -} - -/// Call `check` functions to check if an expression always breaks control flow -#[derive(Default)] -struct BreakVisitor { - is_break: bool, -} - -impl<'ast> Visitor<'ast> for BreakVisitor { - fn visit_block(&mut self, block: &'ast Block) { - self.is_break = match block.stmts.as_slice() { - [.., last] => self.check_stmt(last), - _ => false, - }; - } - - fn visit_expr(&mut self, expr: &'ast Expr) { - self.is_break = match expr.kind { - ExprKind::Break(..) | ExprKind::Continue(..) | ExprKind::Ret(..) => true, - ExprKind::Match(_, ref arms) => arms.iter().all(|arm| self.check_expr(&arm.body)), - ExprKind::If(_, ref then, Some(ref els)) => self.check_block(then) && self.check_expr(els), - ExprKind::If(_, _, None) - // ignore loops for simplicity - | ExprKind::While(..) | ExprKind::ForLoop(..) | ExprKind::Loop(..) => false, - _ => { - walk_expr(self, expr); - return; - }, - }; - } -} - -impl BreakVisitor { - fn check(&mut self, item: T, visit: fn(&mut Self, T)) -> bool { - visit(self, item); - std::mem::replace(&mut self.is_break, false) - } - - fn check_block(&mut self, block: &Block) -> bool { - self.check(block, Self::visit_block) - } - - fn check_expr(&mut self, expr: &Expr) -> bool { - self.check(expr, Self::visit_expr) - } - - fn check_stmt(&mut self, stmt: &Stmt) -> bool { - self.check(stmt, Self::visit_stmt) - } -} diff --git a/clippy_lints/src/redundant_field_names.rs b/clippy_lints/src/redundant_field_names.rs deleted file mode 100644 index 38dcf7a192c8..000000000000 --- a/clippy_lints/src/redundant_field_names.rs +++ /dev/null @@ -1,86 +0,0 @@ -use crate::utils::{meets_msrv, span_lint_and_sugg}; -use rustc_ast::ast::{Expr, ExprKind}; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_middle::lint::in_external_macro; -use rustc_semver::RustcVersion; -use rustc_session::{declare_tool_lint, impl_lint_pass}; - -const REDUNDANT_FIELD_NAMES_MSRV: RustcVersion = RustcVersion::new(1, 17, 0); - -declare_clippy_lint! { - /// **What it does:** Checks for fields in struct literals where shorthands - /// could be used. - /// - /// **Why is this bad?** If the field and variable names are the same, - /// the field name is redundant. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let bar: u8 = 123; - /// - /// struct Foo { - /// bar: u8, - /// } - /// - /// let foo = Foo { bar: bar }; - /// ``` - /// the last line can be simplified to - /// ```ignore - /// let foo = Foo { bar }; - /// ``` - pub REDUNDANT_FIELD_NAMES, - style, - "checks for fields in struct literals where shorthands could be used" -} - -pub struct RedundantFieldNames { - msrv: Option, -} - -impl RedundantFieldNames { - #[must_use] - pub fn new(msrv: Option) -> Self { - Self { msrv } - } -} - -impl_lint_pass!(RedundantFieldNames => [REDUNDANT_FIELD_NAMES]); - -impl EarlyLintPass for RedundantFieldNames { - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - if !meets_msrv(self.msrv.as_ref(), &REDUNDANT_FIELD_NAMES_MSRV) { - return; - } - - if in_external_macro(cx.sess, expr.span) { - return; - } - if let ExprKind::Struct(_, ref fields, _) = expr.kind { - for field in fields { - if field.is_shorthand { - continue; - } - if let ExprKind::Path(None, path) = &field.expr.kind { - if path.segments.len() == 1 - && path.segments[0].ident == field.ident - && path.segments[0].args.is_none() - { - span_lint_and_sugg( - cx, - REDUNDANT_FIELD_NAMES, - field.span, - "redundant field names in struct initialization", - "replace it with", - field.ident.to_string(), - Applicability::MachineApplicable, - ); - } - } - } - } - } - extract_msrv_attr!(EarlyContext); -} diff --git a/clippy_lints/src/redundant_pub_crate.rs b/clippy_lints/src/redundant_pub_crate.rs deleted file mode 100644 index acd9047ace61..000000000000 --- a/clippy_lints/src/redundant_pub_crate.rs +++ /dev/null @@ -1,78 +0,0 @@ -use crate::utils::span_lint_and_then; -use rustc_errors::Applicability; -use rustc_hir::{Item, ItemKind, VisibilityKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; - -declare_clippy_lint! { - /// **What it does:** Checks for items declared `pub(crate)` that are not crate visible because they - /// are inside a private module. - /// - /// **Why is this bad?** Writing `pub(crate)` is misleading when it's redundant due to the parent - /// module's visibility. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// mod internal { - /// pub(crate) fn internal_fn() { } - /// } - /// ``` - /// This function is not visible outside the module and it can be declared with `pub` or - /// private visibility - /// ```rust - /// mod internal { - /// pub fn internal_fn() { } - /// } - /// ``` - pub REDUNDANT_PUB_CRATE, - nursery, - "Using `pub(crate)` visibility on items that are not crate visible due to the visibility of the module that contains them." -} - -#[derive(Default)] -pub struct RedundantPubCrate { - is_exported: Vec, -} - -impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]); - -impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { - if let VisibilityKind::Crate { .. } = item.vis.node { - if !cx.access_levels.is_exported(item.hir_id) { - if let Some(false) = self.is_exported.last() { - let span = item.span.with_hi(item.ident.span.hi()); - let def_id = cx.tcx.hir().local_def_id(item.hir_id); - let descr = cx.tcx.def_kind(def_id).descr(def_id.to_def_id()); - span_lint_and_then( - cx, - REDUNDANT_PUB_CRATE, - span, - &format!("pub(crate) {} inside private module", descr), - |diag| { - diag.span_suggestion( - item.vis.span, - "consider using", - "pub".to_string(), - Applicability::MachineApplicable, - ); - }, - ) - } - } - } - - if let ItemKind::Mod { .. } = item.kind { - self.is_exported.push(cx.access_levels.is_exported(item.hir_id)); - } - } - - fn check_item_post(&mut self, _cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { - if let ItemKind::Mod { .. } = item.kind { - self.is_exported.pop().expect("unbalanced check_item/check_item_post"); - } - } -} diff --git a/clippy_lints/src/redundant_static_lifetimes.rs b/clippy_lints/src/redundant_static_lifetimes.rs deleted file mode 100644 index fcfa3c12755a..000000000000 --- a/clippy_lints/src/redundant_static_lifetimes.rs +++ /dev/null @@ -1,119 +0,0 @@ -use crate::utils::{meets_msrv, snippet, span_lint_and_then}; -use rustc_ast::ast::{Item, ItemKind, Ty, TyKind}; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_semver::RustcVersion; -use rustc_session::{declare_tool_lint, impl_lint_pass}; - -const REDUNDANT_STATIC_LIFETIMES_MSRV: RustcVersion = RustcVersion::new(1, 17, 0); - -declare_clippy_lint! { - /// **What it does:** Checks for constants and statics with an explicit `'static` lifetime. - /// - /// **Why is this bad?** Adding `'static` to every reference can create very - /// complicated types. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// const FOO: &'static [(&'static str, &'static str, fn(&Bar) -> bool)] = - /// &[...] - /// static FOO: &'static [(&'static str, &'static str, fn(&Bar) -> bool)] = - /// &[...] - /// ``` - /// This code can be rewritten as - /// ```ignore - /// const FOO: &[(&str, &str, fn(&Bar) -> bool)] = &[...] - /// static FOO: &[(&str, &str, fn(&Bar) -> bool)] = &[...] - /// ``` - pub REDUNDANT_STATIC_LIFETIMES, - style, - "Using explicit `'static` lifetime for constants or statics when elision rules would allow omitting them." -} - -pub struct RedundantStaticLifetimes { - msrv: Option, -} - -impl RedundantStaticLifetimes { - #[must_use] - pub fn new(msrv: Option) -> Self { - Self { msrv } - } -} - -impl_lint_pass!(RedundantStaticLifetimes => [REDUNDANT_STATIC_LIFETIMES]); - -impl RedundantStaticLifetimes { - // Recursively visit types - fn visit_type(&mut self, ty: &Ty, cx: &EarlyContext<'_>, reason: &str) { - match ty.kind { - // Be careful of nested structures (arrays and tuples) - TyKind::Array(ref ty, _) => { - self.visit_type(&*ty, cx, reason); - }, - TyKind::Tup(ref tup) => { - for tup_ty in tup { - self.visit_type(&*tup_ty, cx, reason); - } - }, - // This is what we are looking for ! - TyKind::Rptr(ref optional_lifetime, ref borrow_type) => { - // Match the 'static lifetime - if let Some(lifetime) = *optional_lifetime { - match borrow_type.ty.kind { - TyKind::Path(..) | TyKind::Slice(..) | TyKind::Array(..) | TyKind::Tup(..) => { - if lifetime.ident.name == rustc_span::symbol::kw::StaticLifetime { - let snip = snippet(cx, borrow_type.ty.span, ""); - let sugg = format!("&{}", snip); - span_lint_and_then( - cx, - REDUNDANT_STATIC_LIFETIMES, - lifetime.ident.span, - reason, - |diag| { - diag.span_suggestion( - ty.span, - "consider removing `'static`", - sugg, - Applicability::MachineApplicable, //snippet - ); - }, - ); - } - }, - _ => {}, - } - } - self.visit_type(&*borrow_type.ty, cx, reason); - }, - TyKind::Slice(ref ty) => { - self.visit_type(ty, cx, reason); - }, - _ => {}, - } - } -} - -impl EarlyLintPass for RedundantStaticLifetimes { - fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { - if !meets_msrv(self.msrv.as_ref(), &REDUNDANT_STATIC_LIFETIMES_MSRV) { - return; - } - - if !item.span.from_expansion() { - if let ItemKind::Const(_, ref var_type, _) = item.kind { - self.visit_type(var_type, cx, "constants have by default a `'static` lifetime"); - // Don't check associated consts because `'static` cannot be elided on those (issue - // #2438) - } - - if let ItemKind::Static(ref var_type, _, _) = item.kind { - self.visit_type(var_type, cx, "statics have by default a `'static` lifetime"); - } - } - } - - extract_msrv_attr!(EarlyContext); -} diff --git a/clippy_lints/src/ref_option_ref.rs b/clippy_lints/src/ref_option_ref.rs deleted file mode 100644 index 803ebada54b7..000000000000 --- a/clippy_lints/src/ref_option_ref.rs +++ /dev/null @@ -1,67 +0,0 @@ -use crate::utils::{last_path_segment, snippet, span_lint_and_sugg}; -use rustc_hir::{GenericArg, Mutability, Ty, TyKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::symbol::sym; - -use if_chain::if_chain; -use rustc_errors::Applicability; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `&Option<&T>`. - /// - /// **Why is this bad?** Since `&` is Copy, it's useless to have a - /// reference on `Option<&T>`. - /// - /// **Known problems:** It may be irrevelent to use this lint on - /// public API code as it will make a breaking change to apply it. - /// - /// **Example:** - /// - /// ```rust,ignore - /// let x: &Option<&u32> = &Some(&0u32); - /// ``` - /// Use instead: - /// ```rust,ignore - /// let x: Option<&u32> = Some(&0u32); - /// ``` - pub REF_OPTION_REF, - pedantic, - "use `Option<&T>` instead of `&Option<&T>`" -} - -declare_lint_pass!(RefOptionRef => [REF_OPTION_REF]); - -impl<'tcx> LateLintPass<'tcx> for RefOptionRef { - fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx Ty<'tcx>) { - if_chain! { - if let TyKind::Rptr(_, ref mut_ty) = ty.kind; - if mut_ty.mutbl == Mutability::Not; - if let TyKind::Path(ref qpath) = &mut_ty.ty.kind; - let last = last_path_segment(qpath); - if let Some(res) = last.res; - if let Some(def_id) = res.opt_def_id(); - - if cx.tcx.is_diagnostic_item(sym::option_type, def_id); - if let Some(ref params) = last_path_segment(qpath).args ; - if !params.parenthesized; - if let Some(inner_ty) = params.args.iter().find_map(|arg| match arg { - GenericArg::Type(inner_ty) => Some(inner_ty), - _ => None, - }); - if let TyKind::Rptr(_, _) = inner_ty.kind; - - then { - span_lint_and_sugg( - cx, - REF_OPTION_REF, - ty.span, - "since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>`", - "try", - format!("Option<{}>", &snippet(cx, inner_ty.span, "..")), - Applicability::MaybeIncorrect, - ); - } - } - } -} diff --git a/clippy_lints/src/reference.rs b/clippy_lints/src/reference.rs deleted file mode 100644 index efe3237990d4..000000000000 --- a/clippy_lints/src/reference.rs +++ /dev/null @@ -1,140 +0,0 @@ -use crate::utils::{in_macro, snippet_opt, snippet_with_applicability, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_ast::ast::{Expr, ExprKind, Mutability, UnOp}; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::BytePos; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `*&` and `*&mut` in expressions. - /// - /// **Why is this bad?** Immediately dereferencing a reference is no-op and - /// makes the code less clear. - /// - /// **Known problems:** Multiple dereference/addrof pairs are not handled so - /// the suggested fix for `x = **&&y` is `x = *&y`, which is still incorrect. - /// - /// **Example:** - /// ```rust,ignore - /// // Bad - /// let a = f(*&mut b); - /// let c = *&d; - /// - /// // Good - /// let a = f(b); - /// let c = d; - /// ``` - pub DEREF_ADDROF, - complexity, - "use of `*&` or `*&mut` in an expression" -} - -declare_lint_pass!(DerefAddrOf => [DEREF_ADDROF]); - -fn without_parens(mut e: &Expr) -> &Expr { - while let ExprKind::Paren(ref child_e) = e.kind { - e = child_e; - } - e -} - -impl EarlyLintPass for DerefAddrOf { - fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) { - if_chain! { - if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.kind; - if let ExprKind::AddrOf(_, ref mutability, ref addrof_target) = without_parens(deref_target).kind; - if !in_macro(addrof_target.span); - then { - let mut applicability = Applicability::MachineApplicable; - let sugg = if e.span.from_expansion() { - if let Ok(macro_source) = cx.sess.source_map().span_to_snippet(e.span) { - // Remove leading whitespace from the given span - // e.g: ` $visitor` turns into `$visitor` - let trim_leading_whitespaces = |span| { - snippet_opt(cx, span).and_then(|snip| { - #[allow(clippy::cast_possible_truncation)] - snip.find(|c: char| !c.is_whitespace()).map(|pos| { - span.lo() + BytePos(pos as u32) - }) - }).map_or(span, |start_no_whitespace| e.span.with_lo(start_no_whitespace)) - }; - - let mut generate_snippet = |pattern: &str| { - #[allow(clippy::cast_possible_truncation)] - macro_source.rfind(pattern).map(|pattern_pos| { - let rpos = pattern_pos + pattern.len(); - let span_after_ref = e.span.with_lo(BytePos(e.span.lo().0 + rpos as u32)); - let span = trim_leading_whitespaces(span_after_ref); - snippet_with_applicability(cx, span, "_", &mut applicability) - }) - }; - - if *mutability == Mutability::Mut { - generate_snippet("mut") - } else { - generate_snippet("&") - } - } else { - Some(snippet_with_applicability(cx, e.span, "_", &mut applicability)) - } - } else { - Some(snippet_with_applicability(cx, addrof_target.span, "_", &mut applicability)) - }; - if let Some(sugg) = sugg { - span_lint_and_sugg( - cx, - DEREF_ADDROF, - e.span, - "immediately dereferencing a reference", - "try this", - sugg.to_string(), - applicability, - ); - } - } - } - } -} - -declare_clippy_lint! { - /// **What it does:** Checks for references in expressions that use - /// auto dereference. - /// - /// **Why is this bad?** The reference is a no-op and is automatically - /// dereferenced by the compiler and makes the code less clear. - /// - /// **Example:** - /// ```rust - /// struct Point(u32, u32); - /// let point = Point(30, 20); - /// let x = (&point).0; - /// ``` - pub REF_IN_DEREF, - complexity, - "Use of reference in auto dereference expression." -} - -declare_lint_pass!(RefInDeref => [REF_IN_DEREF]); - -impl EarlyLintPass for RefInDeref { - fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) { - if_chain! { - if let ExprKind::Field(ref object, _) = e.kind; - if let ExprKind::Paren(ref parened) = object.kind; - if let ExprKind::AddrOf(_, _, ref inner) = parened.kind; - then { - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - REF_IN_DEREF, - object.span, - "creating a reference that is immediately dereferenced", - "try this", - snippet_with_applicability(cx, inner.span, "_", &mut applicability).to_string(), - applicability, - ); - } - } - } -} diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs deleted file mode 100644 index d06ab1434823..000000000000 --- a/clippy_lints/src/regex.rs +++ /dev/null @@ -1,209 +0,0 @@ -use crate::consts::{constant, Constant}; -use crate::utils::{match_def_path, paths, span_lint, span_lint_and_help}; -use if_chain::if_chain; -use rustc_ast::ast::{LitKind, StrStyle}; -use rustc_data_structures::fx::FxHashSet; -use rustc_hir::{BorrowKind, Expr, ExprKind, HirId}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::{BytePos, Span}; -use std::convert::TryFrom; - -declare_clippy_lint! { - /// **What it does:** Checks [regex](https://crates.io/crates/regex) creation - /// (with `Regex::new`, `RegexBuilder::new`, or `RegexSet::new`) for correct - /// regex syntax. - /// - /// **Why is this bad?** This will lead to a runtime panic. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// Regex::new("|") - /// ``` - pub INVALID_REGEX, - correctness, - "invalid regular expressions" -} - -declare_clippy_lint! { - /// **What it does:** Checks for trivial [regex](https://crates.io/crates/regex) - /// creation (with `Regex::new`, `RegexBuilder::new`, or `RegexSet::new`). - /// - /// **Why is this bad?** Matching the regex can likely be replaced by `==` or - /// `str::starts_with`, `str::ends_with` or `std::contains` or other `str` - /// methods. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// Regex::new("^foobar") - /// ``` - pub TRIVIAL_REGEX, - style, - "trivial regular expressions" -} - -#[derive(Clone, Default)] -pub struct Regex { - spans: FxHashSet, - last: Option, -} - -impl_lint_pass!(Regex => [INVALID_REGEX, TRIVIAL_REGEX]); - -impl<'tcx> LateLintPass<'tcx> for Regex { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if_chain! { - if let ExprKind::Call(ref fun, ref args) = expr.kind; - if let ExprKind::Path(ref qpath) = fun.kind; - if args.len() == 1; - if let Some(def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id(); - then { - if match_def_path(cx, def_id, &paths::REGEX_NEW) || - match_def_path(cx, def_id, &paths::REGEX_BUILDER_NEW) { - check_regex(cx, &args[0], true); - } else if match_def_path(cx, def_id, &paths::REGEX_BYTES_NEW) || - match_def_path(cx, def_id, &paths::REGEX_BYTES_BUILDER_NEW) { - check_regex(cx, &args[0], false); - } else if match_def_path(cx, def_id, &paths::REGEX_SET_NEW) { - check_set(cx, &args[0], true); - } else if match_def_path(cx, def_id, &paths::REGEX_BYTES_SET_NEW) { - check_set(cx, &args[0], false); - } - } - } - } -} - -#[allow(clippy::cast_possible_truncation)] // truncation very unlikely here -#[must_use] -fn str_span(base: Span, c: regex_syntax::ast::Span, offset: u16) -> Span { - let offset = u32::from(offset); - let end = base.lo() + BytePos(u32::try_from(c.end.offset).expect("offset too large") + offset); - let start = base.lo() + BytePos(u32::try_from(c.start.offset).expect("offset too large") + offset); - assert!(start <= end); - Span::new(start, end, base.ctxt()) -} - -fn const_str<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> Option { - constant(cx, cx.typeck_results(), e).and_then(|(c, _)| match c { - Constant::Str(s) => Some(s), - _ => None, - }) -} - -fn is_trivial_regex(s: ®ex_syntax::hir::Hir) -> Option<&'static str> { - use regex_syntax::hir::Anchor::{EndText, StartText}; - use regex_syntax::hir::HirKind::{Alternation, Anchor, Concat, Empty, Literal}; - - let is_literal = |e: &[regex_syntax::hir::Hir]| e.iter().all(|e| matches!(*e.kind(), Literal(_))); - - match *s.kind() { - Empty | Anchor(_) => Some("the regex is unlikely to be useful as it is"), - Literal(_) => Some("consider using `str::contains`"), - Alternation(ref exprs) => { - if exprs.iter().all(|e| e.kind().is_empty()) { - Some("the regex is unlikely to be useful as it is") - } else { - None - } - }, - Concat(ref exprs) => match (exprs[0].kind(), exprs[exprs.len() - 1].kind()) { - (&Anchor(StartText), &Anchor(EndText)) if exprs[1..(exprs.len() - 1)].is_empty() => { - Some("consider using `str::is_empty`") - }, - (&Anchor(StartText), &Anchor(EndText)) if is_literal(&exprs[1..(exprs.len() - 1)]) => { - Some("consider using `==` on `str`s") - }, - (&Anchor(StartText), &Literal(_)) if is_literal(&exprs[1..]) => Some("consider using `str::starts_with`"), - (&Literal(_), &Anchor(EndText)) if is_literal(&exprs[1..(exprs.len() - 1)]) => { - Some("consider using `str::ends_with`") - }, - _ if is_literal(exprs) => Some("consider using `str::contains`"), - _ => None, - }, - _ => None, - } -} - -fn check_set<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, utf8: bool) { - if_chain! { - if let ExprKind::AddrOf(BorrowKind::Ref, _, ref expr) = expr.kind; - if let ExprKind::Array(exprs) = expr.kind; - then { - for expr in exprs { - check_regex(cx, expr, utf8); - } - } - } -} - -fn check_regex<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, utf8: bool) { - let mut parser = regex_syntax::ParserBuilder::new() - .unicode(true) - .allow_invalid_utf8(!utf8) - .build(); - - if let ExprKind::Lit(ref lit) = expr.kind { - if let LitKind::Str(ref r, style) = lit.node { - let r = &r.as_str(); - let offset = if let StrStyle::Raw(n) = style { 2 + n } else { 1 }; - match parser.parse(r) { - Ok(r) => { - if let Some(repl) = is_trivial_regex(&r) { - span_lint_and_help(cx, TRIVIAL_REGEX, expr.span, "trivial regex", None, repl); - } - }, - Err(regex_syntax::Error::Parse(e)) => { - span_lint( - cx, - INVALID_REGEX, - str_span(expr.span, *e.span(), offset), - &format!("regex syntax error: {}", e.kind()), - ); - }, - Err(regex_syntax::Error::Translate(e)) => { - span_lint( - cx, - INVALID_REGEX, - str_span(expr.span, *e.span(), offset), - &format!("regex syntax error: {}", e.kind()), - ); - }, - Err(e) => { - span_lint(cx, INVALID_REGEX, expr.span, &format!("regex syntax error: {}", e)); - }, - } - } - } else if let Some(r) = const_str(cx, expr) { - match parser.parse(&r) { - Ok(r) => { - if let Some(repl) = is_trivial_regex(&r) { - span_lint_and_help(cx, TRIVIAL_REGEX, expr.span, "trivial regex", None, repl); - } - }, - Err(regex_syntax::Error::Parse(e)) => { - span_lint( - cx, - INVALID_REGEX, - expr.span, - &format!("regex syntax error on position {}: {}", e.span().start.offset, e.kind()), - ); - }, - Err(regex_syntax::Error::Translate(e)) => { - span_lint( - cx, - INVALID_REGEX, - expr.span, - &format!("regex syntax error on position {}: {}", e.span().start.offset, e.kind()), - ); - }, - Err(e) => { - span_lint(cx, INVALID_REGEX, expr.span, &format!("regex syntax error: {}", e)); - }, - } - } -} diff --git a/clippy_lints/src/repeat_once.rs b/clippy_lints/src/repeat_once.rs deleted file mode 100644 index d34e744eb944..000000000000 --- a/clippy_lints/src/repeat_once.rs +++ /dev/null @@ -1,83 +0,0 @@ -use crate::consts::{constant_context, Constant}; -use crate::utils::{in_macro, is_type_diagnostic_item, snippet, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of `.repeat(1)` and suggest the following method for each types. - /// - `.to_string()` for `str` - /// - `.clone()` for `String` - /// - `.to_vec()` for `slice` - /// - /// **Why is this bad?** For example, `String.repeat(1)` is equivalent to `.clone()`. If cloning the string is the intention behind this, `clone()` should be used. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// fn main() { - /// let x = String::from("hello world").repeat(1); - /// } - /// ``` - /// Use instead: - /// ```rust - /// fn main() { - /// let x = String::from("hello world").clone(); - /// } - /// ``` - pub REPEAT_ONCE, - complexity, - "using `.repeat(1)` instead of `String.clone()`, `str.to_string()` or `slice.to_vec()` " -} - -declare_lint_pass!(RepeatOnce => [REPEAT_ONCE]); - -impl<'tcx> LateLintPass<'tcx> for RepeatOnce { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'tcx Expr<'_>) { - if_chain! { - if let ExprKind::MethodCall(path, _, [receiver, count], _) = &expr.kind; - if path.ident.name == sym!(repeat); - if let Some(Constant::Int(1)) = constant_context(cx, cx.typeck_results()).expr(&count); - if !in_macro(receiver.span); - then { - let ty = cx.typeck_results().expr_ty(&receiver).peel_refs(); - if ty.is_str() { - span_lint_and_sugg( - cx, - REPEAT_ONCE, - expr.span, - "calling `repeat(1)` on str", - "consider using `.to_string()` instead", - format!("{}.to_string()", snippet(cx, receiver.span, r#""...""#)), - Applicability::MachineApplicable, - ); - } else if ty.builtin_index().is_some() { - span_lint_and_sugg( - cx, - REPEAT_ONCE, - expr.span, - "calling `repeat(1)` on slice", - "consider using `.to_vec()` instead", - format!("{}.to_vec()", snippet(cx, receiver.span, r#""...""#)), - Applicability::MachineApplicable, - ); - } else if is_type_diagnostic_item(cx, ty, sym::string_type) { - span_lint_and_sugg( - cx, - REPEAT_ONCE, - expr.span, - "calling `repeat(1)` on a string literal", - "consider using `.clone()` instead", - format!("{}.clone()", snippet(cx, receiver.span, r#""...""#)), - Applicability::MachineApplicable, - ); - } - } - } - } -} diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs deleted file mode 100644 index 7f4913a02cbd..000000000000 --- a/clippy_lints/src/returns.rs +++ /dev/null @@ -1,290 +0,0 @@ -use if_chain::if_chain; -use rustc_ast::ast::Attribute; -use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_expr, FnKind, NestedVisitorMap, Visitor}; -use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, HirId, MatchSource, PatKind, StmtKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::subst::GenericArgKind; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::sym; - -use crate::utils::{fn_def_id, in_macro, match_qpath, snippet_opt, span_lint_and_sugg, span_lint_and_then}; - -declare_clippy_lint! { - /// **What it does:** Checks for `let`-bindings, which are subsequently - /// returned. - /// - /// **Why is this bad?** It is just extraneous code. Remove it to make your code - /// more rusty. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// fn foo() -> String { - /// let x = String::new(); - /// x - /// } - /// ``` - /// instead, use - /// ``` - /// fn foo() -> String { - /// String::new() - /// } - /// ``` - pub LET_AND_RETURN, - style, - "creating a let-binding and then immediately returning it like `let x = expr; x` at the end of a block" -} - -declare_clippy_lint! { - /// **What it does:** Checks for return statements at the end of a block. - /// - /// **Why is this bad?** Removing the `return` and semicolon will make the code - /// more rusty. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// fn foo(x: usize) -> usize { - /// return x; - /// } - /// ``` - /// simplify to - /// ```rust - /// fn foo(x: usize) -> usize { - /// x - /// } - /// ``` - pub NEEDLESS_RETURN, - style, - "using a return statement like `return expr;` where an expression would suffice" -} - -#[derive(PartialEq, Eq, Copy, Clone)] -enum RetReplacement { - Empty, - Block, -} - -declare_lint_pass!(Return => [LET_AND_RETURN, NEEDLESS_RETURN]); - -impl<'tcx> LateLintPass<'tcx> for Return { - fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'_>) { - // we need both a let-binding stmt and an expr - if_chain! { - if let Some(retexpr) = block.expr; - if let Some(stmt) = block.stmts.iter().last(); - if let StmtKind::Local(local) = &stmt.kind; - if local.ty.is_none(); - if local.attrs.is_empty(); - if let Some(initexpr) = &local.init; - if let PatKind::Binding(.., ident, _) = local.pat.kind; - if let ExprKind::Path(qpath) = &retexpr.kind; - if match_qpath(qpath, &[&*ident.name.as_str()]); - if !last_statement_borrows(cx, initexpr); - if !in_external_macro(cx.sess(), initexpr.span); - if !in_external_macro(cx.sess(), retexpr.span); - if !in_external_macro(cx.sess(), local.span); - if !in_macro(local.span); - then { - span_lint_and_then( - cx, - LET_AND_RETURN, - retexpr.span, - "returning the result of a `let` binding from a block", - |err| { - err.span_label(local.span, "unnecessary `let` binding"); - - if let Some(mut snippet) = snippet_opt(cx, initexpr.span) { - if !cx.typeck_results().expr_adjustments(&retexpr).is_empty() { - snippet.push_str(" as _"); - } - err.multipart_suggestion( - "return the expression directly", - vec![ - (local.span, String::new()), - (retexpr.span, snippet), - ], - Applicability::MachineApplicable, - ); - } else { - err.span_help(initexpr.span, "this expression can be directly returned"); - } - }, - ); - } - } - } - - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - kind: FnKind<'tcx>, - _: &'tcx FnDecl<'tcx>, - body: &'tcx Body<'tcx>, - _: Span, - _: HirId, - ) { - match kind { - FnKind::Closure(_) => check_final_expr(cx, &body.value, Some(body.value.span), RetReplacement::Empty), - FnKind::ItemFn(..) | FnKind::Method(..) => { - if let ExprKind::Block(ref block, _) = body.value.kind { - check_block_return(cx, block); - } - }, - } - } -} - -fn attr_is_cfg(attr: &Attribute) -> bool { - attr.meta_item_list().is_some() && attr.has_name(sym::cfg) -} - -fn check_block_return<'tcx>(cx: &LateContext<'tcx>, block: &Block<'tcx>) { - if let Some(expr) = block.expr { - check_final_expr(cx, expr, Some(expr.span), RetReplacement::Empty); - } else if let Some(stmt) = block.stmts.iter().last() { - match stmt.kind { - StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => { - check_final_expr(cx, expr, Some(stmt.span), RetReplacement::Empty); - }, - _ => (), - } - } -} - -fn check_final_expr<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx Expr<'tcx>, - span: Option, - replacement: RetReplacement, -) { - match expr.kind { - // simple return is always "bad" - ExprKind::Ret(ref inner) => { - // allow `#[cfg(a)] return a; #[cfg(b)] return b;` - if !expr.attrs.iter().any(attr_is_cfg) { - let borrows = inner.map_or(false, |inner| last_statement_borrows(cx, inner)); - if !borrows { - emit_return_lint( - cx, - span.expect("`else return` is not possible"), - inner.as_ref().map(|i| i.span), - replacement, - ); - } - } - }, - // a whole block? check it! - ExprKind::Block(ref block, _) => { - check_block_return(cx, block); - }, - // a match expr, check all arms - // an if/if let expr, check both exprs - // note, if without else is going to be a type checking error anyways - // (except for unit type functions) so we don't match it - ExprKind::Match(_, ref arms, source) => match source { - MatchSource::Normal => { - for arm in arms.iter() { - check_final_expr(cx, &arm.body, Some(arm.body.span), RetReplacement::Block); - } - }, - MatchSource::IfDesugar { - contains_else_clause: true, - } - | MatchSource::IfLetDesugar { - contains_else_clause: true, - } => { - if let ExprKind::Block(ref ifblock, _) = arms[0].body.kind { - check_block_return(cx, ifblock); - } - check_final_expr(cx, arms[1].body, None, RetReplacement::Empty); - }, - _ => (), - }, - _ => (), - } -} - -fn emit_return_lint(cx: &LateContext<'_>, ret_span: Span, inner_span: Option, replacement: RetReplacement) { - match inner_span { - Some(inner_span) => { - if in_external_macro(cx.tcx.sess, inner_span) || inner_span.from_expansion() { - return; - } - - span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded `return` statement", |diag| { - if let Some(snippet) = snippet_opt(cx, inner_span) { - diag.span_suggestion(ret_span, "remove `return`", snippet, Applicability::MachineApplicable); - } - }) - }, - None => match replacement { - RetReplacement::Empty => { - span_lint_and_sugg( - cx, - NEEDLESS_RETURN, - ret_span, - "unneeded `return` statement", - "remove `return`", - String::new(), - Applicability::MachineApplicable, - ); - }, - RetReplacement::Block => { - span_lint_and_sugg( - cx, - NEEDLESS_RETURN, - ret_span, - "unneeded `return` statement", - "replace `return` with an empty block", - "{}".to_string(), - Applicability::MachineApplicable, - ); - }, - }, - } -} - -fn last_statement_borrows<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool { - let mut visitor = BorrowVisitor { cx, borrows: false }; - walk_expr(&mut visitor, expr); - visitor.borrows -} - -struct BorrowVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - borrows: bool, -} - -impl<'tcx> Visitor<'tcx> for BorrowVisitor<'_, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if self.borrows { - return; - } - - if let Some(def_id) = fn_def_id(self.cx, expr) { - self.borrows = self - .cx - .tcx - .fn_sig(def_id) - .output() - .skip_binder() - .walk() - .any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_))); - } - - walk_expr(self, expr); - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} diff --git a/clippy_lints/src/self_assignment.rs b/clippy_lints/src/self_assignment.rs deleted file mode 100644 index e096c9aebc12..000000000000 --- a/clippy_lints/src/self_assignment.rs +++ /dev/null @@ -1,51 +0,0 @@ -use crate::utils::{eq_expr_value, snippet, span_lint}; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for explicit self-assignments. - /// - /// **Why is this bad?** Self-assignments are redundant and unlikely to be - /// intentional. - /// - /// **Known problems:** If expression contains any deref coercions or - /// indexing operations they are assumed not to have any side effects. - /// - /// **Example:** - /// - /// ```rust - /// struct Event { - /// id: usize, - /// x: i32, - /// y: i32, - /// } - /// - /// fn copy_position(a: &mut Event, b: &Event) { - /// a.x = b.x; - /// a.y = a.y; - /// } - /// ``` - pub SELF_ASSIGNMENT, - correctness, - "explicit self-assignment" -} - -declare_lint_pass!(SelfAssignment => [SELF_ASSIGNMENT]); - -impl<'tcx> LateLintPass<'tcx> for SelfAssignment { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Assign(lhs, rhs, _) = &expr.kind { - if eq_expr_value(cx, lhs, rhs) { - let lhs = snippet(cx, lhs.span, ""); - let rhs = snippet(cx, rhs.span, ""); - span_lint( - cx, - SELF_ASSIGNMENT, - expr.span, - &format!("self-assignment of `{}` to `{}`", rhs, lhs), - ); - } - } - } -} diff --git a/clippy_lints/src/serde_api.rs b/clippy_lints/src/serde_api.rs deleted file mode 100644 index 339a7cf3bf5d..000000000000 --- a/clippy_lints/src/serde_api.rs +++ /dev/null @@ -1,57 +0,0 @@ -use crate::utils::{get_trait_def_id, paths, span_lint}; -use rustc_hir::{Item, ItemKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for mis-uses of the serde API. - /// - /// **Why is this bad?** Serde is very finnicky about how its API should be - /// used, but the type system can't be used to enforce it (yet?). - /// - /// **Known problems:** None. - /// - /// **Example:** Implementing `Visitor::visit_string` but not - /// `Visitor::visit_str`. - pub SERDE_API_MISUSE, - correctness, - "various things that will negatively affect your serde experience" -} - -declare_lint_pass!(SerdeAPI => [SERDE_API_MISUSE]); - -impl<'tcx> LateLintPass<'tcx> for SerdeAPI { - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Impl { - of_trait: Some(ref trait_ref), - items, - .. - } = item.kind - { - let did = trait_ref.path.res.def_id(); - if let Some(visit_did) = get_trait_def_id(cx, &paths::SERDE_DE_VISITOR) { - if did == visit_did { - let mut seen_str = None; - let mut seen_string = None; - for item in items { - match &*item.ident.as_str() { - "visit_str" => seen_str = Some(item.span), - "visit_string" => seen_string = Some(item.span), - _ => {}, - } - } - if let Some(span) = seen_string { - if seen_str.is_none() { - span_lint( - cx, - SERDE_API_MISUSE, - span, - "you should not implement `visit_string` without also implementing `visit_str`", - ); - } - } - } - } - } - } -} diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs deleted file mode 100644 index f83965926782..000000000000 --- a/clippy_lints/src/shadow.rs +++ /dev/null @@ -1,393 +0,0 @@ -use crate::utils::{contains_name, higher, iter_input_pats, snippet, span_lint_and_then}; -use rustc_hir::intravisit::FnKind; -use rustc_hir::{ - Block, Body, Expr, ExprKind, FnDecl, Guard, HirId, Local, MutTy, Pat, PatKind, Path, QPath, StmtKind, Ty, TyKind, - UnOp, -}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::symbol::Symbol; - -declare_clippy_lint! { - /// **What it does:** Checks for bindings that shadow other bindings already in - /// scope, while just changing reference level or mutability. - /// - /// **Why is this bad?** Not much, in fact it's a very common pattern in Rust - /// code. Still, some may opt to avoid it in their code base, they can set this - /// lint to `Warn`. - /// - /// **Known problems:** This lint, as the other shadowing related lints, - /// currently only catches very simple patterns. - /// - /// **Example:** - /// ```rust - /// # let x = 1; - /// // Bad - /// let x = &x; - /// - /// // Good - /// let y = &x; // use different variable name - /// ``` - pub SHADOW_SAME, - restriction, - "rebinding a name to itself, e.g., `let mut x = &mut x`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for bindings that shadow other bindings already in - /// scope, while reusing the original value. - /// - /// **Why is this bad?** Not too much, in fact it's a common pattern in Rust - /// code. Still, some argue that name shadowing like this hurts readability, - /// because a value may be bound to different things depending on position in - /// the code. - /// - /// **Known problems:** This lint, as the other shadowing related lints, - /// currently only catches very simple patterns. - /// - /// **Example:** - /// ```rust - /// let x = 2; - /// let x = x + 1; - /// ``` - /// use different variable name: - /// ```rust - /// let x = 2; - /// let y = x + 1; - /// ``` - pub SHADOW_REUSE, - restriction, - "rebinding a name to an expression that re-uses the original value, e.g., `let x = x + 1`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for bindings that shadow other bindings already in - /// scope, either without a initialization or with one that does not even use - /// the original value. - /// - /// **Why is this bad?** Name shadowing can hurt readability, especially in - /// large code bases, because it is easy to lose track of the active binding at - /// any place in the code. This can be alleviated by either giving more specific - /// names to bindings or introducing more scopes to contain the bindings. - /// - /// **Known problems:** This lint, as the other shadowing related lints, - /// currently only catches very simple patterns. Note that - /// `allow`/`warn`/`deny`/`forbid` attributes only work on the function level - /// for this lint. - /// - /// **Example:** - /// ```rust - /// # let y = 1; - /// # let z = 2; - /// let x = y; - /// - /// // Bad - /// let x = z; // shadows the earlier binding - /// - /// // Good - /// let w = z; // use different variable name - /// ``` - pub SHADOW_UNRELATED, - pedantic, - "rebinding a name without even using the original value" -} - -declare_lint_pass!(Shadow => [SHADOW_SAME, SHADOW_REUSE, SHADOW_UNRELATED]); - -impl<'tcx> LateLintPass<'tcx> for Shadow { - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - _: FnKind<'tcx>, - decl: &'tcx FnDecl<'_>, - body: &'tcx Body<'_>, - _: Span, - _: HirId, - ) { - if in_external_macro(cx.sess(), body.value.span) { - return; - } - check_fn(cx, decl, body); - } -} - -fn check_fn<'tcx>(cx: &LateContext<'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>) { - let mut bindings = Vec::with_capacity(decl.inputs.len()); - for arg in iter_input_pats(decl, body) { - if let PatKind::Binding(.., ident, _) = arg.pat.kind { - bindings.push((ident.name, ident.span)) - } - } - check_expr(cx, &body.value, &mut bindings); -} - -fn check_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'_>, bindings: &mut Vec<(Symbol, Span)>) { - let len = bindings.len(); - for stmt in block.stmts { - match stmt.kind { - StmtKind::Local(ref local) => check_local(cx, local, bindings), - StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => check_expr(cx, e, bindings), - StmtKind::Item(..) => {}, - } - } - if let Some(ref o) = block.expr { - check_expr(cx, o, bindings); - } - bindings.truncate(len); -} - -fn check_local<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>, bindings: &mut Vec<(Symbol, Span)>) { - if in_external_macro(cx.sess(), local.span) { - return; - } - if higher::is_from_for_desugar(local) { - return; - } - let Local { - ref pat, - ref ty, - ref init, - span, - .. - } = *local; - if let Some(ref t) = *ty { - check_ty(cx, t, bindings) - } - if let Some(ref o) = *init { - check_expr(cx, o, bindings); - check_pat(cx, pat, Some(o), span, bindings); - } else { - check_pat(cx, pat, None, span, bindings); - } -} - -fn is_binding(cx: &LateContext<'_>, pat_id: HirId) -> bool { - let var_ty = cx.typeck_results().node_type_opt(pat_id); - var_ty.map_or(false, |var_ty| !matches!(var_ty.kind(), ty::Adt(..))) -} - -fn check_pat<'tcx>( - cx: &LateContext<'tcx>, - pat: &'tcx Pat<'_>, - init: Option<&'tcx Expr<'_>>, - span: Span, - bindings: &mut Vec<(Symbol, Span)>, -) { - // TODO: match more stuff / destructuring - match pat.kind { - PatKind::Binding(.., ident, ref inner) => { - let name = ident.name; - if is_binding(cx, pat.hir_id) { - let mut new_binding = true; - for tup in bindings.iter_mut() { - if tup.0 == name { - lint_shadow(cx, name, span, pat.span, init, tup.1); - tup.1 = ident.span; - new_binding = false; - break; - } - } - if new_binding { - bindings.push((name, ident.span)); - } - } - if let Some(ref p) = *inner { - check_pat(cx, p, init, span, bindings); - } - }, - PatKind::Struct(_, pfields, _) => { - if let Some(init_struct) = init { - if let ExprKind::Struct(_, ref efields, _) = init_struct.kind { - for field in pfields { - let name = field.ident.name; - let efield = efields - .iter() - .find_map(|f| if f.ident.name == name { Some(&*f.expr) } else { None }); - check_pat(cx, &field.pat, efield, span, bindings); - } - } else { - for field in pfields { - check_pat(cx, &field.pat, init, span, bindings); - } - } - } else { - for field in pfields { - check_pat(cx, &field.pat, None, span, bindings); - } - } - }, - PatKind::Tuple(inner, _) => { - if let Some(init_tup) = init { - if let ExprKind::Tup(ref tup) = init_tup.kind { - for (i, p) in inner.iter().enumerate() { - check_pat(cx, p, Some(&tup[i]), p.span, bindings); - } - } else { - for p in inner { - check_pat(cx, p, init, span, bindings); - } - } - } else { - for p in inner { - check_pat(cx, p, None, span, bindings); - } - } - }, - PatKind::Box(ref inner) => { - if let Some(initp) = init { - if let ExprKind::Box(ref inner_init) = initp.kind { - check_pat(cx, inner, Some(&**inner_init), span, bindings); - } else { - check_pat(cx, inner, init, span, bindings); - } - } else { - check_pat(cx, inner, init, span, bindings); - } - }, - PatKind::Ref(ref inner, _) => check_pat(cx, inner, init, span, bindings), - // PatVec(Vec>, Option>, Vec>), - _ => (), - } -} - -fn lint_shadow<'tcx>( - cx: &LateContext<'tcx>, - name: Symbol, - span: Span, - pattern_span: Span, - init: Option<&'tcx Expr<'_>>, - prev_span: Span, -) { - if let Some(expr) = init { - if is_self_shadow(name, expr) { - span_lint_and_then( - cx, - SHADOW_SAME, - span, - &format!( - "`{}` is shadowed by itself in `{}`", - snippet(cx, pattern_span, "_"), - snippet(cx, expr.span, "..") - ), - |diag| { - diag.span_note(prev_span, "previous binding is here"); - }, - ); - } else if contains_name(name, expr) { - span_lint_and_then( - cx, - SHADOW_REUSE, - pattern_span, - &format!( - "`{}` is shadowed by `{}` which reuses the original value", - snippet(cx, pattern_span, "_"), - snippet(cx, expr.span, "..") - ), - |diag| { - diag.span_note(expr.span, "initialization happens here"); - diag.span_note(prev_span, "previous binding is here"); - }, - ); - } else { - span_lint_and_then( - cx, - SHADOW_UNRELATED, - pattern_span, - &format!("`{}` is being shadowed", snippet(cx, pattern_span, "_")), - |diag| { - diag.span_note(expr.span, "initialization happens here"); - diag.span_note(prev_span, "previous binding is here"); - }, - ); - } - } else { - span_lint_and_then( - cx, - SHADOW_UNRELATED, - span, - &format!("`{}` shadows a previous declaration", snippet(cx, pattern_span, "_")), - |diag| { - diag.span_note(prev_span, "previous binding is here"); - }, - ); - } -} - -fn check_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, bindings: &mut Vec<(Symbol, Span)>) { - if in_external_macro(cx.sess(), expr.span) { - return; - } - match expr.kind { - ExprKind::Unary(_, ref e) - | ExprKind::Field(ref e, _) - | ExprKind::AddrOf(_, _, ref e) - | ExprKind::Box(ref e) => check_expr(cx, e, bindings), - ExprKind::Block(ref block, _) | ExprKind::Loop(ref block, _, _) => check_block(cx, block, bindings), - // ExprKind::Call - // ExprKind::MethodCall - ExprKind::Array(v) | ExprKind::Tup(v) => { - for e in v { - check_expr(cx, e, bindings) - } - }, - ExprKind::Match(ref init, arms, _) => { - check_expr(cx, init, bindings); - let len = bindings.len(); - for arm in arms { - check_pat(cx, &arm.pat, Some(&**init), arm.pat.span, bindings); - // This is ugly, but needed to get the right type - if let Some(ref guard) = arm.guard { - match guard { - Guard::If(if_expr) => check_expr(cx, if_expr, bindings), - Guard::IfLet(guard_pat, guard_expr) => { - check_pat(cx, guard_pat, Some(*guard_expr), guard_pat.span, bindings); - check_expr(cx, guard_expr, bindings); - }, - } - } - check_expr(cx, &arm.body, bindings); - bindings.truncate(len); - } - }, - _ => (), - } -} - -fn check_ty<'tcx>(cx: &LateContext<'tcx>, ty: &'tcx Ty<'_>, bindings: &mut Vec<(Symbol, Span)>) { - match ty.kind { - TyKind::Slice(ref sty) => check_ty(cx, sty, bindings), - TyKind::Array(ref fty, ref anon_const) => { - check_ty(cx, fty, bindings); - check_expr(cx, &cx.tcx.hir().body(anon_const.body).value, bindings); - }, - TyKind::Ptr(MutTy { ty: ref mty, .. }) | TyKind::Rptr(_, MutTy { ty: ref mty, .. }) => { - check_ty(cx, mty, bindings) - }, - TyKind::Tup(tup) => { - for t in tup { - check_ty(cx, t, bindings) - } - }, - TyKind::Typeof(ref anon_const) => check_expr(cx, &cx.tcx.hir().body(anon_const.body).value, bindings), - _ => (), - } -} - -fn is_self_shadow(name: Symbol, expr: &Expr<'_>) -> bool { - match expr.kind { - ExprKind::Box(ref inner) | ExprKind::AddrOf(_, _, ref inner) => is_self_shadow(name, inner), - ExprKind::Block(ref block, _) => { - block.stmts.is_empty() && block.expr.as_ref().map_or(false, |e| is_self_shadow(name, e)) - }, - ExprKind::Unary(op, ref inner) => (UnOp::UnDeref == op) && is_self_shadow(name, inner), - ExprKind::Path(QPath::Resolved(_, ref path)) => path_eq_name(name, path), - _ => false, - } -} - -fn path_eq_name(name: Symbol, path: &Path<'_>) -> bool { - !path.is_global() && path.segments.len() == 1 && path.segments[0].ident.as_str() == name.as_str() -} diff --git a/clippy_lints/src/single_component_path_imports.rs b/clippy_lints/src/single_component_path_imports.rs deleted file mode 100644 index 35b38eca14d1..000000000000 --- a/clippy_lints/src/single_component_path_imports.rs +++ /dev/null @@ -1,62 +0,0 @@ -use crate::utils::{in_macro, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_ast::{Item, ItemKind, UseTreeKind}; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::edition::Edition; - -declare_clippy_lint! { - /// **What it does:** Checking for imports with single component use path. - /// - /// **Why is this bad?** Import with single component use path such as `use cratename;` - /// is not necessary, and thus should be removed. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust,ignore - /// use regex; - /// - /// fn main() { - /// regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap(); - /// } - /// ``` - /// Better as - /// ```rust,ignore - /// fn main() { - /// regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap(); - /// } - /// ``` - pub SINGLE_COMPONENT_PATH_IMPORTS, - style, - "imports with single component path are redundant" -} - -declare_lint_pass!(SingleComponentPathImports => [SINGLE_COMPONENT_PATH_IMPORTS]); - -impl EarlyLintPass for SingleComponentPathImports { - fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { - if_chain! { - if !in_macro(item.span); - if cx.sess.opts.edition == Edition::Edition2018; - if !item.vis.kind.is_pub(); - if let ItemKind::Use(use_tree) = &item.kind; - if let segments = &use_tree.prefix.segments; - if segments.len() == 1; - if let UseTreeKind::Simple(None, _, _) = use_tree.kind; - then { - span_lint_and_sugg( - cx, - SINGLE_COMPONENT_PATH_IMPORTS, - item.span, - "this import is redundant", - "remove it entirely", - String::new(), - Applicability::MachineApplicable - ); - } - } - } -} diff --git a/clippy_lints/src/size_of_in_element_count.rs b/clippy_lints/src/size_of_in_element_count.rs deleted file mode 100644 index ea7a76146f52..000000000000 --- a/clippy_lints/src/size_of_in_element_count.rs +++ /dev/null @@ -1,145 +0,0 @@ -//! Lint on use of `size_of` or `size_of_val` of T in an expression -//! expecting a count of T - -use crate::utils::{match_def_path, paths, span_lint_and_help}; -use if_chain::if_chain; -use rustc_hir::BinOpKind; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, Ty, TyS, TypeAndMut}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Detects expressions where - /// `size_of::` or `size_of_val::` is used as a - /// count of elements of type `T` - /// - /// **Why is this bad?** These functions expect a count - /// of `T` and not a number of bytes - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,no_run - /// # use std::ptr::copy_nonoverlapping; - /// # use std::mem::size_of; - /// const SIZE: usize = 128; - /// let x = [2u8; SIZE]; - /// let mut y = [2u8; SIZE]; - /// unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::() * SIZE) }; - /// ``` - pub SIZE_OF_IN_ELEMENT_COUNT, - correctness, - "using `size_of::` or `size_of_val::` where a count of elements of `T` is expected" -} - -declare_lint_pass!(SizeOfInElementCount => [SIZE_OF_IN_ELEMENT_COUNT]); - -fn get_size_of_ty(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option> { - match expr.kind { - ExprKind::Call(count_func, _func_args) => { - if_chain! { - if let ExprKind::Path(ref count_func_qpath) = count_func.kind; - if let Some(def_id) = cx.qpath_res(count_func_qpath, count_func.hir_id).opt_def_id(); - if match_def_path(cx, def_id, &paths::MEM_SIZE_OF) - || match_def_path(cx, def_id, &paths::MEM_SIZE_OF_VAL); - then { - cx.typeck_results().node_substs(count_func.hir_id).types().next() - } else { - None - } - } - }, - ExprKind::Binary(op, left, right) if BinOpKind::Mul == op.node || BinOpKind::Div == op.node => { - get_size_of_ty(cx, left).or_else(|| get_size_of_ty(cx, right)) - }, - ExprKind::Cast(expr, _) => get_size_of_ty(cx, expr), - _ => None, - } -} - -fn get_pointee_ty_and_count_expr(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<(Ty<'tcx>, &'tcx Expr<'tcx>)> { - const FUNCTIONS: [&[&str]; 8] = [ - &paths::COPY_NONOVERLAPPING, - &paths::COPY, - &paths::WRITE_BYTES, - &paths::PTR_SWAP_NONOVERLAPPING, - &paths::PTR_SLICE_FROM_RAW_PARTS, - &paths::PTR_SLICE_FROM_RAW_PARTS_MUT, - &paths::SLICE_FROM_RAW_PARTS, - &paths::SLICE_FROM_RAW_PARTS_MUT, - ]; - const METHODS: [&str; 11] = [ - "write_bytes", - "copy_to", - "copy_from", - "copy_to_nonoverlapping", - "copy_from_nonoverlapping", - "add", - "wrapping_add", - "sub", - "wrapping_sub", - "offset", - "wrapping_offset", - ]; - - if_chain! { - // Find calls to ptr::{copy, copy_nonoverlapping} - // and ptr::{swap_nonoverlapping, write_bytes}, - if let ExprKind::Call(func, [.., count]) = expr.kind; - if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); - if FUNCTIONS.iter().any(|func_path| match_def_path(cx, def_id, func_path)); - - // Get the pointee type - if let Some(pointee_ty) = cx.typeck_results().node_substs(func.hir_id).types().next(); - then { - return Some((pointee_ty, count)); - } - }; - if_chain! { - // Find calls to copy_{from,to}{,_nonoverlapping} and write_bytes methods - if let ExprKind::MethodCall(method_path, _, [ptr_self, .., count], _) = expr.kind; - let method_ident = method_path.ident.as_str(); - if METHODS.iter().any(|m| *m == &*method_ident); - - // Get the pointee type - if let ty::RawPtr(TypeAndMut { ty: pointee_ty, .. }) = - cx.typeck_results().expr_ty(ptr_self).kind(); - then { - return Some((pointee_ty, count)); - } - }; - None -} - -impl<'tcx> LateLintPass<'tcx> for SizeOfInElementCount { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - const HELP_MSG: &str = "use a count of elements instead of a count of bytes\ - , it already gets multiplied by the size of the type"; - - const LINT_MSG: &str = "found a count of bytes \ - instead of a count of elements of `T`"; - - if_chain! { - // Find calls to functions with an element count parameter and get - // the pointee type and count parameter expression - if let Some((pointee_ty, count_expr)) = get_pointee_ty_and_count_expr(cx, expr); - - // Find a size_of call in the count parameter expression and - // check that it's the same type - if let Some(ty_used_for_size_of) = get_size_of_ty(cx, count_expr); - if TyS::same_type(pointee_ty, ty_used_for_size_of); - then { - span_lint_and_help( - cx, - SIZE_OF_IN_ELEMENT_COUNT, - count_expr.span, - LINT_MSG, - None, - HELP_MSG - ); - } - }; - } -} diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs deleted file mode 100644 index 96f6881556cf..000000000000 --- a/clippy_lints/src/slow_vector_initialization.rs +++ /dev/null @@ -1,330 +0,0 @@ -use crate::utils::sugg::Sugg; -use crate::utils::{get_enclosing_block, match_qpath, span_lint_and_then, SpanlessEq}; -use if_chain::if_chain; -use rustc_ast::ast::LitKind; -use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_block, walk_expr, walk_stmt, NestedVisitorMap, Visitor}; -use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, PatKind, QPath, Stmt, StmtKind}; -use rustc_lint::{LateContext, LateLintPass, Lint}; -use rustc_middle::hir::map::Map; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::symbol::Symbol; - -declare_clippy_lint! { - /// **What it does:** Checks slow zero-filled vector initialization - /// - /// **Why is this bad?** These structures are non-idiomatic and less efficient than simply using - /// `vec![0; len]`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # use core::iter::repeat; - /// # let len = 4; - /// - /// // Bad - /// let mut vec1 = Vec::with_capacity(len); - /// vec1.resize(len, 0); - /// - /// let mut vec2 = Vec::with_capacity(len); - /// vec2.extend(repeat(0).take(len)); - /// - /// // Good - /// let mut vec1 = vec![0; len]; - /// let mut vec2 = vec![0; len]; - /// ``` - pub SLOW_VECTOR_INITIALIZATION, - perf, - "slow vector initialization" -} - -declare_lint_pass!(SlowVectorInit => [SLOW_VECTOR_INITIALIZATION]); - -/// `VecAllocation` contains data regarding a vector allocated with `with_capacity` and then -/// assigned to a variable. For example, `let mut vec = Vec::with_capacity(0)` or -/// `vec = Vec::with_capacity(0)` -struct VecAllocation<'tcx> { - /// Symbol of the local variable name - variable_name: Symbol, - - /// Reference to the expression which allocates the vector - allocation_expr: &'tcx Expr<'tcx>, - - /// Reference to the expression used as argument on `with_capacity` call. This is used - /// to only match slow zero-filling idioms of the same length than vector initialization. - len_expr: &'tcx Expr<'tcx>, -} - -/// Type of slow initialization -enum InitializationType<'tcx> { - /// Extend is a slow initialization with the form `vec.extend(repeat(0).take(..))` - Extend(&'tcx Expr<'tcx>), - - /// Resize is a slow initialization with the form `vec.resize(.., 0)` - Resize(&'tcx Expr<'tcx>), -} - -impl<'tcx> LateLintPass<'tcx> for SlowVectorInit { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - // Matches initialization on reassignements. For example: `vec = Vec::with_capacity(100)` - if_chain! { - if let ExprKind::Assign(ref left, ref right, _) = expr.kind; - - // Extract variable name - if let ExprKind::Path(QPath::Resolved(_, ref path)) = left.kind; - if let Some(variable_name) = path.segments.get(0); - - // Extract len argument - if let Some(ref len_arg) = Self::is_vec_with_capacity(right); - - then { - let vi = VecAllocation { - variable_name: variable_name.ident.name, - allocation_expr: right, - len_expr: len_arg, - }; - - Self::search_initialization(cx, vi, expr.hir_id); - } - } - } - - fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { - // Matches statements which initializes vectors. For example: `let mut vec = Vec::with_capacity(10)` - if_chain! { - if let StmtKind::Local(ref local) = stmt.kind; - if let PatKind::Binding(BindingAnnotation::Mutable, .., variable_name, None) = local.pat.kind; - if let Some(ref init) = local.init; - if let Some(ref len_arg) = Self::is_vec_with_capacity(init); - - then { - let vi = VecAllocation { - variable_name: variable_name.name, - allocation_expr: init, - len_expr: len_arg, - }; - - Self::search_initialization(cx, vi, stmt.hir_id); - } - } - } -} - -impl SlowVectorInit { - /// Checks if the given expression is `Vec::with_capacity(..)`. It will return the expression - /// of the first argument of `with_capacity` call if it matches or `None` if it does not. - fn is_vec_with_capacity<'tcx>(expr: &Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { - if_chain! { - if let ExprKind::Call(ref func, ref args) = expr.kind; - if let ExprKind::Path(ref path) = func.kind; - if match_qpath(path, &["Vec", "with_capacity"]); - if args.len() == 1; - - then { - return Some(&args[0]); - } - } - - None - } - - /// Search initialization for the given vector - fn search_initialization<'tcx>(cx: &LateContext<'tcx>, vec_alloc: VecAllocation<'tcx>, parent_node: HirId) { - let enclosing_body = get_enclosing_block(cx, parent_node); - - if enclosing_body.is_none() { - return; - } - - let mut v = VectorInitializationVisitor { - cx, - vec_alloc, - slow_expression: None, - initialization_found: false, - }; - - v.visit_block(enclosing_body.unwrap()); - - if let Some(ref allocation_expr) = v.slow_expression { - Self::lint_initialization(cx, allocation_expr, &v.vec_alloc); - } - } - - fn lint_initialization<'tcx>( - cx: &LateContext<'tcx>, - initialization: &InitializationType<'tcx>, - vec_alloc: &VecAllocation<'_>, - ) { - match initialization { - InitializationType::Extend(e) | InitializationType::Resize(e) => Self::emit_lint( - cx, - e, - vec_alloc, - "slow zero-filling initialization", - SLOW_VECTOR_INITIALIZATION, - ), - }; - } - - fn emit_lint<'tcx>( - cx: &LateContext<'tcx>, - slow_fill: &Expr<'_>, - vec_alloc: &VecAllocation<'_>, - msg: &str, - lint: &'static Lint, - ) { - let len_expr = Sugg::hir(cx, vec_alloc.len_expr, "len"); - - span_lint_and_then(cx, lint, slow_fill.span, msg, |diag| { - diag.span_suggestion( - vec_alloc.allocation_expr.span, - "consider replace allocation with", - format!("vec![0; {}]", len_expr), - Applicability::Unspecified, - ); - }); - } -} - -/// `VectorInitializationVisitor` searches for unsafe or slow vector initializations for the given -/// vector. -struct VectorInitializationVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - - /// Contains the information. - vec_alloc: VecAllocation<'tcx>, - - /// Contains the slow initialization expression, if one was found. - slow_expression: Option>, - - /// `true` if the initialization of the vector has been found on the visited block. - initialization_found: bool, -} - -impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { - /// Checks if the given expression is extending a vector with `repeat(0).take(..)` - fn search_slow_extend_filling(&mut self, expr: &'tcx Expr<'_>) { - if_chain! { - if self.initialization_found; - if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; - if let ExprKind::Path(ref qpath_subj) = args[0].kind; - if match_qpath(&qpath_subj, &[&*self.vec_alloc.variable_name.as_str()]); - if path.ident.name == sym!(extend); - if let Some(ref extend_arg) = args.get(1); - if self.is_repeat_take(extend_arg); - - then { - self.slow_expression = Some(InitializationType::Extend(expr)); - } - } - } - - /// Checks if the given expression is resizing a vector with 0 - fn search_slow_resize_filling(&mut self, expr: &'tcx Expr<'_>) { - if_chain! { - if self.initialization_found; - if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; - if let ExprKind::Path(ref qpath_subj) = args[0].kind; - if match_qpath(&qpath_subj, &[&*self.vec_alloc.variable_name.as_str()]); - if path.ident.name == sym!(resize); - if let (Some(ref len_arg), Some(fill_arg)) = (args.get(1), args.get(2)); - - // Check that is filled with 0 - if let ExprKind::Lit(ref lit) = fill_arg.kind; - if let LitKind::Int(0, _) = lit.node; - - // Check that len expression is equals to `with_capacity` expression - if SpanlessEq::new(self.cx).eq_expr(len_arg, self.vec_alloc.len_expr); - - then { - self.slow_expression = Some(InitializationType::Resize(expr)); - } - } - } - - /// Returns `true` if give expression is `repeat(0).take(...)` - fn is_repeat_take(&self, expr: &Expr<'_>) -> bool { - if_chain! { - if let ExprKind::MethodCall(ref take_path, _, ref take_args, _) = expr.kind; - if take_path.ident.name == sym!(take); - - // Check that take is applied to `repeat(0)` - if let Some(ref repeat_expr) = take_args.get(0); - if Self::is_repeat_zero(repeat_expr); - - // Check that len expression is equals to `with_capacity` expression - if let Some(ref len_arg) = take_args.get(1); - if SpanlessEq::new(self.cx).eq_expr(len_arg, self.vec_alloc.len_expr); - - then { - return true; - } - } - - false - } - - /// Returns `true` if given expression is `repeat(0)` - fn is_repeat_zero(expr: &Expr<'_>) -> bool { - if_chain! { - if let ExprKind::Call(ref fn_expr, ref repeat_args) = expr.kind; - if let ExprKind::Path(ref qpath_repeat) = fn_expr.kind; - if match_qpath(&qpath_repeat, &["repeat"]); - if let Some(ref repeat_arg) = repeat_args.get(0); - if let ExprKind::Lit(ref lit) = repeat_arg.kind; - if let LitKind::Int(0, _) = lit.node; - - then { - return true - } - } - - false - } -} - -impl<'a, 'tcx> Visitor<'tcx> for VectorInitializationVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { - if self.initialization_found { - match stmt.kind { - StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => { - self.search_slow_extend_filling(expr); - self.search_slow_resize_filling(expr); - }, - _ => (), - } - - self.initialization_found = false; - } else { - walk_stmt(self, stmt); - } - } - - fn visit_block(&mut self, block: &'tcx Block<'_>) { - if self.initialization_found { - if let Some(ref s) = block.stmts.get(0) { - self.visit_stmt(s) - } - - self.initialization_found = false; - } else { - walk_block(self, block); - } - } - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - // Skip all the expressions previous to the vector initialization - if self.vec_alloc.allocation_expr.hir_id == expr.hir_id { - self.initialization_found = true; - } - - walk_expr(self, expr); - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} diff --git a/clippy_lints/src/stable_sort_primitive.rs b/clippy_lints/src/stable_sort_primitive.rs deleted file mode 100644 index 99e4b293ac68..000000000000 --- a/clippy_lints/src/stable_sort_primitive.rs +++ /dev/null @@ -1,132 +0,0 @@ -use crate::utils::{is_slice_of_primitives, span_lint_and_sugg, sugg::Sugg}; - -use if_chain::if_chain; - -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** - /// When sorting primitive values (integers, bools, chars, as well - /// as arrays, slices, and tuples of such items), it is better to - /// use an unstable sort than a stable sort. - /// - /// **Why is this bad?** - /// Using a stable sort consumes more memory and cpu cycles. Because - /// values which compare equal are identical, preserving their - /// relative order (the guarantee that a stable sort provides) means - /// nothing, while the extra costs still apply. - /// - /// **Known problems:** - /// None - /// - /// **Example:** - /// - /// ```rust - /// let mut vec = vec![2, 1, 3]; - /// vec.sort(); - /// ``` - /// Use instead: - /// ```rust - /// let mut vec = vec![2, 1, 3]; - /// vec.sort_unstable(); - /// ``` - pub STABLE_SORT_PRIMITIVE, - perf, - "use of sort() when sort_unstable() is equivalent" -} - -declare_lint_pass!(StableSortPrimitive => [STABLE_SORT_PRIMITIVE]); - -/// The three "kinds" of sorts -enum SortingKind { - Vanilla, - /* The other kinds of lint are currently commented out because they - * can map distinct values to equal ones. If the key function is - * provably one-to-one, or if the Cmp function conserves equality, - * then they could be linted on, but I don't know if we can check - * for that. */ - - /* ByKey, - * ByCmp, */ -} -impl SortingKind { - /// The name of the stable version of this kind of sort - fn stable_name(&self) -> &str { - match self { - SortingKind::Vanilla => "sort", - /* SortingKind::ByKey => "sort_by_key", - * SortingKind::ByCmp => "sort_by", */ - } - } - /// The name of the unstable version of this kind of sort - fn unstable_name(&self) -> &str { - match self { - SortingKind::Vanilla => "sort_unstable", - /* SortingKind::ByKey => "sort_unstable_by_key", - * SortingKind::ByCmp => "sort_unstable_by", */ - } - } - /// Takes the name of a function call and returns the kind of sort - /// that corresponds to that function name (or None if it isn't) - fn from_stable_name(name: &str) -> Option { - match name { - "sort" => Some(SortingKind::Vanilla), - // "sort_by" => Some(SortingKind::ByCmp), - // "sort_by_key" => Some(SortingKind::ByKey), - _ => None, - } - } -} - -/// A detected instance of this lint -struct LintDetection { - slice_name: String, - method: SortingKind, - method_args: String, - slice_type: String, -} - -fn detect_stable_sort_primitive(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { - if_chain! { - if let ExprKind::MethodCall(method_name, _, args, _) = &expr.kind; - if let Some(slice) = &args.get(0); - if let Some(method) = SortingKind::from_stable_name(&method_name.ident.name.as_str()); - if let Some(slice_type) = is_slice_of_primitives(cx, slice); - then { - let args_str = args.iter().skip(1).map(|arg| Sugg::hir(cx, arg, "..").to_string()).collect::>().join(", "); - Some(LintDetection { slice_name: Sugg::hir(cx, slice, "..").to_string(), method, method_args: args_str, slice_type }) - } else { - None - } - } -} - -impl LateLintPass<'_> for StableSortPrimitive { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - if let Some(detection) = detect_stable_sort_primitive(cx, expr) { - span_lint_and_sugg( - cx, - STABLE_SORT_PRIMITIVE, - expr.span, - format!( - "used {} instead of {} to sort primitive type `{}`", - detection.method.stable_name(), - detection.method.unstable_name(), - detection.slice_type, - ) - .as_str(), - "try", - format!( - "{}.{}({})", - detection.slice_name, - detection.method.unstable_name(), - detection.method_args - ), - Applicability::MachineApplicable, - ); - } - } -} diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs deleted file mode 100644 index 31dd5965473d..000000000000 --- a/clippy_lints/src/strings.rs +++ /dev/null @@ -1,388 +0,0 @@ -use rustc_errors::Applicability; -use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, LangItem, QPath}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Spanned; -use rustc_span::sym; - -use if_chain::if_chain; - -use crate::utils::SpanlessEq; -use crate::utils::{ - get_parent_expr, is_allowed, is_type_diagnostic_item, match_function_call, method_calls, paths, span_lint, - span_lint_and_help, span_lint_and_sugg, -}; - -declare_clippy_lint! { - /// **What it does:** Checks for string appends of the form `x = x + y` (without - /// `let`!). - /// - /// **Why is this bad?** It's not really bad, but some people think that the - /// `.push_str(_)` method is more readable. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// let mut x = "Hello".to_owned(); - /// x = x + ", World"; - /// - /// // More readable - /// x += ", World"; - /// x.push_str(", World"); - /// ``` - pub STRING_ADD_ASSIGN, - pedantic, - "using `x = x + ..` where x is a `String` instead of `push_str()`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for all instances of `x + _` where `x` is of type - /// `String`, but only if [`string_add_assign`](#string_add_assign) does *not* - /// match. - /// - /// **Why is this bad?** It's not bad in and of itself. However, this particular - /// `Add` implementation is asymmetric (the other operand need not be `String`, - /// but `x` does), while addition as mathematically defined is symmetric, also - /// the `String::push_str(_)` function is a perfectly good replacement. - /// Therefore, some dislike it and wish not to have it in their code. - /// - /// That said, other people think that string addition, having a long tradition - /// in other languages is actually fine, which is why we decided to make this - /// particular lint `allow` by default. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// let x = "Hello".to_owned(); - /// x + ", World"; - /// ``` - pub STRING_ADD, - restriction, - "using `x + ..` where x is a `String` instead of `push_str()`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for the `as_bytes` method called on string literals - /// that contain only ASCII characters. - /// - /// **Why is this bad?** Byte string literals (e.g., `b"foo"`) can be used - /// instead. They are shorter but less discoverable than `as_bytes()`. - /// - /// **Known Problems:** - /// `"str".as_bytes()` and the suggested replacement of `b"str"` are not - /// equivalent because they have different types. The former is `&[u8]` - /// while the latter is `&[u8; 3]`. That means in general they will have a - /// different set of methods and different trait implementations. - /// - /// ```compile_fail - /// fn f(v: Vec) {} - /// - /// f("...".as_bytes().to_owned()); // works - /// f(b"...".to_owned()); // does not work, because arg is [u8; 3] not Vec - /// - /// fn g(r: impl std::io::Read) {} - /// - /// g("...".as_bytes()); // works - /// g(b"..."); // does not work - /// ``` - /// - /// The actual equivalent of `"str".as_bytes()` with the same type is not - /// `b"str"` but `&b"str"[..]`, which is a great deal of punctuation and not - /// more readable than a function call. - /// - /// **Example:** - /// ```rust - /// // Bad - /// let bs = "a byte string".as_bytes(); - /// - /// // Good - /// let bs = b"a byte string"; - /// ``` - pub STRING_LIT_AS_BYTES, - nursery, - "calling `as_bytes` on a string literal instead of using a byte string literal" -} - -declare_lint_pass!(StringAdd => [STRING_ADD, STRING_ADD_ASSIGN]); - -impl<'tcx> LateLintPass<'tcx> for StringAdd { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if in_external_macro(cx.sess(), e.span) { - return; - } - - if let ExprKind::Binary( - Spanned { - node: BinOpKind::Add, .. - }, - ref left, - _, - ) = e.kind - { - if is_string(cx, left) { - if !is_allowed(cx, STRING_ADD_ASSIGN, e.hir_id) { - let parent = get_parent_expr(cx, e); - if let Some(p) = parent { - if let ExprKind::Assign(ref target, _, _) = p.kind { - // avoid duplicate matches - if SpanlessEq::new(cx).eq_expr(target, left) { - return; - } - } - } - } - span_lint( - cx, - STRING_ADD, - e.span, - "you added something to a string. Consider using `String::push_str()` instead", - ); - } - } else if let ExprKind::Assign(ref target, ref src, _) = e.kind { - if is_string(cx, target) && is_add(cx, src, target) { - span_lint( - cx, - STRING_ADD_ASSIGN, - e.span, - "you assigned the result of adding something to this string. Consider using \ - `String::push_str()` instead", - ); - } - } - } -} - -fn is_string(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { - is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(e).peel_refs(), sym::string_type) -} - -fn is_add(cx: &LateContext<'_>, src: &Expr<'_>, target: &Expr<'_>) -> bool { - match src.kind { - ExprKind::Binary( - Spanned { - node: BinOpKind::Add, .. - }, - ref left, - _, - ) => SpanlessEq::new(cx).eq_expr(target, left), - ExprKind::Block(ref block, _) => { - block.stmts.is_empty() && block.expr.as_ref().map_or(false, |expr| is_add(cx, expr, target)) - }, - _ => false, - } -} - -declare_clippy_lint! { - /// **What it does:** Check if the string is transformed to byte array and casted back to string. - /// - /// **Why is this bad?** It's unnecessary, the string can be used directly. - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```rust - /// let _ = std::str::from_utf8(&"Hello World!".as_bytes()[6..11]).unwrap(); - /// ``` - /// could be written as - /// ```rust - /// let _ = &"Hello World!"[6..11]; - /// ``` - pub STRING_FROM_UTF8_AS_BYTES, - complexity, - "casting string slices to byte slices and back" -} - -// Max length a b"foo" string can take -const MAX_LENGTH_BYTE_STRING_LIT: usize = 32; - -declare_lint_pass!(StringLitAsBytes => [STRING_LIT_AS_BYTES, STRING_FROM_UTF8_AS_BYTES]); - -impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - use crate::utils::{snippet, snippet_with_applicability}; - use rustc_ast::LitKind; - - if_chain! { - // Find std::str::converts::from_utf8 - if let Some(args) = match_function_call(cx, e, &paths::STR_FROM_UTF8); - - // Find string::as_bytes - if let ExprKind::AddrOf(BorrowKind::Ref, _, ref args) = args[0].kind; - if let ExprKind::Index(ref left, ref right) = args.kind; - let (method_names, expressions, _) = method_calls(left, 1); - if method_names.len() == 1; - if expressions.len() == 1; - if expressions[0].len() == 1; - if method_names[0] == sym!(as_bytes); - - // Check for slicer - if let ExprKind::Struct(QPath::LangItem(LangItem::Range, _), _, _) = right.kind; - - then { - let mut applicability = Applicability::MachineApplicable; - let string_expression = &expressions[0][0]; - - let snippet_app = snippet_with_applicability( - cx, - string_expression.span, "..", - &mut applicability, - ); - - span_lint_and_sugg( - cx, - STRING_FROM_UTF8_AS_BYTES, - e.span, - "calling a slice of `as_bytes()` with `from_utf8` should be not necessary", - "try", - format!("Some(&{}[{}])", snippet_app, snippet(cx, right.span, "..")), - applicability - ) - } - } - - if_chain! { - if let ExprKind::MethodCall(path, _, args, _) = &e.kind; - if path.ident.name == sym!(as_bytes); - if let ExprKind::Lit(lit) = &args[0].kind; - if let LitKind::Str(lit_content, _) = &lit.node; - then { - let callsite = snippet(cx, args[0].span.source_callsite(), r#""foo""#); - let mut applicability = Applicability::MachineApplicable; - if callsite.starts_with("include_str!") { - span_lint_and_sugg( - cx, - STRING_LIT_AS_BYTES, - e.span, - "calling `as_bytes()` on `include_str!(..)`", - "consider using `include_bytes!(..)` instead", - snippet_with_applicability(cx, args[0].span, r#""foo""#, &mut applicability).replacen( - "include_str", - "include_bytes", - 1, - ), - applicability, - ); - } else if lit_content.as_str().is_ascii() - && lit_content.as_str().len() <= MAX_LENGTH_BYTE_STRING_LIT - && !args[0].span.from_expansion() - { - span_lint_and_sugg( - cx, - STRING_LIT_AS_BYTES, - e.span, - "calling `as_bytes()` on a string literal", - "consider using a byte string literal instead", - format!( - "b{}", - snippet_with_applicability(cx, args[0].span, r#""foo""#, &mut applicability) - ), - applicability, - ); - } - } - } - } -} - -declare_clippy_lint! { - /// **What it does:** This lint checks for `.to_string()` method calls on values of type `&str`. - /// - /// **Why is this bad?** The `to_string` method is also used on other types to convert them to a string. - /// When called on a `&str` it turns the `&str` into the owned variant `String`, which can be better - /// expressed with `.to_owned()`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// // example code where clippy issues a warning - /// let _ = "str".to_string(); - /// ``` - /// Use instead: - /// ```rust - /// // example code which does not raise clippy warning - /// let _ = "str".to_owned(); - /// ``` - pub STR_TO_STRING, - restriction, - "using `to_string()` on a `&str`, which should be `to_owned()`" -} - -declare_lint_pass!(StrToString => [STR_TO_STRING]); - -impl LateLintPass<'_> for StrToString { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::MethodCall(path, _, args, _) = &expr.kind; - if path.ident.name == sym!(to_string); - let ty = cx.typeck_results().expr_ty(&args[0]); - if let ty::Ref(_, ty, ..) = ty.kind(); - if *ty.kind() == ty::Str; - then { - span_lint_and_help( - cx, - STR_TO_STRING, - expr.span, - "`to_string()` called on a `&str`", - None, - "consider using `.to_owned()`", - ); - } - } - } -} - -declare_clippy_lint! { - /// **What it does:** This lint checks for `.to_string()` method calls on values of type `String`. - /// - /// **Why is this bad?** The `to_string` method is also used on other types to convert them to a string. - /// When called on a `String` it only clones the `String`, which can be better expressed with `.clone()`. - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// // example code where clippy issues a warning - /// let msg = String::from("Hello World"); - /// let _ = msg.to_string(); - /// ``` - /// Use instead: - /// ```rust - /// // example code which does not raise clippy warning - /// let msg = String::from("Hello World"); - /// let _ = msg.clone(); - /// ``` - pub STRING_TO_STRING, - restriction, - "using `to_string()` on a `String`, which should be `clone()`" -} - -declare_lint_pass!(StringToString => [STRING_TO_STRING]); - -impl LateLintPass<'_> for StringToString { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::MethodCall(path, _, args, _) = &expr.kind; - if path.ident.name == sym!(to_string); - let ty = cx.typeck_results().expr_ty(&args[0]); - if is_type_diagnostic_item(cx, ty, sym::string_type); - then { - span_lint_and_help( - cx, - STRING_TO_STRING, - expr.span, - "`to_string()` called on a `String`", - None, - "consider using `.clone()`", - ); - } - } - } -} diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs deleted file mode 100644 index cccd24ccf940..000000000000 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ /dev/null @@ -1,693 +0,0 @@ -use crate::utils::ast_utils::{eq_id, is_useless_with_eq_exprs, IdentIter}; -use crate::utils::{snippet_with_applicability, span_lint_and_sugg}; -use core::ops::{Add, AddAssign}; -use if_chain::if_chain; -use rustc_ast::ast::{BinOpKind, Expr, ExprKind, StmtKind}; -use rustc_data_structures::fx::FxHashSet; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Spanned; -use rustc_span::symbol::Ident; -use rustc_span::Span; - -declare_clippy_lint! { - /// **What it does:** - /// Checks for unlikely usages of binary operators that are almost - /// certainly typos and/or copy/paste errors, given the other usages - /// of binary operators nearby. - /// **Why is this bad?** - /// They are probably bugs and if they aren't then they look like bugs - /// and you should add a comment explaining why you are doing such an - /// odd set of operations. - /// **Known problems:** - /// There may be some false positives if you are trying to do something - /// unusual that happens to look like a typo. - /// - /// **Example:** - /// - /// ```rust - /// struct Vec3 { - /// x: f64, - /// y: f64, - /// z: f64, - /// } - /// - /// impl Eq for Vec3 {} - /// - /// impl PartialEq for Vec3 { - /// fn eq(&self, other: &Self) -> bool { - /// // This should trigger the lint because `self.x` is compared to `other.y` - /// self.x == other.y && self.y == other.y && self.z == other.z - /// } - /// } - /// ``` - /// Use instead: - /// ```rust - /// # struct Vec3 { - /// # x: f64, - /// # y: f64, - /// # z: f64, - /// # } - /// // same as above except: - /// impl PartialEq for Vec3 { - /// fn eq(&self, other: &Self) -> bool { - /// // Note we now compare other.x to self.x - /// self.x == other.x && self.y == other.y && self.z == other.z - /// } - /// } - /// ``` - pub SUSPICIOUS_OPERATION_GROUPINGS, - style, - "groupings of binary operations that look suspiciously like typos" -} - -declare_lint_pass!(SuspiciousOperationGroupings => [SUSPICIOUS_OPERATION_GROUPINGS]); - -impl EarlyLintPass for SuspiciousOperationGroupings { - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - if expr.span.from_expansion() { - return; - } - - if let Some(binops) = extract_related_binops(&expr.kind) { - check_binops(cx, &binops.iter().collect::>()); - - let mut op_types = Vec::with_capacity(binops.len()); - // We could use a hashmap, etc. to avoid being O(n*m) here, but - // we want the lints to be emitted in a consistent order. Besides, - // m, (the number of distinct `BinOpKind`s in `binops`) - // will often be small, and does have an upper limit. - binops.iter().map(|b| b.op).for_each(|op| { - if !op_types.contains(&op) { - op_types.push(op); - } - }); - - for op_type in op_types { - let ops: Vec<_> = binops.iter().filter(|b| b.op == op_type).collect(); - - check_binops(cx, &ops); - } - } - } -} - -fn check_binops(cx: &EarlyContext<'_>, binops: &[&BinaryOp<'_>]) { - let binop_count = binops.len(); - if binop_count < 2 { - // Single binary operation expressions would likely be false - // positives. - return; - } - - let mut one_ident_difference_count = 0; - let mut no_difference_info = None; - let mut double_difference_info = None; - let mut expected_ident_loc = None; - - let mut paired_identifiers = FxHashSet::default(); - - for (i, BinaryOp { left, right, op, .. }) in binops.iter().enumerate() { - match ident_difference_expr(left, right) { - IdentDifference::NoDifference => { - if is_useless_with_eq_exprs(*op) { - // The `eq_op` lint should catch this in this case. - return; - } - - no_difference_info = Some(i); - }, - IdentDifference::Single(ident_loc) => { - one_ident_difference_count += 1; - if let Some(previous_expected) = expected_ident_loc { - if previous_expected != ident_loc { - // This expression doesn't match the form we're - // looking for. - return; - } - } else { - expected_ident_loc = Some(ident_loc); - } - - // If there was only a single difference, all other idents - // must have been the same, and thus were paired. - for id in skip_index(IdentIter::from(*left), ident_loc.index) { - paired_identifiers.insert(id); - } - }, - IdentDifference::Double(ident_loc1, ident_loc2) => { - double_difference_info = Some((i, ident_loc1, ident_loc2)); - }, - IdentDifference::Multiple | IdentDifference::NonIdent => { - // It's too hard to know whether this is a bug or not. - return; - }, - } - } - - let mut applicability = Applicability::MachineApplicable; - - if let Some(expected_loc) = expected_ident_loc { - match (no_difference_info, double_difference_info) { - (Some(i), None) => attempt_to_emit_no_difference_lint(cx, binops, i, expected_loc), - (None, Some((double_difference_index, ident_loc1, ident_loc2))) => { - if_chain! { - if one_ident_difference_count == binop_count - 1; - if let Some(binop) = binops.get(double_difference_index); - then { - let changed_loc = if ident_loc1 == expected_loc { - ident_loc2 - } else if ident_loc2 == expected_loc { - ident_loc1 - } else { - // This expression doesn't match the form we're - // looking for. - return; - }; - - if let Some(sugg) = ident_swap_sugg( - cx, - &paired_identifiers, - binop, - changed_loc, - &mut applicability, - ) { - emit_suggestion( - cx, - binop.span, - sugg, - applicability, - ); - } - } - } - }, - _ => {}, - } - } -} - -fn attempt_to_emit_no_difference_lint( - cx: &EarlyContext<'_>, - binops: &[&BinaryOp<'_>], - i: usize, - expected_loc: IdentLocation, -) { - if let Some(binop) = binops.get(i).cloned() { - // We need to try and figure out which identifier we should - // suggest using instead. Since there could be multiple - // replacement candidates in a given expression, and we're - // just taking the first one, we may get some bad lint - // messages. - let mut applicability = Applicability::MaybeIncorrect; - - // We assume that the correct ident is one used elsewhere in - // the other binops, in a place that there was a single - // difference between idents before. - let old_left_ident = get_ident(binop.left, expected_loc); - let old_right_ident = get_ident(binop.right, expected_loc); - - for b in skip_index(binops.iter(), i) { - if_chain! { - if let (Some(old_ident), Some(new_ident)) = - (old_left_ident, get_ident(b.left, expected_loc)); - if old_ident != new_ident; - if let Some(sugg) = suggestion_with_swapped_ident( - cx, - binop.left, - expected_loc, - new_ident, - &mut applicability, - ); - then { - emit_suggestion( - cx, - binop.span, - replace_left_sugg(cx, &binop, &sugg, &mut applicability), - applicability, - ); - return; - } - } - - if_chain! { - if let (Some(old_ident), Some(new_ident)) = - (old_right_ident, get_ident(b.right, expected_loc)); - if old_ident != new_ident; - if let Some(sugg) = suggestion_with_swapped_ident( - cx, - binop.right, - expected_loc, - new_ident, - &mut applicability, - ); - then { - emit_suggestion( - cx, - binop.span, - replace_right_sugg(cx, &binop, &sugg, &mut applicability), - applicability, - ); - return; - } - } - } - } -} - -fn emit_suggestion(cx: &EarlyContext<'_>, span: Span, sugg: String, applicability: Applicability) { - span_lint_and_sugg( - cx, - SUSPICIOUS_OPERATION_GROUPINGS, - span, - "This sequence of operators looks suspiciously like a bug.", - "I think you meant", - sugg, - applicability, - ) -} - -fn ident_swap_sugg( - cx: &EarlyContext<'_>, - paired_identifiers: &FxHashSet, - binop: &BinaryOp<'_>, - location: IdentLocation, - applicability: &mut Applicability, -) -> Option { - let left_ident = get_ident(&binop.left, location)?; - let right_ident = get_ident(&binop.right, location)?; - - let sugg = match ( - paired_identifiers.contains(&left_ident), - paired_identifiers.contains(&right_ident), - ) { - (true, true) | (false, false) => { - // We don't have a good guess of what ident should be - // used instead, in these cases. - *applicability = Applicability::MaybeIncorrect; - - // We arbitraily choose one side to suggest changing, - // since we don't have a better guess. If the user - // ends up duplicating a clause, the `logic_bug` lint - // should catch it. - - let right_suggestion = - suggestion_with_swapped_ident(cx, &binop.right, location, left_ident, applicability)?; - - replace_right_sugg(cx, binop, &right_suggestion, applicability) - }, - (false, true) => { - // We haven't seen a pair involving the left one, so - // it's probably what is wanted. - - let right_suggestion = - suggestion_with_swapped_ident(cx, &binop.right, location, left_ident, applicability)?; - - replace_right_sugg(cx, binop, &right_suggestion, applicability) - }, - (true, false) => { - // We haven't seen a pair involving the right one, so - // it's probably what is wanted. - let left_suggestion = suggestion_with_swapped_ident(cx, &binop.left, location, right_ident, applicability)?; - - replace_left_sugg(cx, binop, &left_suggestion, applicability) - }, - }; - - Some(sugg) -} - -fn replace_left_sugg( - cx: &EarlyContext<'_>, - binop: &BinaryOp<'_>, - left_suggestion: &str, - applicability: &mut Applicability, -) -> String { - format!( - "{} {} {}", - left_suggestion, - binop.op.to_string(), - snippet_with_applicability(cx, binop.right.span, "..", applicability), - ) -} - -fn replace_right_sugg( - cx: &EarlyContext<'_>, - binop: &BinaryOp<'_>, - right_suggestion: &str, - applicability: &mut Applicability, -) -> String { - format!( - "{} {} {}", - snippet_with_applicability(cx, binop.left.span, "..", applicability), - binop.op.to_string(), - right_suggestion, - ) -} - -#[derive(Clone, Debug)] -struct BinaryOp<'exprs> { - op: BinOpKind, - span: Span, - left: &'exprs Expr, - right: &'exprs Expr, -} - -impl BinaryOp<'exprs> { - fn new(op: BinOpKind, span: Span, (left, right): (&'exprs Expr, &'exprs Expr)) -> Self { - Self { op, span, left, right } - } -} - -fn strip_non_ident_wrappers(expr: &Expr) -> &Expr { - let mut output = expr; - loop { - output = match &output.kind { - ExprKind::Paren(ref inner) | ExprKind::Unary(_, ref inner) => inner, - _ => { - return output; - }, - }; - } -} - -fn extract_related_binops(kind: &ExprKind) -> Option>> { - append_opt_vecs(chained_binops(kind), if_statment_binops(kind)) -} - -fn if_statment_binops(kind: &ExprKind) -> Option>> { - match kind { - ExprKind::If(ref condition, _, _) => chained_binops(&condition.kind), - ExprKind::Paren(ref e) => if_statment_binops(&e.kind), - ExprKind::Block(ref block, _) => { - let mut output = None; - for stmt in &block.stmts { - match stmt.kind { - StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => { - output = append_opt_vecs(output, if_statment_binops(&e.kind)); - }, - _ => {}, - } - } - output - }, - _ => None, - } -} - -fn append_opt_vecs(target_opt: Option>, source_opt: Option>) -> Option> { - match (target_opt, source_opt) { - (Some(mut target), Some(mut source)) => { - target.reserve(source.len()); - for op in source.drain(..) { - target.push(op); - } - Some(target) - }, - (Some(v), None) | (None, Some(v)) => Some(v), - (None, None) => None, - } -} - -fn chained_binops(kind: &ExprKind) -> Option>> { - match kind { - ExprKind::Binary(_, left_outer, right_outer) => chained_binops_helper(left_outer, right_outer), - ExprKind::Paren(ref e) | ExprKind::Unary(_, ref e) => chained_binops(&e.kind), - _ => None, - } -} - -fn chained_binops_helper(left_outer: &'expr Expr, right_outer: &'expr Expr) -> Option>> { - match (&left_outer.kind, &right_outer.kind) { - ( - ExprKind::Paren(ref left_e) | ExprKind::Unary(_, ref left_e), - ExprKind::Paren(ref right_e) | ExprKind::Unary(_, ref right_e), - ) => chained_binops_helper(left_e, right_e), - (ExprKind::Paren(ref left_e) | ExprKind::Unary(_, ref left_e), _) => chained_binops_helper(left_e, right_outer), - (_, ExprKind::Paren(ref right_e) | ExprKind::Unary(_, ref right_e)) => { - chained_binops_helper(left_outer, right_e) - }, - ( - ExprKind::Binary(Spanned { node: left_op, .. }, ref left_left, ref left_right), - ExprKind::Binary(Spanned { node: right_op, .. }, ref right_left, ref right_right), - ) => match ( - chained_binops_helper(left_left, left_right), - chained_binops_helper(right_left, right_right), - ) { - (Some(mut left_ops), Some(mut right_ops)) => { - left_ops.reserve(right_ops.len()); - for op in right_ops.drain(..) { - left_ops.push(op); - } - Some(left_ops) - }, - (Some(mut left_ops), _) => { - left_ops.push(BinaryOp::new(*right_op, right_outer.span, (right_left, right_right))); - Some(left_ops) - }, - (_, Some(mut right_ops)) => { - right_ops.insert(0, BinaryOp::new(*left_op, left_outer.span, (left_left, left_right))); - Some(right_ops) - }, - (None, None) => Some(vec![ - BinaryOp::new(*left_op, left_outer.span, (left_left, left_right)), - BinaryOp::new(*right_op, right_outer.span, (right_left, right_right)), - ]), - }, - _ => None, - } -} - -#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)] -struct IdentLocation { - index: usize, -} - -impl Add for IdentLocation { - type Output = IdentLocation; - - fn add(self, other: Self) -> Self::Output { - Self { - index: self.index + other.index, - } - } -} - -impl AddAssign for IdentLocation { - fn add_assign(&mut self, other: Self) { - *self = *self + other - } -} - -#[derive(Clone, Copy, Debug)] -enum IdentDifference { - NoDifference, - Single(IdentLocation), - Double(IdentLocation, IdentLocation), - Multiple, - NonIdent, -} - -impl Add for IdentDifference { - type Output = IdentDifference; - - fn add(self, other: Self) -> Self::Output { - match (self, other) { - (Self::NoDifference, output) | (output, Self::NoDifference) => output, - (Self::Multiple, _) - | (_, Self::Multiple) - | (Self::Double(_, _), Self::Single(_)) - | (Self::Single(_) | Self::Double(_, _), Self::Double(_, _)) => Self::Multiple, - (Self::NonIdent, _) | (_, Self::NonIdent) => Self::NonIdent, - (Self::Single(il1), Self::Single(il2)) => Self::Double(il1, il2), - } - } -} - -impl AddAssign for IdentDifference { - fn add_assign(&mut self, other: Self) { - *self = *self + other - } -} - -impl IdentDifference { - /// Returns true if learning about more differences will not change the value - /// of this `IdentDifference`, and false otherwise. - fn is_complete(&self) -> bool { - match self { - Self::NoDifference | Self::Single(_) | Self::Double(_, _) => false, - Self::Multiple | Self::NonIdent => true, - } - } -} - -fn ident_difference_expr(left: &Expr, right: &Expr) -> IdentDifference { - ident_difference_expr_with_base_location(left, right, IdentLocation::default()).0 -} - -fn ident_difference_expr_with_base_location( - left: &Expr, - right: &Expr, - mut base: IdentLocation, -) -> (IdentDifference, IdentLocation) { - // Ideally, this function should not use IdentIter because it should return - // early if the expressions have any non-ident differences. We want that early - // return because if without that restriction the lint would lead to false - // positives. - // - // But, we cannot (easily?) use a `rustc_ast::visit::Visitor`, since we need - // the two expressions to be walked in lockstep. And without a `Visitor`, we'd - // have to do all the AST traversal ourselves, which is a lot of work, since to - // do it properly we'd need to be able to handle more or less every possible - // AST node since `Item`s can be written inside `Expr`s. - // - // In practice, it seems likely that expressions, above a certain size, that - // happen to use the exact same idents in the exact same order, and which are - // not structured the same, would be rare. Therefore it seems likely that if - // we do only the first layer of matching ourselves and eventually fallback on - // IdentIter, then the output of this function will be almost always be correct - // in practice. - // - // If it turns out that problematic cases are more prelavent than we assume, - // then we should be able to change this function to do the correct traversal, - // without needing to change the rest of the code. - - #![allow(clippy::enum_glob_use)] - use ExprKind::*; - - match ( - &strip_non_ident_wrappers(left).kind, - &strip_non_ident_wrappers(right).kind, - ) { - (Yield(_), Yield(_)) - | (Try(_), Try(_)) - | (Paren(_), Paren(_)) - | (Repeat(_, _), Repeat(_, _)) - | (Struct(_, _, _), Struct(_, _, _)) - | (MacCall(_), MacCall(_)) - | (LlvmInlineAsm(_), LlvmInlineAsm(_)) - | (InlineAsm(_), InlineAsm(_)) - | (Ret(_), Ret(_)) - | (Continue(_), Continue(_)) - | (Break(_, _), Break(_, _)) - | (AddrOf(_, _, _), AddrOf(_, _, _)) - | (Path(_, _), Path(_, _)) - | (Range(_, _, _), Range(_, _, _)) - | (Index(_, _), Index(_, _)) - | (Field(_, _), Field(_, _)) - | (AssignOp(_, _, _), AssignOp(_, _, _)) - | (Assign(_, _, _), Assign(_, _, _)) - | (TryBlock(_), TryBlock(_)) - | (Await(_), Await(_)) - | (Async(_, _, _), Async(_, _, _)) - | (Block(_, _), Block(_, _)) - | (Closure(_, _, _, _, _, _), Closure(_, _, _, _, _, _)) - | (Match(_, _), Match(_, _)) - | (Loop(_, _), Loop(_, _)) - | (ForLoop(_, _, _, _), ForLoop(_, _, _, _)) - | (While(_, _, _), While(_, _, _)) - | (If(_, _, _), If(_, _, _)) - | (Let(_, _), Let(_, _)) - | (Type(_, _), Type(_, _)) - | (Cast(_, _), Cast(_, _)) - | (Lit(_), Lit(_)) - | (Unary(_, _), Unary(_, _)) - | (Binary(_, _, _), Binary(_, _, _)) - | (Tup(_), Tup(_)) - | (MethodCall(_, _, _), MethodCall(_, _, _)) - | (Call(_, _), Call(_, _)) - | (ConstBlock(_), ConstBlock(_)) - | (Array(_), Array(_)) - | (Box(_), Box(_)) => { - // keep going - }, - _ => { - return (IdentDifference::NonIdent, base); - }, - } - - let mut difference = IdentDifference::NoDifference; - - for (left_attr, right_attr) in left.attrs.iter().zip(right.attrs.iter()) { - let (new_difference, new_base) = - ident_difference_via_ident_iter_with_base_location(left_attr, right_attr, base); - base = new_base; - difference += new_difference; - if difference.is_complete() { - return (difference, base); - } - } - - let (new_difference, new_base) = ident_difference_via_ident_iter_with_base_location(left, right, base); - base = new_base; - difference += new_difference; - - (difference, base) -} - -fn ident_difference_via_ident_iter_with_base_location>( - left: Iterable, - right: Iterable, - mut base: IdentLocation, -) -> (IdentDifference, IdentLocation) { - // See the note in `ident_difference_expr_with_base_location` about `IdentIter` - let mut difference = IdentDifference::NoDifference; - - let mut left_iterator = left.into(); - let mut right_iterator = right.into(); - - loop { - match (left_iterator.next(), right_iterator.next()) { - (Some(left_ident), Some(right_ident)) => { - if !eq_id(left_ident, right_ident) { - difference += IdentDifference::Single(base); - if difference.is_complete() { - return (difference, base); - } - } - }, - (Some(_), None) | (None, Some(_)) => { - return (IdentDifference::NonIdent, base); - }, - (None, None) => { - return (difference, base); - }, - } - base += IdentLocation { index: 1 }; - } -} - -fn get_ident(expr: &Expr, location: IdentLocation) -> Option { - IdentIter::from(expr).nth(location.index) -} - -fn suggestion_with_swapped_ident( - cx: &EarlyContext<'_>, - expr: &Expr, - location: IdentLocation, - new_ident: Ident, - applicability: &mut Applicability, -) -> Option { - get_ident(expr, location).and_then(|current_ident| { - if eq_id(current_ident, new_ident) { - // We never want to suggest a non-change - return None; - } - - Some(format!( - "{}{}{}", - snippet_with_applicability(cx, expr.span.with_hi(current_ident.span.lo()), "..", applicability), - new_ident.to_string(), - snippet_with_applicability(cx, expr.span.with_lo(current_ident.span.hi()), "..", applicability), - )) - }) -} - -fn skip_index(iter: Iter, index: usize) -> impl Iterator -where - Iter: Iterator, -{ - iter.enumerate() - .filter_map(move |(i, a)| if i == index { None } else { Some(a) }) -} diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs deleted file mode 100644 index 3a688a7bbef3..000000000000 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ /dev/null @@ -1,208 +0,0 @@ -use crate::utils::{get_trait_def_id, span_lint, trait_ref_of_method}; -use if_chain::if_chain; -use rustc_hir as hir; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Lints for suspicious operations in impls of arithmetic operators, e.g. - /// subtracting elements in an Add impl. - /// - /// **Why this is bad?** This is probably a typo or copy-and-paste error and not intended. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// impl Add for Foo { - /// type Output = Foo; - /// - /// fn add(self, other: Foo) -> Foo { - /// Foo(self.0 - other.0) - /// } - /// } - /// ``` - pub SUSPICIOUS_ARITHMETIC_IMPL, - correctness, - "suspicious use of operators in impl of arithmetic trait" -} - -declare_clippy_lint! { - /// **What it does:** Lints for suspicious operations in impls of OpAssign, e.g. - /// subtracting elements in an AddAssign impl. - /// - /// **Why this is bad?** This is probably a typo or copy-and-paste error and not intended. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```ignore - /// impl AddAssign for Foo { - /// fn add_assign(&mut self, other: Foo) { - /// *self = *self - other; - /// } - /// } - /// ``` - pub SUSPICIOUS_OP_ASSIGN_IMPL, - correctness, - "suspicious use of operators in impl of OpAssign trait" -} - -declare_lint_pass!(SuspiciousImpl => [SUSPICIOUS_ARITHMETIC_IMPL, SUSPICIOUS_OP_ASSIGN_IMPL]); - -impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - if let hir::ExprKind::Binary(binop, _, _) | hir::ExprKind::AssignOp(binop, ..) = expr.kind { - match binop.node { - hir::BinOpKind::Eq - | hir::BinOpKind::Lt - | hir::BinOpKind::Le - | hir::BinOpKind::Ne - | hir::BinOpKind::Ge - | hir::BinOpKind::Gt => return, - _ => {}, - } - - // Check for more than one binary operation in the implemented function - // Linting when multiple operations are involved can result in false positives - if_chain! { - let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id); - if let hir::Node::ImplItem(impl_item) = cx.tcx.hir().get(parent_fn); - if let hir::ImplItemKind::Fn(_, body_id) = impl_item.kind; - let body = cx.tcx.hir().body(body_id); - let mut visitor = BinaryExprVisitor { nb_binops: 0 }; - - then { - walk_expr(&mut visitor, &body.value); - if visitor.nb_binops > 1 { - return; - } - } - } - - if let Some(impl_trait) = check_binop( - cx, - expr, - binop.node, - &[ - "Add", "Sub", "Mul", "Div", "Rem", "BitAnd", "BitOr", "BitXor", "Shl", "Shr", - ], - &[ - hir::BinOpKind::Add, - hir::BinOpKind::Sub, - hir::BinOpKind::Mul, - hir::BinOpKind::Div, - hir::BinOpKind::Rem, - hir::BinOpKind::BitAnd, - hir::BinOpKind::BitOr, - hir::BinOpKind::BitXor, - hir::BinOpKind::Shl, - hir::BinOpKind::Shr, - ], - ) { - span_lint( - cx, - SUSPICIOUS_ARITHMETIC_IMPL, - binop.span, - &format!("suspicious use of binary operator in `{}` impl", impl_trait), - ); - } - - if let Some(impl_trait) = check_binop( - cx, - expr, - binop.node, - &[ - "AddAssign", - "SubAssign", - "MulAssign", - "DivAssign", - "BitAndAssign", - "BitOrAssign", - "BitXorAssign", - "RemAssign", - "ShlAssign", - "ShrAssign", - ], - &[ - hir::BinOpKind::Add, - hir::BinOpKind::Sub, - hir::BinOpKind::Mul, - hir::BinOpKind::Div, - hir::BinOpKind::BitAnd, - hir::BinOpKind::BitOr, - hir::BinOpKind::BitXor, - hir::BinOpKind::Rem, - hir::BinOpKind::Shl, - hir::BinOpKind::Shr, - ], - ) { - span_lint( - cx, - SUSPICIOUS_OP_ASSIGN_IMPL, - binop.span, - &format!("suspicious use of binary operator in `{}` impl", impl_trait), - ); - } - } - } -} - -fn check_binop( - cx: &LateContext<'_>, - expr: &hir::Expr<'_>, - binop: hir::BinOpKind, - traits: &[&'static str], - expected_ops: &[hir::BinOpKind], -) -> Option<&'static str> { - let mut trait_ids = vec![]; - let [krate, module] = crate::utils::paths::OPS_MODULE; - - for &t in traits { - let path = [krate, module, t]; - if let Some(trait_id) = get_trait_def_id(cx, &path) { - trait_ids.push(trait_id); - } else { - return None; - } - } - - // Get the actually implemented trait - let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id); - - if_chain! { - if let Some(trait_ref) = trait_ref_of_method(cx, parent_fn); - if let Some(idx) = trait_ids.iter().position(|&tid| tid == trait_ref.path.res.def_id()); - if binop != expected_ops[idx]; - then{ - return Some(traits[idx]) - } - } - - None -} - -struct BinaryExprVisitor { - nb_binops: u32, -} - -impl<'tcx> Visitor<'tcx> for BinaryExprVisitor { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { - match expr.kind { - hir::ExprKind::Binary(..) - | hir::ExprKind::Unary(hir::UnOp::UnNot | hir::UnOp::UnNeg, _) - | hir::ExprKind::AssignOp(..) => self.nb_binops += 1, - _ => {}, - } - - walk_expr(self, expr); - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs deleted file mode 100644 index 386987eb181e..000000000000 --- a/clippy_lints/src/swap.rs +++ /dev/null @@ -1,263 +0,0 @@ -use crate::utils::sugg::Sugg; -use crate::utils::{ - differing_macro_contexts, eq_expr_value, is_type_diagnostic_item, snippet_with_applicability, span_lint_and_then, -}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{Block, Expr, ExprKind, PatKind, QPath, StmtKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** Checks for manual swapping. - /// - /// **Why is this bad?** The `std::mem::swap` function exposes the intent better - /// without deinitializing or copying either variable. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let mut a = 42; - /// let mut b = 1337; - /// - /// let t = b; - /// b = a; - /// a = t; - /// ``` - /// Use std::mem::swap(): - /// ```rust - /// let mut a = 1; - /// let mut b = 2; - /// std::mem::swap(&mut a, &mut b); - /// ``` - pub MANUAL_SWAP, - complexity, - "manual swap of two variables" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `foo = bar; bar = foo` sequences. - /// - /// **Why is this bad?** This looks like a failed attempt to swap. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # let mut a = 1; - /// # let mut b = 2; - /// a = b; - /// b = a; - /// ``` - /// If swapping is intended, use `swap()` instead: - /// ```rust - /// # let mut a = 1; - /// # let mut b = 2; - /// std::mem::swap(&mut a, &mut b); - /// ``` - pub ALMOST_SWAPPED, - correctness, - "`foo = bar; bar = foo` sequence" -} - -declare_lint_pass!(Swap => [MANUAL_SWAP, ALMOST_SWAPPED]); - -impl<'tcx> LateLintPass<'tcx> for Swap { - fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'_>) { - check_manual_swap(cx, block); - check_suspicious_swap(cx, block); - } -} - -/// Implementation of the `MANUAL_SWAP` lint. -fn check_manual_swap(cx: &LateContext<'_>, block: &Block<'_>) { - for w in block.stmts.windows(3) { - if_chain! { - // let t = foo(); - if let StmtKind::Local(ref tmp) = w[0].kind; - if let Some(ref tmp_init) = tmp.init; - if let PatKind::Binding(.., ident, None) = tmp.pat.kind; - - // foo() = bar(); - if let StmtKind::Semi(ref first) = w[1].kind; - if let ExprKind::Assign(ref lhs1, ref rhs1, _) = first.kind; - - // bar() = t; - if let StmtKind::Semi(ref second) = w[2].kind; - if let ExprKind::Assign(ref lhs2, ref rhs2, _) = second.kind; - if let ExprKind::Path(QPath::Resolved(None, ref rhs2)) = rhs2.kind; - if rhs2.segments.len() == 1; - - if ident.as_str() == rhs2.segments[0].ident.as_str(); - if eq_expr_value(cx, tmp_init, lhs1); - if eq_expr_value(cx, rhs1, lhs2); - then { - if let ExprKind::Field(ref lhs1, _) = lhs1.kind { - if let ExprKind::Field(ref lhs2, _) = lhs2.kind { - if lhs1.hir_id.owner == lhs2.hir_id.owner { - return; - } - } - } - - let mut applicability = Applicability::MachineApplicable; - - let slice = check_for_slice(cx, lhs1, lhs2); - let (replace, what, sugg) = if let Slice::NotSwappable = slice { - return; - } else if let Slice::Swappable(slice, idx1, idx2) = slice { - if let Some(slice) = Sugg::hir_opt(cx, slice) { - ( - false, - format!(" elements of `{}`", slice), - format!( - "{}.swap({}, {})", - slice.maybe_par(), - snippet_with_applicability(cx, idx1.span, "..", &mut applicability), - snippet_with_applicability(cx, idx2.span, "..", &mut applicability), - ), - ) - } else { - (false, String::new(), String::new()) - } - } else if let (Some(first), Some(second)) = (Sugg::hir_opt(cx, lhs1), Sugg::hir_opt(cx, rhs1)) { - ( - true, - format!(" `{}` and `{}`", first, second), - format!("std::mem::swap({}, {})", first.mut_addr(), second.mut_addr()), - ) - } else { - (true, String::new(), String::new()) - }; - - let span = w[0].span.to(second.span); - - span_lint_and_then( - cx, - MANUAL_SWAP, - span, - &format!("this looks like you are swapping{} manually", what), - |diag| { - if !sugg.is_empty() { - diag.span_suggestion( - span, - "try", - sugg, - applicability, - ); - - if replace { - diag.note("or maybe you should use `std::mem::replace`?"); - } - } - } - ); - } - } - } -} - -enum Slice<'a> { - /// `slice.swap(idx1, idx2)` can be used - /// - /// ## Example - /// - /// ```rust - /// # let mut a = vec![0, 1]; - /// let t = a[1]; - /// a[1] = a[0]; - /// a[0] = t; - /// // can be written as - /// a.swap(0, 1); - /// ``` - Swappable(&'a Expr<'a>, &'a Expr<'a>, &'a Expr<'a>), - /// The `swap` function cannot be used. - /// - /// ## Example - /// - /// ```rust - /// # let mut a = [vec![1, 2], vec![3, 4]]; - /// let t = a[0][1]; - /// a[0][1] = a[1][0]; - /// a[1][0] = t; - /// ``` - NotSwappable, - /// Not a slice - None, -} - -/// Checks if both expressions are index operations into "slice-like" types. -fn check_for_slice<'a>(cx: &LateContext<'_>, lhs1: &'a Expr<'_>, lhs2: &'a Expr<'_>) -> Slice<'a> { - if let ExprKind::Index(ref lhs1, ref idx1) = lhs1.kind { - if let ExprKind::Index(ref lhs2, ref idx2) = lhs2.kind { - if eq_expr_value(cx, lhs1, lhs2) { - let ty = cx.typeck_results().expr_ty(lhs1).peel_refs(); - - if matches!(ty.kind(), ty::Slice(_)) - || matches!(ty.kind(), ty::Array(_, _)) - || is_type_diagnostic_item(cx, ty, sym::vec_type) - || is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) - { - return Slice::Swappable(lhs1, idx1, idx2); - } - } else { - return Slice::NotSwappable; - } - } - } - - Slice::None -} - -/// Implementation of the `ALMOST_SWAPPED` lint. -fn check_suspicious_swap(cx: &LateContext<'_>, block: &Block<'_>) { - for w in block.stmts.windows(2) { - if_chain! { - if let StmtKind::Semi(ref first) = w[0].kind; - if let StmtKind::Semi(ref second) = w[1].kind; - if !differing_macro_contexts(first.span, second.span); - if let ExprKind::Assign(ref lhs0, ref rhs0, _) = first.kind; - if let ExprKind::Assign(ref lhs1, ref rhs1, _) = second.kind; - if eq_expr_value(cx, lhs0, rhs1); - if eq_expr_value(cx, lhs1, rhs0); - then { - let lhs0 = Sugg::hir_opt(cx, lhs0); - let rhs0 = Sugg::hir_opt(cx, rhs0); - let (what, lhs, rhs) = if let (Some(first), Some(second)) = (lhs0, rhs0) { - ( - format!(" `{}` and `{}`", first, second), - first.mut_addr().to_string(), - second.mut_addr().to_string(), - ) - } else { - (String::new(), String::new(), String::new()) - }; - - let span = first.span.to(second.span); - - span_lint_and_then(cx, - ALMOST_SWAPPED, - span, - &format!("this looks like you are trying to swap{}", what), - |diag| { - if !what.is_empty() { - diag.span_suggestion( - span, - "try", - format!( - "std::mem::swap({}, {})", - lhs, - rhs, - ), - Applicability::MaybeIncorrect, - ); - diag.note("or maybe you should use `std::mem::replace`?"); - } - }); - } - } - } -} diff --git a/clippy_lints/src/tabs_in_doc_comments.rs b/clippy_lints/src/tabs_in_doc_comments.rs deleted file mode 100644 index 74ccd9235de8..000000000000 --- a/clippy_lints/src/tabs_in_doc_comments.rs +++ /dev/null @@ -1,220 +0,0 @@ -use crate::utils::span_lint_and_sugg; -use rustc_ast::ast; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::{BytePos, Span}; -use std::convert::TryFrom; - -declare_clippy_lint! { - /// **What it does:** Checks doc comments for usage of tab characters. - /// - /// **Why is this bad?** The rust style-guide promotes spaces instead of tabs for indentation. - /// To keep a consistent view on the source, also doc comments should not have tabs. - /// Also, explaining ascii-diagrams containing tabs can get displayed incorrectly when the - /// display settings of the author and reader differ. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// /// - /// /// Struct to hold two strings: - /// /// - first one - /// /// - second one - /// pub struct DoubleString { - /// /// - /// /// - First String: - /// /// - needs to be inside here - /// first_string: String, - /// /// - /// /// - Second String: - /// /// - needs to be inside here - /// second_string: String, - ///} - /// ``` - /// - /// Will be converted to: - /// ```rust - /// /// - /// /// Struct to hold two strings: - /// /// - first one - /// /// - second one - /// pub struct DoubleString { - /// /// - /// /// - First String: - /// /// - needs to be inside here - /// first_string: String, - /// /// - /// /// - Second String: - /// /// - needs to be inside here - /// second_string: String, - ///} - /// ``` - pub TABS_IN_DOC_COMMENTS, - style, - "using tabs in doc comments is not recommended" -} - -declare_lint_pass!(TabsInDocComments => [TABS_IN_DOC_COMMENTS]); - -impl TabsInDocComments { - fn warn_if_tabs_in_doc(cx: &EarlyContext<'_>, attr: &ast::Attribute) { - if let ast::AttrKind::DocComment(_, comment) = attr.kind { - let comment = comment.as_str(); - - for (lo, hi) in get_chunks_of_tabs(&comment) { - // +3 skips the opening delimiter - let new_span = Span::new( - attr.span.lo() + BytePos(3 + lo), - attr.span.lo() + BytePos(3 + hi), - attr.span.ctxt(), - ); - span_lint_and_sugg( - cx, - TABS_IN_DOC_COMMENTS, - new_span, - "using tabs in doc comments is not recommended", - "consider using four spaces per tab", - " ".repeat((hi - lo) as usize), - Applicability::MaybeIncorrect, - ); - } - } - } -} - -impl EarlyLintPass for TabsInDocComments { - fn check_attribute(&mut self, cx: &EarlyContext<'_>, attribute: &ast::Attribute) { - Self::warn_if_tabs_in_doc(cx, &attribute); - } -} - -/// -/// scans the string for groups of tabs and returns the start(inclusive) and end positions -/// (exclusive) of all groups -/// e.g. "sd\tasd\t\taa" will be converted to [(2, 3), (6, 8)] as -/// 012 3456 7 89 -/// ^-^ ^---^ -fn get_chunks_of_tabs(the_str: &str) -> Vec<(u32, u32)> { - let line_length_way_to_long = "doc comment longer than 2^32 chars"; - let mut spans: Vec<(u32, u32)> = vec![]; - let mut current_start: u32 = 0; - - // tracker to decide if the last group of tabs is not closed by a non-tab character - let mut is_active = false; - - let chars_array: Vec<_> = the_str.chars().collect(); - - if chars_array == vec!['\t'] { - return vec![(0, 1)]; - } - - for (index, arr) in chars_array.windows(2).enumerate() { - let index = u32::try_from(index).expect(line_length_way_to_long); - match arr { - ['\t', '\t'] => { - // either string starts with double tab, then we have to set it active, - // otherwise is_active is true anyway - is_active = true; - }, - [_, '\t'] => { - // as ['\t', '\t'] is excluded, this has to be a start of a tab group, - // set indices accordingly - is_active = true; - current_start = index + 1; - }, - ['\t', _] => { - // this now has to be an end of the group, hence we have to push a new tuple - is_active = false; - spans.push((current_start, index + 1)); - }, - _ => {}, - } - } - - // only possible when tabs are at the end, insert last group - if is_active { - spans.push(( - current_start, - u32::try_from(the_str.chars().count()).expect(line_length_way_to_long), - )); - } - - spans -} - -#[cfg(test)] -mod tests_for_get_chunks_of_tabs { - use super::get_chunks_of_tabs; - - #[test] - fn test_empty_string() { - let res = get_chunks_of_tabs(""); - - assert_eq!(res, vec![]); - } - - #[test] - fn test_simple() { - let res = get_chunks_of_tabs("sd\t\t\taa"); - - assert_eq!(res, vec![(2, 5)]); - } - - #[test] - fn test_only_t() { - let res = get_chunks_of_tabs("\t\t"); - - assert_eq!(res, vec![(0, 2)]); - } - - #[test] - fn test_only_one_t() { - let res = get_chunks_of_tabs("\t"); - - assert_eq!(res, vec![(0, 1)]); - } - - #[test] - fn test_double() { - let res = get_chunks_of_tabs("sd\tasd\t\taa"); - - assert_eq!(res, vec![(2, 3), (6, 8)]); - } - - #[test] - fn test_start() { - let res = get_chunks_of_tabs("\t\taa"); - - assert_eq!(res, vec![(0, 2)]); - } - - #[test] - fn test_end() { - let res = get_chunks_of_tabs("aa\t\t"); - - assert_eq!(res, vec![(2, 4)]); - } - - #[test] - fn test_start_single() { - let res = get_chunks_of_tabs("\taa"); - - assert_eq!(res, vec![(0, 1)]); - } - - #[test] - fn test_end_single() { - let res = get_chunks_of_tabs("aa\t"); - - assert_eq!(res, vec![(2, 3)]); - } - - #[test] - fn test_no_tabs() { - let res = get_chunks_of_tabs("dsfs"); - - assert_eq!(res, vec![]); - } -} diff --git a/clippy_lints/src/temporary_assignment.rs b/clippy_lints/src/temporary_assignment.rs deleted file mode 100644 index fb891866364c..000000000000 --- a/clippy_lints/src/temporary_assignment.rs +++ /dev/null @@ -1,42 +0,0 @@ -use crate::utils::{is_adjusted, span_lint}; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for construction of a structure or tuple just to - /// assign a value in it. - /// - /// **Why is this bad?** Readability. If the structure is only created to be - /// updated, why not write the structure you want in the first place? - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// (0, 0).0 = 1 - /// ``` - pub TEMPORARY_ASSIGNMENT, - complexity, - "assignments to temporaries" -} - -fn is_temporary(expr: &Expr<'_>) -> bool { - matches!(&expr.kind, ExprKind::Struct(..) | ExprKind::Tup(..)) -} - -declare_lint_pass!(TemporaryAssignment => [TEMPORARY_ASSIGNMENT]); - -impl<'tcx> LateLintPass<'tcx> for TemporaryAssignment { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Assign(target, ..) = &expr.kind { - let mut base = target; - while let ExprKind::Field(f, _) | ExprKind::Index(f, _) = &base.kind { - base = f; - } - if is_temporary(base) && !is_adjusted(cx, base) { - span_lint(cx, TEMPORARY_ASSIGNMENT, expr.span, "assignment to temporary"); - } - } - } -} diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs deleted file mode 100644 index eeda39bfa208..000000000000 --- a/clippy_lints/src/to_digit_is_some.rs +++ /dev/null @@ -1,94 +0,0 @@ -use crate::utils::{match_def_path, snippet_with_applicability, span_lint_and_sugg}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for `.to_digit(..).is_some()` on `char`s. - /// - /// **Why is this bad?** This is a convoluted way of checking if a `char` is a digit. It's - /// more straight forward to use the dedicated `is_digit` method. - /// - /// **Example:** - /// ```rust - /// # let c = 'c'; - /// # let radix = 10; - /// let is_digit = c.to_digit(radix).is_some(); - /// ``` - /// can be written as: - /// ``` - /// # let c = 'c'; - /// # let radix = 10; - /// let is_digit = c.is_digit(radix); - /// ``` - pub TO_DIGIT_IS_SOME, - style, - "`char.is_digit()` is clearer" -} - -declare_lint_pass!(ToDigitIsSome => [TO_DIGIT_IS_SOME]); - -impl<'tcx> LateLintPass<'tcx> for ToDigitIsSome { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - if_chain! { - if let hir::ExprKind::MethodCall(is_some_path, _, is_some_args, _) = &expr.kind; - if is_some_path.ident.name.as_str() == "is_some"; - if let [to_digit_expr] = &**is_some_args; - then { - let match_result = match &to_digit_expr.kind { - hir::ExprKind::MethodCall(to_digits_path, _, to_digit_args, _) => { - if_chain! { - if let [char_arg, radix_arg] = &**to_digit_args; - if to_digits_path.ident.name.as_str() == "to_digit"; - let char_arg_ty = cx.typeck_results().expr_ty_adjusted(char_arg); - if *char_arg_ty.kind() == ty::Char; - then { - Some((true, char_arg, radix_arg)) - } else { - None - } - } - } - hir::ExprKind::Call(to_digits_call, to_digit_args) => { - if_chain! { - if let [char_arg, radix_arg] = &**to_digit_args; - if let hir::ExprKind::Path(to_digits_path) = &to_digits_call.kind; - if let to_digits_call_res = cx.qpath_res(to_digits_path, to_digits_call.hir_id); - if let Some(to_digits_def_id) = to_digits_call_res.opt_def_id(); - if match_def_path(cx, to_digits_def_id, &["core", "char", "methods", "", "to_digit"]); - then { - Some((false, char_arg, radix_arg)) - } else { - None - } - } - } - _ => None - }; - - if let Some((is_method_call, char_arg, radix_arg)) = match_result { - let mut applicability = Applicability::MachineApplicable; - let char_arg_snip = snippet_with_applicability(cx, char_arg.span, "_", &mut applicability); - let radix_snip = snippet_with_applicability(cx, radix_arg.span, "_", &mut applicability); - - span_lint_and_sugg( - cx, - TO_DIGIT_IS_SOME, - expr.span, - "use of `.to_digit(..).is_some()`", - "try this", - if is_method_call { - format!("{}.is_digit({})", char_arg_snip, radix_snip) - } else { - format!("char::is_digit({}, {})", char_arg_snip, radix_snip) - }, - applicability, - ); - } - } - } - } -} diff --git a/clippy_lints/src/to_string_in_display.rs b/clippy_lints/src/to_string_in_display.rs deleted file mode 100644 index 006d7a3a12d9..000000000000 --- a/clippy_lints/src/to_string_in_display.rs +++ /dev/null @@ -1,122 +0,0 @@ -use crate::utils::{match_def_path, match_trait_method, paths, qpath_res, span_lint}; -use if_chain::if_chain; -use rustc_hir::def::Res; -use rustc_hir::{Expr, ExprKind, HirId, ImplItem, ImplItemKind, Item, ItemKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; - -declare_clippy_lint! { - /// **What it does:** Checks for uses of `to_string()` in `Display` traits. - /// - /// **Why is this bad?** Usually `to_string` is implemented indirectly - /// via `Display`. Hence using it while implementing `Display` would - /// lead to infinite recursion. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// use std::fmt; - /// - /// struct Structure(i32); - /// impl fmt::Display for Structure { - /// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - /// write!(f, "{}", self.to_string()) - /// } - /// } - /// - /// ``` - /// Use instead: - /// ```rust - /// use std::fmt; - /// - /// struct Structure(i32); - /// impl fmt::Display for Structure { - /// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - /// write!(f, "{}", self.0) - /// } - /// } - /// ``` - pub TO_STRING_IN_DISPLAY, - correctness, - "`to_string` method used while implementing `Display` trait" -} - -#[derive(Default)] -pub struct ToStringInDisplay { - in_display_impl: bool, - self_hir_id: Option, -} - -impl ToStringInDisplay { - pub fn new() -> Self { - Self { - in_display_impl: false, - self_hir_id: None, - } - } -} - -impl_lint_pass!(ToStringInDisplay => [TO_STRING_IN_DISPLAY]); - -impl LateLintPass<'_> for ToStringInDisplay { - fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { - if is_display_impl(cx, item) { - self.in_display_impl = true; - } - } - - fn check_item_post(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { - if is_display_impl(cx, item) { - self.in_display_impl = false; - self.self_hir_id = None; - } - } - - fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &ImplItem<'_>) { - if_chain! { - if self.in_display_impl; - if let ImplItemKind::Fn(.., body_id) = &impl_item.kind; - let body = cx.tcx.hir().body(*body_id); - if !body.params.is_empty(); - then { - let self_param = &body.params[0]; - self.self_hir_id = Some(self_param.pat.hir_id); - } - } - } - - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::MethodCall(ref path, _, args, _) = expr.kind; - if path.ident.name == sym!(to_string); - if match_trait_method(cx, expr, &paths::TO_STRING); - if self.in_display_impl; - if let ExprKind::Path(ref qpath) = args[0].kind; - if let Res::Local(hir_id) = qpath_res(cx, qpath, args[0].hir_id); - if let Some(self_hir_id) = self.self_hir_id; - if hir_id == self_hir_id; - then { - span_lint( - cx, - TO_STRING_IN_DISPLAY, - expr.span, - "using `to_string` in `fmt::Display` implementation might lead to infinite recursion", - ); - } - } - } -} - -fn is_display_impl(cx: &LateContext<'_>, item: &Item<'_>) -> bool { - if_chain! { - if let ItemKind::Impl { of_trait: Some(trait_ref), .. } = &item.kind; - if let Some(did) = trait_ref.trait_def_id(); - then { - match_def_path(cx, did, &paths::DISPLAY_TRAIT) - } else { - false - } - } -} diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs deleted file mode 100644 index daff5f81e8c3..000000000000 --- a/clippy_lints/src/trait_bounds.rs +++ /dev/null @@ -1,192 +0,0 @@ -use crate::utils::{in_macro, snippet, snippet_with_applicability, span_lint_and_help, SpanlessHash}; -use if_chain::if_chain; -use rustc_data_structures::fx::FxHashMap; -use rustc_errors::Applicability; -use rustc_hir::{def::Res, GenericBound, Generics, ParamName, Path, QPath, TyKind, WherePredicate}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::Span; - -declare_clippy_lint! { - /// **What it does:** This lint warns about unnecessary type repetitions in trait bounds - /// - /// **Why is this bad?** Repeating the type for every bound makes the code - /// less readable than combining the bounds - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// pub fn foo(t: T) where T: Copy, T: Clone {} - /// ``` - /// - /// Could be written as: - /// - /// ```rust - /// pub fn foo(t: T) where T: Copy + Clone {} - /// ``` - pub TYPE_REPETITION_IN_BOUNDS, - pedantic, - "Types are repeated unnecessary in trait bounds use `+` instead of using `T: _, T: _`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for cases where generics are being used and multiple - /// syntax specifications for trait bounds are used simultaneously. - /// - /// **Why is this bad?** Duplicate bounds makes the code - /// less readable than specifing them only once. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// fn func(arg: T) where T: Clone + Default {} - /// ``` - /// - /// Could be written as: - /// - /// ```rust - /// fn func(arg: T) {} - /// ``` - /// or - /// - /// ```rust - /// fn func(arg: T) where T: Clone + Default {} - /// ``` - pub TRAIT_DUPLICATION_IN_BOUNDS, - pedantic, - "Check if the same trait bounds are specified twice during a function declaration" -} - -#[derive(Copy, Clone)] -pub struct TraitBounds { - max_trait_bounds: u64, -} - -impl TraitBounds { - #[must_use] - pub fn new(max_trait_bounds: u64) -> Self { - Self { max_trait_bounds } - } -} - -impl_lint_pass!(TraitBounds => [TYPE_REPETITION_IN_BOUNDS, TRAIT_DUPLICATION_IN_BOUNDS]); - -impl<'tcx> LateLintPass<'tcx> for TraitBounds { - fn check_generics(&mut self, cx: &LateContext<'tcx>, gen: &'tcx Generics<'_>) { - self.check_type_repetition(cx, gen); - check_trait_bound_duplication(cx, gen); - } -} - -fn get_trait_res_span_from_bound(bound: &GenericBound<'_>) -> Option<(Res, Span)> { - if let GenericBound::Trait(t, _) = bound { - Some((t.trait_ref.path.res, t.span)) - } else { - None - } -} - -impl TraitBounds { - fn check_type_repetition(self, cx: &LateContext<'_>, gen: &'_ Generics<'_>) { - if in_macro(gen.span) { - return; - } - let hash = |ty| -> u64 { - let mut hasher = SpanlessHash::new(cx); - hasher.hash_ty(ty); - hasher.finish() - }; - let mut map = FxHashMap::default(); - let mut applicability = Applicability::MaybeIncorrect; - for bound in gen.where_clause.predicates { - if_chain! { - if let WherePredicate::BoundPredicate(ref p) = bound; - if p.bounds.len() as u64 <= self.max_trait_bounds; - if !in_macro(p.span); - let h = hash(&p.bounded_ty); - if let Some(ref v) = map.insert(h, p.bounds.iter().collect::>()); - - then { - let mut hint_string = format!( - "consider combining the bounds: `{}:", - snippet(cx, p.bounded_ty.span, "_") - ); - for b in v.iter() { - if let GenericBound::Trait(ref poly_trait_ref, _) = b { - let path = &poly_trait_ref.trait_ref.path; - hint_string.push_str(&format!( - " {} +", - snippet_with_applicability(cx, path.span, "..", &mut applicability) - )); - } - } - for b in p.bounds.iter() { - if let GenericBound::Trait(ref poly_trait_ref, _) = b { - let path = &poly_trait_ref.trait_ref.path; - hint_string.push_str(&format!( - " {} +", - snippet_with_applicability(cx, path.span, "..", &mut applicability) - )); - } - } - hint_string.truncate(hint_string.len() - 2); - hint_string.push('`'); - span_lint_and_help( - cx, - TYPE_REPETITION_IN_BOUNDS, - p.span, - "this type has already been used as a bound predicate", - None, - &hint_string, - ); - } - } - } - } -} - -fn check_trait_bound_duplication(cx: &LateContext<'_>, gen: &'_ Generics<'_>) { - if in_macro(gen.span) || gen.params.is_empty() || gen.where_clause.predicates.is_empty() { - return; - } - - let mut map = FxHashMap::default(); - for param in gen.params { - if let ParamName::Plain(ref ident) = param.name { - let res = param - .bounds - .iter() - .filter_map(get_trait_res_span_from_bound) - .collect::>(); - map.insert(*ident, res); - } - } - - for predicate in gen.where_clause.predicates { - if_chain! { - if let WherePredicate::BoundPredicate(ref bound_predicate) = predicate; - if !in_macro(bound_predicate.span); - if let TyKind::Path(QPath::Resolved(_, Path { ref segments, .. })) = bound_predicate.bounded_ty.kind; - if let Some(segment) = segments.first(); - if let Some(trait_resolutions_direct) = map.get(&segment.ident); - then { - for (res_where, _) in bound_predicate.bounds.iter().filter_map(get_trait_res_span_from_bound) { - if let Some((_, span_direct)) = trait_resolutions_direct - .iter() - .find(|(res_direct, _)| *res_direct == res_where) { - span_lint_and_help( - cx, - TRAIT_DUPLICATION_IN_BOUNDS, - *span_direct, - "this trait bound is already specified in the where clause", - None, - "consider removing this trait bound", - ); - } - } - } - } - } -} diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs deleted file mode 100644 index b0909f731774..000000000000 --- a/clippy_lints/src/transmute.rs +++ /dev/null @@ -1,763 +0,0 @@ -use crate::utils::{ - in_constant, is_normalizable, last_path_segment, match_def_path, paths, snippet, span_lint, span_lint_and_sugg, - span_lint_and_then, sugg, -}; -use if_chain::if_chain; -use rustc_ast as ast; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, GenericArg, Mutability, QPath, TyKind, UnOp}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, cast::CastKind, Ty}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::DUMMY_SP; -use rustc_typeck::check::{cast::CastCheck, FnCtxt, Inherited}; -use std::borrow::Cow; - -declare_clippy_lint! { - /// **What it does:** Checks for transmutes that can't ever be correct on any - /// architecture. - /// - /// **Why is this bad?** It's basically guaranteed to be undefined behaviour. - /// - /// **Known problems:** When accessing C, users might want to store pointer - /// sized objects in `extradata` arguments to save an allocation. - /// - /// **Example:** - /// ```ignore - /// let ptr: *const T = core::intrinsics::transmute('x') - /// ``` - pub WRONG_TRANSMUTE, - correctness, - "transmutes that are confusing at best, undefined behaviour at worst and always useless" -} - -// FIXME: Move this to `complexity` again, after #5343 is fixed -declare_clippy_lint! { - /// **What it does:** Checks for transmutes to the original type of the object - /// and transmutes that could be a cast. - /// - /// **Why is this bad?** Readability. The code tricks people into thinking that - /// something complex is going on. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// core::intrinsics::transmute(t); // where the result type is the same as `t`'s - /// ``` - pub USELESS_TRANSMUTE, - nursery, - "transmutes that have the same to and from types or could be a cast/coercion" -} - -// FIXME: Merge this lint with USELESS_TRANSMUTE once that is out of the nursery. -declare_clippy_lint! { - /// **What it does:**Checks for transmutes that could be a pointer cast. - /// - /// **Why is this bad?** Readability. The code tricks people into thinking that - /// something complex is going on. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// # let p: *const [i32] = &[]; - /// unsafe { std::mem::transmute::<*const [i32], *const [u16]>(p) }; - /// ``` - /// Use instead: - /// ```rust - /// # let p: *const [i32] = &[]; - /// p as *const [u16]; - /// ``` - pub TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, - complexity, - "transmutes that could be a pointer cast" -} - -declare_clippy_lint! { - /// **What it does:** Checks for transmutes between a type `T` and `*T`. - /// - /// **Why is this bad?** It's easy to mistakenly transmute between a type and a - /// pointer to that type. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// core::intrinsics::transmute(t) // where the result type is the same as - /// // `*t` or `&t`'s - /// ``` - pub CROSSPOINTER_TRANSMUTE, - complexity, - "transmutes that have to or from types that are a pointer to the other" -} - -declare_clippy_lint! { - /// **What it does:** Checks for transmutes from a pointer to a reference. - /// - /// **Why is this bad?** This can always be rewritten with `&` and `*`. - /// - /// **Known problems:** - /// - `mem::transmute` in statics and constants is stable from Rust 1.46.0, - /// while dereferencing raw pointer is not stable yet. - /// If you need to do this in those places, - /// you would have to use `transmute` instead. - /// - /// **Example:** - /// ```rust,ignore - /// unsafe { - /// let _: &T = std::mem::transmute(p); // where p: *const T - /// } - /// - /// // can be written: - /// let _: &T = &*p; - /// ``` - pub TRANSMUTE_PTR_TO_REF, - complexity, - "transmutes from a pointer to a reference type" -} - -declare_clippy_lint! { - /// **What it does:** Checks for transmutes from an integer to a `char`. - /// - /// **Why is this bad?** Not every integer is a Unicode scalar value. - /// - /// **Known problems:** - /// - [`from_u32`] which this lint suggests using is slower than `transmute` - /// as it needs to validate the input. - /// If you are certain that the input is always a valid Unicode scalar value, - /// use [`from_u32_unchecked`] which is as fast as `transmute` - /// but has a semantically meaningful name. - /// - You might want to handle `None` returned from [`from_u32`] instead of calling `unwrap`. - /// - /// [`from_u32`]: https://doc.rust-lang.org/std/char/fn.from_u32.html - /// [`from_u32_unchecked`]: https://doc.rust-lang.org/std/char/fn.from_u32_unchecked.html - /// - /// **Example:** - /// ```rust - /// let x = 1_u32; - /// unsafe { - /// let _: char = std::mem::transmute(x); // where x: u32 - /// } - /// - /// // should be: - /// let _ = std::char::from_u32(x).unwrap(); - /// ``` - pub TRANSMUTE_INT_TO_CHAR, - complexity, - "transmutes from an integer to a `char`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for transmutes from a `&[u8]` to a `&str`. - /// - /// **Why is this bad?** Not every byte slice is a valid UTF-8 string. - /// - /// **Known problems:** - /// - [`from_utf8`] which this lint suggests using is slower than `transmute` - /// as it needs to validate the input. - /// If you are certain that the input is always a valid UTF-8, - /// use [`from_utf8_unchecked`] which is as fast as `transmute` - /// but has a semantically meaningful name. - /// - You might want to handle errors returned from [`from_utf8`] instead of calling `unwrap`. - /// - /// [`from_utf8`]: https://doc.rust-lang.org/std/str/fn.from_utf8.html - /// [`from_utf8_unchecked`]: https://doc.rust-lang.org/std/str/fn.from_utf8_unchecked.html - /// - /// **Example:** - /// ```rust - /// let b: &[u8] = &[1_u8, 2_u8]; - /// unsafe { - /// let _: &str = std::mem::transmute(b); // where b: &[u8] - /// } - /// - /// // should be: - /// let _ = std::str::from_utf8(b).unwrap(); - /// ``` - pub TRANSMUTE_BYTES_TO_STR, - complexity, - "transmutes from a `&[u8]` to a `&str`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for transmutes from an integer to a `bool`. - /// - /// **Why is this bad?** This might result in an invalid in-memory representation of a `bool`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let x = 1_u8; - /// unsafe { - /// let _: bool = std::mem::transmute(x); // where x: u8 - /// } - /// - /// // should be: - /// let _: bool = x != 0; - /// ``` - pub TRANSMUTE_INT_TO_BOOL, - complexity, - "transmutes from an integer to a `bool`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for transmutes from an integer to a float. - /// - /// **Why is this bad?** Transmutes are dangerous and error-prone, whereas `from_bits` is intuitive - /// and safe. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// unsafe { - /// let _: f32 = std::mem::transmute(1_u32); // where x: u32 - /// } - /// - /// // should be: - /// let _: f32 = f32::from_bits(1_u32); - /// ``` - pub TRANSMUTE_INT_TO_FLOAT, - complexity, - "transmutes from an integer to a float" -} - -declare_clippy_lint! { - /// **What it does:** Checks for transmutes from a float to an integer. - /// - /// **Why is this bad?** Transmutes are dangerous and error-prone, whereas `to_bits` is intuitive - /// and safe. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// unsafe { - /// let _: u32 = std::mem::transmute(1f32); - /// } - /// - /// // should be: - /// let _: u32 = 1f32.to_bits(); - /// ``` - pub TRANSMUTE_FLOAT_TO_INT, - complexity, - "transmutes from a float to an integer" -} - -declare_clippy_lint! { - /// **What it does:** Checks for transmutes from a pointer to a pointer, or - /// from a reference to a reference. - /// - /// **Why is this bad?** Transmutes are dangerous, and these can instead be - /// written as casts. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let ptr = &1u32 as *const u32; - /// unsafe { - /// // pointer-to-pointer transmute - /// let _: *const f32 = std::mem::transmute(ptr); - /// // ref-ref transmute - /// let _: &f32 = std::mem::transmute(&1u32); - /// } - /// // These can be respectively written: - /// let _ = ptr as *const f32; - /// let _ = unsafe{ &*(&1u32 as *const u32 as *const f32) }; - /// ``` - pub TRANSMUTE_PTR_TO_PTR, - complexity, - "transmutes from a pointer to a pointer / a reference to a reference" -} - -declare_clippy_lint! { - /// **What it does:** Checks for transmutes between collections whose - /// types have different ABI, size or alignment. - /// - /// **Why is this bad?** This is undefined behavior. - /// - /// **Known problems:** Currently, we cannot know whether a type is a - /// collection, so we just lint the ones that come with `std`. - /// - /// **Example:** - /// ```rust - /// // different size, therefore likely out-of-bounds memory access - /// // You absolutely do not want this in your code! - /// unsafe { - /// std::mem::transmute::<_, Vec>(vec![2_u16]) - /// }; - /// ``` - /// - /// You must always iterate, map and collect the values: - /// - /// ```rust - /// vec![2_u16].into_iter().map(u32::from).collect::>(); - /// ``` - pub UNSOUND_COLLECTION_TRANSMUTE, - correctness, - "transmute between collections of layout-incompatible types" -} - -declare_lint_pass!(Transmute => [ - CROSSPOINTER_TRANSMUTE, - TRANSMUTE_PTR_TO_REF, - TRANSMUTE_PTR_TO_PTR, - USELESS_TRANSMUTE, - WRONG_TRANSMUTE, - TRANSMUTE_INT_TO_CHAR, - TRANSMUTE_BYTES_TO_STR, - TRANSMUTE_INT_TO_BOOL, - TRANSMUTE_INT_TO_FLOAT, - TRANSMUTE_FLOAT_TO_INT, - UNSOUND_COLLECTION_TRANSMUTE, - TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, -]); - -// used to check for UNSOUND_COLLECTION_TRANSMUTE -static COLLECTIONS: &[&[&str]] = &[ - &paths::VEC, - &paths::VEC_DEQUE, - &paths::BINARY_HEAP, - &paths::BTREESET, - &paths::BTREEMAP, - &paths::HASHSET, - &paths::HASHMAP, -]; -impl<'tcx> LateLintPass<'tcx> for Transmute { - #[allow(clippy::similar_names, clippy::too_many_lines)] - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if_chain! { - if let ExprKind::Call(ref path_expr, ref args) = e.kind; - if let ExprKind::Path(ref qpath) = path_expr.kind; - if let Some(def_id) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id(); - if match_def_path(cx, def_id, &paths::TRANSMUTE); - then { - // Avoid suggesting from/to bits and dereferencing raw pointers in const contexts. - // See https://github.com/rust-lang/rust/issues/73736 for progress on making them `const fn`. - // And see https://github.com/rust-lang/rust/issues/51911 for dereferencing raw pointers. - let const_context = in_constant(cx, e.hir_id); - - let from_ty = cx.typeck_results().expr_ty(&args[0]); - let to_ty = cx.typeck_results().expr_ty(e); - - match (&from_ty.kind(), &to_ty.kind()) { - _ if from_ty == to_ty => span_lint( - cx, - USELESS_TRANSMUTE, - e.span, - &format!("transmute from a type (`{}`) to itself", from_ty), - ), - (ty::Ref(_, rty, rty_mutbl), ty::RawPtr(ptr_ty)) => span_lint_and_then( - cx, - USELESS_TRANSMUTE, - e.span, - "transmute from a reference to a pointer", - |diag| { - if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { - let rty_and_mut = ty::TypeAndMut { - ty: rty, - mutbl: *rty_mutbl, - }; - - let sugg = if *ptr_ty == rty_and_mut { - arg.as_ty(to_ty) - } else { - arg.as_ty(cx.tcx.mk_ptr(rty_and_mut)).as_ty(to_ty) - }; - - diag.span_suggestion(e.span, "try", sugg.to_string(), Applicability::Unspecified); - } - }, - ), - (ty::Int(_) | ty::Uint(_), ty::RawPtr(_)) => span_lint_and_then( - cx, - USELESS_TRANSMUTE, - e.span, - "transmute from an integer to a pointer", - |diag| { - if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { - diag.span_suggestion( - e.span, - "try", - arg.as_ty(&to_ty.to_string()).to_string(), - Applicability::Unspecified, - ); - } - }, - ), - (ty::Float(_) | ty::Char, ty::Ref(..) | ty::RawPtr(_)) => span_lint( - cx, - WRONG_TRANSMUTE, - e.span, - &format!("transmute from a `{}` to a pointer", from_ty), - ), - (ty::RawPtr(from_ptr), _) if from_ptr.ty == to_ty => span_lint( - cx, - CROSSPOINTER_TRANSMUTE, - e.span, - &format!( - "transmute from a type (`{}`) to the type that it points to (`{}`)", - from_ty, to_ty - ), - ), - (_, ty::RawPtr(to_ptr)) if to_ptr.ty == from_ty => span_lint( - cx, - CROSSPOINTER_TRANSMUTE, - e.span, - &format!( - "transmute from a type (`{}`) to a pointer to that type (`{}`)", - from_ty, to_ty - ), - ), - (ty::RawPtr(from_pty), ty::Ref(_, to_ref_ty, mutbl)) => span_lint_and_then( - cx, - TRANSMUTE_PTR_TO_REF, - e.span, - &format!( - "transmute from a pointer type (`{}`) to a reference type \ - (`{}`)", - from_ty, to_ty - ), - |diag| { - let arg = sugg::Sugg::hir(cx, &args[0], ".."); - let (deref, cast) = if *mutbl == Mutability::Mut { - ("&mut *", "*mut") - } else { - ("&*", "*const") - }; - - let arg = if from_pty.ty == *to_ref_ty { - arg - } else { - arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_ref_ty))) - }; - - diag.span_suggestion( - e.span, - "try", - sugg::make_unop(deref, arg).to_string(), - Applicability::Unspecified, - ); - }, - ), - (ty::Int(ast::IntTy::I32) | ty::Uint(ast::UintTy::U32), &ty::Char) => { - span_lint_and_then( - cx, - TRANSMUTE_INT_TO_CHAR, - e.span, - &format!("transmute from a `{}` to a `char`", from_ty), - |diag| { - let arg = sugg::Sugg::hir(cx, &args[0], ".."); - let arg = if let ty::Int(_) = from_ty.kind() { - arg.as_ty(ast::UintTy::U32.name_str()) - } else { - arg - }; - diag.span_suggestion( - e.span, - "consider using", - format!("std::char::from_u32({}).unwrap()", arg.to_string()), - Applicability::Unspecified, - ); - }, - ) - }, - (ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) => { - if_chain! { - if let (&ty::Slice(slice_ty), &ty::Str) = (&ty_from.kind(), &ty_to.kind()); - if let ty::Uint(ast::UintTy::U8) = slice_ty.kind(); - if from_mutbl == to_mutbl; - then { - let postfix = if *from_mutbl == Mutability::Mut { - "_mut" - } else { - "" - }; - - span_lint_and_sugg( - cx, - TRANSMUTE_BYTES_TO_STR, - e.span, - &format!("transmute from a `{}` to a `{}`", from_ty, to_ty), - "consider using", - format!( - "std::str::from_utf8{}({}).unwrap()", - postfix, - snippet(cx, args[0].span, ".."), - ), - Applicability::Unspecified, - ); - } else { - if (cx.tcx.erase_regions(from_ty) != cx.tcx.erase_regions(to_ty)) - && !const_context { - span_lint_and_then( - cx, - TRANSMUTE_PTR_TO_PTR, - e.span, - "transmute from a reference to a reference", - |diag| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { - let ty_from_and_mut = ty::TypeAndMut { - ty: ty_from, - mutbl: *from_mutbl - }; - let ty_to_and_mut = ty::TypeAndMut { ty: ty_to, mutbl: *to_mutbl }; - let sugg_paren = arg - .as_ty(cx.tcx.mk_ptr(ty_from_and_mut)) - .as_ty(cx.tcx.mk_ptr(ty_to_and_mut)); - let sugg = if *to_mutbl == Mutability::Mut { - sugg_paren.mut_addr_deref() - } else { - sugg_paren.addr_deref() - }; - diag.span_suggestion( - e.span, - "try", - sugg.to_string(), - Applicability::Unspecified, - ); - }, - ) - } - } - } - }, - (ty::RawPtr(_), ty::RawPtr(to_ty)) => span_lint_and_then( - cx, - TRANSMUTE_PTR_TO_PTR, - e.span, - "transmute from a pointer to a pointer", - |diag| { - if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { - let sugg = arg.as_ty(cx.tcx.mk_ptr(*to_ty)); - diag.span_suggestion(e.span, "try", sugg.to_string(), Applicability::Unspecified); - } - }, - ), - (ty::Int(ast::IntTy::I8) | ty::Uint(ast::UintTy::U8), ty::Bool) => { - span_lint_and_then( - cx, - TRANSMUTE_INT_TO_BOOL, - e.span, - &format!("transmute from a `{}` to a `bool`", from_ty), - |diag| { - let arg = sugg::Sugg::hir(cx, &args[0], ".."); - let zero = sugg::Sugg::NonParen(Cow::from("0")); - diag.span_suggestion( - e.span, - "consider using", - sugg::make_binop(ast::BinOpKind::Ne, &arg, &zero).to_string(), - Applicability::Unspecified, - ); - }, - ) - }, - (ty::Int(_) | ty::Uint(_), ty::Float(_)) if !const_context => span_lint_and_then( - cx, - TRANSMUTE_INT_TO_FLOAT, - e.span, - &format!("transmute from a `{}` to a `{}`", from_ty, to_ty), - |diag| { - let arg = sugg::Sugg::hir(cx, &args[0], ".."); - let arg = if let ty::Int(int_ty) = from_ty.kind() { - arg.as_ty(format!( - "u{}", - int_ty.bit_width().map_or_else(|| "size".to_string(), |v| v.to_string()) - )) - } else { - arg - }; - diag.span_suggestion( - e.span, - "consider using", - format!("{}::from_bits({})", to_ty, arg.to_string()), - Applicability::Unspecified, - ); - }, - ), - (ty::Float(float_ty), ty::Int(_) | ty::Uint(_)) if !const_context => span_lint_and_then( - cx, - TRANSMUTE_FLOAT_TO_INT, - e.span, - &format!("transmute from a `{}` to a `{}`", from_ty, to_ty), - |diag| { - let mut expr = &args[0]; - let mut arg = sugg::Sugg::hir(cx, expr, ".."); - - if let ExprKind::Unary(UnOp::UnNeg, inner_expr) = &expr.kind { - expr = &inner_expr; - } - - if_chain! { - // if the expression is a float literal and it is unsuffixed then - // add a suffix so the suggestion is valid and unambiguous - let op = format!("{}{}", arg, float_ty.name_str()).into(); - if let ExprKind::Lit(lit) = &expr.kind; - if let ast::LitKind::Float(_, ast::LitFloatType::Unsuffixed) = lit.node; - then { - match arg { - sugg::Sugg::MaybeParen(_) => arg = sugg::Sugg::MaybeParen(op), - _ => arg = sugg::Sugg::NonParen(op) - } - } - } - - arg = sugg::Sugg::NonParen(format!("{}.to_bits()", arg.maybe_par()).into()); - - // cast the result of `to_bits` if `to_ty` is signed - arg = if let ty::Int(int_ty) = to_ty.kind() { - arg.as_ty(int_ty.name_str().to_string()) - } else { - arg - }; - - diag.span_suggestion( - e.span, - "consider using", - arg.to_string(), - Applicability::Unspecified, - ); - }, - ), - (ty::Adt(from_adt, from_substs), ty::Adt(to_adt, to_substs)) => { - if from_adt.did != to_adt.did || - !COLLECTIONS.iter().any(|path| match_def_path(cx, to_adt.did, path)) { - return; - } - if from_substs.types().zip(to_substs.types()) - .any(|(from_ty, to_ty)| is_layout_incompatible(cx, from_ty, to_ty)) { - span_lint( - cx, - UNSOUND_COLLECTION_TRANSMUTE, - e.span, - &format!( - "transmute from `{}` to `{}` with mismatched layout is unsound", - from_ty, - to_ty - ) - ); - } - }, - (_, _) if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) => span_lint_and_then( - cx, - TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS, - e.span, - &format!( - "transmute from `{}` to `{}` which could be expressed as a pointer cast instead", - from_ty, - to_ty - ), - |diag| { - if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { - let sugg = arg.as_ty(&to_ty.to_string()).to_string(); - diag.span_suggestion(e.span, "try", sugg, Applicability::MachineApplicable); - } - } - ), - _ => { - return; - }, - } - } - } - } -} - -/// Gets the snippet of `Bar` in `…::transmute`. If that snippet is -/// not available , use -/// the type's `ToString` implementation. In weird cases it could lead to types -/// with invalid `'_` -/// lifetime, but it should be rare. -fn get_type_snippet(cx: &LateContext<'_>, path: &QPath<'_>, to_ref_ty: Ty<'_>) -> String { - let seg = last_path_segment(path); - if_chain! { - if let Some(ref params) = seg.args; - if !params.parenthesized; - if let Some(to_ty) = params.args.iter().filter_map(|arg| match arg { - GenericArg::Type(ty) => Some(ty), - _ => None, - }).nth(1); - if let TyKind::Rptr(_, ref to_ty) = to_ty.kind; - then { - return snippet(cx, to_ty.ty.span, &to_ref_ty.to_string()).to_string(); - } - } - - to_ref_ty.to_string() -} - -// check if the component types of the transmuted collection and the result have different ABI, -// size or alignment -fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<'tcx>) -> bool { - let empty_param_env = ty::ParamEnv::empty(); - // check if `from` and `to` are normalizable to avoid ICE (#4968) - if !(is_normalizable(cx, empty_param_env, from) && is_normalizable(cx, empty_param_env, to)) { - return false; - } - let from_ty_layout = cx.tcx.layout_of(empty_param_env.and(from)); - let to_ty_layout = cx.tcx.layout_of(empty_param_env.and(to)); - if let (Ok(from_layout), Ok(to_layout)) = (from_ty_layout, to_ty_layout) { - from_layout.size != to_layout.size || from_layout.align != to_layout.align || from_layout.abi != to_layout.abi - } else { - // no idea about layout, so don't lint - false - } -} - -/// Check if the type conversion can be expressed as a pointer cast, instead of -/// a transmute. In certain cases, including some invalid casts from array -/// references to pointers, this may cause additional errors to be emitted and/or -/// ICE error messages. This function will panic if that occurs. -fn can_be_expressed_as_pointer_cast<'tcx>( - cx: &LateContext<'tcx>, - e: &'tcx Expr<'_>, - from_ty: Ty<'tcx>, - to_ty: Ty<'tcx>, -) -> bool { - use CastKind::{AddrPtrCast, ArrayPtrCast, FnPtrAddrCast, FnPtrPtrCast, PtrAddrCast, PtrPtrCast}; - matches!( - check_cast(cx, e, from_ty, to_ty), - Some(PtrPtrCast | PtrAddrCast | AddrPtrCast | ArrayPtrCast | FnPtrPtrCast | FnPtrAddrCast) - ) -} - -/// If a cast from `from_ty` to `to_ty` is valid, returns an Ok containing the kind of -/// the cast. In certain cases, including some invalid casts from array references -/// to pointers, this may cause additional errors to be emitted and/or ICE error -/// messages. This function will panic if that occurs. -fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> Option { - let hir_id = e.hir_id; - let local_def_id = hir_id.owner; - - Inherited::build(cx.tcx, local_def_id).enter(|inherited| { - let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, hir_id); - - // If we already have errors, we can't be sure we can pointer cast. - assert!( - !fn_ctxt.errors_reported_since_creation(), - "Newly created FnCtxt contained errors" - ); - - if let Ok(check) = CastCheck::new( - &fn_ctxt, e, from_ty, to_ty, - // We won't show any error to the user, so we don't care what the span is here. - DUMMY_SP, DUMMY_SP, - ) { - let res = check.do_check(&fn_ctxt); - - // do_check's documentation says that it might return Ok and create - // errors in the fcx instead of returing Err in some cases. Those cases - // should be filtered out before getting here. - assert!( - !fn_ctxt.errors_reported_since_creation(), - "`fn_ctxt` contained errors after cast check!" - ); - - res.ok() - } else { - None - } - }) -} diff --git a/clippy_lints/src/transmuting_null.rs b/clippy_lints/src/transmuting_null.rs deleted file mode 100644 index 6b171a0fa1af..000000000000 --- a/clippy_lints/src/transmuting_null.rs +++ /dev/null @@ -1,88 +0,0 @@ -use crate::consts::{constant_context, Constant}; -use crate::utils::{match_qpath, paths, span_lint}; -use if_chain::if_chain; -use rustc_ast::LitKind; -use rustc_hir::{Expr, ExprKind}; -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! { - /// **What it does:** Checks for transmute calls which would receive a null pointer. - /// - /// **Why is this bad?** Transmuting a null pointer is undefined behavior. - /// - /// **Known problems:** Not all cases can be detected at the moment of this writing. - /// For example, variables which hold a null pointer and are then fed to a `transmute` - /// call, aren't detectable yet. - /// - /// **Example:** - /// ```rust - /// let null_ref: &u64 = unsafe { std::mem::transmute(0 as *const u64) }; - /// ``` - pub TRANSMUTING_NULL, - correctness, - "transmutes from a null pointer to a reference, which is undefined behavior" -} - -declare_lint_pass!(TransmutingNull => [TRANSMUTING_NULL]); - -const LINT_MSG: &str = "transmuting a known null pointer into a reference."; - -impl<'tcx> LateLintPass<'tcx> for TransmutingNull { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if in_external_macro(cx.sess(), expr.span) { - return; - } - - if_chain! { - if let ExprKind::Call(ref func, ref args) = expr.kind; - if let ExprKind::Path(ref path) = func.kind; - if match_qpath(path, &paths::STD_MEM_TRANSMUTE); - if args.len() == 1; - - then { - - // Catching transmute over constants that resolve to `null`. - let mut const_eval_context = constant_context(cx, cx.typeck_results()); - if_chain! { - if let ExprKind::Path(ref _qpath) = args[0].kind; - let x = const_eval_context.expr(&args[0]); - if let Some(Constant::RawPtr(0)) = x; - then { - span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG) - } - } - - // Catching: - // `std::mem::transmute(0 as *const i32)` - if_chain! { - if let ExprKind::Cast(ref inner_expr, ref _cast_ty) = args[0].kind; - if let ExprKind::Lit(ref lit) = inner_expr.kind; - if let LitKind::Int(0, _) = lit.node; - then { - span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG) - } - } - - // Catching: - // `std::mem::transmute(std::ptr::null::())` - if_chain! { - if let ExprKind::Call(ref func1, ref args1) = args[0].kind; - if let ExprKind::Path(ref path1) = func1.kind; - if match_qpath(path1, &paths::STD_PTR_NULL); - if args1.is_empty(); - then { - span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG) - } - } - - // FIXME: - // Also catch transmutations of variables which are known nulls. - // To do this, MIR const propagation seems to be the better tool. - // Whenever MIR const prop routines are more developed, this will - // become available. As of this writing (25/03/19) it is not yet. - } - } - } -} diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs deleted file mode 100644 index 73e3a04aec98..000000000000 --- a/clippy_lints/src/try_err.rs +++ /dev/null @@ -1,190 +0,0 @@ -use crate::utils::{ - differing_macro_contexts, in_macro, is_type_diagnostic_item, match_def_path, match_qpath, paths, snippet, - snippet_with_macro_callsite, span_lint_and_sugg, -}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, LangItem, MatchSource, QPath}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, Ty}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** Checks for usages of `Err(x)?`. - /// - /// **Why is this bad?** The `?` operator is designed to allow calls that - /// can fail to be easily chained. For example, `foo()?.bar()` or - /// `foo(bar()?)`. Because `Err(x)?` can't be used that way (it will - /// always return), it is more clear to write `return Err(x)`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// fn foo(fail: bool) -> Result { - /// if fail { - /// Err("failed")?; - /// } - /// Ok(0) - /// } - /// ``` - /// Could be written: - /// - /// ```rust - /// fn foo(fail: bool) -> Result { - /// if fail { - /// return Err("failed".into()); - /// } - /// Ok(0) - /// } - /// ``` - pub TRY_ERR, - style, - "return errors explicitly rather than hiding them behind a `?`" -} - -declare_lint_pass!(TryErr => [TRY_ERR]); - -impl<'tcx> LateLintPass<'tcx> for TryErr { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - // Looks for a structure like this: - // match ::std::ops::Try::into_result(Err(5)) { - // ::std::result::Result::Err(err) => - // #[allow(unreachable_code)] - // return ::std::ops::Try::from_error(::std::convert::From::from(err)), - // ::std::result::Result::Ok(val) => - // #[allow(unreachable_code)] - // val, - // }; - if_chain! { - if !in_external_macro(cx.tcx.sess, expr.span); - if let ExprKind::Match(ref match_arg, _, MatchSource::TryDesugar) = expr.kind; - if let ExprKind::Call(ref match_fun, ref try_args) = match_arg.kind; - if let ExprKind::Path(ref match_fun_path) = match_fun.kind; - if matches!(match_fun_path, QPath::LangItem(LangItem::TryIntoResult, _)); - if let Some(ref try_arg) = try_args.get(0); - if let ExprKind::Call(ref err_fun, ref err_args) = try_arg.kind; - if let Some(ref err_arg) = err_args.get(0); - if let ExprKind::Path(ref err_fun_path) = err_fun.kind; - if match_qpath(err_fun_path, &paths::RESULT_ERR); - if let Some(return_ty) = find_return_type(cx, &expr.kind); - then { - let prefix; - let suffix; - let err_ty; - - if let Some(ty) = result_error_type(cx, return_ty) { - prefix = "Err("; - suffix = ")"; - err_ty = ty; - } else if let Some(ty) = poll_result_error_type(cx, return_ty) { - prefix = "Poll::Ready(Err("; - suffix = "))"; - err_ty = ty; - } else if let Some(ty) = poll_option_result_error_type(cx, return_ty) { - prefix = "Poll::Ready(Some(Err("; - suffix = ")))"; - err_ty = ty; - } else { - return; - }; - - let expr_err_ty = cx.typeck_results().expr_ty(err_arg); - let differing_contexts = differing_macro_contexts(expr.span, err_arg.span); - - let origin_snippet = if in_macro(expr.span) && in_macro(err_arg.span) && differing_contexts { - snippet(cx, err_arg.span.ctxt().outer_expn_data().call_site, "_") - } else if err_arg.span.from_expansion() && !in_macro(expr.span) { - snippet_with_macro_callsite(cx, err_arg.span, "_") - } else { - snippet(cx, err_arg.span, "_") - }; - let suggestion = if err_ty == expr_err_ty { - format!("return {}{}{}", prefix, origin_snippet, suffix) - } else { - format!("return {}{}.into(){}", prefix, origin_snippet, suffix) - }; - - span_lint_and_sugg( - cx, - TRY_ERR, - expr.span, - "returning an `Err(_)` with the `?` operator", - "try this", - suggestion, - Applicability::MachineApplicable - ); - } - } - } -} - -/// Finds function return type by examining return expressions in match arms. -fn find_return_type<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx ExprKind<'_>) -> Option> { - if let ExprKind::Match(_, ref arms, MatchSource::TryDesugar) = expr { - for arm in arms.iter() { - if let ExprKind::Ret(Some(ref ret)) = arm.body.kind { - return Some(cx.typeck_results().expr_ty(ret)); - } - } - } - None -} - -/// Extracts the error type from Result. -fn result_error_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option> { - if_chain! { - if let ty::Adt(_, subst) = ty.kind(); - if is_type_diagnostic_item(cx, ty, sym::result_type); - let err_ty = subst.type_at(1); - then { - Some(err_ty) - } else { - None - } - } -} - -/// Extracts the error type from Poll>. -fn poll_result_error_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option> { - if_chain! { - if let ty::Adt(def, subst) = ty.kind(); - if match_def_path(cx, def.did, &paths::POLL); - let ready_ty = subst.type_at(0); - - if let ty::Adt(ready_def, ready_subst) = ready_ty.kind(); - if cx.tcx.is_diagnostic_item(sym::result_type, ready_def.did); - let err_ty = ready_subst.type_at(1); - - then { - Some(err_ty) - } else { - None - } - } -} - -/// Extracts the error type from Poll>>. -fn poll_option_result_error_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option> { - if_chain! { - if let ty::Adt(def, subst) = ty.kind(); - if match_def_path(cx, def.did, &paths::POLL); - let ready_ty = subst.type_at(0); - - if let ty::Adt(ready_def, ready_subst) = ready_ty.kind(); - if cx.tcx.is_diagnostic_item(sym::option_type, ready_def.did); - let some_ty = ready_subst.type_at(0); - - if let ty::Adt(some_def, some_subst) = some_ty.kind(); - if cx.tcx.is_diagnostic_item(sym::result_type, some_def.did); - let err_ty = some_subst.type_at(1); - - then { - Some(err_ty) - } else { - None - } - } -} diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs deleted file mode 100644 index fd74783335d5..000000000000 --- a/clippy_lints/src/types.rs +++ /dev/null @@ -1,2880 +0,0 @@ -#![allow(rustc::default_hash_types)] - -use std::borrow::Cow; -use std::cmp::Ordering; -use std::collections::BTreeMap; - -use if_chain::if_chain; -use rustc_ast::{FloatTy, IntTy, LitFloatType, LitIntType, LitKind, UintTy}; -use rustc_errors::{Applicability, DiagnosticBuilder}; -use rustc_hir as hir; -use rustc_hir::def::Res; -use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, FnKind, NestedVisitorMap, Visitor}; -use rustc_hir::{ - BinOpKind, Block, Body, Expr, ExprKind, FnDecl, FnRetTy, FnSig, GenericArg, GenericBounds, GenericParamKind, HirId, - ImplItem, ImplItemKind, Item, ItemKind, Lifetime, Lit, Local, MatchSource, MutTy, Mutability, Node, QPath, Stmt, - StmtKind, SyntheticTyParamKind, TraitFn, TraitItem, TraitItemKind, TyKind, UnOp, -}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::TypeFoldable; -use rustc_middle::ty::{self, InferTy, Ty, TyCtxt, TyS, TypeckResults}; -use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass}; -use rustc_span::hygiene::{ExpnKind, MacroKind}; -use rustc_span::source_map::Span; -use rustc_span::symbol::sym; -use rustc_target::abi::LayoutOf; -use rustc_target::spec::abi::Abi; -use rustc_typeck::hir_ty_to_ty; - -use crate::consts::{constant, Constant}; -use crate::utils::paths; -use crate::utils::{ - clip, comparisons, differing_macro_contexts, higher, in_constant, indent_of, int_bits, is_type_diagnostic_item, - last_path_segment, match_def_path, match_path, method_chain_args, multispan_sugg, numeric_literal::NumericLiteral, - qpath_res, reindent_multiline, sext, snippet, snippet_opt, snippet_with_applicability, snippet_with_macro_callsite, - span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then, unsext, -}; - -declare_clippy_lint! { - /// **What it does:** Checks for use of `Box>` anywhere in the code. - /// Check the [Box documentation](https://doc.rust-lang.org/std/boxed/index.html) for more information. - /// - /// **Why is this bad?** `Vec` already keeps its contents in a separate area on - /// the heap. So if you `Box` it, you just add another level of indirection - /// without any benefit whatsoever. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// struct X { - /// values: Box>, - /// } - /// ``` - /// - /// Better: - /// - /// ```rust,ignore - /// struct X { - /// values: Vec, - /// } - /// ``` - pub BOX_VEC, - perf, - "usage of `Box>`, vector elements are already on the heap" -} - -declare_clippy_lint! { - /// **What it does:** Checks for use of `Vec>` where T: Sized anywhere in the code. - /// Check the [Box documentation](https://doc.rust-lang.org/std/boxed/index.html) for more information. - /// - /// **Why is this bad?** `Vec` already keeps its contents in a separate area on - /// the heap. So if you `Box` its contents, you just add another level of indirection. - /// - /// **Known problems:** Vec> makes sense if T is a large type (see #3530, - /// 1st comment). - /// - /// **Example:** - /// ```rust - /// struct X { - /// values: Vec>, - /// } - /// ``` - /// - /// Better: - /// - /// ```rust - /// struct X { - /// values: Vec, - /// } - /// ``` - pub VEC_BOX, - complexity, - "usage of `Vec>` where T: Sized, vector elements are already on the heap" -} - -declare_clippy_lint! { - /// **What it does:** Checks for use of `Option>` in function signatures and type - /// definitions - /// - /// **Why is this bad?** `Option<_>` represents an optional value. `Option>` - /// represents an optional optional value which is logically the same thing as an optional - /// value but has an unneeded extra level of wrapping. - /// - /// If you have a case where `Some(Some(_))`, `Some(None)` and `None` are distinct cases, - /// consider a custom `enum` instead, with clear names for each case. - /// - /// **Known problems:** None. - /// - /// **Example** - /// ```rust - /// fn get_data() -> Option> { - /// None - /// } - /// ``` - /// - /// Better: - /// - /// ```rust - /// pub enum Contents { - /// Data(Vec), // Was Some(Some(Vec)) - /// NotYetFetched, // Was Some(None) - /// None, // Was None - /// } - /// - /// fn get_data() -> Contents { - /// Contents::None - /// } - /// ``` - pub OPTION_OPTION, - pedantic, - "usage of `Option>`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for usage of any `LinkedList`, suggesting to use a - /// `Vec` or a `VecDeque` (formerly called `RingBuf`). - /// - /// **Why is this bad?** Gankro says: - /// - /// > The TL;DR of `LinkedList` is that it's built on a massive amount of - /// pointers and indirection. - /// > It wastes memory, it has terrible cache locality, and is all-around slow. - /// `RingBuf`, while - /// > "only" amortized for push/pop, should be faster in the general case for - /// almost every possible - /// > workload, and isn't even amortized at all if you can predict the capacity - /// you need. - /// > - /// > `LinkedList`s are only really good if you're doing a lot of merging or - /// splitting of lists. - /// > This is because they can just mangle some pointers instead of actually - /// copying the data. Even - /// > if you're doing a lot of insertion in the middle of the list, `RingBuf` - /// can still be better - /// > because of how expensive it is to seek to the middle of a `LinkedList`. - /// - /// **Known problems:** False positives – the instances where using a - /// `LinkedList` makes sense are few and far between, but they can still happen. - /// - /// **Example:** - /// ```rust - /// # use std::collections::LinkedList; - /// let x: LinkedList = LinkedList::new(); - /// ``` - pub LINKEDLIST, - pedantic, - "usage of LinkedList, usually a vector is faster, or a more specialized data structure like a `VecDeque`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for use of `&Box` anywhere in the code. - /// Check the [Box documentation](https://doc.rust-lang.org/std/boxed/index.html) for more information. - /// - /// **Why is this bad?** Any `&Box` can also be a `&T`, which is more - /// general. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// fn foo(bar: &Box) { ... } - /// ``` - /// - /// Better: - /// - /// ```rust,ignore - /// fn foo(bar: &T) { ... } - /// ``` - pub BORROWED_BOX, - complexity, - "a borrow of a boxed type" -} - -declare_clippy_lint! { - /// **What it does:** Checks for use of redundant allocations anywhere in the code. - /// - /// **Why is this bad?** Expressions such as `Rc<&T>`, `Rc>`, `Rc>`, `Box<&T>` - /// add an unnecessary level of indirection. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # use std::rc::Rc; - /// fn foo(bar: Rc<&usize>) {} - /// ``` - /// - /// Better: - /// - /// ```rust - /// fn foo(bar: &usize) {} - /// ``` - pub REDUNDANT_ALLOCATION, - perf, - "redundant allocation" -} - -declare_clippy_lint! { - /// **What it does:** Checks for `Rc` and `Arc` when `T` is a mutable buffer type such as `String` or `Vec`. - /// - /// **Why is this bad?** Expressions such as `Rc` usually have no advantage over `Rc`, since - /// it is larger and involves an extra level of indirection, and doesn't implement `Borrow`. - /// - /// While mutating a buffer type would still be possible with `Rc::get_mut()`, it only - /// works if there are no additional references yet, which usually defeats the purpose of - /// enclosing it in a shared ownership type. Instead, additionally wrapping the inner - /// type with an interior mutable container (such as `RefCell` or `Mutex`) would normally - /// be used. - /// - /// **Known problems:** This pattern can be desirable to avoid the overhead of a `RefCell` or `Mutex` for - /// cases where mutation only happens before there are any additional references. - /// - /// **Example:** - /// ```rust,ignore - /// # use std::rc::Rc; - /// fn foo(interned: Rc) { ... } - /// ``` - /// - /// Better: - /// - /// ```rust,ignore - /// fn foo(interned: Rc) { ... } - /// ``` - pub RC_BUFFER, - restriction, - "shared ownership of a buffer type" -} - -pub struct Types { - vec_box_size_threshold: u64, -} - -impl_lint_pass!(Types => [BOX_VEC, VEC_BOX, OPTION_OPTION, LINKEDLIST, BORROWED_BOX, REDUNDANT_ALLOCATION, RC_BUFFER]); - -impl<'tcx> LateLintPass<'tcx> for Types { - fn check_fn(&mut self, cx: &LateContext<'_>, _: FnKind<'_>, decl: &FnDecl<'_>, _: &Body<'_>, _: Span, id: HirId) { - // Skip trait implementations; see issue #605. - if let Some(hir::Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_item(id)) { - if let ItemKind::Impl { of_trait: Some(_), .. } = item.kind { - return; - } - } - - self.check_fn_decl(cx, decl); - } - - fn check_struct_field(&mut self, cx: &LateContext<'_>, field: &hir::StructField<'_>) { - self.check_ty(cx, &field.ty, false); - } - - fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &TraitItem<'_>) { - match item.kind { - TraitItemKind::Const(ref ty, _) | TraitItemKind::Type(_, Some(ref ty)) => self.check_ty(cx, ty, false), - TraitItemKind::Fn(ref sig, _) => self.check_fn_decl(cx, &sig.decl), - _ => (), - } - } - - fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) { - if let Some(ref ty) = local.ty { - self.check_ty(cx, ty, true); - } - } -} - -/// Checks if `qpath` has last segment with type parameter matching `path` -fn match_type_parameter(cx: &LateContext<'_>, qpath: &QPath<'_>, path: &[&str]) -> Option { - let last = last_path_segment(qpath); - if_chain! { - if let Some(ref params) = last.args; - if !params.parenthesized; - if let Some(ty) = params.args.iter().find_map(|arg| match arg { - GenericArg::Type(ty) => Some(ty), - _ => None, - }); - if let TyKind::Path(ref qpath) = ty.kind; - if let Some(did) = qpath_res(cx, qpath, ty.hir_id).opt_def_id(); - if match_def_path(cx, did, path); - then { - return Some(ty.span); - } - } - None -} - -fn match_buffer_type(cx: &LateContext<'_>, qpath: &QPath<'_>) -> Option<&'static str> { - if match_type_parameter(cx, qpath, &paths::STRING).is_some() { - return Some("str"); - } - if match_type_parameter(cx, qpath, &paths::OS_STRING).is_some() { - return Some("std::ffi::OsStr"); - } - if match_type_parameter(cx, qpath, &paths::PATH_BUF).is_some() { - return Some("std::path::Path"); - } - None -} - -fn match_borrows_parameter(_cx: &LateContext<'_>, qpath: &QPath<'_>) -> Option { - let last = last_path_segment(qpath); - if_chain! { - if let Some(ref params) = last.args; - if !params.parenthesized; - if let Some(ty) = params.args.iter().find_map(|arg| match arg { - GenericArg::Type(ty) => Some(ty), - _ => None, - }); - if let TyKind::Rptr(..) = ty.kind; - then { - return Some(ty.span); - } - } - None -} - -impl Types { - pub fn new(vec_box_size_threshold: u64) -> Self { - Self { vec_box_size_threshold } - } - - fn check_fn_decl(&mut self, cx: &LateContext<'_>, decl: &FnDecl<'_>) { - for input in decl.inputs { - self.check_ty(cx, input, false); - } - - if let FnRetTy::Return(ref ty) = decl.output { - self.check_ty(cx, ty, false); - } - } - - /// Recursively check for `TypePass` lints in the given type. Stop at the first - /// lint found. - /// - /// The parameter `is_local` distinguishes the context of the type; types from - /// local bindings should only be checked for the `BORROWED_BOX` lint. - #[allow(clippy::too_many_lines)] - fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, is_local: bool) { - if hir_ty.span.from_expansion() { - return; - } - match hir_ty.kind { - TyKind::Path(ref qpath) if !is_local => { - let hir_id = hir_ty.hir_id; - let res = qpath_res(cx, qpath, hir_id); - if let Some(def_id) = res.opt_def_id() { - if Some(def_id) == cx.tcx.lang_items().owned_box() { - if let Some(span) = match_borrows_parameter(cx, qpath) { - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - REDUNDANT_ALLOCATION, - hir_ty.span, - "usage of `Box<&T>`", - "try", - snippet_with_applicability(cx, span, "..", &mut applicability).to_string(), - applicability, - ); - return; // don't recurse into the type - } - if match_type_parameter(cx, qpath, &paths::VEC).is_some() { - span_lint_and_help( - cx, - BOX_VEC, - hir_ty.span, - "you seem to be trying to use `Box>`. Consider using just `Vec`", - None, - "`Vec` is already on the heap, `Box>` makes an extra allocation.", - ); - return; // don't recurse into the type - } - } else if cx.tcx.is_diagnostic_item(sym::Rc, def_id) { - if let Some(span) = match_type_parameter(cx, qpath, &paths::RC) { - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - REDUNDANT_ALLOCATION, - hir_ty.span, - "usage of `Rc>`", - "try", - snippet_with_applicability(cx, span, "..", &mut applicability).to_string(), - applicability, - ); - return; // don't recurse into the type - } - if match_type_parameter(cx, qpath, &paths::BOX).is_some() { - let box_ty = match &last_path_segment(qpath).args.unwrap().args[0] { - GenericArg::Type(ty) => match &ty.kind { - TyKind::Path(qpath) => qpath, - _ => return, - }, - _ => return, - }; - let inner_span = match &last_path_segment(&box_ty).args.unwrap().args[0] { - GenericArg::Type(ty) => ty.span, - _ => return, - }; - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - REDUNDANT_ALLOCATION, - hir_ty.span, - "usage of `Rc>`", - "try", - format!( - "Rc<{}>", - snippet_with_applicability(cx, inner_span, "..", &mut applicability) - ), - applicability, - ); - return; // don't recurse into the type - } - if let Some(alternate) = match_buffer_type(cx, qpath) { - span_lint_and_sugg( - cx, - RC_BUFFER, - hir_ty.span, - "usage of `Rc` when T is a buffer type", - "try", - format!("Rc<{}>", alternate), - Applicability::MachineApplicable, - ); - return; // don't recurse into the type - } - if match_type_parameter(cx, qpath, &paths::VEC).is_some() { - let vec_ty = match &last_path_segment(qpath).args.unwrap().args[0] { - GenericArg::Type(ty) => match &ty.kind { - TyKind::Path(qpath) => qpath, - _ => return, - }, - _ => return, - }; - let inner_span = match &last_path_segment(&vec_ty).args.unwrap().args[0] { - GenericArg::Type(ty) => ty.span, - _ => return, - }; - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - RC_BUFFER, - hir_ty.span, - "usage of `Rc` when T is a buffer type", - "try", - format!( - "Rc<[{}]>", - snippet_with_applicability(cx, inner_span, "..", &mut applicability) - ), - Applicability::MachineApplicable, - ); - return; // don't recurse into the type - } - if let Some(span) = match_borrows_parameter(cx, qpath) { - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - REDUNDANT_ALLOCATION, - hir_ty.span, - "usage of `Rc<&T>`", - "try", - snippet_with_applicability(cx, span, "..", &mut applicability).to_string(), - applicability, - ); - return; // don't recurse into the type - } - } else if cx.tcx.is_diagnostic_item(sym::Arc, def_id) { - if let Some(alternate) = match_buffer_type(cx, qpath) { - span_lint_and_sugg( - cx, - RC_BUFFER, - hir_ty.span, - "usage of `Arc` when T is a buffer type", - "try", - format!("Arc<{}>", alternate), - Applicability::MachineApplicable, - ); - return; // don't recurse into the type - } - if match_type_parameter(cx, qpath, &paths::VEC).is_some() { - let vec_ty = match &last_path_segment(qpath).args.unwrap().args[0] { - GenericArg::Type(ty) => match &ty.kind { - TyKind::Path(qpath) => qpath, - _ => return, - }, - _ => return, - }; - let inner_span = match &last_path_segment(&vec_ty).args.unwrap().args[0] { - GenericArg::Type(ty) => ty.span, - _ => return, - }; - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - RC_BUFFER, - hir_ty.span, - "usage of `Arc` when T is a buffer type", - "try", - format!( - "Arc<[{}]>", - snippet_with_applicability(cx, inner_span, "..", &mut applicability) - ), - Applicability::MachineApplicable, - ); - return; // don't recurse into the type - } - } else if cx.tcx.is_diagnostic_item(sym::vec_type, def_id) { - if_chain! { - // Get the _ part of Vec<_> - if let Some(ref last) = last_path_segment(qpath).args; - if let Some(ty) = last.args.iter().find_map(|arg| match arg { - GenericArg::Type(ty) => Some(ty), - _ => None, - }); - // ty is now _ at this point - if let TyKind::Path(ref ty_qpath) = ty.kind; - let res = qpath_res(cx, ty_qpath, ty.hir_id); - if let Some(def_id) = res.opt_def_id(); - if Some(def_id) == cx.tcx.lang_items().owned_box(); - // At this point, we know ty is Box, now get T - if let Some(ref last) = last_path_segment(ty_qpath).args; - if let Some(boxed_ty) = last.args.iter().find_map(|arg| match arg { - GenericArg::Type(ty) => Some(ty), - _ => None, - }); - let ty_ty = hir_ty_to_ty(cx.tcx, boxed_ty); - if !ty_ty.has_escaping_bound_vars(); - if ty_ty.is_sized(cx.tcx.at(ty.span), cx.param_env); - if let Ok(ty_ty_size) = cx.layout_of(ty_ty).map(|l| l.size.bytes()); - if ty_ty_size <= self.vec_box_size_threshold; - then { - span_lint_and_sugg( - cx, - VEC_BOX, - hir_ty.span, - "`Vec` is already on the heap, the boxing is unnecessary.", - "try", - format!("Vec<{}>", snippet(cx, boxed_ty.span, "..")), - Applicability::MachineApplicable, - ); - return; // don't recurse into the type - } - } - } else if cx.tcx.is_diagnostic_item(sym::option_type, def_id) { - if match_type_parameter(cx, qpath, &paths::OPTION).is_some() { - span_lint( - cx, - OPTION_OPTION, - hir_ty.span, - "consider using `Option` instead of `Option>` or a custom \ - enum if you need to distinguish all 3 cases", - ); - return; // don't recurse into the type - } - } else if match_def_path(cx, def_id, &paths::LINKED_LIST) { - span_lint_and_help( - cx, - LINKEDLIST, - hir_ty.span, - "I see you're using a LinkedList! Perhaps you meant some other data structure?", - None, - "a `VecDeque` might work", - ); - return; // don't recurse into the type - } - } - match *qpath { - QPath::Resolved(Some(ref ty), ref p) => { - self.check_ty(cx, ty, is_local); - for ty in p.segments.iter().flat_map(|seg| { - seg.args - .as_ref() - .map_or_else(|| [].iter(), |params| params.args.iter()) - .filter_map(|arg| match arg { - GenericArg::Type(ty) => Some(ty), - _ => None, - }) - }) { - self.check_ty(cx, ty, is_local); - } - }, - QPath::Resolved(None, ref p) => { - for ty in p.segments.iter().flat_map(|seg| { - seg.args - .as_ref() - .map_or_else(|| [].iter(), |params| params.args.iter()) - .filter_map(|arg| match arg { - GenericArg::Type(ty) => Some(ty), - _ => None, - }) - }) { - self.check_ty(cx, ty, is_local); - } - }, - QPath::TypeRelative(ref ty, ref seg) => { - self.check_ty(cx, ty, is_local); - if let Some(ref params) = seg.args { - for ty in params.args.iter().filter_map(|arg| match arg { - GenericArg::Type(ty) => Some(ty), - _ => None, - }) { - self.check_ty(cx, ty, is_local); - } - } - }, - QPath::LangItem(..) => {}, - } - }, - TyKind::Rptr(ref lt, ref mut_ty) => self.check_ty_rptr(cx, hir_ty, is_local, lt, mut_ty), - // recurse - TyKind::Slice(ref ty) | TyKind::Array(ref ty, _) | TyKind::Ptr(MutTy { ref ty, .. }) => { - self.check_ty(cx, ty, is_local) - }, - TyKind::Tup(tys) => { - for ty in tys { - self.check_ty(cx, ty, is_local); - } - }, - _ => {}, - } - } - - fn check_ty_rptr( - &mut self, - cx: &LateContext<'_>, - hir_ty: &hir::Ty<'_>, - is_local: bool, - lt: &Lifetime, - mut_ty: &MutTy<'_>, - ) { - match mut_ty.ty.kind { - TyKind::Path(ref qpath) => { - let hir_id = mut_ty.ty.hir_id; - let def = qpath_res(cx, qpath, hir_id); - if_chain! { - if let Some(def_id) = def.opt_def_id(); - if Some(def_id) == cx.tcx.lang_items().owned_box(); - if let QPath::Resolved(None, ref path) = *qpath; - if let [ref bx] = *path.segments; - if let Some(ref params) = bx.args; - if !params.parenthesized; - if let Some(inner) = params.args.iter().find_map(|arg| match arg { - GenericArg::Type(ty) => Some(ty), - _ => None, - }); - then { - if is_any_trait(inner) { - // Ignore `Box` types; see issue #1884 for details. - return; - } - - let ltopt = if lt.is_elided() { - String::new() - } else { - format!("{} ", lt.name.ident().as_str()) - }; - - if mut_ty.mutbl == Mutability::Mut { - // Ignore `&mut Box` types; see issue #2907 for - // details. - return; - } - - // When trait objects or opaque types have lifetime or auto-trait bounds, - // we need to add parentheses to avoid a syntax error due to its ambiguity. - // Originally reported as the issue #3128. - let inner_snippet = snippet(cx, inner.span, ".."); - let suggestion = match &inner.kind { - TyKind::TraitObject(bounds, lt_bound) if bounds.len() > 1 || !lt_bound.is_elided() => { - format!("&{}({})", ltopt, &inner_snippet) - }, - TyKind::Path(qpath) - if get_bounds_if_impl_trait(cx, qpath, inner.hir_id) - .map_or(false, |bounds| bounds.len() > 1) => - { - format!("&{}({})", ltopt, &inner_snippet) - }, - _ => format!("&{}{}", ltopt, &inner_snippet), - }; - span_lint_and_sugg( - cx, - BORROWED_BOX, - hir_ty.span, - "you seem to be trying to use `&Box`. Consider using just `&T`", - "try", - suggestion, - // To make this `MachineApplicable`, at least one needs to check if it isn't a trait item - // because the trait impls of it will break otherwise; - // and there may be other cases that result in invalid code. - // For example, type coercion doesn't work nicely. - Applicability::Unspecified, - ); - return; // don't recurse into the type - } - }; - self.check_ty(cx, &mut_ty.ty, is_local); - }, - _ => self.check_ty(cx, &mut_ty.ty, is_local), - } - } -} - -// Returns true if given type is `Any` trait. -fn is_any_trait(t: &hir::Ty<'_>) -> bool { - if_chain! { - if let TyKind::TraitObject(ref traits, _) = t.kind; - if !traits.is_empty(); - // Only Send/Sync can be used as additional traits, so it is enough to - // check only the first trait. - if match_path(&traits[0].trait_ref.path, &paths::ANY_TRAIT); - then { - return true; - } - } - - false -} - -fn get_bounds_if_impl_trait<'tcx>(cx: &LateContext<'tcx>, qpath: &QPath<'_>, id: HirId) -> Option> { - if_chain! { - if let Some(did) = qpath_res(cx, qpath, id).opt_def_id(); - if let Some(Node::GenericParam(generic_param)) = cx.tcx.hir().get_if_local(did); - if let GenericParamKind::Type { synthetic, .. } = generic_param.kind; - if synthetic == Some(SyntheticTyParamKind::ImplTrait); - then { - Some(generic_param.bounds) - } else { - None - } - } -} - -declare_clippy_lint! { - /// **What it does:** Checks for binding a unit value. - /// - /// **Why is this bad?** A unit value cannot usefully be used anywhere. So - /// binding one is kind of pointless. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let x = { - /// 1; - /// }; - /// ``` - pub LET_UNIT_VALUE, - pedantic, - "creating a `let` binding to a value of unit type, which usually can't be used afterwards" -} - -declare_lint_pass!(LetUnitValue => [LET_UNIT_VALUE]); - -impl<'tcx> LateLintPass<'tcx> for LetUnitValue { - fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { - if let StmtKind::Local(ref local) = stmt.kind { - if is_unit(cx.typeck_results().pat_ty(&local.pat)) { - if in_external_macro(cx.sess(), stmt.span) || local.pat.span.from_expansion() { - return; - } - if higher::is_from_for_desugar(local) { - return; - } - span_lint_and_then( - cx, - LET_UNIT_VALUE, - stmt.span, - "this let-binding has unit value", - |diag| { - if let Some(expr) = &local.init { - let snip = snippet_with_macro_callsite(cx, expr.span, "()"); - diag.span_suggestion( - stmt.span, - "omit the `let` binding", - format!("{};", snip), - Applicability::MachineApplicable, // snippet - ); - } - }, - ); - } - } - } -} - -declare_clippy_lint! { - /// **What it does:** Checks for comparisons to unit. This includes all binary - /// comparisons (like `==` and `<`) and asserts. - /// - /// **Why is this bad?** Unit is always equal to itself, and thus is just a - /// clumsily written constant. Mostly this happens when someone accidentally - /// adds semicolons at the end of the operands. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # fn foo() {}; - /// # fn bar() {}; - /// # fn baz() {}; - /// if { - /// foo(); - /// } == { - /// bar(); - /// } { - /// baz(); - /// } - /// ``` - /// is equal to - /// ```rust - /// # fn foo() {}; - /// # fn bar() {}; - /// # fn baz() {}; - /// { - /// foo(); - /// bar(); - /// baz(); - /// } - /// ``` - /// - /// For asserts: - /// ```rust - /// # fn foo() {}; - /// # fn bar() {}; - /// assert_eq!({ foo(); }, { bar(); }); - /// ``` - /// will always succeed - pub UNIT_CMP, - correctness, - "comparing unit values" -} - -declare_lint_pass!(UnitCmp => [UNIT_CMP]); - -impl<'tcx> LateLintPass<'tcx> for UnitCmp { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - if expr.span.from_expansion() { - if let Some(callee) = expr.span.source_callee() { - if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind { - if let ExprKind::Binary(ref cmp, ref left, _) = expr.kind { - let op = cmp.node; - if op.is_comparison() && is_unit(cx.typeck_results().expr_ty(left)) { - let result = match &*symbol.as_str() { - "assert_eq" | "debug_assert_eq" => "succeed", - "assert_ne" | "debug_assert_ne" => "fail", - _ => return, - }; - span_lint( - cx, - UNIT_CMP, - expr.span, - &format!( - "`{}` of unit values detected. This will always {}", - symbol.as_str(), - result - ), - ); - } - } - } - } - return; - } - if let ExprKind::Binary(ref cmp, ref left, _) = expr.kind { - let op = cmp.node; - if op.is_comparison() && is_unit(cx.typeck_results().expr_ty(left)) { - let result = match op { - BinOpKind::Eq | BinOpKind::Le | BinOpKind::Ge => "true", - _ => "false", - }; - span_lint( - cx, - UNIT_CMP, - expr.span, - &format!( - "{}-comparison of unit values detected. This will always be {}", - op.as_str(), - result - ), - ); - } - } - } -} - -declare_clippy_lint! { - /// **What it does:** Checks for passing a unit value as an argument to a function without using a - /// unit literal (`()`). - /// - /// **Why is this bad?** This is likely the result of an accidental semicolon. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// foo({ - /// let a = bar(); - /// baz(a); - /// }) - /// ``` - pub UNIT_ARG, - complexity, - "passing unit to a function" -} - -declare_lint_pass!(UnitArg => [UNIT_ARG]); - -impl<'tcx> LateLintPass<'tcx> for UnitArg { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if expr.span.from_expansion() { - return; - } - - // apparently stuff in the desugaring of `?` can trigger this - // so check for that here - // only the calls to `Try::from_error` is marked as desugared, - // so we need to check both the current Expr and its parent. - if is_questionmark_desugar_marked_call(expr) { - return; - } - if_chain! { - let map = &cx.tcx.hir(); - let opt_parent_node = map.find(map.get_parent_node(expr.hir_id)); - if let Some(hir::Node::Expr(parent_expr)) = opt_parent_node; - if is_questionmark_desugar_marked_call(parent_expr); - then { - return; - } - } - - match expr.kind { - ExprKind::Call(_, args) | ExprKind::MethodCall(_, _, args, _) => { - let args_to_recover = args - .iter() - .filter(|arg| { - if is_unit(cx.typeck_results().expr_ty(arg)) && !is_unit_literal(arg) { - !matches!(&arg.kind, ExprKind::Match(.., MatchSource::TryDesugar)) - } else { - false - } - }) - .collect::>(); - if !args_to_recover.is_empty() { - lint_unit_args(cx, expr, &args_to_recover); - } - }, - _ => (), - } - } -} - -fn fmt_stmts_and_call( - cx: &LateContext<'_>, - call_expr: &Expr<'_>, - call_snippet: &str, - args_snippets: &[impl AsRef], - non_empty_block_args_snippets: &[impl AsRef], -) -> String { - let call_expr_indent = indent_of(cx, call_expr.span).unwrap_or(0); - let call_snippet_with_replacements = args_snippets - .iter() - .fold(call_snippet.to_owned(), |acc, arg| acc.replacen(arg.as_ref(), "()", 1)); - - let mut stmts_and_call = non_empty_block_args_snippets - .iter() - .map(|it| it.as_ref().to_owned()) - .collect::>(); - stmts_and_call.push(call_snippet_with_replacements); - stmts_and_call = stmts_and_call - .into_iter() - .map(|v| reindent_multiline(v.into(), true, Some(call_expr_indent)).into_owned()) - .collect(); - - let mut stmts_and_call_snippet = stmts_and_call.join(&format!("{}{}", ";\n", " ".repeat(call_expr_indent))); - // expr is not in a block statement or result expression position, wrap in a block - let parent_node = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(call_expr.hir_id)); - if !matches!(parent_node, Some(Node::Block(_))) && !matches!(parent_node, Some(Node::Stmt(_))) { - let block_indent = call_expr_indent + 4; - stmts_and_call_snippet = - reindent_multiline(stmts_and_call_snippet.into(), true, Some(block_indent)).into_owned(); - stmts_and_call_snippet = format!( - "{{\n{}{}\n{}}}", - " ".repeat(block_indent), - &stmts_and_call_snippet, - " ".repeat(call_expr_indent) - ); - } - stmts_and_call_snippet -} - -fn lint_unit_args(cx: &LateContext<'_>, expr: &Expr<'_>, args_to_recover: &[&Expr<'_>]) { - let mut applicability = Applicability::MachineApplicable; - let (singular, plural) = if args_to_recover.len() > 1 { - ("", "s") - } else { - ("a ", "") - }; - span_lint_and_then( - cx, - UNIT_ARG, - expr.span, - &format!("passing {}unit value{} to a function", singular, plural), - |db| { - let mut or = ""; - args_to_recover - .iter() - .filter_map(|arg| { - if_chain! { - if let ExprKind::Block(block, _) = arg.kind; - if block.expr.is_none(); - if let Some(last_stmt) = block.stmts.iter().last(); - if let StmtKind::Semi(last_expr) = last_stmt.kind; - if let Some(snip) = snippet_opt(cx, last_expr.span); - then { - Some(( - last_stmt.span, - snip, - )) - } - else { - None - } - } - }) - .for_each(|(span, sugg)| { - db.span_suggestion( - span, - "remove the semicolon from the last statement in the block", - sugg, - Applicability::MaybeIncorrect, - ); - or = "or "; - applicability = Applicability::MaybeIncorrect; - }); - - let arg_snippets: Vec = args_to_recover - .iter() - .filter_map(|arg| snippet_opt(cx, arg.span)) - .collect(); - let arg_snippets_without_empty_blocks: Vec = args_to_recover - .iter() - .filter(|arg| !is_empty_block(arg)) - .filter_map(|arg| snippet_opt(cx, arg.span)) - .collect(); - - if let Some(call_snippet) = snippet_opt(cx, expr.span) { - let sugg = fmt_stmts_and_call( - cx, - expr, - &call_snippet, - &arg_snippets, - &arg_snippets_without_empty_blocks, - ); - - if arg_snippets_without_empty_blocks.is_empty() { - db.multipart_suggestion( - &format!("use {}unit literal{} instead", singular, plural), - args_to_recover - .iter() - .map(|arg| (arg.span, "()".to_string())) - .collect::>(), - applicability, - ); - } else { - let plural = arg_snippets_without_empty_blocks.len() > 1; - let empty_or_s = if plural { "s" } else { "" }; - let it_or_them = if plural { "them" } else { "it" }; - db.span_suggestion( - expr.span, - &format!( - "{}move the expression{} in front of the call and replace {} with the unit literal `()`", - or, empty_or_s, it_or_them - ), - sugg, - applicability, - ); - } - } - }, - ); -} - -fn is_empty_block(expr: &Expr<'_>) -> bool { - matches!( - expr.kind, - ExprKind::Block( - Block { - stmts: &[], - expr: None, - .. - }, - _, - ) - ) -} - -fn is_questionmark_desugar_marked_call(expr: &Expr<'_>) -> bool { - use rustc_span::hygiene::DesugaringKind; - if let ExprKind::Call(ref callee, _) = expr.kind { - callee.span.is_desugaring(DesugaringKind::QuestionMark) - } else { - false - } -} - -fn is_unit(ty: Ty<'_>) -> bool { - matches!(ty.kind(), ty::Tuple(slice) if slice.is_empty()) -} - -fn is_unit_literal(expr: &Expr<'_>) -> bool { - matches!(expr.kind, ExprKind::Tup(ref slice) if slice.is_empty()) -} - -declare_clippy_lint! { - /// **What it does:** Checks for casts from any numerical to a float type where - /// the receiving type cannot store all values from the original type without - /// rounding errors. This possible rounding is to be expected, so this lint is - /// `Allow` by default. - /// - /// Basically, this warns on casting any integer with 32 or more bits to `f32` - /// or any 64-bit integer to `f64`. - /// - /// **Why is this bad?** It's not bad at all. But in some applications it can be - /// helpful to know where precision loss can take place. This lint can help find - /// those places in the code. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let x = u64::MAX; - /// x as f64; - /// ``` - pub CAST_PRECISION_LOSS, - pedantic, - "casts that cause loss of precision, e.g., `x as f32` where `x: u64`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for casts from a signed to an unsigned numerical - /// type. In this case, negative values wrap around to large positive values, - /// which can be quite surprising in practice. However, as the cast works as - /// defined, this lint is `Allow` by default. - /// - /// **Why is this bad?** Possibly surprising results. You can activate this lint - /// as a one-time check to see where numerical wrapping can arise. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let y: i8 = -1; - /// y as u128; // will return 18446744073709551615 - /// ``` - pub CAST_SIGN_LOSS, - pedantic, - "casts from signed types to unsigned types, e.g., `x as u32` where `x: i32`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for casts between numerical types that may - /// truncate large values. This is expected behavior, so the cast is `Allow` by - /// default. - /// - /// **Why is this bad?** In some problem domains, it is good practice to avoid - /// truncation. This lint can be activated to help assess where additional - /// checks could be beneficial. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// fn as_u8(x: u64) -> u8 { - /// x as u8 - /// } - /// ``` - pub CAST_POSSIBLE_TRUNCATION, - pedantic, - "casts that may cause truncation of the value, e.g., `x as u8` where `x: u32`, or `x as i32` where `x: f32`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for casts from an unsigned type to a signed type of - /// the same size. Performing such a cast is a 'no-op' for the compiler, - /// i.e., nothing is changed at the bit level, and the binary representation of - /// the value is reinterpreted. This can cause wrapping if the value is too big - /// for the target signed type. However, the cast works as defined, so this lint - /// is `Allow` by default. - /// - /// **Why is this bad?** While such a cast is not bad in itself, the results can - /// be surprising when this is not the intended behavior, as demonstrated by the - /// example below. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// u32::MAX as i32; // will yield a value of `-1` - /// ``` - pub CAST_POSSIBLE_WRAP, - pedantic, - "casts that may cause wrapping around the value, e.g., `x as i32` where `x: u32` and `x > i32::MAX`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for casts between numerical types that may - /// be replaced by safe conversion functions. - /// - /// **Why is this bad?** Rust's `as` keyword will perform many kinds of - /// conversions, including silently lossy conversions. Conversion functions such - /// as `i32::from` will only perform lossless conversions. Using the conversion - /// functions prevents conversions from turning into silent lossy conversions if - /// the types of the input expressions ever change, and make it easier for - /// people reading the code to know that the conversion is lossless. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// fn as_u64(x: u8) -> u64 { - /// x as u64 - /// } - /// ``` - /// - /// Using `::from` would look like this: - /// - /// ```rust - /// fn as_u64(x: u8) -> u64 { - /// u64::from(x) - /// } - /// ``` - pub CAST_LOSSLESS, - pedantic, - "casts using `as` that are known to be lossless, e.g., `x as u64` where `x: u8`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for casts to the same type, casts of int literals to integer types - /// and casts of float literals to float types. - /// - /// **Why is this bad?** It's just unnecessary. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let _ = 2i32 as i32; - /// let _ = 0.5 as f32; - /// ``` - /// - /// Better: - /// - /// ```rust - /// let _ = 2_i32; - /// let _ = 0.5_f32; - /// ``` - pub UNNECESSARY_CAST, - complexity, - "cast to the same type, e.g., `x as i32` where `x: i32`" -} - -declare_clippy_lint! { - /// **What it does:** Checks for casts from a less-strictly-aligned pointer to a - /// more-strictly-aligned pointer - /// - /// **Why is this bad?** Dereferencing the resulting pointer may be undefined - /// behavior. - /// - /// **Known problems:** Using `std::ptr::read_unaligned` and `std::ptr::write_unaligned` or similar - /// on the resulting pointer is fine. Is over-zealous: Casts with manual alignment checks or casts like - /// u64-> u8 -> u16 can be fine. Miri is able to do a more in-depth analysis. - /// - /// **Example:** - /// ```rust - /// let _ = (&1u8 as *const u8) as *const u16; - /// let _ = (&mut 1u8 as *mut u8) as *mut u16; - /// ``` - pub CAST_PTR_ALIGNMENT, - pedantic, - "cast from a pointer to a more-strictly-aligned pointer" -} - -declare_clippy_lint! { - /// **What it does:** Checks for casts of function pointers to something other than usize - /// - /// **Why is this bad?** - /// Casting a function pointer to anything other than usize/isize is not portable across - /// architectures, because you end up losing bits if the target type is too small or end up with a - /// bunch of extra bits that waste space and add more instructions to the final binary than - /// strictly necessary for the problem - /// - /// Casting to isize also doesn't make sense since there are no signed addresses. - /// - /// **Example** - /// - /// ```rust - /// // Bad - /// fn fun() -> i32 { 1 } - /// let a = fun as i64; - /// - /// // Good - /// fn fun2() -> i32 { 1 } - /// let a = fun2 as usize; - /// ``` - pub FN_TO_NUMERIC_CAST, - style, - "casting a function pointer to a numeric type other than usize" -} - -declare_clippy_lint! { - /// **What it does:** Checks for casts of a function pointer to a numeric type not wide enough to - /// store address. - /// - /// **Why is this bad?** - /// Such a cast discards some bits of the function's address. If this is intended, it would be more - /// clearly expressed by casting to usize first, then casting the usize to the intended type (with - /// a comment) to perform the truncation. - /// - /// **Example** - /// - /// ```rust - /// // Bad - /// fn fn1() -> i16 { - /// 1 - /// }; - /// let _ = fn1 as i32; - /// - /// // Better: Cast to usize first, then comment with the reason for the truncation - /// fn fn2() -> i16 { - /// 1 - /// }; - /// let fn_ptr = fn2 as usize; - /// let fn_ptr_truncated = fn_ptr as i32; - /// ``` - pub FN_TO_NUMERIC_CAST_WITH_TRUNCATION, - style, - "casting a function pointer to a numeric type not wide enough to store the address" -} - -/// Returns the size in bits of an integral type. -/// Will return 0 if the type is not an int or uint variant -fn int_ty_to_nbits(typ: Ty<'_>, tcx: TyCtxt<'_>) -> u64 { - match typ.kind() { - ty::Int(i) => match i { - IntTy::Isize => tcx.data_layout.pointer_size.bits(), - IntTy::I8 => 8, - IntTy::I16 => 16, - IntTy::I32 => 32, - IntTy::I64 => 64, - IntTy::I128 => 128, - }, - ty::Uint(i) => match i { - UintTy::Usize => tcx.data_layout.pointer_size.bits(), - UintTy::U8 => 8, - UintTy::U16 => 16, - UintTy::U32 => 32, - UintTy::U64 => 64, - UintTy::U128 => 128, - }, - _ => 0, - } -} - -fn is_isize_or_usize(typ: Ty<'_>) -> bool { - matches!(typ.kind(), ty::Int(IntTy::Isize) | ty::Uint(UintTy::Usize)) -} - -fn span_precision_loss_lint(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to_f64: bool) { - let mantissa_nbits = if cast_to_f64 { 52 } else { 23 }; - let arch_dependent = is_isize_or_usize(cast_from) && cast_to_f64; - let arch_dependent_str = "on targets with 64-bit wide pointers "; - let from_nbits_str = if arch_dependent { - "64".to_owned() - } else if is_isize_or_usize(cast_from) { - "32 or 64".to_owned() - } else { - int_ty_to_nbits(cast_from, cx.tcx).to_string() - }; - span_lint( - cx, - CAST_PRECISION_LOSS, - expr.span, - &format!( - "casting `{0}` to `{1}` causes a loss of precision {2}(`{0}` is {3} bits wide, \ - but `{1}`'s mantissa is only {4} bits wide)", - cast_from, - if cast_to_f64 { "f64" } else { "f32" }, - if arch_dependent { arch_dependent_str } else { "" }, - from_nbits_str, - mantissa_nbits - ), - ); -} - -fn should_strip_parens(op: &Expr<'_>, snip: &str) -> bool { - if let ExprKind::Binary(_, _, _) = op.kind { - if snip.starts_with('(') && snip.ends_with(')') { - return true; - } - } - false -} - -fn span_lossless_lint(cx: &LateContext<'_>, expr: &Expr<'_>, op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { - // Do not suggest using From in consts/statics until it is valid to do so (see #2267). - if in_constant(cx, expr.hir_id) { - return; - } - // The suggestion is to use a function call, so if the original expression - // has parens on the outside, they are no longer needed. - let mut applicability = Applicability::MachineApplicable; - let opt = snippet_opt(cx, op.span); - let sugg = opt.as_ref().map_or_else( - || { - applicability = Applicability::HasPlaceholders; - ".." - }, - |snip| { - if should_strip_parens(op, snip) { - &snip[1..snip.len() - 1] - } else { - snip.as_str() - } - }, - ); - - span_lint_and_sugg( - cx, - CAST_LOSSLESS, - expr.span, - &format!( - "casting `{}` to `{}` may become silently lossy if you later change the type", - cast_from, cast_to - ), - "try", - format!("{}::from({})", cast_to, sugg), - applicability, - ); -} - -enum ArchSuffix { - _32, - _64, - None, -} - -fn check_loss_of_sign(cx: &LateContext<'_>, expr: &Expr<'_>, op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { - if !cast_from.is_signed() || cast_to.is_signed() { - return; - } - - // don't lint for positive constants - let const_val = constant(cx, &cx.typeck_results(), op); - if_chain! { - if let Some((Constant::Int(n), _)) = const_val; - if let ty::Int(ity) = *cast_from.kind(); - if sext(cx.tcx, n, ity) >= 0; - then { - return - } - } - - // don't lint for the result of methods that always return non-negative values - if let ExprKind::MethodCall(ref path, _, _, _) = op.kind { - let mut method_name = path.ident.name.as_str(); - let allowed_methods = ["abs", "checked_abs", "rem_euclid", "checked_rem_euclid"]; - - if_chain! { - if method_name == "unwrap"; - if let Some(arglist) = method_chain_args(op, &["unwrap"]); - if let ExprKind::MethodCall(ref inner_path, _, _, _) = &arglist[0][0].kind; - then { - method_name = inner_path.ident.name.as_str(); - } - } - - if allowed_methods.iter().any(|&name| method_name == name) { - return; - } - } - - span_lint( - cx, - CAST_SIGN_LOSS, - expr.span, - &format!( - "casting `{}` to `{}` may lose the sign of the value", - cast_from, cast_to - ), - ); -} - -fn check_truncation_and_wrapping(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { - let arch_64_suffix = " on targets with 64-bit wide pointers"; - let arch_32_suffix = " on targets with 32-bit wide pointers"; - let cast_unsigned_to_signed = !cast_from.is_signed() && cast_to.is_signed(); - let from_nbits = int_ty_to_nbits(cast_from, cx.tcx); - let to_nbits = int_ty_to_nbits(cast_to, cx.tcx); - let (span_truncation, suffix_truncation, span_wrap, suffix_wrap) = - match (is_isize_or_usize(cast_from), is_isize_or_usize(cast_to)) { - (true, true) | (false, false) => ( - to_nbits < from_nbits, - ArchSuffix::None, - to_nbits == from_nbits && cast_unsigned_to_signed, - ArchSuffix::None, - ), - (true, false) => ( - to_nbits <= 32, - if to_nbits == 32 { - ArchSuffix::_64 - } else { - ArchSuffix::None - }, - to_nbits <= 32 && cast_unsigned_to_signed, - ArchSuffix::_32, - ), - (false, true) => ( - from_nbits == 64, - ArchSuffix::_32, - cast_unsigned_to_signed, - if from_nbits == 64 { - ArchSuffix::_64 - } else { - ArchSuffix::_32 - }, - ), - }; - if span_truncation { - span_lint( - cx, - CAST_POSSIBLE_TRUNCATION, - expr.span, - &format!( - "casting `{}` to `{}` may truncate the value{}", - cast_from, - cast_to, - match suffix_truncation { - ArchSuffix::_32 => arch_32_suffix, - ArchSuffix::_64 => arch_64_suffix, - ArchSuffix::None => "", - } - ), - ); - } - if span_wrap { - span_lint( - cx, - CAST_POSSIBLE_WRAP, - expr.span, - &format!( - "casting `{}` to `{}` may wrap around the value{}", - cast_from, - cast_to, - match suffix_wrap { - ArchSuffix::_32 => arch_32_suffix, - ArchSuffix::_64 => arch_64_suffix, - ArchSuffix::None => "", - } - ), - ); - } -} - -fn check_lossless(cx: &LateContext<'_>, expr: &Expr<'_>, op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { - let cast_signed_to_unsigned = cast_from.is_signed() && !cast_to.is_signed(); - let from_nbits = int_ty_to_nbits(cast_from, cx.tcx); - let to_nbits = int_ty_to_nbits(cast_to, cx.tcx); - if !is_isize_or_usize(cast_from) && !is_isize_or_usize(cast_to) && from_nbits < to_nbits && !cast_signed_to_unsigned - { - span_lossless_lint(cx, expr, op, cast_from, cast_to); - } -} - -declare_lint_pass!(Casts => [ - CAST_PRECISION_LOSS, - CAST_SIGN_LOSS, - CAST_POSSIBLE_TRUNCATION, - CAST_POSSIBLE_WRAP, - CAST_LOSSLESS, - UNNECESSARY_CAST, - CAST_PTR_ALIGNMENT, - FN_TO_NUMERIC_CAST, - FN_TO_NUMERIC_CAST_WITH_TRUNCATION, -]); - -// Check if the given type is either `core::ffi::c_void` or -// one of the platform specific `libc::::c_void` of libc. -fn is_c_void(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { - if let ty::Adt(adt, _) = ty.kind() { - let names = cx.get_def_path(adt.did); - - if names.is_empty() { - return false; - } - if names[0] == sym::libc || names[0] == sym::core && *names.last().unwrap() == sym!(c_void) { - return true; - } - } - false -} - -/// Returns the mantissa bits wide of a fp type. -/// Will return 0 if the type is not a fp -fn fp_ty_mantissa_nbits(typ: Ty<'_>) -> u32 { - match typ.kind() { - ty::Float(FloatTy::F32) => 23, - ty::Float(FloatTy::F64) | ty::Infer(InferTy::FloatVar(_)) => 52, - _ => 0, - } -} - -impl<'tcx> LateLintPass<'tcx> for Casts { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if expr.span.from_expansion() { - return; - } - if let ExprKind::Cast(ref ex, cast_to) = expr.kind { - if let TyKind::Path(QPath::Resolved(_, path)) = cast_to.kind { - if let Res::Def(_, def_id) = path.res { - if cx.tcx.has_attr(def_id, sym::cfg) || cx.tcx.has_attr(def_id, sym::cfg_attr) { - return; - } - } - } - let (cast_from, cast_to) = (cx.typeck_results().expr_ty(ex), cx.typeck_results().expr_ty(expr)); - lint_fn_to_numeric_cast(cx, expr, ex, cast_from, cast_to); - if let Some(lit) = get_numeric_literal(ex) { - let literal_str = snippet_opt(cx, ex.span).unwrap_or_default(); - - if_chain! { - if let LitKind::Int(n, _) = lit.node; - if let Some(src) = snippet_opt(cx, lit.span); - if cast_to.is_floating_point(); - if let Some(num_lit) = NumericLiteral::from_lit_kind(&src, &lit.node); - let from_nbits = 128 - n.leading_zeros(); - let to_nbits = fp_ty_mantissa_nbits(cast_to); - if from_nbits != 0 && to_nbits != 0 && from_nbits <= to_nbits && num_lit.is_decimal(); - then { - let literal_str = if is_unary_neg(ex) { format!("-{}", num_lit.integer) } else { num_lit.integer.into() }; - show_unnecessary_cast(cx, expr, &literal_str, cast_from, cast_to); - return; - } - } - - match lit.node { - LitKind::Int(_, LitIntType::Unsuffixed) if cast_to.is_integral() => { - show_unnecessary_cast(cx, expr, &literal_str, cast_from, cast_to); - }, - LitKind::Float(_, LitFloatType::Unsuffixed) if cast_to.is_floating_point() => { - show_unnecessary_cast(cx, expr, &literal_str, cast_from, cast_to); - }, - LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::Float(_, LitFloatType::Unsuffixed) => {}, - _ => { - if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) { - span_lint( - cx, - UNNECESSARY_CAST, - expr.span, - &format!( - "casting to the same type is unnecessary (`{}` -> `{}`)", - cast_from, cast_to - ), - ); - } - }, - } - } - if cast_from.is_numeric() && cast_to.is_numeric() && !in_external_macro(cx.sess(), expr.span) { - lint_numeric_casts(cx, expr, ex, cast_from, cast_to); - } - - lint_cast_ptr_alignment(cx, expr, cast_from, cast_to); - } - } -} - -fn is_unary_neg(expr: &Expr<'_>) -> bool { - matches!(expr.kind, ExprKind::Unary(UnOp::UnNeg, _)) -} - -fn get_numeric_literal<'e>(expr: &'e Expr<'e>) -> Option<&'e Lit> { - match expr.kind { - ExprKind::Lit(ref lit) => Some(lit), - ExprKind::Unary(UnOp::UnNeg, e) => { - if let ExprKind::Lit(ref lit) = e.kind { - Some(lit) - } else { - None - } - }, - _ => None, - } -} - -fn show_unnecessary_cast(cx: &LateContext<'_>, expr: &Expr<'_>, literal_str: &str, cast_from: Ty<'_>, cast_to: Ty<'_>) { - let literal_kind_name = if cast_from.is_integral() { "integer" } else { "float" }; - span_lint_and_sugg( - cx, - UNNECESSARY_CAST, - expr.span, - &format!("casting {} literal to `{}` is unnecessary", literal_kind_name, cast_to), - "try", - format!("{}_{}", literal_str.trim_end_matches('.'), cast_to), - Applicability::MachineApplicable, - ); -} - -fn lint_numeric_casts<'tcx>( - cx: &LateContext<'tcx>, - expr: &Expr<'tcx>, - cast_expr: &Expr<'_>, - cast_from: Ty<'tcx>, - cast_to: Ty<'tcx>, -) { - match (cast_from.is_integral(), cast_to.is_integral()) { - (true, false) => { - let from_nbits = int_ty_to_nbits(cast_from, cx.tcx); - let to_nbits = if let ty::Float(FloatTy::F32) = cast_to.kind() { - 32 - } else { - 64 - }; - if is_isize_or_usize(cast_from) || from_nbits >= to_nbits { - span_precision_loss_lint(cx, expr, cast_from, to_nbits == 64); - } - if from_nbits < to_nbits { - span_lossless_lint(cx, expr, cast_expr, cast_from, cast_to); - } - }, - (false, true) => { - span_lint( - cx, - CAST_POSSIBLE_TRUNCATION, - expr.span, - &format!("casting `{}` to `{}` may truncate the value", cast_from, cast_to), - ); - if !cast_to.is_signed() { - span_lint( - cx, - CAST_SIGN_LOSS, - expr.span, - &format!( - "casting `{}` to `{}` may lose the sign of the value", - cast_from, cast_to - ), - ); - } - }, - (true, true) => { - check_loss_of_sign(cx, expr, cast_expr, cast_from, cast_to); - check_truncation_and_wrapping(cx, expr, cast_from, cast_to); - check_lossless(cx, expr, cast_expr, cast_from, cast_to); - }, - (false, false) => { - if let (&ty::Float(FloatTy::F64), &ty::Float(FloatTy::F32)) = (&cast_from.kind(), &cast_to.kind()) { - span_lint( - cx, - CAST_POSSIBLE_TRUNCATION, - expr.span, - "casting `f64` to `f32` may truncate the value", - ); - } - if let (&ty::Float(FloatTy::F32), &ty::Float(FloatTy::F64)) = (&cast_from.kind(), &cast_to.kind()) { - span_lossless_lint(cx, expr, cast_expr, cast_from, cast_to); - } - }, - } -} - -fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>) { - if_chain! { - if let ty::RawPtr(from_ptr_ty) = &cast_from.kind(); - if let ty::RawPtr(to_ptr_ty) = &cast_to.kind(); - if let Ok(from_layout) = cx.layout_of(from_ptr_ty.ty); - if let Ok(to_layout) = cx.layout_of(to_ptr_ty.ty); - if from_layout.align.abi < to_layout.align.abi; - // with c_void, we inherently need to trust the user - if !is_c_void(cx, from_ptr_ty.ty); - // when casting from a ZST, we don't know enough to properly lint - if !from_layout.is_zst(); - then { - span_lint( - cx, - CAST_PTR_ALIGNMENT, - expr.span, - &format!( - "casting from `{}` to a more-strictly-aligned pointer (`{}`) ({} < {} bytes)", - cast_from, - cast_to, - from_layout.align.abi.bytes(), - to_layout.align.abi.bytes(), - ), - ); - } - } -} - -fn lint_fn_to_numeric_cast( - cx: &LateContext<'_>, - expr: &Expr<'_>, - cast_expr: &Expr<'_>, - cast_from: Ty<'_>, - cast_to: Ty<'_>, -) { - // We only want to check casts to `ty::Uint` or `ty::Int` - match cast_to.kind() { - ty::Uint(_) | ty::Int(..) => { /* continue on */ }, - _ => return, - } - match cast_from.kind() { - ty::FnDef(..) | ty::FnPtr(_) => { - let mut applicability = Applicability::MaybeIncorrect; - let from_snippet = snippet_with_applicability(cx, cast_expr.span, "x", &mut applicability); - - let to_nbits = int_ty_to_nbits(cast_to, cx.tcx); - if to_nbits < cx.tcx.data_layout.pointer_size.bits() { - span_lint_and_sugg( - cx, - FN_TO_NUMERIC_CAST_WITH_TRUNCATION, - expr.span, - &format!( - "casting function pointer `{}` to `{}`, which truncates the value", - from_snippet, cast_to - ), - "try", - format!("{} as usize", from_snippet), - applicability, - ); - } else if *cast_to.kind() != ty::Uint(UintTy::Usize) { - span_lint_and_sugg( - cx, - FN_TO_NUMERIC_CAST, - expr.span, - &format!("casting function pointer `{}` to `{}`", from_snippet, cast_to), - "try", - format!("{} as usize", from_snippet), - applicability, - ); - } - }, - _ => {}, - } -} - -declare_clippy_lint! { - /// **What it does:** Checks for types used in structs, parameters and `let` - /// declarations above a certain complexity threshold. - /// - /// **Why is this bad?** Too complex types make the code less readable. Consider - /// using a `type` definition to simplify them. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// # use std::rc::Rc; - /// struct Foo { - /// inner: Rc>>>, - /// } - /// ``` - pub TYPE_COMPLEXITY, - complexity, - "usage of very complex types that might be better factored into `type` definitions" -} - -pub struct TypeComplexity { - threshold: u64, -} - -impl TypeComplexity { - #[must_use] - pub fn new(threshold: u64) -> Self { - Self { threshold } - } -} - -impl_lint_pass!(TypeComplexity => [TYPE_COMPLEXITY]); - -impl<'tcx> LateLintPass<'tcx> for TypeComplexity { - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - _: FnKind<'tcx>, - decl: &'tcx FnDecl<'_>, - _: &'tcx Body<'_>, - _: Span, - _: HirId, - ) { - self.check_fndecl(cx, decl); - } - - fn check_struct_field(&mut self, cx: &LateContext<'tcx>, field: &'tcx hir::StructField<'_>) { - // enum variants are also struct fields now - self.check_type(cx, &field.ty); - } - - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - match item.kind { - ItemKind::Static(ref ty, _, _) | ItemKind::Const(ref ty, _) => self.check_type(cx, ty), - // functions, enums, structs, impls and traits are covered - _ => (), - } - } - - fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { - match item.kind { - TraitItemKind::Const(ref ty, _) | TraitItemKind::Type(_, Some(ref ty)) => self.check_type(cx, ty), - TraitItemKind::Fn(FnSig { ref decl, .. }, TraitFn::Required(_)) => self.check_fndecl(cx, decl), - // methods with default impl are covered by check_fn - _ => (), - } - } - - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { - match item.kind { - ImplItemKind::Const(ref ty, _) | ImplItemKind::TyAlias(ref ty) => self.check_type(cx, ty), - // methods are covered by check_fn - _ => (), - } - } - - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'_>) { - if let Some(ref ty) = local.ty { - self.check_type(cx, ty); - } - } -} - -impl<'tcx> TypeComplexity { - fn check_fndecl(&self, cx: &LateContext<'tcx>, decl: &'tcx FnDecl<'_>) { - for arg in decl.inputs { - self.check_type(cx, arg); - } - if let FnRetTy::Return(ref ty) = decl.output { - self.check_type(cx, ty); - } - } - - fn check_type(&self, cx: &LateContext<'_>, ty: &hir::Ty<'_>) { - if ty.span.from_expansion() { - return; - } - let score = { - let mut visitor = TypeComplexityVisitor { score: 0, nest: 1 }; - visitor.visit_ty(ty); - visitor.score - }; - - if score > self.threshold { - span_lint( - cx, - TYPE_COMPLEXITY, - ty.span, - "very complex type used. Consider factoring parts into `type` definitions", - ); - } - } -} - -/// Walks a type and assigns a complexity score to it. -struct TypeComplexityVisitor { - /// total complexity score of the type - score: u64, - /// current nesting level - nest: u64, -} - -impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor { - type Map = Map<'tcx>; - - fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) { - let (add_score, sub_nest) = match ty.kind { - // _, &x and *x have only small overhead; don't mess with nesting level - TyKind::Infer | TyKind::Ptr(..) | TyKind::Rptr(..) => (1, 0), - - // the "normal" components of a type: named types, arrays/tuples - TyKind::Path(..) | TyKind::Slice(..) | TyKind::Tup(..) | TyKind::Array(..) => (10 * self.nest, 1), - - // function types bring a lot of overhead - TyKind::BareFn(ref bare) if bare.abi == Abi::Rust => (50 * self.nest, 1), - - TyKind::TraitObject(ref param_bounds, _) => { - let has_lifetime_parameters = param_bounds.iter().any(|bound| { - bound - .bound_generic_params - .iter() - .any(|gen| matches!(gen.kind, GenericParamKind::Lifetime { .. })) - }); - if has_lifetime_parameters { - // complex trait bounds like A<'a, 'b> - (50 * self.nest, 1) - } else { - // simple trait bounds like A + B - (20 * self.nest, 0) - } - }, - - _ => (0, 0), - }; - self.score += add_score; - self.nest += sub_nest; - walk_ty(self, ty); - self.nest -= sub_nest; - } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -declare_clippy_lint! { - /// **What it does:** Checks for expressions where a character literal is cast - /// to `u8` and suggests using a byte literal instead. - /// - /// **Why is this bad?** In general, casting values to smaller types is - /// error-prone and should be avoided where possible. In the particular case of - /// converting a character literal to u8, it is easy to avoid by just using a - /// byte literal instead. As an added bonus, `b'a'` is even slightly shorter - /// than `'a' as u8`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// 'x' as u8 - /// ``` - /// - /// A better version, using the byte literal: - /// - /// ```rust,ignore - /// b'x' - /// ``` - pub CHAR_LIT_AS_U8, - complexity, - "casting a character literal to `u8` truncates" -} - -declare_lint_pass!(CharLitAsU8 => [CHAR_LIT_AS_U8]); - -impl<'tcx> LateLintPass<'tcx> for CharLitAsU8 { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if_chain! { - if !expr.span.from_expansion(); - if let ExprKind::Cast(e, _) = &expr.kind; - if let ExprKind::Lit(l) = &e.kind; - if let LitKind::Char(c) = l.node; - if ty::Uint(UintTy::U8) == *cx.typeck_results().expr_ty(expr).kind(); - then { - let mut applicability = Applicability::MachineApplicable; - let snippet = snippet_with_applicability(cx, e.span, "'x'", &mut applicability); - - span_lint_and_then( - cx, - CHAR_LIT_AS_U8, - expr.span, - "casting a character literal to `u8` truncates", - |diag| { - diag.note("`char` is four bytes wide, but `u8` is a single byte"); - - if c.is_ascii() { - diag.span_suggestion( - expr.span, - "use a byte literal instead", - format!("b{}", snippet), - applicability, - ); - } - }); - } - } - } -} - -declare_clippy_lint! { - /// **What it does:** Checks for comparisons where one side of the relation is - /// either the minimum or maximum value for its type and warns if it involves a - /// case that is always true or always false. Only integer and boolean types are - /// checked. - /// - /// **Why is this bad?** An expression like `min <= x` may misleadingly imply - /// that it is possible for `x` to be less than the minimum. Expressions like - /// `max < x` are probably mistakes. - /// - /// **Known problems:** For `usize` the size of the current compile target will - /// be assumed (e.g., 64 bits on 64 bit systems). This means code that uses such - /// a comparison to detect target pointer width will trigger this lint. One can - /// use `mem::sizeof` and compare its value or conditional compilation - /// attributes - /// like `#[cfg(target_pointer_width = "64")] ..` instead. - /// - /// **Example:** - /// - /// ```rust - /// let vec: Vec = Vec::new(); - /// if vec.len() <= 0 {} - /// if 100 > i32::MAX {} - /// ``` - pub ABSURD_EXTREME_COMPARISONS, - correctness, - "a comparison with a maximum or minimum value that is always true or false" -} - -declare_lint_pass!(AbsurdExtremeComparisons => [ABSURD_EXTREME_COMPARISONS]); - -enum ExtremeType { - Minimum, - Maximum, -} - -struct ExtremeExpr<'a> { - which: ExtremeType, - expr: &'a Expr<'a>, -} - -enum AbsurdComparisonResult { - AlwaysFalse, - AlwaysTrue, - InequalityImpossible, -} - -fn is_cast_between_fixed_and_target<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool { - if let ExprKind::Cast(ref cast_exp, _) = expr.kind { - let precast_ty = cx.typeck_results().expr_ty(cast_exp); - let cast_ty = cx.typeck_results().expr_ty(expr); - - return is_isize_or_usize(precast_ty) != is_isize_or_usize(cast_ty); - } - - false -} - -fn detect_absurd_comparison<'tcx>( - cx: &LateContext<'tcx>, - op: BinOpKind, - lhs: &'tcx Expr<'_>, - rhs: &'tcx Expr<'_>, -) -> Option<(ExtremeExpr<'tcx>, AbsurdComparisonResult)> { - use crate::types::AbsurdComparisonResult::{AlwaysFalse, AlwaysTrue, InequalityImpossible}; - use crate::types::ExtremeType::{Maximum, Minimum}; - use crate::utils::comparisons::{normalize_comparison, Rel}; - - // absurd comparison only makes sense on primitive types - // primitive types don't implement comparison operators with each other - if cx.typeck_results().expr_ty(lhs) != cx.typeck_results().expr_ty(rhs) { - return None; - } - - // comparisons between fix sized types and target sized types are considered unanalyzable - if is_cast_between_fixed_and_target(cx, lhs) || is_cast_between_fixed_and_target(cx, rhs) { - return None; - } - - let (rel, normalized_lhs, normalized_rhs) = normalize_comparison(op, lhs, rhs)?; - - let lx = detect_extreme_expr(cx, normalized_lhs); - let rx = detect_extreme_expr(cx, normalized_rhs); - - Some(match rel { - Rel::Lt => { - match (lx, rx) { - (Some(l @ ExtremeExpr { which: Maximum, .. }), _) => (l, AlwaysFalse), // max < x - (_, Some(r @ ExtremeExpr { which: Minimum, .. })) => (r, AlwaysFalse), // x < min - _ => return None, - } - }, - Rel::Le => { - match (lx, rx) { - (Some(l @ ExtremeExpr { which: Minimum, .. }), _) => (l, AlwaysTrue), // min <= x - (Some(l @ ExtremeExpr { which: Maximum, .. }), _) => (l, InequalityImpossible), // max <= x - (_, Some(r @ ExtremeExpr { which: Minimum, .. })) => (r, InequalityImpossible), // x <= min - (_, Some(r @ ExtremeExpr { which: Maximum, .. })) => (r, AlwaysTrue), // x <= max - _ => return None, - } - }, - Rel::Ne | Rel::Eq => return None, - }) -} - -fn detect_extreme_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option> { - use crate::types::ExtremeType::{Maximum, Minimum}; - - let ty = cx.typeck_results().expr_ty(expr); - - let cv = constant(cx, cx.typeck_results(), expr)?.0; - - let which = match (ty.kind(), cv) { - (&ty::Bool, Constant::Bool(false)) | (&ty::Uint(_), Constant::Int(0)) => Minimum, - (&ty::Int(ity), Constant::Int(i)) if i == unsext(cx.tcx, i128::MIN >> (128 - int_bits(cx.tcx, ity)), ity) => { - Minimum - }, - - (&ty::Bool, Constant::Bool(true)) => Maximum, - (&ty::Int(ity), Constant::Int(i)) if i == unsext(cx.tcx, i128::MAX >> (128 - int_bits(cx.tcx, ity)), ity) => { - Maximum - }, - (&ty::Uint(uty), Constant::Int(i)) if clip(cx.tcx, u128::MAX, uty) == i => Maximum, - - _ => return None, - }; - Some(ExtremeExpr { which, expr }) -} - -impl<'tcx> LateLintPass<'tcx> for AbsurdExtremeComparisons { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - use crate::types::AbsurdComparisonResult::{AlwaysFalse, AlwaysTrue, InequalityImpossible}; - use crate::types::ExtremeType::{Maximum, Minimum}; - - if let ExprKind::Binary(ref cmp, ref lhs, ref rhs) = expr.kind { - if let Some((culprit, result)) = detect_absurd_comparison(cx, cmp.node, lhs, rhs) { - if !expr.span.from_expansion() { - let msg = "this comparison involving the minimum or maximum element for this \ - type contains a case that is always true or always false"; - - let conclusion = match result { - AlwaysFalse => "this comparison is always false".to_owned(), - AlwaysTrue => "this comparison is always true".to_owned(), - InequalityImpossible => format!( - "the case where the two sides are not equal never occurs, consider using `{} == {}` \ - instead", - snippet(cx, lhs.span, "lhs"), - snippet(cx, rhs.span, "rhs") - ), - }; - - let help = format!( - "because `{}` is the {} value for this type, {}", - snippet(cx, culprit.expr.span, "x"), - match culprit.which { - Minimum => "minimum", - Maximum => "maximum", - }, - conclusion - ); - - span_lint_and_help(cx, ABSURD_EXTREME_COMPARISONS, expr.span, msg, None, &help); - } - } - } - } -} - -declare_clippy_lint! { - /// **What it does:** Checks for comparisons where the relation is always either - /// true or false, but where one side has been upcast so that the comparison is - /// necessary. Only integer types are checked. - /// - /// **Why is this bad?** An expression like `let x : u8 = ...; (x as u32) > 300` - /// will mistakenly imply that it is possible for `x` to be outside the range of - /// `u8`. - /// - /// **Known problems:** - /// https://github.com/rust-lang/rust-clippy/issues/886 - /// - /// **Example:** - /// ```rust - /// let x: u8 = 1; - /// (x as u32) > 300; - /// ``` - pub INVALID_UPCAST_COMPARISONS, - pedantic, - "a comparison involving an upcast which is always true or false" -} - -declare_lint_pass!(InvalidUpcastComparisons => [INVALID_UPCAST_COMPARISONS]); - -#[derive(Copy, Clone, Debug, Eq)] -enum FullInt { - S(i128), - U(u128), -} - -impl FullInt { - #[allow(clippy::cast_sign_loss)] - #[must_use] - fn cmp_s_u(s: i128, u: u128) -> Ordering { - if s < 0 { - Ordering::Less - } else if u > (i128::MAX as u128) { - Ordering::Greater - } else { - (s as u128).cmp(&u) - } - } -} - -impl PartialEq for FullInt { - #[must_use] - fn eq(&self, other: &Self) -> bool { - self.partial_cmp(other).expect("`partial_cmp` only returns `Some(_)`") == Ordering::Equal - } -} - -impl PartialOrd for FullInt { - #[must_use] - fn partial_cmp(&self, other: &Self) -> Option { - Some(match (self, other) { - (&Self::S(s), &Self::S(o)) => s.cmp(&o), - (&Self::U(s), &Self::U(o)) => s.cmp(&o), - (&Self::S(s), &Self::U(o)) => Self::cmp_s_u(s, o), - (&Self::U(s), &Self::S(o)) => Self::cmp_s_u(o, s).reverse(), - }) - } -} - -impl Ord for FullInt { - #[must_use] - fn cmp(&self, other: &Self) -> Ordering { - self.partial_cmp(other) - .expect("`partial_cmp` for FullInt can never return `None`") - } -} - -fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_>, expr: &'a Expr<'_>) -> Option<(FullInt, FullInt)> { - if let ExprKind::Cast(ref cast_exp, _) = expr.kind { - let pre_cast_ty = cx.typeck_results().expr_ty(cast_exp); - let cast_ty = cx.typeck_results().expr_ty(expr); - // if it's a cast from i32 to u32 wrapping will invalidate all these checks - if cx.layout_of(pre_cast_ty).ok().map(|l| l.size) == cx.layout_of(cast_ty).ok().map(|l| l.size) { - return None; - } - match pre_cast_ty.kind() { - ty::Int(int_ty) => Some(match int_ty { - IntTy::I8 => (FullInt::S(i128::from(i8::MIN)), FullInt::S(i128::from(i8::MAX))), - IntTy::I16 => (FullInt::S(i128::from(i16::MIN)), FullInt::S(i128::from(i16::MAX))), - IntTy::I32 => (FullInt::S(i128::from(i32::MIN)), FullInt::S(i128::from(i32::MAX))), - IntTy::I64 => (FullInt::S(i128::from(i64::MIN)), FullInt::S(i128::from(i64::MAX))), - IntTy::I128 => (FullInt::S(i128::MIN), FullInt::S(i128::MAX)), - IntTy::Isize => (FullInt::S(isize::MIN as i128), FullInt::S(isize::MAX as i128)), - }), - ty::Uint(uint_ty) => Some(match uint_ty { - UintTy::U8 => (FullInt::U(u128::from(u8::MIN)), FullInt::U(u128::from(u8::MAX))), - UintTy::U16 => (FullInt::U(u128::from(u16::MIN)), FullInt::U(u128::from(u16::MAX))), - UintTy::U32 => (FullInt::U(u128::from(u32::MIN)), FullInt::U(u128::from(u32::MAX))), - UintTy::U64 => (FullInt::U(u128::from(u64::MIN)), FullInt::U(u128::from(u64::MAX))), - UintTy::U128 => (FullInt::U(u128::MIN), FullInt::U(u128::MAX)), - UintTy::Usize => (FullInt::U(usize::MIN as u128), FullInt::U(usize::MAX as u128)), - }), - _ => None, - } - } else { - None - } -} - -fn node_as_const_fullint<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option { - let val = constant(cx, cx.typeck_results(), expr)?.0; - if let Constant::Int(const_int) = val { - match *cx.typeck_results().expr_ty(expr).kind() { - ty::Int(ity) => Some(FullInt::S(sext(cx.tcx, const_int, ity))), - ty::Uint(_) => Some(FullInt::U(const_int)), - _ => None, - } - } else { - None - } -} - -fn err_upcast_comparison(cx: &LateContext<'_>, span: Span, expr: &Expr<'_>, always: bool) { - if let ExprKind::Cast(ref cast_val, _) = expr.kind { - span_lint( - cx, - INVALID_UPCAST_COMPARISONS, - span, - &format!( - "because of the numeric bounds on `{}` prior to casting, this expression is always {}", - snippet(cx, cast_val.span, "the expression"), - if always { "true" } else { "false" }, - ), - ); - } -} - -fn upcast_comparison_bounds_err<'tcx>( - cx: &LateContext<'tcx>, - span: Span, - rel: comparisons::Rel, - lhs_bounds: Option<(FullInt, FullInt)>, - lhs: &'tcx Expr<'_>, - rhs: &'tcx Expr<'_>, - invert: bool, -) { - use crate::utils::comparisons::Rel; - - if let Some((lb, ub)) = lhs_bounds { - if let Some(norm_rhs_val) = node_as_const_fullint(cx, rhs) { - if rel == Rel::Eq || rel == Rel::Ne { - if norm_rhs_val < lb || norm_rhs_val > ub { - err_upcast_comparison(cx, span, lhs, rel == Rel::Ne); - } - } else if match rel { - Rel::Lt => { - if invert { - norm_rhs_val < lb - } else { - ub < norm_rhs_val - } - }, - Rel::Le => { - if invert { - norm_rhs_val <= lb - } else { - ub <= norm_rhs_val - } - }, - Rel::Eq | Rel::Ne => unreachable!(), - } { - err_upcast_comparison(cx, span, lhs, true) - } else if match rel { - Rel::Lt => { - if invert { - norm_rhs_val >= ub - } else { - lb >= norm_rhs_val - } - }, - Rel::Le => { - if invert { - norm_rhs_val > ub - } else { - lb > norm_rhs_val - } - }, - Rel::Eq | Rel::Ne => unreachable!(), - } { - err_upcast_comparison(cx, span, lhs, false) - } - } - } -} - -impl<'tcx> LateLintPass<'tcx> for InvalidUpcastComparisons { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Binary(ref cmp, ref lhs, ref rhs) = expr.kind { - let normalized = comparisons::normalize_comparison(cmp.node, lhs, rhs); - let (rel, normalized_lhs, normalized_rhs) = if let Some(val) = normalized { - val - } else { - return; - }; - - let lhs_bounds = numeric_cast_precast_bounds(cx, normalized_lhs); - let rhs_bounds = numeric_cast_precast_bounds(cx, normalized_rhs); - - upcast_comparison_bounds_err(cx, expr.span, rel, lhs_bounds, normalized_lhs, normalized_rhs, false); - upcast_comparison_bounds_err(cx, expr.span, rel, rhs_bounds, normalized_rhs, normalized_lhs, true); - } - } -} - -declare_clippy_lint! { - /// **What it does:** Checks for public `impl` or `fn` missing generalization - /// over different hashers and implicitly defaulting to the default hashing - /// algorithm (`SipHash`). - /// - /// **Why is this bad?** `HashMap` or `HashSet` with custom hashers cannot be - /// used with them. - /// - /// **Known problems:** Suggestions for replacing constructors can contain - /// false-positives. Also applying suggestions can require modification of other - /// pieces of code, possibly including external crates. - /// - /// **Example:** - /// ```rust - /// # use std::collections::HashMap; - /// # use std::hash::{Hash, BuildHasher}; - /// # trait Serialize {}; - /// impl Serialize for HashMap { } - /// - /// pub fn foo(map: &mut HashMap) { } - /// ``` - /// could be rewritten as - /// ```rust - /// # use std::collections::HashMap; - /// # use std::hash::{Hash, BuildHasher}; - /// # trait Serialize {}; - /// impl Serialize for HashMap { } - /// - /// pub fn foo(map: &mut HashMap) { } - /// ``` - pub IMPLICIT_HASHER, - pedantic, - "missing generalization over different hashers" -} - -declare_lint_pass!(ImplicitHasher => [IMPLICIT_HASHER]); - -impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { - #[allow(clippy::cast_possible_truncation, clippy::too_many_lines)] - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - use rustc_span::BytePos; - - fn suggestion<'tcx>( - cx: &LateContext<'tcx>, - diag: &mut DiagnosticBuilder<'_>, - generics_span: Span, - generics_suggestion_span: Span, - target: &ImplicitHasherType<'_>, - vis: ImplicitHasherConstructorVisitor<'_, '_, '_>, - ) { - let generics_snip = snippet(cx, generics_span, ""); - // trim `<` `>` - let generics_snip = if generics_snip.is_empty() { - "" - } else { - &generics_snip[1..generics_snip.len() - 1] - }; - - multispan_sugg( - diag, - "consider adding a type parameter", - vec![ - ( - generics_suggestion_span, - format!( - "<{}{}S: ::std::hash::BuildHasher{}>", - generics_snip, - if generics_snip.is_empty() { "" } else { ", " }, - if vis.suggestions.is_empty() { - "" - } else { - // request users to add `Default` bound so that generic constructors can be used - " + Default" - }, - ), - ), - ( - target.span(), - format!("{}<{}, S>", target.type_name(), target.type_arguments(),), - ), - ], - ); - - if !vis.suggestions.is_empty() { - multispan_sugg(diag, "...and use generic constructor", vis.suggestions); - } - } - - if !cx.access_levels.is_exported(item.hir_id) { - return; - } - - match item.kind { - ItemKind::Impl { - ref generics, - self_ty: ref ty, - ref items, - .. - } => { - let mut vis = ImplicitHasherTypeVisitor::new(cx); - vis.visit_ty(ty); - - for target in &vis.found { - if differing_macro_contexts(item.span, target.span()) { - return; - } - - let generics_suggestion_span = generics.span.substitute_dummy({ - let pos = snippet_opt(cx, item.span.until(target.span())) - .and_then(|snip| Some(item.span.lo() + BytePos(snip.find("impl")? as u32 + 4))); - if let Some(pos) = pos { - Span::new(pos, pos, item.span.data().ctxt) - } else { - return; - } - }); - - let mut ctr_vis = ImplicitHasherConstructorVisitor::new(cx, target); - for item in items.iter().map(|item| cx.tcx.hir().impl_item(item.id)) { - ctr_vis.visit_impl_item(item); - } - - span_lint_and_then( - cx, - IMPLICIT_HASHER, - target.span(), - &format!( - "impl for `{}` should be generalized over different hashers", - target.type_name() - ), - move |diag| { - suggestion(cx, diag, generics.span, generics_suggestion_span, target, ctr_vis); - }, - ); - } - }, - ItemKind::Fn(ref sig, ref generics, body_id) => { - let body = cx.tcx.hir().body(body_id); - - for ty in sig.decl.inputs { - let mut vis = ImplicitHasherTypeVisitor::new(cx); - vis.visit_ty(ty); - - for target in &vis.found { - if in_external_macro(cx.sess(), generics.span) { - continue; - } - let generics_suggestion_span = generics.span.substitute_dummy({ - let pos = snippet_opt(cx, item.span.until(body.params[0].pat.span)) - .and_then(|snip| { - let i = snip.find("fn")?; - Some(item.span.lo() + BytePos((i + (&snip[i..]).find('(')?) as u32)) - }) - .expect("failed to create span for type parameters"); - Span::new(pos, pos, item.span.data().ctxt) - }); - - let mut ctr_vis = ImplicitHasherConstructorVisitor::new(cx, target); - ctr_vis.visit_body(body); - - span_lint_and_then( - cx, - IMPLICIT_HASHER, - target.span(), - &format!( - "parameter of type `{}` should be generalized over different hashers", - target.type_name() - ), - move |diag| { - suggestion(cx, diag, generics.span, generics_suggestion_span, target, ctr_vis); - }, - ); - } - } - }, - _ => {}, - } - } -} - -enum ImplicitHasherType<'tcx> { - HashMap(Span, Ty<'tcx>, Cow<'static, str>, Cow<'static, str>), - HashSet(Span, Ty<'tcx>, Cow<'static, str>), -} - -impl<'tcx> ImplicitHasherType<'tcx> { - /// Checks that `ty` is a target type without a `BuildHasher`. - fn new(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'_>) -> Option { - if let TyKind::Path(QPath::Resolved(None, ref path)) = hir_ty.kind { - let params: Vec<_> = path - .segments - .last() - .as_ref()? - .args - .as_ref()? - .args - .iter() - .filter_map(|arg| match arg { - GenericArg::Type(ty) => Some(ty), - _ => None, - }) - .collect(); - let params_len = params.len(); - - let ty = hir_ty_to_ty(cx.tcx, hir_ty); - - if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) && params_len == 2 { - Some(ImplicitHasherType::HashMap( - hir_ty.span, - ty, - snippet(cx, params[0].span, "K"), - snippet(cx, params[1].span, "V"), - )) - } else if is_type_diagnostic_item(cx, ty, sym!(hashset_type)) && params_len == 1 { - Some(ImplicitHasherType::HashSet( - hir_ty.span, - ty, - snippet(cx, params[0].span, "T"), - )) - } else { - None - } - } else { - None - } - } - - fn type_name(&self) -> &'static str { - match *self { - ImplicitHasherType::HashMap(..) => "HashMap", - ImplicitHasherType::HashSet(..) => "HashSet", - } - } - - fn type_arguments(&self) -> String { - match *self { - ImplicitHasherType::HashMap(.., ref k, ref v) => format!("{}, {}", k, v), - ImplicitHasherType::HashSet(.., ref t) => format!("{}", t), - } - } - - fn ty(&self) -> Ty<'tcx> { - match *self { - ImplicitHasherType::HashMap(_, ty, ..) | ImplicitHasherType::HashSet(_, ty, ..) => ty, - } - } - - fn span(&self) -> Span { - match *self { - ImplicitHasherType::HashMap(span, ..) | ImplicitHasherType::HashSet(span, ..) => span, - } - } -} - -struct ImplicitHasherTypeVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - found: Vec>, -} - -impl<'a, 'tcx> ImplicitHasherTypeVisitor<'a, 'tcx> { - fn new(cx: &'a LateContext<'tcx>) -> Self { - Self { cx, found: vec![] } - } -} - -impl<'a, 'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_ty(&mut self, t: &'tcx hir::Ty<'_>) { - if let Some(target) = ImplicitHasherType::new(self.cx, t) { - self.found.push(target); - } - - walk_ty(self, t); - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -/// Looks for default-hasher-dependent constructors like `HashMap::new`. -struct ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { - cx: &'a LateContext<'tcx>, - maybe_typeck_results: Option<&'tcx TypeckResults<'tcx>>, - target: &'b ImplicitHasherType<'tcx>, - suggestions: BTreeMap, -} - -impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { - fn new(cx: &'a LateContext<'tcx>, target: &'b ImplicitHasherType<'tcx>) -> Self { - Self { - cx, - maybe_typeck_results: cx.maybe_typeck_results(), - target, - suggestions: BTreeMap::new(), - } - } -} - -impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { - type Map = Map<'tcx>; - - fn visit_body(&mut self, body: &'tcx Body<'_>) { - let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body.id())); - walk_body(self, body); - self.maybe_typeck_results = old_maybe_typeck_results; - } - - fn visit_expr(&mut self, e: &'tcx Expr<'_>) { - if_chain! { - if let ExprKind::Call(ref fun, ref args) = e.kind; - if let ExprKind::Path(QPath::TypeRelative(ref ty, ref method)) = fun.kind; - if let TyKind::Path(QPath::Resolved(None, ty_path)) = ty.kind; - then { - if !TyS::same_type(self.target.ty(), self.maybe_typeck_results.unwrap().expr_ty(e)) { - return; - } - - if match_path(ty_path, &paths::HASHMAP) { - if method.ident.name == sym::new { - self.suggestions - .insert(e.span, "HashMap::default()".to_string()); - } else if method.ident.name == sym!(with_capacity) { - self.suggestions.insert( - e.span, - format!( - "HashMap::with_capacity_and_hasher({}, Default::default())", - snippet(self.cx, args[0].span, "capacity"), - ), - ); - } - } else if match_path(ty_path, &paths::HASHSET) { - if method.ident.name == sym::new { - self.suggestions - .insert(e.span, "HashSet::default()".to_string()); - } else if method.ident.name == sym!(with_capacity) { - self.suggestions.insert( - e.span, - format!( - "HashSet::with_capacity_and_hasher({}, Default::default())", - snippet(self.cx, args[0].span, "capacity"), - ), - ); - } - } - } - } - - walk_expr(self, e); - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) - } -} - -declare_clippy_lint! { - /// **What it does:** Checks for casts of `&T` to `&mut T` anywhere in the code. - /// - /// **Why is this bad?** It’s basically guaranteed to be undefined behaviour. - /// `UnsafeCell` is the only way to obtain aliasable data that is considered - /// mutable. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// fn x(r: &i32) { - /// unsafe { - /// *(r as *const _ as *mut _) += 1; - /// } - /// } - /// ``` - /// - /// Instead consider using interior mutability types. - /// - /// ```rust - /// use std::cell::UnsafeCell; - /// - /// fn x(r: &UnsafeCell) { - /// unsafe { - /// *r.get() += 1; - /// } - /// } - /// ``` - pub CAST_REF_TO_MUT, - correctness, - "a cast of reference to a mutable pointer" -} - -declare_lint_pass!(RefToMut => [CAST_REF_TO_MUT]); - -impl<'tcx> LateLintPass<'tcx> for RefToMut { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if_chain! { - if let ExprKind::Unary(UnOp::UnDeref, e) = &expr.kind; - if let ExprKind::Cast(e, t) = &e.kind; - if let TyKind::Ptr(MutTy { mutbl: Mutability::Mut, .. }) = t.kind; - if let ExprKind::Cast(e, t) = &e.kind; - if let TyKind::Ptr(MutTy { mutbl: Mutability::Not, .. }) = t.kind; - if let ty::Ref(..) = cx.typeck_results().node_type(e.hir_id).kind(); - then { - span_lint( - cx, - CAST_REF_TO_MUT, - expr.span, - "casting `&T` to `&mut T` may cause undefined behavior, consider instead using an `UnsafeCell`", - ); - } - } - } -} diff --git a/clippy_lints/src/undropped_manually_drops.rs b/clippy_lints/src/undropped_manually_drops.rs deleted file mode 100644 index 5443f1601fcb..000000000000 --- a/clippy_lints/src/undropped_manually_drops.rs +++ /dev/null @@ -1,50 +0,0 @@ -use crate::utils::{is_type_lang_item, match_function_call, paths, span_lint_and_help}; -use rustc_hir::{lang_items, Expr}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Prevents the safe `std::mem::drop` function from being called on `std::mem::ManuallyDrop`. - /// - /// **Why is this bad?** The safe `drop` function does not drop the inner value of a `ManuallyDrop`. - /// - /// **Known problems:** Does not catch cases if the user binds `std::mem::drop` - /// to a different name and calls it that way. - /// - /// **Example:** - /// - /// ```rust - /// struct S; - /// drop(std::mem::ManuallyDrop::new(S)); - /// ``` - /// Use instead: - /// ```rust - /// struct S; - /// unsafe { - /// std::mem::ManuallyDrop::drop(&mut std::mem::ManuallyDrop::new(S)); - /// } - /// ``` - pub UNDROPPED_MANUALLY_DROPS, - correctness, - "use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value" -} - -declare_lint_pass!(UndroppedManuallyDrops => [UNDROPPED_MANUALLY_DROPS]); - -impl LateLintPass<'tcx> for UndroppedManuallyDrops { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let Some(ref args) = match_function_call(cx, expr, &paths::DROP) { - let ty = cx.typeck_results().expr_ty(&args[0]); - if is_type_lang_item(cx, ty, lang_items::LangItem::ManuallyDrop) { - span_lint_and_help( - cx, - UNDROPPED_MANUALLY_DROPS, - expr.span, - "the inner value of this ManuallyDrop will not be dropped", - None, - "to drop a `ManuallyDrop`, use std::mem::ManuallyDrop::drop", - ); - } - } - } -} diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs deleted file mode 100644 index 93d59cc7fcd1..000000000000 --- a/clippy_lints/src/unicode.rs +++ /dev/null @@ -1,134 +0,0 @@ -use crate::utils::{is_allowed, snippet, span_lint_and_sugg}; -use rustc_ast::ast::LitKind; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, HirId}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use unicode_normalization::UnicodeNormalization; - -declare_clippy_lint! { - /// **What it does:** Checks for invisible Unicode characters in the code. - /// - /// **Why is this bad?** Having an invisible character in the code makes for all - /// sorts of April fools, but otherwise is very much frowned upon. - /// - /// **Known problems:** None. - /// - /// **Example:** You don't see it, but there may be a zero-width space or soft hyphen - /// some­where in this text. - pub INVISIBLE_CHARACTERS, - correctness, - "using an invisible character in a string literal, which is confusing" -} - -declare_clippy_lint! { - /// **What it does:** Checks for non-ASCII characters in string literals. - /// - /// **Why is this bad?** Yeah, we know, the 90's called and wanted their charset - /// back. Even so, there still are editors and other programs out there that - /// don't work well with Unicode. So if the code is meant to be used - /// internationally, on multiple operating systems, or has other portability - /// requirements, activating this lint could be useful. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// let x = String::from("€"); - /// ``` - /// Could be written as: - /// ```rust - /// let x = String::from("\u{20ac}"); - /// ``` - pub NON_ASCII_LITERAL, - pedantic, - "using any literal non-ASCII chars in a string literal instead of using the `\\u` escape" -} - -declare_clippy_lint! { - /// **What it does:** Checks for string literals that contain Unicode in a form - /// that is not equal to its - /// [NFC-recomposition](http://www.unicode.org/reports/tr15/#Norm_Forms). - /// - /// **Why is this bad?** If such a string is compared to another, the results - /// may be surprising. - /// - /// **Known problems** None. - /// - /// **Example:** You may not see it, but "à"" and "à"" aren't the same string. The - /// former when escaped is actually `"a\u{300}"` while the latter is `"\u{e0}"`. - pub UNICODE_NOT_NFC, - pedantic, - "using a Unicode literal not in NFC normal form (see [Unicode tr15](http://www.unicode.org/reports/tr15/) for further information)" -} - -declare_lint_pass!(Unicode => [INVISIBLE_CHARACTERS, NON_ASCII_LITERAL, UNICODE_NOT_NFC]); - -impl LateLintPass<'_> for Unicode { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) { - if let ExprKind::Lit(ref lit) = expr.kind { - if let LitKind::Str(_, _) = lit.node { - check_str(cx, lit.span, expr.hir_id) - } - } - } -} - -fn escape>(s: T) -> String { - let mut result = String::new(); - for c in s { - if c as u32 > 0x7F { - for d in c.escape_unicode() { - result.push(d) - } - } else { - result.push(c); - } - } - result -} - -fn check_str(cx: &LateContext<'_>, span: Span, id: HirId) { - let string = snippet(cx, span, ""); - if string.chars().any(|c| ['\u{200B}', '\u{ad}', '\u{2060}'].contains(&c)) { - span_lint_and_sugg( - cx, - INVISIBLE_CHARACTERS, - span, - "invisible character detected", - "consider replacing the string with", - string - .replace("\u{200B}", "\\u{200B}") - .replace("\u{ad}", "\\u{AD}") - .replace("\u{2060}", "\\u{2060}"), - Applicability::MachineApplicable, - ); - } - if string.chars().any(|c| c as u32 > 0x7F) { - span_lint_and_sugg( - cx, - NON_ASCII_LITERAL, - span, - "literal non-ASCII character detected", - "consider replacing the string with", - if is_allowed(cx, UNICODE_NOT_NFC, id) { - escape(string.chars()) - } else { - escape(string.nfc()) - }, - Applicability::MachineApplicable, - ); - } - if is_allowed(cx, NON_ASCII_LITERAL, id) && string.chars().zip(string.nfc()).any(|(a, b)| a != b) { - span_lint_and_sugg( - cx, - UNICODE_NOT_NFC, - span, - "non-NFC Unicode sequence detected", - "consider replacing the string with", - string.nfc().collect::(), - Applicability::MachineApplicable, - ); - } -} diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs deleted file mode 100644 index 2501635e7ef6..000000000000 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ /dev/null @@ -1,177 +0,0 @@ -use crate::utils::{get_trait_def_id, paths, span_lint, span_lint_and_help}; -use if_chain::if_chain; -use rustc_hir::def_id::DefId; -use rustc_hir::{Expr, ExprKind, StmtKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_middle::ty::{GenericPredicates, PredicateAtom, ProjectionPredicate, TraitPredicate}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::{BytePos, Span}; - -declare_clippy_lint! { - /// **What it does:** Checks for functions that expect closures of type - /// Fn(...) -> Ord where the implemented closure returns the unit type. - /// The lint also suggests to remove the semi-colon at the end of the statement if present. - /// - /// **Why is this bad?** Likely, returning the unit type is unintentional, and - /// could simply be caused by an extra semi-colon. Since () implements Ord - /// it doesn't cause a compilation error. - /// This is the same reasoning behind the unit_cmp lint. - /// - /// **Known problems:** If returning unit is intentional, then there is no - /// way of specifying this without triggering needless_return lint - /// - /// **Example:** - /// - /// ```rust - /// let mut twins = vec!((1, 1), (2, 2)); - /// twins.sort_by_key(|x| { x.1; }); - /// ``` - pub UNIT_RETURN_EXPECTING_ORD, - correctness, - "fn arguments of type Fn(...) -> Ord returning the unit type ()." -} - -declare_lint_pass!(UnitReturnExpectingOrd => [UNIT_RETURN_EXPECTING_ORD]); - -fn get_trait_predicates_for_trait_id<'tcx>( - cx: &LateContext<'tcx>, - generics: GenericPredicates<'tcx>, - trait_id: Option, -) -> Vec> { - let mut preds = Vec::new(); - for (pred, _) in generics.predicates { - if_chain! { - if let PredicateAtom::Trait(poly_trait_pred, _) = pred.skip_binders(); - let trait_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(poly_trait_pred)); - if let Some(trait_def_id) = trait_id; - if trait_def_id == trait_pred.trait_ref.def_id; - then { - preds.push(trait_pred); - } - } - } - preds -} - -fn get_projection_pred<'tcx>( - cx: &LateContext<'tcx>, - generics: GenericPredicates<'tcx>, - pred: TraitPredicate<'tcx>, -) -> Option> { - generics.predicates.iter().find_map(|(proj_pred, _)| { - if let ty::PredicateAtom::Projection(proj_pred) = proj_pred.skip_binders() { - let projection_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(proj_pred)); - if projection_pred.projection_ty.substs == pred.trait_ref.substs { - return Some(projection_pred); - } - } - None - }) -} - -fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Vec<(usize, String)> { - let mut args_to_check = Vec::new(); - if let Some(def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) { - let fn_sig = cx.tcx.fn_sig(def_id); - let generics = cx.tcx.predicates_of(def_id); - let fn_mut_preds = get_trait_predicates_for_trait_id(cx, generics, cx.tcx.lang_items().fn_mut_trait()); - let ord_preds = get_trait_predicates_for_trait_id(cx, generics, get_trait_def_id(cx, &paths::ORD)); - let partial_ord_preds = - get_trait_predicates_for_trait_id(cx, generics, cx.tcx.lang_items().partial_ord_trait()); - // Trying to call erase_late_bound_regions on fn_sig.inputs() gives the following error - // The trait `rustc::ty::TypeFoldable<'_>` is not implemented for `&[&rustc::ty::TyS<'_>]` - let inputs_output = cx.tcx.erase_late_bound_regions(fn_sig.inputs_and_output()); - inputs_output - .iter() - .rev() - .skip(1) - .rev() - .enumerate() - .for_each(|(i, inp)| { - for trait_pred in &fn_mut_preds { - if_chain! { - if trait_pred.self_ty() == inp; - if let Some(return_ty_pred) = get_projection_pred(cx, generics, *trait_pred); - then { - if ord_preds.iter().any(|ord| ord.self_ty() == return_ty_pred.ty) { - args_to_check.push((i, "Ord".to_string())); - } else if partial_ord_preds.iter().any(|pord| pord.self_ty() == return_ty_pred.ty) { - args_to_check.push((i, "PartialOrd".to_string())); - } - } - } - } - }); - } - args_to_check -} - -fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Span, Option)> { - if_chain! { - if let ExprKind::Closure(_, _fn_decl, body_id, span, _) = arg.kind; - if let ty::Closure(_def_id, substs) = &cx.typeck_results().node_type(arg.hir_id).kind(); - let ret_ty = substs.as_closure().sig().output(); - let ty = cx.tcx.erase_late_bound_regions(ret_ty); - if ty.is_unit(); - then { - if_chain! { - let body = cx.tcx.hir().body(body_id); - if let ExprKind::Block(block, _) = body.value.kind; - if block.expr.is_none(); - if let Some(stmt) = block.stmts.last(); - if let StmtKind::Semi(_) = stmt.kind; - then { - let data = stmt.span.data(); - // Make a span out of the semicolon for the help message - Some((span, Some(Span::new(data.hi-BytePos(1), data.hi, data.ctxt)))) - } else { - Some((span, None)) - } - } - } else { - None - } - } -} - -impl<'tcx> LateLintPass<'tcx> for UnitReturnExpectingOrd { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - if let ExprKind::MethodCall(_, _, ref args, _) = expr.kind { - let arg_indices = get_args_to_check(cx, expr); - for (i, trait_name) in arg_indices { - if i < args.len() { - match check_arg(cx, &args[i]) { - Some((span, None)) => { - span_lint( - cx, - UNIT_RETURN_EXPECTING_ORD, - span, - &format!( - "this closure returns \ - the unit type which also implements {}", - trait_name - ), - ); - }, - Some((span, Some(last_semi))) => { - span_lint_and_help( - cx, - UNIT_RETURN_EXPECTING_ORD, - span, - &format!( - "this closure returns \ - the unit type which also implements {}", - trait_name - ), - Some(last_semi), - &"probably caused by this trailing semicolon".to_string(), - ); - }, - None => {}, - } - } - } - } - } -} diff --git a/clippy_lints/src/unnamed_address.rs b/clippy_lints/src/unnamed_address.rs deleted file mode 100644 index 9582c162e77b..000000000000 --- a/clippy_lints/src/unnamed_address.rs +++ /dev/null @@ -1,131 +0,0 @@ -use crate::utils::{match_def_path, paths, span_lint, span_lint_and_help}; -use if_chain::if_chain; -use rustc_hir::{BinOpKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for comparisons with an address of a function item. - /// - /// **Why is this bad?** Function item address is not guaranteed to be unique and could vary - /// between different code generation units. Furthermore different function items could have - /// the same address after being merged together. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// type F = fn(); - /// fn a() {} - /// let f: F = a; - /// if f == a { - /// // ... - /// } - /// ``` - pub FN_ADDRESS_COMPARISONS, - correctness, - "comparison with an address of a function item" -} - -declare_clippy_lint! { - /// **What it does:** Checks for comparisons with an address of a trait vtable. - /// - /// **Why is this bad?** Comparing trait objects pointers compares an vtable addresses which - /// are not guaranteed to be unique and could vary between different code generation units. - /// Furthermore vtables for different types could have the same address after being merged - /// together. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust,ignore - /// let a: Rc = ... - /// let b: Rc = ... - /// if Rc::ptr_eq(&a, &b) { - /// ... - /// } - /// ``` - pub VTABLE_ADDRESS_COMPARISONS, - correctness, - "comparison with an address of a trait vtable" -} - -declare_lint_pass!(UnnamedAddress => [FN_ADDRESS_COMPARISONS, VTABLE_ADDRESS_COMPARISONS]); - -impl LateLintPass<'_> for UnnamedAddress { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - fn is_comparison(binop: BinOpKind) -> bool { - matches!( - binop, - BinOpKind::Eq | BinOpKind::Lt | BinOpKind::Le | BinOpKind::Ne | BinOpKind::Ge | BinOpKind::Gt - ) - } - - fn is_trait_ptr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - match cx.typeck_results().expr_ty_adjusted(expr).kind() { - ty::RawPtr(ty::TypeAndMut { ty, .. }) => ty.is_trait(), - _ => false, - } - } - - fn is_fn_def(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - matches!(cx.typeck_results().expr_ty(expr).kind(), ty::FnDef(..)) - } - - if_chain! { - if let ExprKind::Binary(binop, ref left, ref right) = expr.kind; - if is_comparison(binop.node); - if is_trait_ptr(cx, left) && is_trait_ptr(cx, right); - then { - span_lint_and_help( - cx, - VTABLE_ADDRESS_COMPARISONS, - expr.span, - "comparing trait object pointers compares a non-unique vtable address", - None, - "consider extracting and comparing data pointers only", - ); - } - } - - if_chain! { - if let ExprKind::Call(ref func, [ref _left, ref _right]) = expr.kind; - if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); - if match_def_path(cx, def_id, &paths::PTR_EQ) || - match_def_path(cx, def_id, &paths::RC_PTR_EQ) || - match_def_path(cx, def_id, &paths::ARC_PTR_EQ); - let ty_param = cx.typeck_results().node_substs(func.hir_id).type_at(0); - if ty_param.is_trait(); - then { - span_lint_and_help( - cx, - VTABLE_ADDRESS_COMPARISONS, - expr.span, - "comparing trait object pointers compares a non-unique vtable address", - None, - "consider extracting and comparing data pointers only", - ); - } - } - - if_chain! { - if let ExprKind::Binary(binop, ref left, ref right) = expr.kind; - if is_comparison(binop.node); - if cx.typeck_results().expr_ty_adjusted(left).is_fn_ptr() && - cx.typeck_results().expr_ty_adjusted(right).is_fn_ptr(); - if is_fn_def(cx, left) || is_fn_def(cx, right); - then { - span_lint( - cx, - FN_ADDRESS_COMPARISONS, - expr.span, - "comparing with a non-unique address of a function item", - ); - } - } - } -} diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs deleted file mode 100644 index 0bccfc156788..000000000000 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ /dev/null @@ -1,274 +0,0 @@ -use crate::utils; -use crate::utils::sugg::Sugg; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, Mutability, Param, Pat, PatKind, Path, PathSegment, QPath}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, subst::GenericArgKind}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; -use rustc_span::symbol::Ident; - -declare_clippy_lint! { - /// **What it does:** - /// Detects uses of `Vec::sort_by` passing in a closure - /// which compares the two arguments, either directly or indirectly. - /// - /// **Why is this bad?** - /// It is more clear to use `Vec::sort_by_key` (or `Vec::sort` if - /// possible) than to use `Vec::sort_by` and a more complicated - /// closure. - /// - /// **Known problems:** - /// If the suggested `Vec::sort_by_key` uses Reverse and it isn't already - /// imported by a use statement, then it will need to be added manually. - /// - /// **Example:** - /// - /// ```rust - /// # struct A; - /// # impl A { fn foo(&self) {} } - /// # let mut vec: Vec = Vec::new(); - /// vec.sort_by(|a, b| a.foo().cmp(&b.foo())); - /// ``` - /// Use instead: - /// ```rust - /// # struct A; - /// # impl A { fn foo(&self) {} } - /// # let mut vec: Vec = Vec::new(); - /// vec.sort_by_key(|a| a.foo()); - /// ``` - pub UNNECESSARY_SORT_BY, - complexity, - "Use of `Vec::sort_by` when `Vec::sort_by_key` or `Vec::sort` would be clearer" -} - -declare_lint_pass!(UnnecessarySortBy => [UNNECESSARY_SORT_BY]); - -enum LintTrigger { - Sort(SortDetection), - SortByKey(SortByKeyDetection), -} - -struct SortDetection { - vec_name: String, - unstable: bool, -} - -struct SortByKeyDetection { - vec_name: String, - closure_arg: String, - closure_body: String, - reverse: bool, - unstable: bool, -} - -/// Detect if the two expressions are mirrored (identical, except one -/// contains a and the other replaces it with b) -fn mirrored_exprs( - cx: &LateContext<'_>, - a_expr: &Expr<'_>, - a_ident: &Ident, - b_expr: &Expr<'_>, - b_ident: &Ident, -) -> bool { - match (&a_expr.kind, &b_expr.kind) { - // Two boxes with mirrored contents - (ExprKind::Box(left_expr), ExprKind::Box(right_expr)) => { - mirrored_exprs(cx, left_expr, a_ident, right_expr, b_ident) - }, - // Two arrays with mirrored contents - (ExprKind::Array(left_exprs), ExprKind::Array(right_exprs)) => left_exprs - .iter() - .zip(right_exprs.iter()) - .all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident)), - // The two exprs are function calls. - // Check to see that the function itself and its arguments are mirrored - (ExprKind::Call(left_expr, left_args), ExprKind::Call(right_expr, right_args)) => { - mirrored_exprs(cx, left_expr, a_ident, right_expr, b_ident) - && left_args - .iter() - .zip(right_args.iter()) - .all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident)) - }, - // The two exprs are method calls. - // Check to see that the function is the same and the arguments are mirrored - // This is enough because the receiver of the method is listed in the arguments - ( - ExprKind::MethodCall(left_segment, _, left_args, _), - ExprKind::MethodCall(right_segment, _, right_args, _), - ) => { - left_segment.ident == right_segment.ident - && left_args - .iter() - .zip(right_args.iter()) - .all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident)) - }, - // Two tuples with mirrored contents - (ExprKind::Tup(left_exprs), ExprKind::Tup(right_exprs)) => left_exprs - .iter() - .zip(right_exprs.iter()) - .all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident)), - // Two binary ops, which are the same operation and which have mirrored arguments - (ExprKind::Binary(left_op, left_left, left_right), ExprKind::Binary(right_op, right_left, right_right)) => { - left_op.node == right_op.node - && mirrored_exprs(cx, left_left, a_ident, right_left, b_ident) - && mirrored_exprs(cx, left_right, a_ident, right_right, b_ident) - }, - // Two unary ops, which are the same operation and which have the same argument - (ExprKind::Unary(left_op, left_expr), ExprKind::Unary(right_op, right_expr)) => { - left_op == right_op && mirrored_exprs(cx, left_expr, a_ident, right_expr, b_ident) - }, - // The two exprs are literals of some kind - (ExprKind::Lit(left_lit), ExprKind::Lit(right_lit)) => left_lit.node == right_lit.node, - (ExprKind::Cast(left, _), ExprKind::Cast(right, _)) => mirrored_exprs(cx, left, a_ident, right, b_ident), - (ExprKind::DropTemps(left_block), ExprKind::DropTemps(right_block)) => { - mirrored_exprs(cx, left_block, a_ident, right_block, b_ident) - }, - (ExprKind::Field(left_expr, left_ident), ExprKind::Field(right_expr, right_ident)) => { - left_ident.name == right_ident.name && mirrored_exprs(cx, left_expr, a_ident, right_expr, right_ident) - }, - // Two paths: either one is a and the other is b, or they're identical to each other - ( - ExprKind::Path(QPath::Resolved( - _, - Path { - segments: left_segments, - .. - }, - )), - ExprKind::Path(QPath::Resolved( - _, - Path { - segments: right_segments, - .. - }, - )), - ) => { - (left_segments - .iter() - .zip(right_segments.iter()) - .all(|(left, right)| left.ident == right.ident) - && left_segments - .iter() - .all(|seg| &seg.ident != a_ident && &seg.ident != b_ident)) - || (left_segments.len() == 1 - && &left_segments[0].ident == a_ident - && right_segments.len() == 1 - && &right_segments[0].ident == b_ident) - }, - // Matching expressions, but one or both is borrowed - ( - ExprKind::AddrOf(left_kind, Mutability::Not, left_expr), - ExprKind::AddrOf(right_kind, Mutability::Not, right_expr), - ) => left_kind == right_kind && mirrored_exprs(cx, left_expr, a_ident, right_expr, b_ident), - (_, ExprKind::AddrOf(_, Mutability::Not, right_expr)) => { - mirrored_exprs(cx, a_expr, a_ident, right_expr, b_ident) - }, - (ExprKind::AddrOf(_, Mutability::Not, left_expr), _) => mirrored_exprs(cx, left_expr, a_ident, b_expr, b_ident), - _ => false, - } -} - -fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { - if_chain! { - if let ExprKind::MethodCall(name_ident, _, args, _) = &expr.kind; - if let name = name_ident.ident.name.to_ident_string(); - if name == "sort_by" || name == "sort_unstable_by"; - if let [vec, Expr { kind: ExprKind::Closure(_, _, closure_body_id, _, _), .. }] = args; - if utils::is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(vec), sym::vec_type); - if let closure_body = cx.tcx.hir().body(*closure_body_id); - if let &[ - Param { pat: Pat { kind: PatKind::Binding(_, _, left_ident, _), .. }, ..}, - Param { pat: Pat { kind: PatKind::Binding(_, _, right_ident, _), .. }, .. } - ] = &closure_body.params; - if let ExprKind::MethodCall(method_path, _, [ref left_expr, ref right_expr], _) = &closure_body.value.kind; - if method_path.ident.name.to_ident_string() == "cmp"; - then { - let (closure_body, closure_arg, reverse) = if mirrored_exprs( - &cx, - &left_expr, - &left_ident, - &right_expr, - &right_ident - ) { - (Sugg::hir(cx, &left_expr, "..").to_string(), left_ident.name.to_string(), false) - } else if mirrored_exprs(&cx, &left_expr, &right_ident, &right_expr, &left_ident) { - (Sugg::hir(cx, &left_expr, "..").to_string(), right_ident.name.to_string(), true) - } else { - return None; - }; - let vec_name = Sugg::hir(cx, &args[0], "..").to_string(); - let unstable = name == "sort_unstable_by"; - - if let ExprKind::Path(QPath::Resolved(_, Path { - segments: [PathSegment { ident: left_name, .. }], .. - })) = &left_expr.kind { - if left_name == left_ident { - return Some(LintTrigger::Sort(SortDetection { vec_name, unstable })); - } - } - - if !expr_borrows(cx, left_expr) { - return Some(LintTrigger::SortByKey(SortByKeyDetection { - vec_name, - unstable, - closure_arg, - closure_body, - reverse - })); - } - } - } - - None -} - -fn expr_borrows(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - let ty = cx.typeck_results().expr_ty(expr); - matches!(ty.kind(), ty::Ref(..)) || ty.walk().any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_))) -} - -impl LateLintPass<'_> for UnnecessarySortBy { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - match detect_lint(cx, expr) { - Some(LintTrigger::SortByKey(trigger)) => utils::span_lint_and_sugg( - cx, - UNNECESSARY_SORT_BY, - expr.span, - "use Vec::sort_by_key here instead", - "try", - format!( - "{}.sort{}_by_key(|{}| {})", - trigger.vec_name, - if trigger.unstable { "_unstable" } else { "" }, - trigger.closure_arg, - if trigger.reverse { - format!("Reverse({})", trigger.closure_body) - } else { - trigger.closure_body.to_string() - }, - ), - if trigger.reverse { - Applicability::MaybeIncorrect - } else { - Applicability::MachineApplicable - }, - ), - Some(LintTrigger::Sort(trigger)) => utils::span_lint_and_sugg( - cx, - UNNECESSARY_SORT_BY, - expr.span, - "use Vec::sort here instead", - "try", - format!( - "{}.sort{}()", - trigger.vec_name, - if trigger.unstable { "_unstable" } else { "" }, - ), - Applicability::MachineApplicable, - ), - None => {}, - } - } -} diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs deleted file mode 100644 index 5b9a80f92db6..000000000000 --- a/clippy_lints/src/unnecessary_wraps.rs +++ /dev/null @@ -1,148 +0,0 @@ -use crate::utils::{ - contains_return, in_macro, is_type_diagnostic_item, match_qpath, paths, return_ty, snippet, span_lint_and_then, - visitors::find_all_ret_expressions, -}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::intravisit::FnKind; -use rustc_hir::{Body, ExprKind, FnDecl, HirId, ItemKind, Node}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::subst::GenericArgKind; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::symbol::sym; -use rustc_span::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for private functions that only return `Ok` or `Some`. - /// - /// **Why is this bad?** It is not meaningful to wrap values when no `None` or `Err` is returned. - /// - /// **Known problems:** Since this lint changes function type signature, you may need to - /// adjust some code at callee side. - /// - /// **Example:** - /// - /// ```rust - /// fn get_cool_number(a: bool, b: bool) -> Option { - /// if a && b { - /// return Some(50); - /// } - /// if a { - /// Some(0) - /// } else { - /// Some(10) - /// } - /// } - /// ``` - /// Use instead: - /// ```rust - /// fn get_cool_number(a: bool, b: bool) -> i32 { - /// if a && b { - /// return 50; - /// } - /// if a { - /// 0 - /// } else { - /// 10 - /// } - /// } - /// ``` - pub UNNECESSARY_WRAPS, - complexity, - "functions that only return `Ok` or `Some`" -} - -declare_lint_pass!(UnnecessaryWraps => [UNNECESSARY_WRAPS]); - -impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - fn_kind: FnKind<'tcx>, - fn_decl: &FnDecl<'tcx>, - body: &Body<'tcx>, - span: Span, - hir_id: HirId, - ) { - match fn_kind { - FnKind::ItemFn(.., visibility, _) | FnKind::Method(.., Some(visibility), _) => { - if visibility.node.is_pub() { - return; - } - }, - FnKind::Closure(..) => return, - _ => (), - } - - if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { - if matches!( - item.kind, - ItemKind::Impl { of_trait: Some(_), .. } | ItemKind::Trait(..) - ) { - return; - } - } - - let (return_type, path) = if is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::option_type) { - ("Option", &paths::OPTION_SOME) - } else if is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::result_type) { - ("Result", &paths::RESULT_OK) - } else { - return; - }; - - let mut suggs = Vec::new(); - let can_sugg = find_all_ret_expressions(cx, &body.value, |ret_expr| { - if_chain! { - if !in_macro(ret_expr.span); - if let ExprKind::Call(ref func, ref args) = ret_expr.kind; - if let ExprKind::Path(ref qpath) = func.kind; - if match_qpath(qpath, path); - if args.len() == 1; - if !contains_return(&args[0]); - then { - suggs.push((ret_expr.span, snippet(cx, args[0].span.source_callsite(), "..").to_string())); - true - } else { - false - } - } - }); - - if can_sugg && !suggs.is_empty() { - span_lint_and_then( - cx, - UNNECESSARY_WRAPS, - span, - format!( - "this function's return value is unnecessarily wrapped by `{}`", - return_type - ) - .as_str(), - |diag| { - let inner_ty = return_ty(cx, hir_id) - .walk() - .skip(1) // skip `std::option::Option` or `std::result::Result` - .take(1) // take the first outermost inner type - .filter_map(|inner| match inner.unpack() { - GenericArgKind::Type(inner_ty) => Some(inner_ty.to_string()), - _ => None, - }); - inner_ty.for_each(|inner_ty| { - diag.span_suggestion( - fn_decl.output.span(), - format!("remove `{}` from the return type...", return_type).as_str(), - inner_ty, - Applicability::MaybeIncorrect, - ); - }); - diag.multipart_suggestion( - "...and change the returning expressions", - suggs, - Applicability::MaybeIncorrect, - ); - }, - ); - } - } -} diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs deleted file mode 100644 index 7f4f16f8faf9..000000000000 --- a/clippy_lints/src/unnested_or_patterns.rs +++ /dev/null @@ -1,408 +0,0 @@ -#![allow(clippy::wildcard_imports, clippy::enum_glob_use)] - -use crate::utils::ast_utils::{eq_field_pat, eq_id, eq_pat, eq_path}; -use crate::utils::{over, span_lint_and_then}; -use rustc_ast::mut_visit::*; -use rustc_ast::ptr::P; -use rustc_ast::{self as ast, Pat, PatKind, PatKind::*, DUMMY_NODE_ID}; -use rustc_ast_pretty::pprust; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::DUMMY_SP; - -use std::cell::Cell; -use std::mem; - -declare_clippy_lint! { - /// **What it does:** - /// - /// Checks for unnested or-patterns, e.g., `Some(0) | Some(2)` and - /// suggests replacing the pattern with a nested one, `Some(0 | 2)`. - /// - /// Another way to think of this is that it rewrites patterns in - /// *disjunctive normal form (DNF)* into *conjunctive normal form (CNF)*. - /// - /// **Why is this bad?** - /// - /// In the example above, `Some` is repeated, which unncessarily complicates the pattern. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// fn main() { - /// if let Some(0) | Some(2) = Some(0) {} - /// } - /// ``` - /// Use instead: - /// ```rust - /// #![feature(or_patterns)] - /// - /// fn main() { - /// if let Some(0 | 2) = Some(0) {} - /// } - /// ``` - pub UNNESTED_OR_PATTERNS, - pedantic, - "unnested or-patterns, e.g., `Foo(Bar) | Foo(Baz) instead of `Foo(Bar | Baz)`" -} - -declare_lint_pass!(UnnestedOrPatterns => [UNNESTED_OR_PATTERNS]); - -impl EarlyLintPass for UnnestedOrPatterns { - fn check_arm(&mut self, cx: &EarlyContext<'_>, a: &ast::Arm) { - lint_unnested_or_patterns(cx, &a.pat); - } - - fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) { - if let ast::ExprKind::Let(pat, _) = &e.kind { - lint_unnested_or_patterns(cx, pat); - } - } - - fn check_param(&mut self, cx: &EarlyContext<'_>, p: &ast::Param) { - lint_unnested_or_patterns(cx, &p.pat); - } - - fn check_local(&mut self, cx: &EarlyContext<'_>, l: &ast::Local) { - lint_unnested_or_patterns(cx, &l.pat); - } -} - -fn lint_unnested_or_patterns(cx: &EarlyContext<'_>, pat: &Pat) { - if !cx.sess.features_untracked().or_patterns { - // Do not suggest nesting the patterns if the feature `or_patterns` is not enabled. - return; - } - - if let Ident(.., None) | Lit(_) | Wild | Path(..) | Range(..) | Rest | MacCall(_) = pat.kind { - // This is a leaf pattern, so cloning is unprofitable. - return; - } - - let mut pat = P(pat.clone()); - - // Nix all the paren patterns everywhere so that they aren't in our way. - remove_all_parens(&mut pat); - - // Transform all unnested or-patterns into nested ones, and if there were none, quit. - if !unnest_or_patterns(&mut pat) { - return; - } - - span_lint_and_then(cx, UNNESTED_OR_PATTERNS, pat.span, "unnested or-patterns", |db| { - insert_necessary_parens(&mut pat); - db.span_suggestion_verbose( - pat.span, - "nest the patterns", - pprust::pat_to_string(&pat), - Applicability::MachineApplicable, - ); - }); -} - -/// Remove all `(p)` patterns in `pat`. -fn remove_all_parens(pat: &mut P) { - struct Visitor; - impl MutVisitor for Visitor { - fn visit_pat(&mut self, pat: &mut P) { - noop_visit_pat(pat, self); - let inner = match &mut pat.kind { - Paren(i) => mem::replace(&mut i.kind, Wild), - _ => return, - }; - pat.kind = inner; - } - } - Visitor.visit_pat(pat); -} - -/// Insert parens where necessary according to Rust's precedence rules for patterns. -fn insert_necessary_parens(pat: &mut P) { - struct Visitor; - impl MutVisitor for Visitor { - fn visit_pat(&mut self, pat: &mut P) { - use ast::{BindingMode::*, Mutability::*}; - noop_visit_pat(pat, self); - let target = match &mut pat.kind { - // `i @ a | b`, `box a | b`, and `& mut? a | b`. - Ident(.., Some(p)) | Box(p) | Ref(p, _) if matches!(&p.kind, Or(ps) if ps.len() > 1) => p, - Ref(p, Not) if matches!(p.kind, Ident(ByValue(Mut), ..)) => p, // `&(mut x)` - _ => return, - }; - target.kind = Paren(P(take_pat(target))); - } - } - Visitor.visit_pat(pat); -} - -/// Unnest or-patterns `p0 | ... | p1` in the pattern `pat`. -/// For example, this would transform `Some(0) | FOO | Some(2)` into `Some(0 | 2) | FOO`. -fn unnest_or_patterns(pat: &mut P) -> bool { - struct Visitor { - changed: bool, - } - impl MutVisitor for Visitor { - fn visit_pat(&mut self, p: &mut P) { - // This is a bottom up transformation, so recurse first. - noop_visit_pat(p, self); - - // Don't have an or-pattern? Just quit early on. - let alternatives = match &mut p.kind { - Or(ps) => ps, - _ => return, - }; - - // Collapse or-patterns directly nested in or-patterns. - let mut idx = 0; - let mut this_level_changed = false; - while idx < alternatives.len() { - let inner = if let Or(ps) = &mut alternatives[idx].kind { - mem::take(ps) - } else { - idx += 1; - continue; - }; - this_level_changed = true; - alternatives.splice(idx..=idx, inner); - } - - // Focus on `p_n` and then try to transform all `p_i` where `i > n`. - let mut focus_idx = 0; - while focus_idx < alternatives.len() { - this_level_changed |= transform_with_focus_on_idx(alternatives, focus_idx); - focus_idx += 1; - } - self.changed |= this_level_changed; - - // Deal with `Some(Some(0)) | Some(Some(1))`. - if this_level_changed { - noop_visit_pat(p, self); - } - } - } - - let mut visitor = Visitor { changed: false }; - visitor.visit_pat(pat); - visitor.changed -} - -/// Match `$scrutinee` against `$pat` and extract `$then` from it. -/// Panics if there is no match. -macro_rules! always_pat { - ($scrutinee:expr, $pat:pat => $then:expr) => { - match $scrutinee { - $pat => $then, - _ => unreachable!(), - } - }; -} - -/// Focus on `focus_idx` in `alternatives`, -/// attempting to extend it with elements of the same constructor `C` -/// in `alternatives[focus_idx + 1..]`. -fn transform_with_focus_on_idx(alternatives: &mut Vec>, focus_idx: usize) -> bool { - // Extract the kind; we'll need to make some changes in it. - let mut focus_kind = mem::replace(&mut alternatives[focus_idx].kind, PatKind::Wild); - // We'll focus on `alternatives[focus_idx]`, - // so we're draining from `alternatives[focus_idx + 1..]`. - let start = focus_idx + 1; - - // We're trying to find whatever kind (~"constructor") we found in `alternatives[start..]`. - let changed = match &mut focus_kind { - // These pattern forms are "leafs" and do not have sub-patterns. - // Therefore they are not some form of constructor `C`, - // with which a pattern `C(p_0)` may be formed, - // which we would want to join with other `C(p_j)`s. - Ident(.., None) | Lit(_) | Wild | Path(..) | Range(..) | Rest | MacCall(_) - // Dealt with elsewhere. - | Or(_) | Paren(_) => false, - // Transform `box x | ... | box y` into `box (x | y)`. - // - // The cases below until `Slice(...)` deal with *singleton* products. - // These patterns have the shape `C(p)`, and not e.g., `C(p0, ..., pn)`. - Box(target) => extend_with_matching( - target, start, alternatives, - |k| matches!(k, Box(_)), - |k| always_pat!(k, Box(p) => p), - ), - // Transform `&m x | ... | &m y` into `&m (x | y)`. - Ref(target, m1) => extend_with_matching( - target, start, alternatives, - |k| matches!(k, Ref(_, m2) if m1 == m2), // Mutabilities must match. - |k| always_pat!(k, Ref(p, _) => p), - ), - // Transform `b @ p0 | ... b @ p1` into `b @ (p0 | p1)`. - Ident(b1, i1, Some(target)) => extend_with_matching( - target, start, alternatives, - // Binding names must match. - |k| matches!(k, Ident(b2, i2, Some(_)) if b1 == b2 && eq_id(*i1, *i2)), - |k| always_pat!(k, Ident(_, _, Some(p)) => p), - ), - // Transform `[pre, x, post] | ... | [pre, y, post]` into `[pre, x | y, post]`. - Slice(ps1) => extend_with_matching_product( - ps1, start, alternatives, - |k, ps1, idx| matches!(k, Slice(ps2) if eq_pre_post(ps1, ps2, idx)), - |k| always_pat!(k, Slice(ps) => ps), - ), - // Transform `(pre, x, post) | ... | (pre, y, post)` into `(pre, x | y, post)`. - Tuple(ps1) => extend_with_matching_product( - ps1, start, alternatives, - |k, ps1, idx| matches!(k, Tuple(ps2) if eq_pre_post(ps1, ps2, idx)), - |k| always_pat!(k, Tuple(ps) => ps), - ), - // Transform `S(pre, x, post) | ... | S(pre, y, post)` into `S(pre, x | y, post)`. - TupleStruct(path1, ps1) => extend_with_matching_product( - ps1, start, alternatives, - |k, ps1, idx| matches!( - k, - TupleStruct(path2, ps2) if eq_path(path1, path2) && eq_pre_post(ps1, ps2, idx) - ), - |k| always_pat!(k, TupleStruct(_, ps) => ps), - ), - // Transform a record pattern `S { fp_0, ..., fp_n }`. - Struct(path1, fps1, rest1) => extend_with_struct_pat(path1, fps1, *rest1, start, alternatives), - }; - - alternatives[focus_idx].kind = focus_kind; - changed -} - -/// Here we focusing on a record pattern `S { fp_0, ..., fp_n }`. -/// In particular, for a record pattern, the order in which the field patterns is irrelevant. -/// So when we fixate on some `ident_k: pat_k`, we try to find `ident_k` in the other pattern -/// and check that all `fp_i` where `i ∈ ((0...n) \ k)` between two patterns are equal. -fn extend_with_struct_pat( - path1: &ast::Path, - fps1: &mut Vec, - rest1: bool, - start: usize, - alternatives: &mut Vec>, -) -> bool { - (0..fps1.len()).any(|idx| { - let pos_in_2 = Cell::new(None); // The element `k`. - let tail_or = drain_matching( - start, - alternatives, - |k| { - matches!(k, Struct(path2, fps2, rest2) - if rest1 == *rest2 // If one struct pattern has `..` so must the other. - && eq_path(path1, path2) - && fps1.len() == fps2.len() - && fps1.iter().enumerate().all(|(idx_1, fp1)| { - if idx_1 == idx { - // In the case of `k`, we merely require identical field names - // so that we will transform into `ident_k: p1_k | p2_k`. - let pos = fps2.iter().position(|fp2| eq_id(fp1.ident, fp2.ident)); - pos_in_2.set(pos); - pos.is_some() - } else { - fps2.iter().any(|fp2| eq_field_pat(fp1, fp2)) - } - })) - }, - // Extract `p2_k`. - |k| always_pat!(k, Struct(_, mut fps, _) => fps.swap_remove(pos_in_2.take().unwrap()).pat), - ); - extend_with_tail_or(&mut fps1[idx].pat, tail_or) - }) -} - -/// Like `extend_with_matching` but for products with > 1 factor, e.g., `C(p_0, ..., p_n)`. -/// Here, the idea is that we fixate on some `p_k` in `C`, -/// allowing it to vary between two `targets` and `ps2` (returned by `extract`), -/// while also requiring `ps1[..n] ~ ps2[..n]` (pre) and `ps1[n + 1..] ~ ps2[n + 1..]` (post), -/// where `~` denotes semantic equality. -fn extend_with_matching_product( - targets: &mut Vec>, - start: usize, - alternatives: &mut Vec>, - predicate: impl Fn(&PatKind, &[P], usize) -> bool, - extract: impl Fn(PatKind) -> Vec>, -) -> bool { - (0..targets.len()).any(|idx| { - let tail_or = drain_matching( - start, - alternatives, - |k| predicate(k, targets, idx), - |k| extract(k).swap_remove(idx), - ); - extend_with_tail_or(&mut targets[idx], tail_or) - }) -} - -/// Extract the pattern from the given one and replace it with `Wild`. -/// This is meant for temporarily swapping out the pattern for manipulation. -fn take_pat(from: &mut Pat) -> Pat { - let dummy = Pat { - id: DUMMY_NODE_ID, - kind: Wild, - span: DUMMY_SP, - tokens: None, - }; - mem::replace(from, dummy) -} - -/// Extend `target` as an or-pattern with the alternatives -/// in `tail_or` if there are any and return if there were. -fn extend_with_tail_or(target: &mut Pat, tail_or: Vec>) -> bool { - fn extend(target: &mut Pat, mut tail_or: Vec>) { - match target { - // On an existing or-pattern in the target, append to it. - Pat { kind: Or(ps), .. } => ps.append(&mut tail_or), - // Otherwise convert the target to an or-pattern. - target => { - let mut init_or = vec![P(take_pat(target))]; - init_or.append(&mut tail_or); - target.kind = Or(init_or); - }, - } - } - - let changed = !tail_or.is_empty(); - if changed { - // Extend the target. - extend(target, tail_or); - } - changed -} - -// Extract all inner patterns in `alternatives` matching our `predicate`. -// Only elements beginning with `start` are considered for extraction. -fn drain_matching( - start: usize, - alternatives: &mut Vec>, - predicate: impl Fn(&PatKind) -> bool, - extract: impl Fn(PatKind) -> P, -) -> Vec> { - let mut tail_or = vec![]; - let mut idx = 0; - for pat in alternatives.drain_filter(|p| { - // Check if we should extract, but only if `idx >= start`. - idx += 1; - idx > start && predicate(&p.kind) - }) { - tail_or.push(extract(pat.into_inner().kind)); - } - tail_or -} - -fn extend_with_matching( - target: &mut Pat, - start: usize, - alternatives: &mut Vec>, - predicate: impl Fn(&PatKind) -> bool, - extract: impl Fn(PatKind) -> P, -) -> bool { - extend_with_tail_or(target, drain_matching(start, alternatives, predicate, extract)) -} - -/// Are the patterns in `ps1` and `ps2` equal save for `ps1[idx]` compared to `ps2[idx]`? -fn eq_pre_post(ps1: &[P], ps2: &[P], idx: usize) -> bool { - ps1.len() == ps2.len() - && ps1[idx].is_rest() == ps2[idx].is_rest() // Avoid `[x, ..] | [x, 0]` => `[x, .. | 0]`. - && over(&ps1[..idx], &ps2[..idx], |l, r| eq_pat(l, r)) - && over(&ps1[idx + 1..], &ps2[idx + 1..], |l, r| eq_pat(l, r)) -} diff --git a/clippy_lints/src/unsafe_removed_from_name.rs b/clippy_lints/src/unsafe_removed_from_name.rs deleted file mode 100644 index 154082a0fdb5..000000000000 --- a/clippy_lints/src/unsafe_removed_from_name.rs +++ /dev/null @@ -1,78 +0,0 @@ -use crate::utils::span_lint; -use rustc_ast::ast::{Item, ItemKind, UseTree, UseTreeKind}; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::symbol::Ident; - -declare_clippy_lint! { - /// **What it does:** Checks for imports that remove "unsafe" from an item's - /// name. - /// - /// **Why is this bad?** Renaming makes it less clear which traits and - /// structures are unsafe. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// use std::cell::{UnsafeCell as TotallySafeCell}; - /// - /// extern crate crossbeam; - /// use crossbeam::{spawn_unsafe as spawn}; - /// ``` - pub UNSAFE_REMOVED_FROM_NAME, - style, - "`unsafe` removed from API names on import" -} - -declare_lint_pass!(UnsafeNameRemoval => [UNSAFE_REMOVED_FROM_NAME]); - -impl EarlyLintPass for UnsafeNameRemoval { - fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { - if let ItemKind::Use(ref use_tree) = item.kind { - check_use_tree(use_tree, cx, item.span); - } - } -} - -fn check_use_tree(use_tree: &UseTree, cx: &EarlyContext<'_>, span: Span) { - match use_tree.kind { - UseTreeKind::Simple(Some(new_name), ..) => { - let old_name = use_tree - .prefix - .segments - .last() - .expect("use paths cannot be empty") - .ident; - unsafe_to_safe_check(old_name, new_name, cx, span); - }, - UseTreeKind::Simple(None, ..) | UseTreeKind::Glob => {}, - UseTreeKind::Nested(ref nested_use_tree) => { - for &(ref use_tree, _) in nested_use_tree { - check_use_tree(use_tree, cx, span); - } - }, - } -} - -fn unsafe_to_safe_check(old_name: Ident, new_name: Ident, cx: &EarlyContext<'_>, span: Span) { - let old_str = old_name.name.as_str(); - let new_str = new_name.name.as_str(); - if contains_unsafe(&old_str) && !contains_unsafe(&new_str) { - span_lint( - cx, - UNSAFE_REMOVED_FROM_NAME, - span, - &format!( - "removed `unsafe` from the name of `{}` in use as `{}`", - old_str, new_str - ), - ); - } -} - -#[must_use] -fn contains_unsafe(name: &str) -> bool { - name.contains("Unsafe") || name.contains("unsafe") -} diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs deleted file mode 100644 index 43166d26787a..000000000000 --- a/clippy_lints/src/unused_io_amount.rs +++ /dev/null @@ -1,92 +0,0 @@ -use crate::utils::{is_try, match_trait_method, paths, span_lint}; -use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for unused written/read amount. - /// - /// **Why is this bad?** `io::Write::write(_vectored)` and - /// `io::Read::read(_vectored)` are not guaranteed to - /// process the entire buffer. They return how many bytes were processed, which - /// might be smaller - /// than a given buffer's length. If you don't need to deal with - /// partial-write/read, use - /// `write_all`/`read_exact` instead. - /// - /// **Known problems:** Detects only common patterns. - /// - /// **Example:** - /// ```rust,ignore - /// use std::io; - /// fn foo(w: &mut W) -> io::Result<()> { - /// // must be `w.write_all(b"foo")?;` - /// w.write(b"foo")?; - /// Ok(()) - /// } - /// ``` - pub UNUSED_IO_AMOUNT, - correctness, - "unused written/read amount" -} - -declare_lint_pass!(UnusedIoAmount => [UNUSED_IO_AMOUNT]); - -impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount { - fn check_stmt(&mut self, cx: &LateContext<'_>, s: &hir::Stmt<'_>) { - let expr = match s.kind { - hir::StmtKind::Semi(ref expr) | hir::StmtKind::Expr(ref expr) => &**expr, - _ => return, - }; - - match expr.kind { - hir::ExprKind::Match(ref res, _, _) if is_try(expr).is_some() => { - if let hir::ExprKind::Call(ref func, ref args) = res.kind { - if matches!( - func.kind, - hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::TryIntoResult, _)) - ) { - check_method_call(cx, &args[0], expr); - } - } else { - check_method_call(cx, res, expr); - } - }, - - hir::ExprKind::MethodCall(ref path, _, ref args, _) => match &*path.ident.as_str() { - "expect" | "unwrap" | "unwrap_or" | "unwrap_or_else" => { - check_method_call(cx, &args[0], expr); - }, - _ => (), - }, - - _ => (), - } - } -} - -fn check_method_call(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) { - if let hir::ExprKind::MethodCall(ref path, _, _, _) = call.kind { - let symbol = &*path.ident.as_str(); - let read_trait = match_trait_method(cx, call, &paths::IO_READ); - let write_trait = match_trait_method(cx, call, &paths::IO_WRITE); - - match (read_trait, write_trait, symbol) { - (true, _, "read") => span_lint( - cx, - UNUSED_IO_AMOUNT, - expr.span, - "read amount is not handled. Use `Read::read_exact` instead", - ), - (true, _, "read_vectored") => span_lint(cx, UNUSED_IO_AMOUNT, expr.span, "read amount is not handled"), - (_, true, "write") => span_lint( - cx, - UNUSED_IO_AMOUNT, - expr.span, - "written amount is not handled. Use `Write::write_all` instead", - ), - (_, true, "write_vectored") => span_lint(cx, UNUSED_IO_AMOUNT, expr.span, "written amount is not handled"), - _ => (), - } - } -} diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs deleted file mode 100644 index da7517125c13..000000000000 --- a/clippy_lints/src/unused_self.rs +++ /dev/null @@ -1,105 +0,0 @@ -use if_chain::if_chain; -use rustc_hir::def::Res; -use rustc_hir::intravisit::{walk_path, NestedVisitorMap, Visitor}; -use rustc_hir::{HirId, ImplItem, ImplItemKind, ItemKind, Path}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -use crate::utils::span_lint_and_help; - -declare_clippy_lint! { - /// **What it does:** Checks methods that contain a `self` argument but don't use it - /// - /// **Why is this bad?** It may be clearer to define the method as an associated function instead - /// of an instance method if it doesn't require `self`. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,ignore - /// struct A; - /// impl A { - /// fn method(&self) {} - /// } - /// ``` - /// - /// Could be written: - /// - /// ```rust,ignore - /// struct A; - /// impl A { - /// fn method() {} - /// } - /// ``` - pub UNUSED_SELF, - pedantic, - "methods that contain a `self` argument but don't use it" -} - -declare_lint_pass!(UnusedSelf => [UNUSED_SELF]); - -impl<'tcx> LateLintPass<'tcx> for UnusedSelf { - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &ImplItem<'_>) { - if impl_item.span.from_expansion() { - return; - } - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id); - let parent_item = cx.tcx.hir().expect_item(parent); - let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); - let assoc_item = cx.tcx.associated_item(def_id); - if_chain! { - if let ItemKind::Impl { of_trait: None, .. } = parent_item.kind; - if assoc_item.fn_has_self_parameter; - if let ImplItemKind::Fn(.., body_id) = &impl_item.kind; - let body = cx.tcx.hir().body(*body_id); - if !body.params.is_empty(); - then { - let self_param = &body.params[0]; - let self_hir_id = self_param.pat.hir_id; - let mut visitor = UnusedSelfVisitor { - cx, - uses_self: false, - self_hir_id: &self_hir_id, - }; - visitor.visit_body(body); - if !visitor.uses_self { - span_lint_and_help( - cx, - UNUSED_SELF, - self_param.span, - "unused `self` argument", - None, - "consider refactoring to a associated function", - ); - return; - } - } - } - } -} - -struct UnusedSelfVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - uses_self: bool, - self_hir_id: &'a HirId, -} - -impl<'a, 'tcx> Visitor<'tcx> for UnusedSelfVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) { - if self.uses_self { - // This function already uses `self` - return; - } - if let Res::Local(hir_id) = &path.res { - self.uses_self = self.self_hir_id == hir_id - } - walk_path(self, path); - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) - } -} diff --git a/clippy_lints/src/unused_unit.rs b/clippy_lints/src/unused_unit.rs deleted file mode 100644 index f61fd2ecd735..000000000000 --- a/clippy_lints/src/unused_unit.rs +++ /dev/null @@ -1,142 +0,0 @@ -use if_chain::if_chain; -use rustc_ast::ast; -use rustc_ast::visit::FnKind; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::BytePos; - -use crate::utils::{position_before_rarrow, span_lint_and_sugg}; - -declare_clippy_lint! { - /// **What it does:** Checks for unit (`()`) expressions that can be removed. - /// - /// **Why is this bad?** Such expressions add no value, but can make the code - /// less readable. Depending on formatting they can make a `break` or `return` - /// statement look like a function call. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust - /// fn return_unit() -> () { - /// () - /// } - /// ``` - pub UNUSED_UNIT, - style, - "needless unit expression" -} - -declare_lint_pass!(UnusedUnit => [UNUSED_UNIT]); - -impl EarlyLintPass for UnusedUnit { - fn check_fn(&mut self, cx: &EarlyContext<'_>, kind: FnKind<'_>, span: Span, _: ast::NodeId) { - if_chain! { - if let ast::FnRetTy::Ty(ref ty) = kind.decl().output; - if let ast::TyKind::Tup(ref vals) = ty.kind; - if vals.is_empty() && !ty.span.from_expansion() && get_def(span) == get_def(ty.span); - then { - lint_unneeded_unit_return(cx, ty, span); - } - } - } - - fn check_block(&mut self, cx: &EarlyContext<'_>, block: &ast::Block) { - if_chain! { - if let Some(ref stmt) = block.stmts.last(); - if let ast::StmtKind::Expr(ref expr) = stmt.kind; - if is_unit_expr(expr) && !stmt.span.from_expansion(); - then { - let sp = expr.span; - span_lint_and_sugg( - cx, - UNUSED_UNIT, - sp, - "unneeded unit expression", - "remove the final `()`", - String::new(), - Applicability::MachineApplicable, - ); - } - } - } - - fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) { - match e.kind { - ast::ExprKind::Ret(Some(ref expr)) | ast::ExprKind::Break(_, Some(ref expr)) => { - if is_unit_expr(expr) && !expr.span.from_expansion() { - span_lint_and_sugg( - cx, - UNUSED_UNIT, - expr.span, - "unneeded `()`", - "remove the `()`", - String::new(), - Applicability::MachineApplicable, - ); - } - }, - _ => (), - } - } - - fn check_poly_trait_ref(&mut self, cx: &EarlyContext<'_>, poly: &ast::PolyTraitRef, _: &ast::TraitBoundModifier) { - let segments = &poly.trait_ref.path.segments; - - if_chain! { - if segments.len() == 1; - if ["Fn", "FnMut", "FnOnce"].contains(&&*segments[0].ident.name.as_str()); - if let Some(args) = &segments[0].args; - if let ast::GenericArgs::Parenthesized(generic_args) = &**args; - if let ast::FnRetTy::Ty(ty) = &generic_args.output; - if ty.kind.is_unit(); - then { - lint_unneeded_unit_return(cx, ty, generic_args.span); - } - } - } -} - -// get the def site -#[must_use] -fn get_def(span: Span) -> Option { - if span.from_expansion() { - Some(span.ctxt().outer_expn_data().def_site) - } else { - None - } -} - -// is this expr a `()` unit? -fn is_unit_expr(expr: &ast::Expr) -> bool { - if let ast::ExprKind::Tup(ref vals) = expr.kind { - vals.is_empty() - } else { - false - } -} - -fn lint_unneeded_unit_return(cx: &EarlyContext<'_>, ty: &ast::Ty, span: Span) { - let (ret_span, appl) = if let Ok(fn_source) = cx.sess().source_map().span_to_snippet(span.with_hi(ty.span.hi())) { - position_before_rarrow(fn_source).map_or((ty.span, Applicability::MaybeIncorrect), |rpos| { - ( - #[allow(clippy::cast_possible_truncation)] - ty.span.with_lo(BytePos(span.lo().0 + rpos as u32)), - Applicability::MachineApplicable, - ) - }) - } else { - (ty.span, Applicability::MaybeIncorrect) - }; - span_lint_and_sugg( - cx, - UNUSED_UNIT, - ret_span, - "unneeded unit return type", - "remove the `-> ()`", - String::new(), - appl, - ); -} diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs deleted file mode 100644 index f4a77e54dd14..000000000000 --- a/clippy_lints/src/unwrap.rs +++ /dev/null @@ -1,234 +0,0 @@ -use crate::utils::{ - differing_macro_contexts, higher::if_block, is_type_diagnostic_item, span_lint_and_then, - usage::is_potentially_mutated, -}; -use if_chain::if_chain; -use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visitor}; -use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, Path, QPath, UnOp}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::Ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** Checks for calls of `unwrap[_err]()` that cannot fail. - /// - /// **Why is this bad?** Using `if let` or `match` is more idiomatic. - /// - /// **Known problems:** None - /// - /// **Example:** - /// ```rust - /// # let option = Some(0); - /// # fn do_something_with(_x: usize) {} - /// if option.is_some() { - /// do_something_with(option.unwrap()) - /// } - /// ``` - /// - /// Could be written: - /// - /// ```rust - /// # let option = Some(0); - /// # fn do_something_with(_x: usize) {} - /// if let Some(value) = option { - /// do_something_with(value) - /// } - /// ``` - pub UNNECESSARY_UNWRAP, - complexity, - "checks for calls of `unwrap[_err]()` that cannot fail" -} - -declare_clippy_lint! { - /// **What it does:** Checks for calls of `unwrap[_err]()` that will always fail. - /// - /// **Why is this bad?** If panicking is desired, an explicit `panic!()` should be used. - /// - /// **Known problems:** This lint only checks `if` conditions not assignments. - /// So something like `let x: Option<()> = None; x.unwrap();` will not be recognized. - /// - /// **Example:** - /// ```rust - /// # let option = Some(0); - /// # fn do_something_with(_x: usize) {} - /// if option.is_none() { - /// do_something_with(option.unwrap()) - /// } - /// ``` - /// - /// This code will always panic. The if condition should probably be inverted. - pub PANICKING_UNWRAP, - correctness, - "checks for calls of `unwrap[_err]()` that will always fail" -} - -/// Visitor that keeps track of which variables are unwrappable. -struct UnwrappableVariablesVisitor<'a, 'tcx> { - unwrappables: Vec>, - cx: &'a LateContext<'tcx>, -} -/// Contains information about whether a variable can be unwrapped. -#[derive(Copy, Clone, Debug)] -struct UnwrapInfo<'tcx> { - /// The variable that is checked - ident: &'tcx Path<'tcx>, - /// The check, like `x.is_ok()` - check: &'tcx Expr<'tcx>, - /// The branch where the check takes place, like `if x.is_ok() { .. }` - branch: &'tcx Expr<'tcx>, - /// Whether `is_some()` or `is_ok()` was called (as opposed to `is_err()` or `is_none()`). - safe_to_unwrap: bool, -} - -/// Collects the information about unwrappable variables from an if condition -/// The `invert` argument tells us whether the condition is negated. -fn collect_unwrap_info<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx Expr<'_>, - branch: &'tcx Expr<'_>, - invert: bool, -) -> Vec> { - fn is_relevant_option_call(cx: &LateContext<'_>, ty: Ty<'_>, method_name: &str) -> bool { - is_type_diagnostic_item(cx, ty, sym::option_type) && ["is_some", "is_none"].contains(&method_name) - } - - fn is_relevant_result_call(cx: &LateContext<'_>, ty: Ty<'_>, method_name: &str) -> bool { - is_type_diagnostic_item(cx, ty, sym::result_type) && ["is_ok", "is_err"].contains(&method_name) - } - - if let ExprKind::Binary(op, left, right) = &expr.kind { - match (invert, op.node) { - (false, BinOpKind::And | BinOpKind::BitAnd) | (true, BinOpKind::Or | BinOpKind::BitOr) => { - let mut unwrap_info = collect_unwrap_info(cx, left, branch, invert); - unwrap_info.append(&mut collect_unwrap_info(cx, right, branch, invert)); - return unwrap_info; - }, - _ => (), - } - } else if let ExprKind::Unary(UnOp::UnNot, expr) = &expr.kind { - return collect_unwrap_info(cx, expr, branch, !invert); - } else { - if_chain! { - if let ExprKind::MethodCall(method_name, _, args, _) = &expr.kind; - if let ExprKind::Path(QPath::Resolved(None, path)) = &args[0].kind; - let ty = cx.typeck_results().expr_ty(&args[0]); - let name = method_name.ident.as_str(); - if is_relevant_option_call(cx, ty, &name) || is_relevant_result_call(cx, ty, &name); - then { - assert!(args.len() == 1); - let unwrappable = match name.as_ref() { - "is_some" | "is_ok" => true, - "is_err" | "is_none" => false, - _ => unreachable!(), - }; - let safe_to_unwrap = unwrappable != invert; - return vec![UnwrapInfo { ident: path, check: expr, branch, safe_to_unwrap }]; - } - } - } - Vec::new() -} - -impl<'a, 'tcx> UnwrappableVariablesVisitor<'a, 'tcx> { - fn visit_branch(&mut self, cond: &'tcx Expr<'_>, branch: &'tcx Expr<'_>, else_branch: bool) { - let prev_len = self.unwrappables.len(); - for unwrap_info in collect_unwrap_info(self.cx, cond, branch, else_branch) { - if is_potentially_mutated(unwrap_info.ident, cond, self.cx) - || is_potentially_mutated(unwrap_info.ident, branch, self.cx) - { - // if the variable is mutated, we don't know whether it can be unwrapped: - continue; - } - self.unwrappables.push(unwrap_info); - } - walk_expr(self, branch); - self.unwrappables.truncate(prev_len); - } -} - -impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - // Shouldn't lint when `expr` is in macro. - if in_external_macro(self.cx.tcx.sess, expr.span) { - return; - } - if let Some((cond, then, els)) = if_block(&expr) { - walk_expr(self, cond); - self.visit_branch(cond, then, false); - if let Some(els) = els { - self.visit_branch(cond, els, true); - } - } else { - // find `unwrap[_err]()` calls: - if_chain! { - if let ExprKind::MethodCall(ref method_name, _, ref args, _) = expr.kind; - if let ExprKind::Path(QPath::Resolved(None, ref path)) = args[0].kind; - if [sym::unwrap, sym!(unwrap_err)].contains(&method_name.ident.name); - let call_to_unwrap = method_name.ident.name == sym::unwrap; - if let Some(unwrappable) = self.unwrappables.iter() - .find(|u| u.ident.res == path.res); - // Span contexts should not differ with the conditional branch - if !differing_macro_contexts(unwrappable.branch.span, expr.span); - if !differing_macro_contexts(unwrappable.branch.span, unwrappable.check.span); - then { - if call_to_unwrap == unwrappable.safe_to_unwrap { - span_lint_and_then( - self.cx, - UNNECESSARY_UNWRAP, - expr.span, - &format!("you checked before that `{}()` cannot fail, \ - instead of checking and unwrapping, it's better to use `if let` or `match`", - method_name.ident.name), - |diag| { diag.span_label(unwrappable.check.span, "the check is happening here"); }, - ); - } else { - span_lint_and_then( - self.cx, - PANICKING_UNWRAP, - expr.span, - &format!("this call to `{}()` will always panic", - method_name.ident.name), - |diag| { diag.span_label(unwrappable.check.span, "because of this check"); }, - ); - } - } - } - walk_expr(self, expr); - } - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) - } -} - -declare_lint_pass!(Unwrap => [PANICKING_UNWRAP, UNNECESSARY_UNWRAP]); - -impl<'tcx> LateLintPass<'tcx> for Unwrap { - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - kind: FnKind<'tcx>, - decl: &'tcx FnDecl<'_>, - body: &'tcx Body<'_>, - span: Span, - fn_id: HirId, - ) { - if span.from_expansion() { - return; - } - - let mut v = UnwrappableVariablesVisitor { - cx, - unwrappables: Vec::new(), - }; - - walk_fn(&mut v, kind, decl, body.id(), span, fn_id); - } -} diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs deleted file mode 100644 index fde310293309..000000000000 --- a/clippy_lints/src/unwrap_in_result.rs +++ /dev/null @@ -1,140 +0,0 @@ -use crate::utils::{is_type_diagnostic_item, method_chain_args, return_ty, span_lint_and_then}; -use if_chain::if_chain; -use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::{sym, Span}; - -declare_clippy_lint! { - /// **What it does:** Checks for functions of type Result that contain `expect()` or `unwrap()` - /// - /// **Why is this bad?** These functions promote recoverable errors to non-recoverable errors which may be undesirable in code bases which wish to avoid panics. - /// - /// **Known problems:** This can cause false positives in functions that handle both recoverable and non recoverable errors. - /// - /// **Example:** - /// Before: - /// ```rust - /// fn divisible_by_3(i_str: String) -> Result<(), String> { - /// let i = i_str - /// .parse::() - /// .expect("cannot divide the input by three"); - /// - /// if i % 3 != 0 { - /// Err("Number is not divisible by 3")? - /// } - /// - /// Ok(()) - /// } - /// ``` - /// - /// After: - /// ```rust - /// fn divisible_by_3(i_str: String) -> Result<(), String> { - /// let i = i_str - /// .parse::() - /// .map_err(|e| format!("cannot divide the input by three: {}", e))?; - /// - /// if i % 3 != 0 { - /// Err("Number is not divisible by 3")? - /// } - /// - /// Ok(()) - /// } - /// ``` - pub UNWRAP_IN_RESULT, - restriction, - "functions of type `Result<..>` or `Option`<...> that contain `expect()` or `unwrap()`" -} - -declare_lint_pass!(UnwrapInResult=> [UNWRAP_IN_RESULT]); - -impl<'tcx> LateLintPass<'tcx> for UnwrapInResult { - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { - if_chain! { - // first check if it's a method or function - if let hir::ImplItemKind::Fn(ref _signature, _) = impl_item.kind; - // checking if its return type is `result` or `option` - if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::result_type) - || is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::option_type); - then { - lint_impl_body(cx, impl_item.span, impl_item); - } - } - } -} - -use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; -use rustc_hir::{Expr, ImplItemKind}; - -struct FindExpectUnwrap<'a, 'tcx> { - lcx: &'a LateContext<'tcx>, - typeck_results: &'tcx ty::TypeckResults<'tcx>, - result: Vec, -} - -impl<'a, 'tcx> Visitor<'tcx> for FindExpectUnwrap<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - // check for `expect` - if let Some(arglists) = method_chain_args(expr, &["expect"]) { - let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); - if is_type_diagnostic_item(self.lcx, reciever_ty, sym::option_type) - || is_type_diagnostic_item(self.lcx, reciever_ty, sym::result_type) - { - self.result.push(expr.span); - } - } - - // check for `unwrap` - if let Some(arglists) = method_chain_args(expr, &["unwrap"]) { - let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); - if is_type_diagnostic_item(self.lcx, reciever_ty, sym::option_type) - || is_type_diagnostic_item(self.lcx, reciever_ty, sym::result_type) - { - self.result.push(expr.span); - } - } - - // and check sub-expressions - intravisit::walk_expr(self, expr); - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_item: &'tcx hir::ImplItem<'_>) { - if_chain! { - - if let ImplItemKind::Fn(_, body_id) = impl_item.kind; - then { - let body = cx.tcx.hir().body(body_id); - let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); - let mut fpu = FindExpectUnwrap { - lcx: cx, - typeck_results: cx.tcx.typeck(impl_item_def_id), - result: Vec::new(), - }; - fpu.visit_expr(&body.value); - - // if we've found one, lint - if !fpu.result.is_empty() { - span_lint_and_then( - cx, - UNWRAP_IN_RESULT, - impl_span, - "used unwrap or expect in a function that returns result or option", - move |diag| { - diag.help( - "unwrap and expect should not be used in a function that returns result or option" ); - diag.span_note(fpu.result, "potential non-recoverable error(s)"); - }); - } - } - } -} diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs deleted file mode 100644 index 3b23f885e08d..000000000000 --- a/clippy_lints/src/use_self.rs +++ /dev/null @@ -1,288 +0,0 @@ -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_hir::def::{DefKind, Res}; -use rustc_hir::intravisit::{walk_item, walk_path, walk_ty, NestedVisitorMap, Visitor}; -use rustc_hir::{ - def, FnDecl, FnRetTy, FnSig, GenericArg, HirId, ImplItem, ImplItemKind, Item, ItemKind, Path, PathSegment, QPath, - TyKind, -}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty; -use rustc_middle::ty::{DefIdTree, Ty}; -use rustc_semver::RustcVersion; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::symbol::kw; -use rustc_typeck::hir_ty_to_ty; - -use crate::utils::{differing_macro_contexts, meets_msrv, span_lint_and_sugg}; - -declare_clippy_lint! { - /// **What it does:** Checks for unnecessary repetition of structure name when a - /// replacement with `Self` is applicable. - /// - /// **Why is this bad?** Unnecessary repetition. Mixed use of `Self` and struct - /// name - /// feels inconsistent. - /// - /// **Known problems:** - /// - False positive when using associated types (#2843) - /// - False positives in some situations when using generics (#3410) - /// - /// **Example:** - /// ```rust - /// struct Foo {} - /// impl Foo { - /// fn new() -> Foo { - /// Foo {} - /// } - /// } - /// ``` - /// could be - /// ```rust - /// struct Foo {} - /// impl Foo { - /// fn new() -> Self { - /// Self {} - /// } - /// } - /// ``` - pub USE_SELF, - nursery, - "unnecessary structure name repetition whereas `Self` is applicable" -} - -impl_lint_pass!(UseSelf => [USE_SELF]); - -const SEGMENTS_MSG: &str = "segments should be composed of at least 1 element"; - -fn span_use_self_lint(cx: &LateContext<'_>, path: &Path<'_>, last_segment: Option<&PathSegment<'_>>) { - let last_segment = last_segment.unwrap_or_else(|| path.segments.last().expect(SEGMENTS_MSG)); - - // Path segments only include actual path, no methods or fields. - let last_path_span = last_segment.ident.span; - - if differing_macro_contexts(path.span, last_path_span) { - return; - } - - // Only take path up to the end of last_path_span. - let span = path.span.with_hi(last_path_span.hi()); - - span_lint_and_sugg( - cx, - USE_SELF, - span, - "unnecessary structure name repetition", - "use the applicable keyword", - "Self".to_owned(), - Applicability::MachineApplicable, - ); -} - -// FIXME: always use this (more correct) visitor, not just in method signatures. -struct SemanticUseSelfVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - self_ty: Ty<'tcx>, -} - -impl<'a, 'tcx> Visitor<'tcx> for SemanticUseSelfVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'_>) { - if let TyKind::Path(QPath::Resolved(_, path)) = &hir_ty.kind { - match path.res { - def::Res::SelfTy(..) => {}, - _ => { - if hir_ty_to_ty(self.cx.tcx, hir_ty) == self.self_ty { - span_use_self_lint(self.cx, path, None); - } - }, - } - } - - walk_ty(self, hir_ty) - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - -fn check_trait_method_impl_decl<'tcx>( - cx: &LateContext<'tcx>, - impl_item: &ImplItem<'_>, - impl_decl: &'tcx FnDecl<'_>, - impl_trait_ref: ty::TraitRef<'tcx>, -) { - let trait_method = cx - .tcx - .associated_items(impl_trait_ref.def_id) - .find_by_name_and_kind(cx.tcx, impl_item.ident, ty::AssocKind::Fn, impl_trait_ref.def_id) - .expect("impl method matches a trait method"); - - let trait_method_sig = cx.tcx.fn_sig(trait_method.def_id); - let trait_method_sig = cx.tcx.erase_late_bound_regions(trait_method_sig); - - let output_hir_ty = if let FnRetTy::Return(ty) = &impl_decl.output { - Some(&**ty) - } else { - None - }; - - // `impl_hir_ty` (of type `hir::Ty`) represents the type written in the signature. - // `trait_ty` (of type `ty::Ty`) is the semantic type for the signature in the trait. - // We use `impl_hir_ty` to see if the type was written as `Self`, - // `hir_ty_to_ty(...)` to check semantic types of paths, and - // `trait_ty` to determine which parts of the signature in the trait, mention - // the type being implemented verbatim (as opposed to `Self`). - for (impl_hir_ty, trait_ty) in impl_decl - .inputs - .iter() - .chain(output_hir_ty) - .zip(trait_method_sig.inputs_and_output) - { - // Check if the input/output type in the trait method specifies the implemented - // type verbatim, and only suggest `Self` if that isn't the case. - // This avoids suggestions to e.g. replace `Vec` with `Vec`, - // in an `impl Trait for u8`, when the trait always uses `Vec`. - // See also https://github.com/rust-lang/rust-clippy/issues/2894. - let self_ty = impl_trait_ref.self_ty(); - if !trait_ty.walk().any(|inner| inner == self_ty.into()) { - let mut visitor = SemanticUseSelfVisitor { cx, self_ty }; - - visitor.visit_ty(&impl_hir_ty); - } - } -} - -const USE_SELF_MSRV: RustcVersion = RustcVersion::new(1, 37, 0); - -pub struct UseSelf { - msrv: Option, -} - -impl UseSelf { - #[must_use] - pub fn new(msrv: Option) -> Self { - Self { msrv } - } -} - -impl<'tcx> LateLintPass<'tcx> for UseSelf { - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if !meets_msrv(self.msrv.as_ref(), &USE_SELF_MSRV) { - return; - } - - if in_external_macro(cx.sess(), item.span) { - return; - } - if_chain! { - if let ItemKind::Impl{ self_ty: ref item_type, items: refs, .. } = item.kind; - if let TyKind::Path(QPath::Resolved(_, ref item_path)) = item_type.kind; - then { - let parameters = &item_path.segments.last().expect(SEGMENTS_MSG).args; - let should_check = parameters.as_ref().map_or( - true, - |params| !params.parenthesized - &&!params.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_))) - ); - - if should_check { - let visitor = &mut UseSelfVisitor { - item_path, - cx, - }; - let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id); - let impl_trait_ref = cx.tcx.impl_trait_ref(impl_def_id); - - if let Some(impl_trait_ref) = impl_trait_ref { - for impl_item_ref in refs { - let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id); - if let ImplItemKind::Fn(FnSig{ decl: impl_decl, .. }, impl_body_id) - = &impl_item.kind { - check_trait_method_impl_decl(cx, impl_item, impl_decl, impl_trait_ref); - - let body = cx.tcx.hir().body(*impl_body_id); - visitor.visit_body(body); - } else { - visitor.visit_impl_item(impl_item); - } - } - } else { - for impl_item_ref in refs { - let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id); - visitor.visit_impl_item(impl_item); - } - } - } - } - } - } - extract_msrv_attr!(LateContext); -} - -struct UseSelfVisitor<'a, 'tcx> { - item_path: &'a Path<'a>, - cx: &'a LateContext<'tcx>, -} - -impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) { - if !path.segments.iter().any(|p| p.ident.span.is_dummy()) { - if path.segments.len() >= 2 { - let last_but_one = &path.segments[path.segments.len() - 2]; - if last_but_one.ident.name != kw::SelfUpper { - let enum_def_id = match path.res { - Res::Def(DefKind::Variant, variant_def_id) => self.cx.tcx.parent(variant_def_id), - Res::Def(DefKind::Ctor(def::CtorOf::Variant, _), ctor_def_id) => { - let variant_def_id = self.cx.tcx.parent(ctor_def_id); - variant_def_id.and_then(|def_id| self.cx.tcx.parent(def_id)) - }, - _ => None, - }; - - if self.item_path.res.opt_def_id() == enum_def_id { - span_use_self_lint(self.cx, path, Some(last_but_one)); - } - } - } - - if path.segments.last().expect(SEGMENTS_MSG).ident.name != kw::SelfUpper { - if self.item_path.res == path.res { - span_use_self_lint(self.cx, path, None); - } else if let Res::Def(DefKind::Ctor(def::CtorOf::Struct, _), ctor_def_id) = path.res { - if self.item_path.res.opt_def_id() == self.cx.tcx.parent(ctor_def_id) { - span_use_self_lint(self.cx, path, None); - } - } - } - } - - walk_path(self, path); - } - - fn visit_item(&mut self, item: &'tcx Item<'_>) { - match item.kind { - ItemKind::Use(..) - | ItemKind::Static(..) - | ItemKind::Enum(..) - | ItemKind::Struct(..) - | ItemKind::Union(..) - | ItemKind::Impl { .. } - | ItemKind::Fn(..) => { - // Don't check statements that shadow `Self` or where `Self` can't be used - }, - _ => walk_item(self, item), - } - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::All(self.cx.tcx.hir()) - } -} diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs deleted file mode 100644 index efa9c3fab4ab..000000000000 --- a/clippy_lints/src/useless_conversion.rs +++ /dev/null @@ -1,190 +0,0 @@ -use crate::utils::sugg::Sugg; -use crate::utils::{ - get_parent_expr, is_type_diagnostic_item, match_def_path, match_trait_method, paths, snippet, - snippet_with_macro_callsite, span_lint_and_help, span_lint_and_sugg, -}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, HirId, MatchSource}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, TyS}; -use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::sym; - -declare_clippy_lint! { - /// **What it does:** Checks for `Into`, `TryInto`, `From`, `TryFrom`, or `IntoIter` calls - /// which uselessly convert to the same type. - /// - /// **Why is this bad?** Redundant code. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// - /// ```rust - /// // Bad - /// // format!() returns a `String` - /// let s: String = format!("hello").into(); - /// - /// // Good - /// let s: String = format!("hello"); - /// ``` - pub USELESS_CONVERSION, - complexity, - "calls to `Into`, `TryInto`, `From`, `TryFrom`, or `IntoIter` which perform useless conversions to the same type" -} - -#[derive(Default)] -pub struct UselessConversion { - try_desugar_arm: Vec, -} - -impl_lint_pass!(UselessConversion => [USELESS_CONVERSION]); - -#[allow(clippy::too_many_lines)] -impl<'tcx> LateLintPass<'tcx> for UselessConversion { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if e.span.from_expansion() { - return; - } - - if Some(&e.hir_id) == self.try_desugar_arm.last() { - return; - } - - match e.kind { - ExprKind::Match(_, ref arms, MatchSource::TryDesugar) => { - let e = match arms[0].body.kind { - ExprKind::Ret(Some(ref e)) | ExprKind::Break(_, Some(ref e)) => e, - _ => return, - }; - if let ExprKind::Call(_, ref args) = e.kind { - self.try_desugar_arm.push(args[0].hir_id); - } - }, - - ExprKind::MethodCall(ref name, .., ref args, _) => { - if match_trait_method(cx, e, &paths::INTO) && &*name.ident.as_str() == "into" { - let a = cx.typeck_results().expr_ty(e); - let b = cx.typeck_results().expr_ty(&args[0]); - if TyS::same_type(a, b) { - let sugg = snippet_with_macro_callsite(cx, args[0].span, "").to_string(); - span_lint_and_sugg( - cx, - USELESS_CONVERSION, - e.span, - &format!("useless conversion to the same type: `{}`", b), - "consider removing `.into()`", - sugg, - Applicability::MachineApplicable, // snippet - ); - } - } - if match_trait_method(cx, e, &paths::INTO_ITERATOR) && &*name.ident.as_str() == "into_iter" { - if let Some(parent_expr) = get_parent_expr(cx, e) { - if let ExprKind::MethodCall(ref parent_name, ..) = parent_expr.kind { - if &*parent_name.ident.as_str() != "into_iter" { - return; - } - } - } - let a = cx.typeck_results().expr_ty(e); - let b = cx.typeck_results().expr_ty(&args[0]); - if TyS::same_type(a, b) { - let sugg = snippet(cx, args[0].span, "").into_owned(); - span_lint_and_sugg( - cx, - USELESS_CONVERSION, - e.span, - &format!("useless conversion to the same type: `{}`", b), - "consider removing `.into_iter()`", - sugg, - Applicability::MachineApplicable, // snippet - ); - } - } - if match_trait_method(cx, e, &paths::TRY_INTO_TRAIT) && &*name.ident.as_str() == "try_into" { - if_chain! { - let a = cx.typeck_results().expr_ty(e); - let b = cx.typeck_results().expr_ty(&args[0]); - if is_type_diagnostic_item(cx, a, sym::result_type); - if let ty::Adt(_, substs) = a.kind(); - if let Some(a_type) = substs.types().next(); - if TyS::same_type(a_type, b); - - then { - span_lint_and_help( - cx, - USELESS_CONVERSION, - e.span, - &format!("useless conversion to the same type: `{}`", b), - None, - "consider removing `.try_into()`", - ); - } - } - } - }, - - ExprKind::Call(ref path, ref args) => { - if_chain! { - if args.len() == 1; - if let ExprKind::Path(ref qpath) = path.kind; - if let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id(); - let a = cx.typeck_results().expr_ty(e); - let b = cx.typeck_results().expr_ty(&args[0]); - - then { - if_chain! { - if match_def_path(cx, def_id, &paths::TRY_FROM); - if is_type_diagnostic_item(cx, a, sym::result_type); - if let ty::Adt(_, substs) = a.kind(); - if let Some(a_type) = substs.types().next(); - if TyS::same_type(a_type, b); - - then { - let hint = format!("consider removing `{}()`", snippet(cx, path.span, "TryFrom::try_from")); - span_lint_and_help( - cx, - USELESS_CONVERSION, - e.span, - &format!("useless conversion to the same type: `{}`", b), - None, - &hint, - ); - } - } - - if_chain! { - if match_def_path(cx, def_id, &paths::FROM_FROM); - if TyS::same_type(a, b); - - then { - let sugg = Sugg::hir_with_macro_callsite(cx, &args[0], "").maybe_par(); - let sugg_msg = - format!("consider removing `{}()`", snippet(cx, path.span, "From::from")); - span_lint_and_sugg( - cx, - USELESS_CONVERSION, - e.span, - &format!("useless conversion to the same type: `{}`", b), - &sugg_msg, - sugg.to_string(), - Applicability::MachineApplicable, // snippet - ); - } - } - } - } - }, - - _ => {}, - } - } - - fn check_expr_post(&mut self, _: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if Some(&e.hir_id) == self.try_desugar_arm.last() { - self.try_desugar_arm.pop(); - } - } -} diff --git a/clippy_lints/src/utils/ast_utils.rs b/clippy_lints/src/utils/ast_utils.rs deleted file mode 100644 index f0267e4c7928..000000000000 --- a/clippy_lints/src/utils/ast_utils.rs +++ /dev/null @@ -1,547 +0,0 @@ -//! Utilities for manipulating and extracting information from `rustc_ast::ast`. -//! -//! - The `eq_foobar` functions test for semantic equality but ignores `NodeId`s and `Span`s. - -#![allow(clippy::similar_names, clippy::wildcard_imports, clippy::enum_glob_use)] - -use crate::utils::{both, over}; -use rustc_ast::ptr::P; -use rustc_ast::{self as ast, *}; -use rustc_span::symbol::Ident; -use std::mem; - -pub mod ident_iter; -pub use ident_iter::IdentIter; - -pub fn is_useless_with_eq_exprs(kind: BinOpKind) -> bool { - use BinOpKind::*; - matches!( - kind, - Sub | Div | Eq | Lt | Le | Gt | Ge | Ne | And | Or | BitXor | BitAnd | BitOr - ) -} - -/// Checks if each element in the first slice is contained within the latter as per `eq_fn`. -pub fn unordered_over(left: &[X], right: &[X], mut eq_fn: impl FnMut(&X, &X) -> bool) -> bool { - left.len() == right.len() && left.iter().all(|l| right.iter().any(|r| eq_fn(l, r))) -} - -pub fn eq_id(l: Ident, r: Ident) -> bool { - l.name == r.name -} - -pub fn eq_pat(l: &Pat, r: &Pat) -> bool { - use PatKind::*; - match (&l.kind, &r.kind) { - (Paren(l), _) => eq_pat(l, r), - (_, Paren(r)) => eq_pat(l, r), - (Wild, Wild) | (Rest, Rest) => true, - (Lit(l), Lit(r)) => eq_expr(l, r), - (Ident(b1, i1, s1), Ident(b2, i2, s2)) => b1 == b2 && eq_id(*i1, *i2) && both(s1, s2, |l, r| eq_pat(l, r)), - (Range(lf, lt, le), Range(rf, rt, re)) => { - eq_expr_opt(lf, rf) && eq_expr_opt(lt, rt) && eq_range_end(&le.node, &re.node) - }, - (Box(l), Box(r)) - | (Ref(l, Mutability::Not), Ref(r, Mutability::Not)) - | (Ref(l, Mutability::Mut), Ref(r, Mutability::Mut)) => eq_pat(l, r), - (Tuple(l), Tuple(r)) | (Slice(l), Slice(r)) => over(l, r, |l, r| eq_pat(l, r)), - (Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp), - (TupleStruct(lp, lfs), TupleStruct(rp, rfs)) => eq_path(lp, rp) && over(lfs, rfs, |l, r| eq_pat(l, r)), - (Struct(lp, lfs, lr), Struct(rp, rfs, rr)) => { - lr == rr && eq_path(lp, rp) && unordered_over(lfs, rfs, |lf, rf| eq_field_pat(lf, rf)) - }, - (Or(ls), Or(rs)) => unordered_over(ls, rs, |l, r| eq_pat(l, r)), - (MacCall(l), MacCall(r)) => eq_mac_call(l, r), - _ => false, - } -} - -pub fn eq_range_end(l: &RangeEnd, r: &RangeEnd) -> bool { - match (l, r) { - (RangeEnd::Excluded, RangeEnd::Excluded) => true, - (RangeEnd::Included(l), RangeEnd::Included(r)) => { - matches!(l, RangeSyntax::DotDotEq) == matches!(r, RangeSyntax::DotDotEq) - }, - _ => false, - } -} - -pub fn eq_field_pat(l: &FieldPat, r: &FieldPat) -> bool { - l.is_placeholder == r.is_placeholder - && eq_id(l.ident, r.ident) - && eq_pat(&l.pat, &r.pat) - && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)) -} - -pub fn eq_qself(l: &QSelf, r: &QSelf) -> bool { - l.position == r.position && eq_ty(&l.ty, &r.ty) -} - -pub fn eq_path(l: &Path, r: &Path) -> bool { - over(&l.segments, &r.segments, |l, r| eq_path_seg(l, r)) -} - -pub fn eq_path_seg(l: &PathSegment, r: &PathSegment) -> bool { - eq_id(l.ident, r.ident) && both(&l.args, &r.args, |l, r| eq_generic_args(l, r)) -} - -pub fn eq_generic_args(l: &GenericArgs, r: &GenericArgs) -> bool { - match (l, r) { - (GenericArgs::AngleBracketed(l), GenericArgs::AngleBracketed(r)) => { - over(&l.args, &r.args, |l, r| eq_angle_arg(l, r)) - }, - (GenericArgs::Parenthesized(l), GenericArgs::Parenthesized(r)) => { - over(&l.inputs, &r.inputs, |l, r| eq_ty(l, r)) && eq_fn_ret_ty(&l.output, &r.output) - }, - _ => false, - } -} - -pub fn eq_angle_arg(l: &AngleBracketedArg, r: &AngleBracketedArg) -> bool { - match (l, r) { - (AngleBracketedArg::Arg(l), AngleBracketedArg::Arg(r)) => eq_generic_arg(l, r), - (AngleBracketedArg::Constraint(l), AngleBracketedArg::Constraint(r)) => eq_assoc_constraint(l, r), - _ => false, - } -} - -pub fn eq_generic_arg(l: &GenericArg, r: &GenericArg) -> bool { - match (l, r) { - (GenericArg::Lifetime(l), GenericArg::Lifetime(r)) => eq_id(l.ident, r.ident), - (GenericArg::Type(l), GenericArg::Type(r)) => eq_ty(l, r), - (GenericArg::Const(l), GenericArg::Const(r)) => eq_expr(&l.value, &r.value), - _ => false, - } -} - -pub fn eq_expr_opt(l: &Option>, r: &Option>) -> bool { - both(l, r, |l, r| eq_expr(l, r)) -} - -pub fn eq_struct_rest(l: &StructRest, r: &StructRest) -> bool { - match (l, r) { - (StructRest::Base(lb), StructRest::Base(rb)) => eq_expr(lb, rb), - (StructRest::Rest(_), StructRest::Rest(_)) | (StructRest::None, StructRest::None) => true, - _ => false, - } -} - -pub fn eq_expr(l: &Expr, r: &Expr) -> bool { - use ExprKind::*; - if !over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)) { - return false; - } - match (&l.kind, &r.kind) { - (Paren(l), _) => eq_expr(l, r), - (_, Paren(r)) => eq_expr(l, r), - (Err, Err) => true, - (Box(l), Box(r)) | (Try(l), Try(r)) | (Await(l), Await(r)) => eq_expr(l, r), - (Array(l), Array(r)) | (Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)), - (Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value), - (Call(lc, la), Call(rc, ra)) => eq_expr(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)), - (MethodCall(lc, la, _), MethodCall(rc, ra, _)) => eq_path_seg(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)), - (Binary(lo, ll, lr), Binary(ro, rl, rr)) => lo.node == ro.node && eq_expr(ll, rl) && eq_expr(lr, rr), - (Unary(lo, l), Unary(ro, r)) => mem::discriminant(lo) == mem::discriminant(ro) && eq_expr(l, r), - (Lit(l), Lit(r)) => l.kind == r.kind, - (Cast(l, lt), Cast(r, rt)) | (Type(l, lt), Type(r, rt)) => eq_expr(l, r) && eq_ty(lt, rt), - (Let(lp, le), Let(rp, re)) => eq_pat(lp, rp) && eq_expr(le, re), - (If(lc, lt, le), If(rc, rt, re)) => eq_expr(lc, rc) && eq_block(lt, rt) && eq_expr_opt(le, re), - (While(lc, lt, ll), While(rc, rt, rl)) => eq_label(ll, rl) && eq_expr(lc, rc) && eq_block(lt, rt), - (ForLoop(lp, li, lt, ll), ForLoop(rp, ri, rt, rl)) => { - eq_label(ll, rl) && eq_pat(lp, rp) && eq_expr(li, ri) && eq_block(lt, rt) - }, - (Loop(lt, ll), Loop(rt, rl)) => eq_label(ll, rl) && eq_block(lt, rt), - (Block(lb, ll), Block(rb, rl)) => eq_label(ll, rl) && eq_block(lb, rb), - (TryBlock(l), TryBlock(r)) => eq_block(l, r), - (Yield(l), Yield(r)) | (Ret(l), Ret(r)) => eq_expr_opt(l, r), - (Break(ll, le), Break(rl, re)) => eq_label(ll, rl) && eq_expr_opt(le, re), - (Continue(ll), Continue(rl)) => eq_label(ll, rl), - (Assign(l1, l2, _), Assign(r1, r2, _)) | (Index(l1, l2), Index(r1, r2)) => eq_expr(l1, r1) && eq_expr(l2, r2), - (AssignOp(lo, lp, lv), AssignOp(ro, rp, rv)) => lo.node == ro.node && eq_expr(lp, rp) && eq_expr(lv, rv), - (Field(lp, lf), Field(rp, rf)) => eq_id(*lf, *rf) && eq_expr(lp, rp), - (Match(ls, la), Match(rs, ra)) => eq_expr(ls, rs) && over(la, ra, |l, r| eq_arm(l, r)), - (Closure(lc, la, lm, lf, lb, _), Closure(rc, ra, rm, rf, rb, _)) => { - lc == rc && la.is_async() == ra.is_async() && lm == rm && eq_fn_decl(lf, rf) && eq_expr(lb, rb) - }, - (Async(lc, _, lb), Async(rc, _, rb)) => lc == rc && eq_block(lb, rb), - (Range(lf, lt, ll), Range(rf, rt, rl)) => ll == rl && eq_expr_opt(lf, rf) && eq_expr_opt(lt, rt), - (AddrOf(lbk, lm, le), AddrOf(rbk, rm, re)) => lbk == rbk && lm == rm && eq_expr(le, re), - (Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp), - (MacCall(l), MacCall(r)) => eq_mac_call(l, r), - (Struct(lp, lfs, lb), Struct(rp, rfs, rb)) => { - eq_path(lp, rp) && eq_struct_rest(lb, rb) && unordered_over(lfs, rfs, |l, r| eq_field(l, r)) - }, - _ => false, - } -} - -pub fn eq_field(l: &Field, r: &Field) -> bool { - l.is_placeholder == r.is_placeholder - && eq_id(l.ident, r.ident) - && eq_expr(&l.expr, &r.expr) - && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)) -} - -pub fn eq_arm(l: &Arm, r: &Arm) -> bool { - l.is_placeholder == r.is_placeholder - && eq_pat(&l.pat, &r.pat) - && eq_expr(&l.body, &r.body) - && eq_expr_opt(&l.guard, &r.guard) - && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)) -} - -pub fn eq_label(l: &Option: Sized, -{ - let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); -} - -fn return_str() -> str -where - str: Sized, -{ - *"Sized".to_string().into_boxed_str() -} - -fn use_op(s: String) -> String -where - String: ::std::ops::Neg, -{ - -s -} - -fn use_for() -where - i32: Iterator, -{ - for _ in 2i32 {} -} - -fn main() {} diff --git a/tests/ui/crashes/ice-3969.stderr b/tests/ui/crashes/ice-3969.stderr deleted file mode 100644 index 923db0664a71..000000000000 --- a/tests/ui/crashes/ice-3969.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: trait objects without an explicit `dyn` are deprecated - --> $DIR/ice-3969.rs:25:17 - | -LL | for<'a> Dst: Sized, - | ^^^^^^ help: use `dyn`: `dyn A + 'a` - | - = note: `-D bare-trait-objects` implied by `-D warnings` - -error: trait objects without an explicit `dyn` are deprecated - --> $DIR/ice-3969.rs:27:16 - | -LL | let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); - | ^ help: use `dyn`: `dyn A` - -error: trait objects without an explicit `dyn` are deprecated - --> $DIR/ice-3969.rs:27:57 - | -LL | let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); - | ^ help: use `dyn`: `dyn A` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/crashes/ice-4121.rs b/tests/ui/crashes/ice-4121.rs deleted file mode 100644 index e1a142fdcb67..000000000000 --- a/tests/ui/crashes/ice-4121.rs +++ /dev/null @@ -1,13 +0,0 @@ -use std::mem; - -pub struct Foo(A, B); - -impl Foo { - const HOST_SIZE: usize = mem::size_of::(); - - pub fn crash() -> bool { - Self::HOST_SIZE == 0 - } -} - -fn main() {} diff --git a/tests/ui/crashes/ice-4545.rs b/tests/ui/crashes/ice-4545.rs deleted file mode 100644 index d9c9c2096d97..000000000000 --- a/tests/ui/crashes/ice-4545.rs +++ /dev/null @@ -1,14 +0,0 @@ -fn repro() { - trait Foo { - type Bar; - } - - #[allow(dead_code)] - struct Baz { - field: T::Bar, - } -} - -fn main() { - repro(); -} diff --git a/tests/ui/crashes/ice-4579.rs b/tests/ui/crashes/ice-4579.rs deleted file mode 100644 index 2e7e279f847d..000000000000 --- a/tests/ui/crashes/ice-4579.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![allow(clippy::single_match)] - -use std::ptr; - -fn main() { - match Some(0_usize) { - Some(_) => { - let s = "012345"; - unsafe { ptr::read(s.as_ptr().offset(1) as *const [u8; 5]) }; - }, - _ => (), - }; -} diff --git a/tests/ui/crashes/ice-4671.rs b/tests/ui/crashes/ice-4671.rs deleted file mode 100644 index 64e8e7769412..000000000000 --- a/tests/ui/crashes/ice-4671.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![warn(clippy::use_self)] - -#[macro_use] -#[path = "auxiliary/use_self_macro.rs"] -mod use_self_macro; - -struct Foo { - a: u32, -} - -use_self! { - impl Foo { - fn func(&self) { - [fields( - a - )] - } - } -} - -fn main() {} diff --git a/tests/ui/crashes/ice-4727.rs b/tests/ui/crashes/ice-4727.rs deleted file mode 100644 index 2a4bc83f58a5..000000000000 --- a/tests/ui/crashes/ice-4727.rs +++ /dev/null @@ -1,6 +0,0 @@ -#![warn(clippy::use_self)] - -#[path = "auxiliary/ice-4727-aux.rs"] -mod aux; - -fn main() {} diff --git a/tests/ui/crashes/ice-4760.rs b/tests/ui/crashes/ice-4760.rs deleted file mode 100644 index 08b06961760f..000000000000 --- a/tests/ui/crashes/ice-4760.rs +++ /dev/null @@ -1,9 +0,0 @@ -const COUNT: usize = 2; -struct Thing; -trait Dummy {} - -const _: () = { - impl Dummy for Thing where [i32; COUNT]: Sized {} -}; - -fn main() {} diff --git a/tests/ui/crashes/ice-4775.rs b/tests/ui/crashes/ice-4775.rs deleted file mode 100644 index 31e53e846d54..000000000000 --- a/tests/ui/crashes/ice-4775.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![feature(const_generics)] -#![allow(incomplete_features)] - -pub struct ArrayWrapper([usize; N]); - -impl ArrayWrapper<{ N }> { - pub fn ice(&self) { - for i in self.0.iter() { - println!("{}", i); - } - } -} - -fn main() {} diff --git a/tests/ui/crashes/ice-4968.rs b/tests/ui/crashes/ice-4968.rs deleted file mode 100644 index 3822f1745985..000000000000 --- a/tests/ui/crashes/ice-4968.rs +++ /dev/null @@ -1,20 +0,0 @@ -// check-pass - -// Test for https://github.com/rust-lang/rust-clippy/issues/4968 - -#![warn(clippy::unsound_collection_transmute)] - -trait Trait { - type Assoc; -} - -use std::mem::{self, ManuallyDrop}; - -#[allow(unused)] -fn func(slice: Vec) { - unsafe { - let _: Vec> = mem::transmute(slice); - } -} - -fn main() {} diff --git a/tests/ui/crashes/ice-5207.rs b/tests/ui/crashes/ice-5207.rs deleted file mode 100644 index 1b20c9defac8..000000000000 --- a/tests/ui/crashes/ice-5207.rs +++ /dev/null @@ -1,7 +0,0 @@ -// edition:2018 - -// Regression test for https://github.com/rust-lang/rust-clippy/issues/5207 - -pub async fn bar<'a, T: 'a>(_: T) {} - -fn main() {} diff --git a/tests/ui/crashes/ice-5223.rs b/tests/ui/crashes/ice-5223.rs deleted file mode 100644 index 9bb2e227fc12..000000000000 --- a/tests/ui/crashes/ice-5223.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Regression test for #5233 - -#![feature(const_generics)] -#![allow(incomplete_features)] -#![warn(clippy::indexing_slicing, clippy::iter_cloned_collect)] - -pub struct KotomineArray { - arr: [T; N], -} - -impl KotomineArray { - pub fn ice(self) { - let _ = self.arr[..]; - let _ = self.arr.iter().cloned().collect::>(); - } -} - -fn main() {} diff --git a/tests/ui/crashes/ice-5238.rs b/tests/ui/crashes/ice-5238.rs deleted file mode 100644 index 989eb6d44855..000000000000 --- a/tests/ui/crashes/ice-5238.rs +++ /dev/null @@ -1,9 +0,0 @@ -// Regression test for #5238 / https://github.com/rust-lang/rust/pull/69562 - -#![feature(generators, generator_trait)] - -fn main() { - let _ = || { - yield; - }; -} diff --git a/tests/ui/crashes/ice-5389.rs b/tests/ui/crashes/ice-5389.rs deleted file mode 100644 index de262199004b..000000000000 --- a/tests/ui/crashes/ice-5389.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![allow(clippy::explicit_counter_loop)] - -fn main() { - let v = vec![1, 2, 3]; - let mut i = 0; - let max_storage_size = [0; 128 * 1024]; - for item in &v { - bar(i, *item); - i += 1; - } -} - -fn bar(_: usize, _: u32) {} diff --git a/tests/ui/crashes/ice-5497.rs b/tests/ui/crashes/ice-5497.rs deleted file mode 100644 index 0769bce5fc80..000000000000 --- a/tests/ui/crashes/ice-5497.rs +++ /dev/null @@ -1,11 +0,0 @@ -// reduced from rustc issue-69020-assoc-const-arith-overflow.rs -pub fn main() {} - -pub trait Foo { - const OOB: i32; -} - -impl Foo for Vec { - const OOB: i32 = [1][1] + T::OOB; - //~^ ERROR operation will panic -} diff --git a/tests/ui/crashes/ice-5579.rs b/tests/ui/crashes/ice-5579.rs deleted file mode 100644 index e1842c73f0e3..000000000000 --- a/tests/ui/crashes/ice-5579.rs +++ /dev/null @@ -1,17 +0,0 @@ -trait IsErr { - fn is_err(&self, err: &str) -> bool; -} - -impl IsErr for Option { - fn is_err(&self, _err: &str) -> bool { - true - } -} - -fn main() { - let t = Some(1); - - if t.is_err("") { - t.unwrap(); - } -} diff --git a/tests/ui/crashes/ice-5872.rs b/tests/ui/crashes/ice-5872.rs deleted file mode 100644 index 68afa8f8c3a8..000000000000 --- a/tests/ui/crashes/ice-5872.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![warn(clippy::needless_collect)] - -fn main() { - let _ = vec![1, 2, 3].into_iter().collect::>().is_empty(); -} diff --git a/tests/ui/crashes/ice-5872.stderr b/tests/ui/crashes/ice-5872.stderr deleted file mode 100644 index a60ca345cf78..000000000000 --- a/tests/ui/crashes/ice-5872.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: avoid using `collect()` when not needed - --> $DIR/ice-5872.rs:4:39 - | -LL | let _ = vec![1, 2, 3].into_iter().collect::>().is_empty(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` - | - = note: `-D clippy::needless-collect` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/crashes/ice-5944.rs b/tests/ui/crashes/ice-5944.rs deleted file mode 100644 index 5caf29c61973..000000000000 --- a/tests/ui/crashes/ice-5944.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![warn(clippy::repeat_once)] - -trait Repeat { - fn repeat(&self) {} -} - -impl Repeat for usize { - fn repeat(&self) {} -} - -fn main() { - let _ = 42.repeat(); -} diff --git a/tests/ui/crashes/ice-6139.rs b/tests/ui/crashes/ice-6139.rs deleted file mode 100644 index f3966e47f5e8..000000000000 --- a/tests/ui/crashes/ice-6139.rs +++ /dev/null @@ -1,7 +0,0 @@ -trait T<'a> {} - -fn foo(_: Vec>>) {} - -fn main() { - foo(vec![]); -} diff --git a/tests/ui/crashes/ice-6153.rs b/tests/ui/crashes/ice-6153.rs deleted file mode 100644 index 9f73f39f10d7..000000000000 --- a/tests/ui/crashes/ice-6153.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub struct S<'a, 'e>(&'a str, &'e str); - -pub type T<'a, 'e> = std::collections::HashMap, ()>; - -impl<'e, 'a: 'e> S<'a, 'e> { - pub fn foo(_a: &str, _b: &str, _map: &T) {} -} - -fn main() {} diff --git a/tests/ui/crashes/ice-6250.rs b/tests/ui/crashes/ice-6250.rs deleted file mode 100644 index c33580ff6ab6..000000000000 --- a/tests/ui/crashes/ice-6250.rs +++ /dev/null @@ -1,16 +0,0 @@ -// originally from glacier/fixed/77218.rs -// ice while adjusting... - -pub struct Cache { - data: Vec, -} - -pub fn list_data(cache: &Cache, key: usize) { - for reference in vec![1, 2, 3] { - if - /* let */ - Some(reference) = cache.data.get(key) { - unimplemented!() - } - } -} diff --git a/tests/ui/crashes/ice-6250.stderr b/tests/ui/crashes/ice-6250.stderr deleted file mode 100644 index c38727316cd4..000000000000 --- a/tests/ui/crashes/ice-6250.stderr +++ /dev/null @@ -1,42 +0,0 @@ -error[E0658]: destructuring assignments are unstable - --> $DIR/ice-6250.rs:12:25 - | -LL | Some(reference) = cache.data.get(key) { - | --------------- ^ - | | - | cannot assign to this expression - | - = note: see issue #71126 for more information - = help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable - -error[E0601]: `main` function not found in crate `ice_6250` - --> $DIR/ice-6250.rs:4:1 - | -LL | / pub struct Cache { -LL | | data: Vec, -LL | | } -LL | | -... | -LL | | } -LL | | } - | |_^ consider adding a `main` function to `$DIR/ice-6250.rs` - -error[E0308]: mismatched types - --> $DIR/ice-6250.rs:12:14 - | -LL | Some(reference) = cache.data.get(key) { - | ^^^^^^^^^ - | | - | expected integer, found `&i32` - | help: consider dereferencing the borrow: `*reference` - -error[E0308]: mismatched types - --> $DIR/ice-6250.rs:12:9 - | -LL | Some(reference) = cache.data.get(key) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()` - -error: aborting due to 4 previous errors - -Some errors have detailed explanations: E0308, E0601, E0658. -For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/crashes/ice-6251.rs b/tests/ui/crashes/ice-6251.rs deleted file mode 100644 index 6aa779aaeb3b..000000000000 --- a/tests/ui/crashes/ice-6251.rs +++ /dev/null @@ -1,6 +0,0 @@ -// originally from glacier/fixed/77329.rs -// assertion failed: `(left == right) ; different DefIds - -fn bug() -> impl Iterator { - std::iter::empty() -} diff --git a/tests/ui/crashes/ice-6251.stderr b/tests/ui/crashes/ice-6251.stderr deleted file mode 100644 index 9a7cf4b0919f..000000000000 --- a/tests/ui/crashes/ice-6251.stderr +++ /dev/null @@ -1,43 +0,0 @@ -error[E0601]: `main` function not found in crate `ice_6251` - --> $DIR/ice-6251.rs:4:1 - | -LL | / fn bug() -> impl Iterator { -LL | | std::iter::empty() -LL | | } - | |_^ consider adding a `main` function to `$DIR/ice-6251.rs` - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/ice-6251.rs:4:45 - | -LL | fn bug() -> impl Iterator { - | ^ doesn't have a size known at compile-time - | - = help: the trait `std::marker::Sized` is not implemented for `[u8]` - = help: unsized fn params are gated as an unstable feature -help: function arguments must have a statically known size, borrowed types always have a known size - | -LL | fn bug() -> impl Iterator { - | ^ - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/ice-6251.rs:4:54 - | -LL | fn bug() -> impl Iterator { - | ^ doesn't have a size known at compile-time - | - = help: the trait `std::marker::Sized` is not implemented for `[u8]` - = note: the return type of a function must have a statically known size - -error[E0308]: mismatched types - --> $DIR/ice-6251.rs:4:44 - | -LL | fn bug() -> impl Iterator { - | ^^^^^^^^^^^ expected `usize`, found closure - | - = note: expected type `usize` - found closure `[closure@$DIR/ice-6251.rs:4:44: 4:55]` - -error: aborting due to 4 previous errors - -Some errors have detailed explanations: E0277, E0308, E0601. -For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/crashes/ice-6252.rs b/tests/ui/crashes/ice-6252.rs deleted file mode 100644 index 2e3d9fd1e924..000000000000 --- a/tests/ui/crashes/ice-6252.rs +++ /dev/null @@ -1,15 +0,0 @@ -// originally from glacier fixed/77919.rs -// encountered errors resolving bounds after type-checking - -trait TypeVal { - const VAL: T; -} -struct Five; -struct Multiply { - _n: PhantomData, -} -impl TypeVal for Multiply where N: TypeVal {} - -fn main() { - [1; >::VAL]; -} diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr deleted file mode 100644 index eaa5e6f51cb4..000000000000 --- a/tests/ui/crashes/ice-6252.stderr +++ /dev/null @@ -1,32 +0,0 @@ -error[E0412]: cannot find type `PhantomData` in this scope - --> $DIR/ice-6252.rs:9:9 - | -LL | _n: PhantomData, - | ^^^^^^^^^^^ not found in this scope - | -help: consider importing this struct - | -LL | use std::marker::PhantomData; - | - -error[E0412]: cannot find type `VAL` in this scope - --> $DIR/ice-6252.rs:11:63 - | -LL | impl TypeVal for Multiply where N: TypeVal {} - | - ^^^ not found in this scope - | | - | help: you might be missing a type parameter: `, VAL` - -error[E0046]: not all trait items implemented, missing: `VAL` - --> $DIR/ice-6252.rs:11:1 - | -LL | const VAL: T; - | ------------- `VAL` from trait -... -LL | impl TypeVal for Multiply where N: TypeVal {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation - -error: aborting due to 3 previous errors - -Some errors have detailed explanations: E0046, E0412. -For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/crashes/ice-6254.rs b/tests/ui/crashes/ice-6254.rs deleted file mode 100644 index c19eca43884a..000000000000 --- a/tests/ui/crashes/ice-6254.rs +++ /dev/null @@ -1,15 +0,0 @@ -// originally from ./src/test/ui/pattern/usefulness/consts-opaque.rs -// panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', -// compiler/rustc_mir_build/src/thir/pattern/_match.rs:2030:5 - -#[derive(PartialEq)] -struct Foo(i32); -const FOO_REF_REF: &&Foo = &&Foo(42); - -fn main() { - // This used to cause an ICE (https://github.com/rust-lang/rust/issues/78071) - match FOO_REF_REF { - FOO_REF_REF => {}, - Foo(_) => {}, - } -} diff --git a/tests/ui/crashes/ice-6254.stderr b/tests/ui/crashes/ice-6254.stderr deleted file mode 100644 index 95ebf23d8181..000000000000 --- a/tests/ui/crashes/ice-6254.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error: to use a constant of type `Foo` in a pattern, `Foo` must be annotated with `#[derive(PartialEq, Eq)]` - --> $DIR/ice-6254.rs:12:9 - | -LL | FOO_REF_REF => {}, - | ^^^^^^^^^^^ - | - = note: `-D indirect-structural-match` implied by `-D warnings` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #62411 - -error: aborting due to previous error - diff --git a/tests/ui/crashes/ice-6255.rs b/tests/ui/crashes/ice-6255.rs deleted file mode 100644 index bd4a81d98e2e..000000000000 --- a/tests/ui/crashes/ice-6255.rs +++ /dev/null @@ -1,15 +0,0 @@ -// originally from rustc ./src/test/ui/macros/issue-78325-inconsistent-resolution.rs -// inconsistent resolution for a macro - -macro_rules! define_other_core { - ( ) => { - extern crate std as core; - //~^ ERROR macro-expanded `extern crate` items cannot shadow names passed with `--extern` - }; -} - -fn main() { - core::panic!(); -} - -define_other_core!(); diff --git a/tests/ui/crashes/ice-6255.stderr b/tests/ui/crashes/ice-6255.stderr deleted file mode 100644 index d973ea1e23a2..000000000000 --- a/tests/ui/crashes/ice-6255.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error: macro-expanded `extern crate` items cannot shadow names passed with `--extern` - --> $DIR/ice-6255.rs:6:9 - | -LL | extern crate std as core; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | define_other_core!(); - | --------------------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to previous error - diff --git a/tests/ui/crashes/ice-6256.rs b/tests/ui/crashes/ice-6256.rs deleted file mode 100644 index 6f60d45d68a8..000000000000 --- a/tests/ui/crashes/ice-6256.rs +++ /dev/null @@ -1,13 +0,0 @@ -// originally from rustc ./src/test/ui/regions/issue-78262.rs -// ICE: to get the signature of a closure, use substs.as_closure().sig() not fn_sig() - -trait TT {} - -impl dyn TT { - fn func(&self) {} -} - -fn main() { - let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types - //[nll]~^ ERROR: borrowed data escapes outside of closure -} diff --git a/tests/ui/crashes/ice-6256.stderr b/tests/ui/crashes/ice-6256.stderr deleted file mode 100644 index 0e8353a418a8..000000000000 --- a/tests/ui/crashes/ice-6256.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/ice-6256.rs:11:28 - | -LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types - | ^^^^ lifetime mismatch - | - = note: expected reference `&(dyn TT + 'static)` - found reference `&dyn TT` -note: the anonymous lifetime #1 defined on the body at 11:13... - --> $DIR/ice-6256.rs:11:13 - | -LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types - | ^^^^^^^^^^^^^^^^^^^^^ - = note: ...does not necessarily outlive the static lifetime - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/crashes/ice-6332.rs b/tests/ui/crashes/ice-6332.rs deleted file mode 100644 index 9dc92aa500b2..000000000000 --- a/tests/ui/crashes/ice-6332.rs +++ /dev/null @@ -1,11 +0,0 @@ -fn cmark_check() { - let mut link_err = false; - macro_rules! cmark_error { - ($bad:expr) => { - *$bad = true; - }; - } - cmark_error!(&mut link_err); -} - -pub fn main() {} diff --git a/tests/ui/crashes/ice-700.rs b/tests/ui/crashes/ice-700.rs deleted file mode 100644 index 0cbceedbd6bd..000000000000 --- a/tests/ui/crashes/ice-700.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![deny(clippy::all)] - -/// Test for https://github.com/rust-lang/rust-clippy/issues/700 - -fn core() {} - -fn main() { - core(); -} diff --git a/tests/ui/crashes/ice_exacte_size.rs b/tests/ui/crashes/ice_exacte_size.rs deleted file mode 100644 index 30e4b11ec0bd..000000000000 --- a/tests/ui/crashes/ice_exacte_size.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![deny(clippy::all)] - -/// Test for https://github.com/rust-lang/rust-clippy/issues/1336 - -#[allow(dead_code)] -struct Foo; - -impl Iterator for Foo { - type Item = (); - - fn next(&mut self) -> Option<()> { - let _ = self.len() == 0; - unimplemented!() - } -} - -impl ExactSizeIterator for Foo {} - -fn main() {} diff --git a/tests/ui/crashes/if_same_then_else.rs b/tests/ui/crashes/if_same_then_else.rs deleted file mode 100644 index 2f913292995e..000000000000 --- a/tests/ui/crashes/if_same_then_else.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![allow(clippy::comparison_chain)] -#![deny(clippy::if_same_then_else)] - -/// Test for https://github.com/rust-lang/rust-clippy/issues/2426 - -fn main() {} - -pub fn foo(a: i32, b: i32) -> Option<&'static str> { - if a == b { - None - } else if a > b { - Some("a pfeil b") - } else { - None - } -} diff --git a/tests/ui/crashes/implements-trait.rs b/tests/ui/crashes/implements-trait.rs deleted file mode 100644 index 4502b0147a83..000000000000 --- a/tests/ui/crashes/implements-trait.rs +++ /dev/null @@ -1,5 +0,0 @@ -#[allow(clippy::needless_borrowed_reference)] -fn main() { - let mut v = Vec::::new(); - let _ = v.iter_mut().filter(|&ref a| a.is_empty()); -} diff --git a/tests/ui/crashes/inherent_impl.rs b/tests/ui/crashes/inherent_impl.rs deleted file mode 100644 index aeb27b5ba8c2..000000000000 --- a/tests/ui/crashes/inherent_impl.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![deny(clippy::multiple_inherent_impl)] - -/// Test for https://github.com/rust-lang/rust-clippy/issues/4578 - -macro_rules! impl_foo { - ($struct:ident) => { - impl $struct { - fn foo() {} - } - }; -} - -macro_rules! impl_bar { - ($struct:ident) => { - impl $struct { - fn bar() {} - } - }; -} - -struct MyStruct; - -impl_foo!(MyStruct); -impl_bar!(MyStruct); - -fn main() {} diff --git a/tests/ui/crashes/issue-825.rs b/tests/ui/crashes/issue-825.rs deleted file mode 100644 index 05696e3d7d56..000000000000 --- a/tests/ui/crashes/issue-825.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![allow(warnings)] - -/// Test for https://github.com/rust-lang/rust-clippy/issues/825 - -// this should compile in a reasonable amount of time -fn rust_type_id(name: &str) { - if "bool" == &name[..] - || "uint" == &name[..] - || "u8" == &name[..] - || "u16" == &name[..] - || "u32" == &name[..] - || "f32" == &name[..] - || "f64" == &name[..] - || "i8" == &name[..] - || "i16" == &name[..] - || "i32" == &name[..] - || "i64" == &name[..] - || "Self" == &name[..] - || "str" == &name[..] - { - unreachable!(); - } -} - -fn main() {} diff --git a/tests/ui/crashes/issues_loop_mut_cond.rs b/tests/ui/crashes/issues_loop_mut_cond.rs deleted file mode 100644 index bb238c81ebc0..000000000000 --- a/tests/ui/crashes/issues_loop_mut_cond.rs +++ /dev/null @@ -1,28 +0,0 @@ -#![allow(dead_code)] - -/// Issue: https://github.com/rust-lang/rust-clippy/issues/2596 -pub fn loop_on_block_condition(u: &mut isize) { - while { *u < 0 } { - *u += 1; - } -} - -/// https://github.com/rust-lang/rust-clippy/issues/2584 -fn loop_with_unsafe_condition(ptr: *const u8) { - let mut len = 0; - while unsafe { *ptr.offset(len) } != 0 { - len += 1; - } -} - -/// https://github.com/rust-lang/rust-clippy/issues/2710 -static mut RUNNING: bool = true; -fn loop_on_static_condition() { - unsafe { - while RUNNING { - RUNNING = false; - } - } -} - -fn main() {} diff --git a/tests/ui/crashes/match_same_arms_const.rs b/tests/ui/crashes/match_same_arms_const.rs deleted file mode 100644 index 94c939665e61..000000000000 --- a/tests/ui/crashes/match_same_arms_const.rs +++ /dev/null @@ -1,18 +0,0 @@ -#![deny(clippy::match_same_arms)] - -/// Test for https://github.com/rust-lang/rust-clippy/issues/2427 - -const PRICE_OF_SWEETS: u32 = 5; -const PRICE_OF_KINDNESS: u32 = 0; -const PRICE_OF_DRINKS: u32 = 5; - -pub fn price(thing: &str) -> u32 { - match thing { - "rolo" => PRICE_OF_SWEETS, - "advice" => PRICE_OF_KINDNESS, - "juice" => PRICE_OF_DRINKS, - _ => panic!(), - } -} - -fn main() {} diff --git a/tests/ui/crashes/mut_mut_macro.rs b/tests/ui/crashes/mut_mut_macro.rs deleted file mode 100644 index a238e7896fc6..000000000000 --- a/tests/ui/crashes/mut_mut_macro.rs +++ /dev/null @@ -1,34 +0,0 @@ -#![deny(clippy::mut_mut, clippy::zero_ptr, clippy::cmp_nan)] -#![allow(dead_code)] - -// FIXME: compiletest + extern crates doesn't work together. To make this test work, it would need -// the following three lines and the lazy_static crate. -// -// #[macro_use] -// extern crate lazy_static; -// use std::collections::HashMap; - -/// ensure that we don't suggest `is_nan` and `is_null` inside constants -/// FIXME: once const fn is stable, suggest these functions again in constants - -const BAA: *const i32 = 0 as *const i32; -static mut BAR: *const i32 = BAA; -static mut FOO: *const i32 = 0 as *const i32; -static mut BUH: bool = 42.0 < f32::NAN; - -#[allow(unused_variables, unused_mut)] -fn main() { - /* - lazy_static! { - static ref MUT_MAP : HashMap = { - let mut m = HashMap::new(); - m.insert(0, "zero"); - m - }; - static ref MUT_COUNT : usize = MUT_MAP.len(); - } - assert_eq!(*MUT_COUNT, 1); - */ - // FIXME: don't lint in array length, requires `check_body` - //let _ = [""; (42.0 < f32::NAN) as usize]; -} diff --git a/tests/ui/crashes/needless_borrow_fp.rs b/tests/ui/crashes/needless_borrow_fp.rs deleted file mode 100644 index 4f61c76828db..000000000000 --- a/tests/ui/crashes/needless_borrow_fp.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[deny(clippy::all)] -#[derive(Debug)] -pub enum Error { - Type(&'static str), -} - -fn main() {} diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.rs b/tests/ui/crashes/needless_lifetimes_impl_trait.rs deleted file mode 100644 index 676564b2445d..000000000000 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![deny(clippy::needless_lifetimes)] -#![allow(dead_code)] - -trait Foo {} - -struct Bar {} - -struct Baz<'a> { - bar: &'a Bar, -} - -impl<'a> Foo for Baz<'a> {} - -impl Bar { - fn baz<'a>(&'a self) -> impl Foo + 'a { - Baz { bar: self } - } -} - -fn main() {} diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.stderr b/tests/ui/crashes/needless_lifetimes_impl_trait.stderr deleted file mode 100644 index d68bbe788021..000000000000 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes_impl_trait.rs:15:5 - | -LL | fn baz<'a>(&'a self) -> impl Foo + 'a { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/needless_lifetimes_impl_trait.rs:1:9 - | -LL | #![deny(clippy::needless_lifetimes)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/tests/ui/crashes/procedural_macro.rs b/tests/ui/crashes/procedural_macro.rs deleted file mode 100644 index c7468493380c..000000000000 --- a/tests/ui/crashes/procedural_macro.rs +++ /dev/null @@ -1,11 +0,0 @@ -#[macro_use] -extern crate clippy_mini_macro_test; - -#[deny(warnings)] -fn main() { - let x = Foo; - println!("{:?}", x); -} - -#[derive(ClippyMiniMacroTest, Debug)] -struct Foo; diff --git a/tests/ui/crashes/regressions.rs b/tests/ui/crashes/regressions.rs deleted file mode 100644 index a41bcb33b446..000000000000 --- a/tests/ui/crashes/regressions.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![allow(clippy::blacklisted_name)] - -pub fn foo(bar: *const u8) { - println!("{:#p}", bar); -} - -// Regression test for https://github.com/rust-lang/rust-clippy/issues/4917 -/// i32 { - #[cfg(unix)] - return 1; - #[cfg(not(unix))] - return 2; -} - -#[deny(warnings)] -fn cfg_let_and_return() -> i32 { - #[cfg(unix)] - let x = 1; - #[cfg(not(unix))] - let x = 2; - x -} - -fn main() { - cfg_return(); - cfg_let_and_return(); -} diff --git a/tests/ui/crashes/shadow.rs b/tests/ui/crashes/shadow.rs deleted file mode 100644 index 843e8ef64dcd..000000000000 --- a/tests/ui/crashes/shadow.rs +++ /dev/null @@ -1,6 +0,0 @@ -fn main() { - let x: [i32; { - let u = 2; - 4 - }] = [2; { 4 }]; -} diff --git a/tests/ui/crashes/single-match-else.rs b/tests/ui/crashes/single-match-else.rs deleted file mode 100644 index 1ba7ac082132..000000000000 --- a/tests/ui/crashes/single-match-else.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![warn(clippy::single_match_else)] - -//! Test for https://github.com/rust-lang/rust-clippy/issues/1588 - -fn main() { - let n = match (42, 43) { - (42, n) => n, - _ => panic!("typeck error"), - }; - assert_eq!(n, 43); -} diff --git a/tests/ui/crashes/third-party/clippy.toml b/tests/ui/crashes/third-party/clippy.toml deleted file mode 100644 index 9f87de20baff..000000000000 --- a/tests/ui/crashes/third-party/clippy.toml +++ /dev/null @@ -1,3 +0,0 @@ -# this is ignored by Clippy, but allowed for other tools like clippy-service -[third-party] -clippy-feature = "nightly" diff --git a/tests/ui/crashes/third-party/conf_allowlisted.rs b/tests/ui/crashes/third-party/conf_allowlisted.rs deleted file mode 100644 index f328e4d9d04c..000000000000 --- a/tests/ui/crashes/third-party/conf_allowlisted.rs +++ /dev/null @@ -1 +0,0 @@ -fn main() {} diff --git a/tests/ui/crashes/trivial_bounds.rs b/tests/ui/crashes/trivial_bounds.rs deleted file mode 100644 index 60105a8213fe..000000000000 --- a/tests/ui/crashes/trivial_bounds.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![feature(trivial_bounds)] -#![allow(unused, trivial_bounds)] - -fn test_trivial_bounds() -where - i32: Iterator, -{ - for _ in 2i32 {} -} - -fn main() {} diff --git a/tests/ui/crashes/used_underscore_binding_macro.rs b/tests/ui/crashes/used_underscore_binding_macro.rs deleted file mode 100644 index c57a45dc7aab..000000000000 --- a/tests/ui/crashes/used_underscore_binding_macro.rs +++ /dev/null @@ -1,18 +0,0 @@ -// edition:2018 - -use serde::Deserialize; - -/// Tests that we do not lint for unused underscores in a `MacroAttribute` -/// expansion -#[deny(clippy::used_underscore_binding)] -#[derive(Deserialize)] -struct MacroAttributesTest { - _foo: u32, -} - -#[test] -fn macro_attributes_test() { - let _ = MacroAttributesTest { _foo: 0 }; -} - -fn main() {} diff --git a/tests/ui/crate_level_checks/entrypoint_recursion.rs b/tests/ui/crate_level_checks/entrypoint_recursion.rs deleted file mode 100644 index 995787c53366..000000000000 --- a/tests/ui/crate_level_checks/entrypoint_recursion.rs +++ /dev/null @@ -1,12 +0,0 @@ -// ignore-macos -// ignore-windows - -#![feature(main)] - -#[warn(clippy::main_recursion)] -#[allow(unconditional_recursion)] -#[main] -fn a() { - println!("Hello, World!"); - a(); -} diff --git a/tests/ui/crate_level_checks/entrypoint_recursion.stderr b/tests/ui/crate_level_checks/entrypoint_recursion.stderr deleted file mode 100644 index f52fc949f6c3..000000000000 --- a/tests/ui/crate_level_checks/entrypoint_recursion.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: recursing into entrypoint `a` - --> $DIR/entrypoint_recursion.rs:11:5 - | -LL | a(); - | ^ - | - = note: `-D clippy::main-recursion` implied by `-D warnings` - = help: consider using another function for this recursion - -error: aborting due to previous error - diff --git a/tests/ui/crate_level_checks/no_std_main_recursion.rs b/tests/ui/crate_level_checks/no_std_main_recursion.rs deleted file mode 100644 index 25b1417be976..000000000000 --- a/tests/ui/crate_level_checks/no_std_main_recursion.rs +++ /dev/null @@ -1,33 +0,0 @@ -// ignore-macos -// ignore-windows - -#![feature(lang_items, link_args, start, libc)] -#![link_args = "-nostartfiles"] -#![no_std] - -use core::panic::PanicInfo; -use core::sync::atomic::{AtomicUsize, Ordering}; - -static N: AtomicUsize = AtomicUsize::new(0); - -#[warn(clippy::main_recursion)] -#[start] -fn main(argc: isize, argv: *const *const u8) -> isize { - let x = N.load(Ordering::Relaxed); - N.store(x + 1, Ordering::Relaxed); - - if x < 3 { - main(argc, argv); - } - - 0 -} - -#[allow(clippy::empty_loop)] -#[panic_handler] -fn panic(_info: &PanicInfo) -> ! { - loop {} -} - -#[lang = "eh_personality"] -extern "C" fn eh_personality() {} diff --git a/tests/ui/crate_level_checks/std_main_recursion.rs b/tests/ui/crate_level_checks/std_main_recursion.rs deleted file mode 100644 index 89ff6609934d..000000000000 --- a/tests/ui/crate_level_checks/std_main_recursion.rs +++ /dev/null @@ -1,6 +0,0 @@ -#[warn(clippy::main_recursion)] -#[allow(unconditional_recursion)] -fn main() { - println!("Hello, World!"); - main(); -} diff --git a/tests/ui/crate_level_checks/std_main_recursion.stderr b/tests/ui/crate_level_checks/std_main_recursion.stderr deleted file mode 100644 index 0a260f9d2309..000000000000 --- a/tests/ui/crate_level_checks/std_main_recursion.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: recursing into entrypoint `main` - --> $DIR/std_main_recursion.rs:5:5 - | -LL | main(); - | ^^^^ - | - = note: `-D clippy::main-recursion` implied by `-D warnings` - = help: consider using another function for this recursion - -error: aborting due to previous error - diff --git a/tests/ui/create_dir.fixed b/tests/ui/create_dir.fixed deleted file mode 100644 index 8ed53a56ac04..000000000000 --- a/tests/ui/create_dir.fixed +++ /dev/null @@ -1,17 +0,0 @@ -// run-rustfix -#![allow(unused_must_use)] -#![warn(clippy::create_dir)] - -use std::fs::create_dir_all; - -fn create_dir() {} - -fn main() { - // Should be warned - create_dir_all("foo"); - create_dir_all("bar").unwrap(); - - // Shouldn't be warned - create_dir(); - std::fs::create_dir_all("foobar"); -} diff --git a/tests/ui/create_dir.rs b/tests/ui/create_dir.rs deleted file mode 100644 index 19c8fc24ba23..000000000000 --- a/tests/ui/create_dir.rs +++ /dev/null @@ -1,17 +0,0 @@ -// run-rustfix -#![allow(unused_must_use)] -#![warn(clippy::create_dir)] - -use std::fs::create_dir_all; - -fn create_dir() {} - -fn main() { - // Should be warned - std::fs::create_dir("foo"); - std::fs::create_dir("bar").unwrap(); - - // Shouldn't be warned - create_dir(); - std::fs::create_dir_all("foobar"); -} diff --git a/tests/ui/create_dir.stderr b/tests/ui/create_dir.stderr deleted file mode 100644 index 67298fc47095..000000000000 --- a/tests/ui/create_dir.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: calling `std::fs::create_dir` where there may be a better way - --> $DIR/create_dir.rs:11:5 - | -LL | std::fs::create_dir("foo"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `create_dir_all("foo")` - | - = note: `-D clippy::create-dir` implied by `-D warnings` - -error: calling `std::fs::create_dir` where there may be a better way - --> $DIR/create_dir.rs:12:5 - | -LL | std::fs::create_dir("bar").unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `create_dir_all("bar")` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/dbg_macro.rs b/tests/ui/dbg_macro.rs deleted file mode 100644 index d2df7fbd3e84..000000000000 --- a/tests/ui/dbg_macro.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![warn(clippy::dbg_macro)] - -fn foo(n: u32) -> u32 { - if let Some(n) = dbg!(n.checked_sub(4)) { - n - } else { - n - } -} - -fn factorial(n: u32) -> u32 { - if dbg!(n <= 1) { - dbg!(1) - } else { - dbg!(n * factorial(n - 1)) - } -} - -fn main() { - dbg!(42); - dbg!(dbg!(dbg!(42))); - foo(3) + dbg!(factorial(4)); -} diff --git a/tests/ui/dbg_macro.stderr b/tests/ui/dbg_macro.stderr deleted file mode 100644 index b8aafe966784..000000000000 --- a/tests/ui/dbg_macro.stderr +++ /dev/null @@ -1,80 +0,0 @@ -error: `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:4:22 - | -LL | if let Some(n) = dbg!(n.checked_sub(4)) { - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::dbg-macro` implied by `-D warnings` -help: ensure to avoid having uses of it in version control - | -LL | if let Some(n) = n.checked_sub(4) { - | ^^^^^^^^^^^^^^^^ - -error: `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:12:8 - | -LL | if dbg!(n <= 1) { - | ^^^^^^^^^^^^ - | -help: ensure to avoid having uses of it in version control - | -LL | if n <= 1 { - | ^^^^^^ - -error: `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:13:9 - | -LL | dbg!(1) - | ^^^^^^^ - | -help: ensure to avoid having uses of it in version control - | -LL | 1 - | - -error: `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:15:9 - | -LL | dbg!(n * factorial(n - 1)) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: ensure to avoid having uses of it in version control - | -LL | n * factorial(n - 1) - | - -error: `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:20:5 - | -LL | dbg!(42); - | ^^^^^^^^ - | -help: ensure to avoid having uses of it in version control - | -LL | 42; - | ^^ - -error: `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:21:5 - | -LL | dbg!(dbg!(dbg!(42))); - | ^^^^^^^^^^^^^^^^^^^^ - | -help: ensure to avoid having uses of it in version control - | -LL | dbg!(dbg!(42)); - | ^^^^^^^^^^^^^^ - -error: `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:22:14 - | -LL | foo(3) + dbg!(factorial(4)); - | ^^^^^^^^^^^^^^^^^^ - | -help: ensure to avoid having uses of it in version control - | -LL | foo(3) + factorial(4); - | ^^^^^^^^^^^^ - -error: aborting due to 7 previous errors - diff --git a/tests/ui/debug_assert_with_mut_call.rs b/tests/ui/debug_assert_with_mut_call.rs deleted file mode 100644 index 477a47118d41..000000000000 --- a/tests/ui/debug_assert_with_mut_call.rs +++ /dev/null @@ -1,133 +0,0 @@ -// compile-flags: --edition=2018 -#![feature(custom_inner_attributes)] -#![rustfmt::skip] -#![warn(clippy::debug_assert_with_mut_call)] -#![allow(clippy::redundant_closure_call)] - -struct S; - -impl S { - fn bool_self_ref(&self) -> bool { false } - fn bool_self_mut(&mut self) -> bool { false } - fn bool_self_ref_arg_ref(&self, _: &u32) -> bool { false } - fn bool_self_ref_arg_mut(&self, _: &mut u32) -> bool { false } - fn bool_self_mut_arg_ref(&mut self, _: &u32) -> bool { false } - fn bool_self_mut_arg_mut(&mut self, _: &mut u32) -> bool { false } - - fn u32_self_ref(&self) -> u32 { 0 } - fn u32_self_mut(&mut self) -> u32 { 0 } - fn u32_self_ref_arg_ref(&self, _: &u32) -> u32 { 0 } - fn u32_self_ref_arg_mut(&self, _: &mut u32) -> u32 { 0 } - fn u32_self_mut_arg_ref(&mut self, _: &u32) -> u32 { 0 } - fn u32_self_mut_arg_mut(&mut self, _: &mut u32) -> u32 { 0 } -} - -fn bool_ref(_: &u32) -> bool { false } -fn bool_mut(_: &mut u32) -> bool { false } -fn u32_ref(_: &u32) -> u32 { 0 } -fn u32_mut(_: &mut u32) -> u32 { 0 } - -fn func_non_mutable() { - debug_assert!(bool_ref(&3)); - debug_assert!(!bool_ref(&3)); - - debug_assert_eq!(0, u32_ref(&3)); - debug_assert_eq!(u32_ref(&3), 0); - - debug_assert_ne!(1, u32_ref(&3)); - debug_assert_ne!(u32_ref(&3), 1); -} - -fn func_mutable() { - debug_assert!(bool_mut(&mut 3)); - debug_assert!(!bool_mut(&mut 3)); - - debug_assert_eq!(0, u32_mut(&mut 3)); - debug_assert_eq!(u32_mut(&mut 3), 0); - - debug_assert_ne!(1, u32_mut(&mut 3)); - debug_assert_ne!(u32_mut(&mut 3), 1); -} - -fn method_non_mutable() { - debug_assert!(S.bool_self_ref()); - debug_assert!(S.bool_self_ref_arg_ref(&3)); - - debug_assert_eq!(S.u32_self_ref(), 0); - debug_assert_eq!(S.u32_self_ref_arg_ref(&3), 0); - - debug_assert_ne!(S.u32_self_ref(), 1); - debug_assert_ne!(S.u32_self_ref_arg_ref(&3), 1); -} - -fn method_mutable() { - debug_assert!(S.bool_self_mut()); - debug_assert!(!S.bool_self_mut()); - debug_assert!(S.bool_self_ref_arg_mut(&mut 3)); - debug_assert!(S.bool_self_mut_arg_ref(&3)); - debug_assert!(S.bool_self_mut_arg_mut(&mut 3)); - - debug_assert_eq!(S.u32_self_mut(), 0); - debug_assert_eq!(S.u32_self_mut_arg_ref(&3), 0); - debug_assert_eq!(S.u32_self_ref_arg_mut(&mut 3), 0); - debug_assert_eq!(S.u32_self_mut_arg_mut(&mut 3), 0); - - debug_assert_ne!(S.u32_self_mut(), 1); - debug_assert_ne!(S.u32_self_mut_arg_ref(&3), 1); - debug_assert_ne!(S.u32_self_ref_arg_mut(&mut 3), 1); - debug_assert_ne!(S.u32_self_mut_arg_mut(&mut 3), 1); -} - -fn misc() { - // with variable - let mut v: Vec = vec![1, 2, 3, 4]; - debug_assert_eq!(v.get(0), Some(&1)); - debug_assert_ne!(v[0], 2); - debug_assert_eq!(v.pop(), Some(1)); - debug_assert_ne!(Some(3), v.pop()); - - let a = &mut 3; - debug_assert!(bool_mut(a)); - - // nested - debug_assert!(!(bool_ref(&u32_mut(&mut 3)))); - - // chained - debug_assert_eq!(v.pop().unwrap(), 3); - - // format args - debug_assert!(bool_ref(&3), "w/o format"); - debug_assert!(bool_mut(&mut 3), "w/o format"); - debug_assert!(bool_ref(&3), "{} format", "w/"); - debug_assert!(bool_mut(&mut 3), "{} format", "w/"); - - // sub block - let mut x = 42_u32; - debug_assert!({ - bool_mut(&mut x); - x > 10 - }); - - // closures - debug_assert!((|| { - let mut x = 42; - bool_mut(&mut x); - x > 10 - })()); -} - -async fn debug_await() { - debug_assert!(async { - true - }.await); -} - -fn main() { - func_non_mutable(); - func_mutable(); - method_non_mutable(); - method_mutable(); - - misc(); - debug_await(); -} diff --git a/tests/ui/debug_assert_with_mut_call.stderr b/tests/ui/debug_assert_with_mut_call.stderr deleted file mode 100644 index a2ca71b57a6f..000000000000 --- a/tests/ui/debug_assert_with_mut_call.stderr +++ /dev/null @@ -1,172 +0,0 @@ -error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:42:19 - | -LL | debug_assert!(bool_mut(&mut 3)); - | ^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::debug-assert-with-mut-call` implied by `-D warnings` - -error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:43:20 - | -LL | debug_assert!(!bool_mut(&mut 3)); - | ^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:45:25 - | -LL | debug_assert_eq!(0, u32_mut(&mut 3)); - | ^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:46:22 - | -LL | debug_assert_eq!(u32_mut(&mut 3), 0); - | ^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:48:25 - | -LL | debug_assert_ne!(1, u32_mut(&mut 3)); - | ^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:49:22 - | -LL | debug_assert_ne!(u32_mut(&mut 3), 1); - | ^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:64:19 - | -LL | debug_assert!(S.bool_self_mut()); - | ^^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:65:20 - | -LL | debug_assert!(!S.bool_self_mut()); - | ^^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:66:19 - | -LL | debug_assert!(S.bool_self_ref_arg_mut(&mut 3)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:67:19 - | -LL | debug_assert!(S.bool_self_mut_arg_ref(&3)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:68:19 - | -LL | debug_assert!(S.bool_self_mut_arg_mut(&mut 3)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:70:22 - | -LL | debug_assert_eq!(S.u32_self_mut(), 0); - | ^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:71:22 - | -LL | debug_assert_eq!(S.u32_self_mut_arg_ref(&3), 0); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:72:22 - | -LL | debug_assert_eq!(S.u32_self_ref_arg_mut(&mut 3), 0); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:73:22 - | -LL | debug_assert_eq!(S.u32_self_mut_arg_mut(&mut 3), 0); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:75:22 - | -LL | debug_assert_ne!(S.u32_self_mut(), 1); - | ^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:76:22 - | -LL | debug_assert_ne!(S.u32_self_mut_arg_ref(&3), 1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:77:22 - | -LL | debug_assert_ne!(S.u32_self_ref_arg_mut(&mut 3), 1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:78:22 - | -LL | debug_assert_ne!(S.u32_self_mut_arg_mut(&mut 3), 1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:86:22 - | -LL | debug_assert_eq!(v.pop(), Some(1)); - | ^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:87:31 - | -LL | debug_assert_ne!(Some(3), v.pop()); - | ^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:90:19 - | -LL | debug_assert!(bool_mut(a)); - | ^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:93:31 - | -LL | debug_assert!(!(bool_ref(&u32_mut(&mut 3)))); - | ^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:96:22 - | -LL | debug_assert_eq!(v.pop().unwrap(), 3); - | ^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:100:19 - | -LL | debug_assert!(bool_mut(&mut 3), "w/o format"); - | ^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:102:19 - | -LL | debug_assert!(bool_mut(&mut 3), "{} format", "w/"); - | ^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:107:9 - | -LL | bool_mut(&mut x); - | ^^^^^^^^^^^^^^^^ - -error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:114:9 - | -LL | bool_mut(&mut x); - | ^^^^^^^^^^^^^^^^ - -error: aborting due to 28 previous errors - diff --git a/tests/ui/decimal_literal_representation.fixed b/tests/ui/decimal_literal_representation.fixed deleted file mode 100644 index de391465125c..000000000000 --- a/tests/ui/decimal_literal_representation.fixed +++ /dev/null @@ -1,27 +0,0 @@ -// run-rustfix - -#[warn(clippy::decimal_literal_representation)] -#[allow(unused_variables)] -#[rustfmt::skip] -fn main() { - let good = ( // Hex: - 127, // 0x7F - 256, // 0x100 - 511, // 0x1FF - 2048, // 0x800 - 4090, // 0xFFA - 16_371, // 0x3FF3 - 61_683, // 0xF0F3 - 2_131_750_925, // 0x7F0F_F00D - ); - let bad = ( // Hex: - 0x8005, // 0x8005 - 0xFF00, // 0xFF00 - 0x7F0F_F00F, // 0x7F0F_F00F - 0x7FFF_FFFF, // 0x7FFF_FFFF - #[allow(overflowing_literals)] - 0xF0F0_F0F0, // 0xF0F0_F0F0 - 0x8005_usize, // 0x8005_usize - 0x7F0F_F00F_isize, // 0x7F0F_F00F_isize - ); -} diff --git a/tests/ui/decimal_literal_representation.rs b/tests/ui/decimal_literal_representation.rs deleted file mode 100644 index 55d07698e7e5..000000000000 --- a/tests/ui/decimal_literal_representation.rs +++ /dev/null @@ -1,27 +0,0 @@ -// run-rustfix - -#[warn(clippy::decimal_literal_representation)] -#[allow(unused_variables)] -#[rustfmt::skip] -fn main() { - let good = ( // Hex: - 127, // 0x7F - 256, // 0x100 - 511, // 0x1FF - 2048, // 0x800 - 4090, // 0xFFA - 16_371, // 0x3FF3 - 61_683, // 0xF0F3 - 2_131_750_925, // 0x7F0F_F00D - ); - let bad = ( // Hex: - 32_773, // 0x8005 - 65_280, // 0xFF00 - 2_131_750_927, // 0x7F0F_F00F - 2_147_483_647, // 0x7FFF_FFFF - #[allow(overflowing_literals)] - 4_042_322_160, // 0xF0F0_F0F0 - 32_773usize, // 0x8005_usize - 2_131_750_927isize, // 0x7F0F_F00F_isize - ); -} diff --git a/tests/ui/decimal_literal_representation.stderr b/tests/ui/decimal_literal_representation.stderr deleted file mode 100644 index 8d50c8f83db4..000000000000 --- a/tests/ui/decimal_literal_representation.stderr +++ /dev/null @@ -1,46 +0,0 @@ -error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:18:9 - | -LL | 32_773, // 0x8005 - | ^^^^^^ help: consider: `0x8005` - | - = note: `-D clippy::decimal-literal-representation` implied by `-D warnings` - -error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:19:9 - | -LL | 65_280, // 0xFF00 - | ^^^^^^ help: consider: `0xFF00` - -error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:20:9 - | -LL | 2_131_750_927, // 0x7F0F_F00F - | ^^^^^^^^^^^^^ help: consider: `0x7F0F_F00F` - -error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:21:9 - | -LL | 2_147_483_647, // 0x7FFF_FFFF - | ^^^^^^^^^^^^^ help: consider: `0x7FFF_FFFF` - -error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:23:9 - | -LL | 4_042_322_160, // 0xF0F0_F0F0 - | ^^^^^^^^^^^^^ help: consider: `0xF0F0_F0F0` - -error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:24:9 - | -LL | 32_773usize, // 0x8005_usize - | ^^^^^^^^^^^ help: consider: `0x8005_usize` - -error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:25:9 - | -LL | 2_131_750_927isize, // 0x7F0F_F00F_isize - | ^^^^^^^^^^^^^^^^^^ help: consider: `0x7F0F_F00F_isize` - -error: aborting due to 7 previous errors - diff --git a/tests/ui/declare_interior_mutable_const/enums.rs b/tests/ui/declare_interior_mutable_const/enums.rs deleted file mode 100644 index f44518694b89..000000000000 --- a/tests/ui/declare_interior_mutable_const/enums.rs +++ /dev/null @@ -1,123 +0,0 @@ -#![warn(clippy::declare_interior_mutable_const)] - -use std::cell::Cell; -use std::sync::atomic::AtomicUsize; - -enum OptionalCell { - Unfrozen(Cell), - Frozen, -} - -// a constant with enums should be linted only when the used variant is unfrozen (#3962). -const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(true)); //~ ERROR interior mutable -const FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen; - -const fn unfrozen_variant() -> OptionalCell { - OptionalCell::Unfrozen(Cell::new(false)) -} - -const fn frozen_variant() -> OptionalCell { - OptionalCell::Frozen -} - -const UNFROZEN_VARIANT_FROM_FN: OptionalCell = unfrozen_variant(); //~ ERROR interior mutable -const FROZEN_VARIANT_FROM_FN: OptionalCell = frozen_variant(); - -enum NestedInnermost { - Unfrozen(AtomicUsize), - Frozen, -} - -struct NestedInner { - inner: NestedInnermost, -} - -enum NestedOuter { - NestedInner(NestedInner), - NotNested(usize), -} - -struct NestedOutermost { - outer: NestedOuter, -} - -// a constant with enums should be linted according to its value, no matter how structs involve. -const NESTED_UNFROZEN_VARIANT: NestedOutermost = NestedOutermost { - outer: NestedOuter::NestedInner(NestedInner { - inner: NestedInnermost::Unfrozen(AtomicUsize::new(2)), - }), -}; //~ ERROR interior mutable -const NESTED_FROZEN_VARIANT: NestedOutermost = NestedOutermost { - outer: NestedOuter::NestedInner(NestedInner { - inner: NestedInnermost::Frozen, - }), -}; - -trait AssocConsts { - // When there's no default value, lint it only according to its type. - // Further details are on the corresponding code (`NonCopyConst::check_trait_item`). - const TO_BE_UNFROZEN_VARIANT: OptionalCell; //~ ERROR interior mutable - const TO_BE_FROZEN_VARIANT: OptionalCell; //~ ERROR interior mutable - - // Lint default values accordingly. - const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); //~ ERROR interior mutable - const DEFAULTED_ON_FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen; -} - -// The lint doesn't trigger for an assoc constant in a trait impl with an unfrozen type even if it -// has enums. Further details are on the corresponding code in 'NonCopyConst::check_impl_item'. -impl AssocConsts for u64 { - const TO_BE_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); - const TO_BE_FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen; - - // even if this sets an unfrozen variant, the lint ignores it. - const DEFAULTED_ON_FROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); -} - -// At first, I thought I'd need to check every patterns in `trait.rs`; but, what matters -// here are values; and I think substituted generics at definitions won't appear in MIR. -trait AssocTypes { - type ToBeUnfrozen; - - const TO_BE_UNFROZEN_VARIANT: Option; - const TO_BE_FROZEN_VARIANT: Option; -} - -impl AssocTypes for u64 { - type ToBeUnfrozen = AtomicUsize; - - const TO_BE_UNFROZEN_VARIANT: Option = Some(Self::ToBeUnfrozen::new(4)); //~ ERROR interior mutable - const TO_BE_FROZEN_VARIANT: Option = None; -} - -// Use raw pointers since direct generics have a false negative at the type level. -enum BothOfCellAndGeneric { - Unfrozen(Cell<*const T>), - Generic(*const T), - Frozen(usize), -} - -impl BothOfCellAndGeneric { - const UNFROZEN_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mutable - - // This is a false positive. The argument about this is on `is_value_unfrozen_raw` - const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mutable - - const FROZEN_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Frozen(5); - - // This is what is likely to be a false negative when one tries to fix - // the `GENERIC_VARIANT` false positive. - const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null()); //~ ERROR interior mutable -} - -// associated types here is basically the same as the one above. -trait BothOfCellAndGenericWithAssocType { - type AssocType; - - const UNFROZEN_VARIANT: BothOfCellAndGeneric = - BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mutable - const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mutable - const FROZEN_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Frozen(5); -} - -fn main() {} diff --git a/tests/ui/declare_interior_mutable_const/enums.stderr b/tests/ui/declare_interior_mutable_const/enums.stderr deleted file mode 100644 index 84198d546157..000000000000 --- a/tests/ui/declare_interior_mutable_const/enums.stderr +++ /dev/null @@ -1,89 +0,0 @@ -error: a `const` item should never be interior mutable - --> $DIR/enums.rs:12:1 - | -LL | const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(true)); //~ ERROR interior mutable - | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | make this a static item (maybe with lazy_static) - | - = note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` - -error: a `const` item should never be interior mutable - --> $DIR/enums.rs:23:1 - | -LL | const UNFROZEN_VARIANT_FROM_FN: OptionalCell = unfrozen_variant(); //~ ERROR interior mutable - | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | make this a static item (maybe with lazy_static) - -error: a `const` item should never be interior mutable - --> $DIR/enums.rs:45:1 - | -LL | const NESTED_UNFROZEN_VARIANT: NestedOutermost = NestedOutermost { - | ^---- - | | - | _make this a static item (maybe with lazy_static) - | | -LL | | outer: NestedOuter::NestedInner(NestedInner { -LL | | inner: NestedInnermost::Unfrozen(AtomicUsize::new(2)), -LL | | }), -LL | | }; //~ ERROR interior mutable - | |__^ - -error: a `const` item should never be interior mutable - --> $DIR/enums.rs:59:5 - | -LL | const TO_BE_UNFROZEN_VARIANT: OptionalCell; //~ ERROR interior mutable - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: a `const` item should never be interior mutable - --> $DIR/enums.rs:60:5 - | -LL | const TO_BE_FROZEN_VARIANT: OptionalCell; //~ ERROR interior mutable - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: a `const` item should never be interior mutable - --> $DIR/enums.rs:63:5 - | -LL | const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); //~ ERROR interior mutable - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: a `const` item should never be interior mutable - --> $DIR/enums.rs:89:5 - | -LL | const TO_BE_UNFROZEN_VARIANT: Option = Some(Self::ToBeUnfrozen::new(4)); //~ ERROR interior mutable - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: a `const` item should never be interior mutable - --> $DIR/enums.rs:101:5 - | -LL | const UNFROZEN_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mut... - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: a `const` item should never be interior mutable - --> $DIR/enums.rs:104:5 - | -LL | const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mutable - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: a `const` item should never be interior mutable - --> $DIR/enums.rs:110:5 - | -LL | const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null()); //~ ERROR interior mutable - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: a `const` item should never be interior mutable - --> $DIR/enums.rs:117:5 - | -LL | / const UNFROZEN_VARIANT: BothOfCellAndGeneric = -LL | | BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mutable - | |____________________________________________________________________^ - -error: a `const` item should never be interior mutable - --> $DIR/enums.rs:119:5 - | -LL | const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mu... - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 12 previous errors - diff --git a/tests/ui/declare_interior_mutable_const/others.rs b/tests/ui/declare_interior_mutable_const/others.rs deleted file mode 100644 index 48c5e9537d6d..000000000000 --- a/tests/ui/declare_interior_mutable_const/others.rs +++ /dev/null @@ -1,34 +0,0 @@ -#![warn(clippy::declare_interior_mutable_const)] - -use std::borrow::Cow; -use std::cell::Cell; -use std::fmt::Display; -use std::sync::atomic::AtomicUsize; -use std::sync::Once; - -const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable -const CELL: Cell = Cell::new(6); //~ ERROR interior mutable -const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec, u8) = ([ATOMIC], Vec::new(), 7); -//~^ ERROR interior mutable - -macro_rules! declare_const { - ($name:ident: $ty:ty = $e:expr) => { - const $name: $ty = $e; - }; -} -declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable - -// const ATOMIC_REF: &AtomicUsize = &AtomicUsize::new(7); // This will simply trigger E0492. - -const INTEGER: u8 = 8; -const STRING: String = String::new(); -const STR: &str = "012345"; -const COW: Cow = Cow::Borrowed("abcdef"); -//^ note: a const item of Cow is used in the `postgres` package. - -const NO_ANN: &dyn Display = &70; - -static STATIC_TUPLE: (AtomicUsize, String) = (ATOMIC, STRING); -//^ there should be no lints on this line - -fn main() {} diff --git a/tests/ui/declare_interior_mutable_const/others.stderr b/tests/ui/declare_interior_mutable_const/others.stderr deleted file mode 100644 index 6153c96edc4f..000000000000 --- a/tests/ui/declare_interior_mutable_const/others.stderr +++ /dev/null @@ -1,39 +0,0 @@ -error: a `const` item should never be interior mutable - --> $DIR/others.rs:9:1 - | -LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable - | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | make this a static item (maybe with lazy_static) - | - = note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` - -error: a `const` item should never be interior mutable - --> $DIR/others.rs:10:1 - | -LL | const CELL: Cell = Cell::new(6); //~ ERROR interior mutable - | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | make this a static item (maybe with lazy_static) - -error: a `const` item should never be interior mutable - --> $DIR/others.rs:11:1 - | -LL | const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec, u8) = ([ATOMIC], Vec::new(), 7); - | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | make this a static item (maybe with lazy_static) - -error: a `const` item should never be interior mutable - --> $DIR/others.rs:16:9 - | -LL | const $name: $ty = $e; - | ^^^^^^^^^^^^^^^^^^^^^^ -... -LL | declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable - | ------------------------------------------ in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 4 previous errors - diff --git a/tests/ui/declare_interior_mutable_const/traits.rs b/tests/ui/declare_interior_mutable_const/traits.rs deleted file mode 100644 index 535147ccc645..000000000000 --- a/tests/ui/declare_interior_mutable_const/traits.rs +++ /dev/null @@ -1,150 +0,0 @@ -#![warn(clippy::declare_interior_mutable_const)] - -use std::borrow::Cow; -use std::cell::Cell; -use std::sync::atomic::AtomicUsize; - -macro_rules! declare_const { - ($name:ident: $ty:ty = $e:expr) => { - const $name: $ty = $e; - }; -} - -// a constant whose type is a concrete type should be linted at the definition site. -trait ConcreteTypes { - const ATOMIC: AtomicUsize; //~ ERROR interior mutable - const INTEGER: u64; - const STRING: String; - declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); //~ ERROR interior mutable -} - -impl ConcreteTypes for u64 { - const ATOMIC: AtomicUsize = AtomicUsize::new(9); - const INTEGER: u64 = 10; - const STRING: String = String::new(); -} - -// a helper trait used below -trait ConstDefault { - const DEFAULT: Self; -} - -// a constant whose type is a generic type should be linted at the implementation site. -trait GenericTypes { - const TO_REMAIN_GENERIC: T; - const TO_BE_CONCRETE: U; - - const HAVING_DEFAULT: T = Self::TO_REMAIN_GENERIC; - declare_const!(IN_MACRO: T = Self::TO_REMAIN_GENERIC); -} - -impl GenericTypes for u64 { - const TO_REMAIN_GENERIC: T = T::DEFAULT; - const TO_BE_CONCRETE: AtomicUsize = AtomicUsize::new(11); //~ ERROR interior mutable -} - -// a helper type used below -struct Wrapper(T); - -// a constant whose type is an associated type should be linted at the implementation site, too. -trait AssocTypes { - type ToBeFrozen; - type ToBeUnfrozen; - type ToBeGenericParam; - - const TO_BE_FROZEN: Self::ToBeFrozen; - const TO_BE_UNFROZEN: Self::ToBeUnfrozen; - const WRAPPED_TO_BE_UNFROZEN: Wrapper; - // to ensure it can handle things when a generic type remains after normalization. - const WRAPPED_TO_BE_GENERIC_PARAM: Wrapper; -} - -impl AssocTypes for Vec { - type ToBeFrozen = u16; - type ToBeUnfrozen = AtomicUsize; - type ToBeGenericParam = T; - - const TO_BE_FROZEN: Self::ToBeFrozen = 12; - const TO_BE_UNFROZEN: Self::ToBeUnfrozen = AtomicUsize::new(13); //~ ERROR interior mutable - const WRAPPED_TO_BE_UNFROZEN: Wrapper = Wrapper(AtomicUsize::new(14)); //~ ERROR interior mutable - const WRAPPED_TO_BE_GENERIC_PARAM: Wrapper = Wrapper(T::DEFAULT); -} - -// a helper trait used below -trait AssocTypesHelper { - type NotToBeBounded; - type ToBeBounded; - - const NOT_TO_BE_BOUNDED: Self::NotToBeBounded; -} - -// a constant whose type is an assoc type originated from a generic param bounded at the definition -// site should be linted at there. -trait AssocTypesFromGenericParam -where - T: AssocTypesHelper, -{ - const NOT_BOUNDED: T::NotToBeBounded; - const BOUNDED: T::ToBeBounded; //~ ERROR interior mutable -} - -impl AssocTypesFromGenericParam for u64 -where - T: AssocTypesHelper, -{ - // an associated type could remain unknown in a trait impl. - const NOT_BOUNDED: T::NotToBeBounded = T::NOT_TO_BE_BOUNDED; - const BOUNDED: T::ToBeBounded = AtomicUsize::new(15); -} - -// a constant whose type is `Self` should be linted at the implementation site as well. -// (`Option` requires `Sized` bound.) -trait SelfType: Sized { - const SELF: Self; - // this was the one in the original issue (#5050). - const WRAPPED_SELF: Option; -} - -impl SelfType for u64 { - const SELF: Self = 16; - const WRAPPED_SELF: Option = Some(20); -} - -impl SelfType for AtomicUsize { - // this (interior mutable `Self` const) exists in `parking_lot`. - // `const_trait_impl` will replace it in the future, hopefully. - const SELF: Self = AtomicUsize::new(17); //~ ERROR interior mutable - const WRAPPED_SELF: Option = Some(AtomicUsize::new(21)); //~ ERROR interior mutable -} - -// Even though a constant contains a generic type, if it also have a interior mutable type, -// it should be linted at the definition site. -trait BothOfCellAndGeneric { - // this is a false negative in the current implementation. - const DIRECT: Cell; - const INDIRECT: Cell<*const T>; //~ ERROR interior mutable -} - -impl BothOfCellAndGeneric for u64 { - const DIRECT: Cell = Cell::new(T::DEFAULT); - const INDIRECT: Cell<*const T> = Cell::new(std::ptr::null()); -} - -struct Local(T); - -// a constant in an inherent impl are essentially the same as a normal const item -// except there can be a generic or associated type. -impl Local -where - T: ConstDefault + AssocTypesHelper, -{ - const ATOMIC: AtomicUsize = AtomicUsize::new(18); //~ ERROR interior mutable - const COW: Cow<'static, str> = Cow::Borrowed("tuvwxy"); - - const GENERIC_TYPE: T = T::DEFAULT; - - const ASSOC_TYPE: T::NotToBeBounded = T::NOT_TO_BE_BOUNDED; - const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); //~ ERROR interior mutable -} - -fn main() {} diff --git a/tests/ui/declare_interior_mutable_const/traits.stderr b/tests/ui/declare_interior_mutable_const/traits.stderr deleted file mode 100644 index bb77f39b62c1..000000000000 --- a/tests/ui/declare_interior_mutable_const/traits.stderr +++ /dev/null @@ -1,75 +0,0 @@ -error: a `const` item should never be interior mutable - --> $DIR/traits.rs:15:5 - | -LL | const ATOMIC: AtomicUsize; //~ ERROR interior mutable - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` - -error: a `const` item should never be interior mutable - --> $DIR/traits.rs:9:9 - | -LL | const $name: $ty = $e; - | ^^^^^^^^^^^^^^^^^^^^^^ -... -LL | declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); //~ ERROR interior mutable - | ----------------------------------------------------------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: a `const` item should never be interior mutable - --> $DIR/traits.rs:43:5 - | -LL | const TO_BE_CONCRETE: AtomicUsize = AtomicUsize::new(11); //~ ERROR interior mutable - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: a `const` item should never be interior mutable - --> $DIR/traits.rs:68:5 - | -LL | const TO_BE_UNFROZEN: Self::ToBeUnfrozen = AtomicUsize::new(13); //~ ERROR interior mutable - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: a `const` item should never be interior mutable - --> $DIR/traits.rs:69:5 - | -LL | const WRAPPED_TO_BE_UNFROZEN: Wrapper = Wrapper(AtomicUsize::new(14)); //~ ERROR interior mutable - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: a `const` item should never be interior mutable - --> $DIR/traits.rs:88:5 - | -LL | const BOUNDED: T::ToBeBounded; //~ ERROR interior mutable - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: a `const` item should never be interior mutable - --> $DIR/traits.rs:116:5 - | -LL | const SELF: Self = AtomicUsize::new(17); //~ ERROR interior mutable - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: a `const` item should never be interior mutable - --> $DIR/traits.rs:117:5 - | -LL | const WRAPPED_SELF: Option = Some(AtomicUsize::new(21)); //~ ERROR interior mutable - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: a `const` item should never be interior mutable - --> $DIR/traits.rs:125:5 - | -LL | const INDIRECT: Cell<*const T>; //~ ERROR interior mutable - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: a `const` item should never be interior mutable - --> $DIR/traits.rs:141:5 - | -LL | const ATOMIC: AtomicUsize = AtomicUsize::new(18); //~ ERROR interior mutable - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: a `const` item should never be interior mutable - --> $DIR/traits.rs:147:5 - | -LL | const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); //~ ERROR interior mutable - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 11 previous errors - diff --git a/tests/ui/def_id_nocore.rs b/tests/ui/def_id_nocore.rs deleted file mode 100644 index 2a948d60b108..000000000000 --- a/tests/ui/def_id_nocore.rs +++ /dev/null @@ -1,29 +0,0 @@ -// ignore-windows -// ignore-macos - -#![feature(no_core, lang_items, start)] -#![no_core] - -#[link(name = "c")] -extern "C" {} - -#[lang = "sized"] -pub trait Sized {} -#[lang = "copy"] -pub trait Copy {} -#[lang = "freeze"] -pub unsafe trait Freeze {} - -#[lang = "start"] -#[start] -fn start(_argc: isize, _argv: *const *const u8) -> isize { - 0 -} - -pub struct A; - -impl A { - pub fn as_ref(self) -> &'static str { - "A" - } -} diff --git a/tests/ui/def_id_nocore.stderr b/tests/ui/def_id_nocore.stderr deleted file mode 100644 index ed87a50547d1..000000000000 --- a/tests/ui/def_id_nocore.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name - --> $DIR/def_id_nocore.rs:26:19 - | -LL | pub fn as_ref(self) -> &'static str { - | ^^^^ - | - = note: `-D clippy::wrong-self-convention` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/default_trait_access.fixed b/tests/ui/default_trait_access.fixed deleted file mode 100644 index d05567a3f824..000000000000 --- a/tests/ui/default_trait_access.fixed +++ /dev/null @@ -1,106 +0,0 @@ -// run-rustfix - -#![allow(unused_imports)] -#![deny(clippy::default_trait_access)] - -use std::default; -use std::default::Default as D2; -use std::string; - -fn main() { - let s1: String = std::string::String::default(); - - let s2 = String::default(); - - let s3: String = std::string::String::default(); - - let s4: String = std::string::String::default(); - - let s5 = string::String::default(); - - let s6: String = std::string::String::default(); - - let s7 = std::string::String::default(); - - let s8: String = DefaultFactory::make_t_badly(); - - let s9: String = DefaultFactory::make_t_nicely(); - - let s10 = DerivedDefault::default(); - - let s11: GenericDerivedDefault = GenericDerivedDefault::default(); - - let s12 = GenericDerivedDefault::::default(); - - let s13 = TupleDerivedDefault::default(); - - let s14: TupleDerivedDefault = TupleDerivedDefault::default(); - - let s15: ArrayDerivedDefault = ArrayDerivedDefault::default(); - - let s16 = ArrayDerivedDefault::default(); - - let s17: TupleStructDerivedDefault = TupleStructDerivedDefault::default(); - - let s18 = TupleStructDerivedDefault::default(); - - let s19 = ::default(); - - println!( - "[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}], [{:?}]", - s1, - s2, - s3, - s4, - s5, - s6, - s7, - s8, - s9, - s10, - s11, - s12, - s13, - s14, - s15, - s16, - s17, - s18, - s19, - ); -} - -struct DefaultFactory; - -impl DefaultFactory { - pub fn make_t_badly() -> T { - Default::default() - } - - pub fn make_t_nicely() -> T { - T::default() - } -} - -#[derive(Debug, Default)] -struct DerivedDefault { - pub s: String, -} - -#[derive(Debug, Default)] -struct GenericDerivedDefault { - pub s: T, -} - -#[derive(Debug, Default)] -struct TupleDerivedDefault { - pub s: (String, String), -} - -#[derive(Debug, Default)] -struct ArrayDerivedDefault { - pub s: [String; 10], -} - -#[derive(Debug, Default)] -struct TupleStructDerivedDefault(String); diff --git a/tests/ui/default_trait_access.rs b/tests/ui/default_trait_access.rs deleted file mode 100644 index 447e70c0bbbe..000000000000 --- a/tests/ui/default_trait_access.rs +++ /dev/null @@ -1,106 +0,0 @@ -// run-rustfix - -#![allow(unused_imports)] -#![deny(clippy::default_trait_access)] - -use std::default; -use std::default::Default as D2; -use std::string; - -fn main() { - let s1: String = Default::default(); - - let s2 = String::default(); - - let s3: String = D2::default(); - - let s4: String = std::default::Default::default(); - - let s5 = string::String::default(); - - let s6: String = default::Default::default(); - - let s7 = std::string::String::default(); - - let s8: String = DefaultFactory::make_t_badly(); - - let s9: String = DefaultFactory::make_t_nicely(); - - let s10 = DerivedDefault::default(); - - let s11: GenericDerivedDefault = Default::default(); - - let s12 = GenericDerivedDefault::::default(); - - let s13 = TupleDerivedDefault::default(); - - let s14: TupleDerivedDefault = Default::default(); - - let s15: ArrayDerivedDefault = Default::default(); - - let s16 = ArrayDerivedDefault::default(); - - let s17: TupleStructDerivedDefault = Default::default(); - - let s18 = TupleStructDerivedDefault::default(); - - let s19 = ::default(); - - println!( - "[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}], [{:?}]", - s1, - s2, - s3, - s4, - s5, - s6, - s7, - s8, - s9, - s10, - s11, - s12, - s13, - s14, - s15, - s16, - s17, - s18, - s19, - ); -} - -struct DefaultFactory; - -impl DefaultFactory { - pub fn make_t_badly() -> T { - Default::default() - } - - pub fn make_t_nicely() -> T { - T::default() - } -} - -#[derive(Debug, Default)] -struct DerivedDefault { - pub s: String, -} - -#[derive(Debug, Default)] -struct GenericDerivedDefault { - pub s: T, -} - -#[derive(Debug, Default)] -struct TupleDerivedDefault { - pub s: (String, String), -} - -#[derive(Debug, Default)] -struct ArrayDerivedDefault { - pub s: [String; 10], -} - -#[derive(Debug, Default)] -struct TupleStructDerivedDefault(String); diff --git a/tests/ui/default_trait_access.stderr b/tests/ui/default_trait_access.stderr deleted file mode 100644 index df8a5b94ddcf..000000000000 --- a/tests/ui/default_trait_access.stderr +++ /dev/null @@ -1,56 +0,0 @@ -error: calling `std::string::String::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:11:22 - | -LL | let s1: String = Default::default(); - | ^^^^^^^^^^^^^^^^^^ help: try: `std::string::String::default()` - | -note: the lint level is defined here - --> $DIR/default_trait_access.rs:4:9 - | -LL | #![deny(clippy::default_trait_access)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: calling `std::string::String::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:15:22 - | -LL | let s3: String = D2::default(); - | ^^^^^^^^^^^^^ help: try: `std::string::String::default()` - -error: calling `std::string::String::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:17:22 - | -LL | let s4: String = std::default::Default::default(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::string::String::default()` - -error: calling `std::string::String::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:21:22 - | -LL | let s6: String = default::Default::default(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::string::String::default()` - -error: calling `GenericDerivedDefault::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:31:46 - | -LL | let s11: GenericDerivedDefault = Default::default(); - | ^^^^^^^^^^^^^^^^^^ help: try: `GenericDerivedDefault::default()` - -error: calling `TupleDerivedDefault::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:37:36 - | -LL | let s14: TupleDerivedDefault = Default::default(); - | ^^^^^^^^^^^^^^^^^^ help: try: `TupleDerivedDefault::default()` - -error: calling `ArrayDerivedDefault::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:39:36 - | -LL | let s15: ArrayDerivedDefault = Default::default(); - | ^^^^^^^^^^^^^^^^^^ help: try: `ArrayDerivedDefault::default()` - -error: calling `TupleStructDerivedDefault::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:43:42 - | -LL | let s17: TupleStructDerivedDefault = Default::default(); - | ^^^^^^^^^^^^^^^^^^ help: try: `TupleStructDerivedDefault::default()` - -error: aborting due to 8 previous errors - diff --git a/tests/ui/deprecated.rs b/tests/ui/deprecated.rs deleted file mode 100644 index e1ee8dbca2c0..000000000000 --- a/tests/ui/deprecated.rs +++ /dev/null @@ -1,13 +0,0 @@ -#[warn(clippy::unstable_as_slice)] -#[warn(clippy::unstable_as_mut_slice)] -#[warn(clippy::misaligned_transmute)] -#[warn(clippy::unused_collect)] -#[warn(clippy::invalid_ref)] -#[warn(clippy::into_iter_on_array)] -#[warn(clippy::unused_label)] -#[warn(clippy::regex_macro)] -#[warn(clippy::drop_bounds)] -#[warn(clippy::temporary_cstring_as_ptr)] -#[warn(clippy::panic_params)] - -fn main() {} diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr deleted file mode 100644 index edbb891afe07..000000000000 --- a/tests/ui/deprecated.stderr +++ /dev/null @@ -1,76 +0,0 @@ -error: lint `clippy::unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` - --> $DIR/deprecated.rs:1:8 - | -LL | #[warn(clippy::unstable_as_slice)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D renamed-and-removed-lints` implied by `-D warnings` - -error: lint `clippy::unstable_as_mut_slice` has been removed: ``Vec::as_mut_slice` has been stabilized in 1.7` - --> $DIR/deprecated.rs:2:8 - | -LL | #[warn(clippy::unstable_as_mut_slice)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::misaligned_transmute` has been removed: `this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr` - --> $DIR/deprecated.rs:3:8 - | -LL | #[warn(clippy::misaligned_transmute)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::unused_collect` has been removed: ``collect` has been marked as #[must_use] in rustc and that covers all cases of this lint` - --> $DIR/deprecated.rs:4:8 - | -LL | #[warn(clippy::unused_collect)] - | ^^^^^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::invalid_ref` has been removed: `superseded by rustc lint `invalid_value`` - --> $DIR/deprecated.rs:5:8 - | -LL | #[warn(clippy::invalid_ref)] - | ^^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::into_iter_on_array` has been removed: `this lint has been uplifted to rustc and is now called `array_into_iter`` - --> $DIR/deprecated.rs:6:8 - | -LL | #[warn(clippy::into_iter_on_array)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::unused_label` has been removed: `this lint has been uplifted to rustc and is now called `unused_labels`` - --> $DIR/deprecated.rs:7:8 - | -LL | #[warn(clippy::unused_label)] - | ^^^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::regex_macro` has been removed: `the regex! macro has been removed from the regex crate in 2018` - --> $DIR/deprecated.rs:8:8 - | -LL | #[warn(clippy::regex_macro)] - | ^^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::drop_bounds` has been removed: `this lint has been uplifted to rustc and is now called `drop_bounds`` - --> $DIR/deprecated.rs:9:8 - | -LL | #[warn(clippy::drop_bounds)] - | ^^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::temporary_cstring_as_ptr` has been removed: `this lint has been uplifted to rustc and is now called `temporary_cstring_as_ptr`` - --> $DIR/deprecated.rs:10:8 - | -LL | #[warn(clippy::temporary_cstring_as_ptr)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::panic_params` has been removed: `this lint has been uplifted to rustc and is now called `panic_fmt`` - --> $DIR/deprecated.rs:11:8 - | -LL | #[warn(clippy::panic_params)] - | ^^^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` - --> $DIR/deprecated.rs:1:8 - | -LL | #[warn(clippy::unstable_as_slice)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 12 previous errors - diff --git a/tests/ui/deprecated_old.rs b/tests/ui/deprecated_old.rs deleted file mode 100644 index e89dca4fcfd4..000000000000 --- a/tests/ui/deprecated_old.rs +++ /dev/null @@ -1,5 +0,0 @@ -#[warn(unstable_as_slice)] -#[warn(unstable_as_mut_slice)] -#[warn(misaligned_transmute)] - -fn main() {} diff --git a/tests/ui/deprecated_old.stderr b/tests/ui/deprecated_old.stderr deleted file mode 100644 index 2fe1facf0c72..000000000000 --- a/tests/ui/deprecated_old.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: lint `unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` - --> $DIR/deprecated_old.rs:1:8 - | -LL | #[warn(unstable_as_slice)] - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D renamed-and-removed-lints` implied by `-D warnings` - -error: lint `unstable_as_mut_slice` has been removed: ``Vec::as_mut_slice` has been stabilized in 1.7` - --> $DIR/deprecated_old.rs:2:8 - | -LL | #[warn(unstable_as_mut_slice)] - | ^^^^^^^^^^^^^^^^^^^^^ - -error: lint `misaligned_transmute` has been removed: `this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr` - --> $DIR/deprecated_old.rs:3:8 - | -LL | #[warn(misaligned_transmute)] - | ^^^^^^^^^^^^^^^^^^^^ - -error: lint `unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` - --> $DIR/deprecated_old.rs:1:8 - | -LL | #[warn(unstable_as_slice)] - | ^^^^^^^^^^^^^^^^^ - -error: aborting due to 4 previous errors - diff --git a/tests/ui/deref_addrof.fixed b/tests/ui/deref_addrof.fixed deleted file mode 100644 index 0795900558b6..000000000000 --- a/tests/ui/deref_addrof.fixed +++ /dev/null @@ -1,63 +0,0 @@ -// run-rustfix -#![warn(clippy::deref_addrof)] - -fn get_number() -> usize { - 10 -} - -fn get_reference(n: &usize) -> &usize { - n -} - -#[allow(clippy::many_single_char_names, clippy::double_parens)] -#[allow(unused_variables, unused_parens)] -fn main() { - let a = 10; - let aref = &a; - - let b = a; - - let b = get_number(); - - let b = *get_reference(&a); - - let bytes: Vec = vec![1, 2, 3, 4]; - let b = bytes[1..2][0]; - - //This produces a suggestion of 'let b = (a);' which - //will trigger the 'unused_parens' lint - let b = (a); - - let b = a; - - #[rustfmt::skip] - let b = a; - - let b = &a; - - let b = *aref; -} - -#[rustfmt::skip] -macro_rules! m { - ($visitor: expr) => { - $visitor - }; -} - -#[rustfmt::skip] -macro_rules! m_mut { - ($visitor: expr) => { - $visitor - }; -} - -pub struct S; -impl S { - pub fn f(&self) -> &Self { - m!(self) - } - pub fn f_mut(&self) -> &Self { - m_mut!(self) - } -} diff --git a/tests/ui/deref_addrof.rs b/tests/ui/deref_addrof.rs deleted file mode 100644 index 60c4318601bc..000000000000 --- a/tests/ui/deref_addrof.rs +++ /dev/null @@ -1,63 +0,0 @@ -// run-rustfix -#![warn(clippy::deref_addrof)] - -fn get_number() -> usize { - 10 -} - -fn get_reference(n: &usize) -> &usize { - n -} - -#[allow(clippy::many_single_char_names, clippy::double_parens)] -#[allow(unused_variables, unused_parens)] -fn main() { - let a = 10; - let aref = &a; - - let b = *&a; - - let b = *&get_number(); - - let b = *get_reference(&a); - - let bytes: Vec = vec![1, 2, 3, 4]; - let b = *&bytes[1..2][0]; - - //This produces a suggestion of 'let b = (a);' which - //will trigger the 'unused_parens' lint - let b = *&(a); - - let b = *(&a); - - #[rustfmt::skip] - let b = *((&a)); - - let b = *&&a; - - let b = **&aref; -} - -#[rustfmt::skip] -macro_rules! m { - ($visitor: expr) => { - *& $visitor - }; -} - -#[rustfmt::skip] -macro_rules! m_mut { - ($visitor: expr) => { - *& mut $visitor - }; -} - -pub struct S; -impl S { - pub fn f(&self) -> &Self { - m!(self) - } - pub fn f_mut(&self) -> &Self { - m_mut!(self) - } -} diff --git a/tests/ui/deref_addrof.stderr b/tests/ui/deref_addrof.stderr deleted file mode 100644 index e85b30fa56eb..000000000000 --- a/tests/ui/deref_addrof.stderr +++ /dev/null @@ -1,74 +0,0 @@ -error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:18:13 - | -LL | let b = *&a; - | ^^^ help: try this: `a` - | - = note: `-D clippy::deref-addrof` implied by `-D warnings` - -error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:20:13 - | -LL | let b = *&get_number(); - | ^^^^^^^^^^^^^^ help: try this: `get_number()` - -error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:25:13 - | -LL | let b = *&bytes[1..2][0]; - | ^^^^^^^^^^^^^^^^ help: try this: `bytes[1..2][0]` - -error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:29:13 - | -LL | let b = *&(a); - | ^^^^^ help: try this: `(a)` - -error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:31:13 - | -LL | let b = *(&a); - | ^^^^^ help: try this: `a` - -error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:34:13 - | -LL | let b = *((&a)); - | ^^^^^^^ help: try this: `a` - -error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:36:13 - | -LL | let b = *&&a; - | ^^^^ help: try this: `&a` - -error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:38:14 - | -LL | let b = **&aref; - | ^^^^^^ help: try this: `aref` - -error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:44:9 - | -LL | *& $visitor - | ^^^^^^^^^^^ help: try this: `$visitor` -... -LL | m!(self) - | -------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:51:9 - | -LL | *& mut $visitor - | ^^^^^^^^^^^^^^^ help: try this: `$visitor` -... -LL | m_mut!(self) - | ------------ in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 10 previous errors - diff --git a/tests/ui/deref_addrof_double_trigger.rs b/tests/ui/deref_addrof_double_trigger.rs deleted file mode 100644 index 4531943299cd..000000000000 --- a/tests/ui/deref_addrof_double_trigger.rs +++ /dev/null @@ -1,23 +0,0 @@ -// This test can't work with run-rustfix because it needs two passes of test+fix - -#[warn(clippy::deref_addrof)] -#[allow(unused_variables, unused_mut)] -fn main() { - let a = 10; - - //This produces a suggestion of 'let b = *&a;' which - //will trigger the 'clippy::deref_addrof' lint again - let b = **&&a; - - { - let mut x = 10; - let y = *&mut x; - } - - { - //This produces a suggestion of 'let y = *&mut x' which - //will trigger the 'clippy::deref_addrof' lint again - let mut x = 10; - let y = **&mut &mut x; - } -} diff --git a/tests/ui/deref_addrof_double_trigger.stderr b/tests/ui/deref_addrof_double_trigger.stderr deleted file mode 100644 index 2c55a4ed6acd..000000000000 --- a/tests/ui/deref_addrof_double_trigger.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: immediately dereferencing a reference - --> $DIR/deref_addrof_double_trigger.rs:10:14 - | -LL | let b = **&&a; - | ^^^^ help: try this: `&a` - | - = note: `-D clippy::deref-addrof` implied by `-D warnings` - -error: immediately dereferencing a reference - --> $DIR/deref_addrof_double_trigger.rs:14:17 - | -LL | let y = *&mut x; - | ^^^^^^^ help: try this: `x` - -error: immediately dereferencing a reference - --> $DIR/deref_addrof_double_trigger.rs:21:18 - | -LL | let y = **&mut &mut x; - | ^^^^^^^^^^^^ help: try this: `&mut x` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/deref_addrof_macro.rs b/tests/ui/deref_addrof_macro.rs deleted file mode 100644 index dcebd6c6e29c..000000000000 --- a/tests/ui/deref_addrof_macro.rs +++ /dev/null @@ -1,10 +0,0 @@ -macro_rules! m { - ($($x:tt),*) => { &[$(($x, stringify!(x)),)*] }; -} - -#[warn(clippy::deref_addrof)] -fn f() -> [(i32, &'static str); 3] { - *m![1, 2, 3] // should be fine -} - -fn main() {} diff --git a/tests/ui/dereference.fixed b/tests/ui/dereference.fixed deleted file mode 100644 index 459ca91b93b9..000000000000 --- a/tests/ui/dereference.fixed +++ /dev/null @@ -1,93 +0,0 @@ -// run-rustfix - -#![allow(unused_variables, clippy::many_single_char_names, clippy::clone_double_ref)] -#![warn(clippy::explicit_deref_methods)] - -use std::ops::{Deref, DerefMut}; - -fn concat(deref_str: &str) -> String { - format!("{}bar", deref_str) -} - -fn just_return(deref_str: &str) -> &str { - deref_str -} - -struct CustomVec(Vec); -impl Deref for CustomVec { - type Target = Vec; - - fn deref(&self) -> &Vec { - &self.0 - } -} - -fn main() { - let a: &mut String = &mut String::from("foo"); - - // these should require linting - - let b: &str = &*a; - - let b: &mut str = &mut *a; - - // both derefs should get linted here - let b: String = format!("{}, {}", &*a, &*a); - - println!("{}", &*a); - - #[allow(clippy::match_single_binding)] - match &*a { - _ => (), - } - - let b: String = concat(&*a); - - let b = &*just_return(a); - - let b: String = concat(&*just_return(a)); - - let b: &str = &*a.deref(); - - let opt_a = Some(a.clone()); - let b = &*opt_a.unwrap(); - - // following should not require linting - - let cv = CustomVec(vec![0, 42]); - let c = cv.deref()[0]; - - let b: &str = &*a.deref(); - - let b: String = a.deref().clone(); - - let b: usize = a.deref_mut().len(); - - let b: &usize = &a.deref().len(); - - let b: &str = &*a; - - let b: &mut str = &mut *a; - - macro_rules! expr_deref { - ($body:expr) => { - $body.deref() - }; - } - let b: &str = expr_deref!(a); - - // The struct does not implement Deref trait - #[derive(Copy, Clone)] - struct NoLint(u32); - impl NoLint { - pub fn deref(self) -> u32 { - self.0 - } - pub fn deref_mut(self) -> u32 { - self.0 - } - } - let no_lint = NoLint(42); - let b = no_lint.deref(); - let b = no_lint.deref_mut(); -} diff --git a/tests/ui/dereference.rs b/tests/ui/dereference.rs deleted file mode 100644 index 8dc5272e67fa..000000000000 --- a/tests/ui/dereference.rs +++ /dev/null @@ -1,93 +0,0 @@ -// run-rustfix - -#![allow(unused_variables, clippy::many_single_char_names, clippy::clone_double_ref)] -#![warn(clippy::explicit_deref_methods)] - -use std::ops::{Deref, DerefMut}; - -fn concat(deref_str: &str) -> String { - format!("{}bar", deref_str) -} - -fn just_return(deref_str: &str) -> &str { - deref_str -} - -struct CustomVec(Vec); -impl Deref for CustomVec { - type Target = Vec; - - fn deref(&self) -> &Vec { - &self.0 - } -} - -fn main() { - let a: &mut String = &mut String::from("foo"); - - // these should require linting - - let b: &str = a.deref(); - - let b: &mut str = a.deref_mut(); - - // both derefs should get linted here - let b: String = format!("{}, {}", a.deref(), a.deref()); - - println!("{}", a.deref()); - - #[allow(clippy::match_single_binding)] - match a.deref() { - _ => (), - } - - let b: String = concat(a.deref()); - - let b = just_return(a).deref(); - - let b: String = concat(just_return(a).deref()); - - let b: &str = a.deref().deref(); - - let opt_a = Some(a.clone()); - let b = opt_a.unwrap().deref(); - - // following should not require linting - - let cv = CustomVec(vec![0, 42]); - let c = cv.deref()[0]; - - let b: &str = &*a.deref(); - - let b: String = a.deref().clone(); - - let b: usize = a.deref_mut().len(); - - let b: &usize = &a.deref().len(); - - let b: &str = &*a; - - let b: &mut str = &mut *a; - - macro_rules! expr_deref { - ($body:expr) => { - $body.deref() - }; - } - let b: &str = expr_deref!(a); - - // The struct does not implement Deref trait - #[derive(Copy, Clone)] - struct NoLint(u32); - impl NoLint { - pub fn deref(self) -> u32 { - self.0 - } - pub fn deref_mut(self) -> u32 { - self.0 - } - } - let no_lint = NoLint(42); - let b = no_lint.deref(); - let b = no_lint.deref_mut(); -} diff --git a/tests/ui/dereference.stderr b/tests/ui/dereference.stderr deleted file mode 100644 index d26b462a4336..000000000000 --- a/tests/ui/dereference.stderr +++ /dev/null @@ -1,70 +0,0 @@ -error: explicit deref method call - --> $DIR/dereference.rs:30:19 - | -LL | let b: &str = a.deref(); - | ^^^^^^^^^ help: try this: `&*a` - | - = note: `-D clippy::explicit-deref-methods` implied by `-D warnings` - -error: explicit deref_mut method call - --> $DIR/dereference.rs:32:23 - | -LL | let b: &mut str = a.deref_mut(); - | ^^^^^^^^^^^^^ help: try this: `&mut *a` - -error: explicit deref method call - --> $DIR/dereference.rs:35:39 - | -LL | let b: String = format!("{}, {}", a.deref(), a.deref()); - | ^^^^^^^^^ help: try this: `&*a` - -error: explicit deref method call - --> $DIR/dereference.rs:35:50 - | -LL | let b: String = format!("{}, {}", a.deref(), a.deref()); - | ^^^^^^^^^ help: try this: `&*a` - -error: explicit deref method call - --> $DIR/dereference.rs:37:20 - | -LL | println!("{}", a.deref()); - | ^^^^^^^^^ help: try this: `&*a` - -error: explicit deref method call - --> $DIR/dereference.rs:40:11 - | -LL | match a.deref() { - | ^^^^^^^^^ help: try this: `&*a` - -error: explicit deref method call - --> $DIR/dereference.rs:44:28 - | -LL | let b: String = concat(a.deref()); - | ^^^^^^^^^ help: try this: `&*a` - -error: explicit deref method call - --> $DIR/dereference.rs:46:13 - | -LL | let b = just_return(a).deref(); - | ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&*just_return(a)` - -error: explicit deref method call - --> $DIR/dereference.rs:48:28 - | -LL | let b: String = concat(just_return(a).deref()); - | ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&*just_return(a)` - -error: explicit deref method call - --> $DIR/dereference.rs:50:19 - | -LL | let b: &str = a.deref().deref(); - | ^^^^^^^^^^^^^^^^^ help: try this: `&*a.deref()` - -error: explicit deref method call - --> $DIR/dereference.rs:53:13 - | -LL | let b = opt_a.unwrap().deref(); - | ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&*opt_a.unwrap()` - -error: aborting due to 11 previous errors - diff --git a/tests/ui/derive.rs b/tests/ui/derive.rs deleted file mode 100644 index 8fcb0e8b28d0..000000000000 --- a/tests/ui/derive.rs +++ /dev/null @@ -1,74 +0,0 @@ -#![feature(untagged_unions)] -#![allow(dead_code)] -#![warn(clippy::expl_impl_clone_on_copy)] - -#[derive(Copy)] -struct Qux; - -impl Clone for Qux { - fn clone(&self) -> Self { - Qux - } -} - -// looks like unions don't support deriving Clone for now -#[derive(Copy)] -union Union { - a: u8, -} - -impl Clone for Union { - fn clone(&self) -> Self { - Union { a: 42 } - } -} - -// See #666 -#[derive(Copy)] -struct Lt<'a> { - a: &'a u8, -} - -impl<'a> Clone for Lt<'a> { - fn clone(&self) -> Self { - unimplemented!() - } -} - -// Ok, `Clone` cannot be derived because of the big array -#[derive(Copy)] -struct BigArray { - a: [u8; 65], -} - -impl Clone for BigArray { - fn clone(&self) -> Self { - unimplemented!() - } -} - -// Ok, function pointers are not always Clone -#[derive(Copy)] -struct FnPtr { - a: fn() -> !, -} - -impl Clone for FnPtr { - fn clone(&self) -> Self { - unimplemented!() - } -} - -// Ok, generics -#[derive(Copy)] -struct Generic { - a: T, -} - -impl Clone for Generic { - fn clone(&self) -> Self { - unimplemented!() - } -} - -fn main() {} diff --git a/tests/ui/derive.stderr b/tests/ui/derive.stderr deleted file mode 100644 index 1328a9b31077..000000000000 --- a/tests/ui/derive.stderr +++ /dev/null @@ -1,83 +0,0 @@ -error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:8:1 - | -LL | / impl Clone for Qux { -LL | | fn clone(&self) -> Self { -LL | | Qux -LL | | } -LL | | } - | |_^ - | - = note: `-D clippy::expl-impl-clone-on-copy` implied by `-D warnings` -note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:8:1 - | -LL | / impl Clone for Qux { -LL | | fn clone(&self) -> Self { -LL | | Qux -LL | | } -LL | | } - | |_^ - -error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:32:1 - | -LL | / impl<'a> Clone for Lt<'a> { -LL | | fn clone(&self) -> Self { -LL | | unimplemented!() -LL | | } -LL | | } - | |_^ - | -note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:32:1 - | -LL | / impl<'a> Clone for Lt<'a> { -LL | | fn clone(&self) -> Self { -LL | | unimplemented!() -LL | | } -LL | | } - | |_^ - -error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:44:1 - | -LL | / impl Clone for BigArray { -LL | | fn clone(&self) -> Self { -LL | | unimplemented!() -LL | | } -LL | | } - | |_^ - | -note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:44:1 - | -LL | / impl Clone for BigArray { -LL | | fn clone(&self) -> Self { -LL | | unimplemented!() -LL | | } -LL | | } - | |_^ - -error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:56:1 - | -LL | / impl Clone for FnPtr { -LL | | fn clone(&self) -> Self { -LL | | unimplemented!() -LL | | } -LL | | } - | |_^ - | -note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:56:1 - | -LL | / impl Clone for FnPtr { -LL | | fn clone(&self) -> Self { -LL | | unimplemented!() -LL | | } -LL | | } - | |_^ - -error: aborting due to 4 previous errors - diff --git a/tests/ui/derive_hash_xor_eq.rs b/tests/ui/derive_hash_xor_eq.rs deleted file mode 100644 index 10abe22d53e5..000000000000 --- a/tests/ui/derive_hash_xor_eq.rs +++ /dev/null @@ -1,54 +0,0 @@ -#[derive(PartialEq, Hash)] -struct Foo; - -impl PartialEq for Foo { - fn eq(&self, _: &u64) -> bool { - true - } -} - -#[derive(Hash)] -struct Bar; - -impl PartialEq for Bar { - fn eq(&self, _: &Bar) -> bool { - true - } -} - -#[derive(Hash)] -struct Baz; - -impl PartialEq for Baz { - fn eq(&self, _: &Baz) -> bool { - true - } -} - -#[derive(PartialEq)] -struct Bah; - -impl std::hash::Hash for Bah { - fn hash(&self, _: &mut H) {} -} - -#[derive(PartialEq)] -struct Foo2; - -trait Hash {} - -// We don't want to lint on user-defined traits called `Hash` -impl Hash for Foo2 {} - -mod use_hash { - use std::hash::{Hash, Hasher}; - - #[derive(PartialEq)] - struct Foo3; - - impl Hash for Foo3 { - fn hash(&self, _: &mut H) {} - } -} - -fn main() {} diff --git a/tests/ui/derive_hash_xor_eq.stderr b/tests/ui/derive_hash_xor_eq.stderr deleted file mode 100644 index 2287a548fe46..000000000000 --- a/tests/ui/derive_hash_xor_eq.stderr +++ /dev/null @@ -1,67 +0,0 @@ -error: you are deriving `Hash` but have implemented `PartialEq` explicitly - --> $DIR/derive_hash_xor_eq.rs:10:10 - | -LL | #[derive(Hash)] - | ^^^^ - | - = note: `#[deny(clippy::derive_hash_xor_eq)]` on by default -note: `PartialEq` implemented here - --> $DIR/derive_hash_xor_eq.rs:13:1 - | -LL | / impl PartialEq for Bar { -LL | | fn eq(&self, _: &Bar) -> bool { -LL | | true -LL | | } -LL | | } - | |_^ - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: you are deriving `Hash` but have implemented `PartialEq` explicitly - --> $DIR/derive_hash_xor_eq.rs:19:10 - | -LL | #[derive(Hash)] - | ^^^^ - | -note: `PartialEq` implemented here - --> $DIR/derive_hash_xor_eq.rs:22:1 - | -LL | / impl PartialEq for Baz { -LL | | fn eq(&self, _: &Baz) -> bool { -LL | | true -LL | | } -LL | | } - | |_^ - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: you are implementing `Hash` explicitly but have derived `PartialEq` - --> $DIR/derive_hash_xor_eq.rs:31:1 - | -LL | / impl std::hash::Hash for Bah { -LL | | fn hash(&self, _: &mut H) {} -LL | | } - | |_^ - | -note: `PartialEq` implemented here - --> $DIR/derive_hash_xor_eq.rs:28:10 - | -LL | #[derive(PartialEq)] - | ^^^^^^^^^ - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: you are implementing `Hash` explicitly but have derived `PartialEq` - --> $DIR/derive_hash_xor_eq.rs:49:5 - | -LL | / impl Hash for Foo3 { -LL | | fn hash(&self, _: &mut H) {} -LL | | } - | |_____^ - | -note: `PartialEq` implemented here - --> $DIR/derive_hash_xor_eq.rs:46:14 - | -LL | #[derive(PartialEq)] - | ^^^^^^^^^ - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 4 previous errors - diff --git a/tests/ui/derive_ord_xor_partial_ord.rs b/tests/ui/derive_ord_xor_partial_ord.rs deleted file mode 100644 index 6f12d36d777d..000000000000 --- a/tests/ui/derive_ord_xor_partial_ord.rs +++ /dev/null @@ -1,69 +0,0 @@ -#![warn(clippy::derive_ord_xor_partial_ord)] -#![allow(clippy::unnecessary_wraps)] - -use std::cmp::Ordering; - -#[derive(PartialOrd, Ord, PartialEq, Eq)] -struct DeriveBoth; - -impl PartialEq for DeriveBoth { - fn eq(&self, _: &u64) -> bool { - true - } -} - -impl PartialOrd for DeriveBoth { - fn partial_cmp(&self, _: &u64) -> Option { - Some(Ordering::Equal) - } -} - -#[derive(Ord, PartialEq, Eq)] -struct DeriveOrd; - -impl PartialOrd for DeriveOrd { - fn partial_cmp(&self, other: &Self) -> Option { - Some(other.cmp(self)) - } -} - -#[derive(Ord, PartialEq, Eq)] -struct DeriveOrdWithExplicitTypeVariable; - -impl PartialOrd for DeriveOrdWithExplicitTypeVariable { - fn partial_cmp(&self, other: &Self) -> Option { - Some(other.cmp(self)) - } -} - -#[derive(PartialOrd, PartialEq, Eq)] -struct DerivePartialOrd; - -impl std::cmp::Ord for DerivePartialOrd { - fn cmp(&self, other: &Self) -> Ordering { - Ordering::Less - } -} - -#[derive(PartialOrd, PartialEq, Eq)] -struct ImplUserOrd; - -trait Ord {} - -// We don't want to lint on user-defined traits called `Ord` -impl Ord for ImplUserOrd {} - -mod use_ord { - use std::cmp::{Ord, Ordering}; - - #[derive(PartialOrd, PartialEq, Eq)] - struct DerivePartialOrdInUseOrd; - - impl Ord for DerivePartialOrdInUseOrd { - fn cmp(&self, other: &Self) -> Ordering { - Ordering::Less - } - } -} - -fn main() {} diff --git a/tests/ui/derive_ord_xor_partial_ord.stderr b/tests/ui/derive_ord_xor_partial_ord.stderr deleted file mode 100644 index 97b46a4aa898..000000000000 --- a/tests/ui/derive_ord_xor_partial_ord.stderr +++ /dev/null @@ -1,71 +0,0 @@ -error: you are deriving `Ord` but have implemented `PartialOrd` explicitly - --> $DIR/derive_ord_xor_partial_ord.rs:21:10 - | -LL | #[derive(Ord, PartialEq, Eq)] - | ^^^ - | - = note: `-D clippy::derive-ord-xor-partial-ord` implied by `-D warnings` -note: `PartialOrd` implemented here - --> $DIR/derive_ord_xor_partial_ord.rs:24:1 - | -LL | / impl PartialOrd for DeriveOrd { -LL | | fn partial_cmp(&self, other: &Self) -> Option { -LL | | Some(other.cmp(self)) -LL | | } -LL | | } - | |_^ - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: you are deriving `Ord` but have implemented `PartialOrd` explicitly - --> $DIR/derive_ord_xor_partial_ord.rs:30:10 - | -LL | #[derive(Ord, PartialEq, Eq)] - | ^^^ - | -note: `PartialOrd` implemented here - --> $DIR/derive_ord_xor_partial_ord.rs:33:1 - | -LL | / impl PartialOrd for DeriveOrdWithExplicitTypeVariable { -LL | | fn partial_cmp(&self, other: &Self) -> Option { -LL | | Some(other.cmp(self)) -LL | | } -LL | | } - | |_^ - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: you are implementing `Ord` explicitly but have derived `PartialOrd` - --> $DIR/derive_ord_xor_partial_ord.rs:42:1 - | -LL | / impl std::cmp::Ord for DerivePartialOrd { -LL | | fn cmp(&self, other: &Self) -> Ordering { -LL | | Ordering::Less -LL | | } -LL | | } - | |_^ - | -note: `PartialOrd` implemented here - --> $DIR/derive_ord_xor_partial_ord.rs:39:10 - | -LL | #[derive(PartialOrd, PartialEq, Eq)] - | ^^^^^^^^^^ - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: you are implementing `Ord` explicitly but have derived `PartialOrd` - --> $DIR/derive_ord_xor_partial_ord.rs:62:5 - | -LL | / impl Ord for DerivePartialOrdInUseOrd { -LL | | fn cmp(&self, other: &Self) -> Ordering { -LL | | Ordering::Less -LL | | } -LL | | } - | |_____^ - | -note: `PartialOrd` implemented here - --> $DIR/derive_ord_xor_partial_ord.rs:59:14 - | -LL | #[derive(PartialOrd, PartialEq, Eq)] - | ^^^^^^^^^^ - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 4 previous errors - diff --git a/tests/ui/diverging_sub_expression.rs b/tests/ui/diverging_sub_expression.rs deleted file mode 100644 index 4df241c9fc39..000000000000 --- a/tests/ui/diverging_sub_expression.rs +++ /dev/null @@ -1,42 +0,0 @@ -#![warn(clippy::diverging_sub_expression)] -#![allow(clippy::match_same_arms, clippy::logic_bug)] - -#[allow(clippy::empty_loop)] -fn diverge() -> ! { - loop {} -} - -struct A; - -impl A { - fn foo(&self) -> ! { - diverge() - } -} - -#[allow(unused_variables, clippy::unnecessary_operation, clippy::short_circuit_statement)] -fn main() { - let b = true; - b || diverge(); - b || A.foo(); -} - -#[allow(dead_code, unused_variables)] -fn foobar() { - loop { - let x = match 5 { - 4 => return, - 5 => continue, - 6 => true || return, - 7 => true || continue, - 8 => break, - 9 => diverge(), - 3 => true || diverge(), - 10 => match 42 { - 99 => return, - _ => true || panic!("boo"), - }, - _ => true || break, - }; - } -} diff --git a/tests/ui/diverging_sub_expression.stderr b/tests/ui/diverging_sub_expression.stderr deleted file mode 100644 index 170e7d92de4a..000000000000 --- a/tests/ui/diverging_sub_expression.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:20:10 - | -LL | b || diverge(); - | ^^^^^^^^^ - | - = note: `-D clippy::diverging-sub-expression` implied by `-D warnings` - -error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:21:10 - | -LL | b || A.foo(); - | ^^^^^^^ - -error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:30:26 - | -LL | 6 => true || return, - | ^^^^^^ - -error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:31:26 - | -LL | 7 => true || continue, - | ^^^^^^^^ - -error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:34:26 - | -LL | 3 => true || diverge(), - | ^^^^^^^^^ - -error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:39:26 - | -LL | _ => true || break, - | ^^^^^ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/dlist.rs b/tests/ui/dlist.rs deleted file mode 100644 index 2940d2d29011..000000000000 --- a/tests/ui/dlist.rs +++ /dev/null @@ -1,40 +0,0 @@ -#![feature(associated_type_defaults)] -#![warn(clippy::linkedlist)] -#![allow(dead_code, clippy::needless_pass_by_value)] - -extern crate alloc; -use alloc::collections::linked_list::LinkedList; - -trait Foo { - type Baz = LinkedList; - fn foo(_: LinkedList); - const BAR: Option>; -} - -// Ok, we don’t want to warn for implementations; see issue #605. -impl Foo for LinkedList { - fn foo(_: LinkedList) {} - const BAR: Option> = None; -} - -struct Bar; -impl Bar { - fn foo(_: LinkedList) {} -} - -pub fn test(my_favourite_linked_list: LinkedList) { - println!("{:?}", my_favourite_linked_list) -} - -pub fn test_ret() -> Option> { - unimplemented!(); -} - -pub fn test_local_not_linted() { - let _: LinkedList; -} - -fn main() { - test(LinkedList::new()); - test_local_not_linted(); -} diff --git a/tests/ui/dlist.stderr b/tests/ui/dlist.stderr deleted file mode 100644 index 64fde33c64f5..000000000000 --- a/tests/ui/dlist.stderr +++ /dev/null @@ -1,51 +0,0 @@ -error: I see you're using a LinkedList! Perhaps you meant some other data structure? - --> $DIR/dlist.rs:9:16 - | -LL | type Baz = LinkedList; - | ^^^^^^^^^^^^^^ - | - = note: `-D clippy::linkedlist` implied by `-D warnings` - = help: a `VecDeque` might work - -error: I see you're using a LinkedList! Perhaps you meant some other data structure? - --> $DIR/dlist.rs:10:15 - | -LL | fn foo(_: LinkedList); - | ^^^^^^^^^^^^^^ - | - = help: a `VecDeque` might work - -error: I see you're using a LinkedList! Perhaps you meant some other data structure? - --> $DIR/dlist.rs:11:23 - | -LL | const BAR: Option>; - | ^^^^^^^^^^^^^^ - | - = help: a `VecDeque` might work - -error: I see you're using a LinkedList! Perhaps you meant some other data structure? - --> $DIR/dlist.rs:22:15 - | -LL | fn foo(_: LinkedList) {} - | ^^^^^^^^^^^^^^ - | - = help: a `VecDeque` might work - -error: I see you're using a LinkedList! Perhaps you meant some other data structure? - --> $DIR/dlist.rs:25:39 - | -LL | pub fn test(my_favourite_linked_list: LinkedList) { - | ^^^^^^^^^^^^^^ - | - = help: a `VecDeque` might work - -error: I see you're using a LinkedList! Perhaps you meant some other data structure? - --> $DIR/dlist.rs:29:29 - | -LL | pub fn test_ret() -> Option> { - | ^^^^^^^^^^^^^^ - | - = help: a `VecDeque` might work - -error: aborting due to 6 previous errors - diff --git a/tests/ui/doc.rs b/tests/ui/doc.rs deleted file mode 100644 index 68c5d32846f1..000000000000 --- a/tests/ui/doc.rs +++ /dev/null @@ -1,191 +0,0 @@ -//! This file tests for the `DOC_MARKDOWN` lint. - -#![allow(dead_code)] -#![warn(clippy::doc_markdown)] -#![feature(custom_inner_attributes)] -#![rustfmt::skip] - -/// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) -/// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not Foo::some_fun -/// which should be reported only once despite being __doubly bad__. -/// Here be ::a::global:path. -/// That's not code ~NotInCodeBlock~. -/// be_sure_we_got_to_the_end_of_it -fn foo_bar() { -} - -/// That one tests multiline ticks. -/// ```rust -/// foo_bar FOO_BAR -/// _foo bar_ -/// ``` -/// -/// ~~~rust -/// foo_bar FOO_BAR -/// _foo bar_ -/// ~~~ -/// be_sure_we_got_to_the_end_of_it -fn multiline_codeblock() { -} - -/// This _is a test for -/// multiline -/// emphasis_. -/// be_sure_we_got_to_the_end_of_it -fn test_emphasis() { -} - -/// This tests units. See also #835. -/// kiB MiB GiB TiB PiB EiB -/// kib Mib Gib Tib Pib Eib -/// kB MB GB TB PB EB -/// kb Mb Gb Tb Pb Eb -/// 32kiB 32MiB 32GiB 32TiB 32PiB 32EiB -/// 32kib 32Mib 32Gib 32Tib 32Pib 32Eib -/// 32kB 32MB 32GB 32TB 32PB 32EB -/// 32kb 32Mb 32Gb 32Tb 32Pb 32Eb -/// NaN -/// be_sure_we_got_to_the_end_of_it -fn test_units() { -} - -/// This tests allowed identifiers. -/// DirectX -/// ECMAScript -/// OAuth GraphQL -/// TeX LaTeX BibTeX BibLaTeX -/// CamelCase (see also #2395) -/// be_sure_we_got_to_the_end_of_it -fn test_allowed() { -} - -/// This test has [a link_with_underscores][chunked-example] inside it. See #823. -/// See also [the issue tracker](https://github.com/rust-lang/rust-clippy/search?q=clippy::doc_markdown&type=Issues) -/// on GitHub (which is a camel-cased word, but is OK). And here is another [inline link][inline_link]. -/// It can also be [inline_link2]. -/// -/// [chunked-example]: https://en.wikipedia.org/wiki/Chunked_transfer_encoding#Example -/// [inline_link]: https://foobar -/// [inline_link2]: https://foobar -/// The `main` function is the entry point of the program. Here it only calls the `foo_bar` and -/// `multiline_ticks` functions. -/// -/// expression of the type `_ m c` (where `` -/// is one of {`&`, '|'} and `` is one of {`!=`, `>=`, `>` , -/// be_sure_we_got_to_the_end_of_it -fn main() { - foo_bar(); - multiline_codeblock(); - test_emphasis(); - test_units(); -} - -/// ## CamelCaseThing -/// Talks about `CamelCaseThing`. Titles should be ignored; see issue #897. -/// -/// # CamelCaseThing -/// -/// Not a title #897 CamelCaseThing -/// be_sure_we_got_to_the_end_of_it -fn issue897() { -} - -/// I am confused by brackets? (`x_y`) -/// I am confused by brackets? (foo `x_y`) -/// I am confused by brackets? (`x_y` foo) -/// be_sure_we_got_to_the_end_of_it -fn issue900() { -} - -/// Diesel queries also have a similar problem to [Iterator][iterator], where -/// /// More talking -/// returning them from a function requires exposing the implementation of that -/// function. The [`helper_types`][helper_types] module exists to help with this, -/// but you might want to hide the return type or have it conditionally change. -/// Boxing can achieve both. -/// -/// [iterator]: https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html -/// [helper_types]: ../helper_types/index.html -/// be_sure_we_got_to_the_end_of_it -fn issue883() { -} - -/// `foo_bar -/// baz_quz` -/// [foo -/// bar](https://doc.rust-lang.org/stable/std/iter/trait.IteratorFooBar.html) -fn multiline() { -} - -/** E.g., serialization of an empty list: FooBar -``` -That's in a code block: `PackedNode` -``` - -And BarQuz too. -be_sure_we_got_to_the_end_of_it -*/ -fn issue1073() { -} - -/** E.g., serialization of an empty list: FooBar -``` -That's in a code block: PackedNode -``` - -And BarQuz too. -be_sure_we_got_to_the_end_of_it -*/ -fn issue1073_alt() { -} - -/// Tests more than three quotes: -/// ```` -/// DoNotWarn -/// ``` -/// StillDont -/// ```` -/// be_sure_we_got_to_the_end_of_it -fn four_quotes() { -} - -/// See [NIST SP 800-56A, revision 2]. -/// -/// [NIST SP 800-56A, revision 2]: -/// https://github.com/rust-lang/rust-clippy/issues/902#issuecomment-261919419 -fn issue_902_comment() {} - -#[cfg_attr(feature = "a", doc = " ```")] -#[cfg_attr(not(feature = "a"), doc = " ```ignore")] -/// fn main() { -/// let s = "localhost:10000".to_string(); -/// println!("{}", s); -/// } -/// ``` -fn issue_1469() {} - -/** - * This is a doc comment that should not be a list - *This would also be an error under a strict common mark interpretation - */ -fn issue_1920() {} - -/// Ok: -/// -/// Not ok: http://www.unicode.org -/// Not ok: https://www.unicode.org -/// Not ok: http://www.unicode.org/ -/// Not ok: http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels -fn issue_1832() {} - -/// An iterator over mycrate::Collection's values. -/// It should not lint a `'static` lifetime in ticks. -fn issue_2210() {} - -/// This should not cause the lint to trigger: -/// #REQ-data-family.lint_partof_exists -fn issue_2343() {} - -/// This should not cause an ICE: -/// __|_ _|__||_| -fn pulldown_cmark_crash() {} diff --git a/tests/ui/doc.stderr b/tests/ui/doc.stderr deleted file mode 100644 index 23fca43590b4..000000000000 --- a/tests/ui/doc.stderr +++ /dev/null @@ -1,190 +0,0 @@ -error: you should put `foo_bar` between ticks in the documentation - --> $DIR/doc.rs:8:9 - | -LL | /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) - | ^^^^^^^ - | - = note: `-D clippy::doc-markdown` implied by `-D warnings` - -error: you should put `foo::bar` between ticks in the documentation - --> $DIR/doc.rs:8:51 - | -LL | /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) - | ^^^^^^^^ - -error: you should put `Foo::some_fun` between ticks in the documentation - --> $DIR/doc.rs:9:83 - | -LL | /// Markdown is _weird_. I mean _really weird_. This /_ is ok. So is `_`. But not Foo::some_fun - | ^^^^^^^^^^^^^ - -error: you should put `a::global:path` between ticks in the documentation - --> $DIR/doc.rs:11:15 - | -LL | /// Here be ::a::global:path. - | ^^^^^^^^^^^^^^ - -error: you should put `NotInCodeBlock` between ticks in the documentation - --> $DIR/doc.rs:12:22 - | -LL | /// That's not code ~NotInCodeBlock~. - | ^^^^^^^^^^^^^^ - -error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation - --> $DIR/doc.rs:13:5 - | -LL | /// be_sure_we_got_to_the_end_of_it - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation - --> $DIR/doc.rs:27:5 - | -LL | /// be_sure_we_got_to_the_end_of_it - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation - --> $DIR/doc.rs:34:5 - | -LL | /// be_sure_we_got_to_the_end_of_it - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation - --> $DIR/doc.rs:48:5 - | -LL | /// be_sure_we_got_to_the_end_of_it - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation - --> $DIR/doc.rs:58:5 - | -LL | /// be_sure_we_got_to_the_end_of_it - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: you should put `link_with_underscores` between ticks in the documentation - --> $DIR/doc.rs:62:22 - | -LL | /// This test has [a link_with_underscores][chunked-example] inside it. See #823. - | ^^^^^^^^^^^^^^^^^^^^^ - -error: you should put `inline_link2` between ticks in the documentation - --> $DIR/doc.rs:65:21 - | -LL | /// It can also be [inline_link2]. - | ^^^^^^^^^^^^ - -error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation - --> $DIR/doc.rs:75:5 - | -LL | /// be_sure_we_got_to_the_end_of_it - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: you should put `CamelCaseThing` between ticks in the documentation - --> $DIR/doc.rs:83:8 - | -LL | /// ## CamelCaseThing - | ^^^^^^^^^^^^^^ - -error: you should put `CamelCaseThing` between ticks in the documentation - --> $DIR/doc.rs:86:7 - | -LL | /// # CamelCaseThing - | ^^^^^^^^^^^^^^ - -error: you should put `CamelCaseThing` between ticks in the documentation - --> $DIR/doc.rs:88:22 - | -LL | /// Not a title #897 CamelCaseThing - | ^^^^^^^^^^^^^^ - -error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation - --> $DIR/doc.rs:89:5 - | -LL | /// be_sure_we_got_to_the_end_of_it - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation - --> $DIR/doc.rs:96:5 - | -LL | /// be_sure_we_got_to_the_end_of_it - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation - --> $DIR/doc.rs:109:5 - | -LL | /// be_sure_we_got_to_the_end_of_it - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: you should put `FooBar` between ticks in the documentation - --> $DIR/doc.rs:120:43 - | -LL | /** E.g., serialization of an empty list: FooBar - | ^^^^^^ - -error: you should put `BarQuz` between ticks in the documentation - --> $DIR/doc.rs:125:5 - | -LL | And BarQuz too. - | ^^^^^^ - -error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation - --> $DIR/doc.rs:126:1 - | -LL | be_sure_we_got_to_the_end_of_it - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: you should put `FooBar` between ticks in the documentation - --> $DIR/doc.rs:131:43 - | -LL | /** E.g., serialization of an empty list: FooBar - | ^^^^^^ - -error: you should put `BarQuz` between ticks in the documentation - --> $DIR/doc.rs:136:5 - | -LL | And BarQuz too. - | ^^^^^^ - -error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation - --> $DIR/doc.rs:137:1 - | -LL | be_sure_we_got_to_the_end_of_it - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation - --> $DIR/doc.rs:148:5 - | -LL | /// be_sure_we_got_to_the_end_of_it - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: you should put bare URLs between `<`/`>` or make a proper Markdown link - --> $DIR/doc.rs:175:13 - | -LL | /// Not ok: http://www.unicode.org - | ^^^^^^^^^^^^^^^^^^^^^^ - -error: you should put bare URLs between `<`/`>` or make a proper Markdown link - --> $DIR/doc.rs:176:13 - | -LL | /// Not ok: https://www.unicode.org - | ^^^^^^^^^^^^^^^^^^^^^^^ - -error: you should put bare URLs between `<`/`>` or make a proper Markdown link - --> $DIR/doc.rs:177:13 - | -LL | /// Not ok: http://www.unicode.org/ - | ^^^^^^^^^^^^^^^^^^^^^^ - -error: you should put bare URLs between `<`/`>` or make a proper Markdown link - --> $DIR/doc.rs:178:13 - | -LL | /// Not ok: http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: you should put `mycrate::Collection` between ticks in the documentation - --> $DIR/doc.rs:181:22 - | -LL | /// An iterator over mycrate::Collection's values. - | ^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 31 previous errors - diff --git a/tests/ui/doc_errors.rs b/tests/ui/doc_errors.rs deleted file mode 100644 index c77a74a58f22..000000000000 --- a/tests/ui/doc_errors.rs +++ /dev/null @@ -1,105 +0,0 @@ -// edition:2018 -#![warn(clippy::missing_errors_doc)] -#![allow(clippy::result_unit_err)] -#![allow(clippy::unnecessary_wraps)] - -use std::io; - -pub fn pub_fn_missing_errors_header() -> Result<(), ()> { - unimplemented!(); -} - -pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> { - unimplemented!(); -} - -/// This is not sufficiently documented. -pub fn pub_fn_returning_io_result() -> io::Result<()> { - unimplemented!(); -} - -/// This is not sufficiently documented. -pub async fn async_pub_fn_returning_io_result() -> io::Result<()> { - unimplemented!(); -} - -/// # Errors -/// A description of the errors goes here. -pub fn pub_fn_with_errors_header() -> Result<(), ()> { - unimplemented!(); -} - -/// # Errors -/// A description of the errors goes here. -pub async fn async_pub_fn_with_errors_header() -> Result<(), ()> { - unimplemented!(); -} - -/// This function doesn't require the documentation because it is private -fn priv_fn_missing_errors_header() -> Result<(), ()> { - unimplemented!(); -} - -/// This function doesn't require the documentation because it is private -async fn async_priv_fn_missing_errors_header() -> Result<(), ()> { - unimplemented!(); -} - -pub struct Struct1; - -impl Struct1 { - /// This is not sufficiently documented. - pub fn pub_method_missing_errors_header() -> Result<(), ()> { - unimplemented!(); - } - - /// This is not sufficiently documented. - pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> { - unimplemented!(); - } - - /// # Errors - /// A description of the errors goes here. - pub fn pub_method_with_errors_header() -> Result<(), ()> { - unimplemented!(); - } - - /// # Errors - /// A description of the errors goes here. - pub async fn async_pub_method_with_errors_header() -> Result<(), ()> { - unimplemented!(); - } - - /// This function doesn't require the documentation because it is private. - fn priv_method_missing_errors_header() -> Result<(), ()> { - unimplemented!(); - } - - /// This function doesn't require the documentation because it is private. - async fn async_priv_method_missing_errors_header() -> Result<(), ()> { - unimplemented!(); - } -} - -pub trait Trait1 { - /// This is not sufficiently documented. - fn trait_method_missing_errors_header() -> Result<(), ()>; - - /// # Errors - /// A description of the errors goes here. - fn trait_method_with_errors_header() -> Result<(), ()>; -} - -impl Trait1 for Struct1 { - fn trait_method_missing_errors_header() -> Result<(), ()> { - unimplemented!(); - } - - fn trait_method_with_errors_header() -> Result<(), ()> { - unimplemented!(); - } -} - -fn main() -> Result<(), ()> { - Ok(()) -} diff --git a/tests/ui/doc_errors.stderr b/tests/ui/doc_errors.stderr deleted file mode 100644 index b5a81419daee..000000000000 --- a/tests/ui/doc_errors.stderr +++ /dev/null @@ -1,58 +0,0 @@ -error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:8:1 - | -LL | / pub fn pub_fn_missing_errors_header() -> Result<(), ()> { -LL | | unimplemented!(); -LL | | } - | |_^ - | - = note: `-D clippy::missing-errors-doc` implied by `-D warnings` - -error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:12:1 - | -LL | / pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> { -LL | | unimplemented!(); -LL | | } - | |_^ - -error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:17:1 - | -LL | / pub fn pub_fn_returning_io_result() -> io::Result<()> { -LL | | unimplemented!(); -LL | | } - | |_^ - -error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:22:1 - | -LL | / pub async fn async_pub_fn_returning_io_result() -> io::Result<()> { -LL | | unimplemented!(); -LL | | } - | |_^ - -error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:52:5 - | -LL | / pub fn pub_method_missing_errors_header() -> Result<(), ()> { -LL | | unimplemented!(); -LL | | } - | |_____^ - -error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:57:5 - | -LL | / pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> { -LL | | unimplemented!(); -LL | | } - | |_____^ - -error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:86:5 - | -LL | fn trait_method_missing_errors_header() -> Result<(), ()>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 7 previous errors - diff --git a/tests/ui/doc_unsafe.rs b/tests/ui/doc_unsafe.rs deleted file mode 100644 index 484aa72d59a2..000000000000 --- a/tests/ui/doc_unsafe.rs +++ /dev/null @@ -1,100 +0,0 @@ -// aux-build:doc_unsafe_macros.rs - -#[macro_use] -extern crate doc_unsafe_macros; - -/// This is not sufficiently documented -pub unsafe fn destroy_the_planet() { - unimplemented!(); -} - -/// This one is -/// -/// # Safety -/// -/// This function shouldn't be called unless the horsemen are ready -pub unsafe fn apocalypse(universe: &mut ()) { - unimplemented!(); -} - -/// This is a private function, so docs aren't necessary -unsafe fn you_dont_see_me() { - unimplemented!(); -} - -mod private_mod { - pub unsafe fn only_crate_wide_accessible() { - unimplemented!(); - } - - pub unsafe fn republished() { - unimplemented!(); - } -} - -pub use private_mod::republished; - -pub trait UnsafeTrait { - unsafe fn woefully_underdocumented(self); - - /// # Safety - unsafe fn at_least_somewhat_documented(self); -} - -pub struct Struct; - -impl UnsafeTrait for Struct { - unsafe fn woefully_underdocumented(self) { - // all is well - } - - unsafe fn at_least_somewhat_documented(self) { - // all is still well - } -} - -impl Struct { - pub unsafe fn more_undocumented_unsafe() -> Self { - unimplemented!(); - } - - /// # Safety - pub unsafe fn somewhat_documented(&self) { - unimplemented!(); - } - - unsafe fn private(&self) { - unimplemented!(); - } -} - -macro_rules! very_unsafe { - () => { - pub unsafe fn whee() { - unimplemented!() - } - - /// # Safety - /// - /// Please keep the seat belt fastened - pub unsafe fn drive() { - whee() - } - }; -} - -very_unsafe!(); - -// we don't lint code from external macros -undocd_unsafe!(); - -fn main() { - unsafe { - you_dont_see_me(); - destroy_the_planet(); - let mut universe = (); - apocalypse(&mut universe); - private_mod::only_crate_wide_accessible(); - drive(); - } -} diff --git a/tests/ui/doc_unsafe.stderr b/tests/ui/doc_unsafe.stderr deleted file mode 100644 index c784d41ba172..000000000000 --- a/tests/ui/doc_unsafe.stderr +++ /dev/null @@ -1,47 +0,0 @@ -error: unsafe function's docs miss `# Safety` section - --> $DIR/doc_unsafe.rs:7:1 - | -LL | / pub unsafe fn destroy_the_planet() { -LL | | unimplemented!(); -LL | | } - | |_^ - | - = note: `-D clippy::missing-safety-doc` implied by `-D warnings` - -error: unsafe function's docs miss `# Safety` section - --> $DIR/doc_unsafe.rs:30:5 - | -LL | / pub unsafe fn republished() { -LL | | unimplemented!(); -LL | | } - | |_____^ - -error: unsafe function's docs miss `# Safety` section - --> $DIR/doc_unsafe.rs:38:5 - | -LL | unsafe fn woefully_underdocumented(self); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: unsafe function's docs miss `# Safety` section - --> $DIR/doc_unsafe.rs:57:5 - | -LL | / pub unsafe fn more_undocumented_unsafe() -> Self { -LL | | unimplemented!(); -LL | | } - | |_____^ - -error: unsafe function's docs miss `# Safety` section - --> $DIR/doc_unsafe.rs:73:9 - | -LL | / pub unsafe fn whee() { -LL | | unimplemented!() -LL | | } - | |_________^ -... -LL | very_unsafe!(); - | --------------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 5 previous errors - diff --git a/tests/ui/double_comparison.fixed b/tests/ui/double_comparison.fixed deleted file mode 100644 index bb6cdaa667d4..000000000000 --- a/tests/ui/double_comparison.fixed +++ /dev/null @@ -1,30 +0,0 @@ -// run-rustfix - -fn main() { - let x = 1; - let y = 2; - if x <= y { - // do something - } - if x <= y { - // do something - } - if x >= y { - // do something - } - if x >= y { - // do something - } - if x != y { - // do something - } - if x != y { - // do something - } - if x == y { - // do something - } - if x == y { - // do something - } -} diff --git a/tests/ui/double_comparison.rs b/tests/ui/double_comparison.rs deleted file mode 100644 index 9a2a9068a28d..000000000000 --- a/tests/ui/double_comparison.rs +++ /dev/null @@ -1,30 +0,0 @@ -// run-rustfix - -fn main() { - let x = 1; - let y = 2; - if x == y || x < y { - // do something - } - if x < y || x == y { - // do something - } - if x == y || x > y { - // do something - } - if x > y || x == y { - // do something - } - if x < y || x > y { - // do something - } - if x > y || x < y { - // do something - } - if x <= y && x >= y { - // do something - } - if x >= y && x <= y { - // do something - } -} diff --git a/tests/ui/double_comparison.stderr b/tests/ui/double_comparison.stderr deleted file mode 100644 index 05ef4e25f7f8..000000000000 --- a/tests/ui/double_comparison.stderr +++ /dev/null @@ -1,52 +0,0 @@ -error: this binary expression can be simplified - --> $DIR/double_comparison.rs:6:8 - | -LL | if x == y || x < y { - | ^^^^^^^^^^^^^^^ help: try: `x <= y` - | - = note: `-D clippy::double-comparisons` implied by `-D warnings` - -error: this binary expression can be simplified - --> $DIR/double_comparison.rs:9:8 - | -LL | if x < y || x == y { - | ^^^^^^^^^^^^^^^ help: try: `x <= y` - -error: this binary expression can be simplified - --> $DIR/double_comparison.rs:12:8 - | -LL | if x == y || x > y { - | ^^^^^^^^^^^^^^^ help: try: `x >= y` - -error: this binary expression can be simplified - --> $DIR/double_comparison.rs:15:8 - | -LL | if x > y || x == y { - | ^^^^^^^^^^^^^^^ help: try: `x >= y` - -error: this binary expression can be simplified - --> $DIR/double_comparison.rs:18:8 - | -LL | if x < y || x > y { - | ^^^^^^^^^^^^^^ help: try: `x != y` - -error: this binary expression can be simplified - --> $DIR/double_comparison.rs:21:8 - | -LL | if x > y || x < y { - | ^^^^^^^^^^^^^^ help: try: `x != y` - -error: this binary expression can be simplified - --> $DIR/double_comparison.rs:24:8 - | -LL | if x <= y && x >= y { - | ^^^^^^^^^^^^^^^^ help: try: `x == y` - -error: this binary expression can be simplified - --> $DIR/double_comparison.rs:27:8 - | -LL | if x >= y && x <= y { - | ^^^^^^^^^^^^^^^^ help: try: `x == y` - -error: aborting due to 8 previous errors - diff --git a/tests/ui/double_must_use.rs b/tests/ui/double_must_use.rs deleted file mode 100644 index 05e087b08bc1..000000000000 --- a/tests/ui/double_must_use.rs +++ /dev/null @@ -1,28 +0,0 @@ -#![warn(clippy::double_must_use)] -#![allow(clippy::result_unit_err)] - -#[must_use] -pub fn must_use_result() -> Result<(), ()> { - unimplemented!(); -} - -#[must_use] -pub fn must_use_tuple() -> (Result<(), ()>, u8) { - unimplemented!(); -} - -#[must_use] -pub fn must_use_array() -> [Result<(), ()>; 1] { - unimplemented!(); -} - -#[must_use = "With note"] -pub fn must_use_with_note() -> Result<(), ()> { - unimplemented!(); -} - -fn main() { - must_use_result(); - must_use_tuple(); - must_use_with_note(); -} diff --git a/tests/ui/double_must_use.stderr b/tests/ui/double_must_use.stderr deleted file mode 100644 index 8290ece1cad1..000000000000 --- a/tests/ui/double_must_use.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]` - --> $DIR/double_must_use.rs:5:1 - | -LL | pub fn must_use_result() -> Result<(), ()> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::double-must-use` implied by `-D warnings` - = help: either add some descriptive text or remove the attribute - -error: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]` - --> $DIR/double_must_use.rs:10:1 - | -LL | pub fn must_use_tuple() -> (Result<(), ()>, u8) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: either add some descriptive text or remove the attribute - -error: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]` - --> $DIR/double_must_use.rs:15:1 - | -LL | pub fn must_use_array() -> [Result<(), ()>; 1] { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: either add some descriptive text or remove the attribute - -error: aborting due to 3 previous errors - diff --git a/tests/ui/double_neg.rs b/tests/ui/double_neg.rs deleted file mode 100644 index d47dfcb5ba1e..000000000000 --- a/tests/ui/double_neg.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[warn(clippy::double_neg)] -fn main() { - let x = 1; - -x; - -(-x); - --x; -} diff --git a/tests/ui/double_neg.stderr b/tests/ui/double_neg.stderr deleted file mode 100644 index d82ed05f0543..000000000000 --- a/tests/ui/double_neg.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: `--x` could be misinterpreted as pre-decrement by C programmers, is usually a no-op - --> $DIR/double_neg.rs:6:5 - | -LL | --x; - | ^^^ - | - = note: `-D clippy::double-neg` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/double_parens.rs b/tests/ui/double_parens.rs deleted file mode 100644 index ff1dc76ab63b..000000000000 --- a/tests/ui/double_parens.rs +++ /dev/null @@ -1,56 +0,0 @@ -#![warn(clippy::double_parens)] -#![allow(dead_code, clippy::eq_op)] -#![feature(custom_inner_attributes)] -#![rustfmt::skip] - -fn dummy_fn(_: T) {} - -struct DummyStruct; - -impl DummyStruct { - fn dummy_method(self, _: T) {} -} - -fn simple_double_parens() -> i32 { - ((0)) -} - -fn fn_double_parens() { - dummy_fn((0)); -} - -fn method_double_parens(x: DummyStruct) { - x.dummy_method((0)); -} - -fn tuple_double_parens() -> (i32, i32) { - ((1, 2)) -} - -fn unit_double_parens() { - (()) -} - -fn fn_tuple_ok() { - dummy_fn((1, 2)); -} - -fn method_tuple_ok(x: DummyStruct) { - x.dummy_method((1, 2)); -} - -fn fn_unit_ok() { - dummy_fn(()); -} - -fn method_unit_ok(x: DummyStruct) { - x.dummy_method(()); -} - -// Issue #3206 -fn inside_macro() { - assert_eq!((1, 2), (1, 2), "Error"); - assert_eq!(((1, 2)), (1, 2), "Error"); -} - -fn main() {} diff --git a/tests/ui/double_parens.stderr b/tests/ui/double_parens.stderr deleted file mode 100644 index 40fcad2ab1d4..000000000000 --- a/tests/ui/double_parens.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:15:5 - | -LL | ((0)) - | ^^^^^ - | - = note: `-D clippy::double-parens` implied by `-D warnings` - -error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:19:14 - | -LL | dummy_fn((0)); - | ^^^ - -error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:23:20 - | -LL | x.dummy_method((0)); - | ^^^ - -error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:27:5 - | -LL | ((1, 2)) - | ^^^^^^^^ - -error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:31:5 - | -LL | (()) - | ^^^^ - -error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:53:16 - | -LL | assert_eq!(((1, 2)), (1, 2), "Error"); - | ^^^^^^^^ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/drop_forget_copy.rs b/tests/ui/drop_forget_copy.rs deleted file mode 100644 index 9ddd6d64701a..000000000000 --- a/tests/ui/drop_forget_copy.rs +++ /dev/null @@ -1,66 +0,0 @@ -#![warn(clippy::drop_copy, clippy::forget_copy)] -#![allow(clippy::toplevel_ref_arg, clippy::drop_ref, clippy::forget_ref, unused_mut)] - -use std::mem::{drop, forget}; -use std::vec::Vec; - -#[derive(Copy, Clone)] -struct SomeStruct {} - -struct AnotherStruct { - x: u8, - y: u8, - z: Vec, -} - -impl Clone for AnotherStruct { - fn clone(&self) -> AnotherStruct { - AnotherStruct { - x: self.x, - y: self.y, - z: self.z.clone(), - } - } -} - -fn main() { - let s1 = SomeStruct {}; - let s2 = s1; - let s3 = &s1; - let mut s4 = s1; - let ref s5 = s1; - - drop(s1); - drop(s2); - drop(s3); - drop(s4); - drop(s5); - - forget(s1); - forget(s2); - forget(s3); - forget(s4); - forget(s5); - - let a1 = AnotherStruct { - x: 255, - y: 0, - z: vec![1, 2, 3], - }; - let a2 = &a1; - let mut a3 = a1.clone(); - let ref a4 = a1; - let a5 = a1.clone(); - - drop(a2); - drop(a3); - drop(a4); - drop(a5); - - forget(a2); - let a3 = &a1; - forget(a3); - forget(a4); - let a5 = a1.clone(); - forget(a5); -} diff --git a/tests/ui/drop_forget_copy.stderr b/tests/ui/drop_forget_copy.stderr deleted file mode 100644 index 82a4f047ba85..000000000000 --- a/tests/ui/drop_forget_copy.stderr +++ /dev/null @@ -1,76 +0,0 @@ -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact. - --> $DIR/drop_forget_copy.rs:33:5 - | -LL | drop(s1); - | ^^^^^^^^ - | - = note: `-D clippy::drop-copy` implied by `-D warnings` -note: argument has type SomeStruct - --> $DIR/drop_forget_copy.rs:33:10 - | -LL | drop(s1); - | ^^ - -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact. - --> $DIR/drop_forget_copy.rs:34:5 - | -LL | drop(s2); - | ^^^^^^^^ - | -note: argument has type SomeStruct - --> $DIR/drop_forget_copy.rs:34:10 - | -LL | drop(s2); - | ^^ - -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact. - --> $DIR/drop_forget_copy.rs:36:5 - | -LL | drop(s4); - | ^^^^^^^^ - | -note: argument has type SomeStruct - --> $DIR/drop_forget_copy.rs:36:10 - | -LL | drop(s4); - | ^^ - -error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact. - --> $DIR/drop_forget_copy.rs:39:5 - | -LL | forget(s1); - | ^^^^^^^^^^ - | - = note: `-D clippy::forget-copy` implied by `-D warnings` -note: argument has type SomeStruct - --> $DIR/drop_forget_copy.rs:39:12 - | -LL | forget(s1); - | ^^ - -error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact. - --> $DIR/drop_forget_copy.rs:40:5 - | -LL | forget(s2); - | ^^^^^^^^^^ - | -note: argument has type SomeStruct - --> $DIR/drop_forget_copy.rs:40:12 - | -LL | forget(s2); - | ^^ - -error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact. - --> $DIR/drop_forget_copy.rs:42:5 - | -LL | forget(s4); - | ^^^^^^^^^^ - | -note: argument has type SomeStruct - --> $DIR/drop_forget_copy.rs:42:12 - | -LL | forget(s4); - | ^^ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/drop_ref.rs b/tests/ui/drop_ref.rs deleted file mode 100644 index e1a15c609fd2..000000000000 --- a/tests/ui/drop_ref.rs +++ /dev/null @@ -1,74 +0,0 @@ -#![warn(clippy::drop_ref)] -#![allow(clippy::toplevel_ref_arg)] -#![allow(clippy::map_err_ignore)] -#![allow(clippy::unnecessary_wraps)] - -use std::mem::drop; - -struct SomeStruct; - -fn main() { - drop(&SomeStruct); - - let mut owned1 = SomeStruct; - drop(&owned1); - drop(&&owned1); - drop(&mut owned1); - drop(owned1); //OK - - let reference1 = &SomeStruct; - drop(reference1); - - let reference2 = &mut SomeStruct; - drop(reference2); - - let ref reference3 = SomeStruct; - drop(reference3); -} - -#[allow(dead_code)] -fn test_generic_fn_drop(val: T) { - drop(&val); - drop(val); //OK -} - -#[allow(dead_code)] -fn test_similarly_named_function() { - fn drop(_val: T) {} - drop(&SomeStruct); //OK; call to unrelated function which happens to have the same name - std::mem::drop(&SomeStruct); -} - -#[derive(Copy, Clone)] -pub struct Error; -fn produce_half_owl_error() -> Result<(), Error> { - Ok(()) -} - -fn produce_half_owl_ok() -> Result { - Ok(true) -} - -#[allow(dead_code)] -fn test_owl_result() -> Result<(), ()> { - produce_half_owl_error().map_err(|_| ())?; - produce_half_owl_ok().map(|_| ())?; - // the following should not be linted, - // we should not force users to use toilet closures - // to produce owl results when drop is more convenient - produce_half_owl_error().map_err(drop)?; - produce_half_owl_ok().map_err(drop)?; - Ok(()) -} - -#[allow(dead_code)] -fn test_owl_result_2() -> Result { - produce_half_owl_error().map_err(|_| ())?; - produce_half_owl_ok().map(|_| ())?; - // the following should not be linted, - // we should not force users to use toilet closures - // to produce owl results when drop is more convenient - produce_half_owl_error().map_err(drop)?; - produce_half_owl_ok().map(drop)?; - Ok(1) -} diff --git a/tests/ui/drop_ref.stderr b/tests/ui/drop_ref.stderr deleted file mode 100644 index 10087cb4820a..000000000000 --- a/tests/ui/drop_ref.stderr +++ /dev/null @@ -1,111 +0,0 @@ -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing. - --> $DIR/drop_ref.rs:11:5 - | -LL | drop(&SomeStruct); - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::drop-ref` implied by `-D warnings` -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:11:10 - | -LL | drop(&SomeStruct); - | ^^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing. - --> $DIR/drop_ref.rs:14:5 - | -LL | drop(&owned1); - | ^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:14:10 - | -LL | drop(&owned1); - | ^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing. - --> $DIR/drop_ref.rs:15:5 - | -LL | drop(&&owned1); - | ^^^^^^^^^^^^^^ - | -note: argument has type `&&SomeStruct` - --> $DIR/drop_ref.rs:15:10 - | -LL | drop(&&owned1); - | ^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing. - --> $DIR/drop_ref.rs:16:5 - | -LL | drop(&mut owned1); - | ^^^^^^^^^^^^^^^^^ - | -note: argument has type `&mut SomeStruct` - --> $DIR/drop_ref.rs:16:10 - | -LL | drop(&mut owned1); - | ^^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing. - --> $DIR/drop_ref.rs:20:5 - | -LL | drop(reference1); - | ^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:20:10 - | -LL | drop(reference1); - | ^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing. - --> $DIR/drop_ref.rs:23:5 - | -LL | drop(reference2); - | ^^^^^^^^^^^^^^^^ - | -note: argument has type `&mut SomeStruct` - --> $DIR/drop_ref.rs:23:10 - | -LL | drop(reference2); - | ^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing. - --> $DIR/drop_ref.rs:26:5 - | -LL | drop(reference3); - | ^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:26:10 - | -LL | drop(reference3); - | ^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing. - --> $DIR/drop_ref.rs:31:5 - | -LL | drop(&val); - | ^^^^^^^^^^ - | -note: argument has type `&T` - --> $DIR/drop_ref.rs:31:10 - | -LL | drop(&val); - | ^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing. - --> $DIR/drop_ref.rs:39:5 - | -LL | std::mem::drop(&SomeStruct); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:39:20 - | -LL | std::mem::drop(&SomeStruct); - | ^^^^^^^^^^^ - -error: aborting due to 9 previous errors - diff --git a/tests/ui/duplicate_underscore_argument.rs b/tests/ui/duplicate_underscore_argument.rs deleted file mode 100644 index 54d748c7ce28..000000000000 --- a/tests/ui/duplicate_underscore_argument.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![warn(clippy::duplicate_underscore_argument)] -#[allow(dead_code, unused)] - -fn join_the_dark_side(darth: i32, _darth: i32) {} -fn join_the_light_side(knight: i32, _master: i32) {} // the Force is strong with this one - -fn main() { - join_the_dark_side(0, 0); - join_the_light_side(0, 0); -} diff --git a/tests/ui/duplicate_underscore_argument.stderr b/tests/ui/duplicate_underscore_argument.stderr deleted file mode 100644 index f71614a5fd16..000000000000 --- a/tests/ui/duplicate_underscore_argument.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: `darth` already exists, having another argument having almost the same name makes code comprehension and documentation more difficult - --> $DIR/duplicate_underscore_argument.rs:4:23 - | -LL | fn join_the_dark_side(darth: i32, _darth: i32) {} - | ^^^^^ - | - = note: `-D clippy::duplicate-underscore-argument` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/duration_subsec.fixed b/tests/ui/duration_subsec.fixed deleted file mode 100644 index ee5c7863effc..000000000000 --- a/tests/ui/duration_subsec.fixed +++ /dev/null @@ -1,29 +0,0 @@ -// run-rustfix -#![allow(dead_code)] -#![warn(clippy::duration_subsec)] - -use std::time::Duration; - -fn main() { - let dur = Duration::new(5, 0); - - let bad_millis_1 = dur.subsec_millis(); - let bad_millis_2 = dur.subsec_millis(); - let good_millis = dur.subsec_millis(); - assert_eq!(bad_millis_1, good_millis); - assert_eq!(bad_millis_2, good_millis); - - let bad_micros = dur.subsec_micros(); - let good_micros = dur.subsec_micros(); - assert_eq!(bad_micros, good_micros); - - // Handle refs - let _ = (&dur).subsec_micros(); - - // Handle constants - const NANOS_IN_MICRO: u32 = 1_000; - let _ = dur.subsec_micros(); - - // Other literals aren't linted - let _ = dur.subsec_nanos() / 699; -} diff --git a/tests/ui/duration_subsec.rs b/tests/ui/duration_subsec.rs deleted file mode 100644 index 3c9d2a286211..000000000000 --- a/tests/ui/duration_subsec.rs +++ /dev/null @@ -1,29 +0,0 @@ -// run-rustfix -#![allow(dead_code)] -#![warn(clippy::duration_subsec)] - -use std::time::Duration; - -fn main() { - let dur = Duration::new(5, 0); - - let bad_millis_1 = dur.subsec_micros() / 1_000; - let bad_millis_2 = dur.subsec_nanos() / 1_000_000; - let good_millis = dur.subsec_millis(); - assert_eq!(bad_millis_1, good_millis); - assert_eq!(bad_millis_2, good_millis); - - let bad_micros = dur.subsec_nanos() / 1_000; - let good_micros = dur.subsec_micros(); - assert_eq!(bad_micros, good_micros); - - // Handle refs - let _ = (&dur).subsec_nanos() / 1_000; - - // Handle constants - const NANOS_IN_MICRO: u32 = 1_000; - let _ = dur.subsec_nanos() / NANOS_IN_MICRO; - - // Other literals aren't linted - let _ = dur.subsec_nanos() / 699; -} diff --git a/tests/ui/duration_subsec.stderr b/tests/ui/duration_subsec.stderr deleted file mode 100644 index cdbeff6a0378..000000000000 --- a/tests/ui/duration_subsec.stderr +++ /dev/null @@ -1,34 +0,0 @@ -error: calling `subsec_millis()` is more concise than this calculation - --> $DIR/duration_subsec.rs:10:24 - | -LL | let bad_millis_1 = dur.subsec_micros() / 1_000; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_millis()` - | - = note: `-D clippy::duration-subsec` implied by `-D warnings` - -error: calling `subsec_millis()` is more concise than this calculation - --> $DIR/duration_subsec.rs:11:24 - | -LL | let bad_millis_2 = dur.subsec_nanos() / 1_000_000; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_millis()` - -error: calling `subsec_micros()` is more concise than this calculation - --> $DIR/duration_subsec.rs:16:22 - | -LL | let bad_micros = dur.subsec_nanos() / 1_000; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_micros()` - -error: calling `subsec_micros()` is more concise than this calculation - --> $DIR/duration_subsec.rs:21:13 - | -LL | let _ = (&dur).subsec_nanos() / 1_000; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(&dur).subsec_micros()` - -error: calling `subsec_micros()` is more concise than this calculation - --> $DIR/duration_subsec.rs:25:13 - | -LL | let _ = dur.subsec_nanos() / NANOS_IN_MICRO; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_micros()` - -error: aborting due to 5 previous errors - diff --git a/tests/ui/else_if_without_else.rs b/tests/ui/else_if_without_else.rs deleted file mode 100644 index 879b3ac398e4..000000000000 --- a/tests/ui/else_if_without_else.rs +++ /dev/null @@ -1,58 +0,0 @@ -#![warn(clippy::all)] -#![warn(clippy::else_if_without_else)] - -fn bla1() -> bool { - unimplemented!() -} -fn bla2() -> bool { - unimplemented!() -} -fn bla3() -> bool { - unimplemented!() -} - -fn main() { - if bla1() { - println!("if"); - } - - if bla1() { - println!("if"); - } else { - println!("else"); - } - - if bla1() { - println!("if"); - } else if bla2() { - println!("else if"); - } else { - println!("else") - } - - if bla1() { - println!("if"); - } else if bla2() { - println!("else if 1"); - } else if bla3() { - println!("else if 2"); - } else { - println!("else") - } - - if bla1() { - println!("if"); - } else if bla2() { - //~ ERROR else if without else - println!("else if"); - } - - if bla1() { - println!("if"); - } else if bla2() { - println!("else if 1"); - } else if bla3() { - //~ ERROR else if without else - println!("else if 2"); - } -} diff --git a/tests/ui/else_if_without_else.stderr b/tests/ui/else_if_without_else.stderr deleted file mode 100644 index 6f47658cfb18..000000000000 --- a/tests/ui/else_if_without_else.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error: `if` expression with an `else if`, but without a final `else` - --> $DIR/else_if_without_else.rs:45:12 - | -LL | } else if bla2() { - | ____________^ -LL | | //~ ERROR else if without else -LL | | println!("else if"); -LL | | } - | |_____^ - | - = note: `-D clippy::else-if-without-else` implied by `-D warnings` - = help: add an `else` block here - -error: `if` expression with an `else if`, but without a final `else` - --> $DIR/else_if_without_else.rs:54:12 - | -LL | } else if bla3() { - | ____________^ -LL | | //~ ERROR else if without else -LL | | println!("else if 2"); -LL | | } - | |_____^ - | - = help: add an `else` block here - -error: aborting due to 2 previous errors - diff --git a/tests/ui/empty_enum.rs b/tests/ui/empty_enum.rs deleted file mode 100644 index 12428f29625c..000000000000 --- a/tests/ui/empty_enum.rs +++ /dev/null @@ -1,6 +0,0 @@ -#![allow(dead_code)] -#![warn(clippy::empty_enum)] - -enum Empty {} - -fn main() {} diff --git a/tests/ui/empty_enum.stderr b/tests/ui/empty_enum.stderr deleted file mode 100644 index 466dfbe7cee7..000000000000 --- a/tests/ui/empty_enum.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: enum with no variants - --> $DIR/empty_enum.rs:4:1 - | -LL | enum Empty {} - | ^^^^^^^^^^^^^ - | - = note: `-D clippy::empty-enum` implied by `-D warnings` - = help: consider using the uninhabited type `!` (never type) or a wrapper around it to introduce a type which can't be instantiated - -error: aborting due to previous error - diff --git a/tests/ui/empty_line_after_outer_attribute.rs b/tests/ui/empty_line_after_outer_attribute.rs deleted file mode 100644 index 3e92bca986ab..000000000000 --- a/tests/ui/empty_line_after_outer_attribute.rs +++ /dev/null @@ -1,113 +0,0 @@ -// aux-build:proc_macro_attr.rs -#![warn(clippy::empty_line_after_outer_attr)] -#![allow(clippy::assertions_on_constants)] -#![feature(custom_inner_attributes)] -#![rustfmt::skip] - -#[macro_use] -extern crate proc_macro_attr; - -// This should produce a warning -#[crate_type = "lib"] - -/// some comment -fn with_one_newline_and_comment() { assert!(true) } - -// This should not produce a warning -#[crate_type = "lib"] -/// some comment -fn with_no_newline_and_comment() { assert!(true) } - - -// This should produce a warning -#[crate_type = "lib"] - -fn with_one_newline() { assert!(true) } - -// This should produce a warning, too -#[crate_type = "lib"] - - -fn with_two_newlines() { assert!(true) } - - -// This should produce a warning -#[crate_type = "lib"] - -enum Baz { - One, - Two -} - -// This should produce a warning -#[crate_type = "lib"] - -struct Foo { - one: isize, - two: isize -} - -// This should produce a warning -#[crate_type = "lib"] - -mod foo { -} - -/// This doc comment should not produce a warning - -/** This is also a doc comment and should not produce a warning - */ - -// This should not produce a warning -#[allow(non_camel_case_types)] -#[allow(missing_docs)] -#[allow(missing_docs)] -fn three_attributes() { assert!(true) } - -// This should not produce a warning -#[doc = " -Returns the escaped value of the textual representation of - -"] -pub fn function() -> bool { - true -} - -// This should not produce a warning -#[derive(Clone, Copy)] -pub enum FooFighter { - Bar1, - - Bar2, - - Bar3, - - Bar4 -} - -// This should not produce a warning because the empty line is inside a block comment -#[crate_type = "lib"] -/* - -*/ -pub struct S; - -// This should not produce a warning -#[crate_type = "lib"] -/* test */ -pub struct T; - -// This should not produce a warning -// See https://github.com/rust-lang/rust-clippy/issues/5567 -#[fake_async_trait] -pub trait Bazz { - fn foo() -> Vec { - let _i = ""; - - - - vec![] - } -} - -fn main() {} diff --git a/tests/ui/empty_line_after_outer_attribute.stderr b/tests/ui/empty_line_after_outer_attribute.stderr deleted file mode 100644 index 594fca44a321..000000000000 --- a/tests/ui/empty_line_after_outer_attribute.stderr +++ /dev/null @@ -1,54 +0,0 @@ -error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:11:1 - | -LL | / #[crate_type = "lib"] -LL | | -LL | | /// some comment -LL | | fn with_one_newline_and_comment() { assert!(true) } - | |_ - | - = note: `-D clippy::empty-line-after-outer-attr` implied by `-D warnings` - -error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:23:1 - | -LL | / #[crate_type = "lib"] -LL | | -LL | | fn with_one_newline() { assert!(true) } - | |_ - -error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:28:1 - | -LL | / #[crate_type = "lib"] -LL | | -LL | | -LL | | fn with_two_newlines() { assert!(true) } - | |_ - -error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:35:1 - | -LL | / #[crate_type = "lib"] -LL | | -LL | | enum Baz { - | |_ - -error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:43:1 - | -LL | / #[crate_type = "lib"] -LL | | -LL | | struct Foo { - | |_ - -error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:51:1 - | -LL | / #[crate_type = "lib"] -LL | | -LL | | mod foo { - | |_ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/empty_loop.rs b/tests/ui/empty_loop.rs deleted file mode 100644 index 8fd7697eb3b2..000000000000 --- a/tests/ui/empty_loop.rs +++ /dev/null @@ -1,51 +0,0 @@ -// aux-build:macro_rules.rs - -#![warn(clippy::empty_loop)] - -#[macro_use] -extern crate macro_rules; - -fn should_trigger() { - loop {} - loop { - loop {} - } - - 'outer: loop { - 'inner: loop {} - } -} - -fn should_not_trigger() { - loop { - panic!("This is fine") - } - let ten_millis = std::time::Duration::from_millis(10); - loop { - std::thread::sleep(ten_millis) - } - - #[allow(clippy::never_loop)] - 'outer: loop { - 'inner: loop { - break 'inner; - } - break 'outer; - } - - // Make sure `allow` works for this lint - #[allow(clippy::empty_loop)] - loop {} - - // We don't lint loops inside macros - macro_rules! foo { - () => { - loop {} - }; - } - - // We don't lint external macros - foofoo!() -} - -fn main() {} diff --git a/tests/ui/empty_loop.stderr b/tests/ui/empty_loop.stderr deleted file mode 100644 index 555f3d3d884a..000000000000 --- a/tests/ui/empty_loop.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error: empty `loop {}` wastes CPU cycles - --> $DIR/empty_loop.rs:9:5 - | -LL | loop {} - | ^^^^^^^ - | - = note: `-D clippy::empty-loop` implied by `-D warnings` - = help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body - -error: empty `loop {}` wastes CPU cycles - --> $DIR/empty_loop.rs:11:9 - | -LL | loop {} - | ^^^^^^^ - | - = help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body - -error: empty `loop {}` wastes CPU cycles - --> $DIR/empty_loop.rs:15:9 - | -LL | 'inner: loop {} - | ^^^^^^^^^^^^^^^ - | - = help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body - -error: aborting due to 3 previous errors - diff --git a/tests/ui/empty_loop_no_std.rs b/tests/ui/empty_loop_no_std.rs deleted file mode 100644 index 4553d3ec505a..000000000000 --- a/tests/ui/empty_loop_no_std.rs +++ /dev/null @@ -1,27 +0,0 @@ -// ignore-macos -// ignore-windows - -#![warn(clippy::empty_loop)] -#![feature(lang_items, link_args, start, libc)] -#![link_args = "-nostartfiles"] -#![no_std] - -use core::panic::PanicInfo; - -#[start] -fn main(argc: isize, argv: *const *const u8) -> isize { - // This should trigger the lint - loop {} -} - -#[panic_handler] -fn panic(_info: &PanicInfo) -> ! { - // This should NOT trigger the lint - loop {} -} - -#[lang = "eh_personality"] -extern "C" fn eh_personality() { - // This should also trigger the lint - loop {} -} diff --git a/tests/ui/empty_loop_no_std.stderr b/tests/ui/empty_loop_no_std.stderr deleted file mode 100644 index 520248fcb689..000000000000 --- a/tests/ui/empty_loop_no_std.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: empty `loop {}` wastes CPU cycles - --> $DIR/empty_loop_no_std.rs:14:5 - | -LL | loop {} - | ^^^^^^^ - | - = note: `-D clippy::empty-loop` implied by `-D warnings` - = help: you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body - -error: empty `loop {}` wastes CPU cycles - --> $DIR/empty_loop_no_std.rs:26:5 - | -LL | loop {} - | ^^^^^^^ - | - = help: you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body - -error: aborting due to 2 previous errors - diff --git a/tests/ui/entry_fixable.fixed b/tests/ui/entry_fixable.fixed deleted file mode 100644 index dcdaae7e7243..000000000000 --- a/tests/ui/entry_fixable.fixed +++ /dev/null @@ -1,15 +0,0 @@ -// run-rustfix - -#![allow(unused, clippy::needless_pass_by_value)] -#![warn(clippy::map_entry)] - -use std::collections::{BTreeMap, HashMap}; -use std::hash::Hash; - -fn foo() {} - -fn insert_if_absent0(m: &mut HashMap, k: K, v: V) { - m.entry(k).or_insert(v); -} - -fn main() {} diff --git a/tests/ui/entry_fixable.rs b/tests/ui/entry_fixable.rs deleted file mode 100644 index 55d5b21568d0..000000000000 --- a/tests/ui/entry_fixable.rs +++ /dev/null @@ -1,17 +0,0 @@ -// run-rustfix - -#![allow(unused, clippy::needless_pass_by_value)] -#![warn(clippy::map_entry)] - -use std::collections::{BTreeMap, HashMap}; -use std::hash::Hash; - -fn foo() {} - -fn insert_if_absent0(m: &mut HashMap, k: K, v: V) { - if !m.contains_key(&k) { - m.insert(k, v); - } -} - -fn main() {} diff --git a/tests/ui/entry_fixable.stderr b/tests/ui/entry_fixable.stderr deleted file mode 100644 index 87403200ced5..000000000000 --- a/tests/ui/entry_fixable.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_fixable.rs:12:5 - | -LL | / if !m.contains_key(&k) { -LL | | m.insert(k, v); -LL | | } - | |_____^ help: consider using: `m.entry(k).or_insert(v);` - | - = note: `-D clippy::map-entry` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/entry_unfixable.rs b/tests/ui/entry_unfixable.rs deleted file mode 100644 index f530fc023cfb..000000000000 --- a/tests/ui/entry_unfixable.rs +++ /dev/null @@ -1,73 +0,0 @@ -#![allow(unused, clippy::needless_pass_by_value)] -#![warn(clippy::map_entry)] - -use std::collections::{BTreeMap, HashMap}; -use std::hash::Hash; - -fn foo() {} - -fn insert_if_absent2(m: &mut HashMap, k: K, v: V) { - if !m.contains_key(&k) { - m.insert(k, v) - } else { - None - }; -} - -fn insert_if_present2(m: &mut HashMap, k: K, v: V) { - if m.contains_key(&k) { - None - } else { - m.insert(k, v) - }; -} - -fn insert_if_absent3(m: &mut HashMap, k: K, v: V) { - if !m.contains_key(&k) { - foo(); - m.insert(k, v) - } else { - None - }; -} - -fn insert_if_present3(m: &mut HashMap, k: K, v: V) { - if m.contains_key(&k) { - None - } else { - foo(); - m.insert(k, v) - }; -} - -fn insert_in_btreemap(m: &mut BTreeMap, k: K, v: V) { - if !m.contains_key(&k) { - foo(); - m.insert(k, v) - } else { - None - }; -} - -// should not trigger -fn insert_other_if_absent(m: &mut HashMap, k: K, o: K, v: V) { - if !m.contains_key(&k) { - m.insert(o, v); - } -} - -// should not trigger, because the one uses different HashMap from another one -fn insert_from_different_map(m: HashMap, n: &mut HashMap, k: K, v: V) { - if !m.contains_key(&k) { - n.insert(k, v); - } -} - -// should not trigger, because the one uses different HashMap from another one -fn insert_from_different_map2(m: &mut HashMap, n: &mut HashMap, k: K, v: V) { - if !m.contains_key(&k) { - n.insert(k, v); - } -} - -fn main() {} diff --git a/tests/ui/entry_unfixable.stderr b/tests/ui/entry_unfixable.stderr deleted file mode 100644 index e58c8d22dc45..000000000000 --- a/tests/ui/entry_unfixable.stderr +++ /dev/null @@ -1,57 +0,0 @@ -error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_unfixable.rs:10:5 - | -LL | / if !m.contains_key(&k) { -LL | | m.insert(k, v) -LL | | } else { -LL | | None -LL | | }; - | |_____^ consider using `m.entry(k)` - | - = note: `-D clippy::map-entry` implied by `-D warnings` - -error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_unfixable.rs:18:5 - | -LL | / if m.contains_key(&k) { -LL | | None -LL | | } else { -LL | | m.insert(k, v) -LL | | }; - | |_____^ consider using `m.entry(k)` - -error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_unfixable.rs:26:5 - | -LL | / if !m.contains_key(&k) { -LL | | foo(); -LL | | m.insert(k, v) -LL | | } else { -LL | | None -LL | | }; - | |_____^ consider using `m.entry(k)` - -error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_unfixable.rs:35:5 - | -LL | / if m.contains_key(&k) { -LL | | None -LL | | } else { -LL | | foo(); -LL | | m.insert(k, v) -LL | | }; - | |_____^ consider using `m.entry(k)` - -error: usage of `contains_key` followed by `insert` on a `BTreeMap` - --> $DIR/entry_unfixable.rs:44:5 - | -LL | / if !m.contains_key(&k) { -LL | | foo(); -LL | | m.insert(k, v) -LL | | } else { -LL | | None -LL | | }; - | |_____^ consider using `m.entry(k)` - -error: aborting due to 5 previous errors - diff --git a/tests/ui/enum_clike_unportable_variant.rs b/tests/ui/enum_clike_unportable_variant.rs deleted file mode 100644 index 7d6842f5b542..000000000000 --- a/tests/ui/enum_clike_unportable_variant.rs +++ /dev/null @@ -1,50 +0,0 @@ -// ignore-x86 - -#![warn(clippy::enum_clike_unportable_variant)] -#![allow(unused, non_upper_case_globals)] - -#[repr(usize)] -enum NonPortable { - X = 0x1_0000_0000, - Y = 0, - Z = 0x7FFF_FFFF, - A = 0xFFFF_FFFF, -} - -enum NonPortableNoHint { - X = 0x1_0000_0000, - Y = 0, - Z = 0x7FFF_FFFF, - A = 0xFFFF_FFFF, -} - -#[repr(isize)] -enum NonPortableSigned { - X = -1, - Y = 0x7FFF_FFFF, - Z = 0xFFFF_FFFF, - A = 0x1_0000_0000, - B = i32::MIN as isize, - C = (i32::MIN as isize) - 1, -} - -enum NonPortableSignedNoHint { - X = -1, - Y = 0x7FFF_FFFF, - Z = 0xFFFF_FFFF, - A = 0x1_0000_0000, -} - -#[repr(usize)] -enum NonPortable2 { - X = ::Number, - Y = 0, -} - -trait Trait { - const Number: usize = 0x1_0000_0000; -} - -impl Trait for usize {} - -fn main() {} diff --git a/tests/ui/enum_clike_unportable_variant.stderr b/tests/ui/enum_clike_unportable_variant.stderr deleted file mode 100644 index 5935eea5e036..000000000000 --- a/tests/ui/enum_clike_unportable_variant.stderr +++ /dev/null @@ -1,58 +0,0 @@ -error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:8:5 - | -LL | X = 0x1_0000_0000, - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::enum-clike-unportable-variant` implied by `-D warnings` - -error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:15:5 - | -LL | X = 0x1_0000_0000, - | ^^^^^^^^^^^^^^^^^ - -error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:18:5 - | -LL | A = 0xFFFF_FFFF, - | ^^^^^^^^^^^^^^^ - -error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:25:5 - | -LL | Z = 0xFFFF_FFFF, - | ^^^^^^^^^^^^^^^ - -error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:26:5 - | -LL | A = 0x1_0000_0000, - | ^^^^^^^^^^^^^^^^^ - -error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:28:5 - | -LL | C = (i32::MIN as isize) - 1, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:34:5 - | -LL | Z = 0xFFFF_FFFF, - | ^^^^^^^^^^^^^^^ - -error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:35:5 - | -LL | A = 0x1_0000_0000, - | ^^^^^^^^^^^^^^^^^ - -error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:40:5 - | -LL | X = ::Number, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 9 previous errors - diff --git a/tests/ui/enum_glob_use.fixed b/tests/ui/enum_glob_use.fixed deleted file mode 100644 index a98216758bb9..000000000000 --- a/tests/ui/enum_glob_use.fixed +++ /dev/null @@ -1,30 +0,0 @@ -// run-rustfix - -#![warn(clippy::enum_glob_use)] -#![allow(unused)] -#![warn(unused_imports)] - -use std::cmp::Ordering::Less; - -enum Enum { - Foo, -} - -use self::Enum::Foo; - -mod in_fn_test { - fn blarg() { - use crate::Enum::Foo; - - let _ = Foo; - } -} - -mod blurg { - pub use std::cmp::Ordering::*; // ok, re-export -} - -fn main() { - let _ = Foo; - let _ = Less; -} diff --git a/tests/ui/enum_glob_use.rs b/tests/ui/enum_glob_use.rs deleted file mode 100644 index 5d929c9731d3..000000000000 --- a/tests/ui/enum_glob_use.rs +++ /dev/null @@ -1,30 +0,0 @@ -// run-rustfix - -#![warn(clippy::enum_glob_use)] -#![allow(unused)] -#![warn(unused_imports)] - -use std::cmp::Ordering::*; - -enum Enum { - Foo, -} - -use self::Enum::*; - -mod in_fn_test { - fn blarg() { - use crate::Enum::*; - - let _ = Foo; - } -} - -mod blurg { - pub use std::cmp::Ordering::*; // ok, re-export -} - -fn main() { - let _ = Foo; - let _ = Less; -} diff --git a/tests/ui/enum_glob_use.stderr b/tests/ui/enum_glob_use.stderr deleted file mode 100644 index 69531aed39bd..000000000000 --- a/tests/ui/enum_glob_use.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: usage of wildcard import for enum variants - --> $DIR/enum_glob_use.rs:7:5 - | -LL | use std::cmp::Ordering::*; - | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::cmp::Ordering::Less` - | - = note: `-D clippy::enum-glob-use` implied by `-D warnings` - -error: usage of wildcard import for enum variants - --> $DIR/enum_glob_use.rs:13:5 - | -LL | use self::Enum::*; - | ^^^^^^^^^^^^^ help: try: `self::Enum::Foo` - -error: usage of wildcard import for enum variants - --> $DIR/enum_glob_use.rs:17:13 - | -LL | use crate::Enum::*; - | ^^^^^^^^^^^^^^ help: try: `crate::Enum::Foo` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/enum_variants.rs b/tests/ui/enum_variants.rs deleted file mode 100644 index 01774a2a9845..000000000000 --- a/tests/ui/enum_variants.rs +++ /dev/null @@ -1,136 +0,0 @@ -#![feature(non_ascii_idents)] -#![warn(clippy::enum_variant_names, clippy::pub_enum_variant_names)] -#![allow(non_camel_case_types)] - -enum FakeCallType { - CALL, - CREATE, -} - -enum FakeCallType2 { - CALL, - CREATELL, -} - -enum Foo { - cFoo, - cBar, - cBaz, -} - -enum Fooo { - cFoo, // no error, threshold is 3 variants by default - cBar, -} - -enum Food { - FoodGood, - FoodMiddle, - FoodBad, -} - -enum Stuff { - StuffBad, // no error -} - -enum BadCallType { - CallTypeCall, - CallTypeCreate, - CallTypeDestroy, -} - -enum TwoCallType { - // no error - CallTypeCall, - CallTypeCreate, -} - -enum Consts { - ConstantInt, - ConstantCake, - ConstantLie, -} - -enum Two { - // no error here - ConstantInt, - ConstantInfer, -} - -enum Something { - CCall, - CCreate, - CCryogenize, -} - -enum Seal { - With, - Without, -} - -enum Seall { - With, - WithOut, - Withbroken, -} - -enum Sealll { - With, - WithOut, -} - -enum Seallll { - WithOutCake, - WithOutTea, - WithOut, -} - -enum NonCaps { - Prefix的, - PrefixTea, - PrefixCake, -} - -pub enum PubSeall { - WithOutCake, - WithOutTea, - WithOut, -} - -#[allow(clippy::pub_enum_variant_names)] -mod allowed { - pub enum PubAllowed { - SomeThis, - SomeThat, - SomeOtherWhat, - } -} - -// should not lint -enum Pat { - Foo, - Bar, - Path, -} - -// should not lint -enum N { - Pos, - Neg, - Float, -} - -// should not lint -enum Peek { - Peek1, - Peek2, - Peek3, -} - -// should not lint -pub enum NetworkLayer { - Layer2, - Layer3, -} - -fn main() {} diff --git a/tests/ui/enum_variants.stderr b/tests/ui/enum_variants.stderr deleted file mode 100644 index b1d481190ff5..000000000000 --- a/tests/ui/enum_variants.stderr +++ /dev/null @@ -1,101 +0,0 @@ -error: variant name ends with the enum's name - --> $DIR/enum_variants.rs:16:5 - | -LL | cFoo, - | ^^^^ - | - = note: `-D clippy::enum-variant-names` implied by `-D warnings` - -error: variant name starts with the enum's name - --> $DIR/enum_variants.rs:27:5 - | -LL | FoodGood, - | ^^^^^^^^ - -error: variant name starts with the enum's name - --> $DIR/enum_variants.rs:28:5 - | -LL | FoodMiddle, - | ^^^^^^^^^^ - -error: variant name starts with the enum's name - --> $DIR/enum_variants.rs:29:5 - | -LL | FoodBad, - | ^^^^^^^ - -error: all variants have the same prefix: `Food` - --> $DIR/enum_variants.rs:26:1 - | -LL | / enum Food { -LL | | FoodGood, -LL | | FoodMiddle, -LL | | FoodBad, -LL | | } - | |_^ - | - = help: remove the prefixes and use full paths to the variants instead of glob imports - -error: all variants have the same prefix: `CallType` - --> $DIR/enum_variants.rs:36:1 - | -LL | / enum BadCallType { -LL | | CallTypeCall, -LL | | CallTypeCreate, -LL | | CallTypeDestroy, -LL | | } - | |_^ - | - = help: remove the prefixes and use full paths to the variants instead of glob imports - -error: all variants have the same prefix: `Constant` - --> $DIR/enum_variants.rs:48:1 - | -LL | / enum Consts { -LL | | ConstantInt, -LL | | ConstantCake, -LL | | ConstantLie, -LL | | } - | |_^ - | - = help: remove the prefixes and use full paths to the variants instead of glob imports - -error: all variants have the same prefix: `With` - --> $DIR/enum_variants.rs:82:1 - | -LL | / enum Seallll { -LL | | WithOutCake, -LL | | WithOutTea, -LL | | WithOut, -LL | | } - | |_^ - | - = help: remove the prefixes and use full paths to the variants instead of glob imports - -error: all variants have the same prefix: `Prefix` - --> $DIR/enum_variants.rs:88:1 - | -LL | / enum NonCaps { -LL | | Prefix的, -LL | | PrefixTea, -LL | | PrefixCake, -LL | | } - | |_^ - | - = help: remove the prefixes and use full paths to the variants instead of glob imports - -error: all variants have the same prefix: `With` - --> $DIR/enum_variants.rs:94:1 - | -LL | / pub enum PubSeall { -LL | | WithOutCake, -LL | | WithOutTea, -LL | | WithOut, -LL | | } - | |_^ - | - = note: `-D clippy::pub-enum-variant-names` implied by `-D warnings` - = help: remove the prefixes and use full paths to the variants instead of glob imports - -error: aborting due to 10 previous errors - diff --git a/tests/ui/eprint_with_newline.rs b/tests/ui/eprint_with_newline.rs deleted file mode 100644 index 8df32649ad94..000000000000 --- a/tests/ui/eprint_with_newline.rs +++ /dev/null @@ -1,49 +0,0 @@ -#![allow(clippy::print_literal)] -#![warn(clippy::print_with_newline)] - -fn main() { - eprint!("Hello\n"); - eprint!("Hello {}\n", "world"); - eprint!("Hello {} {}\n", "world", "#2"); - eprint!("{}\n", 1265); - eprint!("\n"); - - // these are all fine - eprint!(""); - eprint!("Hello"); - eprintln!("Hello"); - eprintln!("Hello\n"); - eprintln!("Hello {}\n", "world"); - eprint!("Issue\n{}", 1265); - eprint!("{}", 1265); - eprint!("\n{}", 1275); - eprint!("\n\n"); - eprint!("like eof\n\n"); - eprint!("Hello {} {}\n\n", "world", "#2"); - eprintln!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - eprintln!("\nbla\n\n"); // #3126 - - // Escaping - eprint!("\\n"); // #3514 - eprint!("\\\n"); // should fail - eprint!("\\\\n"); - - // Raw strings - eprint!(r"\n"); // #3778 - - // Literal newlines should also fail - eprint!( - " -" - ); - eprint!( - r" -" - ); - - // Don't warn on CRLF (#4208) - eprint!("\r\n"); - eprint!("foo\r\n"); - eprint!("\\r\n"); //~ ERROR - eprint!("foo\rbar\n") // ~ ERROR -} diff --git a/tests/ui/eprint_with_newline.stderr b/tests/ui/eprint_with_newline.stderr deleted file mode 100644 index 31811d1d92a0..000000000000 --- a/tests/ui/eprint_with_newline.stderr +++ /dev/null @@ -1,121 +0,0 @@ -error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:5:5 - | -LL | eprint!("Hello/n"); - | ^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::print-with-newline` implied by `-D warnings` -help: use `eprintln!` instead - | -LL | eprintln!("Hello"); - | ^^^^^^^^ -- - -error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:6:5 - | -LL | eprint!("Hello {}/n", "world"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: use `eprintln!` instead - | -LL | eprintln!("Hello {}", "world"); - | ^^^^^^^^ -- - -error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:7:5 - | -LL | eprint!("Hello {} {}/n", "world", "#2"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: use `eprintln!` instead - | -LL | eprintln!("Hello {} {}", "world", "#2"); - | ^^^^^^^^ -- - -error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:8:5 - | -LL | eprint!("{}/n", 1265); - | ^^^^^^^^^^^^^^^^^^^^^ - | -help: use `eprintln!` instead - | -LL | eprintln!("{}", 1265); - | ^^^^^^^^ -- - -error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:9:5 - | -LL | eprint!("/n"); - | ^^^^^^^^^^^^^ - | -help: use `eprintln!` instead - | -LL | eprintln!(); - | ^^^^^^^^ -- - -error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:28:5 - | -LL | eprint!("//n"); // should fail - | ^^^^^^^^^^^^^^^ - | -help: use `eprintln!` instead - | -LL | eprintln!("/"); // should fail - | ^^^^^^^^ -- - -error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:35:5 - | -LL | / eprint!( -LL | | " -LL | | " -LL | | ); - | |_____^ - | -help: use `eprintln!` instead - | -LL | eprintln!( -LL | "" - | - -error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:39:5 - | -LL | / eprint!( -LL | | r" -LL | | " -LL | | ); - | |_____^ - | -help: use `eprintln!` instead - | -LL | eprintln!( -LL | r"" - | - -error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:47:5 - | -LL | eprint!("/r/n"); //~ ERROR - | ^^^^^^^^^^^^^^^^ - | -help: use `eprintln!` instead - | -LL | eprintln!("/r"); //~ ERROR - | ^^^^^^^^ -- - -error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:48:5 - | -LL | eprint!("foo/rbar/n") // ~ ERROR - | ^^^^^^^^^^^^^^^^^^^^^ - | -help: use `eprintln!` instead - | -LL | eprintln!("foo/rbar") // ~ ERROR - | ^^^^^^^^ -- - -error: aborting due to 10 previous errors - diff --git a/tests/ui/eq_op.rs b/tests/ui/eq_op.rs deleted file mode 100644 index 7ab23320db6d..000000000000 --- a/tests/ui/eq_op.rs +++ /dev/null @@ -1,97 +0,0 @@ -// does not test any rustfixable lints - -#[rustfmt::skip] -#[warn(clippy::eq_op)] -#[allow(clippy::identity_op, clippy::double_parens, clippy::many_single_char_names)] -#[allow(clippy::no_effect, unused_variables, clippy::unnecessary_operation, clippy::short_circuit_statement)] -#[allow(clippy::nonminimal_bool)] -#[allow(unused)] -#[allow(clippy::unnecessary_cast)] -fn main() { - // simple values and comparisons - 1 == 1; - "no" == "no"; - // even though I agree that no means no ;-) - false != false; - 1.5 < 1.5; - 1u64 >= 1u64; - - // casts, methods, parentheses - (1 as u64) & (1 as u64); - 1 ^ ((((((1)))))); - - // unary and binary operators - (-(2) < -(2)); - ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); - (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; - - // various other things - ([1] != [1]); - ((1, 2) != (1, 2)); - vec![1, 2, 3] == vec![1, 2, 3]; //no error yet, as we don't match macros - - // const folding - 1 + 1 == 2; - 1 - 1 == 0; - - 1 - 1; - 1 / 1; - true && true; - - true || true; - - - let a: u32 = 0; - let b: u32 = 0; - - a == b && b == a; - a != b && b != a; - a < b && b > a; - a <= b && b >= a; - - let mut a = vec![1]; - a == a; - 2*a.len() == 2*a.len(); // ok, functions - a.pop() == a.pop(); // ok, functions - - check_ignore_macro(); - - // named constants - const A: u32 = 10; - const B: u32 = 10; - const C: u32 = A / B; // ok, different named constants - const D: u32 = A / A; -} - -#[rustfmt::skip] -macro_rules! check_if_named_foo { - ($expression:expr) => ( - if stringify!($expression) == "foo" { - println!("foo!"); - } else { - println!("not foo."); - } - ) -} - -macro_rules! bool_macro { - ($expression:expr) => { - true - }; -} - -#[allow(clippy::short_circuit_statement)] -fn check_ignore_macro() { - check_if_named_foo!(foo); - // checks if the lint ignores macros with `!` operator - !bool_macro!(1) && !bool_macro!(""); -} - -struct Nested { - inner: ((i32,), (i32,), (i32,)), -} - -fn check_nested(n1: &Nested, n2: &Nested) -> bool { - // `n2.inner.0.0` mistyped as `n1.inner.0.0` - (n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0 -} diff --git a/tests/ui/eq_op.stderr b/tests/ui/eq_op.stderr deleted file mode 100644 index 8ef658af8df4..000000000000 --- a/tests/ui/eq_op.stderr +++ /dev/null @@ -1,174 +0,0 @@ -error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:12:5 - | -LL | 1 == 1; - | ^^^^^^ - | - = note: `-D clippy::eq-op` implied by `-D warnings` - -error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:13:5 - | -LL | "no" == "no"; - | ^^^^^^^^^^^^ - -error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:15:5 - | -LL | false != false; - | ^^^^^^^^^^^^^^ - -error: equal expressions as operands to `<` - --> $DIR/eq_op.rs:16:5 - | -LL | 1.5 < 1.5; - | ^^^^^^^^^ - -error: equal expressions as operands to `>=` - --> $DIR/eq_op.rs:17:5 - | -LL | 1u64 >= 1u64; - | ^^^^^^^^^^^^ - -error: equal expressions as operands to `&` - --> $DIR/eq_op.rs:20:5 - | -LL | (1 as u64) & (1 as u64); - | ^^^^^^^^^^^^^^^^^^^^^^^ - -error: equal expressions as operands to `^` - --> $DIR/eq_op.rs:21:5 - | -LL | 1 ^ ((((((1)))))); - | ^^^^^^^^^^^^^^^^^ - -error: equal expressions as operands to `<` - --> $DIR/eq_op.rs:24:5 - | -LL | (-(2) < -(2)); - | ^^^^^^^^^^^^^ - -error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:25:5 - | -LL | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: equal expressions as operands to `&` - --> $DIR/eq_op.rs:25:6 - | -LL | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); - | ^^^^^^^^^^^^^^^^^ - -error: equal expressions as operands to `&` - --> $DIR/eq_op.rs:25:27 - | -LL | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); - | ^^^^^^^^^^^^^^^^^ - -error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:26:5 - | -LL | (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:29:5 - | -LL | ([1] != [1]); - | ^^^^^^^^^^^^ - -error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:30:5 - | -LL | ((1, 2) != (1, 2)); - | ^^^^^^^^^^^^^^^^^^ - -error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:34:5 - | -LL | 1 + 1 == 2; - | ^^^^^^^^^^ - -error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:35:5 - | -LL | 1 - 1 == 0; - | ^^^^^^^^^^ - -error: equal expressions as operands to `-` - --> $DIR/eq_op.rs:35:5 - | -LL | 1 - 1 == 0; - | ^^^^^ - -error: equal expressions as operands to `-` - --> $DIR/eq_op.rs:37:5 - | -LL | 1 - 1; - | ^^^^^ - -error: equal expressions as operands to `/` - --> $DIR/eq_op.rs:38:5 - | -LL | 1 / 1; - | ^^^^^ - -error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:39:5 - | -LL | true && true; - | ^^^^^^^^^^^^ - -error: equal expressions as operands to `||` - --> $DIR/eq_op.rs:41:5 - | -LL | true || true; - | ^^^^^^^^^^^^ - -error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:47:5 - | -LL | a == b && b == a; - | ^^^^^^^^^^^^^^^^ - -error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:48:5 - | -LL | a != b && b != a; - | ^^^^^^^^^^^^^^^^ - -error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:49:5 - | -LL | a < b && b > a; - | ^^^^^^^^^^^^^^ - -error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:50:5 - | -LL | a <= b && b >= a; - | ^^^^^^^^^^^^^^^^ - -error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:53:5 - | -LL | a == a; - | ^^^^^^ - -error: equal expressions as operands to `/` - --> $DIR/eq_op.rs:63:20 - | -LL | const D: u32 = A / A; - | ^^^^^ - -error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:96:5 - | -LL | (n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[deny(clippy::eq_op)]` on by default - -error: aborting due to 28 previous errors - diff --git a/tests/ui/eq_op_macros.rs b/tests/ui/eq_op_macros.rs deleted file mode 100644 index 6b5b31a1a2ef..000000000000 --- a/tests/ui/eq_op_macros.rs +++ /dev/null @@ -1,56 +0,0 @@ -#![warn(clippy::eq_op)] - -// lint also in macro definition -macro_rules! assert_in_macro_def { - () => { - let a = 42; - assert_eq!(a, a); - assert_ne!(a, a); - debug_assert_eq!(a, a); - debug_assert_ne!(a, a); - }; -} - -// lint identical args in assert-like macro invocations (see #3574) -fn main() { - assert_in_macro_def!(); - - let a = 1; - let b = 2; - - // lint identical args in `assert_eq!` - assert_eq!(a, a); - assert_eq!(a + 1, a + 1); - // ok - assert_eq!(a, b); - assert_eq!(a, a + 1); - assert_eq!(a + 1, b + 1); - - // lint identical args in `assert_ne!` - assert_ne!(a, a); - assert_ne!(a + 1, a + 1); - // ok - assert_ne!(a, b); - assert_ne!(a, a + 1); - assert_ne!(a + 1, b + 1); - - // lint identical args in `debug_assert_eq!` - debug_assert_eq!(a, a); - debug_assert_eq!(a + 1, a + 1); - // ok - debug_assert_eq!(a, b); - debug_assert_eq!(a, a + 1); - debug_assert_eq!(a + 1, b + 1); - - // lint identical args in `debug_assert_ne!` - debug_assert_ne!(a, a); - debug_assert_ne!(a + 1, a + 1); - // ok - debug_assert_ne!(a, b); - debug_assert_ne!(a, a + 1); - debug_assert_ne!(a + 1, b + 1); - - let my_vec = vec![1; 5]; - let mut my_iter = my_vec.iter(); - assert_ne!(my_iter.next(), my_iter.next()); -} diff --git a/tests/ui/eq_op_macros.stderr b/tests/ui/eq_op_macros.stderr deleted file mode 100644 index fb9378108b98..000000000000 --- a/tests/ui/eq_op_macros.stderr +++ /dev/null @@ -1,95 +0,0 @@ -error: identical args used in this `assert_eq!` macro call - --> $DIR/eq_op_macros.rs:7:20 - | -LL | assert_eq!(a, a); - | ^^^^ -... -LL | assert_in_macro_def!(); - | ----------------------- in this macro invocation - | - = note: `-D clippy::eq-op` implied by `-D warnings` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: identical args used in this `assert_ne!` macro call - --> $DIR/eq_op_macros.rs:8:20 - | -LL | assert_ne!(a, a); - | ^^^^ -... -LL | assert_in_macro_def!(); - | ----------------------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: identical args used in this `assert_eq!` macro call - --> $DIR/eq_op_macros.rs:22:16 - | -LL | assert_eq!(a, a); - | ^^^^ - -error: identical args used in this `assert_eq!` macro call - --> $DIR/eq_op_macros.rs:23:16 - | -LL | assert_eq!(a + 1, a + 1); - | ^^^^^^^^^^^^ - -error: identical args used in this `assert_ne!` macro call - --> $DIR/eq_op_macros.rs:30:16 - | -LL | assert_ne!(a, a); - | ^^^^ - -error: identical args used in this `assert_ne!` macro call - --> $DIR/eq_op_macros.rs:31:16 - | -LL | assert_ne!(a + 1, a + 1); - | ^^^^^^^^^^^^ - -error: identical args used in this `debug_assert_eq!` macro call - --> $DIR/eq_op_macros.rs:9:26 - | -LL | debug_assert_eq!(a, a); - | ^^^^ -... -LL | assert_in_macro_def!(); - | ----------------------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: identical args used in this `debug_assert_ne!` macro call - --> $DIR/eq_op_macros.rs:10:26 - | -LL | debug_assert_ne!(a, a); - | ^^^^ -... -LL | assert_in_macro_def!(); - | ----------------------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: identical args used in this `debug_assert_eq!` macro call - --> $DIR/eq_op_macros.rs:38:22 - | -LL | debug_assert_eq!(a, a); - | ^^^^ - -error: identical args used in this `debug_assert_eq!` macro call - --> $DIR/eq_op_macros.rs:39:22 - | -LL | debug_assert_eq!(a + 1, a + 1); - | ^^^^^^^^^^^^ - -error: identical args used in this `debug_assert_ne!` macro call - --> $DIR/eq_op_macros.rs:46:22 - | -LL | debug_assert_ne!(a, a); - | ^^^^ - -error: identical args used in this `debug_assert_ne!` macro call - --> $DIR/eq_op_macros.rs:47:22 - | -LL | debug_assert_ne!(a + 1, a + 1); - | ^^^^^^^^^^^^ - -error: aborting due to 12 previous errors - diff --git a/tests/ui/erasing_op.rs b/tests/ui/erasing_op.rs deleted file mode 100644 index 1540062a4bc3..000000000000 --- a/tests/ui/erasing_op.rs +++ /dev/null @@ -1,9 +0,0 @@ -#[allow(clippy::no_effect)] -#[warn(clippy::erasing_op)] -fn main() { - let x: u8 = 0; - - x * 0; - 0 & x; - 0 / x; -} diff --git a/tests/ui/erasing_op.stderr b/tests/ui/erasing_op.stderr deleted file mode 100644 index e54ce85f98ec..000000000000 --- a/tests/ui/erasing_op.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:6:5 - | -LL | x * 0; - | ^^^^^ - | - = note: `-D clippy::erasing-op` implied by `-D warnings` - -error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:7:5 - | -LL | 0 & x; - | ^^^^^ - -error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:8:5 - | -LL | 0 / x; - | ^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/escape_analysis.rs b/tests/ui/escape_analysis.rs deleted file mode 100644 index 07004489610d..000000000000 --- a/tests/ui/escape_analysis.rs +++ /dev/null @@ -1,184 +0,0 @@ -#![feature(box_syntax)] -#![allow( - clippy::borrowed_box, - clippy::needless_pass_by_value, - clippy::unused_unit, - clippy::redundant_clone, - clippy::match_single_binding -)] -#![warn(clippy::boxed_local)] - -#[derive(Clone)] -struct A; - -impl A { - fn foo(&self) {} -} - -trait Z { - fn bar(&self); -} - -impl Z for A { - fn bar(&self) { - //nothing - } -} - -fn main() {} - -fn ok_box_trait(boxed_trait: &Box) { - let boxed_local = boxed_trait; - // done -} - -fn warn_call() { - let x = box A; - x.foo(); -} - -fn warn_arg(x: Box) { - x.foo(); -} - -fn nowarn_closure_arg() { - let x = Some(box A); - x.map_or((), |x| take_ref(&x)); -} - -fn warn_rename_call() { - let x = box A; - - let y = x; - y.foo(); // via autoderef -} - -fn warn_notuse() { - let bz = box A; -} - -fn warn_pass() { - let bz = box A; - take_ref(&bz); // via deref coercion -} - -fn nowarn_return() -> Box { - box A // moved out, "escapes" -} - -fn nowarn_move() { - let bx = box A; - drop(bx) // moved in, "escapes" -} -fn nowarn_call() { - let bx = box A; - bx.clone(); // method only available to Box, not via autoderef -} - -fn nowarn_pass() { - let bx = box A; - take_box(&bx); // fn needs &Box -} - -fn take_box(x: &Box) {} -fn take_ref(x: &A) {} - -fn nowarn_ref_take() { - // false positive, should actually warn - let x = box A; - let y = &x; - take_box(y); -} - -fn nowarn_match() { - let x = box A; // moved into a match - match x { - y => drop(y), - } -} - -fn warn_match() { - let x = box A; - match &x { - // not moved - ref y => (), - } -} - -fn nowarn_large_array() { - // should not warn, is large array - // and should not be on stack - let x = box [1; 10000]; - match &x { - // not moved - ref y => (), - } -} - -/// ICE regression test -pub trait Foo { - type Item; -} - -impl<'a> Foo for &'a () { - type Item = (); -} - -pub struct PeekableSeekable { - _peeked: I::Item, -} - -pub fn new(_needs_name: Box>) -> () {} - -/// Regression for #916, #1123 -/// -/// This shouldn't warn for `boxed_local`as the implementation of a trait -/// can't change much about the trait definition. -trait BoxedAction { - fn do_sth(self: Box); -} - -impl BoxedAction for u64 { - fn do_sth(self: Box) { - println!("{}", *self) - } -} - -/// Regression for #1478 -/// -/// This shouldn't warn for `boxed_local`as self itself is a box type. -trait MyTrait { - fn do_sth(self); -} - -impl MyTrait for Box { - fn do_sth(self) {} -} - -// Issue #3739 - capture in closures -mod issue_3739 { - use super::A; - - fn consume(_: T) {} - fn borrow(_: &T) {} - - fn closure_consume(x: Box) { - let _ = move || { - consume(x); - }; - } - - fn closure_borrow(x: Box) { - let _ = || { - borrow(&x); - }; - } -} - -/// Issue #5542 -/// -/// This shouldn't warn for `boxed_local` as it is intended to called from non-Rust code. -pub extern "C" fn do_not_warn_me(_c_pointer: Box) -> () {} - -#[rustfmt::skip] // Forces rustfmt to not add ABI -pub extern fn do_not_warn_me_no_abi(_c_pointer: Box) -> () {} diff --git a/tests/ui/escape_analysis.stderr b/tests/ui/escape_analysis.stderr deleted file mode 100644 index c86a769a3da4..000000000000 --- a/tests/ui/escape_analysis.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: local variable doesn't need to be boxed here - --> $DIR/escape_analysis.rs:40:13 - | -LL | fn warn_arg(x: Box) { - | ^ - | - = note: `-D clippy::boxed-local` implied by `-D warnings` - -error: local variable doesn't need to be boxed here - --> $DIR/escape_analysis.rs:131:12 - | -LL | pub fn new(_needs_name: Box>) -> () {} - | ^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/eta.fixed b/tests/ui/eta.fixed deleted file mode 100644 index 1b34c2f74eba..000000000000 --- a/tests/ui/eta.fixed +++ /dev/null @@ -1,204 +0,0 @@ -// run-rustfix - -#![allow( - unused, - clippy::no_effect, - clippy::redundant_closure_call, - clippy::many_single_char_names, - clippy::needless_pass_by_value, - clippy::option_map_unit_fn -)] -#![warn( - clippy::redundant_closure, - clippy::redundant_closure_for_method_calls, - clippy::needless_borrow -)] - -use std::path::PathBuf; - -fn main() { - let a = Some(1u8).map(foo); - meta(foo); - let c = Some(1u8).map(|a| {1+2; foo}(a)); - let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted? - all(&[1, 2, 3], &2, |x, y| below(x, y)); //is adjusted - unsafe { - Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn - } - - // See #815 - let e = Some(1u8).map(|a| divergent(a)); - let e = Some(1u8).map(generic); - let e = Some(1u8).map(generic); - // See #515 - let a: Option)>> = - Some(vec![1i32, 2]).map(|v| -> Box)> { Box::new(v) }); -} - -trait TestTrait { - fn trait_foo(self) -> bool; - fn trait_foo_ref(&self) -> bool; -} - -struct TestStruct<'a> { - some_ref: &'a i32, -} - -impl<'a> TestStruct<'a> { - fn foo(self) -> bool { - false - } - unsafe fn foo_unsafe(self) -> bool { - true - } -} - -impl<'a> TestTrait for TestStruct<'a> { - fn trait_foo(self) -> bool { - false - } - fn trait_foo_ref(&self) -> bool { - false - } -} - -impl<'a> std::ops::Deref for TestStruct<'a> { - type Target = char; - fn deref(&self) -> &char { - &'a' - } -} - -fn test_redundant_closures_containing_method_calls() { - let i = 10; - let e = Some(TestStruct { some_ref: &i }).map(TestStruct::foo); - let e = Some(TestStruct { some_ref: &i }).map(TestStruct::foo); - let e = Some(TestStruct { some_ref: &i }).map(TestTrait::trait_foo); - let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo_ref()); - let e = Some(TestStruct { some_ref: &i }).map(TestTrait::trait_foo); - let e = Some(&mut vec![1, 2, 3]).map(std::vec::Vec::clear); - let e = Some(&mut vec![1, 2, 3]).map(std::vec::Vec::clear); - unsafe { - let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo_unsafe()); - } - let e = Some("str").map(std::string::ToString::to_string); - let e = Some("str").map(str::to_string); - let e = Some('a').map(char::to_uppercase); - let e = Some('a').map(char::to_uppercase); - let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(|c| c.len_utf8()).collect(); - let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(char::to_ascii_uppercase).collect(); - let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(char::to_ascii_uppercase).collect(); - let p = Some(PathBuf::new()); - let e = p.as_ref().and_then(|s| s.to_str()); - let c = Some(TestStruct { some_ref: &i }) - .as_ref() - .map(|c| c.to_ascii_uppercase()); - - fn test_different_borrow_levels(t: &[&T]) - where - T: TestTrait, - { - t.iter().filter(|x| x.trait_foo_ref()); - t.iter().map(|x| x.trait_foo_ref()); - } - - let mut some = Some(|x| x * x); - let arr = [Ok(1), Err(2)]; - let _: Vec<_> = arr.iter().map(|x| x.map_err(|e| some.take().unwrap()(e))).collect(); -} - -struct Thunk(Box T>); - -impl Thunk { - fn new T>(f: F) -> Thunk { - let mut option = Some(f); - // This should not trigger redundant_closure (#1439) - Thunk(Box::new(move || option.take().unwrap()())) - } - - fn unwrap(self) -> T { - let Thunk(mut f) = self; - f() - } -} - -fn foobar() { - let thunk = Thunk::new(|| println!("Hello, world!")); - thunk.unwrap() -} - -fn meta(f: F) -where - F: Fn(u8), -{ - f(1u8) -} - -fn foo(_: u8) {} - -fn foo2(_: u8) -> u8 { - 1u8 -} - -fn all(x: &[X], y: &X, f: F) -> bool -where - F: Fn(&X, &X) -> bool, -{ - x.iter().all(|e| f(e, y)) -} - -fn below(x: &u8, y: &u8) -> bool { - x < y -} - -unsafe fn unsafe_fn(_: u8) {} - -fn divergent(_: u8) -> ! { - unimplemented!() -} - -fn generic(_: T) -> u8 { - 0 -} - -fn passes_fn_mut(mut x: Box) { - requires_fn_once(|| x()); -} -fn requires_fn_once(_: T) {} - -fn test_redundant_closure_with_function_pointer() { - type FnPtrType = fn(u8); - let foo_ptr: FnPtrType = foo; - let a = Some(1u8).map(foo_ptr); -} - -fn test_redundant_closure_with_another_closure() { - let closure = |a| println!("{}", a); - let a = Some(1u8).map(closure); -} - -fn make_lazy(f: impl Fn() -> fn(u8) -> u8) -> impl Fn(u8) -> u8 { - // Currently f is called when result of make_lazy is called. - // If the closure is removed, f will be called when make_lazy itself is - // called. This changes semantics, so the closure must stay. - Box::new(move |x| f()(x)) -} - -fn call String>(f: F) -> String { - f(&mut "Hello".to_owned()) -} -fn test_difference_in_mutability() { - call(|s| s.clone()); -} - -struct Bar; -impl std::ops::Deref for Bar { - type Target = str; - fn deref(&self) -> &str { - "hi" - } -} - -fn test_deref_with_trait_method() { - let _ = [Bar].iter().map(|s| s.to_string()).collect::>(); -} diff --git a/tests/ui/eta.rs b/tests/ui/eta.rs deleted file mode 100644 index 4f050bd8479a..000000000000 --- a/tests/ui/eta.rs +++ /dev/null @@ -1,204 +0,0 @@ -// run-rustfix - -#![allow( - unused, - clippy::no_effect, - clippy::redundant_closure_call, - clippy::many_single_char_names, - clippy::needless_pass_by_value, - clippy::option_map_unit_fn -)] -#![warn( - clippy::redundant_closure, - clippy::redundant_closure_for_method_calls, - clippy::needless_borrow -)] - -use std::path::PathBuf; - -fn main() { - let a = Some(1u8).map(|a| foo(a)); - meta(|a| foo(a)); - let c = Some(1u8).map(|a| {1+2; foo}(a)); - let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted? - all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted - unsafe { - Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn - } - - // See #815 - let e = Some(1u8).map(|a| divergent(a)); - let e = Some(1u8).map(|a| generic(a)); - let e = Some(1u8).map(generic); - // See #515 - let a: Option)>> = - Some(vec![1i32, 2]).map(|v| -> Box)> { Box::new(v) }); -} - -trait TestTrait { - fn trait_foo(self) -> bool; - fn trait_foo_ref(&self) -> bool; -} - -struct TestStruct<'a> { - some_ref: &'a i32, -} - -impl<'a> TestStruct<'a> { - fn foo(self) -> bool { - false - } - unsafe fn foo_unsafe(self) -> bool { - true - } -} - -impl<'a> TestTrait for TestStruct<'a> { - fn trait_foo(self) -> bool { - false - } - fn trait_foo_ref(&self) -> bool { - false - } -} - -impl<'a> std::ops::Deref for TestStruct<'a> { - type Target = char; - fn deref(&self) -> &char { - &'a' - } -} - -fn test_redundant_closures_containing_method_calls() { - let i = 10; - let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); - let e = Some(TestStruct { some_ref: &i }).map(TestStruct::foo); - let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo()); - let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo_ref()); - let e = Some(TestStruct { some_ref: &i }).map(TestTrait::trait_foo); - let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear()); - let e = Some(&mut vec![1, 2, 3]).map(std::vec::Vec::clear); - unsafe { - let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo_unsafe()); - } - let e = Some("str").map(|s| s.to_string()); - let e = Some("str").map(str::to_string); - let e = Some('a').map(|s| s.to_uppercase()); - let e = Some('a').map(char::to_uppercase); - let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(|c| c.len_utf8()).collect(); - let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect(); - let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(char::to_ascii_uppercase).collect(); - let p = Some(PathBuf::new()); - let e = p.as_ref().and_then(|s| s.to_str()); - let c = Some(TestStruct { some_ref: &i }) - .as_ref() - .map(|c| c.to_ascii_uppercase()); - - fn test_different_borrow_levels(t: &[&T]) - where - T: TestTrait, - { - t.iter().filter(|x| x.trait_foo_ref()); - t.iter().map(|x| x.trait_foo_ref()); - } - - let mut some = Some(|x| x * x); - let arr = [Ok(1), Err(2)]; - let _: Vec<_> = arr.iter().map(|x| x.map_err(|e| some.take().unwrap()(e))).collect(); -} - -struct Thunk(Box T>); - -impl Thunk { - fn new T>(f: F) -> Thunk { - let mut option = Some(f); - // This should not trigger redundant_closure (#1439) - Thunk(Box::new(move || option.take().unwrap()())) - } - - fn unwrap(self) -> T { - let Thunk(mut f) = self; - f() - } -} - -fn foobar() { - let thunk = Thunk::new(|| println!("Hello, world!")); - thunk.unwrap() -} - -fn meta(f: F) -where - F: Fn(u8), -{ - f(1u8) -} - -fn foo(_: u8) {} - -fn foo2(_: u8) -> u8 { - 1u8 -} - -fn all(x: &[X], y: &X, f: F) -> bool -where - F: Fn(&X, &X) -> bool, -{ - x.iter().all(|e| f(e, y)) -} - -fn below(x: &u8, y: &u8) -> bool { - x < y -} - -unsafe fn unsafe_fn(_: u8) {} - -fn divergent(_: u8) -> ! { - unimplemented!() -} - -fn generic(_: T) -> u8 { - 0 -} - -fn passes_fn_mut(mut x: Box) { - requires_fn_once(|| x()); -} -fn requires_fn_once(_: T) {} - -fn test_redundant_closure_with_function_pointer() { - type FnPtrType = fn(u8); - let foo_ptr: FnPtrType = foo; - let a = Some(1u8).map(|a| foo_ptr(a)); -} - -fn test_redundant_closure_with_another_closure() { - let closure = |a| println!("{}", a); - let a = Some(1u8).map(|a| closure(a)); -} - -fn make_lazy(f: impl Fn() -> fn(u8) -> u8) -> impl Fn(u8) -> u8 { - // Currently f is called when result of make_lazy is called. - // If the closure is removed, f will be called when make_lazy itself is - // called. This changes semantics, so the closure must stay. - Box::new(move |x| f()(x)) -} - -fn call String>(f: F) -> String { - f(&mut "Hello".to_owned()) -} -fn test_difference_in_mutability() { - call(|s| s.clone()); -} - -struct Bar; -impl std::ops::Deref for Bar { - type Target = str; - fn deref(&self) -> &str { - "hi" - } -} - -fn test_deref_with_trait_method() { - let _ = [Bar].iter().map(|s| s.to_string()).collect::>(); -} diff --git a/tests/ui/eta.stderr b/tests/ui/eta.stderr deleted file mode 100644 index 16aa1b07733d..000000000000 --- a/tests/ui/eta.stderr +++ /dev/null @@ -1,80 +0,0 @@ -error: redundant closure found - --> $DIR/eta.rs:20:27 - | -LL | let a = Some(1u8).map(|a| foo(a)); - | ^^^^^^^^^^ help: remove closure as shown: `foo` - | - = note: `-D clippy::redundant-closure` implied by `-D warnings` - -error: redundant closure found - --> $DIR/eta.rs:21:10 - | -LL | meta(|a| foo(a)); - | ^^^^^^^^^^ help: remove closure as shown: `foo` - -error: this expression borrows a reference (`&u8`) that is immediately dereferenced by the compiler - --> $DIR/eta.rs:24:21 - | -LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted - | ^^^ help: change this to: `&2` - | - = note: `-D clippy::needless-borrow` implied by `-D warnings` - -error: redundant closure found - --> $DIR/eta.rs:31:27 - | -LL | let e = Some(1u8).map(|a| generic(a)); - | ^^^^^^^^^^^^^^ help: remove closure as shown: `generic` - -error: redundant closure found - --> $DIR/eta.rs:74:51 - | -LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); - | ^^^^^^^^^^^ help: remove closure as shown: `TestStruct::foo` - | - = note: `-D clippy::redundant-closure-for-method-calls` implied by `-D warnings` - -error: redundant closure found - --> $DIR/eta.rs:76:51 - | -LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo()); - | ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `TestTrait::trait_foo` - -error: redundant closure found - --> $DIR/eta.rs:79:42 - | -LL | let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear()); - | ^^^^^^^^^^^^^ help: remove closure as shown: `std::vec::Vec::clear` - -error: redundant closure found - --> $DIR/eta.rs:84:29 - | -LL | let e = Some("str").map(|s| s.to_string()); - | ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `std::string::ToString::to_string` - -error: redundant closure found - --> $DIR/eta.rs:86:27 - | -LL | let e = Some('a').map(|s| s.to_uppercase()); - | ^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_uppercase` - -error: redundant closure found - --> $DIR/eta.rs:89:65 - | -LL | let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_ascii_uppercase` - -error: redundant closure found - --> $DIR/eta.rs:172:27 - | -LL | let a = Some(1u8).map(|a| foo_ptr(a)); - | ^^^^^^^^^^^^^^ help: remove closure as shown: `foo_ptr` - -error: redundant closure found - --> $DIR/eta.rs:177:27 - | -LL | let a = Some(1u8).map(|a| closure(a)); - | ^^^^^^^^^^^^^^ help: remove closure as shown: `closure` - -error: aborting due to 12 previous errors - diff --git a/tests/ui/eval_order_dependence.rs b/tests/ui/eval_order_dependence.rs deleted file mode 100644 index d806bc6d4010..000000000000 --- a/tests/ui/eval_order_dependence.rs +++ /dev/null @@ -1,109 +0,0 @@ -#[warn(clippy::eval_order_dependence)] -#[allow( - unused_assignments, - unused_variables, - clippy::many_single_char_names, - clippy::no_effect, - dead_code, - clippy::blacklisted_name -)] -fn main() { - let mut x = 0; - let a = { - x = 1; - 1 - } + x; - - // Example from iss#277 - x += { - x = 20; - 2 - }; - - // Does it work in weird places? - // ...in the base for a struct expression? - struct Foo { - a: i32, - b: i32, - }; - let base = Foo { a: 4, b: 5 }; - let foo = Foo { - a: x, - ..{ - x = 6; - base - } - }; - // ...inside a closure? - let closure = || { - let mut x = 0; - x += { - x = 20; - 2 - }; - }; - // ...not across a closure? - let mut y = 0; - let b = (y, || y = 1); - - // && and || evaluate left-to-right. - let a = { - x = 1; - true - } && (x == 3); - let a = { - x = 1; - true - } || (x == 3); - - // Make sure we don't get confused by alpha conversion. - let a = { - let mut x = 1; - x = 2; - 1 - } + x; - - // No warning if we don't read the variable... - x = { - x = 20; - 2 - }; - // ...if the assignment is in a closure... - let b = { - || { - x = 1; - }; - 1 - } + x; - // ... or the access is under an address. - let b = ( - { - let p = &x; - 1 - }, - { - x = 1; - x - }, - ); - - // Limitation: l-values other than simple variables don't trigger - // the warning. - let mut tup = (0, 0); - let c = { - tup.0 = 1; - 1 - } + tup.0; - // Limitation: you can get away with a read under address-of. - let mut z = 0; - let b = ( - &{ - z = x; - x - }, - { - x = 3; - x - }, - ); -} diff --git a/tests/ui/eval_order_dependence.stderr b/tests/ui/eval_order_dependence.stderr deleted file mode 100644 index 8f4fa2228f7f..000000000000 --- a/tests/ui/eval_order_dependence.stderr +++ /dev/null @@ -1,51 +0,0 @@ -error: unsequenced read of a variable - --> $DIR/eval_order_dependence.rs:15:9 - | -LL | } + x; - | ^ - | - = note: `-D clippy::eval-order-dependence` implied by `-D warnings` -note: whether read occurs before this write depends on evaluation order - --> $DIR/eval_order_dependence.rs:13:9 - | -LL | x = 1; - | ^^^^^ - -error: unsequenced read of a variable - --> $DIR/eval_order_dependence.rs:18:5 - | -LL | x += { - | ^ - | -note: whether read occurs before this write depends on evaluation order - --> $DIR/eval_order_dependence.rs:19:9 - | -LL | x = 20; - | ^^^^^^ - -error: unsequenced read of a variable - --> $DIR/eval_order_dependence.rs:31:12 - | -LL | a: x, - | ^ - | -note: whether read occurs before this write depends on evaluation order - --> $DIR/eval_order_dependence.rs:33:13 - | -LL | x = 6; - | ^^^^^ - -error: unsequenced read of a variable - --> $DIR/eval_order_dependence.rs:40:9 - | -LL | x += { - | ^ - | -note: whether read occurs before this write depends on evaluation order - --> $DIR/eval_order_dependence.rs:41:13 - | -LL | x = 20; - | ^^^^^^ - -error: aborting due to 4 previous errors - diff --git a/tests/ui/excessive_precision.fixed b/tests/ui/excessive_precision.fixed deleted file mode 100644 index bf0325fec792..000000000000 --- a/tests/ui/excessive_precision.fixed +++ /dev/null @@ -1,63 +0,0 @@ -// run-rustfix -#![warn(clippy::excessive_precision)] -#![allow(dead_code, unused_variables, clippy::print_literal)] - -fn main() { - // Consts - const GOOD32: f32 = 0.123_456; - const GOOD32_SM: f32 = 0.000_000_000_1; - const GOOD32_DOT: f32 = 10_000_000_000.0; - const GOOD32_EDGE: f32 = 1.000_000_8; - const GOOD64: f64 = 0.123_456_789_012; - const GOOD64_SM: f32 = 0.000_000_000_000_000_1; - const GOOD64_DOT: f32 = 10_000_000_000_000_000.0; - - const BAD32_1: f32 = 0.123_456_79_f32; - const BAD32_2: f32 = 0.123_456_79; - const BAD32_3: f32 = 0.1; - const BAD32_EDGE: f32 = 1.000_001; - - const BAD64_1: f64 = 0.123_456_789_012_345_66_f64; - const BAD64_2: f64 = 0.123_456_789_012_345_66; - const BAD64_3: f64 = 0.1; - - // Literal as param - println!("{:?}", 8.888_888_888_888_89); - - // // TODO add inferred type tests for f32 - // Locals - let good32: f32 = 0.123_456_f32; - let good32_2: f32 = 0.123_456; - - let good64: f64 = 0.123_456_789_012; - let good64_suf: f64 = 0.123_456_789_012f64; - let good64_inf = 0.123_456_789_012; - - let bad32: f32 = 1.123_456_8; - let bad32_suf: f32 = 1.123_456_8_f32; - let bad32_inf = 1.123_456_8_f32; - - let bad64: f64 = 0.123_456_789_012_345_66; - let bad64_suf: f64 = 0.123_456_789_012_345_66_f64; - let bad64_inf = 0.123_456_789_012_345_66; - - // Vectors - let good_vec32: Vec = vec![0.123_456]; - let good_vec64: Vec = vec![0.123_456_789]; - - let bad_vec32: Vec = vec![0.123_456_79]; - let bad_vec64: Vec = vec![0.123_456_789_123_456_78]; - - // Exponential float notation - let good_e32: f32 = 1e-10; - let bad_e32: f32 = 1.123_456_8e-10; - - let good_bige32: f32 = 1E-10; - let bad_bige32: f32 = 1.123_456_8E-10; - - // Inferred type - let good_inferred: f32 = 1f32 * 1_000_000_000.; - - // issue #2840 - let num = 0.000_000_000_01e-10f64; -} diff --git a/tests/ui/excessive_precision.rs b/tests/ui/excessive_precision.rs deleted file mode 100644 index ce4722a90f90..000000000000 --- a/tests/ui/excessive_precision.rs +++ /dev/null @@ -1,63 +0,0 @@ -// run-rustfix -#![warn(clippy::excessive_precision)] -#![allow(dead_code, unused_variables, clippy::print_literal)] - -fn main() { - // Consts - const GOOD32: f32 = 0.123_456; - const GOOD32_SM: f32 = 0.000_000_000_1; - const GOOD32_DOT: f32 = 10_000_000_000.0; - const GOOD32_EDGE: f32 = 1.000_000_8; - const GOOD64: f64 = 0.123_456_789_012; - const GOOD64_SM: f32 = 0.000_000_000_000_000_1; - const GOOD64_DOT: f32 = 10_000_000_000_000_000.0; - - const BAD32_1: f32 = 0.123_456_789_f32; - const BAD32_2: f32 = 0.123_456_789; - const BAD32_3: f32 = 0.100_000_000_000_1; - const BAD32_EDGE: f32 = 1.000_000_9; - - const BAD64_1: f64 = 0.123_456_789_012_345_67f64; - const BAD64_2: f64 = 0.123_456_789_012_345_67; - const BAD64_3: f64 = 0.100_000_000_000_000_000_1; - - // Literal as param - println!("{:?}", 8.888_888_888_888_888_888_888); - - // // TODO add inferred type tests for f32 - // Locals - let good32: f32 = 0.123_456_f32; - let good32_2: f32 = 0.123_456; - - let good64: f64 = 0.123_456_789_012; - let good64_suf: f64 = 0.123_456_789_012f64; - let good64_inf = 0.123_456_789_012; - - let bad32: f32 = 1.123_456_789; - let bad32_suf: f32 = 1.123_456_789_f32; - let bad32_inf = 1.123_456_789_f32; - - let bad64: f64 = 0.123_456_789_012_345_67; - let bad64_suf: f64 = 0.123_456_789_012_345_67f64; - let bad64_inf = 0.123_456_789_012_345_67; - - // Vectors - let good_vec32: Vec = vec![0.123_456]; - let good_vec64: Vec = vec![0.123_456_789]; - - let bad_vec32: Vec = vec![0.123_456_789]; - let bad_vec64: Vec = vec![0.123_456_789_123_456_789]; - - // Exponential float notation - let good_e32: f32 = 1e-10; - let bad_e32: f32 = 1.123_456_788_888e-10; - - let good_bige32: f32 = 1E-10; - let bad_bige32: f32 = 1.123_456_788_888E-10; - - // Inferred type - let good_inferred: f32 = 1f32 * 1_000_000_000.; - - // issue #2840 - let num = 0.000_000_000_01e-10f64; -} diff --git a/tests/ui/excessive_precision.stderr b/tests/ui/excessive_precision.stderr deleted file mode 100644 index 599773f2f70c..000000000000 --- a/tests/ui/excessive_precision.stderr +++ /dev/null @@ -1,112 +0,0 @@ -error: float has excessive precision - --> $DIR/excessive_precision.rs:15:26 - | -LL | const BAD32_1: f32 = 0.123_456_789_f32; - | ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79_f32` - | - = note: `-D clippy::excessive-precision` implied by `-D warnings` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:16:26 - | -LL | const BAD32_2: f32 = 0.123_456_789; - | ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:17:26 - | -LL | const BAD32_3: f32 = 0.100_000_000_000_1; - | ^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.1` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:18:29 - | -LL | const BAD32_EDGE: f32 = 1.000_000_9; - | ^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.000_001` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:20:26 - | -LL | const BAD64_1: f64 = 0.123_456_789_012_345_67f64; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66_f64` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:21:26 - | -LL | const BAD64_2: f64 = 0.123_456_789_012_345_67; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:22:26 - | -LL | const BAD64_3: f64 = 0.100_000_000_000_000_000_1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.1` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:25:22 - | -LL | println!("{:?}", 8.888_888_888_888_888_888_888); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `8.888_888_888_888_89` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:36:22 - | -LL | let bad32: f32 = 1.123_456_789; - | ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:37:26 - | -LL | let bad32_suf: f32 = 1.123_456_789_f32; - | ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8_f32` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:38:21 - | -LL | let bad32_inf = 1.123_456_789_f32; - | ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8_f32` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:40:22 - | -LL | let bad64: f64 = 0.123_456_789_012_345_67; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:41:26 - | -LL | let bad64_suf: f64 = 0.123_456_789_012_345_67f64; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66_f64` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:42:21 - | -LL | let bad64_inf = 0.123_456_789_012_345_67; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_012_345_66` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:48:36 - | -LL | let bad_vec32: Vec = vec![0.123_456_789]; - | ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:49:36 - | -LL | let bad_vec64: Vec = vec![0.123_456_789_123_456_789]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_123_456_78` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:53:24 - | -LL | let bad_e32: f32 = 1.123_456_788_888e-10; - | ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8e-10` - -error: float has excessive precision - --> $DIR/excessive_precision.rs:56:27 - | -LL | let bad_bige32: f32 = 1.123_456_788_888E-10; - | ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8E-10` - -error: aborting due to 18 previous errors - diff --git a/tests/ui/exit1.rs b/tests/ui/exit1.rs deleted file mode 100644 index 4eac6eb74672..000000000000 --- a/tests/ui/exit1.rs +++ /dev/null @@ -1,15 +0,0 @@ -#[warn(clippy::exit)] - -fn not_main() { - if true { - std::process::exit(4); - } -} - -fn main() { - if true { - std::process::exit(2); - }; - not_main(); - std::process::exit(1); -} diff --git a/tests/ui/exit1.stderr b/tests/ui/exit1.stderr deleted file mode 100644 index a8d3956aa27a..000000000000 --- a/tests/ui/exit1.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: usage of `process::exit` - --> $DIR/exit1.rs:5:9 - | -LL | std::process::exit(4); - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::exit` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/exit2.rs b/tests/ui/exit2.rs deleted file mode 100644 index 4b693ed7083f..000000000000 --- a/tests/ui/exit2.rs +++ /dev/null @@ -1,13 +0,0 @@ -#[warn(clippy::exit)] - -fn also_not_main() { - std::process::exit(3); -} - -fn main() { - if true { - std::process::exit(2); - }; - also_not_main(); - std::process::exit(1); -} diff --git a/tests/ui/exit2.stderr b/tests/ui/exit2.stderr deleted file mode 100644 index 7263e156a9d2..000000000000 --- a/tests/ui/exit2.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: usage of `process::exit` - --> $DIR/exit2.rs:4:5 - | -LL | std::process::exit(3); - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::exit` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/exit3.rs b/tests/ui/exit3.rs deleted file mode 100644 index 9dc0e1015a4f..000000000000 --- a/tests/ui/exit3.rs +++ /dev/null @@ -1,8 +0,0 @@ -#[warn(clippy::exit)] - -fn main() { - if true { - std::process::exit(2); - }; - std::process::exit(1); -} diff --git a/tests/ui/expect.rs b/tests/ui/expect.rs deleted file mode 100644 index 1073acf6f0cd..000000000000 --- a/tests/ui/expect.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![warn(clippy::expect_used)] - -fn expect_option() { - let opt = Some(0); - let _ = opt.expect(""); -} - -fn expect_result() { - let res: Result = Ok(0); - let _ = res.expect(""); -} - -fn main() { - expect_option(); - expect_result(); -} diff --git a/tests/ui/expect.stderr b/tests/ui/expect.stderr deleted file mode 100644 index 9d3fc7df15cc..000000000000 --- a/tests/ui/expect.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: used `expect()` on `an Option` value - --> $DIR/expect.rs:5:13 - | -LL | let _ = opt.expect(""); - | ^^^^^^^^^^^^^^ - | - = note: `-D clippy::expect-used` implied by `-D warnings` - = help: if this value is an `None`, it will panic - -error: used `expect()` on `a Result` value - --> $DIR/expect.rs:10:13 - | -LL | let _ = res.expect(""); - | ^^^^^^^^^^^^^^ - | - = help: if this value is an `Err`, it will panic - -error: aborting due to 2 previous errors - diff --git a/tests/ui/expect_fun_call.fixed b/tests/ui/expect_fun_call.fixed deleted file mode 100644 index f3d8a941a92b..000000000000 --- a/tests/ui/expect_fun_call.fixed +++ /dev/null @@ -1,94 +0,0 @@ -// run-rustfix - -#![warn(clippy::expect_fun_call)] - -/// Checks implementation of the `EXPECT_FUN_CALL` lint - -fn main() { - struct Foo; - - impl Foo { - fn new() -> Self { - Foo - } - - fn expect(&self, msg: &str) { - panic!("{}", msg) - } - } - - let with_some = Some("value"); - with_some.expect("error"); - - let with_none: Option = None; - with_none.expect("error"); - - let error_code = 123_i32; - let with_none_and_format: Option = None; - with_none_and_format.unwrap_or_else(|| panic!("Error {}: fake error", error_code)); - - let with_none_and_as_str: Option = None; - with_none_and_as_str.unwrap_or_else(|| panic!("Error {}: fake error", error_code)); - - let with_ok: Result<(), ()> = Ok(()); - with_ok.expect("error"); - - let with_err: Result<(), ()> = Err(()); - with_err.expect("error"); - - let error_code = 123_i32; - let with_err_and_format: Result<(), ()> = Err(()); - with_err_and_format.unwrap_or_else(|_| panic!("Error {}: fake error", error_code)); - - let with_err_and_as_str: Result<(), ()> = Err(()); - with_err_and_as_str.unwrap_or_else(|_| panic!("Error {}: fake error", error_code)); - - let with_dummy_type = Foo::new(); - with_dummy_type.expect("another test string"); - - let with_dummy_type_and_format = Foo::new(); - with_dummy_type_and_format.expect(&format!("Error {}: fake error", error_code)); - - let with_dummy_type_and_as_str = Foo::new(); - with_dummy_type_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); - - //Issue #2937 - Some("foo").unwrap_or_else(|| panic!("{} {}", 1, 2)); - - //Issue #2979 - this should not lint - { - let msg = "bar"; - Some("foo").expect(msg); - } - - { - fn get_string() -> String { - "foo".to_string() - } - - fn get_static_str() -> &'static str { - "foo" - } - - fn get_non_static_str(_: &u32) -> &str { - "foo" - } - - Some("foo").unwrap_or_else(|| { panic!(get_string()) }); - Some("foo").unwrap_or_else(|| { panic!(get_string()) }); - Some("foo").unwrap_or_else(|| { panic!(get_string()) }); - - Some("foo").unwrap_or_else(|| { panic!(get_static_str()) }); - Some("foo").unwrap_or_else(|| { panic!(get_non_static_str(&0).to_string()) }); - } - - //Issue #3839 - Some(true).unwrap_or_else(|| panic!("key {}, {}", 1, 2)); - - //Issue #4912 - the receiver is a &Option - { - let opt = Some(1); - let opt_ref = &opt; - opt_ref.unwrap_or_else(|| panic!("{:?}", opt_ref)); - } -} diff --git a/tests/ui/expect_fun_call.rs b/tests/ui/expect_fun_call.rs deleted file mode 100644 index 60bbaa89d428..000000000000 --- a/tests/ui/expect_fun_call.rs +++ /dev/null @@ -1,94 +0,0 @@ -// run-rustfix - -#![warn(clippy::expect_fun_call)] - -/// Checks implementation of the `EXPECT_FUN_CALL` lint - -fn main() { - struct Foo; - - impl Foo { - fn new() -> Self { - Foo - } - - fn expect(&self, msg: &str) { - panic!("{}", msg) - } - } - - let with_some = Some("value"); - with_some.expect("error"); - - let with_none: Option = None; - with_none.expect("error"); - - let error_code = 123_i32; - let with_none_and_format: Option = None; - with_none_and_format.expect(&format!("Error {}: fake error", error_code)); - - let with_none_and_as_str: Option = None; - with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); - - let with_ok: Result<(), ()> = Ok(()); - with_ok.expect("error"); - - let with_err: Result<(), ()> = Err(()); - with_err.expect("error"); - - let error_code = 123_i32; - let with_err_and_format: Result<(), ()> = Err(()); - with_err_and_format.expect(&format!("Error {}: fake error", error_code)); - - let with_err_and_as_str: Result<(), ()> = Err(()); - with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); - - let with_dummy_type = Foo::new(); - with_dummy_type.expect("another test string"); - - let with_dummy_type_and_format = Foo::new(); - with_dummy_type_and_format.expect(&format!("Error {}: fake error", error_code)); - - let with_dummy_type_and_as_str = Foo::new(); - with_dummy_type_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); - - //Issue #2937 - Some("foo").expect(format!("{} {}", 1, 2).as_ref()); - - //Issue #2979 - this should not lint - { - let msg = "bar"; - Some("foo").expect(msg); - } - - { - fn get_string() -> String { - "foo".to_string() - } - - fn get_static_str() -> &'static str { - "foo" - } - - fn get_non_static_str(_: &u32) -> &str { - "foo" - } - - Some("foo").expect(&get_string()); - Some("foo").expect(get_string().as_ref()); - Some("foo").expect(get_string().as_str()); - - Some("foo").expect(get_static_str()); - Some("foo").expect(get_non_static_str(&0)); - } - - //Issue #3839 - Some(true).expect(&format!("key {}, {}", 1, 2)); - - //Issue #4912 - the receiver is a &Option - { - let opt = Some(1); - let opt_ref = &opt; - opt_ref.expect(&format!("{:?}", opt_ref)); - } -} diff --git a/tests/ui/expect_fun_call.stderr b/tests/ui/expect_fun_call.stderr deleted file mode 100644 index a492e2df89d4..000000000000 --- a/tests/ui/expect_fun_call.stderr +++ /dev/null @@ -1,76 +0,0 @@ -error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:28:26 - | -LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))` - | - = note: `-D clippy::expect-fun-call` implied by `-D warnings` - -error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:31:26 - | -LL | with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))` - -error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:41:25 - | -LL | with_err_and_format.expect(&format!("Error {}: fake error", error_code)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))` - -error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:44:25 - | -LL | with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))` - -error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:56:17 - | -LL | Some("foo").expect(format!("{} {}", 1, 2).as_ref()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{} {}", 1, 2))` - -error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:77:21 - | -LL | Some("foo").expect(&get_string()); - | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })` - -error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:78:21 - | -LL | Some("foo").expect(get_string().as_ref()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })` - -error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:79:21 - | -LL | Some("foo").expect(get_string().as_str()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })` - -error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:81:21 - | -LL | Some("foo").expect(get_static_str()); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_static_str()) })` - -error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:82:21 - | -LL | Some("foo").expect(get_non_static_str(&0)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_non_static_str(&0).to_string()) })` - -error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:86:16 - | -LL | Some(true).expect(&format!("key {}, {}", 1, 2)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("key {}, {}", 1, 2))` - -error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:92:17 - | -LL | opt_ref.expect(&format!("{:?}", opt_ref)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{:?}", opt_ref))` - -error: aborting due to 12 previous errors - diff --git a/tests/ui/explicit_counter_loop.rs b/tests/ui/explicit_counter_loop.rs deleted file mode 100644 index 81d8221bd13e..000000000000 --- a/tests/ui/explicit_counter_loop.rs +++ /dev/null @@ -1,160 +0,0 @@ -#![warn(clippy::explicit_counter_loop)] - -fn main() { - let mut vec = vec![1, 2, 3, 4]; - let mut _index = 0; - for _v in &vec { - _index += 1 - } - - let mut _index = 1; - _index = 0; - for _v in &vec { - _index += 1 - } - - let mut _index = 0; - for _v in &mut vec { - _index += 1; - } - - let mut _index = 0; - for _v in vec { - _index += 1; - } -} - -mod issue_1219 { - pub fn test() { - // should not trigger the lint because variable is used after the loop #473 - let vec = vec![1, 2, 3]; - let mut index = 0; - for _v in &vec { - index += 1 - } - println!("index: {}", index); - - // should not trigger the lint because the count is conditional #1219 - let text = "banana"; - let mut count = 0; - for ch in text.chars() { - println!("{}", count); - if ch == 'a' { - continue; - } - count += 1; - } - - // should not trigger the lint because the count is conditional - let text = "banana"; - let mut count = 0; - for ch in text.chars() { - println!("{}", count); - if ch == 'a' { - count += 1; - } - } - - // should trigger the lint because the count is not conditional - let text = "banana"; - let mut count = 0; - for ch in text.chars() { - println!("{}", count); - count += 1; - if ch == 'a' { - continue; - } - } - - // should trigger the lint because the count is not conditional - let text = "banana"; - let mut count = 0; - for ch in text.chars() { - println!("{}", count); - count += 1; - for i in 0..2 { - let _ = 123; - } - } - - // should not trigger the lint because the count is incremented multiple times - let text = "banana"; - let mut count = 0; - for ch in text.chars() { - println!("{}", count); - count += 1; - for i in 0..2 { - count += 1; - } - } - } -} - -mod issue_3308 { - pub fn test() { - // should not trigger the lint because the count is incremented multiple times - let mut skips = 0; - let erasures = vec![]; - for i in 0..10 { - println!("{}", skips); - while erasures.contains(&(i + skips)) { - skips += 1; - } - } - - // should not trigger the lint because the count is incremented multiple times - let mut skips = 0; - for i in 0..10 { - println!("{}", skips); - let mut j = 0; - while j < 5 { - skips += 1; - j += 1; - } - } - - // should not trigger the lint because the count is incremented multiple times - let mut skips = 0; - for i in 0..10 { - println!("{}", skips); - for j in 0..5 { - skips += 1; - } - } - } -} - -mod issue_1670 { - pub fn test() { - let mut count = 0; - for _i in 3..10 { - count += 1; - } - } -} - -mod issue_4732 { - pub fn test() { - let slice = &[1, 2, 3]; - let mut index = 0; - - // should not trigger the lint because the count is used after the loop - for _v in slice { - index += 1 - } - let _closure = || println!("index: {}", index); - } -} - -mod issue_4677 { - pub fn test() { - let slice = &[1, 2, 3]; - - // should not trigger the lint because the count is used after incremented - let mut count = 0; - for _i in slice { - count += 1; - println!("{}", count); - } - } -} diff --git a/tests/ui/explicit_counter_loop.stderr b/tests/ui/explicit_counter_loop.stderr deleted file mode 100644 index 931af46efe66..000000000000 --- a/tests/ui/explicit_counter_loop.stderr +++ /dev/null @@ -1,46 +0,0 @@ -error: the variable `_index` is used as a loop counter. - --> $DIR/explicit_counter_loop.rs:6:5 - | -LL | for _v in &vec { - | ^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter().enumerate()` - | - = note: `-D clippy::explicit-counter-loop` implied by `-D warnings` - -error: the variable `_index` is used as a loop counter. - --> $DIR/explicit_counter_loop.rs:12:5 - | -LL | for _v in &vec { - | ^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter().enumerate()` - -error: the variable `_index` is used as a loop counter. - --> $DIR/explicit_counter_loop.rs:17:5 - | -LL | for _v in &mut vec { - | ^^^^^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter_mut().enumerate()` - -error: the variable `_index` is used as a loop counter. - --> $DIR/explicit_counter_loop.rs:22:5 - | -LL | for _v in vec { - | ^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.into_iter().enumerate()` - -error: the variable `count` is used as a loop counter. - --> $DIR/explicit_counter_loop.rs:61:9 - | -LL | for ch in text.chars() { - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `for (count, ch) in text.chars().enumerate()` - -error: the variable `count` is used as a loop counter. - --> $DIR/explicit_counter_loop.rs:72:9 - | -LL | for ch in text.chars() { - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `for (count, ch) in text.chars().enumerate()` - -error: the variable `count` is used as a loop counter. - --> $DIR/explicit_counter_loop.rs:130:9 - | -LL | for _i in 3..10 { - | ^^^^^^^^^^^^^^^ help: consider using: `for (count, _i) in (3..10).enumerate()` - -error: aborting due to 7 previous errors - diff --git a/tests/ui/explicit_write.fixed b/tests/ui/explicit_write.fixed deleted file mode 100644 index 692d2ca675f9..000000000000 --- a/tests/ui/explicit_write.fixed +++ /dev/null @@ -1,51 +0,0 @@ -// run-rustfix -#![allow(unused_imports)] -#![warn(clippy::explicit_write)] - -fn stdout() -> String { - String::new() -} - -fn stderr() -> String { - String::new() -} - -fn main() { - // these should warn - { - use std::io::Write; - print!("test"); - eprint!("test"); - println!("test"); - eprintln!("test"); - print!("test"); - eprint!("test"); - - // including newlines - println!("test\ntest"); - eprintln!("test\ntest"); - } - // these should not warn, different destination - { - use std::fmt::Write; - let mut s = String::new(); - write!(s, "test").unwrap(); - write!(s, "test").unwrap(); - writeln!(s, "test").unwrap(); - writeln!(s, "test").unwrap(); - s.write_fmt(format_args!("test")).unwrap(); - s.write_fmt(format_args!("test")).unwrap(); - write!(stdout(), "test").unwrap(); - write!(stderr(), "test").unwrap(); - writeln!(stdout(), "test").unwrap(); - writeln!(stderr(), "test").unwrap(); - stdout().write_fmt(format_args!("test")).unwrap(); - stderr().write_fmt(format_args!("test")).unwrap(); - } - // these should not warn, no unwrap - { - use std::io::Write; - std::io::stdout().write_fmt(format_args!("test")).expect("no stdout"); - std::io::stderr().write_fmt(format_args!("test")).expect("no stderr"); - } -} diff --git a/tests/ui/explicit_write.rs b/tests/ui/explicit_write.rs deleted file mode 100644 index 455c5ef55d05..000000000000 --- a/tests/ui/explicit_write.rs +++ /dev/null @@ -1,51 +0,0 @@ -// run-rustfix -#![allow(unused_imports)] -#![warn(clippy::explicit_write)] - -fn stdout() -> String { - String::new() -} - -fn stderr() -> String { - String::new() -} - -fn main() { - // these should warn - { - use std::io::Write; - write!(std::io::stdout(), "test").unwrap(); - write!(std::io::stderr(), "test").unwrap(); - writeln!(std::io::stdout(), "test").unwrap(); - writeln!(std::io::stderr(), "test").unwrap(); - std::io::stdout().write_fmt(format_args!("test")).unwrap(); - std::io::stderr().write_fmt(format_args!("test")).unwrap(); - - // including newlines - writeln!(std::io::stdout(), "test\ntest").unwrap(); - writeln!(std::io::stderr(), "test\ntest").unwrap(); - } - // these should not warn, different destination - { - use std::fmt::Write; - let mut s = String::new(); - write!(s, "test").unwrap(); - write!(s, "test").unwrap(); - writeln!(s, "test").unwrap(); - writeln!(s, "test").unwrap(); - s.write_fmt(format_args!("test")).unwrap(); - s.write_fmt(format_args!("test")).unwrap(); - write!(stdout(), "test").unwrap(); - write!(stderr(), "test").unwrap(); - writeln!(stdout(), "test").unwrap(); - writeln!(stderr(), "test").unwrap(); - stdout().write_fmt(format_args!("test")).unwrap(); - stderr().write_fmt(format_args!("test")).unwrap(); - } - // these should not warn, no unwrap - { - use std::io::Write; - std::io::stdout().write_fmt(format_args!("test")).expect("no stdout"); - std::io::stderr().write_fmt(format_args!("test")).expect("no stderr"); - } -} diff --git a/tests/ui/explicit_write.stderr b/tests/ui/explicit_write.stderr deleted file mode 100644 index 9feef9c0dc84..000000000000 --- a/tests/ui/explicit_write.stderr +++ /dev/null @@ -1,52 +0,0 @@ -error: use of `write!(stdout(), ...).unwrap()` - --> $DIR/explicit_write.rs:17:9 - | -LL | write!(std::io::stdout(), "test").unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `print!("test")` - | - = note: `-D clippy::explicit-write` implied by `-D warnings` - -error: use of `write!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:18:9 - | -LL | write!(std::io::stderr(), "test").unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprint!("test")` - -error: use of `writeln!(stdout(), ...).unwrap()` - --> $DIR/explicit_write.rs:19:9 - | -LL | writeln!(std::io::stdout(), "test").unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `println!("test")` - -error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:20:9 - | -LL | writeln!(std::io::stderr(), "test").unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("test")` - -error: use of `stdout().write_fmt(...).unwrap()` - --> $DIR/explicit_write.rs:21:9 - | -LL | std::io::stdout().write_fmt(format_args!("test")).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `print!("test")` - -error: use of `stderr().write_fmt(...).unwrap()` - --> $DIR/explicit_write.rs:22:9 - | -LL | std::io::stderr().write_fmt(format_args!("test")).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprint!("test")` - -error: use of `writeln!(stdout(), ...).unwrap()` - --> $DIR/explicit_write.rs:25:9 - | -LL | writeln!(std::io::stdout(), "test/ntest").unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `println!("test/ntest")` - -error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:26:9 - | -LL | writeln!(std::io::stderr(), "test/ntest").unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("test/ntest")` - -error: aborting due to 8 previous errors - diff --git a/tests/ui/explicit_write_non_rustfix.rs b/tests/ui/explicit_write_non_rustfix.rs deleted file mode 100644 index f21e8ef935bd..000000000000 --- a/tests/ui/explicit_write_non_rustfix.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![allow(unused_imports, clippy::blacklisted_name)] -#![warn(clippy::explicit_write)] - -fn main() { - use std::io::Write; - let bar = "bar"; - writeln!(std::io::stderr(), "foo {}", bar).unwrap(); -} diff --git a/tests/ui/explicit_write_non_rustfix.stderr b/tests/ui/explicit_write_non_rustfix.stderr deleted file mode 100644 index 77cadb99bb55..000000000000 --- a/tests/ui/explicit_write_non_rustfix.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: use of `writeln!(stderr(), ...).unwrap()`. Consider using `eprintln!` instead - --> $DIR/explicit_write_non_rustfix.rs:7:5 - | -LL | writeln!(std::io::stderr(), "foo {}", bar).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::explicit-write` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/extra_unused_lifetimes.rs b/tests/ui/extra_unused_lifetimes.rs deleted file mode 100644 index 150acfbfee75..000000000000 --- a/tests/ui/extra_unused_lifetimes.rs +++ /dev/null @@ -1,75 +0,0 @@ -#![allow( - unused, - dead_code, - clippy::needless_lifetimes, - clippy::needless_pass_by_value, - clippy::needless_arbitrary_self_type -)] -#![warn(clippy::extra_unused_lifetimes)] - -fn empty() {} - -fn used_lt<'a>(x: &'a u8) {} - -fn unused_lt<'a>(x: u8) {} - -fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) { - // 'a is useless here since it's not directly bound -} - -fn lt_return<'a, 'b: 'a>(x: &'b u8) -> &'a u8 { - panic!() -} - -fn lt_return_only<'a>() -> &'a u8 { - panic!() -} - -fn unused_lt_blergh<'a>(x: Option>) {} - -trait Foo<'a> { - fn x(&self, a: &'a u8); -} - -impl<'a> Foo<'a> for u8 { - fn x(&self, a: &'a u8) {} -} - -struct Bar; - -impl Bar { - fn x<'a>(&self) {} -} - -// test for #489 (used lifetimes in bounds) -pub fn parse<'a, I: Iterator>(_it: &mut I) { - unimplemented!() -} -pub fn parse2<'a, I>(_it: &mut I) -where - I: Iterator, -{ - unimplemented!() -} - -struct X { - x: u32, -} - -impl X { - fn self_ref_with_lifetime<'a>(&'a self) {} - fn explicit_self_with_lifetime<'a>(self: &'a Self) {} -} - -// Methods implementing traits must have matching lifetimes -mod issue4291 { - trait BadTrait { - fn unused_lt<'a>(x: u8) {} - } - - impl BadTrait for () { - fn unused_lt<'a>(_x: u8) {} - } -} - -fn main() {} diff --git a/tests/ui/extra_unused_lifetimes.stderr b/tests/ui/extra_unused_lifetimes.stderr deleted file mode 100644 index ebdb8e749520..000000000000 --- a/tests/ui/extra_unused_lifetimes.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: this lifetime isn't used in the function definition - --> $DIR/extra_unused_lifetimes.rs:14:14 - | -LL | fn unused_lt<'a>(x: u8) {} - | ^^ - | - = note: `-D clippy::extra-unused-lifetimes` implied by `-D warnings` - -error: this lifetime isn't used in the function definition - --> $DIR/extra_unused_lifetimes.rs:16:25 - | -LL | fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) { - | ^^ - -error: this lifetime isn't used in the function definition - --> $DIR/extra_unused_lifetimes.rs:41:10 - | -LL | fn x<'a>(&self) {} - | ^^ - -error: this lifetime isn't used in the function definition - --> $DIR/extra_unused_lifetimes.rs:67:22 - | -LL | fn unused_lt<'a>(x: u8) {} - | ^^ - -error: aborting due to 4 previous errors - diff --git a/tests/ui/fallible_impl_from.rs b/tests/ui/fallible_impl_from.rs deleted file mode 100644 index 679f4a7dc357..000000000000 --- a/tests/ui/fallible_impl_from.rs +++ /dev/null @@ -1,76 +0,0 @@ -#![deny(clippy::fallible_impl_from)] - -// docs example -struct Foo(i32); -impl From for Foo { - fn from(s: String) -> Self { - Foo(s.parse().unwrap()) - } -} - -struct Valid(Vec); - -impl<'a> From<&'a str> for Valid { - fn from(s: &'a str) -> Valid { - Valid(s.to_owned().into_bytes()) - } -} -impl From for Valid { - fn from(i: usize) -> Valid { - Valid(Vec::with_capacity(i)) - } -} - -struct Invalid; - -impl From for Invalid { - fn from(i: usize) -> Invalid { - if i != 42 { - panic!(); - } - Invalid - } -} - -impl From> for Invalid { - fn from(s: Option) -> Invalid { - let s = s.unwrap(); - if !s.is_empty() { - panic!(42); - } else if s.parse::().unwrap() != 42 { - panic!("{:?}", s); - } - Invalid - } -} - -trait ProjStrTrait { - type ProjString; -} -impl ProjStrTrait for Box { - type ProjString = String; -} -impl<'a> From<&'a mut as ProjStrTrait>::ProjString> for Invalid { - fn from(s: &'a mut as ProjStrTrait>::ProjString) -> Invalid { - if s.parse::().ok().unwrap() != 42 { - panic!("{:?}", s); - } - Invalid - } -} - -struct Unreachable; - -impl From for Unreachable { - fn from(s: String) -> Unreachable { - if s.is_empty() { - return Unreachable; - } - match s.chars().next() { - Some(_) => Unreachable, - None => unreachable!(), // do not lint the unreachable macro - } - } -} - -fn main() {} diff --git a/tests/ui/fallible_impl_from.stderr b/tests/ui/fallible_impl_from.stderr deleted file mode 100644 index ab976b947b35..000000000000 --- a/tests/ui/fallible_impl_from.stderr +++ /dev/null @@ -1,93 +0,0 @@ -error: consider implementing `TryFrom` instead - --> $DIR/fallible_impl_from.rs:5:1 - | -LL | / impl From for Foo { -LL | | fn from(s: String) -> Self { -LL | | Foo(s.parse().unwrap()) -LL | | } -LL | | } - | |_^ - | -note: the lint level is defined here - --> $DIR/fallible_impl_from.rs:1:9 - | -LL | #![deny(clippy::fallible_impl_from)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail. -note: potential failure(s) - --> $DIR/fallible_impl_from.rs:7:13 - | -LL | Foo(s.parse().unwrap()) - | ^^^^^^^^^^^^^^^^^^ - -error: consider implementing `TryFrom` instead - --> $DIR/fallible_impl_from.rs:26:1 - | -LL | / impl From for Invalid { -LL | | fn from(i: usize) -> Invalid { -LL | | if i != 42 { -LL | | panic!(); -... | -LL | | } -LL | | } - | |_^ - | - = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail. -note: potential failure(s) - --> $DIR/fallible_impl_from.rs:29:13 - | -LL | panic!(); - | ^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: consider implementing `TryFrom` instead - --> $DIR/fallible_impl_from.rs:35:1 - | -LL | / impl From> for Invalid { -LL | | fn from(s: Option) -> Invalid { -LL | | let s = s.unwrap(); -LL | | if !s.is_empty() { -... | -LL | | } -LL | | } - | |_^ - | - = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail. -note: potential failure(s) - --> $DIR/fallible_impl_from.rs:37:17 - | -LL | let s = s.unwrap(); - | ^^^^^^^^^^ -LL | if !s.is_empty() { -LL | panic!(42); - | ^^^^^^^^^^^ -LL | } else if s.parse::().unwrap() != 42 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | panic!("{:?}", s); - | ^^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: consider implementing `TryFrom` instead - --> $DIR/fallible_impl_from.rs:53:1 - | -LL | / impl<'a> From<&'a mut as ProjStrTrait>::ProjString> for Invalid { -LL | | fn from(s: &'a mut as ProjStrTrait>::ProjString) -> Invalid { -LL | | if s.parse::().ok().unwrap() != 42 { -LL | | panic!("{:?}", s); -... | -LL | | } -LL | | } - | |_^ - | - = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail. -note: potential failure(s) - --> $DIR/fallible_impl_from.rs:55:12 - | -LL | if s.parse::().ok().unwrap() != 42 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | panic!("{:?}", s); - | ^^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 4 previous errors - diff --git a/tests/ui/field_reassign_with_default.rs b/tests/ui/field_reassign_with_default.rs deleted file mode 100644 index 79a30c22f953..000000000000 --- a/tests/ui/field_reassign_with_default.rs +++ /dev/null @@ -1,110 +0,0 @@ -#![warn(clippy::field_reassign_with_default)] - -#[derive(Default)] -struct A { - i: i32, - j: i64, -} - -struct B { - i: i32, - j: i64, -} - -/// Implements .next() that returns a different number each time. -struct SideEffect(i32); - -impl SideEffect { - fn new() -> SideEffect { - SideEffect(0) - } - fn next(&mut self) -> i32 { - self.0 += 1; - self.0 - } -} - -fn main() { - // wrong, produces first error in stderr - let mut a: A = Default::default(); - a.i = 42; - - // right - let mut a: A = Default::default(); - - // right - let a = A { - i: 42, - ..Default::default() - }; - - // right - let mut a: A = Default::default(); - if a.i == 0 { - a.j = 12; - } - - // right - let mut a: A = Default::default(); - let b = 5; - - // right - let mut b = 32; - let mut a: A = Default::default(); - b = 2; - - // right - let b: B = B { i: 42, j: 24 }; - - // right - let mut b: B = B { i: 42, j: 24 }; - b.i = 52; - - // right - let mut b = B { i: 15, j: 16 }; - let mut a: A = Default::default(); - b.i = 2; - - // wrong, produces second error in stderr - let mut a: A = Default::default(); - a.j = 43; - a.i = 42; - - // wrong, produces third error in stderr - let mut a: A = Default::default(); - a.i = 42; - a.j = 43; - a.j = 44; - - // wrong, produces fourth error in stderr - let mut a = A::default(); - a.i = 42; - - // wrong, but does not produce an error in stderr, because we can't produce a correct kind of - // suggestion with current implementation - let mut c: (i32, i32) = Default::default(); - c.0 = 42; - c.1 = 21; - - // wrong, produces the fifth error in stderr - let mut a: A = Default::default(); - a.i = Default::default(); - - // wrong, produces the sixth error in stderr - let mut a: A = Default::default(); - a.i = Default::default(); - a.j = 45; - - // right, because an assignment refers to another field - let mut x = A::default(); - x.i = 42; - x.j = 21 + x.i as i64; - - // right, we bail out if there's a reassignment to the same variable, since there is a risk of - // side-effects affecting the outcome - let mut x = A::default(); - let mut side_effect = SideEffect::new(); - x.i = side_effect.next(); - x.j = 2; - x.i = side_effect.next(); -} diff --git a/tests/ui/field_reassign_with_default.stderr b/tests/ui/field_reassign_with_default.stderr deleted file mode 100644 index c788ebae5526..000000000000 --- a/tests/ui/field_reassign_with_default.stderr +++ /dev/null @@ -1,75 +0,0 @@ -error: field assignment outside of initializer for an instance created with Default::default() - --> $DIR/field_reassign_with_default.rs:30:5 - | -LL | a.i = 42; - | ^^^^^^^^^ - | - = note: `-D clippy::field-reassign-with-default` implied by `-D warnings` -note: consider initializing the variable with `A { i: 42, ..Default::default() }` and removing relevant reassignments - --> $DIR/field_reassign_with_default.rs:29:5 - | -LL | let mut a: A = Default::default(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: field assignment outside of initializer for an instance created with Default::default() - --> $DIR/field_reassign_with_default.rs:70:5 - | -LL | a.j = 43; - | ^^^^^^^^^ - | -note: consider initializing the variable with `A { j: 43, i: 42 }` and removing relevant reassignments - --> $DIR/field_reassign_with_default.rs:69:5 - | -LL | let mut a: A = Default::default(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: field assignment outside of initializer for an instance created with Default::default() - --> $DIR/field_reassign_with_default.rs:75:5 - | -LL | a.i = 42; - | ^^^^^^^^^ - | -note: consider initializing the variable with `A { i: 42, j: 44 }` and removing relevant reassignments - --> $DIR/field_reassign_with_default.rs:74:5 - | -LL | let mut a: A = Default::default(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: field assignment outside of initializer for an instance created with Default::default() - --> $DIR/field_reassign_with_default.rs:81:5 - | -LL | a.i = 42; - | ^^^^^^^^^ - | -note: consider initializing the variable with `A { i: 42, ..Default::default() }` and removing relevant reassignments - --> $DIR/field_reassign_with_default.rs:80:5 - | -LL | let mut a = A::default(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: field assignment outside of initializer for an instance created with Default::default() - --> $DIR/field_reassign_with_default.rs:91:5 - | -LL | a.i = Default::default(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: consider initializing the variable with `A::default()` and removing relevant reassignments - --> $DIR/field_reassign_with_default.rs:90:5 - | -LL | let mut a: A = Default::default(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: field assignment outside of initializer for an instance created with Default::default() - --> $DIR/field_reassign_with_default.rs:95:5 - | -LL | a.i = Default::default(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: consider initializing the variable with `A { j: 45, ..Default::default() }` and removing relevant reassignments - --> $DIR/field_reassign_with_default.rs:94:5 - | -LL | let mut a: A = Default::default(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/filetype_is_file.rs b/tests/ui/filetype_is_file.rs deleted file mode 100644 index 5de8fe8cdd7b..000000000000 --- a/tests/ui/filetype_is_file.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![warn(clippy::filetype_is_file)] - -fn main() -> std::io::Result<()> { - use std::fs; - use std::ops::BitOr; - - // !filetype.is_dir() - if fs::metadata("foo.txt")?.file_type().is_file() { - // read file - } - - // positive of filetype.is_dir() - if !fs::metadata("foo.txt")?.file_type().is_file() { - // handle dir - } - - // false positive of filetype.is_dir() - if !fs::metadata("foo.txt")?.file_type().is_file().bitor(true) { - // ... - } - - Ok(()) -} diff --git a/tests/ui/filetype_is_file.stderr b/tests/ui/filetype_is_file.stderr deleted file mode 100644 index cd1e3ac37fe8..000000000000 --- a/tests/ui/filetype_is_file.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error: `FileType::is_file()` only covers regular files - --> $DIR/filetype_is_file.rs:8:8 - | -LL | if fs::metadata("foo.txt")?.file_type().is_file() { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::filetype-is-file` implied by `-D warnings` - = help: use `!FileType::is_dir()` instead - -error: `!FileType::is_file()` only denies regular files - --> $DIR/filetype_is_file.rs:13:8 - | -LL | if !fs::metadata("foo.txt")?.file_type().is_file() { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use `FileType::is_dir()` instead - -error: `FileType::is_file()` only covers regular files - --> $DIR/filetype_is_file.rs:18:9 - | -LL | if !fs::metadata("foo.txt")?.file_type().is_file().bitor(true) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use `!FileType::is_dir()` instead - -error: aborting due to 3 previous errors - diff --git a/tests/ui/filter_map_next.rs b/tests/ui/filter_map_next.rs deleted file mode 100644 index dbeb2354309c..000000000000 --- a/tests/ui/filter_map_next.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![warn(clippy::all, clippy::pedantic)] - -fn main() { - let a = ["1", "lol", "3", "NaN", "5"]; - - #[rustfmt::skip] - let _: Option = vec![1, 2, 3, 4, 5, 6] - .into_iter() - .filter_map(|x| { - if x == 2 { - Some(x * 2) - } else { - None - } - }) - .next(); -} diff --git a/tests/ui/filter_map_next.stderr b/tests/ui/filter_map_next.stderr deleted file mode 100644 index 45427684d96e..000000000000 --- a/tests/ui/filter_map_next.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead. - --> $DIR/filter_map_next.rs:7:26 - | -LL | let _: Option = vec![1, 2, 3, 4, 5, 6] - | __________________________^ -LL | | .into_iter() -LL | | .filter_map(|x| { -LL | | if x == 2 { -... | -LL | | }) -LL | | .next(); - | |_______________^ - | - = note: `-D clippy::filter-map-next` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/filter_map_next_fixable.fixed b/tests/ui/filter_map_next_fixable.fixed deleted file mode 100644 index c3992d7e92cf..000000000000 --- a/tests/ui/filter_map_next_fixable.fixed +++ /dev/null @@ -1,10 +0,0 @@ -// run-rustfix - -#![warn(clippy::all, clippy::pedantic)] - -fn main() { - let a = ["1", "lol", "3", "NaN", "5"]; - - let element: Option = a.iter().find_map(|s| s.parse().ok()); - assert_eq!(element, Some(1)); -} diff --git a/tests/ui/filter_map_next_fixable.rs b/tests/ui/filter_map_next_fixable.rs deleted file mode 100644 index 447219a96839..000000000000 --- a/tests/ui/filter_map_next_fixable.rs +++ /dev/null @@ -1,10 +0,0 @@ -// run-rustfix - -#![warn(clippy::all, clippy::pedantic)] - -fn main() { - let a = ["1", "lol", "3", "NaN", "5"]; - - let element: Option = a.iter().filter_map(|s| s.parse().ok()).next(); - assert_eq!(element, Some(1)); -} diff --git a/tests/ui/filter_map_next_fixable.stderr b/tests/ui/filter_map_next_fixable.stderr deleted file mode 100644 index 6c2530e0379e..000000000000 --- a/tests/ui/filter_map_next_fixable.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead. - --> $DIR/filter_map_next_fixable.rs:8:32 - | -LL | let element: Option = a.iter().filter_map(|s| s.parse().ok()).next(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `a.iter().find_map(|s| s.parse().ok())` - | - = note: `-D clippy::filter-map-next` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/filter_methods.rs b/tests/ui/filter_methods.rs deleted file mode 100644 index 514502416192..000000000000 --- a/tests/ui/filter_methods.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![warn(clippy::all, clippy::pedantic)] -#![allow(clippy::clippy::let_underscore_drop)] -#![allow(clippy::missing_docs_in_private_items)] - -fn main() { - let _: Vec<_> = vec![5; 6].into_iter().filter(|&x| x == 0).map(|x| x * 2).collect(); - - let _: Vec<_> = vec![5_i8; 6] - .into_iter() - .filter(|&x| x == 0) - .flat_map(|x| x.checked_mul(2)) - .collect(); - - let _: Vec<_> = vec![5_i8; 6] - .into_iter() - .filter_map(|x| x.checked_mul(2)) - .flat_map(|x| x.checked_mul(2)) - .collect(); - - let _: Vec<_> = vec![5_i8; 6] - .into_iter() - .filter_map(|x| x.checked_mul(2)) - .map(|x| x.checked_mul(2)) - .collect(); -} diff --git a/tests/ui/filter_methods.stderr b/tests/ui/filter_methods.stderr deleted file mode 100644 index 119226813793..000000000000 --- a/tests/ui/filter_methods.stderr +++ /dev/null @@ -1,47 +0,0 @@ -error: called `filter(..).map(..)` on an `Iterator` - --> $DIR/filter_methods.rs:6:21 - | -LL | let _: Vec<_> = vec![5; 6].into_iter().filter(|&x| x == 0).map(|x| x * 2).collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::filter-map` implied by `-D warnings` - = help: this is more succinctly expressed by calling `.filter_map(..)` instead - -error: called `filter(..).flat_map(..)` on an `Iterator` - --> $DIR/filter_methods.rs:8:21 - | -LL | let _: Vec<_> = vec![5_i8; 6] - | _____________________^ -LL | | .into_iter() -LL | | .filter(|&x| x == 0) -LL | | .flat_map(|x| x.checked_mul(2)) - | |_______________________________________^ - | - = help: this is more succinctly expressed by calling `.flat_map(..)` and filtering by returning `iter::empty()` - -error: called `filter_map(..).flat_map(..)` on an `Iterator` - --> $DIR/filter_methods.rs:14:21 - | -LL | let _: Vec<_> = vec![5_i8; 6] - | _____________________^ -LL | | .into_iter() -LL | | .filter_map(|x| x.checked_mul(2)) -LL | | .flat_map(|x| x.checked_mul(2)) - | |_______________________________________^ - | - = help: this is more succinctly expressed by calling `.flat_map(..)` and filtering by returning `iter::empty()` - -error: called `filter_map(..).map(..)` on an `Iterator` - --> $DIR/filter_methods.rs:20:21 - | -LL | let _: Vec<_> = vec![5_i8; 6] - | _____________________^ -LL | | .into_iter() -LL | | .filter_map(|x| x.checked_mul(2)) -LL | | .map(|x| x.checked_mul(2)) - | |__________________________________^ - | - = help: this is more succinctly expressed by only calling `.filter_map(..)` instead - -error: aborting due to 4 previous errors - diff --git a/tests/ui/find_map.rs b/tests/ui/find_map.rs deleted file mode 100644 index 88d3b0e74900..000000000000 --- a/tests/ui/find_map.rs +++ /dev/null @@ -1,33 +0,0 @@ -#![warn(clippy::all, clippy::pedantic)] - -#[derive(Debug, Copy, Clone)] -enum Flavor { - Chocolate, -} - -#[derive(Debug, Copy, Clone)] -enum Dessert { - Banana, - Pudding, - Cake(Flavor), -} - -fn main() { - let desserts_of_the_week = vec![Dessert::Banana, Dessert::Cake(Flavor::Chocolate), Dessert::Pudding]; - - let a = ["lol", "NaN", "2", "5", "Xunda"]; - - let _: Option = a.iter().find(|s| s.parse::().is_ok()).map(|s| s.parse().unwrap()); - - #[allow(clippy::match_like_matches_macro)] - let _: Option = desserts_of_the_week - .iter() - .find(|dessert| match *dessert { - Dessert::Cake(_) => true, - _ => false, - }) - .map(|dessert| match *dessert { - Dessert::Cake(ref flavor) => *flavor, - _ => unreachable!(), - }); -} diff --git a/tests/ui/find_map.stderr b/tests/ui/find_map.stderr deleted file mode 100644 index aea3cc62afcc..000000000000 --- a/tests/ui/find_map.stderr +++ /dev/null @@ -1,26 +0,0 @@ -error: called `find(..).map(..)` on an `Iterator` - --> $DIR/find_map.rs:20:26 - | -LL | let _: Option = a.iter().find(|s| s.parse::().is_ok()).map(|s| s.parse().unwrap()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::find-map` implied by `-D warnings` - = help: this is more succinctly expressed by calling `.find_map(..)` instead - -error: called `find(..).map(..)` on an `Iterator` - --> $DIR/find_map.rs:23:29 - | -LL | let _: Option = desserts_of_the_week - | _____________________________^ -LL | | .iter() -LL | | .find(|dessert| match *dessert { -LL | | Dessert::Cake(_) => true, -... | -LL | | _ => unreachable!(), -LL | | }); - | |__________^ - | - = help: this is more succinctly expressed by calling `.find_map(..)` instead - -error: aborting due to 2 previous errors - diff --git a/tests/ui/float_arithmetic.rs b/tests/ui/float_arithmetic.rs deleted file mode 100644 index 60fa7569eb9d..000000000000 --- a/tests/ui/float_arithmetic.rs +++ /dev/null @@ -1,52 +0,0 @@ -#![warn(clippy::integer_arithmetic, clippy::float_arithmetic)] -#![allow( - unused, - clippy::shadow_reuse, - clippy::shadow_unrelated, - clippy::no_effect, - clippy::unnecessary_operation, - clippy::op_ref -)] - -#[rustfmt::skip] -fn main() { - let mut f = 1.0f32; - - f * 2.0; - - 1.0 + f; - f * 2.0; - f / 2.0; - f - 2.0 * 4.2; - -f; - - f += 1.0; - f -= 1.0; - f *= 2.0; - f /= 2.0; -} - -// also warn about floating point arith with references involved - -pub fn float_arith_ref() { - 3.1_f32 + &1.2_f32; - &3.4_f32 + 1.5_f32; - &3.5_f32 + &1.3_f32; -} - -pub fn float_foo(f: &f32) -> f32 { - let a = 5.1; - a + f -} - -pub fn float_bar(f1: &f32, f2: &f32) -> f32 { - f1 + f2 -} - -pub fn float_baz(f1: f32, f2: &f32) -> f32 { - f1 + f2 -} - -pub fn float_qux(f1: f32, f2: f32) -> f32 { - (&f1 + &f2) -} diff --git a/tests/ui/float_arithmetic.stderr b/tests/ui/float_arithmetic.stderr deleted file mode 100644 index 1ceffb35beed..000000000000 --- a/tests/ui/float_arithmetic.stderr +++ /dev/null @@ -1,106 +0,0 @@ -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:15:5 - | -LL | f * 2.0; - | ^^^^^^^ - | - = note: `-D clippy::float-arithmetic` implied by `-D warnings` - -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:17:5 - | -LL | 1.0 + f; - | ^^^^^^^ - -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:18:5 - | -LL | f * 2.0; - | ^^^^^^^ - -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:19:5 - | -LL | f / 2.0; - | ^^^^^^^ - -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:20:5 - | -LL | f - 2.0 * 4.2; - | ^^^^^^^^^^^^^ - -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:21:5 - | -LL | -f; - | ^^ - -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:23:5 - | -LL | f += 1.0; - | ^^^^^^^^ - -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:24:5 - | -LL | f -= 1.0; - | ^^^^^^^^ - -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:25:5 - | -LL | f *= 2.0; - | ^^^^^^^^ - -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:26:5 - | -LL | f /= 2.0; - | ^^^^^^^^ - -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:32:5 - | -LL | 3.1_f32 + &1.2_f32; - | ^^^^^^^^^^^^^^^^^^ - -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:33:5 - | -LL | &3.4_f32 + 1.5_f32; - | ^^^^^^^^^^^^^^^^^^ - -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:34:5 - | -LL | &3.5_f32 + &1.3_f32; - | ^^^^^^^^^^^^^^^^^^^ - -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:39:5 - | -LL | a + f - | ^^^^^ - -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:43:5 - | -LL | f1 + f2 - | ^^^^^^^ - -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:47:5 - | -LL | f1 + f2 - | ^^^^^^^ - -error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:51:5 - | -LL | (&f1 + &f2) - | ^^^^^^^^^^^ - -error: aborting due to 17 previous errors - diff --git a/tests/ui/float_cmp.rs b/tests/ui/float_cmp.rs deleted file mode 100644 index 586784b73e69..000000000000 --- a/tests/ui/float_cmp.rs +++ /dev/null @@ -1,124 +0,0 @@ -#![warn(clippy::float_cmp)] -#![allow( - unused, - clippy::no_effect, - clippy::op_ref, - clippy::unnecessary_operation, - clippy::cast_lossless, - clippy::many_single_char_names -)] - -use std::ops::Add; - -const ZERO: f32 = 0.0; -const ONE: f32 = ZERO + 1.0; - -fn twice(x: T) -> T -where - T: Add + Copy, -{ - x + x -} - -fn eq_fl(x: f32, y: f32) -> bool { - if x.is_nan() { - y.is_nan() - } else { - x == y - } // no error, inside "eq" fn -} - -fn fl_eq(x: f32, y: f32) -> bool { - if x.is_nan() { - y.is_nan() - } else { - x == y - } // no error, inside "eq" fn -} - -struct X { - val: f32, -} - -impl PartialEq for X { - fn eq(&self, o: &X) -> bool { - if self.val.is_nan() { - o.val.is_nan() - } else { - self.val == o.val // no error, inside "eq" fn - } - } -} - -fn main() { - ZERO == 0f32; //no error, comparison with zero is ok - 1.0f32 != f32::INFINITY; // also comparison with infinity - 1.0f32 != f32::NEG_INFINITY; // and negative infinity - ZERO == 0.0; //no error, comparison with zero is ok - ZERO + ZERO != 1.0; //no error, comparison with zero is ok - - ONE == 1f32; - ONE == 1.0 + 0.0; - ONE + ONE == ZERO + ONE + ONE; - ONE != 2.0; - ONE != 0.0; // no error, comparison with zero is ok - twice(ONE) != ONE; - ONE as f64 != 2.0; - ONE as f64 != 0.0; // no error, comparison with zero is ok - - let x: f64 = 1.0; - - x == 1.0; - x != 0f64; // no error, comparison with zero is ok - - twice(x) != twice(ONE as f64); - - x < 0.0; // no errors, lower or greater comparisons need no fuzzyness - x > 0.0; - x <= 0.0; - x >= 0.0; - - let xs: [f32; 1] = [0.0]; - let a: *const f32 = xs.as_ptr(); - let b: *const f32 = xs.as_ptr(); - - assert_eq!(a, b); // no errors - - const ZERO_ARRAY: [f32; 2] = [0.0, 0.0]; - const NON_ZERO_ARRAY: [f32; 2] = [0.0, 0.1]; - - let i = 0; - let j = 1; - - ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; // ok, because lhs is zero regardless of i - NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; - - let a1: [f32; 1] = [0.0]; - let a2: [f32; 1] = [1.1]; - - a1 == a2; - a1[0] == a2[0]; - - // no errors - comparing signums is ok - let x32 = 3.21f32; - 1.23f32.signum() == x32.signum(); - 1.23f32.signum() == -(x32.signum()); - 1.23f32.signum() == 3.21f32.signum(); - - 1.23f32.signum() != x32.signum(); - 1.23f32.signum() != -(x32.signum()); - 1.23f32.signum() != 3.21f32.signum(); - - let x64 = 3.21f64; - 1.23f64.signum() == x64.signum(); - 1.23f64.signum() == -(x64.signum()); - 1.23f64.signum() == 3.21f64.signum(); - - 1.23f64.signum() != x64.signum(); - 1.23f64.signum() != -(x64.signum()); - 1.23f64.signum() != 3.21f64.signum(); - - // the comparison should also look through references - &0.0 == &ZERO; - &&&&0.0 == &&&&ZERO; -} diff --git a/tests/ui/float_cmp.stderr b/tests/ui/float_cmp.stderr deleted file mode 100644 index bb4051c46620..000000000000 --- a/tests/ui/float_cmp.stderr +++ /dev/null @@ -1,51 +0,0 @@ -error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:66:5 - | -LL | ONE as f64 != 2.0; - | ^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE as f64 - 2.0).abs() > error_margin` - | - = note: `-D clippy::float-cmp` implied by `-D warnings` - = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` - -error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:71:5 - | -LL | x == 1.0; - | ^^^^^^^^ help: consider comparing them within some margin of error: `(x - 1.0).abs() < error_margin` - | - = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` - -error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:74:5 - | -LL | twice(x) != twice(ONE as f64); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(twice(x) - twice(ONE as f64)).abs() > error_margin` - | - = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` - -error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:94:5 - | -LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(NON_ZERO_ARRAY[i] - NON_ZERO_ARRAY[j]).abs() < error_margin` - | - = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` - -error: strict comparison of `f32` or `f64` arrays - --> $DIR/float_cmp.rs:99:5 - | -LL | a1 == a2; - | ^^^^^^^^ - | - = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` - -error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:100:5 - | -LL | a1[0] == a2[0]; - | ^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(a1[0] - a2[0]).abs() < error_margin` - | - = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` - -error: aborting due to 6 previous errors - diff --git a/tests/ui/float_cmp_const.rs b/tests/ui/float_cmp_const.rs deleted file mode 100644 index 263d9a7b92dd..000000000000 --- a/tests/ui/float_cmp_const.rs +++ /dev/null @@ -1,62 +0,0 @@ -// does not test any rustfixable lints - -#![warn(clippy::float_cmp_const)] -#![allow(clippy::float_cmp)] -#![allow(unused, clippy::no_effect, clippy::unnecessary_operation)] - -const ONE: f32 = 1.0; -const TWO: f32 = 2.0; - -fn eq_one(x: f32) -> bool { - if x.is_nan() { - false - } else { - x == ONE - } // no error, inside "eq" fn -} - -fn main() { - // has errors - 1f32 == ONE; - TWO == ONE; - TWO != ONE; - ONE + ONE == TWO; - let x = 1; - x as f32 == ONE; - - let v = 0.9; - v == ONE; - v != ONE; - - // no errors, lower than or greater than comparisons - v < ONE; - v > ONE; - v <= ONE; - v >= ONE; - - // no errors, zero and infinity values - ONE != 0f32; - TWO == 0f32; - ONE != f32::INFINITY; - ONE == f32::NEG_INFINITY; - - // no errors, but will warn clippy::float_cmp if '#![allow(float_cmp)]' above is removed - let w = 1.1; - v == w; - v != w; - v == 1.0; - v != 1.0; - - const ZERO_ARRAY: [f32; 3] = [0.0, 0.0, 0.0]; - const ZERO_INF_ARRAY: [f32; 3] = [0.0, f32::INFINITY, f32::NEG_INFINITY]; - const NON_ZERO_ARRAY: [f32; 3] = [0.0, 0.1, 0.2]; - const NON_ZERO_ARRAY2: [f32; 3] = [0.2, 0.1, 0.0]; - - // no errors, zero and infinity values - NON_ZERO_ARRAY[0] == NON_ZERO_ARRAY2[1]; // lhs is 0.0 - ZERO_ARRAY == NON_ZERO_ARRAY; // lhs is all zeros - ZERO_INF_ARRAY == NON_ZERO_ARRAY; // lhs is all zeros or infinities - - // has errors - NON_ZERO_ARRAY == NON_ZERO_ARRAY2; -} diff --git a/tests/ui/float_cmp_const.stderr b/tests/ui/float_cmp_const.stderr deleted file mode 100644 index 5d0455363e8e..000000000000 --- a/tests/ui/float_cmp_const.stderr +++ /dev/null @@ -1,67 +0,0 @@ -error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:20:5 - | -LL | 1f32 == ONE; - | ^^^^^^^^^^^ help: consider comparing them within some margin of error: `(1f32 - ONE).abs() < error_margin` - | - = note: `-D clippy::float-cmp-const` implied by `-D warnings` - = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` - -error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:21:5 - | -LL | TWO == ONE; - | ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() < error_margin` - | - = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` - -error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:22:5 - | -LL | TWO != ONE; - | ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() > error_margin` - | - = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` - -error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:23:5 - | -LL | ONE + ONE == TWO; - | ^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE + ONE - TWO).abs() < error_margin` - | - = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` - -error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:25:5 - | -LL | x as f32 == ONE; - | ^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(x as f32 - ONE).abs() < error_margin` - | - = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` - -error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:28:5 - | -LL | v == ONE; - | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() < error_margin` - | - = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` - -error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:29:5 - | -LL | v != ONE; - | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() > error_margin` - | - = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` - -error: strict comparison of `f32` or `f64` constant arrays - --> $DIR/float_cmp_const.rs:61:5 - | -LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` - -error: aborting due to 8 previous errors - diff --git a/tests/ui/float_equality_without_abs.rs b/tests/ui/float_equality_without_abs.rs deleted file mode 100644 index d40fa00c3155..000000000000 --- a/tests/ui/float_equality_without_abs.rs +++ /dev/null @@ -1,31 +0,0 @@ -#![warn(clippy::float_equality_without_abs)] - -pub fn is_roughly_equal(a: f32, b: f32) -> bool { - (a - b) < f32::EPSILON -} - -pub fn main() { - // all errors - is_roughly_equal(1.0, 2.0); - let a = 0.05; - let b = 0.0500001; - - let _ = (a - b) < f32::EPSILON; - let _ = a - b < f32::EPSILON; - let _ = a - b.abs() < f32::EPSILON; - let _ = (a as f64 - b as f64) < f64::EPSILON; - let _ = 1.0 - 2.0 < f32::EPSILON; - - let _ = f32::EPSILON > (a - b); - let _ = f32::EPSILON > a - b; - let _ = f32::EPSILON > a - b.abs(); - let _ = f64::EPSILON > (a as f64 - b as f64); - let _ = f32::EPSILON > 1.0 - 2.0; - - // those are correct - let _ = (a - b).abs() < f32::EPSILON; - let _ = (a as f64 - b as f64).abs() < f64::EPSILON; - - let _ = f32::EPSILON > (a - b).abs(); - let _ = f64::EPSILON > (a as f64 - b as f64).abs(); -} diff --git a/tests/ui/float_equality_without_abs.stderr b/tests/ui/float_equality_without_abs.stderr deleted file mode 100644 index b34c8159da04..000000000000 --- a/tests/ui/float_equality_without_abs.stderr +++ /dev/null @@ -1,92 +0,0 @@ -error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:4:5 - | -LL | (a - b) < f32::EPSILON - | -------^^^^^^^^^^^^^^^ - | | - | help: add `.abs()`: `(a - b).abs()` - | - = note: `-D clippy::float-equality-without-abs` implied by `-D warnings` - -error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:13:13 - | -LL | let _ = (a - b) < f32::EPSILON; - | -------^^^^^^^^^^^^^^^ - | | - | help: add `.abs()`: `(a - b).abs()` - -error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:14:13 - | -LL | let _ = a - b < f32::EPSILON; - | -----^^^^^^^^^^^^^^^ - | | - | help: add `.abs()`: `(a - b).abs()` - -error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:15:13 - | -LL | let _ = a - b.abs() < f32::EPSILON; - | -----------^^^^^^^^^^^^^^^ - | | - | help: add `.abs()`: `(a - b.abs()).abs()` - -error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:16:13 - | -LL | let _ = (a as f64 - b as f64) < f64::EPSILON; - | ---------------------^^^^^^^^^^^^^^^ - | | - | help: add `.abs()`: `(a as f64 - b as f64).abs()` - -error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:17:13 - | -LL | let _ = 1.0 - 2.0 < f32::EPSILON; - | ---------^^^^^^^^^^^^^^^ - | | - | help: add `.abs()`: `(1.0 - 2.0).abs()` - -error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:19:13 - | -LL | let _ = f32::EPSILON > (a - b); - | ^^^^^^^^^^^^^^^------- - | | - | help: add `.abs()`: `(a - b).abs()` - -error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:20:13 - | -LL | let _ = f32::EPSILON > a - b; - | ^^^^^^^^^^^^^^^----- - | | - | help: add `.abs()`: `(a - b).abs()` - -error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:21:13 - | -LL | let _ = f32::EPSILON > a - b.abs(); - | ^^^^^^^^^^^^^^^----------- - | | - | help: add `.abs()`: `(a - b.abs()).abs()` - -error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:22:13 - | -LL | let _ = f64::EPSILON > (a as f64 - b as f64); - | ^^^^^^^^^^^^^^^--------------------- - | | - | help: add `.abs()`: `(a as f64 - b as f64).abs()` - -error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:23:13 - | -LL | let _ = f32::EPSILON > 1.0 - 2.0; - | ^^^^^^^^^^^^^^^--------- - | | - | help: add `.abs()`: `(1.0 - 2.0).abs()` - -error: aborting due to 11 previous errors - diff --git a/tests/ui/floating_point_abs.fixed b/tests/ui/floating_point_abs.fixed deleted file mode 100644 index b623e4988e7d..000000000000 --- a/tests/ui/floating_point_abs.fixed +++ /dev/null @@ -1,98 +0,0 @@ -// run-rustfix -#![warn(clippy::suboptimal_flops)] - -struct A { - a: f64, - b: f64, -} - -fn fake_abs1(num: f64) -> f64 { - num.abs() -} - -fn fake_abs2(num: f64) -> f64 { - num.abs() -} - -fn fake_abs3(a: A) -> f64 { - a.a.abs() -} - -fn fake_abs4(num: f64) -> f64 { - num.abs() -} - -fn fake_abs5(a: A) -> f64 { - a.a.abs() -} - -fn fake_nabs1(num: f64) -> f64 { - -num.abs() -} - -fn fake_nabs2(num: f64) -> f64 { - -num.abs() -} - -fn fake_nabs3(a: A) -> A { - A { - a: -a.a.abs(), - b: a.b, - } -} - -fn not_fake_abs1(num: f64) -> f64 { - if num > 0.0 { - num - } else { - -num - 1f64 - } -} - -fn not_fake_abs2(num: f64) -> f64 { - if num > 0.0 { - num + 1.0 - } else { - -(num + 1.0) - } -} - -fn not_fake_abs3(num1: f64, num2: f64) -> f64 { - if num1 > 0.0 { - num2 - } else { - -num2 - } -} - -fn not_fake_abs4(a: A) -> f64 { - if a.a > 0.0 { - a.b - } else { - -a.b - } -} - -fn not_fake_abs5(a: A) -> f64 { - if a.a > 0.0 { - a.a - } else { - -a.b - } -} - -fn main() { - fake_abs1(5.0); - fake_abs2(5.0); - fake_abs3(A { a: 5.0, b: 5.0 }); - fake_abs4(5.0); - fake_abs5(A { a: 5.0, b: 5.0 }); - fake_nabs1(5.0); - fake_nabs2(5.0); - fake_nabs3(A { a: 5.0, b: 5.0 }); - not_fake_abs1(5.0); - not_fake_abs2(5.0); - not_fake_abs3(5.0, 5.0); - not_fake_abs4(A { a: 5.0, b: 5.0 }); - not_fake_abs5(A { a: 5.0, b: 5.0 }); -} diff --git a/tests/ui/floating_point_abs.rs b/tests/ui/floating_point_abs.rs deleted file mode 100644 index cbf9c94e41e6..000000000000 --- a/tests/ui/floating_point_abs.rs +++ /dev/null @@ -1,126 +0,0 @@ -// run-rustfix -#![warn(clippy::suboptimal_flops)] - -struct A { - a: f64, - b: f64, -} - -fn fake_abs1(num: f64) -> f64 { - if num >= 0.0 { - num - } else { - -num - } -} - -fn fake_abs2(num: f64) -> f64 { - if 0.0 < num { - num - } else { - -num - } -} - -fn fake_abs3(a: A) -> f64 { - if a.a > 0.0 { - a.a - } else { - -a.a - } -} - -fn fake_abs4(num: f64) -> f64 { - if 0.0 >= num { - -num - } else { - num - } -} - -fn fake_abs5(a: A) -> f64 { - if a.a < 0.0 { - -a.a - } else { - a.a - } -} - -fn fake_nabs1(num: f64) -> f64 { - if num < 0.0 { - num - } else { - -num - } -} - -fn fake_nabs2(num: f64) -> f64 { - if 0.0 >= num { - num - } else { - -num - } -} - -fn fake_nabs3(a: A) -> A { - A { - a: if a.a >= 0.0 { -a.a } else { a.a }, - b: a.b, - } -} - -fn not_fake_abs1(num: f64) -> f64 { - if num > 0.0 { - num - } else { - -num - 1f64 - } -} - -fn not_fake_abs2(num: f64) -> f64 { - if num > 0.0 { - num + 1.0 - } else { - -(num + 1.0) - } -} - -fn not_fake_abs3(num1: f64, num2: f64) -> f64 { - if num1 > 0.0 { - num2 - } else { - -num2 - } -} - -fn not_fake_abs4(a: A) -> f64 { - if a.a > 0.0 { - a.b - } else { - -a.b - } -} - -fn not_fake_abs5(a: A) -> f64 { - if a.a > 0.0 { - a.a - } else { - -a.b - } -} - -fn main() { - fake_abs1(5.0); - fake_abs2(5.0); - fake_abs3(A { a: 5.0, b: 5.0 }); - fake_abs4(5.0); - fake_abs5(A { a: 5.0, b: 5.0 }); - fake_nabs1(5.0); - fake_nabs2(5.0); - fake_nabs3(A { a: 5.0, b: 5.0 }); - not_fake_abs1(5.0); - not_fake_abs2(5.0); - not_fake_abs3(5.0, 5.0); - not_fake_abs4(A { a: 5.0, b: 5.0 }); - not_fake_abs5(A { a: 5.0, b: 5.0 }); -} diff --git a/tests/ui/floating_point_abs.stderr b/tests/ui/floating_point_abs.stderr deleted file mode 100644 index 74a71f2ca7c5..000000000000 --- a/tests/ui/floating_point_abs.stderr +++ /dev/null @@ -1,80 +0,0 @@ -error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:10:5 - | -LL | / if num >= 0.0 { -LL | | num -LL | | } else { -LL | | -num -LL | | } - | |_____^ help: try: `num.abs()` - | - = note: `-D clippy::suboptimal-flops` implied by `-D warnings` - -error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:18:5 - | -LL | / if 0.0 < num { -LL | | num -LL | | } else { -LL | | -num -LL | | } - | |_____^ help: try: `num.abs()` - -error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:26:5 - | -LL | / if a.a > 0.0 { -LL | | a.a -LL | | } else { -LL | | -a.a -LL | | } - | |_____^ help: try: `a.a.abs()` - -error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:34:5 - | -LL | / if 0.0 >= num { -LL | | -num -LL | | } else { -LL | | num -LL | | } - | |_____^ help: try: `num.abs()` - -error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:42:5 - | -LL | / if a.a < 0.0 { -LL | | -a.a -LL | | } else { -LL | | a.a -LL | | } - | |_____^ help: try: `a.a.abs()` - -error: manual implementation of negation of `abs` method - --> $DIR/floating_point_abs.rs:50:5 - | -LL | / if num < 0.0 { -LL | | num -LL | | } else { -LL | | -num -LL | | } - | |_____^ help: try: `-num.abs()` - -error: manual implementation of negation of `abs` method - --> $DIR/floating_point_abs.rs:58:5 - | -LL | / if 0.0 >= num { -LL | | num -LL | | } else { -LL | | -num -LL | | } - | |_____^ help: try: `-num.abs()` - -error: manual implementation of negation of `abs` method - --> $DIR/floating_point_abs.rs:67:12 - | -LL | a: if a.a >= 0.0 { -a.a } else { a.a }, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-a.a.abs()` - -error: aborting due to 8 previous errors - diff --git a/tests/ui/floating_point_exp.fixed b/tests/ui/floating_point_exp.fixed deleted file mode 100644 index ae7805fdf018..000000000000 --- a/tests/ui/floating_point_exp.fixed +++ /dev/null @@ -1,18 +0,0 @@ -// run-rustfix -#![warn(clippy::imprecise_flops)] - -fn main() { - let x = 2f32; - let _ = x.exp_m1(); - let _ = x.exp_m1() + 2.0; - // Cases where the lint shouldn't be applied - let _ = x.exp() - 2.0; - let _ = x.exp() - 1.0 * 2.0; - - let x = 2f64; - let _ = x.exp_m1(); - let _ = x.exp_m1() + 2.0; - // Cases where the lint shouldn't be applied - let _ = x.exp() - 2.0; - let _ = x.exp() - 1.0 * 2.0; -} diff --git a/tests/ui/floating_point_exp.rs b/tests/ui/floating_point_exp.rs deleted file mode 100644 index 27e0b9bcbc93..000000000000 --- a/tests/ui/floating_point_exp.rs +++ /dev/null @@ -1,18 +0,0 @@ -// run-rustfix -#![warn(clippy::imprecise_flops)] - -fn main() { - let x = 2f32; - let _ = x.exp() - 1.0; - let _ = x.exp() - 1.0 + 2.0; - // Cases where the lint shouldn't be applied - let _ = x.exp() - 2.0; - let _ = x.exp() - 1.0 * 2.0; - - let x = 2f64; - let _ = x.exp() - 1.0; - let _ = x.exp() - 1.0 + 2.0; - // Cases where the lint shouldn't be applied - let _ = x.exp() - 2.0; - let _ = x.exp() - 1.0 * 2.0; -} diff --git a/tests/ui/floating_point_exp.stderr b/tests/ui/floating_point_exp.stderr deleted file mode 100644 index 5cd999ad47cd..000000000000 --- a/tests/ui/floating_point_exp.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: (e.pow(x) - 1) can be computed more accurately - --> $DIR/floating_point_exp.rs:6:13 - | -LL | let _ = x.exp() - 1.0; - | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` - | - = note: `-D clippy::imprecise-flops` implied by `-D warnings` - -error: (e.pow(x) - 1) can be computed more accurately - --> $DIR/floating_point_exp.rs:7:13 - | -LL | let _ = x.exp() - 1.0 + 2.0; - | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` - -error: (e.pow(x) - 1) can be computed more accurately - --> $DIR/floating_point_exp.rs:13:13 - | -LL | let _ = x.exp() - 1.0; - | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` - -error: (e.pow(x) - 1) can be computed more accurately - --> $DIR/floating_point_exp.rs:14:13 - | -LL | let _ = x.exp() - 1.0 + 2.0; - | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/floating_point_hypot.fixed b/tests/ui/floating_point_hypot.fixed deleted file mode 100644 index bbe411b3f488..000000000000 --- a/tests/ui/floating_point_hypot.fixed +++ /dev/null @@ -1,14 +0,0 @@ -// run-rustfix -#![warn(clippy::imprecise_flops)] - -fn main() { - let x = 3f32; - let y = 4f32; - let _ = x.hypot(y); - let _ = (x + 1f32).hypot(y); - let _ = x.hypot(y); - // Cases where the lint shouldn't be applied - // TODO: linting this adds some complexity, but could be done - let _ = x.mul_add(x, y * y).sqrt(); - let _ = (x * 4f32 + y * y).sqrt(); -} diff --git a/tests/ui/floating_point_hypot.rs b/tests/ui/floating_point_hypot.rs deleted file mode 100644 index 586fd170ea14..000000000000 --- a/tests/ui/floating_point_hypot.rs +++ /dev/null @@ -1,14 +0,0 @@ -// run-rustfix -#![warn(clippy::imprecise_flops)] - -fn main() { - let x = 3f32; - let y = 4f32; - let _ = (x * x + y * y).sqrt(); - let _ = ((x + 1f32) * (x + 1f32) + y * y).sqrt(); - let _ = (x.powi(2) + y.powi(2)).sqrt(); - // Cases where the lint shouldn't be applied - // TODO: linting this adds some complexity, but could be done - let _ = x.mul_add(x, y * y).sqrt(); - let _ = (x * 4f32 + y * y).sqrt(); -} diff --git a/tests/ui/floating_point_hypot.stderr b/tests/ui/floating_point_hypot.stderr deleted file mode 100644 index 42069d9ee9ef..000000000000 --- a/tests/ui/floating_point_hypot.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: hypotenuse can be computed more accurately - --> $DIR/floating_point_hypot.rs:7:13 - | -LL | let _ = (x * x + y * y).sqrt(); - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.hypot(y)` - | - = note: `-D clippy::imprecise-flops` implied by `-D warnings` - -error: hypotenuse can be computed more accurately - --> $DIR/floating_point_hypot.rs:8:13 - | -LL | let _ = ((x + 1f32) * (x + 1f32) + y * y).sqrt(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 1f32).hypot(y)` - -error: hypotenuse can be computed more accurately - --> $DIR/floating_point_hypot.rs:9:13 - | -LL | let _ = (x.powi(2) + y.powi(2)).sqrt(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.hypot(y)` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/floating_point_log.fixed b/tests/ui/floating_point_log.fixed deleted file mode 100644 index 7dc7ee94affc..000000000000 --- a/tests/ui/floating_point_log.fixed +++ /dev/null @@ -1,58 +0,0 @@ -// run-rustfix -#![allow(dead_code, clippy::double_parens)] -#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] - -const TWO: f32 = 2.0; -const E: f32 = std::f32::consts::E; - -fn check_log_base() { - let x = 1f32; - let _ = x.log2(); - let _ = x.log10(); - let _ = x.ln(); - let _ = x.log2(); - let _ = x.ln(); - - let x = 1f64; - let _ = x.log2(); - let _ = x.log10(); - let _ = x.ln(); -} - -fn check_ln1p() { - let x = 1f32; - let _ = 2.0f32.ln_1p(); - let _ = 2.0f32.ln_1p(); - let _ = x.ln_1p(); - let _ = (x / 2.0).ln_1p(); - let _ = x.powi(3).ln_1p(); - let _ = (x.powi(3) / 2.0).ln_1p(); - let _ = ((std::f32::consts::E - 1.0)).ln_1p(); - let _ = x.ln_1p(); - let _ = x.powi(3).ln_1p(); - let _ = (x + 2.0).ln_1p(); - let _ = (x / 2.0).ln_1p(); - // Cases where the lint shouldn't be applied - let _ = (1.0 + x + 2.0).ln(); - let _ = (x + 1.0 + 2.0).ln(); - let _ = (x + 1.0 / 2.0).ln(); - let _ = (1.0 + x - 2.0).ln(); - - let x = 1f64; - let _ = 2.0f64.ln_1p(); - let _ = 2.0f64.ln_1p(); - let _ = x.ln_1p(); - let _ = (x / 2.0).ln_1p(); - let _ = x.powi(3).ln_1p(); - let _ = x.ln_1p(); - let _ = x.powi(3).ln_1p(); - let _ = (x + 2.0).ln_1p(); - let _ = (x / 2.0).ln_1p(); - // Cases where the lint shouldn't be applied - let _ = (1.0 + x + 2.0).ln(); - let _ = (x + 1.0 + 2.0).ln(); - let _ = (x + 1.0 / 2.0).ln(); - let _ = (1.0 + x - 2.0).ln(); -} - -fn main() {} diff --git a/tests/ui/floating_point_log.rs b/tests/ui/floating_point_log.rs deleted file mode 100644 index 01181484e7de..000000000000 --- a/tests/ui/floating_point_log.rs +++ /dev/null @@ -1,58 +0,0 @@ -// run-rustfix -#![allow(dead_code, clippy::double_parens)] -#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] - -const TWO: f32 = 2.0; -const E: f32 = std::f32::consts::E; - -fn check_log_base() { - let x = 1f32; - let _ = x.log(2f32); - let _ = x.log(10f32); - let _ = x.log(std::f32::consts::E); - let _ = x.log(TWO); - let _ = x.log(E); - - let x = 1f64; - let _ = x.log(2f64); - let _ = x.log(10f64); - let _ = x.log(std::f64::consts::E); -} - -fn check_ln1p() { - let x = 1f32; - let _ = (1f32 + 2.).ln(); - let _ = (1f32 + 2.0).ln(); - let _ = (1.0 + x).ln(); - let _ = (1.0 + x / 2.0).ln(); - let _ = (1.0 + x.powi(3)).ln(); - let _ = (1.0 + x.powi(3) / 2.0).ln(); - let _ = (1.0 + (std::f32::consts::E - 1.0)).ln(); - let _ = (x + 1.0).ln(); - let _ = (x.powi(3) + 1.0).ln(); - let _ = (x + 2.0 + 1.0).ln(); - let _ = (x / 2.0 + 1.0).ln(); - // Cases where the lint shouldn't be applied - let _ = (1.0 + x + 2.0).ln(); - let _ = (x + 1.0 + 2.0).ln(); - let _ = (x + 1.0 / 2.0).ln(); - let _ = (1.0 + x - 2.0).ln(); - - let x = 1f64; - let _ = (1f64 + 2.).ln(); - let _ = (1f64 + 2.0).ln(); - let _ = (1.0 + x).ln(); - let _ = (1.0 + x / 2.0).ln(); - let _ = (1.0 + x.powi(3)).ln(); - let _ = (x + 1.0).ln(); - let _ = (x.powi(3) + 1.0).ln(); - let _ = (x + 2.0 + 1.0).ln(); - let _ = (x / 2.0 + 1.0).ln(); - // Cases where the lint shouldn't be applied - let _ = (1.0 + x + 2.0).ln(); - let _ = (x + 1.0 + 2.0).ln(); - let _ = (x + 1.0 / 2.0).ln(); - let _ = (1.0 + x - 2.0).ln(); -} - -fn main() {} diff --git a/tests/ui/floating_point_log.stderr b/tests/ui/floating_point_log.stderr deleted file mode 100644 index 900dc2b79336..000000000000 --- a/tests/ui/floating_point_log.stderr +++ /dev/null @@ -1,174 +0,0 @@ -error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:10:13 - | -LL | let _ = x.log(2f32); - | ^^^^^^^^^^^ help: consider using: `x.log2()` - | - = note: `-D clippy::suboptimal-flops` implied by `-D warnings` - -error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:11:13 - | -LL | let _ = x.log(10f32); - | ^^^^^^^^^^^^ help: consider using: `x.log10()` - -error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:12:13 - | -LL | let _ = x.log(std::f32::consts::E); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()` - -error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:13:13 - | -LL | let _ = x.log(TWO); - | ^^^^^^^^^^ help: consider using: `x.log2()` - -error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:14:13 - | -LL | let _ = x.log(E); - | ^^^^^^^^ help: consider using: `x.ln()` - -error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:17:13 - | -LL | let _ = x.log(2f64); - | ^^^^^^^^^^^ help: consider using: `x.log2()` - -error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:18:13 - | -LL | let _ = x.log(10f64); - | ^^^^^^^^^^^^ help: consider using: `x.log10()` - -error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:19:13 - | -LL | let _ = x.log(std::f64::consts::E); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:24:13 - | -LL | let _ = (1f32 + 2.).ln(); - | ^^^^^^^^^^^^^^^^ help: consider using: `2.0f32.ln_1p()` - | - = note: `-D clippy::imprecise-flops` implied by `-D warnings` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:25:13 - | -LL | let _ = (1f32 + 2.0).ln(); - | ^^^^^^^^^^^^^^^^^ help: consider using: `2.0f32.ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:26:13 - | -LL | let _ = (1.0 + x).ln(); - | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:27:13 - | -LL | let _ = (1.0 + x / 2.0).ln(); - | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x / 2.0).ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:28:13 - | -LL | let _ = (1.0 + x.powi(3)).ln(); - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(3).ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:29:13 - | -LL | let _ = (1.0 + x.powi(3) / 2.0).ln(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x.powi(3) / 2.0).ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:30:13 - | -LL | let _ = (1.0 + (std::f32::consts::E - 1.0)).ln(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `((std::f32::consts::E - 1.0)).ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:31:13 - | -LL | let _ = (x + 1.0).ln(); - | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:32:13 - | -LL | let _ = (x.powi(3) + 1.0).ln(); - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(3).ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:33:13 - | -LL | let _ = (x + 2.0 + 1.0).ln(); - | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 2.0).ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:34:13 - | -LL | let _ = (x / 2.0 + 1.0).ln(); - | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x / 2.0).ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:42:13 - | -LL | let _ = (1f64 + 2.).ln(); - | ^^^^^^^^^^^^^^^^ help: consider using: `2.0f64.ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:43:13 - | -LL | let _ = (1f64 + 2.0).ln(); - | ^^^^^^^^^^^^^^^^^ help: consider using: `2.0f64.ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:44:13 - | -LL | let _ = (1.0 + x).ln(); - | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:45:13 - | -LL | let _ = (1.0 + x / 2.0).ln(); - | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x / 2.0).ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:46:13 - | -LL | let _ = (1.0 + x.powi(3)).ln(); - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(3).ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:47:13 - | -LL | let _ = (x + 1.0).ln(); - | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:48:13 - | -LL | let _ = (x.powi(3) + 1.0).ln(); - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(3).ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:49:13 - | -LL | let _ = (x + 2.0 + 1.0).ln(); - | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 2.0).ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:50:13 - | -LL | let _ = (x / 2.0 + 1.0).ln(); - | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x / 2.0).ln_1p()` - -error: aborting due to 28 previous errors - diff --git a/tests/ui/floating_point_logbase.fixed b/tests/ui/floating_point_logbase.fixed deleted file mode 100644 index 13962a272d45..000000000000 --- a/tests/ui/floating_point_logbase.fixed +++ /dev/null @@ -1,16 +0,0 @@ -// run-rustfix -#![warn(clippy::suboptimal_flops)] - -fn main() { - let x = 3f32; - let y = 5f32; - let _ = x.log(y); - let _ = x.log(y); - let _ = x.log(y); - let _ = x.log(y); - // Cases where the lint shouldn't be applied - let _ = x.ln() / y.powf(3.2); - let _ = x.powf(3.2) / y.powf(3.2); - let _ = x.powf(3.2) / y.ln(); - let _ = x.log(5f32) / y.log(7f32); -} diff --git a/tests/ui/floating_point_logbase.rs b/tests/ui/floating_point_logbase.rs deleted file mode 100644 index 26bc20d5370b..000000000000 --- a/tests/ui/floating_point_logbase.rs +++ /dev/null @@ -1,16 +0,0 @@ -// run-rustfix -#![warn(clippy::suboptimal_flops)] - -fn main() { - let x = 3f32; - let y = 5f32; - let _ = x.ln() / y.ln(); - let _ = x.log2() / y.log2(); - let _ = x.log10() / y.log10(); - let _ = x.log(5f32) / y.log(5f32); - // Cases where the lint shouldn't be applied - let _ = x.ln() / y.powf(3.2); - let _ = x.powf(3.2) / y.powf(3.2); - let _ = x.powf(3.2) / y.ln(); - let _ = x.log(5f32) / y.log(7f32); -} diff --git a/tests/ui/floating_point_logbase.stderr b/tests/ui/floating_point_logbase.stderr deleted file mode 100644 index 78354c2f62d4..000000000000 --- a/tests/ui/floating_point_logbase.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: log base can be expressed more clearly - --> $DIR/floating_point_logbase.rs:7:13 - | -LL | let _ = x.ln() / y.ln(); - | ^^^^^^^^^^^^^^^ help: consider using: `x.log(y)` - | - = note: `-D clippy::suboptimal-flops` implied by `-D warnings` - -error: log base can be expressed more clearly - --> $DIR/floating_point_logbase.rs:8:13 - | -LL | let _ = x.log2() / y.log2(); - | ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)` - -error: log base can be expressed more clearly - --> $DIR/floating_point_logbase.rs:9:13 - | -LL | let _ = x.log10() / y.log10(); - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)` - -error: log base can be expressed more clearly - --> $DIR/floating_point_logbase.rs:10:13 - | -LL | let _ = x.log(5f32) / y.log(5f32); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/floating_point_mul_add.fixed b/tests/ui/floating_point_mul_add.fixed deleted file mode 100644 index 911700bab004..000000000000 --- a/tests/ui/floating_point_mul_add.fixed +++ /dev/null @@ -1,26 +0,0 @@ -// run-rustfix -#![warn(clippy::suboptimal_flops)] - -fn main() { - let a: f64 = 1234.567; - let b: f64 = 45.67834; - let c: f64 = 0.0004; - let d: f64 = 0.0001; - - let _ = a.mul_add(b, c); - let _ = a.mul_add(b, c); - let _ = 2.0f64.mul_add(4.0, a); - let _ = 2.0f64.mul_add(4., a); - - let _ = a.mul_add(b, c); - let _ = a.mul_add(b, c); - let _ = (a * b).mul_add(c, d); - - let _ = a.mul_add(b, c).mul_add(a.mul_add(b, c), a.mul_add(b, c)) + c; - let _ = 1234.567_f64.mul_add(45.67834_f64, 0.0004_f64); - - let _ = a.mul_add(a, b).sqrt(); - - // Cases where the lint shouldn't be applied - let _ = (a * a + b * b).sqrt(); -} diff --git a/tests/ui/floating_point_mul_add.rs b/tests/ui/floating_point_mul_add.rs deleted file mode 100644 index d202385fc8ae..000000000000 --- a/tests/ui/floating_point_mul_add.rs +++ /dev/null @@ -1,26 +0,0 @@ -// run-rustfix -#![warn(clippy::suboptimal_flops)] - -fn main() { - let a: f64 = 1234.567; - let b: f64 = 45.67834; - let c: f64 = 0.0004; - let d: f64 = 0.0001; - - let _ = a * b + c; - let _ = c + a * b; - let _ = a + 2.0 * 4.0; - let _ = a + 2. * 4.; - - let _ = (a * b) + c; - let _ = c + (a * b); - let _ = a * b * c + d; - - let _ = a.mul_add(b, c) * a.mul_add(b, c) + a.mul_add(b, c) + c; - let _ = 1234.567_f64 * 45.67834_f64 + 0.0004_f64; - - let _ = (a * a + b).sqrt(); - - // Cases where the lint shouldn't be applied - let _ = (a * a + b * b).sqrt(); -} diff --git a/tests/ui/floating_point_mul_add.stderr b/tests/ui/floating_point_mul_add.stderr deleted file mode 100644 index ac8d0c0cae06..000000000000 --- a/tests/ui/floating_point_mul_add.stderr +++ /dev/null @@ -1,64 +0,0 @@ -error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:10:13 - | -LL | let _ = a * b + c; - | ^^^^^^^^^ help: consider using: `a.mul_add(b, c)` - | - = note: `-D clippy::suboptimal-flops` implied by `-D warnings` - -error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:11:13 - | -LL | let _ = c + a * b; - | ^^^^^^^^^ help: consider using: `a.mul_add(b, c)` - -error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:12:13 - | -LL | let _ = a + 2.0 * 4.0; - | ^^^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4.0, a)` - -error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:13:13 - | -LL | let _ = a + 2. * 4.; - | ^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4., a)` - -error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:15:13 - | -LL | let _ = (a * b) + c; - | ^^^^^^^^^^^ help: consider using: `a.mul_add(b, c)` - -error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:16:13 - | -LL | let _ = c + (a * b); - | ^^^^^^^^^^^ help: consider using: `a.mul_add(b, c)` - -error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:17:13 - | -LL | let _ = a * b * c + d; - | ^^^^^^^^^^^^^ help: consider using: `(a * b).mul_add(c, d)` - -error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:19:13 - | -LL | let _ = a.mul_add(b, c) * a.mul_add(b, c) + a.mul_add(b, c) + c; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `a.mul_add(b, c).mul_add(a.mul_add(b, c), a.mul_add(b, c))` - -error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:20:13 - | -LL | let _ = 1234.567_f64 * 45.67834_f64 + 0.0004_f64; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1234.567_f64.mul_add(45.67834_f64, 0.0004_f64)` - -error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:22:13 - | -LL | let _ = (a * a + b).sqrt(); - | ^^^^^^^^^^^ help: consider using: `a.mul_add(a, b)` - -error: aborting due to 10 previous errors - diff --git a/tests/ui/floating_point_powf.fixed b/tests/ui/floating_point_powf.fixed deleted file mode 100644 index b0641a100cdc..000000000000 --- a/tests/ui/floating_point_powf.fixed +++ /dev/null @@ -1,42 +0,0 @@ -// run-rustfix -#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] - -fn main() { - let x = 3f32; - let _ = x.exp2(); - let _ = 3.1f32.exp2(); - let _ = (-3.1f32).exp2(); - let _ = x.exp(); - let _ = 3.1f32.exp(); - let _ = (-3.1f32).exp(); - let _ = x.sqrt(); - let _ = x.cbrt(); - let _ = x.powi(3); - let _ = x.powi(-2); - let _ = x.powi(16_777_215); - let _ = x.powi(-16_777_215); - // Cases where the lint shouldn't be applied - let _ = x.powf(2.1); - let _ = x.powf(-2.1); - let _ = x.powf(16_777_216.0); - let _ = x.powf(-16_777_216.0); - - let x = 3f64; - let _ = x.exp2(); - let _ = 3.1f64.exp2(); - let _ = (-3.1f64).exp2(); - let _ = x.exp(); - let _ = 3.1f64.exp(); - let _ = (-3.1f64).exp(); - let _ = x.sqrt(); - let _ = x.cbrt(); - let _ = x.powi(3); - let _ = x.powi(-2); - let _ = x.powi(-2_147_483_648); - let _ = x.powi(2_147_483_647); - // Cases where the lint shouldn't be applied - let _ = x.powf(2.1); - let _ = x.powf(-2.1); - let _ = x.powf(-2_147_483_649.0); - let _ = x.powf(2_147_483_648.0); -} diff --git a/tests/ui/floating_point_powf.rs b/tests/ui/floating_point_powf.rs deleted file mode 100644 index a0a2c973900f..000000000000 --- a/tests/ui/floating_point_powf.rs +++ /dev/null @@ -1,42 +0,0 @@ -// run-rustfix -#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] - -fn main() { - let x = 3f32; - let _ = 2f32.powf(x); - let _ = 2f32.powf(3.1); - let _ = 2f32.powf(-3.1); - let _ = std::f32::consts::E.powf(x); - let _ = std::f32::consts::E.powf(3.1); - let _ = std::f32::consts::E.powf(-3.1); - let _ = x.powf(1.0 / 2.0); - let _ = x.powf(1.0 / 3.0); - let _ = x.powf(3.0); - let _ = x.powf(-2.0); - let _ = x.powf(16_777_215.0); - let _ = x.powf(-16_777_215.0); - // Cases where the lint shouldn't be applied - let _ = x.powf(2.1); - let _ = x.powf(-2.1); - let _ = x.powf(16_777_216.0); - let _ = x.powf(-16_777_216.0); - - let x = 3f64; - let _ = 2f64.powf(x); - let _ = 2f64.powf(3.1); - let _ = 2f64.powf(-3.1); - let _ = std::f64::consts::E.powf(x); - let _ = std::f64::consts::E.powf(3.1); - let _ = std::f64::consts::E.powf(-3.1); - let _ = x.powf(1.0 / 2.0); - let _ = x.powf(1.0 / 3.0); - let _ = x.powf(3.0); - let _ = x.powf(-2.0); - let _ = x.powf(-2_147_483_648.0); - let _ = x.powf(2_147_483_647.0); - // Cases where the lint shouldn't be applied - let _ = x.powf(2.1); - let _ = x.powf(-2.1); - let _ = x.powf(-2_147_483_649.0); - let _ = x.powf(2_147_483_648.0); -} diff --git a/tests/ui/floating_point_powf.stderr b/tests/ui/floating_point_powf.stderr deleted file mode 100644 index 2422eb911e90..000000000000 --- a/tests/ui/floating_point_powf.stderr +++ /dev/null @@ -1,150 +0,0 @@ -error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:6:13 - | -LL | let _ = 2f32.powf(x); - | ^^^^^^^^^^^^ help: consider using: `x.exp2()` - | - = note: `-D clippy::suboptimal-flops` implied by `-D warnings` - -error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:7:13 - | -LL | let _ = 2f32.powf(3.1); - | ^^^^^^^^^^^^^^ help: consider using: `3.1f32.exp2()` - -error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:8:13 - | -LL | let _ = 2f32.powf(-3.1); - | ^^^^^^^^^^^^^^^ help: consider using: `(-3.1f32).exp2()` - -error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:9:13 - | -LL | let _ = std::f32::consts::E.powf(x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()` - -error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:10:13 - | -LL | let _ = std::f32::consts::E.powf(3.1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `3.1f32.exp()` - -error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:11:13 - | -LL | let _ = std::f32::consts::E.powf(-3.1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-3.1f32).exp()` - -error: square-root of a number can be computed more efficiently and accurately - --> $DIR/floating_point_powf.rs:12:13 - | -LL | let _ = x.powf(1.0 / 2.0); - | ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()` - -error: cube-root of a number can be computed more accurately - --> $DIR/floating_point_powf.rs:13:13 - | -LL | let _ = x.powf(1.0 / 3.0); - | ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()` - | - = note: `-D clippy::imprecise-flops` implied by `-D warnings` - -error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:14:13 - | -LL | let _ = x.powf(3.0); - | ^^^^^^^^^^^ help: consider using: `x.powi(3)` - -error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:15:13 - | -LL | let _ = x.powf(-2.0); - | ^^^^^^^^^^^^ help: consider using: `x.powi(-2)` - -error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:16:13 - | -LL | let _ = x.powf(16_777_215.0); - | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(16_777_215)` - -error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:17:13 - | -LL | let _ = x.powf(-16_777_215.0); - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(-16_777_215)` - -error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:25:13 - | -LL | let _ = 2f64.powf(x); - | ^^^^^^^^^^^^ help: consider using: `x.exp2()` - -error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:26:13 - | -LL | let _ = 2f64.powf(3.1); - | ^^^^^^^^^^^^^^ help: consider using: `3.1f64.exp2()` - -error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:27:13 - | -LL | let _ = 2f64.powf(-3.1); - | ^^^^^^^^^^^^^^^ help: consider using: `(-3.1f64).exp2()` - -error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:28:13 - | -LL | let _ = std::f64::consts::E.powf(x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()` - -error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:29:13 - | -LL | let _ = std::f64::consts::E.powf(3.1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `3.1f64.exp()` - -error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:30:13 - | -LL | let _ = std::f64::consts::E.powf(-3.1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-3.1f64).exp()` - -error: square-root of a number can be computed more efficiently and accurately - --> $DIR/floating_point_powf.rs:31:13 - | -LL | let _ = x.powf(1.0 / 2.0); - | ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()` - -error: cube-root of a number can be computed more accurately - --> $DIR/floating_point_powf.rs:32:13 - | -LL | let _ = x.powf(1.0 / 3.0); - | ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()` - -error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:33:13 - | -LL | let _ = x.powf(3.0); - | ^^^^^^^^^^^ help: consider using: `x.powi(3)` - -error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:34:13 - | -LL | let _ = x.powf(-2.0); - | ^^^^^^^^^^^^ help: consider using: `x.powi(-2)` - -error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:35:13 - | -LL | let _ = x.powf(-2_147_483_648.0); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(-2_147_483_648)` - -error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:36:13 - | -LL | let _ = x.powf(2_147_483_647.0); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2_147_483_647)` - -error: aborting due to 24 previous errors - diff --git a/tests/ui/floating_point_powi.fixed b/tests/ui/floating_point_powi.fixed deleted file mode 100644 index 56762400593b..000000000000 --- a/tests/ui/floating_point_powi.fixed +++ /dev/null @@ -1,19 +0,0 @@ -// run-rustfix -#![warn(clippy::suboptimal_flops)] - -fn main() { - let one = 1; - let x = 3f32; - let _ = x * x; - let _ = x * x; - - let y = 4f32; - let _ = x.mul_add(x, y); - let _ = y.mul_add(y, x); - let _ = x.mul_add(x, y).sqrt(); - let _ = y.mul_add(y, x).sqrt(); - // Cases where the lint shouldn't be applied - let _ = x.powi(3); - let _ = x.powi(one + 1); - let _ = (x.powi(2) + y.powi(2)).sqrt(); -} diff --git a/tests/ui/floating_point_powi.rs b/tests/ui/floating_point_powi.rs deleted file mode 100644 index 1f800e4628dc..000000000000 --- a/tests/ui/floating_point_powi.rs +++ /dev/null @@ -1,19 +0,0 @@ -// run-rustfix -#![warn(clippy::suboptimal_flops)] - -fn main() { - let one = 1; - let x = 3f32; - let _ = x.powi(2); - let _ = x.powi(1 + 1); - - let y = 4f32; - let _ = x.powi(2) + y; - let _ = x + y.powi(2); - let _ = (x.powi(2) + y).sqrt(); - let _ = (x + y.powi(2)).sqrt(); - // Cases where the lint shouldn't be applied - let _ = x.powi(3); - let _ = x.powi(one + 1); - let _ = (x.powi(2) + y.powi(2)).sqrt(); -} diff --git a/tests/ui/floating_point_powi.stderr b/tests/ui/floating_point_powi.stderr deleted file mode 100644 index d5a5f1bcca10..000000000000 --- a/tests/ui/floating_point_powi.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: square can be computed more efficiently - --> $DIR/floating_point_powi.rs:7:13 - | -LL | let _ = x.powi(2); - | ^^^^^^^^^ help: consider using: `x * x` - | - = note: `-D clippy::suboptimal-flops` implied by `-D warnings` - -error: square can be computed more efficiently - --> $DIR/floating_point_powi.rs:8:13 - | -LL | let _ = x.powi(1 + 1); - | ^^^^^^^^^^^^^ help: consider using: `x * x` - -error: square can be computed more efficiently - --> $DIR/floating_point_powi.rs:11:13 - | -LL | let _ = x.powi(2) + y; - | ^^^^^^^^^^^^^ help: consider using: `x.mul_add(x, y)` - -error: square can be computed more efficiently - --> $DIR/floating_point_powi.rs:12:13 - | -LL | let _ = x + y.powi(2); - | ^^^^^^^^^^^^^ help: consider using: `y.mul_add(y, x)` - -error: square can be computed more efficiently - --> $DIR/floating_point_powi.rs:13:13 - | -LL | let _ = (x.powi(2) + y).sqrt(); - | ^^^^^^^^^^^^^^^ help: consider using: `x.mul_add(x, y)` - -error: square can be computed more efficiently - --> $DIR/floating_point_powi.rs:14:13 - | -LL | let _ = (x + y.powi(2)).sqrt(); - | ^^^^^^^^^^^^^^^ help: consider using: `y.mul_add(y, x)` - -error: aborting due to 6 previous errors - diff --git a/tests/ui/floating_point_rad.fixed b/tests/ui/floating_point_rad.fixed deleted file mode 100644 index 92480c5db8be..000000000000 --- a/tests/ui/floating_point_rad.fixed +++ /dev/null @@ -1,13 +0,0 @@ -// run-rustfix -#![warn(clippy::suboptimal_flops)] - -fn main() { - let x = 3f32; - let _ = x.to_degrees(); - let _ = x.to_radians(); - // Cases where the lint shouldn't be applied - let _ = x * 90f32 / std::f32::consts::PI; - let _ = x * std::f32::consts::PI / 90f32; - let _ = x * 180f32 / std::f32::consts::E; - let _ = x * std::f32::consts::E / 180f32; -} diff --git a/tests/ui/floating_point_rad.rs b/tests/ui/floating_point_rad.rs deleted file mode 100644 index 062e7c3fdc17..000000000000 --- a/tests/ui/floating_point_rad.rs +++ /dev/null @@ -1,13 +0,0 @@ -// run-rustfix -#![warn(clippy::suboptimal_flops)] - -fn main() { - let x = 3f32; - let _ = x * 180f32 / std::f32::consts::PI; - let _ = x * std::f32::consts::PI / 180f32; - // Cases where the lint shouldn't be applied - let _ = x * 90f32 / std::f32::consts::PI; - let _ = x * std::f32::consts::PI / 90f32; - let _ = x * 180f32 / std::f32::consts::E; - let _ = x * std::f32::consts::E / 180f32; -} diff --git a/tests/ui/floating_point_rad.stderr b/tests/ui/floating_point_rad.stderr deleted file mode 100644 index a6ffdca64eef..000000000000 --- a/tests/ui/floating_point_rad.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: conversion to degrees can be done more accurately - --> $DIR/floating_point_rad.rs:6:13 - | -LL | let _ = x * 180f32 / std::f32::consts::PI; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_degrees()` - | - = note: `-D clippy::suboptimal-flops` implied by `-D warnings` - -error: conversion to radians can be done more accurately - --> $DIR/floating_point_rad.rs:7:13 - | -LL | let _ = x * std::f32::consts::PI / 180f32; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_radians()` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/fn_address_comparisons.rs b/tests/ui/fn_address_comparisons.rs deleted file mode 100644 index 362dcb4fd80c..000000000000 --- a/tests/ui/fn_address_comparisons.rs +++ /dev/null @@ -1,20 +0,0 @@ -use std::fmt::Debug; -use std::ptr; -use std::rc::Rc; -use std::sync::Arc; - -fn a() {} - -#[warn(clippy::fn_address_comparisons)] -fn main() { - type F = fn(); - let f: F = a; - let g: F = f; - - // These should fail: - let _ = f == a; - let _ = f != a; - - // These should be fine: - let _ = f == g; -} diff --git a/tests/ui/fn_address_comparisons.stderr b/tests/ui/fn_address_comparisons.stderr deleted file mode 100644 index 9c1b5419a431..000000000000 --- a/tests/ui/fn_address_comparisons.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: comparing with a non-unique address of a function item - --> $DIR/fn_address_comparisons.rs:15:13 - | -LL | let _ = f == a; - | ^^^^^^ - | - = note: `-D clippy::fn-address-comparisons` implied by `-D warnings` - -error: comparing with a non-unique address of a function item - --> $DIR/fn_address_comparisons.rs:16:13 - | -LL | let _ = f != a; - | ^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/fn_params_excessive_bools.rs b/tests/ui/fn_params_excessive_bools.rs deleted file mode 100644 index 7d6fd607e654..000000000000 --- a/tests/ui/fn_params_excessive_bools.rs +++ /dev/null @@ -1,44 +0,0 @@ -#![warn(clippy::fn_params_excessive_bools)] - -extern "C" { - fn f(_: bool, _: bool, _: bool, _: bool); -} - -macro_rules! foo { - () => { - fn fff(_: bool, _: bool, _: bool, _: bool) {} - }; -} - -foo!(); - -#[no_mangle] -extern "C" fn k(_: bool, _: bool, _: bool, _: bool) {} -fn g(_: bool, _: bool, _: bool, _: bool) {} -fn h(_: bool, _: bool, _: bool) {} -fn e(_: S, _: S, _: Box, _: Vec) {} -fn t(_: S, _: S, _: Box, _: Vec, _: bool, _: bool, _: bool, _: bool) {} - -struct S {} -trait Trait { - fn f(_: bool, _: bool, _: bool, _: bool); - fn g(_: bool, _: bool, _: bool, _: Vec); -} - -impl S { - fn f(&self, _: bool, _: bool, _: bool, _: bool) {} - fn g(&self, _: bool, _: bool, _: bool) {} - #[no_mangle] - extern "C" fn h(_: bool, _: bool, _: bool, _: bool) {} -} - -impl Trait for S { - fn f(_: bool, _: bool, _: bool, _: bool) {} - fn g(_: bool, _: bool, _: bool, _: Vec) {} -} - -fn main() { - fn n(_: bool, _: u32, _: bool, _: Box, _: bool, _: bool) { - fn nn(_: bool, _: bool, _: bool, _: bool) {} - } -} diff --git a/tests/ui/fn_params_excessive_bools.stderr b/tests/ui/fn_params_excessive_bools.stderr deleted file mode 100644 index 4e5dbc261d66..000000000000 --- a/tests/ui/fn_params_excessive_bools.stderr +++ /dev/null @@ -1,53 +0,0 @@ -error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:17:1 - | -LL | fn g(_: bool, _: bool, _: bool, _: bool) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings` - = help: consider refactoring bools into two-variant enums - -error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:20:1 - | -LL | fn t(_: S, _: S, _: Box, _: Vec, _: bool, _: bool, _: bool, _: bool) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider refactoring bools into two-variant enums - -error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:24:5 - | -LL | fn f(_: bool, _: bool, _: bool, _: bool); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider refactoring bools into two-variant enums - -error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:29:5 - | -LL | fn f(&self, _: bool, _: bool, _: bool, _: bool) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider refactoring bools into two-variant enums - -error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:41:5 - | -LL | / fn n(_: bool, _: u32, _: bool, _: Box, _: bool, _: bool) { -LL | | fn nn(_: bool, _: bool, _: bool, _: bool) {} -LL | | } - | |_____^ - | - = help: consider refactoring bools into two-variant enums - -error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:42:9 - | -LL | fn nn(_: bool, _: bool, _: bool, _: bool) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider refactoring bools into two-variant enums - -error: aborting due to 6 previous errors - diff --git a/tests/ui/fn_to_numeric_cast.rs b/tests/ui/fn_to_numeric_cast.rs deleted file mode 100644 index a456c085c876..000000000000 --- a/tests/ui/fn_to_numeric_cast.rs +++ /dev/null @@ -1,55 +0,0 @@ -// ignore-32bit - -#![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)] - -fn foo() -> String { - String::new() -} - -fn test_function_to_numeric_cast() { - let _ = foo as i8; - let _ = foo as i16; - let _ = foo as i32; - let _ = foo as i64; - let _ = foo as i128; - let _ = foo as isize; - - let _ = foo as u8; - let _ = foo as u16; - let _ = foo as u32; - let _ = foo as u64; - let _ = foo as u128; - - // Casting to usize is OK and should not warn - let _ = foo as usize; - - // Cast `f` (a `FnDef`) to `fn()` should not warn - fn f() {} - let _ = f as fn(); -} - -fn test_function_var_to_numeric_cast() { - let abc: fn() -> String = foo; - - let _ = abc as i8; - let _ = abc as i16; - let _ = abc as i32; - let _ = abc as i64; - let _ = abc as i128; - let _ = abc as isize; - - let _ = abc as u8; - let _ = abc as u16; - let _ = abc as u32; - let _ = abc as u64; - let _ = abc as u128; - - // Casting to usize is OK and should not warn - let _ = abc as usize; -} - -fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 { - f as i32 -} - -fn main() {} diff --git a/tests/ui/fn_to_numeric_cast.stderr b/tests/ui/fn_to_numeric_cast.stderr deleted file mode 100644 index e9549e157cd9..000000000000 --- a/tests/ui/fn_to_numeric_cast.stderr +++ /dev/null @@ -1,144 +0,0 @@ -error: casting function pointer `foo` to `i8`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:10:13 - | -LL | let _ = foo as i8; - | ^^^^^^^^^ help: try: `foo as usize` - | - = note: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings` - -error: casting function pointer `foo` to `i16`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:11:13 - | -LL | let _ = foo as i16; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `i32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:12:13 - | -LL | let _ = foo as i32; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `i64` - --> $DIR/fn_to_numeric_cast.rs:13:13 - | -LL | let _ = foo as i64; - | ^^^^^^^^^^ help: try: `foo as usize` - | - = note: `-D clippy::fn-to-numeric-cast` implied by `-D warnings` - -error: casting function pointer `foo` to `i128` - --> $DIR/fn_to_numeric_cast.rs:14:13 - | -LL | let _ = foo as i128; - | ^^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `isize` - --> $DIR/fn_to_numeric_cast.rs:15:13 - | -LL | let _ = foo as isize; - | ^^^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u8`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:17:13 - | -LL | let _ = foo as u8; - | ^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u16`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:18:13 - | -LL | let _ = foo as u16; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:19:13 - | -LL | let _ = foo as u32; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u64` - --> $DIR/fn_to_numeric_cast.rs:20:13 - | -LL | let _ = foo as u64; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u128` - --> $DIR/fn_to_numeric_cast.rs:21:13 - | -LL | let _ = foo as u128; - | ^^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `abc` to `i8`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:34:13 - | -LL | let _ = abc as i8; - | ^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `i16`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:35:13 - | -LL | let _ = abc as i16; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `i32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:36:13 - | -LL | let _ = abc as i32; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `i64` - --> $DIR/fn_to_numeric_cast.rs:37:13 - | -LL | let _ = abc as i64; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `i128` - --> $DIR/fn_to_numeric_cast.rs:38:13 - | -LL | let _ = abc as i128; - | ^^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `isize` - --> $DIR/fn_to_numeric_cast.rs:39:13 - | -LL | let _ = abc as isize; - | ^^^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u8`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:41:13 - | -LL | let _ = abc as u8; - | ^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u16`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:42:13 - | -LL | let _ = abc as u16; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:43:13 - | -LL | let _ = abc as u32; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u64` - --> $DIR/fn_to_numeric_cast.rs:44:13 - | -LL | let _ = abc as u64; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u128` - --> $DIR/fn_to_numeric_cast.rs:45:13 - | -LL | let _ = abc as u128; - | ^^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `f` to `i32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:52:5 - | -LL | f as i32 - | ^^^^^^^^ help: try: `f as usize` - -error: aborting due to 23 previous errors - diff --git a/tests/ui/fn_to_numeric_cast_32bit.rs b/tests/ui/fn_to_numeric_cast_32bit.rs deleted file mode 100644 index 04ee985c0863..000000000000 --- a/tests/ui/fn_to_numeric_cast_32bit.rs +++ /dev/null @@ -1,55 +0,0 @@ -// ignore-64bit - -#![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)] - -fn foo() -> String { - String::new() -} - -fn test_function_to_numeric_cast() { - let _ = foo as i8; - let _ = foo as i16; - let _ = foo as i32; - let _ = foo as i64; - let _ = foo as i128; - let _ = foo as isize; - - let _ = foo as u8; - let _ = foo as u16; - let _ = foo as u32; - let _ = foo as u64; - let _ = foo as u128; - - // Casting to usize is OK and should not warn - let _ = foo as usize; - - // Cast `f` (a `FnDef`) to `fn()` should not warn - fn f() {} - let _ = f as fn(); -} - -fn test_function_var_to_numeric_cast() { - let abc: fn() -> String = foo; - - let _ = abc as i8; - let _ = abc as i16; - let _ = abc as i32; - let _ = abc as i64; - let _ = abc as i128; - let _ = abc as isize; - - let _ = abc as u8; - let _ = abc as u16; - let _ = abc as u32; - let _ = abc as u64; - let _ = abc as u128; - - // Casting to usize is OK and should not warn - let _ = abc as usize; -} - -fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 { - f as i32 -} - -fn main() {} diff --git a/tests/ui/fn_to_numeric_cast_32bit.stderr b/tests/ui/fn_to_numeric_cast_32bit.stderr deleted file mode 100644 index 08dd611d6752..000000000000 --- a/tests/ui/fn_to_numeric_cast_32bit.stderr +++ /dev/null @@ -1,144 +0,0 @@ -error: casting function pointer `foo` to `i8`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:10:13 - | -LL | let _ = foo as i8; - | ^^^^^^^^^ help: try: `foo as usize` - | - = note: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings` - -error: casting function pointer `foo` to `i16`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:11:13 - | -LL | let _ = foo as i16; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `i32` - --> $DIR/fn_to_numeric_cast_32bit.rs:12:13 - | -LL | let _ = foo as i32; - | ^^^^^^^^^^ help: try: `foo as usize` - | - = note: `-D clippy::fn-to-numeric-cast` implied by `-D warnings` - -error: casting function pointer `foo` to `i64` - --> $DIR/fn_to_numeric_cast_32bit.rs:13:13 - | -LL | let _ = foo as i64; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `i128` - --> $DIR/fn_to_numeric_cast_32bit.rs:14:13 - | -LL | let _ = foo as i128; - | ^^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `isize` - --> $DIR/fn_to_numeric_cast_32bit.rs:15:13 - | -LL | let _ = foo as isize; - | ^^^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u8`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:17:13 - | -LL | let _ = foo as u8; - | ^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u16`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:18:13 - | -LL | let _ = foo as u16; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u32` - --> $DIR/fn_to_numeric_cast_32bit.rs:19:13 - | -LL | let _ = foo as u32; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u64` - --> $DIR/fn_to_numeric_cast_32bit.rs:20:13 - | -LL | let _ = foo as u64; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u128` - --> $DIR/fn_to_numeric_cast_32bit.rs:21:13 - | -LL | let _ = foo as u128; - | ^^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `abc` to `i8`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:34:13 - | -LL | let _ = abc as i8; - | ^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `i16`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:35:13 - | -LL | let _ = abc as i16; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `i32` - --> $DIR/fn_to_numeric_cast_32bit.rs:36:13 - | -LL | let _ = abc as i32; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `i64` - --> $DIR/fn_to_numeric_cast_32bit.rs:37:13 - | -LL | let _ = abc as i64; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `i128` - --> $DIR/fn_to_numeric_cast_32bit.rs:38:13 - | -LL | let _ = abc as i128; - | ^^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `isize` - --> $DIR/fn_to_numeric_cast_32bit.rs:39:13 - | -LL | let _ = abc as isize; - | ^^^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u8`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:41:13 - | -LL | let _ = abc as u8; - | ^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u16`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:42:13 - | -LL | let _ = abc as u16; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u32` - --> $DIR/fn_to_numeric_cast_32bit.rs:43:13 - | -LL | let _ = abc as u32; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u64` - --> $DIR/fn_to_numeric_cast_32bit.rs:44:13 - | -LL | let _ = abc as u64; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u128` - --> $DIR/fn_to_numeric_cast_32bit.rs:45:13 - | -LL | let _ = abc as u128; - | ^^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `f` to `i32` - --> $DIR/fn_to_numeric_cast_32bit.rs:52:5 - | -LL | f as i32 - | ^^^^^^^^ help: try: `f as usize` - -error: aborting due to 23 previous errors - diff --git a/tests/ui/for_kv_map.rs b/tests/ui/for_kv_map.rs deleted file mode 100644 index 39a8d960a7e9..000000000000 --- a/tests/ui/for_kv_map.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![warn(clippy::for_kv_map)] -#![allow(clippy::used_underscore_binding)] - -use std::collections::*; -use std::rc::Rc; - -fn main() { - let m: HashMap = HashMap::new(); - for (_, v) in &m { - let _v = v; - } - - let m: Rc> = Rc::new(HashMap::new()); - for (_, v) in &*m { - let _v = v; - // Here the `*` is not actually necessary, but the test tests that we don't - // suggest - // `in *m.values()` as we used to - } - - let mut m: HashMap = HashMap::new(); - for (_, v) in &mut m { - let _v = v; - } - - let m: &mut HashMap = &mut HashMap::new(); - for (_, v) in &mut *m { - let _v = v; - } - - let m: HashMap = HashMap::new(); - let rm = &m; - for (k, _value) in rm { - let _k = k; - } - - // The following should not produce warnings. - - let m: HashMap = HashMap::new(); - // No error, _value is actually used - for (k, _value) in &m { - let _ = _value; - let _k = k; - } - - let m: HashMap = Default::default(); - for (_, v) in m { - let _v = v; - } -} diff --git a/tests/ui/for_kv_map.stderr b/tests/ui/for_kv_map.stderr deleted file mode 100644 index 241758c542cf..000000000000 --- a/tests/ui/for_kv_map.stderr +++ /dev/null @@ -1,58 +0,0 @@ -error: you seem to want to iterate on a map's values - --> $DIR/for_kv_map.rs:9:19 - | -LL | for (_, v) in &m { - | ^^ - | - = note: `-D clippy::for-kv-map` implied by `-D warnings` -help: use the corresponding method - | -LL | for v in m.values() { - | ^ ^^^^^^^^^^ - -error: you seem to want to iterate on a map's values - --> $DIR/for_kv_map.rs:14:19 - | -LL | for (_, v) in &*m { - | ^^^ - | -help: use the corresponding method - | -LL | for v in (*m).values() { - | ^ ^^^^^^^^^^^^^ - -error: you seem to want to iterate on a map's values - --> $DIR/for_kv_map.rs:22:19 - | -LL | for (_, v) in &mut m { - | ^^^^^^ - | -help: use the corresponding method - | -LL | for v in m.values_mut() { - | ^ ^^^^^^^^^^^^^^ - -error: you seem to want to iterate on a map's values - --> $DIR/for_kv_map.rs:27:19 - | -LL | for (_, v) in &mut *m { - | ^^^^^^^ - | -help: use the corresponding method - | -LL | for v in (*m).values_mut() { - | ^ ^^^^^^^^^^^^^^^^^ - -error: you seem to want to iterate on a map's keys - --> $DIR/for_kv_map.rs:33:24 - | -LL | for (k, _value) in rm { - | ^^ - | -help: use the corresponding method - | -LL | for k in rm.keys() { - | ^ ^^^^^^^^^ - -error: aborting due to 5 previous errors - diff --git a/tests/ui/for_loop_fixable.fixed b/tests/ui/for_loop_fixable.fixed deleted file mode 100644 index 249a88a0b398..000000000000 --- a/tests/ui/for_loop_fixable.fixed +++ /dev/null @@ -1,283 +0,0 @@ -// run-rustfix - -#![allow(dead_code, unused)] - -use std::collections::*; - -#[warn(clippy::all)] -struct Unrelated(Vec); -impl Unrelated { - fn next(&self) -> std::slice::Iter { - self.0.iter() - } - - fn iter(&self) -> std::slice::Iter { - self.0.iter() - } -} - -#[warn( - clippy::needless_range_loop, - clippy::explicit_iter_loop, - clippy::explicit_into_iter_loop, - clippy::iter_next_loop, - clippy::for_kv_map -)] -#[allow( - clippy::linkedlist, - clippy::shadow_unrelated, - clippy::unnecessary_mut_passed, - clippy::similar_names -)] -#[allow(clippy::many_single_char_names, unused_variables)] -fn main() { - let mut vec = vec![1, 2, 3, 4]; - - // See #601 - for i in 0..10 { - // no error, id_col does not exist outside the loop - let mut id_col = vec![0f64; 10]; - id_col[i] = 1f64; - } - - for _v in &vec {} - - for _v in &mut vec {} - - let out_vec = vec![1, 2, 3]; - for _v in out_vec {} - - for _v in &vec {} // these are fine - for _v in &mut vec {} // these are fine - - for _v in &[1, 2, 3] {} - - for _v in (&mut [1, 2, 3]).iter() {} // no error - - for _v in &[0; 32] {} - - for _v in [0; 33].iter() {} // no error - - let ll: LinkedList<()> = LinkedList::new(); - for _v in &ll {} - - let vd: VecDeque<()> = VecDeque::new(); - for _v in &vd {} - - let bh: BinaryHeap<()> = BinaryHeap::new(); - for _v in &bh {} - - let hm: HashMap<(), ()> = HashMap::new(); - for _v in &hm {} - - let bt: BTreeMap<(), ()> = BTreeMap::new(); - for _v in &bt {} - - let hs: HashSet<()> = HashSet::new(); - for _v in &hs {} - - let bs: BTreeSet<()> = BTreeSet::new(); - for _v in &bs {} - - let u = Unrelated(vec![]); - for _v in u.next() {} // no error - for _v in u.iter() {} // no error - - let mut out = vec![]; - vec.iter().cloned().map(|x| out.push(x)).collect::>(); - let _y = vec.iter().cloned().map(|x| out.push(x)).collect::>(); // this is fine - - // Loop with explicit counter variable - - // Potential false positives - let mut _index = 0; - _index = 1; - for _v in &vec { - _index += 1 - } - - let mut _index = 0; - _index += 1; - for _v in &vec { - _index += 1 - } - - let mut _index = 0; - if true { - _index = 1 - } - for _v in &vec { - _index += 1 - } - - let mut _index = 0; - let mut _index = 1; - for _v in &vec { - _index += 1 - } - - let mut _index = 0; - for _v in &vec { - _index += 1; - _index += 1 - } - - let mut _index = 0; - for _v in &vec { - _index *= 2; - _index += 1 - } - - let mut _index = 0; - for _v in &vec { - _index = 1; - _index += 1 - } - - let mut _index = 0; - - for _v in &vec { - let mut _index = 0; - _index += 1 - } - - let mut _index = 0; - for _v in &vec { - _index += 1; - _index = 0; - } - - let mut _index = 0; - for _v in &vec { - for _x in 0..1 { - _index += 1; - } - _index += 1 - } - - let mut _index = 0; - for x in &vec { - if *x == 1 { - _index += 1 - } - } - - let mut _index = 0; - if true { - _index = 1 - }; - for _v in &vec { - _index += 1 - } - - let mut _index = 1; - if false { - _index = 0 - }; - for _v in &vec { - _index += 1 - } - - let mut index = 0; - { - let mut _x = &mut index; - } - for _v in &vec { - _index += 1 - } - - let mut index = 0; - for _v in &vec { - index += 1 - } - println!("index: {}", index); - - fn f(_: &T, _: &T) -> bool { - unimplemented!() - } - fn g(_: &mut [T], _: usize, _: usize) { - unimplemented!() - } - for i in 1..vec.len() { - if f(&vec[i - 1], &vec[i]) { - g(&mut vec, i - 1, i); - } - } - - for mid in 1..vec.len() { - let (_, _) = vec.split_at(mid); - } -} - -fn partition(v: &mut [T]) -> usize { - let pivot = v.len() - 1; - let mut i = 0; - for j in 0..pivot { - if v[j] <= v[pivot] { - v.swap(i, j); - i += 1; - } - } - v.swap(i, pivot); - i -} - -#[warn(clippy::needless_range_loop)] -pub fn manual_copy_same_destination(dst: &mut [i32], d: usize, s: usize) { - // Same source and destination - don't trigger lint - for i in 0..dst.len() { - dst[d + i] = dst[s + i]; - } -} - -mod issue_2496 { - pub trait Handle { - fn new_for_index(index: usize) -> Self; - fn index(&self) -> usize; - } - - pub fn test() -> H { - for x in 0..5 { - let next_handle = H::new_for_index(x); - println!("{}", next_handle.index()); - } - unimplemented!() - } -} - -// explicit_into_iter_loop bad suggestions -#[warn(clippy::explicit_into_iter_loop, clippy::explicit_iter_loop)] -mod issue_4958 { - fn takes_iterator(iterator: &T) - where - for<'a> &'a T: IntoIterator, - { - for i in iterator { - println!("{}", i); - } - } - - struct T; - impl IntoIterator for &T { - type Item = (); - type IntoIter = std::vec::IntoIter; - fn into_iter(self) -> Self::IntoIter { - vec![].into_iter() - } - } - - fn more_tests() { - let t = T; - let r = &t; - let rr = &&t; - - // This case is handled by `explicit_iter_loop`. No idea why. - for _ in &t {} - - for _ in r {} - - // No suggestion for this. - // We'd have to suggest `for _ in *rr {}` which is less clear. - for _ in rr.into_iter() {} - } -} diff --git a/tests/ui/for_loop_fixable.rs b/tests/ui/for_loop_fixable.rs deleted file mode 100644 index 306d85a6351e..000000000000 --- a/tests/ui/for_loop_fixable.rs +++ /dev/null @@ -1,283 +0,0 @@ -// run-rustfix - -#![allow(dead_code, unused)] - -use std::collections::*; - -#[warn(clippy::all)] -struct Unrelated(Vec); -impl Unrelated { - fn next(&self) -> std::slice::Iter { - self.0.iter() - } - - fn iter(&self) -> std::slice::Iter { - self.0.iter() - } -} - -#[warn( - clippy::needless_range_loop, - clippy::explicit_iter_loop, - clippy::explicit_into_iter_loop, - clippy::iter_next_loop, - clippy::for_kv_map -)] -#[allow( - clippy::linkedlist, - clippy::shadow_unrelated, - clippy::unnecessary_mut_passed, - clippy::similar_names -)] -#[allow(clippy::many_single_char_names, unused_variables)] -fn main() { - let mut vec = vec![1, 2, 3, 4]; - - // See #601 - for i in 0..10 { - // no error, id_col does not exist outside the loop - let mut id_col = vec![0f64; 10]; - id_col[i] = 1f64; - } - - for _v in vec.iter() {} - - for _v in vec.iter_mut() {} - - let out_vec = vec![1, 2, 3]; - for _v in out_vec.into_iter() {} - - for _v in &vec {} // these are fine - for _v in &mut vec {} // these are fine - - for _v in [1, 2, 3].iter() {} - - for _v in (&mut [1, 2, 3]).iter() {} // no error - - for _v in [0; 32].iter() {} - - for _v in [0; 33].iter() {} // no error - - let ll: LinkedList<()> = LinkedList::new(); - for _v in ll.iter() {} - - let vd: VecDeque<()> = VecDeque::new(); - for _v in vd.iter() {} - - let bh: BinaryHeap<()> = BinaryHeap::new(); - for _v in bh.iter() {} - - let hm: HashMap<(), ()> = HashMap::new(); - for _v in hm.iter() {} - - let bt: BTreeMap<(), ()> = BTreeMap::new(); - for _v in bt.iter() {} - - let hs: HashSet<()> = HashSet::new(); - for _v in hs.iter() {} - - let bs: BTreeSet<()> = BTreeSet::new(); - for _v in bs.iter() {} - - let u = Unrelated(vec![]); - for _v in u.next() {} // no error - for _v in u.iter() {} // no error - - let mut out = vec![]; - vec.iter().cloned().map(|x| out.push(x)).collect::>(); - let _y = vec.iter().cloned().map(|x| out.push(x)).collect::>(); // this is fine - - // Loop with explicit counter variable - - // Potential false positives - let mut _index = 0; - _index = 1; - for _v in &vec { - _index += 1 - } - - let mut _index = 0; - _index += 1; - for _v in &vec { - _index += 1 - } - - let mut _index = 0; - if true { - _index = 1 - } - for _v in &vec { - _index += 1 - } - - let mut _index = 0; - let mut _index = 1; - for _v in &vec { - _index += 1 - } - - let mut _index = 0; - for _v in &vec { - _index += 1; - _index += 1 - } - - let mut _index = 0; - for _v in &vec { - _index *= 2; - _index += 1 - } - - let mut _index = 0; - for _v in &vec { - _index = 1; - _index += 1 - } - - let mut _index = 0; - - for _v in &vec { - let mut _index = 0; - _index += 1 - } - - let mut _index = 0; - for _v in &vec { - _index += 1; - _index = 0; - } - - let mut _index = 0; - for _v in &vec { - for _x in 0..1 { - _index += 1; - } - _index += 1 - } - - let mut _index = 0; - for x in &vec { - if *x == 1 { - _index += 1 - } - } - - let mut _index = 0; - if true { - _index = 1 - }; - for _v in &vec { - _index += 1 - } - - let mut _index = 1; - if false { - _index = 0 - }; - for _v in &vec { - _index += 1 - } - - let mut index = 0; - { - let mut _x = &mut index; - } - for _v in &vec { - _index += 1 - } - - let mut index = 0; - for _v in &vec { - index += 1 - } - println!("index: {}", index); - - fn f(_: &T, _: &T) -> bool { - unimplemented!() - } - fn g(_: &mut [T], _: usize, _: usize) { - unimplemented!() - } - for i in 1..vec.len() { - if f(&vec[i - 1], &vec[i]) { - g(&mut vec, i - 1, i); - } - } - - for mid in 1..vec.len() { - let (_, _) = vec.split_at(mid); - } -} - -fn partition(v: &mut [T]) -> usize { - let pivot = v.len() - 1; - let mut i = 0; - for j in 0..pivot { - if v[j] <= v[pivot] { - v.swap(i, j); - i += 1; - } - } - v.swap(i, pivot); - i -} - -#[warn(clippy::needless_range_loop)] -pub fn manual_copy_same_destination(dst: &mut [i32], d: usize, s: usize) { - // Same source and destination - don't trigger lint - for i in 0..dst.len() { - dst[d + i] = dst[s + i]; - } -} - -mod issue_2496 { - pub trait Handle { - fn new_for_index(index: usize) -> Self; - fn index(&self) -> usize; - } - - pub fn test() -> H { - for x in 0..5 { - let next_handle = H::new_for_index(x); - println!("{}", next_handle.index()); - } - unimplemented!() - } -} - -// explicit_into_iter_loop bad suggestions -#[warn(clippy::explicit_into_iter_loop, clippy::explicit_iter_loop)] -mod issue_4958 { - fn takes_iterator(iterator: &T) - where - for<'a> &'a T: IntoIterator, - { - for i in iterator.into_iter() { - println!("{}", i); - } - } - - struct T; - impl IntoIterator for &T { - type Item = (); - type IntoIter = std::vec::IntoIter; - fn into_iter(self) -> Self::IntoIter { - vec![].into_iter() - } - } - - fn more_tests() { - let t = T; - let r = &t; - let rr = &&t; - - // This case is handled by `explicit_iter_loop`. No idea why. - for _ in t.into_iter() {} - - for _ in r.into_iter() {} - - // No suggestion for this. - // We'd have to suggest `for _ in *rr {}` which is less clear. - for _ in rr.into_iter() {} - } -} diff --git a/tests/ui/for_loop_fixable.stderr b/tests/ui/for_loop_fixable.stderr deleted file mode 100644 index ddfe66d675f9..000000000000 --- a/tests/ui/for_loop_fixable.stderr +++ /dev/null @@ -1,96 +0,0 @@ -error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:43:15 - | -LL | for _v in vec.iter() {} - | ^^^^^^^^^^ help: to write this more concisely, try: `&vec` - | - = note: `-D clippy::explicit-iter-loop` implied by `-D warnings` - -error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:45:15 - | -LL | for _v in vec.iter_mut() {} - | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut vec` - -error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:48:15 - | -LL | for _v in out_vec.into_iter() {} - | ^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `out_vec` - | - = note: `-D clippy::explicit-into-iter-loop` implied by `-D warnings` - -error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:53:15 - | -LL | for _v in [1, 2, 3].iter() {} - | ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[1, 2, 3]` - -error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:57:15 - | -LL | for _v in [0; 32].iter() {} - | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]` - -error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:62:15 - | -LL | for _v in ll.iter() {} - | ^^^^^^^^^ help: to write this more concisely, try: `&ll` - -error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:65:15 - | -LL | for _v in vd.iter() {} - | ^^^^^^^^^ help: to write this more concisely, try: `&vd` - -error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:68:15 - | -LL | for _v in bh.iter() {} - | ^^^^^^^^^ help: to write this more concisely, try: `&bh` - -error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:71:15 - | -LL | for _v in hm.iter() {} - | ^^^^^^^^^ help: to write this more concisely, try: `&hm` - -error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:74:15 - | -LL | for _v in bt.iter() {} - | ^^^^^^^^^ help: to write this more concisely, try: `&bt` - -error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:77:15 - | -LL | for _v in hs.iter() {} - | ^^^^^^^^^ help: to write this more concisely, try: `&hs` - -error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:80:15 - | -LL | for _v in bs.iter() {} - | ^^^^^^^^^ help: to write this more concisely, try: `&bs` - -error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:255:18 - | -LL | for i in iterator.into_iter() { - | ^^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `iterator` - -error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:275:18 - | -LL | for _ in t.into_iter() {} - | ^^^^^^^^^^^^^ help: to write this more concisely, try: `&t` - -error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/for_loop_fixable.rs:277:18 - | -LL | for _ in r.into_iter() {} - | ^^^^^^^^^^^^^ help: to write this more concisely, try: `r` - -error: aborting due to 15 previous errors - diff --git a/tests/ui/for_loop_unfixable.rs b/tests/ui/for_loop_unfixable.rs deleted file mode 100644 index e73536052f0f..000000000000 --- a/tests/ui/for_loop_unfixable.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Tests from for_loop.rs that don't have suggestions - -#[warn( - clippy::needless_range_loop, - clippy::explicit_iter_loop, - clippy::explicit_into_iter_loop, - clippy::iter_next_loop, - clippy::for_kv_map -)] -#[allow( - clippy::linkedlist, - clippy::shadow_unrelated, - clippy::unnecessary_mut_passed, - clippy::similar_names, - unused, - dead_code -)] -fn main() { - let vec = vec![1, 2, 3, 4]; - - for _v in vec.iter().next() {} -} diff --git a/tests/ui/for_loop_unfixable.stderr b/tests/ui/for_loop_unfixable.stderr deleted file mode 100644 index 1c9287b6acbb..000000000000 --- a/tests/ui/for_loop_unfixable.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want - --> $DIR/for_loop_unfixable.rs:21:15 - | -LL | for _v in vec.iter().next() {} - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::iter-next-loop` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/for_loops_over_fallibles.rs b/tests/ui/for_loops_over_fallibles.rs deleted file mode 100644 index 1b9dde87cd5a..000000000000 --- a/tests/ui/for_loops_over_fallibles.rs +++ /dev/null @@ -1,57 +0,0 @@ -#![warn(clippy::for_loops_over_fallibles)] - -fn for_loops_over_fallibles() { - let option = Some(1); - let result = option.ok_or("x not found"); - let v = vec![0, 1, 2]; - - // check over an `Option` - for x in option { - println!("{}", x); - } - - // check over a `Result` - for x in result { - println!("{}", x); - } - - for x in option.ok_or("x not found") { - println!("{}", x); - } - - // make sure LOOP_OVER_NEXT lint takes clippy::precedence when next() is the last call - // in the chain - for x in v.iter().next() { - println!("{}", x); - } - - // make sure we lint when next() is not the last call in the chain - for x in v.iter().next().and(Some(0)) { - println!("{}", x); - } - - for x in v.iter().next().ok_or("x not found") { - println!("{}", x); - } - - // check for false positives - - // for loop false positive - for x in v { - println!("{}", x); - } - - // while let false positive for Option - while let Some(x) = option { - println!("{}", x); - break; - } - - // while let false positive for Result - while let Ok(x) = result { - println!("{}", x); - break; - } -} - -fn main() {} diff --git a/tests/ui/for_loops_over_fallibles.stderr b/tests/ui/for_loops_over_fallibles.stderr deleted file mode 100644 index bef228d4b93a..000000000000 --- a/tests/ui/for_loops_over_fallibles.stderr +++ /dev/null @@ -1,71 +0,0 @@ -error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement. - --> $DIR/for_loops_over_fallibles.rs:9:14 - | -LL | for x in option { - | ^^^^^^ - | - = note: `-D clippy::for-loops-over-fallibles` implied by `-D warnings` - = help: consider replacing `for x in option` with `if let Some(x) = option` - -error: for loop over `result`, which is a `Result`. This is more readably written as an `if let` statement. - --> $DIR/for_loops_over_fallibles.rs:14:14 - | -LL | for x in result { - | ^^^^^^ - | - = help: consider replacing `for x in result` with `if let Ok(x) = result` - -error: for loop over `option.ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement. - --> $DIR/for_loops_over_fallibles.rs:18:14 - | -LL | for x in option.ok_or("x not found") { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider replacing `for x in option.ok_or("x not found")` with `if let Ok(x) = option.ok_or("x not found")` - -error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want - --> $DIR/for_loops_over_fallibles.rs:24:14 - | -LL | for x in v.iter().next() { - | ^^^^^^^^^^^^^^^ - | - = note: `#[deny(clippy::iter_next_loop)]` on by default - -error: for loop over `v.iter().next().and(Some(0))`, which is an `Option`. This is more readably written as an `if let` statement. - --> $DIR/for_loops_over_fallibles.rs:29:14 - | -LL | for x in v.iter().next().and(Some(0)) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider replacing `for x in v.iter().next().and(Some(0))` with `if let Some(x) = v.iter().next().and(Some(0))` - -error: for loop over `v.iter().next().ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement. - --> $DIR/for_loops_over_fallibles.rs:33:14 - | -LL | for x in v.iter().next().ok_or("x not found") { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider replacing `for x in v.iter().next().ok_or("x not found")` with `if let Ok(x) = v.iter().next().ok_or("x not found")` - -error: this loop never actually loops - --> $DIR/for_loops_over_fallibles.rs:45:5 - | -LL | / while let Some(x) = option { -LL | | println!("{}", x); -LL | | break; -LL | | } - | |_____^ - | - = note: `#[deny(clippy::never_loop)]` on by default - -error: this loop never actually loops - --> $DIR/for_loops_over_fallibles.rs:51:5 - | -LL | / while let Ok(x) = result { -LL | | println!("{}", x); -LL | | break; -LL | | } - | |_____^ - -error: aborting due to 8 previous errors - diff --git a/tests/ui/forget_ref.rs b/tests/ui/forget_ref.rs deleted file mode 100644 index c49e6756a6c5..000000000000 --- a/tests/ui/forget_ref.rs +++ /dev/null @@ -1,49 +0,0 @@ -#![warn(clippy::forget_ref)] -#![allow(clippy::toplevel_ref_arg)] -#![allow(clippy::unnecessary_wraps)] - -use std::mem::forget; - -struct SomeStruct; - -fn main() { - forget(&SomeStruct); - - let mut owned = SomeStruct; - forget(&owned); - forget(&&owned); - forget(&mut owned); - forget(owned); //OK - - let reference1 = &SomeStruct; - forget(&*reference1); - - let reference2 = &mut SomeStruct; - forget(reference2); - - let ref reference3 = SomeStruct; - forget(reference3); -} - -#[allow(dead_code)] -fn test_generic_fn_forget(val: T) { - forget(&val); - forget(val); //OK -} - -#[allow(dead_code)] -fn test_similarly_named_function() { - fn forget(_val: T) {} - forget(&SomeStruct); //OK; call to unrelated function which happens to have the same name - std::mem::forget(&SomeStruct); -} - -#[derive(Copy, Clone)] -pub struct Error; -fn produce_half_owl_error() -> Result<(), Error> { - Ok(()) -} - -fn produce_half_owl_ok() -> Result { - Ok(true) -} diff --git a/tests/ui/forget_ref.stderr b/tests/ui/forget_ref.stderr deleted file mode 100644 index b2c7f2023bfb..000000000000 --- a/tests/ui/forget_ref.stderr +++ /dev/null @@ -1,111 +0,0 @@ -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing. - --> $DIR/forget_ref.rs:10:5 - | -LL | forget(&SomeStruct); - | ^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::forget-ref` implied by `-D warnings` -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:10:12 - | -LL | forget(&SomeStruct); - | ^^^^^^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing. - --> $DIR/forget_ref.rs:13:5 - | -LL | forget(&owned); - | ^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:13:12 - | -LL | forget(&owned); - | ^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing. - --> $DIR/forget_ref.rs:14:5 - | -LL | forget(&&owned); - | ^^^^^^^^^^^^^^^ - | -note: argument has type `&&SomeStruct` - --> $DIR/forget_ref.rs:14:12 - | -LL | forget(&&owned); - | ^^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing. - --> $DIR/forget_ref.rs:15:5 - | -LL | forget(&mut owned); - | ^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&mut SomeStruct` - --> $DIR/forget_ref.rs:15:12 - | -LL | forget(&mut owned); - | ^^^^^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing. - --> $DIR/forget_ref.rs:19:5 - | -LL | forget(&*reference1); - | ^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:19:12 - | -LL | forget(&*reference1); - | ^^^^^^^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing. - --> $DIR/forget_ref.rs:22:5 - | -LL | forget(reference2); - | ^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&mut SomeStruct` - --> $DIR/forget_ref.rs:22:12 - | -LL | forget(reference2); - | ^^^^^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing. - --> $DIR/forget_ref.rs:25:5 - | -LL | forget(reference3); - | ^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:25:12 - | -LL | forget(reference3); - | ^^^^^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing. - --> $DIR/forget_ref.rs:30:5 - | -LL | forget(&val); - | ^^^^^^^^^^^^ - | -note: argument has type `&T` - --> $DIR/forget_ref.rs:30:12 - | -LL | forget(&val); - | ^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing. - --> $DIR/forget_ref.rs:38:5 - | -LL | std::mem::forget(&SomeStruct); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:38:22 - | -LL | std::mem::forget(&SomeStruct); - | ^^^^^^^^^^^ - -error: aborting due to 9 previous errors - diff --git a/tests/ui/format.fixed b/tests/ui/format.fixed deleted file mode 100644 index 740a22a07d74..000000000000 --- a/tests/ui/format.fixed +++ /dev/null @@ -1,68 +0,0 @@ -// run-rustfix - -#![allow(clippy::print_literal, clippy::redundant_clone)] -#![warn(clippy::useless_format)] - -struct Foo(pub String); - -macro_rules! foo { - ($($t:tt)*) => (Foo(format!($($t)*))) -} - -fn main() { - "foo".to_string(); - "{}".to_string(); - "{} abc {}".to_string(); - r##"foo {} -" bar"##.to_string(); - - "foo".to_string(); - format!("{:?}", "foo"); // Don't warn about `Debug`. - format!("{:8}", "foo"); - format!("{:width$}", "foo", width = 8); - "foo".to_string(); // Warn when the format makes no difference. - "foo".to_string(); // Warn when the format makes no difference. - format!("foo {}", "bar"); - format!("{} bar", "foo"); - - let arg: String = "".to_owned(); - arg.to_string(); - format!("{:?}", arg); // Don't warn about debug. - format!("{:8}", arg); - format!("{:width$}", arg, width = 8); - arg.to_string(); // Warn when the format makes no difference. - arg.to_string(); // Warn when the format makes no difference. - format!("foo {}", arg); - format!("{} bar", arg); - - // We don’t want to warn for non-string args; see issue #697. - format!("{}", 42); - format!("{:?}", 42); - format!("{:+}", 42); - format!("foo {}", 42); - format!("{} bar", 42); - - // We only want to warn about `format!` itself. - println!("foo"); - println!("{}", "foo"); - println!("foo {}", "foo"); - println!("{}", 42); - println!("foo {}", 42); - - // A `format!` inside a macro should not trigger a warning. - foo!("should not warn"); - - // Precision on string means slicing without panicking on size. - format!("{:.1}", "foo"); // Could be `"foo"[..1]` - format!("{:.10}", "foo"); // Could not be `"foo"[..10]` - format!("{:.prec$}", "foo", prec = 1); - format!("{:.prec$}", "foo", prec = 10); - - 42.to_string(); - let x = std::path::PathBuf::from("/bar/foo/qux"); - x.display().to_string(); - - // False positive - let a = "foo".to_string(); - let _ = Some(a + "bar"); -} diff --git a/tests/ui/format.rs b/tests/ui/format.rs deleted file mode 100644 index b604d79cca37..000000000000 --- a/tests/ui/format.rs +++ /dev/null @@ -1,70 +0,0 @@ -// run-rustfix - -#![allow(clippy::print_literal, clippy::redundant_clone)] -#![warn(clippy::useless_format)] - -struct Foo(pub String); - -macro_rules! foo { - ($($t:tt)*) => (Foo(format!($($t)*))) -} - -fn main() { - format!("foo"); - format!("{{}}"); - format!("{{}} abc {{}}"); - format!( - r##"foo {{}} -" bar"## - ); - - format!("{}", "foo"); - format!("{:?}", "foo"); // Don't warn about `Debug`. - format!("{:8}", "foo"); - format!("{:width$}", "foo", width = 8); - format!("{:+}", "foo"); // Warn when the format makes no difference. - format!("{:<}", "foo"); // Warn when the format makes no difference. - format!("foo {}", "bar"); - format!("{} bar", "foo"); - - let arg: String = "".to_owned(); - format!("{}", arg); - format!("{:?}", arg); // Don't warn about debug. - format!("{:8}", arg); - format!("{:width$}", arg, width = 8); - format!("{:+}", arg); // Warn when the format makes no difference. - format!("{:<}", arg); // Warn when the format makes no difference. - format!("foo {}", arg); - format!("{} bar", arg); - - // We don’t want to warn for non-string args; see issue #697. - format!("{}", 42); - format!("{:?}", 42); - format!("{:+}", 42); - format!("foo {}", 42); - format!("{} bar", 42); - - // We only want to warn about `format!` itself. - println!("foo"); - println!("{}", "foo"); - println!("foo {}", "foo"); - println!("{}", 42); - println!("foo {}", 42); - - // A `format!` inside a macro should not trigger a warning. - foo!("should not warn"); - - // Precision on string means slicing without panicking on size. - format!("{:.1}", "foo"); // Could be `"foo"[..1]` - format!("{:.10}", "foo"); // Could not be `"foo"[..10]` - format!("{:.prec$}", "foo", prec = 1); - format!("{:.prec$}", "foo", prec = 10); - - format!("{}", 42.to_string()); - let x = std::path::PathBuf::from("/bar/foo/qux"); - format!("{}", x.display().to_string()); - - // False positive - let a = "foo".to_string(); - let _ = Some(format!("{}", a + "bar")); -} diff --git a/tests/ui/format.stderr b/tests/ui/format.stderr deleted file mode 100644 index 96df7f37f779..000000000000 --- a/tests/ui/format.stderr +++ /dev/null @@ -1,91 +0,0 @@ -error: useless use of `format!` - --> $DIR/format.rs:13:5 - | -LL | format!("foo"); - | ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string();` - | - = note: `-D clippy::useless-format` implied by `-D warnings` - -error: useless use of `format!` - --> $DIR/format.rs:14:5 - | -LL | format!("{{}}"); - | ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{}".to_string();` - -error: useless use of `format!` - --> $DIR/format.rs:15:5 - | -LL | format!("{{}} abc {{}}"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string();` - -error: useless use of `format!` - --> $DIR/format.rs:16:5 - | -LL | / format!( -LL | | r##"foo {{}} -LL | | " bar"## -LL | | ); - | |______^ - | -help: consider using `.to_string()` - | -LL | r##"foo {} -LL | " bar"##.to_string(); - | - -error: useless use of `format!` - --> $DIR/format.rs:21:5 - | -LL | format!("{}", "foo"); - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string();` - -error: useless use of `format!` - --> $DIR/format.rs:25:5 - | -LL | format!("{:+}", "foo"); // Warn when the format makes no difference. - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string();` - -error: useless use of `format!` - --> $DIR/format.rs:26:5 - | -LL | format!("{:<}", "foo"); // Warn when the format makes no difference. - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string();` - -error: useless use of `format!` - --> $DIR/format.rs:31:5 - | -LL | format!("{}", arg); - | ^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string();` - -error: useless use of `format!` - --> $DIR/format.rs:35:5 - | -LL | format!("{:+}", arg); // Warn when the format makes no difference. - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string();` - -error: useless use of `format!` - --> $DIR/format.rs:36:5 - | -LL | format!("{:<}", arg); // Warn when the format makes no difference. - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string();` - -error: useless use of `format!` - --> $DIR/format.rs:63:5 - | -LL | format!("{}", 42.to_string()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string();` - -error: useless use of `format!` - --> $DIR/format.rs:65:5 - | -LL | format!("{}", x.display().to_string()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string();` - -error: useless use of `format!` - --> $DIR/format.rs:69:18 - | -LL | let _ = Some(format!("{}", a + "bar")); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `a + "bar"` - -error: aborting due to 13 previous errors - diff --git a/tests/ui/formatting.rs b/tests/ui/formatting.rs deleted file mode 100644 index 0d14807ff1cf..000000000000 --- a/tests/ui/formatting.rs +++ /dev/null @@ -1,72 +0,0 @@ -#![warn(clippy::all)] -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(clippy::if_same_then_else)] -#![allow(clippy::deref_addrof)] - -fn foo() -> bool { - true -} - -#[rustfmt::skip] -fn main() { - // weird op_eq formatting: - let mut a = 42; - a =- 35; - a =* &191; - - let mut b = true; - b =! false; - - // those are ok: - a = -35; - a = *&191; - b = !false; - - // possible missing comma in an array - let _ = &[ - -1, -2, -3 // <= no comma here - -4, -5, -6 - ]; - let _ = &[ - -1, -2, -3 // <= no comma here - *4, -5, -6 - ]; - - // those are ok: - let _ = &[ - -1, -2, -3, - -4, -5, -6 - ]; - let _ = &[ - -1, -2, -3, - -4, -5, -6, - ]; - let _ = &[ - 1 + 2, 3 + - 4, 5 + 6, - ]; - - // don't lint for bin op without unary equiv - // issue 3244 - vec![ - 1 - / 2, - ]; - // issue 3396 - vec![ - true - | false, - ]; - - // don't lint if the indentation suggests not to - let _ = &[ - 1 + 2, 3 - - 4, 5 - ]; - // lint if it doesn't - let _ = &[ - -1 - -4, - ]; -} diff --git a/tests/ui/formatting.stderr b/tests/ui/formatting.stderr deleted file mode 100644 index bde434c7e2e7..000000000000 --- a/tests/ui/formatting.stderr +++ /dev/null @@ -1,52 +0,0 @@ -error: this looks like you are trying to use `.. -= ..`, but you really are doing `.. = (- ..)` - --> $DIR/formatting.rs:15:6 - | -LL | a =- 35; - | ^^^^ - | - = note: `-D clippy::suspicious-assignment-formatting` implied by `-D warnings` - = note: to remove this lint, use either `-=` or `= -` - -error: this looks like you are trying to use `.. *= ..`, but you really are doing `.. = (* ..)` - --> $DIR/formatting.rs:16:6 - | -LL | a =* &191; - | ^^^^ - | - = note: to remove this lint, use either `*=` or `= *` - -error: this looks like you are trying to use `.. != ..`, but you really are doing `.. = (! ..)` - --> $DIR/formatting.rs:19:6 - | -LL | b =! false; - | ^^^^ - | - = note: to remove this lint, use either `!=` or `= !` - -error: possibly missing a comma here - --> $DIR/formatting.rs:28:19 - | -LL | -1, -2, -3 // <= no comma here - | ^ - | - = note: `-D clippy::possible-missing-comma` implied by `-D warnings` - = note: to remove this lint, add a comma or write the expr in a single line - -error: possibly missing a comma here - --> $DIR/formatting.rs:32:19 - | -LL | -1, -2, -3 // <= no comma here - | ^ - | - = note: to remove this lint, add a comma or write the expr in a single line - -error: possibly missing a comma here - --> $DIR/formatting.rs:69:11 - | -LL | -1 - | ^ - | - = note: to remove this lint, add a comma or write the expr in a single line - -error: aborting due to 6 previous errors - diff --git a/tests/ui/from_iter_instead_of_collect.rs b/tests/ui/from_iter_instead_of_collect.rs deleted file mode 100644 index 045eb3133d3c..000000000000 --- a/tests/ui/from_iter_instead_of_collect.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![warn(clippy::from_iter_instead_of_collect)] - -use std::collections::HashMap; -use std::iter::FromIterator; - -fn main() { - let iter_expr = std::iter::repeat(5).take(5); - Vec::from_iter(iter_expr); - - HashMap::::from_iter(vec![5, 5, 5, 5].iter().enumerate()); - - Vec::from_iter(vec![42u32]); -} diff --git a/tests/ui/from_iter_instead_of_collect.stderr b/tests/ui/from_iter_instead_of_collect.stderr deleted file mode 100644 index 46bdc2f4e199..000000000000 --- a/tests/ui/from_iter_instead_of_collect.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:8:5 - | -LL | Vec::from_iter(iter_expr); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `iter_expr.collect()` - | - = note: `-D clippy::from-iter-instead-of-collect` implied by `-D warnings` - -error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:10:5 - | -LL | HashMap::::from_iter(vec![5, 5, 5, 5].iter().enumerate()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `vec![5, 5, 5, 5].iter().enumerate().collect()` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/functions.rs b/tests/ui/functions.rs deleted file mode 100644 index 271754cb06ee..000000000000 --- a/tests/ui/functions.rs +++ /dev/null @@ -1,104 +0,0 @@ -#![warn(clippy::all)] -#![allow(dead_code)] -#![allow(unused_unsafe, clippy::missing_safety_doc)] - -// TOO_MANY_ARGUMENTS -fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {} - -fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} - -#[rustfmt::skip] -fn bad_multiline( - one: u32, - two: u32, - three: &str, - four: bool, - five: f32, - six: f32, - seven: bool, - eight: () -) { - let _one = one; - let _two = two; - let _three = three; - let _four = four; - let _five = five; - let _six = six; - let _seven = seven; -} - -// don't lint extern fns -extern "C" fn extern_fn( - _one: u32, - _two: u32, - _three: *const u8, - _four: bool, - _five: f32, - _six: f32, - _seven: bool, - _eight: *const std::ffi::c_void, -) { -} - -pub trait Foo { - fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool); - fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()); - - fn ptr(p: *const u8); -} - -pub struct Bar; - -impl Bar { - fn good_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {} - fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} -} - -// ok, we don’t want to warn implementations -impl Foo for Bar { - fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {} - fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} - - fn ptr(p: *const u8) { - println!("{}", unsafe { *p }); - println!("{:?}", unsafe { p.as_ref() }); - unsafe { std::ptr::read(p) }; - } -} - -// NOT_UNSAFE_PTR_ARG_DEREF - -fn private(p: *const u8) { - println!("{}", unsafe { *p }); -} - -pub fn public(p: *const u8) { - println!("{}", unsafe { *p }); - println!("{:?}", unsafe { p.as_ref() }); - unsafe { std::ptr::read(p) }; -} - -impl Bar { - fn private(self, p: *const u8) { - println!("{}", unsafe { *p }); - } - - pub fn public(self, p: *const u8) { - println!("{}", unsafe { *p }); - println!("{:?}", unsafe { p.as_ref() }); - unsafe { std::ptr::read(p) }; - } - - pub fn public_ok(self, p: *const u8) { - if !p.is_null() { - println!("{:p}", p); - } - } - - pub unsafe fn public_unsafe(self, p: *const u8) { - println!("{}", unsafe { *p }); - println!("{:?}", unsafe { p.as_ref() }); - } -} - -fn main() {} diff --git a/tests/ui/functions.stderr b/tests/ui/functions.stderr deleted file mode 100644 index 0a86568b18de..000000000000 --- a/tests/ui/functions.stderr +++ /dev/null @@ -1,90 +0,0 @@ -error: this function has too many arguments (8/7) - --> $DIR/functions.rs:8:1 - | -LL | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::too-many-arguments` implied by `-D warnings` - -error: this function has too many arguments (8/7) - --> $DIR/functions.rs:11:1 - | -LL | / fn bad_multiline( -LL | | one: u32, -LL | | two: u32, -LL | | three: &str, -... | -LL | | eight: () -LL | | ) { - | |__^ - -error: this function has too many arguments (8/7) - --> $DIR/functions.rs:45:5 - | -LL | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: this function has too many arguments (8/7) - --> $DIR/functions.rs:54:5 - | -LL | fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: this public function dereferences a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:63:34 - | -LL | println!("{}", unsafe { *p }); - | ^ - | - = note: `-D clippy::not-unsafe-ptr-arg-deref` implied by `-D warnings` - -error: this public function dereferences a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:64:35 - | -LL | println!("{:?}", unsafe { p.as_ref() }); - | ^ - -error: this public function dereferences a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:65:33 - | -LL | unsafe { std::ptr::read(p) }; - | ^ - -error: this public function dereferences a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:76:30 - | -LL | println!("{}", unsafe { *p }); - | ^ - -error: this public function dereferences a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:77:31 - | -LL | println!("{:?}", unsafe { p.as_ref() }); - | ^ - -error: this public function dereferences a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:78:29 - | -LL | unsafe { std::ptr::read(p) }; - | ^ - -error: this public function dereferences a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:87:34 - | -LL | println!("{}", unsafe { *p }); - | ^ - -error: this public function dereferences a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:88:35 - | -LL | println!("{:?}", unsafe { p.as_ref() }); - | ^ - -error: this public function dereferences a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:89:33 - | -LL | unsafe { std::ptr::read(p) }; - | ^ - -error: aborting due to 13 previous errors - diff --git a/tests/ui/functions_maxlines.rs b/tests/ui/functions_maxlines.rs deleted file mode 100644 index 5e1ee55e0104..000000000000 --- a/tests/ui/functions_maxlines.rs +++ /dev/null @@ -1,163 +0,0 @@ -#![warn(clippy::too_many_lines)] - -fn good_lines() { - /* println!("This is good."); */ - // println!("This is good."); - /* */ // println!("This is good."); - /* */ // println!("This is good."); - /* */ // println!("This is good."); - /* */ // println!("This is good."); - /* println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); */ - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); - println!("This is good."); -} - -fn bad_lines() { - println!("Dont get confused by braces: {{}}"); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); - println!("This is bad."); -} - -fn main() {} diff --git a/tests/ui/functions_maxlines.stderr b/tests/ui/functions_maxlines.stderr deleted file mode 100644 index dc6c8ba2f154..000000000000 --- a/tests/ui/functions_maxlines.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: this function has too many lines (102/100) - --> $DIR/functions_maxlines.rs:58:1 - | -LL | / fn bad_lines() { -LL | | println!("Dont get confused by braces: {{}}"); -LL | | println!("This is bad."); -LL | | println!("This is bad."); -... | -LL | | println!("This is bad."); -LL | | } - | |_^ - | - = note: `-D clippy::too-many-lines` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/future_not_send.rs b/tests/ui/future_not_send.rs deleted file mode 100644 index d3a920de4b6a..000000000000 --- a/tests/ui/future_not_send.rs +++ /dev/null @@ -1,80 +0,0 @@ -// edition:2018 -#![warn(clippy::future_not_send)] - -use std::cell::Cell; -use std::rc::Rc; -use std::sync::Arc; - -async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { - async { true }.await -} - -pub async fn public_future(rc: Rc<[u8]>) { - async { true }.await; -} - -pub async fn public_send(arc: Arc<[u8]>) -> bool { - async { false }.await -} - -async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { - true -} - -pub async fn public_future2(rc: Rc<[u8]>) {} - -pub async fn public_send2(arc: Arc<[u8]>) -> bool { - false -} - -struct Dummy { - rc: Rc<[u8]>, -} - -impl Dummy { - async fn private_future(&self) -> usize { - async { true }.await; - self.rc.len() - } - - pub async fn public_future(&self) { - self.private_future().await; - } - - #[allow(clippy::manual_async_fn)] - pub fn public_send(&self) -> impl std::future::Future { - async { false } - } -} - -async fn generic_future(t: T) -> T -where - T: Send, -{ - let rt = &t; - async { true }.await; - t -} - -async fn generic_future_send(t: T) -where - T: Send, -{ - async { true }.await; -} - -async fn unclear_future(t: T) {} - -fn main() { - let rc = Rc::new([1, 2, 3]); - private_future(rc.clone(), &Cell::new(42)); - public_future(rc.clone()); - let arc = Arc::new([4, 5, 6]); - public_send(arc); - generic_future(42); - generic_future_send(42); - - let dummy = Dummy { rc }; - dummy.public_future(); - dummy.public_send(); -} diff --git a/tests/ui/future_not_send.stderr b/tests/ui/future_not_send.stderr deleted file mode 100644 index b59dbb3e76c6..000000000000 --- a/tests/ui/future_not_send.stderr +++ /dev/null @@ -1,145 +0,0 @@ -error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:8:62 - | -LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { - | ^^^^ future returned by `private_future` is not `Send` - | - = note: `-D clippy::future-not-send` implied by `-D warnings` -note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:9:5 - | -LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { - | -- has type `std::rc::Rc<[u8]>` which is not `Send` -LL | async { true }.await - | ^^^^^^^^^^^^^^^^^^^^ await occurs here, with `rc` maybe used later -LL | } - | - `rc` is later dropped here - = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` -note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:9:5 - | -LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { - | ---- has type `&std::cell::Cell` which is not `Send` -LL | async { true }.await - | ^^^^^^^^^^^^^^^^^^^^ await occurs here, with `cell` maybe used later -LL | } - | - `cell` is later dropped here - = note: `std::cell::Cell` doesn't implement `std::marker::Sync` - -error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:12:42 - | -LL | pub async fn public_future(rc: Rc<[u8]>) { - | ^ future returned by `public_future` is not `Send` - | -note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:13:5 - | -LL | pub async fn public_future(rc: Rc<[u8]>) { - | -- has type `std::rc::Rc<[u8]>` which is not `Send` -LL | async { true }.await; - | ^^^^^^^^^^^^^^^^^^^^ await occurs here, with `rc` maybe used later -LL | } - | - `rc` is later dropped here - = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` - -error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:20:63 - | -LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { - | ^^^^ future returned by `private_future2` is not `Send` - | -note: captured value is not `Send` - --> $DIR/future_not_send.rs:20:26 - | -LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { - | ^^ has type `std::rc::Rc<[u8]>` which is not `Send` - = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` -note: captured value is not `Send` - --> $DIR/future_not_send.rs:20:40 - | -LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { - | ^^^^ has type `&std::cell::Cell` which is not `Send` - = note: `std::cell::Cell` doesn't implement `std::marker::Sync` - -error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:24:43 - | -LL | pub async fn public_future2(rc: Rc<[u8]>) {} - | ^ future returned by `public_future2` is not `Send` - | -note: captured value is not `Send` - --> $DIR/future_not_send.rs:24:29 - | -LL | pub async fn public_future2(rc: Rc<[u8]>) {} - | ^^ has type `std::rc::Rc<[u8]>` which is not `Send` - = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` - -error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:35:39 - | -LL | async fn private_future(&self) -> usize { - | ^^^^^ future returned by `private_future` is not `Send` - | -note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:36:9 - | -LL | async fn private_future(&self) -> usize { - | ----- has type `&Dummy` which is not `Send` -LL | async { true }.await; - | ^^^^^^^^^^^^^^^^^^^^ await occurs here, with `&self` maybe used later -LL | self.rc.len() -LL | } - | - `&self` is later dropped here - = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` - -error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:40:39 - | -LL | pub async fn public_future(&self) { - | ^ future returned by `public_future` is not `Send` - | -note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:41:9 - | -LL | pub async fn public_future(&self) { - | ----- has type `&Dummy` which is not `Send` -LL | self.private_future().await; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ await occurs here, with `&self` maybe used later -LL | } - | - `&self` is later dropped here - = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` - -error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:50:37 - | -LL | async fn generic_future(t: T) -> T - | ^ future returned by `generic_future` is not `Send` - | -note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:55:5 - | -LL | let rt = &t; - | -- has type `&T` which is not `Send` -LL | async { true }.await; - | ^^^^^^^^^^^^^^^^^^^^ await occurs here, with `rt` maybe used later -LL | t -LL | } - | - `rt` is later dropped here - = note: `T` doesn't implement `std::marker::Sync` - -error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:66:34 - | -LL | async fn unclear_future(t: T) {} - | ^ future returned by `unclear_future` is not `Send` - | -note: captured value is not `Send` - --> $DIR/future_not_send.rs:66:28 - | -LL | async fn unclear_future(t: T) {} - | ^ has type `T` which is not `Send` - = note: `T` doesn't implement `std::marker::Send` - -error: aborting due to 8 previous errors - diff --git a/tests/ui/get_last_with_len.fixed b/tests/ui/get_last_with_len.fixed deleted file mode 100644 index c8b363f9c38e..000000000000 --- a/tests/ui/get_last_with_len.fixed +++ /dev/null @@ -1,31 +0,0 @@ -// run-rustfix - -#![warn(clippy::get_last_with_len)] - -fn dont_use_last() { - let x = vec![2, 3, 5]; - let _ = x.last(); // ~ERROR Use x.last() -} - -fn indexing_two_from_end() { - let x = vec![2, 3, 5]; - let _ = x.get(x.len() - 2); -} - -fn index_into_last() { - let x = vec![2, 3, 5]; - let _ = x[x.len() - 1]; -} - -fn use_last_with_different_vec_length() { - let x = vec![2, 3, 5]; - let y = vec!['a', 'b', 'c']; - let _ = x.get(y.len() - 1); -} - -fn main() { - dont_use_last(); - indexing_two_from_end(); - index_into_last(); - use_last_with_different_vec_length(); -} diff --git a/tests/ui/get_last_with_len.rs b/tests/ui/get_last_with_len.rs deleted file mode 100644 index bf9cb2d7e0cc..000000000000 --- a/tests/ui/get_last_with_len.rs +++ /dev/null @@ -1,31 +0,0 @@ -// run-rustfix - -#![warn(clippy::get_last_with_len)] - -fn dont_use_last() { - let x = vec![2, 3, 5]; - let _ = x.get(x.len() - 1); // ~ERROR Use x.last() -} - -fn indexing_two_from_end() { - let x = vec![2, 3, 5]; - let _ = x.get(x.len() - 2); -} - -fn index_into_last() { - let x = vec![2, 3, 5]; - let _ = x[x.len() - 1]; -} - -fn use_last_with_different_vec_length() { - let x = vec![2, 3, 5]; - let y = vec!['a', 'b', 'c']; - let _ = x.get(y.len() - 1); -} - -fn main() { - dont_use_last(); - indexing_two_from_end(); - index_into_last(); - use_last_with_different_vec_length(); -} diff --git a/tests/ui/get_last_with_len.stderr b/tests/ui/get_last_with_len.stderr deleted file mode 100644 index 55baf87384a2..000000000000 --- a/tests/ui/get_last_with_len.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: accessing last element with `x.get(x.len() - 1)` - --> $DIR/get_last_with_len.rs:7:13 - | -LL | let _ = x.get(x.len() - 1); // ~ERROR Use x.last() - | ^^^^^^^^^^^^^^^^^^ help: try: `x.last()` - | - = note: `-D clippy::get-last-with-len` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/get_unwrap.fixed b/tests/ui/get_unwrap.fixed deleted file mode 100644 index 924c02a4054d..000000000000 --- a/tests/ui/get_unwrap.fixed +++ /dev/null @@ -1,62 +0,0 @@ -// run-rustfix -#![allow(unused_mut, clippy::from_iter_instead_of_collect)] -#![deny(clippy::get_unwrap)] - -use std::collections::BTreeMap; -use std::collections::HashMap; -use std::collections::VecDeque; -use std::iter::FromIterator; - -struct GetFalsePositive { - arr: [u32; 3], -} - -impl GetFalsePositive { - fn get(&self, pos: usize) -> Option<&u32> { - self.arr.get(pos) - } - fn get_mut(&mut self, pos: usize) -> Option<&mut u32> { - self.arr.get_mut(pos) - } -} - -fn main() { - let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); - let mut some_slice = &mut [0, 1, 2, 3]; - let mut some_vec = vec![0, 1, 2, 3]; - let mut some_vecdeque: VecDeque<_> = some_vec.iter().cloned().collect(); - let mut some_hashmap: HashMap = HashMap::from_iter(vec![(1, 'a'), (2, 'b')]); - let mut some_btreemap: BTreeMap = BTreeMap::from_iter(vec![(1, 'a'), (2, 'b')]); - let mut false_positive = GetFalsePositive { arr: [0, 1, 2] }; - - { - // Test `get().unwrap()` - let _ = &boxed_slice[1]; - let _ = &some_slice[0]; - let _ = &some_vec[0]; - let _ = &some_vecdeque[0]; - let _ = &some_hashmap[&1]; - let _ = &some_btreemap[&1]; - let _ = false_positive.get(0).unwrap(); - // Test with deref - let _: u8 = boxed_slice[1]; - } - - { - // Test `get_mut().unwrap()` - boxed_slice[0] = 1; - some_slice[0] = 1; - some_vec[0] = 1; - some_vecdeque[0] = 1; - // Check false positives - *some_hashmap.get_mut(&1).unwrap() = 'b'; - *some_btreemap.get_mut(&1).unwrap() = 'b'; - *false_positive.get_mut(0).unwrap() = 1; - } - - { - // Test `get().unwrap().foo()` and `get_mut().unwrap().bar()` - let _ = some_vec[0..1].to_vec(); - let _ = some_vec[0..1].to_vec(); - } -} diff --git a/tests/ui/get_unwrap.rs b/tests/ui/get_unwrap.rs deleted file mode 100644 index c0c37bb72066..000000000000 --- a/tests/ui/get_unwrap.rs +++ /dev/null @@ -1,62 +0,0 @@ -// run-rustfix -#![allow(unused_mut, clippy::from_iter_instead_of_collect)] -#![deny(clippy::get_unwrap)] - -use std::collections::BTreeMap; -use std::collections::HashMap; -use std::collections::VecDeque; -use std::iter::FromIterator; - -struct GetFalsePositive { - arr: [u32; 3], -} - -impl GetFalsePositive { - fn get(&self, pos: usize) -> Option<&u32> { - self.arr.get(pos) - } - fn get_mut(&mut self, pos: usize) -> Option<&mut u32> { - self.arr.get_mut(pos) - } -} - -fn main() { - let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); - let mut some_slice = &mut [0, 1, 2, 3]; - let mut some_vec = vec![0, 1, 2, 3]; - let mut some_vecdeque: VecDeque<_> = some_vec.iter().cloned().collect(); - let mut some_hashmap: HashMap = HashMap::from_iter(vec![(1, 'a'), (2, 'b')]); - let mut some_btreemap: BTreeMap = BTreeMap::from_iter(vec![(1, 'a'), (2, 'b')]); - let mut false_positive = GetFalsePositive { arr: [0, 1, 2] }; - - { - // Test `get().unwrap()` - let _ = boxed_slice.get(1).unwrap(); - let _ = some_slice.get(0).unwrap(); - let _ = some_vec.get(0).unwrap(); - let _ = some_vecdeque.get(0).unwrap(); - let _ = some_hashmap.get(&1).unwrap(); - let _ = some_btreemap.get(&1).unwrap(); - let _ = false_positive.get(0).unwrap(); - // Test with deref - let _: u8 = *boxed_slice.get(1).unwrap(); - } - - { - // Test `get_mut().unwrap()` - *boxed_slice.get_mut(0).unwrap() = 1; - *some_slice.get_mut(0).unwrap() = 1; - *some_vec.get_mut(0).unwrap() = 1; - *some_vecdeque.get_mut(0).unwrap() = 1; - // Check false positives - *some_hashmap.get_mut(&1).unwrap() = 'b'; - *some_btreemap.get_mut(&1).unwrap() = 'b'; - *false_positive.get_mut(0).unwrap() = 1; - } - - { - // Test `get().unwrap().foo()` and `get_mut().unwrap().bar()` - let _ = some_vec.get(0..1).unwrap().to_vec(); - let _ = some_vec.get_mut(0..1).unwrap().to_vec(); - } -} diff --git a/tests/ui/get_unwrap.stderr b/tests/ui/get_unwrap.stderr deleted file mode 100644 index 76a098df82aa..000000000000 --- a/tests/ui/get_unwrap.stderr +++ /dev/null @@ -1,86 +0,0 @@ -error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:34:17 - | -LL | let _ = boxed_slice.get(1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&boxed_slice[1]` - | -note: the lint level is defined here - --> $DIR/get_unwrap.rs:3:9 - | -LL | #![deny(clippy::get_unwrap)] - | ^^^^^^^^^^^^^^^^^^ - -error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:35:17 - | -LL | let _ = some_slice.get(0).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_slice[0]` - -error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:36:17 - | -LL | let _ = some_vec.get(0).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vec[0]` - -error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:37:17 - | -LL | let _ = some_vecdeque.get(0).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vecdeque[0]` - -error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:38:17 - | -LL | let _ = some_hashmap.get(&1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_hashmap[&1]` - -error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:39:17 - | -LL | let _ = some_btreemap.get(&1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_btreemap[&1]` - -error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:42:21 - | -LL | let _: u8 = *boxed_slice.get(1).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[1]` - -error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:47:9 - | -LL | *boxed_slice.get_mut(0).unwrap() = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[0]` - -error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:48:9 - | -LL | *some_slice.get_mut(0).unwrap() = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_slice[0]` - -error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:49:9 - | -LL | *some_vec.get_mut(0).unwrap() = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0]` - -error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:50:9 - | -LL | *some_vecdeque.get_mut(0).unwrap() = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vecdeque[0]` - -error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:59:17 - | -LL | let _ = some_vec.get(0..1).unwrap().to_vec(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]` - -error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:60:17 - | -LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]` - -error: aborting due to 13 previous errors - diff --git a/tests/ui/identity_op.rs b/tests/ui/identity_op.rs deleted file mode 100644 index ceaacaaf6bd7..000000000000 --- a/tests/ui/identity_op.rs +++ /dev/null @@ -1,41 +0,0 @@ -const ONE: i64 = 1; -const NEG_ONE: i64 = -1; -const ZERO: i64 = 0; - -#[allow( - clippy::eq_op, - clippy::no_effect, - clippy::unnecessary_operation, - clippy::double_parens -)] -#[warn(clippy::identity_op)] -#[rustfmt::skip] -fn main() { - let x = 0; - - x + 0; - x + (1 - 1); - x + 1; - 0 + x; - 1 + x; - x - ZERO; //no error, as we skip lookups (for now) - x | (0); - ((ZERO)) | x; //no error, as we skip lookups (for now) - - x * 1; - 1 * x; - x / ONE; //no error, as we skip lookups (for now) - - x / 2; //no false positive - - x & NEG_ONE; //no error, as we skip lookups (for now) - -1 & x; - - let u: u8 = 0; - u & 255; - - 1 << 0; // no error, this case is allowed, see issue 3430 - 42 << 0; - 1 >> 0; - 42 >> 0; -} diff --git a/tests/ui/identity_op.stderr b/tests/ui/identity_op.stderr deleted file mode 100644 index d8d44a74f9ab..000000000000 --- a/tests/ui/identity_op.stderr +++ /dev/null @@ -1,70 +0,0 @@ -error: the operation is ineffective. Consider reducing it to `x` - --> $DIR/identity_op.rs:16:5 - | -LL | x + 0; - | ^^^^^ - | - = note: `-D clippy::identity-op` implied by `-D warnings` - -error: the operation is ineffective. Consider reducing it to `x` - --> $DIR/identity_op.rs:17:5 - | -LL | x + (1 - 1); - | ^^^^^^^^^^^ - -error: the operation is ineffective. Consider reducing it to `x` - --> $DIR/identity_op.rs:19:5 - | -LL | 0 + x; - | ^^^^^ - -error: the operation is ineffective. Consider reducing it to `x` - --> $DIR/identity_op.rs:22:5 - | -LL | x | (0); - | ^^^^^^^ - -error: the operation is ineffective. Consider reducing it to `x` - --> $DIR/identity_op.rs:25:5 - | -LL | x * 1; - | ^^^^^ - -error: the operation is ineffective. Consider reducing it to `x` - --> $DIR/identity_op.rs:26:5 - | -LL | 1 * x; - | ^^^^^ - -error: the operation is ineffective. Consider reducing it to `x` - --> $DIR/identity_op.rs:32:5 - | -LL | -1 & x; - | ^^^^^^ - -error: the operation is ineffective. Consider reducing it to `u` - --> $DIR/identity_op.rs:35:5 - | -LL | u & 255; - | ^^^^^^^ - -error: the operation is ineffective. Consider reducing it to `42` - --> $DIR/identity_op.rs:38:5 - | -LL | 42 << 0; - | ^^^^^^^ - -error: the operation is ineffective. Consider reducing it to `1` - --> $DIR/identity_op.rs:39:5 - | -LL | 1 >> 0; - | ^^^^^^ - -error: the operation is ineffective. Consider reducing it to `42` - --> $DIR/identity_op.rs:40:5 - | -LL | 42 >> 0; - | ^^^^^^^ - -error: aborting due to 11 previous errors - diff --git a/tests/ui/if_let_mutex.rs b/tests/ui/if_let_mutex.rs deleted file mode 100644 index 58feae422a3c..000000000000 --- a/tests/ui/if_let_mutex.rs +++ /dev/null @@ -1,42 +0,0 @@ -#![warn(clippy::if_let_mutex)] - -use std::ops::Deref; -use std::sync::Mutex; - -fn do_stuff(_: T) {} - -fn if_let() { - let m = Mutex::new(1_u8); - if let Err(locked) = m.lock() { - do_stuff(locked); - } else { - let lock = m.lock().unwrap(); - do_stuff(lock); - }; -} - -// This is the most common case as the above case is pretty -// contrived. -fn if_let_option() { - let m = Mutex::new(Some(0_u8)); - if let Some(locked) = m.lock().unwrap().deref() { - do_stuff(locked); - } else { - let lock = m.lock().unwrap(); - do_stuff(lock); - }; -} - -// When mutexs are different don't warn -fn if_let_different_mutex() { - let m = Mutex::new(Some(0_u8)); - let other = Mutex::new(None::); - if let Some(locked) = m.lock().unwrap().deref() { - do_stuff(locked); - } else { - let lock = other.lock().unwrap(); - do_stuff(lock); - }; -} - -fn main() {} diff --git a/tests/ui/if_let_mutex.stderr b/tests/ui/if_let_mutex.stderr deleted file mode 100644 index e9c4d9163328..000000000000 --- a/tests/ui/if_let_mutex.stderr +++ /dev/null @@ -1,29 +0,0 @@ -error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock - --> $DIR/if_let_mutex.rs:10:5 - | -LL | / if let Err(locked) = m.lock() { -LL | | do_stuff(locked); -LL | | } else { -LL | | let lock = m.lock().unwrap(); -LL | | do_stuff(lock); -LL | | }; - | |_____^ - | - = note: `-D clippy::if-let-mutex` implied by `-D warnings` - = help: move the lock call outside of the `if let ...` expression - -error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock - --> $DIR/if_let_mutex.rs:22:5 - | -LL | / if let Some(locked) = m.lock().unwrap().deref() { -LL | | do_stuff(locked); -LL | | } else { -LL | | let lock = m.lock().unwrap(); -LL | | do_stuff(lock); -LL | | }; - | |_____^ - | - = help: move the lock call outside of the `if let ...` expression - -error: aborting due to 2 previous errors - diff --git a/tests/ui/if_let_some_result.fixed b/tests/ui/if_let_some_result.fixed deleted file mode 100644 index 80505fd997f4..000000000000 --- a/tests/ui/if_let_some_result.fixed +++ /dev/null @@ -1,35 +0,0 @@ -// run-rustfix - -#![warn(clippy::if_let_some_result)] - -fn str_to_int(x: &str) -> i32 { - if let Ok(y) = x.parse() { - y - } else { - 0 - } -} - -fn str_to_int_ok(x: &str) -> i32 { - if let Ok(y) = x.parse() { - y - } else { - 0 - } -} - -#[rustfmt::skip] -fn strange_some_no_else(x: &str) -> i32 { - { - if let Ok(y) = x . parse() { - return y; - }; - 0 - } -} - -fn main() { - let _ = str_to_int("1"); - let _ = str_to_int_ok("2"); - let _ = strange_some_no_else("3"); -} diff --git a/tests/ui/if_let_some_result.rs b/tests/ui/if_let_some_result.rs deleted file mode 100644 index ecac13574456..000000000000 --- a/tests/ui/if_let_some_result.rs +++ /dev/null @@ -1,35 +0,0 @@ -// run-rustfix - -#![warn(clippy::if_let_some_result)] - -fn str_to_int(x: &str) -> i32 { - if let Some(y) = x.parse().ok() { - y - } else { - 0 - } -} - -fn str_to_int_ok(x: &str) -> i32 { - if let Ok(y) = x.parse() { - y - } else { - 0 - } -} - -#[rustfmt::skip] -fn strange_some_no_else(x: &str) -> i32 { - { - if let Some(y) = x . parse() . ok () { - return y; - }; - 0 - } -} - -fn main() { - let _ = str_to_int("1"); - let _ = str_to_int_ok("2"); - let _ = strange_some_no_else("3"); -} diff --git a/tests/ui/if_let_some_result.stderr b/tests/ui/if_let_some_result.stderr deleted file mode 100644 index 6afee0f36b9d..000000000000 --- a/tests/ui/if_let_some_result.stderr +++ /dev/null @@ -1,25 +0,0 @@ -error: matching on `Some` with `ok()` is redundant - --> $DIR/if_let_some_result.rs:6:5 - | -LL | if let Some(y) = x.parse().ok() { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::if-let-some-result` implied by `-D warnings` -help: consider matching on `Ok(y)` and removing the call to `ok` instead - | -LL | if let Ok(y) = x.parse() { - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: matching on `Some` with `ok()` is redundant - --> $DIR/if_let_some_result.rs:24:9 - | -LL | if let Some(y) = x . parse() . ok () { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider matching on `Ok(y)` and removing the call to `ok` instead - | -LL | if let Ok(y) = x . parse() { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/if_not_else.rs b/tests/ui/if_not_else.rs deleted file mode 100644 index dc3fb1ceac9a..000000000000 --- a/tests/ui/if_not_else.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![warn(clippy::all)] -#![warn(clippy::if_not_else)] - -fn bla() -> bool { - unimplemented!() -} - -fn main() { - if !bla() { - println!("Bugs"); - } else { - println!("Bunny"); - } - if 4 != 5 { - println!("Bugs"); - } else { - println!("Bunny"); - } -} diff --git a/tests/ui/if_not_else.stderr b/tests/ui/if_not_else.stderr deleted file mode 100644 index 53d1b86d02a9..000000000000 --- a/tests/ui/if_not_else.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error: unnecessary boolean `not` operation - --> $DIR/if_not_else.rs:9:5 - | -LL | / if !bla() { -LL | | println!("Bugs"); -LL | | } else { -LL | | println!("Bunny"); -LL | | } - | |_____^ - | - = note: `-D clippy::if-not-else` implied by `-D warnings` - = help: remove the `!` and swap the blocks of the `if`/`else` - -error: unnecessary `!=` operation - --> $DIR/if_not_else.rs:14:5 - | -LL | / if 4 != 5 { -LL | | println!("Bugs"); -LL | | } else { -LL | | println!("Bunny"); -LL | | } - | |_____^ - | - = help: change to `==` and swap the blocks of the `if`/`else` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/if_same_then_else.rs b/tests/ui/if_same_then_else.rs deleted file mode 100644 index 9c5fe02f7519..000000000000 --- a/tests/ui/if_same_then_else.rs +++ /dev/null @@ -1,157 +0,0 @@ -#![warn(clippy::if_same_then_else)] -#![allow( - clippy::blacklisted_name, - clippy::eq_op, - clippy::never_loop, - clippy::no_effect, - clippy::unused_unit, - clippy::zero_divided_by_zero -)] - -struct Foo { - bar: u8, -} - -fn foo() -> bool { - unimplemented!() -} - -fn if_same_then_else() { - if true { - Foo { bar: 42 }; - 0..10; - ..; - 0..; - ..10; - 0..=10; - foo(); - } else { - //~ ERROR same body as `if` block - Foo { bar: 42 }; - 0..10; - ..; - 0..; - ..10; - 0..=10; - foo(); - } - - if true { - Foo { bar: 42 }; - } else { - Foo { bar: 43 }; - } - - if true { - (); - } else { - () - } - - if true { - 0..10; - } else { - 0..=10; - } - - if true { - foo(); - foo(); - } else { - foo(); - } - - let _ = if true { - 0.0 - } else { - //~ ERROR same body as `if` block - 0.0 - }; - - let _ = if true { - -0.0 - } else { - //~ ERROR same body as `if` block - -0.0 - }; - - let _ = if true { 0.0 } else { -0.0 }; - - // Different NaNs - let _ = if true { 0.0 / 0.0 } else { f32::NAN }; - - if true { - foo(); - } - - let _ = if true { - 42 - } else { - //~ ERROR same body as `if` block - 42 - }; - - if true { - let bar = if true { 42 } else { 43 }; - - while foo() { - break; - } - bar + 1; - } else { - //~ ERROR same body as `if` block - let bar = if true { 42 } else { 43 }; - - while foo() { - break; - } - bar + 1; - } - - if true { - let _ = match 42 { - 42 => 1, - a if a > 0 => 2, - 10..=15 => 3, - _ => 4, - }; - } else if false { - foo(); - } else if foo() { - let _ = match 42 { - 42 => 1, - a if a > 0 => 2, - 10..=15 => 3, - _ => 4, - }; - } -} - -// Issue #2423. This was causing an ICE. -fn func() { - if true { - f(&[0; 62]); - f(&[0; 4]); - f(&[0; 3]); - } else { - f(&[0; 62]); - f(&[0; 6]); - f(&[0; 6]); - } -} - -fn f(val: &[u8]) {} - -mod issue_5698 { - fn mul_not_always_commutative(x: i32, y: i32) -> i32 { - if x == 42 { - x * y - } else if x == 21 { - y * x - } else { - 0 - } - } -} - -fn main() {} diff --git a/tests/ui/if_same_then_else.stderr b/tests/ui/if_same_then_else.stderr deleted file mode 100644 index d9fdf06fa8b7..000000000000 --- a/tests/ui/if_same_then_else.stderr +++ /dev/null @@ -1,112 +0,0 @@ -error: this `if` has identical blocks - --> $DIR/if_same_then_else.rs:28:12 - | -LL | } else { - | ____________^ -LL | | //~ ERROR same body as `if` block -LL | | Foo { bar: 42 }; -LL | | 0..10; -... | -LL | | foo(); -LL | | } - | |_____^ - | - = note: `-D clippy::if-same-then-else` implied by `-D warnings` -note: same as this - --> $DIR/if_same_then_else.rs:20:13 - | -LL | if true { - | _____________^ -LL | | Foo { bar: 42 }; -LL | | 0..10; -LL | | ..; -... | -LL | | foo(); -LL | | } else { - | |_____^ - -error: this `if` has identical blocks - --> $DIR/if_same_then_else.rs:66:12 - | -LL | } else { - | ____________^ -LL | | //~ ERROR same body as `if` block -LL | | 0.0 -LL | | }; - | |_____^ - | -note: same as this - --> $DIR/if_same_then_else.rs:64:21 - | -LL | let _ = if true { - | _____________________^ -LL | | 0.0 -LL | | } else { - | |_____^ - -error: this `if` has identical blocks - --> $DIR/if_same_then_else.rs:73:12 - | -LL | } else { - | ____________^ -LL | | //~ ERROR same body as `if` block -LL | | -0.0 -LL | | }; - | |_____^ - | -note: same as this - --> $DIR/if_same_then_else.rs:71:21 - | -LL | let _ = if true { - | _____________________^ -LL | | -0.0 -LL | | } else { - | |_____^ - -error: this `if` has identical blocks - --> $DIR/if_same_then_else.rs:89:12 - | -LL | } else { - | ____________^ -LL | | //~ ERROR same body as `if` block -LL | | 42 -LL | | }; - | |_____^ - | -note: same as this - --> $DIR/if_same_then_else.rs:87:21 - | -LL | let _ = if true { - | _____________________^ -LL | | 42 -LL | | } else { - | |_____^ - -error: this `if` has identical blocks - --> $DIR/if_same_then_else.rs:101:12 - | -LL | } else { - | ____________^ -LL | | //~ ERROR same body as `if` block -LL | | let bar = if true { 42 } else { 43 }; -LL | | -... | -LL | | bar + 1; -LL | | } - | |_____^ - | -note: same as this - --> $DIR/if_same_then_else.rs:94:13 - | -LL | if true { - | _____________^ -LL | | let bar = if true { 42 } else { 43 }; -LL | | -LL | | while foo() { -... | -LL | | bar + 1; -LL | | } else { - | |_____^ - -error: aborting due to 5 previous errors - diff --git a/tests/ui/if_same_then_else2.rs b/tests/ui/if_same_then_else2.rs deleted file mode 100644 index 8d54f75b5d19..000000000000 --- a/tests/ui/if_same_then_else2.rs +++ /dev/null @@ -1,140 +0,0 @@ -#![warn(clippy::if_same_then_else)] -#![allow( - clippy::blacklisted_name, - clippy::collapsible_if, - clippy::ifs_same_cond, - clippy::needless_return, - clippy::single_element_loop -)] - -fn if_same_then_else2() -> Result<&'static str, ()> { - if true { - for _ in &[42] { - let foo: &Option<_> = &Some::(42); - if true { - break; - } else { - continue; - } - } - } else { - //~ ERROR same body as `if` block - for _ in &[42] { - let foo: &Option<_> = &Some::(42); - if true { - break; - } else { - continue; - } - } - } - - if true { - if let Some(a) = Some(42) {} - } else { - //~ ERROR same body as `if` block - if let Some(a) = Some(42) {} - } - - if true { - if let (1, .., 3) = (1, 2, 3) {} - } else { - //~ ERROR same body as `if` block - if let (1, .., 3) = (1, 2, 3) {} - } - - if true { - if let (1, .., 3) = (1, 2, 3) {} - } else { - if let (.., 3) = (1, 2, 3) {} - } - - if true { - if let (1, .., 3) = (1, 2, 3) {} - } else { - if let (.., 4) = (1, 2, 3) {} - } - - if true { - if let (1, .., 3) = (1, 2, 3) {} - } else { - if let (.., 1, 3) = (1, 2, 3) {} - } - - if true { - if let Some(42) = None {} - } else { - if let Option::Some(42) = None {} - } - - if true { - if let Some(42) = None:: {} - } else { - if let Some(42) = None {} - } - - if true { - if let Some(42) = None:: {} - } else { - if let Some(42) = None:: {} - } - - if true { - if let Some(a) = Some(42) {} - } else { - if let Some(a) = Some(43) {} - } - - // Same NaNs - let _ = if true { - f32::NAN - } else { - //~ ERROR same body as `if` block - f32::NAN - }; - - if true { - Ok("foo")?; - } else { - //~ ERROR same body as `if` block - Ok("foo")?; - } - - if true { - let foo = ""; - return Ok(&foo[0..]); - } else if false { - let foo = "bar"; - return Ok(&foo[0..]); - } else { - let foo = ""; - return Ok(&foo[0..]); - } - - if true { - let foo = ""; - return Ok(&foo[0..]); - } else if false { - let foo = "bar"; - return Ok(&foo[0..]); - } else if true { - let foo = ""; - return Ok(&foo[0..]); - } else { - let foo = ""; - return Ok(&foo[0..]); - } - - // False positive `if_same_then_else`: `let (x, y)` vs. `let (y, x)`; see issue #3559. - if true { - let foo = ""; - let (x, y) = (1, 2); - return Ok(&foo[x..y]); - } else { - let foo = ""; - let (y, x) = (1, 2); - return Ok(&foo[x..y]); - } -} - -fn main() {} diff --git a/tests/ui/if_same_then_else2.stderr b/tests/ui/if_same_then_else2.stderr deleted file mode 100644 index da2be6c8aa5a..000000000000 --- a/tests/ui/if_same_then_else2.stderr +++ /dev/null @@ -1,125 +0,0 @@ -error: this `if` has identical blocks - --> $DIR/if_same_then_else2.rs:20:12 - | -LL | } else { - | ____________^ -LL | | //~ ERROR same body as `if` block -LL | | for _ in &[42] { -LL | | let foo: &Option<_> = &Some::(42); -... | -LL | | } -LL | | } - | |_____^ - | - = note: `-D clippy::if-same-then-else` implied by `-D warnings` -note: same as this - --> $DIR/if_same_then_else2.rs:11:13 - | -LL | if true { - | _____________^ -LL | | for _ in &[42] { -LL | | let foo: &Option<_> = &Some::(42); -LL | | if true { -... | -LL | | } -LL | | } else { - | |_____^ - -error: this `if` has identical blocks - --> $DIR/if_same_then_else2.rs:34:12 - | -LL | } else { - | ____________^ -LL | | //~ ERROR same body as `if` block -LL | | if let Some(a) = Some(42) {} -LL | | } - | |_____^ - | -note: same as this - --> $DIR/if_same_then_else2.rs:32:13 - | -LL | if true { - | _____________^ -LL | | if let Some(a) = Some(42) {} -LL | | } else { - | |_____^ - -error: this `if` has identical blocks - --> $DIR/if_same_then_else2.rs:41:12 - | -LL | } else { - | ____________^ -LL | | //~ ERROR same body as `if` block -LL | | if let (1, .., 3) = (1, 2, 3) {} -LL | | } - | |_____^ - | -note: same as this - --> $DIR/if_same_then_else2.rs:39:13 - | -LL | if true { - | _____________^ -LL | | if let (1, .., 3) = (1, 2, 3) {} -LL | | } else { - | |_____^ - -error: this `if` has identical blocks - --> $DIR/if_same_then_else2.rs:91:12 - | -LL | } else { - | ____________^ -LL | | //~ ERROR same body as `if` block -LL | | f32::NAN -LL | | }; - | |_____^ - | -note: same as this - --> $DIR/if_same_then_else2.rs:89:21 - | -LL | let _ = if true { - | _____________________^ -LL | | f32::NAN -LL | | } else { - | |_____^ - -error: this `if` has identical blocks - --> $DIR/if_same_then_else2.rs:98:12 - | -LL | } else { - | ____________^ -LL | | //~ ERROR same body as `if` block -LL | | Ok("foo")?; -LL | | } - | |_____^ - | -note: same as this - --> $DIR/if_same_then_else2.rs:96:13 - | -LL | if true { - | _____________^ -LL | | Ok("foo")?; -LL | | } else { - | |_____^ - -error: this `if` has identical blocks - --> $DIR/if_same_then_else2.rs:123:12 - | -LL | } else { - | ____________^ -LL | | let foo = ""; -LL | | return Ok(&foo[0..]); -LL | | } - | |_____^ - | -note: same as this - --> $DIR/if_same_then_else2.rs:120:20 - | -LL | } else if true { - | ____________________^ -LL | | let foo = ""; -LL | | return Ok(&foo[0..]); -LL | | } else { - | |_____^ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/ifs_same_cond.rs b/tests/ui/ifs_same_cond.rs deleted file mode 100644 index 80e9839ff40b..000000000000 --- a/tests/ui/ifs_same_cond.rs +++ /dev/null @@ -1,46 +0,0 @@ -#![warn(clippy::ifs_same_cond)] -#![allow(clippy::if_same_then_else, clippy::comparison_chain)] // all empty blocks - -fn ifs_same_cond() { - let a = 0; - let b = false; - - if b { - } else if b { - //~ ERROR ifs same condition - } - - if a == 1 { - } else if a == 1 { - //~ ERROR ifs same condition - } - - if 2 * a == 1 { - } else if 2 * a == 2 { - } else if 2 * a == 1 { - //~ ERROR ifs same condition - } else if a == 1 { - } - - // See #659 - if cfg!(feature = "feature1-659") { - 1 - } else if cfg!(feature = "feature2-659") { - 2 - } else { - 3 - }; - - let mut v = vec![1]; - if v.pop() == None { - // ok, functions - } else if v.pop() == None { - } - - if v.len() == 42 { - // ok, functions - } else if v.len() == 42 { - } -} - -fn main() {} diff --git a/tests/ui/ifs_same_cond.stderr b/tests/ui/ifs_same_cond.stderr deleted file mode 100644 index 0c8f49b8687f..000000000000 --- a/tests/ui/ifs_same_cond.stderr +++ /dev/null @@ -1,39 +0,0 @@ -error: this `if` has the same condition as a previous `if` - --> $DIR/ifs_same_cond.rs:9:15 - | -LL | } else if b { - | ^ - | - = note: `-D clippy::ifs-same-cond` implied by `-D warnings` -note: same as this - --> $DIR/ifs_same_cond.rs:8:8 - | -LL | if b { - | ^ - -error: this `if` has the same condition as a previous `if` - --> $DIR/ifs_same_cond.rs:14:15 - | -LL | } else if a == 1 { - | ^^^^^^ - | -note: same as this - --> $DIR/ifs_same_cond.rs:13:8 - | -LL | if a == 1 { - | ^^^^^^ - -error: this `if` has the same condition as a previous `if` - --> $DIR/ifs_same_cond.rs:20:15 - | -LL | } else if 2 * a == 1 { - | ^^^^^^^^^^ - | -note: same as this - --> $DIR/ifs_same_cond.rs:18:8 - | -LL | if 2 * a == 1 { - | ^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/impl.rs b/tests/ui/impl.rs deleted file mode 100644 index 1c46e3a53378..000000000000 --- a/tests/ui/impl.rs +++ /dev/null @@ -1,36 +0,0 @@ -#![allow(dead_code)] -#![warn(clippy::multiple_inherent_impl)] - -struct MyStruct; - -impl MyStruct { - fn first() {} -} - -impl MyStruct { - fn second() {} -} - -impl<'a> MyStruct { - fn lifetimed() {} -} - -mod submod { - struct MyStruct; - impl MyStruct { - fn other() {} - } - - impl super::MyStruct { - fn third() {} - } -} - -use std::fmt; -impl fmt::Debug for MyStruct { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "MyStruct {{ }}") - } -} - -fn main() {} diff --git a/tests/ui/impl.stderr b/tests/ui/impl.stderr deleted file mode 100644 index aab688cc2d8b..000000000000 --- a/tests/ui/impl.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error: multiple implementations of this structure - --> $DIR/impl.rs:10:1 - | -LL | / impl MyStruct { -LL | | fn second() {} -LL | | } - | |_^ - | - = note: `-D clippy::multiple-inherent-impl` implied by `-D warnings` -note: first implementation here - --> $DIR/impl.rs:6:1 - | -LL | / impl MyStruct { -LL | | fn first() {} -LL | | } - | |_^ - -error: multiple implementations of this structure - --> $DIR/impl.rs:24:5 - | -LL | / impl super::MyStruct { -LL | | fn third() {} -LL | | } - | |_____^ - | -note: first implementation here - --> $DIR/impl.rs:6:1 - | -LL | / impl MyStruct { -LL | | fn first() {} -LL | | } - | |_^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/implicit_hasher.rs b/tests/ui/implicit_hasher.rs deleted file mode 100644 index fdcc9a33f55f..000000000000 --- a/tests/ui/implicit_hasher.rs +++ /dev/null @@ -1,99 +0,0 @@ -// aux-build:implicit_hasher_macros.rs -#![deny(clippy::implicit_hasher)] -#![allow(unused)] - -#[macro_use] -extern crate implicit_hasher_macros; - -use std::cmp::Eq; -use std::collections::{HashMap, HashSet}; -use std::hash::{BuildHasher, Hash}; - -pub trait Foo: Sized { - fn make() -> (Self, Self); -} - -impl Foo for HashMap { - fn make() -> (Self, Self) { - // OK, don't suggest to modify these - let _: HashMap = HashMap::new(); - let _: HashSet = HashSet::new(); - - (HashMap::new(), HashMap::with_capacity(10)) - } -} -impl Foo for (HashMap,) { - fn make() -> (Self, Self) { - ((HashMap::new(),), (HashMap::with_capacity(10),)) - } -} -impl Foo for HashMap { - fn make() -> (Self, Self) { - (HashMap::new(), HashMap::with_capacity(10)) - } -} - -impl Foo for HashMap { - fn make() -> (Self, Self) { - (HashMap::default(), HashMap::with_capacity_and_hasher(10, S::default())) - } -} -impl Foo for HashMap { - fn make() -> (Self, Self) { - (HashMap::default(), HashMap::with_capacity_and_hasher(10, S::default())) - } -} - -impl Foo for HashSet { - fn make() -> (Self, Self) { - (HashSet::new(), HashSet::with_capacity(10)) - } -} -impl Foo for HashSet { - fn make() -> (Self, Self) { - (HashSet::new(), HashSet::with_capacity(10)) - } -} - -impl Foo for HashSet { - fn make() -> (Self, Self) { - (HashSet::default(), HashSet::with_capacity_and_hasher(10, S::default())) - } -} -impl Foo for HashSet { - fn make() -> (Self, Self) { - (HashSet::default(), HashSet::with_capacity_and_hasher(10, S::default())) - } -} - -pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} - -macro_rules! gen { - (impl) => { - impl Foo for HashMap { - fn make() -> (Self, Self) { - (HashMap::new(), HashMap::with_capacity(10)) - } - } - }; - - (fn $name:ident) => { - pub fn $name(_map: &mut HashMap, _set: &mut HashSet) {} - }; -} -#[rustfmt::skip] -gen!(impl); -gen!(fn bar); - -// When the macro is in a different file, the suggestion spans can't be combined properly -// and should not cause an ICE -// See #2707 -#[macro_use] -#[path = "../auxiliary/test_macro.rs"] -pub mod test_macro; -__implicit_hasher_test_macro!(impl for HashMap where V: test_macro::A); - -// #4260 -implicit_hasher_fn!(); - -fn main() {} diff --git a/tests/ui/implicit_hasher.stderr b/tests/ui/implicit_hasher.stderr deleted file mode 100644 index 2b06d661772d..000000000000 --- a/tests/ui/implicit_hasher.stderr +++ /dev/null @@ -1,153 +0,0 @@ -error: impl for `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:16:35 - | -LL | impl Foo for HashMap { - | ^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/implicit_hasher.rs:2:9 - | -LL | #![deny(clippy::implicit_hasher)] - | ^^^^^^^^^^^^^^^^^^^^^^^ -help: consider adding a type parameter - | -LL | impl Foo for HashMap { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ -help: ...and use generic constructor - | -LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) - | ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: impl for `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:25:36 - | -LL | impl Foo for (HashMap,) { - | ^^^^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | impl Foo for (HashMap,) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ -help: ...and use generic constructor - | -LL | ((HashMap::default(),), (HashMap::with_capacity_and_hasher(10, Default::default()),)) - | ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: impl for `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:30:19 - | -LL | impl Foo for HashMap { - | ^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | impl Foo for HashMap { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: ...and use generic constructor - | -LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) - | ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: impl for `HashSet` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:47:32 - | -LL | impl Foo for HashSet { - | ^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | impl Foo for HashSet { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^ -help: ...and use generic constructor - | -LL | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) - | ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: impl for `HashSet` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:52:19 - | -LL | impl Foo for HashSet { - | ^^^^^^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | impl Foo for HashSet { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ -help: ...and use generic constructor - | -LL | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) - | ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: parameter of type `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:69:23 - | -LL | pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ - -error: parameter of type `HashSet` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:69:53 - | -LL | pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ - -error: impl for `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:73:43 - | -LL | impl Foo for HashMap { - | ^^^^^^^^^^^^^ -... -LL | gen!(impl); - | ----------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider adding a type parameter - | -LL | impl Foo for HashMap { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ -help: ...and use generic constructor - | -LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) - | ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: parameter of type `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:81:33 - | -LL | pub fn $name(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^^^^^^ -... -LL | gen!(fn bar); - | ------------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider adding a type parameter - | -LL | pub fn $name(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ - -error: parameter of type `HashSet` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:81:63 - | -LL | pub fn $name(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^ -... -LL | gen!(fn bar); - | ------------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider adding a type parameter - | -LL | pub fn $name(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ - -error: aborting due to 10 previous errors - diff --git a/tests/ui/implicit_return.fixed b/tests/ui/implicit_return.fixed deleted file mode 100644 index 9066dc3fedfd..000000000000 --- a/tests/ui/implicit_return.fixed +++ /dev/null @@ -1,101 +0,0 @@ -// run-rustfix - -#![warn(clippy::implicit_return)] -#![allow(clippy::needless_return, unused)] - -fn test_end_of_fn() -> bool { - if true { - // no error! - return true; - } - - return true -} - -#[allow(clippy::needless_bool)] -fn test_if_block() -> bool { - if true { - return true - } else { - return false - } -} - -#[rustfmt::skip] -fn test_match(x: bool) -> bool { - match x { - true => return false, - false => { return true }, - } -} - -#[allow(clippy::needless_return)] -fn test_match_with_unreachable(x: bool) -> bool { - match x { - true => return false, - false => unreachable!(), - } -} - -#[allow(clippy::never_loop)] -fn test_loop() -> bool { - loop { - return true; - } -} - -#[allow(clippy::never_loop)] -fn test_loop_with_block() -> bool { - loop { - { - return true; - } - } -} - -#[allow(clippy::never_loop)] -fn test_loop_with_nests() -> bool { - loop { - if true { - return true; - } else { - let _ = true; - } - } -} - -#[allow(clippy::redundant_pattern_matching)] -fn test_loop_with_if_let() -> bool { - loop { - if let Some(x) = Some(true) { - return x; - } - } -} - -fn test_closure() { - #[rustfmt::skip] - let _ = || { return true }; - let _ = || return true; -} - -fn test_panic() -> bool { - panic!() -} - -fn test_return_macro() -> String { - return format!("test {}", "test") -} - -fn main() { - let _ = test_end_of_fn(); - let _ = test_if_block(); - let _ = test_match(true); - let _ = test_match_with_unreachable(true); - let _ = test_loop(); - let _ = test_loop_with_block(); - let _ = test_loop_with_nests(); - let _ = test_loop_with_if_let(); - test_closure(); - let _ = test_return_macro(); -} diff --git a/tests/ui/implicit_return.rs b/tests/ui/implicit_return.rs deleted file mode 100644 index c0d70ecf502e..000000000000 --- a/tests/ui/implicit_return.rs +++ /dev/null @@ -1,101 +0,0 @@ -// run-rustfix - -#![warn(clippy::implicit_return)] -#![allow(clippy::needless_return, unused)] - -fn test_end_of_fn() -> bool { - if true { - // no error! - return true; - } - - true -} - -#[allow(clippy::needless_bool)] -fn test_if_block() -> bool { - if true { - true - } else { - false - } -} - -#[rustfmt::skip] -fn test_match(x: bool) -> bool { - match x { - true => false, - false => { true }, - } -} - -#[allow(clippy::needless_return)] -fn test_match_with_unreachable(x: bool) -> bool { - match x { - true => return false, - false => unreachable!(), - } -} - -#[allow(clippy::never_loop)] -fn test_loop() -> bool { - loop { - break true; - } -} - -#[allow(clippy::never_loop)] -fn test_loop_with_block() -> bool { - loop { - { - break true; - } - } -} - -#[allow(clippy::never_loop)] -fn test_loop_with_nests() -> bool { - loop { - if true { - break true; - } else { - let _ = true; - } - } -} - -#[allow(clippy::redundant_pattern_matching)] -fn test_loop_with_if_let() -> bool { - loop { - if let Some(x) = Some(true) { - return x; - } - } -} - -fn test_closure() { - #[rustfmt::skip] - let _ = || { true }; - let _ = || true; -} - -fn test_panic() -> bool { - panic!() -} - -fn test_return_macro() -> String { - format!("test {}", "test") -} - -fn main() { - let _ = test_end_of_fn(); - let _ = test_if_block(); - let _ = test_match(true); - let _ = test_match_with_unreachable(true); - let _ = test_loop(); - let _ = test_loop_with_block(); - let _ = test_loop_with_nests(); - let _ = test_loop_with_if_let(); - test_closure(); - let _ = test_return_macro(); -} diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr deleted file mode 100644 index fb2ec9027645..000000000000 --- a/tests/ui/implicit_return.stderr +++ /dev/null @@ -1,70 +0,0 @@ -error: missing `return` statement - --> $DIR/implicit_return.rs:12:5 - | -LL | true - | ^^^^ help: add `return` as shown: `return true` - | - = note: `-D clippy::implicit-return` implied by `-D warnings` - -error: missing `return` statement - --> $DIR/implicit_return.rs:18:9 - | -LL | true - | ^^^^ help: add `return` as shown: `return true` - -error: missing `return` statement - --> $DIR/implicit_return.rs:20:9 - | -LL | false - | ^^^^^ help: add `return` as shown: `return false` - -error: missing `return` statement - --> $DIR/implicit_return.rs:27:17 - | -LL | true => false, - | ^^^^^ help: add `return` as shown: `return false` - -error: missing `return` statement - --> $DIR/implicit_return.rs:28:20 - | -LL | false => { true }, - | ^^^^ help: add `return` as shown: `return true` - -error: missing `return` statement - --> $DIR/implicit_return.rs:43:9 - | -LL | break true; - | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` - -error: missing `return` statement - --> $DIR/implicit_return.rs:51:13 - | -LL | break true; - | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` - -error: missing `return` statement - --> $DIR/implicit_return.rs:60:13 - | -LL | break true; - | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` - -error: missing `return` statement - --> $DIR/implicit_return.rs:78:18 - | -LL | let _ = || { true }; - | ^^^^ help: add `return` as shown: `return true` - -error: missing `return` statement - --> $DIR/implicit_return.rs:79:16 - | -LL | let _ = || true; - | ^^^^ help: add `return` as shown: `return true` - -error: missing `return` statement - --> $DIR/implicit_return.rs:87:5 - | -LL | format!("test {}", "test") - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")` - -error: aborting due to 11 previous errors - diff --git a/tests/ui/implicit_saturating_sub.fixed b/tests/ui/implicit_saturating_sub.fixed deleted file mode 100644 index 859765d08a70..000000000000 --- a/tests/ui/implicit_saturating_sub.fixed +++ /dev/null @@ -1,160 +0,0 @@ -// run-rustfix -#![allow(unused_assignments, unused_mut, clippy::assign_op_pattern)] -#![warn(clippy::implicit_saturating_sub)] - -fn main() { - // Tests for unsigned integers - - let end_8: u8 = 10; - let start_8: u8 = 5; - let mut u_8: u8 = end_8 - start_8; - - // Lint - u_8 = u_8.saturating_sub(1); - - match end_8 { - 10 => { - // Lint - u_8 = u_8.saturating_sub(1); - }, - 11 => u_8 += 1, - _ => u_8 = 0, - } - - let end_16: u16 = 40; - let start_16: u16 = 35; - - let mut u_16: u16 = end_16 - start_16; - - // Lint - u_16 = u_16.saturating_sub(1); - - let mut end_32: u32 = 7010; - let mut start_32: u32 = 7000; - - let mut u_32: u32 = end_32 - start_32; - - // Lint - u_32 = u_32.saturating_sub(1); - - // No Lint - if u_32 > 0 { - u_16 += 1; - } - - // No Lint - if u_32 != 0 { - end_32 -= 1; - start_32 += 1; - } - - let mut end_64: u64 = 75001; - let mut start_64: u64 = 75000; - - let mut u_64: u64 = end_64 - start_64; - - // Lint - u_64 = u_64.saturating_sub(1); - - // Lint - u_64 = u_64.saturating_sub(1); - - // Lint - u_64 = u_64.saturating_sub(1); - - // No Lint - if u_64 >= 1 { - u_64 -= 1; - } - - // No Lint - if u_64 > 0 { - end_64 -= 1; - } - - // Tests for usize - let end_usize: usize = 8054; - let start_usize: usize = 8050; - - let mut u_usize: usize = end_usize - start_usize; - - // Lint - u_usize = u_usize.saturating_sub(1); - - // Tests for signed integers - - let endi_8: i8 = 10; - let starti_8: i8 = 50; - - let mut i_8: i8 = endi_8 - starti_8; - - // Lint - i_8 = i_8.saturating_sub(1); - - // Lint - i_8 = i_8.saturating_sub(1); - - // Lint - i_8 = i_8.saturating_sub(1); - - // Lint - i_8 = i_8.saturating_sub(1); - - let endi_16: i16 = 45; - let starti_16: i16 = 44; - - let mut i_16: i16 = endi_16 - starti_16; - - // Lint - i_16 = i_16.saturating_sub(1); - - // Lint - i_16 = i_16.saturating_sub(1); - - // Lint - i_16 = i_16.saturating_sub(1); - - // Lint - i_16 = i_16.saturating_sub(1); - - let endi_32: i32 = 45; - let starti_32: i32 = 44; - - let mut i_32: i32 = endi_32 - starti_32; - - // Lint - i_32 = i_32.saturating_sub(1); - - // Lint - i_32 = i_32.saturating_sub(1); - - // Lint - i_32 = i_32.saturating_sub(1); - - // Lint - i_32 = i_32.saturating_sub(1); - - let endi_64: i64 = 45; - let starti_64: i64 = 44; - - let mut i_64: i64 = endi_64 - starti_64; - - // Lint - i_64 = i_64.saturating_sub(1); - - // Lint - i_64 = i_64.saturating_sub(1); - - // Lint - i_64 = i_64.saturating_sub(1); - - // No Lint - if i_64 > 0 { - i_64 -= 1; - } - - // No Lint - if i_64 != 0 { - i_64 -= 1; - } -} diff --git a/tests/ui/implicit_saturating_sub.rs b/tests/ui/implicit_saturating_sub.rs deleted file mode 100644 index 2f32a7b15782..000000000000 --- a/tests/ui/implicit_saturating_sub.rs +++ /dev/null @@ -1,206 +0,0 @@ -// run-rustfix -#![allow(unused_assignments, unused_mut, clippy::assign_op_pattern)] -#![warn(clippy::implicit_saturating_sub)] - -fn main() { - // Tests for unsigned integers - - let end_8: u8 = 10; - let start_8: u8 = 5; - let mut u_8: u8 = end_8 - start_8; - - // Lint - if u_8 > 0 { - u_8 = u_8 - 1; - } - - match end_8 { - 10 => { - // Lint - if u_8 > 0 { - u_8 -= 1; - } - }, - 11 => u_8 += 1, - _ => u_8 = 0, - } - - let end_16: u16 = 40; - let start_16: u16 = 35; - - let mut u_16: u16 = end_16 - start_16; - - // Lint - if u_16 > 0 { - u_16 -= 1; - } - - let mut end_32: u32 = 7010; - let mut start_32: u32 = 7000; - - let mut u_32: u32 = end_32 - start_32; - - // Lint - if u_32 != 0 { - u_32 -= 1; - } - - // No Lint - if u_32 > 0 { - u_16 += 1; - } - - // No Lint - if u_32 != 0 { - end_32 -= 1; - start_32 += 1; - } - - let mut end_64: u64 = 75001; - let mut start_64: u64 = 75000; - - let mut u_64: u64 = end_64 - start_64; - - // Lint - if u_64 > 0 { - u_64 -= 1; - } - - // Lint - if 0 < u_64 { - u_64 -= 1; - } - - // Lint - if 0 != u_64 { - u_64 -= 1; - } - - // No Lint - if u_64 >= 1 { - u_64 -= 1; - } - - // No Lint - if u_64 > 0 { - end_64 -= 1; - } - - // Tests for usize - let end_usize: usize = 8054; - let start_usize: usize = 8050; - - let mut u_usize: usize = end_usize - start_usize; - - // Lint - if u_usize > 0 { - u_usize -= 1; - } - - // Tests for signed integers - - let endi_8: i8 = 10; - let starti_8: i8 = 50; - - let mut i_8: i8 = endi_8 - starti_8; - - // Lint - if i_8 > i8::MIN { - i_8 -= 1; - } - - // Lint - if i_8 > i8::MIN { - i_8 -= 1; - } - - // Lint - if i_8 != i8::MIN { - i_8 -= 1; - } - - // Lint - if i_8 != i8::MIN { - i_8 -= 1; - } - - let endi_16: i16 = 45; - let starti_16: i16 = 44; - - let mut i_16: i16 = endi_16 - starti_16; - - // Lint - if i_16 > i16::MIN { - i_16 -= 1; - } - - // Lint - if i_16 > i16::MIN { - i_16 -= 1; - } - - // Lint - if i_16 != i16::MIN { - i_16 -= 1; - } - - // Lint - if i_16 != i16::MIN { - i_16 -= 1; - } - - let endi_32: i32 = 45; - let starti_32: i32 = 44; - - let mut i_32: i32 = endi_32 - starti_32; - - // Lint - if i_32 > i32::MIN { - i_32 -= 1; - } - - // Lint - if i_32 > i32::MIN { - i_32 -= 1; - } - - // Lint - if i_32 != i32::MIN { - i_32 -= 1; - } - - // Lint - if i_32 != i32::MIN { - i_32 -= 1; - } - - let endi_64: i64 = 45; - let starti_64: i64 = 44; - - let mut i_64: i64 = endi_64 - starti_64; - - // Lint - if i64::MIN < i_64 { - i_64 -= 1; - } - - // Lint - if i64::MIN != i_64 { - i_64 -= 1; - } - - // Lint - if i64::MIN < i_64 { - i_64 -= 1; - } - - // No Lint - if i_64 > 0 { - i_64 -= 1; - } - - // No Lint - if i_64 != 0 { - i_64 -= 1; - } -} diff --git a/tests/ui/implicit_saturating_sub.stderr b/tests/ui/implicit_saturating_sub.stderr deleted file mode 100644 index 5bb9a606422a..000000000000 --- a/tests/ui/implicit_saturating_sub.stderr +++ /dev/null @@ -1,188 +0,0 @@ -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:13:5 - | -LL | / if u_8 > 0 { -LL | | u_8 = u_8 - 1; -LL | | } - | |_____^ help: try: `u_8 = u_8.saturating_sub(1);` - | - = note: `-D clippy::implicit-saturating-sub` implied by `-D warnings` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:20:13 - | -LL | / if u_8 > 0 { -LL | | u_8 -= 1; -LL | | } - | |_____________^ help: try: `u_8 = u_8.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:34:5 - | -LL | / if u_16 > 0 { -LL | | u_16 -= 1; -LL | | } - | |_____^ help: try: `u_16 = u_16.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:44:5 - | -LL | / if u_32 != 0 { -LL | | u_32 -= 1; -LL | | } - | |_____^ help: try: `u_32 = u_32.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:65:5 - | -LL | / if u_64 > 0 { -LL | | u_64 -= 1; -LL | | } - | |_____^ help: try: `u_64 = u_64.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:70:5 - | -LL | / if 0 < u_64 { -LL | | u_64 -= 1; -LL | | } - | |_____^ help: try: `u_64 = u_64.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:75:5 - | -LL | / if 0 != u_64 { -LL | | u_64 -= 1; -LL | | } - | |_____^ help: try: `u_64 = u_64.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:96:5 - | -LL | / if u_usize > 0 { -LL | | u_usize -= 1; -LL | | } - | |_____^ help: try: `u_usize = u_usize.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:108:5 - | -LL | / if i_8 > i8::MIN { -LL | | i_8 -= 1; -LL | | } - | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:113:5 - | -LL | / if i_8 > i8::MIN { -LL | | i_8 -= 1; -LL | | } - | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:118:5 - | -LL | / if i_8 != i8::MIN { -LL | | i_8 -= 1; -LL | | } - | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:123:5 - | -LL | / if i_8 != i8::MIN { -LL | | i_8 -= 1; -LL | | } - | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:133:5 - | -LL | / if i_16 > i16::MIN { -LL | | i_16 -= 1; -LL | | } - | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:138:5 - | -LL | / if i_16 > i16::MIN { -LL | | i_16 -= 1; -LL | | } - | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:143:5 - | -LL | / if i_16 != i16::MIN { -LL | | i_16 -= 1; -LL | | } - | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:148:5 - | -LL | / if i_16 != i16::MIN { -LL | | i_16 -= 1; -LL | | } - | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:158:5 - | -LL | / if i_32 > i32::MIN { -LL | | i_32 -= 1; -LL | | } - | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:163:5 - | -LL | / if i_32 > i32::MIN { -LL | | i_32 -= 1; -LL | | } - | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:168:5 - | -LL | / if i_32 != i32::MIN { -LL | | i_32 -= 1; -LL | | } - | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:173:5 - | -LL | / if i_32 != i32::MIN { -LL | | i_32 -= 1; -LL | | } - | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:183:5 - | -LL | / if i64::MIN < i_64 { -LL | | i_64 -= 1; -LL | | } - | |_____^ help: try: `i_64 = i_64.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:188:5 - | -LL | / if i64::MIN != i_64 { -LL | | i_64 -= 1; -LL | | } - | |_____^ help: try: `i_64 = i_64.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:193:5 - | -LL | / if i64::MIN < i_64 { -LL | | i_64 -= 1; -LL | | } - | |_____^ help: try: `i_64 = i_64.saturating_sub(1);` - -error: aborting due to 23 previous errors - diff --git a/tests/ui/inconsistent_digit_grouping.fixed b/tests/ui/inconsistent_digit_grouping.fixed deleted file mode 100644 index dd683e7f746a..000000000000 --- a/tests/ui/inconsistent_digit_grouping.fixed +++ /dev/null @@ -1,47 +0,0 @@ -// run-rustfix -#[warn(clippy::inconsistent_digit_grouping)] -#[deny(clippy::unreadable_literal)] -#[allow(unused_variables, clippy::excessive_precision)] -fn main() { - macro_rules! mac1 { - () => { - 1_23_456 - }; - } - macro_rules! mac2 { - () => { - 1_234.5678_f32 - }; - } - - let good = ( - 123, - 1_234, - 1_2345_6789, - 123_f32, - 1_234.12_f32, - 1_234.123_4_f32, - 1.123_456_7_f32, - ); - let bad = (123_456, 12_345_678, 1_234_567, 1_234.567_8_f32, 1.234_567_8_f32); - - // Test padding - let _ = 0x0010_0000; - let _ = 0x0100_0000; - let _ = 0x1000_0000; - let _ = 0x0001_0000_0000_u64; - - // Test suggestion when fraction has no digits - let _: f32 = 123_456.; - - // Test UUID formatted literal - let _: u128 = 0x12345678_1234_1234_1234_123456789012; - - // Ignore literals in macros - let _ = mac1!(); - let _ = mac2!(); - - // Issue #6096 - // Allow separating exponent with '_' - let _ = 1.025_011_10_E0; -} diff --git a/tests/ui/inconsistent_digit_grouping.rs b/tests/ui/inconsistent_digit_grouping.rs deleted file mode 100644 index d5d27c853c28..000000000000 --- a/tests/ui/inconsistent_digit_grouping.rs +++ /dev/null @@ -1,47 +0,0 @@ -// run-rustfix -#[warn(clippy::inconsistent_digit_grouping)] -#[deny(clippy::unreadable_literal)] -#[allow(unused_variables, clippy::excessive_precision)] -fn main() { - macro_rules! mac1 { - () => { - 1_23_456 - }; - } - macro_rules! mac2 { - () => { - 1_234.5678_f32 - }; - } - - let good = ( - 123, - 1_234, - 1_2345_6789, - 123_f32, - 1_234.12_f32, - 1_234.123_4_f32, - 1.123_456_7_f32, - ); - let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); - - // Test padding - let _ = 0x100000; - let _ = 0x1000000; - let _ = 0x10000000; - let _ = 0x100000000_u64; - - // Test suggestion when fraction has no digits - let _: f32 = 1_23_456.; - - // Test UUID formatted literal - let _: u128 = 0x12345678_1234_1234_1234_123456789012; - - // Ignore literals in macros - let _ = mac1!(); - let _ = mac2!(); - - // Issue #6096 - // Allow separating exponent with '_' - let _ = 1.025_011_10_E0; -} diff --git a/tests/ui/inconsistent_digit_grouping.stderr b/tests/ui/inconsistent_digit_grouping.stderr deleted file mode 100644 index b8ac91554620..000000000000 --- a/tests/ui/inconsistent_digit_grouping.stderr +++ /dev/null @@ -1,70 +0,0 @@ -error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:26:16 - | -LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); - | ^^^^^^^^ help: consider: `123_456` - | - = note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` - -error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:26:26 - | -LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); - | ^^^^^^^^^^ help: consider: `12_345_678` - -error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:26:38 - | -LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); - | ^^^^^^^^ help: consider: `1_234_567` - -error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:26:48 - | -LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); - | ^^^^^^^^^^^^^^ help: consider: `1_234.567_8_f32` - -error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:26:64 - | -LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); - | ^^^^^^^^^^^^^^ help: consider: `1.234_567_8_f32` - -error: long literal lacking separators - --> $DIR/inconsistent_digit_grouping.rs:29:13 - | -LL | let _ = 0x100000; - | ^^^^^^^^ help: consider: `0x0010_0000` - | -note: the lint level is defined here - --> $DIR/inconsistent_digit_grouping.rs:3:8 - | -LL | #[deny(clippy::unreadable_literal)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: long literal lacking separators - --> $DIR/inconsistent_digit_grouping.rs:30:13 - | -LL | let _ = 0x1000000; - | ^^^^^^^^^ help: consider: `0x0100_0000` - -error: long literal lacking separators - --> $DIR/inconsistent_digit_grouping.rs:31:13 - | -LL | let _ = 0x10000000; - | ^^^^^^^^^^ help: consider: `0x1000_0000` - -error: long literal lacking separators - --> $DIR/inconsistent_digit_grouping.rs:32:13 - | -LL | let _ = 0x100000000_u64; - | ^^^^^^^^^^^^^^^ help: consider: `0x0001_0000_0000_u64` - -error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:35:18 - | -LL | let _: f32 = 1_23_456.; - | ^^^^^^^^^ help: consider: `123_456.` - -error: aborting due to 10 previous errors - diff --git a/tests/ui/indexing_slicing_index.rs b/tests/ui/indexing_slicing_index.rs deleted file mode 100644 index ca8ca53c80c3..000000000000 --- a/tests/ui/indexing_slicing_index.rs +++ /dev/null @@ -1,32 +0,0 @@ -#![warn(clippy::indexing_slicing)] -// We also check the out_of_bounds_indexing lint here, because it lints similar things and -// we want to avoid false positives. -#![warn(clippy::out_of_bounds_indexing)] -#![allow(clippy::no_effect, clippy::unnecessary_operation)] - -fn main() { - let x = [1, 2, 3, 4]; - let index: usize = 1; - x[index]; - x[4]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. - x[1 << 3]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. - - x[0]; // Ok, should not produce stderr. - x[3]; // Ok, should not produce stderr. - - let y = &x; - y[0]; // Ok, referencing shouldn't affect this lint. See the issue 6021 - y[4]; // Ok, rustc will handle references too. - - let v = vec![0; 5]; - v[0]; - v[10]; - v[1 << 3]; - - const N: usize = 15; // Out of bounds - const M: usize = 3; // In bounds - x[N]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. - x[M]; // Ok, should not produce stderr. - v[N]; - v[M]; -} diff --git a/tests/ui/indexing_slicing_index.stderr b/tests/ui/indexing_slicing_index.stderr deleted file mode 100644 index 2f6c9e2f4e5a..000000000000 --- a/tests/ui/indexing_slicing_index.stderr +++ /dev/null @@ -1,51 +0,0 @@ -error: indexing may panic. - --> $DIR/indexing_slicing_index.rs:10:5 - | -LL | x[index]; - | ^^^^^^^^ - | - = note: `-D clippy::indexing-slicing` implied by `-D warnings` - = help: Consider using `.get(n)` or `.get_mut(n)` instead - -error: indexing may panic. - --> $DIR/indexing_slicing_index.rs:22:5 - | -LL | v[0]; - | ^^^^ - | - = help: Consider using `.get(n)` or `.get_mut(n)` instead - -error: indexing may panic. - --> $DIR/indexing_slicing_index.rs:23:5 - | -LL | v[10]; - | ^^^^^ - | - = help: Consider using `.get(n)` or `.get_mut(n)` instead - -error: indexing may panic. - --> $DIR/indexing_slicing_index.rs:24:5 - | -LL | v[1 << 3]; - | ^^^^^^^^^ - | - = help: Consider using `.get(n)` or `.get_mut(n)` instead - -error: indexing may panic. - --> $DIR/indexing_slicing_index.rs:30:5 - | -LL | v[N]; - | ^^^^ - | - = help: Consider using `.get(n)` or `.get_mut(n)` instead - -error: indexing may panic. - --> $DIR/indexing_slicing_index.rs:31:5 - | -LL | v[M]; - | ^^^^ - | - = help: Consider using `.get(n)` or `.get_mut(n)` instead - -error: aborting due to 6 previous errors - diff --git a/tests/ui/indexing_slicing_slice.rs b/tests/ui/indexing_slicing_slice.rs deleted file mode 100644 index 7b107db39f02..000000000000 --- a/tests/ui/indexing_slicing_slice.rs +++ /dev/null @@ -1,37 +0,0 @@ -#![warn(clippy::indexing_slicing)] -// We also check the out_of_bounds_indexing lint here, because it lints similar things and -// we want to avoid false positives. -#![warn(clippy::out_of_bounds_indexing)] -#![allow(clippy::no_effect, clippy::unnecessary_operation)] - -fn main() { - let x = [1, 2, 3, 4]; - let index: usize = 1; - let index_from: usize = 2; - let index_to: usize = 3; - &x[index..]; - &x[..index]; - &x[index_from..index_to]; - &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to]. - &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10]. - &x[0..][..3]; - &x[1..][..5]; - - &x[0..].get(..3); // Ok, should not produce stderr. - &x[0..3]; // Ok, should not produce stderr. - - let y = &x; - &y[1..2]; - &y[0..=4]; - &y[..=4]; - - &y[..]; // Ok, should not produce stderr. - - let v = vec![0; 5]; - &v[10..100]; - &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100]. - &v[10..]; - &v[..100]; - - &v[..]; // Ok, should not produce stderr. -} diff --git a/tests/ui/indexing_slicing_slice.stderr b/tests/ui/indexing_slicing_slice.stderr deleted file mode 100644 index 2231deee833e..000000000000 --- a/tests/ui/indexing_slicing_slice.stderr +++ /dev/null @@ -1,125 +0,0 @@ -error: slicing may panic. - --> $DIR/indexing_slicing_slice.rs:12:6 - | -LL | &x[index..]; - | ^^^^^^^^^^ - | - = note: `-D clippy::indexing-slicing` implied by `-D warnings` - = help: Consider using `.get(n..)` or .get_mut(n..)` instead - -error: slicing may panic. - --> $DIR/indexing_slicing_slice.rs:13:6 - | -LL | &x[..index]; - | ^^^^^^^^^^ - | - = help: Consider using `.get(..n)`or `.get_mut(..n)` instead - -error: slicing may panic. - --> $DIR/indexing_slicing_slice.rs:14:6 - | -LL | &x[index_from..index_to]; - | ^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: Consider using `.get(n..m)` or `.get_mut(n..m)` instead - -error: slicing may panic. - --> $DIR/indexing_slicing_slice.rs:15:6 - | -LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to]. - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: Consider using `.get(..n)`or `.get_mut(..n)` instead - -error: slicing may panic. - --> $DIR/indexing_slicing_slice.rs:15:6 - | -LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to]. - | ^^^^^^^^^^^^^^^ - | - = help: Consider using `.get(n..)` or .get_mut(n..)` instead - -error: slicing may panic. - --> $DIR/indexing_slicing_slice.rs:16:6 - | -LL | &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10]. - | ^^^^^^^^^^^^ - | - = help: Consider using `.get(..n)`or `.get_mut(..n)` instead - -error: range is out of bounds - --> $DIR/indexing_slicing_slice.rs:16:8 - | -LL | &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10]. - | ^ - | - = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` - -error: slicing may panic. - --> $DIR/indexing_slicing_slice.rs:17:6 - | -LL | &x[0..][..3]; - | ^^^^^^^^^^^ - | - = help: Consider using `.get(..n)`or `.get_mut(..n)` instead - -error: slicing may panic. - --> $DIR/indexing_slicing_slice.rs:18:6 - | -LL | &x[1..][..5]; - | ^^^^^^^^^^^ - | - = help: Consider using `.get(..n)`or `.get_mut(..n)` instead - -error: range is out of bounds - --> $DIR/indexing_slicing_slice.rs:25:12 - | -LL | &y[0..=4]; - | ^ - -error: range is out of bounds - --> $DIR/indexing_slicing_slice.rs:26:11 - | -LL | &y[..=4]; - | ^ - -error: slicing may panic. - --> $DIR/indexing_slicing_slice.rs:31:6 - | -LL | &v[10..100]; - | ^^^^^^^^^^ - | - = help: Consider using `.get(n..m)` or `.get_mut(n..m)` instead - -error: slicing may panic. - --> $DIR/indexing_slicing_slice.rs:32:6 - | -LL | &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100]. - | ^^^^^^^^^^^^^^ - | - = help: Consider using `.get(..n)`or `.get_mut(..n)` instead - -error: range is out of bounds - --> $DIR/indexing_slicing_slice.rs:32:8 - | -LL | &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100]. - | ^^ - -error: slicing may panic. - --> $DIR/indexing_slicing_slice.rs:33:6 - | -LL | &v[10..]; - | ^^^^^^^ - | - = help: Consider using `.get(n..)` or .get_mut(n..)` instead - -error: slicing may panic. - --> $DIR/indexing_slicing_slice.rs:34:6 - | -LL | &v[..100]; - | ^^^^^^^^ - | - = help: Consider using `.get(..n)`or `.get_mut(..n)` instead - -error: aborting due to 16 previous errors - diff --git a/tests/ui/inefficient_to_string.fixed b/tests/ui/inefficient_to_string.fixed deleted file mode 100644 index c972b9419ef7..000000000000 --- a/tests/ui/inefficient_to_string.fixed +++ /dev/null @@ -1,31 +0,0 @@ -// run-rustfix -#![deny(clippy::inefficient_to_string)] - -use std::borrow::Cow; - -fn main() { - let rstr: &str = "hello"; - let rrstr: &&str = &rstr; - let rrrstr: &&&str = &rrstr; - let _: String = rstr.to_string(); - let _: String = (*rrstr).to_string(); - let _: String = (**rrrstr).to_string(); - - let string: String = String::from("hello"); - let rstring: &String = &string; - let rrstring: &&String = &rstring; - let rrrstring: &&&String = &rrstring; - let _: String = string.to_string(); - let _: String = rstring.to_string(); - let _: String = (*rrstring).to_string(); - let _: String = (**rrrstring).to_string(); - - let cow: Cow<'_, str> = Cow::Borrowed("hello"); - let rcow: &Cow<'_, str> = &cow; - let rrcow: &&Cow<'_, str> = &rcow; - let rrrcow: &&&Cow<'_, str> = &rrcow; - let _: String = cow.to_string(); - let _: String = rcow.to_string(); - let _: String = (*rrcow).to_string(); - let _: String = (**rrrcow).to_string(); -} diff --git a/tests/ui/inefficient_to_string.rs b/tests/ui/inefficient_to_string.rs deleted file mode 100644 index acdc55aa0d69..000000000000 --- a/tests/ui/inefficient_to_string.rs +++ /dev/null @@ -1,31 +0,0 @@ -// run-rustfix -#![deny(clippy::inefficient_to_string)] - -use std::borrow::Cow; - -fn main() { - let rstr: &str = "hello"; - let rrstr: &&str = &rstr; - let rrrstr: &&&str = &rrstr; - let _: String = rstr.to_string(); - let _: String = rrstr.to_string(); - let _: String = rrrstr.to_string(); - - let string: String = String::from("hello"); - let rstring: &String = &string; - let rrstring: &&String = &rstring; - let rrrstring: &&&String = &rrstring; - let _: String = string.to_string(); - let _: String = rstring.to_string(); - let _: String = rrstring.to_string(); - let _: String = rrrstring.to_string(); - - let cow: Cow<'_, str> = Cow::Borrowed("hello"); - let rcow: &Cow<'_, str> = &cow; - let rrcow: &&Cow<'_, str> = &rcow; - let rrrcow: &&&Cow<'_, str> = &rrcow; - let _: String = cow.to_string(); - let _: String = rcow.to_string(); - let _: String = rrcow.to_string(); - let _: String = rrrcow.to_string(); -} diff --git a/tests/ui/inefficient_to_string.stderr b/tests/ui/inefficient_to_string.stderr deleted file mode 100644 index 4be46161e8b7..000000000000 --- a/tests/ui/inefficient_to_string.stderr +++ /dev/null @@ -1,55 +0,0 @@ -error: calling `to_string` on `&&str` - --> $DIR/inefficient_to_string.rs:11:21 - | -LL | let _: String = rrstr.to_string(); - | ^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrstr).to_string()` - | -note: the lint level is defined here - --> $DIR/inefficient_to_string.rs:2:9 - | -LL | #![deny(clippy::inefficient_to_string)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: `&str` implements `ToString` through a slower blanket impl, but `str` has a fast specialization of `ToString` - -error: calling `to_string` on `&&&str` - --> $DIR/inefficient_to_string.rs:12:21 - | -LL | let _: String = rrrstr.to_string(); - | ^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrstr).to_string()` - | - = help: `&&str` implements `ToString` through a slower blanket impl, but `str` has a fast specialization of `ToString` - -error: calling `to_string` on `&&std::string::String` - --> $DIR/inefficient_to_string.rs:20:21 - | -LL | let _: String = rrstring.to_string(); - | ^^^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrstring).to_string()` - | - = help: `&std::string::String` implements `ToString` through a slower blanket impl, but `std::string::String` has a fast specialization of `ToString` - -error: calling `to_string` on `&&&std::string::String` - --> $DIR/inefficient_to_string.rs:21:21 - | -LL | let _: String = rrrstring.to_string(); - | ^^^^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrstring).to_string()` - | - = help: `&&std::string::String` implements `ToString` through a slower blanket impl, but `std::string::String` has a fast specialization of `ToString` - -error: calling `to_string` on `&&std::borrow::Cow` - --> $DIR/inefficient_to_string.rs:29:21 - | -LL | let _: String = rrcow.to_string(); - | ^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrcow).to_string()` - | - = help: `&std::borrow::Cow` implements `ToString` through a slower blanket impl, but `std::borrow::Cow` has a fast specialization of `ToString` - -error: calling `to_string` on `&&&std::borrow::Cow` - --> $DIR/inefficient_to_string.rs:30:21 - | -LL | let _: String = rrrcow.to_string(); - | ^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrcow).to_string()` - | - = help: `&&std::borrow::Cow` implements `ToString` through a slower blanket impl, but `std::borrow::Cow` has a fast specialization of `ToString` - -error: aborting due to 6 previous errors - diff --git a/tests/ui/infallible_destructuring_match.fixed b/tests/ui/infallible_destructuring_match.fixed deleted file mode 100644 index b8e40d995531..000000000000 --- a/tests/ui/infallible_destructuring_match.fixed +++ /dev/null @@ -1,112 +0,0 @@ -// run-rustfix -#![feature(exhaustive_patterns, never_type)] -#![allow(dead_code, unreachable_code, unused_variables)] -#![allow(clippy::let_and_return)] - -enum SingleVariantEnum { - Variant(i32), -} - -struct TupleStruct(i32); - -enum EmptyEnum {} - -macro_rules! match_enum { - ($param:expr) => { - let data = match $param { - SingleVariantEnum::Variant(i) => i, - }; - }; -} - -fn infallible_destructuring_match_enum() { - let wrapper = SingleVariantEnum::Variant(0); - - // This should lint! - let SingleVariantEnum::Variant(data) = wrapper; - - // This shouldn't (inside macro) - match_enum!(wrapper); - - // This shouldn't! - let data = match wrapper { - SingleVariantEnum::Variant(_) => -1, - }; - - // Neither should this! - let data = match wrapper { - SingleVariantEnum::Variant(i) => -1, - }; - - let SingleVariantEnum::Variant(data) = wrapper; -} - -macro_rules! match_struct { - ($param:expr) => { - let data = match $param { - TupleStruct(i) => i, - }; - }; -} - -fn infallible_destructuring_match_struct() { - let wrapper = TupleStruct(0); - - // This should lint! - let TupleStruct(data) = wrapper; - - // This shouldn't (inside macro) - match_struct!(wrapper); - - // This shouldn't! - let data = match wrapper { - TupleStruct(_) => -1, - }; - - // Neither should this! - let data = match wrapper { - TupleStruct(i) => -1, - }; - - let TupleStruct(data) = wrapper; -} - -macro_rules! match_never_enum { - ($param:expr) => { - let data = match $param { - Ok(i) => i, - }; - }; -} - -fn never_enum() { - let wrapper: Result = Ok(23); - - // This should lint! - let Ok(data) = wrapper; - - // This shouldn't (inside macro) - match_never_enum!(wrapper); - - // This shouldn't! - let data = match wrapper { - Ok(_) => -1, - }; - - // Neither should this! - let data = match wrapper { - Ok(i) => -1, - }; - - let Ok(data) = wrapper; -} - -impl EmptyEnum { - fn match_on(&self) -> ! { - // The lint shouldn't pick this up, as `let` won't work here! - let data = match *self {}; - data - } -} - -fn main() {} diff --git a/tests/ui/infallible_destructuring_match.rs b/tests/ui/infallible_destructuring_match.rs deleted file mode 100644 index 106cd438b90e..000000000000 --- a/tests/ui/infallible_destructuring_match.rs +++ /dev/null @@ -1,118 +0,0 @@ -// run-rustfix -#![feature(exhaustive_patterns, never_type)] -#![allow(dead_code, unreachable_code, unused_variables)] -#![allow(clippy::let_and_return)] - -enum SingleVariantEnum { - Variant(i32), -} - -struct TupleStruct(i32); - -enum EmptyEnum {} - -macro_rules! match_enum { - ($param:expr) => { - let data = match $param { - SingleVariantEnum::Variant(i) => i, - }; - }; -} - -fn infallible_destructuring_match_enum() { - let wrapper = SingleVariantEnum::Variant(0); - - // This should lint! - let data = match wrapper { - SingleVariantEnum::Variant(i) => i, - }; - - // This shouldn't (inside macro) - match_enum!(wrapper); - - // This shouldn't! - let data = match wrapper { - SingleVariantEnum::Variant(_) => -1, - }; - - // Neither should this! - let data = match wrapper { - SingleVariantEnum::Variant(i) => -1, - }; - - let SingleVariantEnum::Variant(data) = wrapper; -} - -macro_rules! match_struct { - ($param:expr) => { - let data = match $param { - TupleStruct(i) => i, - }; - }; -} - -fn infallible_destructuring_match_struct() { - let wrapper = TupleStruct(0); - - // This should lint! - let data = match wrapper { - TupleStruct(i) => i, - }; - - // This shouldn't (inside macro) - match_struct!(wrapper); - - // This shouldn't! - let data = match wrapper { - TupleStruct(_) => -1, - }; - - // Neither should this! - let data = match wrapper { - TupleStruct(i) => -1, - }; - - let TupleStruct(data) = wrapper; -} - -macro_rules! match_never_enum { - ($param:expr) => { - let data = match $param { - Ok(i) => i, - }; - }; -} - -fn never_enum() { - let wrapper: Result = Ok(23); - - // This should lint! - let data = match wrapper { - Ok(i) => i, - }; - - // This shouldn't (inside macro) - match_never_enum!(wrapper); - - // This shouldn't! - let data = match wrapper { - Ok(_) => -1, - }; - - // Neither should this! - let data = match wrapper { - Ok(i) => -1, - }; - - let Ok(data) = wrapper; -} - -impl EmptyEnum { - fn match_on(&self) -> ! { - // The lint shouldn't pick this up, as `let` won't work here! - let data = match *self {}; - data - } -} - -fn main() {} diff --git a/tests/ui/infallible_destructuring_match.stderr b/tests/ui/infallible_destructuring_match.stderr deleted file mode 100644 index 1b78db42014a..000000000000 --- a/tests/ui/infallible_destructuring_match.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let` - --> $DIR/infallible_destructuring_match.rs:26:5 - | -LL | / let data = match wrapper { -LL | | SingleVariantEnum::Variant(i) => i, -LL | | }; - | |______^ help: try this: `let SingleVariantEnum::Variant(data) = wrapper;` - | - = note: `-D clippy::infallible-destructuring-match` implied by `-D warnings` - -error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let` - --> $DIR/infallible_destructuring_match.rs:58:5 - | -LL | / let data = match wrapper { -LL | | TupleStruct(i) => i, -LL | | }; - | |______^ help: try this: `let TupleStruct(data) = wrapper;` - -error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let` - --> $DIR/infallible_destructuring_match.rs:90:5 - | -LL | / let data = match wrapper { -LL | | Ok(i) => i, -LL | | }; - | |______^ help: try this: `let Ok(data) = wrapper;` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/infinite_iter.rs b/tests/ui/infinite_iter.rs deleted file mode 100644 index 1fe688977659..000000000000 --- a/tests/ui/infinite_iter.rs +++ /dev/null @@ -1,69 +0,0 @@ -use std::iter::repeat; -fn square_is_lower_64(x: &u32) -> bool { - x * x < 64 -} - -#[allow(clippy::maybe_infinite_iter)] -#[deny(clippy::infinite_iter)] -fn infinite_iters() { - repeat(0_u8).collect::>(); // infinite iter - (0..8_u32).take_while(square_is_lower_64).cycle().count(); // infinite iter - (0..8_u64).chain(0..).max(); // infinite iter - (0_usize..) - .chain([0usize, 1, 2].iter().cloned()) - .skip_while(|x| *x != 42) - .min(); // infinite iter - (0..8_u32) - .rev() - .cycle() - .map(|x| x + 1_u32) - .for_each(|x| println!("{}", x)); // infinite iter - (0..3_u32).flat_map(|x| x..).sum::(); // infinite iter - (0_usize..).flat_map(|x| 0..x).product::(); // infinite iter - (0_u64..).filter(|x| x % 2 == 0).last(); // infinite iter - (0..42_u64).by_ref().last(); // not an infinite, because ranges are double-ended - (0..).next(); // iterator is not exhausted -} - -#[deny(clippy::maybe_infinite_iter)] -fn potential_infinite_iters() { - (0..).zip((0..).take_while(square_is_lower_64)).count(); // maybe infinite iter - repeat(42).take_while(|x| *x == 42).chain(0..42).max(); // maybe infinite iter - (1..) - .scan(0, |state, x| { - *state += x; - Some(*state) - }) - .min(); // maybe infinite iter - (0..).find(|x| *x == 24); // maybe infinite iter - (0..).position(|x| x == 24); // maybe infinite iter - (0..).any(|x| x == 24); // maybe infinite iter - (0..).all(|x| x == 24); // maybe infinite iter - - (0..).zip(0..42).take_while(|&(x, _)| x != 42).count(); // not infinite - repeat(42).take_while(|x| *x == 42).next(); // iterator is not exhausted -} - -fn main() { - infinite_iters(); - potential_infinite_iters(); -} - -mod finite_collect { - use std::collections::HashSet; - use std::iter::FromIterator; - - struct C; - impl FromIterator for C { - fn from_iter>(iter: I) -> Self { - C - } - } - - fn check_collect() { - let _: HashSet = (0..).collect(); // Infinite iter - - // Some data structures don't collect infinitely, such as `ArrayVec` - let _: C = (0..).collect(); - } -} diff --git a/tests/ui/infinite_iter.stderr b/tests/ui/infinite_iter.stderr deleted file mode 100644 index 5f5e7ac9f253..000000000000 --- a/tests/ui/infinite_iter.stderr +++ /dev/null @@ -1,109 +0,0 @@ -error: infinite iteration detected - --> $DIR/infinite_iter.rs:9:5 - | -LL | repeat(0_u8).collect::>(); // infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/infinite_iter.rs:7:8 - | -LL | #[deny(clippy::infinite_iter)] - | ^^^^^^^^^^^^^^^^^^^^^ - -error: infinite iteration detected - --> $DIR/infinite_iter.rs:10:5 - | -LL | (0..8_u32).take_while(square_is_lower_64).cycle().count(); // infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: infinite iteration detected - --> $DIR/infinite_iter.rs:11:5 - | -LL | (0..8_u64).chain(0..).max(); // infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: infinite iteration detected - --> $DIR/infinite_iter.rs:16:5 - | -LL | / (0..8_u32) -LL | | .rev() -LL | | .cycle() -LL | | .map(|x| x + 1_u32) -LL | | .for_each(|x| println!("{}", x)); // infinite iter - | |________________________________________^ - -error: infinite iteration detected - --> $DIR/infinite_iter.rs:22:5 - | -LL | (0_usize..).flat_map(|x| 0..x).product::(); // infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: infinite iteration detected - --> $DIR/infinite_iter.rs:23:5 - | -LL | (0_u64..).filter(|x| x % 2 == 0).last(); // infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:30:5 - | -LL | (0..).zip((0..).take_while(square_is_lower_64)).count(); // maybe infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/infinite_iter.rs:28:8 - | -LL | #[deny(clippy::maybe_infinite_iter)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:31:5 - | -LL | repeat(42).take_while(|x| *x == 42).chain(0..42).max(); // maybe infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:32:5 - | -LL | / (1..) -LL | | .scan(0, |state, x| { -LL | | *state += x; -LL | | Some(*state) -LL | | }) -LL | | .min(); // maybe infinite iter - | |______________^ - -error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:38:5 - | -LL | (0..).find(|x| *x == 24); // maybe infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:39:5 - | -LL | (0..).position(|x| x == 24); // maybe infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:40:5 - | -LL | (0..).any(|x| x == 24); // maybe infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^ - -error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:41:5 - | -LL | (0..).all(|x| x == 24); // maybe infinite iter - | ^^^^^^^^^^^^^^^^^^^^^^ - -error: infinite iteration detected - --> $DIR/infinite_iter.rs:64:31 - | -LL | let _: HashSet = (0..).collect(); // Infinite iter - | ^^^^^^^^^^^^^^^ - | - = note: `#[deny(clippy::infinite_iter)]` on by default - -error: aborting due to 14 previous errors - diff --git a/tests/ui/infinite_loop.rs b/tests/ui/infinite_loop.rs deleted file mode 100644 index 72591f12baf8..000000000000 --- a/tests/ui/infinite_loop.rs +++ /dev/null @@ -1,206 +0,0 @@ -fn fn_val(i: i32) -> i32 { - unimplemented!() -} -fn fn_constref(i: &i32) -> i32 { - unimplemented!() -} -fn fn_mutref(i: &mut i32) { - unimplemented!() -} -fn fooi() -> i32 { - unimplemented!() -} -fn foob() -> bool { - unimplemented!() -} - -#[allow(clippy::many_single_char_names)] -fn immutable_condition() { - // Should warn when all vars mentioned are immutable - let y = 0; - while y < 10 { - println!("KO - y is immutable"); - } - - let x = 0; - while y < 10 && x < 3 { - let mut k = 1; - k += 2; - println!("KO - x and y immutable"); - } - - let cond = false; - while !cond { - println!("KO - cond immutable"); - } - - let mut i = 0; - while y < 10 && i < 3 { - i += 1; - println!("OK - i is mutable"); - } - - let mut mut_cond = false; - while !mut_cond || cond { - mut_cond = true; - println!("OK - mut_cond is mutable"); - } - - while fooi() < x { - println!("OK - Fn call results may vary"); - } - - while foob() { - println!("OK - Fn call results may vary"); - } - - let mut a = 0; - let mut c = move || { - while a < 5 { - a += 1; - println!("OK - a is mutable"); - } - }; - c(); - - let mut tup = (0, 0); - while tup.0 < 5 { - tup.0 += 1; - println!("OK - tup.0 gets mutated") - } -} - -fn unused_var() { - // Should warn when a (mutable) var is not used in while body - let (mut i, mut j) = (0, 0); - - while i < 3 { - j = 3; - println!("KO - i not mentioned"); - } - - while i < 3 && j > 0 { - println!("KO - i and j not mentioned"); - } - - while i < 3 { - let mut i = 5; - fn_mutref(&mut i); - println!("KO - shadowed"); - } - - while i < 3 && j > 0 { - i = 5; - println!("OK - i in cond and mentioned"); - } -} - -fn used_immutable() { - let mut i = 0; - - while i < 3 { - fn_constref(&i); - println!("KO - const reference"); - } - - while i < 3 { - fn_val(i); - println!("KO - passed by value"); - } - - while i < 3 { - println!("OK - passed by mutable reference"); - fn_mutref(&mut i) - } - - while i < 3 { - fn_mutref(&mut i); - println!("OK - passed by mutable reference"); - } -} - -const N: i32 = 5; -const B: bool = false; - -fn consts() { - while false { - println!("Constants are not linted"); - } - - while B { - println!("Constants are not linted"); - } - - while N > 0 { - println!("Constants are not linted"); - } -} - -use std::cell::Cell; - -fn maybe_i_mutate(i: &Cell) { - unimplemented!() -} - -fn internally_mutable() { - let b = Cell::new(true); - - while b.get() { - // b cannot be silently coerced to `bool` - maybe_i_mutate(&b); - println!("OK - Method call within condition"); - } -} - -struct Counter { - count: usize, -} - -impl Counter { - fn inc(&mut self) { - self.count += 1; - } - - fn inc_n(&mut self, n: usize) { - while self.count < n { - self.inc(); - } - println!("OK - self borrowed mutably"); - } - - fn print_n(&self, n: usize) { - while self.count < n { - println!("KO - {} is not mutated", self.count); - } - } -} - -fn while_loop_with_break_and_return() { - let y = 0; - while y < 10 { - if y == 0 { - break; - } - println!("KO - loop contains break"); - } - - while y < 10 { - if y == 0 { - return; - } - println!("KO - loop contains return"); - } -} - -fn main() { - immutable_condition(); - unused_var(); - used_immutable(); - internally_mutable(); - - let mut c = Counter { count: 0 }; - c.inc_n(5); - c.print_n(2); - - while_loop_with_break_and_return(); -} diff --git a/tests/ui/infinite_loop.stderr b/tests/ui/infinite_loop.stderr deleted file mode 100644 index 1fcb29eff18e..000000000000 --- a/tests/ui/infinite_loop.stderr +++ /dev/null @@ -1,95 +0,0 @@ -error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:21:11 - | -LL | while y < 10 { - | ^^^^^^ - | - = note: `#[deny(clippy::while_immutable_condition)]` on by default - = note: this may lead to an infinite or to a never running loop - -error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:26:11 - | -LL | while y < 10 && x < 3 { - | ^^^^^^^^^^^^^^^ - | - = note: this may lead to an infinite or to a never running loop - -error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:33:11 - | -LL | while !cond { - | ^^^^^ - | - = note: this may lead to an infinite or to a never running loop - -error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:77:11 - | -LL | while i < 3 { - | ^^^^^ - | - = note: this may lead to an infinite or to a never running loop - -error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:82:11 - | -LL | while i < 3 && j > 0 { - | ^^^^^^^^^^^^^^ - | - = note: this may lead to an infinite or to a never running loop - -error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:86:11 - | -LL | while i < 3 { - | ^^^^^ - | - = note: this may lead to an infinite or to a never running loop - -error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:101:11 - | -LL | while i < 3 { - | ^^^^^ - | - = note: this may lead to an infinite or to a never running loop - -error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:106:11 - | -LL | while i < 3 { - | ^^^^^ - | - = note: this may lead to an infinite or to a never running loop - -error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:172:15 - | -LL | while self.count < n { - | ^^^^^^^^^^^^^^ - | - = note: this may lead to an infinite or to a never running loop - -error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:180:11 - | -LL | while y < 10 { - | ^^^^^^ - | - = note: this may lead to an infinite or to a never running loop - = note: this loop contains `return`s or `break`s - = help: rewrite it as `if cond { loop { } }` - -error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:187:11 - | -LL | while y < 10 { - | ^^^^^^ - | - = note: this may lead to an infinite or to a never running loop - = note: this loop contains `return`s or `break`s - = help: rewrite it as `if cond { loop { } }` - -error: aborting due to 11 previous errors - diff --git a/tests/ui/inherent_to_string.rs b/tests/ui/inherent_to_string.rs deleted file mode 100644 index e6cf337d1bb1..000000000000 --- a/tests/ui/inherent_to_string.rs +++ /dev/null @@ -1,96 +0,0 @@ -#![warn(clippy::inherent_to_string)] -#![deny(clippy::inherent_to_string_shadow_display)] -#![allow(clippy::many_single_char_names)] - -use std::fmt; - -trait FalsePositive { - fn to_string(&self) -> String; -} - -struct A; -struct B; -struct C; -struct D; -struct E; -struct F; - -impl A { - // Should be detected; emit warning - fn to_string(&self) -> String { - "A.to_string()".to_string() - } - - // Should not be detected as it does not match the function signature - fn to_str(&self) -> String { - "A.to_str()".to_string() - } -} - -// Should not be detected as it is a free function -fn to_string() -> String { - "free to_string()".to_string() -} - -impl B { - // Should not be detected, wrong return type - fn to_string(&self) -> i32 { - 42 - } -} - -impl C { - // Should be detected and emit error as C also implements Display - fn to_string(&self) -> String { - "C.to_string()".to_string() - } -} - -impl fmt::Display for C { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "impl Display for C") - } -} - -impl FalsePositive for D { - // Should not be detected, as it is a trait function - fn to_string(&self) -> String { - "impl FalsePositive for D".to_string() - } -} - -impl E { - // Should not be detected, as it is not bound to an instance - fn to_string() -> String { - "E::to_string()".to_string() - } -} - -impl F { - // Should not be detected, as it does not match the function signature - fn to_string(&self, _i: i32) -> String { - "F.to_string()".to_string() - } -} - -fn main() { - let a = A; - a.to_string(); - a.to_str(); - - to_string(); - - let b = B; - b.to_string(); - - let c = C; - C.to_string(); - - let d = D; - d.to_string(); - - E::to_string(); - - let f = F; - f.to_string(1); -} diff --git a/tests/ui/inherent_to_string.stderr b/tests/ui/inherent_to_string.stderr deleted file mode 100644 index 4f331f5bec9e..000000000000 --- a/tests/ui/inherent_to_string.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: implementation of inherent method `to_string(&self) -> String` for type `A` - --> $DIR/inherent_to_string.rs:20:5 - | -LL | / fn to_string(&self) -> String { -LL | | "A.to_string()".to_string() -LL | | } - | |_____^ - | - = note: `-D clippy::inherent-to-string` implied by `-D warnings` - = help: implement trait `Display` for type `A` instead - -error: type `C` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display` - --> $DIR/inherent_to_string.rs:44:5 - | -LL | / fn to_string(&self) -> String { -LL | | "C.to_string()".to_string() -LL | | } - | |_____^ - | -note: the lint level is defined here - --> $DIR/inherent_to_string.rs:2:9 - | -LL | #![deny(clippy::inherent_to_string_shadow_display)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: remove the inherent method from type `C` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/inline_fn_without_body.fixed b/tests/ui/inline_fn_without_body.fixed deleted file mode 100644 index fe21a71a42c2..000000000000 --- a/tests/ui/inline_fn_without_body.fixed +++ /dev/null @@ -1,17 +0,0 @@ -// run-rustfix - -#![warn(clippy::inline_fn_without_body)] -#![allow(clippy::inline_always)] - -trait Foo { - fn default_inline(); - - fn always_inline(); - - fn never_inline(); - - #[inline] - fn has_body() {} -} - -fn main() {} diff --git a/tests/ui/inline_fn_without_body.rs b/tests/ui/inline_fn_without_body.rs deleted file mode 100644 index 507469894665..000000000000 --- a/tests/ui/inline_fn_without_body.rs +++ /dev/null @@ -1,20 +0,0 @@ -// run-rustfix - -#![warn(clippy::inline_fn_without_body)] -#![allow(clippy::inline_always)] - -trait Foo { - #[inline] - fn default_inline(); - - #[inline(always)] - fn always_inline(); - - #[inline(never)] - fn never_inline(); - - #[inline] - fn has_body() {} -} - -fn main() {} diff --git a/tests/ui/inline_fn_without_body.stderr b/tests/ui/inline_fn_without_body.stderr deleted file mode 100644 index 32d35e209b01..000000000000 --- a/tests/ui/inline_fn_without_body.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: use of `#[inline]` on trait method `default_inline` which has no body - --> $DIR/inline_fn_without_body.rs:7:5 - | -LL | #[inline] - | _____-^^^^^^^^ -LL | | fn default_inline(); - | |____- help: remove - | - = note: `-D clippy::inline-fn-without-body` implied by `-D warnings` - -error: use of `#[inline]` on trait method `always_inline` which has no body - --> $DIR/inline_fn_without_body.rs:10:5 - | -LL | #[inline(always)] - | _____-^^^^^^^^^^^^^^^^ -LL | | fn always_inline(); - | |____- help: remove - -error: use of `#[inline]` on trait method `never_inline` which has no body - --> $DIR/inline_fn_without_body.rs:13:5 - | -LL | #[inline(never)] - | _____-^^^^^^^^^^^^^^^ -LL | | fn never_inline(); - | |____- help: remove - -error: aborting due to 3 previous errors - diff --git a/tests/ui/int_plus_one.fixed b/tests/ui/int_plus_one.fixed deleted file mode 100644 index 642830f24f58..000000000000 --- a/tests/ui/int_plus_one.fixed +++ /dev/null @@ -1,17 +0,0 @@ -// run-rustfix - -#[allow(clippy::no_effect, clippy::unnecessary_operation)] -#[warn(clippy::int_plus_one)] -fn main() { - let x = 1i32; - let y = 0i32; - - let _ = x > y; - let _ = y < x; - - let _ = x > y; - let _ = y < x; - - let _ = x > y; // should be ok - let _ = y < x; // should be ok -} diff --git a/tests/ui/int_plus_one.rs b/tests/ui/int_plus_one.rs deleted file mode 100644 index 0755a0c79d28..000000000000 --- a/tests/ui/int_plus_one.rs +++ /dev/null @@ -1,17 +0,0 @@ -// run-rustfix - -#[allow(clippy::no_effect, clippy::unnecessary_operation)] -#[warn(clippy::int_plus_one)] -fn main() { - let x = 1i32; - let y = 0i32; - - let _ = x >= y + 1; - let _ = y + 1 <= x; - - let _ = x - 1 >= y; - let _ = y <= x - 1; - - let _ = x > y; // should be ok - let _ = y < x; // should be ok -} diff --git a/tests/ui/int_plus_one.stderr b/tests/ui/int_plus_one.stderr deleted file mode 100644 index c5b020ba8ced..000000000000 --- a/tests/ui/int_plus_one.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: unnecessary `>= y + 1` or `x - 1 >=` - --> $DIR/int_plus_one.rs:9:13 - | -LL | let _ = x >= y + 1; - | ^^^^^^^^^^ help: change it to: `x > y` - | - = note: `-D clippy::int-plus-one` implied by `-D warnings` - -error: unnecessary `>= y + 1` or `x - 1 >=` - --> $DIR/int_plus_one.rs:10:13 - | -LL | let _ = y + 1 <= x; - | ^^^^^^^^^^ help: change it to: `y < x` - -error: unnecessary `>= y + 1` or `x - 1 >=` - --> $DIR/int_plus_one.rs:12:13 - | -LL | let _ = x - 1 >= y; - | ^^^^^^^^^^ help: change it to: `x > y` - -error: unnecessary `>= y + 1` or `x - 1 >=` - --> $DIR/int_plus_one.rs:13:13 - | -LL | let _ = y <= x - 1; - | ^^^^^^^^^^ help: change it to: `y < x` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/integer_arithmetic.rs b/tests/ui/integer_arithmetic.rs deleted file mode 100644 index b74c93dc4a66..000000000000 --- a/tests/ui/integer_arithmetic.rs +++ /dev/null @@ -1,109 +0,0 @@ -#![warn(clippy::integer_arithmetic, clippy::float_arithmetic)] -#![allow( - unused, - clippy::shadow_reuse, - clippy::shadow_unrelated, - clippy::no_effect, - clippy::unnecessary_operation, - clippy::op_ref -)] - -#[rustfmt::skip] -fn main() { - let mut i = 1i32; - let mut var1 = 0i32; - let mut var2 = -1i32; - 1 + i; - i * 2; - 1 % - i / 2; // no error, this is part of the expression in the preceding line - i - 2 + 2 - i; - -i; - i >> 1; - i << 1; - - // no error, overflows are checked by `overflowing_literals` - -1; - -(-1); - - i & 1; // no wrapping - i | 1; - i ^ 1; - - i += 1; - i -= 1; - i *= 2; - i /= 2; - i /= 0; - i /= -1; - i /= var1; - i /= var2; - i %= 2; - i %= 0; - i %= -1; - i %= var1; - i %= var2; - i <<= 3; - i >>= 2; - - // no errors - i |= 1; - i &= 1; - i ^= i; - - // No errors for the following items because they are constant expressions - enum Foo { - Bar = -2, - } - struct Baz([i32; 1 + 1]); - union Qux { - field: [i32; 1 + 1], - } - type Alias = [i32; 1 + 1]; - - const FOO: i32 = -2; - static BAR: i32 = -2; - - let _: [i32; 1 + 1] = [0, 0]; - - let _: [i32; 1 + 1] = { - let a: [i32; 1 + 1] = [0, 0]; - a - }; - - trait Trait { - const ASSOC: i32 = 1 + 1; - } - - impl Trait for Foo { - const ASSOC: i32 = { - let _: [i32; 1 + 1]; - fn foo() {} - 1 + 1 - }; - } -} - -// warn on references as well! (#5328) -pub fn int_arith_ref() { - 3 + &1; - &3 + 1; - &3 + &1; -} - -pub fn foo(x: &i32) -> i32 { - let a = 5; - a + x -} - -pub fn bar(x: &i32, y: &i32) -> i32 { - x + y -} - -pub fn baz(x: i32, y: &i32) -> i32 { - x + y -} - -pub fn qux(x: i32, y: i32) -> i32 { - (&x + &y) -} diff --git a/tests/ui/integer_arithmetic.stderr b/tests/ui/integer_arithmetic.stderr deleted file mode 100644 index add3b6b90fa2..000000000000 --- a/tests/ui/integer_arithmetic.stderr +++ /dev/null @@ -1,169 +0,0 @@ -error: this operation will panic at runtime - --> $DIR/integer_arithmetic.rs:37:5 - | -LL | i /= 0; - | ^^^^^^ attempt to divide `_` by zero - | - = note: `#[deny(unconditional_panic)]` on by default - -error: this operation will panic at runtime - --> $DIR/integer_arithmetic.rs:42:5 - | -LL | i %= 0; - | ^^^^^^ attempt to calculate the remainder of `_` with a divisor of zero - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:16:5 - | -LL | 1 + i; - | ^^^^^ - | - = note: `-D clippy::integer-arithmetic` implied by `-D warnings` - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:17:5 - | -LL | i * 2; - | ^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:18:5 - | -LL | / 1 % -LL | | i / 2; // no error, this is part of the expression in the preceding line - | |_____^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:20:5 - | -LL | i - 2 + 2 - i; - | ^^^^^^^^^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:21:5 - | -LL | -i; - | ^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:22:5 - | -LL | i >> 1; - | ^^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:23:5 - | -LL | i << 1; - | ^^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:33:5 - | -LL | i += 1; - | ^^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:34:5 - | -LL | i -= 1; - | ^^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:35:5 - | -LL | i *= 2; - | ^^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:38:11 - | -LL | i /= -1; - | ^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:39:5 - | -LL | i /= var1; - | ^^^^^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:40:5 - | -LL | i /= var2; - | ^^^^^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:43:11 - | -LL | i %= -1; - | ^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:44:5 - | -LL | i %= var1; - | ^^^^^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:45:5 - | -LL | i %= var2; - | ^^^^^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:46:5 - | -LL | i <<= 3; - | ^^^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:47:5 - | -LL | i >>= 2; - | ^^^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:89:5 - | -LL | 3 + &1; - | ^^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:90:5 - | -LL | &3 + 1; - | ^^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:91:5 - | -LL | &3 + &1; - | ^^^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:96:5 - | -LL | a + x - | ^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:100:5 - | -LL | x + y - | ^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:104:5 - | -LL | x + y - | ^^^^^ - -error: integer arithmetic detected - --> $DIR/integer_arithmetic.rs:108:5 - | -LL | (&x + &y) - | ^^^^^^^^^ - -error: aborting due to 27 previous errors - diff --git a/tests/ui/integer_division.rs b/tests/ui/integer_division.rs deleted file mode 100644 index 800c75257524..000000000000 --- a/tests/ui/integer_division.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![warn(clippy::integer_division)] - -fn main() { - let two = 2; - let n = 1 / 2; - let o = 1 / two; - let p = two / 4; - let x = 1. / 2.0; -} diff --git a/tests/ui/integer_division.stderr b/tests/ui/integer_division.stderr deleted file mode 100644 index 72a232ef3d75..000000000000 --- a/tests/ui/integer_division.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error: integer division - --> $DIR/integer_division.rs:5:13 - | -LL | let n = 1 / 2; - | ^^^^^ - | - = note: `-D clippy::integer-division` implied by `-D warnings` - = help: division of integers may cause loss of precision. consider using floats. - -error: integer division - --> $DIR/integer_division.rs:6:13 - | -LL | let o = 1 / two; - | ^^^^^^^ - | - = help: division of integers may cause loss of precision. consider using floats. - -error: integer division - --> $DIR/integer_division.rs:7:13 - | -LL | let p = two / 4; - | ^^^^^^^ - | - = help: division of integers may cause loss of precision. consider using floats. - -error: aborting due to 3 previous errors - diff --git a/tests/ui/into_iter_on_ref.fixed b/tests/ui/into_iter_on_ref.fixed deleted file mode 100644 index 7f92d0dbdc97..000000000000 --- a/tests/ui/into_iter_on_ref.fixed +++ /dev/null @@ -1,45 +0,0 @@ -// run-rustfix -#![allow(clippy::useless_vec)] -#![warn(clippy::into_iter_on_ref)] - -struct X; -use std::collections::*; - -fn main() { - for _ in &[1, 2, 3] {} - for _ in vec![X, X] {} - for _ in &vec![X, X] {} - - let _ = vec![1, 2, 3].into_iter(); - let _ = (&vec![1, 2, 3]).iter(); //~ WARN equivalent to .iter() - let _ = vec![1, 2, 3].into_boxed_slice().iter(); //~ WARN equivalent to .iter() - let _ = std::rc::Rc::from(&[X][..]).iter(); //~ WARN equivalent to .iter() - let _ = std::sync::Arc::from(&[X][..]).iter(); //~ WARN equivalent to .iter() - - let _ = (&&&&&&&[1, 2, 3]).iter(); //~ ERROR equivalent to .iter() - let _ = (&&&&mut &&&[1, 2, 3]).iter(); //~ ERROR equivalent to .iter() - let _ = (&mut &mut &mut [1, 2, 3]).iter_mut(); //~ ERROR equivalent to .iter_mut() - - let _ = (&Some(4)).iter(); //~ WARN equivalent to .iter() - let _ = (&mut Some(5)).iter_mut(); //~ WARN equivalent to .iter_mut() - let _ = (&Ok::<_, i32>(6)).iter(); //~ WARN equivalent to .iter() - let _ = (&mut Err::(7)).iter_mut(); //~ WARN equivalent to .iter_mut() - let _ = (&Vec::::new()).iter(); //~ WARN equivalent to .iter() - let _ = (&mut Vec::::new()).iter_mut(); //~ WARN equivalent to .iter_mut() - let _ = (&BTreeMap::::new()).iter(); //~ WARN equivalent to .iter() - let _ = (&mut BTreeMap::::new()).iter_mut(); //~ WARN equivalent to .iter_mut() - let _ = (&VecDeque::::new()).iter(); //~ WARN equivalent to .iter() - let _ = (&mut VecDeque::::new()).iter_mut(); //~ WARN equivalent to .iter_mut() - let _ = (&LinkedList::::new()).iter(); //~ WARN equivalent to .iter() - let _ = (&mut LinkedList::::new()).iter_mut(); //~ WARN equivalent to .iter_mut() - let _ = (&HashMap::::new()).iter(); //~ WARN equivalent to .iter() - let _ = (&mut HashMap::::new()).iter_mut(); //~ WARN equivalent to .iter_mut() - - let _ = (&BTreeSet::::new()).iter(); //~ WARN equivalent to .iter() - let _ = (&BinaryHeap::::new()).iter(); //~ WARN equivalent to .iter() - let _ = (&HashSet::::new()).iter(); //~ WARN equivalent to .iter() - let _ = std::path::Path::new("12/34").iter(); //~ WARN equivalent to .iter() - let _ = std::path::PathBuf::from("12/34").iter(); //~ ERROR equivalent to .iter() - - let _ = (&[1, 2, 3]).iter().next(); //~ WARN equivalent to .iter() -} diff --git a/tests/ui/into_iter_on_ref.rs b/tests/ui/into_iter_on_ref.rs deleted file mode 100644 index 416056d3fdb9..000000000000 --- a/tests/ui/into_iter_on_ref.rs +++ /dev/null @@ -1,45 +0,0 @@ -// run-rustfix -#![allow(clippy::useless_vec)] -#![warn(clippy::into_iter_on_ref)] - -struct X; -use std::collections::*; - -fn main() { - for _ in &[1, 2, 3] {} - for _ in vec![X, X] {} - for _ in &vec![X, X] {} - - let _ = vec![1, 2, 3].into_iter(); - let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter() - let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); //~ WARN equivalent to .iter() - let _ = std::rc::Rc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter() - let _ = std::sync::Arc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter() - - let _ = (&&&&&&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter() - let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter() - let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter_mut() - - let _ = (&Some(4)).into_iter(); //~ WARN equivalent to .iter() - let _ = (&mut Some(5)).into_iter(); //~ WARN equivalent to .iter_mut() - let _ = (&Ok::<_, i32>(6)).into_iter(); //~ WARN equivalent to .iter() - let _ = (&mut Err::(7)).into_iter(); //~ WARN equivalent to .iter_mut() - let _ = (&Vec::::new()).into_iter(); //~ WARN equivalent to .iter() - let _ = (&mut Vec::::new()).into_iter(); //~ WARN equivalent to .iter_mut() - let _ = (&BTreeMap::::new()).into_iter(); //~ WARN equivalent to .iter() - let _ = (&mut BTreeMap::::new()).into_iter(); //~ WARN equivalent to .iter_mut() - let _ = (&VecDeque::::new()).into_iter(); //~ WARN equivalent to .iter() - let _ = (&mut VecDeque::::new()).into_iter(); //~ WARN equivalent to .iter_mut() - let _ = (&LinkedList::::new()).into_iter(); //~ WARN equivalent to .iter() - let _ = (&mut LinkedList::::new()).into_iter(); //~ WARN equivalent to .iter_mut() - let _ = (&HashMap::::new()).into_iter(); //~ WARN equivalent to .iter() - let _ = (&mut HashMap::::new()).into_iter(); //~ WARN equivalent to .iter_mut() - - let _ = (&BTreeSet::::new()).into_iter(); //~ WARN equivalent to .iter() - let _ = (&BinaryHeap::::new()).into_iter(); //~ WARN equivalent to .iter() - let _ = (&HashSet::::new()).into_iter(); //~ WARN equivalent to .iter() - let _ = std::path::Path::new("12/34").into_iter(); //~ WARN equivalent to .iter() - let _ = std::path::PathBuf::from("12/34").into_iter(); //~ ERROR equivalent to .iter() - - let _ = (&[1, 2, 3]).into_iter().next(); //~ WARN equivalent to .iter() -} diff --git a/tests/ui/into_iter_on_ref.stderr b/tests/ui/into_iter_on_ref.stderr deleted file mode 100644 index 28003b365bbd..000000000000 --- a/tests/ui/into_iter_on_ref.stderr +++ /dev/null @@ -1,166 +0,0 @@ -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Vec` - --> $DIR/into_iter_on_ref.rs:14:30 - | -LL | let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - | - = note: `-D clippy::into-iter-on-ref` implied by `-D warnings` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` - --> $DIR/into_iter_on_ref.rs:15:46 - | -LL | let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); //~ WARN equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` - --> $DIR/into_iter_on_ref.rs:16:41 - | -LL | let _ = std::rc::Rc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` - --> $DIR/into_iter_on_ref.rs:17:44 - | -LL | let _ = std::sync::Arc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `array` - --> $DIR/into_iter_on_ref.rs:19:32 - | -LL | let _ = (&&&&&&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `array` - --> $DIR/into_iter_on_ref.rs:20:36 - | -LL | let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `array` - --> $DIR/into_iter_on_ref.rs:21:40 - | -LL | let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter_mut() - | ^^^^^^^^^ help: call directly: `iter_mut` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Option` - --> $DIR/into_iter_on_ref.rs:23:24 - | -LL | let _ = (&Some(4)).into_iter(); //~ WARN equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `Option` - --> $DIR/into_iter_on_ref.rs:24:28 - | -LL | let _ = (&mut Some(5)).into_iter(); //~ WARN equivalent to .iter_mut() - | ^^^^^^^^^ help: call directly: `iter_mut` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Result` - --> $DIR/into_iter_on_ref.rs:25:32 - | -LL | let _ = (&Ok::<_, i32>(6)).into_iter(); //~ WARN equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `Result` - --> $DIR/into_iter_on_ref.rs:26:37 - | -LL | let _ = (&mut Err::(7)).into_iter(); //~ WARN equivalent to .iter_mut() - | ^^^^^^^^^ help: call directly: `iter_mut` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Vec` - --> $DIR/into_iter_on_ref.rs:27:34 - | -LL | let _ = (&Vec::::new()).into_iter(); //~ WARN equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `Vec` - --> $DIR/into_iter_on_ref.rs:28:38 - | -LL | let _ = (&mut Vec::::new()).into_iter(); //~ WARN equivalent to .iter_mut() - | ^^^^^^^^^ help: call directly: `iter_mut` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `BTreeMap` - --> $DIR/into_iter_on_ref.rs:29:44 - | -LL | let _ = (&BTreeMap::::new()).into_iter(); //~ WARN equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `BTreeMap` - --> $DIR/into_iter_on_ref.rs:30:48 - | -LL | let _ = (&mut BTreeMap::::new()).into_iter(); //~ WARN equivalent to .iter_mut() - | ^^^^^^^^^ help: call directly: `iter_mut` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `VecDeque` - --> $DIR/into_iter_on_ref.rs:31:39 - | -LL | let _ = (&VecDeque::::new()).into_iter(); //~ WARN equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `VecDeque` - --> $DIR/into_iter_on_ref.rs:32:43 - | -LL | let _ = (&mut VecDeque::::new()).into_iter(); //~ WARN equivalent to .iter_mut() - | ^^^^^^^^^ help: call directly: `iter_mut` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `LinkedList` - --> $DIR/into_iter_on_ref.rs:33:41 - | -LL | let _ = (&LinkedList::::new()).into_iter(); //~ WARN equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `LinkedList` - --> $DIR/into_iter_on_ref.rs:34:45 - | -LL | let _ = (&mut LinkedList::::new()).into_iter(); //~ WARN equivalent to .iter_mut() - | ^^^^^^^^^ help: call directly: `iter_mut` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `HashMap` - --> $DIR/into_iter_on_ref.rs:35:43 - | -LL | let _ = (&HashMap::::new()).into_iter(); //~ WARN equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `HashMap` - --> $DIR/into_iter_on_ref.rs:36:47 - | -LL | let _ = (&mut HashMap::::new()).into_iter(); //~ WARN equivalent to .iter_mut() - | ^^^^^^^^^ help: call directly: `iter_mut` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `BTreeSet` - --> $DIR/into_iter_on_ref.rs:38:39 - | -LL | let _ = (&BTreeSet::::new()).into_iter(); //~ WARN equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `BinaryHeap` - --> $DIR/into_iter_on_ref.rs:39:41 - | -LL | let _ = (&BinaryHeap::::new()).into_iter(); //~ WARN equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `HashSet` - --> $DIR/into_iter_on_ref.rs:40:38 - | -LL | let _ = (&HashSet::::new()).into_iter(); //~ WARN equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Path` - --> $DIR/into_iter_on_ref.rs:41:43 - | -LL | let _ = std::path::Path::new("12/34").into_iter(); //~ WARN equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `PathBuf` - --> $DIR/into_iter_on_ref.rs:42:47 - | -LL | let _ = std::path::PathBuf::from("12/34").into_iter(); //~ ERROR equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `array` - --> $DIR/into_iter_on_ref.rs:44:26 - | -LL | let _ = (&[1, 2, 3]).into_iter().next(); //~ WARN equivalent to .iter() - | ^^^^^^^^^ help: call directly: `iter` - -error: aborting due to 27 previous errors - diff --git a/tests/ui/invalid_upcast_comparisons.rs b/tests/ui/invalid_upcast_comparisons.rs deleted file mode 100644 index 697416dcee83..000000000000 --- a/tests/ui/invalid_upcast_comparisons.rs +++ /dev/null @@ -1,85 +0,0 @@ -#![warn(clippy::invalid_upcast_comparisons)] -#![allow( - unused, - clippy::eq_op, - clippy::no_effect, - clippy::unnecessary_operation, - clippy::cast_lossless -)] - -fn mk_value() -> T { - unimplemented!() -} - -fn main() { - let u32: u32 = mk_value(); - let u8: u8 = mk_value(); - let i32: i32 = mk_value(); - let i8: i8 = mk_value(); - - // always false, since no u8 can be > 300 - (u8 as u32) > 300; - (u8 as i32) > 300; - (u8 as u32) == 300; - (u8 as i32) == 300; - 300 < (u8 as u32); - 300 < (u8 as i32); - 300 == (u8 as u32); - 300 == (u8 as i32); - // inverted of the above - (u8 as u32) <= 300; - (u8 as i32) <= 300; - (u8 as u32) != 300; - (u8 as i32) != 300; - 300 >= (u8 as u32); - 300 >= (u8 as i32); - 300 != (u8 as u32); - 300 != (u8 as i32); - - // always false, since u8 -> i32 doesn't wrap - (u8 as i32) < 0; - -5 != (u8 as i32); - // inverted of the above - (u8 as i32) >= 0; - -5 == (u8 as i32); - - // always false, since no u8 can be 1337 - 1337 == (u8 as i32); - 1337 == (u8 as u32); - // inverted of the above - 1337 != (u8 as i32); - 1337 != (u8 as u32); - - // Those are Ok: - (u8 as u32) > 20; - 42 == (u8 as i32); - 42 != (u8 as i32); - 42 > (u8 as i32); - (u8 as i32) == 42; - (u8 as i32) != 42; - (u8 as i32) > 42; - (u8 as i32) < 42; - - (u8 as i8) == -1; - (u8 as i8) != -1; - (u8 as i32) > -1; - (u8 as i32) < -1; - (u32 as i32) < -5; - (u32 as i32) < 10; - - (i8 as u8) == 1; - (i8 as u8) != 1; - (i8 as u8) < 1; - (i8 as u8) > 1; - (i32 as u32) < 5; - (i32 as u32) < 10; - - -5 < (u32 as i32); - 0 <= (u32 as i32); - 0 < (u32 as i32); - - -5 > (u32 as i32); - -5 >= (u8 as i32); - - -5 == (u32 as i32); -} diff --git a/tests/ui/invalid_upcast_comparisons.stderr b/tests/ui/invalid_upcast_comparisons.stderr deleted file mode 100644 index 03c3fb80aaab..000000000000 --- a/tests/ui/invalid_upcast_comparisons.stderr +++ /dev/null @@ -1,166 +0,0 @@ -error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:21:5 - | -LL | (u8 as u32) > 300; - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-upcast-comparisons` implied by `-D warnings` - -error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:22:5 - | -LL | (u8 as i32) > 300; - | ^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:23:5 - | -LL | (u8 as u32) == 300; - | ^^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:24:5 - | -LL | (u8 as i32) == 300; - | ^^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:25:5 - | -LL | 300 < (u8 as u32); - | ^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:26:5 - | -LL | 300 < (u8 as i32); - | ^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:27:5 - | -LL | 300 == (u8 as u32); - | ^^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:28:5 - | -LL | 300 == (u8 as i32); - | ^^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:30:5 - | -LL | (u8 as u32) <= 300; - | ^^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:31:5 - | -LL | (u8 as i32) <= 300; - | ^^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:32:5 - | -LL | (u8 as u32) != 300; - | ^^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:33:5 - | -LL | (u8 as i32) != 300; - | ^^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:34:5 - | -LL | 300 >= (u8 as u32); - | ^^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:35:5 - | -LL | 300 >= (u8 as i32); - | ^^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:36:5 - | -LL | 300 != (u8 as u32); - | ^^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:37:5 - | -LL | 300 != (u8 as i32); - | ^^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:40:5 - | -LL | (u8 as i32) < 0; - | ^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:41:5 - | -LL | -5 != (u8 as i32); - | ^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:43:5 - | -LL | (u8 as i32) >= 0; - | ^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:44:5 - | -LL | -5 == (u8 as i32); - | ^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:47:5 - | -LL | 1337 == (u8 as i32); - | ^^^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:48:5 - | -LL | 1337 == (u8 as u32); - | ^^^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:50:5 - | -LL | 1337 != (u8 as i32); - | ^^^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:51:5 - | -LL | 1337 != (u8 as u32); - | ^^^^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:65:5 - | -LL | (u8 as i32) > -1; - | ^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:66:5 - | -LL | (u8 as i32) < -1; - | ^^^^^^^^^^^^^^^^ - -error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:82:5 - | -LL | -5 >= (u8 as i32); - | ^^^^^^^^^^^^^^^^^ - -error: aborting due to 27 previous errors - diff --git a/tests/ui/issue-3145.rs b/tests/ui/issue-3145.rs deleted file mode 100644 index 586d13647d15..000000000000 --- a/tests/ui/issue-3145.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("{}" a); //~ERROR expected `,`, found `a` -} diff --git a/tests/ui/issue-3145.stderr b/tests/ui/issue-3145.stderr deleted file mode 100644 index a35032aa150d..000000000000 --- a/tests/ui/issue-3145.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: expected `,`, found `a` - --> $DIR/issue-3145.rs:2:19 - | -LL | println!("{}" a); //~ERROR expected `,`, found `a` - | ^ expected `,` - -error: aborting due to previous error - diff --git a/tests/ui/issue_2356.rs b/tests/ui/issue_2356.rs deleted file mode 100644 index da580a1839a1..000000000000 --- a/tests/ui/issue_2356.rs +++ /dev/null @@ -1,24 +0,0 @@ -#![deny(clippy::while_let_on_iterator)] - -use std::iter::Iterator; - -struct Foo; - -impl Foo { - fn foo1>(mut it: I) { - while let Some(_) = it.next() { - println!("{:?}", it.size_hint()); - } - } - - fn foo2>(mut it: I) { - while let Some(e) = it.next() { - println!("{:?}", e); - } - } -} - -fn main() { - Foo::foo1(vec![].into_iter()); - Foo::foo2(vec![].into_iter()); -} diff --git a/tests/ui/issue_2356.stderr b/tests/ui/issue_2356.stderr deleted file mode 100644 index 51b872e21c08..000000000000 --- a/tests/ui/issue_2356.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: this loop could be written as a `for` loop - --> $DIR/issue_2356.rs:15:9 - | -LL | while let Some(e) = it.next() { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for e in it` - | -note: the lint level is defined here - --> $DIR/issue_2356.rs:1:9 - | -LL | #![deny(clippy::while_let_on_iterator)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/tests/ui/issue_4266.rs b/tests/ui/issue_4266.rs deleted file mode 100644 index 8a9d5a3d1d56..000000000000 --- a/tests/ui/issue_4266.rs +++ /dev/null @@ -1,37 +0,0 @@ -// edition:2018 -#![allow(dead_code)] - -async fn sink1<'a>(_: &'a str) {} // lint -async fn sink1_elided(_: &str) {} // ok - -// lint -async fn one_to_one<'a>(s: &'a str) -> &'a str { - s -} - -// ok -async fn one_to_one_elided(s: &str) -> &str { - s -} - -// ok -async fn all_to_one<'a>(a: &'a str, _b: &'a str) -> &'a str { - a -} - -// async fn unrelated(_: &str, _: &str) {} // Not allowed in async fn - -// #3988 -struct Foo; -impl Foo { - // ok - pub async fn foo(&mut self) {} -} - -// rust-lang/rust#61115 -// ok -async fn print(s: &str) { - println!("{}", s); -} - -fn main() {} diff --git a/tests/ui/issue_4266.stderr b/tests/ui/issue_4266.stderr deleted file mode 100644 index 0426508e622f..000000000000 --- a/tests/ui/issue_4266.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/issue_4266.rs:4:1 - | -LL | async fn sink1<'a>(_: &'a str) {} // lint - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::needless-lifetimes` implied by `-D warnings` - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/issue_4266.rs:8:1 - | -LL | async fn one_to_one<'a>(s: &'a str) -> &'a str { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/item_after_statement.rs b/tests/ui/item_after_statement.rs deleted file mode 100644 index d439ca1e4e1a..000000000000 --- a/tests/ui/item_after_statement.rs +++ /dev/null @@ -1,52 +0,0 @@ -#![warn(clippy::items_after_statements)] - -fn ok() { - fn foo() { - println!("foo"); - } - foo(); -} - -fn last() { - foo(); - fn foo() { - println!("foo"); - } -} - -fn main() { - foo(); - fn foo() { - println!("foo"); - } - foo(); -} - -fn mac() { - let mut a = 5; - println!("{}", a); - // do not lint this, because it needs to be after `a` - macro_rules! b { - () => {{ - a = 6; - fn say_something() { - println!("something"); - } - }}; - } - b!(); - println!("{}", a); -} - -fn semicolon() { - struct S { - a: u32, - }; - impl S { - fn new(a: u32) -> Self { - Self { a } - } - } - - let _ = S::new(3); -} diff --git a/tests/ui/item_after_statement.stderr b/tests/ui/item_after_statement.stderr deleted file mode 100644 index 68a3c81b6a80..000000000000 --- a/tests/ui/item_after_statement.stderr +++ /dev/null @@ -1,33 +0,0 @@ -error: adding items after statements is confusing, since items exist from the start of the scope - --> $DIR/item_after_statement.rs:12:5 - | -LL | / fn foo() { -LL | | println!("foo"); -LL | | } - | |_____^ - | - = note: `-D clippy::items-after-statements` implied by `-D warnings` - -error: adding items after statements is confusing, since items exist from the start of the scope - --> $DIR/item_after_statement.rs:19:5 - | -LL | / fn foo() { -LL | | println!("foo"); -LL | | } - | |_____^ - -error: adding items after statements is confusing, since items exist from the start of the scope - --> $DIR/item_after_statement.rs:32:13 - | -LL | / fn say_something() { -LL | | println!("something"); -LL | | } - | |_____________^ -... -LL | b!(); - | ----- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 3 previous errors - diff --git a/tests/ui/iter_cloned_collect.fixed b/tests/ui/iter_cloned_collect.fixed deleted file mode 100644 index 2773227e26bc..000000000000 --- a/tests/ui/iter_cloned_collect.fixed +++ /dev/null @@ -1,22 +0,0 @@ -// run-rustfix - -#![allow(unused)] - -use std::collections::HashSet; -use std::collections::VecDeque; - -fn main() { - let v = [1, 2, 3, 4, 5]; - let v2: Vec = v.to_vec(); - let v3: HashSet = v.iter().cloned().collect(); - let v4: VecDeque = v.iter().cloned().collect(); - - // Handle macro expansion in suggestion - let _: Vec = vec![1, 2, 3].to_vec(); - - // Issue #3704 - unsafe { - let _: Vec = std::ffi::CStr::from_ptr(std::ptr::null()) - .to_bytes().to_vec(); - } -} diff --git a/tests/ui/iter_cloned_collect.rs b/tests/ui/iter_cloned_collect.rs deleted file mode 100644 index 60a4eac23c79..000000000000 --- a/tests/ui/iter_cloned_collect.rs +++ /dev/null @@ -1,25 +0,0 @@ -// run-rustfix - -#![allow(unused)] - -use std::collections::HashSet; -use std::collections::VecDeque; - -fn main() { - let v = [1, 2, 3, 4, 5]; - let v2: Vec = v.iter().cloned().collect(); - let v3: HashSet = v.iter().cloned().collect(); - let v4: VecDeque = v.iter().cloned().collect(); - - // Handle macro expansion in suggestion - let _: Vec = vec![1, 2, 3].iter().cloned().collect(); - - // Issue #3704 - unsafe { - let _: Vec = std::ffi::CStr::from_ptr(std::ptr::null()) - .to_bytes() - .iter() - .cloned() - .collect(); - } -} diff --git a/tests/ui/iter_cloned_collect.stderr b/tests/ui/iter_cloned_collect.stderr deleted file mode 100644 index b90a1e6c9196..000000000000 --- a/tests/ui/iter_cloned_collect.stderr +++ /dev/null @@ -1,26 +0,0 @@ -error: called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable - --> $DIR/iter_cloned_collect.rs:10:27 - | -LL | let v2: Vec = v.iter().cloned().collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()` - | - = note: `-D clippy::iter-cloned-collect` implied by `-D warnings` - -error: called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable - --> $DIR/iter_cloned_collect.rs:15:38 - | -LL | let _: Vec = vec![1, 2, 3].iter().cloned().collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()` - -error: called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable - --> $DIR/iter_cloned_collect.rs:20:24 - | -LL | .to_bytes() - | ________________________^ -LL | | .iter() -LL | | .cloned() -LL | | .collect(); - | |______________________^ help: try: `.to_vec()` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/iter_next_slice.fixed b/tests/ui/iter_next_slice.fixed deleted file mode 100644 index 79c1db87ac3c..000000000000 --- a/tests/ui/iter_next_slice.fixed +++ /dev/null @@ -1,24 +0,0 @@ -// run-rustfix -#![warn(clippy::iter_next_slice)] - -fn main() { - // test code goes here - let s = [1, 2, 3]; - let v = vec![1, 2, 3]; - - s.get(0); - // Should be replaced by s.get(0) - - s.get(2); - // Should be replaced by s.get(2) - - v.get(5); - // Should be replaced by v.get(5) - - v.get(0); - // Should be replaced by v.get(0) - - let o = Some(5); - o.iter().next(); - // Shouldn't be linted since this is not a Slice or an Array -} diff --git a/tests/ui/iter_next_slice.rs b/tests/ui/iter_next_slice.rs deleted file mode 100644 index ef9a55f3d997..000000000000 --- a/tests/ui/iter_next_slice.rs +++ /dev/null @@ -1,24 +0,0 @@ -// run-rustfix -#![warn(clippy::iter_next_slice)] - -fn main() { - // test code goes here - let s = [1, 2, 3]; - let v = vec![1, 2, 3]; - - s.iter().next(); - // Should be replaced by s.get(0) - - s[2..].iter().next(); - // Should be replaced by s.get(2) - - v[5..].iter().next(); - // Should be replaced by v.get(5) - - v.iter().next(); - // Should be replaced by v.get(0) - - let o = Some(5); - o.iter().next(); - // Shouldn't be linted since this is not a Slice or an Array -} diff --git a/tests/ui/iter_next_slice.stderr b/tests/ui/iter_next_slice.stderr deleted file mode 100644 index 8c10a252ee01..000000000000 --- a/tests/ui/iter_next_slice.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: using `.iter().next()` on an array - --> $DIR/iter_next_slice.rs:9:5 - | -LL | s.iter().next(); - | ^^^^^^^^^^^^^^^ help: try calling: `s.get(0)` - | - = note: `-D clippy::iter-next-slice` implied by `-D warnings` - -error: using `.iter().next()` on a Slice without end index - --> $DIR/iter_next_slice.rs:12:5 - | -LL | s[2..].iter().next(); - | ^^^^^^^^^^^^^^^^^^^^ help: try calling: `s.get(2)` - -error: using `.iter().next()` on a Slice without end index - --> $DIR/iter_next_slice.rs:15:5 - | -LL | v[5..].iter().next(); - | ^^^^^^^^^^^^^^^^^^^^ help: try calling: `v.get(5)` - -error: using `.iter().next()` on an array - --> $DIR/iter_next_slice.rs:18:5 - | -LL | v.iter().next(); - | ^^^^^^^^^^^^^^^ help: try calling: `v.get(0)` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/iter_nth.rs b/tests/ui/iter_nth.rs deleted file mode 100644 index 9c21dd82ee45..000000000000 --- a/tests/ui/iter_nth.rs +++ /dev/null @@ -1,56 +0,0 @@ -// aux-build:option_helpers.rs - -#![warn(clippy::iter_nth)] - -#[macro_use] -extern crate option_helpers; - -use option_helpers::IteratorFalsePositives; -use std::collections::VecDeque; - -/// Struct to generate false positives for things with `.iter()`. -#[derive(Copy, Clone)] -struct HasIter; - -impl HasIter { - fn iter(self) -> IteratorFalsePositives { - IteratorFalsePositives { foo: 0 } - } - - fn iter_mut(self) -> IteratorFalsePositives { - IteratorFalsePositives { foo: 0 } - } -} - -/// Checks implementation of `ITER_NTH` lint. -fn iter_nth() { - let mut some_vec = vec![0, 1, 2, 3]; - let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); - let mut some_vec_deque: VecDeque<_> = some_vec.iter().cloned().collect(); - - { - // Make sure we lint `.iter()` for relevant types. - let bad_vec = some_vec.iter().nth(3); - let bad_slice = &some_vec[..].iter().nth(3); - let bad_boxed_slice = boxed_slice.iter().nth(3); - let bad_vec_deque = some_vec_deque.iter().nth(3); - } - - { - // Make sure we lint `.iter_mut()` for relevant types. - let bad_vec = some_vec.iter_mut().nth(3); - } - { - let bad_slice = &some_vec[..].iter_mut().nth(3); - } - { - let bad_vec_deque = some_vec_deque.iter_mut().nth(3); - } - - // Make sure we don't lint for non-relevant types. - let false_positive = HasIter; - let ok = false_positive.iter().nth(3); - let ok_mut = false_positive.iter_mut().nth(3); -} - -fn main() {} diff --git a/tests/ui/iter_nth.stderr b/tests/ui/iter_nth.stderr deleted file mode 100644 index d00b2fb672bb..000000000000 --- a/tests/ui/iter_nth.stderr +++ /dev/null @@ -1,59 +0,0 @@ -error: called `.iter().nth()` on a Vec - --> $DIR/iter_nth.rs:33:23 - | -LL | let bad_vec = some_vec.iter().nth(3); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::iter-nth` implied by `-D warnings` - = help: calling `.get()` is both faster and more readable - -error: called `.iter().nth()` on a slice - --> $DIR/iter_nth.rs:34:26 - | -LL | let bad_slice = &some_vec[..].iter().nth(3); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: calling `.get()` is both faster and more readable - -error: called `.iter().nth()` on a slice - --> $DIR/iter_nth.rs:35:31 - | -LL | let bad_boxed_slice = boxed_slice.iter().nth(3); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: calling `.get()` is both faster and more readable - -error: called `.iter().nth()` on a VecDeque - --> $DIR/iter_nth.rs:36:29 - | -LL | let bad_vec_deque = some_vec_deque.iter().nth(3); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: calling `.get()` is both faster and more readable - -error: called `.iter_mut().nth()` on a Vec - --> $DIR/iter_nth.rs:41:23 - | -LL | let bad_vec = some_vec.iter_mut().nth(3); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: calling `.get_mut()` is both faster and more readable - -error: called `.iter_mut().nth()` on a slice - --> $DIR/iter_nth.rs:44:26 - | -LL | let bad_slice = &some_vec[..].iter_mut().nth(3); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: calling `.get_mut()` is both faster and more readable - -error: called `.iter_mut().nth()` on a VecDeque - --> $DIR/iter_nth.rs:47:29 - | -LL | let bad_vec_deque = some_vec_deque.iter_mut().nth(3); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: calling `.get_mut()` is both faster and more readable - -error: aborting due to 7 previous errors - diff --git a/tests/ui/iter_nth_zero.fixed b/tests/ui/iter_nth_zero.fixed deleted file mode 100644 index b54147c94d19..000000000000 --- a/tests/ui/iter_nth_zero.fixed +++ /dev/null @@ -1,31 +0,0 @@ -// run-rustfix - -#![warn(clippy::iter_nth_zero)] -use std::collections::HashSet; - -struct Foo {} - -impl Foo { - fn nth(&self, index: usize) -> usize { - index + 1 - } -} - -fn main() { - let f = Foo {}; - f.nth(0); // lint does not apply here - - let mut s = HashSet::new(); - s.insert(1); - let _x = s.iter().next(); - - let mut s2 = HashSet::new(); - s2.insert(2); - let mut iter = s2.iter(); - let _y = iter.next(); - - let mut s3 = HashSet::new(); - s3.insert(3); - let mut iter2 = s3.iter(); - let _unwrapped = iter2.next().unwrap(); -} diff --git a/tests/ui/iter_nth_zero.rs b/tests/ui/iter_nth_zero.rs deleted file mode 100644 index b92c7d18adb4..000000000000 --- a/tests/ui/iter_nth_zero.rs +++ /dev/null @@ -1,31 +0,0 @@ -// run-rustfix - -#![warn(clippy::iter_nth_zero)] -use std::collections::HashSet; - -struct Foo {} - -impl Foo { - fn nth(&self, index: usize) -> usize { - index + 1 - } -} - -fn main() { - let f = Foo {}; - f.nth(0); // lint does not apply here - - let mut s = HashSet::new(); - s.insert(1); - let _x = s.iter().nth(0); - - let mut s2 = HashSet::new(); - s2.insert(2); - let mut iter = s2.iter(); - let _y = iter.nth(0); - - let mut s3 = HashSet::new(); - s3.insert(3); - let mut iter2 = s3.iter(); - let _unwrapped = iter2.nth(0).unwrap(); -} diff --git a/tests/ui/iter_nth_zero.stderr b/tests/ui/iter_nth_zero.stderr deleted file mode 100644 index 29c56f3a94f5..000000000000 --- a/tests/ui/iter_nth_zero.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent - --> $DIR/iter_nth_zero.rs:20:14 - | -LL | let _x = s.iter().nth(0); - | ^^^^^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `s.iter().next()` - | - = note: `-D clippy::iter-nth-zero` implied by `-D warnings` - -error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent - --> $DIR/iter_nth_zero.rs:25:14 - | -LL | let _y = iter.nth(0); - | ^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `iter.next()` - -error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent - --> $DIR/iter_nth_zero.rs:30:22 - | -LL | let _unwrapped = iter2.nth(0).unwrap(); - | ^^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `iter2.next()` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/iter_skip_next.fixed b/tests/ui/iter_skip_next.fixed deleted file mode 100644 index 928b6acb9510..000000000000 --- a/tests/ui/iter_skip_next.fixed +++ /dev/null @@ -1,22 +0,0 @@ -// run-rustfix -// aux-build:option_helpers.rs - -#![warn(clippy::iter_skip_next)] -#![allow(clippy::blacklisted_name)] -#![allow(clippy::iter_nth)] - -extern crate option_helpers; - -use option_helpers::IteratorFalsePositives; - -/// Checks implementation of `ITER_SKIP_NEXT` lint -fn main() { - let some_vec = vec![0, 1, 2, 3]; - let _ = some_vec.iter().nth(42); - let _ = some_vec.iter().cycle().nth(42); - let _ = (1..10).nth(10); - let _ = &some_vec[..].iter().nth(3); - let foo = IteratorFalsePositives { foo: 0 }; - let _ = foo.skip(42).next(); - let _ = foo.filter().skip(42).next(); -} diff --git a/tests/ui/iter_skip_next.rs b/tests/ui/iter_skip_next.rs deleted file mode 100644 index 7075e2598ebe..000000000000 --- a/tests/ui/iter_skip_next.rs +++ /dev/null @@ -1,22 +0,0 @@ -// run-rustfix -// aux-build:option_helpers.rs - -#![warn(clippy::iter_skip_next)] -#![allow(clippy::blacklisted_name)] -#![allow(clippy::iter_nth)] - -extern crate option_helpers; - -use option_helpers::IteratorFalsePositives; - -/// Checks implementation of `ITER_SKIP_NEXT` lint -fn main() { - let some_vec = vec![0, 1, 2, 3]; - let _ = some_vec.iter().skip(42).next(); - let _ = some_vec.iter().cycle().skip(42).next(); - let _ = (1..10).skip(10).next(); - let _ = &some_vec[..].iter().skip(3).next(); - let foo = IteratorFalsePositives { foo: 0 }; - let _ = foo.skip(42).next(); - let _ = foo.filter().skip(42).next(); -} diff --git a/tests/ui/iter_skip_next.stderr b/tests/ui/iter_skip_next.stderr deleted file mode 100644 index 486de718bb56..000000000000 --- a/tests/ui/iter_skip_next.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next.rs:15:28 - | -LL | let _ = some_vec.iter().skip(42).next(); - | ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)` - | - = note: `-D clippy::iter-skip-next` implied by `-D warnings` - -error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next.rs:16:36 - | -LL | let _ = some_vec.iter().cycle().skip(42).next(); - | ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)` - -error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next.rs:17:20 - | -LL | let _ = (1..10).skip(10).next(); - | ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(10)` - -error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next.rs:18:33 - | -LL | let _ = &some_vec[..].iter().skip(3).next(); - | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(3)` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/iterator_step_by_zero.rs b/tests/ui/iterator_step_by_zero.rs deleted file mode 100644 index 13d1cfd42818..000000000000 --- a/tests/ui/iterator_step_by_zero.rs +++ /dev/null @@ -1,28 +0,0 @@ -#[warn(clippy::iterator_step_by_zero)] -fn main() { - let _ = vec!["A", "B", "B"].iter().step_by(0); - let _ = "XXX".chars().step_by(0); - let _ = (0..1).step_by(0); - - // No error, not an iterator. - let y = NotIterator; - y.step_by(0); - - // No warning for non-zero step - let _ = (0..1).step_by(1); - - let _ = (1..).step_by(0); - let _ = (1..=2).step_by(0); - - let x = 0..1; - let _ = x.step_by(0); - - // check const eval - let v1 = vec![1, 2, 3]; - let _ = v1.iter().step_by(2 / 3); -} - -struct NotIterator; -impl NotIterator { - fn step_by(&self, _: u32) {} -} diff --git a/tests/ui/iterator_step_by_zero.stderr b/tests/ui/iterator_step_by_zero.stderr deleted file mode 100644 index c2c6803b3e6e..000000000000 --- a/tests/ui/iterator_step_by_zero.stderr +++ /dev/null @@ -1,46 +0,0 @@ -error: Iterator::step_by(0) will panic at runtime - --> $DIR/iterator_step_by_zero.rs:3:13 - | -LL | let _ = vec!["A", "B", "B"].iter().step_by(0); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::iterator-step-by-zero` implied by `-D warnings` - -error: Iterator::step_by(0) will panic at runtime - --> $DIR/iterator_step_by_zero.rs:4:13 - | -LL | let _ = "XXX".chars().step_by(0); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: Iterator::step_by(0) will panic at runtime - --> $DIR/iterator_step_by_zero.rs:5:13 - | -LL | let _ = (0..1).step_by(0); - | ^^^^^^^^^^^^^^^^^ - -error: Iterator::step_by(0) will panic at runtime - --> $DIR/iterator_step_by_zero.rs:14:13 - | -LL | let _ = (1..).step_by(0); - | ^^^^^^^^^^^^^^^^ - -error: Iterator::step_by(0) will panic at runtime - --> $DIR/iterator_step_by_zero.rs:15:13 - | -LL | let _ = (1..=2).step_by(0); - | ^^^^^^^^^^^^^^^^^^ - -error: Iterator::step_by(0) will panic at runtime - --> $DIR/iterator_step_by_zero.rs:18:13 - | -LL | let _ = x.step_by(0); - | ^^^^^^^^^^^^ - -error: Iterator::step_by(0) will panic at runtime - --> $DIR/iterator_step_by_zero.rs:22:13 - | -LL | let _ = v1.iter().step_by(2 / 3); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 7 previous errors - diff --git a/tests/ui/large_const_arrays.fixed b/tests/ui/large_const_arrays.fixed deleted file mode 100644 index c5af07c8a172..000000000000 --- a/tests/ui/large_const_arrays.fixed +++ /dev/null @@ -1,37 +0,0 @@ -// run-rustfix - -#![warn(clippy::large_const_arrays)] -#![allow(dead_code)] - -#[derive(Clone, Copy)] -pub struct S { - pub data: [u64; 32], -} - -// Should lint -pub(crate) static FOO_PUB_CRATE: [u32; 1_000_000] = [0u32; 1_000_000]; -pub static FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; -static FOO: [u32; 1_000_000] = [0u32; 1_000_000]; - -// Good -pub(crate) const G_FOO_PUB_CRATE: [u32; 1_000] = [0u32; 1_000]; -pub const G_FOO_PUB: [u32; 1_000] = [0u32; 1_000]; -const G_FOO: [u32; 1_000] = [0u32; 1_000]; - -fn main() { - // Should lint - pub static BAR_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; - static BAR: [u32; 1_000_000] = [0u32; 1_000_000]; - pub static BAR_STRUCT_PUB: [S; 5_000] = [S { data: [0; 32] }; 5_000]; - static BAR_STRUCT: [S; 5_000] = [S { data: [0; 32] }; 5_000]; - pub static BAR_S_PUB: [Option<&str>; 200_000] = [Some("str"); 200_000]; - static BAR_S: [Option<&str>; 200_000] = [Some("str"); 200_000]; - - // Good - pub const G_BAR_PUB: [u32; 1_000] = [0u32; 1_000]; - const G_BAR: [u32; 1_000] = [0u32; 1_000]; - pub const G_BAR_STRUCT_PUB: [S; 500] = [S { data: [0; 32] }; 500]; - const G_BAR_STRUCT: [S; 500] = [S { data: [0; 32] }; 500]; - pub const G_BAR_S_PUB: [Option<&str>; 200] = [Some("str"); 200]; - const G_BAR_S: [Option<&str>; 200] = [Some("str"); 200]; -} diff --git a/tests/ui/large_const_arrays.rs b/tests/ui/large_const_arrays.rs deleted file mode 100644 index a160b9f8ad5b..000000000000 --- a/tests/ui/large_const_arrays.rs +++ /dev/null @@ -1,37 +0,0 @@ -// run-rustfix - -#![warn(clippy::large_const_arrays)] -#![allow(dead_code)] - -#[derive(Clone, Copy)] -pub struct S { - pub data: [u64; 32], -} - -// Should lint -pub(crate) const FOO_PUB_CRATE: [u32; 1_000_000] = [0u32; 1_000_000]; -pub const FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; -const FOO: [u32; 1_000_000] = [0u32; 1_000_000]; - -// Good -pub(crate) const G_FOO_PUB_CRATE: [u32; 1_000] = [0u32; 1_000]; -pub const G_FOO_PUB: [u32; 1_000] = [0u32; 1_000]; -const G_FOO: [u32; 1_000] = [0u32; 1_000]; - -fn main() { - // Should lint - pub const BAR_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; - const BAR: [u32; 1_000_000] = [0u32; 1_000_000]; - pub const BAR_STRUCT_PUB: [S; 5_000] = [S { data: [0; 32] }; 5_000]; - const BAR_STRUCT: [S; 5_000] = [S { data: [0; 32] }; 5_000]; - pub const BAR_S_PUB: [Option<&str>; 200_000] = [Some("str"); 200_000]; - const BAR_S: [Option<&str>; 200_000] = [Some("str"); 200_000]; - - // Good - pub const G_BAR_PUB: [u32; 1_000] = [0u32; 1_000]; - const G_BAR: [u32; 1_000] = [0u32; 1_000]; - pub const G_BAR_STRUCT_PUB: [S; 500] = [S { data: [0; 32] }; 500]; - const G_BAR_STRUCT: [S; 500] = [S { data: [0; 32] }; 500]; - pub const G_BAR_S_PUB: [Option<&str>; 200] = [Some("str"); 200]; - const G_BAR_S: [Option<&str>; 200] = [Some("str"); 200]; -} diff --git a/tests/ui/large_const_arrays.stderr b/tests/ui/large_const_arrays.stderr deleted file mode 100644 index 3fb0acbca67d..000000000000 --- a/tests/ui/large_const_arrays.stderr +++ /dev/null @@ -1,76 +0,0 @@ -error: large array defined as const - --> $DIR/large_const_arrays.rs:12:1 - | -LL | pub(crate) const FOO_PUB_CRATE: [u32; 1_000_000] = [0u32; 1_000_000]; - | ^^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | help: make this a static item: `static` - | - = note: `-D clippy::large-const-arrays` implied by `-D warnings` - -error: large array defined as const - --> $DIR/large_const_arrays.rs:13:1 - | -LL | pub const FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; - | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | help: make this a static item: `static` - -error: large array defined as const - --> $DIR/large_const_arrays.rs:14:1 - | -LL | const FOO: [u32; 1_000_000] = [0u32; 1_000_000]; - | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | help: make this a static item: `static` - -error: large array defined as const - --> $DIR/large_const_arrays.rs:23:5 - | -LL | pub const BAR_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; - | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | help: make this a static item: `static` - -error: large array defined as const - --> $DIR/large_const_arrays.rs:24:5 - | -LL | const BAR: [u32; 1_000_000] = [0u32; 1_000_000]; - | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | help: make this a static item: `static` - -error: large array defined as const - --> $DIR/large_const_arrays.rs:25:5 - | -LL | pub const BAR_STRUCT_PUB: [S; 5_000] = [S { data: [0; 32] }; 5_000]; - | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | help: make this a static item: `static` - -error: large array defined as const - --> $DIR/large_const_arrays.rs:26:5 - | -LL | const BAR_STRUCT: [S; 5_000] = [S { data: [0; 32] }; 5_000]; - | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | help: make this a static item: `static` - -error: large array defined as const - --> $DIR/large_const_arrays.rs:27:5 - | -LL | pub const BAR_S_PUB: [Option<&str>; 200_000] = [Some("str"); 200_000]; - | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | help: make this a static item: `static` - -error: large array defined as const - --> $DIR/large_const_arrays.rs:28:5 - | -LL | const BAR_S: [Option<&str>; 200_000] = [Some("str"); 200_000]; - | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | help: make this a static item: `static` - -error: aborting due to 9 previous errors - diff --git a/tests/ui/large_digit_groups.fixed b/tests/ui/large_digit_groups.fixed deleted file mode 100644 index 3430c137ec22..000000000000 --- a/tests/ui/large_digit_groups.fixed +++ /dev/null @@ -1,31 +0,0 @@ -// run-rustfix -#![warn(clippy::large_digit_groups)] - -fn main() { - macro_rules! mac { - () => { - 0b1_10110_i64 - }; - } - - let _good = ( - 0b1011_i64, - 0o1_234_u32, - 0x0123_4567, - 1_2345_6789, - 1234_f32, - 1_234.12_f32, - 1_234.123_f32, - 1.123_4_f32, - ); - let _bad = ( - 0b11_0110_i64, - 0xdead_beef_usize, - 123_456_f32, - 123_456.12_f32, - 123_456.123_45_f64, - 123_456.123_456_f64, - ); - // Ignore literals in macros - let _ = mac!(); -} diff --git a/tests/ui/large_digit_groups.rs b/tests/ui/large_digit_groups.rs deleted file mode 100644 index ac116d5dbda1..000000000000 --- a/tests/ui/large_digit_groups.rs +++ /dev/null @@ -1,31 +0,0 @@ -// run-rustfix -#![warn(clippy::large_digit_groups)] - -fn main() { - macro_rules! mac { - () => { - 0b1_10110_i64 - }; - } - - let _good = ( - 0b1011_i64, - 0o1_234_u32, - 0x1_234_567, - 1_2345_6789, - 1234_f32, - 1_234.12_f32, - 1_234.123_f32, - 1.123_4_f32, - ); - let _bad = ( - 0b1_10110_i64, - 0xd_e_adbee_f_usize, - 1_23456_f32, - 1_23456.12_f32, - 1_23456.12345_f64, - 1_23456.12345_6_f64, - ); - // Ignore literals in macros - let _ = mac!(); -} diff --git a/tests/ui/large_digit_groups.stderr b/tests/ui/large_digit_groups.stderr deleted file mode 100644 index 13d108b56e02..000000000000 --- a/tests/ui/large_digit_groups.stderr +++ /dev/null @@ -1,48 +0,0 @@ -error: digits of hex or binary literal not grouped by four - --> $DIR/large_digit_groups.rs:14:9 - | -LL | 0x1_234_567, - | ^^^^^^^^^^^ help: consider: `0x0123_4567` - | - = note: `-D clippy::unusual-byte-groupings` implied by `-D warnings` - -error: digits of hex or binary literal not grouped by four - --> $DIR/large_digit_groups.rs:22:9 - | -LL | 0b1_10110_i64, - | ^^^^^^^^^^^^^ help: consider: `0b11_0110_i64` - -error: digits of hex or binary literal not grouped by four - --> $DIR/large_digit_groups.rs:23:9 - | -LL | 0xd_e_adbee_f_usize, - | ^^^^^^^^^^^^^^^^^^^ help: consider: `0xdead_beef_usize` - -error: digit groups should be smaller - --> $DIR/large_digit_groups.rs:24:9 - | -LL | 1_23456_f32, - | ^^^^^^^^^^^ help: consider: `123_456_f32` - | - = note: `-D clippy::large-digit-groups` implied by `-D warnings` - -error: digit groups should be smaller - --> $DIR/large_digit_groups.rs:25:9 - | -LL | 1_23456.12_f32, - | ^^^^^^^^^^^^^^ help: consider: `123_456.12_f32` - -error: digit groups should be smaller - --> $DIR/large_digit_groups.rs:26:9 - | -LL | 1_23456.12345_f64, - | ^^^^^^^^^^^^^^^^^ help: consider: `123_456.123_45_f64` - -error: digit groups should be smaller - --> $DIR/large_digit_groups.rs:27:9 - | -LL | 1_23456.12345_6_f64, - | ^^^^^^^^^^^^^^^^^^^ help: consider: `123_456.123_456_f64` - -error: aborting due to 7 previous errors - diff --git a/tests/ui/large_enum_variant.rs b/tests/ui/large_enum_variant.rs deleted file mode 100644 index 852ef5fec0e7..000000000000 --- a/tests/ui/large_enum_variant.rs +++ /dev/null @@ -1,54 +0,0 @@ -#![allow(dead_code)] -#![allow(unused_variables)] -#![warn(clippy::large_enum_variant)] - -enum LargeEnum { - A(i32), - B([i32; 8000]), -} - -enum GenericEnumOk { - A(i32), - B([T; 8000]), -} - -enum GenericEnum2 { - A(i32), - B([i32; 8000]), - C(T, [i32; 8000]), -} - -trait SomeTrait { - type Item; -} - -enum LargeEnumGeneric { - Var(A::Item), -} - -enum LargeEnum2 { - VariantOk(i32, u32), - ContainingLargeEnum(LargeEnum), -} -enum LargeEnum3 { - ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), - VoidVariant, - StructLikeLittle { x: i32, y: i32 }, -} - -enum LargeEnum4 { - VariantOk(i32, u32), - StructLikeLarge { x: [i32; 8000], y: i32 }, -} - -enum LargeEnum5 { - VariantOk(i32, u32), - StructLikeLarge2 { x: [i32; 8000] }, -} - -enum LargeEnumOk { - LargeA([i32; 8000]), - LargeB([i32; 8001]), -} - -fn main() {} diff --git a/tests/ui/large_enum_variant.stderr b/tests/ui/large_enum_variant.stderr deleted file mode 100644 index 8ce641a81f29..000000000000 --- a/tests/ui/large_enum_variant.stderr +++ /dev/null @@ -1,68 +0,0 @@ -error: large size difference between variants - --> $DIR/large_enum_variant.rs:7:5 - | -LL | B([i32; 8000]), - | ^^^^^^^^^^^^^^ this variant is 32000 bytes - | - = note: `-D clippy::large-enum-variant` implied by `-D warnings` -note: and the second-largest variant is 4 bytes: - --> $DIR/large_enum_variant.rs:6:5 - | -LL | A(i32), - | ^^^^^^ -help: consider boxing the large fields to reduce the total size of the enum - | -LL | B(Box<[i32; 8000]>), - | ^^^^^^^^^^^^^^^^ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:31:5 - | -LL | ContainingLargeEnum(LargeEnum), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this variant is 32004 bytes - | -note: and the second-largest variant is 8 bytes: - --> $DIR/large_enum_variant.rs:30:5 - | -LL | VariantOk(i32, u32), - | ^^^^^^^^^^^^^^^^^^^ -help: consider boxing the large fields to reduce the total size of the enum - | -LL | ContainingLargeEnum(Box), - | ^^^^^^^^^^^^^^ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:41:5 - | -LL | StructLikeLarge { x: [i32; 8000], y: i32 }, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this variant is 32004 bytes - | -note: and the second-largest variant is 8 bytes: - --> $DIR/large_enum_variant.rs:40:5 - | -LL | VariantOk(i32, u32), - | ^^^^^^^^^^^^^^^^^^^ -help: consider boxing the large fields to reduce the total size of the enum - --> $DIR/large_enum_variant.rs:41:5 - | -LL | StructLikeLarge { x: [i32; 8000], y: i32 }, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:46:5 - | -LL | StructLikeLarge2 { x: [i32; 8000] }, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this variant is 32000 bytes - | -note: and the second-largest variant is 8 bytes: - --> $DIR/large_enum_variant.rs:45:5 - | -LL | VariantOk(i32, u32), - | ^^^^^^^^^^^^^^^^^^^ -help: consider boxing the large fields to reduce the total size of the enum - | -LL | StructLikeLarge2 { x: Box<[i32; 8000]> }, - | ^^^^^^^^^^^^^^^^ - -error: aborting due to 4 previous errors - diff --git a/tests/ui/large_stack_arrays.rs b/tests/ui/large_stack_arrays.rs deleted file mode 100644 index d9161bfcf154..000000000000 --- a/tests/ui/large_stack_arrays.rs +++ /dev/null @@ -1,30 +0,0 @@ -#![warn(clippy::large_stack_arrays)] -#![allow(clippy::large_enum_variant)] - -#[derive(Clone, Copy)] -struct S { - pub data: [u64; 32], -} - -#[derive(Clone, Copy)] -enum E { - S(S), - T(u32), -} - -fn main() { - let bad = ( - [0u32; 20_000_000], - [S { data: [0; 32] }; 5000], - [Some(""); 20_000_000], - [E::T(0); 5000], - ); - - let good = ( - [0u32; 1000], - [S { data: [0; 32] }; 1000], - [Some(""); 1000], - [E::T(0); 1000], - [(); 20_000_000], - ); -} diff --git a/tests/ui/large_stack_arrays.stderr b/tests/ui/large_stack_arrays.stderr deleted file mode 100644 index 58c0a77c1c84..000000000000 --- a/tests/ui/large_stack_arrays.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:17:9 - | -LL | [0u32; 20_000_000], - | ^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::large-stack-arrays` implied by `-D warnings` - = help: consider allocating on the heap with `vec![0u32; 20_000_000].into_boxed_slice()` - -error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:18:9 - | -LL | [S { data: [0; 32] }; 5000], - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider allocating on the heap with `vec![S { data: [0; 32] }; 5000].into_boxed_slice()` - -error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:19:9 - | -LL | [Some(""); 20_000_000], - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider allocating on the heap with `vec![Some(""); 20_000_000].into_boxed_slice()` - -error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:20:9 - | -LL | [E::T(0); 5000], - | ^^^^^^^^^^^^^^^ - | - = help: consider allocating on the heap with `vec![E::T(0); 5000].into_boxed_slice()` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/large_types_passed_by_value.rs b/tests/ui/large_types_passed_by_value.rs deleted file mode 100644 index e4a2e9df4d7b..000000000000 --- a/tests/ui/large_types_passed_by_value.rs +++ /dev/null @@ -1,66 +0,0 @@ -// normalize-stderr-test "\(\d+ byte\)" -> "(N byte)" -// normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)" - -#![warn(clippy::large_types_passed_by_value)] - -pub struct Large([u8; 2048]); - -#[derive(Clone, Copy)] -pub struct LargeAndCopy([u8; 2048]); - -pub struct Small([u8; 4]); - -#[derive(Clone, Copy)] -pub struct SmallAndCopy([u8; 4]); - -fn small(a: Small, b: SmallAndCopy) {} -fn not_copy(a: Large) {} -fn by_ref(a: &Large, b: &LargeAndCopy) {} -fn mutable(mut a: LargeAndCopy) {} -fn bad(a: LargeAndCopy) {} -pub fn bad_but_pub(a: LargeAndCopy) {} - -impl LargeAndCopy { - fn self_is_ok(self) {} - fn other_is_not_ok(self, other: LargeAndCopy) {} - fn unless_other_can_change(self, mut other: LargeAndCopy) {} - pub fn or_were_in_public(self, other: LargeAndCopy) {} -} - -trait LargeTypeDevourer { - fn devoure_array(&self, array: [u8; 6666]); - fn devoure_tuple(&self, tup: (LargeAndCopy, LargeAndCopy)); - fn devoure_array_and_tuple_wow(&self, array: [u8; 6666], tup: (LargeAndCopy, LargeAndCopy)); -} - -pub trait PubLargeTypeDevourer { - fn devoure_array_in_public(&self, array: [u8; 6666]); -} - -struct S {} -impl LargeTypeDevourer for S { - fn devoure_array(&self, array: [u8; 6666]) { - todo!(); - } - fn devoure_tuple(&self, tup: (LargeAndCopy, LargeAndCopy)) { - todo!(); - } - fn devoure_array_and_tuple_wow(&self, array: [u8; 6666], tup: (LargeAndCopy, LargeAndCopy)) { - todo!(); - } -} - -#[inline(always)] -fn foo_always(x: LargeAndCopy) { - todo!(); -} -#[inline(never)] -fn foo_never(x: LargeAndCopy) { - todo!(); -} -#[inline] -fn foo(x: LargeAndCopy) { - todo!(); -} - -fn main() {} diff --git a/tests/ui/large_types_passed_by_value.stderr b/tests/ui/large_types_passed_by_value.stderr deleted file mode 100644 index 5f42dcfb9b52..000000000000 --- a/tests/ui/large_types_passed_by_value.stderr +++ /dev/null @@ -1,52 +0,0 @@ -error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> $DIR/large_types_passed_by_value.rs:20:11 - | -LL | fn bad(a: LargeAndCopy) {} - | ^^^^^^^^^^^^ help: consider passing by reference instead: `&LargeAndCopy` - | - = note: `-D clippy::large-types-passed-by-value` implied by `-D warnings` - -error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> $DIR/large_types_passed_by_value.rs:25:37 - | -LL | fn other_is_not_ok(self, other: LargeAndCopy) {} - | ^^^^^^^^^^^^ help: consider passing by reference instead: `&LargeAndCopy` - -error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> $DIR/large_types_passed_by_value.rs:31:36 - | -LL | fn devoure_array(&self, array: [u8; 6666]); - | ^^^^^^^^^^ help: consider passing by reference instead: `&[u8; 6666]` - -error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> $DIR/large_types_passed_by_value.rs:32:34 - | -LL | fn devoure_tuple(&self, tup: (LargeAndCopy, LargeAndCopy)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider passing by reference instead: `&(LargeAndCopy, LargeAndCopy)` - -error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> $DIR/large_types_passed_by_value.rs:33:50 - | -LL | fn devoure_array_and_tuple_wow(&self, array: [u8; 6666], tup: (LargeAndCopy, LargeAndCopy)); - | ^^^^^^^^^^ help: consider passing by reference instead: `&[u8; 6666]` - -error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> $DIR/large_types_passed_by_value.rs:33:67 - | -LL | fn devoure_array_and_tuple_wow(&self, array: [u8; 6666], tup: (LargeAndCopy, LargeAndCopy)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider passing by reference instead: `&(LargeAndCopy, LargeAndCopy)` - -error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> $DIR/large_types_passed_by_value.rs:58:17 - | -LL | fn foo_never(x: LargeAndCopy) { - | ^^^^^^^^^^^^ help: consider passing by reference instead: `&LargeAndCopy` - -error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> $DIR/large_types_passed_by_value.rs:62:11 - | -LL | fn foo(x: LargeAndCopy) { - | ^^^^^^^^^^^^ help: consider passing by reference instead: `&LargeAndCopy` - -error: aborting due to 8 previous errors - diff --git a/tests/ui/len_without_is_empty.rs b/tests/ui/len_without_is_empty.rs deleted file mode 100644 index b5211318a150..000000000000 --- a/tests/ui/len_without_is_empty.rs +++ /dev/null @@ -1,145 +0,0 @@ -#![warn(clippy::len_without_is_empty)] -#![allow(dead_code, unused)] - -pub struct PubOne; - -impl PubOne { - pub fn len(&self) -> isize { - 1 - } -} - -impl PubOne { - // A second impl for this struct -- the error span shouldn't mention this. - pub fn irrelevant(&self) -> bool { - false - } -} - -// Identical to `PubOne`, but with an `allow` attribute on the impl complaining `len`. -pub struct PubAllowed; - -#[allow(clippy::len_without_is_empty)] -impl PubAllowed { - pub fn len(&self) -> isize { - 1 - } -} - -// No `allow` attribute on this impl block, but that doesn't matter -- we only require one on the -// impl containing `len`. -impl PubAllowed { - pub fn irrelevant(&self) -> bool { - false - } -} - -pub trait PubTraitsToo { - fn len(&self) -> isize; -} - -impl PubTraitsToo for One { - fn len(&self) -> isize { - 0 - } -} - -pub struct HasIsEmpty; - -impl HasIsEmpty { - pub fn len(&self) -> isize { - 1 - } - - fn is_empty(&self) -> bool { - false - } -} - -pub struct HasWrongIsEmpty; - -impl HasWrongIsEmpty { - pub fn len(&self) -> isize { - 1 - } - - pub fn is_empty(&self, x: u32) -> bool { - false - } -} - -struct NotPubOne; - -impl NotPubOne { - pub fn len(&self) -> isize { - // No error; `len` is pub but `NotPubOne` is not exported anyway. - 1 - } -} - -struct One; - -impl One { - fn len(&self) -> isize { - // No error; `len` is private; see issue #1085. - 1 - } -} - -trait TraitsToo { - fn len(&self) -> isize; - // No error; `len` is private; see issue #1085. -} - -impl TraitsToo for One { - fn len(&self) -> isize { - 0 - } -} - -struct HasPrivateIsEmpty; - -impl HasPrivateIsEmpty { - pub fn len(&self) -> isize { - 1 - } - - fn is_empty(&self) -> bool { - false - } -} - -struct Wither; - -pub trait WithIsEmpty { - fn len(&self) -> isize; - fn is_empty(&self) -> bool; -} - -impl WithIsEmpty for Wither { - fn len(&self) -> isize { - 1 - } - - fn is_empty(&self) -> bool { - false - } -} - -pub trait Empty { - fn is_empty(&self) -> bool; -} - -pub trait InheritingEmpty: Empty { - // Must not trigger `LEN_WITHOUT_IS_EMPTY`. - fn len(&self) -> isize; -} - -// This used to ICE. -pub trait Foo: Sized {} - -pub trait DependsOnFoo: Foo { - fn len(&mut self) -> usize; -} - -fn main() {} diff --git a/tests/ui/len_without_is_empty.stderr b/tests/ui/len_without_is_empty.stderr deleted file mode 100644 index d79c300c0744..000000000000 --- a/tests/ui/len_without_is_empty.stderr +++ /dev/null @@ -1,54 +0,0 @@ -error: item `PubOne` has a public `len` method but no corresponding `is_empty` method - --> $DIR/len_without_is_empty.rs:6:1 - | -LL | / impl PubOne { -LL | | pub fn len(&self) -> isize { -LL | | 1 -LL | | } -LL | | } - | |_^ - | - = note: `-D clippy::len-without-is-empty` implied by `-D warnings` - -error: trait `PubTraitsToo` has a `len` method but no (possibly inherited) `is_empty` method - --> $DIR/len_without_is_empty.rs:37:1 - | -LL | / pub trait PubTraitsToo { -LL | | fn len(&self) -> isize; -LL | | } - | |_^ - -error: item `HasIsEmpty` has a public `len` method but a private `is_empty` method - --> $DIR/len_without_is_empty.rs:49:1 - | -LL | / impl HasIsEmpty { -LL | | pub fn len(&self) -> isize { -LL | | 1 -LL | | } -... | -LL | | } -LL | | } - | |_^ - -error: item `HasWrongIsEmpty` has a public `len` method but no corresponding `is_empty` method - --> $DIR/len_without_is_empty.rs:61:1 - | -LL | / impl HasWrongIsEmpty { -LL | | pub fn len(&self) -> isize { -LL | | 1 -LL | | } -... | -LL | | } -LL | | } - | |_^ - -error: trait `DependsOnFoo` has a `len` method but no (possibly inherited) `is_empty` method - --> $DIR/len_without_is_empty.rs:141:1 - | -LL | / pub trait DependsOnFoo: Foo { -LL | | fn len(&mut self) -> usize; -LL | | } - | |_^ - -error: aborting due to 5 previous errors - diff --git a/tests/ui/len_zero.fixed b/tests/ui/len_zero.fixed deleted file mode 100644 index 1f3b8ac99b19..000000000000 --- a/tests/ui/len_zero.fixed +++ /dev/null @@ -1,143 +0,0 @@ -// run-rustfix - -#![warn(clippy::len_zero)] -#![allow(dead_code, unused, clippy::len_without_is_empty)] - -pub struct One; -struct Wither; - -trait TraitsToo { - fn len(&self) -> isize; - // No error; `len` is private; see issue #1085. -} - -impl TraitsToo for One { - fn len(&self) -> isize { - 0 - } -} - -pub struct HasIsEmpty; - -impl HasIsEmpty { - pub fn len(&self) -> isize { - 1 - } - - fn is_empty(&self) -> bool { - false - } -} - -pub struct HasWrongIsEmpty; - -impl HasWrongIsEmpty { - pub fn len(&self) -> isize { - 1 - } - - pub fn is_empty(&self, x: u32) -> bool { - false - } -} - -pub trait WithIsEmpty { - fn len(&self) -> isize; - fn is_empty(&self) -> bool; -} - -impl WithIsEmpty for Wither { - fn len(&self) -> isize { - 1 - } - - fn is_empty(&self) -> bool { - false - } -} - -fn main() { - let x = [1, 2]; - if x.is_empty() { - println!("This should not happen!"); - } - - if "".is_empty() {} - - let y = One; - if y.len() == 0 { - // No error; `One` does not have `.is_empty()`. - println!("This should not happen either!"); - } - - let z: &dyn TraitsToo = &y; - if z.len() > 0 { - // No error; `TraitsToo` has no `.is_empty()` method. - println!("Nor should this!"); - } - - let has_is_empty = HasIsEmpty; - if has_is_empty.is_empty() { - println!("Or this!"); - } - if !has_is_empty.is_empty() { - println!("Or this!"); - } - if !has_is_empty.is_empty() { - println!("Or this!"); - } - if has_is_empty.is_empty() { - println!("Or this!"); - } - if !has_is_empty.is_empty() { - println!("Or this!"); - } - if has_is_empty.len() > 1 { - // No error. - println!("This can happen."); - } - if has_is_empty.len() <= 1 { - // No error. - println!("This can happen."); - } - if has_is_empty.is_empty() { - println!("Or this!"); - } - if !has_is_empty.is_empty() { - println!("Or this!"); - } - if !has_is_empty.is_empty() { - println!("Or this!"); - } - if !has_is_empty.is_empty() { - println!("Or this!"); - } - if has_is_empty.is_empty() { - println!("Or this!"); - } - if 1 < has_is_empty.len() { - // No error. - println!("This can happen."); - } - if 1 >= has_is_empty.len() { - // No error. - println!("This can happen."); - } - assert!(!has_is_empty.is_empty()); - - let with_is_empty: &dyn WithIsEmpty = &Wither; - if with_is_empty.is_empty() { - println!("Or this!"); - } - assert!(!with_is_empty.is_empty()); - - let has_wrong_is_empty = HasWrongIsEmpty; - if has_wrong_is_empty.len() == 0 { - // No error; `HasWrongIsEmpty` does not have `.is_empty()`. - println!("Or this!"); - } -} - -fn test_slice(b: &[u8]) { - if !b.is_empty() {} -} diff --git a/tests/ui/len_zero.rs b/tests/ui/len_zero.rs deleted file mode 100644 index dc21de0001b6..000000000000 --- a/tests/ui/len_zero.rs +++ /dev/null @@ -1,143 +0,0 @@ -// run-rustfix - -#![warn(clippy::len_zero)] -#![allow(dead_code, unused, clippy::len_without_is_empty)] - -pub struct One; -struct Wither; - -trait TraitsToo { - fn len(&self) -> isize; - // No error; `len` is private; see issue #1085. -} - -impl TraitsToo for One { - fn len(&self) -> isize { - 0 - } -} - -pub struct HasIsEmpty; - -impl HasIsEmpty { - pub fn len(&self) -> isize { - 1 - } - - fn is_empty(&self) -> bool { - false - } -} - -pub struct HasWrongIsEmpty; - -impl HasWrongIsEmpty { - pub fn len(&self) -> isize { - 1 - } - - pub fn is_empty(&self, x: u32) -> bool { - false - } -} - -pub trait WithIsEmpty { - fn len(&self) -> isize; - fn is_empty(&self) -> bool; -} - -impl WithIsEmpty for Wither { - fn len(&self) -> isize { - 1 - } - - fn is_empty(&self) -> bool { - false - } -} - -fn main() { - let x = [1, 2]; - if x.len() == 0 { - println!("This should not happen!"); - } - - if "".len() == 0 {} - - let y = One; - if y.len() == 0 { - // No error; `One` does not have `.is_empty()`. - println!("This should not happen either!"); - } - - let z: &dyn TraitsToo = &y; - if z.len() > 0 { - // No error; `TraitsToo` has no `.is_empty()` method. - println!("Nor should this!"); - } - - let has_is_empty = HasIsEmpty; - if has_is_empty.len() == 0 { - println!("Or this!"); - } - if has_is_empty.len() != 0 { - println!("Or this!"); - } - if has_is_empty.len() > 0 { - println!("Or this!"); - } - if has_is_empty.len() < 1 { - println!("Or this!"); - } - if has_is_empty.len() >= 1 { - println!("Or this!"); - } - if has_is_empty.len() > 1 { - // No error. - println!("This can happen."); - } - if has_is_empty.len() <= 1 { - // No error. - println!("This can happen."); - } - if 0 == has_is_empty.len() { - println!("Or this!"); - } - if 0 != has_is_empty.len() { - println!("Or this!"); - } - if 0 < has_is_empty.len() { - println!("Or this!"); - } - if 1 <= has_is_empty.len() { - println!("Or this!"); - } - if 1 > has_is_empty.len() { - println!("Or this!"); - } - if 1 < has_is_empty.len() { - // No error. - println!("This can happen."); - } - if 1 >= has_is_empty.len() { - // No error. - println!("This can happen."); - } - assert!(!has_is_empty.is_empty()); - - let with_is_empty: &dyn WithIsEmpty = &Wither; - if with_is_empty.len() == 0 { - println!("Or this!"); - } - assert!(!with_is_empty.is_empty()); - - let has_wrong_is_empty = HasWrongIsEmpty; - if has_wrong_is_empty.len() == 0 { - // No error; `HasWrongIsEmpty` does not have `.is_empty()`. - println!("Or this!"); - } -} - -fn test_slice(b: &[u8]) { - if b.len() != 0 {} -} diff --git a/tests/ui/len_zero.stderr b/tests/ui/len_zero.stderr deleted file mode 100644 index 6c71f1beeac6..000000000000 --- a/tests/ui/len_zero.stderr +++ /dev/null @@ -1,88 +0,0 @@ -error: length comparison to zero - --> $DIR/len_zero.rs:61:8 - | -LL | if x.len() == 0 { - | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `x.is_empty()` - | - = note: `-D clippy::len-zero` implied by `-D warnings` - -error: length comparison to zero - --> $DIR/len_zero.rs:65:8 - | -LL | if "".len() == 0 {} - | ^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `"".is_empty()` - -error: length comparison to zero - --> $DIR/len_zero.rs:80:8 - | -LL | if has_is_empty.len() == 0 { - | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` - -error: length comparison to zero - --> $DIR/len_zero.rs:83:8 - | -LL | if has_is_empty.len() != 0 { - | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` - -error: length comparison to zero - --> $DIR/len_zero.rs:86:8 - | -LL | if has_is_empty.len() > 0 { - | ^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` - -error: length comparison to one - --> $DIR/len_zero.rs:89:8 - | -LL | if has_is_empty.len() < 1 { - | ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` - -error: length comparison to one - --> $DIR/len_zero.rs:92:8 - | -LL | if has_is_empty.len() >= 1 { - | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` - -error: length comparison to zero - --> $DIR/len_zero.rs:103:8 - | -LL | if 0 == has_is_empty.len() { - | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` - -error: length comparison to zero - --> $DIR/len_zero.rs:106:8 - | -LL | if 0 != has_is_empty.len() { - | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` - -error: length comparison to zero - --> $DIR/len_zero.rs:109:8 - | -LL | if 0 < has_is_empty.len() { - | ^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` - -error: length comparison to one - --> $DIR/len_zero.rs:112:8 - | -LL | if 1 <= has_is_empty.len() { - | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` - -error: length comparison to one - --> $DIR/len_zero.rs:115:8 - | -LL | if 1 > has_is_empty.len() { - | ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` - -error: length comparison to zero - --> $DIR/len_zero.rs:129:8 - | -LL | if with_is_empty.len() == 0 { - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `with_is_empty.is_empty()` - -error: length comparison to zero - --> $DIR/len_zero.rs:142:8 - | -LL | if b.len() != 0 {} - | ^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!b.is_empty()` - -error: aborting due to 14 previous errors - diff --git a/tests/ui/len_zero_ranges.fixed b/tests/ui/len_zero_ranges.fixed deleted file mode 100644 index 797817662427..000000000000 --- a/tests/ui/len_zero_ranges.fixed +++ /dev/null @@ -1,17 +0,0 @@ -// run-rustfix - -#![warn(clippy::len_zero)] -#![allow(unused)] - -// Now that `Range(Inclusive)::is_empty` is stable (1.47), we can always suggest this -mod issue_3807 { - fn suggestion_is_fine_range() { - let _ = (0..42).is_empty(); - } - - fn suggestion_is_fine_range_inclusive() { - let _ = (0_u8..=42).is_empty(); - } -} - -fn main() {} diff --git a/tests/ui/len_zero_ranges.rs b/tests/ui/len_zero_ranges.rs deleted file mode 100644 index a0eb51cc9760..000000000000 --- a/tests/ui/len_zero_ranges.rs +++ /dev/null @@ -1,17 +0,0 @@ -// run-rustfix - -#![warn(clippy::len_zero)] -#![allow(unused)] - -// Now that `Range(Inclusive)::is_empty` is stable (1.47), we can always suggest this -mod issue_3807 { - fn suggestion_is_fine_range() { - let _ = (0..42).len() == 0; - } - - fn suggestion_is_fine_range_inclusive() { - let _ = (0_u8..=42).len() == 0; - } -} - -fn main() {} diff --git a/tests/ui/len_zero_ranges.stderr b/tests/ui/len_zero_ranges.stderr deleted file mode 100644 index d0defb5a79ed..000000000000 --- a/tests/ui/len_zero_ranges.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: length comparison to zero - --> $DIR/len_zero_ranges.rs:9:17 - | -LL | let _ = (0..42).len() == 0; - | ^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(0..42).is_empty()` - | - = note: `-D clippy::len-zero` implied by `-D warnings` - -error: length comparison to zero - --> $DIR/len_zero_ranges.rs:13:17 - | -LL | let _ = (0_u8..=42).len() == 0; - | ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(0_u8..=42).is_empty()` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/let_and_return.rs b/tests/ui/let_and_return.rs deleted file mode 100644 index 73e550b3df89..000000000000 --- a/tests/ui/let_and_return.rs +++ /dev/null @@ -1,159 +0,0 @@ -#![allow(unused)] -#![warn(clippy::let_and_return)] - -fn test() -> i32 { - let _y = 0; // no warning - let x = 5; - x -} - -fn test_inner() -> i32 { - if true { - let x = 5; - x - } else { - 0 - } -} - -fn test_nowarn_1() -> i32 { - let mut x = 5; - x += 1; - x -} - -fn test_nowarn_2() -> i32 { - let x = 5; - x + 1 -} - -fn test_nowarn_3() -> (i32, i32) { - // this should technically warn, but we do not compare complex patterns - let (x, y) = (5, 9); - (x, y) -} - -fn test_nowarn_4() -> i32 { - // this should technically warn, but not b/c of clippy::let_and_return, but b/c of useless type - let x: i32 = 5; - x -} - -fn test_nowarn_5(x: i16) -> u16 { - #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] - let x = x as u16; - x -} - -// False positive example -trait Decode { - fn decode(d: D) -> Result - where - Self: Sized; -} - -macro_rules! tuple_encode { - ($($x:ident),*) => ( - impl<$($x: Decode),*> Decode for ($($x),*) { - #[inline] - #[allow(non_snake_case)] - fn decode(mut d: D) -> Result { - // Shouldn't trigger lint - Ok(($({let $x = Decode::decode(&mut d)?; $x }),*)) - } - } - ); -} - -tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); - -mod no_lint_if_stmt_borrows { - mod issue_3792 { - use std::io::{self, BufRead, Stdin}; - - fn read_line() -> String { - let stdin = io::stdin(); - let line = stdin.lock().lines().next().unwrap().unwrap(); - line - } - } - - mod issue_3324 { - use std::cell::RefCell; - use std::rc::{Rc, Weak}; - - fn test(value: Weak>) -> u32 { - let value = value.upgrade().unwrap(); - let ret = value.borrow().baz(); - ret - } - - struct Bar {} - - impl Bar { - fn new() -> Self { - Bar {} - } - fn baz(&self) -> u32 { - 0 - } - } - - fn main() { - let a = Rc::new(RefCell::new(Bar::new())); - let b = Rc::downgrade(&a); - test(b); - } - } - - mod free_function { - struct Inner; - - struct Foo<'a> { - inner: &'a Inner, - } - - impl Drop for Foo<'_> { - fn drop(&mut self) {} - } - - impl Foo<'_> { - fn value(&self) -> i32 { - 42 - } - } - - fn some_foo(inner: &Inner) -> Foo<'_> { - Foo { inner } - } - - fn test() -> i32 { - let x = Inner {}; - let value = some_foo(&x).value(); - value - } - } -} - -mod issue_5729 { - use std::sync::Arc; - - trait Foo {} - - trait FooStorage { - fn foo_cloned(&self) -> Arc; - } - - struct FooStorageImpl { - foo: Arc, - } - - impl FooStorage for FooStorageImpl { - fn foo_cloned(&self) -> Arc { - let clone = Arc::clone(&self.foo); - clone - } - } -} - -fn main() {} diff --git a/tests/ui/let_and_return.stderr b/tests/ui/let_and_return.stderr deleted file mode 100644 index fe878e5f2060..000000000000 --- a/tests/ui/let_and_return.stderr +++ /dev/null @@ -1,45 +0,0 @@ -error: returning the result of a `let` binding from a block - --> $DIR/let_and_return.rs:7:5 - | -LL | let x = 5; - | ---------- unnecessary `let` binding -LL | x - | ^ - | - = note: `-D clippy::let-and-return` implied by `-D warnings` -help: return the expression directly - | -LL | -LL | 5 - | - -error: returning the result of a `let` binding from a block - --> $DIR/let_and_return.rs:13:9 - | -LL | let x = 5; - | ---------- unnecessary `let` binding -LL | x - | ^ - | -help: return the expression directly - | -LL | -LL | 5 - | - -error: returning the result of a `let` binding from a block - --> $DIR/let_and_return.rs:154:13 - | -LL | let clone = Arc::clone(&self.foo); - | ---------------------------------- unnecessary `let` binding -LL | clone - | ^^^^^ - | -help: return the expression directly - | -LL | -LL | Arc::clone(&self.foo) as _ - | - -error: aborting due to 3 previous errors - diff --git a/tests/ui/let_if_seq.rs b/tests/ui/let_if_seq.rs deleted file mode 100644 index 32a67f181df4..000000000000 --- a/tests/ui/let_if_seq.rs +++ /dev/null @@ -1,120 +0,0 @@ -#![allow( - unused_variables, - unused_assignments, - clippy::similar_names, - clippy::blacklisted_name -)] -#![warn(clippy::useless_let_if_seq)] - -fn f() -> bool { - true -} -fn g(x: i32) -> i32 { - x + 1 -} - -fn issue985() -> i32 { - let mut x = 42; - if f() { - x = g(x); - } - - x -} - -fn issue985_alt() -> i32 { - let mut x = 42; - if f() { - f(); - } else { - x = g(x); - } - - x -} - -#[allow(clippy::manual_strip)] -fn issue975() -> String { - let mut udn = "dummy".to_string(); - if udn.starts_with("uuid:") { - udn = String::from(&udn[5..]); - } - udn -} - -fn early_return() -> u8 { - // FIXME: we could extend the lint to include such cases: - let foo; - - if f() { - return 42; - } else { - foo = 0; - } - - foo -} - -fn main() { - early_return(); - issue975(); - issue985(); - issue985_alt(); - - let mut foo = 0; - if f() { - foo = 42; - } - - let mut bar = 0; - if f() { - f(); - bar = 42; - } else { - f(); - } - - let quz; - if f() { - quz = 42; - } else { - quz = 0; - } - - // `toto` is used several times - let mut toto; - if f() { - toto = 42; - } else { - for i in &[1, 2] { - toto = *i; - } - - toto = 2; - } - - // found in libcore, the inner if is not a statement but the block's expr - let mut ch = b'x'; - if f() { - ch = b'*'; - if f() { - ch = b'?'; - } - } - - // baz needs to be mut - let mut baz = 0; - if f() { - baz = 42; - } - - baz = 1337; - - // issue 3043 - types with interior mutability should not trigger this lint - use std::cell::Cell; - let mut val = Cell::new(1); - if true { - val = Cell::new(2); - } - println!("{}", val.get()); -} diff --git a/tests/ui/let_if_seq.stderr b/tests/ui/let_if_seq.stderr deleted file mode 100644 index 7de560c73486..000000000000 --- a/tests/ui/let_if_seq.stderr +++ /dev/null @@ -1,50 +0,0 @@ -error: `if _ { .. } else { .. }` is an expression - --> $DIR/let_if_seq.rs:64:5 - | -LL | / let mut foo = 0; -LL | | if f() { -LL | | foo = 42; -LL | | } - | |_____^ help: it is more idiomatic to write: `let foo = if f() { 42 } else { 0 };` - | - = note: `-D clippy::useless-let-if-seq` implied by `-D warnings` - = note: you might not need `mut` at all - -error: `if _ { .. } else { .. }` is an expression - --> $DIR/let_if_seq.rs:69:5 - | -LL | / let mut bar = 0; -LL | | if f() { -LL | | f(); -LL | | bar = 42; -LL | | } else { -LL | | f(); -LL | | } - | |_____^ help: it is more idiomatic to write: `let bar = if f() { ..; 42 } else { ..; 0 };` - | - = note: you might not need `mut` at all - -error: `if _ { .. } else { .. }` is an expression - --> $DIR/let_if_seq.rs:77:5 - | -LL | / let quz; -LL | | if f() { -LL | | quz = 42; -LL | | } else { -LL | | quz = 0; -LL | | } - | |_____^ help: it is more idiomatic to write: `let quz = if f() { 42 } else { 0 };` - -error: `if _ { .. } else { .. }` is an expression - --> $DIR/let_if_seq.rs:106:5 - | -LL | / let mut baz = 0; -LL | | if f() { -LL | | baz = 42; -LL | | } - | |_____^ help: it is more idiomatic to write: `let baz = if f() { 42 } else { 0 };` - | - = note: you might not need `mut` at all - -error: aborting due to 4 previous errors - diff --git a/tests/ui/let_underscore_drop.rs b/tests/ui/let_underscore_drop.rs deleted file mode 100644 index 98593edb9c59..000000000000 --- a/tests/ui/let_underscore_drop.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![warn(clippy::let_underscore_drop)] - -struct Droppable; - -impl Drop for Droppable { - fn drop(&mut self) {} -} - -fn main() { - let unit = (); - let boxed = Box::new(()); - let droppable = Droppable; - let optional = Some(Droppable); - - let _ = (); - let _ = Box::new(()); - let _ = Droppable; - let _ = Some(Droppable); -} diff --git a/tests/ui/let_underscore_drop.stderr b/tests/ui/let_underscore_drop.stderr deleted file mode 100644 index 66069e0c5e13..000000000000 --- a/tests/ui/let_underscore_drop.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error: non-binding `let` on a type that implements `Drop` - --> $DIR/let_underscore_drop.rs:16:5 - | -LL | let _ = Box::new(()); - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::let-underscore-drop` implied by `-D warnings` - = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` - -error: non-binding `let` on a type that implements `Drop` - --> $DIR/let_underscore_drop.rs:17:5 - | -LL | let _ = Droppable; - | ^^^^^^^^^^^^^^^^^^ - | - = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` - -error: non-binding `let` on a type that implements `Drop` - --> $DIR/let_underscore_drop.rs:18:5 - | -LL | let _ = Some(Droppable); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/let_underscore_lock.rs b/tests/ui/let_underscore_lock.rs deleted file mode 100644 index 88fb216a7432..000000000000 --- a/tests/ui/let_underscore_lock.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![warn(clippy::let_underscore_lock)] - -fn main() { - let m = std::sync::Mutex::new(()); - let rw = std::sync::RwLock::new(()); - - let _ = m.lock(); - let _ = rw.read(); - let _ = rw.write(); - let _ = m.try_lock(); - let _ = rw.try_read(); - let _ = rw.try_write(); -} diff --git a/tests/ui/let_underscore_lock.stderr b/tests/ui/let_underscore_lock.stderr deleted file mode 100644 index 5d5f6059ef13..000000000000 --- a/tests/ui/let_underscore_lock.stderr +++ /dev/null @@ -1,51 +0,0 @@ -error: non-binding let on a synchronization lock - --> $DIR/let_underscore_lock.rs:7:5 - | -LL | let _ = m.lock(); - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::let-underscore-lock` implied by `-D warnings` - = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` - -error: non-binding let on a synchronization lock - --> $DIR/let_underscore_lock.rs:8:5 - | -LL | let _ = rw.read(); - | ^^^^^^^^^^^^^^^^^^ - | - = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` - -error: non-binding let on a synchronization lock - --> $DIR/let_underscore_lock.rs:9:5 - | -LL | let _ = rw.write(); - | ^^^^^^^^^^^^^^^^^^^ - | - = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` - -error: non-binding let on a synchronization lock - --> $DIR/let_underscore_lock.rs:10:5 - | -LL | let _ = m.try_lock(); - | ^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` - -error: non-binding let on a synchronization lock - --> $DIR/let_underscore_lock.rs:11:5 - | -LL | let _ = rw.try_read(); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` - -error: non-binding let on a synchronization lock - --> $DIR/let_underscore_lock.rs:12:5 - | -LL | let _ = rw.try_write(); - | ^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` - -error: aborting due to 6 previous errors - diff --git a/tests/ui/let_underscore_must_use.rs b/tests/ui/let_underscore_must_use.rs deleted file mode 100644 index a842e872a37b..000000000000 --- a/tests/ui/let_underscore_must_use.rs +++ /dev/null @@ -1,95 +0,0 @@ -#![warn(clippy::let_underscore_must_use)] -#![allow(clippy::unnecessary_wraps)] - -// Debug implementations can fire this lint, -// so we shouldn't lint external macros -#[derive(Debug)] -struct Foo { - field: i32, -} - -#[must_use] -fn f() -> u32 { - 0 -} - -fn g() -> Result { - Ok(0) -} - -#[must_use] -fn l(x: T) -> T { - x -} - -fn h() -> u32 { - 0 -} - -struct S {} - -impl S { - #[must_use] - pub fn f(&self) -> u32 { - 0 - } - - pub fn g(&self) -> Result { - Ok(0) - } - - fn k(&self) -> u32 { - 0 - } - - #[must_use] - fn h() -> u32 { - 0 - } - - fn p() -> Result { - Ok(0) - } -} - -trait Trait { - #[must_use] - fn a() -> u32; -} - -impl Trait for S { - fn a() -> u32 { - 0 - } -} - -fn main() { - let _ = f(); - let _ = g(); - let _ = h(); - let _ = l(0_u32); - - let s = S {}; - - let _ = s.f(); - let _ = s.g(); - let _ = s.k(); - - let _ = S::h(); - let _ = S::p(); - - let _ = S::a(); - - let _ = if true { Ok(()) } else { Err(()) }; - - let a = Result::<(), ()>::Ok(()); - - let _ = a.is_ok(); - - let _ = a.map(|_| ()); - - let _ = a; - - #[allow(clippy::let_underscore_must_use)] - let _ = a; -} diff --git a/tests/ui/let_underscore_must_use.stderr b/tests/ui/let_underscore_must_use.stderr deleted file mode 100644 index 5b751ea56def..000000000000 --- a/tests/ui/let_underscore_must_use.stderr +++ /dev/null @@ -1,99 +0,0 @@ -error: non-binding let on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:67:5 - | -LL | let _ = f(); - | ^^^^^^^^^^^^ - | - = note: `-D clippy::let-underscore-must-use` implied by `-D warnings` - = help: consider explicitly using function result - -error: non-binding let on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:68:5 - | -LL | let _ = g(); - | ^^^^^^^^^^^^ - | - = help: consider explicitly using expression value - -error: non-binding let on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:70:5 - | -LL | let _ = l(0_u32); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider explicitly using function result - -error: non-binding let on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:74:5 - | -LL | let _ = s.f(); - | ^^^^^^^^^^^^^^ - | - = help: consider explicitly using function result - -error: non-binding let on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:75:5 - | -LL | let _ = s.g(); - | ^^^^^^^^^^^^^^ - | - = help: consider explicitly using expression value - -error: non-binding let on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:78:5 - | -LL | let _ = S::h(); - | ^^^^^^^^^^^^^^^ - | - = help: consider explicitly using function result - -error: non-binding let on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:79:5 - | -LL | let _ = S::p(); - | ^^^^^^^^^^^^^^^ - | - = help: consider explicitly using expression value - -error: non-binding let on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:81:5 - | -LL | let _ = S::a(); - | ^^^^^^^^^^^^^^^ - | - = help: consider explicitly using function result - -error: non-binding let on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:83:5 - | -LL | let _ = if true { Ok(()) } else { Err(()) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider explicitly using expression value - -error: non-binding let on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:87:5 - | -LL | let _ = a.is_ok(); - | ^^^^^^^^^^^^^^^^^^ - | - = help: consider explicitly using function result - -error: non-binding let on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:89:5 - | -LL | let _ = a.map(|_| ()); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider explicitly using expression value - -error: non-binding let on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:91:5 - | -LL | let _ = a; - | ^^^^^^^^^^ - | - = help: consider explicitly using expression value - -error: aborting due to 12 previous errors - diff --git a/tests/ui/let_unit.fixed b/tests/ui/let_unit.fixed deleted file mode 100644 index f398edc23cb5..000000000000 --- a/tests/ui/let_unit.fixed +++ /dev/null @@ -1,63 +0,0 @@ -// run-rustfix - -#![warn(clippy::let_unit_value)] -#![allow(clippy::no_effect)] -#![allow(unused_variables)] - -macro_rules! let_and_return { - ($n:expr) => {{ - let ret = $n; - }}; -} - -fn main() { - println!("x"); - let _y = 1; // this is fine - let _z = ((), 1); // this as well - if true { - (); - } - - consume_units_with_for_loop(); // should be fine as well - - multiline_sugg(); - - let_and_return!(()) // should be fine -} - -// Related to issue #1964 -fn consume_units_with_for_loop() { - // `for_let_unit` lint should not be triggered by consuming them using for loop. - let v = vec![(), (), ()]; - let mut count = 0; - for _ in v { - count += 1; - } - assert_eq!(count, 3); - - // Same for consuming from some other Iterator. - let (tx, rx) = ::std::sync::mpsc::channel(); - tx.send(()).unwrap(); - drop(tx); - - count = 0; - for _ in rx.iter() { - count += 1; - } - assert_eq!(count, 1); -} - -fn multiline_sugg() { - let v: Vec = vec![2]; - - v - .into_iter() - .map(|i| i * 2) - .filter(|i| i % 2 == 0) - .map(|_| ()) - .next() - .unwrap(); -} - -#[derive(Copy, Clone)] -pub struct ContainsUnit(()); // should be fine diff --git a/tests/ui/let_unit.rs b/tests/ui/let_unit.rs deleted file mode 100644 index af5b1fb2ac7e..000000000000 --- a/tests/ui/let_unit.rs +++ /dev/null @@ -1,63 +0,0 @@ -// run-rustfix - -#![warn(clippy::let_unit_value)] -#![allow(clippy::no_effect)] -#![allow(unused_variables)] - -macro_rules! let_and_return { - ($n:expr) => {{ - let ret = $n; - }}; -} - -fn main() { - let _x = println!("x"); - let _y = 1; // this is fine - let _z = ((), 1); // this as well - if true { - let _a = (); - } - - consume_units_with_for_loop(); // should be fine as well - - multiline_sugg(); - - let_and_return!(()) // should be fine -} - -// Related to issue #1964 -fn consume_units_with_for_loop() { - // `for_let_unit` lint should not be triggered by consuming them using for loop. - let v = vec![(), (), ()]; - let mut count = 0; - for _ in v { - count += 1; - } - assert_eq!(count, 3); - - // Same for consuming from some other Iterator. - let (tx, rx) = ::std::sync::mpsc::channel(); - tx.send(()).unwrap(); - drop(tx); - - count = 0; - for _ in rx.iter() { - count += 1; - } - assert_eq!(count, 1); -} - -fn multiline_sugg() { - let v: Vec = vec![2]; - - let _ = v - .into_iter() - .map(|i| i * 2) - .filter(|i| i % 2 == 0) - .map(|_| ()) - .next() - .unwrap(); -} - -#[derive(Copy, Clone)] -pub struct ContainsUnit(()); // should be fine diff --git a/tests/ui/let_unit.stderr b/tests/ui/let_unit.stderr deleted file mode 100644 index eb8482087bcc..000000000000 --- a/tests/ui/let_unit.stderr +++ /dev/null @@ -1,38 +0,0 @@ -error: this let-binding has unit value - --> $DIR/let_unit.rs:14:5 - | -LL | let _x = println!("x"); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `println!("x");` - | - = note: `-D clippy::let-unit-value` implied by `-D warnings` - -error: this let-binding has unit value - --> $DIR/let_unit.rs:18:9 - | -LL | let _a = (); - | ^^^^^^^^^^^^ help: omit the `let` binding: `();` - -error: this let-binding has unit value - --> $DIR/let_unit.rs:53:5 - | -LL | / let _ = v -LL | | .into_iter() -LL | | .map(|i| i * 2) -LL | | .filter(|i| i % 2 == 0) -LL | | .map(|_| ()) -LL | | .next() -LL | | .unwrap(); - | |__________________^ - | -help: omit the `let` binding - | -LL | v -LL | .into_iter() -LL | .map(|i| i * 2) -LL | .filter(|i| i % 2 == 0) -LL | .map(|_| ()) -LL | .next() - ... - -error: aborting due to 3 previous errors - diff --git a/tests/ui/literals.rs b/tests/ui/literals.rs deleted file mode 100644 index a72a74b9131d..000000000000 --- a/tests/ui/literals.rs +++ /dev/null @@ -1,41 +0,0 @@ -// does not test any rustfixable lints - -#![warn(clippy::mixed_case_hex_literals)] -#![warn(clippy::zero_prefixed_literal)] -#![allow(clippy::unseparated_literal_suffix)] -#![allow(dead_code)] - -fn main() { - let ok1 = 0xABCD; - let ok3 = 0xab_cd; - let ok4 = 0xab_cd_i32; - let ok5 = 0xAB_CD_u32; - let ok5 = 0xAB_CD_isize; - let fail1 = 0xabCD; - let fail2 = 0xabCD_u32; - let fail2 = 0xabCD_isize; - let fail_multi_zero = 000_123usize; - - let ok9 = 0; - let ok10 = 0_i64; - let fail8 = 0123; - - let ok11 = 0o123; - let ok12 = 0b10_1010; - - let ok13 = 0xab_abcd; - let ok14 = 0xBAFE_BAFE; - let ok15 = 0xab_cabc_abca_bcab_cabc; - let ok16 = 0xFE_BAFE_ABAB_ABCD; - let ok17 = 0x123_4567_8901_usize; - let ok18 = 0xF; - - let fail19 = 12_3456_21; - let fail22 = 3__4___23; - let fail23 = 3__16___23; - - let fail24 = 0xAB_ABC_AB; - let fail25 = 0b01_100_101; - let ok26 = 0x6_A0_BF; - let ok27 = 0b1_0010_0101; -} diff --git a/tests/ui/literals.stderr b/tests/ui/literals.stderr deleted file mode 100644 index 64ceeb316d8e..000000000000 --- a/tests/ui/literals.stderr +++ /dev/null @@ -1,87 +0,0 @@ -error: inconsistent casing in hexadecimal literal - --> $DIR/literals.rs:14:17 - | -LL | let fail1 = 0xabCD; - | ^^^^^^ - | - = note: `-D clippy::mixed-case-hex-literals` implied by `-D warnings` - -error: inconsistent casing in hexadecimal literal - --> $DIR/literals.rs:15:17 - | -LL | let fail2 = 0xabCD_u32; - | ^^^^^^^^^^ - -error: inconsistent casing in hexadecimal literal - --> $DIR/literals.rs:16:17 - | -LL | let fail2 = 0xabCD_isize; - | ^^^^^^^^^^^^ - -error: this is a decimal constant - --> $DIR/literals.rs:17:27 - | -LL | let fail_multi_zero = 000_123usize; - | ^^^^^^^^^^^^ - | - = note: `-D clippy::zero-prefixed-literal` implied by `-D warnings` -help: if you mean to use a decimal constant, remove the `0` to avoid confusion - | -LL | let fail_multi_zero = 123usize; - | ^^^^^^^^ -help: if you mean to use an octal constant, use `0o` - | -LL | let fail_multi_zero = 0o123usize; - | ^^^^^^^^^^ - -error: this is a decimal constant - --> $DIR/literals.rs:21:17 - | -LL | let fail8 = 0123; - | ^^^^ - | -help: if you mean to use a decimal constant, remove the `0` to avoid confusion - | -LL | let fail8 = 123; - | ^^^ -help: if you mean to use an octal constant, use `0o` - | -LL | let fail8 = 0o123; - | ^^^^^ - -error: digits grouped inconsistently by underscores - --> $DIR/literals.rs:33:18 - | -LL | let fail19 = 12_3456_21; - | ^^^^^^^^^^ help: consider: `12_345_621` - | - = note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` - -error: digits grouped inconsistently by underscores - --> $DIR/literals.rs:34:18 - | -LL | let fail22 = 3__4___23; - | ^^^^^^^^^ help: consider: `3_423` - -error: digits grouped inconsistently by underscores - --> $DIR/literals.rs:35:18 - | -LL | let fail23 = 3__16___23; - | ^^^^^^^^^^ help: consider: `31_623` - -error: digits of hex or binary literal not grouped by four - --> $DIR/literals.rs:37:18 - | -LL | let fail24 = 0xAB_ABC_AB; - | ^^^^^^^^^^^ help: consider: `0x0ABA_BCAB` - | - = note: `-D clippy::unusual-byte-groupings` implied by `-D warnings` - -error: digits of hex or binary literal not grouped by four - --> $DIR/literals.rs:38:18 - | -LL | let fail25 = 0b01_100_101; - | ^^^^^^^^^^^^ help: consider: `0b0110_0101` - -error: aborting due to 10 previous errors - diff --git a/tests/ui/logic_bug.rs b/tests/ui/logic_bug.rs deleted file mode 100644 index a01c6ef99db9..000000000000 --- a/tests/ui/logic_bug.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![allow(unused, clippy::many_single_char_names, clippy::diverging_sub_expression)] -#![warn(clippy::logic_bug)] - -fn main() { - let a: bool = unimplemented!(); - let b: bool = unimplemented!(); - let c: bool = unimplemented!(); - let d: bool = unimplemented!(); - let e: bool = unimplemented!(); - let _ = a && b || a; - let _ = !(a && b); - let _ = false && a; - // don't lint on cfgs - let _ = cfg!(you_shall_not_not_pass) && a; - let _ = a || !b || !c || !d || !e; - let _ = !(a && b || c); -} - -fn equality_stuff() { - let a: i32 = unimplemented!(); - let b: i32 = unimplemented!(); - let _ = a == b && a != b; - let _ = a < b && a >= b; - let _ = a > b && a <= b; - let _ = a > b && a == b; -} diff --git a/tests/ui/logic_bug.stderr b/tests/ui/logic_bug.stderr deleted file mode 100644 index 8f55e1c8ad85..000000000000 --- a/tests/ui/logic_bug.stderr +++ /dev/null @@ -1,63 +0,0 @@ -error: this boolean expression contains a logic bug - --> $DIR/logic_bug.rs:10:13 - | -LL | let _ = a && b || a; - | ^^^^^^^^^^^ help: it would look like the following: `a` - | - = note: `-D clippy::logic-bug` implied by `-D warnings` -help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/logic_bug.rs:10:18 - | -LL | let _ = a && b || a; - | ^ - -error: this boolean expression contains a logic bug - --> $DIR/logic_bug.rs:12:13 - | -LL | let _ = false && a; - | ^^^^^^^^^^ help: it would look like the following: `false` - | -help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/logic_bug.rs:12:22 - | -LL | let _ = false && a; - | ^ - -error: this boolean expression contains a logic bug - --> $DIR/logic_bug.rs:22:13 - | -LL | let _ = a == b && a != b; - | ^^^^^^^^^^^^^^^^ help: it would look like the following: `false` - | -help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/logic_bug.rs:22:13 - | -LL | let _ = a == b && a != b; - | ^^^^^^ - -error: this boolean expression contains a logic bug - --> $DIR/logic_bug.rs:23:13 - | -LL | let _ = a < b && a >= b; - | ^^^^^^^^^^^^^^^ help: it would look like the following: `false` - | -help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/logic_bug.rs:23:13 - | -LL | let _ = a < b && a >= b; - | ^^^^^ - -error: this boolean expression contains a logic bug - --> $DIR/logic_bug.rs:24:13 - | -LL | let _ = a > b && a <= b; - | ^^^^^^^^^^^^^^^ help: it would look like the following: `false` - | -help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/logic_bug.rs:24:13 - | -LL | let _ = a > b && a <= b; - | ^^^^^ - -error: aborting due to 5 previous errors - diff --git a/tests/ui/lossy_float_literal.fixed b/tests/ui/lossy_float_literal.fixed deleted file mode 100644 index 24e372354fc0..000000000000 --- a/tests/ui/lossy_float_literal.fixed +++ /dev/null @@ -1,35 +0,0 @@ -// run-rustfix -#![warn(clippy::lossy_float_literal)] - -fn main() { - // Lossy whole-number float literals - let _: f32 = 16_777_216.0; - let _: f32 = 16_777_220.0; - let _: f32 = 16_777_220.0; - let _: f32 = 16_777_220.0; - let _ = 16_777_220_f32; - let _: f32 = -16_777_220.0; - let _: f64 = 9_007_199_254_740_992.0; - let _: f64 = 9_007_199_254_740_992.0; - let _: f64 = 9_007_199_254_740_992.0; - let _ = 9_007_199_254_740_992_f64; - let _: f64 = -9_007_199_254_740_992.0; - - // Lossless whole number float literals - let _: f32 = 16_777_216.0; - let _: f32 = 16_777_218.0; - let _: f32 = 16_777_220.0; - let _: f32 = -16_777_216.0; - let _: f32 = -16_777_220.0; - let _: f64 = 16_777_217.0; - let _: f64 = -16_777_217.0; - let _: f64 = 9_007_199_254_740_992.0; - let _: f64 = -9_007_199_254_740_992.0; - - // Ignored whole number float literals - let _: f32 = 1e25; - let _: f32 = 1E25; - let _: f64 = 1e99; - let _: f64 = 1E99; - let _: f32 = 0.1; -} diff --git a/tests/ui/lossy_float_literal.rs b/tests/ui/lossy_float_literal.rs deleted file mode 100644 index 3dcf98fa0bdd..000000000000 --- a/tests/ui/lossy_float_literal.rs +++ /dev/null @@ -1,35 +0,0 @@ -// run-rustfix -#![warn(clippy::lossy_float_literal)] - -fn main() { - // Lossy whole-number float literals - let _: f32 = 16_777_217.0; - let _: f32 = 16_777_219.0; - let _: f32 = 16_777_219.; - let _: f32 = 16_777_219.000; - let _ = 16_777_219f32; - let _: f32 = -16_777_219.0; - let _: f64 = 9_007_199_254_740_993.0; - let _: f64 = 9_007_199_254_740_993.; - let _: f64 = 9_007_199_254_740_993.00; - let _ = 9_007_199_254_740_993f64; - let _: f64 = -9_007_199_254_740_993.0; - - // Lossless whole number float literals - let _: f32 = 16_777_216.0; - let _: f32 = 16_777_218.0; - let _: f32 = 16_777_220.0; - let _: f32 = -16_777_216.0; - let _: f32 = -16_777_220.0; - let _: f64 = 16_777_217.0; - let _: f64 = -16_777_217.0; - let _: f64 = 9_007_199_254_740_992.0; - let _: f64 = -9_007_199_254_740_992.0; - - // Ignored whole number float literals - let _: f32 = 1e25; - let _: f32 = 1E25; - let _: f64 = 1e99; - let _: f64 = 1E99; - let _: f32 = 0.1; -} diff --git a/tests/ui/lossy_float_literal.stderr b/tests/ui/lossy_float_literal.stderr deleted file mode 100644 index d2193c0c8195..000000000000 --- a/tests/ui/lossy_float_literal.stderr +++ /dev/null @@ -1,70 +0,0 @@ -error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:6:18 - | -LL | let _: f32 = 16_777_217.0; - | ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_216.0` - | - = note: `-D clippy::lossy-float-literal` implied by `-D warnings` - -error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:7:18 - | -LL | let _: f32 = 16_777_219.0; - | ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` - -error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:8:18 - | -LL | let _: f32 = 16_777_219.; - | ^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` - -error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:9:18 - | -LL | let _: f32 = 16_777_219.000; - | ^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` - -error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:10:13 - | -LL | let _ = 16_777_219f32; - | ^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220_f32` - -error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:11:19 - | -LL | let _: f32 = -16_777_219.0; - | ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` - -error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:12:18 - | -LL | let _: f64 = 9_007_199_254_740_993.0; - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` - -error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:13:18 - | -LL | let _: f64 = 9_007_199_254_740_993.; - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` - -error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:14:18 - | -LL | let _: f64 = 9_007_199_254_740_993.00; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` - -error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:15:13 - | -LL | let _ = 9_007_199_254_740_993f64; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992_f64` - -error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:16:19 - | -LL | let _: f64 = -9_007_199_254_740_993.0; - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` - -error: aborting due to 11 previous errors - diff --git a/tests/ui/macro_use_imports.fixed b/tests/ui/macro_use_imports.fixed deleted file mode 100644 index 91e34c62160a..000000000000 --- a/tests/ui/macro_use_imports.fixed +++ /dev/null @@ -1,43 +0,0 @@ -// compile-flags: --edition 2018 -// aux-build:macro_rules.rs -// aux-build:macro_use_helper.rs -// run-rustfix -// ignore-32bit - -#![allow(unused_imports, unreachable_code, unused_variables, dead_code)] -#![allow(clippy::single_component_path_imports)] -#![warn(clippy::macro_use_imports)] - -#[macro_use] -extern crate macro_use_helper as mac; - -#[macro_use] -extern crate clippy_mini_macro_test as mini_mac; - -mod a { - use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro}; - use mac; - use mini_mac::ClippyMiniMacroTest; - use mini_mac; - use mac::{inner::foofoo, inner::try_err}; - use mac::inner; - use mac::inner::nested::string_add; - use mac::inner::nested; - - #[derive(ClippyMiniMacroTest)] - struct Test; - - fn test() { - pub_macro!(); - inner_mod_macro!(); - pub_in_private_macro!(_var); - function_macro!(); - let v: ty_macro!() = Vec::default(); - - inner::try_err!(); - inner::foofoo!(); - nested::string_add!(); - } -} - -fn main() {} diff --git a/tests/ui/macro_use_imports.rs b/tests/ui/macro_use_imports.rs deleted file mode 100644 index 9c3c50c5d49f..000000000000 --- a/tests/ui/macro_use_imports.rs +++ /dev/null @@ -1,43 +0,0 @@ -// compile-flags: --edition 2018 -// aux-build:macro_rules.rs -// aux-build:macro_use_helper.rs -// run-rustfix -// ignore-32bit - -#![allow(unused_imports, unreachable_code, unused_variables, dead_code)] -#![allow(clippy::single_component_path_imports)] -#![warn(clippy::macro_use_imports)] - -#[macro_use] -extern crate macro_use_helper as mac; - -#[macro_use] -extern crate clippy_mini_macro_test as mini_mac; - -mod a { - #[macro_use] - use mac; - #[macro_use] - use mini_mac; - #[macro_use] - use mac::inner; - #[macro_use] - use mac::inner::nested; - - #[derive(ClippyMiniMacroTest)] - struct Test; - - fn test() { - pub_macro!(); - inner_mod_macro!(); - pub_in_private_macro!(_var); - function_macro!(); - let v: ty_macro!() = Vec::default(); - - inner::try_err!(); - inner::foofoo!(); - nested::string_add!(); - } -} - -fn main() {} diff --git a/tests/ui/macro_use_imports.stderr b/tests/ui/macro_use_imports.stderr deleted file mode 100644 index f8c86c8d9179..000000000000 --- a/tests/ui/macro_use_imports.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:18:5 - | -LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro};` - | - = note: `-D clippy::macro-use-imports` implied by `-D warnings` - -error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:20:5 - | -LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;` - -error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:22:5 - | -LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::foofoo, inner::try_err};` - -error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:24:5 - | -LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/manual_async_fn.fixed b/tests/ui/manual_async_fn.fixed deleted file mode 100644 index 5184f6fdb88b..000000000000 --- a/tests/ui/manual_async_fn.fixed +++ /dev/null @@ -1,111 +0,0 @@ -// run-rustfix -// edition:2018 -#![warn(clippy::manual_async_fn)] -#![allow(unused)] - -use std::future::Future; - -async fn fut() -> i32 { 42 } - -#[rustfmt::skip] -async fn fut2() -> i32 { 42 } - -#[rustfmt::skip] -async fn fut3() -> i32 { 42 } - -async fn empty_fut() {} - -#[rustfmt::skip] -async fn empty_fut2() {} - -#[rustfmt::skip] -async fn empty_fut3() {} - -async fn core_fut() -> i32 { 42 } - -// should be ignored -fn has_other_stmts() -> impl core::future::Future { - let _ = 42; - async move { 42 } -} - -// should be ignored -fn not_fut() -> i32 { - 42 -} - -// should be ignored -async fn already_async() -> impl Future { - async { 42 } -} - -struct S {} -impl S { - async fn inh_fut() -> i32 { - // NOTE: this code is here just to check that the indentation is correct in the suggested fix - let a = 42; - let b = 21; - if a < b { - let c = 21; - let d = 42; - if c < d { - let _ = 42; - } - } - 42 - } - - // should be ignored - fn not_fut(&self) -> i32 { - 42 - } - - // should be ignored - fn has_other_stmts() -> impl core::future::Future { - let _ = 42; - async move { 42 } - } - - // should be ignored - async fn already_async(&self) -> impl Future { - async { 42 } - } -} - -// Tests related to lifetime capture - -async fn elided(_: &i32) -> i32 { 42 } - -// should be ignored -fn elided_not_bound(_: &i32) -> impl Future { - async { 42 } -} - -async fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> i32 { 42 } - -// should be ignored -#[allow(clippy::needless_lifetimes)] -fn explicit_not_bound<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future { - async { 42 } -} - -// should be ignored -mod issue_5765 { - use std::future::Future; - - struct A; - impl A { - fn f(&self) -> impl Future { - async {} - } - } - - fn test() { - let _future = { - let a = A; - a.f() - }; - } -} - -fn main() {} diff --git a/tests/ui/manual_async_fn.rs b/tests/ui/manual_async_fn.rs deleted file mode 100644 index 68c0e591f0b6..000000000000 --- a/tests/ui/manual_async_fn.rs +++ /dev/null @@ -1,131 +0,0 @@ -// run-rustfix -// edition:2018 -#![warn(clippy::manual_async_fn)] -#![allow(unused)] - -use std::future::Future; - -fn fut() -> impl Future { - async { 42 } -} - -#[rustfmt::skip] -fn fut2() ->impl Future { - async { 42 } -} - -#[rustfmt::skip] -fn fut3()-> impl Future { - async { 42 } -} - -fn empty_fut() -> impl Future { - async {} -} - -#[rustfmt::skip] -fn empty_fut2() ->impl Future { - async {} -} - -#[rustfmt::skip] -fn empty_fut3()-> impl Future { - async {} -} - -fn core_fut() -> impl core::future::Future { - async move { 42 } -} - -// should be ignored -fn has_other_stmts() -> impl core::future::Future { - let _ = 42; - async move { 42 } -} - -// should be ignored -fn not_fut() -> i32 { - 42 -} - -// should be ignored -async fn already_async() -> impl Future { - async { 42 } -} - -struct S {} -impl S { - fn inh_fut() -> impl Future { - async { - // NOTE: this code is here just to check that the indentation is correct in the suggested fix - let a = 42; - let b = 21; - if a < b { - let c = 21; - let d = 42; - if c < d { - let _ = 42; - } - } - 42 - } - } - - // should be ignored - fn not_fut(&self) -> i32 { - 42 - } - - // should be ignored - fn has_other_stmts() -> impl core::future::Future { - let _ = 42; - async move { 42 } - } - - // should be ignored - async fn already_async(&self) -> impl Future { - async { 42 } - } -} - -// Tests related to lifetime capture - -fn elided(_: &i32) -> impl Future + '_ { - async { 42 } -} - -// should be ignored -fn elided_not_bound(_: &i32) -> impl Future { - async { 42 } -} - -fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { - async { 42 } -} - -// should be ignored -#[allow(clippy::needless_lifetimes)] -fn explicit_not_bound<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future { - async { 42 } -} - -// should be ignored -mod issue_5765 { - use std::future::Future; - - struct A; - impl A { - fn f(&self) -> impl Future { - async {} - } - } - - fn test() { - let _future = { - let a = A; - a.f() - }; - } -} - -fn main() {} diff --git a/tests/ui/manual_async_fn.stderr b/tests/ui/manual_async_fn.stderr deleted file mode 100644 index fdd43db3255e..000000000000 --- a/tests/ui/manual_async_fn.stderr +++ /dev/null @@ -1,158 +0,0 @@ -error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:8:1 - | -LL | fn fut() -> impl Future { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::manual-async-fn` implied by `-D warnings` -help: make the function `async` and return the output of the future directly - | -LL | async fn fut() -> i32 { - | ^^^^^^^^^^^^^^^^^^^^^ -help: move the body of the async block to the enclosing function - | -LL | fn fut() -> impl Future { 42 } - | ^^^^^^ - -error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:13:1 - | -LL | fn fut2() ->impl Future { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: make the function `async` and return the output of the future directly - | -LL | async fn fut2() -> i32 { - | ^^^^^^^^^^^^^^^^^^^^^^ -help: move the body of the async block to the enclosing function - | -LL | fn fut2() ->impl Future { 42 } - | ^^^^^^ - -error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:18:1 - | -LL | fn fut3()-> impl Future { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: make the function `async` and return the output of the future directly - | -LL | async fn fut3() -> i32 { - | ^^^^^^^^^^^^^^^^^^^^^^ -help: move the body of the async block to the enclosing function - | -LL | fn fut3()-> impl Future { 42 } - | ^^^^^^ - -error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:22:1 - | -LL | fn empty_fut() -> impl Future { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: make the function `async` and remove the return type - | -LL | async fn empty_fut() { - | ^^^^^^^^^^^^^^^^^^^^ -help: move the body of the async block to the enclosing function - | -LL | fn empty_fut() -> impl Future {} - | ^^ - -error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:27:1 - | -LL | fn empty_fut2() ->impl Future { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: make the function `async` and remove the return type - | -LL | async fn empty_fut2() { - | ^^^^^^^^^^^^^^^^^^^^^ -help: move the body of the async block to the enclosing function - | -LL | fn empty_fut2() ->impl Future {} - | ^^ - -error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:32:1 - | -LL | fn empty_fut3()-> impl Future { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: make the function `async` and remove the return type - | -LL | async fn empty_fut3() { - | ^^^^^^^^^^^^^^^^^^^^^ -help: move the body of the async block to the enclosing function - | -LL | fn empty_fut3()-> impl Future {} - | ^^ - -error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:36:1 - | -LL | fn core_fut() -> impl core::future::Future { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: make the function `async` and return the output of the future directly - | -LL | async fn core_fut() -> i32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: move the body of the async block to the enclosing function - | -LL | fn core_fut() -> impl core::future::Future { 42 } - | ^^^^^^ - -error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:58:5 - | -LL | fn inh_fut() -> impl Future { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: make the function `async` and return the output of the future directly - | -LL | async fn inh_fut() -> i32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -help: move the body of the async block to the enclosing function - | -LL | fn inh_fut() -> impl Future { -LL | // NOTE: this code is here just to check that the indentation is correct in the suggested fix -LL | let a = 42; -LL | let b = 21; -LL | if a < b { -LL | let c = 21; - ... - -error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:93:1 - | -LL | fn elided(_: &i32) -> impl Future + '_ { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: make the function `async` and return the output of the future directly - | -LL | async fn elided(_: &i32) -> i32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: move the body of the async block to the enclosing function - | -LL | fn elided(_: &i32) -> impl Future + '_ { 42 } - | ^^^^^^ - -error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:102:1 - | -LL | fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: make the function `async` and return the output of the future directly - | -LL | async fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> i32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: move the body of the async block to the enclosing function - | -LL | fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { 42 } - | ^^^^^^ - -error: aborting due to 10 previous errors - diff --git a/tests/ui/manual_memcpy/with_loop_counters.rs b/tests/ui/manual_memcpy/with_loop_counters.rs deleted file mode 100644 index ba388a05a285..000000000000 --- a/tests/ui/manual_memcpy/with_loop_counters.rs +++ /dev/null @@ -1,88 +0,0 @@ -#![warn(clippy::needless_range_loop, clippy::manual_memcpy)] - -pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { - let mut count = 0; - for i in 3..src.len() { - dst[i] = src[count]; - count += 1; - } - - let mut count = 0; - for i in 3..src.len() { - dst[count] = src[i]; - count += 1; - } - - let mut count = 3; - for i in 0..src.len() { - dst[count] = src[i]; - count += 1; - } - - let mut count = 3; - for i in 0..src.len() { - dst[i] = src[count]; - count += 1; - } - - let mut count = 0; - for i in 3..(3 + src.len()) { - dst[i] = src[count]; - count += 1; - } - - let mut count = 3; - for i in 5..src.len() { - dst[i] = src[count - 2]; - count += 1; - } - - let mut count = 2; - for i in 0..dst.len() { - dst[i] = src[count]; - count += 1; - } - - let mut count = 5; - for i in 3..10 { - dst[i] = src[count]; - count += 1; - } - - let mut count = 3; - let mut count2 = 30; - for i in 0..src.len() { - dst[count] = src[i]; - dst2[count2] = src[i]; - count += 1; - count2 += 1; - } - - // make sure parentheses are added properly to bitwise operators, which have lower precedence than - // arithmetric ones - let mut count = 0 << 1; - for i in 0..1 << 1 { - dst[count] = src[i + 2]; - count += 1; - } - - // make sure incrementing expressions without semicolons at the end of loops are handled correctly. - let mut count = 0; - for i in 3..src.len() { - dst[i] = src[count]; - count += 1 - } - - // make sure ones where the increment is not at the end of the loop. - // As a possible enhancement, one could adjust the offset in the suggestion according to - // the position. For example, if the increment is at the top of the loop; - // treating the loop counter as if it were initialized 1 greater than the original value. - let mut count = 0; - #[allow(clippy::needless_range_loop)] - for i in 0..src.len() { - count += 1; - dst[i] = src[count]; - } -} - -fn main() {} diff --git a/tests/ui/manual_memcpy/with_loop_counters.stderr b/tests/ui/manual_memcpy/with_loop_counters.stderr deleted file mode 100644 index 2547b19f5d1d..000000000000 --- a/tests/ui/manual_memcpy/with_loop_counters.stderr +++ /dev/null @@ -1,111 +0,0 @@ -error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:5:5 - | -LL | / for i in 3..src.len() { -LL | | dst[i] = src[count]; -LL | | count += 1; -LL | | } - | |_____^ help: try replacing the loop by: `dst[3..src.len()].clone_from_slice(&src[..(src.len() - 3)]);` - | - = note: `-D clippy::manual-memcpy` implied by `-D warnings` - -error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:11:5 - | -LL | / for i in 3..src.len() { -LL | | dst[count] = src[i]; -LL | | count += 1; -LL | | } - | |_____^ help: try replacing the loop by: `dst[..(src.len() - 3)].clone_from_slice(&src[3..]);` - -error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:17:5 - | -LL | / for i in 0..src.len() { -LL | | dst[count] = src[i]; -LL | | count += 1; -LL | | } - | |_____^ help: try replacing the loop by: `dst[3..(src.len() + 3)].clone_from_slice(&src[..]);` - -error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:23:5 - | -LL | / for i in 0..src.len() { -LL | | dst[i] = src[count]; -LL | | count += 1; -LL | | } - | |_____^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[3..(src.len() + 3)]);` - -error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:29:5 - | -LL | / for i in 3..(3 + src.len()) { -LL | | dst[i] = src[count]; -LL | | count += 1; -LL | | } - | |_____^ help: try replacing the loop by: `dst[3..((3 + src.len()))].clone_from_slice(&src[..((3 + src.len()) - 3)]);` - -error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:35:5 - | -LL | / for i in 5..src.len() { -LL | | dst[i] = src[count - 2]; -LL | | count += 1; -LL | | } - | |_____^ help: try replacing the loop by: `dst[5..src.len()].clone_from_slice(&src[(3 - 2)..((src.len() - 2) + 3 - 5)]);` - -error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:41:5 - | -LL | / for i in 0..dst.len() { -LL | | dst[i] = src[count]; -LL | | count += 1; -LL | | } - | |_____^ help: try replacing the loop by: `dst.clone_from_slice(&src[2..(dst.len() + 2)]);` - -error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:47:5 - | -LL | / for i in 3..10 { -LL | | dst[i] = src[count]; -LL | | count += 1; -LL | | } - | |_____^ help: try replacing the loop by: `dst[3..10].clone_from_slice(&src[5..(10 + 5 - 3)]);` - -error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:54:5 - | -LL | / for i in 0..src.len() { -LL | | dst[count] = src[i]; -LL | | dst2[count2] = src[i]; -LL | | count += 1; -LL | | count2 += 1; -LL | | } - | |_____^ - | -help: try replacing the loop by - | -LL | dst[3..(src.len() + 3)].clone_from_slice(&src[..]); -LL | dst2[30..(src.len() + 30)].clone_from_slice(&src[..]); - | - -error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:64:5 - | -LL | / for i in 0..1 << 1 { -LL | | dst[count] = src[i + 2]; -LL | | count += 1; -LL | | } - | |_____^ help: try replacing the loop by: `dst[(0 << 1)..((1 << 1) + (0 << 1))].clone_from_slice(&src[2..((1 << 1) + 2)]);` - -error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:71:5 - | -LL | / for i in 3..src.len() { -LL | | dst[i] = src[count]; -LL | | count += 1 -LL | | } - | |_____^ help: try replacing the loop by: `dst[3..src.len()].clone_from_slice(&src[..(src.len() - 3)]);` - -error: aborting due to 11 previous errors - diff --git a/tests/ui/manual_memcpy/without_loop_counters.rs b/tests/ui/manual_memcpy/without_loop_counters.rs deleted file mode 100644 index 0083f94798fe..000000000000 --- a/tests/ui/manual_memcpy/without_loop_counters.rs +++ /dev/null @@ -1,125 +0,0 @@ -#![warn(clippy::needless_range_loop, clippy::manual_memcpy)] - -const LOOP_OFFSET: usize = 5000; - -pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { - // plain manual memcpy - for i in 0..src.len() { - dst[i] = src[i]; - } - - // dst offset memcpy - for i in 0..src.len() { - dst[i + 10] = src[i]; - } - - // src offset memcpy - for i in 0..src.len() { - dst[i] = src[i + 10]; - } - - // src offset memcpy - for i in 11..src.len() { - dst[i] = src[i - 10]; - } - - // overwrite entire dst - for i in 0..dst.len() { - dst[i] = src[i]; - } - - // manual copy with branch - can't easily convert to memcpy! - for i in 0..src.len() { - dst[i] = src[i]; - if dst[i] > 5 { - break; - } - } - - // multiple copies - suggest two memcpy statements - for i in 10..256 { - dst[i] = src[i - 5]; - dst2[i + 500] = src[i] - } - - // this is a reversal - the copy lint shouldn't be triggered - for i in 10..LOOP_OFFSET { - dst[i + LOOP_OFFSET] = src[LOOP_OFFSET - i]; - } - - let some_var = 5; - // Offset in variable - for i in 10..LOOP_OFFSET { - dst[i + LOOP_OFFSET] = src[i - some_var]; - } - - // Non continuous copy - don't trigger lint - for i in 0..10 { - dst[i + i] = src[i]; - } - - let src_vec = vec![1, 2, 3, 4, 5]; - let mut dst_vec = vec![0, 0, 0, 0, 0]; - - // make sure vectors are supported - for i in 0..src_vec.len() { - dst_vec[i] = src_vec[i]; - } - - // lint should not trigger when either - // source or destination type is not - // slice-like, like DummyStruct - struct DummyStruct(i32); - - impl ::std::ops::Index for DummyStruct { - type Output = i32; - - fn index(&self, _: usize) -> &i32 { - &self.0 - } - } - - let src = DummyStruct(5); - let mut dst_vec = vec![0; 10]; - - for i in 0..10 { - dst_vec[i] = src[i]; - } - - // Simplify suggestion (issue #3004) - let src = [0, 1, 2, 3, 4]; - let mut dst = [0, 0, 0, 0, 0, 0]; - let from = 1; - - for i in from..from + src.len() { - dst[i] = src[i - from]; - } - - for i in from..from + 3 { - dst[i] = src[i - from]; - } - - #[allow(clippy::identity_op)] - for i in 0..5 { - dst[i - 0] = src[i]; - } - - #[allow(clippy::reversed_empty_ranges)] - for i in 0..0 { - dst[i] = src[i]; - } - - // `RangeTo` `for` loop - don't trigger lint - for i in 0.. { - dst[i] = src[i]; - } -} - -#[warn(clippy::needless_range_loop, clippy::manual_memcpy)] -pub fn manual_clone(src: &[String], dst: &mut [String]) { - for i in 0..src.len() { - dst[i] = src[i].clone(); - } -} - -fn main() {} diff --git a/tests/ui/manual_memcpy/without_loop_counters.stderr b/tests/ui/manual_memcpy/without_loop_counters.stderr deleted file mode 100644 index 54b966f6e541..000000000000 --- a/tests/ui/manual_memcpy/without_loop_counters.stderr +++ /dev/null @@ -1,115 +0,0 @@ -error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:7:5 - | -LL | / for i in 0..src.len() { -LL | | dst[i] = src[i]; -LL | | } - | |_____^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..]);` - | - = note: `-D clippy::manual-memcpy` implied by `-D warnings` - -error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:12:5 - | -LL | / for i in 0..src.len() { -LL | | dst[i + 10] = src[i]; -LL | | } - | |_____^ help: try replacing the loop by: `dst[10..(src.len() + 10)].clone_from_slice(&src[..]);` - -error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:17:5 - | -LL | / for i in 0..src.len() { -LL | | dst[i] = src[i + 10]; -LL | | } - | |_____^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[10..(src.len() + 10)]);` - -error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:22:5 - | -LL | / for i in 11..src.len() { -LL | | dst[i] = src[i - 10]; -LL | | } - | |_____^ help: try replacing the loop by: `dst[11..src.len()].clone_from_slice(&src[(11 - 10)..(src.len() - 10)]);` - -error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:27:5 - | -LL | / for i in 0..dst.len() { -LL | | dst[i] = src[i]; -LL | | } - | |_____^ help: try replacing the loop by: `dst.clone_from_slice(&src[..dst.len()]);` - -error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:40:5 - | -LL | / for i in 10..256 { -LL | | dst[i] = src[i - 5]; -LL | | dst2[i + 500] = src[i] -LL | | } - | |_____^ - | -help: try replacing the loop by - | -LL | dst[10..256].clone_from_slice(&src[(10 - 5)..(256 - 5)]); -LL | dst2[(10 + 500)..(256 + 500)].clone_from_slice(&src[10..256]); - | - -error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:52:5 - | -LL | / for i in 10..LOOP_OFFSET { -LL | | dst[i + LOOP_OFFSET] = src[i - some_var]; -LL | | } - | |_____^ help: try replacing the loop by: `dst[(10 + LOOP_OFFSET)..(LOOP_OFFSET + LOOP_OFFSET)].clone_from_slice(&src[(10 - some_var)..(LOOP_OFFSET - some_var)]);` - -error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:65:5 - | -LL | / for i in 0..src_vec.len() { -LL | | dst_vec[i] = src_vec[i]; -LL | | } - | |_____^ help: try replacing the loop by: `dst_vec[..src_vec.len()].clone_from_slice(&src_vec[..]);` - -error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:94:5 - | -LL | / for i in from..from + src.len() { -LL | | dst[i] = src[i - from]; -LL | | } - | |_____^ help: try replacing the loop by: `dst[from..(from + src.len())].clone_from_slice(&src[..(from + src.len() - from)]);` - -error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:98:5 - | -LL | / for i in from..from + 3 { -LL | | dst[i] = src[i - from]; -LL | | } - | |_____^ help: try replacing the loop by: `dst[from..(from + 3)].clone_from_slice(&src[..(from + 3 - from)]);` - -error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:103:5 - | -LL | / for i in 0..5 { -LL | | dst[i - 0] = src[i]; -LL | | } - | |_____^ help: try replacing the loop by: `dst[..5].clone_from_slice(&src[..5]);` - -error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:108:5 - | -LL | / for i in 0..0 { -LL | | dst[i] = src[i]; -LL | | } - | |_____^ help: try replacing the loop by: `dst[..0].clone_from_slice(&src[..0]);` - -error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:120:5 - | -LL | / for i in 0..src.len() { -LL | | dst[i] = src[i].clone(); -LL | | } - | |_____^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..]);` - -error: aborting due to 13 previous errors - diff --git a/tests/ui/manual_non_exhaustive.rs b/tests/ui/manual_non_exhaustive.rs deleted file mode 100644 index 7a788f485207..000000000000 --- a/tests/ui/manual_non_exhaustive.rs +++ /dev/null @@ -1,137 +0,0 @@ -#![warn(clippy::manual_non_exhaustive)] -#![allow(unused)] - -mod enums { - enum E { - A, - B, - #[doc(hidden)] - _C, - } - - // user forgot to remove the marker - #[non_exhaustive] - enum Ep { - A, - B, - #[doc(hidden)] - _C, - } - - // marker variant does not have doc hidden attribute, should be ignored - enum NoDocHidden { - A, - B, - _C, - } - - // name of variant with doc hidden does not start with underscore, should be ignored - enum NoUnderscore { - A, - B, - #[doc(hidden)] - C, - } - - // variant with doc hidden is not unit, should be ignored - enum NotUnit { - A, - B, - #[doc(hidden)] - _C(bool), - } - - // variant with doc hidden is the only one, should be ignored - enum OnlyMarker { - #[doc(hidden)] - _A, - } - - // variant with multiple markers, should be ignored - enum MultipleMarkers { - A, - #[doc(hidden)] - _B, - #[doc(hidden)] - _C, - } - - // already non_exhaustive and no markers, should be ignored - #[non_exhaustive] - enum NonExhaustive { - A, - B, - } -} - -mod structs { - struct S { - pub a: i32, - pub b: i32, - _c: (), - } - - // user forgot to remove the private field - #[non_exhaustive] - struct Sp { - pub a: i32, - pub b: i32, - _c: (), - } - - // some other fields are private, should be ignored - struct PrivateFields { - a: i32, - pub b: i32, - _c: (), - } - - // private field name does not start with underscore, should be ignored - struct NoUnderscore { - pub a: i32, - pub b: i32, - c: (), - } - - // private field is not unit type, should be ignored - struct NotUnit { - pub a: i32, - pub b: i32, - _c: i32, - } - - // private field is the only field, should be ignored - struct OnlyMarker { - _a: (), - } - - // already non exhaustive and no private fields, should be ignored - #[non_exhaustive] - struct NonExhaustive { - pub a: i32, - pub b: i32, - } -} - -mod tuple_structs { - struct T(pub i32, pub i32, ()); - - // user forgot to remove the private field - #[non_exhaustive] - struct Tp(pub i32, pub i32, ()); - - // some other fields are private, should be ignored - struct PrivateFields(pub i32, i32, ()); - - // private field is not unit type, should be ignored - struct NotUnit(pub i32, pub i32, i32); - - // private field is the only field, should be ignored - struct OnlyMarker(()); - - // already non exhaustive and no private fields, should be ignored - #[non_exhaustive] - struct NonExhaustive(pub i32, pub i32); -} - -fn main() {} diff --git a/tests/ui/manual_non_exhaustive.stderr b/tests/ui/manual_non_exhaustive.stderr deleted file mode 100644 index 613c5e8ca1d4..000000000000 --- a/tests/ui/manual_non_exhaustive.stderr +++ /dev/null @@ -1,103 +0,0 @@ -error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive.rs:5:5 - | -LL | enum E { - | ^----- - | | - | _____help: add the attribute: `#[non_exhaustive] enum E` - | | -LL | | A, -LL | | B, -LL | | #[doc(hidden)] -LL | | _C, -LL | | } - | |_____^ - | - = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings` -help: remove this variant - --> $DIR/manual_non_exhaustive.rs:9:9 - | -LL | _C, - | ^^ - -error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive.rs:14:5 - | -LL | / enum Ep { -LL | | A, -LL | | B, -LL | | #[doc(hidden)] -LL | | _C, -LL | | } - | |_____^ - | -help: remove this variant - --> $DIR/manual_non_exhaustive.rs:18:9 - | -LL | _C, - | ^^ - -error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive.rs:68:5 - | -LL | struct S { - | ^------- - | | - | _____help: add the attribute: `#[non_exhaustive] struct S` - | | -LL | | pub a: i32, -LL | | pub b: i32, -LL | | _c: (), -LL | | } - | |_____^ - | -help: remove this field - --> $DIR/manual_non_exhaustive.rs:71:9 - | -LL | _c: (), - | ^^^^^^ - -error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive.rs:76:5 - | -LL | / struct Sp { -LL | | pub a: i32, -LL | | pub b: i32, -LL | | _c: (), -LL | | } - | |_____^ - | -help: remove this field - --> $DIR/manual_non_exhaustive.rs:79:9 - | -LL | _c: (), - | ^^^^^^ - -error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive.rs:117:5 - | -LL | struct T(pub i32, pub i32, ()); - | --------^^^^^^^^^^^^^^^^^^^^^^^ - | | - | help: add the attribute: `#[non_exhaustive] struct T` - | -help: remove this field - --> $DIR/manual_non_exhaustive.rs:117:32 - | -LL | struct T(pub i32, pub i32, ()); - | ^^ - -error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive.rs:121:5 - | -LL | struct Tp(pub i32, pub i32, ()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: remove this field - --> $DIR/manual_non_exhaustive.rs:121:33 - | -LL | struct Tp(pub i32, pub i32, ()); - | ^^ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/manual_ok_or.fixed b/tests/ui/manual_ok_or.fixed deleted file mode 100644 index 887a97d7a017..000000000000 --- a/tests/ui/manual_ok_or.fixed +++ /dev/null @@ -1,40 +0,0 @@ -// run-rustfix -#![warn(clippy::manual_ok_or)] -#![allow(clippy::blacklisted_name)] -#![allow(clippy::redundant_closure)] -#![allow(dead_code)] -#![allow(unused_must_use)] - -fn main() { - // basic case - let foo: Option = None; - foo.ok_or("error"); - - // eta expansion case - foo.ok_or("error"); - - // turbo fish syntax - None::.ok_or("error"); - - // multiline case - #[rustfmt::skip] - foo.ok_or(&format!( - "{}{}{}{}{}{}{}", - "Alice", "Bob", "Sarah", "Marc", "Sandra", "Eric", "Jenifer")); - - // not applicable, closure isn't direct `Ok` wrapping - foo.map_or(Err("error"), |v| Ok(v + 1)); - - // not applicable, or side isn't `Result::Err` - foo.map_or(Ok::(1), |v| Ok(v)); - - // not applicable, expr is not a `Result` value - foo.map_or(42, |v| v); - - // TODO patterns not covered yet - match foo { - Some(v) => Ok(v), - None => Err("error"), - }; - foo.map_or_else(|| Err("error"), |v| Ok(v)); -} diff --git a/tests/ui/manual_ok_or.rs b/tests/ui/manual_ok_or.rs deleted file mode 100644 index 3c99872f5022..000000000000 --- a/tests/ui/manual_ok_or.rs +++ /dev/null @@ -1,44 +0,0 @@ -// run-rustfix -#![warn(clippy::manual_ok_or)] -#![allow(clippy::blacklisted_name)] -#![allow(clippy::redundant_closure)] -#![allow(dead_code)] -#![allow(unused_must_use)] - -fn main() { - // basic case - let foo: Option = None; - foo.map_or(Err("error"), |v| Ok(v)); - - // eta expansion case - foo.map_or(Err("error"), Ok); - - // turbo fish syntax - None::.map_or(Err("error"), |v| Ok(v)); - - // multiline case - #[rustfmt::skip] - foo.map_or(Err::( - &format!( - "{}{}{}{}{}{}{}", - "Alice", "Bob", "Sarah", "Marc", "Sandra", "Eric", "Jenifer") - ), - |v| Ok(v), - ); - - // not applicable, closure isn't direct `Ok` wrapping - foo.map_or(Err("error"), |v| Ok(v + 1)); - - // not applicable, or side isn't `Result::Err` - foo.map_or(Ok::(1), |v| Ok(v)); - - // not applicable, expr is not a `Result` value - foo.map_or(42, |v| v); - - // TODO patterns not covered yet - match foo { - Some(v) => Ok(v), - None => Err("error"), - }; - foo.map_or_else(|| Err("error"), |v| Ok(v)); -} diff --git a/tests/ui/manual_ok_or.stderr b/tests/ui/manual_ok_or.stderr deleted file mode 100644 index 8ea10ac54363..000000000000 --- a/tests/ui/manual_ok_or.stderr +++ /dev/null @@ -1,41 +0,0 @@ -error: this pattern reimplements `Option::ok_or` - --> $DIR/manual_ok_or.rs:11:5 - | -LL | foo.map_or(Err("error"), |v| Ok(v)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `foo.ok_or("error")` - | - = note: `-D clippy::manual-ok-or` implied by `-D warnings` - -error: this pattern reimplements `Option::ok_or` - --> $DIR/manual_ok_or.rs:14:5 - | -LL | foo.map_or(Err("error"), Ok); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `foo.ok_or("error")` - -error: this pattern reimplements `Option::ok_or` - --> $DIR/manual_ok_or.rs:17:5 - | -LL | None::.map_or(Err("error"), |v| Ok(v)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `None::.ok_or("error")` - -error: this pattern reimplements `Option::ok_or` - --> $DIR/manual_ok_or.rs:21:5 - | -LL | / foo.map_or(Err::( -LL | | &format!( -LL | | "{}{}{}{}{}{}{}", -LL | | "Alice", "Bob", "Sarah", "Marc", "Sandra", "Eric", "Jenifer") -LL | | ), -LL | | |v| Ok(v), -LL | | ); - | |_____^ - | -help: replace with - | -LL | foo.ok_or(&format!( -LL | "{}{}{}{}{}{}{}", -LL | "Alice", "Bob", "Sarah", "Marc", "Sandra", "Eric", "Jenifer")); - | - -error: aborting due to 4 previous errors - diff --git a/tests/ui/manual_saturating_arithmetic.fixed b/tests/ui/manual_saturating_arithmetic.fixed deleted file mode 100644 index c4f53c446c9f..000000000000 --- a/tests/ui/manual_saturating_arithmetic.fixed +++ /dev/null @@ -1,45 +0,0 @@ -// run-rustfix - -#![allow(unused_imports)] - -use std::{i128, i32, u128, u32}; - -fn main() { - let _ = 1u32.saturating_add(1); - let _ = 1u32.saturating_add(1); - let _ = 1u8.saturating_add(1); - let _ = 1u128.saturating_add(1); - let _ = 1u32.checked_add(1).unwrap_or(1234); // ok - let _ = 1u8.checked_add(1).unwrap_or(0); // ok - let _ = 1u32.saturating_mul(1); - - let _ = 1u32.saturating_sub(1); - let _ = 1u32.saturating_sub(1); - let _ = 1u8.saturating_sub(1); - let _ = 1u32.checked_sub(1).unwrap_or(1234); // ok - let _ = 1u8.checked_sub(1).unwrap_or(255); // ok - - let _ = 1i32.saturating_add(1); - let _ = 1i32.saturating_add(1); - let _ = 1i8.saturating_add(1); - let _ = 1i128.saturating_add(1); - let _ = 1i32.saturating_add(-1); - let _ = 1i32.saturating_add(-1); - let _ = 1i8.saturating_add(-1); - let _ = 1i128.saturating_add(-1); - let _ = 1i32.checked_add(1).unwrap_or(1234); // ok - let _ = 1i8.checked_add(1).unwrap_or(-128); // ok - let _ = 1i8.checked_add(-1).unwrap_or(127); // ok - - let _ = 1i32.saturating_sub(1); - let _ = 1i32.saturating_sub(1); - let _ = 1i8.saturating_sub(1); - let _ = 1i128.saturating_sub(1); - let _ = 1i32.saturating_sub(-1); - let _ = 1i32.saturating_sub(-1); - let _ = 1i8.saturating_sub(-1); - let _ = 1i128.saturating_sub(-1); - let _ = 1i32.checked_sub(1).unwrap_or(1234); // ok - let _ = 1i8.checked_sub(1).unwrap_or(127); // ok - let _ = 1i8.checked_sub(-1).unwrap_or(-128); // ok -} diff --git a/tests/ui/manual_saturating_arithmetic.rs b/tests/ui/manual_saturating_arithmetic.rs deleted file mode 100644 index cd83cf6e65e9..000000000000 --- a/tests/ui/manual_saturating_arithmetic.rs +++ /dev/null @@ -1,55 +0,0 @@ -// run-rustfix - -#![allow(unused_imports)] - -use std::{i128, i32, u128, u32}; - -fn main() { - let _ = 1u32.checked_add(1).unwrap_or(u32::max_value()); - let _ = 1u32.checked_add(1).unwrap_or(u32::MAX); - let _ = 1u8.checked_add(1).unwrap_or(255); - let _ = 1u128 - .checked_add(1) - .unwrap_or(340_282_366_920_938_463_463_374_607_431_768_211_455); - let _ = 1u32.checked_add(1).unwrap_or(1234); // ok - let _ = 1u8.checked_add(1).unwrap_or(0); // ok - let _ = 1u32.checked_mul(1).unwrap_or(u32::MAX); - - let _ = 1u32.checked_sub(1).unwrap_or(u32::min_value()); - let _ = 1u32.checked_sub(1).unwrap_or(u32::MIN); - let _ = 1u8.checked_sub(1).unwrap_or(0); - let _ = 1u32.checked_sub(1).unwrap_or(1234); // ok - let _ = 1u8.checked_sub(1).unwrap_or(255); // ok - - let _ = 1i32.checked_add(1).unwrap_or(i32::max_value()); - let _ = 1i32.checked_add(1).unwrap_or(i32::MAX); - let _ = 1i8.checked_add(1).unwrap_or(127); - let _ = 1i128 - .checked_add(1) - .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727); - let _ = 1i32.checked_add(-1).unwrap_or(i32::min_value()); - let _ = 1i32.checked_add(-1).unwrap_or(i32::MIN); - let _ = 1i8.checked_add(-1).unwrap_or(-128); - let _ = 1i128 - .checked_add(-1) - .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); - let _ = 1i32.checked_add(1).unwrap_or(1234); // ok - let _ = 1i8.checked_add(1).unwrap_or(-128); // ok - let _ = 1i8.checked_add(-1).unwrap_or(127); // ok - - let _ = 1i32.checked_sub(1).unwrap_or(i32::min_value()); - let _ = 1i32.checked_sub(1).unwrap_or(i32::MIN); - let _ = 1i8.checked_sub(1).unwrap_or(-128); - let _ = 1i128 - .checked_sub(1) - .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); - let _ = 1i32.checked_sub(-1).unwrap_or(i32::max_value()); - let _ = 1i32.checked_sub(-1).unwrap_or(i32::MAX); - let _ = 1i8.checked_sub(-1).unwrap_or(127); - let _ = 1i128 - .checked_sub(-1) - .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727); - let _ = 1i32.checked_sub(1).unwrap_or(1234); // ok - let _ = 1i8.checked_sub(1).unwrap_or(127); // ok - let _ = 1i8.checked_sub(-1).unwrap_or(-128); // ok -} diff --git a/tests/ui/manual_saturating_arithmetic.stderr b/tests/ui/manual_saturating_arithmetic.stderr deleted file mode 100644 index d985f2e754bc..000000000000 --- a/tests/ui/manual_saturating_arithmetic.stderr +++ /dev/null @@ -1,163 +0,0 @@ -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:8:13 - | -LL | let _ = 1u32.checked_add(1).unwrap_or(u32::max_value()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1u32.saturating_add(1)` - | - = note: `-D clippy::manual-saturating-arithmetic` implied by `-D warnings` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:9:13 - | -LL | let _ = 1u32.checked_add(1).unwrap_or(u32::MAX); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1u32.saturating_add(1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:10:13 - | -LL | let _ = 1u8.checked_add(1).unwrap_or(255); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1u8.saturating_add(1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:11:13 - | -LL | let _ = 1u128 - | _____________^ -LL | | .checked_add(1) -LL | | .unwrap_or(340_282_366_920_938_463_463_374_607_431_768_211_455); - | |_______________________________________________________________________^ help: try using `saturating_add`: `1u128.saturating_add(1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:16:13 - | -LL | let _ = 1u32.checked_mul(1).unwrap_or(u32::MAX); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_mul`: `1u32.saturating_mul(1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:18:13 - | -LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::min_value()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1u32.saturating_sub(1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:19:13 - | -LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::MIN); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1u32.saturating_sub(1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:20:13 - | -LL | let _ = 1u8.checked_sub(1).unwrap_or(0); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1u8.saturating_sub(1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:24:13 - | -LL | let _ = 1i32.checked_add(1).unwrap_or(i32::max_value()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:25:13 - | -LL | let _ = 1i32.checked_add(1).unwrap_or(i32::MAX); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:26:13 - | -LL | let _ = 1i8.checked_add(1).unwrap_or(127); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i8.saturating_add(1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:27:13 - | -LL | let _ = 1i128 - | _____________^ -LL | | .checked_add(1) -LL | | .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727); - | |_______________________________________________________________________^ help: try using `saturating_add`: `1i128.saturating_add(1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:30:13 - | -LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::min_value()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(-1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:31:13 - | -LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::MIN); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(-1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:32:13 - | -LL | let _ = 1i8.checked_add(-1).unwrap_or(-128); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i8.saturating_add(-1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:33:13 - | -LL | let _ = 1i128 - | _____________^ -LL | | .checked_add(-1) -LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); - | |________________________________________________________________________^ help: try using `saturating_add`: `1i128.saturating_add(-1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:40:13 - | -LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::min_value()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:41:13 - | -LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::MIN); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:42:13 - | -LL | let _ = 1i8.checked_sub(1).unwrap_or(-128); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i8.saturating_sub(1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:43:13 - | -LL | let _ = 1i128 - | _____________^ -LL | | .checked_sub(1) -LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); - | |________________________________________________________________________^ help: try using `saturating_sub`: `1i128.saturating_sub(1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:46:13 - | -LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::max_value()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(-1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:47:13 - | -LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::MAX); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(-1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:48:13 - | -LL | let _ = 1i8.checked_sub(-1).unwrap_or(127); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i8.saturating_sub(-1)` - -error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:49:13 - | -LL | let _ = 1i128 - | _____________^ -LL | | .checked_sub(-1) -LL | | .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727); - | |_______________________________________________________________________^ help: try using `saturating_sub`: `1i128.saturating_sub(-1)` - -error: aborting due to 24 previous errors - diff --git a/tests/ui/manual_strip.rs b/tests/ui/manual_strip.rs deleted file mode 100644 index cbb84eb5c7e3..000000000000 --- a/tests/ui/manual_strip.rs +++ /dev/null @@ -1,66 +0,0 @@ -#![warn(clippy::manual_strip)] - -fn main() { - let s = "abc"; - - if s.starts_with("ab") { - str::to_string(&s["ab".len()..]); - s["ab".len()..].to_string(); - - str::to_string(&s[2..]); - s[2..].to_string(); - } - - if s.ends_with("bc") { - str::to_string(&s[..s.len() - "bc".len()]); - s[..s.len() - "bc".len()].to_string(); - - str::to_string(&s[..s.len() - 2]); - s[..s.len() - 2].to_string(); - } - - // Character patterns - if s.starts_with('a') { - str::to_string(&s[1..]); - s[1..].to_string(); - } - - // Variable prefix - let prefix = "ab"; - if s.starts_with(prefix) { - str::to_string(&s[prefix.len()..]); - } - - // Constant prefix - const PREFIX: &str = "ab"; - if s.starts_with(PREFIX) { - str::to_string(&s[PREFIX.len()..]); - str::to_string(&s[2..]); - } - - // Constant target - const TARGET: &str = "abc"; - if TARGET.starts_with(prefix) { - str::to_string(&TARGET[prefix.len()..]); - } - - // String target - not mutated. - let s1: String = "abc".into(); - if s1.starts_with("ab") { - s1[2..].to_uppercase(); - } - - // String target - mutated. (Don't lint.) - let mut s2: String = "abc".into(); - if s2.starts_with("ab") { - s2.push('d'); - s2[2..].to_uppercase(); - } - - // Target not stripped. (Don't lint.) - let s3 = String::from("abcd"); - let s4 = String::from("efgh"); - if s3.starts_with("ab") { - s4[2..].to_string(); - } -} diff --git a/tests/ui/manual_strip.stderr b/tests/ui/manual_strip.stderr deleted file mode 100644 index 1352a8713d4f..000000000000 --- a/tests/ui/manual_strip.stderr +++ /dev/null @@ -1,132 +0,0 @@ -error: stripping a prefix manually - --> $DIR/manual_strip.rs:7:24 - | -LL | str::to_string(&s["ab".len()..]); - | ^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::manual-strip` implied by `-D warnings` -note: the prefix was tested here - --> $DIR/manual_strip.rs:6:5 - | -LL | if s.starts_with("ab") { - | ^^^^^^^^^^^^^^^^^^^^^^^ -help: try using the `strip_prefix` method - | -LL | if let Some() = s.strip_prefix("ab") { -LL | str::to_string(); -LL | .to_string(); -LL | -LL | str::to_string(); -LL | .to_string(); - | - -error: stripping a suffix manually - --> $DIR/manual_strip.rs:15:24 - | -LL | str::to_string(&s[..s.len() - "bc".len()]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: the suffix was tested here - --> $DIR/manual_strip.rs:14:5 - | -LL | if s.ends_with("bc") { - | ^^^^^^^^^^^^^^^^^^^^^ -help: try using the `strip_suffix` method - | -LL | if let Some() = s.strip_suffix("bc") { -LL | str::to_string(); -LL | .to_string(); -LL | -LL | str::to_string(); -LL | .to_string(); - | - -error: stripping a prefix manually - --> $DIR/manual_strip.rs:24:24 - | -LL | str::to_string(&s[1..]); - | ^^^^^^^ - | -note: the prefix was tested here - --> $DIR/manual_strip.rs:23:5 - | -LL | if s.starts_with('a') { - | ^^^^^^^^^^^^^^^^^^^^^^ -help: try using the `strip_prefix` method - | -LL | if let Some() = s.strip_prefix('a') { -LL | str::to_string(); -LL | .to_string(); - | - -error: stripping a prefix manually - --> $DIR/manual_strip.rs:31:24 - | -LL | str::to_string(&s[prefix.len()..]); - | ^^^^^^^^^^^^^^^^^^ - | -note: the prefix was tested here - --> $DIR/manual_strip.rs:30:5 - | -LL | if s.starts_with(prefix) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -help: try using the `strip_prefix` method - | -LL | if let Some() = s.strip_prefix(prefix) { -LL | str::to_string(); - | - -error: stripping a prefix manually - --> $DIR/manual_strip.rs:37:24 - | -LL | str::to_string(&s[PREFIX.len()..]); - | ^^^^^^^^^^^^^^^^^^ - | -note: the prefix was tested here - --> $DIR/manual_strip.rs:36:5 - | -LL | if s.starts_with(PREFIX) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -help: try using the `strip_prefix` method - | -LL | if let Some() = s.strip_prefix(PREFIX) { -LL | str::to_string(); -LL | str::to_string(); - | - -error: stripping a prefix manually - --> $DIR/manual_strip.rs:44:24 - | -LL | str::to_string(&TARGET[prefix.len()..]); - | ^^^^^^^^^^^^^^^^^^^^^^^ - | -note: the prefix was tested here - --> $DIR/manual_strip.rs:43:5 - | -LL | if TARGET.starts_with(prefix) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: try using the `strip_prefix` method - | -LL | if let Some() = TARGET.strip_prefix(prefix) { -LL | str::to_string(); - | - -error: stripping a prefix manually - --> $DIR/manual_strip.rs:50:9 - | -LL | s1[2..].to_uppercase(); - | ^^^^^^^ - | -note: the prefix was tested here - --> $DIR/manual_strip.rs:49:5 - | -LL | if s1.starts_with("ab") { - | ^^^^^^^^^^^^^^^^^^^^^^^^ -help: try using the `strip_prefix` method - | -LL | if let Some() = s1.strip_prefix("ab") { -LL | .to_uppercase(); - | - -error: aborting due to 7 previous errors - diff --git a/tests/ui/manual_unwrap_or.fixed b/tests/ui/manual_unwrap_or.fixed deleted file mode 100644 index 81d903c15d32..000000000000 --- a/tests/ui/manual_unwrap_or.fixed +++ /dev/null @@ -1,139 +0,0 @@ -// run-rustfix -#![allow(dead_code)] -#![allow(unused_variables, clippy::unnecessary_wraps)] - -fn option_unwrap_or() { - // int case - Some(1).unwrap_or(42); - - // int case reversed - Some(1).unwrap_or(42); - - // richer none expr - Some(1).unwrap_or(1 + 42); - - // multiline case - #[rustfmt::skip] - Some(1).unwrap_or({ - 42 + 42 - + 42 + 42 + 42 - + 42 + 42 + 42 - }); - - // string case - Some("Bob").unwrap_or("Alice"); - - // don't lint - match Some(1) { - Some(i) => i + 2, - None => 42, - }; - match Some(1) { - Some(i) => i, - None => return, - }; - for j in 0..4 { - match Some(j) { - Some(i) => i, - None => continue, - }; - match Some(j) { - Some(i) => i, - None => break, - }; - } - - // cases where the none arm isn't a constant expression - // are not linted due to potential ownership issues - - // ownership issue example, don't lint - struct NonCopyable; - let mut option: Option = None; - match option { - Some(x) => x, - None => { - option = Some(NonCopyable); - // some more code ... - option.unwrap() - }, - }; - - // ownership issue example, don't lint - let option: Option<&str> = None; - match option { - Some(s) => s, - None => &format!("{} {}!", "hello", "world"), - }; -} - -fn result_unwrap_or() { - // int case - Ok::(1).unwrap_or(42); - - // int case, scrutinee is a binding - let a = Ok::(1); - a.unwrap_or(42); - - // int case, suggestion must surround Result expr with parenthesis - (Ok(1) as Result).unwrap_or(42); - - // method call case, suggestion must not surround Result expr `s.method()` with parenthesis - struct S {} - impl S { - fn method(self) -> Option { - Some(42) - } - } - let s = S {}; - s.method().unwrap_or(42); - - // int case reversed - Ok::(1).unwrap_or(42); - - // richer none expr - Ok::(1).unwrap_or(1 + 42); - - // multiline case - #[rustfmt::skip] - Ok::(1).unwrap_or({ - 42 + 42 - + 42 + 42 + 42 - + 42 + 42 + 42 - }); - - // string case - Ok::<&str, &str>("Bob").unwrap_or("Alice"); - - // don't lint - match Ok::(1) { - Ok(i) => i + 2, - Err(_) => 42, - }; - match Ok::(1) { - Ok(i) => i, - Err(_) => return, - }; - for j in 0..4 { - match Ok::(j) { - Ok(i) => i, - Err(_) => continue, - }; - match Ok::(j) { - Ok(i) => i, - Err(_) => break, - }; - } - - // don't lint, Err value is used - match Ok::<&str, &str>("Alice") { - Ok(s) => s, - Err(s) => s, - }; - // could lint, but unused_variables takes care of it - match Ok::<&str, &str>("Alice") { - Ok(s) => s, - Err(s) => "Bob", - }; -} - -fn main() {} diff --git a/tests/ui/manual_unwrap_or.rs b/tests/ui/manual_unwrap_or.rs deleted file mode 100644 index 16105d379c30..000000000000 --- a/tests/ui/manual_unwrap_or.rs +++ /dev/null @@ -1,178 +0,0 @@ -// run-rustfix -#![allow(dead_code)] -#![allow(unused_variables, clippy::unnecessary_wraps)] - -fn option_unwrap_or() { - // int case - match Some(1) { - Some(i) => i, - None => 42, - }; - - // int case reversed - match Some(1) { - None => 42, - Some(i) => i, - }; - - // richer none expr - match Some(1) { - Some(i) => i, - None => 1 + 42, - }; - - // multiline case - #[rustfmt::skip] - match Some(1) { - Some(i) => i, - None => { - 42 + 42 - + 42 + 42 + 42 - + 42 + 42 + 42 - } - }; - - // string case - match Some("Bob") { - Some(i) => i, - None => "Alice", - }; - - // don't lint - match Some(1) { - Some(i) => i + 2, - None => 42, - }; - match Some(1) { - Some(i) => i, - None => return, - }; - for j in 0..4 { - match Some(j) { - Some(i) => i, - None => continue, - }; - match Some(j) { - Some(i) => i, - None => break, - }; - } - - // cases where the none arm isn't a constant expression - // are not linted due to potential ownership issues - - // ownership issue example, don't lint - struct NonCopyable; - let mut option: Option = None; - match option { - Some(x) => x, - None => { - option = Some(NonCopyable); - // some more code ... - option.unwrap() - }, - }; - - // ownership issue example, don't lint - let option: Option<&str> = None; - match option { - Some(s) => s, - None => &format!("{} {}!", "hello", "world"), - }; -} - -fn result_unwrap_or() { - // int case - match Ok::(1) { - Ok(i) => i, - Err(_) => 42, - }; - - // int case, scrutinee is a binding - let a = Ok::(1); - match a { - Ok(i) => i, - Err(_) => 42, - }; - - // int case, suggestion must surround Result expr with parenthesis - match Ok(1) as Result { - Ok(i) => i, - Err(_) => 42, - }; - - // method call case, suggestion must not surround Result expr `s.method()` with parenthesis - struct S {} - impl S { - fn method(self) -> Option { - Some(42) - } - } - let s = S {}; - match s.method() { - Some(i) => i, - None => 42, - }; - - // int case reversed - match Ok::(1) { - Err(_) => 42, - Ok(i) => i, - }; - - // richer none expr - match Ok::(1) { - Ok(i) => i, - Err(_) => 1 + 42, - }; - - // multiline case - #[rustfmt::skip] - match Ok::(1) { - Ok(i) => i, - Err(_) => { - 42 + 42 - + 42 + 42 + 42 - + 42 + 42 + 42 - } - }; - - // string case - match Ok::<&str, &str>("Bob") { - Ok(i) => i, - Err(_) => "Alice", - }; - - // don't lint - match Ok::(1) { - Ok(i) => i + 2, - Err(_) => 42, - }; - match Ok::(1) { - Ok(i) => i, - Err(_) => return, - }; - for j in 0..4 { - match Ok::(j) { - Ok(i) => i, - Err(_) => continue, - }; - match Ok::(j) { - Ok(i) => i, - Err(_) => break, - }; - } - - // don't lint, Err value is used - match Ok::<&str, &str>("Alice") { - Ok(s) => s, - Err(s) => s, - }; - // could lint, but unused_variables takes care of it - match Ok::<&str, &str>("Alice") { - Ok(s) => s, - Err(s) => "Bob", - }; -} - -fn main() {} diff --git a/tests/ui/manual_unwrap_or.stderr b/tests/ui/manual_unwrap_or.stderr deleted file mode 100644 index fc174c4c2705..000000000000 --- a/tests/ui/manual_unwrap_or.stderr +++ /dev/null @@ -1,145 +0,0 @@ -error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:7:5 - | -LL | / match Some(1) { -LL | | Some(i) => i, -LL | | None => 42, -LL | | }; - | |_____^ help: replace with: `Some(1).unwrap_or(42)` - | - = note: `-D clippy::manual-unwrap-or` implied by `-D warnings` - -error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:13:5 - | -LL | / match Some(1) { -LL | | None => 42, -LL | | Some(i) => i, -LL | | }; - | |_____^ help: replace with: `Some(1).unwrap_or(42)` - -error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:19:5 - | -LL | / match Some(1) { -LL | | Some(i) => i, -LL | | None => 1 + 42, -LL | | }; - | |_____^ help: replace with: `Some(1).unwrap_or(1 + 42)` - -error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:26:5 - | -LL | / match Some(1) { -LL | | Some(i) => i, -LL | | None => { -LL | | 42 + 42 -... | -LL | | } -LL | | }; - | |_____^ - | -help: replace with - | -LL | Some(1).unwrap_or({ -LL | 42 + 42 -LL | + 42 + 42 + 42 -LL | + 42 + 42 + 42 -LL | }); - | - -error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:36:5 - | -LL | / match Some("Bob") { -LL | | Some(i) => i, -LL | | None => "Alice", -LL | | }; - | |_____^ help: replace with: `Some("Bob").unwrap_or("Alice")` - -error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:86:5 - | -LL | / match Ok::(1) { -LL | | Ok(i) => i, -LL | | Err(_) => 42, -LL | | }; - | |_____^ help: replace with: `Ok::(1).unwrap_or(42)` - -error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:93:5 - | -LL | / match a { -LL | | Ok(i) => i, -LL | | Err(_) => 42, -LL | | }; - | |_____^ help: replace with: `a.unwrap_or(42)` - -error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:99:5 - | -LL | / match Ok(1) as Result { -LL | | Ok(i) => i, -LL | | Err(_) => 42, -LL | | }; - | |_____^ help: replace with: `(Ok(1) as Result).unwrap_or(42)` - -error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:112:5 - | -LL | / match s.method() { -LL | | Some(i) => i, -LL | | None => 42, -LL | | }; - | |_____^ help: replace with: `s.method().unwrap_or(42)` - -error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:118:5 - | -LL | / match Ok::(1) { -LL | | Err(_) => 42, -LL | | Ok(i) => i, -LL | | }; - | |_____^ help: replace with: `Ok::(1).unwrap_or(42)` - -error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:124:5 - | -LL | / match Ok::(1) { -LL | | Ok(i) => i, -LL | | Err(_) => 1 + 42, -LL | | }; - | |_____^ help: replace with: `Ok::(1).unwrap_or(1 + 42)` - -error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:131:5 - | -LL | / match Ok::(1) { -LL | | Ok(i) => i, -LL | | Err(_) => { -LL | | 42 + 42 -... | -LL | | } -LL | | }; - | |_____^ - | -help: replace with - | -LL | Ok::(1).unwrap_or({ -LL | 42 + 42 -LL | + 42 + 42 + 42 -LL | + 42 + 42 + 42 -LL | }); - | - -error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:141:5 - | -LL | / match Ok::<&str, &str>("Bob") { -LL | | Ok(i) => i, -LL | | Err(_) => "Alice", -LL | | }; - | |_____^ help: replace with: `Ok::<&str, &str>("Bob").unwrap_or("Alice")` - -error: aborting due to 13 previous errors - diff --git a/tests/ui/many_single_char_names.rs b/tests/ui/many_single_char_names.rs deleted file mode 100644 index 80800e487248..000000000000 --- a/tests/ui/many_single_char_names.rs +++ /dev/null @@ -1,73 +0,0 @@ -#[warn(clippy::many_single_char_names)] - -fn bla() { - let a: i32; - let (b, c, d): (i32, i64, i16); - { - { - let cdefg: i32; - let blar: i32; - } - { - let e: i32; - } - { - let e: i32; - let f: i32; - } - match 5 { - 1 => println!(), - e => panic!(), - } - match 5 { - 1 => println!(), - _ => panic!(), - } - } -} - -fn bindings(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) {} - -fn bindings2() { - let (a, b, c, d, e, f, g, h): (bool, bool, bool, bool, bool, bool, bool, bool) = unimplemented!(); -} - -fn shadowing() { - let a = 0i32; - let a = 0i32; - let a = 0i32; - let a = 0i32; - let a = 0i32; - let a = 0i32; - { - let a = 0i32; - } -} - -fn patterns() { - enum Z { - A(i32), - B(i32), - C(i32), - D(i32), - E(i32), - F(i32), - } - - // These should not trigger a warning, since the pattern bindings are a new scope. - match Z::A(0) { - Z::A(a) => {}, - Z::B(b) => {}, - Z::C(c) => {}, - Z::D(d) => {}, - Z::E(e) => {}, - Z::F(f) => {}, - } -} - -#[allow(clippy::many_single_char_names)] -fn issue_3198_allow_works() { - let (a, b, c, d, e) = (0, 0, 0, 0, 0); -} - -fn main() {} diff --git a/tests/ui/many_single_char_names.stderr b/tests/ui/many_single_char_names.stderr deleted file mode 100644 index 27e62e641ade..000000000000 --- a/tests/ui/many_single_char_names.stderr +++ /dev/null @@ -1,51 +0,0 @@ -error: 5 bindings with single-character names in scope - --> $DIR/many_single_char_names.rs:4:9 - | -LL | let a: i32; - | ^ -LL | let (b, c, d): (i32, i64, i16); - | ^ ^ ^ -... -LL | let e: i32; - | ^ - | - = note: `-D clippy::many-single-char-names` implied by `-D warnings` - -error: 6 bindings with single-character names in scope - --> $DIR/many_single_char_names.rs:4:9 - | -LL | let a: i32; - | ^ -LL | let (b, c, d): (i32, i64, i16); - | ^ ^ ^ -... -LL | let e: i32; - | ^ -LL | let f: i32; - | ^ - -error: 5 bindings with single-character names in scope - --> $DIR/many_single_char_names.rs:4:9 - | -LL | let a: i32; - | ^ -LL | let (b, c, d): (i32, i64, i16); - | ^ ^ ^ -... -LL | e => panic!(), - | ^ - -error: 8 bindings with single-character names in scope - --> $DIR/many_single_char_names.rs:29:13 - | -LL | fn bindings(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) {} - | ^ ^ ^ ^ ^ ^ ^ ^ - -error: 8 bindings with single-character names in scope - --> $DIR/many_single_char_names.rs:32:10 - | -LL | let (a, b, c, d, e, f, g, h): (bool, bool, bool, bool, bool, bool, bool, bool) = unimplemented!(); - | ^ ^ ^ ^ ^ ^ ^ ^ - -error: aborting due to 5 previous errors - diff --git a/tests/ui/map_clone.fixed b/tests/ui/map_clone.fixed deleted file mode 100644 index 178d8705c2f0..000000000000 --- a/tests/ui/map_clone.fixed +++ /dev/null @@ -1,63 +0,0 @@ -// run-rustfix -#![warn(clippy::all, clippy::pedantic)] -#![allow(clippy::iter_cloned_collect)] -#![allow(clippy::clone_on_copy, clippy::redundant_clone)] -#![allow(clippy::let_underscore_drop)] -#![allow(clippy::missing_docs_in_private_items)] -#![allow(clippy::redundant_closure_for_method_calls)] -#![allow(clippy::many_single_char_names)] - -fn main() { - let _: Vec = vec![5_i8; 6].iter().copied().collect(); - let _: Vec = vec![String::new()].iter().cloned().collect(); - let _: Vec = vec![42, 43].iter().copied().collect(); - let _: Option = Some(Box::new(16)).map(|b| *b); - let _: Option = Some(&16).copied(); - let _: Option = Some(&1).copied(); - - // Don't lint these - let v = vec![5_i8; 6]; - let a = 0; - let b = &a; - let _ = v.iter().map(|_x| *b); - let _ = v.iter().map(|_x| a.clone()); - let _ = v.iter().map(|&_x| a); - - // Issue #498 - let _ = std::env::args(); - - // Issue #4824 item types that aren't references - { - use std::rc::Rc; - - let o: Option> = Some(Rc::new(0_u32)); - let _: Option = o.map(|x| *x); - let v: Vec> = vec![Rc::new(0_u32)]; - let _: Vec = v.into_iter().map(|x| *x).collect(); - } - - // Issue #5524 mutable references - { - let mut c = 42; - let v = vec![&mut c]; - let _: Vec = v.into_iter().map(|x| *x).collect(); - let mut d = 21; - let v = vec![&mut d]; - let _: Vec = v.into_iter().map(|&mut x| x).collect(); - } - - // Issue #6299 - { - let mut aa = 5; - let mut bb = 3; - let items = vec![&mut aa, &mut bb]; - let _: Vec<_> = items.into_iter().map(|x| x.clone()).collect(); - } - - // Issue #6239 deref coercion and clone deref - { - use std::cell::RefCell; - - let _ = Some(RefCell::new(String::new()).borrow()).map(|s| s.clone()); - } -} diff --git a/tests/ui/map_clone.rs b/tests/ui/map_clone.rs deleted file mode 100644 index c73d81713b8a..000000000000 --- a/tests/ui/map_clone.rs +++ /dev/null @@ -1,63 +0,0 @@ -// run-rustfix -#![warn(clippy::all, clippy::pedantic)] -#![allow(clippy::iter_cloned_collect)] -#![allow(clippy::clone_on_copy, clippy::redundant_clone)] -#![allow(clippy::let_underscore_drop)] -#![allow(clippy::missing_docs_in_private_items)] -#![allow(clippy::redundant_closure_for_method_calls)] -#![allow(clippy::many_single_char_names)] - -fn main() { - let _: Vec = vec![5_i8; 6].iter().map(|x| *x).collect(); - let _: Vec = vec![String::new()].iter().map(|x| x.clone()).collect(); - let _: Vec = vec![42, 43].iter().map(|&x| x).collect(); - let _: Option = Some(Box::new(16)).map(|b| *b); - let _: Option = Some(&16).map(|b| *b); - let _: Option = Some(&1).map(|x| x.clone()); - - // Don't lint these - let v = vec![5_i8; 6]; - let a = 0; - let b = &a; - let _ = v.iter().map(|_x| *b); - let _ = v.iter().map(|_x| a.clone()); - let _ = v.iter().map(|&_x| a); - - // Issue #498 - let _ = std::env::args().map(|v| v.clone()); - - // Issue #4824 item types that aren't references - { - use std::rc::Rc; - - let o: Option> = Some(Rc::new(0_u32)); - let _: Option = o.map(|x| *x); - let v: Vec> = vec![Rc::new(0_u32)]; - let _: Vec = v.into_iter().map(|x| *x).collect(); - } - - // Issue #5524 mutable references - { - let mut c = 42; - let v = vec![&mut c]; - let _: Vec = v.into_iter().map(|x| *x).collect(); - let mut d = 21; - let v = vec![&mut d]; - let _: Vec = v.into_iter().map(|&mut x| x).collect(); - } - - // Issue #6299 - { - let mut aa = 5; - let mut bb = 3; - let items = vec![&mut aa, &mut bb]; - let _: Vec<_> = items.into_iter().map(|x| x.clone()).collect(); - } - - // Issue #6239 deref coercion and clone deref - { - use std::cell::RefCell; - - let _ = Some(RefCell::new(String::new()).borrow()).map(|s| s.clone()); - } -} diff --git a/tests/ui/map_clone.stderr b/tests/ui/map_clone.stderr deleted file mode 100644 index d84a5bf8d4de..000000000000 --- a/tests/ui/map_clone.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: you are using an explicit closure for copying elements - --> $DIR/map_clone.rs:11:22 - | -LL | let _: Vec = vec![5_i8; 6].iter().map(|x| *x).collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `vec![5_i8; 6].iter().copied()` - | - = note: `-D clippy::map-clone` implied by `-D warnings` - -error: you are using an explicit closure for cloning elements - --> $DIR/map_clone.rs:12:26 - | -LL | let _: Vec = vec![String::new()].iter().map(|x| x.clone()).collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `vec![String::new()].iter().cloned()` - -error: you are using an explicit closure for copying elements - --> $DIR/map_clone.rs:13:23 - | -LL | let _: Vec = vec![42, 43].iter().map(|&x| x).collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `vec![42, 43].iter().copied()` - -error: you are using an explicit closure for copying elements - --> $DIR/map_clone.rs:15:26 - | -LL | let _: Option = Some(&16).map(|b| *b); - | ^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `Some(&16).copied()` - -error: you are using an explicit closure for copying elements - --> $DIR/map_clone.rs:16:25 - | -LL | let _: Option = Some(&1).map(|x| x.clone()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `Some(&1).copied()` - -error: you are needlessly cloning iterator elements - --> $DIR/map_clone.rs:27:29 - | -LL | let _ = std::env::args().map(|v| v.clone()); - | ^^^^^^^^^^^^^^^^^^^ help: remove the `map` call - -error: aborting due to 6 previous errors - diff --git a/tests/ui/map_collect_result_unit.fixed b/tests/ui/map_collect_result_unit.fixed deleted file mode 100644 index e66c9cc24207..000000000000 --- a/tests/ui/map_collect_result_unit.fixed +++ /dev/null @@ -1,16 +0,0 @@ -// run-rustfix -#![warn(clippy::map_collect_result_unit)] - -fn main() { - { - let _ = (0..3).try_for_each(|t| Err(t + 1)); - let _: Result<(), _> = (0..3).try_for_each(|t| Err(t + 1)); - - let _ = (0..3).try_for_each(|t| Err(t + 1)); - } -} - -fn _ignore() { - let _ = (0..3).map(|t| Err(t + 1)).collect::, _>>(); - let _ = (0..3).map(|t| Err(t + 1)).collect::>>(); -} diff --git a/tests/ui/map_collect_result_unit.rs b/tests/ui/map_collect_result_unit.rs deleted file mode 100644 index 6f08f4c3c535..000000000000 --- a/tests/ui/map_collect_result_unit.rs +++ /dev/null @@ -1,16 +0,0 @@ -// run-rustfix -#![warn(clippy::map_collect_result_unit)] - -fn main() { - { - let _ = (0..3).map(|t| Err(t + 1)).collect::>(); - let _: Result<(), _> = (0..3).map(|t| Err(t + 1)).collect(); - - let _ = (0..3).try_for_each(|t| Err(t + 1)); - } -} - -fn _ignore() { - let _ = (0..3).map(|t| Err(t + 1)).collect::, _>>(); - let _ = (0..3).map(|t| Err(t + 1)).collect::>>(); -} diff --git a/tests/ui/map_collect_result_unit.stderr b/tests/ui/map_collect_result_unit.stderr deleted file mode 100644 index 8b06e13baa6b..000000000000 --- a/tests/ui/map_collect_result_unit.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: `.map().collect()` can be replaced with `.try_for_each()` - --> $DIR/map_collect_result_unit.rs:6:17 - | -LL | let _ = (0..3).map(|t| Err(t + 1)).collect::>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `(0..3).try_for_each(|t| Err(t + 1))` - | - = note: `-D clippy::map-collect-result-unit` implied by `-D warnings` - -error: `.map().collect()` can be replaced with `.try_for_each()` - --> $DIR/map_collect_result_unit.rs:7:32 - | -LL | let _: Result<(), _> = (0..3).map(|t| Err(t + 1)).collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `(0..3).try_for_each(|t| Err(t + 1))` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/map_err.rs b/tests/ui/map_err.rs deleted file mode 100644 index 00e037843f8c..000000000000 --- a/tests/ui/map_err.rs +++ /dev/null @@ -1,30 +0,0 @@ -#![warn(clippy::map_err_ignore)] -#![allow(clippy::unnecessary_wraps)] -use std::convert::TryFrom; -use std::error::Error; -use std::fmt; - -#[derive(Debug)] -enum Errors { - Ignored, -} - -impl Error for Errors {} - -impl fmt::Display for Errors { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "Error") - } -} - -fn main() -> Result<(), Errors> { - let x = u32::try_from(-123_i32); - - println!("{:?}", x.map_err(|_| Errors::Ignored)); - - // Should not warn you because you explicitly ignore the parameter - // using a named wildcard value - println!("{:?}", x.map_err(|_foo| Errors::Ignored)); - - Ok(()) -} diff --git a/tests/ui/map_err.stderr b/tests/ui/map_err.stderr deleted file mode 100644 index 8ee2941790d3..000000000000 --- a/tests/ui/map_err.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: `map_err(|_|...` wildcard pattern discards the original error - --> $DIR/map_err.rs:23:32 - | -LL | println!("{:?}", x.map_err(|_| Errors::Ignored)); - | ^^^ - | - = note: `-D clippy::map-err-ignore` implied by `-D warnings` - = help: Consider storing the original error as a source in the new error, or silence this warning using an ignored identifier (`.map_err(|_foo| ...`) - -error: aborting due to previous error - diff --git a/tests/ui/map_flatten.fixed b/tests/ui/map_flatten.fixed deleted file mode 100644 index 773b5914439d..000000000000 --- a/tests/ui/map_flatten.fixed +++ /dev/null @@ -1,26 +0,0 @@ -// run-rustfix - -#![warn(clippy::all, clippy::pedantic)] -#![allow(clippy::let_underscore_drop)] -#![allow(clippy::missing_docs_in_private_items)] -#![allow(clippy::map_identity)] -#![allow(clippy::unnecessary_wraps)] - -fn main() { - // mapping to Option on Iterator - fn option_id(x: i8) -> Option { - Some(x) - } - let option_id_ref: fn(i8) -> Option = option_id; - let option_id_closure = |x| Some(x); - let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id).collect(); - let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id_ref).collect(); - let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id_closure).collect(); - let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(|x| x.checked_add(1)).collect(); - - // mapping to Iterator on Iterator - let _: Vec<_> = vec![5_i8; 6].into_iter().flat_map(|x| 0..x).collect(); - - // mapping to Option on Option - let _: Option<_> = (Some(Some(1))).and_then(|x| x); -} diff --git a/tests/ui/map_flatten.rs b/tests/ui/map_flatten.rs deleted file mode 100644 index 578bd8772679..000000000000 --- a/tests/ui/map_flatten.rs +++ /dev/null @@ -1,26 +0,0 @@ -// run-rustfix - -#![warn(clippy::all, clippy::pedantic)] -#![allow(clippy::let_underscore_drop)] -#![allow(clippy::missing_docs_in_private_items)] -#![allow(clippy::map_identity)] -#![allow(clippy::unnecessary_wraps)] - -fn main() { - // mapping to Option on Iterator - fn option_id(x: i8) -> Option { - Some(x) - } - let option_id_ref: fn(i8) -> Option = option_id; - let option_id_closure = |x| Some(x); - let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().collect(); - let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_ref).flatten().collect(); - let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_closure).flatten().collect(); - let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| x.checked_add(1)).flatten().collect(); - - // mapping to Iterator on Iterator - let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect(); - - // mapping to Option on Option - let _: Option<_> = (Some(Some(1))).map(|x| x).flatten(); -} diff --git a/tests/ui/map_flatten.stderr b/tests/ui/map_flatten.stderr deleted file mode 100644 index 756e6e818ad4..000000000000 --- a/tests/ui/map_flatten.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: called `map(..).flatten()` on an `Iterator` - --> $DIR/map_flatten.rs:16:46 - | -LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `filter_map` instead: `.filter_map(option_id)` - | - = note: `-D clippy::map-flatten` implied by `-D warnings` - -error: called `map(..).flatten()` on an `Iterator` - --> $DIR/map_flatten.rs:17:46 - | -LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_ref).flatten().collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `filter_map` instead: `.filter_map(option_id_ref)` - -error: called `map(..).flatten()` on an `Iterator` - --> $DIR/map_flatten.rs:18:46 - | -LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_closure).flatten().collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `filter_map` instead: `.filter_map(option_id_closure)` - -error: called `map(..).flatten()` on an `Iterator` - --> $DIR/map_flatten.rs:19:46 - | -LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| x.checked_add(1)).flatten().collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `filter_map` instead: `.filter_map(|x| x.checked_add(1))` - -error: called `map(..).flatten()` on an `Iterator` - --> $DIR/map_flatten.rs:22:46 - | -LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `flat_map` instead: `.flat_map(|x| 0..x)` - -error: called `map(..).flatten()` on an `Option` - --> $DIR/map_flatten.rs:25:39 - | -LL | let _: Option<_> = (Some(Some(1))).map(|x| x).flatten(); - | ^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `.and_then(|x| x)` - -error: aborting due to 6 previous errors - diff --git a/tests/ui/map_identity.fixed b/tests/ui/map_identity.fixed deleted file mode 100644 index 4a1452b25f34..000000000000 --- a/tests/ui/map_identity.fixed +++ /dev/null @@ -1,23 +0,0 @@ -// run-rustfix -#![warn(clippy::map_identity)] -#![allow(clippy::needless_return)] - -fn main() { - let x: [u16; 3] = [1, 2, 3]; - // should lint - let _: Vec<_> = x.iter().map(not_identity).collect(); - let _: Vec<_> = x.iter().collect(); - let _: Option = Some(3); - let _: Result = Ok(-3); - // should not lint - let _: Vec<_> = x.iter().map(|x| 2 * x).collect(); - let _: Vec<_> = x.iter().map(not_identity).map(|x| return x - 4).collect(); - let _: Option = None.map(|x: u8| x - 1); - let _: Result = Err(2.3).map(|x: i8| { - return x + 3; - }); -} - -fn not_identity(x: &u16) -> u16 { - *x -} diff --git a/tests/ui/map_identity.rs b/tests/ui/map_identity.rs deleted file mode 100644 index 65c7e6e1ea55..000000000000 --- a/tests/ui/map_identity.rs +++ /dev/null @@ -1,25 +0,0 @@ -// run-rustfix -#![warn(clippy::map_identity)] -#![allow(clippy::needless_return)] - -fn main() { - let x: [u16; 3] = [1, 2, 3]; - // should lint - let _: Vec<_> = x.iter().map(not_identity).map(|x| return x).collect(); - let _: Vec<_> = x.iter().map(std::convert::identity).map(|y| y).collect(); - let _: Option = Some(3).map(|x| x); - let _: Result = Ok(-3).map(|x| { - return x; - }); - // should not lint - let _: Vec<_> = x.iter().map(|x| 2 * x).collect(); - let _: Vec<_> = x.iter().map(not_identity).map(|x| return x - 4).collect(); - let _: Option = None.map(|x: u8| x - 1); - let _: Result = Err(2.3).map(|x: i8| { - return x + 3; - }); -} - -fn not_identity(x: &u16) -> u16 { - *x -} diff --git a/tests/ui/map_identity.stderr b/tests/ui/map_identity.stderr deleted file mode 100644 index e4a0320cbda5..000000000000 --- a/tests/ui/map_identity.stderr +++ /dev/null @@ -1,37 +0,0 @@ -error: unnecessary map of the identity function - --> $DIR/map_identity.rs:8:47 - | -LL | let _: Vec<_> = x.iter().map(not_identity).map(|x| return x).collect(); - | ^^^^^^^^^^^^^^^^^^ help: remove the call to `map` - | - = note: `-D clippy::map-identity` implied by `-D warnings` - -error: unnecessary map of the identity function - --> $DIR/map_identity.rs:9:57 - | -LL | let _: Vec<_> = x.iter().map(std::convert::identity).map(|y| y).collect(); - | ^^^^^^^^^^^ help: remove the call to `map` - -error: unnecessary map of the identity function - --> $DIR/map_identity.rs:9:29 - | -LL | let _: Vec<_> = x.iter().map(std::convert::identity).map(|y| y).collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map` - -error: unnecessary map of the identity function - --> $DIR/map_identity.rs:10:32 - | -LL | let _: Option = Some(3).map(|x| x); - | ^^^^^^^^^^^ help: remove the call to `map` - -error: unnecessary map of the identity function - --> $DIR/map_identity.rs:11:36 - | -LL | let _: Result = Ok(-3).map(|x| { - | ____________________________________^ -LL | | return x; -LL | | }); - | |______^ help: remove the call to `map` - -error: aborting due to 5 previous errors - diff --git a/tests/ui/map_unit_fn.rs b/tests/ui/map_unit_fn.rs deleted file mode 100644 index 9a74da4e3b8b..000000000000 --- a/tests/ui/map_unit_fn.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![allow(unused)] -struct Mappable {} - -impl Mappable { - pub fn map(&self) {} -} - -fn main() { - let m = Mappable {}; - m.map(); -} diff --git a/tests/ui/map_unwrap_or.rs b/tests/ui/map_unwrap_or.rs deleted file mode 100644 index 87e16f5d09bd..000000000000 --- a/tests/ui/map_unwrap_or.rs +++ /dev/null @@ -1,81 +0,0 @@ -// aux-build:option_helpers.rs - -#![warn(clippy::map_unwrap_or)] - -#[macro_use] -extern crate option_helpers; - -use std::collections::HashMap; - -#[rustfmt::skip] -fn option_methods() { - let opt = Some(1); - - // Check for `option.map(_).unwrap_or(_)` use. - // Single line case. - let _ = opt.map(|x| x + 1) - // Should lint even though this call is on a separate line. - .unwrap_or(0); - // Multi-line cases. - let _ = opt.map(|x| { - x + 1 - } - ).unwrap_or(0); - let _ = opt.map(|x| x + 1) - .unwrap_or({ - 0 - }); - // Single line `map(f).unwrap_or(None)` case. - let _ = opt.map(|x| Some(x + 1)).unwrap_or(None); - // Multi-line `map(f).unwrap_or(None)` cases. - let _ = opt.map(|x| { - Some(x + 1) - } - ).unwrap_or(None); - let _ = opt - .map(|x| Some(x + 1)) - .unwrap_or(None); - // macro case - let _ = opt_map!(opt, |x| x + 1).unwrap_or(0); // should not lint - - // Should not lint if not copyable - let id: String = "identifier".to_string(); - let _ = Some("prefix").map(|p| format!("{}.{}", p, id)).unwrap_or(id); - // ...but DO lint if the `unwrap_or` argument is not used in the `map` - let id: String = "identifier".to_string(); - let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id); - - // Check for `option.map(_).unwrap_or_else(_)` use. - // Multi-line cases. - let _ = opt.map(|x| { - x + 1 - } - ).unwrap_or_else(|| 0); - let _ = opt.map(|x| x + 1) - .unwrap_or_else(|| - 0 - ); -} - -#[rustfmt::skip] -fn result_methods() { - let res: Result = Ok(1); - - // Check for `result.map(_).unwrap_or_else(_)` use. - // multi line cases - let _ = res.map(|x| { - x + 1 - } - ).unwrap_or_else(|_e| 0); - let _ = res.map(|x| x + 1) - .unwrap_or_else(|_e| { - 0 - }); - // macro case - let _ = opt_map!(res, |x| x + 1).unwrap_or_else(|_e| 0); // should not lint -} - -fn main() { - option_methods(); - result_methods(); -} diff --git a/tests/ui/map_unwrap_or.stderr b/tests/ui/map_unwrap_or.stderr deleted file mode 100644 index 96b9d6cc3c14..000000000000 --- a/tests/ui/map_unwrap_or.stderr +++ /dev/null @@ -1,146 +0,0 @@ -error: called `map().unwrap_or()` on an `Option` value. This can be done more directly by calling `map_or(, )` instead - --> $DIR/map_unwrap_or.rs:16:13 - | -LL | let _ = opt.map(|x| x + 1) - | _____________^ -LL | | // Should lint even though this call is on a separate line. -LL | | .unwrap_or(0); - | |_____________________^ - | - = note: `-D clippy::map-unwrap-or` implied by `-D warnings` -help: use `map_or(, )` instead - | -LL | let _ = opt.map_or(0, |x| x + 1); - | ^^^^^^ ^^ -- - -error: called `map().unwrap_or()` on an `Option` value. This can be done more directly by calling `map_or(, )` instead - --> $DIR/map_unwrap_or.rs:20:13 - | -LL | let _ = opt.map(|x| { - | _____________^ -LL | | x + 1 -LL | | } -LL | | ).unwrap_or(0); - | |__________________^ - | -help: use `map_or(, )` instead - | -LL | let _ = opt.map_or(0, |x| { -LL | x + 1 -LL | } -LL | ); - | - -error: called `map().unwrap_or()` on an `Option` value. This can be done more directly by calling `map_or(, )` instead - --> $DIR/map_unwrap_or.rs:24:13 - | -LL | let _ = opt.map(|x| x + 1) - | _____________^ -LL | | .unwrap_or({ -LL | | 0 -LL | | }); - | |__________^ - | -help: use `map_or(, )` instead - | -LL | let _ = opt.map_or({ -LL | 0 -LL | }, |x| x + 1); - | - -error: called `map().unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then()` instead - --> $DIR/map_unwrap_or.rs:29:13 - | -LL | let _ = opt.map(|x| Some(x + 1)).unwrap_or(None); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: use `and_then()` instead - | -LL | let _ = opt.and_then(|x| Some(x + 1)); - | ^^^^^^^^ -- - -error: called `map().unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then()` instead - --> $DIR/map_unwrap_or.rs:31:13 - | -LL | let _ = opt.map(|x| { - | _____________^ -LL | | Some(x + 1) -LL | | } -LL | | ).unwrap_or(None); - | |_____________________^ - | -help: use `and_then()` instead - | -LL | let _ = opt.and_then(|x| { -LL | Some(x + 1) -LL | } -LL | ); - | - -error: called `map().unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then()` instead - --> $DIR/map_unwrap_or.rs:35:13 - | -LL | let _ = opt - | _____________^ -LL | | .map(|x| Some(x + 1)) -LL | | .unwrap_or(None); - | |________________________^ - | -help: use `and_then()` instead - | -LL | .and_then(|x| Some(x + 1)); - | ^^^^^^^^ -- - -error: called `map().unwrap_or()` on an `Option` value. This can be done more directly by calling `map_or(, )` instead - --> $DIR/map_unwrap_or.rs:46:13 - | -LL | let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: use `map_or(, )` instead - | -LL | let _ = Some("prefix").map_or(id, |p| format!("{}.", p)); - | ^^^^^^ ^^^ -- - -error: called `map().unwrap_or_else()` on an `Option` value. This can be done more directly by calling `map_or_else(, )` instead - --> $DIR/map_unwrap_or.rs:50:13 - | -LL | let _ = opt.map(|x| { - | _____________^ -LL | | x + 1 -LL | | } -LL | | ).unwrap_or_else(|| 0); - | |__________________________^ - -error: called `map().unwrap_or_else()` on an `Option` value. This can be done more directly by calling `map_or_else(, )` instead - --> $DIR/map_unwrap_or.rs:54:13 - | -LL | let _ = opt.map(|x| x + 1) - | _____________^ -LL | | .unwrap_or_else(|| -LL | | 0 -LL | | ); - | |_________^ - -error: called `map().unwrap_or_else()` on a `Result` value. This can be done more directly by calling `.map_or_else(, )` instead - --> $DIR/map_unwrap_or.rs:66:13 - | -LL | let _ = res.map(|x| { - | _____________^ -LL | | x + 1 -LL | | } -LL | | ).unwrap_or_else(|_e| 0); - | |____________________________^ - -error: called `map().unwrap_or_else()` on a `Result` value. This can be done more directly by calling `.map_or_else(, )` instead - --> $DIR/map_unwrap_or.rs:70:13 - | -LL | let _ = res.map(|x| x + 1) - | _____________^ -LL | | .unwrap_or_else(|_e| { -LL | | 0 -LL | | }); - | |__________^ - -error: aborting due to 11 previous errors - diff --git a/tests/ui/map_unwrap_or_fixable.fixed b/tests/ui/map_unwrap_or_fixable.fixed deleted file mode 100644 index bd5b4f7165a4..000000000000 --- a/tests/ui/map_unwrap_or_fixable.fixed +++ /dev/null @@ -1,54 +0,0 @@ -// run-rustfix -// aux-build:option_helpers.rs - -#![warn(clippy::map_unwrap_or)] - -#[macro_use] -extern crate option_helpers; - -use std::collections::HashMap; - -#[rustfmt::skip] -fn option_methods() { - let opt = Some(1); - - // Check for `option.map(_).unwrap_or_else(_)` use. - // single line case - let _ = opt.map_or_else(|| 0, |x| x + 1); - - // Macro case. - // Should not lint. - let _ = opt_map!(opt, |x| x + 1).unwrap_or_else(|| 0); - - // Issue #4144 - { - let mut frequencies = HashMap::new(); - let word = "foo"; - - frequencies - .get_mut(word) - .map(|count| { - *count += 1; - }) - .unwrap_or_else(|| { - frequencies.insert(word.to_owned(), 1); - }); - } -} - -#[rustfmt::skip] -fn result_methods() { - let res: Result = Ok(1); - - // Check for `result.map(_).unwrap_or_else(_)` use. - // single line case - let _ = res.map_or_else(|_e| 0, |x| x + 1); - - // macro case - let _ = opt_map!(res, |x| x + 1).unwrap_or_else(|_e| 0); // should not lint -} - -fn main() { - option_methods(); - result_methods(); -} diff --git a/tests/ui/map_unwrap_or_fixable.rs b/tests/ui/map_unwrap_or_fixable.rs deleted file mode 100644 index 0b892caf20e8..000000000000 --- a/tests/ui/map_unwrap_or_fixable.rs +++ /dev/null @@ -1,58 +0,0 @@ -// run-rustfix -// aux-build:option_helpers.rs - -#![warn(clippy::map_unwrap_or)] - -#[macro_use] -extern crate option_helpers; - -use std::collections::HashMap; - -#[rustfmt::skip] -fn option_methods() { - let opt = Some(1); - - // Check for `option.map(_).unwrap_or_else(_)` use. - // single line case - let _ = opt.map(|x| x + 1) - // Should lint even though this call is on a separate line. - .unwrap_or_else(|| 0); - - // Macro case. - // Should not lint. - let _ = opt_map!(opt, |x| x + 1).unwrap_or_else(|| 0); - - // Issue #4144 - { - let mut frequencies = HashMap::new(); - let word = "foo"; - - frequencies - .get_mut(word) - .map(|count| { - *count += 1; - }) - .unwrap_or_else(|| { - frequencies.insert(word.to_owned(), 1); - }); - } -} - -#[rustfmt::skip] -fn result_methods() { - let res: Result = Ok(1); - - // Check for `result.map(_).unwrap_or_else(_)` use. - // single line case - let _ = res.map(|x| x + 1) - // should lint even though this call is on a separate line - .unwrap_or_else(|_e| 0); - - // macro case - let _ = opt_map!(res, |x| x + 1).unwrap_or_else(|_e| 0); // should not lint -} - -fn main() { - option_methods(); - result_methods(); -} diff --git a/tests/ui/map_unwrap_or_fixable.stderr b/tests/ui/map_unwrap_or_fixable.stderr deleted file mode 100644 index 1837bc2ca3b8..000000000000 --- a/tests/ui/map_unwrap_or_fixable.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: called `map().unwrap_or_else()` on an `Option` value. This can be done more directly by calling `map_or_else(, )` instead - --> $DIR/map_unwrap_or_fixable.rs:17:13 - | -LL | let _ = opt.map(|x| x + 1) - | _____________^ -LL | | // Should lint even though this call is on a separate line. -LL | | .unwrap_or_else(|| 0); - | |_____________________________^ help: try this: `opt.map_or_else(|| 0, |x| x + 1)` - | - = note: `-D clippy::map-unwrap-or` implied by `-D warnings` - -error: called `map().unwrap_or_else()` on a `Result` value. This can be done more directly by calling `.map_or_else(, )` instead - --> $DIR/map_unwrap_or_fixable.rs:47:13 - | -LL | let _ = res.map(|x| x + 1) - | _____________^ -LL | | // should lint even though this call is on a separate line -LL | | .unwrap_or_else(|_e| 0); - | |_______________________________^ help: try this: `res.map_or_else(|_e| 0, |x| x + 1)` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/match_as_ref.fixed b/tests/ui/match_as_ref.fixed deleted file mode 100644 index c61eb9216643..000000000000 --- a/tests/ui/match_as_ref.fixed +++ /dev/null @@ -1,35 +0,0 @@ -// run-rustfix - -#![allow(unused)] -#![warn(clippy::match_as_ref)] - -fn match_as_ref() { - let owned: Option<()> = None; - let borrowed: Option<&()> = owned.as_ref(); - - let mut mut_owned: Option<()> = None; - let borrow_mut: Option<&mut ()> = mut_owned.as_mut(); -} - -mod issue4437 { - use std::{error::Error, fmt, num::ParseIntError}; - - #[derive(Debug)] - struct E { - source: Option, - } - - impl Error for E { - fn source(&self) -> Option<&(dyn Error + 'static)> { - self.source.as_ref().map(|x| x as _) - } - } - - impl fmt::Display for E { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - unimplemented!() - } - } -} - -fn main() {} diff --git a/tests/ui/match_as_ref.rs b/tests/ui/match_as_ref.rs deleted file mode 100644 index 2fbd0b255faa..000000000000 --- a/tests/ui/match_as_ref.rs +++ /dev/null @@ -1,44 +0,0 @@ -// run-rustfix - -#![allow(unused)] -#![warn(clippy::match_as_ref)] - -fn match_as_ref() { - let owned: Option<()> = None; - let borrowed: Option<&()> = match owned { - None => None, - Some(ref v) => Some(v), - }; - - let mut mut_owned: Option<()> = None; - let borrow_mut: Option<&mut ()> = match mut_owned { - None => None, - Some(ref mut v) => Some(v), - }; -} - -mod issue4437 { - use std::{error::Error, fmt, num::ParseIntError}; - - #[derive(Debug)] - struct E { - source: Option, - } - - impl Error for E { - fn source(&self) -> Option<&(dyn Error + 'static)> { - match self.source { - Some(ref s) => Some(s), - None => None, - } - } - } - - impl fmt::Display for E { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - unimplemented!() - } - } -} - -fn main() {} diff --git a/tests/ui/match_as_ref.stderr b/tests/ui/match_as_ref.stderr deleted file mode 100644 index c3b62849cb33..000000000000 --- a/tests/ui/match_as_ref.stderr +++ /dev/null @@ -1,33 +0,0 @@ -error: use `as_ref()` instead - --> $DIR/match_as_ref.rs:8:33 - | -LL | let borrowed: Option<&()> = match owned { - | _________________________________^ -LL | | None => None, -LL | | Some(ref v) => Some(v), -LL | | }; - | |_____^ help: try this: `owned.as_ref()` - | - = note: `-D clippy::match-as-ref` implied by `-D warnings` - -error: use `as_mut()` instead - --> $DIR/match_as_ref.rs:14:39 - | -LL | let borrow_mut: Option<&mut ()> = match mut_owned { - | _______________________________________^ -LL | | None => None, -LL | | Some(ref mut v) => Some(v), -LL | | }; - | |_____^ help: try this: `mut_owned.as_mut()` - -error: use `as_ref()` instead - --> $DIR/match_as_ref.rs:30:13 - | -LL | / match self.source { -LL | | Some(ref s) => Some(s), -LL | | None => None, -LL | | } - | |_____________^ help: try this: `self.source.as_ref().map(|x| x as _)` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/match_bool.rs b/tests/ui/match_bool.rs deleted file mode 100644 index 9ed55ca7ae7f..000000000000 --- a/tests/ui/match_bool.rs +++ /dev/null @@ -1,55 +0,0 @@ -#![deny(clippy::match_bool)] - -fn match_bool() { - let test: bool = true; - - match test { - true => 0, - false => 42, - }; - - let option = 1; - match option == 1 { - true => 1, - false => 0, - }; - - match test { - true => (), - false => { - println!("Noooo!"); - }, - }; - - match test { - false => { - println!("Noooo!"); - }, - _ => (), - }; - - match test && test { - false => { - println!("Noooo!"); - }, - _ => (), - }; - - match test { - false => { - println!("Noooo!"); - }, - true => { - println!("Yes!"); - }, - }; - - // Not linted - match option { - 1..=10 => 1, - 11..=20 => 2, - _ => 3, - }; -} - -fn main() {} diff --git a/tests/ui/match_bool.stderr b/tests/ui/match_bool.stderr deleted file mode 100644 index 1ad78c740c68..000000000000 --- a/tests/ui/match_bool.stderr +++ /dev/null @@ -1,117 +0,0 @@ -error: this boolean expression can be simplified - --> $DIR/match_bool.rs:31:11 - | -LL | match test && test { - | ^^^^^^^^^^^^ help: try: `test` - | - = note: `-D clippy::nonminimal-bool` implied by `-D warnings` - -error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:6:5 - | -LL | / match test { -LL | | true => 0, -LL | | false => 42, -LL | | }; - | |_____^ help: consider using an `if`/`else` expression: `if test { 0 } else { 42 }` - | -note: the lint level is defined here - --> $DIR/match_bool.rs:1:9 - | -LL | #![deny(clippy::match_bool)] - | ^^^^^^^^^^^^^^^^^^ - -error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:12:5 - | -LL | / match option == 1 { -LL | | true => 1, -LL | | false => 0, -LL | | }; - | |_____^ help: consider using an `if`/`else` expression: `if option == 1 { 1 } else { 0 }` - -error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:17:5 - | -LL | / match test { -LL | | true => (), -LL | | false => { -LL | | println!("Noooo!"); -LL | | }, -LL | | }; - | |_____^ - | -help: consider using an `if`/`else` expression - | -LL | if !test { -LL | println!("Noooo!"); -LL | }; - | - -error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:24:5 - | -LL | / match test { -LL | | false => { -LL | | println!("Noooo!"); -LL | | }, -LL | | _ => (), -LL | | }; - | |_____^ - | -help: consider using an `if`/`else` expression - | -LL | if !test { -LL | println!("Noooo!"); -LL | }; - | - -error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:31:5 - | -LL | / match test && test { -LL | | false => { -LL | | println!("Noooo!"); -LL | | }, -LL | | _ => (), -LL | | }; - | |_____^ - | -help: consider using an `if`/`else` expression - | -LL | if !(test && test) { -LL | println!("Noooo!"); -LL | }; - | - -error: equal expressions as operands to `&&` - --> $DIR/match_bool.rs:31:11 - | -LL | match test && test { - | ^^^^^^^^^^^^ - | - = note: `#[deny(clippy::eq_op)]` on by default - -error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:38:5 - | -LL | / match test { -LL | | false => { -LL | | println!("Noooo!"); -LL | | }, -... | -LL | | }, -LL | | }; - | |_____^ - | -help: consider using an `if`/`else` expression - | -LL | if test { -LL | println!("Yes!"); -LL | } else { -LL | println!("Noooo!"); -LL | }; - | - -error: aborting due to 8 previous errors - diff --git a/tests/ui/match_expr_like_matches_macro.fixed b/tests/ui/match_expr_like_matches_macro.fixed deleted file mode 100644 index 7f4ebf566733..000000000000 --- a/tests/ui/match_expr_like_matches_macro.fixed +++ /dev/null @@ -1,102 +0,0 @@ -// run-rustfix - -#![warn(clippy::match_like_matches_macro)] -#![allow(unreachable_patterns, dead_code)] - -fn main() { - let x = Some(5); - - // Lint - let _y = matches!(x, Some(0)); - - // Lint - let _w = matches!(x, Some(_)); - - // Turn into is_none - let _z = x.is_none(); - - // Lint - let _zz = !matches!(x, Some(r) if r == 0); - - // Lint - let _zzz = matches!(x, Some(5)); - - // No lint - let _a = match x { - Some(_) => false, - _ => false, - }; - - // No lint - let _ab = match x { - Some(0) => false, - _ => true, - None => false, - }; - - enum E { - A(u32), - B(i32), - C, - D, - }; - let x = E::A(2); - { - // lint - let _ans = matches!(x, E::A(_) | E::B(_)); - } - { - // lint - let _ans = !matches!(x, E::B(_) | E::C); - } - { - // no lint - let _ans = match x { - E::A(_) => false, - E::B(_) => false, - E::C => true, - _ => true, - }; - } - { - // no lint - let _ans = match x { - E::A(_) => true, - E::B(_) => false, - E::C => false, - _ => true, - }; - } - { - // no lint - let _ans = match x { - E::A(a) if a < 10 => false, - E::B(a) if a < 10 => false, - _ => true, - }; - } - { - // no lint - let _ans = match x { - E::A(_) => false, - E::B(a) if a < 10 => false, - _ => true, - }; - } - { - // no lint - let _ans = match x { - E::A(a) => a == 10, - E::B(_) => false, - _ => true, - }; - } - { - // no lint - let _ans = match x { - E::A(_) => false, - E::B(_) => true, - _ => false, - }; - } -} diff --git a/tests/ui/match_expr_like_matches_macro.rs b/tests/ui/match_expr_like_matches_macro.rs deleted file mode 100644 index aee56dd4a5ef..000000000000 --- a/tests/ui/match_expr_like_matches_macro.rs +++ /dev/null @@ -1,122 +0,0 @@ -// run-rustfix - -#![warn(clippy::match_like_matches_macro)] -#![allow(unreachable_patterns, dead_code)] - -fn main() { - let x = Some(5); - - // Lint - let _y = match x { - Some(0) => true, - _ => false, - }; - - // Lint - let _w = match x { - Some(_) => true, - _ => false, - }; - - // Turn into is_none - let _z = match x { - Some(_) => false, - None => true, - }; - - // Lint - let _zz = match x { - Some(r) if r == 0 => false, - _ => true, - }; - - // Lint - let _zzz = if let Some(5) = x { true } else { false }; - - // No lint - let _a = match x { - Some(_) => false, - _ => false, - }; - - // No lint - let _ab = match x { - Some(0) => false, - _ => true, - None => false, - }; - - enum E { - A(u32), - B(i32), - C, - D, - }; - let x = E::A(2); - { - // lint - let _ans = match x { - E::A(_) => true, - E::B(_) => true, - _ => false, - }; - } - { - // lint - let _ans = match x { - E::B(_) => false, - E::C => false, - _ => true, - }; - } - { - // no lint - let _ans = match x { - E::A(_) => false, - E::B(_) => false, - E::C => true, - _ => true, - }; - } - { - // no lint - let _ans = match x { - E::A(_) => true, - E::B(_) => false, - E::C => false, - _ => true, - }; - } - { - // no lint - let _ans = match x { - E::A(a) if a < 10 => false, - E::B(a) if a < 10 => false, - _ => true, - }; - } - { - // no lint - let _ans = match x { - E::A(_) => false, - E::B(a) if a < 10 => false, - _ => true, - }; - } - { - // no lint - let _ans = match x { - E::A(a) => a == 10, - E::B(_) => false, - _ => true, - }; - } - { - // no lint - let _ans = match x { - E::A(_) => false, - E::B(_) => true, - _ => false, - }; - } -} diff --git a/tests/ui/match_expr_like_matches_macro.stderr b/tests/ui/match_expr_like_matches_macro.stderr deleted file mode 100644 index c52e41c78894..000000000000 --- a/tests/ui/match_expr_like_matches_macro.stderr +++ /dev/null @@ -1,74 +0,0 @@ -error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:10:14 - | -LL | let _y = match x { - | ______________^ -LL | | Some(0) => true, -LL | | _ => false, -LL | | }; - | |_____^ help: try this: `matches!(x, Some(0))` - | - = note: `-D clippy::match-like-matches-macro` implied by `-D warnings` - -error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:16:14 - | -LL | let _w = match x { - | ______________^ -LL | | Some(_) => true, -LL | | _ => false, -LL | | }; - | |_____^ help: try this: `matches!(x, Some(_))` - -error: redundant pattern matching, consider using `is_none()` - --> $DIR/match_expr_like_matches_macro.rs:22:14 - | -LL | let _z = match x { - | ______________^ -LL | | Some(_) => false, -LL | | None => true, -LL | | }; - | |_____^ help: try this: `x.is_none()` - | - = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` - -error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:28:15 - | -LL | let _zz = match x { - | _______________^ -LL | | Some(r) if r == 0 => false, -LL | | _ => true, -LL | | }; - | |_____^ help: try this: `!matches!(x, Some(r) if r == 0)` - -error: if let .. else expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:34:16 - | -LL | let _zzz = if let Some(5) = x { true } else { false }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `matches!(x, Some(5))` - -error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:58:20 - | -LL | let _ans = match x { - | ____________________^ -LL | | E::A(_) => true, -LL | | E::B(_) => true, -LL | | _ => false, -LL | | }; - | |_________^ help: try this: `matches!(x, E::A(_) | E::B(_))` - -error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:66:20 - | -LL | let _ans = match x { - | ____________________^ -LL | | E::B(_) => false, -LL | | E::C => false, -LL | | _ => true, -LL | | }; - | |_________^ help: try this: `!matches!(x, E::B(_) | E::C)` - -error: aborting due to 7 previous errors - diff --git a/tests/ui/match_on_vec_items.rs b/tests/ui/match_on_vec_items.rs deleted file mode 100644 index 30415e3b94dc..000000000000 --- a/tests/ui/match_on_vec_items.rs +++ /dev/null @@ -1,152 +0,0 @@ -#![warn(clippy::match_on_vec_items)] - -fn match_with_wildcard() { - let arr = vec![0, 1, 2, 3]; - let range = 1..3; - let idx = 1; - - // Lint, may panic - match arr[idx] { - 0 => println!("0"), - 1 => println!("1"), - _ => {}, - } - - // Lint, may panic - match arr[range] { - [0, 1] => println!("0 1"), - [1, 2] => println!("1 2"), - _ => {}, - } -} - -fn match_without_wildcard() { - let arr = vec![0, 1, 2, 3]; - let range = 1..3; - let idx = 2; - - // Lint, may panic - match arr[idx] { - 0 => println!("0"), - 1 => println!("1"), - num => {}, - } - - // Lint, may panic - match arr[range] { - [0, 1] => println!("0 1"), - [1, 2] => println!("1 2"), - [ref sub @ ..] => {}, - } -} - -fn match_wildcard_and_action() { - let arr = vec![0, 1, 2, 3]; - let range = 1..3; - let idx = 3; - - // Lint, may panic - match arr[idx] { - 0 => println!("0"), - 1 => println!("1"), - _ => println!("Hello, World!"), - } - - // Lint, may panic - match arr[range] { - [0, 1] => println!("0 1"), - [1, 2] => println!("1 2"), - _ => println!("Hello, World!"), - } -} - -fn match_vec_ref() { - let arr = &vec![0, 1, 2, 3]; - let range = 1..3; - let idx = 3; - - // Lint, may panic - match arr[idx] { - 0 => println!("0"), - 1 => println!("1"), - _ => {}, - } - - // Lint, may panic - match arr[range] { - [0, 1] => println!("0 1"), - [1, 2] => println!("1 2"), - _ => {}, - } -} - -fn match_with_get() { - let arr = vec![0, 1, 2, 3]; - let range = 1..3; - let idx = 3; - - // Ok - match arr.get(idx) { - Some(0) => println!("0"), - Some(1) => println!("1"), - _ => {}, - } - - // Ok - match arr.get(range) { - Some(&[0, 1]) => println!("0 1"), - Some(&[1, 2]) => println!("1 2"), - _ => {}, - } -} - -fn match_with_array() { - let arr = [0, 1, 2, 3]; - let range = 1..3; - let idx = 3; - - // Ok - match arr[idx] { - 0 => println!("0"), - 1 => println!("1"), - _ => {}, - } - - // Ok - match arr[range] { - [0, 1] => println!("0 1"), - [1, 2] => println!("1 2"), - _ => {}, - } -} - -fn match_with_endless_range() { - let arr = vec![0, 1, 2, 3]; - let range = ..; - - // Ok - match arr[range] { - [0, 1] => println!("0 1"), - [1, 2] => println!("1 2"), - [0, 1, 2, 3] => println!("0, 1, 2, 3"), - _ => {}, - } - - // Ok - match arr[..] { - [0, 1] => println!("0 1"), - [1, 2] => println!("1 2"), - [0, 1, 2, 3] => println!("0, 1, 2, 3"), - _ => {}, - } -} - -fn main() { - match_with_wildcard(); - match_without_wildcard(); - match_wildcard_and_action(); - match_vec_ref(); - match_with_get(); - match_with_array(); - match_with_endless_range(); -} diff --git a/tests/ui/match_on_vec_items.stderr b/tests/ui/match_on_vec_items.stderr deleted file mode 100644 index 49446d715abe..000000000000 --- a/tests/ui/match_on_vec_items.stderr +++ /dev/null @@ -1,52 +0,0 @@ -error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:9:11 - | -LL | match arr[idx] { - | ^^^^^^^^ help: try this: `arr.get(idx)` - | - = note: `-D clippy::match-on-vec-items` implied by `-D warnings` - -error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:16:11 - | -LL | match arr[range] { - | ^^^^^^^^^^ help: try this: `arr.get(range)` - -error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:29:11 - | -LL | match arr[idx] { - | ^^^^^^^^ help: try this: `arr.get(idx)` - -error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:36:11 - | -LL | match arr[range] { - | ^^^^^^^^^^ help: try this: `arr.get(range)` - -error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:49:11 - | -LL | match arr[idx] { - | ^^^^^^^^ help: try this: `arr.get(idx)` - -error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:56:11 - | -LL | match arr[range] { - | ^^^^^^^^^^ help: try this: `arr.get(range)` - -error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:69:11 - | -LL | match arr[idx] { - | ^^^^^^^^ help: try this: `arr.get(idx)` - -error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:76:11 - | -LL | match arr[range] { - | ^^^^^^^^^^ help: try this: `arr.get(range)` - -error: aborting due to 8 previous errors - diff --git a/tests/ui/match_overlapping_arm.rs b/tests/ui/match_overlapping_arm.rs deleted file mode 100644 index 97789bb766f8..000000000000 --- a/tests/ui/match_overlapping_arm.rs +++ /dev/null @@ -1,82 +0,0 @@ -#![feature(exclusive_range_pattern)] -#![feature(half_open_range_patterns)] -#![warn(clippy::match_overlapping_arm)] -#![allow(clippy::redundant_pattern_matching)] - -/// Tests for match_overlapping_arm - -fn overlapping() { - const FOO: u64 = 2; - - match 42 { - 0..=10 => println!("0 ... 10"), - 0..=11 => println!("0 ... 11"), - _ => (), - } - - match 42 { - 0..=5 => println!("0 ... 5"), - 6..=7 => println!("6 ... 7"), - FOO..=11 => println!("0 ... 11"), - _ => (), - } - - match 42 { - 2 => println!("2"), - 0..=5 => println!("0 ... 5"), - _ => (), - } - - match 42 { - 2 => println!("2"), - 0..=2 => println!("0 ... 2"), - _ => (), - } - - match 42 { - 0..=10 => println!("0 ... 10"), - 11..=50 => println!("11 ... 50"), - _ => (), - } - - match 42 { - 2 => println!("2"), - 0..2 => println!("0 .. 2"), - _ => (), - } - - match 42 { - 0..10 => println!("0 .. 10"), - 10..50 => println!("10 .. 50"), - _ => (), - } - - match 42 { - 0..11 => println!("0 .. 11"), - 0..=11 => println!("0 ... 11"), - _ => (), - } - - /* - // FIXME(JohnTitor): uncomment this once rustfmt knows half-open patterns - match 42 { - 0.. => println!("0 .. 42"), - 3.. => println!("3 .. 42"), - _ => (), - } - - match 42 { - ..=23 => println!("0 ... 23"), - ..26 => println!("0 .. 26"), - _ => (), - } - */ - - if let None = Some(42) { - // nothing - } else if let None = Some(42) { - // another nothing :-) - } -} - -fn main() {} diff --git a/tests/ui/match_overlapping_arm.stderr b/tests/ui/match_overlapping_arm.stderr deleted file mode 100644 index eb20d5405a95..000000000000 --- a/tests/ui/match_overlapping_arm.stderr +++ /dev/null @@ -1,63 +0,0 @@ -error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:12:9 - | -LL | 0..=10 => println!("0 ... 10"), - | ^^^^^^ - | - = note: `-D clippy::match-overlapping-arm` implied by `-D warnings` -note: overlaps with this - --> $DIR/match_overlapping_arm.rs:13:9 - | -LL | 0..=11 => println!("0 ... 11"), - | ^^^^^^ - -error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:18:9 - | -LL | 0..=5 => println!("0 ... 5"), - | ^^^^^ - | -note: overlaps with this - --> $DIR/match_overlapping_arm.rs:20:9 - | -LL | FOO..=11 => println!("0 ... 11"), - | ^^^^^^^^ - -error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:26:9 - | -LL | 0..=5 => println!("0 ... 5"), - | ^^^^^ - | -note: overlaps with this - --> $DIR/match_overlapping_arm.rs:25:9 - | -LL | 2 => println!("2"), - | ^ - -error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:32:9 - | -LL | 0..=2 => println!("0 ... 2"), - | ^^^^^ - | -note: overlaps with this - --> $DIR/match_overlapping_arm.rs:31:9 - | -LL | 2 => println!("2"), - | ^ - -error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:55:9 - | -LL | 0..11 => println!("0 .. 11"), - | ^^^^^ - | -note: overlaps with this - --> $DIR/match_overlapping_arm.rs:56:9 - | -LL | 0..=11 => println!("0 ... 11"), - | ^^^^^^ - -error: aborting due to 5 previous errors - diff --git a/tests/ui/match_ref_pats.rs b/tests/ui/match_ref_pats.rs deleted file mode 100644 index 5de43733ad33..000000000000 --- a/tests/ui/match_ref_pats.rs +++ /dev/null @@ -1,74 +0,0 @@ -#![warn(clippy::match_ref_pats)] - -fn ref_pats() { - { - let v = &Some(0); - match v { - &Some(v) => println!("{:?}", v), - &None => println!("none"), - } - match v { - // This doesn't trigger; we have a different pattern. - &Some(v) => println!("some"), - other => println!("other"), - } - } - let tup = &(1, 2); - match tup { - &(v, 1) => println!("{}", v), - _ => println!("none"), - } - // Special case: using `&` both in expr and pats. - let w = Some(0); - match &w { - &Some(v) => println!("{:?}", v), - &None => println!("none"), - } - // False positive: only wildcard pattern. - let w = Some(0); - #[allow(clippy::match_single_binding)] - match w { - _ => println!("none"), - } - - let a = &Some(0); - if let &None = a { - println!("none"); - } - - let b = Some(0); - if let &None = &b { - println!("none"); - } -} - -mod ice_3719 { - macro_rules! foo_variant( - ($idx:expr) => (Foo::get($idx).unwrap()) - ); - - enum Foo { - A, - B, - } - - impl Foo { - fn get(idx: u8) -> Option<&'static Self> { - match idx { - 0 => Some(&Foo::A), - 1 => Some(&Foo::B), - _ => None, - } - } - } - - fn ice_3719() { - // ICE #3719 - match foo_variant!(0) { - &Foo::A => println!("A"), - _ => println!("Wild"), - } - } -} - -fn main() {} diff --git a/tests/ui/match_ref_pats.stderr b/tests/ui/match_ref_pats.stderr deleted file mode 100644 index 52cb4a14b72b..000000000000 --- a/tests/ui/match_ref_pats.stderr +++ /dev/null @@ -1,91 +0,0 @@ -error: you don't need to add `&` to all patterns - --> $DIR/match_ref_pats.rs:6:9 - | -LL | / match v { -LL | | &Some(v) => println!("{:?}", v), -LL | | &None => println!("none"), -LL | | } - | |_________^ - | - = note: `-D clippy::match-ref-pats` implied by `-D warnings` -help: instead of prefixing all patterns with `&`, you can dereference the expression - | -LL | match *v { -LL | Some(v) => println!("{:?}", v), -LL | None => println!("none"), - | - -error: you don't need to add `&` to all patterns - --> $DIR/match_ref_pats.rs:17:5 - | -LL | / match tup { -LL | | &(v, 1) => println!("{}", v), -LL | | _ => println!("none"), -LL | | } - | |_____^ - | -help: instead of prefixing all patterns with `&`, you can dereference the expression - | -LL | match *tup { -LL | (v, 1) => println!("{}", v), - | - -error: you don't need to add `&` to both the expression and the patterns - --> $DIR/match_ref_pats.rs:23:5 - | -LL | / match &w { -LL | | &Some(v) => println!("{:?}", v), -LL | | &None => println!("none"), -LL | | } - | |_____^ - | -help: try - | -LL | match w { -LL | Some(v) => println!("{:?}", v), -LL | None => println!("none"), - | - -error: you don't need to add `&` to all patterns - --> $DIR/match_ref_pats.rs:35:5 - | -LL | / if let &None = a { -LL | | println!("none"); -LL | | } - | |_____^ - | -help: instead of prefixing all patterns with `&`, you can dereference the expression - | -LL | if let None = *a { - | ^^^^ ^^ - -error: you don't need to add `&` to both the expression and the patterns - --> $DIR/match_ref_pats.rs:40:5 - | -LL | / if let &None = &b { -LL | | println!("none"); -LL | | } - | |_____^ - | -help: try - | -LL | if let None = b { - | ^^^^ ^ - -error: you don't need to add `&` to all patterns - --> $DIR/match_ref_pats.rs:67:9 - | -LL | / match foo_variant!(0) { -LL | | &Foo::A => println!("A"), -LL | | _ => println!("Wild"), -LL | | } - | |_________^ - | -help: instead of prefixing all patterns with `&`, you can dereference the expression - | -LL | match *foo_variant!(0) { -LL | Foo::A => println!("A"), - | - -error: aborting due to 6 previous errors - diff --git a/tests/ui/match_same_arms.rs b/tests/ui/match_same_arms.rs deleted file mode 100644 index 0b9342c9c423..000000000000 --- a/tests/ui/match_same_arms.rs +++ /dev/null @@ -1,56 +0,0 @@ -#![warn(clippy::match_same_arms)] - -pub enum Abc { - A, - B, - C, -} - -fn match_same_arms() { - let _ = match Abc::A { - Abc::A => 0, - Abc::B => 1, - _ => 0, //~ ERROR match arms have same body - }; - - match (1, 2, 3) { - (1, .., 3) => 42, - (.., 3) => 42, //~ ERROR match arms have same body - _ => 0, - }; - - let _ = match 42 { - 42 => 1, - 51 => 1, //~ ERROR match arms have same body - 41 => 2, - 52 => 2, //~ ERROR match arms have same body - _ => 0, - }; - - let _ = match 42 { - 1 => 2, - 2 => 2, //~ ERROR 2nd matched arms have same body - 3 => 2, //~ ERROR 3rd matched arms have same body - 4 => 3, - _ => 0, - }; -} - -mod issue4244 { - #[derive(PartialEq, PartialOrd, Eq, Ord)] - pub enum CommandInfo { - BuiltIn { name: String, about: Option }, - External { name: String, path: std::path::PathBuf }, - } - - impl CommandInfo { - pub fn name(&self) -> String { - match self { - CommandInfo::BuiltIn { name, .. } => name.to_string(), - CommandInfo::External { name, .. } => name.to_string(), - } - } - } -} - -fn main() {} diff --git a/tests/ui/match_same_arms.stderr b/tests/ui/match_same_arms.stderr deleted file mode 100644 index 0549886a1e8e..000000000000 --- a/tests/ui/match_same_arms.stderr +++ /dev/null @@ -1,139 +0,0 @@ -error: this `match` has identical arm bodies - --> $DIR/match_same_arms.rs:13:14 - | -LL | _ => 0, //~ ERROR match arms have same body - | ^ - | - = note: `-D clippy::match-same-arms` implied by `-D warnings` -note: same as this - --> $DIR/match_same_arms.rs:11:19 - | -LL | Abc::A => 0, - | ^ -note: `Abc::A` has the same arm body as the `_` wildcard, consider removing it - --> $DIR/match_same_arms.rs:11:19 - | -LL | Abc::A => 0, - | ^ - -error: this `match` has identical arm bodies - --> $DIR/match_same_arms.rs:18:20 - | -LL | (.., 3) => 42, //~ ERROR match arms have same body - | ^^ - | -note: same as this - --> $DIR/match_same_arms.rs:17:23 - | -LL | (1, .., 3) => 42, - | ^^ -help: consider refactoring into `(1, .., 3) | (.., 3)` - --> $DIR/match_same_arms.rs:17:9 - | -LL | (1, .., 3) => 42, - | ^^^^^^^^^^ - -error: this `match` has identical arm bodies - --> $DIR/match_same_arms.rs:24:15 - | -LL | 51 => 1, //~ ERROR match arms have same body - | ^ - | -note: same as this - --> $DIR/match_same_arms.rs:23:15 - | -LL | 42 => 1, - | ^ -help: consider refactoring into `42 | 51` - --> $DIR/match_same_arms.rs:23:9 - | -LL | 42 => 1, - | ^^ - -error: this `match` has identical arm bodies - --> $DIR/match_same_arms.rs:26:15 - | -LL | 52 => 2, //~ ERROR match arms have same body - | ^ - | -note: same as this - --> $DIR/match_same_arms.rs:25:15 - | -LL | 41 => 2, - | ^ -help: consider refactoring into `41 | 52` - --> $DIR/match_same_arms.rs:25:9 - | -LL | 41 => 2, - | ^^ - -error: this `match` has identical arm bodies - --> $DIR/match_same_arms.rs:32:14 - | -LL | 2 => 2, //~ ERROR 2nd matched arms have same body - | ^ - | -note: same as this - --> $DIR/match_same_arms.rs:31:14 - | -LL | 1 => 2, - | ^ -help: consider refactoring into `1 | 2` - --> $DIR/match_same_arms.rs:31:9 - | -LL | 1 => 2, - | ^ - -error: this `match` has identical arm bodies - --> $DIR/match_same_arms.rs:33:14 - | -LL | 3 => 2, //~ ERROR 3rd matched arms have same body - | ^ - | -note: same as this - --> $DIR/match_same_arms.rs:31:14 - | -LL | 1 => 2, - | ^ -help: consider refactoring into `1 | 3` - --> $DIR/match_same_arms.rs:31:9 - | -LL | 1 => 2, - | ^ - -error: this `match` has identical arm bodies - --> $DIR/match_same_arms.rs:33:14 - | -LL | 3 => 2, //~ ERROR 3rd matched arms have same body - | ^ - | -note: same as this - --> $DIR/match_same_arms.rs:32:14 - | -LL | 2 => 2, //~ ERROR 2nd matched arms have same body - | ^ -help: consider refactoring into `2 | 3` - --> $DIR/match_same_arms.rs:32:9 - | -LL | 2 => 2, //~ ERROR 2nd matched arms have same body - | ^ - -error: this `match` has identical arm bodies - --> $DIR/match_same_arms.rs:50:55 - | -LL | CommandInfo::External { name, .. } => name.to_string(), - | ^^^^^^^^^^^^^^^^ - | -note: same as this - --> $DIR/match_same_arms.rs:49:54 - | -LL | CommandInfo::BuiltIn { name, .. } => name.to_string(), - | ^^^^^^^^^^^^^^^^ -help: consider refactoring into `CommandInfo::BuiltIn { name, .. } | CommandInfo::External { name, .. }` - --> $DIR/match_same_arms.rs:49:17 - | -LL | CommandInfo::BuiltIn { name, .. } => name.to_string(), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 8 previous errors - diff --git a/tests/ui/match_same_arms2.rs b/tests/ui/match_same_arms2.rs deleted file mode 100644 index 06d91497242e..000000000000 --- a/tests/ui/match_same_arms2.rs +++ /dev/null @@ -1,140 +0,0 @@ -#![warn(clippy::match_same_arms)] -#![allow(clippy::blacklisted_name)] - -fn bar(_: T) {} -fn foo() -> bool { - unimplemented!() -} - -fn match_same_arms() { - let _ = match 42 { - 42 => { - foo(); - let mut a = 42 + [23].len() as i32; - if true { - a += 7; - } - a = -31 - a; - a - }, - _ => { - //~ ERROR match arms have same body - foo(); - let mut a = 42 + [23].len() as i32; - if true { - a += 7; - } - a = -31 - a; - a - }, - }; - - let _ = match 42 { - 42 => foo(), - 51 => foo(), //~ ERROR match arms have same body - _ => true, - }; - - let _ = match Some(42) { - Some(_) => 24, - None => 24, //~ ERROR match arms have same body - }; - - let _ = match Some(42) { - Some(foo) => 24, - None => 24, - }; - - let _ = match Some(42) { - Some(42) => 24, - Some(a) => 24, // bindings are different - None => 0, - }; - - let _ = match Some(42) { - Some(a) if a > 0 => 24, - Some(a) => 24, // one arm has a guard - None => 0, - }; - - match (Some(42), Some(42)) { - (Some(a), None) => bar(a), - (None, Some(a)) => bar(a), //~ ERROR match arms have same body - _ => (), - } - - match (Some(42), Some(42)) { - (Some(a), ..) => bar(a), - (.., Some(a)) => bar(a), //~ ERROR match arms have same body - _ => (), - } - - let _ = match Some(()) { - Some(()) => 0.0, - None => -0.0, - }; - - match (Some(42), Some("")) { - (Some(a), None) => bar(a), - (None, Some(a)) => bar(a), // bindings have different types - _ => (), - } - - let x: Result = Ok(3); - - // No warning because of the guard. - match x { - Ok(x) if x * x == 64 => println!("ok"), - Ok(_) => println!("ok"), - Err(_) => println!("err"), - } - - // This used to be a false positive; see issue #1996. - match x { - Ok(3) => println!("ok"), - Ok(x) if x * x == 64 => println!("ok 64"), - Ok(_) => println!("ok"), - Err(_) => println!("err"), - } - - match (x, Some(1i32)) { - (Ok(x), Some(_)) => println!("ok {}", x), - (Ok(_), Some(x)) => println!("ok {}", x), - _ => println!("err"), - } - - // No warning; different types for `x`. - match (x, Some(1.0f64)) { - (Ok(x), Some(_)) => println!("ok {}", x), - (Ok(_), Some(x)) => println!("ok {}", x), - _ => println!("err"), - } - - // False negative #2251. - match x { - Ok(_tmp) => println!("ok"), - Ok(3) => println!("ok"), - Ok(_) => println!("ok"), - Err(_) => { - unreachable!(); - }, - } - - match_expr_like_matches_macro_priority(); -} - -fn match_expr_like_matches_macro_priority() { - enum E { - A, - B, - C, - } - let x = E::A; - let _ans = match x { - E::A => false, - E::B => false, - _ => true, - }; -} - -fn main() {} diff --git a/tests/ui/match_same_arms2.stderr b/tests/ui/match_same_arms2.stderr deleted file mode 100644 index fccaf805616b..000000000000 --- a/tests/ui/match_same_arms2.stderr +++ /dev/null @@ -1,158 +0,0 @@ -error: this `match` has identical arm bodies - --> $DIR/match_same_arms2.rs:20:14 - | -LL | _ => { - | ______________^ -LL | | //~ ERROR match arms have same body -LL | | foo(); -LL | | let mut a = 42 + [23].len() as i32; -... | -LL | | a -LL | | }, - | |_________^ - | - = note: `-D clippy::match-same-arms` implied by `-D warnings` -note: same as this - --> $DIR/match_same_arms2.rs:11:15 - | -LL | 42 => { - | _______________^ -LL | | foo(); -LL | | let mut a = 42 + [23].len() as i32; -LL | | if true { -... | -LL | | a -LL | | }, - | |_________^ -note: `42` has the same arm body as the `_` wildcard, consider removing it - --> $DIR/match_same_arms2.rs:11:15 - | -LL | 42 => { - | _______________^ -LL | | foo(); -LL | | let mut a = 42 + [23].len() as i32; -LL | | if true { -... | -LL | | a -LL | | }, - | |_________^ - -error: this `match` has identical arm bodies - --> $DIR/match_same_arms2.rs:34:15 - | -LL | 51 => foo(), //~ ERROR match arms have same body - | ^^^^^ - | -note: same as this - --> $DIR/match_same_arms2.rs:33:15 - | -LL | 42 => foo(), - | ^^^^^ -help: consider refactoring into `42 | 51` - --> $DIR/match_same_arms2.rs:33:9 - | -LL | 42 => foo(), - | ^^ - -error: this `match` has identical arm bodies - --> $DIR/match_same_arms2.rs:40:17 - | -LL | None => 24, //~ ERROR match arms have same body - | ^^ - | -note: same as this - --> $DIR/match_same_arms2.rs:39:20 - | -LL | Some(_) => 24, - | ^^ -help: consider refactoring into `Some(_) | None` - --> $DIR/match_same_arms2.rs:39:9 - | -LL | Some(_) => 24, - | ^^^^^^^ - -error: this `match` has identical arm bodies - --> $DIR/match_same_arms2.rs:62:28 - | -LL | (None, Some(a)) => bar(a), //~ ERROR match arms have same body - | ^^^^^^ - | -note: same as this - --> $DIR/match_same_arms2.rs:61:28 - | -LL | (Some(a), None) => bar(a), - | ^^^^^^ -help: consider refactoring into `(Some(a), None) | (None, Some(a))` - --> $DIR/match_same_arms2.rs:61:9 - | -LL | (Some(a), None) => bar(a), - | ^^^^^^^^^^^^^^^ - -error: this `match` has identical arm bodies - --> $DIR/match_same_arms2.rs:68:26 - | -LL | (.., Some(a)) => bar(a), //~ ERROR match arms have same body - | ^^^^^^ - | -note: same as this - --> $DIR/match_same_arms2.rs:67:26 - | -LL | (Some(a), ..) => bar(a), - | ^^^^^^ -help: consider refactoring into `(Some(a), ..) | (.., Some(a))` - --> $DIR/match_same_arms2.rs:67:9 - | -LL | (Some(a), ..) => bar(a), - | ^^^^^^^^^^^^^ - -error: this `match` has identical arm bodies - --> $DIR/match_same_arms2.rs:102:29 - | -LL | (Ok(_), Some(x)) => println!("ok {}", x), - | ^^^^^^^^^^^^^^^^^^^^ - | -note: same as this - --> $DIR/match_same_arms2.rs:101:29 - | -LL | (Ok(x), Some(_)) => println!("ok {}", x), - | ^^^^^^^^^^^^^^^^^^^^ -help: consider refactoring into `(Ok(x), Some(_)) | (Ok(_), Some(x))` - --> $DIR/match_same_arms2.rs:101:9 - | -LL | (Ok(x), Some(_)) => println!("ok {}", x), - | ^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: this `match` has identical arm bodies - --> $DIR/match_same_arms2.rs:117:18 - | -LL | Ok(_) => println!("ok"), - | ^^^^^^^^^^^^^^ - | -note: same as this - --> $DIR/match_same_arms2.rs:116:18 - | -LL | Ok(3) => println!("ok"), - | ^^^^^^^^^^^^^^ -help: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/match_same_arms2.rs:116:9 - | -LL | Ok(3) => println!("ok"), - | ^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: match expression looks like `matches!` macro - --> $DIR/match_same_arms2.rs:133:16 - | -LL | let _ans = match x { - | ________________^ -LL | | E::A => false, -LL | | E::B => false, -LL | | _ => true, -LL | | }; - | |_____^ help: try this: `!matches!(x, E::A | E::B)` - | - = note: `-D clippy::match-like-matches-macro` implied by `-D warnings` - -error: aborting due to 8 previous errors - diff --git a/tests/ui/match_single_binding.fixed b/tests/ui/match_single_binding.fixed deleted file mode 100644 index 526e94b10bd0..000000000000 --- a/tests/ui/match_single_binding.fixed +++ /dev/null @@ -1,118 +0,0 @@ -// run-rustfix - -#![warn(clippy::match_single_binding)] -#![allow(unused_variables, clippy::many_single_char_names, clippy::toplevel_ref_arg)] - -struct Point { - x: i32, - y: i32, -} - -fn coords() -> Point { - Point { x: 1, y: 2 } -} - -macro_rules! foo { - ($param:expr) => { - match $param { - _ => println!("whatever"), - } - }; -} - -fn main() { - let a = 1; - let b = 2; - let c = 3; - // Lint - let (x, y, z) = (a, b, c); - { - println!("{} {} {}", x, y, z); - } - // Lint - let (x, y, z) = (a, b, c); - println!("{} {} {}", x, y, z); - // Ok - foo!(a); - // Ok - match a { - 2 => println!("2"), - _ => println!("Not 2"), - } - // Ok - let d = Some(5); - match d { - Some(d) => println!("{}", d), - _ => println!("None"), - } - // Lint - println!("whatever"); - // Lint - { - let x = 29; - println!("x has a value of {}", x); - } - // Lint - { - let e = 5 * a; - if e >= 5 { - println!("e is superior to 5"); - } - } - // Lint - let p = Point { x: 0, y: 7 }; - let Point { x, y } = p; - println!("Coords: ({}, {})", x, y); - // Lint - let Point { x: x1, y: y1 } = p; - println!("Coords: ({}, {})", x1, y1); - // Lint - let x = 5; - let ref r = x; - println!("Got a reference to {}", r); - // Lint - let mut x = 5; - let ref mut mr = x; - println!("Got a mutable reference to {}", mr); - // Lint - let Point { x, y } = coords(); - let product = x * y; - // Lint - let v = vec![Some(1), Some(2), Some(3), Some(4)]; - #[allow(clippy::let_and_return)] - let _ = v - .iter() - .map(|i| { - let unwrapped = i.unwrap(); - unwrapped - }) - .collect::>(); - // Ok - let x = 1; - match x { - #[cfg(disabled_feature)] - 0 => println!("Disabled branch"), - _ => println!("Enabled branch"), - } - // Lint - let x = 1; - let y = 1; - println!("Single branch"); - // Ok - let x = 1; - let y = 1; - match match y { - 0 => 1, - _ => 2, - } { - #[cfg(disabled_feature)] - 0 => println!("Array index start"), - _ => println!("Not an array index start"), - } - // False negative - let x = 1; - match x { - // => - _ => println!("Not an array index start"), - } -} diff --git a/tests/ui/match_single_binding.rs b/tests/ui/match_single_binding.rs deleted file mode 100644 index 6a2ca7c5e934..000000000000 --- a/tests/ui/match_single_binding.rs +++ /dev/null @@ -1,135 +0,0 @@ -// run-rustfix - -#![warn(clippy::match_single_binding)] -#![allow(unused_variables, clippy::many_single_char_names, clippy::toplevel_ref_arg)] - -struct Point { - x: i32, - y: i32, -} - -fn coords() -> Point { - Point { x: 1, y: 2 } -} - -macro_rules! foo { - ($param:expr) => { - match $param { - _ => println!("whatever"), - } - }; -} - -fn main() { - let a = 1; - let b = 2; - let c = 3; - // Lint - match (a, b, c) { - (x, y, z) => { - println!("{} {} {}", x, y, z); - }, - } - // Lint - match (a, b, c) { - (x, y, z) => println!("{} {} {}", x, y, z), - } - // Ok - foo!(a); - // Ok - match a { - 2 => println!("2"), - _ => println!("Not 2"), - } - // Ok - let d = Some(5); - match d { - Some(d) => println!("{}", d), - _ => println!("None"), - } - // Lint - match a { - _ => println!("whatever"), - } - // Lint - match a { - _ => { - let x = 29; - println!("x has a value of {}", x); - }, - } - // Lint - match a { - _ => { - let e = 5 * a; - if e >= 5 { - println!("e is superior to 5"); - } - }, - } - // Lint - let p = Point { x: 0, y: 7 }; - match p { - Point { x, y } => println!("Coords: ({}, {})", x, y), - } - // Lint - match p { - Point { x: x1, y: y1 } => println!("Coords: ({}, {})", x1, y1), - } - // Lint - let x = 5; - match x { - ref r => println!("Got a reference to {}", r), - } - // Lint - let mut x = 5; - match x { - ref mut mr => println!("Got a mutable reference to {}", mr), - } - // Lint - let product = match coords() { - Point { x, y } => x * y, - }; - // Lint - let v = vec![Some(1), Some(2), Some(3), Some(4)]; - #[allow(clippy::let_and_return)] - let _ = v - .iter() - .map(|i| match i.unwrap() { - unwrapped => unwrapped, - }) - .collect::>(); - // Ok - let x = 1; - match x { - #[cfg(disabled_feature)] - 0 => println!("Disabled branch"), - _ => println!("Enabled branch"), - } - // Lint - let x = 1; - let y = 1; - match match y { - 0 => 1, - _ => 2, - } { - _ => println!("Single branch"), - } - // Ok - let x = 1; - let y = 1; - match match y { - 0 => 1, - _ => 2, - } { - #[cfg(disabled_feature)] - 0 => println!("Array index start"), - _ => println!("Not an array index start"), - } - // False negative - let x = 1; - match x { - // => - _ => println!("Not an array index start"), - } -} diff --git a/tests/ui/match_single_binding.stderr b/tests/ui/match_single_binding.stderr deleted file mode 100644 index cbbf5d29c024..000000000000 --- a/tests/ui/match_single_binding.stderr +++ /dev/null @@ -1,182 +0,0 @@ -error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:28:5 - | -LL | / match (a, b, c) { -LL | | (x, y, z) => { -LL | | println!("{} {} {}", x, y, z); -LL | | }, -LL | | } - | |_____^ - | - = note: `-D clippy::match-single-binding` implied by `-D warnings` -help: consider using `let` statement - | -LL | let (x, y, z) = (a, b, c); -LL | { -LL | println!("{} {} {}", x, y, z); -LL | } - | - -error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:34:5 - | -LL | / match (a, b, c) { -LL | | (x, y, z) => println!("{} {} {}", x, y, z), -LL | | } - | |_____^ - | -help: consider using `let` statement - | -LL | let (x, y, z) = (a, b, c); -LL | println!("{} {} {}", x, y, z); - | - -error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:51:5 - | -LL | / match a { -LL | | _ => println!("whatever"), -LL | | } - | |_____^ help: consider using the match body instead: `println!("whatever");` - -error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:55:5 - | -LL | / match a { -LL | | _ => { -LL | | let x = 29; -LL | | println!("x has a value of {}", x); -LL | | }, -LL | | } - | |_____^ - | -help: consider using the match body instead - | -LL | { -LL | let x = 29; -LL | println!("x has a value of {}", x); -LL | } - | - -error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:62:5 - | -LL | / match a { -LL | | _ => { -LL | | let e = 5 * a; -LL | | if e >= 5 { -... | -LL | | }, -LL | | } - | |_____^ - | -help: consider using the match body instead - | -LL | { -LL | let e = 5 * a; -LL | if e >= 5 { -LL | println!("e is superior to 5"); -LL | } -LL | } - | - -error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:72:5 - | -LL | / match p { -LL | | Point { x, y } => println!("Coords: ({}, {})", x, y), -LL | | } - | |_____^ - | -help: consider using `let` statement - | -LL | let Point { x, y } = p; -LL | println!("Coords: ({}, {})", x, y); - | - -error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:76:5 - | -LL | / match p { -LL | | Point { x: x1, y: y1 } => println!("Coords: ({}, {})", x1, y1), -LL | | } - | |_____^ - | -help: consider using `let` statement - | -LL | let Point { x: x1, y: y1 } = p; -LL | println!("Coords: ({}, {})", x1, y1); - | - -error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:81:5 - | -LL | / match x { -LL | | ref r => println!("Got a reference to {}", r), -LL | | } - | |_____^ - | -help: consider using `let` statement - | -LL | let ref r = x; -LL | println!("Got a reference to {}", r); - | - -error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:86:5 - | -LL | / match x { -LL | | ref mut mr => println!("Got a mutable reference to {}", mr), -LL | | } - | |_____^ - | -help: consider using `let` statement - | -LL | let ref mut mr = x; -LL | println!("Got a mutable reference to {}", mr); - | - -error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:90:5 - | -LL | / let product = match coords() { -LL | | Point { x, y } => x * y, -LL | | }; - | |______^ - | -help: consider using `let` statement - | -LL | let Point { x, y } = coords(); -LL | let product = x * y; - | - -error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:98:18 - | -LL | .map(|i| match i.unwrap() { - | __________________^ -LL | | unwrapped => unwrapped, -LL | | }) - | |_________^ - | -help: consider using `let` statement - | -LL | .map(|i| { -LL | let unwrapped = i.unwrap(); -LL | unwrapped -LL | }) - | - -error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:112:5 - | -LL | / match match y { -LL | | 0 => 1, -LL | | _ => 2, -LL | | } { -LL | | _ => println!("Single branch"), -LL | | } - | |_____^ help: consider using the match body instead: `println!("Single branch");` - -error: aborting due to 12 previous errors - diff --git a/tests/ui/match_wild_err_arm.rs b/tests/ui/match_wild_err_arm.rs deleted file mode 100644 index 823be65efe06..000000000000 --- a/tests/ui/match_wild_err_arm.rs +++ /dev/null @@ -1,65 +0,0 @@ -#![feature(exclusive_range_pattern)] -#![allow(clippy::match_same_arms)] -#![warn(clippy::match_wild_err_arm)] - -fn match_wild_err_arm() { - let x: Result = Ok(3); - - match x { - Ok(3) => println!("ok"), - Ok(_) => println!("ok"), - Err(_) => panic!("err"), - } - - match x { - Ok(3) => println!("ok"), - Ok(_) => println!("ok"), - Err(_) => panic!(), - } - - match x { - Ok(3) => println!("ok"), - Ok(_) => println!("ok"), - Err(_) => { - panic!(); - }, - } - - match x { - Ok(3) => println!("ok"), - Ok(_) => println!("ok"), - Err(_e) => panic!(), - } - - // Allowed when used in `panic!`. - match x { - Ok(3) => println!("ok"), - Ok(_) => println!("ok"), - Err(_e) => panic!("{}", _e), - } - - // Allowed when not with `panic!` block. - match x { - Ok(3) => println!("ok"), - Ok(_) => println!("ok"), - Err(_) => println!("err"), - } - - // Allowed when used with `unreachable!`. - match x { - Ok(3) => println!("ok"), - Ok(_) => println!("ok"), - Err(_) => unreachable!(), - } - - // Allowed when used with `unreachable!`. - match x { - Ok(3) => println!("ok"), - Ok(_) => println!("ok"), - Err(_) => { - unreachable!(); - }, - } -} - -fn main() {} diff --git a/tests/ui/match_wild_err_arm.stderr b/tests/ui/match_wild_err_arm.stderr deleted file mode 100644 index 6a2a02987dea..000000000000 --- a/tests/ui/match_wild_err_arm.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error: `Err(_)` matches all errors - --> $DIR/match_wild_err_arm.rs:11:9 - | -LL | Err(_) => panic!("err"), - | ^^^^^^ - | - = note: `-D clippy::match-wild-err-arm` implied by `-D warnings` - = note: match each error separately or use the error output, or use `.except(msg)` if the error case is unreachable - -error: `Err(_)` matches all errors - --> $DIR/match_wild_err_arm.rs:17:9 - | -LL | Err(_) => panic!(), - | ^^^^^^ - | - = note: match each error separately or use the error output, or use `.except(msg)` if the error case is unreachable - -error: `Err(_)` matches all errors - --> $DIR/match_wild_err_arm.rs:23:9 - | -LL | Err(_) => { - | ^^^^^^ - | - = note: match each error separately or use the error output, or use `.except(msg)` if the error case is unreachable - -error: `Err(_e)` matches all errors - --> $DIR/match_wild_err_arm.rs:31:9 - | -LL | Err(_e) => panic!(), - | ^^^^^^^ - | - = note: match each error separately or use the error output, or use `.except(msg)` if the error case is unreachable - -error: aborting due to 4 previous errors - diff --git a/tests/ui/match_wildcard_for_single_variants.fixed b/tests/ui/match_wildcard_for_single_variants.fixed deleted file mode 100644 index 519200977a79..000000000000 --- a/tests/ui/match_wildcard_for_single_variants.fixed +++ /dev/null @@ -1,59 +0,0 @@ -// run-rustfix - -#![warn(clippy::match_wildcard_for_single_variants)] -#![allow(dead_code)] - -enum Foo { - A, - B, - C, -} - -enum Color { - Red, - Green, - Blue, - Rgb(u8, u8, u8), -} - -fn main() { - let f = Foo::A; - match f { - Foo::A => {}, - Foo::B => {}, - Foo::C => {}, - } - - let color = Color::Red; - - // check exhaustive bindings - match color { - Color::Red => {}, - Color::Green => {}, - Color::Rgb(_r, _g, _b) => {}, - Color::Blue => {}, - } - - // check exhaustive wild - match color { - Color::Red => {}, - Color::Green => {}, - Color::Rgb(..) => {}, - Color::Blue => {}, - } - match color { - Color::Red => {}, - Color::Green => {}, - Color::Rgb(_, _, _) => {}, - Color::Blue => {}, - } - - // shouldn't lint as there is one missing variant - // and one that isn't exhaustively covered - match color { - Color::Red => {}, - Color::Green => {}, - Color::Rgb(255, _, _) => {}, - _ => {}, - } -} diff --git a/tests/ui/match_wildcard_for_single_variants.rs b/tests/ui/match_wildcard_for_single_variants.rs deleted file mode 100644 index 1df917e085c7..000000000000 --- a/tests/ui/match_wildcard_for_single_variants.rs +++ /dev/null @@ -1,59 +0,0 @@ -// run-rustfix - -#![warn(clippy::match_wildcard_for_single_variants)] -#![allow(dead_code)] - -enum Foo { - A, - B, - C, -} - -enum Color { - Red, - Green, - Blue, - Rgb(u8, u8, u8), -} - -fn main() { - let f = Foo::A; - match f { - Foo::A => {}, - Foo::B => {}, - _ => {}, - } - - let color = Color::Red; - - // check exhaustive bindings - match color { - Color::Red => {}, - Color::Green => {}, - Color::Rgb(_r, _g, _b) => {}, - _ => {}, - } - - // check exhaustive wild - match color { - Color::Red => {}, - Color::Green => {}, - Color::Rgb(..) => {}, - _ => {}, - } - match color { - Color::Red => {}, - Color::Green => {}, - Color::Rgb(_, _, _) => {}, - _ => {}, - } - - // shouldn't lint as there is one missing variant - // and one that isn't exhaustively covered - match color { - Color::Red => {}, - Color::Green => {}, - Color::Rgb(255, _, _) => {}, - _ => {}, - } -} diff --git a/tests/ui/match_wildcard_for_single_variants.stderr b/tests/ui/match_wildcard_for_single_variants.stderr deleted file mode 100644 index 82790aa9e80b..000000000000 --- a/tests/ui/match_wildcard_for_single_variants.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: wildcard match will miss any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:24:9 - | -LL | _ => {}, - | ^ help: try this: `Foo::C` - | - = note: `-D clippy::match-wildcard-for-single-variants` implied by `-D warnings` - -error: wildcard match will miss any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:34:9 - | -LL | _ => {}, - | ^ help: try this: `Color::Blue` - -error: wildcard match will miss any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:42:9 - | -LL | _ => {}, - | ^ help: try this: `Color::Blue` - -error: wildcard match will miss any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:48:9 - | -LL | _ => {}, - | ^ help: try this: `Color::Blue` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/mem_discriminant.fixed b/tests/ui/mem_discriminant.fixed deleted file mode 100644 index 69a8f286d050..000000000000 --- a/tests/ui/mem_discriminant.fixed +++ /dev/null @@ -1,45 +0,0 @@ -// run-rustfix - -#![deny(clippy::mem_discriminant_non_enum)] - -use std::mem; - -enum Foo { - One(usize), - Two(u8), -} - -fn main() { - // bad - mem::discriminant(&Some(2)); - mem::discriminant(&None::); - mem::discriminant(&Foo::One(5)); - mem::discriminant(&Foo::Two(5)); - - let ro = &Some(3); - let rro = &ro; - mem::discriminant(ro); - mem::discriminant(*rro); - mem::discriminant(*rro); - - macro_rules! mem_discriminant_but_in_a_macro { - ($param:expr) => { - mem::discriminant($param) - }; - } - - mem_discriminant_but_in_a_macro!(*rro); - - let rrrrro = &&&rro; - mem::discriminant(****rrrrro); - mem::discriminant(****rrrrro); - - // ok - mem::discriminant(&Some(2)); - mem::discriminant(&None::); - mem::discriminant(&Foo::One(5)); - mem::discriminant(&Foo::Two(5)); - mem::discriminant(ro); - mem::discriminant(*rro); - mem::discriminant(****rrrrro); -} diff --git a/tests/ui/mem_discriminant.rs b/tests/ui/mem_discriminant.rs deleted file mode 100644 index 55db50fcdc73..000000000000 --- a/tests/ui/mem_discriminant.rs +++ /dev/null @@ -1,45 +0,0 @@ -// run-rustfix - -#![deny(clippy::mem_discriminant_non_enum)] - -use std::mem; - -enum Foo { - One(usize), - Two(u8), -} - -fn main() { - // bad - mem::discriminant(&&Some(2)); - mem::discriminant(&&None::); - mem::discriminant(&&Foo::One(5)); - mem::discriminant(&&Foo::Two(5)); - - let ro = &Some(3); - let rro = &ro; - mem::discriminant(&ro); - mem::discriminant(rro); - mem::discriminant(&rro); - - macro_rules! mem_discriminant_but_in_a_macro { - ($param:expr) => { - mem::discriminant($param) - }; - } - - mem_discriminant_but_in_a_macro!(&rro); - - let rrrrro = &&&rro; - mem::discriminant(&rrrrro); - mem::discriminant(*rrrrro); - - // ok - mem::discriminant(&Some(2)); - mem::discriminant(&None::); - mem::discriminant(&Foo::One(5)); - mem::discriminant(&Foo::Two(5)); - mem::discriminant(ro); - mem::discriminant(*rro); - mem::discriminant(****rrrrro); -} diff --git a/tests/ui/mem_discriminant.stderr b/tests/ui/mem_discriminant.stderr deleted file mode 100644 index 8d9810970ade..000000000000 --- a/tests/ui/mem_discriminant.stderr +++ /dev/null @@ -1,94 +0,0 @@ -error: calling `mem::discriminant` on non-enum type `&std::option::Option` - --> $DIR/mem_discriminant.rs:14:5 - | -LL | mem::discriminant(&&Some(2)); - | ^^^^^^^^^^^^^^^^^^---------^ - | | - | help: try dereferencing: `&Some(2)` - | -note: the lint level is defined here - --> $DIR/mem_discriminant.rs:3:9 - | -LL | #![deny(clippy::mem_discriminant_non_enum)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: calling `mem::discriminant` on non-enum type `&std::option::Option` - --> $DIR/mem_discriminant.rs:15:5 - | -LL | mem::discriminant(&&None::); - | ^^^^^^^^^^^^^^^^^^------------^ - | | - | help: try dereferencing: `&None::` - -error: calling `mem::discriminant` on non-enum type `&Foo` - --> $DIR/mem_discriminant.rs:16:5 - | -LL | mem::discriminant(&&Foo::One(5)); - | ^^^^^^^^^^^^^^^^^^-------------^ - | | - | help: try dereferencing: `&Foo::One(5)` - -error: calling `mem::discriminant` on non-enum type `&Foo` - --> $DIR/mem_discriminant.rs:17:5 - | -LL | mem::discriminant(&&Foo::Two(5)); - | ^^^^^^^^^^^^^^^^^^-------------^ - | | - | help: try dereferencing: `&Foo::Two(5)` - -error: calling `mem::discriminant` on non-enum type `&std::option::Option` - --> $DIR/mem_discriminant.rs:21:5 - | -LL | mem::discriminant(&ro); - | ^^^^^^^^^^^^^^^^^^---^ - | | - | help: try dereferencing: `ro` - -error: calling `mem::discriminant` on non-enum type `&std::option::Option` - --> $DIR/mem_discriminant.rs:22:5 - | -LL | mem::discriminant(rro); - | ^^^^^^^^^^^^^^^^^^---^ - | | - | help: try dereferencing: `*rro` - -error: calling `mem::discriminant` on non-enum type `&&std::option::Option` - --> $DIR/mem_discriminant.rs:23:5 - | -LL | mem::discriminant(&rro); - | ^^^^^^^^^^^^^^^^^^----^ - | | - | help: try dereferencing: `*rro` - -error: calling `mem::discriminant` on non-enum type `&&std::option::Option` - --> $DIR/mem_discriminant.rs:27:13 - | -LL | mem::discriminant($param) - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | mem_discriminant_but_in_a_macro!(&rro); - | --------------------------------------- - | | | - | | help: try dereferencing: `*rro` - | in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: calling `mem::discriminant` on non-enum type `&&&&&std::option::Option` - --> $DIR/mem_discriminant.rs:34:5 - | -LL | mem::discriminant(&rrrrro); - | ^^^^^^^^^^^^^^^^^^-------^ - | | - | help: try dereferencing: `****rrrrro` - -error: calling `mem::discriminant` on non-enum type `&&&std::option::Option` - --> $DIR/mem_discriminant.rs:35:5 - | -LL | mem::discriminant(*rrrrro); - | ^^^^^^^^^^^^^^^^^^-------^ - | | - | help: try dereferencing: `****rrrrro` - -error: aborting due to 10 previous errors - diff --git a/tests/ui/mem_discriminant_unfixable.rs b/tests/ui/mem_discriminant_unfixable.rs deleted file mode 100644 index e245d3257d55..000000000000 --- a/tests/ui/mem_discriminant_unfixable.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![deny(clippy::mem_discriminant_non_enum)] - -use std::mem; - -enum Foo { - One(usize), - Two(u8), -} - -struct A(Foo); - -fn main() { - // bad - mem::discriminant(&"hello"); - mem::discriminant(&A(Foo::One(0))); -} diff --git a/tests/ui/mem_discriminant_unfixable.stderr b/tests/ui/mem_discriminant_unfixable.stderr deleted file mode 100644 index e2de3776f2c9..000000000000 --- a/tests/ui/mem_discriminant_unfixable.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: calling `mem::discriminant` on non-enum type `&str` - --> $DIR/mem_discriminant_unfixable.rs:14:5 - | -LL | mem::discriminant(&"hello"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/mem_discriminant_unfixable.rs:1:9 - | -LL | #![deny(clippy::mem_discriminant_non_enum)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: calling `mem::discriminant` on non-enum type `A` - --> $DIR/mem_discriminant_unfixable.rs:15:5 - | -LL | mem::discriminant(&A(Foo::One(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/mem_forget.rs b/tests/ui/mem_forget.rs deleted file mode 100644 index e5b35c098a23..000000000000 --- a/tests/ui/mem_forget.rs +++ /dev/null @@ -1,23 +0,0 @@ -use std::rc::Rc; -use std::sync::Arc; - -use std::mem as memstuff; -use std::mem::forget as forgetSomething; - -#[warn(clippy::mem_forget)] -#[allow(clippy::forget_copy)] -fn main() { - let five: i32 = 5; - forgetSomething(five); - - let six: Arc = Arc::new(6); - memstuff::forget(six); - - let seven: Rc = Rc::new(7); - std::mem::forget(seven); - - let eight: Vec = vec![8]; - forgetSomething(eight); - - std::mem::forget(7); -} diff --git a/tests/ui/mem_forget.stderr b/tests/ui/mem_forget.stderr deleted file mode 100644 index a90d8b1655dc..000000000000 --- a/tests/ui/mem_forget.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: usage of `mem::forget` on `Drop` type - --> $DIR/mem_forget.rs:14:5 - | -LL | memstuff::forget(six); - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::mem-forget` implied by `-D warnings` - -error: usage of `mem::forget` on `Drop` type - --> $DIR/mem_forget.rs:17:5 - | -LL | std::mem::forget(seven); - | ^^^^^^^^^^^^^^^^^^^^^^^ - -error: usage of `mem::forget` on `Drop` type - --> $DIR/mem_forget.rs:20:5 - | -LL | forgetSomething(eight); - | ^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/mem_replace.fixed b/tests/ui/mem_replace.fixed deleted file mode 100644 index 54e962e7116e..000000000000 --- a/tests/ui/mem_replace.fixed +++ /dev/null @@ -1,30 +0,0 @@ -// run-rustfix -#![allow(unused_imports)] -#![warn( - clippy::all, - clippy::style, - clippy::mem_replace_option_with_none, - clippy::mem_replace_with_default -)] - -use std::mem; - -fn replace_option_with_none() { - let mut an_option = Some(1); - let _ = an_option.take(); - let an_option = &mut Some(1); - let _ = an_option.take(); -} - -fn replace_with_default() { - let mut s = String::from("foo"); - let _ = std::mem::take(&mut s); - let s = &mut String::from("foo"); - let _ = std::mem::take(s); - let _ = std::mem::take(s); -} - -fn main() { - replace_option_with_none(); - replace_with_default(); -} diff --git a/tests/ui/mem_replace.rs b/tests/ui/mem_replace.rs deleted file mode 100644 index 60f527810716..000000000000 --- a/tests/ui/mem_replace.rs +++ /dev/null @@ -1,30 +0,0 @@ -// run-rustfix -#![allow(unused_imports)] -#![warn( - clippy::all, - clippy::style, - clippy::mem_replace_option_with_none, - clippy::mem_replace_with_default -)] - -use std::mem; - -fn replace_option_with_none() { - let mut an_option = Some(1); - let _ = mem::replace(&mut an_option, None); - let an_option = &mut Some(1); - let _ = mem::replace(an_option, None); -} - -fn replace_with_default() { - let mut s = String::from("foo"); - let _ = std::mem::replace(&mut s, String::default()); - let s = &mut String::from("foo"); - let _ = std::mem::replace(s, String::default()); - let _ = std::mem::replace(s, Default::default()); -} - -fn main() { - replace_option_with_none(); - replace_with_default(); -} diff --git a/tests/ui/mem_replace.stderr b/tests/ui/mem_replace.stderr deleted file mode 100644 index 245d33aa4f26..000000000000 --- a/tests/ui/mem_replace.stderr +++ /dev/null @@ -1,36 +0,0 @@ -error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:14:13 - | -LL | let _ = mem::replace(&mut an_option, None); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` - | - = note: `-D clippy::mem-replace-option-with-none` implied by `-D warnings` - -error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:16:13 - | -LL | let _ = mem::replace(an_option, None); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` - -error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:21:13 - | -LL | let _ = std::mem::replace(&mut s, String::default()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` - | - = note: `-D clippy::mem-replace-with-default` implied by `-D warnings` - -error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:23:13 - | -LL | let _ = std::mem::replace(s, String::default()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` - -error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:24:13 - | -LL | let _ = std::mem::replace(s, Default::default()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` - -error: aborting due to 5 previous errors - diff --git a/tests/ui/mem_replace_macro.rs b/tests/ui/mem_replace_macro.rs deleted file mode 100644 index 0c09344b80d1..000000000000 --- a/tests/ui/mem_replace_macro.rs +++ /dev/null @@ -1,21 +0,0 @@ -// aux-build:macro_rules.rs -#![warn(clippy::mem_replace_with_default)] - -#[macro_use] -extern crate macro_rules; - -macro_rules! take { - ($s:expr) => { - std::mem::replace($s, Default::default()) - }; -} - -fn replace_with_default() { - let s = &mut String::from("foo"); - take!(s); - take_external!(s); -} - -fn main() { - replace_with_default(); -} diff --git a/tests/ui/mem_replace_macro.stderr b/tests/ui/mem_replace_macro.stderr deleted file mode 100644 index 4971a91050bf..000000000000 --- a/tests/ui/mem_replace_macro.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace_macro.rs:9:9 - | -LL | std::mem::replace($s, Default::default()) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | take!(s); - | --------- in this macro invocation - | - = note: `-D clippy::mem-replace-with-default` implied by `-D warnings` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to previous error - diff --git a/tests/ui/methods.rs b/tests/ui/methods.rs deleted file mode 100644 index 513d930e0568..000000000000 --- a/tests/ui/methods.rs +++ /dev/null @@ -1,138 +0,0 @@ -// aux-build:option_helpers.rs -// edition:2018 - -#![warn(clippy::all, clippy::pedantic)] -#![allow( - clippy::blacklisted_name, - clippy::default_trait_access, - clippy::missing_docs_in_private_items, - clippy::missing_safety_doc, - clippy::non_ascii_literal, - clippy::new_without_default, - clippy::needless_pass_by_value, - clippy::needless_lifetimes, - clippy::print_stdout, - clippy::must_use_candidate, - clippy::use_self, - clippy::useless_format, - clippy::wrong_self_convention, - clippy::unused_self, - unused -)] - -#[macro_use] -extern crate option_helpers; - -use std::collections::BTreeMap; -use std::collections::HashMap; -use std::collections::HashSet; -use std::collections::VecDeque; -use std::iter::FromIterator; -use std::ops::Mul; -use std::rc::{self, Rc}; -use std::sync::{self, Arc}; - -use option_helpers::IteratorFalsePositives; - -struct Lt<'a> { - foo: &'a u32, -} - -impl<'a> Lt<'a> { - // The lifetime is different, but that’s irrelevant; see issue #734. - #[allow(clippy::needless_lifetimes)] - pub fn new<'b>(s: &'b str) -> Lt<'b> { - unimplemented!() - } -} - -struct Lt2<'a> { - foo: &'a u32, -} - -impl<'a> Lt2<'a> { - // The lifetime is different, but that’s irrelevant; see issue #734. - pub fn new(s: &str) -> Lt2 { - unimplemented!() - } -} - -struct Lt3<'a> { - foo: &'a u32, -} - -impl<'a> Lt3<'a> { - // The lifetime is different, but that’s irrelevant; see issue #734. - pub fn new() -> Lt3<'static> { - unimplemented!() - } -} - -#[derive(Clone, Copy)] -struct U; - -impl U { - fn new() -> Self { - U - } - // Ok because `U` is `Copy`. - fn to_something(self) -> u32 { - 0 - } -} - -struct V { - _dummy: T, -} - -impl V { - fn new() -> Option> { - None - } -} - -struct AsyncNew; - -impl AsyncNew { - async fn new() -> Option { - None - } -} - -struct BadNew; - -impl BadNew { - fn new() -> i32 { - 0 - } -} - -struct T; - -impl Mul for T { - type Output = T; - // No error, obviously. - fn mul(self, other: T) -> T { - self - } -} - -/// Checks implementation of `FILTER_NEXT` lint. -#[rustfmt::skip] -fn filter_next() { - let v = vec![3, 2, 1, 0, -1, -2, -3]; - - // Multi-line case. - let _ = v.iter().filter(|&x| { - *x < 0 - } - ).next(); - - // Check that we don't lint if the caller is not an `Iterator`. - let foo = IteratorFalsePositives { foo: 0 }; - let _ = foo.filter().next(); -} - -fn main() { - filter_next(); -} diff --git a/tests/ui/methods.stderr b/tests/ui/methods.stderr deleted file mode 100644 index 33aba630a530..000000000000 --- a/tests/ui/methods.stderr +++ /dev/null @@ -1,24 +0,0 @@ -error: methods called `new` usually return `Self` - --> $DIR/methods.rs:105:5 - | -LL | / fn new() -> i32 { -LL | | 0 -LL | | } - | |_____^ - | - = note: `-D clippy::new-ret-no-self` implied by `-D warnings` - -error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead. - --> $DIR/methods.rs:126:13 - | -LL | let _ = v.iter().filter(|&x| { - | _____________^ -LL | | *x < 0 -LL | | } -LL | | ).next(); - | |___________________________^ - | - = note: `-D clippy::filter-next` implied by `-D warnings` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/methods_fixable.fixed b/tests/ui/methods_fixable.fixed deleted file mode 100644 index ee7c1b0da6d9..000000000000 --- a/tests/ui/methods_fixable.fixed +++ /dev/null @@ -1,11 +0,0 @@ -// run-rustfix - -#![warn(clippy::filter_next)] - -/// Checks implementation of `FILTER_NEXT` lint. -fn main() { - let v = vec![3, 2, 1, 0, -1, -2, -3]; - - // Single-line case. - let _ = v.iter().find(|&x| *x < 0); -} diff --git a/tests/ui/methods_fixable.rs b/tests/ui/methods_fixable.rs deleted file mode 100644 index 6d0f1b7bd514..000000000000 --- a/tests/ui/methods_fixable.rs +++ /dev/null @@ -1,11 +0,0 @@ -// run-rustfix - -#![warn(clippy::filter_next)] - -/// Checks implementation of `FILTER_NEXT` lint. -fn main() { - let v = vec![3, 2, 1, 0, -1, -2, -3]; - - // Single-line case. - let _ = v.iter().filter(|&x| *x < 0).next(); -} diff --git a/tests/ui/methods_fixable.stderr b/tests/ui/methods_fixable.stderr deleted file mode 100644 index 70e7c3dea545..000000000000 --- a/tests/ui/methods_fixable.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead. - --> $DIR/methods_fixable.rs:10:13 - | -LL | let _ = v.iter().filter(|&x| *x < 0).next(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `v.iter().find(|&x| *x < 0)` - | - = note: `-D clippy::filter-next` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/min_max.rs b/tests/ui/min_max.rs deleted file mode 100644 index f7ed72a11cf6..000000000000 --- a/tests/ui/min_max.rs +++ /dev/null @@ -1,65 +0,0 @@ -#![warn(clippy::all)] - -use std::cmp::max as my_max; -use std::cmp::min as my_min; -use std::cmp::{max, min}; - -const LARGE: usize = 3; - -struct NotOrd(u64); - -impl NotOrd { - fn min(self, x: u64) -> NotOrd { - NotOrd(x) - } - - fn max(self, x: u64) -> NotOrd { - NotOrd(x) - } -} - -fn main() { - let x; - x = 2usize; - min(1, max(3, x)); - min(max(3, x), 1); - max(min(x, 1), 3); - max(3, min(x, 1)); - - my_max(3, my_min(x, 1)); - - min(3, max(1, x)); // ok, could be 1, 2 or 3 depending on x - - min(1, max(LARGE, x)); // no error, we don't lookup consts here - - let y = 2isize; - min(max(y, -1), 3); - - let s; - s = "Hello"; - - min("Apple", max("Zoo", s)); - max(min(s, "Apple"), "Zoo"); - - max("Apple", min(s, "Zoo")); // ok - - let f = 3f32; - x.min(1).max(3); - x.max(3).min(1); - f.max(3f32).min(1f32); - - x.max(1).min(3); // ok - x.min(3).max(1); // ok - f.min(3f32).max(1f32); // ok - - max(x.min(1), 3); - min(x.max(1), 3); // ok - - s.max("Zoo").min("Apple"); - s.min("Apple").max("Zoo"); - - s.min("Zoo").max("Apple"); // ok - - let not_ord = NotOrd(1); - not_ord.min(1).max(3); // ok -} diff --git a/tests/ui/min_max.stderr b/tests/ui/min_max.stderr deleted file mode 100644 index 9f8e26fa406f..000000000000 --- a/tests/ui/min_max.stderr +++ /dev/null @@ -1,82 +0,0 @@ -error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:24:5 - | -LL | min(1, max(3, x)); - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::min-max` implied by `-D warnings` - -error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:25:5 - | -LL | min(max(3, x), 1); - | ^^^^^^^^^^^^^^^^^ - -error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:26:5 - | -LL | max(min(x, 1), 3); - | ^^^^^^^^^^^^^^^^^ - -error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:27:5 - | -LL | max(3, min(x, 1)); - | ^^^^^^^^^^^^^^^^^ - -error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:29:5 - | -LL | my_max(3, my_min(x, 1)); - | ^^^^^^^^^^^^^^^^^^^^^^^ - -error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:41:5 - | -LL | min("Apple", max("Zoo", s)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:42:5 - | -LL | max(min(s, "Apple"), "Zoo"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:47:5 - | -LL | x.min(1).max(3); - | ^^^^^^^^^^^^^^^ - -error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:48:5 - | -LL | x.max(3).min(1); - | ^^^^^^^^^^^^^^^ - -error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:49:5 - | -LL | f.max(3f32).min(1f32); - | ^^^^^^^^^^^^^^^^^^^^^ - -error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:55:5 - | -LL | max(x.min(1), 3); - | ^^^^^^^^^^^^^^^^ - -error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:58:5 - | -LL | s.max("Zoo").min("Apple"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:59:5 - | -LL | s.min("Apple").max("Zoo"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 13 previous errors - diff --git a/tests/ui/min_rust_version_attr.rs b/tests/ui/min_rust_version_attr.rs deleted file mode 100644 index 3848bca32075..000000000000 --- a/tests/ui/min_rust_version_attr.rs +++ /dev/null @@ -1,169 +0,0 @@ -#![allow(clippy::redundant_clone)] -#![feature(custom_inner_attributes)] -#![clippy::msrv = "1.0.0"] - -use std::ops::{Deref, RangeFrom}; - -fn option_as_ref_deref() { - let mut opt = Some(String::from("123")); - - let _ = opt.as_ref().map(String::as_str); - let _ = opt.as_ref().map(|x| x.as_str()); - let _ = opt.as_mut().map(String::as_mut_str); - let _ = opt.as_mut().map(|x| x.as_mut_str()); -} - -fn match_like_matches() { - let _y = match Some(5) { - Some(0) => true, - _ => false, - }; -} - -fn match_same_arms() { - match (1, 2, 3) { - (1, .., 3) => 42, - (.., 3) => 42, //~ ERROR match arms have same body - _ => 0, - }; -} - -fn match_same_arms2() { - let _ = match Some(42) { - Some(_) => 24, - None => 24, //~ ERROR match arms have same body - }; -} - -pub fn manual_strip_msrv() { - let s = "hello, world!"; - if s.starts_with("hello, ") { - assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!"); - } -} - -pub fn redundant_fieldnames() { - let start = 0; - let _ = RangeFrom { start: start }; -} - -pub fn redundant_static_lifetime() { - const VAR_ONE: &'static str = "Test constant #1"; -} - -pub fn checked_conversion() { - let value: i64 = 42; - let _ = value <= (u32::max_value() as i64) && value >= 0; - let _ = value <= (u32::MAX as i64) && value >= 0; -} - -pub fn filter_map_next() { - let a = ["1", "lol", "3", "NaN", "5"]; - - #[rustfmt::skip] - let _: Option = vec![1, 2, 3, 4, 5, 6] - .into_iter() - .filter_map(|x| { - if x == 2 { - Some(x * 2) - } else { - None - } - }) - .next(); -} - -#[allow(clippy::no_effect)] -#[allow(clippy::short_circuit_statement)] -#[allow(clippy::unnecessary_operation)] -pub fn manual_range_contains() { - let x = 5; - x >= 8 && x < 12; -} - -pub fn use_self() { - struct Foo {} - - impl Foo { - fn new() -> Foo { - Foo {} - } - fn test() -> Foo { - Foo::new() - } - } -} - -fn replace_with_default() { - let mut s = String::from("foo"); - let _ = std::mem::replace(&mut s, String::default()); -} - -fn map_unwrap_or() { - let opt = Some(1); - - // Check for `option.map(_).unwrap_or(_)` use. - // Single line case. - let _ = opt - .map(|x| x + 1) - // Should lint even though this call is on a separate line. - .unwrap_or(0); -} - -// Could be const -fn missing_const_for_fn() -> i32 { - 1 -} - -fn main() { - filter_map_next(); - checked_conversion(); - redundant_fieldnames(); - redundant_static_lifetime(); - option_as_ref_deref(); - match_like_matches(); - match_same_arms(); - match_same_arms2(); - manual_strip_msrv(); - manual_range_contains(); - use_self(); - replace_with_default(); - map_unwrap_or(); - missing_const_for_fn(); -} - -mod meets_msrv { - #![feature(custom_inner_attributes)] - #![clippy::msrv = "1.45.0"] - - fn main() { - let s = "hello, world!"; - if s.starts_with("hello, ") { - assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!"); - } - } -} - -mod just_under_msrv { - #![feature(custom_inner_attributes)] - #![clippy::msrv = "1.46.0"] - - fn main() { - let s = "hello, world!"; - if s.starts_with("hello, ") { - assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!"); - } - } -} - -mod just_above_msrv { - #![feature(custom_inner_attributes)] - #![clippy::msrv = "1.44.0"] - - fn main() { - let s = "hello, world!"; - if s.starts_with("hello, ") { - assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!"); - } - } -} diff --git a/tests/ui/min_rust_version_attr.stderr b/tests/ui/min_rust_version_attr.stderr deleted file mode 100644 index 348052631049..000000000000 --- a/tests/ui/min_rust_version_attr.stderr +++ /dev/null @@ -1,37 +0,0 @@ -error: stripping a prefix manually - --> $DIR/min_rust_version_attr.rs:142:24 - | -LL | assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!"); - | ^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::manual-strip` implied by `-D warnings` -note: the prefix was tested here - --> $DIR/min_rust_version_attr.rs:141:9 - | -LL | if s.starts_with("hello, ") { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: try using the `strip_prefix` method - | -LL | if let Some() = s.strip_prefix("hello, ") { -LL | assert_eq!(.to_uppercase(), "WORLD!"); - | - -error: stripping a prefix manually - --> $DIR/min_rust_version_attr.rs:154:24 - | -LL | assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!"); - | ^^^^^^^^^^^^^^^^^^^^ - | -note: the prefix was tested here - --> $DIR/min_rust_version_attr.rs:153:9 - | -LL | if s.starts_with("hello, ") { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: try using the `strip_prefix` method - | -LL | if let Some() = s.strip_prefix("hello, ") { -LL | assert_eq!(.to_uppercase(), "WORLD!"); - | - -error: aborting due to 2 previous errors - diff --git a/tests/ui/min_rust_version_invalid_attr.rs b/tests/ui/min_rust_version_invalid_attr.rs deleted file mode 100644 index f20841891a74..000000000000 --- a/tests/ui/min_rust_version_invalid_attr.rs +++ /dev/null @@ -1,4 +0,0 @@ -#![feature(custom_inner_attributes)] -#![clippy::msrv = "invalid.version"] - -fn main() {} diff --git a/tests/ui/min_rust_version_invalid_attr.stderr b/tests/ui/min_rust_version_invalid_attr.stderr deleted file mode 100644 index 6ff88ca56f8b..000000000000 --- a/tests/ui/min_rust_version_invalid_attr.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: `invalid.version` is not a valid Rust version - --> $DIR/min_rust_version_invalid_attr.rs:2:1 - | -LL | #![clippy::msrv = "invalid.version"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/tests/ui/min_rust_version_multiple_inner_attr.rs b/tests/ui/min_rust_version_multiple_inner_attr.rs deleted file mode 100644 index e882d5ccf91a..000000000000 --- a/tests/ui/min_rust_version_multiple_inner_attr.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![feature(custom_inner_attributes)] -#![clippy::msrv = "1.40"] -#![clippy::msrv = "=1.35.0"] -#![clippy::msrv = "1.10.1"] - -mod foo { - #![clippy::msrv = "1"] - #![clippy::msrv = "1.0.0"] -} - -fn main() {} diff --git a/tests/ui/min_rust_version_multiple_inner_attr.stderr b/tests/ui/min_rust_version_multiple_inner_attr.stderr deleted file mode 100644 index e3ff6605cde8..000000000000 --- a/tests/ui/min_rust_version_multiple_inner_attr.stderr +++ /dev/null @@ -1,38 +0,0 @@ -error: `msrv` is defined multiple times - --> $DIR/min_rust_version_multiple_inner_attr.rs:3:1 - | -LL | #![clippy::msrv = "=1.35.0"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: first definition found here - --> $DIR/min_rust_version_multiple_inner_attr.rs:2:1 - | -LL | #![clippy::msrv = "1.40"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: `msrv` is defined multiple times - --> $DIR/min_rust_version_multiple_inner_attr.rs:4:1 - | -LL | #![clippy::msrv = "1.10.1"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: first definition found here - --> $DIR/min_rust_version_multiple_inner_attr.rs:2:1 - | -LL | #![clippy::msrv = "1.40"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: `msrv` is defined multiple times - --> $DIR/min_rust_version_multiple_inner_attr.rs:8:5 - | -LL | #![clippy::msrv = "1.0.0"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: first definition found here - --> $DIR/min_rust_version_multiple_inner_attr.rs:7:5 - | -LL | #![clippy::msrv = "1"] - | ^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/min_rust_version_no_patch.rs b/tests/ui/min_rust_version_no_patch.rs deleted file mode 100644 index 98fffe1e3512..000000000000 --- a/tests/ui/min_rust_version_no_patch.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![allow(clippy::redundant_clone)] -#![feature(custom_inner_attributes)] -#![clippy::msrv = "1.0"] - -fn manual_strip_msrv() { - let s = "hello, world!"; - if s.starts_with("hello, ") { - assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!"); - } -} - -fn main() { - manual_strip_msrv() -} diff --git a/tests/ui/min_rust_version_outer_attr.rs b/tests/ui/min_rust_version_outer_attr.rs deleted file mode 100644 index 551948bd72ef..000000000000 --- a/tests/ui/min_rust_version_outer_attr.rs +++ /dev/null @@ -1,4 +0,0 @@ -#![feature(custom_inner_attributes)] - -#[clippy::msrv = "invalid.version"] -fn main() {} diff --git a/tests/ui/min_rust_version_outer_attr.stderr b/tests/ui/min_rust_version_outer_attr.stderr deleted file mode 100644 index 579ee7a87d23..000000000000 --- a/tests/ui/min_rust_version_outer_attr.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: `msrv` cannot be an outer attribute - --> $DIR/min_rust_version_outer_attr.rs:3:1 - | -LL | #[clippy::msrv = "invalid.version"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/tests/ui/mismatched_target_os_non_unix.fixed b/tests/ui/mismatched_target_os_non_unix.fixed deleted file mode 100644 index f219a570e7fc..000000000000 --- a/tests/ui/mismatched_target_os_non_unix.fixed +++ /dev/null @@ -1,27 +0,0 @@ -// run-rustfix - -#![warn(clippy::mismatched_target_os)] -#![allow(unused)] - -#[cfg(target_os = "hermit")] -fn hermit() {} - -#[cfg(target_os = "wasi")] -fn wasi() {} - -#[cfg(target_os = "none")] -fn none() {} - -// list with conditions -#[cfg(all(not(windows), target_os = "wasi"))] -fn list() {} - -// windows is a valid target family, should be ignored -#[cfg(windows)] -fn windows() {} - -// correct use, should be ignored -#[cfg(target_os = "hermit")] -fn correct() {} - -fn main() {} diff --git a/tests/ui/mismatched_target_os_non_unix.rs b/tests/ui/mismatched_target_os_non_unix.rs deleted file mode 100644 index 8a8ae756a4fc..000000000000 --- a/tests/ui/mismatched_target_os_non_unix.rs +++ /dev/null @@ -1,27 +0,0 @@ -// run-rustfix - -#![warn(clippy::mismatched_target_os)] -#![allow(unused)] - -#[cfg(hermit)] -fn hermit() {} - -#[cfg(wasi)] -fn wasi() {} - -#[cfg(none)] -fn none() {} - -// list with conditions -#[cfg(all(not(windows), wasi))] -fn list() {} - -// windows is a valid target family, should be ignored -#[cfg(windows)] -fn windows() {} - -// correct use, should be ignored -#[cfg(target_os = "hermit")] -fn correct() {} - -fn main() {} diff --git a/tests/ui/mismatched_target_os_non_unix.stderr b/tests/ui/mismatched_target_os_non_unix.stderr deleted file mode 100644 index 5f1b09083046..000000000000 --- a/tests/ui/mismatched_target_os_non_unix.stderr +++ /dev/null @@ -1,36 +0,0 @@ -error: operating system used in target family position - --> $DIR/mismatched_target_os_non_unix.rs:6:1 - | -LL | #[cfg(hermit)] - | ^^^^^^------^^ - | | - | help: try: `target_os = "hermit"` - | - = note: `-D clippy::mismatched-target-os` implied by `-D warnings` - -error: operating system used in target family position - --> $DIR/mismatched_target_os_non_unix.rs:9:1 - | -LL | #[cfg(wasi)] - | ^^^^^^----^^ - | | - | help: try: `target_os = "wasi"` - -error: operating system used in target family position - --> $DIR/mismatched_target_os_non_unix.rs:12:1 - | -LL | #[cfg(none)] - | ^^^^^^----^^ - | | - | help: try: `target_os = "none"` - -error: operating system used in target family position - --> $DIR/mismatched_target_os_non_unix.rs:16:1 - | -LL | #[cfg(all(not(windows), wasi))] - | ^^^^^^^^^^^^^^^^^^^^^^^^----^^^ - | | - | help: try: `target_os = "wasi"` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/mismatched_target_os_unix.fixed b/tests/ui/mismatched_target_os_unix.fixed deleted file mode 100644 index 7d9d406d99df..000000000000 --- a/tests/ui/mismatched_target_os_unix.fixed +++ /dev/null @@ -1,62 +0,0 @@ -// run-rustfix - -#![warn(clippy::mismatched_target_os)] -#![allow(unused)] - -#[cfg(target_os = "linux")] -fn linux() {} - -#[cfg(target_os = "freebsd")] -fn freebsd() {} - -#[cfg(target_os = "dragonfly")] -fn dragonfly() {} - -#[cfg(target_os = "openbsd")] -fn openbsd() {} - -#[cfg(target_os = "netbsd")] -fn netbsd() {} - -#[cfg(target_os = "macos")] -fn macos() {} - -#[cfg(target_os = "ios")] -fn ios() {} - -#[cfg(target_os = "android")] -fn android() {} - -#[cfg(target_os = "emscripten")] -fn emscripten() {} - -#[cfg(target_os = "fuchsia")] -fn fuchsia() {} - -#[cfg(target_os = "haiku")] -fn haiku() {} - -#[cfg(target_os = "illumos")] -fn illumos() {} - -#[cfg(target_os = "l4re")] -fn l4re() {} - -#[cfg(target_os = "redox")] -fn redox() {} - -#[cfg(target_os = "solaris")] -fn solaris() {} - -#[cfg(target_os = "vxworks")] -fn vxworks() {} - -// list with conditions -#[cfg(all(not(any(target_os = "solaris", target_os = "linux")), target_os = "freebsd"))] -fn list() {} - -// correct use, should be ignored -#[cfg(target_os = "freebsd")] -fn correct() {} - -fn main() {} diff --git a/tests/ui/mismatched_target_os_unix.rs b/tests/ui/mismatched_target_os_unix.rs deleted file mode 100644 index c1177f1eedc6..000000000000 --- a/tests/ui/mismatched_target_os_unix.rs +++ /dev/null @@ -1,62 +0,0 @@ -// run-rustfix - -#![warn(clippy::mismatched_target_os)] -#![allow(unused)] - -#[cfg(linux)] -fn linux() {} - -#[cfg(freebsd)] -fn freebsd() {} - -#[cfg(dragonfly)] -fn dragonfly() {} - -#[cfg(openbsd)] -fn openbsd() {} - -#[cfg(netbsd)] -fn netbsd() {} - -#[cfg(macos)] -fn macos() {} - -#[cfg(ios)] -fn ios() {} - -#[cfg(android)] -fn android() {} - -#[cfg(emscripten)] -fn emscripten() {} - -#[cfg(fuchsia)] -fn fuchsia() {} - -#[cfg(haiku)] -fn haiku() {} - -#[cfg(illumos)] -fn illumos() {} - -#[cfg(l4re)] -fn l4re() {} - -#[cfg(redox)] -fn redox() {} - -#[cfg(solaris)] -fn solaris() {} - -#[cfg(vxworks)] -fn vxworks() {} - -// list with conditions -#[cfg(all(not(any(solaris, linux)), freebsd))] -fn list() {} - -// correct use, should be ignored -#[cfg(target_os = "freebsd")] -fn correct() {} - -fn main() {} diff --git a/tests/ui/mismatched_target_os_unix.stderr b/tests/ui/mismatched_target_os_unix.stderr deleted file mode 100644 index fe9aeedb59c4..000000000000 --- a/tests/ui/mismatched_target_os_unix.stderr +++ /dev/null @@ -1,183 +0,0 @@ -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:6:1 - | -LL | #[cfg(linux)] - | ^^^^^^-----^^ - | | - | help: try: `target_os = "linux"` - | - = note: `-D clippy::mismatched-target-os` implied by `-D warnings` - = help: Did you mean `unix`? - -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:9:1 - | -LL | #[cfg(freebsd)] - | ^^^^^^-------^^ - | | - | help: try: `target_os = "freebsd"` - | - = help: Did you mean `unix`? - -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:12:1 - | -LL | #[cfg(dragonfly)] - | ^^^^^^---------^^ - | | - | help: try: `target_os = "dragonfly"` - | - = help: Did you mean `unix`? - -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:15:1 - | -LL | #[cfg(openbsd)] - | ^^^^^^-------^^ - | | - | help: try: `target_os = "openbsd"` - | - = help: Did you mean `unix`? - -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:18:1 - | -LL | #[cfg(netbsd)] - | ^^^^^^------^^ - | | - | help: try: `target_os = "netbsd"` - | - = help: Did you mean `unix`? - -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:21:1 - | -LL | #[cfg(macos)] - | ^^^^^^-----^^ - | | - | help: try: `target_os = "macos"` - | - = help: Did you mean `unix`? - -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:24:1 - | -LL | #[cfg(ios)] - | ^^^^^^---^^ - | | - | help: try: `target_os = "ios"` - | - = help: Did you mean `unix`? - -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:27:1 - | -LL | #[cfg(android)] - | ^^^^^^-------^^ - | | - | help: try: `target_os = "android"` - | - = help: Did you mean `unix`? - -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:30:1 - | -LL | #[cfg(emscripten)] - | ^^^^^^----------^^ - | | - | help: try: `target_os = "emscripten"` - | - = help: Did you mean `unix`? - -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:33:1 - | -LL | #[cfg(fuchsia)] - | ^^^^^^-------^^ - | | - | help: try: `target_os = "fuchsia"` - | - = help: Did you mean `unix`? - -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:36:1 - | -LL | #[cfg(haiku)] - | ^^^^^^-----^^ - | | - | help: try: `target_os = "haiku"` - | - = help: Did you mean `unix`? - -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:39:1 - | -LL | #[cfg(illumos)] - | ^^^^^^-------^^ - | | - | help: try: `target_os = "illumos"` - | - = help: Did you mean `unix`? - -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:42:1 - | -LL | #[cfg(l4re)] - | ^^^^^^----^^ - | | - | help: try: `target_os = "l4re"` - | - = help: Did you mean `unix`? - -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:45:1 - | -LL | #[cfg(redox)] - | ^^^^^^-----^^ - | | - | help: try: `target_os = "redox"` - | - = help: Did you mean `unix`? - -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:48:1 - | -LL | #[cfg(solaris)] - | ^^^^^^-------^^ - | | - | help: try: `target_os = "solaris"` - | - = help: Did you mean `unix`? - -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:51:1 - | -LL | #[cfg(vxworks)] - | ^^^^^^-------^^ - | | - | help: try: `target_os = "vxworks"` - | - = help: Did you mean `unix`? - -error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:55:1 - | -LL | #[cfg(all(not(any(solaris, linux)), freebsd))] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: Did you mean `unix`? -help: try - | -LL | #[cfg(all(not(any(target_os = "solaris", linux)), freebsd))] - | ^^^^^^^^^^^^^^^^^^^^^ -help: try - | -LL | #[cfg(all(not(any(solaris, target_os = "linux")), freebsd))] - | ^^^^^^^^^^^^^^^^^^^ -help: try - | -LL | #[cfg(all(not(any(solaris, linux)), target_os = "freebsd"))] - | ^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 17 previous errors - diff --git a/tests/ui/missing-doc-crate-missing.rs b/tests/ui/missing-doc-crate-missing.rs deleted file mode 100644 index 51fd57df8df1..000000000000 --- a/tests/ui/missing-doc-crate-missing.rs +++ /dev/null @@ -1,3 +0,0 @@ -#![warn(clippy::missing_docs_in_private_items)] - -fn main() {} diff --git a/tests/ui/missing-doc-crate-missing.stderr b/tests/ui/missing-doc-crate-missing.stderr deleted file mode 100644 index d56c5cc4c3ae..000000000000 --- a/tests/ui/missing-doc-crate-missing.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error: missing documentation for the crate - --> $DIR/missing-doc-crate-missing.rs:1:1 - | -LL | / #![warn(clippy::missing_docs_in_private_items)] -LL | | -LL | | fn main() {} - | |____________^ - | - = note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/missing-doc-crate.rs b/tests/ui/missing-doc-crate.rs deleted file mode 100644 index 04711f864886..000000000000 --- a/tests/ui/missing-doc-crate.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![warn(clippy::missing_docs_in_private_items)] -#![feature(external_doc)] -#![doc(include = "../../README.md")] - -fn main() {} diff --git a/tests/ui/missing-doc-crate.stderr b/tests/ui/missing-doc-crate.stderr deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/tests/ui/missing-doc-impl.rs b/tests/ui/missing-doc-impl.rs deleted file mode 100644 index 57af84dcdf4d..000000000000 --- a/tests/ui/missing-doc-impl.rs +++ /dev/null @@ -1,87 +0,0 @@ -#![warn(clippy::missing_docs_in_private_items)] -#![allow(dead_code)] -#![feature(associated_type_defaults)] - -//! Some garbage docs for the crate here -#![doc = "More garbage"] - -struct Foo { - a: isize, - b: isize, -} - -pub struct PubFoo { - pub a: isize, - b: isize, -} - -#[allow(clippy::missing_docs_in_private_items)] -pub struct PubFoo2 { - pub a: isize, - pub c: isize, -} - -/// dox -pub trait A { - /// dox - fn foo(&self); - /// dox - fn foo_with_impl(&self) {} -} - -#[allow(clippy::missing_docs_in_private_items)] -trait B { - fn foo(&self); - fn foo_with_impl(&self) {} -} - -pub trait C { - fn foo(&self); - fn foo_with_impl(&self) {} -} - -#[allow(clippy::missing_docs_in_private_items)] -pub trait D { - fn dummy(&self) {} -} - -/// dox -pub trait E: Sized { - type AssociatedType; - type AssociatedTypeDef = Self; - - /// dox - type DocumentedType; - /// dox - type DocumentedTypeDef = Self; - /// dox - fn dummy(&self) {} -} - -impl Foo { - pub fn foo() {} - fn bar() {} -} - -impl PubFoo { - pub fn foo() {} - /// dox - pub fn foo1() {} - fn foo2() {} - #[allow(clippy::missing_docs_in_private_items)] - pub fn foo3() {} -} - -#[allow(clippy::missing_docs_in_private_items)] -trait F { - fn a(); - fn b(&self); -} - -// should need to redefine documentation for implementations of traits -impl F for Foo { - fn a() {} - fn b(&self) {} -} - -fn main() {} diff --git a/tests/ui/missing-doc-impl.stderr b/tests/ui/missing-doc-impl.stderr deleted file mode 100644 index 7e10404ca005..000000000000 --- a/tests/ui/missing-doc-impl.stderr +++ /dev/null @@ -1,103 +0,0 @@ -error: missing documentation for a struct - --> $DIR/missing-doc-impl.rs:8:1 - | -LL | / struct Foo { -LL | | a: isize, -LL | | b: isize, -LL | | } - | |_^ - | - = note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` - -error: missing documentation for a struct field - --> $DIR/missing-doc-impl.rs:9:5 - | -LL | a: isize, - | ^^^^^^^^ - -error: missing documentation for a struct field - --> $DIR/missing-doc-impl.rs:10:5 - | -LL | b: isize, - | ^^^^^^^^ - -error: missing documentation for a struct - --> $DIR/missing-doc-impl.rs:13:1 - | -LL | / pub struct PubFoo { -LL | | pub a: isize, -LL | | b: isize, -LL | | } - | |_^ - -error: missing documentation for a struct field - --> $DIR/missing-doc-impl.rs:14:5 - | -LL | pub a: isize, - | ^^^^^^^^^^^^ - -error: missing documentation for a struct field - --> $DIR/missing-doc-impl.rs:15:5 - | -LL | b: isize, - | ^^^^^^^^ - -error: missing documentation for a trait - --> $DIR/missing-doc-impl.rs:38:1 - | -LL | / pub trait C { -LL | | fn foo(&self); -LL | | fn foo_with_impl(&self) {} -LL | | } - | |_^ - -error: missing documentation for an associated function - --> $DIR/missing-doc-impl.rs:39:5 - | -LL | fn foo(&self); - | ^^^^^^^^^^^^^^ - -error: missing documentation for an associated function - --> $DIR/missing-doc-impl.rs:40:5 - | -LL | fn foo_with_impl(&self) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for an associated type - --> $DIR/missing-doc-impl.rs:50:5 - | -LL | type AssociatedType; - | ^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for an associated type - --> $DIR/missing-doc-impl.rs:51:5 - | -LL | type AssociatedTypeDef = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for an associated function - --> $DIR/missing-doc-impl.rs:62:5 - | -LL | pub fn foo() {} - | ^^^^^^^^^^^^^^^ - -error: missing documentation for an associated function - --> $DIR/missing-doc-impl.rs:63:5 - | -LL | fn bar() {} - | ^^^^^^^^^^^ - -error: missing documentation for an associated function - --> $DIR/missing-doc-impl.rs:67:5 - | -LL | pub fn foo() {} - | ^^^^^^^^^^^^^^^ - -error: missing documentation for an associated function - --> $DIR/missing-doc-impl.rs:70:5 - | -LL | fn foo2() {} - | ^^^^^^^^^^^^ - -error: aborting due to 15 previous errors - diff --git a/tests/ui/missing-doc.rs b/tests/ui/missing-doc.rs deleted file mode 100644 index a9bf7140a1e5..000000000000 --- a/tests/ui/missing-doc.rs +++ /dev/null @@ -1,102 +0,0 @@ -#![warn(clippy::missing_docs_in_private_items)] -// When denying at the crate level, be sure to not get random warnings from the -// injected intrinsics by the compiler. -#![allow(dead_code)] -#![feature(global_asm)] - -//! Some garbage docs for the crate here -#![doc = "More garbage"] - -type Typedef = String; -pub type PubTypedef = String; - -mod module_no_dox {} -pub mod pub_module_no_dox {} - -/// dox -pub fn foo() {} -pub fn foo2() {} -fn foo3() {} -#[allow(clippy::missing_docs_in_private_items)] -pub fn foo4() {} - -// It sure is nice if doc(hidden) implies allow(missing_docs), and that it -// applies recursively -#[doc(hidden)] -mod a { - pub fn baz() {} - pub mod b { - pub fn baz() {} - } -} - -enum Baz { - BazA { a: isize, b: isize }, - BarB, -} - -pub enum PubBaz { - PubBazA { a: isize }, -} - -/// dox -pub enum PubBaz2 { - /// dox - PubBaz2A { - /// dox - a: isize, - }, -} - -#[allow(clippy::missing_docs_in_private_items)] -pub enum PubBaz3 { - PubBaz3A { b: isize }, -} - -#[doc(hidden)] -pub fn baz() {} - -const FOO: u32 = 0; -/// dox -pub const FOO1: u32 = 0; -#[allow(clippy::missing_docs_in_private_items)] -pub const FOO2: u32 = 0; -#[doc(hidden)] -pub const FOO3: u32 = 0; -pub const FOO4: u32 = 0; - -static BAR: u32 = 0; -/// dox -pub static BAR1: u32 = 0; -#[allow(clippy::missing_docs_in_private_items)] -pub static BAR2: u32 = 0; -#[doc(hidden)] -pub static BAR3: u32 = 0; -pub static BAR4: u32 = 0; - -mod internal_impl { - /// dox - pub fn documented() {} - pub fn undocumented1() {} - pub fn undocumented2() {} - fn undocumented3() {} - /// dox - pub mod globbed { - /// dox - pub fn also_documented() {} - pub fn also_undocumented1() {} - fn also_undocumented2() {} - } -} -/// dox -pub mod public_interface { - pub use internal_impl::documented as foo; - pub use internal_impl::globbed::*; - pub use internal_impl::undocumented1 as bar; - pub use internal_impl::{documented, undocumented2}; -} - -fn main() {} - -// Ensure global asm doesn't require documentation. -global_asm! { "" } diff --git a/tests/ui/missing-doc.stderr b/tests/ui/missing-doc.stderr deleted file mode 100644 index a876dc078ebf..000000000000 --- a/tests/ui/missing-doc.stderr +++ /dev/null @@ -1,159 +0,0 @@ -error: missing documentation for a type alias - --> $DIR/missing-doc.rs:10:1 - | -LL | type Typedef = String; - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` - -error: missing documentation for a type alias - --> $DIR/missing-doc.rs:11:1 - | -LL | pub type PubTypedef = String; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for a module - --> $DIR/missing-doc.rs:13:1 - | -LL | mod module_no_dox {} - | ^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for a module - --> $DIR/missing-doc.rs:14:1 - | -LL | pub mod pub_module_no_dox {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for a function - --> $DIR/missing-doc.rs:18:1 - | -LL | pub fn foo2() {} - | ^^^^^^^^^^^^^^^^ - -error: missing documentation for a function - --> $DIR/missing-doc.rs:19:1 - | -LL | fn foo3() {} - | ^^^^^^^^^^^^ - -error: missing documentation for an enum - --> $DIR/missing-doc.rs:33:1 - | -LL | / enum Baz { -LL | | BazA { a: isize, b: isize }, -LL | | BarB, -LL | | } - | |_^ - -error: missing documentation for a variant - --> $DIR/missing-doc.rs:34:5 - | -LL | BazA { a: isize, b: isize }, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for a struct field - --> $DIR/missing-doc.rs:34:12 - | -LL | BazA { a: isize, b: isize }, - | ^^^^^^^^ - -error: missing documentation for a struct field - --> $DIR/missing-doc.rs:34:22 - | -LL | BazA { a: isize, b: isize }, - | ^^^^^^^^ - -error: missing documentation for a variant - --> $DIR/missing-doc.rs:35:5 - | -LL | BarB, - | ^^^^ - -error: missing documentation for an enum - --> $DIR/missing-doc.rs:38:1 - | -LL | / pub enum PubBaz { -LL | | PubBazA { a: isize }, -LL | | } - | |_^ - -error: missing documentation for a variant - --> $DIR/missing-doc.rs:39:5 - | -LL | PubBazA { a: isize }, - | ^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for a struct field - --> $DIR/missing-doc.rs:39:15 - | -LL | PubBazA { a: isize }, - | ^^^^^^^^ - -error: missing documentation for a constant - --> $DIR/missing-doc.rs:59:1 - | -LL | const FOO: u32 = 0; - | ^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for a constant - --> $DIR/missing-doc.rs:66:1 - | -LL | pub const FOO4: u32 = 0; - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for a static - --> $DIR/missing-doc.rs:68:1 - | -LL | static BAR: u32 = 0; - | ^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for a static - --> $DIR/missing-doc.rs:75:1 - | -LL | pub static BAR4: u32 = 0; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for a module - --> $DIR/missing-doc.rs:77:1 - | -LL | / mod internal_impl { -LL | | /// dox -LL | | pub fn documented() {} -LL | | pub fn undocumented1() {} -... | -LL | | } -LL | | } - | |_^ - -error: missing documentation for a function - --> $DIR/missing-doc.rs:80:5 - | -LL | pub fn undocumented1() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for a function - --> $DIR/missing-doc.rs:81:5 - | -LL | pub fn undocumented2() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for a function - --> $DIR/missing-doc.rs:82:5 - | -LL | fn undocumented3() {} - | ^^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for a function - --> $DIR/missing-doc.rs:87:9 - | -LL | pub fn also_undocumented1() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: missing documentation for a function - --> $DIR/missing-doc.rs:88:9 - | -LL | fn also_undocumented2() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 24 previous errors - diff --git a/tests/ui/missing_const_for_fn/cant_be_const.rs b/tests/ui/missing_const_for_fn/cant_be_const.rs deleted file mode 100644 index ba352ef9ee93..000000000000 --- a/tests/ui/missing_const_for_fn/cant_be_const.rs +++ /dev/null @@ -1,103 +0,0 @@ -//! False-positive tests to ensure we don't suggest `const` for things where it would cause a -//! compilation error. -//! The .stderr output of this test should be empty. Otherwise it's a bug somewhere. - -#![warn(clippy::missing_const_for_fn)] -#![allow(incomplete_features)] -#![feature(start, const_generics)] - -struct Game; - -// This should not be linted because it's already const -const fn already_const() -> i32 { - 32 -} - -impl Game { - // This should not be linted because it's already const - pub const fn already_const() -> i32 { - 32 - } -} - -// Allowing on this function, because it would lint, which we don't want in this case. -#[allow(clippy::missing_const_for_fn)] -fn random() -> u32 { - 42 -} - -// We should not suggest to make this function `const` because `random()` is non-const -fn random_caller() -> u32 { - random() -} - -static Y: u32 = 0; - -// We should not suggest to make this function `const` because const functions are not allowed to -// refer to a static variable -fn get_y() -> u32 { - Y - //~^ ERROR E0013 -} - -// Don't lint entrypoint functions -#[start] -fn init(num: isize, something: *const *const u8) -> isize { - 1 -} - -trait Foo { - // This should not be suggested to be made const - // (rustc doesn't allow const trait methods) - fn f() -> u32; - - // This should not be suggested to be made const either - fn g() -> u32 { - 33 - } -} - -// Don't lint in external macros (derive) -#[derive(PartialEq, Eq)] -struct Point(isize, isize); - -impl std::ops::Add for Point { - type Output = Self; - - // Don't lint in trait impls of derived methods - fn add(self, other: Self) -> Self { - Point(self.0 + other.0, self.1 + other.1) - } -} - -mod with_drop { - pub struct A; - pub struct B; - impl Drop for A { - fn drop(&mut self) {} - } - - impl A { - // This can not be const because the type implements `Drop`. - pub fn a(self) -> B { - B - } - } - - impl B { - // This can not be const because `a` implements `Drop`. - pub fn a(self, a: A) -> B { - B - } - } -} - -fn const_generic_params(t: &[T; N]) -> &[T; N] { - t -} - -fn const_generic_return(t: &[T]) -> &[T; N] { - let p = t.as_ptr() as *const [T; N]; - - unsafe { &*p } -} diff --git a/tests/ui/missing_const_for_fn/cant_be_const.stderr b/tests/ui/missing_const_for_fn/cant_be_const.stderr deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/tests/ui/missing_const_for_fn/could_be_const.rs b/tests/ui/missing_const_for_fn/could_be_const.rs deleted file mode 100644 index c6f44b7daa34..000000000000 --- a/tests/ui/missing_const_for_fn/could_be_const.rs +++ /dev/null @@ -1,74 +0,0 @@ -#![warn(clippy::missing_const_for_fn)] -#![allow(incomplete_features, clippy::let_and_return)] -#![feature(const_generics)] - -use std::mem::transmute; - -struct Game { - guess: i32, -} - -impl Game { - // Could be const - pub fn new() -> Self { - Self { guess: 42 } - } - - fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] { - b - } -} - -// Could be const -fn one() -> i32 { - 1 -} - -// Could also be const -fn two() -> i32 { - let abc = 2; - abc -} - -// Could be const (since Rust 1.39) -fn string() -> String { - String::new() -} - -// Could be const -unsafe fn four() -> i32 { - 4 -} - -// Could also be const -fn generic(t: T) -> T { - t -} - -fn sub(x: u32) -> usize { - unsafe { transmute(&x) } -} - -// NOTE: This is currently not yet allowed to be const -// Once implemented, Clippy should be able to suggest this as const, too. -fn generic_arr(t: [T; 1]) -> T { - t[0] -} - -mod with_drop { - pub struct A; - pub struct B; - impl Drop for A { - fn drop(&mut self) {} - } - - impl B { - // This can be const, because `a` is passed by reference - pub fn b(self, a: &A) -> B { - B - } - } -} - -// Should not be const -fn main() {} diff --git a/tests/ui/missing_const_for_fn/could_be_const.stderr b/tests/ui/missing_const_for_fn/could_be_const.stderr deleted file mode 100644 index 74d32b8a1aa9..000000000000 --- a/tests/ui/missing_const_for_fn/could_be_const.stderr +++ /dev/null @@ -1,69 +0,0 @@ -error: this could be a `const fn` - --> $DIR/could_be_const.rs:13:5 - | -LL | / pub fn new() -> Self { -LL | | Self { guess: 42 } -LL | | } - | |_____^ - | - = note: `-D clippy::missing-const-for-fn` implied by `-D warnings` - -error: this could be a `const fn` - --> $DIR/could_be_const.rs:17:5 - | -LL | / fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] { -LL | | b -LL | | } - | |_____^ - -error: this could be a `const fn` - --> $DIR/could_be_const.rs:23:1 - | -LL | / fn one() -> i32 { -LL | | 1 -LL | | } - | |_^ - -error: this could be a `const fn` - --> $DIR/could_be_const.rs:28:1 - | -LL | / fn two() -> i32 { -LL | | let abc = 2; -LL | | abc -LL | | } - | |_^ - -error: this could be a `const fn` - --> $DIR/could_be_const.rs:34:1 - | -LL | / fn string() -> String { -LL | | String::new() -LL | | } - | |_^ - -error: this could be a `const fn` - --> $DIR/could_be_const.rs:39:1 - | -LL | / unsafe fn four() -> i32 { -LL | | 4 -LL | | } - | |_^ - -error: this could be a `const fn` - --> $DIR/could_be_const.rs:44:1 - | -LL | / fn generic(t: T) -> T { -LL | | t -LL | | } - | |_^ - -error: this could be a `const fn` - --> $DIR/could_be_const.rs:67:9 - | -LL | / pub fn b(self, a: &A) -> B { -LL | | B -LL | | } - | |_________^ - -error: aborting due to 8 previous errors - diff --git a/tests/ui/missing_inline.rs b/tests/ui/missing_inline.rs deleted file mode 100644 index b73b24b8e0a3..000000000000 --- a/tests/ui/missing_inline.rs +++ /dev/null @@ -1,66 +0,0 @@ -#![warn(clippy::missing_inline_in_public_items)] -#![crate_type = "dylib"] -// When denying at the crate level, be sure to not get random warnings from the -// injected intrinsics by the compiler. -#![allow(dead_code, non_snake_case)] - -type Typedef = String; -pub type PubTypedef = String; - -struct Foo {} // ok -pub struct PubFoo {} // ok -enum FooE {} // ok -pub enum PubFooE {} // ok - -mod module {} // ok -pub mod pub_module {} // ok - -fn foo() {} -pub fn pub_foo() {} // missing #[inline] -#[inline] -pub fn pub_foo_inline() {} // ok -#[inline(always)] -pub fn pub_foo_inline_always() {} // ok - -#[allow(clippy::missing_inline_in_public_items)] -pub fn pub_foo_no_inline() {} - -trait Bar { - fn Bar_a(); // ok - fn Bar_b() {} // ok -} - -pub trait PubBar { - fn PubBar_a(); // ok - fn PubBar_b() {} // missing #[inline] - #[inline] - fn PubBar_c() {} // ok -} - -// none of these need inline because Foo is not exported -impl PubBar for Foo { - fn PubBar_a() {} // ok - fn PubBar_b() {} // ok - fn PubBar_c() {} // ok -} - -// all of these need inline because PubFoo is exported -impl PubBar for PubFoo { - fn PubBar_a() {} // missing #[inline] - fn PubBar_b() {} // missing #[inline] - fn PubBar_c() {} // missing #[inline] -} - -// do not need inline because Foo is not exported -impl Foo { - fn FooImpl() {} // ok -} - -// need inline because PubFoo is exported -impl PubFoo { - pub fn PubFooImpl() {} // missing #[inline] -} - -// do not lint this since users cannot control the external code -#[derive(Debug)] -pub struct S {} diff --git a/tests/ui/missing_inline.stderr b/tests/ui/missing_inline.stderr deleted file mode 100644 index 40b92b7647bf..000000000000 --- a/tests/ui/missing_inline.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: missing `#[inline]` for a function - --> $DIR/missing_inline.rs:19:1 - | -LL | pub fn pub_foo() {} // missing #[inline] - | ^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::missing-inline-in-public-items` implied by `-D warnings` - -error: missing `#[inline]` for a default trait method - --> $DIR/missing_inline.rs:35:5 - | -LL | fn PubBar_b() {} // missing #[inline] - | ^^^^^^^^^^^^^^^^ - -error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:49:5 - | -LL | fn PubBar_a() {} // missing #[inline] - | ^^^^^^^^^^^^^^^^ - -error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:50:5 - | -LL | fn PubBar_b() {} // missing #[inline] - | ^^^^^^^^^^^^^^^^ - -error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:51:5 - | -LL | fn PubBar_c() {} // missing #[inline] - | ^^^^^^^^^^^^^^^^ - -error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:61:5 - | -LL | pub fn PubFooImpl() {} // missing #[inline] - | ^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/mistyped_literal_suffix.fixed b/tests/ui/mistyped_literal_suffix.fixed deleted file mode 100644 index 70cdb067d913..000000000000 --- a/tests/ui/mistyped_literal_suffix.fixed +++ /dev/null @@ -1,29 +0,0 @@ -// run-rustfix - -#![allow( - dead_code, - unused_variables, - clippy::excessive_precision, - clippy::inconsistent_digit_grouping -)] - -fn main() { - let fail14 = 2_i32; - let fail15 = 4_i64; - let fail16 = 7_i8; // - let fail17 = 23_i16; // - let ok18 = 23_128; - - let fail20 = 2_i8; // - let fail21 = 4_i16; // - - let ok24 = 12.34_64; - let fail25 = 1E2_f32; - let fail26 = 43E7_f64; - let fail27 = 243E17_f32; - #[allow(overflowing_literals)] - let fail28 = 241_251_235E723_f64; - let ok29 = 42279.911_32; - - let _ = 1.123_45E1_f32; -} diff --git a/tests/ui/mistyped_literal_suffix.rs b/tests/ui/mistyped_literal_suffix.rs deleted file mode 100644 index 729990af3998..000000000000 --- a/tests/ui/mistyped_literal_suffix.rs +++ /dev/null @@ -1,29 +0,0 @@ -// run-rustfix - -#![allow( - dead_code, - unused_variables, - clippy::excessive_precision, - clippy::inconsistent_digit_grouping -)] - -fn main() { - let fail14 = 2_32; - let fail15 = 4_64; - let fail16 = 7_8; // - let fail17 = 23_16; // - let ok18 = 23_128; - - let fail20 = 2__8; // - let fail21 = 4___16; // - - let ok24 = 12.34_64; - let fail25 = 1E2_32; - let fail26 = 43E7_64; - let fail27 = 243E17_32; - #[allow(overflowing_literals)] - let fail28 = 241251235E723_64; - let ok29 = 42279.911_32; - - let _ = 1.12345E1_32; -} diff --git a/tests/ui/mistyped_literal_suffix.stderr b/tests/ui/mistyped_literal_suffix.stderr deleted file mode 100644 index b338b8aa6228..000000000000 --- a/tests/ui/mistyped_literal_suffix.stderr +++ /dev/null @@ -1,70 +0,0 @@ -error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:11:18 - | -LL | let fail14 = 2_32; - | ^^^^ help: did you mean to write: `2_i32` - | - = note: `#[deny(clippy::mistyped_literal_suffixes)]` on by default - -error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:12:18 - | -LL | let fail15 = 4_64; - | ^^^^ help: did you mean to write: `4_i64` - -error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:13:18 - | -LL | let fail16 = 7_8; // - | ^^^ help: did you mean to write: `7_i8` - -error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:14:18 - | -LL | let fail17 = 23_16; // - | ^^^^^ help: did you mean to write: `23_i16` - -error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:17:18 - | -LL | let fail20 = 2__8; // - | ^^^^ help: did you mean to write: `2_i8` - -error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:18:18 - | -LL | let fail21 = 4___16; // - | ^^^^^^ help: did you mean to write: `4_i16` - -error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:21:18 - | -LL | let fail25 = 1E2_32; - | ^^^^^^ help: did you mean to write: `1E2_f32` - -error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:22:18 - | -LL | let fail26 = 43E7_64; - | ^^^^^^^ help: did you mean to write: `43E7_f64` - -error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:23:18 - | -LL | let fail27 = 243E17_32; - | ^^^^^^^^^ help: did you mean to write: `243E17_f32` - -error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:25:18 - | -LL | let fail28 = 241251235E723_64; - | ^^^^^^^^^^^^^^^^ help: did you mean to write: `241_251_235E723_f64` - -error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:28:13 - | -LL | let _ = 1.12345E1_32; - | ^^^^^^^^^^^^ help: did you mean to write: `1.123_45E1_f32` - -error: aborting due to 11 previous errors - diff --git a/tests/ui/module_inception.rs b/tests/ui/module_inception.rs deleted file mode 100644 index a23aba9164a5..000000000000 --- a/tests/ui/module_inception.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![warn(clippy::module_inception)] - -mod foo { - mod bar { - mod bar { - mod foo {} - } - mod foo {} - } - mod foo { - mod bar {} - } -} - -// No warning. See . -mod bar { - #[allow(clippy::module_inception)] - mod bar {} -} - -fn main() {} diff --git a/tests/ui/module_inception.stderr b/tests/ui/module_inception.stderr deleted file mode 100644 index 77564dce9eb4..000000000000 --- a/tests/ui/module_inception.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: module has the same name as its containing module - --> $DIR/module_inception.rs:5:9 - | -LL | / mod bar { -LL | | mod foo {} -LL | | } - | |_________^ - | - = note: `-D clippy::module-inception` implied by `-D warnings` - -error: module has the same name as its containing module - --> $DIR/module_inception.rs:10:5 - | -LL | / mod foo { -LL | | mod bar {} -LL | | } - | |_____^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/module_name_repetitions.rs b/tests/ui/module_name_repetitions.rs deleted file mode 100644 index 669bf01a84c1..000000000000 --- a/tests/ui/module_name_repetitions.rs +++ /dev/null @@ -1,26 +0,0 @@ -// compile-flags: --test - -#![warn(clippy::module_name_repetitions)] -#![allow(dead_code)] - -mod foo { - pub fn foo() {} - pub fn foo_bar() {} - pub fn bar_foo() {} - pub struct FooCake {} - pub enum CakeFoo {} - pub struct Foo7Bar; - - // Should not warn - pub struct Foobar; -} - -#[cfg(test)] -mod test { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } -} - -fn main() {} diff --git a/tests/ui/module_name_repetitions.stderr b/tests/ui/module_name_repetitions.stderr deleted file mode 100644 index bdd217a969c0..000000000000 --- a/tests/ui/module_name_repetitions.stderr +++ /dev/null @@ -1,34 +0,0 @@ -error: item name starts with its containing module's name - --> $DIR/module_name_repetitions.rs:8:5 - | -LL | pub fn foo_bar() {} - | ^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::module-name-repetitions` implied by `-D warnings` - -error: item name ends with its containing module's name - --> $DIR/module_name_repetitions.rs:9:5 - | -LL | pub fn bar_foo() {} - | ^^^^^^^^^^^^^^^^^^^ - -error: item name starts with its containing module's name - --> $DIR/module_name_repetitions.rs:10:5 - | -LL | pub struct FooCake {} - | ^^^^^^^^^^^^^^^^^^^^^ - -error: item name ends with its containing module's name - --> $DIR/module_name_repetitions.rs:11:5 - | -LL | pub enum CakeFoo {} - | ^^^^^^^^^^^^^^^^^^^ - -error: item name starts with its containing module's name - --> $DIR/module_name_repetitions.rs:12:5 - | -LL | pub struct Foo7Bar; - | ^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 5 previous errors - diff --git a/tests/ui/modulo_arithmetic_float.rs b/tests/ui/modulo_arithmetic_float.rs deleted file mode 100644 index b010b0dbdfa6..000000000000 --- a/tests/ui/modulo_arithmetic_float.rs +++ /dev/null @@ -1,36 +0,0 @@ -#![warn(clippy::modulo_arithmetic)] -#![allow( - unused, - clippy::shadow_reuse, - clippy::shadow_unrelated, - clippy::no_effect, - clippy::unnecessary_operation, - clippy::modulo_one -)] - -fn main() { - // Lint when both sides are const and of the opposite sign - -1.6 % 2.1; - 1.6 % -2.1; - (1.1 - 2.3) % (1.1 + 2.3); - (1.1 + 2.3) % (1.1 - 2.3); - - // Lint on floating point numbers - let a_f32: f32 = -1.6; - let mut b_f32: f32 = 2.1; - a_f32 % b_f32; - b_f32 % a_f32; - b_f32 %= a_f32; - - let a_f64: f64 = -1.6; - let mut b_f64: f64 = 2.1; - a_f64 % b_f64; - b_f64 % a_f64; - b_f64 %= a_f64; - - // No lint when both sides are const and of the same sign - 1.6 % 2.1; - -1.6 % -2.1; - (1.1 + 2.3) % (-1.1 + 2.3); - (-1.1 - 2.3) % (1.1 - 2.3); -} diff --git a/tests/ui/modulo_arithmetic_float.stderr b/tests/ui/modulo_arithmetic_float.stderr deleted file mode 100644 index 7bfdb0bde607..000000000000 --- a/tests/ui/modulo_arithmetic_float.stderr +++ /dev/null @@ -1,83 +0,0 @@ -error: you are using modulo operator on constants with different signs: `-1.600 % 2.100` - --> $DIR/modulo_arithmetic_float.rs:13:5 - | -LL | -1.6 % 2.1; - | ^^^^^^^^^^ - | - = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` - = note: double check for expected result especially when interoperating with different languages - -error: you are using modulo operator on constants with different signs: `1.600 % -2.100` - --> $DIR/modulo_arithmetic_float.rs:14:5 - | -LL | 1.6 % -2.1; - | ^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - -error: you are using modulo operator on constants with different signs: `-1.200 % 3.400` - --> $DIR/modulo_arithmetic_float.rs:15:5 - | -LL | (1.1 - 2.3) % (1.1 + 2.3); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - -error: you are using modulo operator on constants with different signs: `3.400 % -1.200` - --> $DIR/modulo_arithmetic_float.rs:16:5 - | -LL | (1.1 + 2.3) % (1.1 - 2.3); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:21:5 - | -LL | a_f32 % b_f32; - | ^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:22:5 - | -LL | b_f32 % a_f32; - | ^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:23:5 - | -LL | b_f32 %= a_f32; - | ^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:27:5 - | -LL | a_f64 % b_f64; - | ^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:28:5 - | -LL | b_f64 % a_f64; - | ^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:29:5 - | -LL | b_f64 %= a_f64; - | ^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - -error: aborting due to 10 previous errors - diff --git a/tests/ui/modulo_arithmetic_integral.rs b/tests/ui/modulo_arithmetic_integral.rs deleted file mode 100644 index 779d035c5f8a..000000000000 --- a/tests/ui/modulo_arithmetic_integral.rs +++ /dev/null @@ -1,90 +0,0 @@ -#![warn(clippy::modulo_arithmetic)] -#![allow( - unused, - clippy::shadow_reuse, - clippy::shadow_unrelated, - clippy::no_effect, - clippy::unnecessary_operation, - clippy::modulo_one -)] - -fn main() { - // Lint on signed integral numbers - let a = -1; - let mut b = 2; - a % b; - b % a; - b %= a; - - let a_i8: i8 = 1; - let mut b_i8: i8 = 2; - a_i8 % b_i8; - b_i8 %= a_i8; - - let a_i16: i16 = 1; - let mut b_i16: i16 = 2; - a_i16 % b_i16; - b_i16 %= a_i16; - - let a_i32: i32 = 1; - let mut b_i32: i32 = 2; - a_i32 % b_i32; - b_i32 %= a_i32; - - let a_i64: i64 = 1; - let mut b_i64: i64 = 2; - a_i64 % b_i64; - b_i64 %= a_i64; - - let a_i128: i128 = 1; - let mut b_i128: i128 = 2; - a_i128 % b_i128; - b_i128 %= a_i128; - - let a_isize: isize = 1; - let mut b_isize: isize = 2; - a_isize % b_isize; - b_isize %= a_isize; - - let a = 1; - let mut b = 2; - a % b; - b %= a; - - // No lint on unsigned integral value - let a_u8: u8 = 17; - let b_u8: u8 = 3; - a_u8 % b_u8; - let mut a_u8: u8 = 1; - a_u8 %= 2; - - let a_u16: u16 = 17; - let b_u16: u16 = 3; - a_u16 % b_u16; - let mut a_u16: u16 = 1; - a_u16 %= 2; - - let a_u32: u32 = 17; - let b_u32: u32 = 3; - a_u32 % b_u32; - let mut a_u32: u32 = 1; - a_u32 %= 2; - - let a_u64: u64 = 17; - let b_u64: u64 = 3; - a_u64 % b_u64; - let mut a_u64: u64 = 1; - a_u64 %= 2; - - let a_u128: u128 = 17; - let b_u128: u128 = 3; - a_u128 % b_u128; - let mut a_u128: u128 = 1; - a_u128 %= 2; - - let a_usize: usize = 17; - let b_usize: usize = 3; - a_usize % b_usize; - let mut a_usize: usize = 1; - a_usize %= 2; -} diff --git a/tests/ui/modulo_arithmetic_integral.stderr b/tests/ui/modulo_arithmetic_integral.stderr deleted file mode 100644 index e863b838699e..000000000000 --- a/tests/ui/modulo_arithmetic_integral.stderr +++ /dev/null @@ -1,156 +0,0 @@ -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:15:5 - | -LL | a % b; - | ^^^^^ - | - = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:16:5 - | -LL | b % a; - | ^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:17:5 - | -LL | b %= a; - | ^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:21:5 - | -LL | a_i8 % b_i8; - | ^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:22:5 - | -LL | b_i8 %= a_i8; - | ^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:26:5 - | -LL | a_i16 % b_i16; - | ^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:27:5 - | -LL | b_i16 %= a_i16; - | ^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:31:5 - | -LL | a_i32 % b_i32; - | ^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:32:5 - | -LL | b_i32 %= a_i32; - | ^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:36:5 - | -LL | a_i64 % b_i64; - | ^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:37:5 - | -LL | b_i64 %= a_i64; - | ^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:41:5 - | -LL | a_i128 % b_i128; - | ^^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:42:5 - | -LL | b_i128 %= a_i128; - | ^^^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:46:5 - | -LL | a_isize % b_isize; - | ^^^^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:47:5 - | -LL | b_isize %= a_isize; - | ^^^^^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:51:5 - | -LL | a % b; - | ^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:52:5 - | -LL | b %= a; - | ^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: aborting due to 17 previous errors - diff --git a/tests/ui/modulo_arithmetic_integral_const.rs b/tests/ui/modulo_arithmetic_integral_const.rs deleted file mode 100644 index 57a96692c009..000000000000 --- a/tests/ui/modulo_arithmetic_integral_const.rs +++ /dev/null @@ -1,44 +0,0 @@ -#![warn(clippy::modulo_arithmetic)] -#![allow( - unused, - clippy::shadow_reuse, - clippy::shadow_unrelated, - clippy::no_effect, - clippy::unnecessary_operation, - clippy::modulo_one -)] - -fn main() { - // Lint when both sides are const and of the opposite sign - -1 % 2; - 1 % -2; - (1 - 2) % (1 + 2); - (1 + 2) % (1 - 2); - 35 * (7 - 4 * 2) % (-500 * -600); - - -1i8 % 2i8; - 1i8 % -2i8; - -1i16 % 2i16; - 1i16 % -2i16; - -1i32 % 2i32; - 1i32 % -2i32; - -1i64 % 2i64; - 1i64 % -2i64; - -1i128 % 2i128; - 1i128 % -2i128; - -1isize % 2isize; - 1isize % -2isize; - - // No lint when both sides are const and of the same sign - 1 % 2; - -1 % -2; - (1 + 2) % (-1 + 2); - (-1 - 2) % (1 - 2); - - 1u8 % 2u8; - 1u16 % 2u16; - 1u32 % 2u32; - 1u64 % 2u64; - 1u128 % 2u128; - 1usize % 2usize; -} diff --git a/tests/ui/modulo_arithmetic_integral_const.stderr b/tests/ui/modulo_arithmetic_integral_const.stderr deleted file mode 100644 index de328bb75fe9..000000000000 --- a/tests/ui/modulo_arithmetic_integral_const.stderr +++ /dev/null @@ -1,156 +0,0 @@ -error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:13:5 - | -LL | -1 % 2; - | ^^^^^^ - | - = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:14:5 - | -LL | 1 % -2; - | ^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on constants with different signs: `-1 % 3` - --> $DIR/modulo_arithmetic_integral_const.rs:15:5 - | -LL | (1 - 2) % (1 + 2); - | ^^^^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on constants with different signs: `3 % -1` - --> $DIR/modulo_arithmetic_integral_const.rs:16:5 - | -LL | (1 + 2) % (1 - 2); - | ^^^^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on constants with different signs: `-35 % 300000` - --> $DIR/modulo_arithmetic_integral_const.rs:17:5 - | -LL | 35 * (7 - 4 * 2) % (-500 * -600); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:19:5 - | -LL | -1i8 % 2i8; - | ^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:20:5 - | -LL | 1i8 % -2i8; - | ^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:21:5 - | -LL | -1i16 % 2i16; - | ^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:22:5 - | -LL | 1i16 % -2i16; - | ^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:23:5 - | -LL | -1i32 % 2i32; - | ^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:24:5 - | -LL | 1i32 % -2i32; - | ^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:25:5 - | -LL | -1i64 % 2i64; - | ^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:26:5 - | -LL | 1i64 % -2i64; - | ^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:27:5 - | -LL | -1i128 % 2i128; - | ^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:28:5 - | -LL | 1i128 % -2i128; - | ^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:29:5 - | -LL | -1isize % 2isize; - | ^^^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:30:5 - | -LL | 1isize % -2isize; - | ^^^^^^^^^^^^^^^^ - | - = note: double check for expected result especially when interoperating with different languages - = note: or consider using `rem_euclid` or similar function - -error: aborting due to 17 previous errors - diff --git a/tests/ui/modulo_one.rs b/tests/ui/modulo_one.rs deleted file mode 100644 index 678a312f66e5..000000000000 --- a/tests/ui/modulo_one.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![warn(clippy::modulo_one)] -#![allow(clippy::no_effect, clippy::unnecessary_operation)] - -static STATIC_ONE: usize = 2 - 1; -static STATIC_NEG_ONE: i64 = 1 - 2; - -fn main() { - 10 % 1; - 10 % -1; - 10 % 2; - i32::MIN % (-1); // also caught by rustc - - const ONE: u32 = 1 * 1; - const NEG_ONE: i64 = 1 - 2; - const INT_MIN: i64 = i64::MIN; - - 2 % ONE; - 5 % STATIC_ONE; // NOT caught by lint - 2 % NEG_ONE; - 5 % STATIC_NEG_ONE; // NOT caught by lint - INT_MIN % NEG_ONE; // also caught by rustc - INT_MIN % STATIC_NEG_ONE; // ONLY caught by rustc -} diff --git a/tests/ui/modulo_one.stderr b/tests/ui/modulo_one.stderr deleted file mode 100644 index 2b2c69973385..000000000000 --- a/tests/ui/modulo_one.stderr +++ /dev/null @@ -1,74 +0,0 @@ -error: this arithmetic operation will overflow - --> $DIR/modulo_one.rs:11:5 - | -LL | i32::MIN % (-1); // also caught by rustc - | ^^^^^^^^^^^^^^^ attempt to compute the remainder of `i32::MIN % -1_i32`, which would overflow - | - = note: `#[deny(arithmetic_overflow)]` on by default - -error: this arithmetic operation will overflow - --> $DIR/modulo_one.rs:21:5 - | -LL | INT_MIN % NEG_ONE; // also caught by rustc - | ^^^^^^^^^^^^^^^^^ attempt to compute the remainder of `i64::MIN % -1_i64`, which would overflow - -error: this arithmetic operation will overflow - --> $DIR/modulo_one.rs:22:5 - | -LL | INT_MIN % STATIC_NEG_ONE; // ONLY caught by rustc - | ^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute the remainder of `i64::MIN % -1_i64`, which would overflow - -error: any number modulo 1 will be 0 - --> $DIR/modulo_one.rs:8:5 - | -LL | 10 % 1; - | ^^^^^^ - | - = note: `-D clippy::modulo-one` implied by `-D warnings` - -error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:9:5 - | -LL | 10 % -1; - | ^^^^^^^ - -error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:11:5 - | -LL | i32::MIN % (-1); // also caught by rustc - | ^^^^^^^^^^^^^^^ - -error: the operation is ineffective. Consider reducing it to `1` - --> $DIR/modulo_one.rs:13:22 - | -LL | const ONE: u32 = 1 * 1; - | ^^^^^ - | - = note: `-D clippy::identity-op` implied by `-D warnings` - -error: the operation is ineffective. Consider reducing it to `1` - --> $DIR/modulo_one.rs:13:22 - | -LL | const ONE: u32 = 1 * 1; - | ^^^^^ - -error: any number modulo 1 will be 0 - --> $DIR/modulo_one.rs:17:5 - | -LL | 2 % ONE; - | ^^^^^^^ - -error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:19:5 - | -LL | 2 % NEG_ONE; - | ^^^^^^^^^^^ - -error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:21:5 - | -LL | INT_MIN % NEG_ONE; // also caught by rustc - | ^^^^^^^^^^^^^^^^^ - -error: aborting due to 11 previous errors - diff --git a/tests/ui/must_use_candidates.fixed b/tests/ui/must_use_candidates.fixed deleted file mode 100644 index 9556f6f82cc6..000000000000 --- a/tests/ui/must_use_candidates.fixed +++ /dev/null @@ -1,93 +0,0 @@ -// run-rustfix -#![feature(never_type)] -#![allow(unused_mut, clippy::redundant_allocation)] -#![warn(clippy::must_use_candidate)] -use std::rc::Rc; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::Arc; - -pub struct MyAtomic(AtomicBool); -pub struct MyPure; - -#[must_use] pub fn pure(i: u8) -> u8 { - i -} - -impl MyPure { - #[must_use] pub fn inherent_pure(&self) -> u8 { - 0 - } -} - -pub trait MyPureTrait { - fn trait_pure(&self, i: u32) -> u32 { - self.trait_impl_pure(i) + 1 - } - - fn trait_impl_pure(&self, i: u32) -> u32; -} - -impl MyPureTrait for MyPure { - fn trait_impl_pure(&self, i: u32) -> u32 { - i - } -} - -pub fn without_result() { - // OK -} - -pub fn impure_primitive(i: &mut u8) -> u8 { - *i -} - -pub fn with_callback bool>(f: &F) -> bool { - f(0) -} - -#[must_use] pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool { - true -} - -pub fn quoth_the_raven(_more: !) -> u32 { - unimplemented!(); -} - -pub fn atomics(b: &AtomicBool) -> bool { - b.load(Ordering::SeqCst) -} - -#[must_use] pub fn rcd(_x: Rc) -> bool { - true -} - -pub fn rcmut(_x: Rc<&mut u32>) -> bool { - true -} - -#[must_use] pub fn arcd(_x: Arc) -> bool { - false -} - -pub fn inner_types(_m: &MyAtomic) -> bool { - true -} - -static mut COUNTER: usize = 0; - -/// # Safety -/// -/// Don't ever call this from multiple threads -pub unsafe fn mutates_static() -> usize { - COUNTER += 1; - COUNTER -} - -#[no_mangle] -pub fn unmangled(i: bool) -> bool { - !i -} - -fn main() { - assert_eq!(1, pure(1)); -} diff --git a/tests/ui/must_use_candidates.rs b/tests/ui/must_use_candidates.rs deleted file mode 100644 index 373242201710..000000000000 --- a/tests/ui/must_use_candidates.rs +++ /dev/null @@ -1,93 +0,0 @@ -// run-rustfix -#![feature(never_type)] -#![allow(unused_mut, clippy::redundant_allocation)] -#![warn(clippy::must_use_candidate)] -use std::rc::Rc; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::Arc; - -pub struct MyAtomic(AtomicBool); -pub struct MyPure; - -pub fn pure(i: u8) -> u8 { - i -} - -impl MyPure { - pub fn inherent_pure(&self) -> u8 { - 0 - } -} - -pub trait MyPureTrait { - fn trait_pure(&self, i: u32) -> u32 { - self.trait_impl_pure(i) + 1 - } - - fn trait_impl_pure(&self, i: u32) -> u32; -} - -impl MyPureTrait for MyPure { - fn trait_impl_pure(&self, i: u32) -> u32 { - i - } -} - -pub fn without_result() { - // OK -} - -pub fn impure_primitive(i: &mut u8) -> u8 { - *i -} - -pub fn with_callback bool>(f: &F) -> bool { - f(0) -} - -pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool { - true -} - -pub fn quoth_the_raven(_more: !) -> u32 { - unimplemented!(); -} - -pub fn atomics(b: &AtomicBool) -> bool { - b.load(Ordering::SeqCst) -} - -pub fn rcd(_x: Rc) -> bool { - true -} - -pub fn rcmut(_x: Rc<&mut u32>) -> bool { - true -} - -pub fn arcd(_x: Arc) -> bool { - false -} - -pub fn inner_types(_m: &MyAtomic) -> bool { - true -} - -static mut COUNTER: usize = 0; - -/// # Safety -/// -/// Don't ever call this from multiple threads -pub unsafe fn mutates_static() -> usize { - COUNTER += 1; - COUNTER -} - -#[no_mangle] -pub fn unmangled(i: bool) -> bool { - !i -} - -fn main() { - assert_eq!(1, pure(1)); -} diff --git a/tests/ui/must_use_candidates.stderr b/tests/ui/must_use_candidates.stderr deleted file mode 100644 index 0fa3849d03bf..000000000000 --- a/tests/ui/must_use_candidates.stderr +++ /dev/null @@ -1,34 +0,0 @@ -error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:12:1 - | -LL | pub fn pure(i: u8) -> u8 { - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn pure(i: u8) -> u8` - | - = note: `-D clippy::must-use-candidate` implied by `-D warnings` - -error: this method could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:17:5 - | -LL | pub fn inherent_pure(&self) -> u8 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn inherent_pure(&self) -> u8` - -error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:48:1 - | -LL | pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool` - -error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:60:1 - | -LL | pub fn rcd(_x: Rc) -> bool { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn rcd(_x: Rc) -> bool` - -error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:68:1 - | -LL | pub fn arcd(_x: Arc) -> bool { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn arcd(_x: Arc) -> bool` - -error: aborting due to 5 previous errors - diff --git a/tests/ui/must_use_unit.fixed b/tests/ui/must_use_unit.fixed deleted file mode 100644 index 6c9aa434ac01..000000000000 --- a/tests/ui/must_use_unit.fixed +++ /dev/null @@ -1,26 +0,0 @@ -//run-rustfix -// aux-build:macro_rules.rs - -#![warn(clippy::must_use_unit)] -#![allow(clippy::unused_unit)] - -#[macro_use] -extern crate macro_rules; - - -pub fn must_use_default() {} - - -pub fn must_use_unit() -> () {} - - -pub fn must_use_with_note() {} - -fn main() { - must_use_default(); - must_use_unit(); - must_use_with_note(); - - // We should not lint in external macros - must_use_unit!(); -} diff --git a/tests/ui/must_use_unit.rs b/tests/ui/must_use_unit.rs deleted file mode 100644 index 8a395dc284db..000000000000 --- a/tests/ui/must_use_unit.rs +++ /dev/null @@ -1,26 +0,0 @@ -//run-rustfix -// aux-build:macro_rules.rs - -#![warn(clippy::must_use_unit)] -#![allow(clippy::unused_unit)] - -#[macro_use] -extern crate macro_rules; - -#[must_use] -pub fn must_use_default() {} - -#[must_use] -pub fn must_use_unit() -> () {} - -#[must_use = "With note"] -pub fn must_use_with_note() {} - -fn main() { - must_use_default(); - must_use_unit(); - must_use_with_note(); - - // We should not lint in external macros - must_use_unit!(); -} diff --git a/tests/ui/must_use_unit.stderr b/tests/ui/must_use_unit.stderr deleted file mode 100644 index 15e0906b66b5..000000000000 --- a/tests/ui/must_use_unit.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: this unit-returning function has a `#[must_use]` attribute - --> $DIR/must_use_unit.rs:11:1 - | -LL | #[must_use] - | ----------- help: remove the attribute -LL | pub fn must_use_default() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::must-use-unit` implied by `-D warnings` - -error: this unit-returning function has a `#[must_use]` attribute - --> $DIR/must_use_unit.rs:14:1 - | -LL | #[must_use] - | ----------- help: remove the attribute -LL | pub fn must_use_unit() -> () {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: this unit-returning function has a `#[must_use]` attribute - --> $DIR/must_use_unit.rs:17:1 - | -LL | #[must_use = "With note"] - | ------------------------- help: remove the attribute -LL | pub fn must_use_with_note() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/mut_from_ref.rs b/tests/ui/mut_from_ref.rs deleted file mode 100644 index a9a04c8f56b9..000000000000 --- a/tests/ui/mut_from_ref.rs +++ /dev/null @@ -1,46 +0,0 @@ -#![allow(unused)] -#![warn(clippy::mut_from_ref)] - -struct Foo; - -impl Foo { - fn this_wont_hurt_a_bit(&self) -> &mut Foo { - unimplemented!() - } -} - -trait Ouch { - fn ouch(x: &Foo) -> &mut Foo; -} - -impl Ouch for Foo { - fn ouch(x: &Foo) -> &mut Foo { - unimplemented!() - } -} - -fn fail(x: &u32) -> &mut u16 { - unimplemented!() -} - -fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { - unimplemented!() -} - -fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 { - unimplemented!() -} - -// this is OK, because the result borrows y -fn works<'a>(x: &u32, y: &'a mut u32) -> &'a mut u32 { - unimplemented!() -} - -// this is also OK, because the result could borrow y -fn also_works<'a>(x: &'a u32, y: &'a mut u32) -> &'a mut u32 { - unimplemented!() -} - -fn main() { - //TODO -} diff --git a/tests/ui/mut_from_ref.stderr b/tests/ui/mut_from_ref.stderr deleted file mode 100644 index 4787999920bc..000000000000 --- a/tests/ui/mut_from_ref.stderr +++ /dev/null @@ -1,63 +0,0 @@ -error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:7:39 - | -LL | fn this_wont_hurt_a_bit(&self) -> &mut Foo { - | ^^^^^^^^ - | - = note: `-D clippy::mut-from-ref` implied by `-D warnings` -note: immutable borrow here - --> $DIR/mut_from_ref.rs:7:29 - | -LL | fn this_wont_hurt_a_bit(&self) -> &mut Foo { - | ^^^^^ - -error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:13:25 - | -LL | fn ouch(x: &Foo) -> &mut Foo; - | ^^^^^^^^ - | -note: immutable borrow here - --> $DIR/mut_from_ref.rs:13:16 - | -LL | fn ouch(x: &Foo) -> &mut Foo; - | ^^^^ - -error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:22:21 - | -LL | fn fail(x: &u32) -> &mut u16 { - | ^^^^^^^^ - | -note: immutable borrow here - --> $DIR/mut_from_ref.rs:22:12 - | -LL | fn fail(x: &u32) -> &mut u16 { - | ^^^^ - -error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:26:50 - | -LL | fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { - | ^^^^^^^^^^^ - | -note: immutable borrow here - --> $DIR/mut_from_ref.rs:26:25 - | -LL | fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { - | ^^^^^^^ - -error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:30:67 - | -LL | fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 { - | ^^^^^^^^^^^ - | -note: immutable borrow here - --> $DIR/mut_from_ref.rs:30:27 - | -LL | fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 { - | ^^^^^^^ ^^^^^^^ - -error: aborting due to 5 previous errors - diff --git a/tests/ui/mut_key.rs b/tests/ui/mut_key.rs deleted file mode 100644 index 2d227e6654c3..000000000000 --- a/tests/ui/mut_key.rs +++ /dev/null @@ -1,55 +0,0 @@ -use std::collections::{HashMap, HashSet}; -use std::hash::{Hash, Hasher}; -use std::sync::atomic::{AtomicUsize, Ordering::Relaxed}; - -struct Key(AtomicUsize); - -impl Clone for Key { - fn clone(&self) -> Self { - Key(AtomicUsize::new(self.0.load(Relaxed))) - } -} - -impl PartialEq for Key { - fn eq(&self, other: &Self) -> bool { - self.0.load(Relaxed) == other.0.load(Relaxed) - } -} - -impl Eq for Key {} - -impl Hash for Key { - fn hash(&self, h: &mut H) { - self.0.load(Relaxed).hash(h); - } -} - -fn should_not_take_this_arg(m: &mut HashMap, _n: usize) -> HashSet { - let _other: HashMap = HashMap::new(); - m.keys().cloned().collect() -} - -fn this_is_ok(_m: &mut HashMap) {} - -#[allow(unused)] -trait Trait { - type AssociatedType; - - fn trait_fn(&self, set: std::collections::HashSet); -} - -fn generics_are_ok_too(_m: &mut HashSet) { - // nothing to see here, move along -} - -fn tuples(_m: &mut HashMap<((), U), ()>) {} - -fn tuples_bad(_m: &mut HashMap<(Key, U), bool>) {} - -fn main() { - let _ = should_not_take_this_arg(&mut HashMap::new(), 1); - this_is_ok(&mut HashMap::new()); - tuples::(&mut HashMap::new()); - tuples::<()>(&mut HashMap::new()); - tuples_bad::<()>(&mut HashMap::new()); -} diff --git a/tests/ui/mut_key.stderr b/tests/ui/mut_key.stderr deleted file mode 100644 index 8d6a259c7e38..000000000000 --- a/tests/ui/mut_key.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: mutable key type - --> $DIR/mut_key.rs:27:32 - | -LL | fn should_not_take_this_arg(m: &mut HashMap, _n: usize) -> HashSet { - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[deny(clippy::mutable_key_type)]` on by default - -error: mutable key type - --> $DIR/mut_key.rs:27:72 - | -LL | fn should_not_take_this_arg(m: &mut HashMap, _n: usize) -> HashSet { - | ^^^^^^^^^^^^ - -error: mutable key type - --> $DIR/mut_key.rs:28:5 - | -LL | let _other: HashMap = HashMap::new(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: mutable key type - --> $DIR/mut_key.rs:47:22 - | -LL | fn tuples_bad(_m: &mut HashMap<(Key, U), bool>) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 4 previous errors - diff --git a/tests/ui/mut_mut.rs b/tests/ui/mut_mut.rs deleted file mode 100644 index 8965cef66ded..000000000000 --- a/tests/ui/mut_mut.rs +++ /dev/null @@ -1,49 +0,0 @@ -#![allow(unused, clippy::no_effect, clippy::unnecessary_operation)] -#![warn(clippy::mut_mut)] - -fn fun(x: &mut &mut u32) -> bool { - **x > 0 -} - -fn less_fun(x: *mut *mut u32) { - let y = x; -} - -macro_rules! mut_ptr { - ($p:expr) => { - &mut $p - }; -} - -#[allow(unused_mut, unused_variables)] -fn main() { - let mut x = &mut &mut 1u32; - { - let mut y = &mut x; - } - - if fun(x) { - let y: &mut &mut u32 = &mut &mut 2; - **y + **x; - } - - if fun(x) { - let y: &mut &mut &mut u32 = &mut &mut &mut 2; - ***y + **x; - } - - let mut z = mut_ptr!(&mut 3u32); -} - -fn issue939() { - let array = [5, 6, 7, 8, 9]; - let mut args = array.iter().skip(2); - for &arg in &mut args { - println!("{}", arg); - } - - let args = &mut args; - for arg in args { - println!(":{}", arg); - } -} diff --git a/tests/ui/mut_mut.stderr b/tests/ui/mut_mut.stderr deleted file mode 100644 index 44e814227141..000000000000 --- a/tests/ui/mut_mut.stderr +++ /dev/null @@ -1,63 +0,0 @@ -error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:4:11 - | -LL | fn fun(x: &mut &mut u32) -> bool { - | ^^^^^^^^^^^^^ - | - = note: `-D clippy::mut-mut` implied by `-D warnings` - -error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:20:17 - | -LL | let mut x = &mut &mut 1u32; - | ^^^^^^^^^^^^^^ - -error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:14:9 - | -LL | &mut $p - | ^^^^^^^ -... -LL | let mut z = mut_ptr!(&mut 3u32); - | ------------------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: this expression mutably borrows a mutable reference. Consider reborrowing - --> $DIR/mut_mut.rs:22:21 - | -LL | let mut y = &mut x; - | ^^^^^^ - -error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:26:32 - | -LL | let y: &mut &mut u32 = &mut &mut 2; - | ^^^^^^^^^^^ - -error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:26:16 - | -LL | let y: &mut &mut u32 = &mut &mut 2; - | ^^^^^^^^^^^^^ - -error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:31:37 - | -LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; - | ^^^^^^^^^^^^^^^^ - -error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:31:16 - | -LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; - | ^^^^^^^^^^^^^^^^^^ - -error: generally you want to avoid `&mut &mut _` if possible - --> $DIR/mut_mut.rs:31:21 - | -LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; - | ^^^^^^^^^^^^^ - -error: aborting due to 9 previous errors - diff --git a/tests/ui/mut_mutex_lock.fixed b/tests/ui/mut_mutex_lock.fixed deleted file mode 100644 index 36bc52e3374e..000000000000 --- a/tests/ui/mut_mutex_lock.fixed +++ /dev/null @@ -1,21 +0,0 @@ -// run-rustfix -#![allow(dead_code, unused_mut)] -#![warn(clippy::mut_mutex_lock)] - -use std::sync::{Arc, Mutex}; - -fn mut_mutex_lock() { - let mut value_rc = Arc::new(Mutex::new(42_u8)); - let value_mutex = Arc::get_mut(&mut value_rc).unwrap(); - - let mut value = value_mutex.get_mut().unwrap(); - *value += 1; -} - -fn no_owned_mutex_lock() { - let mut value_rc = Arc::new(Mutex::new(42_u8)); - let mut value = value_rc.lock().unwrap(); - *value += 1; -} - -fn main() {} diff --git a/tests/ui/mut_mutex_lock.rs b/tests/ui/mut_mutex_lock.rs deleted file mode 100644 index ea60df5ae1bb..000000000000 --- a/tests/ui/mut_mutex_lock.rs +++ /dev/null @@ -1,21 +0,0 @@ -// run-rustfix -#![allow(dead_code, unused_mut)] -#![warn(clippy::mut_mutex_lock)] - -use std::sync::{Arc, Mutex}; - -fn mut_mutex_lock() { - let mut value_rc = Arc::new(Mutex::new(42_u8)); - let value_mutex = Arc::get_mut(&mut value_rc).unwrap(); - - let mut value = value_mutex.lock().unwrap(); - *value += 1; -} - -fn no_owned_mutex_lock() { - let mut value_rc = Arc::new(Mutex::new(42_u8)); - let mut value = value_rc.lock().unwrap(); - *value += 1; -} - -fn main() {} diff --git a/tests/ui/mut_mutex_lock.stderr b/tests/ui/mut_mutex_lock.stderr deleted file mode 100644 index 21c1b3486cac..000000000000 --- a/tests/ui/mut_mutex_lock.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: calling `&mut Mutex::lock` unnecessarily locks an exclusive (mutable) reference - --> $DIR/mut_mutex_lock.rs:11:33 - | -LL | let mut value = value_mutex.lock().unwrap(); - | ^^^^ help: change this to: `get_mut` - | - = note: `-D clippy::mut-mutex-lock` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/mut_range_bound.rs b/tests/ui/mut_range_bound.rs deleted file mode 100644 index 1348dd2a3d8b..000000000000 --- a/tests/ui/mut_range_bound.rs +++ /dev/null @@ -1,63 +0,0 @@ -#![allow(unused)] - -fn main() { - mut_range_bound_upper(); - mut_range_bound_lower(); - mut_range_bound_both(); - mut_range_bound_no_mutation(); - immut_range_bound(); - mut_borrow_range_bound(); - immut_borrow_range_bound(); -} - -fn mut_range_bound_upper() { - let mut m = 4; - for i in 0..m { - m = 5; - } // warning -} - -fn mut_range_bound_lower() { - let mut m = 4; - for i in m..10 { - m *= 2; - } // warning -} - -fn mut_range_bound_both() { - let mut m = 4; - let mut n = 6; - for i in m..n { - m = 5; - n = 7; - } // warning (1 for each mutated bound) -} - -fn mut_range_bound_no_mutation() { - let mut m = 4; - for i in 0..m { - continue; - } // no warning -} - -fn mut_borrow_range_bound() { - let mut m = 4; - for i in 0..m { - let n = &mut m; // warning - *n += 1; - } -} - -fn immut_borrow_range_bound() { - let mut m = 4; - for i in 0..m { - let n = &m; // should be no warning? - } -} - -fn immut_range_bound() { - let m = 4; - for i in 0..m { - continue; - } // no warning -} diff --git a/tests/ui/mut_range_bound.stderr b/tests/ui/mut_range_bound.stderr deleted file mode 100644 index 0eeb76e0ec5f..000000000000 --- a/tests/ui/mut_range_bound.stderr +++ /dev/null @@ -1,34 +0,0 @@ -error: attempt to mutate range bound within loop; note that the range of the loop is unchanged - --> $DIR/mut_range_bound.rs:16:9 - | -LL | m = 5; - | ^ - | - = note: `-D clippy::mut-range-bound` implied by `-D warnings` - -error: attempt to mutate range bound within loop; note that the range of the loop is unchanged - --> $DIR/mut_range_bound.rs:23:9 - | -LL | m *= 2; - | ^ - -error: attempt to mutate range bound within loop; note that the range of the loop is unchanged - --> $DIR/mut_range_bound.rs:31:9 - | -LL | m = 5; - | ^ - -error: attempt to mutate range bound within loop; note that the range of the loop is unchanged - --> $DIR/mut_range_bound.rs:32:9 - | -LL | n = 7; - | ^ - -error: attempt to mutate range bound within loop; note that the range of the loop is unchanged - --> $DIR/mut_range_bound.rs:46:22 - | -LL | let n = &mut m; // warning - | ^ - -error: aborting due to 5 previous errors - diff --git a/tests/ui/mut_reference.rs b/tests/ui/mut_reference.rs deleted file mode 100644 index 73906121c402..000000000000 --- a/tests/ui/mut_reference.rs +++ /dev/null @@ -1,43 +0,0 @@ -#![allow(unused_variables)] - -fn takes_an_immutable_reference(a: &i32) {} -fn takes_a_mutable_reference(a: &mut i32) {} - -struct MyStruct; - -impl MyStruct { - fn takes_an_immutable_reference(&self, a: &i32) {} - - fn takes_a_mutable_reference(&self, a: &mut i32) {} -} - -#[warn(clippy::unnecessary_mut_passed)] -fn main() { - // Functions - takes_an_immutable_reference(&mut 42); - let as_ptr: fn(&i32) = takes_an_immutable_reference; - as_ptr(&mut 42); - - // Methods - let my_struct = MyStruct; - my_struct.takes_an_immutable_reference(&mut 42); - - // No error - - // Functions - takes_an_immutable_reference(&42); - let as_ptr: fn(&i32) = takes_an_immutable_reference; - as_ptr(&42); - - takes_a_mutable_reference(&mut 42); - let as_ptr: fn(&mut i32) = takes_a_mutable_reference; - as_ptr(&mut 42); - - let a = &mut 42; - takes_an_immutable_reference(a); - - // Methods - my_struct.takes_an_immutable_reference(&42); - my_struct.takes_a_mutable_reference(&mut 42); - my_struct.takes_an_immutable_reference(a); -} diff --git a/tests/ui/mut_reference.stderr b/tests/ui/mut_reference.stderr deleted file mode 100644 index 062d30b262c1..000000000000 --- a/tests/ui/mut_reference.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: the function `takes_an_immutable_reference` doesn't need a mutable reference - --> $DIR/mut_reference.rs:17:34 - | -LL | takes_an_immutable_reference(&mut 42); - | ^^^^^^^ - | - = note: `-D clippy::unnecessary-mut-passed` implied by `-D warnings` - -error: the function `as_ptr` doesn't need a mutable reference - --> $DIR/mut_reference.rs:19:12 - | -LL | as_ptr(&mut 42); - | ^^^^^^^ - -error: the method `takes_an_immutable_reference` doesn't need a mutable reference - --> $DIR/mut_reference.rs:23:44 - | -LL | my_struct.takes_an_immutable_reference(&mut 42); - | ^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/mutex_atomic.rs b/tests/ui/mutex_atomic.rs deleted file mode 100644 index b9d78b7f4792..000000000000 --- a/tests/ui/mutex_atomic.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![warn(clippy::all)] -#![warn(clippy::mutex_integer)] - -fn main() { - use std::sync::Mutex; - Mutex::new(true); - Mutex::new(5usize); - Mutex::new(9isize); - let mut x = 4u32; - Mutex::new(&x as *const u32); - Mutex::new(&mut x as *mut u32); - Mutex::new(0u32); - Mutex::new(0i32); - Mutex::new(0f32); // there are no float atomics, so this should not lint -} diff --git a/tests/ui/mutex_atomic.stderr b/tests/ui/mutex_atomic.stderr deleted file mode 100644 index a3511ba708a8..000000000000 --- a/tests/ui/mutex_atomic.stderr +++ /dev/null @@ -1,48 +0,0 @@ -error: consider using an `AtomicBool` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:6:5 - | -LL | Mutex::new(true); - | ^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::mutex-atomic` implied by `-D warnings` - -error: consider using an `AtomicUsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:7:5 - | -LL | Mutex::new(5usize); - | ^^^^^^^^^^^^^^^^^^ - -error: consider using an `AtomicIsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:8:5 - | -LL | Mutex::new(9isize); - | ^^^^^^^^^^^^^^^^^^ - -error: consider using an `AtomicPtr` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:10:5 - | -LL | Mutex::new(&x as *const u32); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: consider using an `AtomicPtr` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:11:5 - | -LL | Mutex::new(&mut x as *mut u32); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: consider using an `AtomicUsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:12:5 - | -LL | Mutex::new(0u32); - | ^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::mutex-integer` implied by `-D warnings` - -error: consider using an `AtomicIsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:13:5 - | -LL | Mutex::new(0i32); - | ^^^^^^^^^^^^^^^^ - -error: aborting due to 7 previous errors - diff --git a/tests/ui/needless_arbitrary_self_type.fixed b/tests/ui/needless_arbitrary_self_type.fixed deleted file mode 100644 index 9da21eb6b29b..000000000000 --- a/tests/ui/needless_arbitrary_self_type.fixed +++ /dev/null @@ -1,69 +0,0 @@ -// run-rustfix - -#![warn(clippy::needless_arbitrary_self_type)] -#![allow(unused_mut, clippy::needless_lifetimes)] - -pub enum ValType { - A, - B, -} - -impl ValType { - pub fn bad(self) { - unimplemented!(); - } - - pub fn good(self) { - unimplemented!(); - } - - pub fn mut_bad(mut self) { - unimplemented!(); - } - - pub fn mut_good(mut self) { - unimplemented!(); - } - - pub fn ref_bad(&self) { - unimplemented!(); - } - - pub fn ref_good(&self) { - unimplemented!(); - } - - pub fn ref_bad_with_lifetime<'a>(&'a self) { - unimplemented!(); - } - - pub fn ref_good_with_lifetime<'a>(&'a self) { - unimplemented!(); - } - - pub fn mut_ref_bad(&mut self) { - unimplemented!(); - } - - pub fn mut_ref_good(&mut self) { - unimplemented!(); - } - - pub fn mut_ref_bad_with_lifetime<'a>(&'a mut self) { - unimplemented!(); - } - - pub fn mut_ref_good_with_lifetime<'a>(&'a mut self) { - unimplemented!(); - } - - pub fn mut_ref_mut_good(mut self: &mut Self) { - unimplemented!(); - } - - pub fn mut_ref_mut_ref_good(self: &&mut &mut Self) { - unimplemented!(); - } -} - -fn main() {} diff --git a/tests/ui/needless_arbitrary_self_type.rs b/tests/ui/needless_arbitrary_self_type.rs deleted file mode 100644 index 17aeaaf97ac7..000000000000 --- a/tests/ui/needless_arbitrary_self_type.rs +++ /dev/null @@ -1,69 +0,0 @@ -// run-rustfix - -#![warn(clippy::needless_arbitrary_self_type)] -#![allow(unused_mut, clippy::needless_lifetimes)] - -pub enum ValType { - A, - B, -} - -impl ValType { - pub fn bad(self: Self) { - unimplemented!(); - } - - pub fn good(self) { - unimplemented!(); - } - - pub fn mut_bad(mut self: Self) { - unimplemented!(); - } - - pub fn mut_good(mut self) { - unimplemented!(); - } - - pub fn ref_bad(self: &Self) { - unimplemented!(); - } - - pub fn ref_good(&self) { - unimplemented!(); - } - - pub fn ref_bad_with_lifetime<'a>(self: &'a Self) { - unimplemented!(); - } - - pub fn ref_good_with_lifetime<'a>(&'a self) { - unimplemented!(); - } - - pub fn mut_ref_bad(self: &mut Self) { - unimplemented!(); - } - - pub fn mut_ref_good(&mut self) { - unimplemented!(); - } - - pub fn mut_ref_bad_with_lifetime<'a>(self: &'a mut Self) { - unimplemented!(); - } - - pub fn mut_ref_good_with_lifetime<'a>(&'a mut self) { - unimplemented!(); - } - - pub fn mut_ref_mut_good(mut self: &mut Self) { - unimplemented!(); - } - - pub fn mut_ref_mut_ref_good(self: &&mut &mut Self) { - unimplemented!(); - } -} - -fn main() {} diff --git a/tests/ui/needless_arbitrary_self_type.stderr b/tests/ui/needless_arbitrary_self_type.stderr deleted file mode 100644 index f4c645d35c8f..000000000000 --- a/tests/ui/needless_arbitrary_self_type.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:12:16 - | -LL | pub fn bad(self: Self) { - | ^^^^^^^^^^ help: consider to change this parameter to: `self` - | - = note: `-D clippy::needless-arbitrary-self-type` implied by `-D warnings` - -error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:20:20 - | -LL | pub fn mut_bad(mut self: Self) { - | ^^^^^^^^^^^^^^ help: consider to change this parameter to: `mut self` - -error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:28:20 - | -LL | pub fn ref_bad(self: &Self) { - | ^^^^^^^^^^^ help: consider to change this parameter to: `&self` - -error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:36:38 - | -LL | pub fn ref_bad_with_lifetime<'a>(self: &'a Self) { - | ^^^^^^^^^^^^^^ help: consider to change this parameter to: `&'a self` - -error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:44:24 - | -LL | pub fn mut_ref_bad(self: &mut Self) { - | ^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&mut self` - -error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:52:42 - | -LL | pub fn mut_ref_bad_with_lifetime<'a>(self: &'a mut Self) { - | ^^^^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&'a mut self` - -error: aborting due to 6 previous errors - diff --git a/tests/ui/needless_arbitrary_self_type_unfixable.rs b/tests/ui/needless_arbitrary_self_type_unfixable.rs deleted file mode 100644 index a39d96109f17..000000000000 --- a/tests/ui/needless_arbitrary_self_type_unfixable.rs +++ /dev/null @@ -1,45 +0,0 @@ -// aux-build:proc_macro_attr.rs - -#![warn(clippy::needless_arbitrary_self_type)] - -#[macro_use] -extern crate proc_macro_attr; - -mod issue_6089 { - // Check that we don't lint if the `self` parameter comes from expansion - - macro_rules! test_from_expansion { - () => { - trait T1 { - fn test(self: &Self); - } - - struct S1 {} - - impl T1 for S1 { - fn test(self: &Self) {} - } - }; - } - - test_from_expansion!(); - - // If only the lifetime name comes from expansion we will lint, but the suggestion will have - // placeholders and will not be applied automatically, as we can't reliably know the original name. - // This specific case happened with async_trait. - - trait T2 { - fn call_with_mut_self(&mut self); - } - - struct S2 {} - - // The method's signature will be expanded to: - // fn call_with_mut_self<'life0>(self: &'life0 mut Self) {} - #[rename_my_lifetimes] - impl T2 for S2 { - fn call_with_mut_self(self: &mut Self) {} - } -} - -fn main() {} diff --git a/tests/ui/needless_arbitrary_self_type_unfixable.stderr b/tests/ui/needless_arbitrary_self_type_unfixable.stderr deleted file mode 100644 index 44a0e6ddeace..000000000000 --- a/tests/ui/needless_arbitrary_self_type_unfixable.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type_unfixable.rs:41:31 - | -LL | fn call_with_mut_self(self: &mut Self) {} - | ^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&'_ mut self` - | - = note: `-D clippy::needless-arbitrary-self-type` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/needless_bool/fixable.fixed b/tests/ui/needless_bool/fixable.fixed deleted file mode 100644 index 567dbc54100a..000000000000 --- a/tests/ui/needless_bool/fixable.fixed +++ /dev/null @@ -1,98 +0,0 @@ -// run-rustfix - -#![warn(clippy::needless_bool)] -#![allow( - unused, - dead_code, - clippy::no_effect, - clippy::if_same_then_else, - clippy::needless_return -)] - -use std::cell::Cell; - -macro_rules! bool_comparison_trigger { - ($($i:ident: $def:expr, $stb:expr );+ $(;)*) => ( - - #[derive(Clone)] - pub struct Trigger { - $($i: (Cell, bool, bool)),+ - } - - #[allow(dead_code)] - impl Trigger { - pub fn trigger(&self, key: &str) -> bool { - $( - if let stringify!($i) = key { - return self.$i.1 && self.$i.2 == $def; - } - )+ - false - } - } - ) -} - -fn main() { - let x = true; - let y = false; - x; - !x; - !(x && y); - if x { - x - } else { - false - }; // would also be questionable, but we don't catch this yet - bool_ret3(x); - bool_ret4(x); - bool_ret5(x, x); - bool_ret6(x, x); - needless_bool(x); - needless_bool2(x); - needless_bool3(x); -} - -fn bool_ret3(x: bool) -> bool { - return x; -} - -fn bool_ret4(x: bool) -> bool { - return !x; -} - -fn bool_ret5(x: bool, y: bool) -> bool { - return x && y; -} - -fn bool_ret6(x: bool, y: bool) -> bool { - return !(x && y); -} - -fn needless_bool(x: bool) { - if x {}; -} - -fn needless_bool2(x: bool) { - if !x {}; -} - -fn needless_bool3(x: bool) { - bool_comparison_trigger! { - test_one: false, false; - test_three: false, false; - test_two: true, true; - } - - if x {}; - if !x {}; -} - -fn needless_bool_in_the_suggestion_wraps_the_predicate_of_if_else_statement_in_brackets() { - let b = false; - let returns_bool = || false; - - let x = if b { - true - } else { !returns_bool() }; -} diff --git a/tests/ui/needless_bool/fixable.rs b/tests/ui/needless_bool/fixable.rs deleted file mode 100644 index 10126ad4dbb1..000000000000 --- a/tests/ui/needless_bool/fixable.rs +++ /dev/null @@ -1,130 +0,0 @@ -// run-rustfix - -#![warn(clippy::needless_bool)] -#![allow( - unused, - dead_code, - clippy::no_effect, - clippy::if_same_then_else, - clippy::needless_return -)] - -use std::cell::Cell; - -macro_rules! bool_comparison_trigger { - ($($i:ident: $def:expr, $stb:expr );+ $(;)*) => ( - - #[derive(Clone)] - pub struct Trigger { - $($i: (Cell, bool, bool)),+ - } - - #[allow(dead_code)] - impl Trigger { - pub fn trigger(&self, key: &str) -> bool { - $( - if let stringify!($i) = key { - return self.$i.1 && self.$i.2 == $def; - } - )+ - false - } - } - ) -} - -fn main() { - let x = true; - let y = false; - if x { - true - } else { - false - }; - if x { - false - } else { - true - }; - if x && y { - false - } else { - true - }; - if x { - x - } else { - false - }; // would also be questionable, but we don't catch this yet - bool_ret3(x); - bool_ret4(x); - bool_ret5(x, x); - bool_ret6(x, x); - needless_bool(x); - needless_bool2(x); - needless_bool3(x); -} - -fn bool_ret3(x: bool) -> bool { - if x { - return true; - } else { - return false; - }; -} - -fn bool_ret4(x: bool) -> bool { - if x { - return false; - } else { - return true; - }; -} - -fn bool_ret5(x: bool, y: bool) -> bool { - if x && y { - return true; - } else { - return false; - }; -} - -fn bool_ret6(x: bool, y: bool) -> bool { - if x && y { - return false; - } else { - return true; - }; -} - -fn needless_bool(x: bool) { - if x == true {}; -} - -fn needless_bool2(x: bool) { - if x == false {}; -} - -fn needless_bool3(x: bool) { - bool_comparison_trigger! { - test_one: false, false; - test_three: false, false; - test_two: true, true; - } - - if x == true {}; - if x == false {}; -} - -fn needless_bool_in_the_suggestion_wraps_the_predicate_of_if_else_statement_in_brackets() { - let b = false; - let returns_bool = || false; - - let x = if b { - true - } else if returns_bool() { - false - } else { - true - }; -} diff --git a/tests/ui/needless_bool/fixable.stderr b/tests/ui/needless_bool/fixable.stderr deleted file mode 100644 index 25abfb2a472b..000000000000 --- a/tests/ui/needless_bool/fixable.stderr +++ /dev/null @@ -1,111 +0,0 @@ -error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:39:5 - | -LL | / if x { -LL | | true -LL | | } else { -LL | | false -LL | | }; - | |_____^ help: you can reduce it to: `x` - | - = note: `-D clippy::needless-bool` implied by `-D warnings` - -error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:44:5 - | -LL | / if x { -LL | | false -LL | | } else { -LL | | true -LL | | }; - | |_____^ help: you can reduce it to: `!x` - -error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:49:5 - | -LL | / if x && y { -LL | | false -LL | | } else { -LL | | true -LL | | }; - | |_____^ help: you can reduce it to: `!(x && y)` - -error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:69:5 - | -LL | / if x { -LL | | return true; -LL | | } else { -LL | | return false; -LL | | }; - | |_____^ help: you can reduce it to: `return x` - -error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:77:5 - | -LL | / if x { -LL | | return false; -LL | | } else { -LL | | return true; -LL | | }; - | |_____^ help: you can reduce it to: `return !x` - -error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:85:5 - | -LL | / if x && y { -LL | | return true; -LL | | } else { -LL | | return false; -LL | | }; - | |_____^ help: you can reduce it to: `return x && y` - -error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:93:5 - | -LL | / if x && y { -LL | | return false; -LL | | } else { -LL | | return true; -LL | | }; - | |_____^ help: you can reduce it to: `return !(x && y)` - -error: equality checks against true are unnecessary - --> $DIR/fixable.rs:101:8 - | -LL | if x == true {}; - | ^^^^^^^^^ help: try simplifying it as shown: `x` - | - = note: `-D clippy::bool-comparison` implied by `-D warnings` - -error: equality checks against false can be replaced by a negation - --> $DIR/fixable.rs:105:8 - | -LL | if x == false {}; - | ^^^^^^^^^^ help: try simplifying it as shown: `!x` - -error: equality checks against true are unnecessary - --> $DIR/fixable.rs:115:8 - | -LL | if x == true {}; - | ^^^^^^^^^ help: try simplifying it as shown: `x` - -error: equality checks against false can be replaced by a negation - --> $DIR/fixable.rs:116:8 - | -LL | if x == false {}; - | ^^^^^^^^^^ help: try simplifying it as shown: `!x` - -error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:125:12 - | -LL | } else if returns_bool() { - | ____________^ -LL | | false -LL | | } else { -LL | | true -LL | | }; - | |_____^ help: you can reduce it to: `{ !returns_bool() }` - -error: aborting due to 12 previous errors - diff --git a/tests/ui/needless_bool/simple.rs b/tests/ui/needless_bool/simple.rs deleted file mode 100644 index e9f1428fc3a4..000000000000 --- a/tests/ui/needless_bool/simple.rs +++ /dev/null @@ -1,46 +0,0 @@ -#![warn(clippy::needless_bool)] -#![allow( - unused, - dead_code, - clippy::no_effect, - clippy::if_same_then_else, - clippy::needless_return -)] - -fn main() { - let x = true; - let y = false; - if x { - true - } else { - true - }; - if x { - false - } else { - false - }; - if x { - x - } else { - false - }; // would also be questionable, but we don't catch this yet - bool_ret(x); - bool_ret2(x); -} - -fn bool_ret(x: bool) -> bool { - if x { - return true; - } else { - return true; - }; -} - -fn bool_ret2(x: bool) -> bool { - if x { - return false; - } else { - return false; - }; -} diff --git a/tests/ui/needless_bool/simple.stderr b/tests/ui/needless_bool/simple.stderr deleted file mode 100644 index c57a8a042fb8..000000000000 --- a/tests/ui/needless_bool/simple.stderr +++ /dev/null @@ -1,44 +0,0 @@ -error: this if-then-else expression will always return true - --> $DIR/simple.rs:13:5 - | -LL | / if x { -LL | | true -LL | | } else { -LL | | true -LL | | }; - | |_____^ - | - = note: `-D clippy::needless-bool` implied by `-D warnings` - -error: this if-then-else expression will always return false - --> $DIR/simple.rs:18:5 - | -LL | / if x { -LL | | false -LL | | } else { -LL | | false -LL | | }; - | |_____^ - -error: this if-then-else expression will always return true - --> $DIR/simple.rs:33:5 - | -LL | / if x { -LL | | return true; -LL | | } else { -LL | | return true; -LL | | }; - | |_____^ - -error: this if-then-else expression will always return false - --> $DIR/simple.rs:41:5 - | -LL | / if x { -LL | | return false; -LL | | } else { -LL | | return false; -LL | | }; - | |_____^ - -error: aborting due to 4 previous errors - diff --git a/tests/ui/needless_borrow.fixed b/tests/ui/needless_borrow.fixed deleted file mode 100644 index 5ae4a0e79b99..000000000000 --- a/tests/ui/needless_borrow.fixed +++ /dev/null @@ -1,61 +0,0 @@ -// run-rustfix - -#![allow(clippy::needless_borrowed_reference)] - -fn x(y: &i32) -> i32 { - *y -} - -#[warn(clippy::all, clippy::needless_borrow)] -#[allow(unused_variables)] -fn main() { - let a = 5; - let b = x(&a); - let c = x(&a); - let s = &String::from("hi"); - let s_ident = f(&s); // should not error, because `&String` implements Copy, but `String` does not - let g_val = g(&Vec::new()); // should not error, because `&Vec` derefs to `&[T]` - let vec = Vec::new(); - let vec_val = g(&vec); // should not error, because `&Vec` derefs to `&[T]` - h(&"foo"); // should not error, because the `&&str` is required, due to `&Trait` - if let Some(cake) = Some(&5) {} - let garbl = match 42 { - 44 => &a, - 45 => { - println!("foo"); - &&a // FIXME: this should lint, too - }, - 46 => &a, - _ => panic!(), - }; -} - -fn f(y: &T) -> T { - *y -} - -fn g(y: &[u8]) -> u8 { - y[0] -} - -trait Trait {} - -impl<'a> Trait for &'a str {} - -fn h(_: &dyn Trait) {} -#[warn(clippy::needless_borrow)] -#[allow(dead_code)] -fn issue_1432() { - let mut v = Vec::::new(); - let _ = v.iter_mut().filter(|&ref a| a.is_empty()); - let _ = v.iter().filter(|&a| a.is_empty()); - - let _ = v.iter().filter(|&a| a.is_empty()); -} - -#[allow(dead_code)] -#[warn(clippy::needless_borrow)] -#[derive(Debug)] -enum Foo<'a> { - Str(&'a str), -} diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs deleted file mode 100644 index 1e281316c8a3..000000000000 --- a/tests/ui/needless_borrow.rs +++ /dev/null @@ -1,61 +0,0 @@ -// run-rustfix - -#![allow(clippy::needless_borrowed_reference)] - -fn x(y: &i32) -> i32 { - *y -} - -#[warn(clippy::all, clippy::needless_borrow)] -#[allow(unused_variables)] -fn main() { - let a = 5; - let b = x(&a); - let c = x(&&a); - let s = &String::from("hi"); - let s_ident = f(&s); // should not error, because `&String` implements Copy, but `String` does not - let g_val = g(&Vec::new()); // should not error, because `&Vec` derefs to `&[T]` - let vec = Vec::new(); - let vec_val = g(&vec); // should not error, because `&Vec` derefs to `&[T]` - h(&"foo"); // should not error, because the `&&str` is required, due to `&Trait` - if let Some(ref cake) = Some(&5) {} - let garbl = match 42 { - 44 => &a, - 45 => { - println!("foo"); - &&a // FIXME: this should lint, too - }, - 46 => &&a, - _ => panic!(), - }; -} - -fn f(y: &T) -> T { - *y -} - -fn g(y: &[u8]) -> u8 { - y[0] -} - -trait Trait {} - -impl<'a> Trait for &'a str {} - -fn h(_: &dyn Trait) {} -#[warn(clippy::needless_borrow)] -#[allow(dead_code)] -fn issue_1432() { - let mut v = Vec::::new(); - let _ = v.iter_mut().filter(|&ref a| a.is_empty()); - let _ = v.iter().filter(|&ref a| a.is_empty()); - - let _ = v.iter().filter(|&a| a.is_empty()); -} - -#[allow(dead_code)] -#[warn(clippy::needless_borrow)] -#[derive(Debug)] -enum Foo<'a> { - Str(&'a str), -} diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr deleted file mode 100644 index bea4b41b803d..000000000000 --- a/tests/ui/needless_borrow.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:14:15 - | -LL | let c = x(&&a); - | ^^^ help: change this to: `&a` - | - = note: `-D clippy::needless-borrow` implied by `-D warnings` - -error: this pattern creates a reference to a reference - --> $DIR/needless_borrow.rs:21:17 - | -LL | if let Some(ref cake) = Some(&5) {} - | ^^^^^^^^ help: change this to: `cake` - -error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:28:15 - | -LL | 46 => &&a, - | ^^^ help: change this to: `&a` - -error: this pattern creates a reference to a reference - --> $DIR/needless_borrow.rs:51:31 - | -LL | let _ = v.iter().filter(|&ref a| a.is_empty()); - | ^^^^^ help: change this to: `a` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/needless_borrowed_ref.fixed b/tests/ui/needless_borrowed_ref.fixed deleted file mode 100644 index a0937a2c5f62..000000000000 --- a/tests/ui/needless_borrowed_ref.fixed +++ /dev/null @@ -1,45 +0,0 @@ -// run-rustfix - -#[warn(clippy::needless_borrowed_reference)] -#[allow(unused_variables)] -fn main() { - let mut v = Vec::::new(); - let _ = v.iter_mut().filter(|a| a.is_empty()); - // ^ should be linted - - let var = 3; - let thingy = Some(&var); - if let Some(&ref v) = thingy { - // ^ should be linted - } - - let mut var2 = 5; - let thingy2 = Some(&mut var2); - if let Some(&mut ref mut v) = thingy2 { - // ^ should **not** be linted - // v is borrowed as mutable. - *v = 10; - } - if let Some(&mut ref v) = thingy2 { - // ^ should **not** be linted - // here, v is borrowed as immutable. - // can't do that: - //*v = 15; - } -} - -#[allow(dead_code)] -enum Animal { - Cat(u64), - Dog(u64), -} - -#[allow(unused_variables)] -#[allow(dead_code)] -fn foo(a: &Animal, b: &Animal) { - match (a, b) { - (&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (), // lifetime mismatch error if there is no '&ref' - // ^ and ^ should **not** be linted - (&Animal::Dog(ref a), &Animal::Dog(_)) => (), // ^ should **not** be linted - } -} diff --git a/tests/ui/needless_borrowed_ref.rs b/tests/ui/needless_borrowed_ref.rs deleted file mode 100644 index 500ac448f0d5..000000000000 --- a/tests/ui/needless_borrowed_ref.rs +++ /dev/null @@ -1,45 +0,0 @@ -// run-rustfix - -#[warn(clippy::needless_borrowed_reference)] -#[allow(unused_variables)] -fn main() { - let mut v = Vec::::new(); - let _ = v.iter_mut().filter(|&ref a| a.is_empty()); - // ^ should be linted - - let var = 3; - let thingy = Some(&var); - if let Some(&ref v) = thingy { - // ^ should be linted - } - - let mut var2 = 5; - let thingy2 = Some(&mut var2); - if let Some(&mut ref mut v) = thingy2 { - // ^ should **not** be linted - // v is borrowed as mutable. - *v = 10; - } - if let Some(&mut ref v) = thingy2 { - // ^ should **not** be linted - // here, v is borrowed as immutable. - // can't do that: - //*v = 15; - } -} - -#[allow(dead_code)] -enum Animal { - Cat(u64), - Dog(u64), -} - -#[allow(unused_variables)] -#[allow(dead_code)] -fn foo(a: &Animal, b: &Animal) { - match (a, b) { - (&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (), // lifetime mismatch error if there is no '&ref' - // ^ and ^ should **not** be linted - (&Animal::Dog(ref a), &Animal::Dog(_)) => (), // ^ should **not** be linted - } -} diff --git a/tests/ui/needless_borrowed_ref.stderr b/tests/ui/needless_borrowed_ref.stderr deleted file mode 100644 index 0a5cfb3db0b1..000000000000 --- a/tests/ui/needless_borrowed_ref.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: this pattern takes a reference on something that is being de-referenced - --> $DIR/needless_borrowed_ref.rs:7:34 - | -LL | let _ = v.iter_mut().filter(|&ref a| a.is_empty()); - | ^^^^^^ help: try removing the `&ref` part and just keep: `a` - | - = note: `-D clippy::needless-borrowed-reference` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/needless_collect.fixed b/tests/ui/needless_collect.fixed deleted file mode 100644 index 7f2fcf02f6b5..000000000000 --- a/tests/ui/needless_collect.fixed +++ /dev/null @@ -1,21 +0,0 @@ -// run-rustfix - -#![allow(unused, clippy::suspicious_map)] - -use std::collections::{BTreeSet, HashMap, HashSet}; - -#[warn(clippy::needless_collect)] -#[allow(unused_variables, clippy::iter_cloned_collect, clippy::iter_next_slice)] -fn main() { - let sample = [1; 5]; - let len = sample.iter().count(); - if sample.iter().next().is_none() { - // Empty - } - sample.iter().cloned().any(|x| x == 1); - sample.iter().map(|x| (x, x)).count(); - // Notice the `HashSet`--this should not be linted - sample.iter().collect::>().len(); - // Neither should this - sample.iter().collect::>().len(); -} diff --git a/tests/ui/needless_collect.rs b/tests/ui/needless_collect.rs deleted file mode 100644 index 788a9eb3264e..000000000000 --- a/tests/ui/needless_collect.rs +++ /dev/null @@ -1,21 +0,0 @@ -// run-rustfix - -#![allow(unused, clippy::suspicious_map)] - -use std::collections::{BTreeSet, HashMap, HashSet}; - -#[warn(clippy::needless_collect)] -#[allow(unused_variables, clippy::iter_cloned_collect, clippy::iter_next_slice)] -fn main() { - let sample = [1; 5]; - let len = sample.iter().collect::>().len(); - if sample.iter().collect::>().is_empty() { - // Empty - } - sample.iter().cloned().collect::>().contains(&1); - sample.iter().map(|x| (x, x)).collect::>().len(); - // Notice the `HashSet`--this should not be linted - sample.iter().collect::>().len(); - // Neither should this - sample.iter().collect::>().len(); -} diff --git a/tests/ui/needless_collect.stderr b/tests/ui/needless_collect.stderr deleted file mode 100644 index 2a9539d59759..000000000000 --- a/tests/ui/needless_collect.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:11:29 - | -LL | let len = sample.iter().collect::>().len(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` - | - = note: `-D clippy::needless-collect` implied by `-D warnings` - -error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:12:22 - | -LL | if sample.iter().collect::>().is_empty() { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` - -error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:15:28 - | -LL | sample.iter().cloned().collect::>().contains(&1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == 1)` - -error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:16:35 - | -LL | sample.iter().map(|x| (x, x)).collect::>().len(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/needless_collect_indirect.rs b/tests/ui/needless_collect_indirect.rs deleted file mode 100644 index 0918a6868ab4..000000000000 --- a/tests/ui/needless_collect_indirect.rs +++ /dev/null @@ -1,45 +0,0 @@ -use std::collections::{HashMap, VecDeque}; - -fn main() { - let sample = [1; 5]; - let indirect_iter = sample.iter().collect::>(); - indirect_iter.into_iter().map(|x| (x, x + 1)).collect::>(); - let indirect_len = sample.iter().collect::>(); - indirect_len.len(); - let indirect_empty = sample.iter().collect::>(); - indirect_empty.is_empty(); - let indirect_contains = sample.iter().collect::>(); - indirect_contains.contains(&&5); - let indirect_negative = sample.iter().collect::>(); - indirect_negative.len(); - indirect_negative - .into_iter() - .map(|x| (*x, *x + 1)) - .collect::>(); - - // #6202 - let a = "a".to_string(); - let sample = vec![a.clone(), "b".to_string(), "c".to_string()]; - let non_copy_contains = sample.into_iter().collect::>(); - non_copy_contains.contains(&a); - - // Fix #5991 - let vec_a = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - let vec_b = vec_a.iter().collect::>(); - if vec_b.len() > 3 {} - let other_vec = vec![1, 3, 12, 4, 16, 2]; - let we_got_the_same_numbers = other_vec.iter().filter(|item| vec_b.contains(item)).collect::>(); - - // Fix #6297 - let sample = [1; 5]; - let multiple_indirect = sample.iter().collect::>(); - let sample2 = vec![2, 3]; - if multiple_indirect.is_empty() { - // do something - } else { - let found = sample2 - .iter() - .filter(|i| multiple_indirect.iter().any(|s| **s % **i == 0)) - .collect::>(); - } -} diff --git a/tests/ui/needless_collect_indirect.stderr b/tests/ui/needless_collect_indirect.stderr deleted file mode 100644 index fb807da5f8ab..000000000000 --- a/tests/ui/needless_collect_indirect.stderr +++ /dev/null @@ -1,68 +0,0 @@ -error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:5:5 - | -LL | / let indirect_iter = sample.iter().collect::>(); -LL | | indirect_iter.into_iter().map(|x| (x, x + 1)).collect::>(); - | |____^ - | - = note: `-D clippy::needless-collect` implied by `-D warnings` -help: Use the original Iterator instead of collecting it and then producing a new one - | -LL | -LL | sample.iter().map(|x| (x, x + 1)).collect::>(); - | - -error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:7:5 - | -LL | / let indirect_len = sample.iter().collect::>(); -LL | | indirect_len.len(); - | |____^ - | -help: Take the original Iterator's count instead of collecting it and finding the length - | -LL | -LL | sample.iter().count(); - | - -error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:9:5 - | -LL | / let indirect_empty = sample.iter().collect::>(); -LL | | indirect_empty.is_empty(); - | |____^ - | -help: Check if the original Iterator has anything instead of collecting it and seeing if it's empty - | -LL | -LL | sample.iter().next().is_none(); - | - -error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:11:5 - | -LL | / let indirect_contains = sample.iter().collect::>(); -LL | | indirect_contains.contains(&&5); - | |____^ - | -help: Check if the original Iterator contains an element instead of collecting then checking - | -LL | -LL | sample.iter().any(|x| x == &5); - | - -error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:23:5 - | -LL | / let non_copy_contains = sample.into_iter().collect::>(); -LL | | non_copy_contains.contains(&a); - | |____^ - | -help: Check if the original Iterator contains an element instead of collecting then checking - | -LL | -LL | sample.into_iter().any(|x| x == a); - | - -error: aborting due to 5 previous errors - diff --git a/tests/ui/needless_continue.rs b/tests/ui/needless_continue.rs deleted file mode 100644 index 5da95647f2c1..000000000000 --- a/tests/ui/needless_continue.rs +++ /dev/null @@ -1,115 +0,0 @@ -#![warn(clippy::needless_continue)] - -macro_rules! zero { - ($x:expr) => { - $x == 0 - }; -} - -macro_rules! nonzero { - ($x:expr) => { - !zero!($x) - }; -} - -fn main() { - let mut i = 1; - while i < 10 { - i += 1; - - if i % 2 == 0 && i % 3 == 0 { - println!("{}", i); - println!("{}", i + 1); - if i % 5 == 0 { - println!("{}", i + 2); - } - let i = 0; - println!("bar {} ", i); - } else { - continue; - } - - println!("bleh"); - { - println!("blah"); - } - - // some comments that also should ideally be included in the - // output of the lint suggestion if possible. - if !(!(i == 2) || !(i == 5)) { - println!("lama"); - } - - if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { - continue; - } else { - println!("Blabber"); - println!("Jabber"); - } - - println!("bleh"); - } -} - -mod issue_2329 { - fn condition() -> bool { - unimplemented!() - } - fn update_condition() {} - - // only the outer loop has a label - fn foo() { - 'outer: loop { - println!("Entry"); - while condition() { - update_condition(); - if condition() { - println!("foo-1"); - } else { - continue 'outer; // should not lint here - } - println!("foo-2"); - - update_condition(); - if condition() { - continue 'outer; // should not lint here - } else { - println!("foo-3"); - } - println!("foo-4"); - } - } - } - - // both loops have labels - fn bar() { - 'outer: loop { - println!("Entry"); - 'inner: while condition() { - update_condition(); - if condition() { - println!("bar-1"); - } else { - continue 'outer; // should not lint here - } - println!("bar-2"); - - update_condition(); - if condition() { - println!("bar-3"); - } else { - continue 'inner; // should lint here - } - println!("bar-4"); - - update_condition(); - if condition() { - continue; // should lint here - } else { - println!("bar-5"); - } - println!("bar-6"); - } - } - } -} diff --git a/tests/ui/needless_continue.stderr b/tests/ui/needless_continue.stderr deleted file mode 100644 index 8d6a37df9601..000000000000 --- a/tests/ui/needless_continue.stderr +++ /dev/null @@ -1,99 +0,0 @@ -error: this `else` block is redundant - --> $DIR/needless_continue.rs:28:16 - | -LL | } else { - | ________________^ -LL | | continue; -LL | | } - | |_________^ - | - = note: `-D clippy::needless-continue` implied by `-D warnings` - = help: consider dropping the `else` clause and merging the code that follows (in the loop) with the `if` block - if i % 2 == 0 && i % 3 == 0 { - println!("{}", i); - println!("{}", i + 1); - if i % 5 == 0 { - println!("{}", i + 2); - } - let i = 0; - println!("bar {} ", i); - // merged code follows: - println!("bleh"); - { - println!("blah"); - } - if !(!(i == 2) || !(i == 5)) { - println!("lama"); - } - if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { - continue; - } else { - println!("Blabber"); - println!("Jabber"); - } - println!("bleh"); - } - -error: there is no need for an explicit `else` block for this `if` expression - --> $DIR/needless_continue.rs:43:9 - | -LL | / if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { -LL | | continue; -LL | | } else { -LL | | println!("Blabber"); -LL | | println!("Jabber"); -LL | | } - | |_________^ - | - = help: consider dropping the `else` clause - if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { - continue; - } - { - println!("Blabber"); - println!("Jabber"); - } - -error: this `else` block is redundant - --> $DIR/needless_continue.rs:100:24 - | -LL | } else { - | ________________________^ -LL | | continue 'inner; // should lint here -LL | | } - | |_________________^ - | - = help: consider dropping the `else` clause and merging the code that follows (in the loop) with the `if` block - if condition() { - println!("bar-3"); - // merged code follows: - println!("bar-4"); - update_condition(); - if condition() { - continue; // should lint here - } else { - println!("bar-5"); - } - println!("bar-6"); - } - -error: there is no need for an explicit `else` block for this `if` expression - --> $DIR/needless_continue.rs:106:17 - | -LL | / if condition() { -LL | | continue; // should lint here -LL | | } else { -LL | | println!("bar-5"); -LL | | } - | |_________________^ - | - = help: consider dropping the `else` clause - if condition() { - continue; // should lint here - } - { - println!("bar-5"); - } - -error: aborting due to 4 previous errors - diff --git a/tests/ui/needless_doc_main.rs b/tests/ui/needless_doc_main.rs deleted file mode 100644 index 83e9bbaa3af4..000000000000 --- a/tests/ui/needless_doc_main.rs +++ /dev/null @@ -1,140 +0,0 @@ -/// This is a test for needless `fn main()` in doctests. -/// -/// # Examples -/// -/// This should lint -/// ``` -/// fn main() { -/// unimplemented!(); -/// } -/// ``` -/// -/// With an explicit return type it should lint too -/// ```edition2015 -/// fn main() -> () { -/// unimplemented!(); -/// } -/// ``` -/// -/// This should, too. -/// ```rust -/// fn main() { -/// unimplemented!(); -/// } -/// ``` -/// -/// This one too. -/// ```no_run -/// fn main() { -/// unimplemented!(); -/// } -/// ``` -fn bad_doctests() {} - -/// # Examples -/// -/// This shouldn't lint, because the `main` is empty: -/// ``` -/// fn main(){} -/// ``` -/// -/// This shouldn't lint either, because main is async: -/// ```edition2018 -/// async fn main() { -/// assert_eq!(42, ANSWER); -/// } -/// ``` -/// -/// Same here, because the return type is not the unit type: -/// ``` -/// fn main() -> Result<()> { -/// Ok(()) -/// } -/// ``` -/// -/// This shouldn't lint either, because there's a `static`: -/// ``` -/// static ANSWER: i32 = 42; -/// -/// fn main() { -/// assert_eq!(42, ANSWER); -/// } -/// ``` -/// -/// This shouldn't lint either, because there's a `const`: -/// ``` -/// fn main() { -/// assert_eq!(42, ANSWER); -/// } -/// -/// const ANSWER: i32 = 42; -/// ``` -/// -/// Neither should this lint because of `extern crate`: -/// ``` -/// #![feature(test)] -/// extern crate test; -/// fn main() { -/// assert_eq(1u8, test::black_box(1)); -/// } -/// ``` -/// -/// Neither should this lint because it has an extern block: -/// ``` -/// extern {} -/// fn main() { -/// unimplemented!(); -/// } -/// ``` -/// -/// This should not lint because there is another function defined: -/// ``` -/// fn fun() {} -/// -/// fn main() { -/// unimplemented!(); -/// } -/// ``` -/// -/// We should not lint inside raw strings ... -/// ``` -/// let string = r#" -/// fn main() { -/// unimplemented!(); -/// } -/// "#; -/// ``` -/// -/// ... or comments -/// ``` -/// // fn main() { -/// // let _inception = 42; -/// // } -/// let _inception = 42; -/// ``` -/// -/// We should not lint ignored examples: -/// ```rust,ignore -/// fn main() { -/// unimplemented!(); -/// } -/// ``` -/// -/// Or even non-rust examples: -/// ```text -/// fn main() { -/// is what starts the program -/// } -/// ``` -fn no_false_positives() {} - -/// Yields a parse error when interpreted as rust code: -/// ``` -/// r#"hi" -/// ``` -fn issue_6022() {} - -fn main() { - bad_doctests(); - no_false_positives(); -} diff --git a/tests/ui/needless_doc_main.stderr b/tests/ui/needless_doc_main.stderr deleted file mode 100644 index 05c7f9d33a79..000000000000 --- a/tests/ui/needless_doc_main.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:7:4 - | -LL | /// fn main() { - | ^^^^^^^^^^^^ - | - = note: `-D clippy::needless-doctest-main` implied by `-D warnings` - -error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:14:4 - | -LL | /// fn main() -> () { - | ^^^^^^^^^^^^^^^^^^ - -error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:21:4 - | -LL | /// fn main() { - | ^^^^^^^^^^^^ - -error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:28:4 - | -LL | /// fn main() { - | ^^^^^^^^^^^^ - -error: aborting due to 4 previous errors - diff --git a/tests/ui/needless_lifetimes.rs b/tests/ui/needless_lifetimes.rs deleted file mode 100644 index 44972c8c6396..000000000000 --- a/tests/ui/needless_lifetimes.rs +++ /dev/null @@ -1,371 +0,0 @@ -#![warn(clippy::needless_lifetimes)] -#![allow(dead_code, clippy::needless_pass_by_value, clippy::unnecessary_wraps)] - -fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {} - -fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) {} - -// No error; same lifetime on two params. -fn same_lifetime_on_input<'a>(_x: &'a u8, _y: &'a u8) {} - -// No error; static involved. -fn only_static_on_input(_x: &u8, _y: &u8, _z: &'static u8) {} - -fn mut_and_static_input(_x: &mut u8, _y: &'static str) {} - -fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { - x -} - -// No error; multiple input refs. -fn multiple_in_and_out_1<'a>(x: &'a u8, _y: &'a u8) -> &'a u8 { - x -} - -// No error; multiple input refs. -fn multiple_in_and_out_2<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 { - x -} - -// No error; static involved. -fn in_static_and_out<'a>(x: &'a u8, _y: &'static u8) -> &'a u8 { - x -} - -// No error. -fn deep_reference_1<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> { - Ok(x) -} - -// No error; two input refs. -fn deep_reference_2<'a>(x: Result<&'a u8, &'a u8>) -> &'a u8 { - x.unwrap() -} - -fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> { - Ok(x) -} - -// Where-clause, but without lifetimes. -fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> -where - T: Copy, -{ - Ok(x) -} - -type Ref<'r> = &'r u8; - -// No error; same lifetime on two params. -fn lifetime_param_1<'a>(_x: Ref<'a>, _y: &'a u8) {} - -fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {} - -// No error; bounded lifetime. -fn lifetime_param_3<'a, 'b: 'a>(_x: Ref<'a>, _y: &'b u8) {} - -// No error; bounded lifetime. -fn lifetime_param_4<'a, 'b>(_x: Ref<'a>, _y: &'b u8) -where - 'b: 'a, -{ -} - -struct Lt<'a, I: 'static> { - x: &'a I, -} - -// No error; fn bound references `'a`. -fn fn_bound<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> -where - F: Fn(Lt<'a, I>) -> Lt<'a, I>, -{ - unreachable!() -} - -fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> -where - for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>, -{ - unreachable!() -} - -// No error; see below. -fn fn_bound_3<'a, F: FnOnce(&'a i32)>(x: &'a i32, f: F) { - f(x); -} - -fn fn_bound_3_cannot_elide() { - let x = 42; - let p = &x; - let mut q = &x; - // This will fail if we elide lifetimes of `fn_bound_3`. - fn_bound_3(p, |y| q = y); -} - -// No error; multiple input refs. -fn fn_bound_4<'a, F: FnOnce() -> &'a ()>(cond: bool, x: &'a (), f: F) -> &'a () { - if cond { - x - } else { - f() - } -} - -struct X { - x: u8, -} - -impl X { - fn self_and_out<'s>(&'s self) -> &'s u8 { - &self.x - } - - // No error; multiple input refs. - fn self_and_in_out<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 { - &self.x - } - - fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {} - - // No error; same lifetimes on two params. - fn self_and_same_in<'s>(&'s self, _x: &'s u8) {} -} - -struct Foo<'a>(&'a u8); - -impl<'a> Foo<'a> { - // No error; lifetime `'a` not defined in method. - fn self_shared_lifetime(&self, _: &'a u8) {} - // No error; bounds exist. - fn self_bound_lifetime<'b: 'a>(&self, _: &'b u8) {} -} - -fn already_elided<'a>(_: &u8, _: &'a u8) -> &'a u8 { - unimplemented!() -} - -fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { - unimplemented!() -} - -// No warning; two input lifetimes (named on the reference, anonymous on `Foo`). -fn struct_with_lt2<'a>(_foo: &'a Foo) -> &'a str { - unimplemented!() -} - -// No warning; two input lifetimes (anonymous on the reference, named on `Foo`). -fn struct_with_lt3<'a>(_foo: &Foo<'a>) -> &'a str { - unimplemented!() -} - -// No warning; two input lifetimes. -fn struct_with_lt4<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { - unimplemented!() -} - -trait WithLifetime<'a> {} - -type WithLifetimeAlias<'a> = dyn WithLifetime<'a>; - -// Should not warn because it won't build without the lifetime. -fn trait_obj_elided<'a>(_arg: &'a dyn WithLifetime) -> &'a str { - unimplemented!() -} - -// Should warn because there is no lifetime on `Drop`, so this would be -// unambiguous if we elided the lifetime. -fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str { - unimplemented!() -} - -type FooAlias<'a> = Foo<'a>; - -fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { - unimplemented!() -} - -// No warning; two input lifetimes (named on the reference, anonymous on `FooAlias`). -fn alias_with_lt2<'a>(_foo: &'a FooAlias) -> &'a str { - unimplemented!() -} - -// No warning; two input lifetimes (anonymous on the reference, named on `FooAlias`). -fn alias_with_lt3<'a>(_foo: &FooAlias<'a>) -> &'a str { - unimplemented!() -} - -// No warning; two input lifetimes. -fn alias_with_lt4<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { - unimplemented!() -} - -fn named_input_elided_output<'a>(_arg: &'a str) -> &str { - unimplemented!() -} - -fn elided_input_named_output<'a>(_arg: &str) -> &'a str { - unimplemented!() -} - -fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { - unimplemented!() -} -fn trait_bound<'a, T: WithLifetime<'a>>(_: &'a u8, _: T) { - unimplemented!() -} - -// Don't warn on these; see issue #292. -fn trait_bound_bug<'a, T: WithLifetime<'a>>() { - unimplemented!() -} - -// See issue #740. -struct Test { - vec: Vec, -} - -impl Test { - fn iter<'a>(&'a self) -> Box + 'a> { - unimplemented!() - } -} - -trait LintContext<'a> {} - -fn f<'a, T: LintContext<'a>>(_: &T) {} - -fn test<'a>(x: &'a [u8]) -> u8 { - let y: &'a u8 = &x[5]; - *y -} - -// Issue #3284: give hint regarding lifetime in return type. -struct Cow<'a> { - x: &'a str, -} -fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { - unimplemented!() -} - -// Make sure we still warn on implementations -mod issue4291 { - trait BadTrait { - fn needless_lt<'a>(x: &'a u8) {} - } - - impl BadTrait for () { - fn needless_lt<'a>(_x: &'a u8) {} - } -} - -mod issue2944 { - trait Foo {} - struct Bar {} - struct Baz<'a> { - bar: &'a Bar, - } - - impl<'a> Foo for Baz<'a> {} - impl Bar { - fn baz<'a>(&'a self) -> impl Foo + 'a { - Baz { bar: self } - } - } -} - -mod nested_elision_sites { - // issue #issue2944 - - // closure trait bounds subject to nested elision - // don't lint because they refer to outer lifetimes - fn trait_fn<'a>(i: &'a i32) -> impl Fn() -> &'a i32 { - move || i - } - fn trait_fn_mut<'a>(i: &'a i32) -> impl FnMut() -> &'a i32 { - move || i - } - fn trait_fn_once<'a>(i: &'a i32) -> impl FnOnce() -> &'a i32 { - move || i - } - - // don't lint - fn impl_trait_in_input_position<'a>(f: impl Fn() -> &'a i32) -> &'a i32 { - f() - } - fn impl_trait_in_output_position<'a>(i: &'a i32) -> impl Fn() -> &'a i32 { - move || i - } - // lint - fn impl_trait_elidable_nested_named_lifetimes<'a>(i: &'a i32, f: impl for<'b> Fn(&'b i32) -> &'b i32) -> &'a i32 { - f(i) - } - fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 { - f(i) - } - - // don't lint - fn generics_not_elidable<'a, T: Fn() -> &'a i32>(f: T) -> &'a i32 { - f() - } - // lint - fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 { - f(i) - } - - // don't lint - fn where_clause_not_elidable<'a, T>(f: T) -> &'a i32 - where - T: Fn() -> &'a i32, - { - f() - } - // lint - fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32 - where - T: Fn(&i32) -> &i32, - { - f(i) - } - - // don't lint - fn pointer_fn_in_input_position<'a>(f: fn(&'a i32) -> &'a i32, i: &'a i32) -> &'a i32 { - f(i) - } - fn pointer_fn_in_output_position<'a>(_: &'a i32) -> fn(&'a i32) -> &'a i32 { - |i| i - } - // lint - fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 { - f(i) - } - - // don't lint - fn nested_fn_pointer_1<'a>(_: &'a i32) -> fn(fn(&'a i32) -> &'a i32) -> i32 { - |f| 42 - } - fn nested_fn_pointer_2<'a>(_: &'a i32) -> impl Fn(fn(&'a i32)) { - |f| () - } - - // lint - fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 { - |f| 42 - } - fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) { - |f| () - } -} - -mod issue6159 { - use std::ops::Deref; - pub fn apply_deref<'a, T, F, R>(x: &'a T, f: F) -> R - where - T: Deref, - F: FnOnce(&'a T::Target) -> R, - { - f(x.deref()) - } -} - -fn main() {} diff --git a/tests/ui/needless_lifetimes.stderr b/tests/ui/needless_lifetimes.stderr deleted file mode 100644 index c8a2e8b81c01..000000000000 --- a/tests/ui/needless_lifetimes.stderr +++ /dev/null @@ -1,154 +0,0 @@ -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:4:1 - | -LL | fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::needless-lifetimes` implied by `-D warnings` - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:6:1 - | -LL | fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:16:1 - | -LL | fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:45:1 - | -LL | fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:50:1 - | -LL | fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:62:1 - | -LL | fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:86:1 - | -LL | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:120:5 - | -LL | fn self_and_out<'s>(&'s self) -> &'s u8 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:129:5 - | -LL | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:148:1 - | -LL | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:178:1 - | -LL | fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:184:1 - | -LL | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:203:1 - | -LL | fn named_input_elided_output<'a>(_arg: &'a str) -> &str { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:211:1 - | -LL | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:247:1 - | -LL | fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:254:9 - | -LL | fn needless_lt<'a>(x: &'a u8) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:258:9 - | -LL | fn needless_lt<'a>(_x: &'a u8) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:271:9 - | -LL | fn baz<'a>(&'a self) -> impl Foo + 'a { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:300:5 - | -LL | fn impl_trait_elidable_nested_named_lifetimes<'a>(i: &'a i32, f: impl for<'b> Fn(&'b i32) -> &'b i32) -> &'a i32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:303:5 - | -LL | fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:312:5 - | -LL | fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:324:5 - | -LL | fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:339:5 - | -LL | fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:352:5 - | -LL | fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:355:5 - | -LL | fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 25 previous errors - diff --git a/tests/ui/needless_pass_by_value.rs b/tests/ui/needless_pass_by_value.rs deleted file mode 100644 index 7a9ba55590dc..000000000000 --- a/tests/ui/needless_pass_by_value.rs +++ /dev/null @@ -1,161 +0,0 @@ -#![warn(clippy::needless_pass_by_value)] -#![allow( - dead_code, - clippy::single_match, - clippy::redundant_pattern_matching, - clippy::many_single_char_names, - clippy::option_option, - clippy::redundant_clone -)] - -use std::borrow::Borrow; -use std::collections::HashSet; -use std::convert::AsRef; -use std::mem::MaybeUninit; - -// `v` should be warned -// `w`, `x` and `y` are allowed (moved or mutated) -fn foo(v: Vec, w: Vec, mut x: Vec, y: Vec) -> Vec { - assert_eq!(v.len(), 42); - - consume(w); - - x.push(T::default()); - - y -} - -fn consume(_: T) {} - -struct Wrapper(String); - -fn bar(x: String, y: Wrapper) { - assert_eq!(x.len(), 42); - assert_eq!(y.0.len(), 42); -} - -// V implements `Borrow`, but should be warned correctly -fn test_borrow_trait, U: AsRef, V>(t: T, u: U, v: V) { - println!("{}", t.borrow()); - println!("{}", u.as_ref()); - consume(&v); -} - -// ok -fn test_fn i32>(f: F) { - f(1); -} - -// x should be warned, but y is ok -fn test_match(x: Option>, y: Option>) { - match x { - Some(Some(_)) => 1, // not moved - _ => 0, - }; - - match y { - Some(Some(s)) => consume(s), // moved - _ => (), - }; -} - -// x and y should be warned, but z is ok -fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { - let Wrapper(s) = z; // moved - let Wrapper(ref t) = y; // not moved - let Wrapper(_) = y; // still not moved - - assert_eq!(x.0.len(), s.len()); - println!("{}", t); -} - -trait Foo {} - -// `S: Serialize` is allowed to be passed by value, since a caller can pass `&S` instead -trait Serialize {} -impl<'a, T> Serialize for &'a T where T: Serialize {} -impl Serialize for i32 {} - -fn test_blanket_ref(_foo: T, _serializable: S) {} - -fn issue_2114(s: String, t: String, u: Vec, v: Vec) { - s.capacity(); - let _ = t.clone(); - u.capacity(); - let _ = v.clone(); -} - -struct S(T, U); - -impl S { - fn foo( - self, - // taking `self` by value is always allowed - s: String, - t: String, - ) -> usize { - s.len() + t.capacity() - } - - fn bar(_t: T, // Ok, since `&T: Serialize` too - ) { - } - - fn baz(&self, _u: U, _s: Self) {} -} - -trait FalsePositive { - fn visit_str(s: &str); - fn visit_string(s: String) { - Self::visit_str(&s); - } -} - -// shouldn't warn on extern funcs -extern "C" fn ext(x: MaybeUninit) -> usize { - unsafe { x.assume_init() } -} - -// exempt RangeArgument -fn range>(range: T) { - let _ = range.start_bound(); -} - -struct CopyWrapper(u32); - -fn bar_copy(x: u32, y: CopyWrapper) { - assert_eq!(x, 42); - assert_eq!(y.0, 42); -} - -// x and y should be warned, but z is ok -fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { - let CopyWrapper(s) = z; // moved - let CopyWrapper(ref t) = y; // not moved - let CopyWrapper(_) = y; // still not moved - - assert_eq!(x.0, s); - println!("{}", t); -} - -// The following 3 lines should not cause an ICE. See #2831 -trait Bar<'a, A> {} -impl<'b, T> Bar<'b, T> for T {} -fn some_fun<'b, S: Bar<'b, ()>>(_item: S) {} - -// Also this should not cause an ICE. See #2831 -trait Club<'a, A> {} -impl Club<'static, T> for T {} -fn more_fun(_item: impl Club<'static, i32>) {} - -fn is_sync(_: T) -where - T: Sync, -{ -} - -fn main() { - // This should not cause an ICE either - // https://github.com/rust-lang/rust-clippy/issues/3144 - is_sync(HashSet::::new()); -} diff --git a/tests/ui/needless_pass_by_value.stderr b/tests/ui/needless_pass_by_value.stderr deleted file mode 100644 index 9aa783bf904e..000000000000 --- a/tests/ui/needless_pass_by_value.stderr +++ /dev/null @@ -1,178 +0,0 @@ -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:18:23 - | -LL | fn foo(v: Vec, w: Vec, mut x: Vec, y: Vec) -> Vec { - | ^^^^^^ help: consider changing the type to: `&[T]` - | - = note: `-D clippy::needless-pass-by-value` implied by `-D warnings` - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:32:11 - | -LL | fn bar(x: String, y: Wrapper) { - | ^^^^^^ help: consider changing the type to: `&str` - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:32:22 - | -LL | fn bar(x: String, y: Wrapper) { - | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:38:71 - | -LL | fn test_borrow_trait, U: AsRef, V>(t: T, u: U, v: V) { - | ^ help: consider taking a reference instead: `&V` - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:50:18 - | -LL | fn test_match(x: Option>, y: Option>) { - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&Option>` - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:63:24 - | -LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { - | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:63:36 - | -LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { - | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:79:49 - | -LL | fn test_blanket_ref(_foo: T, _serializable: S) {} - | ^ help: consider taking a reference instead: `&T` - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:81:18 - | -LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { - | ^^^^^^ help: consider taking a reference instead: `&String` - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:81:29 - | -LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { - | ^^^^^^ - | -help: consider changing the type to - | -LL | fn issue_2114(s: String, t: &str, u: Vec, v: Vec) { - | ^^^^ -help: change `t.clone()` to - | -LL | let _ = t.to_string(); - | ^^^^^^^^^^^^^ - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:81:40 - | -LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { - | ^^^^^^^^ help: consider taking a reference instead: `&Vec` - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:81:53 - | -LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { - | ^^^^^^^^ - | -help: consider changing the type to - | -LL | fn issue_2114(s: String, t: String, u: Vec, v: &[i32]) { - | ^^^^^^ -help: change `v.clone()` to - | -LL | let _ = v.to_owned(); - | ^^^^^^^^^^^^ - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:94:12 - | -LL | s: String, - | ^^^^^^ help: consider changing the type to: `&str` - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:95:12 - | -LL | t: String, - | ^^^^^^ help: consider taking a reference instead: `&String` - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:104:23 - | -LL | fn baz(&self, _u: U, _s: Self) {} - | ^ help: consider taking a reference instead: `&U` - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:104:30 - | -LL | fn baz(&self, _u: U, _s: Self) {} - | ^^^^ help: consider taking a reference instead: `&Self` - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:126:24 - | -LL | fn bar_copy(x: u32, y: CopyWrapper) { - | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` - | -help: consider marking this type as `Copy` - --> $DIR/needless_pass_by_value.rs:124:1 - | -LL | struct CopyWrapper(u32); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:132:29 - | -LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { - | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` - | -help: consider marking this type as `Copy` - --> $DIR/needless_pass_by_value.rs:124:1 - | -LL | struct CopyWrapper(u32); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:132:45 - | -LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { - | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` - | -help: consider marking this type as `Copy` - --> $DIR/needless_pass_by_value.rs:124:1 - | -LL | struct CopyWrapper(u32); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:132:61 - | -LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { - | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` - | -help: consider marking this type as `Copy` - --> $DIR/needless_pass_by_value.rs:124:1 - | -LL | struct CopyWrapper(u32); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:144:40 - | -LL | fn some_fun<'b, S: Bar<'b, ()>>(_item: S) {} - | ^ help: consider taking a reference instead: `&S` - -error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:149:20 - | -LL | fn more_fun(_item: impl Club<'static, i32>) {} - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&impl Club<'static, i32>` - -error: aborting due to 22 previous errors - diff --git a/tests/ui/needless_pass_by_value_proc_macro.rs b/tests/ui/needless_pass_by_value_proc_macro.rs deleted file mode 100644 index 78a0e92d1797..000000000000 --- a/tests/ui/needless_pass_by_value_proc_macro.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![crate_type = "proc-macro"] -#![warn(clippy::needless_pass_by_value)] - -extern crate proc_macro; - -use proc_macro::TokenStream; - -#[proc_macro_derive(Foo)] -pub fn foo(_input: TokenStream) -> TokenStream { - unimplemented!() -} - -#[proc_macro] -pub fn bar(_input: TokenStream) -> TokenStream { - unimplemented!() -} - -#[proc_macro_attribute] -pub fn baz(_args: TokenStream, _input: TokenStream) -> TokenStream { - unimplemented!() -} diff --git a/tests/ui/needless_range_loop.rs b/tests/ui/needless_range_loop.rs deleted file mode 100644 index 3fce34367ae5..000000000000 --- a/tests/ui/needless_range_loop.rs +++ /dev/null @@ -1,95 +0,0 @@ -#![warn(clippy::needless_range_loop)] - -static STATIC: [usize; 4] = [0, 1, 8, 16]; -const CONST: [usize; 4] = [0, 1, 8, 16]; -const MAX_LEN: usize = 42; - -fn main() { - let mut vec = vec![1, 2, 3, 4]; - let vec2 = vec![1, 2, 3, 4]; - for i in 0..vec.len() { - println!("{}", vec[i]); - } - - for i in 0..vec.len() { - let i = 42; // make a different `i` - println!("{}", vec[i]); // ok, not the `i` of the for-loop - } - - for i in 0..vec.len() { - let _ = vec[i]; - } - - // ICE #746 - for j in 0..4 { - println!("{:?}", STATIC[j]); - } - - for j in 0..4 { - println!("{:?}", CONST[j]); - } - - for i in 0..vec.len() { - println!("{} {}", vec[i], i); - } - for i in 0..vec.len() { - // not an error, indexing more than one variable - println!("{} {}", vec[i], vec2[i]); - } - - for i in 0..vec.len() { - println!("{}", vec2[i]); - } - - for i in 5..vec.len() { - println!("{}", vec[i]); - } - - for i in 0..MAX_LEN { - println!("{}", vec[i]); - } - - for i in 0..=MAX_LEN { - println!("{}", vec[i]); - } - - for i in 5..10 { - println!("{}", vec[i]); - } - - for i in 5..=10 { - println!("{}", vec[i]); - } - - for i in 5..vec.len() { - println!("{} {}", vec[i], i); - } - - for i in 5..10 { - println!("{} {}", vec[i], i); - } - - // #2542 - for i in 0..vec.len() { - vec[i] = Some(1).unwrap_or_else(|| panic!("error on {}", i)); - } - - // #3788 - let test = Test { - inner: vec![1, 2, 3, 4], - }; - for i in 0..2 { - println!("{}", test[i]); - } -} - -struct Test { - inner: Vec, -} - -impl std::ops::Index for Test { - type Output = usize; - fn index(&self, index: usize) -> &Self::Output { - &self.inner[index] - } -} diff --git a/tests/ui/needless_range_loop.stderr b/tests/ui/needless_range_loop.stderr deleted file mode 100644 index c50c4931fb4c..000000000000 --- a/tests/ui/needless_range_loop.stderr +++ /dev/null @@ -1,157 +0,0 @@ -error: the loop variable `i` is only used to index `vec`. - --> $DIR/needless_range_loop.rs:10:14 - | -LL | for i in 0..vec.len() { - | ^^^^^^^^^^^^ - | - = note: `-D clippy::needless-range-loop` implied by `-D warnings` -help: consider using an iterator - | -LL | for in &vec { - | ^^^^^^ ^^^^ - -error: the loop variable `i` is only used to index `vec`. - --> $DIR/needless_range_loop.rs:19:14 - | -LL | for i in 0..vec.len() { - | ^^^^^^^^^^^^ - | -help: consider using an iterator - | -LL | for in &vec { - | ^^^^^^ ^^^^ - -error: the loop variable `j` is only used to index `STATIC`. - --> $DIR/needless_range_loop.rs:24:14 - | -LL | for j in 0..4 { - | ^^^^ - | -help: consider using an iterator - | -LL | for in &STATIC { - | ^^^^^^ ^^^^^^^ - -error: the loop variable `j` is only used to index `CONST`. - --> $DIR/needless_range_loop.rs:28:14 - | -LL | for j in 0..4 { - | ^^^^ - | -help: consider using an iterator - | -LL | for in &CONST { - | ^^^^^^ ^^^^^^ - -error: the loop variable `i` is used to index `vec` - --> $DIR/needless_range_loop.rs:32:14 - | -LL | for i in 0..vec.len() { - | ^^^^^^^^^^^^ - | -help: consider using an iterator - | -LL | for (i, ) in vec.iter().enumerate() { - | ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ - -error: the loop variable `i` is only used to index `vec2`. - --> $DIR/needless_range_loop.rs:40:14 - | -LL | for i in 0..vec.len() { - | ^^^^^^^^^^^^ - | -help: consider using an iterator - | -LL | for in vec2.iter().take(vec.len()) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the loop variable `i` is only used to index `vec`. - --> $DIR/needless_range_loop.rs:44:14 - | -LL | for i in 5..vec.len() { - | ^^^^^^^^^^^^ - | -help: consider using an iterator - | -LL | for in vec.iter().skip(5) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^ - -error: the loop variable `i` is only used to index `vec`. - --> $DIR/needless_range_loop.rs:48:14 - | -LL | for i in 0..MAX_LEN { - | ^^^^^^^^^^ - | -help: consider using an iterator - | -LL | for in vec.iter().take(MAX_LEN) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the loop variable `i` is only used to index `vec`. - --> $DIR/needless_range_loop.rs:52:14 - | -LL | for i in 0..=MAX_LEN { - | ^^^^^^^^^^^ - | -help: consider using an iterator - | -LL | for in vec.iter().take(MAX_LEN + 1) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the loop variable `i` is only used to index `vec`. - --> $DIR/needless_range_loop.rs:56:14 - | -LL | for i in 5..10 { - | ^^^^^ - | -help: consider using an iterator - | -LL | for in vec.iter().take(10).skip(5) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the loop variable `i` is only used to index `vec`. - --> $DIR/needless_range_loop.rs:60:14 - | -LL | for i in 5..=10 { - | ^^^^^^ - | -help: consider using an iterator - | -LL | for in vec.iter().take(10 + 1).skip(5) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the loop variable `i` is used to index `vec` - --> $DIR/needless_range_loop.rs:64:14 - | -LL | for i in 5..vec.len() { - | ^^^^^^^^^^^^ - | -help: consider using an iterator - | -LL | for (i, ) in vec.iter().enumerate().skip(5) { - | ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the loop variable `i` is used to index `vec` - --> $DIR/needless_range_loop.rs:68:14 - | -LL | for i in 5..10 { - | ^^^^^ - | -help: consider using an iterator - | -LL | for (i, ) in vec.iter().enumerate().take(10).skip(5) { - | ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the loop variable `i` is used to index `vec` - --> $DIR/needless_range_loop.rs:73:14 - | -LL | for i in 0..vec.len() { - | ^^^^^^^^^^^^ - | -help: consider using an iterator - | -LL | for (i, ) in vec.iter_mut().enumerate() { - | ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 14 previous errors - diff --git a/tests/ui/needless_range_loop2.rs b/tests/ui/needless_range_loop2.rs deleted file mode 100644 index 7633316e0f87..000000000000 --- a/tests/ui/needless_range_loop2.rs +++ /dev/null @@ -1,109 +0,0 @@ -#![warn(clippy::needless_range_loop)] - -fn calc_idx(i: usize) -> usize { - (i + i + 20) % 4 -} - -fn main() { - let ns = vec![2, 3, 5, 7]; - - for i in 3..10 { - println!("{}", ns[i]); - } - - for i in 3..10 { - println!("{}", ns[i % 4]); - } - - for i in 3..10 { - println!("{}", ns[i % ns.len()]); - } - - for i in 3..10 { - println!("{}", ns[calc_idx(i)]); - } - - for i in 3..10 { - println!("{}", ns[calc_idx(i) % 4]); - } - - let mut ms = vec![1, 2, 3, 4, 5, 6]; - for i in 0..ms.len() { - ms[i] *= 2; - } - assert_eq!(ms, vec![2, 4, 6, 8, 10, 12]); - - let mut ms = vec![1, 2, 3, 4, 5, 6]; - for i in 0..ms.len() { - let x = &mut ms[i]; - *x *= 2; - } - assert_eq!(ms, vec![2, 4, 6, 8, 10, 12]); - - let g = vec![1, 2, 3, 4, 5, 6]; - let glen = g.len(); - for i in 0..glen { - let x: u32 = g[i + 1..].iter().sum(); - println!("{}", g[i] + x); - } - assert_eq!(g, vec![20, 18, 15, 11, 6, 0]); - - let mut g = vec![1, 2, 3, 4, 5, 6]; - let glen = g.len(); - for i in 0..glen { - g[i] = g[i + 1..].iter().sum(); - } - assert_eq!(g, vec![20, 18, 15, 11, 6, 0]); - - let x = 5; - let mut vec = vec![0; 9]; - - for i in x..x + 4 { - vec[i] += 1; - } - - let x = 5; - let mut vec = vec![0; 10]; - - for i in x..=x + 4 { - vec[i] += 1; - } - - let arr = [1, 2, 3]; - - for i in 0..3 { - println!("{}", arr[i]); - } - - for i in 0..2 { - println!("{}", arr[i]); - } - - for i in 1..3 { - println!("{}", arr[i]); - } - - // Fix #5945 - let mut vec = vec![1, 2, 3, 4]; - for i in 0..vec.len() - 1 { - vec[i] += 1; - } - let mut vec = vec![1, 2, 3, 4]; - for i in vec.len() - 3..vec.len() { - vec[i] += 1; - } - let mut vec = vec![1, 2, 3, 4]; - for i in vec.len() - 3..vec.len() - 1 { - vec[i] += 1; - } -} - -mod issue2277 { - pub fn example(list: &[[f64; 3]]) { - let mut x: [f64; 3] = [10.; 3]; - - for i in 0..3 { - x[i] = list.iter().map(|item| item[i]).sum::(); - } - } -} diff --git a/tests/ui/needless_range_loop2.stderr b/tests/ui/needless_range_loop2.stderr deleted file mode 100644 index c54ab5ec9809..000000000000 --- a/tests/ui/needless_range_loop2.stderr +++ /dev/null @@ -1,91 +0,0 @@ -error: the loop variable `i` is only used to index `ns`. - --> $DIR/needless_range_loop2.rs:10:14 - | -LL | for i in 3..10 { - | ^^^^^ - | - = note: `-D clippy::needless-range-loop` implied by `-D warnings` -help: consider using an iterator - | -LL | for in ns.iter().take(10).skip(3) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the loop variable `i` is only used to index `ms`. - --> $DIR/needless_range_loop2.rs:31:14 - | -LL | for i in 0..ms.len() { - | ^^^^^^^^^^^ - | -help: consider using an iterator - | -LL | for in &mut ms { - | ^^^^^^ ^^^^^^^ - -error: the loop variable `i` is only used to index `ms`. - --> $DIR/needless_range_loop2.rs:37:14 - | -LL | for i in 0..ms.len() { - | ^^^^^^^^^^^ - | -help: consider using an iterator - | -LL | for in &mut ms { - | ^^^^^^ ^^^^^^^ - -error: the loop variable `i` is only used to index `vec`. - --> $DIR/needless_range_loop2.rs:61:14 - | -LL | for i in x..x + 4 { - | ^^^^^^^^ - | -help: consider using an iterator - | -LL | for in vec.iter_mut().skip(x).take(4) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the loop variable `i` is only used to index `vec`. - --> $DIR/needless_range_loop2.rs:68:14 - | -LL | for i in x..=x + 4 { - | ^^^^^^^^^ - | -help: consider using an iterator - | -LL | for in vec.iter_mut().skip(x).take(4 + 1) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the loop variable `i` is only used to index `arr`. - --> $DIR/needless_range_loop2.rs:74:14 - | -LL | for i in 0..3 { - | ^^^^ - | -help: consider using an iterator - | -LL | for in &arr { - | ^^^^^^ ^^^^ - -error: the loop variable `i` is only used to index `arr`. - --> $DIR/needless_range_loop2.rs:78:14 - | -LL | for i in 0..2 { - | ^^^^ - | -help: consider using an iterator - | -LL | for in arr.iter().take(2) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^ - -error: the loop variable `i` is only used to index `arr`. - --> $DIR/needless_range_loop2.rs:82:14 - | -LL | for i in 1..3 { - | ^^^^ - | -help: consider using an iterator - | -LL | for in arr.iter().skip(1) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^ - -error: aborting due to 8 previous errors - diff --git a/tests/ui/needless_return.fixed b/tests/ui/needless_return.fixed deleted file mode 100644 index d849e093da7b..000000000000 --- a/tests/ui/needless_return.fixed +++ /dev/null @@ -1,95 +0,0 @@ -// run-rustfix - -#![allow(unused, clippy::needless_bool)] -#![allow(clippy::if_same_then_else, clippy::single_match)] -#![warn(clippy::needless_return)] - -macro_rules! the_answer { - () => { - 42 - }; -} - -fn test_end_of_fn() -> bool { - if true { - // no error! - return true; - } - true -} - -fn test_no_semicolon() -> bool { - true -} - -fn test_if_block() -> bool { - if true { - true - } else { - false - } -} - -fn test_match(x: bool) -> bool { - match x { - true => false, - false => { - true - }, - } -} - -fn test_closure() { - let _ = || { - true - }; - let _ = || true; -} - -fn test_macro_call() -> i32 { - return the_answer!(); -} - -fn test_void_fun() { - -} - -fn test_void_if_fun(b: bool) { - if b { - - } else { - - } -} - -fn test_void_match(x: u32) { - match x { - 0 => (), - _ => {}, - } -} - -fn read_line() -> String { - use std::io::BufRead; - let stdin = ::std::io::stdin(); - return stdin.lock().lines().next().unwrap().unwrap(); -} - -fn borrows_but_not_last(value: bool) -> String { - if value { - use std::io::BufRead; - let stdin = ::std::io::stdin(); - let _a = stdin.lock().lines().next().unwrap().unwrap(); - String::from("test") - } else { - String::new() - } -} - -fn main() { - let _ = test_end_of_fn(); - let _ = test_no_semicolon(); - let _ = test_if_block(); - let _ = test_match(true); - test_closure(); -} diff --git a/tests/ui/needless_return.rs b/tests/ui/needless_return.rs deleted file mode 100644 index 29f2bd1852af..000000000000 --- a/tests/ui/needless_return.rs +++ /dev/null @@ -1,95 +0,0 @@ -// run-rustfix - -#![allow(unused, clippy::needless_bool)] -#![allow(clippy::if_same_then_else, clippy::single_match)] -#![warn(clippy::needless_return)] - -macro_rules! the_answer { - () => { - 42 - }; -} - -fn test_end_of_fn() -> bool { - if true { - // no error! - return true; - } - return true; -} - -fn test_no_semicolon() -> bool { - return true; -} - -fn test_if_block() -> bool { - if true { - return true; - } else { - return false; - } -} - -fn test_match(x: bool) -> bool { - match x { - true => return false, - false => { - return true; - }, - } -} - -fn test_closure() { - let _ = || { - return true; - }; - let _ = || return true; -} - -fn test_macro_call() -> i32 { - return the_answer!(); -} - -fn test_void_fun() { - return; -} - -fn test_void_if_fun(b: bool) { - if b { - return; - } else { - return; - } -} - -fn test_void_match(x: u32) { - match x { - 0 => (), - _ => return, - } -} - -fn read_line() -> String { - use std::io::BufRead; - let stdin = ::std::io::stdin(); - return stdin.lock().lines().next().unwrap().unwrap(); -} - -fn borrows_but_not_last(value: bool) -> String { - if value { - use std::io::BufRead; - let stdin = ::std::io::stdin(); - let _a = stdin.lock().lines().next().unwrap().unwrap(); - return String::from("test"); - } else { - return String::new(); - } -} - -fn main() { - let _ = test_end_of_fn(); - let _ = test_no_semicolon(); - let _ = test_if_block(); - let _ = test_match(true); - test_closure(); -} diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr deleted file mode 100644 index f73c833a801f..000000000000 --- a/tests/ui/needless_return.stderr +++ /dev/null @@ -1,88 +0,0 @@ -error: unneeded `return` statement - --> $DIR/needless_return.rs:18:5 - | -LL | return true; - | ^^^^^^^^^^^^ help: remove `return`: `true` - | - = note: `-D clippy::needless-return` implied by `-D warnings` - -error: unneeded `return` statement - --> $DIR/needless_return.rs:22:5 - | -LL | return true; - | ^^^^^^^^^^^^ help: remove `return`: `true` - -error: unneeded `return` statement - --> $DIR/needless_return.rs:27:9 - | -LL | return true; - | ^^^^^^^^^^^^ help: remove `return`: `true` - -error: unneeded `return` statement - --> $DIR/needless_return.rs:29:9 - | -LL | return false; - | ^^^^^^^^^^^^^ help: remove `return`: `false` - -error: unneeded `return` statement - --> $DIR/needless_return.rs:35:17 - | -LL | true => return false, - | ^^^^^^^^^^^^ help: remove `return`: `false` - -error: unneeded `return` statement - --> $DIR/needless_return.rs:37:13 - | -LL | return true; - | ^^^^^^^^^^^^ help: remove `return`: `true` - -error: unneeded `return` statement - --> $DIR/needless_return.rs:44:9 - | -LL | return true; - | ^^^^^^^^^^^^ help: remove `return`: `true` - -error: unneeded `return` statement - --> $DIR/needless_return.rs:46:16 - | -LL | let _ = || return true; - | ^^^^^^^^^^^ help: remove `return`: `true` - -error: unneeded `return` statement - --> $DIR/needless_return.rs:54:5 - | -LL | return; - | ^^^^^^^ help: remove `return` - -error: unneeded `return` statement - --> $DIR/needless_return.rs:59:9 - | -LL | return; - | ^^^^^^^ help: remove `return` - -error: unneeded `return` statement - --> $DIR/needless_return.rs:61:9 - | -LL | return; - | ^^^^^^^ help: remove `return` - -error: unneeded `return` statement - --> $DIR/needless_return.rs:68:14 - | -LL | _ => return, - | ^^^^^^ help: replace `return` with an empty block: `{}` - -error: unneeded `return` statement - --> $DIR/needless_return.rs:83:9 - | -LL | return String::from("test"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::from("test")` - -error: unneeded `return` statement - --> $DIR/needless_return.rs:85:9 - | -LL | return String::new(); - | ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::new()` - -error: aborting due to 14 previous errors - diff --git a/tests/ui/needless_update.rs b/tests/ui/needless_update.rs deleted file mode 100644 index b93ff048a62f..000000000000 --- a/tests/ui/needless_update.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![warn(clippy::needless_update)] -#![allow(clippy::no_effect)] - -struct S { - pub a: i32, - pub b: i32, -} - -#[non_exhaustive] -struct T { - pub x: i32, - pub y: i32, -} - -fn main() { - let base = S { a: 0, b: 0 }; - S { ..base }; // no error - S { a: 1, ..base }; // no error - S { a: 1, b: 1, ..base }; - - let base = T { x: 0, y: 0 }; - T { ..base }; // no error - T { x: 1, ..base }; // no error - T { x: 1, y: 1, ..base }; // no error -} diff --git a/tests/ui/needless_update.stderr b/tests/ui/needless_update.stderr deleted file mode 100644 index b154b3b306dd..000000000000 --- a/tests/ui/needless_update.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: struct update has no effect, all the fields in the struct have already been specified - --> $DIR/needless_update.rs:19:23 - | -LL | S { a: 1, b: 1, ..base }; - | ^^^^ - | - = note: `-D clippy::needless-update` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/neg_cmp_op_on_partial_ord.rs b/tests/ui/neg_cmp_op_on_partial_ord.rs deleted file mode 100644 index 2d392c593b3e..000000000000 --- a/tests/ui/neg_cmp_op_on_partial_ord.rs +++ /dev/null @@ -1,62 +0,0 @@ -//! This test case utilizes `f64` an easy example for `PartialOrd` only types -//! but the lint itself actually validates any expression where the left -//! operand implements `PartialOrd` but not `Ord`. - -use std::cmp::Ordering; - -#[allow(clippy::unnested_or_patterns, clippy::match_like_matches_macro)] -#[warn(clippy::neg_cmp_op_on_partial_ord)] -fn main() { - let a_value = 1.0; - let another_value = 7.0; - - // --- Bad --- - - // Not Less but potentially Greater, Equal or Uncomparable. - let _not_less = !(a_value < another_value); - - // Not Less or Equal but potentially Greater or Uncomparable. - let _not_less_or_equal = !(a_value <= another_value); - - // Not Greater but potentially Less, Equal or Uncomparable. - let _not_greater = !(a_value > another_value); - - // Not Greater or Equal but potentially Less or Uncomparable. - let _not_greater_or_equal = !(a_value >= another_value); - - // --- Good --- - - let _not_less = match a_value.partial_cmp(&another_value) { - None | Some(Ordering::Greater) | Some(Ordering::Equal) => true, - _ => false, - }; - let _not_less_or_equal = match a_value.partial_cmp(&another_value) { - None | Some(Ordering::Greater) => true, - _ => false, - }; - let _not_greater = match a_value.partial_cmp(&another_value) { - None | Some(Ordering::Less) | Some(Ordering::Equal) => true, - _ => false, - }; - let _not_greater_or_equal = match a_value.partial_cmp(&another_value) { - None | Some(Ordering::Less) => true, - _ => false, - }; - - // --- Should not trigger --- - - let _ = a_value < another_value; - let _ = a_value <= another_value; - let _ = a_value > another_value; - let _ = a_value >= another_value; - - // --- regression tests --- - - // Issue 2856: False positive on assert!() - // - // The macro always negates the result of the given comparison in its - // internal check which automatically triggered the lint. As it's an - // external macro there was no chance to do anything about it which led - // to an exempting of all external macros. - assert!(a_value < another_value); -} diff --git a/tests/ui/neg_cmp_op_on_partial_ord.stderr b/tests/ui/neg_cmp_op_on_partial_ord.stderr deleted file mode 100644 index c78560007217..000000000000 --- a/tests/ui/neg_cmp_op_on_partial_ord.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: the use of negated comparison operators on partially ordered types produces code that is hard to read and refactor, please consider using the `partial_cmp` method instead, to make it clear that the two values could be incomparable - --> $DIR/neg_cmp_op_on_partial_ord.rs:16:21 - | -LL | let _not_less = !(a_value < another_value); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::neg-cmp-op-on-partial-ord` implied by `-D warnings` - -error: the use of negated comparison operators on partially ordered types produces code that is hard to read and refactor, please consider using the `partial_cmp` method instead, to make it clear that the two values could be incomparable - --> $DIR/neg_cmp_op_on_partial_ord.rs:19:30 - | -LL | let _not_less_or_equal = !(a_value <= another_value); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the use of negated comparison operators on partially ordered types produces code that is hard to read and refactor, please consider using the `partial_cmp` method instead, to make it clear that the two values could be incomparable - --> $DIR/neg_cmp_op_on_partial_ord.rs:22:24 - | -LL | let _not_greater = !(a_value > another_value); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the use of negated comparison operators on partially ordered types produces code that is hard to read and refactor, please consider using the `partial_cmp` method instead, to make it clear that the two values could be incomparable - --> $DIR/neg_cmp_op_on_partial_ord.rs:25:33 - | -LL | let _not_greater_or_equal = !(a_value >= another_value); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 4 previous errors - diff --git a/tests/ui/neg_multiply.rs b/tests/ui/neg_multiply.rs deleted file mode 100644 index d4a20ce9db1c..000000000000 --- a/tests/ui/neg_multiply.rs +++ /dev/null @@ -1,35 +0,0 @@ -#![warn(clippy::neg_multiply)] -#![allow(clippy::no_effect, clippy::unnecessary_operation)] - -use std::ops::Mul; - -struct X; - -impl Mul for X { - type Output = X; - - fn mul(self, _r: isize) -> Self { - self - } -} - -impl Mul for isize { - type Output = X; - - fn mul(self, _r: X) -> X { - X - } -} - -fn main() { - let x = 0; - - x * -1; - - -1 * x; - - -1 * -1; // should be ok - - X * -1; // should be ok - -1 * X; // should also be ok -} diff --git a/tests/ui/neg_multiply.stderr b/tests/ui/neg_multiply.stderr deleted file mode 100644 index ad677f6d6fb9..000000000000 --- a/tests/ui/neg_multiply.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: negation by multiplying with `-1` - --> $DIR/neg_multiply.rs:27:5 - | -LL | x * -1; - | ^^^^^^ - | - = note: `-D clippy::neg-multiply` implied by `-D warnings` - -error: negation by multiplying with `-1` - --> $DIR/neg_multiply.rs:29:5 - | -LL | -1 * x; - | ^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/never_loop.rs b/tests/ui/never_loop.rs deleted file mode 100644 index 2770eb2b2ab4..000000000000 --- a/tests/ui/never_loop.rs +++ /dev/null @@ -1,204 +0,0 @@ -#![allow( - clippy::single_match, - unused_assignments, - unused_variables, - clippy::while_immutable_condition -)] - -fn test1() { - let mut x = 0; - loop { - // clippy::never_loop - x += 1; - if x == 1 { - return; - } - break; - } -} - -fn test2() { - let mut x = 0; - loop { - x += 1; - if x == 1 { - break; - } - } -} - -fn test3() { - let mut x = 0; - loop { - // never loops - x += 1; - break; - } -} - -fn test4() { - let mut x = 1; - loop { - x += 1; - match x { - 5 => return, - _ => (), - } - } -} - -fn test5() { - let i = 0; - loop { - // never loops - while i == 0 { - // never loops - break; - } - return; - } -} - -fn test6() { - let mut x = 0; - 'outer: loop { - x += 1; - loop { - // never loops - if x == 5 { - break; - } - continue 'outer; - } - return; - } -} - -fn test7() { - let mut x = 0; - loop { - x += 1; - match x { - 1 => continue, - _ => (), - } - return; - } -} - -fn test8() { - let mut x = 0; - loop { - x += 1; - match x { - 5 => return, - _ => continue, - } - } -} - -fn test9() { - let x = Some(1); - while let Some(y) = x { - // never loops - return; - } -} - -fn test10() { - for x in 0..10 { - // never loops - match x { - 1 => break, - _ => return, - } - } -} - -fn test11 i32>(mut f: F) { - loop { - return match f() { - 1 => continue, - _ => (), - }; - } -} - -pub fn test12(a: bool, b: bool) { - 'label: loop { - loop { - if a { - continue 'label; - } - if b { - break; - } - } - break; - } -} - -pub fn test13() { - let mut a = true; - loop { - // infinite loop - while a { - if true { - a = false; - continue; - } - return; - } - } -} - -pub fn test14() { - let mut a = true; - 'outer: while a { - // never loops - while a { - if a { - a = false; - continue; - } - } - break 'outer; - } -} - -// Issue #1991: the outer loop should not warn. -pub fn test15() { - 'label: loop { - while false { - break 'label; - } - } -} - -// Issue #4058: `continue` in `break` expression -pub fn test16() { - let mut n = 1; - loop { - break if n != 5 { - n += 1; - continue; - }; - } -} - -fn main() { - test1(); - test2(); - test3(); - test4(); - test5(); - test6(); - test7(); - test8(); - test9(); - test10(); - test11(|| 0); - test12(true, false); - test13(); - test14(); -} diff --git a/tests/ui/never_loop.stderr b/tests/ui/never_loop.stderr deleted file mode 100644 index c00b4c78cf28..000000000000 --- a/tests/ui/never_loop.stderr +++ /dev/null @@ -1,100 +0,0 @@ -error: this loop never actually loops - --> $DIR/never_loop.rs:10:5 - | -LL | / loop { -LL | | // clippy::never_loop -LL | | x += 1; -LL | | if x == 1 { -... | -LL | | break; -LL | | } - | |_____^ - | - = note: `#[deny(clippy::never_loop)]` on by default - -error: this loop never actually loops - --> $DIR/never_loop.rs:32:5 - | -LL | / loop { -LL | | // never loops -LL | | x += 1; -LL | | break; -LL | | } - | |_____^ - -error: this loop never actually loops - --> $DIR/never_loop.rs:52:5 - | -LL | / loop { -LL | | // never loops -LL | | while i == 0 { -LL | | // never loops -... | -LL | | return; -LL | | } - | |_____^ - -error: this loop never actually loops - --> $DIR/never_loop.rs:54:9 - | -LL | / while i == 0 { -LL | | // never loops -LL | | break; -LL | | } - | |_________^ - -error: this loop never actually loops - --> $DIR/never_loop.rs:66:9 - | -LL | / loop { -LL | | // never loops -LL | | if x == 5 { -LL | | break; -LL | | } -LL | | continue 'outer; -LL | | } - | |_________^ - -error: this loop never actually loops - --> $DIR/never_loop.rs:102:5 - | -LL | / while let Some(y) = x { -LL | | // never loops -LL | | return; -LL | | } - | |_____^ - -error: this loop never actually loops - --> $DIR/never_loop.rs:109:5 - | -LL | / for x in 0..10 { -LL | | // never loops -LL | | match x { -LL | | 1 => break, -LL | | _ => return, -LL | | } -LL | | } - | |_____^ - -error: this loop never actually loops - --> $DIR/never_loop.rs:157:5 - | -LL | / 'outer: while a { -LL | | // never loops -LL | | while a { -LL | | if a { -... | -LL | | break 'outer; -LL | | } - | |_____^ - -error: this loop never actually loops - --> $DIR/never_loop.rs:172:9 - | -LL | / while false { -LL | | break 'label; -LL | | } - | |_________^ - -error: aborting due to 9 previous errors - diff --git a/tests/ui/new_ret_no_self.rs b/tests/ui/new_ret_no_self.rs deleted file mode 100644 index e82873629a54..000000000000 --- a/tests/ui/new_ret_no_self.rs +++ /dev/null @@ -1,342 +0,0 @@ -#![warn(clippy::new_ret_no_self)] -#![allow(dead_code)] - -fn main() {} - -trait R { - type Item; -} - -trait Q { - type Item; - type Item2; -} - -struct S; - -impl R for S { - type Item = Self; -} - -impl S { - // should not trigger the lint - pub fn new() -> impl R { - S - } -} - -struct S2; - -impl R for S2 { - type Item = Self; -} - -impl S2 { - // should not trigger the lint - pub fn new(_: String) -> impl R { - S2 - } -} - -struct S3; - -impl R for S3 { - type Item = u32; -} - -impl S3 { - // should trigger the lint - pub fn new(_: String) -> impl R { - S3 - } -} - -struct S4; - -impl Q for S4 { - type Item = u32; - type Item2 = Self; -} - -impl S4 { - // should not trigger the lint - pub fn new(_: String) -> impl Q { - S4 - } -} - -struct T; - -impl T { - // should not trigger lint - pub fn new() -> Self { - unimplemented!(); - } -} - -struct U; - -impl U { - // should trigger lint - pub fn new() -> u32 { - unimplemented!(); - } -} - -struct V; - -impl V { - // should trigger lint - pub fn new(_: String) -> u32 { - unimplemented!(); - } -} - -struct TupleReturnerOk; - -impl TupleReturnerOk { - // should not trigger lint - pub fn new() -> (Self, u32) { - unimplemented!(); - } -} - -struct TupleReturnerOk2; - -impl TupleReturnerOk2 { - // should not trigger lint (it doesn't matter which element in the tuple is Self) - pub fn new() -> (u32, Self) { - unimplemented!(); - } -} - -struct TupleReturnerOk3; - -impl TupleReturnerOk3 { - // should not trigger lint (tuple can contain multiple Self) - pub fn new() -> (Self, Self) { - unimplemented!(); - } -} - -struct TupleReturnerBad; - -impl TupleReturnerBad { - // should trigger lint - pub fn new() -> (u32, u32) { - unimplemented!(); - } -} - -struct MutPointerReturnerOk; - -impl MutPointerReturnerOk { - // should not trigger lint - pub fn new() -> *mut Self { - unimplemented!(); - } -} - -struct ConstPointerReturnerOk2; - -impl ConstPointerReturnerOk2 { - // should not trigger lint - pub fn new() -> *const Self { - unimplemented!(); - } -} - -struct MutPointerReturnerBad; - -impl MutPointerReturnerBad { - // should trigger lint - pub fn new() -> *mut V { - unimplemented!(); - } -} - -struct GenericReturnerOk; - -impl GenericReturnerOk { - // should not trigger lint - pub fn new() -> Option { - unimplemented!(); - } -} - -struct GenericReturnerBad; - -impl GenericReturnerBad { - // should trigger lint - pub fn new() -> Option { - unimplemented!(); - } -} - -struct NestedReturnerOk; - -impl NestedReturnerOk { - // should not trigger lint - pub fn new() -> (Option, u32) { - unimplemented!(); - } -} - -struct NestedReturnerOk2; - -impl NestedReturnerOk2 { - // should not trigger lint - pub fn new() -> ((Self, u32), u32) { - unimplemented!(); - } -} - -struct NestedReturnerOk3; - -impl NestedReturnerOk3 { - // should not trigger lint - pub fn new() -> Option<(Self, u32)> { - unimplemented!(); - } -} - -struct WithLifetime<'a> { - cat: &'a str, -} - -impl<'a> WithLifetime<'a> { - // should not trigger the lint, because the lifetimes are different - pub fn new<'b: 'a>(s: &'b str) -> WithLifetime<'b> { - unimplemented!(); - } -} - -mod issue5435 { - struct V; - - pub trait TraitRetSelf { - // should not trigger lint - fn new() -> Self; - } - - pub trait TraitRet { - // should trigger lint as we are in trait definition - fn new() -> String; - } - pub struct StructRet; - impl TraitRet for StructRet { - // should not trigger lint as we are in the impl block - fn new() -> String { - unimplemented!(); - } - } - - pub trait TraitRet2 { - // should trigger lint - fn new(_: String) -> String; - } - - trait TupleReturnerOk { - // should not trigger lint - fn new() -> (Self, u32) - where - Self: Sized, - { - unimplemented!(); - } - } - - trait TupleReturnerOk2 { - // should not trigger lint (it doesn't matter which element in the tuple is Self) - fn new() -> (u32, Self) - where - Self: Sized, - { - unimplemented!(); - } - } - - trait TupleReturnerOk3 { - // should not trigger lint (tuple can contain multiple Self) - fn new() -> (Self, Self) - where - Self: Sized, - { - unimplemented!(); - } - } - - trait TupleReturnerBad { - // should trigger lint - fn new() -> (u32, u32) { - unimplemented!(); - } - } - - trait MutPointerReturnerOk { - // should not trigger lint - fn new() -> *mut Self - where - Self: Sized, - { - unimplemented!(); - } - } - - trait ConstPointerReturnerOk2 { - // should not trigger lint - fn new() -> *const Self - where - Self: Sized, - { - unimplemented!(); - } - } - - trait MutPointerReturnerBad { - // should trigger lint - fn new() -> *mut V { - unimplemented!(); - } - } - - trait GenericReturnerOk { - // should not trigger lint - fn new() -> Option - where - Self: Sized, - { - unimplemented!(); - } - } - - trait NestedReturnerOk { - // should not trigger lint - fn new() -> (Option, u32) - where - Self: Sized, - { - unimplemented!(); - } - } - - trait NestedReturnerOk2 { - // should not trigger lint - fn new() -> ((Self, u32), u32) - where - Self: Sized, - { - unimplemented!(); - } - } - - trait NestedReturnerOk3 { - // should not trigger lint - fn new() -> Option<(Self, u32)> - where - Self: Sized, - { - unimplemented!(); - } - } -} diff --git a/tests/ui/new_ret_no_self.stderr b/tests/ui/new_ret_no_self.stderr deleted file mode 100644 index 8217bc6187f9..000000000000 --- a/tests/ui/new_ret_no_self.stderr +++ /dev/null @@ -1,80 +0,0 @@ -error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:49:5 - | -LL | / pub fn new(_: String) -> impl R { -LL | | S3 -LL | | } - | |_____^ - | - = note: `-D clippy::new-ret-no-self` implied by `-D warnings` - -error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:81:5 - | -LL | / pub fn new() -> u32 { -LL | | unimplemented!(); -LL | | } - | |_____^ - -error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:90:5 - | -LL | / pub fn new(_: String) -> u32 { -LL | | unimplemented!(); -LL | | } - | |_____^ - -error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:126:5 - | -LL | / pub fn new() -> (u32, u32) { -LL | | unimplemented!(); -LL | | } - | |_____^ - -error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:153:5 - | -LL | / pub fn new() -> *mut V { -LL | | unimplemented!(); -LL | | } - | |_____^ - -error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:171:5 - | -LL | / pub fn new() -> Option { -LL | | unimplemented!(); -LL | | } - | |_____^ - -error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:224:9 - | -LL | fn new() -> String; - | ^^^^^^^^^^^^^^^^^^^ - -error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:236:9 - | -LL | fn new(_: String) -> String; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:271:9 - | -LL | / fn new() -> (u32, u32) { -LL | | unimplemented!(); -LL | | } - | |_________^ - -error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:298:9 - | -LL | / fn new() -> *mut V { -LL | | unimplemented!(); -LL | | } - | |_________^ - -error: aborting due to 10 previous errors - diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs deleted file mode 100644 index 3b6041823d87..000000000000 --- a/tests/ui/new_without_default.rs +++ /dev/null @@ -1,162 +0,0 @@ -#![feature(const_fn)] -#![allow(dead_code, clippy::missing_safety_doc)] -#![warn(clippy::new_without_default)] - -pub struct Foo; - -impl Foo { - pub fn new() -> Foo { - Foo - } -} - -pub struct Bar; - -impl Bar { - pub fn new() -> Self { - Bar - } -} - -pub struct Ok; - -impl Ok { - pub fn new() -> Self { - Ok - } -} - -impl Default for Ok { - fn default() -> Self { - Ok - } -} - -pub struct Params; - -impl Params { - pub fn new(_: u32) -> Self { - Params - } -} - -pub struct GenericsOk { - bar: T, -} - -impl Default for GenericsOk { - fn default() -> Self { - unimplemented!(); - } -} - -impl<'c, V> GenericsOk { - pub fn new() -> GenericsOk { - unimplemented!() - } -} - -pub struct LtOk<'a> { - foo: &'a bool, -} - -impl<'b> Default for LtOk<'b> { - fn default() -> Self { - unimplemented!(); - } -} - -impl<'c> LtOk<'c> { - pub fn new() -> LtOk<'c> { - unimplemented!() - } -} - -pub struct LtKo<'a> { - foo: &'a bool, -} - -impl<'c> LtKo<'c> { - pub fn new() -> LtKo<'c> { - unimplemented!() - } - // FIXME: that suggestion is missing lifetimes -} - -struct Private; - -impl Private { - fn new() -> Private { - unimplemented!() - } // We don't lint private items -} - -struct Const; - -impl Const { - pub const fn new() -> Const { - Const - } // const fns can't be implemented via Default -} - -pub struct IgnoreGenericNew; - -impl IgnoreGenericNew { - pub fn new() -> Self { - IgnoreGenericNew - } // the derived Default does not make sense here as the result depends on T -} - -pub trait TraitWithNew: Sized { - fn new() -> Self { - panic!() - } -} - -pub struct IgnoreUnsafeNew; - -impl IgnoreUnsafeNew { - pub unsafe fn new() -> Self { - IgnoreUnsafeNew - } -} - -#[derive(Default)] -pub struct OptionRefWrapper<'a, T>(Option<&'a T>); - -impl<'a, T> OptionRefWrapper<'a, T> { - pub fn new() -> Self { - OptionRefWrapper(None) - } -} - -pub struct Allow(Foo); - -impl Allow { - #[allow(clippy::new_without_default)] - pub fn new() -> Self { - unimplemented!() - } -} - -pub struct AllowDerive; - -impl AllowDerive { - #[allow(clippy::new_without_default)] - pub fn new() -> Self { - unimplemented!() - } -} - -pub struct NewNotEqualToDerive { - foo: i32, -} - -impl NewNotEqualToDerive { - // This `new` implementation is not equal to a derived `Default`, so do not suggest deriving. - pub fn new() -> Self { - NewNotEqualToDerive { foo: 1 } - } -} - -fn main() {} diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr deleted file mode 100644 index e529e441eb73..000000000000 --- a/tests/ui/new_without_default.stderr +++ /dev/null @@ -1,71 +0,0 @@ -error: you should consider adding a `Default` implementation for `Foo` - --> $DIR/new_without_default.rs:8:5 - | -LL | / pub fn new() -> Foo { -LL | | Foo -LL | | } - | |_____^ - | - = note: `-D clippy::new-without-default` implied by `-D warnings` -help: try this - | -LL | impl Default for Foo { -LL | fn default() -> Self { -LL | Self::new() -LL | } -LL | } - | - -error: you should consider adding a `Default` implementation for `Bar` - --> $DIR/new_without_default.rs:16:5 - | -LL | / pub fn new() -> Self { -LL | | Bar -LL | | } - | |_____^ - | -help: try this - | -LL | impl Default for Bar { -LL | fn default() -> Self { -LL | Self::new() -LL | } -LL | } - | - -error: you should consider adding a `Default` implementation for `LtKo<'c>` - --> $DIR/new_without_default.rs:80:5 - | -LL | / pub fn new() -> LtKo<'c> { -LL | | unimplemented!() -LL | | } - | |_____^ - | -help: try this - | -LL | impl Default for LtKo<'c> { -LL | fn default() -> Self { -LL | Self::new() -LL | } -LL | } - | - -error: you should consider adding a `Default` implementation for `NewNotEqualToDerive` - --> $DIR/new_without_default.rs:157:5 - | -LL | / pub fn new() -> Self { -LL | | NewNotEqualToDerive { foo: 1 } -LL | | } - | |_____^ - | -help: try this - | -LL | impl Default for NewNotEqualToDerive { -LL | fn default() -> Self { -LL | Self::new() -LL | } -LL | } - | - -error: aborting due to 4 previous errors - diff --git a/tests/ui/no_effect.rs b/tests/ui/no_effect.rs deleted file mode 100644 index 8fbfcb79860a..000000000000 --- a/tests/ui/no_effect.rs +++ /dev/null @@ -1,102 +0,0 @@ -#![feature(box_syntax)] -#![warn(clippy::no_effect)] -#![allow(dead_code)] -#![allow(path_statements)] -#![allow(clippy::deref_addrof)] -#![allow(clippy::redundant_field_names)] -#![feature(untagged_unions)] - -struct Unit; -struct Tuple(i32); -struct Struct { - field: i32, -} -enum Enum { - Tuple(i32), - Struct { field: i32 }, -} -struct DropUnit; -impl Drop for DropUnit { - fn drop(&mut self) {} -} -struct DropStruct { - field: i32, -} -impl Drop for DropStruct { - fn drop(&mut self) {} -} -struct DropTuple(i32); -impl Drop for DropTuple { - fn drop(&mut self) {} -} -enum DropEnum { - Tuple(i32), - Struct { field: i32 }, -} -impl Drop for DropEnum { - fn drop(&mut self) {} -} -struct FooString { - s: String, -} -union Union { - a: u8, - b: f64, -} - -fn get_number() -> i32 { - 0 -} -fn get_struct() -> Struct { - Struct { field: 0 } -} -fn get_drop_struct() -> DropStruct { - DropStruct { field: 0 } -} - -unsafe fn unsafe_fn() -> i32 { - 0 -} - -fn main() { - let s = get_struct(); - let s2 = get_struct(); - - 0; - s2; - Unit; - Tuple(0); - Struct { field: 0 }; - Struct { ..s }; - Union { a: 0 }; - Enum::Tuple(0); - Enum::Struct { field: 0 }; - 5 + 6; - *&42; - &6; - (5, 6, 7); - box 42; - ..; - 5..; - ..5; - 5..6; - 5..=6; - [42, 55]; - [42, 55][1]; - (42, 55).1; - [42; 55]; - [42; 55][13]; - let mut x = 0; - || x += 5; - let s: String = "foo".into(); - FooString { s: s }; - - // Do not warn - get_number(); - unsafe { unsafe_fn() }; - DropUnit; - DropStruct { field: 0 }; - DropTuple(0); - DropEnum::Tuple(0); - DropEnum::Struct { field: 0 }; -} diff --git a/tests/ui/no_effect.stderr b/tests/ui/no_effect.stderr deleted file mode 100644 index 834b9056e311..000000000000 --- a/tests/ui/no_effect.stderr +++ /dev/null @@ -1,154 +0,0 @@ -error: statement with no effect - --> $DIR/no_effect.rs:65:5 - | -LL | 0; - | ^^ - | - = note: `-D clippy::no-effect` implied by `-D warnings` - -error: statement with no effect - --> $DIR/no_effect.rs:66:5 - | -LL | s2; - | ^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:67:5 - | -LL | Unit; - | ^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:68:5 - | -LL | Tuple(0); - | ^^^^^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:69:5 - | -LL | Struct { field: 0 }; - | ^^^^^^^^^^^^^^^^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:70:5 - | -LL | Struct { ..s }; - | ^^^^^^^^^^^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:71:5 - | -LL | Union { a: 0 }; - | ^^^^^^^^^^^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:72:5 - | -LL | Enum::Tuple(0); - | ^^^^^^^^^^^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:73:5 - | -LL | Enum::Struct { field: 0 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:74:5 - | -LL | 5 + 6; - | ^^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:75:5 - | -LL | *&42; - | ^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:76:5 - | -LL | &6; - | ^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:77:5 - | -LL | (5, 6, 7); - | ^^^^^^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:78:5 - | -LL | box 42; - | ^^^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:79:5 - | -LL | ..; - | ^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:80:5 - | -LL | 5..; - | ^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:81:5 - | -LL | ..5; - | ^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:82:5 - | -LL | 5..6; - | ^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:84:5 - | -LL | [42, 55]; - | ^^^^^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:85:5 - | -LL | [42, 55][1]; - | ^^^^^^^^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:86:5 - | -LL | (42, 55).1; - | ^^^^^^^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:87:5 - | -LL | [42; 55]; - | ^^^^^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:88:5 - | -LL | [42; 55][13]; - | ^^^^^^^^^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:90:5 - | -LL | || x += 5; - | ^^^^^^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:92:5 - | -LL | FooString { s: s }; - | ^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 25 previous errors - diff --git a/tests/ui/non_expressive_names.rs b/tests/ui/non_expressive_names.rs deleted file mode 100644 index 58415b4aede2..000000000000 --- a/tests/ui/non_expressive_names.rs +++ /dev/null @@ -1,56 +0,0 @@ -#![warn(clippy::all)] -#![allow(unused, clippy::println_empty_string)] - -#[derive(Clone, Debug)] -enum MaybeInst { - Split, - Split1(usize), - Split2(usize), -} - -struct InstSplit { - uiae: usize, -} - -impl MaybeInst { - fn fill(&mut self) { - let filled = match *self { - MaybeInst::Split1(goto1) => panic!(1), - MaybeInst::Split2(goto2) => panic!(2), - _ => unimplemented!(), - }; - unimplemented!() - } -} - -fn underscores_and_numbers() { - let _1 = 1; //~ERROR Consider a more descriptive name - let ____1 = 1; //~ERROR Consider a more descriptive name - let __1___2 = 12; //~ERROR Consider a more descriptive name - let _1_ok = 1; -} - -fn issue2927() { - let args = 1; - format!("{:?}", 2); -} - -fn issue3078() { - match "a" { - stringify!(a) => {}, - _ => {}, - } -} - -struct Bar; - -impl Bar { - fn bar() { - let _1 = 1; - let ____1 = 1; - let __1___2 = 12; - let _1_ok = 1; - } -} - -fn main() {} diff --git a/tests/ui/non_expressive_names.stderr b/tests/ui/non_expressive_names.stderr deleted file mode 100644 index a0ca46f0efc6..000000000000 --- a/tests/ui/non_expressive_names.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: consider choosing a more descriptive name - --> $DIR/non_expressive_names.rs:27:9 - | -LL | let _1 = 1; //~ERROR Consider a more descriptive name - | ^^ - | - = note: `-D clippy::just-underscores-and-digits` implied by `-D warnings` - -error: consider choosing a more descriptive name - --> $DIR/non_expressive_names.rs:28:9 - | -LL | let ____1 = 1; //~ERROR Consider a more descriptive name - | ^^^^^ - -error: consider choosing a more descriptive name - --> $DIR/non_expressive_names.rs:29:9 - | -LL | let __1___2 = 12; //~ERROR Consider a more descriptive name - | ^^^^^^^ - -error: consider choosing a more descriptive name - --> $DIR/non_expressive_names.rs:49:13 - | -LL | let _1 = 1; - | ^^ - -error: consider choosing a more descriptive name - --> $DIR/non_expressive_names.rs:50:13 - | -LL | let ____1 = 1; - | ^^^^^ - -error: consider choosing a more descriptive name - --> $DIR/non_expressive_names.rs:51:13 - | -LL | let __1___2 = 12; - | ^^^^^^^ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/non_expressive_names.stdout b/tests/ui/non_expressive_names.stdout deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/tests/ui/nonminimal_bool.rs b/tests/ui/nonminimal_bool.rs deleted file mode 100644 index 971be26278f3..000000000000 --- a/tests/ui/nonminimal_bool.rs +++ /dev/null @@ -1,52 +0,0 @@ -#![allow(unused, clippy::many_single_char_names, clippy::diverging_sub_expression)] -#![warn(clippy::nonminimal_bool)] - -fn main() { - let a: bool = unimplemented!(); - let b: bool = unimplemented!(); - let c: bool = unimplemented!(); - let d: bool = unimplemented!(); - let e: bool = unimplemented!(); - let _ = !true; - let _ = !false; - let _ = !!a; - let _ = false || a; - // don't lint on cfgs - let _ = cfg!(you_shall_not_not_pass) && a; - let _ = a || !b || !c || !d || !e; - let _ = !(!a && b); - let _ = !(!a || b); - let _ = !a && !(b && c); -} - -fn equality_stuff() { - let a: i32 = unimplemented!(); - let b: i32 = unimplemented!(); - let c: i32 = unimplemented!(); - let d: i32 = unimplemented!(); - let _ = a == b && c == 5 && a == b; - let _ = a == b || c == 5 || a == b; - let _ = a == b && c == 5 && b == a; - let _ = a != b || !(a != b || c == d); - let _ = a != b && !(a != b && c == d); -} - -fn issue3847(a: u32, b: u32) -> bool { - const THRESHOLD: u32 = 1_000; - - if a < THRESHOLD && b >= THRESHOLD || a >= THRESHOLD && b < THRESHOLD { - return false; - } - true -} - -fn issue4548() { - fn f(_i: u32, _j: u32) -> u32 { - unimplemented!(); - } - - let i = 0; - let j = 0; - - if i != j && f(i, j) != 0 || i == j && f(i, j) != 1 {} -} diff --git a/tests/ui/nonminimal_bool.stderr b/tests/ui/nonminimal_bool.stderr deleted file mode 100644 index d34d106cb2fb..000000000000 --- a/tests/ui/nonminimal_bool.stderr +++ /dev/null @@ -1,111 +0,0 @@ -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:10:13 - | -LL | let _ = !true; - | ^^^^^ help: try: `false` - | - = note: `-D clippy::nonminimal-bool` implied by `-D warnings` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:11:13 - | -LL | let _ = !false; - | ^^^^^^ help: try: `true` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:12:13 - | -LL | let _ = !!a; - | ^^^ help: try: `a` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:13:13 - | -LL | let _ = false || a; - | ^^^^^^^^^^ help: try: `a` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:17:13 - | -LL | let _ = !(!a && b); - | ^^^^^^^^^^ help: try: `a || !b` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:18:13 - | -LL | let _ = !(!a || b); - | ^^^^^^^^^^ help: try: `a && !b` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:19:13 - | -LL | let _ = !a && !(b && c); - | ^^^^^^^^^^^^^^^ help: try: `!(a || b && c)` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:27:13 - | -LL | let _ = a == b && c == 5 && a == b; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: try - | -LL | let _ = a == b && c == 5; - | ^^^^^^^^^^^^^^^^ -LL | let _ = !(a != b || c != 5); - | ^^^^^^^^^^^^^^^^^^^ - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:28:13 - | -LL | let _ = a == b || c == 5 || a == b; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: try - | -LL | let _ = a == b || c == 5; - | ^^^^^^^^^^^^^^^^ -LL | let _ = !(a != b && c != 5); - | ^^^^^^^^^^^^^^^^^^^ - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:29:13 - | -LL | let _ = a == b && c == 5 && b == a; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: try - | -LL | let _ = a == b && c == 5; - | ^^^^^^^^^^^^^^^^ -LL | let _ = !(a != b || c != 5); - | ^^^^^^^^^^^^^^^^^^^ - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:30:13 - | -LL | let _ = a != b || !(a != b || c == d); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: try - | -LL | let _ = a != b || c != d; - | ^^^^^^^^^^^^^^^^ -LL | let _ = !(a == b && c == d); - | ^^^^^^^^^^^^^^^^^^^ - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:31:13 - | -LL | let _ = a != b && !(a != b && c == d); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: try - | -LL | let _ = a != b && c != d; - | ^^^^^^^^^^^^^^^^ -LL | let _ = !(a == b || c == d); - | ^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 12 previous errors - diff --git a/tests/ui/nonminimal_bool_methods.rs b/tests/ui/nonminimal_bool_methods.rs deleted file mode 100644 index 907587402908..000000000000 --- a/tests/ui/nonminimal_bool_methods.rs +++ /dev/null @@ -1,110 +0,0 @@ -#![allow(unused, clippy::many_single_char_names, clippy::diverging_sub_expression)] -#![warn(clippy::nonminimal_bool)] - -fn methods_with_negation() { - let a: Option = unimplemented!(); - let b: Result = unimplemented!(); - let _ = a.is_some(); - let _ = !a.is_some(); - let _ = a.is_none(); - let _ = !a.is_none(); - let _ = b.is_err(); - let _ = !b.is_err(); - let _ = b.is_ok(); - let _ = !b.is_ok(); - let c = false; - let _ = !(a.is_some() && !c); - let _ = !(a.is_some() || !c); - let _ = !(!c ^ c) || !a.is_some(); - let _ = (!c ^ c) || !a.is_some(); - let _ = !c ^ c || !a.is_some(); -} - -// Simplified versions of https://github.com/rust-lang/rust-clippy/issues/2638 -// clippy::nonminimal_bool should only check the built-in Result and Some type, not -// any other types like the following. -enum CustomResultOk { - Ok, - Err(E), -} -enum CustomResultErr { - Ok, - Err(E), -} -enum CustomSomeSome { - Some(T), - None, -} -enum CustomSomeNone { - Some(T), - None, -} - -impl CustomResultOk { - pub fn is_ok(&self) -> bool { - true - } -} - -impl CustomResultErr { - pub fn is_err(&self) -> bool { - true - } -} - -impl CustomSomeSome { - pub fn is_some(&self) -> bool { - true - } -} - -impl CustomSomeNone { - pub fn is_none(&self) -> bool { - true - } -} - -fn dont_warn_for_custom_methods_with_negation() { - let res = CustomResultOk::Err("Error"); - // Should not warn and suggest 'is_err()' because the type does not - // implement is_err(). - if !res.is_ok() {} - - let res = CustomResultErr::Err("Error"); - // Should not warn and suggest 'is_ok()' because the type does not - // implement is_ok(). - if !res.is_err() {} - - let res = CustomSomeSome::Some("thing"); - // Should not warn and suggest 'is_none()' because the type does not - // implement is_none(). - if !res.is_some() {} - - let res = CustomSomeNone::Some("thing"); - // Should not warn and suggest 'is_some()' because the type does not - // implement is_some(). - if !res.is_none() {} -} - -// Only Built-in Result and Some types should suggest the negated alternative -fn warn_for_built_in_methods_with_negation() { - let res: Result = Ok(1); - if !res.is_ok() {} - if !res.is_err() {} - - let res = Some(1); - if !res.is_some() {} - if !res.is_none() {} -} - -#[allow(clippy::neg_cmp_op_on_partial_ord)] -fn dont_warn_for_negated_partial_ord_comparison() { - let a: f64 = unimplemented!(); - let b: f64 = unimplemented!(); - let _ = !(a < b); - let _ = !(a <= b); - let _ = !(a > b); - let _ = !(a >= b); -} - -fn main() {} diff --git a/tests/ui/nonminimal_bool_methods.stderr b/tests/ui/nonminimal_bool_methods.stderr deleted file mode 100644 index a2df889d6230..000000000000 --- a/tests/ui/nonminimal_bool_methods.stderr +++ /dev/null @@ -1,82 +0,0 @@ -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:8:13 - | -LL | let _ = !a.is_some(); - | ^^^^^^^^^^^^ help: try: `a.is_none()` - | - = note: `-D clippy::nonminimal-bool` implied by `-D warnings` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:10:13 - | -LL | let _ = !a.is_none(); - | ^^^^^^^^^^^^ help: try: `a.is_some()` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:12:13 - | -LL | let _ = !b.is_err(); - | ^^^^^^^^^^^ help: try: `b.is_ok()` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:14:13 - | -LL | let _ = !b.is_ok(); - | ^^^^^^^^^^ help: try: `b.is_err()` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:16:13 - | -LL | let _ = !(a.is_some() && !c); - | ^^^^^^^^^^^^^^^^^^^^ help: try: `a.is_none() || c` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:17:13 - | -LL | let _ = !(a.is_some() || !c); - | ^^^^^^^^^^^^^^^^^^^^ help: try: `a.is_none() && c` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:18:26 - | -LL | let _ = !(!c ^ c) || !a.is_some(); - | ^^^^^^^^^^^^ help: try: `a.is_none()` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:19:25 - | -LL | let _ = (!c ^ c) || !a.is_some(); - | ^^^^^^^^^^^^ help: try: `a.is_none()` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:20:23 - | -LL | let _ = !c ^ c || !a.is_some(); - | ^^^^^^^^^^^^ help: try: `a.is_none()` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:92:8 - | -LL | if !res.is_ok() {} - | ^^^^^^^^^^^^ help: try: `res.is_err()` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:93:8 - | -LL | if !res.is_err() {} - | ^^^^^^^^^^^^^ help: try: `res.is_ok()` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:96:8 - | -LL | if !res.is_some() {} - | ^^^^^^^^^^^^^^ help: try: `res.is_none()` - -error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:97:8 - | -LL | if !res.is_none() {} - | ^^^^^^^^^^^^^^ help: try: `res.is_some()` - -error: aborting due to 13 previous errors - diff --git a/tests/ui/ok_expect.rs b/tests/ui/ok_expect.rs deleted file mode 100644 index ff68d38c73bf..000000000000 --- a/tests/ui/ok_expect.rs +++ /dev/null @@ -1,27 +0,0 @@ -use std::io; - -struct MyError(()); // doesn't implement Debug - -#[derive(Debug)] -struct MyErrorWithParam { - x: T, -} - -fn main() { - let res: Result = Ok(0); - let _ = res.unwrap(); - - res.ok().expect("disaster!"); - // the following should not warn, since `expect` isn't implemented unless - // the error type implements `Debug` - let res2: Result = Ok(0); - res2.ok().expect("oh noes!"); - let res3: Result> = Ok(0); - res3.ok().expect("whoof"); - let res4: Result = Ok(0); - res4.ok().expect("argh"); - let res5: io::Result = Ok(0); - res5.ok().expect("oops"); - let res6: Result = Ok(0); - res6.ok().expect("meh"); -} diff --git a/tests/ui/ok_expect.stderr b/tests/ui/ok_expect.stderr deleted file mode 100644 index b02b28e7f68c..000000000000 --- a/tests/ui/ok_expect.stderr +++ /dev/null @@ -1,43 +0,0 @@ -error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:14:5 - | -LL | res.ok().expect("disaster!"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::ok-expect` implied by `-D warnings` - = help: you can call `expect()` directly on the `Result` - -error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:20:5 - | -LL | res3.ok().expect("whoof"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: you can call `expect()` directly on the `Result` - -error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:22:5 - | -LL | res4.ok().expect("argh"); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: you can call `expect()` directly on the `Result` - -error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:24:5 - | -LL | res5.ok().expect("oops"); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: you can call `expect()` directly on the `Result` - -error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:26:5 - | -LL | res6.ok().expect("meh"); - | ^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: you can call `expect()` directly on the `Result` - -error: aborting due to 5 previous errors - diff --git a/tests/ui/op_ref.rs b/tests/ui/op_ref.rs deleted file mode 100644 index 6605c967c8e7..000000000000 --- a/tests/ui/op_ref.rs +++ /dev/null @@ -1,58 +0,0 @@ -#![allow(unused_variables, clippy::blacklisted_name)] -#![warn(clippy::op_ref)] -#![allow(clippy::many_single_char_names)] -use std::collections::HashSet; -use std::ops::BitAnd; - -fn main() { - let tracked_fds: HashSet = HashSet::new(); - let new_fds = HashSet::new(); - let unwanted = &tracked_fds - &new_fds; - - let foo = &5 - &6; - - let bar = String::new(); - let bar = "foo" == &bar; - - let a = "a".to_string(); - let b = "a"; - - if b < &a { - println!("OK"); - } - - struct X(i32); - impl BitAnd for X { - type Output = X; - fn bitand(self, rhs: X) -> X { - X(self.0 & rhs.0) - } - } - impl<'a> BitAnd<&'a X> for X { - type Output = X; - fn bitand(self, rhs: &'a X) -> X { - X(self.0 & rhs.0) - } - } - let x = X(1); - let y = X(2); - let z = x & &y; - - #[derive(Copy, Clone)] - struct Y(i32); - impl BitAnd for Y { - type Output = Y; - fn bitand(self, rhs: Y) -> Y { - Y(self.0 & rhs.0) - } - } - impl<'a> BitAnd<&'a Y> for Y { - type Output = Y; - fn bitand(self, rhs: &'a Y) -> Y { - Y(self.0 & rhs.0) - } - } - let x = Y(1); - let y = Y(2); - let z = x & &y; -} diff --git a/tests/ui/op_ref.stderr b/tests/ui/op_ref.stderr deleted file mode 100644 index a3a9adcc4835..000000000000 --- a/tests/ui/op_ref.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: needlessly taken reference of both operands - --> $DIR/op_ref.rs:12:15 - | -LL | let foo = &5 - &6; - | ^^^^^^^ - | - = note: `-D clippy::op-ref` implied by `-D warnings` -help: use the values directly - | -LL | let foo = 5 - 6; - | ^ ^ - -error: taken reference of right operand - --> $DIR/op_ref.rs:57:13 - | -LL | let z = x & &y; - | ^^^^-- - | | - | help: use the right value directly: `y` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/open_options.rs b/tests/ui/open_options.rs deleted file mode 100644 index 9063fafbcd04..000000000000 --- a/tests/ui/open_options.rs +++ /dev/null @@ -1,14 +0,0 @@ -use std::fs::OpenOptions; - -#[allow(unused_must_use)] -#[warn(clippy::nonsensical_open_options)] -fn main() { - OpenOptions::new().read(true).truncate(true).open("foo.txt"); - OpenOptions::new().append(true).truncate(true).open("foo.txt"); - - OpenOptions::new().read(true).read(false).open("foo.txt"); - OpenOptions::new().create(true).create(false).open("foo.txt"); - OpenOptions::new().write(true).write(false).open("foo.txt"); - OpenOptions::new().append(true).append(false).open("foo.txt"); - OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); -} diff --git a/tests/ui/open_options.stderr b/tests/ui/open_options.stderr deleted file mode 100644 index 26fe9f6fb206..000000000000 --- a/tests/ui/open_options.stderr +++ /dev/null @@ -1,46 +0,0 @@ -error: file opened with `truncate` and `read` - --> $DIR/open_options.rs:6:5 - | -LL | OpenOptions::new().read(true).truncate(true).open("foo.txt"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::nonsensical-open-options` implied by `-D warnings` - -error: file opened with `append` and `truncate` - --> $DIR/open_options.rs:7:5 - | -LL | OpenOptions::new().append(true).truncate(true).open("foo.txt"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the method `read` is called more than once - --> $DIR/open_options.rs:9:5 - | -LL | OpenOptions::new().read(true).read(false).open("foo.txt"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the method `create` is called more than once - --> $DIR/open_options.rs:10:5 - | -LL | OpenOptions::new().create(true).create(false).open("foo.txt"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the method `write` is called more than once - --> $DIR/open_options.rs:11:5 - | -LL | OpenOptions::new().write(true).write(false).open("foo.txt"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the method `append` is called more than once - --> $DIR/open_options.rs:12:5 - | -LL | OpenOptions::new().append(true).append(false).open("foo.txt"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: the method `truncate` is called more than once - --> $DIR/open_options.rs:13:5 - | -LL | OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 7 previous errors - diff --git a/tests/ui/option_as_ref_deref.fixed b/tests/ui/option_as_ref_deref.fixed deleted file mode 100644 index 07d7f0b45b0c..000000000000 --- a/tests/ui/option_as_ref_deref.fixed +++ /dev/null @@ -1,44 +0,0 @@ -// run-rustfix - -#![allow(unused_imports, clippy::redundant_clone)] -#![warn(clippy::option_as_ref_deref)] - -use std::ffi::{CString, OsString}; -use std::ops::{Deref, DerefMut}; -use std::path::PathBuf; - -fn main() { - let mut opt = Some(String::from("123")); - - let _ = opt.clone().as_deref().map(str::len); - - #[rustfmt::skip] - let _ = opt.clone().as_deref() - .map(str::len); - - let _ = opt.as_deref_mut(); - - let _ = opt.as_deref(); - let _ = opt.as_deref(); - let _ = opt.as_deref_mut(); - let _ = opt.as_deref_mut(); - let _ = Some(CString::new(vec![]).unwrap()).as_deref(); - let _ = Some(OsString::new()).as_deref(); - let _ = Some(PathBuf::new()).as_deref(); - let _ = Some(Vec::<()>::new()).as_deref(); - let _ = Some(Vec::<()>::new()).as_deref_mut(); - - let _ = opt.as_deref(); - let _ = opt.clone().as_deref_mut().map(|x| x.len()); - - let vc = vec![String::new()]; - let _ = Some(1_usize).as_ref().map(|x| vc[*x].as_str()); // should not be linted - - let _: Option<&str> = Some(&String::new()).as_ref().map(|x| x.as_str()); // should not be linted - - let _ = opt.as_deref(); - let _ = opt.as_deref_mut(); - - // Issue #5927 - let _ = opt.as_deref(); -} diff --git a/tests/ui/option_as_ref_deref.rs b/tests/ui/option_as_ref_deref.rs deleted file mode 100644 index 6ae059c9425d..000000000000 --- a/tests/ui/option_as_ref_deref.rs +++ /dev/null @@ -1,47 +0,0 @@ -// run-rustfix - -#![allow(unused_imports, clippy::redundant_clone)] -#![warn(clippy::option_as_ref_deref)] - -use std::ffi::{CString, OsString}; -use std::ops::{Deref, DerefMut}; -use std::path::PathBuf; - -fn main() { - let mut opt = Some(String::from("123")); - - let _ = opt.clone().as_ref().map(Deref::deref).map(str::len); - - #[rustfmt::skip] - let _ = opt.clone() - .as_ref().map( - Deref::deref - ) - .map(str::len); - - let _ = opt.as_mut().map(DerefMut::deref_mut); - - let _ = opt.as_ref().map(String::as_str); - let _ = opt.as_ref().map(|x| x.as_str()); - let _ = opt.as_mut().map(String::as_mut_str); - let _ = opt.as_mut().map(|x| x.as_mut_str()); - let _ = Some(CString::new(vec![]).unwrap()).as_ref().map(CString::as_c_str); - let _ = Some(OsString::new()).as_ref().map(OsString::as_os_str); - let _ = Some(PathBuf::new()).as_ref().map(PathBuf::as_path); - let _ = Some(Vec::<()>::new()).as_ref().map(Vec::as_slice); - let _ = Some(Vec::<()>::new()).as_mut().map(Vec::as_mut_slice); - - let _ = opt.as_ref().map(|x| x.deref()); - let _ = opt.clone().as_mut().map(|x| x.deref_mut()).map(|x| x.len()); - - let vc = vec![String::new()]; - let _ = Some(1_usize).as_ref().map(|x| vc[*x].as_str()); // should not be linted - - let _: Option<&str> = Some(&String::new()).as_ref().map(|x| x.as_str()); // should not be linted - - let _ = opt.as_ref().map(|x| &**x); - let _ = opt.as_mut().map(|x| &mut **x); - - // Issue #5927 - let _ = opt.as_ref().map(std::ops::Deref::deref); -} diff --git a/tests/ui/option_as_ref_deref.stderr b/tests/ui/option_as_ref_deref.stderr deleted file mode 100644 index 62f282324752..000000000000 --- a/tests/ui/option_as_ref_deref.stderr +++ /dev/null @@ -1,110 +0,0 @@ -error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead - --> $DIR/option_as_ref_deref.rs:13:13 - | -LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.clone().as_deref()` - | - = note: `-D clippy::option-as-ref-deref` implied by `-D warnings` - -error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead - --> $DIR/option_as_ref_deref.rs:16:13 - | -LL | let _ = opt.clone() - | _____________^ -LL | | .as_ref().map( -LL | | Deref::deref -LL | | ) - | |_________^ help: try using as_deref instead: `opt.clone().as_deref()` - -error: called `.as_mut().map(DerefMut::deref_mut)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:22:13 - | -LL | let _ = opt.as_mut().map(DerefMut::deref_mut); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()` - -error: called `.as_ref().map(String::as_str)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:24:13 - | -LL | let _ = opt.as_ref().map(String::as_str); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` - -error: called `.as_ref().map(|x| x.as_str())` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:25:13 - | -LL | let _ = opt.as_ref().map(|x| x.as_str()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` - -error: called `.as_mut().map(String::as_mut_str)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:26:13 - | -LL | let _ = opt.as_mut().map(String::as_mut_str); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()` - -error: called `.as_mut().map(|x| x.as_mut_str())` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:27:13 - | -LL | let _ = opt.as_mut().map(|x| x.as_mut_str()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()` - -error: called `.as_ref().map(CString::as_c_str)` on an Option value. This can be done more directly by calling `Some(CString::new(vec![]).unwrap()).as_deref()` instead - --> $DIR/option_as_ref_deref.rs:28:13 - | -LL | let _ = Some(CString::new(vec![]).unwrap()).as_ref().map(CString::as_c_str); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(CString::new(vec![]).unwrap()).as_deref()` - -error: called `.as_ref().map(OsString::as_os_str)` on an Option value. This can be done more directly by calling `Some(OsString::new()).as_deref()` instead - --> $DIR/option_as_ref_deref.rs:29:13 - | -LL | let _ = Some(OsString::new()).as_ref().map(OsString::as_os_str); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(OsString::new()).as_deref()` - -error: called `.as_ref().map(PathBuf::as_path)` on an Option value. This can be done more directly by calling `Some(PathBuf::new()).as_deref()` instead - --> $DIR/option_as_ref_deref.rs:30:13 - | -LL | let _ = Some(PathBuf::new()).as_ref().map(PathBuf::as_path); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(PathBuf::new()).as_deref()` - -error: called `.as_ref().map(Vec::as_slice)` on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref()` instead - --> $DIR/option_as_ref_deref.rs:31:13 - | -LL | let _ = Some(Vec::<()>::new()).as_ref().map(Vec::as_slice); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(Vec::<()>::new()).as_deref()` - -error: called `.as_mut().map(Vec::as_mut_slice)` on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:32:13 - | -LL | let _ = Some(Vec::<()>::new()).as_mut().map(Vec::as_mut_slice); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `Some(Vec::<()>::new()).as_deref_mut()` - -error: called `.as_ref().map(|x| x.deref())` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:34:13 - | -LL | let _ = opt.as_ref().map(|x| x.deref()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` - -error: called `.as_mut().map(|x| x.deref_mut())` on an Option value. This can be done more directly by calling `opt.clone().as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:35:13 - | -LL | let _ = opt.clone().as_mut().map(|x| x.deref_mut()).map(|x| x.len()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.clone().as_deref_mut()` - -error: called `.as_ref().map(|x| &**x)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:42:13 - | -LL | let _ = opt.as_ref().map(|x| &**x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` - -error: called `.as_mut().map(|x| &mut **x)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:43:13 - | -LL | let _ = opt.as_mut().map(|x| &mut **x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()` - -error: called `.as_ref().map(std::ops::Deref::deref)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:46:13 - | -LL | let _ = opt.as_ref().map(std::ops::Deref::deref); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` - -error: aborting due to 17 previous errors - diff --git a/tests/ui/option_env_unwrap.rs b/tests/ui/option_env_unwrap.rs deleted file mode 100644 index 642c77460a34..000000000000 --- a/tests/ui/option_env_unwrap.rs +++ /dev/null @@ -1,23 +0,0 @@ -// aux-build:macro_rules.rs -#![warn(clippy::option_env_unwrap)] - -#[macro_use] -extern crate macro_rules; - -macro_rules! option_env_unwrap { - ($env: expr) => { - option_env!($env).unwrap() - }; - ($env: expr, $message: expr) => { - option_env!($env).expect($message) - }; -} - -fn main() { - let _ = option_env!("PATH").unwrap(); - let _ = option_env!("PATH").expect("environment variable PATH isn't set"); - let _ = option_env_unwrap!("PATH"); - let _ = option_env_unwrap!("PATH", "environment variable PATH isn't set"); - let _ = option_env_unwrap_external!("PATH"); - let _ = option_env_unwrap_external!("PATH", "environment variable PATH isn't set"); -} diff --git a/tests/ui/option_env_unwrap.stderr b/tests/ui/option_env_unwrap.stderr deleted file mode 100644 index 8de9c8a9d29e..000000000000 --- a/tests/ui/option_env_unwrap.stderr +++ /dev/null @@ -1,61 +0,0 @@ -error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:17:13 - | -LL | let _ = option_env!("PATH").unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::option-env-unwrap` implied by `-D warnings` - = help: consider using the `env!` macro instead - -error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:18:13 - | -LL | let _ = option_env!("PATH").expect("environment variable PATH isn't set"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using the `env!` macro instead - -error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:9:9 - | -LL | option_env!($env).unwrap() - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | let _ = option_env_unwrap!("PATH"); - | -------------------------- in this macro invocation - | - = help: consider using the `env!` macro instead - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:12:9 - | -LL | option_env!($env).expect($message) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | let _ = option_env_unwrap!("PATH", "environment variable PATH isn't set"); - | ----------------------------------------------------------------- in this macro invocation - | - = help: consider using the `env!` macro instead - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:21:13 - | -LL | let _ = option_env_unwrap_external!("PATH"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using the `env!` macro instead - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> $DIR/option_env_unwrap.rs:22:13 - | -LL | let _ = option_env_unwrap_external!("PATH", "environment variable PATH isn't set"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using the `env!` macro instead - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 6 previous errors - diff --git a/tests/ui/option_if_let_else.fixed b/tests/ui/option_if_let_else.fixed deleted file mode 100644 index 47e7460fa7a4..000000000000 --- a/tests/ui/option_if_let_else.fixed +++ /dev/null @@ -1,85 +0,0 @@ -// run-rustfix -#![warn(clippy::option_if_let_else)] -#![allow(clippy::redundant_closure)] -#![allow(clippy::ref_option_ref)] - -fn bad1(string: Option<&str>) -> (bool, &str) { - string.map_or((false, "hello"), |x| (true, x)) -} - -fn else_if_option(string: Option<&str>) -> Option<(bool, &str)> { - if string.is_none() { - None - } else { string.map_or(Some((false, "")), |x| Some((true, x))) } -} - -fn unop_bad(string: &Option<&str>, mut num: Option) { - let _ = string.map_or(0, |s| s.len()); - let _ = num.as_ref().map_or(&0, |s| s); - let _ = num.as_mut().map_or(&mut 0, |s| { - *s += 1; - s - }); - let _ = num.as_ref().map_or(&0, |s| s); - let _ = num.map_or(0, |mut s| { - s += 1; - s - }); - let _ = num.as_mut().map_or(&mut 0, |s| { - *s += 1; - s - }); -} - -fn longer_body(arg: Option) -> u32 { - arg.map_or(13, |x| { - let y = x * x; - y * y - }) -} - -fn impure_else(arg: Option) { - let side_effect = || { - println!("return 1"); - 1 - }; - let _ = arg.map_or_else(|| side_effect(), |x| x); -} - -fn test_map_or_else(arg: Option) { - let _ = arg.map_or_else(|| { - let mut y = 1; - y = (y + 2 / y) / 2; - y = (y + 2 / y) / 2; - y - }, |x| x * x * x * x); -} - -fn negative_tests(arg: Option) -> u32 { - let _ = if let Some(13) = arg { "unlucky" } else { "lucky" }; - for _ in 0..10 { - let _ = if let Some(x) = arg { - x - } else { - continue; - }; - } - let _ = if let Some(x) = arg { - return x; - } else { - 5 - }; - 7 -} - -fn main() { - let optional = Some(5); - let _ = optional.map_or(5, |x| x + 2); - let _ = bad1(None); - let _ = else_if_option(None); - unop_bad(&None, None); - let _ = longer_body(None); - test_map_or_else(None); - let _ = negative_tests(None); - let _ = impure_else(None); -} diff --git a/tests/ui/option_if_let_else.rs b/tests/ui/option_if_let_else.rs deleted file mode 100644 index e2f8dec3b930..000000000000 --- a/tests/ui/option_if_let_else.rs +++ /dev/null @@ -1,108 +0,0 @@ -// run-rustfix -#![warn(clippy::option_if_let_else)] -#![allow(clippy::redundant_closure)] -#![allow(clippy::ref_option_ref)] - -fn bad1(string: Option<&str>) -> (bool, &str) { - if let Some(x) = string { - (true, x) - } else { - (false, "hello") - } -} - -fn else_if_option(string: Option<&str>) -> Option<(bool, &str)> { - if string.is_none() { - None - } else if let Some(x) = string { - Some((true, x)) - } else { - Some((false, "")) - } -} - -fn unop_bad(string: &Option<&str>, mut num: Option) { - let _ = if let Some(s) = *string { s.len() } else { 0 }; - let _ = if let Some(s) = &num { s } else { &0 }; - let _ = if let Some(s) = &mut num { - *s += 1; - s - } else { - &mut 0 - }; - let _ = if let Some(ref s) = num { s } else { &0 }; - let _ = if let Some(mut s) = num { - s += 1; - s - } else { - 0 - }; - let _ = if let Some(ref mut s) = num { - *s += 1; - s - } else { - &mut 0 - }; -} - -fn longer_body(arg: Option) -> u32 { - if let Some(x) = arg { - let y = x * x; - y * y - } else { - 13 - } -} - -fn impure_else(arg: Option) { - let side_effect = || { - println!("return 1"); - 1 - }; - let _ = if let Some(x) = arg { - x - } else { - // map_or_else must be suggested - side_effect() - }; -} - -fn test_map_or_else(arg: Option) { - let _ = if let Some(x) = arg { - x * x * x * x - } else { - let mut y = 1; - y = (y + 2 / y) / 2; - y = (y + 2 / y) / 2; - y - }; -} - -fn negative_tests(arg: Option) -> u32 { - let _ = if let Some(13) = arg { "unlucky" } else { "lucky" }; - for _ in 0..10 { - let _ = if let Some(x) = arg { - x - } else { - continue; - }; - } - let _ = if let Some(x) = arg { - return x; - } else { - 5 - }; - 7 -} - -fn main() { - let optional = Some(5); - let _ = if let Some(x) = optional { x + 2 } else { 5 }; - let _ = bad1(None); - let _ = else_if_option(None); - unop_bad(&None, None); - let _ = longer_body(None); - test_map_or_else(None); - let _ = negative_tests(None); - let _ = impure_else(None); -} diff --git a/tests/ui/option_if_let_else.stderr b/tests/ui/option_if_let_else.stderr deleted file mode 100644 index 7aab068800a0..000000000000 --- a/tests/ui/option_if_let_else.stderr +++ /dev/null @@ -1,163 +0,0 @@ -error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:7:5 - | -LL | / if let Some(x) = string { -LL | | (true, x) -LL | | } else { -LL | | (false, "hello") -LL | | } - | |_____^ help: try: `string.map_or((false, "hello"), |x| (true, x))` - | - = note: `-D clippy::option-if-let-else` implied by `-D warnings` - -error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:17:12 - | -LL | } else if let Some(x) = string { - | ____________^ -LL | | Some((true, x)) -LL | | } else { -LL | | Some((false, "")) -LL | | } - | |_____^ help: try: `{ string.map_or(Some((false, "")), |x| Some((true, x))) }` - -error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:25:13 - | -LL | let _ = if let Some(s) = *string { s.len() } else { 0 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.map_or(0, |s| s.len())` - -error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:26:13 - | -LL | let _ = if let Some(s) = &num { s } else { &0 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)` - -error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:27:13 - | -LL | let _ = if let Some(s) = &mut num { - | _____________^ -LL | | *s += 1; -LL | | s -LL | | } else { -LL | | &mut 0 -LL | | }; - | |_____^ - | -help: try - | -LL | let _ = num.as_mut().map_or(&mut 0, |s| { -LL | *s += 1; -LL | s -LL | }); - | - -error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:33:13 - | -LL | let _ = if let Some(ref s) = num { s } else { &0 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)` - -error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:34:13 - | -LL | let _ = if let Some(mut s) = num { - | _____________^ -LL | | s += 1; -LL | | s -LL | | } else { -LL | | 0 -LL | | }; - | |_____^ - | -help: try - | -LL | let _ = num.map_or(0, |mut s| { -LL | s += 1; -LL | s -LL | }); - | - -error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:40:13 - | -LL | let _ = if let Some(ref mut s) = num { - | _____________^ -LL | | *s += 1; -LL | | s -LL | | } else { -LL | | &mut 0 -LL | | }; - | |_____^ - | -help: try - | -LL | let _ = num.as_mut().map_or(&mut 0, |s| { -LL | *s += 1; -LL | s -LL | }); - | - -error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:49:5 - | -LL | / if let Some(x) = arg { -LL | | let y = x * x; -LL | | y * y -LL | | } else { -LL | | 13 -LL | | } - | |_____^ - | -help: try - | -LL | arg.map_or(13, |x| { -LL | let y = x * x; -LL | y * y -LL | }) - | - -error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:62:13 - | -LL | let _ = if let Some(x) = arg { - | _____________^ -LL | | x -LL | | } else { -LL | | // map_or_else must be suggested -LL | | side_effect() -LL | | }; - | |_____^ help: try: `arg.map_or_else(|| side_effect(), |x| x)` - -error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:71:13 - | -LL | let _ = if let Some(x) = arg { - | _____________^ -LL | | x * x * x * x -LL | | } else { -LL | | let mut y = 1; -... | -LL | | y -LL | | }; - | |_____^ - | -help: try - | -LL | let _ = arg.map_or_else(|| { -LL | let mut y = 1; -LL | y = (y + 2 / y) / 2; -LL | y = (y + 2 / y) / 2; -LL | y -LL | }, |x| x * x * x * x); - | - -error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:100:13 - | -LL | let _ = if let Some(x) = optional { x + 2 } else { 5 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)` - -error: aborting due to 12 previous errors - diff --git a/tests/ui/option_map_or_none.fixed b/tests/ui/option_map_or_none.fixed deleted file mode 100644 index d80c3c7c1b72..000000000000 --- a/tests/ui/option_map_or_none.fixed +++ /dev/null @@ -1,16 +0,0 @@ -// run-rustfix - -#![allow(clippy::bind_instead_of_map)] - -fn main() { - let opt = Some(1); - - // Check `OPTION_MAP_OR_NONE`. - // Single line case. - let _ = opt.and_then(|x| Some(x + 1)); - // Multi-line case. - #[rustfmt::skip] - let _ = opt.and_then(|x| { - Some(x + 1) - }); -} diff --git a/tests/ui/option_map_or_none.rs b/tests/ui/option_map_or_none.rs deleted file mode 100644 index 629842419e54..000000000000 --- a/tests/ui/option_map_or_none.rs +++ /dev/null @@ -1,16 +0,0 @@ -// run-rustfix - -#![allow(clippy::bind_instead_of_map)] - -fn main() { - let opt = Some(1); - - // Check `OPTION_MAP_OR_NONE`. - // Single line case. - let _ = opt.map_or(None, |x| Some(x + 1)); - // Multi-line case. - #[rustfmt::skip] - let _ = opt.map_or(None, |x| { - Some(x + 1) - }); -} diff --git a/tests/ui/option_map_or_none.stderr b/tests/ui/option_map_or_none.stderr deleted file mode 100644 index 1cba29412b87..000000000000 --- a/tests/ui/option_map_or_none.stderr +++ /dev/null @@ -1,26 +0,0 @@ -error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead - --> $DIR/option_map_or_none.rs:10:13 - | -LL | let _ = opt.map_or(None, |x| Some(x + 1)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(|x| Some(x + 1))` - | - = note: `-D clippy::option-map-or-none` implied by `-D warnings` - -error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead - --> $DIR/option_map_or_none.rs:13:13 - | -LL | let _ = opt.map_or(None, |x| { - | _____________^ -LL | | Some(x + 1) -LL | | }); - | |_________________________^ - | -help: try using `and_then` instead - | -LL | let _ = opt.and_then(|x| { -LL | Some(x + 1) -LL | }); - | - -error: aborting due to 2 previous errors - diff --git a/tests/ui/option_map_unit_fn_fixable.fixed b/tests/ui/option_map_unit_fn_fixable.fixed deleted file mode 100644 index 7d29445e66c8..000000000000 --- a/tests/ui/option_map_unit_fn_fixable.fixed +++ /dev/null @@ -1,85 +0,0 @@ -// run-rustfix - -#![warn(clippy::option_map_unit_fn)] -#![allow(unused)] -#![allow(clippy::unnecessary_wraps)] - -fn do_nothing(_: T) {} - -fn diverge(_: T) -> ! { - panic!() -} - -fn plus_one(value: usize) -> usize { - value + 1 -} - -fn option() -> Option { - Some(10) -} - -struct HasOption { - field: Option, -} - -impl HasOption { - fn do_option_nothing(&self, value: usize) {} - - fn do_option_plus_one(&self, value: usize) -> usize { - value + 1 - } -} -#[rustfmt::skip] -fn option_map_unit_fn() { - let x = HasOption { field: Some(10) }; - - x.field.map(plus_one); - let _ : Option<()> = x.field.map(do_nothing); - - if let Some(x_field) = x.field { do_nothing(x_field) } - - if let Some(x_field) = x.field { do_nothing(x_field) } - - if let Some(x_field) = x.field { diverge(x_field) } - - let captured = 10; - if let Some(value) = x.field { do_nothing(value + captured) }; - let _ : Option<()> = x.field.map(|value| do_nothing(value + captured)); - - if let Some(value) = x.field { x.do_option_nothing(value + captured) } - - if let Some(value) = x.field { x.do_option_plus_one(value + captured); } - - - if let Some(value) = x.field { do_nothing(value + captured) } - - if let Some(value) = x.field { do_nothing(value + captured) } - - if let Some(value) = x.field { do_nothing(value + captured); } - - if let Some(value) = x.field { do_nothing(value + captured); } - - - if let Some(value) = x.field { diverge(value + captured) } - - if let Some(value) = x.field { diverge(value + captured) } - - if let Some(value) = x.field { diverge(value + captured); } - - if let Some(value) = x.field { diverge(value + captured); } - - - x.field.map(|value| plus_one(value + captured)); - x.field.map(|value| { plus_one(value + captured) }); - if let Some(value) = x.field { let y = plus_one(value + captured); } - - if let Some(value) = x.field { plus_one(value + captured); } - - if let Some(value) = x.field { plus_one(value + captured); } - - - if let Some(ref value) = x.field { do_nothing(value + captured) } - - if let Some(a) = option() { do_nothing(a) }} - -fn main() {} diff --git a/tests/ui/option_map_unit_fn_fixable.rs b/tests/ui/option_map_unit_fn_fixable.rs deleted file mode 100644 index b6f834f686f9..000000000000 --- a/tests/ui/option_map_unit_fn_fixable.rs +++ /dev/null @@ -1,85 +0,0 @@ -// run-rustfix - -#![warn(clippy::option_map_unit_fn)] -#![allow(unused)] -#![allow(clippy::unnecessary_wraps)] - -fn do_nothing(_: T) {} - -fn diverge(_: T) -> ! { - panic!() -} - -fn plus_one(value: usize) -> usize { - value + 1 -} - -fn option() -> Option { - Some(10) -} - -struct HasOption { - field: Option, -} - -impl HasOption { - fn do_option_nothing(&self, value: usize) {} - - fn do_option_plus_one(&self, value: usize) -> usize { - value + 1 - } -} -#[rustfmt::skip] -fn option_map_unit_fn() { - let x = HasOption { field: Some(10) }; - - x.field.map(plus_one); - let _ : Option<()> = x.field.map(do_nothing); - - x.field.map(do_nothing); - - x.field.map(do_nothing); - - x.field.map(diverge); - - let captured = 10; - if let Some(value) = x.field { do_nothing(value + captured) }; - let _ : Option<()> = x.field.map(|value| do_nothing(value + captured)); - - x.field.map(|value| x.do_option_nothing(value + captured)); - - x.field.map(|value| { x.do_option_plus_one(value + captured); }); - - - x.field.map(|value| do_nothing(value + captured)); - - x.field.map(|value| { do_nothing(value + captured) }); - - x.field.map(|value| { do_nothing(value + captured); }); - - x.field.map(|value| { { do_nothing(value + captured); } }); - - - x.field.map(|value| diverge(value + captured)); - - x.field.map(|value| { diverge(value + captured) }); - - x.field.map(|value| { diverge(value + captured); }); - - x.field.map(|value| { { diverge(value + captured); } }); - - - x.field.map(|value| plus_one(value + captured)); - x.field.map(|value| { plus_one(value + captured) }); - x.field.map(|value| { let y = plus_one(value + captured); }); - - x.field.map(|value| { plus_one(value + captured); }); - - x.field.map(|value| { { plus_one(value + captured); } }); - - - x.field.map(|ref value| { do_nothing(value + captured) }); - - option().map(do_nothing);} - -fn main() {} diff --git a/tests/ui/option_map_unit_fn_fixable.stderr b/tests/ui/option_map_unit_fn_fixable.stderr deleted file mode 100644 index 8abdbcafb6e9..000000000000 --- a/tests/ui/option_map_unit_fn_fixable.stderr +++ /dev/null @@ -1,148 +0,0 @@ -error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:39:5 - | -LL | x.field.map(do_nothing); - | ^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(x_field) = x.field { do_nothing(x_field) }` - | - = note: `-D clippy::option-map-unit-fn` implied by `-D warnings` - -error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:41:5 - | -LL | x.field.map(do_nothing); - | ^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(x_field) = x.field { do_nothing(x_field) }` - -error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:43:5 - | -LL | x.field.map(diverge); - | ^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(x_field) = x.field { diverge(x_field) }` - -error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:49:5 - | -LL | x.field.map(|value| x.do_option_nothing(value + captured)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(value) = x.field { x.do_option_nothing(value + captured) }` - -error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:51:5 - | -LL | x.field.map(|value| { x.do_option_plus_one(value + captured); }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(value) = x.field { x.do_option_plus_one(value + captured); }` - -error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:54:5 - | -LL | x.field.map(|value| do_nothing(value + captured)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }` - -error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:56:5 - | -LL | x.field.map(|value| { do_nothing(value + captured) }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }` - -error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:58:5 - | -LL | x.field.map(|value| { do_nothing(value + captured); }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(value) = x.field { do_nothing(value + captured); }` - -error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:60:5 - | -LL | x.field.map(|value| { { do_nothing(value + captured); } }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(value) = x.field { do_nothing(value + captured); }` - -error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:63:5 - | -LL | x.field.map(|value| diverge(value + captured)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(value) = x.field { diverge(value + captured) }` - -error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:65:5 - | -LL | x.field.map(|value| { diverge(value + captured) }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(value) = x.field { diverge(value + captured) }` - -error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:67:5 - | -LL | x.field.map(|value| { diverge(value + captured); }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(value) = x.field { diverge(value + captured); }` - -error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:69:5 - | -LL | x.field.map(|value| { { diverge(value + captured); } }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(value) = x.field { diverge(value + captured); }` - -error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:74:5 - | -LL | x.field.map(|value| { let y = plus_one(value + captured); }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(value) = x.field { let y = plus_one(value + captured); }` - -error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:76:5 - | -LL | x.field.map(|value| { plus_one(value + captured); }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(value) = x.field { plus_one(value + captured); }` - -error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:78:5 - | -LL | x.field.map(|value| { { plus_one(value + captured); } }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(value) = x.field { plus_one(value + captured); }` - -error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:81:5 - | -LL | x.field.map(|ref value| { do_nothing(value + captured) }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(ref value) = x.field { do_nothing(value + captured) }` - -error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:83:5 - | -LL | option().map(do_nothing);} - | ^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Some(a) = option() { do_nothing(a) }` - -error: aborting due to 18 previous errors - diff --git a/tests/ui/option_map_unit_fn_unfixable.rs b/tests/ui/option_map_unit_fn_unfixable.rs deleted file mode 100644 index 20e6c15b18d5..000000000000 --- a/tests/ui/option_map_unit_fn_unfixable.rs +++ /dev/null @@ -1,39 +0,0 @@ -#![warn(clippy::option_map_unit_fn)] -#![allow(unused)] - -fn do_nothing(_: T) {} - -fn diverge(_: T) -> ! { - panic!() -} - -fn plus_one(value: usize) -> usize { - value + 1 -} - -#[rustfmt::skip] -fn option_map_unit_fn() { - - x.field.map(|value| { do_nothing(value); do_nothing(value) }); - - x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) }); - - // Suggestion for the let block should be `{ ... }` as it's too difficult to build a - // proper suggestion for these cases - x.field.map(|value| { - do_nothing(value); - do_nothing(value) - }); - x.field.map(|value| { do_nothing(value); do_nothing(value); }); - - // The following should suggest `if let Some(_X) ...` as it's difficult to generate a proper let variable name for them - Some(42).map(diverge); - "12".parse::().ok().map(diverge); - Some(plus_one(1)).map(do_nothing); - - // Should suggest `if let Some(_y) ...` to not override the existing foo variable - let y = Some(42); - y.map(do_nothing); -} - -fn main() {} diff --git a/tests/ui/option_map_unit_fn_unfixable.stderr b/tests/ui/option_map_unit_fn_unfixable.stderr deleted file mode 100644 index a53f5889c58d..000000000000 --- a/tests/ui/option_map_unit_fn_unfixable.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error[E0425]: cannot find value `x` in this scope - --> $DIR/option_map_unit_fn_unfixable.rs:17:5 - | -LL | x.field.map(|value| { do_nothing(value); do_nothing(value) }); - | ^ not found in this scope - -error[E0425]: cannot find value `x` in this scope - --> $DIR/option_map_unit_fn_unfixable.rs:19:5 - | -LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) }); - | ^ not found in this scope - -error[E0425]: cannot find value `x` in this scope - --> $DIR/option_map_unit_fn_unfixable.rs:23:5 - | -LL | x.field.map(|value| { - | ^ not found in this scope - -error[E0425]: cannot find value `x` in this scope - --> $DIR/option_map_unit_fn_unfixable.rs:27:5 - | -LL | x.field.map(|value| { do_nothing(value); do_nothing(value); }); - | ^ not found in this scope - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/option_option.rs b/tests/ui/option_option.rs deleted file mode 100644 index 6859ba8e5bb8..000000000000 --- a/tests/ui/option_option.rs +++ /dev/null @@ -1,86 +0,0 @@ -#![deny(clippy::option_option)] -#![allow(clippy::unnecessary_wraps)] - -fn input(_: Option>) {} - -fn output() -> Option> { - None -} - -fn output_nested() -> Vec>> { - vec![None] -} - -// The lint only generates one warning for this -fn output_nested_nested() -> Option>> { - None -} - -struct Struct { - x: Option>, -} - -impl Struct { - fn struct_fn() -> Option> { - None - } -} - -trait Trait { - fn trait_fn() -> Option>; -} - -enum Enum { - Tuple(Option>), - Struct { x: Option> }, -} - -// The lint allows this -type OptionOption = Option>; - -// The lint allows this -fn output_type_alias() -> OptionOption { - None -} - -// The line allows this -impl Trait for Struct { - fn trait_fn() -> Option> { - None - } -} - -fn main() { - input(None); - output(); - output_nested(); - - // The lint allows this - let local: Option> = None; - - // The lint allows this - let expr = Some(Some(true)); -} - -extern crate serde; -mod issue_4298 { - use serde::{Deserialize, Deserializer, Serialize}; - use std::borrow::Cow; - - #[derive(Serialize, Deserialize)] - struct Foo<'a> { - #[serde(deserialize_with = "func")] - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(default)] - #[serde(borrow)] - foo: Option>>, - } - - #[allow(clippy::option_option)] - fn func<'a, D>(_: D) -> Result>>, D::Error> - where - D: Deserializer<'a>, - { - Ok(Some(Some(Cow::Borrowed("hi")))) - } -} diff --git a/tests/ui/option_option.stderr b/tests/ui/option_option.stderr deleted file mode 100644 index ad7f081c7139..000000000000 --- a/tests/ui/option_option.stderr +++ /dev/null @@ -1,68 +0,0 @@ -error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:4:13 - | -LL | fn input(_: Option>) {} - | ^^^^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/option_option.rs:1:9 - | -LL | #![deny(clippy::option_option)] - | ^^^^^^^^^^^^^^^^^^^^^ - -error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:6:16 - | -LL | fn output() -> Option> { - | ^^^^^^^^^^^^^^^^^^ - -error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:10:27 - | -LL | fn output_nested() -> Vec>> { - | ^^^^^^^^^^^^^^^^^^ - -error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:15:30 - | -LL | fn output_nested_nested() -> Option>> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:20:8 - | -LL | x: Option>, - | ^^^^^^^^^^^^^^^^^^ - -error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:24:23 - | -LL | fn struct_fn() -> Option> { - | ^^^^^^^^^^^^^^^^^^ - -error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:30:22 - | -LL | fn trait_fn() -> Option>; - | ^^^^^^^^^^^^^^^^^^ - -error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:34:11 - | -LL | Tuple(Option>), - | ^^^^^^^^^^^^^^^^^^ - -error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:35:17 - | -LL | Struct { x: Option> }, - | ^^^^^^^^^^^^^^^^^^ - -error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:76:14 - | -LL | foo: Option>>, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 10 previous errors - diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed deleted file mode 100644 index 2a63318c8c7a..000000000000 --- a/tests/ui/or_fun_call.fixed +++ /dev/null @@ -1,129 +0,0 @@ -// run-rustfix - -#![warn(clippy::or_fun_call)] -#![allow(dead_code)] -#![allow(clippy::unnecessary_wraps)] - -use std::collections::BTreeMap; -use std::collections::HashMap; -use std::time::Duration; - -/// Checks implementation of the `OR_FUN_CALL` lint. -fn or_fun_call() { - struct Foo; - - impl Foo { - fn new() -> Foo { - Foo - } - } - - enum Enum { - A(i32), - } - - fn make() -> T { - unimplemented!(); - } - - let with_enum = Some(Enum::A(1)); - with_enum.unwrap_or(Enum::A(5)); - - let with_const_fn = Some(Duration::from_secs(1)); - with_const_fn.unwrap_or_else(|| Duration::from_secs(5)); - - let with_constructor = Some(vec![1]); - with_constructor.unwrap_or_else(make); - - let with_new = Some(vec![1]); - with_new.unwrap_or_default(); - - let with_const_args = Some(vec![1]); - with_const_args.unwrap_or_else(|| Vec::with_capacity(12)); - - let with_err: Result<_, ()> = Ok(vec![1]); - with_err.unwrap_or_else(|_| make()); - - let with_err_args: Result<_, ()> = Ok(vec![1]); - with_err_args.unwrap_or_else(|_| Vec::with_capacity(12)); - - let with_default_trait = Some(1); - with_default_trait.unwrap_or_default(); - - let with_default_type = Some(1); - with_default_type.unwrap_or_default(); - - let with_vec = Some(vec![1]); - with_vec.unwrap_or_default(); - - let without_default = Some(Foo); - without_default.unwrap_or_else(Foo::new); - - let mut map = HashMap::::new(); - map.entry(42).or_insert_with(String::new); - - let mut btree = BTreeMap::::new(); - btree.entry(42).or_insert_with(String::new); - - let stringy = Some(String::from("")); - let _ = stringy.unwrap_or_else(|| "".to_owned()); - - let opt = Some(1); - let hello = "Hello"; - let _ = opt.ok_or(format!("{} world.", hello)); - - // index - let map = HashMap::::new(); - let _ = Some(1).unwrap_or_else(|| map[&1]); - let map = BTreeMap::::new(); - let _ = Some(1).unwrap_or_else(|| map[&1]); - // don't lint index vec - let vec = vec![1]; - let _ = Some(1).unwrap_or(vec[1]); -} - -struct Foo(u8); -struct Bar(String, Duration); -#[rustfmt::skip] -fn test_or_with_ctors() { - let opt = Some(1); - let opt_opt = Some(Some(1)); - // we also test for const promotion, this makes sure we don't hit that - let two = 2; - - let _ = opt_opt.unwrap_or(Some(2)); - let _ = opt_opt.unwrap_or(Some(two)); - let _ = opt.ok_or(Some(2)); - let _ = opt.ok_or(Some(two)); - let _ = opt.ok_or(Foo(2)); - let _ = opt.ok_or(Foo(two)); - let _ = opt.or(Some(2)); - let _ = opt.or(Some(two)); - - let _ = Some("a".to_string()).or_else(|| Some("b".to_string())); - - let b = "b".to_string(); - let _ = Some(Bar("a".to_string(), Duration::from_secs(1))) - .or_else(|| Some(Bar(b, Duration::from_secs(2)))); - - let vec = vec!["foo"]; - let _ = opt.ok_or(vec.len()); - - let array = ["foo"]; - let _ = opt.ok_or(array.len()); - - let slice = &["foo"][..]; - let _ = opt.ok_or(slice.len()); -} - -// Issue 4514 - early return -fn f() -> Option<()> { - let a = Some(1); - let b = 1i32; - - let _ = a.unwrap_or(b.checked_mul(3)?.min(240)); - - Some(()) -} - -fn main() {} diff --git a/tests/ui/or_fun_call.rs b/tests/ui/or_fun_call.rs deleted file mode 100644 index 026ef437caa1..000000000000 --- a/tests/ui/or_fun_call.rs +++ /dev/null @@ -1,129 +0,0 @@ -// run-rustfix - -#![warn(clippy::or_fun_call)] -#![allow(dead_code)] -#![allow(clippy::unnecessary_wraps)] - -use std::collections::BTreeMap; -use std::collections::HashMap; -use std::time::Duration; - -/// Checks implementation of the `OR_FUN_CALL` lint. -fn or_fun_call() { - struct Foo; - - impl Foo { - fn new() -> Foo { - Foo - } - } - - enum Enum { - A(i32), - } - - fn make() -> T { - unimplemented!(); - } - - let with_enum = Some(Enum::A(1)); - with_enum.unwrap_or(Enum::A(5)); - - let with_const_fn = Some(Duration::from_secs(1)); - with_const_fn.unwrap_or(Duration::from_secs(5)); - - let with_constructor = Some(vec![1]); - with_constructor.unwrap_or(make()); - - let with_new = Some(vec![1]); - with_new.unwrap_or(Vec::new()); - - let with_const_args = Some(vec![1]); - with_const_args.unwrap_or(Vec::with_capacity(12)); - - let with_err: Result<_, ()> = Ok(vec![1]); - with_err.unwrap_or(make()); - - let with_err_args: Result<_, ()> = Ok(vec![1]); - with_err_args.unwrap_or(Vec::with_capacity(12)); - - let with_default_trait = Some(1); - with_default_trait.unwrap_or(Default::default()); - - let with_default_type = Some(1); - with_default_type.unwrap_or(u64::default()); - - let with_vec = Some(vec![1]); - with_vec.unwrap_or(vec![]); - - let without_default = Some(Foo); - without_default.unwrap_or(Foo::new()); - - let mut map = HashMap::::new(); - map.entry(42).or_insert(String::new()); - - let mut btree = BTreeMap::::new(); - btree.entry(42).or_insert(String::new()); - - let stringy = Some(String::from("")); - let _ = stringy.unwrap_or("".to_owned()); - - let opt = Some(1); - let hello = "Hello"; - let _ = opt.ok_or(format!("{} world.", hello)); - - // index - let map = HashMap::::new(); - let _ = Some(1).unwrap_or(map[&1]); - let map = BTreeMap::::new(); - let _ = Some(1).unwrap_or(map[&1]); - // don't lint index vec - let vec = vec![1]; - let _ = Some(1).unwrap_or(vec[1]); -} - -struct Foo(u8); -struct Bar(String, Duration); -#[rustfmt::skip] -fn test_or_with_ctors() { - let opt = Some(1); - let opt_opt = Some(Some(1)); - // we also test for const promotion, this makes sure we don't hit that - let two = 2; - - let _ = opt_opt.unwrap_or(Some(2)); - let _ = opt_opt.unwrap_or(Some(two)); - let _ = opt.ok_or(Some(2)); - let _ = opt.ok_or(Some(two)); - let _ = opt.ok_or(Foo(2)); - let _ = opt.ok_or(Foo(two)); - let _ = opt.or(Some(2)); - let _ = opt.or(Some(two)); - - let _ = Some("a".to_string()).or(Some("b".to_string())); - - let b = "b".to_string(); - let _ = Some(Bar("a".to_string(), Duration::from_secs(1))) - .or(Some(Bar(b, Duration::from_secs(2)))); - - let vec = vec!["foo"]; - let _ = opt.ok_or(vec.len()); - - let array = ["foo"]; - let _ = opt.ok_or(array.len()); - - let slice = &["foo"][..]; - let _ = opt.ok_or(slice.len()); -} - -// Issue 4514 - early return -fn f() -> Option<()> { - let a = Some(1); - let b = 1i32; - - let _ = a.unwrap_or(b.checked_mul(3)?.min(240)); - - Some(()) -} - -fn main() {} diff --git a/tests/ui/or_fun_call.stderr b/tests/ui/or_fun_call.stderr deleted file mode 100644 index fb8bf339828f..000000000000 --- a/tests/ui/or_fun_call.stderr +++ /dev/null @@ -1,106 +0,0 @@ -error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:33:19 - | -LL | with_const_fn.unwrap_or(Duration::from_secs(5)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| Duration::from_secs(5))` - | - = note: `-D clippy::or-fun-call` implied by `-D warnings` - -error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:36:22 - | -LL | with_constructor.unwrap_or(make()); - | ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(make)` - -error: use of `unwrap_or` followed by a call to `new` - --> $DIR/or_fun_call.rs:39:5 - | -LL | with_new.unwrap_or(Vec::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_new.unwrap_or_default()` - -error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:42:21 - | -LL | with_const_args.unwrap_or(Vec::with_capacity(12)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| Vec::with_capacity(12))` - -error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:45:14 - | -LL | with_err.unwrap_or(make()); - | ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| make())` - -error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:48:19 - | -LL | with_err_args.unwrap_or(Vec::with_capacity(12)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| Vec::with_capacity(12))` - -error: use of `unwrap_or` followed by a call to `default` - --> $DIR/or_fun_call.rs:51:5 - | -LL | with_default_trait.unwrap_or(Default::default()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_default_trait.unwrap_or_default()` - -error: use of `unwrap_or` followed by a call to `default` - --> $DIR/or_fun_call.rs:54:5 - | -LL | with_default_type.unwrap_or(u64::default()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_default_type.unwrap_or_default()` - -error: use of `unwrap_or` followed by a call to `new` - --> $DIR/or_fun_call.rs:57:5 - | -LL | with_vec.unwrap_or(vec![]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_vec.unwrap_or_default()` - -error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:60:21 - | -LL | without_default.unwrap_or(Foo::new()); - | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(Foo::new)` - -error: use of `or_insert` followed by a function call - --> $DIR/or_fun_call.rs:63:19 - | -LL | map.entry(42).or_insert(String::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_insert_with(String::new)` - -error: use of `or_insert` followed by a function call - --> $DIR/or_fun_call.rs:66:21 - | -LL | btree.entry(42).or_insert(String::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_insert_with(String::new)` - -error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:69:21 - | -LL | let _ = stringy.unwrap_or("".to_owned()); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| "".to_owned())` - -error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:77:21 - | -LL | let _ = Some(1).unwrap_or(map[&1]); - | ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])` - -error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:79:21 - | -LL | let _ = Some(1).unwrap_or(map[&1]); - | ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])` - -error: use of `or` followed by a function call - --> $DIR/or_fun_call.rs:103:35 - | -LL | let _ = Some("a".to_string()).or(Some("b".to_string())); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some("b".to_string()))` - -error: use of `or` followed by a function call - --> $DIR/or_fun_call.rs:107:10 - | -LL | .or(Some(Bar(b, Duration::from_secs(2)))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some(Bar(b, Duration::from_secs(2))))` - -error: aborting due to 17 previous errors - diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.rs b/tests/ui/out_of_bounds_indexing/issue-3102.rs deleted file mode 100644 index f20a0ede1137..000000000000 --- a/tests/ui/out_of_bounds_indexing/issue-3102.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![warn(clippy::out_of_bounds_indexing)] -#![allow(clippy::no_effect, const_err)] - -fn main() { - let x = [1, 2, 3, 4]; - - // issue 3102 - let num = 1; - &x[num..10]; // should trigger out of bounds error - &x[10..num]; // should trigger out of bounds error -} diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.stderr b/tests/ui/out_of_bounds_indexing/issue-3102.stderr deleted file mode 100644 index 516c1df40be0..000000000000 --- a/tests/ui/out_of_bounds_indexing/issue-3102.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: range is out of bounds - --> $DIR/issue-3102.rs:9:13 - | -LL | &x[num..10]; // should trigger out of bounds error - | ^^ - | - = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` - -error: range is out of bounds - --> $DIR/issue-3102.rs:10:8 - | -LL | &x[10..num]; // should trigger out of bounds error - | ^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/out_of_bounds_indexing/simple.rs b/tests/ui/out_of_bounds_indexing/simple.rs deleted file mode 100644 index 590e578d758e..000000000000 --- a/tests/ui/out_of_bounds_indexing/simple.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![warn(clippy::out_of_bounds_indexing)] -#![allow(clippy::no_effect, clippy::unnecessary_operation, const_err)] - -fn main() { - let x = [1, 2, 3, 4]; - - &x[..=4]; - &x[1..5]; - &x[5..]; - &x[..5]; - &x[5..].iter().map(|x| 2 * x).collect::>(); - &x[0..=4]; - - &x[4..]; // Ok, should not produce stderr. - &x[..4]; // Ok, should not produce stderr. - &x[..]; // Ok, should not produce stderr. - &x[1..]; // Ok, should not produce stderr. - &x[2..].iter().map(|x| 2 * x).collect::>(); // Ok, should not produce stderr. - - &x[0..].get(..3); // Ok, should not produce stderr. - &x[0..3]; // Ok, should not produce stderr. -} diff --git a/tests/ui/out_of_bounds_indexing/simple.stderr b/tests/ui/out_of_bounds_indexing/simple.stderr deleted file mode 100644 index 3d95afcdab23..000000000000 --- a/tests/ui/out_of_bounds_indexing/simple.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: range is out of bounds - --> $DIR/simple.rs:7:11 - | -LL | &x[..=4]; - | ^ - | - = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` - -error: range is out of bounds - --> $DIR/simple.rs:8:11 - | -LL | &x[1..5]; - | ^ - -error: range is out of bounds - --> $DIR/simple.rs:9:8 - | -LL | &x[5..]; - | ^ - -error: range is out of bounds - --> $DIR/simple.rs:10:10 - | -LL | &x[..5]; - | ^ - -error: range is out of bounds - --> $DIR/simple.rs:11:8 - | -LL | &x[5..].iter().map(|x| 2 * x).collect::>(); - | ^ - -error: range is out of bounds - --> $DIR/simple.rs:12:12 - | -LL | &x[0..=4]; - | ^ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/overflow_check_conditional.rs b/tests/ui/overflow_check_conditional.rs deleted file mode 100644 index 84332040dbad..000000000000 --- a/tests/ui/overflow_check_conditional.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![allow(clippy::many_single_char_names)] -#![warn(clippy::overflow_check_conditional)] - -fn main() { - let a: u32 = 1; - let b: u32 = 2; - let c: u32 = 3; - if a + b < a {} - if a > a + b {} - if a + b < b {} - if b > a + b {} - if a - b > b {} - if b < a - b {} - if a - b > a {} - if a < a - b {} - if a + b < c {} - if c > a + b {} - if a - b < c {} - if c > a - b {} - let i = 1.1; - let j = 2.2; - if i + j < i {} - if i - j < i {} - if i > i + j {} - if i - j < i {} -} diff --git a/tests/ui/overflow_check_conditional.stderr b/tests/ui/overflow_check_conditional.stderr deleted file mode 100644 index 19e843c2c0a5..000000000000 --- a/tests/ui/overflow_check_conditional.stderr +++ /dev/null @@ -1,52 +0,0 @@ -error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:8:8 - | -LL | if a + b < a {} - | ^^^^^^^^^ - | - = note: `-D clippy::overflow-check-conditional` implied by `-D warnings` - -error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:9:8 - | -LL | if a > a + b {} - | ^^^^^^^^^ - -error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:10:8 - | -LL | if a + b < b {} - | ^^^^^^^^^ - -error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:11:8 - | -LL | if b > a + b {} - | ^^^^^^^^^ - -error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:12:8 - | -LL | if a - b > b {} - | ^^^^^^^^^ - -error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:13:8 - | -LL | if b < a - b {} - | ^^^^^^^^^ - -error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:14:8 - | -LL | if a - b > a {} - | ^^^^^^^^^ - -error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:15:8 - | -LL | if a < a - b {} - | ^^^^^^^^^ - -error: aborting due to 8 previous errors - diff --git a/tests/ui/panic_in_result_fn.rs b/tests/ui/panic_in_result_fn.rs deleted file mode 100644 index 3d3c19a1be51..000000000000 --- a/tests/ui/panic_in_result_fn.rs +++ /dev/null @@ -1,71 +0,0 @@ -#![warn(clippy::panic_in_result_fn)] -#![allow(clippy::unnecessary_wraps)] - -struct A; - -impl A { - fn result_with_panic() -> Result // should emit lint - { - panic!("error"); - } - - fn result_with_unimplemented() -> Result // should emit lint - { - unimplemented!(); - } - - fn result_with_unreachable() -> Result // should emit lint - { - unreachable!(); - } - - fn result_with_todo() -> Result // should emit lint - { - todo!("Finish this"); - } - - fn other_with_panic() // should not emit lint - { - panic!(""); - } - - fn other_with_unreachable() // should not emit lint - { - unreachable!(); - } - - fn other_with_unimplemented() // should not emit lint - { - unimplemented!(); - } - - fn other_with_todo() // should not emit lint - { - todo!("finish this") - } - - fn result_without_banned_functions() -> Result // should not emit lint - { - Ok(true) - } -} - -fn function_result_with_panic() -> Result // should emit lint -{ - panic!("error"); -} - -fn todo() { - println!("something"); -} - -fn function_result_with_custom_todo() -> Result // should not emit lint -{ - todo(); - Ok(true) -} - -fn main() -> Result<(), String> { - todo!("finish main method"); - Ok(()) -} diff --git a/tests/ui/panic_in_result_fn.stderr b/tests/ui/panic_in_result_fn.stderr deleted file mode 100644 index eb744b0c198f..000000000000 --- a/tests/ui/panic_in_result_fn.stderr +++ /dev/null @@ -1,105 +0,0 @@ -error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn.rs:7:5 - | -LL | / fn result_with_panic() -> Result // should emit lint -LL | | { -LL | | panic!("error"); -LL | | } - | |_____^ - | - = note: `-D clippy::panic-in-result-fn` implied by `-D warnings` - = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing -note: return Err() instead of panicking - --> $DIR/panic_in_result_fn.rs:9:9 - | -LL | panic!("error"); - | ^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn.rs:12:5 - | -LL | / fn result_with_unimplemented() -> Result // should emit lint -LL | | { -LL | | unimplemented!(); -LL | | } - | |_____^ - | - = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing -note: return Err() instead of panicking - --> $DIR/panic_in_result_fn.rs:14:9 - | -LL | unimplemented!(); - | ^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn.rs:17:5 - | -LL | / fn result_with_unreachable() -> Result // should emit lint -LL | | { -LL | | unreachable!(); -LL | | } - | |_____^ - | - = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing -note: return Err() instead of panicking - --> $DIR/panic_in_result_fn.rs:19:9 - | -LL | unreachable!(); - | ^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn.rs:22:5 - | -LL | / fn result_with_todo() -> Result // should emit lint -LL | | { -LL | | todo!("Finish this"); -LL | | } - | |_____^ - | - = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing -note: return Err() instead of panicking - --> $DIR/panic_in_result_fn.rs:24:9 - | -LL | todo!("Finish this"); - | ^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn.rs:53:1 - | -LL | / fn function_result_with_panic() -> Result // should emit lint -LL | | { -LL | | panic!("error"); -LL | | } - | |_^ - | - = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing -note: return Err() instead of panicking - --> $DIR/panic_in_result_fn.rs:55:5 - | -LL | panic!("error"); - | ^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn.rs:68:1 - | -LL | / fn main() -> Result<(), String> { -LL | | todo!("finish main method"); -LL | | Ok(()) -LL | | } - | |_^ - | - = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing -note: return Err() instead of panicking - --> $DIR/panic_in_result_fn.rs:69:5 - | -LL | todo!("finish main method"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 6 previous errors - diff --git a/tests/ui/panic_in_result_fn_assertions.rs b/tests/ui/panic_in_result_fn_assertions.rs deleted file mode 100644 index ffdf8288adc7..000000000000 --- a/tests/ui/panic_in_result_fn_assertions.rs +++ /dev/null @@ -1,48 +0,0 @@ -#![warn(clippy::panic_in_result_fn)] -#![allow(clippy::unnecessary_wraps)] - -struct A; - -impl A { - fn result_with_assert_with_message(x: i32) -> Result // should emit lint - { - assert!(x == 5, "wrong argument"); - Ok(true) - } - - fn result_with_assert_eq(x: i32) -> Result // should emit lint - { - assert_eq!(x, 5); - Ok(true) - } - - fn result_with_assert_ne(x: i32) -> Result // should emit lint - { - assert_ne!(x, 1); - Ok(true) - } - - fn other_with_assert_with_message(x: i32) // should not emit lint - { - assert!(x == 5, "wrong argument"); - } - - fn other_with_assert_eq(x: i32) // should not emit lint - { - assert_eq!(x, 5); - } - - fn other_with_assert_ne(x: i32) // should not emit lint - { - assert_ne!(x, 1); - } - - fn result_without_banned_functions() -> Result // should not emit lint - { - let assert = "assert!"; - println!("No {}", assert); - Ok(true) - } -} - -fn main() {} diff --git a/tests/ui/panic_in_result_fn_assertions.stderr b/tests/ui/panic_in_result_fn_assertions.stderr deleted file mode 100644 index 86f61ad718a9..000000000000 --- a/tests/ui/panic_in_result_fn_assertions.stderr +++ /dev/null @@ -1,57 +0,0 @@ -error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn_assertions.rs:7:5 - | -LL | / fn result_with_assert_with_message(x: i32) -> Result // should emit lint -LL | | { -LL | | assert!(x == 5, "wrong argument"); -LL | | Ok(true) -LL | | } - | |_____^ - | - = note: `-D clippy::panic-in-result-fn` implied by `-D warnings` - = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing -note: return Err() instead of panicking - --> $DIR/panic_in_result_fn_assertions.rs:9:9 - | -LL | assert!(x == 5, "wrong argument"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn_assertions.rs:13:5 - | -LL | / fn result_with_assert_eq(x: i32) -> Result // should emit lint -LL | | { -LL | | assert_eq!(x, 5); -LL | | Ok(true) -LL | | } - | |_____^ - | - = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing -note: return Err() instead of panicking - --> $DIR/panic_in_result_fn_assertions.rs:15:9 - | -LL | assert_eq!(x, 5); - | ^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn_assertions.rs:19:5 - | -LL | / fn result_with_assert_ne(x: i32) -> Result // should emit lint -LL | | { -LL | | assert_ne!(x, 1); -LL | | Ok(true) -LL | | } - | |_____^ - | - = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing -note: return Err() instead of panicking - --> $DIR/panic_in_result_fn_assertions.rs:21:9 - | -LL | assert_ne!(x, 1); - | ^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 3 previous errors - diff --git a/tests/ui/panic_in_result_fn_debug_assertions.rs b/tests/ui/panic_in_result_fn_debug_assertions.rs deleted file mode 100644 index b60c79f97c86..000000000000 --- a/tests/ui/panic_in_result_fn_debug_assertions.rs +++ /dev/null @@ -1,48 +0,0 @@ -#![warn(clippy::panic_in_result_fn)] -#![allow(clippy::unnecessary_wraps)] - -struct A; - -impl A { - fn result_with_debug_assert_with_message(x: i32) -> Result // should emit lint - { - debug_assert!(x == 5, "wrong argument"); - Ok(true) - } - - fn result_with_debug_assert_eq(x: i32) -> Result // should emit lint - { - debug_assert_eq!(x, 5); - Ok(true) - } - - fn result_with_debug_assert_ne(x: i32) -> Result // should emit lint - { - debug_assert_ne!(x, 1); - Ok(true) - } - - fn other_with_debug_assert_with_message(x: i32) // should not emit lint - { - debug_assert!(x == 5, "wrong argument"); - } - - fn other_with_debug_assert_eq(x: i32) // should not emit lint - { - debug_assert_eq!(x, 5); - } - - fn other_with_debug_assert_ne(x: i32) // should not emit lint - { - debug_assert_ne!(x, 1); - } - - fn result_without_banned_functions() -> Result // should not emit lint - { - let debug_assert = "debug_assert!"; - println!("No {}", debug_assert); - Ok(true) - } -} - -fn main() {} diff --git a/tests/ui/panic_in_result_fn_debug_assertions.stderr b/tests/ui/panic_in_result_fn_debug_assertions.stderr deleted file mode 100644 index ec18e89698c5..000000000000 --- a/tests/ui/panic_in_result_fn_debug_assertions.stderr +++ /dev/null @@ -1,57 +0,0 @@ -error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn_debug_assertions.rs:7:5 - | -LL | / fn result_with_debug_assert_with_message(x: i32) -> Result // should emit lint -LL | | { -LL | | debug_assert!(x == 5, "wrong argument"); -LL | | Ok(true) -LL | | } - | |_____^ - | - = note: `-D clippy::panic-in-result-fn` implied by `-D warnings` - = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing -note: return Err() instead of panicking - --> $DIR/panic_in_result_fn_debug_assertions.rs:9:9 - | -LL | debug_assert!(x == 5, "wrong argument"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn_debug_assertions.rs:13:5 - | -LL | / fn result_with_debug_assert_eq(x: i32) -> Result // should emit lint -LL | | { -LL | | debug_assert_eq!(x, 5); -LL | | Ok(true) -LL | | } - | |_____^ - | - = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing -note: return Err() instead of panicking - --> $DIR/panic_in_result_fn_debug_assertions.rs:15:9 - | -LL | debug_assert_eq!(x, 5); - | ^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn_debug_assertions.rs:19:5 - | -LL | / fn result_with_debug_assert_ne(x: i32) -> Result // should emit lint -LL | | { -LL | | debug_assert_ne!(x, 1); -LL | | Ok(true) -LL | | } - | |_____^ - | - = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing -note: return Err() instead of panicking - --> $DIR/panic_in_result_fn_debug_assertions.rs:21:9 - | -LL | debug_assert_ne!(x, 1); - | ^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 3 previous errors - diff --git a/tests/ui/panicking_macros.rs b/tests/ui/panicking_macros.rs deleted file mode 100644 index 77fcb8dfd02f..000000000000 --- a/tests/ui/panicking_macros.rs +++ /dev/null @@ -1,52 +0,0 @@ -#![warn(clippy::unimplemented, clippy::unreachable, clippy::todo, clippy::panic)] -#![allow(clippy::assertions_on_constants)] - -extern crate core; - -fn panic() { - let a = 2; - panic!(); - panic!("message"); - panic!("{} {}", "panic with", "multiple arguments"); - let b = a + 2; -} - -fn todo() { - let a = 2; - todo!(); - todo!("message"); - todo!("{} {}", "panic with", "multiple arguments"); - let b = a + 2; -} - -fn unimplemented() { - let a = 2; - unimplemented!(); - unimplemented!("message"); - unimplemented!("{} {}", "panic with", "multiple arguments"); - let b = a + 2; -} - -fn unreachable() { - let a = 2; - unreachable!(); - unreachable!("message"); - unreachable!("{} {}", "panic with", "multiple arguments"); - let b = a + 2; -} - -fn core_versions() { - use core::{panic, todo, unimplemented, unreachable}; - panic!(); - todo!(); - unimplemented!(); - unreachable!(); -} - -fn main() { - panic(); - todo(); - unimplemented(); - unreachable(); - core_versions(); -} diff --git a/tests/ui/panicking_macros.stderr b/tests/ui/panicking_macros.stderr deleted file mode 100644 index 6028323a3c84..000000000000 --- a/tests/ui/panicking_macros.stderr +++ /dev/null @@ -1,112 +0,0 @@ -error: `panic` should not be present in production code - --> $DIR/panicking_macros.rs:8:5 - | -LL | panic!(); - | ^^^^^^^^^ - | - = note: `-D clippy::panic` implied by `-D warnings` - -error: `panic` should not be present in production code - --> $DIR/panicking_macros.rs:9:5 - | -LL | panic!("message"); - | ^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `panic` should not be present in production code - --> $DIR/panicking_macros.rs:10:5 - | -LL | panic!("{} {}", "panic with", "multiple arguments"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:16:5 - | -LL | todo!(); - | ^^^^^^^^ - | - = note: `-D clippy::todo` implied by `-D warnings` - -error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:17:5 - | -LL | todo!("message"); - | ^^^^^^^^^^^^^^^^^ - -error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:18:5 - | -LL | todo!("{} {}", "panic with", "multiple arguments"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:24:5 - | -LL | unimplemented!(); - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::unimplemented` implied by `-D warnings` - -error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:25:5 - | -LL | unimplemented!("message"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:26:5 - | -LL | unimplemented!("{} {}", "panic with", "multiple arguments"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: usage of the `unreachable!` macro - --> $DIR/panicking_macros.rs:32:5 - | -LL | unreachable!(); - | ^^^^^^^^^^^^^^^ - | - = note: `-D clippy::unreachable` implied by `-D warnings` - -error: usage of the `unreachable!` macro - --> $DIR/panicking_macros.rs:33:5 - | -LL | unreachable!("message"); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `unreachable!` macro - --> $DIR/panicking_macros.rs:34:5 - | -LL | unreachable!("{} {}", "panic with", "multiple arguments"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: `panic` should not be present in production code - --> $DIR/panicking_macros.rs:40:5 - | -LL | panic!(); - | ^^^^^^^^^ - -error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:41:5 - | -LL | todo!(); - | ^^^^^^^^ - -error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:42:5 - | -LL | unimplemented!(); - | ^^^^^^^^^^^^^^^^^ - -error: usage of the `unreachable!` macro - --> $DIR/panicking_macros.rs:43:5 - | -LL | unreachable!(); - | ^^^^^^^^^^^^^^^ - -error: aborting due to 16 previous errors - diff --git a/tests/ui/partialeq_ne_impl.rs b/tests/ui/partialeq_ne_impl.rs deleted file mode 100644 index 1338d3c74d55..000000000000 --- a/tests/ui/partialeq_ne_impl.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![allow(dead_code)] - -struct Foo; - -impl PartialEq for Foo { - fn eq(&self, _: &Foo) -> bool { - true - } - fn ne(&self, _: &Foo) -> bool { - false - } -} - -struct Bar; - -impl PartialEq for Bar { - fn eq(&self, _: &Bar) -> bool { - true - } - #[allow(clippy::partialeq_ne_impl)] - fn ne(&self, _: &Bar) -> bool { - false - } -} - -fn main() {} diff --git a/tests/ui/partialeq_ne_impl.stderr b/tests/ui/partialeq_ne_impl.stderr deleted file mode 100644 index b92da4511b48..000000000000 --- a/tests/ui/partialeq_ne_impl.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error: re-implementing `PartialEq::ne` is unnecessary - --> $DIR/partialeq_ne_impl.rs:9:5 - | -LL | / fn ne(&self, _: &Foo) -> bool { -LL | | false -LL | | } - | |_____^ - | - = note: `-D clippy::partialeq-ne-impl` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/path_buf_push_overwrite.fixed b/tests/ui/path_buf_push_overwrite.fixed deleted file mode 100644 index ef8856830fc9..000000000000 --- a/tests/ui/path_buf_push_overwrite.fixed +++ /dev/null @@ -1,8 +0,0 @@ -// run-rustfix -use std::path::PathBuf; - -#[warn(clippy::all, clippy::path_buf_push_overwrite)] -fn main() { - let mut x = PathBuf::from("/foo"); - x.push("bar"); -} diff --git a/tests/ui/path_buf_push_overwrite.rs b/tests/ui/path_buf_push_overwrite.rs deleted file mode 100644 index 6e2d483f4541..000000000000 --- a/tests/ui/path_buf_push_overwrite.rs +++ /dev/null @@ -1,8 +0,0 @@ -// run-rustfix -use std::path::PathBuf; - -#[warn(clippy::all, clippy::path_buf_push_overwrite)] -fn main() { - let mut x = PathBuf::from("/foo"); - x.push("/bar"); -} diff --git a/tests/ui/path_buf_push_overwrite.stderr b/tests/ui/path_buf_push_overwrite.stderr deleted file mode 100644 index bb8dce2bbba4..000000000000 --- a/tests/ui/path_buf_push_overwrite.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: calling `push` with '/' or '/' (file system root) will overwrite the previous path definition - --> $DIR/path_buf_push_overwrite.rs:7:12 - | -LL | x.push("/bar"); - | ^^^^^^ help: try: `"bar"` - | - = note: `-D clippy::path-buf-push-overwrite` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/pattern_type_mismatch/mutability.rs b/tests/ui/pattern_type_mismatch/mutability.rs deleted file mode 100644 index 9b4f2f1f5793..000000000000 --- a/tests/ui/pattern_type_mismatch/mutability.rs +++ /dev/null @@ -1,40 +0,0 @@ -#![allow(clippy::all)] -#![warn(clippy::pattern_type_mismatch)] - -fn main() {} - -fn should_lint() { - let value = &Some(23); - match value { - Some(_) => (), - _ => (), - } - - let value = &mut Some(23); - match value { - Some(_) => (), - _ => (), - } -} - -fn should_not_lint() { - let value = &Some(23); - match value { - &Some(_) => (), - _ => (), - } - match *value { - Some(_) => (), - _ => (), - } - - let value = &mut Some(23); - match value { - &mut Some(_) => (), - _ => (), - } - match *value { - Some(_) => (), - _ => (), - } -} diff --git a/tests/ui/pattern_type_mismatch/mutability.stderr b/tests/ui/pattern_type_mismatch/mutability.stderr deleted file mode 100644 index 3421d568365c..000000000000 --- a/tests/ui/pattern_type_mismatch/mutability.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: type of pattern does not match the expression type - --> $DIR/mutability.rs:9:9 - | -LL | Some(_) => (), - | ^^^^^^^ - | - = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` - = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/mutability.rs:15:9 - | -LL | Some(_) => (), - | ^^^^^^^ - | - = help: use `*` to dereference the match expression or explicitly match against a `&mut _` pattern and adjust the enclosed variable bindings - -error: aborting due to 2 previous errors - diff --git a/tests/ui/pattern_type_mismatch/pattern_alternatives.rs b/tests/ui/pattern_type_mismatch/pattern_alternatives.rs deleted file mode 100644 index 065ea9fb9b5a..000000000000 --- a/tests/ui/pattern_type_mismatch/pattern_alternatives.rs +++ /dev/null @@ -1,24 +0,0 @@ -#![allow(clippy::all)] -#![warn(clippy::pattern_type_mismatch)] - -fn main() {} - -fn alternatives() { - enum Value<'a> { - Unused, - A(&'a Option), - B, - } - let ref_value = &Value::A(&Some(23)); - - // not ok - if let Value::B | Value::A(_) = ref_value {} - if let &Value::B | &Value::A(Some(_)) = ref_value {} - if let Value::B | Value::A(Some(_)) = *ref_value {} - - // ok - if let &Value::B | &Value::A(_) = ref_value {} - if let Value::B | Value::A(_) = *ref_value {} - if let &Value::B | &Value::A(&Some(_)) = ref_value {} - if let Value::B | Value::A(&Some(_)) = *ref_value {} -} diff --git a/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr b/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr deleted file mode 100644 index d285c93782c6..000000000000 --- a/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error: type of pattern does not match the expression type - --> $DIR/pattern_alternatives.rs:15:12 - | -LL | if let Value::B | Value::A(_) = ref_value {} - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` - = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_alternatives.rs:16:34 - | -LL | if let &Value::B | &Value::A(Some(_)) = ref_value {} - | ^^^^^^^ - | - = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_alternatives.rs:17:32 - | -LL | if let Value::B | Value::A(Some(_)) = *ref_value {} - | ^^^^^^^ - | - = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: aborting due to 3 previous errors - diff --git a/tests/ui/pattern_type_mismatch/pattern_structs.rs b/tests/ui/pattern_type_mismatch/pattern_structs.rs deleted file mode 100644 index 417b1c107c55..000000000000 --- a/tests/ui/pattern_type_mismatch/pattern_structs.rs +++ /dev/null @@ -1,45 +0,0 @@ -#![allow(clippy::all)] -#![warn(clippy::pattern_type_mismatch)] - -fn main() {} - -fn struct_types() { - struct Struct<'a> { - ref_inner: &'a Option, - } - let ref_value = &Struct { ref_inner: &Some(42) }; - - // not ok - let Struct { .. } = ref_value; - if let &Struct { ref_inner: Some(_) } = ref_value {} - if let Struct { ref_inner: Some(_) } = *ref_value {} - - // ok - let &Struct { .. } = ref_value; - let Struct { .. } = *ref_value; - if let &Struct { ref_inner: &Some(_) } = ref_value {} - if let Struct { ref_inner: &Some(_) } = *ref_value {} -} - -fn struct_enum_variants() { - enum StructEnum<'a> { - Empty, - Var { inner_ref: &'a Option }, - } - let ref_value = &StructEnum::Var { inner_ref: &Some(42) }; - - // not ok - if let StructEnum::Var { .. } = ref_value {} - if let StructEnum::Var { inner_ref: Some(_) } = ref_value {} - if let &StructEnum::Var { inner_ref: Some(_) } = ref_value {} - if let StructEnum::Var { inner_ref: Some(_) } = *ref_value {} - if let StructEnum::Empty = ref_value {} - - // ok - if let &StructEnum::Var { .. } = ref_value {} - if let StructEnum::Var { .. } = *ref_value {} - if let &StructEnum::Var { inner_ref: &Some(_) } = ref_value {} - if let StructEnum::Var { inner_ref: &Some(_) } = *ref_value {} - if let &StructEnum::Empty = ref_value {} - if let StructEnum::Empty = *ref_value {} -} diff --git a/tests/ui/pattern_type_mismatch/pattern_structs.stderr b/tests/ui/pattern_type_mismatch/pattern_structs.stderr deleted file mode 100644 index d428e85b0c91..000000000000 --- a/tests/ui/pattern_type_mismatch/pattern_structs.stderr +++ /dev/null @@ -1,67 +0,0 @@ -error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:13:9 - | -LL | let Struct { .. } = ref_value; - | ^^^^^^^^^^^^^ - | - = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` - = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:14:33 - | -LL | if let &Struct { ref_inner: Some(_) } = ref_value {} - | ^^^^^^^ - | - = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:15:32 - | -LL | if let Struct { ref_inner: Some(_) } = *ref_value {} - | ^^^^^^^ - | - = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:32:12 - | -LL | if let StructEnum::Var { .. } = ref_value {} - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:33:12 - | -LL | if let StructEnum::Var { inner_ref: Some(_) } = ref_value {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:34:42 - | -LL | if let &StructEnum::Var { inner_ref: Some(_) } = ref_value {} - | ^^^^^^^ - | - = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:35:41 - | -LL | if let StructEnum::Var { inner_ref: Some(_) } = *ref_value {} - | ^^^^^^^ - | - = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:36:12 - | -LL | if let StructEnum::Empty = ref_value {} - | ^^^^^^^^^^^^^^^^^ - | - = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: aborting due to 8 previous errors - diff --git a/tests/ui/pattern_type_mismatch/pattern_tuples.rs b/tests/ui/pattern_type_mismatch/pattern_tuples.rs deleted file mode 100644 index 19504a051d8b..000000000000 --- a/tests/ui/pattern_type_mismatch/pattern_tuples.rs +++ /dev/null @@ -1,57 +0,0 @@ -#![allow(clippy::all)] -#![warn(clippy::pattern_type_mismatch)] - -fn main() {} - -fn tuple_types() { - struct TupleStruct<'a>(&'a Option); - let ref_value = &TupleStruct(&Some(42)); - - // not ok - let TupleStruct(_) = ref_value; - if let &TupleStruct(Some(_)) = ref_value {} - if let TupleStruct(Some(_)) = *ref_value {} - - // ok - let &TupleStruct(_) = ref_value; - let TupleStruct(_) = *ref_value; - if let &TupleStruct(&Some(_)) = ref_value {} - if let TupleStruct(&Some(_)) = *ref_value {} -} - -fn tuple_enum_variants() { - enum TupleEnum<'a> { - Empty, - Var(&'a Option), - } - let ref_value = &TupleEnum::Var(&Some(42)); - - // not ok - if let TupleEnum::Var(_) = ref_value {} - if let &TupleEnum::Var(Some(_)) = ref_value {} - if let TupleEnum::Var(Some(_)) = *ref_value {} - if let TupleEnum::Empty = ref_value {} - - // ok - if let &TupleEnum::Var(_) = ref_value {} - if let TupleEnum::Var(_) = *ref_value {} - if let &TupleEnum::Var(&Some(_)) = ref_value {} - if let TupleEnum::Var(&Some(_)) = *ref_value {} - if let &TupleEnum::Empty = ref_value {} - if let TupleEnum::Empty = *ref_value {} -} - -fn plain_tuples() { - let ref_value = &(&Some(23), &Some(42)); - - // not ok - let (_a, _b) = ref_value; - if let &(_a, Some(_)) = ref_value {} - if let (_a, Some(_)) = *ref_value {} - - // ok - let &(_a, _b) = ref_value; - let (_a, _b) = *ref_value; - if let &(_a, &Some(_)) = ref_value {} - if let (_a, &Some(_)) = *ref_value {} -} diff --git a/tests/ui/pattern_type_mismatch/pattern_tuples.stderr b/tests/ui/pattern_type_mismatch/pattern_tuples.stderr deleted file mode 100644 index edd0074d00d3..000000000000 --- a/tests/ui/pattern_type_mismatch/pattern_tuples.stderr +++ /dev/null @@ -1,83 +0,0 @@ -error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:11:9 - | -LL | let TupleStruct(_) = ref_value; - | ^^^^^^^^^^^^^^ - | - = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` - = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:12:25 - | -LL | if let &TupleStruct(Some(_)) = ref_value {} - | ^^^^^^^ - | - = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:13:24 - | -LL | if let TupleStruct(Some(_)) = *ref_value {} - | ^^^^^^^ - | - = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:30:12 - | -LL | if let TupleEnum::Var(_) = ref_value {} - | ^^^^^^^^^^^^^^^^^ - | - = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:31:28 - | -LL | if let &TupleEnum::Var(Some(_)) = ref_value {} - | ^^^^^^^ - | - = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:32:27 - | -LL | if let TupleEnum::Var(Some(_)) = *ref_value {} - | ^^^^^^^ - | - = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:33:12 - | -LL | if let TupleEnum::Empty = ref_value {} - | ^^^^^^^^^^^^^^^^ - | - = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:48:9 - | -LL | let (_a, _b) = ref_value; - | ^^^^^^^^ - | - = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:49:18 - | -LL | if let &(_a, Some(_)) = ref_value {} - | ^^^^^^^ - | - = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:50:17 - | -LL | if let (_a, Some(_)) = *ref_value {} - | ^^^^^^^ - | - = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: aborting due to 10 previous errors - diff --git a/tests/ui/pattern_type_mismatch/syntax.rs b/tests/ui/pattern_type_mismatch/syntax.rs deleted file mode 100644 index e89917c41e8c..000000000000 --- a/tests/ui/pattern_type_mismatch/syntax.rs +++ /dev/null @@ -1,146 +0,0 @@ -#![allow(clippy::all)] -#![warn(clippy::pattern_type_mismatch)] - -fn main() {} - -fn syntax_match() { - let ref_value = &Some(&Some(42)); - - // not ok - match ref_value { - Some(_) => (), - None => (), - } - - // ok - match ref_value { - &Some(_) => (), - &None => (), - } - match *ref_value { - Some(_) => (), - None => (), - } -} - -fn syntax_if_let() { - let ref_value = &Some(42); - - // not ok - if let Some(_) = ref_value {} - - // ok - if let &Some(_) = ref_value {} - if let Some(_) = *ref_value {} -} - -fn syntax_while_let() { - let ref_value = &Some(42); - - // not ok - while let Some(_) = ref_value { - break; - } - - // ok - while let &Some(_) = ref_value { - break; - } - while let Some(_) = *ref_value { - break; - } -} - -fn syntax_for() { - let ref_value = &Some(23); - let slice = &[(2, 3), (4, 2)]; - - // not ok - for (_a, _b) in slice.iter() {} - - // ok - for &(_a, _b) in slice.iter() {} -} - -fn syntax_let() { - let ref_value = &(2, 3); - - // not ok - let (_n, _m) = ref_value; - - // ok - let &(_n, _m) = ref_value; - let (_n, _m) = *ref_value; -} - -fn syntax_fn() { - // not ok - fn foo((_a, _b): &(i32, i32)) {} - - // ok - fn foo_ok_1(&(_a, _b): &(i32, i32)) {} -} - -fn syntax_closure() { - fn foo(f: F) - where - F: FnOnce(&(i32, i32)), - { - } - - // not ok - foo(|(_a, _b)| ()); - - // ok - foo(|&(_a, _b)| ()); -} - -fn macro_with_expression() { - macro_rules! matching_macro { - ($e:expr) => { - $e - }; - } - let value = &Some(23); - - // not ok - matching_macro!(match value { - Some(_) => (), - _ => (), - }); - - // ok - matching_macro!(match value { - &Some(_) => (), - _ => (), - }); - matching_macro!(match *value { - Some(_) => (), - _ => (), - }); -} - -fn macro_expansion() { - macro_rules! matching_macro { - ($e:expr) => { - // not ok - match $e { - Some(_) => (), - _ => (), - } - - // ok - match $e { - &Some(_) => (), - _ => (), - } - match *$e { - Some(_) => (), - _ => (), - } - }; - } - - let value = &Some(23); - matching_macro!(value); -} diff --git a/tests/ui/pattern_type_mismatch/syntax.stderr b/tests/ui/pattern_type_mismatch/syntax.stderr deleted file mode 100644 index 5a5186bd4fcb..000000000000 --- a/tests/ui/pattern_type_mismatch/syntax.stderr +++ /dev/null @@ -1,79 +0,0 @@ -error: type of pattern does not match the expression type - --> $DIR/syntax.rs:11:9 - | -LL | Some(_) => (), - | ^^^^^^^ - | - = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` - = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/syntax.rs:30:12 - | -LL | if let Some(_) = ref_value {} - | ^^^^^^^ - | - = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/syntax.rs:41:15 - | -LL | while let Some(_) = ref_value { - | ^^^^^^^ - | - = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/syntax.rs:59:9 - | -LL | for (_a, _b) in slice.iter() {} - | ^^^^^^^^ - | - = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/syntax.rs:69:9 - | -LL | let (_n, _m) = ref_value; - | ^^^^^^^^ - | - = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/syntax.rs:78:12 - | -LL | fn foo((_a, _b): &(i32, i32)) {} - | ^^^^^^^^ - | - = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/syntax.rs:92:10 - | -LL | foo(|(_a, _b)| ()); - | ^^^^^^^^ - | - = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/syntax.rs:108:9 - | -LL | Some(_) => (), - | ^^^^^^^ - | - = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - -error: type of pattern does not match the expression type - --> $DIR/syntax.rs:128:17 - | -LL | Some(_) => (), - | ^^^^^^^ -... -LL | matching_macro!(value); - | ----------------------- in this macro invocation - | - = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 9 previous errors - diff --git a/tests/ui/patterns.fixed b/tests/ui/patterns.fixed deleted file mode 100644 index f22388154499..000000000000 --- a/tests/ui/patterns.fixed +++ /dev/null @@ -1,36 +0,0 @@ -// run-rustfix -#![allow(unused)] -#![warn(clippy::all)] - -fn main() { - let v = Some(true); - let s = [0, 1, 2, 3, 4]; - match v { - Some(x) => (), - y => (), - } - match v { - Some(x) => (), - y @ None => (), // no error - } - match s { - [x, inside @ .., y] => (), // no error - [..] => (), - } - - let mut mutv = vec![1, 2, 3]; - - // required "ref" left out in suggestion: #5271 - match mutv { - ref mut x => { - x.push(4); - println!("vec: {:?}", x); - }, - ref y if y == &vec![0] => (), - } - - match mutv { - ref x => println!("vec: {:?}", x), - ref y if y == &vec![0] => (), - } -} diff --git a/tests/ui/patterns.rs b/tests/ui/patterns.rs deleted file mode 100644 index 5848ecd38d98..000000000000 --- a/tests/ui/patterns.rs +++ /dev/null @@ -1,36 +0,0 @@ -// run-rustfix -#![allow(unused)] -#![warn(clippy::all)] - -fn main() { - let v = Some(true); - let s = [0, 1, 2, 3, 4]; - match v { - Some(x) => (), - y @ _ => (), - } - match v { - Some(x) => (), - y @ None => (), // no error - } - match s { - [x, inside @ .., y] => (), // no error - [..] => (), - } - - let mut mutv = vec![1, 2, 3]; - - // required "ref" left out in suggestion: #5271 - match mutv { - ref mut x @ _ => { - x.push(4); - println!("vec: {:?}", x); - }, - ref y if y == &vec![0] => (), - } - - match mutv { - ref x @ _ => println!("vec: {:?}", x), - ref y if y == &vec![0] => (), - } -} diff --git a/tests/ui/patterns.stderr b/tests/ui/patterns.stderr deleted file mode 100644 index af067580688b..000000000000 --- a/tests/ui/patterns.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: the `y @ _` pattern can be written as just `y` - --> $DIR/patterns.rs:10:9 - | -LL | y @ _ => (), - | ^^^^^ help: try: `y` - | - = note: `-D clippy::redundant-pattern` implied by `-D warnings` - -error: the `x @ _` pattern can be written as just `x` - --> $DIR/patterns.rs:25:9 - | -LL | ref mut x @ _ => { - | ^^^^^^^^^^^^^ help: try: `ref mut x` - -error: the `x @ _` pattern can be written as just `x` - --> $DIR/patterns.rs:33:9 - | -LL | ref x @ _ => println!("vec: {:?}", x), - | ^^^^^^^^^ help: try: `ref x` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/precedence.fixed b/tests/ui/precedence.fixed deleted file mode 100644 index 163bd044c178..000000000000 --- a/tests/ui/precedence.fixed +++ /dev/null @@ -1,61 +0,0 @@ -// run-rustfix -#![warn(clippy::precedence)] -#![allow(unused_must_use, clippy::no_effect, clippy::unnecessary_operation)] -#![allow(clippy::identity_op)] -#![allow(clippy::eq_op)] - -macro_rules! trip { - ($a:expr) => { - match $a & 0b1111_1111u8 { - 0 => println!("a is zero ({})", $a), - _ => println!("a is {}", $a), - } - }; -} - -fn main() { - 1 << (2 + 3); - (1 + 2) << 3; - 4 >> (1 + 1); - (1 + 3) >> 2; - 1 ^ (1 - 1); - 3 | (2 - 1); - 3 & (5 - 2); - -(1i32.abs()); - -(1f32.abs()); - - // These should not trigger an error - let _ = (-1i32).abs(); - let _ = (-1f32).abs(); - let _ = -(1i32).abs(); - let _ = -(1f32).abs(); - let _ = -(1i32.abs()); - let _ = -(1f32.abs()); - - // Odd functions should not trigger an error - let _ = -1f64.asin(); - let _ = -1f64.asinh(); - let _ = -1f64.atan(); - let _ = -1f64.atanh(); - let _ = -1f64.cbrt(); - let _ = -1f64.fract(); - let _ = -1f64.round(); - let _ = -1f64.signum(); - let _ = -1f64.sin(); - let _ = -1f64.sinh(); - let _ = -1f64.tan(); - let _ = -1f64.tanh(); - let _ = -1f64.to_degrees(); - let _ = -1f64.to_radians(); - - // Chains containing any non-odd function should trigger (issue #5924) - let _ = -(1.0_f64.cos().cos()); - let _ = -(1.0_f64.cos().sin()); - let _ = -(1.0_f64.sin().cos()); - - // Chains of odd functions shouldn't trigger - let _ = -1f64.sin().sin(); - - let b = 3; - trip!(b * 8); -} diff --git a/tests/ui/precedence.rs b/tests/ui/precedence.rs deleted file mode 100644 index 8c849e3209b0..000000000000 --- a/tests/ui/precedence.rs +++ /dev/null @@ -1,61 +0,0 @@ -// run-rustfix -#![warn(clippy::precedence)] -#![allow(unused_must_use, clippy::no_effect, clippy::unnecessary_operation)] -#![allow(clippy::identity_op)] -#![allow(clippy::eq_op)] - -macro_rules! trip { - ($a:expr) => { - match $a & 0b1111_1111u8 { - 0 => println!("a is zero ({})", $a), - _ => println!("a is {}", $a), - } - }; -} - -fn main() { - 1 << 2 + 3; - 1 + 2 << 3; - 4 >> 1 + 1; - 1 + 3 >> 2; - 1 ^ 1 - 1; - 3 | 2 - 1; - 3 & 5 - 2; - -1i32.abs(); - -1f32.abs(); - - // These should not trigger an error - let _ = (-1i32).abs(); - let _ = (-1f32).abs(); - let _ = -(1i32).abs(); - let _ = -(1f32).abs(); - let _ = -(1i32.abs()); - let _ = -(1f32.abs()); - - // Odd functions should not trigger an error - let _ = -1f64.asin(); - let _ = -1f64.asinh(); - let _ = -1f64.atan(); - let _ = -1f64.atanh(); - let _ = -1f64.cbrt(); - let _ = -1f64.fract(); - let _ = -1f64.round(); - let _ = -1f64.signum(); - let _ = -1f64.sin(); - let _ = -1f64.sinh(); - let _ = -1f64.tan(); - let _ = -1f64.tanh(); - let _ = -1f64.to_degrees(); - let _ = -1f64.to_radians(); - - // Chains containing any non-odd function should trigger (issue #5924) - let _ = -1.0_f64.cos().cos(); - let _ = -1.0_f64.cos().sin(); - let _ = -1.0_f64.sin().cos(); - - // Chains of odd functions shouldn't trigger - let _ = -1f64.sin().sin(); - - let b = 3; - trip!(b * 8); -} diff --git a/tests/ui/precedence.stderr b/tests/ui/precedence.stderr deleted file mode 100644 index 03d585b39750..000000000000 --- a/tests/ui/precedence.stderr +++ /dev/null @@ -1,76 +0,0 @@ -error: operator precedence can trip the unwary - --> $DIR/precedence.rs:17:5 - | -LL | 1 << 2 + 3; - | ^^^^^^^^^^ help: consider parenthesizing your expression: `1 << (2 + 3)` - | - = note: `-D clippy::precedence` implied by `-D warnings` - -error: operator precedence can trip the unwary - --> $DIR/precedence.rs:18:5 - | -LL | 1 + 2 << 3; - | ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 2) << 3` - -error: operator precedence can trip the unwary - --> $DIR/precedence.rs:19:5 - | -LL | 4 >> 1 + 1; - | ^^^^^^^^^^ help: consider parenthesizing your expression: `4 >> (1 + 1)` - -error: operator precedence can trip the unwary - --> $DIR/precedence.rs:20:5 - | -LL | 1 + 3 >> 2; - | ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 3) >> 2` - -error: operator precedence can trip the unwary - --> $DIR/precedence.rs:21:5 - | -LL | 1 ^ 1 - 1; - | ^^^^^^^^^ help: consider parenthesizing your expression: `1 ^ (1 - 1)` - -error: operator precedence can trip the unwary - --> $DIR/precedence.rs:22:5 - | -LL | 3 | 2 - 1; - | ^^^^^^^^^ help: consider parenthesizing your expression: `3 | (2 - 1)` - -error: operator precedence can trip the unwary - --> $DIR/precedence.rs:23:5 - | -LL | 3 & 5 - 2; - | ^^^^^^^^^ help: consider parenthesizing your expression: `3 & (5 - 2)` - -error: unary minus has lower precedence than method call - --> $DIR/precedence.rs:24:5 - | -LL | -1i32.abs(); - | ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1i32.abs())` - -error: unary minus has lower precedence than method call - --> $DIR/precedence.rs:25:5 - | -LL | -1f32.abs(); - | ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1f32.abs())` - -error: unary minus has lower precedence than method call - --> $DIR/precedence.rs:52:13 - | -LL | let _ = -1.0_f64.cos().cos(); - | ^^^^^^^^^^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1.0_f64.cos().cos())` - -error: unary minus has lower precedence than method call - --> $DIR/precedence.rs:53:13 - | -LL | let _ = -1.0_f64.cos().sin(); - | ^^^^^^^^^^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1.0_f64.cos().sin())` - -error: unary minus has lower precedence than method call - --> $DIR/precedence.rs:54:13 - | -LL | let _ = -1.0_f64.sin().cos(); - | ^^^^^^^^^^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1.0_f64.sin().cos())` - -error: aborting due to 12 previous errors - diff --git a/tests/ui/print.rs b/tests/ui/print.rs deleted file mode 100644 index 366ccc2b3bd5..000000000000 --- a/tests/ui/print.rs +++ /dev/null @@ -1,35 +0,0 @@ -#![allow(clippy::print_literal, clippy::write_literal)] -#![warn(clippy::print_stdout, clippy::use_debug)] - -use std::fmt::{Debug, Display, Formatter, Result}; - -#[allow(dead_code)] -struct Foo; - -impl Display for Foo { - fn fmt(&self, f: &mut Formatter) -> Result { - write!(f, "{:?}", 43.1415) - } -} - -impl Debug for Foo { - fn fmt(&self, f: &mut Formatter) -> Result { - // ok, we can use `Debug` formatting in `Debug` implementations - write!(f, "{:?}", 42.718) - } -} - -fn main() { - println!("Hello"); - print!("Hello"); - - print!("Hello {}", "World"); - - print!("Hello {:?}", "World"); - - print!("Hello {:#?}", "#orld"); - - assert_eq!(42, 1337); - - vec![1, 2]; -} diff --git a/tests/ui/print.stderr b/tests/ui/print.stderr deleted file mode 100644 index 208d95326285..000000000000 --- a/tests/ui/print.stderr +++ /dev/null @@ -1,54 +0,0 @@ -error: use of `Debug`-based formatting - --> $DIR/print.rs:11:19 - | -LL | write!(f, "{:?}", 43.1415) - | ^^^^^^ - | - = note: `-D clippy::use-debug` implied by `-D warnings` - -error: use of `println!` - --> $DIR/print.rs:23:5 - | -LL | println!("Hello"); - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::print-stdout` implied by `-D warnings` - -error: use of `print!` - --> $DIR/print.rs:24:5 - | -LL | print!("Hello"); - | ^^^^^^^^^^^^^^^ - -error: use of `print!` - --> $DIR/print.rs:26:5 - | -LL | print!("Hello {}", "World"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: use of `print!` - --> $DIR/print.rs:28:5 - | -LL | print!("Hello {:?}", "World"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: use of `Debug`-based formatting - --> $DIR/print.rs:28:12 - | -LL | print!("Hello {:?}", "World"); - | ^^^^^^^^^^^^ - -error: use of `print!` - --> $DIR/print.rs:30:5 - | -LL | print!("Hello {:#?}", "#orld"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: use of `Debug`-based formatting - --> $DIR/print.rs:30:12 - | -LL | print!("Hello {:#?}", "#orld"); - | ^^^^^^^^^^^^^ - -error: aborting due to 8 previous errors - diff --git a/tests/ui/print_literal.rs b/tests/ui/print_literal.rs deleted file mode 100644 index 40ed18e93026..000000000000 --- a/tests/ui/print_literal.rs +++ /dev/null @@ -1,38 +0,0 @@ -#![warn(clippy::print_literal)] - -fn main() { - // these should be fine - print!("Hello"); - println!("Hello"); - let world = "world"; - println!("Hello {}", world); - println!("Hello {world}", world = world); - println!("3 in hex is {:X}", 3); - println!("2 + 1 = {:.4}", 3); - println!("2 + 1 = {:5.4}", 3); - println!("Debug test {:?}", "hello, world"); - println!("{0:8} {1:>8}", "hello", "world"); - println!("{1:8} {0:>8}", "hello", "world"); - println!("{foo:8} {bar:>8}", foo = "hello", bar = "world"); - println!("{bar:8} {foo:>8}", foo = "hello", bar = "world"); - println!("{number:>width$}", number = 1, width = 6); - println!("{number:>0width$}", number = 1, width = 6); - - // these should throw warnings - println!("{} of {:b} people know binary, the other half doesn't", 1, 2); - print!("Hello {}", "world"); - println!("Hello {} {}", world, "world"); - println!("Hello {}", "world"); - println!("10 / 4 is {}", 2.5); - println!("2 + 1 = {}", 3); - - // positional args don't change the fact - // that we're using a literal -- this should - // throw a warning - println!("{0} {1}", "hello", "world"); - println!("{1} {0}", "hello", "world"); - - // named args shouldn't change anything either - println!("{foo} {bar}", foo = "hello", bar = "world"); - println!("{bar} {foo}", foo = "hello", bar = "world"); -} diff --git a/tests/ui/print_literal.stderr b/tests/ui/print_literal.stderr deleted file mode 100644 index fc502e9f71d5..000000000000 --- a/tests/ui/print_literal.stderr +++ /dev/null @@ -1,88 +0,0 @@ -error: literal with an empty format string - --> $DIR/print_literal.rs:22:71 - | -LL | println!("{} of {:b} people know binary, the other half doesn't", 1, 2); - | ^ - | - = note: `-D clippy::print-literal` implied by `-D warnings` - -error: literal with an empty format string - --> $DIR/print_literal.rs:23:24 - | -LL | print!("Hello {}", "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/print_literal.rs:24:36 - | -LL | println!("Hello {} {}", world, "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/print_literal.rs:25:26 - | -LL | println!("Hello {}", "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/print_literal.rs:26:30 - | -LL | println!("10 / 4 is {}", 2.5); - | ^^^ - -error: literal with an empty format string - --> $DIR/print_literal.rs:27:28 - | -LL | println!("2 + 1 = {}", 3); - | ^ - -error: literal with an empty format string - --> $DIR/print_literal.rs:32:25 - | -LL | println!("{0} {1}", "hello", "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/print_literal.rs:32:34 - | -LL | println!("{0} {1}", "hello", "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/print_literal.rs:33:25 - | -LL | println!("{1} {0}", "hello", "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/print_literal.rs:33:34 - | -LL | println!("{1} {0}", "hello", "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/print_literal.rs:36:35 - | -LL | println!("{foo} {bar}", foo = "hello", bar = "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/print_literal.rs:36:50 - | -LL | println!("{foo} {bar}", foo = "hello", bar = "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/print_literal.rs:37:35 - | -LL | println!("{bar} {foo}", foo = "hello", bar = "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/print_literal.rs:37:50 - | -LL | println!("{bar} {foo}", foo = "hello", bar = "world"); - | ^^^^^^^ - -error: aborting due to 14 previous errors - diff --git a/tests/ui/print_stderr.rs b/tests/ui/print_stderr.rs deleted file mode 100644 index fa07e74a7be4..000000000000 --- a/tests/ui/print_stderr.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![warn(clippy::print_stderr)] - -fn main() { - eprintln!("Hello"); - println!("This should not do anything"); - eprint!("World"); - print!("Nor should this"); -} diff --git a/tests/ui/print_stderr.stderr b/tests/ui/print_stderr.stderr deleted file mode 100644 index 5af735af6576..000000000000 --- a/tests/ui/print_stderr.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: use of `eprintln!` - --> $DIR/print_stderr.rs:4:5 - | -LL | eprintln!("Hello"); - | ^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::print-stderr` implied by `-D warnings` - -error: use of `eprint!` - --> $DIR/print_stderr.rs:6:5 - | -LL | eprint!("World"); - | ^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/print_stdout_build_script.rs b/tests/ui/print_stdout_build_script.rs deleted file mode 100644 index 997ebef8a699..000000000000 --- a/tests/ui/print_stdout_build_script.rs +++ /dev/null @@ -1,12 +0,0 @@ -// compile-flags: --crate-name=build_script_build - -#![warn(clippy::print_stdout)] - -fn main() { - // Fix #6041 - // - // The `print_stdout` lint shouldn't emit in `build.rs` - // as these methods are used for the build script. - println!("Hello"); - print!("Hello"); -} diff --git a/tests/ui/print_with_newline.rs b/tests/ui/print_with_newline.rs deleted file mode 100644 index a43a1fc4f524..000000000000 --- a/tests/ui/print_with_newline.rs +++ /dev/null @@ -1,52 +0,0 @@ -// FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 -// // run-rustfix - -#![allow(clippy::print_literal)] -#![warn(clippy::print_with_newline)] - -fn main() { - print!("Hello\n"); - print!("Hello {}\n", "world"); - print!("Hello {} {}\n", "world", "#2"); - print!("{}\n", 1265); - print!("\n"); - - // these are all fine - print!(""); - print!("Hello"); - println!("Hello"); - println!("Hello\n"); - println!("Hello {}\n", "world"); - print!("Issue\n{}", 1265); - print!("{}", 1265); - print!("\n{}", 1275); - print!("\n\n"); - print!("like eof\n\n"); - print!("Hello {} {}\n\n", "world", "#2"); - println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - println!("\nbla\n\n"); // #3126 - - // Escaping - print!("\\n"); // #3514 - print!("\\\n"); // should fail - print!("\\\\n"); - - // Raw strings - print!(r"\n"); // #3778 - - // Literal newlines should also fail - print!( - " -" - ); - print!( - r" -" - ); - - // Don't warn on CRLF (#4208) - print!("\r\n"); - print!("foo\r\n"); - print!("\\r\n"); //~ ERROR - print!("foo\rbar\n") // ~ ERROR -} diff --git a/tests/ui/print_with_newline.stderr b/tests/ui/print_with_newline.stderr deleted file mode 100644 index 54b3ad75b31e..000000000000 --- a/tests/ui/print_with_newline.stderr +++ /dev/null @@ -1,121 +0,0 @@ -error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:8:5 - | -LL | print!("Hello/n"); - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::print-with-newline` implied by `-D warnings` -help: use `println!` instead - | -LL | println!("Hello"); - | ^^^^^^^ -- - -error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:9:5 - | -LL | print!("Hello {}/n", "world"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: use `println!` instead - | -LL | println!("Hello {}", "world"); - | ^^^^^^^ -- - -error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:10:5 - | -LL | print!("Hello {} {}/n", "world", "#2"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: use `println!` instead - | -LL | println!("Hello {} {}", "world", "#2"); - | ^^^^^^^ -- - -error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:11:5 - | -LL | print!("{}/n", 1265); - | ^^^^^^^^^^^^^^^^^^^^ - | -help: use `println!` instead - | -LL | println!("{}", 1265); - | ^^^^^^^ -- - -error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:12:5 - | -LL | print!("/n"); - | ^^^^^^^^^^^^ - | -help: use `println!` instead - | -LL | println!(); - | ^^^^^^^ -- - -error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:31:5 - | -LL | print!("//n"); // should fail - | ^^^^^^^^^^^^^^ - | -help: use `println!` instead - | -LL | println!("/"); // should fail - | ^^^^^^^ -- - -error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:38:5 - | -LL | / print!( -LL | | " -LL | | " -LL | | ); - | |_____^ - | -help: use `println!` instead - | -LL | println!( -LL | "" - | - -error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:42:5 - | -LL | / print!( -LL | | r" -LL | | " -LL | | ); - | |_____^ - | -help: use `println!` instead - | -LL | println!( -LL | r"" - | - -error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:50:5 - | -LL | print!("/r/n"); //~ ERROR - | ^^^^^^^^^^^^^^^ - | -help: use `println!` instead - | -LL | println!("/r"); //~ ERROR - | ^^^^^^^ -- - -error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:51:5 - | -LL | print!("foo/rbar/n") // ~ ERROR - | ^^^^^^^^^^^^^^^^^^^^ - | -help: use `println!` instead - | -LL | println!("foo/rbar") // ~ ERROR - | ^^^^^^^ -- - -error: aborting due to 10 previous errors - diff --git a/tests/ui/println_empty_string.fixed b/tests/ui/println_empty_string.fixed deleted file mode 100644 index 9760680927a6..000000000000 --- a/tests/ui/println_empty_string.fixed +++ /dev/null @@ -1,18 +0,0 @@ -// run-rustfix -#![allow(clippy::match_single_binding)] - -fn main() { - println!(); - println!(); - - match "a" { - _ => println!(), - } - - eprintln!(); - eprintln!(); - - match "a" { - _ => eprintln!(), - } -} diff --git a/tests/ui/println_empty_string.rs b/tests/ui/println_empty_string.rs deleted file mode 100644 index 80fdb3e6e210..000000000000 --- a/tests/ui/println_empty_string.rs +++ /dev/null @@ -1,18 +0,0 @@ -// run-rustfix -#![allow(clippy::match_single_binding)] - -fn main() { - println!(); - println!(""); - - match "a" { - _ => println!(""), - } - - eprintln!(); - eprintln!(""); - - match "a" { - _ => eprintln!(""), - } -} diff --git a/tests/ui/println_empty_string.stderr b/tests/ui/println_empty_string.stderr deleted file mode 100644 index 17fe4ea74790..000000000000 --- a/tests/ui/println_empty_string.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: using `println!("")` - --> $DIR/println_empty_string.rs:6:5 - | -LL | println!(""); - | ^^^^^^^^^^^^ help: replace it with: `println!()` - | - = note: `-D clippy::println-empty-string` implied by `-D warnings` - -error: using `println!("")` - --> $DIR/println_empty_string.rs:9:14 - | -LL | _ => println!(""), - | ^^^^^^^^^^^^ help: replace it with: `println!()` - -error: using `eprintln!("")` - --> $DIR/println_empty_string.rs:13:5 - | -LL | eprintln!(""); - | ^^^^^^^^^^^^^ help: replace it with: `eprintln!()` - -error: using `eprintln!("")` - --> $DIR/println_empty_string.rs:16:14 - | -LL | _ => eprintln!(""), - | ^^^^^^^^^^^^^ help: replace it with: `eprintln!()` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/proc_macro.rs b/tests/ui/proc_macro.rs deleted file mode 100644 index 59914b8b8f62..000000000000 --- a/tests/ui/proc_macro.rs +++ /dev/null @@ -1,26 +0,0 @@ -//! Check that we correctly lint procedural macros. -#![crate_type = "proc-macro"] - -extern crate proc_macro; - -use proc_macro::TokenStream; - -#[allow(dead_code)] -fn f() { - let _x = 3.14; -} - -#[proc_macro] -pub fn mybangmacro(t: TokenStream) -> TokenStream { - t -} - -#[proc_macro_derive(MyDerivedTrait)] -pub fn myderive(t: TokenStream) -> TokenStream { - t -} - -#[proc_macro_attribute] -pub fn myattribute(t: TokenStream, a: TokenStream) -> TokenStream { - t -} diff --git a/tests/ui/proc_macro.stderr b/tests/ui/proc_macro.stderr deleted file mode 100644 index 872cbc66af62..000000000000 --- a/tests/ui/proc_macro.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: approximate value of `f{32, 64}::consts::PI` found. Consider using it directly - --> $DIR/proc_macro.rs:10:14 - | -LL | let _x = 3.14; - | ^^^^ - | - = note: `#[deny(clippy::approx_constant)]` on by default - -error: aborting due to previous error - diff --git a/tests/ui/ptr_arg.rs b/tests/ui/ptr_arg.rs deleted file mode 100644 index 541225e63510..000000000000 --- a/tests/ui/ptr_arg.rs +++ /dev/null @@ -1,116 +0,0 @@ -#![allow(unused, clippy::many_single_char_names, clippy::redundant_clone)] -#![warn(clippy::ptr_arg)] - -use std::borrow::Cow; - -fn do_vec(x: &Vec) { - //Nothing here -} - -fn do_vec_mut(x: &mut Vec) { - // no error here - //Nothing here -} - -fn do_str(x: &String) { - //Nothing here either -} - -fn do_str_mut(x: &mut String) { - // no error here - //Nothing here either -} - -fn main() {} - -trait Foo { - type Item; - fn do_vec(x: &Vec); - fn do_item(x: &Self::Item); -} - -struct Bar; - -// no error, in trait impl (#425) -impl Foo for Bar { - type Item = Vec; - fn do_vec(x: &Vec) {} - fn do_item(x: &Vec) {} -} - -fn cloned(x: &Vec) -> Vec { - let e = x.clone(); - let f = e.clone(); // OK - let g = x; - let h = g.clone(); // Alas, we cannot reliably detect this without following data. - let i = (e).clone(); - x.clone() -} - -fn str_cloned(x: &String) -> String { - let a = x.clone(); - let b = x.clone(); - let c = b.clone(); - let d = a.clone().clone().clone(); - x.clone() -} - -fn false_positive_capacity(x: &Vec, y: &String) { - let a = x.capacity(); - let b = y.clone(); - let c = y.as_str(); -} - -fn false_positive_capacity_too(x: &String) -> String { - if x.capacity() > 1024 { - panic!("Too large!"); - } - x.clone() -} - -#[allow(dead_code)] -fn test_cow_with_ref(c: &Cow<[i32]>) {} - -fn test_cow(c: Cow<[i32]>) { - let _c = c; -} - -trait Foo2 { - fn do_string(&self); -} - -// no error for &self references where self is of type String (#2293) -impl Foo2 for String { - fn do_string(&self) {} -} - -// Check that the allow attribute on parameters is honored -mod issue_5644 { - use std::borrow::Cow; - - fn allowed( - #[allow(clippy::ptr_arg)] _v: &Vec, - #[allow(clippy::ptr_arg)] _s: &String, - #[allow(clippy::ptr_arg)] _c: &Cow<[i32]>, - ) { - } - - struct S {} - impl S { - fn allowed( - #[allow(clippy::ptr_arg)] _v: &Vec, - #[allow(clippy::ptr_arg)] _s: &String, - #[allow(clippy::ptr_arg)] _c: &Cow<[i32]>, - ) { - } - } - - trait T { - fn allowed( - #[allow(clippy::ptr_arg)] _v: &Vec, - #[allow(clippy::ptr_arg)] _s: &String, - #[allow(clippy::ptr_arg)] _c: &Cow<[i32]>, - ) { - } - } -} diff --git a/tests/ui/ptr_arg.stderr b/tests/ui/ptr_arg.stderr deleted file mode 100644 index 314f23497f97..000000000000 --- a/tests/ui/ptr_arg.stderr +++ /dev/null @@ -1,89 +0,0 @@ -error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices. - --> $DIR/ptr_arg.rs:6:14 - | -LL | fn do_vec(x: &Vec) { - | ^^^^^^^^^ help: change this to: `&[i64]` - | - = note: `-D clippy::ptr-arg` implied by `-D warnings` - -error: writing `&String` instead of `&str` involves a new object where a slice will do. - --> $DIR/ptr_arg.rs:15:14 - | -LL | fn do_str(x: &String) { - | ^^^^^^^ help: change this to: `&str` - -error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices. - --> $DIR/ptr_arg.rs:28:18 - | -LL | fn do_vec(x: &Vec); - | ^^^^^^^^^ help: change this to: `&[i64]` - -error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices. - --> $DIR/ptr_arg.rs:41:14 - | -LL | fn cloned(x: &Vec) -> Vec { - | ^^^^^^^^ - | -help: change this to - | -LL | fn cloned(x: &[u8]) -> Vec { - | ^^^^^ -help: change `x.clone()` to - | -LL | let e = x.to_owned(); - | ^^^^^^^^^^^^ -help: change `x.clone()` to - | -LL | x.to_owned() - | - -error: writing `&String` instead of `&str` involves a new object where a slice will do. - --> $DIR/ptr_arg.rs:50:18 - | -LL | fn str_cloned(x: &String) -> String { - | ^^^^^^^ - | -help: change this to - | -LL | fn str_cloned(x: &str) -> String { - | ^^^^ -help: change `x.clone()` to - | -LL | let a = x.to_string(); - | ^^^^^^^^^^^^^ -help: change `x.clone()` to - | -LL | let b = x.to_string(); - | ^^^^^^^^^^^^^ -help: change `x.clone()` to - | -LL | x.to_string() - | - -error: writing `&String` instead of `&str` involves a new object where a slice will do. - --> $DIR/ptr_arg.rs:58:44 - | -LL | fn false_positive_capacity(x: &Vec, y: &String) { - | ^^^^^^^ - | -help: change this to - | -LL | fn false_positive_capacity(x: &Vec, y: &str) { - | ^^^^ -help: change `y.clone()` to - | -LL | let b = y.to_string(); - | ^^^^^^^^^^^^^ -help: change `y.as_str()` to - | -LL | let c = y; - | ^ - -error: using a reference to `Cow` is not recommended. - --> $DIR/ptr_arg.rs:72:25 - | -LL | fn test_cow_with_ref(c: &Cow<[i32]>) {} - | ^^^^^^^^^^^ help: change this to: `&[i32]` - -error: aborting due to 7 previous errors - diff --git a/tests/ui/ptr_eq.fixed b/tests/ui/ptr_eq.fixed deleted file mode 100644 index 209081e6e801..000000000000 --- a/tests/ui/ptr_eq.fixed +++ /dev/null @@ -1,38 +0,0 @@ -// run-rustfix -#![warn(clippy::ptr_eq)] - -macro_rules! mac { - ($a:expr, $b:expr) => { - $a as *const _ as usize == $b as *const _ as usize - }; -} - -macro_rules! another_mac { - ($a:expr, $b:expr) => { - $a as *const _ == $b as *const _ - }; -} - -fn main() { - let a = &[1, 2, 3]; - let b = &[1, 2, 3]; - - let _ = std::ptr::eq(a, b); - let _ = std::ptr::eq(a, b); - let _ = a.as_ptr() == b as *const _; - let _ = a.as_ptr() == b.as_ptr(); - - // Do not lint - - let _ = mac!(a, b); - let _ = another_mac!(a, b); - - let a = &mut [1, 2, 3]; - let b = &mut [1, 2, 3]; - - let _ = a.as_mut_ptr() == b as *mut [i32] as *mut _; - let _ = a.as_mut_ptr() == b.as_mut_ptr(); - - let _ = a == b; - let _ = core::ptr::eq(a, b); -} diff --git a/tests/ui/ptr_eq.rs b/tests/ui/ptr_eq.rs deleted file mode 100644 index 69162870807a..000000000000 --- a/tests/ui/ptr_eq.rs +++ /dev/null @@ -1,38 +0,0 @@ -// run-rustfix -#![warn(clippy::ptr_eq)] - -macro_rules! mac { - ($a:expr, $b:expr) => { - $a as *const _ as usize == $b as *const _ as usize - }; -} - -macro_rules! another_mac { - ($a:expr, $b:expr) => { - $a as *const _ == $b as *const _ - }; -} - -fn main() { - let a = &[1, 2, 3]; - let b = &[1, 2, 3]; - - let _ = a as *const _ as usize == b as *const _ as usize; - let _ = a as *const _ == b as *const _; - let _ = a.as_ptr() == b as *const _; - let _ = a.as_ptr() == b.as_ptr(); - - // Do not lint - - let _ = mac!(a, b); - let _ = another_mac!(a, b); - - let a = &mut [1, 2, 3]; - let b = &mut [1, 2, 3]; - - let _ = a.as_mut_ptr() == b as *mut [i32] as *mut _; - let _ = a.as_mut_ptr() == b.as_mut_ptr(); - - let _ = a == b; - let _ = core::ptr::eq(a, b); -} diff --git a/tests/ui/ptr_eq.stderr b/tests/ui/ptr_eq.stderr deleted file mode 100644 index 45d8c60382b5..000000000000 --- a/tests/ui/ptr_eq.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: use `std::ptr::eq` when comparing raw pointers - --> $DIR/ptr_eq.rs:20:13 - | -LL | let _ = a as *const _ as usize == b as *const _ as usize; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(a, b)` - | - = note: `-D clippy::ptr-eq` implied by `-D warnings` - -error: use `std::ptr::eq` when comparing raw pointers - --> $DIR/ptr_eq.rs:21:13 - | -LL | let _ = a as *const _ == b as *const _; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(a, b)` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/ptr_offset_with_cast.fixed b/tests/ui/ptr_offset_with_cast.fixed deleted file mode 100644 index 718e391e8bf6..000000000000 --- a/tests/ui/ptr_offset_with_cast.fixed +++ /dev/null @@ -1,20 +0,0 @@ -// run-rustfix - -fn main() { - let vec = vec![b'a', b'b', b'c']; - let ptr = vec.as_ptr(); - - let offset_u8 = 1_u8; - let offset_usize = 1_usize; - let offset_isize = 1_isize; - - unsafe { - let _ = ptr.add(offset_usize); - let _ = ptr.offset(offset_isize as isize); - let _ = ptr.offset(offset_u8 as isize); - - let _ = ptr.wrapping_add(offset_usize); - let _ = ptr.wrapping_offset(offset_isize as isize); - let _ = ptr.wrapping_offset(offset_u8 as isize); - } -} diff --git a/tests/ui/ptr_offset_with_cast.rs b/tests/ui/ptr_offset_with_cast.rs deleted file mode 100644 index f613742c741e..000000000000 --- a/tests/ui/ptr_offset_with_cast.rs +++ /dev/null @@ -1,20 +0,0 @@ -// run-rustfix - -fn main() { - let vec = vec![b'a', b'b', b'c']; - let ptr = vec.as_ptr(); - - let offset_u8 = 1_u8; - let offset_usize = 1_usize; - let offset_isize = 1_isize; - - unsafe { - let _ = ptr.offset(offset_usize as isize); - let _ = ptr.offset(offset_isize as isize); - let _ = ptr.offset(offset_u8 as isize); - - let _ = ptr.wrapping_offset(offset_usize as isize); - let _ = ptr.wrapping_offset(offset_isize as isize); - let _ = ptr.wrapping_offset(offset_u8 as isize); - } -} diff --git a/tests/ui/ptr_offset_with_cast.stderr b/tests/ui/ptr_offset_with_cast.stderr deleted file mode 100644 index fd45224ca067..000000000000 --- a/tests/ui/ptr_offset_with_cast.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: use of `offset` with a `usize` casted to an `isize` - --> $DIR/ptr_offset_with_cast.rs:12:17 - | -LL | let _ = ptr.offset(offset_usize as isize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.add(offset_usize)` - | - = note: `-D clippy::ptr-offset-with-cast` implied by `-D warnings` - -error: use of `wrapping_offset` with a `usize` casted to an `isize` - --> $DIR/ptr_offset_with_cast.rs:16:17 - | -LL | let _ = ptr.wrapping_offset(offset_usize as isize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.wrapping_add(offset_usize)` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/question_mark.fixed b/tests/ui/question_mark.fixed deleted file mode 100644 index 0b5746cb5227..000000000000 --- a/tests/ui/question_mark.fixed +++ /dev/null @@ -1,126 +0,0 @@ -// run-rustfix -#![allow(unreachable_code)] -#![allow(clippy::unnecessary_wraps)] - -fn some_func(a: Option) -> Option { - a?; - - a -} - -fn some_other_func(a: Option) -> Option { - if a.is_none() { - return None; - } else { - return Some(0); - } - unreachable!() -} - -pub enum SeemsOption { - Some(T), - None, -} - -impl SeemsOption { - pub fn is_none(&self) -> bool { - match *self { - SeemsOption::None => true, - SeemsOption::Some(_) => false, - } - } -} - -fn returns_something_similar_to_option(a: SeemsOption) -> SeemsOption { - if a.is_none() { - return SeemsOption::None; - } - - a -} - -pub struct CopyStruct { - pub opt: Option, -} - -impl CopyStruct { - #[rustfmt::skip] - pub fn func(&self) -> Option { - (self.opt)?; - - self.opt?; - - let _ = Some(self.opt?); - - let _ = self.opt?; - - self.opt - } -} - -#[derive(Clone)] -pub struct MoveStruct { - pub opt: Option>, -} - -impl MoveStruct { - pub fn ref_func(&self) -> Option> { - self.opt.as_ref()?; - - self.opt.clone() - } - - pub fn mov_func_reuse(self) -> Option> { - self.opt.as_ref()?; - - self.opt - } - - pub fn mov_func_no_use(self) -> Option> { - self.opt.as_ref()?; - Some(Vec::new()) - } - - pub fn if_let_ref_func(self) -> Option> { - let v: &Vec<_> = self.opt.as_ref()?; - - Some(v.clone()) - } - - pub fn if_let_mov_func(self) -> Option> { - let v = self.opt?; - - Some(v) - } -} - -fn func() -> Option { - fn f() -> Option { - Some(String::new()) - } - - f()?; - - Some(0) -} - -fn main() { - some_func(Some(42)); - some_func(None); - some_other_func(Some(42)); - - let copy_struct = CopyStruct { opt: Some(54) }; - copy_struct.func(); - - let move_struct = MoveStruct { - opt: Some(vec![42, 1337]), - }; - move_struct.ref_func(); - move_struct.clone().mov_func_reuse(); - move_struct.mov_func_no_use(); - - let so = SeemsOption::Some(45); - returns_something_similar_to_option(so); - - func(); -} diff --git a/tests/ui/question_mark.rs b/tests/ui/question_mark.rs deleted file mode 100644 index 0f0825c93346..000000000000 --- a/tests/ui/question_mark.rs +++ /dev/null @@ -1,156 +0,0 @@ -// run-rustfix -#![allow(unreachable_code)] -#![allow(clippy::unnecessary_wraps)] - -fn some_func(a: Option) -> Option { - if a.is_none() { - return None; - } - - a -} - -fn some_other_func(a: Option) -> Option { - if a.is_none() { - return None; - } else { - return Some(0); - } - unreachable!() -} - -pub enum SeemsOption { - Some(T), - None, -} - -impl SeemsOption { - pub fn is_none(&self) -> bool { - match *self { - SeemsOption::None => true, - SeemsOption::Some(_) => false, - } - } -} - -fn returns_something_similar_to_option(a: SeemsOption) -> SeemsOption { - if a.is_none() { - return SeemsOption::None; - } - - a -} - -pub struct CopyStruct { - pub opt: Option, -} - -impl CopyStruct { - #[rustfmt::skip] - pub fn func(&self) -> Option { - if (self.opt).is_none() { - return None; - } - - if self.opt.is_none() { - return None - } - - let _ = if self.opt.is_none() { - return None; - } else { - self.opt - }; - - let _ = if let Some(x) = self.opt { - x - } else { - return None; - }; - - self.opt - } -} - -#[derive(Clone)] -pub struct MoveStruct { - pub opt: Option>, -} - -impl MoveStruct { - pub fn ref_func(&self) -> Option> { - if self.opt.is_none() { - return None; - } - - self.opt.clone() - } - - pub fn mov_func_reuse(self) -> Option> { - if self.opt.is_none() { - return None; - } - - self.opt - } - - pub fn mov_func_no_use(self) -> Option> { - if self.opt.is_none() { - return None; - } - Some(Vec::new()) - } - - pub fn if_let_ref_func(self) -> Option> { - let v: &Vec<_> = if let Some(ref v) = self.opt { - v - } else { - return None; - }; - - Some(v.clone()) - } - - pub fn if_let_mov_func(self) -> Option> { - let v = if let Some(v) = self.opt { - v - } else { - return None; - }; - - Some(v) - } -} - -fn func() -> Option { - fn f() -> Option { - Some(String::new()) - } - - if f().is_none() { - return None; - } - - Some(0) -} - -fn main() { - some_func(Some(42)); - some_func(None); - some_other_func(Some(42)); - - let copy_struct = CopyStruct { opt: Some(54) }; - copy_struct.func(); - - let move_struct = MoveStruct { - opt: Some(vec![42, 1337]), - }; - move_struct.ref_func(); - move_struct.clone().mov_func_reuse(); - move_struct.mov_func_no_use(); - - let so = SeemsOption::Some(45); - returns_something_similar_to_option(so); - - func(); -} diff --git a/tests/ui/question_mark.stderr b/tests/ui/question_mark.stderr deleted file mode 100644 index 6f330cfa385d..000000000000 --- a/tests/ui/question_mark.stderr +++ /dev/null @@ -1,104 +0,0 @@ -error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:6:5 - | -LL | / if a.is_none() { -LL | | return None; -LL | | } - | |_____^ help: replace it with: `a?;` - | - = note: `-D clippy::question-mark` implied by `-D warnings` - -error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:51:9 - | -LL | / if (self.opt).is_none() { -LL | | return None; -LL | | } - | |_________^ help: replace it with: `(self.opt)?;` - -error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:55:9 - | -LL | / if self.opt.is_none() { -LL | | return None -LL | | } - | |_________^ help: replace it with: `self.opt?;` - -error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:59:17 - | -LL | let _ = if self.opt.is_none() { - | _________________^ -LL | | return None; -LL | | } else { -LL | | self.opt -LL | | }; - | |_________^ help: replace it with: `Some(self.opt?)` - -error: this if-let-else may be rewritten with the `?` operator - --> $DIR/question_mark.rs:65:17 - | -LL | let _ = if let Some(x) = self.opt { - | _________________^ -LL | | x -LL | | } else { -LL | | return None; -LL | | }; - | |_________^ help: replace it with: `self.opt?` - -error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:82:9 - | -LL | / if self.opt.is_none() { -LL | | return None; -LL | | } - | |_________^ help: replace it with: `self.opt.as_ref()?;` - -error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:90:9 - | -LL | / if self.opt.is_none() { -LL | | return None; -LL | | } - | |_________^ help: replace it with: `self.opt.as_ref()?;` - -error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:98:9 - | -LL | / if self.opt.is_none() { -LL | | return None; -LL | | } - | |_________^ help: replace it with: `self.opt.as_ref()?;` - -error: this if-let-else may be rewritten with the `?` operator - --> $DIR/question_mark.rs:105:26 - | -LL | let v: &Vec<_> = if let Some(ref v) = self.opt { - | __________________________^ -LL | | v -LL | | } else { -LL | | return None; -LL | | }; - | |_________^ help: replace it with: `self.opt.as_ref()?` - -error: this if-let-else may be rewritten with the `?` operator - --> $DIR/question_mark.rs:115:17 - | -LL | let v = if let Some(v) = self.opt { - | _________________^ -LL | | v -LL | | } else { -LL | | return None; -LL | | }; - | |_________^ help: replace it with: `self.opt?` - -error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:130:5 - | -LL | / if f().is_none() { -LL | | return None; -LL | | } - | |_____^ help: replace it with: `f()?;` - -error: aborting due to 11 previous errors - diff --git a/tests/ui/range.rs b/tests/ui/range.rs deleted file mode 100644 index 628282509c1a..000000000000 --- a/tests/ui/range.rs +++ /dev/null @@ -1,16 +0,0 @@ -#[warn(clippy::range_zip_with_len)] -fn main() { - let v1 = vec![1, 2, 3]; - let v2 = vec![4, 5]; - let _x = v1.iter().zip(0..v1.len()); - let _y = v1.iter().zip(0..v2.len()); // No error -} - -#[allow(unused)] -fn no_panic_with_fake_range_types() { - struct Range { - foo: i32, - } - - let _ = Range { foo: 0 }; -} diff --git a/tests/ui/range.stderr b/tests/ui/range.stderr deleted file mode 100644 index dcb5061371f8..000000000000 --- a/tests/ui/range.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: it is more idiomatic to use `v1.iter().enumerate()` - --> $DIR/range.rs:5:14 - | -LL | let _x = v1.iter().zip(0..v1.len()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::range-zip-with-len` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/range_contains.fixed b/tests/ui/range_contains.fixed deleted file mode 100644 index 47c974e614b9..000000000000 --- a/tests/ui/range_contains.fixed +++ /dev/null @@ -1,51 +0,0 @@ -// run-rustfix - -#[warn(clippy::manual_range_contains)] -#[allow(unused)] -#[allow(clippy::no_effect)] -#[allow(clippy::short_circuit_statement)] -#[allow(clippy::unnecessary_operation)] -fn main() { - let x = 9_u32; - - // order shouldn't matter - (8..12).contains(&x); - (21..42).contains(&x); - (1..100).contains(&x); - - // also with inclusive ranges - (9..=99).contains(&x); - (1..=33).contains(&x); - (1..=999).contains(&x); - - // and the outside - !(8..12).contains(&x); - !(21..42).contains(&x); - !(1..100).contains(&x); - - // also with the outside of inclusive ranges - !(9..=99).contains(&x); - !(1..=33).contains(&x); - !(1..=999).contains(&x); - - // not a range.contains - x > 8 && x < 12; // lower bound not inclusive - x < 8 && x <= 12; // same direction - x >= 12 && 12 >= x; // same bounds - x < 8 && x > 12; // wrong direction - - x <= 8 || x >= 12; - x >= 8 || x >= 12; - x < 12 || 12 < x; - x >= 8 || x <= 12; - - // Fix #6315 - let y = 3.; - (0. ..1.).contains(&y); - !(0. ..=1.).contains(&y); -} - -// Fix #6373 -pub const fn in_range(a: i32) -> bool { - 3 <= a && a <= 20 -} diff --git a/tests/ui/range_contains.rs b/tests/ui/range_contains.rs deleted file mode 100644 index 835deced5e4c..000000000000 --- a/tests/ui/range_contains.rs +++ /dev/null @@ -1,51 +0,0 @@ -// run-rustfix - -#[warn(clippy::manual_range_contains)] -#[allow(unused)] -#[allow(clippy::no_effect)] -#[allow(clippy::short_circuit_statement)] -#[allow(clippy::unnecessary_operation)] -fn main() { - let x = 9_u32; - - // order shouldn't matter - x >= 8 && x < 12; - x < 42 && x >= 21; - 100 > x && 1 <= x; - - // also with inclusive ranges - x >= 9 && x <= 99; - x <= 33 && x >= 1; - 999 >= x && 1 <= x; - - // and the outside - x < 8 || x >= 12; - x >= 42 || x < 21; - 100 <= x || 1 > x; - - // also with the outside of inclusive ranges - x < 9 || x > 99; - x > 33 || x < 1; - 999 < x || 1 > x; - - // not a range.contains - x > 8 && x < 12; // lower bound not inclusive - x < 8 && x <= 12; // same direction - x >= 12 && 12 >= x; // same bounds - x < 8 && x > 12; // wrong direction - - x <= 8 || x >= 12; - x >= 8 || x >= 12; - x < 12 || 12 < x; - x >= 8 || x <= 12; - - // Fix #6315 - let y = 3.; - y >= 0. && y < 1.; - y < 0. || y > 1.; -} - -// Fix #6373 -pub const fn in_range(a: i32) -> bool { - 3 <= a && a <= 20 -} diff --git a/tests/ui/range_contains.stderr b/tests/ui/range_contains.stderr deleted file mode 100644 index bc79f1bca846..000000000000 --- a/tests/ui/range_contains.stderr +++ /dev/null @@ -1,88 +0,0 @@ -error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:12:5 - | -LL | x >= 8 && x < 12; - | ^^^^^^^^^^^^^^^^ help: use: `(8..12).contains(&x)` - | - = note: `-D clippy::manual-range-contains` implied by `-D warnings` - -error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:13:5 - | -LL | x < 42 && x >= 21; - | ^^^^^^^^^^^^^^^^^ help: use: `(21..42).contains(&x)` - -error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:14:5 - | -LL | 100 > x && 1 <= x; - | ^^^^^^^^^^^^^^^^^ help: use: `(1..100).contains(&x)` - -error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:17:5 - | -LL | x >= 9 && x <= 99; - | ^^^^^^^^^^^^^^^^^ help: use: `(9..=99).contains(&x)` - -error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:18:5 - | -LL | x <= 33 && x >= 1; - | ^^^^^^^^^^^^^^^^^ help: use: `(1..=33).contains(&x)` - -error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:19:5 - | -LL | 999 >= x && 1 <= x; - | ^^^^^^^^^^^^^^^^^^ help: use: `(1..=999).contains(&x)` - -error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:22:5 - | -LL | x < 8 || x >= 12; - | ^^^^^^^^^^^^^^^^ help: use: `!(8..12).contains(&x)` - -error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:23:5 - | -LL | x >= 42 || x < 21; - | ^^^^^^^^^^^^^^^^^ help: use: `!(21..42).contains(&x)` - -error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:24:5 - | -LL | 100 <= x || 1 > x; - | ^^^^^^^^^^^^^^^^^ help: use: `!(1..100).contains(&x)` - -error: manual `!RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:27:5 - | -LL | x < 9 || x > 99; - | ^^^^^^^^^^^^^^^ help: use: `!(9..=99).contains(&x)` - -error: manual `!RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:28:5 - | -LL | x > 33 || x < 1; - | ^^^^^^^^^^^^^^^ help: use: `!(1..=33).contains(&x)` - -error: manual `!RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:29:5 - | -LL | 999 < x || 1 > x; - | ^^^^^^^^^^^^^^^^ help: use: `!(1..=999).contains(&x)` - -error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:44:5 - | -LL | y >= 0. && y < 1.; - | ^^^^^^^^^^^^^^^^^ help: use: `(0. ..1.).contains(&y)` - -error: manual `!RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:45:5 - | -LL | y < 0. || y > 1.; - | ^^^^^^^^^^^^^^^^ help: use: `!(0. ..=1.).contains(&y)` - -error: aborting due to 14 previous errors - diff --git a/tests/ui/range_plus_minus_one.fixed b/tests/ui/range_plus_minus_one.fixed deleted file mode 100644 index 19b253b0fe2c..000000000000 --- a/tests/ui/range_plus_minus_one.fixed +++ /dev/null @@ -1,42 +0,0 @@ -// run-rustfix - -#![allow(unused_parens)] - -fn f() -> usize { - 42 -} - -#[warn(clippy::range_plus_one)] -#[warn(clippy::range_minus_one)] -fn main() { - for _ in 0..2 {} - for _ in 0..=2 {} - - for _ in 0..=3 {} - for _ in 0..=3 + 1 {} - - for _ in 0..=5 {} - for _ in 0..=1 + 5 {} - - for _ in 1..=1 {} - for _ in 1..=1 + 1 {} - - for _ in 0..13 + 13 {} - for _ in 0..=13 - 7 {} - - for _ in 0..=f() {} - for _ in 0..=(1 + f()) {} - - let _ = ..11 - 1; - let _ = ..11; - let _ = ..11; - let _ = (1..=11); - let _ = ((f() + 1)..=f()); - - const ONE: usize = 1; - // integer consts are linted, too - for _ in 1..=ONE {} - - let mut vec: Vec<()> = std::vec::Vec::new(); - vec.drain(..); -} diff --git a/tests/ui/range_plus_minus_one.rs b/tests/ui/range_plus_minus_one.rs deleted file mode 100644 index 7d034117547c..000000000000 --- a/tests/ui/range_plus_minus_one.rs +++ /dev/null @@ -1,42 +0,0 @@ -// run-rustfix - -#![allow(unused_parens)] - -fn f() -> usize { - 42 -} - -#[warn(clippy::range_plus_one)] -#[warn(clippy::range_minus_one)] -fn main() { - for _ in 0..2 {} - for _ in 0..=2 {} - - for _ in 0..3 + 1 {} - for _ in 0..=3 + 1 {} - - for _ in 0..1 + 5 {} - for _ in 0..=1 + 5 {} - - for _ in 1..1 + 1 {} - for _ in 1..=1 + 1 {} - - for _ in 0..13 + 13 {} - for _ in 0..=13 - 7 {} - - for _ in 0..(1 + f()) {} - for _ in 0..=(1 + f()) {} - - let _ = ..11 - 1; - let _ = ..=11 - 1; - let _ = ..=(11 - 1); - let _ = (1..11 + 1); - let _ = (f() + 1)..(f() + 1); - - const ONE: usize = 1; - // integer consts are linted, too - for _ in 1..ONE + ONE {} - - let mut vec: Vec<()> = std::vec::Vec::new(); - vec.drain(..); -} diff --git a/tests/ui/range_plus_minus_one.stderr b/tests/ui/range_plus_minus_one.stderr deleted file mode 100644 index fb4f1658597a..000000000000 --- a/tests/ui/range_plus_minus_one.stderr +++ /dev/null @@ -1,60 +0,0 @@ -error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:15:14 - | -LL | for _ in 0..3 + 1 {} - | ^^^^^^^^ help: use: `0..=3` - | - = note: `-D clippy::range-plus-one` implied by `-D warnings` - -error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:18:14 - | -LL | for _ in 0..1 + 5 {} - | ^^^^^^^^ help: use: `0..=5` - -error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:21:14 - | -LL | for _ in 1..1 + 1 {} - | ^^^^^^^^ help: use: `1..=1` - -error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:27:14 - | -LL | for _ in 0..(1 + f()) {} - | ^^^^^^^^^^^^ help: use: `0..=f()` - -error: an exclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:31:13 - | -LL | let _ = ..=11 - 1; - | ^^^^^^^^^ help: use: `..11` - | - = note: `-D clippy::range-minus-one` implied by `-D warnings` - -error: an exclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:32:13 - | -LL | let _ = ..=(11 - 1); - | ^^^^^^^^^^^ help: use: `..11` - -error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:33:13 - | -LL | let _ = (1..11 + 1); - | ^^^^^^^^^^^ help: use: `(1..=11)` - -error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:34:13 - | -LL | let _ = (f() + 1)..(f() + 1); - | ^^^^^^^^^^^^^^^^^^^^ help: use: `((f() + 1)..=f())` - -error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:38:14 - | -LL | for _ in 1..ONE + ONE {} - | ^^^^^^^^^^^^ help: use: `1..=ONE` - -error: aborting due to 9 previous errors - diff --git a/tests/ui/rc_buffer.rs b/tests/ui/rc_buffer.rs deleted file mode 100644 index 1fa986439368..000000000000 --- a/tests/ui/rc_buffer.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![warn(clippy::rc_buffer)] - -use std::cell::RefCell; -use std::ffi::OsString; -use std::path::PathBuf; -use std::rc::Rc; - -struct S { - // triggers lint - bad1: Rc, - bad2: Rc, - bad3: Rc>, - bad4: Rc, - // does not trigger lint - good1: Rc>, -} - -// triggers lint -fn func_bad1(_: Rc) {} -fn func_bad2(_: Rc) {} -fn func_bad3(_: Rc>) {} -fn func_bad4(_: Rc) {} -// does not trigger lint -fn func_good1(_: Rc>) {} - -fn main() {} diff --git a/tests/ui/rc_buffer.stderr b/tests/ui/rc_buffer.stderr deleted file mode 100644 index e4cc169af07b..000000000000 --- a/tests/ui/rc_buffer.stderr +++ /dev/null @@ -1,52 +0,0 @@ -error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:10:11 - | -LL | bad1: Rc, - | ^^^^^^^^^^ help: try: `Rc` - | - = note: `-D clippy::rc-buffer` implied by `-D warnings` - -error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:11:11 - | -LL | bad2: Rc, - | ^^^^^^^^^^^ help: try: `Rc` - -error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:12:11 - | -LL | bad3: Rc>, - | ^^^^^^^^^^^ help: try: `Rc<[u8]>` - -error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:13:11 - | -LL | bad4: Rc, - | ^^^^^^^^^^^^ help: try: `Rc` - -error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:19:17 - | -LL | fn func_bad1(_: Rc) {} - | ^^^^^^^^^^ help: try: `Rc` - -error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:20:17 - | -LL | fn func_bad2(_: Rc) {} - | ^^^^^^^^^^^ help: try: `Rc` - -error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:21:17 - | -LL | fn func_bad3(_: Rc>) {} - | ^^^^^^^^^^^ help: try: `Rc<[u8]>` - -error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:22:17 - | -LL | fn func_bad4(_: Rc) {} - | ^^^^^^^^^^^^ help: try: `Rc` - -error: aborting due to 8 previous errors - diff --git a/tests/ui/rc_buffer_arc.rs b/tests/ui/rc_buffer_arc.rs deleted file mode 100644 index 5d586584817b..000000000000 --- a/tests/ui/rc_buffer_arc.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![warn(clippy::rc_buffer)] - -use std::ffi::OsString; -use std::path::PathBuf; -use std::sync::{Arc, Mutex}; - -struct S { - // triggers lint - bad1: Arc, - bad2: Arc, - bad3: Arc>, - bad4: Arc, - // does not trigger lint - good1: Arc>, -} - -// triggers lint -fn func_bad1(_: Arc) {} -fn func_bad2(_: Arc) {} -fn func_bad3(_: Arc>) {} -fn func_bad4(_: Arc) {} -// does not trigger lint -fn func_good1(_: Arc>) {} - -fn main() {} diff --git a/tests/ui/rc_buffer_arc.stderr b/tests/ui/rc_buffer_arc.stderr deleted file mode 100644 index 8252270d2ac7..000000000000 --- a/tests/ui/rc_buffer_arc.stderr +++ /dev/null @@ -1,52 +0,0 @@ -error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:9:11 - | -LL | bad1: Arc, - | ^^^^^^^^^^^ help: try: `Arc` - | - = note: `-D clippy::rc-buffer` implied by `-D warnings` - -error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:10:11 - | -LL | bad2: Arc, - | ^^^^^^^^^^^^ help: try: `Arc` - -error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:11:11 - | -LL | bad3: Arc>, - | ^^^^^^^^^^^^ help: try: `Arc<[u8]>` - -error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:12:11 - | -LL | bad4: Arc, - | ^^^^^^^^^^^^^ help: try: `Arc` - -error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:18:17 - | -LL | fn func_bad1(_: Arc) {} - | ^^^^^^^^^^^ help: try: `Arc` - -error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:19:17 - | -LL | fn func_bad2(_: Arc) {} - | ^^^^^^^^^^^^ help: try: `Arc` - -error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:20:17 - | -LL | fn func_bad3(_: Arc>) {} - | ^^^^^^^^^^^^ help: try: `Arc<[u8]>` - -error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:21:17 - | -LL | fn func_bad4(_: Arc) {} - | ^^^^^^^^^^^^^ help: try: `Arc` - -error: aborting due to 8 previous errors - diff --git a/tests/ui/rc_buffer_redefined_string.rs b/tests/ui/rc_buffer_redefined_string.rs deleted file mode 100644 index 5d31a848cf72..000000000000 --- a/tests/ui/rc_buffer_redefined_string.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![warn(clippy::rc_buffer)] - -use std::rc::Rc; - -struct String; - -struct S { - // does not trigger lint - good1: Rc, -} - -fn main() {} diff --git a/tests/ui/rc_buffer_redefined_string.stderr b/tests/ui/rc_buffer_redefined_string.stderr deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/tests/ui/redundant_allocation.fixed b/tests/ui/redundant_allocation.fixed deleted file mode 100644 index 6514fd6d1ac7..000000000000 --- a/tests/ui/redundant_allocation.fixed +++ /dev/null @@ -1,48 +0,0 @@ -// run-rustfix -#![warn(clippy::all)] -#![allow(clippy::boxed_local, clippy::needless_pass_by_value)] -#![allow(clippy::blacklisted_name, unused_variables, dead_code)] - -use std::boxed::Box; -use std::rc::Rc; - -pub struct MyStruct {} - -pub struct SubT { - foo: T, -} - -pub enum MyEnum { - One, - Two, -} - -// Rc<&T> - -pub fn test1(foo: &T) {} - -pub fn test2(foo: &MyStruct) {} - -pub fn test3(foo: &MyEnum) {} - -pub fn test4_neg(foo: Rc>) {} - -// Rc> - -pub fn test5(a: Rc) {} - -// Rc> - -pub fn test6(a: Rc) {} - -// Box<&T> - -pub fn test7(foo: &T) {} - -pub fn test8(foo: &MyStruct) {} - -pub fn test9(foo: &MyEnum) {} - -pub fn test10_neg(foo: Box>) {} - -fn main() {} diff --git a/tests/ui/redundant_allocation.rs b/tests/ui/redundant_allocation.rs deleted file mode 100644 index 677b3e56d4dc..000000000000 --- a/tests/ui/redundant_allocation.rs +++ /dev/null @@ -1,48 +0,0 @@ -// run-rustfix -#![warn(clippy::all)] -#![allow(clippy::boxed_local, clippy::needless_pass_by_value)] -#![allow(clippy::blacklisted_name, unused_variables, dead_code)] - -use std::boxed::Box; -use std::rc::Rc; - -pub struct MyStruct {} - -pub struct SubT { - foo: T, -} - -pub enum MyEnum { - One, - Two, -} - -// Rc<&T> - -pub fn test1(foo: Rc<&T>) {} - -pub fn test2(foo: Rc<&MyStruct>) {} - -pub fn test3(foo: Rc<&MyEnum>) {} - -pub fn test4_neg(foo: Rc>) {} - -// Rc> - -pub fn test5(a: Rc>) {} - -// Rc> - -pub fn test6(a: Rc>) {} - -// Box<&T> - -pub fn test7(foo: Box<&T>) {} - -pub fn test8(foo: Box<&MyStruct>) {} - -pub fn test9(foo: Box<&MyEnum>) {} - -pub fn test10_neg(foo: Box>) {} - -fn main() {} diff --git a/tests/ui/redundant_allocation.stderr b/tests/ui/redundant_allocation.stderr deleted file mode 100644 index 92e4f67f5db6..000000000000 --- a/tests/ui/redundant_allocation.stderr +++ /dev/null @@ -1,52 +0,0 @@ -error: usage of `Rc<&T>` - --> $DIR/redundant_allocation.rs:22:22 - | -LL | pub fn test1(foo: Rc<&T>) {} - | ^^^^^^ help: try: `&T` - | - = note: `-D clippy::redundant-allocation` implied by `-D warnings` - -error: usage of `Rc<&T>` - --> $DIR/redundant_allocation.rs:24:19 - | -LL | pub fn test2(foo: Rc<&MyStruct>) {} - | ^^^^^^^^^^^^^ help: try: `&MyStruct` - -error: usage of `Rc<&T>` - --> $DIR/redundant_allocation.rs:26:19 - | -LL | pub fn test3(foo: Rc<&MyEnum>) {} - | ^^^^^^^^^^^ help: try: `&MyEnum` - -error: usage of `Rc>` - --> $DIR/redundant_allocation.rs:32:17 - | -LL | pub fn test5(a: Rc>) {} - | ^^^^^^^^^^^^ help: try: `Rc` - -error: usage of `Rc>` - --> $DIR/redundant_allocation.rs:36:17 - | -LL | pub fn test6(a: Rc>) {} - | ^^^^^^^^^^^^^ help: try: `Rc` - -error: usage of `Box<&T>` - --> $DIR/redundant_allocation.rs:40:22 - | -LL | pub fn test7(foo: Box<&T>) {} - | ^^^^^^^ help: try: `&T` - -error: usage of `Box<&T>` - --> $DIR/redundant_allocation.rs:42:19 - | -LL | pub fn test8(foo: Box<&MyStruct>) {} - | ^^^^^^^^^^^^^^ help: try: `&MyStruct` - -error: usage of `Box<&T>` - --> $DIR/redundant_allocation.rs:44:19 - | -LL | pub fn test9(foo: Box<&MyEnum>) {} - | ^^^^^^^^^^^^ help: try: `&MyEnum` - -error: aborting due to 8 previous errors - diff --git a/tests/ui/redundant_clone.fixed b/tests/ui/redundant_clone.fixed deleted file mode 100644 index cdeefda4c234..000000000000 --- a/tests/ui/redundant_clone.fixed +++ /dev/null @@ -1,187 +0,0 @@ -// run-rustfix -// rustfix-only-machine-applicable - -use std::ffi::OsString; -use std::path::Path; - -fn main() { - let _s = ["lorem", "ipsum"].join(" "); - - let s = String::from("foo"); - let _s = s; - - let s = String::from("foo"); - let _s = s; - - let s = String::from("foo"); - let _s = s; - - let _s = Path::new("/a/b/").join("c"); - - let _s = Path::new("/a/b/").join("c"); - - let _s = OsString::new(); - - let _s = OsString::new(); - - // Check that lint level works - #[allow(clippy::redundant_clone)] - let _s = String::new().to_string(); - - let tup = (String::from("foo"),); - let _t = tup.0; - - let tup_ref = &(String::from("foo"),); - let _s = tup_ref.0.clone(); // this `.clone()` cannot be removed - - { - let x = String::new(); - let y = &x; - - let _x = x.clone(); // ok; `x` is borrowed by `y` - - let _ = y.len(); - } - - let x = (String::new(),); - let _ = Some(String::new()).unwrap_or_else(|| x.0.clone()); // ok; closure borrows `x` - - with_branch(Alpha, true); - cannot_double_move(Alpha); - cannot_move_from_type_with_drop(); - borrower_propagation(); - not_consumed(); - issue_5405(); - manually_drop(); -} - -#[derive(Clone)] -struct Alpha; -fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) { - if b { - (a.clone(), a) - } else { - (Alpha, a) - } -} - -fn cannot_double_move(a: Alpha) -> (Alpha, Alpha) { - (a.clone(), a) -} - -struct TypeWithDrop { - x: String, -} - -impl Drop for TypeWithDrop { - fn drop(&mut self) {} -} - -fn cannot_move_from_type_with_drop() -> String { - let s = TypeWithDrop { x: String::new() }; - s.x.clone() // removing this `clone()` summons E0509 -} - -fn borrower_propagation() { - let s = String::new(); - let t = String::new(); - - { - fn b() -> bool { - unimplemented!() - } - let _u = if b() { &s } else { &t }; - - // ok; `s` and `t` are possibly borrowed - let _s = s.clone(); - let _t = t.clone(); - } - - { - let _u = || s.len(); - let _v = [&t; 32]; - let _s = s.clone(); // ok - let _t = t.clone(); // ok - } - - { - let _u = { - let u = Some(&s); - let _ = s.clone(); // ok - u - }; - let _s = s.clone(); // ok - } - - { - use std::convert::identity as id; - let _u = id(id(&s)); - let _s = s.clone(); // ok, `u` borrows `s` - } - - let _s = s; - let _t = t; - - #[derive(Clone)] - struct Foo { - x: usize, - } - - { - let f = Foo { x: 123 }; - let _x = Some(f.x); - let _f = f; - } - - { - let f = Foo { x: 123 }; - let _x = &f.x; - let _f = f.clone(); // ok - } -} - -fn not_consumed() { - let x = std::path::PathBuf::from("home"); - let y = x.join("matthias"); - // join() creates a new owned PathBuf, does not take a &mut to x variable, thus the .clone() is - // redundant. (It also does not consume the PathBuf) - - println!("x: {:?}, y: {:?}", x, y); - - let mut s = String::new(); - s.clone().push_str("foo"); // OK, removing this `clone()` will change the behavior. - s.push_str("bar"); - assert_eq!(s, "bar"); - - let t = Some(s); - // OK - if let Some(x) = t.clone() { - println!("{}", x); - } - if let Some(x) = t { - println!("{}", x); - } -} - -#[allow(clippy::clone_on_copy)] -fn issue_5405() { - let a: [String; 1] = [String::from("foo")]; - let _b: String = a[0].clone(); - - let c: [usize; 2] = [2, 3]; - let _d: usize = c[1].clone(); -} - -fn manually_drop() { - use std::mem::ManuallyDrop; - use std::sync::Arc; - - let a = ManuallyDrop::new(Arc::new("Hello!".to_owned())); - let _ = a.clone(); // OK - - let p: *const String = Arc::into_raw(ManuallyDrop::into_inner(a)); - unsafe { - Arc::from_raw(p); - Arc::from_raw(p); - } -} diff --git a/tests/ui/redundant_clone.rs b/tests/ui/redundant_clone.rs deleted file mode 100644 index acb7ffb305f2..000000000000 --- a/tests/ui/redundant_clone.rs +++ /dev/null @@ -1,187 +0,0 @@ -// run-rustfix -// rustfix-only-machine-applicable - -use std::ffi::OsString; -use std::path::Path; - -fn main() { - let _s = ["lorem", "ipsum"].join(" ").to_string(); - - let s = String::from("foo"); - let _s = s.clone(); - - let s = String::from("foo"); - let _s = s.to_string(); - - let s = String::from("foo"); - let _s = s.to_owned(); - - let _s = Path::new("/a/b/").join("c").to_owned(); - - let _s = Path::new("/a/b/").join("c").to_path_buf(); - - let _s = OsString::new().to_owned(); - - let _s = OsString::new().to_os_string(); - - // Check that lint level works - #[allow(clippy::redundant_clone)] - let _s = String::new().to_string(); - - let tup = (String::from("foo"),); - let _t = tup.0.clone(); - - let tup_ref = &(String::from("foo"),); - let _s = tup_ref.0.clone(); // this `.clone()` cannot be removed - - { - let x = String::new(); - let y = &x; - - let _x = x.clone(); // ok; `x` is borrowed by `y` - - let _ = y.len(); - } - - let x = (String::new(),); - let _ = Some(String::new()).unwrap_or_else(|| x.0.clone()); // ok; closure borrows `x` - - with_branch(Alpha, true); - cannot_double_move(Alpha); - cannot_move_from_type_with_drop(); - borrower_propagation(); - not_consumed(); - issue_5405(); - manually_drop(); -} - -#[derive(Clone)] -struct Alpha; -fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) { - if b { - (a.clone(), a.clone()) - } else { - (Alpha, a) - } -} - -fn cannot_double_move(a: Alpha) -> (Alpha, Alpha) { - (a.clone(), a) -} - -struct TypeWithDrop { - x: String, -} - -impl Drop for TypeWithDrop { - fn drop(&mut self) {} -} - -fn cannot_move_from_type_with_drop() -> String { - let s = TypeWithDrop { x: String::new() }; - s.x.clone() // removing this `clone()` summons E0509 -} - -fn borrower_propagation() { - let s = String::new(); - let t = String::new(); - - { - fn b() -> bool { - unimplemented!() - } - let _u = if b() { &s } else { &t }; - - // ok; `s` and `t` are possibly borrowed - let _s = s.clone(); - let _t = t.clone(); - } - - { - let _u = || s.len(); - let _v = [&t; 32]; - let _s = s.clone(); // ok - let _t = t.clone(); // ok - } - - { - let _u = { - let u = Some(&s); - let _ = s.clone(); // ok - u - }; - let _s = s.clone(); // ok - } - - { - use std::convert::identity as id; - let _u = id(id(&s)); - let _s = s.clone(); // ok, `u` borrows `s` - } - - let _s = s.clone(); - let _t = t.clone(); - - #[derive(Clone)] - struct Foo { - x: usize, - } - - { - let f = Foo { x: 123 }; - let _x = Some(f.x); - let _f = f.clone(); - } - - { - let f = Foo { x: 123 }; - let _x = &f.x; - let _f = f.clone(); // ok - } -} - -fn not_consumed() { - let x = std::path::PathBuf::from("home"); - let y = x.clone().join("matthias"); - // join() creates a new owned PathBuf, does not take a &mut to x variable, thus the .clone() is - // redundant. (It also does not consume the PathBuf) - - println!("x: {:?}, y: {:?}", x, y); - - let mut s = String::new(); - s.clone().push_str("foo"); // OK, removing this `clone()` will change the behavior. - s.push_str("bar"); - assert_eq!(s, "bar"); - - let t = Some(s); - // OK - if let Some(x) = t.clone() { - println!("{}", x); - } - if let Some(x) = t { - println!("{}", x); - } -} - -#[allow(clippy::clone_on_copy)] -fn issue_5405() { - let a: [String; 1] = [String::from("foo")]; - let _b: String = a[0].clone(); - - let c: [usize; 2] = [2, 3]; - let _d: usize = c[1].clone(); -} - -fn manually_drop() { - use std::mem::ManuallyDrop; - use std::sync::Arc; - - let a = ManuallyDrop::new(Arc::new("Hello!".to_owned())); - let _ = a.clone(); // OK - - let p: *const String = Arc::into_raw(ManuallyDrop::into_inner(a)); - unsafe { - Arc::from_raw(p); - Arc::from_raw(p); - } -} diff --git a/tests/ui/redundant_clone.stderr b/tests/ui/redundant_clone.stderr deleted file mode 100644 index 89b392542991..000000000000 --- a/tests/ui/redundant_clone.stderr +++ /dev/null @@ -1,171 +0,0 @@ -error: redundant clone - --> $DIR/redundant_clone.rs:8:42 - | -LL | let _s = ["lorem", "ipsum"].join(" ").to_string(); - | ^^^^^^^^^^^^ help: remove this - | - = note: `-D clippy::redundant-clone` implied by `-D warnings` -note: this value is dropped without further use - --> $DIR/redundant_clone.rs:8:14 - | -LL | let _s = ["lorem", "ipsum"].join(" ").to_string(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: redundant clone - --> $DIR/redundant_clone.rs:11:15 - | -LL | let _s = s.clone(); - | ^^^^^^^^ help: remove this - | -note: this value is dropped without further use - --> $DIR/redundant_clone.rs:11:14 - | -LL | let _s = s.clone(); - | ^ - -error: redundant clone - --> $DIR/redundant_clone.rs:14:15 - | -LL | let _s = s.to_string(); - | ^^^^^^^^^^^^ help: remove this - | -note: this value is dropped without further use - --> $DIR/redundant_clone.rs:14:14 - | -LL | let _s = s.to_string(); - | ^ - -error: redundant clone - --> $DIR/redundant_clone.rs:17:15 - | -LL | let _s = s.to_owned(); - | ^^^^^^^^^^^ help: remove this - | -note: this value is dropped without further use - --> $DIR/redundant_clone.rs:17:14 - | -LL | let _s = s.to_owned(); - | ^ - -error: redundant clone - --> $DIR/redundant_clone.rs:19:42 - | -LL | let _s = Path::new("/a/b/").join("c").to_owned(); - | ^^^^^^^^^^^ help: remove this - | -note: this value is dropped without further use - --> $DIR/redundant_clone.rs:19:14 - | -LL | let _s = Path::new("/a/b/").join("c").to_owned(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: redundant clone - --> $DIR/redundant_clone.rs:21:42 - | -LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); - | ^^^^^^^^^^^^^^ help: remove this - | -note: this value is dropped without further use - --> $DIR/redundant_clone.rs:21:14 - | -LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: redundant clone - --> $DIR/redundant_clone.rs:23:29 - | -LL | let _s = OsString::new().to_owned(); - | ^^^^^^^^^^^ help: remove this - | -note: this value is dropped without further use - --> $DIR/redundant_clone.rs:23:14 - | -LL | let _s = OsString::new().to_owned(); - | ^^^^^^^^^^^^^^^ - -error: redundant clone - --> $DIR/redundant_clone.rs:25:29 - | -LL | let _s = OsString::new().to_os_string(); - | ^^^^^^^^^^^^^^^ help: remove this - | -note: this value is dropped without further use - --> $DIR/redundant_clone.rs:25:14 - | -LL | let _s = OsString::new().to_os_string(); - | ^^^^^^^^^^^^^^^ - -error: redundant clone - --> $DIR/redundant_clone.rs:32:19 - | -LL | let _t = tup.0.clone(); - | ^^^^^^^^ help: remove this - | -note: this value is dropped without further use - --> $DIR/redundant_clone.rs:32:14 - | -LL | let _t = tup.0.clone(); - | ^^^^^ - -error: redundant clone - --> $DIR/redundant_clone.rs:62:22 - | -LL | (a.clone(), a.clone()) - | ^^^^^^^^ help: remove this - | -note: this value is dropped without further use - --> $DIR/redundant_clone.rs:62:21 - | -LL | (a.clone(), a.clone()) - | ^ - -error: redundant clone - --> $DIR/redundant_clone.rs:122:15 - | -LL | let _s = s.clone(); - | ^^^^^^^^ help: remove this - | -note: this value is dropped without further use - --> $DIR/redundant_clone.rs:122:14 - | -LL | let _s = s.clone(); - | ^ - -error: redundant clone - --> $DIR/redundant_clone.rs:123:15 - | -LL | let _t = t.clone(); - | ^^^^^^^^ help: remove this - | -note: this value is dropped without further use - --> $DIR/redundant_clone.rs:123:14 - | -LL | let _t = t.clone(); - | ^ - -error: redundant clone - --> $DIR/redundant_clone.rs:133:19 - | -LL | let _f = f.clone(); - | ^^^^^^^^ help: remove this - | -note: this value is dropped without further use - --> $DIR/redundant_clone.rs:133:18 - | -LL | let _f = f.clone(); - | ^ - -error: redundant clone - --> $DIR/redundant_clone.rs:145:14 - | -LL | let y = x.clone().join("matthias"); - | ^^^^^^^^ help: remove this - | -note: cloned value is neither consumed nor mutated - --> $DIR/redundant_clone.rs:145:13 - | -LL | let y = x.clone().join("matthias"); - | ^^^^^^^^^ - -error: aborting due to 14 previous errors - diff --git a/tests/ui/redundant_closure_call_early.rs b/tests/ui/redundant_closure_call_early.rs deleted file mode 100644 index 3dd365620ccb..000000000000 --- a/tests/ui/redundant_closure_call_early.rs +++ /dev/null @@ -1,19 +0,0 @@ -// non rustfixable, see redundant_closure_call_fixable.rs - -#![warn(clippy::redundant_closure_call)] - -fn main() { - let mut i = 1; - - // lint here - let mut k = (|m| m + 1)(i); - - // lint here - k = (|a, b| a * b)(1, 5); - - // don't lint these - #[allow(clippy::needless_return)] - (|| return 2)(); - (|| -> Option { None? })(); - (|| -> Result { Err(2)? })(); -} diff --git a/tests/ui/redundant_closure_call_early.stderr b/tests/ui/redundant_closure_call_early.stderr deleted file mode 100644 index 2735e41738f0..000000000000 --- a/tests/ui/redundant_closure_call_early.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_early.rs:9:17 - | -LL | let mut k = (|m| m + 1)(i); - | ^^^^^^^^^^^^^^ - | - = note: `-D clippy::redundant-closure-call` implied by `-D warnings` - -error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_early.rs:12:9 - | -LL | k = (|a, b| a * b)(1, 5); - | ^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/redundant_closure_call_fixable.fixed b/tests/ui/redundant_closure_call_fixable.fixed deleted file mode 100644 index 0abca6fca061..000000000000 --- a/tests/ui/redundant_closure_call_fixable.fixed +++ /dev/null @@ -1,8 +0,0 @@ -// run-rustfix - -#![warn(clippy::redundant_closure_call)] -#![allow(unused)] - -fn main() { - let a = 42; -} diff --git a/tests/ui/redundant_closure_call_fixable.rs b/tests/ui/redundant_closure_call_fixable.rs deleted file mode 100644 index f8b9d37a5cc4..000000000000 --- a/tests/ui/redundant_closure_call_fixable.rs +++ /dev/null @@ -1,8 +0,0 @@ -// run-rustfix - -#![warn(clippy::redundant_closure_call)] -#![allow(unused)] - -fn main() { - let a = (|| 42)(); -} diff --git a/tests/ui/redundant_closure_call_fixable.stderr b/tests/ui/redundant_closure_call_fixable.stderr deleted file mode 100644 index afd704ef12a9..000000000000 --- a/tests/ui/redundant_closure_call_fixable.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:7:13 - | -LL | let a = (|| 42)(); - | ^^^^^^^^^ help: try doing something like: `42` - | - = note: `-D clippy::redundant-closure-call` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/redundant_closure_call_late.rs b/tests/ui/redundant_closure_call_late.rs deleted file mode 100644 index 1f4864b72895..000000000000 --- a/tests/ui/redundant_closure_call_late.rs +++ /dev/null @@ -1,39 +0,0 @@ -// non rustfixable, see redundant_closure_call_fixable.rs - -#![warn(clippy::redundant_closure_call)] - -fn main() { - let mut i = 1; - - // don't lint here, the closure is used more than once - let closure = |i| i + 1; - i = closure(3); - i = closure(4); - - // lint here - let redun_closure = || 1; - i = redun_closure(); - - // shadowed closures are supported, lint here - let shadowed_closure = || 1; - i = shadowed_closure(); - let shadowed_closure = || 2; - i = shadowed_closure(); - - // don't lint here - let shadowed_closure = || 2; - i = shadowed_closure(); - i = shadowed_closure(); - - // Fix FP in #5916 - let mut x; - let create = || 2 * 2; - x = create(); - fun(move || { - x = create(); - }) -} - -fn fun(mut f: T) { - f(); -} diff --git a/tests/ui/redundant_closure_call_late.stderr b/tests/ui/redundant_closure_call_late.stderr deleted file mode 100644 index 7c8865f1bd37..000000000000 --- a/tests/ui/redundant_closure_call_late.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: closure called just once immediately after it was declared - --> $DIR/redundant_closure_call_late.rs:15:5 - | -LL | i = redun_closure(); - | ^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::redundant-closure-call` implied by `-D warnings` - -error: closure called just once immediately after it was declared - --> $DIR/redundant_closure_call_late.rs:19:5 - | -LL | i = shadowed_closure(); - | ^^^^^^^^^^^^^^^^^^^^^^ - -error: closure called just once immediately after it was declared - --> $DIR/redundant_closure_call_late.rs:21:5 - | -LL | i = shadowed_closure(); - | ^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/redundant_else.rs b/tests/ui/redundant_else.rs deleted file mode 100644 index 737c8a9f8db4..000000000000 --- a/tests/ui/redundant_else.rs +++ /dev/null @@ -1,154 +0,0 @@ -#![warn(clippy::redundant_else)] -#![allow(clippy::needless_return)] - -fn main() { - loop { - // break - if foo() { - println!("Love your neighbor;"); - break; - } else { - println!("yet don't pull down your hedge."); - } - // continue - if foo() { - println!("He that lies down with Dogs,"); - continue; - } else { - println!("shall rise up with fleas."); - } - // match block - if foo() { - match foo() { - 1 => break, - _ => return, - } - } else { - println!("You may delay, but time will not."); - } - } - // else if - if foo() { - return; - } else if foo() { - return; - } else { - println!("A fat kitchen makes a lean will."); - } - // let binding outside of block - let _ = { - if foo() { - return; - } else { - 1 - } - }; - // else if with let binding outside of block - let _ = { - if foo() { - return; - } else if foo() { - return; - } else { - 2 - } - }; - // inside if let - let _ = if let Some(1) = foo() { - let _ = 1; - if foo() { - return; - } else { - 1 - } - } else { - 1 - }; - - // - // non-lint cases - // - - // sanity check - if foo() { - let _ = 1; - } else { - println!("Who is wise? He that learns from every one."); - } - // else if without else - if foo() { - return; - } else if foo() { - foo() - }; - // nested if return - if foo() { - if foo() { - return; - } - } else { - foo() - }; - // match with non-breaking branch - if foo() { - match foo() { - 1 => foo(), - _ => return, - } - } else { - println!("Three may keep a secret, if two of them are dead."); - } - // let binding - let _ = if foo() { - return; - } else { - 1 - }; - // assign - let a; - a = if foo() { - return; - } else { - 1 - }; - // assign-op - a += if foo() { - return; - } else { - 1 - }; - // if return else if else - if foo() { - return; - } else if foo() { - 1 - } else { - 2 - }; - // if else if return else - if foo() { - 1 - } else if foo() { - return; - } else { - 2 - }; - // else if with let binding - let _ = if foo() { - return; - } else if foo() { - return; - } else { - 2 - }; - // inside function call - Box::new(if foo() { - return; - } else { - 1 - }); -} - -fn foo() -> T { - unimplemented!("I'm not Santa Claus") -} diff --git a/tests/ui/redundant_else.stderr b/tests/ui/redundant_else.stderr deleted file mode 100644 index 9000cdc814b1..000000000000 --- a/tests/ui/redundant_else.stderr +++ /dev/null @@ -1,80 +0,0 @@ -error: redundant else block - --> $DIR/redundant_else.rs:10:16 - | -LL | } else { - | ________________^ -LL | | println!("yet don't pull down your hedge."); -LL | | } - | |_________^ - | - = note: `-D clippy::redundant-else` implied by `-D warnings` - = help: remove the `else` block and move the contents out - -error: redundant else block - --> $DIR/redundant_else.rs:17:16 - | -LL | } else { - | ________________^ -LL | | println!("shall rise up with fleas."); -LL | | } - | |_________^ - | - = help: remove the `else` block and move the contents out - -error: redundant else block - --> $DIR/redundant_else.rs:26:16 - | -LL | } else { - | ________________^ -LL | | println!("You may delay, but time will not."); -LL | | } - | |_________^ - | - = help: remove the `else` block and move the contents out - -error: redundant else block - --> $DIR/redundant_else.rs:35:12 - | -LL | } else { - | ____________^ -LL | | println!("A fat kitchen makes a lean will."); -LL | | } - | |_____^ - | - = help: remove the `else` block and move the contents out - -error: redundant else block - --> $DIR/redundant_else.rs:42:16 - | -LL | } else { - | ________________^ -LL | | 1 -LL | | } - | |_________^ - | - = help: remove the `else` block and move the contents out - -error: redundant else block - --> $DIR/redundant_else.rs:52:16 - | -LL | } else { - | ________________^ -LL | | 2 -LL | | } - | |_________^ - | - = help: remove the `else` block and move the contents out - -error: redundant else block - --> $DIR/redundant_else.rs:61:16 - | -LL | } else { - | ________________^ -LL | | 1 -LL | | } - | |_________^ - | - = help: remove the `else` block and move the contents out - -error: aborting due to 7 previous errors - diff --git a/tests/ui/redundant_field_names.fixed b/tests/ui/redundant_field_names.fixed deleted file mode 100644 index 5b4b8eeedd46..000000000000 --- a/tests/ui/redundant_field_names.fixed +++ /dev/null @@ -1,71 +0,0 @@ -// run-rustfix -#![warn(clippy::redundant_field_names)] -#![allow(clippy::no_effect, dead_code, unused_variables)] - -#[macro_use] -extern crate derive_new; - -use std::ops::{Range, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive}; - -mod foo { - pub const BAR: u8 = 0; -} - -struct Person { - gender: u8, - age: u8, - name: u8, - buzz: u64, - foo: u8, -} - -#[derive(new)] -pub struct S { - v: String, -} - -fn main() { - let gender: u8 = 42; - let age = 0; - let fizz: u64 = 0; - let name: u8 = 0; - - let me = Person { - gender, - age, - - name, //should be ok - buzz: fizz, //should be ok - foo: foo::BAR, //should be ok - }; - - // Range expressions - let (start, end) = (0, 0); - - let _ = start..; - let _ = ..end; - let _ = start..end; - - let _ = ..=end; - let _ = start..=end; - - // Issue #2799 - let _: Vec<_> = (start..end).collect(); - - // hand-written Range family structs are linted - let _ = RangeFrom { start }; - let _ = RangeTo { end }; - let _ = Range { start, end }; - let _ = RangeInclusive::new(start, end); - let _ = RangeToInclusive { end }; -} - -fn issue_3476() { - fn foo() {} - - struct S { - foo: fn(), - } - - S { foo: foo:: }; -} diff --git a/tests/ui/redundant_field_names.rs b/tests/ui/redundant_field_names.rs deleted file mode 100644 index 3f97b80c5682..000000000000 --- a/tests/ui/redundant_field_names.rs +++ /dev/null @@ -1,71 +0,0 @@ -// run-rustfix -#![warn(clippy::redundant_field_names)] -#![allow(clippy::no_effect, dead_code, unused_variables)] - -#[macro_use] -extern crate derive_new; - -use std::ops::{Range, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive}; - -mod foo { - pub const BAR: u8 = 0; -} - -struct Person { - gender: u8, - age: u8, - name: u8, - buzz: u64, - foo: u8, -} - -#[derive(new)] -pub struct S { - v: String, -} - -fn main() { - let gender: u8 = 42; - let age = 0; - let fizz: u64 = 0; - let name: u8 = 0; - - let me = Person { - gender: gender, - age: age, - - name, //should be ok - buzz: fizz, //should be ok - foo: foo::BAR, //should be ok - }; - - // Range expressions - let (start, end) = (0, 0); - - let _ = start..; - let _ = ..end; - let _ = start..end; - - let _ = ..=end; - let _ = start..=end; - - // Issue #2799 - let _: Vec<_> = (start..end).collect(); - - // hand-written Range family structs are linted - let _ = RangeFrom { start: start }; - let _ = RangeTo { end: end }; - let _ = Range { start: start, end: end }; - let _ = RangeInclusive::new(start, end); - let _ = RangeToInclusive { end: end }; -} - -fn issue_3476() { - fn foo() {} - - struct S { - foo: fn(), - } - - S { foo: foo:: }; -} diff --git a/tests/ui/redundant_field_names.stderr b/tests/ui/redundant_field_names.stderr deleted file mode 100644 index 7976292df224..000000000000 --- a/tests/ui/redundant_field_names.stderr +++ /dev/null @@ -1,46 +0,0 @@ -error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:34:9 - | -LL | gender: gender, - | ^^^^^^^^^^^^^^ help: replace it with: `gender` - | - = note: `-D clippy::redundant-field-names` implied by `-D warnings` - -error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:35:9 - | -LL | age: age, - | ^^^^^^^^ help: replace it with: `age` - -error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:56:25 - | -LL | let _ = RangeFrom { start: start }; - | ^^^^^^^^^^^^ help: replace it with: `start` - -error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:57:23 - | -LL | let _ = RangeTo { end: end }; - | ^^^^^^^^ help: replace it with: `end` - -error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:58:21 - | -LL | let _ = Range { start: start, end: end }; - | ^^^^^^^^^^^^ help: replace it with: `start` - -error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:58:35 - | -LL | let _ = Range { start: start, end: end }; - | ^^^^^^^^ help: replace it with: `end` - -error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:60:32 - | -LL | let _ = RangeToInclusive { end: end }; - | ^^^^^^^^ help: replace it with: `end` - -error: aborting due to 7 previous errors - diff --git a/tests/ui/redundant_pattern_matching_ipaddr.fixed b/tests/ui/redundant_pattern_matching_ipaddr.fixed deleted file mode 100644 index acc8de5f41ee..000000000000 --- a/tests/ui/redundant_pattern_matching_ipaddr.fixed +++ /dev/null @@ -1,73 +0,0 @@ -// run-rustfix - -#![warn(clippy::all)] -#![warn(clippy::redundant_pattern_matching)] -#![allow(unused_must_use, clippy::needless_bool, clippy::match_like_matches_macro)] - -use std::net::{ - IpAddr::{self, V4, V6}, - Ipv4Addr, Ipv6Addr, -}; - -fn main() { - let ipaddr: IpAddr = V4(Ipv4Addr::LOCALHOST); - if ipaddr.is_ipv4() {} - - if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} - - if V6(Ipv6Addr::LOCALHOST).is_ipv6() {} - - while V4(Ipv4Addr::LOCALHOST).is_ipv4() {} - - while V6(Ipv6Addr::LOCALHOST).is_ipv6() {} - - if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} - - if V6(Ipv6Addr::LOCALHOST).is_ipv6() {} - - if let V4(ipaddr) = V4(Ipv4Addr::LOCALHOST) { - println!("{}", ipaddr); - } - - V4(Ipv4Addr::LOCALHOST).is_ipv4(); - - V4(Ipv4Addr::LOCALHOST).is_ipv6(); - - V6(Ipv6Addr::LOCALHOST).is_ipv6(); - - V6(Ipv6Addr::LOCALHOST).is_ipv4(); - - let _ = if V4(Ipv4Addr::LOCALHOST).is_ipv4() { - true - } else { - false - }; - - ipaddr_const(); - - let _ = if gen_ipaddr().is_ipv4() { - 1 - } else if gen_ipaddr().is_ipv6() { - 2 - } else { - 3 - }; -} - -fn gen_ipaddr() -> IpAddr { - V4(Ipv4Addr::LOCALHOST) -} - -const fn ipaddr_const() { - if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} - - if V6(Ipv6Addr::LOCALHOST).is_ipv6() {} - - while V4(Ipv4Addr::LOCALHOST).is_ipv4() {} - - while V6(Ipv6Addr::LOCALHOST).is_ipv6() {} - - V4(Ipv4Addr::LOCALHOST).is_ipv4(); - - V6(Ipv6Addr::LOCALHOST).is_ipv6(); -} diff --git a/tests/ui/redundant_pattern_matching_ipaddr.rs b/tests/ui/redundant_pattern_matching_ipaddr.rs deleted file mode 100644 index 678d91ce93ac..000000000000 --- a/tests/ui/redundant_pattern_matching_ipaddr.rs +++ /dev/null @@ -1,91 +0,0 @@ -// run-rustfix - -#![warn(clippy::all)] -#![warn(clippy::redundant_pattern_matching)] -#![allow(unused_must_use, clippy::needless_bool, clippy::match_like_matches_macro)] - -use std::net::{ - IpAddr::{self, V4, V6}, - Ipv4Addr, Ipv6Addr, -}; - -fn main() { - let ipaddr: IpAddr = V4(Ipv4Addr::LOCALHOST); - if let V4(_) = &ipaddr {} - - if let V4(_) = V4(Ipv4Addr::LOCALHOST) {} - - if let V6(_) = V6(Ipv6Addr::LOCALHOST) {} - - while let V4(_) = V4(Ipv4Addr::LOCALHOST) {} - - while let V6(_) = V6(Ipv6Addr::LOCALHOST) {} - - if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} - - if V6(Ipv6Addr::LOCALHOST).is_ipv6() {} - - if let V4(ipaddr) = V4(Ipv4Addr::LOCALHOST) { - println!("{}", ipaddr); - } - - match V4(Ipv4Addr::LOCALHOST) { - V4(_) => true, - V6(_) => false, - }; - - match V4(Ipv4Addr::LOCALHOST) { - V4(_) => false, - V6(_) => true, - }; - - match V6(Ipv6Addr::LOCALHOST) { - V4(_) => false, - V6(_) => true, - }; - - match V6(Ipv6Addr::LOCALHOST) { - V4(_) => true, - V6(_) => false, - }; - - let _ = if let V4(_) = V4(Ipv4Addr::LOCALHOST) { - true - } else { - false - }; - - ipaddr_const(); - - let _ = if let V4(_) = gen_ipaddr() { - 1 - } else if let V6(_) = gen_ipaddr() { - 2 - } else { - 3 - }; -} - -fn gen_ipaddr() -> IpAddr { - V4(Ipv4Addr::LOCALHOST) -} - -const fn ipaddr_const() { - if let V4(_) = V4(Ipv4Addr::LOCALHOST) {} - - if let V6(_) = V6(Ipv6Addr::LOCALHOST) {} - - while let V4(_) = V4(Ipv4Addr::LOCALHOST) {} - - while let V6(_) = V6(Ipv6Addr::LOCALHOST) {} - - match V4(Ipv4Addr::LOCALHOST) { - V4(_) => true, - V6(_) => false, - }; - - match V6(Ipv6Addr::LOCALHOST) { - V4(_) => false, - V6(_) => true, - }; -} diff --git a/tests/ui/redundant_pattern_matching_ipaddr.stderr b/tests/ui/redundant_pattern_matching_ipaddr.stderr deleted file mode 100644 index caf458cd862e..000000000000 --- a/tests/ui/redundant_pattern_matching_ipaddr.stderr +++ /dev/null @@ -1,130 +0,0 @@ -error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:14:12 - | -LL | if let V4(_) = &ipaddr {} - | -------^^^^^---------- help: try this: `if ipaddr.is_ipv4()` - | - = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` - -error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:16:12 - | -LL | if let V4(_) = V4(Ipv4Addr::LOCALHOST) {} - | -------^^^^^-------------------------- help: try this: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()` - -error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:18:12 - | -LL | if let V6(_) = V6(Ipv6Addr::LOCALHOST) {} - | -------^^^^^-------------------------- help: try this: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()` - -error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:20:15 - | -LL | while let V4(_) = V4(Ipv4Addr::LOCALHOST) {} - | ----------^^^^^-------------------------- help: try this: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()` - -error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:22:15 - | -LL | while let V6(_) = V6(Ipv6Addr::LOCALHOST) {} - | ----------^^^^^-------------------------- help: try this: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()` - -error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:32:5 - | -LL | / match V4(Ipv4Addr::LOCALHOST) { -LL | | V4(_) => true, -LL | | V6(_) => false, -LL | | }; - | |_____^ help: try this: `V4(Ipv4Addr::LOCALHOST).is_ipv4()` - -error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:37:5 - | -LL | / match V4(Ipv4Addr::LOCALHOST) { -LL | | V4(_) => false, -LL | | V6(_) => true, -LL | | }; - | |_____^ help: try this: `V4(Ipv4Addr::LOCALHOST).is_ipv6()` - -error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:42:5 - | -LL | / match V6(Ipv6Addr::LOCALHOST) { -LL | | V4(_) => false, -LL | | V6(_) => true, -LL | | }; - | |_____^ help: try this: `V6(Ipv6Addr::LOCALHOST).is_ipv6()` - -error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:47:5 - | -LL | / match V6(Ipv6Addr::LOCALHOST) { -LL | | V4(_) => true, -LL | | V6(_) => false, -LL | | }; - | |_____^ help: try this: `V6(Ipv6Addr::LOCALHOST).is_ipv4()` - -error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:52:20 - | -LL | let _ = if let V4(_) = V4(Ipv4Addr::LOCALHOST) { - | -------^^^^^-------------------------- help: try this: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()` - -error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:60:20 - | -LL | let _ = if let V4(_) = gen_ipaddr() { - | -------^^^^^--------------- help: try this: `if gen_ipaddr().is_ipv4()` - -error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:62:19 - | -LL | } else if let V6(_) = gen_ipaddr() { - | -------^^^^^--------------- help: try this: `if gen_ipaddr().is_ipv6()` - -error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:74:12 - | -LL | if let V4(_) = V4(Ipv4Addr::LOCALHOST) {} - | -------^^^^^-------------------------- help: try this: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()` - -error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:76:12 - | -LL | if let V6(_) = V6(Ipv6Addr::LOCALHOST) {} - | -------^^^^^-------------------------- help: try this: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()` - -error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:78:15 - | -LL | while let V4(_) = V4(Ipv4Addr::LOCALHOST) {} - | ----------^^^^^-------------------------- help: try this: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()` - -error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:80:15 - | -LL | while let V6(_) = V6(Ipv6Addr::LOCALHOST) {} - | ----------^^^^^-------------------------- help: try this: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()` - -error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:82:5 - | -LL | / match V4(Ipv4Addr::LOCALHOST) { -LL | | V4(_) => true, -LL | | V6(_) => false, -LL | | }; - | |_____^ help: try this: `V4(Ipv4Addr::LOCALHOST).is_ipv4()` - -error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:87:5 - | -LL | / match V6(Ipv6Addr::LOCALHOST) { -LL | | V4(_) => false, -LL | | V6(_) => true, -LL | | }; - | |_____^ help: try this: `V6(Ipv6Addr::LOCALHOST).is_ipv6()` - -error: aborting due to 18 previous errors - diff --git a/tests/ui/redundant_pattern_matching_option.fixed b/tests/ui/redundant_pattern_matching_option.fixed deleted file mode 100644 index 66f580a0a683..000000000000 --- a/tests/ui/redundant_pattern_matching_option.fixed +++ /dev/null @@ -1,76 +0,0 @@ -// run-rustfix - -#![warn(clippy::all)] -#![warn(clippy::redundant_pattern_matching)] -#![allow(unused_must_use, clippy::needless_bool, clippy::match_like_matches_macro)] - -fn main() { - if None::<()>.is_none() {} - - if Some(42).is_some() {} - - if Some(42).is_some() { - foo(); - } else { - bar(); - } - - while Some(42).is_some() {} - - while Some(42).is_none() {} - - while None::<()>.is_none() {} - - let mut v = vec![1, 2, 3]; - while v.pop().is_some() { - foo(); - } - - if None::.is_none() {} - - if Some(42).is_some() {} - - Some(42).is_some(); - - None::<()>.is_none(); - - let _ = None::<()>.is_none(); - - let opt = Some(false); - let _ = if opt.is_some() { true } else { false }; - - issue6067(); - - let _ = if gen_opt().is_some() { - 1 - } else if gen_opt().is_none() { - 2 - } else { - 3 - }; -} - -fn gen_opt() -> Option<()> { - None -} - -fn foo() {} - -fn bar() {} - -// Methods that are unstable const should not be suggested within a const context, see issue #5697. -// However, in Rust 1.48.0 the methods `is_some` and `is_none` of `Option` were stabilized as const, -// so the following should be linted. -const fn issue6067() { - if Some(42).is_some() {} - - if None::<()>.is_none() {} - - while Some(42).is_some() {} - - while None::<()>.is_none() {} - - Some(42).is_some(); - - None::<()>.is_none(); -} diff --git a/tests/ui/redundant_pattern_matching_option.rs b/tests/ui/redundant_pattern_matching_option.rs deleted file mode 100644 index f18b27b8b95c..000000000000 --- a/tests/ui/redundant_pattern_matching_option.rs +++ /dev/null @@ -1,91 +0,0 @@ -// run-rustfix - -#![warn(clippy::all)] -#![warn(clippy::redundant_pattern_matching)] -#![allow(unused_must_use, clippy::needless_bool, clippy::match_like_matches_macro)] - -fn main() { - if let None = None::<()> {} - - if let Some(_) = Some(42) {} - - if let Some(_) = Some(42) { - foo(); - } else { - bar(); - } - - while let Some(_) = Some(42) {} - - while let None = Some(42) {} - - while let None = None::<()> {} - - let mut v = vec![1, 2, 3]; - while let Some(_) = v.pop() { - foo(); - } - - if None::.is_none() {} - - if Some(42).is_some() {} - - match Some(42) { - Some(_) => true, - None => false, - }; - - match None::<()> { - Some(_) => false, - None => true, - }; - - let _ = match None::<()> { - Some(_) => false, - None => true, - }; - - let opt = Some(false); - let _ = if let Some(_) = opt { true } else { false }; - - issue6067(); - - let _ = if let Some(_) = gen_opt() { - 1 - } else if let None = gen_opt() { - 2 - } else { - 3 - }; -} - -fn gen_opt() -> Option<()> { - None -} - -fn foo() {} - -fn bar() {} - -// Methods that are unstable const should not be suggested within a const context, see issue #5697. -// However, in Rust 1.48.0 the methods `is_some` and `is_none` of `Option` were stabilized as const, -// so the following should be linted. -const fn issue6067() { - if let Some(_) = Some(42) {} - - if let None = None::<()> {} - - while let Some(_) = Some(42) {} - - while let None = None::<()> {} - - match Some(42) { - Some(_) => true, - None => false, - }; - - match None::<()> { - Some(_) => false, - None => true, - }; -} diff --git a/tests/ui/redundant_pattern_matching_option.stderr b/tests/ui/redundant_pattern_matching_option.stderr deleted file mode 100644 index 58482a0ab70d..000000000000 --- a/tests/ui/redundant_pattern_matching_option.stderr +++ /dev/null @@ -1,134 +0,0 @@ -error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:8:12 - | -LL | if let None = None::<()> {} - | -------^^^^------------- help: try this: `if None::<()>.is_none()` - | - = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` - -error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:10:12 - | -LL | if let Some(_) = Some(42) {} - | -------^^^^^^^----------- help: try this: `if Some(42).is_some()` - -error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:12:12 - | -LL | if let Some(_) = Some(42) { - | -------^^^^^^^----------- help: try this: `if Some(42).is_some()` - -error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:18:15 - | -LL | while let Some(_) = Some(42) {} - | ----------^^^^^^^----------- help: try this: `while Some(42).is_some()` - -error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:20:15 - | -LL | while let None = Some(42) {} - | ----------^^^^----------- help: try this: `while Some(42).is_none()` - -error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:22:15 - | -LL | while let None = None::<()> {} - | ----------^^^^------------- help: try this: `while None::<()>.is_none()` - -error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:25:15 - | -LL | while let Some(_) = v.pop() { - | ----------^^^^^^^---------- help: try this: `while v.pop().is_some()` - -error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:33:5 - | -LL | / match Some(42) { -LL | | Some(_) => true, -LL | | None => false, -LL | | }; - | |_____^ help: try this: `Some(42).is_some()` - -error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:38:5 - | -LL | / match None::<()> { -LL | | Some(_) => false, -LL | | None => true, -LL | | }; - | |_____^ help: try this: `None::<()>.is_none()` - -error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:43:13 - | -LL | let _ = match None::<()> { - | _____________^ -LL | | Some(_) => false, -LL | | None => true, -LL | | }; - | |_____^ help: try this: `None::<()>.is_none()` - -error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:49:20 - | -LL | let _ = if let Some(_) = opt { true } else { false }; - | -------^^^^^^^------ help: try this: `if opt.is_some()` - -error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:53:20 - | -LL | let _ = if let Some(_) = gen_opt() { - | -------^^^^^^^------------ help: try this: `if gen_opt().is_some()` - -error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:55:19 - | -LL | } else if let None = gen_opt() { - | -------^^^^------------ help: try this: `if gen_opt().is_none()` - -error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:74:12 - | -LL | if let Some(_) = Some(42) {} - | -------^^^^^^^----------- help: try this: `if Some(42).is_some()` - -error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:76:12 - | -LL | if let None = None::<()> {} - | -------^^^^------------- help: try this: `if None::<()>.is_none()` - -error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:78:15 - | -LL | while let Some(_) = Some(42) {} - | ----------^^^^^^^----------- help: try this: `while Some(42).is_some()` - -error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:80:15 - | -LL | while let None = None::<()> {} - | ----------^^^^------------- help: try this: `while None::<()>.is_none()` - -error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:82:5 - | -LL | / match Some(42) { -LL | | Some(_) => true, -LL | | None => false, -LL | | }; - | |_____^ help: try this: `Some(42).is_some()` - -error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:87:5 - | -LL | / match None::<()> { -LL | | Some(_) => false, -LL | | None => true, -LL | | }; - | |_____^ help: try this: `None::<()>.is_none()` - -error: aborting due to 19 previous errors - diff --git a/tests/ui/redundant_pattern_matching_poll.fixed b/tests/ui/redundant_pattern_matching_poll.fixed deleted file mode 100644 index 465aa80dac27..000000000000 --- a/tests/ui/redundant_pattern_matching_poll.fixed +++ /dev/null @@ -1,70 +0,0 @@ -// run-rustfix - -#![warn(clippy::all)] -#![warn(clippy::redundant_pattern_matching)] -#![allow(unused_must_use, clippy::needless_bool, clippy::match_like_matches_macro)] - -use std::task::Poll::{self, Pending, Ready}; - -fn main() { - if Pending::<()>.is_pending() {} - - if Ready(42).is_ready() {} - - if Ready(42).is_ready() { - foo(); - } else { - bar(); - } - - while Ready(42).is_ready() {} - - while Ready(42).is_pending() {} - - while Pending::<()>.is_pending() {} - - if Pending::.is_pending() {} - - if Ready(42).is_ready() {} - - Ready(42).is_ready(); - - Pending::<()>.is_pending(); - - let _ = Pending::<()>.is_pending(); - - let poll = Ready(false); - let _ = if poll.is_ready() { true } else { false }; - - poll_const(); - - let _ = if gen_poll().is_ready() { - 1 - } else if gen_poll().is_pending() { - 2 - } else { - 3 - }; -} - -fn gen_poll() -> Poll<()> { - Pending -} - -fn foo() {} - -fn bar() {} - -const fn poll_const() { - if Ready(42).is_ready() {} - - if Pending::<()>.is_pending() {} - - while Ready(42).is_ready() {} - - while Pending::<()>.is_pending() {} - - Ready(42).is_ready(); - - Pending::<()>.is_pending(); -} diff --git a/tests/ui/redundant_pattern_matching_poll.rs b/tests/ui/redundant_pattern_matching_poll.rs deleted file mode 100644 index 7891ff353b13..000000000000 --- a/tests/ui/redundant_pattern_matching_poll.rs +++ /dev/null @@ -1,85 +0,0 @@ -// run-rustfix - -#![warn(clippy::all)] -#![warn(clippy::redundant_pattern_matching)] -#![allow(unused_must_use, clippy::needless_bool, clippy::match_like_matches_macro)] - -use std::task::Poll::{self, Pending, Ready}; - -fn main() { - if let Pending = Pending::<()> {} - - if let Ready(_) = Ready(42) {} - - if let Ready(_) = Ready(42) { - foo(); - } else { - bar(); - } - - while let Ready(_) = Ready(42) {} - - while let Pending = Ready(42) {} - - while let Pending = Pending::<()> {} - - if Pending::.is_pending() {} - - if Ready(42).is_ready() {} - - match Ready(42) { - Ready(_) => true, - Pending => false, - }; - - match Pending::<()> { - Ready(_) => false, - Pending => true, - }; - - let _ = match Pending::<()> { - Ready(_) => false, - Pending => true, - }; - - let poll = Ready(false); - let _ = if let Ready(_) = poll { true } else { false }; - - poll_const(); - - let _ = if let Ready(_) = gen_poll() { - 1 - } else if let Pending = gen_poll() { - 2 - } else { - 3 - }; -} - -fn gen_poll() -> Poll<()> { - Pending -} - -fn foo() {} - -fn bar() {} - -const fn poll_const() { - if let Ready(_) = Ready(42) {} - - if let Pending = Pending::<()> {} - - while let Ready(_) = Ready(42) {} - - while let Pending = Pending::<()> {} - - match Ready(42) { - Ready(_) => true, - Pending => false, - }; - - match Pending::<()> { - Ready(_) => false, - Pending => true, - }; -} diff --git a/tests/ui/redundant_pattern_matching_poll.stderr b/tests/ui/redundant_pattern_matching_poll.stderr deleted file mode 100644 index 5ffc6c47c90a..000000000000 --- a/tests/ui/redundant_pattern_matching_poll.stderr +++ /dev/null @@ -1,128 +0,0 @@ -error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:10:12 - | -LL | if let Pending = Pending::<()> {} - | -------^^^^^^^---------------- help: try this: `if Pending::<()>.is_pending()` - | - = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` - -error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:12:12 - | -LL | if let Ready(_) = Ready(42) {} - | -------^^^^^^^^------------ help: try this: `if Ready(42).is_ready()` - -error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:14:12 - | -LL | if let Ready(_) = Ready(42) { - | -------^^^^^^^^------------ help: try this: `if Ready(42).is_ready()` - -error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:20:15 - | -LL | while let Ready(_) = Ready(42) {} - | ----------^^^^^^^^------------ help: try this: `while Ready(42).is_ready()` - -error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:22:15 - | -LL | while let Pending = Ready(42) {} - | ----------^^^^^^^------------ help: try this: `while Ready(42).is_pending()` - -error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:24:15 - | -LL | while let Pending = Pending::<()> {} - | ----------^^^^^^^---------------- help: try this: `while Pending::<()>.is_pending()` - -error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:30:5 - | -LL | / match Ready(42) { -LL | | Ready(_) => true, -LL | | Pending => false, -LL | | }; - | |_____^ help: try this: `Ready(42).is_ready()` - -error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:35:5 - | -LL | / match Pending::<()> { -LL | | Ready(_) => false, -LL | | Pending => true, -LL | | }; - | |_____^ help: try this: `Pending::<()>.is_pending()` - -error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:40:13 - | -LL | let _ = match Pending::<()> { - | _____________^ -LL | | Ready(_) => false, -LL | | Pending => true, -LL | | }; - | |_____^ help: try this: `Pending::<()>.is_pending()` - -error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:46:20 - | -LL | let _ = if let Ready(_) = poll { true } else { false }; - | -------^^^^^^^^------- help: try this: `if poll.is_ready()` - -error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:50:20 - | -LL | let _ = if let Ready(_) = gen_poll() { - | -------^^^^^^^^------------- help: try this: `if gen_poll().is_ready()` - -error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:52:19 - | -LL | } else if let Pending = gen_poll() { - | -------^^^^^^^------------- help: try this: `if gen_poll().is_pending()` - -error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:68:12 - | -LL | if let Ready(_) = Ready(42) {} - | -------^^^^^^^^------------ help: try this: `if Ready(42).is_ready()` - -error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:70:12 - | -LL | if let Pending = Pending::<()> {} - | -------^^^^^^^---------------- help: try this: `if Pending::<()>.is_pending()` - -error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:72:15 - | -LL | while let Ready(_) = Ready(42) {} - | ----------^^^^^^^^------------ help: try this: `while Ready(42).is_ready()` - -error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:74:15 - | -LL | while let Pending = Pending::<()> {} - | ----------^^^^^^^---------------- help: try this: `while Pending::<()>.is_pending()` - -error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:76:5 - | -LL | / match Ready(42) { -LL | | Ready(_) => true, -LL | | Pending => false, -LL | | }; - | |_____^ help: try this: `Ready(42).is_ready()` - -error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:81:5 - | -LL | / match Pending::<()> { -LL | | Ready(_) => false, -LL | | Pending => true, -LL | | }; - | |_____^ help: try this: `Pending::<()>.is_pending()` - -error: aborting due to 18 previous errors - diff --git a/tests/ui/redundant_pattern_matching_result.fixed b/tests/ui/redundant_pattern_matching_result.fixed deleted file mode 100644 index e94c5704b489..000000000000 --- a/tests/ui/redundant_pattern_matching_result.fixed +++ /dev/null @@ -1,109 +0,0 @@ -// run-rustfix - -#![warn(clippy::all)] -#![warn(clippy::redundant_pattern_matching)] -#![allow( - unused_must_use, - clippy::needless_bool, - clippy::match_like_matches_macro, - clippy::unnecessary_wraps, - deprecated -)] - -fn main() { - let result: Result = Err(5); - if result.is_ok() {} - - if Ok::(42).is_ok() {} - - if Err::(42).is_err() {} - - while Ok::(10).is_ok() {} - - while Ok::(10).is_err() {} - - if Ok::(42).is_ok() {} - - if Err::(42).is_err() {} - - if let Ok(x) = Ok::(42) { - println!("{}", x); - } - - Ok::(42).is_ok(); - - Ok::(42).is_err(); - - Err::(42).is_err(); - - Err::(42).is_ok(); - - let _ = if Ok::(4).is_ok() { true } else { false }; - - issue5504(); - issue6067(); - issue6065(); - - let _ = if gen_res().is_ok() { - 1 - } else if gen_res().is_err() { - 2 - } else { - 3 - }; -} - -fn gen_res() -> Result<(), ()> { - Ok(()) -} - -macro_rules! m { - () => { - Some(42u32) - }; -} - -fn issue5504() { - fn result_opt() -> Result, i32> { - Err(42) - } - - fn try_result_opt() -> Result { - while r#try!(result_opt()).is_some() {} - if r#try!(result_opt()).is_some() {} - Ok(42) - } - - try_result_opt(); - - if m!().is_some() {} - while m!().is_some() {} -} - -fn issue6065() { - macro_rules! if_let_in_macro { - ($pat:pat, $x:expr) => { - if let Some($pat) = $x {} - }; - } - - // shouldn't be linted - if_let_in_macro!(_, Some(42)); -} - -// Methods that are unstable const should not be suggested within a const context, see issue #5697. -// However, in Rust 1.48.0 the methods `is_ok` and `is_err` of `Result` were stabilized as const, -// so the following should be linted. -const fn issue6067() { - if Ok::(42).is_ok() {} - - if Err::(42).is_err() {} - - while Ok::(10).is_ok() {} - - while Ok::(10).is_err() {} - - Ok::(42).is_ok(); - - Err::(42).is_err(); -} diff --git a/tests/ui/redundant_pattern_matching_result.rs b/tests/ui/redundant_pattern_matching_result.rs deleted file mode 100644 index 5d1752942322..000000000000 --- a/tests/ui/redundant_pattern_matching_result.rs +++ /dev/null @@ -1,127 +0,0 @@ -// run-rustfix - -#![warn(clippy::all)] -#![warn(clippy::redundant_pattern_matching)] -#![allow( - unused_must_use, - clippy::needless_bool, - clippy::match_like_matches_macro, - clippy::unnecessary_wraps, - deprecated -)] - -fn main() { - let result: Result = Err(5); - if let Ok(_) = &result {} - - if let Ok(_) = Ok::(42) {} - - if let Err(_) = Err::(42) {} - - while let Ok(_) = Ok::(10) {} - - while let Err(_) = Ok::(10) {} - - if Ok::(42).is_ok() {} - - if Err::(42).is_err() {} - - if let Ok(x) = Ok::(42) { - println!("{}", x); - } - - match Ok::(42) { - Ok(_) => true, - Err(_) => false, - }; - - match Ok::(42) { - Ok(_) => false, - Err(_) => true, - }; - - match Err::(42) { - Ok(_) => false, - Err(_) => true, - }; - - match Err::(42) { - Ok(_) => true, - Err(_) => false, - }; - - let _ = if let Ok(_) = Ok::(4) { true } else { false }; - - issue5504(); - issue6067(); - issue6065(); - - let _ = if let Ok(_) = gen_res() { - 1 - } else if let Err(_) = gen_res() { - 2 - } else { - 3 - }; -} - -fn gen_res() -> Result<(), ()> { - Ok(()) -} - -macro_rules! m { - () => { - Some(42u32) - }; -} - -fn issue5504() { - fn result_opt() -> Result, i32> { - Err(42) - } - - fn try_result_opt() -> Result { - while let Some(_) = r#try!(result_opt()) {} - if let Some(_) = r#try!(result_opt()) {} - Ok(42) - } - - try_result_opt(); - - if let Some(_) = m!() {} - while let Some(_) = m!() {} -} - -fn issue6065() { - macro_rules! if_let_in_macro { - ($pat:pat, $x:expr) => { - if let Some($pat) = $x {} - }; - } - - // shouldn't be linted - if_let_in_macro!(_, Some(42)); -} - -// Methods that are unstable const should not be suggested within a const context, see issue #5697. -// However, in Rust 1.48.0 the methods `is_ok` and `is_err` of `Result` were stabilized as const, -// so the following should be linted. -const fn issue6067() { - if let Ok(_) = Ok::(42) {} - - if let Err(_) = Err::(42) {} - - while let Ok(_) = Ok::(10) {} - - while let Err(_) = Ok::(10) {} - - match Ok::(42) { - Ok(_) => true, - Err(_) => false, - }; - - match Err::(42) { - Ok(_) => false, - Err(_) => true, - }; -} diff --git a/tests/ui/redundant_pattern_matching_result.stderr b/tests/ui/redundant_pattern_matching_result.stderr deleted file mode 100644 index d6a46babb779..000000000000 --- a/tests/ui/redundant_pattern_matching_result.stderr +++ /dev/null @@ -1,154 +0,0 @@ -error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:15:12 - | -LL | if let Ok(_) = &result {} - | -------^^^^^---------- help: try this: `if result.is_ok()` - | - = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` - -error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:17:12 - | -LL | if let Ok(_) = Ok::(42) {} - | -------^^^^^--------------------- help: try this: `if Ok::(42).is_ok()` - -error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:19:12 - | -LL | if let Err(_) = Err::(42) {} - | -------^^^^^^---------------------- help: try this: `if Err::(42).is_err()` - -error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:21:15 - | -LL | while let Ok(_) = Ok::(10) {} - | ----------^^^^^--------------------- help: try this: `while Ok::(10).is_ok()` - -error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:23:15 - | -LL | while let Err(_) = Ok::(10) {} - | ----------^^^^^^--------------------- help: try this: `while Ok::(10).is_err()` - -error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:33:5 - | -LL | / match Ok::(42) { -LL | | Ok(_) => true, -LL | | Err(_) => false, -LL | | }; - | |_____^ help: try this: `Ok::(42).is_ok()` - -error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:38:5 - | -LL | / match Ok::(42) { -LL | | Ok(_) => false, -LL | | Err(_) => true, -LL | | }; - | |_____^ help: try this: `Ok::(42).is_err()` - -error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:43:5 - | -LL | / match Err::(42) { -LL | | Ok(_) => false, -LL | | Err(_) => true, -LL | | }; - | |_____^ help: try this: `Err::(42).is_err()` - -error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:48:5 - | -LL | / match Err::(42) { -LL | | Ok(_) => true, -LL | | Err(_) => false, -LL | | }; - | |_____^ help: try this: `Err::(42).is_ok()` - -error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:53:20 - | -LL | let _ = if let Ok(_) = Ok::(4) { true } else { false }; - | -------^^^^^--------------------- help: try this: `if Ok::(4).is_ok()` - -error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:59:20 - | -LL | let _ = if let Ok(_) = gen_res() { - | -------^^^^^------------ help: try this: `if gen_res().is_ok()` - -error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:61:19 - | -LL | } else if let Err(_) = gen_res() { - | -------^^^^^^------------ help: try this: `if gen_res().is_err()` - -error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_result.rs:84:19 - | -LL | while let Some(_) = r#try!(result_opt()) {} - | ----------^^^^^^^----------------------- help: try this: `while r#try!(result_opt()).is_some()` - -error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_result.rs:85:16 - | -LL | if let Some(_) = r#try!(result_opt()) {} - | -------^^^^^^^----------------------- help: try this: `if r#try!(result_opt()).is_some()` - -error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_result.rs:91:12 - | -LL | if let Some(_) = m!() {} - | -------^^^^^^^------- help: try this: `if m!().is_some()` - -error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_result.rs:92:15 - | -LL | while let Some(_) = m!() {} - | ----------^^^^^^^------- help: try this: `while m!().is_some()` - -error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:110:12 - | -LL | if let Ok(_) = Ok::(42) {} - | -------^^^^^--------------------- help: try this: `if Ok::(42).is_ok()` - -error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:112:12 - | -LL | if let Err(_) = Err::(42) {} - | -------^^^^^^---------------------- help: try this: `if Err::(42).is_err()` - -error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:114:15 - | -LL | while let Ok(_) = Ok::(10) {} - | ----------^^^^^--------------------- help: try this: `while Ok::(10).is_ok()` - -error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:116:15 - | -LL | while let Err(_) = Ok::(10) {} - | ----------^^^^^^--------------------- help: try this: `while Ok::(10).is_err()` - -error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:118:5 - | -LL | / match Ok::(42) { -LL | | Ok(_) => true, -LL | | Err(_) => false, -LL | | }; - | |_____^ help: try this: `Ok::(42).is_ok()` - -error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:123:5 - | -LL | / match Err::(42) { -LL | | Ok(_) => false, -LL | | Err(_) => true, -LL | | }; - | |_____^ help: try this: `Err::(42).is_err()` - -error: aborting due to 22 previous errors - diff --git a/tests/ui/redundant_pub_crate.fixed b/tests/ui/redundant_pub_crate.fixed deleted file mode 100644 index 25f2fd061b88..000000000000 --- a/tests/ui/redundant_pub_crate.fixed +++ /dev/null @@ -1,107 +0,0 @@ -// run-rustfix -#![allow(dead_code)] -#![warn(clippy::redundant_pub_crate)] - -mod m1 { - fn f() {} - pub fn g() {} // private due to m1 - pub fn h() {} - - mod m1_1 { - fn f() {} - pub fn g() {} // private due to m1_1 and m1 - pub fn h() {} - } - - pub mod m1_2 { - // ^ private due to m1 - fn f() {} - pub fn g() {} // private due to m1_2 and m1 - pub fn h() {} - } - - pub mod m1_3 { - fn f() {} - pub fn g() {} // private due to m1 - pub fn h() {} - } -} - -pub(crate) mod m2 { - fn f() {} - pub fn g() {} // already crate visible due to m2 - pub fn h() {} - - mod m2_1 { - fn f() {} - pub fn g() {} // private due to m2_1 - pub fn h() {} - } - - pub mod m2_2 { - // ^ already crate visible due to m2 - fn f() {} - pub fn g() {} // already crate visible due to m2_2 and m2 - pub fn h() {} - } - - pub mod m2_3 { - fn f() {} - pub fn g() {} // already crate visible due to m2 - pub fn h() {} - } -} - -pub mod m3 { - fn f() {} - pub(crate) fn g() {} // ok: m3 is exported - pub fn h() {} - - mod m3_1 { - fn f() {} - pub fn g() {} // private due to m3_1 - pub fn h() {} - } - - pub(crate) mod m3_2 { - // ^ ok - fn f() {} - pub fn g() {} // already crate visible due to m3_2 - pub fn h() {} - } - - pub mod m3_3 { - fn f() {} - pub(crate) fn g() {} // ok: m3 and m3_3 are exported - pub fn h() {} - } -} - -mod m4 { - fn f() {} - pub fn g() {} // private: not re-exported by `pub use m4::*` - pub fn h() {} - - mod m4_1 { - fn f() {} - pub fn g() {} // private due to m4_1 - pub fn h() {} - } - - pub mod m4_2 { - // ^ private: not re-exported by `pub use m4::*` - fn f() {} - pub fn g() {} // private due to m4_2 - pub fn h() {} - } - - pub mod m4_3 { - fn f() {} - pub(crate) fn g() {} // ok: m4_3 is re-exported by `pub use m4::*` - pub fn h() {} - } -} - -pub use m4::*; - -fn main() {} diff --git a/tests/ui/redundant_pub_crate.rs b/tests/ui/redundant_pub_crate.rs deleted file mode 100644 index 616286b4f39f..000000000000 --- a/tests/ui/redundant_pub_crate.rs +++ /dev/null @@ -1,107 +0,0 @@ -// run-rustfix -#![allow(dead_code)] -#![warn(clippy::redundant_pub_crate)] - -mod m1 { - fn f() {} - pub(crate) fn g() {} // private due to m1 - pub fn h() {} - - mod m1_1 { - fn f() {} - pub(crate) fn g() {} // private due to m1_1 and m1 - pub fn h() {} - } - - pub(crate) mod m1_2 { - // ^ private due to m1 - fn f() {} - pub(crate) fn g() {} // private due to m1_2 and m1 - pub fn h() {} - } - - pub mod m1_3 { - fn f() {} - pub(crate) fn g() {} // private due to m1 - pub fn h() {} - } -} - -pub(crate) mod m2 { - fn f() {} - pub(crate) fn g() {} // already crate visible due to m2 - pub fn h() {} - - mod m2_1 { - fn f() {} - pub(crate) fn g() {} // private due to m2_1 - pub fn h() {} - } - - pub(crate) mod m2_2 { - // ^ already crate visible due to m2 - fn f() {} - pub(crate) fn g() {} // already crate visible due to m2_2 and m2 - pub fn h() {} - } - - pub mod m2_3 { - fn f() {} - pub(crate) fn g() {} // already crate visible due to m2 - pub fn h() {} - } -} - -pub mod m3 { - fn f() {} - pub(crate) fn g() {} // ok: m3 is exported - pub fn h() {} - - mod m3_1 { - fn f() {} - pub(crate) fn g() {} // private due to m3_1 - pub fn h() {} - } - - pub(crate) mod m3_2 { - // ^ ok - fn f() {} - pub(crate) fn g() {} // already crate visible due to m3_2 - pub fn h() {} - } - - pub mod m3_3 { - fn f() {} - pub(crate) fn g() {} // ok: m3 and m3_3 are exported - pub fn h() {} - } -} - -mod m4 { - fn f() {} - pub(crate) fn g() {} // private: not re-exported by `pub use m4::*` - pub fn h() {} - - mod m4_1 { - fn f() {} - pub(crate) fn g() {} // private due to m4_1 - pub fn h() {} - } - - pub(crate) mod m4_2 { - // ^ private: not re-exported by `pub use m4::*` - fn f() {} - pub(crate) fn g() {} // private due to m4_2 - pub fn h() {} - } - - pub mod m4_3 { - fn f() {} - pub(crate) fn g() {} // ok: m4_3 is re-exported by `pub use m4::*` - pub fn h() {} - } -} - -pub use m4::*; - -fn main() {} diff --git a/tests/ui/redundant_pub_crate.stderr b/tests/ui/redundant_pub_crate.stderr deleted file mode 100644 index 6fccdaa4e203..000000000000 --- a/tests/ui/redundant_pub_crate.stderr +++ /dev/null @@ -1,132 +0,0 @@ -error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:7:5 - | -LL | pub(crate) fn g() {} // private due to m1 - | ----------^^^^^ - | | - | help: consider using: `pub` - | - = note: `-D clippy::redundant-pub-crate` implied by `-D warnings` - -error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:12:9 - | -LL | pub(crate) fn g() {} // private due to m1_1 and m1 - | ----------^^^^^ - | | - | help: consider using: `pub` - -error: pub(crate) module inside private module - --> $DIR/redundant_pub_crate.rs:16:5 - | -LL | pub(crate) mod m1_2 { - | ----------^^^^^^^^^ - | | - | help: consider using: `pub` - -error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:19:9 - | -LL | pub(crate) fn g() {} // private due to m1_2 and m1 - | ----------^^^^^ - | | - | help: consider using: `pub` - -error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:25:9 - | -LL | pub(crate) fn g() {} // private due to m1 - | ----------^^^^^ - | | - | help: consider using: `pub` - -error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:32:5 - | -LL | pub(crate) fn g() {} // already crate visible due to m2 - | ----------^^^^^ - | | - | help: consider using: `pub` - -error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:37:9 - | -LL | pub(crate) fn g() {} // private due to m2_1 - | ----------^^^^^ - | | - | help: consider using: `pub` - -error: pub(crate) module inside private module - --> $DIR/redundant_pub_crate.rs:41:5 - | -LL | pub(crate) mod m2_2 { - | ----------^^^^^^^^^ - | | - | help: consider using: `pub` - -error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:44:9 - | -LL | pub(crate) fn g() {} // already crate visible due to m2_2 and m2 - | ----------^^^^^ - | | - | help: consider using: `pub` - -error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:50:9 - | -LL | pub(crate) fn g() {} // already crate visible due to m2 - | ----------^^^^^ - | | - | help: consider using: `pub` - -error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:62:9 - | -LL | pub(crate) fn g() {} // private due to m3_1 - | ----------^^^^^ - | | - | help: consider using: `pub` - -error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:69:9 - | -LL | pub(crate) fn g() {} // already crate visible due to m3_2 - | ----------^^^^^ - | | - | help: consider using: `pub` - -error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:82:5 - | -LL | pub(crate) fn g() {} // private: not re-exported by `pub use m4::*` - | ----------^^^^^ - | | - | help: consider using: `pub` - -error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:87:9 - | -LL | pub(crate) fn g() {} // private due to m4_1 - | ----------^^^^^ - | | - | help: consider using: `pub` - -error: pub(crate) module inside private module - --> $DIR/redundant_pub_crate.rs:91:5 - | -LL | pub(crate) mod m4_2 { - | ----------^^^^^^^^^ - | | - | help: consider using: `pub` - -error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:94:9 - | -LL | pub(crate) fn g() {} // private due to m4_2 - | ----------^^^^^ - | | - | help: consider using: `pub` - -error: aborting due to 16 previous errors - diff --git a/tests/ui/redundant_static_lifetimes.fixed b/tests/ui/redundant_static_lifetimes.fixed deleted file mode 100644 index 921249606ad2..000000000000 --- a/tests/ui/redundant_static_lifetimes.fixed +++ /dev/null @@ -1,56 +0,0 @@ -// run-rustfix - -#![allow(unused)] - -#[derive(Debug)] -struct Foo {} - -const VAR_ONE: &str = "Test constant #1"; // ERROR Consider removing 'static. - -const VAR_TWO: &str = "Test constant #2"; // This line should not raise a warning. - -const VAR_THREE: &[&str] = &["one", "two"]; // ERROR Consider removing 'static - -const VAR_FOUR: (&str, (&str, &str), &str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static - -const VAR_SIX: &u8 = &5; - -const VAR_HEIGHT: &Foo = &Foo {}; - -const VAR_SLICE: &[u8] = b"Test constant #1"; // ERROR Consider removing 'static. - -const VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR Consider removing 'static. - -const VAR_ARRAY: &[u8; 1] = b"T"; // ERROR Consider removing 'static. - -static STATIC_VAR_ONE: &str = "Test static #1"; // ERROR Consider removing 'static. - -static STATIC_VAR_TWO: &str = "Test static #2"; // This line should not raise a warning. - -static STATIC_VAR_THREE: &[&str] = &["one", "two"]; // ERROR Consider removing 'static - -static STATIC_VAR_SIX: &u8 = &5; - -static STATIC_VAR_HEIGHT: &Foo = &Foo {}; - -static STATIC_VAR_SLICE: &[u8] = b"Test static #3"; // ERROR Consider removing 'static. - -static STATIC_VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR Consider removing 'static. - -static STATIC_VAR_ARRAY: &[u8; 1] = b"T"; // ERROR Consider removing 'static. - -fn main() { - let false_positive: &'static str = "test"; -} - -trait Bar { - const TRAIT_VAR: &'static str; -} - -impl Foo { - const IMPL_VAR: &'static str = "var"; -} - -impl Bar for Foo { - const TRAIT_VAR: &'static str = "foo"; -} diff --git a/tests/ui/redundant_static_lifetimes.rs b/tests/ui/redundant_static_lifetimes.rs deleted file mode 100644 index 4d4b249d076f..000000000000 --- a/tests/ui/redundant_static_lifetimes.rs +++ /dev/null @@ -1,56 +0,0 @@ -// run-rustfix - -#![allow(unused)] - -#[derive(Debug)] -struct Foo {} - -const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removing 'static. - -const VAR_TWO: &str = "Test constant #2"; // This line should not raise a warning. - -const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static - -const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static - -const VAR_SIX: &'static u8 = &5; - -const VAR_HEIGHT: &'static Foo = &Foo {}; - -const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR Consider removing 'static. - -const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static. - -const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static. - -static STATIC_VAR_ONE: &'static str = "Test static #1"; // ERROR Consider removing 'static. - -static STATIC_VAR_TWO: &str = "Test static #2"; // This line should not raise a warning. - -static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static - -static STATIC_VAR_SIX: &'static u8 = &5; - -static STATIC_VAR_HEIGHT: &'static Foo = &Foo {}; - -static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR Consider removing 'static. - -static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static. - -static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static. - -fn main() { - let false_positive: &'static str = "test"; -} - -trait Bar { - const TRAIT_VAR: &'static str; -} - -impl Foo { - const IMPL_VAR: &'static str = "var"; -} - -impl Bar for Foo { - const TRAIT_VAR: &'static str = "foo"; -} diff --git a/tests/ui/redundant_static_lifetimes.stderr b/tests/ui/redundant_static_lifetimes.stderr deleted file mode 100644 index 649831f9c069..000000000000 --- a/tests/ui/redundant_static_lifetimes.stderr +++ /dev/null @@ -1,100 +0,0 @@ -error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:8:17 - | -LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removing 'static. - | -^^^^^^^---- help: consider removing `'static`: `&str` - | - = note: `-D clippy::redundant-static-lifetimes` implied by `-D warnings` - -error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:12:21 - | -LL | const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static - | -^^^^^^^---- help: consider removing `'static`: `&str` - -error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:14:32 - | -LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static - | -^^^^^^^---- help: consider removing `'static`: `&str` - -error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:14:47 - | -LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static - | -^^^^^^^---- help: consider removing `'static`: `&str` - -error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:16:17 - | -LL | const VAR_SIX: &'static u8 = &5; - | -^^^^^^^--- help: consider removing `'static`: `&u8` - -error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:18:20 - | -LL | const VAR_HEIGHT: &'static Foo = &Foo {}; - | -^^^^^^^---- help: consider removing `'static`: `&Foo` - -error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:20:19 - | -LL | const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR Consider removing 'static. - | -^^^^^^^----- help: consider removing `'static`: `&[u8]` - -error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:22:19 - | -LL | const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static. - | -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)` - -error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:24:19 - | -LL | const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static. - | -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]` - -error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:26:25 - | -LL | static STATIC_VAR_ONE: &'static str = "Test static #1"; // ERROR Consider removing 'static. - | -^^^^^^^---- help: consider removing `'static`: `&str` - -error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:30:29 - | -LL | static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static - | -^^^^^^^---- help: consider removing `'static`: `&str` - -error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:32:25 - | -LL | static STATIC_VAR_SIX: &'static u8 = &5; - | -^^^^^^^--- help: consider removing `'static`: `&u8` - -error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:34:28 - | -LL | static STATIC_VAR_HEIGHT: &'static Foo = &Foo {}; - | -^^^^^^^---- help: consider removing `'static`: `&Foo` - -error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:36:27 - | -LL | static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR Consider removing 'static. - | -^^^^^^^----- help: consider removing `'static`: `&[u8]` - -error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:38:27 - | -LL | static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static. - | -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)` - -error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:40:27 - | -LL | static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static. - | -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]` - -error: aborting due to 16 previous errors - diff --git a/tests/ui/redundant_static_lifetimes_multiple.rs b/tests/ui/redundant_static_lifetimes_multiple.rs deleted file mode 100644 index f57dd58e230a..000000000000 --- a/tests/ui/redundant_static_lifetimes_multiple.rs +++ /dev/null @@ -1,13 +0,0 @@ -// these are rustfixable, but run-rustfix tests cannot handle them - -const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static - -const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; - -static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static - -static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static - -static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; - -fn main() {} diff --git a/tests/ui/redundant_static_lifetimes_multiple.stderr b/tests/ui/redundant_static_lifetimes_multiple.stderr deleted file mode 100644 index cc7e55a757a3..000000000000 --- a/tests/ui/redundant_static_lifetimes_multiple.stderr +++ /dev/null @@ -1,64 +0,0 @@ -error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:3:18 - | -LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static - | -^^^^^^^------------------ help: consider removing `'static`: `&[&[&'static str]]` - | - = note: `-D clippy::redundant-static-lifetimes` implied by `-D warnings` - -error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:3:30 - | -LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static - | -^^^^^^^---- help: consider removing `'static`: `&str` - -error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:5:29 - | -LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; - | -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]` - -error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:5:39 - | -LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; - | -^^^^^^^---- help: consider removing `'static`: `&str` - -error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:7:40 - | -LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static - | -^^^^^^^---- help: consider removing `'static`: `&str` - -error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:7:55 - | -LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static - | -^^^^^^^---- help: consider removing `'static`: `&str` - -error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:9:26 - | -LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static - | -^^^^^^^------------------ help: consider removing `'static`: `&[&[&'static str]]` - -error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:9:38 - | -LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static - | -^^^^^^^---- help: consider removing `'static`: `&str` - -error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:11:37 - | -LL | static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; - | -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]` - -error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:11:47 - | -LL | static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; - | -^^^^^^^---- help: consider removing `'static`: `&str` - -error: aborting due to 10 previous errors - diff --git a/tests/ui/ref_option_ref.rs b/tests/ui/ref_option_ref.rs deleted file mode 100644 index b2c275d68afa..000000000000 --- a/tests/ui/ref_option_ref.rs +++ /dev/null @@ -1,47 +0,0 @@ -#![allow(unused)] -#![warn(clippy::ref_option_ref)] - -// This lint is not tagged as run-rustfix because automatically -// changing the type of a variable would also means changing -// all usages of this variable to match and This is not handled -// by this lint. - -static THRESHOLD: i32 = 10; -static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD); -const CONST_THRESHOLD: &i32 = &10; -const REF_CONST: &Option<&i32> = &Some(&CONST_THRESHOLD); - -type RefOptRefU32<'a> = &'a Option<&'a u32>; -type RefOptRef<'a, T> = &'a Option<&'a T>; - -fn foo(data: &Option<&u32>) {} - -fn bar(data: &u32) -> &Option<&u32> { - &None -} - -struct StructRef<'a> { - data: &'a Option<&'a u32>, -} - -struct StructTupleRef<'a>(u32, &'a Option<&'a u32>); - -enum EnumRef<'a> { - Variant1(u32), - Variant2(&'a Option<&'a u32>), -} - -trait RefOptTrait { - type A; - fn foo(&self, _: Self::A); -} - -impl RefOptTrait for u32 { - type A = &'static Option<&'static Self>; - - fn foo(&self, _: Self::A) {} -} - -fn main() { - let x: &Option<&u32> = &None; -} diff --git a/tests/ui/ref_option_ref.stderr b/tests/ui/ref_option_ref.stderr deleted file mode 100644 index 4e7fc8000611..000000000000 --- a/tests/ui/ref_option_ref.stderr +++ /dev/null @@ -1,70 +0,0 @@ -error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:10:23 - | -LL | static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD); - | ^^^^^^^^^^^^^ help: try: `Option<&i32>` - | - = note: `-D clippy::ref-option-ref` implied by `-D warnings` - -error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:12:18 - | -LL | const REF_CONST: &Option<&i32> = &Some(&CONST_THRESHOLD); - | ^^^^^^^^^^^^^ help: try: `Option<&i32>` - -error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:14:25 - | -LL | type RefOptRefU32<'a> = &'a Option<&'a u32>; - | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` - -error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:15:25 - | -LL | type RefOptRef<'a, T> = &'a Option<&'a T>; - | ^^^^^^^^^^^^^^^^^ help: try: `Option<&'a T>` - -error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:17:14 - | -LL | fn foo(data: &Option<&u32>) {} - | ^^^^^^^^^^^^^ help: try: `Option<&u32>` - -error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:19:23 - | -LL | fn bar(data: &u32) -> &Option<&u32> { - | ^^^^^^^^^^^^^ help: try: `Option<&u32>` - -error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:24:11 - | -LL | data: &'a Option<&'a u32>, - | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` - -error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:27:32 - | -LL | struct StructTupleRef<'a>(u32, &'a Option<&'a u32>); - | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` - -error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:31:14 - | -LL | Variant2(&'a Option<&'a u32>), - | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` - -error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:40:14 - | -LL | type A = &'static Option<&'static Self>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'static Self>` - -error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:46:12 - | -LL | let x: &Option<&u32> = &None; - | ^^^^^^^^^^^^^ help: try: `Option<&u32>` - -error: aborting due to 11 previous errors - diff --git a/tests/ui/regex.rs b/tests/ui/regex.rs deleted file mode 100644 index f7f3b195ccc1..000000000000 --- a/tests/ui/regex.rs +++ /dev/null @@ -1,82 +0,0 @@ -#![allow(unused)] -#![warn(clippy::invalid_regex, clippy::trivial_regex)] - -extern crate regex; - -use regex::bytes::{Regex as BRegex, RegexBuilder as BRegexBuilder, RegexSet as BRegexSet}; -use regex::{Regex, RegexBuilder, RegexSet}; - -const OPENING_PAREN: &str = "("; -const NOT_A_REAL_REGEX: &str = "foobar"; - -fn syntax_error() { - let pipe_in_wrong_position = Regex::new("|"); - let pipe_in_wrong_position_builder = RegexBuilder::new("|"); - let wrong_char_ranice = Regex::new("[z-a]"); - let some_unicode = Regex::new("[é-è]"); - - let some_regex = Regex::new(OPENING_PAREN); - - let binary_pipe_in_wrong_position = BRegex::new("|"); - let some_binary_regex = BRegex::new(OPENING_PAREN); - let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN); - - let closing_paren = ")"; - let not_linted = Regex::new(closing_paren); - - let set = RegexSet::new(&[r"[a-z]+@[a-z]+\.(com|org|net)", r"[a-z]+\.(com|org|net)"]); - let bset = BRegexSet::new(&[ - r"[a-z]+@[a-z]+\.(com|org|net)", - r"[a-z]+\.(com|org|net)", - r".", // regression test - ]); - - let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); - let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); - - let raw_string_error = Regex::new(r"[...\/...]"); - let raw_string_error = Regex::new(r#"[...\/...]"#); -} - -fn trivial_regex() { - let trivial_eq = Regex::new("^foobar$"); - - let trivial_eq_builder = RegexBuilder::new("^foobar$"); - - let trivial_starts_with = Regex::new("^foobar"); - - let trivial_ends_with = Regex::new("foobar$"); - - let trivial_contains = Regex::new("foobar"); - - let trivial_contains = Regex::new(NOT_A_REAL_REGEX); - - let trivial_backslash = Regex::new("a\\.b"); - - // unlikely corner cases - let trivial_empty = Regex::new(""); - - let trivial_empty = Regex::new("^"); - - let trivial_empty = Regex::new("^$"); - - let binary_trivial_empty = BRegex::new("^$"); - - // non-trivial regexes - let non_trivial_dot = Regex::new("a.b"); - let non_trivial_dot_builder = RegexBuilder::new("a.b"); - let non_trivial_eq = Regex::new("^foo|bar$"); - let non_trivial_starts_with = Regex::new("^foo|bar"); - let non_trivial_ends_with = Regex::new("^foo|bar"); - let non_trivial_ends_with = Regex::new("foo|bar"); - let non_trivial_binary = BRegex::new("foo|bar"); - let non_trivial_binary_builder = BRegexBuilder::new("foo|bar"); - - // #6005: unicode classes in bytes::Regex - let a_byte_of_unicode = BRegex::new(r"\p{C}"); -} - -fn main() { - syntax_error(); - trivial_regex(); -} diff --git a/tests/ui/regex.stderr b/tests/ui/regex.stderr deleted file mode 100644 index 1394a9b63bc6..000000000000 --- a/tests/ui/regex.stderr +++ /dev/null @@ -1,171 +0,0 @@ -error: trivial regex - --> $DIR/regex.rs:13:45 - | -LL | let pipe_in_wrong_position = Regex::new("|"); - | ^^^ - | - = note: `-D clippy::trivial-regex` implied by `-D warnings` - = help: the regex is unlikely to be useful as it is - -error: trivial regex - --> $DIR/regex.rs:14:60 - | -LL | let pipe_in_wrong_position_builder = RegexBuilder::new("|"); - | ^^^ - | - = help: the regex is unlikely to be useful as it is - -error: regex syntax error: invalid character class range, the start must be <= the end - --> $DIR/regex.rs:15:42 - | -LL | let wrong_char_ranice = Regex::new("[z-a]"); - | ^^^ - | - = note: `-D clippy::invalid-regex` implied by `-D warnings` - -error: regex syntax error: invalid character class range, the start must be <= the end - --> $DIR/regex.rs:16:37 - | -LL | let some_unicode = Regex::new("[é-è]"); - | ^^^ - -error: regex syntax error on position 0: unclosed group - --> $DIR/regex.rs:18:33 - | -LL | let some_regex = Regex::new(OPENING_PAREN); - | ^^^^^^^^^^^^^ - -error: trivial regex - --> $DIR/regex.rs:20:53 - | -LL | let binary_pipe_in_wrong_position = BRegex::new("|"); - | ^^^ - | - = help: the regex is unlikely to be useful as it is - -error: regex syntax error on position 0: unclosed group - --> $DIR/regex.rs:21:41 - | -LL | let some_binary_regex = BRegex::new(OPENING_PAREN); - | ^^^^^^^^^^^^^ - -error: regex syntax error on position 0: unclosed group - --> $DIR/regex.rs:22:56 - | -LL | let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN); - | ^^^^^^^^^^^^^ - -error: regex syntax error on position 0: unclosed group - --> $DIR/regex.rs:34:37 - | -LL | let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+/.(com|org|net)"]); - | ^^^^^^^^^^^^^ - -error: regex syntax error on position 0: unclosed group - --> $DIR/regex.rs:35:39 - | -LL | let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+/.(com|org|net)"]); - | ^^^^^^^^^^^^^ - -error: regex syntax error: unrecognized escape sequence - --> $DIR/regex.rs:37:45 - | -LL | let raw_string_error = Regex::new(r"[...//...]"); - | ^^ - -error: regex syntax error: unrecognized escape sequence - --> $DIR/regex.rs:38:46 - | -LL | let raw_string_error = Regex::new(r#"[...//...]"#); - | ^^ - -error: trivial regex - --> $DIR/regex.rs:42:33 - | -LL | let trivial_eq = Regex::new("^foobar$"); - | ^^^^^^^^^^ - | - = help: consider using `==` on `str`s - -error: trivial regex - --> $DIR/regex.rs:44:48 - | -LL | let trivial_eq_builder = RegexBuilder::new("^foobar$"); - | ^^^^^^^^^^ - | - = help: consider using `==` on `str`s - -error: trivial regex - --> $DIR/regex.rs:46:42 - | -LL | let trivial_starts_with = Regex::new("^foobar"); - | ^^^^^^^^^ - | - = help: consider using `str::starts_with` - -error: trivial regex - --> $DIR/regex.rs:48:40 - | -LL | let trivial_ends_with = Regex::new("foobar$"); - | ^^^^^^^^^ - | - = help: consider using `str::ends_with` - -error: trivial regex - --> $DIR/regex.rs:50:39 - | -LL | let trivial_contains = Regex::new("foobar"); - | ^^^^^^^^ - | - = help: consider using `str::contains` - -error: trivial regex - --> $DIR/regex.rs:52:39 - | -LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using `str::contains` - -error: trivial regex - --> $DIR/regex.rs:54:40 - | -LL | let trivial_backslash = Regex::new("a/.b"); - | ^^^^^^^ - | - = help: consider using `str::contains` - -error: trivial regex - --> $DIR/regex.rs:57:36 - | -LL | let trivial_empty = Regex::new(""); - | ^^ - | - = help: the regex is unlikely to be useful as it is - -error: trivial regex - --> $DIR/regex.rs:59:36 - | -LL | let trivial_empty = Regex::new("^"); - | ^^^ - | - = help: the regex is unlikely to be useful as it is - -error: trivial regex - --> $DIR/regex.rs:61:36 - | -LL | let trivial_empty = Regex::new("^$"); - | ^^^^ - | - = help: consider using `str::is_empty` - -error: trivial regex - --> $DIR/regex.rs:63:44 - | -LL | let binary_trivial_empty = BRegex::new("^$"); - | ^^^^ - | - = help: consider using `str::is_empty` - -error: aborting due to 23 previous errors - diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed deleted file mode 100644 index 13fbb6e2a6ee..000000000000 --- a/tests/ui/rename.fixed +++ /dev/null @@ -1,19 +0,0 @@ -//! Test for Clippy lint renames. -// run-rustfix - -#![allow(dead_code)] -// allow the new lint name here, to test if the new name works -#![allow(clippy::module_name_repetitions)] -#![allow(clippy::new_without_default)] -#![allow(clippy::redundant_static_lifetimes)] -// warn for the old lint name here, to test if the renaming worked -#![warn(clippy::cognitive_complexity)] - -#[warn(clippy::module_name_repetitions)] -fn main() {} - -#[warn(clippy::new_without_default)] -struct Foo; - -#[warn(clippy::redundant_static_lifetimes)] -fn foo() {} diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs deleted file mode 100644 index cbd3b1e91666..000000000000 --- a/tests/ui/rename.rs +++ /dev/null @@ -1,19 +0,0 @@ -//! Test for Clippy lint renames. -// run-rustfix - -#![allow(dead_code)] -// allow the new lint name here, to test if the new name works -#![allow(clippy::module_name_repetitions)] -#![allow(clippy::new_without_default)] -#![allow(clippy::redundant_static_lifetimes)] -// warn for the old lint name here, to test if the renaming worked -#![warn(clippy::cyclomatic_complexity)] - -#[warn(clippy::stutter)] -fn main() {} - -#[warn(clippy::new_without_default_derive)] -struct Foo; - -#[warn(clippy::const_static_lifetime)] -fn foo() {} diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr deleted file mode 100644 index a9e803946041..000000000000 --- a/tests/ui/rename.stderr +++ /dev/null @@ -1,34 +0,0 @@ -error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:10:9 - | -LL | #![warn(clippy::cyclomatic_complexity)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` - | - = note: `-D renamed-and-removed-lints` implied by `-D warnings` - -error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:12:8 - | -LL | #[warn(clippy::stutter)] - | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` - -error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:15:8 - | -LL | #[warn(clippy::new_without_default_derive)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` - -error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:18:8 - | -LL | #[warn(clippy::const_static_lifetime)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` - -error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:10:9 - | -LL | #![warn(clippy::cyclomatic_complexity)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` - -error: aborting due to 5 previous errors - diff --git a/tests/ui/renamed_builtin_attr.fixed b/tests/ui/renamed_builtin_attr.fixed deleted file mode 100644 index cb91b841d2cb..000000000000 --- a/tests/ui/renamed_builtin_attr.fixed +++ /dev/null @@ -1,4 +0,0 @@ -// run-rustfix - -#[clippy::cognitive_complexity = "1"] -fn main() {} diff --git a/tests/ui/renamed_builtin_attr.rs b/tests/ui/renamed_builtin_attr.rs deleted file mode 100644 index b3ce2758067c..000000000000 --- a/tests/ui/renamed_builtin_attr.rs +++ /dev/null @@ -1,4 +0,0 @@ -// run-rustfix - -#[clippy::cyclomatic_complexity = "1"] -fn main() {} diff --git a/tests/ui/renamed_builtin_attr.stderr b/tests/ui/renamed_builtin_attr.stderr deleted file mode 100644 index 880467624835..000000000000 --- a/tests/ui/renamed_builtin_attr.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: usage of deprecated attribute - --> $DIR/renamed_builtin_attr.rs:3:11 - | -LL | #[clippy::cyclomatic_complexity = "1"] - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `cognitive_complexity` - -error: aborting due to previous error - diff --git a/tests/ui/repeat_once.fixed b/tests/ui/repeat_once.fixed deleted file mode 100644 index a637c22fbcd2..000000000000 --- a/tests/ui/repeat_once.fixed +++ /dev/null @@ -1,16 +0,0 @@ -// run-rustfix -#![warn(clippy::repeat_once)] -#[allow(unused, clippy::many_single_char_names, clippy::redundant_clone)] -fn main() { - const N: usize = 1; - let s = "str"; - let string = "String".to_string(); - let slice = [1; 5]; - - let a = [1; 5].to_vec(); - let b = slice.to_vec(); - let c = "hello".to_string(); - let d = "hi".to_string(); - let e = s.to_string(); - let f = string.clone(); -} diff --git a/tests/ui/repeat_once.rs b/tests/ui/repeat_once.rs deleted file mode 100644 index d99ca1b5b55d..000000000000 --- a/tests/ui/repeat_once.rs +++ /dev/null @@ -1,16 +0,0 @@ -// run-rustfix -#![warn(clippy::repeat_once)] -#[allow(unused, clippy::many_single_char_names, clippy::redundant_clone)] -fn main() { - const N: usize = 1; - let s = "str"; - let string = "String".to_string(); - let slice = [1; 5]; - - let a = [1; 5].repeat(1); - let b = slice.repeat(1); - let c = "hello".repeat(N); - let d = "hi".repeat(1); - let e = s.repeat(1); - let f = string.repeat(1); -} diff --git a/tests/ui/repeat_once.stderr b/tests/ui/repeat_once.stderr deleted file mode 100644 index 915eea3bfc6b..000000000000 --- a/tests/ui/repeat_once.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: calling `repeat(1)` on slice - --> $DIR/repeat_once.rs:10:13 - | -LL | let a = [1; 5].repeat(1); - | ^^^^^^^^^^^^^^^^ help: consider using `.to_vec()` instead: `[1; 5].to_vec()` - | - = note: `-D clippy::repeat-once` implied by `-D warnings` - -error: calling `repeat(1)` on slice - --> $DIR/repeat_once.rs:11:13 - | -LL | let b = slice.repeat(1); - | ^^^^^^^^^^^^^^^ help: consider using `.to_vec()` instead: `slice.to_vec()` - -error: calling `repeat(1)` on str - --> $DIR/repeat_once.rs:12:13 - | -LL | let c = "hello".repeat(N); - | ^^^^^^^^^^^^^^^^^ help: consider using `.to_string()` instead: `"hello".to_string()` - -error: calling `repeat(1)` on str - --> $DIR/repeat_once.rs:13:13 - | -LL | let d = "hi".repeat(1); - | ^^^^^^^^^^^^^^ help: consider using `.to_string()` instead: `"hi".to_string()` - -error: calling `repeat(1)` on str - --> $DIR/repeat_once.rs:14:13 - | -LL | let e = s.repeat(1); - | ^^^^^^^^^^^ help: consider using `.to_string()` instead: `s.to_string()` - -error: calling `repeat(1)` on a string literal - --> $DIR/repeat_once.rs:15:13 - | -LL | let f = string.repeat(1); - | ^^^^^^^^^^^^^^^^ help: consider using `.clone()` instead: `string.clone()` - -error: aborting due to 6 previous errors - diff --git a/tests/ui/repl_uninit.rs b/tests/ui/repl_uninit.rs deleted file mode 100644 index ad5b8e4857d1..000000000000 --- a/tests/ui/repl_uninit.rs +++ /dev/null @@ -1,41 +0,0 @@ -#![allow(deprecated, invalid_value)] -#![warn(clippy::all)] - -use std::mem; - -fn might_panic(x: X) -> X { - // in practice this would be a possibly-panicky operation - x -} - -fn main() { - let mut v = vec![0i32; 4]; - // the following is UB if `might_panic` panics - unsafe { - let taken_v = mem::replace(&mut v, mem::uninitialized()); - let new_v = might_panic(taken_v); - std::mem::forget(mem::replace(&mut v, new_v)); - } - - unsafe { - let taken_v = mem::replace(&mut v, mem::MaybeUninit::uninit().assume_init()); - let new_v = might_panic(taken_v); - std::mem::forget(mem::replace(&mut v, new_v)); - } - - unsafe { - let taken_v = mem::replace(&mut v, mem::zeroed()); - let new_v = might_panic(taken_v); - std::mem::forget(mem::replace(&mut v, new_v)); - } - - // this is silly but OK, because usize is a primitive type - let mut u: usize = 42; - let uref = &mut u; - let taken_u = unsafe { mem::replace(uref, mem::zeroed()) }; - *uref = taken_u + 1; - - // this is still not OK, because uninit - let taken_u = unsafe { mem::replace(uref, mem::uninitialized()) }; - *uref = taken_u + 1; -} diff --git a/tests/ui/repl_uninit.stderr b/tests/ui/repl_uninit.stderr deleted file mode 100644 index 09468eeaea4b..000000000000 --- a/tests/ui/repl_uninit.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error: replacing with `mem::uninitialized()` - --> $DIR/repl_uninit.rs:15:23 - | -LL | let taken_v = mem::replace(&mut v, mem::uninitialized()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(&mut v)` - | - = note: `-D clippy::mem-replace-with-uninit` implied by `-D warnings` - -error: replacing with `mem::MaybeUninit::uninit().assume_init()` - --> $DIR/repl_uninit.rs:21:23 - | -LL | let taken_v = mem::replace(&mut v, mem::MaybeUninit::uninit().assume_init()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(&mut v)` - -error: replacing with `mem::zeroed()` - --> $DIR/repl_uninit.rs:27:23 - | -LL | let taken_v = mem::replace(&mut v, mem::zeroed()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a default value or the `take_mut` crate instead - -error: replacing with `mem::uninitialized()` - --> $DIR/repl_uninit.rs:39:28 - | -LL | let taken_u = unsafe { mem::replace(uref, mem::uninitialized()) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(uref)` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/rest_pat_in_fully_bound_structs.rs b/tests/ui/rest_pat_in_fully_bound_structs.rs deleted file mode 100644 index 38fc9969804f..000000000000 --- a/tests/ui/rest_pat_in_fully_bound_structs.rs +++ /dev/null @@ -1,42 +0,0 @@ -#![warn(clippy::rest_pat_in_fully_bound_structs)] - -struct A { - a: i32, - b: i64, - c: &'static str, -} - -macro_rules! foo { - ($param:expr) => { - match $param { - A { a: 0, b: 0, c: "", .. } => {}, - _ => {}, - } - }; -} - -fn main() { - let a_struct = A { a: 5, b: 42, c: "A" }; - - match a_struct { - A { a: 5, b: 42, c: "", .. } => {}, // Lint - A { a: 0, b: 0, c: "", .. } => {}, // Lint - _ => {}, - } - - match a_struct { - A { a: 5, b: 42, .. } => {}, - A { a: 0, b: 0, c: "", .. } => {}, // Lint - _ => {}, - } - - // No lint - match a_struct { - A { a: 5, .. } => {}, - A { a: 0, b: 0, .. } => {}, - _ => {}, - } - - // No lint - foo!(a_struct); -} diff --git a/tests/ui/rest_pat_in_fully_bound_structs.stderr b/tests/ui/rest_pat_in_fully_bound_structs.stderr deleted file mode 100644 index 57ebd47f8c7a..000000000000 --- a/tests/ui/rest_pat_in_fully_bound_structs.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error: unnecessary use of `..` pattern in struct binding. All fields were already bound - --> $DIR/rest_pat_in_fully_bound_structs.rs:22:9 - | -LL | A { a: 5, b: 42, c: "", .. } => {}, // Lint - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::rest-pat-in-fully-bound-structs` implied by `-D warnings` - = help: consider removing `..` from this binding - -error: unnecessary use of `..` pattern in struct binding. All fields were already bound - --> $DIR/rest_pat_in_fully_bound_structs.rs:23:9 - | -LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider removing `..` from this binding - -error: unnecessary use of `..` pattern in struct binding. All fields were already bound - --> $DIR/rest_pat_in_fully_bound_structs.rs:29:9 - | -LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider removing `..` from this binding - -error: aborting due to 3 previous errors - diff --git a/tests/ui/result_map_or_into_option.fixed b/tests/ui/result_map_or_into_option.fixed deleted file mode 100644 index 331531b5165f..000000000000 --- a/tests/ui/result_map_or_into_option.fixed +++ /dev/null @@ -1,19 +0,0 @@ -// run-rustfix - -#![warn(clippy::result_map_or_into_option)] - -fn main() { - let opt: Result = Ok(1); - let _ = opt.ok(); - - let rewrap = |s: u32| -> Option { Some(s) }; - - // A non-Some `f` arg should not emit the lint - let opt: Result = Ok(1); - let _ = opt.map_or(None, rewrap); - - // A non-Some `f` closure where the argument is not used as the - // return should not emit the lint - let opt: Result = Ok(1); - opt.map_or(None, |_x| Some(1)); -} diff --git a/tests/ui/result_map_or_into_option.rs b/tests/ui/result_map_or_into_option.rs deleted file mode 100644 index 3058480e2ad3..000000000000 --- a/tests/ui/result_map_or_into_option.rs +++ /dev/null @@ -1,19 +0,0 @@ -// run-rustfix - -#![warn(clippy::result_map_or_into_option)] - -fn main() { - let opt: Result = Ok(1); - let _ = opt.map_or(None, Some); - - let rewrap = |s: u32| -> Option { Some(s) }; - - // A non-Some `f` arg should not emit the lint - let opt: Result = Ok(1); - let _ = opt.map_or(None, rewrap); - - // A non-Some `f` closure where the argument is not used as the - // return should not emit the lint - let opt: Result = Ok(1); - opt.map_or(None, |_x| Some(1)); -} diff --git a/tests/ui/result_map_or_into_option.stderr b/tests/ui/result_map_or_into_option.stderr deleted file mode 100644 index febf32147d13..000000000000 --- a/tests/ui/result_map_or_into_option.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling `ok()` instead - --> $DIR/result_map_or_into_option.rs:7:13 - | -LL | let _ = opt.map_or(None, Some); - | ^^^^^^^^^^^^^^^^^^^^^^ help: try using `ok` instead: `opt.ok()` - | - = note: `-D clippy::result-map-or-into-option` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/result_map_unit_fn_fixable.fixed b/tests/ui/result_map_unit_fn_fixable.fixed deleted file mode 100644 index 631042c616bc..000000000000 --- a/tests/ui/result_map_unit_fn_fixable.fixed +++ /dev/null @@ -1,80 +0,0 @@ -// run-rustfix - -#![warn(clippy::result_map_unit_fn)] -#![allow(unused)] - -fn do_nothing(_: T) {} - -fn diverge(_: T) -> ! { - panic!() -} - -fn plus_one(value: usize) -> usize { - value + 1 -} - -struct HasResult { - field: Result, -} - -impl HasResult { - fn do_result_nothing(&self, value: usize) {} - - fn do_result_plus_one(&self, value: usize) -> usize { - value + 1 - } -} - -#[rustfmt::skip] -fn result_map_unit_fn() { - let x = HasResult { field: Ok(10) }; - - x.field.map(plus_one); - let _: Result<(), usize> = x.field.map(do_nothing); - - if let Ok(x_field) = x.field { do_nothing(x_field) } - - if let Ok(x_field) = x.field { do_nothing(x_field) } - - if let Ok(x_field) = x.field { diverge(x_field) } - - let captured = 10; - if let Ok(value) = x.field { do_nothing(value + captured) }; - let _: Result<(), usize> = x.field.map(|value| do_nothing(value + captured)); - - if let Ok(value) = x.field { x.do_result_nothing(value + captured) } - - if let Ok(value) = x.field { x.do_result_plus_one(value + captured); } - - - if let Ok(value) = x.field { do_nothing(value + captured) } - - if let Ok(value) = x.field { do_nothing(value + captured) } - - if let Ok(value) = x.field { do_nothing(value + captured); } - - if let Ok(value) = x.field { do_nothing(value + captured); } - - - if let Ok(value) = x.field { diverge(value + captured) } - - if let Ok(value) = x.field { diverge(value + captured) } - - if let Ok(value) = x.field { diverge(value + captured); } - - if let Ok(value) = x.field { diverge(value + captured); } - - - x.field.map(|value| plus_one(value + captured)); - x.field.map(|value| { plus_one(value + captured) }); - if let Ok(value) = x.field { let y = plus_one(value + captured); } - - if let Ok(value) = x.field { plus_one(value + captured); } - - if let Ok(value) = x.field { plus_one(value + captured); } - - - if let Ok(ref value) = x.field { do_nothing(value + captured) } -} - -fn main() {} diff --git a/tests/ui/result_map_unit_fn_fixable.rs b/tests/ui/result_map_unit_fn_fixable.rs deleted file mode 100644 index 679eb2326268..000000000000 --- a/tests/ui/result_map_unit_fn_fixable.rs +++ /dev/null @@ -1,80 +0,0 @@ -// run-rustfix - -#![warn(clippy::result_map_unit_fn)] -#![allow(unused)] - -fn do_nothing(_: T) {} - -fn diverge(_: T) -> ! { - panic!() -} - -fn plus_one(value: usize) -> usize { - value + 1 -} - -struct HasResult { - field: Result, -} - -impl HasResult { - fn do_result_nothing(&self, value: usize) {} - - fn do_result_plus_one(&self, value: usize) -> usize { - value + 1 - } -} - -#[rustfmt::skip] -fn result_map_unit_fn() { - let x = HasResult { field: Ok(10) }; - - x.field.map(plus_one); - let _: Result<(), usize> = x.field.map(do_nothing); - - x.field.map(do_nothing); - - x.field.map(do_nothing); - - x.field.map(diverge); - - let captured = 10; - if let Ok(value) = x.field { do_nothing(value + captured) }; - let _: Result<(), usize> = x.field.map(|value| do_nothing(value + captured)); - - x.field.map(|value| x.do_result_nothing(value + captured)); - - x.field.map(|value| { x.do_result_plus_one(value + captured); }); - - - x.field.map(|value| do_nothing(value + captured)); - - x.field.map(|value| { do_nothing(value + captured) }); - - x.field.map(|value| { do_nothing(value + captured); }); - - x.field.map(|value| { { do_nothing(value + captured); } }); - - - x.field.map(|value| diverge(value + captured)); - - x.field.map(|value| { diverge(value + captured) }); - - x.field.map(|value| { diverge(value + captured); }); - - x.field.map(|value| { { diverge(value + captured); } }); - - - x.field.map(|value| plus_one(value + captured)); - x.field.map(|value| { plus_one(value + captured) }); - x.field.map(|value| { let y = plus_one(value + captured); }); - - x.field.map(|value| { plus_one(value + captured); }); - - x.field.map(|value| { { plus_one(value + captured); } }); - - - x.field.map(|ref value| { do_nothing(value + captured) }); -} - -fn main() {} diff --git a/tests/ui/result_map_unit_fn_fixable.stderr b/tests/ui/result_map_unit_fn_fixable.stderr deleted file mode 100644 index 4f3a8c6b7923..000000000000 --- a/tests/ui/result_map_unit_fn_fixable.stderr +++ /dev/null @@ -1,140 +0,0 @@ -error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:35:5 - | -LL | x.field.map(do_nothing); - | ^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(x_field) = x.field { do_nothing(x_field) }` - | - = note: `-D clippy::result-map-unit-fn` implied by `-D warnings` - -error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:37:5 - | -LL | x.field.map(do_nothing); - | ^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(x_field) = x.field { do_nothing(x_field) }` - -error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:39:5 - | -LL | x.field.map(diverge); - | ^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(x_field) = x.field { diverge(x_field) }` - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:45:5 - | -LL | x.field.map(|value| x.do_result_nothing(value + captured)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(value) = x.field { x.do_result_nothing(value + captured) }` - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:47:5 - | -LL | x.field.map(|value| { x.do_result_plus_one(value + captured); }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(value) = x.field { x.do_result_plus_one(value + captured); }` - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:50:5 - | -LL | x.field.map(|value| do_nothing(value + captured)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(value) = x.field { do_nothing(value + captured) }` - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:52:5 - | -LL | x.field.map(|value| { do_nothing(value + captured) }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(value) = x.field { do_nothing(value + captured) }` - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:54:5 - | -LL | x.field.map(|value| { do_nothing(value + captured); }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(value) = x.field { do_nothing(value + captured); }` - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:56:5 - | -LL | x.field.map(|value| { { do_nothing(value + captured); } }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(value) = x.field { do_nothing(value + captured); }` - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:59:5 - | -LL | x.field.map(|value| diverge(value + captured)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(value) = x.field { diverge(value + captured) }` - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:61:5 - | -LL | x.field.map(|value| { diverge(value + captured) }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(value) = x.field { diverge(value + captured) }` - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:63:5 - | -LL | x.field.map(|value| { diverge(value + captured); }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(value) = x.field { diverge(value + captured); }` - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:65:5 - | -LL | x.field.map(|value| { { diverge(value + captured); } }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(value) = x.field { diverge(value + captured); }` - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:70:5 - | -LL | x.field.map(|value| { let y = plus_one(value + captured); }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(value) = x.field { let y = plus_one(value + captured); }` - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:72:5 - | -LL | x.field.map(|value| { plus_one(value + captured); }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(value) = x.field { plus_one(value + captured); }` - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:74:5 - | -LL | x.field.map(|value| { { plus_one(value + captured); } }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(value) = x.field { plus_one(value + captured); }` - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:77:5 - | -LL | x.field.map(|ref value| { do_nothing(value + captured) }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(ref value) = x.field { do_nothing(value + captured) }` - -error: aborting due to 17 previous errors - diff --git a/tests/ui/result_map_unit_fn_unfixable.rs b/tests/ui/result_map_unit_fn_unfixable.rs deleted file mode 100644 index b197c609d7bf..000000000000 --- a/tests/ui/result_map_unit_fn_unfixable.rs +++ /dev/null @@ -1,46 +0,0 @@ -#![warn(clippy::result_map_unit_fn)] -#![feature(never_type)] -#![allow(unused)] - -struct HasResult { - field: Result, -} - -fn do_nothing(_: T) {} - -fn diverge(_: T) -> ! { - panic!() -} - -fn plus_one(value: usize) -> usize { - value + 1 -} - -#[rustfmt::skip] -fn result_map_unit_fn() { - let x = HasResult { field: Ok(10) }; - - x.field.map(|value| { do_nothing(value); do_nothing(value) }); - - x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) }); - - // Suggestion for the let block should be `{ ... }` as it's too difficult to build a - // proper suggestion for these cases - x.field.map(|value| { - do_nothing(value); - do_nothing(value) - }); - x.field.map(|value| { do_nothing(value); do_nothing(value); }); - - // The following should suggest `if let Ok(_X) ...` as it's difficult to generate a proper let variable name for them - let res: Result = Ok(42).map(diverge); - "12".parse::().map(diverge); - - let res: Result<(), usize> = Ok(plus_one(1)).map(do_nothing); - - // Should suggest `if let Ok(_y) ...` to not override the existing foo variable - let y: Result = Ok(42); - y.map(do_nothing); -} - -fn main() {} diff --git a/tests/ui/result_map_unit_fn_unfixable.stderr b/tests/ui/result_map_unit_fn_unfixable.stderr deleted file mode 100644 index 88e4efdb0f05..000000000000 --- a/tests/ui/result_map_unit_fn_unfixable.stderr +++ /dev/null @@ -1,58 +0,0 @@ -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:23:5 - | -LL | x.field.map(|value| { do_nothing(value); do_nothing(value) }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(value) = x.field { ... }` - | - = note: `-D clippy::result-map-unit-fn` implied by `-D warnings` - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:25:5 - | -LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(value) = x.field { ... }` - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:29:5 - | -LL | x.field.map(|value| { - | _____^ - | |_____| - | || -LL | || do_nothing(value); -LL | || do_nothing(value) -LL | || }); - | ||______^- help: try this: `if let Ok(value) = x.field { ... }` - | |_______| - | - -error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:33:5 - | -LL | x.field.map(|value| { do_nothing(value); do_nothing(value); }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(value) = x.field { ... }` - -error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:37:5 - | -LL | "12".parse::().map(diverge); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(a) = "12".parse::() { diverge(a) }` - -error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:43:5 - | -LL | y.map(do_nothing); - | ^^^^^^^^^^^^^^^^^- - | | - | help: try this: `if let Ok(_y) = y { do_nothing(_y) }` - -error: aborting due to 6 previous errors - diff --git a/tests/ui/result_unit_error.rs b/tests/ui/result_unit_error.rs deleted file mode 100644 index 5e57c752b5a0..000000000000 --- a/tests/ui/result_unit_error.rs +++ /dev/null @@ -1,39 +0,0 @@ -#![allow(clippy::unnecessary_wraps)] -#[warn(clippy::result_unit_err)] -#[allow(unused)] - -pub fn returns_unit_error() -> Result { - Err(()) -} - -fn private_unit_errors() -> Result { - Err(()) -} - -pub trait HasUnitError { - fn get_that_error(&self) -> Result; - - fn get_this_one_too(&self) -> Result { - Err(()) - } -} - -impl HasUnitError for () { - fn get_that_error(&self) -> Result { - Ok(true) - } -} - -trait PrivateUnitError { - fn no_problem(&self) -> Result; -} - -pub struct UnitErrorHolder; - -impl UnitErrorHolder { - pub fn unit_error(&self) -> Result { - Ok(0) - } -} - -fn main() {} diff --git a/tests/ui/result_unit_error.stderr b/tests/ui/result_unit_error.stderr deleted file mode 100644 index 12901b354f91..000000000000 --- a/tests/ui/result_unit_error.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error: this returns a `Result<_, ()> - --> $DIR/result_unit_error.rs:5:1 - | -LL | pub fn returns_unit_error() -> Result { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::result-unit-err` implied by `-D warnings` - = help: use a custom Error type instead - -error: this returns a `Result<_, ()> - --> $DIR/result_unit_error.rs:14:5 - | -LL | fn get_that_error(&self) -> Result; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use a custom Error type instead - -error: this returns a `Result<_, ()> - --> $DIR/result_unit_error.rs:16:5 - | -LL | fn get_this_one_too(&self) -> Result { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use a custom Error type instead - -error: this returns a `Result<_, ()> - --> $DIR/result_unit_error.rs:34:5 - | -LL | pub fn unit_error(&self) -> Result { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use a custom Error type instead - -error: aborting due to 4 previous errors - diff --git a/tests/ui/reversed_empty_ranges_fixable.fixed b/tests/ui/reversed_empty_ranges_fixable.fixed deleted file mode 100644 index 79e482eec303..000000000000 --- a/tests/ui/reversed_empty_ranges_fixable.fixed +++ /dev/null @@ -1,29 +0,0 @@ -// run-rustfix -#![warn(clippy::reversed_empty_ranges)] - -const ANSWER: i32 = 42; - -fn main() { - // These should be linted: - - (21..=42).rev().for_each(|x| println!("{}", x)); - let _ = (21..ANSWER).rev().filter(|x| x % 2 == 0).take(10).collect::>(); - - for _ in (-42..=-21).rev() {} - for _ in (21u32..42u32).rev() {} - - // These should be ignored as they are not empty ranges: - - (21..=42).for_each(|x| println!("{}", x)); - (21..42).for_each(|x| println!("{}", x)); - - let arr = [1, 2, 3, 4, 5]; - let _ = &arr[1..=3]; - let _ = &arr[1..3]; - - for _ in 21..=42 {} - for _ in 21..42 {} - - // This range is empty but should be ignored, see issue #5689 - let _ = &arr[0..0]; -} diff --git a/tests/ui/reversed_empty_ranges_fixable.rs b/tests/ui/reversed_empty_ranges_fixable.rs deleted file mode 100644 index b2e8bf33771a..000000000000 --- a/tests/ui/reversed_empty_ranges_fixable.rs +++ /dev/null @@ -1,29 +0,0 @@ -// run-rustfix -#![warn(clippy::reversed_empty_ranges)] - -const ANSWER: i32 = 42; - -fn main() { - // These should be linted: - - (42..=21).for_each(|x| println!("{}", x)); - let _ = (ANSWER..21).filter(|x| x % 2 == 0).take(10).collect::>(); - - for _ in -21..=-42 {} - for _ in 42u32..21u32 {} - - // These should be ignored as they are not empty ranges: - - (21..=42).for_each(|x| println!("{}", x)); - (21..42).for_each(|x| println!("{}", x)); - - let arr = [1, 2, 3, 4, 5]; - let _ = &arr[1..=3]; - let _ = &arr[1..3]; - - for _ in 21..=42 {} - for _ in 21..42 {} - - // This range is empty but should be ignored, see issue #5689 - let _ = &arr[0..0]; -} diff --git a/tests/ui/reversed_empty_ranges_fixable.stderr b/tests/ui/reversed_empty_ranges_fixable.stderr deleted file mode 100644 index de83c4f3d633..000000000000 --- a/tests/ui/reversed_empty_ranges_fixable.stderr +++ /dev/null @@ -1,47 +0,0 @@ -error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_fixable.rs:9:5 - | -LL | (42..=21).for_each(|x| println!("{}", x)); - | ^^^^^^^^^ - | - = note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` -help: consider using the following if you are attempting to iterate over this range in reverse - | -LL | (21..=42).rev().for_each(|x| println!("{}", x)); - | ^^^^^^^^^^^^^^^ - -error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_fixable.rs:10:13 - | -LL | let _ = (ANSWER..21).filter(|x| x % 2 == 0).take(10).collect::>(); - | ^^^^^^^^^^^^ - | -help: consider using the following if you are attempting to iterate over this range in reverse - | -LL | let _ = (21..ANSWER).rev().filter(|x| x % 2 == 0).take(10).collect::>(); - | ^^^^^^^^^^^^^^^^^^ - -error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_fixable.rs:12:14 - | -LL | for _ in -21..=-42 {} - | ^^^^^^^^^ - | -help: consider using the following if you are attempting to iterate over this range in reverse - | -LL | for _ in (-42..=-21).rev() {} - | ^^^^^^^^^^^^^^^^^ - -error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_fixable.rs:13:14 - | -LL | for _ in 42u32..21u32 {} - | ^^^^^^^^^^^^ - | -help: consider using the following if you are attempting to iterate over this range in reverse - | -LL | for _ in (21u32..42u32).rev() {} - | ^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 4 previous errors - diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.fixed b/tests/ui/reversed_empty_ranges_loops_fixable.fixed deleted file mode 100644 index f1503ed6d12f..000000000000 --- a/tests/ui/reversed_empty_ranges_loops_fixable.fixed +++ /dev/null @@ -1,57 +0,0 @@ -// run-rustfix -#![warn(clippy::reversed_empty_ranges)] - -fn main() { - const MAX_LEN: usize = 42; - - for i in (0..10).rev() { - println!("{}", i); - } - - for i in (0..=10).rev() { - println!("{}", i); - } - - for i in (0..MAX_LEN).rev() { - println!("{}", i); - } - - for i in 5..=5 { - // not an error, this is the range with only one element “5” - println!("{}", i); - } - - for i in 0..10 { - // not an error, the start index is less than the end index - println!("{}", i); - } - - for i in -10..0 { - // not an error - println!("{}", i); - } - - for i in (0..10).rev().map(|x| x * 2) { - println!("{}", i); - } - - // testing that the empty range lint folds constants - for i in (5 + 4..10).rev() { - println!("{}", i); - } - - for i in ((3 - 1)..(5 + 2)).rev() { - println!("{}", i); - } - - for i in (2 * 2)..(2 * 3) { - // no error, 4..6 is fine - println!("{}", i); - } - - let x = 42; - for i in x..10 { - // no error, not constant-foldable - println!("{}", i); - } -} diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.rs b/tests/ui/reversed_empty_ranges_loops_fixable.rs deleted file mode 100644 index a733788dc22c..000000000000 --- a/tests/ui/reversed_empty_ranges_loops_fixable.rs +++ /dev/null @@ -1,57 +0,0 @@ -// run-rustfix -#![warn(clippy::reversed_empty_ranges)] - -fn main() { - const MAX_LEN: usize = 42; - - for i in 10..0 { - println!("{}", i); - } - - for i in 10..=0 { - println!("{}", i); - } - - for i in MAX_LEN..0 { - println!("{}", i); - } - - for i in 5..=5 { - // not an error, this is the range with only one element “5” - println!("{}", i); - } - - for i in 0..10 { - // not an error, the start index is less than the end index - println!("{}", i); - } - - for i in -10..0 { - // not an error - println!("{}", i); - } - - for i in (10..0).map(|x| x * 2) { - println!("{}", i); - } - - // testing that the empty range lint folds constants - for i in 10..5 + 4 { - println!("{}", i); - } - - for i in (5 + 2)..(3 - 1) { - println!("{}", i); - } - - for i in (2 * 2)..(2 * 3) { - // no error, 4..6 is fine - println!("{}", i); - } - - let x = 42; - for i in x..10 { - // no error, not constant-foldable - println!("{}", i); - } -} diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.stderr b/tests/ui/reversed_empty_ranges_loops_fixable.stderr deleted file mode 100644 index e89e040a0ff9..000000000000 --- a/tests/ui/reversed_empty_ranges_loops_fixable.stderr +++ /dev/null @@ -1,69 +0,0 @@ -error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:7:14 - | -LL | for i in 10..0 { - | ^^^^^ - | - = note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` -help: consider using the following if you are attempting to iterate over this range in reverse - | -LL | for i in (0..10).rev() { - | ^^^^^^^^^^^^^ - -error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:11:14 - | -LL | for i in 10..=0 { - | ^^^^^^ - | -help: consider using the following if you are attempting to iterate over this range in reverse - | -LL | for i in (0..=10).rev() { - | ^^^^^^^^^^^^^^ - -error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:15:14 - | -LL | for i in MAX_LEN..0 { - | ^^^^^^^^^^ - | -help: consider using the following if you are attempting to iterate over this range in reverse - | -LL | for i in (0..MAX_LEN).rev() { - | ^^^^^^^^^^^^^^^^^^ - -error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:34:14 - | -LL | for i in (10..0).map(|x| x * 2) { - | ^^^^^^^ - | -help: consider using the following if you are attempting to iterate over this range in reverse - | -LL | for i in (0..10).rev().map(|x| x * 2) { - | ^^^^^^^^^^^^^ - -error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:39:14 - | -LL | for i in 10..5 + 4 { - | ^^^^^^^^^ - | -help: consider using the following if you are attempting to iterate over this range in reverse - | -LL | for i in (5 + 4..10).rev() { - | ^^^^^^^^^^^^^^^^^ - -error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:43:14 - | -LL | for i in (5 + 2)..(3 - 1) { - | ^^^^^^^^^^^^^^^^ - | -help: consider using the following if you are attempting to iterate over this range in reverse - | -LL | for i in ((3 - 1)..(5 + 2)).rev() { - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/reversed_empty_ranges_loops_unfixable.rs b/tests/ui/reversed_empty_ranges_loops_unfixable.rs deleted file mode 100644 index c4c572244168..000000000000 --- a/tests/ui/reversed_empty_ranges_loops_unfixable.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![warn(clippy::reversed_empty_ranges)] - -fn main() { - for i in 5..5 { - println!("{}", i); - } - - for i in (5 + 2)..(8 - 1) { - println!("{}", i); - } -} diff --git a/tests/ui/reversed_empty_ranges_loops_unfixable.stderr b/tests/ui/reversed_empty_ranges_loops_unfixable.stderr deleted file mode 100644 index 30095d20cfd4..000000000000 --- a/tests/ui/reversed_empty_ranges_loops_unfixable.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_unfixable.rs:4:14 - | -LL | for i in 5..5 { - | ^^^^ - | - = note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` - -error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_unfixable.rs:8:14 - | -LL | for i in (5 + 2)..(8 - 1) { - | ^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/reversed_empty_ranges_unfixable.rs b/tests/ui/reversed_empty_ranges_unfixable.rs deleted file mode 100644 index 264d3d1e95af..000000000000 --- a/tests/ui/reversed_empty_ranges_unfixable.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![warn(clippy::reversed_empty_ranges)] - -const ANSWER: i32 = 42; -const SOME_NUM: usize = 3; - -fn main() { - let arr = [1, 2, 3, 4, 5]; - let _ = &arr[3usize..=1usize]; - let _ = &arr[SOME_NUM..1]; - - for _ in ANSWER..ANSWER {} - - // Should not be linted, see issue #5689 - let _ = (42 + 10..42 + 10).map(|x| x / 2).find(|&x| x == 21); -} diff --git a/tests/ui/reversed_empty_ranges_unfixable.stderr b/tests/ui/reversed_empty_ranges_unfixable.stderr deleted file mode 100644 index f23d4eb0f9ca..000000000000 --- a/tests/ui/reversed_empty_ranges_unfixable.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: this range is reversed and using it to index a slice will panic at run-time - --> $DIR/reversed_empty_ranges_unfixable.rs:8:18 - | -LL | let _ = &arr[3usize..=1usize]; - | ^^^^^^^^^^^^^^^ - | - = note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` - -error: this range is reversed and using it to index a slice will panic at run-time - --> $DIR/reversed_empty_ranges_unfixable.rs:9:18 - | -LL | let _ = &arr[SOME_NUM..1]; - | ^^^^^^^^^^^ - -error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_unfixable.rs:11:14 - | -LL | for _ in ANSWER..ANSWER {} - | ^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/same_functions_in_if_condition.rs b/tests/ui/same_functions_in_if_condition.rs deleted file mode 100644 index 7f28f0257904..000000000000 --- a/tests/ui/same_functions_in_if_condition.rs +++ /dev/null @@ -1,90 +0,0 @@ -#![warn(clippy::same_functions_in_if_condition)] -#![allow(clippy::ifs_same_cond)] // This warning is different from `ifs_same_cond`. -#![allow(clippy::if_same_then_else, clippy::comparison_chain)] // all empty blocks - -fn function() -> bool { - true -} - -fn fn_arg(_arg: u8) -> bool { - true -} - -struct Struct; - -impl Struct { - fn method(&self) -> bool { - true - } - fn method_arg(&self, _arg: u8) -> bool { - true - } -} - -fn ifs_same_cond_fn() { - let a = 0; - let obj = Struct; - - if function() { - } else if function() { - //~ ERROR ifs same condition - } - - if fn_arg(a) { - } else if fn_arg(a) { - //~ ERROR ifs same condition - } - - if obj.method() { - } else if obj.method() { - //~ ERROR ifs same condition - } - - if obj.method_arg(a) { - } else if obj.method_arg(a) { - //~ ERROR ifs same condition - } - - let mut v = vec![1]; - if v.pop() == None { - //~ ERROR ifs same condition - } else if v.pop() == None { - } - - if v.len() == 42 { - //~ ERROR ifs same condition - } else if v.len() == 42 { - } - - if v.len() == 1 { - // ok, different conditions - } else if v.len() == 2 { - } - - if fn_arg(0) { - // ok, different arguments. - } else if fn_arg(1) { - } - - if obj.method_arg(0) { - // ok, different arguments. - } else if obj.method_arg(1) { - } - - if a == 1 { - // ok, warning is on `ifs_same_cond` behalf. - } else if a == 1 { - } -} - -fn main() { - // macro as condition (see #6168) - let os = if cfg!(target_os = "macos") { - "macos" - } else if cfg!(target_os = "windows") { - "windows" - } else { - "linux" - }; - println!("{}", os); -} diff --git a/tests/ui/same_functions_in_if_condition.stderr b/tests/ui/same_functions_in_if_condition.stderr deleted file mode 100644 index 363a03846d23..000000000000 --- a/tests/ui/same_functions_in_if_condition.stderr +++ /dev/null @@ -1,75 +0,0 @@ -error: this `if` has the same function call as a previous `if` - --> $DIR/same_functions_in_if_condition.rs:29:15 - | -LL | } else if function() { - | ^^^^^^^^^^ - | - = note: `-D clippy::same-functions-in-if-condition` implied by `-D warnings` -note: same as this - --> $DIR/same_functions_in_if_condition.rs:28:8 - | -LL | if function() { - | ^^^^^^^^^^ - -error: this `if` has the same function call as a previous `if` - --> $DIR/same_functions_in_if_condition.rs:34:15 - | -LL | } else if fn_arg(a) { - | ^^^^^^^^^ - | -note: same as this - --> $DIR/same_functions_in_if_condition.rs:33:8 - | -LL | if fn_arg(a) { - | ^^^^^^^^^ - -error: this `if` has the same function call as a previous `if` - --> $DIR/same_functions_in_if_condition.rs:39:15 - | -LL | } else if obj.method() { - | ^^^^^^^^^^^^ - | -note: same as this - --> $DIR/same_functions_in_if_condition.rs:38:8 - | -LL | if obj.method() { - | ^^^^^^^^^^^^ - -error: this `if` has the same function call as a previous `if` - --> $DIR/same_functions_in_if_condition.rs:44:15 - | -LL | } else if obj.method_arg(a) { - | ^^^^^^^^^^^^^^^^^ - | -note: same as this - --> $DIR/same_functions_in_if_condition.rs:43:8 - | -LL | if obj.method_arg(a) { - | ^^^^^^^^^^^^^^^^^ - -error: this `if` has the same function call as a previous `if` - --> $DIR/same_functions_in_if_condition.rs:51:15 - | -LL | } else if v.pop() == None { - | ^^^^^^^^^^^^^^^ - | -note: same as this - --> $DIR/same_functions_in_if_condition.rs:49:8 - | -LL | if v.pop() == None { - | ^^^^^^^^^^^^^^^ - -error: this `if` has the same function call as a previous `if` - --> $DIR/same_functions_in_if_condition.rs:56:15 - | -LL | } else if v.len() == 42 { - | ^^^^^^^^^^^^^ - | -note: same as this - --> $DIR/same_functions_in_if_condition.rs:54:8 - | -LL | if v.len() == 42 { - | ^^^^^^^^^^^^^ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/same_item_push.rs b/tests/ui/same_item_push.rs deleted file mode 100644 index a37c8782ec33..000000000000 --- a/tests/ui/same_item_push.rs +++ /dev/null @@ -1,151 +0,0 @@ -#![warn(clippy::same_item_push)] - -const VALUE: u8 = 7; - -fn mutate_increment(x: &mut u8) -> u8 { - *x += 1; - *x -} - -fn increment(x: u8) -> u8 { - x + 1 -} - -fn fun() -> usize { - 42 -} - -fn main() { - // ** linted cases ** - let mut vec: Vec = Vec::new(); - let item = 2; - for _ in 5..=20 { - vec.push(item); - } - - let mut vec: Vec = Vec::new(); - for _ in 0..15 { - let item = 2; - vec.push(item); - } - - let mut vec: Vec = Vec::new(); - for _ in 0..15 { - vec.push(13); - } - - let mut vec = Vec::new(); - for _ in 0..20 { - vec.push(VALUE); - } - - let mut vec = Vec::new(); - let item = VALUE; - for _ in 0..20 { - vec.push(item); - } - - // ** non-linted cases ** - let mut spaces = Vec::with_capacity(10); - for _ in 0..10 { - spaces.push(vec![b' ']); - } - - // Suggestion should not be given as pushed variable can mutate - let mut vec: Vec = Vec::new(); - let mut item: u8 = 2; - for _ in 0..30 { - vec.push(mutate_increment(&mut item)); - } - - let mut vec: Vec = Vec::new(); - let mut item: u8 = 2; - let mut item2 = &mut mutate_increment(&mut item); - for _ in 0..30 { - vec.push(mutate_increment(item2)); - } - - let mut vec: Vec = Vec::new(); - for (a, b) in [0, 1, 4, 9, 16].iter().enumerate() { - vec.push(a); - } - - let mut vec: Vec = Vec::new(); - for i in 0..30 { - vec.push(increment(i)); - } - - let mut vec: Vec = Vec::new(); - for i in 0..30 { - vec.push(i + i * i); - } - - // Suggestion should not be given as there are multiple pushes that are not the same - let mut vec: Vec = Vec::new(); - let item: u8 = 2; - for _ in 0..30 { - vec.push(item); - vec.push(item * 2); - } - - // Suggestion should not be given as Vec is not involved - for _ in 0..5 { - println!("Same Item Push"); - } - - struct A { - kind: u32, - } - let mut vec_a: Vec = Vec::new(); - for i in 0..30 { - vec_a.push(A { kind: i }); - } - let mut vec: Vec = Vec::new(); - for a in vec_a { - vec.push(2u8.pow(a.kind)); - } - - // Fix #5902 - let mut vec: Vec = Vec::new(); - let mut item = 0; - for _ in 0..10 { - vec.push(item); - item += 10; - } - - // Fix #5979 - let mut vec: Vec = Vec::new(); - for _ in 0..10 { - vec.push(std::fs::File::open("foobar").unwrap()); - } - // Fix #5979 - #[derive(Clone)] - struct S {} - - trait T {} - impl T for S {} - - let mut vec: Vec> = Vec::new(); - for _ in 0..10 { - vec.push(Box::new(S {})); - } - - // Fix #5985 - let mut vec = Vec::new(); - let item = 42; - let item = fun(); - for _ in 0..20 { - vec.push(item); - } - - // Fix #5985 - let mut vec = Vec::new(); - let key = 1; - for _ in 0..20 { - let item = match key { - 1 => 10, - _ => 0, - }; - vec.push(item); - } -} diff --git a/tests/ui/same_item_push.stderr b/tests/ui/same_item_push.stderr deleted file mode 100644 index d9ffa15780ad..000000000000 --- a/tests/ui/same_item_push.stderr +++ /dev/null @@ -1,43 +0,0 @@ -error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:23:9 - | -LL | vec.push(item); - | ^^^ - | - = note: `-D clippy::same-item-push` implied by `-D warnings` - = help: try using vec![item;SIZE] or vec.resize(NEW_SIZE, item) - -error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:29:9 - | -LL | vec.push(item); - | ^^^ - | - = help: try using vec![item;SIZE] or vec.resize(NEW_SIZE, item) - -error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:34:9 - | -LL | vec.push(13); - | ^^^ - | - = help: try using vec![13;SIZE] or vec.resize(NEW_SIZE, 13) - -error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:39:9 - | -LL | vec.push(VALUE); - | ^^^ - | - = help: try using vec![VALUE;SIZE] or vec.resize(NEW_SIZE, VALUE) - -error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:45:9 - | -LL | vec.push(item); - | ^^^ - | - = help: try using vec![item;SIZE] or vec.resize(NEW_SIZE, item) - -error: aborting due to 5 previous errors - diff --git a/tests/ui/search_is_some.rs b/tests/ui/search_is_some.rs deleted file mode 100644 index f0dc3b3d06bb..000000000000 --- a/tests/ui/search_is_some.rs +++ /dev/null @@ -1,38 +0,0 @@ -// aux-build:option_helpers.rs -extern crate option_helpers; -use option_helpers::IteratorFalsePositives; - -#[warn(clippy::search_is_some)] -#[rustfmt::skip] -fn main() { - let v = vec![3, 2, 1, 0, -1, -2, -3]; - let y = &&42; - - - // Check `find().is_some()`, multi-line case. - let _ = v.iter().find(|&x| { - *x < 0 - } - ).is_some(); - - // Check `position().is_some()`, multi-line case. - let _ = v.iter().position(|&x| { - x < 0 - } - ).is_some(); - - // Check `rposition().is_some()`, multi-line case. - let _ = v.iter().rposition(|&x| { - x < 0 - } - ).is_some(); - - // Check that we don't lint if the caller is not an `Iterator` or string - let falsepos = IteratorFalsePositives { foo: 0 }; - let _ = falsepos.find().is_some(); - let _ = falsepos.position().is_some(); - let _ = falsepos.rposition().is_some(); - // check that we don't lint if `find()` is called with - // `Pattern` that is not a string - let _ = "hello world".find(|c: char| c == 'o' || c == 'l').is_some(); -} diff --git a/tests/ui/search_is_some.stderr b/tests/ui/search_is_some.stderr deleted file mode 100644 index c601f568c609..000000000000 --- a/tests/ui/search_is_some.stderr +++ /dev/null @@ -1,39 +0,0 @@ -error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some.rs:13:13 - | -LL | let _ = v.iter().find(|&x| { - | _____________^ -LL | | *x < 0 -LL | | } -LL | | ).is_some(); - | |______________________________^ - | - = note: `-D clippy::search-is-some` implied by `-D warnings` - = help: this is more succinctly expressed by calling `any()` - -error: called `is_some()` after searching an `Iterator` with `position` - --> $DIR/search_is_some.rs:19:13 - | -LL | let _ = v.iter().position(|&x| { - | _____________^ -LL | | x < 0 -LL | | } -LL | | ).is_some(); - | |______________________________^ - | - = help: this is more succinctly expressed by calling `any()` - -error: called `is_some()` after searching an `Iterator` with `rposition` - --> $DIR/search_is_some.rs:25:13 - | -LL | let _ = v.iter().rposition(|&x| { - | _____________^ -LL | | x < 0 -LL | | } -LL | | ).is_some(); - | |______________________________^ - | - = help: this is more succinctly expressed by calling `any()` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/search_is_some_fixable.fixed b/tests/ui/search_is_some_fixable.fixed deleted file mode 100644 index dc3f290e5624..000000000000 --- a/tests/ui/search_is_some_fixable.fixed +++ /dev/null @@ -1,35 +0,0 @@ -// run-rustfix - -#![warn(clippy::search_is_some)] - -fn main() { - let v = vec![3, 2, 1, 0, -1, -2, -3]; - let y = &&42; - - // Check `find().is_some()`, single-line case. - let _ = v.iter().any(|x| *x < 0); - let _ = (0..1).any(|x| **y == x); // one dereference less - let _ = (0..1).any(|x| x == 0); - let _ = v.iter().any(|x| *x == 0); - - // Check `position().is_some()`, single-line case. - let _ = v.iter().any(|&x| x < 0); - - // Check `rposition().is_some()`, single-line case. - let _ = v.iter().any(|&x| x < 0); - - let s1 = String::from("hello world"); - let s2 = String::from("world"); - // caller of `find()` is a `&`static str` - let _ = "hello world".contains("world"); - let _ = "hello world".contains(&s2); - let _ = "hello world".contains(&s2[2..]); - // caller of `find()` is a `String` - let _ = s1.contains("world"); - let _ = s1.contains(&s2); - let _ = s1.contains(&s2[2..]); - // caller of `find()` is slice of `String` - let _ = s1[2..].contains("world"); - let _ = s1[2..].contains(&s2); - let _ = s1[2..].contains(&s2[2..]); -} diff --git a/tests/ui/search_is_some_fixable.rs b/tests/ui/search_is_some_fixable.rs deleted file mode 100644 index 146cf5adf1b0..000000000000 --- a/tests/ui/search_is_some_fixable.rs +++ /dev/null @@ -1,35 +0,0 @@ -// run-rustfix - -#![warn(clippy::search_is_some)] - -fn main() { - let v = vec![3, 2, 1, 0, -1, -2, -3]; - let y = &&42; - - // Check `find().is_some()`, single-line case. - let _ = v.iter().find(|&x| *x < 0).is_some(); - let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less - let _ = (0..1).find(|x| *x == 0).is_some(); - let _ = v.iter().find(|x| **x == 0).is_some(); - - // Check `position().is_some()`, single-line case. - let _ = v.iter().position(|&x| x < 0).is_some(); - - // Check `rposition().is_some()`, single-line case. - let _ = v.iter().rposition(|&x| x < 0).is_some(); - - let s1 = String::from("hello world"); - let s2 = String::from("world"); - // caller of `find()` is a `&`static str` - let _ = "hello world".find("world").is_some(); - let _ = "hello world".find(&s2).is_some(); - let _ = "hello world".find(&s2[2..]).is_some(); - // caller of `find()` is a `String` - let _ = s1.find("world").is_some(); - let _ = s1.find(&s2).is_some(); - let _ = s1.find(&s2[2..]).is_some(); - // caller of `find()` is slice of `String` - let _ = s1[2..].find("world").is_some(); - let _ = s1[2..].find(&s2).is_some(); - let _ = s1[2..].find(&s2[2..]).is_some(); -} diff --git a/tests/ui/search_is_some_fixable.stderr b/tests/ui/search_is_some_fixable.stderr deleted file mode 100644 index 23c1d9a901b9..000000000000 --- a/tests/ui/search_is_some_fixable.stderr +++ /dev/null @@ -1,94 +0,0 @@ -error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable.rs:10:22 - | -LL | let _ = v.iter().find(|&x| *x < 0).is_some(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| *x < 0)` - | - = note: `-D clippy::search-is-some` implied by `-D warnings` - -error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable.rs:11:20 - | -LL | let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| **y == x)` - -error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable.rs:12:20 - | -LL | let _ = (0..1).find(|x| *x == 0).is_some(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| x == 0)` - -error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable.rs:13:22 - | -LL | let _ = v.iter().find(|x| **x == 0).is_some(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| *x == 0)` - -error: called `is_some()` after searching an `Iterator` with `position` - --> $DIR/search_is_some_fixable.rs:16:22 - | -LL | let _ = v.iter().position(|&x| x < 0).is_some(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|&x| x < 0)` - -error: called `is_some()` after searching an `Iterator` with `rposition` - --> $DIR/search_is_some_fixable.rs:19:22 - | -LL | let _ = v.iter().rposition(|&x| x < 0).is_some(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|&x| x < 0)` - -error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable.rs:24:27 - | -LL | let _ = "hello world".find("world").is_some(); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")` - -error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable.rs:25:27 - | -LL | let _ = "hello world".find(&s2).is_some(); - | ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)` - -error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable.rs:26:27 - | -LL | let _ = "hello world".find(&s2[2..]).is_some(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])` - -error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable.rs:28:16 - | -LL | let _ = s1.find("world").is_some(); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")` - -error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable.rs:29:16 - | -LL | let _ = s1.find(&s2).is_some(); - | ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)` - -error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable.rs:30:16 - | -LL | let _ = s1.find(&s2[2..]).is_some(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])` - -error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable.rs:32:21 - | -LL | let _ = s1[2..].find("world").is_some(); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")` - -error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable.rs:33:21 - | -LL | let _ = s1[2..].find(&s2).is_some(); - | ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)` - -error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable.rs:34:21 - | -LL | let _ = s1[2..].find(&s2[2..]).is_some(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])` - -error: aborting due to 15 previous errors - diff --git a/tests/ui/self_assignment.rs b/tests/ui/self_assignment.rs deleted file mode 100644 index a7cbb9cd78b1..000000000000 --- a/tests/ui/self_assignment.rs +++ /dev/null @@ -1,67 +0,0 @@ -#![warn(clippy::self_assignment)] - -pub struct S<'a> { - a: i32, - b: [i32; 10], - c: Vec>, - e: &'a mut i32, - f: &'a mut i32, -} - -pub fn positives(mut a: usize, b: &mut u32, mut s: S) { - a = a; - *b = *b; - s = s; - s.a = s.a; - s.b[10] = s.b[5 + 5]; - s.c[0][1] = s.c[0][1]; - s.b[a] = s.b[a]; - *s.e = *s.e; - s.b[a + 10] = s.b[10 + a]; - - let mut t = (0, 1); - t.1 = t.1; - t.0 = (t.0); -} - -pub fn negatives_not_equal(mut a: usize, b: &mut usize, mut s: S) { - dbg!(&a); - a = *b; - dbg!(&a); - s.b[1] += s.b[1]; - s.b[1] = s.b[2]; - s.c[1][0] = s.c[0][1]; - s.b[a] = s.b[*b]; - s.b[a + 10] = s.b[a + 11]; - *s.e = *s.f; - - let mut t = (0, 1); - t.0 = t.1; -} - -#[allow(clippy::eval_order_dependence)] -pub fn negatives_side_effects() { - let mut v = vec![1, 2, 3, 4, 5]; - let mut i = 0; - v[{ - i += 1; - i - }] = v[{ - i += 1; - i - }]; - - fn next(n: &mut usize) -> usize { - let v = *n; - *n += 1; - v - } - - let mut w = vec![1, 2, 3, 4, 5]; - let mut i = 0; - let i = &mut i; - w[next(i)] = w[next(i)]; - w[next(i)] = w[next(i)]; -} - -fn main() {} diff --git a/tests/ui/self_assignment.stderr b/tests/ui/self_assignment.stderr deleted file mode 100644 index 826e0d0ba888..000000000000 --- a/tests/ui/self_assignment.stderr +++ /dev/null @@ -1,70 +0,0 @@ -error: self-assignment of `a` to `a` - --> $DIR/self_assignment.rs:12:5 - | -LL | a = a; - | ^^^^^ - | - = note: `-D clippy::self-assignment` implied by `-D warnings` - -error: self-assignment of `*b` to `*b` - --> $DIR/self_assignment.rs:13:5 - | -LL | *b = *b; - | ^^^^^^^ - -error: self-assignment of `s` to `s` - --> $DIR/self_assignment.rs:14:5 - | -LL | s = s; - | ^^^^^ - -error: self-assignment of `s.a` to `s.a` - --> $DIR/self_assignment.rs:15:5 - | -LL | s.a = s.a; - | ^^^^^^^^^ - -error: self-assignment of `s.b[5 + 5]` to `s.b[10]` - --> $DIR/self_assignment.rs:16:5 - | -LL | s.b[10] = s.b[5 + 5]; - | ^^^^^^^^^^^^^^^^^^^^ - -error: self-assignment of `s.c[0][1]` to `s.c[0][1]` - --> $DIR/self_assignment.rs:17:5 - | -LL | s.c[0][1] = s.c[0][1]; - | ^^^^^^^^^^^^^^^^^^^^^ - -error: self-assignment of `s.b[a]` to `s.b[a]` - --> $DIR/self_assignment.rs:18:5 - | -LL | s.b[a] = s.b[a]; - | ^^^^^^^^^^^^^^^ - -error: self-assignment of `*s.e` to `*s.e` - --> $DIR/self_assignment.rs:19:5 - | -LL | *s.e = *s.e; - | ^^^^^^^^^^^ - -error: self-assignment of `s.b[10 + a]` to `s.b[a + 10]` - --> $DIR/self_assignment.rs:20:5 - | -LL | s.b[a + 10] = s.b[10 + a]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: self-assignment of `t.1` to `t.1` - --> $DIR/self_assignment.rs:23:5 - | -LL | t.1 = t.1; - | ^^^^^^^^^ - -error: self-assignment of `(t.0)` to `t.0` - --> $DIR/self_assignment.rs:24:5 - | -LL | t.0 = (t.0); - | ^^^^^^^^^^^ - -error: aborting due to 11 previous errors - diff --git a/tests/ui/serde.rs b/tests/ui/serde.rs deleted file mode 100644 index 5843344eba89..000000000000 --- a/tests/ui/serde.rs +++ /dev/null @@ -1,47 +0,0 @@ -#![warn(clippy::serde_api_misuse)] -#![allow(dead_code)] - -extern crate serde; - -struct A; - -impl<'de> serde::de::Visitor<'de> for A { - type Value = (); - - fn expecting(&self, _: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - unimplemented!() - } - - fn visit_str(self, _v: &str) -> Result - where - E: serde::de::Error, - { - unimplemented!() - } - - fn visit_string(self, _v: String) -> Result - where - E: serde::de::Error, - { - unimplemented!() - } -} - -struct B; - -impl<'de> serde::de::Visitor<'de> for B { - type Value = (); - - fn expecting(&self, _: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - unimplemented!() - } - - fn visit_string(self, _v: String) -> Result - where - E: serde::de::Error, - { - unimplemented!() - } -} - -fn main() {} diff --git a/tests/ui/serde.stderr b/tests/ui/serde.stderr deleted file mode 100644 index 760c9c9908a6..000000000000 --- a/tests/ui/serde.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error: you should not implement `visit_string` without also implementing `visit_str` - --> $DIR/serde.rs:39:5 - | -LL | / fn visit_string(self, _v: String) -> Result -LL | | where -LL | | E: serde::de::Error, -LL | | { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = note: `-D clippy::serde-api-misuse` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/shadow.rs b/tests/ui/shadow.rs deleted file mode 100644 index e366c75335c2..000000000000 --- a/tests/ui/shadow.rs +++ /dev/null @@ -1,54 +0,0 @@ -#![warn( - clippy::all, - clippy::pedantic, - clippy::shadow_same, - clippy::shadow_reuse, - clippy::shadow_unrelated -)] -#![allow( - unused_parens, - unused_variables, - clippy::manual_unwrap_or, - clippy::missing_docs_in_private_items, - clippy::single_match -)] - -fn id(x: T) -> T { - x -} - -#[must_use] -fn first(x: (isize, isize)) -> isize { - x.0 -} - -fn main() { - let mut x = 1; - let x = &mut x; - let x = { x }; - let x = (&*x); - let x = { *x + 1 }; - let x = id(x); - let x = (1, x); - let x = first(x); - let y = 1; - let x = y; - - let x; - x = 42; - - let o = Some(1_u8); - - if let Some(p) = o { - assert_eq!(1, p); - } - match o { - Some(p) => p, // no error, because the p above is in its own scope - None => 0, - }; - - match (x, o) { - (1, Some(a)) | (a, Some(1)) => (), // no error though `a` appears twice - _ => (), - } -} diff --git a/tests/ui/shadow.stderr b/tests/ui/shadow.stderr deleted file mode 100644 index 7c1ad2949e91..000000000000 --- a/tests/ui/shadow.stderr +++ /dev/null @@ -1,138 +0,0 @@ -error: `x` is shadowed by itself in `&mut x` - --> $DIR/shadow.rs:27:5 - | -LL | let x = &mut x; - | ^^^^^^^^^^^^^^^ - | - = note: `-D clippy::shadow-same` implied by `-D warnings` -note: previous binding is here - --> $DIR/shadow.rs:26:13 - | -LL | let mut x = 1; - | ^ - -error: `x` is shadowed by itself in `{ x }` - --> $DIR/shadow.rs:28:5 - | -LL | let x = { x }; - | ^^^^^^^^^^^^^^ - | -note: previous binding is here - --> $DIR/shadow.rs:27:9 - | -LL | let x = &mut x; - | ^ - -error: `x` is shadowed by itself in `(&*x)` - --> $DIR/shadow.rs:29:5 - | -LL | let x = (&*x); - | ^^^^^^^^^^^^^^ - | -note: previous binding is here - --> $DIR/shadow.rs:28:9 - | -LL | let x = { x }; - | ^ - -error: `x` is shadowed by `{ *x + 1 }` which reuses the original value - --> $DIR/shadow.rs:30:9 - | -LL | let x = { *x + 1 }; - | ^ - | - = note: `-D clippy::shadow-reuse` implied by `-D warnings` -note: initialization happens here - --> $DIR/shadow.rs:30:13 - | -LL | let x = { *x + 1 }; - | ^^^^^^^^^^ -note: previous binding is here - --> $DIR/shadow.rs:29:9 - | -LL | let x = (&*x); - | ^ - -error: `x` is shadowed by `id(x)` which reuses the original value - --> $DIR/shadow.rs:31:9 - | -LL | let x = id(x); - | ^ - | -note: initialization happens here - --> $DIR/shadow.rs:31:13 - | -LL | let x = id(x); - | ^^^^^ -note: previous binding is here - --> $DIR/shadow.rs:30:9 - | -LL | let x = { *x + 1 }; - | ^ - -error: `x` is shadowed by `(1, x)` which reuses the original value - --> $DIR/shadow.rs:32:9 - | -LL | let x = (1, x); - | ^ - | -note: initialization happens here - --> $DIR/shadow.rs:32:13 - | -LL | let x = (1, x); - | ^^^^^^ -note: previous binding is here - --> $DIR/shadow.rs:31:9 - | -LL | let x = id(x); - | ^ - -error: `x` is shadowed by `first(x)` which reuses the original value - --> $DIR/shadow.rs:33:9 - | -LL | let x = first(x); - | ^ - | -note: initialization happens here - --> $DIR/shadow.rs:33:13 - | -LL | let x = first(x); - | ^^^^^^^^ -note: previous binding is here - --> $DIR/shadow.rs:32:9 - | -LL | let x = (1, x); - | ^ - -error: `x` is being shadowed - --> $DIR/shadow.rs:35:9 - | -LL | let x = y; - | ^ - | - = note: `-D clippy::shadow-unrelated` implied by `-D warnings` -note: initialization happens here - --> $DIR/shadow.rs:35:13 - | -LL | let x = y; - | ^ -note: previous binding is here - --> $DIR/shadow.rs:33:9 - | -LL | let x = first(x); - | ^ - -error: `x` shadows a previous declaration - --> $DIR/shadow.rs:37:5 - | -LL | let x; - | ^^^^^^ - | -note: previous binding is here - --> $DIR/shadow.rs:35:9 - | -LL | let x = y; - | ^ - -error: aborting due to 9 previous errors - diff --git a/tests/ui/short_circuit_statement.fixed b/tests/ui/short_circuit_statement.fixed deleted file mode 100644 index af0a397bd1af..000000000000 --- a/tests/ui/short_circuit_statement.fixed +++ /dev/null @@ -1,18 +0,0 @@ -// run-rustfix - -#![warn(clippy::short_circuit_statement)] -#![allow(clippy::nonminimal_bool)] - -fn main() { - if f() { g(); } - if !f() { g(); } - if !(1 == 2) { g(); } -} - -fn f() -> bool { - true -} - -fn g() -> bool { - false -} diff --git a/tests/ui/short_circuit_statement.rs b/tests/ui/short_circuit_statement.rs deleted file mode 100644 index 73a55bf1f5e2..000000000000 --- a/tests/ui/short_circuit_statement.rs +++ /dev/null @@ -1,18 +0,0 @@ -// run-rustfix - -#![warn(clippy::short_circuit_statement)] -#![allow(clippy::nonminimal_bool)] - -fn main() { - f() && g(); - f() || g(); - 1 == 2 || g(); -} - -fn f() -> bool { - true -} - -fn g() -> bool { - false -} diff --git a/tests/ui/short_circuit_statement.stderr b/tests/ui/short_circuit_statement.stderr deleted file mode 100644 index 0a3f60c3d132..000000000000 --- a/tests/ui/short_circuit_statement.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: boolean short circuit operator in statement may be clearer using an explicit test - --> $DIR/short_circuit_statement.rs:7:5 - | -LL | f() && g(); - | ^^^^^^^^^^^ help: replace it with: `if f() { g(); }` - | - = note: `-D clippy::short-circuit-statement` implied by `-D warnings` - -error: boolean short circuit operator in statement may be clearer using an explicit test - --> $DIR/short_circuit_statement.rs:8:5 - | -LL | f() || g(); - | ^^^^^^^^^^^ help: replace it with: `if !f() { g(); }` - -error: boolean short circuit operator in statement may be clearer using an explicit test - --> $DIR/short_circuit_statement.rs:9:5 - | -LL | 1 == 2 || g(); - | ^^^^^^^^^^^^^^ help: replace it with: `if !(1 == 2) { g(); }` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/should_impl_trait/corner_cases.rs b/tests/ui/should_impl_trait/corner_cases.rs deleted file mode 100644 index 6c5ffe6aba8b..000000000000 --- a/tests/ui/should_impl_trait/corner_cases.rs +++ /dev/null @@ -1,83 +0,0 @@ -// edition:2018 - -#![warn(clippy::all, clippy::pedantic)] -#![allow( - clippy::missing_errors_doc, - clippy::needless_pass_by_value, - clippy::must_use_candidate, - clippy::unused_self, - clippy::needless_lifetimes, - clippy::missing_safety_doc, - clippy::wrong_self_convention -)] - -use std::ops::Mul; -use std::rc::{self, Rc}; -use std::sync::{self, Arc}; - -fn main() {} - -pub struct T1; -impl T1 { - // corner cases: should not lint - - // no error, not public interface - pub(crate) fn drop(&mut self) {} - - // no error, private function - fn neg(self) -> Self { - self - } - - // no error, private function - fn eq(&self, other: Self) -> bool { - true - } - - // No error; self is a ref. - fn sub(&self, other: Self) -> &Self { - self - } - - // No error; different number of arguments. - fn div(self) -> Self { - self - } - - // No error; wrong return type. - fn rem(self, other: Self) {} - - // Fine - fn into_u32(self) -> u32 { - 0 - } - - fn into_u16(&self) -> u16 { - 0 - } - - fn to_something(self) -> u32 { - 0 - } - - fn new(self) -> Self { - unimplemented!(); - } - - pub fn next<'b>(&'b mut self) -> Option<&'b mut T1> { - unimplemented!(); - } -} - -pub struct T2; -impl T2 { - // Shouldn't trigger lint as it is unsafe. - pub unsafe fn add(self, rhs: Self) -> Self { - self - } - - // Should not trigger lint since this is an async function. - pub async fn next(&mut self) -> Option { - None - } -} diff --git a/tests/ui/should_impl_trait/method_list_1.rs b/tests/ui/should_impl_trait/method_list_1.rs deleted file mode 100644 index f8d248fc98d8..000000000000 --- a/tests/ui/should_impl_trait/method_list_1.rs +++ /dev/null @@ -1,87 +0,0 @@ -// edition:2018 - -#![warn(clippy::all, clippy::pedantic)] -#![allow( - clippy::missing_errors_doc, - clippy::needless_pass_by_value, - clippy::must_use_candidate, - clippy::unused_self, - clippy::needless_lifetimes, - clippy::missing_safety_doc, - clippy::wrong_self_convention -)] - -use std::ops::Mul; -use std::rc::{self, Rc}; -use std::sync::{self, Arc}; - -fn main() {} -pub struct T; - -impl T { - // ***************************************** - // trait method list part 1, should lint all - // ***************************************** - pub fn add(self, other: T) -> T { - unimplemented!() - } - - pub fn as_mut(&mut self) -> &mut T { - unimplemented!() - } - - pub fn as_ref(&self) -> &T { - unimplemented!() - } - - pub fn bitand(self, rhs: T) -> T { - unimplemented!() - } - - pub fn bitor(self, rhs: Self) -> Self { - unimplemented!() - } - - pub fn bitxor(self, rhs: Self) -> Self { - unimplemented!() - } - - pub fn borrow(&self) -> &str { - unimplemented!() - } - - pub fn borrow_mut(&mut self) -> &mut str { - unimplemented!() - } - - pub fn clone(&self) -> Self { - unimplemented!() - } - - pub fn cmp(&self, other: &Self) -> Self { - unimplemented!() - } - - pub fn default() -> Self { - unimplemented!() - } - - pub fn deref(&self) -> &Self { - unimplemented!() - } - - pub fn deref_mut(&mut self) -> &mut Self { - unimplemented!() - } - - pub fn div(self, rhs: Self) -> Self { - unimplemented!() - } - - pub fn drop(&mut self) { - unimplemented!() - } - // ********** - // part 1 end - // ********** -} diff --git a/tests/ui/should_impl_trait/method_list_1.stderr b/tests/ui/should_impl_trait/method_list_1.stderr deleted file mode 100644 index 2b7d4628c3fa..000000000000 --- a/tests/ui/should_impl_trait/method_list_1.stderr +++ /dev/null @@ -1,143 +0,0 @@ -error: method `add` can be confused for the standard trait method `std::ops::Add::add` - --> $DIR/method_list_1.rs:25:5 - | -LL | / pub fn add(self, other: T) -> T { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = note: `-D clippy::should-implement-trait` implied by `-D warnings` - = help: consider implementing the trait `std::ops::Add` or choosing a less ambiguous method name - -error: method `as_mut` can be confused for the standard trait method `std::convert::AsMut::as_mut` - --> $DIR/method_list_1.rs:29:5 - | -LL | / pub fn as_mut(&mut self) -> &mut T { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::convert::AsMut` or choosing a less ambiguous method name - -error: method `as_ref` can be confused for the standard trait method `std::convert::AsRef::as_ref` - --> $DIR/method_list_1.rs:33:5 - | -LL | / pub fn as_ref(&self) -> &T { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::convert::AsRef` or choosing a less ambiguous method name - -error: method `bitand` can be confused for the standard trait method `std::ops::BitAnd::bitand` - --> $DIR/method_list_1.rs:37:5 - | -LL | / pub fn bitand(self, rhs: T) -> T { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::ops::BitAnd` or choosing a less ambiguous method name - -error: method `bitor` can be confused for the standard trait method `std::ops::BitOr::bitor` - --> $DIR/method_list_1.rs:41:5 - | -LL | / pub fn bitor(self, rhs: Self) -> Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::ops::BitOr` or choosing a less ambiguous method name - -error: method `bitxor` can be confused for the standard trait method `std::ops::BitXor::bitxor` - --> $DIR/method_list_1.rs:45:5 - | -LL | / pub fn bitxor(self, rhs: Self) -> Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::ops::BitXor` or choosing a less ambiguous method name - -error: method `borrow` can be confused for the standard trait method `std::borrow::Borrow::borrow` - --> $DIR/method_list_1.rs:49:5 - | -LL | / pub fn borrow(&self) -> &str { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::borrow::Borrow` or choosing a less ambiguous method name - -error: method `borrow_mut` can be confused for the standard trait method `std::borrow::BorrowMut::borrow_mut` - --> $DIR/method_list_1.rs:53:5 - | -LL | / pub fn borrow_mut(&mut self) -> &mut str { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::borrow::BorrowMut` or choosing a less ambiguous method name - -error: method `clone` can be confused for the standard trait method `std::clone::Clone::clone` - --> $DIR/method_list_1.rs:57:5 - | -LL | / pub fn clone(&self) -> Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::clone::Clone` or choosing a less ambiguous method name - -error: method `cmp` can be confused for the standard trait method `std::cmp::Ord::cmp` - --> $DIR/method_list_1.rs:61:5 - | -LL | / pub fn cmp(&self, other: &Self) -> Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::cmp::Ord` or choosing a less ambiguous method name - -error: method `deref` can be confused for the standard trait method `std::ops::Deref::deref` - --> $DIR/method_list_1.rs:69:5 - | -LL | / pub fn deref(&self) -> &Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::ops::Deref` or choosing a less ambiguous method name - -error: method `deref_mut` can be confused for the standard trait method `std::ops::DerefMut::deref_mut` - --> $DIR/method_list_1.rs:73:5 - | -LL | / pub fn deref_mut(&mut self) -> &mut Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::ops::DerefMut` or choosing a less ambiguous method name - -error: method `div` can be confused for the standard trait method `std::ops::Div::div` - --> $DIR/method_list_1.rs:77:5 - | -LL | / pub fn div(self, rhs: Self) -> Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::ops::Div` or choosing a less ambiguous method name - -error: method `drop` can be confused for the standard trait method `std::ops::Drop::drop` - --> $DIR/method_list_1.rs:81:5 - | -LL | / pub fn drop(&mut self) { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::ops::Drop` or choosing a less ambiguous method name - -error: aborting due to 14 previous errors - diff --git a/tests/ui/should_impl_trait/method_list_2.rs b/tests/ui/should_impl_trait/method_list_2.rs deleted file mode 100644 index ed5e0d384bf5..000000000000 --- a/tests/ui/should_impl_trait/method_list_2.rs +++ /dev/null @@ -1,88 +0,0 @@ -// edition:2018 - -#![warn(clippy::all, clippy::pedantic)] -#![allow( - clippy::missing_errors_doc, - clippy::needless_pass_by_value, - clippy::must_use_candidate, - clippy::unused_self, - clippy::needless_lifetimes, - clippy::missing_safety_doc, - clippy::wrong_self_convention -)] - -use std::ops::Mul; -use std::rc::{self, Rc}; -use std::sync::{self, Arc}; - -fn main() {} -pub struct T; - -impl T { - // ***************************************** - // trait method list part 2, should lint all - // ***************************************** - - pub fn eq(&self, other: &Self) -> bool { - unimplemented!() - } - - pub fn from_iter(iter: T) -> Self { - unimplemented!() - } - - pub fn from_str(s: &str) -> Result { - unimplemented!() - } - - pub fn hash(&self, state: &mut T) { - unimplemented!() - } - - pub fn index(&self, index: usize) -> &Self { - unimplemented!() - } - - pub fn index_mut(&mut self, index: usize) -> &mut Self { - unimplemented!() - } - - pub fn into_iter(self) -> Self { - unimplemented!() - } - - pub fn mul(self, rhs: Self) -> Self { - unimplemented!() - } - - pub fn neg(self) -> Self { - unimplemented!() - } - - pub fn next(&mut self) -> Option { - unimplemented!() - } - - pub fn not(self) -> Self { - unimplemented!() - } - - pub fn rem(self, rhs: Self) -> Self { - unimplemented!() - } - - pub fn shl(self, rhs: Self) -> Self { - unimplemented!() - } - - pub fn shr(self, rhs: Self) -> Self { - unimplemented!() - } - - pub fn sub(self, rhs: Self) -> Self { - unimplemented!() - } - // ********** - // part 2 end - // ********** -} diff --git a/tests/ui/should_impl_trait/method_list_2.stderr b/tests/ui/should_impl_trait/method_list_2.stderr deleted file mode 100644 index b6fd43569569..000000000000 --- a/tests/ui/should_impl_trait/method_list_2.stderr +++ /dev/null @@ -1,153 +0,0 @@ -error: method `eq` can be confused for the standard trait method `std::cmp::PartialEq::eq` - --> $DIR/method_list_2.rs:26:5 - | -LL | / pub fn eq(&self, other: &Self) -> bool { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = note: `-D clippy::should-implement-trait` implied by `-D warnings` - = help: consider implementing the trait `std::cmp::PartialEq` or choosing a less ambiguous method name - -error: method `from_iter` can be confused for the standard trait method `std::iter::FromIterator::from_iter` - --> $DIR/method_list_2.rs:30:5 - | -LL | / pub fn from_iter(iter: T) -> Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::iter::FromIterator` or choosing a less ambiguous method name - -error: method `from_str` can be confused for the standard trait method `std::str::FromStr::from_str` - --> $DIR/method_list_2.rs:34:5 - | -LL | / pub fn from_str(s: &str) -> Result { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::str::FromStr` or choosing a less ambiguous method name - -error: method `hash` can be confused for the standard trait method `std::hash::Hash::hash` - --> $DIR/method_list_2.rs:38:5 - | -LL | / pub fn hash(&self, state: &mut T) { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::hash::Hash` or choosing a less ambiguous method name - -error: method `index` can be confused for the standard trait method `std::ops::Index::index` - --> $DIR/method_list_2.rs:42:5 - | -LL | / pub fn index(&self, index: usize) -> &Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::ops::Index` or choosing a less ambiguous method name - -error: method `index_mut` can be confused for the standard trait method `std::ops::IndexMut::index_mut` - --> $DIR/method_list_2.rs:46:5 - | -LL | / pub fn index_mut(&mut self, index: usize) -> &mut Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::ops::IndexMut` or choosing a less ambiguous method name - -error: method `into_iter` can be confused for the standard trait method `std::iter::IntoIterator::into_iter` - --> $DIR/method_list_2.rs:50:5 - | -LL | / pub fn into_iter(self) -> Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::iter::IntoIterator` or choosing a less ambiguous method name - -error: method `mul` can be confused for the standard trait method `std::ops::Mul::mul` - --> $DIR/method_list_2.rs:54:5 - | -LL | / pub fn mul(self, rhs: Self) -> Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::ops::Mul` or choosing a less ambiguous method name - -error: method `neg` can be confused for the standard trait method `std::ops::Neg::neg` - --> $DIR/method_list_2.rs:58:5 - | -LL | / pub fn neg(self) -> Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::ops::Neg` or choosing a less ambiguous method name - -error: method `next` can be confused for the standard trait method `std::iter::Iterator::next` - --> $DIR/method_list_2.rs:62:5 - | -LL | / pub fn next(&mut self) -> Option { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::iter::Iterator` or choosing a less ambiguous method name - -error: method `not` can be confused for the standard trait method `std::ops::Not::not` - --> $DIR/method_list_2.rs:66:5 - | -LL | / pub fn not(self) -> Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::ops::Not` or choosing a less ambiguous method name - -error: method `rem` can be confused for the standard trait method `std::ops::Rem::rem` - --> $DIR/method_list_2.rs:70:5 - | -LL | / pub fn rem(self, rhs: Self) -> Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::ops::Rem` or choosing a less ambiguous method name - -error: method `shl` can be confused for the standard trait method `std::ops::Shl::shl` - --> $DIR/method_list_2.rs:74:5 - | -LL | / pub fn shl(self, rhs: Self) -> Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::ops::Shl` or choosing a less ambiguous method name - -error: method `shr` can be confused for the standard trait method `std::ops::Shr::shr` - --> $DIR/method_list_2.rs:78:5 - | -LL | / pub fn shr(self, rhs: Self) -> Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::ops::Shr` or choosing a less ambiguous method name - -error: method `sub` can be confused for the standard trait method `std::ops::Sub::sub` - --> $DIR/method_list_2.rs:82:5 - | -LL | / pub fn sub(self, rhs: Self) -> Self { -LL | | unimplemented!() -LL | | } - | |_____^ - | - = help: consider implementing the trait `std::ops::Sub` or choosing a less ambiguous method name - -error: aborting due to 15 previous errors - diff --git a/tests/ui/similar_names.rs b/tests/ui/similar_names.rs deleted file mode 100644 index 6796b15289ec..000000000000 --- a/tests/ui/similar_names.rs +++ /dev/null @@ -1,103 +0,0 @@ -#![warn(clippy::similar_names)] -#![allow(unused, clippy::println_empty_string)] - -struct Foo { - apple: i32, - bpple: i32, -} - -fn main() { - let specter: i32; - let spectre: i32; - - let apple: i32; - - let bpple: i32; - - let cpple: i32; - - let a_bar: i32; - let b_bar: i32; - let c_bar: i32; - - let items = [5]; - for item in &items { - loop {} - } - - let foo_x: i32; - let foo_y: i32; - - let rhs: i32; - let lhs: i32; - - let bla_rhs: i32; - let bla_lhs: i32; - - let blubrhs: i32; - let blublhs: i32; - - let blubx: i32; - let bluby: i32; - - let cake: i32; - let cakes: i32; - let coke: i32; - - match 5 { - cheese @ 1 => {}, - rabbit => panic!(), - } - let cheese: i32; - match (42, 43) { - (cheese1, 1) => {}, - (cheese2, 2) => panic!(), - _ => println!(""), - } - let ipv4: i32; - let ipv6: i32; - let abcd1: i32; - let abdc2: i32; - let xyz1abc: i32; - let xyz2abc: i32; - let xyzeabc: i32; - - let parser: i32; - let parsed: i32; - let parsee: i32; - - let setter: i32; - let getter: i32; - let tx1: i32; - let rx1: i32; - let tx_cake: i32; - let rx_cake: i32; -} - -fn foo() { - let Foo { apple, bpple } = unimplemented!(); - let Foo { - apple: spring, - bpple: sprang, - } = unimplemented!(); -} - -// false positive similar_names (#3057, #2651) -// clippy claimed total_reg_src_size and total_size and -// numb_reg_src_checkouts and total_bin_size were similar -#[derive(Debug, Clone)] -pub(crate) struct DirSizes { - pub(crate) total_size: u64, - pub(crate) numb_bins: u64, - pub(crate) total_bin_size: u64, - pub(crate) total_reg_size: u64, - pub(crate) total_git_db_size: u64, - pub(crate) total_git_repos_bare_size: u64, - pub(crate) numb_git_repos_bare_repos: u64, - pub(crate) numb_git_checkouts: u64, - pub(crate) total_git_chk_size: u64, - pub(crate) total_reg_cache_size: u64, - pub(crate) total_reg_src_size: u64, - pub(crate) numb_reg_cache_entries: u64, - pub(crate) numb_reg_src_checkouts: u64, -} diff --git a/tests/ui/similar_names.stderr b/tests/ui/similar_names.stderr deleted file mode 100644 index 0256f126a94f..000000000000 --- a/tests/ui/similar_names.stderr +++ /dev/null @@ -1,107 +0,0 @@ -error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:15:9 - | -LL | let bpple: i32; - | ^^^^^ - | - = note: `-D clippy::similar-names` implied by `-D warnings` -note: existing binding defined here - --> $DIR/similar_names.rs:13:9 - | -LL | let apple: i32; - | ^^^^^ -help: separate the discriminating character by an underscore like: `b_pple` - --> $DIR/similar_names.rs:15:9 - | -LL | let bpple: i32; - | ^^^^^ - -error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:17:9 - | -LL | let cpple: i32; - | ^^^^^ - | -note: existing binding defined here - --> $DIR/similar_names.rs:13:9 - | -LL | let apple: i32; - | ^^^^^ -help: separate the discriminating character by an underscore like: `c_pple` - --> $DIR/similar_names.rs:17:9 - | -LL | let cpple: i32; - | ^^^^^ - -error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:41:9 - | -LL | let bluby: i32; - | ^^^^^ - | -note: existing binding defined here - --> $DIR/similar_names.rs:40:9 - | -LL | let blubx: i32; - | ^^^^^ -help: separate the discriminating character by an underscore like: `blub_y` - --> $DIR/similar_names.rs:41:9 - | -LL | let bluby: i32; - | ^^^^^ - -error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:45:9 - | -LL | let coke: i32; - | ^^^^ - | -note: existing binding defined here - --> $DIR/similar_names.rs:43:9 - | -LL | let cake: i32; - | ^^^^ - -error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:63:9 - | -LL | let xyzeabc: i32; - | ^^^^^^^ - | -note: existing binding defined here - --> $DIR/similar_names.rs:61:9 - | -LL | let xyz1abc: i32; - | ^^^^^^^ - -error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:67:9 - | -LL | let parsee: i32; - | ^^^^^^ - | -note: existing binding defined here - --> $DIR/similar_names.rs:65:9 - | -LL | let parser: i32; - | ^^^^^^ -help: separate the discriminating character by an underscore like: `parse_e` - --> $DIR/similar_names.rs:67:9 - | -LL | let parsee: i32; - | ^^^^^^ - -error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:81:16 - | -LL | bpple: sprang, - | ^^^^^^ - | -note: existing binding defined here - --> $DIR/similar_names.rs:80:16 - | -LL | apple: spring, - | ^^^^^^ - -error: aborting due to 7 previous errors - diff --git a/tests/ui/single_char_add_str.fixed b/tests/ui/single_char_add_str.fixed deleted file mode 100644 index 63a6d37a9cce..000000000000 --- a/tests/ui/single_char_add_str.fixed +++ /dev/null @@ -1,45 +0,0 @@ -// run-rustfix -#![warn(clippy::single_char_add_str)] - -macro_rules! get_string { - () => { - String::from("Hello world!") - }; -} - -fn main() { - // `push_str` tests - - let mut string = String::new(); - string.push('R'); - string.push('\''); - - string.push('u'); - string.push_str("st"); - string.push_str(""); - string.push('\x52'); - string.push('\u{0052}'); - string.push('a'); - - get_string!().push('ö'); - - // `insert_str` tests - - let mut string = String::new(); - string.insert(0, 'R'); - string.insert(1, '\''); - - string.insert(0, 'u'); - string.insert_str(2, "st"); - string.insert_str(0, ""); - string.insert(0, '\x52'); - string.insert(0, '\u{0052}'); - let x: usize = 2; - string.insert(x, 'a'); - const Y: usize = 1; - string.insert(Y, 'a'); - string.insert(Y, '"'); - string.insert(Y, '\''); - - get_string!().insert(1, '?'); -} diff --git a/tests/ui/single_char_add_str.rs b/tests/ui/single_char_add_str.rs deleted file mode 100644 index a799ea7d8856..000000000000 --- a/tests/ui/single_char_add_str.rs +++ /dev/null @@ -1,45 +0,0 @@ -// run-rustfix -#![warn(clippy::single_char_add_str)] - -macro_rules! get_string { - () => { - String::from("Hello world!") - }; -} - -fn main() { - // `push_str` tests - - let mut string = String::new(); - string.push_str("R"); - string.push_str("'"); - - string.push('u'); - string.push_str("st"); - string.push_str(""); - string.push_str("\x52"); - string.push_str("\u{0052}"); - string.push_str(r##"a"##); - - get_string!().push_str("ö"); - - // `insert_str` tests - - let mut string = String::new(); - string.insert_str(0, "R"); - string.insert_str(1, "'"); - - string.insert(0, 'u'); - string.insert_str(2, "st"); - string.insert_str(0, ""); - string.insert_str(0, "\x52"); - string.insert_str(0, "\u{0052}"); - let x: usize = 2; - string.insert_str(x, r##"a"##); - const Y: usize = 1; - string.insert_str(Y, r##"a"##); - string.insert_str(Y, r##"""##); - string.insert_str(Y, r##"'"##); - - get_string!().insert_str(1, "?"); -} diff --git a/tests/ui/single_char_add_str.stderr b/tests/ui/single_char_add_str.stderr deleted file mode 100644 index 55d91583ad04..000000000000 --- a/tests/ui/single_char_add_str.stderr +++ /dev/null @@ -1,94 +0,0 @@ -error: calling `push_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:14:5 - | -LL | string.push_str("R"); - | ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('R')` - | - = note: `-D clippy::single-char-add-str` implied by `-D warnings` - -error: calling `push_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:15:5 - | -LL | string.push_str("'"); - | ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('/'')` - -error: calling `push_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:20:5 - | -LL | string.push_str("/x52"); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('/x52')` - -error: calling `push_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:21:5 - | -LL | string.push_str("/u{0052}"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('/u{0052}')` - -error: calling `push_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:22:5 - | -LL | string.push_str(r##"a"##); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('a')` - -error: calling `push_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:24:5 - | -LL | get_string!().push_str("ö"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `get_string!().push('ö')` - -error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:29:5 - | -LL | string.insert_str(0, "R"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, 'R')` - -error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:30:5 - | -LL | string.insert_str(1, "'"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(1, '/'')` - -error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:35:5 - | -LL | string.insert_str(0, "/x52"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, '/x52')` - -error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:36:5 - | -LL | string.insert_str(0, "/u{0052}"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, '/u{0052}')` - -error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:38:5 - | -LL | string.insert_str(x, r##"a"##); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(x, 'a')` - -error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:40:5 - | -LL | string.insert_str(Y, r##"a"##); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, 'a')` - -error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:41:5 - | -LL | string.insert_str(Y, r##"""##); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, '"')` - -error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:42:5 - | -LL | string.insert_str(Y, r##"'"##); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, '/'')` - -error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:44:5 - | -LL | get_string!().insert_str(1, "?"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `get_string!().insert(1, '?')` - -error: aborting due to 15 previous errors - diff --git a/tests/ui/single_char_pattern.fixed b/tests/ui/single_char_pattern.fixed deleted file mode 100644 index d8b5f19e144d..000000000000 --- a/tests/ui/single_char_pattern.fixed +++ /dev/null @@ -1,57 +0,0 @@ -// run-rustfix - -#![allow(unused_must_use)] - -use std::collections::HashSet; - -fn main() { - let x = "foo"; - x.split('x'); - x.split("xx"); - x.split('x'); - - let y = "x"; - x.split(y); - x.split('ß'); - x.split('ℝ'); - x.split('💣'); - // Can't use this lint for unicode code points which don't fit in a char - x.split("❤️"); - x.contains('x'); - x.starts_with('x'); - x.ends_with('x'); - x.find('x'); - x.rfind('x'); - x.rsplit('x'); - x.split_terminator('x'); - x.rsplit_terminator('x'); - x.splitn(0, 'x'); - x.rsplitn(0, 'x'); - x.matches('x'); - x.rmatches('x'); - x.match_indices('x'); - x.rmatch_indices('x'); - x.trim_start_matches('x'); - x.trim_end_matches('x'); - // Make sure we escape characters correctly. - x.split('\n'); - x.split('\''); - x.split('\''); - - let h = HashSet::::new(); - h.contains("X"); // should not warn - - x.replace(";", ",").split(','); // issue #2978 - x.starts_with('\x03'); // issue #2996 - - // Issue #3204 - const S: &str = "#"; - x.find(S); - - // Raw string - x.split('a'); - x.split('a'); - x.split('a'); - x.split('\''); - x.split('#'); -} diff --git a/tests/ui/single_char_pattern.rs b/tests/ui/single_char_pattern.rs deleted file mode 100644 index a7bc73e3756d..000000000000 --- a/tests/ui/single_char_pattern.rs +++ /dev/null @@ -1,57 +0,0 @@ -// run-rustfix - -#![allow(unused_must_use)] - -use std::collections::HashSet; - -fn main() { - let x = "foo"; - x.split("x"); - x.split("xx"); - x.split('x'); - - let y = "x"; - x.split(y); - x.split("ß"); - x.split("ℝ"); - x.split("💣"); - // Can't use this lint for unicode code points which don't fit in a char - x.split("❤️"); - x.contains("x"); - x.starts_with("x"); - x.ends_with("x"); - x.find("x"); - x.rfind("x"); - x.rsplit("x"); - x.split_terminator("x"); - x.rsplit_terminator("x"); - x.splitn(0, "x"); - x.rsplitn(0, "x"); - x.matches("x"); - x.rmatches("x"); - x.match_indices("x"); - x.rmatch_indices("x"); - x.trim_start_matches("x"); - x.trim_end_matches("x"); - // Make sure we escape characters correctly. - x.split("\n"); - x.split("'"); - x.split("\'"); - - let h = HashSet::::new(); - h.contains("X"); // should not warn - - x.replace(";", ",").split(","); // issue #2978 - x.starts_with("\x03"); // issue #2996 - - // Issue #3204 - const S: &str = "#"; - x.find(S); - - // Raw string - x.split(r"a"); - x.split(r#"a"#); - x.split(r###"a"###); - x.split(r###"'"###); - x.split(r###"#"###); -} diff --git a/tests/ui/single_char_pattern.stderr b/tests/ui/single_char_pattern.stderr deleted file mode 100644 index ee4e7e50efd1..000000000000 --- a/tests/ui/single_char_pattern.stderr +++ /dev/null @@ -1,184 +0,0 @@ -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:9:13 - | -LL | x.split("x"); - | ^^^ help: try using a `char` instead: `'x'` - | - = note: `-D clippy::single-char-pattern` implied by `-D warnings` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:15:13 - | -LL | x.split("ß"); - | ^^^ help: try using a `char` instead: `'ß'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:16:13 - | -LL | x.split("ℝ"); - | ^^^ help: try using a `char` instead: `'ℝ'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:17:13 - | -LL | x.split("💣"); - | ^^^^ help: try using a `char` instead: `'💣'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:20:16 - | -LL | x.contains("x"); - | ^^^ help: try using a `char` instead: `'x'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:21:19 - | -LL | x.starts_with("x"); - | ^^^ help: try using a `char` instead: `'x'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:22:17 - | -LL | x.ends_with("x"); - | ^^^ help: try using a `char` instead: `'x'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:23:12 - | -LL | x.find("x"); - | ^^^ help: try using a `char` instead: `'x'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:24:13 - | -LL | x.rfind("x"); - | ^^^ help: try using a `char` instead: `'x'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:25:14 - | -LL | x.rsplit("x"); - | ^^^ help: try using a `char` instead: `'x'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:26:24 - | -LL | x.split_terminator("x"); - | ^^^ help: try using a `char` instead: `'x'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:27:25 - | -LL | x.rsplit_terminator("x"); - | ^^^ help: try using a `char` instead: `'x'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:28:17 - | -LL | x.splitn(0, "x"); - | ^^^ help: try using a `char` instead: `'x'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:29:18 - | -LL | x.rsplitn(0, "x"); - | ^^^ help: try using a `char` instead: `'x'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:30:15 - | -LL | x.matches("x"); - | ^^^ help: try using a `char` instead: `'x'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:31:16 - | -LL | x.rmatches("x"); - | ^^^ help: try using a `char` instead: `'x'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:32:21 - | -LL | x.match_indices("x"); - | ^^^ help: try using a `char` instead: `'x'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:33:22 - | -LL | x.rmatch_indices("x"); - | ^^^ help: try using a `char` instead: `'x'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:34:26 - | -LL | x.trim_start_matches("x"); - | ^^^ help: try using a `char` instead: `'x'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:35:24 - | -LL | x.trim_end_matches("x"); - | ^^^ help: try using a `char` instead: `'x'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:37:13 - | -LL | x.split("/n"); - | ^^^^ help: try using a `char` instead: `'/n'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:38:13 - | -LL | x.split("'"); - | ^^^ help: try using a `char` instead: `'/''` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:39:13 - | -LL | x.split("/'"); - | ^^^^ help: try using a `char` instead: `'/''` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:44:31 - | -LL | x.replace(";", ",").split(","); // issue #2978 - | ^^^ help: try using a `char` instead: `','` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:45:19 - | -LL | x.starts_with("/x03"); // issue #2996 - | ^^^^^^ help: try using a `char` instead: `'/x03'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:52:13 - | -LL | x.split(r"a"); - | ^^^^ help: try using a `char` instead: `'a'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:53:13 - | -LL | x.split(r#"a"#); - | ^^^^^^ help: try using a `char` instead: `'a'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:54:13 - | -LL | x.split(r###"a"###); - | ^^^^^^^^^^ help: try using a `char` instead: `'a'` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:55:13 - | -LL | x.split(r###"'"###); - | ^^^^^^^^^^ help: try using a `char` instead: `'/''` - -error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:56:13 - | -LL | x.split(r###"#"###); - | ^^^^^^^^^^ help: try using a `char` instead: `'#'` - -error: aborting due to 30 previous errors - diff --git a/tests/ui/single_component_path_imports.fixed b/tests/ui/single_component_path_imports.fixed deleted file mode 100644 index a7a8499b58f0..000000000000 --- a/tests/ui/single_component_path_imports.fixed +++ /dev/null @@ -1,21 +0,0 @@ -// run-rustfix -// edition:2018 -#![warn(clippy::single_component_path_imports)] -#![allow(unused_imports)] - - -use serde as edres; -pub use serde; - -macro_rules! m { - () => { - use regex; - }; -} - -fn main() { - regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap(); - - // False positive #5154, shouldn't trigger lint. - m!(); -} diff --git a/tests/ui/single_component_path_imports.rs b/tests/ui/single_component_path_imports.rs deleted file mode 100644 index 9a427e90ad3d..000000000000 --- a/tests/ui/single_component_path_imports.rs +++ /dev/null @@ -1,21 +0,0 @@ -// run-rustfix -// edition:2018 -#![warn(clippy::single_component_path_imports)] -#![allow(unused_imports)] - -use regex; -use serde as edres; -pub use serde; - -macro_rules! m { - () => { - use regex; - }; -} - -fn main() { - regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap(); - - // False positive #5154, shouldn't trigger lint. - m!(); -} diff --git a/tests/ui/single_component_path_imports.stderr b/tests/ui/single_component_path_imports.stderr deleted file mode 100644 index 519ada0169a6..000000000000 --- a/tests/ui/single_component_path_imports.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: this import is redundant - --> $DIR/single_component_path_imports.rs:6:1 - | -LL | use regex; - | ^^^^^^^^^^ help: remove it entirely - | - = note: `-D clippy::single-component-path-imports` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/single_element_loop.fixed b/tests/ui/single_element_loop.fixed deleted file mode 100644 index 8ca068293a61..000000000000 --- a/tests/ui/single_element_loop.fixed +++ /dev/null @@ -1,11 +0,0 @@ -// run-rustfix -// Tests from for_loop.rs that don't have suggestions - -#[warn(clippy::single_element_loop)] -fn main() { - let item1 = 2; - { - let item = &item1; - println!("{}", item); - } -} diff --git a/tests/ui/single_element_loop.rs b/tests/ui/single_element_loop.rs deleted file mode 100644 index 57e9336a31fc..000000000000 --- a/tests/ui/single_element_loop.rs +++ /dev/null @@ -1,10 +0,0 @@ -// run-rustfix -// Tests from for_loop.rs that don't have suggestions - -#[warn(clippy::single_element_loop)] -fn main() { - let item1 = 2; - for item in &[item1] { - println!("{}", item); - } -} diff --git a/tests/ui/single_element_loop.stderr b/tests/ui/single_element_loop.stderr deleted file mode 100644 index 90be1dc32837..000000000000 --- a/tests/ui/single_element_loop.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: for loop over a single element - --> $DIR/single_element_loop.rs:7:5 - | -LL | / for item in &[item1] { -LL | | println!("{}", item); -LL | | } - | |_____^ - | - = note: `-D clippy::single-element-loop` implied by `-D warnings` -help: try - | -LL | { -LL | let item = &item1; -LL | println!("{}", item); -LL | } - | - -error: aborting due to previous error - diff --git a/tests/ui/single_match.rs b/tests/ui/single_match.rs deleted file mode 100644 index 1c55af5dfb67..000000000000 --- a/tests/ui/single_match.rs +++ /dev/null @@ -1,95 +0,0 @@ -#![warn(clippy::single_match)] - -fn dummy() {} - -fn single_match() { - let x = Some(1u8); - - match x { - Some(y) => { - println!("{:?}", y); - }, - _ => (), - }; - - let x = Some(1u8); - match x { - // Note the missing block braces. - // We suggest `if let Some(y) = x { .. }` because the macro - // is expanded before we can do anything. - Some(y) => println!("{:?}", y), - _ => (), - } - - let z = (1u8, 1u8); - match z { - (2..=3, 7..=9) => dummy(), - _ => {}, - }; - - // Not linted (pattern guards used) - match x { - Some(y) if y == 0 => println!("{:?}", y), - _ => (), - } - - // Not linted (no block with statements in the single arm) - match z { - (2..=3, 7..=9) => println!("{:?}", z), - _ => println!("nope"), - } -} - -enum Foo { - Bar, - Baz(u8), -} -use std::borrow::Cow; -use Foo::*; - -fn single_match_know_enum() { - let x = Some(1u8); - let y: Result<_, i8> = Ok(1i8); - - match x { - Some(y) => dummy(), - None => (), - }; - - match y { - Ok(y) => dummy(), - Err(..) => (), - }; - - let c = Cow::Borrowed(""); - - match c { - Cow::Borrowed(..) => dummy(), - Cow::Owned(..) => (), - }; - - let z = Foo::Bar; - // no warning - match z { - Bar => println!("42"), - Baz(_) => (), - } - - match z { - Baz(_) => println!("42"), - Bar => (), - } -} - -macro_rules! single_match { - ($num:literal) => { - match $num { - 15 => println!("15"), - _ => (), - } - }; -} - -fn main() { - single_match!(5); -} diff --git a/tests/ui/single_match.stderr b/tests/ui/single_match.stderr deleted file mode 100644 index f69554d75f9b..000000000000 --- a/tests/ui/single_match.stderr +++ /dev/null @@ -1,69 +0,0 @@ -error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:8:5 - | -LL | / match x { -LL | | Some(y) => { -LL | | println!("{:?}", y); -LL | | }, -LL | | _ => (), -LL | | }; - | |_____^ - | - = note: `-D clippy::single-match` implied by `-D warnings` -help: try this - | -LL | if let Some(y) = x { -LL | println!("{:?}", y); -LL | }; - | - -error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:16:5 - | -LL | / match x { -LL | | // Note the missing block braces. -LL | | // We suggest `if let Some(y) = x { .. }` because the macro -LL | | // is expanded before we can do anything. -LL | | Some(y) => println!("{:?}", y), -LL | | _ => (), -LL | | } - | |_____^ help: try this: `if let Some(y) = x { println!("{:?}", y) }` - -error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:25:5 - | -LL | / match z { -LL | | (2..=3, 7..=9) => dummy(), -LL | | _ => {}, -LL | | }; - | |_____^ help: try this: `if let (2..=3, 7..=9) = z { dummy() }` - -error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:54:5 - | -LL | / match x { -LL | | Some(y) => dummy(), -LL | | None => (), -LL | | }; - | |_____^ help: try this: `if let Some(y) = x { dummy() }` - -error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:59:5 - | -LL | / match y { -LL | | Ok(y) => dummy(), -LL | | Err(..) => (), -LL | | }; - | |_____^ help: try this: `if let Ok(y) = y { dummy() }` - -error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:66:5 - | -LL | / match c { -LL | | Cow::Borrowed(..) => dummy(), -LL | | Cow::Owned(..) => (), -LL | | }; - | |_____^ help: try this: `if let Cow::Borrowed(..) = c { dummy() }` - -error: aborting due to 6 previous errors - diff --git a/tests/ui/single_match_else.rs b/tests/ui/single_match_else.rs deleted file mode 100644 index b624a41a29b2..000000000000 --- a/tests/ui/single_match_else.rs +++ /dev/null @@ -1,86 +0,0 @@ -#![warn(clippy::single_match_else)] -#![allow(clippy::needless_return)] -#![allow(clippy::no_effect)] - -enum ExprNode { - ExprAddrOf, - Butterflies, - Unicorns, -} - -static NODE: ExprNode = ExprNode::Unicorns; - -fn unwrap_addr() -> Option<&'static ExprNode> { - match ExprNode::Butterflies { - ExprNode::ExprAddrOf => Some(&NODE), - _ => { - let x = 5; - None - }, - } -} - -macro_rules! unwrap_addr { - ($expression:expr) => { - match $expression { - ExprNode::ExprAddrOf => Some(&NODE), - _ => { - let x = 5; - None - }, - } - }; -} - -#[rustfmt::skip] -fn main() { - unwrap_addr!(ExprNode::Unicorns); - - // - // don't lint single exprs/statements - // - - // don't lint here - match Some(1) { - Some(a) => println!("${:?}", a), - None => return, - } - - // don't lint here - match Some(1) { - Some(a) => println!("${:?}", a), - None => { - return - }, - } - - // don't lint here - match Some(1) { - Some(a) => println!("${:?}", a), - None => { - return; - }, - } - - // - // lint multiple exprs/statements "else" blocks - // - - // lint here - match Some(1) { - Some(a) => println!("${:?}", a), - None => { - println!("else block"); - return - }, - } - - // lint here - match Some(1) { - Some(a) => println!("${:?}", a), - None => { - println!("else block"); - return; - }, - } -} diff --git a/tests/ui/single_match_else.stderr b/tests/ui/single_match_else.stderr deleted file mode 100644 index 3a07c2ec5426..000000000000 --- a/tests/ui/single_match_else.stderr +++ /dev/null @@ -1,63 +0,0 @@ -error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:14:5 - | -LL | / match ExprNode::Butterflies { -LL | | ExprNode::ExprAddrOf => Some(&NODE), -LL | | _ => { -LL | | let x = 5; -LL | | None -LL | | }, -LL | | } - | |_____^ - | - = note: `-D clippy::single-match-else` implied by `-D warnings` -help: try this - | -LL | if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { -LL | let x = 5; -LL | None -LL | } - | - -error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:70:5 - | -LL | / match Some(1) { -LL | | Some(a) => println!("${:?}", a), -LL | | None => { -LL | | println!("else block"); -LL | | return -LL | | }, -LL | | } - | |_____^ - | -help: try this - | -LL | if let Some(a) = Some(1) { println!("${:?}", a) } else { -LL | println!("else block"); -LL | return -LL | } - | - -error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:79:5 - | -LL | / match Some(1) { -LL | | Some(a) => println!("${:?}", a), -LL | | None => { -LL | | println!("else block"); -LL | | return; -LL | | }, -LL | | } - | |_____^ - | -help: try this - | -LL | if let Some(a) = Some(1) { println!("${:?}", a) } else { -LL | println!("else block"); -LL | return; -LL | } - | - -error: aborting due to 3 previous errors - diff --git a/tests/ui/size_of_in_element_count.rs b/tests/ui/size_of_in_element_count.rs deleted file mode 100644 index b13e390705ab..000000000000 --- a/tests/ui/size_of_in_element_count.rs +++ /dev/null @@ -1,61 +0,0 @@ -#![warn(clippy::size_of_in_element_count)] -#![allow(clippy::ptr_offset_with_cast)] - -use std::mem::{size_of, size_of_val}; -use std::ptr::{ - copy, copy_nonoverlapping, slice_from_raw_parts, slice_from_raw_parts_mut, swap_nonoverlapping, write_bytes, -}; -use std::slice::{from_raw_parts, from_raw_parts_mut}; - -fn main() { - const SIZE: usize = 128; - const HALF_SIZE: usize = SIZE / 2; - const DOUBLE_SIZE: usize = SIZE * 2; - let mut x = [2u8; SIZE]; - let mut y = [2u8; SIZE]; - - // Count is size_of (Should trigger the lint) - unsafe { copy_nonoverlapping::(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; - unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; - - unsafe { x.as_ptr().copy_to(y.as_mut_ptr(), size_of::()) }; - unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of::()) }; - unsafe { y.as_mut_ptr().copy_from(x.as_ptr(), size_of::()) }; - unsafe { y.as_mut_ptr().copy_from_nonoverlapping(x.as_ptr(), size_of::()) }; - - unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; - unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; - - unsafe { y.as_mut_ptr().write_bytes(0u8, size_of::() * SIZE) }; - unsafe { write_bytes(y.as_mut_ptr(), 0u8, size_of::() * SIZE) }; - - unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), size_of::() * SIZE) }; - - slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE); - slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); - - unsafe { from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE) }; - unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; - - unsafe { y.as_mut_ptr().sub(size_of::()) }; - y.as_ptr().wrapping_sub(size_of::()); - unsafe { y.as_ptr().add(size_of::()) }; - y.as_mut_ptr().wrapping_add(size_of::()); - unsafe { y.as_ptr().offset(size_of::() as isize) }; - y.as_mut_ptr().wrapping_offset(size_of::() as isize); - - // Count expression involving multiplication of size_of (Should trigger the lint) - unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::() * SIZE) }; - - // Count expression involving nested multiplications of size_of (Should trigger the lint) - unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * size_of_val(&x[0]) * 2) }; - - // Count expression involving divisions of size_of (Should trigger the lint) - unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::() / 2) }; - - // No size_of calls (Should not trigger the lint) - unsafe { copy(x.as_ptr(), y.as_mut_ptr(), SIZE) }; - - // Different types for pointee and size_of (Should not trigger the lint) - unsafe { y.as_mut_ptr().write_bytes(0u8, size_of::() / 2 * SIZE) }; -} diff --git a/tests/ui/size_of_in_element_count.stderr b/tests/ui/size_of_in_element_count.stderr deleted file mode 100644 index 8cf3612abda3..000000000000 --- a/tests/ui/size_of_in_element_count.stderr +++ /dev/null @@ -1,195 +0,0 @@ -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:18:68 - | -LL | unsafe { copy_nonoverlapping::(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; - | ^^^^^^^^^^^^^^^ - | - = note: `-D clippy::size-of-in-element-count` implied by `-D warnings` - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:19:62 - | -LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; - | ^^^^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:21:49 - | -LL | unsafe { x.as_ptr().copy_to(y.as_mut_ptr(), size_of::()) }; - | ^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:22:64 - | -LL | unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of::()) }; - | ^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:23:51 - | -LL | unsafe { y.as_mut_ptr().copy_from(x.as_ptr(), size_of::()) }; - | ^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:24:66 - | -LL | unsafe { y.as_mut_ptr().copy_from_nonoverlapping(x.as_ptr(), size_of::()) }; - | ^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:26:47 - | -LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; - | ^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:27:47 - | -LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; - | ^^^^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:29:46 - | -LL | unsafe { y.as_mut_ptr().write_bytes(0u8, size_of::() * SIZE) }; - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:30:47 - | -LL | unsafe { write_bytes(y.as_mut_ptr(), 0u8, size_of::() * SIZE) }; - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:32:66 - | -LL | unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), size_of::() * SIZE) }; - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:34:46 - | -LL | slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:35:38 - | -LL | slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:37:49 - | -LL | unsafe { from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE) }; - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:38:41 - | -LL | unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:40:33 - | -LL | unsafe { y.as_mut_ptr().sub(size_of::()) }; - | ^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:41:29 - | -LL | y.as_ptr().wrapping_sub(size_of::()); - | ^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:42:29 - | -LL | unsafe { y.as_ptr().add(size_of::()) }; - | ^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:43:33 - | -LL | y.as_mut_ptr().wrapping_add(size_of::()); - | ^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:44:32 - | -LL | unsafe { y.as_ptr().offset(size_of::() as isize) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:45:36 - | -LL | y.as_mut_ptr().wrapping_offset(size_of::() as isize); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:48:62 - | -LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::() * SIZE) }; - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:51:62 - | -LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * size_of_val(&x[0]) * 2) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: found a count of bytes instead of a count of elements of `T` - --> $DIR/size_of_in_element_count.rs:54:47 - | -LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::() / 2) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type - -error: aborting due to 24 previous errors - diff --git a/tests/ui/skip_while_next.rs b/tests/ui/skip_while_next.rs deleted file mode 100644 index a522c0f08b20..000000000000 --- a/tests/ui/skip_while_next.rs +++ /dev/null @@ -1,29 +0,0 @@ -// aux-build:option_helpers.rs - -#![warn(clippy::skip_while_next)] -#![allow(clippy::blacklisted_name)] - -extern crate option_helpers; -use option_helpers::IteratorFalsePositives; - -#[rustfmt::skip] -fn skip_while_next() { - let v = vec![3, 2, 1, 0, -1, -2, -3]; - - // Single-line case. - let _ = v.iter().skip_while(|&x| *x < 0).next(); - - // Multi-line case. - let _ = v.iter().skip_while(|&x| { - *x < 0 - } - ).next(); - - // Check that hat we don't lint if the caller is not an `Iterator`. - let foo = IteratorFalsePositives { foo: 0 }; - let _ = foo.skip_while().next(); -} - -fn main() { - skip_while_next(); -} diff --git a/tests/ui/skip_while_next.stderr b/tests/ui/skip_while_next.stderr deleted file mode 100644 index 269cc13468bc..000000000000 --- a/tests/ui/skip_while_next.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error: called `skip_while(

).next()` on an `Iterator` - --> $DIR/skip_while_next.rs:14:13 - | -LL | let _ = v.iter().skip_while(|&x| *x < 0).next(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::skip-while-next` implied by `-D warnings` - = help: this is more succinctly expressed by calling `.find(!

)` instead - -error: called `skip_while(

).next()` on an `Iterator` - --> $DIR/skip_while_next.rs:17:13 - | -LL | let _ = v.iter().skip_while(|&x| { - | _____________^ -LL | | *x < 0 -LL | | } -LL | | ).next(); - | |___________________________^ - | - = help: this is more succinctly expressed by calling `.find(!

)` instead - -error: aborting due to 2 previous errors - diff --git a/tests/ui/slow_vector_initialization.rs b/tests/ui/slow_vector_initialization.rs deleted file mode 100644 index c5ae3ff769b1..000000000000 --- a/tests/ui/slow_vector_initialization.rs +++ /dev/null @@ -1,63 +0,0 @@ -use std::iter::repeat; - -fn main() { - resize_vector(); - extend_vector(); - mixed_extend_resize_vector(); -} - -fn extend_vector() { - // Extend with constant expression - let len = 300; - let mut vec1 = Vec::with_capacity(len); - vec1.extend(repeat(0).take(len)); - - // Extend with len expression - let mut vec2 = Vec::with_capacity(len - 10); - vec2.extend(repeat(0).take(len - 10)); - - // Extend with mismatching expression should not be warned - let mut vec3 = Vec::with_capacity(24322); - vec3.extend(repeat(0).take(2)); -} - -fn mixed_extend_resize_vector() { - // Mismatching len - let mut mismatching_len = Vec::with_capacity(30); - mismatching_len.extend(repeat(0).take(40)); - - // Slow initialization - let mut resized_vec = Vec::with_capacity(30); - resized_vec.resize(30, 0); - - let mut extend_vec = Vec::with_capacity(30); - extend_vec.extend(repeat(0).take(30)); -} - -fn resize_vector() { - // Resize with constant expression - let len = 300; - let mut vec1 = Vec::with_capacity(len); - vec1.resize(len, 0); - - // Resize mismatch len - let mut vec2 = Vec::with_capacity(200); - vec2.resize(10, 0); - - // Resize with len expression - let mut vec3 = Vec::with_capacity(len - 10); - vec3.resize(len - 10, 0); - - // Reinitialization should be warned - vec1 = Vec::with_capacity(10); - vec1.resize(10, 0); -} - -fn do_stuff(vec: &mut Vec) {} - -fn extend_vector_with_manipulations_between() { - let len = 300; - let mut vec1: Vec = Vec::with_capacity(len); - do_stuff(&mut vec1); - vec1.extend(repeat(0).take(len)); -} diff --git a/tests/ui/slow_vector_initialization.stderr b/tests/ui/slow_vector_initialization.stderr deleted file mode 100644 index 5d2788ec2608..000000000000 --- a/tests/ui/slow_vector_initialization.stderr +++ /dev/null @@ -1,60 +0,0 @@ -error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:13:5 - | -LL | let mut vec1 = Vec::with_capacity(len); - | ----------------------- help: consider replace allocation with: `vec![0; len]` -LL | vec1.extend(repeat(0).take(len)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::slow-vector-initialization` implied by `-D warnings` - -error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:17:5 - | -LL | let mut vec2 = Vec::with_capacity(len - 10); - | ---------------------------- help: consider replace allocation with: `vec![0; len - 10]` -LL | vec2.extend(repeat(0).take(len - 10)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:31:5 - | -LL | let mut resized_vec = Vec::with_capacity(30); - | ---------------------- help: consider replace allocation with: `vec![0; 30]` -LL | resized_vec.resize(30, 0); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:34:5 - | -LL | let mut extend_vec = Vec::with_capacity(30); - | ---------------------- help: consider replace allocation with: `vec![0; 30]` -LL | extend_vec.extend(repeat(0).take(30)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:41:5 - | -LL | let mut vec1 = Vec::with_capacity(len); - | ----------------------- help: consider replace allocation with: `vec![0; len]` -LL | vec1.resize(len, 0); - | ^^^^^^^^^^^^^^^^^^^ - -error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:49:5 - | -LL | let mut vec3 = Vec::with_capacity(len - 10); - | ---------------------------- help: consider replace allocation with: `vec![0; len - 10]` -LL | vec3.resize(len - 10, 0); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:53:5 - | -LL | vec1 = Vec::with_capacity(10); - | ---------------------- help: consider replace allocation with: `vec![0; 10]` -LL | vec1.resize(10, 0); - | ^^^^^^^^^^^^^^^^^^ - -error: aborting due to 7 previous errors - diff --git a/tests/ui/stable_sort_primitive.fixed b/tests/ui/stable_sort_primitive.fixed deleted file mode 100644 index 8f8f56659315..000000000000 --- a/tests/ui/stable_sort_primitive.fixed +++ /dev/null @@ -1,32 +0,0 @@ -// run-rustfix -#![warn(clippy::stable_sort_primitive)] - -fn main() { - // positive examples - let mut vec = vec![1, 3, 2]; - vec.sort_unstable(); - let mut vec = vec![false, false, true]; - vec.sort_unstable(); - let mut vec = vec!['a', 'A', 'c']; - vec.sort_unstable(); - let mut vec = vec!["ab", "cd", "ab", "bc"]; - vec.sort_unstable(); - let mut vec = vec![(2, 1), (1, 2), (2, 5)]; - vec.sort_unstable(); - let mut vec = vec![[2, 1], [1, 2], [2, 5]]; - vec.sort_unstable(); - let mut arr = [1, 3, 2]; - arr.sort_unstable(); - // Negative examples: behavior changes if made unstable - let mut vec = vec![1, 3, 2]; - vec.sort_by_key(|i| i / 2); - vec.sort_by(|a, b| (a + b).cmp(&b)); - // negative examples - Not of a primitive type - let mut vec_of_complex = vec![String::from("hello"), String::from("world!")]; - vec_of_complex.sort(); - vec_of_complex.sort_by_key(String::len); - let mut vec = vec![(String::from("hello"), String::from("world"))]; - vec.sort(); - let mut vec = vec![[String::from("hello"), String::from("world")]]; - vec.sort(); -} diff --git a/tests/ui/stable_sort_primitive.rs b/tests/ui/stable_sort_primitive.rs deleted file mode 100644 index f9bd97790671..000000000000 --- a/tests/ui/stable_sort_primitive.rs +++ /dev/null @@ -1,32 +0,0 @@ -// run-rustfix -#![warn(clippy::stable_sort_primitive)] - -fn main() { - // positive examples - let mut vec = vec![1, 3, 2]; - vec.sort(); - let mut vec = vec![false, false, true]; - vec.sort(); - let mut vec = vec!['a', 'A', 'c']; - vec.sort(); - let mut vec = vec!["ab", "cd", "ab", "bc"]; - vec.sort(); - let mut vec = vec![(2, 1), (1, 2), (2, 5)]; - vec.sort(); - let mut vec = vec![[2, 1], [1, 2], [2, 5]]; - vec.sort(); - let mut arr = [1, 3, 2]; - arr.sort(); - // Negative examples: behavior changes if made unstable - let mut vec = vec![1, 3, 2]; - vec.sort_by_key(|i| i / 2); - vec.sort_by(|a, b| (a + b).cmp(&b)); - // negative examples - Not of a primitive type - let mut vec_of_complex = vec![String::from("hello"), String::from("world!")]; - vec_of_complex.sort(); - vec_of_complex.sort_by_key(String::len); - let mut vec = vec![(String::from("hello"), String::from("world"))]; - vec.sort(); - let mut vec = vec![[String::from("hello"), String::from("world")]]; - vec.sort(); -} diff --git a/tests/ui/stable_sort_primitive.stderr b/tests/ui/stable_sort_primitive.stderr deleted file mode 100644 index 780389f32bc1..000000000000 --- a/tests/ui/stable_sort_primitive.stderr +++ /dev/null @@ -1,46 +0,0 @@ -error: used sort instead of sort_unstable to sort primitive type `i32` - --> $DIR/stable_sort_primitive.rs:7:5 - | -LL | vec.sort(); - | ^^^^^^^^^^ help: try: `vec.sort_unstable()` - | - = note: `-D clippy::stable-sort-primitive` implied by `-D warnings` - -error: used sort instead of sort_unstable to sort primitive type `bool` - --> $DIR/stable_sort_primitive.rs:9:5 - | -LL | vec.sort(); - | ^^^^^^^^^^ help: try: `vec.sort_unstable()` - -error: used sort instead of sort_unstable to sort primitive type `char` - --> $DIR/stable_sort_primitive.rs:11:5 - | -LL | vec.sort(); - | ^^^^^^^^^^ help: try: `vec.sort_unstable()` - -error: used sort instead of sort_unstable to sort primitive type `str` - --> $DIR/stable_sort_primitive.rs:13:5 - | -LL | vec.sort(); - | ^^^^^^^^^^ help: try: `vec.sort_unstable()` - -error: used sort instead of sort_unstable to sort primitive type `tuple` - --> $DIR/stable_sort_primitive.rs:15:5 - | -LL | vec.sort(); - | ^^^^^^^^^^ help: try: `vec.sort_unstable()` - -error: used sort instead of sort_unstable to sort primitive type `array` - --> $DIR/stable_sort_primitive.rs:17:5 - | -LL | vec.sort(); - | ^^^^^^^^^^ help: try: `vec.sort_unstable()` - -error: used sort instead of sort_unstable to sort primitive type `i32` - --> $DIR/stable_sort_primitive.rs:19:5 - | -LL | arr.sort(); - | ^^^^^^^^^^ help: try: `arr.sort_unstable()` - -error: aborting due to 7 previous errors - diff --git a/tests/ui/starts_ends_with.fixed b/tests/ui/starts_ends_with.fixed deleted file mode 100644 index 7dfcf9c91e48..000000000000 --- a/tests/ui/starts_ends_with.fixed +++ /dev/null @@ -1,46 +0,0 @@ -// run-rustfix -#![allow(dead_code, unused_must_use)] - -fn main() {} - -#[allow(clippy::unnecessary_operation)] -fn starts_with() { - "".starts_with(' '); - !"".starts_with(' '); -} - -fn chars_cmp_with_unwrap() { - let s = String::from("foo"); - if s.starts_with('f') { - // s.starts_with('f') - // Nothing here - } - if s.ends_with('o') { - // s.ends_with('o') - // Nothing here - } - if s.ends_with('o') { - // s.ends_with('o') - // Nothing here - } - if !s.starts_with('f') { - // !s.starts_with('f') - // Nothing here - } - if !s.ends_with('o') { - // !s.ends_with('o') - // Nothing here - } - if !s.ends_with('o') { - // !s.ends_with('o') - // Nothing here - } -} - -#[allow(clippy::unnecessary_operation)] -fn ends_with() { - "".ends_with(' '); - !"".ends_with(' '); - "".ends_with(' '); - !"".ends_with(' '); -} diff --git a/tests/ui/starts_ends_with.rs b/tests/ui/starts_ends_with.rs deleted file mode 100644 index e48a42463543..000000000000 --- a/tests/ui/starts_ends_with.rs +++ /dev/null @@ -1,46 +0,0 @@ -// run-rustfix -#![allow(dead_code, unused_must_use)] - -fn main() {} - -#[allow(clippy::unnecessary_operation)] -fn starts_with() { - "".chars().next() == Some(' '); - Some(' ') != "".chars().next(); -} - -fn chars_cmp_with_unwrap() { - let s = String::from("foo"); - if s.chars().next().unwrap() == 'f' { - // s.starts_with('f') - // Nothing here - } - if s.chars().next_back().unwrap() == 'o' { - // s.ends_with('o') - // Nothing here - } - if s.chars().last().unwrap() == 'o' { - // s.ends_with('o') - // Nothing here - } - if s.chars().next().unwrap() != 'f' { - // !s.starts_with('f') - // Nothing here - } - if s.chars().next_back().unwrap() != 'o' { - // !s.ends_with('o') - // Nothing here - } - if s.chars().last().unwrap() != 'o' { - // !s.ends_with('o') - // Nothing here - } -} - -#[allow(clippy::unnecessary_operation)] -fn ends_with() { - "".chars().last() == Some(' '); - Some(' ') != "".chars().last(); - "".chars().next_back() == Some(' '); - Some(' ') != "".chars().next_back(); -} diff --git a/tests/ui/starts_ends_with.stderr b/tests/ui/starts_ends_with.stderr deleted file mode 100644 index 7c726d0e0102..000000000000 --- a/tests/ui/starts_ends_with.stderr +++ /dev/null @@ -1,78 +0,0 @@ -error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:8:5 - | -LL | "".chars().next() == Some(' '); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".starts_with(' ')` - | - = note: `-D clippy::chars-next-cmp` implied by `-D warnings` - -error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:9:5 - | -LL | Some(' ') != "".chars().next(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".starts_with(' ')` - -error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:14:8 - | -LL | if s.chars().next().unwrap() == 'f' { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.starts_with('f')` - -error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:18:8 - | -LL | if s.chars().next_back().unwrap() == 'o' { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')` - | - = note: `-D clippy::chars-last-cmp` implied by `-D warnings` - -error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:22:8 - | -LL | if s.chars().last().unwrap() == 'o' { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')` - -error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:26:8 - | -LL | if s.chars().next().unwrap() != 'f' { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.starts_with('f')` - -error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:30:8 - | -LL | if s.chars().next_back().unwrap() != 'o' { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('o')` - -error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:34:8 - | -LL | if s.chars().last().unwrap() != 'o' { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('o')` - -error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:42:5 - | -LL | "".chars().last() == Some(' '); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')` - -error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:43:5 - | -LL | Some(' ') != "".chars().last(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')` - -error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:44:5 - | -LL | "".chars().next_back() == Some(' '); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')` - -error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:45:5 - | -LL | Some(' ') != "".chars().next_back(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')` - -error: aborting due to 12 previous errors - diff --git a/tests/ui/str_to_string.rs b/tests/ui/str_to_string.rs deleted file mode 100644 index 08f734025181..000000000000 --- a/tests/ui/str_to_string.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![warn(clippy::str_to_string)] - -fn main() { - let hello = "hello world".to_string(); - let msg = &hello[..]; - msg.to_string(); -} diff --git a/tests/ui/str_to_string.stderr b/tests/ui/str_to_string.stderr deleted file mode 100644 index b1f73eda5d26..000000000000 --- a/tests/ui/str_to_string.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: `to_string()` called on a `&str` - --> $DIR/str_to_string.rs:4:17 - | -LL | let hello = "hello world".to_string(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::str-to-string` implied by `-D warnings` - = help: consider using `.to_owned()` - -error: `to_string()` called on a `&str` - --> $DIR/str_to_string.rs:6:5 - | -LL | msg.to_string(); - | ^^^^^^^^^^^^^^^ - | - = help: consider using `.to_owned()` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/string_add.rs b/tests/ui/string_add.rs deleted file mode 100644 index 30fd17c59e51..000000000000 --- a/tests/ui/string_add.rs +++ /dev/null @@ -1,26 +0,0 @@ -// aux-build:macro_rules.rs - -#[macro_use] -extern crate macro_rules; - -#[warn(clippy::string_add)] -#[allow(clippy::string_add_assign, unused)] -fn main() { - // ignores assignment distinction - let mut x = "".to_owned(); - - for _ in 1..3 { - x = x + "."; - } - - let y = "".to_owned(); - let z = y + "..."; - - assert_eq!(&x, &z); - - let mut x = 1; - x = x + 1; - assert_eq!(2, x); - - string_add!(); -} diff --git a/tests/ui/string_add.stderr b/tests/ui/string_add.stderr deleted file mode 100644 index 3987641c75a3..000000000000 --- a/tests/ui/string_add.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error: manual implementation of an assign operation - --> $DIR/string_add.rs:13:9 - | -LL | x = x + "."; - | ^^^^^^^^^^^ help: replace it with: `x += "."` - | - = note: `-D clippy::assign-op-pattern` implied by `-D warnings` - -error: you added something to a string. Consider using `String::push_str()` instead - --> $DIR/string_add.rs:13:13 - | -LL | x = x + "."; - | ^^^^^^^ - | - = note: `-D clippy::string-add` implied by `-D warnings` - -error: you added something to a string. Consider using `String::push_str()` instead - --> $DIR/string_add.rs:17:13 - | -LL | let z = y + "..."; - | ^^^^^^^^^ - -error: manual implementation of an assign operation - --> $DIR/string_add.rs:22:5 - | -LL | x = x + 1; - | ^^^^^^^^^ help: replace it with: `x += 1` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/string_add_assign.fixed b/tests/ui/string_add_assign.fixed deleted file mode 100644 index db71bab1e521..000000000000 --- a/tests/ui/string_add_assign.fixed +++ /dev/null @@ -1,21 +0,0 @@ -// run-rustfix - -#[allow(clippy::string_add, unused)] -#[warn(clippy::string_add_assign)] -fn main() { - // ignores assignment distinction - let mut x = "".to_owned(); - - for _ in 1..3 { - x += "."; - } - - let y = "".to_owned(); - let z = y + "..."; - - assert_eq!(&x, &z); - - let mut x = 1; - x += 1; - assert_eq!(2, x); -} diff --git a/tests/ui/string_add_assign.rs b/tests/ui/string_add_assign.rs deleted file mode 100644 index 644991945cbe..000000000000 --- a/tests/ui/string_add_assign.rs +++ /dev/null @@ -1,21 +0,0 @@ -// run-rustfix - -#[allow(clippy::string_add, unused)] -#[warn(clippy::string_add_assign)] -fn main() { - // ignores assignment distinction - let mut x = "".to_owned(); - - for _ in 1..3 { - x = x + "."; - } - - let y = "".to_owned(); - let z = y + "..."; - - assert_eq!(&x, &z); - - let mut x = 1; - x = x + 1; - assert_eq!(2, x); -} diff --git a/tests/ui/string_add_assign.stderr b/tests/ui/string_add_assign.stderr deleted file mode 100644 index 7676175c1b82..000000000000 --- a/tests/ui/string_add_assign.stderr +++ /dev/null @@ -1,24 +0,0 @@ -error: you assigned the result of adding something to this string. Consider using `String::push_str()` instead - --> $DIR/string_add_assign.rs:10:9 - | -LL | x = x + "."; - | ^^^^^^^^^^^ - | - = note: `-D clippy::string-add-assign` implied by `-D warnings` - -error: manual implementation of an assign operation - --> $DIR/string_add_assign.rs:10:9 - | -LL | x = x + "."; - | ^^^^^^^^^^^ help: replace it with: `x += "."` - | - = note: `-D clippy::assign-op-pattern` implied by `-D warnings` - -error: manual implementation of an assign operation - --> $DIR/string_add_assign.rs:19:5 - | -LL | x = x + 1; - | ^^^^^^^^^ help: replace it with: `x += 1` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/string_extend.fixed b/tests/ui/string_extend.fixed deleted file mode 100644 index 1883a9f83257..000000000000 --- a/tests/ui/string_extend.fixed +++ /dev/null @@ -1,32 +0,0 @@ -// run-rustfix - -#[derive(Copy, Clone)] -struct HasChars; - -impl HasChars { - fn chars(self) -> std::str::Chars<'static> { - "HasChars".chars() - } -} - -fn main() { - let abc = "abc"; - let def = String::from("def"); - let mut s = String::new(); - - s.push_str(abc); - s.push_str(abc); - - s.push_str("abc"); - s.push_str("abc"); - - s.push_str(&def); - s.push_str(&def); - - s.extend(abc.chars().skip(1)); - s.extend("abc".chars().skip(1)); - s.extend(['a', 'b', 'c'].iter()); - - let f = HasChars; - s.extend(f.chars()); -} diff --git a/tests/ui/string_extend.rs b/tests/ui/string_extend.rs deleted file mode 100644 index 07d0baa1be6c..000000000000 --- a/tests/ui/string_extend.rs +++ /dev/null @@ -1,32 +0,0 @@ -// run-rustfix - -#[derive(Copy, Clone)] -struct HasChars; - -impl HasChars { - fn chars(self) -> std::str::Chars<'static> { - "HasChars".chars() - } -} - -fn main() { - let abc = "abc"; - let def = String::from("def"); - let mut s = String::new(); - - s.push_str(abc); - s.extend(abc.chars()); - - s.push_str("abc"); - s.extend("abc".chars()); - - s.push_str(&def); - s.extend(def.chars()); - - s.extend(abc.chars().skip(1)); - s.extend("abc".chars().skip(1)); - s.extend(['a', 'b', 'c'].iter()); - - let f = HasChars; - s.extend(f.chars()); -} diff --git a/tests/ui/string_extend.stderr b/tests/ui/string_extend.stderr deleted file mode 100644 index 6af8c9e1662b..000000000000 --- a/tests/ui/string_extend.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: calling `.extend(_.chars())` - --> $DIR/string_extend.rs:18:5 - | -LL | s.extend(abc.chars()); - | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str(abc)` - | - = note: `-D clippy::string-extend-chars` implied by `-D warnings` - -error: calling `.extend(_.chars())` - --> $DIR/string_extend.rs:21:5 - | -LL | s.extend("abc".chars()); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str("abc")` - -error: calling `.extend(_.chars())` - --> $DIR/string_extend.rs:24:5 - | -LL | s.extend(def.chars()); - | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str(&def)` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/string_from_utf8_as_bytes.fixed b/tests/ui/string_from_utf8_as_bytes.fixed deleted file mode 100644 index 6e665cdd5630..000000000000 --- a/tests/ui/string_from_utf8_as_bytes.fixed +++ /dev/null @@ -1,6 +0,0 @@ -// run-rustfix -#![warn(clippy::string_from_utf8_as_bytes)] - -fn main() { - let _ = Some(&"Hello World!"[6..11]); -} diff --git a/tests/ui/string_from_utf8_as_bytes.rs b/tests/ui/string_from_utf8_as_bytes.rs deleted file mode 100644 index 670d206d3679..000000000000 --- a/tests/ui/string_from_utf8_as_bytes.rs +++ /dev/null @@ -1,6 +0,0 @@ -// run-rustfix -#![warn(clippy::string_from_utf8_as_bytes)] - -fn main() { - let _ = std::str::from_utf8(&"Hello World!".as_bytes()[6..11]); -} diff --git a/tests/ui/string_from_utf8_as_bytes.stderr b/tests/ui/string_from_utf8_as_bytes.stderr deleted file mode 100644 index bf5e5d33e8f9..000000000000 --- a/tests/ui/string_from_utf8_as_bytes.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: calling a slice of `as_bytes()` with `from_utf8` should be not necessary - --> $DIR/string_from_utf8_as_bytes.rs:5:13 - | -LL | let _ = std::str::from_utf8(&"Hello World!".as_bytes()[6..11]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(&"Hello World!"[6..11])` - | - = note: `-D clippy::string-from-utf8-as-bytes` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/string_lit_as_bytes.fixed b/tests/ui/string_lit_as_bytes.fixed deleted file mode 100644 index ccf8f61c4a92..000000000000 --- a/tests/ui/string_lit_as_bytes.fixed +++ /dev/null @@ -1,24 +0,0 @@ -// run-rustfix - -#![allow(dead_code, unused_variables)] -#![warn(clippy::string_lit_as_bytes)] - -fn str_lit_as_bytes() { - let bs = b"hello there"; - - let bs = br###"raw string with 3# plus " ""###; - - // no warning, because these cannot be written as byte string literals: - let ubs = "☃".as_bytes(); - let ubs = "hello there! this is a very long string".as_bytes(); - - let strify = stringify!(foobar).as_bytes(); - - let current_version = env!("CARGO_PKG_VERSION").as_bytes(); - - let includestr = include_bytes!("entry_unfixable.rs"); - - let _ = b"string with newline\t\n"; -} - -fn main() {} diff --git a/tests/ui/string_lit_as_bytes.rs b/tests/ui/string_lit_as_bytes.rs deleted file mode 100644 index 178df08e249e..000000000000 --- a/tests/ui/string_lit_as_bytes.rs +++ /dev/null @@ -1,24 +0,0 @@ -// run-rustfix - -#![allow(dead_code, unused_variables)] -#![warn(clippy::string_lit_as_bytes)] - -fn str_lit_as_bytes() { - let bs = "hello there".as_bytes(); - - let bs = r###"raw string with 3# plus " ""###.as_bytes(); - - // no warning, because these cannot be written as byte string literals: - let ubs = "☃".as_bytes(); - let ubs = "hello there! this is a very long string".as_bytes(); - - let strify = stringify!(foobar).as_bytes(); - - let current_version = env!("CARGO_PKG_VERSION").as_bytes(); - - let includestr = include_str!("entry_unfixable.rs").as_bytes(); - - let _ = "string with newline\t\n".as_bytes(); -} - -fn main() {} diff --git a/tests/ui/string_lit_as_bytes.stderr b/tests/ui/string_lit_as_bytes.stderr deleted file mode 100644 index 99c512354d58..000000000000 --- a/tests/ui/string_lit_as_bytes.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: calling `as_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:7:14 - | -LL | let bs = "hello there".as_bytes(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"hello there"` - | - = note: `-D clippy::string-lit-as-bytes` implied by `-D warnings` - -error: calling `as_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:9:14 - | -LL | let bs = r###"raw string with 3# plus " ""###.as_bytes(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `br###"raw string with 3# plus " ""###` - -error: calling `as_bytes()` on `include_str!(..)` - --> $DIR/string_lit_as_bytes.rs:19:22 - | -LL | let includestr = include_str!("entry_unfixable.rs").as_bytes(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `include_bytes!(..)` instead: `include_bytes!("entry_unfixable.rs")` - -error: calling `as_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:21:13 - | -LL | let _ = "string with newline/t/n".as_bytes(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"string with newline/t/n"` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/string_to_string.rs b/tests/ui/string_to_string.rs deleted file mode 100644 index 4c66855f7094..000000000000 --- a/tests/ui/string_to_string.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![warn(clippy::string_to_string)] -#![allow(clippy::redundant_clone)] - -fn main() { - let mut message = String::from("Hello"); - let mut v = message.to_string(); -} diff --git a/tests/ui/string_to_string.stderr b/tests/ui/string_to_string.stderr deleted file mode 100644 index 1ebd17999bd8..000000000000 --- a/tests/ui/string_to_string.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: `to_string()` called on a `String` - --> $DIR/string_to_string.rs:6:17 - | -LL | let mut v = message.to_string(); - | ^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::string-to-string` implied by `-D warnings` - = help: consider using `.clone()` - -error: aborting due to previous error - diff --git a/tests/ui/struct_excessive_bools.rs b/tests/ui/struct_excessive_bools.rs deleted file mode 100644 index ce4fe830a0a2..000000000000 --- a/tests/ui/struct_excessive_bools.rs +++ /dev/null @@ -1,44 +0,0 @@ -#![warn(clippy::struct_excessive_bools)] - -macro_rules! foo { - () => { - struct MacroFoo { - a: bool, - b: bool, - c: bool, - d: bool, - } - }; -} - -foo!(); - -struct Foo { - a: bool, - b: bool, - c: bool, -} - -struct BadFoo { - a: bool, - b: bool, - c: bool, - d: bool, -} - -#[repr(C)] -struct Bar { - a: bool, - b: bool, - c: bool, - d: bool, -} - -fn main() { - struct FooFoo { - a: bool, - b: bool, - c: bool, - d: bool, - } -} diff --git a/tests/ui/struct_excessive_bools.stderr b/tests/ui/struct_excessive_bools.stderr deleted file mode 100644 index 2941bf2983aa..000000000000 --- a/tests/ui/struct_excessive_bools.stderr +++ /dev/null @@ -1,29 +0,0 @@ -error: more than 3 bools in a struct - --> $DIR/struct_excessive_bools.rs:22:1 - | -LL | / struct BadFoo { -LL | | a: bool, -LL | | b: bool, -LL | | c: bool, -LL | | d: bool, -LL | | } - | |_^ - | - = note: `-D clippy::struct-excessive-bools` implied by `-D warnings` - = help: consider using a state machine or refactoring bools into two-variant enums - -error: more than 3 bools in a struct - --> $DIR/struct_excessive_bools.rs:38:5 - | -LL | / struct FooFoo { -LL | | a: bool, -LL | | b: bool, -LL | | c: bool, -LL | | d: bool, -LL | | } - | |_____^ - | - = help: consider using a state machine or refactoring bools into two-variant enums - -error: aborting due to 2 previous errors - diff --git a/tests/ui/suspicious_arithmetic_impl.rs b/tests/ui/suspicious_arithmetic_impl.rs deleted file mode 100644 index 5c280efac1a8..000000000000 --- a/tests/ui/suspicious_arithmetic_impl.rs +++ /dev/null @@ -1,170 +0,0 @@ -#![warn(clippy::suspicious_arithmetic_impl)] -use std::ops::{ - Add, AddAssign, BitAnd, BitOr, BitOrAssign, BitXor, Div, DivAssign, Mul, MulAssign, Rem, Shl, Shr, Sub, -}; - -#[derive(Copy, Clone)] -struct Foo(u32); - -impl Add for Foo { - type Output = Foo; - - fn add(self, other: Self) -> Self { - Foo(self.0 - other.0) - } -} - -impl AddAssign for Foo { - fn add_assign(&mut self, other: Foo) { - *self = *self - other; - } -} - -impl BitOrAssign for Foo { - fn bitor_assign(&mut self, other: Foo) { - let idx = other.0; - self.0 |= 1 << idx; // OK: BinOpKind::Shl part of AssignOp as child node - } -} - -impl MulAssign for Foo { - fn mul_assign(&mut self, other: Foo) { - self.0 /= other.0; - } -} - -impl DivAssign for Foo { - fn div_assign(&mut self, other: Foo) { - self.0 /= other.0; // OK: BinOpKind::Div == DivAssign - } -} - -impl Mul for Foo { - type Output = Foo; - - fn mul(self, other: Foo) -> Foo { - Foo(self.0 * other.0 % 42) // OK: BinOpKind::Rem part of BiExpr as parent node - } -} - -impl Sub for Foo { - type Output = Foo; - - fn sub(self, other: Self) -> Self { - Foo(self.0 * other.0 - 42) // OK: BinOpKind::Mul part of BiExpr as child node - } -} - -impl Div for Foo { - type Output = Foo; - - fn div(self, other: Self) -> Self { - Foo(do_nothing(self.0 + other.0) / 42) // OK: BinOpKind::Add part of BiExpr as child node - } -} - -impl Rem for Foo { - type Output = Foo; - - fn rem(self, other: Self) -> Self { - Foo(self.0 / other.0) - } -} - -impl BitAnd for Foo { - type Output = Foo; - - fn bitand(self, other: Self) -> Self { - Foo(self.0 | other.0) - } -} - -impl BitOr for Foo { - type Output = Foo; - - fn bitor(self, other: Self) -> Self { - Foo(self.0 ^ other.0) - } -} - -impl BitXor for Foo { - type Output = Foo; - - fn bitxor(self, other: Self) -> Self { - Foo(self.0 & other.0) - } -} - -impl Shl for Foo { - type Output = Foo; - - fn shl(self, other: Self) -> Self { - Foo(self.0 >> other.0) - } -} - -impl Shr for Foo { - type Output = Foo; - - fn shr(self, other: Self) -> Self { - Foo(self.0 << other.0) - } -} - -struct Bar(i32); - -impl Add for Bar { - type Output = Bar; - - fn add(self, other: Self) -> Self { - Bar(self.0 & !other.0) // OK: UnNot part of BiExpr as child node - } -} - -impl Sub for Bar { - type Output = Bar; - - fn sub(self, other: Self) -> Self { - if self.0 <= other.0 { - Bar(-(self.0 & other.0)) // OK: UnNeg part of BiExpr as parent node - } else { - Bar(0) - } - } -} - -fn main() {} - -fn do_nothing(x: u32) -> u32 { - x -} - -struct MultipleBinops(u32); - -impl Add for MultipleBinops { - type Output = MultipleBinops; - - // OK: multiple Binops in `add` impl - fn add(self, other: Self) -> Self::Output { - let mut result = self.0 + other.0; - if result >= u32::max_value() { - result -= u32::max_value(); - } - MultipleBinops(result) - } -} - -impl Mul for MultipleBinops { - type Output = MultipleBinops; - - // OK: multiple Binops in `mul` impl - fn mul(self, other: Self) -> Self::Output { - let mut result: u32 = 0; - let size = std::cmp::max(self.0, other.0) as usize; - let mut v = vec![0; size + 1]; - for i in 0..size + 1 { - result *= i as u32; - } - MultipleBinops(result) - } -} diff --git a/tests/ui/suspicious_arithmetic_impl.stderr b/tests/ui/suspicious_arithmetic_impl.stderr deleted file mode 100644 index 388fc7400820..000000000000 --- a/tests/ui/suspicious_arithmetic_impl.stderr +++ /dev/null @@ -1,60 +0,0 @@ -error: suspicious use of binary operator in `Add` impl - --> $DIR/suspicious_arithmetic_impl.rs:13:20 - | -LL | Foo(self.0 - other.0) - | ^ - | - = note: `-D clippy::suspicious-arithmetic-impl` implied by `-D warnings` - -error: suspicious use of binary operator in `AddAssign` impl - --> $DIR/suspicious_arithmetic_impl.rs:19:23 - | -LL | *self = *self - other; - | ^ - | - = note: `#[deny(clippy::suspicious_op_assign_impl)]` on by default - -error: suspicious use of binary operator in `MulAssign` impl - --> $DIR/suspicious_arithmetic_impl.rs:32:16 - | -LL | self.0 /= other.0; - | ^^ - -error: suspicious use of binary operator in `Rem` impl - --> $DIR/suspicious_arithmetic_impl.rs:70:20 - | -LL | Foo(self.0 / other.0) - | ^ - -error: suspicious use of binary operator in `BitAnd` impl - --> $DIR/suspicious_arithmetic_impl.rs:78:20 - | -LL | Foo(self.0 | other.0) - | ^ - -error: suspicious use of binary operator in `BitOr` impl - --> $DIR/suspicious_arithmetic_impl.rs:86:20 - | -LL | Foo(self.0 ^ other.0) - | ^ - -error: suspicious use of binary operator in `BitXor` impl - --> $DIR/suspicious_arithmetic_impl.rs:94:20 - | -LL | Foo(self.0 & other.0) - | ^ - -error: suspicious use of binary operator in `Shl` impl - --> $DIR/suspicious_arithmetic_impl.rs:102:20 - | -LL | Foo(self.0 >> other.0) - | ^^ - -error: suspicious use of binary operator in `Shr` impl - --> $DIR/suspicious_arithmetic_impl.rs:110:20 - | -LL | Foo(self.0 << other.0) - | ^^ - -error: aborting due to 9 previous errors - diff --git a/tests/ui/suspicious_else_formatting.rs b/tests/ui/suspicious_else_formatting.rs deleted file mode 100644 index 226010ec6df3..000000000000 --- a/tests/ui/suspicious_else_formatting.rs +++ /dev/null @@ -1,79 +0,0 @@ -#![warn(clippy::suspicious_else_formatting)] - -fn foo() -> bool { - true -} - -#[rustfmt::skip] -fn main() { - // weird `else` formatting: - if foo() { - } { - } - - if foo() { - } if foo() { - } - - let _ = { // if as the last expression - let _ = 0; - - if foo() { - } if foo() { - } - else { - } - }; - - let _ = { // if in the middle of a block - if foo() { - } if foo() { - } - else { - } - - let _ = 0; - }; - - if foo() { - } else - { - } - - if foo() { - } - else - { - } - - if foo() { - } else - if foo() { // the span of the above error should continue here - } - - if foo() { - } - else - if foo() { // the span of the above error should continue here - } - - // those are ok: - if foo() { - } - { - } - - if foo() { - } else { - } - - if foo() { - } - else { - } - - if foo() { - } - if foo() { - } -} diff --git a/tests/ui/suspicious_else_formatting.stderr b/tests/ui/suspicious_else_formatting.stderr deleted file mode 100644 index bbc036d376fe..000000000000 --- a/tests/ui/suspicious_else_formatting.stderr +++ /dev/null @@ -1,77 +0,0 @@ -error: this looks like an `else {..}` but the `else` is missing - --> $DIR/suspicious_else_formatting.rs:11:6 - | -LL | } { - | ^ - | - = note: `-D clippy::suspicious-else-formatting` implied by `-D warnings` - = note: to remove this lint, add the missing `else` or add a new line before the next block - -error: this looks like an `else if` but the `else` is missing - --> $DIR/suspicious_else_formatting.rs:15:6 - | -LL | } if foo() { - | ^ - | - = note: to remove this lint, add the missing `else` or add a new line before the second `if` - -error: this looks like an `else if` but the `else` is missing - --> $DIR/suspicious_else_formatting.rs:22:10 - | -LL | } if foo() { - | ^ - | - = note: to remove this lint, add the missing `else` or add a new line before the second `if` - -error: this looks like an `else if` but the `else` is missing - --> $DIR/suspicious_else_formatting.rs:30:10 - | -LL | } if foo() { - | ^ - | - = note: to remove this lint, add the missing `else` or add a new line before the second `if` - -error: this is an `else {..}` but the formatting might hide it - --> $DIR/suspicious_else_formatting.rs:39:6 - | -LL | } else - | ______^ -LL | | { - | |____^ - | - = note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}` - -error: this is an `else {..}` but the formatting might hide it - --> $DIR/suspicious_else_formatting.rs:44:6 - | -LL | } - | ______^ -LL | | else -LL | | { - | |____^ - | - = note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}` - -error: this is an `else if` but the formatting might hide it - --> $DIR/suspicious_else_formatting.rs:50:6 - | -LL | } else - | ______^ -LL | | if foo() { // the span of the above error should continue here - | |____^ - | - = note: to remove this lint, remove the `else` or remove the new line between `else` and `if` - -error: this is an `else if` but the formatting might hide it - --> $DIR/suspicious_else_formatting.rs:55:6 - | -LL | } - | ______^ -LL | | else -LL | | if foo() { // the span of the above error should continue here - | |____^ - | - = note: to remove this lint, remove the `else` or remove the new line between `else` and `if` - -error: aborting due to 8 previous errors - diff --git a/tests/ui/suspicious_map.rs b/tests/ui/suspicious_map.rs deleted file mode 100644 index d838d8fde210..000000000000 --- a/tests/ui/suspicious_map.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![warn(clippy::suspicious_map)] - -fn main() { - let _ = (0..3).map(|x| x + 2).count(); -} diff --git a/tests/ui/suspicious_map.stderr b/tests/ui/suspicious_map.stderr deleted file mode 100644 index e1b4ba40376f..000000000000 --- a/tests/ui/suspicious_map.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: this call to `map()` won't have an effect on the call to `count()` - --> $DIR/suspicious_map.rs:4:13 - | -LL | let _ = (0..3).map(|x| x + 2).count(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::suspicious-map` implied by `-D warnings` - = help: make sure you did not confuse `map` with `filter` or `for_each` - -error: aborting due to previous error - diff --git a/tests/ui/suspicious_operation_groupings.rs b/tests/ui/suspicious_operation_groupings.rs deleted file mode 100644 index dd6f4ec7bd9b..000000000000 --- a/tests/ui/suspicious_operation_groupings.rs +++ /dev/null @@ -1,207 +0,0 @@ -#![warn(clippy::suspicious_operation_groupings)] - -struct Vec3 { - x: f64, - y: f64, - z: f64, -} - -impl Eq for Vec3 {} - -impl PartialEq for Vec3 { - fn eq(&self, other: &Self) -> bool { - // This should trigger the lint because `self.x` is compared to `other.y` - self.x == other.y && self.y == other.y && self.z == other.z - } -} - -struct S { - a: i32, - b: i32, - c: i32, - d: i32, -} - -fn buggy_ab_cmp(s1: &S, s2: &S) -> bool { - // There's no `s1.b` - s1.a < s2.a && s1.a < s2.b -} - -struct SAOnly { - a: i32, -} - -impl S { - fn a(&self) -> i32 { - 0 - } -} - -fn do_not_give_bad_suggestions_for_this_unusual_expr(s1: &S, s2: &SAOnly) -> bool { - // This is superficially similar to `buggy_ab_cmp`, but we should not suggest - // `s2.b` since that is invalid. - s1.a < s2.a && s1.a() < s1.b -} - -fn do_not_give_bad_suggestions_for_this_macro_expr(s1: &S, s2: &SAOnly) -> bool { - macro_rules! s1 { - () => { - S { - a: 1, - b: 1, - c: 1, - d: 1, - } - }; - } - - // This is superficially similar to `buggy_ab_cmp`, but we should not suggest - // `s2.b` since that is invalid. - s1.a < s2.a && s1!().a < s1.b -} - -fn do_not_give_bad_suggestions_for_this_incorrect_expr(s1: &S, s2: &SAOnly) -> bool { - // There's two `s1.b`, but we should not suggest `s2.b` since that is invalid - s1.a < s2.a && s1.b < s1.b -} - -fn permissable(s1: &S, s2: &S) -> bool { - // Something like this seems like it might actually be what is desired. - s1.a == s2.b -} - -fn non_boolean_operators(s1: &S, s2: &S) -> i32 { - // There's no `s2.c` - s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d -} - -fn odd_number_of_pairs(s1: &S, s2: &S) -> i32 { - // There's no `s2.b` - s1.a * s2.a + s1.b * s2.c + s1.c * s2.c -} - -fn not_caught_by_eq_op_middle_change_left(s1: &S, s2: &S) -> i32 { - // There's no `s1.b` - s1.a * s2.a + s2.b * s2.b + s1.c * s2.c -} - -fn not_caught_by_eq_op_middle_change_right(s1: &S, s2: &S) -> i32 { - // There's no `s2.b` - s1.a * s2.a + s1.b * s1.b + s1.c * s2.c -} - -fn not_caught_by_eq_op_start(s1: &S, s2: &S) -> i32 { - // There's no `s2.a` - s1.a * s1.a + s1.b * s2.b + s1.c * s2.c -} - -fn not_caught_by_eq_op_end(s1: &S, s2: &S) -> i32 { - // There's no `s2.c` - s1.a * s2.a + s1.b * s2.b + s1.c * s1.c -} - -fn the_cross_product_should_not_lint(s1: &S, s2: &S) -> (i32, i32, i32) { - ( - s1.b * s2.c - s1.c * s2.b, - s1.c * s2.a - s1.a * s2.c, - s1.a * s2.b - s1.b * s2.a, - ) -} - -fn outer_parens_simple(s1: &S, s2: &S) -> i32 { - // There's no `s2.b` - (s1.a * s2.a + s1.b * s1.b) -} - -fn outer_parens(s1: &S, s2: &S) -> i32 { - // There's no `s2.c` - (s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d) -} - -fn inner_parens(s1: &S, s2: &S) -> i32 { - // There's no `s2.c` - (s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d) -} - -fn outer_and_some_inner_parens(s1: &S, s2: &S) -> i32 { - // There's no `s2.c` - ((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d)) -} - -fn all_parens_balanced_tree(s1: &S, s2: &S) -> i32 { - // There's no `s2.c` - (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.b) + (s1.d * s2.d))) -} - -fn all_parens_left_tree(s1: &S, s2: &S) -> i32 { - // There's no `s2.c` - (((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b)) + (s1.d * s2.d)) -} - -fn all_parens_right_tree(s1: &S, s2: &S) -> i32 { - // There's no `s2.c` - ((s1.a * s2.a) + ((s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d))) -} - -fn inside_other_binop_expression(s1: &S, s2: &S) -> i32 { - // There's no `s1.b` - (s1.a * s2.a + s2.b * s2.b) / 2 -} - -fn inside_function_call(s1: &S, s2: &S) -> i32 { - // There's no `s1.b` - i32::swap_bytes(s1.a * s2.a + s2.b * s2.b) -} - -fn inside_larger_boolean_expression(s1: &S, s2: &S) -> bool { - // There's no `s1.c` - s1.a > 0 && s1.b > 0 && s1.d == s2.c && s1.d == s2.d -} - -fn inside_larger_boolean_expression_with_unsorted_ops(s1: &S, s2: &S) -> bool { - // There's no `s1.c` - s1.a > 0 && s1.d == s2.c && s1.b > 0 && s1.d == s2.d -} - -struct Nested { - inner: ((i32,), (i32,), (i32,)), -} - -fn changed_middle_ident(n1: &Nested, n2: &Nested) -> bool { - // There's no `n2.inner.2.0` - (n1.inner.0).0 == (n2.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.1).0 -} - -// `eq_op` should catch this one. -fn changed_initial_ident(n1: &Nested, n2: &Nested) -> bool { - // There's no `n2.inner.0.0` - (n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0 -} - -fn inside_fn_with_similar_expression(s1: &S, s2: &S, strict: bool) -> bool { - if strict { - s1.a < s2.a && s1.b < s2.b - } else { - // There's no `s1.b` in this subexpression - s1.a <= s2.a && s1.a <= s2.b - } -} - -fn inside_an_if_statement(s1: &S, s2: &S) { - // There's no `s1.b` - if s1.a < s2.a && s1.a < s2.b { - s1.c = s2.c; - } -} - -fn maximum_unary_minus_right_tree(s1: &S, s2: &S) -> i32 { - // There's no `s2.c` - -(-(-s1.a * -s2.a) + (-(-s1.b * -s2.b) + -(-s1.c * -s2.b) + -(-s1.d * -s2.d))) -} - -fn unary_minus_and_an_if_expression(s1: &S, s2: &S) -> i32 { - // There's no `s1.b` - -(if -s1.a < -s2.a && -s1.a < -s2.b { s1.c } else { s2.a }) -} - -fn main() {} diff --git a/tests/ui/suspicious_operation_groupings.stderr b/tests/ui/suspicious_operation_groupings.stderr deleted file mode 100644 index ce7108217f18..000000000000 --- a/tests/ui/suspicious_operation_groupings.stderr +++ /dev/null @@ -1,166 +0,0 @@ -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:14:9 - | -LL | self.x == other.y && self.y == other.y && self.z == other.z - | ^^^^^^^^^^^^^^^^^ help: I think you meant: `self.x == other.x` - | - = note: `-D clippy::suspicious-operation-groupings` implied by `-D warnings` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:14:9 - | -LL | self.x == other.y && self.y == other.y && self.z == other.z - | ^^^^^^^^^^^^^^^^^ help: I think you meant: `self.x == other.x` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:27:20 - | -LL | s1.a < s2.a && s1.a < s2.b - | ^^^^^^^^^^^ help: I think you meant: `s1.b < s2.b` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:75:33 - | -LL | s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d - | ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:80:19 - | -LL | s1.a * s2.a + s1.b * s2.c + s1.c * s2.c - | ^^^^^^^^^^^ help: I think you meant: `s1.b * s2.b` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:80:19 - | -LL | s1.a * s2.a + s1.b * s2.c + s1.c * s2.c - | ^^^^^^^^^^^ help: I think you meant: `s1.b * s2.b` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:85:19 - | -LL | s1.a * s2.a + s2.b * s2.b + s1.c * s2.c - | ^^^^^^^^^^^ help: I think you meant: `s1.b * s2.b` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:90:19 - | -LL | s1.a * s2.a + s1.b * s1.b + s1.c * s2.c - | ^^^^^^^^^^^ help: I think you meant: `s1.b * s2.b` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:95:5 - | -LL | s1.a * s1.a + s1.b * s2.b + s1.c * s2.c - | ^^^^^^^^^^^ help: I think you meant: `s1.a * s2.a` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:100:33 - | -LL | s1.a * s2.a + s1.b * s2.b + s1.c * s1.c - | ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:113:20 - | -LL | (s1.a * s2.a + s1.b * s1.b) - | ^^^^^^^^^^^ help: I think you meant: `s1.b * s2.b` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:118:34 - | -LL | (s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d) - | ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:123:38 - | -LL | (s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d) - | ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:128:39 - | -LL | ((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d)) - | ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:133:42 - | -LL | (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.b) + (s1.d * s2.d))) - | ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:133:42 - | -LL | (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.b) + (s1.d * s2.d))) - | ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:138:40 - | -LL | (((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b)) + (s1.d * s2.d)) - | ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:143:40 - | -LL | ((s1.a * s2.a) + ((s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d))) - | ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:148:20 - | -LL | (s1.a * s2.a + s2.b * s2.b) / 2 - | ^^^^^^^^^^^ help: I think you meant: `s1.b * s2.b` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:153:35 - | -LL | i32::swap_bytes(s1.a * s2.a + s2.b * s2.b) - | ^^^^^^^^^^^ help: I think you meant: `s1.b * s2.b` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:158:29 - | -LL | s1.a > 0 && s1.b > 0 && s1.d == s2.c && s1.d == s2.d - | ^^^^^^^^^^^^ help: I think you meant: `s1.c == s2.c` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:163:17 - | -LL | s1.a > 0 && s1.d == s2.c && s1.b > 0 && s1.d == s2.d - | ^^^^^^^^^^^^ help: I think you meant: `s1.c == s2.c` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:172:77 - | -LL | (n1.inner.0).0 == (n2.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.1).0 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: I think you meant: `(n1.inner.2).0 == (n2.inner.2).0` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:186:25 - | -LL | s1.a <= s2.a && s1.a <= s2.b - | ^^^^^^^^^^^^ help: I think you meant: `s1.b <= s2.b` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:192:23 - | -LL | if s1.a < s2.a && s1.a < s2.b { - | ^^^^^^^^^^^ help: I think you meant: `s1.b < s2.b` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:199:48 - | -LL | -(-(-s1.a * -s2.a) + (-(-s1.b * -s2.b) + -(-s1.c * -s2.b) + -(-s1.d * -s2.d))) - | ^^^^^^^^^^^^^ help: I think you meant: `-s1.c * -s2.c` - -error: This sequence of operators looks suspiciously like a bug. - --> $DIR/suspicious_operation_groupings.rs:204:27 - | -LL | -(if -s1.a < -s2.a && -s1.a < -s2.b { s1.c } else { s2.a }) - | ^^^^^^^^^^^^^ help: I think you meant: `-s1.b < -s2.b` - -error: aborting due to 27 previous errors - diff --git a/tests/ui/suspicious_unary_op_formatting.rs b/tests/ui/suspicious_unary_op_formatting.rs deleted file mode 100644 index 9564e373c246..000000000000 --- a/tests/ui/suspicious_unary_op_formatting.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![warn(clippy::suspicious_unary_op_formatting)] - -#[rustfmt::skip] -fn main() { - // weird binary operator formatting: - let a = 42; - - if a >- 30 {} - if a >=- 30 {} - - let b = true; - let c = false; - - if b &&! c {} - - if a >- 30 {} - - // those are ok: - if a >-30 {} - if a < -30 {} - if b && !c {} - if a > - 30 {} -} diff --git a/tests/ui/suspicious_unary_op_formatting.stderr b/tests/ui/suspicious_unary_op_formatting.stderr deleted file mode 100644 index 581527dcff8e..000000000000 --- a/tests/ui/suspicious_unary_op_formatting.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error: by not having a space between `>` and `-` it looks like `>-` is a single operator - --> $DIR/suspicious_unary_op_formatting.rs:8:9 - | -LL | if a >- 30 {} - | ^^^^ - | - = note: `-D clippy::suspicious-unary-op-formatting` implied by `-D warnings` - = help: put a space between `>` and `-` and remove the space after `-` - -error: by not having a space between `>=` and `-` it looks like `>=-` is a single operator - --> $DIR/suspicious_unary_op_formatting.rs:9:9 - | -LL | if a >=- 30 {} - | ^^^^^ - | - = help: put a space between `>=` and `-` and remove the space after `-` - -error: by not having a space between `&&` and `!` it looks like `&&!` is a single operator - --> $DIR/suspicious_unary_op_formatting.rs:14:9 - | -LL | if b &&! c {} - | ^^^^^ - | - = help: put a space between `&&` and `!` and remove the space after `!` - -error: by not having a space between `>` and `-` it looks like `>-` is a single operator - --> $DIR/suspicious_unary_op_formatting.rs:16:9 - | -LL | if a >- 30 {} - | ^^^^^^ - | - = help: put a space between `>` and `-` and remove the space after `-` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/swap.fixed b/tests/ui/swap.fixed deleted file mode 100644 index 0f8f839a0d54..000000000000 --- a/tests/ui/swap.fixed +++ /dev/null @@ -1,83 +0,0 @@ -// run-rustfix - -#![warn(clippy::all)] -#![allow( - clippy::blacklisted_name, - clippy::no_effect, - clippy::redundant_clone, - redundant_semicolons, - unused_assignments -)] - -struct Foo(u32); - -#[derive(Clone)] -struct Bar { - a: u32, - b: u32, -} - -fn field() { - let mut bar = Bar { a: 1, b: 2 }; - - let temp = bar.a; - bar.a = bar.b; - bar.b = temp; - - let mut baz = vec![bar.clone(), bar.clone()]; - let temp = baz[0].a; - baz[0].a = baz[1].a; - baz[1].a = temp; -} - -fn array() { - let mut foo = [1, 2]; - foo.swap(0, 1); - - foo.swap(0, 1); -} - -fn slice() { - let foo = &mut [1, 2]; - foo.swap(0, 1); - - foo.swap(0, 1); -} - -fn unswappable_slice() { - let foo = &mut [vec![1, 2], vec![3, 4]]; - let temp = foo[0][1]; - foo[0][1] = foo[1][0]; - foo[1][0] = temp; - - // swap(foo[0][1], foo[1][0]) would fail -} - -fn vec() { - let mut foo = vec![1, 2]; - foo.swap(0, 1); - - foo.swap(0, 1); -} - -#[rustfmt::skip] -fn main() { - field(); - array(); - slice(); - unswappable_slice(); - vec(); - - let mut a = 42; - let mut b = 1337; - - std::mem::swap(&mut a, &mut b); - - ; std::mem::swap(&mut a, &mut b); - - let mut c = Foo(42); - - std::mem::swap(&mut c.0, &mut a); - - ; std::mem::swap(&mut c.0, &mut a); -} diff --git a/tests/ui/swap.rs b/tests/ui/swap.rs deleted file mode 100644 index 5763d9e82d48..000000000000 --- a/tests/ui/swap.rs +++ /dev/null @@ -1,95 +0,0 @@ -// run-rustfix - -#![warn(clippy::all)] -#![allow( - clippy::blacklisted_name, - clippy::no_effect, - clippy::redundant_clone, - redundant_semicolons, - unused_assignments -)] - -struct Foo(u32); - -#[derive(Clone)] -struct Bar { - a: u32, - b: u32, -} - -fn field() { - let mut bar = Bar { a: 1, b: 2 }; - - let temp = bar.a; - bar.a = bar.b; - bar.b = temp; - - let mut baz = vec![bar.clone(), bar.clone()]; - let temp = baz[0].a; - baz[0].a = baz[1].a; - baz[1].a = temp; -} - -fn array() { - let mut foo = [1, 2]; - let temp = foo[0]; - foo[0] = foo[1]; - foo[1] = temp; - - foo.swap(0, 1); -} - -fn slice() { - let foo = &mut [1, 2]; - let temp = foo[0]; - foo[0] = foo[1]; - foo[1] = temp; - - foo.swap(0, 1); -} - -fn unswappable_slice() { - let foo = &mut [vec![1, 2], vec![3, 4]]; - let temp = foo[0][1]; - foo[0][1] = foo[1][0]; - foo[1][0] = temp; - - // swap(foo[0][1], foo[1][0]) would fail -} - -fn vec() { - let mut foo = vec![1, 2]; - let temp = foo[0]; - foo[0] = foo[1]; - foo[1] = temp; - - foo.swap(0, 1); -} - -#[rustfmt::skip] -fn main() { - field(); - array(); - slice(); - unswappable_slice(); - vec(); - - let mut a = 42; - let mut b = 1337; - - a = b; - b = a; - - ; let t = a; - a = b; - b = t; - - let mut c = Foo(42); - - c.0 = a; - a = c.0; - - ; let t = c.0; - c.0 = a; - a = t; -} diff --git a/tests/ui/swap.stderr b/tests/ui/swap.stderr deleted file mode 100644 index f49bcfedf3a1..000000000000 --- a/tests/ui/swap.stderr +++ /dev/null @@ -1,69 +0,0 @@ -error: this looks like you are swapping elements of `foo` manually - --> $DIR/swap.rs:35:5 - | -LL | / let temp = foo[0]; -LL | | foo[0] = foo[1]; -LL | | foo[1] = temp; - | |_________________^ help: try: `foo.swap(0, 1)` - | - = note: `-D clippy::manual-swap` implied by `-D warnings` - -error: this looks like you are swapping elements of `foo` manually - --> $DIR/swap.rs:44:5 - | -LL | / let temp = foo[0]; -LL | | foo[0] = foo[1]; -LL | | foo[1] = temp; - | |_________________^ help: try: `foo.swap(0, 1)` - -error: this looks like you are swapping elements of `foo` manually - --> $DIR/swap.rs:62:5 - | -LL | / let temp = foo[0]; -LL | | foo[0] = foo[1]; -LL | | foo[1] = temp; - | |_________________^ help: try: `foo.swap(0, 1)` - -error: this looks like you are swapping `a` and `b` manually - --> $DIR/swap.rs:83:7 - | -LL | ; let t = a; - | _______^ -LL | | a = b; -LL | | b = t; - | |_________^ help: try: `std::mem::swap(&mut a, &mut b)` - | - = note: or maybe you should use `std::mem::replace`? - -error: this looks like you are swapping `c.0` and `a` manually - --> $DIR/swap.rs:92:7 - | -LL | ; let t = c.0; - | _______^ -LL | | c.0 = a; -LL | | a = t; - | |_________^ help: try: `std::mem::swap(&mut c.0, &mut a)` - | - = note: or maybe you should use `std::mem::replace`? - -error: this looks like you are trying to swap `a` and `b` - --> $DIR/swap.rs:80:5 - | -LL | / a = b; -LL | | b = a; - | |_________^ help: try: `std::mem::swap(&mut a, &mut b)` - | - = note: `-D clippy::almost-swapped` implied by `-D warnings` - = note: or maybe you should use `std::mem::replace`? - -error: this looks like you are trying to swap `c.0` and `a` - --> $DIR/swap.rs:89:5 - | -LL | / c.0 = a; -LL | | a = c.0; - | |___________^ help: try: `std::mem::swap(&mut c.0, &mut a)` - | - = note: or maybe you should use `std::mem::replace`? - -error: aborting due to 7 previous errors - diff --git a/tests/ui/tabs_in_doc_comments.fixed b/tests/ui/tabs_in_doc_comments.fixed deleted file mode 100644 index 4bc4bc86c76c..000000000000 --- a/tests/ui/tabs_in_doc_comments.fixed +++ /dev/null @@ -1,22 +0,0 @@ -// run-rustfix - -#![warn(clippy::tabs_in_doc_comments)] -#[allow(dead_code)] - -/// -/// Struct to hold two strings: -/// - first one -/// - second one -pub struct DoubleString { - /// - /// - First String: - /// - needs to be inside here - first_string: String, - /// - /// - Second String: - /// - needs to be inside here - second_string: String, -} - -/// This is main -fn main() {} diff --git a/tests/ui/tabs_in_doc_comments.rs b/tests/ui/tabs_in_doc_comments.rs deleted file mode 100644 index 9db3416e6596..000000000000 --- a/tests/ui/tabs_in_doc_comments.rs +++ /dev/null @@ -1,22 +0,0 @@ -// run-rustfix - -#![warn(clippy::tabs_in_doc_comments)] -#[allow(dead_code)] - -/// -/// Struct to hold two strings: -/// - first one -/// - second one -pub struct DoubleString { - /// - /// - First String: - /// - needs to be inside here - first_string: String, - /// - /// - Second String: - /// - needs to be inside here - second_string: String, -} - -/// This is main -fn main() {} diff --git a/tests/ui/tabs_in_doc_comments.stderr b/tests/ui/tabs_in_doc_comments.stderr deleted file mode 100644 index 355f2e805796..000000000000 --- a/tests/ui/tabs_in_doc_comments.stderr +++ /dev/null @@ -1,52 +0,0 @@ -error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:12:9 - | -LL | /// - First String: - | ^^^^ help: consider using four spaces per tab - | - = note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` - -error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:13:9 - | -LL | /// - needs to be inside here - | ^^^^^^^^ help: consider using four spaces per tab - -error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:16:9 - | -LL | /// - Second String: - | ^^^^ help: consider using four spaces per tab - -error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:17:9 - | -LL | /// - needs to be inside here - | ^^^^^^^^ help: consider using four spaces per tab - -error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:8:5 - | -LL | /// - first one - | ^^^^ help: consider using four spaces per tab - -error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:8:13 - | -LL | /// - first one - | ^^^^^^^^ help: consider using four spaces per tab - -error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:9:5 - | -LL | /// - second one - | ^^^^ help: consider using four spaces per tab - -error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:9:14 - | -LL | /// - second one - | ^^^^ help: consider using four spaces per tab - -error: aborting due to 8 previous errors - diff --git a/tests/ui/temporary_assignment.rs b/tests/ui/temporary_assignment.rs deleted file mode 100644 index ac4c1bc65979..000000000000 --- a/tests/ui/temporary_assignment.rs +++ /dev/null @@ -1,70 +0,0 @@ -#![warn(clippy::temporary_assignment)] - -use std::ops::{Deref, DerefMut}; - -struct TupleStruct(i32); - -struct Struct { - field: i32, -} - -struct MultiStruct { - structure: Struct, -} - -struct Wrapper<'a> { - inner: &'a mut Struct, -} - -impl<'a> Deref for Wrapper<'a> { - type Target = Struct; - fn deref(&self) -> &Struct { - self.inner - } -} - -impl<'a> DerefMut for Wrapper<'a> { - fn deref_mut(&mut self) -> &mut Struct { - self.inner - } -} - -struct ArrayStruct { - array: [i32; 1], -} - -const A: TupleStruct = TupleStruct(1); -const B: Struct = Struct { field: 1 }; -const C: MultiStruct = MultiStruct { - structure: Struct { field: 1 }, -}; -const D: ArrayStruct = ArrayStruct { array: [1] }; - -fn main() { - let mut s = Struct { field: 0 }; - let mut t = (0, 0); - - Struct { field: 0 }.field = 1; - MultiStruct { - structure: Struct { field: 0 }, - } - .structure - .field = 1; - ArrayStruct { array: [0] }.array[0] = 1; - (0, 0).0 = 1; - - // no error - s.field = 1; - t.0 = 1; - Wrapper { inner: &mut s }.field = 1; - let mut a_mut = TupleStruct(1); - a_mut.0 = 2; - let mut b_mut = Struct { field: 1 }; - b_mut.field = 2; - let mut c_mut = MultiStruct { - structure: Struct { field: 1 }, - }; - c_mut.structure.field = 2; - let mut d_mut = ArrayStruct { array: [1] }; - d_mut.array[0] = 2; -} diff --git a/tests/ui/temporary_assignment.stderr b/tests/ui/temporary_assignment.stderr deleted file mode 100644 index 7d79901a28d1..000000000000 --- a/tests/ui/temporary_assignment.stderr +++ /dev/null @@ -1,32 +0,0 @@ -error: assignment to temporary - --> $DIR/temporary_assignment.rs:47:5 - | -LL | Struct { field: 0 }.field = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::temporary-assignment` implied by `-D warnings` - -error: assignment to temporary - --> $DIR/temporary_assignment.rs:48:5 - | -LL | / MultiStruct { -LL | | structure: Struct { field: 0 }, -LL | | } -LL | | .structure -LL | | .field = 1; - | |______________^ - -error: assignment to temporary - --> $DIR/temporary_assignment.rs:53:5 - | -LL | ArrayStruct { array: [0] }.array[0] = 1; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: assignment to temporary - --> $DIR/temporary_assignment.rs:54:5 - | -LL | (0, 0).0 = 1; - | ^^^^^^^^^^^^ - -error: aborting due to 4 previous errors - diff --git a/tests/ui/to_digit_is_some.fixed b/tests/ui/to_digit_is_some.fixed deleted file mode 100644 index 19184df0becb..000000000000 --- a/tests/ui/to_digit_is_some.fixed +++ /dev/null @@ -1,11 +0,0 @@ -//run-rustfix - -#![warn(clippy::to_digit_is_some)] - -fn main() { - let c = 'x'; - let d = &c; - - let _ = d.is_digit(10); - let _ = char::is_digit(c, 10); -} diff --git a/tests/ui/to_digit_is_some.rs b/tests/ui/to_digit_is_some.rs deleted file mode 100644 index 45a6728ebf57..000000000000 --- a/tests/ui/to_digit_is_some.rs +++ /dev/null @@ -1,11 +0,0 @@ -//run-rustfix - -#![warn(clippy::to_digit_is_some)] - -fn main() { - let c = 'x'; - let d = &c; - - let _ = d.to_digit(10).is_some(); - let _ = char::to_digit(c, 10).is_some(); -} diff --git a/tests/ui/to_digit_is_some.stderr b/tests/ui/to_digit_is_some.stderr deleted file mode 100644 index 177d3ccd3e23..000000000000 --- a/tests/ui/to_digit_is_some.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: use of `.to_digit(..).is_some()` - --> $DIR/to_digit_is_some.rs:9:13 - | -LL | let _ = d.to_digit(10).is_some(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `d.is_digit(10)` - | - = note: `-D clippy::to-digit-is-some` implied by `-D warnings` - -error: use of `.to_digit(..).is_some()` - --> $DIR/to_digit_is_some.rs:10:13 - | -LL | let _ = char::to_digit(c, 10).is_some(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `char::is_digit(c, 10)` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/to_string_in_display.rs b/tests/ui/to_string_in_display.rs deleted file mode 100644 index eb8105c6b6da..000000000000 --- a/tests/ui/to_string_in_display.rs +++ /dev/null @@ -1,69 +0,0 @@ -#![warn(clippy::to_string_in_display)] -#![allow(clippy::inherent_to_string_shadow_display)] - -use std::fmt; - -struct A; -impl A { - fn fmt(&self) { - self.to_string(); - } -} - -trait B { - fn fmt(&self) {} -} - -impl B for A { - fn fmt(&self) { - self.to_string(); - } -} - -impl fmt::Display for A { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.to_string()) - } -} - -fn fmt(a: A) { - a.to_string(); -} - -struct C; - -impl C { - fn to_string(&self) -> String { - String::from("I am C") - } -} - -impl fmt::Display for C { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.to_string()) - } -} - -enum D { - E(String), - F, -} - -impl std::fmt::Display for D { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self { - Self::E(string) => write!(f, "E {}", string.to_string()), - Self::F => write!(f, "F"), - } - } -} - -fn main() { - let a = A; - a.to_string(); - a.fmt(); - fmt(a); - - let c = C; - c.to_string(); -} diff --git a/tests/ui/to_string_in_display.stderr b/tests/ui/to_string_in_display.stderr deleted file mode 100644 index 5f26ef413e23..000000000000 --- a/tests/ui/to_string_in_display.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: using `to_string` in `fmt::Display` implementation might lead to infinite recursion - --> $DIR/to_string_in_display.rs:25:25 - | -LL | write!(f, "{}", self.to_string()) - | ^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::to-string-in-display` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/toplevel_ref_arg.fixed b/tests/ui/toplevel_ref_arg.fixed deleted file mode 100644 index b129d95c5602..000000000000 --- a/tests/ui/toplevel_ref_arg.fixed +++ /dev/null @@ -1,50 +0,0 @@ -// run-rustfix -// aux-build:macro_rules.rs - -#![warn(clippy::toplevel_ref_arg)] - -#[macro_use] -extern crate macro_rules; - -macro_rules! gen_binding { - () => { - let _y = &42; - }; -} - -fn main() { - // Closures should not warn - let y = |ref x| println!("{:?}", x); - y(1u8); - - let _x = &1; - - let _y: &(&_, u8) = &(&1, 2); - - let _z = &(1 + 2); - - let _z = &mut (1 + 2); - - let (ref x, _) = (1, 2); // ok, not top level - println!("The answer is {}.", x); - - let _x = &vec![1, 2, 3]; - - // Make sure that allowing the lint works - #[allow(clippy::toplevel_ref_arg)] - let ref mut _x = 1_234_543; - - // ok - for ref _x in 0..10 {} - - // lint in macro - #[allow(unused)] - { - gen_binding!(); - } - - // do not lint in external macro - { - ref_arg_binding!(); - } -} diff --git a/tests/ui/toplevel_ref_arg.rs b/tests/ui/toplevel_ref_arg.rs deleted file mode 100644 index 73eb4ff7306f..000000000000 --- a/tests/ui/toplevel_ref_arg.rs +++ /dev/null @@ -1,50 +0,0 @@ -// run-rustfix -// aux-build:macro_rules.rs - -#![warn(clippy::toplevel_ref_arg)] - -#[macro_use] -extern crate macro_rules; - -macro_rules! gen_binding { - () => { - let ref _y = 42; - }; -} - -fn main() { - // Closures should not warn - let y = |ref x| println!("{:?}", x); - y(1u8); - - let ref _x = 1; - - let ref _y: (&_, u8) = (&1, 2); - - let ref _z = 1 + 2; - - let ref mut _z = 1 + 2; - - let (ref x, _) = (1, 2); // ok, not top level - println!("The answer is {}.", x); - - let ref _x = vec![1, 2, 3]; - - // Make sure that allowing the lint works - #[allow(clippy::toplevel_ref_arg)] - let ref mut _x = 1_234_543; - - // ok - for ref _x in 0..10 {} - - // lint in macro - #[allow(unused)] - { - gen_binding!(); - } - - // do not lint in external macro - { - ref_arg_binding!(); - } -} diff --git a/tests/ui/toplevel_ref_arg.stderr b/tests/ui/toplevel_ref_arg.stderr deleted file mode 100644 index 15cb933fedc9..000000000000 --- a/tests/ui/toplevel_ref_arg.stderr +++ /dev/null @@ -1,45 +0,0 @@ -error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:20:9 - | -LL | let ref _x = 1; - | ----^^^^^^----- help: try: `let _x = &1;` - | - = note: `-D clippy::toplevel-ref-arg` implied by `-D warnings` - -error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:22:9 - | -LL | let ref _y: (&_, u8) = (&1, 2); - | ----^^^^^^--------------------- help: try: `let _y: &(&_, u8) = &(&1, 2);` - -error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:24:9 - | -LL | let ref _z = 1 + 2; - | ----^^^^^^--------- help: try: `let _z = &(1 + 2);` - -error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:26:9 - | -LL | let ref mut _z = 1 + 2; - | ----^^^^^^^^^^--------- help: try: `let _z = &mut (1 + 2);` - -error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:31:9 - | -LL | let ref _x = vec![1, 2, 3]; - | ----^^^^^^----------------- help: try: `let _x = &vec![1, 2, 3];` - -error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:11:13 - | -LL | let ref _y = 42; - | ----^^^^^^------ help: try: `let _y = &42;` -... -LL | gen_binding!(); - | --------------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 6 previous errors - diff --git a/tests/ui/toplevel_ref_arg_non_rustfix.rs b/tests/ui/toplevel_ref_arg_non_rustfix.rs deleted file mode 100644 index 1a493fbce0ef..000000000000 --- a/tests/ui/toplevel_ref_arg_non_rustfix.rs +++ /dev/null @@ -1,33 +0,0 @@ -// aux-build:macro_rules.rs - -#![warn(clippy::toplevel_ref_arg)] -#![allow(unused)] - -#[macro_use] -extern crate macro_rules; - -fn the_answer(ref mut x: u8) { - *x = 42; -} - -macro_rules! gen_function { - () => { - fn fun_example(ref _x: usize) {} - }; -} - -fn main() { - let mut x = 0; - the_answer(x); - - // lint in macro - #[allow(unused)] - { - gen_function!(); - } - - // do not lint in external macro - { - ref_arg_function!(); - } -} diff --git a/tests/ui/toplevel_ref_arg_non_rustfix.stderr b/tests/ui/toplevel_ref_arg_non_rustfix.stderr deleted file mode 100644 index 6c36141a58c6..000000000000 --- a/tests/ui/toplevel_ref_arg_non_rustfix.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error: `ref` directly on a function argument is ignored. Consider using a reference type instead. - --> $DIR/toplevel_ref_arg_non_rustfix.rs:9:15 - | -LL | fn the_answer(ref mut x: u8) { - | ^^^^^^^^^ - | - = note: `-D clippy::toplevel-ref-arg` implied by `-D warnings` - -error: `ref` directly on a function argument is ignored. Consider using a reference type instead. - --> $DIR/toplevel_ref_arg_non_rustfix.rs:15:24 - | -LL | fn fun_example(ref _x: usize) {} - | ^^^^^^ -... -LL | gen_function!(); - | ---------------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 2 previous errors - diff --git a/tests/ui/trailing_zeros.rs b/tests/ui/trailing_zeros.rs deleted file mode 100644 index fbdc977b769a..000000000000 --- a/tests/ui/trailing_zeros.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![allow(unused_parens)] -#![warn(clippy::verbose_bit_mask)] - -fn main() { - let x: i32 = 42; - let _ = (x & 0b1111 == 0); // suggest trailing_zeros - let _ = x & 0b1_1111 == 0; // suggest trailing_zeros - let _ = x & 0b1_1010 == 0; // do not lint - let _ = x & 1 == 0; // do not lint -} diff --git a/tests/ui/trailing_zeros.stderr b/tests/ui/trailing_zeros.stderr deleted file mode 100644 index 798551118309..000000000000 --- a/tests/ui/trailing_zeros.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: bit mask could be simplified with a call to `trailing_zeros` - --> $DIR/trailing_zeros.rs:6:13 - | -LL | let _ = (x & 0b1111 == 0); // suggest trailing_zeros - | ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 4` - | - = note: `-D clippy::verbose-bit-mask` implied by `-D warnings` - -error: bit mask could be simplified with a call to `trailing_zeros` - --> $DIR/trailing_zeros.rs:7:13 - | -LL | let _ = x & 0b1_1111 == 0; // suggest trailing_zeros - | ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 5` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/trait_duplication_in_bounds.rs b/tests/ui/trait_duplication_in_bounds.rs deleted file mode 100644 index cb2b0054e352..000000000000 --- a/tests/ui/trait_duplication_in_bounds.rs +++ /dev/null @@ -1,31 +0,0 @@ -#![deny(clippy::trait_duplication_in_bounds)] - -use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; - -fn bad_foo(arg0: T, arg1: Z) -where - T: Clone, - T: Default, -{ - unimplemented!(); -} - -fn good_bar(arg: T) { - unimplemented!(); -} - -fn good_foo(arg: T) -where - T: Clone + Default, -{ - unimplemented!(); -} - -fn good_foobar(arg: T) -where - T: Clone, -{ - unimplemented!(); -} - -fn main() {} diff --git a/tests/ui/trait_duplication_in_bounds.stderr b/tests/ui/trait_duplication_in_bounds.stderr deleted file mode 100644 index 027e1c752041..000000000000 --- a/tests/ui/trait_duplication_in_bounds.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error: this trait bound is already specified in the where clause - --> $DIR/trait_duplication_in_bounds.rs:5:15 - | -LL | fn bad_foo(arg0: T, arg1: Z) - | ^^^^^ - | -note: the lint level is defined here - --> $DIR/trait_duplication_in_bounds.rs:1:9 - | -LL | #![deny(clippy::trait_duplication_in_bounds)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: consider removing this trait bound - -error: this trait bound is already specified in the where clause - --> $DIR/trait_duplication_in_bounds.rs:5:23 - | -LL | fn bad_foo(arg0: T, arg1: Z) - | ^^^^^^^ - | - = help: consider removing this trait bound - -error: aborting due to 2 previous errors - diff --git a/tests/ui/transmute.rs b/tests/ui/transmute.rs deleted file mode 100644 index 9f1948359e7d..000000000000 --- a/tests/ui/transmute.rs +++ /dev/null @@ -1,112 +0,0 @@ -#![feature(const_fn_transmute)] -#![allow(dead_code)] - -extern crate core; - -use std::mem::transmute as my_transmute; -use std::vec::Vec as MyVec; - -fn my_int() -> Usize { - Usize(42) -} - -fn my_vec() -> MyVec { - vec![] -} - -#[allow(clippy::needless_lifetimes, clippy::transmute_ptr_to_ptr)] -#[warn(clippy::useless_transmute)] -unsafe fn _generic<'a, T, U: 'a>(t: &'a T) { - let _: &'a T = core::intrinsics::transmute(t); - - let _: &'a U = core::intrinsics::transmute(t); - - let _: *const T = core::intrinsics::transmute(t); - - let _: *mut T = core::intrinsics::transmute(t); - - let _: *const U = core::intrinsics::transmute(t); -} - -#[warn(clippy::useless_transmute)] -fn useless() { - unsafe { - let _: Vec = core::intrinsics::transmute(my_vec()); - - let _: Vec = core::mem::transmute(my_vec()); - - let _: Vec = std::intrinsics::transmute(my_vec()); - - let _: Vec = std::mem::transmute(my_vec()); - - let _: Vec = my_transmute(my_vec()); - - let _: *const usize = std::mem::transmute(5_isize); - - let _ = 5_isize as *const usize; - - let _: *const usize = std::mem::transmute(1 + 1usize); - - let _ = (1 + 1_usize) as *const usize; - } -} - -struct Usize(usize); - -#[warn(clippy::crosspointer_transmute)] -fn crosspointer() { - let mut int: Usize = Usize(0); - let int_const_ptr: *const Usize = &int as *const Usize; - let int_mut_ptr: *mut Usize = &mut int as *mut Usize; - - unsafe { - let _: Usize = core::intrinsics::transmute(int_const_ptr); - - let _: Usize = core::intrinsics::transmute(int_mut_ptr); - - let _: *const Usize = core::intrinsics::transmute(my_int()); - - let _: *mut Usize = core::intrinsics::transmute(my_int()); - } -} - -#[warn(clippy::transmute_int_to_char)] -fn int_to_char() { - let _: char = unsafe { std::mem::transmute(0_u32) }; - let _: char = unsafe { std::mem::transmute(0_i32) }; -} - -#[warn(clippy::transmute_int_to_bool)] -fn int_to_bool() { - let _: bool = unsafe { std::mem::transmute(0_u8) }; -} - -#[warn(clippy::transmute_int_to_float)] -mod int_to_float { - fn test() { - let _: f32 = unsafe { std::mem::transmute(0_u32) }; - let _: f32 = unsafe { std::mem::transmute(0_i32) }; - let _: f64 = unsafe { std::mem::transmute(0_u64) }; - let _: f64 = unsafe { std::mem::transmute(0_i64) }; - } - - mod issue_5747 { - const VALUE32: f32 = unsafe { std::mem::transmute(0_u32) }; - const VALUE64: f64 = unsafe { std::mem::transmute(0_i64) }; - - const fn from_bits_32(v: i32) -> f32 { - unsafe { std::mem::transmute(v) } - } - - const fn from_bits_64(v: u64) -> f64 { - unsafe { std::mem::transmute(v) } - } - } -} - -fn bytes_to_str(b: &[u8], mb: &mut [u8]) { - let _: &str = unsafe { std::mem::transmute(b) }; - let _: &mut str = unsafe { std::mem::transmute(mb) }; -} - -fn main() {} diff --git a/tests/ui/transmute.stderr b/tests/ui/transmute.stderr deleted file mode 100644 index ad9953d12bcc..000000000000 --- a/tests/ui/transmute.stderr +++ /dev/null @@ -1,158 +0,0 @@ -error: transmute from a type (`&T`) to itself - --> $DIR/transmute.rs:20:20 - | -LL | let _: &'a T = core::intrinsics::transmute(t); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::useless-transmute` implied by `-D warnings` - -error: transmute from a reference to a pointer - --> $DIR/transmute.rs:24:23 - | -LL | let _: *const T = core::intrinsics::transmute(t); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T` - -error: transmute from a reference to a pointer - --> $DIR/transmute.rs:26:21 - | -LL | let _: *mut T = core::intrinsics::transmute(t); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *mut T` - -error: transmute from a reference to a pointer - --> $DIR/transmute.rs:28:23 - | -LL | let _: *const U = core::intrinsics::transmute(t); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *const U` - -error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:34:27 - | -LL | let _: Vec = core::intrinsics::transmute(my_vec()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:36:27 - | -LL | let _: Vec = core::mem::transmute(my_vec()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:38:27 - | -LL | let _: Vec = std::intrinsics::transmute(my_vec()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:40:27 - | -LL | let _: Vec = std::mem::transmute(my_vec()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:42:27 - | -LL | let _: Vec = my_transmute(my_vec()); - | ^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from an integer to a pointer - --> $DIR/transmute.rs:44:31 - | -LL | let _: *const usize = std::mem::transmute(5_isize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `5_isize as *const usize` - -error: transmute from an integer to a pointer - --> $DIR/transmute.rs:48:31 - | -LL | let _: *const usize = std::mem::transmute(1 + 1usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(1 + 1usize) as *const usize` - -error: transmute from a type (`*const Usize`) to the type that it points to (`Usize`) - --> $DIR/transmute.rs:63:24 - | -LL | let _: Usize = core::intrinsics::transmute(int_const_ptr); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::crosspointer-transmute` implied by `-D warnings` - -error: transmute from a type (`*mut Usize`) to the type that it points to (`Usize`) - --> $DIR/transmute.rs:65:24 - | -LL | let _: Usize = core::intrinsics::transmute(int_mut_ptr); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from a type (`Usize`) to a pointer to that type (`*const Usize`) - --> $DIR/transmute.rs:67:31 - | -LL | let _: *const Usize = core::intrinsics::transmute(my_int()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize`) - --> $DIR/transmute.rs:69:29 - | -LL | let _: *mut Usize = core::intrinsics::transmute(my_int()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from a `u32` to a `char` - --> $DIR/transmute.rs:75:28 - | -LL | let _: char = unsafe { std::mem::transmute(0_u32) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_u32).unwrap()` - | - = note: `-D clippy::transmute-int-to-char` implied by `-D warnings` - -error: transmute from a `i32` to a `char` - --> $DIR/transmute.rs:76:28 - | -LL | let _: char = unsafe { std::mem::transmute(0_i32) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_i32 as u32).unwrap()` - -error: transmute from a `u8` to a `bool` - --> $DIR/transmute.rs:81:28 - | -LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `0_u8 != 0` - | - = note: `-D clippy::transmute-int-to-bool` implied by `-D warnings` - -error: transmute from a `u32` to a `f32` - --> $DIR/transmute.rs:87:31 - | -LL | let _: f32 = unsafe { std::mem::transmute(0_u32) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_u32)` - | - = note: `-D clippy::transmute-int-to-float` implied by `-D warnings` - -error: transmute from a `i32` to a `f32` - --> $DIR/transmute.rs:88:31 - | -LL | let _: f32 = unsafe { std::mem::transmute(0_i32) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_i32 as u32)` - -error: transmute from a `u64` to a `f64` - --> $DIR/transmute.rs:89:31 - | -LL | let _: f64 = unsafe { std::mem::transmute(0_u64) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_u64)` - -error: transmute from a `i64` to a `f64` - --> $DIR/transmute.rs:90:31 - | -LL | let _: f64 = unsafe { std::mem::transmute(0_i64) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_i64 as u64)` - -error: transmute from a `&[u8]` to a `&str` - --> $DIR/transmute.rs:108:28 - | -LL | let _: &str = unsafe { std::mem::transmute(b) }; - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8(b).unwrap()` - | - = note: `-D clippy::transmute-bytes-to-str` implied by `-D warnings` - -error: transmute from a `&mut [u8]` to a `&mut str` - --> $DIR/transmute.rs:109:32 - | -LL | let _: &mut str = unsafe { std::mem::transmute(mb) }; - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_mut(mb).unwrap()` - -error: aborting due to 24 previous errors - diff --git a/tests/ui/transmute_32bit.rs b/tests/ui/transmute_32bit.rs deleted file mode 100644 index ffe22b12f551..000000000000 --- a/tests/ui/transmute_32bit.rs +++ /dev/null @@ -1,14 +0,0 @@ -// ignore-64bit - -#[warn(clippy::wrong_transmute)] -fn main() { - unsafe { - let _: *const usize = std::mem::transmute(6.0f32); - - let _: *mut usize = std::mem::transmute(6.0f32); - - let _: *const usize = std::mem::transmute('x'); - - let _: *mut usize = std::mem::transmute('x'); - } -} diff --git a/tests/ui/transmute_32bit.stderr b/tests/ui/transmute_32bit.stderr deleted file mode 100644 index 040519564b94..000000000000 --- a/tests/ui/transmute_32bit.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: transmute from a `f32` to a pointer - --> $DIR/transmute_32bit.rs:6:31 - | -LL | let _: *const usize = std::mem::transmute(6.0f32); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::wrong-transmute` implied by `-D warnings` - -error: transmute from a `f32` to a pointer - --> $DIR/transmute_32bit.rs:8:29 - | -LL | let _: *mut usize = std::mem::transmute(6.0f32); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from a `char` to a pointer - --> $DIR/transmute_32bit.rs:10:31 - | -LL | let _: *const usize = std::mem::transmute('x'); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from a `char` to a pointer - --> $DIR/transmute_32bit.rs:12:29 - | -LL | let _: *mut usize = std::mem::transmute('x'); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 4 previous errors - diff --git a/tests/ui/transmute_64bit.rs b/tests/ui/transmute_64bit.rs deleted file mode 100644 index 00dc0b2c3608..000000000000 --- a/tests/ui/transmute_64bit.rs +++ /dev/null @@ -1,10 +0,0 @@ -// ignore-32bit - -#[warn(clippy::wrong_transmute)] -fn main() { - unsafe { - let _: *const usize = std::mem::transmute(6.0f64); - - let _: *mut usize = std::mem::transmute(6.0f64); - } -} diff --git a/tests/ui/transmute_64bit.stderr b/tests/ui/transmute_64bit.stderr deleted file mode 100644 index d1854c009ef5..000000000000 --- a/tests/ui/transmute_64bit.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: transmute from a `f64` to a pointer - --> $DIR/transmute_64bit.rs:6:31 - | -LL | let _: *const usize = std::mem::transmute(6.0f64); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::wrong-transmute` implied by `-D warnings` - -error: transmute from a `f64` to a pointer - --> $DIR/transmute_64bit.rs:8:29 - | -LL | let _: *mut usize = std::mem::transmute(6.0f64); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/transmute_collection.rs b/tests/ui/transmute_collection.rs deleted file mode 100644 index cd5a7127791a..000000000000 --- a/tests/ui/transmute_collection.rs +++ /dev/null @@ -1,47 +0,0 @@ -#![warn(clippy::unsound_collection_transmute)] - -use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; -use std::mem::transmute; - -fn main() { - unsafe { - // wrong size - let _ = transmute::<_, Vec>(vec![0u8]); - // wrong layout - let _ = transmute::<_, Vec<[u8; 4]>>(vec![1234u32]); - - // wrong size - let _ = transmute::<_, VecDeque>(VecDeque::::new()); - // wrong layout - let _ = transmute::<_, VecDeque>(VecDeque::<[u8; 4]>::new()); - - // wrong size - let _ = transmute::<_, BinaryHeap>(BinaryHeap::::new()); - // wrong layout - let _ = transmute::<_, BinaryHeap>(BinaryHeap::<[u8; 4]>::new()); - - // wrong size - let _ = transmute::<_, BTreeSet>(BTreeSet::::new()); - // wrong layout - let _ = transmute::<_, BTreeSet>(BTreeSet::<[u8; 4]>::new()); - - // wrong size - let _ = transmute::<_, HashSet>(HashSet::::new()); - // wrong layout - let _ = transmute::<_, HashSet>(HashSet::<[u8; 4]>::new()); - - // wrong size - let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); - let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); - // wrong layout - let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); - let _ = transmute::<_, BTreeMap>(BTreeMap::<[u8; 4], u32>::new()); - - // wrong size - let _ = transmute::<_, HashMap>(HashMap::::new()); - let _ = transmute::<_, HashMap>(HashMap::::new()); - // wrong layout - let _ = transmute::<_, HashMap>(HashMap::::new()); - let _ = transmute::<_, HashMap>(HashMap::<[u8; 4], u32>::new()); - } -} diff --git a/tests/ui/transmute_collection.stderr b/tests/ui/transmute_collection.stderr deleted file mode 100644 index ebc05c402abf..000000000000 --- a/tests/ui/transmute_collection.stderr +++ /dev/null @@ -1,112 +0,0 @@ -error: transmute from `std::vec::Vec` to `std::vec::Vec` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:9:17 - | -LL | let _ = transmute::<_, Vec>(vec![0u8]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::unsound-collection-transmute` implied by `-D warnings` - -error: transmute from `std::vec::Vec` to `std::vec::Vec<[u8; 4]>` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:11:17 - | -LL | let _ = transmute::<_, Vec<[u8; 4]>>(vec![1234u32]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from `std::collections::VecDeque` to `std::collections::VecDeque` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:14:17 - | -LL | let _ = transmute::<_, VecDeque>(VecDeque::::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from `std::collections::VecDeque<[u8; 4]>` to `std::collections::VecDeque` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:16:17 - | -LL | let _ = transmute::<_, VecDeque>(VecDeque::<[u8; 4]>::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from `std::collections::BinaryHeap` to `std::collections::BinaryHeap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:19:17 - | -LL | let _ = transmute::<_, BinaryHeap>(BinaryHeap::::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from `std::collections::BinaryHeap<[u8; 4]>` to `std::collections::BinaryHeap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:21:17 - | -LL | let _ = transmute::<_, BinaryHeap>(BinaryHeap::<[u8; 4]>::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from `std::collections::BTreeSet` to `std::collections::BTreeSet` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:24:17 - | -LL | let _ = transmute::<_, BTreeSet>(BTreeSet::::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from `std::collections::BTreeSet<[u8; 4]>` to `std::collections::BTreeSet` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:26:17 - | -LL | let _ = transmute::<_, BTreeSet>(BTreeSet::<[u8; 4]>::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from `std::collections::HashSet` to `std::collections::HashSet` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:29:17 - | -LL | let _ = transmute::<_, HashSet>(HashSet::::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from `std::collections::HashSet<[u8; 4]>` to `std::collections::HashSet` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:31:17 - | -LL | let _ = transmute::<_, HashSet>(HashSet::<[u8; 4]>::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:34:17 - | -LL | let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:35:17 - | -LL | let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:37:17 - | -LL | let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from `std::collections::BTreeMap<[u8; 4], u32>` to `std::collections::BTreeMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:38:17 - | -LL | let _ = transmute::<_, BTreeMap>(BTreeMap::<[u8; 4], u32>::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from `std::collections::HashMap` to `std::collections::HashMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:41:17 - | -LL | let _ = transmute::<_, HashMap>(HashMap::::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from `std::collections::HashMap` to `std::collections::HashMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:42:17 - | -LL | let _ = transmute::<_, HashMap>(HashMap::::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from `std::collections::HashMap` to `std::collections::HashMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:44:17 - | -LL | let _ = transmute::<_, HashMap>(HashMap::::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from `std::collections::HashMap<[u8; 4], u32>` to `std::collections::HashMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:45:17 - | -LL | let _ = transmute::<_, HashMap>(HashMap::<[u8; 4], u32>::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 18 previous errors - diff --git a/tests/ui/transmute_float_to_int.rs b/tests/ui/transmute_float_to_int.rs deleted file mode 100644 index 1040fee4b34d..000000000000 --- a/tests/ui/transmute_float_to_int.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![feature(const_fn_transmute)] -#![warn(clippy::transmute_float_to_int)] - -fn float_to_int() { - let _: u32 = unsafe { std::mem::transmute(1f32) }; - let _: i32 = unsafe { std::mem::transmute(1f32) }; - let _: u64 = unsafe { std::mem::transmute(1f64) }; - let _: i64 = unsafe { std::mem::transmute(1f64) }; - let _: u64 = unsafe { std::mem::transmute(1.0) }; - let _: u64 = unsafe { std::mem::transmute(-1.0) }; -} - -mod issue_5747 { - const VALUE32: i32 = unsafe { std::mem::transmute(1f32) }; - const VALUE64: u64 = unsafe { std::mem::transmute(1f64) }; - - const fn to_bits_32(v: f32) -> u32 { - unsafe { std::mem::transmute(v) } - } - - const fn to_bits_64(v: f64) -> i64 { - unsafe { std::mem::transmute(v) } - } -} - -fn main() {} diff --git a/tests/ui/transmute_float_to_int.stderr b/tests/ui/transmute_float_to_int.stderr deleted file mode 100644 index 5a40cf381d61..000000000000 --- a/tests/ui/transmute_float_to_int.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: transmute from a `f32` to a `u32` - --> $DIR/transmute_float_to_int.rs:5:27 - | -LL | let _: u32 = unsafe { std::mem::transmute(1f32) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits()` - | - = note: `-D clippy::transmute-float-to-int` implied by `-D warnings` - -error: transmute from a `f32` to a `i32` - --> $DIR/transmute_float_to_int.rs:6:27 - | -LL | let _: i32 = unsafe { std::mem::transmute(1f32) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits() as i32` - -error: transmute from a `f64` to a `u64` - --> $DIR/transmute_float_to_int.rs:7:27 - | -LL | let _: u64 = unsafe { std::mem::transmute(1f64) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits()` - -error: transmute from a `f64` to a `i64` - --> $DIR/transmute_float_to_int.rs:8:27 - | -LL | let _: i64 = unsafe { std::mem::transmute(1f64) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits() as i64` - -error: transmute from a `f64` to a `u64` - --> $DIR/transmute_float_to_int.rs:9:27 - | -LL | let _: u64 = unsafe { std::mem::transmute(1.0) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.0f64.to_bits()` - -error: transmute from a `f64` to a `u64` - --> $DIR/transmute_float_to_int.rs:10:27 - | -LL | let _: u64 = unsafe { std::mem::transmute(-1.0) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-1.0f64).to_bits()` - -error: aborting due to 6 previous errors - diff --git a/tests/ui/transmute_ptr_to_ptr.rs b/tests/ui/transmute_ptr_to_ptr.rs deleted file mode 100644 index 26b03bdc7405..000000000000 --- a/tests/ui/transmute_ptr_to_ptr.rs +++ /dev/null @@ -1,62 +0,0 @@ -#![warn(clippy::transmute_ptr_to_ptr)] - -// Make sure we can modify lifetimes, which is one of the recommended uses -// of transmute - -// Make sure we can do static lifetime transmutes -unsafe fn transmute_lifetime_to_static<'a, T>(t: &'a T) -> &'static T { - std::mem::transmute::<&'a T, &'static T>(t) -} - -// Make sure we can do non-static lifetime transmutes -unsafe fn transmute_lifetime<'a, 'b, T>(t: &'a T, u: &'b T) -> &'b T { - std::mem::transmute::<&'a T, &'b T>(t) -} - -struct LifetimeParam<'a> { - s: &'a str, -} - -struct GenericParam { - t: T, -} - -fn transmute_ptr_to_ptr() { - let ptr = &1u32 as *const u32; - let mut_ptr = &mut 1u32 as *mut u32; - unsafe { - // pointer-to-pointer transmutes; bad - let _: *const f32 = std::mem::transmute(ptr); - let _: *mut f32 = std::mem::transmute(mut_ptr); - // ref-ref transmutes; bad - let _: &f32 = std::mem::transmute(&1u32); - let _: &f64 = std::mem::transmute(&1f32); - // ^ this test is here because both f32 and f64 are the same TypeVariant, but they are not - // the same type - let _: &mut f32 = std::mem::transmute(&mut 1u32); - let _: &GenericParam = std::mem::transmute(&GenericParam { t: 1u32 }); - } - - // these are recommendations for solving the above; if these lint we need to update - // those suggestions - let _ = ptr as *const f32; - let _ = mut_ptr as *mut f32; - let _ = unsafe { &*(&1u32 as *const u32 as *const f32) }; - let _ = unsafe { &mut *(&mut 1u32 as *mut u32 as *mut f32) }; - - // transmute internal lifetimes, should not lint - let s = "hello world".to_owned(); - let lp = LifetimeParam { s: &s }; - let _: &LifetimeParam<'static> = unsafe { std::mem::transmute(&lp) }; - let _: &GenericParam<&LifetimeParam<'static>> = unsafe { std::mem::transmute(&GenericParam { t: &lp }) }; -} - -// dereferencing raw pointers in const contexts, should not lint as it's unstable (issue 5959) -const _: &() = { - struct ZST; - let zst = &ZST; - - unsafe { std::mem::transmute::<&'static ZST, &'static ()>(zst) } -}; - -fn main() {} diff --git a/tests/ui/transmute_ptr_to_ptr.stderr b/tests/ui/transmute_ptr_to_ptr.stderr deleted file mode 100644 index 4d1b8fcc199e..000000000000 --- a/tests/ui/transmute_ptr_to_ptr.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: transmute from a pointer to a pointer - --> $DIR/transmute_ptr_to_ptr.rs:29:29 - | -LL | let _: *const f32 = std::mem::transmute(ptr); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr as *const f32` - | - = note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` - -error: transmute from a pointer to a pointer - --> $DIR/transmute_ptr_to_ptr.rs:30:27 - | -LL | let _: *mut f32 = std::mem::transmute(mut_ptr); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `mut_ptr as *mut f32` - -error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:32:23 - | -LL | let _: &f32 = std::mem::transmute(&1u32); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&1u32 as *const u32 as *const f32)` - -error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:33:23 - | -LL | let _: &f64 = std::mem::transmute(&1f32); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&1f32 as *const f32 as *const f64)` - -error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:36:27 - | -LL | let _: &mut f32 = std::mem::transmute(&mut 1u32); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(&mut 1u32 as *mut u32 as *mut f32)` - -error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:37:37 - | -LL | let _: &GenericParam = std::mem::transmute(&GenericParam { t: 1u32 }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&GenericParam { t: 1u32 } as *const GenericParam as *const GenericParam)` - -error: aborting due to 6 previous errors - diff --git a/tests/ui/transmute_ptr_to_ref.rs b/tests/ui/transmute_ptr_to_ref.rs deleted file mode 100644 index ba35c6adc4de..000000000000 --- a/tests/ui/transmute_ptr_to_ref.rs +++ /dev/null @@ -1,41 +0,0 @@ -#![warn(clippy::transmute_ptr_to_ref)] - -unsafe fn _ptr_to_ref(p: *const T, m: *mut T, o: *const U, om: *mut U) { - let _: &T = std::mem::transmute(p); - let _: &T = &*p; - - let _: &mut T = std::mem::transmute(m); - let _: &mut T = &mut *m; - - let _: &T = std::mem::transmute(m); - let _: &T = &*m; - - let _: &mut T = std::mem::transmute(p as *mut T); - let _ = &mut *(p as *mut T); - - let _: &T = std::mem::transmute(o); - let _: &T = &*(o as *const T); - - let _: &mut T = std::mem::transmute(om); - let _: &mut T = &mut *(om as *mut T); - - let _: &T = std::mem::transmute(om); - let _: &T = &*(om as *const T); -} - -fn issue1231() { - struct Foo<'a, T> { - bar: &'a T, - } - - let raw = 42 as *const i32; - let _: &Foo = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) }; - - let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) }; - - type Bar<'a> = &'a u8; - let raw = 42 as *const i32; - unsafe { std::mem::transmute::<_, Bar>(raw) }; -} - -fn main() {} diff --git a/tests/ui/transmute_ptr_to_ref.stderr b/tests/ui/transmute_ptr_to_ref.stderr deleted file mode 100644 index df0598a58cd3..000000000000 --- a/tests/ui/transmute_ptr_to_ref.stderr +++ /dev/null @@ -1,64 +0,0 @@ -error: transmute from a pointer type (`*const T`) to a reference type (`&T`) - --> $DIR/transmute_ptr_to_ref.rs:4:17 - | -LL | let _: &T = std::mem::transmute(p); - | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*p` - | - = note: `-D clippy::transmute-ptr-to-ref` implied by `-D warnings` - -error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`) - --> $DIR/transmute_ptr_to_ref.rs:7:21 - | -LL | let _: &mut T = std::mem::transmute(m); - | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *m` - -error: transmute from a pointer type (`*mut T`) to a reference type (`&T`) - --> $DIR/transmute_ptr_to_ref.rs:10:17 - | -LL | let _: &T = std::mem::transmute(m); - | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*m` - -error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`) - --> $DIR/transmute_ptr_to_ref.rs:13:21 - | -LL | let _: &mut T = std::mem::transmute(p as *mut T); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(p as *mut T)` - -error: transmute from a pointer type (`*const U`) to a reference type (`&T`) - --> $DIR/transmute_ptr_to_ref.rs:16:17 - | -LL | let _: &T = std::mem::transmute(o); - | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(o as *const T)` - -error: transmute from a pointer type (`*mut U`) to a reference type (`&mut T`) - --> $DIR/transmute_ptr_to_ref.rs:19:21 - | -LL | let _: &mut T = std::mem::transmute(om); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(om as *mut T)` - -error: transmute from a pointer type (`*mut U`) to a reference type (`&T`) - --> $DIR/transmute_ptr_to_ref.rs:22:17 - | -LL | let _: &T = std::mem::transmute(om); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(om as *const T)` - -error: transmute from a pointer type (`*const i32`) to a reference type (`&issue1231::Foo`) - --> $DIR/transmute_ptr_to_ref.rs:32:32 - | -LL | let _: &Foo = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const Foo<_>)` - -error: transmute from a pointer type (`*const i32`) to a reference type (`&issue1231::Foo<&u8>`) - --> $DIR/transmute_ptr_to_ref.rs:34:33 - | -LL | let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const Foo<&_>)` - -error: transmute from a pointer type (`*const i32`) to a reference type (`&u8`) - --> $DIR/transmute_ptr_to_ref.rs:38:14 - | -LL | unsafe { std::mem::transmute::<_, Bar>(raw) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const u8)` - -error: aborting due to 10 previous errors - diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.fixed b/tests/ui/transmutes_expressible_as_ptr_casts.fixed deleted file mode 100644 index b6f1e83181cc..000000000000 --- a/tests/ui/transmutes_expressible_as_ptr_casts.fixed +++ /dev/null @@ -1,78 +0,0 @@ -// run-rustfix -#![warn(clippy::transmutes_expressible_as_ptr_casts)] -// These two warnings currrently cover the cases transmutes_expressible_as_ptr_casts -// would otherwise be responsible for -#![warn(clippy::useless_transmute)] -#![warn(clippy::transmute_ptr_to_ptr)] -#![allow(unused_unsafe)] -#![allow(dead_code)] - -use std::mem::{size_of, transmute}; - -// rustc_typeck::check::cast contains documentation about when a cast `e as U` is -// valid, which we quote from below. -fn main() { - // We should see an error message for each transmute, and no error messages for - // the casts, since the casts are the recommended fixes. - - // e is an integer and U is *U_0, while U_0: Sized; addr-ptr-cast - let _ptr_i32_transmute = unsafe { usize::MAX as *const i32 }; - let ptr_i32 = usize::MAX as *const i32; - - // e has type *T, U is *U_0, and either U_0: Sized ... - let _ptr_i8_transmute = unsafe { ptr_i32 as *const i8 }; - let _ptr_i8 = ptr_i32 as *const i8; - - let slice_ptr = &[0, 1, 2, 3] as *const [i32]; - - // ... or pointer_kind(T) = pointer_kind(U_0); ptr-ptr-cast - let _ptr_to_unsized_transmute = unsafe { slice_ptr as *const [u16] }; - let _ptr_to_unsized = slice_ptr as *const [u16]; - // TODO: We could try testing vtable casts here too, but maybe - // we should wait until std::raw::TraitObject is stabilized? - - // e has type *T and U is a numeric type, while T: Sized; ptr-addr-cast - let _usize_from_int_ptr_transmute = unsafe { ptr_i32 as usize }; - let _usize_from_int_ptr = ptr_i32 as usize; - - let array_ref: &[i32; 4] = &[1, 2, 3, 4]; - - // e has type &[T; n] and U is *const T; array-ptr-cast - let _array_ptr_transmute = unsafe { array_ref as *const [i32; 4] }; - let _array_ptr = array_ref as *const [i32; 4]; - - fn foo(_: usize) -> u8 { - 42 - } - - // e is a function pointer type and U has type *T, while T: Sized; fptr-ptr-cast - let _usize_ptr_transmute = unsafe { foo as *const usize }; - let _usize_ptr_transmute = foo as *const usize; - - // e is a function pointer type and U is an integer; fptr-addr-cast - let _usize_from_fn_ptr_transmute = unsafe { foo as usize }; - let _usize_from_fn_ptr = foo as *const usize; -} - -// If a ref-to-ptr cast of this form where the pointer type points to a type other -// than the referenced type, calling `CastCheck::do_check` has been observed to -// cause an ICE error message. `do_check` is currently called inside the -// `transmutes_expressible_as_ptr_casts` check, but other, more specific lints -// currently prevent it from being called in these cases. This test is meant to -// fail if the ordering of the checks ever changes enough to cause these cases to -// fall through into `do_check`. -fn trigger_do_check_to_emit_error(in_param: &[i32; 1]) -> *const u8 { - unsafe { in_param as *const [i32; 1] as *const u8 } -} - -#[repr(C)] -struct Single(u64); - -#[repr(C)] -struct Pair(u32, u32); - -fn cannot_be_expressed_as_pointer_cast(in_param: Single) -> Pair { - assert_eq!(size_of::(), size_of::()); - - unsafe { transmute::(in_param) } -} diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs deleted file mode 100644 index 0205d1ece60d..000000000000 --- a/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ /dev/null @@ -1,78 +0,0 @@ -// run-rustfix -#![warn(clippy::transmutes_expressible_as_ptr_casts)] -// These two warnings currrently cover the cases transmutes_expressible_as_ptr_casts -// would otherwise be responsible for -#![warn(clippy::useless_transmute)] -#![warn(clippy::transmute_ptr_to_ptr)] -#![allow(unused_unsafe)] -#![allow(dead_code)] - -use std::mem::{size_of, transmute}; - -// rustc_typeck::check::cast contains documentation about when a cast `e as U` is -// valid, which we quote from below. -fn main() { - // We should see an error message for each transmute, and no error messages for - // the casts, since the casts are the recommended fixes. - - // e is an integer and U is *U_0, while U_0: Sized; addr-ptr-cast - let _ptr_i32_transmute = unsafe { transmute::(usize::MAX) }; - let ptr_i32 = usize::MAX as *const i32; - - // e has type *T, U is *U_0, and either U_0: Sized ... - let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr_i32) }; - let _ptr_i8 = ptr_i32 as *const i8; - - let slice_ptr = &[0, 1, 2, 3] as *const [i32]; - - // ... or pointer_kind(T) = pointer_kind(U_0); ptr-ptr-cast - let _ptr_to_unsized_transmute = unsafe { transmute::<*const [i32], *const [u16]>(slice_ptr) }; - let _ptr_to_unsized = slice_ptr as *const [u16]; - // TODO: We could try testing vtable casts here too, but maybe - // we should wait until std::raw::TraitObject is stabilized? - - // e has type *T and U is a numeric type, while T: Sized; ptr-addr-cast - let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, usize>(ptr_i32) }; - let _usize_from_int_ptr = ptr_i32 as usize; - - let array_ref: &[i32; 4] = &[1, 2, 3, 4]; - - // e has type &[T; n] and U is *const T; array-ptr-cast - let _array_ptr_transmute = unsafe { transmute::<&[i32; 4], *const [i32; 4]>(array_ref) }; - let _array_ptr = array_ref as *const [i32; 4]; - - fn foo(_: usize) -> u8 { - 42 - } - - // e is a function pointer type and U has type *T, while T: Sized; fptr-ptr-cast - let _usize_ptr_transmute = unsafe { transmute:: u8, *const usize>(foo) }; - let _usize_ptr_transmute = foo as *const usize; - - // e is a function pointer type and U is an integer; fptr-addr-cast - let _usize_from_fn_ptr_transmute = unsafe { transmute:: u8, usize>(foo) }; - let _usize_from_fn_ptr = foo as *const usize; -} - -// If a ref-to-ptr cast of this form where the pointer type points to a type other -// than the referenced type, calling `CastCheck::do_check` has been observed to -// cause an ICE error message. `do_check` is currently called inside the -// `transmutes_expressible_as_ptr_casts` check, but other, more specific lints -// currently prevent it from being called in these cases. This test is meant to -// fail if the ordering of the checks ever changes enough to cause these cases to -// fall through into `do_check`. -fn trigger_do_check_to_emit_error(in_param: &[i32; 1]) -> *const u8 { - unsafe { transmute::<&[i32; 1], *const u8>(in_param) } -} - -#[repr(C)] -struct Single(u64); - -#[repr(C)] -struct Pair(u32, u32); - -fn cannot_be_expressed_as_pointer_cast(in_param: Single) -> Pair { - assert_eq!(size_of::(), size_of::()); - - unsafe { transmute::(in_param) } -} diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.stderr b/tests/ui/transmutes_expressible_as_ptr_casts.stderr deleted file mode 100644 index 1157b179317e..000000000000 --- a/tests/ui/transmutes_expressible_as_ptr_casts.stderr +++ /dev/null @@ -1,56 +0,0 @@ -error: transmute from an integer to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:19:39 - | -LL | let _ptr_i32_transmute = unsafe { transmute::(usize::MAX) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `usize::MAX as *const i32` - | - = note: `-D clippy::useless-transmute` implied by `-D warnings` - -error: transmute from a pointer to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:23:38 - | -LL | let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr_i32) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as *const i8` - | - = note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` - -error: transmute from a pointer to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:29:46 - | -LL | let _ptr_to_unsized_transmute = unsafe { transmute::<*const [i32], *const [u16]>(slice_ptr) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `slice_ptr as *const [u16]` - -error: transmute from `*const i32` to `usize` which could be expressed as a pointer cast instead - --> $DIR/transmutes_expressible_as_ptr_casts.rs:35:50 - | -LL | let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, usize>(ptr_i32) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as usize` - | - = note: `-D clippy::transmutes-expressible-as-ptr-casts` implied by `-D warnings` - -error: transmute from a reference to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:41:41 - | -LL | let _array_ptr_transmute = unsafe { transmute::<&[i32; 4], *const [i32; 4]>(array_ref) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `array_ref as *const [i32; 4]` - -error: transmute from `fn(usize) -> u8 {main::foo}` to `*const usize` which could be expressed as a pointer cast instead - --> $DIR/transmutes_expressible_as_ptr_casts.rs:49:41 - | -LL | let _usize_ptr_transmute = unsafe { transmute:: u8, *const usize>(foo) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as *const usize` - -error: transmute from `fn(usize) -> u8 {main::foo}` to `usize` which could be expressed as a pointer cast instead - --> $DIR/transmutes_expressible_as_ptr_casts.rs:53:49 - | -LL | let _usize_from_fn_ptr_transmute = unsafe { transmute:: u8, usize>(foo) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as usize` - -error: transmute from a reference to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:65:14 - | -LL | unsafe { transmute::<&[i32; 1], *const u8>(in_param) } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `in_param as *const [i32; 1] as *const u8` - -error: aborting due to 8 previous errors - diff --git a/tests/ui/transmuting_null.rs b/tests/ui/transmuting_null.rs deleted file mode 100644 index ea3ee8edc81b..000000000000 --- a/tests/ui/transmuting_null.rs +++ /dev/null @@ -1,30 +0,0 @@ -#![allow(dead_code)] -#![warn(clippy::transmuting_null)] -#![allow(clippy::zero_ptr)] -#![allow(clippy::transmute_ptr_to_ref)] -#![allow(clippy::eq_op)] - -// Easy to lint because these only span one line. -fn one_liners() { - unsafe { - let _: &u64 = std::mem::transmute(0 as *const u64); - let _: &u64 = std::mem::transmute(std::ptr::null::()); - } -} - -pub const ZPTR: *const usize = 0 as *const _; -pub const NOT_ZPTR: *const usize = 1 as *const _; - -fn transmute_const() { - unsafe { - // Should raise a lint. - let _: &u64 = std::mem::transmute(ZPTR); - // Should NOT raise a lint. - let _: &u64 = std::mem::transmute(NOT_ZPTR); - } -} - -fn main() { - one_liners(); - transmute_const(); -} diff --git a/tests/ui/transmuting_null.stderr b/tests/ui/transmuting_null.stderr deleted file mode 100644 index 05f91ee2adaa..000000000000 --- a/tests/ui/transmuting_null.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: transmuting a known null pointer into a reference. - --> $DIR/transmuting_null.rs:10:23 - | -LL | let _: &u64 = std::mem::transmute(0 as *const u64); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::transmuting-null` implied by `-D warnings` - -error: transmuting a known null pointer into a reference. - --> $DIR/transmuting_null.rs:11:23 - | -LL | let _: &u64 = std::mem::transmute(std::ptr::null::()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmuting a known null pointer into a reference. - --> $DIR/transmuting_null.rs:21:23 - | -LL | let _: &u64 = std::mem::transmute(ZPTR); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/trivially_copy_pass_by_ref.rs b/tests/ui/trivially_copy_pass_by_ref.rs deleted file mode 100644 index e7e0a31febc4..000000000000 --- a/tests/ui/trivially_copy_pass_by_ref.rs +++ /dev/null @@ -1,132 +0,0 @@ -// normalize-stderr-test "\(\d+ byte\)" -> "(N byte)" -// normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)" - -#![deny(clippy::trivially_copy_pass_by_ref)] -#![allow( - clippy::many_single_char_names, - clippy::blacklisted_name, - clippy::redundant_field_names -)] - -#[derive(Copy, Clone)] -struct Foo(u32); - -#[derive(Copy, Clone)] -struct Bar([u8; 24]); - -#[derive(Copy, Clone)] -pub struct Color { - pub r: u8, - pub g: u8, - pub b: u8, - pub a: u8, -} - -struct FooRef<'a> { - foo: &'a Foo, -} - -type Baz = u32; - -fn good(a: &mut u32, b: u32, c: &Bar) {} - -fn good_return_implicit_lt_ref(foo: &Foo) -> &u32 { - &foo.0 -} - -#[allow(clippy::needless_lifetimes)] -fn good_return_explicit_lt_ref<'a>(foo: &'a Foo) -> &'a u32 { - &foo.0 -} - -fn good_return_implicit_lt_struct(foo: &Foo) -> FooRef { - FooRef { foo } -} - -#[allow(clippy::needless_lifetimes)] -fn good_return_explicit_lt_struct<'a>(foo: &'a Foo) -> FooRef<'a> { - FooRef { foo } -} - -fn bad(x: &u32, y: &Foo, z: &Baz) {} - -impl Foo { - fn good(self, a: &mut u32, b: u32, c: &Bar) {} - - fn good2(&mut self) {} - - fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} - - fn bad2(x: &u32, y: &Foo, z: &Baz) {} -} - -impl AsRef for Foo { - fn as_ref(&self) -> &u32 { - &self.0 - } -} - -impl Bar { - fn good(&self, a: &mut u32, b: u32, c: &Bar) {} - - fn bad2(x: &u32, y: &Foo, z: &Baz) {} -} - -trait MyTrait { - fn trait_method(&self, _foo: &Foo); -} - -pub trait MyTrait2 { - fn trait_method2(&self, _color: &Color); -} - -impl MyTrait for Foo { - fn trait_method(&self, _foo: &Foo) { - unimplemented!() - } -} - -#[allow(unused_variables)] -mod issue3992 { - pub trait A { - #[allow(clippy::trivially_copy_pass_by_ref)] - fn a(b: &u16) {} - } - - #[allow(clippy::trivially_copy_pass_by_ref)] - pub fn c(d: &u16) {} -} - -mod issue5876 { - // Don't lint here as it is always inlined - #[inline(always)] - fn foo_always(x: &i32) { - println!("{}", x); - } - - #[inline(never)] - fn foo_never(x: &i32) { - println!("{}", x); - } - - #[inline] - fn foo(x: &i32) { - println!("{}", x); - } -} - -fn main() { - let (mut foo, bar) = (Foo(0), Bar([0; 24])); - let (mut a, b, c, x, y, z) = (0, 0, Bar([0; 24]), 0, Foo(0), 0); - good(&mut a, b, &c); - good_return_implicit_lt_ref(&y); - good_return_explicit_lt_ref(&y); - bad(&x, &y, &z); - foo.good(&mut a, b, &c); - foo.good2(); - foo.bad(&x, &y, &z); - Foo::bad2(&x, &y, &z); - bar.good(&mut a, b, &c); - Bar::bad2(&x, &y, &z); - foo.as_ref(); -} diff --git a/tests/ui/trivially_copy_pass_by_ref.stderr b/tests/ui/trivially_copy_pass_by_ref.stderr deleted file mode 100644 index ccc3cdb2b742..000000000000 --- a/tests/ui/trivially_copy_pass_by_ref.stderr +++ /dev/null @@ -1,110 +0,0 @@ -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:51:11 - | -LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} - | ^^^^ help: consider passing by value instead: `u32` - | -note: the lint level is defined here - --> $DIR/trivially_copy_pass_by_ref.rs:4:9 - | -LL | #![deny(clippy::trivially_copy_pass_by_ref)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:51:20 - | -LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} - | ^^^^ help: consider passing by value instead: `Foo` - -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:51:29 - | -LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} - | ^^^^ help: consider passing by value instead: `Baz` - -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:58:12 - | -LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} - | ^^^^^ help: consider passing by value instead: `self` - -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:58:22 - | -LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} - | ^^^^ help: consider passing by value instead: `u32` - -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:58:31 - | -LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} - | ^^^^ help: consider passing by value instead: `Foo` - -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:58:40 - | -LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} - | ^^^^ help: consider passing by value instead: `Baz` - -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:60:16 - | -LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} - | ^^^^ help: consider passing by value instead: `u32` - -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:60:25 - | -LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} - | ^^^^ help: consider passing by value instead: `Foo` - -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:60:34 - | -LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} - | ^^^^ help: consider passing by value instead: `Baz` - -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:72:16 - | -LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} - | ^^^^ help: consider passing by value instead: `u32` - -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:72:25 - | -LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} - | ^^^^ help: consider passing by value instead: `Foo` - -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:72:34 - | -LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} - | ^^^^ help: consider passing by value instead: `Baz` - -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:76:34 - | -LL | fn trait_method(&self, _foo: &Foo); - | ^^^^ help: consider passing by value instead: `Foo` - -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:80:37 - | -LL | fn trait_method2(&self, _color: &Color); - | ^^^^^^ help: consider passing by value instead: `Color` - -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:108:21 - | -LL | fn foo_never(x: &i32) { - | ^^^^ help: consider passing by value instead: `i32` - -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:113:15 - | -LL | fn foo(x: &i32) { - | ^^^^ help: consider passing by value instead: `i32` - -error: aborting due to 17 previous errors - diff --git a/tests/ui/try_err.fixed b/tests/ui/try_err.fixed deleted file mode 100644 index 652b611208b7..000000000000 --- a/tests/ui/try_err.fixed +++ /dev/null @@ -1,162 +0,0 @@ -// run-rustfix -// aux-build:macro_rules.rs - -#![deny(clippy::try_err)] -#![allow(clippy::unnecessary_wraps)] - -#[macro_use] -extern crate macro_rules; - -use std::io; -use std::task::Poll; - -// Tests that a simple case works -// Should flag `Err(err)?` -pub fn basic_test() -> Result { - let err: i32 = 1; - // To avoid warnings during rustfix - if true { - return Err(err); - } - Ok(0) -} - -// Tests that `.into()` is added when appropriate -pub fn into_test() -> Result { - let err: u8 = 1; - // To avoid warnings during rustfix - if true { - return Err(err.into()); - } - Ok(0) -} - -// Tests that tries in general don't trigger the error -pub fn negative_test() -> Result { - Ok(nested_error()? + 1) -} - -// Tests that `.into()` isn't added when the error type -// matches the surrounding closure's return type, even -// when it doesn't match the surrounding function's. -pub fn closure_matches_test() -> Result { - let res: Result = Some(1) - .into_iter() - .map(|i| { - let err: i8 = 1; - // To avoid warnings during rustfix - if true { - return Err(err); - } - Ok(i) - }) - .next() - .unwrap(); - - Ok(res?) -} - -// Tests that `.into()` isn't added when the error type -// doesn't match the surrounding closure's return type. -pub fn closure_into_test() -> Result { - let res: Result = Some(1) - .into_iter() - .map(|i| { - let err: i8 = 1; - // To avoid warnings during rustfix - if true { - return Err(err.into()); - } - Ok(i) - }) - .next() - .unwrap(); - - Ok(res?) -} - -fn nested_error() -> Result { - Ok(1) -} - -// Bad suggestion when in macro (see #6242) -macro_rules! try_validation { - ($e: expr) => {{ - match $e { - Ok(_) => 0, - Err(_) => return Err(1), - } - }}; -} - -macro_rules! ret_one { - () => { - 1 - }; -} - -macro_rules! try_validation_in_macro { - ($e: expr) => {{ - match $e { - Ok(_) => 0, - Err(_) => return Err(ret_one!()), - } - }}; -} - -fn calling_macro() -> Result { - // macro - try_validation!(Ok::<_, i32>(5)); - // `Err` arg is another macro - try_validation_in_macro!(Ok::<_, i32>(5)); - Ok(5) -} - -fn main() { - basic_test().unwrap(); - into_test().unwrap(); - negative_test().unwrap(); - closure_matches_test().unwrap(); - closure_into_test().unwrap(); - calling_macro().unwrap(); - - // We don't want to lint in external macros - try_err!(); -} - -macro_rules! bar { - () => { - String::from("aasdfasdfasdfa") - }; -} - -macro_rules! foo { - () => { - bar!() - }; -} - -pub fn macro_inside(fail: bool) -> Result { - if fail { - return Err(foo!()); - } - Ok(0) -} - -pub fn poll_write(n: usize) -> Poll> { - if n == 0 { - return Poll::Ready(Err(io::ErrorKind::WriteZero.into())) - } else if n == 1 { - return Poll::Ready(Err(io::Error::new(io::ErrorKind::InvalidInput, "error"))) - }; - - Poll::Ready(Ok(n)) -} - -pub fn poll_next(ready: bool) -> Poll>> { - if !ready { - return Poll::Ready(Some(Err(io::ErrorKind::NotFound.into()))) - } - - Poll::Ready(None) -} diff --git a/tests/ui/try_err.rs b/tests/ui/try_err.rs deleted file mode 100644 index 6bd479657b70..000000000000 --- a/tests/ui/try_err.rs +++ /dev/null @@ -1,162 +0,0 @@ -// run-rustfix -// aux-build:macro_rules.rs - -#![deny(clippy::try_err)] -#![allow(clippy::unnecessary_wraps)] - -#[macro_use] -extern crate macro_rules; - -use std::io; -use std::task::Poll; - -// Tests that a simple case works -// Should flag `Err(err)?` -pub fn basic_test() -> Result { - let err: i32 = 1; - // To avoid warnings during rustfix - if true { - Err(err)?; - } - Ok(0) -} - -// Tests that `.into()` is added when appropriate -pub fn into_test() -> Result { - let err: u8 = 1; - // To avoid warnings during rustfix - if true { - Err(err)?; - } - Ok(0) -} - -// Tests that tries in general don't trigger the error -pub fn negative_test() -> Result { - Ok(nested_error()? + 1) -} - -// Tests that `.into()` isn't added when the error type -// matches the surrounding closure's return type, even -// when it doesn't match the surrounding function's. -pub fn closure_matches_test() -> Result { - let res: Result = Some(1) - .into_iter() - .map(|i| { - let err: i8 = 1; - // To avoid warnings during rustfix - if true { - Err(err)?; - } - Ok(i) - }) - .next() - .unwrap(); - - Ok(res?) -} - -// Tests that `.into()` isn't added when the error type -// doesn't match the surrounding closure's return type. -pub fn closure_into_test() -> Result { - let res: Result = Some(1) - .into_iter() - .map(|i| { - let err: i8 = 1; - // To avoid warnings during rustfix - if true { - Err(err)?; - } - Ok(i) - }) - .next() - .unwrap(); - - Ok(res?) -} - -fn nested_error() -> Result { - Ok(1) -} - -// Bad suggestion when in macro (see #6242) -macro_rules! try_validation { - ($e: expr) => {{ - match $e { - Ok(_) => 0, - Err(_) => Err(1)?, - } - }}; -} - -macro_rules! ret_one { - () => { - 1 - }; -} - -macro_rules! try_validation_in_macro { - ($e: expr) => {{ - match $e { - Ok(_) => 0, - Err(_) => Err(ret_one!())?, - } - }}; -} - -fn calling_macro() -> Result { - // macro - try_validation!(Ok::<_, i32>(5)); - // `Err` arg is another macro - try_validation_in_macro!(Ok::<_, i32>(5)); - Ok(5) -} - -fn main() { - basic_test().unwrap(); - into_test().unwrap(); - negative_test().unwrap(); - closure_matches_test().unwrap(); - closure_into_test().unwrap(); - calling_macro().unwrap(); - - // We don't want to lint in external macros - try_err!(); -} - -macro_rules! bar { - () => { - String::from("aasdfasdfasdfa") - }; -} - -macro_rules! foo { - () => { - bar!() - }; -} - -pub fn macro_inside(fail: bool) -> Result { - if fail { - Err(foo!())?; - } - Ok(0) -} - -pub fn poll_write(n: usize) -> Poll> { - if n == 0 { - Err(io::ErrorKind::WriteZero)? - } else if n == 1 { - Err(io::Error::new(io::ErrorKind::InvalidInput, "error"))? - }; - - Poll::Ready(Ok(n)) -} - -pub fn poll_next(ready: bool) -> Poll>> { - if !ready { - Err(io::ErrorKind::NotFound)? - } - - Poll::Ready(None) -} diff --git a/tests/ui/try_err.stderr b/tests/ui/try_err.stderr deleted file mode 100644 index 2c01d37192e8..000000000000 --- a/tests/ui/try_err.stderr +++ /dev/null @@ -1,78 +0,0 @@ -error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:19:9 - | -LL | Err(err)?; - | ^^^^^^^^^ help: try this: `return Err(err)` - | -note: the lint level is defined here - --> $DIR/try_err.rs:4:9 - | -LL | #![deny(clippy::try_err)] - | ^^^^^^^^^^^^^^^ - -error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:29:9 - | -LL | Err(err)?; - | ^^^^^^^^^ help: try this: `return Err(err.into())` - -error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:49:17 - | -LL | Err(err)?; - | ^^^^^^^^^ help: try this: `return Err(err)` - -error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:68:17 - | -LL | Err(err)?; - | ^^^^^^^^^ help: try this: `return Err(err.into())` - -error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:87:23 - | -LL | Err(_) => Err(1)?, - | ^^^^^^^ help: try this: `return Err(1)` -... -LL | try_validation!(Ok::<_, i32>(5)); - | --------------------------------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:102:23 - | -LL | Err(_) => Err(ret_one!())?, - | ^^^^^^^^^^^^^^^^ help: try this: `return Err(ret_one!())` -... -LL | try_validation_in_macro!(Ok::<_, i32>(5)); - | ------------------------------------------ in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:141:9 - | -LL | Err(foo!())?; - | ^^^^^^^^^^^^ help: try this: `return Err(foo!())` - -error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:148:9 - | -LL | Err(io::ErrorKind::WriteZero)? - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `return Poll::Ready(Err(io::ErrorKind::WriteZero.into()))` - -error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:150:9 - | -LL | Err(io::Error::new(io::ErrorKind::InvalidInput, "error"))? - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `return Poll::Ready(Err(io::Error::new(io::ErrorKind::InvalidInput, "error")))` - -error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:158:9 - | -LL | Err(io::ErrorKind::NotFound)? - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `return Poll::Ready(Some(Err(io::ErrorKind::NotFound.into())))` - -error: aborting due to 10 previous errors - diff --git a/tests/ui/ty_fn_sig.rs b/tests/ui/ty_fn_sig.rs deleted file mode 100644 index 9e2753dcb18d..000000000000 --- a/tests/ui/ty_fn_sig.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Regression test - -pub fn retry(f: F) { - for _i in 0.. { - f(); - } -} - -fn main() { - for y in 0..4 { - let func = || (); - func(); - } -} diff --git a/tests/ui/type_repetition_in_bounds.rs b/tests/ui/type_repetition_in_bounds.rs deleted file mode 100644 index 766190f20997..000000000000 --- a/tests/ui/type_repetition_in_bounds.rs +++ /dev/null @@ -1,72 +0,0 @@ -#![deny(clippy::type_repetition_in_bounds)] - -use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; - -pub fn foo(_t: T) -where - T: Copy, - T: Clone, -{ - unimplemented!(); -} - -pub fn bar(_t: T, _u: U) -where - T: Copy, - U: Clone, -{ - unimplemented!(); -} - -// Threshold test (see #4380) -trait LintBounds -where - Self: Clone, - Self: Copy + Default + Ord, - Self: Add + AddAssign + Sub + SubAssign, - Self: Mul + MulAssign + Div + DivAssign, -{ -} - -trait LotsOfBounds -where - Self: Clone + Copy + Default + Ord, - Self: Add + AddAssign + Sub + SubAssign, - Self: Mul + MulAssign + Div + DivAssign, -{ -} - -// Generic distinction (see #4323) -mod issue4323 { - pub struct Foo(A); - pub struct Bar { - a: Foo, - b: Foo, - } - - impl Unpin for Bar - where - Foo: Unpin, - Foo: Unpin, - { - } -} - -// Extern macros shouldn't lint (see #4326) -extern crate serde; -mod issue4326 { - use serde::{Deserialize, Serialize}; - - trait Foo {} - impl Foo for String {} - - #[derive(Debug, Serialize, Deserialize)] - struct Bar - where - S: Foo, - { - foo: S, - } -} - -fn main() {} diff --git a/tests/ui/type_repetition_in_bounds.stderr b/tests/ui/type_repetition_in_bounds.stderr deleted file mode 100644 index 148c19c7d070..000000000000 --- a/tests/ui/type_repetition_in_bounds.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error: this type has already been used as a bound predicate - --> $DIR/type_repetition_in_bounds.rs:8:5 - | -LL | T: Clone, - | ^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/type_repetition_in_bounds.rs:1:9 - | -LL | #![deny(clippy::type_repetition_in_bounds)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: consider combining the bounds: `T: Copy + Clone` - -error: this type has already been used as a bound predicate - --> $DIR/type_repetition_in_bounds.rs:25:5 - | -LL | Self: Copy + Default + Ord, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider combining the bounds: `Self: Clone + Copy + Default + Ord` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/types.fixed b/tests/ui/types.fixed deleted file mode 100644 index 417da42edf17..000000000000 --- a/tests/ui/types.fixed +++ /dev/null @@ -1,15 +0,0 @@ -// run-rustfix - -#![allow(dead_code, unused_variables)] -#![warn(clippy::cast_lossless)] - -// should not warn on lossy casting in constant types -// because not supported yet -const C: i32 = 42; -const C_I64: i64 = C as i64; - -fn main() { - // should suggest i64::from(c) - let c: i32 = 42; - let c_i64: i64 = i64::from(c); -} diff --git a/tests/ui/types.rs b/tests/ui/types.rs deleted file mode 100644 index b16e9e538b10..000000000000 --- a/tests/ui/types.rs +++ /dev/null @@ -1,15 +0,0 @@ -// run-rustfix - -#![allow(dead_code, unused_variables)] -#![warn(clippy::cast_lossless)] - -// should not warn on lossy casting in constant types -// because not supported yet -const C: i32 = 42; -const C_I64: i64 = C as i64; - -fn main() { - // should suggest i64::from(c) - let c: i32 = 42; - let c_i64: i64 = c as i64; -} diff --git a/tests/ui/types.stderr b/tests/ui/types.stderr deleted file mode 100644 index 59c3e05a1aa3..000000000000 --- a/tests/ui/types.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: casting `i32` to `i64` may become silently lossy if you later change the type - --> $DIR/types.rs:14:22 - | -LL | let c_i64: i64 = c as i64; - | ^^^^^^^^ help: try: `i64::from(c)` - | - = note: `-D clippy::cast-lossless` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/undropped_manually_drops.rs b/tests/ui/undropped_manually_drops.rs deleted file mode 100644 index f4cfc92e1cd0..000000000000 --- a/tests/ui/undropped_manually_drops.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![warn(clippy::undropped_manually_drops)] - -struct S; - -fn main() { - let f = std::mem::drop; - let g = std::mem::ManuallyDrop::drop; - let mut manual1 = std::mem::ManuallyDrop::new(S); - let mut manual2 = std::mem::ManuallyDrop::new(S); - let mut manual3 = std::mem::ManuallyDrop::new(S); - let mut manual4 = std::mem::ManuallyDrop::new(S); - - // These lines will not drop `S` and should be linted - drop(std::mem::ManuallyDrop::new(S)); - drop(manual1); - - // FIXME: this line is not linted, though it should be - f(manual2); - - // These lines will drop `S` and should be okay. - unsafe { - std::mem::ManuallyDrop::drop(&mut std::mem::ManuallyDrop::new(S)); - std::mem::ManuallyDrop::drop(&mut manual3); - g(&mut manual4); - } -} diff --git a/tests/ui/undropped_manually_drops.stderr b/tests/ui/undropped_manually_drops.stderr deleted file mode 100644 index 2ac0fe98697e..000000000000 --- a/tests/ui/undropped_manually_drops.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: the inner value of this ManuallyDrop will not be dropped - --> $DIR/undropped_manually_drops.rs:14:5 - | -LL | drop(std::mem::ManuallyDrop::new(S)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::undropped-manually-drops` implied by `-D warnings` - = help: to drop a `ManuallyDrop`, use std::mem::ManuallyDrop::drop - -error: the inner value of this ManuallyDrop will not be dropped - --> $DIR/undropped_manually_drops.rs:15:5 - | -LL | drop(manual1); - | ^^^^^^^^^^^^^ - | - = help: to drop a `ManuallyDrop`, use std::mem::ManuallyDrop::drop - -error: aborting due to 2 previous errors - diff --git a/tests/ui/unicode.rs b/tests/ui/unicode.rs deleted file mode 100644 index 1f596c312fe3..000000000000 --- a/tests/ui/unicode.rs +++ /dev/null @@ -1,27 +0,0 @@ -#[warn(clippy::invisible_characters)] -fn zero() { - print!("Here >​< is a ZWS, and ​another"); - print!("This\u{200B}is\u{200B}fine"); - print!("Here >­< is a SHY, and ­another"); - print!("This\u{ad}is\u{ad}fine"); - print!("Here >⁠< is a WJ, and ⁠another"); - print!("This\u{2060}is\u{2060}fine"); -} - -#[warn(clippy::unicode_not_nfc)] -fn canon() { - print!("̀àh?"); - print!("a\u{0300}h?"); // also ok -} - -#[warn(clippy::non_ascii_literal)] -fn uni() { - print!("Üben!"); - print!("\u{DC}ben!"); // this is ok -} - -fn main() { - zero(); - uni(); - canon(); -} diff --git a/tests/ui/unicode.stderr b/tests/ui/unicode.stderr deleted file mode 100644 index 3fca463c620b..000000000000 --- a/tests/ui/unicode.stderr +++ /dev/null @@ -1,38 +0,0 @@ -error: invisible character detected - --> $DIR/unicode.rs:3:12 - | -LL | print!("Here >​< is a ZWS, and ​another"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >/u{200B}< is a ZWS, and /u{200B}another"` - | - = note: `-D clippy::invisible-characters` implied by `-D warnings` - -error: invisible character detected - --> $DIR/unicode.rs:5:12 - | -LL | print!("Here >­< is a SHY, and ­another"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >/u{AD}< is a SHY, and /u{AD}another"` - -error: invisible character detected - --> $DIR/unicode.rs:7:12 - | -LL | print!("Here >⁠< is a WJ, and ⁠another"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >/u{2060}< is a WJ, and /u{2060}another"` - -error: non-NFC Unicode sequence detected - --> $DIR/unicode.rs:13:12 - | -LL | print!("̀àh?"); - | ^^^^^ help: consider replacing the string with: `"̀àh?"` - | - = note: `-D clippy::unicode-not-nfc` implied by `-D warnings` - -error: literal non-ASCII character detected - --> $DIR/unicode.rs:19:12 - | -LL | print!("Üben!"); - | ^^^^^^^ help: consider replacing the string with: `"/u{dc}ben!"` - | - = note: `-D clippy::non-ascii-literal` implied by `-D warnings` - -error: aborting due to 5 previous errors - diff --git a/tests/ui/uninit.rs b/tests/ui/uninit.rs deleted file mode 100644 index f42b884e0f0e..000000000000 --- a/tests/ui/uninit.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![feature(stmt_expr_attributes)] - -use std::mem::MaybeUninit; - -fn main() { - let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; - - // edge case: For now we lint on empty arrays - let _: [u8; 0] = unsafe { MaybeUninit::uninit().assume_init() }; - - // edge case: For now we accept unit tuples - let _: () = unsafe { MaybeUninit::uninit().assume_init() }; - - // This is OK, because `MaybeUninit` allows uninitialized data. - let _: MaybeUninit = unsafe { MaybeUninit::uninit().assume_init() }; - - // This is OK, because all constitutent types are uninit-compatible. - let _: (MaybeUninit, MaybeUninit) = unsafe { MaybeUninit::uninit().assume_init() }; - - // This is OK, because all constitutent types are uninit-compatible. - let _: (MaybeUninit, [MaybeUninit; 2]) = unsafe { MaybeUninit::uninit().assume_init() }; -} diff --git a/tests/ui/uninit.stderr b/tests/ui/uninit.stderr deleted file mode 100644 index a37233ecddae..000000000000 --- a/tests/ui/uninit.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: this call for this type may be undefined behavior - --> $DIR/uninit.rs:6:29 - | -LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[deny(clippy::uninit_assumed_init)]` on by default - -error: this call for this type may be undefined behavior - --> $DIR/uninit.rs:9:31 - | -LL | let _: [u8; 0] = unsafe { MaybeUninit::uninit().assume_init() }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/unit_arg.rs b/tests/ui/unit_arg.rs deleted file mode 100644 index 9ad16d365094..000000000000 --- a/tests/ui/unit_arg.rs +++ /dev/null @@ -1,102 +0,0 @@ -#![warn(clippy::unit_arg)] -#![allow( - clippy::no_effect, - unused_must_use, - unused_variables, - clippy::unused_unit, - clippy::unnecessary_wraps, - clippy::or_fun_call -)] - -use std::fmt::Debug; - -fn foo(t: T) { - println!("{:?}", t); -} - -fn foo3(t1: T1, t2: T2, t3: T3) { - println!("{:?}, {:?}, {:?}", t1, t2, t3); -} - -struct Bar; - -impl Bar { - fn bar(&self, t: T) { - println!("{:?}", t); - } -} - -fn bad() { - foo({ - 1; - }); - foo(foo(1)); - foo({ - foo(1); - foo(2); - }); - let b = Bar; - b.bar({ - 1; - }); - taking_multiple_units(foo(0), foo(1)); - taking_multiple_units(foo(0), { - foo(1); - foo(2); - }); - taking_multiple_units( - { - foo(0); - foo(1); - }, - { - foo(2); - foo(3); - }, - ); - // here Some(foo(2)) isn't the top level statement expression, wrap the suggestion in a block - None.or(Some(foo(2))); - // in this case, the suggestion can be inlined, no need for a surrounding block - // foo(()); foo(()) instead of { foo(()); foo(()) } - foo(foo(())) -} - -fn ok() { - foo(()); - foo(1); - foo({ 1 }); - foo3("a", 3, vec![3]); - let b = Bar; - b.bar({ 1 }); - b.bar(()); - question_mark(); -} - -fn question_mark() -> Result<(), ()> { - Ok(Ok(())?)?; - Ok(Ok(()))??; - Ok(()) -} - -#[allow(dead_code)] -mod issue_2945 { - fn unit_fn() -> Result<(), i32> { - Ok(()) - } - - fn fallible() -> Result<(), i32> { - Ok(unit_fn()?) - } -} - -#[allow(dead_code)] -fn returning_expr() -> Option<()> { - Some(foo(1)) -} - -fn taking_multiple_units(a: (), b: ()) {} - -fn main() { - bad(); - ok(); -} diff --git a/tests/ui/unit_arg.stderr b/tests/ui/unit_arg.stderr deleted file mode 100644 index c3a839a9bf81..000000000000 --- a/tests/ui/unit_arg.stderr +++ /dev/null @@ -1,181 +0,0 @@ -error: passing a unit value to a function - --> $DIR/unit_arg.rs:30:5 - | -LL | / foo({ -LL | | 1; -LL | | }); - | |______^ - | - = note: `-D clippy::unit-arg` implied by `-D warnings` -help: remove the semicolon from the last statement in the block - | -LL | 1 - | -help: or move the expression in front of the call and replace it with the unit literal `()` - | -LL | { -LL | 1; -LL | }; -LL | foo(()); - | - -error: passing a unit value to a function - --> $DIR/unit_arg.rs:33:5 - | -LL | foo(foo(1)); - | ^^^^^^^^^^^ - | -help: move the expression in front of the call and replace it with the unit literal `()` - | -LL | foo(1); -LL | foo(()); - | - -error: passing a unit value to a function - --> $DIR/unit_arg.rs:34:5 - | -LL | / foo({ -LL | | foo(1); -LL | | foo(2); -LL | | }); - | |______^ - | -help: remove the semicolon from the last statement in the block - | -LL | foo(2) - | -help: or move the expression in front of the call and replace it with the unit literal `()` - | -LL | { -LL | foo(1); -LL | foo(2); -LL | }; -LL | foo(()); - | - -error: passing a unit value to a function - --> $DIR/unit_arg.rs:39:5 - | -LL | / b.bar({ -LL | | 1; -LL | | }); - | |______^ - | -help: remove the semicolon from the last statement in the block - | -LL | 1 - | -help: or move the expression in front of the call and replace it with the unit literal `()` - | -LL | { -LL | 1; -LL | }; -LL | b.bar(()); - | - -error: passing unit values to a function - --> $DIR/unit_arg.rs:42:5 - | -LL | taking_multiple_units(foo(0), foo(1)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: move the expressions in front of the call and replace them with the unit literal `()` - | -LL | foo(0); -LL | foo(1); -LL | taking_multiple_units((), ()); - | - -error: passing unit values to a function - --> $DIR/unit_arg.rs:43:5 - | -LL | / taking_multiple_units(foo(0), { -LL | | foo(1); -LL | | foo(2); -LL | | }); - | |______^ - | -help: remove the semicolon from the last statement in the block - | -LL | foo(2) - | -help: or move the expressions in front of the call and replace them with the unit literal `()` - | -LL | foo(0); -LL | { -LL | foo(1); -LL | foo(2); -LL | }; -LL | taking_multiple_units((), ()); - | - -error: passing unit values to a function - --> $DIR/unit_arg.rs:47:5 - | -LL | / taking_multiple_units( -LL | | { -LL | | foo(0); -LL | | foo(1); -... | -LL | | }, -LL | | ); - | |_____^ - | -help: remove the semicolon from the last statement in the block - | -LL | foo(1) - | -help: remove the semicolon from the last statement in the block - | -LL | foo(3) - | -help: or move the expressions in front of the call and replace them with the unit literal `()` - | -LL | { -LL | foo(0); -LL | foo(1); -LL | }; -LL | { -LL | foo(2); - ... - -error: passing a unit value to a function - --> $DIR/unit_arg.rs:58:13 - | -LL | None.or(Some(foo(2))); - | ^^^^^^^^^^^^ - | -help: move the expression in front of the call and replace it with the unit literal `()` - | -LL | None.or({ -LL | foo(2); -LL | Some(()) -LL | }); - | - -error: passing a unit value to a function - --> $DIR/unit_arg.rs:61:5 - | -LL | foo(foo(())) - | ^^^^^^^^^^^^ - | -help: move the expression in front of the call and replace it with the unit literal `()` - | -LL | foo(()); -LL | foo(()) - | - -error: passing a unit value to a function - --> $DIR/unit_arg.rs:94:5 - | -LL | Some(foo(1)) - | ^^^^^^^^^^^^ - | -help: move the expression in front of the call and replace it with the unit literal `()` - | -LL | foo(1); -LL | Some(()) - | - -error: aborting due to 10 previous errors - diff --git a/tests/ui/unit_arg_empty_blocks.rs b/tests/ui/unit_arg_empty_blocks.rs deleted file mode 100644 index 18a31eb3deee..000000000000 --- a/tests/ui/unit_arg_empty_blocks.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![warn(clippy::unit_arg)] -#![allow(clippy::no_effect, unused_must_use, unused_variables)] - -use std::fmt::Debug; - -fn foo(t: T) { - println!("{:?}", t); -} - -fn foo3(t1: T1, t2: T2, t3: T3) { - println!("{:?}, {:?}, {:?}", t1, t2, t3); -} - -fn bad() { - foo({}); - foo3({}, 2, 2); - taking_two_units({}, foo(0)); - taking_three_units({}, foo(0), foo(1)); -} - -fn taking_two_units(a: (), b: ()) {} -fn taking_three_units(a: (), b: (), c: ()) {} - -fn main() { - bad(); -} diff --git a/tests/ui/unit_arg_empty_blocks.stderr b/tests/ui/unit_arg_empty_blocks.stderr deleted file mode 100644 index 456b12a2c6b1..000000000000 --- a/tests/ui/unit_arg_empty_blocks.stderr +++ /dev/null @@ -1,45 +0,0 @@ -error: passing a unit value to a function - --> $DIR/unit_arg_empty_blocks.rs:15:5 - | -LL | foo({}); - | ^^^^--^ - | | - | help: use a unit literal instead: `()` - | - = note: `-D clippy::unit-arg` implied by `-D warnings` - -error: passing a unit value to a function - --> $DIR/unit_arg_empty_blocks.rs:16:5 - | -LL | foo3({}, 2, 2); - | ^^^^^--^^^^^^^ - | | - | help: use a unit literal instead: `()` - -error: passing unit values to a function - --> $DIR/unit_arg_empty_blocks.rs:17:5 - | -LL | taking_two_units({}, foo(0)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: move the expression in front of the call and replace it with the unit literal `()` - | -LL | foo(0); -LL | taking_two_units((), ()); - | - -error: passing unit values to a function - --> $DIR/unit_arg_empty_blocks.rs:18:5 - | -LL | taking_three_units({}, foo(0), foo(1)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: move the expressions in front of the call and replace them with the unit literal `()` - | -LL | foo(0); -LL | foo(1); -LL | taking_three_units((), (), ()); - | - -error: aborting due to 4 previous errors - diff --git a/tests/ui/unit_cmp.rs b/tests/ui/unit_cmp.rs deleted file mode 100644 index 8d3a4eed82e3..000000000000 --- a/tests/ui/unit_cmp.rs +++ /dev/null @@ -1,57 +0,0 @@ -#![warn(clippy::unit_cmp)] -#![allow(clippy::no_effect, clippy::unnecessary_operation)] - -#[derive(PartialEq)] -pub struct ContainsUnit(()); // should be fine - -fn main() { - // this is fine - if true == false {} - - // this warns - if { - true; - } == { - false; - } {} - - if { - true; - } > { - false; - } {} - - assert_eq!( - { - true; - }, - { - false; - } - ); - debug_assert_eq!( - { - true; - }, - { - false; - } - ); - - assert_ne!( - { - true; - }, - { - false; - } - ); - debug_assert_ne!( - { - true; - }, - { - false; - } - ); -} diff --git a/tests/ui/unit_cmp.stderr b/tests/ui/unit_cmp.stderr deleted file mode 100644 index c8c0a85dfc10..000000000000 --- a/tests/ui/unit_cmp.stderr +++ /dev/null @@ -1,82 +0,0 @@ -error: ==-comparison of unit values detected. This will always be true - --> $DIR/unit_cmp.rs:12:8 - | -LL | if { - | ________^ -LL | | true; -LL | | } == { -LL | | false; -LL | | } {} - | |_____^ - | - = note: `-D clippy::unit-cmp` implied by `-D warnings` - -error: >-comparison of unit values detected. This will always be false - --> $DIR/unit_cmp.rs:18:8 - | -LL | if { - | ________^ -LL | | true; -LL | | } > { -LL | | false; -LL | | } {} - | |_____^ - -error: `assert_eq` of unit values detected. This will always succeed - --> $DIR/unit_cmp.rs:24:5 - | -LL | / assert_eq!( -LL | | { -LL | | true; -LL | | }, -... | -LL | | } -LL | | ); - | |______^ - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `debug_assert_eq` of unit values detected. This will always succeed - --> $DIR/unit_cmp.rs:32:5 - | -LL | / debug_assert_eq!( -LL | | { -LL | | true; -LL | | }, -... | -LL | | } -LL | | ); - | |______^ - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `assert_ne` of unit values detected. This will always fail - --> $DIR/unit_cmp.rs:41:5 - | -LL | / assert_ne!( -LL | | { -LL | | true; -LL | | }, -... | -LL | | } -LL | | ); - | |______^ - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: `debug_assert_ne` of unit values detected. This will always fail - --> $DIR/unit_cmp.rs:49:5 - | -LL | / debug_assert_ne!( -LL | | { -LL | | true; -LL | | }, -... | -LL | | } -LL | | ); - | |______^ - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 6 previous errors - diff --git a/tests/ui/unit_return_expecting_ord.rs b/tests/ui/unit_return_expecting_ord.rs deleted file mode 100644 index bdb4710cc697..000000000000 --- a/tests/ui/unit_return_expecting_ord.rs +++ /dev/null @@ -1,36 +0,0 @@ -#![warn(clippy::unit_return_expecting_ord)] -#![allow(clippy::needless_return)] -#![allow(clippy::unused_unit)] -#![feature(is_sorted)] - -struct Struct { - field: isize, -} - -fn double(i: isize) -> isize { - i * 2 -} - -fn unit(_i: isize) {} - -fn main() { - let mut structs = vec![Struct { field: 2 }, Struct { field: 1 }]; - structs.sort_by_key(|s| { - double(s.field); - }); - structs.sort_by_key(|s| double(s.field)); - structs.is_sorted_by_key(|s| { - double(s.field); - }); - structs.is_sorted_by_key(|s| { - if s.field > 0 { - () - } else { - return (); - } - }); - structs.sort_by_key(|s| { - return double(s.field); - }); - structs.sort_by_key(|s| unit(s.field)); -} diff --git a/tests/ui/unit_return_expecting_ord.stderr b/tests/ui/unit_return_expecting_ord.stderr deleted file mode 100644 index e63d58746090..000000000000 --- a/tests/ui/unit_return_expecting_ord.stderr +++ /dev/null @@ -1,39 +0,0 @@ -error: this closure returns the unit type which also implements Ord - --> $DIR/unit_return_expecting_ord.rs:18:25 - | -LL | structs.sort_by_key(|s| { - | ^^^ - | - = note: `-D clippy::unit-return-expecting-ord` implied by `-D warnings` -help: probably caused by this trailing semicolon - --> $DIR/unit_return_expecting_ord.rs:19:24 - | -LL | double(s.field); - | ^ - -error: this closure returns the unit type which also implements PartialOrd - --> $DIR/unit_return_expecting_ord.rs:22:30 - | -LL | structs.is_sorted_by_key(|s| { - | ^^^ - | -help: probably caused by this trailing semicolon - --> $DIR/unit_return_expecting_ord.rs:23:24 - | -LL | double(s.field); - | ^ - -error: this closure returns the unit type which also implements PartialOrd - --> $DIR/unit_return_expecting_ord.rs:25:30 - | -LL | structs.is_sorted_by_key(|s| { - | ^^^ - -error: this closure returns the unit type which also implements Ord - --> $DIR/unit_return_expecting_ord.rs:35:25 - | -LL | structs.sort_by_key(|s| unit(s.field)); - | ^^^ - -error: aborting due to 4 previous errors - diff --git a/tests/ui/unknown_attribute.rs b/tests/ui/unknown_attribute.rs deleted file mode 100644 index e993e63f8ed8..000000000000 --- a/tests/ui/unknown_attribute.rs +++ /dev/null @@ -1,3 +0,0 @@ -#[clippy::unknown] -#[clippy::cognitive_complexity = "1"] -fn main() {} diff --git a/tests/ui/unknown_attribute.stderr b/tests/ui/unknown_attribute.stderr deleted file mode 100644 index 618c5980d64e..000000000000 --- a/tests/ui/unknown_attribute.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: usage of unknown attribute - --> $DIR/unknown_attribute.rs:1:11 - | -LL | #[clippy::unknown] - | ^^^^^^^ - -error: aborting due to previous error - diff --git a/tests/ui/unknown_clippy_lints.fixed b/tests/ui/unknown_clippy_lints.fixed deleted file mode 100644 index 4249ff8a958d..000000000000 --- a/tests/ui/unknown_clippy_lints.fixed +++ /dev/null @@ -1,18 +0,0 @@ -// run-rustfix - -#![warn(clippy::pedantic)] -// Should suggest lowercase -#![allow(clippy::all)] -#![warn(clippy::cmp_nan)] - -// Should suggest similar clippy lint name -#[warn(clippy::if_not_else)] -#[warn(clippy::unnecessary_cast)] -#[warn(clippy::useless_transmute)] -// Shouldn't suggest rustc lint name(`dead_code`) -#[warn(clippy::drop_copy)] -// Shouldn't suggest removed/deprecated clippy lint name(`unused_collect`) -#[warn(clippy::unused_self)] -// Shouldn't suggest renamed clippy lint name(`const_static_lifetime`) -#[warn(clippy::redundant_static_lifetimes)] -fn main() {} diff --git a/tests/ui/unknown_clippy_lints.rs b/tests/ui/unknown_clippy_lints.rs deleted file mode 100644 index 5db345f54441..000000000000 --- a/tests/ui/unknown_clippy_lints.rs +++ /dev/null @@ -1,18 +0,0 @@ -// run-rustfix - -#![warn(clippy::pedantic)] -// Should suggest lowercase -#![allow(clippy::All)] -#![warn(clippy::CMP_NAN)] - -// Should suggest similar clippy lint name -#[warn(clippy::if_not_els)] -#[warn(clippy::UNNecsaRy_cAst)] -#[warn(clippy::useles_transute)] -// Shouldn't suggest rustc lint name(`dead_code`) -#[warn(clippy::dead_cod)] -// Shouldn't suggest removed/deprecated clippy lint name(`unused_collect`) -#[warn(clippy::unused_colle)] -// Shouldn't suggest renamed clippy lint name(`const_static_lifetime`) -#[warn(clippy::const_static_lifetim)] -fn main() {} diff --git a/tests/ui/unknown_clippy_lints.stderr b/tests/ui/unknown_clippy_lints.stderr deleted file mode 100644 index 1b859043bb53..000000000000 --- a/tests/ui/unknown_clippy_lints.stderr +++ /dev/null @@ -1,52 +0,0 @@ -error: unknown clippy lint: clippy::if_not_els - --> $DIR/unknown_clippy_lints.rs:9:8 - | -LL | #[warn(clippy::if_not_els)] - | ^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::if_not_else` - | - = note: `-D clippy::unknown-clippy-lints` implied by `-D warnings` - -error: unknown clippy lint: clippy::UNNecsaRy_cAst - --> $DIR/unknown_clippy_lints.rs:10:8 - | -LL | #[warn(clippy::UNNecsaRy_cAst)] - | ^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::unnecessary_cast` - -error: unknown clippy lint: clippy::useles_transute - --> $DIR/unknown_clippy_lints.rs:11:8 - | -LL | #[warn(clippy::useles_transute)] - | ^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::useless_transmute` - -error: unknown clippy lint: clippy::dead_cod - --> $DIR/unknown_clippy_lints.rs:13:8 - | -LL | #[warn(clippy::dead_cod)] - | ^^^^^^^^^^^^^^^^ help: did you mean: `clippy::drop_copy` - -error: unknown clippy lint: clippy::unused_colle - --> $DIR/unknown_clippy_lints.rs:15:8 - | -LL | #[warn(clippy::unused_colle)] - | ^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::unused_self` - -error: unknown clippy lint: clippy::const_static_lifetim - --> $DIR/unknown_clippy_lints.rs:17:8 - | -LL | #[warn(clippy::const_static_lifetim)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::redundant_static_lifetimes` - -error: unknown clippy lint: clippy::All - --> $DIR/unknown_clippy_lints.rs:5:10 - | -LL | #![allow(clippy::All)] - | ^^^^^^^^^^^ help: lowercase the lint name: `clippy::all` - -error: unknown clippy lint: clippy::CMP_NAN - --> $DIR/unknown_clippy_lints.rs:6:9 - | -LL | #![warn(clippy::CMP_NAN)] - | ^^^^^^^^^^^^^^^ help: lowercase the lint name: `clippy::cmp_nan` - -error: aborting due to 8 previous errors - diff --git a/tests/ui/unnecessary_cast.rs b/tests/ui/unnecessary_cast.rs deleted file mode 100644 index e8f2fb466659..000000000000 --- a/tests/ui/unnecessary_cast.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![warn(clippy::unnecessary_cast)] -#![allow(clippy::no_effect)] - -fn main() { - // Test cast_unnecessary - 1i32 as i32; - 1f32 as f32; - false as bool; - &1i32 as &i32; - - // macro version - macro_rules! foo { - ($a:ident, $b:ident) => { - #[allow(unused)] - pub fn $a() -> $b { - 1 as $b - } - }; - } - foo!(a, i32); - foo!(b, f32); - foo!(c, f64); - - // do not lint cast to cfg-dependant type - 1 as std::os::raw::c_char; -} diff --git a/tests/ui/unnecessary_cast.stderr b/tests/ui/unnecessary_cast.stderr deleted file mode 100644 index 8981d13e8eab..000000000000 --- a/tests/ui/unnecessary_cast.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: casting to the same type is unnecessary (`i32` -> `i32`) - --> $DIR/unnecessary_cast.rs:6:5 - | -LL | 1i32 as i32; - | ^^^^^^^^^^^ - | - = note: `-D clippy::unnecessary-cast` implied by `-D warnings` - -error: casting to the same type is unnecessary (`f32` -> `f32`) - --> $DIR/unnecessary_cast.rs:7:5 - | -LL | 1f32 as f32; - | ^^^^^^^^^^^ - -error: casting to the same type is unnecessary (`bool` -> `bool`) - --> $DIR/unnecessary_cast.rs:8:5 - | -LL | false as bool; - | ^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/unnecessary_cast_fixable.fixed b/tests/ui/unnecessary_cast_fixable.fixed deleted file mode 100644 index 7fbce58a82f8..000000000000 --- a/tests/ui/unnecessary_cast_fixable.fixed +++ /dev/null @@ -1,40 +0,0 @@ -// run-rustfix - -#![warn(clippy::unnecessary_cast)] -#![allow(clippy::no_effect, clippy::unnecessary_operation)] - -fn main() { - // casting integer literal to float is unnecessary - 100_f32; - 100_f64; - 100_f64; - let _ = -100_f32; - let _ = -100_f64; - let _ = -100_f64; - 100_f32; - 100_f64; - // Should not trigger - #[rustfmt::skip] - let v = vec!(1); - &v as &[i32]; - 0x10 as f32; - 0o10 as f32; - 0b10 as f32; - 0x11 as f64; - 0o11 as f64; - 0b11 as f64; - - 1_u32; - 0x10_i32; - 0b10_usize; - 0o73_u16; - 1_000_000_000_u32; - - 1.0_f64; - 0.5_f32; - - 1.0 as u16; - - let _ = -1_i32; - let _ = -1.0_f32; -} diff --git a/tests/ui/unnecessary_cast_fixable.rs b/tests/ui/unnecessary_cast_fixable.rs deleted file mode 100644 index a71363ea4d26..000000000000 --- a/tests/ui/unnecessary_cast_fixable.rs +++ /dev/null @@ -1,40 +0,0 @@ -// run-rustfix - -#![warn(clippy::unnecessary_cast)] -#![allow(clippy::no_effect, clippy::unnecessary_operation)] - -fn main() { - // casting integer literal to float is unnecessary - 100 as f32; - 100 as f64; - 100_i32 as f64; - let _ = -100 as f32; - let _ = -100 as f64; - let _ = -100_i32 as f64; - 100. as f32; - 100. as f64; - // Should not trigger - #[rustfmt::skip] - let v = vec!(1); - &v as &[i32]; - 0x10 as f32; - 0o10 as f32; - 0b10 as f32; - 0x11 as f64; - 0o11 as f64; - 0b11 as f64; - - 1 as u32; - 0x10 as i32; - 0b10 as usize; - 0o73 as u16; - 1_000_000_000 as u32; - - 1.0 as f64; - 0.5 as f32; - - 1.0 as u16; - - let _ = -1 as i32; - let _ = -1.0 as f32; -} diff --git a/tests/ui/unnecessary_cast_fixable.stderr b/tests/ui/unnecessary_cast_fixable.stderr deleted file mode 100644 index 3695a8f819c4..000000000000 --- a/tests/ui/unnecessary_cast_fixable.stderr +++ /dev/null @@ -1,106 +0,0 @@ -error: casting integer literal to `f32` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:8:5 - | -LL | 100 as f32; - | ^^^^^^^^^^ help: try: `100_f32` - | - = note: `-D clippy::unnecessary-cast` implied by `-D warnings` - -error: casting integer literal to `f64` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:9:5 - | -LL | 100 as f64; - | ^^^^^^^^^^ help: try: `100_f64` - -error: casting integer literal to `f64` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:10:5 - | -LL | 100_i32 as f64; - | ^^^^^^^^^^^^^^ help: try: `100_f64` - -error: casting integer literal to `f32` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:11:13 - | -LL | let _ = -100 as f32; - | ^^^^^^^^^^^ help: try: `-100_f32` - -error: casting integer literal to `f64` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:12:13 - | -LL | let _ = -100 as f64; - | ^^^^^^^^^^^ help: try: `-100_f64` - -error: casting integer literal to `f64` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:13:13 - | -LL | let _ = -100_i32 as f64; - | ^^^^^^^^^^^^^^^ help: try: `-100_f64` - -error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:14:5 - | -LL | 100. as f32; - | ^^^^^^^^^^^ help: try: `100_f32` - -error: casting float literal to `f64` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:15:5 - | -LL | 100. as f64; - | ^^^^^^^^^^^ help: try: `100_f64` - -error: casting integer literal to `u32` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:27:5 - | -LL | 1 as u32; - | ^^^^^^^^ help: try: `1_u32` - -error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:28:5 - | -LL | 0x10 as i32; - | ^^^^^^^^^^^ help: try: `0x10_i32` - -error: casting integer literal to `usize` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:29:5 - | -LL | 0b10 as usize; - | ^^^^^^^^^^^^^ help: try: `0b10_usize` - -error: casting integer literal to `u16` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:30:5 - | -LL | 0o73 as u16; - | ^^^^^^^^^^^ help: try: `0o73_u16` - -error: casting integer literal to `u32` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:31:5 - | -LL | 1_000_000_000 as u32; - | ^^^^^^^^^^^^^^^^^^^^ help: try: `1_000_000_000_u32` - -error: casting float literal to `f64` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:33:5 - | -LL | 1.0 as f64; - | ^^^^^^^^^^ help: try: `1.0_f64` - -error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:34:5 - | -LL | 0.5 as f32; - | ^^^^^^^^^^ help: try: `0.5_f32` - -error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:38:13 - | -LL | let _ = -1 as i32; - | ^^^^^^^^^ help: try: `-1_i32` - -error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast_fixable.rs:39:13 - | -LL | let _ = -1.0 as f32; - | ^^^^^^^^^^^ help: try: `-1.0_f32` - -error: aborting due to 17 previous errors - diff --git a/tests/ui/unnecessary_clone.rs b/tests/ui/unnecessary_clone.rs deleted file mode 100644 index 6770a7fac90f..000000000000 --- a/tests/ui/unnecessary_clone.rs +++ /dev/null @@ -1,110 +0,0 @@ -// does not test any rustfixable lints - -#![warn(clippy::clone_on_ref_ptr)] -#![allow(unused, clippy::redundant_clone, clippy::unnecessary_wraps)] - -use std::cell::RefCell; -use std::rc::{self, Rc}; -use std::sync::{self, Arc}; - -trait SomeTrait {} -struct SomeImpl; -impl SomeTrait for SomeImpl {} - -fn main() {} - -fn clone_on_ref_ptr() { - let rc = Rc::new(true); - let arc = Arc::new(true); - - let rcweak = Rc::downgrade(&rc); - let arc_weak = Arc::downgrade(&arc); - - rc.clone(); - Rc::clone(&rc); - - arc.clone(); - Arc::clone(&arc); - - rcweak.clone(); - rc::Weak::clone(&rcweak); - - arc_weak.clone(); - sync::Weak::clone(&arc_weak); - - let x = Arc::new(SomeImpl); - let _: Arc = x.clone(); -} - -fn clone_on_copy_generic(t: T) { - t.clone(); - - Some(t).clone(); -} - -fn clone_on_double_ref() { - let x = vec![1]; - let y = &&x; - let z: &Vec<_> = y.clone(); - - println!("{:p} {:p}", *y, z); -} - -mod many_derefs { - struct A; - struct B; - struct C; - struct D; - #[derive(Copy, Clone)] - struct E; - - macro_rules! impl_deref { - ($src:ident, $dst:ident) => { - impl std::ops::Deref for $src { - type Target = $dst; - fn deref(&self) -> &Self::Target { - &$dst - } - } - }; - } - - impl_deref!(A, B); - impl_deref!(B, C); - impl_deref!(C, D); - impl std::ops::Deref for D { - type Target = &'static E; - fn deref(&self) -> &Self::Target { - &&E - } - } - - fn go1() { - let a = A; - let _: E = a.clone(); - let _: E = *****a; - } - - fn check(mut encoded: &[u8]) { - let _ = &mut encoded.clone(); - let _ = &encoded.clone(); - } -} - -mod issue2076 { - use std::rc::Rc; - - macro_rules! try_opt { - ($expr: expr) => { - match $expr { - Some(value) => value, - None => return None, - } - }; - } - - fn func() -> Option> { - let rc = Rc::new(42); - Some(try_opt!(Some(rc)).clone()) - } -} diff --git a/tests/ui/unnecessary_clone.stderr b/tests/ui/unnecessary_clone.stderr deleted file mode 100644 index 9df1ae568673..000000000000 --- a/tests/ui/unnecessary_clone.stderr +++ /dev/null @@ -1,106 +0,0 @@ -error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:23:5 - | -LL | rc.clone(); - | ^^^^^^^^^^ help: try this: `Rc::::clone(&rc)` - | - = note: `-D clippy::clone-on-ref-ptr` implied by `-D warnings` - -error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:26:5 - | -LL | arc.clone(); - | ^^^^^^^^^^^ help: try this: `Arc::::clone(&arc)` - -error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:29:5 - | -LL | rcweak.clone(); - | ^^^^^^^^^^^^^^ help: try this: `Weak::::clone(&rcweak)` - -error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:32:5 - | -LL | arc_weak.clone(); - | ^^^^^^^^^^^^^^^^ help: try this: `Weak::::clone(&arc_weak)` - -error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:36:33 - | -LL | let _: Arc = x.clone(); - | ^^^^^^^^^ help: try this: `Arc::::clone(&x)` - -error: using `clone` on type `T` which implements the `Copy` trait - --> $DIR/unnecessary_clone.rs:40:5 - | -LL | t.clone(); - | ^^^^^^^^^ help: try removing the `clone` call: `t` - | - = note: `-D clippy::clone-on-copy` implied by `-D warnings` - -error: using `clone` on type `std::option::Option` which implements the `Copy` trait - --> $DIR/unnecessary_clone.rs:42:5 - | -LL | Some(t).clone(); - | ^^^^^^^^^^^^^^^ help: try removing the `clone` call: `Some(t)` - -error: using `clone` on a double-reference; this will copy the reference of type `&std::vec::Vec` instead of cloning the inner type - --> $DIR/unnecessary_clone.rs:48:22 - | -LL | let z: &Vec<_> = y.clone(); - | ^^^^^^^^^ - | - = note: `#[deny(clippy::clone_double_ref)]` on by default -help: try dereferencing it - | -LL | let z: &Vec<_> = &(*y).clone(); - | ^^^^^^^^^^^^^ -help: or try being explicit if you are sure, that you want to clone a reference - | -LL | let z: &Vec<_> = <&std::vec::Vec>::clone(y); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: using `clone` on type `many_derefs::E` which implements the `Copy` trait - --> $DIR/unnecessary_clone.rs:84:20 - | -LL | let _: E = a.clone(); - | ^^^^^^^^^ help: try dereferencing it: `*****a` - -error: using `clone` on a double-reference; this will copy the reference of type `&[u8]` instead of cloning the inner type - --> $DIR/unnecessary_clone.rs:89:22 - | -LL | let _ = &mut encoded.clone(); - | ^^^^^^^^^^^^^^^ - | -help: try dereferencing it - | -LL | let _ = &mut &(*encoded).clone(); - | ^^^^^^^^^^^^^^^^^^^ -help: or try being explicit if you are sure, that you want to clone a reference - | -LL | let _ = &mut <&[u8]>::clone(encoded); - | ^^^^^^^^^^^^^^^^^^^^^^^ - -error: using `clone` on a double-reference; this will copy the reference of type `&[u8]` instead of cloning the inner type - --> $DIR/unnecessary_clone.rs:90:18 - | -LL | let _ = &encoded.clone(); - | ^^^^^^^^^^^^^^^ - | -help: try dereferencing it - | -LL | let _ = &&(*encoded).clone(); - | ^^^^^^^^^^^^^^^^^^^ -help: or try being explicit if you are sure, that you want to clone a reference - | -LL | let _ = &<&[u8]>::clone(encoded); - | ^^^^^^^^^^^^^^^^^^^^^^^ - -error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:108:14 - | -LL | Some(try_opt!(Some(rc)).clone()) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `Rc::::clone(&try_opt!(Some(rc)))` - -error: aborting due to 12 previous errors - diff --git a/tests/ui/unnecessary_filter_map.rs b/tests/ui/unnecessary_filter_map.rs deleted file mode 100644 index af858e4abcf5..000000000000 --- a/tests/ui/unnecessary_filter_map.rs +++ /dev/null @@ -1,17 +0,0 @@ -fn main() { - let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); - let _ = (0..4).filter_map(|x| { - if x > 1 { - return Some(x); - }; - None - }); - let _ = (0..4).filter_map(|x| match x { - 0 | 1 => None, - _ => Some(x), - }); - - let _ = (0..4).filter_map(|x| Some(x + 1)); - - let _ = (0..4).filter_map(i32::checked_abs); -} diff --git a/tests/ui/unnecessary_filter_map.stderr b/tests/ui/unnecessary_filter_map.stderr deleted file mode 100644 index 041829c3c785..000000000000 --- a/tests/ui/unnecessary_filter_map.stderr +++ /dev/null @@ -1,38 +0,0 @@ -error: this `.filter_map` can be written more simply using `.filter` - --> $DIR/unnecessary_filter_map.rs:2:13 - | -LL | let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::unnecessary-filter-map` implied by `-D warnings` - -error: this `.filter_map` can be written more simply using `.filter` - --> $DIR/unnecessary_filter_map.rs:3:13 - | -LL | let _ = (0..4).filter_map(|x| { - | _____________^ -LL | | if x > 1 { -LL | | return Some(x); -LL | | }; -LL | | None -LL | | }); - | |______^ - -error: this `.filter_map` can be written more simply using `.filter` - --> $DIR/unnecessary_filter_map.rs:9:13 - | -LL | let _ = (0..4).filter_map(|x| match x { - | _____________^ -LL | | 0 | 1 => None, -LL | | _ => Some(x), -LL | | }); - | |______^ - -error: this `.filter_map` can be written more simply using `.map` - --> $DIR/unnecessary_filter_map.rs:14:13 - | -LL | let _ = (0..4).filter_map(|x| Some(x + 1)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 4 previous errors - diff --git a/tests/ui/unnecessary_flat_map.fixed b/tests/ui/unnecessary_flat_map.fixed deleted file mode 100644 index dfe3bd47e139..000000000000 --- a/tests/ui/unnecessary_flat_map.fixed +++ /dev/null @@ -1,14 +0,0 @@ -// run-rustfix - -#![allow(unused_imports)] -#![warn(clippy::flat_map_identity)] - -use std::convert; - -fn main() { - let iterator = [[0, 1], [2, 3], [4, 5]].iter(); - let _ = iterator.flatten(); - - let iterator = [[0, 1], [2, 3], [4, 5]].iter(); - let _ = iterator.flatten(); -} diff --git a/tests/ui/unnecessary_flat_map.rs b/tests/ui/unnecessary_flat_map.rs deleted file mode 100644 index 393b95692554..000000000000 --- a/tests/ui/unnecessary_flat_map.rs +++ /dev/null @@ -1,14 +0,0 @@ -// run-rustfix - -#![allow(unused_imports)] -#![warn(clippy::flat_map_identity)] - -use std::convert; - -fn main() { - let iterator = [[0, 1], [2, 3], [4, 5]].iter(); - let _ = iterator.flat_map(|x| x); - - let iterator = [[0, 1], [2, 3], [4, 5]].iter(); - let _ = iterator.flat_map(convert::identity); -} diff --git a/tests/ui/unnecessary_flat_map.stderr b/tests/ui/unnecessary_flat_map.stderr deleted file mode 100644 index a1cd5745e494..000000000000 --- a/tests/ui/unnecessary_flat_map.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: called `flat_map(|x| x)` on an `Iterator` - --> $DIR/unnecessary_flat_map.rs:10:22 - | -LL | let _ = iterator.flat_map(|x| x); - | ^^^^^^^^^^^^^^^ help: try: `flatten()` - | - = note: `-D clippy::flat-map-identity` implied by `-D warnings` - -error: called `flat_map(std::convert::identity)` on an `Iterator` - --> $DIR/unnecessary_flat_map.rs:13:22 - | -LL | let _ = iterator.flat_map(convert::identity); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/unnecessary_fold.fixed b/tests/ui/unnecessary_fold.fixed deleted file mode 100644 index 52300a3b6406..000000000000 --- a/tests/ui/unnecessary_fold.fixed +++ /dev/null @@ -1,52 +0,0 @@ -// run-rustfix - -#![allow(dead_code)] - -/// Calls which should trigger the `UNNECESSARY_FOLD` lint -fn unnecessary_fold() { - // Can be replaced by .any - let _ = (0..3).any(|x| x > 2); - // Can be replaced by .all - let _ = (0..3).all(|x| x > 2); - // Can be replaced by .sum - let _: i32 = (0..3).sum(); - // Can be replaced by .product - let _: i32 = (0..3).product(); -} - -/// Should trigger the `UNNECESSARY_FOLD` lint, with an error span including exactly `.fold(...)` -fn unnecessary_fold_span_for_multi_element_chain() { - let _: bool = (0..3).map(|x| 2 * x).any(|x| x > 2); -} - -/// Calls which should not trigger the `UNNECESSARY_FOLD` lint -fn unnecessary_fold_should_ignore() { - let _ = (0..3).fold(true, |acc, x| acc || x > 2); - let _ = (0..3).fold(false, |acc, x| acc && x > 2); - let _ = (0..3).fold(1, |acc, x| acc + x); - let _ = (0..3).fold(0, |acc, x| acc * x); - let _ = (0..3).fold(0, |acc, x| 1 + acc + x); - - // We only match against an accumulator on the left - // hand side. We could lint for .sum and .product when - // it's on the right, but don't for now (and this wouldn't - // be valid if we extended the lint to cover arbitrary numeric - // types). - let _ = (0..3).fold(false, |acc, x| x > 2 || acc); - let _ = (0..3).fold(true, |acc, x| x > 2 && acc); - let _ = (0..3).fold(0, |acc, x| x + acc); - let _ = (0..3).fold(1, |acc, x| x * acc); - - let _ = [(0..2), (0..3)].iter().fold(0, |a, b| a + b.len()); - let _ = [(0..2), (0..3)].iter().fold(1, |a, b| a * b.len()); -} - -/// Should lint only the line containing the fold -fn unnecessary_fold_over_multiple_lines() { - let _ = (0..3) - .map(|x| x + 1) - .filter(|x| x % 2 == 0) - .any(|x| x > 2); -} - -fn main() {} diff --git a/tests/ui/unnecessary_fold.rs b/tests/ui/unnecessary_fold.rs deleted file mode 100644 index 4028d80c0a3c..000000000000 --- a/tests/ui/unnecessary_fold.rs +++ /dev/null @@ -1,52 +0,0 @@ -// run-rustfix - -#![allow(dead_code)] - -/// Calls which should trigger the `UNNECESSARY_FOLD` lint -fn unnecessary_fold() { - // Can be replaced by .any - let _ = (0..3).fold(false, |acc, x| acc || x > 2); - // Can be replaced by .all - let _ = (0..3).fold(true, |acc, x| acc && x > 2); - // Can be replaced by .sum - let _: i32 = (0..3).fold(0, |acc, x| acc + x); - // Can be replaced by .product - let _: i32 = (0..3).fold(1, |acc, x| acc * x); -} - -/// Should trigger the `UNNECESSARY_FOLD` lint, with an error span including exactly `.fold(...)` -fn unnecessary_fold_span_for_multi_element_chain() { - let _: bool = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2); -} - -/// Calls which should not trigger the `UNNECESSARY_FOLD` lint -fn unnecessary_fold_should_ignore() { - let _ = (0..3).fold(true, |acc, x| acc || x > 2); - let _ = (0..3).fold(false, |acc, x| acc && x > 2); - let _ = (0..3).fold(1, |acc, x| acc + x); - let _ = (0..3).fold(0, |acc, x| acc * x); - let _ = (0..3).fold(0, |acc, x| 1 + acc + x); - - // We only match against an accumulator on the left - // hand side. We could lint for .sum and .product when - // it's on the right, but don't for now (and this wouldn't - // be valid if we extended the lint to cover arbitrary numeric - // types). - let _ = (0..3).fold(false, |acc, x| x > 2 || acc); - let _ = (0..3).fold(true, |acc, x| x > 2 && acc); - let _ = (0..3).fold(0, |acc, x| x + acc); - let _ = (0..3).fold(1, |acc, x| x * acc); - - let _ = [(0..2), (0..3)].iter().fold(0, |a, b| a + b.len()); - let _ = [(0..2), (0..3)].iter().fold(1, |a, b| a * b.len()); -} - -/// Should lint only the line containing the fold -fn unnecessary_fold_over_multiple_lines() { - let _ = (0..3) - .map(|x| x + 1) - .filter(|x| x % 2 == 0) - .fold(false, |acc, x| acc || x > 2); -} - -fn main() {} diff --git a/tests/ui/unnecessary_fold.stderr b/tests/ui/unnecessary_fold.stderr deleted file mode 100644 index 22c44588ab7a..000000000000 --- a/tests/ui/unnecessary_fold.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:8:20 - | -LL | let _ = (0..3).fold(false, |acc, x| acc || x > 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `any(|x| x > 2)` - | - = note: `-D clippy::unnecessary-fold` implied by `-D warnings` - -error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:10:20 - | -LL | let _ = (0..3).fold(true, |acc, x| acc && x > 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `all(|x| x > 2)` - -error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:12:25 - | -LL | let _: i32 = (0..3).fold(0, |acc, x| acc + x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `sum()` - -error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:14:25 - | -LL | let _: i32 = (0..3).fold(1, |acc, x| acc * x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `product()` - -error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:19:41 - | -LL | let _: bool = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `any(|x| x > 2)` - -error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:49:10 - | -LL | .fold(false, |acc, x| acc || x > 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `any(|x| x > 2)` - -error: aborting due to 6 previous errors - diff --git a/tests/ui/unnecessary_lazy_eval.fixed b/tests/ui/unnecessary_lazy_eval.fixed deleted file mode 100644 index 4ba2a0a5dbcc..000000000000 --- a/tests/ui/unnecessary_lazy_eval.fixed +++ /dev/null @@ -1,122 +0,0 @@ -// run-rustfix -#![warn(clippy::unnecessary_lazy_evaluations)] -#![allow(clippy::redundant_closure)] -#![allow(clippy::bind_instead_of_map)] -#![allow(clippy::map_identity)] - -struct Deep(Option); - -#[derive(Copy, Clone)] -struct SomeStruct { - some_field: usize, -} - -impl SomeStruct { - fn return_some_field(&self) -> usize { - self.some_field - } -} - -fn some_call() -> T { - T::default() -} - -fn main() { - let astronomers_pi = 10; - let ext_arr: [usize; 1] = [2]; - let ext_str = SomeStruct { some_field: 10 }; - - let mut opt = Some(42); - let ext_opt = Some(42); - let nested_opt = Some(Some(42)); - let nested_tuple_opt = Some(Some((42, 43))); - - // Should lint - Option - let _ = opt.unwrap_or(2); - let _ = opt.unwrap_or(astronomers_pi); - let _ = opt.unwrap_or(ext_str.some_field); - let _ = opt.unwrap_or_else(|| ext_arr[0]); - let _ = opt.and(ext_opt); - let _ = opt.or(ext_opt); - let _ = opt.or(None); - let _ = opt.get_or_insert(2); - let _ = opt.ok_or(2); - let _ = nested_tuple_opt.unwrap_or(Some((1, 2))); - - // Cases when unwrap is not called on a simple variable - let _ = Some(10).unwrap_or(2); - let _ = Some(10).and(ext_opt); - let _: Option = None.or(ext_opt); - let _ = None.get_or_insert(2); - let _: Result = None.ok_or(2); - let _: Option = None.or(None); - - let mut deep = Deep(Some(42)); - let _ = deep.0.unwrap_or(2); - let _ = deep.0.and(ext_opt); - let _ = deep.0.or(None); - let _ = deep.0.get_or_insert(2); - let _ = deep.0.ok_or(2); - - // Should not lint - Option - let _ = opt.unwrap_or_else(|| ext_str.return_some_field()); - let _ = nested_opt.unwrap_or_else(|| Some(some_call())); - let _ = nested_tuple_opt.unwrap_or_else(|| Some((some_call(), some_call()))); - let _ = opt.or_else(some_call); - let _ = opt.or_else(|| some_call()); - let _: Result = opt.ok_or_else(|| some_call()); - let _: Result = opt.ok_or_else(some_call); - let _ = deep.0.get_or_insert_with(|| some_call()); - let _ = deep.0.or_else(some_call); - let _ = deep.0.or_else(|| some_call()); - let _ = opt.ok_or_else(|| ext_arr[0]); - - // should not lint, bind_instead_of_map takes priority - let _ = Some(10).and_then(|idx| Some(ext_arr[idx])); - let _ = Some(10).and_then(|idx| Some(idx)); - - // should lint, bind_instead_of_map doesn't apply - let _: Option = None.or(Some(3)); - let _ = deep.0.or(Some(3)); - let _ = opt.or(Some(3)); - - // Should lint - Result - let res: Result = Err(5); - let res2: Result = Err(SomeStruct { some_field: 5 }); - - let _ = res2.unwrap_or(2); - let _ = res2.unwrap_or(astronomers_pi); - let _ = res2.unwrap_or(ext_str.some_field); - - // Should not lint - Result - let _ = res.unwrap_or_else(|err| err); - let _ = res.unwrap_or_else(|err| ext_arr[err]); - let _ = res2.unwrap_or_else(|err| err.some_field); - let _ = res2.unwrap_or_else(|err| err.return_some_field()); - let _ = res2.unwrap_or_else(|_| ext_str.return_some_field()); - - // should not lint, bind_instead_of_map takes priority - let _: Result = res.and_then(|x| Ok(x)); - let _: Result = res.or_else(|err| Err(err)); - - let _: Result = res.and_then(|_| Ok(2)); - let _: Result = res.and_then(|_| Ok(astronomers_pi)); - let _: Result = res.and_then(|_| Ok(ext_str.some_field)); - - let _: Result = res.or_else(|_| Err(2)); - let _: Result = res.or_else(|_| Err(astronomers_pi)); - let _: Result = res.or_else(|_| Err(ext_str.some_field)); - - // should lint, bind_instead_of_map doesn't apply - let _: Result = res.and(Err(2)); - let _: Result = res.and(Err(astronomers_pi)); - let _: Result = res.and(Err(ext_str.some_field)); - - let _: Result = res.or(Ok(2)); - let _: Result = res.or(Ok(astronomers_pi)); - let _: Result = res.or(Ok(ext_str.some_field)); - - // neither bind_instead_of_map nor unnecessary_lazy_eval applies here - let _: Result = res.and_then(|x| Err(x)); - let _: Result = res.or_else(|err| Ok(err)); -} diff --git a/tests/ui/unnecessary_lazy_eval.rs b/tests/ui/unnecessary_lazy_eval.rs deleted file mode 100644 index 466915217e42..000000000000 --- a/tests/ui/unnecessary_lazy_eval.rs +++ /dev/null @@ -1,122 +0,0 @@ -// run-rustfix -#![warn(clippy::unnecessary_lazy_evaluations)] -#![allow(clippy::redundant_closure)] -#![allow(clippy::bind_instead_of_map)] -#![allow(clippy::map_identity)] - -struct Deep(Option); - -#[derive(Copy, Clone)] -struct SomeStruct { - some_field: usize, -} - -impl SomeStruct { - fn return_some_field(&self) -> usize { - self.some_field - } -} - -fn some_call() -> T { - T::default() -} - -fn main() { - let astronomers_pi = 10; - let ext_arr: [usize; 1] = [2]; - let ext_str = SomeStruct { some_field: 10 }; - - let mut opt = Some(42); - let ext_opt = Some(42); - let nested_opt = Some(Some(42)); - let nested_tuple_opt = Some(Some((42, 43))); - - // Should lint - Option - let _ = opt.unwrap_or_else(|| 2); - let _ = opt.unwrap_or_else(|| astronomers_pi); - let _ = opt.unwrap_or_else(|| ext_str.some_field); - let _ = opt.unwrap_or_else(|| ext_arr[0]); - let _ = opt.and_then(|_| ext_opt); - let _ = opt.or_else(|| ext_opt); - let _ = opt.or_else(|| None); - let _ = opt.get_or_insert_with(|| 2); - let _ = opt.ok_or_else(|| 2); - let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2))); - - // Cases when unwrap is not called on a simple variable - let _ = Some(10).unwrap_or_else(|| 2); - let _ = Some(10).and_then(|_| ext_opt); - let _: Option = None.or_else(|| ext_opt); - let _ = None.get_or_insert_with(|| 2); - let _: Result = None.ok_or_else(|| 2); - let _: Option = None.or_else(|| None); - - let mut deep = Deep(Some(42)); - let _ = deep.0.unwrap_or_else(|| 2); - let _ = deep.0.and_then(|_| ext_opt); - let _ = deep.0.or_else(|| None); - let _ = deep.0.get_or_insert_with(|| 2); - let _ = deep.0.ok_or_else(|| 2); - - // Should not lint - Option - let _ = opt.unwrap_or_else(|| ext_str.return_some_field()); - let _ = nested_opt.unwrap_or_else(|| Some(some_call())); - let _ = nested_tuple_opt.unwrap_or_else(|| Some((some_call(), some_call()))); - let _ = opt.or_else(some_call); - let _ = opt.or_else(|| some_call()); - let _: Result = opt.ok_or_else(|| some_call()); - let _: Result = opt.ok_or_else(some_call); - let _ = deep.0.get_or_insert_with(|| some_call()); - let _ = deep.0.or_else(some_call); - let _ = deep.0.or_else(|| some_call()); - let _ = opt.ok_or_else(|| ext_arr[0]); - - // should not lint, bind_instead_of_map takes priority - let _ = Some(10).and_then(|idx| Some(ext_arr[idx])); - let _ = Some(10).and_then(|idx| Some(idx)); - - // should lint, bind_instead_of_map doesn't apply - let _: Option = None.or_else(|| Some(3)); - let _ = deep.0.or_else(|| Some(3)); - let _ = opt.or_else(|| Some(3)); - - // Should lint - Result - let res: Result = Err(5); - let res2: Result = Err(SomeStruct { some_field: 5 }); - - let _ = res2.unwrap_or_else(|_| 2); - let _ = res2.unwrap_or_else(|_| astronomers_pi); - let _ = res2.unwrap_or_else(|_| ext_str.some_field); - - // Should not lint - Result - let _ = res.unwrap_or_else(|err| err); - let _ = res.unwrap_or_else(|err| ext_arr[err]); - let _ = res2.unwrap_or_else(|err| err.some_field); - let _ = res2.unwrap_or_else(|err| err.return_some_field()); - let _ = res2.unwrap_or_else(|_| ext_str.return_some_field()); - - // should not lint, bind_instead_of_map takes priority - let _: Result = res.and_then(|x| Ok(x)); - let _: Result = res.or_else(|err| Err(err)); - - let _: Result = res.and_then(|_| Ok(2)); - let _: Result = res.and_then(|_| Ok(astronomers_pi)); - let _: Result = res.and_then(|_| Ok(ext_str.some_field)); - - let _: Result = res.or_else(|_| Err(2)); - let _: Result = res.or_else(|_| Err(astronomers_pi)); - let _: Result = res.or_else(|_| Err(ext_str.some_field)); - - // should lint, bind_instead_of_map doesn't apply - let _: Result = res.and_then(|_| Err(2)); - let _: Result = res.and_then(|_| Err(astronomers_pi)); - let _: Result = res.and_then(|_| Err(ext_str.some_field)); - - let _: Result = res.or_else(|_| Ok(2)); - let _: Result = res.or_else(|_| Ok(astronomers_pi)); - let _: Result = res.or_else(|_| Ok(ext_str.some_field)); - - // neither bind_instead_of_map nor unnecessary_lazy_eval applies here - let _: Result = res.and_then(|x| Err(x)); - let _: Result = res.or_else(|err| Ok(err)); -} diff --git a/tests/ui/unnecessary_lazy_eval.stderr b/tests/ui/unnecessary_lazy_eval.stderr deleted file mode 100644 index 44dcd0cafbb6..000000000000 --- a/tests/ui/unnecessary_lazy_eval.stderr +++ /dev/null @@ -1,196 +0,0 @@ -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:35:13 - | -LL | let _ = opt.unwrap_or_else(|| 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `opt.unwrap_or(2)` - | - = note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:36:13 - | -LL | let _ = opt.unwrap_or_else(|| astronomers_pi); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `opt.unwrap_or(astronomers_pi)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:37:13 - | -LL | let _ = opt.unwrap_or_else(|| ext_str.some_field); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `opt.unwrap_or(ext_str.some_field)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:39:13 - | -LL | let _ = opt.and_then(|_| ext_opt); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `and` instead: `opt.and(ext_opt)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:40:13 - | -LL | let _ = opt.or_else(|| ext_opt); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `opt.or(ext_opt)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:41:13 - | -LL | let _ = opt.or_else(|| None); - | ^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `opt.or(None)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:42:13 - | -LL | let _ = opt.get_or_insert_with(|| 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `get_or_insert` instead: `opt.get_or_insert(2)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:43:13 - | -LL | let _ = opt.ok_or_else(|| 2); - | ^^^^^^^^^^^^^^^^^^^^ help: Use `ok_or` instead: `opt.ok_or(2)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:44:13 - | -LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `nested_tuple_opt.unwrap_or(Some((1, 2)))` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:47:13 - | -LL | let _ = Some(10).unwrap_or_else(|| 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Some(10).unwrap_or(2)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:48:13 - | -LL | let _ = Some(10).and_then(|_| ext_opt); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `and` instead: `Some(10).and(ext_opt)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:49:28 - | -LL | let _: Option = None.or_else(|| ext_opt); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `None.or(ext_opt)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:50:13 - | -LL | let _ = None.get_or_insert_with(|| 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `get_or_insert` instead: `None.get_or_insert(2)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:51:35 - | -LL | let _: Result = None.ok_or_else(|| 2); - | ^^^^^^^^^^^^^^^^^^^^^ help: Use `ok_or` instead: `None.ok_or(2)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:52:28 - | -LL | let _: Option = None.or_else(|| None); - | ^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `None.or(None)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:55:13 - | -LL | let _ = deep.0.unwrap_or_else(|| 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `deep.0.unwrap_or(2)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:56:13 - | -LL | let _ = deep.0.and_then(|_| ext_opt); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `and` instead: `deep.0.and(ext_opt)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:57:13 - | -LL | let _ = deep.0.or_else(|| None); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `deep.0.or(None)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:58:13 - | -LL | let _ = deep.0.get_or_insert_with(|| 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `get_or_insert` instead: `deep.0.get_or_insert(2)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:59:13 - | -LL | let _ = deep.0.ok_or_else(|| 2); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: Use `ok_or` instead: `deep.0.ok_or(2)` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:79:28 - | -LL | let _: Option = None.or_else(|| Some(3)); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `None.or(Some(3))` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:80:13 - | -LL | let _ = deep.0.or_else(|| Some(3)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `deep.0.or(Some(3))` - -error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:81:13 - | -LL | let _ = opt.or_else(|| Some(3)); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `opt.or(Some(3))` - -error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:87:13 - | -LL | let _ = res2.unwrap_or_else(|_| 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `res2.unwrap_or(2)` - -error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:88:13 - | -LL | let _ = res2.unwrap_or_else(|_| astronomers_pi); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `res2.unwrap_or(astronomers_pi)` - -error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:89:13 - | -LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `res2.unwrap_or(ext_str.some_field)` - -error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:111:35 - | -LL | let _: Result = res.and_then(|_| Err(2)); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `and` instead: `res.and(Err(2))` - -error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:112:35 - | -LL | let _: Result = res.and_then(|_| Err(astronomers_pi)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `and` instead: `res.and(Err(astronomers_pi))` - -error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:113:35 - | -LL | let _: Result = res.and_then(|_| Err(ext_str.some_field)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `and` instead: `res.and(Err(ext_str.some_field))` - -error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:115:35 - | -LL | let _: Result = res.or_else(|_| Ok(2)); - | ^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `res.or(Ok(2))` - -error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:116:35 - | -LL | let _: Result = res.or_else(|_| Ok(astronomers_pi)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `res.or(Ok(astronomers_pi))` - -error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:117:35 - | -LL | let _: Result = res.or_else(|_| Ok(ext_str.some_field)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `res.or(Ok(ext_str.some_field))` - -error: aborting due to 32 previous errors - diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.rs b/tests/ui/unnecessary_lazy_eval_unfixable.rs deleted file mode 100644 index b05dd143bfd7..000000000000 --- a/tests/ui/unnecessary_lazy_eval_unfixable.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![warn(clippy::unnecessary_lazy_evaluations)] - -struct Deep(Option); - -#[derive(Copy, Clone)] -struct SomeStruct { - some_field: usize, -} - -fn main() { - // fix will break type inference - let _ = Ok(1).unwrap_or_else(|()| 2); - mod e { - pub struct E; - } - let _ = Ok(1).unwrap_or_else(|e::E| 2); - let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); - - // Fix #6343 - let arr = [(Some(1),)]; - Some(&0).and_then(|&i| arr[i].0); -} diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.stderr b/tests/ui/unnecessary_lazy_eval_unfixable.stderr deleted file mode 100644 index 581d641cbf54..000000000000 --- a/tests/ui/unnecessary_lazy_eval_unfixable.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval_unfixable.rs:12:13 - | -LL | let _ = Ok(1).unwrap_or_else(|()| 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Ok(1).unwrap_or(2)` - | - = note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings` - -error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval_unfixable.rs:16:13 - | -LL | let _ = Ok(1).unwrap_or_else(|e::E| 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Ok(1).unwrap_or(2)` - -error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval_unfixable.rs:17:13 - | -LL | let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Ok(1).unwrap_or(2)` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/unnecessary_operation.fixed b/tests/ui/unnecessary_operation.fixed deleted file mode 100644 index 2fca96c4cd55..000000000000 --- a/tests/ui/unnecessary_operation.fixed +++ /dev/null @@ -1,79 +0,0 @@ -// run-rustfix - -#![feature(box_syntax)] -#![allow(clippy::deref_addrof, dead_code, unused, clippy::no_effect)] -#![warn(clippy::unnecessary_operation)] - -struct Tuple(i32); -struct Struct { - field: i32, -} -enum Enum { - Tuple(i32), - Struct { field: i32 }, -} -struct DropStruct { - field: i32, -} -impl Drop for DropStruct { - fn drop(&mut self) {} -} -struct DropTuple(i32); -impl Drop for DropTuple { - fn drop(&mut self) {} -} -enum DropEnum { - Tuple(i32), - Struct { field: i32 }, -} -impl Drop for DropEnum { - fn drop(&mut self) {} -} -struct FooString { - s: String, -} - -fn get_number() -> i32 { - 0 -} - -fn get_usize() -> usize { - 0 -} -fn get_struct() -> Struct { - Struct { field: 0 } -} -fn get_drop_struct() -> DropStruct { - DropStruct { field: 0 } -} - -fn main() { - get_number(); - get_number(); - get_struct(); - get_number(); - get_number(); - 5;get_number(); - get_number(); - get_number(); - 5;6;get_number(); - get_number(); - get_number(); - get_number(); - 5;get_number(); - 42;get_number(); - [42, 55];get_usize(); - 42;get_number(); - get_number(); - [42; 55];get_usize(); - get_number(); - String::from("blah"); - - // Do not warn - DropTuple(get_number()); - DropStruct { field: get_number() }; - DropStruct { field: get_number() }; - DropStruct { ..get_drop_struct() }; - DropEnum::Tuple(get_number()); - DropEnum::Struct { field: get_number() }; -} diff --git a/tests/ui/unnecessary_operation.rs b/tests/ui/unnecessary_operation.rs deleted file mode 100644 index 08cb9ab522ee..000000000000 --- a/tests/ui/unnecessary_operation.rs +++ /dev/null @@ -1,83 +0,0 @@ -// run-rustfix - -#![feature(box_syntax)] -#![allow(clippy::deref_addrof, dead_code, unused, clippy::no_effect)] -#![warn(clippy::unnecessary_operation)] - -struct Tuple(i32); -struct Struct { - field: i32, -} -enum Enum { - Tuple(i32), - Struct { field: i32 }, -} -struct DropStruct { - field: i32, -} -impl Drop for DropStruct { - fn drop(&mut self) {} -} -struct DropTuple(i32); -impl Drop for DropTuple { - fn drop(&mut self) {} -} -enum DropEnum { - Tuple(i32), - Struct { field: i32 }, -} -impl Drop for DropEnum { - fn drop(&mut self) {} -} -struct FooString { - s: String, -} - -fn get_number() -> i32 { - 0 -} - -fn get_usize() -> usize { - 0 -} -fn get_struct() -> Struct { - Struct { field: 0 } -} -fn get_drop_struct() -> DropStruct { - DropStruct { field: 0 } -} - -fn main() { - Tuple(get_number()); - Struct { field: get_number() }; - Struct { ..get_struct() }; - Enum::Tuple(get_number()); - Enum::Struct { field: get_number() }; - 5 + get_number(); - *&get_number(); - &get_number(); - (5, 6, get_number()); - box get_number(); - get_number()..; - ..get_number(); - 5..get_number(); - [42, get_number()]; - [42, 55][get_usize()]; - (42, get_number()).1; - [get_number(); 55]; - [42; 55][get_usize()]; - { - get_number() - }; - FooString { - s: String::from("blah"), - }; - - // Do not warn - DropTuple(get_number()); - DropStruct { field: get_number() }; - DropStruct { field: get_number() }; - DropStruct { ..get_drop_struct() }; - DropEnum::Tuple(get_number()); - DropEnum::Struct { field: get_number() }; -} diff --git a/tests/ui/unnecessary_operation.stderr b/tests/ui/unnecessary_operation.stderr deleted file mode 100644 index f88c9f9908be..000000000000 --- a/tests/ui/unnecessary_operation.stderr +++ /dev/null @@ -1,128 +0,0 @@ -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:51:5 - | -LL | Tuple(get_number()); - | ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();` - | - = note: `-D clippy::unnecessary-operation` implied by `-D warnings` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:52:5 - | -LL | Struct { field: get_number() }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:53:5 - | -LL | Struct { ..get_struct() }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_struct();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:54:5 - | -LL | Enum::Tuple(get_number()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:55:5 - | -LL | Enum::Struct { field: get_number() }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:56:5 - | -LL | 5 + get_number(); - | ^^^^^^^^^^^^^^^^^ help: replace it with: `5;get_number();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:57:5 - | -LL | *&get_number(); - | ^^^^^^^^^^^^^^^ help: replace it with: `get_number();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:58:5 - | -LL | &get_number(); - | ^^^^^^^^^^^^^^ help: replace it with: `get_number();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:59:5 - | -LL | (5, 6, get_number()); - | ^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `5;6;get_number();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:60:5 - | -LL | box get_number(); - | ^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:61:5 - | -LL | get_number()..; - | ^^^^^^^^^^^^^^^ help: replace it with: `get_number();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:62:5 - | -LL | ..get_number(); - | ^^^^^^^^^^^^^^^ help: replace it with: `get_number();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:63:5 - | -LL | 5..get_number(); - | ^^^^^^^^^^^^^^^^ help: replace it with: `5;get_number();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:64:5 - | -LL | [42, get_number()]; - | ^^^^^^^^^^^^^^^^^^^ help: replace it with: `42;get_number();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:65:5 - | -LL | [42, 55][get_usize()]; - | ^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `[42, 55];get_usize();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:66:5 - | -LL | (42, get_number()).1; - | ^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `42;get_number();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:67:5 - | -LL | [get_number(); 55]; - | ^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:68:5 - | -LL | [42; 55][get_usize()]; - | ^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `[42; 55];get_usize();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:69:5 - | -LL | / { -LL | | get_number() -LL | | }; - | |______^ help: replace it with: `get_number();` - -error: statement can be reduced - --> $DIR/unnecessary_operation.rs:72:5 - | -LL | / FooString { -LL | | s: String::from("blah"), -LL | | }; - | |______^ help: replace it with: `String::from("blah");` - -error: aborting due to 20 previous errors - diff --git a/tests/ui/unnecessary_ref.fixed b/tests/ui/unnecessary_ref.fixed deleted file mode 100644 index f7b94118d4e8..000000000000 --- a/tests/ui/unnecessary_ref.fixed +++ /dev/null @@ -1,14 +0,0 @@ -// run-rustfix - -#![feature(stmt_expr_attributes)] -#![allow(unused_variables)] - -struct Outer { - inner: u32, -} - -#[deny(clippy::ref_in_deref)] -fn main() { - let outer = Outer { inner: 0 }; - let inner = outer.inner; -} diff --git a/tests/ui/unnecessary_ref.rs b/tests/ui/unnecessary_ref.rs deleted file mode 100644 index 4e585b9b96ba..000000000000 --- a/tests/ui/unnecessary_ref.rs +++ /dev/null @@ -1,14 +0,0 @@ -// run-rustfix - -#![feature(stmt_expr_attributes)] -#![allow(unused_variables)] - -struct Outer { - inner: u32, -} - -#[deny(clippy::ref_in_deref)] -fn main() { - let outer = Outer { inner: 0 }; - let inner = (&outer).inner; -} diff --git a/tests/ui/unnecessary_ref.stderr b/tests/ui/unnecessary_ref.stderr deleted file mode 100644 index d0a0f219097e..000000000000 --- a/tests/ui/unnecessary_ref.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: creating a reference that is immediately dereferenced - --> $DIR/unnecessary_ref.rs:13:17 - | -LL | let inner = (&outer).inner; - | ^^^^^^^^ help: try this: `outer` - | -note: the lint level is defined here - --> $DIR/unnecessary_ref.rs:10:8 - | -LL | #[deny(clippy::ref_in_deref)] - | ^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/tests/ui/unnecessary_sort_by.fixed b/tests/ui/unnecessary_sort_by.fixed deleted file mode 100644 index b45b27d8f23b..000000000000 --- a/tests/ui/unnecessary_sort_by.fixed +++ /dev/null @@ -1,100 +0,0 @@ -// run-rustfix - -#![allow(clippy::stable_sort_primitive)] - -use std::cmp::Reverse; - -fn unnecessary_sort_by() { - fn id(x: isize) -> isize { - x - } - - let mut vec: Vec = vec![3, 6, 1, 2, 5]; - // Forward examples - vec.sort(); - vec.sort_unstable(); - vec.sort_by_key(|a| (a + 5).abs()); - vec.sort_unstable_by_key(|a| id(-a)); - // Reverse examples - vec.sort_by(|a, b| b.cmp(a)); // not linted to avoid suggesting `Reverse(b)` which would borrow - vec.sort_by_key(|b| Reverse((b + 5).abs())); - vec.sort_unstable_by_key(|b| Reverse(id(-b))); - // Negative examples (shouldn't be changed) - let c = &7; - vec.sort_by(|a, b| (b - a).cmp(&(a - b))); - vec.sort_by(|_, b| b.cmp(&5)); - vec.sort_by(|_, b| b.cmp(c)); - vec.sort_unstable_by(|a, _| a.cmp(c)); - - // Vectors of references are fine as long as the resulting key does not borrow - let mut vec: Vec<&&&isize> = vec![&&&3, &&&6, &&&1, &&&2, &&&5]; - vec.sort_by_key(|a| (***a).abs()); - vec.sort_unstable_by_key(|a| (***a).abs()); - // `Reverse(b)` would borrow in the following cases, don't lint - vec.sort_by(|a, b| b.cmp(a)); - vec.sort_unstable_by(|a, b| b.cmp(a)); -} - -// Do not suggest returning a reference to the closure parameter of `Vec::sort_by_key` -mod issue_5754 { - #[derive(Clone, Copy)] - struct Test(usize); - - #[derive(PartialOrd, Ord, PartialEq, Eq)] - struct Wrapper<'a>(&'a usize); - - impl Test { - fn name(&self) -> &usize { - &self.0 - } - - fn wrapped(&self) -> Wrapper<'_> { - Wrapper(&self.0) - } - } - - pub fn test() { - let mut args: Vec = vec![]; - - // Forward - args.sort_by(|a, b| a.name().cmp(b.name())); - args.sort_by(|a, b| a.wrapped().cmp(&b.wrapped())); - args.sort_unstable_by(|a, b| a.name().cmp(b.name())); - args.sort_unstable_by(|a, b| a.wrapped().cmp(&b.wrapped())); - // Reverse - args.sort_by(|a, b| b.name().cmp(a.name())); - args.sort_by(|a, b| b.wrapped().cmp(&a.wrapped())); - args.sort_unstable_by(|a, b| b.name().cmp(a.name())); - args.sort_unstable_by(|a, b| b.wrapped().cmp(&a.wrapped())); - } -} - -// The closure parameter is not dereferenced anymore, so non-Copy types can be linted -mod issue_6001 { - use super::*; - struct Test(String); - - impl Test { - // Return an owned type so that we don't hit the fix for 5754 - fn name(&self) -> String { - self.0.clone() - } - } - - pub fn test() { - let mut args: Vec = vec![]; - - // Forward - args.sort_by_key(|a| a.name()); - args.sort_unstable_by_key(|a| a.name()); - // Reverse - args.sort_by_key(|b| Reverse(b.name())); - args.sort_unstable_by_key(|b| Reverse(b.name())); - } -} - -fn main() { - unnecessary_sort_by(); - issue_5754::test(); - issue_6001::test(); -} diff --git a/tests/ui/unnecessary_sort_by.rs b/tests/ui/unnecessary_sort_by.rs deleted file mode 100644 index be2abe7f7014..000000000000 --- a/tests/ui/unnecessary_sort_by.rs +++ /dev/null @@ -1,100 +0,0 @@ -// run-rustfix - -#![allow(clippy::stable_sort_primitive)] - -use std::cmp::Reverse; - -fn unnecessary_sort_by() { - fn id(x: isize) -> isize { - x - } - - let mut vec: Vec = vec![3, 6, 1, 2, 5]; - // Forward examples - vec.sort_by(|a, b| a.cmp(b)); - vec.sort_unstable_by(|a, b| a.cmp(b)); - vec.sort_by(|a, b| (a + 5).abs().cmp(&(b + 5).abs())); - vec.sort_unstable_by(|a, b| id(-a).cmp(&id(-b))); - // Reverse examples - vec.sort_by(|a, b| b.cmp(a)); // not linted to avoid suggesting `Reverse(b)` which would borrow - vec.sort_by(|a, b| (b + 5).abs().cmp(&(a + 5).abs())); - vec.sort_unstable_by(|a, b| id(-b).cmp(&id(-a))); - // Negative examples (shouldn't be changed) - let c = &7; - vec.sort_by(|a, b| (b - a).cmp(&(a - b))); - vec.sort_by(|_, b| b.cmp(&5)); - vec.sort_by(|_, b| b.cmp(c)); - vec.sort_unstable_by(|a, _| a.cmp(c)); - - // Vectors of references are fine as long as the resulting key does not borrow - let mut vec: Vec<&&&isize> = vec![&&&3, &&&6, &&&1, &&&2, &&&5]; - vec.sort_by(|a, b| (***a).abs().cmp(&(***b).abs())); - vec.sort_unstable_by(|a, b| (***a).abs().cmp(&(***b).abs())); - // `Reverse(b)` would borrow in the following cases, don't lint - vec.sort_by(|a, b| b.cmp(a)); - vec.sort_unstable_by(|a, b| b.cmp(a)); -} - -// Do not suggest returning a reference to the closure parameter of `Vec::sort_by_key` -mod issue_5754 { - #[derive(Clone, Copy)] - struct Test(usize); - - #[derive(PartialOrd, Ord, PartialEq, Eq)] - struct Wrapper<'a>(&'a usize); - - impl Test { - fn name(&self) -> &usize { - &self.0 - } - - fn wrapped(&self) -> Wrapper<'_> { - Wrapper(&self.0) - } - } - - pub fn test() { - let mut args: Vec = vec![]; - - // Forward - args.sort_by(|a, b| a.name().cmp(b.name())); - args.sort_by(|a, b| a.wrapped().cmp(&b.wrapped())); - args.sort_unstable_by(|a, b| a.name().cmp(b.name())); - args.sort_unstable_by(|a, b| a.wrapped().cmp(&b.wrapped())); - // Reverse - args.sort_by(|a, b| b.name().cmp(a.name())); - args.sort_by(|a, b| b.wrapped().cmp(&a.wrapped())); - args.sort_unstable_by(|a, b| b.name().cmp(a.name())); - args.sort_unstable_by(|a, b| b.wrapped().cmp(&a.wrapped())); - } -} - -// The closure parameter is not dereferenced anymore, so non-Copy types can be linted -mod issue_6001 { - use super::*; - struct Test(String); - - impl Test { - // Return an owned type so that we don't hit the fix for 5754 - fn name(&self) -> String { - self.0.clone() - } - } - - pub fn test() { - let mut args: Vec = vec![]; - - // Forward - args.sort_by(|a, b| a.name().cmp(&b.name())); - args.sort_unstable_by(|a, b| a.name().cmp(&b.name())); - // Reverse - args.sort_by(|a, b| b.name().cmp(&a.name())); - args.sort_unstable_by(|a, b| b.name().cmp(&a.name())); - } -} - -fn main() { - unnecessary_sort_by(); - issue_5754::test(); - issue_6001::test(); -} diff --git a/tests/ui/unnecessary_sort_by.stderr b/tests/ui/unnecessary_sort_by.stderr deleted file mode 100644 index 50607933e18f..000000000000 --- a/tests/ui/unnecessary_sort_by.stderr +++ /dev/null @@ -1,76 +0,0 @@ -error: use Vec::sort here instead - --> $DIR/unnecessary_sort_by.rs:14:5 - | -LL | vec.sort_by(|a, b| a.cmp(b)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort()` - | - = note: `-D clippy::unnecessary-sort-by` implied by `-D warnings` - -error: use Vec::sort here instead - --> $DIR/unnecessary_sort_by.rs:15:5 - | -LL | vec.sort_unstable_by(|a, b| a.cmp(b)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable()` - -error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:16:5 - | -LL | vec.sort_by(|a, b| (a + 5).abs().cmp(&(b + 5).abs())); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_by_key(|a| (a + 5).abs())` - -error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:17:5 - | -LL | vec.sort_unstable_by(|a, b| id(-a).cmp(&id(-b))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable_by_key(|a| id(-a))` - -error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:20:5 - | -LL | vec.sort_by(|a, b| (b + 5).abs().cmp(&(a + 5).abs())); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_by_key(|b| Reverse((b + 5).abs()))` - -error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:21:5 - | -LL | vec.sort_unstable_by(|a, b| id(-b).cmp(&id(-a))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable_by_key(|b| Reverse(id(-b)))` - -error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:31:5 - | -LL | vec.sort_by(|a, b| (***a).abs().cmp(&(***b).abs())); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_by_key(|a| (***a).abs())` - -error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:32:5 - | -LL | vec.sort_unstable_by(|a, b| (***a).abs().cmp(&(***b).abs())); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable_by_key(|a| (***a).abs())` - -error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:88:9 - | -LL | args.sort_by(|a, b| a.name().cmp(&b.name())); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_by_key(|a| a.name())` - -error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:89:9 - | -LL | args.sort_unstable_by(|a, b| a.name().cmp(&b.name())); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_unstable_by_key(|a| a.name())` - -error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:91:9 - | -LL | args.sort_by(|a, b| b.name().cmp(&a.name())); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_by_key(|b| Reverse(b.name()))` - -error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:92:9 - | -LL | args.sort_unstable_by(|a, b| b.name().cmp(&a.name())); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_unstable_by_key(|b| Reverse(b.name()))` - -error: aborting due to 12 previous errors - diff --git a/tests/ui/unnecessary_wraps.rs b/tests/ui/unnecessary_wraps.rs deleted file mode 100644 index a4570098d716..000000000000 --- a/tests/ui/unnecessary_wraps.rs +++ /dev/null @@ -1,123 +0,0 @@ -#![warn(clippy::unnecessary_wraps)] -#![allow(clippy::no_effect)] -#![allow(clippy::needless_return)] -#![allow(clippy::if_same_then_else)] -#![allow(dead_code)] - -// should be linted -fn func1(a: bool, b: bool) -> Option { - if a && b { - return Some(42); - } - if a { - Some(-1); - Some(2) - } else { - return Some(1337); - } -} - -// should be linted -fn func2(a: bool, b: bool) -> Option { - if a && b { - return Some(10); - } - if a { - Some(20) - } else { - Some(30) - } -} - -// public fns should not be linted -pub fn func3(a: bool) -> Option { - if a { - Some(1) - } else { - Some(1) - } -} - -// should not be linted -fn func4(a: bool) -> Option { - if a { - Some(1) - } else { - None - } -} - -// should be linted -fn func5() -> Option { - Some(1) -} - -// should not be linted -fn func6() -> Option { - None -} - -// should be linted -fn func7() -> Result { - Ok(1) -} - -// should not be linted -fn func8(a: bool) -> Result { - if a { - Ok(1) - } else { - Err(()) - } -} - -// should not be linted -fn func9(a: bool) -> Result { - Err(()) -} - -// should not be linted -fn func10() -> Option<()> { - unimplemented!() -} - -struct A; - -impl A { - // should not be linted - pub fn func11() -> Option { - Some(1) - } - - // should be linted - fn func12() -> Option { - Some(1) - } -} - -trait B { - // trait impls are not linted - fn func13() -> Option { - Some(1) - } -} - -impl B for A { - // trait impls are not linted - fn func13() -> Option { - Some(0) - } -} - -fn issue_6384(s: &str) -> Option<&str> { - Some(match s { - "a" => "A", - _ => return None, - }) -} - -fn main() { - // method calls are not linted - func1(true, true); - func2(true, true); -} diff --git a/tests/ui/unnecessary_wraps.stderr b/tests/ui/unnecessary_wraps.stderr deleted file mode 100644 index 410f054b8efc..000000000000 --- a/tests/ui/unnecessary_wraps.stderr +++ /dev/null @@ -1,106 +0,0 @@ -error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:8:1 - | -LL | / fn func1(a: bool, b: bool) -> Option { -LL | | if a && b { -LL | | return Some(42); -LL | | } -... | -LL | | } -LL | | } - | |_^ - | - = note: `-D clippy::unnecessary-wraps` implied by `-D warnings` -help: remove `Option` from the return type... - | -LL | fn func1(a: bool, b: bool) -> i32 { - | ^^^ -help: ...and change the returning expressions - | -LL | return 42; -LL | } -LL | if a { -LL | Some(-1); -LL | 2 -LL | } else { - ... - -error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:21:1 - | -LL | / fn func2(a: bool, b: bool) -> Option { -LL | | if a && b { -LL | | return Some(10); -LL | | } -... | -LL | | } -LL | | } - | |_^ - | -help: remove `Option` from the return type... - | -LL | fn func2(a: bool, b: bool) -> i32 { - | ^^^ -help: ...and change the returning expressions - | -LL | return 10; -LL | } -LL | if a { -LL | 20 -LL | } else { -LL | 30 - | - -error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:51:1 - | -LL | / fn func5() -> Option { -LL | | Some(1) -LL | | } - | |_^ - | -help: remove `Option` from the return type... - | -LL | fn func5() -> i32 { - | ^^^ -help: ...and change the returning expressions - | -LL | 1 - | - -error: this function's return value is unnecessarily wrapped by `Result` - --> $DIR/unnecessary_wraps.rs:61:1 - | -LL | / fn func7() -> Result { -LL | | Ok(1) -LL | | } - | |_^ - | -help: remove `Result` from the return type... - | -LL | fn func7() -> i32 { - | ^^^ -help: ...and change the returning expressions - | -LL | 1 - | - -error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:93:5 - | -LL | / fn func12() -> Option { -LL | | Some(1) -LL | | } - | |_____^ - | -help: remove `Option` from the return type... - | -LL | fn func12() -> i32 { - | ^^^ -help: ...and change the returning expressions - | -LL | 1 - | - -error: aborting due to 5 previous errors - diff --git a/tests/ui/unneeded_field_pattern.rs b/tests/ui/unneeded_field_pattern.rs deleted file mode 100644 index fa639aa70d61..000000000000 --- a/tests/ui/unneeded_field_pattern.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![warn(clippy::unneeded_field_pattern)] -#[allow(dead_code, unused)] - -struct Foo { - a: i32, - b: i32, - c: i32, -} - -fn main() { - let f = Foo { a: 0, b: 0, c: 0 }; - - match f { - Foo { a: _, b: 0, .. } => {}, - - Foo { a: _, b: _, c: _ } => {}, - } - match f { - Foo { b: 0, .. } => {}, // should be OK - Foo { .. } => {}, // and the Force might be with this one - } -} diff --git a/tests/ui/unneeded_field_pattern.stderr b/tests/ui/unneeded_field_pattern.stderr deleted file mode 100644 index b8d3c2945322..000000000000 --- a/tests/ui/unneeded_field_pattern.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: you matched a field with a wildcard pattern, consider using `..` instead - --> $DIR/unneeded_field_pattern.rs:14:15 - | -LL | Foo { a: _, b: 0, .. } => {}, - | ^^^^ - | - = note: `-D clippy::unneeded-field-pattern` implied by `-D warnings` - = help: try with `Foo { b: 0, .. }` - -error: all the struct fields are matched to a wildcard pattern, consider using `..` - --> $DIR/unneeded_field_pattern.rs:16:9 - | -LL | Foo { a: _, b: _, c: _ } => {}, - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: try with `Foo { .. }` instead - -error: aborting due to 2 previous errors - diff --git a/tests/ui/unneeded_wildcard_pattern.fixed b/tests/ui/unneeded_wildcard_pattern.fixed deleted file mode 100644 index 12c3461c9557..000000000000 --- a/tests/ui/unneeded_wildcard_pattern.fixed +++ /dev/null @@ -1,45 +0,0 @@ -// run-rustfix -#![feature(stmt_expr_attributes)] -#![deny(clippy::unneeded_wildcard_pattern)] - -fn main() { - let t = (0, 1, 2, 3); - - if let (0, ..) = t {}; - if let (0, ..) = t {}; - if let (.., 0) = t {}; - if let (.., 0) = t {}; - if let (0, ..) = t {}; - if let (0, ..) = t {}; - if let (_, 0, ..) = t {}; - if let (.., 0, _) = t {}; - if let (0, _, _, _) = t {}; - if let (0, ..) = t {}; - if let (.., 0) = t {}; - - #[rustfmt::skip] - { - if let (0, ..,) = t {}; - } - - struct S(usize, usize, usize, usize); - - let s = S(0, 1, 2, 3); - - if let S(0, ..) = s {}; - if let S(0, ..) = s {}; - if let S(.., 0) = s {}; - if let S(.., 0) = s {}; - if let S(0, ..) = s {}; - if let S(0, ..) = s {}; - if let S(_, 0, ..) = s {}; - if let S(.., 0, _) = s {}; - if let S(0, _, _, _) = s {}; - if let S(0, ..) = s {}; - if let S(.., 0) = s {}; - - #[rustfmt::skip] - { - if let S(0, ..,) = s {}; - } -} diff --git a/tests/ui/unneeded_wildcard_pattern.rs b/tests/ui/unneeded_wildcard_pattern.rs deleted file mode 100644 index 4ac01d5d23b0..000000000000 --- a/tests/ui/unneeded_wildcard_pattern.rs +++ /dev/null @@ -1,45 +0,0 @@ -// run-rustfix -#![feature(stmt_expr_attributes)] -#![deny(clippy::unneeded_wildcard_pattern)] - -fn main() { - let t = (0, 1, 2, 3); - - if let (0, .., _) = t {}; - if let (0, _, ..) = t {}; - if let (_, .., 0) = t {}; - if let (.., _, 0) = t {}; - if let (0, _, _, ..) = t {}; - if let (0, .., _, _) = t {}; - if let (_, 0, ..) = t {}; - if let (.., 0, _) = t {}; - if let (0, _, _, _) = t {}; - if let (0, ..) = t {}; - if let (.., 0) = t {}; - - #[rustfmt::skip] - { - if let (0, .., _, _,) = t {}; - } - - struct S(usize, usize, usize, usize); - - let s = S(0, 1, 2, 3); - - if let S(0, .., _) = s {}; - if let S(0, _, ..) = s {}; - if let S(_, .., 0) = s {}; - if let S(.., _, 0) = s {}; - if let S(0, _, _, ..) = s {}; - if let S(0, .., _, _) = s {}; - if let S(_, 0, ..) = s {}; - if let S(.., 0, _) = s {}; - if let S(0, _, _, _) = s {}; - if let S(0, ..) = s {}; - if let S(.., 0) = s {}; - - #[rustfmt::skip] - { - if let S(0, .., _, _,) = s {}; - } -} diff --git a/tests/ui/unneeded_wildcard_pattern.stderr b/tests/ui/unneeded_wildcard_pattern.stderr deleted file mode 100644 index 716d9ecff89a..000000000000 --- a/tests/ui/unneeded_wildcard_pattern.stderr +++ /dev/null @@ -1,92 +0,0 @@ -error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:8:18 - | -LL | if let (0, .., _) = t {}; - | ^^^ help: remove it - | -note: the lint level is defined here - --> $DIR/unneeded_wildcard_pattern.rs:3:9 - | -LL | #![deny(clippy::unneeded_wildcard_pattern)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:9:16 - | -LL | if let (0, _, ..) = t {}; - | ^^^ help: remove it - -error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:10:13 - | -LL | if let (_, .., 0) = t {}; - | ^^^ help: remove it - -error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:11:15 - | -LL | if let (.., _, 0) = t {}; - | ^^^ help: remove it - -error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:12:16 - | -LL | if let (0, _, _, ..) = t {}; - | ^^^^^^ help: remove them - -error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:13:18 - | -LL | if let (0, .., _, _) = t {}; - | ^^^^^^ help: remove them - -error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:22:22 - | -LL | if let (0, .., _, _,) = t {}; - | ^^^^^^ help: remove them - -error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:29:19 - | -LL | if let S(0, .., _) = s {}; - | ^^^ help: remove it - -error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:30:17 - | -LL | if let S(0, _, ..) = s {}; - | ^^^ help: remove it - -error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:31:14 - | -LL | if let S(_, .., 0) = s {}; - | ^^^ help: remove it - -error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:32:16 - | -LL | if let S(.., _, 0) = s {}; - | ^^^ help: remove it - -error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:33:17 - | -LL | if let S(0, _, _, ..) = s {}; - | ^^^^^^ help: remove them - -error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:34:19 - | -LL | if let S(0, .., _, _) = s {}; - | ^^^^^^ help: remove them - -error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:43:23 - | -LL | if let S(0, .., _, _,) = s {}; - | ^^^^^^ help: remove them - -error: aborting due to 14 previous errors - diff --git a/tests/ui/unnested_or_patterns.fixed b/tests/ui/unnested_or_patterns.fixed deleted file mode 100644 index b39e891094fd..000000000000 --- a/tests/ui/unnested_or_patterns.fixed +++ /dev/null @@ -1,33 +0,0 @@ -// run-rustfix - -#![feature(or_patterns)] -#![feature(box_patterns)] -#![warn(clippy::unnested_or_patterns)] -#![allow(clippy::cognitive_complexity, clippy::match_ref_pats)] -#![allow(unreachable_patterns, irrefutable_let_patterns, unused_variables)] - -fn main() { - if let box (0 | 2) = Box::new(0) {} - if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} - const C0: &u8 = &1; - if let &(0 | 2) | C0 = &0 {} - if let &mut (0 | 2) = &mut 0 {} - if let x @ (0 | 2) = 0 {} - if let (0, 1 | 2 | 3) = (0, 0) {} - if let (1 | 2 | 3, 0) = (0, 0) {} - if let (x, ..) | (x, 1 | 2) = (0, 1) {} - if let [0 | 1] = [0] {} - if let [x, 0 | 1] = [0, 1] {} - if let [x, 0 | 1 | 2] = [0, 1] {} - if let [x, ..] | [x, 1 | 2] = [0, 1] {} - struct TS(u8, u8); - if let TS(0 | 1, x) = TS(0, 0) {} - if let TS(1 | 2 | 3, 0) = TS(0, 0) {} - if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {} - struct S { - x: u8, - y: u8, - } - if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {} - if let S { x: 0, y, .. } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} -} diff --git a/tests/ui/unnested_or_patterns.rs b/tests/ui/unnested_or_patterns.rs deleted file mode 100644 index 096f5a71150b..000000000000 --- a/tests/ui/unnested_or_patterns.rs +++ /dev/null @@ -1,33 +0,0 @@ -// run-rustfix - -#![feature(or_patterns)] -#![feature(box_patterns)] -#![warn(clippy::unnested_or_patterns)] -#![allow(clippy::cognitive_complexity, clippy::match_ref_pats)] -#![allow(unreachable_patterns, irrefutable_let_patterns, unused_variables)] - -fn main() { - if let box 0 | box 2 = Box::new(0) {} - if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {} - const C0: &u8 = &1; - if let &0 | C0 | &2 = &0 {} - if let &mut 0 | &mut 2 = &mut 0 {} - if let x @ 0 | x @ 2 = 0 {} - if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} - if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {} - if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {} - if let [0] | [1] = [0] {} - if let [x, 0] | [x, 1] = [0, 1] {} - if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {} - if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {} - struct TS(u8, u8); - if let TS(0, x) | TS(1, x) = TS(0, 0) {} - if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {} - if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {} - struct S { - x: u8, - y: u8, - } - if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} - if let S { x: 0, y, .. } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} -} diff --git a/tests/ui/unnested_or_patterns.stderr b/tests/ui/unnested_or_patterns.stderr deleted file mode 100644 index 1899dc657dfe..000000000000 --- a/tests/ui/unnested_or_patterns.stderr +++ /dev/null @@ -1,179 +0,0 @@ -error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:10:12 - | -LL | if let box 0 | box 2 = Box::new(0) {} - | ^^^^^^^^^^^^^ - | - = note: `-D clippy::unnested-or-patterns` implied by `-D warnings` -help: nest the patterns - | -LL | if let box (0 | 2) = Box::new(0) {} - | ^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:11:12 - | -LL | if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} - | ^^^^^^^^^^^^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:13:12 - | -LL | if let &0 | C0 | &2 = &0 {} - | ^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let &(0 | 2) | C0 = &0 {} - | ^^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:14:12 - | -LL | if let &mut 0 | &mut 2 = &mut 0 {} - | ^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let &mut (0 | 2) = &mut 0 {} - | ^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:15:12 - | -LL | if let x @ 0 | x @ 2 = 0 {} - | ^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let x @ (0 | 2) = 0 {} - | ^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:16:12 - | -LL | if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let (0, 1 | 2 | 3) = (0, 0) {} - | ^^^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:17:12 - | -LL | if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let (1 | 2 | 3, 0) = (0, 0) {} - | ^^^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:18:12 - | -LL | if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let (x, ..) | (x, 1 | 2) = (0, 1) {} - | ^^^^^^^^^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:19:12 - | -LL | if let [0] | [1] = [0] {} - | ^^^^^^^^^ - | -help: nest the patterns - | -LL | if let [0 | 1] = [0] {} - | ^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:20:12 - | -LL | if let [x, 0] | [x, 1] = [0, 1] {} - | ^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let [x, 0 | 1] = [0, 1] {} - | ^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:21:12 - | -LL | if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let [x, 0 | 1 | 2] = [0, 1] {} - | ^^^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:22:12 - | -LL | if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let [x, ..] | [x, 1 | 2] = [0, 1] {} - | ^^^^^^^^^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:24:12 - | -LL | if let TS(0, x) | TS(1, x) = TS(0, 0) {} - | ^^^^^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let TS(0 | 1, x) = TS(0, 0) {} - | ^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:25:12 - | -LL | if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let TS(1 | 2 | 3, 0) = TS(0, 0) {} - | ^^^^^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:26:12 - | -LL | if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:31:12 - | -LL | if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {} - | ^^^^^^^^^^^^^^^^^ - -error: aborting due to 16 previous errors - diff --git a/tests/ui/unnested_or_patterns2.fixed b/tests/ui/unnested_or_patterns2.fixed deleted file mode 100644 index 02a129c55a3f..000000000000 --- a/tests/ui/unnested_or_patterns2.fixed +++ /dev/null @@ -1,18 +0,0 @@ -// run-rustfix - -#![feature(or_patterns)] -#![feature(box_patterns)] -#![warn(clippy::unnested_or_patterns)] -#![allow(clippy::cognitive_complexity, clippy::match_ref_pats)] -#![allow(unreachable_patterns, irrefutable_let_patterns, unused_variables)] - -fn main() { - if let Some(Some(0 | 1)) = None {} - if let Some(Some(0 | 1 | 2)) = None {} - if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {} - if let Some(Some(0 | 1 | 2)) = None {} - if let ((0 | 1 | 2,),) = ((0,),) {} - if let 0 | 1 | 2 = 0 {} - if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} - if let box box (0 | 2 | 4) = Box::new(Box::new(0)) {} -} diff --git a/tests/ui/unnested_or_patterns2.rs b/tests/ui/unnested_or_patterns2.rs deleted file mode 100644 index acf3158989dc..000000000000 --- a/tests/ui/unnested_or_patterns2.rs +++ /dev/null @@ -1,18 +0,0 @@ -// run-rustfix - -#![feature(or_patterns)] -#![feature(box_patterns)] -#![warn(clippy::unnested_or_patterns)] -#![allow(clippy::cognitive_complexity, clippy::match_ref_pats)] -#![allow(unreachable_patterns, irrefutable_let_patterns, unused_variables)] - -fn main() { - if let Some(Some(0)) | Some(Some(1)) = None {} - if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {} - if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {} - if let Some(Some(0) | Some(1 | 2)) = None {} - if let ((0,),) | ((1,) | (2,),) = ((0,),) {} - if let 0 | (1 | 2) = 0 {} - if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {} - if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {} -} diff --git a/tests/ui/unnested_or_patterns2.stderr b/tests/ui/unnested_or_patterns2.stderr deleted file mode 100644 index 1847fd8e098c..000000000000 --- a/tests/ui/unnested_or_patterns2.stderr +++ /dev/null @@ -1,91 +0,0 @@ -error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:10:12 - | -LL | if let Some(Some(0)) | Some(Some(1)) = None {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::unnested-or-patterns` implied by `-D warnings` -help: nest the patterns - | -LL | if let Some(Some(0 | 1)) = None {} - | ^^^^^^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:11:12 - | -LL | if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let Some(Some(0 | 1 | 2)) = None {} - | ^^^^^^^^^^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:12:12 - | -LL | if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:13:12 - | -LL | if let Some(Some(0) | Some(1 | 2)) = None {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let Some(Some(0 | 1 | 2)) = None {} - | ^^^^^^^^^^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:14:12 - | -LL | if let ((0,),) | ((1,) | (2,),) = ((0,),) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let ((0 | 1 | 2,),) = ((0,),) {} - | ^^^^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:15:12 - | -LL | if let 0 | (1 | 2) = 0 {} - | ^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let 0 | 1 | 2 = 0 {} - | ^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:16:12 - | -LL | if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} - | ^^^^^^^^^^^^^^^^^^^^^^^ - -error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:17:12 - | -LL | if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: nest the patterns - | -LL | if let box box (0 | 2 | 4) = Box::new(Box::new(0)) {} - | ^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 8 previous errors - diff --git a/tests/ui/unnested_or_patterns3.rs b/tests/ui/unnested_or_patterns3.rs deleted file mode 100644 index 6bd35057bfad..000000000000 --- a/tests/ui/unnested_or_patterns3.rs +++ /dev/null @@ -1,6 +0,0 @@ -#![warn(clippy::unnested_or_patterns)] - -// Test that `unnested_or_patterns` does not trigger without enabling `or_patterns` -fn main() { - if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} -} diff --git a/tests/ui/unreadable_literal.fixed b/tests/ui/unreadable_literal.fixed deleted file mode 100644 index c2e38037addd..000000000000 --- a/tests/ui/unreadable_literal.fixed +++ /dev/null @@ -1,45 +0,0 @@ -// run-rustfix - -#![warn(clippy::unreadable_literal)] - -struct Foo(u64); - -macro_rules! foo { - () => { - Foo(123123123123) - }; -} - -struct Bar(f32); - -macro_rules! bar { - () => { - Bar(100200300400.100200300400500) - }; -} - -fn main() { - let _good = ( - 0b1011_i64, - 0o1_234_u32, - 0x0123_4567, - 65536, - 1_2345_6789, - 1234_f32, - 1_234.12_f32, - 1_234.123_f32, - 1.123_4_f32, - ); - let _bad = (0b11_0110_i64, 0xcafe_babe_usize, 123_456_f32, 1.234_567_f32); - let _good_sci = 1.1234e1; - let _bad_sci = 1.123_456e1; - - let _fail1 = 0x00ab_cdef; - let _fail2: u32 = 0xBAFE_BAFE; - let _fail3 = 0x0abc_deff; - let _fail4: i128 = 0x00ab_cabc_abca_bcab_cabc; - let _fail5 = 1.100_300_400; - - let _ = foo!(); - let _ = bar!(); -} diff --git a/tests/ui/unreadable_literal.rs b/tests/ui/unreadable_literal.rs deleted file mode 100644 index 8296945b25eb..000000000000 --- a/tests/ui/unreadable_literal.rs +++ /dev/null @@ -1,45 +0,0 @@ -// run-rustfix - -#![warn(clippy::unreadable_literal)] - -struct Foo(u64); - -macro_rules! foo { - () => { - Foo(123123123123) - }; -} - -struct Bar(f32); - -macro_rules! bar { - () => { - Bar(100200300400.100200300400500) - }; -} - -fn main() { - let _good = ( - 0b1011_i64, - 0o1_234_u32, - 0x1_234_567, - 65536, - 1_2345_6789, - 1234_f32, - 1_234.12_f32, - 1_234.123_f32, - 1.123_4_f32, - ); - let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); - let _good_sci = 1.1234e1; - let _bad_sci = 1.123456e1; - - let _fail1 = 0xabcdef; - let _fail2: u32 = 0xBAFEBAFE; - let _fail3 = 0xabcdeff; - let _fail4: i128 = 0xabcabcabcabcabcabc; - let _fail5 = 1.100300400; - - let _ = foo!(); - let _ = bar!(); -} diff --git a/tests/ui/unreadable_literal.stderr b/tests/ui/unreadable_literal.stderr deleted file mode 100644 index 8436aac17acf..000000000000 --- a/tests/ui/unreadable_literal.stderr +++ /dev/null @@ -1,72 +0,0 @@ -error: digits of hex or binary literal not grouped by four - --> $DIR/unreadable_literal.rs:25:9 - | -LL | 0x1_234_567, - | ^^^^^^^^^^^ help: consider: `0x0123_4567` - | - = note: `-D clippy::unusual-byte-groupings` implied by `-D warnings` - -error: long literal lacking separators - --> $DIR/unreadable_literal.rs:33:17 - | -LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); - | ^^^^^^^^^^^^ help: consider: `0b11_0110_i64` - | - = note: `-D clippy::unreadable-literal` implied by `-D warnings` - -error: long literal lacking separators - --> $DIR/unreadable_literal.rs:33:31 - | -LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); - | ^^^^^^^^^^^^^^^^ help: consider: `0xcafe_babe_usize` - -error: long literal lacking separators - --> $DIR/unreadable_literal.rs:33:49 - | -LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); - | ^^^^^^^^^^ help: consider: `123_456_f32` - -error: long literal lacking separators - --> $DIR/unreadable_literal.rs:33:61 - | -LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); - | ^^^^^^^^^^^^ help: consider: `1.234_567_f32` - -error: long literal lacking separators - --> $DIR/unreadable_literal.rs:35:20 - | -LL | let _bad_sci = 1.123456e1; - | ^^^^^^^^^^ help: consider: `1.123_456e1` - -error: long literal lacking separators - --> $DIR/unreadable_literal.rs:37:18 - | -LL | let _fail1 = 0xabcdef; - | ^^^^^^^^ help: consider: `0x00ab_cdef` - -error: long literal lacking separators - --> $DIR/unreadable_literal.rs:38:23 - | -LL | let _fail2: u32 = 0xBAFEBAFE; - | ^^^^^^^^^^ help: consider: `0xBAFE_BAFE` - -error: long literal lacking separators - --> $DIR/unreadable_literal.rs:39:18 - | -LL | let _fail3 = 0xabcdeff; - | ^^^^^^^^^ help: consider: `0x0abc_deff` - -error: long literal lacking separators - --> $DIR/unreadable_literal.rs:40:24 - | -LL | let _fail4: i128 = 0xabcabcabcabcabcabc; - | ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc` - -error: long literal lacking separators - --> $DIR/unreadable_literal.rs:41:18 - | -LL | let _fail5 = 1.100300400; - | ^^^^^^^^^^^ help: consider: `1.100_300_400` - -error: aborting due to 11 previous errors - diff --git a/tests/ui/unsafe_derive_deserialize.rs b/tests/ui/unsafe_derive_deserialize.rs deleted file mode 100644 index 690d705573d3..000000000000 --- a/tests/ui/unsafe_derive_deserialize.rs +++ /dev/null @@ -1,70 +0,0 @@ -#![warn(clippy::unsafe_derive_deserialize)] -#![allow(unused, clippy::missing_safety_doc)] - -extern crate serde; - -use serde::Deserialize; - -#[derive(Deserialize)] -pub struct A {} -impl A { - pub unsafe fn new(_a: i32, _b: i32) -> Self { - Self {} - } -} - -#[derive(Deserialize)] -pub struct B {} -impl B { - pub unsafe fn unsafe_method(&self) {} -} - -#[derive(Deserialize)] -pub struct C {} -impl C { - pub fn unsafe_block(&self) { - unsafe {} - } -} - -#[derive(Deserialize)] -pub struct D {} -impl D { - pub fn inner_unsafe_fn(&self) { - unsafe fn inner() {} - } -} - -// Does not derive `Deserialize`, should be ignored -pub struct E {} -impl E { - pub unsafe fn new(_a: i32, _b: i32) -> Self { - Self {} - } - - pub unsafe fn unsafe_method(&self) {} - - pub fn unsafe_block(&self) { - unsafe {} - } - - pub fn inner_unsafe_fn(&self) { - unsafe fn inner() {} - } -} - -// Does not have methods using `unsafe`, should be ignored -#[derive(Deserialize)] -pub struct F {} - -// Check that we honor the `allow` attribute on the ADT -#[allow(clippy::unsafe_derive_deserialize)] -#[derive(Deserialize)] -pub struct G {} -impl G { - pub fn unsafe_block(&self) { - unsafe {} - } -} - -fn main() {} diff --git a/tests/ui/unsafe_derive_deserialize.stderr b/tests/ui/unsafe_derive_deserialize.stderr deleted file mode 100644 index 1978bd95a670..000000000000 --- a/tests/ui/unsafe_derive_deserialize.stderr +++ /dev/null @@ -1,39 +0,0 @@ -error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> $DIR/unsafe_derive_deserialize.rs:8:10 - | -LL | #[derive(Deserialize)] - | ^^^^^^^^^^^ - | - = note: `-D clippy::unsafe-derive-deserialize` implied by `-D warnings` - = help: consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> $DIR/unsafe_derive_deserialize.rs:16:10 - | -LL | #[derive(Deserialize)] - | ^^^^^^^^^^^ - | - = help: consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> $DIR/unsafe_derive_deserialize.rs:22:10 - | -LL | #[derive(Deserialize)] - | ^^^^^^^^^^^ - | - = help: consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> $DIR/unsafe_derive_deserialize.rs:30:10 - | -LL | #[derive(Deserialize)] - | ^^^^^^^^^^^ - | - = help: consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 4 previous errors - diff --git a/tests/ui/unsafe_removed_from_name.rs b/tests/ui/unsafe_removed_from_name.rs deleted file mode 100644 index a1f616733bd9..000000000000 --- a/tests/ui/unsafe_removed_from_name.rs +++ /dev/null @@ -1,27 +0,0 @@ -#![allow(unused_imports)] -#![allow(dead_code)] -#![warn(clippy::unsafe_removed_from_name)] - -use std::cell::UnsafeCell as TotallySafeCell; - -use std::cell::UnsafeCell as TotallySafeCellAgain; - -// Shouldn't error -use std::cell::RefCell as ProbablyNotUnsafe; -use std::cell::RefCell as RefCellThatCantBeUnsafe; -use std::cell::UnsafeCell as SuperDangerousUnsafeCell; -use std::cell::UnsafeCell as Dangerunsafe; -use std::cell::UnsafeCell as Bombsawayunsafe; - -mod mod_with_some_unsafe_things { - pub struct Safe {} - pub struct Unsafe {} -} - -use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety; - -// Shouldn't error -use mod_with_some_unsafe_things::Safe as IPromiseItsSafeThisTime; -use mod_with_some_unsafe_things::Unsafe as SuperUnsafeModThing; - -fn main() {} diff --git a/tests/ui/unsafe_removed_from_name.stderr b/tests/ui/unsafe_removed_from_name.stderr deleted file mode 100644 index 4f871cbe41b0..000000000000 --- a/tests/ui/unsafe_removed_from_name.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCell` - --> $DIR/unsafe_removed_from_name.rs:5:1 - | -LL | use std::cell::UnsafeCell as TotallySafeCell; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::unsafe-removed-from-name` implied by `-D warnings` - -error: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCellAgain` - --> $DIR/unsafe_removed_from_name.rs:7:1 - | -LL | use std::cell::UnsafeCell as TotallySafeCellAgain; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: removed `unsafe` from the name of `Unsafe` in use as `LieAboutModSafety` - --> $DIR/unsafe_removed_from_name.rs:21:1 - | -LL | use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/unseparated_prefix_literals.fixed b/tests/ui/unseparated_prefix_literals.fixed deleted file mode 100644 index 3c422cc4fee7..000000000000 --- a/tests/ui/unseparated_prefix_literals.fixed +++ /dev/null @@ -1,41 +0,0 @@ -// run-rustfix - -#![warn(clippy::unseparated_literal_suffix)] -#![allow(dead_code)] - -#[macro_use] -extern crate clippy_mini_macro_test; - -// Test for proc-macro attribute -#[derive(ClippyMiniMacroTest)] -struct Foo; - -macro_rules! lit_from_macro { - () => { - 42_usize - }; -} - -fn main() { - let _ok1 = 1234_i32; - let _ok2 = 1234_isize; - let _ok3 = 0x123_isize; - let _fail1 = 1234_i32; - let _fail2 = 1234_u32; - let _fail3 = 1234_isize; - let _fail4 = 1234_usize; - let _fail5 = 0x123_isize; - - let _okf1 = 1.5_f32; - let _okf2 = 1_f32; - let _failf1 = 1.5_f32; - let _failf2 = 1_f32; - - // Test for macro - let _ = lit_from_macro!(); - - // Counter example - let _ = line!(); - // Because `assert!` contains `line!()` macro. - assert_eq!(4897_u32, 32223); -} diff --git a/tests/ui/unseparated_prefix_literals.rs b/tests/ui/unseparated_prefix_literals.rs deleted file mode 100644 index 09608661e0ef..000000000000 --- a/tests/ui/unseparated_prefix_literals.rs +++ /dev/null @@ -1,41 +0,0 @@ -// run-rustfix - -#![warn(clippy::unseparated_literal_suffix)] -#![allow(dead_code)] - -#[macro_use] -extern crate clippy_mini_macro_test; - -// Test for proc-macro attribute -#[derive(ClippyMiniMacroTest)] -struct Foo; - -macro_rules! lit_from_macro { - () => { - 42usize - }; -} - -fn main() { - let _ok1 = 1234_i32; - let _ok2 = 1234_isize; - let _ok3 = 0x123_isize; - let _fail1 = 1234i32; - let _fail2 = 1234u32; - let _fail3 = 1234isize; - let _fail4 = 1234usize; - let _fail5 = 0x123isize; - - let _okf1 = 1.5_f32; - let _okf2 = 1_f32; - let _failf1 = 1.5f32; - let _failf2 = 1f32; - - // Test for macro - let _ = lit_from_macro!(); - - // Counter example - let _ = line!(); - // Because `assert!` contains `line!()` macro. - assert_eq!(4897u32, 32223); -} diff --git a/tests/ui/unseparated_prefix_literals.stderr b/tests/ui/unseparated_prefix_literals.stderr deleted file mode 100644 index d7dd526bcb9a..000000000000 --- a/tests/ui/unseparated_prefix_literals.stderr +++ /dev/null @@ -1,63 +0,0 @@ -error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:23:18 - | -LL | let _fail1 = 1234i32; - | ^^^^^^^ help: add an underscore: `1234_i32` - | - = note: `-D clippy::unseparated-literal-suffix` implied by `-D warnings` - -error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:24:18 - | -LL | let _fail2 = 1234u32; - | ^^^^^^^ help: add an underscore: `1234_u32` - -error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:25:18 - | -LL | let _fail3 = 1234isize; - | ^^^^^^^^^ help: add an underscore: `1234_isize` - -error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:26:18 - | -LL | let _fail4 = 1234usize; - | ^^^^^^^^^ help: add an underscore: `1234_usize` - -error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:27:18 - | -LL | let _fail5 = 0x123isize; - | ^^^^^^^^^^ help: add an underscore: `0x123_isize` - -error: float type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:31:19 - | -LL | let _failf1 = 1.5f32; - | ^^^^^^ help: add an underscore: `1.5_f32` - -error: float type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:32:19 - | -LL | let _failf2 = 1f32; - | ^^^^ help: add an underscore: `1_f32` - -error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:15:9 - | -LL | 42usize - | ^^^^^^^ help: add an underscore: `42_usize` -... -LL | let _ = lit_from_macro!(); - | ----------------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:40:16 - | -LL | assert_eq!(4897u32, 32223); - | ^^^^^^^ help: add an underscore: `4897_u32` - -error: aborting due to 9 previous errors - diff --git a/tests/ui/unused_io_amount.rs b/tests/ui/unused_io_amount.rs deleted file mode 100644 index ebaba9629db1..000000000000 --- a/tests/ui/unused_io_amount.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![allow(dead_code)] -#![warn(clippy::unused_io_amount)] - -use std::io; - -fn question_mark(s: &mut T) -> io::Result<()> { - s.write(b"test")?; - let mut buf = [0u8; 4]; - s.read(&mut buf)?; - Ok(()) -} - -fn unwrap(s: &mut T) { - s.write(b"test").unwrap(); - let mut buf = [0u8; 4]; - s.read(&mut buf).unwrap(); -} - -fn vectored(s: &mut T) -> io::Result<()> { - s.read_vectored(&mut [io::IoSliceMut::new(&mut [])])?; - s.write_vectored(&[io::IoSlice::new(&[])])?; - Ok(()) -} - -fn main() {} diff --git a/tests/ui/unused_io_amount.stderr b/tests/ui/unused_io_amount.stderr deleted file mode 100644 index 5219d63980b4..000000000000 --- a/tests/ui/unused_io_amount.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: written amount is not handled. Use `Write::write_all` instead - --> $DIR/unused_io_amount.rs:7:5 - | -LL | s.write(b"test")?; - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::unused-io-amount` implied by `-D warnings` - -error: read amount is not handled. Use `Read::read_exact` instead - --> $DIR/unused_io_amount.rs:9:5 - | -LL | s.read(&mut buf)?; - | ^^^^^^^^^^^^^^^^^ - -error: written amount is not handled. Use `Write::write_all` instead - --> $DIR/unused_io_amount.rs:14:5 - | -LL | s.write(b"test").unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: read amount is not handled. Use `Read::read_exact` instead - --> $DIR/unused_io_amount.rs:16:5 - | -LL | s.read(&mut buf).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: read amount is not handled - --> $DIR/unused_io_amount.rs:20:5 - | -LL | s.read_vectored(&mut [io::IoSliceMut::new(&mut [])])?; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: written amount is not handled - --> $DIR/unused_io_amount.rs:21:5 - | -LL | s.write_vectored(&[io::IoSlice::new(&[])])?; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/unused_self.rs b/tests/ui/unused_self.rs deleted file mode 100644 index 7a4bbdda1ab2..000000000000 --- a/tests/ui/unused_self.rs +++ /dev/null @@ -1,140 +0,0 @@ -#![warn(clippy::unused_self)] -#![allow(clippy::boxed_local, clippy::fn_params_excessive_bools)] - -mod unused_self { - use std::pin::Pin; - use std::sync::{Arc, Mutex}; - - struct A {} - - impl A { - fn unused_self_move(self) {} - fn unused_self_ref(&self) {} - fn unused_self_mut_ref(&mut self) {} - fn unused_self_pin_ref(self: Pin<&Self>) {} - fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {} - fn unused_self_pin_nested(self: Pin>) {} - fn unused_self_box(self: Box) {} - fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 { - x + y - } - fn unused_self_class_method(&self) { - Self::static_method(); - } - - fn static_method() {} - } -} - -mod unused_self_allow { - struct A {} - - impl A { - // shouldn't trigger - #[allow(clippy::unused_self)] - fn unused_self_move(self) {} - } - - struct B {} - - // shouldn't trigger - #[allow(clippy::unused_self)] - impl B { - fn unused_self_move(self) {} - } - - struct C {} - - #[allow(clippy::unused_self)] - impl C { - #[warn(clippy::unused_self)] - fn some_fn((): ()) {} - - // shouldn't trigger - fn unused_self_move(self) {} - } -} - -mod used_self { - use std::pin::Pin; - - struct A { - x: u8, - } - - impl A { - fn used_self_move(self) -> u8 { - self.x - } - fn used_self_ref(&self) -> u8 { - self.x - } - fn used_self_mut_ref(&mut self) { - self.x += 1 - } - fn used_self_pin_ref(self: Pin<&Self>) -> u8 { - self.x - } - fn used_self_box(self: Box) -> u8 { - self.x - } - fn used_self_with_other_unused_args(&self, x: u8, y: u8) -> u8 { - self.x - } - fn used_in_nested_closure(&self) -> u8 { - let mut a = || -> u8 { self.x }; - a() - } - - #[allow(clippy::collapsible_if)] - fn used_self_method_nested_conditions(&self, a: bool, b: bool, c: bool, d: bool) { - if a { - if b { - if c { - if d { - self.used_self_ref(); - } - } - } - } - } - - fn foo(&self) -> u32 { - let mut sum = 0u32; - for i in 0..self.x { - sum += i as u32; - } - sum - } - - fn bar(&mut self, x: u8) -> u32 { - let mut y = 0u32; - for i in 0..x { - y += self.foo() - } - y - } - } -} - -mod not_applicable { - use std::fmt; - - struct A {} - - impl fmt::Debug for A { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "A") - } - } - - impl A { - fn method(x: u8, y: u8) {} - } - - trait B { - fn method(&self) {} - } -} - -fn main() {} diff --git a/tests/ui/unused_self.stderr b/tests/ui/unused_self.stderr deleted file mode 100644 index 0534b40eabb7..000000000000 --- a/tests/ui/unused_self.stderr +++ /dev/null @@ -1,75 +0,0 @@ -error: unused `self` argument - --> $DIR/unused_self.rs:11:29 - | -LL | fn unused_self_move(self) {} - | ^^^^ - | - = note: `-D clippy::unused-self` implied by `-D warnings` - = help: consider refactoring to a associated function - -error: unused `self` argument - --> $DIR/unused_self.rs:12:28 - | -LL | fn unused_self_ref(&self) {} - | ^^^^^ - | - = help: consider refactoring to a associated function - -error: unused `self` argument - --> $DIR/unused_self.rs:13:32 - | -LL | fn unused_self_mut_ref(&mut self) {} - | ^^^^^^^^^ - | - = help: consider refactoring to a associated function - -error: unused `self` argument - --> $DIR/unused_self.rs:14:32 - | -LL | fn unused_self_pin_ref(self: Pin<&Self>) {} - | ^^^^ - | - = help: consider refactoring to a associated function - -error: unused `self` argument - --> $DIR/unused_self.rs:15:36 - | -LL | fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {} - | ^^^^ - | - = help: consider refactoring to a associated function - -error: unused `self` argument - --> $DIR/unused_self.rs:16:35 - | -LL | fn unused_self_pin_nested(self: Pin>) {} - | ^^^^ - | - = help: consider refactoring to a associated function - -error: unused `self` argument - --> $DIR/unused_self.rs:17:28 - | -LL | fn unused_self_box(self: Box) {} - | ^^^^ - | - = help: consider refactoring to a associated function - -error: unused `self` argument - --> $DIR/unused_self.rs:18:40 - | -LL | fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 { - | ^^^^^ - | - = help: consider refactoring to a associated function - -error: unused `self` argument - --> $DIR/unused_self.rs:21:37 - | -LL | fn unused_self_class_method(&self) { - | ^^^^^ - | - = help: consider refactoring to a associated function - -error: aborting due to 9 previous errors - diff --git a/tests/ui/unused_unit.fixed b/tests/ui/unused_unit.fixed deleted file mode 100644 index 7afc53613563..000000000000 --- a/tests/ui/unused_unit.fixed +++ /dev/null @@ -1,81 +0,0 @@ -// run-rustfix - -// The output for humans should just highlight the whole span without showing -// the suggested replacement, but we also want to test that suggested -// replacement only removes one set of parentheses, rather than naïvely -// stripping away any starting or ending parenthesis characters—hence this -// test of the JSON error format. - -#![feature(custom_inner_attributes)] -#![rustfmt::skip] - -#![deny(clippy::unused_unit)] -#![allow(dead_code)] - -struct Unitter; -impl Unitter { - #[allow(clippy::no_effect)] - pub fn get_unit(&self, f: F, _g: G) - where G: Fn() { - let _y: &dyn Fn() = &f; - (); // this should not lint, as it's not in return type position - } -} - -impl Into<()> for Unitter { - #[rustfmt::skip] - fn into(self) { - - } -} - -trait Trait { - fn redundant(&self, _f: F, _g: G, _h: H) - where - G: FnMut(), - H: Fn(); -} - -impl Trait for Unitter { - fn redundant(&self, _f: F, _g: G, _h: H) - where - G: FnMut(), - H: Fn() {} -} - -fn return_unit() { } - -#[allow(clippy::needless_return)] -#[allow(clippy::never_loop)] -#[allow(clippy::unit_cmp)] -fn main() { - let u = Unitter; - assert_eq!(u.get_unit(|| {}, return_unit), u.into()); - return_unit(); - loop { - break; - } - return; -} - -// https://github.com/rust-lang/rust-clippy/issues/4076 -fn foo() { - macro_rules! foo { - (recv($r:expr) -> $res:pat => $body:expr) => { - $body - } - } - - foo! { - recv(rx) -> _x => () - } -} - -#[rustfmt::skip] -fn test(){} - -#[rustfmt::skip] -fn test2(){} - -#[rustfmt::skip] -fn test3(){} diff --git a/tests/ui/unused_unit.rs b/tests/ui/unused_unit.rs deleted file mode 100644 index 96cef1ed5a5f..000000000000 --- a/tests/ui/unused_unit.rs +++ /dev/null @@ -1,81 +0,0 @@ -// run-rustfix - -// The output for humans should just highlight the whole span without showing -// the suggested replacement, but we also want to test that suggested -// replacement only removes one set of parentheses, rather than naïvely -// stripping away any starting or ending parenthesis characters—hence this -// test of the JSON error format. - -#![feature(custom_inner_attributes)] -#![rustfmt::skip] - -#![deny(clippy::unused_unit)] -#![allow(dead_code)] - -struct Unitter; -impl Unitter { - #[allow(clippy::no_effect)] - pub fn get_unit (), G>(&self, f: F, _g: G) -> () - where G: Fn() -> () { - let _y: &dyn Fn() -> () = &f; - (); // this should not lint, as it's not in return type position - } -} - -impl Into<()> for Unitter { - #[rustfmt::skip] - fn into(self) -> () { - () - } -} - -trait Trait { - fn redundant (), G, H>(&self, _f: F, _g: G, _h: H) - where - G: FnMut() -> (), - H: Fn() -> (); -} - -impl Trait for Unitter { - fn redundant (), G, H>(&self, _f: F, _g: G, _h: H) - where - G: FnMut() -> (), - H: Fn() -> () {} -} - -fn return_unit() -> () { () } - -#[allow(clippy::needless_return)] -#[allow(clippy::never_loop)] -#[allow(clippy::unit_cmp)] -fn main() { - let u = Unitter; - assert_eq!(u.get_unit(|| {}, return_unit), u.into()); - return_unit(); - loop { - break(); - } - return(); -} - -// https://github.com/rust-lang/rust-clippy/issues/4076 -fn foo() { - macro_rules! foo { - (recv($r:expr) -> $res:pat => $body:expr) => { - $body - } - } - - foo! { - recv(rx) -> _x => () - } -} - -#[rustfmt::skip] -fn test()->(){} - -#[rustfmt::skip] -fn test2() ->(){} - -#[rustfmt::skip] -fn test3()-> (){} diff --git a/tests/ui/unused_unit.stderr b/tests/ui/unused_unit.stderr deleted file mode 100644 index c45634c2b6df..000000000000 --- a/tests/ui/unused_unit.stderr +++ /dev/null @@ -1,122 +0,0 @@ -error: unneeded unit return type - --> $DIR/unused_unit.rs:18:28 - | -LL | pub fn get_unit (), G>(&self, f: F, _g: G) -> () - | ^^^^^^ help: remove the `-> ()` - | -note: the lint level is defined here - --> $DIR/unused_unit.rs:12:9 - | -LL | #![deny(clippy::unused_unit)] - | ^^^^^^^^^^^^^^^^^^^ - -error: unneeded unit return type - --> $DIR/unused_unit.rs:19:18 - | -LL | where G: Fn() -> () { - | ^^^^^^ help: remove the `-> ()` - -error: unneeded unit return type - --> $DIR/unused_unit.rs:18:58 - | -LL | pub fn get_unit (), G>(&self, f: F, _g: G) -> () - | ^^^^^^ help: remove the `-> ()` - -error: unneeded unit return type - --> $DIR/unused_unit.rs:20:26 - | -LL | let _y: &dyn Fn() -> () = &f; - | ^^^^^^ help: remove the `-> ()` - -error: unneeded unit return type - --> $DIR/unused_unit.rs:27:18 - | -LL | fn into(self) -> () { - | ^^^^^^ help: remove the `-> ()` - -error: unneeded unit expression - --> $DIR/unused_unit.rs:28:9 - | -LL | () - | ^^ help: remove the final `()` - -error: unneeded unit return type - --> $DIR/unused_unit.rs:33:29 - | -LL | fn redundant (), G, H>(&self, _f: F, _g: G, _h: H) - | ^^^^^^ help: remove the `-> ()` - -error: unneeded unit return type - --> $DIR/unused_unit.rs:35:19 - | -LL | G: FnMut() -> (), - | ^^^^^^ help: remove the `-> ()` - -error: unneeded unit return type - --> $DIR/unused_unit.rs:36:16 - | -LL | H: Fn() -> (); - | ^^^^^^ help: remove the `-> ()` - -error: unneeded unit return type - --> $DIR/unused_unit.rs:40:29 - | -LL | fn redundant (), G, H>(&self, _f: F, _g: G, _h: H) - | ^^^^^^ help: remove the `-> ()` - -error: unneeded unit return type - --> $DIR/unused_unit.rs:42:19 - | -LL | G: FnMut() -> (), - | ^^^^^^ help: remove the `-> ()` - -error: unneeded unit return type - --> $DIR/unused_unit.rs:43:16 - | -LL | H: Fn() -> () {} - | ^^^^^^ help: remove the `-> ()` - -error: unneeded unit return type - --> $DIR/unused_unit.rs:46:17 - | -LL | fn return_unit() -> () { () } - | ^^^^^^ help: remove the `-> ()` - -error: unneeded unit expression - --> $DIR/unused_unit.rs:46:26 - | -LL | fn return_unit() -> () { () } - | ^^ help: remove the final `()` - -error: unneeded `()` - --> $DIR/unused_unit.rs:56:14 - | -LL | break(); - | ^^ help: remove the `()` - -error: unneeded `()` - --> $DIR/unused_unit.rs:58:11 - | -LL | return(); - | ^^ help: remove the `()` - -error: unneeded unit return type - --> $DIR/unused_unit.rs:75:10 - | -LL | fn test()->(){} - | ^^^^ help: remove the `-> ()` - -error: unneeded unit return type - --> $DIR/unused_unit.rs:78:11 - | -LL | fn test2() ->(){} - | ^^^^^ help: remove the `-> ()` - -error: unneeded unit return type - --> $DIR/unused_unit.rs:81:11 - | -LL | fn test3()-> (){} - | ^^^^^ help: remove the `-> ()` - -error: aborting due to 19 previous errors - diff --git a/tests/ui/unwrap.rs b/tests/ui/unwrap.rs deleted file mode 100644 index a4a3cd1d3797..000000000000 --- a/tests/ui/unwrap.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![warn(clippy::unwrap_used)] - -fn unwrap_option() { - let opt = Some(0); - let _ = opt.unwrap(); -} - -fn unwrap_result() { - let res: Result = Ok(0); - let _ = res.unwrap(); -} - -fn main() { - unwrap_option(); - unwrap_result(); -} diff --git a/tests/ui/unwrap.stderr b/tests/ui/unwrap.stderr deleted file mode 100644 index 4f0858005f6e..000000000000 --- a/tests/ui/unwrap.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: used `unwrap()` on `an Option` value - --> $DIR/unwrap.rs:5:13 - | -LL | let _ = opt.unwrap(); - | ^^^^^^^^^^^^ - | - = note: `-D clippy::unwrap-used` implied by `-D warnings` - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message - -error: used `unwrap()` on `a Result` value - --> $DIR/unwrap.rs:10:13 - | -LL | let _ = res.unwrap(); - | ^^^^^^^^^^^^ - | - = help: if you don't want to handle the `Err` case gracefully, consider using `expect()` to provide a better panic message - -error: aborting due to 2 previous errors - diff --git a/tests/ui/unwrap_in_result.rs b/tests/ui/unwrap_in_result.rs deleted file mode 100644 index 2aa842adc856..000000000000 --- a/tests/ui/unwrap_in_result.rs +++ /dev/null @@ -1,44 +0,0 @@ -#![warn(clippy::unwrap_in_result)] - -struct A; - -impl A { - // should not be detected - fn good_divisible_by_3(i_str: String) -> Result { - // checks whether a string represents a number divisible by 3 - let i_result = i_str.parse::(); - match i_result { - Err(_e) => Err("Not a number".to_string()), - Ok(i) => { - if i % 3 == 0 { - return Ok(true); - } - Err("Number is not divisible by 3".to_string()) - }, - } - } - - // should be detected - fn bad_divisible_by_3(i_str: String) -> Result { - // checks whether a string represents a number divisible by 3 - let i = i_str.parse::().unwrap(); - if i % 3 == 0 { - Ok(true) - } else { - Err("Number is not divisible by 3".to_string()) - } - } - - fn example_option_expect(i_str: String) -> Option { - let i = i_str.parse::().expect("not a number"); - if i % 3 == 0 { - return Some(true); - } - None - } -} - -fn main() { - A::bad_divisible_by_3("3".to_string()); - A::good_divisible_by_3("3".to_string()); -} diff --git a/tests/ui/unwrap_in_result.stderr b/tests/ui/unwrap_in_result.stderr deleted file mode 100644 index 56bc2f2d1c00..000000000000 --- a/tests/ui/unwrap_in_result.stderr +++ /dev/null @@ -1,41 +0,0 @@ -error: used unwrap or expect in a function that returns result or option - --> $DIR/unwrap_in_result.rs:22:5 - | -LL | / fn bad_divisible_by_3(i_str: String) -> Result { -LL | | // checks whether a string represents a number divisible by 3 -LL | | let i = i_str.parse::().unwrap(); -LL | | if i % 3 == 0 { -... | -LL | | } -LL | | } - | |_____^ - | - = note: `-D clippy::unwrap-in-result` implied by `-D warnings` - = help: unwrap and expect should not be used in a function that returns result or option -note: potential non-recoverable error(s) - --> $DIR/unwrap_in_result.rs:24:17 - | -LL | let i = i_str.parse::().unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: used unwrap or expect in a function that returns result or option - --> $DIR/unwrap_in_result.rs:32:5 - | -LL | / fn example_option_expect(i_str: String) -> Option { -LL | | let i = i_str.parse::().expect("not a number"); -LL | | if i % 3 == 0 { -LL | | return Some(true); -LL | | } -LL | | None -LL | | } - | |_____^ - | - = help: unwrap and expect should not be used in a function that returns result or option -note: potential non-recoverable error(s) - --> $DIR/unwrap_in_result.rs:33:17 - | -LL | let i = i_str.parse::().expect("not a number"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/unwrap_or.rs b/tests/ui/unwrap_or.rs deleted file mode 100644 index bfb41e439473..000000000000 --- a/tests/ui/unwrap_or.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![warn(clippy::all)] - -fn main() { - let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); -} - -fn new_lines() { - let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); -} diff --git a/tests/ui/unwrap_or.stderr b/tests/ui/unwrap_or.stderr deleted file mode 100644 index c3a7464fd470..000000000000 --- a/tests/ui/unwrap_or.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: use of `unwrap_or` followed by a function call - --> $DIR/unwrap_or.rs:4:47 - | -LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| "Fail".to_string())` - | - = note: `-D clippy::or-fun-call` implied by `-D warnings` - -error: use of `unwrap_or` followed by a function call - --> $DIR/unwrap_or.rs:8:47 - | -LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| "Fail".to_string())` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/update-all-references.sh b/tests/ui/update-all-references.sh deleted file mode 100755 index 4391499a1e1f..000000000000 --- a/tests/ui/update-all-references.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -echo "Please use 'cargo dev bless' instead." diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed deleted file mode 100644 index d6a890014e68..000000000000 --- a/tests/ui/use_self.fixed +++ /dev/null @@ -1,254 +0,0 @@ -// run-rustfix -// edition:2018 - -#![warn(clippy::use_self)] -#![allow(dead_code)] -#![allow(clippy::should_implement_trait)] - -fn main() {} - -mod use_self { - struct Foo {} - - impl Foo { - fn new() -> Self { - Self {} - } - fn test() -> Self { - Self::new() - } - } - - impl Default for Foo { - fn default() -> Self { - Self::new() - } - } -} - -mod better { - struct Foo {} - - impl Foo { - fn new() -> Self { - Self {} - } - fn test() -> Self { - Self::new() - } - } - - impl Default for Foo { - fn default() -> Self { - Self::new() - } - } -} - -mod lifetimes { - struct Foo<'a> { - foo_str: &'a str, - } - - impl<'a> Foo<'a> { - // Cannot use `Self` as return type, because the function is actually `fn foo<'b>(s: &'b str) -> - // Foo<'b>` - fn foo(s: &str) -> Foo { - Foo { foo_str: s } - } - // cannot replace with `Self`, because that's `Foo<'a>` - fn bar() -> Foo<'static> { - Foo { foo_str: "foo" } - } - - // FIXME: the lint does not handle lifetimed struct - // `Self` should be applicable here - fn clone(&self) -> Foo<'a> { - Foo { foo_str: self.foo_str } - } - } -} - -mod issue2894 { - trait IntoBytes { - #[allow(clippy::wrong_self_convention)] - fn into_bytes(&self) -> Vec; - } - - // This should not be linted - impl IntoBytes for u8 { - fn into_bytes(&self) -> Vec { - vec![*self] - } - } -} - -mod existential { - struct Foo; - - impl Foo { - fn bad(foos: &[Self]) -> impl Iterator { - foos.iter() - } - - fn good(foos: &[Self]) -> impl Iterator { - foos.iter() - } - } -} - -mod tuple_structs { - pub struct TS(i32); - - impl TS { - pub fn ts() -> Self { - Self(0) - } - } -} - -mod macros { - macro_rules! use_self_expand { - () => { - fn new() -> Self { - Self {} - } - }; - } - - struct Foo {} - - impl Foo { - use_self_expand!(); // Should lint in local macros - } -} - -mod nesting { - struct Foo {} - impl Foo { - fn foo() { - #[allow(unused_imports)] - use self::Foo; // Can't use Self here - struct Bar { - foo: Foo, // Foo != Self - } - - impl Bar { - fn bar() -> Self { - Self { foo: Foo {} } - } - } - - // Can't use Self here - fn baz() -> Foo { - Foo {} - } - } - - // Should lint here - fn baz() -> Self { - Self {} - } - } - - enum Enum { - A, - B(u64), - C { field: bool }, - } - impl Enum { - fn method() { - #[allow(unused_imports)] - use self::Enum::*; // Issue 3425 - static STATIC: Enum = Enum::A; // Can't use Self as type - } - - fn method2() { - let _ = Self::B(42); - let _ = Self::C { field: true }; - let _ = Self::A; - } - } -} - -mod issue3410 { - - struct A; - struct B; - - trait Trait { - fn a(v: T); - } - - impl Trait> for Vec { - fn a(_: Vec) {} - } -} - -#[allow(clippy::no_effect, path_statements)] -mod rustfix { - mod nested { - pub struct A {} - } - - impl nested::A { - const A: bool = true; - - fn fun_1() {} - - fn fun_2() { - Self::fun_1(); - Self::A; - - Self {}; - } - } -} - -mod issue3567 { - struct TestStruct {} - impl TestStruct { - fn from_something() -> Self { - Self {} - } - } - - trait Test { - fn test() -> TestStruct; - } - - impl Test for TestStruct { - fn test() -> TestStruct { - Self::from_something() - } - } -} - -mod paths_created_by_lowering { - use std::ops::Range; - - struct S {} - - impl S { - const A: usize = 0; - const B: usize = 1; - - async fn g() -> Self { - Self {} - } - - fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] { - &p[Self::A..Self::B] - } - } - - trait T { - fn f<'a>(&self, p: &'a [u8]) -> &'a [u8]; - } - - impl T for Range { - fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] { - &p[0..1] - } - } -} diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs deleted file mode 100644 index b04d9ce75b2a..000000000000 --- a/tests/ui/use_self.rs +++ /dev/null @@ -1,254 +0,0 @@ -// run-rustfix -// edition:2018 - -#![warn(clippy::use_self)] -#![allow(dead_code)] -#![allow(clippy::should_implement_trait)] - -fn main() {} - -mod use_self { - struct Foo {} - - impl Foo { - fn new() -> Foo { - Foo {} - } - fn test() -> Foo { - Foo::new() - } - } - - impl Default for Foo { - fn default() -> Foo { - Foo::new() - } - } -} - -mod better { - struct Foo {} - - impl Foo { - fn new() -> Self { - Self {} - } - fn test() -> Self { - Self::new() - } - } - - impl Default for Foo { - fn default() -> Self { - Self::new() - } - } -} - -mod lifetimes { - struct Foo<'a> { - foo_str: &'a str, - } - - impl<'a> Foo<'a> { - // Cannot use `Self` as return type, because the function is actually `fn foo<'b>(s: &'b str) -> - // Foo<'b>` - fn foo(s: &str) -> Foo { - Foo { foo_str: s } - } - // cannot replace with `Self`, because that's `Foo<'a>` - fn bar() -> Foo<'static> { - Foo { foo_str: "foo" } - } - - // FIXME: the lint does not handle lifetimed struct - // `Self` should be applicable here - fn clone(&self) -> Foo<'a> { - Foo { foo_str: self.foo_str } - } - } -} - -mod issue2894 { - trait IntoBytes { - #[allow(clippy::wrong_self_convention)] - fn into_bytes(&self) -> Vec; - } - - // This should not be linted - impl IntoBytes for u8 { - fn into_bytes(&self) -> Vec { - vec![*self] - } - } -} - -mod existential { - struct Foo; - - impl Foo { - fn bad(foos: &[Self]) -> impl Iterator { - foos.iter() - } - - fn good(foos: &[Self]) -> impl Iterator { - foos.iter() - } - } -} - -mod tuple_structs { - pub struct TS(i32); - - impl TS { - pub fn ts() -> Self { - TS(0) - } - } -} - -mod macros { - macro_rules! use_self_expand { - () => { - fn new() -> Foo { - Foo {} - } - }; - } - - struct Foo {} - - impl Foo { - use_self_expand!(); // Should lint in local macros - } -} - -mod nesting { - struct Foo {} - impl Foo { - fn foo() { - #[allow(unused_imports)] - use self::Foo; // Can't use Self here - struct Bar { - foo: Foo, // Foo != Self - } - - impl Bar { - fn bar() -> Bar { - Bar { foo: Foo {} } - } - } - - // Can't use Self here - fn baz() -> Foo { - Foo {} - } - } - - // Should lint here - fn baz() -> Foo { - Foo {} - } - } - - enum Enum { - A, - B(u64), - C { field: bool }, - } - impl Enum { - fn method() { - #[allow(unused_imports)] - use self::Enum::*; // Issue 3425 - static STATIC: Enum = Enum::A; // Can't use Self as type - } - - fn method2() { - let _ = Enum::B(42); - let _ = Enum::C { field: true }; - let _ = Enum::A; - } - } -} - -mod issue3410 { - - struct A; - struct B; - - trait Trait { - fn a(v: T); - } - - impl Trait> for Vec { - fn a(_: Vec) {} - } -} - -#[allow(clippy::no_effect, path_statements)] -mod rustfix { - mod nested { - pub struct A {} - } - - impl nested::A { - const A: bool = true; - - fn fun_1() {} - - fn fun_2() { - nested::A::fun_1(); - nested::A::A; - - nested::A {}; - } - } -} - -mod issue3567 { - struct TestStruct {} - impl TestStruct { - fn from_something() -> Self { - Self {} - } - } - - trait Test { - fn test() -> TestStruct; - } - - impl Test for TestStruct { - fn test() -> TestStruct { - TestStruct::from_something() - } - } -} - -mod paths_created_by_lowering { - use std::ops::Range; - - struct S {} - - impl S { - const A: usize = 0; - const B: usize = 1; - - async fn g() -> S { - S {} - } - - fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] { - &p[S::A..S::B] - } - } - - trait T { - fn f<'a>(&self, p: &'a [u8]) -> &'a [u8]; - } - - impl T for Range { - fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] { - &p[0..1] - } - } -} diff --git a/tests/ui/use_self.stderr b/tests/ui/use_self.stderr deleted file mode 100644 index 80e1bfc75e80..000000000000 --- a/tests/ui/use_self.stderr +++ /dev/null @@ -1,164 +0,0 @@ -error: unnecessary structure name repetition - --> $DIR/use_self.rs:14:21 - | -LL | fn new() -> Foo { - | ^^^ help: use the applicable keyword: `Self` - | - = note: `-D clippy::use-self` implied by `-D warnings` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:15:13 - | -LL | Foo {} - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:17:22 - | -LL | fn test() -> Foo { - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:18:13 - | -LL | Foo::new() - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:23:25 - | -LL | fn default() -> Foo { - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:24:13 - | -LL | Foo::new() - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:90:56 - | -LL | fn bad(foos: &[Self]) -> impl Iterator { - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:105:13 - | -LL | TS(0) - | ^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:113:25 - | -LL | fn new() -> Foo { - | ^^^ help: use the applicable keyword: `Self` -... -LL | use_self_expand!(); // Should lint in local macros - | ------------------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:114:17 - | -LL | Foo {} - | ^^^ help: use the applicable keyword: `Self` -... -LL | use_self_expand!(); // Should lint in local macros - | ------------------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:149:21 - | -LL | fn baz() -> Foo { - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:150:13 - | -LL | Foo {} - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:137:29 - | -LL | fn bar() -> Bar { - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:138:21 - | -LL | Bar { foo: Foo {} } - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:167:21 - | -LL | let _ = Enum::B(42); - | ^^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:168:21 - | -LL | let _ = Enum::C { field: true }; - | ^^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:169:21 - | -LL | let _ = Enum::A; - | ^^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:200:13 - | -LL | nested::A::fun_1(); - | ^^^^^^^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:201:13 - | -LL | nested::A::A; - | ^^^^^^^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:203:13 - | -LL | nested::A {}; - | ^^^^^^^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:222:13 - | -LL | TestStruct::from_something() - | ^^^^^^^^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:236:25 - | -LL | async fn g() -> S { - | ^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:237:13 - | -LL | S {} - | ^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:241:16 - | -LL | &p[S::A..S::B] - | ^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:241:22 - | -LL | &p[S::A..S::B] - | ^ help: use the applicable keyword: `Self` - -error: aborting due to 25 previous errors - diff --git a/tests/ui/use_self_trait.fixed b/tests/ui/use_self_trait.fixed deleted file mode 100644 index 1582ae114bf4..000000000000 --- a/tests/ui/use_self_trait.fixed +++ /dev/null @@ -1,114 +0,0 @@ -// run-rustfix - -#![warn(clippy::use_self)] -#![allow(dead_code)] -#![allow(clippy::should_implement_trait, clippy::boxed_local)] - -use std::ops::Mul; - -trait SelfTrait { - fn refs(p1: &Self) -> &Self; - fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self; - fn mut_refs(p1: &mut Self) -> &mut Self; - fn nested(p1: Box, p2: (&u8, &Self)); - fn vals(r: Self) -> Self; -} - -#[derive(Default)] -struct Bad; - -impl SelfTrait for Bad { - fn refs(p1: &Self) -> &Self { - p1 - } - - fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self { - p1 - } - - fn mut_refs(p1: &mut Self) -> &mut Self { - p1 - } - - fn nested(_p1: Box, _p2: (&u8, &Self)) {} - - fn vals(_: Self) -> Self { - Self::default() - } -} - -impl Mul for Bad { - type Output = Self; - - fn mul(self, rhs: Self) -> Self { - rhs - } -} - -impl Clone for Bad { - fn clone(&self) -> Self { - Self - } -} - -#[derive(Default)] -struct Good; - -impl SelfTrait for Good { - fn refs(p1: &Self) -> &Self { - p1 - } - - fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self { - p1 - } - - fn mut_refs(p1: &mut Self) -> &mut Self { - p1 - } - - fn nested(_p1: Box, _p2: (&u8, &Self)) {} - - fn vals(_: Self) -> Self { - Self::default() - } -} - -impl Mul for Good { - type Output = Self; - - fn mul(self, rhs: Self) -> Self { - rhs - } -} - -trait NameTrait { - fn refs(p1: &u8) -> &u8; - fn ref_refs<'a>(p1: &'a &'a u8) -> &'a &'a u8; - fn mut_refs(p1: &mut u8) -> &mut u8; - fn nested(p1: Box, p2: (&u8, &u8)); - fn vals(p1: u8) -> u8; -} - -// Using `Self` instead of the type name is OK -impl NameTrait for u8 { - fn refs(p1: &Self) -> &Self { - p1 - } - - fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self { - p1 - } - - fn mut_refs(p1: &mut Self) -> &mut Self { - p1 - } - - fn nested(_p1: Box, _p2: (&Self, &Self)) {} - - fn vals(_: Self) -> Self { - Self::default() - } -} - -fn main() {} diff --git a/tests/ui/use_self_trait.rs b/tests/ui/use_self_trait.rs deleted file mode 100644 index 70667b9797e7..000000000000 --- a/tests/ui/use_self_trait.rs +++ /dev/null @@ -1,114 +0,0 @@ -// run-rustfix - -#![warn(clippy::use_self)] -#![allow(dead_code)] -#![allow(clippy::should_implement_trait, clippy::boxed_local)] - -use std::ops::Mul; - -trait SelfTrait { - fn refs(p1: &Self) -> &Self; - fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self; - fn mut_refs(p1: &mut Self) -> &mut Self; - fn nested(p1: Box, p2: (&u8, &Self)); - fn vals(r: Self) -> Self; -} - -#[derive(Default)] -struct Bad; - -impl SelfTrait for Bad { - fn refs(p1: &Bad) -> &Bad { - p1 - } - - fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad { - p1 - } - - fn mut_refs(p1: &mut Bad) -> &mut Bad { - p1 - } - - fn nested(_p1: Box, _p2: (&u8, &Bad)) {} - - fn vals(_: Bad) -> Bad { - Bad::default() - } -} - -impl Mul for Bad { - type Output = Bad; - - fn mul(self, rhs: Bad) -> Bad { - rhs - } -} - -impl Clone for Bad { - fn clone(&self) -> Self { - Bad - } -} - -#[derive(Default)] -struct Good; - -impl SelfTrait for Good { - fn refs(p1: &Self) -> &Self { - p1 - } - - fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self { - p1 - } - - fn mut_refs(p1: &mut Self) -> &mut Self { - p1 - } - - fn nested(_p1: Box, _p2: (&u8, &Self)) {} - - fn vals(_: Self) -> Self { - Self::default() - } -} - -impl Mul for Good { - type Output = Self; - - fn mul(self, rhs: Self) -> Self { - rhs - } -} - -trait NameTrait { - fn refs(p1: &u8) -> &u8; - fn ref_refs<'a>(p1: &'a &'a u8) -> &'a &'a u8; - fn mut_refs(p1: &mut u8) -> &mut u8; - fn nested(p1: Box, p2: (&u8, &u8)); - fn vals(p1: u8) -> u8; -} - -// Using `Self` instead of the type name is OK -impl NameTrait for u8 { - fn refs(p1: &Self) -> &Self { - p1 - } - - fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self { - p1 - } - - fn mut_refs(p1: &mut Self) -> &mut Self { - p1 - } - - fn nested(_p1: Box, _p2: (&Self, &Self)) {} - - fn vals(_: Self) -> Self { - Self::default() - } -} - -fn main() {} diff --git a/tests/ui/use_self_trait.stderr b/tests/ui/use_self_trait.stderr deleted file mode 100644 index 4f2506cc1192..000000000000 --- a/tests/ui/use_self_trait.stderr +++ /dev/null @@ -1,94 +0,0 @@ -error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:21:18 - | -LL | fn refs(p1: &Bad) -> &Bad { - | ^^^ help: use the applicable keyword: `Self` - | - = note: `-D clippy::use-self` implied by `-D warnings` - -error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:21:27 - | -LL | fn refs(p1: &Bad) -> &Bad { - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:25:33 - | -LL | fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad { - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:25:49 - | -LL | fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad { - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:29:26 - | -LL | fn mut_refs(p1: &mut Bad) -> &mut Bad { - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:29:39 - | -LL | fn mut_refs(p1: &mut Bad) -> &mut Bad { - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:33:24 - | -LL | fn nested(_p1: Box, _p2: (&u8, &Bad)) {} - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:33:42 - | -LL | fn nested(_p1: Box, _p2: (&u8, &Bad)) {} - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:35:16 - | -LL | fn vals(_: Bad) -> Bad { - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:35:24 - | -LL | fn vals(_: Bad) -> Bad { - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:36:9 - | -LL | Bad::default() - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:41:19 - | -LL | type Output = Bad; - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:43:23 - | -LL | fn mul(self, rhs: Bad) -> Bad { - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:43:31 - | -LL | fn mul(self, rhs: Bad) -> Bad { - | ^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:50:9 - | -LL | Bad - | ^^^ help: use the applicable keyword: `Self` - -error: aborting due to 15 previous errors - diff --git a/tests/ui/used_underscore_binding.rs b/tests/ui/used_underscore_binding.rs deleted file mode 100644 index d8bda7e8f48a..000000000000 --- a/tests/ui/used_underscore_binding.rs +++ /dev/null @@ -1,119 +0,0 @@ -// edition:2018 -// aux-build:proc_macro_derive.rs - -#![feature(rustc_private)] -#![warn(clippy::all)] -#![allow(clippy::blacklisted_name, clippy::eq_op)] -#![warn(clippy::used_underscore_binding)] - -#[macro_use] -extern crate proc_macro_derive; - -// This should not trigger the lint. There's underscore binding inside the external derive that -// would trigger the `used_underscore_binding` lint. -#[derive(DeriveSomething)] -struct Baz; - -macro_rules! test_macro { - () => {{ - let _foo = 42; - _foo + 1 - }}; -} - -/// Tests that we lint if we use a binding with a single leading underscore -fn prefix_underscore(_foo: u32) -> u32 { - _foo + 1 -} - -/// Tests that we lint if we use a `_`-variable defined outside within a macro expansion -fn in_macro_or_desugar(_foo: u32) { - println!("{}", _foo); - assert_eq!(_foo, _foo); - - test_macro!() + 1; -} - -// Struct for testing use of fields prefixed with an underscore -struct StructFieldTest { - _underscore_field: u32, -} - -/// Tests that we lint the use of a struct field which is prefixed with an underscore -fn in_struct_field() { - let mut s = StructFieldTest { _underscore_field: 0 }; - s._underscore_field += 1; -} - -/// Tests that we do not lint if the underscore is not a prefix -fn non_prefix_underscore(some_foo: u32) -> u32 { - some_foo + 1 -} - -/// Tests that we do not lint if we do not use the binding (simple case) -fn unused_underscore_simple(_foo: u32) -> u32 { - 1 -} - -/// Tests that we do not lint if we do not use the binding (complex case). This checks for -/// compatibility with the built-in `unused_variables` lint. -fn unused_underscore_complex(mut _foo: u32) -> u32 { - _foo += 1; - _foo = 2; - 1 -} - -/// Test that we do not lint for multiple underscores -fn multiple_underscores(__foo: u32) -> u32 { - __foo + 1 -} - -// Non-variable bindings with preceding underscore -fn _fn_test() {} -struct _StructTest; -enum _EnumTest { - _Empty, - _Value(_StructTest), -} - -/// Tests that we do not lint for non-variable bindings -fn non_variables() { - _fn_test(); - let _s = _StructTest; - let _e = match _EnumTest::_Value(_StructTest) { - _EnumTest::_Empty => 0, - _EnumTest::_Value(_st) => 1, - }; - let f = _fn_test; - f(); -} - -// Tests that we do not lint if the binding comes from await desugaring, -// but we do lint the awaited expression. See issue 5360. -async fn await_desugaring() { - async fn foo() {} - fn uses_i(_i: i32) {} - - foo().await; - ({ - let _i = 5; - uses_i(_i); - foo() - }) - .await -} - -fn main() { - let foo = 0u32; - // tests of unused_underscore lint - let _ = prefix_underscore(foo); - in_macro_or_desugar(foo); - in_struct_field(); - // possible false positives - let _ = non_prefix_underscore(foo); - let _ = unused_underscore_simple(foo); - let _ = unused_underscore_complex(foo); - let _ = multiple_underscores(foo); - non_variables(); - await_desugaring(); -} diff --git a/tests/ui/used_underscore_binding.stderr b/tests/ui/used_underscore_binding.stderr deleted file mode 100644 index 68e96148093d..000000000000 --- a/tests/ui/used_underscore_binding.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used. - --> $DIR/used_underscore_binding.rs:26:5 - | -LL | _foo + 1 - | ^^^^ - | - = note: `-D clippy::used-underscore-binding` implied by `-D warnings` - -error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used. - --> $DIR/used_underscore_binding.rs:31:20 - | -LL | println!("{}", _foo); - | ^^^^ - -error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used. - --> $DIR/used_underscore_binding.rs:32:16 - | -LL | assert_eq!(_foo, _foo); - | ^^^^ - -error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used. - --> $DIR/used_underscore_binding.rs:32:22 - | -LL | assert_eq!(_foo, _foo); - | ^^^^ - -error: used binding `_underscore_field` which is prefixed with an underscore. A leading underscore signals that a binding will not be used. - --> $DIR/used_underscore_binding.rs:45:5 - | -LL | s._underscore_field += 1; - | ^^^^^^^^^^^^^^^^^^^ - -error: used binding `_i` which is prefixed with an underscore. A leading underscore signals that a binding will not be used. - --> $DIR/used_underscore_binding.rs:100:16 - | -LL | uses_i(_i); - | ^^ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/useful_asref.rs b/tests/ui/useful_asref.rs deleted file mode 100644 index a9f0170a79cd..000000000000 --- a/tests/ui/useful_asref.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![deny(clippy::useless_asref)] - -trait Trait { - fn as_ptr(&self); -} - -impl<'a> Trait for &'a [u8] { - fn as_ptr(&self) { - self.as_ref().as_ptr(); - } -} - -fn main() {} diff --git a/tests/ui/useless_asref.fixed b/tests/ui/useless_asref.fixed deleted file mode 100644 index e356f13d087b..000000000000 --- a/tests/ui/useless_asref.fixed +++ /dev/null @@ -1,135 +0,0 @@ -// run-rustfix - -#![deny(clippy::useless_asref)] - -use std::fmt::Debug; - -struct FakeAsRef; - -#[allow(clippy::should_implement_trait)] -impl FakeAsRef { - fn as_ref(&self) -> &Self { - self - } -} - -struct MoreRef; - -impl<'a, 'b, 'c> AsRef<&'a &'b &'c MoreRef> for MoreRef { - fn as_ref(&self) -> &&'a &'b &'c MoreRef { - &&&&MoreRef - } -} - -fn foo_rstr(x: &str) { - println!("{:?}", x); -} -fn foo_rslice(x: &[i32]) { - println!("{:?}", x); -} -fn foo_mrslice(x: &mut [i32]) { - println!("{:?}", x); -} -fn foo_rrrrmr(_: &&&&MoreRef) { - println!("so many refs"); -} - -fn not_ok() { - let rstr: &str = "hello"; - let mut mrslice: &mut [i32] = &mut [1, 2, 3]; - - { - let rslice: &[i32] = &*mrslice; - foo_rstr(rstr); - foo_rstr(rstr); - foo_rslice(rslice); - foo_rslice(rslice); - } - { - foo_mrslice(mrslice); - foo_mrslice(mrslice); - foo_rslice(mrslice); - foo_rslice(mrslice); - } - - { - let rrrrrstr = &&&&rstr; - let rrrrrslice = &&&&&*mrslice; - foo_rslice(rrrrrslice); - foo_rslice(rrrrrslice); - foo_rstr(rrrrrstr); - foo_rstr(rrrrrstr); - } - { - let mrrrrrslice = &mut &mut &mut &mut mrslice; - foo_mrslice(mrrrrrslice); - foo_mrslice(mrrrrrslice); - foo_rslice(mrrrrrslice); - foo_rslice(mrrrrrslice); - } - #[allow(unused_parens, clippy::double_parens)] - foo_rrrrmr((&&&&MoreRef)); - - generic_not_ok(mrslice); - generic_ok(mrslice); -} - -fn ok() { - let string = "hello".to_owned(); - let mut arr = [1, 2, 3]; - let mut vec = vec![1, 2, 3]; - - { - foo_rstr(string.as_ref()); - foo_rslice(arr.as_ref()); - foo_rslice(vec.as_ref()); - } - { - foo_mrslice(arr.as_mut()); - foo_mrslice(vec.as_mut()); - } - - { - let rrrrstring = &&&&string; - let rrrrarr = &&&&arr; - let rrrrvec = &&&&vec; - foo_rstr(rrrrstring.as_ref()); - foo_rslice(rrrrarr.as_ref()); - foo_rslice(rrrrvec.as_ref()); - } - { - let mrrrrarr = &mut &mut &mut &mut arr; - let mrrrrvec = &mut &mut &mut &mut vec; - foo_mrslice(mrrrrarr.as_mut()); - foo_mrslice(mrrrrvec.as_mut()); - } - FakeAsRef.as_ref(); - foo_rrrrmr(MoreRef.as_ref()); - - generic_not_ok(arr.as_mut()); - generic_ok(&mut arr); -} - -fn foo_mrt(t: &mut T) { - println!("{:?}", t); -} -fn foo_rt(t: &T) { - println!("{:?}", t); -} - -fn generic_not_ok + AsRef + Debug + ?Sized>(mrt: &mut T) { - foo_mrt(mrt); - foo_mrt(mrt); - foo_rt(mrt); - foo_rt(mrt); -} - -fn generic_ok + AsRef + ?Sized, T: Debug + ?Sized>(mru: &mut U) { - foo_mrt(mru.as_mut()); - foo_rt(mru.as_ref()); -} - -fn main() { - not_ok(); - ok(); -} diff --git a/tests/ui/useless_asref.rs b/tests/ui/useless_asref.rs deleted file mode 100644 index 2a80291f5d83..000000000000 --- a/tests/ui/useless_asref.rs +++ /dev/null @@ -1,135 +0,0 @@ -// run-rustfix - -#![deny(clippy::useless_asref)] - -use std::fmt::Debug; - -struct FakeAsRef; - -#[allow(clippy::should_implement_trait)] -impl FakeAsRef { - fn as_ref(&self) -> &Self { - self - } -} - -struct MoreRef; - -impl<'a, 'b, 'c> AsRef<&'a &'b &'c MoreRef> for MoreRef { - fn as_ref(&self) -> &&'a &'b &'c MoreRef { - &&&&MoreRef - } -} - -fn foo_rstr(x: &str) { - println!("{:?}", x); -} -fn foo_rslice(x: &[i32]) { - println!("{:?}", x); -} -fn foo_mrslice(x: &mut [i32]) { - println!("{:?}", x); -} -fn foo_rrrrmr(_: &&&&MoreRef) { - println!("so many refs"); -} - -fn not_ok() { - let rstr: &str = "hello"; - let mut mrslice: &mut [i32] = &mut [1, 2, 3]; - - { - let rslice: &[i32] = &*mrslice; - foo_rstr(rstr.as_ref()); - foo_rstr(rstr); - foo_rslice(rslice.as_ref()); - foo_rslice(rslice); - } - { - foo_mrslice(mrslice.as_mut()); - foo_mrslice(mrslice); - foo_rslice(mrslice.as_ref()); - foo_rslice(mrslice); - } - - { - let rrrrrstr = &&&&rstr; - let rrrrrslice = &&&&&*mrslice; - foo_rslice(rrrrrslice.as_ref()); - foo_rslice(rrrrrslice); - foo_rstr(rrrrrstr.as_ref()); - foo_rstr(rrrrrstr); - } - { - let mrrrrrslice = &mut &mut &mut &mut mrslice; - foo_mrslice(mrrrrrslice.as_mut()); - foo_mrslice(mrrrrrslice); - foo_rslice(mrrrrrslice.as_ref()); - foo_rslice(mrrrrrslice); - } - #[allow(unused_parens, clippy::double_parens)] - foo_rrrrmr((&&&&MoreRef).as_ref()); - - generic_not_ok(mrslice); - generic_ok(mrslice); -} - -fn ok() { - let string = "hello".to_owned(); - let mut arr = [1, 2, 3]; - let mut vec = vec![1, 2, 3]; - - { - foo_rstr(string.as_ref()); - foo_rslice(arr.as_ref()); - foo_rslice(vec.as_ref()); - } - { - foo_mrslice(arr.as_mut()); - foo_mrslice(vec.as_mut()); - } - - { - let rrrrstring = &&&&string; - let rrrrarr = &&&&arr; - let rrrrvec = &&&&vec; - foo_rstr(rrrrstring.as_ref()); - foo_rslice(rrrrarr.as_ref()); - foo_rslice(rrrrvec.as_ref()); - } - { - let mrrrrarr = &mut &mut &mut &mut arr; - let mrrrrvec = &mut &mut &mut &mut vec; - foo_mrslice(mrrrrarr.as_mut()); - foo_mrslice(mrrrrvec.as_mut()); - } - FakeAsRef.as_ref(); - foo_rrrrmr(MoreRef.as_ref()); - - generic_not_ok(arr.as_mut()); - generic_ok(&mut arr); -} - -fn foo_mrt(t: &mut T) { - println!("{:?}", t); -} -fn foo_rt(t: &T) { - println!("{:?}", t); -} - -fn generic_not_ok + AsRef + Debug + ?Sized>(mrt: &mut T) { - foo_mrt(mrt.as_mut()); - foo_mrt(mrt); - foo_rt(mrt.as_ref()); - foo_rt(mrt); -} - -fn generic_ok + AsRef + ?Sized, T: Debug + ?Sized>(mru: &mut U) { - foo_mrt(mru.as_mut()); - foo_rt(mru.as_ref()); -} - -fn main() { - not_ok(); - ok(); -} diff --git a/tests/ui/useless_asref.stderr b/tests/ui/useless_asref.stderr deleted file mode 100644 index 5876b54aca8f..000000000000 --- a/tests/ui/useless_asref.stderr +++ /dev/null @@ -1,74 +0,0 @@ -error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:43:18 - | -LL | foo_rstr(rstr.as_ref()); - | ^^^^^^^^^^^^^ help: try this: `rstr` - | -note: the lint level is defined here - --> $DIR/useless_asref.rs:3:9 - | -LL | #![deny(clippy::useless_asref)] - | ^^^^^^^^^^^^^^^^^^^^^ - -error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:45:20 - | -LL | foo_rslice(rslice.as_ref()); - | ^^^^^^^^^^^^^^^ help: try this: `rslice` - -error: this call to `as_mut` does nothing - --> $DIR/useless_asref.rs:49:21 - | -LL | foo_mrslice(mrslice.as_mut()); - | ^^^^^^^^^^^^^^^^ help: try this: `mrslice` - -error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:51:20 - | -LL | foo_rslice(mrslice.as_ref()); - | ^^^^^^^^^^^^^^^^ help: try this: `mrslice` - -error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:58:20 - | -LL | foo_rslice(rrrrrslice.as_ref()); - | ^^^^^^^^^^^^^^^^^^^ help: try this: `rrrrrslice` - -error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:60:18 - | -LL | foo_rstr(rrrrrstr.as_ref()); - | ^^^^^^^^^^^^^^^^^ help: try this: `rrrrrstr` - -error: this call to `as_mut` does nothing - --> $DIR/useless_asref.rs:65:21 - | -LL | foo_mrslice(mrrrrrslice.as_mut()); - | ^^^^^^^^^^^^^^^^^^^^ help: try this: `mrrrrrslice` - -error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:67:20 - | -LL | foo_rslice(mrrrrrslice.as_ref()); - | ^^^^^^^^^^^^^^^^^^^^ help: try this: `mrrrrrslice` - -error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:71:16 - | -LL | foo_rrrrmr((&&&&MoreRef).as_ref()); - | ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `(&&&&MoreRef)` - -error: this call to `as_mut` does nothing - --> $DIR/useless_asref.rs:121:13 - | -LL | foo_mrt(mrt.as_mut()); - | ^^^^^^^^^^^^ help: try this: `mrt` - -error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:123:12 - | -LL | foo_rt(mrt.as_ref()); - | ^^^^^^^^^^^^ help: try this: `mrt` - -error: aborting due to 11 previous errors - diff --git a/tests/ui/useless_attribute.fixed b/tests/ui/useless_attribute.fixed deleted file mode 100644 index a5fcde768f18..000000000000 --- a/tests/ui/useless_attribute.fixed +++ /dev/null @@ -1,69 +0,0 @@ -// run-rustfix -// aux-build:proc_macro_derive.rs - -#![warn(clippy::useless_attribute)] -#![warn(unreachable_pub)] -#![feature(rustc_private)] - -#![allow(dead_code)] -#![cfg_attr(feature = "cargo-clippy", allow(dead_code))] -#[rustfmt::skip] -#[allow(unused_imports)] -#[allow(unused_extern_crates)] -#[macro_use] -extern crate rustc_middle; - -#[macro_use] -extern crate proc_macro_derive; - -// don't lint on unused_import for `use` items -#[allow(unused_imports)] -use std::collections; - -// don't lint on unused for `use` items -#[allow(unused)] -use std::option; - -// don't lint on deprecated for `use` items -mod foo { - #[deprecated] - pub struct Bar; -} -#[allow(deprecated)] -pub use foo::Bar; - -// This should not trigger the lint. There's lint level definitions inside the external derive -// that would trigger the useless_attribute lint. -#[derive(DeriveSomething)] -struct Baz; - -// don't lint on unreachable_pub for `use` items -mod a { - mod b { - #[allow(dead_code)] - #[allow(unreachable_pub)] - pub struct C {} - } - - #[allow(unreachable_pub)] - pub use self::b::C; -} - -// don't lint on clippy::wildcard_imports for `use` items -#[allow(clippy::wildcard_imports)] -pub use std::io::prelude::*; - -// don't lint on clippy::enum_glob_use for `use` items -#[allow(clippy::enum_glob_use)] -pub use std::cmp::Ordering::*; - -fn test_indented_attr() { - #![allow(clippy::almost_swapped)] - use std::collections::HashSet; - - let _ = HashSet::::default(); -} - -fn main() { - test_indented_attr(); -} diff --git a/tests/ui/useless_attribute.rs b/tests/ui/useless_attribute.rs deleted file mode 100644 index 0396d39e3d54..000000000000 --- a/tests/ui/useless_attribute.rs +++ /dev/null @@ -1,69 +0,0 @@ -// run-rustfix -// aux-build:proc_macro_derive.rs - -#![warn(clippy::useless_attribute)] -#![warn(unreachable_pub)] -#![feature(rustc_private)] - -#[allow(dead_code)] -#[cfg_attr(feature = "cargo-clippy", allow(dead_code))] -#[rustfmt::skip] -#[allow(unused_imports)] -#[allow(unused_extern_crates)] -#[macro_use] -extern crate rustc_middle; - -#[macro_use] -extern crate proc_macro_derive; - -// don't lint on unused_import for `use` items -#[allow(unused_imports)] -use std::collections; - -// don't lint on unused for `use` items -#[allow(unused)] -use std::option; - -// don't lint on deprecated for `use` items -mod foo { - #[deprecated] - pub struct Bar; -} -#[allow(deprecated)] -pub use foo::Bar; - -// This should not trigger the lint. There's lint level definitions inside the external derive -// that would trigger the useless_attribute lint. -#[derive(DeriveSomething)] -struct Baz; - -// don't lint on unreachable_pub for `use` items -mod a { - mod b { - #[allow(dead_code)] - #[allow(unreachable_pub)] - pub struct C {} - } - - #[allow(unreachable_pub)] - pub use self::b::C; -} - -// don't lint on clippy::wildcard_imports for `use` items -#[allow(clippy::wildcard_imports)] -pub use std::io::prelude::*; - -// don't lint on clippy::enum_glob_use for `use` items -#[allow(clippy::enum_glob_use)] -pub use std::cmp::Ordering::*; - -fn test_indented_attr() { - #[allow(clippy::almost_swapped)] - use std::collections::HashSet; - - let _ = HashSet::::default(); -} - -fn main() { - test_indented_attr(); -} diff --git a/tests/ui/useless_attribute.stderr b/tests/ui/useless_attribute.stderr deleted file mode 100644 index d0194e4bbbe5..000000000000 --- a/tests/ui/useless_attribute.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: useless lint attribute - --> $DIR/useless_attribute.rs:8:1 - | -LL | #[allow(dead_code)] - | ^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(dead_code)]` - | - = note: `-D clippy::useless-attribute` implied by `-D warnings` - -error: useless lint attribute - --> $DIR/useless_attribute.rs:9:1 - | -LL | #[cfg_attr(feature = "cargo-clippy", allow(dead_code))] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![cfg_attr(feature = "cargo-clippy", allow(dead_code)` - -error: useless lint attribute - --> $DIR/useless_attribute.rs:61:5 - | -LL | #[allow(clippy::almost_swapped)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(clippy::almost_swapped)]` - -error: aborting due to 3 previous errors - diff --git a/tests/ui/useless_conversion.fixed b/tests/ui/useless_conversion.fixed deleted file mode 100644 index 03977de9455e..000000000000 --- a/tests/ui/useless_conversion.fixed +++ /dev/null @@ -1,73 +0,0 @@ -// run-rustfix - -#![deny(clippy::useless_conversion)] -#![allow(clippy::unnecessary_wraps)] - -fn test_generic(val: T) -> T { - let _ = val; - val -} - -fn test_generic2 + Into, U: From>(val: T) { - // ok - let _: i32 = val.into(); - let _: U = val.into(); - let _ = U::from(val); -} - -fn test_questionmark() -> Result<(), ()> { - { - let _: i32 = 0i32; - Ok(Ok(())) - }??; - Ok(()) -} - -fn test_issue_3913() -> Result<(), std::io::Error> { - use std::fs; - use std::path::Path; - - let path = Path::new("."); - for _ in fs::read_dir(path)? {} - - Ok(()) -} - -fn test_issue_5833() -> Result<(), ()> { - let text = "foo\r\nbar\n\nbaz\n"; - let lines = text.lines(); - if Some("ok") == lines.into_iter().next() {} - - Ok(()) -} - -fn main() { - test_generic(10i32); - test_generic2::(10i32); - test_questionmark().unwrap(); - test_issue_3913().unwrap(); - test_issue_5833().unwrap(); - - let _: String = "foo".into(); - let _: String = From::from("foo"); - let _ = String::from("foo"); - #[allow(clippy::useless_conversion)] - { - let _: String = "foo".into(); - let _ = String::from("foo"); - let _ = "".lines().into_iter(); - } - - let _: String = "foo".to_string(); - let _: String = "foo".to_string(); - let _ = "foo".to_string(); - let _ = format!("A: {:04}", 123); - let _ = "".lines(); - let _ = vec![1, 2, 3].into_iter(); - let _: String = format!("Hello {}", "world"); - - // keep parenthesis around `a + b` for suggestion (see #4750) - let a: i32 = 1; - let b: i32 = 1; - let _ = (a + b) * 3; -} diff --git a/tests/ui/useless_conversion.rs b/tests/ui/useless_conversion.rs deleted file mode 100644 index f6e094c16616..000000000000 --- a/tests/ui/useless_conversion.rs +++ /dev/null @@ -1,73 +0,0 @@ -// run-rustfix - -#![deny(clippy::useless_conversion)] -#![allow(clippy::unnecessary_wraps)] - -fn test_generic(val: T) -> T { - let _ = T::from(val); - val.into() -} - -fn test_generic2 + Into, U: From>(val: T) { - // ok - let _: i32 = val.into(); - let _: U = val.into(); - let _ = U::from(val); -} - -fn test_questionmark() -> Result<(), ()> { - { - let _: i32 = 0i32.into(); - Ok(Ok(())) - }??; - Ok(()) -} - -fn test_issue_3913() -> Result<(), std::io::Error> { - use std::fs; - use std::path::Path; - - let path = Path::new("."); - for _ in fs::read_dir(path)? {} - - Ok(()) -} - -fn test_issue_5833() -> Result<(), ()> { - let text = "foo\r\nbar\n\nbaz\n"; - let lines = text.lines(); - if Some("ok") == lines.into_iter().next() {} - - Ok(()) -} - -fn main() { - test_generic(10i32); - test_generic2::(10i32); - test_questionmark().unwrap(); - test_issue_3913().unwrap(); - test_issue_5833().unwrap(); - - let _: String = "foo".into(); - let _: String = From::from("foo"); - let _ = String::from("foo"); - #[allow(clippy::useless_conversion)] - { - let _: String = "foo".into(); - let _ = String::from("foo"); - let _ = "".lines().into_iter(); - } - - let _: String = "foo".to_string().into(); - let _: String = From::from("foo".to_string()); - let _ = String::from("foo".to_string()); - let _ = String::from(format!("A: {:04}", 123)); - let _ = "".lines().into_iter(); - let _ = vec![1, 2, 3].into_iter().into_iter(); - let _: String = format!("Hello {}", "world").into(); - - // keep parenthesis around `a + b` for suggestion (see #4750) - let a: i32 = 1; - let b: i32 = 1; - let _ = i32::from(a + b) * 3; -} diff --git a/tests/ui/useless_conversion.stderr b/tests/ui/useless_conversion.stderr deleted file mode 100644 index 26a33595031b..000000000000 --- a/tests/ui/useless_conversion.stderr +++ /dev/null @@ -1,74 +0,0 @@ -error: useless conversion to the same type: `T` - --> $DIR/useless_conversion.rs:7:13 - | -LL | let _ = T::from(val); - | ^^^^^^^^^^^^ help: consider removing `T::from()`: `val` - | -note: the lint level is defined here - --> $DIR/useless_conversion.rs:3:9 - | -LL | #![deny(clippy::useless_conversion)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: useless conversion to the same type: `T` - --> $DIR/useless_conversion.rs:8:5 - | -LL | val.into() - | ^^^^^^^^^^ help: consider removing `.into()`: `val` - -error: useless conversion to the same type: `i32` - --> $DIR/useless_conversion.rs:20:22 - | -LL | let _: i32 = 0i32.into(); - | ^^^^^^^^^^^ help: consider removing `.into()`: `0i32` - -error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion.rs:61:21 - | -LL | let _: String = "foo".to_string().into(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `"foo".to_string()` - -error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion.rs:62:21 - | -LL | let _: String = From::from("foo".to_string()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `From::from()`: `"foo".to_string()` - -error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion.rs:63:13 - | -LL | let _ = String::from("foo".to_string()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `"foo".to_string()` - -error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion.rs:64:13 - | -LL | let _ = String::from(format!("A: {:04}", 123)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `format!("A: {:04}", 123)` - -error: useless conversion to the same type: `std::str::Lines` - --> $DIR/useless_conversion.rs:65:13 - | -LL | let _ = "".lines().into_iter(); - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `"".lines()` - -error: useless conversion to the same type: `std::vec::IntoIter` - --> $DIR/useless_conversion.rs:66:13 - | -LL | let _ = vec![1, 2, 3].into_iter().into_iter(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![1, 2, 3].into_iter()` - -error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion.rs:67:21 - | -LL | let _: String = format!("Hello {}", "world").into(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `format!("Hello {}", "world")` - -error: useless conversion to the same type: `i32` - --> $DIR/useless_conversion.rs:72:13 - | -LL | let _ = i32::from(a + b) * 3; - | ^^^^^^^^^^^^^^^^ help: consider removing `i32::from()`: `(a + b)` - -error: aborting due to 11 previous errors - diff --git a/tests/ui/useless_conversion_try.rs b/tests/ui/useless_conversion_try.rs deleted file mode 100644 index 3787ea991445..000000000000 --- a/tests/ui/useless_conversion_try.rs +++ /dev/null @@ -1,42 +0,0 @@ -#![deny(clippy::useless_conversion)] - -use std::convert::{TryFrom, TryInto}; - -fn test_generic(val: T) -> T { - let _ = T::try_from(val).unwrap(); - val.try_into().unwrap() -} - -fn test_generic2 + Into, U: From>(val: T) { - // ok - let _: i32 = val.try_into().unwrap(); - let _: U = val.try_into().unwrap(); - let _ = U::try_from(val).unwrap(); -} - -fn main() { - test_generic(10i32); - test_generic2::(10i32); - - let _: String = "foo".try_into().unwrap(); - let _: String = TryFrom::try_from("foo").unwrap(); - let _ = String::try_from("foo").unwrap(); - #[allow(clippy::useless_conversion)] - { - let _ = String::try_from("foo").unwrap(); - let _: String = "foo".try_into().unwrap(); - } - let _: String = "foo".to_string().try_into().unwrap(); - let _: String = TryFrom::try_from("foo".to_string()).unwrap(); - let _ = String::try_from("foo".to_string()).unwrap(); - let _ = String::try_from(format!("A: {:04}", 123)).unwrap(); - let _: String = format!("Hello {}", "world").try_into().unwrap(); - let _: String = "".to_owned().try_into().unwrap(); - let _: String = match String::from("_").try_into() { - Ok(a) => a, - Err(_) => "".into(), - }; - // FIXME this is a false negative - #[allow(clippy::cmp_owned)] - if String::from("a") == TryInto::::try_into(String::from("a")).unwrap() {} -} diff --git a/tests/ui/useless_conversion_try.stderr b/tests/ui/useless_conversion_try.stderr deleted file mode 100644 index 2e0d9129bfb3..000000000000 --- a/tests/ui/useless_conversion_try.stderr +++ /dev/null @@ -1,79 +0,0 @@ -error: useless conversion to the same type: `T` - --> $DIR/useless_conversion_try.rs:6:13 - | -LL | let _ = T::try_from(val).unwrap(); - | ^^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/useless_conversion_try.rs:1:9 - | -LL | #![deny(clippy::useless_conversion)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: consider removing `T::try_from()` - -error: useless conversion to the same type: `T` - --> $DIR/useless_conversion_try.rs:7:5 - | -LL | val.try_into().unwrap() - | ^^^^^^^^^^^^^^ - | - = help: consider removing `.try_into()` - -error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:29:21 - | -LL | let _: String = "foo".to_string().try_into().unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider removing `.try_into()` - -error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:30:21 - | -LL | let _: String = TryFrom::try_from("foo".to_string()).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider removing `TryFrom::try_from()` - -error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:31:13 - | -LL | let _ = String::try_from("foo".to_string()).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider removing `String::try_from()` - -error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:32:13 - | -LL | let _ = String::try_from(format!("A: {:04}", 123)).unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider removing `String::try_from()` - -error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:33:21 - | -LL | let _: String = format!("Hello {}", "world").try_into().unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider removing `.try_into()` - -error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:34:21 - | -LL | let _: String = "".to_owned().try_into().unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider removing `.try_into()` - -error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:35:27 - | -LL | let _: String = match String::from("_").try_into() { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider removing `.try_into()` - -error: aborting due to 9 previous errors - diff --git a/tests/ui/vec.fixed b/tests/ui/vec.fixed deleted file mode 100644 index 856771596202..000000000000 --- a/tests/ui/vec.fixed +++ /dev/null @@ -1,62 +0,0 @@ -// run-rustfix - -#![warn(clippy::useless_vec)] - -#[derive(Debug)] -struct NonCopy; - -fn on_slice(_: &[u8]) {} -#[allow(clippy::ptr_arg)] -fn on_vec(_: &Vec) {} - -struct Line { - length: usize, -} - -impl Line { - fn length(&self) -> usize { - self.length - } -} - -fn main() { - on_slice(&[]); - on_slice(&[]); - - on_slice(&[1, 2]); - on_slice(&[1, 2]); - - on_slice(&[1, 2]); - on_slice(&[1, 2]); - #[rustfmt::skip] - on_slice(&[1, 2]); - on_slice(&[1, 2]); - - on_slice(&[1; 2]); - on_slice(&[1; 2]); - - on_vec(&vec![]); - on_vec(&vec![1, 2]); - on_vec(&vec![1; 2]); - - // Now with non-constant expressions - let line = Line { length: 2 }; - - on_slice(&vec![2; line.length]); - on_slice(&vec![2; line.length()]); - - for a in &[1, 2, 3] { - println!("{:?}", a); - } - - for a in vec![NonCopy, NonCopy] { - println!("{:?}", a); - } - - on_vec(&vec![1; 201]); // Ok, size of `vec` higher than `too_large_for_stack` - - // Ok - for a in vec![1; 201] { - println!("{:?}", a); - } -} diff --git a/tests/ui/vec.rs b/tests/ui/vec.rs deleted file mode 100644 index 03b8ee816658..000000000000 --- a/tests/ui/vec.rs +++ /dev/null @@ -1,62 +0,0 @@ -// run-rustfix - -#![warn(clippy::useless_vec)] - -#[derive(Debug)] -struct NonCopy; - -fn on_slice(_: &[u8]) {} -#[allow(clippy::ptr_arg)] -fn on_vec(_: &Vec) {} - -struct Line { - length: usize, -} - -impl Line { - fn length(&self) -> usize { - self.length - } -} - -fn main() { - on_slice(&vec![]); - on_slice(&[]); - - on_slice(&vec![1, 2]); - on_slice(&[1, 2]); - - on_slice(&vec![1, 2]); - on_slice(&[1, 2]); - #[rustfmt::skip] - on_slice(&vec!(1, 2)); - on_slice(&[1, 2]); - - on_slice(&vec![1; 2]); - on_slice(&[1; 2]); - - on_vec(&vec![]); - on_vec(&vec![1, 2]); - on_vec(&vec![1; 2]); - - // Now with non-constant expressions - let line = Line { length: 2 }; - - on_slice(&vec![2; line.length]); - on_slice(&vec![2; line.length()]); - - for a in vec![1, 2, 3] { - println!("{:?}", a); - } - - for a in vec![NonCopy, NonCopy] { - println!("{:?}", a); - } - - on_vec(&vec![1; 201]); // Ok, size of `vec` higher than `too_large_for_stack` - - // Ok - for a in vec![1; 201] { - println!("{:?}", a); - } -} diff --git a/tests/ui/vec.stderr b/tests/ui/vec.stderr deleted file mode 100644 index 37e28ebddb55..000000000000 --- a/tests/ui/vec.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: useless use of `vec!` - --> $DIR/vec.rs:23:14 - | -LL | on_slice(&vec![]); - | ^^^^^^^ help: you can use a slice directly: `&[]` - | - = note: `-D clippy::useless-vec` implied by `-D warnings` - -error: useless use of `vec!` - --> $DIR/vec.rs:26:14 - | -LL | on_slice(&vec![1, 2]); - | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` - -error: useless use of `vec!` - --> $DIR/vec.rs:29:14 - | -LL | on_slice(&vec![1, 2]); - | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` - -error: useless use of `vec!` - --> $DIR/vec.rs:32:14 - | -LL | on_slice(&vec!(1, 2)); - | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` - -error: useless use of `vec!` - --> $DIR/vec.rs:35:14 - | -LL | on_slice(&vec![1; 2]); - | ^^^^^^^^^^^ help: you can use a slice directly: `&[1; 2]` - -error: useless use of `vec!` - --> $DIR/vec.rs:48:14 - | -LL | for a in vec![1, 2, 3] { - | ^^^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2, 3]` - -error: aborting due to 6 previous errors - diff --git a/tests/ui/vec_box_sized.fixed b/tests/ui/vec_box_sized.fixed deleted file mode 100644 index 4fa28b525c3c..000000000000 --- a/tests/ui/vec_box_sized.fixed +++ /dev/null @@ -1,52 +0,0 @@ -// run-rustfix - -#![allow(dead_code)] - -struct SizedStruct(i32); -struct UnsizedStruct([i32]); -struct BigStruct([i32; 10000]); - -/// The following should trigger the lint -mod should_trigger { - use super::SizedStruct; - - struct StructWithVecBox { - sized_type: Vec, - } - - struct A(Vec); - struct B(Vec>); -} - -/// The following should not trigger the lint -mod should_not_trigger { - use super::{BigStruct, UnsizedStruct}; - - struct C(Vec>); - struct D(Vec>); - - struct StructWithVecBoxButItsUnsized { - unsized_type: Vec>, - } - - struct TraitVec { - // Regression test for #3720. This was causing an ICE. - inner: Vec>, - } -} - -mod inner_mod { - mod inner { - pub struct S; - } - - mod inner2 { - use super::inner::S; - - pub fn f() -> Vec { - vec![] - } - } -} - -fn main() {} diff --git a/tests/ui/vec_box_sized.rs b/tests/ui/vec_box_sized.rs deleted file mode 100644 index 7dc735cd90be..000000000000 --- a/tests/ui/vec_box_sized.rs +++ /dev/null @@ -1,52 +0,0 @@ -// run-rustfix - -#![allow(dead_code)] - -struct SizedStruct(i32); -struct UnsizedStruct([i32]); -struct BigStruct([i32; 10000]); - -/// The following should trigger the lint -mod should_trigger { - use super::SizedStruct; - - struct StructWithVecBox { - sized_type: Vec>, - } - - struct A(Vec>); - struct B(Vec>>); -} - -/// The following should not trigger the lint -mod should_not_trigger { - use super::{BigStruct, UnsizedStruct}; - - struct C(Vec>); - struct D(Vec>); - - struct StructWithVecBoxButItsUnsized { - unsized_type: Vec>, - } - - struct TraitVec { - // Regression test for #3720. This was causing an ICE. - inner: Vec>, - } -} - -mod inner_mod { - mod inner { - pub struct S; - } - - mod inner2 { - use super::inner::S; - - pub fn f() -> Vec> { - vec![] - } - } -} - -fn main() {} diff --git a/tests/ui/vec_box_sized.stderr b/tests/ui/vec_box_sized.stderr deleted file mode 100644 index 57e2f1fdf9a7..000000000000 --- a/tests/ui/vec_box_sized.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: `Vec` is already on the heap, the boxing is unnecessary. - --> $DIR/vec_box_sized.rs:14:21 - | -LL | sized_type: Vec>, - | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec` - | - = note: `-D clippy::vec-box` implied by `-D warnings` - -error: `Vec` is already on the heap, the boxing is unnecessary. - --> $DIR/vec_box_sized.rs:17:14 - | -LL | struct A(Vec>); - | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec` - -error: `Vec` is already on the heap, the boxing is unnecessary. - --> $DIR/vec_box_sized.rs:18:18 - | -LL | struct B(Vec>>); - | ^^^^^^^^^^^^^^^ help: try: `Vec` - -error: `Vec` is already on the heap, the boxing is unnecessary. - --> $DIR/vec_box_sized.rs:46:23 - | -LL | pub fn f() -> Vec> { - | ^^^^^^^^^^^ help: try: `Vec` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/vec_resize_to_zero.rs b/tests/ui/vec_resize_to_zero.rs deleted file mode 100644 index 7ed27439ec6e..000000000000 --- a/tests/ui/vec_resize_to_zero.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![warn(clippy::vec_resize_to_zero)] - -fn main() { - // applicable here - vec![1, 2, 3, 4, 5].resize(0, 5); - - // not applicable - vec![1, 2, 3, 4, 5].resize(2, 5); - - // applicable here, but only implemented for integer literals for now - vec!["foo", "bar", "baz"].resize(0, "bar"); - - // not applicable - vec!["foo", "bar", "baz"].resize(2, "bar") -} diff --git a/tests/ui/vec_resize_to_zero.stderr b/tests/ui/vec_resize_to_zero.stderr deleted file mode 100644 index feb846298c65..000000000000 --- a/tests/ui/vec_resize_to_zero.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error: emptying a vector with `resize` - --> $DIR/vec_resize_to_zero.rs:5:5 - | -LL | vec![1, 2, 3, 4, 5].resize(0, 5); - | ^^^^^^^^^^^^^^^^^^^^------------ - | | - | help: ...or you can empty the vector with: `clear()` - | - = note: `-D clippy::vec-resize-to-zero` implied by `-D warnings` - = help: the arguments may be inverted... - -error: aborting due to previous error - diff --git a/tests/ui/verbose_file_reads.rs b/tests/ui/verbose_file_reads.rs deleted file mode 100644 index e0065e05ade6..000000000000 --- a/tests/ui/verbose_file_reads.rs +++ /dev/null @@ -1,28 +0,0 @@ -#![warn(clippy::verbose_file_reads)] -use std::env::temp_dir; -use std::fs::File; -use std::io::Read; - -struct Struct; -// To make sure we only warn on File::{read_to_end, read_to_string} calls -impl Struct { - pub fn read_to_end(&self) {} - - pub fn read_to_string(&self) {} -} - -fn main() -> std::io::Result<()> { - let path = "foo.txt"; - // Lint shouldn't catch this - let s = Struct; - s.read_to_end(); - s.read_to_string(); - // Should catch this - let mut f = File::open(&path)?; - let mut buffer = Vec::new(); - f.read_to_end(&mut buffer)?; - // ...and this - let mut string_buffer = String::new(); - f.read_to_string(&mut string_buffer)?; - Ok(()) -} diff --git a/tests/ui/verbose_file_reads.stderr b/tests/ui/verbose_file_reads.stderr deleted file mode 100644 index 550b6ab679f1..000000000000 --- a/tests/ui/verbose_file_reads.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: use of `File::read_to_end` - --> $DIR/verbose_file_reads.rs:23:5 - | -LL | f.read_to_end(&mut buffer)?; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::verbose-file-reads` implied by `-D warnings` - = help: consider using `fs::read` instead - -error: use of `File::read_to_string` - --> $DIR/verbose_file_reads.rs:26:5 - | -LL | f.read_to_string(&mut string_buffer)?; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using `fs::read_to_string` instead - -error: aborting due to 2 previous errors - diff --git a/tests/ui/vtable_address_comparisons.rs b/tests/ui/vtable_address_comparisons.rs deleted file mode 100644 index c91d96ee18a3..000000000000 --- a/tests/ui/vtable_address_comparisons.rs +++ /dev/null @@ -1,42 +0,0 @@ -use std::fmt::Debug; -use std::ptr; -use std::rc::Rc; -use std::sync::Arc; - -#[warn(clippy::vtable_address_comparisons)] -fn main() { - let a: *const dyn Debug = &1 as &dyn Debug; - let b: *const dyn Debug = &1 as &dyn Debug; - - // These should fail: - let _ = a == b; - let _ = a != b; - let _ = a < b; - let _ = a <= b; - let _ = a > b; - let _ = a >= b; - ptr::eq(a, b); - - let a = &1 as &dyn Debug; - let b = &1 as &dyn Debug; - ptr::eq(a, b); - - let a: Rc = Rc::new(1); - Rc::ptr_eq(&a, &a); - - let a: Arc = Arc::new(1); - Arc::ptr_eq(&a, &a); - - // These should be fine: - let a = &1; - ptr::eq(a, a); - - let a = Rc::new(1); - Rc::ptr_eq(&a, &a); - - let a = Arc::new(1); - Arc::ptr_eq(&a, &a); - - let a: &[u8] = b""; - ptr::eq(a, a); -} diff --git a/tests/ui/vtable_address_comparisons.stderr b/tests/ui/vtable_address_comparisons.stderr deleted file mode 100644 index 76bd57217d78..000000000000 --- a/tests/ui/vtable_address_comparisons.stderr +++ /dev/null @@ -1,83 +0,0 @@ -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:12:13 - | -LL | let _ = a == b; - | ^^^^^^ - | - = note: `-D clippy::vtable-address-comparisons` implied by `-D warnings` - = help: consider extracting and comparing data pointers only - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:13:13 - | -LL | let _ = a != b; - | ^^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:14:13 - | -LL | let _ = a < b; - | ^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:15:13 - | -LL | let _ = a <= b; - | ^^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:16:13 - | -LL | let _ = a > b; - | ^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:17:13 - | -LL | let _ = a >= b; - | ^^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:18:5 - | -LL | ptr::eq(a, b); - | ^^^^^^^^^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:22:5 - | -LL | ptr::eq(a, b); - | ^^^^^^^^^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:25:5 - | -LL | Rc::ptr_eq(&a, &a); - | ^^^^^^^^^^^^^^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:28:5 - | -LL | Arc::ptr_eq(&a, &a); - | ^^^^^^^^^^^^^^^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: aborting due to 10 previous errors - diff --git a/tests/ui/while_let_loop.rs b/tests/ui/while_let_loop.rs deleted file mode 100644 index 3ce699f551b2..000000000000 --- a/tests/ui/while_let_loop.rs +++ /dev/null @@ -1,119 +0,0 @@ -#![warn(clippy::while_let_loop)] - -fn main() { - let y = Some(true); - loop { - if let Some(_x) = y { - let _v = 1; - } else { - break; - } - } - - #[allow(clippy::never_loop)] - loop { - // no error, break is not in else clause - if let Some(_x) = y { - let _v = 1; - } - break; - } - - loop { - match y { - Some(_x) => true, - None => break, - }; - } - - loop { - let x = match y { - Some(x) => x, - None => break, - }; - let _x = x; - let _str = "foo"; - } - - loop { - let x = match y { - Some(x) => x, - None => break, - }; - { - let _a = "bar"; - }; - { - let _b = "foobar"; - } - } - - loop { - // no error, else branch does something other than break - match y { - Some(_x) => true, - _ => { - let _z = 1; - break; - }, - }; - } - - while let Some(x) = y { - // no error, obviously - println!("{}", x); - } - - // #675, this used to have a wrong suggestion - loop { - let (e, l) = match "".split_whitespace().next() { - Some(word) => (word.is_empty(), word.len()), - None => break, - }; - - let _ = (e, l); - } -} - -fn issue771() { - let mut a = 100; - let b = Some(true); - loop { - if a > 10 { - break; - } - - match b { - Some(_) => a = 0, - None => break, - } - } -} - -fn issue1017() { - let r: Result = Ok(42); - let mut len = 1337; - - loop { - match r { - Err(_) => len = 0, - Ok(length) => { - len = length; - break; - }, - } - } -} - -#[allow(clippy::never_loop)] -fn issue1948() { - // should not trigger clippy::while_let_loop lint because break passes an expression - let a = Some(10); - let b = loop { - if let Some(c) = a { - break Some(c); - } else { - break None; - } - }; -} diff --git a/tests/ui/while_let_loop.stderr b/tests/ui/while_let_loop.stderr deleted file mode 100644 index 13dd0ee224c1..000000000000 --- a/tests/ui/while_let_loop.stderr +++ /dev/null @@ -1,63 +0,0 @@ -error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:5:5 - | -LL | / loop { -LL | | if let Some(_x) = y { -LL | | let _v = 1; -LL | | } else { -LL | | break; -LL | | } -LL | | } - | |_____^ help: try: `while let Some(_x) = y { .. }` - | - = note: `-D clippy::while-let-loop` implied by `-D warnings` - -error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:22:5 - | -LL | / loop { -LL | | match y { -LL | | Some(_x) => true, -LL | | None => break, -LL | | }; -LL | | } - | |_____^ help: try: `while let Some(_x) = y { .. }` - -error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:29:5 - | -LL | / loop { -LL | | let x = match y { -LL | | Some(x) => x, -LL | | None => break, -... | -LL | | let _str = "foo"; -LL | | } - | |_____^ help: try: `while let Some(x) = y { .. }` - -error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:38:5 - | -LL | / loop { -LL | | let x = match y { -LL | | Some(x) => x, -LL | | None => break, -... | -LL | | } -LL | | } - | |_____^ help: try: `while let Some(x) = y { .. }` - -error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:68:5 - | -LL | / loop { -LL | | let (e, l) = match "".split_whitespace().next() { -LL | | Some(word) => (word.is_empty(), word.len()), -LL | | None => break, -... | -LL | | let _ = (e, l); -LL | | } - | |_____^ help: try: `while let Some(word) = "".split_whitespace().next() { .. }` - -error: aborting due to 5 previous errors - diff --git a/tests/ui/while_let_on_iterator.fixed b/tests/ui/while_let_on_iterator.fixed deleted file mode 100644 index e99c98ac79f2..000000000000 --- a/tests/ui/while_let_on_iterator.fixed +++ /dev/null @@ -1,218 +0,0 @@ -// run-rustfix - -#![warn(clippy::while_let_on_iterator)] -#![allow(clippy::never_loop, unreachable_code, unused_mut)] -#![feature(or_patterns)] - -fn base() { - let mut iter = 1..20; - for x in iter { - println!("{}", x); - } - - let mut iter = 1..20; - for x in iter { - println!("{}", x); - } - - let mut iter = 1..20; - for _ in iter {} - - let mut iter = 1..20; - while let None = iter.next() {} // this is fine (if nonsensical) - - let mut iter = 1..20; - if let Some(x) = iter.next() { - // also fine - println!("{}", x) - } - - // the following shouldn't warn because it can't be written with a for loop - let mut iter = 1u32..20; - while let Some(_) = iter.next() { - println!("next: {:?}", iter.next()) - } - - // neither can this - let mut iter = 1u32..20; - while let Some(_) = iter.next() { - println!("next: {:?}", iter.next()); - } - - // or this - let mut iter = 1u32..20; - while let Some(_) = iter.next() { - break; - } - println!("Remaining iter {:?}", iter); - - // or this - let mut iter = 1u32..20; - while let Some(_) = iter.next() { - iter = 1..20; - } -} - -// Issue #1188 -fn refutable() { - let a = [42, 1337]; - let mut b = a.iter(); - - // consume all the 42s - while let Some(&42) = b.next() {} - - let a = [(1, 2, 3)]; - let mut b = a.iter(); - - while let Some(&(1, 2, 3)) = b.next() {} - - let a = [Some(42)]; - let mut b = a.iter(); - - while let Some(&None) = b.next() {} - - /* This gives “refutable pattern in `for` loop binding: `&_` not covered” - for &42 in b {} - for &(1, 2, 3) in b {} - for &Option::None in b.next() {} - // */ -} - -fn refutable2() { - // Issue 3780 - { - let v = vec![1, 2, 3]; - let mut it = v.windows(2); - while let Some([x, y]) = it.next() { - println!("x: {}", x); - println!("y: {}", y); - } - - let mut it = v.windows(2); - while let Some([x, ..]) = it.next() { - println!("x: {}", x); - } - - let mut it = v.windows(2); - while let Some([.., y]) = it.next() { - println!("y: {}", y); - } - - let mut it = v.windows(2); - for [..] in it {} - - let v = vec![[1], [2], [3]]; - let mut it = v.iter(); - while let Some([1]) = it.next() {} - - let mut it = v.iter(); - for [_x] in it {} - } - - // binding - { - let v = vec![1, 2, 3]; - let mut it = v.iter(); - while let Some(x @ 1) = it.next() { - println!("{}", x); - } - - let v = vec![[1], [2], [3]]; - let mut it = v.iter(); - for x @ [_] in it { - println!("{:?}", x); - } - } - - // false negative - { - let v = vec![1, 2, 3]; - let mut it = v.iter().map(Some); - while let Some(Some(_) | None) = it.next() { - println!("1"); - } - } -} - -fn nested_loops() { - let a = [42, 1337]; - let mut y = a.iter(); - loop { - // x is reused, so don't lint here - while let Some(_) = y.next() {} - } - - let mut y = a.iter(); - for _ in 0..2 { - while let Some(_) = y.next() { - // y is reused, don't lint - } - } - - loop { - let mut y = a.iter(); - for _ in y { - // use a for loop here - } - } -} - -fn issue1121() { - use std::collections::HashSet; - let mut values = HashSet::new(); - values.insert(1); - - while let Some(&value) = values.iter().next() { - values.remove(&value); - } -} - -fn issue2965() { - // This should not cause an ICE and suggest: - // - // for _ in values.iter() {} - // - use std::collections::HashSet; - let mut values = HashSet::new(); - values.insert(1); - - while let Some(..) = values.iter().next() {} -} - -fn issue3670() { - let array = [Some(0), None, Some(1)]; - let mut iter = array.iter(); - - while let Some(elem) = iter.next() { - let _ = elem.or_else(|| *iter.next()?); - } -} - -fn issue1654() { - // should not lint if the iterator is generated on every iteration - use std::collections::HashSet; - let mut values = HashSet::new(); - values.insert(1); - - while let Some(..) = values.iter().next() { - values.remove(&1); - } - - while let Some(..) = values.iter().map(|x| x + 1).next() {} - - let chars = "Hello, World!".char_indices(); - while let Some((i, ch)) = chars.clone().next() { - println!("{}: {}", i, ch); - } -} - -fn main() { - base(); - refutable(); - refutable2(); - nested_loops(); - issue1121(); - issue2965(); - issue3670(); - issue1654(); -} diff --git a/tests/ui/while_let_on_iterator.rs b/tests/ui/while_let_on_iterator.rs deleted file mode 100644 index ba13172428e1..000000000000 --- a/tests/ui/while_let_on_iterator.rs +++ /dev/null @@ -1,218 +0,0 @@ -// run-rustfix - -#![warn(clippy::while_let_on_iterator)] -#![allow(clippy::never_loop, unreachable_code, unused_mut)] -#![feature(or_patterns)] - -fn base() { - let mut iter = 1..20; - while let Option::Some(x) = iter.next() { - println!("{}", x); - } - - let mut iter = 1..20; - while let Some(x) = iter.next() { - println!("{}", x); - } - - let mut iter = 1..20; - while let Some(_) = iter.next() {} - - let mut iter = 1..20; - while let None = iter.next() {} // this is fine (if nonsensical) - - let mut iter = 1..20; - if let Some(x) = iter.next() { - // also fine - println!("{}", x) - } - - // the following shouldn't warn because it can't be written with a for loop - let mut iter = 1u32..20; - while let Some(_) = iter.next() { - println!("next: {:?}", iter.next()) - } - - // neither can this - let mut iter = 1u32..20; - while let Some(_) = iter.next() { - println!("next: {:?}", iter.next()); - } - - // or this - let mut iter = 1u32..20; - while let Some(_) = iter.next() { - break; - } - println!("Remaining iter {:?}", iter); - - // or this - let mut iter = 1u32..20; - while let Some(_) = iter.next() { - iter = 1..20; - } -} - -// Issue #1188 -fn refutable() { - let a = [42, 1337]; - let mut b = a.iter(); - - // consume all the 42s - while let Some(&42) = b.next() {} - - let a = [(1, 2, 3)]; - let mut b = a.iter(); - - while let Some(&(1, 2, 3)) = b.next() {} - - let a = [Some(42)]; - let mut b = a.iter(); - - while let Some(&None) = b.next() {} - - /* This gives “refutable pattern in `for` loop binding: `&_` not covered” - for &42 in b {} - for &(1, 2, 3) in b {} - for &Option::None in b.next() {} - // */ -} - -fn refutable2() { - // Issue 3780 - { - let v = vec![1, 2, 3]; - let mut it = v.windows(2); - while let Some([x, y]) = it.next() { - println!("x: {}", x); - println!("y: {}", y); - } - - let mut it = v.windows(2); - while let Some([x, ..]) = it.next() { - println!("x: {}", x); - } - - let mut it = v.windows(2); - while let Some([.., y]) = it.next() { - println!("y: {}", y); - } - - let mut it = v.windows(2); - while let Some([..]) = it.next() {} - - let v = vec![[1], [2], [3]]; - let mut it = v.iter(); - while let Some([1]) = it.next() {} - - let mut it = v.iter(); - while let Some([_x]) = it.next() {} - } - - // binding - { - let v = vec![1, 2, 3]; - let mut it = v.iter(); - while let Some(x @ 1) = it.next() { - println!("{}", x); - } - - let v = vec![[1], [2], [3]]; - let mut it = v.iter(); - while let Some(x @ [_]) = it.next() { - println!("{:?}", x); - } - } - - // false negative - { - let v = vec![1, 2, 3]; - let mut it = v.iter().map(Some); - while let Some(Some(_) | None) = it.next() { - println!("1"); - } - } -} - -fn nested_loops() { - let a = [42, 1337]; - let mut y = a.iter(); - loop { - // x is reused, so don't lint here - while let Some(_) = y.next() {} - } - - let mut y = a.iter(); - for _ in 0..2 { - while let Some(_) = y.next() { - // y is reused, don't lint - } - } - - loop { - let mut y = a.iter(); - while let Some(_) = y.next() { - // use a for loop here - } - } -} - -fn issue1121() { - use std::collections::HashSet; - let mut values = HashSet::new(); - values.insert(1); - - while let Some(&value) = values.iter().next() { - values.remove(&value); - } -} - -fn issue2965() { - // This should not cause an ICE and suggest: - // - // for _ in values.iter() {} - // - use std::collections::HashSet; - let mut values = HashSet::new(); - values.insert(1); - - while let Some(..) = values.iter().next() {} -} - -fn issue3670() { - let array = [Some(0), None, Some(1)]; - let mut iter = array.iter(); - - while let Some(elem) = iter.next() { - let _ = elem.or_else(|| *iter.next()?); - } -} - -fn issue1654() { - // should not lint if the iterator is generated on every iteration - use std::collections::HashSet; - let mut values = HashSet::new(); - values.insert(1); - - while let Some(..) = values.iter().next() { - values.remove(&1); - } - - while let Some(..) = values.iter().map(|x| x + 1).next() {} - - let chars = "Hello, World!".char_indices(); - while let Some((i, ch)) = chars.clone().next() { - println!("{}: {}", i, ch); - } -} - -fn main() { - base(); - refutable(); - refutable2(); - nested_loops(); - issue1121(); - issue2965(); - issue3670(); - issue1654(); -} diff --git a/tests/ui/while_let_on_iterator.stderr b/tests/ui/while_let_on_iterator.stderr deleted file mode 100644 index aa980d9965c7..000000000000 --- a/tests/ui/while_let_on_iterator.stderr +++ /dev/null @@ -1,46 +0,0 @@ -error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:9:5 - | -LL | while let Option::Some(x) = iter.next() { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter` - | - = note: `-D clippy::while-let-on-iterator` implied by `-D warnings` - -error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:14:5 - | -LL | while let Some(x) = iter.next() { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter` - -error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:19:5 - | -LL | while let Some(_) = iter.next() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in iter` - -error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:102:9 - | -LL | while let Some([..]) = it.next() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for [..] in it` - -error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:109:9 - | -LL | while let Some([_x]) = it.next() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for [_x] in it` - -error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:122:9 - | -LL | while let Some(x @ [_]) = it.next() { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x @ [_] in it` - -error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:154:9 - | -LL | while let Some(_) = y.next() { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in y` - -error: aborting due to 7 previous errors - diff --git a/tests/ui/wild_in_or_pats.rs b/tests/ui/wild_in_or_pats.rs deleted file mode 100644 index ad600f125772..000000000000 --- a/tests/ui/wild_in_or_pats.rs +++ /dev/null @@ -1,36 +0,0 @@ -#![warn(clippy::wildcard_in_or_patterns)] - -fn main() { - match "foo" { - "a" => { - dbg!("matched a"); - }, - "bar" | _ => { - dbg!("matched (bar or) wild"); - }, - }; - match "foo" { - "a" => { - dbg!("matched a"); - }, - "bar" | "bar2" | _ => { - dbg!("matched (bar or bar2 or) wild"); - }, - }; - match "foo" { - "a" => { - dbg!("matched a"); - }, - _ | "bar" | _ => { - dbg!("matched (bar or) wild"); - }, - }; - match "foo" { - "a" => { - dbg!("matched a"); - }, - _ | "bar" => { - dbg!("matched (bar or) wild"); - }, - }; -} diff --git a/tests/ui/wild_in_or_pats.stderr b/tests/ui/wild_in_or_pats.stderr deleted file mode 100644 index 33c34cbbd408..000000000000 --- a/tests/ui/wild_in_or_pats.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error: wildcard pattern covers any other pattern as it will match anyway. - --> $DIR/wild_in_or_pats.rs:8:9 - | -LL | "bar" | _ => { - | ^^^^^^^^^ - | - = note: `-D clippy::wildcard-in-or-patterns` implied by `-D warnings` - = help: Consider handling `_` separately. - -error: wildcard pattern covers any other pattern as it will match anyway. - --> $DIR/wild_in_or_pats.rs:16:9 - | -LL | "bar" | "bar2" | _ => { - | ^^^^^^^^^^^^^^^^^^ - | - = help: Consider handling `_` separately. - -error: wildcard pattern covers any other pattern as it will match anyway. - --> $DIR/wild_in_or_pats.rs:24:9 - | -LL | _ | "bar" | _ => { - | ^^^^^^^^^^^^^ - | - = help: Consider handling `_` separately. - -error: wildcard pattern covers any other pattern as it will match anyway. - --> $DIR/wild_in_or_pats.rs:32:9 - | -LL | _ | "bar" => { - | ^^^^^^^^^ - | - = help: Consider handling `_` separately. - -error: aborting due to 4 previous errors - diff --git a/tests/ui/wildcard_enum_match_arm.fixed b/tests/ui/wildcard_enum_match_arm.fixed deleted file mode 100644 index c266f684a36f..000000000000 --- a/tests/ui/wildcard_enum_match_arm.fixed +++ /dev/null @@ -1,103 +0,0 @@ -// run-rustfix - -#![deny(clippy::wildcard_enum_match_arm)] -#![allow( - unreachable_code, - unused_variables, - dead_code, - clippy::single_match, - clippy::wildcard_in_or_patterns, - clippy::unnested_or_patterns, - clippy::diverging_sub_expression -)] - -use std::io::ErrorKind; - -#[derive(Clone, Copy, Debug, Eq, PartialEq)] -enum Color { - Red, - Green, - Blue, - Rgb(u8, u8, u8), - Cyan, -} - -impl Color { - fn is_monochrome(self) -> bool { - match self { - Color::Red | Color::Green | Color::Blue => true, - Color::Rgb(r, g, b) => r | g == 0 || r | b == 0 || g | b == 0, - Color::Cyan => false, - } - } -} - -fn main() { - let color = Color::Rgb(0, 0, 127); - match color { - Color::Red => println!("Red"), - Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan => eprintln!("Not red"), - }; - match color { - Color::Red => println!("Red"), - _not_red @ Color::Green | _not_red @ Color::Blue | _not_red @ Color::Rgb(..) | _not_red @ Color::Cyan => eprintln!("Not red"), - }; - let _str = match color { - Color::Red => "Red".to_owned(), - not_red @ Color::Green | not_red @ Color::Blue | not_red @ Color::Rgb(..) | not_red @ Color::Cyan => format!("{:?}", not_red), - }; - match color { - Color::Red => {}, - Color::Green => {}, - Color::Blue => {}, - Color::Cyan => {}, - c if c.is_monochrome() => {}, - Color::Rgb(_, _, _) => {}, - }; - let _str = match color { - Color::Red => "Red", - c @ Color::Green | c @ Color::Blue | c @ Color::Rgb(_, _, _) | c @ Color::Cyan => "Not red", - }; - match color { - Color::Rgb(r, _, _) if r > 0 => "Some red", - Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan => "No red", - }; - match color { - Color::Red | Color::Green | Color::Blue | Color::Cyan => {}, - Color::Rgb(..) => {}, - }; - let x: u8 = unimplemented!(); - match x { - 0 => {}, - 140 => {}, - _ => {}, - }; - // We need to use an enum not defined in this test because non_exhaustive is ignored for the - // purposes of dead code analysis within a crate. - let error_kind = ErrorKind::NotFound; - match error_kind { - ErrorKind::NotFound => {}, - std::io::ErrorKind::PermissionDenied | std::io::ErrorKind::ConnectionRefused | std::io::ErrorKind::ConnectionReset | std::io::ErrorKind::ConnectionAborted | std::io::ErrorKind::NotConnected | std::io::ErrorKind::AddrInUse | std::io::ErrorKind::AddrNotAvailable | std::io::ErrorKind::BrokenPipe | std::io::ErrorKind::AlreadyExists | std::io::ErrorKind::WouldBlock | std::io::ErrorKind::InvalidInput | std::io::ErrorKind::InvalidData | std::io::ErrorKind::TimedOut | std::io::ErrorKind::WriteZero | std::io::ErrorKind::Interrupted | std::io::ErrorKind::Other | std::io::ErrorKind::UnexpectedEof | _ => {}, - } - match error_kind { - ErrorKind::NotFound => {}, - ErrorKind::PermissionDenied => {}, - ErrorKind::ConnectionRefused => {}, - ErrorKind::ConnectionReset => {}, - ErrorKind::ConnectionAborted => {}, - ErrorKind::NotConnected => {}, - ErrorKind::AddrInUse => {}, - ErrorKind::AddrNotAvailable => {}, - ErrorKind::BrokenPipe => {}, - ErrorKind::AlreadyExists => {}, - ErrorKind::WouldBlock => {}, - ErrorKind::InvalidInput => {}, - ErrorKind::InvalidData => {}, - ErrorKind::TimedOut => {}, - ErrorKind::WriteZero => {}, - ErrorKind::Interrupted => {}, - ErrorKind::Other => {}, - ErrorKind::UnexpectedEof => {}, - _ => {}, - } -} diff --git a/tests/ui/wildcard_enum_match_arm.rs b/tests/ui/wildcard_enum_match_arm.rs deleted file mode 100644 index 2dbf726d5d07..000000000000 --- a/tests/ui/wildcard_enum_match_arm.rs +++ /dev/null @@ -1,103 +0,0 @@ -// run-rustfix - -#![deny(clippy::wildcard_enum_match_arm)] -#![allow( - unreachable_code, - unused_variables, - dead_code, - clippy::single_match, - clippy::wildcard_in_or_patterns, - clippy::unnested_or_patterns, - clippy::diverging_sub_expression -)] - -use std::io::ErrorKind; - -#[derive(Clone, Copy, Debug, Eq, PartialEq)] -enum Color { - Red, - Green, - Blue, - Rgb(u8, u8, u8), - Cyan, -} - -impl Color { - fn is_monochrome(self) -> bool { - match self { - Color::Red | Color::Green | Color::Blue => true, - Color::Rgb(r, g, b) => r | g == 0 || r | b == 0 || g | b == 0, - Color::Cyan => false, - } - } -} - -fn main() { - let color = Color::Rgb(0, 0, 127); - match color { - Color::Red => println!("Red"), - _ => eprintln!("Not red"), - }; - match color { - Color::Red => println!("Red"), - _not_red => eprintln!("Not red"), - }; - let _str = match color { - Color::Red => "Red".to_owned(), - not_red => format!("{:?}", not_red), - }; - match color { - Color::Red => {}, - Color::Green => {}, - Color::Blue => {}, - Color::Cyan => {}, - c if c.is_monochrome() => {}, - Color::Rgb(_, _, _) => {}, - }; - let _str = match color { - Color::Red => "Red", - c @ Color::Green | c @ Color::Blue | c @ Color::Rgb(_, _, _) | c @ Color::Cyan => "Not red", - }; - match color { - Color::Rgb(r, _, _) if r > 0 => "Some red", - _ => "No red", - }; - match color { - Color::Red | Color::Green | Color::Blue | Color::Cyan => {}, - Color::Rgb(..) => {}, - }; - let x: u8 = unimplemented!(); - match x { - 0 => {}, - 140 => {}, - _ => {}, - }; - // We need to use an enum not defined in this test because non_exhaustive is ignored for the - // purposes of dead code analysis within a crate. - let error_kind = ErrorKind::NotFound; - match error_kind { - ErrorKind::NotFound => {}, - _ => {}, - } - match error_kind { - ErrorKind::NotFound => {}, - ErrorKind::PermissionDenied => {}, - ErrorKind::ConnectionRefused => {}, - ErrorKind::ConnectionReset => {}, - ErrorKind::ConnectionAborted => {}, - ErrorKind::NotConnected => {}, - ErrorKind::AddrInUse => {}, - ErrorKind::AddrNotAvailable => {}, - ErrorKind::BrokenPipe => {}, - ErrorKind::AlreadyExists => {}, - ErrorKind::WouldBlock => {}, - ErrorKind::InvalidInput => {}, - ErrorKind::InvalidData => {}, - ErrorKind::TimedOut => {}, - ErrorKind::WriteZero => {}, - ErrorKind::Interrupted => {}, - ErrorKind::Other => {}, - ErrorKind::UnexpectedEof => {}, - _ => {}, - } -} diff --git a/tests/ui/wildcard_enum_match_arm.stderr b/tests/ui/wildcard_enum_match_arm.stderr deleted file mode 100644 index 0da2b68ba0b2..000000000000 --- a/tests/ui/wildcard_enum_match_arm.stderr +++ /dev/null @@ -1,38 +0,0 @@ -error: wildcard match will miss any future added variants - --> $DIR/wildcard_enum_match_arm.rs:39:9 - | -LL | _ => eprintln!("Not red"), - | ^ help: try this: `Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan` - | -note: the lint level is defined here - --> $DIR/wildcard_enum_match_arm.rs:3:9 - | -LL | #![deny(clippy::wildcard_enum_match_arm)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: wildcard match will miss any future added variants - --> $DIR/wildcard_enum_match_arm.rs:43:9 - | -LL | _not_red => eprintln!("Not red"), - | ^^^^^^^^ help: try this: `_not_red @ Color::Green | _not_red @ Color::Blue | _not_red @ Color::Rgb(..) | _not_red @ Color::Cyan` - -error: wildcard match will miss any future added variants - --> $DIR/wildcard_enum_match_arm.rs:47:9 - | -LL | not_red => format!("{:?}", not_red), - | ^^^^^^^ help: try this: `not_red @ Color::Green | not_red @ Color::Blue | not_red @ Color::Rgb(..) | not_red @ Color::Cyan` - -error: wildcard match will miss any future added variants - --> $DIR/wildcard_enum_match_arm.rs:63:9 - | -LL | _ => "No red", - | ^ help: try this: `Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan` - -error: match on non-exhaustive enum doesn't explicitly match all known variants - --> $DIR/wildcard_enum_match_arm.rs:80:9 - | -LL | _ => {}, - | ^ help: try this: `std::io::ErrorKind::PermissionDenied | std::io::ErrorKind::ConnectionRefused | std::io::ErrorKind::ConnectionReset | std::io::ErrorKind::ConnectionAborted | std::io::ErrorKind::NotConnected | std::io::ErrorKind::AddrInUse | std::io::ErrorKind::AddrNotAvailable | std::io::ErrorKind::BrokenPipe | std::io::ErrorKind::AlreadyExists | std::io::ErrorKind::WouldBlock | std::io::ErrorKind::InvalidInput | std::io::ErrorKind::InvalidData | std::io::ErrorKind::TimedOut | std::io::ErrorKind::WriteZero | std::io::ErrorKind::Interrupted | std::io::ErrorKind::Other | std::io::ErrorKind::UnexpectedEof | _` - -error: aborting due to 5 previous errors - diff --git a/tests/ui/wildcard_imports.fixed b/tests/ui/wildcard_imports.fixed deleted file mode 100644 index ee9c9045fff5..000000000000 --- a/tests/ui/wildcard_imports.fixed +++ /dev/null @@ -1,233 +0,0 @@ -// run-rustfix -// aux-build:wildcard_imports_helper.rs - -#![warn(clippy::wildcard_imports)] -//#![allow(clippy::redundant_pub_crate)] -#![allow(unused)] -#![allow(clippy::unnecessary_wraps)] -#![warn(unused_imports)] - -extern crate wildcard_imports_helper; - -use crate::fn_mod::foo; -use crate::mod_mod::inner_mod; -use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}; -#[macro_use] -use crate::struct_mod::{A, inner_struct_mod}; - -#[allow(unused_imports)] -use wildcard_imports_helper::inner::inner_for_self_import; -use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar; -use wildcard_imports_helper::{ExternA, extern_foo}; - -use std::io::prelude::*; -use wildcard_imports_helper::prelude::v1::*; - -struct ReadFoo; - -impl Read for ReadFoo { - fn read(&mut self, _buf: &mut [u8]) -> std::io::Result { - Ok(0) - } -} - -mod fn_mod { - pub fn foo() {} -} - -mod mod_mod { - pub mod inner_mod { - pub fn foo() {} - } -} - -mod multi_fn_mod { - pub fn multi_foo() {} - pub fn multi_bar() {} - pub fn multi_baz() {} - pub mod multi_inner_mod { - pub fn foo() {} - } -} - -mod struct_mod { - pub struct A; - pub struct B; - pub mod inner_struct_mod { - pub struct C; - } - - #[macro_export] - macro_rules! double_struct_import_test { - () => { - let _ = A; - }; - } -} - -fn main() { - foo(); - multi_foo(); - multi_bar(); - multi_inner_mod::foo(); - inner_mod::foo(); - extern_foo(); - inner_extern_bar(); - - let _ = A; - let _ = inner_struct_mod::C; - let _ = ExternA; - let _ = PreludeModAnywhere; - - double_struct_import_test!(); - double_struct_import_test!(); -} - -mod in_fn_test { - pub use self::inner_exported::*; - #[allow(unused_imports)] - pub(crate) use self::inner_exported2::*; - - fn test_intern() { - use crate::fn_mod::foo; - - foo(); - } - - fn test_extern() { - use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo}; - use wildcard_imports_helper::{ExternA, extern_foo}; - - inner_for_self_import::inner_extern_foo(); - inner_extern_foo(); - - extern_foo(); - - let _ = ExternA; - } - - fn test_inner_nested() { - use self::{inner::inner_foo, inner2::inner_bar}; - - inner_foo(); - inner_bar(); - } - - fn test_extern_reexported() { - use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}; - - extern_exported(); - let _ = ExternExportedStruct; - let _ = ExternExportedEnum::A; - } - - mod inner_exported { - pub fn exported() {} - pub struct ExportedStruct; - pub enum ExportedEnum { - A, - } - } - - mod inner_exported2 { - pub(crate) fn exported2() {} - } - - mod inner { - pub fn inner_foo() {} - } - - mod inner2 { - pub fn inner_bar() {} - } -} - -fn test_reexported() { - use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}; - - exported(); - let _ = ExportedStruct; - let _ = ExportedEnum::A; -} - -#[rustfmt::skip] -fn test_weird_formatting() { - use crate:: in_fn_test::exported; - use crate:: fn_mod::foo; - - exported(); - foo(); -} - -mod super_imports { - fn foofoo() {} - - mod should_be_replaced { - use super::foofoo; - - fn with_super() { - let _ = foofoo(); - } - } - - mod test_should_pass { - use super::*; - - fn with_super() { - let _ = foofoo(); - } - } - - mod test_should_pass_inside_function { - fn with_super_inside_function() { - use super::*; - let _ = foofoo(); - } - } - - mod test_should_pass_further_inside { - fn insidefoo() {} - mod inner { - use super::*; - fn with_super() { - let _ = insidefoo(); - } - } - } - - mod should_be_replaced_futher_inside { - fn insidefoo() {} - mod inner { - use super::insidefoo; - fn with_super() { - let _ = insidefoo(); - } - } - } - - mod use_explicit_should_be_replaced { - use super_imports::foofoo; - - fn with_explicit() { - let _ = foofoo(); - } - } - - mod use_double_super_should_be_replaced { - mod inner { - use super::super::foofoo; - - fn with_double_super() { - let _ = foofoo(); - } - } - } - - mod use_super_explicit_should_be_replaced { - use super::super::super_imports::foofoo; - - fn with_super_explicit() { - let _ = foofoo(); - } - } -} diff --git a/tests/ui/wildcard_imports.rs b/tests/ui/wildcard_imports.rs deleted file mode 100644 index efaa8f9ef664..000000000000 --- a/tests/ui/wildcard_imports.rs +++ /dev/null @@ -1,234 +0,0 @@ -// run-rustfix -// aux-build:wildcard_imports_helper.rs - -#![warn(clippy::wildcard_imports)] -//#![allow(clippy::redundant_pub_crate)] -#![allow(unused)] -#![allow(clippy::unnecessary_wraps)] -#![warn(unused_imports)] - -extern crate wildcard_imports_helper; - -use crate::fn_mod::*; -use crate::mod_mod::*; -use crate::multi_fn_mod::*; -#[macro_use] -use crate::struct_mod::*; - -#[allow(unused_imports)] -use wildcard_imports_helper::inner::inner_for_self_import; -use wildcard_imports_helper::inner::inner_for_self_import::*; -use wildcard_imports_helper::*; - -use std::io::prelude::*; -use wildcard_imports_helper::prelude::v1::*; - -struct ReadFoo; - -impl Read for ReadFoo { - fn read(&mut self, _buf: &mut [u8]) -> std::io::Result { - Ok(0) - } -} - -mod fn_mod { - pub fn foo() {} -} - -mod mod_mod { - pub mod inner_mod { - pub fn foo() {} - } -} - -mod multi_fn_mod { - pub fn multi_foo() {} - pub fn multi_bar() {} - pub fn multi_baz() {} - pub mod multi_inner_mod { - pub fn foo() {} - } -} - -mod struct_mod { - pub struct A; - pub struct B; - pub mod inner_struct_mod { - pub struct C; - } - - #[macro_export] - macro_rules! double_struct_import_test { - () => { - let _ = A; - }; - } -} - -fn main() { - foo(); - multi_foo(); - multi_bar(); - multi_inner_mod::foo(); - inner_mod::foo(); - extern_foo(); - inner_extern_bar(); - - let _ = A; - let _ = inner_struct_mod::C; - let _ = ExternA; - let _ = PreludeModAnywhere; - - double_struct_import_test!(); - double_struct_import_test!(); -} - -mod in_fn_test { - pub use self::inner_exported::*; - #[allow(unused_imports)] - pub(crate) use self::inner_exported2::*; - - fn test_intern() { - use crate::fn_mod::*; - - foo(); - } - - fn test_extern() { - use wildcard_imports_helper::inner::inner_for_self_import::{self, *}; - use wildcard_imports_helper::*; - - inner_for_self_import::inner_extern_foo(); - inner_extern_foo(); - - extern_foo(); - - let _ = ExternA; - } - - fn test_inner_nested() { - use self::{inner::*, inner2::*}; - - inner_foo(); - inner_bar(); - } - - fn test_extern_reexported() { - use wildcard_imports_helper::*; - - extern_exported(); - let _ = ExternExportedStruct; - let _ = ExternExportedEnum::A; - } - - mod inner_exported { - pub fn exported() {} - pub struct ExportedStruct; - pub enum ExportedEnum { - A, - } - } - - mod inner_exported2 { - pub(crate) fn exported2() {} - } - - mod inner { - pub fn inner_foo() {} - } - - mod inner2 { - pub fn inner_bar() {} - } -} - -fn test_reexported() { - use crate::in_fn_test::*; - - exported(); - let _ = ExportedStruct; - let _ = ExportedEnum::A; -} - -#[rustfmt::skip] -fn test_weird_formatting() { - use crate:: in_fn_test:: * ; - use crate:: fn_mod:: - *; - - exported(); - foo(); -} - -mod super_imports { - fn foofoo() {} - - mod should_be_replaced { - use super::*; - - fn with_super() { - let _ = foofoo(); - } - } - - mod test_should_pass { - use super::*; - - fn with_super() { - let _ = foofoo(); - } - } - - mod test_should_pass_inside_function { - fn with_super_inside_function() { - use super::*; - let _ = foofoo(); - } - } - - mod test_should_pass_further_inside { - fn insidefoo() {} - mod inner { - use super::*; - fn with_super() { - let _ = insidefoo(); - } - } - } - - mod should_be_replaced_futher_inside { - fn insidefoo() {} - mod inner { - use super::*; - fn with_super() { - let _ = insidefoo(); - } - } - } - - mod use_explicit_should_be_replaced { - use super_imports::*; - - fn with_explicit() { - let _ = foofoo(); - } - } - - mod use_double_super_should_be_replaced { - mod inner { - use super::super::*; - - fn with_double_super() { - let _ = foofoo(); - } - } - } - - mod use_super_explicit_should_be_replaced { - use super::super::super_imports::*; - - fn with_super_explicit() { - let _ = foofoo(); - } - } -} diff --git a/tests/ui/wildcard_imports.stderr b/tests/ui/wildcard_imports.stderr deleted file mode 100644 index 66267dd27b84..000000000000 --- a/tests/ui/wildcard_imports.stderr +++ /dev/null @@ -1,126 +0,0 @@ -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:12:5 - | -LL | use crate::fn_mod::*; - | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` - | - = note: `-D clippy::wildcard-imports` implied by `-D warnings` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:13:5 - | -LL | use crate::mod_mod::*; - | ^^^^^^^^^^^^^^^^^ help: try: `crate::mod_mod::inner_mod` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:14:5 - | -LL | use crate::multi_fn_mod::*; - | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:16:5 - | -LL | use crate::struct_mod::*; - | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::struct_mod::{A, inner_struct_mod}` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:20:5 - | -LL | use wildcard_imports_helper::inner::inner_for_self_import::*; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:21:5 - | -LL | use wildcard_imports_helper::*; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:92:13 - | -LL | use crate::fn_mod::*; - | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:98:75 - | -LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *}; - | ^ help: try: `inner_extern_foo` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:99:13 - | -LL | use wildcard_imports_helper::*; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:110:20 - | -LL | use self::{inner::*, inner2::*}; - | ^^^^^^^^ help: try: `inner::inner_foo` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:110:30 - | -LL | use self::{inner::*, inner2::*}; - | ^^^^^^^^^ help: try: `inner2::inner_bar` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:117:13 - | -LL | use wildcard_imports_helper::*; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:146:9 - | -LL | use crate::in_fn_test::*; - | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:155:9 - | -LL | use crate:: in_fn_test:: * ; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:156:9 - | -LL | use crate:: fn_mod:: - | _________^ -LL | | *; - | |_________^ help: try: `crate:: fn_mod::foo` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:167:13 - | -LL | use super::*; - | ^^^^^^^^ help: try: `super::foofoo` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:202:17 - | -LL | use super::*; - | ^^^^^^^^ help: try: `super::insidefoo` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:210:13 - | -LL | use super_imports::*; - | ^^^^^^^^^^^^^^^^ help: try: `super_imports::foofoo` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:219:17 - | -LL | use super::super::*; - | ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo` - -error: usage of wildcard import - --> $DIR/wildcard_imports.rs:228:13 - | -LL | use super::super::super_imports::*; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo` - -error: aborting due to 20 previous errors - diff --git a/tests/ui/write_literal.rs b/tests/ui/write_literal.rs deleted file mode 100644 index d8205c5eb670..000000000000 --- a/tests/ui/write_literal.rs +++ /dev/null @@ -1,43 +0,0 @@ -#![allow(unused_must_use)] -#![warn(clippy::write_literal)] - -use std::io::Write; - -fn main() { - let mut v = Vec::new(); - - // these should be fine - write!(&mut v, "Hello"); - writeln!(&mut v, "Hello"); - let world = "world"; - writeln!(&mut v, "Hello {}", world); - writeln!(&mut v, "Hello {world}", world = world); - writeln!(&mut v, "3 in hex is {:X}", 3); - writeln!(&mut v, "2 + 1 = {:.4}", 3); - writeln!(&mut v, "2 + 1 = {:5.4}", 3); - writeln!(&mut v, "Debug test {:?}", "hello, world"); - writeln!(&mut v, "{0:8} {1:>8}", "hello", "world"); - writeln!(&mut v, "{1:8} {0:>8}", "hello", "world"); - writeln!(&mut v, "{foo:8} {bar:>8}", foo = "hello", bar = "world"); - writeln!(&mut v, "{bar:8} {foo:>8}", foo = "hello", bar = "world"); - writeln!(&mut v, "{number:>width$}", number = 1, width = 6); - writeln!(&mut v, "{number:>0width$}", number = 1, width = 6); - - // these should throw warnings - writeln!(&mut v, "{} of {:b} people know binary, the other half doesn't", 1, 2); - write!(&mut v, "Hello {}", "world"); - writeln!(&mut v, "Hello {} {}", world, "world"); - writeln!(&mut v, "Hello {}", "world"); - writeln!(&mut v, "10 / 4 is {}", 2.5); - writeln!(&mut v, "2 + 1 = {}", 3); - - // positional args don't change the fact - // that we're using a literal -- this should - // throw a warning - writeln!(&mut v, "{0} {1}", "hello", "world"); - writeln!(&mut v, "{1} {0}", "hello", "world"); - - // named args shouldn't change anything either - writeln!(&mut v, "{foo} {bar}", foo = "hello", bar = "world"); - writeln!(&mut v, "{bar} {foo}", foo = "hello", bar = "world"); -} diff --git a/tests/ui/write_literal.stderr b/tests/ui/write_literal.stderr deleted file mode 100644 index 54a787fe555a..000000000000 --- a/tests/ui/write_literal.stderr +++ /dev/null @@ -1,88 +0,0 @@ -error: literal with an empty format string - --> $DIR/write_literal.rs:27:79 - | -LL | writeln!(&mut v, "{} of {:b} people know binary, the other half doesn't", 1, 2); - | ^ - | - = note: `-D clippy::write-literal` implied by `-D warnings` - -error: literal with an empty format string - --> $DIR/write_literal.rs:28:32 - | -LL | write!(&mut v, "Hello {}", "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/write_literal.rs:29:44 - | -LL | writeln!(&mut v, "Hello {} {}", world, "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/write_literal.rs:30:34 - | -LL | writeln!(&mut v, "Hello {}", "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/write_literal.rs:31:38 - | -LL | writeln!(&mut v, "10 / 4 is {}", 2.5); - | ^^^ - -error: literal with an empty format string - --> $DIR/write_literal.rs:32:36 - | -LL | writeln!(&mut v, "2 + 1 = {}", 3); - | ^ - -error: literal with an empty format string - --> $DIR/write_literal.rs:37:33 - | -LL | writeln!(&mut v, "{0} {1}", "hello", "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/write_literal.rs:37:42 - | -LL | writeln!(&mut v, "{0} {1}", "hello", "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/write_literal.rs:38:33 - | -LL | writeln!(&mut v, "{1} {0}", "hello", "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/write_literal.rs:38:42 - | -LL | writeln!(&mut v, "{1} {0}", "hello", "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/write_literal.rs:41:43 - | -LL | writeln!(&mut v, "{foo} {bar}", foo = "hello", bar = "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/write_literal.rs:41:58 - | -LL | writeln!(&mut v, "{foo} {bar}", foo = "hello", bar = "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/write_literal.rs:42:43 - | -LL | writeln!(&mut v, "{bar} {foo}", foo = "hello", bar = "world"); - | ^^^^^^^ - -error: literal with an empty format string - --> $DIR/write_literal.rs:42:58 - | -LL | writeln!(&mut v, "{bar} {foo}", foo = "hello", bar = "world"); - | ^^^^^^^ - -error: aborting due to 14 previous errors - diff --git a/tests/ui/write_with_newline.rs b/tests/ui/write_with_newline.rs deleted file mode 100644 index 1c1b1b58402e..000000000000 --- a/tests/ui/write_with_newline.rs +++ /dev/null @@ -1,59 +0,0 @@ -// FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 -// // run-rustfix - -#![allow(clippy::write_literal)] -#![warn(clippy::write_with_newline)] - -use std::io::Write; - -fn main() { - let mut v = Vec::new(); - - // These should fail - write!(&mut v, "Hello\n"); - write!(&mut v, "Hello {}\n", "world"); - write!(&mut v, "Hello {} {}\n", "world", "#2"); - write!(&mut v, "{}\n", 1265); - write!(&mut v, "\n"); - - // These should be fine - write!(&mut v, ""); - write!(&mut v, "Hello"); - writeln!(&mut v, "Hello"); - writeln!(&mut v, "Hello\n"); - writeln!(&mut v, "Hello {}\n", "world"); - write!(&mut v, "Issue\n{}", 1265); - write!(&mut v, "{}", 1265); - write!(&mut v, "\n{}", 1275); - write!(&mut v, "\n\n"); - write!(&mut v, "like eof\n\n"); - write!(&mut v, "Hello {} {}\n\n", "world", "#2"); - writeln!(&mut v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - writeln!(&mut v, "\nbla\n\n"); // #3126 - - // Escaping - write!(&mut v, "\\n"); // #3514 - write!(&mut v, "\\\n"); // should fail - write!(&mut v, "\\\\n"); - - // Raw strings - write!(&mut v, r"\n"); // #3778 - - // Literal newlines should also fail - write!( - &mut v, - " -" - ); - write!( - &mut v, - r" -" - ); - - // Don't warn on CRLF (#4208) - write!(&mut v, "\r\n"); - write!(&mut v, "foo\r\n"); - write!(&mut v, "\\r\n"); //~ ERROR - write!(&mut v, "foo\rbar\n"); -} diff --git a/tests/ui/write_with_newline.stderr b/tests/ui/write_with_newline.stderr deleted file mode 100644 index a14e86122ee5..000000000000 --- a/tests/ui/write_with_newline.stderr +++ /dev/null @@ -1,125 +0,0 @@ -error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:13:5 - | -LL | write!(&mut v, "Hello/n"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::write-with-newline` implied by `-D warnings` -help: use `writeln!()` instead - | -LL | writeln!(&mut v, "Hello"); - | ^^^^^^^ -- - -error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:14:5 - | -LL | write!(&mut v, "Hello {}/n", "world"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: use `writeln!()` instead - | -LL | writeln!(&mut v, "Hello {}", "world"); - | ^^^^^^^ -- - -error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:15:5 - | -LL | write!(&mut v, "Hello {} {}/n", "world", "#2"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: use `writeln!()` instead - | -LL | writeln!(&mut v, "Hello {} {}", "world", "#2"); - | ^^^^^^^ -- - -error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:16:5 - | -LL | write!(&mut v, "{}/n", 1265); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: use `writeln!()` instead - | -LL | writeln!(&mut v, "{}", 1265); - | ^^^^^^^ -- - -error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:17:5 - | -LL | write!(&mut v, "/n"); - | ^^^^^^^^^^^^^^^^^^^^ - | -help: use `writeln!()` instead - | -LL | writeln!(&mut v, ); - | ^^^^^^^ -- - -error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:36:5 - | -LL | write!(&mut v, "//n"); // should fail - | ^^^^^^^^^^^^^^^^^^^^^^ - | -help: use `writeln!()` instead - | -LL | writeln!(&mut v, "/"); // should fail - | ^^^^^^^ -- - -error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:43:5 - | -LL | / write!( -LL | | &mut v, -LL | | " -LL | | " -LL | | ); - | |_____^ - | -help: use `writeln!()` instead - | -LL | writeln!( -LL | &mut v, -LL | "" - | - -error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:48:5 - | -LL | / write!( -LL | | &mut v, -LL | | r" -LL | | " -LL | | ); - | |_____^ - | -help: use `writeln!()` instead - | -LL | writeln!( -LL | &mut v, -LL | r"" - | - -error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:57:5 - | -LL | write!(&mut v, "/r/n"); //~ ERROR - | ^^^^^^^^^^^^^^^^^^^^^^^ - | -help: use `writeln!()` instead - | -LL | writeln!(&mut v, "/r"); //~ ERROR - | ^^^^^^^ -- - -error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:58:5 - | -LL | write!(&mut v, "foo/rbar/n"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: use `writeln!()` instead - | -LL | writeln!(&mut v, "foo/rbar"); - | ^^^^^^^ -- - -error: aborting due to 10 previous errors - diff --git a/tests/ui/writeln_empty_string.fixed b/tests/ui/writeln_empty_string.fixed deleted file mode 100644 index c3ac15b03751..000000000000 --- a/tests/ui/writeln_empty_string.fixed +++ /dev/null @@ -1,20 +0,0 @@ -// run-rustfix - -#![allow(unused_must_use)] -#![warn(clippy::writeln_empty_string)] -use std::io::Write; - -fn main() { - let mut v = Vec::new(); - - // These should fail - writeln!(&mut v); - - let mut suggestion = Vec::new(); - writeln!(&mut suggestion); - - // These should be fine - writeln!(&mut v); - writeln!(&mut v, " "); - write!(&mut v, ""); -} diff --git a/tests/ui/writeln_empty_string.rs b/tests/ui/writeln_empty_string.rs deleted file mode 100644 index 9a8894b6c0d3..000000000000 --- a/tests/ui/writeln_empty_string.rs +++ /dev/null @@ -1,20 +0,0 @@ -// run-rustfix - -#![allow(unused_must_use)] -#![warn(clippy::writeln_empty_string)] -use std::io::Write; - -fn main() { - let mut v = Vec::new(); - - // These should fail - writeln!(&mut v, ""); - - let mut suggestion = Vec::new(); - writeln!(&mut suggestion, ""); - - // These should be fine - writeln!(&mut v); - writeln!(&mut v, " "); - write!(&mut v, ""); -} diff --git a/tests/ui/writeln_empty_string.stderr b/tests/ui/writeln_empty_string.stderr deleted file mode 100644 index 99635229b3e1..000000000000 --- a/tests/ui/writeln_empty_string.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: using `writeln!(&mut v, "")` - --> $DIR/writeln_empty_string.rs:11:5 - | -LL | writeln!(&mut v, ""); - | ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `writeln!(&mut v)` - | - = note: `-D clippy::writeln-empty-string` implied by `-D warnings` - -error: using `writeln!(&mut suggestion, "")` - --> $DIR/writeln_empty_string.rs:14:5 - | -LL | writeln!(&mut suggestion, ""); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `writeln!(&mut suggestion)` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/wrong_self_convention.rs b/tests/ui/wrong_self_convention.rs deleted file mode 100644 index 5282eba74fd1..000000000000 --- a/tests/ui/wrong_self_convention.rs +++ /dev/null @@ -1,139 +0,0 @@ -// edition:2018 -#![warn(clippy::wrong_self_convention)] -#![warn(clippy::wrong_pub_self_convention)] -#![allow(dead_code)] - -fn main() {} - -#[derive(Clone, Copy)] -struct Foo; - -impl Foo { - fn as_i32(self) {} - fn as_u32(&self) {} - fn into_i32(self) {} - fn is_i32(self) {} - fn is_u32(&self) {} - fn to_i32(self) {} - fn from_i32(self) {} - - pub fn as_i64(self) {} - pub fn into_i64(self) {} - pub fn is_i64(self) {} - pub fn to_i64(self) {} - pub fn from_i64(self) {} - // check whether the lint can be allowed at the function level - #[allow(clippy::wrong_self_convention)] - pub fn from_cake(self) {} - - fn as_x>(_: F) {} - fn as_y>(_: F) {} -} - -struct Bar; - -impl Bar { - fn as_i32(self) {} - fn as_u32(&self) {} - fn into_i32(&self) {} - fn into_u32(self) {} - fn is_i32(self) {} - fn is_u32(&self) {} - fn to_i32(self) {} - fn to_u32(&self) {} - fn from_i32(self) {} - - pub fn as_i64(self) {} - pub fn into_i64(&self) {} - pub fn is_i64(self) {} - pub fn to_i64(self) {} - pub fn from_i64(self) {} - - // test for false positives - fn as_(self) {} - fn into_(&self) {} - fn is_(self) {} - fn to_(self) {} - fn from_(self) {} - fn to_mut(&mut self) {} -} - -// Allow Box, Rc, Arc for methods that take conventionally take Self by value -#[allow(clippy::boxed_local)] -mod issue4293 { - use std::rc::Rc; - use std::sync::Arc; - - struct T; - - impl T { - fn into_s1(self: Box) {} - fn into_s2(self: Rc) {} - fn into_s3(self: Arc) {} - - fn into_t1(self: Box) {} - fn into_t2(self: Rc) {} - fn into_t3(self: Arc) {} - } -} - -// False positive for async (see #4037) -mod issue4037 { - pub struct Foo; - pub struct Bar; - - impl Foo { - pub async fn into_bar(self) -> Bar { - Bar - } - } -} - -// Lint also in trait definition (see #6307) -mod issue6307 { - trait T: Sized { - fn as_i32(self) {} - fn as_u32(&self) {} - fn into_i32(&self) {} - fn into_u32(self) {} - fn is_i32(self) {} - fn is_u32(&self) {} - fn to_i32(self) {} - fn to_u32(&self) {} - fn from_i32(self) {} - // check whether the lint can be allowed at the function level - #[allow(clippy::wrong_self_convention)] - fn from_cake(self) {} - - // test for false positives - fn as_(self) {} - fn into_(&self) {} - fn is_(self) {} - fn to_(self) {} - fn from_(self) {} - fn to_mut(&mut self) {} - } - - trait U { - fn as_i32(self); - fn as_u32(&self); - fn into_i32(&self); - fn into_u32(self); - fn is_i32(self); - fn is_u32(&self); - fn to_i32(self); - fn to_u32(&self); - fn from_i32(self); - // check whether the lint can be allowed at the function level - #[allow(clippy::wrong_self_convention)] - fn from_cake(self); - - // test for false positives - fn as_(self); - fn into_(&self); - fn is_(self); - fn to_(self); - fn from_(self); - fn to_mut(&mut self); - } -} diff --git a/tests/ui/wrong_self_convention.stderr b/tests/ui/wrong_self_convention.stderr deleted file mode 100644 index 86467eb0fc73..000000000000 --- a/tests/ui/wrong_self_convention.stderr +++ /dev/null @@ -1,136 +0,0 @@ -error: methods called `from_*` usually take no self; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:18:17 - | -LL | fn from_i32(self) {} - | ^^^^ - | - = note: `-D clippy::wrong-self-convention` implied by `-D warnings` - -error: methods called `from_*` usually take no self; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:24:21 - | -LL | pub fn from_i64(self) {} - | ^^^^ - -error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:36:15 - | -LL | fn as_i32(self) {} - | ^^^^ - -error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:38:17 - | -LL | fn into_i32(&self) {} - | ^^^^^ - -error: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:40:15 - | -LL | fn is_i32(self) {} - | ^^^^ - -error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:42:15 - | -LL | fn to_i32(self) {} - | ^^^^ - -error: methods called `from_*` usually take no self; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:44:17 - | -LL | fn from_i32(self) {} - | ^^^^ - -error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:46:19 - | -LL | pub fn as_i64(self) {} - | ^^^^ - -error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:47:21 - | -LL | pub fn into_i64(&self) {} - | ^^^^^ - -error: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:48:19 - | -LL | pub fn is_i64(self) {} - | ^^^^ - -error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:49:19 - | -LL | pub fn to_i64(self) {} - | ^^^^ - -error: methods called `from_*` usually take no self; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:50:21 - | -LL | pub fn from_i64(self) {} - | ^^^^ - -error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:95:19 - | -LL | fn as_i32(self) {} - | ^^^^ - -error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:97:21 - | -LL | fn into_i32(&self) {} - | ^^^^^ - -error: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:99:19 - | -LL | fn is_i32(self) {} - | ^^^^ - -error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:101:19 - | -LL | fn to_i32(self) {} - | ^^^^ - -error: methods called `from_*` usually take no self; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:103:21 - | -LL | fn from_i32(self) {} - | ^^^^ - -error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:118:19 - | -LL | fn as_i32(self); - | ^^^^ - -error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:120:21 - | -LL | fn into_i32(&self); - | ^^^^^ - -error: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:122:19 - | -LL | fn is_i32(self); - | ^^^^ - -error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:124:19 - | -LL | fn to_i32(self); - | ^^^^ - -error: methods called `from_*` usually take no self; consider choosing a less ambiguous name - --> $DIR/wrong_self_convention.rs:126:21 - | -LL | fn from_i32(self); - | ^^^^ - -error: aborting due to 22 previous errors - diff --git a/tests/ui/zero_div_zero.rs b/tests/ui/zero_div_zero.rs deleted file mode 100644 index 09db130a7643..000000000000 --- a/tests/ui/zero_div_zero.rs +++ /dev/null @@ -1,13 +0,0 @@ -#[allow(unused_variables)] -#[warn(clippy::zero_divided_by_zero)] -fn main() { - let nan = 0.0 / 0.0; - let f64_nan = 0.0 / 0.0f64; - let other_f64_nan = 0.0f64 / 0.0; - let one_more_f64_nan = 0.0f64 / 0.0f64; - let zero = 0.0; - let other_zero = 0.0; - let other_nan = zero / other_zero; // fine - this lint doesn't propegate constants. - let not_nan = 2.0 / 0.0; // not an error: 2/0 = inf - let also_not_nan = 0.0 / 2.0; // not an error: 0/2 = 0 -} diff --git a/tests/ui/zero_div_zero.stderr b/tests/ui/zero_div_zero.stderr deleted file mode 100644 index d0e88f3c5a54..000000000000 --- a/tests/ui/zero_div_zero.stderr +++ /dev/null @@ -1,61 +0,0 @@ -error: equal expressions as operands to `/` - --> $DIR/zero_div_zero.rs:4:15 - | -LL | let nan = 0.0 / 0.0; - | ^^^^^^^^^ - | - = note: `#[deny(clippy::eq_op)]` on by default - -error: constant division of `0.0` with `0.0` will always result in NaN - --> $DIR/zero_div_zero.rs:4:15 - | -LL | let nan = 0.0 / 0.0; - | ^^^^^^^^^ - | - = note: `-D clippy::zero-divided-by-zero` implied by `-D warnings` - = help: Consider using `f64::NAN` if you would like a constant representing NaN - -error: equal expressions as operands to `/` - --> $DIR/zero_div_zero.rs:5:19 - | -LL | let f64_nan = 0.0 / 0.0f64; - | ^^^^^^^^^^^^ - -error: constant division of `0.0` with `0.0` will always result in NaN - --> $DIR/zero_div_zero.rs:5:19 - | -LL | let f64_nan = 0.0 / 0.0f64; - | ^^^^^^^^^^^^ - | - = help: Consider using `f64::NAN` if you would like a constant representing NaN - -error: equal expressions as operands to `/` - --> $DIR/zero_div_zero.rs:6:25 - | -LL | let other_f64_nan = 0.0f64 / 0.0; - | ^^^^^^^^^^^^ - -error: constant division of `0.0` with `0.0` will always result in NaN - --> $DIR/zero_div_zero.rs:6:25 - | -LL | let other_f64_nan = 0.0f64 / 0.0; - | ^^^^^^^^^^^^ - | - = help: Consider using `f64::NAN` if you would like a constant representing NaN - -error: equal expressions as operands to `/` - --> $DIR/zero_div_zero.rs:7:28 - | -LL | let one_more_f64_nan = 0.0f64 / 0.0f64; - | ^^^^^^^^^^^^^^^ - -error: constant division of `0.0` with `0.0` will always result in NaN - --> $DIR/zero_div_zero.rs:7:28 - | -LL | let one_more_f64_nan = 0.0f64 / 0.0f64; - | ^^^^^^^^^^^^^^^ - | - = help: Consider using `f64::NAN` if you would like a constant representing NaN - -error: aborting due to 8 previous errors - diff --git a/tests/ui/zero_offset.rs b/tests/ui/zero_offset.rs deleted file mode 100644 index 2de904376ad4..000000000000 --- a/tests/ui/zero_offset.rs +++ /dev/null @@ -1,12 +0,0 @@ -fn main() { - unsafe { - let x = &() as *const (); - x.offset(0); - x.wrapping_add(0); - x.sub(0); - x.wrapping_sub(0); - - let y = &1 as *const u8; - y.offset(0); - } -} diff --git a/tests/ui/zero_offset.stderr b/tests/ui/zero_offset.stderr deleted file mode 100644 index cfcd7de2b3d2..000000000000 --- a/tests/ui/zero_offset.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0606]: casting `&i32` as `*const u8` is invalid - --> $DIR/zero_offset.rs:9:17 - | -LL | let y = &1 as *const u8; - | ^^^^^^^^^^^^^^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0606`. diff --git a/tests/ui/zero_ptr.fixed b/tests/ui/zero_ptr.fixed deleted file mode 100644 index 489aa4121a3a..000000000000 --- a/tests/ui/zero_ptr.fixed +++ /dev/null @@ -1,14 +0,0 @@ -// run-rustfix -pub fn foo(_const: *const f32, _mut: *mut i64) {} - -fn main() { - let _ = std::ptr::null::(); - let _ = std::ptr::null_mut::(); - let _: *const u8 = std::ptr::null(); - - foo(0 as _, 0 as _); - foo(std::ptr::null(), std::ptr::null_mut()); - - let z = 0; - let _ = z as *const usize; // this is currently not caught -} diff --git a/tests/ui/zero_ptr.rs b/tests/ui/zero_ptr.rs deleted file mode 100644 index c3b55ef9ebd9..000000000000 --- a/tests/ui/zero_ptr.rs +++ /dev/null @@ -1,14 +0,0 @@ -// run-rustfix -pub fn foo(_const: *const f32, _mut: *mut i64) {} - -fn main() { - let _ = 0 as *const usize; - let _ = 0 as *mut f64; - let _: *const u8 = 0 as *const _; - - foo(0 as _, 0 as _); - foo(0 as *const _, 0 as *mut _); - - let z = 0; - let _ = z as *const usize; // this is currently not caught -} diff --git a/tests/ui/zero_ptr.stderr b/tests/ui/zero_ptr.stderr deleted file mode 100644 index 4ee5e9a26168..000000000000 --- a/tests/ui/zero_ptr.stderr +++ /dev/null @@ -1,34 +0,0 @@ -error: `0 as *const _` detected - --> $DIR/zero_ptr.rs:5:13 - | -LL | let _ = 0 as *const usize; - | ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::null::()` - | - = note: `-D clippy::zero-ptr` implied by `-D warnings` - -error: `0 as *mut _` detected - --> $DIR/zero_ptr.rs:6:13 - | -LL | let _ = 0 as *mut f64; - | ^^^^^^^^^^^^^ help: try: `std::ptr::null_mut::()` - -error: `0 as *const _` detected - --> $DIR/zero_ptr.rs:7:24 - | -LL | let _: *const u8 = 0 as *const _; - | ^^^^^^^^^^^^^ help: try: `std::ptr::null()` - -error: `0 as *const _` detected - --> $DIR/zero_ptr.rs:10:9 - | -LL | foo(0 as *const _, 0 as *mut _); - | ^^^^^^^^^^^^^ help: try: `std::ptr::null()` - -error: `0 as *mut _` detected - --> $DIR/zero_ptr.rs:10:24 - | -LL | foo(0 as *const _, 0 as *mut _); - | ^^^^^^^^^^^ help: try: `std::ptr::null_mut()` - -error: aborting due to 5 previous errors - diff --git a/tests/ui/zero_sized_btreemap_values.rs b/tests/ui/zero_sized_btreemap_values.rs deleted file mode 100644 index 5cd254787d83..000000000000 --- a/tests/ui/zero_sized_btreemap_values.rs +++ /dev/null @@ -1,68 +0,0 @@ -#![warn(clippy::zero_sized_map_values)] -use std::collections::BTreeMap; - -const CONST_OK: Option> = None; -const CONST_NOT_OK: Option> = None; - -static STATIC_OK: Option> = None; -static STATIC_NOT_OK: Option> = None; - -type OkMap = BTreeMap; -type NotOkMap = BTreeMap; - -enum TestEnum { - Ok(BTreeMap), - NotOk(BTreeMap), -} - -struct Test { - ok: BTreeMap, - not_ok: BTreeMap, - - also_not_ok: Vec>, -} - -trait TestTrait { - type Output; - - fn produce_output() -> Self::Output; - - fn weird_map(&self, map: BTreeMap); -} - -impl Test { - fn ok(&self) -> BTreeMap { - todo!() - } - - fn not_ok(&self) -> BTreeMap { - todo!() - } -} - -impl TestTrait for Test { - type Output = BTreeMap; - - fn produce_output() -> Self::Output { - todo!(); - } - - fn weird_map(&self, map: BTreeMap) { - todo!(); - } -} - -fn test(map: BTreeMap, key: &str) -> BTreeMap { - todo!(); -} - -fn test2(map: BTreeMap, key: &str) -> BTreeMap { - todo!(); -} - -fn main() { - let _: BTreeMap = BTreeMap::new(); - let _: BTreeMap = BTreeMap::new(); - - let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect(); -} diff --git a/tests/ui/zero_sized_btreemap_values.stderr b/tests/ui/zero_sized_btreemap_values.stderr deleted file mode 100644 index 334d921a9af3..000000000000 --- a/tests/ui/zero_sized_btreemap_values.stderr +++ /dev/null @@ -1,107 +0,0 @@ -error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:5:28 - | -LL | const CONST_NOT_OK: Option> = None; - | ^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::zero-sized-map-values` implied by `-D warnings` - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:8:30 - | -LL | static STATIC_NOT_OK: Option> = None; - | ^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:11:17 - | -LL | type NotOkMap = BTreeMap; - | ^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:15:11 - | -LL | NotOk(BTreeMap), - | ^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:20:13 - | -LL | not_ok: BTreeMap, - | ^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:22:22 - | -LL | also_not_ok: Vec>, - | ^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:30:30 - | -LL | fn weird_map(&self, map: BTreeMap); - | ^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:38:25 - | -LL | fn not_ok(&self) -> BTreeMap { - | ^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:55:14 - | -LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { - | ^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:55:50 - | -LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { - | ^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:64:35 - | -LL | let _: BTreeMap = BTreeMap::new(); - | ^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:64:12 - | -LL | let _: BTreeMap = BTreeMap::new(); - | ^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:67:12 - | -LL | let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect(); - | ^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: aborting due to 13 previous errors - diff --git a/tests/ui/zero_sized_hashmap_values.rs b/tests/ui/zero_sized_hashmap_values.rs deleted file mode 100644 index a1608d863fb5..000000000000 --- a/tests/ui/zero_sized_hashmap_values.rs +++ /dev/null @@ -1,68 +0,0 @@ -#![warn(clippy::zero_sized_map_values)] -use std::collections::HashMap; - -const CONST_OK: Option> = None; -const CONST_NOT_OK: Option> = None; - -static STATIC_OK: Option> = None; -static STATIC_NOT_OK: Option> = None; - -type OkMap = HashMap; -type NotOkMap = HashMap; - -enum TestEnum { - Ok(HashMap), - NotOk(HashMap), -} - -struct Test { - ok: HashMap, - not_ok: HashMap, - - also_not_ok: Vec>, -} - -trait TestTrait { - type Output; - - fn produce_output() -> Self::Output; - - fn weird_map(&self, map: HashMap); -} - -impl Test { - fn ok(&self) -> HashMap { - todo!() - } - - fn not_ok(&self) -> HashMap { - todo!() - } -} - -impl TestTrait for Test { - type Output = HashMap; - - fn produce_output() -> Self::Output { - todo!(); - } - - fn weird_map(&self, map: HashMap) { - todo!(); - } -} - -fn test(map: HashMap, key: &str) -> HashMap { - todo!(); -} - -fn test2(map: HashMap, key: &str) -> HashMap { - todo!(); -} - -fn main() { - let _: HashMap = HashMap::new(); - let _: HashMap = HashMap::new(); - - let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect(); -} diff --git a/tests/ui/zero_sized_hashmap_values.stderr b/tests/ui/zero_sized_hashmap_values.stderr deleted file mode 100644 index 43987b3d01d1..000000000000 --- a/tests/ui/zero_sized_hashmap_values.stderr +++ /dev/null @@ -1,107 +0,0 @@ -error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:5:28 - | -LL | const CONST_NOT_OK: Option> = None; - | ^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::zero-sized-map-values` implied by `-D warnings` - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:8:30 - | -LL | static STATIC_NOT_OK: Option> = None; - | ^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:11:17 - | -LL | type NotOkMap = HashMap; - | ^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:15:11 - | -LL | NotOk(HashMap), - | ^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:20:13 - | -LL | not_ok: HashMap, - | ^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:22:22 - | -LL | also_not_ok: Vec>, - | ^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:30:30 - | -LL | fn weird_map(&self, map: HashMap); - | ^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:38:25 - | -LL | fn not_ok(&self) -> HashMap { - | ^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:55:14 - | -LL | fn test(map: HashMap, key: &str) -> HashMap { - | ^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:55:49 - | -LL | fn test(map: HashMap, key: &str) -> HashMap { - | ^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:64:34 - | -LL | let _: HashMap = HashMap::new(); - | ^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:64:12 - | -LL | let _: HashMap = HashMap::new(); - | ^^^^^^^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:67:12 - | -LL | let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect(); - | ^^^^^^^^^^^^^ - | - = help: consider using a set instead - -error: aborting due to 13 previous errors - diff --git a/tests/versioncheck.rs b/tests/versioncheck.rs deleted file mode 100644 index f5d03c645df0..000000000000 --- a/tests/versioncheck.rs +++ /dev/null @@ -1,19 +0,0 @@ -#[test] -fn check_that_clippy_lints_has_the_same_version_as_clippy() { - let clippy_meta = cargo_metadata::MetadataCommand::new() - .no_deps() - .exec() - .expect("could not obtain cargo metadata"); - std::env::set_current_dir(std::env::current_dir().unwrap().join("clippy_lints")).unwrap(); - let clippy_lints_meta = cargo_metadata::MetadataCommand::new() - .no_deps() - .exec() - .expect("could not obtain cargo metadata"); - assert_eq!(clippy_lints_meta.packages[0].version, clippy_meta.packages[0].version); - for package in &clippy_meta.packages[0].dependencies { - if package.name == "clippy_lints" { - assert!(package.req.matches(&clippy_lints_meta.packages[0].version)); - return; - } - } -} diff --git a/triagebot.toml b/triagebot.toml deleted file mode 100644 index b9549be3a8b6..000000000000 --- a/triagebot.toml +++ /dev/null @@ -1,7 +0,0 @@ -[relabel] -allow-unauthenticated = [ - "A-*", "C-*", "E-*", "L-*", "M-*", "O-*", "P-*", "S-*", "T-*", - "good-first-issue" -] - -[assign] diff --git a/util/cov.sh b/util/cov.sh deleted file mode 100755 index 3f9a6b06f725..000000000000 --- a/util/cov.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/bash - -# This run `kcov` on Clippy. The coverage report will be at -# `./target/cov/index.html`. -# `compile-test` is special. `kcov` does not work directly on it so these files -# are compiled manually. - -tests=$(find tests/ -maxdepth 1 -name '*.rs' ! -name compile-test.rs -exec basename {} .rs \;) -tmpdir=$(mktemp -d) - -cargo test --no-run --verbose - -for t in $tests; do - kcov \ - --verify \ - --include-path="$(pwd)/src,$(pwd)/clippy_lints/src" \ - "$tmpdir/$t" \ - cargo test --test "$t" -done - -for t in ./tests/compile-fail/*.rs; do - kcov \ - --verify \ - --include-path="$(pwd)/src,$(pwd)/clippy_lints/src" \ - "$tmpdir/compile-fail-$(basename "$t")" \ - cargo run -- -L target/debug -L target/debug/deps -Z no-trans "$t" -done - -for t in ./tests/run-pass/*.rs; do - kcov \ - --verify \ - --include-path="$(pwd)/src,$(pwd)/clippy_lints/src" \ - "$tmpdir/run-pass-$(basename "$t")" \ - cargo run -- -L target/debug -L target/debug/deps -Z no-trans "$t" -done - -kcov --verify --merge target/cov "$tmpdir"/* diff --git a/util/export.py b/util/export.py deleted file mode 100755 index 5d1bd60acf3d..000000000000 --- a/util/export.py +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env python - -# Build the gh-pages - -from collections import OrderedDict -import re -import sys -import json - -from lintlib import parse_all, log - -lint_subheadline = re.compile(r'''^\*\*([\w\s]+?)[:?.!]?\*\*(.*)''') -rust_code_block = re.compile(r'''```rust.+?```''', flags=re.DOTALL) - -CONF_TEMPLATE = """\ -This lint has the following configuration variables: - -* `%s: %s`: %s (defaults to `%s`).""" - - -def parse_code_block(match): - lines = [] - - for line in match.group(0).split('\n'): - if not line.startswith('# '): - lines.append(line) - - return '\n'.join(lines) - - -def parse_lint_def(lint): - lint_dict = {} - lint_dict['id'] = lint.name - lint_dict['group'] = lint.group - lint_dict['level'] = lint.level - lint_dict['docs'] = OrderedDict() - - last_section = None - - for line in lint.doc: - match = re.match(lint_subheadline, line) - if match: - last_section = match.groups()[0] - text = match.groups()[1] - else: - text = line - - if not last_section: - log.warning("Skipping comment line as it was not preceded by a heading") - log.debug("in lint `%s`, line `%s`", lint.name, line) - - if last_section not in lint_dict['docs']: - lint_dict['docs'][last_section] = "" - - lint_dict['docs'][last_section] += text + "\n" - - for section in lint_dict['docs']: - lint_dict['docs'][section] = re.sub(rust_code_block, parse_code_block, lint_dict['docs'][section].strip()) - - return lint_dict - - -def main(): - lintlist, configs = parse_all() - lints = {} - for lint in lintlist: - lints[lint.name] = parse_lint_def(lint) - if lint.name in configs: - lints[lint.name]['docs']['Configuration'] = \ - CONF_TEMPLATE % configs[lint.name] - - outfile = sys.argv[1] if len(sys.argv) > 1 else "util/gh-pages/lints.json" - with open(outfile, "w") as fp: - lints = list(lints.values()) - lints.sort(key=lambda x: x['id']) - json.dump(lints, fp, indent=2) - log.info("wrote JSON for great justice") - - -if __name__ == "__main__": - main() diff --git a/util/fetch_prs_between.sh b/util/fetch_prs_between.sh deleted file mode 100755 index 6865abf971b2..000000000000 --- a/util/fetch_prs_between.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# Fetches the merge commits between two git commits and prints the PR URL -# together with the full commit message -# -# If you want to use this to update the Clippy changelog, be sure to manually -# exclude the non-user facing changes like 'rustup' PRs, typo fixes, etc. - -first=$1 -last=$2 - -IFS=' -' -for pr in $(git log --oneline --grep "Merge #" --grep "Merge pull request" --grep "Auto merge of" --grep "Rollup merge of" "$first...$last" | sort -rn | uniq); do - id=$(echo "$pr" | rg -o '#[0-9]{3,5}' | cut -c 2-) - commit=$(echo "$pr" | cut -d' ' -f 1) - message=$(git --no-pager show --pretty=medium "$commit") - if [[ -n $(echo "$message" | rg "^[\s]{4}changelog: [nN]one\.*$") ]]; then - continue - fi - - echo "URL: https://github.com/rust-lang/rust-clippy/pull/$id" - echo "Markdown URL: [#$id](https://github.com/rust-lang/rust-clippy/pull/$id)" - echo "$message" - echo "---------------------------------------------------------" - echo -done diff --git a/util/gh-pages/index.html b/util/gh-pages/index.html deleted file mode 100644 index 428708136cb6..000000000000 --- a/util/gh-pages/index.html +++ /dev/null @@ -1,317 +0,0 @@ - - - - - - - ALL the Clippy Lints - - - - - - -

- - - Fork me on Github - - - - - - - - - diff --git a/util/gh-pages/versions.html b/util/gh-pages/versions.html deleted file mode 100644 index 6e810a349bfc..000000000000 --- a/util/gh-pages/versions.html +++ /dev/null @@ -1,91 +0,0 @@ - - - - - - - Clippy lints documentation - - - - - -
- - -
- - - - -
-
- - - - - - - - - - diff --git a/util/lintlib.py b/util/lintlib.py deleted file mode 100644 index d0d9beb9b2d9..000000000000 --- a/util/lintlib.py +++ /dev/null @@ -1,114 +0,0 @@ -# Common utils for the several housekeeping scripts. - -import os -import re -import collections - -import logging as log -log.basicConfig(level=log.INFO, format='%(levelname)s: %(message)s') - -Lint = collections.namedtuple('Lint', 'name level doc sourcefile group') -Config = collections.namedtuple('Config', 'name ty doc default') - -lintname_re = re.compile(r'''pub\s+([A-Z_][A-Z_0-9]*)''') -group_re = re.compile(r'''\s*([a-z_][a-z_0-9]+)''') -conf_re = re.compile(r'''define_Conf! {\n([^}]*)\n}''', re.MULTILINE) -confvar_re = re.compile( - r'''/// Lint: ([\w,\s]+)\. (.*)\n\s*\([^,]+,\s+"([^"]+)":\s+([^,]+),\s+([^\.\)]+).*\),''', re.MULTILINE) -comment_re = re.compile(r'''\s*/// ?(.*)''') - -lint_levels = { - "correctness": 'Deny', - "style": 'Warn', - "complexity": 'Warn', - "perf": 'Warn', - "restriction": 'Allow', - "pedantic": 'Allow', - "nursery": 'Allow', - "cargo": 'Allow', -} - - -def parse_lints(lints, filepath): - comment = [] - clippy = False - deprecated = False - name = "" - - with open(filepath) as fp: - for line in fp: - if clippy or deprecated: - m = lintname_re.search(line) - if m: - name = m.group(1).lower() - line = next(fp) - - if deprecated: - level = "Deprecated" - group = "deprecated" - else: - while True: - g = group_re.search(line) - if g: - group = g.group(1).lower() - level = lint_levels.get(group, None) - break - line = next(fp) - - if level is None: - continue - - log.info("found %s with level %s in %s", - name, level, filepath) - lints.append(Lint(name, level, comment, filepath, group)) - comment = [] - - clippy = False - deprecated = False - name = "" - else: - m = comment_re.search(line) - if m: - comment.append(m.group(1)) - elif line.startswith("declare_clippy_lint!"): - clippy = True - deprecated = False - elif line.startswith("declare_deprecated_lint!"): - clippy = False - deprecated = True - elif line.startswith("declare_lint!"): - import sys - print( - "don't use `declare_lint!` in Clippy, " - "use `declare_clippy_lint!` instead" - ) - sys.exit(42) - - -def parse_configs(path): - configs = {} - with open(os.path.join(path, 'utils/conf.rs')) as fp: - contents = fp.read() - - match = re.search(conf_re, contents) - confvars = re.findall(confvar_re, match.group(1)) - - for (lints, doc, name, ty, default) in confvars: - for lint in lints.split(','): - configs[lint.strip().lower()] = Config(name.replace("_", "-"), ty, doc, default) - return configs - - -def parse_all(path="clippy_lints/src"): - lints = [] - for root, dirs, files in os.walk(path): - for fn in files: - if fn.endswith('.rs'): - parse_lints(lints, os.path.join(root, fn)) - - log.info("got %s lints", len(lints)) - - configs = parse_configs(path) - log.info("got %d configs", len(configs)) - - return lints, configs diff --git a/util/versions.py b/util/versions.py deleted file mode 100755 index 5cdc7313f543..000000000000 --- a/util/versions.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python - -import json -import os -import sys - -from lintlib import log - - -def key(v): - if v == 'master': - return float('inf') - if v == 'stable': - return sys.maxsize - if v == 'beta': - return sys.maxsize - 1 - - v = v.replace('v', '').replace('rust-', '') - - s = 0 - for i, val in enumerate(v.split('.')[::-1]): - s += int(val) * 100**i - - return s - - -def main(): - if len(sys.argv) < 2: - print("Error: specify output directory") - return - - outdir = sys.argv[1] - versions = [ - dir for dir in os.listdir(outdir) if not dir.startswith(".") and os.path.isdir(os.path.join(outdir, dir)) - ] - versions.sort(key=key) - - with open(os.path.join(outdir, "versions.json"), "w") as fp: - json.dump(versions, fp, indent=2) - log.info("wrote JSON for great justice") - - -if __name__ == "__main__": - main() From 090e0317c4e86505623fd70ddd01a769fec6351f Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 29 Dec 2020 17:15:53 -0500 Subject: [PATCH 0156/1222] Remove unnecessary semicolon from Clippy test --- tests/ui/match_expr_like_matches_macro.fixed | 2 +- tests/ui/match_expr_like_matches_macro.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/match_expr_like_matches_macro.fixed b/tests/ui/match_expr_like_matches_macro.fixed index 7f4ebf566733..84981a525973 100644 --- a/tests/ui/match_expr_like_matches_macro.fixed +++ b/tests/ui/match_expr_like_matches_macro.fixed @@ -39,7 +39,7 @@ fn main() { B(i32), C, D, - }; + } let x = E::A(2); { // lint diff --git a/tests/ui/match_expr_like_matches_macro.rs b/tests/ui/match_expr_like_matches_macro.rs index aee56dd4a5ef..94c7c3cadacf 100644 --- a/tests/ui/match_expr_like_matches_macro.rs +++ b/tests/ui/match_expr_like_matches_macro.rs @@ -51,7 +51,7 @@ fn main() { B(i32), C, D, - }; + } let x = E::A(2); { // lint From 641dcb0e74f2202107b865878bd156acc2103309 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 29 Dec 2020 20:28:08 -0500 Subject: [PATCH 0157/1222] Rename kw::Invalid -> kw::Empty See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471 for context. --- clippy_lints/src/lifetimes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 4d737b3f49b0..e84c8b4e5b3e 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -501,7 +501,7 @@ impl<'tcx> Visitor<'tcx> for BodyLifetimeChecker { // for lifetimes as parameters of generics fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { - if lifetime.name.ident().name != kw::Invalid && lifetime.name.ident().name != kw::StaticLifetime { + if lifetime.name.ident().name != kw::Empty && lifetime.name.ident().name != kw::StaticLifetime { self.lifetimes_used_in_body = true; } } From bbaa5b63a532520644999fb02bff03840d4f248f Mon Sep 17 00:00:00 2001 From: Julian Knodt Date: Thu, 31 Dec 2020 01:58:27 +0100 Subject: [PATCH 0158/1222] first pass at default values for const generics - Adds optional default values to const generic parameters in the AST and HIR - Parses these optional default values - Adds a `const_generics_defaults` feature gate --- clippy_lints/src/utils/ast_utils.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/ast_utils.rs b/clippy_lints/src/utils/ast_utils.rs index f0267e4c7928..940573e4caa6 100644 --- a/clippy_lints/src/utils/ast_utils.rs +++ b/clippy_lints/src/utils/ast_utils.rs @@ -407,6 +407,10 @@ pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool { } } +pub fn eq_anon_const(l: &AnonConst, r: &AnonConst) -> bool { + eq_expr(&l.value, &r.value) +} + pub fn eq_defaultness(l: Defaultness, r: Defaultness) -> bool { matches!( (l, r), @@ -497,7 +501,8 @@ pub fn eq_generic_param(l: &GenericParam, r: &GenericParam) -> bool { && match (&l.kind, &r.kind) { (Lifetime, Lifetime) => true, (Type { default: l }, Type { default: r }) => both(l, r, |l, r| eq_ty(l, r)), - (Const { ty: l, kw_span: _ }, Const { ty: r, kw_span: _ }) => eq_ty(l, r), + (Const { ty: lt, kw_span: _ , default: ld}, Const { ty: rt, kw_span: _, default: rd }) => + eq_ty(lt, rt) && both(ld, rd, |ld, rd| eq_anon_const(ld, rd)), _ => false, } && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)) From 30fc04e79336622d5df631446c7e0a357988b056 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Sat, 2 Jan 2021 18:01:42 +0100 Subject: [PATCH 0159/1222] Use bootstrap rustc for versioncheck in Clippy --- tests/versioncheck.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/versioncheck.rs b/tests/versioncheck.rs index 589b19f68f7a..76b6126c76c6 100644 --- a/tests/versioncheck.rs +++ b/tests/versioncheck.rs @@ -28,10 +28,11 @@ fn check_that_clippy_has_the_same_major_version_as_rustc() { let clippy_minor = clippy_version.minor; let clippy_patch = clippy_version.patch; - // get the rustc version - // this way the rust-toolchain file version is honored + // get the rustc version either from the rustc installed with the toolchain file or from + // `RUSTC_REAL` if Clippy is build in the Rust repo with `./x.py`. + let rustc = std::env::var("RUSTC_REAL").unwrap_or_else(|_| "rustc".to_string()); let rustc_version = String::from_utf8( - std::process::Command::new("rustc") + std::process::Command::new(&rustc) .arg("--version") .output() .expect("failed to run `rustc --version`") From 91de1136a67043ab73d313f7831adeaabc95c99f Mon Sep 17 00:00:00 2001 From: Caio Date: Fri, 1 Jan 2021 15:38:11 -0300 Subject: [PATCH 0160/1222] Reintroduce hir::ExprKind::If --- clippy_lints/src/assertions_on_constants.rs | 30 ++++------- clippy_lints/src/blocks_in_if_conditions.rs | 4 +- clippy_lints/src/cognitive_complexity.rs | 3 ++ clippy_lints/src/consts.rs | 6 +-- clippy_lints/src/copies.rs | 15 +++--- clippy_lints/src/entry.rs | 4 +- clippy_lints/src/floating_point_arithmetic.rs | 6 +-- clippy_lints/src/implicit_return.rs | 7 +++ clippy_lints/src/implicit_saturating_sub.rs | 4 +- clippy_lints/src/let_if_seq.rs | 5 +- clippy_lints/src/loops.rs | 10 +++- clippy_lints/src/manual_strip.rs | 2 +- clippy_lints/src/methods/mod.rs | 1 + .../src/methods/unnecessary_filter_map.rs | 6 +++ clippy_lints/src/mutable_debug_assertion.rs | 4 ++ clippy_lints/src/needless_bool.rs | 4 +- clippy_lints/src/option_if_let_else.rs | 15 +++--- clippy_lints/src/question_mark.rs | 4 +- clippy_lints/src/returns.rs | 11 ++-- clippy_lints/src/shadow.rs | 7 +++ clippy_lints/src/unwrap.rs | 4 +- clippy_lints/src/utils/author.rs | 51 ++++++++----------- clippy_lints/src/utils/eager_or_lazy.rs | 1 + clippy_lints/src/utils/higher.rs | 34 ++----------- clippy_lints/src/utils/hir_utils.rs | 12 +++++ clippy_lints/src/utils/inspector.rs | 9 ++++ clippy_lints/src/utils/mod.rs | 12 ++--- clippy_lints/src/utils/sugg.rs | 1 + clippy_lints/src/utils/visitors.rs | 7 +++ tests/ui/author/if.stdout | 2 +- tests/ui/panic_in_result_fn_assertions.stderr | 2 +- 31 files changed, 152 insertions(+), 131 deletions(-) diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index 62c73dbac48b..aa431f0596cc 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -1,8 +1,7 @@ use crate::consts::{constant, Constant}; use crate::utils::{is_direct_expn_of, is_expn_of, match_panic_call, snippet_opt, span_lint_and_help}; use if_chain::if_chain; -use rustc_ast::ast::LitKind; -use rustc_hir::{Expr, ExprKind, PatKind, UnOp}; +use rustc_hir::{Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -102,31 +101,22 @@ enum AssertKind { /// Check if the expression matches /// /// ```rust,ignore -/// match { let _t = !c; _t } { -/// true => { -/// { -/// ::std::rt::begin_panic(message, _) -/// } -/// } -/// _ => { } -/// }; +/// if !c { +/// { +/// ::std::rt::begin_panic(message, _) +/// } +/// } /// ``` /// /// where `message` is any expression and `c` is a constant bool. fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option { if_chain! { - if let ExprKind::Match(ref expr, ref arms, _) = expr.kind; - // matches { let _t = expr; _t } - if let ExprKind::DropTemps(ref expr) = expr.kind; - if let ExprKind::Unary(UnOp::UnNot, ref expr) = expr.kind; + if let ExprKind::If(ref cond, ref then, _) = expr.kind; + if let ExprKind::Unary(UnOp::UnNot, ref expr) = cond.kind; // bind the first argument of the `assert!` macro if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), expr); - // arm 1 pattern - if let PatKind::Lit(ref lit_expr) = arms[0].pat.kind; - if let ExprKind::Lit(ref lit) = lit_expr.kind; - if let LitKind::Bool(true) = lit.node; - // arm 1 block - if let ExprKind::Block(ref block, _) = arms[0].body.kind; + // block + if let ExprKind::Block(ref block, _) = then.kind; if block.stmts.is_empty(); if let Some(block_expr) = &block.expr; // inner block is optional. unwrap it if it exists, or use the expression as is otherwise. diff --git a/clippy_lints/src/blocks_in_if_conditions.rs b/clippy_lints/src/blocks_in_if_conditions.rs index 736730d4084f..4efca10bcdf1 100644 --- a/clippy_lints/src/blocks_in_if_conditions.rs +++ b/clippy_lints/src/blocks_in_if_conditions.rs @@ -1,4 +1,4 @@ -use crate::utils::{differing_macro_contexts, higher, snippet_block_with_applicability, span_lint, span_lint_and_sugg}; +use crate::utils::{differing_macro_contexts, snippet_block_with_applicability, span_lint, span_lint_and_sugg}; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_hir::{BlockCheckMode, Expr, ExprKind}; @@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInIfConditions { if in_external_macro(cx.sess(), expr.span) { return; } - if let Some((cond, _, _)) = higher::if_block(&expr) { + if let ExprKind::If(cond, _, _) = &expr.kind { if let ExprKind::Block(block, _) = &cond.kind { if block.rules == BlockCheckMode::DefaultBlock { if block.stmts.is_empty() { diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index b1bc2ec29e16..b3ebdf4ca30d 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -147,6 +147,9 @@ impl<'tcx> Visitor<'tcx> for CCHelper { fn visit_expr(&mut self, e: &'tcx Expr<'_>) { walk_expr(self, e); match e.kind { + ExprKind::If(_, _, _) => { + self.cc += 1; + }, ExprKind::Match(_, ref arms, _) => { if arms.len() > 1 { self.cc += 1; diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 0035ded9356c..166eadf86c17 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -1,6 +1,6 @@ #![allow(clippy::float_cmp)] -use crate::utils::{clip, higher, sext, unsext}; +use crate::utils::{clip, sext, unsext}; use if_chain::if_chain; use rustc_ast::ast::{FloatTy, LitFloatType, LitKind}; use rustc_data_structures::sync::Lrc; @@ -228,9 +228,6 @@ pub struct ConstEvalLateContext<'a, 'tcx> { impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { /// Simple constant folding: Insert an expression, get a constant or none. pub fn expr(&mut self, e: &Expr<'_>) -> Option { - if let Some((ref cond, ref then, otherwise)) = higher::if_block(&e) { - return self.ifthenelse(cond, then, otherwise); - } match e.kind { ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id, self.typeck_results.expr_ty(e)), ExprKind::Block(ref block, _) => self.block(block), @@ -249,6 +246,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { UnOp::UnNeg => self.constant_negate(&o, self.typeck_results.expr_ty(e)), UnOp::UnDeref => Some(if let Constant::Ref(r) = o { *r } else { o }), }), + ExprKind::If(ref cond, ref then, ref otherwise) => self.ifthenelse(cond, then, *otherwise), ExprKind::Binary(op, ref left, ref right) => self.binop(op, left, right), ExprKind::Call(ref callee, ref args) => { // We only handle a few const functions for now. diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 46ce92ea6d78..6f48ffeb0e9c 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -1,6 +1,6 @@ use crate::utils::{eq_expr_value, in_macro, search_same, SpanlessEq, SpanlessHash}; -use crate::utils::{get_parent_expr, higher, if_sequence, span_lint_and_note}; -use rustc_hir::{Block, Expr}; +use crate::utils::{get_parent_expr, if_sequence, span_lint_and_note}; +use rustc_hir::{Block, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -109,11 +109,12 @@ impl<'tcx> LateLintPass<'tcx> for CopyAndPaste { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if !expr.span.from_expansion() { // skip ifs directly in else, it will be checked in the parent if - if let Some(expr) = get_parent_expr(cx, expr) { - if let Some((_, _, Some(ref else_expr))) = higher::if_block(&expr) { - if else_expr.hir_id == expr.hir_id { - return; - } + if let Some(&Expr { + kind: ExprKind::If(_, _, Some(ref else_expr)), + .. + }) = get_parent_expr(cx, expr) { + if else_expr.hir_id == expr.hir_id { + return; } } diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 35a5d00f4aa5..37948e06869c 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -1,5 +1,5 @@ use crate::utils::SpanlessEq; -use crate::utils::{get_item_name, higher, is_type_diagnostic_item, match_type, paths, snippet, snippet_opt}; +use crate::utils::{get_item_name, is_type_diagnostic_item, match_type, paths, snippet, snippet_opt}; use crate::utils::{snippet_with_applicability, span_lint_and_then}; use if_chain::if_chain; use rustc_errors::Applicability; @@ -54,7 +54,7 @@ declare_lint_pass!(HashMapPass => [MAP_ENTRY]); impl<'tcx> LateLintPass<'tcx> for HashMapPass { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let Some((ref check, ref then_block, ref else_block)) = higher::if_block(&expr) { + if let ExprKind::If(ref check, ref then_block, ref else_block) = expr.kind { if let ExprKind::Unary(UnOp::UnNot, ref check) = check.kind { if let Some((ty, map, key)) = check_cond(cx, check) { // in case of `if !m.contains_key(&k) { m.insert(k, v); }` diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index 18fea8b34bfd..ffef78aac806 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -2,7 +2,7 @@ use crate::consts::{ constant, constant_simple, Constant, Constant::{Int, F32, F64}, }; -use crate::utils::{eq_expr_value, get_parent_expr, higher, numeric_literal, span_lint_and_sugg, sugg}; +use crate::utils::{eq_expr_value, get_parent_expr, numeric_literal, span_lint_and_sugg, sugg}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, PathSegment, UnOp}; @@ -556,11 +556,11 @@ fn are_negated<'a>(cx: &LateContext<'_>, expr1: &'a Expr<'a>, expr2: &'a Expr<'a fn check_custom_abs(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { - if let Some((cond, body, Some(else_body))) = higher::if_block(&expr); + if let ExprKind::If(cond, body, else_body) = expr.kind; if let ExprKind::Block(block, _) = body.kind; if block.stmts.is_empty(); if let Some(if_body_expr) = block.expr; - if let ExprKind::Block(else_block, _) = else_body.kind; + if let Some(ExprKind::Block(else_block, _)) = else_body.map(|el| &el.kind); if else_block.stmts.is_empty(); if let Some(else_body_expr) = else_block.expr; if let Some((if_expr_positive, body)) = are_negated(cx, if_body_expr, else_body_expr); diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index 03e95c9e27f6..109d90ff772b 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -81,6 +81,13 @@ fn expr_match(cx: &LateContext<'_>, expr: &Expr<'_>) { lint(cx, expr.span, break_expr.span, LINT_BREAK); } }, + ExprKind::If(.., if_expr, else_expr) => { + expr_match(cx, if_expr); + + if let Some(else_expr) = else_expr { + expr_match(cx, else_expr); + } + }, ExprKind::Match(.., arms, source) => { let check_all_arms = match source { MatchSource::IfLetDesugar { diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index 3a01acd8fdc9..16e162badb5e 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -1,4 +1,4 @@ -use crate::utils::{higher, in_macro, match_qpath, span_lint_and_sugg, SpanlessEq}; +use crate::utils::{in_macro, match_qpath, span_lint_and_sugg, SpanlessEq}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; @@ -42,7 +42,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { return; } if_chain! { - if let Some((ref cond, ref then, None)) = higher::if_block(&expr); + if let ExprKind::If(cond, then, None) = &expr.kind; // Check if the conditional expression is a binary operation if let ExprKind::Binary(ref cond_op, ref cond_left, ref cond_right) = cond.kind; diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 0d2d95324c4f..db717cd1240a 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -1,5 +1,4 @@ -use crate::utils::visitors::LocalUsedVisitor; -use crate::utils::{higher, qpath_res, snippet, span_lint_and_then}; +use crate::utils::{qpath_res, snippet, span_lint_and_then, visitors::LocalUsedVisitor}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; @@ -64,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq { if let hir::StmtKind::Local(ref local) = stmt.kind; if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.kind; if let hir::StmtKind::Expr(ref if_) = expr.kind; - if let Some((ref cond, ref then, ref else_)) = higher::if_block(&if_); + if let hir::ExprKind::If(ref cond, ref then, ref else_) = if_.kind; if !LocalUsedVisitor::new(canonical_id).check_expr(cond); if let hir::ExprKind::Block(ref then, _) = then.kind; if let Some(value) = check_assign(cx, canonical_id, &*then); diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 1bd96b2b4c89..281964ee5e8f 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -742,6 +742,14 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { // Break can come from the inner loop so remove them. absorb_break(&never_loop_block(b, main_loop_id)) }, + ExprKind::If(ref e, ref e2, ref e3) => { + let e1 = never_loop_expr(e, main_loop_id); + let e2 = never_loop_expr(e2, main_loop_id); + let e3 = e3 + .as_ref() + .map_or(NeverLoopResult::Otherwise, |e| never_loop_expr(e, main_loop_id)); + combine_seq(e1, combine_branches(e2, e3)) + }, ExprKind::Match(ref e, ref arms, _) => { let e = never_loop_expr(e, main_loop_id); if arms.is_empty() { @@ -2594,7 +2602,7 @@ fn is_loop(expr: &Expr<'_>) -> bool { } fn is_conditional(expr: &Expr<'_>) -> bool { - matches!(expr.kind, ExprKind::Match(..)) + matches!(expr.kind, ExprKind::If(..) | ExprKind::Match(..)) } fn is_nested(cx: &LateContext<'_>, match_expr: &Expr<'_>, iter_expr: &Expr<'_>) -> bool { diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index 3c4368a3545a..a0cfe145a301 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -80,7 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { } if_chain! { - if let Some((cond, then, _)) = higher::if_block(&expr); + if let ExprKind::If(cond, then, _) = &expr.kind; if let ExprKind::MethodCall(_, _, [target_arg, pattern], _) = cond.kind; if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(cond.hir_id); if let ExprKind::Path(target_path) = &target_arg.kind; diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index e99fe1b97ff6..2234890d6e94 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2048,6 +2048,7 @@ fn lint_expect_fun_call( hir::ExprKind::Call(..) | hir::ExprKind::MethodCall(..) // These variants are debatable or require further examination + | hir::ExprKind::If(..) | hir::ExprKind::Match(..) | hir::ExprKind::Block{ .. } => true, _ => false, diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index d082a88cd2db..d98e6160d308 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -90,6 +90,12 @@ fn check_expression<'tcx>(cx: &LateContext<'tcx>, arg_id: hir::HirId, expr: &'tc } (found_mapping, found_filtering) }, + // There must be an else_arm or there will be a type error + hir::ExprKind::If(_, ref if_arm, Some(ref else_arm)) => { + let if_check = check_expression(cx, arg_id, if_arm); + let else_check = check_expression(cx, arg_id, else_arm); + (if_check.0 | else_check.0, if_check.1 | else_check.1) + }, hir::ExprKind::Path(path) if match_qpath(path, &paths::OPTION_NONE) => (false, true), _ => (true, true), } diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index 76417aa7ed09..71f91eb4bfbe 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -90,6 +90,10 @@ impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> { self.found = true; return; }, + ExprKind::If(..) => { + self.found = true; + return; + }, ExprKind::Path(_) => { if let Some(adj) = self.cx.typeck_results().adjustments().get(expr.hir_id) { if adj diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index 42f97b2ac497..6b9a37b52520 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -4,7 +4,7 @@ use crate::utils::sugg::Sugg; use crate::utils::{ - higher, is_expn_of, parent_node_is_if_expr, snippet_with_applicability, span_lint, span_lint_and_sugg, + is_expn_of, parent_node_is_if_expr, snippet_with_applicability, span_lint, span_lint_and_sugg, }; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; @@ -71,7 +71,7 @@ declare_lint_pass!(NeedlessBool => [NEEDLESS_BOOL]); impl<'tcx> LateLintPass<'tcx> for NeedlessBool { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { use self::Expression::{Bool, RetBool}; - if let Some((ref pred, ref then_block, Some(ref else_expr))) = higher::if_block(&e) { + if let ExprKind::If(ref pred, ref then_block, Some(ref else_expr)) = e.kind { let reduce = |ret, not| { let mut applicability = Applicability::MachineApplicable; let snip = Sugg::hir_with_applicability(cx, pred, "", &mut applicability); diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index 681dbce97697..391f893ef35f 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -109,25 +109,26 @@ fn extract_body_from_arm<'a>(arm: &'a Arm<'a>) -> Option<&'a Expr<'a>> { /// it in curly braces. Otherwise, we don't. fn should_wrap_in_braces(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { utils::get_enclosing_block(cx, expr.hir_id).map_or(false, |parent| { + let mut should_wrap = false; + if let Some(Expr { kind: ExprKind::Match( _, arms, - MatchSource::IfDesugar { - contains_else_clause: true, - } - | MatchSource::IfLetDesugar { + MatchSource::IfLetDesugar { contains_else_clause: true, }, ), .. }) = parent.expr { - expr.hir_id == arms[1].body.hir_id - } else { - false + should_wrap = expr.hir_id == arms[1].body.hir_id; + } else if let Some(Expr { kind: ExprKind::If(_, _, Some(else_clause)), .. }) = parent.expr { + should_wrap = expr.hir_id == else_clause.hir_id; } + + should_wrap }) } diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index b91233ac5828..6c480d48c756 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -8,7 +8,7 @@ use rustc_span::sym; use crate::utils::sugg::Sugg; use crate::utils::{ - eq_expr_value, higher, is_type_diagnostic_item, match_def_path, match_qpath, paths, snippet_with_applicability, + eq_expr_value, is_type_diagnostic_item, match_def_path, match_qpath, paths, snippet_with_applicability, span_lint_and_sugg, }; @@ -50,7 +50,7 @@ impl QuestionMark { /// If it matches, it will suggest to use the question mark operator instead fn check_is_none_and_early_return_none(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { - if let Some((if_expr, body, else_)) = higher::if_block(&expr); + if let ExprKind::If(if_expr, body, else_) = &expr.kind; if let ExprKind::MethodCall(segment, _, args, _) = &if_expr.kind; if segment.ident.name == sym!(is_none); if Self::expression_returns_none(cx, body); diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 7f4913a02cbd..35827e027aab 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -184,6 +184,14 @@ fn check_final_expr<'tcx>( ExprKind::Block(ref block, _) => { check_block_return(cx, block); }, + ExprKind::If(_, then, else_clause_opt) => { + if let ExprKind::Block(ref ifblock, _) = then.kind { + check_block_return(cx, ifblock); + } + if let Some(else_clause) = else_clause_opt { + check_final_expr(cx, else_clause, None, RetReplacement::Empty); + } + }, // a match expr, check all arms // an if/if let expr, check both exprs // note, if without else is going to be a type checking error anyways @@ -194,9 +202,6 @@ fn check_final_expr<'tcx>( check_final_expr(cx, &arm.body, Some(arm.body.span), RetReplacement::Block); } }, - MatchSource::IfDesugar { - contains_else_clause: true, - } | MatchSource::IfLetDesugar { contains_else_clause: true, } => { diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index f83965926782..f2f3dfa09a7d 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -333,6 +333,13 @@ fn check_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, bindings: &mut check_expr(cx, e, bindings) } }, + ExprKind::If(ref cond, ref then, ref otherwise) => { + check_expr(cx, cond, bindings); + check_expr(cx, &**then, bindings); + if let Some(ref o) = *otherwise { + check_expr(cx, o, bindings); + } + }, ExprKind::Match(ref init, arms, _) => { check_expr(cx, init, bindings); let len = bindings.len(); diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index f4a77e54dd14..6a87f5343698 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -1,5 +1,5 @@ use crate::utils::{ - differing_macro_contexts, higher::if_block, is_type_diagnostic_item, span_lint_and_then, + differing_macro_contexts, is_type_diagnostic_item, span_lint_and_then, usage::is_potentially_mutated, }; use if_chain::if_chain; @@ -158,7 +158,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> { if in_external_macro(self.cx.tcx.sess, expr.span) { return; } - if let Some((cond, then, els)) = if_block(&expr) { + if let ExprKind::If(cond, then, els) = &expr.kind { walk_expr(self, cond); self.visit_branch(cond, then, false); if let Some(els) = els { diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 4249dbb4e651..43afa65de3e5 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -1,7 +1,7 @@ //! A group of attributes that can be attached to Rust code in order //! to generate a clippy lint detecting said code automatically. -use crate::utils::{get_attr, higher}; +use crate::utils::get_attr; use rustc_ast::ast::{Attribute, LitFloatType, LitKind}; use rustc_ast::walk_list; use rustc_data_structures::fx::FxHashMap; @@ -201,32 +201,6 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { #[allow(clippy::too_many_lines)] fn visit_expr(&mut self, expr: &Expr<'_>) { - // handle if desugarings - // TODO add more desugarings here - if let Some((cond, then, opt_else)) = higher::if_block(&expr) { - let cond_pat = self.next("cond"); - let then_pat = self.next("then"); - if let Some(else_) = opt_else { - let else_pat = self.next("else_"); - println!( - " if let Some((ref {}, ref {}, Some({}))) = higher::if_block(&{});", - cond_pat, then_pat, else_pat, self.current - ); - self.current = else_pat; - self.visit_expr(else_); - } else { - println!( - " if let Some((ref {}, ref {}, None)) = higher::if_block(&{});", - cond_pat, then_pat, self.current - ); - } - self.current = cond_pat; - self.visit_expr(cond); - self.current = then_pat; - self.visit_expr(then); - return; - } - print!(" if let ExprKind::"); let current = format!("{}.kind", self.current); match expr.kind { @@ -351,6 +325,25 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { self.current = body_pat; self.visit_block(body); }, + ExprKind::If(ref cond, ref then, ref opt_else) => { + let cond_pat = self.next("cond"); + let then_pat = self.next("then"); + if let Some(ref else_) = *opt_else { + let else_pat = self.next("else_"); + println!( + "If(ref {}, ref {}, Some(ref {})) = {};", + cond_pat, then_pat, else_pat, current + ); + self.current = else_pat; + self.visit_expr(else_); + } else { + println!("If(ref {}, ref {}, None) = {};", cond_pat, then_pat, current); + } + self.current = cond_pat; + self.visit_expr(cond); + self.current = then_pat; + self.visit_expr(then); + }, ExprKind::Match(ref expr, ref arms, desugaring) => { let des = desugaring_name(desugaring); let expr_pat = self.next("expr"); @@ -743,10 +736,6 @@ fn desugaring_name(des: hir::MatchSource) -> String { contains_else_clause ), hir::MatchSource::IfLetGuardDesugar => "MatchSource::IfLetGuardDesugar".to_string(), - hir::MatchSource::IfDesugar { contains_else_clause } => format!( - "MatchSource::IfDesugar {{ contains_else_clause: {} }}", - contains_else_clause - ), hir::MatchSource::AwaitDesugar => "MatchSource::AwaitDesugar".to_string(), } } diff --git a/clippy_lints/src/utils/eager_or_lazy.rs b/clippy_lints/src/utils/eager_or_lazy.rs index 8fe5ddee1ca8..2f157c5030f4 100644 --- a/clippy_lints/src/utils/eager_or_lazy.rs +++ b/clippy_lints/src/utils/eager_or_lazy.rs @@ -62,6 +62,7 @@ fn identify_some_pure_patterns(expr: &Expr<'_>) -> bool { | ExprKind::Type(..) | ExprKind::DropTemps(..) | ExprKind::Loop(..) + | ExprKind::If(..) | ExprKind::Match(..) | ExprKind::Closure(..) | ExprKind::Block(..) diff --git a/clippy_lints/src/utils/higher.rs b/clippy_lints/src/utils/higher.rs index 01ffac5b5599..9b3585865da3 100644 --- a/clippy_lints/src/utils/higher.rs +++ b/clippy_lints/src/utils/higher.rs @@ -170,33 +170,6 @@ pub fn while_loop<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> Option<(&'tcx hir::Expr< None } -/// Recover the essential nodes of a desugared if block -/// `if cond { then } else { els }` becomes `(cond, then, Some(els))` -pub fn if_block<'tcx>( - expr: &'tcx hir::Expr<'tcx>, -) -> Option<( - &'tcx hir::Expr<'tcx>, - &'tcx hir::Expr<'tcx>, - Option<&'tcx hir::Expr<'tcx>>, -)> { - if let hir::ExprKind::Match(ref cond, ref arms, hir::MatchSource::IfDesugar { contains_else_clause }) = expr.kind { - let cond = if let hir::ExprKind::DropTemps(ref cond) = cond.kind { - cond - } else { - panic!("If block desugar must contain DropTemps"); - }; - let then = &arms[0].body; - let els = if contains_else_clause { - Some(&*arms[1].body) - } else { - None - }; - Some((cond, then, els)) - } else { - None - } -} - /// Represent the pre-expansion arguments of a `vec!` invocation. pub enum VecArgs<'a> { /// `vec![elem; len]` @@ -267,12 +240,11 @@ pub fn extract_assert_macro_args<'tcx>(e: &'tcx Expr<'tcx>) -> Option SpanlessEq<'a, 'tcx> { (&ExprKind::Index(ref la, ref li), &ExprKind::Index(ref ra, ref ri)) => { self.eq_expr(la, ra) && self.eq_expr(li, ri) }, + (&ExprKind::If(ref lc, ref lt, ref le), &ExprKind::If(ref rc, ref rt, ref re)) => { + self.eq_expr(lc, rc) && self.eq_expr(&**lt, &**rt) && both(le, re, |l, r| self.eq_expr(l, r)) + }, (&ExprKind::Lit(ref l), &ExprKind::Lit(ref r)) => l.node == r.node, (&ExprKind::Loop(ref lb, ref ll, ref lls), &ExprKind::Loop(ref rb, ref rl, ref rls)) => { lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.as_str() == r.ident.as_str()) @@ -564,6 +567,15 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_name(i.ident.name); } }, + ExprKind::If(ref cond, ref then, ref else_opt) => { + let c: fn(_, _, _) -> _ = ExprKind::If; + c.hash(&mut self.s); + self.hash_expr(cond); + self.hash_expr(&**then); + if let Some(ref e) = *else_opt { + self.hash_expr(e); + } + }, ExprKind::Match(ref e, arms, ref s) => { self.hash_expr(e); diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 5d946e4bd495..71c11788d93a 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -213,6 +213,15 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { hir::ExprKind::Loop(..) => { println!("{}Loop", ind); }, + hir::ExprKind::If(ref cond, _, ref else_opt) => { + println!("{}If", ind); + println!("{}condition:", ind); + print_expr(cx, cond, indent + 1); + if let Some(ref els) = *else_opt { + println!("{}else:", ind); + print_expr(cx, els, indent + 1); + } + }, hir::ExprKind::Match(ref cond, _, ref source) => { println!("{}Match", ind); println!("{}condition:", ind); diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 1c68e837c4ab..bd103246e4ef 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1405,7 +1405,7 @@ pub fn if_sequence<'tcx>( let mut conds = SmallVec::new(); let mut blocks: SmallVec<[&Block<'_>; 1]> = SmallVec::new(); - while let Some((ref cond, ref then_expr, ref else_expr)) = higher::if_block(&expr) { + while let ExprKind::If(ref cond, ref then_expr, ref else_expr) = expr.kind { conds.push(&**cond); if let ExprKind::Block(ref block, _) = then_expr.kind { blocks.push(block); @@ -1434,11 +1434,11 @@ pub fn parent_node_is_if_expr(expr: &Expr<'_>, cx: &LateContext<'_>) -> bool { let map = cx.tcx.hir(); let parent_id = map.get_parent_node(expr.hir_id); let parent_node = map.get(parent_id); - - match parent_node { - Node::Expr(e) => higher::if_block(&e).is_some(), - Node::Arm(e) => higher::if_block(&e.body).is_some(), - _ => false, + if let Node::Expr(Expr { kind: ExprKind::If(_, _, _), .. }) = parent_node { + true + } + else { + false } } diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index 1fcd41e4dbfe..03678db575f0 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -103,6 +103,7 @@ impl<'a> Sugg<'a> { match expr.kind { hir::ExprKind::AddrOf(..) | hir::ExprKind::Box(..) + | hir::ExprKind::If(..) | hir::ExprKind::Closure(..) | hir::ExprKind::Unary(..) | hir::ExprKind::Match(..) => Sugg::MaybeParen(snippet), diff --git a/clippy_lints/src/utils/visitors.rs b/clippy_lints/src/utils/visitors.rs index 28b3e79d7a6d..b769a18802b6 100644 --- a/clippy_lints/src/utils/visitors.rs +++ b/clippy_lints/src/utils/visitors.rs @@ -101,6 +101,13 @@ where } } else { match expr.kind { + hir::ExprKind::If(cond, then, else_opt) => { + self.inside_stmt(true).visit_expr(cond); + self.visit_expr(then); + if let Some(el) = else_opt { + self.visit_expr(el); + } + } hir::ExprKind::Match(cond, arms, _) => { self.inside_stmt(true).visit_expr(cond); for arm in arms { diff --git a/tests/ui/author/if.stdout b/tests/ui/author/if.stdout index c18d035953e5..cac64a3f40b4 100644 --- a/tests/ui/author/if.stdout +++ b/tests/ui/author/if.stdout @@ -1,7 +1,7 @@ if_chain! { if let StmtKind::Local(ref local) = stmt.kind; if let Some(ref init) = local.init; - if let Some((ref cond, ref then, Some(else_))) = higher::if_block(&init); + if let ExprKind::If(ref cond, ref then, Some(ref else_)) = init.kind; if let ExprKind::Block(ref block) = else_.kind; if let Some(trailing_expr) = &block.expr; if block.stmts.len() == 1; diff --git a/tests/ui/panic_in_result_fn_assertions.stderr b/tests/ui/panic_in_result_fn_assertions.stderr index 86f61ad718a9..a17f043737d4 100644 --- a/tests/ui/panic_in_result_fn_assertions.stderr +++ b/tests/ui/panic_in_result_fn_assertions.stderr @@ -14,7 +14,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn_assertions.rs:9:9 | LL | assert!(x == 5, "wrong argument"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` From 82b770698fed2578dcd497f418d36c72960070d1 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 19 Dec 2020 23:38:22 +0300 Subject: [PATCH 0161/1222] ast: Remove some indirection layers from values in key-value attributes --- clippy_lints/src/utils/ast_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/ast_utils.rs b/clippy_lints/src/utils/ast_utils.rs index 5aed676fceb2..eac5d0aa3ee9 100644 --- a/clippy_lints/src/utils/ast_utils.rs +++ b/clippy_lints/src/utils/ast_utils.rs @@ -556,7 +556,7 @@ pub fn eq_mac_args(l: &MacArgs, r: &MacArgs) -> bool { match (l, r) { (Empty, Empty) => true, (Delimited(_, ld, lts), Delimited(_, rd, rts)) => ld == rd && lts.eq_unspanned(rts), - (Eq(_, lts), Eq(_, rts)) => lts.eq_unspanned(rts), + (Eq(_, lt), Eq(_, rt)) => lt.kind == rt.kind, _ => false, } } From d8e7fcfd82f211eed09163d4f35d7f59bbcb9ff9 Mon Sep 17 00:00:00 2001 From: Patryk Wychowaniec Date: Sat, 2 Jan 2021 19:45:11 +0100 Subject: [PATCH 0162/1222] Rework diagnostics for wrong number of generic args --- clippy_lints/src/utils/hir_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index a8fbb2ffaf0b..1ec92500ce82 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -744,7 +744,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } for segment in path.segments { segment.ident.name.hash(&mut self.s); - self.hash_generic_args(segment.generic_args().args); + self.hash_generic_args(segment.args().args); } }, QPath::TypeRelative(ref ty, ref segment) => { From 004fe91c510ebb741ee78a07ccb33695d8a1ad0d Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 22 Nov 2020 17:46:21 -0500 Subject: [PATCH 0163/1222] Separate out a `hir::Impl` struct This makes it possible to pass the `Impl` directly to functions, instead of having to pass each of the many fields one at a time. It also simplifies matches in many cases. --- clippy_lints/src/copy_iterator.rs | 6 +++--- clippy_lints/src/derive.rs | 6 +++--- clippy_lints/src/doc.rs | 7 ++----- clippy_lints/src/escape.rs | 4 ++-- clippy_lints/src/fallible_impl_from.rs | 4 ++-- clippy_lints/src/inherent_impl.rs | 6 +++--- clippy_lints/src/len_zero.rs | 6 +++--- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- clippy_lints/src/new_without_default.rs | 4 ++-- clippy_lints/src/non_copy_const.rs | 8 ++++---- clippy_lints/src/partialeq_ne_impl.rs | 4 ++-- clippy_lints/src/pass_by_ref_or_value.rs | 4 ++-- clippy_lints/src/ptr.rs | 4 ++-- clippy_lints/src/serde_api.rs | 6 +++--- clippy_lints/src/to_string_in_display.rs | 4 ++-- clippy_lints/src/types.rs | 17 ++++++----------- clippy_lints/src/unnecessary_wraps.rs | 4 ++-- clippy_lints/src/unused_self.rs | 4 ++-- clippy_lints/src/use_self.rs | 8 ++++---- clippy_lints/src/utils/inspector.rs | 6 +++--- clippy_lints/src/utils/internal_lints.rs | 4 ++-- clippy_lints/src/utils/mod.rs | 6 +++--- clippy_lints/src/zero_sized_map_values.rs | 2 +- 24 files changed, 61 insertions(+), 69 deletions(-) diff --git a/clippy_lints/src/copy_iterator.rs b/clippy_lints/src/copy_iterator.rs index 349402453226..a7aa2cb35c1c 100644 --- a/clippy_lints/src/copy_iterator.rs +++ b/clippy_lints/src/copy_iterator.rs @@ -1,5 +1,5 @@ use crate::utils::{is_copy, match_path, paths, span_lint_and_note}; -use rustc_hir::{Item, ItemKind}; +use rustc_hir::{Item, ItemKind, Impl}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -33,10 +33,10 @@ declare_lint_pass!(CopyIterator => [COPY_ITERATOR]); impl<'tcx> LateLintPass<'tcx> for CopyIterator { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Impl { + if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), .. - } = item.kind + }) = item.kind { let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id)); diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index c75efc6e99f8..b55f59f021df 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -7,7 +7,7 @@ use if_chain::if_chain; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, NestedVisitorMap, Visitor}; use rustc_hir::{ - BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, TraitRef, UnsafeSource, Unsafety, + BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, Impl, TraitRef, UnsafeSource, Unsafety, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::map::Map; @@ -164,10 +164,10 @@ declare_lint_pass!(Derive => [ impl<'tcx> LateLintPass<'tcx> for Derive { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Impl { + if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), .. - } = item.kind + }) = item.kind { let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id)); let is_automatically_derived = is_automatically_derived(&*item.attrs); diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index aba655327959..f518da55cd76 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -182,11 +182,8 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id)); } }, - hir::ItemKind::Impl { - of_trait: ref trait_ref, - .. - } => { - self.in_trait_impl = trait_ref.is_some(); + hir::ItemKind::Impl(ref impl_) => { + self.in_trait_impl = impl_.of_trait.is_some(); }, _ => {}, } diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index d2dcb3e5c464..550876978129 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -1,5 +1,5 @@ use rustc_hir::intravisit; -use rustc_hir::{self, Body, FnDecl, HirId, HirIdSet, ItemKind, Node}; +use rustc_hir::{self, Body, FnDecl, HirId, HirIdSet, ItemKind, Impl, Node}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, Ty}; @@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { let parent_node = cx.tcx.hir().find(parent_id); if let Some(Node::Item(item)) = parent_node { - if let ItemKind::Impl { of_trait: Some(_), .. } = item.kind { + if let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = item.kind { return; } } diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 509a4a4e15f6..9f389c8d2f9e 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -57,11 +57,11 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom { // check for `impl From for ..` let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id); if_chain! { - if let hir::ItemKind::Impl{ items: impl_items, .. } = item.kind; + if let hir::ItemKind::Impl(impl_) = &item.kind; if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id); if match_def_path(cx, impl_trait_ref.def_id, &FROM_TRAIT); then { - lint_impl_body(cx, item.span, impl_items); + lint_impl_body(cx, item.span, impl_.items); } } } diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index 4e6bb6047854..e287aecb044f 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -2,7 +2,7 @@ use crate::utils::{in_macro, span_lint_and_then}; use rustc_data_structures::fx::FxHashMap; -use rustc_hir::{def_id, Crate, Item, ItemKind}; +use rustc_hir::{def_id, Crate, Item, ItemKind, Impl}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; @@ -49,11 +49,11 @@ impl_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]); impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Impl { + if let ItemKind::Impl(Impl { ref generics, of_trait: None, .. - } = item.kind + }) = item.kind { // Remember for each inherent implementation encountered its span and generics // but filter out implementations that have generic params (type or lifetime) diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 6fe533510904..5474b30bdec8 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -3,7 +3,7 @@ use rustc_ast::ast::LitKind; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; -use rustc_hir::{AssocItemKind, BinOpKind, Expr, ExprKind, ImplItemRef, Item, ItemKind, TraitItemRef}; +use rustc_hir::{AssocItemKind, BinOpKind, Expr, ExprKind, ImplItemRef, Item, ItemKind, Impl, TraitItemRef}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -115,11 +115,11 @@ impl<'tcx> LateLintPass<'tcx> for LenZero { match item.kind { ItemKind::Trait(_, _, _, _, ref trait_items) => check_trait_items(cx, item, trait_items), - ItemKind::Impl { + ItemKind::Impl(Impl { of_trait: None, items: ref impl_items, .. - } => check_impl_items(cx, item, impl_items), + }) => check_impl_items(cx, item, impl_items), _ => (), } } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index e99fe1b97ff6..2658c365e135 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1626,7 +1626,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { let self_ty = cx.tcx.type_of(def_id); // if this impl block implements a trait, lint in trait definition instead - if let hir::ItemKind::Impl { of_trait: Some(_), .. } = item.kind { + if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind { return; } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 5043b7b1fc3c..a435f86bfd8d 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -8,7 +8,7 @@ use rustc_ast::ast::Attribute; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir::intravisit::FnKind; -use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, ItemKind, Node, PatKind, QPath, TyKind}; +use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, ItemKind, Impl, Node, PatKind, QPath, TyKind}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, TypeFoldable}; @@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { if matches!( item.kind, - ItemKind::Impl { of_trait: Some(_), .. } | ItemKind::Trait(..) + ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) ) { return; } diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 68fdd0eb269e..bd3dac663fe2 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -60,9 +60,9 @@ impl_lint_pass!(NewWithoutDefault => [NEW_WITHOUT_DEFAULT]); impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { #[allow(clippy::too_many_lines)] fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { - if let hir::ItemKind::Impl { + if let hir::ItemKind::Impl(hir::Impl { of_trait: None, items, .. - } = item.kind + }) = item.kind { for assoc_item in items { if let hir::AssocItemKind::Fn { has_self: false } = assoc_item.kind { diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 6b0d198edcff..3a9aa6ced03b 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -7,7 +7,7 @@ use std::ptr; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{ - BodyId, Expr, ExprKind, HirId, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind, UnOp, + BodyId, Expr, ExprKind, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind, UnOp, }; use rustc_infer::traits::specialization_graph; use rustc_lint::{LateContext, LateLintPass, Lint}; @@ -275,10 +275,10 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { let item = cx.tcx.hir().expect_item(item_hir_id); match &item.kind { - ItemKind::Impl { + ItemKind::Impl(Impl { of_trait: Some(of_trait_ref), .. - } => { + }) => { if_chain! { // Lint a trait impl item only when the definition is a generic type, // assuming a assoc const is not meant to be a interior mutable type. @@ -317,7 +317,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { } } }, - ItemKind::Impl { of_trait: None, .. } => { + ItemKind::Impl(Impl { of_trait: None, .. }) => { let ty = hir_ty_to_ty(cx.tcx, hir_ty); // Normalize assoc types originated from generic params. let normalized = cx.tcx.normalize_erasing_regions(cx.param_env, ty); diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index ceecc8dbc06f..04b6e5d58478 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -1,6 +1,6 @@ use crate::utils::{is_automatically_derived, span_lint_hir}; use if_chain::if_chain; -use rustc_hir::{Item, ItemKind}; +use rustc_hir::{Item, ItemKind, Impl}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; @@ -34,7 +34,7 @@ declare_lint_pass!(PartialEqNeImpl => [PARTIALEQ_NE_IMPL]); impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if_chain! { - if let ItemKind::Impl{ of_trait: Some(ref trait_ref), items: impl_items, .. } = item.kind; + if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), items: impl_items, .. }) = item.kind; if !is_automatically_derived(&*item.attrs); if let Some(eq_trait) = cx.tcx.lang_items().eq_trait(); if trait_ref.path.res.def_id() == eq_trait; diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 6a17d654ac94..7814065e31a1 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -6,7 +6,7 @@ use rustc_ast::attr; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::intravisit::FnKind; -use rustc_hir::{BindingAnnotation, Body, FnDecl, HirId, ItemKind, MutTy, Mutability, Node, PatKind}; +use rustc_hir::{BindingAnnotation, Body, FnDecl, HirId, ItemKind, MutTy, Mutability, Node, PatKind, Impl}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -246,7 +246,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { if matches!( item.kind, - ItemKind::Impl { of_trait: Some(_), .. } | ItemKind::Trait(..) + ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) ) { return; } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index c494a7136313..b832add009f8 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -8,7 +8,7 @@ use crate::utils::{ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{ - BinOpKind, BodyId, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, HirId, ImplItem, ImplItemKind, Item, ItemKind, + BinOpKind, BodyId, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, HirId, ImplItem, ImplItemKind, Item, ItemKind, Impl, Lifetime, MutTy, Mutability, Node, PathSegment, QPath, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, }; use rustc_lint::{LateContext, LateLintPass}; @@ -132,7 +132,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { if let ImplItemKind::Fn(ref sig, body_id) = item.kind { let parent_item = cx.tcx.hir().get_parent_item(item.hir_id); if let Some(Node::Item(it)) = cx.tcx.hir().find(parent_item) { - if let ItemKind::Impl { of_trait: Some(_), .. } = it.kind { + if let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = it.kind { return; // ignore trait impls } } diff --git a/clippy_lints/src/serde_api.rs b/clippy_lints/src/serde_api.rs index 339a7cf3bf5d..ca4fd9f35597 100644 --- a/clippy_lints/src/serde_api.rs +++ b/clippy_lints/src/serde_api.rs @@ -1,5 +1,5 @@ use crate::utils::{get_trait_def_id, paths, span_lint}; -use rustc_hir::{Item, ItemKind}; +use rustc_hir::{Item, ItemKind, Impl}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -22,11 +22,11 @@ declare_lint_pass!(SerdeAPI => [SERDE_API_MISUSE]); impl<'tcx> LateLintPass<'tcx> for SerdeAPI { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Impl { + if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), items, .. - } = item.kind + }) = item.kind { let did = trait_ref.path.res.def_id(); if let Some(visit_did) = get_trait_def_id(cx, &paths::SERDE_DE_VISITOR) { diff --git a/clippy_lints/src/to_string_in_display.rs b/clippy_lints/src/to_string_in_display.rs index 006d7a3a12d9..675eaf4277a4 100644 --- a/clippy_lints/src/to_string_in_display.rs +++ b/clippy_lints/src/to_string_in_display.rs @@ -1,7 +1,7 @@ use crate::utils::{match_def_path, match_trait_method, paths, qpath_res, span_lint}; use if_chain::if_chain; use rustc_hir::def::Res; -use rustc_hir::{Expr, ExprKind, HirId, ImplItem, ImplItemKind, Item, ItemKind}; +use rustc_hir::{Expr, ExprKind, HirId, ImplItem, ImplItemKind, Item, ItemKind, Impl}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -111,7 +111,7 @@ impl LateLintPass<'_> for ToStringInDisplay { fn is_display_impl(cx: &LateContext<'_>, item: &Item<'_>) -> bool { if_chain! { - if let ItemKind::Impl { of_trait: Some(trait_ref), .. } = &item.kind; + if let ItemKind::Impl(Impl { of_trait: Some(trait_ref), .. }) = &item.kind; if let Some(did) = trait_ref.trait_def_id(); then { match_def_path(cx, did, &paths::DISPLAY_TRAIT) diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index fd74783335d5..2696c5e781ab 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -258,7 +258,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { fn check_fn(&mut self, cx: &LateContext<'_>, _: FnKind<'_>, decl: &FnDecl<'_>, _: &Body<'_>, _: Span, id: HirId) { // Skip trait implementations; see issue #605. if let Some(hir::Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_item(id)) { - if let ItemKind::Impl { of_trait: Some(_), .. } = item.kind { + if let ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind { return; } } @@ -2558,21 +2558,16 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { } match item.kind { - ItemKind::Impl { - ref generics, - self_ty: ref ty, - ref items, - .. - } => { + ItemKind::Impl(ref impl_) => { let mut vis = ImplicitHasherTypeVisitor::new(cx); - vis.visit_ty(ty); + vis.visit_ty(impl_.self_ty); for target in &vis.found { if differing_macro_contexts(item.span, target.span()) { return; } - let generics_suggestion_span = generics.span.substitute_dummy({ + let generics_suggestion_span = impl_.generics.span.substitute_dummy({ let pos = snippet_opt(cx, item.span.until(target.span())) .and_then(|snip| Some(item.span.lo() + BytePos(snip.find("impl")? as u32 + 4))); if let Some(pos) = pos { @@ -2583,7 +2578,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { }); let mut ctr_vis = ImplicitHasherConstructorVisitor::new(cx, target); - for item in items.iter().map(|item| cx.tcx.hir().impl_item(item.id)) { + for item in impl_.items.iter().map(|item| cx.tcx.hir().impl_item(item.id)) { ctr_vis.visit_impl_item(item); } @@ -2596,7 +2591,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { target.type_name() ), move |diag| { - suggestion(cx, diag, generics.span, generics_suggestion_span, target, ctr_vis); + suggestion(cx, diag, impl_.generics.span, generics_suggestion_span, target, ctr_vis); }, ); } diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index 5b9a80f92db6..07cd752184bb 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -5,7 +5,7 @@ use crate::utils::{ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; -use rustc_hir::{Body, ExprKind, FnDecl, HirId, ItemKind, Node}; +use rustc_hir::{Body, ExprKind, FnDecl, HirId, ItemKind, Impl, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::subst::GenericArgKind; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { if matches!( item.kind, - ItemKind::Impl { of_trait: Some(_), .. } | ItemKind::Trait(..) + ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) ) { return; } diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index da7517125c13..a61717943110 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -1,7 +1,7 @@ use if_chain::if_chain; use rustc_hir::def::Res; use rustc_hir::intravisit::{walk_path, NestedVisitorMap, Visitor}; -use rustc_hir::{HirId, ImplItem, ImplItemKind, ItemKind, Path}; +use rustc_hir::{HirId, ImplItem, ImplItemKind, ItemKind, Impl, Path}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf { let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); let assoc_item = cx.tcx.associated_item(def_id); if_chain! { - if let ItemKind::Impl { of_trait: None, .. } = parent_item.kind; + if let ItemKind::Impl(Impl { of_trait: None, .. }) = parent_item.kind; if assoc_item.fn_has_self_parameter; if let ImplItemKind::Fn(.., body_id) = &impl_item.kind; let body = cx.tcx.hir().body(*body_id); diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 3b23f885e08d..b82ea66190fc 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -181,8 +181,8 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { return; } if_chain! { - if let ItemKind::Impl{ self_ty: ref item_type, items: refs, .. } = item.kind; - if let TyKind::Path(QPath::Resolved(_, ref item_path)) = item_type.kind; + if let ItemKind::Impl(impl_) = &item.kind; + if let TyKind::Path(QPath::Resolved(_, ref item_path)) = impl_.self_ty.kind; then { let parameters = &item_path.segments.last().expect(SEGMENTS_MSG).args; let should_check = parameters.as_ref().map_or( @@ -200,7 +200,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { let impl_trait_ref = cx.tcx.impl_trait_ref(impl_def_id); if let Some(impl_trait_ref) = impl_trait_ref { - for impl_item_ref in refs { + for impl_item_ref in impl_.items { let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id); if let ImplItemKind::Fn(FnSig{ decl: impl_decl, .. }, impl_body_id) = &impl_item.kind { @@ -213,7 +213,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { } } } else { - for impl_item_ref in refs { + for impl_item_ref in impl_.items { let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id); visitor.visit_impl_item(impl_item); } diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 5d946e4bd495..a02c0a3f44d7 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -423,13 +423,13 @@ fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) { hir::ItemKind::TraitAlias(..) => { println!("trait alias"); }, - hir::ItemKind::Impl { + hir::ItemKind::Impl(hir::Impl { of_trait: Some(ref _trait_ref), .. - } => { + }) => { println!("trait impl"); }, - hir::ItemKind::Impl { of_trait: None, .. } => { + hir::ItemKind::Impl(hir::Impl { of_trait: None, .. }) => { println!("impl"); }, } diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 9ba39f73ee88..407f06f48942 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -352,11 +352,11 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { } else if is_expn_of(item.span, "impl_lint_pass").is_some() || is_expn_of(item.span, "declare_lint_pass").is_some() { - if let hir::ItemKind::Impl { + if let hir::ItemKind::Impl(hir::Impl { of_trait: None, items: ref impl_item_refs, .. - } = item.kind + }) = item.kind { let mut collector = LintCollector { output: &mut self.registered_lints, diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 1c68e837c4ab..87f99019d72d 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -439,8 +439,8 @@ pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio if_chain! { if parent_impl != hir::CRATE_HIR_ID; if let hir::Node::Item(item) = cx.tcx.hir().get(parent_impl); - if let hir::ItemKind::Impl{ of_trait: trait_ref, .. } = &item.kind; - then { return trait_ref.as_ref(); } + if let hir::ItemKind::Impl(impl_) = &item.kind; + then { return impl_.of_trait.as_ref(); } } None } @@ -1530,7 +1530,7 @@ pub fn is_no_std_crate(krate: &Crate<'_>) -> bool { /// ``` pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool { if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { - matches!(item.kind, ItemKind::Impl { of_trait: Some(_), .. }) + matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) } else { false } diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 1d5fa8d06a99..9761e822a7a0 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -62,7 +62,7 @@ impl LateLintPass<'_> for ZeroSizedMapValues { fn in_trait_impl(cx: &LateContext<'_>, hir_id: HirId) -> bool { let parent_id = cx.tcx.hir().get_parent_item(hir_id); if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_item(parent_id)) { - if let ItemKind::Impl { of_trait: Some(_), .. } = item.kind { + if let ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind { return true; } } From 3e50ddc0de93e102cac32c48bdb80df6c4beb296 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Sat, 16 Jan 2021 17:30:31 +0100 Subject: [PATCH 0164/1222] Deprecate unknown_clippy_lints This is now handled by unknown_lints --- clippy_lints/src/attrs.rs | 72 +--------------------------- clippy_lints/src/deprecated_lints.rs | 13 +++++ clippy_lints/src/lib.rs | 7 +-- tests/ui/deprecated.rs | 1 + tests/ui/deprecated.stderr | 8 +++- tests/ui/unknown_clippy_lints.stderr | 40 +++++++++------- 6 files changed, 50 insertions(+), 91 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 3edbe723922f..7607394b2fe9 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -10,11 +10,10 @@ use rustc_errors::Applicability; use rustc_hir::{ Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind, }; -use rustc_lint::{CheckLintNameResult, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::lev_distance::find_best_match_for_name; use rustc_span::source_map::Span; use rustc_span::sym; use rustc_span::symbol::{Symbol, SymbolStr}; @@ -156,33 +155,6 @@ declare_clippy_lint! { "empty line after outer attribute" } -declare_clippy_lint! { - /// **What it does:** Checks for `allow`/`warn`/`deny`/`forbid` attributes with scoped clippy - /// lints and if those lints exist in clippy. If there is an uppercase letter in the lint name - /// (not the tool name) and a lowercase version of this lint exists, it will suggest to lowercase - /// the lint name. - /// - /// **Why is this bad?** A lint attribute with a mistyped lint name won't have an effect. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// Bad: - /// ```rust - /// #![warn(if_not_els)] - /// #![deny(clippy::All)] - /// ``` - /// - /// Good: - /// ```rust - /// #![warn(if_not_else)] - /// #![deny(clippy::all)] - /// ``` - pub UNKNOWN_CLIPPY_LINTS, - style, - "unknown_lints for scoped Clippy lints" -} - declare_clippy_lint! { /// **What it does:** Checks for `warn`/`deny`/`forbid` attributes targeting the whole clippy::restriction category. /// @@ -272,7 +244,6 @@ declare_lint_pass!(Attributes => [ INLINE_ALWAYS, DEPRECATED_SEMVER, USELESS_ATTRIBUTE, - UNKNOWN_CLIPPY_LINTS, BLANKET_CLIPPY_RESTRICTION_LINTS, ]); @@ -409,48 +380,9 @@ fn extract_clippy_lint(lint: &NestedMetaItem) -> Option { } fn check_clippy_lint_names(cx: &LateContext<'_>, ident: &str, items: &[NestedMetaItem]) { - let lint_store = cx.lints(); for lint in items { if let Some(lint_name) = extract_clippy_lint(lint) { - if let CheckLintNameResult::Tool(Err((None, _))) = lint_store.check_lint_name(&lint_name, Some(sym::clippy)) - { - span_lint_and_then( - cx, - UNKNOWN_CLIPPY_LINTS, - lint.span(), - &format!("unknown clippy lint: clippy::{}", lint_name), - |diag| { - let name_lower = lint_name.to_lowercase(); - let symbols = lint_store - .get_lints() - .iter() - .map(|l| Symbol::intern(&l.name_lower())) - .collect::>(); - let sugg = find_best_match_for_name( - &symbols, - Symbol::intern(&format!("clippy::{}", name_lower)), - None, - ); - if lint_name.chars().any(char::is_uppercase) - && lint_store.find_lints(&format!("clippy::{}", name_lower)).is_ok() - { - diag.span_suggestion( - lint.span(), - "lowercase the lint name", - format!("clippy::{}", name_lower), - Applicability::MachineApplicable, - ); - } else if let Some(sugg) = sugg { - diag.span_suggestion( - lint.span(), - "did you mean", - sugg.to_string(), - Applicability::MachineApplicable, - ); - } - }, - ); - } else if lint_name == "restriction" && ident != "allow" { + if lint_name == "restriction" && ident != "allow" { span_lint_and_help( cx, BLANKET_CLIPPY_RESTRICTION_LINTS, diff --git a/clippy_lints/src/deprecated_lints.rs b/clippy_lints/src/deprecated_lints.rs index bec0c9f93a0d..47b3cc3ad303 100644 --- a/clippy_lints/src/deprecated_lints.rs +++ b/clippy_lints/src/deprecated_lints.rs @@ -163,6 +163,19 @@ declare_deprecated_lint! { } declare_deprecated_lint! { + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** This lint has been uplifted to rustc and is now called + /// `panic_fmt`. pub PANIC_PARAMS, "this lint has been uplifted to rustc and is now called `panic_fmt`" } + +declare_deprecated_lint! { + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** This lint has been integrated into the `unknown_lints` + /// rustc lint. + pub UNKNOWN_CLIPPY_LINTS, + "this lint has been integrated into the `unknown_lints` rustc lint" +} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 35b057d7b6a4..aaa17561f06d 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -500,6 +500,10 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: "clippy::panic_params", "this lint has been uplifted to rustc and is now called `panic_fmt`", ); + store.register_removed( + "clippy::unknown_clippy_lints", + "this lint has been integrated into the `unknown_lints` rustc lint", + ); // end deprecated lints, do not remove this comment, it’s used in `update_lints` // begin register lints, do not remove this comment, it’s used in `update_lints` @@ -541,7 +545,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &attrs::EMPTY_LINE_AFTER_OUTER_ATTR, &attrs::INLINE_ALWAYS, &attrs::MISMATCHED_TARGET_OS, - &attrs::UNKNOWN_CLIPPY_LINTS, &attrs::USELESS_ATTRIBUTE, &await_holding_invalid::AWAIT_HOLDING_LOCK, &await_holding_invalid::AWAIT_HOLDING_REFCELL_REF, @@ -1375,7 +1378,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&attrs::DEPRECATED_CFG_ATTR), LintId::of(&attrs::DEPRECATED_SEMVER), LintId::of(&attrs::MISMATCHED_TARGET_OS), - LintId::of(&attrs::UNKNOWN_CLIPPY_LINTS), LintId::of(&attrs::USELESS_ATTRIBUTE), LintId::of(&bit_mask::BAD_BIT_MASK), LintId::of(&bit_mask::INEFFECTIVE_BIT_MASK), @@ -1650,7 +1652,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&assertions_on_constants::ASSERTIONS_ON_CONSTANTS), LintId::of(&assign_ops::ASSIGN_OP_PATTERN), LintId::of(&attrs::BLANKET_CLIPPY_RESTRICTION_LINTS), - LintId::of(&attrs::UNKNOWN_CLIPPY_LINTS), LintId::of(&blacklisted_name::BLACKLISTED_NAME), LintId::of(&blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS), LintId::of(&collapsible_if::COLLAPSIBLE_IF), diff --git a/tests/ui/deprecated.rs b/tests/ui/deprecated.rs index e1ee8dbca2c0..4a538021b98e 100644 --- a/tests/ui/deprecated.rs +++ b/tests/ui/deprecated.rs @@ -9,5 +9,6 @@ #[warn(clippy::drop_bounds)] #[warn(clippy::temporary_cstring_as_ptr)] #[warn(clippy::panic_params)] +#[warn(clippy::unknown_clippy_lints)] fn main() {} diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr index edbb891afe07..3429317498ed 100644 --- a/tests/ui/deprecated.stderr +++ b/tests/ui/deprecated.stderr @@ -66,11 +66,17 @@ error: lint `clippy::panic_params` has been removed: `this lint has been uplifte LL | #[warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ +error: lint `clippy::unknown_clippy_lints` has been removed: `this lint has been integrated into the `unknown_lints` rustc lint` + --> $DIR/deprecated.rs:12:8 + | +LL | #[warn(clippy::unknown_clippy_lints)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: lint `clippy::unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` --> $DIR/deprecated.rs:1:8 | LL | #[warn(clippy::unstable_as_slice)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 12 previous errors +error: aborting due to 13 previous errors diff --git a/tests/ui/unknown_clippy_lints.stderr b/tests/ui/unknown_clippy_lints.stderr index 1b859043bb53..94a667e58989 100644 --- a/tests/ui/unknown_clippy_lints.stderr +++ b/tests/ui/unknown_clippy_lints.stderr @@ -1,52 +1,58 @@ -error: unknown clippy lint: clippy::if_not_els +error: unknown lint: `clippy::All` + --> $DIR/unknown_clippy_lints.rs:5:10 + | +LL | #![allow(clippy::All)] + | ^^^^^^^^^^^ help: did you mean: `clippy::all` + | + = note: `-D unknown-lints` implied by `-D warnings` + +error: unknown lint: `clippy::CMP_NAN` + --> $DIR/unknown_clippy_lints.rs:6:9 + | +LL | #![warn(clippy::CMP_NAN)] + | ^^^^^^^^^^^^^^^ help: did you mean: `clippy::cmp_nan` + +error: unknown lint: `clippy::if_not_els` --> $DIR/unknown_clippy_lints.rs:9:8 | LL | #[warn(clippy::if_not_els)] | ^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::if_not_else` - | - = note: `-D clippy::unknown-clippy-lints` implied by `-D warnings` -error: unknown clippy lint: clippy::UNNecsaRy_cAst +error: unknown lint: `clippy::UNNecsaRy_cAst` --> $DIR/unknown_clippy_lints.rs:10:8 | LL | #[warn(clippy::UNNecsaRy_cAst)] | ^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::unnecessary_cast` -error: unknown clippy lint: clippy::useles_transute +error: unknown lint: `clippy::useles_transute` --> $DIR/unknown_clippy_lints.rs:11:8 | LL | #[warn(clippy::useles_transute)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::useless_transmute` -error: unknown clippy lint: clippy::dead_cod +error: unknown lint: `clippy::dead_cod` --> $DIR/unknown_clippy_lints.rs:13:8 | LL | #[warn(clippy::dead_cod)] | ^^^^^^^^^^^^^^^^ help: did you mean: `clippy::drop_copy` -error: unknown clippy lint: clippy::unused_colle +error: unknown lint: `clippy::unused_colle` --> $DIR/unknown_clippy_lints.rs:15:8 | LL | #[warn(clippy::unused_colle)] | ^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::unused_self` -error: unknown clippy lint: clippy::const_static_lifetim +error: unknown lint: `clippy::const_static_lifetim` --> $DIR/unknown_clippy_lints.rs:17:8 | LL | #[warn(clippy::const_static_lifetim)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::redundant_static_lifetimes` -error: unknown clippy lint: clippy::All +error: unknown lint: `clippy::All` --> $DIR/unknown_clippy_lints.rs:5:10 | LL | #![allow(clippy::All)] - | ^^^^^^^^^^^ help: lowercase the lint name: `clippy::all` - -error: unknown clippy lint: clippy::CMP_NAN - --> $DIR/unknown_clippy_lints.rs:6:9 - | -LL | #![warn(clippy::CMP_NAN)] - | ^^^^^^^^^^^^^^^ help: lowercase the lint name: `clippy::cmp_nan` + | ^^^^^^^^^^^ help: did you mean: `clippy::all` -error: aborting due to 8 previous errors +error: aborting due to 9 previous errors From 93ed13298ea2cc12d3188e521008fe99aaf62fcb Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Mon, 21 Dec 2020 22:49:03 -0500 Subject: [PATCH 0165/1222] Remove PredicateKind::Atom --- clippy_lints/src/needless_pass_by_value.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index a435f86bfd8d..ad50a6a0405f 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -115,13 +115,15 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { .filter(|p| !p.is_global()) .filter_map(|obligation| { // Note that we do not want to deal with qualified predicates here. - if let ty::PredicateKind::Atom(ty::PredicateAtom::Trait(pred, _)) = obligation.predicate.kind() { - if pred.def_id() == sized_trait { - return None; + let ty::PredicateKind::ForAll(binder) = obligation.predicate.kind(); + match binder.skip_binder() { + ty::PredicateAtom::Trait(pred, _) if !binder.has_escaping_bound_vars() => { + if pred.def_id() == sized_trait { + return None; + } + Some(pred) } - Some(pred) - } else { - None + _ => None, } }) .collect::>(); From b9c3a1380300da8930d1e0b5b00792c25f4a1f02 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Wed, 23 Dec 2020 16:36:23 -0500 Subject: [PATCH 0166/1222] Remove PredicateKind --- clippy_lints/src/needless_pass_by_value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index ad50a6a0405f..d2a3bd3921d2 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { .filter(|p| !p.is_global()) .filter_map(|obligation| { // Note that we do not want to deal with qualified predicates here. - let ty::PredicateKind::ForAll(binder) = obligation.predicate.kind(); + let binder = obligation.predicate.kind(); match binder.skip_binder() { ty::PredicateAtom::Trait(pred, _) if !binder.has_escaping_bound_vars() => { if pred.def_id() == sized_trait { From 9a4156d6df6b1fc723b23cc8aa4bc2a93e6fffa5 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Mon, 4 Jan 2021 01:58:33 -0500 Subject: [PATCH 0167/1222] Cleanup --- clippy_lints/src/needless_pass_by_value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index d2a3bd3921d2..9306b198051c 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { .filter(|p| !p.is_global()) .filter_map(|obligation| { // Note that we do not want to deal with qualified predicates here. - let binder = obligation.predicate.kind(); + let binder = obligation.predicate.bound_atom(); match binder.skip_binder() { ty::PredicateAtom::Trait(pred, _) if !binder.has_escaping_bound_vars() => { if pred.def_id() == sized_trait { From a7faf6707d68db9b4bc0538ece778c9d301d5eca Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Mon, 4 Jan 2021 15:30:22 -0500 Subject: [PATCH 0168/1222] Use pred not binder --- clippy_lints/src/needless_pass_by_value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 9306b198051c..6dc5654862b6 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -117,7 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { // Note that we do not want to deal with qualified predicates here. let binder = obligation.predicate.bound_atom(); match binder.skip_binder() { - ty::PredicateAtom::Trait(pred, _) if !binder.has_escaping_bound_vars() => { + ty::PredicateAtom::Trait(pred, _) if !pred.has_escaping_bound_vars() => { if pred.def_id() == sized_trait { return None; } From 7e61c9c1d7ba51e74f69abdde804d37d08bc8880 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Mon, 4 Jan 2021 16:50:36 -0500 Subject: [PATCH 0169/1222] Cleanup --- clippy_lints/src/needless_pass_by_value.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 6dc5654862b6..3e87ef03832d 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -115,8 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { .filter(|p| !p.is_global()) .filter_map(|obligation| { // Note that we do not want to deal with qualified predicates here. - let binder = obligation.predicate.bound_atom(); - match binder.skip_binder() { + match obligation.predicate.bound_atom().skip_binder() { ty::PredicateAtom::Trait(pred, _) if !pred.has_escaping_bound_vars() => { if pred.def_id() == sized_trait { return None; From b34a8666499eb193d59b47bbe411ae0b73d62c32 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Thu, 7 Jan 2021 11:20:28 -0500 Subject: [PATCH 0170/1222] Review changes --- clippy_lints/src/future_not_send.rs | 4 ++-- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 9 +++---- clippy_lints/src/unit_return_expecting_ord.rs | 6 ++--- clippy_lints/src/utils/mod.rs | 2 +- .../src/utils/qualify_min_const_fn.rs | 24 +++++++++---------- 6 files changed, 22 insertions(+), 25 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index f9697afe4052..a3a38fad9a37 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -4,7 +4,7 @@ use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::subst::Subst; -use rustc_middle::ty::{Opaque, PredicateAtom::Trait}; +use rustc_middle::ty::{Opaque, PredicateKind::Trait}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt; @@ -97,7 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { &obligation, ); if let Trait(trait_pred, _) = - obligation.predicate.skip_binders() + obligation.predicate.kind().skip_binder() { db.note(&format!( "`{}` doesn't implement `{}`", diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 6e8102790a59..f7231bba1750 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1697,7 +1697,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let ty::Opaque(def_id, _) = *ret_ty.kind() { // one of the associated types must be Self for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) { - if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() { + if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() { // walk the associated type and check for Self if contains_ty(projection_predicate.ty, self_ty) { return; diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 3e87ef03832d..3b71f1b46e2e 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -115,13 +115,10 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { .filter(|p| !p.is_global()) .filter_map(|obligation| { // Note that we do not want to deal with qualified predicates here. - match obligation.predicate.bound_atom().skip_binder() { - ty::PredicateAtom::Trait(pred, _) if !pred.has_escaping_bound_vars() => { - if pred.def_id() == sized_trait { - return None; - } + match obligation.predicate.kind().no_bound_vars() { + Some(ty::PredicateKind::Trait(pred, _)) if pred.def_id() != sized_trait => { Some(pred) - } + }, _ => None, } }) diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 2501635e7ef6..c6ae8b9b5983 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -4,7 +4,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; -use rustc_middle::ty::{GenericPredicates, PredicateAtom, ProjectionPredicate, TraitPredicate}; +use rustc_middle::ty::{GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{BytePos, Span}; @@ -42,7 +42,7 @@ fn get_trait_predicates_for_trait_id<'tcx>( let mut preds = Vec::new(); for (pred, _) in generics.predicates { if_chain! { - if let PredicateAtom::Trait(poly_trait_pred, _) = pred.skip_binders(); + if let PredicateKind::Trait(poly_trait_pred, _) = pred.kind().skip_binder(); let trait_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(poly_trait_pred)); if let Some(trait_def_id) = trait_id; if trait_def_id == trait_pred.trait_ref.def_id; @@ -60,7 +60,7 @@ fn get_projection_pred<'tcx>( pred: TraitPredicate<'tcx>, ) -> Option> { generics.predicates.iter().find_map(|(proj_pred, _)| { - if let ty::PredicateAtom::Projection(proj_pred) = proj_pred.skip_binders() { + if let ty::PredicateKind::Projection(proj_pred) = proj_pred.kind().skip_binder() { let projection_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(proj_pred)); if projection_pred.projection_ty.substs == pred.trait_ref.substs { return Some(projection_pred); diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 3e39a47f1963..4c707c4b9044 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1470,7 +1470,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { - if let ty::PredicateAtom::Trait(trait_predicate, _) = predicate.skip_binders() { + if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.kind().skip_binder() { if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() { return true; } diff --git a/clippy_lints/src/utils/qualify_min_const_fn.rs b/clippy_lints/src/utils/qualify_min_const_fn.rs index 7cb7d0a26b65..a482017afeb1 100644 --- a/clippy_lints/src/utils/qualify_min_const_fn.rs +++ b/clippy_lints/src/utils/qualify_min_const_fn.rs @@ -19,18 +19,18 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>) -> McfResult { loop { let predicates = tcx.predicates_of(current); for (predicate, _) in predicates.predicates { - match predicate.skip_binders() { - ty::PredicateAtom::RegionOutlives(_) - | ty::PredicateAtom::TypeOutlives(_) - | ty::PredicateAtom::WellFormed(_) - | ty::PredicateAtom::Projection(_) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => continue, - ty::PredicateAtom::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate), - ty::PredicateAtom::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate), - ty::PredicateAtom::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate), - ty::PredicateAtom::Trait(pred, _) => { + match predicate.kind().skip_binder() { + ty::PredicateKind::RegionOutlives(_) + | ty::PredicateKind::TypeOutlives(_) + | ty::PredicateKind::WellFormed(_) + | ty::PredicateKind::Projection(_) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => continue, + ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate), + ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate), + ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate), + ty::PredicateKind::Trait(pred, _) => { if Some(pred.def_id()) == tcx.lang_items().sized_trait() { continue; } From 92e4f33d3e7e39948b619f2a958d0fbcf7ce3bbc Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 17 Jan 2021 14:23:25 -0500 Subject: [PATCH 0171/1222] Fix formatting for removed lints - Don't add backticks for the reason a lint was removed. This is almost never a code block, and when it is the backticks should be in the reason itself. - Don't assume clippy is the only tool that needs to be checked for backwards compatibility --- tests/ui/deprecated.stderr | 26 +++++++++++++------------- tests/ui/deprecated_old.stderr | 8 ++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr index 3429317498ed..f361db6b147d 100644 --- a/tests/ui/deprecated.stderr +++ b/tests/ui/deprecated.stderr @@ -1,4 +1,4 @@ -error: lint `clippy::unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` +error: lint `clippy::unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7 --> $DIR/deprecated.rs:1:8 | LL | #[warn(clippy::unstable_as_slice)] @@ -6,73 +6,73 @@ LL | #[warn(clippy::unstable_as_slice)] | = note: `-D renamed-and-removed-lints` implied by `-D warnings` -error: lint `clippy::unstable_as_mut_slice` has been removed: ``Vec::as_mut_slice` has been stabilized in 1.7` +error: lint `clippy::unstable_as_mut_slice` has been removed: `Vec::as_mut_slice` has been stabilized in 1.7 --> $DIR/deprecated.rs:2:8 | LL | #[warn(clippy::unstable_as_mut_slice)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::misaligned_transmute` has been removed: `this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr` +error: lint `clippy::misaligned_transmute` has been removed: this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr --> $DIR/deprecated.rs:3:8 | LL | #[warn(clippy::misaligned_transmute)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::unused_collect` has been removed: ``collect` has been marked as #[must_use] in rustc and that covers all cases of this lint` +error: lint `clippy::unused_collect` has been removed: `collect` has been marked as #[must_use] in rustc and that covers all cases of this lint --> $DIR/deprecated.rs:4:8 | LL | #[warn(clippy::unused_collect)] | ^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::invalid_ref` has been removed: `superseded by rustc lint `invalid_value`` +error: lint `clippy::invalid_ref` has been removed: superseded by rustc lint `invalid_value` --> $DIR/deprecated.rs:5:8 | LL | #[warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::into_iter_on_array` has been removed: `this lint has been uplifted to rustc and is now called `array_into_iter`` +error: lint `clippy::into_iter_on_array` has been removed: this lint has been uplifted to rustc and is now called `array_into_iter` --> $DIR/deprecated.rs:6:8 | LL | #[warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::unused_label` has been removed: `this lint has been uplifted to rustc and is now called `unused_labels`` +error: lint `clippy::unused_label` has been removed: this lint has been uplifted to rustc and is now called `unused_labels` --> $DIR/deprecated.rs:7:8 | LL | #[warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::regex_macro` has been removed: `the regex! macro has been removed from the regex crate in 2018` +error: lint `clippy::regex_macro` has been removed: the regex! macro has been removed from the regex crate in 2018 --> $DIR/deprecated.rs:8:8 | LL | #[warn(clippy::regex_macro)] | ^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::drop_bounds` has been removed: `this lint has been uplifted to rustc and is now called `drop_bounds`` +error: lint `clippy::drop_bounds` has been removed: this lint has been uplifted to rustc and is now called `drop_bounds` --> $DIR/deprecated.rs:9:8 | LL | #[warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::temporary_cstring_as_ptr` has been removed: `this lint has been uplifted to rustc and is now called `temporary_cstring_as_ptr`` +error: lint `clippy::temporary_cstring_as_ptr` has been removed: this lint has been uplifted to rustc and is now called `temporary_cstring_as_ptr` --> $DIR/deprecated.rs:10:8 | LL | #[warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::panic_params` has been removed: `this lint has been uplifted to rustc and is now called `panic_fmt`` +error: lint `clippy::panic_params` has been removed: this lint has been uplifted to rustc and is now called `panic_fmt` --> $DIR/deprecated.rs:11:8 | LL | #[warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::unknown_clippy_lints` has been removed: `this lint has been integrated into the `unknown_lints` rustc lint` +error: lint `clippy::unknown_clippy_lints` has been removed: this lint has been integrated into the `unknown_lints` rustc lint --> $DIR/deprecated.rs:12:8 | LL | #[warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `clippy::unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` +error: lint `clippy::unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7 --> $DIR/deprecated.rs:1:8 | LL | #[warn(clippy::unstable_as_slice)] diff --git a/tests/ui/deprecated_old.stderr b/tests/ui/deprecated_old.stderr index 2fe1facf0c72..b8550078c460 100644 --- a/tests/ui/deprecated_old.stderr +++ b/tests/ui/deprecated_old.stderr @@ -1,4 +1,4 @@ -error: lint `unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` +error: lint `unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7 --> $DIR/deprecated_old.rs:1:8 | LL | #[warn(unstable_as_slice)] @@ -6,19 +6,19 @@ LL | #[warn(unstable_as_slice)] | = note: `-D renamed-and-removed-lints` implied by `-D warnings` -error: lint `unstable_as_mut_slice` has been removed: ``Vec::as_mut_slice` has been stabilized in 1.7` +error: lint `unstable_as_mut_slice` has been removed: `Vec::as_mut_slice` has been stabilized in 1.7 --> $DIR/deprecated_old.rs:2:8 | LL | #[warn(unstable_as_mut_slice)] | ^^^^^^^^^^^^^^^^^^^^^ -error: lint `misaligned_transmute` has been removed: `this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr` +error: lint `misaligned_transmute` has been removed: this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr --> $DIR/deprecated_old.rs:3:8 | LL | #[warn(misaligned_transmute)] | ^^^^^^^^^^^^^^^^^^^^ -error: lint `unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` +error: lint `unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7 --> $DIR/deprecated_old.rs:1:8 | LL | #[warn(unstable_as_slice)] From e7333fe1810a9e90c7e2425ae1d4aa84463d32ce Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Sat, 12 Dec 2020 15:32:45 +0100 Subject: [PATCH 0172/1222] Use ty::{IntTy,UintTy,FloatTy} in rustdoc and clippy --- clippy_lints/src/bytecount.rs | 3 +-- clippy_lints/src/consts.rs | 8 ++++---- clippy_lints/src/enum_clike.rs | 3 +-- clippy_lints/src/float_literal.rs | 8 ++++---- clippy_lints/src/mutex_atomic.rs | 5 ++--- clippy_lints/src/transmute.rs | 6 +++--- clippy_lints/src/types.rs | 8 +++----- clippy_lints/src/utils/mod.rs | 13 ++++++------- 8 files changed, 24 insertions(+), 30 deletions(-) diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index 38a0e27c4cf5..ac9098a7584d 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -2,11 +2,10 @@ use crate::utils::{ contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability, span_lint_and_sugg, }; use if_chain::if_chain; -use rustc_ast::ast::UintTy; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; +use rustc_middle::ty::{self, UintTy}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; use rustc_span::Symbol; diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 166eadf86c17..640cffd24a70 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -2,14 +2,14 @@ use crate::utils::{clip, sext, unsext}; use if_chain::if_chain; -use rustc_ast::ast::{FloatTy, LitFloatType, LitKind}; +use rustc_ast::ast::{self, LitFloatType, LitKind}; use rustc_data_structures::sync::Lrc; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, QPath, UnOp}; use rustc_lint::LateContext; use rustc_middle::mir::interpret::Scalar; use rustc_middle::ty::subst::{Subst, SubstsRef}; -use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt}; +use rustc_middle::ty::{self, FloatTy, ScalarInt, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; use rustc_span::symbol::Symbol; use std::cmp::Ordering::{self, Equal}; @@ -167,8 +167,8 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option>) -> Constant { LitKind::Char(c) => Constant::Char(c), LitKind::Int(n, _) => Constant::Int(n), LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty { - FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()), - FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()), + ast::FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()), + ast::FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()), }, LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind() { ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()), diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index fb80f48a9ccf..ae56a8ba5ab4 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -3,10 +3,9 @@ use crate::consts::{miri_to_const, Constant}; use crate::utils::span_lint; -use rustc_ast::ast::{IntTy, UintTy}; use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; +use rustc_middle::ty::{self, IntTy, UintTy}; use rustc_middle::ty::util::IntTypeExt; use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::convert::TryFrom; diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index 1fe4461533b3..be646cbe4d04 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -1,10 +1,10 @@ use crate::utils::{numeric_literal, span_lint_and_sugg}; use if_chain::if_chain; -use rustc_ast::ast::{FloatTy, LitFloatType, LitKind}; +use rustc_ast::ast::{self, LitFloatType, LitKind}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; +use rustc_middle::ty::{self, FloatTy}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::fmt; @@ -75,8 +75,8 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral { let digits = count_digits(&sym_str); let max = max_digits(fty); let type_suffix = match lit_float_ty { - LitFloatType::Suffixed(FloatTy::F32) => Some("f32"), - LitFloatType::Suffixed(FloatTy::F64) => Some("f64"), + LitFloatType::Suffixed(ast::FloatTy::F32) => Some("f32"), + LitFloatType::Suffixed(ast::FloatTy::F64) => Some("f64"), LitFloatType::Unsuffixed => None }; let (is_whole, mut float_str) = match fty { diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index ea986874291e..40b236493a31 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -3,7 +3,6 @@ //! This lint is **warn** by default use crate::utils::{is_type_diagnostic_item, span_lint}; -use rustc_ast::ast; use rustc_hir::Expr; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, Ty}; @@ -77,8 +76,8 @@ impl<'tcx> LateLintPass<'tcx> for Mutex { atomic_name ); match *mutex_param.kind() { - ty::Uint(t) if t != ast::UintTy::Usize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg), - ty::Int(t) if t != ast::IntTy::Isize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg), + ty::Uint(t) if t != ty::UintTy::Usize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg), + ty::Int(t) if t != ty::IntTy::Isize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg), _ => span_lint(cx, MUTEX_ATOMIC, expr.span, &msg), }; } diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index b0909f731774..d977cea4da50 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -443,7 +443,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { ); }, ), - (ty::Int(ast::IntTy::I32) | ty::Uint(ast::UintTy::U32), &ty::Char) => { + (ty::Int(ty::IntTy::I32) | ty::Uint(ty::UintTy::U32), &ty::Char) => { span_lint_and_then( cx, TRANSMUTE_INT_TO_CHAR, @@ -468,7 +468,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { (ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) => { if_chain! { if let (&ty::Slice(slice_ty), &ty::Str) = (&ty_from.kind(), &ty_to.kind()); - if let ty::Uint(ast::UintTy::U8) = slice_ty.kind(); + if let ty::Uint(ty::UintTy::U8) = slice_ty.kind(); if from_mutbl == to_mutbl; then { let postfix = if *from_mutbl == Mutability::Mut { @@ -536,7 +536,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { } }, ), - (ty::Int(ast::IntTy::I8) | ty::Uint(ast::UintTy::U8), ty::Bool) => { + (ty::Int(ty::IntTy::I8) | ty::Uint(ty::UintTy::U8), ty::Bool) => { span_lint_and_then( cx, TRANSMUTE_INT_TO_BOOL, diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 3b5a83d2a0be..17cef0af3e9c 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -5,7 +5,7 @@ use std::cmp::Ordering; use std::collections::BTreeMap; use if_chain::if_chain; -use rustc_ast::{FloatTy, IntTy, LitFloatType, LitIntType, LitKind, UintTy}; +use rustc_ast::{LitFloatType, LitIntType, LitKind}; use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, FnKind, NestedVisitorMap, Visitor}; @@ -18,7 +18,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::hir::map::Map; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::TypeFoldable; -use rustc_middle::ty::{self, InferTy, Ty, TyCtxt, TyS, TypeAndMut, TypeckResults}; +use rustc_middle::ty::{self, FloatTy, InferTy, IntTy, Ty, TyCtxt, TyS, TypeAndMut, TypeckResults, UintTy}; use rustc_semver::RustcVersion; use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass}; use rustc_span::hygiene::{ExpnKind, MacroKind}; @@ -1106,9 +1106,7 @@ fn is_empty_block(expr: &Expr<'_>) -> bool { expr.kind, ExprKind::Block( Block { - stmts: &[], - expr: None, - .. + stmts: &[], expr: None, .. }, _, ) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 9b262517a983..46b2b06d1a28 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -35,7 +35,6 @@ use std::mem; use if_chain::if_chain; use rustc_ast::ast::{self, Attribute, LitKind}; -use rustc_attr as attr; use rustc_data_structures::fx::FxHashMap; use rustc_errors::Applicability; use rustc_hir as hir; @@ -1224,27 +1223,27 @@ pub fn get_arg_name(pat: &Pat<'_>) -> Option { } } -pub fn int_bits(tcx: TyCtxt<'_>, ity: ast::IntTy) -> u64 { - Integer::from_attr(&tcx, attr::IntType::SignedInt(ity)).size().bits() +pub fn int_bits(tcx: TyCtxt<'_>, ity: ty::IntTy) -> u64 { + Integer::from_int_ty(&tcx, ity).size().bits() } #[allow(clippy::cast_possible_wrap)] /// Turn a constant int byte representation into an i128 -pub fn sext(tcx: TyCtxt<'_>, u: u128, ity: ast::IntTy) -> i128 { +pub fn sext(tcx: TyCtxt<'_>, u: u128, ity: ty::IntTy) -> i128 { let amt = 128 - int_bits(tcx, ity); ((u as i128) << amt) >> amt } #[allow(clippy::cast_sign_loss)] /// clip unused bytes -pub fn unsext(tcx: TyCtxt<'_>, u: i128, ity: ast::IntTy) -> u128 { +pub fn unsext(tcx: TyCtxt<'_>, u: i128, ity: ty::IntTy) -> u128 { let amt = 128 - int_bits(tcx, ity); ((u as u128) << amt) >> amt } /// clip unused bytes -pub fn clip(tcx: TyCtxt<'_>, u: u128, ity: ast::UintTy) -> u128 { - let bits = Integer::from_attr(&tcx, attr::IntType::UnsignedInt(ity)).size().bits(); +pub fn clip(tcx: TyCtxt<'_>, u: u128, ity: ty::UintTy) -> u128 { + let bits = Integer::from_uint_ty(&tcx, ity).size().bits(); let amt = 128 - bits; (u << amt) >> amt } From 96572c498602729d8ae1bfc4236fa5343fd3e02a Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Mon, 18 Jan 2021 13:36:32 -0600 Subject: [PATCH 0173/1222] Remove qpath_res util function --- clippy_lints/src/default.rs | 4 ++-- clippy_lints/src/drop_forget_ref.rs | 4 ++-- clippy_lints/src/exit.rs | 4 ++-- clippy_lints/src/functions.rs | 8 ++++---- clippy_lints/src/let_if_seq.rs | 4 ++-- clippy_lints/src/loops.rs | 22 +++++++++++----------- clippy_lints/src/manual_strip.rs | 8 ++++---- clippy_lints/src/mem_forget.rs | 4 ++-- clippy_lints/src/no_effect.rs | 6 +++--- clippy_lints/src/non_copy_const.rs | 4 ++-- clippy_lints/src/to_string_in_display.rs | 4 ++-- clippy_lints/src/types.rs | 12 ++++++------ clippy_lints/src/utils/internal_lints.rs | 6 +++--- clippy_lints/src/utils/mod.rs | 13 ------------- 14 files changed, 45 insertions(+), 58 deletions(-) diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index f7224811e6e7..6fa1378b8c73 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -1,5 +1,5 @@ use crate::utils::{ - any_parent_is_automatically_derived, contains_name, match_def_path, paths, qpath_res, snippet_with_macro_callsite, + any_parent_is_automatically_derived, contains_name, match_def_path, paths, snippet_with_macro_callsite, }; use crate::utils::{span_lint_and_note, span_lint_and_sugg}; use if_chain::if_chain; @@ -231,7 +231,7 @@ fn is_expr_default<'tcx>(expr: &'tcx Expr<'tcx>, cx: &LateContext<'tcx>) -> bool if_chain! { if let ExprKind::Call(ref fn_expr, _) = &expr.kind; if let ExprKind::Path(qpath) = &fn_expr.kind; - if let Res::Def(_, def_id) = qpath_res(cx, qpath, fn_expr.hir_id); + if let Res::Def(_, def_id) = cx.qpath_res(qpath, fn_expr.hir_id); then { // right hand side of assignment is `Default::default` match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD) diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index cf528d189b4b..a84f9c462871 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -1,4 +1,4 @@ -use crate::utils::{is_copy, match_def_path, paths, qpath_res, span_lint_and_note}; +use crate::utils::{is_copy, match_def_path, paths, span_lint_and_note}; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; @@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { if let ExprKind::Call(ref path, ref args) = expr.kind; if let ExprKind::Path(ref qpath) = path.kind; if args.len() == 1; - if let Some(def_id) = qpath_res(cx, qpath, path.hir_id).opt_def_id(); + if let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id(); then { let lint; let msg; diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index 7337d98c8be3..915859270009 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -1,4 +1,4 @@ -use crate::utils::{is_entrypoint_fn, match_def_path, paths, qpath_res, span_lint}; +use crate::utils::{is_entrypoint_fn, match_def_path, paths, span_lint}; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind, Item, ItemKind, Node}; use rustc_lint::{LateContext, LateLintPass}; @@ -29,7 +29,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit { if_chain! { if let ExprKind::Call(ref path_expr, ref _args) = e.kind; if let ExprKind::Path(ref path) = path_expr.kind; - if let Some(def_id) = qpath_res(cx, path, path_expr.hir_id).opt_def_id(); + if let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::EXIT); then { let parent = cx.tcx.hir().get_parent_item(e.hir_id); diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index fd93548b55c6..879542546103 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -1,7 +1,7 @@ use crate::utils::{ attr_by_name, attrs::is_proc_macro, is_must_use_ty, is_trait_impl_item, is_type_diagnostic_item, iter_input_pats, - last_path_segment, match_def_path, must_use_attr, qpath_res, return_ty, snippet, snippet_opt, span_lint, - span_lint_and_help, span_lint_and_then, trait_ref_of_method, type_is_unsafe_function, + last_path_segment, match_def_path, must_use_attr, return_ty, snippet, snippet_opt, span_lint, span_lint_and_help, + span_lint_and_then, trait_ref_of_method, type_is_unsafe_function, }; use if_chain::if_chain; use rustc_ast::ast::Attribute; @@ -659,7 +659,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { impl<'a, 'tcx> DerefVisitor<'a, 'tcx> { fn check_arg(&self, ptr: &hir::Expr<'_>) { if let hir::ExprKind::Path(ref qpath) = ptr.kind { - if let Res::Local(id) = qpath_res(self.cx, qpath, ptr.hir_id) { + if let Res::Local(id) = self.cx.qpath_res(qpath, ptr.hir_id) { if self.ptrs.contains(&id) { span_lint( self.cx, @@ -722,7 +722,7 @@ fn is_mutated_static(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> bool { use hir::ExprKind::{Field, Index, Path}; match e.kind { - Path(ref qpath) => !matches!(qpath_res(cx, qpath, e.hir_id), Res::Local(_)), + Path(ref qpath) => !matches!(cx.qpath_res(qpath, e.hir_id), Res::Local(_)), Field(ref inner, _) | Index(ref inner, _) => is_mutated_static(cx, inner), _ => false, } diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index db717cd1240a..5886c2360e36 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -1,4 +1,4 @@ -use crate::utils::{qpath_res, snippet, span_lint_and_then, visitors::LocalUsedVisitor}; +use crate::utils::{snippet, span_lint_and_then, visitors::LocalUsedVisitor}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; @@ -145,7 +145,7 @@ fn check_assign<'tcx>( if let hir::StmtKind::Semi(ref expr) = expr.kind; if let hir::ExprKind::Assign(ref var, ref value, _) = expr.kind; if let hir::ExprKind::Path(ref qpath) = var.kind; - if let Res::Local(local_id) = qpath_res(cx, qpath, var.hir_id); + if let Res::Local(local_id) = cx.qpath_res(qpath, var.hir_id); if decl == local_id; then { let mut v = LocalUsedVisitor::new(decl); diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 1c5ab2874b04..1ae2c6ca9578 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -6,9 +6,9 @@ use crate::utils::visitors::LocalUsedVisitor; use crate::utils::{ contains_name, get_enclosing_block, get_parent_expr, get_trait_def_id, has_iter_method, higher, implements_trait, indent_of, is_in_panic_handler, is_integer_const, is_no_std_crate, is_refutable, is_type_diagnostic_item, - last_path_segment, match_trait_method, match_type, match_var, multispan_sugg, qpath_res, single_segment_path, - snippet, snippet_with_applicability, snippet_with_macro_callsite, span_lint, span_lint_and_help, - span_lint_and_sugg, span_lint_and_then, sugg, SpanlessEq, + last_path_segment, match_trait_method, match_type, match_var, multispan_sugg, single_segment_path, snippet, + snippet_with_applicability, snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg, + span_lint_and_then, sugg, SpanlessEq, }; use if_chain::if_chain; use rustc_ast::ast; @@ -848,7 +848,7 @@ fn same_var<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, var: HirId) -> bool { if let ExprKind::Path(qpath) = &expr.kind; if let QPath::Resolved(None, path) = qpath; if path.segments.len() == 1; - if let Res::Local(local_id) = qpath_res(cx, qpath, expr.hir_id); + if let Res::Local(local_id) = cx.qpath_res(qpath, expr.hir_id); then { // our variable! local_id == var @@ -1420,7 +1420,7 @@ fn detect_same_item_push<'tcx>( // Make sure that the push does not involve possibly mutating values match pushed_item.kind { ExprKind::Path(ref qpath) => { - match qpath_res(cx, qpath, pushed_item.hir_id) { + match cx.qpath_res(qpath, pushed_item.hir_id) { // immutable bindings that are initialized with literal or constant Res::Local(hir_id) => { if_chain! { @@ -1437,7 +1437,7 @@ fn detect_same_item_push<'tcx>( ExprKind::Lit(..) => emit_lint(cx, vec, pushed_item), // immutable bindings that are initialized with constant ExprKind::Path(ref path) => { - if let Res::Def(DefKind::Const, ..) = qpath_res(cx, path, init.hir_id) { + if let Res::Def(DefKind::Const, ..) = cx.qpath_res(path, init.hir_id) { emit_lint(cx, vec, pushed_item); } } @@ -2028,7 +2028,7 @@ fn check_for_mutability(cx: &LateContext<'_>, bound: &Expr<'_>) -> Option if let ExprKind::Path(ref qpath) = bound.kind; if let QPath::Resolved(None, _) = *qpath; then { - let res = qpath_res(cx, qpath, bound.hir_id); + let res = cx.qpath_res(qpath, bound.hir_id); if let Res::Local(hir_id) = res { let node_str = cx.tcx.hir().get(hir_id); if_chain! { @@ -2120,7 +2120,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { if self.prefer_mutable { self.indexed_mut.insert(seqvar.segments[0].ident.name); } - let res = qpath_res(self.cx, seqpath, seqexpr.hir_id); + let res = self.cx.qpath_res(seqpath, seqexpr.hir_id); match res { Res::Local(hir_id) => { let parent_id = self.cx.tcx.hir().get_parent_item(expr.hir_id); @@ -2184,7 +2184,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { if let QPath::Resolved(None, ref path) = *qpath; if path.segments.len() == 1; then { - if let Res::Local(local_id) = qpath_res(self.cx, qpath, expr.hir_id) { + if let Res::Local(local_id) = self.cx.qpath_res(qpath, expr.hir_id) { if local_id == self.var { self.nonindex = true; } else { @@ -2589,7 +2589,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { fn var_def_id(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { if let ExprKind::Path(ref qpath) = expr.kind { - let path_res = qpath_res(cx, qpath, expr.hir_id); + let path_res = cx.qpath_res(qpath, expr.hir_id); if let Res::Local(hir_id) = path_res { return Some(hir_id); } @@ -2819,7 +2819,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> { if_chain! { if let ExprKind::Path(ref qpath) = ex.kind; if let QPath::Resolved(None, _) = *qpath; - let res = qpath_res(self.cx, qpath, ex.hir_id); + let res = self.cx.qpath_res(qpath, ex.hir_id); then { match res { Res::Local(hir_id) => { diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index a0cfe145a301..42a92104a491 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -1,7 +1,7 @@ use crate::consts::{constant, Constant}; use crate::utils::usage::mutated_variables; use crate::utils::{ - eq_expr_value, higher, match_def_path, meets_msrv, multispan_sugg, paths, qpath_res, snippet, span_lint_and_then, + eq_expr_value, higher, match_def_path, meets_msrv, multispan_sugg, paths, snippet, span_lint_and_then, }; use if_chain::if_chain; @@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { } else { return; }; - let target_res = qpath_res(cx, &target_path, target_arg.hir_id); + let target_res = cx.qpath_res(&target_path, target_arg.hir_id); if target_res == Res::Err { return; }; @@ -221,7 +221,7 @@ fn find_stripping<'tcx>( if let ExprKind::Index(indexed, index) = &unref.kind; if let Some(higher::Range { start, end, .. }) = higher::range(index); if let ExprKind::Path(path) = &indexed.kind; - if qpath_res(self.cx, path, ex.hir_id) == self.target; + if self.cx.qpath_res(path, ex.hir_id) == self.target; then { match (self.strip_kind, start, end) { (StripKind::Prefix, Some(start), None) => { @@ -235,7 +235,7 @@ fn find_stripping<'tcx>( if let ExprKind::Binary(Spanned { node: BinOpKind::Sub, .. }, left, right) = end.kind; if let Some(left_arg) = len_arg(self.cx, left); if let ExprKind::Path(left_path) = &left_arg.kind; - if qpath_res(self.cx, left_path, left_arg.hir_id) == self.target; + if self.cx.qpath_res(left_path, left_arg.hir_id) == self.target; if eq_pattern_length(self.cx, self.pattern, right); then { self.results.push(ex.span); diff --git a/clippy_lints/src/mem_forget.rs b/clippy_lints/src/mem_forget.rs index 8c6fd10f98a1..d34f9761e26f 100644 --- a/clippy_lints/src/mem_forget.rs +++ b/clippy_lints/src/mem_forget.rs @@ -1,4 +1,4 @@ -use crate::utils::{match_def_path, paths, qpath_res, span_lint}; +use crate::utils::{match_def_path, paths, span_lint}; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -29,7 +29,7 @@ impl<'tcx> LateLintPass<'tcx> for MemForget { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::Call(ref path_expr, ref args) = e.kind { if let ExprKind::Path(ref qpath) = path_expr.kind { - if let Some(def_id) = qpath_res(cx, qpath, path_expr.hir_id).opt_def_id() { + if let Some(def_id) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id() { if match_def_path(cx, def_id, &paths::MEM_FORGET) { let forgot_ty = cx.typeck_results().expr_ty(&args[0]); diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index b1b5b3439a0e..69302d695ce0 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -1,4 +1,4 @@ -use crate::utils::{has_drop, qpath_res, snippet_opt, span_lint, span_lint_and_sugg}; +use crate::utils::{has_drop, snippet_opt, span_lint, span_lint_and_sugg}; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{BinOpKind, BlockCheckMode, Expr, ExprKind, Stmt, StmtKind, UnsafeSource}; @@ -67,7 +67,7 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { }, ExprKind::Call(ref callee, ref args) => { if let ExprKind::Path(ref qpath) = callee.kind { - let res = qpath_res(cx, qpath, callee.hir_id); + let res = cx.qpath_res(qpath, callee.hir_id); match res { Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..) => { !has_drop(cx, cx.typeck_results().expr_ty(expr)) @@ -146,7 +146,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option { if let ExprKind::Path(ref qpath) = callee.kind { - let res = qpath_res(cx, qpath, callee.hir_id); + let res = cx.qpath_res(qpath, callee.hir_id); match res { Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..) if !has_drop(cx, cx.typeck_results().expr_ty(expr)) => diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 3a9aa6ced03b..f57d75363175 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -18,7 +18,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{InnerSpan, Span, DUMMY_SP}; use rustc_typeck::hir_ty_to_ty; -use crate::utils::{in_constant, qpath_res, span_lint_and_then}; +use crate::utils::{in_constant, span_lint_and_then}; use if_chain::if_chain; // FIXME: this is a correctness problem but there's no suitable @@ -339,7 +339,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { } // Make sure it is a const item. - let item_def_id = match qpath_res(cx, qpath, expr.hir_id) { + let item_def_id = match cx.qpath_res(qpath, expr.hir_id) { Res::Def(DefKind::Const | DefKind::AssocConst, did) => did, _ => return, }; diff --git a/clippy_lints/src/to_string_in_display.rs b/clippy_lints/src/to_string_in_display.rs index c53727ba1600..fa508df865e4 100644 --- a/clippy_lints/src/to_string_in_display.rs +++ b/clippy_lints/src/to_string_in_display.rs @@ -1,4 +1,4 @@ -use crate::utils::{match_def_path, match_trait_method, paths, qpath_res, span_lint}; +use crate::utils::{match_def_path, match_trait_method, paths, span_lint}; use if_chain::if_chain; use rustc_hir::def::Res; use rustc_hir::{Expr, ExprKind, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind}; @@ -94,7 +94,7 @@ impl LateLintPass<'_> for ToStringInDisplay { if match_trait_method(cx, expr, &paths::TO_STRING); if self.in_display_impl; if let ExprKind::Path(ref qpath) = args[0].kind; - if let Res::Local(hir_id) = qpath_res(cx, qpath, args[0].hir_id); + if let Res::Local(hir_id) = cx.qpath_res(qpath, args[0].hir_id); if let Some(self_hir_id) = self.self_hir_id; if hir_id == self_hir_id; then { diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 3b5a83d2a0be..624ea16f585d 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -34,7 +34,7 @@ use crate::utils::sugg::Sugg; use crate::utils::{ clip, comparisons, differing_macro_contexts, higher, in_constant, indent_of, int_bits, is_hir_ty_cfg_dependant, is_type_diagnostic_item, last_path_segment, match_def_path, match_path, meets_msrv, method_chain_args, - multispan_sugg, numeric_literal::NumericLiteral, qpath_res, reindent_multiline, sext, snippet, snippet_opt, + multispan_sugg, numeric_literal::NumericLiteral, reindent_multiline, sext, snippet, snippet_opt, snippet_with_applicability, snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then, unsext, }; @@ -298,7 +298,7 @@ fn match_type_parameter(cx: &LateContext<'_>, qpath: &QPath<'_>, path: &[&str]) _ => None, }); if let TyKind::Path(ref qpath) = ty.kind; - if let Some(did) = qpath_res(cx, qpath, ty.hir_id).opt_def_id(); + if let Some(did) = cx.qpath_res(qpath, ty.hir_id).opt_def_id(); if match_def_path(cx, did, path); then { return Some(ty.span); @@ -365,7 +365,7 @@ impl Types { match hir_ty.kind { TyKind::Path(ref qpath) if !is_local => { let hir_id = hir_ty.hir_id; - let res = qpath_res(cx, qpath, hir_id); + let res = cx.qpath_res(qpath, hir_id); if let Some(def_id) = res.opt_def_id() { if Some(def_id) == cx.tcx.lang_items().owned_box() { if let Some(span) = match_borrows_parameter(cx, qpath) { @@ -535,7 +535,7 @@ impl Types { }); // ty is now _ at this point if let TyKind::Path(ref ty_qpath) = ty.kind; - let res = qpath_res(cx, ty_qpath, ty.hir_id); + let res = cx.qpath_res(ty_qpath, ty.hir_id); if let Some(def_id) = res.opt_def_id(); if Some(def_id) == cx.tcx.lang_items().owned_box(); // At this point, we know ty is Box, now get T @@ -652,7 +652,7 @@ impl Types { match mut_ty.ty.kind { TyKind::Path(ref qpath) => { let hir_id = mut_ty.ty.hir_id; - let def = qpath_res(cx, qpath, hir_id); + let def = cx.qpath_res(qpath, hir_id); if_chain! { if let Some(def_id) = def.opt_def_id(); if Some(def_id) == cx.tcx.lang_items().owned_box(); @@ -739,7 +739,7 @@ fn is_any_trait(t: &hir::Ty<'_>) -> bool { fn get_bounds_if_impl_trait<'tcx>(cx: &LateContext<'tcx>, qpath: &QPath<'_>, id: HirId) -> Option> { if_chain! { - if let Some(did) = qpath_res(cx, qpath, id).opt_def_id(); + if let Some(did) = cx.qpath_res(qpath, id).opt_def_id(); if let Some(Node::GenericParam(generic_param)) = cx.tcx.hir().get_if_local(did); if let GenericParamKind::Type { synthetic, .. } = generic_param.kind; if synthetic == Some(SyntheticTyParamKind::ImplTrait); diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 7aa17520ba79..822863ca3e27 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -1,7 +1,7 @@ use crate::consts::{constant_simple, Constant}; use crate::utils::{ - is_expn_of, match_def_path, match_qpath, match_type, method_calls, path_to_res, paths, qpath_res, run_lints, - snippet, span_lint, span_lint_and_help, span_lint_and_sugg, SpanlessEq, + is_expn_of, match_def_path, match_qpath, match_type, method_calls, path_to_res, paths, run_lints, snippet, + span_lint, span_lint_and_help, span_lint_and_sugg, SpanlessEq, }; use if_chain::if_chain; use rustc_ast::ast::{Crate as AstCrate, ItemKind, LitKind, NodeId}; @@ -787,7 +787,7 @@ fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option return path_to_matched_type(cx, expr), - ExprKind::Path(qpath) => match qpath_res(cx, qpath, expr.hir_id) { + ExprKind::Path(qpath) => match cx.qpath_res(qpath, expr.hir_id) { Res::Local(hir_id) => { let parent_id = cx.tcx.hir().get_parent_node(hir_id); if let Some(Node::Local(local)) = cx.tcx.hir().find(parent_id) { diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 9b262517a983..023fb0a7112c 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -370,19 +370,6 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Option { } } -pub fn qpath_res(cx: &LateContext<'_>, qpath: &hir::QPath<'_>, id: hir::HirId) -> Res { - match qpath { - hir::QPath::Resolved(_, path) => path.res, - hir::QPath::TypeRelative(..) | hir::QPath::LangItem(..) => { - if cx.tcx.has_typeck_results(id.owner.to_def_id()) { - cx.tcx.typeck(id.owner).qpath_res(qpath, id) - } else { - Res::Err - } - }, - } -} - /// Convenience function to get the `DefId` of a trait by path. /// It could be a trait or trait alias. pub fn get_trait_def_id(cx: &LateContext<'_>, path: &[&str]) -> Option { From bbb7a3454edc2041c8361e5a9ea869913abd4061 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 18 Jan 2021 16:47:37 -0500 Subject: [PATCH 0174/1222] Force token collection to run when parsing nonterminals Fixes #81007 Previously, we would fail to collect tokens in the proper place when only builtin attributes were present. As a result, we would end up with attribute tokens in the collected `TokenStream`, leading to duplication when we attempted to prepend the attributes from the AST node. We now explicitly track when token collection must be performed due to nomterminal parsing. --- clippy_lints/src/doc.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index f518da55cd76..3a754f499178 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -12,6 +12,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty; use rustc_parse::maybe_new_parser_from_source_str; +use rustc_parse::parser::ForceCollect; use rustc_session::parse::ParseSess; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::edition::Edition; @@ -483,7 +484,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { let mut relevant_main_found = false; loop { - match parser.parse_item() { + match parser.parse_item(ForceCollect::No) { Ok(Some(item)) => match &item.kind { // Tests with one of these items are ignored ItemKind::Static(..) From 4c11a41b02a5f72bbb0f741ca19a934cbc276387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 20 Jan 2021 17:15:08 -0800 Subject: [PATCH 0175/1222] Add loop head span to hir --- clippy_lints/src/loops.rs | 8 ++++---- clippy_lints/src/needless_continue.rs | 2 +- clippy_lints/src/shadow.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 1c5ab2874b04..bbcea387de2c 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -533,7 +533,7 @@ impl<'tcx> LateLintPass<'tcx> for Loops { } // check for never_loop - if let ExprKind::Loop(ref block, _, _) = expr.kind { + if let ExprKind::Loop(ref block, _, _, _) = expr.kind { match never_loop_block(block, expr.hir_id) { NeverLoopResult::AlwaysBreak => span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually loops"), NeverLoopResult::MayContinueMainLoop | NeverLoopResult::Otherwise => (), @@ -543,7 +543,7 @@ impl<'tcx> LateLintPass<'tcx> for Loops { // check for `loop { if let {} else break }` that could be `while let` // (also matches an explicit "match" instead of "if let") // (even if the "match" or "if let" is used for declaration) - if let ExprKind::Loop(ref block, _, LoopSource::Loop) = expr.kind { + if let ExprKind::Loop(ref block, _, LoopSource::Loop, _) = expr.kind { // also check for empty `loop {}` statements, skipping those in #[panic_handler] if block.stmts.is_empty() && block.expr.is_none() && !is_in_panic_handler(cx, expr) { let msg = "empty `loop {}` wastes CPU cycles"; @@ -738,7 +738,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { | ExprKind::Assign(ref e1, ref e2, _) | ExprKind::AssignOp(_, ref e1, ref e2) | ExprKind::Index(ref e1, ref e2) => never_loop_expr_all(&mut [&**e1, &**e2].iter().cloned(), main_loop_id), - ExprKind::Loop(ref b, _, _) => { + ExprKind::Loop(ref b, _, _, _) => { // Break can come from the inner loop so remove them. absorb_break(&never_loop_block(b, main_loop_id)) }, @@ -1314,7 +1314,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SameItemPushVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { match &expr.kind { // Non-determinism may occur ... don't give a lint - ExprKind::Loop(_, _, _) | ExprKind::Match(_, _, _) => self.should_lint = false, + ExprKind::Loop(..) | ExprKind::Match(..) => self.should_lint = false, ExprKind::Block(block, _) => self.visit_block(block), _ => {}, } diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs index a971d041ca66..bb4d84834043 100644 --- a/clippy_lints/src/needless_continue.rs +++ b/clippy_lints/src/needless_continue.rs @@ -221,7 +221,7 @@ where { if let ast::ExprKind::While(_, loop_block, label) | ast::ExprKind::ForLoop(_, _, loop_block, label) - | ast::ExprKind::Loop(loop_block, label) = &expr.kind + | ast::ExprKind::Loop(loop_block, label, _) = &expr.kind { func(loop_block, label.as_ref()); } diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 24da056770c9..d5b1767e945b 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -325,7 +325,7 @@ fn check_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, bindings: &mut | ExprKind::Field(ref e, _) | ExprKind::AddrOf(_, _, ref e) | ExprKind::Box(ref e) => check_expr(cx, e, bindings), - ExprKind::Block(ref block, _) | ExprKind::Loop(ref block, _, _) => check_block(cx, block, bindings), + ExprKind::Block(ref block, _) | ExprKind::Loop(ref block, ..) => check_block(cx, block, bindings), // ExprKind::Call // ExprKind::MethodCall ExprKind::Array(v) | ExprKind::Tup(v) => { From 809ed13aab5ee47ff002651b68341872f5bcb011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 21 Jan 2021 16:48:17 -0800 Subject: [PATCH 0176/1222] Fix clippy and comment --- clippy_lints/src/needless_continue.rs | 2 +- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/utils/higher.rs | 4 ++-- clippy_lints/src/utils/hir_utils.rs | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs index bb4d84834043..603071a5f4ac 100644 --- a/clippy_lints/src/needless_continue.rs +++ b/clippy_lints/src/needless_continue.rs @@ -221,7 +221,7 @@ where { if let ast::ExprKind::While(_, loop_block, label) | ast::ExprKind::ForLoop(_, _, loop_block, label) - | ast::ExprKind::Loop(loop_block, label, _) = &expr.kind + | ast::ExprKind::Loop(loop_block, label, ..) = &expr.kind { func(loop_block, label.as_ref()); } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 43afa65de3e5..ca60d335262b 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -317,7 +317,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { self.current = cast_pat; self.visit_expr(expr); }, - ExprKind::Loop(ref body, _, desugaring) => { + ExprKind::Loop(ref body, _, desugaring, _) => { let body_pat = self.next("body"); let des = loop_desugaring_name(desugaring); let label_pat = self.next("label"); diff --git a/clippy_lints/src/utils/higher.rs b/clippy_lints/src/utils/higher.rs index 9b3585865da3..42ab9a1e7d24 100644 --- a/clippy_lints/src/utils/higher.rs +++ b/clippy_lints/src/utils/higher.rs @@ -142,7 +142,7 @@ pub fn for_loop<'tcx>( if let hir::ExprKind::Match(ref iterexpr, ref arms, hir::MatchSource::ForLoopDesugar) = expr.kind; if let hir::ExprKind::Call(_, ref iterargs) = iterexpr.kind; if iterargs.len() == 1 && arms.len() == 1 && arms[0].guard.is_none(); - if let hir::ExprKind::Loop(ref block, _, _) = arms[0].body.kind; + if let hir::ExprKind::Loop(ref block, ..) = arms[0].body.kind; if block.expr.is_none(); if let [ _, _, ref let_stmt, ref body ] = *block.stmts; if let hir::StmtKind::Local(ref local) = let_stmt.kind; @@ -158,7 +158,7 @@ pub fn for_loop<'tcx>( /// `while cond { body }` becomes `(cond, body)`. pub fn while_loop<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> Option<(&'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>)> { if_chain! { - if let hir::ExprKind::Loop(block, _, hir::LoopSource::While) = &expr.kind; + if let hir::ExprKind::Loop(block, _, hir::LoopSource::While, _) = &expr.kind; if let hir::Block { expr: Some(expr), .. } = &**block; if let hir::ExprKind::Match(cond, arms, hir::MatchSource::WhileDesugar) = &expr.kind; if let hir::ExprKind::DropTemps(cond) = &cond.kind; diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index 10120a8805db..6066383f2ef4 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -123,7 +123,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { self.eq_expr(lc, rc) && self.eq_expr(&**lt, &**rt) && both(le, re, |l, r| self.eq_expr(l, r)) }, (&ExprKind::Lit(ref l), &ExprKind::Lit(ref r)) => l.node == r.node, - (&ExprKind::Loop(ref lb, ref ll, ref lls), &ExprKind::Loop(ref rb, ref rl, ref rls)) => { + (&ExprKind::Loop(ref lb, ref ll, ref lls, _), &ExprKind::Loop(ref rb, ref rl, ref rls, _)) => { lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.name == r.ident.name) }, (&ExprKind::Match(ref le, ref la, ref ls), &ExprKind::Match(ref re, ref ra, ref rs)) => { @@ -560,7 +560,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { ExprKind::Lit(ref l) => { l.node.hash(&mut self.s); }, - ExprKind::Loop(ref b, ref i, _) => { + ExprKind::Loop(ref b, ref i, ..) => { self.hash_block(b); if let Some(i) = *i { self.hash_name(i.ident.name); From 49521027ffea2d2e061b822c2c33c164ee672486 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Fri, 22 Jan 2021 18:07:00 +0100 Subject: [PATCH 0177/1222] Make more traits of the From/Into family diagnostic items Following traits are now diagnostic items: - `From` (unchanged) - `Into` - `TryFrom` - `TryInto` This also adds symbols for those items: - `into_trait` - `try_from_trait` - `try_into_trait` --- clippy_lints/src/fallible_impl_from.rs | 7 ++----- clippy_lints/src/utils/paths.rs | 1 - 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 9f389c8d2f9e..527905e375d2 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -1,7 +1,4 @@ -use crate::utils::paths::FROM_TRAIT; -use crate::utils::{ - is_expn_of, is_type_diagnostic_item, match_def_path, match_panic_def_id, method_chain_args, span_lint_and_then, -}; +use crate::utils::{is_expn_of, is_type_diagnostic_item, match_panic_def_id, method_chain_args, span_lint_and_then}; use if_chain::if_chain; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; @@ -59,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom { if_chain! { if let hir::ItemKind::Impl(impl_) = &item.kind; if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id); - if match_def_path(cx, impl_trait_ref.def_id, &FROM_TRAIT); + if cx.tcx.is_diagnostic_item(sym::from_trait, impl_trait_ref.def_id); then { lint_impl_body(cx, item.span, impl_.items); } diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index c0b203b5388d..432cc5b59f68 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -48,7 +48,6 @@ pub const FN_MUT: [&str; 3] = ["core", "ops", "FnMut"]; pub const FN_ONCE: [&str; 3] = ["core", "ops", "FnOnce"]; pub const FROM_FROM: [&str; 4] = ["core", "convert", "From", "from"]; pub const FROM_ITERATOR: [&str; 5] = ["core", "iter", "traits", "collect", "FromIterator"]; -pub const FROM_TRAIT: [&str; 3] = ["core", "convert", "From"]; pub const FUTURE_FROM_GENERATOR: [&str; 3] = ["core", "future", "from_generator"]; pub const HASH: [&str; 3] = ["core", "hash", "Hash"]; pub const HASHMAP: [&str; 5] = ["std", "collections", "hash", "map", "HashMap"]; From b97ff86d84acb4b42845d66f6a56ba6aed003187 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sat, 30 Jan 2021 19:33:21 +0100 Subject: [PATCH 0178/1222] Update clippy test output for panic macros. --- tests/ui/panicking_macros.stderr | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/ui/panicking_macros.stderr b/tests/ui/panicking_macros.stderr index 6028323a3c84..ffced49690e9 100644 --- a/tests/ui/panicking_macros.stderr +++ b/tests/ui/panicking_macros.stderr @@ -11,16 +11,12 @@ error: `panic` should not be present in production code | LL | panic!("message"); | ^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `panic` should not be present in production code --> $DIR/panicking_macros.rs:10:5 | LL | panic!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `todo` should not be present in production code --> $DIR/panicking_macros.rs:16:5 @@ -29,18 +25,23 @@ LL | todo!(); | ^^^^^^^^ | = note: `-D clippy::todo` implied by `-D warnings` + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `todo` should not be present in production code --> $DIR/panicking_macros.rs:17:5 | LL | todo!("message"); | ^^^^^^^^^^^^^^^^^ + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `todo` should not be present in production code --> $DIR/panicking_macros.rs:18:5 | LL | todo!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:24:5 @@ -49,18 +50,23 @@ LL | unimplemented!(); | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unimplemented` implied by `-D warnings` + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:25:5 | LL | unimplemented!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:26:5 | LL | unimplemented!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:32:5 @@ -69,6 +75,7 @@ LL | unreachable!(); | ^^^^^^^^^^^^^^^ | = note: `-D clippy::unreachable` implied by `-D warnings` + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:33:5 @@ -83,6 +90,8 @@ error: usage of the `unreachable!` macro | LL | unreachable!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `panic` should not be present in production code --> $DIR/panicking_macros.rs:40:5 @@ -95,18 +104,24 @@ error: `todo` should not be present in production code | LL | todo!(); | ^^^^^^^^ + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:42:5 | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^^ + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:43:5 | LL | unreachable!(); | ^^^^^^^^^^^^^^^ + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 16 previous errors From f1c77dda068b6922dd41aea54d395096cc260a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Fri, 29 Jan 2021 08:31:08 +0100 Subject: [PATCH 0179/1222] Box the biggest ast::ItemKind variants --- clippy_lints/src/doc.rs | 6 ++- clippy_lints/src/excessive_bools.rs | 16 +++--- clippy_lints/src/non_expressive_names.rs | 9 ++-- clippy_lints/src/utils/ast_utils.rs | 67 +++++++++++++++--------- clippy_lints/src/write.rs | 50 ++++++++++++------ 5 files changed, 94 insertions(+), 54 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 3a754f499178..fa0289c977c7 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -1,7 +1,7 @@ use crate::utils::{implements_trait, is_entrypoint_fn, is_type_diagnostic_item, return_ty, span_lint}; use if_chain::if_chain; use itertools::Itertools; -use rustc_ast::ast::{Async, AttrKind, Attribute, FnRetTy, ItemKind}; +use rustc_ast::ast::{Async, AttrKind, Attribute, FnKind, FnRetTy, ItemKind}; use rustc_ast::token::CommentKind; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; @@ -492,7 +492,9 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) => return false, // We found a main function ... - ItemKind::Fn(_, sig, _, Some(block)) if item.ident.name == sym::main => { + ItemKind::Fn(box FnKind(_, sig, _, Some(block))) + if item.ident.name == sym::main => + { let is_async = matches!(sig.header.asyncness, Async::Yes { .. }); let returns_nothing = match &sig.decl.output { FnRetTy::Default(..) => true, diff --git a/clippy_lints/src/excessive_bools.rs b/clippy_lints/src/excessive_bools.rs index 82ca4baacb7a..fecde8e27434 100644 --- a/clippy_lints/src/excessive_bools.rs +++ b/clippy_lints/src/excessive_bools.rs @@ -1,5 +1,7 @@ use crate::utils::{attr_by_name, in_macro, match_path_ast, span_lint_and_help}; -use rustc_ast::ast::{AssocItemKind, Extern, FnSig, Item, ItemKind, Ty, TyKind}; +use rustc_ast::ast::{ + AssocItemKind, Extern, FnKind, FnSig, ImplKind, Item, ItemKind, TraitKind, Ty, TyKind, +}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; @@ -158,18 +160,16 @@ impl EarlyLintPass for ExcessiveBools { "consider using a state machine or refactoring bools into two-variant enums", ); } - }, - ItemKind::Impl { - of_trait: None, items, .. } - | ItemKind::Trait(_, _, _, _, items) => { + ItemKind::Impl(box ImplKind { of_trait: None, items, .. }) + | ItemKind::Trait(box TraitKind(.., items)) => { for item in items { - if let AssocItemKind::Fn(_, fn_sig, _, _) = &item.kind { + if let AssocItemKind::Fn(box FnKind(_, fn_sig, _, _)) = &item.kind { self.check_fn_sig(cx, fn_sig, item.span); } } - }, - ItemKind::Fn(_, fn_sig, _, _) => self.check_fn_sig(cx, fn_sig, item.span), + } + ItemKind::Fn(box FnKind(_, fn_sig, _, _)) => self.check_fn_sig(cx, fn_sig, item.span), _ => (), } } diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 855529378e65..d5222a030d7a 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -1,5 +1,8 @@ use crate::utils::{span_lint, span_lint_and_then}; -use rustc_ast::ast::{Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Item, ItemKind, Local, Pat, PatKind}; +use rustc_ast::ast::{ + Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, FnKind, Item, ItemKind, Local, Pat, + PatKind, +}; use rustc_ast::visit::{walk_block, walk_expr, walk_pat, Visitor}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_middle::lint::in_external_macro; @@ -364,7 +367,7 @@ impl EarlyLintPass for NonExpressiveNames { return; } - if let ItemKind::Fn(_, ref sig, _, Some(ref blk)) = item.kind { + if let ItemKind::Fn(box FnKind(_, ref sig, _, Some(ref blk))) = item.kind { do_check(self, cx, &item.attrs, &sig.decl, blk); } } @@ -374,7 +377,7 @@ impl EarlyLintPass for NonExpressiveNames { return; } - if let AssocItemKind::Fn(_, ref sig, _, Some(ref blk)) = item.kind { + if let AssocItemKind::Fn(box FnKind(_, ref sig, _, Some(ref blk))) = item.kind { do_check(self, cx, &item.attrs, &sig.decl, blk); } } diff --git a/clippy_lints/src/utils/ast_utils.rs b/clippy_lints/src/utils/ast_utils.rs index eac5d0aa3ee9..69492e84e4ac 100644 --- a/clippy_lints/src/utils/ast_utils.rs +++ b/clippy_lints/src/utils/ast_utils.rs @@ -229,17 +229,26 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { match (l, r) { (ExternCrate(l), ExternCrate(r)) => l == r, (Use(l), Use(r)) => eq_use_tree(l, r), - (Static(lt, lm, le), Static(rt, rm, re)) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), - (Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), - (Fn(ld, lf, lg, lb), Fn(rd, rf, rg, rb)) => { - eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r)) - }, - (Mod(l), Mod(r)) => l.inline == r.inline && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_item_kind)), + (Static(lt, lm, le), Static(rt, rm, re)) => { + lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re) + } + (Const(ld, lt, le), Const(rd, rt, re)) => { + eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re) + } + (Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => { + eq_defaultness(*ld, *rd) + && eq_fn_sig(lf, rf) + && eq_generics(lg, rg) + && both(lb, rb, |l, r| eq_block(l, r)) + } + (Mod(l), Mod(r)) => { + l.inline == r.inline && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_item_kind)) + } (ForeignMod(l), ForeignMod(r)) => { both(&l.abi, &r.abi, |l, r| eq_str_lit(l, r)) && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_foreign_item_kind)) - }, - (TyAlias(ld, lg, lb, lt), TyAlias(rd, rg, rb, rt)) => { + } + (TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => { eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && over(lb, rb, |l, r| eq_generic_bound(l, r)) @@ -250,8 +259,8 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { }, (Struct(lv, lg), Struct(rv, rg)) | (Union(lv, lg), Union(rv, rg)) => { eq_variant_data(lv, rv) && eq_generics(lg, rg) - }, - (Trait(la, lu, lg, lb, li), Trait(ra, ru, rg, rb, ri)) => { + } + (Trait(box TraitKind(la, lu, lg, lb, li)), Trait(box TraitKind(ra, ru, rg, rb, ri))) => { la == ra && matches!(lu, Unsafe::No) == matches!(ru, Unsafe::No) && eq_generics(lg, rg) @@ -260,7 +269,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { }, (TraitAlias(lg, lb), TraitAlias(rg, rb)) => eq_generics(lg, rg) && over(lb, rb, |l, r| eq_generic_bound(l, r)), ( - Impl { + Impl(box ImplKind { unsafety: lu, polarity: lp, defaultness: ld, @@ -269,8 +278,8 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { of_trait: lot, self_ty: lst, items: li, - }, - Impl { + }), + Impl(box ImplKind { unsafety: ru, polarity: rp, defaultness: rd, @@ -279,7 +288,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { of_trait: rot, self_ty: rst, items: ri, - }, + }), ) => { matches!(lu, Unsafe::No) == matches!(ru, Unsafe::No) && matches!(lp, ImplPolarity::Positive) == matches!(rp, ImplPolarity::Positive) @@ -299,11 +308,16 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { use ForeignItemKind::*; match (l, r) { - (Static(lt, lm, le), Static(rt, rm, re)) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), - (Fn(ld, lf, lg, lb), Fn(rd, rf, rg, rb)) => { - eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r)) - }, - (TyAlias(ld, lg, lb, lt), TyAlias(rd, rg, rb, rt)) => { + (Static(lt, lm, le), Static(rt, rm, re)) => { + lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re) + } + (Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => { + eq_defaultness(*ld, *rd) + && eq_fn_sig(lf, rf) + && eq_generics(lg, rg) + && both(lb, rb, |l, r| eq_block(l, r)) + } + (TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => { eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && over(lb, rb, |l, r| eq_generic_bound(l, r)) @@ -317,11 +331,16 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { use AssocItemKind::*; match (l, r) { - (Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), - (Fn(ld, lf, lg, lb), Fn(rd, rf, rg, rb)) => { - eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r)) - }, - (TyAlias(ld, lg, lb, lt), TyAlias(rd, rg, rb, rt)) => { + (Const(ld, lt, le), Const(rd, rt, re)) => { + eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re) + } + (Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => { + eq_defaultness(*ld, *rd) + && eq_fn_sig(lf, rf) + && eq_generics(lg, rg) + && both(lb, rb, |l, r| eq_block(l, r)) + } + (TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => { eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && over(lb, rb, |l, r| eq_generic_bound(l, r)) diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 6358104eedad..b9e97077c540 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -3,7 +3,9 @@ use std::ops::Range; use crate::utils::{snippet_with_applicability, span_lint, span_lint_and_sugg, span_lint_and_then}; use if_chain::if_chain; -use rustc_ast::ast::{Expr, ExprKind, Item, ItemKind, LitKind, MacCall, StrLit, StrStyle}; +use rustc_ast::ast::{ + Expr, ExprKind, ImplKind, Item, ItemKind, LitKind, MacCall, StrLit, StrStyle, +}; use rustc_ast::token; use rustc_ast::tokenstream::TokenStream; use rustc_errors::Applicability; @@ -231,11 +233,7 @@ impl_lint_pass!(Write => [ impl EarlyLintPass for Write { fn check_item(&mut self, _: &EarlyContext<'_>, item: &Item) { - if let ItemKind::Impl { - of_trait: Some(trait_ref), - .. - } = &item.kind - { + if let ItemKind::Impl(box ImplKind { of_trait: Some(trait_ref), .. }) = &item.kind { let trait_name = trait_ref .path .segments @@ -377,10 +375,15 @@ impl Write { /// (Some("string to write: {}"), Some(buf)) /// ``` #[allow(clippy::too_many_lines)] - fn check_tts<'a>(&self, cx: &EarlyContext<'a>, tts: TokenStream, is_write: bool) -> (Option, Option) { + fn check_tts<'a>( + &self, + cx: &EarlyContext<'a>, + tts: TokenStream, + is_write: bool, + ) -> (Option, Option) { use rustc_parse_format::{ - AlignUnknown, ArgumentImplicitlyIs, ArgumentIs, ArgumentNamed, CountImplied, FormatSpec, ParseMode, Parser, - Piece, + AlignUnknown, ArgumentImplicitlyIs, ArgumentIs, ArgumentNamed, CountImplied, + FormatSpec, ParseMode, Parser, Piece, }; let mut parser = parser::Parser::new(&cx.sess.parse_sess, tts, false, None); @@ -410,7 +413,12 @@ impl Write { if let Piece::NextArgument(arg) = piece { if !self.in_debug_impl && arg.format.ty == "?" { // FIXME: modify rustc's fmt string parser to give us the current span - span_lint(cx, USE_DEBUG, parser.prev_token.span, "use of `Debug`-based formatting"); + span_lint( + cx, + USE_DEBUG, + parser.prev_token.span, + "use of `Debug`-based formatting", + ); } args.push(arg); } @@ -438,7 +446,9 @@ impl Write { return (Some(fmtstr), None); }; match &token_expr.kind { - ExprKind::Lit(lit) if !matches!(lit.kind, LitKind::Int(..) | LitKind::Float(..)) => { + ExprKind::Lit(lit) + if !matches!(lit.kind, LitKind::Int(..) | LitKind::Float(..)) => + { let mut all_simple = true; let mut seen = false; for arg in &args { @@ -448,15 +458,15 @@ impl Write { all_simple &= arg.format == SIMPLE; seen = true; } - }, - ArgumentNamed(_) => {}, + } + ArgumentNamed(_) => {} } } if all_simple && seen { span_lint(cx, lint, token_expr.span, "literal with an empty format string"); } idx += 1; - }, + } ExprKind::Assign(lhs, rhs, _) => { if_chain! { if let ExprKind::Lit(ref lit) = rhs.kind; @@ -481,7 +491,7 @@ impl Write { } } } - }, + } _ => idx += 1, } } @@ -513,11 +523,17 @@ impl Write { cx, PRINT_WITH_NEWLINE, mac.span(), - &format!("using `{}!()` with a format string that ends in a single newline", name), + &format!( + "using `{}!()` with a format string that ends in a single newline", + name + ), |err| { err.multipart_suggestion( &format!("use `{}!` instead", suggested), - vec![(mac.path.span, suggested), (newline_span(&fmt_str), String::new())], + vec![ + (mac.path.span, suggested), + (newline_span(&fmt_str), String::new()), + ], Applicability::MachineApplicable, ); }, From 3ab758f59ec4b548cfe622d8577b2341f3d69390 Mon Sep 17 00:00:00 2001 From: Vasili Novikov Date: Fri, 22 Jan 2021 09:51:23 +0100 Subject: [PATCH 0180/1222] Add .editorconfig Editorconfig is a lightweight specification that helps maintaining consistent coding/formatting style accross editors, especially those editors that are not explicitly aware of Rust and rustfmt. https://editorconfig.org/ --- .editorconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.editorconfig b/.editorconfig index a13173544d80..ec6e107d547f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,6 +13,8 @@ indent_style = space indent_size = 4 [*.md] +# double whitespace at end of line +# denotes a line break in Markdown trim_trailing_whitespace = false [*.yml] From 6754ccfdb003b488fb208213785c3906abfe0f82 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Tue, 2 Feb 2021 12:28:58 -0600 Subject: [PATCH 0181/1222] Use PrimTy in builtin type shadow lint --- clippy_lints/src/misc_early.rs | 8 ++++---- clippy_lints/src/utils/constants.rs | 13 ------------- clippy_lints/src/utils/mod.rs | 1 - 3 files changed, 4 insertions(+), 18 deletions(-) delete mode 100644 clippy_lints/src/utils/constants.rs diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index 5bc45c87874b..84a0df92f5b4 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -1,4 +1,4 @@ -use crate::utils::{constants, snippet_opt, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then}; +use crate::utils::{snippet_opt, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then}; use rustc_ast::ast::{ BindingMode, Expr, ExprKind, GenericParamKind, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability, NodeId, Pat, PatKind, UnOp, @@ -6,6 +6,7 @@ use rustc_ast::ast::{ use rustc_ast::visit::FnKind; use rustc_data_structures::fx::FxHashMap; use rustc_errors::Applicability; +use rustc_hir::PrimTy; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -264,13 +265,12 @@ impl EarlyLintPass for MiscEarlyLints { fn check_generics(&mut self, cx: &EarlyContext<'_>, gen: &Generics) { for param in &gen.params { if let GenericParamKind::Type { .. } = param.kind { - let name = param.ident.as_str(); - if constants::BUILTIN_TYPES.contains(&&*name) { + if let Some(prim_ty) = PrimTy::from_name(param.ident.name) { span_lint( cx, BUILTIN_TYPE_SHADOW, param.ident.span, - &format!("this generic shadows the built-in type `{}`", name), + &format!("this generic shadows the built-in type `{}`", prim_ty.name()), ); } } diff --git a/clippy_lints/src/utils/constants.rs b/clippy_lints/src/utils/constants.rs deleted file mode 100644 index 522932f054d8..000000000000 --- a/clippy_lints/src/utils/constants.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! This module contains some useful constants. - -#![deny(clippy::missing_docs_in_private_items)] - -/// List of the built-in types names. -/// -/// See also [the reference][reference-types] for a list of such types. -/// -/// [reference-types]: https://doc.rust-lang.org/reference/types.html -pub const BUILTIN_TYPES: &[&str] = &[ - "i8", "u8", "i16", "u16", "i32", "u32", "i64", "u64", "i128", "u128", "isize", "usize", "f32", "f64", "bool", - "str", "char", -]; diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index d0db3a67533b..e639d33ed471 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -8,7 +8,6 @@ pub mod author; pub mod camel_case; pub mod comparisons; pub mod conf; -pub mod constants; mod diagnostics; pub mod eager_or_lazy; pub mod higher; From aee8d74583f223453e85a5ce82ae5df8de2a4f09 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Tue, 2 Feb 2021 20:24:42 +0100 Subject: [PATCH 0182/1222] Fix/allow non_fmt_panic in clippy tests. --- tests/missing-test-files.rs | 14 ++++++-------- tests/ui/assertions_on_constants.rs | 2 ++ tests/ui/assertions_on_constants.stderr | 18 +++++++++--------- tests/ui/fallible_impl_from.rs | 2 +- tests/ui/fallible_impl_from.stderr | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/missing-test-files.rs b/tests/missing-test-files.rs index d87bb4be3c3f..9cef7438d225 100644 --- a/tests/missing-test-files.rs +++ b/tests/missing-test-files.rs @@ -9,14 +9,12 @@ fn test_missing_tests() { if !missing_files.is_empty() { assert!( false, - format!( - "Didn't see a test file for the following files:\n\n{}\n", - missing_files - .iter() - .map(|s| format!("\t{}", s)) - .collect::>() - .join("\n") - ) + "Didn't see a test file for the following files:\n\n{}\n", + missing_files + .iter() + .map(|s| format!("\t{}", s)) + .collect::>() + .join("\n") ); } } diff --git a/tests/ui/assertions_on_constants.rs b/tests/ui/assertions_on_constants.rs index 60d721c2f204..e989de654045 100644 --- a/tests/ui/assertions_on_constants.rs +++ b/tests/ui/assertions_on_constants.rs @@ -1,3 +1,5 @@ +#![allow(non_fmt_panic)] + macro_rules! assert_const { ($len:expr) => { assert!($len > 0); diff --git a/tests/ui/assertions_on_constants.stderr b/tests/ui/assertions_on_constants.stderr index 8f09c8ce9d52..c66fdf093f51 100644 --- a/tests/ui/assertions_on_constants.stderr +++ b/tests/ui/assertions_on_constants.stderr @@ -1,5 +1,5 @@ error: `assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:9:5 + --> $DIR/assertions_on_constants.rs:11:5 | LL | assert!(true); | ^^^^^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | assert!(true); = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(false)` should probably be replaced - --> $DIR/assertions_on_constants.rs:10:5 + --> $DIR/assertions_on_constants.rs:12:5 | LL | assert!(false); | ^^^^^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | assert!(false); = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:11:5 + --> $DIR/assertions_on_constants.rs:13:5 | LL | assert!(true, "true message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL | assert!(true, "true message"); = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(false, "false message")` should probably be replaced - --> $DIR/assertions_on_constants.rs:12:5 + --> $DIR/assertions_on_constants.rs:14:5 | LL | assert!(false, "false message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | assert!(false, "false message"); = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(false, msg.to_uppercase())` should probably be replaced - --> $DIR/assertions_on_constants.rs:15:5 + --> $DIR/assertions_on_constants.rs:17:5 | LL | assert!(false, msg.to_uppercase()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | assert!(false, msg.to_uppercase()); = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:18:5 + --> $DIR/assertions_on_constants.rs:20:5 | LL | assert!(B); | ^^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | assert!(B); = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(false)` should probably be replaced - --> $DIR/assertions_on_constants.rs:21:5 + --> $DIR/assertions_on_constants.rs:23:5 | LL | assert!(C); | ^^^^^^^^^^^ @@ -63,7 +63,7 @@ LL | assert!(C); = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(false, "C message")` should probably be replaced - --> $DIR/assertions_on_constants.rs:22:5 + --> $DIR/assertions_on_constants.rs:24:5 | LL | assert!(C, "C message"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | assert!(C, "C message"); = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: `debug_assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:24:5 + --> $DIR/assertions_on_constants.rs:26:5 | LL | debug_assert!(true); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/fallible_impl_from.rs b/tests/ui/fallible_impl_from.rs index 679f4a7dc357..5d5af4e46329 100644 --- a/tests/ui/fallible_impl_from.rs +++ b/tests/ui/fallible_impl_from.rs @@ -36,7 +36,7 @@ impl From> for Invalid { fn from(s: Option) -> Invalid { let s = s.unwrap(); if !s.is_empty() { - panic!(42); + panic!("42"); } else if s.parse::().unwrap() != 42 { panic!("{:?}", s); } diff --git a/tests/ui/fallible_impl_from.stderr b/tests/ui/fallible_impl_from.stderr index ab976b947b35..f787b30bdabc 100644 --- a/tests/ui/fallible_impl_from.stderr +++ b/tests/ui/fallible_impl_from.stderr @@ -59,8 +59,8 @@ note: potential failure(s) LL | let s = s.unwrap(); | ^^^^^^^^^^ LL | if !s.is_empty() { -LL | panic!(42); - | ^^^^^^^^^^^ +LL | panic!("42"); + | ^^^^^^^^^^^^^ LL | } else if s.parse::().unwrap() != 42 { | ^^^^^^^^^^^^^^^^^^^^^^^^^ LL | panic!("{:?}", s); From cbab128a98caa3d2530ca30e93101bd0e206267f Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 3 Feb 2021 10:55:33 +0100 Subject: [PATCH 0183/1222] Suggest panic!("{}", ..) instead of panic!(..) clippy::expect_fun_call. --- clippy_lints/src/methods/mod.rs | 2 +- tests/ui/expect_fun_call.fixed | 10 +++++----- tests/ui/expect_fun_call.stderr | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index a17c5996293e..4ee423b383b0 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2183,7 +2183,7 @@ fn lint_expect_fun_call( span_replace_word, &format!("use of `{}` followed by a function call", name), "try this", - format!("unwrap_or_else({} {{ panic!({}) }})", closure_args, arg_root_snippet), + format!("unwrap_or_else({} {{ panic!(\"{{}}\", {}) }})", closure_args, arg_root_snippet), applicability, ); } diff --git a/tests/ui/expect_fun_call.fixed b/tests/ui/expect_fun_call.fixed index f3d8a941a92b..a756d1cf5065 100644 --- a/tests/ui/expect_fun_call.fixed +++ b/tests/ui/expect_fun_call.fixed @@ -74,12 +74,12 @@ fn main() { "foo" } - Some("foo").unwrap_or_else(|| { panic!(get_string()) }); - Some("foo").unwrap_or_else(|| { panic!(get_string()) }); - Some("foo").unwrap_or_else(|| { panic!(get_string()) }); + Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) }); + Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) }); + Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) }); - Some("foo").unwrap_or_else(|| { panic!(get_static_str()) }); - Some("foo").unwrap_or_else(|| { panic!(get_non_static_str(&0).to_string()) }); + Some("foo").unwrap_or_else(|| { panic!("{}", get_static_str()) }); + Some("foo").unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) }); } //Issue #3839 diff --git a/tests/ui/expect_fun_call.stderr b/tests/ui/expect_fun_call.stderr index a492e2df89d4..6dc796f5cee3 100644 --- a/tests/ui/expect_fun_call.stderr +++ b/tests/ui/expect_fun_call.stderr @@ -34,31 +34,31 @@ error: use of `expect` followed by a function call --> $DIR/expect_fun_call.rs:77:21 | LL | Some("foo").expect(&get_string()); - | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })` + | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })` error: use of `expect` followed by a function call --> $DIR/expect_fun_call.rs:78:21 | LL | Some("foo").expect(get_string().as_ref()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })` error: use of `expect` followed by a function call --> $DIR/expect_fun_call.rs:79:21 | LL | Some("foo").expect(get_string().as_str()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })` error: use of `expect` followed by a function call --> $DIR/expect_fun_call.rs:81:21 | LL | Some("foo").expect(get_static_str()); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_static_str()) })` + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_static_str()) })` error: use of `expect` followed by a function call --> $DIR/expect_fun_call.rs:82:21 | LL | Some("foo").expect(get_non_static_str(&0)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_non_static_str(&0).to_string()) })` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) })` error: use of `expect` followed by a function call --> $DIR/expect_fun_call.rs:86:16 From 3931a00e33b8d33df692532a2ebab0d680f10960 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 5 Feb 2021 18:29:05 -0500 Subject: [PATCH 0184/1222] Bump clippy version --- Cargo.toml | 2 +- clippy_lints/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e60aa472846c..e7755c46eb80 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.1.51" +version = "0.1.52" authors = [ "Manish Goregaokar ", "Andre Bogus ", diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index a9516560a619..840341fefc6a 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippy_lints" # begin automatic update -version = "0.1.51" +version = "0.1.52" # end automatic update authors = [ "Manish Goregaokar ", From c5803168c6c7ed1ff94b08ad4d86a7a4fdf9edbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Tue, 9 Feb 2021 11:15:53 +0300 Subject: [PATCH 0185/1222] Rename HIR UnOp variants This renames the variants in HIR UnOp from enum UnOp { UnDeref, UnNot, UnNeg, } to enum UnOp { Deref, Not, Neg, } Motivations: - This is more consistent with the rest of the code base where most enum variants don't have a prefix. - These variants are never used without the `UnOp` prefix so the extra `Un` prefix doesn't help with readability. E.g. we don't have any `UnDeref`s in the code, we only have `UnOp::UnDeref`. - MIR `UnOp` type variants don't have a prefix so this is more consistent with MIR types. - "un" prefix reads like "inverse" or "reverse", so as a beginner in rustc code base when I see "UnDeref" what comes to my mind is something like "&*" instead of just "*". --- clippy_lints/src/arithmetic.rs | 4 ++-- clippy_lints/src/assertions_on_constants.rs | 2 +- clippy_lints/src/booleans.rs | 6 +++--- clippy_lints/src/bytecount.rs | 2 +- clippy_lints/src/collapsible_match.rs | 2 +- clippy_lints/src/consts.rs | 6 +++--- clippy_lints/src/entry.rs | 2 +- clippy_lints/src/floating_point_arithmetic.rs | 6 +++--- clippy_lints/src/functions.rs | 2 +- clippy_lints/src/map_clone.rs | 2 +- .../src/methods/manual_saturating_arithmetic.rs | 4 ++-- clippy_lints/src/methods/mod.rs | 10 +++++----- clippy_lints/src/misc.rs | 4 ++-- clippy_lints/src/needless_bool.rs | 2 +- clippy_lints/src/neg_cmp_op_on_partial_ord.rs | 2 +- clippy_lints/src/neg_multiply.rs | 4 ++-- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/option_if_let_else.rs | 2 +- clippy_lints/src/shadow.rs | 2 +- clippy_lints/src/suspicious_trait_impl.rs | 2 +- clippy_lints/src/transmute.rs | 2 +- clippy_lints/src/types.rs | 6 +++--- clippy_lints/src/unwrap.rs | 2 +- clippy_lints/src/utils/higher.rs | 2 +- clippy_lints/src/utils/internal_lints.rs | 2 +- tests/ui/suspicious_arithmetic_impl.rs | 4 ++-- 26 files changed, 43 insertions(+), 43 deletions(-) diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs index 9861d8cfc4e5..61fdf9495b91 100644 --- a/clippy_lints/src/arithmetic.rs +++ b/clippy_lints/src/arithmetic.rs @@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for Arithmetic { match op.node { hir::BinOpKind::Div | hir::BinOpKind::Rem => match &r.kind { hir::ExprKind::Lit(_lit) => (), - hir::ExprKind::Unary(hir::UnOp::UnNeg, expr) => { + hir::ExprKind::Unary(hir::UnOp::Neg, expr) => { if let hir::ExprKind::Lit(lit) = &expr.kind { if let rustc_ast::ast::LitKind::Int(1, _) = lit.node { span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected"); @@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for Arithmetic { self.expr_span = Some(expr.span); } }, - hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => { + hir::ExprKind::Unary(hir::UnOp::Neg, arg) => { let ty = cx.typeck_results().expr_ty(arg); if constant_simple(cx, cx.typeck_results(), expr).is_none() { if ty.is_integral() { diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index aa431f0596cc..77b26faaa586 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -112,7 +112,7 @@ enum AssertKind { fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option { if_chain! { if let ExprKind::If(ref cond, ref then, _) = expr.kind; - if let ExprKind::Unary(UnOp::UnNot, ref expr) = cond.kind; + if let ExprKind::Unary(UnOp::Not, ref expr) = cond.kind; // bind the first argument of the `assert!` macro if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), expr); // block diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 90bb0bd555f2..0713303ec4b6 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -110,7 +110,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> { // prevent folding of `cfg!` macros and the like if !e.span.from_expansion() { match &e.kind { - ExprKind::Unary(UnOp::UnNot, inner) => return Ok(Bool::Not(box self.run(inner)?)), + ExprKind::Unary(UnOp::Not, inner) => return Ok(Bool::Not(box self.run(inner)?)), ExprKind::Binary(binop, lhs, rhs) => match &binop.node { BinOpKind::Or => { return Ok(Bool::Or(self.extract(BinOpKind::Or, &[lhs, rhs], Vec::new())?)); @@ -454,7 +454,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { ExprKind::Binary(binop, _, _) if binop.node == BinOpKind::Or || binop.node == BinOpKind::And => { self.bool_expr(e) }, - ExprKind::Unary(UnOp::UnNot, inner) => { + ExprKind::Unary(UnOp::Not, inner) => { if self.cx.typeck_results().node_types()[inner.hir_id].is_bool() { self.bool_expr(e); } else { @@ -482,7 +482,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> { type Map = Map<'tcx>; fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if let ExprKind::Unary(UnOp::UnNot, inner) = &expr.kind { + if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind { if let Some(suggestion) = simplify_not(self.cx, inner) { span_lint_and_sugg( self.cx, diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index ac9098a7584d..b8828719f627 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -101,7 +101,7 @@ fn check_arg(name: Symbol, arg: Symbol, needle: &Expr<'_>) -> bool { fn get_path_name(expr: &Expr<'_>) -> Option { match expr.kind { - ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) | ExprKind::Unary(UnOp::UnDeref, ref e) => { + ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) | ExprKind::Unary(UnOp::Deref, ref e) => { get_path_name(e) }, ExprKind::Block(ref b, _) => { diff --git a/clippy_lints/src/collapsible_match.rs b/clippy_lints/src/collapsible_match.rs index 604ba1020469..b83aae0e5719 100644 --- a/clippy_lints/src/collapsible_match.rs +++ b/clippy_lints/src/collapsible_match.rs @@ -186,7 +186,7 @@ fn addr_adjusted_binding(mut expr: &Expr<'_>, cx: &LateContext<'_>) -> Option break Some(binding_id), _ => break None, }, - ExprKind::Unary(UnOp::UnDeref, e) if cx.typeck_results().expr_ty(e).is_ref() => expr = e, + ExprKind::Unary(UnOp::Deref, e) if cx.typeck_results().expr_ty(e).is_ref() => expr = e, _ => break None, } } diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 640cffd24a70..1b89d0bbe386 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -242,9 +242,9 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { self.expr(value).map(|v| Constant::Repeat(Box::new(v), n)) }, ExprKind::Unary(op, ref operand) => self.expr(operand).and_then(|o| match op { - UnOp::UnNot => self.constant_not(&o, self.typeck_results.expr_ty(e)), - UnOp::UnNeg => self.constant_negate(&o, self.typeck_results.expr_ty(e)), - UnOp::UnDeref => Some(if let Constant::Ref(r) = o { *r } else { o }), + UnOp::Not => self.constant_not(&o, self.typeck_results.expr_ty(e)), + UnOp::Neg => self.constant_negate(&o, self.typeck_results.expr_ty(e)), + UnOp::Deref => Some(if let Constant::Ref(r) = o { *r } else { o }), }), ExprKind::If(ref cond, ref then, ref otherwise) => self.ifthenelse(cond, then, *otherwise), ExprKind::Binary(op, ref left, ref right) => self.binop(op, left, right), diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 37948e06869c..6b9f9a567548 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -55,7 +55,7 @@ declare_lint_pass!(HashMapPass => [MAP_ENTRY]); impl<'tcx> LateLintPass<'tcx> for HashMapPass { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::If(ref check, ref then_block, ref else_block) = expr.kind { - if let ExprKind::Unary(UnOp::UnNot, ref check) = check.kind { + if let ExprKind::Unary(UnOp::Not, ref check) = check.kind { if let Some((ty, map, key)) = check_cond(cx, check) { // in case of `if !m.contains_key(&k) { m.insert(k, v); }` // we can give a better error message diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index ffef78aac806..086a791520fa 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -129,7 +129,7 @@ fn get_specialized_log_method(cx: &LateContext<'_>, base: &Expr<'_>) -> Option<& fn prepare_receiver_sugg<'a>(cx: &LateContext<'_>, mut expr: &'a Expr<'a>) -> Sugg<'a> { let mut suggestion = Sugg::hir(cx, expr, ".."); - if let ExprKind::Unary(UnOp::UnNeg, inner_expr) = &expr.kind { + if let ExprKind::Unary(UnOp::Neg, inner_expr) = &expr.kind { expr = &inner_expr; } @@ -541,12 +541,12 @@ fn is_zero(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { /// If the two expressions are not negations of each other, then it /// returns None. fn are_negated<'a>(cx: &LateContext<'_>, expr1: &'a Expr<'a>, expr2: &'a Expr<'a>) -> Option<(bool, &'a Expr<'a>)> { - if let ExprKind::Unary(UnOp::UnNeg, expr1_negated) = &expr1.kind { + if let ExprKind::Unary(UnOp::Neg, expr1_negated) = &expr1.kind { if eq_expr_value(cx, expr1_negated, expr2) { return Some((false, expr2)); } } - if let ExprKind::Unary(UnOp::UnNeg, expr2_negated) = &expr2.kind { + if let ExprKind::Unary(UnOp::Neg, expr2_negated) = &expr2.kind { if eq_expr_value(cx, expr1, expr2_negated) { return Some((true, expr1)); } diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 879542546103..71a146cc2980 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -644,7 +644,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { } } }, - hir::ExprKind::Unary(hir::UnOp::UnDeref, ref ptr) => self.check_arg(ptr), + hir::ExprKind::Unary(hir::UnOp::Deref, ref ptr) => self.check_arg(ptr), _ => (), } diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 1818836d5d5e..bd0be8802890 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone { }, hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, .., name, None) => { match closure_expr.kind { - hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner) => { + hir::ExprKind::Unary(hir::UnOp::Deref, ref inner) => { if ident_eq(name, inner) { if let ty::Ref(.., Mutability::Not) = cx.typeck_results().expr_ty(inner).kind() { lint(cx, e.span, args[0].span, true); diff --git a/clippy_lints/src/methods/manual_saturating_arithmetic.rs b/clippy_lints/src/methods/manual_saturating_arithmetic.rs index 44c974b9d985..eaa604c2ae63 100644 --- a/clippy_lints/src/methods/manual_saturating_arithmetic.rs +++ b/clippy_lints/src/methods/manual_saturating_arithmetic.rs @@ -148,7 +148,7 @@ fn is_min_or_max<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>) -> Option) -> Option { - if let hir::ExprKind::Unary(hir::UnOp::UnNeg, inner) = &expr.kind { + if let hir::ExprKind::Unary(hir::UnOp::Neg, inner) = &expr.kind { if let hir::ExprKind::Lit(..) = &inner.kind { return Some(Sign::Neg); } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 4ee423b383b0..0918843294d4 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2619,7 +2619,7 @@ fn lint_get_unwrap<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, get_args: if_chain! { if needs_ref; if let Some(parent) = get_parent_expr(cx, expr); - if let hir::ExprKind::Unary(hir::UnOp::UnDeref, _) = parent.kind; + if let hir::ExprKind::Unary(hir::UnOp::Deref, _) = parent.kind; then { needs_ref = false; span = parent.span; @@ -3063,7 +3063,7 @@ fn lint_filter_map<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, is_f // in `filter(|x| ..)`, replace `*x` with `x` let a_path = if_chain! { if !is_filter_param_ref; - if let ExprKind::Unary(UnOp::UnDeref, expr_path) = a.kind; + if let ExprKind::Unary(UnOp::Deref, expr_path) = a.kind; then { expr_path } else { a } }; // let the filter closure arg and the map closure arg be equal @@ -3708,8 +3708,8 @@ fn lint_option_as_ref_deref<'tcx>( }, hir::ExprKind::AddrOf(hir::BorrowKind::Ref, m, ref inner) if same_mutability(m) => { if_chain! { - if let hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner1) = inner.kind; - if let hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner2) = inner1.kind; + if let hir::ExprKind::Unary(hir::UnOp::Deref, ref inner1) = inner.kind; + if let hir::ExprKind::Unary(hir::UnOp::Deref, ref inner2) = inner1.kind; if let hir::ExprKind::Path(ref qpath) = inner2.kind; if let hir::def::Res::Local(local_id) = cx.qpath_res(qpath, inner2.hir_id); then { @@ -4065,7 +4065,7 @@ fn lint_filetype_is_file(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir if_chain! { if let Some(parent) = get_parent_expr(cx, expr); if let hir::ExprKind::Unary(op, _) = parent.kind; - if op == hir::UnOp::UnNot; + if op == hir::UnOp::Not; then { lint_unary = "!"; verb = "denies"; diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 0512d74c7b1c..2ef5c6aa2a4e 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -502,7 +502,7 @@ fn is_allowed<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool { // Return true if `expr` is the result of `signum()` invoked on a float value. fn is_signum(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { // The negation of a signum is still a signum - if let ExprKind::Unary(UnOp::UnNeg, ref child_expr) = expr.kind { + if let ExprKind::Unary(UnOp::Neg, ref child_expr) = expr.kind { return is_signum(cx, &child_expr); } @@ -586,7 +586,7 @@ fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: return; } - let other_gets_derefed = matches!(other.kind, ExprKind::Unary(UnOp::UnDeref, _)); + let other_gets_derefed = matches!(other.kind, ExprKind::Unary(UnOp::Deref, _)); let lint_span = if other_gets_derefed { expr.span.to(other.span) diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index d795f1264579..f283ff1715fb 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -195,7 +195,7 @@ struct ExpressionInfoWithSpan { } fn is_unary_not(e: &Expr<'_>) -> (bool, Span) { - if let ExprKind::Unary(UnOp::UnNot, operand) = e.kind { + if let ExprKind::Unary(UnOp::Not, operand) = e.kind { return (true, operand.span); } (false, e.span) diff --git a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs index 4fb899125e8a..ec0ad58ca9c3 100644 --- a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for NoNegCompOpForPartialOrd { if_chain! { if !in_external_macro(cx.sess(), expr.span); - if let ExprKind::Unary(UnOp::UnNot, ref inner) = expr.kind; + if let ExprKind::Unary(UnOp::Not, ref inner) = expr.kind; if let ExprKind::Binary(ref op, ref left, _) = inner.kind; if let BinOpKind::Le | BinOpKind::Ge | BinOpKind::Lt | BinOpKind::Gt = op.node; diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index aa550510867f..ef7cc65cfcf0 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -32,8 +32,8 @@ impl<'tcx> LateLintPass<'tcx> for NegMultiply { if BinOpKind::Mul == op.node { match (&left.kind, &right.kind) { (&ExprKind::Unary(..), &ExprKind::Unary(..)) => {}, - (&ExprKind::Unary(UnOp::UnNeg, ref lit), _) => check_mul(cx, e.span, lit, right), - (_, &ExprKind::Unary(UnOp::UnNeg, ref lit)) => check_mul(cx, e.span, lit, left), + (&ExprKind::Unary(UnOp::Neg, ref lit), _) => check_mul(cx, e.span, lit, right), + (_, &ExprKind::Unary(UnOp::Neg, ref lit)) => check_mul(cx, e.span, lit, left), _ => {}, } } diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index f57d75363175..0b2262d84907 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -383,7 +383,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { needs_check_adjustment = false; break; }, - ExprKind::Unary(UnOp::UnDeref, _) => { + ExprKind::Unary(UnOp::Deref, _) => { // `*e` => desugared to `*Deref::deref(&e)`, // meaning `e` must be referenced. // no need to go further up since a method call is involved now. diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index 7bdf975ffd44..9ef0d267b0b2 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -181,7 +181,7 @@ fn detect_option_if_let_else<'tcx>( }; let cond_expr = match &cond_expr.kind { // Pointer dereferencing happens automatically, so we can omit it in the suggestion - ExprKind::Unary(UnOp::UnDeref, expr) | ExprKind::AddrOf(_, _, expr) => expr, + ExprKind::Unary(UnOp::Deref, expr) | ExprKind::AddrOf(_, _, expr) => expr, _ => cond_expr, }; Some(OptionIfLetElseOccurence { diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index d5b1767e945b..32f6bc74642c 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -389,7 +389,7 @@ fn is_self_shadow(name: Symbol, expr: &Expr<'_>) -> bool { ExprKind::Block(ref block, _) => { block.stmts.is_empty() && block.expr.as_ref().map_or(false, |e| is_self_shadow(name, e)) }, - ExprKind::Unary(op, ref inner) => (UnOp::UnDeref == op) && is_self_shadow(name, inner), + ExprKind::Unary(op, ref inner) => (UnOp::Deref == op) && is_self_shadow(name, inner), ExprKind::Path(QPath::Resolved(_, ref path)) => path_eq_name(name, path), _ => false, } diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index 3a688a7bbef3..0b7d08cb1645 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -194,7 +194,7 @@ impl<'tcx> Visitor<'tcx> for BinaryExprVisitor { fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { match expr.kind { hir::ExprKind::Binary(..) - | hir::ExprKind::Unary(hir::UnOp::UnNot | hir::UnOp::UnNeg, _) + | hir::ExprKind::Unary(hir::UnOp::Not | hir::UnOp::Neg, _) | hir::ExprKind::AssignOp(..) => self.nb_binops += 1, _ => {}, } diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index d977cea4da50..dc938ed02383 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -586,7 +586,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { let mut expr = &args[0]; let mut arg = sugg::Sugg::hir(cx, expr, ".."); - if let ExprKind::Unary(UnOp::UnNeg, inner_expr) = &expr.kind { + if let ExprKind::Unary(UnOp::Neg, inner_expr) = &expr.kind { expr = &inner_expr; } diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 04c32ce9e8f2..58af5b12c373 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -1706,13 +1706,13 @@ impl<'tcx> LateLintPass<'tcx> for Casts { } fn is_unary_neg(expr: &Expr<'_>) -> bool { - matches!(expr.kind, ExprKind::Unary(UnOp::UnNeg, _)) + matches!(expr.kind, ExprKind::Unary(UnOp::Neg, _)) } fn get_numeric_literal<'e>(expr: &'e Expr<'e>) -> Option<&'e Lit> { match expr.kind { ExprKind::Lit(ref lit) => Some(lit), - ExprKind::Unary(UnOp::UnNeg, e) => { + ExprKind::Unary(UnOp::Neg, e) => { if let ExprKind::Lit(ref lit) = e.kind { Some(lit) } else { @@ -2868,7 +2868,7 @@ declare_lint_pass!(RefToMut => [CAST_REF_TO_MUT]); impl<'tcx> LateLintPass<'tcx> for RefToMut { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { - if let ExprKind::Unary(UnOp::UnDeref, e) = &expr.kind; + if let ExprKind::Unary(UnOp::Deref, e) = &expr.kind; if let ExprKind::Cast(e, t) = &e.kind; if let TyKind::Ptr(MutTy { mutbl: Mutability::Mut, .. }) = t.kind; if let ExprKind::Cast(e, t) = &e.kind; diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index b82909eaea60..2fb0463c5a6c 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -108,7 +108,7 @@ fn collect_unwrap_info<'tcx>( }, _ => (), } - } else if let ExprKind::Unary(UnOp::UnNot, expr) = &expr.kind { + } else if let ExprKind::Unary(UnOp::Not, expr) = &expr.kind { return collect_unwrap_info(cx, expr, branch, !invert); } else { if_chain! { diff --git a/clippy_lints/src/utils/higher.rs b/clippy_lints/src/utils/higher.rs index 340d340d6d34..145703d1bdc3 100644 --- a/clippy_lints/src/utils/higher.rs +++ b/clippy_lints/src/utils/higher.rs @@ -243,7 +243,7 @@ pub fn extract_assert_macro_args<'tcx>(e: &'tcx Expr<'tcx>) -> Option Self { - Bar(self.0 & !other.0) // OK: UnNot part of BiExpr as child node + Bar(self.0 & !other.0) // OK: Not part of BiExpr as child node } } @@ -126,7 +126,7 @@ impl Sub for Bar { fn sub(self, other: Self) -> Self { if self.0 <= other.0 { - Bar(-(self.0 & other.0)) // OK: UnNeg part of BiExpr as parent node + Bar(-(self.0 & other.0)) // OK: Neg part of BiExpr as parent node } else { Bar(0) } From 0e742f01f7c393ce0de52d9d49be0813b55b564c Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sat, 13 Feb 2021 18:58:54 +0100 Subject: [PATCH 0186/1222] Fix clippy's path to the copy intrinsics. --- clippy_lints/src/utils/paths.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index c0b203b5388d..e59aa76e303f 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -20,8 +20,8 @@ pub const CLONE_TRAIT: [&str; 3] = ["core", "clone", "Clone"]; pub const CLONE_TRAIT_METHOD: [&str; 4] = ["core", "clone", "Clone", "clone"]; pub const CMP_MAX: [&str; 3] = ["core", "cmp", "max"]; pub const CMP_MIN: [&str; 3] = ["core", "cmp", "min"]; -pub const COPY: [&str; 3] = ["core", "intrinsics", "copy_nonoverlapping"]; -pub const COPY_NONOVERLAPPING: [&str; 3] = ["core", "intrinsics", "copy"]; +pub const COPY: [&str; 4] = ["core", "intrinsics", "", "copy_nonoverlapping"]; +pub const COPY_NONOVERLAPPING: [&str; 4] = ["core", "intrinsics", "", "copy"]; pub const COW: [&str; 3] = ["alloc", "borrow", "Cow"]; pub const CSTRING_AS_C_STR: [&str; 5] = ["std", "ffi", "c_str", "CString", "as_c_str"]; pub const DEFAULT_TRAIT: [&str; 3] = ["core", "default", "Default"]; From 7599b7e221caff80367e43f7979124c76932a738 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 30 Jan 2021 12:06:04 +0100 Subject: [PATCH 0187/1222] Use ItemId as a strongly typed index. --- clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/manual_async_fn.rs | 2 +- clippy_lints/src/missing_inline.rs | 2 +- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/utils/inspector.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index e84c8b4e5b3e..05c747eee076 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -375,7 +375,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { match ty.kind { TyKind::OpaqueDef(item, _) => { let map = self.cx.tcx.hir(); - let item = map.expect_item(item.id); + let item = map.item(item); walk_item(self, item); walk_ty(self, ty); }, diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 89f5b2ff3113..2e2e693592c8 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -102,7 +102,7 @@ fn future_trait_ref<'tcx>( ) -> Option<(&'tcx TraitRef<'tcx>, Vec)> { if_chain! { if let TyKind::OpaqueDef(item_id, bounds) = ty.kind; - let item = cx.tcx.hir().item(item_id.id); + let item = cx.tcx.hir().item(item_id); if let ItemKind::OpaqueTy(opaque) = &item.kind; if let Some(trait_ref) = opaque.bounds.iter().find_map(|bound| { if let GenericBound::Trait(poly, _) = bound { diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 913d9daff46f..1264813d378a 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -107,7 +107,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { // trait method with default body needs inline in case // an impl is not provided let desc = "a default trait method"; - let item = cx.tcx.hir().expect_trait_item(tit.id.hir_id); + let item = cx.tcx.hir().trait_item(tit.id); check_missing_inline_attrs(cx, &item.attrs, item.span, desc); } }, diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index ca60d335262b..6e3d4fde1077 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -130,7 +130,7 @@ impl<'tcx> LateLintPass<'tcx> for Author { } fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx hir::Stmt<'_>) { - if !has_attr(cx.sess(), stmt.kind.attrs(|id| cx.tcx.hir().item(id.id))) { + if !has_attr(cx.sess(), stmt.kind.attrs(|id| cx.tcx.hir().item(id))) { return; } prelude(); diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 9bec24be9e4e..b52083af6fd3 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -109,7 +109,7 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector { } fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx hir::Stmt<'_>) { - if !has_attr(cx.sess(), stmt.kind.attrs(|id| cx.tcx.hir().item(id.id))) { + if !has_attr(cx.sess(), stmt.kind.attrs(|id| cx.tcx.hir().item(id))) { return; } match stmt.kind { From 1ef2a812a90cea07dfd60fac38e936b06631d209 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 30 Jan 2021 17:47:51 +0100 Subject: [PATCH 0188/1222] Only store a LocalDefId in hir::Item. Items are guaranteed to be HIR owner. --- clippy_lints/src/copy_iterator.rs | 2 +- clippy_lints/src/derive.rs | 2 +- clippy_lints/src/doc.rs | 7 +++---- clippy_lints/src/empty_enum.rs | 3 +-- clippy_lints/src/exhaustive_items.rs | 2 +- clippy_lints/src/fallible_impl_from.rs | 3 +-- clippy_lints/src/from_over_into.rs | 3 +-- clippy_lints/src/functions.rs | 6 +++--- clippy_lints/src/inherent_impl.rs | 11 +++-------- clippy_lints/src/large_enum_variant.rs | 3 +-- clippy_lints/src/len_zero.rs | 8 +++----- clippy_lints/src/methods/mod.rs | 3 +-- clippy_lints/src/missing_doc.rs | 6 ++---- clippy_lints/src/missing_inline.rs | 2 +- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/needless_borrow.rs | 9 +++++---- clippy_lints/src/ptr.rs | 2 +- clippy_lints/src/redundant_pub_crate.rs | 7 +++---- clippy_lints/src/types.rs | 6 ++++-- clippy_lints/src/use_self.rs | 3 +-- clippy_lints/src/utils/inspector.rs | 5 ++--- clippy_lints/src/wildcard_imports.rs | 2 +- 22 files changed, 41 insertions(+), 56 deletions(-) diff --git a/clippy_lints/src/copy_iterator.rs b/clippy_lints/src/copy_iterator.rs index 48899b338993..004bce5f62a8 100644 --- a/clippy_lints/src/copy_iterator.rs +++ b/clippy_lints/src/copy_iterator.rs @@ -38,7 +38,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyIterator { .. }) = item.kind { - let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id)); + let ty = cx.tcx.type_of(item.def_id); if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) { span_lint_and_note( diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index b1e363663bb2..e8510bde9adc 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -169,7 +169,7 @@ impl<'tcx> LateLintPass<'tcx> for Derive { .. }) = item.kind { - let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id)); + let ty = cx.tcx.type_of(item.def_id); let is_automatically_derived = is_automatically_derived(&*item.attrs); check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived); diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 75e71eb1e4ce..c12448588891 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -216,18 +216,17 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { let headers = check_attrs(cx, &self.valid_idents, &item.attrs); match item.kind { hir::ItemKind::Fn(ref sig, _, body_id) => { - if !(is_entrypoint_fn(cx, cx.tcx.hir().local_def_id(item.hir_id).to_def_id()) + if !(is_entrypoint_fn(cx, item.def_id.to_def_id()) || in_external_macro(cx.tcx.sess, item.span)) { let body = cx.tcx.hir().body(body_id); - let impl_item_def_id = cx.tcx.hir().local_def_id(item.hir_id); let mut fpu = FindPanicUnwrap { cx, - typeck_results: cx.tcx.typeck(impl_item_def_id), + typeck_results: cx.tcx.typeck(item.def_id), panic_span: None, }; fpu.visit_expr(&body.value); - lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id), fpu.panic_span); + lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, Some(body_id), fpu.panic_span); } }, hir::ItemKind::Impl(ref impl_) => { diff --git a/clippy_lints/src/empty_enum.rs b/clippy_lints/src/empty_enum.rs index 853b3afdc3ae..077c3b75fb8c 100644 --- a/clippy_lints/src/empty_enum.rs +++ b/clippy_lints/src/empty_enum.rs @@ -49,9 +49,8 @@ impl<'tcx> LateLintPass<'tcx> for EmptyEnum { return; } - let did = cx.tcx.hir().local_def_id(item.hir_id); if let ItemKind::Enum(..) = item.kind { - let ty = cx.tcx.type_of(did); + let ty = cx.tcx.type_of(item.def_id); let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); if adt.variants.is_empty() { span_lint_and_help( diff --git a/clippy_lints/src/exhaustive_items.rs b/clippy_lints/src/exhaustive_items.rs index e3988d0038c2..ab9be3398bfa 100644 --- a/clippy_lints/src/exhaustive_items.rs +++ b/clippy_lints/src/exhaustive_items.rs @@ -72,7 +72,7 @@ impl LateLintPass<'_> for ExhaustiveItems { fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { if_chain! { if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind; - if cx.access_levels.is_exported(item.hir_id); + if cx.access_levels.is_exported(item.hir_id()); if !item.attrs.iter().any(|a| a.has_name(sym::non_exhaustive)); then { let (lint, msg) = if let ItemKind::Struct(ref v, ..) = item.kind { diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 527905e375d2..79828efc206d 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -52,10 +52,9 @@ declare_lint_pass!(FallibleImplFrom => [FALLIBLE_IMPL_FROM]); impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { // check for `impl From for ..` - let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id); if_chain! { if let hir::ItemKind::Impl(impl_) = &item.kind; - if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id); + if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id); if cx.tcx.is_diagnostic_item(sym::from_trait, impl_trait_ref.def_id); then { lint_impl_body(cx, item.span, impl_.items); diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index b010abda24d1..b644bb079908 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -60,10 +60,9 @@ impl LateLintPass<'_> for FromOverInto { return; } - let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id); if_chain! { if let hir::ItemKind::Impl{ .. } = &item.kind; - if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id); + if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id); if match_def_path(cx, impl_trait_ref.def_id, &INTO); then { diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 71a146cc2980..28d025315cfe 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -283,13 +283,13 @@ impl<'tcx> LateLintPass<'tcx> for Functions { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { let attr = must_use_attr(&item.attrs); if let hir::ItemKind::Fn(ref sig, ref _generics, ref body_id) = item.kind { - let is_public = cx.access_levels.is_exported(item.hir_id); + let is_public = cx.access_levels.is_exported(item.hir_id()); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); if is_public { check_result_unit_err(cx, &sig.decl, item.span, fn_header_span); } if let Some(attr) = attr { - check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr); + check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr); return; } if is_public && !is_proc_macro(cx.sess(), &item.attrs) && attr_by_name(&item.attrs, "no_mangle").is_none() { @@ -298,7 +298,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions { &sig.decl, cx.tcx.hir().body(*body_id), item.span, - item.hir_id, + item.hir_id(), item.span.with_hi(sig.decl.output.span().hi()), "this function could have a `#[must_use]` attribute", ); diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index ea26c84cde16..005c461f105e 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -59,20 +59,15 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { // but filter out implementations that have generic params (type or lifetime) // or are derived from a macro if !in_macro(item.span) && generics.params.is_empty() { - self.impls.insert(item.hir_id.owner.to_def_id(), item.span); + self.impls.insert(item.def_id.to_def_id(), item.span); } } } fn check_crate_post(&mut self, cx: &LateContext<'tcx>, krate: &'tcx Crate<'_>) { - if let Some(item) = krate.items.values().next() { + if !krate.items.is_empty() { // Retrieve all inherent implementations from the crate, grouped by type - for impls in cx - .tcx - .crate_inherent_impls(item.hir_id.owner.to_def_id().krate) - .inherent_impls - .values() - { + for impls in cx.tcx.crate_inherent_impls(def_id::LOCAL_CRATE).inherent_impls.values() { // Filter out implementations that have generic params (type or lifetime) let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def)); if let Some(initial_span) = impl_spans.next() { diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index ad9b4f357a74..ab4cb33612d3 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -62,9 +62,8 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant { if in_external_macro(cx.tcx.sess, item.span) { return; } - let did = cx.tcx.hir().local_def_id(item.hir_id); if let ItemKind::Enum(ref def, _) = item.kind { - let ty = cx.tcx.type_of(did); + let ty = cx.tcx.type_of(item.def_id); let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); let mut largest_variant: Option<(_, _)> = None; diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index e95caf6a35f9..8706cf7f02b9 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -177,10 +177,9 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items } } - if cx.access_levels.is_exported(visited_trait.hir_id) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) { + if cx.access_levels.is_exported(visited_trait.hir_id()) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) { let mut current_and_super_traits = FxHashSet::default(); - let visited_trait_def_id = cx.tcx.hir().local_def_id(visited_trait.hir_id); - fill_trait_set(visited_trait_def_id.to_def_id(), &mut current_and_super_traits, cx); + fill_trait_set(visited_trait.def_id.to_def_id(), &mut current_and_super_traits, cx); let is_empty_method_found = current_and_super_traits .iter() @@ -230,8 +229,7 @@ fn check_impl_items(cx: &LateContext<'_>, item: &Item<'_>, impl_items: &[ImplIte if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) { if cx.access_levels.is_exported(i.id.hir_id) { - let def_id = cx.tcx.hir().local_def_id(item.hir_id); - let ty = cx.tcx.type_of(def_id); + let ty = cx.tcx.type_of(item.def_id); span_lint( cx, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 0918843294d4..a2104b48b4ff 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1687,8 +1687,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { let name = impl_item.ident.name.as_str(); let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id); let item = cx.tcx.hir().expect_item(parent); - let def_id = cx.tcx.hir().local_def_id(item.hir_id); - let self_ty = cx.tcx.type_of(def_id); + let self_ty = cx.tcx.type_of(item.def_id); // if this impl block implements a trait, lint in trait definition instead if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind { diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 0e49eaab4368..21b59fba995f 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -135,8 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { hir::ItemKind::Fn(..) => { // ignore main() if it.ident.name == sym::main { - let def_id = it.hir_id.owner; - let def_key = cx.tcx.hir().def_key(def_id); + let def_key = cx.tcx.hir().def_key(it.def_id); if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) { return; } @@ -159,8 +158,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { | hir::ItemKind::Use(..) => return, }; - let def_id = cx.tcx.hir().local_def_id(it.hir_id); - let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id()); + let (article, desc) = cx.tcx.article_and_description(it.def_id.to_def_id()); self.check_missing_docs_attrs(cx, &it.attrs, it.span, article, desc); } diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 1264813d378a..5132bed590a0 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { return; } - if !cx.access_levels.is_exported(it.hir_id) { + if !cx.access_levels.is_exported(it.hir_id()) { return; } match it.kind { diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 11044e0c2fb4..7b9205a99de1 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -57,7 +57,7 @@ declare_lint_pass!(MutableKeyType => [ MUTABLE_KEY_TYPE ]); impl<'tcx> LateLintPass<'tcx> for MutableKeyType { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) { if let hir::ItemKind::Fn(ref sig, ..) = item.kind { - check_sig(cx, item.hir_id, &sig.decl); + check_sig(cx, item.hir_id(), &sig.decl); } } diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index f1c06692e30d..1453ea6e8975 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -5,11 +5,12 @@ use crate::utils::{is_automatically_derived, snippet_opt, span_lint_and_then}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::{BindingAnnotation, BorrowKind, Expr, ExprKind, HirId, Item, Mutability, Pat, PatKind}; +use rustc_hir::{BindingAnnotation, BorrowKind, Expr, ExprKind, Item, Mutability, Pat, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_middle::ty::adjustment::{Adjust, Adjustment}; use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::def_id::LocalDefId; declare_clippy_lint! { /// **What it does:** Checks for address of operations (`&`) that are going to @@ -35,7 +36,7 @@ declare_clippy_lint! { #[derive(Default)] pub struct NeedlessBorrow { - derived_item: Option, + derived_item: Option, } impl_lint_pass!(NeedlessBorrow => [NEEDLESS_BORROW]); @@ -117,13 +118,13 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow { fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) { if is_automatically_derived(item.attrs) { debug_assert!(self.derived_item.is_none()); - self.derived_item = Some(item.hir_id); + self.derived_item = Some(item.def_id); } } fn check_item_post(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) { if let Some(id) = self.derived_item { - if item.hir_id == id { + if item.def_id == id { self.derived_item = None; } } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index b5aa34111402..9efeac3d8238 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -124,7 +124,7 @@ declare_lint_pass!(Ptr => [PTR_ARG, CMP_NULL, MUT_FROM_REF]); impl<'tcx> LateLintPass<'tcx> for Ptr { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if let ItemKind::Fn(ref sig, _, body_id) = item.kind { - check_fn(cx, &sig.decl, item.hir_id, Some(body_id)); + check_fn(cx, &sig.decl, item.hir_id(), Some(body_id)); } } diff --git a/clippy_lints/src/redundant_pub_crate.rs b/clippy_lints/src/redundant_pub_crate.rs index acd9047ace61..c876bae2303a 100644 --- a/clippy_lints/src/redundant_pub_crate.rs +++ b/clippy_lints/src/redundant_pub_crate.rs @@ -42,11 +42,10 @@ impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]); impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { if let VisibilityKind::Crate { .. } = item.vis.node { - if !cx.access_levels.is_exported(item.hir_id) { + if !cx.access_levels.is_exported(item.hir_id()) { if let Some(false) = self.is_exported.last() { let span = item.span.with_hi(item.ident.span.hi()); - let def_id = cx.tcx.hir().local_def_id(item.hir_id); - let descr = cx.tcx.def_kind(def_id).descr(def_id.to_def_id()); + let descr = cx.tcx.def_kind(item.def_id).descr(item.def_id.to_def_id()); span_lint_and_then( cx, REDUNDANT_PUB_CRATE, @@ -66,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { } if let ItemKind::Mod { .. } = item.kind { - self.is_exported.push(cx.access_levels.is_exported(item.hir_id)); + self.is_exported.push(cx.access_levels.is_exported(item.hir_id())); } } diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 58af5b12c373..05754503163b 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -1106,7 +1106,9 @@ fn is_empty_block(expr: &Expr<'_>) -> bool { expr.kind, ExprKind::Block( Block { - stmts: &[], expr: None, .. + stmts: &[], + expr: None, + .. }, _, ) @@ -2565,7 +2567,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { } } - if !cx.access_levels.is_exported(item.hir_id) { + if !cx.access_levels.is_exported(item.hir_id()) { return; } diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 72d1ca739291..f2ff8c959c2e 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -196,8 +196,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { item_path, cx, }; - let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id); - let impl_trait_ref = cx.tcx.impl_trait_ref(impl_def_id); + let impl_trait_ref = cx.tcx.impl_trait_ref(item.def_id); if let Some(impl_trait_ref) = impl_trait_ref { for impl_item_ref in impl_.items { diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index b52083af6fd3..9c1d98cd7074 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -370,7 +370,7 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { } fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) { - let did = cx.tcx.hir().local_def_id(item.hir_id); + let did = item.def_id; println!("item `{}`", item.ident.name); match item.vis.node { hir::VisibilityKind::Public => println!("public"), @@ -383,8 +383,7 @@ fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) { } match item.kind { hir::ItemKind::ExternCrate(ref _renamed_from) => { - let def_id = cx.tcx.hir().local_def_id(item.hir_id); - if let Some(crate_id) = cx.tcx.extern_mod_stmt_cnum(def_id) { + if let Some(crate_id) = cx.tcx.extern_mod_stmt_cnum(did) { let source = cx.tcx.used_crate_source(crate_id); if let Some(ref src) = source.dylib { println!("extern crate dylib source: {:?}", src.0); diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 10005a7fc81e..094b1a42346c 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -113,7 +113,7 @@ impl LateLintPass<'_> for WildcardImports { if_chain! { if let ItemKind::Use(use_path, UseKind::Glob) = &item.kind; if self.warn_on_all || !self.check_exceptions(item, use_path.segments); - let used_imports = cx.tcx.names_imported_by_glob_use(item.hir_id.owner); + let used_imports = cx.tcx.names_imported_by_glob_use(item.def_id); if !used_imports.is_empty(); // Already handled by `unused_imports` then { let mut applicability = Applicability::MachineApplicable; From f5ed81c34ffb181b7dd212544982cc5a60d33fb9 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 30 Jan 2021 20:46:50 +0100 Subject: [PATCH 0189/1222] Only store a LocalDefId in hir::TraitItem. --- clippy_lints/src/doc.rs | 2 +- clippy_lints/src/escape.rs | 4 ++-- clippy_lints/src/functions.rs | 8 ++++---- clippy_lints/src/len_zero.rs | 5 +---- clippy_lints/src/methods/mod.rs | 6 +++--- clippy_lints/src/missing_doc.rs | 3 +-- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/ptr.rs | 2 +- 9 files changed, 15 insertions(+), 19 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index c12448588891..8a82b550bdae 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -246,7 +246,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { let headers = check_attrs(cx, &self.valid_idents, &item.attrs); if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { if !in_external_macro(cx.tcx.sess, item.span) { - lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, None, None); + lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, None, None); } } } diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 40e93da8dffb..f8ef2a464d5c 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -87,11 +87,11 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { // find `self` ty for this trait if relevant if let ItemKind::Trait(_, _, _, _, items) = item.kind { for trait_item in items { - if trait_item.id.hir_id == hir_id { + if trait_item.id.hir_id() == hir_id { // be sure we have `self` parameter in this function if let AssocItemKind::Fn { has_self: true } = trait_item.kind { trait_self_ty = - Some(TraitRef::identity(cx.tcx, trait_item.id.hir_id.owner.to_def_id()).self_ty()); + Some(TraitRef::identity(cx.tcx, trait_item.id.def_id.to_def_id()).self_ty()); } } } diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 28d025315cfe..eabc745a7b07 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -339,7 +339,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions { if sig.header.abi == Abi::Rust { self.check_arg_number(cx, &sig.decl, item.span.with_hi(sig.decl.output.span().hi())); } - let is_public = cx.access_levels.is_exported(item.hir_id); + let is_public = cx.access_levels.is_exported(item.hir_id()); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); if is_public { check_result_unit_err(cx, &sig.decl, item.span, fn_header_span); @@ -347,11 +347,11 @@ impl<'tcx> LateLintPass<'tcx> for Functions { let attr = must_use_attr(&item.attrs); if let Some(attr) = attr { - check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr); + check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr); } if let hir::TraitFn::Provided(eid) = *eid { let body = cx.tcx.hir().body(eid); - Self::check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id); + Self::check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id()); if attr.is_none() && is_public && !is_proc_macro(cx.sess(), &item.attrs) { check_must_use_candidate( @@ -359,7 +359,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions { &sig.decl, body, item.span, - item.hir_id, + item.hir_id(), item.span.with_hi(sig.decl.output.span().hi()), "this method could have a `#[must_use]` attribute", ); diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 8706cf7f02b9..a89941ceb226 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -159,10 +159,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items fn is_named_self(cx: &LateContext<'_>, item: &TraitItemRef, name: &str) -> bool { item.ident.name.as_str() == name && if let AssocItemKind::Fn { has_self } = item.kind { - has_self && { - let did = cx.tcx.hir().local_def_id(item.id.hir_id); - cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1 - } + has_self && { cx.tcx.fn_sig(item.id.def_id).inputs().skip_binder().len() == 1 } } else { false } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index a2104b48b4ff..a68775ffb754 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1791,7 +1791,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let Some(first_arg_ty) = sig.decl.inputs.iter().next(); let first_arg_span = first_arg_ty.span; let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty); - let self_ty = TraitRef::identity(cx.tcx, item.hir_id.owner.to_def_id()).self_ty(); + let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty(); then { lint_wrong_self_convention(cx, &item.ident.name.as_str(), false, self_ty, first_arg_ty, first_arg_span); @@ -1801,8 +1801,8 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if_chain! { if item.ident.name == sym::new; if let TraitItemKind::Fn(_, _) = item.kind; - let ret_ty = return_ty(cx, item.hir_id); - let self_ty = TraitRef::identity(cx.tcx, item.hir_id.owner.to_def_id()).self_ty(); + let ret_ty = return_ty(cx, item.hir_id()); + let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty(); if !contains_ty(ret_ty, self_ty); then { diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 21b59fba995f..5fce322933e9 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -164,8 +164,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { } fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) { - let def_id = cx.tcx.hir().local_def_id(trait_item.hir_id); - let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id()); + let (article, desc) = cx.tcx.article_and_description(trait_item.def_id.to_def_id()); self.check_missing_docs_attrs(cx, &trait_item.attrs, trait_item.span, article, desc); } diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 7b9205a99de1..16981946e18e 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType { fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'tcx>) { if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { - check_sig(cx, item.hir_id, &sig.decl); + check_sig(cx, item.hir_id(), &sig.decl); } } diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index d96a9b025f08..b9ba32001b51 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -206,7 +206,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { } if let hir::TraitItemKind::Fn(method_sig, _) = &item.kind { - self.check_poly_fn(cx, item.hir_id, &*method_sig.decl, None); + self.check_poly_fn(cx, item.hir_id(), &*method_sig.decl, None); } } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 9efeac3d8238..ee4ad086eb9a 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { } else { None }; - check_fn(cx, &sig.decl, item.hir_id, body_id); + check_fn(cx, &sig.decl, item.hir_id(), body_id); } } From e24298f70c6fee29fd7ef9bd7359dc1d6ba96303 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 30 Jan 2021 23:25:03 +0100 Subject: [PATCH 0190/1222] Only store a LocalDefId in hir::ImplItem. --- clippy_lints/src/doc.rs | 5 ++--- clippy_lints/src/fallible_impl_from.rs | 3 +-- clippy_lints/src/functions.rs | 10 +++++----- clippy_lints/src/inherent_to_string.rs | 7 +++---- clippy_lints/src/len_zero.rs | 9 +++------ clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/methods/mod.rs | 9 ++++----- clippy_lints/src/missing_doc.rs | 5 ++--- clippy_lints/src/missing_inline.rs | 7 +++---- clippy_lints/src/mut_key.rs | 4 ++-- clippy_lints/src/new_without_default.rs | 2 +- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/partialeq_ne_impl.rs | 2 +- clippy_lints/src/ptr.rs | 4 ++-- clippy_lints/src/unused_self.rs | 5 ++--- clippy_lints/src/unwrap_in_result.rs | 7 +++---- 16 files changed, 36 insertions(+), 47 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 8a82b550bdae..67b7cf919586 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -258,14 +258,13 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { } if let hir::ImplItemKind::Fn(ref sig, body_id) = item.kind { let body = cx.tcx.hir().body(body_id); - let impl_item_def_id = cx.tcx.hir().local_def_id(item.hir_id); let mut fpu = FindPanicUnwrap { cx, - typeck_results: cx.tcx.typeck(impl_item_def_id), + typeck_results: cx.tcx.typeck(item.def_id), panic_span: None, }; fpu.visit_expr(&body.value); - lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id), fpu.panic_span); + lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, Some(body_id), fpu.panic_span); } } } diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 79828efc206d..6d522c7ef339 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -116,10 +116,9 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h then { // check the body for `begin_panic` or `unwrap` let body = cx.tcx.hir().body(body_id); - let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.id.hir_id); let mut fpu = FindPanicUnwrap { lcx: cx, - typeck_results: cx.tcx.typeck(impl_item_def_id), + typeck_results: cx.tcx.typeck(impl_item.id.def_id), result: Vec::new(), }; fpu.visit_expr(&body.value); diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index eabc745a7b07..0c6bf8bbdf24 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -308,24 +308,24 @@ impl<'tcx> LateLintPass<'tcx> for Functions { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind { - let is_public = cx.access_levels.is_exported(item.hir_id); + let is_public = cx.access_levels.is_exported(item.hir_id()); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); - if is_public && trait_ref_of_method(cx, item.hir_id).is_none() { + if is_public && trait_ref_of_method(cx, item.hir_id()).is_none() { check_result_unit_err(cx, &sig.decl, item.span, fn_header_span); } let attr = must_use_attr(&item.attrs); if let Some(attr) = attr { - check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr); + check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr); } else if is_public && !is_proc_macro(cx.sess(), &item.attrs) - && trait_ref_of_method(cx, item.hir_id).is_none() + && trait_ref_of_method(cx, item.hir_id()).is_none() { check_must_use_candidate( cx, &sig.decl, cx.tcx.hir().body(*body_id), item.span, - item.hir_id, + item.hir_id(), item.span.with_hi(sig.decl.output.span().hi()), "this method could have a `#[must_use]` attribute", ); diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index b723d06a6881..76e7a4992d34 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -108,10 +108,10 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString { if decl.inputs.len() == 1; // Check if return type is String - if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::string_type); + if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::string_type); // Filters instances of to_string which are required by a trait - if trait_ref_of_method(cx, impl_item.hir_id).is_none(); + if trait_ref_of_method(cx, impl_item.hir_id()).is_none(); then { show_lint(cx, impl_item); @@ -124,8 +124,7 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) { let display_trait_id = get_trait_def_id(cx, &paths::DISPLAY_TRAIT).expect("Failed to get trait ID of `Display`!"); // Get the real type of 'self' - let fn_def_id = cx.tcx.hir().local_def_id(item.hir_id); - let self_type = cx.tcx.fn_sig(fn_def_id).input(0); + let self_type = cx.tcx.fn_sig(item.def_id).input(0); let self_type = self_type.skip_binder().peel_refs(); // Emit either a warning or an error diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index a89941ceb226..dab3e0565caf 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -206,17 +206,14 @@ fn check_impl_items(cx: &LateContext<'_>, item: &Item<'_>, impl_items: &[ImplIte fn is_named_self(cx: &LateContext<'_>, item: &ImplItemRef<'_>, name: &str) -> bool { item.ident.name.as_str() == name && if let AssocItemKind::Fn { has_self } = item.kind { - has_self && { - let did = cx.tcx.hir().local_def_id(item.id.hir_id); - cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1 - } + has_self && cx.tcx.fn_sig(item.id.def_id).inputs().skip_binder().len() == 1 } else { false } } let is_empty = if let Some(is_empty) = impl_items.iter().find(|i| is_named_self(cx, i, "is_empty")) { - if cx.access_levels.is_exported(is_empty.id.hir_id) { + if cx.access_levels.is_exported(is_empty.id.hir_id()) { return; } "a private" @@ -225,7 +222,7 @@ fn check_impl_items(cx: &LateContext<'_>, item: &Item<'_>, impl_items: &[ImplIte }; if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) { - if cx.access_levels.is_exported(i.id.hir_id) { + if cx.access_levels.is_exported(i.id.hir_id()) { let ty = cx.tcx.type_of(item.def_id); span_lint( diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 05c747eee076..50e6383263dd 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { if let ImplItemKind::Fn(ref sig, id) = item.kind { - let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id).is_none(); + let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id()).is_none(); check_fn_inner( cx, &sig.decl, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index a68775ffb754..55660cc95a8e 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1685,7 +1685,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { return; } let name = impl_item.ident.name.as_str(); - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id); + let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); let item = cx.tcx.hir().expect_item(parent); let self_ty = cx.tcx.type_of(item.def_id); @@ -1698,8 +1698,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind; if let Some(first_arg) = iter_input_pats(&sig.decl, cx.tcx.hir().body(id)).next(); - let method_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); - let method_sig = cx.tcx.fn_sig(method_def_id); + let method_sig = cx.tcx.fn_sig(impl_item.def_id); let method_sig = cx.tcx.erase_late_bound_regions(method_sig); let first_arg_ty = &method_sig.inputs().iter().next(); @@ -1708,7 +1707,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let Some(first_arg_ty) = first_arg_ty; then { - if cx.access_levels.is_exported(impl_item.hir_id) { + if cx.access_levels.is_exported(impl_item.hir_id()) { // check missing trait implementations for method_config in &TRAIT_METHODS { if name == method_config.method_name && @@ -1750,7 +1749,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { } if let hir::ImplItemKind::Fn(_, _) = impl_item.kind { - let ret_ty = return_ty(cx, impl_item.hir_id); + let ret_ty = return_ty(cx, impl_item.hir_id()); // walk the return type and check for Self (this does not check associated types) if contains_ty(ret_ty, self_ty) { diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 5fce322933e9..761b9261772b 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -171,8 +171,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { // If the method is an impl for a trait, don't doc. - let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); - match cx.tcx.associated_item(def_id).container { + match cx.tcx.associated_item(impl_item.def_id).container { ty::TraitContainer(_) => return, ty::ImplContainer(cid) => { if cx.tcx.impl_trait_ref(cid).is_some() { @@ -181,7 +180,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { }, } - let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id()); + let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id()); self.check_missing_docs_attrs(cx, &impl_item.attrs, impl_item.span, article, desc); } diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 5132bed590a0..47d7c5306c43 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -138,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { } // If the item being implemented is not exported, then we don't need #[inline] - if !cx.access_levels.is_exported(impl_item.hir_id) { + if !cx.access_levels.is_exported(impl_item.hir_id()) { return; } @@ -147,14 +147,13 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) => return, }; - let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); - let trait_def_id = match cx.tcx.associated_item(def_id).container { + let trait_def_id = match cx.tcx.associated_item(impl_item.def_id).container { TraitContainer(cid) => Some(cid), ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id), }; if let Some(trait_def_id) = trait_def_id { - if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.hir_id) { + if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.hir_id()) { // If a trait is being implemented for an item, and the // trait is not exported, we don't need #[inline] return; diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 16981946e18e..908b7bb7ce00 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -63,8 +63,8 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'tcx>) { if let hir::ImplItemKind::Fn(ref sig, ..) = item.kind { - if trait_ref_of_method(cx, item.hir_id).is_none() { - check_sig(cx, item.hir_id, &sig.decl); + if trait_ref_of_method(cx, item.hir_id()).is_none() { + check_sig(cx, item.hir_id(), &sig.decl); } } } diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index bd3dac663fe2..de2899c3462a 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { } if let hir::ImplItemKind::Fn(ref sig, _) = impl_item.kind { let name = impl_item.ident.name; - let id = impl_item.hir_id; + let id = impl_item.hir_id(); if sig.header.constness == hir::Constness::Const { // can't be implemented by default return; diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 0b2262d84907..8aebce67917a 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -271,7 +271,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { if let ImplItemKind::Const(hir_ty, body_id) = &impl_item.kind { - let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id); + let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id()); let item = cx.tcx.hir().expect_item(item_hir_id); match &item.kind { diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index ed314937ce8b..3d6129aa78d4 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -44,7 +44,7 @@ impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl { span_lint_hir( cx, PARTIALEQ_NE_IMPL, - impl_item.id.hir_id, + impl_item.id.hir_id(), impl_item.span, "re-implementing `PartialEq::ne` is unnecessary", ); diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index ee4ad086eb9a..de2fb8decb71 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -130,13 +130,13 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { if let ImplItemKind::Fn(ref sig, body_id) = item.kind { - let parent_item = cx.tcx.hir().get_parent_item(item.hir_id); + let parent_item = cx.tcx.hir().get_parent_item(item.hir_id()); if let Some(Node::Item(it)) = cx.tcx.hir().find(parent_item) { if let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = it.kind { return; // ignore trait impls } } - check_fn(cx, &sig.decl, item.hir_id, Some(body_id)); + check_fn(cx, &sig.decl, item.hir_id(), Some(body_id)); } } diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index 5349c4f7eb8a..73c64b808405 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -44,10 +44,9 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf { if impl_item.span.from_expansion() { return; } - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id); + let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); let parent_item = cx.tcx.hir().expect_item(parent); - let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); - let assoc_item = cx.tcx.associated_item(def_id); + let assoc_item = cx.tcx.associated_item(impl_item.def_id); if_chain! { if let ItemKind::Impl(Impl { of_trait: None, .. }) = parent_item.kind; if assoc_item.fn_has_self_parameter; diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs index fde310293309..8cb7429849da 100644 --- a/clippy_lints/src/unwrap_in_result.rs +++ b/clippy_lints/src/unwrap_in_result.rs @@ -57,8 +57,8 @@ impl<'tcx> LateLintPass<'tcx> for UnwrapInResult { // first check if it's a method or function if let hir::ImplItemKind::Fn(ref _signature, _) = impl_item.kind; // checking if its return type is `result` or `option` - if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::result_type) - || is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::option_type); + if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::result_type) + || is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::option_type); then { lint_impl_body(cx, impl_item.span, impl_item); } @@ -114,10 +114,9 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_item: &'tc if let ImplItemKind::Fn(_, body_id) = impl_item.kind; then { let body = cx.tcx.hir().body(body_id); - let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); let mut fpu = FindExpectUnwrap { lcx: cx, - typeck_results: cx.tcx.typeck(impl_item_def_id), + typeck_results: cx.tcx.typeck(impl_item.def_id), result: Vec::new(), }; fpu.visit_expr(&body.value); From b7edbf6ff1880fc49bd211c91c79cef963023182 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Wed, 17 Feb 2021 19:26:38 +0900 Subject: [PATCH 0191/1222] replace if-let and while-let with `if let` and `while let` --- clippy_lints/src/loops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 5211ca7da323..eb0047602fd2 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -341,7 +341,7 @@ declare_clippy_lint! { /// ``` pub WHILE_LET_ON_ITERATOR, style, - "using a while-let loop instead of a for loop on an iterator" + "using a `while let` loop instead of a for loop on an iterator" } declare_clippy_lint! { From 6ee7c8821e2488ec4c10b66e901fe1add7aec377 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 17 Feb 2021 00:56:07 +0300 Subject: [PATCH 0192/1222] ast: Keep expansion status for out-of-line module items Also remove `ast::Mod` which is mostly redundant now --- clippy_lints/src/utils/ast_utils.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/utils/ast_utils.rs b/clippy_lints/src/utils/ast_utils.rs index 642326469725..9ff7ef7cc3b5 100644 --- a/clippy_lints/src/utils/ast_utils.rs +++ b/clippy_lints/src/utils/ast_utils.rs @@ -241,9 +241,12 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r)) } - (Mod(l), Mod(r)) => { - l.inline == r.inline && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_item_kind)) - } + (Mod(lu, lmk), Mod(ru, rmk)) => lu == ru && match (lmk, rmk) { + (ModKind::Loaded(litems, linline, _), ModKind::Loaded(ritems, rinline, _)) => + linline == rinline && over(litems, ritems, |l, r| eq_item(l, r, eq_item_kind)), + (ModKind::Unloaded, ModKind::Unloaded) => true, + _ => false, + }, (ForeignMod(l), ForeignMod(r)) => { both(&l.abi, &r.abi, |l, r| eq_str_lit(l, r)) && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_foreign_item_kind)) From 828e0c9c90b29dd909e604326f48538c702fc687 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 8 Apr 2020 20:47:36 +0200 Subject: [PATCH 0193/1222] Move try_print_query_stack to rustc_interface. --- src/driver.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index f5f6c09ed8e9..d5143e1438ee 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -11,10 +11,8 @@ extern crate rustc_driver; extern crate rustc_errors; extern crate rustc_interface; -extern crate rustc_middle; use rustc_interface::interface; -use rustc_middle::ty::TyCtxt; use rustc_tools_util::VersionInfo; use std::borrow::Cow; @@ -168,7 +166,7 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { let num_frames = if backtrace { None } else { Some(2) }; - TyCtxt::try_print_query_stack(&handler, num_frames); + interface::try_print_query_stack(&handler, num_frames); } fn toolchain_path(home: Option, toolchain: Option) -> Option { From f323eae2726e816f71a53310a89b21be802c5762 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 25 Feb 2021 11:25:45 +0100 Subject: [PATCH 0194/1222] Fix Clippy build and test --- Cargo.toml | 3 --- tests/versioncheck.rs | 6 ++++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1d6bf1ea0eb9..ea32a8edd1ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,9 +18,6 @@ build = "build.rs" edition = "2018" publish = false -[workspace] -exclude = ["clippy_dev", "mini-macro", "target/lintcheck/crates"] - [[bin]] name = "cargo-clippy" test = false diff --git a/tests/versioncheck.rs b/tests/versioncheck.rs index 1c954c57a854..922a8207cea8 100644 --- a/tests/versioncheck.rs +++ b/tests/versioncheck.rs @@ -3,6 +3,12 @@ use rustc_tools_util::VersionInfo; #[test] fn check_that_clippy_lints_and_clippy_utils_have_the_same_version_as_clippy() { + // do not run this test inside the upstream rustc repo: + // https://github.com/rust-lang/rust-clippy/issues/6683 + if option_env!("RUSTC_TEST_SUITE").is_some() { + return; + } + let clippy_meta = cargo_metadata::MetadataCommand::new() .no_deps() .exec() From 5f107dcd2bd2fdbc8beeeaf21ed98e6d272f62ac Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Fri, 26 Feb 2021 22:04:02 -0600 Subject: [PATCH 0195/1222] Add missing diagnostic item Symbols --- clippy_lints/src/entry.rs | 3 ++- clippy_lints/src/loops.rs | 16 ++++++++-------- clippy_lints/src/methods/mod.rs | 6 +++--- clippy_lints/src/swap.rs | 2 +- clippy_lints/src/types.rs | 4 ++-- clippy_lints/src/zero_sized_map_values.rs | 3 ++- clippy_utils/src/eager_or_lazy.rs | 3 ++- 7 files changed, 20 insertions(+), 17 deletions(-) diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 6b9f9a567548..55575969927b 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -9,6 +9,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; +use rustc_span::sym; declare_clippy_lint! { /// **What it does:** Checks for uses of `contains_key` + `insert` on `HashMap` @@ -111,7 +112,7 @@ fn check_cond<'a>(cx: &LateContext<'_>, check: &'a Expr<'a>) -> Option<(&'static return if match_type(cx, obj_ty, &paths::BTREEMAP) { Some(("BTreeMap", map, key)) } - else if is_type_diagnostic_item(cx, obj_ty, sym!(hashmap_type)) { + else if is_type_diagnostic_item(cx, obj_ty, sym::hashmap_type) { Some(("HashMap", map, key)) } else { diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 1c9373a756c8..63d9b7f86459 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -1010,7 +1010,7 @@ fn is_slice_like<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'_>) -> bool { _ => false, }; - is_slice || is_type_diagnostic_item(cx, ty, sym::vec_type) || is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) + is_slice || is_type_diagnostic_item(cx, ty, sym::vec_type) || is_type_diagnostic_item(cx, ty, sym::vecdeque_type) } fn fetch_cloned_expr<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { @@ -1908,7 +1908,7 @@ fn check_for_loop_over_map_kv<'tcx>( _ => arg, }; - if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) || match_type(cx, ty, &paths::BTREEMAP) { + if is_type_diagnostic_item(cx, ty, sym::hashmap_type) || match_type(cx, ty, &paths::BTREEMAP) { span_lint_and_then( cx, FOR_KV_MAP, @@ -2386,9 +2386,9 @@ fn is_ref_iterable_type(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { is_iterable_array(ty, cx) || is_type_diagnostic_item(cx, ty, sym::vec_type) || match_type(cx, ty, &paths::LINKED_LIST) || - is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) || - is_type_diagnostic_item(cx, ty, sym!(hashset_type)) || - is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) || + is_type_diagnostic_item(cx, ty, sym::hashmap_type) || + is_type_diagnostic_item(cx, ty, sym::hashset_type) || + is_type_diagnostic_item(cx, ty, sym::vecdeque_type) || match_type(cx, ty, &paths::BINARY_HEAP) || match_type(cx, ty, &paths::BTREEMAP) || match_type(cx, ty, &paths::BTREESET) @@ -2922,9 +2922,9 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont then { let ty = cx.typeck_results().node_type(ty.hir_id); if is_type_diagnostic_item(cx, ty, sym::vec_type) || - is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) || + is_type_diagnostic_item(cx, ty, sym::vecdeque_type) || match_type(cx, ty, &paths::BTREEMAP) || - is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) { + is_type_diagnostic_item(cx, ty, sym::hashmap_type) { if method.ident.name == sym!(len) { let span = shorten_needless_collect_span(expr); span_lint_and_sugg( @@ -2992,7 +2992,7 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0); if let ty = cx.typeck_results().node_type(ty.hir_id); if is_type_diagnostic_item(cx, ty, sym::vec_type) || - is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) || + is_type_diagnostic_item(cx, ty, sym::vecdeque_type) || match_type(cx, ty, &paths::LINKED_LIST); if let Some(iter_calls) = detect_iter_and_into_iters(block, *ident); if iter_calls.len() == 1; diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index ebd8af93dd0f..f101b6476f50 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2598,7 +2598,7 @@ fn lint_iter_nth<'tcx>( "slice" } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&iter_args[0]), sym::vec_type) { "Vec" - } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&iter_args[0]), sym!(vecdeque_type)) { + } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&iter_args[0]), sym::vecdeque_type) { "VecDeque" } else { let nth_args = nth_and_iter_args[0]; @@ -2652,10 +2652,10 @@ fn lint_get_unwrap<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, get_args: } else if is_type_diagnostic_item(cx, expr_ty, sym::vec_type) { needs_ref = get_args_str.parse::().is_ok(); "Vec" - } else if is_type_diagnostic_item(cx, expr_ty, sym!(vecdeque_type)) { + } else if is_type_diagnostic_item(cx, expr_ty, sym::vecdeque_type) { needs_ref = get_args_str.parse::().is_ok(); "VecDeque" - } else if !is_mut && is_type_diagnostic_item(cx, expr_ty, sym!(hashmap_type)) { + } else if !is_mut && is_type_diagnostic_item(cx, expr_ty, sym::hashmap_type) { needs_ref = true; "HashMap" } else if !is_mut && match_type(cx, expr_ty, &paths::BTREEMAP) { diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index 699fd51ccc19..9d8a0c248334 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -199,7 +199,7 @@ fn check_for_slice<'a>(cx: &LateContext<'_>, lhs1: &'a Expr<'_>, lhs2: &'a Expr< if matches!(ty.kind(), ty::Slice(_)) || matches!(ty.kind(), ty::Array(_, _)) || is_type_diagnostic_item(cx, ty, sym::vec_type) - || is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) + || is_type_diagnostic_item(cx, ty, sym::vecdeque_type) { return Slice::Swappable(lhs1, idx1, idx2); } diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 05754503163b..eb2016db3dc2 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -2680,14 +2680,14 @@ impl<'tcx> ImplicitHasherType<'tcx> { let ty = hir_ty_to_ty(cx.tcx, hir_ty); - if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) && params_len == 2 { + if is_type_diagnostic_item(cx, ty, sym::hashmap_type) && params_len == 2 { Some(ImplicitHasherType::HashMap( hir_ty.span, ty, snippet(cx, params[0].span, "K"), snippet(cx, params[1].span, "V"), )) - } else if is_type_diagnostic_item(cx, ty, sym!(hashset_type)) && params_len == 1 { + } else if is_type_diagnostic_item(cx, ty, sym::hashset_type) && params_len == 1 { Some(ImplicitHasherType::HashSet( hir_ty.span, ty, diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 319b85ac42a8..316b8d820a71 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -5,6 +5,7 @@ use rustc_middle::ty::{Adt, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_target::abi::LayoutOf as _; use rustc_typeck::hir_ty_to_ty; +use rustc_span::sym; use crate::utils::{is_normalizable, is_type_diagnostic_item, match_type, paths, span_lint_and_help}; @@ -47,7 +48,7 @@ impl LateLintPass<'_> for ZeroSizedMapValues { if !hir_ty.span.from_expansion(); if !in_trait_impl(cx, hir_ty.hir_id); let ty = ty_from_hir_ty(cx, hir_ty); - if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) || match_type(cx, ty, &paths::BTREEMAP); + if is_type_diagnostic_item(cx, ty, sym::hashmap_type) || match_type(cx, ty, &paths::BTREEMAP); if let Adt(_, ref substs) = ty.kind(); let ty = substs.type_at(1); // Do this to prevent `layout_of` crashing, being unable to fully normalize `ty`. diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 52a33e9b1704..81cd99c0558d 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -18,6 +18,7 @@ use rustc_hir::intravisit::{NestedVisitorMap, Visitor}; use rustc_hir::{Block, Expr, ExprKind, Path, QPath}; use rustc_lint::LateContext; use rustc_middle::hir::map::Map; +use rustc_span::sym; /// Is the expr pure (is it free from side-effects)? /// This function is named so to stress that it isn't exhaustive and returns FNs. @@ -99,7 +100,7 @@ fn identify_some_potentially_expensive_patterns<'tcx>(cx: &LateContext<'tcx>, ex ExprKind::Call(..) => !is_ctor_or_promotable_const_function(self.cx, expr), ExprKind::Index(obj, _) => { let ty = self.cx.typeck_results().expr_ty(obj); - is_type_diagnostic_item(self.cx, ty, sym!(hashmap_type)) + is_type_diagnostic_item(self.cx, ty, sym::hashmap_type) || match_type(self.cx, ty, &paths::BTREEMAP) }, ExprKind::MethodCall(..) => true, From 3233545c6b0c2b9240c91bf7f48f5dbe93cbc3e0 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Fri, 26 Feb 2021 21:17:29 -0600 Subject: [PATCH 0196/1222] Use diagnostic items in into_iter_collections --- clippy_lints/src/methods/mod.rs | 4 ++-- clippy_utils/src/lib.rs | 40 ++++++++++++++++----------------- clippy_utils/src/paths.rs | 2 -- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index f101b6476f50..5163074453b5 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -24,7 +24,7 @@ use rustc_middle::ty::{self, TraitRef, Ty, TyS}; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; -use rustc_span::symbol::{sym, SymbolStr}; +use rustc_span::symbol::{sym, Symbol, SymbolStr}; use rustc_typeck::hir_ty_to_ty; use crate::consts::{constant, Constant}; @@ -3619,7 +3619,7 @@ fn lint_asref(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str, as_re } } -fn ty_has_iter_method(cx: &LateContext<'_>, self_ref_ty: Ty<'_>) -> Option<(&'static str, &'static str)> { +fn ty_has_iter_method(cx: &LateContext<'_>, self_ref_ty: Ty<'_>) -> Option<(Symbol, &'static str)> { has_iter_method(cx, self_ref_ty).map(|ty_name| { let mutbl = match self_ref_ty.kind() { ty::Ref(_, _, mutbl) => mutbl, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 94b7339c7eb6..42512cadfb18 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1295,24 +1295,24 @@ pub fn any_parent_is_automatically_derived(tcx: TyCtxt<'_>, node: HirId) -> bool } /// Returns true if ty has `iter` or `iter_mut` methods -pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option<&'static str> { +pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option { // FIXME: instead of this hard-coded list, we should check if `::iter` // exists and has the desired signature. Unfortunately FnCtxt is not exported // so we can't use its `lookup_method` method. - let into_iter_collections: [&[&str]; 13] = [ - &paths::VEC, - &paths::OPTION, - &paths::RESULT, - &paths::BTREESET, - &paths::BTREEMAP, - &paths::VEC_DEQUE, - &paths::LINKED_LIST, - &paths::BINARY_HEAP, - &paths::HASHSET, - &paths::HASHMAP, - &paths::PATH_BUF, - &paths::PATH, - &paths::RECEIVER, + let into_iter_collections: &[Symbol] = &[ + sym::vec_type, + sym::option_type, + sym::result_type, + sym::BTreeMap, + sym::BTreeSet, + sym::vecdeque_type, + sym::LinkedList, + sym::BinaryHeap, + sym::hashset_type, + sym::hashmap_type, + sym::PathBuf, + sym::Path, + sym::Receiver, ]; let ty_to_check = match probably_ref_ty.kind() { @@ -1321,15 +1321,15 @@ pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option< }; let def_id = match ty_to_check.kind() { - ty::Array(..) => return Some("array"), - ty::Slice(..) => return Some("slice"), + ty::Array(..) => return Some(sym::array), + ty::Slice(..) => return Some(sym::slice), ty::Adt(adt, _) => adt.did, _ => return None, }; - for path in &into_iter_collections { - if match_def_path(cx, def_id, path) { - return Some(*path.last().unwrap()); + for &name in into_iter_collections { + if cx.tcx.is_diagnostic_item(name, def_id) { + return Some(cx.tcx.item_name(def_id)); } } None diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index e61786796475..c2da1f9b7c9f 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -99,7 +99,6 @@ pub(super) const PANIC_ANY: [&str; 3] = ["std", "panic", "panic_any"]; pub const PARKING_LOT_MUTEX_GUARD: [&str; 2] = ["parking_lot", "MutexGuard"]; pub const PARKING_LOT_RWLOCK_READ_GUARD: [&str; 2] = ["parking_lot", "RwLockReadGuard"]; pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 2] = ["parking_lot", "RwLockWriteGuard"]; -pub const PATH: [&str; 3] = ["std", "path", "Path"]; pub const PATH_BUF: [&str; 3] = ["std", "path", "PathBuf"]; pub const PATH_BUF_AS_PATH: [&str; 4] = ["std", "path", "PathBuf", "as_path"]; pub const PATH_TO_PATH_BUF: [&str; 4] = ["std", "path", "Path", "to_path_buf"]; @@ -116,7 +115,6 @@ pub const PUSH_STR: [&str; 4] = ["alloc", "string", "String", "push_str"]; pub const RANGE_ARGUMENT_TRAIT: [&str; 3] = ["core", "ops", "RangeBounds"]; pub const RC: [&str; 3] = ["alloc", "rc", "Rc"]; pub const RC_PTR_EQ: [&str; 4] = ["alloc", "rc", "Rc", "ptr_eq"]; -pub const RECEIVER: [&str; 4] = ["std", "sync", "mpsc", "Receiver"]; pub const REFCELL_REF: [&str; 3] = ["core", "cell", "Ref"]; pub const REFCELL_REFMUT: [&str; 3] = ["core", "cell", "RefMut"]; pub const REGEX_BUILDER_NEW: [&str; 5] = ["regex", "re_builder", "unicode", "RegexBuilder", "new"]; From b4d48b1dc1dac3f6f574e525047a1396b425482a Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 5 Mar 2021 09:32:47 +0000 Subject: [PATCH 0197/1222] Shrink the size of Rvalue by 16 bytes --- clippy_lints/src/redundant_clone.rs | 4 ++-- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 06adbb523d70..6a4537e6735c 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -584,10 +584,10 @@ fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) { match rvalue { Use(op) | Repeat(op, _) | Cast(_, op, _) | UnaryOp(_, op) => visit_op(op), Aggregate(_, ops) => ops.iter().for_each(visit_op), - BinaryOp(_, lhs, rhs) | CheckedBinaryOp(_, lhs, rhs) => { + BinaryOp(_, box (lhs, rhs)) | CheckedBinaryOp(_, box (lhs, rhs)) => { visit_op(lhs); visit_op(rhs); - }, + } _ => (), } } diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index a482017afeb1..2cb9588e13f9 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -172,7 +172,7 @@ fn check_rvalue(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, rvalue: &Rv } }, // binops are fine on integers - Rvalue::BinaryOp(_, lhs, rhs) | Rvalue::CheckedBinaryOp(_, lhs, rhs) => { + Rvalue::BinaryOp(_, box (lhs, rhs)) | Rvalue::CheckedBinaryOp(_, box (lhs, rhs)) => { check_operand(tcx, lhs, span, body)?; check_operand(tcx, rhs, span, body)?; let ty = lhs.ty(body, tcx); From b8d5624ff2a72d9cafa3d3ef5122e9121c3eb008 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 3 Mar 2021 23:33:18 -0300 Subject: [PATCH 0198/1222] Make clippy set mir_opt_level using Option --- src/driver.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver.rs b/src/driver.rs index d5143e1438ee..94af21568ee8 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -83,7 +83,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks { // run on the unoptimized MIR. On the other hand this results in some false negatives. If // MIR passes can be enabled / disabled separately, we should figure out, what passes to // use for Clippy. - config.opts.debugging_opts.mir_opt_level = 0; + config.opts.debugging_opts.mir_opt_level = Some(0); } } From 002ac4b9809378096190360f3b3212c3b9251ac2 Mon Sep 17 00:00:00 2001 From: mark Date: Mon, 8 Mar 2021 12:41:28 -0600 Subject: [PATCH 0199/1222] clippy: fix or-pattern in let binding --- clippy_lints/src/loops.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 1c9373a756c8..a87d5b9d3730 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -885,7 +885,9 @@ struct MinifyingSugg<'a>(Sugg<'a>); impl<'a> MinifyingSugg<'a> { fn as_str(&self) -> &str { - let Sugg::NonParen(s) | Sugg::MaybeParen(s) | Sugg::BinOp(_, s) = &self.0; + let s = match &self.0 { + Sugg::NonParen(s) | Sugg::MaybeParen(s) | Sugg::BinOp(_, s) => s, + }; s.as_ref() } From fa5d3ea08643fd99f675102d3fb355b39e4ed20f Mon Sep 17 00:00:00 2001 From: kadmin Date: Mon, 5 Oct 2020 22:53:00 +0000 Subject: [PATCH 0200/1222] Update match branches This updates all places where match branches check on StatementKind or UseContext. This doesn't properly implement them, but adds TODOs where they are, and also adds some best guesses to what they should be in some cases. --- clippy_utils/src/qualify_min_const_fn.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 2cb9588e13f9..53935f02a90e 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -210,7 +210,7 @@ fn check_statement(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, statemen StatementKind::Assign(box (place, rval)) => { check_place(tcx, *place, span, body)?; check_rvalue(tcx, body, def_id, rval, span) - }, + } StatementKind::FakeRead(_, place) | // just an assignment @@ -218,6 +218,13 @@ fn check_statement(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, statemen StatementKind::LlvmInlineAsm { .. } => Err((span, "cannot use inline assembly in const fn".into())), + StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping{ + dst, src, size, + }) => { + check_operand(tcx, dst, span, body)?; + check_operand(tcx, src, span, body)?; + check_operand(tcx, size, span, body) + }, // These are all NOPs StatementKind::StorageLive(_) | StatementKind::StorageDead(_) From e088586f50d249e1b237c74010c4f7722af2330e Mon Sep 17 00:00:00 2001 From: kadmin Date: Tue, 29 Dec 2020 02:00:04 +0000 Subject: [PATCH 0201/1222] Update cranelift --- clippy_utils/src/qualify_min_const_fn.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 53935f02a90e..0678d8253d59 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -219,11 +219,11 @@ fn check_statement(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, statemen StatementKind::LlvmInlineAsm { .. } => Err((span, "cannot use inline assembly in const fn".into())), StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping{ - dst, src, size, + dst, src, count, }) => { check_operand(tcx, dst, span, body)?; check_operand(tcx, src, span, body)?; - check_operand(tcx, size, span, body) + check_operand(tcx, count, span, body) }, // These are all NOPs StatementKind::StorageLive(_) From 2b35c2f34bca356d9fbe4c60d676a7a905d286a7 Mon Sep 17 00:00:00 2001 From: kadmin Date: Sat, 23 Jan 2021 08:57:04 +0000 Subject: [PATCH 0202/1222] Switch to changing cp_non_overlap in tform It was suggested to lower this in MIR instead of ssa, so do that instead. --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 0678d8253d59..1391f7505e27 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -224,7 +224,7 @@ fn check_statement(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, statemen check_operand(tcx, dst, span, body)?; check_operand(tcx, src, span, body)?; check_operand(tcx, count, span, body) - }, + } // These are all NOPs StatementKind::StorageLive(_) | StatementKind::StorageDead(_) From 41fdee7e0a1ec772fe06fa72a90b91713458c96b Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 6 Dec 2020 22:00:24 +0100 Subject: [PATCH 0203/1222] Simplify clippy author. --- clippy_lints/src/utils/author.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 6e3d4fde1077..3dd190ba4401 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -2,7 +2,7 @@ //! to generate a clippy lint detecting said code automatically. use crate::utils::get_attr; -use rustc_ast::ast::{Attribute, LitFloatType, LitKind}; +use rustc_ast::ast::{LitFloatType, LitKind}; use rustc_ast::walk_list; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; @@ -10,7 +10,6 @@ use rustc_hir::intravisit::{NestedVisitorMap, Visitor}; use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, Pat, PatKind, QPath, Stmt, StmtKind, TyKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::hir::map::Map; -use rustc_session::Session; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { @@ -66,7 +65,7 @@ fn done() { impl<'tcx> LateLintPass<'tcx> for Author { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { - if !has_attr(cx.sess(), &item.attrs) { + if !has_attr(cx, item.hir_id()) { return; } prelude(); @@ -75,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for Author { } fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { - if !has_attr(cx.sess(), &item.attrs) { + if !has_attr(cx, item.hir_id()) { return; } prelude(); @@ -84,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for Author { } fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { - if !has_attr(cx.sess(), &item.attrs) { + if !has_attr(cx, item.hir_id()) { return; } prelude(); @@ -93,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for Author { } fn check_variant(&mut self, cx: &LateContext<'tcx>, var: &'tcx hir::Variant<'_>) { - if !has_attr(cx.sess(), &var.attrs) { + if !has_attr(cx, var.id) { return; } prelude(); @@ -103,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for Author { } fn check_struct_field(&mut self, cx: &LateContext<'tcx>, field: &'tcx hir::StructField<'_>) { - if !has_attr(cx.sess(), &field.attrs) { + if !has_attr(cx, field.hir_id) { return; } prelude(); @@ -112,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for Author { } fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - if !has_attr(cx.sess(), &expr.attrs) { + if !has_attr(cx, expr.hir_id) { return; } prelude(); @@ -121,7 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for Author { } fn check_arm(&mut self, cx: &LateContext<'tcx>, arm: &'tcx hir::Arm<'_>) { - if !has_attr(cx.sess(), &arm.attrs) { + if !has_attr(cx, arm.hir_id) { return; } prelude(); @@ -130,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for Author { } fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx hir::Stmt<'_>) { - if !has_attr(cx.sess(), stmt.kind.attrs(|id| cx.tcx.hir().item(id))) { + if !has_attr(cx, stmt.hir_id) { return; } prelude(); @@ -139,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for Author { } fn check_foreign_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ForeignItem<'_>) { - if !has_attr(cx.sess(), &item.attrs) { + if !has_attr(cx, item.hir_id()) { return; } prelude(); @@ -719,8 +718,9 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { } } -fn has_attr(sess: &Session, attrs: &[Attribute]) -> bool { - get_attr(sess, attrs, "author").count() > 0 +fn has_attr(cx: &LateContext<'_>, hir_id: hir::HirId) -> bool { + let attrs = cx.tcx.hir().attrs(hir_id); + get_attr(cx.sess(), attrs, "author").count() > 0 } #[must_use] From cbf1e64d4e279e3c88de4b2d84f24b7c55ac3fcf Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 27 Nov 2020 09:24:42 +0100 Subject: [PATCH 0204/1222] Do not store attrs in FnKind. --- clippy_lints/src/cognitive_complexity.rs | 4 ++-- clippy_lints/src/functions.rs | 9 ++++----- clippy_lints/src/future_not_send.rs | 2 +- clippy_lints/src/misc.rs | 2 +- clippy_lints/src/missing_const_for_fn.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 5 +++-- clippy_lints/src/panic_in_result_fn.rs | 4 +--- clippy_lints/src/pass_by_ref_or_value.rs | 5 +++-- clippy_lints/src/returns.rs | 2 +- clippy_lints/src/unnecessary_wraps.rs | 4 ++-- 10 files changed, 19 insertions(+), 20 deletions(-) diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index f21a734bb439..658d445dfec5 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -76,8 +76,8 @@ impl CognitiveComplexity { if rust_cc > self.limit.limit() { let fn_span = match kind { - FnKind::ItemFn(ident, _, _, _, _) | FnKind::Method(ident, _, _, _) => ident.span, - FnKind::Closure(_) => { + FnKind::ItemFn(ident, _, _, _) | FnKind::Method(ident, _, _) => ident.span, + FnKind::Closure => { let header_span = body_span.with_hi(decl.output.span().lo()); let pos = snippet_opt(cx, header_span).and_then(|snip| { let low_offset = snip.find('|')?; diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index e4b3a9009f61..ae0b8d06dc2f 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -251,9 +251,9 @@ impl<'tcx> LateLintPass<'tcx> for Functions { hir_id: hir::HirId, ) { let unsafety = match kind { - intravisit::FnKind::ItemFn(_, _, hir::FnHeader { unsafety, .. }, _, _) => unsafety, - intravisit::FnKind::Method(_, sig, _, _) => sig.header.unsafety, - intravisit::FnKind::Closure(_) => return, + intravisit::FnKind::ItemFn(_, _, hir::FnHeader { unsafety, .. }, _) => unsafety, + intravisit::FnKind::Method(_, sig, _) => sig.header.unsafety, + intravisit::FnKind::Closure => return, }; // don't warn for implementations, it's not their fault @@ -267,9 +267,8 @@ impl<'tcx> LateLintPass<'tcx> for Functions { .. }, _, - _, ) - | intravisit::FnKind::ItemFn(_, _, hir::FnHeader { abi: Abi::Rust, .. }, _, _) => { + | intravisit::FnKind::ItemFn(_, _, hir::FnHeader { abi: Abi::Rust, .. }, _) => { self.check_arg_number(cx, decl, span.with_hi(decl.output.span().hi())) }, _ => {}, diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 7208e66ff7be..9e1a8864a3eb 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { _: Span, hir_id: HirId, ) { - if let FnKind::Closure(_) = kind { + if let FnKind::Closure = kind { return; } let ret_ty = utils::return_ty(cx, hir_id); diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 2ef5c6aa2a4e..35b4c3d5b03a 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -278,7 +278,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints { span: Span, _: HirId, ) { - if let FnKind::Closure(_) = k { + if let FnKind::Closure = k { // Does not apply to closures return; } diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 6ebeaced62a3..b0998a80128c 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -133,7 +133,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { return; } }, - FnKind::Closure(..) => return, + FnKind::Closure => return, } let mir = cx.tcx.optimized_mir(def_id); diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 54033f408714..cac4b2075114 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -80,13 +80,14 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { } match kind { - FnKind::ItemFn(.., header, _, attrs) => { + FnKind::ItemFn(.., header, _) => { + let attrs = cx.tcx.hir().attrs(hir_id); if header.abi != Abi::Rust || requires_exact_signature(attrs) { return; } }, FnKind::Method(..) => (), - FnKind::Closure(..) => return, + FnKind::Closure => return, } // Exclude non-inherent impls diff --git a/clippy_lints/src/panic_in_result_fn.rs b/clippy_lints/src/panic_in_result_fn.rs index 37e2b50def17..207423a18614 100644 --- a/clippy_lints/src/panic_in_result_fn.rs +++ b/clippy_lints/src/panic_in_result_fn.rs @@ -43,9 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for PanicInResultFn { span: Span, hir_id: hir::HirId, ) { - if !matches!(fn_kind, FnKind::Closure(_)) - && is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::result_type) - { + if !matches!(fn_kind, FnKind::Closure) && is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::result_type) { lint_impl_body(cx, span, body); } } diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index b9ba32001b51..ff700aa51460 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -224,10 +224,11 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { } match kind { - FnKind::ItemFn(.., header, _, attrs) => { + FnKind::ItemFn(.., header, _) => { if header.abi != Abi::Rust { return; } + let attrs = cx.tcx.hir().attrs(hir_id); for a in attrs { if let Some(meta_items) = a.meta_item_list() { if a.has_name(sym::proc_macro_derive) @@ -239,7 +240,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { } }, FnKind::Method(..) => (), - FnKind::Closure(..) => return, + FnKind::Closure => return, } // Exclude non-inherent impls diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index e438f92b136a..28d7011207f8 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -131,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for Return { _: HirId, ) { match kind { - FnKind::Closure(_) => { + FnKind::Closure => { // when returning without value in closure, replace this `return` // with an empty block to prevent invalid suggestion (see #6501) let replacement = if let ExprKind::Ret(None) = &body.value.kind { diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index 1e58576d0599..8e076397c119 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -66,12 +66,12 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { ) { // Abort if public function/method or closure. match fn_kind { - FnKind::ItemFn(.., visibility, _) | FnKind::Method(.., Some(visibility), _) => { + FnKind::ItemFn(.., visibility) | FnKind::Method(.., Some(visibility)) => { if visibility.node.is_pub() { return; } }, - FnKind::Closure(..) => return, + FnKind::Closure => return, _ => (), } From 3346f4eec45fd68bc3c0fdb2a73cd48bbcc3fdd9 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 25 Nov 2020 22:07:09 +0100 Subject: [PATCH 0205/1222] Remove hir::StmtKind::attrs. --- clippy_lints/src/utils/inspector.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 9c1d98cd7074..4ac15095ef5f 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -109,7 +109,7 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector { } fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx hir::Stmt<'_>) { - if !has_attr(cx.sess(), stmt.kind.attrs(|id| cx.tcx.hir().item(id))) { + if !has_attr(cx.sess(), cx.tcx.hir().attrs(stmt.hir_id)) { return; } match stmt.kind { From b910724bd5ff5c9c789b24de390c6cdbcb52d04c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 25 Nov 2020 22:45:24 +0100 Subject: [PATCH 0206/1222] Remove hir::Local::attrs. --- clippy_lints/src/returns.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 28d7011207f8..e8646695e0b2 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -81,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for Return { if let Some(stmt) = block.stmts.iter().last(); if let StmtKind::Local(local) = &stmt.kind; if local.ty.is_none(); - if local.attrs.is_empty(); + if cx.tcx.hir().attrs(local.hir_id).is_empty(); if let Some(initexpr) = &local.init; if let PatKind::Binding(.., ident, _) = local.pat.kind; if let ExprKind::Path(qpath) = &retexpr.kind; From 428ae75ebce63f1cbce4e0b1a30639346e0611fa Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 26 Nov 2020 23:38:53 +0100 Subject: [PATCH 0207/1222] Remove hir::Crate::attrs. --- clippy_lints/src/doc.rs | 5 +++-- clippy_lints/src/loops.rs | 2 +- clippy_lints/src/main_recursion.rs | 4 ++-- clippy_lints/src/missing_doc.rs | 3 ++- clippy_utils/src/lib.rs | 6 +++--- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 39a202f281cb..8deccd6f9d77 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -208,8 +208,9 @@ impl_lint_pass!(DocMarkdown => ); impl<'tcx> LateLintPass<'tcx> for DocMarkdown { - fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) { - check_attrs(cx, &self.valid_idents, &krate.item.attrs); + fn check_crate(&mut self, cx: &LateContext<'tcx>, _: &'tcx hir::Crate<'_>) { + let attrs = cx.tcx.hir().attrs(hir::CRATE_HIR_ID); + check_attrs(cx, &self.valid_idents, attrs); } fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index c89a08765750..9b626d81ebd8 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -578,7 +578,7 @@ impl<'tcx> LateLintPass<'tcx> for Loops { // also check for empty `loop {}` statements, skipping those in #[panic_handler] if block.stmts.is_empty() && block.expr.is_none() && !is_in_panic_handler(cx, expr) { let msg = "empty `loop {}` wastes CPU cycles"; - let help = if is_no_std_crate(cx.tcx.hir().krate()) { + let help = if is_no_std_crate(cx) { "you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body" } else { "you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body" diff --git a/clippy_lints/src/main_recursion.rs b/clippy_lints/src/main_recursion.rs index 1ed3f3de8390..1b274c79d382 100644 --- a/clippy_lints/src/main_recursion.rs +++ b/clippy_lints/src/main_recursion.rs @@ -32,8 +32,8 @@ pub struct MainRecursion { impl_lint_pass!(MainRecursion => [MAIN_RECURSION]); impl LateLintPass<'_> for MainRecursion { - fn check_crate(&mut self, _: &LateContext<'_>, krate: &Crate<'_>) { - self.has_no_std_attr = is_no_std_crate(krate); + fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { + self.has_no_std_attr = is_no_std_crate(cx); } fn check_expr_post(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 761b9261772b..a1eb8e29850b 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -127,7 +127,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { } fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) { - self.check_missing_docs_attrs(cx, &krate.item.attrs, krate.item.span, "the", "crate"); + let attrs = cx.tcx.hir().attrs(hir::CRATE_HIR_ID); + self.check_missing_docs_attrs(cx, attrs, krate.item.span, "the", "crate"); } fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 42512cadfb18..4cd7ed5c45da 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -61,7 +61,7 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::Node; use rustc_hir::{ - def, Arm, Block, Body, Constness, Crate, Expr, ExprKind, FnDecl, HirId, ImplItem, ImplItemKind, Item, ItemKind, + def, Arm, Block, Body, Constness, Expr, ExprKind, FnDecl, HirId, ImplItem, ImplItemKind, Item, ItemKind, MatchSource, Param, Pat, PatKind, Path, PathSegment, QPath, TraitItem, TraitItemKind, TraitRef, TyKind, Unsafety, }; use rustc_infer::infer::TyCtxtInferExt; @@ -1510,8 +1510,8 @@ pub fn is_must_use_func_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { did.map_or(false, |did| must_use_attr(&cx.tcx.get_attrs(did)).is_some()) } -pub fn is_no_std_crate(krate: &Crate<'_>) -> bool { - krate.item.attrs.iter().any(|attr| { +pub fn is_no_std_crate(cx: &LateContext<'_>) -> bool { + cx.tcx.hir().attrs(hir::CRATE_HIR_ID).iter().any(|attr| { if let ast::AttrKind::Normal(ref attr, _) = attr.kind { attr.path == sym::no_std } else { From 67e342ed4416cbc938202e0bd570e8cfd77f9dbe Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 26 Nov 2020 23:46:48 +0100 Subject: [PATCH 0208/1222] Remove hir::Arm::attrs. --- clippy_lints/src/matches.rs | 4 ++-- clippy_lints/src/utils/inspector.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index efc8b1394250..9c87759d51d2 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -1207,11 +1207,11 @@ fn find_matches_sugg(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr if b0 != b1; let if_guard = &b0_arms[0].guard; if if_guard.is_none() || b0_arms.len() == 1; - if b0_arms[0].attrs.is_empty(); + if cx.tcx.hir().attrs(b0_arms[0].hir_id).is_empty(); if b0_arms[1..].iter() .all(|arm| { find_bool_lit(&arm.body.kind, desugared).map_or(false, |b| b == b0) && - arm.guard.is_none() && arm.attrs.is_empty() + arm.guard.is_none() && cx.tcx.hir().attrs(arm.hir_id).is_empty() }); then { // The suggestion may be incorrect, because some arms can have `cfg` attributes diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 4ac15095ef5f..e1c58d88952e 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector { } fn check_arm(&mut self, cx: &LateContext<'tcx>, arm: &'tcx hir::Arm<'_>) { - if !has_attr(cx.sess(), &arm.attrs) { + if !has_attr(cx.sess(), cx.tcx.hir().attrs(arm.hir_id)) { return; } print_pat(cx, &arm.pat, 1); From b5d14ef191be24782b90c18020f81071f0b80794 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 27 Nov 2020 00:07:36 +0100 Subject: [PATCH 0209/1222] Remove hir::Variant::attrs. --- clippy_lints/src/missing_doc.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index a1eb8e29850b..8665a2d71b6d 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -192,6 +192,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { } fn check_variant(&mut self, cx: &LateContext<'tcx>, v: &'tcx hir::Variant<'_>) { - self.check_missing_docs_attrs(cx, &v.attrs, v.span, "a", "variant"); + let attrs = cx.tcx.hir().attrs(v.id); + self.check_missing_docs_attrs(cx, attrs, v.span, "a", "variant"); } } From ead41d01e7ea2365add7854d67474975a9f4e1b7 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 27 Nov 2020 00:27:34 +0100 Subject: [PATCH 0210/1222] Remove hir::StructField::attrs. --- clippy_lints/src/missing_doc.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 8665a2d71b6d..e82fe9f01000 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -187,7 +187,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn check_struct_field(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::StructField<'_>) { if !sf.is_positional() { - self.check_missing_docs_attrs(cx, &sf.attrs, sf.span, "a", "struct field"); + let attrs = cx.tcx.hir().attrs(sf.hir_id); + self.check_missing_docs_attrs(cx, attrs, sf.span, "a", "struct field"); } } From f1c3cfa4a815f0ed1c6d6f82f1a470f29074d001 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 27 Nov 2020 09:41:53 +0100 Subject: [PATCH 0211/1222] Remove hir::TraitItem::attrs. --- clippy_lints/src/attrs.rs | 2 +- clippy_lints/src/doc.rs | 3 ++- clippy_lints/src/functions.rs | 5 +++-- clippy_lints/src/inline_fn_without_body.rs | 3 ++- clippy_lints/src/missing_doc.rs | 3 ++- clippy_lints/src/missing_inline.rs | 3 ++- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 652d1fa16b6d..5ca67507a3d4 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -359,7 +359,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { if is_relevant_trait(cx, item) { - check_attrs(cx, item.span, item.ident.name, &item.attrs) + check_attrs(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id())) } } } diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 8deccd6f9d77..5299b192f501 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -250,7 +250,8 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { } fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { - let headers = check_attrs(cx, &self.valid_idents, &item.attrs); + let attrs = cx.tcx.hir().attrs(item.hir_id()); + let headers = check_attrs(cx, &self.valid_idents, attrs); if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { if !in_external_macro(cx.tcx.sess, item.span) { lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, None, None); diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index ae0b8d06dc2f..4a10f9abce4b 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -344,7 +344,8 @@ impl<'tcx> LateLintPass<'tcx> for Functions { check_result_unit_err(cx, &sig.decl, item.span, fn_header_span); } - let attr = must_use_attr(&item.attrs); + let attrs = cx.tcx.hir().attrs(item.hir_id()); + let attr = must_use_attr(attrs); if let Some(attr) = attr { check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr); } @@ -352,7 +353,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions { let body = cx.tcx.hir().body(eid); Self::check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id()); - if attr.is_none() && is_public && !is_proc_macro(cx.sess(), &item.attrs) { + if attr.is_none() && is_public && !is_proc_macro(cx.sess(), attrs) { check_must_use_candidate( cx, &sig.decl, diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index d1c3fdc71461..00acbd6cc3f7 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -34,7 +34,8 @@ declare_lint_pass!(InlineFnWithoutBody => [INLINE_FN_WITHOUT_BODY]); impl<'tcx> LateLintPass<'tcx> for InlineFnWithoutBody { fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { if let TraitItemKind::Fn(_, TraitFn::Required(_)) = item.kind { - check_attrs(cx, item.ident.name, &item.attrs); + let attrs = cx.tcx.hir().attrs(item.hir_id()); + check_attrs(cx, item.ident.name, attrs); } } } diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index e82fe9f01000..0a75b47e2c65 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -167,7 +167,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) { let (article, desc) = cx.tcx.article_and_description(trait_item.def_id.to_def_id()); - self.check_missing_docs_attrs(cx, &trait_item.attrs, trait_item.span, article, desc); + let attrs = cx.tcx.hir().attrs(trait_item.hir_id()); + self.check_missing_docs_attrs(cx, attrs, trait_item.span, article, desc); } fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 47d7c5306c43..74afc292f018 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -108,7 +108,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { // an impl is not provided let desc = "a default trait method"; let item = cx.tcx.hir().trait_item(tit.id); - check_missing_inline_attrs(cx, &item.attrs, item.span, desc); + let attrs = cx.tcx.hir().attrs(item.hir_id()); + check_missing_inline_attrs(cx, attrs, item.span, desc); } }, } From bb5b738bd505507a4c90b71fcfe9d9aa32e060b1 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 27 Nov 2020 09:55:10 +0100 Subject: [PATCH 0212/1222] Remove hir::ImplItem::attrs. --- clippy_lints/src/attrs.rs | 2 +- clippy_lints/src/doc.rs | 3 ++- clippy_lints/src/functions.rs | 5 +++-- clippy_lints/src/missing_doc.rs | 3 ++- clippy_lints/src/missing_inline.rs | 3 ++- clippy_lints/src/utils/inspector.rs | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 5ca67507a3d4..362b11792a8d 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -353,7 +353,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { if is_relevant_impl(cx, item) { - check_attrs(cx, item.span, item.ident.name, &item.attrs) + check_attrs(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id())) } } diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 5299b192f501..058f64780d69 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -260,7 +260,8 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { } fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { - let headers = check_attrs(cx, &self.valid_idents, &item.attrs); + let attrs = cx.tcx.hir().attrs(item.hir_id()); + let headers = check_attrs(cx, &self.valid_idents, attrs); if self.in_trait_impl || in_external_macro(cx.tcx.sess, item.span) { return; } diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 4a10f9abce4b..b48b0b9f3e2f 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -312,11 +312,12 @@ impl<'tcx> LateLintPass<'tcx> for Functions { if is_public && trait_ref_of_method(cx, item.hir_id()).is_none() { check_result_unit_err(cx, &sig.decl, item.span, fn_header_span); } - let attr = must_use_attr(&item.attrs); + let attrs = cx.tcx.hir().attrs(item.hir_id()); + let attr = must_use_attr(attrs); if let Some(attr) = attr { check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr); } else if is_public - && !is_proc_macro(cx.sess(), &item.attrs) + && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.hir_id()).is_none() { check_must_use_candidate( diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 0a75b47e2c65..84852dd602bb 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -183,7 +183,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { } let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id()); - self.check_missing_docs_attrs(cx, &impl_item.attrs, impl_item.span, article, desc); + let attrs = cx.tcx.hir().attrs(impl_item.hir_id()); + self.check_missing_docs_attrs(cx, attrs, impl_item.span, article, desc); } fn check_struct_field(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::StructField<'_>) { diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 74afc292f018..c915e329087f 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -161,6 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { } } - check_missing_inline_attrs(cx, &impl_item.attrs, impl_item.span, desc); + let attrs = cx.tcx.hir().attrs(impl_item.hir_id()); + check_missing_inline_attrs(cx, attrs, impl_item.span, desc); } } diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index e1c58d88952e..e95840e9db1c 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -40,7 +40,7 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector { } fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { - if !has_attr(cx.sess(), &item.attrs) { + if !has_attr(cx.sess(), cx.tcx.hir().attrs(item.hir_id())) { return; } println!("impl item `{}`", item.ident.name); From db31176d43b85ab0bafebeeedee1528a52153b7a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 24 Jan 2021 13:17:54 +0100 Subject: [PATCH 0213/1222] Remove hir::Item::attrs. --- clippy_lints/src/attrs.rs | 7 ++++--- clippy_lints/src/derive.rs | 3 ++- clippy_lints/src/doc.rs | 3 ++- clippy_lints/src/exhaustive_items.rs | 3 ++- clippy_lints/src/functions.rs | 5 +++-- clippy_lints/src/macro_use.rs | 4 ++-- clippy_lints/src/missing_doc.rs | 3 ++- clippy_lints/src/missing_inline.rs | 3 ++- clippy_lints/src/needless_borrow.rs | 5 +++-- clippy_lints/src/partialeq_ne_impl.rs | 3 ++- clippy_lints/src/utils/inspector.rs | 2 +- 11 files changed, 25 insertions(+), 16 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 362b11792a8d..78f0846e88e7 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -276,14 +276,15 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { } fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { + let attrs = cx.tcx.hir().attrs(item.hir_id()); if is_relevant_item(cx, item) { - check_attrs(cx, item.span, item.ident.name, &item.attrs) + check_attrs(cx, item.span, item.ident.name, attrs) } match item.kind { ItemKind::ExternCrate(..) | ItemKind::Use(..) => { - let skip_unused_imports = item.attrs.iter().any(|attr| attr.has_name(sym::macro_use)); + let skip_unused_imports = attrs.iter().any(|attr| attr.has_name(sym::macro_use)); - for attr in item.attrs { + for attr in attrs { if in_external_macro(cx.sess(), attr.span) { return; } diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index e8510bde9adc..66cf6682f850 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -170,7 +170,8 @@ impl<'tcx> LateLintPass<'tcx> for Derive { }) = item.kind { let ty = cx.tcx.type_of(item.def_id); - let is_automatically_derived = is_automatically_derived(&*item.attrs); + let attrs = cx.tcx.hir().attrs(item.hir_id()); + let is_automatically_derived = is_automatically_derived(attrs); check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived); check_ord_partial_ord(cx, item.span, trait_ref, ty, is_automatically_derived); diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 058f64780d69..23c99e45ca7f 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -214,7 +214,8 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { } fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { - let headers = check_attrs(cx, &self.valid_idents, &item.attrs); + let attrs = cx.tcx.hir().attrs(item.hir_id()); + let headers = check_attrs(cx, &self.valid_idents, attrs); match item.kind { hir::ItemKind::Fn(ref sig, _, body_id) => { if !(is_entrypoint_fn(cx, item.def_id.to_def_id()) || in_external_macro(cx.tcx.sess, item.span)) { diff --git a/clippy_lints/src/exhaustive_items.rs b/clippy_lints/src/exhaustive_items.rs index ab9be3398bfa..316f74848628 100644 --- a/clippy_lints/src/exhaustive_items.rs +++ b/clippy_lints/src/exhaustive_items.rs @@ -73,7 +73,8 @@ impl LateLintPass<'_> for ExhaustiveItems { if_chain! { if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind; if cx.access_levels.is_exported(item.hir_id()); - if !item.attrs.iter().any(|a| a.has_name(sym::non_exhaustive)); + let attrs = cx.tcx.hir().attrs(item.hir_id()); + if !attrs.iter().any(|a| a.has_name(sym::non_exhaustive)); then { let (lint, msg) = if let ItemKind::Struct(ref v, ..) = item.kind { if v.fields().iter().any(|f| !f.vis.node.is_pub()) { diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index b48b0b9f3e2f..234cb0f53aa0 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -280,7 +280,8 @@ impl<'tcx> LateLintPass<'tcx> for Functions { } fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { - let attr = must_use_attr(&item.attrs); + let attrs = cx.tcx.hir().attrs(item.hir_id()); + let attr = must_use_attr(attrs); if let hir::ItemKind::Fn(ref sig, ref _generics, ref body_id) = item.kind { let is_public = cx.access_levels.is_exported(item.hir_id()); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); @@ -291,7 +292,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions { check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr); return; } - if is_public && !is_proc_macro(cx.sess(), &item.attrs) && attr_by_name(&item.attrs, "no_mangle").is_none() { + if is_public && !is_proc_macro(cx.sess(), attrs) && attr_by_name(attrs, "no_mangle").is_none() { check_must_use_candidate( cx, &sig.decl, diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index 40f04bd677d5..6d9c78393c8c 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -107,8 +107,8 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports { if_chain! { if cx.sess().opts.edition >= Edition::Edition2018; if let hir::ItemKind::Use(path, _kind) = &item.kind; - if let Some(mac_attr) = item - .attrs + let attrs = cx.tcx.hir().attrs(item.hir_id()); + if let Some(mac_attr) = attrs .iter() .find(|attr| attr.ident().map(|s| s.to_string()) == Some("macro_use".to_string())); if let Res::Def(DefKind::Mod, id) = path.res; diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 84852dd602bb..6ec4c38d0f9c 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -161,7 +161,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { let (article, desc) = cx.tcx.article_and_description(it.def_id.to_def_id()); - self.check_missing_docs_attrs(cx, &it.attrs, it.span, article, desc); + let attrs = cx.tcx.hir().attrs(it.hir_id()); + self.check_missing_docs_attrs(cx, attrs, it.span, article, desc); } fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) { diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index c915e329087f..9b604471573d 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -93,7 +93,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { match it.kind { hir::ItemKind::Fn(..) => { let desc = "a function"; - check_missing_inline_attrs(cx, &it.attrs, it.span, desc); + let attrs = cx.tcx.hir().attrs(it.hir_id()); + check_missing_inline_attrs(cx, attrs, it.span, desc); }, hir::ItemKind::Trait(ref _is_auto, ref _unsafe, ref _generics, ref _bounds, trait_items) => { // note: we need to check if the trait is exported so we can't use diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index 1453ea6e8975..1aadcfd87b60 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -115,8 +115,9 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow { } } - fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if is_automatically_derived(item.attrs) { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { + let attrs = cx.tcx.hir().attrs(item.hir_id()); + if is_automatically_derived(attrs) { debug_assert!(self.derived_item.is_none()); self.derived_item = Some(item.def_id); } diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index 3d6129aa78d4..aca1ed5ca656 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -35,7 +35,8 @@ impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if_chain! { if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), items: impl_items, .. }) = item.kind; - if !is_automatically_derived(&*item.attrs); + let attrs = cx.tcx.hir().attrs(item.hir_id()); + if !is_automatically_derived(attrs); if let Some(eq_trait) = cx.tcx.lang_items().eq_trait(); if trait_ref.path.res.def_id() == eq_trait; then { diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index e95840e9db1c..07a79592a4ac 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -33,7 +33,7 @@ declare_lint_pass!(DeepCodeInspector => [DEEP_CODE_INSPECTION]); impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { - if !has_attr(cx.sess(), &item.attrs) { + if !has_attr(cx.sess(), cx.tcx.hir().attrs(item.hir_id())) { return; } print_item(cx, item); From 0daac8b4262f082b06125b736c1ce243e7a0a122 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 27 Nov 2020 17:41:05 +0100 Subject: [PATCH 0214/1222] Remove hir::Expr::attrs. --- clippy_lints/src/returns.rs | 3 ++- clippy_lints/src/utils/inspector.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index e8646695e0b2..40c0f1f45895 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -177,7 +177,8 @@ fn check_final_expr<'tcx>( // simple return is always "bad" ExprKind::Ret(ref inner) => { // allow `#[cfg(a)] return a; #[cfg(b)] return b;` - if !expr.attrs.iter().any(attr_is_cfg) { + let attrs = cx.tcx.hir().attrs(expr.hir_id); + if !attrs.iter().any(attr_is_cfg) { let borrows = inner.map_or(false, |inner| last_statement_borrows(cx, inner)); if !borrows { emit_return_lint( diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 07a79592a4ac..9e3973e1d51f 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector { // fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - if !has_attr(cx.sess(), &expr.attrs) { + if !has_attr(cx.sess(), cx.tcx.hir().attrs(expr.hir_id)) { return; } print_expr(cx, expr, 0); From 638b2d50ee2540bd59176d155359b163f4ddde01 Mon Sep 17 00:00:00 2001 From: bstrie <865233+bstrie@users.noreply.github.com> Date: Sun, 14 Feb 2021 16:42:38 -0500 Subject: [PATCH 0215/1222] Deprecate items that accidentally weren't deprecated Fixes #82080 --- clippy_lints/src/matches.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index efc8b1394250..9b7328caf318 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -27,7 +27,7 @@ use rustc_span::source_map::{Span, Spanned}; use rustc_span::sym; use std::cmp::Ordering; use std::collections::hash_map::Entry; -use std::collections::Bound; +use std::ops::Bound; declare_clippy_lint! { /// **What it does:** Checks for matches with a single arm where an `if let` From 3c4b6f4ad04b7f9e7aa71cdb11f725b26682ccd4 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Fri, 12 Mar 2021 15:32:04 +0100 Subject: [PATCH 0216/1222] Clippy: HACK! Fix bootstrap error This will be removed in the next sync, once beta is at 1.52. Until then this hack avoids to put `cfg(bootstrap)` into Clippy. --- clippy_lints/src/loops/manual_memcpy.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index fad96c2d5c04..11660a8fe0df 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -203,8 +203,11 @@ struct MinifyingSugg<'a>(Sugg<'a>); impl<'a> MinifyingSugg<'a> { fn as_str(&self) -> &str { - let (Sugg::NonParen(s) | Sugg::MaybeParen(s) | Sugg::BinOp(_, s)) = &self.0; - s.as_ref() + // HACK: Don't sync to Clippy! Required because something with the `or_patterns` feature + // changed and this would now require parentheses. + match &self.0 { + Sugg::NonParen(s) | Sugg::MaybeParen(s) | Sugg::BinOp(_, s) => s.as_ref(), + } } fn into_sugg(self) -> Sugg<'a> { From 635a44abf6cf915151376380258d91568cea0c93 Mon Sep 17 00:00:00 2001 From: Roxane Date: Thu, 25 Feb 2021 15:33:18 -0500 Subject: [PATCH 0217/1222] Add fake_read() to clippy --- clippy_lints/src/escape.rs | 3 +++ clippy_lints/src/needless_pass_by_value.rs | 3 +++ clippy_utils/src/usage.rs | 3 +++ 3 files changed, 9 insertions(+) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index f8ef2a464d5c..6994e9f7d2e6 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -2,6 +2,7 @@ use rustc_hir::intravisit; use rustc_hir::{self, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::{self, TraitRef, Ty}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; @@ -184,6 +185,8 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { } } } + + fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause) { } } impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index cac4b2075114..d5a9d5e4e13b 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -11,6 +11,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, Impl, ItemKind, Node, PatKind, QPath, TyKind}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::{self, TypeFoldable}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::kw; @@ -333,4 +334,6 @@ impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt { fn borrow(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {} fn mutate(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId) {} + + fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause) { } } diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index d577827dcf3c..8aa8781f6be3 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -7,6 +7,7 @@ use rustc_hir::intravisit::{NestedVisitorMap, Visitor}; use rustc_hir::{Expr, ExprKind, HirId, Path}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; +use rustc_middle::mir::FakeReadCause; use rustc_middle::hir::map::Map; use rustc_middle::ty; use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; @@ -77,6 +78,8 @@ impl<'tcx> Delegate<'tcx> for MutVarsDelegate { fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) { self.update(&cmt) } + + fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause) { } } pub struct ParamBindingIdCollector { From d8fca781e9de1f9df52f4df658e1cc45976817fb Mon Sep 17 00:00:00 2001 From: hyd-dev Date: Mon, 15 Mar 2021 18:24:28 +0800 Subject: [PATCH 0218/1222] Use `rustc_interface::interface::Config::parse_sess_created` in Clippy --- src/driver.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index 30272c9b8006..b6aed862e895 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -15,7 +15,7 @@ extern crate rustc_session; extern crate rustc_span; use rustc_interface::interface; -use rustc_session::Session; +use rustc_session::parse::ParseSess; use rustc_span::symbol::Symbol; use rustc_tools_util::VersionInfo; @@ -63,8 +63,8 @@ fn test_arg_value() { assert_eq!(arg_value(args, "--foo", |_| true), None); } -fn track_clippy_args(sess: &Session, args_env_var: &Option) { - sess.parse_sess.env_depinfo.borrow_mut().insert(( +fn track_clippy_args(parse_sess: &mut ParseSess, args_env_var: &Option) { + parse_sess.env_depinfo.get_mut().insert(( Symbol::intern("CLIPPY_ARGS"), args_env_var.as_deref().map(Symbol::intern), )); @@ -81,14 +81,9 @@ struct RustcCallbacks { impl rustc_driver::Callbacks for RustcCallbacks { fn config(&mut self, config: &mut interface::Config) { - let previous = config.register_lints.take(); let clippy_args_var = self.clippy_args_var.take(); - config.register_lints = Some(Box::new(move |sess, lint_store| { - if let Some(ref previous) = previous { - (previous)(sess, lint_store); - } - - track_clippy_args(sess, &clippy_args_var); + config.parse_sess_created = Some(Box::new(move |parse_sess| { + track_clippy_args(parse_sess, &clippy_args_var); })); } } @@ -101,6 +96,9 @@ impl rustc_driver::Callbacks for ClippyCallbacks { fn config(&mut self, config: &mut interface::Config) { let previous = config.register_lints.take(); let clippy_args_var = self.clippy_args_var.take(); + config.parse_sess_created = Some(Box::new(move |parse_sess| { + track_clippy_args(parse_sess, &clippy_args_var); + })); config.register_lints = Some(Box::new(move |sess, mut lint_store| { // technically we're ~guaranteed that this is none but might as well call anything that // is there already. Certainly it can't hurt. @@ -108,8 +106,6 @@ impl rustc_driver::Callbacks for ClippyCallbacks { (previous)(sess, lint_store); } - track_clippy_args(sess, &clippy_args_var); - let conf = clippy_lints::read_conf(&[], &sess); clippy_lints::register_plugins(&mut lint_store, &sess, &conf); clippy_lints::register_pre_expansion_lints(&mut lint_store); From 3b26508ba6205687e1730925b7e22d3478d79b14 Mon Sep 17 00:00:00 2001 From: Roxane Date: Thu, 25 Feb 2021 18:03:41 -0500 Subject: [PATCH 0219/1222] Add comments with examples and tests --- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_utils/src/usage.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 6994e9f7d2e6..972167575475 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -186,7 +186,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { } } - fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause) { } + fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _: HirId) { } } impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index d5a9d5e4e13b..d439577f9c33 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -335,5 +335,5 @@ impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt { fn mutate(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId) {} - fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause) { } + fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _: HirId) { } } diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index 8aa8781f6be3..0b1ab6b7ea18 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -79,7 +79,7 @@ impl<'tcx> Delegate<'tcx> for MutVarsDelegate { self.update(&cmt) } - fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause) { } + fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _:HirId) { } } pub struct ParamBindingIdCollector { From 9a41dc58e76c09f06117e87e0d27a68608367126 Mon Sep 17 00:00:00 2001 From: Roxane Date: Sun, 14 Mar 2021 23:53:43 -0400 Subject: [PATCH 0220/1222] Fix error after rebase --- clippy_lints/src/loops/mut_range_bound.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index 3ae592950f13..cb56512db60f 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -4,6 +4,7 @@ use if_chain::if_chain; use rustc_hir::{BindingAnnotation, Expr, HirId, Node, PatKind}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; +use rustc_middle::mir::FakeReadCause; use rustc_middle::ty; use rustc_span::source_map::Span; use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; @@ -106,6 +107,8 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> { } } } + + fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _:HirId) { } } impl MutatePairDelegate<'_, '_> { From 0c1fe40ea5ecb622139955e02c37198495eab38d Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 15 Mar 2021 23:52:57 +0300 Subject: [PATCH 0221/1222] Update clippy tests --- tests/ui/use_self.fixed | 23 +++++++++++----------- tests/ui/use_self.rs | 23 +++++++++++----------- tests/ui/use_self.stderr | 16 ++------------- tests/ui/zero_sized_btreemap_values.stderr | 2 +- tests/ui/zero_sized_hashmap_values.stderr | 2 +- 5 files changed, 28 insertions(+), 38 deletions(-) diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed index a630936e3b1d..b94d5448d923 100644 --- a/tests/ui/use_self.fixed +++ b/tests/ui/use_self.fixed @@ -312,17 +312,18 @@ mod issue4140 { fn try_from(value: T) -> Result>; } - impl TryFrom for T - where - T: From, - { - type From = Self; - type To = Self; - - fn try_from(value: F) -> Result> { - Ok(From::from(value)) - } - } + // FIXME: Suggested fix results in infinite recursion. + // impl TryFrom for T + // where + // T: From, + // { + // type From = Self::From; + // type To = Self::To; + + // fn try_from(value: F) -> Result> { + // Ok(From::from(value)) + // } + // } impl From for i64 { type From = bool; diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index f3e081dd2032..ac99c6d9d7bb 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -312,17 +312,18 @@ mod issue4140 { fn try_from(value: T) -> Result>; } - impl TryFrom for T - where - T: From, - { - type From = T::From; - type To = T::To; - - fn try_from(value: F) -> Result> { - Ok(From::from(value)) - } - } + // FIXME: Suggested fix results in infinite recursion. + // impl TryFrom for T + // where + // T: From, + // { + // type From = Self::From; + // type To = Self::To; + + // fn try_from(value: F) -> Result> { + // Ok(From::from(value)) + // } + // } impl From for i64 { type From = bool; diff --git a/tests/ui/use_self.stderr b/tests/ui/use_self.stderr index e1410d2e652c..a32a9b9157d7 100644 --- a/tests/ui/use_self.stderr +++ b/tests/ui/use_self.stderr @@ -157,22 +157,10 @@ LL | Foo { value } | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:319:21 - | -LL | type From = T::From; - | ^^^^^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:320:19 - | -LL | type To = T::To; - | ^^^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> $DIR/use_self.rs:453:13 + --> $DIR/use_self.rs:454:13 | LL | A::new::(submod::B {}) | ^ help: use the applicable keyword: `Self` -error: aborting due to 29 previous errors +error: aborting due to 27 previous errors diff --git a/tests/ui/zero_sized_btreemap_values.stderr b/tests/ui/zero_sized_btreemap_values.stderr index 334d921a9af3..d924f33797d2 100644 --- a/tests/ui/zero_sized_btreemap_values.stderr +++ b/tests/ui/zero_sized_btreemap_values.stderr @@ -83,7 +83,7 @@ error: map with zero-sized value type --> $DIR/zero_sized_btreemap_values.rs:64:35 | LL | let _: BTreeMap = BTreeMap::new(); - | ^^^^^^^^^^^^^ + | ^^^^^^^^ | = help: consider using a set instead diff --git a/tests/ui/zero_sized_hashmap_values.stderr b/tests/ui/zero_sized_hashmap_values.stderr index 43987b3d01d1..79770bf90d70 100644 --- a/tests/ui/zero_sized_hashmap_values.stderr +++ b/tests/ui/zero_sized_hashmap_values.stderr @@ -83,7 +83,7 @@ error: map with zero-sized value type --> $DIR/zero_sized_hashmap_values.rs:64:34 | LL | let _: HashMap = HashMap::new(); - | ^^^^^^^^^^^^ + | ^^^^^^^ | = help: consider using a set instead From fbab432cab7b50a05401b85084183c5fad2fee08 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 16 Mar 2021 00:36:07 +0300 Subject: [PATCH 0222/1222] ast/hir: Rename field-related structures StructField -> FieldDef ("field definition") Field -> ExprField ("expression field", not "field expression") FieldPat -> PatField ("pattern field", not "field pattern") Also rename visiting and other methods working on them. --- clippy_lints/src/inconsistent_struct_constructor.rs | 2 +- clippy_lints/src/manual_non_exhaustive.rs | 6 +++--- clippy_lints/src/missing_doc.rs | 2 +- clippy_lints/src/pattern_type_mismatch.rs | 4 ++-- clippy_lints/src/types/mod.rs | 4 ++-- clippy_lints/src/unnested_or_patterns.rs | 2 +- clippy_lints/src/utils/author.rs | 4 ++-- clippy_lints/src/utils/inspector.rs | 4 ++-- clippy_utils/src/ast_utils.rs | 6 +++--- clippy_utils/src/higher.rs | 2 +- clippy_utils/src/hir_utils.rs | 8 ++++---- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/clippy_lints/src/inconsistent_struct_constructor.rs b/clippy_lints/src/inconsistent_struct_constructor.rs index 4f35e13c85a1..48aef74e4d3c 100644 --- a/clippy_lints/src/inconsistent_struct_constructor.rs +++ b/clippy_lints/src/inconsistent_struct_constructor.rs @@ -119,7 +119,7 @@ impl LateLintPass<'_> for InconsistentStructConstructor { // Check whether the order of the fields in the constructor is consistent with the order in the // definition. -fn is_consistent_order<'tcx>(fields: &'tcx [hir::Field<'tcx>], def_order_map: &FxHashMap) -> bool { +fn is_consistent_order<'tcx>(fields: &'tcx [hir::ExprField<'tcx>], def_order_map: &FxHashMap) -> bool { let mut cur_idx = usize::MIN; for f in fields { let next_idx = def_order_map[&f.ident.name]; diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 91849e748878..7e6d4d3a2160 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -1,6 +1,6 @@ use crate::utils::{meets_msrv, snippet_opt, span_lint_and_then}; use if_chain::if_chain; -use rustc_ast::ast::{Attribute, Item, ItemKind, StructField, Variant, VariantData, VisibilityKind}; +use rustc_ast::ast::{Attribute, Item, ItemKind, FieldDef, Variant, VariantData, VisibilityKind}; use rustc_attr as attr; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; @@ -142,11 +142,11 @@ fn check_manual_non_exhaustive_enum(cx: &EarlyContext<'_>, item: &Item, variants } fn check_manual_non_exhaustive_struct(cx: &EarlyContext<'_>, item: &Item, data: &VariantData) { - fn is_private(field: &StructField) -> bool { + fn is_private(field: &FieldDef) -> bool { matches!(field.vis.kind, VisibilityKind::Inherited) } - fn is_non_exhaustive_marker(field: &StructField) -> bool { + fn is_non_exhaustive_marker(field: &FieldDef) -> bool { is_private(field) && field.ty.kind.is_unit() && field.ident.map_or(true, |n| n.as_str().starts_with('_')) } diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 6ec4c38d0f9c..985a66b6cfca 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -188,7 +188,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { self.check_missing_docs_attrs(cx, attrs, impl_item.span, article, desc); } - fn check_struct_field(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::StructField<'_>) { + fn check_field_def(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::FieldDef<'_>) { if !sf.is_positional() { let attrs = cx.tcx.hir().attrs(sf.hir_id); self.check_missing_docs_attrs(cx, attrs, sf.span, "a", "struct field"); diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index 5539331d0460..e76c8624b6fe 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -1,6 +1,6 @@ use crate::utils::{last_path_segment, span_lint_and_help}; use rustc_hir::{ - intravisit, Body, Expr, ExprKind, FieldPat, FnDecl, HirId, LocalSource, MatchSource, Mutability, Pat, PatKind, + intravisit, Body, Expr, ExprKind, PatField, FnDecl, HirId, LocalSource, MatchSource, Mutability, Pat, PatKind, QPath, Stmt, StmtKind, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; @@ -281,7 +281,7 @@ where fn find_first_mismatch_in_struct<'tcx>( cx: &LateContext<'tcx>, - field_pats: &[FieldPat<'_>], + field_pats: &[PatField<'_>], field_defs: &[FieldDef], substs_ref: SubstsRef<'tcx>, ) -> Option<(Span, Mutability, Level)> { diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 13da768b0ca3..f7a6399a7f04 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -271,7 +271,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { self.check_fn_decl(cx, decl); } - fn check_struct_field(&mut self, cx: &LateContext<'_>, field: &hir::StructField<'_>) { + fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) { self.check_ty(cx, &field.ty, false); } @@ -821,7 +821,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeComplexity { self.check_fndecl(cx, decl); } - fn check_struct_field(&mut self, cx: &LateContext<'tcx>, field: &'tcx hir::StructField<'_>) { + fn check_field_def(&mut self, cx: &LateContext<'tcx>, field: &'tcx hir::FieldDef<'_>) { // enum variants are also struct fields now self.check_type(cx, &field.ty); } diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 7f4f16f8faf9..fa613bb7da30 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -276,7 +276,7 @@ fn transform_with_focus_on_idx(alternatives: &mut Vec>, focus_idx: usize) /// and check that all `fp_i` where `i ∈ ((0...n) \ k)` between two patterns are equal. fn extend_with_struct_pat( path1: &ast::Path, - fps1: &mut Vec, + fps1: &mut Vec, rest1: bool, start: usize, alternatives: &mut Vec>, diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 3dd190ba4401..c57614800805 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -101,12 +101,12 @@ impl<'tcx> LateLintPass<'tcx> for Author { done(); } - fn check_struct_field(&mut self, cx: &LateContext<'tcx>, field: &'tcx hir::StructField<'_>) { + fn check_field_def(&mut self, cx: &LateContext<'tcx>, field: &'tcx hir::FieldDef<'_>) { if !has_attr(cx, field.hir_id) { return; } prelude(); - PrintVisitor::new("field").visit_struct_field(field); + PrintVisitor::new("field").visit_field_def(field); done(); } diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 9e3973e1d51f..64ee9e65bb1a 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -80,8 +80,8 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector { // } // } // - // fn check_struct_field(&mut self, cx: &LateContext<'tcx>, field: &'tcx - // hir::StructField) { + // fn check_field_def(&mut self, cx: &LateContext<'tcx>, field: &'tcx + // hir::FieldDef) { // if !has_attr(&field.attrs) { // return; // } diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 9ef1557ec061..05afa5342962 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -66,7 +66,7 @@ pub fn eq_range_end(l: &RangeEnd, r: &RangeEnd) -> bool { } } -pub fn eq_field_pat(l: &FieldPat, r: &FieldPat) -> bool { +pub fn eq_field_pat(l: &PatField, r: &PatField) -> bool { l.is_placeholder == r.is_placeholder && eq_id(l.ident, r.ident) && eq_pat(&l.pat, &r.pat) @@ -175,7 +175,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { } } -pub fn eq_field(l: &Field, r: &Field) -> bool { +pub fn eq_field(l: &ExprField, r: &ExprField) -> bool { l.is_placeholder == r.is_placeholder && eq_id(l.ident, r.ident) && eq_expr(&l.expr, &r.expr) @@ -359,7 +359,7 @@ pub fn eq_variant_data(l: &VariantData, r: &VariantData) -> bool { } } -pub fn eq_struct_field(l: &StructField, r: &StructField) -> bool { +pub fn eq_struct_field(l: &FieldDef, r: &FieldDef) -> bool { l.is_placeholder == r.is_placeholder && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)) && eq_vis(&l.vis, &r.vis) diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index be22df7109af..0c0e4d3b4ce8 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -51,7 +51,7 @@ pub struct Range<'a> { pub fn range<'a>(expr: &'a hir::Expr<'_>) -> Option> { /// Finds the field named `name` in the field. Always return `Some` for /// convenience. - fn get_field<'c>(name: &str, fields: &'c [hir::Field<'_>]) -> Option<&'c hir::Expr<'c>> { + fn get_field<'c>(name: &str, fields: &'c [hir::ExprField<'_>]) -> Option<&'c hir::Expr<'c>> { let expr = &fields.iter().find(|field| field.ident.name.as_str() == name)?.expr; Some(expr) diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index e28ad27d9a6f..af82f992d56f 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -5,7 +5,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir::def::Res; use rustc_hir::{ - BinOpKind, Block, BlockCheckMode, BodyId, BorrowKind, CaptureBy, Expr, ExprKind, Field, FieldPat, FnRetTy, + BinOpKind, Block, BlockCheckMode, BodyId, BorrowKind, CaptureBy, Expr, ExprKind, ExprField, PatField, FnRetTy, GenericArg, GenericArgs, Guard, HirId, InlineAsmOperand, Lifetime, LifetimeName, ParamName, Pat, PatKind, Path, PathSegment, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding, }; @@ -266,7 +266,7 @@ impl HirEqInterExpr<'_, '_, '_> { over(left, right, |l, r| self.eq_expr(l, r)) } - fn eq_field(&mut self, left: &Field<'_>, right: &Field<'_>) -> bool { + fn eq_field(&mut self, left: &ExprField<'_>, right: &ExprField<'_>) -> bool { left.ident.name == right.ident.name && self.eq_expr(&left.expr, &right.expr) } @@ -290,8 +290,8 @@ impl HirEqInterExpr<'_, '_, '_> { left.name == right.name } - fn eq_fieldpat(&mut self, left: &FieldPat<'_>, right: &FieldPat<'_>) -> bool { - let (FieldPat { ident: li, pat: lp, .. }, FieldPat { ident: ri, pat: rp, .. }) = (&left, &right); + fn eq_fieldpat(&mut self, left: &PatField<'_>, right: &PatField<'_>) -> bool { + let (PatField { ident: li, pat: lp, .. }, PatField { ident: ri, pat: rp, .. }) = (&left, &right); li.name == ri.name && self.eq_pat(lp, rp) } From 7e830c043c669579746798144266a3feb15dacf3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 16 Mar 2021 03:15:53 +0300 Subject: [PATCH 0223/1222] ast: Reduce size of `ExprKind` by boxing fields of `ExprKind::Struct` --- clippy_lints/src/redundant_field_names.rs | 4 ++-- clippy_lints/src/suspicious_operation_groupings.rs | 2 +- clippy_utils/src/ast_utils.rs | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/redundant_field_names.rs b/clippy_lints/src/redundant_field_names.rs index 38dcf7a192c8..9688ef393313 100644 --- a/clippy_lints/src/redundant_field_names.rs +++ b/clippy_lints/src/redundant_field_names.rs @@ -58,8 +58,8 @@ impl EarlyLintPass for RedundantFieldNames { if in_external_macro(cx.sess, expr.span) { return; } - if let ExprKind::Struct(_, ref fields, _) = expr.kind { - for field in fields { + if let ExprKind::Struct(ref se) = expr.kind { + for field in &se.fields { if field.is_shorthand { continue; } diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index 44521885d200..9acc47deb066 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -564,7 +564,7 @@ fn ident_difference_expr_with_base_location( | (Try(_), Try(_)) | (Paren(_), Paren(_)) | (Repeat(_, _), Repeat(_, _)) - | (Struct(_, _, _), Struct(_, _, _)) + | (Struct(_), Struct(_)) | (MacCall(_), MacCall(_)) | (LlvmInlineAsm(_), LlvmInlineAsm(_)) | (InlineAsm(_), InlineAsm(_)) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 05afa5342962..ea9a910d1b92 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -168,8 +168,10 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (AddrOf(lbk, lm, le), AddrOf(rbk, rm, re)) => lbk == rbk && lm == rm && eq_expr(le, re), (Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp), (MacCall(l), MacCall(r)) => eq_mac_call(l, r), - (Struct(lp, lfs, lb), Struct(rp, rfs, rb)) => { - eq_path(lp, rp) && eq_struct_rest(lb, rb) && unordered_over(lfs, rfs, |l, r| eq_field(l, r)) + (Struct(lse), Struct(rse)) => { + eq_path(&lse.path, &rse.path) && + eq_struct_rest(&lse.rest, &rse.rest) && + unordered_over(&lse.fields, &rse.fields, |l, r| eq_field(l, r)) }, _ => false, } From 1d25a99864cf9aa0b35cfc67209e5eccdf8e2fc3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 13 Mar 2021 15:44:29 +0300 Subject: [PATCH 0224/1222] hir: Preserve used syntax in `TyKind::TraitObject` --- clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/types/borrowed_box.rs | 4 ++-- clippy_lints/src/types/mod.rs | 2 +- clippy_utils/src/hir_utils.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 33ff01a30e88..3ac6e6cbbefc 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -387,7 +387,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { self.nested_elision_site_lts.append(&mut sub_visitor.all_lts()); return; }, - TyKind::TraitObject(bounds, ref lt) => { + TyKind::TraitObject(bounds, ref lt, _) => { if !lt.is_elided() { self.unelided_trait_object_lifetime = true; } diff --git a/clippy_lints/src/types/borrowed_box.rs b/clippy_lints/src/types/borrowed_box.rs index a7a511b21cf5..81090040d92e 100644 --- a/clippy_lints/src/types/borrowed_box.rs +++ b/clippy_lints/src/types/borrowed_box.rs @@ -50,7 +50,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m // Originally reported as the issue #3128. let inner_snippet = snippet(cx, inner.span, ".."); let suggestion = match &inner.kind { - TyKind::TraitObject(bounds, lt_bound) if bounds.len() > 1 || !lt_bound.is_elided() => { + TyKind::TraitObject(bounds, lt_bound, _) if bounds.len() > 1 || !lt_bound.is_elided() => { format!("&{}({})", ltopt, &inner_snippet) }, TyKind::Path(qpath) @@ -86,7 +86,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m // Returns true if given type is `Any` trait. fn is_any_trait(t: &hir::Ty<'_>) -> bool { if_chain! { - if let TyKind::TraitObject(ref traits, _) = t.kind; + if let TyKind::TraitObject(ref traits, ..) = t.kind; if !traits.is_empty(); // Only Send/Sync can be used as additional traits, so it is enough to // check only the first trait. diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index f7a6399a7f04..4a1a608e8ae6 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -911,7 +911,7 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor { // function types bring a lot of overhead TyKind::BareFn(ref bare) if bare.abi == Abi::Rust => (50 * self.nest, 1), - TyKind::TraitObject(ref param_bounds, _) => { + TyKind::TraitObject(ref param_bounds, ..) => { let has_lifetime_parameters = param_bounds.iter().any(|bound| { bound .bound_generic_params diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index af82f992d56f..7f7d9c5f56a1 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -892,7 +892,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { TyKind::OpaqueDef(_, arg_list) => { self.hash_generic_args(arg_list); }, - TyKind::TraitObject(_, lifetime) => { + TyKind::TraitObject(_, lifetime, _) => { self.hash_lifetime(lifetime); }, TyKind::Typeof(anon_const) => { From 9f4a3bc50635fe237e6dae9a72dcc62e9b56cabf Mon Sep 17 00:00:00 2001 From: mark Date: Sat, 21 Nov 2020 15:22:32 -0600 Subject: [PATCH 0225/1222] clippy: stabilize or_patterns lint --- clippy_lints/src/lib.rs | 2 +- clippy_lints/src/unnested_or_patterns.rs | 5 ---- clippy_utils/src/lib.rs | 2 +- tests/ui/unnested_or_patterns.fixed | 1 - tests/ui/unnested_or_patterns.rs | 1 - tests/ui/unnested_or_patterns.stderr | 32 ++++++++++++------------ tests/ui/unnested_or_patterns2.fixed | 1 - tests/ui/unnested_or_patterns2.rs | 1 - tests/ui/unnested_or_patterns2.stderr | 16 ++++++------ tests/ui/unnested_or_patterns3.rs | 6 ----- tests/ui/while_let_on_iterator.fixed | 1 - tests/ui/while_let_on_iterator.rs | 1 - tests/ui/while_let_on_iterator.stderr | 14 +++++------ 13 files changed, 33 insertions(+), 50 deletions(-) delete mode 100644 tests/ui/unnested_or_patterns3.rs diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 04e151df8e85..b4c450bda5c7 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -5,7 +5,7 @@ #![feature(drain_filter)] #![feature(in_band_lifetimes)] #![feature(once_cell)] -#![feature(or_patterns)] +#![cfg_attr(bootstrap, feature(or_patterns))] #![feature(rustc_private)] #![feature(stmt_expr_attributes)] #![feature(control_flow_enum)] diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index fa613bb7da30..5826e9a4aa5b 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -72,11 +72,6 @@ impl EarlyLintPass for UnnestedOrPatterns { } fn lint_unnested_or_patterns(cx: &EarlyContext<'_>, pat: &Pat) { - if !cx.sess.features_untracked().or_patterns { - // Do not suggest nesting the patterns if the feature `or_patterns` is not enabled. - return; - } - if let Ident(.., None) | Lit(_) | Wild | Path(..) | Range(..) | Rest | MacCall(_) = pat.kind { // This is a leaf pattern, so cloning is unprofitable. return; diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index d81b89dd001c..7d3584333af6 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1,6 +1,6 @@ #![feature(box_patterns)] #![feature(in_band_lifetimes)] -#![feature(or_patterns)] +#![cfg_attr(bootstrap, feature(or_patterns))] #![feature(rustc_private)] #![recursion_limit = "512"] #![allow(clippy::missing_errors_doc, clippy::missing_panics_doc, clippy::must_use_candidate)] diff --git a/tests/ui/unnested_or_patterns.fixed b/tests/ui/unnested_or_patterns.fixed index 13a036cd800b..46463a29e9b2 100644 --- a/tests/ui/unnested_or_patterns.fixed +++ b/tests/ui/unnested_or_patterns.fixed @@ -1,6 +1,5 @@ // run-rustfix -#![feature(or_patterns)] #![feature(box_patterns)] #![warn(clippy::unnested_or_patterns)] #![allow(clippy::cognitive_complexity, clippy::match_ref_pats, clippy::upper_case_acronyms)] diff --git a/tests/ui/unnested_or_patterns.rs b/tests/ui/unnested_or_patterns.rs index 4a10cc702c40..8ce0738bfc27 100644 --- a/tests/ui/unnested_or_patterns.rs +++ b/tests/ui/unnested_or_patterns.rs @@ -1,6 +1,5 @@ // run-rustfix -#![feature(or_patterns)] #![feature(box_patterns)] #![warn(clippy::unnested_or_patterns)] #![allow(clippy::cognitive_complexity, clippy::match_ref_pats, clippy::upper_case_acronyms)] diff --git a/tests/ui/unnested_or_patterns.stderr b/tests/ui/unnested_or_patterns.stderr index 1899dc657dfe..f7cb513c15c9 100644 --- a/tests/ui/unnested_or_patterns.stderr +++ b/tests/ui/unnested_or_patterns.stderr @@ -1,5 +1,5 @@ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:10:12 + --> $DIR/unnested_or_patterns.rs:9:12 | LL | if let box 0 | box 2 = Box::new(0) {} | ^^^^^^^^^^^^^ @@ -11,7 +11,7 @@ LL | if let box (0 | 2) = Box::new(0) {} | ^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:11:12 + --> $DIR/unnested_or_patterns.rs:10:12 | LL | if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} | ^^^^^^^^^^^^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:13:12 + --> $DIR/unnested_or_patterns.rs:12:12 | LL | if let &0 | C0 | &2 = &0 {} | ^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | if let &(0 | 2) | C0 = &0 {} | ^^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:14:12 + --> $DIR/unnested_or_patterns.rs:13:12 | LL | if let &mut 0 | &mut 2 = &mut 0 {} | ^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | if let &mut (0 | 2) = &mut 0 {} | ^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:15:12 + --> $DIR/unnested_or_patterns.rs:14:12 | LL | if let x @ 0 | x @ 2 = 0 {} | ^^^^^^^^^^^^^ @@ -55,7 +55,7 @@ LL | if let x @ (0 | 2) = 0 {} | ^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:16:12 + --> $DIR/unnested_or_patterns.rs:15:12 | LL | if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL | if let (0, 1 | 2 | 3) = (0, 0) {} | ^^^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:17:12 + --> $DIR/unnested_or_patterns.rs:16:12 | LL | if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -77,7 +77,7 @@ LL | if let (1 | 2 | 3, 0) = (0, 0) {} | ^^^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:18:12 + --> $DIR/unnested_or_patterns.rs:17:12 | LL | if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | if let (x, ..) | (x, 1 | 2) = (0, 1) {} | ^^^^^^^^^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:19:12 + --> $DIR/unnested_or_patterns.rs:18:12 | LL | if let [0] | [1] = [0] {} | ^^^^^^^^^ @@ -99,7 +99,7 @@ LL | if let [0 | 1] = [0] {} | ^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:20:12 + --> $DIR/unnested_or_patterns.rs:19:12 | LL | if let [x, 0] | [x, 1] = [0, 1] {} | ^^^^^^^^^^^^^^^ @@ -110,7 +110,7 @@ LL | if let [x, 0 | 1] = [0, 1] {} | ^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:21:12 + --> $DIR/unnested_or_patterns.rs:20:12 | LL | if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | if let [x, 0 | 1 | 2] = [0, 1] {} | ^^^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:22:12 + --> $DIR/unnested_or_patterns.rs:21:12 | LL | if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +132,7 @@ LL | if let [x, ..] | [x, 1 | 2] = [0, 1] {} | ^^^^^^^^^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:24:12 + --> $DIR/unnested_or_patterns.rs:23:12 | LL | if let TS(0, x) | TS(1, x) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^ @@ -143,7 +143,7 @@ LL | if let TS(0 | 1, x) = TS(0, 0) {} | ^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:25:12 + --> $DIR/unnested_or_patterns.rs:24:12 | LL | if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -154,7 +154,7 @@ LL | if let TS(1 | 2 | 3, 0) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:26:12 + --> $DIR/unnested_or_patterns.rs:25:12 | LL | if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -165,7 +165,7 @@ LL | if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:31:12 + --> $DIR/unnested_or_patterns.rs:30:12 | LL | if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnested_or_patterns2.fixed b/tests/ui/unnested_or_patterns2.fixed index 02a129c55a3f..d3539d798157 100644 --- a/tests/ui/unnested_or_patterns2.fixed +++ b/tests/ui/unnested_or_patterns2.fixed @@ -1,6 +1,5 @@ // run-rustfix -#![feature(or_patterns)] #![feature(box_patterns)] #![warn(clippy::unnested_or_patterns)] #![allow(clippy::cognitive_complexity, clippy::match_ref_pats)] diff --git a/tests/ui/unnested_or_patterns2.rs b/tests/ui/unnested_or_patterns2.rs index acf3158989dc..9cea5cdea699 100644 --- a/tests/ui/unnested_or_patterns2.rs +++ b/tests/ui/unnested_or_patterns2.rs @@ -1,6 +1,5 @@ // run-rustfix -#![feature(or_patterns)] #![feature(box_patterns)] #![warn(clippy::unnested_or_patterns)] #![allow(clippy::cognitive_complexity, clippy::match_ref_pats)] diff --git a/tests/ui/unnested_or_patterns2.stderr b/tests/ui/unnested_or_patterns2.stderr index 1847fd8e098c..9042c9c00b1a 100644 --- a/tests/ui/unnested_or_patterns2.stderr +++ b/tests/ui/unnested_or_patterns2.stderr @@ -1,5 +1,5 @@ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:10:12 + --> $DIR/unnested_or_patterns2.rs:9:12 | LL | if let Some(Some(0)) | Some(Some(1)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -11,7 +11,7 @@ LL | if let Some(Some(0 | 1)) = None {} | ^^^^^^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:11:12 + --> $DIR/unnested_or_patterns2.rs:10:12 | LL | if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | if let Some(Some(0 | 1 | 2)) = None {} | ^^^^^^^^^^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:12:12 + --> $DIR/unnested_or_patterns2.rs:11:12 | LL | if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:13:12 + --> $DIR/unnested_or_patterns2.rs:12:12 | LL | if let Some(Some(0) | Some(1 | 2)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | if let Some(Some(0 | 1 | 2)) = None {} | ^^^^^^^^^^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:14:12 + --> $DIR/unnested_or_patterns2.rs:13:12 | LL | if let ((0,),) | ((1,) | (2,),) = ((0,),) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -55,7 +55,7 @@ LL | if let ((0 | 1 | 2,),) = ((0,),) {} | ^^^^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:15:12 + --> $DIR/unnested_or_patterns2.rs:14:12 | LL | if let 0 | (1 | 2) = 0 {} | ^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL | if let 0 | 1 | 2 = 0 {} | ^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:16:12 + --> $DIR/unnested_or_patterns2.rs:15:12 | LL | if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -77,7 +77,7 @@ LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} | ^^^^^^^^^^^^^^^^^^^^^^^ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:17:12 + --> $DIR/unnested_or_patterns2.rs:16:12 | LL | if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnested_or_patterns3.rs b/tests/ui/unnested_or_patterns3.rs deleted file mode 100644 index 6bd35057bfad..000000000000 --- a/tests/ui/unnested_or_patterns3.rs +++ /dev/null @@ -1,6 +0,0 @@ -#![warn(clippy::unnested_or_patterns)] - -// Test that `unnested_or_patterns` does not trigger without enabling `or_patterns` -fn main() { - if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} -} diff --git a/tests/ui/while_let_on_iterator.fixed b/tests/ui/while_let_on_iterator.fixed index e99c98ac79f2..749393db124b 100644 --- a/tests/ui/while_let_on_iterator.fixed +++ b/tests/ui/while_let_on_iterator.fixed @@ -2,7 +2,6 @@ #![warn(clippy::while_let_on_iterator)] #![allow(clippy::never_loop, unreachable_code, unused_mut)] -#![feature(or_patterns)] fn base() { let mut iter = 1..20; diff --git a/tests/ui/while_let_on_iterator.rs b/tests/ui/while_let_on_iterator.rs index ba13172428e1..30e3b82a7ccd 100644 --- a/tests/ui/while_let_on_iterator.rs +++ b/tests/ui/while_let_on_iterator.rs @@ -2,7 +2,6 @@ #![warn(clippy::while_let_on_iterator)] #![allow(clippy::never_loop, unreachable_code, unused_mut)] -#![feature(or_patterns)] fn base() { let mut iter = 1..20; diff --git a/tests/ui/while_let_on_iterator.stderr b/tests/ui/while_let_on_iterator.stderr index aa980d9965c7..6554977c798b 100644 --- a/tests/ui/while_let_on_iterator.stderr +++ b/tests/ui/while_let_on_iterator.stderr @@ -1,5 +1,5 @@ error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:9:5 + --> $DIR/while_let_on_iterator.rs:8:5 | LL | while let Option::Some(x) = iter.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter` @@ -7,37 +7,37 @@ LL | while let Option::Some(x) = iter.next() { = note: `-D clippy::while-let-on-iterator` implied by `-D warnings` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:14:5 + --> $DIR/while_let_on_iterator.rs:13:5 | LL | while let Some(x) = iter.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:19:5 + --> $DIR/while_let_on_iterator.rs:18:5 | LL | while let Some(_) = iter.next() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in iter` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:102:9 + --> $DIR/while_let_on_iterator.rs:101:9 | LL | while let Some([..]) = it.next() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for [..] in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:109:9 + --> $DIR/while_let_on_iterator.rs:108:9 | LL | while let Some([_x]) = it.next() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for [_x] in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:122:9 + --> $DIR/while_let_on_iterator.rs:121:9 | LL | while let Some(x @ [_]) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x @ [_] in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:154:9 + --> $DIR/while_let_on_iterator.rs:153:9 | LL | while let Some(_) = y.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in y` From ca848e0d446f833e634dcde5aa4282b56887a554 Mon Sep 17 00:00:00 2001 From: lcnr Date: Sat, 13 Mar 2021 16:31:38 +0100 Subject: [PATCH 0226/1222] update `const_eval_resolve` --- clippy_lints/src/non_copy_const.rs | 10 +++++++++- clippy_utils/src/consts.rs | 8 +++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 8aebce67917a..3e1db233696f 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -181,7 +181,15 @@ fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: D let result = cx .tcx - .const_eval_resolve(cx.param_env, ty::WithOptConstParam::unknown(def_id), substs, None, None); + .const_eval_resolve( + cx.param_env, + ty::Unevaluated { + def: ty::WithOptConstParam::unknown(def_id), + substs, + promoted: None + }, + None + ); is_value_unfrozen_raw(cx, result, ty) } diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 802c01055a68..ebe896b7ae86 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -341,9 +341,11 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { .tcx .const_eval_resolve( self.param_env, - ty::WithOptConstParam::unknown(def_id), - substs, - None, + ty::Unevaluated { + def: ty::WithOptConstParam::unknown(def_id), + substs, + promoted: None, + }, None, ) .ok() From 538de2b5f9312f00dc2bfd76e7d9da8f2395e8c8 Mon Sep 17 00:00:00 2001 From: kadmin Date: Tue, 11 Aug 2020 00:02:45 +0000 Subject: [PATCH 0227/1222] Add has_default to GenericParamDefKind::Const This currently creates a field which is always false on GenericParamDefKind for future use when consts are permitted to have defaults Update const_generics:default locations Previously just ignored them, now actually do something about them. Fix using type check instead of value Add parsing This adds all the necessary changes to lower const-generics defaults from parsing. Change P to AnonConst This matches the arguments passed to instantiations of const generics, and makes it specific to just anonymous constants. Attempt to fix lowering bugs --- clippy_utils/src/ast_utils.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index ea9a910d1b92..e202b5061a67 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -408,6 +408,10 @@ pub fn eq_use_tree(l: &UseTree, r: &UseTree) -> bool { eq_path(&l.prefix, &r.prefix) && eq_use_tree_kind(&l.kind, &r.kind) } +pub fn eq_anon_const(l: &AnonConst, r: &AnonConst) -> bool { + eq_expr(&l.value, &r.value) +} + pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool { use UseTreeKind::*; match (l, r) { @@ -418,10 +422,6 @@ pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool { } } -pub fn eq_anon_const(l: &AnonConst, r: &AnonConst) -> bool { - eq_expr(&l.value, &r.value) -} - pub fn eq_defaultness(l: Defaultness, r: Defaultness) -> bool { matches!( (l, r), From d55264858acd4cbeb8f4d8e4b03a6e9ce2ce2488 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 8 Mar 2021 15:57:44 -0800 Subject: [PATCH 0228/1222] Use iter::zip in src/tools/clippy/ --- clippy_lints/src/default_numeric_fallback.rs | 5 +-- clippy_lints/src/lib.rs | 1 + clippy_lints/src/literal_representation.rs | 3 +- clippy_lints/src/loops/needless_range_loop.rs | 4 +-- clippy_lints/src/matches.rs | 3 +- clippy_lints/src/mut_key.rs | 3 +- clippy_lints/src/mut_reference.rs | 3 +- clippy_lints/src/pass_by_ref_or_value.rs | 3 +- clippy_lints/src/pattern_type_mismatch.rs | 3 +- clippy_lints/src/unnecessary_sort_by.rs | 31 ++++++++----------- clippy_utils/src/consts.rs | 13 ++++---- clippy_utils/src/lib.rs | 1 + clippy_utils/src/numeric_literal.rs | 3 +- 13 files changed, 41 insertions(+), 35 deletions(-) diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index d136db9373c2..73f71d88b052 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -13,6 +13,7 @@ use rustc_middle::{ ty::{self, FloatTy, IntTy, PolyFnSig, Ty}, }; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use std::iter; declare_clippy_lint! { /// **What it does:** Checks for usage of unconstrained numeric literals which may cause default numeric fallback in type @@ -107,7 +108,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { match &expr.kind { ExprKind::Call(func, args) => { if let Some(fn_sig) = fn_sig_opt(self.cx, func.hir_id) { - for (expr, bound) in args.iter().zip(fn_sig.skip_binder().inputs().iter()) { + for (expr, bound) in iter::zip(*args, fn_sig.skip_binder().inputs()) { // Push found arg type, then visit arg. self.ty_bounds.push(TyBound::Ty(bound)); self.visit_expr(expr); @@ -120,7 +121,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { ExprKind::MethodCall(_, _, args, _) => { if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) { let fn_sig = self.cx.tcx.fn_sig(def_id).skip_binder(); - for (expr, bound) in args.iter().zip(fn_sig.inputs().iter()) { + for (expr, bound) in iter::zip(*args, fn_sig.inputs()) { self.ty_bounds.push(TyBound::Ty(bound)); self.visit_expr(expr); self.ty_bounds.pop(); diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 1c3841f8efd6..a99ed7656bfb 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -4,6 +4,7 @@ #![feature(box_syntax)] #![feature(drain_filter)] #![feature(in_band_lifetimes)] +#![feature(iter_zip)] #![feature(once_cell)] #![cfg_attr(bootstrap, feature(or_patterns))] #![feature(rustc_private)] diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index 7fd55151226b..544705192606 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -13,6 +13,7 @@ use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_tool_lint, impl_lint_pass}; +use std::iter; declare_clippy_lint! { /// **What it does:** Warns if a long integral or floating-point constant does @@ -349,7 +350,7 @@ impl LiteralDigitGrouping { let group_sizes: Vec = num_lit.integer.split('_').map(str::len).collect(); if UUID_GROUP_LENS.len() == group_sizes.len() { - UUID_GROUP_LENS.iter().zip(&group_sizes).all(|(&a, &b)| a == b) + iter::zip(&UUID_GROUP_LENS, &group_sizes).all(|(&a, &b)| a == b) } else { false } diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 3c40d54cb421..64ab3b6bfec0 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -17,7 +17,7 @@ use rustc_middle::hir::map::Map; use rustc_middle::middle::region; use rustc_middle::ty::{self, Ty}; use rustc_span::symbol::{sym, Symbol}; -use std::iter::Iterator; +use std::iter::{self, Iterator}; use std::mem; /// Checks for looping over a range and then indexing a sequence with it. @@ -369,7 +369,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { }, ExprKind::MethodCall(_, _, args, _) => { let def_id = self.cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap(); - for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) { + for (ty, expr) in iter::zip(self.cx.tcx.fn_sig(def_id).inputs().skip_binder(), args) { self.prefer_mutable = false; if let ty::Ref(_, _, mutbl) = *ty.kind() { if mutbl == Mutability::Mut { diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 3680429fed7d..2f2dc4cfc6b0 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -29,6 +29,7 @@ use rustc_span::source_map::{Span, Spanned}; use rustc_span::sym; use std::cmp::Ordering; use std::collections::hash_map::Entry; +use std::iter; use std::ops::Bound; declare_clippy_lint! { @@ -1668,7 +1669,7 @@ where values.sort(); - for (a, b) in values.iter().zip(values.iter().skip(1)) { + for (a, b) in iter::zip(&values, &values[1..]) { match (a, b) { (&Kind::Start(_, ra), &Kind::End(_, rb)) => { if ra.node != rb.node { diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 41bd07bcf1ea..4d3dff36a206 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -6,6 +6,7 @@ use rustc_middle::ty::TypeFoldable; use rustc_middle::ty::{Adt, Array, RawPtr, Ref, Slice, Tuple, Ty, TypeAndMut}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; +use std::iter; declare_clippy_lint! { /// **What it does:** Checks for sets/maps with mutable key types. @@ -87,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType { fn check_sig<'tcx>(cx: &LateContext<'tcx>, item_hir_id: hir::HirId, decl: &hir::FnDecl<'_>) { let fn_def_id = cx.tcx.hir().local_def_id(item_hir_id); let fn_sig = cx.tcx.fn_sig(fn_def_id); - for (hir_ty, ty) in decl.inputs.iter().zip(fn_sig.inputs().skip_binder().iter()) { + for (hir_ty, ty) in iter::zip(decl.inputs, fn_sig.inputs().skip_binder()) { check_ty(cx, hir_ty.span, ty); } check_ty(cx, decl.output.span(), cx.tcx.erase_late_bound_regions(fn_sig.output())); diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 0c09ddb80733..05457e80d52c 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -4,6 +4,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::subst::Subst; use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use std::iter; declare_clippy_lint! { /// **What it does:** Detects passing a mutable reference to a function that only @@ -64,7 +65,7 @@ fn check_arguments<'tcx>( match type_definition.kind() { ty::FnDef(..) | ty::FnPtr(_) => { let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs(); - for (argument, parameter) in arguments.iter().zip(parameters.iter()) { + for (argument, parameter) in iter::zip(arguments, parameters) { match parameter.kind() { ty::Ref(_, _, Mutability::Not) | ty::RawPtr(ty::TypeAndMut { diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 9a5b1c3b9442..e151f85a3913 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -1,4 +1,5 @@ use std::cmp; +use std::iter; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::is_self_ty; @@ -122,7 +123,7 @@ impl<'tcx> PassByRefOrValue { let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir().body(id)); - for (index, (input, &ty)) in decl.inputs.iter().zip(fn_sig.inputs()).enumerate() { + for (index, (input, &ty)) in iter::zip(decl.inputs, fn_sig.inputs()).enumerate() { // All spans generated from a proc-macro invocation are the same... match span { Some(s) if s == input.span => return, diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index 4550b367da4b..c0c2ab67e382 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -10,6 +10,7 @@ use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{AdtDef, FieldDef, Ty, TyKind, VariantDef}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; +use std::iter; declare_clippy_lint! { /// **What it does:** Checks for patterns that aren't exact representations of the types @@ -134,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch { hir_id: HirId, ) { if let Some(fn_sig) = cx.typeck_results().liberated_fn_sigs().get(hir_id) { - for (param, ty) in body.params.iter().zip(fn_sig.inputs().iter()) { + for (param, ty) in iter::zip(body.params, fn_sig.inputs()) { apply_lint(cx, ¶m.pat, ty, DerefPossible::Impossible); } } diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index e23bab5eba03..6becff9662a7 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -9,6 +9,7 @@ use rustc_middle::ty::{self, subst::GenericArgKind}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; use rustc_span::symbol::Ident; +use std::iter; declare_clippy_lint! { /// **What it does:** @@ -79,17 +80,15 @@ fn mirrored_exprs( mirrored_exprs(cx, left_expr, a_ident, right_expr, b_ident) }, // Two arrays with mirrored contents - (ExprKind::Array(left_exprs), ExprKind::Array(right_exprs)) => left_exprs - .iter() - .zip(right_exprs.iter()) - .all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident)), + (ExprKind::Array(left_exprs), ExprKind::Array(right_exprs)) => { + iter::zip(*left_exprs, *right_exprs) + .all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident)) + } // The two exprs are function calls. // Check to see that the function itself and its arguments are mirrored (ExprKind::Call(left_expr, left_args), ExprKind::Call(right_expr, right_args)) => { mirrored_exprs(cx, left_expr, a_ident, right_expr, b_ident) - && left_args - .iter() - .zip(right_args.iter()) + && iter::zip(*left_args, *right_args) .all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident)) }, // The two exprs are method calls. @@ -100,16 +99,14 @@ fn mirrored_exprs( ExprKind::MethodCall(right_segment, _, right_args, _), ) => { left_segment.ident == right_segment.ident - && left_args - .iter() - .zip(right_args.iter()) + && iter::zip(*left_args, *right_args) .all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident)) - }, + } // Two tuples with mirrored contents - (ExprKind::Tup(left_exprs), ExprKind::Tup(right_exprs)) => left_exprs - .iter() - .zip(right_exprs.iter()) - .all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident)), + (ExprKind::Tup(left_exprs), ExprKind::Tup(right_exprs)) => { + iter::zip(*left_exprs, *right_exprs) + .all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident)) + } // Two binary ops, which are the same operation and which have mirrored arguments (ExprKind::Binary(left_op, left_left, left_right), ExprKind::Binary(right_op, right_left, right_right)) => { left_op.node == right_op.node @@ -146,9 +143,7 @@ fn mirrored_exprs( }, )), ) => { - (left_segments - .iter() - .zip(right_segments.iter()) + (iter::zip(*left_segments, *right_segments) .all(|(left, right)| left.ident == right.ident) && left_segments .iter() diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index ebe896b7ae86..8af10ebe777e 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -15,6 +15,7 @@ use rustc_span::symbol::Symbol; use std::cmp::Ordering::{self, Equal}; use std::convert::TryInto; use std::hash::{Hash, Hasher}; +use std::iter; /// A `LitKind`-like enum to fold constant `Expr`s into. #[derive(Debug, Clone)] @@ -139,12 +140,12 @@ impl Constant { (&Self::F64(l), &Self::F64(r)) => l.partial_cmp(&r), (&Self::F32(l), &Self::F32(r)) => l.partial_cmp(&r), (&Self::Bool(ref l), &Self::Bool(ref r)) => Some(l.cmp(r)), - (&Self::Tuple(ref l), &Self::Tuple(ref r)) | (&Self::Vec(ref l), &Self::Vec(ref r)) => l - .iter() - .zip(r.iter()) - .map(|(li, ri)| Self::partial_cmp(tcx, cmp_type, li, ri)) - .find(|r| r.map_or(true, |o| o != Ordering::Equal)) - .unwrap_or_else(|| Some(l.len().cmp(&r.len()))), + (&Self::Tuple(ref l), &Self::Tuple(ref r)) | (&Self::Vec(ref l), &Self::Vec(ref r)) => { + iter::zip(l, r) + .map(|(li, ri)| Self::partial_cmp(tcx, cmp_type, li, ri)) + .find(|r| r.map_or(true, |o| o != Ordering::Equal)) + .unwrap_or_else(|| Some(l.len().cmp(&r.len()))) + } (&Self::Repeat(ref lv, ref ls), &Self::Repeat(ref rv, ref rs)) => { match Self::partial_cmp(tcx, cmp_type, lv, rv) { Some(Equal) => Some(ls.cmp(rs)), diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index b613ae9b9180..b2655f8d797b 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1,5 +1,6 @@ #![feature(box_patterns)] #![feature(in_band_lifetimes)] +#![feature(iter_zip)] #![cfg_attr(bootstrap, feature(or_patterns))] #![feature(rustc_private)] #![recursion_limit = "512"] diff --git a/clippy_utils/src/numeric_literal.rs b/clippy_utils/src/numeric_literal.rs index d02603d7702c..268bc5b32053 100644 --- a/clippy_utils/src/numeric_literal.rs +++ b/clippy_utils/src/numeric_literal.rs @@ -1,4 +1,5 @@ use rustc_ast::ast::{Lit, LitFloatType, LitIntType, LitKind}; +use std::iter; #[derive(Debug, PartialEq, Copy, Clone)] pub enum Radix { @@ -192,7 +193,7 @@ impl<'a> NumericLiteral<'a> { } } - for (c, i) in digits.zip((0..group_size).cycle()) { + for (c, i) in iter::zip(digits, (0..group_size).cycle()) { if i == 0 { output.push('_'); } From 4afceffcc4ff59369ea0b93d4350d95531835f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Sun, 21 Mar 2021 17:29:21 +0300 Subject: [PATCH 0229/1222] format macro argument parsing fix When the character next to `{}` is "shifted" (when mapping a byte index in the format string to span) we should avoid shifting the span end index, so first map the index of `}` to span, then bump the span, instead of first mapping the next byte index to a span (which causes bumping the end span too much). Regression test added. Fixes #83344 --- tests/ui/write_literal_2.stderr | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/ui/write_literal_2.stderr b/tests/ui/write_literal_2.stderr index 5b4883580111..0aa1b55e58c5 100644 --- a/tests/ui/write_literal_2.stderr +++ b/tests/ui/write_literal_2.stderr @@ -75,8 +75,9 @@ LL | "1", "2", "3", | help: try this | -LL | "some 1{} / {}", "2", "3", - | ^ -- +LL | "some 1/ +LL | {} / {}", "2", "3", + | error: literal with an empty format string --> $DIR/write_literal_2.rs:25:14 From 40fc0bbab76be0edd8ca953f360d30b0229b24e1 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 16 Mar 2021 01:50:34 -0400 Subject: [PATCH 0230/1222] Remove (lots of) dead code Found with https://github.com/est31/warnalyzer. Dubious changes: - Is anyone else using rustc_apfloat? I feel weird completely deleting x87 support. - Maybe some of the dead code in rustc_data_structures, in case someone wants to use it in the future? - Don't change rustc_serialize I plan to scrap most of the json module in the near future (see https://github.com/rust-lang/compiler-team/issues/418) and fixing the tests needed more work than I expected. TODO: check if any of the comments on the deleted code should be kept. --- clippy_lints/src/functions.rs | 2 +- clippy_lints/src/missing_doc.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 730492fc7e3e..5fe46065348f 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -516,7 +516,7 @@ fn check_needless_must_use( ); }, ); - } else if !attr.is_value_str() && is_must_use_ty(cx, return_ty(cx, item_id)) { + } else if !attr.value_str().is_some() && is_must_use_ty(cx, return_ty(cx, item_id)) { span_lint_and_help( cx, DOUBLE_MUST_USE, diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index ff87828c2e77..5741aad261bb 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -95,7 +95,7 @@ impl MissingDoc { let has_doc = attrs .iter() - .any(|a| a.is_doc_comment() || a.doc_str().is_some() || a.is_value_str() || Self::has_include(a.meta())); + .any(|a| a.is_doc_comment() || a.doc_str().is_some() || a.value_str().is_some() || Self::has_include(a.meta())); if !has_doc { span_lint( cx, From 7cb88beb8c8ac9206351bc246e5427e514687c5a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 30 Mar 2021 20:31:06 +0200 Subject: [PATCH 0231/1222] Remove hir::CrateItem. --- clippy_lints/src/missing_doc.rs | 2 +- clippy_utils/src/lib.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 5741aad261bb..21b4983a1af0 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -128,7 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) { let attrs = cx.tcx.hir().attrs(hir::CRATE_HIR_ID); - self.check_missing_docs_attrs(cx, attrs, krate.item.span, "the", "crate"); + self.check_missing_docs_attrs(cx, attrs, krate.item.inner, "the", "crate"); } fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index b2655f8d797b..6b235875c203 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -61,10 +61,10 @@ use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::{ - def, Arm, BindingAnnotation, Block, Body, Constness, CrateItem, Expr, ExprKind, FieldDef, FnDecl, ForeignItem, - GenericArgs, GenericParam, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, LangItem, Lifetime, Local, - MacroDef, MatchSource, Node, Param, Pat, PatKind, Path, PathSegment, QPath, Stmt, TraitItem, TraitItemKind, - TraitRef, TyKind, Variant, Visibility, + def, Arm, BindingAnnotation, Block, Body, Constness, Expr, ExprKind, FieldDef, FnDecl, ForeignItem, GenericArgs, + GenericParam, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, LangItem, Lifetime, Local, MacroDef, + MatchSource, Mod, Node, Param, Pat, PatKind, Path, PathSegment, QPath, Stmt, TraitItem, TraitItemKind, TraitRef, + TyKind, Variant, Visibility, }; use rustc_lint::{LateContext, Level, Lint, LintContext}; use rustc_middle::hir::exports::Export; @@ -743,7 +743,7 @@ pub fn get_node_span(node: Node<'_>) -> Option { | Node::Lifetime(Lifetime { span, .. }) | Node::GenericParam(GenericParam { span, .. }) | Node::Visibility(Visibility { span, .. }) - | Node::Crate(CrateItem { span, .. }) => Some(*span), + | Node::Crate(Mod { inner: span, .. }) => Some(*span), Node::Ctor(_) | Node::AnonConst(_) => None, } } From 504f89b83080c72fd9d55fb86bbf5416ef838475 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Mon, 5 Oct 2020 20:41:46 -0400 Subject: [PATCH 0232/1222] Track bound vars --- clippy_lints/src/unit_return_expecting_ord.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index bad3e488bb6d..4c13941f6659 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -44,7 +44,7 @@ fn get_trait_predicates_for_trait_id<'tcx>( for (pred, _) in generics.predicates { if_chain! { if let PredicateKind::Trait(poly_trait_pred, _) = pred.kind().skip_binder(); - let trait_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(poly_trait_pred)); + let trait_pred = cx.tcx.erase_late_bound_regions(pred.kind().rebind(poly_trait_pred)); if let Some(trait_def_id) = trait_id; if trait_def_id == trait_pred.trait_ref.def_id; then { @@ -58,12 +58,12 @@ fn get_trait_predicates_for_trait_id<'tcx>( fn get_projection_pred<'tcx>( cx: &LateContext<'tcx>, generics: GenericPredicates<'tcx>, - pred: TraitPredicate<'tcx>, + trait_pred: TraitPredicate<'tcx>, ) -> Option> { generics.predicates.iter().find_map(|(proj_pred, _)| { - if let ty::PredicateKind::Projection(proj_pred) = proj_pred.kind().skip_binder() { - let projection_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(proj_pred)); - if projection_pred.projection_ty.substs == pred.trait_ref.substs { + if let ty::PredicateKind::Projection(pred) = proj_pred.kind().skip_binder() { + let projection_pred = cx.tcx.erase_late_bound_regions(proj_pred.kind().rebind(pred)); + if projection_pred.projection_ty.substs == trait_pred.trait_ref.substs { return Some(projection_pred); } } From 707ab68a8b1de3ddd11ba88c508470f0d6b77d67 Mon Sep 17 00:00:00 2001 From: Roxane Date: Tue, 30 Mar 2021 00:30:20 -0400 Subject: [PATCH 0233/1222] fix clippy error --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 1391f7505e27..dac4d93499dc 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -212,7 +212,7 @@ fn check_statement(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, statemen check_rvalue(tcx, body, def_id, rval, span) } - StatementKind::FakeRead(_, place) | + StatementKind::FakeRead(box (_, place)) => check_place(tcx, *place, span, body), // just an assignment StatementKind::SetDiscriminant { place, .. } => check_place(tcx, **place, span, body), From 39e338504b7b9987f95ea29e83463d633ed0f55d Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 3 Apr 2021 20:20:18 +0300 Subject: [PATCH 0234/1222] Remove attribute `#[link_args]` --- tests/ui/crate_level_checks/no_std_main_recursion.rs | 4 ++-- tests/ui/empty_loop_no_std.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ui/crate_level_checks/no_std_main_recursion.rs b/tests/ui/crate_level_checks/no_std_main_recursion.rs index 25b1417be976..be4348e2bb71 100644 --- a/tests/ui/crate_level_checks/no_std_main_recursion.rs +++ b/tests/ui/crate_level_checks/no_std_main_recursion.rs @@ -1,8 +1,8 @@ +// compile-flags: -Clink-arg=-nostartfiles // ignore-macos // ignore-windows -#![feature(lang_items, link_args, start, libc)] -#![link_args = "-nostartfiles"] +#![feature(lang_items, start, libc)] #![no_std] use core::panic::PanicInfo; diff --git a/tests/ui/empty_loop_no_std.rs b/tests/ui/empty_loop_no_std.rs index 4553d3ec505a..235e0fc51799 100644 --- a/tests/ui/empty_loop_no_std.rs +++ b/tests/ui/empty_loop_no_std.rs @@ -1,9 +1,9 @@ +// compile-flags: -Clink-arg=-nostartfiles // ignore-macos // ignore-windows #![warn(clippy::empty_loop)] -#![feature(lang_items, link_args, start, libc)] -#![link_args = "-nostartfiles"] +#![feature(lang_items, start, libc)] #![no_std] use core::panic::PanicInfo; From 16a71c56d8d89e61be55d5c32f3f29b11d8e3d36 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Tue, 6 Apr 2021 05:50:55 +0100 Subject: [PATCH 0235/1222] Use AnonConst for asm! constants --- clippy_lints/src/loops/never_loop.rs | 2 +- clippy_lints/src/utils/inspector.rs | 5 ++++- clippy_utils/src/hir_utils.rs | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index f63a3761a0d1..01a7627fc7f3 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -142,12 +142,12 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { .map(|(o, _)| match o { InlineAsmOperand::In { expr, .. } | InlineAsmOperand::InOut { expr, .. } - | InlineAsmOperand::Const { expr } | InlineAsmOperand::Sym { expr } => never_loop_expr(expr, main_loop_id), InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter(), main_loop_id), InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { never_loop_expr_all(&mut once(in_expr).chain(out_expr.iter()), main_loop_id) }, + InlineAsmOperand::Const { .. } => NeverLoopResult::Otherwise, }) .fold(NeverLoopResult::Otherwise, combine_both), ExprKind::Struct(_, _, None) diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 6fd3c9d7dec2..b3fe66ed4285 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -306,7 +306,6 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { match op { hir::InlineAsmOperand::In { expr, .. } | hir::InlineAsmOperand::InOut { expr, .. } - | hir::InlineAsmOperand::Const { expr } | hir::InlineAsmOperand::Sym { expr } => print_expr(cx, expr, indent + 1), hir::InlineAsmOperand::Out { expr, .. } => { if let Some(expr) = expr { @@ -319,6 +318,10 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { print_expr(cx, out_expr, indent + 1); } }, + hir::InlineAsmOperand::Const { anon_const } => { + println!("{}anon_const:", ind); + print_expr(cx, &cx.tcx.hir().body(anon_const.body).value, indent + 1); + } } } }, diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 618d33545a4e..b30c0b798819 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -663,7 +663,8 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_expr(out_expr); } }, - InlineAsmOperand::Const { expr } | InlineAsmOperand::Sym { expr } => self.hash_expr(expr), + InlineAsmOperand::Const { anon_const } => self.hash_body(anon_const.body), + InlineAsmOperand::Sym { expr } => self.hash_expr(expr), } } }, From 9fb658c8b1ea4593bbf691322541b07207a70dfe Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Thu, 8 Apr 2021 21:37:38 +0800 Subject: [PATCH 0236/1222] Remove #[main] attribute. --- tests/ui/crate_level_checks/entrypoint_recursion.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/crate_level_checks/entrypoint_recursion.rs b/tests/ui/crate_level_checks/entrypoint_recursion.rs index 995787c53366..7ff5a16ed86c 100644 --- a/tests/ui/crate_level_checks/entrypoint_recursion.rs +++ b/tests/ui/crate_level_checks/entrypoint_recursion.rs @@ -1,11 +1,11 @@ // ignore-macos // ignore-windows -#![feature(main)] +#![feature(rustc_attrs)] #[warn(clippy::main_recursion)] #[allow(unconditional_recursion)] -#[main] +#[rustc_main] fn a() { println!("Hello, World!"); a(); From a49e951f05b1dc67f405e96b6f1c79b859b0da87 Mon Sep 17 00:00:00 2001 From: hyd-dev Date: Sun, 11 Apr 2021 01:08:31 +0800 Subject: [PATCH 0237/1222] Do not ignore path segments in the middle in `#[allow]`/`#[warn]`/`#[deny]`/`#[forbid]` attributes --- tests/ui/filter_methods.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/filter_methods.rs b/tests/ui/filter_methods.rs index 514502416192..96121b114ce6 100644 --- a/tests/ui/filter_methods.rs +++ b/tests/ui/filter_methods.rs @@ -1,5 +1,5 @@ #![warn(clippy::all, clippy::pedantic)] -#![allow(clippy::clippy::let_underscore_drop)] +#![allow(clippy::let_underscore_drop)] #![allow(clippy::missing_docs_in_private_items)] fn main() { From 55c0a3391a0023ee71e7ef7c8a3a53b3e9471a9e Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Mon, 29 Mar 2021 12:35:16 +0200 Subject: [PATCH 0238/1222] Fix clippy test using `ErrorKind` --- tests/ui/wildcard_enum_match_arm.fixed | 3 ++- tests/ui/wildcard_enum_match_arm.rs | 1 + tests/ui/wildcard_enum_match_arm.stderr | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/ui/wildcard_enum_match_arm.fixed b/tests/ui/wildcard_enum_match_arm.fixed index fd754e4c794f..129d82652d75 100644 --- a/tests/ui/wildcard_enum_match_arm.fixed +++ b/tests/ui/wildcard_enum_match_arm.fixed @@ -77,7 +77,7 @@ fn main() { let error_kind = ErrorKind::NotFound; match error_kind { ErrorKind::NotFound => {}, - ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | _ => {}, + ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | ErrorKind::Unsupported | _ => {}, } match error_kind { ErrorKind::NotFound => {}, @@ -98,6 +98,7 @@ fn main() { ErrorKind::Interrupted => {}, ErrorKind::Other => {}, ErrorKind::UnexpectedEof => {}, + ErrorKind::Unsupported => {}, _ => {}, } } diff --git a/tests/ui/wildcard_enum_match_arm.rs b/tests/ui/wildcard_enum_match_arm.rs index 2dbf726d5d07..028ecb63e7e6 100644 --- a/tests/ui/wildcard_enum_match_arm.rs +++ b/tests/ui/wildcard_enum_match_arm.rs @@ -98,6 +98,7 @@ fn main() { ErrorKind::Interrupted => {}, ErrorKind::Other => {}, ErrorKind::UnexpectedEof => {}, + ErrorKind::Unsupported => {}, _ => {}, } } diff --git a/tests/ui/wildcard_enum_match_arm.stderr b/tests/ui/wildcard_enum_match_arm.stderr index a513a62c748d..fd45cad00d6b 100644 --- a/tests/ui/wildcard_enum_match_arm.stderr +++ b/tests/ui/wildcard_enum_match_arm.stderr @@ -32,7 +32,7 @@ error: wildcard matches known variants and will also match future added variants --> $DIR/wildcard_enum_match_arm.rs:80:9 | LL | _ => {}, - | ^ help: try this: `ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | _` + | ^ help: try this: `ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | ErrorKind::Unsupported | _` error: aborting due to 5 previous errors From 9229e8b9affc70ac88ae04d9e143a815355117b6 Mon Sep 17 00:00:00 2001 From: lcnr Date: Sun, 18 Apr 2021 19:35:23 +0200 Subject: [PATCH 0239/1222] fix suggestion for unsized function parameters --- tests/ui/crashes/ice-6251.stderr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/crashes/ice-6251.stderr b/tests/ui/crashes/ice-6251.stderr index 9a7cf4b0919f..8498c0407808 100644 --- a/tests/ui/crashes/ice-6251.stderr +++ b/tests/ui/crashes/ice-6251.stderr @@ -16,8 +16,8 @@ LL | fn bug() -> impl Iterator { = help: unsized fn params are gated as an unstable feature help: function arguments must have a statically known size, borrowed types always have a known size | -LL | fn bug() -> impl Iterator { - | ^ +LL | fn bug() -> impl Iterator { + | ^ error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/ice-6251.rs:4:54 From 08bea9689e455df3bc644dda2dfa9c4f7216d2b6 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 25 Apr 2021 17:05:48 +0200 Subject: [PATCH 0240/1222] fix clippy --- clippy_lints/src/missing_const_for_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 93b7a897405a..60425ff853b7 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -139,7 +139,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { let mir = cx.tcx.optimized_mir(def_id); if let Err((span, err)) = is_min_const_fn(cx.tcx, mir, self.msrv.as_ref()) { - if rustc_mir::const_eval::is_min_const_fn(cx.tcx, def_id.to_def_id()) { + if cx.tcx.is_const_fn_raw(def_id.to_def_id()) { cx.tcx.sess.span_err(span, &err); } } else { From 8ee76d9308082bb209992460ca6b42d1c66e2341 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 14 Apr 2021 09:20:49 -0400 Subject: [PATCH 0241/1222] Implement `x.py test src/tools/clippy --bless` - Add clippy_dev to the rust workspace Before, it would give an error that it wasn't either included or excluded from the workspace: ``` error: current package believes it's in a workspace when it's not: current: /home/joshua/rustc/src/tools/clippy/clippy_dev/Cargo.toml workspace: /home/joshua/rustc/Cargo.toml this may be fixable by adding `src/tools/clippy/clippy_dev` to the `workspace.members` array of the manifest located at: /home/joshua/rustc/Cargo.toml Alternatively, to keep it out of the workspace, add the package to the `workspace.exclude` array, or add an empty `[workspace]` table to the package's manifest. ``` - Change clippy's copy of compiletest not to special-case rust-lang/rust. Using OUT_DIR confused `clippy_dev` and it couldn't find the test outputs. This is one of the reasons why `cargo dev bless` used to silently do nothing (the others were that `CARGO_TARGET_DIR` and `PROFILE` weren't set appropriately). - Run clippy_dev on test failure I tested this by removing a couple lines from a stderr file, and they were correctly replaced. - Fix clippy_dev warnings --- clippy_dev/src/new_lint.rs | 4 ++-- tests/compile-test.rs | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/clippy_dev/src/new_lint.rs b/clippy_dev/src/new_lint.rs index d951ca0e6308..4676c2affad7 100644 --- a/clippy_dev/src/new_lint.rs +++ b/clippy_dev/src/new_lint.rs @@ -44,7 +44,7 @@ pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str create_test(&lint).context("Unable to create a test for the new lint") } -fn create_lint(lint: &LintData) -> io::Result<()> { +fn create_lint(lint: &LintData<'_>) -> io::Result<()> { let (pass_type, pass_lifetimes, pass_import, context_import) = match lint.pass { "early" => ("EarlyLintPass", "", "use rustc_ast::ast::*;", "EarlyContext"), "late" => ("LateLintPass", "<'_>", "use rustc_hir::*;", "LateContext"), @@ -68,7 +68,7 @@ fn create_lint(lint: &LintData) -> io::Result<()> { write_file(lint.project_root.join(&lint_path), lint_contents.as_bytes()) } -fn create_test(lint: &LintData) -> io::Result<()> { +fn create_test(lint: &LintData<'_>) -> io::Result<()> { fn create_project_layout>(lint_name: &str, location: P, case: &str, hint: &str) -> io::Result<()> { let mut path = location.into().join(case); fs::create_dir(&path)?; diff --git a/tests/compile-test.rs b/tests/compile-test.rs index f4d354f0bf94..e1110721f6ec 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -83,14 +83,7 @@ fn default_config() -> compiletest::Config { third_party_crates(), )); - config.build_base = if cargo::is_rustc_test_suite() { - // This make the stderr files go to clippy OUT_DIR on rustc repo build dir - let mut path = PathBuf::from(env!("OUT_DIR")); - path.push("test_build_base"); - path - } else { - host_lib().join("test_build_base") - }; + config.build_base = host_lib().join("test_build_base"); config.rustc_path = clippy_driver_path(); config } From 182aa44b43912e5c1881eb9e0472f7239454c97c Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 27 Apr 2021 13:00:36 -0400 Subject: [PATCH 0242/1222] Switch `rustc::internal` from deny to warn These should still obey deny-warnings. --- clippy_lints/src/lib.rs | 2 +- src/driver.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 11fef30945d7..22e6bb822b8c 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -17,7 +17,7 @@ // warn on lints, that are included in `rust-lang/rust`s bootstrap #![warn(rust_2018_idioms, unused_lifetimes)] // warn on rustc internal lints -#![deny(rustc::internal)] +#![warn(rustc::internal)] // FIXME: switch to something more ergonomic here, once available. // (Currently there is no way to opt into sysroot crates without `extern crate`.) diff --git a/src/driver.rs b/src/driver.rs index fa0c5f01430b..750a23e8c984 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -4,7 +4,7 @@ // warn on lints, that are included in `rust-lang/rust`s bootstrap #![warn(rust_2018_idioms, unused_lifetimes)] // warn on rustc internal lints -#![deny(rustc::internal)] +#![warn(rustc::internal)] // FIXME: switch to something more ergonomic here, once available. // (Currently there is no way to opt into sysroot crates without `extern crate`.) From 02850cb7fcbe5d706603b43f3c25876146404723 Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Mon, 26 Apr 2021 01:09:35 +0800 Subject: [PATCH 0243/1222] Implement RFC 1260 with feature_name `imported_main`. --- clippy_utils/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index cd85c487798d..e81a92eb74ca 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -678,7 +678,7 @@ pub fn method_chain_args<'a>(expr: &'a Expr<'_>, methods: &[&str]) -> Option, def_id: DefId) -> bool { cx.tcx .entry_fn(LOCAL_CRATE) - .map_or(false, |(entry_fn_def_id, _)| def_id == entry_fn_def_id.to_def_id()) + .map_or(false, |(entry_fn_def_id, _)| def_id == entry_fn_def_id) } /// Returns `true` if the expression is in the program's `#[panic_handler]`. From ad075cc77b237c45cff61fadf0e409a172d7791b Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Thu, 29 Apr 2021 18:37:22 +0200 Subject: [PATCH 0244/1222] Fix clippy error --- tests/ui/crashes/ice-3969.stderr | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/ui/crashes/ice-3969.stderr b/tests/ui/crashes/ice-3969.stderr index 923db0664a71..fb4589a48ec4 100644 --- a/tests/ui/crashes/ice-3969.stderr +++ b/tests/ui/crashes/ice-3969.stderr @@ -5,18 +5,26 @@ LL | for<'a> Dst: Sized, | ^^^^^^ help: use `dyn`: `dyn A + 'a` | = note: `-D bare-trait-objects` implied by `-D warnings` + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition! + = note: for more information, see issue #80165 error: trait objects without an explicit `dyn` are deprecated --> $DIR/ice-3969.rs:27:16 | LL | let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); | ^ help: use `dyn`: `dyn A` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition! + = note: for more information, see issue #80165 error: trait objects without an explicit `dyn` are deprecated --> $DIR/ice-3969.rs:27:57 | LL | let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); | ^ help: use `dyn`: `dyn A` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition! + = note: for more information, see issue #80165 error: aborting due to 3 previous errors From e3431fb7504c2b9c6a4f4c8a06b57f1960f7b087 Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 30 Apr 2021 12:15:38 +0100 Subject: [PATCH 0245/1222] Add ErrorKind::OutOfMemory --- tests/ui/wildcard_enum_match_arm.fixed | 3 ++- tests/ui/wildcard_enum_match_arm.rs | 1 + tests/ui/wildcard_enum_match_arm.stderr | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/ui/wildcard_enum_match_arm.fixed b/tests/ui/wildcard_enum_match_arm.fixed index 129d82652d75..5ad27bb14501 100644 --- a/tests/ui/wildcard_enum_match_arm.fixed +++ b/tests/ui/wildcard_enum_match_arm.fixed @@ -77,7 +77,7 @@ fn main() { let error_kind = ErrorKind::NotFound; match error_kind { ErrorKind::NotFound => {}, - ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | ErrorKind::Unsupported | _ => {}, + ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | ErrorKind::Unsupported | ErrorKind::OutOfMemory | _ => {}, } match error_kind { ErrorKind::NotFound => {}, @@ -99,6 +99,7 @@ fn main() { ErrorKind::Other => {}, ErrorKind::UnexpectedEof => {}, ErrorKind::Unsupported => {}, + ErrorKind::OutOfMemory => {}, _ => {}, } } diff --git a/tests/ui/wildcard_enum_match_arm.rs b/tests/ui/wildcard_enum_match_arm.rs index 028ecb63e7e6..adca0738bba5 100644 --- a/tests/ui/wildcard_enum_match_arm.rs +++ b/tests/ui/wildcard_enum_match_arm.rs @@ -99,6 +99,7 @@ fn main() { ErrorKind::Other => {}, ErrorKind::UnexpectedEof => {}, ErrorKind::Unsupported => {}, + ErrorKind::OutOfMemory => {}, _ => {}, } } diff --git a/tests/ui/wildcard_enum_match_arm.stderr b/tests/ui/wildcard_enum_match_arm.stderr index fd45cad00d6b..73f6a4a80c96 100644 --- a/tests/ui/wildcard_enum_match_arm.stderr +++ b/tests/ui/wildcard_enum_match_arm.stderr @@ -32,7 +32,7 @@ error: wildcard matches known variants and will also match future added variants --> $DIR/wildcard_enum_match_arm.rs:80:9 | LL | _ => {}, - | ^ help: try this: `ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | ErrorKind::Unsupported | _` + | ^ help: try this: `ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | ErrorKind::Unsupported | ErrorKind::OutOfMemory | _` error: aborting due to 5 previous errors From 3b6f500a8979dc3d061f5d2cabd78a14e8091161 Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Sun, 25 Apr 2021 13:10:19 +0200 Subject: [PATCH 0246/1222] Change `std::sys::unix::ext::fs::PermissionsExt::from_mode` to `std::os::imp::unix::fs::PermissionsExt::from_mode` in Clippy --- clippy_utils/src/paths.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index 5e6733a300f2..1fa439639b24 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -101,7 +101,7 @@ pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 2] = ["parking_lot", "RwLockWri pub const PATH_BUF_AS_PATH: [&str; 4] = ["std", "path", "PathBuf", "as_path"]; pub const PATH_TO_PATH_BUF: [&str; 4] = ["std", "path", "Path", "to_path_buf"]; pub const PERMISSIONS: [&str; 3] = ["std", "fs", "Permissions"]; -pub const PERMISSIONS_FROM_MODE: [&str; 7] = ["std", "sys", "unix", "ext", "fs", "PermissionsExt", "from_mode"]; +pub const PERMISSIONS_FROM_MODE: [&str; 7] = ["std", "os", "imp", "unix", "fs", "PermissionsExt", "from_mode"]; pub const POLL: [&str; 4] = ["core", "task", "poll", "Poll"]; pub const POLL_PENDING: [&str; 5] = ["core", "task", "poll", "Poll", "Pending"]; pub const POLL_READY: [&str; 5] = ["core", "task", "poll", "Poll", "Ready"]; From 44527eee0dc4119b5be68c8badca76e108cf5f20 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Mon, 19 Apr 2021 23:27:02 +0100 Subject: [PATCH 0247/1222] Use local and remapped paths where appropriate --- clippy_lints/src/macro_use.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index ec03daff87b0..314bf11e2d66 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -47,7 +47,7 @@ pub struct MacroRefData { impl MacroRefData { pub fn new(name: String, callee: Span, cx: &LateContext<'_>) -> Self { - let mut path = cx.sess().source_map().span_to_filename(callee).to_string(); + let mut path = cx.sess().source_map().span_to_filename(callee).prefer_local().to_string(); // std lib paths are <::std::module::file type> // so remove brackets, space and type. @@ -96,8 +96,7 @@ impl MacroUseImports { let name = snippet(cx, cx.sess().source_map().span_until_char(call_site, '!'), "_"); if let Some(callee) = span.source_callee() { if !self.collected.contains(&call_site) { - self.mac_refs - .push(MacroRefData::new(name.to_string(), callee.def_site, cx)); + self.mac_refs.push(MacroRefData::new(name.to_string(), callee.def_site, cx)); self.collected.insert(call_site); } } @@ -175,7 +174,7 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports { .push((*item).to_string()); check_dup.push((*item).to_string()); } - }, + } [root, rest @ ..] => { if rest.iter().all(|item| !check_dup.contains(&(*item).to_string())) { let filtered = rest @@ -199,7 +198,7 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports { .push(rest.join("::")); check_dup.extend(rest.iter().map(ToString::to_string)); } - }, + } } } } From 876ef2addc1c11d5383ae8cce2bed867167d6d98 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Fri, 30 Apr 2021 18:40:34 -0700 Subject: [PATCH 0248/1222] Fix clippy --- clippy_lints/src/needless_question_mark.rs | 2 +- clippy_lints/src/try_err.rs | 2 +- clippy_lints/src/unused_io_amount.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index 7b156a8c49dd..d8417c7dc70d 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -147,7 +147,7 @@ fn is_some_or_ok_call<'a>(cx: &'a LateContext<'_>, expr: &'a Expr<'_>) -> Option if let ExprKind::Call(called, args) = &inner_expr_with_q.kind; if args.len() == 1; - if let ExprKind::Path(QPath::LangItem(LangItem::TryIntoResult, _)) = &called.kind; + if let ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, _)) = &called.kind; then { // Extract inner expr type from match argument generated by // question mark operator diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs index ebb39ea4877d..f2ba2b2ecf63 100644 --- a/clippy_lints/src/try_err.rs +++ b/clippy_lints/src/try_err.rs @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for TryErr { if let ExprKind::Match(match_arg, _, MatchSource::TryDesugar) = expr.kind; if let ExprKind::Call(match_fun, try_args) = match_arg.kind; if let ExprKind::Path(ref match_fun_path) = match_fun.kind; - if matches!(match_fun_path, QPath::LangItem(LangItem::TryIntoResult, _)); + if matches!(match_fun_path, QPath::LangItem(LangItem::TryTraitBranch, _)); if let Some(try_arg) = try_args.get(0); if let ExprKind::Call(err_fun, err_args) = try_arg.kind; if let Some(err_arg) = err_args.get(0); diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index 3387f35bac3d..c27a6d4e347b 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount { if let hir::ExprKind::Call(func, args) = res.kind { if matches!( func.kind, - hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::TryIntoResult, _)) + hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::TryTraitBranch, _)) ) { check_map_error(cx, &args[0], expr); } From 0506054a7e82a1437005e2c2dcc3fad7ef258e13 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Fri, 7 May 2021 14:53:02 -0500 Subject: [PATCH 0249/1222] Fix duplicate unknown lint errors --- tests/ui/deprecated.stderr | 8 +------- tests/ui/deprecated_old.stderr | 8 +------- tests/ui/rename.stderr | 8 +------- tests/ui/unknown_clippy_lints.stderr | 8 +------- 4 files changed, 4 insertions(+), 28 deletions(-) diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr index 3e125c1dab56..e5de839dbc50 100644 --- a/tests/ui/deprecated.stderr +++ b/tests/ui/deprecated.stderr @@ -84,11 +84,5 @@ error: lint `clippy::filter_map` has been removed: this lint has been replaced b LL | #[warn(clippy::filter_map)] | ^^^^^^^^^^^^^^^^^^ -error: lint `clippy::unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7 - --> $DIR/deprecated.rs:1:8 - | -LL | #[warn(clippy::unstable_as_slice)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 15 previous errors +error: aborting due to 14 previous errors diff --git a/tests/ui/deprecated_old.stderr b/tests/ui/deprecated_old.stderr index b8550078c460..8043ab0058a5 100644 --- a/tests/ui/deprecated_old.stderr +++ b/tests/ui/deprecated_old.stderr @@ -18,11 +18,5 @@ error: lint `misaligned_transmute` has been removed: this lint has been split in LL | #[warn(misaligned_transmute)] | ^^^^^^^^^^^^^^^^^^^^ -error: lint `unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7 - --> $DIR/deprecated_old.rs:1:8 - | -LL | #[warn(unstable_as_slice)] - | ^^^^^^^^^^^^^^^^^ - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index a9e803946041..c5d633ff86bf 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -24,11 +24,5 @@ error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redunda LL | #[warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` -error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:10:9 - | -LL | #![warn(clippy::cyclomatic_complexity)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` - -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors diff --git a/tests/ui/unknown_clippy_lints.stderr b/tests/ui/unknown_clippy_lints.stderr index 94a667e58989..421bf5ffa9a7 100644 --- a/tests/ui/unknown_clippy_lints.stderr +++ b/tests/ui/unknown_clippy_lints.stderr @@ -48,11 +48,5 @@ error: unknown lint: `clippy::const_static_lifetim` LL | #[warn(clippy::const_static_lifetim)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::redundant_static_lifetimes` -error: unknown lint: `clippy::All` - --> $DIR/unknown_clippy_lints.rs:5:10 - | -LL | #![allow(clippy::All)] - | ^^^^^^^^^^^ help: did you mean: `clippy::all` - -error: aborting due to 9 previous errors +error: aborting due to 8 previous errors From c8b03858823f8372a7c633331d943781a9454991 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 11 May 2021 00:40:25 +0200 Subject: [PATCH 0250/1222] fix clippy test --- tests/ui/new_without_default.rs | 1 - tests/ui/new_without_default.stderr | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index 64659b63f469..58094646b505 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -1,4 +1,3 @@ -#![feature(const_fn)] #![allow(dead_code, clippy::missing_safety_doc)] #![warn(clippy::new_without_default)] diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 973836f75a90..56c5fe1c6189 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -1,5 +1,5 @@ error: you should consider adding a `Default` implementation for `Foo` - --> $DIR/new_without_default.rs:8:5 + --> $DIR/new_without_default.rs:7:5 | LL | / pub fn new() -> Foo { LL | | Foo @@ -17,7 +17,7 @@ LL | } | error: you should consider adding a `Default` implementation for `Bar` - --> $DIR/new_without_default.rs:16:5 + --> $DIR/new_without_default.rs:15:5 | LL | / pub fn new() -> Self { LL | | Bar @@ -34,7 +34,7 @@ LL | } | error: you should consider adding a `Default` implementation for `LtKo<'c>` - --> $DIR/new_without_default.rs:80:5 + --> $DIR/new_without_default.rs:79:5 | LL | / pub fn new() -> LtKo<'c> { LL | | unimplemented!() @@ -51,7 +51,7 @@ LL | } | error: you should consider adding a `Default` implementation for `NewNotEqualToDerive` - --> $DIR/new_without_default.rs:157:5 + --> $DIR/new_without_default.rs:156:5 | LL | / pub fn new() -> Self { LL | | NewNotEqualToDerive { foo: 1 } @@ -68,7 +68,7 @@ LL | } | error: you should consider adding a `Default` implementation for `FooGenerics` - --> $DIR/new_without_default.rs:165:5 + --> $DIR/new_without_default.rs:164:5 | LL | / pub fn new() -> Self { LL | | Self(Default::default()) @@ -85,7 +85,7 @@ LL | } | error: you should consider adding a `Default` implementation for `BarGenerics` - --> $DIR/new_without_default.rs:172:5 + --> $DIR/new_without_default.rs:171:5 | LL | / pub fn new() -> Self { LL | | Self(Default::default()) From c29da91551dda5b6a605a107a963930a6501ff91 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sun, 2 Aug 2020 19:52:16 -0400 Subject: [PATCH 0251/1222] Implement span quoting for proc-macros This PR implements span quoting, allowing proc-macros to produce spans pointing *into their own crate*. This is used by the unstable `proc_macro::quote!` macro, allowing us to get error messages like this: ``` error[E0412]: cannot find type `MissingType` in this scope --> $DIR/auxiliary/span-from-proc-macro.rs:37:20 | LL | pub fn error_from_attribute(_args: TokenStream, _input: TokenStream) -> TokenStream { | ----------------------------------------------------------------------------------- in this expansion of procedural macro `#[error_from_attribute]` ... LL | field: MissingType | ^^^^^^^^^^^ not found in this scope | ::: $DIR/span-from-proc-macro.rs:8:1 | LL | #[error_from_attribute] | ----------------------- in this macro invocation ``` Here, `MissingType` occurs inside the implementation of the proc-macro `#[error_from_attribute]`. Previosuly, this would always result in a span pointing at `#[error_from_attribute]` This will make many proc-macro-related error message much more useful - when a proc-macro generates code containing an error, users will get an error message pointing directly at that code (within the macro definition), instead of always getting a span pointing at the macro invocation site. This is implemented as follows: * When a proc-macro crate is being *compiled*, it causes the `quote!` macro to get run. This saves all of the sapns in the input to `quote!` into the metadata of *the proc-macro-crate* (which we are currently compiling). The `quote!` macro then expands to a call to `proc_macro::Span::recover_proc_macro_span(id)`, where `id` is an opaque identifier for the span in the crate metadata. * When the same proc-macro crate is *run* (e.g. it is loaded from disk and invoked by some consumer crate), the call to `proc_macro::Span::recover_proc_macro_span` causes us to load the span from the proc-macro crate's metadata. The proc-macro then produces a `TokenStream` containing a `Span` pointing into the proc-macro crate itself. The recursive nature of 'quote!' can be difficult to understand at first. The file `src/test/ui/proc-macro/quote-debug.stdout` shows the output of the `quote!` macro, which should make this eaier to understand. This PR also supports custom quoting spans in custom quote macros (e.g. the `quote` crate). All span quoting goes through the `proc_macro::quote_span` method, which can be called by a custom quote macro to perform span quoting. An example of this usage is provided in `src/test/ui/proc-macro/auxiliary/custom-quote.rs` Custom quoting currently has a few limitations: In order to quote a span, we need to generate a call to `proc_macro::Span::recover_proc_macro_span`. However, proc-macros support renaming the `proc_macro` crate, so we can't simply hardcode this path. Previously, the `quote_span` method used the path `crate::Span` - however, this only works when it is called by the builtin `quote!` macro in the same crate. To support being called from arbitrary crates, we need access to the name of the `proc_macro` crate to generate a path. This PR adds an additional argument to `quote_span` to specify the name of the `proc_macro` crate. Howver, this feels kind of hacky, and we may want to change this before stabilizing anything quote-related. Additionally, using `quote_span` currently requires enabling the `proc_macro_internals` feature. The builtin `quote!` macro has an `#[allow_internal_unstable]` attribute, but this won't work for custom quote implementations. This will likely require some additional tricks to apply `allow_internal_unstable` to the span of `proc_macro::Span::recover_proc_macro_span`. --- clippy_lints/src/misc.rs | 2 +- clippy_lints/src/unit_types/unit_cmp.rs | 2 +- clippy_utils/src/lib.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 0b0cd9be46cf..6966d798c537 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -660,7 +660,7 @@ fn in_attributes_expansion(expr: &Expr<'_>) -> bool { use rustc_span::hygiene::MacroKind; if expr.span.from_expansion() { let data = expr.span.ctxt().outer_expn_data(); - matches!(data.kind, ExpnKind::Macro(MacroKind::Attr, _)) + matches!(data.kind, ExpnKind::Macro { kind: MacroKind::Attr, name: _, proc_macro: _ }) } else { false } diff --git a/clippy_lints/src/unit_types/unit_cmp.rs b/clippy_lints/src/unit_types/unit_cmp.rs index 85257f3113cb..d22f7d9a96bf 100644 --- a/clippy_lints/src/unit_types/unit_cmp.rs +++ b/clippy_lints/src/unit_types/unit_cmp.rs @@ -8,7 +8,7 @@ use super::UNIT_CMP; pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { if expr.span.from_expansion() { if let Some(callee) = expr.span.source_callee() { - if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind { + if let ExpnKind::Macro { kind: MacroKind::Bang, name: symbol, proc_macro: _ } = callee.kind { if let ExprKind::Binary(ref cmp, left, _) = expr.kind { let op = cmp.node; if op.is_comparison() && cx.typeck_results().expr_ty(left).is_unit() { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index f5ee49c7d5f9..9a0b72f06bbc 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -947,7 +947,7 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option { let data = span.ctxt().outer_expn_data(); let new_span = data.call_site; - if let ExpnKind::Macro(MacroKind::Bang, mac_name) = data.kind { + if let ExpnKind::Macro { kind: MacroKind::Bang, name: mac_name, proc_macro: _ } = data.kind { if mac_name.as_str() == name { return Some(new_span); } @@ -975,7 +975,7 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option { let data = span.ctxt().outer_expn_data(); let new_span = data.call_site; - if let ExpnKind::Macro(MacroKind::Bang, mac_name) = data.kind { + if let ExpnKind::Macro { kind: MacroKind::Bang, name: mac_name, proc_macro: _ } = data.kind { if mac_name.as_str() == name { return Some(new_span); } From 5c64f7d2f541aa21719e4bab6ecd97f1f2a755a1 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 11 May 2021 11:42:01 +0200 Subject: [PATCH 0252/1222] Use () for HIR queries. --- clippy_lints/src/derive.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 647af3bdc04d..e742cd626ab0 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -12,7 +12,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::map::Map; use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::{def_id::LOCAL_CRATE, source_map::Span}; +use rustc_span::{source_map::Span}; declare_clippy_lint! { /// **What it does:** Checks for deriving `Hash` but implementing `PartialEq` @@ -312,7 +312,7 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &T if ty_subs.non_erasable_generics().next().is_some() { let has_copy_impl = cx .tcx - .all_local_trait_impls(LOCAL_CRATE) + .all_local_trait_impls(()) .get(©_id) .map_or(false, |impls| { impls From 37bc4dd3e96ba6371d7dab30475883ccc9b074cf Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 11 May 2021 12:00:59 +0200 Subject: [PATCH 0253/1222] Use () for entry_fn. --- clippy_utils/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 9a0b72f06bbc..9ac9500b4eb7 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -60,7 +60,7 @@ use rustc_ast::ast::{self, Attribute, BorrowKind, LitKind}; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{DefId, LOCAL_CRATE}; +use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{self, walk_expr, ErasedMap, FnKind, NestedVisitorMap, Visitor}; use rustc_hir::LangItem::{ResultErr, ResultOk}; use rustc_hir::{ @@ -677,7 +677,7 @@ pub fn method_chain_args<'a>(expr: &'a Expr<'_>, methods: &[&str]) -> Option, def_id: DefId) -> bool { cx.tcx - .entry_fn(LOCAL_CRATE) + .entry_fn(()) .map_or(false, |(entry_fn_def_id, _)| def_id == entry_fn_def_id) } From b55a388b796c69e7f742aa6d5e07528366ca3c51 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 11 May 2021 13:39:19 +0200 Subject: [PATCH 0254/1222] Use () for inherent_impls. --- clippy_lints/src/inherent_impl.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index c31013e49be5..4e0b1ae78dfe 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::in_macro; use rustc_hir::def_id::DefIdMap; -use rustc_hir::{def_id, Crate, Impl, Item, ItemKind}; +use rustc_hir::{Crate, Impl, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { fn check_crate_post(&mut self, cx: &LateContext<'tcx>, krate: &'tcx Crate<'_>) { if !krate.items.is_empty() { // Retrieve all inherent implementations from the crate, grouped by type - for impls in cx.tcx.crate_inherent_impls(def_id::LOCAL_CRATE).inherent_impls.values() { + for impls in cx.tcx.crate_inherent_impls(()).inherent_impls.values() { // Filter out implementations that have generic params (type or lifetime) let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def)); if let Some(initial_span) = impl_spans.next() { From 732d0b006f808445963f66476b4f445812283ef1 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sat, 13 Feb 2021 14:52:25 -0500 Subject: [PATCH 0255/1222] Show macro name in 'this error originates in macro' message When there are multiple macros in use, it can be difficult to tell which one was responsible for producing an error. --- tests/ui-internal/default_lint.stderr | 2 +- tests/ui-internal/if_chain_style.stderr | 2 +- .../ui-internal/lint_without_lint_pass.stderr | 2 +- tests/ui/assertions_on_constants.stderr | 18 +++++++------- .../checked_unwrap/simple_conditionals.stderr | 2 +- tests/ui/collapsible_match2.stderr | 2 +- tests/ui/crashes/ice-6255.stderr | 2 +- .../others.stderr | 2 +- .../traits.stderr | 2 +- tests/ui/deref_addrof.stderr | 4 ++-- tests/ui/derive_hash_xor_eq.stderr | 8 +++---- tests/ui/derive_ord_xor_partial_ord.stderr | 8 +++---- tests/ui/doc_unsafe.stderr | 2 +- tests/ui/eq_op_macros.stderr | 8 +++---- tests/ui/fallible_impl_from.stderr | 6 ++--- tests/ui/implicit_hasher.stderr | 6 ++--- tests/ui/item_after_statement.stderr | 2 +- tests/ui/match_same_arms2.stderr | 4 ++-- tests/ui/mem_discriminant.stderr | 2 +- tests/ui/mem_replace_macro.stderr | 2 +- tests/ui/missing_panics_doc.stderr | 12 +++++----- tests/ui/mut_mut.stderr | 2 +- tests/ui/needless_question_mark.stderr | 2 +- tests/ui/option_env_unwrap.stderr | 8 +++---- tests/ui/panic_in_result_fn.stderr | 12 +++++----- tests/ui/panic_in_result_fn_assertions.stderr | 6 ++--- tests/ui/panicking_macros.stderr | 24 +++++++++---------- tests/ui/pattern_type_mismatch/syntax.stderr | 2 +- tests/ui/toplevel_ref_arg.stderr | 2 +- tests/ui/toplevel_ref_arg_non_rustfix.stderr | 2 +- tests/ui/try_err.stderr | 4 ++-- tests/ui/unit_cmp.stderr | 8 +++---- tests/ui/unsafe_derive_deserialize.stderr | 8 +++---- tests/ui/unseparated_prefix_literals.stderr | 2 +- 34 files changed, 90 insertions(+), 90 deletions(-) diff --git a/tests/ui-internal/default_lint.stderr b/tests/ui-internal/default_lint.stderr index 5c5836a7d297..4735573a47d3 100644 --- a/tests/ui-internal/default_lint.stderr +++ b/tests/ui-internal/default_lint.stderr @@ -15,7 +15,7 @@ note: the lint level is defined here LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ = note: `#[deny(clippy::default_lint)]` implied by `#[deny(clippy::internal)]` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/tests/ui-internal/if_chain_style.stderr b/tests/ui-internal/if_chain_style.stderr index b53c3ea05da9..d0f100f00692 100644 --- a/tests/ui-internal/if_chain_style.stderr +++ b/tests/ui-internal/if_chain_style.stderr @@ -56,7 +56,7 @@ LL | | } LL | | } | |_____^ | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `__if_chain` (in Nightly builds, run with -Z macro-backtrace for more info) error: `let` expression should be above the `if_chain!` --> $DIR/if_chain_style.rs:40:9 diff --git a/tests/ui-internal/lint_without_lint_pass.stderr b/tests/ui-internal/lint_without_lint_pass.stderr index 1257dae96d71..e308e13da138 100644 --- a/tests/ui-internal/lint_without_lint_pass.stderr +++ b/tests/ui-internal/lint_without_lint_pass.stderr @@ -15,7 +15,7 @@ note: the lint level is defined here LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ = note: `#[deny(clippy::lint_without_lint_pass)]` implied by `#[deny(clippy::internal)]` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/tests/ui/assertions_on_constants.stderr b/tests/ui/assertions_on_constants.stderr index c66fdf093f51..1eb87d89fad0 100644 --- a/tests/ui/assertions_on_constants.stderr +++ b/tests/ui/assertions_on_constants.stderr @@ -6,7 +6,7 @@ LL | assert!(true); | = note: `-D clippy::assertions-on-constants` implied by `-D warnings` = help: remove it - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(false)` should probably be replaced --> $DIR/assertions_on_constants.rs:12:5 @@ -15,7 +15,7 @@ LL | assert!(false); | ^^^^^^^^^^^^^^^ | = help: use `panic!()` or `unreachable!()` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(true)` will be optimized out by the compiler --> $DIR/assertions_on_constants.rs:13:5 @@ -24,7 +24,7 @@ LL | assert!(true, "true message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: remove it - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(false, "false message")` should probably be replaced --> $DIR/assertions_on_constants.rs:14:5 @@ -33,7 +33,7 @@ LL | assert!(false, "false message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `panic!("false message")` or `unreachable!("false message")` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(false, msg.to_uppercase())` should probably be replaced --> $DIR/assertions_on_constants.rs:17:5 @@ -42,7 +42,7 @@ LL | assert!(false, msg.to_uppercase()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `panic!(msg.to_uppercase())` or `unreachable!(msg.to_uppercase())` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(true)` will be optimized out by the compiler --> $DIR/assertions_on_constants.rs:20:5 @@ -51,7 +51,7 @@ LL | assert!(B); | ^^^^^^^^^^^ | = help: remove it - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(false)` should probably be replaced --> $DIR/assertions_on_constants.rs:23:5 @@ -60,7 +60,7 @@ LL | assert!(C); | ^^^^^^^^^^^ | = help: use `panic!()` or `unreachable!()` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert!(false, "C message")` should probably be replaced --> $DIR/assertions_on_constants.rs:24:5 @@ -69,7 +69,7 @@ LL | assert!(C, "C message"); | ^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `panic!("C message")` or `unreachable!("C message")` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: `debug_assert!(true)` will be optimized out by the compiler --> $DIR/assertions_on_constants.rs:26:5 @@ -78,7 +78,7 @@ LL | debug_assert!(true); | ^^^^^^^^^^^^^^^^^^^^ | = help: remove it - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 9 previous errors diff --git a/tests/ui/checked_unwrap/simple_conditionals.stderr b/tests/ui/checked_unwrap/simple_conditionals.stderr index 416ec1a01ab3..a4bc058fe202 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.stderr +++ b/tests/ui/checked_unwrap/simple_conditionals.stderr @@ -55,7 +55,7 @@ LL | $a.unwrap(); // unnecessary LL | m!(x); | ------ in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: you checked before that `unwrap()` cannot fail, instead of checking and unwrapping, it's better to use `if let` or `match` --> $DIR/simple_conditionals.rs:54:9 diff --git a/tests/ui/collapsible_match2.stderr b/tests/ui/collapsible_match2.stderr index ffef32d1fde9..8975b2efbaee 100644 --- a/tests/ui/collapsible_match2.stderr +++ b/tests/ui/collapsible_match2.stderr @@ -55,7 +55,7 @@ LL | mac!(res_opt => Ok(val), val => Some(n), foo(n)); | ^^^ ^^^^^^^ with this pattern | | | replace this binding - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) error: unnecessary nested match --> $DIR/collapsible_match2.rs:51:20 diff --git a/tests/ui/crashes/ice-6255.stderr b/tests/ui/crashes/ice-6255.stderr index d973ea1e23a2..5dbf9d440dd7 100644 --- a/tests/ui/crashes/ice-6255.stderr +++ b/tests/ui/crashes/ice-6255.stderr @@ -7,7 +7,7 @@ LL | extern crate std as core; LL | define_other_core!(); | --------------------- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/tests/ui/declare_interior_mutable_const/others.stderr b/tests/ui/declare_interior_mutable_const/others.stderr index 6153c96edc4f..7c9d705fa989 100644 --- a/tests/ui/declare_interior_mutable_const/others.stderr +++ b/tests/ui/declare_interior_mutable_const/others.stderr @@ -33,7 +33,7 @@ LL | const $name: $ty = $e; LL | declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable | ------------------------------------------ in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 4 previous errors diff --git a/tests/ui/declare_interior_mutable_const/traits.stderr b/tests/ui/declare_interior_mutable_const/traits.stderr index bb77f39b62c1..bed385b5273a 100644 --- a/tests/ui/declare_interior_mutable_const/traits.stderr +++ b/tests/ui/declare_interior_mutable_const/traits.stderr @@ -15,7 +15,7 @@ LL | const $name: $ty = $e; LL | declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); //~ ERROR interior mutable | ----------------------------------------------------------- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info) error: a `const` item should never be interior mutable --> $DIR/traits.rs:43:5 diff --git a/tests/ui/deref_addrof.stderr b/tests/ui/deref_addrof.stderr index e85b30fa56eb..1a14f31af8d7 100644 --- a/tests/ui/deref_addrof.stderr +++ b/tests/ui/deref_addrof.stderr @@ -57,7 +57,7 @@ LL | *& $visitor LL | m!(self) | -------- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: immediately dereferencing a reference --> $DIR/deref_addrof.rs:51:9 @@ -68,7 +68,7 @@ LL | *& mut $visitor LL | m_mut!(self) | ------------ in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `m_mut` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 10 previous errors diff --git a/tests/ui/derive_hash_xor_eq.stderr b/tests/ui/derive_hash_xor_eq.stderr index 2287a548fe46..b383072ca4db 100644 --- a/tests/ui/derive_hash_xor_eq.stderr +++ b/tests/ui/derive_hash_xor_eq.stderr @@ -14,7 +14,7 @@ LL | | true LL | | } LL | | } | |_^ - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `Hash` but have implemented `PartialEq` explicitly --> $DIR/derive_hash_xor_eq.rs:19:10 @@ -31,7 +31,7 @@ LL | | true LL | | } LL | | } | |_^ - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are implementing `Hash` explicitly but have derived `PartialEq` --> $DIR/derive_hash_xor_eq.rs:31:1 @@ -46,7 +46,7 @@ note: `PartialEq` implemented here | LL | #[derive(PartialEq)] | ^^^^^^^^^ - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are implementing `Hash` explicitly but have derived `PartialEq` --> $DIR/derive_hash_xor_eq.rs:49:5 @@ -61,7 +61,7 @@ note: `PartialEq` implemented here | LL | #[derive(PartialEq)] | ^^^^^^^^^ - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 4 previous errors diff --git a/tests/ui/derive_ord_xor_partial_ord.stderr b/tests/ui/derive_ord_xor_partial_ord.stderr index 97b46a4aa898..32896c99dad0 100644 --- a/tests/ui/derive_ord_xor_partial_ord.stderr +++ b/tests/ui/derive_ord_xor_partial_ord.stderr @@ -14,7 +14,7 @@ LL | | Some(other.cmp(self)) LL | | } LL | | } | |_^ - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `Ord` but have implemented `PartialOrd` explicitly --> $DIR/derive_ord_xor_partial_ord.rs:30:10 @@ -31,7 +31,7 @@ LL | | Some(other.cmp(self)) LL | | } LL | | } | |_^ - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are implementing `Ord` explicitly but have derived `PartialOrd` --> $DIR/derive_ord_xor_partial_ord.rs:42:1 @@ -48,7 +48,7 @@ note: `PartialOrd` implemented here | LL | #[derive(PartialOrd, PartialEq, Eq)] | ^^^^^^^^^^ - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are implementing `Ord` explicitly but have derived `PartialOrd` --> $DIR/derive_ord_xor_partial_ord.rs:62:5 @@ -65,7 +65,7 @@ note: `PartialOrd` implemented here | LL | #[derive(PartialOrd, PartialEq, Eq)] | ^^^^^^^^^^ - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 4 previous errors diff --git a/tests/ui/doc_unsafe.stderr b/tests/ui/doc_unsafe.stderr index c784d41ba172..73b53f3431e7 100644 --- a/tests/ui/doc_unsafe.stderr +++ b/tests/ui/doc_unsafe.stderr @@ -41,7 +41,7 @@ LL | | } LL | very_unsafe!(); | --------------- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `very_unsafe` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 5 previous errors diff --git a/tests/ui/eq_op_macros.stderr b/tests/ui/eq_op_macros.stderr index fb9378108b98..a28961e7568e 100644 --- a/tests/ui/eq_op_macros.stderr +++ b/tests/ui/eq_op_macros.stderr @@ -8,7 +8,7 @@ LL | assert_in_macro_def!(); | ----------------------- in this macro invocation | = note: `-D clippy::eq-op` implied by `-D warnings` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) error: identical args used in this `assert_ne!` macro call --> $DIR/eq_op_macros.rs:8:20 @@ -19,7 +19,7 @@ LL | assert_ne!(a, a); LL | assert_in_macro_def!(); | ----------------------- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) error: identical args used in this `assert_eq!` macro call --> $DIR/eq_op_macros.rs:22:16 @@ -54,7 +54,7 @@ LL | debug_assert_eq!(a, a); LL | assert_in_macro_def!(); | ----------------------- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) error: identical args used in this `debug_assert_ne!` macro call --> $DIR/eq_op_macros.rs:10:26 @@ -65,7 +65,7 @@ LL | debug_assert_ne!(a, a); LL | assert_in_macro_def!(); | ----------------------- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) error: identical args used in this `debug_assert_eq!` macro call --> $DIR/eq_op_macros.rs:38:22 diff --git a/tests/ui/fallible_impl_from.stderr b/tests/ui/fallible_impl_from.stderr index a938d234fa07..64c8ea857277 100644 --- a/tests/ui/fallible_impl_from.stderr +++ b/tests/ui/fallible_impl_from.stderr @@ -38,7 +38,7 @@ note: potential failure(s) | LL | panic!(); | ^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: consider implementing `TryFrom` instead --> $DIR/fallible_impl_from.rs:35:1 @@ -65,7 +65,7 @@ LL | } else if s.parse::().unwrap() != 42 { | ^^^^^^^^^^^^^^^^^^^^^^^^^ LL | panic!("{:?}", s); | ^^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: consider implementing `TryFrom` instead --> $DIR/fallible_impl_from.rs:53:1 @@ -87,7 +87,7 @@ LL | if s.parse::().ok().unwrap() != 42 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | panic!("{:?}", s); | ^^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 4 previous errors diff --git a/tests/ui/implicit_hasher.stderr b/tests/ui/implicit_hasher.stderr index 2b06d661772d..41ca6485c4c9 100644 --- a/tests/ui/implicit_hasher.stderr +++ b/tests/ui/implicit_hasher.stderr @@ -109,7 +109,7 @@ LL | impl Foo for HashMap { LL | gen!(impl); | ----------- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `gen` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider adding a type parameter | LL | impl Foo for HashMap { @@ -128,7 +128,7 @@ LL | pub fn $name(_map: &mut HashMap, _set: &mut HashSet) LL | gen!(fn bar); | ------------- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `gen` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider adding a type parameter | LL | pub fn $name(_map: &mut HashMap, _set: &mut HashSet) {} @@ -143,7 +143,7 @@ LL | pub fn $name(_map: &mut HashMap, _set: &mut HashSet) LL | gen!(fn bar); | ------------- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `gen` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider adding a type parameter | LL | pub fn $name(_map: &mut HashMap, _set: &mut HashSet) {} diff --git a/tests/ui/item_after_statement.stderr b/tests/ui/item_after_statement.stderr index 68a3c81b6a80..bcb163d4bc12 100644 --- a/tests/ui/item_after_statement.stderr +++ b/tests/ui/item_after_statement.stderr @@ -27,7 +27,7 @@ LL | | } LL | b!(); | ----- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 3 previous errors diff --git a/tests/ui/match_same_arms2.stderr b/tests/ui/match_same_arms2.stderr index 95f9494cdc99..430021a0f7f5 100644 --- a/tests/ui/match_same_arms2.stderr +++ b/tests/ui/match_same_arms2.stderr @@ -121,7 +121,7 @@ help: consider refactoring into `(Ok(x), Some(_)) | (Ok(_), Some(x))` | LL | (Ok(x), Some(_)) => println!("ok {}", x), | ^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) error: this `match` has identical arm bodies --> $DIR/match_same_arms2.rs:117:18 @@ -139,7 +139,7 @@ help: consider refactoring into `Ok(3) | Ok(_)` | LL | Ok(3) => println!("ok"), | ^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) error: this `match` has identical arm bodies --> $DIR/match_same_arms2.rs:144:14 diff --git a/tests/ui/mem_discriminant.stderr b/tests/ui/mem_discriminant.stderr index 8d9810970ade..36a225b75948 100644 --- a/tests/ui/mem_discriminant.stderr +++ b/tests/ui/mem_discriminant.stderr @@ -72,7 +72,7 @@ LL | mem_discriminant_but_in_a_macro!(&rro); | | help: try dereferencing: `*rro` | in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `mem_discriminant_but_in_a_macro` (in Nightly builds, run with -Z macro-backtrace for more info) error: calling `mem::discriminant` on non-enum type `&&&&&std::option::Option` --> $DIR/mem_discriminant.rs:34:5 diff --git a/tests/ui/mem_replace_macro.stderr b/tests/ui/mem_replace_macro.stderr index 4971a91050bf..b4963acc4553 100644 --- a/tests/ui/mem_replace_macro.stderr +++ b/tests/ui/mem_replace_macro.stderr @@ -8,7 +8,7 @@ LL | take!(s); | --------- in this macro invocation | = note: `-D clippy::mem-replace-with-default` implied by `-D warnings` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `take` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/tests/ui/missing_panics_doc.stderr b/tests/ui/missing_panics_doc.stderr index ba96a6a12b5d..8d882cc6e0d0 100644 --- a/tests/ui/missing_panics_doc.stderr +++ b/tests/ui/missing_panics_doc.stderr @@ -27,7 +27,7 @@ note: first possible panic found here | LL | panic!("This function panics") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: docs for function which may panic missing `# Panics` section --> $DIR/missing_panics_doc.rs:18:1 @@ -42,7 +42,7 @@ note: first possible panic found here | LL | todo!() | ^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: docs for function which may panic missing `# Panics` section --> $DIR/missing_panics_doc.rs:23:1 @@ -61,7 +61,7 @@ note: first possible panic found here | LL | panic!() | ^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: docs for function which may panic missing `# Panics` section --> $DIR/missing_panics_doc.rs:32:1 @@ -76,7 +76,7 @@ note: first possible panic found here | LL | if true { unreachable!() } else { panic!() } | ^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: docs for function which may panic missing `# Panics` section --> $DIR/missing_panics_doc.rs:37:1 @@ -92,7 +92,7 @@ note: first possible panic found here | LL | assert_eq!(x, 0); | ^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) error: docs for function which may panic missing `# Panics` section --> $DIR/missing_panics_doc.rs:43:1 @@ -108,7 +108,7 @@ note: first possible panic found here | LL | assert_ne!(x, 0); | ^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 7 previous errors diff --git a/tests/ui/mut_mut.stderr b/tests/ui/mut_mut.stderr index 44e814227141..0fed6953cb85 100644 --- a/tests/ui/mut_mut.stderr +++ b/tests/ui/mut_mut.stderr @@ -21,7 +21,7 @@ LL | &mut $p LL | let mut z = mut_ptr!(&mut 3u32); | ------------------- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `mut_ptr` (in Nightly builds, run with -Z macro-backtrace for more info) error: this expression mutably borrows a mutable reference. Consider reborrowing --> $DIR/mut_mut.rs:22:21 diff --git a/tests/ui/needless_question_mark.stderr b/tests/ui/needless_question_mark.stderr index afd68d91e51f..f1f05d1af3ae 100644 --- a/tests/ui/needless_question_mark.stderr +++ b/tests/ui/needless_question_mark.stderr @@ -75,7 +75,7 @@ LL | || -> Option<_> { Some(Some($expr)?) }() LL | let _x = some_and_qmark_in_macro!(x?); | ---------------------------- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `some_and_qmark_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 12 previous errors diff --git a/tests/ui/option_env_unwrap.stderr b/tests/ui/option_env_unwrap.stderr index 8de9c8a9d29e..e6a58b0b2b75 100644 --- a/tests/ui/option_env_unwrap.stderr +++ b/tests/ui/option_env_unwrap.stderr @@ -25,7 +25,7 @@ LL | let _ = option_env_unwrap!("PATH"); | -------------------------- in this macro invocation | = help: consider using the `env!` macro instead - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `option_env_unwrap` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time --> $DIR/option_env_unwrap.rs:12:9 @@ -37,7 +37,7 @@ LL | let _ = option_env_unwrap!("PATH", "environment variable PATH isn't set | ----------------------------------------------------------------- in this macro invocation | = help: consider using the `env!` macro instead - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `option_env_unwrap` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time --> $DIR/option_env_unwrap.rs:21:13 @@ -46,7 +46,7 @@ LL | let _ = option_env_unwrap_external!("PATH"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider using the `env!` macro instead - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `option_env_unwrap_external` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time --> $DIR/option_env_unwrap.rs:22:13 @@ -55,7 +55,7 @@ LL | let _ = option_env_unwrap_external!("PATH", "environment variable PATH | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider using the `env!` macro instead - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `option_env_unwrap_external` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 6 previous errors diff --git a/tests/ui/panic_in_result_fn.stderr b/tests/ui/panic_in_result_fn.stderr index eb744b0c198f..8d6e40c30a10 100644 --- a/tests/ui/panic_in_result_fn.stderr +++ b/tests/ui/panic_in_result_fn.stderr @@ -14,7 +14,7 @@ note: return Err() instead of panicking | LL | panic!("error"); | ^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn.rs:12:5 @@ -31,7 +31,7 @@ note: return Err() instead of panicking | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn.rs:17:5 @@ -48,7 +48,7 @@ note: return Err() instead of panicking | LL | unreachable!(); | ^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn.rs:22:5 @@ -65,7 +65,7 @@ note: return Err() instead of panicking | LL | todo!("Finish this"); | ^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn.rs:53:1 @@ -82,7 +82,7 @@ note: return Err() instead of panicking | LL | panic!("error"); | ^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn.rs:68:1 @@ -99,7 +99,7 @@ note: return Err() instead of panicking | LL | todo!("finish main method"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 6 previous errors diff --git a/tests/ui/panic_in_result_fn_assertions.stderr b/tests/ui/panic_in_result_fn_assertions.stderr index a17f043737d4..4c39b37d8798 100644 --- a/tests/ui/panic_in_result_fn_assertions.stderr +++ b/tests/ui/panic_in_result_fn_assertions.stderr @@ -15,7 +15,7 @@ note: return Err() instead of panicking | LL | assert!(x == 5, "wrong argument"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn_assertions.rs:13:5 @@ -33,7 +33,7 @@ note: return Err() instead of panicking | LL | assert_eq!(x, 5); | ^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn_assertions.rs:19:5 @@ -51,7 +51,7 @@ note: return Err() instead of panicking | LL | assert_ne!(x, 1); | ^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 3 previous errors diff --git a/tests/ui/panicking_macros.stderr b/tests/ui/panicking_macros.stderr index ffced49690e9..2e83c305a67e 100644 --- a/tests/ui/panicking_macros.stderr +++ b/tests/ui/panicking_macros.stderr @@ -25,7 +25,7 @@ LL | todo!(); | ^^^^^^^^ | = note: `-D clippy::todo` implied by `-D warnings` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: `todo` should not be present in production code --> $DIR/panicking_macros.rs:17:5 @@ -33,7 +33,7 @@ error: `todo` should not be present in production code LL | todo!("message"); | ^^^^^^^^^^^^^^^^^ | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: `todo` should not be present in production code --> $DIR/panicking_macros.rs:18:5 @@ -41,7 +41,7 @@ error: `todo` should not be present in production code LL | todo!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:24:5 @@ -50,7 +50,7 @@ LL | unimplemented!(); | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unimplemented` implied by `-D warnings` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:25:5 @@ -58,7 +58,7 @@ error: `unimplemented` should not be present in production code LL | unimplemented!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:26:5 @@ -66,7 +66,7 @@ error: `unimplemented` should not be present in production code LL | unimplemented!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:32:5 @@ -75,7 +75,7 @@ LL | unreachable!(); | ^^^^^^^^^^^^^^^ | = note: `-D clippy::unreachable` implied by `-D warnings` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:33:5 @@ -83,7 +83,7 @@ error: usage of the `unreachable!` macro LL | unreachable!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:34:5 @@ -91,7 +91,7 @@ error: usage of the `unreachable!` macro LL | unreachable!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) error: `panic` should not be present in production code --> $DIR/panicking_macros.rs:40:5 @@ -105,7 +105,7 @@ error: `todo` should not be present in production code LL | todo!(); | ^^^^^^^^ | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:42:5 @@ -113,7 +113,7 @@ error: `unimplemented` should not be present in production code LL | unimplemented!(); | ^^^^^^^^^^^^^^^^^ | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:43:5 @@ -121,7 +121,7 @@ error: usage of the `unreachable!` macro LL | unreachable!(); | ^^^^^^^^^^^^^^^ | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 16 previous errors diff --git a/tests/ui/pattern_type_mismatch/syntax.stderr b/tests/ui/pattern_type_mismatch/syntax.stderr index 5a5186bd4fcb..f309b2739829 100644 --- a/tests/ui/pattern_type_mismatch/syntax.stderr +++ b/tests/ui/pattern_type_mismatch/syntax.stderr @@ -73,7 +73,7 @@ LL | matching_macro!(value); | ----------------------- in this macro invocation | = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `matching_macro` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 9 previous errors diff --git a/tests/ui/toplevel_ref_arg.stderr b/tests/ui/toplevel_ref_arg.stderr index 15cb933fedc9..48e7d9ddd5ae 100644 --- a/tests/ui/toplevel_ref_arg.stderr +++ b/tests/ui/toplevel_ref_arg.stderr @@ -39,7 +39,7 @@ LL | let ref _y = 42; LL | gen_binding!(); | --------------- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `gen_binding` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 6 previous errors diff --git a/tests/ui/toplevel_ref_arg_non_rustfix.stderr b/tests/ui/toplevel_ref_arg_non_rustfix.stderr index b8cfd9873949..31f8c103ede5 100644 --- a/tests/ui/toplevel_ref_arg_non_rustfix.stderr +++ b/tests/ui/toplevel_ref_arg_non_rustfix.stderr @@ -15,7 +15,7 @@ LL | fn fun_example(ref _x: usize) {} LL | gen_function!(); | ---------------- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `gen_function` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/tests/ui/try_err.stderr b/tests/ui/try_err.stderr index 8f332a9b6492..09efc16c154e 100644 --- a/tests/ui/try_err.stderr +++ b/tests/ui/try_err.stderr @@ -37,7 +37,7 @@ LL | Err(_) => Err(1)?, LL | try_validation!(Ok::<_, i32>(5)); | --------------------------------- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `try_validation` (in Nightly builds, run with -Z macro-backtrace for more info) error: returning an `Err(_)` with the `?` operator --> $DIR/try_err.rs:102:23 @@ -48,7 +48,7 @@ LL | Err(_) => Err(ret_one!())?, LL | try_validation_in_macro!(Ok::<_, i32>(5)); | ------------------------------------------ in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `try_validation_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info) error: returning an `Err(_)` with the `?` operator --> $DIR/try_err.rs:141:9 diff --git a/tests/ui/unit_cmp.stderr b/tests/ui/unit_cmp.stderr index c8c0a85dfc10..75017cab0577 100644 --- a/tests/ui/unit_cmp.stderr +++ b/tests/ui/unit_cmp.stderr @@ -34,7 +34,7 @@ LL | | } LL | | ); | |______^ | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) error: `debug_assert_eq` of unit values detected. This will always succeed --> $DIR/unit_cmp.rs:32:5 @@ -48,7 +48,7 @@ LL | | } LL | | ); | |______^ | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) error: `assert_ne` of unit values detected. This will always fail --> $DIR/unit_cmp.rs:41:5 @@ -62,7 +62,7 @@ LL | | } LL | | ); | |______^ | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info) error: `debug_assert_ne` of unit values detected. This will always fail --> $DIR/unit_cmp.rs:49:5 @@ -76,7 +76,7 @@ LL | | } LL | | ); | |______^ | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 6 previous errors diff --git a/tests/ui/unsafe_derive_deserialize.stderr b/tests/ui/unsafe_derive_deserialize.stderr index 1978bd95a670..18c4276c6ddf 100644 --- a/tests/ui/unsafe_derive_deserialize.stderr +++ b/tests/ui/unsafe_derive_deserialize.stderr @@ -6,7 +6,7 @@ LL | #[derive(Deserialize)] | = note: `-D clippy::unsafe-derive-deserialize` implied by `-D warnings` = help: consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` --> $DIR/unsafe_derive_deserialize.rs:16:10 @@ -15,7 +15,7 @@ LL | #[derive(Deserialize)] | ^^^^^^^^^^^ | = help: consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` --> $DIR/unsafe_derive_deserialize.rs:22:10 @@ -24,7 +24,7 @@ LL | #[derive(Deserialize)] | ^^^^^^^^^^^ | = help: consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` --> $DIR/unsafe_derive_deserialize.rs:30:10 @@ -33,7 +33,7 @@ LL | #[derive(Deserialize)] | ^^^^^^^^^^^ | = help: consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 4 previous errors diff --git a/tests/ui/unseparated_prefix_literals.stderr b/tests/ui/unseparated_prefix_literals.stderr index d7dd526bcb9a..a0c0be7a9d15 100644 --- a/tests/ui/unseparated_prefix_literals.stderr +++ b/tests/ui/unseparated_prefix_literals.stderr @@ -51,7 +51,7 @@ LL | 42usize LL | let _ = lit_from_macro!(); | ----------------- in this macro invocation | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `lit_from_macro` (in Nightly builds, run with -Z macro-backtrace for more info) error: integer type suffix should be separated by an underscore --> $DIR/unseparated_prefix_literals.rs:40:16 From 5f11c35e90ce762a343d832c070f861d4e5a97d7 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Thu, 6 May 2021 13:36:07 +0200 Subject: [PATCH 0256/1222] remove cfg(bootstrap) --- clippy_lints/src/lib.rs | 1 - clippy_utils/src/lib.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index eb85cca0bd37..2c83409b402a 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -6,7 +6,6 @@ #![feature(in_band_lifetimes)] #![feature(iter_zip)] #![feature(once_cell)] -#![cfg_attr(bootstrap, feature(or_patterns))] #![feature(rustc_private)] #![feature(stmt_expr_attributes)] #![feature(control_flow_enum)] diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index d6dcd4abbd96..82250151aabc 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1,7 +1,6 @@ #![feature(box_patterns)] #![feature(in_band_lifetimes)] #![feature(iter_zip)] -#![cfg_attr(bootstrap, feature(or_patterns))] #![feature(rustc_private)] #![recursion_limit = "512"] #![cfg_attr(feature = "deny-warnings", deny(warnings))] From b72a7acf717bde664b6cd17cecad0b6ae05380c6 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 18 May 2021 21:46:41 -0400 Subject: [PATCH 0257/1222] Remove `doc(include)` --- clippy_lints/src/missing_doc.rs | 19 ++----------------- tests/ui/missing-doc-crate.rs | 3 +-- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index ec1572c26c26..a46a7407df0c 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -7,8 +7,7 @@ use clippy_utils::attrs::is_doc_hidden; use clippy_utils::diagnostics::span_lint; -use if_chain::if_chain; -use rustc_ast::ast::{self, MetaItem, MetaItemKind}; +use rustc_ast::ast; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::ty; @@ -56,20 +55,6 @@ impl MissingDoc { *self.doc_hidden_stack.last().expect("empty doc_hidden_stack") } - fn has_include(meta: Option) -> bool { - if_chain! { - if let Some(meta) = meta; - if let MetaItemKind::List(list) = meta.kind; - if let Some(meta) = list.get(0); - if let Some(name) = meta.ident(); - then { - name.name == sym::include - } else { - false - } - } - } - fn check_missing_docs_attrs( &self, cx: &LateContext<'_>, @@ -95,7 +80,7 @@ impl MissingDoc { let has_doc = attrs .iter() - .any(|a| a.doc_str().is_some() || Self::has_include(a.meta())); + .any(|a| a.doc_str().is_some()); if !has_doc { span_lint( cx, diff --git a/tests/ui/missing-doc-crate.rs b/tests/ui/missing-doc-crate.rs index 04711f864886..e00c7fbfed15 100644 --- a/tests/ui/missing-doc-crate.rs +++ b/tests/ui/missing-doc-crate.rs @@ -1,5 +1,4 @@ #![warn(clippy::missing_docs_in_private_items)] -#![feature(external_doc)] -#![doc(include = "../../README.md")] +#![doc = include_str!("../../README.md")] fn main() {} From c1674259a7be613d85037e67a6d7bcb30e618c2d Mon Sep 17 00:00:00 2001 From: r00ster91 Date: Fri, 4 Jun 2021 14:32:47 +0200 Subject: [PATCH 0258/1222] Replace some std::iter::repeat with str::repeat --- clippy_lints/src/mem_discriminant.rs | 3 +-- clippy_lints/src/methods/clone_on_copy.rs | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/mem_discriminant.rs b/clippy_lints/src/mem_discriminant.rs index a735c616f6e4..aca96e06ef2e 100644 --- a/clippy_lints/src/mem_discriminant.rs +++ b/clippy_lints/src/mem_discriminant.rs @@ -7,7 +7,6 @@ use rustc_errors::Applicability; use rustc_hir::{BorrowKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use std::iter; declare_clippy_lint! { /// **What it does:** Checks for calls of `mem::discriminant()` on a non-enum type. @@ -67,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for MemDiscriminant { } } - let derefs: String = iter::repeat('*').take(derefs_needed).collect(); + let derefs = "*".repeat(derefs_needed); diag.span_suggestion( param.span, "try dereferencing", diff --git a/clippy_lints/src/methods/clone_on_copy.rs b/clippy_lints/src/methods/clone_on_copy.rs index ce2e8fa8b107..1a32af5dc7a3 100644 --- a/clippy_lints/src/methods/clone_on_copy.rs +++ b/clippy_lints/src/methods/clone_on_copy.rs @@ -8,7 +8,6 @@ use rustc_hir::{BindingAnnotation, Expr, ExprKind, MatchSource, Node, PatKind}; use rustc_lint::LateContext; use rustc_middle::ty::{self, adjustment::Adjust}; use rustc_span::symbol::{sym, Symbol}; -use std::iter; use super::CLONE_DOUBLE_REF; use super::CLONE_ON_COPY; @@ -54,8 +53,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol, ty = inner; n += 1; } - let refs: String = iter::repeat('&').take(n + 1).collect(); - let derefs: String = iter::repeat('*').take(n).collect(); + let refs = "&".repeat(n + 1); + let derefs = "*".repeat(n); let explicit = format!("<{}{}>::clone({})", refs, ty, snip); diag.span_suggestion( expr.span, From ec5f99fe360a9a7a6583642ee4f83e9b6f802e8a Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 4 Jun 2021 16:14:03 -0400 Subject: [PATCH 0259/1222] Revert clippy's path to the copy intrinsics (part of reverting PR 81238). --- clippy_utils/src/paths.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index 8037d670500b..b913d1ce8b1f 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -116,8 +116,8 @@ pub const PERMISSIONS_FROM_MODE: [&str; 7] = ["std", "os", "imp", "unix", "fs", pub const POLL: [&str; 4] = ["core", "task", "poll", "Poll"]; pub const POLL_PENDING: [&str; 5] = ["core", "task", "poll", "Poll", "Pending"]; pub const POLL_READY: [&str; 5] = ["core", "task", "poll", "Poll", "Ready"]; -pub const PTR_COPY: [&str; 4] = ["core", "intrinsics", "", "copy"]; -pub const PTR_COPY_NONOVERLAPPING: [&str; 4] = ["core", "intrinsics", "", "copy_nonoverlapping"]; +pub const PTR_COPY: [&str; 3] = ["core", "intrinsics", "copy"]; +pub const PTR_COPY_NONOVERLAPPING: [&str; 3] = ["core", "intrinsics", "copy_nonoverlapping"]; pub const PTR_EQ: [&str; 3] = ["core", "ptr", "eq"]; pub const PTR_NULL: [&str; 3] = ["core", "ptr", "null"]; pub const PTR_NULL_MUT: [&str; 3] = ["core", "ptr", "null_mut"]; From 04c9394ddd033889f145a58d59667d9cb11f5d7d Mon Sep 17 00:00:00 2001 From: Smitty Date: Mon, 17 May 2021 17:19:48 -0400 Subject: [PATCH 0260/1222] Remove some last remants of {push,pop}_unsafe! These macros have already been removed, but there was still some code handling these macros. That code is now removed. --- clippy_lints/src/derive.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 840c1eba79d1..729941f345a9 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -411,9 +411,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> { if let ExprKind::Block(block, _) = expr.kind { match block.rules { - BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) - | BlockCheckMode::PushUnsafeBlock(UnsafeSource::UserProvided) - | BlockCheckMode::PopUnsafeBlock(UnsafeSource::UserProvided) => { + BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) => { self.has_unsafe = true; }, _ => {}, From 263e92cd31682da80a46d8700716d14265af267b Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Thu, 10 Dec 2020 13:20:07 +0100 Subject: [PATCH 0261/1222] Add support for using qualified paths with structs in expression and pattern position. --- .../src/misc_early/unneeded_field_pattern.rs | 2 +- .../src/misc_early/unneeded_wildcard_pattern.rs | 2 +- clippy_lints/src/non_expressive_names.rs | 2 +- clippy_lints/src/unnested_or_patterns.rs | 16 +++++++++------- clippy_utils/src/ast_utils.rs | 17 +++++++++++++---- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/misc_early/unneeded_field_pattern.rs b/clippy_lints/src/misc_early/unneeded_field_pattern.rs index 329a0009a3e2..2201cf56d52a 100644 --- a/clippy_lints/src/misc_early/unneeded_field_pattern.rs +++ b/clippy_lints/src/misc_early/unneeded_field_pattern.rs @@ -5,7 +5,7 @@ use rustc_lint::{EarlyContext, LintContext}; use super::UNNEEDED_FIELD_PATTERN; pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) { - if let PatKind::Struct(ref npat, ref pfields, _) = pat.kind { + if let PatKind::Struct(_, ref npat, ref pfields, _) = pat.kind { let mut wilds = 0; let type_name = npat .segments diff --git a/clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs b/clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs index 4dd032d78f1d..df044538fe19 100644 --- a/clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs +++ b/clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs @@ -7,7 +7,7 @@ use rustc_span::source_map::Span; use super::UNNEEDED_WILDCARD_PATTERN; pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) { - if let PatKind::TupleStruct(_, ref patterns) | PatKind::Tuple(ref patterns) = pat.kind { + if let PatKind::TupleStruct(_, _, ref patterns) | PatKind::Tuple(ref patterns) = pat.kind { if let Some(rest_index) = patterns.iter().position(|pat| pat.is_rest()) { if let Some((left_index, left_pat)) = patterns[..rest_index] .iter() diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 5292af5f0765..1a23e6afe283 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -139,7 +139,7 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for SimilarNamesNameVisitor<'a, 'tcx, 'b> { self.check_ident(ident); } }, - PatKind::Struct(_, ref fields, _) => { + PatKind::Struct(_, _, ref fields, _) => { for field in fields { if !field.is_shorthand { self.visit_pat(&field.pat); diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 3e985fa72b8f..1b3c457b01ad 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -1,6 +1,6 @@ #![allow(clippy::wildcard_imports, clippy::enum_glob_use)] -use clippy_utils::ast_utils::{eq_field_pat, eq_id, eq_pat, eq_path}; +use clippy_utils::ast_utils::{eq_field_pat, eq_id, eq_pat, eq_path, eq_maybe_qself}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::{meets_msrv, msrvs, over}; use rustc_ast::mut_visit::*; @@ -273,16 +273,16 @@ fn transform_with_focus_on_idx(alternatives: &mut Vec>, focus_idx: usize) |k| always_pat!(k, Tuple(ps) => ps), ), // Transform `S(pre, x, post) | ... | S(pre, y, post)` into `S(pre, x | y, post)`. - TupleStruct(path1, ps1) => extend_with_matching_product( + TupleStruct(qself1, path1, ps1) => extend_with_matching_product( ps1, start, alternatives, |k, ps1, idx| matches!( k, - TupleStruct(path2, ps2) if eq_path(path1, path2) && eq_pre_post(ps1, ps2, idx) + TupleStruct(qself2, path2, ps2) if eq_maybe_qself(qself1, qself2) && eq_path(path1, path2) && eq_pre_post(ps1, ps2, idx) ), - |k| always_pat!(k, TupleStruct(_, ps) => ps), + |k| always_pat!(k, TupleStruct(_, _, ps) => ps), ), // Transform a record pattern `S { fp_0, ..., fp_n }`. - Struct(path1, fps1, rest1) => extend_with_struct_pat(path1, fps1, *rest1, start, alternatives), + Struct(qself1, path1, fps1, rest1) => extend_with_struct_pat(qself1, path1, fps1, *rest1, start, alternatives), }; alternatives[focus_idx].kind = focus_kind; @@ -294,6 +294,7 @@ fn transform_with_focus_on_idx(alternatives: &mut Vec>, focus_idx: usize) /// So when we fixate on some `ident_k: pat_k`, we try to find `ident_k` in the other pattern /// and check that all `fp_i` where `i ∈ ((0...n) \ k)` between two patterns are equal. fn extend_with_struct_pat( + qself1: &Option, path1: &ast::Path, fps1: &mut Vec, rest1: bool, @@ -306,8 +307,9 @@ fn extend_with_struct_pat( start, alternatives, |k| { - matches!(k, Struct(path2, fps2, rest2) + matches!(k, Struct(qself2, path2, fps2, rest2) if rest1 == *rest2 // If one struct pattern has `..` so must the other. + && eq_maybe_qself(qself1, qself2) && eq_path(path1, path2) && fps1.len() == fps2.len() && fps1.iter().enumerate().all(|(idx_1, fp1)| { @@ -323,7 +325,7 @@ fn extend_with_struct_pat( })) }, // Extract `p2_k`. - |k| always_pat!(k, Struct(_, mut fps, _) => fps.swap_remove(pos_in_2.take().unwrap()).pat), + |k| always_pat!(k, Struct(_, _, mut fps, _) => fps.swap_remove(pos_in_2.take().unwrap()).pat), ); extend_with_tail_or(&mut fps1[idx].pat, tail_or) }) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 93e10c836cc7..e6d84bc7560b 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -47,9 +47,9 @@ pub fn eq_pat(l: &Pat, r: &Pat) -> bool { | (Ref(l, Mutability::Mut), Ref(r, Mutability::Mut)) => eq_pat(l, r), (Tuple(l), Tuple(r)) | (Slice(l), Slice(r)) => over(l, r, |l, r| eq_pat(l, r)), (Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp), - (TupleStruct(lp, lfs), TupleStruct(rp, rfs)) => eq_path(lp, rp) && over(lfs, rfs, |l, r| eq_pat(l, r)), - (Struct(lp, lfs, lr), Struct(rp, rfs, rr)) => { - lr == rr && eq_path(lp, rp) && unordered_over(lfs, rfs, |lf, rf| eq_field_pat(lf, rf)) + (TupleStruct(lqself, lp, lfs), TupleStruct(rqself, rp, rfs)) => eq_maybe_qself(lqself, rqself) && eq_path(lp, rp) && over(lfs, rfs, |l, r| eq_pat(l, r)), + (Struct(lqself, lp, lfs, lr), Struct(rqself, rp, rfs, rr)) => { + lr == rr && eq_maybe_qself(lqself, rqself) &&eq_path(lp, rp) && unordered_over(lfs, rfs, |lf, rf| eq_field_pat(lf, rf)) }, (Or(ls), Or(rs)) => unordered_over(ls, rs, |l, r| eq_pat(l, r)), (MacCall(l), MacCall(r)) => eq_mac_call(l, r), @@ -78,6 +78,14 @@ pub fn eq_qself(l: &QSelf, r: &QSelf) -> bool { l.position == r.position && eq_ty(&l.ty, &r.ty) } +pub fn eq_maybe_qself(l: &Option, r: &Option) -> bool { + match (l, r) { + (Some(l), Some(r)) => eq_qself(l, r), + (None, None) => true, + _ => false + } +} + pub fn eq_path(l: &Path, r: &Path) -> bool { over(&l.segments, &r.segments, |l, r| eq_path_seg(l, r)) } @@ -170,7 +178,8 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp), (MacCall(l), MacCall(r)) => eq_mac_call(l, r), (Struct(lse), Struct(rse)) => { - eq_path(&lse.path, &rse.path) + eq_maybe_qself(&lse.qself, &rse.qself) + && eq_path(&lse.path, &rse.path) && eq_struct_rest(&lse.rest, &rse.rest) && unordered_over(&lse.fields, &rse.fields, |l, r| eq_field(l, r)) }, From 1773409486f48afe4179ce6f0c277874735cb5e7 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Fri, 18 Jun 2021 16:11:32 +0800 Subject: [PATCH 0262/1222] Make clippy tests happy --- tests/ui/bytes_nth.fixed | 2 +- tests/ui/bytes_nth.rs | 2 +- tests/ui/bytes_nth.stderr | 6 +++--- tests/ui/iter_count.fixed | 16 ++++++++-------- tests/ui/iter_count.rs | 16 ++++++++-------- tests/ui/iter_count.stderr | 18 +++++++++--------- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/ui/bytes_nth.fixed b/tests/ui/bytes_nth.fixed index bf68a7bbbf1d..46b7833f4280 100644 --- a/tests/ui/bytes_nth.fixed +++ b/tests/ui/bytes_nth.fixed @@ -6,6 +6,6 @@ fn main() { let s = String::from("String"); s.as_bytes().get(3); - &s.as_bytes().get(3); + let _ = &s.as_bytes().get(3); s[..].as_bytes().get(3); } diff --git a/tests/ui/bytes_nth.rs b/tests/ui/bytes_nth.rs index 629812cc02cb..c5e983d4d4e0 100644 --- a/tests/ui/bytes_nth.rs +++ b/tests/ui/bytes_nth.rs @@ -6,6 +6,6 @@ fn main() { let s = String::from("String"); s.bytes().nth(3); - &s.bytes().nth(3); + let _ = &s.bytes().nth(3); s[..].bytes().nth(3); } diff --git a/tests/ui/bytes_nth.stderr b/tests/ui/bytes_nth.stderr index 9a5742928cd6..536decf5e7fc 100644 --- a/tests/ui/bytes_nth.stderr +++ b/tests/ui/bytes_nth.stderr @@ -7,10 +7,10 @@ LL | s.bytes().nth(3); = note: `-D clippy::bytes-nth` implied by `-D warnings` error: called `.byte().nth()` on a `String` - --> $DIR/bytes_nth.rs:9:6 + --> $DIR/bytes_nth.rs:9:14 | -LL | &s.bytes().nth(3); - | ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)` +LL | let _ = &s.bytes().nth(3); + | ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)` error: called `.byte().nth()` on a `str` --> $DIR/bytes_nth.rs:10:5 diff --git a/tests/ui/iter_count.fixed b/tests/ui/iter_count.fixed index b11dadda6c24..52f833ece696 100644 --- a/tests/ui/iter_count.fixed +++ b/tests/ui/iter_count.fixed @@ -3,11 +3,11 @@ #![warn(clippy::iter_count)] #![allow( - unused_variables, - array_into_iter, - unused_mut, - clippy::into_iter_on_ref, - clippy::unnecessary_operation +unused_variables, +array_into_iter, +unused_mut, +clippy::into_iter_on_ref, +clippy::unnecessary_operation )] extern crate option_helpers; @@ -50,7 +50,7 @@ fn main() { linked_list.push_back(1); binary_heap.push(1); - &vec[..].len(); + let _ = &vec[..].len(); vec.len(); boxed_slice.len(); vec_deque.len(); @@ -62,13 +62,13 @@ fn main() { binary_heap.len(); vec.len(); - &vec[..].len(); + let _ = &vec[..].len(); vec_deque.len(); hash_map.len(); b_tree_map.len(); linked_list.len(); - &vec[..].len(); + let _ = &vec[..].len(); vec.len(); vec_deque.len(); hash_set.len(); diff --git a/tests/ui/iter_count.rs b/tests/ui/iter_count.rs index 7d49c6a3dbbb..e76914aa54c1 100644 --- a/tests/ui/iter_count.rs +++ b/tests/ui/iter_count.rs @@ -3,11 +3,11 @@ #![warn(clippy::iter_count)] #![allow( - unused_variables, - array_into_iter, - unused_mut, - clippy::into_iter_on_ref, - clippy::unnecessary_operation +unused_variables, +array_into_iter, +unused_mut, +clippy::into_iter_on_ref, +clippy::unnecessary_operation )] extern crate option_helpers; @@ -50,7 +50,7 @@ fn main() { linked_list.push_back(1); binary_heap.push(1); - &vec[..].iter().count(); + let _ = &vec[..].iter().count(); vec.iter().count(); boxed_slice.iter().count(); vec_deque.iter().count(); @@ -62,13 +62,13 @@ fn main() { binary_heap.iter().count(); vec.iter_mut().count(); - &vec[..].iter_mut().count(); + let _ = &vec[..].iter_mut().count(); vec_deque.iter_mut().count(); hash_map.iter_mut().count(); b_tree_map.iter_mut().count(); linked_list.iter_mut().count(); - &vec[..].into_iter().count(); + let _ = &vec[..].into_iter().count(); vec.into_iter().count(); vec_deque.into_iter().count(); hash_set.into_iter().count(); diff --git a/tests/ui/iter_count.stderr b/tests/ui/iter_count.stderr index f3fb98e65b99..1d2c22f9dfad 100644 --- a/tests/ui/iter_count.stderr +++ b/tests/ui/iter_count.stderr @@ -1,8 +1,8 @@ error: called `.iter().count()` on a `slice` - --> $DIR/iter_count.rs:53:6 + --> $DIR/iter_count.rs:53:14 | -LL | &vec[..].iter().count(); - | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` +LL | let _ = &vec[..].iter().count(); + | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` | = note: `-D clippy::iter-count` implied by `-D warnings` @@ -67,10 +67,10 @@ LL | vec.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()` error: called `.iter_mut().count()` on a `slice` - --> $DIR/iter_count.rs:65:6 + --> $DIR/iter_count.rs:65:14 | -LL | &vec[..].iter_mut().count(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` +LL | let _ = &vec[..].iter_mut().count(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` error: called `.iter_mut().count()` on a `VecDeque` --> $DIR/iter_count.rs:66:5 @@ -97,10 +97,10 @@ LL | linked_list.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()` error: called `.into_iter().count()` on a `slice` - --> $DIR/iter_count.rs:71:6 + --> $DIR/iter_count.rs:71:14 | -LL | &vec[..].into_iter().count(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` +LL | let _ = &vec[..].into_iter().count(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` error: called `.into_iter().count()` on a `Vec` --> $DIR/iter_count.rs:72:5 From 13fd025499acbed5a1e4db72a1aac53934cc12d8 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Fri, 18 Jun 2021 16:20:30 +0800 Subject: [PATCH 0263/1222] Address comment --- tests/ui/iter_count.fixed | 10 +++++----- tests/ui/iter_count.rs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/ui/iter_count.fixed b/tests/ui/iter_count.fixed index 52f833ece696..97c5929783d8 100644 --- a/tests/ui/iter_count.fixed +++ b/tests/ui/iter_count.fixed @@ -3,11 +3,11 @@ #![warn(clippy::iter_count)] #![allow( -unused_variables, -array_into_iter, -unused_mut, -clippy::into_iter_on_ref, -clippy::unnecessary_operation + unused_variables, + array_into_iter, + unused_mut, + clippy::into_iter_on_ref, + clippy::unnecessary_operation )] extern crate option_helpers; diff --git a/tests/ui/iter_count.rs b/tests/ui/iter_count.rs index e76914aa54c1..70bb734763f0 100644 --- a/tests/ui/iter_count.rs +++ b/tests/ui/iter_count.rs @@ -3,11 +3,11 @@ #![warn(clippy::iter_count)] #![allow( -unused_variables, -array_into_iter, -unused_mut, -clippy::into_iter_on_ref, -clippy::unnecessary_operation + unused_variables, + array_into_iter, + unused_mut, + clippy::into_iter_on_ref, + clippy::unnecessary_operation )] extern crate option_helpers; From df6e16b9bc01c4beb434ee76823e658dfa542e4e Mon Sep 17 00:00:00 2001 From: Alexander Melentyev Date: Mon, 21 Jun 2021 12:11:37 +0300 Subject: [PATCH 0264/1222] Delete spaces --- CONTRIBUTING.md | 2 +- README.md | 2 +- clippy_utils/src/ast_utils.rs | 2 +- doc/basics.md | 4 ++-- lintcheck/README.md | 2 +- util/gh-pages/index.html | 8 ++++---- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7265d1b83237..7d7b7c811738 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -342,7 +342,7 @@ We have prioritization labels and a sync-blocker label, which are described belo - [P-low][p-low]: Requires attention (fix/response/evaluation) by a team member but isn't urgent. - [P-medium][p-medium]: Should be addressed by a team member until the next sync. - [P-high][p-high]: Should be immediately addressed and will require an out-of-cycle sync or a backport. -- [L-sync-blocker][l-sync-blocker]: An issue that "blocks" a sync. +- [L-sync-blocker][l-sync-blocker]: An issue that "blocks" a sync. Or rather: before the sync this should be addressed, e.g. by removing a lint again, so it doesn't hit beta/stable. diff --git a/README.md b/README.md index 6c556f579ca4..bd322cc80702 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ As with `cargo check`, this includes dependencies that are members of the worksp If you want to run Clippy **only** on the given crate, use the `--no-deps` option like this: ```terminal -cargo clippy -p example -- --no-deps +cargo clippy -p example -- --no-deps ``` ### As a rustc replacement (`clippy-driver`) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index e6d84bc7560b..90c034bd02a9 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -178,7 +178,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp), (MacCall(l), MacCall(r)) => eq_mac_call(l, r), (Struct(lse), Struct(rse)) => { - eq_maybe_qself(&lse.qself, &rse.qself) + eq_maybe_qself(&lse.qself, &rse.qself) && eq_path(&lse.path, &rse.path) && eq_struct_rest(&lse.rest, &rse.rest) && unordered_over(&lse.fields, &rse.fields, |l, r| eq_field(l, r)) diff --git a/doc/basics.md b/doc/basics.md index e2e307ce4f6c..ed3a2fff83f1 100644 --- a/doc/basics.md +++ b/doc/basics.md @@ -96,9 +96,9 @@ cargo dev ide_setup ## lintcheck `cargo lintcheck` will build and run clippy on a fixed set of crates and generate a log of the results. -You can `git diff` the updated log against its previous version and +You can `git diff` the updated log against its previous version and see what impact your lint made on a small set of crates. -If you add a new lint, please audit the resulting warnings and make sure +If you add a new lint, please audit the resulting warnings and make sure there are no false positives and that the suggestions are valid. Refer to the tools [README] for more details. diff --git a/lintcheck/README.md b/lintcheck/README.md index 52bbcc0a8317..a61070d8a80e 100644 --- a/lintcheck/README.md +++ b/lintcheck/README.md @@ -73,5 +73,5 @@ You can run `./lintcheck/target/debug/lintcheck --fix` which will run Clippy wit print a warning if Clippys suggestions fail to apply (if the resulting code does not build). This lets us spot bad suggestions or false positives automatically in some cases. -Please note that the target dir should be cleaned afterwards since clippy will modify +Please note that the target dir should be cleaned afterwards since clippy will modify the downloaded sources which can lead to unexpected results when running lintcheck again afterwards. diff --git a/util/gh-pages/index.html b/util/gh-pages/index.html index 27ecb532dd00..0174d3ffcbc2 100644 --- a/util/gh-pages/index.html +++ b/util/gh-pages/index.html @@ -363,7 +363,7 @@

$scope.bySearch = function (lint, index, array) { let searchStr = $scope.search; - // It can be `null` I haven't missed this value + // It can be `null` I haven't missed this value if (searchStr == null || searchStr.length < 3) { return true; } @@ -375,7 +375,7 @@

} // Search the description - // The use of `for`-loops instead of `foreach` enables us to return early + // The use of `for`-loops instead of `foreach` enables us to return early let terms = searchStr.split(" "); for (index = 0; index < terms.length; index++) { if (lint.id.indexOf(terms[index]) !== -1) { @@ -463,7 +463,7 @@

let children = themeMenu.children; for (let index = 0; index < children.length; index++) { - let child = children[index]; + let child = children[index]; child.addEventListener("click", function(e) { setTheme(child.id, true); }); @@ -476,7 +476,7 @@

let enableHighlight = false; let enableNight = false; let enableAyu = false; - + if (theme == "ayu") { enableAyu = true; } else if (theme == "coal" || theme == "navy") { From 901e62e5b144929a1a7ccc1e564c2b99eb2e43bd Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Fri, 25 Jun 2021 15:29:14 +0200 Subject: [PATCH 0265/1222] Fix clippy test --- tests/ui/crashes/ice-3969.stderr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ui/crashes/ice-3969.stderr b/tests/ui/crashes/ice-3969.stderr index fb4589a48ec4..8b2c318acf84 100644 --- a/tests/ui/crashes/ice-3969.stderr +++ b/tests/ui/crashes/ice-3969.stderr @@ -5,7 +5,7 @@ LL | for<'a> Dst: Sized, | ^^^^^^ help: use `dyn`: `dyn A + 'a` | = note: `-D bare-trait-objects` implied by `-D warnings` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition! + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see issue #80165 error: trait objects without an explicit `dyn` are deprecated @@ -14,7 +14,7 @@ error: trait objects without an explicit `dyn` are deprecated LL | let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); | ^ help: use `dyn`: `dyn A` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition! + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see issue #80165 error: trait objects without an explicit `dyn` are deprecated @@ -23,7 +23,7 @@ error: trait objects without an explicit `dyn` are deprecated LL | let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); | ^ help: use `dyn`: `dyn A` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition! + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see issue #80165 error: aborting due to 3 previous errors From e97d455da17acefd276a08c250465d284abff09d Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 7 Jun 2021 11:03:17 +0200 Subject: [PATCH 0266/1222] Rename all_crate_nums query to crates and remove useless wrapper --- clippy_utils/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 769836aaf18e..9dcfa66c4efb 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -493,7 +493,7 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Res { _ => return Res::Err, }; let tcx = cx.tcx; - let crates = tcx.crates(); + let crates = tcx.crates(()); let krate = try_res!(crates.iter().find(|&&num| tcx.crate_name(num).as_str() == krate)); let first = try_res!(item_child_by_name(tcx, krate.as_def_id(), first)); let last = path From cbc184ecae56ad43d5e34ed7f67175d633f40275 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sun, 4 Jul 2021 11:26:32 -0400 Subject: [PATCH 0267/1222] allow inference vars in type_implements_trait --- clippy_utils/src/ty.rs | 60 ++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index a92d3be5d3cf..add487593c6d 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -128,7 +128,9 @@ pub fn implements_trait<'tcx>( return false; } let ty_params = cx.tcx.mk_substs(ty_params.iter()); - cx.tcx.type_implements_trait((trait_id, ty, ty_params, cx.param_env)) + cx.tcx + .type_implements_trait((trait_id, ty, ty_params, cx.param_env)) + .must_apply_modulo_regions() } /// Checks whether this type implements `Drop`. @@ -144,22 +146,26 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { match ty.kind() { ty::Adt(adt, _) => must_use_attr(cx.tcx.get_attrs(adt.did)).is_some(), ty::Foreign(ref did) => must_use_attr(cx.tcx.get_attrs(*did)).is_some(), - ty::Slice(ty) | ty::Array(ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) | ty::Ref(_, ty, _) => { + ty::Slice(ty) + | ty::Array(ty, _) + | ty::RawPtr(ty::TypeAndMut { ty, .. }) + | ty::Ref(_, ty, _) => { // for the Array case we don't need to care for the len == 0 case // because we don't want to lint functions returning empty arrays is_must_use_ty(cx, *ty) - }, + } ty::Tuple(substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { - if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.kind().skip_binder() { + if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.kind().skip_binder() + { if must_use_attr(cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() { return true; } } } false - }, + } ty::Dynamic(binder, _) => { for predicate in binder.iter() { if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() { @@ -169,7 +175,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { } } false - }, + } _ => false, } } @@ -179,7 +185,11 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { // not succeed /// Checks if `Ty` is normalizable. This function is useful /// to avoid crashes on `layout_of`. -pub fn is_normalizable<'tcx>(cx: &LateContext<'tcx>, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool { +pub fn is_normalizable<'tcx>( + cx: &LateContext<'tcx>, + param_env: ty::ParamEnv<'tcx>, + ty: Ty<'tcx>, +) -> bool { is_normalizable_helper(cx, param_env, ty, &mut FxHashMap::default()) } @@ -199,15 +209,14 @@ fn is_normalizable_helper<'tcx>( if infcx.at(&cause, param_env).normalize(ty).is_ok() { match ty.kind() { ty::Adt(def, substs) => def.variants.iter().all(|variant| { - variant - .fields - .iter() - .all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache)) + variant.fields.iter().all(|field| { + is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache) + }) }), _ => ty.walk().all(|generic_arg| match generic_arg.unpack() { GenericArgKind::Type(inner_ty) if inner_ty != ty => { is_normalizable_helper(cx, param_env, inner_ty, cache) - }, + } _ => true, // if inner_ty == ty, we've already checked it }), } @@ -225,7 +234,9 @@ pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool { match ty.kind() { ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => true, ty::Ref(_, inner, _) if *inner.kind() == ty::Str => true, - ty::Array(inner_type, _) | ty::Slice(inner_type) => is_recursively_primitive_type(inner_type), + ty::Array(inner_type, _) | ty::Slice(inner_type) => { + is_recursively_primitive_type(inner_type) + } ty::Tuple(inner_types) => inner_types.types().all(is_recursively_primitive_type), _ => false, } @@ -269,11 +280,7 @@ pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool { /// removed. pub fn peel_mid_ty_refs(ty: Ty<'_>) -> (Ty<'_>, usize) { fn peel(ty: Ty<'_>, count: usize) -> (Ty<'_>, usize) { - if let ty::Ref(_, ty, _) = ty.kind() { - peel(ty, count + 1) - } else { - (ty, count) - } + if let ty::Ref(_, ty, _) = ty.kind() { peel(ty, count + 1) } else { (ty, count) } } peel(ty, 0) } @@ -328,17 +335,18 @@ pub fn same_type_and_consts(a: Ty<'tcx>, b: Ty<'tcx>) -> bool { return false; } - substs_a - .iter() - .zip(substs_b.iter()) - .all(|(arg_a, arg_b)| match (arg_a.unpack(), arg_b.unpack()) { - (GenericArgKind::Const(inner_a), GenericArgKind::Const(inner_b)) => inner_a == inner_b, + substs_a.iter().zip(substs_b.iter()).all(|(arg_a, arg_b)| { + match (arg_a.unpack(), arg_b.unpack()) { + (GenericArgKind::Const(inner_a), GenericArgKind::Const(inner_b)) => { + inner_a == inner_b + } (GenericArgKind::Type(type_a), GenericArgKind::Type(type_b)) => { same_type_and_consts(type_a, type_b) - }, + } _ => true, - }) - }, + } + }) + } _ => a == b, } } From 29140d6c6e26529208cb950a927cbee3bc985369 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sun, 4 Jul 2021 12:50:41 -0400 Subject: [PATCH 0268/1222] revert broken formatting --- clippy_utils/src/ty.rs | 56 +++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index add487593c6d..2808fc35e2a1 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -146,26 +146,22 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { match ty.kind() { ty::Adt(adt, _) => must_use_attr(cx.tcx.get_attrs(adt.did)).is_some(), ty::Foreign(ref did) => must_use_attr(cx.tcx.get_attrs(*did)).is_some(), - ty::Slice(ty) - | ty::Array(ty, _) - | ty::RawPtr(ty::TypeAndMut { ty, .. }) - | ty::Ref(_, ty, _) => { + ty::Slice(ty) | ty::Array(ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) | ty::Ref(_, ty, _) => { // for the Array case we don't need to care for the len == 0 case // because we don't want to lint functions returning empty arrays is_must_use_ty(cx, *ty) - } + }, ty::Tuple(substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { - if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.kind().skip_binder() - { + if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.kind().skip_binder() { if must_use_attr(cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() { return true; } } } false - } + }, ty::Dynamic(binder, _) => { for predicate in binder.iter() { if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() { @@ -175,7 +171,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { } } false - } + }, _ => false, } } @@ -185,11 +181,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { // not succeed /// Checks if `Ty` is normalizable. This function is useful /// to avoid crashes on `layout_of`. -pub fn is_normalizable<'tcx>( - cx: &LateContext<'tcx>, - param_env: ty::ParamEnv<'tcx>, - ty: Ty<'tcx>, -) -> bool { +pub fn is_normalizable<'tcx>(cx: &LateContext<'tcx>, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool { is_normalizable_helper(cx, param_env, ty, &mut FxHashMap::default()) } @@ -209,14 +201,15 @@ fn is_normalizable_helper<'tcx>( if infcx.at(&cause, param_env).normalize(ty).is_ok() { match ty.kind() { ty::Adt(def, substs) => def.variants.iter().all(|variant| { - variant.fields.iter().all(|field| { - is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache) - }) + variant + .fields + .iter() + .all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache)) }), _ => ty.walk().all(|generic_arg| match generic_arg.unpack() { GenericArgKind::Type(inner_ty) if inner_ty != ty => { is_normalizable_helper(cx, param_env, inner_ty, cache) - } + }, _ => true, // if inner_ty == ty, we've already checked it }), } @@ -234,9 +227,7 @@ pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool { match ty.kind() { ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => true, ty::Ref(_, inner, _) if *inner.kind() == ty::Str => true, - ty::Array(inner_type, _) | ty::Slice(inner_type) => { - is_recursively_primitive_type(inner_type) - } + ty::Array(inner_type, _) | ty::Slice(inner_type) => is_recursively_primitive_type(inner_type), ty::Tuple(inner_types) => inner_types.types().all(is_recursively_primitive_type), _ => false, } @@ -280,7 +271,11 @@ pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool { /// removed. pub fn peel_mid_ty_refs(ty: Ty<'_>) -> (Ty<'_>, usize) { fn peel(ty: Ty<'_>, count: usize) -> (Ty<'_>, usize) { - if let ty::Ref(_, ty, _) = ty.kind() { peel(ty, count + 1) } else { (ty, count) } + if let ty::Ref(_, ty, _) = ty.kind() { + peel(ty, count + 1) + } else { + (ty, count) + } } peel(ty, 0) } @@ -335,18 +330,17 @@ pub fn same_type_and_consts(a: Ty<'tcx>, b: Ty<'tcx>) -> bool { return false; } - substs_a.iter().zip(substs_b.iter()).all(|(arg_a, arg_b)| { - match (arg_a.unpack(), arg_b.unpack()) { - (GenericArgKind::Const(inner_a), GenericArgKind::Const(inner_b)) => { - inner_a == inner_b - } + substs_a + .iter() + .zip(substs_b.iter()) + .all(|(arg_a, arg_b)| match (arg_a.unpack(), arg_b.unpack()) { + (GenericArgKind::Const(inner_a), GenericArgKind::Const(inner_b)) => inner_a == inner_b, (GenericArgKind::Type(type_a), GenericArgKind::Type(type_b)) => { same_type_and_consts(type_a, type_b) - } + }, _ => true, - } - }) - } + }) + }, _ => a == b, } } From 2a7eb5c856bf3dd106cbd10d1a4f06d2c26bc537 Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Tue, 29 Jun 2021 20:33:31 +0200 Subject: [PATCH 0269/1222] Add s to non_fmt_panic --- CHANGELOG.md | 2 +- clippy_lints/src/lib.rs | 2 +- tests/ui/assertions_on_constants.rs | 2 +- tests/ui/deprecated.stderr | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3a807032387..421614057c57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -592,7 +592,7 @@ Released 2021-02-11 * Previously deprecated [`str_to_string`] and [`string_to_string`] have been un-deprecated as `restriction` lints [#6333](https://github.com/rust-lang/rust-clippy/pull/6333) -* Deprecate `panic_params` lint. This is now available in rustc as `non_fmt_panic` +* Deprecate `panic_params` lint. This is now available in rustc as `non_fmt_panics` [#6351](https://github.com/rust-lang/rust-clippy/pull/6351) * Move [`map_err_ignore`] to `restriction` [#6416](https://github.com/rust-lang/rust-clippy/pull/6416) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index e0325738466b..c29b3e7c74c2 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -2171,7 +2171,7 @@ pub fn register_renamed(ls: &mut rustc_lint::LintStore) { ls.register_renamed("clippy::unused_label", "unused_labels"); ls.register_renamed("clippy::drop_bounds", "drop_bounds"); ls.register_renamed("clippy::temporary_cstring_as_ptr", "temporary_cstring_as_ptr"); - ls.register_renamed("clippy::panic_params", "non_fmt_panic"); + ls.register_renamed("clippy::panic_params", "non_fmt_panics"); ls.register_renamed("clippy::unknown_clippy_lints", "unknown_lints"); } diff --git a/tests/ui/assertions_on_constants.rs b/tests/ui/assertions_on_constants.rs index 6617ca183a8c..2180f848d62c 100644 --- a/tests/ui/assertions_on_constants.rs +++ b/tests/ui/assertions_on_constants.rs @@ -1,4 +1,4 @@ -#![allow(non_fmt_panic)] +#![allow(non_fmt_panics)] macro_rules! assert_const { ($len:expr) => { diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr index 0af6b500115d..c0002e535431 100644 --- a/tests/ui/deprecated.stderr +++ b/tests/ui/deprecated.stderr @@ -60,11 +60,11 @@ error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cs LL | #[warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` -error: lint `clippy::panic_params` has been renamed to `non_fmt_panic` +error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` --> $DIR/deprecated.rs:11:8 | LL | #[warn(clippy::panic_params)] - | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panic` + | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` --> $DIR/deprecated.rs:12:8 From 41c56a1c2e9996a7600e92f58d57aa6f302a29b3 Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Tue, 6 Jul 2021 05:38:15 -0400 Subject: [PATCH 0270/1222] Make type_implements_trait not a query --- clippy_utils/src/ty.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 2808fc35e2a1..8857e77d8983 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -15,6 +15,7 @@ use rustc_span::sym; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::DUMMY_SP; use rustc_trait_selection::traits::query::normalize::AtExt; +use rustc_trait_selection::infer::InferCtxtExt; use crate::{match_def_path, must_use_attr}; @@ -112,6 +113,7 @@ pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option< } /// Checks whether a type implements a trait. +/// The function returns false in case the type contains an inference variable. /// See also `get_trait_def_id`. pub fn implements_trait<'tcx>( cx: &LateContext<'tcx>, @@ -119,18 +121,18 @@ pub fn implements_trait<'tcx>( trait_id: DefId, ty_params: &[GenericArg<'tcx>], ) -> bool { - // Do not check on infer_types to avoid panic in evaluate_obligation. - if ty.has_infer_types() { - return false; - } + // Clippy shouldn't have infer types + assert!(!ty.needs_infer()); + let ty = cx.tcx.erase_regions(ty); if ty.has_escaping_bound_vars() { return false; } let ty_params = cx.tcx.mk_substs(ty_params.iter()); - cx.tcx - .type_implements_trait((trait_id, ty, ty_params, cx.param_env)) + cx.tcx.infer_ctxt().enter(|infcx| + infcx.type_implements_trait(trait_id, ty, ty_params, cx.param_env) .must_apply_modulo_regions() + ) } /// Checks whether this type implements `Drop`. From 98010c956c76a04fb1cecdbc6aa4278d4d2e141c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 5 May 2021 21:31:25 +0200 Subject: [PATCH 0271/1222] Rework SESSION_GLOBALS API to prevent overwriting it --- clippy_lints/src/doc.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 4e164d33a051..d6e3e92fc5eb 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -26,6 +26,7 @@ use rustc_span::source_map::{BytePos, FilePathMapping, MultiSpan, SourceMap, Spa use rustc_span::{sym, FileName, Pos}; use std::io; use std::ops::Range; +use std::thread; use url::Url; declare_clippy_lint! { @@ -584,10 +585,10 @@ fn get_current_span(spans: &[(usize, Span)], idx: usize) -> (usize, Span) { } fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { - fn has_needless_main(code: &str, edition: Edition) -> bool { + fn has_needless_main(code: String, edition: Edition) -> bool { rustc_driver::catch_fatal_errors(|| { - rustc_span::with_session_globals(edition, || { - let filename = FileName::anon_source_code(code); + rustc_span::create_session_globals_then(edition, || { + let filename = FileName::anon_source_code(&code); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let emitter = EmitterWriter::new(box io::sink(), None, false, false, false, None, false); @@ -649,7 +650,10 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { .unwrap_or_default() } - if has_needless_main(text, edition) { + // 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") { span_lint(cx, NEEDLESS_DOCTEST_MAIN, span, "needless `fn main` in doctest"); } } From bf5fbaddef98e5baaf086c2b8c668d609fd21797 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Thu, 8 Jul 2021 12:59:16 -0500 Subject: [PATCH 0272/1222] clippy: allow default_hash_types on bootstrap --- clippy_lints/src/implicit_hasher.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 03fe0d16d480..9a040ca572af 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -1,4 +1,4 @@ -#![allow(rustc::default_hash_types)] +#![cfg_attr(bootstrap, allow(rustc::default_hash_types))] use std::borrow::Cow; use std::collections::BTreeMap; From 3f332749bf1028ca55b38026ef3794fe40115b61 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 10 Jul 2021 22:14:52 +0300 Subject: [PATCH 0273/1222] rustc_span: Revert addition of `proc_macro` field to `ExpnKind::Macro` The flag has a vague meaning and is used for a single diagnostic change that is low benefit and appears only under `-Z macro_backtrace`. --- clippy_lints/src/misc.rs | 9 +-------- clippy_lints/src/unit_types/unit_cmp.rs | 7 +------ clippy_utils/src/lib.rs | 14 ++------------ 3 files changed, 4 insertions(+), 26 deletions(-) diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 804c04fe1b83..7cfce2e61cca 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -662,14 +662,7 @@ fn in_attributes_expansion(expr: &Expr<'_>) -> bool { use rustc_span::hygiene::MacroKind; if expr.span.from_expansion() { let data = expr.span.ctxt().outer_expn_data(); - matches!( - data.kind, - ExpnKind::Macro { - kind: MacroKind::Attr, - name: _, - proc_macro: _ - } - ) + matches!(data.kind, ExpnKind::Macro(MacroKind::Attr, _)) } else { false } diff --git a/clippy_lints/src/unit_types/unit_cmp.rs b/clippy_lints/src/unit_types/unit_cmp.rs index 045421465168..85257f3113cb 100644 --- a/clippy_lints/src/unit_types/unit_cmp.rs +++ b/clippy_lints/src/unit_types/unit_cmp.rs @@ -8,12 +8,7 @@ use super::UNIT_CMP; pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { if expr.span.from_expansion() { if let Some(callee) = expr.span.source_callee() { - if let ExpnKind::Macro { - kind: MacroKind::Bang, - name: symbol, - proc_macro: _, - } = callee.kind - { + if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind { if let ExprKind::Binary(ref cmp, left, _) = expr.kind { let op = cmp.node; if op.is_comparison() && cx.typeck_results().expr_ty(left).is_unit() { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 217a1f4dded5..2f10472180f5 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -953,12 +953,7 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option { let data = span.ctxt().outer_expn_data(); let new_span = data.call_site; - if let ExpnKind::Macro { - kind: MacroKind::Bang, - name: mac_name, - proc_macro: _, - } = data.kind - { + if let ExpnKind::Macro(MacroKind::Bang, mac_name) = data.kind { if mac_name.as_str() == name { return Some(new_span); } @@ -986,12 +981,7 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option { let data = span.ctxt().outer_expn_data(); let new_span = data.call_site; - if let ExpnKind::Macro { - kind: MacroKind::Bang, - name: mac_name, - proc_macro: _, - } = data.kind - { + if let ExpnKind::Macro(MacroKind::Bang, mac_name) = data.kind { if mac_name.as_str() == name { return Some(new_span); } From c4ced6c896a3833a6c80e2e339f7a9c9aa3e5085 Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Wed, 14 Jul 2021 02:21:08 -0400 Subject: [PATCH 0274/1222] ExprUseVisitor::Delegate consume only when moving --- clippy_lints/src/escape.rs | 9 +++------ clippy_lints/src/loops/mut_range_bound.rs | 4 ++-- clippy_lints/src/needless_pass_by_value.rs | 6 ++---- clippy_utils/src/usage.rs | 4 ++-- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 3581ab41906f..5f400d079da2 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -11,7 +11,7 @@ use rustc_span::source_map::Span; use rustc_span::symbol::kw; use rustc_target::abi::LayoutOf; use rustc_target::spec::abi::Abi; -use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; +use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; #[derive(Copy, Clone)] pub struct BoxedLocal { @@ -133,13 +133,10 @@ fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool { } impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { - fn consume(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, mode: ConsumeMode) { + fn consume(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) { if cmt.place.projections.is_empty() { if let PlaceBase::Local(lid) = cmt.place.base { - if let ConsumeMode::Move = mode { - // moved out or in. clearly can't be localized - self.set.remove(&lid); - } + self.set.remove(&lid); let map = &self.cx.tcx.hir(); if let Some(Node::Binding(_)) = map.find(cmt.hir_id) { if self.set.contains(&lid) { diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index d07b5a93b67c..1e54a1e2de16 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -7,7 +7,7 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::{mir::FakeReadCause, ty}; use rustc_span::source_map::Span; -use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; +use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>, body: &Expr<'_>) { if let Some(higher::Range { @@ -82,7 +82,7 @@ struct MutatePairDelegate<'a, 'tcx> { } impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> { - fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId, _: ConsumeMode) {} + fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {} fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: ty::BorrowKind) { if let ty::BorrowKind::MutBorrow = bk { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index e33a33e23863..57fd03f4e12a 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -326,10 +326,8 @@ impl MovedVariablesCtxt { } impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt { - fn consume(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, _: HirId, mode: euv::ConsumeMode) { - if let euv::ConsumeMode::Move = mode { - self.move_common(cmt); - } + fn consume(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, _: HirId) { + self.move_common(cmt); } fn borrow(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {} diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index 2c55021ac883..82e4b3000680 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -10,7 +10,7 @@ use rustc_lint::LateContext; use rustc_middle::hir::map::Map; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty; -use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; +use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; /// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined. pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) -> Option { @@ -67,7 +67,7 @@ impl<'tcx> MutVarsDelegate { } impl<'tcx> Delegate<'tcx> for MutVarsDelegate { - fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId, _: ConsumeMode) {} + fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {} fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, bk: ty::BorrowKind) { if let ty::BorrowKind::MutBorrow = bk { From aeb3bb73645c62af311858c0251c7150a30df838 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Wed, 14 Jul 2021 16:17:04 -0500 Subject: [PATCH 0275/1222] Remove refs from pat slices --- clippy_lints/src/manual_unwrap_or.rs | 4 ++-- clippy_lints/src/matches.rs | 2 +- clippy_lints/src/option_if_let_else.rs | 2 +- clippy_lints/src/pattern_type_mismatch.rs | 2 +- clippy_utils/src/lib.rs | 18 +++++++++--------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/manual_unwrap_or.rs b/clippy_lints/src/manual_unwrap_or.rs index 18038dd78194..9d8d77cf8f08 100644 --- a/clippy_lints/src/manual_unwrap_or.rs +++ b/clippy_lints/src/manual_unwrap_or.rs @@ -61,13 +61,13 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if let Some((idx, or_arm)) = arms.iter().enumerate().find(|(_, arm)| { match arm.pat.kind { PatKind::Path(ref qpath) => is_lang_ctor(cx, qpath, OptionNone), - PatKind::TupleStruct(ref qpath, &[pat], _) => + PatKind::TupleStruct(ref qpath, [pat], _) => matches!(pat.kind, PatKind::Wild) && is_lang_ctor(cx, qpath, ResultErr), _ => false, } }); let unwrap_arm = &arms[1 - idx]; - if let PatKind::TupleStruct(ref qpath, &[unwrap_pat], _) = unwrap_arm.pat.kind; + if let PatKind::TupleStruct(ref qpath, [unwrap_pat], _) = unwrap_arm.pat.kind; if is_lang_ctor(cx, qpath, OptionSome) || is_lang_ctor(cx, qpath, ResultOk); if let PatKind::Binding(_, binding_hir_id, ..) = unwrap_pat.kind; if path_to_local_id(unwrap_arm.body, binding_hir_id); diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 986469a2b698..6d5ce3373f79 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -625,7 +625,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches { if let PatKind::TupleStruct( QPath::Resolved(None, variant_name), args, _) = arms[0].pat.kind; if args.len() == 1; - if let PatKind::Binding(_, arg, ..) = strip_pat_refs(args[0]).kind; + if let PatKind::Binding(_, arg, ..) = strip_pat_refs(&args[0]).kind; let body = remove_blocks(arms[0].body); if path_to_local_id(body, arg); diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index b6af4175edfd..b2be35bdddb3 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -132,7 +132,7 @@ fn detect_option_if_let_else<'tcx>( if !is_else_clause(cx.tcx, expr); if arms.len() == 2; if !is_result_ok(cx, cond_expr); // Don't lint on Result::ok because a different lint does it already - if let PatKind::TupleStruct(struct_qpath, &[inner_pat], _) = &arms[0].pat.kind; + if let PatKind::TupleStruct(struct_qpath, [inner_pat], _) = &arms[0].pat.kind; if is_lang_ctor(cx, struct_qpath, OptionSome); if let PatKind::Binding(bind_annotation, _, id, _) = &inner_pat.kind; if !contains_return_break_continue_macro(arms[0].body); diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index 9bab783998aa..ea4065d371b8 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -258,7 +258,7 @@ fn get_variant<'a>(adt_def: &'a AdtDef, qpath: &QPath<'_>) -> Option<&'a Variant fn find_first_mismatch_in_tuple<'tcx, I>( cx: &LateContext<'tcx>, - pats: &[&Pat<'_>], + pats: &[Pat<'_>], ty_iter_src: I, ) -> Option<(Span, Mutability, Level)> where diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 6db221ab0fdf..4f0a9f442ed9 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -255,7 +255,7 @@ pub fn in_macro(span: Span) -> bool { } /// Checks if given pattern is a wildcard (`_`) -pub fn is_wild<'tcx>(pat: &impl std::ops::Deref>) -> bool { +pub fn is_wild(pat: &Pat<'_>) -> bool { matches!(pat.kind, PatKind::Wild) } @@ -1023,8 +1023,8 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { ) } - fn are_refutable<'a, I: Iterator>>(cx: &LateContext<'_>, mut i: I) -> bool { - i.any(|pat| is_refutable(cx, pat)) + fn are_refutable<'a, I: IntoIterator>>(cx: &LateContext<'_>, i: I) -> bool { + i.into_iter().any(|pat| is_refutable(cx, pat)) } match pat.kind { @@ -1035,23 +1035,23 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { PatKind::Path(ref qpath) => is_enum_variant(cx, qpath, pat.hir_id), PatKind::Or(pats) => { // TODO: should be the honest check, that pats is exhaustive set - are_refutable(cx, pats.iter().map(|pat| &**pat)) + are_refutable(cx, pats) }, - PatKind::Tuple(pats, _) => are_refutable(cx, pats.iter().map(|pat| &**pat)), + PatKind::Tuple(pats, _) => are_refutable(cx, pats), PatKind::Struct(ref qpath, fields, _) => { is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, fields.iter().map(|field| &*field.pat)) }, PatKind::TupleStruct(ref qpath, pats, _) => { - is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, pats.iter().map(|pat| &**pat)) + is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, pats) }, - PatKind::Slice(head, ref middle, tail) => { + PatKind::Slice(head, middle, tail) => { match &cx.typeck_results().node_type(pat.hir_id).kind() { rustc_ty::Slice(..) => { // [..] is the only irrefutable slice pattern. !head.is_empty() || middle.is_none() || !tail.is_empty() }, rustc_ty::Array(..) => { - are_refutable(cx, head.iter().chain(middle).chain(tail.iter()).map(|pat| &**pat)) + are_refutable(cx, head.iter().chain(middle).chain(tail.iter())) }, _ => { // unreachable!() @@ -1066,7 +1066,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { /// the function once on the given pattern. pub fn recurse_or_patterns<'tcx, F: FnMut(&'tcx Pat<'tcx>)>(pat: &'tcx Pat<'tcx>, mut f: F) { if let PatKind::Or(pats) = pat.kind { - pats.iter().copied().for_each(f); + pats.iter().for_each(f); } else { f(pat); } From b6d29dd3117d62f9a0de6bd2cfac312c550382b0 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 18 Jul 2021 07:57:03 -0700 Subject: [PATCH 0276/1222] fix(clippy): add missing allow(dyn_drop) --- tests/ui/needless_lifetimes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/needless_lifetimes.rs b/tests/ui/needless_lifetimes.rs index bda0801e51c7..1d77382bf2cd 100644 --- a/tests/ui/needless_lifetimes.rs +++ b/tests/ui/needless_lifetimes.rs @@ -1,5 +1,5 @@ #![warn(clippy::needless_lifetimes)] -#![allow(dead_code, clippy::needless_pass_by_value, clippy::unnecessary_wraps)] +#![allow(dead_code, clippy::needless_pass_by_value, clippy::unnecessary_wraps, dyn_drop)] fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {} From 8f2228d07c43c26b1281d0056890dab87998a4de Mon Sep 17 00:00:00 2001 From: chaz-kiker Date: Fri, 23 Jul 2021 12:30:52 -0500 Subject: [PATCH 0277/1222] update clippy ui test 'future_not_send.stderr' to match the new diagnostic messages --- tests/ui/future_not_send.stderr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/future_not_send.stderr b/tests/ui/future_not_send.stderr index b59dbb3e76c6..c734051ccf32 100644 --- a/tests/ui/future_not_send.stderr +++ b/tests/ui/future_not_send.stderr @@ -55,11 +55,11 @@ note: captured value is not `Send` LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { | ^^ has type `std::rc::Rc<[u8]>` which is not `Send` = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` -note: captured value is not `Send` +note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` --> $DIR/future_not_send.rs:20:40 | LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { - | ^^^^ has type `&std::cell::Cell` which is not `Send` + | ^^^^ has type `&std::cell::Cell` which is not `Send`, because `std::cell::Cell` is not `Sync` = note: `std::cell::Cell` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely From 06e8c1b4328fa2ce66121e0a4ef51d632249fad4 Mon Sep 17 00:00:00 2001 From: kadmin Date: Sat, 24 Apr 2021 21:41:57 +0000 Subject: [PATCH 0278/1222] Add generic arg infer --- clippy_utils/src/hir_utils.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index a21ad42c0617..63737955f09b 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -885,7 +885,15 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { pub fn hash_ty(&mut self, ty: &Ty<'_>) { std::mem::discriminant(&ty.kind).hash(&mut self.s); - match ty.kind { + self.hash_tykind(&ty.kind); + } + + pub fn hash_infer(&mut self) { + "_".hash(&mut self.s); + } + + pub fn hash_tykind(&mut self, ty: &TyKind<'_>) { + match ty { TyKind::Slice(ty) => { self.hash_ty(ty); }, @@ -949,6 +957,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { GenericArg::Lifetime(l) => self.hash_lifetime(l), GenericArg::Type(ref ty) => self.hash_ty(ty), GenericArg::Const(ref ca) => self.hash_body(ca.value.body), + GenericArg::Infer(ref _inf) => self.hash_infer(), } } } From 612228aca58a517d951394e5158f7d58c6fb975a Mon Sep 17 00:00:00 2001 From: kadmin Date: Mon, 26 Apr 2021 18:19:23 +0000 Subject: [PATCH 0279/1222] Add inferred args to typeck --- clippy_lints/src/implicit_hasher.rs | 10 +++- clippy_lints/src/types/type_complexity.rs | 7 ++- clippy_lints/src/use_self.rs | 56 ++++++++++++++++++++++- clippy_utils/src/hir_utils.rs | 8 ++-- clippy_utils/src/ty.rs | 2 +- tests/ui/transmute_ptr_to_ref.stderr | 4 +- 6 files changed, 75 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 9a040ca572af..ad4898d1ccbb 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -5,7 +5,7 @@ use std::collections::BTreeMap; use rustc_errors::DiagnosticBuilder; use rustc_hir as hir; -use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, walk_inf, NestedVisitorMap, Visitor}; use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::hir::map::Map; @@ -295,6 +295,14 @@ impl<'a, 'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> { walk_ty(self, t); } + fn visit_infer(&mut self, inf: &'tcx hir::InferArg) { + if let Some(target) = ImplicitHasherType::new(self.cx, &inf.to_ty()) { + self.found.push(target); + } + + walk_inf(self, inf); + } + fn nested_visit_map(&mut self) -> NestedVisitorMap { NestedVisitorMap::None } diff --git a/clippy_lints/src/types/type_complexity.rs b/clippy_lints/src/types/type_complexity.rs index d8c4b67520d1..b438d680d2cb 100644 --- a/clippy_lints/src/types/type_complexity.rs +++ b/clippy_lints/src/types/type_complexity.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint; use rustc_hir as hir; -use rustc_hir::intravisit::{walk_ty, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_ty, walk_inf, NestedVisitorMap, Visitor}; use rustc_hir::{GenericParamKind, TyKind}; use rustc_lint::LateContext; use rustc_middle::hir::map::Map; @@ -39,6 +39,11 @@ struct TypeComplexityVisitor { impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor { type Map = Map<'tcx>; + fn visit_infer(&mut self, inf: &'tcx hir::InferArg) { + self.score += 1; + walk_inf(self, inf); + } + fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) { let (add_score, sub_nest) = match ty.kind { // _, &x and *x have only small overhead; don't mess with nesting level diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 71117e967e31..c8cdf1a5d2c9 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -8,8 +8,9 @@ use rustc_hir::{ self as hir, def::{CtorOf, DefKind, Res}, def_id::LocalDefId, - intravisit::{walk_ty, NestedVisitorMap, Visitor}, - Expr, ExprKind, FnRetTy, FnSig, GenericArg, HirId, Impl, ImplItemKind, Item, ItemKind, Path, QPath, TyKind, + intravisit::{walk_ty, walk_inf, NestedVisitorMap, Visitor}, + Expr, ExprKind, FnRetTy, FnSig, GenericArg, HirId, Impl, ImplItemKind, Item, ItemKind, Node, Path, PathSegment, + QPath, TyKind, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::hir::map::Map; @@ -263,6 +264,11 @@ struct SkipTyCollector { impl<'tcx> Visitor<'tcx> for SkipTyCollector { type Map = Map<'tcx>; + fn visit_infer(&mut self, inf: &hir::InferArg) { + self.types_to_skip.push(inf.hir_id); + + walk_inf(self, inf) + } fn visit_ty(&mut self, hir_ty: &hir::Ty<'_>) { self.types_to_skip.push(hir_ty.hir_id); @@ -274,6 +280,52 @@ impl<'tcx> Visitor<'tcx> for SkipTyCollector { } } +<<<<<<< HEAD +======= +struct LintTyCollector<'a, 'tcx> { + cx: &'a LateContext<'tcx>, + self_ty: Ty<'tcx>, + types_to_lint: Vec, + types_to_skip: Vec, +} + +impl<'a, 'tcx> Visitor<'tcx> for LintTyCollector<'a, 'tcx> { + type Map = Map<'tcx>; + + fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'_>) { + if_chain! { + if let Some(ty) = self.cx.typeck_results().node_type_opt(hir_ty.hir_id); + if should_lint_ty(hir_ty, ty, self.self_ty); + then { + self.types_to_lint.push(hir_ty.hir_id); + } else { + self.types_to_skip.push(hir_ty.hir_id); + } + } + + walk_ty(self, hir_ty); + } + + fn visit_infer(&mut self, inf: &'tcx hir::InferArg) { + if_chain! { + if let Some(ty) = self.cx.typeck_results().node_type_opt(inf.hir_id); + if should_lint_ty(&inf.to_ty(), ty, self.self_ty); + then { + self.types_to_lint.push(inf.hir_id); + } else { + self.types_to_skip.push(inf.hir_id); + } + } + + walk_inf(self, inf) + } + + fn nested_visit_map(&mut self) -> NestedVisitorMap { + NestedVisitorMap::None + } +} + +>>>>>>> Add inferred args to typeck fn span_lint(cx: &LateContext<'_>, span: Span) { span_lint_and_sugg( cx, diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 63737955f09b..e636038b6e1a 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -288,6 +288,8 @@ impl HirEqInterExpr<'_, '_, '_> { (GenericArg::Const(l), GenericArg::Const(r)) => self.eq_body(l.value.body, r.value.body), (GenericArg::Lifetime(l_lt), GenericArg::Lifetime(r_lt)) => Self::eq_lifetime(l_lt, r_lt), (GenericArg::Type(l_ty), GenericArg::Type(r_ty)) => self.eq_ty(l_ty, r_ty), + (GenericArg::Infer(l_inf), GenericArg::Infer(r_inf)) => + self.eq_ty(&l_inf.to_ty(), &r_inf.to_ty()), _ => false, } } @@ -888,10 +890,6 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_tykind(&ty.kind); } - pub fn hash_infer(&mut self) { - "_".hash(&mut self.s); - } - pub fn hash_tykind(&mut self, ty: &TyKind<'_>) { match ty { TyKind::Slice(ty) => { @@ -957,7 +955,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { GenericArg::Lifetime(l) => self.hash_lifetime(l), GenericArg::Type(ref ty) => self.hash_ty(ty), GenericArg::Const(ref ca) => self.hash_body(ca.value.body), - GenericArg::Infer(ref _inf) => self.hash_infer(), + GenericArg::Infer(ref inf) => self.hash_ty(&inf.to_ty()), } } } diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 523d55219ab6..e914dc1c222f 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -180,7 +180,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { } // FIXME: Per https://doc.rust-lang.org/nightly/nightly-rustc/rustc_trait_selection/infer/at/struct.At.html#method.normalize -// this function can be removed once the `normalizie` method does not panic when normalization does +// this function can be removed once the `normalize` method does not panic when normalization does // not succeed /// Checks if `Ty` is normalizable. This function is useful /// to avoid crashes on `layout_of`. diff --git a/tests/ui/transmute_ptr_to_ref.stderr b/tests/ui/transmute_ptr_to_ref.stderr index df0598a58cd3..54ab04f8c5d3 100644 --- a/tests/ui/transmute_ptr_to_ref.stderr +++ b/tests/ui/transmute_ptr_to_ref.stderr @@ -46,13 +46,13 @@ error: transmute from a pointer type (`*const i32`) to a reference type (`&issue --> $DIR/transmute_ptr_to_ref.rs:32:32 | LL | let _: &Foo = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const Foo<_>)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const issue1231::Foo)` error: transmute from a pointer type (`*const i32`) to a reference type (`&issue1231::Foo<&u8>`) --> $DIR/transmute_ptr_to_ref.rs:34:33 | LL | let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const Foo<&_>)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const issue1231::Foo<&u8>)` error: transmute from a pointer type (`*const i32`) to a reference type (`&u8`) --> $DIR/transmute_ptr_to_ref.rs:38:14 From c452574f0403574220cdb3d1b1237a4ba4e0c349 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 25 Jul 2021 12:03:24 +0200 Subject: [PATCH 0280/1222] Introduce OwnerNode::Crate. --- clippy_lints/src/missing_doc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index a46a7407df0c..6ad702f8eafd 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -106,7 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) { let attrs = cx.tcx.hir().attrs(hir::CRATE_HIR_ID); - self.check_missing_docs_attrs(cx, attrs, krate.item.inner, "the", "crate"); + self.check_missing_docs_attrs(cx, attrs, krate.module().inner, "the", "crate"); } fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) { From e69886526b280c85615001cc957e3567bfe7ca25 Mon Sep 17 00:00:00 2001 From: kadmin Date: Thu, 6 May 2021 15:33:44 +0000 Subject: [PATCH 0281/1222] Actually infer args in visitors --- clippy_lints/src/use_self.rs | 48 +--------------------------- clippy_utils/src/hir_utils.rs | 6 ++-- tests/ui/transmute_ptr_to_ref.stderr | 4 +-- 3 files changed, 6 insertions(+), 52 deletions(-) diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index c8cdf1a5d2c9..d5ee717accd2 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -9,7 +9,7 @@ use rustc_hir::{ def::{CtorOf, DefKind, Res}, def_id::LocalDefId, intravisit::{walk_ty, walk_inf, NestedVisitorMap, Visitor}, - Expr, ExprKind, FnRetTy, FnSig, GenericArg, HirId, Impl, ImplItemKind, Item, ItemKind, Node, Path, PathSegment, + Expr, ExprKind, FnRetTy, FnSig, GenericArg, HirId, Impl, ImplItemKind, Item, ItemKind, Path, QPath, TyKind, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; @@ -280,52 +280,6 @@ impl<'tcx> Visitor<'tcx> for SkipTyCollector { } } -<<<<<<< HEAD -======= -struct LintTyCollector<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - self_ty: Ty<'tcx>, - types_to_lint: Vec, - types_to_skip: Vec, -} - -impl<'a, 'tcx> Visitor<'tcx> for LintTyCollector<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'_>) { - if_chain! { - if let Some(ty) = self.cx.typeck_results().node_type_opt(hir_ty.hir_id); - if should_lint_ty(hir_ty, ty, self.self_ty); - then { - self.types_to_lint.push(hir_ty.hir_id); - } else { - self.types_to_skip.push(hir_ty.hir_id); - } - } - - walk_ty(self, hir_ty); - } - - fn visit_infer(&mut self, inf: &'tcx hir::InferArg) { - if_chain! { - if let Some(ty) = self.cx.typeck_results().node_type_opt(inf.hir_id); - if should_lint_ty(&inf.to_ty(), ty, self.self_ty); - then { - self.types_to_lint.push(inf.hir_id); - } else { - self.types_to_skip.push(inf.hir_id); - } - } - - walk_inf(self, inf) - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } -} - ->>>>>>> Add inferred args to typeck fn span_lint(cx: &LateContext<'_>, span: Span) { span_lint_and_sugg( cx, diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index e636038b6e1a..6ea360a88a63 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -904,7 +904,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { mut_ty.mutbl.hash(&mut self.s); }, TyKind::Rptr(lifetime, ref mut_ty) => { - self.hash_lifetime(lifetime); + self.hash_lifetime(*lifetime); self.hash_ty(mut_ty.ty); mut_ty.mutbl.hash(&mut self.s); }, @@ -924,7 +924,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { bfn.decl.c_variadic.hash(&mut self.s); }, TyKind::Tup(ty_list) => { - for ty in ty_list { + for ty in *ty_list { self.hash_ty(ty); } }, @@ -933,7 +933,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_generic_args(arg_list); }, TyKind::TraitObject(_, lifetime, _) => { - self.hash_lifetime(lifetime); + self.hash_lifetime(*lifetime); }, TyKind::Typeof(anon_const) => { self.hash_body(anon_const.body); diff --git a/tests/ui/transmute_ptr_to_ref.stderr b/tests/ui/transmute_ptr_to_ref.stderr index 54ab04f8c5d3..df0598a58cd3 100644 --- a/tests/ui/transmute_ptr_to_ref.stderr +++ b/tests/ui/transmute_ptr_to_ref.stderr @@ -46,13 +46,13 @@ error: transmute from a pointer type (`*const i32`) to a reference type (`&issue --> $DIR/transmute_ptr_to_ref.rs:32:32 | LL | let _: &Foo = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const issue1231::Foo)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const Foo<_>)` error: transmute from a pointer type (`*const i32`) to a reference type (`&issue1231::Foo<&u8>`) --> $DIR/transmute_ptr_to_ref.rs:34:33 | LL | let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const issue1231::Foo<&u8>)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const Foo<&_>)` error: transmute from a pointer type (`*const i32`) to a reference type (`&u8`) --> $DIR/transmute_ptr_to_ref.rs:38:14 From a815155aa16a3dcc3a6cd9aac84cd52cdd972e86 Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Thu, 3 Jun 2021 03:31:27 -0400 Subject: [PATCH 0282/1222] Update tests --- tests/ui/transmute.rs | 1 - tests/ui/transmute.stderr | 48 +++++++++++++------------- tests/ui/transmute_float_to_int.rs | 1 - tests/ui/transmute_float_to_int.stderr | 12 +++---- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/tests/ui/transmute.rs b/tests/ui/transmute.rs index 9f1948359e7d..bce4c81b78aa 100644 --- a/tests/ui/transmute.rs +++ b/tests/ui/transmute.rs @@ -1,4 +1,3 @@ -#![feature(const_fn_transmute)] #![allow(dead_code)] extern crate core; diff --git a/tests/ui/transmute.stderr b/tests/ui/transmute.stderr index ad9953d12bcc..e31accb982af 100644 --- a/tests/ui/transmute.stderr +++ b/tests/ui/transmute.stderr @@ -1,5 +1,5 @@ error: transmute from a type (`&T`) to itself - --> $DIR/transmute.rs:20:20 + --> $DIR/transmute.rs:19:20 | LL | let _: &'a T = core::intrinsics::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,67 +7,67 @@ LL | let _: &'a T = core::intrinsics::transmute(t); = note: `-D clippy::useless-transmute` implied by `-D warnings` error: transmute from a reference to a pointer - --> $DIR/transmute.rs:24:23 + --> $DIR/transmute.rs:23:23 | LL | let _: *const T = core::intrinsics::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T` error: transmute from a reference to a pointer - --> $DIR/transmute.rs:26:21 + --> $DIR/transmute.rs:25:21 | LL | let _: *mut T = core::intrinsics::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *mut T` error: transmute from a reference to a pointer - --> $DIR/transmute.rs:28:23 + --> $DIR/transmute.rs:27:23 | LL | let _: *const U = core::intrinsics::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *const U` error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:34:27 + --> $DIR/transmute.rs:33:27 | LL | let _: Vec = core::intrinsics::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:36:27 + --> $DIR/transmute.rs:35:27 | LL | let _: Vec = core::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:38:27 + --> $DIR/transmute.rs:37:27 | LL | let _: Vec = std::intrinsics::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:40:27 + --> $DIR/transmute.rs:39:27 | LL | let _: Vec = std::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:42:27 + --> $DIR/transmute.rs:41:27 | LL | let _: Vec = my_transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^ error: transmute from an integer to a pointer - --> $DIR/transmute.rs:44:31 + --> $DIR/transmute.rs:43:31 | LL | let _: *const usize = std::mem::transmute(5_isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `5_isize as *const usize` error: transmute from an integer to a pointer - --> $DIR/transmute.rs:48:31 + --> $DIR/transmute.rs:47:31 | LL | let _: *const usize = std::mem::transmute(1 + 1usize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(1 + 1usize) as *const usize` error: transmute from a type (`*const Usize`) to the type that it points to (`Usize`) - --> $DIR/transmute.rs:63:24 + --> $DIR/transmute.rs:62:24 | LL | let _: Usize = core::intrinsics::transmute(int_const_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -75,25 +75,25 @@ LL | let _: Usize = core::intrinsics::transmute(int_const_ptr); = note: `-D clippy::crosspointer-transmute` implied by `-D warnings` error: transmute from a type (`*mut Usize`) to the type that it points to (`Usize`) - --> $DIR/transmute.rs:65:24 + --> $DIR/transmute.rs:64:24 | LL | let _: Usize = core::intrinsics::transmute(int_mut_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`Usize`) to a pointer to that type (`*const Usize`) - --> $DIR/transmute.rs:67:31 + --> $DIR/transmute.rs:66:31 | LL | let _: *const Usize = core::intrinsics::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize`) - --> $DIR/transmute.rs:69:29 + --> $DIR/transmute.rs:68:29 | LL | let _: *mut Usize = core::intrinsics::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a `u32` to a `char` - --> $DIR/transmute.rs:75:28 + --> $DIR/transmute.rs:74:28 | LL | let _: char = unsafe { std::mem::transmute(0_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_u32).unwrap()` @@ -101,13 +101,13 @@ LL | let _: char = unsafe { std::mem::transmute(0_u32) }; = note: `-D clippy::transmute-int-to-char` implied by `-D warnings` error: transmute from a `i32` to a `char` - --> $DIR/transmute.rs:76:28 + --> $DIR/transmute.rs:75:28 | LL | let _: char = unsafe { std::mem::transmute(0_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_i32 as u32).unwrap()` error: transmute from a `u8` to a `bool` - --> $DIR/transmute.rs:81:28 + --> $DIR/transmute.rs:80:28 | LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `0_u8 != 0` @@ -115,7 +115,7 @@ LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; = note: `-D clippy::transmute-int-to-bool` implied by `-D warnings` error: transmute from a `u32` to a `f32` - --> $DIR/transmute.rs:87:31 + --> $DIR/transmute.rs:86:31 | LL | let _: f32 = unsafe { std::mem::transmute(0_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_u32)` @@ -123,25 +123,25 @@ LL | let _: f32 = unsafe { std::mem::transmute(0_u32) }; = note: `-D clippy::transmute-int-to-float` implied by `-D warnings` error: transmute from a `i32` to a `f32` - --> $DIR/transmute.rs:88:31 + --> $DIR/transmute.rs:87:31 | LL | let _: f32 = unsafe { std::mem::transmute(0_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_i32 as u32)` error: transmute from a `u64` to a `f64` - --> $DIR/transmute.rs:89:31 + --> $DIR/transmute.rs:88:31 | LL | let _: f64 = unsafe { std::mem::transmute(0_u64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_u64)` error: transmute from a `i64` to a `f64` - --> $DIR/transmute.rs:90:31 + --> $DIR/transmute.rs:89:31 | LL | let _: f64 = unsafe { std::mem::transmute(0_i64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_i64 as u64)` error: transmute from a `&[u8]` to a `&str` - --> $DIR/transmute.rs:108:28 + --> $DIR/transmute.rs:107:28 | LL | let _: &str = unsafe { std::mem::transmute(b) }; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8(b).unwrap()` @@ -149,7 +149,7 @@ LL | let _: &str = unsafe { std::mem::transmute(b) }; = note: `-D clippy::transmute-bytes-to-str` implied by `-D warnings` error: transmute from a `&mut [u8]` to a `&mut str` - --> $DIR/transmute.rs:109:32 + --> $DIR/transmute.rs:108:32 | LL | let _: &mut str = unsafe { std::mem::transmute(mb) }; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_mut(mb).unwrap()` diff --git a/tests/ui/transmute_float_to_int.rs b/tests/ui/transmute_float_to_int.rs index 1040fee4b34d..806b2d77dc77 100644 --- a/tests/ui/transmute_float_to_int.rs +++ b/tests/ui/transmute_float_to_int.rs @@ -1,4 +1,3 @@ -#![feature(const_fn_transmute)] #![warn(clippy::transmute_float_to_int)] fn float_to_int() { diff --git a/tests/ui/transmute_float_to_int.stderr b/tests/ui/transmute_float_to_int.stderr index 5a40cf381d61..eb786bb39f95 100644 --- a/tests/ui/transmute_float_to_int.stderr +++ b/tests/ui/transmute_float_to_int.stderr @@ -1,5 +1,5 @@ error: transmute from a `f32` to a `u32` - --> $DIR/transmute_float_to_int.rs:5:27 + --> $DIR/transmute_float_to_int.rs:4:27 | LL | let _: u32 = unsafe { std::mem::transmute(1f32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits()` @@ -7,31 +7,31 @@ LL | let _: u32 = unsafe { std::mem::transmute(1f32) }; = note: `-D clippy::transmute-float-to-int` implied by `-D warnings` error: transmute from a `f32` to a `i32` - --> $DIR/transmute_float_to_int.rs:6:27 + --> $DIR/transmute_float_to_int.rs:5:27 | LL | let _: i32 = unsafe { std::mem::transmute(1f32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits() as i32` error: transmute from a `f64` to a `u64` - --> $DIR/transmute_float_to_int.rs:7:27 + --> $DIR/transmute_float_to_int.rs:6:27 | LL | let _: u64 = unsafe { std::mem::transmute(1f64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits()` error: transmute from a `f64` to a `i64` - --> $DIR/transmute_float_to_int.rs:8:27 + --> $DIR/transmute_float_to_int.rs:7:27 | LL | let _: i64 = unsafe { std::mem::transmute(1f64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits() as i64` error: transmute from a `f64` to a `u64` - --> $DIR/transmute_float_to_int.rs:9:27 + --> $DIR/transmute_float_to_int.rs:8:27 | LL | let _: u64 = unsafe { std::mem::transmute(1.0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.0f64.to_bits()` error: transmute from a `f64` to a `u64` - --> $DIR/transmute_float_to_int.rs:10:27 + --> $DIR/transmute_float_to_int.rs:9:27 | LL | let _: u64 = unsafe { std::mem::transmute(-1.0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-1.0f64).to_bits()` From e1401679b07430291948fc166a85ea44de668da2 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Thu, 29 Jul 2021 09:52:35 -0500 Subject: [PATCH 0283/1222] Remove unnecessary trailing semicolons from clippy tests --- tests/ui/needless_borrow_pat.rs | 2 +- tests/ui/ref_binding_to_reference.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/needless_borrow_pat.rs b/tests/ui/needless_borrow_pat.rs index f0926220755a..7a8137778b44 100644 --- a/tests/ui/needless_borrow_pat.rs +++ b/tests/ui/needless_borrow_pat.rs @@ -7,7 +7,7 @@ fn f1(_: &str) {} macro_rules! m1 { ($e:expr) => { - f1($e); + f1($e) }; } macro_rules! m3 { diff --git a/tests/ui/ref_binding_to_reference.rs b/tests/ui/ref_binding_to_reference.rs index c7235e1c2210..cd6db8ddc886 100644 --- a/tests/ui/ref_binding_to_reference.rs +++ b/tests/ui/ref_binding_to_reference.rs @@ -7,7 +7,7 @@ fn f1(_: &str) {} macro_rules! m2 { ($e:expr) => { - f1(*$e); + f1(*$e) }; } macro_rules! m3 { From 9961f45da1c18d1ffdf18a8a234d45529db55c36 Mon Sep 17 00:00:00 2001 From: Jade Date: Tue, 27 Jul 2021 16:38:13 -0700 Subject: [PATCH 0284/1222] rfc3052: Remove authors field from Cargo manifests Since RFC 3052 soft deprecated the authors field anyway, hiding it from crates.io, docs.rs, and making Cargo not add it by default, and it is not generally up to date/useful information, we should remove it from crates in this repo. --- Cargo.toml | 1 - clippy_dev/Cargo.toml | 1 - clippy_dummy/Cargo.toml | 1 - clippy_lints/Cargo.toml | 1 - clippy_utils/Cargo.toml | 1 - lintcheck/Cargo.toml | 1 - rustc_tools_util/Cargo.toml | 1 - 7 files changed, 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 82e04c8fb854..16b6c207a5f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "clippy" version = "0.1.56" -authors = ["The Rust Clippy Developers"] description = "A bunch of helpful lints to avoid common pitfalls in Rust" repository = "https://github.com/rust-lang/rust-clippy" readme = "README.md" diff --git a/clippy_dev/Cargo.toml b/clippy_dev/Cargo.toml index 5c6c106e0e63..0fae8c7b9afc 100644 --- a/clippy_dev/Cargo.toml +++ b/clippy_dev/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "clippy_dev" version = "0.0.1" -authors = ["The Rust Clippy Developers"] edition = "2018" [dependencies] diff --git a/clippy_dummy/Cargo.toml b/clippy_dummy/Cargo.toml index 6959de7ffee7..a1707bad5c26 100644 --- a/clippy_dummy/Cargo.toml +++ b/clippy_dummy/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "clippy_dummy" # rename to clippy before publishing version = "0.0.303" -authors = ["The Rust Clippy Developers"] edition = "2018" readme = "crates-readme.md" description = "A bunch of helpful lints to avoid common pitfalls in Rust." diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 0aa5b297442e..a3b92e1faa1a 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -3,7 +3,6 @@ name = "clippy_lints" # begin automatic update version = "0.1.56" # end automatic update -authors = ["The Rust Clippy Developers"] description = "A bunch of helpful lints to avoid common pitfalls in Rust" repository = "https://github.com/rust-lang/rust-clippy" readme = "README.md" diff --git a/clippy_utils/Cargo.toml b/clippy_utils/Cargo.toml index 8bd859c97ada..c65b2958ec56 100644 --- a/clippy_utils/Cargo.toml +++ b/clippy_utils/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "clippy_utils" version = "0.1.56" -authors = ["The Rust Clippy Developers"] edition = "2018" publish = false diff --git a/lintcheck/Cargo.toml b/lintcheck/Cargo.toml index 8db6d28e5aca..8c33fa372ecc 100644 --- a/lintcheck/Cargo.toml +++ b/lintcheck/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "lintcheck" version = "0.0.1" -authors = ["The Rust Clippy Developers"] description = "tool to monitor impact of changes in Clippys lints on a part of the ecosystem" readme = "README.md" license = "MIT OR Apache-2.0" diff --git a/rustc_tools_util/Cargo.toml b/rustc_tools_util/Cargo.toml index 2972bc6d51ca..9554d4d6c003 100644 --- a/rustc_tools_util/Cargo.toml +++ b/rustc_tools_util/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "rustc_tools_util" version = "0.2.0" -authors = ["The Rust Clippy Developers"] description = "small helper to generate version information for git packages" repository = "https://github.com/rust-lang/rust-clippy" readme = "README.md" From e84d56343c48e034f29893237030a7e878dc398f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 28 Jun 2021 11:22:47 -0700 Subject: [PATCH 0285/1222] Use multispan suggestions more often * Use more accurate span for `async move` suggestion * Use more accurate span for deref suggestion * Use `multipart_suggestion` more often --- tests/ui/crashes/ice-6250.stderr | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/ui/crashes/ice-6250.stderr b/tests/ui/crashes/ice-6250.stderr index c38727316cd4..320b3bb42f89 100644 --- a/tests/ui/crashes/ice-6250.stderr +++ b/tests/ui/crashes/ice-6250.stderr @@ -25,10 +25,12 @@ error[E0308]: mismatched types --> $DIR/ice-6250.rs:12:14 | LL | Some(reference) = cache.data.get(key) { - | ^^^^^^^^^ - | | - | expected integer, found `&i32` - | help: consider dereferencing the borrow: `*reference` + | ^^^^^^^^^ expected integer, found `&i32` + | +help: consider dereferencing the borrow + | +LL | Some(*reference) = cache.data.get(key) { + | ^ error[E0308]: mismatched types --> $DIR/ice-6250.rs:12:9 From 4535c5f2b4f744b534573eaad16c2fe5f3060e31 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 29 Jul 2021 01:07:32 +0300 Subject: [PATCH 0286/1222] Fix clippy --- clippy_lints/src/doc.rs | 12 +++++++----- clippy_lints/src/enum_variants.rs | 2 +- clippy_lints/src/exhaustive_items.rs | 2 +- clippy_lints/src/functions/must_use.rs | 18 +++++++++--------- .../src/functions/not_unsafe_ptr_arg_deref.rs | 9 +++++---- clippy_lints/src/functions/result_unit_err.rs | 6 +++--- clippy_lints/src/implicit_hasher.rs | 2 +- clippy_lints/src/len_zero.rs | 10 +++------- clippy_lints/src/methods/mod.rs | 4 ++-- clippy_lints/src/missing_inline.rs | 6 +++--- clippy_lints/src/new_without_default.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 12 ++++++------ clippy_lints/src/redundant_pub_crate.rs | 4 ++-- clippy_lints/src/unnecessary_wraps.rs | 3 ++- clippy_lints/src/upper_case_acronyms.rs | 2 +- 15 files changed, 47 insertions(+), 47 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index c39829fdc7aa..a3a3603c4c0e 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -21,6 +21,7 @@ use rustc_parse::maybe_new_parser_from_source_str; use rustc_parse::parser::ForceCollect; use rustc_session::parse::ParseSess; use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::def_id::LocalDefId; use rustc_span::edition::Edition; use rustc_span::source_map::{BytePos, FilePathMapping, MultiSpan, SourceMap, Span}; use rustc_span::{sym, FileName, Pos}; @@ -231,7 +232,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { fpu.visit_expr(&body.value); lint_for_missing_headers( cx, - item.hir_id(), + item.def_id, item.span, sig, headers, @@ -258,7 +259,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { let headers = check_attrs(cx, &self.valid_idents, attrs); if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { if !in_external_macro(cx.tcx.sess, item.span) { - lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, None, None); + lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, None, None); } } } @@ -279,7 +280,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { fpu.visit_expr(&body.value); lint_for_missing_headers( cx, - item.hir_id(), + item.def_id, item.span, sig, headers, @@ -292,14 +293,14 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { fn lint_for_missing_headers<'tcx>( cx: &LateContext<'tcx>, - hir_id: hir::HirId, + def_id: LocalDefId, span: impl Into + Copy, sig: &hir::FnSig<'_>, headers: DocHeaders, body_id: Option, panic_span: Option, ) { - if !cx.access_levels.is_exported(hir_id) { + if !cx.access_levels.is_exported(def_id) { return; // Private functions do not require doc comments } if !headers.safety && sig.header.unsafety == hir::Unsafety::Unsafe { @@ -321,6 +322,7 @@ fn lint_for_missing_headers<'tcx>( ); } if !headers.errors { + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); if is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::result_type) { span_lint( cx, diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index 32b95745b64d..174260fabd22 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -297,7 +297,7 @@ impl LateLintPass<'_> for EnumVariantNames { } } if let ItemKind::Enum(ref def, _) = item.kind { - if !(self.avoid_breaking_exported_api && cx.access_levels.is_exported(item.hir_id())) { + if !(self.avoid_breaking_exported_api && cx.access_levels.is_exported(item.def_id)) { check_variant(cx, self.threshold, def, &item_name, item_name_chars, item.span); } } diff --git a/clippy_lints/src/exhaustive_items.rs b/clippy_lints/src/exhaustive_items.rs index e00126046c02..bb4684ce38b3 100644 --- a/clippy_lints/src/exhaustive_items.rs +++ b/clippy_lints/src/exhaustive_items.rs @@ -71,7 +71,7 @@ impl LateLintPass<'_> for ExhaustiveItems { fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { if_chain! { if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind; - if cx.access_levels.is_exported(item.hir_id()); + if cx.access_levels.is_exported(item.def_id); let attrs = cx.tcx.hir().attrs(item.hir_id()); if !attrs.iter().any(|a| a.has_name(sym::non_exhaustive)); then { diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 7f4fb68cf2f6..ea6193acbe84 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -1,6 +1,6 @@ use rustc_ast::ast::Attribute; use rustc_errors::Applicability; -use rustc_hir::def_id::DefIdSet; +use rustc_hir::def_id::{DefIdSet, LocalDefId}; use rustc_hir::{self as hir, def::Res, intravisit, QPath}; use rustc_lint::{LateContext, LintContext}; use rustc_middle::{ @@ -22,7 +22,7 @@ pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { let attrs = cx.tcx.hir().attrs(item.hir_id()); let attr = must_use_attr(attrs); if let hir::ItemKind::Fn(ref sig, ref _generics, ref body_id) = item.kind { - let is_public = cx.access_levels.is_exported(item.hir_id()); + let is_public = cx.access_levels.is_exported(item.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); if let Some(attr) = attr { check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr); @@ -33,7 +33,7 @@ pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { sig.decl, cx.tcx.hir().body(*body_id), item.span, - item.hir_id(), + item.def_id, item.span.with_hi(sig.decl.output.span().hi()), "this function could have a `#[must_use]` attribute", ); @@ -43,7 +43,7 @@ pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind { - let is_public = cx.access_levels.is_exported(item.hir_id()); + let is_public = cx.access_levels.is_exported(item.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let attrs = cx.tcx.hir().attrs(item.hir_id()); let attr = must_use_attr(attrs); @@ -55,7 +55,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem< sig.decl, cx.tcx.hir().body(*body_id), item.span, - item.hir_id(), + item.def_id, item.span.with_hi(sig.decl.output.span().hi()), "this method could have a `#[must_use]` attribute", ); @@ -65,7 +65,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem< pub(super) fn check_trait_item(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { if let hir::TraitItemKind::Fn(ref sig, ref eid) = item.kind { - let is_public = cx.access_levels.is_exported(item.hir_id()); + let is_public = cx.access_levels.is_exported(item.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let attrs = cx.tcx.hir().attrs(item.hir_id()); @@ -80,7 +80,7 @@ pub(super) fn check_trait_item(cx: &LateContext<'tcx>, item: &'tcx hir::TraitIte sig.decl, body, item.span, - item.hir_id(), + item.def_id, item.span.with_hi(sig.decl.output.span().hi()), "this method could have a `#[must_use]` attribute", ); @@ -132,7 +132,7 @@ fn check_must_use_candidate<'tcx>( decl: &'tcx hir::FnDecl<'_>, body: &'tcx hir::Body<'_>, item_span: Span, - item_id: hir::HirId, + item_id: LocalDefId, fn_span: Span, msg: &str, ) { @@ -141,7 +141,7 @@ fn check_must_use_candidate<'tcx>( || in_external_macro(cx.sess(), item_span) || returns_unit(decl) || !cx.access_levels.is_exported(item_id) - || is_must_use_ty(cx, return_ty(cx, item_id)) + || is_must_use_ty(cx, return_ty(cx, cx.tcx.hir().local_def_id_to_hir_id(item_id))) { return; } diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index af759a48e10c..f83789bb2199 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -1,6 +1,7 @@ use rustc_hir::{self as hir, intravisit, HirIdSet}; use rustc_lint::LateContext; use rustc_middle::{hir::map::Map, ty}; +use rustc_span::def_id::LocalDefId; use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::type_is_unsafe_function; @@ -21,13 +22,13 @@ pub(super) fn check_fn( intravisit::FnKind::Closure => return, }; - check_raw_ptr(cx, unsafety, decl, body, hir_id); + check_raw_ptr(cx, unsafety, decl, body, cx.tcx.hir().local_def_id(hir_id)); } pub(super) fn check_trait_item(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { if let hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(eid)) = item.kind { let body = cx.tcx.hir().body(eid); - check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.hir_id()); + check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.def_id); } } @@ -36,10 +37,10 @@ fn check_raw_ptr( unsafety: hir::Unsafety, decl: &'tcx hir::FnDecl<'tcx>, body: &'tcx hir::Body<'tcx>, - hir_id: hir::HirId, + def_id: LocalDefId, ) { let expr = &body.value; - if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(hir_id) { + if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(def_id) { let raw_ptrs = iter_input_pats(decl, body) .zip(decl.inputs.iter()) .filter_map(|(arg, ty)| raw_ptr_arg(arg, ty)) diff --git a/clippy_lints/src/functions/result_unit_err.rs b/clippy_lints/src/functions/result_unit_err.rs index c073f312d386..13863ec8381b 100644 --- a/clippy_lints/src/functions/result_unit_err.rs +++ b/clippy_lints/src/functions/result_unit_err.rs @@ -15,7 +15,7 @@ use super::RESULT_UNIT_ERR; pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { if let hir::ItemKind::Fn(ref sig, ref _generics, _) = item.kind { - let is_public = cx.access_levels.is_exported(item.hir_id()); + let is_public = cx.access_levels.is_exported(item.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); if is_public { check_result_unit_err(cx, sig.decl, item.span, fn_header_span); @@ -25,7 +25,7 @@ pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { if let hir::ImplItemKind::Fn(ref sig, _) = item.kind { - let is_public = cx.access_levels.is_exported(item.hir_id()); + let is_public = cx.access_levels.is_exported(item.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); if is_public && trait_ref_of_method(cx, item.hir_id()).is_none() { check_result_unit_err(cx, sig.decl, item.span, fn_header_span); @@ -35,7 +35,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem< pub(super) fn check_trait_item(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { if let hir::TraitItemKind::Fn(ref sig, _) = item.kind { - let is_public = cx.access_levels.is_exported(item.hir_id()); + let is_public = cx.access_levels.is_exported(item.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); if is_public { check_result_unit_err(cx, sig.decl, item.span, fn_header_span); diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 31b3fd4a538e..57a826d558ea 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { } } - if !cx.access_levels.is_exported(item.hir_id()) { + if !cx.access_levels.is_exported(item.def_id) { return; } diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index b66d7a9f7294..a2cbfb1a05ee 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -131,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero { if item.ident.name == sym::len; if let ImplItemKind::Fn(sig, _) = &item.kind; if sig.decl.implicit_self.has_implicit_self(); - if cx.access_levels.is_exported(item.hir_id()); + if cx.access_levels.is_exported(item.def_id); if matches!(sig.decl.output, FnRetTy::Return(_)); if let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id()); if imp.of_trait.is_none(); @@ -207,7 +207,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items } } - if cx.access_levels.is_exported(visited_trait.hir_id()) + if cx.access_levels.is_exported(visited_trait.def_id) && trait_items.iter().any(|i| is_named_self(cx, i, sym::len)) { let mut current_and_super_traits = DefIdSet::default(); @@ -331,11 +331,7 @@ fn check_for_is_empty( None, None, ), - Some(is_empty) - if !cx - .access_levels - .is_exported(cx.tcx.hir().local_def_id_to_hir_id(is_empty.def_id.expect_local())) => - { + Some(is_empty) if !cx.access_levels.is_exported(is_empty.def_id.expect_local()) => { ( format!( "{} `{}` has a public `len` method, but a private `is_empty` method", diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 5aa29424349f..1909fabb22fe 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1903,7 +1903,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { then { // if this impl block implements a trait, lint in trait definition instead - if !implements_trait && cx.access_levels.is_exported(impl_item.hir_id()) { + if !implements_trait && cx.access_levels.is_exported(impl_item.def_id) { // check missing trait implementations for method_config in &TRAIT_METHODS { if name == method_config.method_name && @@ -1935,7 +1935,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if sig.decl.implicit_self.has_implicit_self() && !(self.avoid_breaking_exported_api - && cx.access_levels.is_exported(impl_item.hir_id())) + && cx.access_levels.is_exported(impl_item.def_id)) { wrong_self_convention::check( cx, diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index be5b4b4006ff..977e6d966e87 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { return; } - if !cx.access_levels.is_exported(it.hir_id()) { + if !cx.access_levels.is_exported(it.def_id) { return; } match it.kind { @@ -140,7 +140,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { } // If the item being implemented is not exported, then we don't need #[inline] - if !cx.access_levels.is_exported(impl_item.hir_id()) { + if !cx.access_levels.is_exported(impl_item.def_id) { return; } @@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { }; if let Some(trait_def_id) = trait_def_id { - if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.hir_id()) { + if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.def_id) { // If a trait is being implemented for an item, and the // trait is not exported, we don't need #[inline] return; diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 5c63d245bf12..0ad616a39d26 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -99,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { if_chain! { if sig.decl.inputs.is_empty(); if name == sym::new; - if cx.access_levels.is_reachable(id); + if cx.access_levels.is_reachable(impl_item.def_id); let self_def_id = cx.tcx.hir().local_def_id(cx.tcx.hir().get_parent_item(id)); let self_ty = cx.tcx.type_of(self_def_id); if TyS::same_type(self_ty, return_ty(cx, id)); diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index f738ac254178..1222a95d4eaa 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -14,6 +14,7 @@ use rustc_hir::{BindingAnnotation, Body, FnDecl, HirId, Impl, ItemKind, MutTy, M use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::def_id::LocalDefId; use rustc_span::{sym, Span}; use rustc_target::abi::LayoutOf; use rustc_target::spec::abi::Abi; @@ -134,13 +135,12 @@ impl<'tcx> PassByRefOrValue { } } - fn check_poly_fn(&mut self, cx: &LateContext<'tcx>, hir_id: HirId, decl: &FnDecl<'_>, span: Option) { - if self.avoid_breaking_exported_api && cx.access_levels.is_exported(hir_id) { + fn check_poly_fn(&mut self, cx: &LateContext<'tcx>, def_id: LocalDefId, decl: &FnDecl<'_>, span: Option) { + if self.avoid_breaking_exported_api && cx.access_levels.is_exported(def_id) { return; } - let fn_def_id = cx.tcx.hir().local_def_id(hir_id); - let fn_sig = cx.tcx.fn_sig(fn_def_id); + let fn_sig = cx.tcx.fn_sig(def_id); let fn_sig = cx.tcx.erase_late_bound_regions(fn_sig); let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir().body(id)); @@ -231,7 +231,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { } if let hir::TraitItemKind::Fn(method_sig, _) = &item.kind { - self.check_poly_fn(cx, item.hir_id(), &*method_sig.decl, None); + self.check_poly_fn(cx, item.def_id, &*method_sig.decl, None); } } @@ -278,6 +278,6 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { } } - self.check_poly_fn(cx, hir_id, decl, Some(span)); + self.check_poly_fn(cx, cx.tcx.hir().local_def_id(hir_id), decl, Some(span)); } } diff --git a/clippy_lints/src/redundant_pub_crate.rs b/clippy_lints/src/redundant_pub_crate.rs index 59a55b9dffad..ed2e1f90fa59 100644 --- a/clippy_lints/src/redundant_pub_crate.rs +++ b/clippy_lints/src/redundant_pub_crate.rs @@ -41,7 +41,7 @@ impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]); impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { if let VisibilityKind::Crate { .. } = item.vis.node { - if !cx.access_levels.is_exported(item.hir_id()) { + if !cx.access_levels.is_exported(item.def_id) { if let Some(false) = self.is_exported.last() { let span = item.span.with_hi(item.ident.span.hi()); let descr = cx.tcx.def_kind(item.def_id).descr(item.def_id.to_def_id()); @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { } if let ItemKind::Mod { .. } = item.kind { - self.is_exported.push(cx.access_levels.is_exported(item.hir_id())); + self.is_exported.push(cx.access_levels.is_exported(item.def_id)); } } diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index 7a62b21937ff..5ca861a14bf2 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -81,7 +81,8 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { // Abort if public function/method or closure. match fn_kind { FnKind::ItemFn(..) | FnKind::Method(..) => { - if self.avoid_breaking_exported_api && cx.access_levels.is_exported(hir_id) { + let def_id = cx.tcx.hir().local_def_id(hir_id); + if self.avoid_breaking_exported_api && cx.access_levels.is_exported(def_id) { return; } }, diff --git a/clippy_lints/src/upper_case_acronyms.rs b/clippy_lints/src/upper_case_acronyms.rs index 7fa0e23ee73e..dbf335a70c83 100644 --- a/clippy_lints/src/upper_case_acronyms.rs +++ b/clippy_lints/src/upper_case_acronyms.rs @@ -104,7 +104,7 @@ impl LateLintPass<'_> for UpperCaseAcronyms { fn check_item(&mut self, cx: &LateContext<'_>, it: &Item<'_>) { // do not lint public items or in macros if in_external_macro(cx.sess(), it.span) - || (self.avoid_breaking_exported_api && cx.access_levels.is_exported(it.hir_id())) + || (self.avoid_breaking_exported_api && cx.access_levels.is_exported(it.def_id)) { return; } From b1f6ae7bcc37f8ebeb57ecb7c206e29653f33f71 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Fri, 30 Jul 2021 14:46:56 +0200 Subject: [PATCH 0287/1222] bump bootstrap compiler to 1.55 --- clippy_lints/src/implicit_hasher.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 31b3fd4a538e..fcc43cce6ce4 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -1,5 +1,3 @@ -#![cfg_attr(bootstrap, allow(rustc::default_hash_types))] - use std::borrow::Cow; use std::collections::BTreeMap; From 9f6f2bbc503df5577a9e7125a1a7580a2486a41e Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Wed, 11 Aug 2021 14:21:33 +0000 Subject: [PATCH 0288/1222] update clippy --- tests/ui/assign_ops2.stderr | 36 ++++---- tests/ui/async_yields_async.stderr | 12 +-- tests/ui/bind_instead_of_map_multipart.stderr | 12 +-- tests/ui/blocks_in_if_conditions.stderr | 8 +- .../shared_at_bottom.stderr | 50 +++++------ .../shared_at_top.stderr | 34 +++---- .../shared_at_top_and_bottom.stderr | 62 ++++++------- tests/ui/collapsible_else_if.stderr | 72 +++++++-------- tests/ui/collapsible_if.stderr | 42 ++++----- tests/ui/crashes/ice-3717.stderr | 4 +- tests/ui/crashes/ice-6250.stderr | 2 +- tests/ui/crashes/ice-6251.stderr | 2 +- tests/ui/dbg_macro.stderr | 10 +-- tests/ui/entry.stderr | 88 +++++++++---------- tests/ui/entry_with_else.stderr | 80 ++++++++--------- tests/ui/eprint_with_newline.stderr | 48 +++++----- tests/ui/exhaustive_items.stderr | 12 +-- tests/ui/for_kv_map.stderr | 10 +-- tests/ui/format.stderr | 4 +- tests/ui/if_let_some_result.stderr | 4 +- tests/ui/implicit_hasher.stderr | 32 +++---- tests/ui/implicit_return.stderr | 6 +- tests/ui/large_enum_variant.stderr | 6 +- tests/ui/let_and_return.stderr | 12 +-- tests/ui/let_unit.stderr | 12 +-- tests/ui/literals.stderr | 8 +- tests/ui/manual_async_fn.stderr | 50 +++++------ .../manual_memcpy/with_loop_counters.stderr | 4 +- .../without_loop_counters.stderr | 4 +- tests/ui/manual_ok_or.stderr | 6 +- tests/ui/manual_strip.stderr | 44 +++++----- tests/ui/manual_unwrap_or.stderr | 20 ++--- tests/ui/map_unwrap_or.stderr | 34 +++---- tests/ui/match_bool.stderr | 28 +++--- tests/ui/match_expr_like_matches_macro.stderr | 8 +- tests/ui/match_ref_pats.stderr | 24 ++--- tests/ui/match_single_binding.stderr | 60 ++++++------- tests/ui/match_single_binding2.stderr | 26 +++--- tests/ui/min_rust_version_attr.stderr | 8 +- tests/ui/mismatched_target_os_unix.stderr | 6 +- tests/ui/needless_borrow_pat.stderr | 20 ++--- tests/ui/needless_collect_indirect.stderr | 36 ++++---- tests/ui/needless_for_each_fixable.stderr | 48 +++++----- tests/ui/needless_for_each_unfixable.stderr | 14 +-- tests/ui/needless_pass_by_value.stderr | 8 +- tests/ui/needless_range_loop.stderr | 28 +++--- tests/ui/needless_range_loop2.stderr | 16 ++-- tests/ui/new_without_default.stderr | 72 +++++++-------- tests/ui/nonminimal_bool.stderr | 20 ++--- tests/ui/op_ref.stderr | 2 +- tests/ui/option_if_let_else.stderr | 44 +++++----- tests/ui/option_map_or_none.stderr | 6 +- tests/ui/print_literal.stderr | 55 +++++++----- tests/ui/print_with_newline.stderr | 48 +++++----- tests/ui/ptr_arg.stderr | 40 ++++----- tests/ui/ref_binding_to_reference.stderr | 28 +++--- tests/ui/reversed_empty_ranges_fixable.stderr | 8 +- ...reversed_empty_ranges_loops_fixable.stderr | 12 +-- tests/ui/single_element_loop.stderr | 16 ++-- tests/ui/single_match.stderr | 6 +- tests/ui/single_match_else.stderr | 24 ++--- tests/ui/strlen_on_c_strings.stderr | 4 +- tests/ui/unit_arg.stderr | 76 ++++++++-------- tests/ui/unit_arg_empty_blocks.stderr | 10 +-- tests/ui/unnecessary_clone.stderr | 12 +-- tests/ui/unnecessary_wraps.stderr | 32 +++---- tests/ui/unnested_or_patterns.stderr | 32 +++---- tests/ui/unnested_or_patterns2.stderr | 16 ++-- tests/ui/write_literal.stderr | 55 +++++++----- tests/ui/write_literal_2.stderr | 41 +++++---- tests/ui/write_with_newline.stderr | 48 +++++----- 71 files changed, 961 insertions(+), 906 deletions(-) diff --git a/tests/ui/assign_ops2.stderr b/tests/ui/assign_ops2.stderr index e40668ed339f..04b1dc93d4a4 100644 --- a/tests/ui/assign_ops2.stderr +++ b/tests/ui/assign_ops2.stderr @@ -8,11 +8,11 @@ LL | a += a + 1; help: did you mean `a = a + 1` or `a = a + a + 1`? Consider replacing it with | LL | a += 1; - | ^^^^^^ + | ~~~~~~ help: or | LL | a = a + a + 1; - | ^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation --> $DIR/assign_ops2.rs:6:5 @@ -23,11 +23,11 @@ LL | a += 1 + a; help: did you mean `a = a + 1` or `a = a + 1 + a`? Consider replacing it with | LL | a += 1; - | ^^^^^^ + | ~~~~~~ help: or | LL | a = a + 1 + a; - | ^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation --> $DIR/assign_ops2.rs:7:5 @@ -38,11 +38,11 @@ LL | a -= a - 1; help: did you mean `a = a - 1` or `a = a - (a - 1)`? Consider replacing it with | LL | a -= 1; - | ^^^^^^ + | ~~~~~~ help: or | LL | a = a - (a - 1); - | ^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation --> $DIR/assign_ops2.rs:8:5 @@ -53,11 +53,11 @@ LL | a *= a * 99; help: did you mean `a = a * 99` or `a = a * a * 99`? Consider replacing it with | LL | a *= 99; - | ^^^^^^^ + | ~~~~~~~ help: or | LL | a = a * a * 99; - | ^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation --> $DIR/assign_ops2.rs:9:5 @@ -68,11 +68,11 @@ LL | a *= 42 * a; help: did you mean `a = a * 42` or `a = a * 42 * a`? Consider replacing it with | LL | a *= 42; - | ^^^^^^^ + | ~~~~~~~ help: or | LL | a = a * 42 * a; - | ^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation --> $DIR/assign_ops2.rs:10:5 @@ -83,11 +83,11 @@ LL | a /= a / 2; help: did you mean `a = a / 2` or `a = a / (a / 2)`? Consider replacing it with | LL | a /= 2; - | ^^^^^^ + | ~~~~~~ help: or | LL | a = a / (a / 2); - | ^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation --> $DIR/assign_ops2.rs:11:5 @@ -98,11 +98,11 @@ LL | a %= a % 5; help: did you mean `a = a % 5` or `a = a % (a % 5)`? Consider replacing it with | LL | a %= 5; - | ^^^^^^ + | ~~~~~~ help: or | LL | a = a % (a % 5); - | ^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation --> $DIR/assign_ops2.rs:12:5 @@ -113,11 +113,11 @@ LL | a &= a & 1; help: did you mean `a = a & 1` or `a = a & a & 1`? Consider replacing it with | LL | a &= 1; - | ^^^^^^ + | ~~~~~~ help: or | LL | a = a & a & 1; - | ^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation --> $DIR/assign_ops2.rs:13:5 @@ -128,11 +128,11 @@ LL | a *= a * a; help: did you mean `a = a * a` or `a = a * a * a`? Consider replacing it with | LL | a *= a; - | ^^^^^^ + | ~~~~~~ help: or | LL | a = a * a * a; - | ^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~ error: manual implementation of an assign operation --> $DIR/assign_ops2.rs:50:5 diff --git a/tests/ui/async_yields_async.stderr b/tests/ui/async_yields_async.stderr index 17d0c3751064..3f2051458f67 100644 --- a/tests/ui/async_yields_async.stderr +++ b/tests/ui/async_yields_async.stderr @@ -14,9 +14,9 @@ LL | | }; = note: `-D clippy::async-yields-async` implied by `-D warnings` help: consider awaiting this value | -LL | async { -LL | 3 -LL | }.await +LL ~ async { +LL + 3 +LL + }.await | error: an async construct yields a type which is itself awaitable @@ -47,9 +47,9 @@ LL | | }; | help: consider awaiting this value | -LL | async { -LL | 3 -LL | }.await +LL ~ async { +LL + 3 +LL + }.await | error: an async construct yields a type which is itself awaitable diff --git a/tests/ui/bind_instead_of_map_multipart.stderr b/tests/ui/bind_instead_of_map_multipart.stderr index 50ce2f4051e0..e4f605a4de30 100644 --- a/tests/ui/bind_instead_of_map_multipart.stderr +++ b/tests/ui/bind_instead_of_map_multipart.stderr @@ -12,7 +12,7 @@ LL | #![deny(clippy::bind_instead_of_map)] help: try this | LL | let _ = Some("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); - | ^^^ ^ ^^^^^^^ + | ~~~ ~ ~~~~~~~ error: using `Result.and_then(|x| Ok(y))`, which is more succinctly expressed as `map(|x| y)` --> $DIR/bind_instead_of_map_multipart.rs:8:13 @@ -23,7 +23,7 @@ LL | let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Ok(0) } else { help: try this | LL | let _ = Ok::<_, ()>("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); - | ^^^ ^ ^^^^^^^ + | ~~~ ~ ~~~~~~~ error: using `Result.or_else(|x| Err(y))`, which is more succinctly expressed as `map_err(|x| y)` --> $DIR/bind_instead_of_map_multipart.rs:11:13 @@ -34,7 +34,7 @@ LL | let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Err(s.len() + help: try this | LL | let _ = Err::<(), _>("42").map_err(|s| if s.len() < 42 { s.len() + 20 } else { s.len() }); - | ^^^^^^^ ^^^^^^^^^^^^ ^^^^^^^ + | ~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~ error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` --> $DIR/bind_instead_of_map_multipart.rs:19:5 @@ -50,10 +50,10 @@ LL | | }); | help: try this | -LL | Some("42").map(|s| { +LL ~ Some("42").map(|s| { LL | if { LL | if s == "43" { -LL | return 43; +LL ~ return 43; LL | } LL | s == "42" ... @@ -67,7 +67,7 @@ LL | let _ = Some("").and_then(|s| if s.len() == 20 { Some(m!()) } else { So help: try this | LL | let _ = Some("").map(|s| if s.len() == 20 { m!() } else { Some(20) }); - | ^^^ ^^^^ ^^^^^^^^ + | ~~~ ~~~~ ~~~~~~~~ error: aborting due to 5 previous errors diff --git a/tests/ui/blocks_in_if_conditions.stderr b/tests/ui/blocks_in_if_conditions.stderr index 9328492733fd..079f2feb5c48 100644 --- a/tests/ui/blocks_in_if_conditions.stderr +++ b/tests/ui/blocks_in_if_conditions.stderr @@ -10,10 +10,10 @@ LL | | } { = note: `-D clippy::blocks-in-if-conditions` implied by `-D warnings` help: try | -LL | let res = { -LL | let x = 3; -LL | x == 3 -LL | }; if res { +LL ~ let res = { +LL + let x = 3; +LL + x == 3 +LL ~ }; if res { | error: omit braces around single expression condition diff --git a/tests/ui/branches_sharing_code/shared_at_bottom.stderr b/tests/ui/branches_sharing_code/shared_at_bottom.stderr index 271fcd8b6c12..e3c1bbee9942 100644 --- a/tests/ui/branches_sharing_code/shared_at_bottom.stderr +++ b/tests/ui/branches_sharing_code/shared_at_bottom.stderr @@ -15,10 +15,10 @@ LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)] = note: The end suggestion probably needs some adjustments to use the expression result correctly help: consider moving the end statements out like this | -LL | } -LL | let result = false; -LL | println!("Block end!"); -LL | result; +LL ~ } +LL + let result = false; +LL + println!("Block end!"); +LL ~ result; | error: all if blocks contain the same code at the end @@ -30,8 +30,8 @@ LL | | } | help: consider moving the end statements out like this | -LL | } -LL | println!("Same end of block"); +LL ~ } +LL + println!("Same end of block"); | error: all if blocks contain the same code at the end @@ -46,11 +46,11 @@ LL | | } | help: consider moving the end statements out like this | -LL | } -LL | println!( -LL | "I'm moveable because I know: `outer_scope_value`: '{}'", -LL | outer_scope_value -LL | ); +LL ~ } +LL + println!( +LL + "I'm moveable because I know: `outer_scope_value`: '{}'", +LL + outer_scope_value +LL + ); | error: all if blocks contain the same code at the end @@ -62,8 +62,8 @@ LL | | } | help: consider moving the end statements out like this | -LL | } -LL | println!("Hello World"); +LL ~ } +LL + println!("Hello World"); | error: all if blocks contain the same code at the end @@ -78,9 +78,9 @@ LL | | } = warning: Some moved values might need to be renamed to avoid wrong references help: consider moving the end statements out like this | -LL | } -LL | let later_used_value = "A string value"; -LL | println!("{}", later_used_value); +LL ~ } +LL + let later_used_value = "A string value"; +LL + println!("{}", later_used_value); | error: all if blocks contain the same code at the end @@ -94,9 +94,9 @@ LL | | } = warning: Some moved values might need to be renamed to avoid wrong references help: consider moving the end statements out like this | -LL | } -LL | let simple_examples = "I now identify as a &str :)"; -LL | println!("This is the new simple_example: {}", simple_examples); +LL ~ } +LL + let simple_examples = "I now identify as a &str :)"; +LL + println!("This is the new simple_example: {}", simple_examples); | error: all if blocks contain the same code at the end @@ -109,8 +109,8 @@ LL | | }; = note: The end suggestion probably needs some adjustments to use the expression result correctly help: consider moving the end statements out like this | -LL | } -LL | x << 2; +LL ~ } +LL ~ x << 2; | error: all if blocks contain the same code at the end @@ -123,8 +123,8 @@ LL | | } = note: The end suggestion probably needs some adjustments to use the expression result correctly help: consider moving the end statements out like this | -LL | } -LL | x * 4 +LL ~ } +LL + x * 4 | error: all if blocks contain the same code at the end @@ -135,8 +135,8 @@ LL | if x == 17 { b = 1; a = 0x99; } else { a = 0x99; } | help: consider moving the end statements out like this | -LL | if x == 17 { b = 1; a = 0x99; } else { } -LL | a = 0x99; +LL ~ if x == 17 { b = 1; a = 0x99; } else { } +LL + a = 0x99; | error: aborting due to 9 previous errors diff --git a/tests/ui/branches_sharing_code/shared_at_top.stderr b/tests/ui/branches_sharing_code/shared_at_top.stderr index 15867e9ea020..8d78fa5de7e4 100644 --- a/tests/ui/branches_sharing_code/shared_at_top.stderr +++ b/tests/ui/branches_sharing_code/shared_at_top.stderr @@ -12,8 +12,8 @@ LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider moving the start statements out like this | -LL | println!("Hello World!"); -LL | if true { +LL ~ println!("Hello World!"); +LL + if true { | error: all if blocks contain the same code at the start @@ -28,10 +28,10 @@ LL | | let _z = y; = warning: Some moved values might need to be renamed to avoid wrong references help: consider moving the start statements out like this | -LL | let y = 9; -LL | println!("The value y was set to: `{}`", y); -LL | let _z = y; -LL | if x == 0 { +LL ~ let y = 9; +LL + println!("The value y was set to: `{}`", y); +LL + let _z = y; +LL + if x == 0 { | error: all if blocks contain the same code at the start @@ -43,8 +43,8 @@ LL | | let y = 16; | help: consider moving the start statements out like this | -LL | let y = 16; -LL | let _ = if x == 7 { +LL ~ let y = 16; +LL + let _ = if x == 7 { | error: all if blocks contain the same code at the start @@ -58,9 +58,9 @@ LL | | println!("Str: {}", used_value_name); = warning: Some moved values might need to be renamed to avoid wrong references help: consider moving the start statements out like this | -LL | let used_value_name = "Different type"; -LL | println!("Str: {}", used_value_name); -LL | if x == 10 { +LL ~ let used_value_name = "Different type"; +LL + println!("Str: {}", used_value_name); +LL + if x == 10 { | error: all if blocks contain the same code at the start @@ -74,9 +74,9 @@ LL | | println!("I'm also moveable"); = warning: Some moved values might need to be renamed to avoid wrong references help: consider moving the start statements out like this | -LL | let can_be_overridden = "Move me"; -LL | println!("I'm also moveable"); -LL | if x == 11 { +LL ~ let can_be_overridden = "Move me"; +LL + println!("I'm also moveable"); +LL + if x == 11 { | error: all if blocks contain the same code at the start @@ -89,9 +89,9 @@ LL | | println!("Because `IF_SAME_THEN_ELSE` is allowed here"); | help: consider moving the start statements out like this | -LL | println!("This should trigger the `SHARED_CODE_IN_IF_BLOCKS` lint."); -LL | println!("Because `IF_SAME_THEN_ELSE` is allowed here"); -LL | if x == 2020 { +LL ~ println!("This should trigger the `SHARED_CODE_IN_IF_BLOCKS` lint."); +LL + println!("Because `IF_SAME_THEN_ELSE` is allowed here"); +LL + if x == 2020 { | error: this `if` has identical blocks diff --git a/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr b/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr index 212cfb2f1d18..1db2343d3fe9 100644 --- a/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr +++ b/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr @@ -20,15 +20,15 @@ LL | | } | |_____^ help: consider moving the start statements out like this | -LL | let t = 7; -LL | let _overlap_start = t * 2; -LL | let _overlap_end = 2 * t; -LL | if x == 7 { +LL ~ let t = 7; +LL + let _overlap_start = t * 2; +LL + let _overlap_end = 2 * t; +LL + if x == 7 { | help: and consider moving the end statements out like this | -LL | } -LL | let _u = 9; +LL ~ } +LL + let _u = 9; | error: all if blocks contain the same code at the start and the end. Here at the start @@ -50,16 +50,16 @@ LL | | } = warning: Some moved values might need to be renamed to avoid wrong references help: consider moving the start statements out like this | -LL | let r = 7; -LL | let _overlap_start = r; -LL | let _overlap_middle = r * r; -LL | if x == 99 { +LL ~ let r = 7; +LL + let _overlap_start = r; +LL + let _overlap_middle = r * r; +LL + if x == 99 { | help: and consider moving the end statements out like this | -LL | } -LL | let _overlap_end = r * r * r; -LL | let z = "end"; +LL ~ } +LL + let _overlap_end = r * r * r; +LL + let z = "end"; | error: all if blocks contain the same code at the start and the end. Here at the start @@ -85,19 +85,19 @@ LL | | } = warning: Some moved values might need to be renamed to avoid wrong references help: consider moving the start statements out like this | -LL | let a = 0xcafe; -LL | let b = 0xffff00ff; -LL | let e_id = gen_id(a, b); -LL | if (x > 7 && y < 13) || (x + y) % 2 == 1 { +LL ~ let a = 0xcafe; +LL + let b = 0xffff00ff; +LL + let e_id = gen_id(a, b); +LL + if (x > 7 && y < 13) || (x + y) % 2 == 1 { | help: and consider moving the end statements out like this | -LL | } -LL | let pack = DataPack { -LL | id: e_id, -LL | name: "Player 1".to_string(), -LL | some_data: vec![0x12, 0x34, 0x56, 0x78, 0x90], -LL | }; +LL ~ } +LL + let pack = DataPack { +LL + id: e_id, +LL + name: "Player 1".to_string(), +LL + some_data: vec![0x12, 0x34, 0x56, 0x78, 0x90], +LL + }; ... error: all if blocks contain the same code at the start and the end. Here at the start @@ -116,13 +116,13 @@ LL | | }; = note: The end suggestion probably needs some adjustments to use the expression result correctly help: consider moving the start statements out like this | -LL | let _ = 19; -LL | let _ = if x == 7 { +LL ~ let _ = 19; +LL + let _ = if x == 7 { | help: and consider moving the end statements out like this | -LL | } -LL | x << 2; +LL ~ } +LL ~ x << 2; | error: all if blocks contain the same code at the start and the end. Here at the start @@ -141,13 +141,13 @@ LL | | } = note: The end suggestion probably needs some adjustments to use the expression result correctly help: consider moving the start statements out like this | -LL | let _ = 17; -LL | if x == 9 { +LL ~ let _ = 17; +LL + if x == 9 { | help: and consider moving the end statements out like this | -LL | } -LL | x * 4 +LL ~ } +LL + x * 4 | error: aborting due to 5 previous errors diff --git a/tests/ui/collapsible_else_if.stderr b/tests/ui/collapsible_else_if.stderr index ee3e11ae565d..6970f6609790 100644 --- a/tests/ui/collapsible_else_if.stderr +++ b/tests/ui/collapsible_else_if.stderr @@ -12,9 +12,9 @@ LL | | } = note: `-D clippy::collapsible-else-if` implied by `-D warnings` help: collapse nested if block | -LL | } else if y == "world" { -LL | println!("world!") -LL | } +LL ~ } else if y == "world" { +LL + println!("world!") +LL + } | error: this `else { if .. }` block can be collapsed @@ -30,9 +30,9 @@ LL | | } | help: collapse nested if block | -LL | } else if let Some(42) = Some(42) { -LL | println!("world!") -LL | } +LL ~ } else if let Some(42) = Some(42) { +LL + println!("world!") +LL + } | error: this `else { if .. }` block can be collapsed @@ -50,12 +50,12 @@ LL | | } | help: collapse nested if block | -LL | } else if y == "world" { -LL | println!("world") -LL | } -LL | else { -LL | println!("!") -LL | } +LL ~ } else if y == "world" { +LL + println!("world") +LL + } +LL + else { +LL + println!("!") +LL + } | error: this `else { if .. }` block can be collapsed @@ -73,12 +73,12 @@ LL | | } | help: collapse nested if block | -LL | } else if let Some(42) = Some(42) { -LL | println!("world") -LL | } -LL | else { -LL | println!("!") -LL | } +LL ~ } else if let Some(42) = Some(42) { +LL + println!("world") +LL + } +LL + else { +LL + println!("!") +LL + } | error: this `else { if .. }` block can be collapsed @@ -96,12 +96,12 @@ LL | | } | help: collapse nested if block | -LL | } else if let Some(42) = Some(42) { -LL | println!("world") -LL | } -LL | else { -LL | println!("!") -LL | } +LL ~ } else if let Some(42) = Some(42) { +LL + println!("world") +LL + } +LL + else { +LL + println!("!") +LL + } | error: this `else { if .. }` block can be collapsed @@ -119,12 +119,12 @@ LL | | } | help: collapse nested if block | -LL | } else if x == "hello" { -LL | println!("world") -LL | } -LL | else { -LL | println!("!") -LL | } +LL ~ } else if x == "hello" { +LL + println!("world") +LL + } +LL + else { +LL + println!("!") +LL + } | error: this `else { if .. }` block can be collapsed @@ -142,12 +142,12 @@ LL | | } | help: collapse nested if block | -LL | } else if let Some(42) = Some(42) { -LL | println!("world") -LL | } -LL | else { -LL | println!("!") -LL | } +LL ~ } else if let Some(42) = Some(42) { +LL + println!("world") +LL + } +LL + else { +LL + println!("!") +LL + } | error: aborting due to 7 previous errors diff --git a/tests/ui/collapsible_if.stderr b/tests/ui/collapsible_if.stderr index acd1ec3f2cae..6749612388fe 100644 --- a/tests/ui/collapsible_if.stderr +++ b/tests/ui/collapsible_if.stderr @@ -11,9 +11,9 @@ LL | | } = note: `-D clippy::collapsible-if` implied by `-D warnings` help: collapse nested if block | -LL | if x == "hello" && y == "world" { -LL | println!("Hello world!"); -LL | } +LL ~ if x == "hello" && y == "world" { +LL + println!("Hello world!"); +LL + } | error: this `if` statement can be collapsed @@ -28,9 +28,9 @@ LL | | } | help: collapse nested if block | -LL | if (x == "hello" || x == "world") && (y == "world" || y == "hello") { -LL | println!("Hello world!"); -LL | } +LL ~ if (x == "hello" || x == "world") && (y == "world" || y == "hello") { +LL + println!("Hello world!"); +LL + } | error: this `if` statement can be collapsed @@ -45,9 +45,9 @@ LL | | } | help: collapse nested if block | -LL | if x == "hello" && x == "world" && (y == "world" || y == "hello") { -LL | println!("Hello world!"); -LL | } +LL ~ if x == "hello" && x == "world" && (y == "world" || y == "hello") { +LL + println!("Hello world!"); +LL + } | error: this `if` statement can be collapsed @@ -62,9 +62,9 @@ LL | | } | help: collapse nested if block | -LL | if (x == "hello" || x == "world") && y == "world" && y == "hello" { -LL | println!("Hello world!"); -LL | } +LL ~ if (x == "hello" || x == "world") && y == "world" && y == "hello" { +LL + println!("Hello world!"); +LL + } | error: this `if` statement can be collapsed @@ -79,9 +79,9 @@ LL | | } | help: collapse nested if block | -LL | if x == "hello" && x == "world" && y == "world" && y == "hello" { -LL | println!("Hello world!"); -LL | } +LL ~ if x == "hello" && x == "world" && y == "world" && y == "hello" { +LL + println!("Hello world!"); +LL + } | error: this `if` statement can be collapsed @@ -96,9 +96,9 @@ LL | | } | help: collapse nested if block | -LL | if 42 == 1337 && 'a' != 'A' { -LL | println!("world!") -LL | } +LL ~ if 42 == 1337 && 'a' != 'A' { +LL + println!("world!") +LL + } | error: this `if` statement can be collapsed @@ -113,9 +113,9 @@ LL | | } | help: collapse nested if block | -LL | if x == "hello" && y == "world" { // Collapsible -LL | println!("Hello world!"); -LL | } +LL ~ if x == "hello" && y == "world" { // Collapsible +LL + println!("Hello world!"); +LL + } | error: this `if` statement can be collapsed diff --git a/tests/ui/crashes/ice-3717.stderr b/tests/ui/crashes/ice-3717.stderr index 296c95abb96d..4d3d617b6937 100644 --- a/tests/ui/crashes/ice-3717.stderr +++ b/tests/ui/crashes/ice-3717.stderr @@ -12,11 +12,11 @@ LL | #![deny(clippy::implicit_hasher)] help: consider adding a type parameter | LL | pub fn ice_3717(_: &HashSet) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ + | +++++++++++++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~ help: ...and use generic constructor | LL | let _: HashSet = HashSet::default(); - | ^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/tests/ui/crashes/ice-6250.stderr b/tests/ui/crashes/ice-6250.stderr index 320b3bb42f89..439884b7d274 100644 --- a/tests/ui/crashes/ice-6250.stderr +++ b/tests/ui/crashes/ice-6250.stderr @@ -30,7 +30,7 @@ LL | Some(reference) = cache.data.get(key) { help: consider dereferencing the borrow | LL | Some(*reference) = cache.data.get(key) { - | ^ + | + error[E0308]: mismatched types --> $DIR/ice-6250.rs:12:9 diff --git a/tests/ui/crashes/ice-6251.stderr b/tests/ui/crashes/ice-6251.stderr index 8498c0407808..14c71e884b6e 100644 --- a/tests/ui/crashes/ice-6251.stderr +++ b/tests/ui/crashes/ice-6251.stderr @@ -17,7 +17,7 @@ LL | fn bug() -> impl Iterator { help: function arguments must have a statically known size, borrowed types always have a known size | LL | fn bug() -> impl Iterator { - | ^ + | + error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/ice-6251.rs:4:54 diff --git a/tests/ui/dbg_macro.stderr b/tests/ui/dbg_macro.stderr index bdf372af2907..0abe953af261 100644 --- a/tests/ui/dbg_macro.stderr +++ b/tests/ui/dbg_macro.stderr @@ -8,7 +8,7 @@ LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } help: ensure to avoid having uses of it in version control | LL | if let Some(n) = n.checked_sub(4) { n } else { n } - | ^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~ error: `dbg!` macro is intended as a debugging tool --> $DIR/dbg_macro.rs:8:8 @@ -19,7 +19,7 @@ LL | if dbg!(n <= 1) { help: ensure to avoid having uses of it in version control | LL | if n <= 1 { - | ^^^^^^ + | ~~~~~~ error: `dbg!` macro is intended as a debugging tool --> $DIR/dbg_macro.rs:9:9 @@ -52,7 +52,7 @@ LL | dbg!(42); help: ensure to avoid having uses of it in version control | LL | 42; - | ^^ + | ~~ error: `dbg!` macro is intended as a debugging tool --> $DIR/dbg_macro.rs:17:5 @@ -63,7 +63,7 @@ LL | dbg!(dbg!(dbg!(42))); help: ensure to avoid having uses of it in version control | LL | dbg!(dbg!(42)); - | ^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~ error: `dbg!` macro is intended as a debugging tool --> $DIR/dbg_macro.rs:18:14 @@ -74,7 +74,7 @@ LL | foo(3) + dbg!(factorial(4)); help: ensure to avoid having uses of it in version control | LL | foo(3) + factorial(4); - | ^^^^^^^^^^^^ + | ~~~~~~~~~~~~ error: aborting due to 7 previous errors diff --git a/tests/ui/entry.stderr b/tests/ui/entry.stderr index 2f075a97010a..8f2e383d675d 100644 --- a/tests/ui/entry.stderr +++ b/tests/ui/entry.stderr @@ -22,12 +22,12 @@ LL | | } | help: try this | -LL | m.entry(k).or_insert_with(|| { -LL | if true { -LL | v -LL | } else { -LL | v2 -LL | } +LL ~ m.entry(k).or_insert_with(|| { +LL + if true { +LL + v +LL + } else { +LL + v2 +LL + } ... error: usage of `contains_key` followed by `insert` on a `HashMap` @@ -44,12 +44,12 @@ LL | | } | help: try this | -LL | m.entry(k).or_insert_with(|| { -LL | if true { -LL | v -LL | } else { -LL | v2 -LL | } +LL ~ m.entry(k).or_insert_with(|| { +LL + if true { +LL + v +LL + } else { +LL + v2 +LL + } ... error: usage of `contains_key` followed by `insert` on a `HashMap` @@ -66,12 +66,12 @@ LL | | } | help: try this | -LL | if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { -LL | if true { -LL | e.insert(v); -LL | } else { -LL | e.insert(v2); -LL | return; +LL ~ if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { +LL + if true { +LL + e.insert(v); +LL + } else { +LL + e.insert(v2); +LL + return; ... error: usage of `contains_key` followed by `insert` on a `HashMap` @@ -85,10 +85,10 @@ LL | | } | help: try this | -LL | m.entry(k).or_insert_with(|| { -LL | foo(); -LL | v -LL | }); +LL ~ m.entry(k).or_insert_with(|| { +LL + foo(); +LL + v +LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` @@ -105,12 +105,12 @@ LL | | } | help: try this | -LL | m.entry(k).or_insert_with(|| { -LL | match 0 { -LL | 1 if true => { -LL | v -LL | }, -LL | _ => { +LL ~ m.entry(k).or_insert_with(|| { +LL + match 0 { +LL + 1 if true => { +LL + v +LL + }, +LL + _ => { ... error: usage of `contains_key` followed by `insert` on a `HashMap` @@ -127,12 +127,12 @@ LL | | } | help: try this | -LL | if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { -LL | match 0 { -LL | 0 => foo(), -LL | _ => { -LL | e.insert(v2); -LL | }, +LL ~ if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { +LL + match 0 { +LL + 0 => foo(), +LL + _ => { +LL + e.insert(v2); +LL + }, ... error: usage of `contains_key` followed by `insert` on a `HashMap` @@ -149,12 +149,12 @@ LL | | } | help: try this | -LL | m.entry(k).or_insert_with(|| { -LL | foo(); -LL | match 0 { -LL | 0 if false => { -LL | v -LL | }, +LL ~ m.entry(k).or_insert_with(|| { +LL + foo(); +LL + match 0 { +LL + 0 if false => { +LL + v +LL + }, ... error: usage of `contains_key` followed by `insert` on a `HashMap` @@ -176,10 +176,10 @@ LL | | } | help: try this | -LL | if let std::collections::btree_map::Entry::Vacant(e) = m.entry(k) { -LL | e.insert(v); -LL | foo(); -LL | } +LL ~ if let std::collections::btree_map::Entry::Vacant(e) = m.entry(k) { +LL + e.insert(v); +LL + foo(); +LL + } | error: aborting due to 10 previous errors diff --git a/tests/ui/entry_with_else.stderr b/tests/ui/entry_with_else.stderr index 6f62ff8d3745..7279efc59595 100644 --- a/tests/ui/entry_with_else.stderr +++ b/tests/ui/entry_with_else.stderr @@ -11,12 +11,12 @@ LL | | } = note: `-D clippy::map-entry` implied by `-D warnings` help: try this | -LL | match m.entry(k) { -LL | std::collections::hash_map::Entry::Vacant(e) => { -LL | e.insert(v); -LL | } -LL | std::collections::hash_map::Entry::Occupied(mut e) => { -LL | e.insert(v2); +LL ~ match m.entry(k) { +LL + std::collections::hash_map::Entry::Vacant(e) => { +LL + e.insert(v); +LL + } +LL + std::collections::hash_map::Entry::Occupied(mut e) => { +LL + e.insert(v2); ... error: usage of `contains_key` followed by `insert` on a `HashMap` @@ -31,12 +31,12 @@ LL | | } | help: try this | -LL | match m.entry(k) { -LL | std::collections::hash_map::Entry::Occupied(mut e) => { -LL | e.insert(v); -LL | } -LL | std::collections::hash_map::Entry::Vacant(e) => { -LL | e.insert(v2); +LL ~ match m.entry(k) { +LL + std::collections::hash_map::Entry::Occupied(mut e) => { +LL + e.insert(v); +LL + } +LL + std::collections::hash_map::Entry::Vacant(e) => { +LL + e.insert(v2); ... error: usage of `contains_key` followed by `insert` on a `HashMap` @@ -51,11 +51,11 @@ LL | | } | help: try this | -LL | if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { -LL | e.insert(v); -LL | } else { -LL | foo(); -LL | } +LL ~ if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { +LL + e.insert(v); +LL + } else { +LL + foo(); +LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` @@ -70,11 +70,11 @@ LL | | } | help: try this | -LL | if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) { -LL | e.insert(v); -LL | } else { -LL | foo(); -LL | } +LL ~ if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) { +LL + e.insert(v); +LL + } else { +LL + foo(); +LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` @@ -89,12 +89,12 @@ LL | | } | help: try this | -LL | match m.entry(k) { -LL | std::collections::hash_map::Entry::Vacant(e) => { -LL | e.insert(v); -LL | } -LL | std::collections::hash_map::Entry::Occupied(mut e) => { -LL | e.insert(v2); +LL ~ match m.entry(k) { +LL + std::collections::hash_map::Entry::Vacant(e) => { +LL + e.insert(v); +LL + } +LL + std::collections::hash_map::Entry::Occupied(mut e) => { +LL + e.insert(v2); ... error: usage of `contains_key` followed by `insert` on a `HashMap` @@ -109,12 +109,12 @@ LL | | }; | help: try this | -LL | match m.entry(k) { -LL | std::collections::hash_map::Entry::Occupied(mut e) => { -LL | if true { Some(e.insert(v)) } else { Some(e.insert(v2)) } -LL | } -LL | std::collections::hash_map::Entry::Vacant(e) => { -LL | e.insert(v); +LL ~ match m.entry(k) { +LL + std::collections::hash_map::Entry::Occupied(mut e) => { +LL + if true { Some(e.insert(v)) } else { Some(e.insert(v2)) } +LL + } +LL + std::collections::hash_map::Entry::Vacant(e) => { +LL + e.insert(v); ... error: usage of `contains_key` followed by `insert` on a `HashMap` @@ -130,12 +130,12 @@ LL | | }; | help: try this | -LL | if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) { -LL | foo(); -LL | Some(e.insert(v)) -LL | } else { -LL | None -LL | }; +LL ~ if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) { +LL + foo(); +LL + Some(e.insert(v)) +LL + } else { +LL + None +LL ~ }; | error: aborting due to 7 previous errors diff --git a/tests/ui/eprint_with_newline.stderr b/tests/ui/eprint_with_newline.stderr index 31811d1d92a0..090dae3733d9 100644 --- a/tests/ui/eprint_with_newline.stderr +++ b/tests/ui/eprint_with_newline.stderr @@ -7,8 +7,9 @@ LL | eprint!("Hello/n"); = note: `-D clippy::print-with-newline` implied by `-D warnings` help: use `eprintln!` instead | -LL | eprintln!("Hello"); - | ^^^^^^^^ -- +LL - eprint!("Hello/n"); +LL + eprintln!("Hello"); + | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:6:5 @@ -18,8 +19,9 @@ LL | eprint!("Hello {}/n", "world"); | help: use `eprintln!` instead | -LL | eprintln!("Hello {}", "world"); - | ^^^^^^^^ -- +LL - eprint!("Hello {}/n", "world"); +LL + eprintln!("Hello {}", "world"); + | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:7:5 @@ -29,8 +31,9 @@ LL | eprint!("Hello {} {}/n", "world", "#2"); | help: use `eprintln!` instead | -LL | eprintln!("Hello {} {}", "world", "#2"); - | ^^^^^^^^ -- +LL - eprint!("Hello {} {}/n", "world", "#2"); +LL + eprintln!("Hello {} {}", "world", "#2"); + | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:8:5 @@ -40,8 +43,9 @@ LL | eprint!("{}/n", 1265); | help: use `eprintln!` instead | -LL | eprintln!("{}", 1265); - | ^^^^^^^^ -- +LL - eprint!("{}/n", 1265); +LL + eprintln!("{}", 1265); + | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:9:5 @@ -51,8 +55,9 @@ LL | eprint!("/n"); | help: use `eprintln!` instead | -LL | eprintln!(); - | ^^^^^^^^ -- +LL - eprint!("/n"); +LL + eprintln!(); + | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:28:5 @@ -62,8 +67,9 @@ LL | eprint!("//n"); // should fail | help: use `eprintln!` instead | -LL | eprintln!("/"); // should fail - | ^^^^^^^^ -- +LL - eprint!("//n"); // should fail +LL + eprintln!("/"); // should fail + | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:35:5 @@ -76,8 +82,8 @@ LL | | ); | help: use `eprintln!` instead | -LL | eprintln!( -LL | "" +LL ~ eprintln!( +LL ~ "" | error: using `eprint!()` with a format string that ends in a single newline @@ -91,8 +97,8 @@ LL | | ); | help: use `eprintln!` instead | -LL | eprintln!( -LL | r"" +LL ~ eprintln!( +LL ~ r"" | error: using `eprint!()` with a format string that ends in a single newline @@ -103,8 +109,9 @@ LL | eprint!("/r/n"); //~ ERROR | help: use `eprintln!` instead | -LL | eprintln!("/r"); //~ ERROR - | ^^^^^^^^ -- +LL - eprint!("/r/n"); //~ ERROR +LL + eprintln!("/r"); //~ ERROR + | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:48:5 @@ -114,8 +121,9 @@ LL | eprint!("foo/rbar/n") // ~ ERROR | help: use `eprintln!` instead | -LL | eprintln!("foo/rbar") // ~ ERROR - | ^^^^^^^^ -- +LL - eprint!("foo/rbar/n") // ~ ERROR +LL + eprintln!("foo/rbar") // ~ ERROR + | error: aborting due to 10 previous errors diff --git a/tests/ui/exhaustive_items.stderr b/tests/ui/exhaustive_items.stderr index 8fbab535a9b2..f46ebd477b8f 100644 --- a/tests/ui/exhaustive_items.stderr +++ b/tests/ui/exhaustive_items.stderr @@ -16,8 +16,8 @@ LL | #![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try adding #[non_exhaustive] | -LL | #[non_exhaustive] -LL | pub enum Exhaustive { +LL ~ #[non_exhaustive] +LL ~ pub enum Exhaustive { | error: exported enums should not be exhaustive @@ -33,8 +33,8 @@ LL | | } | help: try adding #[non_exhaustive] | -LL | #[non_exhaustive] -LL | pub enum ExhaustiveWithAttrs { +LL ~ #[non_exhaustive] +LL ~ pub enum ExhaustiveWithAttrs { | error: exported structs should not be exhaustive @@ -53,8 +53,8 @@ LL | #![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try adding #[non_exhaustive] | -LL | #[non_exhaustive] -LL | pub struct Exhaustive { +LL ~ #[non_exhaustive] +LL ~ pub struct Exhaustive { | error: aborting due to 3 previous errors diff --git a/tests/ui/for_kv_map.stderr b/tests/ui/for_kv_map.stderr index 241758c542cf..e5cc7c1466ab 100644 --- a/tests/ui/for_kv_map.stderr +++ b/tests/ui/for_kv_map.stderr @@ -8,7 +8,7 @@ LL | for (_, v) in &m { help: use the corresponding method | LL | for v in m.values() { - | ^ ^^^^^^^^^^ + | ~ ~~~~~~~~~~ error: you seem to want to iterate on a map's values --> $DIR/for_kv_map.rs:14:19 @@ -19,7 +19,7 @@ LL | for (_, v) in &*m { help: use the corresponding method | LL | for v in (*m).values() { - | ^ ^^^^^^^^^^^^^ + | ~ ~~~~~~~~~~~~~ error: you seem to want to iterate on a map's values --> $DIR/for_kv_map.rs:22:19 @@ -30,7 +30,7 @@ LL | for (_, v) in &mut m { help: use the corresponding method | LL | for v in m.values_mut() { - | ^ ^^^^^^^^^^^^^^ + | ~ ~~~~~~~~~~~~~~ error: you seem to want to iterate on a map's values --> $DIR/for_kv_map.rs:27:19 @@ -41,7 +41,7 @@ LL | for (_, v) in &mut *m { help: use the corresponding method | LL | for v in (*m).values_mut() { - | ^ ^^^^^^^^^^^^^^^^^ + | ~ ~~~~~~~~~~~~~~~~~ error: you seem to want to iterate on a map's keys --> $DIR/for_kv_map.rs:33:24 @@ -52,7 +52,7 @@ LL | for (k, _value) in rm { help: use the corresponding method | LL | for k in rm.keys() { - | ^ ^^^^^^^^^ + | ~ ~~~~~~~~~ error: aborting due to 5 previous errors diff --git a/tests/ui/format.stderr b/tests/ui/format.stderr index 2017eb2b3838..496a083497df 100644 --- a/tests/ui/format.stderr +++ b/tests/ui/format.stderr @@ -29,8 +29,8 @@ LL | | ); | help: consider using `.to_string()` | -LL | r##"foo {} -LL | " bar"##.to_string(); +LL ~ r##"foo {} +LL + " bar"##.to_string(); | error: useless use of `format!` diff --git a/tests/ui/if_let_some_result.stderr b/tests/ui/if_let_some_result.stderr index 0646dd27f35e..134ce9d24116 100644 --- a/tests/ui/if_let_some_result.stderr +++ b/tests/ui/if_let_some_result.stderr @@ -8,7 +8,7 @@ LL | if let Some(y) = x.parse().ok() { y } else { 0 } help: consider matching on `Ok(y)` and removing the call to `ok` instead | LL | if let Ok(y) = x.parse() { y } else { 0 } - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~~ error: matching on `Some` with `ok()` is redundant --> $DIR/if_let_some_result.rs:16:9 @@ -19,7 +19,7 @@ LL | if let Some(y) = x . parse() . ok () { help: consider matching on `Ok(y)` and removing the call to `ok` instead | LL | if let Ok(y) = x . parse() { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 2 previous errors diff --git a/tests/ui/implicit_hasher.stderr b/tests/ui/implicit_hasher.stderr index 41ca6485c4c9..2e62dd30f9fc 100644 --- a/tests/ui/implicit_hasher.stderr +++ b/tests/ui/implicit_hasher.stderr @@ -12,11 +12,11 @@ LL | #![deny(clippy::implicit_hasher)] help: consider adding a type parameter | LL | impl Foo for HashMap { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ help: ...and use generic constructor | LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) - | ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: impl for `HashMap` should be generalized over different hashers --> $DIR/implicit_hasher.rs:25:36 @@ -27,11 +27,11 @@ LL | impl Foo for (HashMap,) { help: consider adding a type parameter | LL | impl Foo for (HashMap,) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ help: ...and use generic constructor | LL | ((HashMap::default(),), (HashMap::with_capacity_and_hasher(10, Default::default()),)) - | ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: impl for `HashMap` should be generalized over different hashers --> $DIR/implicit_hasher.rs:30:19 @@ -42,11 +42,11 @@ LL | impl Foo for HashMap { help: consider adding a type parameter | LL | impl Foo for HashMap { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +++++++++++++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~~~~~~~ help: ...and use generic constructor | LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) - | ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: impl for `HashSet` should be generalized over different hashers --> $DIR/implicit_hasher.rs:47:32 @@ -57,11 +57,11 @@ LL | impl Foo for HashSet { help: consider adding a type parameter | LL | impl Foo for HashSet { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~ help: ...and use generic constructor | LL | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) - | ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: impl for `HashSet` should be generalized over different hashers --> $DIR/implicit_hasher.rs:52:19 @@ -72,11 +72,11 @@ LL | impl Foo for HashSet { help: consider adding a type parameter | LL | impl Foo for HashSet { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ + | +++++++++++++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~ help: ...and use generic constructor | LL | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) - | ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: parameter of type `HashMap` should be generalized over different hashers --> $DIR/implicit_hasher.rs:69:23 @@ -87,7 +87,7 @@ LL | pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} help: consider adding a type parameter | LL | pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~ error: parameter of type `HashSet` should be generalized over different hashers --> $DIR/implicit_hasher.rs:69:53 @@ -98,7 +98,7 @@ LL | pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} help: consider adding a type parameter | LL | pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ + | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~ error: impl for `HashMap` should be generalized over different hashers --> $DIR/implicit_hasher.rs:73:43 @@ -113,11 +113,11 @@ LL | gen!(impl); help: consider adding a type parameter | LL | impl Foo for HashMap { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ help: ...and use generic constructor | LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) - | ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: parameter of type `HashMap` should be generalized over different hashers --> $DIR/implicit_hasher.rs:81:33 @@ -132,7 +132,7 @@ LL | gen!(fn bar); help: consider adding a type parameter | LL | pub fn $name(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~ error: parameter of type `HashSet` should be generalized over different hashers --> $DIR/implicit_hasher.rs:81:63 @@ -147,7 +147,7 @@ LL | gen!(fn bar); help: consider adding a type parameter | LL | pub fn $name(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ + | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~ error: aborting due to 10 previous errors diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr index 16fe9ed444ff..5e078b15ce39 100644 --- a/tests/ui/implicit_return.stderr +++ b/tests/ui/implicit_return.stderr @@ -94,9 +94,9 @@ LL | | } | help: add `return` as shown | -LL | return loop { -LL | m!(true); -LL | } +LL ~ return loop { +LL + m!(true); +LL + } | error: missing `return` statement diff --git a/tests/ui/large_enum_variant.stderr b/tests/ui/large_enum_variant.stderr index d39a4d462aab..0eac28fbd350 100644 --- a/tests/ui/large_enum_variant.stderr +++ b/tests/ui/large_enum_variant.stderr @@ -13,7 +13,7 @@ LL | A(i32), help: consider boxing the large fields to reduce the total size of the enum | LL | B(Box<[i32; 8000]>), - | ^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~ error: large size difference between variants --> $DIR/large_enum_variant.rs:36:5 @@ -29,7 +29,7 @@ LL | VariantOk(i32, u32), help: consider boxing the large fields to reduce the total size of the enum | LL | ContainingLargeEnum(Box), - | ^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~ error: large size difference between variants --> $DIR/large_enum_variant.rs:46:5 @@ -62,7 +62,7 @@ LL | VariantOk(i32, u32), help: consider boxing the large fields to reduce the total size of the enum | LL | StructLikeLarge2 { x: Box<[i32; 8000]> }, - | ^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~ error: aborting due to 4 previous errors diff --git a/tests/ui/let_and_return.stderr b/tests/ui/let_and_return.stderr index a6941dabeb88..17fd694bf7ac 100644 --- a/tests/ui/let_and_return.stderr +++ b/tests/ui/let_and_return.stderr @@ -9,8 +9,8 @@ LL | x = note: `-D clippy::let-and-return` implied by `-D warnings` help: return the expression directly | -LL | -LL | 5 +LL ~ +LL ~ 5 | error: returning the result of a `let` binding from a block @@ -23,8 +23,8 @@ LL | x | help: return the expression directly | -LL | -LL | 5 +LL ~ +LL ~ 5 | error: returning the result of a `let` binding from a block @@ -37,8 +37,8 @@ LL | clone | help: return the expression directly | -LL | -LL | Arc::clone(&self.foo) as _ +LL ~ +LL ~ Arc::clone(&self.foo) as _ | error: aborting due to 3 previous errors diff --git a/tests/ui/let_unit.stderr b/tests/ui/let_unit.stderr index eb8482087bcc..f2600c6c2288 100644 --- a/tests/ui/let_unit.stderr +++ b/tests/ui/let_unit.stderr @@ -26,12 +26,12 @@ LL | | .unwrap(); | help: omit the `let` binding | -LL | v -LL | .into_iter() -LL | .map(|i| i * 2) -LL | .filter(|i| i % 2 == 0) -LL | .map(|_| ()) -LL | .next() +LL ~ v +LL + .into_iter() +LL + .map(|i| i * 2) +LL + .filter(|i| i % 2 == 0) +LL + .map(|_| ()) +LL + .next() ... error: aborting due to 3 previous errors diff --git a/tests/ui/literals.stderr b/tests/ui/literals.stderr index 64ceeb316d8e..99542e20f785 100644 --- a/tests/ui/literals.stderr +++ b/tests/ui/literals.stderr @@ -28,11 +28,11 @@ LL | let fail_multi_zero = 000_123usize; help: if you mean to use a decimal constant, remove the `0` to avoid confusion | LL | let fail_multi_zero = 123usize; - | ^^^^^^^^ + | ~~~~~~~~ help: if you mean to use an octal constant, use `0o` | LL | let fail_multi_zero = 0o123usize; - | ^^^^^^^^^^ + | ~~~~~~~~~~ error: this is a decimal constant --> $DIR/literals.rs:21:17 @@ -43,11 +43,11 @@ LL | let fail8 = 0123; help: if you mean to use a decimal constant, remove the `0` to avoid confusion | LL | let fail8 = 123; - | ^^^ + | ~~~ help: if you mean to use an octal constant, use `0o` | LL | let fail8 = 0o123; - | ^^^^^ + | ~~~~~ error: digits grouped inconsistently by underscores --> $DIR/literals.rs:33:18 diff --git a/tests/ui/manual_async_fn.stderr b/tests/ui/manual_async_fn.stderr index fdd43db3255e..51f1a52b6dd6 100644 --- a/tests/ui/manual_async_fn.stderr +++ b/tests/ui/manual_async_fn.stderr @@ -8,11 +8,11 @@ LL | fn fut() -> impl Future { help: make the function `async` and return the output of the future directly | LL | async fn fut() -> i32 { - | ^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~ help: move the body of the async block to the enclosing function | LL | fn fut() -> impl Future { 42 } - | ^^^^^^ + | ~~~~~~ error: this function can be simplified using the `async fn` syntax --> $DIR/manual_async_fn.rs:13:1 @@ -23,11 +23,11 @@ LL | fn fut2() ->impl Future { help: make the function `async` and return the output of the future directly | LL | async fn fut2() -> i32 { - | ^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~ help: move the body of the async block to the enclosing function | LL | fn fut2() ->impl Future { 42 } - | ^^^^^^ + | ~~~~~~ error: this function can be simplified using the `async fn` syntax --> $DIR/manual_async_fn.rs:18:1 @@ -38,11 +38,11 @@ LL | fn fut3()-> impl Future { help: make the function `async` and return the output of the future directly | LL | async fn fut3() -> i32 { - | ^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~ help: move the body of the async block to the enclosing function | LL | fn fut3()-> impl Future { 42 } - | ^^^^^^ + | ~~~~~~ error: this function can be simplified using the `async fn` syntax --> $DIR/manual_async_fn.rs:22:1 @@ -53,11 +53,11 @@ LL | fn empty_fut() -> impl Future { help: make the function `async` and remove the return type | LL | async fn empty_fut() { - | ^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~ help: move the body of the async block to the enclosing function | LL | fn empty_fut() -> impl Future {} - | ^^ + | ~~ error: this function can be simplified using the `async fn` syntax --> $DIR/manual_async_fn.rs:27:1 @@ -68,11 +68,11 @@ LL | fn empty_fut2() ->impl Future { help: make the function `async` and remove the return type | LL | async fn empty_fut2() { - | ^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~ help: move the body of the async block to the enclosing function | LL | fn empty_fut2() ->impl Future {} - | ^^ + | ~~ error: this function can be simplified using the `async fn` syntax --> $DIR/manual_async_fn.rs:32:1 @@ -83,11 +83,11 @@ LL | fn empty_fut3()-> impl Future { help: make the function `async` and remove the return type | LL | async fn empty_fut3() { - | ^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~ help: move the body of the async block to the enclosing function | LL | fn empty_fut3()-> impl Future {} - | ^^ + | ~~ error: this function can be simplified using the `async fn` syntax --> $DIR/manual_async_fn.rs:36:1 @@ -98,11 +98,11 @@ LL | fn core_fut() -> impl core::future::Future { help: make the function `async` and return the output of the future directly | LL | async fn core_fut() -> i32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ help: move the body of the async block to the enclosing function | LL | fn core_fut() -> impl core::future::Future { 42 } - | ^^^^^^ + | ~~~~~~ error: this function can be simplified using the `async fn` syntax --> $DIR/manual_async_fn.rs:58:5 @@ -113,15 +113,15 @@ LL | fn inh_fut() -> impl Future { help: make the function `async` and return the output of the future directly | LL | async fn inh_fut() -> i32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~~~ help: move the body of the async block to the enclosing function | -LL | fn inh_fut() -> impl Future { -LL | // NOTE: this code is here just to check that the indentation is correct in the suggested fix -LL | let a = 42; -LL | let b = 21; -LL | if a < b { -LL | let c = 21; +LL ~ fn inh_fut() -> impl Future { +LL + // NOTE: this code is here just to check that the indentation is correct in the suggested fix +LL + let a = 42; +LL + let b = 21; +LL + if a < b { +LL + let c = 21; ... error: this function can be simplified using the `async fn` syntax @@ -133,11 +133,11 @@ LL | fn elided(_: &i32) -> impl Future + '_ { help: make the function `async` and return the output of the future directly | LL | async fn elided(_: &i32) -> i32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ help: move the body of the async block to the enclosing function | LL | fn elided(_: &i32) -> impl Future + '_ { 42 } - | ^^^^^^ + | ~~~~~~ error: this function can be simplified using the `async fn` syntax --> $DIR/manual_async_fn.rs:102:1 @@ -148,11 +148,11 @@ LL | fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + help: make the function `async` and return the output of the future directly | LL | async fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> i32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ help: move the body of the async block to the enclosing function | LL | fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { 42 } - | ^^^^^^ + | ~~~~~~ error: aborting due to 10 previous errors diff --git a/tests/ui/manual_memcpy/with_loop_counters.stderr b/tests/ui/manual_memcpy/with_loop_counters.stderr index a2f2dfce168d..0243158dec50 100644 --- a/tests/ui/manual_memcpy/with_loop_counters.stderr +++ b/tests/ui/manual_memcpy/with_loop_counters.stderr @@ -85,8 +85,8 @@ LL | | } | help: try replacing the loop by | -LL | dst[3..(src.len() + 3)].clone_from_slice(&src[..]); -LL | dst2[30..(src.len() + 30)].clone_from_slice(&src[..]); +LL ~ dst[3..(src.len() + 3)].clone_from_slice(&src[..]); +LL + dst2[30..(src.len() + 30)].clone_from_slice(&src[..]); | error: it looks like you're manually copying between slices diff --git a/tests/ui/manual_memcpy/without_loop_counters.stderr b/tests/ui/manual_memcpy/without_loop_counters.stderr index 54b966f6e541..8ff0137a8120 100644 --- a/tests/ui/manual_memcpy/without_loop_counters.stderr +++ b/tests/ui/manual_memcpy/without_loop_counters.stderr @@ -51,8 +51,8 @@ LL | | } | help: try replacing the loop by | -LL | dst[10..256].clone_from_slice(&src[(10 - 5)..(256 - 5)]); -LL | dst2[(10 + 500)..(256 + 500)].clone_from_slice(&src[10..256]); +LL ~ dst[10..256].clone_from_slice(&src[(10 - 5)..(256 - 5)]); +LL + dst2[(10 + 500)..(256 + 500)].clone_from_slice(&src[10..256]); | error: it looks like you're manually copying between slices diff --git a/tests/ui/manual_ok_or.stderr b/tests/ui/manual_ok_or.stderr index 8ea10ac54363..65459a097384 100644 --- a/tests/ui/manual_ok_or.stderr +++ b/tests/ui/manual_ok_or.stderr @@ -32,9 +32,9 @@ LL | | ); | help: replace with | -LL | foo.ok_or(&format!( -LL | "{}{}{}{}{}{}{}", -LL | "Alice", "Bob", "Sarah", "Marc", "Sandra", "Eric", "Jenifer")); +LL ~ foo.ok_or(&format!( +LL + "{}{}{}{}{}{}{}", +LL ~ "Alice", "Bob", "Sarah", "Marc", "Sandra", "Eric", "Jenifer")); | error: aborting due to 4 previous errors diff --git a/tests/ui/manual_strip.stderr b/tests/ui/manual_strip.stderr index 1352a8713d4f..896edf2ae516 100644 --- a/tests/ui/manual_strip.stderr +++ b/tests/ui/manual_strip.stderr @@ -12,12 +12,12 @@ LL | if s.starts_with("ab") { | ^^^^^^^^^^^^^^^^^^^^^^^ help: try using the `strip_prefix` method | -LL | if let Some() = s.strip_prefix("ab") { -LL | str::to_string(); -LL | .to_string(); +LL ~ if let Some() = s.strip_prefix("ab") { +LL ~ str::to_string(); +LL ~ .to_string(); LL | -LL | str::to_string(); -LL | .to_string(); +LL ~ str::to_string(); +LL ~ .to_string(); | error: stripping a suffix manually @@ -33,12 +33,12 @@ LL | if s.ends_with("bc") { | ^^^^^^^^^^^^^^^^^^^^^ help: try using the `strip_suffix` method | -LL | if let Some() = s.strip_suffix("bc") { -LL | str::to_string(); -LL | .to_string(); +LL ~ if let Some() = s.strip_suffix("bc") { +LL ~ str::to_string(); +LL ~ .to_string(); LL | -LL | str::to_string(); -LL | .to_string(); +LL ~ str::to_string(); +LL ~ .to_string(); | error: stripping a prefix manually @@ -54,9 +54,9 @@ LL | if s.starts_with('a') { | ^^^^^^^^^^^^^^^^^^^^^^ help: try using the `strip_prefix` method | -LL | if let Some() = s.strip_prefix('a') { -LL | str::to_string(); -LL | .to_string(); +LL ~ if let Some() = s.strip_prefix('a') { +LL ~ str::to_string(); +LL ~ .to_string(); | error: stripping a prefix manually @@ -72,8 +72,8 @@ LL | if s.starts_with(prefix) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using the `strip_prefix` method | -LL | if let Some() = s.strip_prefix(prefix) { -LL | str::to_string(); +LL ~ if let Some() = s.strip_prefix(prefix) { +LL ~ str::to_string(); | error: stripping a prefix manually @@ -89,9 +89,9 @@ LL | if s.starts_with(PREFIX) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using the `strip_prefix` method | -LL | if let Some() = s.strip_prefix(PREFIX) { -LL | str::to_string(); -LL | str::to_string(); +LL ~ if let Some() = s.strip_prefix(PREFIX) { +LL ~ str::to_string(); +LL ~ str::to_string(); | error: stripping a prefix manually @@ -107,8 +107,8 @@ LL | if TARGET.starts_with(prefix) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using the `strip_prefix` method | -LL | if let Some() = TARGET.strip_prefix(prefix) { -LL | str::to_string(); +LL ~ if let Some() = TARGET.strip_prefix(prefix) { +LL ~ str::to_string(); | error: stripping a prefix manually @@ -124,8 +124,8 @@ LL | if s1.starts_with("ab") { | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try using the `strip_prefix` method | -LL | if let Some() = s1.strip_prefix("ab") { -LL | .to_uppercase(); +LL ~ if let Some() = s1.strip_prefix("ab") { +LL ~ .to_uppercase(); | error: aborting due to 7 previous errors diff --git a/tests/ui/manual_unwrap_or.stderr b/tests/ui/manual_unwrap_or.stderr index 99625b789b6a..0e4cb798d455 100644 --- a/tests/ui/manual_unwrap_or.stderr +++ b/tests/ui/manual_unwrap_or.stderr @@ -41,11 +41,11 @@ LL | | }; | help: replace with | -LL | Some(1).unwrap_or({ -LL | 42 + 42 -LL | + 42 + 42 + 42 -LL | + 42 + 42 + 42 -LL | }); +LL ~ Some(1).unwrap_or({ +LL + 42 + 42 +LL + + 42 + 42 + 42 +LL + + 42 + 42 + 42 +LL ~ }); | error: this pattern reimplements `Option::unwrap_or` @@ -125,11 +125,11 @@ LL | | }; | help: replace with | -LL | Ok::(1).unwrap_or({ -LL | 42 + 42 -LL | + 42 + 42 + 42 -LL | + 42 + 42 + 42 -LL | }); +LL ~ Ok::(1).unwrap_or({ +LL + 42 + 42 +LL + + 42 + 42 + 42 +LL + + 42 + 42 + 42 +LL ~ }); | error: this pattern reimplements `Result::unwrap_or` diff --git a/tests/ui/map_unwrap_or.stderr b/tests/ui/map_unwrap_or.stderr index 96b9d6cc3c14..954000b8b76d 100644 --- a/tests/ui/map_unwrap_or.stderr +++ b/tests/ui/map_unwrap_or.stderr @@ -10,8 +10,9 @@ LL | | .unwrap_or(0); = note: `-D clippy::map-unwrap-or` implied by `-D warnings` help: use `map_or(, )` instead | -LL | let _ = opt.map_or(0, |x| x + 1); - | ^^^^^^ ^^ -- +LL - let _ = opt.map(|x| x + 1) +LL + let _ = opt.map_or(0, |x| x + 1); + | error: called `map().unwrap_or()` on an `Option` value. This can be done more directly by calling `map_or(, )` instead --> $DIR/map_unwrap_or.rs:20:13 @@ -25,10 +26,10 @@ LL | | ).unwrap_or(0); | help: use `map_or(, )` instead | -LL | let _ = opt.map_or(0, |x| { +LL ~ let _ = opt.map_or(0, |x| { LL | x + 1 LL | } -LL | ); +LL ~ ); | error: called `map().unwrap_or()` on an `Option` value. This can be done more directly by calling `map_or(, )` instead @@ -43,9 +44,9 @@ LL | | }); | help: use `map_or(, )` instead | -LL | let _ = opt.map_or({ -LL | 0 -LL | }, |x| x + 1); +LL ~ let _ = opt.map_or({ +LL + 0 +LL ~ }, |x| x + 1); | error: called `map().unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then()` instead @@ -56,8 +57,9 @@ LL | let _ = opt.map(|x| Some(x + 1)).unwrap_or(None); | help: use `and_then()` instead | -LL | let _ = opt.and_then(|x| Some(x + 1)); - | ^^^^^^^^ -- +LL - let _ = opt.map(|x| Some(x + 1)).unwrap_or(None); +LL + let _ = opt.and_then(|x| Some(x + 1)); + | error: called `map().unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then()` instead --> $DIR/map_unwrap_or.rs:31:13 @@ -71,10 +73,10 @@ LL | | ).unwrap_or(None); | help: use `and_then()` instead | -LL | let _ = opt.and_then(|x| { +LL ~ let _ = opt.and_then(|x| { LL | Some(x + 1) LL | } -LL | ); +LL ~ ); | error: called `map().unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then()` instead @@ -88,8 +90,9 @@ LL | | .unwrap_or(None); | help: use `and_then()` instead | -LL | .and_then(|x| Some(x + 1)); - | ^^^^^^^^ -- +LL - .map(|x| Some(x + 1)) +LL + .and_then(|x| Some(x + 1)); + | error: called `map().unwrap_or()` on an `Option` value. This can be done more directly by calling `map_or(, )` instead --> $DIR/map_unwrap_or.rs:46:13 @@ -99,8 +102,9 @@ LL | let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id); | help: use `map_or(, )` instead | -LL | let _ = Some("prefix").map_or(id, |p| format!("{}.", p)); - | ^^^^^^ ^^^ -- +LL - let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id); +LL + let _ = Some("prefix").map_or(id, |p| format!("{}.", p)); + | error: called `map().unwrap_or_else()` on an `Option` value. This can be done more directly by calling `map_or_else(, )` instead --> $DIR/map_unwrap_or.rs:50:13 diff --git a/tests/ui/match_bool.stderr b/tests/ui/match_bool.stderr index 1ad78c740c68..3fd0468e51de 100644 --- a/tests/ui/match_bool.stderr +++ b/tests/ui/match_bool.stderr @@ -43,9 +43,9 @@ LL | | }; | help: consider using an `if`/`else` expression | -LL | if !test { -LL | println!("Noooo!"); -LL | }; +LL ~ if !test { +LL + println!("Noooo!"); +LL ~ }; | error: you seem to be trying to match on a boolean expression @@ -61,9 +61,9 @@ LL | | }; | help: consider using an `if`/`else` expression | -LL | if !test { -LL | println!("Noooo!"); -LL | }; +LL ~ if !test { +LL + println!("Noooo!"); +LL ~ }; | error: you seem to be trying to match on a boolean expression @@ -79,9 +79,9 @@ LL | | }; | help: consider using an `if`/`else` expression | -LL | if !(test && test) { -LL | println!("Noooo!"); -LL | }; +LL ~ if !(test && test) { +LL + println!("Noooo!"); +LL ~ }; | error: equal expressions as operands to `&&` @@ -106,11 +106,11 @@ LL | | }; | help: consider using an `if`/`else` expression | -LL | if test { -LL | println!("Yes!"); -LL | } else { -LL | println!("Noooo!"); -LL | }; +LL ~ if test { +LL + println!("Yes!"); +LL + } else { +LL + println!("Noooo!"); +LL ~ }; | error: aborting due to 8 previous errors diff --git a/tests/ui/match_expr_like_matches_macro.stderr b/tests/ui/match_expr_like_matches_macro.stderr index f27b4e9cb20b..366ef36c367b 100644 --- a/tests/ui/match_expr_like_matches_macro.stderr +++ b/tests/ui/match_expr_like_matches_macro.stderr @@ -123,8 +123,8 @@ LL | | }; = note: `-D clippy::match-ref-pats` implied by `-D warnings` help: try | -LL | let _res = match val { -LL | Some(ref _a) => true, +LL ~ let _res = match val { +LL ~ Some(ref _a) => true, | error: match expression looks like `matches!` macro @@ -149,8 +149,8 @@ LL | | }; | help: try | -LL | let _res = match val { -LL | Some(ref _a) => true, +LL ~ let _res = match val { +LL ~ Some(ref _a) => true, | error: aborting due to 14 previous errors diff --git a/tests/ui/match_ref_pats.stderr b/tests/ui/match_ref_pats.stderr index 67474e65cde4..a57a338b2763 100644 --- a/tests/ui/match_ref_pats.stderr +++ b/tests/ui/match_ref_pats.stderr @@ -10,9 +10,9 @@ LL | | } = note: `-D clippy::match-ref-pats` implied by `-D warnings` help: instead of prefixing all patterns with `&`, you can dereference the expression | -LL | match *v { -LL | Some(v) => println!("{:?}", v), -LL | None => println!("none"), +LL ~ match *v { +LL ~ Some(v) => println!("{:?}", v), +LL ~ None => println!("none"), | error: you don't need to add `&` to all patterns @@ -26,8 +26,8 @@ LL | | } | help: instead of prefixing all patterns with `&`, you can dereference the expression | -LL | match *tup { -LL | (v, 1) => println!("{}", v), +LL ~ match *tup { +LL ~ (v, 1) => println!("{}", v), | error: you don't need to add `&` to both the expression and the patterns @@ -41,9 +41,9 @@ LL | | } | help: try | -LL | match w { -LL | Some(v) => println!("{:?}", v), -LL | None => println!("none"), +LL ~ match w { +LL ~ Some(v) => println!("{:?}", v), +LL ~ None => println!("none"), | error: redundant pattern matching, consider using `is_none()` @@ -65,7 +65,7 @@ LL | | } help: instead of prefixing all patterns with `&`, you can dereference the expression | LL | if let None = *a { - | ^^^^ ^^ + | ~~~~ ~~ error: redundant pattern matching, consider using `is_none()` --> $DIR/match_ref_pats.rs:40:12 @@ -84,7 +84,7 @@ LL | | } help: try | LL | if let None = b { - | ^^^^ ^ + | ~~~~ ~ error: you don't need to add `&` to all patterns --> $DIR/match_ref_pats.rs:67:9 @@ -97,8 +97,8 @@ LL | | } | help: instead of prefixing all patterns with `&`, you can dereference the expression | -LL | match *foo_variant!(0) { -LL | Foo::A => println!("A"), +LL ~ match *foo_variant!(0) { +LL ~ Foo::A => println!("A"), | error: aborting due to 8 previous errors diff --git a/tests/ui/match_single_binding.stderr b/tests/ui/match_single_binding.stderr index 795c8c3e24d7..291fa77dc2ee 100644 --- a/tests/ui/match_single_binding.stderr +++ b/tests/ui/match_single_binding.stderr @@ -11,10 +11,10 @@ LL | | } = note: `-D clippy::match-single-binding` implied by `-D warnings` help: consider using `let` statement | -LL | let (x, y, z) = (a, b, c); -LL | { -LL | println!("{} {} {}", x, y, z); -LL | } +LL ~ let (x, y, z) = (a, b, c); +LL + { +LL + println!("{} {} {}", x, y, z); +LL + } | error: this match could be written as a `let` statement @@ -27,8 +27,8 @@ LL | | } | help: consider using `let` statement | -LL | let (x, y, z) = (a, b, c); -LL | println!("{} {} {}", x, y, z); +LL ~ let (x, y, z) = (a, b, c); +LL + println!("{} {} {}", x, y, z); | error: this match could be replaced by its body itself @@ -52,10 +52,10 @@ LL | | } | help: consider using the match body instead | -LL | { -LL | let x = 29; -LL | println!("x has a value of {}", x); -LL | } +LL ~ { +LL + let x = 29; +LL + println!("x has a value of {}", x); +LL + } | error: this match could be replaced by its body itself @@ -72,12 +72,12 @@ LL | | } | help: consider using the match body instead | -LL | { -LL | let e = 5 * a; -LL | if e >= 5 { -LL | println!("e is superior to 5"); -LL | } -LL | } +LL ~ { +LL + let e = 5 * a; +LL + if e >= 5 { +LL + println!("e is superior to 5"); +LL + } +LL + } | error: this match could be written as a `let` statement @@ -90,8 +90,8 @@ LL | | } | help: consider using `let` statement | -LL | let Point { x, y } = p; -LL | println!("Coords: ({}, {})", x, y); +LL ~ let Point { x, y } = p; +LL + println!("Coords: ({}, {})", x, y); | error: this match could be written as a `let` statement @@ -104,8 +104,8 @@ LL | | } | help: consider using `let` statement | -LL | let Point { x: x1, y: y1 } = p; -LL | println!("Coords: ({}, {})", x1, y1); +LL ~ let Point { x: x1, y: y1 } = p; +LL + println!("Coords: ({}, {})", x1, y1); | error: this match could be written as a `let` statement @@ -118,8 +118,8 @@ LL | | } | help: consider using `let` statement | -LL | let ref r = x; -LL | println!("Got a reference to {}", r); +LL ~ let ref r = x; +LL + println!("Got a reference to {}", r); | error: this match could be written as a `let` statement @@ -132,8 +132,8 @@ LL | | } | help: consider using `let` statement | -LL | let ref mut mr = x; -LL | println!("Got a mutable reference to {}", mr); +LL ~ let ref mut mr = x; +LL + println!("Got a mutable reference to {}", mr); | error: this match could be written as a `let` statement @@ -146,8 +146,8 @@ LL | | }; | help: consider using `let` statement | -LL | let Point { x, y } = coords(); -LL | let product = x * y; +LL ~ let Point { x, y } = coords(); +LL + let product = x * y; | error: this match could be written as a `let` statement @@ -161,10 +161,10 @@ LL | | }) | help: consider using `let` statement | -LL | .map(|i| { -LL | let unwrapped = i.unwrap(); -LL | unwrapped -LL | }) +LL ~ .map(|i| { +LL + let unwrapped = i.unwrap(); +LL + unwrapped +LL ~ }) | error: aborting due to 11 previous errors diff --git a/tests/ui/match_single_binding2.stderr b/tests/ui/match_single_binding2.stderr index 4372f55af876..d34933194660 100644 --- a/tests/ui/match_single_binding2.stderr +++ b/tests/ui/match_single_binding2.stderr @@ -10,10 +10,10 @@ LL | | }, = note: `-D clippy::match-single-binding` implied by `-D warnings` help: consider using `let` statement | -LL | Some((iter, _item)) => { -LL | let (min, max) = iter.size_hint(); -LL | (min.saturating_add(1), max.and_then(|max| max.checked_add(1))) -LL | }, +LL ~ Some((iter, _item)) => { +LL + let (min, max) = iter.size_hint(); +LL + (min.saturating_add(1), max.and_then(|max| max.checked_add(1))) +LL ~ }, | error: this match could be written as a `let` statement @@ -26,8 +26,8 @@ LL | | } | help: consider using `let` statement | -LL | let (a, b) = get_tup(); -LL | println!("a {:?} and b {:?}", a, b); +LL ~ let (a, b) = get_tup(); +LL + println!("a {:?} and b {:?}", a, b); | error: this match could be replaced by its scrutinee and body @@ -40,8 +40,8 @@ LL | | } | help: consider using the scrutinee and body instead | -LL | side_effects(); -LL | println!("Side effects"); +LL ~ side_effects(); +LL + println!("Side effects"); | error: this match could be replaced by its scrutinee and body @@ -57,11 +57,11 @@ LL | | } | help: consider using the scrutinee and body instead | -LL | match x { -LL | 0 => 1, -LL | _ => 2, -LL | }; -LL | println!("Single branch"); +LL ~ match x { +LL + 0 => 1, +LL + _ => 2, +LL + }; +LL + println!("Single branch"); | error: aborting due to 4 previous errors diff --git a/tests/ui/min_rust_version_attr.stderr b/tests/ui/min_rust_version_attr.stderr index ddb1e1f37240..a2e4e86ed6b8 100644 --- a/tests/ui/min_rust_version_attr.stderr +++ b/tests/ui/min_rust_version_attr.stderr @@ -12,8 +12,8 @@ LL | if s.starts_with("hello, ") { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using the `strip_prefix` method | -LL | if let Some() = s.strip_prefix("hello, ") { -LL | assert_eq!(.to_uppercase(), "WORLD!"); +LL ~ if let Some() = s.strip_prefix("hello, ") { +LL ~ assert_eq!(.to_uppercase(), "WORLD!"); | error: stripping a prefix manually @@ -29,8 +29,8 @@ LL | if s.starts_with("hello, ") { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using the `strip_prefix` method | -LL | if let Some() = s.strip_prefix("hello, ") { -LL | assert_eq!(.to_uppercase(), "WORLD!"); +LL ~ if let Some() = s.strip_prefix("hello, ") { +LL ~ assert_eq!(.to_uppercase(), "WORLD!"); | error: aborting due to 2 previous errors diff --git a/tests/ui/mismatched_target_os_unix.stderr b/tests/ui/mismatched_target_os_unix.stderr index ea39f5b5577b..3534b53282f9 100644 --- a/tests/ui/mismatched_target_os_unix.stderr +++ b/tests/ui/mismatched_target_os_unix.stderr @@ -169,15 +169,15 @@ LL | #[cfg(all(not(any(solaris, linux)), freebsd))] help: try | LL | #[cfg(all(not(any(target_os = "solaris", linux)), freebsd))] - | ^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~ help: try | LL | #[cfg(all(not(any(solaris, target_os = "linux")), freebsd))] - | ^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~ help: try | LL | #[cfg(all(not(any(solaris, linux)), target_os = "freebsd"))] - | ^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 17 previous errors diff --git a/tests/ui/needless_borrow_pat.stderr b/tests/ui/needless_borrow_pat.stderr index 32913d59f7ae..365ecd68d8ff 100644 --- a/tests/ui/needless_borrow_pat.stderr +++ b/tests/ui/needless_borrow_pat.stderr @@ -15,7 +15,7 @@ LL | Some(ref x) => *x, help: try this | LL | Some(x) => x, - | ^ ^ + | ~ ~ error: this pattern creates a reference to a reference --> $DIR/needless_borrow_pat.rs:72:14 @@ -25,9 +25,9 @@ LL | Some(ref x) => { | help: try this | -LL | Some(x) => { -LL | f1(x); +LL ~ Some(x) => { LL | f1(x); +LL ~ f1(x); | error: this pattern creates a reference to a reference @@ -50,8 +50,8 @@ LL | let (ref y,) = (&x,); | help: try this | -LL | let (y,) = (&x,); -LL | let _: &String = y; +LL ~ let (y,) = (&x,); +LL ~ let _: &String = y; | error: this pattern creates a reference to a reference @@ -69,7 +69,7 @@ LL | E::A(ref x) | E::B(ref x) => *x, help: try this | LL | E::A(x) | E::B(x) => x, - | ^ ^ ^ + | ~ ~ ~ error: this pattern creates a reference to a reference --> $DIR/needless_borrow_pat.rs:118:21 @@ -85,9 +85,9 @@ LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { | help: try this | -LL | fn f2<'a>(&x: &&'a String) -> &'a String { +LL ~ fn f2<'a>(&x: &&'a String) -> &'a String { LL | let _: &String = x; -LL | x +LL ~ x | error: this pattern creates a reference to a reference @@ -104,8 +104,8 @@ LL | fn f(&ref x: &&String) { | help: try this | -LL | fn f(&x: &&String) { -LL | let _: &String = x; +LL ~ fn f(&x: &&String) { +LL ~ let _: &String = x; | error: aborting due to 12 previous errors diff --git a/tests/ui/needless_collect_indirect.stderr b/tests/ui/needless_collect_indirect.stderr index f094e182a48f..0f5e78f91198 100644 --- a/tests/ui/needless_collect_indirect.stderr +++ b/tests/ui/needless_collect_indirect.stderr @@ -9,8 +9,8 @@ LL | indirect_iter.into_iter().map(|x| (x, x + 1)).collect::>( = note: `-D clippy::needless-collect` implied by `-D warnings` help: use the original Iterator instead of collecting it and then producing a new one | -LL | -LL | sample.iter().map(|x| (x, x + 1)).collect::>(); +LL ~ +LL ~ sample.iter().map(|x| (x, x + 1)).collect::>(); | error: avoid using `collect()` when not needed @@ -23,8 +23,8 @@ LL | indirect_len.len(); | help: take the original Iterator's count instead of collecting it and finding the length | -LL | -LL | sample.iter().count(); +LL ~ +LL ~ sample.iter().count(); | error: avoid using `collect()` when not needed @@ -37,8 +37,8 @@ LL | indirect_empty.is_empty(); | help: check if the original Iterator has anything instead of collecting it and seeing if it's empty | -LL | -LL | sample.iter().next().is_none(); +LL ~ +LL ~ sample.iter().next().is_none(); | error: avoid using `collect()` when not needed @@ -51,8 +51,8 @@ LL | indirect_contains.contains(&&5); | help: check if the original Iterator contains an element instead of collecting then checking | -LL | -LL | sample.iter().any(|x| x == &5); +LL ~ +LL ~ sample.iter().any(|x| x == &5); | error: avoid using `collect()` when not needed @@ -65,8 +65,8 @@ LL | non_copy_contains.contains(&a); | help: check if the original Iterator contains an element instead of collecting then checking | -LL | -LL | sample.into_iter().any(|x| x == a); +LL ~ +LL ~ sample.into_iter().any(|x| x == a); | error: avoid using `collect()` when not needed @@ -79,8 +79,8 @@ LL | buffer.len() | help: take the original Iterator's count instead of collecting it and finding the length | -LL | -LL | string.split('/').count() +LL ~ +LL ~ string.split('/').count() | error: avoid using `collect()` when not needed @@ -93,8 +93,8 @@ LL | indirect_len.len() | help: take the original Iterator's count instead of collecting it and finding the length | -LL | -LL | sample.iter().count() +LL ~ +LL ~ sample.iter().count() | error: avoid using `collect()` when not needed @@ -107,8 +107,8 @@ LL | indirect_len.len() | help: take the original Iterator's count instead of collecting it and finding the length | -LL | -LL | sample.iter().count() +LL ~ +LL ~ sample.iter().count() | error: avoid using `collect()` when not needed @@ -121,8 +121,8 @@ LL | indirect_len.len() | help: take the original Iterator's count instead of collecting it and finding the length | -LL | -LL | sample.iter().count() +LL ~ +LL ~ sample.iter().count() | error: aborting due to 9 previous errors diff --git a/tests/ui/needless_for_each_fixable.stderr b/tests/ui/needless_for_each_fixable.stderr index 483a5e6d61d7..6487e57266c7 100644 --- a/tests/ui/needless_for_each_fixable.stderr +++ b/tests/ui/needless_for_each_fixable.stderr @@ -9,9 +9,9 @@ LL | | }); = note: `-D clippy::needless-for-each` implied by `-D warnings` help: try | -LL | for elem in v.iter() { -LL | acc += elem; -LL | } +LL ~ for elem in v.iter() { +LL + acc += elem; +LL + } | error: needless use of `for_each` @@ -24,9 +24,9 @@ LL | | }); | help: try | -LL | for elem in v.into_iter() { -LL | acc += elem; -LL | } +LL ~ for elem in v.into_iter() { +LL + acc += elem; +LL + } | error: needless use of `for_each` @@ -39,9 +39,9 @@ LL | | }); | help: try | -LL | for elem in [1, 2, 3].iter() { -LL | acc += elem; -LL | } +LL ~ for elem in [1, 2, 3].iter() { +LL + acc += elem; +LL + } | error: needless use of `for_each` @@ -54,9 +54,9 @@ LL | | }); | help: try | -LL | for (k, v) in hash_map.iter() { -LL | acc += k + v; -LL | } +LL ~ for (k, v) in hash_map.iter() { +LL + acc += k + v; +LL + } | error: needless use of `for_each` @@ -69,9 +69,9 @@ LL | | }); | help: try | -LL | for (k, v) in hash_map.iter_mut() { -LL | acc += *k + *v; -LL | } +LL ~ for (k, v) in hash_map.iter_mut() { +LL + acc += *k + *v; +LL + } | error: needless use of `for_each` @@ -84,9 +84,9 @@ LL | | }); | help: try | -LL | for k in hash_map.keys() { -LL | acc += k; -LL | } +LL ~ for k in hash_map.keys() { +LL + acc += k; +LL + } | error: needless use of `for_each` @@ -99,9 +99,9 @@ LL | | }); | help: try | -LL | for v in hash_map.values() { -LL | acc += v; -LL | } +LL ~ for v in hash_map.values() { +LL + acc += v; +LL + } | error: needless use of `for_each` @@ -114,9 +114,9 @@ LL | | }); | help: try | -LL | for elem in my_vec().iter() { -LL | acc += elem; -LL | } +LL ~ for elem in my_vec().iter() { +LL + acc += elem; +LL + } | error: aborting due to 8 previous errors diff --git a/tests/ui/needless_for_each_unfixable.stderr b/tests/ui/needless_for_each_unfixable.stderr index 8c4507d23283..f607e0a430e2 100644 --- a/tests/ui/needless_for_each_unfixable.stderr +++ b/tests/ui/needless_for_each_unfixable.stderr @@ -13,17 +13,17 @@ LL | | }); = note: `-D clippy::needless-for-each` implied by `-D warnings` help: try | -LL | for v in v.iter() { -LL | if *v == 10 { -LL | return; -LL | } else { -LL | println!("{}", v); -LL | } +LL ~ for v in v.iter() { +LL + if *v == 10 { +LL + return; +LL + } else { +LL + println!("{}", v); +LL + } ... help: ...and replace `return` with `continue` | LL | continue; - | ^^^^^^^^ + | ~~~~~~~~ error: aborting due to previous error diff --git a/tests/ui/needless_pass_by_value.stderr b/tests/ui/needless_pass_by_value.stderr index 9aa783bf904e..2f61ba241c45 100644 --- a/tests/ui/needless_pass_by_value.stderr +++ b/tests/ui/needless_pass_by_value.stderr @@ -63,11 +63,11 @@ LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { help: consider changing the type to | LL | fn issue_2114(s: String, t: &str, u: Vec, v: Vec) { - | ^^^^ + | ~~~~ help: change `t.clone()` to | LL | let _ = t.to_string(); - | ^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~ error: this argument is passed by value, but not consumed in the function body --> $DIR/needless_pass_by_value.rs:81:40 @@ -84,11 +84,11 @@ LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { help: consider changing the type to | LL | fn issue_2114(s: String, t: String, u: Vec, v: &[i32]) { - | ^^^^^^ + | ~~~~~~ help: change `v.clone()` to | LL | let _ = v.to_owned(); - | ^^^^^^^^^^^^ + | ~~~~~~~~~~~~ error: this argument is passed by value, but not consumed in the function body --> $DIR/needless_pass_by_value.rs:94:12 diff --git a/tests/ui/needless_range_loop.stderr b/tests/ui/needless_range_loop.stderr index c898cd64a939..a86cc69dfc5d 100644 --- a/tests/ui/needless_range_loop.stderr +++ b/tests/ui/needless_range_loop.stderr @@ -8,7 +8,7 @@ LL | for i in 0..vec.len() { help: consider using an iterator | LL | for in &vec { - | ^^^^^^ ^^^^ + | ~~~~~~ ~~~~ error: the loop variable `i` is only used to index `vec` --> $DIR/needless_range_loop.rs:19:14 @@ -19,7 +19,7 @@ LL | for i in 0..vec.len() { help: consider using an iterator | LL | for in &vec { - | ^^^^^^ ^^^^ + | ~~~~~~ ~~~~ error: the loop variable `j` is only used to index `STATIC` --> $DIR/needless_range_loop.rs:24:14 @@ -30,7 +30,7 @@ LL | for j in 0..4 { help: consider using an iterator | LL | for in &STATIC { - | ^^^^^^ ^^^^^^^ + | ~~~~~~ ~~~~~~~ error: the loop variable `j` is only used to index `CONST` --> $DIR/needless_range_loop.rs:28:14 @@ -41,7 +41,7 @@ LL | for j in 0..4 { help: consider using an iterator | LL | for in &CONST { - | ^^^^^^ ^^^^^^ + | ~~~~~~ ~~~~~~ error: the loop variable `i` is used to index `vec` --> $DIR/needless_range_loop.rs:32:14 @@ -52,7 +52,7 @@ LL | for i in 0..vec.len() { help: consider using an iterator | LL | for (i, ) in vec.iter().enumerate() { - | ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec2` --> $DIR/needless_range_loop.rs:40:14 @@ -63,7 +63,7 @@ LL | for i in 0..vec.len() { help: consider using an iterator | LL | for in vec2.iter().take(vec.len()) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` --> $DIR/needless_range_loop.rs:44:14 @@ -74,7 +74,7 @@ LL | for i in 5..vec.len() { help: consider using an iterator | LL | for in vec.iter().skip(5) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^ + | ~~~~~~ ~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` --> $DIR/needless_range_loop.rs:48:14 @@ -85,7 +85,7 @@ LL | for i in 0..MAX_LEN { help: consider using an iterator | LL | for in vec.iter().take(MAX_LEN) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` --> $DIR/needless_range_loop.rs:52:14 @@ -96,7 +96,7 @@ LL | for i in 0..=MAX_LEN { help: consider using an iterator | LL | for in vec.iter().take(MAX_LEN + 1) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` --> $DIR/needless_range_loop.rs:56:14 @@ -107,7 +107,7 @@ LL | for i in 5..10 { help: consider using an iterator | LL | for in vec.iter().take(10).skip(5) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` --> $DIR/needless_range_loop.rs:60:14 @@ -118,7 +118,7 @@ LL | for i in 5..=10 { help: consider using an iterator | LL | for in vec.iter().take(10 + 1).skip(5) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` --> $DIR/needless_range_loop.rs:64:14 @@ -129,7 +129,7 @@ LL | for i in 5..vec.len() { help: consider using an iterator | LL | for (i, ) in vec.iter().enumerate().skip(5) { - | ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` --> $DIR/needless_range_loop.rs:68:14 @@ -140,7 +140,7 @@ LL | for i in 5..10 { help: consider using an iterator | LL | for (i, ) in vec.iter().enumerate().take(10).skip(5) { - | ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` --> $DIR/needless_range_loop.rs:73:14 @@ -151,7 +151,7 @@ LL | for i in 0..vec.len() { help: consider using an iterator | LL | for (i, ) in vec.iter_mut().enumerate() { - | ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 14 previous errors diff --git a/tests/ui/needless_range_loop2.stderr b/tests/ui/needless_range_loop2.stderr index 2e1f0fd0299b..1e6ec5e667aa 100644 --- a/tests/ui/needless_range_loop2.stderr +++ b/tests/ui/needless_range_loop2.stderr @@ -8,7 +8,7 @@ LL | for i in 3..10 { help: consider using an iterator | LL | for in ns.iter().take(10).skip(3) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `ms` --> $DIR/needless_range_loop2.rs:31:14 @@ -19,7 +19,7 @@ LL | for i in 0..ms.len() { help: consider using an iterator | LL | for in &mut ms { - | ^^^^^^ ^^^^^^^ + | ~~~~~~ ~~~~~~~ error: the loop variable `i` is only used to index `ms` --> $DIR/needless_range_loop2.rs:37:14 @@ -30,7 +30,7 @@ LL | for i in 0..ms.len() { help: consider using an iterator | LL | for in &mut ms { - | ^^^^^^ ^^^^^^^ + | ~~~~~~ ~~~~~~~ error: the loop variable `i` is only used to index `vec` --> $DIR/needless_range_loop2.rs:61:14 @@ -41,7 +41,7 @@ LL | for i in x..x + 4 { help: consider using an iterator | LL | for in vec.iter_mut().skip(x).take(4) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` --> $DIR/needless_range_loop2.rs:68:14 @@ -52,7 +52,7 @@ LL | for i in x..=x + 4 { help: consider using an iterator | LL | for in vec.iter_mut().skip(x).take(4 + 1) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `arr` --> $DIR/needless_range_loop2.rs:74:14 @@ -63,7 +63,7 @@ LL | for i in 0..3 { help: consider using an iterator | LL | for in &arr { - | ^^^^^^ ^^^^ + | ~~~~~~ ~~~~ error: the loop variable `i` is only used to index `arr` --> $DIR/needless_range_loop2.rs:78:14 @@ -74,7 +74,7 @@ LL | for i in 0..2 { help: consider using an iterator | LL | for in arr.iter().take(2) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^ + | ~~~~~~ ~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `arr` --> $DIR/needless_range_loop2.rs:82:14 @@ -85,7 +85,7 @@ LL | for i in 1..3 { help: consider using an iterator | LL | for in arr.iter().skip(1) { - | ^^^^^^ ^^^^^^^^^^^^^^^^^^ + | ~~~~~~ ~~~~~~~~~~~~~~~~~~ error: aborting due to 8 previous errors diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 7c964000807e..14ddb66f2324 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -9,11 +9,11 @@ LL | | } = note: `-D clippy::new-without-default` implied by `-D warnings` help: try adding this | -LL | impl Default for Foo { -LL | fn default() -> Self { -LL | Self::new() -LL | } -LL | } +LL + impl Default for Foo { +LL + fn default() -> Self { +LL + Self::new() +LL + } +LL + } | error: you should consider adding a `Default` implementation for `Bar` @@ -26,11 +26,11 @@ LL | | } | help: try adding this | -LL | impl Default for Bar { -LL | fn default() -> Self { -LL | Self::new() -LL | } -LL | } +LL + impl Default for Bar { +LL + fn default() -> Self { +LL + Self::new() +LL + } +LL + } | error: you should consider adding a `Default` implementation for `LtKo<'c>` @@ -43,11 +43,11 @@ LL | | } | help: try adding this | -LL | impl<'c> Default for LtKo<'c> { -LL | fn default() -> Self { -LL | Self::new() -LL | } -LL | } +LL + impl<'c> Default for LtKo<'c> { +LL + fn default() -> Self { +LL + Self::new() +LL + } +LL + } | error: you should consider adding a `Default` implementation for `NewNotEqualToDerive` @@ -60,11 +60,11 @@ LL | | } | help: try adding this | -LL | impl Default for NewNotEqualToDerive { -LL | fn default() -> Self { -LL | Self::new() -LL | } -LL | } +LL + impl Default for NewNotEqualToDerive { +LL + fn default() -> Self { +LL + Self::new() +LL + } +LL + } | error: you should consider adding a `Default` implementation for `FooGenerics` @@ -77,11 +77,11 @@ LL | | } | help: try adding this | -LL | impl Default for FooGenerics { -LL | fn default() -> Self { -LL | Self::new() -LL | } -LL | } +LL + impl Default for FooGenerics { +LL + fn default() -> Self { +LL + Self::new() +LL + } +LL + } | error: you should consider adding a `Default` implementation for `BarGenerics` @@ -94,11 +94,11 @@ LL | | } | help: try adding this | -LL | impl Default for BarGenerics { -LL | fn default() -> Self { -LL | Self::new() -LL | } -LL | } +LL + impl Default for BarGenerics { +LL + fn default() -> Self { +LL + Self::new() +LL + } +LL + } | error: you should consider adding a `Default` implementation for `Foo` @@ -111,12 +111,12 @@ LL | | } | help: try adding this | -LL | impl Default for Foo { -LL | fn default() -> Self { -LL | Self::new() -LL | } -LL | } -LL | +LL ~ impl Default for Foo { +LL + fn default() -> Self { +LL + Self::new() +LL + } +LL + } +LL + ... error: aborting due to 7 previous errors diff --git a/tests/ui/nonminimal_bool.stderr b/tests/ui/nonminimal_bool.stderr index d34d106cb2fb..1d39bce935db 100644 --- a/tests/ui/nonminimal_bool.stderr +++ b/tests/ui/nonminimal_bool.stderr @@ -51,9 +51,9 @@ LL | let _ = a == b && c == 5 && a == b; help: try | LL | let _ = a == b && c == 5; - | ^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~ LL | let _ = !(a != b || c != 5); - | ^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified --> $DIR/nonminimal_bool.rs:28:13 @@ -64,9 +64,9 @@ LL | let _ = a == b || c == 5 || a == b; help: try | LL | let _ = a == b || c == 5; - | ^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~ LL | let _ = !(a != b && c != 5); - | ^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified --> $DIR/nonminimal_bool.rs:29:13 @@ -77,9 +77,9 @@ LL | let _ = a == b && c == 5 && b == a; help: try | LL | let _ = a == b && c == 5; - | ^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~ LL | let _ = !(a != b || c != 5); - | ^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified --> $DIR/nonminimal_bool.rs:30:13 @@ -90,9 +90,9 @@ LL | let _ = a != b || !(a != b || c == d); help: try | LL | let _ = a != b || c != d; - | ^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~ LL | let _ = !(a == b && c == d); - | ^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified --> $DIR/nonminimal_bool.rs:31:13 @@ -103,9 +103,9 @@ LL | let _ = a != b && !(a != b && c == d); help: try | LL | let _ = a != b && c != d; - | ^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~ LL | let _ = !(a == b || c == d); - | ^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~ error: aborting due to 12 previous errors diff --git a/tests/ui/op_ref.stderr b/tests/ui/op_ref.stderr index a3a9adcc4835..821099d8779d 100644 --- a/tests/ui/op_ref.stderr +++ b/tests/ui/op_ref.stderr @@ -8,7 +8,7 @@ LL | let foo = &5 - &6; help: use the values directly | LL | let foo = 5 - 6; - | ^ ^ + | ~ ~ error: taken reference of right operand --> $DIR/op_ref.rs:57:13 diff --git a/tests/ui/option_if_let_else.stderr b/tests/ui/option_if_let_else.stderr index 4ebb068d22ed..099e49ef8e3d 100644 --- a/tests/ui/option_if_let_else.stderr +++ b/tests/ui/option_if_let_else.stderr @@ -36,10 +36,10 @@ LL | | }; | help: try | -LL | let _ = num.as_mut().map_or(&mut 0, |s| { -LL | *s += 1; -LL | s -LL | }); +LL ~ let _ = num.as_mut().map_or(&mut 0, |s| { +LL + *s += 1; +LL + s +LL ~ }); | error: use Option::map_or instead of an if let/else @@ -62,10 +62,10 @@ LL | | }; | help: try | -LL | let _ = num.map_or(0, |mut s| { -LL | s += 1; -LL | s -LL | }); +LL ~ let _ = num.map_or(0, |mut s| { +LL + s += 1; +LL + s +LL ~ }); | error: use Option::map_or instead of an if let/else @@ -82,10 +82,10 @@ LL | | }; | help: try | -LL | let _ = num.as_mut().map_or(&mut 0, |s| { -LL | *s += 1; -LL | s -LL | }); +LL ~ let _ = num.as_mut().map_or(&mut 0, |s| { +LL + *s += 1; +LL + s +LL ~ }); | error: use Option::map_or instead of an if let/else @@ -101,10 +101,10 @@ LL | | } | help: try | -LL | arg.map_or(13, |x| { -LL | let y = x * x; -LL | y * y -LL | }) +LL ~ arg.map_or(13, |x| { +LL + let y = x * x; +LL + y * y +LL + }) | error: use Option::map_or_else instead of an if let/else @@ -134,12 +134,12 @@ LL | | }; | help: try | -LL | let _ = arg.map_or_else(|| { -LL | let mut y = 1; -LL | y = (y + 2 / y) / 2; -LL | y = (y + 2 / y) / 2; -LL | y -LL | }, |x| x * x * x * x); +LL ~ let _ = arg.map_or_else(|| { +LL + let mut y = 1; +LL + y = (y + 2 / y) / 2; +LL + y = (y + 2 / y) / 2; +LL + y +LL ~ }, |x| x * x * x * x); | error: use Option::map_or instead of an if let/else diff --git a/tests/ui/option_map_or_none.stderr b/tests/ui/option_map_or_none.stderr index 1cba29412b87..27d68b85e6f8 100644 --- a/tests/ui/option_map_or_none.stderr +++ b/tests/ui/option_map_or_none.stderr @@ -17,9 +17,9 @@ LL | | }); | help: try using `and_then` instead | -LL | let _ = opt.and_then(|x| { -LL | Some(x + 1) -LL | }); +LL ~ let _ = opt.and_then(|x| { +LL + Some(x + 1) +LL ~ }); | error: aborting due to 2 previous errors diff --git a/tests/ui/print_literal.stderr b/tests/ui/print_literal.stderr index 54a4084c89e1..a10cac04411c 100644 --- a/tests/ui/print_literal.stderr +++ b/tests/ui/print_literal.stderr @@ -7,8 +7,9 @@ LL | print!("Hello {}", "world"); = note: `-D clippy::print-literal` implied by `-D warnings` help: try this | -LL | print!("Hello world"); - | ^^^^^-- +LL - print!("Hello {}", "world"); +LL + print!("Hello world"); + | error: literal with an empty format string --> $DIR/print_literal.rs:26:36 @@ -18,8 +19,9 @@ LL | println!("Hello {} {}", world, "world"); | help: try this | -LL | println!("Hello {} world", world); - | ^^^^^ -- +LL - println!("Hello {} {}", world, "world"); +LL + println!("Hello {} world", world); + | error: literal with an empty format string --> $DIR/print_literal.rs:27:26 @@ -29,8 +31,9 @@ LL | println!("Hello {}", "world"); | help: try this | -LL | println!("Hello world"); - | ^^^^^-- +LL - println!("Hello {}", "world"); +LL + println!("Hello world"); + | error: literal with an empty format string --> $DIR/print_literal.rs:32:25 @@ -40,8 +43,9 @@ LL | println!("{0} {1}", "hello", "world"); | help: try this | -LL | println!("hello {1}", "world"); - | ^^^^^ -- +LL - println!("{0} {1}", "hello", "world"); +LL + println!("hello {1}", "world"); + | error: literal with an empty format string --> $DIR/print_literal.rs:32:34 @@ -51,8 +55,9 @@ LL | println!("{0} {1}", "hello", "world"); | help: try this | -LL | println!("{0} world", "hello"); - | ^^^^^ -- +LL - println!("{0} {1}", "hello", "world"); +LL + println!("{0} world", "hello"); + | error: literal with an empty format string --> $DIR/print_literal.rs:33:25 @@ -62,8 +67,9 @@ LL | println!("{1} {0}", "hello", "world"); | help: try this | -LL | println!("{1} hello", "world"); - | ^^^^^-- +LL - println!("{1} {0}", "hello", "world"); +LL + println!("{1} hello", "world"); + | error: literal with an empty format string --> $DIR/print_literal.rs:33:34 @@ -73,8 +79,9 @@ LL | println!("{1} {0}", "hello", "world"); | help: try this | -LL | println!("world {0}", "hello"); - | ^^^^^ -- +LL - println!("{1} {0}", "hello", "world"); +LL + println!("world {0}", "hello"); + | error: literal with an empty format string --> $DIR/print_literal.rs:36:29 @@ -84,8 +91,9 @@ LL | println!("{foo} {bar}", foo = "hello", bar = "world"); | help: try this | -LL | println!("hello {bar}", bar = "world"); - | ^^^^^ -- +LL - println!("{foo} {bar}", foo = "hello", bar = "world"); +LL + println!("hello {bar}", bar = "world"); + | error: literal with an empty format string --> $DIR/print_literal.rs:36:44 @@ -95,8 +103,9 @@ LL | println!("{foo} {bar}", foo = "hello", bar = "world"); | help: try this | -LL | println!("{foo} world", foo = "hello"); - | ^^^^^ -- +LL - println!("{foo} {bar}", foo = "hello", bar = "world"); +LL + println!("{foo} world", foo = "hello"); + | error: literal with an empty format string --> $DIR/print_literal.rs:37:29 @@ -106,8 +115,9 @@ LL | println!("{bar} {foo}", foo = "hello", bar = "world"); | help: try this | -LL | println!("{bar} hello", bar = "world"); - | ^^^^^-- +LL - println!("{bar} {foo}", foo = "hello", bar = "world"); +LL + println!("{bar} hello", bar = "world"); + | error: literal with an empty format string --> $DIR/print_literal.rs:37:44 @@ -117,8 +127,9 @@ LL | println!("{bar} {foo}", foo = "hello", bar = "world"); | help: try this | -LL | println!("world {foo}", foo = "hello"); - | ^^^^^ -- +LL - println!("{bar} {foo}", foo = "hello", bar = "world"); +LL + println!("world {foo}", foo = "hello"); + | error: aborting due to 11 previous errors diff --git a/tests/ui/print_with_newline.stderr b/tests/ui/print_with_newline.stderr index 54b3ad75b31e..d409bee30ece 100644 --- a/tests/ui/print_with_newline.stderr +++ b/tests/ui/print_with_newline.stderr @@ -7,8 +7,9 @@ LL | print!("Hello/n"); = note: `-D clippy::print-with-newline` implied by `-D warnings` help: use `println!` instead | -LL | println!("Hello"); - | ^^^^^^^ -- +LL - print!("Hello/n"); +LL + println!("Hello"); + | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:9:5 @@ -18,8 +19,9 @@ LL | print!("Hello {}/n", "world"); | help: use `println!` instead | -LL | println!("Hello {}", "world"); - | ^^^^^^^ -- +LL - print!("Hello {}/n", "world"); +LL + println!("Hello {}", "world"); + | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:10:5 @@ -29,8 +31,9 @@ LL | print!("Hello {} {}/n", "world", "#2"); | help: use `println!` instead | -LL | println!("Hello {} {}", "world", "#2"); - | ^^^^^^^ -- +LL - print!("Hello {} {}/n", "world", "#2"); +LL + println!("Hello {} {}", "world", "#2"); + | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:11:5 @@ -40,8 +43,9 @@ LL | print!("{}/n", 1265); | help: use `println!` instead | -LL | println!("{}", 1265); - | ^^^^^^^ -- +LL - print!("{}/n", 1265); +LL + println!("{}", 1265); + | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:12:5 @@ -51,8 +55,9 @@ LL | print!("/n"); | help: use `println!` instead | -LL | println!(); - | ^^^^^^^ -- +LL - print!("/n"); +LL + println!(); + | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:31:5 @@ -62,8 +67,9 @@ LL | print!("//n"); // should fail | help: use `println!` instead | -LL | println!("/"); // should fail - | ^^^^^^^ -- +LL - print!("//n"); // should fail +LL + println!("/"); // should fail + | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:38:5 @@ -76,8 +82,8 @@ LL | | ); | help: use `println!` instead | -LL | println!( -LL | "" +LL ~ println!( +LL ~ "" | error: using `print!()` with a format string that ends in a single newline @@ -91,8 +97,8 @@ LL | | ); | help: use `println!` instead | -LL | println!( -LL | r"" +LL ~ println!( +LL ~ r"" | error: using `print!()` with a format string that ends in a single newline @@ -103,8 +109,9 @@ LL | print!("/r/n"); //~ ERROR | help: use `println!` instead | -LL | println!("/r"); //~ ERROR - | ^^^^^^^ -- +LL - print!("/r/n"); //~ ERROR +LL + println!("/r"); //~ ERROR + | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:51:5 @@ -114,8 +121,9 @@ LL | print!("foo/rbar/n") // ~ ERROR | help: use `println!` instead | -LL | println!("foo/rbar") // ~ ERROR - | ^^^^^^^ -- +LL - print!("foo/rbar/n") // ~ ERROR +LL + println!("foo/rbar") // ~ ERROR + | error: aborting due to 10 previous errors diff --git a/tests/ui/ptr_arg.stderr b/tests/ui/ptr_arg.stderr index d302b16d4b72..64594eb870c2 100644 --- a/tests/ui/ptr_arg.stderr +++ b/tests/ui/ptr_arg.stderr @@ -33,11 +33,11 @@ LL | fn cloned(x: &Vec) -> Vec { help: change this to | LL | fn cloned(x: &[u8]) -> Vec { - | ^^^^^ + | ~~~~~ help: change `x.clone()` to | LL | let e = x.to_owned(); - | ^^^^^^^^^^^^ + | ~~~~~~~~~~~~ help: change `x.clone()` to | LL | x.to_owned() @@ -52,15 +52,15 @@ LL | fn str_cloned(x: &String) -> String { help: change this to | LL | fn str_cloned(x: &str) -> String { - | ^^^^ + | ~~~~ help: change `x.clone()` to | LL | let a = x.to_string(); - | ^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~ help: change `x.clone()` to | LL | let b = x.to_string(); - | ^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~ help: change `x.clone()` to | LL | x.to_string() @@ -75,15 +75,15 @@ LL | fn path_cloned(x: &PathBuf) -> PathBuf { help: change this to | LL | fn path_cloned(x: &Path) -> PathBuf { - | ^^^^^ + | ~~~~~ help: change `x.clone()` to | LL | let a = x.to_path_buf(); - | ^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~ help: change `x.clone()` to | LL | let b = x.to_path_buf(); - | ^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~ help: change `x.clone()` to | LL | x.to_path_buf() @@ -98,15 +98,15 @@ LL | fn false_positive_capacity(x: &Vec, y: &String) { help: change this to | LL | fn false_positive_capacity(x: &Vec, y: &str) { - | ^^^^ + | ~~~~ help: change `y.clone()` to | LL | let b = y.to_string(); - | ^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~ help: change `y.as_str()` to | LL | let c = y; - | ^ + | ~ error: using a reference to `Cow` is not recommended --> $DIR/ptr_arg.rs:90:25 @@ -123,15 +123,15 @@ LL | fn foo_vec(vec: &Vec) { help: change this to | LL | fn foo_vec(vec: &[u8]) { - | ^^^^^ + | ~~~~~ help: change `vec.clone()` to | LL | let _ = vec.to_owned().pop(); - | ^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~ help: change `vec.clone()` to | LL | let _ = vec.to_owned().clone(); - | ^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~ error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do --> $DIR/ptr_arg.rs:148:23 @@ -142,15 +142,15 @@ LL | fn foo_path(path: &PathBuf) { help: change this to | LL | fn foo_path(path: &Path) { - | ^^^^^ + | ~~~~~ help: change `path.clone()` to | LL | let _ = path.to_path_buf().pop(); - | ^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~ help: change `path.clone()` to | LL | let _ = path.to_path_buf().clone(); - | ^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~ error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do --> $DIR/ptr_arg.rs:153:21 @@ -161,15 +161,15 @@ LL | fn foo_str(str: &PathBuf) { help: change this to | LL | fn foo_str(str: &Path) { - | ^^^^^ + | ~~~~~ help: change `str.clone()` to | LL | let _ = str.to_path_buf().pop(); - | ^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~ help: change `str.clone()` to | LL | let _ = str.to_path_buf().clone(); - | ^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~ error: aborting due to 12 previous errors diff --git a/tests/ui/ref_binding_to_reference.stderr b/tests/ui/ref_binding_to_reference.stderr index 00aeff4fefa3..eb36cd516a24 100644 --- a/tests/ui/ref_binding_to_reference.stderr +++ b/tests/ui/ref_binding_to_reference.stderr @@ -8,7 +8,7 @@ LL | Some(ref x) => x, help: try this | LL | Some(x) => &x, - | ^ ^^ + | ~ ~~ error: this pattern creates a reference to a reference --> $DIR/ref_binding_to_reference.rs:37:14 @@ -18,10 +18,10 @@ LL | Some(ref x) => { | help: try this | -LL | Some(x) => { +LL ~ Some(x) => { LL | f1(x); -LL | f1(x); -LL | &x +LL ~ f1(x); +LL ~ &x | error: this pattern creates a reference to a reference @@ -33,7 +33,7 @@ LL | Some(ref x) => m2!(x), help: try this | LL | Some(x) => m2!(&x), - | ^ ^^ + | ~ ~~ error: this pattern creates a reference to a reference --> $DIR/ref_binding_to_reference.rs:52:15 @@ -43,8 +43,8 @@ LL | let _ = |&ref x: &&String| { | help: try this | -LL | let _ = |&x: &&String| { -LL | let _: &&String = &x; +LL ~ let _ = |&x: &&String| { +LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference @@ -55,9 +55,9 @@ LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { | help: try this | -LL | fn f2<'a>(&x: &&'a String) -> &'a String { -LL | let _: &&String = &x; -LL | x +LL ~ fn f2<'a>(&x: &&'a String) -> &'a String { +LL ~ let _: &&String = &x; +LL ~ x | error: this pattern creates a reference to a reference @@ -68,8 +68,8 @@ LL | fn f(&ref x: &&String) { | help: try this | -LL | fn f(&x: &&String) { -LL | let _: &&String = &x; +LL ~ fn f(&x: &&String) { +LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference @@ -80,8 +80,8 @@ LL | fn f(&ref x: &&String) { | help: try this | -LL | fn f(&x: &&String) { -LL | let _: &&String = &x; +LL ~ fn f(&x: &&String) { +LL ~ let _: &&String = &x; | error: aborting due to 7 previous errors diff --git a/tests/ui/reversed_empty_ranges_fixable.stderr b/tests/ui/reversed_empty_ranges_fixable.stderr index de83c4f3d633..2d1bfe62c923 100644 --- a/tests/ui/reversed_empty_ranges_fixable.stderr +++ b/tests/ui/reversed_empty_ranges_fixable.stderr @@ -8,7 +8,7 @@ LL | (42..=21).for_each(|x| println!("{}", x)); help: consider using the following if you are attempting to iterate over this range in reverse | LL | (21..=42).rev().for_each(|x| println!("{}", x)); - | ^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values --> $DIR/reversed_empty_ranges_fixable.rs:10:13 @@ -19,7 +19,7 @@ LL | let _ = (ANSWER..21).filter(|x| x % 2 == 0).take(10).collect::>( help: consider using the following if you are attempting to iterate over this range in reverse | LL | let _ = (21..ANSWER).rev().filter(|x| x % 2 == 0).take(10).collect::>(); - | ^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values --> $DIR/reversed_empty_ranges_fixable.rs:12:14 @@ -30,7 +30,7 @@ LL | for _ in -21..=-42 {} help: consider using the following if you are attempting to iterate over this range in reverse | LL | for _ in (-42..=-21).rev() {} - | ^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values --> $DIR/reversed_empty_ranges_fixable.rs:13:14 @@ -41,7 +41,7 @@ LL | for _ in 42u32..21u32 {} help: consider using the following if you are attempting to iterate over this range in reverse | LL | for _ in (21u32..42u32).rev() {} - | ^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~ error: aborting due to 4 previous errors diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.stderr b/tests/ui/reversed_empty_ranges_loops_fixable.stderr index e89e040a0ff9..a135da488ffd 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.stderr +++ b/tests/ui/reversed_empty_ranges_loops_fixable.stderr @@ -8,7 +8,7 @@ LL | for i in 10..0 { help: consider using the following if you are attempting to iterate over this range in reverse | LL | for i in (0..10).rev() { - | ^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~ error: this range is empty so it will yield no values --> $DIR/reversed_empty_ranges_loops_fixable.rs:11:14 @@ -19,7 +19,7 @@ LL | for i in 10..=0 { help: consider using the following if you are attempting to iterate over this range in reverse | LL | for i in (0..=10).rev() { - | ^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~ error: this range is empty so it will yield no values --> $DIR/reversed_empty_ranges_loops_fixable.rs:15:14 @@ -30,7 +30,7 @@ LL | for i in MAX_LEN..0 { help: consider using the following if you are attempting to iterate over this range in reverse | LL | for i in (0..MAX_LEN).rev() { - | ^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values --> $DIR/reversed_empty_ranges_loops_fixable.rs:34:14 @@ -41,7 +41,7 @@ LL | for i in (10..0).map(|x| x * 2) { help: consider using the following if you are attempting to iterate over this range in reverse | LL | for i in (0..10).rev().map(|x| x * 2) { - | ^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~ error: this range is empty so it will yield no values --> $DIR/reversed_empty_ranges_loops_fixable.rs:39:14 @@ -52,7 +52,7 @@ LL | for i in 10..5 + 4 { help: consider using the following if you are attempting to iterate over this range in reverse | LL | for i in (5 + 4..10).rev() { - | ^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values --> $DIR/reversed_empty_ranges_loops_fixable.rs:43:14 @@ -63,7 +63,7 @@ LL | for i in (5 + 2)..(3 - 1) { help: consider using the following if you are attempting to iterate over this range in reverse | LL | for i in ((3 - 1)..(5 + 2)).rev() { - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 6 previous errors diff --git a/tests/ui/single_element_loop.stderr b/tests/ui/single_element_loop.stderr index 0e35a33ded5b..f52ca8c5a9b0 100644 --- a/tests/ui/single_element_loop.stderr +++ b/tests/ui/single_element_loop.stderr @@ -9,10 +9,10 @@ LL | | } = note: `-D clippy::single-element-loop` implied by `-D warnings` help: try | -LL | { -LL | let item = &item1; -LL | println!("{}", item); -LL | } +LL ~ { +LL + let item = &item1; +LL + println!("{}", item); +LL + } | error: for loop over a single element @@ -25,10 +25,10 @@ LL | | } | help: try | -LL | { -LL | let item = &item1; -LL | println!("{:?}", item); -LL | } +LL ~ { +LL + let item = &item1; +LL + println!("{:?}", item); +LL + } | error: aborting due to 2 previous errors diff --git a/tests/ui/single_match.stderr b/tests/ui/single_match.stderr index 9ef2a8668a6f..c261b5111c8b 100644 --- a/tests/ui/single_match.stderr +++ b/tests/ui/single_match.stderr @@ -12,9 +12,9 @@ LL | | }; = note: `-D clippy::single-match` implied by `-D warnings` help: try this | -LL | if let Some(y) = x { -LL | println!("{:?}", y); -LL | }; +LL ~ if let Some(y) = x { +LL + println!("{:?}", y); +LL ~ }; | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` diff --git a/tests/ui/single_match_else.stderr b/tests/ui/single_match_else.stderr index 20be4fa226cf..c61d80a905c9 100644 --- a/tests/ui/single_match_else.stderr +++ b/tests/ui/single_match_else.stderr @@ -13,10 +13,10 @@ LL | | } = note: `-D clippy::single-match-else` implied by `-D warnings` help: try this | -LL | if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { -LL | let x = 5; -LL | None -LL | } +LL ~ if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { +LL + let x = 5; +LL + None +LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` @@ -33,10 +33,10 @@ LL | | } | help: try this | -LL | if let Some(a) = Some(1) { println!("${:?}", a) } else { -LL | println!("else block"); -LL | return -LL | } +LL ~ if let Some(a) = Some(1) { println!("${:?}", a) } else { +LL + println!("else block"); +LL + return +LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` @@ -53,10 +53,10 @@ LL | | } | help: try this | -LL | if let Some(a) = Some(1) { println!("${:?}", a) } else { -LL | println!("else block"); -LL | return; -LL | } +LL ~ if let Some(a) = Some(1) { println!("${:?}", a) } else { +LL + println!("else block"); +LL + return; +LL + } | error: aborting due to 3 previous errors diff --git a/tests/ui/strlen_on_c_strings.stderr b/tests/ui/strlen_on_c_strings.stderr index a212bd327c35..e0ca511557c5 100644 --- a/tests/ui/strlen_on_c_strings.stderr +++ b/tests/ui/strlen_on_c_strings.stderr @@ -8,7 +8,7 @@ LL | let len = unsafe { libc::strlen(cstring.as_ptr()) }; help: try this (you might also need to get rid of `unsafe` block in some cases): | LL | let len = unsafe { cstring.as_bytes().len() }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~~ error: using `libc::strlen` on a `CString` or `CStr` value --> $DIR/strlen_on_c_strings.rs:15:24 @@ -19,7 +19,7 @@ LL | let len = unsafe { libc::strlen(cstr.as_ptr()) }; help: try this (you might also need to get rid of `unsafe` block in some cases): | LL | let len = unsafe { cstr.to_bytes().len() }; - | ^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 2 previous errors diff --git a/tests/ui/unit_arg.stderr b/tests/ui/unit_arg.stderr index 8155c4ae1107..5cfb367a7be8 100644 --- a/tests/ui/unit_arg.stderr +++ b/tests/ui/unit_arg.stderr @@ -13,10 +13,10 @@ LL | 1 | help: or move the expression in front of the call and replace it with the unit literal `()` | -LL | { -LL | 1; -LL | }; -LL | foo(()); +LL ~ { +LL + 1; +LL + }; +LL ~ foo(()); | error: passing a unit value to a function @@ -27,8 +27,8 @@ LL | foo(foo(1)); | help: move the expression in front of the call and replace it with the unit literal `()` | -LL | foo(1); -LL | foo(()); +LL ~ foo(1); +LL ~ foo(()); | error: passing a unit value to a function @@ -46,11 +46,11 @@ LL | foo(2) | help: or move the expression in front of the call and replace it with the unit literal `()` | -LL | { -LL | foo(1); -LL | foo(2); -LL | }; -LL | foo(()); +LL ~ { +LL + foo(1); +LL + foo(2); +LL + }; +LL ~ foo(()); | error: passing a unit value to a function @@ -67,10 +67,10 @@ LL | 1 | help: or move the expression in front of the call and replace it with the unit literal `()` | -LL | { -LL | 1; -LL | }; -LL | b.bar(()); +LL ~ { +LL + 1; +LL + }; +LL ~ b.bar(()); | error: passing unit values to a function @@ -81,9 +81,9 @@ LL | taking_multiple_units(foo(0), foo(1)); | help: move the expressions in front of the call and replace them with the unit literal `()` | -LL | foo(0); -LL | foo(1); -LL | taking_multiple_units((), ()); +LL ~ foo(0); +LL + foo(1); +LL ~ taking_multiple_units((), ()); | error: passing unit values to a function @@ -101,12 +101,12 @@ LL | foo(2) | help: or move the expressions in front of the call and replace them with the unit literal `()` | -LL | foo(0); -LL | { -LL | foo(1); -LL | foo(2); -LL | }; -LL | taking_multiple_units((), ()); +LL ~ foo(0); +LL + { +LL + foo(1); +LL + foo(2); +LL + }; +LL ~ taking_multiple_units((), ()); | error: passing unit values to a function @@ -131,12 +131,12 @@ LL | foo(3) | help: or move the expressions in front of the call and replace them with the unit literal `()` | -LL | { -LL | foo(0); -LL | foo(1); -LL | }; -LL | { -LL | foo(2); +LL ~ { +LL + foo(0); +LL + foo(1); +LL + }; +LL + { +LL + foo(2); ... error: passing a unit value to a function @@ -147,10 +147,10 @@ LL | None.or(Some(foo(2))); | help: move the expression in front of the call and replace it with the unit literal `()` | -LL | None.or({ -LL | foo(2); -LL | Some(()) -LL | }); +LL ~ None.or({ +LL + foo(2); +LL + Some(()) +LL ~ }); | error: passing a unit value to a function @@ -161,8 +161,8 @@ LL | foo(foo(())); | help: move the expression in front of the call and replace it with the unit literal `()` | -LL | foo(()); -LL | foo(()); +LL ~ foo(()); +LL ~ foo(()); | error: passing a unit value to a function @@ -173,8 +173,8 @@ LL | Some(foo(1)) | help: move the expression in front of the call and replace it with the unit literal `()` | -LL | foo(1); -LL | Some(()) +LL ~ foo(1); +LL + Some(()) | error: aborting due to 10 previous errors diff --git a/tests/ui/unit_arg_empty_blocks.stderr b/tests/ui/unit_arg_empty_blocks.stderr index 456b12a2c6b1..39072c9a8cc0 100644 --- a/tests/ui/unit_arg_empty_blocks.stderr +++ b/tests/ui/unit_arg_empty_blocks.stderr @@ -24,8 +24,8 @@ LL | taking_two_units({}, foo(0)); | help: move the expression in front of the call and replace it with the unit literal `()` | -LL | foo(0); -LL | taking_two_units((), ()); +LL ~ foo(0); +LL ~ taking_two_units((), ()); | error: passing unit values to a function @@ -36,9 +36,9 @@ LL | taking_three_units({}, foo(0), foo(1)); | help: move the expressions in front of the call and replace them with the unit literal `()` | -LL | foo(0); -LL | foo(1); -LL | taking_three_units((), (), ()); +LL ~ foo(0); +LL + foo(1); +LL ~ taking_three_units((), (), ()); | error: aborting due to 4 previous errors diff --git a/tests/ui/unnecessary_clone.stderr b/tests/ui/unnecessary_clone.stderr index 9df1ae568673..94cc7777acac 100644 --- a/tests/ui/unnecessary_clone.stderr +++ b/tests/ui/unnecessary_clone.stderr @@ -54,11 +54,11 @@ LL | let z: &Vec<_> = y.clone(); help: try dereferencing it | LL | let z: &Vec<_> = &(*y).clone(); - | ^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~ help: or try being explicit if you are sure, that you want to clone a reference | LL | let z: &Vec<_> = <&std::vec::Vec>::clone(y); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: using `clone` on type `many_derefs::E` which implements the `Copy` trait --> $DIR/unnecessary_clone.rs:84:20 @@ -75,11 +75,11 @@ LL | let _ = &mut encoded.clone(); help: try dereferencing it | LL | let _ = &mut &(*encoded).clone(); - | ^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~ help: or try being explicit if you are sure, that you want to clone a reference | LL | let _ = &mut <&[u8]>::clone(encoded); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~ error: using `clone` on a double-reference; this will copy the reference of type `&[u8]` instead of cloning the inner type --> $DIR/unnecessary_clone.rs:90:18 @@ -90,11 +90,11 @@ LL | let _ = &encoded.clone(); help: try dereferencing it | LL | let _ = &&(*encoded).clone(); - | ^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~ help: or try being explicit if you are sure, that you want to clone a reference | LL | let _ = &<&[u8]>::clone(encoded); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~ error: using `.clone()` on a ref-counted pointer --> $DIR/unnecessary_clone.rs:108:14 diff --git a/tests/ui/unnecessary_wraps.stderr b/tests/ui/unnecessary_wraps.stderr index 0e570397e2a2..8e31db395024 100644 --- a/tests/ui/unnecessary_wraps.stderr +++ b/tests/ui/unnecessary_wraps.stderr @@ -14,14 +14,14 @@ LL | | } help: remove `Option` from the return type... | LL | fn func1(a: bool, b: bool) -> i32 { - | ^^^ + | ~~~ help: ...and then change returning expressions | -LL | return 42; +LL ~ return 42; LL | } LL | if a { LL | Some(-1); -LL | 2 +LL ~ 2 LL | } else { ... @@ -39,12 +39,12 @@ LL | | } help: remove `Option` from the return type... | LL | fn func2(a: bool, b: bool) -> i32 { - | ^^^ + | ~~~ help: ...and then change returning expressions | -LL | return 10; +LL ~ return 10; LL | } -LL | if a { 20 } else { 30 } +LL ~ if a { 20 } else { 30 } | error: this function's return value is unnecessarily wrapped by `Option` @@ -58,7 +58,7 @@ LL | | } help: remove `Option` from the return type... | LL | fn func5() -> i32 { - | ^^^ + | ~~~ help: ...and then change returning expressions | LL | 1 @@ -75,7 +75,7 @@ LL | | } help: remove `Result` from the return type... | LL | fn func7() -> i32 { - | ^^^ + | ~~~ help: ...and then change returning expressions | LL | 1 @@ -92,7 +92,7 @@ LL | | } help: remove `Option` from the return type... | LL | fn func12() -> i32 { - | ^^^ + | ~~~ help: ...and then change returning expressions | LL | 1 @@ -113,14 +113,14 @@ LL | | } help: remove the return type... | LL | fn issue_6640_1(a: bool, b: bool) -> Option<()> { - | ^^^^^^^^^^ + | ~~~~~~~~~~ help: ...and then remove returned values | -LL | return ; +LL ~ return ; LL | } LL | if a { LL | Some(()); -LL | +LL ~ LL | } else { ... @@ -139,15 +139,15 @@ LL | | } help: remove the return type... | LL | fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { - | ^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~ help: ...and then remove returned values | -LL | return ; +LL ~ return ; LL | } LL | if a { -LL | +LL ~ LL | } else { -LL | return ; +LL ~ return ; | error: aborting due to 7 previous errors diff --git a/tests/ui/unnested_or_patterns.stderr b/tests/ui/unnested_or_patterns.stderr index f7cb513c15c9..de424c3fdb8f 100644 --- a/tests/ui/unnested_or_patterns.stderr +++ b/tests/ui/unnested_or_patterns.stderr @@ -8,7 +8,7 @@ LL | if let box 0 | box 2 = Box::new(0) {} help: nest the patterns | LL | if let box (0 | 2) = Box::new(0) {} - | ^^^^^^^^^^^ + | ~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns.rs:10:12 @@ -19,7 +19,7 @@ LL | if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {} help: nest the patterns | LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns.rs:12:12 @@ -30,7 +30,7 @@ LL | if let &0 | C0 | &2 = &0 {} help: nest the patterns | LL | if let &(0 | 2) | C0 = &0 {} - | ^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns.rs:13:12 @@ -41,7 +41,7 @@ LL | if let &mut 0 | &mut 2 = &mut 0 {} help: nest the patterns | LL | if let &mut (0 | 2) = &mut 0 {} - | ^^^^^^^^^^^^ + | ~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns.rs:14:12 @@ -52,7 +52,7 @@ LL | if let x @ 0 | x @ 2 = 0 {} help: nest the patterns | LL | if let x @ (0 | 2) = 0 {} - | ^^^^^^^^^^^ + | ~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns.rs:15:12 @@ -63,7 +63,7 @@ LL | if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} help: nest the patterns | LL | if let (0, 1 | 2 | 3) = (0, 0) {} - | ^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns.rs:16:12 @@ -74,7 +74,7 @@ LL | if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {} help: nest the patterns | LL | if let (1 | 2 | 3, 0) = (0, 0) {} - | ^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns.rs:17:12 @@ -85,7 +85,7 @@ LL | if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {} help: nest the patterns | LL | if let (x, ..) | (x, 1 | 2) = (0, 1) {} - | ^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns.rs:18:12 @@ -96,7 +96,7 @@ LL | if let [0] | [1] = [0] {} help: nest the patterns | LL | if let [0 | 1] = [0] {} - | ^^^^^^^ + | ~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns.rs:19:12 @@ -107,7 +107,7 @@ LL | if let [x, 0] | [x, 1] = [0, 1] {} help: nest the patterns | LL | if let [x, 0 | 1] = [0, 1] {} - | ^^^^^^^^^^ + | ~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns.rs:20:12 @@ -118,7 +118,7 @@ LL | if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {} help: nest the patterns | LL | if let [x, 0 | 1 | 2] = [0, 1] {} - | ^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns.rs:21:12 @@ -129,7 +129,7 @@ LL | if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {} help: nest the patterns | LL | if let [x, ..] | [x, 1 | 2] = [0, 1] {} - | ^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns.rs:23:12 @@ -140,7 +140,7 @@ LL | if let TS(0, x) | TS(1, x) = TS(0, 0) {} help: nest the patterns | LL | if let TS(0 | 1, x) = TS(0, 0) {} - | ^^^^^^^^^^^^ + | ~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns.rs:24:12 @@ -151,7 +151,7 @@ LL | if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {} help: nest the patterns | LL | if let TS(1 | 2 | 3, 0) = TS(0, 0) {} - | ^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns.rs:25:12 @@ -162,7 +162,7 @@ LL | if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {} help: nest the patterns | LL | if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns.rs:30:12 @@ -173,7 +173,7 @@ LL | if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} help: nest the patterns | LL | if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {} - | ^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~ error: aborting due to 16 previous errors diff --git a/tests/ui/unnested_or_patterns2.stderr b/tests/ui/unnested_or_patterns2.stderr index 9042c9c00b1a..41e8d3fc7092 100644 --- a/tests/ui/unnested_or_patterns2.stderr +++ b/tests/ui/unnested_or_patterns2.stderr @@ -8,7 +8,7 @@ LL | if let Some(Some(0)) | Some(Some(1)) = None {} help: nest the patterns | LL | if let Some(Some(0 | 1)) = None {} - | ^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns2.rs:10:12 @@ -19,7 +19,7 @@ LL | if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {} help: nest the patterns | LL | if let Some(Some(0 | 1 | 2)) = None {} - | ^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns2.rs:11:12 @@ -30,7 +30,7 @@ LL | if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {} help: nest the patterns | LL | if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns2.rs:12:12 @@ -41,7 +41,7 @@ LL | if let Some(Some(0) | Some(1 | 2)) = None {} help: nest the patterns | LL | if let Some(Some(0 | 1 | 2)) = None {} - | ^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns2.rs:13:12 @@ -52,7 +52,7 @@ LL | if let ((0,),) | ((1,) | (2,),) = ((0,),) {} help: nest the patterns | LL | if let ((0 | 1 | 2,),) = ((0,),) {} - | ^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns2.rs:14:12 @@ -63,7 +63,7 @@ LL | if let 0 | (1 | 2) = 0 {} help: nest the patterns | LL | if let 0 | 1 | 2 = 0 {} - | ^^^^^^^^^ + | ~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns2.rs:15:12 @@ -74,7 +74,7 @@ LL | if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {} help: nest the patterns | LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns --> $DIR/unnested_or_patterns2.rs:16:12 @@ -85,7 +85,7 @@ LL | if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {} help: nest the patterns | LL | if let box box (0 | 2 | 4) = Box::new(Box::new(0)) {} - | ^^^^^^^^^^^^^^^^^^^ + | ~~~~~~~~~~~~~~~~~~~ error: aborting due to 8 previous errors diff --git a/tests/ui/write_literal.stderr b/tests/ui/write_literal.stderr index 507a78e82805..e0297c002315 100644 --- a/tests/ui/write_literal.stderr +++ b/tests/ui/write_literal.stderr @@ -7,8 +7,9 @@ LL | write!(&mut v, "Hello {}", "world"); = note: `-D clippy::write-literal` implied by `-D warnings` help: try this | -LL | write!(&mut v, "Hello world"); - | ^^^^^-- +LL - write!(&mut v, "Hello {}", "world"); +LL + write!(&mut v, "Hello world"); + | error: literal with an empty format string --> $DIR/write_literal.rs:31:44 @@ -18,8 +19,9 @@ LL | writeln!(&mut v, "Hello {} {}", world, "world"); | help: try this | -LL | writeln!(&mut v, "Hello {} world", world); - | ^^^^^ -- +LL - writeln!(&mut v, "Hello {} {}", world, "world"); +LL + writeln!(&mut v, "Hello {} world", world); + | error: literal with an empty format string --> $DIR/write_literal.rs:32:34 @@ -29,8 +31,9 @@ LL | writeln!(&mut v, "Hello {}", "world"); | help: try this | -LL | writeln!(&mut v, "Hello world"); - | ^^^^^-- +LL - writeln!(&mut v, "Hello {}", "world"); +LL + writeln!(&mut v, "Hello world"); + | error: literal with an empty format string --> $DIR/write_literal.rs:37:33 @@ -40,8 +43,9 @@ LL | writeln!(&mut v, "{0} {1}", "hello", "world"); | help: try this | -LL | writeln!(&mut v, "hello {1}", "world"); - | ^^^^^ -- +LL - writeln!(&mut v, "{0} {1}", "hello", "world"); +LL + writeln!(&mut v, "hello {1}", "world"); + | error: literal with an empty format string --> $DIR/write_literal.rs:37:42 @@ -51,8 +55,9 @@ LL | writeln!(&mut v, "{0} {1}", "hello", "world"); | help: try this | -LL | writeln!(&mut v, "{0} world", "hello"); - | ^^^^^ -- +LL - writeln!(&mut v, "{0} {1}", "hello", "world"); +LL + writeln!(&mut v, "{0} world", "hello"); + | error: literal with an empty format string --> $DIR/write_literal.rs:38:33 @@ -62,8 +67,9 @@ LL | writeln!(&mut v, "{1} {0}", "hello", "world"); | help: try this | -LL | writeln!(&mut v, "{1} hello", "world"); - | ^^^^^-- +LL - writeln!(&mut v, "{1} {0}", "hello", "world"); +LL + writeln!(&mut v, "{1} hello", "world"); + | error: literal with an empty format string --> $DIR/write_literal.rs:38:42 @@ -73,8 +79,9 @@ LL | writeln!(&mut v, "{1} {0}", "hello", "world"); | help: try this | -LL | writeln!(&mut v, "world {0}", "hello"); - | ^^^^^ -- +LL - writeln!(&mut v, "{1} {0}", "hello", "world"); +LL + writeln!(&mut v, "world {0}", "hello"); + | error: literal with an empty format string --> $DIR/write_literal.rs:41:37 @@ -84,8 +91,9 @@ LL | writeln!(&mut v, "{foo} {bar}", foo = "hello", bar = "world"); | help: try this | -LL | writeln!(&mut v, "hello {bar}", bar = "world"); - | ^^^^^ -- +LL - writeln!(&mut v, "{foo} {bar}", foo = "hello", bar = "world"); +LL + writeln!(&mut v, "hello {bar}", bar = "world"); + | error: literal with an empty format string --> $DIR/write_literal.rs:41:52 @@ -95,8 +103,9 @@ LL | writeln!(&mut v, "{foo} {bar}", foo = "hello", bar = "world"); | help: try this | -LL | writeln!(&mut v, "{foo} world", foo = "hello"); - | ^^^^^ -- +LL - writeln!(&mut v, "{foo} {bar}", foo = "hello", bar = "world"); +LL + writeln!(&mut v, "{foo} world", foo = "hello"); + | error: literal with an empty format string --> $DIR/write_literal.rs:42:37 @@ -106,8 +115,9 @@ LL | writeln!(&mut v, "{bar} {foo}", foo = "hello", bar = "world"); | help: try this | -LL | writeln!(&mut v, "{bar} hello", bar = "world"); - | ^^^^^-- +LL - writeln!(&mut v, "{bar} {foo}", foo = "hello", bar = "world"); +LL + writeln!(&mut v, "{bar} hello", bar = "world"); + | error: literal with an empty format string --> $DIR/write_literal.rs:42:52 @@ -117,8 +127,9 @@ LL | writeln!(&mut v, "{bar} {foo}", foo = "hello", bar = "world"); | help: try this | -LL | writeln!(&mut v, "world {foo}", foo = "hello"); - | ^^^^^ -- +LL - writeln!(&mut v, "{bar} {foo}", foo = "hello", bar = "world"); +LL + writeln!(&mut v, "world {foo}", foo = "hello"); + | error: aborting due to 11 previous errors diff --git a/tests/ui/write_literal_2.stderr b/tests/ui/write_literal_2.stderr index 0aa1b55e58c5..73c6b8858132 100644 --- a/tests/ui/write_literal_2.stderr +++ b/tests/ui/write_literal_2.stderr @@ -7,8 +7,9 @@ LL | writeln!(&mut v, "{}", "{hello}"); = note: `-D clippy::write-literal` implied by `-D warnings` help: try this | -LL | writeln!(&mut v, "{{hello}}"); - | ^^^^^^^^^-- +LL - writeln!(&mut v, "{}", "{hello}"); +LL + writeln!(&mut v, "{{hello}}"); + | error: literal with an empty format string --> $DIR/write_literal_2.rs:10:29 @@ -18,8 +19,9 @@ LL | writeln!(&mut v, r"{}", r"{hello}"); | help: try this | -LL | writeln!(&mut v, r"{{hello}}"); - | ^^^^^^^^^-- +LL - writeln!(&mut v, r"{}", r"{hello}"); +LL + writeln!(&mut v, r"{{hello}}"); + | error: literal with an empty format string --> $DIR/write_literal_2.rs:11:28 @@ -29,8 +31,9 @@ LL | writeln!(&mut v, "{}", '/''); | help: try this | -LL | writeln!(&mut v, "'"); - | ^-- +LL - writeln!(&mut v, "{}", '/''); +LL + writeln!(&mut v, "'"); + | error: literal with an empty format string --> $DIR/write_literal_2.rs:12:28 @@ -40,8 +43,9 @@ LL | writeln!(&mut v, "{}", '"'); | help: try this | -LL | writeln!(&mut v, "/""); - | ^^-- +LL - writeln!(&mut v, "{}", '"'); +LL + writeln!(&mut v, "/""); + | error: literal with an empty format string --> $DIR/write_literal_2.rs:14:29 @@ -51,8 +55,9 @@ LL | writeln!(&mut v, r"{}", '/''); | help: try this | -LL | writeln!(&mut v, r"'"); - | ^-- +LL - writeln!(&mut v, r"{}", '/''); +LL + writeln!(&mut v, r"'"); + | error: literal with an empty format string --> $DIR/write_literal_2.rs:18:9 @@ -63,8 +68,8 @@ LL | | world!" | help: try this | -LL | "some hello / -LL | world!" +LL ~ "some hello / +LL ~ world!" | error: literal with an empty format string @@ -75,8 +80,8 @@ LL | "1", "2", "3", | help: try this | -LL | "some 1/ -LL | {} / {}", "2", "3", +LL ~ "some 1/ +LL ~ {} / {}", "2", "3", | error: literal with an empty format string @@ -87,8 +92,8 @@ LL | "1", "2", "3", | help: try this | -LL | 2 / {}", -LL | "1", "3", +LL ~ 2 / {}", +LL ~ "1", "3", | error: literal with an empty format string @@ -99,8 +104,8 @@ LL | "1", "2", "3", | help: try this | -LL | {} / 3", -LL | "1", "2", +LL ~ {} / 3", +LL ~ "1", "2", | error: aborting due to 9 previous errors diff --git a/tests/ui/write_with_newline.stderr b/tests/ui/write_with_newline.stderr index cecc2ea9406a..186459e50b64 100644 --- a/tests/ui/write_with_newline.stderr +++ b/tests/ui/write_with_newline.stderr @@ -7,8 +7,9 @@ LL | write!(&mut v, "Hello/n"); = note: `-D clippy::write-with-newline` implied by `-D warnings` help: use `writeln!()` instead | -LL | writeln!(&mut v, "Hello"); - | ^^^^^^^ -- +LL - write!(&mut v, "Hello/n"); +LL + writeln!(&mut v, "Hello"); + | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:14:5 @@ -18,8 +19,9 @@ LL | write!(&mut v, "Hello {}/n", "world"); | help: use `writeln!()` instead | -LL | writeln!(&mut v, "Hello {}", "world"); - | ^^^^^^^ -- +LL - write!(&mut v, "Hello {}/n", "world"); +LL + writeln!(&mut v, "Hello {}", "world"); + | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:15:5 @@ -29,8 +31,9 @@ LL | write!(&mut v, "Hello {} {}/n", "world", "#2"); | help: use `writeln!()` instead | -LL | writeln!(&mut v, "Hello {} {}", "world", "#2"); - | ^^^^^^^ -- +LL - write!(&mut v, "Hello {} {}/n", "world", "#2"); +LL + writeln!(&mut v, "Hello {} {}", "world", "#2"); + | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:16:5 @@ -40,8 +43,9 @@ LL | write!(&mut v, "{}/n", 1265); | help: use `writeln!()` instead | -LL | writeln!(&mut v, "{}", 1265); - | ^^^^^^^ -- +LL - write!(&mut v, "{}/n", 1265); +LL + writeln!(&mut v, "{}", 1265); + | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:17:5 @@ -51,8 +55,9 @@ LL | write!(&mut v, "/n"); | help: use `writeln!()` instead | -LL | writeln!(&mut v); - | ^^^^^^^ -- +LL - write!(&mut v, "/n"); +LL + writeln!(&mut v); + | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:36:5 @@ -62,8 +67,9 @@ LL | write!(&mut v, "//n"); // should fail | help: use `writeln!()` instead | -LL | writeln!(&mut v, "/"); // should fail - | ^^^^^^^ -- +LL - write!(&mut v, "//n"); // should fail +LL + writeln!(&mut v, "/"); // should fail + | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:43:5 @@ -77,9 +83,9 @@ LL | | ); | help: use `writeln!()` instead | -LL | writeln!( +LL ~ writeln!( LL | &mut v, -LL | "" +LL ~ "" | error: using `write!()` with a format string that ends in a single newline @@ -94,9 +100,9 @@ LL | | ); | help: use `writeln!()` instead | -LL | writeln!( +LL ~ writeln!( LL | &mut v, -LL | r"" +LL ~ r"" | error: using `write!()` with a format string that ends in a single newline @@ -107,8 +113,9 @@ LL | write!(&mut v, "/r/n"); //~ ERROR | help: use `writeln!()` instead | -LL | writeln!(&mut v, "/r"); //~ ERROR - | ^^^^^^^ -- +LL - write!(&mut v, "/r/n"); //~ ERROR +LL + writeln!(&mut v, "/r"); //~ ERROR + | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:58:5 @@ -118,8 +125,9 @@ LL | write!(&mut v, "foo/rbar/n"); | help: use `writeln!()` instead | -LL | writeln!(&mut v, "foo/rbar"); - | ^^^^^^^ -- +LL - write!(&mut v, "foo/rbar/n"); +LL + writeln!(&mut v, "foo/rbar"); + | error: aborting due to 10 previous errors From 6539e8ddb243b9b6cafcb6e384063bc07d201f28 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Thu, 12 Aug 2021 10:48:16 +0200 Subject: [PATCH 0289/1222] Bless clippy tests. --- tests/ui/crashes/ice-3969.stderr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ui/crashes/ice-3969.stderr b/tests/ui/crashes/ice-3969.stderr index 8b2c318acf84..9a89047f0727 100644 --- a/tests/ui/crashes/ice-3969.stderr +++ b/tests/ui/crashes/ice-3969.stderr @@ -6,7 +6,7 @@ LL | for<'a> Dst: Sized, | = note: `-D bare-trait-objects` implied by `-D warnings` = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! - = note: for more information, see issue #80165 + = note: for more information, see error: trait objects without an explicit `dyn` are deprecated --> $DIR/ice-3969.rs:27:16 @@ -15,7 +15,7 @@ LL | let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); | ^ help: use `dyn`: `dyn A` | = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! - = note: for more information, see issue #80165 + = note: for more information, see error: trait objects without an explicit `dyn` are deprecated --> $DIR/ice-3969.rs:27:57 @@ -24,7 +24,7 @@ LL | let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); | ^ help: use `dyn`: `dyn A` | = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! - = note: for more information, see issue #80165 + = note: for more information, see error: aborting due to 3 previous errors From 08b8090ae694709ecdb3378226e027d8d7cca4b7 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Thu, 22 Jul 2021 21:56:07 +0800 Subject: [PATCH 0290/1222] move Constness into TraitPredicate --- clippy_lints/src/future_not_send.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/unit_return_expecting_ord.rs | 2 +- clippy_utils/src/qualify_min_const_fn.rs | 2 +- clippy_utils/src/ty.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 0be03969bcbe..3e35ada7b2a1 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -93,7 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { cx.tcx.infer_ctxt().enter(|infcx| { for FulfillmentError { obligation, .. } in send_errors { infcx.maybe_note_obligation_cause_for_async_await(db, &obligation); - if let Trait(trait_pred, _) = obligation.predicate.kind().skip_binder() { + if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() { db.note(&format!( "`{}` doesn't implement `{}`", trait_pred.self_ty(), diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 03eeb54d8d1c..5e559991c169 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -121,7 +121,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { .filter_map(|obligation| { // Note that we do not want to deal with qualified predicates here. match obligation.predicate.kind().no_bound_vars() { - Some(ty::PredicateKind::Trait(pred, _)) if pred.def_id() != sized_trait => Some(pred), + Some(ty::PredicateKind::Trait(pred)) if pred.def_id() != sized_trait => Some(pred), _ => None, } }) diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 900d45317607..ee675838c4cb 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -45,7 +45,7 @@ fn get_trait_predicates_for_trait_id<'tcx>( let mut preds = Vec::new(); for (pred, _) in generics.predicates { if_chain! { - if let PredicateKind::Trait(poly_trait_pred, _) = pred.kind().skip_binder(); + if let PredicateKind::Trait(poly_trait_pred) = pred.kind().skip_binder(); let trait_pred = cx.tcx.erase_late_bound_regions(pred.kind().rebind(poly_trait_pred)); if let Some(trait_def_id) = trait_id; if trait_def_id == trait_pred.trait_ref.def_id; diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 0e6ead675c24..dee9d487c78e 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -36,7 +36,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: Option<&Ru ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate), ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate), ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate), - ty::PredicateKind::Trait(pred, _) => { + ty::PredicateKind::Trait(pred) => { if Some(pred.def_id()) == tcx.lang_items().sized_trait() { continue; } diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 4f9aaf396b80..a2221a0b283b 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -157,7 +157,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { ty::Tuple(substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { - if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.kind().skip_binder() { + if let ty::PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() { if must_use_attr(cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() { return true; } From c0c5de9bcb08ff7bde0d9c9299130f8256035b0f Mon Sep 17 00:00:00 2001 From: Caio Date: Sun, 8 Aug 2021 11:49:13 -0300 Subject: [PATCH 0291/1222] Introduce hir::ExprKind::Let - Take 2 --- clippy_lints/src/assertions_on_constants.rs | 5 +- clippy_lints/src/blocks_in_if_conditions.rs | 3 +- clippy_lints/src/collapsible_match.rs | 77 ++- clippy_lints/src/copies.rs | 17 +- clippy_lints/src/dereference.rs | 1 + clippy_lints/src/entry.rs | 8 +- clippy_lints/src/eta_reduction.rs | 2 +- clippy_lints/src/floating_point_arithmetic.rs | 7 +- clippy_lints/src/if_let_mutex.rs | 27 +- clippy_lints/src/if_let_some_result.rs | 15 +- clippy_lints/src/if_then_some_else_none.rs | 4 +- clippy_lints/src/implicit_saturating_sub.rs | 3 +- clippy_lints/src/indexing_slicing.rs | 2 +- clippy_lints/src/infinite_iter.rs | 2 +- clippy_lints/src/let_if_seq.rs | 4 +- clippy_lints/src/loops/manual_flatten.rs | 13 +- clippy_lints/src/loops/manual_memcpy.rs | 2 +- clippy_lints/src/loops/mod.rs | 6 +- clippy_lints/src/loops/mut_range_bound.rs | 2 +- clippy_lints/src/loops/needless_range_loop.rs | 2 +- clippy_lints/src/loops/never_loop.rs | 9 +- clippy_lints/src/loops/while_let_loop.rs | 98 ++-- .../src/loops/while_let_on_iterator.rs | 25 +- clippy_lints/src/manual_map.rs | 301 ++++++----- clippy_lints/src/manual_strip.rs | 4 +- clippy_lints/src/matches.rs | 265 +++++---- clippy_lints/src/methods/iter_next_slice.rs | 4 +- clippy_lints/src/mut_mut.rs | 2 +- clippy_lints/src/needless_bool.rs | 14 +- clippy_lints/src/non_expressive_names.rs | 3 +- clippy_lints/src/option_if_let_else.rs | 43 +- clippy_lints/src/pattern_type_mismatch.rs | 33 +- clippy_lints/src/question_mark.rs | 27 +- clippy_lints/src/ranges.rs | 14 +- clippy_lints/src/redundant_clone.rs | 2 +- clippy_lints/src/returns.rs | 8 - .../src/suspicious_operation_groupings.rs | 2 +- clippy_lints/src/unnested_or_patterns.rs | 2 +- clippy_lints/src/unwrap.rs | 7 +- clippy_lints/src/utils/author.rs | 9 + clippy_lints/src/utils/inspector.rs | 33 +- clippy_lints/src/vec.rs | 8 +- clippy_utils/src/ast_utils.rs | 2 +- clippy_utils/src/eager_or_lazy.rs | 1 + clippy_utils/src/higher.rs | 507 +++++++++++++----- clippy_utils/src/hir_utils.rs | 7 + clippy_utils/src/lib.rs | 19 +- clippy_utils/src/sugg.rs | 3 +- tests/ui/author/if.stdout | 3 +- tests/ui/collapsible_match.stderr | 8 +- tests/ui/crashes/ice-7410.rs | 1 + tests/ui/crashes/issues_loop_mut_cond.rs | 1 + tests/ui/infinite_loop.rs | 2 + tests/ui/infinite_loop.stderr | 22 +- tests/ui/match_overlapping_arm.rs | 1 + tests/ui/match_overlapping_arm.stderr | 20 +- 56 files changed, 1043 insertions(+), 669 deletions(-) diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index cb9347a923d8..891e865b245d 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -1,5 +1,6 @@ use clippy_utils::consts::{constant, Constant}; use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::higher; use clippy_utils::source::snippet_opt; use clippy_utils::{is_direct_expn_of, is_expn_of, match_panic_call}; use if_chain::if_chain; @@ -116,8 +117,8 @@ enum AssertKind { /// where `message` is any expression and `c` is a constant bool. fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option { if_chain! { - if let ExprKind::If(cond, then, _) = expr.kind; - if let ExprKind::Unary(UnOp::Not, expr) = cond.kind; + if let Some(higher::If { cond, then, .. }) = higher::If::hir(expr); + if let ExprKind::Unary(UnOp::Not, ref expr) = cond.kind; // bind the first argument of the `assert!` macro if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), expr); // block diff --git a/clippy_lints/src/blocks_in_if_conditions.rs b/clippy_lints/src/blocks_in_if_conditions.rs index 9b2e4f8998e4..51d95cc6f0b1 100644 --- a/clippy_lints/src/blocks_in_if_conditions.rs +++ b/clippy_lints/src/blocks_in_if_conditions.rs @@ -1,4 +1,5 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; +use clippy_utils::higher; use clippy_utils::source::snippet_block_with_applicability; use clippy_utils::ty::implements_trait; use clippy_utils::{differing_macro_contexts, get_parent_expr}; @@ -92,7 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInIfConditions { if in_external_macro(cx.sess(), expr.span) { return; } - if let ExprKind::If(cond, _, _) = &expr.kind { + if let Some(higher::If { cond, .. }) = higher::If::hir(expr) { if let ExprKind::Block(block, _) = &cond.kind { if block.rules == BlockCheckMode::DefaultBlock { if block.stmts.is_empty() { diff --git a/clippy_lints/src/collapsible_match.rs b/clippy_lints/src/collapsible_match.rs index a403a9846bab..6b63c2cf157a 100644 --- a/clippy_lints/src/collapsible_match.rs +++ b/clippy_lints/src/collapsible_match.rs @@ -1,9 +1,9 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::visitors::LocalUsedVisitor; -use clippy_utils::{is_lang_ctor, path_to_local, peel_ref_operators, SpanlessEq}; +use clippy_utils::{higher, is_lang_ctor, path_to_local, peel_ref_operators, SpanlessEq}; use if_chain::if_chain; use rustc_hir::LangItem::OptionNone; -use rustc_hir::{Arm, Expr, ExprKind, Guard, HirId, Pat, PatKind, StmtKind}; +use rustc_hir::{Expr, ExprKind, Guard, HirId, Pat, PatKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{MultiSpan, Span}; @@ -49,22 +49,44 @@ declare_lint_pass!(CollapsibleMatch => [COLLAPSIBLE_MATCH]); impl<'tcx> LateLintPass<'tcx> for CollapsibleMatch { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) { + if let Some(higher::IfLet { + let_pat, + if_then, + if_else, + .. + }) = higher::IfLet::hir(expr) + { + check_arm(cx, if_then, None, let_pat, if_else); + + check_if_let(cx, if_then, let_pat); + } + if let ExprKind::Match(_expr, arms, _source) = expr.kind { - if let Some(wild_arm) = arms.iter().rfind(|arm| arm_is_wild_like(cx, arm)) { + if let Some(wild_arm) = arms.iter().rfind(|arm| is_wild_like(cx, &arm.pat.kind, &arm.guard)) { for arm in arms { - check_arm(arm, wild_arm, cx); + check_arm(cx, arm.body, arm.guard.as_ref(), arm.pat, Some(wild_arm.body)); } } + + if let Some(first_arm) = arms.get(0) { + check_if_let(cx, &first_arm.body, &first_arm.pat); + } } } } -fn check_arm<'tcx>(arm: &Arm<'tcx>, wild_outer_arm: &Arm<'tcx>, cx: &LateContext<'tcx>) { - let expr = strip_singleton_blocks(arm.body); +fn check_arm<'tcx>( + cx: &LateContext<'tcx>, + outer_block: &'tcx Expr<'tcx>, + outer_guard: Option<&Guard<'tcx>>, + outer_pat: &'tcx Pat<'tcx>, + wild_outer_block: Option<&'tcx Expr<'tcx>>, +) { + let expr = strip_singleton_blocks(outer_block); if_chain! { if let ExprKind::Match(expr_in, arms_inner, _) = expr.kind; // the outer arm pattern and the inner match - if expr_in.span.ctxt() == arm.pat.span.ctxt(); + if expr_in.span.ctxt() == outer_pat.span.ctxt(); // there must be no more than two arms in the inner match for this lint if arms_inner.len() == 2; // no if guards on the inner match @@ -73,18 +95,18 @@ fn check_arm<'tcx>(arm: &Arm<'tcx>, wild_outer_arm: &Arm<'tcx>, cx: &LateContext // match { .. } if let Some(binding_id) = path_to_local(peel_ref_operators(cx, expr_in)); // one of the branches must be "wild-like" - if let Some(wild_inner_arm_idx) = arms_inner.iter().rposition(|arm_inner| arm_is_wild_like(cx, arm_inner)); + if let Some(wild_inner_arm_idx) = arms_inner.iter().rposition(|arm_inner| is_wild_like(cx, &arm_inner.pat.kind, &arm_inner.guard)); let (wild_inner_arm, non_wild_inner_arm) = (&arms_inner[wild_inner_arm_idx], &arms_inner[1 - wild_inner_arm_idx]); if !pat_contains_or(non_wild_inner_arm.pat); // the binding must come from the pattern of the containing match arm // .... => match { .. } - if let Some(binding_span) = find_pat_binding(arm.pat, binding_id); + if let Some(binding_span) = find_pat_binding(outer_pat, binding_id); // the "wild-like" branches must be equal - if SpanlessEq::new(cx).eq_expr(wild_inner_arm.body, wild_outer_arm.body); + if wild_outer_block.map(|el| SpanlessEq::new(cx).eq_expr(wild_inner_arm.body, el)).unwrap_or(true); // the binding must not be used in the if guard let mut used_visitor = LocalUsedVisitor::new(cx, binding_id); - if match arm.guard { + if match outer_guard { None => true, Some(Guard::If(expr) | Guard::IfLet(_, expr)) => !used_visitor.check_expr(expr), }; @@ -107,6 +129,31 @@ fn check_arm<'tcx>(arm: &Arm<'tcx>, wild_outer_arm: &Arm<'tcx>, cx: &LateContext } } +fn check_if_let<'tcx>(cx: &LateContext<'tcx>, outer_expr: &'tcx Expr<'tcx>, outer_pat: &'tcx Pat<'tcx>) { + let block_inner = strip_singleton_blocks(outer_expr); + if_chain! { + if let Some(higher::IfLet { if_then: inner_if_then, let_expr: inner_let_expr, let_pat: inner_let_pat, .. }) = higher::IfLet::hir(block_inner); + if let Some(binding_id) = path_to_local(peel_ref_operators(cx, inner_let_expr)); + if let Some(binding_span) = find_pat_binding(outer_pat, binding_id); + let mut used_visitor = LocalUsedVisitor::new(cx, binding_id); + if !used_visitor.check_expr(inner_if_then); + then { + span_lint_and_then( + cx, + COLLAPSIBLE_MATCH, + block_inner.span, + "unnecessary nested `if let` or `match`", + |diag| { + let mut help_span = MultiSpan::from_spans(vec![binding_span, inner_let_pat.span]); + help_span.push_span_label(binding_span, "replace this binding".into()); + help_span.push_span_label(inner_let_pat.span, "with this pattern".into()); + diag.span_help(help_span, "the outer pattern can be modified to include the inner pattern"); + }, + ); + } + } +} + fn strip_singleton_blocks<'hir>(mut expr: &'hir Expr<'hir>) -> &'hir Expr<'hir> { while let ExprKind::Block(block, _) = expr.kind { match (block.stmts, block.expr) { @@ -122,13 +169,13 @@ fn strip_singleton_blocks<'hir>(mut expr: &'hir Expr<'hir>) -> &'hir Expr<'hir> } /// A "wild-like" pattern is wild ("_") or `None`. -/// For this lint to apply, both the outer and inner match expressions +/// For this lint to apply, both the outer and inner patterns /// must have "wild-like" branches that can be combined. -fn arm_is_wild_like(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool { - if arm.guard.is_some() { +fn is_wild_like(cx: &LateContext<'_>, pat_kind: &PatKind<'_>, arm_guard: &Option>) -> bool { + if arm_guard.is_some() { return false; } - match arm.pat.kind { + match pat_kind { PatKind::Binding(..) | PatKind::Wild => true, PatKind::Path(ref qpath) => is_lang_ctor(cx, qpath, OptionNone), _ => false, diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 2dcd55457993..5eb99cfe24f4 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -316,9 +316,10 @@ fn scan_block_for_eq(cx: &LateContext<'tcx>, blocks: &[&Block<'tcx>]) -> Option< let mut start_eq = usize::MAX; let mut end_eq = usize::MAX; let mut expr_eq = true; - for win in blocks.windows(2) { - let l_stmts = win[0].stmts; - let r_stmts = win[1].stmts; + let mut iter = blocks.windows(2); + while let Some(&[win0, win1]) = iter.next() { + let l_stmts = win0.stmts; + let r_stmts = win1.stmts; // `SpanlessEq` now keeps track of the locals and is therefore context sensitive clippy#6752. // The comparison therefore needs to be done in a way that builds the correct context. @@ -335,22 +336,22 @@ fn scan_block_for_eq(cx: &LateContext<'tcx>, blocks: &[&Block<'tcx>]) -> Option< it1.zip(it2) .fold(0, |acc, (l, r)| if evaluator.eq_stmt(l, r) { acc + 1 } else { 0 }) }; - let block_expr_eq = both(&win[0].expr, &win[1].expr, |l, r| evaluator.eq_expr(l, r)); + let block_expr_eq = both(&win0.expr, &win1.expr, |l, r| evaluator.eq_expr(l, r)); // IF_SAME_THEN_ELSE if_chain! { if block_expr_eq; if l_stmts.len() == r_stmts.len(); if l_stmts.len() == current_start_eq; - 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); + if !is_lint_allowed(cx, IF_SAME_THEN_ELSE, win0.hir_id); + if !is_lint_allowed(cx, IF_SAME_THEN_ELSE, win1.hir_id); then { span_lint_and_note( cx, IF_SAME_THEN_ELSE, - win[0].span, + win0.span, "this `if` has identical blocks", - Some(win[1].span), + Some(win1.span), "same as this", ); diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index ded7001ad8c8..7825e5f6ed52 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -232,6 +232,7 @@ fn is_linted_explicit_deref_position(parent: Option>, child_id: HirId, | ExprKind::If(..) | ExprKind::Loop(..) | ExprKind::Match(..) + | ExprKind::Let(..) | ExprKind::Closure(..) | ExprKind::Block(..) | ExprKind::Assign(..) diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index e1d0d65edb1b..627f746ec997 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -1,3 +1,4 @@ +use clippy_utils::higher; use clippy_utils::{ can_move_expr_to_closure_no_visit, diagnostics::span_lint_and_sugg, @@ -5,6 +6,7 @@ use clippy_utils::{ source::{reindent_multiline, snippet_indent, snippet_with_applicability, snippet_with_context}, SpanlessEq, }; +use core::fmt::Write; use rustc_errors::Applicability; use rustc_hir::{ intravisit::{walk_expr, ErasedMap, NestedVisitorMap, Visitor}, @@ -13,7 +15,6 @@ use rustc_hir::{ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{Span, SyntaxContext, DUMMY_SP}; -use std::fmt::Write; declare_clippy_lint! { /// ### What it does @@ -62,10 +63,11 @@ declare_lint_pass!(HashMapPass => [MAP_ENTRY]); impl<'tcx> LateLintPass<'tcx> for HashMapPass { #[allow(clippy::too_many_lines)] fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - let (cond_expr, then_expr, else_expr) = match expr.kind { - ExprKind::If(c, t, e) => (c, t, e), + let (cond_expr, then_expr, else_expr) = match higher::If::hir(expr) { + Some(higher::If { cond, then, r#else }) => (cond, then, r#else), _ => return, }; + let (map_ty, contains_expr) = match try_parse_contains(cx, cond_expr) { Some(x) => x, None => return, diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 192b69e18f90..f6a64a8ca603 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -100,7 +100,7 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if ex.span.ctxt() != expr.span.ctxt() { if decl.inputs.is_empty() { - if let Some(VecArgs::Vec(&[])) = higher::vec_macro(cx, ex) { + if let Some(VecArgs::Vec(&[])) = higher::VecArgs::hir(cx, ex) { // replace `|| vec![]` with `Vec::new` span_lint_and_sugg( cx, diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index b01c0cdd8462..d12482e7b7bb 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -3,6 +3,7 @@ use clippy_utils::consts::{ Constant::{Int, F32, F64}, }; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::higher; use clippy_utils::{eq_expr_value, get_parent_expr, numeric_literal, sugg}; use if_chain::if_chain; use rustc_errors::Applicability; @@ -545,11 +546,11 @@ fn are_negated<'a>(cx: &LateContext<'_>, expr1: &'a Expr<'a>, expr2: &'a Expr<'a fn check_custom_abs(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { - if let ExprKind::If(cond, body, else_body) = expr.kind; - if let ExprKind::Block(block, _) = body.kind; + if let Some(higher::If { cond, then, r#else }) = higher::If::hir(expr); + if let ExprKind::Block(block, _) = then.kind; if block.stmts.is_empty(); if let Some(if_body_expr) = block.expr; - if let Some(ExprKind::Block(else_block, _)) = else_body.map(|el| &el.kind); + if let Some(ExprKind::Block(else_block, _)) = r#else.map(|el| &el.kind); if else_block.stmts.is_empty(); if let Some(else_body_expr) = else_block.expr; if let Some((if_expr_positive, body)) = are_negated(cx, if_body_expr, else_body_expr); diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index d3ddeda9fd1b..e2d3905eacb5 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -1,9 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::higher; use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::SpanlessEq; use if_chain::if_chain; use rustc_hir::intravisit::{self as visit, NestedVisitorMap, Visitor}; -use rustc_hir::{Expr, ExprKind, MatchSource}; +use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -42,7 +43,7 @@ declare_clippy_lint! { declare_lint_pass!(IfLetMutex => [IF_LET_MUTEX]); impl<'tcx> LateLintPass<'tcx> for IfLetMutex { - fn check_expr(&mut self, cx: &LateContext<'tcx>, ex: &'tcx Expr<'tcx>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { let mut arm_visit = ArmVisitor { mutex_lock_called: false, found_mutex: None, @@ -53,25 +54,23 @@ impl<'tcx> LateLintPass<'tcx> for IfLetMutex { found_mutex: None, cx, }; - if let ExprKind::Match( - op, - arms, - MatchSource::IfLetDesugar { - contains_else_clause: true, - }, - ) = ex.kind + if let Some(higher::IfLet { + let_expr, + if_then, + if_else: Some(if_else), + .. + }) = higher::IfLet::hir(expr) { - op_visit.visit_expr(op); + op_visit.visit_expr(let_expr); if op_visit.mutex_lock_called { - for arm in arms { - arm_visit.visit_arm(arm); - } + arm_visit.visit_expr(if_then); + arm_visit.visit_expr(if_else); if arm_visit.mutex_lock_called && arm_visit.same_mutex(cx, op_visit.found_mutex.unwrap()) { span_lint_and_help( cx, IF_LET_MUTEX, - ex.span, + expr.span, "calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock", None, "move the lock call outside of the `if let ...` expression", diff --git a/clippy_lints/src/if_let_some_result.rs b/clippy_lints/src/if_let_some_result.rs index 587307811a11..cd813c639dbb 100644 --- a/clippy_lints/src/if_let_some_result.rs +++ b/clippy_lints/src/if_let_some_result.rs @@ -1,10 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::higher; use clippy_utils::method_chain_args; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, MatchSource, PatKind, QPath}; +use rustc_hir::{Expr, ExprKind, PatKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; @@ -44,17 +45,17 @@ declare_lint_pass!(OkIfLet => [IF_LET_SOME_RESULT]); impl<'tcx> LateLintPass<'tcx> for OkIfLet { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { //begin checking variables - if let ExprKind::Match(op, body, MatchSource::IfLetDesugar { .. }) = expr.kind; //test if expr is if let - if let ExprKind::MethodCall(_, ok_span, result_types, _) = op.kind; //check is expr.ok() has type Result.ok(, _) - if let PatKind::TupleStruct(QPath::Resolved(_, x), y, _) = body[0].pat.kind; //get operation - if method_chain_args(op, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized; + if let Some(higher::IfLet { let_pat, let_expr, .. }) = higher::IfLet::hir(expr); + if let ExprKind::MethodCall(_, ok_span, ref result_types, _) = let_expr.kind; //check is expr.ok() has type Result.ok(, _) + if let PatKind::TupleStruct(QPath::Resolved(_, ref x), ref y, _) = let_pat.kind; //get operation + if method_chain_args(let_expr, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized; if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&result_types[0]), sym::result_type); if rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(x, false)) == "Some"; then { let mut applicability = Applicability::MachineApplicable; let some_expr_string = snippet_with_applicability(cx, y[0].span, "", &mut applicability); - let trimmed_ok = snippet_with_applicability(cx, op.span.until(ok_span), "", &mut applicability); + let trimmed_ok = snippet_with_applicability(cx, let_expr.span.until(ok_span), "", &mut applicability); let sugg = format!( "if let Ok({}) = {}", some_expr_string, @@ -63,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for OkIfLet { span_lint_and_sugg( cx, IF_LET_SOME_RESULT, - expr.span.with_hi(op.span.hi()), + expr.span.with_hi(let_expr.span.hi()), "matching on `Some` with `ok()` is redundant", &format!("consider matching on `Ok({})` and removing the call to `ok` instead", some_expr_string), sugg, diff --git a/clippy_lints/src/if_then_some_else_none.rs b/clippy_lints/src/if_then_some_else_none.rs index 17b9a2f888e0..a2dac57454f2 100644 --- a/clippy_lints/src/if_then_some_else_none.rs +++ b/clippy_lints/src/if_then_some_else_none.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::snippet_with_macro_callsite; -use clippy_utils::{is_else_clause, is_lang_ctor, meets_msrv, msrvs}; +use clippy_utils::{higher, is_else_clause, is_lang_ctor, meets_msrv, msrvs}; use if_chain::if_chain; use rustc_hir::LangItem::{OptionNone, OptionSome}; use rustc_hir::{Expr, ExprKind}; @@ -70,7 +70,7 @@ impl LateLintPass<'_> for IfThenSomeElseNone { } if_chain! { - if let ExprKind::If(cond, then, Some(els)) = expr.kind; + if let Some(higher::If { cond, then, r#else: Some(els) }) = higher::If::hir(expr); if let ExprKind::Block(then_block, _) = then.kind; if let Some(then_expr) = then_block.expr; if let ExprKind::Call(then_call, [then_arg]) = then_expr.kind; diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index 0a7d31dce2fd..79d4d7ddcbce 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -1,4 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::higher; use clippy_utils::{in_macro, SpanlessEq}; use if_chain::if_chain; use rustc_ast::ast::LitKind; @@ -42,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { return; } if_chain! { - if let ExprKind::If(cond, then, None) = &expr.kind; + if let Some(higher::If { cond, then, .. }) = higher::If::hir(expr); // Check if the conditional expression is a binary operation if let ExprKind::Binary(ref cond_op, cond_left, cond_right) = cond.kind; diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index 8c1f10733095..f52f090d3872 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Index(array, index) = &expr.kind { let ty = cx.typeck_results().expr_ty(array).peel_refs(); - if let Some(range) = higher::range(index) { + if let Some(range) = higher::Range::hir(index) { // Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..] if let ty::Array(_, s) = ty.kind() { let size: u128 = if let Some(size) = s.try_eval_usize(cx.tcx, cx.param_env) { diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index 2411a3175b91..58646385def5 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -172,7 +172,7 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { Finite } }, - ExprKind::Struct(..) => higher::range(expr).map_or(false, |r| r.end.is_none()).into(), + ExprKind::Struct(..) => higher::Range::hir(expr).map_or(false, |r| r.end.is_none()).into(), _ => Finite, } } diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 13f0d43cf8dd..0594b73dd383 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq { if let hir::StmtKind::Local(local) = stmt.kind; if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.kind; if let hir::StmtKind::Expr(if_) = expr.kind; - if let hir::ExprKind::If(cond, then, ref else_) = if_.kind; + if let hir::ExprKind::If(hir::Expr { kind: hir::ExprKind::DropTemps(cond), ..}, then, else_) = if_.kind; let mut used_visitor = LocalUsedVisitor::new(cx, canonical_id); if !used_visitor.check_expr(cond); if let hir::ExprKind::Block(then, _) = then.kind; @@ -79,7 +79,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq { ); if has_interior_mutability { return; } - let (default_multi_stmts, default) = if let Some(else_) = *else_ { + let (default_multi_stmts, default) = if let Some(else_) = else_ { if let hir::ExprKind::Block(else_, _) = else_.kind { if let Some(default) = check_assign(cx, canonical_id, else_) { (else_.stmts.len() > 1, default) diff --git a/clippy_lints/src/loops/manual_flatten.rs b/clippy_lints/src/loops/manual_flatten.rs index 64ff7574f86b..9f2bc3c7ebae 100644 --- a/clippy_lints/src/loops/manual_flatten.rs +++ b/clippy_lints/src/loops/manual_flatten.rs @@ -1,11 +1,12 @@ use super::utils::make_iterator_snippet; use super::MANUAL_FLATTEN; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::higher; use clippy_utils::{is_lang_ctor, path_to_local_id}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::LangItem::{OptionSome, ResultOk}; -use rustc_hir::{Expr, ExprKind, MatchSource, Pat, PatKind, StmtKind}; +use rustc_hir::{Expr, ExprKind, Pat, PatKind, StmtKind}; use rustc_lint::LateContext; use rustc_middle::ty; use rustc_span::source_map::Span; @@ -36,14 +37,12 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(inner_expr) = inner_expr; - if let ExprKind::Match( - match_expr, match_arms, MatchSource::IfLetDesugar{ contains_else_clause: false } - ) = inner_expr.kind; + if let Some(higher::IfLet { let_pat, let_expr, if_else: None, .. }) = higher::IfLet::hir(inner_expr); // Ensure match_expr in `if let` statement is the same as the pat from the for-loop if let PatKind::Binding(_, pat_hir_id, _, _) = pat.kind; - if path_to_local_id(match_expr, pat_hir_id); + if path_to_local_id(let_expr, pat_hir_id); // Ensure the `if let` statement is for the `Some` variant of `Option` or the `Ok` variant of `Result` - if let PatKind::TupleStruct(ref qpath, _, _) = match_arms[0].pat.kind; + if let PatKind::TupleStruct(ref qpath, _, _) = let_pat.kind; let some_ctor = is_lang_ctor(cx, qpath, OptionSome); let ok_ctor = is_lang_ctor(cx, qpath, ResultOk); if some_ctor || ok_ctor; @@ -55,7 +54,7 @@ pub(super) fn check<'tcx>( // Prepare the help message let mut applicability = Applicability::MaybeIncorrect; let arg_snippet = make_iterator_snippet(cx, arg, &mut applicability); - let copied = match cx.typeck_results().expr_ty(match_expr).kind() { + let copied = match cx.typeck_results().expr_ty(let_expr).kind() { ty::Ref(_, inner, _) => match inner.kind() { ty::Ref(..) => ".copied()", _ => "" diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index a98e2dc1372d..2525b14e1c5c 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -27,7 +27,7 @@ pub(super) fn check<'tcx>( start: Some(start), end: Some(end), limits, - }) = higher::range(arg) + }) = higher::Range::hir(arg) { // the var must be a single name if let PatKind::Binding(_, canonical_id, _, _) = pat.kind { diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index 7ca54d539720..bd9de5e08d73 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -551,7 +551,7 @@ declare_lint_pass!(Loops => [ impl<'tcx> LateLintPass<'tcx> for Loops { #[allow(clippy::too_many_lines)] fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let Some((pat, arg, body, span)) = higher::for_loop(expr) { + if let Some(higher::ForLoop { pat, arg, body, span }) = higher::ForLoop::hir(expr) { // we don't want to check expanded macros // this check is not at the top of the function // since higher::for_loop expressions are marked as expansions @@ -580,8 +580,8 @@ impl<'tcx> LateLintPass<'tcx> for Loops { while_let_on_iterator::check(cx, expr); - if let Some((cond, body)) = higher::while_loop(expr) { - while_immutable_condition::check(cx, cond, body); + if let Some(higher::While { if_cond, if_then, .. }) = higher::While::hir(&expr) { + while_immutable_condition::check(cx, if_cond, if_then); } needless_collect::check(expr, cx); diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index 1e54a1e2de16..344dc5074d36 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -14,7 +14,7 @@ pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>, body: &Expr<'_>) { start: Some(start), end: Some(end), .. - }) = higher::range(arg) + }) = higher::Range::hir(arg) { let mut_ids = vec![check_for_mutability(cx, start), check_for_mutability(cx, end)]; if mut_ids[0].is_some() || mut_ids[1].is_some() { diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 3810d0dcc051..3f77e7af927a 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -34,7 +34,7 @@ pub(super) fn check<'tcx>( start: Some(start), ref end, limits, - }) = higher::range(arg) + }) = higher::Range::hir(arg) { // the var must be a single name if let PatKind::Binding(_, canonical_id, ident, _) = pat.kind { diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index 6d9f6215ed41..2c46971d5f74 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -1,7 +1,7 @@ use super::utils::make_iterator_snippet; use super::NEVER_LOOP; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::higher; +use clippy_utils::higher::ForLoop; use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir::{Block, Expr, ExprKind, HirId, InlineAsmOperand, LoopSource, Node, Pat, Stmt, StmtKind}; @@ -16,7 +16,7 @@ pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let LoopSource::ForLoop = source; if let Some((_, Node::Expr(parent_match))) = cx.tcx.hir().parent_iter(expr.hir_id).nth(1); - if let Some((pat, iterator, _, for_span)) = higher::for_loop(parent_match); + if let Some(ForLoop { arg: iterator, pat, span: for_span, .. }) = ForLoop::hir(parent_match); then { // Suggests using an `if let` instead. This is `Unspecified` because the // loop may (probably) contain `break` statements which would be invalid @@ -111,6 +111,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { | ExprKind::Unary(_, e) | ExprKind::Cast(e, _) | ExprKind::Type(e, _) + | ExprKind::Let(_, e, _) | ExprKind::Field(e, _) | ExprKind::AddrOf(_, _, e) | ExprKind::Struct(_, _, Some(e)) @@ -128,7 +129,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { // Break can come from the inner loop so remove them. absorb_break(&never_loop_block(b, main_loop_id)) }, - ExprKind::If(e, e2, ref e3) => { + ExprKind::If(e, e2, e3) => { let e1 = never_loop_expr(e, main_loop_id); let e2 = never_loop_expr(e2, main_loop_id); let e3 = e3 @@ -156,7 +157,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { NeverLoopResult::AlwaysBreak } }, - ExprKind::Break(_, ref e) | ExprKind::Ret(ref e) => e.as_ref().map_or(NeverLoopResult::AlwaysBreak, |e| { + ExprKind::Break(_, e) | ExprKind::Ret(e) => e.as_ref().map_or(NeverLoopResult::AlwaysBreak, |e| { combine_seq(never_loop_expr(e, main_loop_id), NeverLoopResult::AlwaysBreak) }), ExprKind::InlineAsm(asm) => asm diff --git a/clippy_lints/src/loops/while_let_loop.rs b/clippy_lints/src/loops/while_let_loop.rs index 9c1720798529..6be410ca8e3c 100644 --- a/clippy_lints/src/loops/while_let_loop.rs +++ b/clippy_lints/src/loops/while_let_loop.rs @@ -1,8 +1,9 @@ use super::WHILE_LET_LOOP; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::higher; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; -use rustc_hir::{Block, Expr, ExprKind, MatchSource, StmtKind}; +use rustc_hir::{Block, Expr, ExprKind, MatchSource, Pat, StmtKind}; use rustc_lint::{LateContext, LintContext}; use rustc_middle::lint::in_external_macro; @@ -11,41 +12,25 @@ pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &' let inner_stmt_expr = extract_expr_from_first_stmt(loop_block); // or extract the first expression (if any) from the block if let Some(inner) = inner_stmt_expr.or_else(|| extract_first_expr(loop_block)) { - if let ExprKind::Match(matchexpr, arms, ref source) = inner.kind { - // ensure "if let" compatible match structure - match *source { - MatchSource::Normal | MatchSource::IfLetDesugar { .. } => { - if arms.len() == 2 - && arms[0].guard.is_none() - && arms[1].guard.is_none() - && is_simple_break_expr(arms[1].body) - { - if in_external_macro(cx.sess(), expr.span) { - return; - } + if let Some(higher::IfLet { + let_pat, + let_expr, + if_else: Some(if_else), + .. + }) = higher::IfLet::hir(inner) + { + if is_simple_break_expr(if_else) { + could_be_while_let(cx, expr, let_pat, let_expr); + } + } - // NOTE: we used to build a body here instead of using - // ellipsis, this was removed because: - // 1) it was ugly with big bodies; - // 2) it was not indented properly; - // 3) it wasn’t very smart (see #675). - let mut applicability = Applicability::HasPlaceholders; - span_lint_and_sugg( - cx, - WHILE_LET_LOOP, - expr.span, - "this loop could be written as a `while let` loop", - "try", - format!( - "while let {} = {} {{ .. }}", - snippet_with_applicability(cx, arms[0].pat.span, "..", &mut applicability), - snippet_with_applicability(cx, matchexpr.span, "..", &mut applicability), - ), - applicability, - ); - } - }, - _ => (), + if let ExprKind::Match(ref matchexpr, ref arms, MatchSource::Normal) = inner.kind { + if arms.len() == 2 + && arms[0].guard.is_none() + && arms[1].guard.is_none() + && is_simple_break_expr(&arms[1].body) + { + could_be_while_let(cx, expr, &arms[0].pat, matchexpr); } } } @@ -54,14 +39,12 @@ pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &' /// If a block begins with a statement (possibly a `let` binding) and has an /// expression, return it. fn extract_expr_from_first_stmt<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<'tcx>> { - if block.stmts.is_empty() { - return None; - } - if let StmtKind::Local(local) = block.stmts[0].kind { - local.init //.map(|expr| expr) - } else { - None + if let Some(first_stmt) = block.stmts.get(0) { + if let StmtKind::Local(local) = first_stmt.kind { + return local.init; + } } + None } /// If a block begins with an expression (with or without semicolon), return it. @@ -86,3 +69,34 @@ fn is_simple_break_expr(expr: &Expr<'_>) -> bool { _ => false, } } + +fn could_be_while_let<'tcx>( + cx: &LateContext<'tcx>, + expr: &'tcx Expr<'_>, + let_pat: &'tcx Pat<'_>, + let_expr: &'tcx Expr<'_>, +) { + if in_external_macro(cx.sess(), expr.span) { + return; + } + + // NOTE: we used to build a body here instead of using + // ellipsis, this was removed because: + // 1) it was ugly with big bodies; + // 2) it was not indented properly; + // 3) it wasn’t very smart (see #675). + let mut applicability = Applicability::HasPlaceholders; + span_lint_and_sugg( + cx, + WHILE_LET_LOOP, + expr.span, + "this loop could be written as a `while let` loop", + "try", + format!( + "while let {} = {} {{ .. }}", + snippet_with_applicability(cx, let_pat.span, "..", &mut applicability), + snippet_with_applicability(cx, let_expr.span, "..", &mut applicability), + ), + applicability, + ); +} diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index ef822e0cbe54..0757d329125c 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -1,5 +1,6 @@ use super::WHILE_LET_ON_ITERATOR; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::higher; use clippy_utils::source::snippet_with_applicability; use clippy_utils::{ get_enclosing_loop_or_closure, is_refutable, is_trait_method, match_def_path, paths, visitors::is_res_used, @@ -7,27 +8,31 @@ use clippy_utils::{ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_expr, ErasedMap, NestedVisitorMap, Visitor}; -use rustc_hir::{def::Res, Expr, ExprKind, HirId, Local, MatchSource, Mutability, Node, PatKind, QPath, UnOp}; +use rustc_hir::{def::Res, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, UnOp}; use rustc_lint::LateContext; use rustc_span::{symbol::sym, Span, Symbol}; pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { let (scrutinee_expr, iter_expr, some_pat, loop_expr) = if_chain! { - if let ExprKind::Match(scrutinee_expr, [arm, _], MatchSource::WhileLetDesugar) = expr.kind; + if let Some(higher::WhileLet { + if_then, + let_pat, + let_expr, + .. + }) = higher::WhileLet::hir(expr); // check for `Some(..)` pattern - if let PatKind::TupleStruct(QPath::Resolved(None, pat_path), some_pat, _) = arm.pat.kind; + if let PatKind::TupleStruct(QPath::Resolved(None, pat_path), some_pat, _) = let_pat.kind; if let Res::Def(_, pat_did) = pat_path.res; if match_def_path(cx, pat_did, &paths::OPTION_SOME); // check for call to `Iterator::next` - if let ExprKind::MethodCall(method_name, _, [iter_expr], _) = scrutinee_expr.kind; + if let ExprKind::MethodCall(method_name, _, [iter_expr], _) = let_expr.kind; if method_name.ident.name == sym::next; - if is_trait_method(cx, scrutinee_expr, sym::Iterator); - if let Some(iter_expr) = try_parse_iter_expr(cx, iter_expr); + if is_trait_method(cx, let_expr, sym::Iterator); + if let Some(iter_expr_struct) = try_parse_iter_expr(cx, iter_expr); // get the loop containing the match expression - if let Some((_, Node::Expr(loop_expr))) = cx.tcx.hir().parent_iter(expr.hir_id).nth(1); - if !uses_iter(cx, &iter_expr, arm.body); + if !uses_iter(cx, &iter_expr_struct, if_then); then { - (scrutinee_expr, iter_expr, some_pat, loop_expr) + (let_expr, iter_expr_struct, some_pat, expr) } else { return; } @@ -81,6 +86,7 @@ struct IterExpr { /// The path being used. path: Res, } + /// Parses any expression to find out which field of which variable is used. Will return `None` if /// the expression might have side effects. fn try_parse_iter_expr(cx: &LateContext<'_>, mut e: &Expr<'_>) -> Option { @@ -285,6 +291,7 @@ fn needs_mutable_borrow(cx: &LateContext<'tcx>, iter_expr: &IterExpr, loop_expr: } impl Visitor<'tcx> for NestedLoopVisitor<'a, 'b, 'tcx> { type Map = ErasedMap<'tcx>; + fn nested_visit_map(&mut self) -> NestedVisitorMap { NestedVisitorMap::None } diff --git a/clippy_lints/src/manual_map.rs b/clippy_lints/src/manual_map.rs index 7dec1595e0d1..53d97f775435 100644 --- a/clippy_lints/src/manual_map.rs +++ b/clippy_lints/src/manual_map.rs @@ -1,5 +1,6 @@ use crate::{map_unit_fn::OPTION_MAP_UNIT_FN, matches::MATCH_AS_REF}; use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::higher; use clippy_utils::source::{snippet_with_applicability, snippet_with_context}; use clippy_utils::ty::{is_type_diagnostic_item, peel_mid_ty_refs_is_mutable}; use clippy_utils::{ @@ -9,7 +10,7 @@ use clippy_utils::{ use rustc_ast::util::parser::PREC_POSTFIX; use rustc_errors::Applicability; use rustc_hir::LangItem::{OptionNone, OptionSome}; -use rustc_hir::{Arm, BindingAnnotation, Block, Expr, ExprKind, HirId, MatchSource, Mutability, Pat, PatKind}; +use rustc_hir::{Arm, BindingAnnotation, Block, Expr, ExprKind, HirId, Mutability, Pat, PatKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -43,155 +44,168 @@ declare_lint_pass!(ManualMap => [MANUAL_MAP]); impl LateLintPass<'_> for ManualMap { #[allow(clippy::too_many_lines)] fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Match( - scrutinee, - [arm1 @ Arm { guard: None, .. }, arm2 @ Arm { guard: None, .. }], - match_kind, - ) = expr.kind + if let Some(higher::IfLet { + let_pat, + let_expr, + if_then, + if_else: Some(if_else), + }) = higher::IfLet::hir(expr) { - if in_external_macro(cx.sess(), expr.span) || in_constant(cx, expr.hir_id) { - return; - } + manage_lint(cx, expr, (&let_pat.kind, if_then), (&PatKind::Wild, if_else), let_expr); + } - let (scrutinee_ty, ty_ref_count, ty_mutability) = - peel_mid_ty_refs_is_mutable(cx.typeck_results().expr_ty(scrutinee)); - if !(is_type_diagnostic_item(cx, scrutinee_ty, sym::option_type) - && is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::option_type)) - { - return; - } + if let ExprKind::Match(scrutinee, [then @ Arm { guard: None, .. }, r#else @ Arm { guard: None, .. }], _) = + expr.kind + { + manage_lint( + cx, + expr, + (&then.pat.kind, then.body), + (&r#else.pat.kind, r#else.body), + scrutinee, + ); + } + } +} - let expr_ctxt = expr.span.ctxt(); - let (some_expr, some_pat, pat_ref_count, is_wild_none) = match ( - try_parse_pattern(cx, arm1.pat, expr_ctxt), - try_parse_pattern(cx, arm2.pat, expr_ctxt), - ) { - (Some(OptionPat::Wild), Some(OptionPat::Some { pattern, ref_count })) - if is_none_expr(cx, arm1.body) => - { - (arm2.body, pattern, ref_count, true) - }, - (Some(OptionPat::None), Some(OptionPat::Some { pattern, ref_count })) - if is_none_expr(cx, arm1.body) => - { - (arm2.body, pattern, ref_count, false) - }, - (Some(OptionPat::Some { pattern, ref_count }), Some(OptionPat::Wild)) - if is_none_expr(cx, arm2.body) => - { - (arm1.body, pattern, ref_count, true) - }, - (Some(OptionPat::Some { pattern, ref_count }), Some(OptionPat::None)) - if is_none_expr(cx, arm2.body) => - { - (arm1.body, pattern, ref_count, false) - }, - _ => return, - }; +fn manage_lint<'tcx>( + cx: &LateContext<'tcx>, + expr: &'tcx Expr<'_>, + then: (&'tcx PatKind<'_>, &'tcx Expr<'_>), + r#else: (&'tcx PatKind<'_>, &'tcx Expr<'_>), + scrut: &'tcx Expr<'_>, +) { + if in_external_macro(cx.sess(), expr.span) || in_constant(cx, expr.hir_id) { + return; + } - // Top level or patterns aren't allowed in closures. - if matches!(some_pat.kind, PatKind::Or(_)) { - return; - } + let (scrutinee_ty, ty_ref_count, ty_mutability) = peel_mid_ty_refs_is_mutable(cx.typeck_results().expr_ty(scrut)); + if !(is_type_diagnostic_item(cx, scrutinee_ty, sym::option_type) + && is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::option_type)) + { + return; + } - let some_expr = match get_some_expr(cx, some_expr, expr_ctxt) { - Some(expr) => expr, - None => return, - }; + let (then_pat, then_expr) = then; + let (else_pat, else_expr) = r#else; - // These two lints will go back and forth with each other. - if cx.typeck_results().expr_ty(some_expr) == cx.tcx.types.unit - && !is_lint_allowed(cx, OPTION_MAP_UNIT_FN, expr.hir_id) - { - return; - } + let expr_ctxt = expr.span.ctxt(); + let (some_expr, some_pat, pat_ref_count, is_wild_none) = match ( + try_parse_pattern(cx, then_pat, expr_ctxt), + try_parse_pattern(cx, else_pat, expr_ctxt), + ) { + (Some(OptionPat::Wild), Some(OptionPat::Some { pattern, ref_count })) if is_none_expr(cx, then_expr) => { + (else_expr, pattern, ref_count, true) + }, + (Some(OptionPat::None), Some(OptionPat::Some { pattern, ref_count })) if is_none_expr(cx, then_expr) => { + (else_expr, pattern, ref_count, false) + }, + (Some(OptionPat::Some { pattern, ref_count }), Some(OptionPat::Wild)) if is_none_expr(cx, else_expr) => { + (then_expr, pattern, ref_count, true) + }, + (Some(OptionPat::Some { pattern, ref_count }), Some(OptionPat::None)) if is_none_expr(cx, else_expr) => { + (then_expr, pattern, ref_count, false) + }, + _ => return, + }; - // `map` won't perform any adjustments. - if !cx.typeck_results().expr_adjustments(some_expr).is_empty() { - return; - } + // Top level or patterns aren't allowed in closures. + if matches!(some_pat.kind, PatKind::Or(_)) { + return; + } - if !can_move_expr_to_closure(cx, some_expr) { - return; - } + let some_expr = match get_some_expr(cx, some_expr, expr_ctxt) { + Some(expr) => expr, + None => return, + }; - // Determine which binding mode to use. - let explicit_ref = some_pat.contains_explicit_ref_binding(); - let binding_ref = explicit_ref.or_else(|| (ty_ref_count != pat_ref_count).then(|| ty_mutability)); + if cx.typeck_results().expr_ty(some_expr) == cx.tcx.types.unit && !is_lint_allowed(cx, OPTION_MAP_UNIT_FN, expr.hir_id) { + return; + } - let as_ref_str = match binding_ref { - Some(Mutability::Mut) => ".as_mut()", - Some(Mutability::Not) => ".as_ref()", - None => "", - }; + // `map` won't perform any adjustments. + if !cx.typeck_results().expr_adjustments(some_expr).is_empty() { + return; + } - let mut app = Applicability::MachineApplicable; + if !can_move_expr_to_closure(cx, some_expr) { + return; + } - // Remove address-of expressions from the scrutinee. Either `as_ref` will be called, or - // it's being passed by value. - let scrutinee = peel_hir_expr_refs(scrutinee).0; - let (scrutinee_str, _) = snippet_with_context(cx, scrutinee.span, expr_ctxt, "..", &mut app); - let scrutinee_str = - if scrutinee.span.ctxt() == expr.span.ctxt() && scrutinee.precedence().order() < PREC_POSTFIX { - format!("({})", scrutinee_str) - } else { - scrutinee_str.into() - }; + // Determine which binding mode to use. + let explicit_ref = some_pat.contains_explicit_ref_binding(); + let binding_ref = explicit_ref.or_else(|| (ty_ref_count != pat_ref_count).then(|| ty_mutability)); + + let as_ref_str = match binding_ref { + Some(Mutability::Mut) => ".as_mut()", + Some(Mutability::Not) => ".as_ref()", + None => "", + }; + + let mut app = Applicability::MachineApplicable; - let body_str = if let PatKind::Binding(annotation, id, some_binding, None) = some_pat.kind { - match can_pass_as_func(cx, id, some_expr) { - Some(func) if func.span.ctxt() == some_expr.span.ctxt() => { - snippet_with_applicability(cx, func.span, "..", &mut app).into_owned() - }, - _ => { - if path_to_local_id(some_expr, id) - && !is_lint_allowed(cx, MATCH_AS_REF, expr.hir_id) - && binding_ref.is_some() - { - return; - } + // Remove address-of expressions from the scrutinee. Either `as_ref` will be called, or + // it's being passed by value. + let scrutinee = peel_hir_expr_refs(scrut).0; + let (scrutinee_str, _) = snippet_with_context(cx, scrutinee.span, expr_ctxt, "..", &mut app); + let scrutinee_str = if scrutinee.span.ctxt() == expr.span.ctxt() && scrutinee.precedence().order() < PREC_POSTFIX { + format!("({})", scrutinee_str) + } else { + scrutinee_str.into() + }; - // `ref` and `ref mut` annotations were handled earlier. - let annotation = if matches!(annotation, BindingAnnotation::Mutable) { - "mut " - } else { - "" - }; - format!( - "|{}{}| {}", - annotation, - some_binding, - snippet_with_context(cx, some_expr.span, expr_ctxt, "..", &mut app).0 - ) - }, + let body_str = if let PatKind::Binding(annotation, id, some_binding, None) = some_pat.kind { + match can_pass_as_func(cx, id, some_expr) { + Some(func) if func.span.ctxt() == some_expr.span.ctxt() => { + snippet_with_applicability(cx, func.span, "..", &mut app).into_owned() + }, + _ => { + if path_to_local_id(some_expr, id) + && !is_lint_allowed(cx, MATCH_AS_REF, expr.hir_id) + && binding_ref.is_some() + { + return; } - } else if !is_wild_none && explicit_ref.is_none() { - // TODO: handle explicit reference annotations. + + // `ref` and `ref mut` annotations were handled earlier. + let annotation = if matches!(annotation, BindingAnnotation::Mutable) { + "mut " + } else { + "" + }; format!( - "|{}| {}", - snippet_with_context(cx, some_pat.span, expr_ctxt, "..", &mut app).0, + "|{}{}| {}", + annotation, + some_binding, snippet_with_context(cx, some_expr.span, expr_ctxt, "..", &mut app).0 ) - } else { - // Refutable bindings and mixed reference annotations can't be handled by `map`. - return; - }; - - span_lint_and_sugg( - cx, - MANUAL_MAP, - expr.span, - "manual implementation of `Option::map`", - "try this", - if matches!(match_kind, MatchSource::IfLetDesugar { .. }) && is_else_clause(cx.tcx, expr) { - format!("{{ {}{}.map({}) }}", scrutinee_str, as_ref_str, body_str) - } else { - format!("{}{}.map({})", scrutinee_str, as_ref_str, body_str) - }, - app, - ); + }, } - } + } else if !is_wild_none && explicit_ref.is_none() { + // TODO: handle explicit reference annotations. + format!( + "|{}| {}", + snippet_with_context(cx, some_pat.span, expr_ctxt, "..", &mut app).0, + snippet_with_context(cx, some_expr.span, expr_ctxt, "..", &mut app).0 + ) + } else { + // Refutable bindings and mixed reference annotations can't be handled by `map`. + return; + }; + + span_lint_and_sugg( + cx, + MANUAL_MAP, + expr.span, + "manual implementation of `Option::map`", + "try this", + if is_else_clause(cx.tcx, expr) { + format!("{{ {}{}.map({}) }}", scrutinee_str, as_ref_str, body_str) + } else { + format!("{}{}.map({})", scrutinee_str, as_ref_str, body_str) + }, + app, + ); } // Checks whether the expression could be passed as a function, or whether a closure is needed. @@ -199,7 +213,7 @@ impl LateLintPass<'_> for ManualMap { fn can_pass_as_func(cx: &LateContext<'tcx>, binding: HirId, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { match expr.kind { ExprKind::Call(func, [arg]) - if path_to_local_id(arg, binding) && cx.typeck_results().expr_adjustments(arg).is_empty() => + if path_to_local_id (arg, binding) && cx.typeck_results().expr_adjustments(arg).is_empty() => { Some(func) }, @@ -221,21 +235,28 @@ enum OptionPat<'a> { // Try to parse into a recognized `Option` pattern. // i.e. `_`, `None`, `Some(..)`, or a reference to any of those. -fn try_parse_pattern(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, ctxt: SyntaxContext) -> Option> { - fn f(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, ref_count: usize, ctxt: SyntaxContext) -> Option> { - match pat.kind { +fn try_parse_pattern( + cx: &LateContext<'tcx>, + pat_kind: &'tcx PatKind<'_>, + ctxt: SyntaxContext, +) -> Option> { + fn f( + cx: &LateContext<'tcx>, + pat_kind: &'tcx PatKind<'_>, + ref_count: usize, + ctxt: SyntaxContext, + ) -> Option> { + match pat_kind { PatKind::Wild => Some(OptionPat::Wild), - PatKind::Ref(pat, _) => f(cx, pat, ref_count + 1, ctxt), + PatKind::Ref(ref_pat, _) => f(cx, &ref_pat.kind, ref_count + 1, ctxt), PatKind::Path(ref qpath) if is_lang_ctor(cx, qpath, OptionNone) => Some(OptionPat::None), - PatKind::TupleStruct(ref qpath, [pattern], _) - if is_lang_ctor(cx, qpath, OptionSome) && pat.span.ctxt() == ctxt => - { + PatKind::TupleStruct(ref qpath, [pattern], _) if is_lang_ctor(cx, qpath, OptionSome) => { Some(OptionPat::Some { pattern, ref_count }) }, _ => None, } } - f(cx, pat, 0, ctxt) + f(cx, pat_kind, 0, ctxt) } // Checks for an expression wrapped by the `Some` constructor. Returns the contained expression. diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index db12c377488b..4e040508b6bf 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -73,7 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { } if_chain! { - if let ExprKind::If(cond, then, _) = &expr.kind; + if let Some(higher::If { cond, then, .. }) = higher::If::hir(expr); if let ExprKind::MethodCall(_, _, [target_arg, pattern], _) = cond.kind; if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(cond.hir_id); if let ExprKind::Path(target_path) = &target_arg.kind; @@ -212,7 +212,7 @@ fn find_stripping<'tcx>( if is_ref_str(self.cx, ex); let unref = peel_ref(ex); if let ExprKind::Index(indexed, index) = &unref.kind; - if let Some(higher::Range { start, end, .. }) = higher::range(index); + if let Some(higher::Range { start, end, .. }) = higher::Range::hir(index); if let ExprKind::Path(path) = &indexed.kind; if self.cx.qpath_res(path, ex.hir_id) == self.target; then { diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 5360c02f9053..a183d0c66e8c 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -2,6 +2,7 @@ use clippy_utils::consts::{constant, miri_to_const, Constant}; use clippy_utils::diagnostics::{ multispan_sugg, span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then, }; +use clippy_utils::higher; use clippy_utils::source::{expr_block, indent_of, snippet, snippet_block, snippet_opt, snippet_with_applicability}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item, match_type, peel_mid_ty_refs}; @@ -12,8 +13,10 @@ use clippy_utils::{ strip_pat_refs, }; use clippy_utils::{paths, search_same, SpanlessEq, SpanlessHash}; +use core::array; +use core::iter::{once, ExactSizeIterator}; use if_chain::if_chain; -use rustc_ast::ast::LitKind; +use rustc_ast::ast::{Attribute, LitKind}; use rustc_errors::Applicability; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::LangItem::{OptionNone, OptionSome}; @@ -628,8 +631,11 @@ impl<'tcx> LateLintPass<'tcx> for Matches { check_match_single_binding(cx, ex, arms, expr); } } - if let ExprKind::Match(ex, arms, _) = expr.kind { - check_match_ref_pats(cx, ex, arms, expr); + if let ExprKind::Match(ref ex, ref arms, _) = expr.kind { + check_match_ref_pats(cx, ex, arms.iter().map(|el| el.pat), expr); + } + if let Some(higher::IfLet { let_pat, let_expr, .. }) = higher::IfLet::hir(expr) { + check_match_ref_pats(cx, let_expr, once(let_pat), expr); } } @@ -1179,39 +1185,40 @@ fn is_panic_block(block: &Block<'_>) -> bool { } } -fn check_match_ref_pats(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { - if has_only_ref_pats(arms) { - let mut suggs = Vec::with_capacity(arms.len() + 1); - let (title, msg) = if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = ex.kind { - let span = ex.span.source_callsite(); - suggs.push((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string())); - ( - "you don't need to add `&` to both the expression and the patterns", - "try", - ) - } else { - let span = ex.span.source_callsite(); - suggs.push((span, Sugg::hir_with_macro_callsite(cx, ex, "..").deref().to_string())); - ( - "you don't need to add `&` to all patterns", - "instead of prefixing all patterns with `&`, you can dereference the expression", - ) - }; - - suggs.extend(arms.iter().filter_map(|a| { - if let PatKind::Ref(refp, _) = a.pat.kind { - Some((a.pat.span, snippet(cx, refp.span, "..").to_string())) - } else { - None - } - })); +fn check_match_ref_pats<'a, 'b, I>(cx: &LateContext<'_>, ex: &Expr<'_>, pats: I, expr: &Expr<'_>) +where + 'b: 'a, + I: Clone + Iterator>, +{ + if !has_only_ref_pats(pats.clone()) { + return; + } - span_lint_and_then(cx, MATCH_REF_PATS, expr.span, title, |diag| { - if !expr.span.from_expansion() { - multispan_sugg(diag, msg, suggs); - } - }); + let (first_sugg, msg, title); + let span = ex.span.source_callsite(); + if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = ex.kind { + first_sugg = once((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string())); + msg = "try"; + title = "you don't need to add `&` to both the expression and the patterns"; + } else { + first_sugg = once((span, Sugg::hir_with_macro_callsite(cx, ex, "..").deref().to_string())); + msg = "instead of prefixing all patterns with `&`, you can dereference the expression"; + title = "you don't need to add `&` to all patterns"; } + + let remaining_suggs = pats.filter_map(|pat| { + if let PatKind::Ref(ref refp, _) = pat.kind { + Some((pat.span, snippet(cx, refp.span, "..").to_string())) + } else { + None + } + }); + + span_lint_and_then(cx, MATCH_REF_PATS, expr.span, title, |diag| { + if !expr.span.from_expansion() { + multispan_sugg(diag, msg, first_sugg.chain(remaining_suggs)); + } + }); } fn check_match_as_ref(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { @@ -1286,46 +1293,99 @@ fn check_wild_in_or_pats(cx: &LateContext<'_>, arms: &[Arm<'_>]) { /// Lint a `match` or `if let .. { .. } else { .. }` expr that could be replaced by `matches!` fn check_match_like_matches<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool { - if let ExprKind::Match(ex, arms, ref match_source) = &expr.kind { - match match_source { - MatchSource::Normal => find_matches_sugg(cx, ex, arms, expr, false), - MatchSource::IfLetDesugar { .. } => find_matches_sugg(cx, ex, arms, expr, true), - _ => false, - } - } else { - false + if let Some(higher::IfLet { + let_pat, + let_expr, + if_then, + if_else: Some(if_else), + }) = higher::IfLet::hir(expr) + { + return find_matches_sugg( + cx, + let_expr, + array::IntoIter::new([(&[][..], Some(let_pat), if_then, None), (&[][..], None, if_else, None)]), + expr, + true, + ); } + + if let ExprKind::Match(scrut, arms, MatchSource::Normal) = expr.kind { + return find_matches_sugg( + cx, + scrut, + arms.iter().map(|arm| { + ( + cx.tcx.hir().attrs(arm.hir_id), + Some(arm.pat), + arm.body, + arm.guard.as_ref(), + ) + }), + expr, + false, + ); + } + + false } -/// Lint a `match` or desugared `if let` for replacement by `matches!` -fn find_matches_sugg(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>, desugared: bool) -> bool { +/// Lint a `match` or `if let` for replacement by `matches!` +fn find_matches_sugg<'a, 'b, I>( + cx: &LateContext<'_>, + ex: &Expr<'_>, + mut iter: I, + expr: &Expr<'_>, + is_if_let: bool, +) -> bool +where + 'b: 'a, + I: Clone + + DoubleEndedIterator + + ExactSizeIterator + + Iterator< + Item = ( + &'a [Attribute], + Option<&'a Pat<'b>>, + &'a Expr<'b>, + Option<&'a Guard<'b>>, + ), + >, +{ if_chain! { - if arms.len() >= 2; + if iter.len() >= 2; if cx.typeck_results().expr_ty(expr).is_bool(); - if let Some((b1_arm, b0_arms)) = arms.split_last(); - if let Some(b0) = find_bool_lit(&b0_arms[0].body.kind, desugared); - if let Some(b1) = find_bool_lit(&b1_arm.body.kind, desugared); - if is_wild(b1_arm.pat); + if let Some((_, last_pat_opt, last_expr, _)) = iter.next_back(); + let iter_without_last = iter.clone(); + if let Some((first_attrs, _, first_expr, first_guard)) = iter.next(); + if let Some(b0) = find_bool_lit(&first_expr.kind, is_if_let); + if let Some(b1) = find_bool_lit(&last_expr.kind, is_if_let); if b0 != b1; - let if_guard = &b0_arms[0].guard; - if if_guard.is_none() || b0_arms.len() == 1; - if cx.tcx.hir().attrs(b0_arms[0].hir_id).is_empty(); - if b0_arms[1..].iter() + if first_guard.is_none() || iter.len() == 0; + if first_attrs.is_empty(); + if iter .all(|arm| { - find_bool_lit(&arm.body.kind, desugared).map_or(false, |b| b == b0) && - arm.guard.is_none() && cx.tcx.hir().attrs(arm.hir_id).is_empty() + find_bool_lit(&arm.2.kind, is_if_let).map_or(false, |b| b == b0) && arm.3.is_none() && arm.0.is_empty() }); then { + if let Some(ref last_pat) = last_pat_opt { + if !is_wild(last_pat) { + return false; + } + } + // The suggestion may be incorrect, because some arms can have `cfg` attributes // evaluated into `false` and so such arms will be stripped before. let mut applicability = Applicability::MaybeIncorrect; let pat = { use itertools::Itertools as _; - b0_arms.iter() - .map(|arm| snippet_with_applicability(cx, arm.pat.span, "..", &mut applicability)) + iter_without_last + .filter_map(|arm| { + let pat_span = arm.1?.span; + Some(snippet_with_applicability(cx, pat_span, "..", &mut applicability)) + }) .join(" | ") }; - let pat_and_guard = if let Some(Guard::If(g)) = if_guard { + let pat_and_guard = if let Some(Guard::If(g)) = first_guard { format!("{} if {}", pat, snippet_with_applicability(cx, g.span, "..", &mut applicability)) } else { pat @@ -1342,7 +1402,7 @@ fn find_matches_sugg(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr cx, MATCH_LIKE_MATCHES_MACRO, expr.span, - &format!("{} expression looks like `matches!` macro", if desugared { "if let .. else" } else { "match" }), + &format!("{} expression looks like `matches!` macro", if is_if_let { "if let .. else" } else { "match" }), "try this", format!( "{}matches!({}, {})", @@ -1360,7 +1420,7 @@ fn find_matches_sugg(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr } /// Extract a `bool` or `{ bool }` -fn find_bool_lit(ex: &ExprKind<'_>, desugared: bool) -> Option { +fn find_bool_lit(ex: &ExprKind<'_>, is_if_let: bool) -> Option { match ex { ExprKind::Lit(Spanned { node: LitKind::Bool(b), .. @@ -1372,7 +1432,7 @@ fn find_bool_lit(ex: &ExprKind<'_>, desugared: bool) -> Option { .. }, _, - ) if desugared => { + ) if is_if_let => { if let ExprKind::Lit(Spanned { node: LitKind::Bool(b), .. }) = exp.kind @@ -1644,19 +1704,26 @@ fn is_ref_some_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> Option]) -> bool { - let mapped = arms - .iter() - .map(|a| { - match a.pat.kind { - PatKind::Ref(..) => Some(true), // &-patterns - PatKind::Wild => Some(false), // an "anything" wildcard is also fine - _ => None, // any other pattern is not fine +fn has_only_ref_pats<'a, 'b, I>(pats: I) -> bool +where + 'b: 'a, + I: Iterator>, +{ + let mut at_least_one_is_true = false; + for opt in pats.map(|pat| match pat.kind { + PatKind::Ref(..) => Some(true), // &-patterns + PatKind::Wild => Some(false), // an "anything" wildcard is also fine + _ => None, // any other pattern is not fine + }) { + if let Some(inner) = opt { + if inner { + at_least_one_is_true = true; } - }) - .collect::>>(); - // look for Some(v) where there's at least one true element - mapped.map_or(false, |v| v.iter().any(|el| *el)) + } else { + return false; + } + } + at_least_one_is_true } pub fn overlapping(ranges: &[SpannedRange]) -> Option<(&SpannedRange, &SpannedRange)> @@ -1745,6 +1812,7 @@ where mod redundant_pattern_match { use super::REDUNDANT_PATTERN_MATCHING; use clippy_utils::diagnostics::span_lint_and_then; + use clippy_utils::higher; use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item, is_type_lang_item, match_type}; use clippy_utils::{is_lang_ctor, is_qpath_def_path, is_trait_method, paths}; @@ -1755,22 +1823,27 @@ mod redundant_pattern_match { use rustc_hir::LangItem::{OptionNone, OptionSome, PollPending, PollReady, ResultErr, ResultOk}; use rustc_hir::{ intravisit::{walk_expr, ErasedMap, NestedVisitorMap, Visitor}, - Arm, Block, Expr, ExprKind, LangItem, MatchSource, Node, PatKind, QPath, + Arm, Block, Expr, ExprKind, LangItem, MatchSource, Node, Pat, PatKind, QPath, }; use rustc_lint::LateContext; use rustc_middle::ty::{self, subst::GenericArgKind, Ty}; use rustc_span::sym; pub fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Match(op, arms, ref match_source) = &expr.kind { - match match_source { - MatchSource::Normal => find_sugg_for_match(cx, expr, op, arms), - MatchSource::IfLetDesugar { contains_else_clause } => { - find_sugg_for_if_let(cx, expr, op, &arms[0], "if", *contains_else_clause); - }, - MatchSource::WhileLetDesugar => find_sugg_for_if_let(cx, expr, op, &arms[0], "while", false), - _ => {}, - } + if let Some(higher::IfLet { + if_else, + let_pat, + let_expr, + .. + }) = higher::IfLet::ast(cx, expr) + { + find_sugg_for_if_let(cx, expr, let_pat, let_expr, "if", if_else.is_some()) + } + if let ExprKind::Match(op, arms, MatchSource::Normal) = &expr.kind { + find_sugg_for_match(cx, expr, op, arms) + } + if let Some(higher::WhileLet { let_pat, let_expr, .. }) = higher::WhileLet::hir(expr) { + find_sugg_for_if_let(cx, expr, let_pat, let_expr, "while", false) } } @@ -1924,18 +1997,18 @@ mod redundant_pattern_match { fn find_sugg_for_if_let<'tcx>( cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, - op: &'tcx Expr<'tcx>, - arm: &Arm<'_>, + let_pat: &Pat<'_>, + let_expr: &'tcx Expr<'_>, keyword: &'static str, has_else: bool, ) { // also look inside refs - let mut kind = &arm.pat.kind; + let mut kind = &let_pat.kind; // if we have &None for example, peel it so we can detect "if let None = x" if let PatKind::Ref(inner, _mutability) = kind { kind = &inner.kind; } - let op_ty = cx.typeck_results().expr_ty(op); + let op_ty = cx.typeck_results().expr_ty(let_expr); // Determine which function should be used, and the type contained by the corresponding // variant. let (good_method, inner_ty) = match kind { @@ -1989,38 +2062,38 @@ mod redundant_pattern_match { // scrutinee would be, so they have to be considered as well. // e.g. in `if let Some(x) = foo.lock().unwrap().baz.as_ref() { .. }` the lock will be held // for the duration if body. - let needs_drop = type_needs_ordered_drop(cx, check_ty) || temporaries_need_ordered_drop(cx, op); + let needs_drop = type_needs_ordered_drop(cx, check_ty) || temporaries_need_ordered_drop(cx, let_expr); // check that `while_let_on_iterator` lint does not trigger if_chain! { if keyword == "while"; - if let ExprKind::MethodCall(method_path, _, _, _) = op.kind; + if let ExprKind::MethodCall(method_path, _, _, _) = let_expr.kind; if method_path.ident.name == sym::next; - if is_trait_method(cx, op, sym::Iterator); + if is_trait_method(cx, let_expr, sym::Iterator); then { return; } } - let result_expr = match &op.kind { + let result_expr = match &let_expr.kind { ExprKind::AddrOf(_, _, borrowed) => borrowed, - _ => op, + _ => let_expr, }; span_lint_and_then( cx, REDUNDANT_PATTERN_MATCHING, - arm.pat.span, + let_pat.span, &format!("redundant pattern matching, consider using `{}`", good_method), |diag| { - // while let ... = ... { ... } + // if/while let ... = ... { ... } // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ let expr_span = expr.span; - // while let ... = ... { ... } + // if/while let ... = ... { ... } // ^^^ let op_span = result_expr.span.source_callsite(); - // while let ... = ... { ... } + // if/while let ... = ... { ... } // ^^^^^^^^^^^^^^^^^^^ let span = expr_span.until(op_span.shrink_to_hi()); diff --git a/clippy_lints/src/methods/iter_next_slice.rs b/clippy_lints/src/methods/iter_next_slice.rs index a49851de38e1..6954da67e32c 100644 --- a/clippy_lints/src/methods/iter_next_slice.rs +++ b/clippy_lints/src/methods/iter_next_slice.rs @@ -18,7 +18,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, cal // since it is already covered by `&loops::ITER_NEXT_LOOP` let mut parent_expr_opt = get_parent_expr(cx, expr); while let Some(parent_expr) = parent_expr_opt { - if higher::for_loop(parent_expr).is_some() { + if higher::ForLoop::hir(parent_expr).is_some() { return; } parent_expr_opt = get_parent_expr(cx, parent_expr); @@ -29,7 +29,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, cal if_chain! { if let hir::ExprKind::Index(caller_var, index_expr) = &caller_expr.kind; if let Some(higher::Range { start: Some(start_expr), end: None, limits: ast::RangeLimits::HalfOpen }) - = higher::range(index_expr); + = higher::Range::hir(index_expr); if let hir::ExprKind::Lit(ref start_lit) = &start_expr.kind; if let ast::LitKind::Int(start_idx, _) = start_lit.node; then { diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index d5032c5ba7f2..610152a217f1 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -53,7 +53,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { return; } - if let Some((_, arg, body, _)) = higher::for_loop(expr) { + if let Some(higher::ForLoop { arg, body, .. }) = higher::ForLoop::hir(expr) { // A `for` loop lowers to: // ```rust // match ::std::iter::Iterator::next(&mut iter) { diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index 36f2829a5b94..c9dd94400efb 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -3,6 +3,7 @@ //! This lint is **warn** by default use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; +use clippy_utils::higher; use clippy_utils::source::snippet_with_applicability; use clippy_utils::sugg::Sugg; use clippy_utils::{is_else_clause, is_expn_of}; @@ -77,10 +78,15 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBool { if e.span.from_expansion() { return; } - if let ExprKind::If(pred, then_block, Some(else_expr)) = e.kind { + if let Some(higher::If { + cond, + then, + r#else: Some(r#else), + }) = higher::If::hir(e) + { let reduce = |ret, not| { let mut applicability = Applicability::MachineApplicable; - let snip = Sugg::hir_with_applicability(cx, pred, "", &mut applicability); + let snip = Sugg::hir_with_applicability(cx, cond, "", &mut applicability); let mut snip = if not { !snip } else { snip }; if ret { @@ -101,8 +107,8 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBool { applicability, ); }; - if let ExprKind::Block(then_block, _) = then_block.kind { - match (fetch_bool_block(then_block), fetch_bool_expr(else_expr)) { + if let ExprKind::Block(then, _) = then.kind { + match (fetch_bool_block(then), fetch_bool_expr(r#else)) { (RetBool(true), RetBool(true)) | (Bool(true), Bool(true)) => { span_lint( cx, diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index f6254aa715a4..ac21eb5275f0 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -1,7 +1,6 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; use rustc_ast::ast::{ - Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, FnKind, Item, ItemKind, Local, Pat, - PatKind, + Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, FnKind, Item, ItemKind, Local, Pat, PatKind, }; use rustc_ast::visit::{walk_block, walk_expr, walk_pat, Visitor}; use rustc_lint::{EarlyContext, EarlyLintPass}; diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index 7aef3a5f34cf..d0b0bad5eb1c 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -1,4 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::higher; use clippy_utils::sugg::Sugg; use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::usage::contains_return_break_continue_macro; @@ -6,7 +7,7 @@ use clippy_utils::{eager_or_lazy, in_macro, is_else_clause, is_lang_ctor}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::LangItem::OptionSome; -use rustc_hir::{Arm, BindingAnnotation, Block, Expr, ExprKind, MatchSource, Mutability, PatKind, UnOp}; +use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, Mutability, PatKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; @@ -84,20 +85,20 @@ struct OptionIfLetElseOccurence { /// Extracts the body of a given arm. If the arm contains only an expression, /// then it returns the expression. Otherwise, it returns the entire block -fn extract_body_from_arm<'a>(arm: &'a Arm<'a>) -> Option<&'a Expr<'a>> { +fn extract_body_from_expr<'a>(expr: &'a Expr<'a>) -> Option<&'a Expr<'a>> { if let ExprKind::Block( Block { - stmts: statements, - expr: Some(expr), + stmts: block_stmts, + expr: Some(block_expr), .. }, _, - ) = &arm.body.kind + ) = expr.kind { - if let [] = statements { - Some(expr) + if let [] = block_stmts { + Some(block_expr) } else { - Some(arm.body) + Some(expr) } } else { None @@ -121,37 +122,33 @@ fn format_option_in_sugg(cx: &LateContext<'_>, cond_expr: &Expr<'_>, as_ref: boo /// If this expression is the option if let/else construct we're detecting, then /// this function returns an `OptionIfLetElseOccurence` struct with details if /// this construct is found, or None if this construct is not found. -fn detect_option_if_let_else<'tcx>( - cx: &'_ LateContext<'tcx>, - expr: &'_ Expr<'tcx>, -) -> Option { +fn detect_option_if_let_else<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> Option { if_chain! { if !in_macro(expr.span); // Don't lint macros, because it behaves weirdly - if let ExprKind::Match(cond_expr, arms, MatchSource::IfLetDesugar{contains_else_clause: true}) = &expr.kind; + if let Some(higher::IfLet { let_pat, let_expr, if_then, if_else: Some(if_else) }) = higher::IfLet::hir(expr); if !is_else_clause(cx.tcx, expr); - if arms.len() == 2; - if !is_result_ok(cx, cond_expr); // Don't lint on Result::ok because a different lint does it already - if let PatKind::TupleStruct(struct_qpath, [inner_pat], _) = &arms[0].pat.kind; + if !is_result_ok(cx, let_expr); // Don't lint on Result::ok because a different lint does it already + if let PatKind::TupleStruct(struct_qpath, [inner_pat], _) = &let_pat.kind; if is_lang_ctor(cx, struct_qpath, OptionSome); if let PatKind::Binding(bind_annotation, _, id, _) = &inner_pat.kind; - if !contains_return_break_continue_macro(arms[0].body); - if !contains_return_break_continue_macro(arms[1].body); + if !contains_return_break_continue_macro(if_then); + if !contains_return_break_continue_macro(if_else); then { let capture_mut = if bind_annotation == &BindingAnnotation::Mutable { "mut " } else { "" }; - let some_body = extract_body_from_arm(&arms[0])?; - let none_body = extract_body_from_arm(&arms[1])?; + let some_body = extract_body_from_expr(if_then)?; + let none_body = extract_body_from_expr(if_else)?; let method_sugg = if eager_or_lazy::is_eagerness_candidate(cx, none_body) { "map_or" } else { "map_or_else" }; let capture_name = id.name.to_ident_string(); - let (as_ref, as_mut) = match &cond_expr.kind { + let (as_ref, as_mut) = match &let_expr.kind { ExprKind::AddrOf(_, Mutability::Not, _) => (true, false), ExprKind::AddrOf(_, Mutability::Mut, _) => (false, true), _ => (bind_annotation == &BindingAnnotation::Ref, bind_annotation == &BindingAnnotation::RefMut), }; - let cond_expr = match &cond_expr.kind { + let cond_expr = match let_expr.kind { // Pointer dereferencing happens automatically, so we can omit it in the suggestion ExprKind::Unary(UnOp::Deref, expr) | ExprKind::AddrOf(_, _, expr) => expr, - _ => cond_expr, + _ => let_expr, }; Some(OptionIfLetElseOccurence { option: format_option_in_sugg(cx, cond_expr, as_ref, as_mut), diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index 4534f6e25165..35cff4141a90 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -104,22 +104,25 @@ impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch { } fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Match(expr, arms, source) = expr.kind { - match source { - MatchSource::Normal | MatchSource::IfLetDesugar { .. } | MatchSource::WhileLetDesugar => { - if let Some(expr_ty) = cx.typeck_results().node_type_opt(expr.hir_id) { - 'pattern_checks: for arm in arms { - let pat = &arm.pat; - if in_external_macro(cx.sess(), pat.span) { - continue 'pattern_checks; - } - if apply_lint(cx, pat, expr_ty, DerefPossible::Possible) { - break 'pattern_checks; - } - } + if let ExprKind::Match(scrutinee, arms, MatchSource::Normal) = expr.kind { + if let Some(expr_ty) = cx.typeck_results().node_type_opt(scrutinee.hir_id) { + 'pattern_checks: for arm in arms { + let pat = &arm.pat; + if in_external_macro(cx.sess(), pat.span) { + continue 'pattern_checks; } - }, - _ => (), + if apply_lint(cx, pat, expr_ty, DerefPossible::Possible) { + break 'pattern_checks; + } + } + } + } + if let ExprKind::Let(let_pat, let_expr, _) = expr.kind { + if let Some(ref expr_ty) = cx.typeck_results().node_type_opt(let_expr.hir_id) { + if in_external_macro(cx.sess(), let_pat.span) { + return; + } + apply_lint(cx, let_pat, expr_ty, DerefPossible::Possible); } } } diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 0e682c692c7a..91085c13ac4a 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -1,4 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::higher; use clippy_utils::is_lang_ctor; use clippy_utils::source::snippet_with_applicability; use clippy_utils::sugg::Sugg; @@ -7,7 +8,7 @@ use clippy_utils::{eq_expr_value, path_to_local_id}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::LangItem::{OptionNone, OptionSome}; -use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, MatchSource, PatKind, StmtKind}; +use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, PatKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; @@ -50,10 +51,10 @@ impl QuestionMark { /// If it matches, it will suggest to use the question mark operator instead fn check_is_none_and_early_return_none(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { - if let ExprKind::If(if_expr, body, else_) = &expr.kind; - if let ExprKind::MethodCall(segment, _, args, _) = &if_expr.kind; + if let Some(higher::If { cond, then, r#else }) = higher::If::hir(expr); + if let ExprKind::MethodCall(segment, _, args, _) = &cond.kind; if segment.ident.name == sym!(is_none); - if Self::expression_returns_none(cx, body); + if Self::expression_returns_none(cx, then); if let Some(subject) = args.get(0); if Self::is_option(cx, subject); @@ -61,9 +62,9 @@ impl QuestionMark { let mut applicability = Applicability::MachineApplicable; let receiver_str = &Sugg::hir_with_applicability(cx, subject, "..", &mut applicability); let mut replacement: Option = None; - if let Some(else_) = else_ { + if let Some(else_inner) = r#else { if_chain! { - if let ExprKind::Block(block, None) = &else_.kind; + if let ExprKind::Block(block, None) = &else_inner.kind; if block.stmts.is_empty(); if let Some(block_expr) = &block.expr; if eq_expr_value(cx, subject, block_expr); @@ -96,25 +97,23 @@ impl QuestionMark { fn check_if_let_some_and_early_return_none(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { - if let ExprKind::Match(subject, arms, source) = &expr.kind; - if *source == MatchSource::IfLetDesugar { contains_else_clause: true }; - if Self::is_option(cx, subject); + if let Some(higher::IfLet { let_pat, let_expr, if_then, if_else: Some(if_else) }) = higher::IfLet::hir(expr); + if Self::is_option(cx, let_expr); - if let PatKind::TupleStruct(path1, fields, None) = &arms[0].pat.kind; + if let PatKind::TupleStruct(ref path1, fields, None) = let_pat.kind; if is_lang_ctor(cx, path1, OptionSome); if let PatKind::Binding(annot, bind_id, _, _) = fields[0].kind; let by_ref = matches!(annot, BindingAnnotation::Ref | BindingAnnotation::RefMut); - if let ExprKind::Block(block, None) = &arms[0].body.kind; + if let ExprKind::Block(ref block, None) = if_then.kind; if block.stmts.is_empty(); if let Some(trailing_expr) = &block.expr; if path_to_local_id(trailing_expr, bind_id); - if let PatKind::Wild = arms[1].pat.kind; - if Self::expression_returns_none(cx, arms[1].body); + if Self::expression_returns_none(cx, if_else); then { let mut applicability = Applicability::MachineApplicable; - let receiver_str = snippet_with_applicability(cx, subject.span, "..", &mut applicability); + let receiver_str = snippet_with_applicability(cx, let_expr.span, "..", &mut applicability); let replacement = format!( "{}{}?", receiver_str, diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 0179bd48ee3c..0114a2f97a22 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -329,7 +329,7 @@ fn check_range_zip_with_len(cx: &LateContext<'_>, path: &PathSegment<'_>, args: if let ExprKind::MethodCall(iter_path, _, iter_args, _) = iter.kind; if iter_path.ident.name == sym::iter; // range expression in `.zip()` call: `0..x.len()` - if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::range(zip_arg); + if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::Range::hir(zip_arg); if is_integer_const(cx, start, 0); // `.len()` call if let ExprKind::MethodCall(len_path, _, len_args, _) = end.kind; @@ -337,7 +337,7 @@ fn check_range_zip_with_len(cx: &LateContext<'_>, path: &PathSegment<'_>, args: // `.iter()` and `.len()` called on same `Path` if let ExprKind::Path(QPath::Resolved(_, iter_path)) = iter_args[0].kind; if let ExprKind::Path(QPath::Resolved(_, len_path)) = len_args[0].kind; - if SpanlessEq::new(cx).eq_path_segments(iter_path.segments, len_path.segments); + if SpanlessEq::new(cx).eq_path_segments(&iter_path.segments, &len_path.segments); then { span_lint(cx, RANGE_ZIP_WITH_LEN, @@ -356,7 +356,7 @@ fn check_exclusive_range_plus_one(cx: &LateContext<'_>, expr: &Expr<'_>) { start, end: Some(end), limits: RangeLimits::HalfOpen - }) = higher::range(expr); + }) = higher::Range::hir(expr); if let Some(y) = y_plus_one(cx, end); then { let span = if expr.span.from_expansion() { @@ -401,7 +401,7 @@ fn check_exclusive_range_plus_one(cx: &LateContext<'_>, expr: &Expr<'_>) { // inclusive range minus one: `x..=(y-1)` fn check_inclusive_range_minus_one(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { - if let Some(higher::Range { start, end: Some(end), limits: RangeLimits::Closed }) = higher::range(expr); + if let Some(higher::Range { start, end: Some(end), limits: RangeLimits::Closed }) = higher::Range::hir(expr); if let Some(y) = y_minus_one(cx, end); then { span_lint_and_then( @@ -438,8 +438,8 @@ fn check_reversed_empty_range(cx: &LateContext<'_>, expr: &Expr<'_>) { fn is_for_loop_arg(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let mut cur_expr = expr; while let Some(parent_expr) = get_parent_expr(cx, cur_expr) { - match higher::for_loop(parent_expr) { - Some((_, args, _, _)) if args.hir_id == expr.hir_id => return true, + match higher::ForLoop::hir(parent_expr) { + Some(higher::ForLoop { arg, .. }) if arg.hir_id == expr.hir_id => return true, _ => cur_expr = parent_expr, } } @@ -455,7 +455,7 @@ fn check_reversed_empty_range(cx: &LateContext<'_>, expr: &Expr<'_>) { } if_chain! { - if let Some(higher::Range { start: Some(start), end: Some(end), limits }) = higher::range(expr); + if let Some(higher::Range { start: Some(start), end: Some(end), limits }) = higher::Range::hir(expr); let ty = cx.typeck_results().expr_ty(start); if let ty::Int(_) | ty::Uint(_) = ty.kind(); if let Some((start_idx, _)) = constant(cx, cx.typeck_results(), start); diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index eeeac35a6d51..530b3396abef 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -725,7 +725,7 @@ fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) { BinaryOp(_, box (lhs, rhs)) | CheckedBinaryOp(_, box (lhs, rhs)) => { visit_op(lhs); visit_op(rhs); - } + }, _ => (), } } diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index db4b1002ce12..e153288aa58d 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -212,14 +212,6 @@ fn check_final_expr<'tcx>( check_final_expr(cx, arm.body, Some(arm.body.span), RetReplacement::Block); } }, - MatchSource::IfLetDesugar { - contains_else_clause: true, - } => { - if let ExprKind::Block(ifblock, _) = arms[0].body.kind { - check_block_return(cx, ifblock); - } - check_final_expr(cx, arms[1].body, None, RetReplacement::Empty); - }, _ => (), }, ExprKind::DropTemps(expr) => check_final_expr(cx, expr, None, RetReplacement::Empty), diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index a8e962d1af3f..44d5ff0b63ad 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -588,7 +588,7 @@ fn ident_difference_expr_with_base_location( | (ForLoop(_, _, _, _), ForLoop(_, _, _, _)) | (While(_, _, _), While(_, _, _)) | (If(_, _, _), If(_, _, _)) - | (Let(_, _), Let(_, _)) + | (Let(_, _, _), Let(_, _, _)) | (Type(_, _), Type(_, _)) | (Cast(_, _), Cast(_, _)) | (Lit(_), Lit(_)) diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index c8a231341b7e..d6cf7190abb0 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -67,7 +67,7 @@ impl EarlyLintPass for UnnestedOrPatterns { fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) { if meets_msrv(self.msrv.as_ref(), &msrvs::OR_PATTERNS) { - if let ast::ExprKind::Let(pat, _) = &e.kind { + if let ast::ExprKind::Let(pat, _, _) = &e.kind { lint_unnested_or_patterns(cx, pat); } } diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index c5b8acb9982d..bffd9f3612b0 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -1,4 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::higher; use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::{differing_macro_contexts, usage::is_potentially_mutated}; use if_chain::if_chain; @@ -160,11 +161,11 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> { if in_external_macro(self.cx.tcx.sess, expr.span) { return; } - if let ExprKind::If(cond, then, els) = &expr.kind { + if let Some(higher::If { cond, then, r#else }) = higher::If::hir(expr) { walk_expr(self, cond); self.visit_branch(cond, then, false); - if let Some(els) = els { - self.visit_branch(cond, els, true); + if let Some(else_inner) = r#else { + self.visit_branch(cond, else_inner, true); } } else { // find `unwrap[_err]()` calls: diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 61fd375a9892..f93d7782e251 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -208,6 +208,15 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { print!(" if let ExprKind::"); let current = format!("{}.kind", self.current); match expr.kind { + ExprKind::Let(pat, expr, _) => { + let let_pat = self.next("pat"); + let let_expr = self.next("expr"); + println!(" Let(ref {}, ref {}, _) = {};", let_pat, let_expr, current); + self.current = let_expr; + self.visit_expr(expr); + self.current = let_pat; + self.visit_pat(pat); + }, ExprKind::Box(inner) => { let inner_pat = self.next("inner"); println!("Box(ref {}) = {};", inner_pat, current); diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index f7ddee12dcf6..6bf216cec167 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -66,28 +66,6 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector { hir::ImplItemKind::TyAlias(_) => println!("associated type"), } } - // fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx - // hir::TraitItem) { - // if !has_attr(&item.attrs) { - // return; - // } - // } - // - // fn check_variant(&mut self, cx: &LateContext<'tcx>, var: &'tcx - // hir::Variant, _: - // &hir::Generics) { - // if !has_attr(&var.node.attrs) { - // return; - // } - // } - // - // fn check_field_def(&mut self, cx: &LateContext<'tcx>, field: &'tcx - // hir::FieldDef) { - // if !has_attr(&field.attrs) { - // return; - // } - // } - // fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if !has_attr(cx.sess(), cx.tcx.hir().attrs(expr.hir_id)) { @@ -127,13 +105,6 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector { hir::StmtKind::Expr(e) | hir::StmtKind::Semi(e) => print_expr(cx, e, 0), } } - // fn check_foreign_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx - // hir::ForeignItem) { - // if !has_attr(&item.attrs) { - // return; - // } - // } - // } fn has_attr(sess: &Session, attrs: &[Attribute]) -> bool { @@ -171,6 +142,10 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { print_expr(cx, arg, indent + 1); } }, + hir::ExprKind::Let(ref pat, ref expr, _) => { + print_pat(cx, pat, indent + 1); + print_expr(cx, expr, indent + 1); + }, hir::ExprKind::MethodCall(path, _, args, _) => { println!("{}MethodCall", ind); println!("{}method name: {}", ind, path.ident.name); diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index 32fa46f042ce..95a45fa937f1 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -49,8 +49,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec { if_chain! { if let ty::Ref(_, ty, _) = cx.typeck_results().expr_ty_adjusted(expr).kind(); if let ty::Slice(..) = ty.kind(); - if let ExprKind::AddrOf(BorrowKind::Ref, mutability, addressee) = expr.kind; - if let Some(vec_args) = higher::vec_macro(cx, addressee); + if let ExprKind::AddrOf(BorrowKind::Ref, mutability, ref addressee) = expr.kind; + if let Some(vec_args) = higher::VecArgs::hir(cx, addressee); then { self.check_vec_macro(cx, &vec_args, mutability, expr.span); } @@ -58,8 +58,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec { // search for `for _ in vec![…]` if_chain! { - if let Some((_, arg, _, _)) = higher::for_loop(expr); - if let Some(vec_args) = higher::vec_macro(cx, arg); + if let Some(higher::ForLoop { arg, .. }) = higher::ForLoop::hir(expr); + if let Some(vec_args) = higher::VecArgs::hir(cx, arg); if is_copy(cx, vec_type(cx.typeck_results().expr_ty_adjusted(arg))); then { // report the error around the `vec!` not inside `:` diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 30c2260d15ca..7ea07a15aea5 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -158,7 +158,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (Unary(lo, l), Unary(ro, r)) => mem::discriminant(lo) == mem::discriminant(ro) && eq_expr(l, r), (Lit(l), Lit(r)) => l.kind == r.kind, (Cast(l, lt), Cast(r, rt)) | (Type(l, lt), Type(r, rt)) => eq_expr(l, r) && eq_ty(lt, rt), - (Let(lp, le), Let(rp, re)) => eq_pat(lp, rp) && eq_expr(le, re), + (Let(lp, le, _), Let(rp, re, _)) => eq_pat(lp, rp) && eq_expr(le, re), (If(lc, lt, le), If(rc, rt, re)) => eq_expr(lc, rc) && eq_block(lt, rt) && eq_expr_opt(le, re), (While(lc, lt, ll), While(rc, rt, rl)) => eq_label(ll, rl) && eq_expr(lc, rc) && eq_block(lt, rt), (ForLoop(lp, li, lt, ll), ForLoop(rp, ri, rt, rl)) => { diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 88b115a63d78..29e2559fc6d6 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -60,6 +60,7 @@ fn identify_some_pure_patterns(expr: &Expr<'_>) -> bool { | ExprKind::MethodCall(..) | ExprKind::Binary(..) | ExprKind::Unary(..) + | ExprKind::Let(..) | ExprKind::Cast(..) | ExprKind::Type(..) | ExprKind::DropTemps(..) diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index 884180f0586e..29b698e56e3c 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -1,5 +1,4 @@ -//! This module contains functions for retrieve the original AST from lowered -//! `hir`. +//! This module contains functions that retrieves specifiec elements. #![deny(clippy::missing_docs_in_private_items)] @@ -7,142 +6,214 @@ use crate::{is_expn_of, match_def_path, paths}; use if_chain::if_chain; use rustc_ast::ast::{self, LitKind}; use rustc_hir as hir; -use rustc_hir::{BorrowKind, Expr, ExprKind, StmtKind, UnOp}; +use rustc_hir::{Block, BorrowKind, Expr, ExprKind, LoopSource, Node, Pat, StmtKind, UnOp}; use rustc_lint::LateContext; use rustc_span::{sym, ExpnKind, Span, Symbol}; -/// Represent a range akin to `ast::ExprKind::Range`. -#[derive(Debug, Copy, Clone)] -pub struct Range<'a> { - /// The lower bound of the range, or `None` for ranges such as `..X`. - pub start: Option<&'a hir::Expr<'a>>, - /// The upper bound of the range, or `None` for ranges such as `X..`. - pub end: Option<&'a hir::Expr<'a>>, - /// Whether the interval is open or closed. - pub limits: ast::RangeLimits, +/// The essential nodes of a desugared for loop as well as the entire span: +/// `for pat in arg { body }` becomes `(pat, arg, body)`. Return `(pat, arg, body, span)`. +pub struct ForLoop<'tcx> { + pub pat: &'tcx hir::Pat<'tcx>, + pub arg: &'tcx hir::Expr<'tcx>, + pub body: &'tcx hir::Expr<'tcx>, + pub span: Span, } -/// Higher a `hir` range to something similar to `ast::ExprKind::Range`. -pub fn range<'a>(expr: &'a hir::Expr<'_>) -> Option> { - /// Finds the field named `name` in the field. Always return `Some` for - /// convenience. - fn get_field<'c>(name: &str, fields: &'c [hir::ExprField<'_>]) -> Option<&'c hir::Expr<'c>> { - let expr = &fields.iter().find(|field| field.ident.name.as_str() == name)?.expr; - - Some(expr) +impl<'tcx> ForLoop<'tcx> { + #[inline] + pub fn hir(expr: &Expr<'tcx>) -> Option { + if_chain! { + if let hir::ExprKind::Match(ref iterexpr, ref arms, hir::MatchSource::ForLoopDesugar) = expr.kind; + if let Some(first_arm) = arms.get(0); + if let hir::ExprKind::Call(_, ref iterargs) = iterexpr.kind; + if let Some(first_arg) = iterargs.get(0); + if iterargs.len() == 1 && arms.len() == 1 && first_arm.guard.is_none(); + if let hir::ExprKind::Loop(ref block, ..) = first_arm.body.kind; + if block.expr.is_none(); + if let [ _, _, ref let_stmt, ref body ] = *block.stmts; + if let hir::StmtKind::Local(ref local) = let_stmt.kind; + if let hir::StmtKind::Expr(ref body_expr) = body.kind; + then { + return Some(Self { + pat: &*local.pat, + arg: first_arg, + body: body_expr, + span: first_arm.span + }); + } + } + None } +} + +pub struct If<'hir> { + pub cond: &'hir Expr<'hir>, + pub r#else: Option<&'hir Expr<'hir>>, + pub then: &'hir Expr<'hir>, +} - match expr.kind { - hir::ExprKind::Call(path, args) - if matches!( - path.kind, - hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::RangeInclusiveNew, _)) - ) => +impl<'hir> If<'hir> { + #[inline] + pub const fn hir(expr: &Expr<'hir>) -> Option { + if let ExprKind::If( + Expr { + kind: ExprKind::DropTemps(cond), + .. + }, + then, + r#else, + ) = expr.kind { - Some(Range { - start: Some(&args[0]), - end: Some(&args[1]), - limits: ast::RangeLimits::Closed, - }) - }, - hir::ExprKind::Struct(path, fields, None) => match path { - hir::QPath::LangItem(hir::LangItem::RangeFull, _) => Some(Range { - start: None, - end: None, - limits: ast::RangeLimits::HalfOpen, - }), - hir::QPath::LangItem(hir::LangItem::RangeFrom, _) => Some(Range { - start: Some(get_field("start", fields)?), - end: None, - limits: ast::RangeLimits::HalfOpen, - }), - hir::QPath::LangItem(hir::LangItem::Range, _) => Some(Range { - start: Some(get_field("start", fields)?), - end: Some(get_field("end", fields)?), - limits: ast::RangeLimits::HalfOpen, - }), - hir::QPath::LangItem(hir::LangItem::RangeToInclusive, _) => Some(Range { - start: None, - end: Some(get_field("end", fields)?), - limits: ast::RangeLimits::Closed, - }), - hir::QPath::LangItem(hir::LangItem::RangeTo, _) => Some(Range { - start: None, - end: Some(get_field("end", fields)?), - limits: ast::RangeLimits::HalfOpen, - }), - _ => None, - }, - _ => None, + Some(Self { cond, r#else, then }) + } else { + None + } } } -/// Checks if a `let` statement is from a `for` loop desugaring. -pub fn is_from_for_desugar(local: &hir::Local<'_>) -> bool { - // This will detect plain for-loops without an actual variable binding: - // - // ``` - // for x in some_vec { - // // do stuff - // } - // ``` - if_chain! { - if let Some(expr) = local.init; - if let hir::ExprKind::Match(_, _, hir::MatchSource::ForLoopDesugar) = expr.kind; - then { - return true; +pub struct IfLet<'hir> { + pub let_pat: &'hir Pat<'hir>, + pub let_expr: &'hir Expr<'hir>, + pub if_then: &'hir Expr<'hir>, + pub if_else: Option<&'hir Expr<'hir>>, +} + +impl<'hir> IfLet<'hir> { + #[inline] + pub fn ast(cx: &LateContext<'tcx>, expr: &Expr<'hir>) -> Option { + let rslt = Self::hir(expr)?; + Self::is_not_within_while_context(cx, expr)?; + Some(rslt) + } + + #[inline] + pub const fn hir(expr: &Expr<'hir>) -> Option { + if let ExprKind::If( + Expr { + kind: ExprKind::Let(let_pat, let_expr, _), + .. + }, + if_then, + if_else, + ) = expr.kind + { + return Some(Self { + let_pat, + let_expr, + if_then, + if_else, + }); } + None } - // This detects a variable binding in for loop to avoid `let_unit_value` - // lint (see issue #1964). - // - // ``` - // for _ in vec![()] { - // // anything - // } - // ``` - if let hir::LocalSource::ForLoopDesugar = local.source { - return true; + #[inline] + fn is_not_within_while_context(cx: &LateContext<'tcx>, expr: &Expr<'hir>) -> Option<()> { + let hir = cx.tcx.hir(); + let parent = hir.get_parent_node(expr.hir_id); + let parent_parent = hir.get_parent_node(parent); + let parent_parent_node = hir.get(parent_parent); + if let Node::Expr(Expr { + kind: ExprKind::Loop(_, _, LoopSource::While, _), + .. + }) = parent_parent_node + { + return None; + } + Some(()) } +} - false +pub struct IfOrIfLet<'hir> { + pub cond: &'hir Expr<'hir>, + pub r#else: Option<&'hir Expr<'hir>>, + pub then: &'hir Expr<'hir>, } -/// Recover the essential nodes of a desugared for loop as well as the entire span: -/// `for pat in arg { body }` becomes `(pat, arg, body)`. Return `(pat, arg, body, span)`. -pub fn for_loop<'tcx>( - expr: &'tcx hir::Expr<'tcx>, -) -> Option<(&hir::Pat<'_>, &'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>, Span)> { - if_chain! { - if let hir::ExprKind::Match(iterexpr, arms, hir::MatchSource::ForLoopDesugar) = expr.kind; - if let hir::ExprKind::Call(_, iterargs) = iterexpr.kind; - if iterargs.len() == 1 && arms.len() == 1 && arms[0].guard.is_none(); - if let hir::ExprKind::Loop(block, ..) = arms[0].body.kind; - if block.expr.is_none(); - if let [ _, _, ref let_stmt, ref body ] = *block.stmts; - if let hir::StmtKind::Local(local) = let_stmt.kind; - if let hir::StmtKind::Expr(expr) = body.kind; - then { - return Some((&*local.pat, &iterargs[0], expr, arms[0].span)); +impl<'hir> IfOrIfLet<'hir> { + #[inline] + pub const fn hir(expr: &Expr<'hir>) -> Option { + if let ExprKind::If(cond, then, r#else) = expr.kind { + if let ExprKind::DropTemps(new_cond) = cond.kind { + return Some(Self { + cond: new_cond, + r#else, + then, + }); + } + if let ExprKind::Let(..) = cond.kind { + return Some(Self { cond, r#else, then }); + } } + None } - None } -/// Recover the essential nodes of a desugared while loop: -/// `while cond { body }` becomes `(cond, body)`. -pub fn while_loop<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> Option<(&'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>)> { - if_chain! { - if let hir::ExprKind::Loop(hir::Block { expr: Some(expr), .. }, _, hir::LoopSource::While, _) = &expr.kind; - if let hir::ExprKind::Match(cond, arms, hir::MatchSource::WhileDesugar) = &expr.kind; - if let hir::ExprKind::DropTemps(cond) = &cond.kind; - if let [hir::Arm { body, .. }, ..] = &arms[..]; - then { - return Some((cond, body)); +/// Represent a range akin to `ast::ExprKind::Range`. +#[derive(Debug, Copy, Clone)] +pub struct Range<'a> { + /// The lower bound of the range, or `None` for ranges such as `..X`. + pub start: Option<&'a hir::Expr<'a>>, + /// The upper bound of the range, or `None` for ranges such as `X..`. + pub end: Option<&'a hir::Expr<'a>>, + /// Whether the interval is open or closed. + pub limits: ast::RangeLimits, +} + +impl<'a> Range<'a> { + /// Higher a `hir` range to something similar to `ast::ExprKind::Range`. + pub fn hir(expr: &'a hir::Expr<'_>) -> Option> { + /// Finds the field named `name` in the field. Always return `Some` for + /// convenience. + fn get_field<'c>(name: &str, fields: &'c [hir::ExprField<'_>]) -> Option<&'c hir::Expr<'c>> { + let expr = &fields.iter().find(|field| field.ident.name.as_str() == name)?.expr; + Some(expr) + } + + match expr.kind { + hir::ExprKind::Call(ref path, ref args) + if matches!( + path.kind, + hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::RangeInclusiveNew, _)) + ) => + { + Some(Range { + start: Some(&args[0]), + end: Some(&args[1]), + limits: ast::RangeLimits::Closed, + }) + }, + hir::ExprKind::Struct(ref path, ref fields, None) => match path { + hir::QPath::LangItem(hir::LangItem::RangeFull, _) => Some(Range { + start: None, + end: None, + limits: ast::RangeLimits::HalfOpen, + }), + hir::QPath::LangItem(hir::LangItem::RangeFrom, _) => Some(Range { + start: Some(get_field("start", fields)?), + end: None, + limits: ast::RangeLimits::HalfOpen, + }), + hir::QPath::LangItem(hir::LangItem::Range, _) => Some(Range { + start: Some(get_field("start", fields)?), + end: Some(get_field("end", fields)?), + limits: ast::RangeLimits::HalfOpen, + }), + hir::QPath::LangItem(hir::LangItem::RangeToInclusive, _) => Some(Range { + start: None, + end: Some(get_field("end", fields)?), + limits: ast::RangeLimits::Closed, + }), + hir::QPath::LangItem(hir::LangItem::RangeTo, _) => Some(Range { + start: None, + end: Some(get_field("end", fields)?), + limits: ast::RangeLimits::HalfOpen, + }), + _ => None, + }, + _ => None, } } - None } /// Represent the pre-expansion arguments of a `vec!` invocation. @@ -153,41 +224,157 @@ pub enum VecArgs<'a> { Vec(&'a [hir::Expr<'a>]), } -/// Returns the arguments of the `vec!` macro if this expression was expanded -/// from `vec!`. -pub fn vec_macro<'e>(cx: &LateContext<'_>, expr: &'e hir::Expr<'_>) -> Option> { - if_chain! { - if let hir::ExprKind::Call(fun, args) = expr.kind; - if let hir::ExprKind::Path(ref qpath) = fun.kind; - if is_expn_of(fun.span, "vec").is_some(); - if let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id(); - then { - return if match_def_path(cx, fun_def_id, &paths::VEC_FROM_ELEM) && args.len() == 2 { - // `vec![elem; size]` case - Some(VecArgs::Repeat(&args[0], &args[1])) - } - else if match_def_path(cx, fun_def_id, &paths::SLICE_INTO_VEC) && args.len() == 1 { - // `vec![a, b, c]` case - if_chain! { - if let hir::ExprKind::Box(boxed) = args[0].kind; - if let hir::ExprKind::Array(args) = boxed.kind; - then { - return Some(VecArgs::Vec(&*args)); - } +impl<'a> VecArgs<'a> { + /// Returns the arguments of the `vec!` macro if this expression was expanded + /// from `vec!`. + pub fn hir(cx: &LateContext<'_>, expr: &'a hir::Expr<'_>) -> Option> { + if_chain! { + if let hir::ExprKind::Call(ref fun, ref args) = expr.kind; + if let hir::ExprKind::Path(ref qpath) = fun.kind; + if is_expn_of(fun.span, "vec").is_some(); + if let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id(); + then { + return if match_def_path(cx, fun_def_id, &paths::VEC_FROM_ELEM) && args.len() == 2 { + // `vec![elem; size]` case + Some(VecArgs::Repeat(&args[0], &args[1])) } + else if match_def_path(cx, fun_def_id, &paths::SLICE_INTO_VEC) && args.len() == 1 { + // `vec![a, b, c]` case + if_chain! { + if let hir::ExprKind::Box(ref boxed) = args[0].kind; + if let hir::ExprKind::Array(ref args) = boxed.kind; + then { + return Some(VecArgs::Vec(&*args)); + } + } - None + None + } + else if match_def_path(cx, fun_def_id, &paths::VEC_NEW) && args.is_empty() { + Some(VecArgs::Vec(&[])) + } + else { + None + }; } - else if match_def_path(cx, fun_def_id, &paths::VEC_NEW) && args.is_empty() { - Some(VecArgs::Vec(&[])) + } + + None + } +} + +pub struct While<'hir> { + pub if_cond: &'hir Expr<'hir>, + pub if_then: &'hir Expr<'hir>, + pub if_else: Option<&'hir Expr<'hir>>, +} + +impl<'hir> While<'hir> { + #[inline] + pub const fn hir(expr: &Expr<'hir>) -> Option { + if let ExprKind::Loop( + Block { + expr: + Some(Expr { + kind: + ExprKind::If( + Expr { + kind: ExprKind::DropTemps(if_cond), + .. + }, + if_then, + if_else_ref, + ), + .. + }), + .. + }, + _, + LoopSource::While, + _, + ) = expr.kind + { + let if_else = *if_else_ref; + return Some(Self { + if_cond, + if_then, + if_else, + }); + } + None + } +} + +pub struct WhileLet<'hir> { + pub if_expr: &'hir Expr<'hir>, + pub let_pat: &'hir Pat<'hir>, + pub let_expr: &'hir Expr<'hir>, + pub if_then: &'hir Expr<'hir>, + pub if_else: Option<&'hir Expr<'hir>>, +} + +impl<'hir> WhileLet<'hir> { + #[inline] + pub const fn hir(expr: &Expr<'hir>) -> Option { + if let ExprKind::Loop( + Block { + expr: Some(if_expr), .. + }, + _, + LoopSource::While, + _, + ) = expr.kind + { + if let Expr { + kind: + ExprKind::If( + Expr { + kind: ExprKind::Let(let_pat, let_expr, _), + .. + }, + if_then, + if_else_ref, + ), + .. + } = if_expr + { + let if_else = *if_else_ref; + return Some(Self { + if_expr, + let_pat, + let_expr, + if_then, + if_else, + }); } - else { - None - }; } + None } +} - None +/// Converts a hir binary operator to the corresponding `ast` type. +#[must_use] +pub fn binop(op: hir::BinOpKind) -> ast::BinOpKind { + match op { + hir::BinOpKind::Eq => ast::BinOpKind::Eq, + hir::BinOpKind::Ge => ast::BinOpKind::Ge, + hir::BinOpKind::Gt => ast::BinOpKind::Gt, + hir::BinOpKind::Le => ast::BinOpKind::Le, + hir::BinOpKind::Lt => ast::BinOpKind::Lt, + hir::BinOpKind::Ne => ast::BinOpKind::Ne, + hir::BinOpKind::Or => ast::BinOpKind::Or, + hir::BinOpKind::Add => ast::BinOpKind::Add, + hir::BinOpKind::And => ast::BinOpKind::And, + hir::BinOpKind::BitAnd => ast::BinOpKind::BitAnd, + hir::BinOpKind::BitOr => ast::BinOpKind::BitOr, + hir::BinOpKind::BitXor => ast::BinOpKind::BitXor, + hir::BinOpKind::Div => ast::BinOpKind::Div, + hir::BinOpKind::Mul => ast::BinOpKind::Mul, + hir::BinOpKind::Rem => ast::BinOpKind::Rem, + hir::BinOpKind::Shl => ast::BinOpKind::Shl, + hir::BinOpKind::Shr => ast::BinOpKind::Shr, + hir::BinOpKind::Sub => ast::BinOpKind::Sub, + } } /// Extract args from an assert-like macro. @@ -218,8 +405,8 @@ pub fn extract_assert_macro_args<'tcx>(e: &'tcx Expr<'tcx>) -> Option { } } } + +/// Checks if a `let` statement is from a `for` loop desugaring. +pub fn is_from_for_desugar(local: &hir::Local<'_>) -> bool { + // This will detect plain for-loops without an actual variable binding: + // + // ``` + // for x in some_vec { + // // do stuff + // } + // ``` + if_chain! { + if let Some(ref expr) = local.init; + if let hir::ExprKind::Match(_, _, hir::MatchSource::ForLoopDesugar) = expr.kind; + then { + return true; + } + } + + // This detects a variable binding in for loop to avoid `let_unit_value` + // lint (see issue #1964). + // + // ``` + // for _ in vec![()] { + // // anything + // } + // ``` + if let hir::LocalSource::ForLoopDesugar = local.source { + return true; + } + + false +} diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index fd70553e064b..a44f2df2fd63 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -232,6 +232,9 @@ impl HirEqInterExpr<'_, '_, '_> { (&ExprKind::If(lc, lt, ref le), &ExprKind::If(rc, rt, ref re)) => { self.eq_expr(lc, rc) && self.eq_expr(&**lt, &**rt) && both(le, re, |l, r| self.eq_expr(l, r)) }, + (&ExprKind::Let(ref lp, ref le, _), &ExprKind::Let(ref rp, ref re, _)) => { + self.eq_pat(lp, rp) && self.eq_expr(le, re) + }, (&ExprKind::Lit(ref l), &ExprKind::Lit(ref r)) => l.node == r.node, (&ExprKind::Loop(lb, ref ll, ref lls, _), &ExprKind::Loop(rb, ref rl, ref rls, _)) => { lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.name == r.ident.name) @@ -665,6 +668,10 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } }, + ExprKind::Let(ref pat, ref expr, _) => { + self.hash_expr(expr); + self.hash_pat(pat); + }, ExprKind::LlvmInlineAsm(..) | ExprKind::Err => {}, ExprKind::Lit(ref l) => { l.node.hash(&mut self.s); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 1d59d6bfea1b..82bfce8fe789 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -961,17 +961,6 @@ pub fn is_else_clause(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { let map = tcx.hir(); let mut iter = map.parent_iter(expr.hir_id); match iter.next() { - Some((arm_id, Node::Arm(..))) => matches!( - iter.next(), - Some(( - _, - Node::Expr(Expr { - kind: ExprKind::Match(_, [_, else_arm], MatchSource::IfLetDesugar { .. }), - .. - }) - )) - if else_arm.hir_id == arm_id - ), Some(( _, Node::Expr(Expr { @@ -1370,15 +1359,15 @@ pub fn if_sequence<'tcx>(mut expr: &'tcx Expr<'tcx>) -> (Vec<&'tcx Expr<'tcx>>, let mut conds = Vec::new(); let mut blocks: Vec<&Block<'_>> = Vec::new(); - while let ExprKind::If(cond, then_expr, ref else_expr) = expr.kind { - conds.push(cond); - if let ExprKind::Block(block, _) = then_expr.kind { + while let Some(higher::IfOrIfLet { cond, then, r#else }) = higher::IfOrIfLet::hir(expr) { + conds.push(&*cond); + if let ExprKind::Block(ref block, _) = then.kind { blocks.push(block); } else { panic!("ExprKind::If node is not an ExprKind::Block"); } - if let Some(else_expr) = *else_expr { + if let Some(ref else_expr) = r#else { expr = else_expr; } else { break; diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 3bd75b10e905..3b494e1fc853 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -116,7 +116,7 @@ impl<'a> Sugg<'a> { /// Generate a suggestion for an expression with the given snippet. This is used by the `hir_*` /// function variants of `Sugg`, since these use different snippet functions. fn hir_from_snippet(expr: &hir::Expr<'_>, snippet: Cow<'a, str>) -> Self { - if let Some(range) = higher::range(expr) { + if let Some(range) = higher::Range::hir(expr) { let op = match range.limits { ast::RangeLimits::HalfOpen => AssocOp::DotDot, ast::RangeLimits::Closed => AssocOp::DotDotEq, @@ -128,6 +128,7 @@ impl<'a> Sugg<'a> { hir::ExprKind::AddrOf(..) | hir::ExprKind::Box(..) | hir::ExprKind::If(..) + | hir::ExprKind::Let(..) | hir::ExprKind::Closure(..) | hir::ExprKind::Unary(..) | hir::ExprKind::Match(..) => Sugg::MaybeParen(snippet), diff --git a/tests/ui/author/if.stdout b/tests/ui/author/if.stdout index 502b38545b8e..1653de9a6f26 100644 --- a/tests/ui/author/if.stdout +++ b/tests/ui/author/if.stdout @@ -12,7 +12,8 @@ if_chain! { if let ExprKind::Lit(ref lit1) = right.kind; if let LitKind::Int(2, _) = lit1.node; if block.expr.is_none(); - if let ExprKind::Lit(ref lit2) = cond.kind; + if let ExprKind::DropTemps(ref expr) = cond.kind; + if let ExprKind::Lit(ref lit2) = expr.kind; if let LitKind::Bool(true) = lit2.node; if let ExprKind::Block(ref block1) = then.kind; if block1.stmts.len() == 1; diff --git a/tests/ui/collapsible_match.stderr b/tests/ui/collapsible_match.stderr index 779788849008..f96917f58334 100644 --- a/tests/ui/collapsible_match.stderr +++ b/tests/ui/collapsible_match.stderr @@ -35,7 +35,7 @@ LL | Ok(val) => match val { LL | Some(n) => foo(n), | ^^^^^^^ with this pattern -error: unnecessary nested match +error: unnecessary nested `if let` or `match` --> $DIR/collapsible_match.rs:25:9 | LL | / if let Some(n) = val { @@ -51,7 +51,7 @@ LL | if let Ok(val) = res_opt { LL | if let Some(n) = val { | ^^^^^^^ with this pattern -error: unnecessary nested match +error: unnecessary nested `if let` or `match` --> $DIR/collapsible_match.rs:32:9 | LL | / if let Some(n) = val { @@ -87,7 +87,7 @@ LL | match val { LL | Some(n) => foo(n), | ^^^^^^^ with this pattern -error: unnecessary nested match +error: unnecessary nested `if let` or `match` --> $DIR/collapsible_match.rs:52:13 | LL | / if let Some(n) = val { @@ -121,7 +121,7 @@ LL | match val { LL | Some(n) => foo(n), | ^^^^^^^ with this pattern -error: unnecessary nested match +error: unnecessary nested `if let` or `match` --> $DIR/collapsible_match.rs:72:13 | LL | / if let Some(n) = val { diff --git a/tests/ui/crashes/ice-7410.rs b/tests/ui/crashes/ice-7410.rs index aaa422d88c3e..85fa42103219 100644 --- a/tests/ui/crashes/ice-7410.rs +++ b/tests/ui/crashes/ice-7410.rs @@ -4,6 +4,7 @@ #![feature(lang_items, start, libc)] #![no_std] +#![allow(clippy::if_same_then_else)] #![allow(clippy::redundant_pattern_matching)] use core::panic::PanicInfo; diff --git a/tests/ui/crashes/issues_loop_mut_cond.rs b/tests/ui/crashes/issues_loop_mut_cond.rs index bb238c81ebc0..553c840f9b08 100644 --- a/tests/ui/crashes/issues_loop_mut_cond.rs +++ b/tests/ui/crashes/issues_loop_mut_cond.rs @@ -1,3 +1,4 @@ +#![allow(clippy::blocks_in_if_conditions)] #![allow(dead_code)] /// Issue: https://github.com/rust-lang/rust-clippy/issues/2596 diff --git a/tests/ui/infinite_loop.rs b/tests/ui/infinite_loop.rs index 3d8fb8507e51..e518b2677b7b 100644 --- a/tests/ui/infinite_loop.rs +++ b/tests/ui/infinite_loop.rs @@ -1,3 +1,5 @@ +#![allow(clippy::blocks_in_if_conditions)] + fn fn_val(i: i32) -> i32 { unimplemented!() } diff --git a/tests/ui/infinite_loop.stderr b/tests/ui/infinite_loop.stderr index 1fcb29eff18e..2736753c14b6 100644 --- a/tests/ui/infinite_loop.stderr +++ b/tests/ui/infinite_loop.stderr @@ -1,5 +1,5 @@ error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:21:11 + --> $DIR/infinite_loop.rs:23:11 | LL | while y < 10 { | ^^^^^^ @@ -8,7 +8,7 @@ LL | while y < 10 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:26:11 + --> $DIR/infinite_loop.rs:28:11 | LL | while y < 10 && x < 3 { | ^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | while y < 10 && x < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:33:11 + --> $DIR/infinite_loop.rs:35:11 | LL | while !cond { | ^^^^^ @@ -24,7 +24,7 @@ LL | while !cond { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:77:11 + --> $DIR/infinite_loop.rs:79:11 | LL | while i < 3 { | ^^^^^ @@ -32,7 +32,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:82:11 + --> $DIR/infinite_loop.rs:84:11 | LL | while i < 3 && j > 0 { | ^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | while i < 3 && j > 0 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:86:11 + --> $DIR/infinite_loop.rs:88:11 | LL | while i < 3 { | ^^^^^ @@ -48,7 +48,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:101:11 + --> $DIR/infinite_loop.rs:103:11 | LL | while i < 3 { | ^^^^^ @@ -56,7 +56,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:106:11 + --> $DIR/infinite_loop.rs:108:11 | LL | while i < 3 { | ^^^^^ @@ -64,7 +64,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:172:15 + --> $DIR/infinite_loop.rs:174:15 | LL | while self.count < n { | ^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | while self.count < n { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:180:11 + --> $DIR/infinite_loop.rs:182:11 | LL | while y < 10 { | ^^^^^^ @@ -82,7 +82,7 @@ LL | while y < 10 { = help: rewrite it as `if cond { loop { } }` error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:187:11 + --> $DIR/infinite_loop.rs:189:11 | LL | while y < 10 { | ^^^^^^ diff --git a/tests/ui/match_overlapping_arm.rs b/tests/ui/match_overlapping_arm.rs index 44c51e8112a7..c84e31ea482a 100644 --- a/tests/ui/match_overlapping_arm.rs +++ b/tests/ui/match_overlapping_arm.rs @@ -2,6 +2,7 @@ #![feature(half_open_range_patterns)] #![warn(clippy::match_overlapping_arm)] #![allow(clippy::redundant_pattern_matching)] +#![allow(clippy::if_same_then_else)] /// Tests for match_overlapping_arm diff --git a/tests/ui/match_overlapping_arm.stderr b/tests/ui/match_overlapping_arm.stderr index f25a66d634e8..359fa49f51be 100644 --- a/tests/ui/match_overlapping_arm.stderr +++ b/tests/ui/match_overlapping_arm.stderr @@ -1,60 +1,60 @@ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:12:9 + --> $DIR/match_overlapping_arm.rs:13:9 | LL | 0..=10 => println!("0 ... 10"), | ^^^^^^ | = note: `-D clippy::match-overlapping-arm` implied by `-D warnings` note: overlaps with this - --> $DIR/match_overlapping_arm.rs:13:9 + --> $DIR/match_overlapping_arm.rs:14:9 | LL | 0..=11 => println!("0 ... 11"), | ^^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:18:9 + --> $DIR/match_overlapping_arm.rs:19:9 | LL | 0..=5 => println!("0 ... 5"), | ^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:20:9 + --> $DIR/match_overlapping_arm.rs:21:9 | LL | FOO..=11 => println!("0 ... 11"), | ^^^^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:55:9 + --> $DIR/match_overlapping_arm.rs:56:9 | LL | 0..11 => println!("0 .. 11"), | ^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:56:9 + --> $DIR/match_overlapping_arm.rs:57:9 | LL | 0..=11 => println!("0 ... 11"), | ^^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:80:9 + --> $DIR/match_overlapping_arm.rs:81:9 | LL | 0..=10 => println!("0 ... 10"), | ^^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:79:9 + --> $DIR/match_overlapping_arm.rs:80:9 | LL | 5..14 => println!("5 .. 14"), | ^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:85:9 + --> $DIR/match_overlapping_arm.rs:86:9 | LL | 0..7 => println!("0 .. 7"), | ^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:86:9 + --> $DIR/match_overlapping_arm.rs:87:9 | LL | 0..=10 => println!("0 ... 10"), | ^^^^^^ From 7feb7769d4c98add615213e81ed982076c319fc3 Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Wed, 2 Dec 2020 15:16:12 -0800 Subject: [PATCH 0292/1222] Uplift the `invalid_atomic_ordering` lint from clippy to rustc - Deprecate clippy::invalid_atomic_ordering - Use rustc_diagnostic_item for the orderings in the invalid_atomic_ordering lint - Reduce code duplication - Give up on making enum variants diagnostic items and just look for `Ordering` instead I ran into tons of trouble with this because apparently the change to store HIR attrs in a side table also gave the DefIds of the constructor instead of the variant itself. So I had to change `matches_ordering` to also check the grandparent of the defid as well. - Rename `atomic_ordering_x` symbols to just the name of the variant - Fix typos in checks - there were a few places that said "may not be Release" in the diagnostic but actually checked for SeqCst in the lint. - Make constant items const - Use fewer diagnostic items - Only look at arguments after making sure the method matches This prevents an ICE when there aren't enough arguments. - Ignore trait methods - Only check Ctors instead of going through `qpath_res` The functions take values, so this couldn't ever be anything else. - Add if_chain to allowed dependencies - Fix grammar - Remove unnecessary allow --- clippy_lints/src/atomic_ordering.rs | 230 ------------------ clippy_lints/src/lib.rs | 6 +- tests/ui/atomic_ordering_bool.rs | 25 -- tests/ui/atomic_ordering_bool.stderr | 35 --- tests/ui/atomic_ordering_exchange.rs | 45 ---- tests/ui/atomic_ordering_exchange.stderr | 131 ---------- tests/ui/atomic_ordering_exchange_weak.rs | 47 ---- tests/ui/atomic_ordering_exchange_weak.stderr | 131 ---------- tests/ui/atomic_ordering_fence.rs | 20 -- tests/ui/atomic_ordering_fence.stderr | 19 -- tests/ui/atomic_ordering_fetch_update.rs | 45 ---- tests/ui/atomic_ordering_fetch_update.stderr | 131 ---------- tests/ui/atomic_ordering_int.rs | 86 ------- tests/ui/atomic_ordering_int.stderr | 163 ------------- tests/ui/atomic_ordering_ptr.rs | 27 -- tests/ui/atomic_ordering_ptr.stderr | 35 --- tests/ui/atomic_ordering_uint.rs | 86 ------- tests/ui/atomic_ordering_uint.stderr | 163 ------------- tests/ui/deprecated.rs | 1 + tests/ui/deprecated.stderr | 8 +- 20 files changed, 9 insertions(+), 1425 deletions(-) delete mode 100644 clippy_lints/src/atomic_ordering.rs delete mode 100644 tests/ui/atomic_ordering_bool.rs delete mode 100644 tests/ui/atomic_ordering_bool.stderr delete mode 100644 tests/ui/atomic_ordering_exchange.rs delete mode 100644 tests/ui/atomic_ordering_exchange.stderr delete mode 100644 tests/ui/atomic_ordering_exchange_weak.rs delete mode 100644 tests/ui/atomic_ordering_exchange_weak.stderr delete mode 100644 tests/ui/atomic_ordering_fence.rs delete mode 100644 tests/ui/atomic_ordering_fence.stderr delete mode 100644 tests/ui/atomic_ordering_fetch_update.rs delete mode 100644 tests/ui/atomic_ordering_fetch_update.stderr delete mode 100644 tests/ui/atomic_ordering_int.rs delete mode 100644 tests/ui/atomic_ordering_int.stderr delete mode 100644 tests/ui/atomic_ordering_ptr.rs delete mode 100644 tests/ui/atomic_ordering_ptr.stderr delete mode 100644 tests/ui/atomic_ordering_uint.rs delete mode 100644 tests/ui/atomic_ordering_uint.stderr diff --git a/clippy_lints/src/atomic_ordering.rs b/clippy_lints/src/atomic_ordering.rs deleted file mode 100644 index cece28e8b3c3..000000000000 --- a/clippy_lints/src/atomic_ordering.rs +++ /dev/null @@ -1,230 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::match_def_path; -use if_chain::if_chain; -use rustc_hir::def_id::DefId; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of invalid atomic - /// ordering in atomic loads/stores/exchanges/updates and - /// memory fences. - /// - /// ### Why is this bad? - /// Using an invalid atomic ordering - /// will cause a panic at run-time. - /// - /// ### Example - /// ```rust,no_run - /// # use std::sync::atomic::{self, AtomicU8, Ordering}; - /// - /// let x = AtomicU8::new(0); - /// - /// // Bad: `Release` and `AcqRel` cannot be used for `load`. - /// let _ = x.load(Ordering::Release); - /// let _ = x.load(Ordering::AcqRel); - /// - /// // Bad: `Acquire` and `AcqRel` cannot be used for `store`. - /// x.store(1, Ordering::Acquire); - /// x.store(2, Ordering::AcqRel); - /// - /// // Bad: `Relaxed` cannot be used as a fence's ordering. - /// atomic::fence(Ordering::Relaxed); - /// atomic::compiler_fence(Ordering::Relaxed); - /// - /// // Bad: `Release` and `AcqRel` are both always invalid - /// // for the failure ordering (the last arg). - /// let _ = x.compare_exchange(1, 2, Ordering::SeqCst, Ordering::Release); - /// let _ = x.compare_exchange_weak(2, 3, Ordering::AcqRel, Ordering::AcqRel); - /// - /// // Bad: The failure ordering is not allowed to be - /// // stronger than the success order, and `SeqCst` is - /// // stronger than `Relaxed`. - /// let _ = x.fetch_update(Ordering::Relaxed, Ordering::SeqCst, |val| Some(val + val)); - /// ``` - pub INVALID_ATOMIC_ORDERING, - correctness, - "usage of invalid atomic ordering in atomic operations and memory fences" -} - -declare_lint_pass!(AtomicOrdering => [INVALID_ATOMIC_ORDERING]); - -const ATOMIC_TYPES: [&str; 12] = [ - "AtomicBool", - "AtomicI8", - "AtomicI16", - "AtomicI32", - "AtomicI64", - "AtomicIsize", - "AtomicPtr", - "AtomicU8", - "AtomicU16", - "AtomicU32", - "AtomicU64", - "AtomicUsize", -]; - -fn type_is_atomic(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.typeck_results().expr_ty(expr).kind() { - ATOMIC_TYPES - .iter() - .any(|ty| match_def_path(cx, did, &["core", "sync", "atomic", ty])) - } else { - false - } -} - -fn match_ordering_def_path(cx: &LateContext<'_>, did: DefId, orderings: &[&str]) -> bool { - orderings - .iter() - .any(|ordering| match_def_path(cx, did, &["core", "sync", "atomic", "Ordering", ordering])) -} - -fn check_atomic_load_store(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::MethodCall(method_path, _, args, _) = &expr.kind; - let method = method_path.ident.name.as_str(); - if type_is_atomic(cx, &args[0]); - if method == "load" || method == "store"; - let ordering_arg = if method == "load" { &args[1] } else { &args[2] }; - if let ExprKind::Path(ref ordering_qpath) = ordering_arg.kind; - if let Some(ordering_def_id) = cx.qpath_res(ordering_qpath, ordering_arg.hir_id).opt_def_id(); - then { - if method == "load" && - match_ordering_def_path(cx, ordering_def_id, &["Release", "AcqRel"]) { - span_lint_and_help( - cx, - INVALID_ATOMIC_ORDERING, - ordering_arg.span, - "atomic loads cannot have `Release` and `AcqRel` ordering", - None, - "consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`" - ); - } else if method == "store" && - match_ordering_def_path(cx, ordering_def_id, &["Acquire", "AcqRel"]) { - span_lint_and_help( - cx, - INVALID_ATOMIC_ORDERING, - ordering_arg.span, - "atomic stores cannot have `Acquire` and `AcqRel` ordering", - None, - "consider using ordering modes `Release`, `SeqCst` or `Relaxed`" - ); - } - } - } -} - -fn check_memory_fence(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::Call(func, args) = expr.kind; - if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); - if ["fence", "compiler_fence"] - .iter() - .any(|func| match_def_path(cx, def_id, &["core", "sync", "atomic", func])); - if let ExprKind::Path(ref ordering_qpath) = &args[0].kind; - if let Some(ordering_def_id) = cx.qpath_res(ordering_qpath, args[0].hir_id).opt_def_id(); - if match_ordering_def_path(cx, ordering_def_id, &["Relaxed"]); - then { - span_lint_and_help( - cx, - INVALID_ATOMIC_ORDERING, - args[0].span, - "memory fences cannot have `Relaxed` ordering", - None, - "consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`" - ); - } - } -} - -fn opt_ordering_defid(cx: &LateContext<'_>, ord_arg: &Expr<'_>) -> Option { - if let ExprKind::Path(ref ord_qpath) = ord_arg.kind { - cx.qpath_res(ord_qpath, ord_arg.hir_id).opt_def_id() - } else { - None - } -} - -fn check_atomic_compare_exchange(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::MethodCall(method_path, _, args, _) = &expr.kind; - let method = method_path.ident.name.as_str(); - if type_is_atomic(cx, &args[0]); - if method == "compare_exchange" || method == "compare_exchange_weak" || method == "fetch_update"; - let (success_order_arg, failure_order_arg) = if method == "fetch_update" { - (&args[1], &args[2]) - } else { - (&args[3], &args[4]) - }; - if let Some(fail_ordering_def_id) = opt_ordering_defid(cx, failure_order_arg); - then { - // Helper type holding on to some checking and error reporting data. Has - // - (success ordering name, - // - list of failure orderings forbidden by the success order, - // - suggestion message) - type OrdLintInfo = (&'static str, &'static [&'static str], &'static str); - let relaxed: OrdLintInfo = ("Relaxed", &["SeqCst", "Acquire"], "ordering mode `Relaxed`"); - let acquire: OrdLintInfo = ("Acquire", &["SeqCst"], "ordering modes `Acquire` or `Relaxed`"); - let seq_cst: OrdLintInfo = ("SeqCst", &[], "ordering modes `Acquire`, `SeqCst` or `Relaxed`"); - let release = ("Release", relaxed.1, relaxed.2); - let acqrel = ("AcqRel", acquire.1, acquire.2); - let search = [relaxed, acquire, seq_cst, release, acqrel]; - - let success_lint_info = opt_ordering_defid(cx, success_order_arg) - .and_then(|success_ord_def_id| -> Option { - search - .iter() - .find(|(ordering, ..)| { - match_def_path(cx, success_ord_def_id, - &["core", "sync", "atomic", "Ordering", ordering]) - }) - .copied() - }); - - if match_ordering_def_path(cx, fail_ordering_def_id, &["Release", "AcqRel"]) { - // If we don't know the success order is, use what we'd suggest - // if it were maximally permissive. - let suggested = success_lint_info.unwrap_or(seq_cst).2; - span_lint_and_help( - cx, - INVALID_ATOMIC_ORDERING, - failure_order_arg.span, - &format!( - "{}'s failure ordering may not be `Release` or `AcqRel`", - method, - ), - None, - &format!("consider using {} instead", suggested), - ); - } else if let Some((success_ord_name, bad_ords_given_success, suggested)) = success_lint_info { - if match_ordering_def_path(cx, fail_ordering_def_id, bad_ords_given_success) { - span_lint_and_help( - cx, - INVALID_ATOMIC_ORDERING, - failure_order_arg.span, - &format!( - "{}'s failure ordering may not be stronger than the success ordering of `{}`", - method, - success_ord_name, - ), - None, - &format!("consider using {} instead", suggested), - ); - } - } - } - } -} - -impl<'tcx> LateLintPass<'tcx> for AtomicOrdering { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - check_atomic_load_store(cx, expr); - check_memory_fence(cx, expr); - check_atomic_compare_exchange(cx, expr); - } -} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index f49b382c5ea3..e455c8db03f5 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -165,7 +165,6 @@ mod asm_syntax; mod assertions_on_constants; mod assign_ops; mod async_yields_async; -mod atomic_ordering; mod attrs; mod await_holding_invalid; mod bit_mask; @@ -537,7 +536,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: assign_ops::ASSIGN_OP_PATTERN, assign_ops::MISREFACTORED_ASSIGN_OP, async_yields_async::ASYNC_YIELDS_ASYNC, - atomic_ordering::INVALID_ATOMIC_ORDERING, attrs::BLANKET_CLIPPY_RESTRICTION_LINTS, attrs::DEPRECATED_CFG_ATTR, attrs::DEPRECATED_SEMVER, @@ -1174,7 +1172,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(assign_ops::ASSIGN_OP_PATTERN), LintId::of(assign_ops::MISREFACTORED_ASSIGN_OP), LintId::of(async_yields_async::ASYNC_YIELDS_ASYNC), - LintId::of(atomic_ordering::INVALID_ATOMIC_ORDERING), LintId::of(attrs::BLANKET_CLIPPY_RESTRICTION_LINTS), LintId::of(attrs::DEPRECATED_CFG_ATTR), LintId::of(attrs::DEPRECATED_SEMVER), @@ -1670,7 +1667,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(absurd_extreme_comparisons::ABSURD_EXTREME_COMPARISONS), LintId::of(approx_const::APPROX_CONSTANT), LintId::of(async_yields_async::ASYNC_YIELDS_ASYNC), - LintId::of(atomic_ordering::INVALID_ATOMIC_ORDERING), LintId::of(attrs::DEPRECATED_SEMVER), LintId::of(attrs::MISMATCHED_TARGET_OS), LintId::of(attrs::USELESS_ATTRIBUTE), @@ -2044,7 +2040,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_late_pass(|| box floating_point_arithmetic::FloatingPointArithmetic); store.register_early_pass(|| box as_conversions::AsConversions); store.register_late_pass(|| box let_underscore::LetUnderscore); - store.register_late_pass(|| box atomic_ordering::AtomicOrdering); store.register_early_pass(|| box single_component_path_imports::SingleComponentPathImports); let max_fn_params_bools = conf.max_fn_params_bools; let max_struct_bools = conf.max_struct_bools; @@ -2183,6 +2178,7 @@ pub fn register_renamed(ls: &mut rustc_lint::LintStore) { ls.register_renamed("clippy::temporary_cstring_as_ptr", "temporary_cstring_as_ptr"); ls.register_renamed("clippy::panic_params", "non_fmt_panics"); ls.register_renamed("clippy::unknown_clippy_lints", "unknown_lints"); + ls.register_renamed("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"); } // only exists to let the dogfood integration test works. diff --git a/tests/ui/atomic_ordering_bool.rs b/tests/ui/atomic_ordering_bool.rs deleted file mode 100644 index cdbde79b19eb..000000000000 --- a/tests/ui/atomic_ordering_bool.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![warn(clippy::invalid_atomic_ordering)] - -use std::sync::atomic::{AtomicBool, Ordering}; - -fn main() { - let x = AtomicBool::new(true); - - // Allowed load ordering modes - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - - // Disallowed load ordering modes - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - // Allowed store ordering modes - x.store(false, Ordering::Release); - x.store(false, Ordering::SeqCst); - x.store(false, Ordering::Relaxed); - - // Disallowed store ordering modes - x.store(false, Ordering::Acquire); - x.store(false, Ordering::AcqRel); -} diff --git a/tests/ui/atomic_ordering_bool.stderr b/tests/ui/atomic_ordering_bool.stderr deleted file mode 100644 index 397b893aed96..000000000000 --- a/tests/ui/atomic_ordering_bool.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_bool.rs:14:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_bool.rs:15:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_bool.rs:23:20 - | -LL | x.store(false, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_bool.rs:24:20 - | -LL | x.store(false, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/atomic_ordering_exchange.rs b/tests/ui/atomic_ordering_exchange.rs deleted file mode 100644 index 1ddc12f9ab21..000000000000 --- a/tests/ui/atomic_ordering_exchange.rs +++ /dev/null @@ -1,45 +0,0 @@ -#![warn(clippy::invalid_atomic_ordering)] - -use std::sync::atomic::{AtomicUsize, Ordering}; - -fn main() { - // `compare_exchange` (not weak) testing - let x = AtomicUsize::new(0); - - // Allowed ordering combos - let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Relaxed); - let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::Acquire); - let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::Relaxed); - let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Relaxed); - let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::Acquire); - let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::Relaxed); - let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::Relaxed); - let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::Acquire); - let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::SeqCst); - - // AcqRel is always forbidden as a failure ordering - let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::AcqRel); - let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::AcqRel); - let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::AcqRel); - let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::AcqRel); - let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::AcqRel); - - // Release is always forbidden as a failure ordering - let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Release); - let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::Release); - let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Release); - let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::Release); - let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::Release); - - // Release success order forbids failure order of Acquire or SeqCst - let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Acquire); - let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::SeqCst); - - // Relaxed success order also forbids failure order of Acquire or SeqCst - let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::SeqCst); - let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Acquire); - - // Acquire/AcqRel forbids failure order of SeqCst - let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::SeqCst); - let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::SeqCst); -} diff --git a/tests/ui/atomic_ordering_exchange.stderr b/tests/ui/atomic_ordering_exchange.stderr deleted file mode 100644 index 4b9bfef79748..000000000000 --- a/tests/ui/atomic_ordering_exchange.stderr +++ /dev/null @@ -1,131 +0,0 @@ -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:21:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:22:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:23:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:24:56 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:25:56 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:28:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:29:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:30:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:31:56 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:32:56 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead - -error: compare_exchange's failure ordering may not be stronger than the success ordering of `Release` - --> $DIR/atomic_ordering_exchange.rs:35:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange's failure ordering may not be stronger than the success ordering of `Release` - --> $DIR/atomic_ordering_exchange.rs:36:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange's failure ordering may not be stronger than the success ordering of `Relaxed` - --> $DIR/atomic_ordering_exchange.rs:39:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange's failure ordering may not be stronger than the success ordering of `Relaxed` - --> $DIR/atomic_ordering_exchange.rs:40:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange's failure ordering may not be stronger than the success ordering of `Acquire` - --> $DIR/atomic_ordering_exchange.rs:43:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange's failure ordering may not be stronger than the success ordering of `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:44:56 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: aborting due to 16 previous errors - diff --git a/tests/ui/atomic_ordering_exchange_weak.rs b/tests/ui/atomic_ordering_exchange_weak.rs deleted file mode 100644 index 590699025072..000000000000 --- a/tests/ui/atomic_ordering_exchange_weak.rs +++ /dev/null @@ -1,47 +0,0 @@ -#![warn(clippy::invalid_atomic_ordering)] - -use std::sync::atomic::{AtomicPtr, Ordering}; - -fn main() { - let ptr = &mut 5; - let ptr2 = &mut 10; - // `compare_exchange_weak` testing - let x = AtomicPtr::new(ptr); - - // Allowed ordering combos - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Relaxed); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Acquire); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Relaxed); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Release, Ordering::Relaxed); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Acquire); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Relaxed); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Relaxed); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Acquire); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::SeqCst); - - // AcqRel is always forbidden as a failure ordering - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Relaxed, Ordering::AcqRel); - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::AcqRel); - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::AcqRel); - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::AcqRel); - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::SeqCst, Ordering::AcqRel); - - // Release is always forbidden as a failure ordering - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Release); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Release); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Release, Ordering::Release); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Release); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Release); - - // Release success order forbids failure order of Acquire or SeqCst - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::Acquire); - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::SeqCst); - - // Relaxed success order also forbids failure order of Acquire or SeqCst - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::SeqCst); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Acquire); - - // Acquire/AcqRel forbids failure order of SeqCst - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::SeqCst); - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::SeqCst); -} diff --git a/tests/ui/atomic_ordering_exchange_weak.stderr b/tests/ui/atomic_ordering_exchange_weak.stderr deleted file mode 100644 index de7026f3ffaf..000000000000 --- a/tests/ui/atomic_ordering_exchange_weak.stderr +++ /dev/null @@ -1,131 +0,0 @@ -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:23:67 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Relaxed, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:24:67 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:25:67 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:26:66 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:27:66 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::SeqCst, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:30:67 - | -LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:31:67 - | -LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:32:67 - | -LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Release, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:33:66 - | -LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:34:66 - | -LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Release` - --> $DIR/atomic_ordering_exchange_weak.rs:37:67 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Release` - --> $DIR/atomic_ordering_exchange_weak.rs:38:67 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Relaxed` - --> $DIR/atomic_ordering_exchange_weak.rs:41:67 - | -LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Relaxed` - --> $DIR/atomic_ordering_exchange_weak.rs:42:67 - | -LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Acquire` - --> $DIR/atomic_ordering_exchange_weak.rs:45:67 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:46:66 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: aborting due to 16 previous errors - diff --git a/tests/ui/atomic_ordering_fence.rs b/tests/ui/atomic_ordering_fence.rs deleted file mode 100644 index 5ee5182ca051..000000000000 --- a/tests/ui/atomic_ordering_fence.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![warn(clippy::invalid_atomic_ordering)] - -use std::sync::atomic::{compiler_fence, fence, Ordering}; - -fn main() { - // Allowed fence ordering modes - fence(Ordering::Acquire); - fence(Ordering::Release); - fence(Ordering::AcqRel); - fence(Ordering::SeqCst); - - // Disallowed fence ordering modes - fence(Ordering::Relaxed); - - compiler_fence(Ordering::Acquire); - compiler_fence(Ordering::Release); - compiler_fence(Ordering::AcqRel); - compiler_fence(Ordering::SeqCst); - compiler_fence(Ordering::Relaxed); -} diff --git a/tests/ui/atomic_ordering_fence.stderr b/tests/ui/atomic_ordering_fence.stderr deleted file mode 100644 index 3ceff27d9ad5..000000000000 --- a/tests/ui/atomic_ordering_fence.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: memory fences cannot have `Relaxed` ordering - --> $DIR/atomic_ordering_fence.rs:13:11 - | -LL | fence(Ordering::Relaxed); - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` - = help: consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst` - -error: memory fences cannot have `Relaxed` ordering - --> $DIR/atomic_ordering_fence.rs:19:20 - | -LL | compiler_fence(Ordering::Relaxed); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/atomic_ordering_fetch_update.rs b/tests/ui/atomic_ordering_fetch_update.rs deleted file mode 100644 index 550bdb001e4c..000000000000 --- a/tests/ui/atomic_ordering_fetch_update.rs +++ /dev/null @@ -1,45 +0,0 @@ -#![warn(clippy::invalid_atomic_ordering)] - -use std::sync::atomic::{AtomicIsize, Ordering}; - -fn main() { - // `fetch_update` testing - let x = AtomicIsize::new(0); - - // Allowed ordering combos - let _ = x.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Acquire, Ordering::Acquire, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Acquire, Ordering::Relaxed, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Release, Ordering::Relaxed, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::AcqRel, Ordering::Acquire, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::AcqRel, Ordering::Relaxed, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::SeqCst, Ordering::Relaxed, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::SeqCst, Ordering::Acquire, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |old| Some(old + 1)); - - // AcqRel is always forbidden as a failure ordering - let _ = x.fetch_update(Ordering::Relaxed, Ordering::AcqRel, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Acquire, Ordering::AcqRel, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Release, Ordering::AcqRel, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::AcqRel, Ordering::AcqRel, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::SeqCst, Ordering::AcqRel, |old| Some(old + 1)); - - // Release is always forbidden as a failure ordering - let _ = x.fetch_update(Ordering::Relaxed, Ordering::Release, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Acquire, Ordering::Release, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Release, Ordering::Release, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::AcqRel, Ordering::Release, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::SeqCst, Ordering::Release, |old| Some(old + 1)); - - // Release success order forbids failure order of Acquire or SeqCst - let _ = x.fetch_update(Ordering::Release, Ordering::Acquire, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Release, Ordering::SeqCst, |old| Some(old + 1)); - - // Relaxed success order also forbids failure order of Acquire or SeqCst - let _ = x.fetch_update(Ordering::Relaxed, Ordering::SeqCst, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Relaxed, Ordering::Acquire, |old| Some(old + 1)); - - // Acquire/AcqRel forbids failure order of SeqCst - let _ = x.fetch_update(Ordering::Acquire, Ordering::SeqCst, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::AcqRel, Ordering::SeqCst, |old| Some(old + 1)); -} diff --git a/tests/ui/atomic_ordering_fetch_update.stderr b/tests/ui/atomic_ordering_fetch_update.stderr deleted file mode 100644 index 694548ece97b..000000000000 --- a/tests/ui/atomic_ordering_fetch_update.stderr +++ /dev/null @@ -1,131 +0,0 @@ -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:21:47 - | -LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::AcqRel, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` - = help: consider using ordering mode `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:22:47 - | -LL | let _ = x.fetch_update(Ordering::Acquire, Ordering::AcqRel, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:23:47 - | -LL | let _ = x.fetch_update(Ordering::Release, Ordering::AcqRel, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:24:46 - | -LL | let _ = x.fetch_update(Ordering::AcqRel, Ordering::AcqRel, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:25:46 - | -LL | let _ = x.fetch_update(Ordering::SeqCst, Ordering::AcqRel, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:28:47 - | -LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::Release, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:29:47 - | -LL | let _ = x.fetch_update(Ordering::Acquire, Ordering::Release, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:30:47 - | -LL | let _ = x.fetch_update(Ordering::Release, Ordering::Release, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:31:46 - | -LL | let _ = x.fetch_update(Ordering::AcqRel, Ordering::Release, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:32:46 - | -LL | let _ = x.fetch_update(Ordering::SeqCst, Ordering::Release, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead - -error: fetch_update's failure ordering may not be stronger than the success ordering of `Release` - --> $DIR/atomic_ordering_fetch_update.rs:35:47 - | -LL | let _ = x.fetch_update(Ordering::Release, Ordering::Acquire, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: fetch_update's failure ordering may not be stronger than the success ordering of `Release` - --> $DIR/atomic_ordering_fetch_update.rs:36:47 - | -LL | let _ = x.fetch_update(Ordering::Release, Ordering::SeqCst, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: fetch_update's failure ordering may not be stronger than the success ordering of `Relaxed` - --> $DIR/atomic_ordering_fetch_update.rs:39:47 - | -LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::SeqCst, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: fetch_update's failure ordering may not be stronger than the success ordering of `Relaxed` - --> $DIR/atomic_ordering_fetch_update.rs:40:47 - | -LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::Acquire, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: fetch_update's failure ordering may not be stronger than the success ordering of `Acquire` - --> $DIR/atomic_ordering_fetch_update.rs:43:47 - | -LL | let _ = x.fetch_update(Ordering::Acquire, Ordering::SeqCst, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: fetch_update's failure ordering may not be stronger than the success ordering of `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:44:46 - | -LL | let _ = x.fetch_update(Ordering::AcqRel, Ordering::SeqCst, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: aborting due to 16 previous errors - diff --git a/tests/ui/atomic_ordering_int.rs b/tests/ui/atomic_ordering_int.rs deleted file mode 100644 index 40a00ba3de35..000000000000 --- a/tests/ui/atomic_ordering_int.rs +++ /dev/null @@ -1,86 +0,0 @@ -#![warn(clippy::invalid_atomic_ordering)] - -use std::sync::atomic::{AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, Ordering}; - -fn main() { - // `AtomicI8` test cases - let x = AtomicI8::new(0); - - // Allowed load ordering modes - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - - // Disallowed load ordering modes - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - // Allowed store ordering modes - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - - // Disallowed store ordering modes - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); - - // `AtomicI16` test cases - let x = AtomicI16::new(0); - - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); - - // `AtomicI32` test cases - let x = AtomicI32::new(0); - - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); - - // `AtomicI64` test cases - let x = AtomicI64::new(0); - - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); - - // `AtomicIsize` test cases - let x = AtomicIsize::new(0); - - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); -} diff --git a/tests/ui/atomic_ordering_int.stderr b/tests/ui/atomic_ordering_int.stderr deleted file mode 100644 index bbaf234d3c9f..000000000000 --- a/tests/ui/atomic_ordering_int.stderr +++ /dev/null @@ -1,163 +0,0 @@ -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:15:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:16:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:24:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:25:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:33:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:34:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:39:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:40:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:48:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:49:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:54:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:55:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:63:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:64:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:69:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:70:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:78:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:79:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:84:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:85:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: aborting due to 20 previous errors - diff --git a/tests/ui/atomic_ordering_ptr.rs b/tests/ui/atomic_ordering_ptr.rs deleted file mode 100644 index ecbb05c7fbc3..000000000000 --- a/tests/ui/atomic_ordering_ptr.rs +++ /dev/null @@ -1,27 +0,0 @@ -#![warn(clippy::invalid_atomic_ordering)] - -use std::sync::atomic::{AtomicPtr, Ordering}; - -fn main() { - let ptr = &mut 5; - let other_ptr = &mut 10; - let x = AtomicPtr::new(ptr); - - // Allowed load ordering modes - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - - // Disallowed load ordering modes - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - // Allowed store ordering modes - x.store(other_ptr, Ordering::Release); - x.store(other_ptr, Ordering::SeqCst); - x.store(other_ptr, Ordering::Relaxed); - - // Disallowed store ordering modes - x.store(other_ptr, Ordering::Acquire); - x.store(other_ptr, Ordering::AcqRel); -} diff --git a/tests/ui/atomic_ordering_ptr.stderr b/tests/ui/atomic_ordering_ptr.stderr deleted file mode 100644 index 558ae55518d5..000000000000 --- a/tests/ui/atomic_ordering_ptr.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_ptr.rs:16:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_ptr.rs:17:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_ptr.rs:25:24 - | -LL | x.store(other_ptr, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_ptr.rs:26:24 - | -LL | x.store(other_ptr, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/atomic_ordering_uint.rs b/tests/ui/atomic_ordering_uint.rs deleted file mode 100644 index a0d5d7c40103..000000000000 --- a/tests/ui/atomic_ordering_uint.rs +++ /dev/null @@ -1,86 +0,0 @@ -#![warn(clippy::invalid_atomic_ordering)] - -use std::sync::atomic::{AtomicU16, AtomicU32, AtomicU64, AtomicU8, AtomicUsize, Ordering}; - -fn main() { - // `AtomicU8` test cases - let x = AtomicU8::new(0); - - // Allowed load ordering modes - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - - // Disallowed load ordering modes - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - // Allowed store ordering modes - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - - // Disallowed store ordering modes - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); - - // `AtomicU16` test cases - let x = AtomicU16::new(0); - - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); - - // `AtomicU32` test cases - let x = AtomicU32::new(0); - - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); - - // `AtomicU64` test cases - let x = AtomicU64::new(0); - - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); - - // `AtomicUsize` test cases - let x = AtomicUsize::new(0); - - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); -} diff --git a/tests/ui/atomic_ordering_uint.stderr b/tests/ui/atomic_ordering_uint.stderr deleted file mode 100644 index 5703135bcf1e..000000000000 --- a/tests/ui/atomic_ordering_uint.stderr +++ /dev/null @@ -1,163 +0,0 @@ -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:15:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:16:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:24:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:25:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:33:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:34:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:39:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:40:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:48:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:49:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:54:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:55:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:63:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:64:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:69:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:70:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:78:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:79:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:84:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:85:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: aborting due to 20 previous errors - diff --git a/tests/ui/deprecated.rs b/tests/ui/deprecated.rs index 4ba9f0c1fcff..1943d0092e62 100644 --- a/tests/ui/deprecated.rs +++ b/tests/ui/deprecated.rs @@ -14,5 +14,6 @@ #[warn(clippy::filter_map)] #[warn(clippy::pub_enum_variant_names)] #[warn(clippy::wrong_pub_self_convention)] +#[warn(clippy::invalid_atomic_ordering)] fn main() {} diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr index c0002e535431..51048e45c067 100644 --- a/tests/ui/deprecated.stderr +++ b/tests/ui/deprecated.stderr @@ -96,5 +96,11 @@ error: lint `clippy::wrong_pub_self_convention` has been removed: set the `avoid LL | #[warn(clippy::wrong_pub_self_convention)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 16 previous errors +error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` + --> $DIR/deprecated.rs:17:8 + | +LL | #[warn(clippy::invalid_atomic_ordering)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` + +error: aborting due to 17 previous errors From c87d07365b71a00d7c7cc06041aa596571d64503 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Fri, 16 Jul 2021 08:54:08 -0500 Subject: [PATCH 0293/1222] clippy: Fix format_args expansion parsing --- clippy_utils/src/higher.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index 29b698e56e3c..6437363bad74 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -485,12 +485,28 @@ impl FormatArgsExpn<'tcx> { if let ExpnKind::Macro(_, name) = expr.span.ctxt().outer_expn_data().kind; let name = name.as_str(); if name.ends_with("format_args") || name.ends_with("format_args_nl"); - if let ExprKind::Call(_, args) = expr.kind; - if let Some((strs_ref, args, fmt_expr)) = match args { + + if let ExprKind::Match(inner_match, [arm], _) = expr.kind; + + // `match match`, if you will + if let ExprKind::Match(args, [inner_arm], _) = inner_match.kind; + if let ExprKind::Tup(value_args) = args.kind; + if let Some(value_args) = value_args + .iter() + .map(|e| match e.kind { + ExprKind::AddrOf(_, _, e) => Some(e), + _ => None, + }) + .collect(); + if let ExprKind::Array(args) = inner_arm.body.kind; + + if let ExprKind::Block(Block { stmts: [], expr: Some(expr), .. }, _) = arm.body.kind; + if let ExprKind::Call(_, call_args) = expr.kind; + if let Some((strs_ref, fmt_expr)) = match call_args { // Arguments::new_v1 - [strs_ref, args] => Some((strs_ref, args, None)), + [strs_ref, _] => Some((strs_ref, None)), // Arguments::new_v1_formatted - [strs_ref, args, fmt_expr] => Some((strs_ref, args, Some(fmt_expr))), + [strs_ref, _, fmt_expr] => Some((strs_ref, Some(fmt_expr))), _ => None, }; if let ExprKind::AddrOf(BorrowKind::Ref, _, strs_arr) = strs_ref.kind; @@ -506,17 +522,6 @@ impl FormatArgsExpn<'tcx> { None }) .collect(); - if let ExprKind::AddrOf(BorrowKind::Ref, _, args) = args.kind; - if let ExprKind::Match(args, [arm], _) = args.kind; - if let ExprKind::Tup(value_args) = args.kind; - if let Some(value_args) = value_args - .iter() - .map(|e| match e.kind { - ExprKind::AddrOf(_, _, e) => Some(e), - _ => None, - }) - .collect(); - if let ExprKind::Array(args) = arm.body.kind; then { Some(FormatArgsExpn { format_string_span: strs_ref.span, From 0f7f397db0e231ac5a3deafa6e4880e96ecf9af4 Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Fri, 6 Aug 2021 17:14:27 +0200 Subject: [PATCH 0294/1222] remove box_syntax uses from cranelift and tools --- clippy_lints/src/booleans.rs | 2 +- clippy_lints/src/doc.rs | 4 +- clippy_lints/src/lib.rs | 489 +++++++++++++++++------------------ 3 files changed, 247 insertions(+), 248 deletions(-) diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 4a83d35a568c..6f12d34e66b6 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -116,7 +116,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> { // prevent folding of `cfg!` macros and the like if !e.span.from_expansion() { match &e.kind { - ExprKind::Unary(UnOp::Not, inner) => return Ok(Bool::Not(box self.run(inner)?)), + ExprKind::Unary(UnOp::Not, inner) => return Ok(Bool::Not(Box::new(self.run(inner)?))), ExprKind::Binary(binop, lhs, rhs) => match &binop.node { BinOpKind::Or => { return Ok(Bool::Or(self.extract(BinOpKind::Or, &[lhs, rhs], Vec::new())?)); diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 75561cfde369..cb2b7f5be70a 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -578,8 +578,8 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { let filename = FileName::anon_source_code(&code); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let emitter = EmitterWriter::new(box io::sink(), None, false, false, false, None, false); - let handler = Handler::with_emitter(false, None, box emitter); + let emitter = EmitterWriter::new(Box::new(io::sink()), None, false, false, false, None, false); + let handler = Handler::with_emitter(false, None, Box::new(emitter)); let sess = ParseSess::with_span_handler(handler, sm); let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) { diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 6f73a00d1f78..19719502870b 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -1,7 +1,6 @@ // error-pattern:cargo-clippy #![feature(box_patterns)] -#![feature(box_syntax)] #![feature(drain_filter)] #![feature(in_band_lifetimes)] #![feature(iter_zip)] @@ -393,9 +392,9 @@ use crate::utils::conf::TryConf; /// Used in `./src/driver.rs`. pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore) { // NOTE: Do not add any more pre-expansion passes. These should be removed eventually. - store.register_pre_expansion_pass(|| box write::Write::default()); - store.register_pre_expansion_pass(|| box attrs::EarlyAttributes); - store.register_pre_expansion_pass(|| box dbg_macro::DbgMacro); + store.register_pre_expansion_pass(|| Box::new(write::Write::default())); + store.register_pre_expansion_pass(|| Box::new(attrs::EarlyAttributes)); + store.register_pre_expansion_pass(|| Box::new(dbg_macro::DbgMacro)); } #[doc(hidden)] @@ -1810,7 +1809,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: #[cfg(feature = "metadata-collector-lint")] { if std::env::var("ENABLE_METADATA_COLLECTION").eq(&Ok("1".to_string())) { - store.register_late_pass(|| box utils::internal_lints::metadata_collector::MetadataCollector::new()); + store.register_late_pass(|| Box::new(utils::internal_lints::metadata_collector::MetadataCollector::new())); return; } } @@ -1818,57 +1817,57 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: // all the internal lints #[cfg(feature = "internal-lints")] { - store.register_early_pass(|| box utils::internal_lints::ClippyLintsInternal); - store.register_early_pass(|| box utils::internal_lints::ProduceIce); - store.register_late_pass(|| box utils::inspector::DeepCodeInspector); - store.register_late_pass(|| box utils::internal_lints::CollapsibleCalls); - store.register_late_pass(|| box utils::internal_lints::CompilerLintFunctions::new()); - store.register_late_pass(|| box utils::internal_lints::IfChainStyle); - store.register_late_pass(|| box utils::internal_lints::InvalidPaths); - store.register_late_pass(|| box utils::internal_lints::InterningDefinedSymbol::default()); - store.register_late_pass(|| box utils::internal_lints::LintWithoutLintPass::default()); - store.register_late_pass(|| box utils::internal_lints::MatchTypeOnDiagItem); - store.register_late_pass(|| box utils::internal_lints::OuterExpnDataPass); + store.register_early_pass(|| Box::new(utils::internal_lints::ClippyLintsInternal)); + store.register_early_pass(|| Box::new(utils::internal_lints::ProduceIce)); + store.register_late_pass(|| Box::new(utils::inspector::DeepCodeInspector)); + store.register_late_pass(|| Box::new(utils::internal_lints::CollapsibleCalls)); + store.register_late_pass(|| Box::new(utils::internal_lints::CompilerLintFunctions::new())); + store.register_late_pass(|| Box::new(utils::internal_lints::IfChainStyle)); + store.register_late_pass(|| Box::new(utils::internal_lints::InvalidPaths)); + store.register_late_pass(|| Box::new(utils::internal_lints::InterningDefinedSymbol::default())); + store.register_late_pass(|| Box::new(utils::internal_lints::LintWithoutLintPass::default())); + store.register_late_pass(|| Box::new(utils::internal_lints::MatchTypeOnDiagItem)); + store.register_late_pass(|| Box::new(utils::internal_lints::OuterExpnDataPass)); } - store.register_late_pass(|| box utils::author::Author); - store.register_late_pass(|| box await_holding_invalid::AwaitHolding); - store.register_late_pass(|| box serde_api::SerdeApi); + store.register_late_pass(|| Box::new(utils::author::Author)); + store.register_late_pass(|| Box::new(await_holding_invalid::AwaitHolding)); + store.register_late_pass(|| Box::new(serde_api::SerdeApi)); let vec_box_size_threshold = conf.vec_box_size_threshold; let type_complexity_threshold = conf.type_complexity_threshold; - store.register_late_pass(move || box types::Types::new(vec_box_size_threshold, type_complexity_threshold)); - store.register_late_pass(|| box booleans::NonminimalBool); - store.register_late_pass(|| box needless_bitwise_bool::NeedlessBitwiseBool); - store.register_late_pass(|| box eq_op::EqOp); - store.register_late_pass(|| box enum_clike::UnportableVariant); - store.register_late_pass(|| box float_literal::FloatLiteral); + store.register_late_pass(move || Box::new(types::Types::new(vec_box_size_threshold, type_complexity_threshold))); + store.register_late_pass(|| Box::new(booleans::NonminimalBool)); + store.register_late_pass(|| Box::new(needless_bitwise_bool::NeedlessBitwiseBool)); + store.register_late_pass(|| Box::new(eq_op::EqOp)); + store.register_late_pass(|| Box::new(enum_clike::UnportableVariant)); + store.register_late_pass(|| Box::new(float_literal::FloatLiteral)); let verbose_bit_mask_threshold = conf.verbose_bit_mask_threshold; - store.register_late_pass(move || box bit_mask::BitMask::new(verbose_bit_mask_threshold)); - store.register_late_pass(|| box ptr::Ptr); - store.register_late_pass(|| box ptr_eq::PtrEq); - store.register_late_pass(|| box needless_bool::NeedlessBool); - store.register_late_pass(|| box needless_bool::BoolComparison); - store.register_late_pass(|| box needless_for_each::NeedlessForEach); - store.register_late_pass(|| box approx_const::ApproxConstant); - store.register_late_pass(|| box misc::MiscLints); - store.register_late_pass(|| box eta_reduction::EtaReduction); - store.register_late_pass(|| box identity_op::IdentityOp); - store.register_late_pass(|| box erasing_op::ErasingOp); - store.register_late_pass(|| box mut_mut::MutMut); - store.register_late_pass(|| box mut_reference::UnnecessaryMutPassed); - store.register_late_pass(|| box len_zero::LenZero); - store.register_late_pass(|| box attrs::Attributes); - store.register_late_pass(|| box blocks_in_if_conditions::BlocksInIfConditions); - store.register_late_pass(|| box collapsible_match::CollapsibleMatch); - store.register_late_pass(|| box unicode::Unicode); - store.register_late_pass(|| box unit_return_expecting_ord::UnitReturnExpectingOrd); - store.register_late_pass(|| box strings::StringAdd); - store.register_late_pass(|| box implicit_return::ImplicitReturn); - store.register_late_pass(|| box implicit_saturating_sub::ImplicitSaturatingSub); - store.register_late_pass(|| box default_numeric_fallback::DefaultNumericFallback); - store.register_late_pass(|| box inconsistent_struct_constructor::InconsistentStructConstructor); - store.register_late_pass(|| box non_octal_unix_permissions::NonOctalUnixPermissions); - store.register_early_pass(|| box unnecessary_self_imports::UnnecessarySelfImports); + store.register_late_pass(move || Box::new(bit_mask::BitMask::new(verbose_bit_mask_threshold))); + store.register_late_pass(|| Box::new(ptr::Ptr)); + store.register_late_pass(|| Box::new(ptr_eq::PtrEq)); + store.register_late_pass(|| Box::new(needless_bool::NeedlessBool)); + store.register_late_pass(|| Box::new(needless_bool::BoolComparison)); + store.register_late_pass(|| Box::new(needless_for_each::NeedlessForEach)); + store.register_late_pass(|| Box::new(approx_const::ApproxConstant)); + store.register_late_pass(|| Box::new(misc::MiscLints)); + store.register_late_pass(|| Box::new(eta_reduction::EtaReduction)); + store.register_late_pass(|| Box::new(identity_op::IdentityOp)); + store.register_late_pass(|| Box::new(erasing_op::ErasingOp)); + store.register_late_pass(|| Box::new(mut_mut::MutMut)); + store.register_late_pass(|| Box::new(mut_reference::UnnecessaryMutPassed)); + store.register_late_pass(|| Box::new(len_zero::LenZero)); + store.register_late_pass(|| Box::new(attrs::Attributes)); + store.register_late_pass(|| Box::new(blocks_in_if_conditions::BlocksInIfConditions)); + store.register_late_pass(|| Box::new(collapsible_match::CollapsibleMatch)); + store.register_late_pass(|| Box::new(unicode::Unicode)); + store.register_late_pass(|| Box::new(unit_return_expecting_ord::UnitReturnExpectingOrd)); + store.register_late_pass(|| Box::new(strings::StringAdd)); + store.register_late_pass(|| Box::new(implicit_return::ImplicitReturn)); + store.register_late_pass(|| Box::new(implicit_saturating_sub::ImplicitSaturatingSub)); + store.register_late_pass(|| Box::new(default_numeric_fallback::DefaultNumericFallback)); + store.register_late_pass(|| Box::new(inconsistent_struct_constructor::InconsistentStructConstructor)); + store.register_late_pass(|| Box::new(non_octal_unix_permissions::NonOctalUnixPermissions)); + store.register_early_pass(|| Box::new(unnecessary_self_imports::UnnecessarySelfImports)); let msrv = conf.msrv.as_ref().and_then(|s| { parse_msrv(s, None, None).or_else(|| { @@ -1878,231 +1877,231 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: }); let avoid_breaking_exported_api = conf.avoid_breaking_exported_api; - store.register_late_pass(move || box methods::Methods::new(avoid_breaking_exported_api, msrv)); - store.register_late_pass(move || box matches::Matches::new(msrv)); - store.register_early_pass(move || box manual_non_exhaustive::ManualNonExhaustive::new(msrv)); - store.register_late_pass(move || box manual_strip::ManualStrip::new(msrv)); - store.register_early_pass(move || box redundant_static_lifetimes::RedundantStaticLifetimes::new(msrv)); - store.register_early_pass(move || box redundant_field_names::RedundantFieldNames::new(msrv)); - store.register_late_pass(move || box checked_conversions::CheckedConversions::new(msrv)); - store.register_late_pass(move || box mem_replace::MemReplace::new(msrv)); - store.register_late_pass(move || box ranges::Ranges::new(msrv)); - store.register_late_pass(move || box from_over_into::FromOverInto::new(msrv)); - store.register_late_pass(move || box use_self::UseSelf::new(msrv)); - store.register_late_pass(move || box missing_const_for_fn::MissingConstForFn::new(msrv)); - store.register_late_pass(move || box needless_question_mark::NeedlessQuestionMark); - store.register_late_pass(move || box casts::Casts::new(msrv)); - store.register_early_pass(move || box unnested_or_patterns::UnnestedOrPatterns::new(msrv)); + store.register_late_pass(move || Box::new(methods::Methods::new(avoid_breaking_exported_api, msrv))); + store.register_late_pass(move || Box::new(matches::Matches::new(msrv))); + store.register_early_pass(move || Box::new(manual_non_exhaustive::ManualNonExhaustive::new(msrv))); + store.register_late_pass(move || Box::new(manual_strip::ManualStrip::new(msrv))); + store.register_early_pass(move || Box::new(redundant_static_lifetimes::RedundantStaticLifetimes::new(msrv))); + store.register_early_pass(move || Box::new(redundant_field_names::RedundantFieldNames::new(msrv))); + store.register_late_pass(move || Box::new(checked_conversions::CheckedConversions::new(msrv))); + store.register_late_pass(move || Box::new(mem_replace::MemReplace::new(msrv))); + store.register_late_pass(move || Box::new(ranges::Ranges::new(msrv))); + store.register_late_pass(move || Box::new(from_over_into::FromOverInto::new(msrv))); + store.register_late_pass(move || Box::new(use_self::UseSelf::new(msrv))); + store.register_late_pass(move || Box::new(missing_const_for_fn::MissingConstForFn::new(msrv))); + store.register_late_pass(move || Box::new(needless_question_mark::NeedlessQuestionMark)); + store.register_late_pass(move || Box::new(casts::Casts::new(msrv))); + store.register_early_pass(move || Box::new(unnested_or_patterns::UnnestedOrPatterns::new(msrv))); - store.register_late_pass(|| box size_of_in_element_count::SizeOfInElementCount); - store.register_late_pass(|| box map_clone::MapClone); - store.register_late_pass(|| box map_err_ignore::MapErrIgnore); - store.register_late_pass(|| box shadow::Shadow); - store.register_late_pass(|| box unit_types::UnitTypes); - store.register_late_pass(|| box loops::Loops); - store.register_late_pass(|| box main_recursion::MainRecursion::default()); - store.register_late_pass(|| box lifetimes::Lifetimes); - store.register_late_pass(|| box entry::HashMapPass); - store.register_late_pass(|| box minmax::MinMaxPass); - store.register_late_pass(|| box open_options::OpenOptions); - store.register_late_pass(|| box zero_div_zero::ZeroDiv); - store.register_late_pass(|| box mutex_atomic::Mutex); - store.register_late_pass(|| box needless_update::NeedlessUpdate); - store.register_late_pass(|| box needless_borrow::NeedlessBorrow::default()); - store.register_late_pass(|| box needless_borrowed_ref::NeedlessBorrowedRef); - store.register_late_pass(|| box no_effect::NoEffect); - store.register_late_pass(|| box temporary_assignment::TemporaryAssignment); - store.register_late_pass(|| box transmute::Transmute); + store.register_late_pass(|| Box::new(size_of_in_element_count::SizeOfInElementCount)); + store.register_late_pass(|| Box::new(map_clone::MapClone)); + store.register_late_pass(|| Box::new(map_err_ignore::MapErrIgnore)); + store.register_late_pass(|| Box::new(shadow::Shadow)); + store.register_late_pass(|| Box::new(unit_types::UnitTypes)); + store.register_late_pass(|| Box::new(loops::Loops)); + store.register_late_pass(|| Box::new(main_recursion::MainRecursion::default())); + store.register_late_pass(|| Box::new(lifetimes::Lifetimes)); + store.register_late_pass(|| Box::new(entry::HashMapPass)); + store.register_late_pass(|| Box::new(minmax::MinMaxPass)); + store.register_late_pass(|| Box::new(open_options::OpenOptions)); + store.register_late_pass(|| Box::new(zero_div_zero::ZeroDiv)); + store.register_late_pass(|| Box::new(mutex_atomic::Mutex)); + store.register_late_pass(|| Box::new(needless_update::NeedlessUpdate)); + store.register_late_pass(|| Box::new(needless_borrow::NeedlessBorrow::default())); + store.register_late_pass(|| Box::new(needless_borrowed_ref::NeedlessBorrowedRef)); + store.register_late_pass(|| Box::new(no_effect::NoEffect)); + store.register_late_pass(|| Box::new(temporary_assignment::TemporaryAssignment)); + store.register_late_pass(|| Box::new(transmute::Transmute)); let cognitive_complexity_threshold = conf.cognitive_complexity_threshold; - store.register_late_pass(move || box cognitive_complexity::CognitiveComplexity::new(cognitive_complexity_threshold)); + store.register_late_pass(move || Box::new(cognitive_complexity::CognitiveComplexity::new(cognitive_complexity_threshold))); let too_large_for_stack = conf.too_large_for_stack; - store.register_late_pass(move || box escape::BoxedLocal{too_large_for_stack}); - store.register_late_pass(move || box vec::UselessVec{too_large_for_stack}); - store.register_late_pass(|| box panic_unimplemented::PanicUnimplemented); - store.register_late_pass(|| box strings::StringLitAsBytes); - store.register_late_pass(|| box derive::Derive); - store.register_late_pass(|| box get_last_with_len::GetLastWithLen); - store.register_late_pass(|| box drop_forget_ref::DropForgetRef); - store.register_late_pass(|| box empty_enum::EmptyEnum); - store.register_late_pass(|| box absurd_extreme_comparisons::AbsurdExtremeComparisons); - store.register_late_pass(|| box invalid_upcast_comparisons::InvalidUpcastComparisons); - store.register_late_pass(|| box regex::Regex::default()); - store.register_late_pass(|| box copies::CopyAndPaste); - store.register_late_pass(|| box copy_iterator::CopyIterator); - store.register_late_pass(|| box format::UselessFormat); - store.register_late_pass(|| box swap::Swap); - store.register_late_pass(|| box overflow_check_conditional::OverflowCheckConditional); - store.register_late_pass(|| box new_without_default::NewWithoutDefault::default()); + store.register_late_pass(move || Box::new(escape::BoxedLocal{too_large_for_stack})); + store.register_late_pass(move || Box::new(vec::UselessVec{too_large_for_stack})); + store.register_late_pass(|| Box::new(panic_unimplemented::PanicUnimplemented)); + store.register_late_pass(|| Box::new(strings::StringLitAsBytes)); + store.register_late_pass(|| Box::new(derive::Derive)); + store.register_late_pass(|| Box::new(get_last_with_len::GetLastWithLen)); + store.register_late_pass(|| Box::new(drop_forget_ref::DropForgetRef)); + store.register_late_pass(|| Box::new(empty_enum::EmptyEnum)); + store.register_late_pass(|| Box::new(absurd_extreme_comparisons::AbsurdExtremeComparisons)); + store.register_late_pass(|| Box::new(invalid_upcast_comparisons::InvalidUpcastComparisons)); + store.register_late_pass(|| Box::new(regex::Regex::default())); + store.register_late_pass(|| Box::new(copies::CopyAndPaste)); + store.register_late_pass(|| Box::new(copy_iterator::CopyIterator)); + store.register_late_pass(|| Box::new(format::UselessFormat)); + store.register_late_pass(|| Box::new(swap::Swap)); + store.register_late_pass(|| Box::new(overflow_check_conditional::OverflowCheckConditional)); + store.register_late_pass(|| Box::new(new_without_default::NewWithoutDefault::default())); let blacklisted_names = conf.blacklisted_names.iter().cloned().collect::>(); - store.register_late_pass(move || box blacklisted_name::BlacklistedName::new(blacklisted_names.clone())); + store.register_late_pass(move || Box::new(blacklisted_name::BlacklistedName::new(blacklisted_names.clone()))); let too_many_arguments_threshold = conf.too_many_arguments_threshold; let too_many_lines_threshold = conf.too_many_lines_threshold; - store.register_late_pass(move || box functions::Functions::new(too_many_arguments_threshold, too_many_lines_threshold)); + store.register_late_pass(move || Box::new(functions::Functions::new(too_many_arguments_threshold, too_many_lines_threshold))); let doc_valid_idents = conf.doc_valid_idents.iter().cloned().collect::>(); - store.register_late_pass(move || box doc::DocMarkdown::new(doc_valid_idents.clone())); - store.register_late_pass(|| box neg_multiply::NegMultiply); - store.register_late_pass(|| box mem_discriminant::MemDiscriminant); - store.register_late_pass(|| box mem_forget::MemForget); - store.register_late_pass(|| box arithmetic::Arithmetic::default()); - store.register_late_pass(|| box assign_ops::AssignOps); - store.register_late_pass(|| box let_if_seq::LetIfSeq); - store.register_late_pass(|| box eval_order_dependence::EvalOrderDependence); - store.register_late_pass(|| box missing_doc::MissingDoc::new()); - store.register_late_pass(|| box missing_inline::MissingInline); - store.register_late_pass(move || box exhaustive_items::ExhaustiveItems); - store.register_late_pass(|| box if_let_some_result::OkIfLet); - store.register_late_pass(|| box partialeq_ne_impl::PartialEqNeImpl); - store.register_late_pass(|| box unused_io_amount::UnusedIoAmount); + store.register_late_pass(move || Box::new(doc::DocMarkdown::new(doc_valid_idents.clone()))); + store.register_late_pass(|| Box::new(neg_multiply::NegMultiply)); + store.register_late_pass(|| Box::new(mem_discriminant::MemDiscriminant)); + store.register_late_pass(|| Box::new(mem_forget::MemForget)); + store.register_late_pass(|| Box::new(arithmetic::Arithmetic::default())); + store.register_late_pass(|| Box::new(assign_ops::AssignOps)); + store.register_late_pass(|| Box::new(let_if_seq::LetIfSeq)); + store.register_late_pass(|| Box::new(eval_order_dependence::EvalOrderDependence)); + store.register_late_pass(|| Box::new(missing_doc::MissingDoc::new())); + store.register_late_pass(|| Box::new(missing_inline::MissingInline)); + store.register_late_pass(move || Box::new(exhaustive_items::ExhaustiveItems)); + store.register_late_pass(|| Box::new(if_let_some_result::OkIfLet)); + store.register_late_pass(|| Box::new(partialeq_ne_impl::PartialEqNeImpl)); + store.register_late_pass(|| Box::new(unused_io_amount::UnusedIoAmount)); let enum_variant_size_threshold = conf.enum_variant_size_threshold; - store.register_late_pass(move || box large_enum_variant::LargeEnumVariant::new(enum_variant_size_threshold)); - store.register_late_pass(|| box explicit_write::ExplicitWrite); - store.register_late_pass(|| box needless_pass_by_value::NeedlessPassByValue); + store.register_late_pass(move || Box::new(large_enum_variant::LargeEnumVariant::new(enum_variant_size_threshold))); + store.register_late_pass(|| Box::new(explicit_write::ExplicitWrite)); + store.register_late_pass(|| Box::new(needless_pass_by_value::NeedlessPassByValue)); let pass_by_ref_or_value = pass_by_ref_or_value::PassByRefOrValue::new( conf.trivial_copy_size_limit, conf.pass_by_value_size_limit, conf.avoid_breaking_exported_api, &sess.target, ); - store.register_late_pass(move || box pass_by_ref_or_value); - store.register_late_pass(|| box ref_option_ref::RefOptionRef); - store.register_late_pass(|| box try_err::TryErr); - store.register_late_pass(|| box bytecount::ByteCount); - store.register_late_pass(|| box infinite_iter::InfiniteIter); - store.register_late_pass(|| box inline_fn_without_body::InlineFnWithoutBody); - store.register_late_pass(|| box useless_conversion::UselessConversion::default()); - store.register_late_pass(|| box implicit_hasher::ImplicitHasher); - store.register_late_pass(|| box fallible_impl_from::FallibleImplFrom); - store.register_late_pass(|| box double_comparison::DoubleComparisons); - store.register_late_pass(|| box question_mark::QuestionMark); - store.register_early_pass(|| box suspicious_operation_groupings::SuspiciousOperationGroupings); - store.register_late_pass(|| box suspicious_trait_impl::SuspiciousImpl); - store.register_late_pass(|| box map_unit_fn::MapUnit); - store.register_late_pass(|| box inherent_impl::MultipleInherentImpl); - store.register_late_pass(|| box neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd); - store.register_late_pass(|| box unwrap::Unwrap); - store.register_late_pass(|| box duration_subsec::DurationSubsec); - store.register_late_pass(|| box indexing_slicing::IndexingSlicing); - store.register_late_pass(|| box non_copy_const::NonCopyConst); - store.register_late_pass(|| box ptr_offset_with_cast::PtrOffsetWithCast); - store.register_late_pass(|| box redundant_clone::RedundantClone); - store.register_late_pass(|| box slow_vector_initialization::SlowVectorInit); - store.register_late_pass(|| box unnecessary_sort_by::UnnecessarySortBy); - store.register_late_pass(move || box unnecessary_wraps::UnnecessaryWraps::new(avoid_breaking_exported_api)); - store.register_late_pass(|| box assertions_on_constants::AssertionsOnConstants); - store.register_late_pass(|| box transmuting_null::TransmutingNull); - store.register_late_pass(|| box path_buf_push_overwrite::PathBufPushOverwrite); - store.register_late_pass(|| box integer_division::IntegerDivision); - store.register_late_pass(|| box inherent_to_string::InherentToString); + store.register_late_pass(move || Box::new(pass_by_ref_or_value)); + store.register_late_pass(|| Box::new(ref_option_ref::RefOptionRef)); + store.register_late_pass(|| Box::new(try_err::TryErr)); + store.register_late_pass(|| Box::new(bytecount::ByteCount)); + store.register_late_pass(|| Box::new(infinite_iter::InfiniteIter)); + store.register_late_pass(|| Box::new(inline_fn_without_body::InlineFnWithoutBody)); + store.register_late_pass(|| Box::new(useless_conversion::UselessConversion::default())); + store.register_late_pass(|| Box::new(implicit_hasher::ImplicitHasher)); + store.register_late_pass(|| Box::new(fallible_impl_from::FallibleImplFrom)); + store.register_late_pass(|| Box::new(double_comparison::DoubleComparisons)); + store.register_late_pass(|| Box::new(question_mark::QuestionMark)); + store.register_early_pass(|| Box::new(suspicious_operation_groupings::SuspiciousOperationGroupings)); + store.register_late_pass(|| Box::new(suspicious_trait_impl::SuspiciousImpl)); + store.register_late_pass(|| Box::new(map_unit_fn::MapUnit)); + store.register_late_pass(|| Box::new(inherent_impl::MultipleInherentImpl)); + store.register_late_pass(|| Box::new(neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd)); + store.register_late_pass(|| Box::new(unwrap::Unwrap)); + store.register_late_pass(|| Box::new(duration_subsec::DurationSubsec)); + store.register_late_pass(|| Box::new(indexing_slicing::IndexingSlicing)); + store.register_late_pass(|| Box::new(non_copy_const::NonCopyConst)); + store.register_late_pass(|| Box::new(ptr_offset_with_cast::PtrOffsetWithCast)); + store.register_late_pass(|| Box::new(redundant_clone::RedundantClone)); + store.register_late_pass(|| Box::new(slow_vector_initialization::SlowVectorInit)); + store.register_late_pass(|| Box::new(unnecessary_sort_by::UnnecessarySortBy)); + store.register_late_pass(move || Box::new(unnecessary_wraps::UnnecessaryWraps::new(avoid_breaking_exported_api))); + store.register_late_pass(|| Box::new(assertions_on_constants::AssertionsOnConstants)); + store.register_late_pass(|| Box::new(transmuting_null::TransmutingNull)); + store.register_late_pass(|| Box::new(path_buf_push_overwrite::PathBufPushOverwrite)); + store.register_late_pass(|| Box::new(integer_division::IntegerDivision)); + store.register_late_pass(|| Box::new(inherent_to_string::InherentToString)); let max_trait_bounds = conf.max_trait_bounds; - store.register_late_pass(move || box trait_bounds::TraitBounds::new(max_trait_bounds)); - store.register_late_pass(|| box comparison_chain::ComparisonChain); - store.register_late_pass(|| box mut_key::MutableKeyType); - store.register_late_pass(|| box modulo_arithmetic::ModuloArithmetic); - store.register_early_pass(|| box reference::DerefAddrOf); - store.register_early_pass(|| box reference::RefInDeref); - store.register_early_pass(|| box double_parens::DoubleParens); - store.register_late_pass(|| box to_string_in_display::ToStringInDisplay::new()); - store.register_early_pass(|| box unsafe_removed_from_name::UnsafeNameRemoval); - store.register_early_pass(|| box if_not_else::IfNotElse); - store.register_early_pass(|| box else_if_without_else::ElseIfWithoutElse); - store.register_early_pass(|| box int_plus_one::IntPlusOne); - store.register_early_pass(|| box formatting::Formatting); - store.register_early_pass(|| box misc_early::MiscEarlyLints); - store.register_early_pass(|| box redundant_closure_call::RedundantClosureCall); - store.register_late_pass(|| box redundant_closure_call::RedundantClosureCall); - store.register_early_pass(|| box unused_unit::UnusedUnit); - store.register_late_pass(|| box returns::Return); - store.register_early_pass(|| box collapsible_if::CollapsibleIf); - store.register_early_pass(|| box items_after_statements::ItemsAfterStatements); - store.register_early_pass(|| box precedence::Precedence); - store.register_early_pass(|| box needless_continue::NeedlessContinue); - store.register_early_pass(|| box redundant_else::RedundantElse); - store.register_late_pass(|| box create_dir::CreateDir); - store.register_early_pass(|| box needless_arbitrary_self_type::NeedlessArbitrarySelfType); + store.register_late_pass(move || Box::new(trait_bounds::TraitBounds::new(max_trait_bounds))); + store.register_late_pass(|| Box::new(comparison_chain::ComparisonChain)); + store.register_late_pass(|| Box::new(mut_key::MutableKeyType)); + store.register_late_pass(|| Box::new(modulo_arithmetic::ModuloArithmetic)); + store.register_early_pass(|| Box::new(reference::DerefAddrOf)); + store.register_early_pass(|| Box::new(reference::RefInDeref)); + store.register_early_pass(|| Box::new(double_parens::DoubleParens)); + store.register_late_pass(|| Box::new(to_string_in_display::ToStringInDisplay::new())); + store.register_early_pass(|| Box::new(unsafe_removed_from_name::UnsafeNameRemoval)); + store.register_early_pass(|| Box::new(if_not_else::IfNotElse)); + store.register_early_pass(|| Box::new(else_if_without_else::ElseIfWithoutElse)); + store.register_early_pass(|| Box::new(int_plus_one::IntPlusOne)); + store.register_early_pass(|| Box::new(formatting::Formatting)); + store.register_early_pass(|| Box::new(misc_early::MiscEarlyLints)); + store.register_early_pass(|| Box::new(redundant_closure_call::RedundantClosureCall)); + store.register_late_pass(|| Box::new(redundant_closure_call::RedundantClosureCall)); + store.register_early_pass(|| Box::new(unused_unit::UnusedUnit)); + store.register_late_pass(|| Box::new(returns::Return)); + store.register_early_pass(|| Box::new(collapsible_if::CollapsibleIf)); + store.register_early_pass(|| Box::new(items_after_statements::ItemsAfterStatements)); + store.register_early_pass(|| Box::new(precedence::Precedence)); + store.register_early_pass(|| Box::new(needless_continue::NeedlessContinue)); + store.register_early_pass(|| Box::new(redundant_else::RedundantElse)); + store.register_late_pass(|| Box::new(create_dir::CreateDir)); + store.register_early_pass(|| Box::new(needless_arbitrary_self_type::NeedlessArbitrarySelfType)); let cargo_ignore_publish = conf.cargo_ignore_publish; - store.register_late_pass(move || box cargo_common_metadata::CargoCommonMetadata::new(cargo_ignore_publish)); - store.register_late_pass(|| box multiple_crate_versions::MultipleCrateVersions); - store.register_late_pass(|| box wildcard_dependencies::WildcardDependencies); + store.register_late_pass(move || Box::new(cargo_common_metadata::CargoCommonMetadata::new(cargo_ignore_publish))); + store.register_late_pass(|| Box::new(multiple_crate_versions::MultipleCrateVersions)); + store.register_late_pass(|| Box::new(wildcard_dependencies::WildcardDependencies)); let literal_representation_lint_fraction_readability = conf.unreadable_literal_lint_fractions; - store.register_early_pass(move || box literal_representation::LiteralDigitGrouping::new(literal_representation_lint_fraction_readability)); + store.register_early_pass(move || Box::new(literal_representation::LiteralDigitGrouping::new(literal_representation_lint_fraction_readability))); let literal_representation_threshold = conf.literal_representation_threshold; - store.register_early_pass(move || box literal_representation::DecimalLiteralRepresentation::new(literal_representation_threshold)); + store.register_early_pass(move || Box::new(literal_representation::DecimalLiteralRepresentation::new(literal_representation_threshold))); let enum_variant_name_threshold = conf.enum_variant_name_threshold; - store.register_late_pass(move || box enum_variants::EnumVariantNames::new(enum_variant_name_threshold, avoid_breaking_exported_api)); - store.register_early_pass(|| box tabs_in_doc_comments::TabsInDocComments); + store.register_late_pass(move || Box::new(enum_variants::EnumVariantNames::new(enum_variant_name_threshold, avoid_breaking_exported_api))); + store.register_early_pass(|| Box::new(tabs_in_doc_comments::TabsInDocComments)); let upper_case_acronyms_aggressive = conf.upper_case_acronyms_aggressive; - store.register_late_pass(move || box upper_case_acronyms::UpperCaseAcronyms::new(avoid_breaking_exported_api, upper_case_acronyms_aggressive)); - store.register_late_pass(|| box default::Default::default()); - store.register_late_pass(|| box unused_self::UnusedSelf); - store.register_late_pass(|| box mutable_debug_assertion::DebugAssertWithMutCall); - store.register_late_pass(|| box exit::Exit); - store.register_late_pass(|| box to_digit_is_some::ToDigitIsSome); + store.register_late_pass(move || Box::new(upper_case_acronyms::UpperCaseAcronyms::new(avoid_breaking_exported_api, upper_case_acronyms_aggressive))); + store.register_late_pass(|| Box::new(default::Default::default())); + store.register_late_pass(|| Box::new(unused_self::UnusedSelf)); + store.register_late_pass(|| Box::new(mutable_debug_assertion::DebugAssertWithMutCall)); + store.register_late_pass(|| Box::new(exit::Exit)); + store.register_late_pass(|| Box::new(to_digit_is_some::ToDigitIsSome)); let array_size_threshold = conf.array_size_threshold; - store.register_late_pass(move || box large_stack_arrays::LargeStackArrays::new(array_size_threshold)); - store.register_late_pass(move || box large_const_arrays::LargeConstArrays::new(array_size_threshold)); - store.register_late_pass(|| box floating_point_arithmetic::FloatingPointArithmetic); - store.register_early_pass(|| box as_conversions::AsConversions); - store.register_late_pass(|| box let_underscore::LetUnderscore); - store.register_early_pass(|| box single_component_path_imports::SingleComponentPathImports); + store.register_late_pass(move || Box::new(large_stack_arrays::LargeStackArrays::new(array_size_threshold))); + store.register_late_pass(move || Box::new(large_const_arrays::LargeConstArrays::new(array_size_threshold))); + store.register_late_pass(|| Box::new(floating_point_arithmetic::FloatingPointArithmetic)); + store.register_early_pass(|| Box::new(as_conversions::AsConversions)); + store.register_late_pass(|| Box::new(let_underscore::LetUnderscore)); + store.register_early_pass(|| Box::new(single_component_path_imports::SingleComponentPathImports)); let max_fn_params_bools = conf.max_fn_params_bools; let max_struct_bools = conf.max_struct_bools; - store.register_early_pass(move || box excessive_bools::ExcessiveBools::new(max_struct_bools, max_fn_params_bools)); - store.register_early_pass(|| box option_env_unwrap::OptionEnvUnwrap); + store.register_early_pass(move || Box::new(excessive_bools::ExcessiveBools::new(max_struct_bools, max_fn_params_bools))); + store.register_early_pass(|| Box::new(option_env_unwrap::OptionEnvUnwrap)); let warn_on_all_wildcard_imports = conf.warn_on_all_wildcard_imports; - store.register_late_pass(move || box wildcard_imports::WildcardImports::new(warn_on_all_wildcard_imports)); - store.register_late_pass(|| box verbose_file_reads::VerboseFileReads); - store.register_late_pass(|| box redundant_pub_crate::RedundantPubCrate::default()); - store.register_late_pass(|| box unnamed_address::UnnamedAddress); - store.register_late_pass(|| box dereference::Dereferencing::default()); - store.register_late_pass(|| box option_if_let_else::OptionIfLetElse); - store.register_late_pass(|| box future_not_send::FutureNotSend); - store.register_late_pass(|| box if_let_mutex::IfLetMutex); - store.register_late_pass(|| box mut_mutex_lock::MutMutexLock); - store.register_late_pass(|| box match_on_vec_items::MatchOnVecItems); - store.register_late_pass(|| box manual_async_fn::ManualAsyncFn); - store.register_late_pass(|| box vec_resize_to_zero::VecResizeToZero); - store.register_late_pass(|| box panic_in_result_fn::PanicInResultFn); + store.register_late_pass(move || Box::new(wildcard_imports::WildcardImports::new(warn_on_all_wildcard_imports))); + store.register_late_pass(|| Box::new(verbose_file_reads::VerboseFileReads)); + store.register_late_pass(|| Box::new(redundant_pub_crate::RedundantPubCrate::default())); + store.register_late_pass(|| Box::new(unnamed_address::UnnamedAddress)); + store.register_late_pass(|| Box::new(dereference::Dereferencing::default())); + store.register_late_pass(|| Box::new(option_if_let_else::OptionIfLetElse)); + store.register_late_pass(|| Box::new(future_not_send::FutureNotSend)); + store.register_late_pass(|| Box::new(if_let_mutex::IfLetMutex)); + store.register_late_pass(|| Box::new(mut_mutex_lock::MutMutexLock)); + store.register_late_pass(|| Box::new(match_on_vec_items::MatchOnVecItems)); + store.register_late_pass(|| Box::new(manual_async_fn::ManualAsyncFn)); + store.register_late_pass(|| Box::new(vec_resize_to_zero::VecResizeToZero)); + store.register_late_pass(|| Box::new(panic_in_result_fn::PanicInResultFn)); let single_char_binding_names_threshold = conf.single_char_binding_names_threshold; - store.register_early_pass(move || box non_expressive_names::NonExpressiveNames { + store.register_early_pass(move || Box::new(non_expressive_names::NonExpressiveNames { single_char_binding_names_threshold, - }); + })); let macro_matcher = conf.standard_macro_braces.iter().cloned().collect::>(); - store.register_early_pass(move || box nonstandard_macro_braces::MacroBraces::new(¯o_matcher)); - store.register_late_pass(|| box macro_use::MacroUseImports::default()); - store.register_late_pass(|| box pattern_type_mismatch::PatternTypeMismatch); - store.register_late_pass(|| box stable_sort_primitive::StableSortPrimitive); - store.register_late_pass(|| box repeat_once::RepeatOnce); - store.register_late_pass(|| box unwrap_in_result::UnwrapInResult); - store.register_late_pass(|| box self_assignment::SelfAssignment); - store.register_late_pass(|| box manual_unwrap_or::ManualUnwrapOr); - store.register_late_pass(|| box manual_ok_or::ManualOkOr); - store.register_late_pass(|| box float_equality_without_abs::FloatEqualityWithoutAbs); - store.register_late_pass(|| box semicolon_if_nothing_returned::SemicolonIfNothingReturned); - store.register_late_pass(|| box async_yields_async::AsyncYieldsAsync); + store.register_early_pass(move || Box::new(nonstandard_macro_braces::MacroBraces::new(¯o_matcher))); + store.register_late_pass(|| Box::new(macro_use::MacroUseImports::default())); + store.register_late_pass(|| Box::new(pattern_type_mismatch::PatternTypeMismatch)); + store.register_late_pass(|| Box::new(stable_sort_primitive::StableSortPrimitive)); + store.register_late_pass(|| Box::new(repeat_once::RepeatOnce)); + store.register_late_pass(|| Box::new(unwrap_in_result::UnwrapInResult)); + store.register_late_pass(|| Box::new(self_assignment::SelfAssignment)); + store.register_late_pass(|| Box::new(manual_unwrap_or::ManualUnwrapOr)); + store.register_late_pass(|| Box::new(manual_ok_or::ManualOkOr)); + store.register_late_pass(|| Box::new(float_equality_without_abs::FloatEqualityWithoutAbs)); + store.register_late_pass(|| Box::new(semicolon_if_nothing_returned::SemicolonIfNothingReturned)); + store.register_late_pass(|| Box::new(async_yields_async::AsyncYieldsAsync)); let disallowed_methods = conf.disallowed_methods.iter().cloned().collect::>(); - store.register_late_pass(move || box disallowed_method::DisallowedMethod::new(&disallowed_methods)); - store.register_early_pass(|| box asm_syntax::InlineAsmX86AttSyntax); - store.register_early_pass(|| box asm_syntax::InlineAsmX86IntelSyntax); - store.register_late_pass(|| box undropped_manually_drops::UndroppedManuallyDrops); - store.register_late_pass(|| box strings::StrToString); - store.register_late_pass(|| box strings::StringToString); - store.register_late_pass(|| box zero_sized_map_values::ZeroSizedMapValues); - store.register_late_pass(|| box vec_init_then_push::VecInitThenPush::default()); - store.register_late_pass(|| box case_sensitive_file_extension_comparisons::CaseSensitiveFileExtensionComparisons); - store.register_late_pass(|| box redundant_slicing::RedundantSlicing); - store.register_late_pass(|| box from_str_radix_10::FromStrRadix10); - store.register_late_pass(|| box manual_map::ManualMap); - store.register_late_pass(move || box if_then_some_else_none::IfThenSomeElseNone::new(msrv)); - store.register_early_pass(|| box bool_assert_comparison::BoolAssertComparison); - store.register_late_pass(|| box unused_async::UnusedAsync); + store.register_late_pass(move || Box::new(disallowed_method::DisallowedMethod::new(&disallowed_methods))); + store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86AttSyntax)); + store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86IntelSyntax)); + store.register_late_pass(|| Box::new(undropped_manually_drops::UndroppedManuallyDrops)); + store.register_late_pass(|| Box::new(strings::StrToString)); + store.register_late_pass(|| Box::new(strings::StringToString)); + store.register_late_pass(|| Box::new(zero_sized_map_values::ZeroSizedMapValues)); + store.register_late_pass(|| Box::new(vec_init_then_push::VecInitThenPush::default())); + store.register_late_pass(|| Box::new(case_sensitive_file_extension_comparisons::CaseSensitiveFileExtensionComparisons)); + store.register_late_pass(|| Box::new(redundant_slicing::RedundantSlicing)); + store.register_late_pass(|| Box::new(from_str_radix_10::FromStrRadix10)); + store.register_late_pass(|| Box::new(manual_map::ManualMap)); + store.register_late_pass(move || Box::new(if_then_some_else_none::IfThenSomeElseNone::new(msrv))); + store.register_early_pass(|| Box::new(bool_assert_comparison::BoolAssertComparison)); + store.register_late_pass(|| Box::new(unused_async::UnusedAsync)); let disallowed_types = conf.disallowed_types.iter().cloned().collect::>(); - store.register_late_pass(move || box disallowed_type::DisallowedType::new(&disallowed_types)); + store.register_late_pass(move || Box::new(disallowed_type::DisallowedType::new(&disallowed_types))); let import_renames = conf.enforced_import_renames.clone(); - store.register_late_pass(move || box missing_enforced_import_rename::ImportRename::new(import_renames.clone())); + store.register_late_pass(move || Box::new(missing_enforced_import_rename::ImportRename::new(import_renames.clone()))); let scripts = conf.allowed_scripts.clone(); - store.register_early_pass(move || box disallowed_script_idents::DisallowedScriptIdents::new(&scripts)); - store.register_late_pass(|| box strlen_on_c_strings::StrlenOnCStrings); - store.register_late_pass(move || box self_named_constructors::SelfNamedConstructors); + store.register_early_pass(move || Box::new(disallowed_script_idents::DisallowedScriptIdents::new(&scripts))); + store.register_late_pass(|| Box::new(strlen_on_c_strings::StrlenOnCStrings)); + store.register_late_pass(move || Box::new(self_named_constructors::SelfNamedConstructors)); } #[rustfmt::skip] From 485db7a3090a96a080e0188ab552be883ac1b94e Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Thu, 19 Aug 2021 13:31:25 -0500 Subject: [PATCH 0295/1222] Fix clippy let expressions fallout --- clippy_lints/src/collapsible_match.rs | 157 +++++++++++------------ clippy_lints/src/if_let_mutex.rs | 2 +- clippy_lints/src/if_let_some_result.rs | 2 +- clippy_lints/src/loops/manual_flatten.rs | 2 +- clippy_lints/src/loops/while_let_loop.rs | 2 +- clippy_lints/src/manual_map.rs | 2 +- clippy_lints/src/matches.rs | 20 +-- clippy_lints/src/option_if_let_else.rs | 2 +- clippy_lints/src/question_mark.rs | 2 +- clippy_utils/src/higher.rs | 34 ++--- clippy_utils/src/lib.rs | 4 + tests/ui/collapsible_match.rs | 5 + tests/ui/collapsible_match.stderr | 20 +-- tests/ui/collapsible_match2.stderr | 10 +- tests/ui/if_let_some_result.fixed | 9 +- tests/ui/if_let_some_result.rs | 9 +- tests/ui/if_let_some_result.stderr | 4 +- 17 files changed, 136 insertions(+), 150 deletions(-) diff --git a/clippy_lints/src/collapsible_match.rs b/clippy_lints/src/collapsible_match.rs index 6b63c2cf157a..a42eee53459e 100644 --- a/clippy_lints/src/collapsible_match.rs +++ b/clippy_lints/src/collapsible_match.rs @@ -1,9 +1,9 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::visitors::LocalUsedVisitor; -use clippy_utils::{higher, is_lang_ctor, path_to_local, peel_ref_operators, SpanlessEq}; +use clippy_utils::{higher, is_lang_ctor, is_unit_expr, path_to_local, peel_ref_operators, SpanlessEq}; use if_chain::if_chain; use rustc_hir::LangItem::OptionNone; -use rustc_hir::{Expr, ExprKind, Guard, HirId, Pat, PatKind, StmtKind}; +use rustc_hir::{Arm, Expr, ExprKind, Guard, HirId, MatchSource, Pat, PatKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{MultiSpan, Span}; @@ -49,104 +49,87 @@ declare_lint_pass!(CollapsibleMatch => [COLLAPSIBLE_MATCH]); impl<'tcx> LateLintPass<'tcx> for CollapsibleMatch { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) { - if let Some(higher::IfLet { - let_pat, - if_then, - if_else, - .. - }) = higher::IfLet::hir(expr) - { - check_arm(cx, if_then, None, let_pat, if_else); - - check_if_let(cx, if_then, let_pat); - } - - if let ExprKind::Match(_expr, arms, _source) = expr.kind { - if let Some(wild_arm) = arms.iter().rfind(|arm| is_wild_like(cx, &arm.pat.kind, &arm.guard)) { - for arm in arms { - check_arm(cx, arm.body, arm.guard.as_ref(), arm.pat, Some(wild_arm.body)); + match IfLetOrMatch::parse(cx, expr) { + Some(IfLetOrMatch::Match(_, arms, _)) => { + if let Some(els_arm) = arms.iter().rfind(|arm| arm_is_wild_like(cx, arm)) { + for arm in arms { + check_arm(cx, true, arm.pat, arm.body, arm.guard.as_ref(), Some(els_arm.body)); + } } } - - if let Some(first_arm) = arms.get(0) { - check_if_let(cx, &first_arm.body, &first_arm.pat); + Some(IfLetOrMatch::IfLet(_, pat, body, els)) => { + check_arm(cx, false, pat, body, None, els); } + None => {} } } } fn check_arm<'tcx>( cx: &LateContext<'tcx>, - outer_block: &'tcx Expr<'tcx>, - outer_guard: Option<&Guard<'tcx>>, + outer_is_match: bool, outer_pat: &'tcx Pat<'tcx>, - wild_outer_block: Option<&'tcx Expr<'tcx>>, + outer_then_body: &'tcx Expr<'tcx>, + outer_guard: Option<&'tcx Guard<'tcx>>, + outer_else_body: Option<&'tcx Expr<'tcx>> ) { - let expr = strip_singleton_blocks(outer_block); + let inner_expr = strip_singleton_blocks(outer_then_body); if_chain! { - if let ExprKind::Match(expr_in, arms_inner, _) = expr.kind; - // the outer arm pattern and the inner match - if expr_in.span.ctxt() == outer_pat.span.ctxt(); - // there must be no more than two arms in the inner match for this lint - if arms_inner.len() == 2; - // no if guards on the inner match - if arms_inner.iter().all(|arm| arm.guard.is_none()); + if let Some(inner) = IfLetOrMatch::parse(cx, inner_expr); + if let Some((inner_scrutinee, inner_then_pat, inner_else_body)) = match inner { + IfLetOrMatch::IfLet(scrutinee, pat, _, els) => Some((scrutinee, pat, els)), + IfLetOrMatch::Match(scrutinee, arms, ..) => if_chain! { + // if there are more than two arms, collapsing would be non-trivial + if arms.len() == 2 && arms.iter().all(|a| a.guard.is_none()); + // one of the arms must be "wild-like" + if let Some(wild_idx) = arms.iter().rposition(|a| arm_is_wild_like(cx, a)); + then { + let (then, els) = (&arms[1 - wild_idx], &arms[wild_idx]); + Some((scrutinee, then.pat, Some(els.body))) + } else { + None + } + }, + }; + if outer_pat.span.ctxt() == inner_scrutinee.span.ctxt(); // match expression must be a local binding // match { .. } - if let Some(binding_id) = path_to_local(peel_ref_operators(cx, expr_in)); - // one of the branches must be "wild-like" - if let Some(wild_inner_arm_idx) = arms_inner.iter().rposition(|arm_inner| is_wild_like(cx, &arm_inner.pat.kind, &arm_inner.guard)); - let (wild_inner_arm, non_wild_inner_arm) = - (&arms_inner[wild_inner_arm_idx], &arms_inner[1 - wild_inner_arm_idx]); - if !pat_contains_or(non_wild_inner_arm.pat); + if let Some(binding_id) = path_to_local(peel_ref_operators(cx, inner_scrutinee)); + if !pat_contains_or(inner_then_pat); // the binding must come from the pattern of the containing match arm // .... => match { .. } if let Some(binding_span) = find_pat_binding(outer_pat, binding_id); - // the "wild-like" branches must be equal - if wild_outer_block.map(|el| SpanlessEq::new(cx).eq_expr(wild_inner_arm.body, el)).unwrap_or(true); + // the "else" branches must be equal + if match (outer_else_body, inner_else_body) { + (None, None) => true, + (None, Some(e)) | (Some(e), None) => is_unit_expr(e), + (Some(a), Some(b)) => SpanlessEq::new(cx).eq_expr(a, b), + }; // the binding must not be used in the if guard let mut used_visitor = LocalUsedVisitor::new(cx, binding_id); - if match outer_guard { - None => true, - Some(Guard::If(expr) | Guard::IfLet(_, expr)) => !used_visitor.check_expr(expr), + if outer_guard.map_or(true, |(Guard::If(e) | Guard::IfLet(_, e))| !used_visitor.check_expr(e)); + // ...or anywhere in the inner expression + if match inner { + IfLetOrMatch::IfLet(_, _, body, els) => { + !used_visitor.check_expr(body) && els.map_or(true, |e| !used_visitor.check_expr(e)) + }, + IfLetOrMatch::Match(_, arms, ..) => !arms.iter().any(|arm| used_visitor.check_arm(arm)), }; - // ...or anywhere in the inner match - if !arms_inner.iter().any(|arm| used_visitor.check_arm(arm)); then { - span_lint_and_then( - cx, - COLLAPSIBLE_MATCH, - expr.span, - "unnecessary nested match", - |diag| { - let mut help_span = MultiSpan::from_spans(vec![binding_span, non_wild_inner_arm.pat.span]); - help_span.push_span_label(binding_span, "replace this binding".into()); - help_span.push_span_label(non_wild_inner_arm.pat.span, "with this pattern".into()); - diag.span_help(help_span, "the outer pattern can be modified to include the inner pattern"); - }, + let msg = format!( + "this `{}` can be collapsed into the outer `{}`", + if matches!(inner, IfLetOrMatch::Match(..)) { "match" } else { "if let" }, + if outer_is_match { "match" } else { "if let" }, ); - } - } -} - -fn check_if_let<'tcx>(cx: &LateContext<'tcx>, outer_expr: &'tcx Expr<'tcx>, outer_pat: &'tcx Pat<'tcx>) { - let block_inner = strip_singleton_blocks(outer_expr); - if_chain! { - if let Some(higher::IfLet { if_then: inner_if_then, let_expr: inner_let_expr, let_pat: inner_let_pat, .. }) = higher::IfLet::hir(block_inner); - if let Some(binding_id) = path_to_local(peel_ref_operators(cx, inner_let_expr)); - if let Some(binding_span) = find_pat_binding(outer_pat, binding_id); - let mut used_visitor = LocalUsedVisitor::new(cx, binding_id); - if !used_visitor.check_expr(inner_if_then); - then { span_lint_and_then( cx, COLLAPSIBLE_MATCH, - block_inner.span, - "unnecessary nested `if let` or `match`", + inner_expr.span, + &msg, |diag| { - let mut help_span = MultiSpan::from_spans(vec![binding_span, inner_let_pat.span]); + let mut help_span = MultiSpan::from_spans(vec![binding_span, inner_then_pat.span]); help_span.push_span_label(binding_span, "replace this binding".into()); - help_span.push_span_label(inner_let_pat.span, "with this pattern".into()); + help_span.push_span_label(inner_then_pat.span, "with this pattern".into()); diag.span_help(help_span, "the outer pattern can be modified to include the inner pattern"); }, ); @@ -168,14 +151,30 @@ fn strip_singleton_blocks<'hir>(mut expr: &'hir Expr<'hir>) -> &'hir Expr<'hir> expr } -/// A "wild-like" pattern is wild ("_") or `None`. -/// For this lint to apply, both the outer and inner patterns -/// must have "wild-like" branches that can be combined. -fn is_wild_like(cx: &LateContext<'_>, pat_kind: &PatKind<'_>, arm_guard: &Option>) -> bool { - if arm_guard.is_some() { +enum IfLetOrMatch<'hir> { + Match(&'hir Expr<'hir>, &'hir [Arm<'hir>], MatchSource), + /// scrutinee, pattern, then block, else block + IfLet(&'hir Expr<'hir>, &'hir Pat<'hir>, &'hir Expr<'hir>, Option<&'hir Expr<'hir>>), +} + +impl<'hir> IfLetOrMatch<'hir> { + fn parse(cx: &LateContext<'_>, expr: &Expr<'hir>) -> Option { + match expr.kind { + ExprKind::Match(expr, arms, source) => Some(Self::Match(expr, arms, source)), + _ => higher::IfLet::hir(cx, expr).map(|higher::IfLet { let_expr, let_pat, if_then, if_else }| { + Self::IfLet(let_expr, let_pat, if_then, if_else) + }) + } + } +} + +/// A "wild-like" arm has a wild (`_`) or `None` pattern and no guard. Such arms can be "collapsed" +/// into a single wild arm without any significant loss in semantics or readability. +fn arm_is_wild_like(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool { + if arm.guard.is_some() { return false; } - match pat_kind { + match arm.pat.kind { PatKind::Binding(..) | PatKind::Wild => true, PatKind::Path(ref qpath) => is_lang_ctor(cx, qpath, OptionNone), _ => false, diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index e2d3905eacb5..7dad1c31150e 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -59,7 +59,7 @@ impl<'tcx> LateLintPass<'tcx> for IfLetMutex { if_then, if_else: Some(if_else), .. - }) = higher::IfLet::hir(expr) + }) = higher::IfLet::hir(cx, expr) { op_visit.visit_expr(let_expr); if op_visit.mutex_lock_called { diff --git a/clippy_lints/src/if_let_some_result.rs b/clippy_lints/src/if_let_some_result.rs index cd813c639dbb..fb5637fcec18 100644 --- a/clippy_lints/src/if_let_some_result.rs +++ b/clippy_lints/src/if_let_some_result.rs @@ -45,7 +45,7 @@ declare_lint_pass!(OkIfLet => [IF_LET_SOME_RESULT]); impl<'tcx> LateLintPass<'tcx> for OkIfLet { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { //begin checking variables - if let Some(higher::IfLet { let_pat, let_expr, .. }) = higher::IfLet::hir(expr); + if let Some(higher::IfLet { let_pat, let_expr, .. }) = higher::IfLet::hir(cx, expr); if let ExprKind::MethodCall(_, ok_span, ref result_types, _) = let_expr.kind; //check is expr.ok() has type Result.ok(, _) if let PatKind::TupleStruct(QPath::Resolved(_, ref x), ref y, _) = let_pat.kind; //get operation if method_chain_args(let_expr, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized; diff --git a/clippy_lints/src/loops/manual_flatten.rs b/clippy_lints/src/loops/manual_flatten.rs index 9f2bc3c7ebae..5852674da578 100644 --- a/clippy_lints/src/loops/manual_flatten.rs +++ b/clippy_lints/src/loops/manual_flatten.rs @@ -37,7 +37,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(inner_expr) = inner_expr; - if let Some(higher::IfLet { let_pat, let_expr, if_else: None, .. }) = higher::IfLet::hir(inner_expr); + if let Some(higher::IfLet { let_pat, let_expr, if_else: None, .. }) = higher::IfLet::hir(cx, inner_expr); // Ensure match_expr in `if let` statement is the same as the pat from the for-loop if let PatKind::Binding(_, pat_hir_id, _, _) = pat.kind; if path_to_local_id(let_expr, pat_hir_id); diff --git a/clippy_lints/src/loops/while_let_loop.rs b/clippy_lints/src/loops/while_let_loop.rs index 6be410ca8e3c..d6d3315e0a83 100644 --- a/clippy_lints/src/loops/while_let_loop.rs +++ b/clippy_lints/src/loops/while_let_loop.rs @@ -17,7 +17,7 @@ pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &' let_expr, if_else: Some(if_else), .. - }) = higher::IfLet::hir(inner) + }) = higher::IfLet::hir(cx, inner) { if is_simple_break_expr(if_else) { could_be_while_let(cx, expr, let_pat, let_expr); diff --git a/clippy_lints/src/manual_map.rs b/clippy_lints/src/manual_map.rs index 53d97f775435..161d88414907 100644 --- a/clippy_lints/src/manual_map.rs +++ b/clippy_lints/src/manual_map.rs @@ -49,7 +49,7 @@ impl LateLintPass<'_> for ManualMap { let_expr, if_then, if_else: Some(if_else), - }) = higher::IfLet::hir(expr) + }) = higher::IfLet::hir(cx, expr) { manage_lint(cx, expr, (&let_pat.kind, if_then), (&PatKind::Wild, if_else), let_expr); } diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index a183d0c66e8c..3d0da472ddcb 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -8,9 +8,9 @@ use clippy_utils::sugg::Sugg; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item, match_type, peel_mid_ty_refs}; use clippy_utils::visitors::LocalUsedVisitor; use clippy_utils::{ - get_parent_expr, in_macro, is_expn_of, is_lang_ctor, is_lint_allowed, is_refutable, is_wild, meets_msrv, msrvs, - path_to_local, path_to_local_id, peel_hir_pat_refs, peel_n_hir_expr_refs, recurse_or_patterns, remove_blocks, - strip_pat_refs, + get_parent_expr, in_macro, is_expn_of, is_lang_ctor, is_lint_allowed, is_refutable, is_unit_expr, is_wild, + meets_msrv, msrvs, path_to_local, path_to_local_id, peel_hir_pat_refs, peel_n_hir_expr_refs, recurse_or_patterns, + remove_blocks, strip_pat_refs, }; use clippy_utils::{paths, search_same, SpanlessEq, SpanlessHash}; use core::array; @@ -634,7 +634,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches { if let ExprKind::Match(ref ex, ref arms, _) = expr.kind { check_match_ref_pats(cx, ex, arms.iter().map(|el| el.pat), expr); } - if let Some(higher::IfLet { let_pat, let_expr, .. }) = higher::IfLet::hir(expr) { + if let Some(higher::IfLet { let_pat, let_expr, .. }) = higher::IfLet::hir(cx, expr) { check_match_ref_pats(cx, let_expr, once(let_pat), expr); } } @@ -1298,7 +1298,7 @@ fn check_match_like_matches<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) let_expr, if_then, if_else: Some(if_else), - }) = higher::IfLet::hir(expr) + }) = higher::IfLet::hir(cx, expr) { return find_matches_sugg( cx, @@ -1672,14 +1672,6 @@ fn type_ranges(ranges: &[SpannedRange]) -> TypedRanges { .collect() } -fn is_unit_expr(expr: &Expr<'_>) -> bool { - match expr.kind { - ExprKind::Tup(v) if v.is_empty() => true, - ExprKind::Block(b, _) if b.stmts.is_empty() && b.expr.is_none() => true, - _ => false, - } -} - // Checks if arm has the form `None => None` fn is_none_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool { matches!(arm.pat.kind, PatKind::Path(ref qpath) if is_lang_ctor(cx, qpath, OptionNone)) @@ -1835,7 +1827,7 @@ mod redundant_pattern_match { let_pat, let_expr, .. - }) = higher::IfLet::ast(cx, expr) + }) = higher::IfLet::hir(cx, expr) { find_sugg_for_if_let(cx, expr, let_pat, let_expr, "if", if_else.is_some()) } diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index d0b0bad5eb1c..eff3d3abff80 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -125,7 +125,7 @@ fn format_option_in_sugg(cx: &LateContext<'_>, cond_expr: &Expr<'_>, as_ref: boo fn detect_option_if_let_else<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> Option { if_chain! { if !in_macro(expr.span); // Don't lint macros, because it behaves weirdly - if let Some(higher::IfLet { let_pat, let_expr, if_then, if_else: Some(if_else) }) = higher::IfLet::hir(expr); + if let Some(higher::IfLet { let_pat, let_expr, if_then, if_else: Some(if_else) }) = higher::IfLet::hir(cx, expr); if !is_else_clause(cx.tcx, expr); if !is_result_ok(cx, let_expr); // Don't lint on Result::ok because a different lint does it already if let PatKind::TupleStruct(struct_qpath, [inner_pat], _) = &let_pat.kind; diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 91085c13ac4a..7b6a0894e6d2 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -97,7 +97,7 @@ impl QuestionMark { fn check_if_let_some_and_early_return_none(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { - if let Some(higher::IfLet { let_pat, let_expr, if_then, if_else: Some(if_else) }) = higher::IfLet::hir(expr); + if let Some(higher::IfLet { let_pat, let_expr, if_then, if_else: Some(if_else) }) = higher::IfLet::hir(cx, expr); if Self::is_option(cx, let_expr); if let PatKind::TupleStruct(ref path1, fields, None) = let_pat.kind; diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index 29b698e56e3c..957ec35be6f9 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -79,15 +79,7 @@ pub struct IfLet<'hir> { } impl<'hir> IfLet<'hir> { - #[inline] - pub fn ast(cx: &LateContext<'tcx>, expr: &Expr<'hir>) -> Option { - let rslt = Self::hir(expr)?; - Self::is_not_within_while_context(cx, expr)?; - Some(rslt) - } - - #[inline] - pub const fn hir(expr: &Expr<'hir>) -> Option { + pub fn hir(cx: &LateContext<'_>, expr: &Expr<'hir>) -> Option { if let ExprKind::If( Expr { kind: ExprKind::Let(let_pat, let_expr, _), @@ -97,6 +89,14 @@ impl<'hir> IfLet<'hir> { if_else, ) = expr.kind { + let hir = cx.tcx.hir(); + let mut iter = hir.parent_iter(expr.hir_id); + if let Some((_, Node::Block(Block { stmts: [], .. }))) = iter.next() { + if let Some((_, Node::Expr(Expr { kind: ExprKind::Loop(_, _, LoopSource::While, _), .. }))) = iter.next() { + // while loop desugar + return None; + } + } return Some(Self { let_pat, let_expr, @@ -106,22 +106,6 @@ impl<'hir> IfLet<'hir> { } None } - - #[inline] - fn is_not_within_while_context(cx: &LateContext<'tcx>, expr: &Expr<'hir>) -> Option<()> { - let hir = cx.tcx.hir(); - let parent = hir.get_parent_node(expr.hir_id); - let parent_parent = hir.get_parent_node(parent); - let parent_parent_node = hir.get(parent_parent); - if let Node::Expr(Expr { - kind: ExprKind::Loop(_, _, LoopSource::While, _), - .. - }) = parent_parent_node - { - return None; - } - Some(()) - } } pub struct IfOrIfLet<'hir> { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 82bfce8fe789..7d7c3b8846c3 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -254,6 +254,10 @@ pub fn in_macro(span: Span) -> bool { } } +pub fn is_unit_expr(expr: &Expr<'_>) -> bool { + matches!(expr.kind, ExprKind::Block(Block { stmts: [], expr: None, .. }, _) | ExprKind::Tup([])) +} + /// Checks if given pattern is a wildcard (`_`) pub fn is_wild(pat: &Pat<'_>) -> bool { matches!(pat.kind, PatKind::Wild) diff --git a/tests/ui/collapsible_match.rs b/tests/ui/collapsible_match.rs index 55467cf4229d..4ce365cc7649 100644 --- a/tests/ui/collapsible_match.rs +++ b/tests/ui/collapsible_match.rs @@ -98,6 +98,11 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> } fn negative_cases(res_opt: Result, String>, res_res: Result, String>) { + while let Some(x) = make() { + if let Some(1) = x { + todo!(); + } + } // no wild pattern in outer match match res_opt { Ok(val) => match val { diff --git a/tests/ui/collapsible_match.stderr b/tests/ui/collapsible_match.stderr index f96917f58334..c119570e8abd 100644 --- a/tests/ui/collapsible_match.stderr +++ b/tests/ui/collapsible_match.stderr @@ -1,4 +1,4 @@ -error: unnecessary nested match +error: this `match` can be collapsed into the outer `match` --> $DIR/collapsible_match.rs:7:20 | LL | Ok(val) => match val { @@ -17,7 +17,7 @@ LL | Ok(val) => match val { LL | Some(n) => foo(n), | ^^^^^^^ with this pattern -error: unnecessary nested match +error: this `match` can be collapsed into the outer `match` --> $DIR/collapsible_match.rs:16:20 | LL | Ok(val) => match val { @@ -35,7 +35,7 @@ LL | Ok(val) => match val { LL | Some(n) => foo(n), | ^^^^^^^ with this pattern -error: unnecessary nested `if let` or `match` +error: this `if let` can be collapsed into the outer `if let` --> $DIR/collapsible_match.rs:25:9 | LL | / if let Some(n) = val { @@ -51,7 +51,7 @@ LL | if let Ok(val) = res_opt { LL | if let Some(n) = val { | ^^^^^^^ with this pattern -error: unnecessary nested `if let` or `match` +error: this `if let` can be collapsed into the outer `if let` --> $DIR/collapsible_match.rs:32:9 | LL | / if let Some(n) = val { @@ -69,7 +69,7 @@ LL | if let Ok(val) = res_opt { LL | if let Some(n) = val { | ^^^^^^^ with this pattern -error: unnecessary nested match +error: this `match` can be collapsed into the outer `if let` --> $DIR/collapsible_match.rs:43:9 | LL | / match val { @@ -87,7 +87,7 @@ LL | match val { LL | Some(n) => foo(n), | ^^^^^^^ with this pattern -error: unnecessary nested `if let` or `match` +error: this `if let` can be collapsed into the outer `match` --> $DIR/collapsible_match.rs:52:13 | LL | / if let Some(n) = val { @@ -103,7 +103,7 @@ LL | Ok(val) => { LL | if let Some(n) = val { | ^^^^^^^ with this pattern -error: unnecessary nested match +error: this `match` can be collapsed into the outer `if let` --> $DIR/collapsible_match.rs:61:9 | LL | / match val { @@ -121,7 +121,7 @@ LL | match val { LL | Some(n) => foo(n), | ^^^^^^^ with this pattern -error: unnecessary nested `if let` or `match` +error: this `if let` can be collapsed into the outer `match` --> $DIR/collapsible_match.rs:72:13 | LL | / if let Some(n) = val { @@ -139,7 +139,7 @@ LL | Ok(val) => { LL | if let Some(n) = val { | ^^^^^^^ with this pattern -error: unnecessary nested match +error: this `match` can be collapsed into the outer `match` --> $DIR/collapsible_match.rs:83:20 | LL | Ok(val) => match val { @@ -157,7 +157,7 @@ LL | Ok(val) => match val { LL | Some(n) => foo(n), | ^^^^^^^ with this pattern -error: unnecessary nested match +error: this `match` can be collapsed into the outer `match` --> $DIR/collapsible_match.rs:92:22 | LL | Some(val) => match val { diff --git a/tests/ui/collapsible_match2.stderr b/tests/ui/collapsible_match2.stderr index 8975b2efbaee..55e70dce208a 100644 --- a/tests/ui/collapsible_match2.stderr +++ b/tests/ui/collapsible_match2.stderr @@ -1,4 +1,4 @@ -error: unnecessary nested match +error: this `match` can be collapsed into the outer `match` --> $DIR/collapsible_match2.rs:13:34 | LL | Ok(val) if make() => match val { @@ -17,7 +17,7 @@ LL | Ok(val) if make() => match val { LL | Some(n) => foo(n), | ^^^^^^^ with this pattern -error: unnecessary nested match +error: this `match` can be collapsed into the outer `match` --> $DIR/collapsible_match2.rs:20:24 | LL | Ok(val) => match val { @@ -35,7 +35,7 @@ LL | Ok(val) => match val { LL | Some(n) => foo(n), | ^^^^^^^ with this pattern -error: unnecessary nested match +error: this `match` can be collapsed into the outer `match` --> $DIR/collapsible_match2.rs:34:29 | LL | $pat => match $e { @@ -57,7 +57,7 @@ LL | mac!(res_opt => Ok(val), val => Some(n), foo(n)); | replace this binding = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) -error: unnecessary nested match +error: this `match` can be collapsed into the outer `match` --> $DIR/collapsible_match2.rs:51:20 | LL | Some(s) => match *s { @@ -75,7 +75,7 @@ LL | Some(s) => match *s { LL | [n] => foo(n), | ^^^ with this pattern -error: unnecessary nested match +error: this `match` can be collapsed into the outer `match` --> $DIR/collapsible_match2.rs:60:24 | LL | Some(ref s) => match &*s { diff --git a/tests/ui/if_let_some_result.fixed b/tests/ui/if_let_some_result.fixed index 62a25ce2d128..1bddc47721e5 100644 --- a/tests/ui/if_let_some_result.fixed +++ b/tests/ui/if_let_some_result.fixed @@ -1,6 +1,7 @@ // run-rustfix #![warn(clippy::if_let_some_result)] +#![allow(dead_code)] fn str_to_int(x: &str) -> i32 { if let Ok(y) = x.parse() { y } else { 0 } @@ -20,8 +21,8 @@ fn strange_some_no_else(x: &str) -> i32 { } } -fn main() { - let _ = str_to_int("1"); - let _ = str_to_int_ok("2"); - let _ = strange_some_no_else("3"); +fn negative() { + while let Some(1) = "".parse().ok() {} } + +fn main() {} diff --git a/tests/ui/if_let_some_result.rs b/tests/ui/if_let_some_result.rs index 234ff5e9e80e..d4a52ec9881d 100644 --- a/tests/ui/if_let_some_result.rs +++ b/tests/ui/if_let_some_result.rs @@ -1,6 +1,7 @@ // run-rustfix #![warn(clippy::if_let_some_result)] +#![allow(dead_code)] fn str_to_int(x: &str) -> i32 { if let Some(y) = x.parse().ok() { y } else { 0 } @@ -20,8 +21,8 @@ fn strange_some_no_else(x: &str) -> i32 { } } -fn main() { - let _ = str_to_int("1"); - let _ = str_to_int_ok("2"); - let _ = strange_some_no_else("3"); +fn negative() { + while let Some(1) = "".parse().ok() {} } + +fn main() {} diff --git a/tests/ui/if_let_some_result.stderr b/tests/ui/if_let_some_result.stderr index 134ce9d24116..bc3a5e7698d7 100644 --- a/tests/ui/if_let_some_result.stderr +++ b/tests/ui/if_let_some_result.stderr @@ -1,5 +1,5 @@ error: matching on `Some` with `ok()` is redundant - --> $DIR/if_let_some_result.rs:6:5 + --> $DIR/if_let_some_result.rs:7:5 | LL | if let Some(y) = x.parse().ok() { y } else { 0 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -11,7 +11,7 @@ LL | if let Ok(y) = x.parse() { y } else { 0 } | ~~~~~~~~~~~~~~~~~~~~~~~~ error: matching on `Some` with `ok()` is redundant - --> $DIR/if_let_some_result.rs:16:9 + --> $DIR/if_let_some_result.rs:17:9 | LL | if let Some(y) = x . parse() . ok () { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 76e982d2142e820ccd4ab02b2ea73e31abb7d2ee Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sat, 21 Nov 2020 07:06:16 -0500 Subject: [PATCH 0296/1222] introduce a Coerce predicate --- clippy_utils/src/qualify_min_const_fn.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index dee9d487c78e..8e544f580665 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -36,6 +36,9 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: Option<&Ru ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate), ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate), ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate), + ty::PredicateKind::Coerce(_) => { + panic!("coerce predicate on function: {:#?}", predicate) + }, ty::PredicateKind::Trait(pred) => { if Some(pred.def_id()) == tcx.lang_items().sized_trait() { continue; From 2ec0c2ba77deca23c89f6f8d2dce0c05ba4d0a52 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 21 Aug 2021 18:07:21 +0300 Subject: [PATCH 0297/1222] cleanup: `Span::new` -> `Span::with_lo` --- clippy_lints/src/unit_return_expecting_ord.rs | 2 +- clippy_lints/src/write.rs | 2 +- clippy_utils/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index ee675838c4cb..db0f412f2a18 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -127,7 +127,7 @@ fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Spa then { let data = stmt.span.data(); // Make a span out of the semicolon for the help message - Some((span, Some(Span::new(data.hi-BytePos(1), data.hi, data.ctxt)))) + Some((span, Some(data.with_lo(data.hi-BytePos(1))))) } else { Some((span, None)) } diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 4553ac704a28..85d1f65c51f0 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -299,7 +299,7 @@ impl EarlyLintPass for Write { let nl_span = match (dest, only_nl) { // Special case of `write!(buf, "\n")`: Mark everything from the end of // `buf` for removal so no trailing comma [`writeln!(buf, )`] remains. - (Some(dest_expr), true) => Span::new(dest_expr.span.hi(), nl_span.hi(), nl_span.ctxt()), + (Some(dest_expr), true) => nl_span.with_lo(dest_expr.span.hi()), _ => nl_span, }; span_lint_and_then( diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 82bfce8fe789..0da86a76d39e 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -877,7 +877,7 @@ fn line_span(cx: &T, span: Span) -> Span { let source_map_and_line = cx.sess().source_map().lookup_line(span.lo()).unwrap(); let line_no = source_map_and_line.line; let line_start = source_map_and_line.sf.lines[line_no]; - Span::new(line_start, span.hi(), span.ctxt()) + span.with_lo(line_start) } /// Gets the parent node, if any. From e3e8800b26d8a98b5a17d3e47ddd0a7ccf678b10 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Sun, 22 Aug 2021 14:46:15 +0200 Subject: [PATCH 0298/1222] =?UTF-8?q?Fix=20typos=20=E2=80=9Ca=E2=80=9D?= =?UTF-8?q?=E2=86=92=E2=80=9Can=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clippy_lints/src/loops/manual_memcpy.rs | 2 +- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/ranges.rs | 2 +- clippy_lints/src/shadow.rs | 2 +- clippy_lints/src/utils/conf.rs | 2 +- clippy_utils/src/consts.rs | 2 +- clippy_utils/src/lib.rs | 2 +- clippy_utils/src/sugg.rs | 2 +- tests/ui/declare_interior_mutable_const/traits.rs | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index 2525b14e1c5c..2296842e86f5 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -268,7 +268,7 @@ impl std::ops::Sub<&MinifyingSugg<'static>> for MinifyingSugg<'static> { } } -/// a wrapper around `MinifyingSugg`, which carries a operator like currying +/// a wrapper around `MinifyingSugg`, which carries an operator like currying /// so that the suggested code become more efficient (e.g. `foo + -bar` `foo - bar`). struct Offset { value: MinifyingSugg<'static>, diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index aa3067876ebf..6c2563358caf 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -293,7 +293,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { }) => { if_chain! { // Lint a trait impl item only when the definition is a generic type, - // assuming a assoc const is not meant to be a interior mutable type. + // assuming an assoc const is not meant to be an interior mutable type. if let Some(of_trait_def_id) = of_trait_ref.trait_def_id(); if let Some(of_assoc_item) = specialization_graph::Node::Trait(of_trait_def_id) .item(cx.tcx, impl_item.ident, AssocKind::Const, of_trait_def_id); diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 0114a2f97a22..4fa361fedafa 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -51,7 +51,7 @@ declare_clippy_lint! { /// /// ### Known problems /// Will add unnecessary pair of parentheses when the - /// expression is not wrapped in a pair but starts with a opening parenthesis + /// expression is not wrapped in a pair but starts with an opening parenthesis /// and ends with a closing one. /// I.e., `let _ = (f()+1)..(f()+1)` results in `let _ = ((f()+1)..=f())`. /// diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index b28a37cabd40..b9e317a3cfd0 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -74,7 +74,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does /// Checks for bindings that shadow other bindings already in - /// scope, either without a initialization or with one that does not even use + /// scope, either without an initialization or with one that does not even use /// the original value. /// /// ### Why is this bad? diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index a28b1d78f7d4..c192f9094a8a 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -198,7 +198,7 @@ define_Conf! { (enum_variant_name_threshold: u64 = 3), /// Lint: LARGE_ENUM_VARIANT. /// - /// The maximum size of a enum's variant to avoid box suggestion + /// The maximum size of an enum's variant to avoid box suggestion (enum_variant_size_threshold: u64 = 200), /// Lint: VERBOSE_BIT_MASK. /// diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 15c27d1a996d..9ba1381da659 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -329,7 +329,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { vec.iter().map(|elem| self.expr(elem)).collect::>() } - /// Lookup a possibly constant expression from a `ExprKind::Path`. + /// Lookup a possibly constant expression from an `ExprKind::Path`. fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'tcx>) -> Option { let res = self.typeck_results.qpath_res(qpath, id); match res { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 82bfce8fe789..2a13b5ee3474 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -583,7 +583,7 @@ pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio /// For example, if `e` represents the `v[0].a.b[x]` /// this method will return a tuple, composed of a `Vec` /// containing the `Expr`s for `v[0], v[0].a, v[0].a.b, v[0].a.b[x]` -/// and a `Expr` for root of them, `v` +/// and an `Expr` for root of them, `v` fn projection_stack<'a, 'hir>(mut e: &'a Expr<'hir>) -> (Vec<&'a Expr<'hir>>, &'a Expr<'hir>) { let mut result = vec![]; let root = loop { diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 3b494e1fc853..65d93e8f86e4 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -434,7 +434,7 @@ pub fn make_assoc(op: AssocOp, lhs: &Sugg<'_>, rhs: &Sugg<'_>) -> Sugg<'static> matches!(op, AssocOp::ShiftLeft | AssocOp::ShiftRight) } - /// Returns `true` if the operator is a arithmetic operator + /// Returns `true` if the operator is an arithmetic operator /// (i.e., `+`, `-`, `*`, `/`, `%`). fn is_arith(op: AssocOp) -> bool { matches!( diff --git a/tests/ui/declare_interior_mutable_const/traits.rs b/tests/ui/declare_interior_mutable_const/traits.rs index 535147ccc645..256a336db821 100644 --- a/tests/ui/declare_interior_mutable_const/traits.rs +++ b/tests/ui/declare_interior_mutable_const/traits.rs @@ -117,7 +117,7 @@ impl SelfType for AtomicUsize { const WRAPPED_SELF: Option = Some(AtomicUsize::new(21)); //~ ERROR interior mutable } -// Even though a constant contains a generic type, if it also have a interior mutable type, +// Even though a constant contains a generic type, if it also have an interior mutable type, // it should be linted at the definition site. trait BothOfCellAndGeneric { // this is a false negative in the current implementation. From 1460ef67fdd8445a02348f33bac9b4ae26f8aa73 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Sun, 22 Aug 2021 17:27:18 +0200 Subject: [PATCH 0299/1222] =?UTF-8?q?Fix=20more=20=E2=80=9Ca=E2=80=9D/?= =?UTF-8?q?=E2=80=9Can=E2=80=9D=20typos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clippy_lints/src/formatting.rs | 2 +- clippy_lints/src/non_copy_const.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index b4cf1971d78d..4dd0ffe77ea4 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -164,7 +164,7 @@ fn check_unop(cx: &EarlyContext<'_>, expr: &Expr) { if !differing_macro_contexts(lhs.span, rhs.span) && !lhs.span.from_expansion(); // span between BinOp LHS and RHS let binop_span = lhs.span.between(rhs.span); - // if RHS is a UnOp + // if RHS is an UnOp if let ExprKind::Unary(op, ref un_rhs) = rhs.kind; // from UnOp operator to UnOp operand let unop_operand_span = rhs.span.until(un_rhs.span); diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 6c2563358caf..3f9110295fc6 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -122,7 +122,7 @@ fn is_unfrozen<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { // Ignore types whose layout is unknown since `is_freeze` reports every generic types as `!Freeze`, // making it indistinguishable from `UnsafeCell`. i.e. it isn't a tool to prove a type is // 'unfrozen'. However, this code causes a false negative in which - // a type contains a layout-unknown type, but also a unsafe cell like `const CELL: Cell`. + // a type contains a layout-unknown type, but also an unsafe cell like `const CELL: Cell`. // Yet, it's better than `ty.has_type_flags(TypeFlags::HAS_TY_PARAM | TypeFlags::HAS_PROJECTION)` // since it works when a pointer indirection involves (`Cell<*const T>`). // Making up a `ParamEnv` where every generic params and assoc types are `Freeze`is another option; @@ -266,7 +266,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { // in other words, lint consts whose value *could* be unfrozen, not definitely is. // This feels inconsistent with how the lint treats generic types, // which avoids linting types which potentially become unfrozen. - // One could check whether a unfrozen type have a *frozen variant* + // One could check whether an unfrozen type have a *frozen variant* // (like `body_id_opt.map_or_else(|| !has_frozen_variant(...), ...)`), // and do the same as the case of generic types at impl items. // Note that it isn't sufficient to check if it has an enum From 43a63e3d96b1030db2ac757964800700f953deae Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Sun, 22 Aug 2021 18:15:49 +0200 Subject: [PATCH 0300/1222] =?UTF-8?q?Fix=20typos=20=E2=80=9Can=E2=80=9D?= =?UTF-8?q?=E2=86=92=E2=80=9Ca=E2=80=9D=20and=20a=20few=20different=20ones?= =?UTF-8?q?=20that=20appeared=20in=20the=20same=20search?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clippy_lints/src/ptr_eq.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/ptr_eq.rs b/clippy_lints/src/ptr_eq.rs index d6d7049fb61b..3258c9fb3fed 100644 --- a/clippy_lints/src/ptr_eq.rs +++ b/clippy_lints/src/ptr_eq.rs @@ -74,7 +74,7 @@ impl LateLintPass<'_> for PtrEq { } } -// If the given expression is a cast to an usize, return the lhs of the cast +// If the given expression is a cast to a usize, return the lhs of the cast // E.g., `foo as *const _ as usize` returns `foo as *const _`. fn expr_as_cast_to_usize<'tcx>(cx: &LateContext<'tcx>, cast_expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { if cx.typeck_results().expr_ty(cast_expr) == cx.tcx.types.usize { From 9ec7e06915b35cb88a81bc1984272413db56ed72 Mon Sep 17 00:00:00 2001 From: lcnr Date: Sat, 13 Mar 2021 16:05:15 +0100 Subject: [PATCH 0301/1222] require a `tcx` for `TypeVisitor` --- clippy_lints/src/redundant_clone.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 530b3396abef..2335d2248aa9 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -14,7 +14,7 @@ use rustc_middle::mir::{ visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor as _}, Mutability, }; -use rustc_middle::ty::{self, fold::TypeVisitor, Ty}; +use rustc_middle::ty::{self, fold::TypeVisitor, Ty, TyCtxt}; use rustc_mir::dataflow::{Analysis, AnalysisDomain, GenKill, GenKillAnalysis, ResultsCursor}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::{BytePos, Span}; @@ -576,7 +576,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { self.possible_borrower.add(borrowed.local, lhs); }, other => { - if ContainsRegion + if ContainsRegion(self.cx.tcx) .visit_ty(place.ty(&self.body.local_decls, self.cx.tcx).ty) .is_continue() { @@ -625,7 +625,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { .flat_map(HybridBitSet::iter) .collect(); - if ContainsRegion.visit_ty(self.body.local_decls[*dest].ty).is_break() { + if ContainsRegion(self.cx.tcx).visit_ty(self.body.local_decls[*dest].ty).is_break() { mutable_variables.push(*dest); } @@ -701,12 +701,15 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleOriginVisitor<'a, 'tcx> { } } -struct ContainsRegion; +struct ContainsRegion<'tcx>(TyCtxt<'tcx>); -impl TypeVisitor<'_> for ContainsRegion { +impl<'tcx> TypeVisitor<'tcx> for ContainsRegion<'tcx> { type BreakTy = (); + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.0 + } - fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow { + fn visit_region(&mut self, _: ty::Region<'tcx>) -> ControlFlow { ControlFlow::BREAK } } From 61f05de2df958bb4077621d7d1a756572d39b119 Mon Sep 17 00:00:00 2001 From: lcnr Date: Tue, 16 Mar 2021 00:05:45 +0100 Subject: [PATCH 0302/1222] make unevaluated const substs optional --- clippy_lints/src/non_copy_const.rs | 6 +----- clippy_lints/src/redundant_clone.rs | 4 ++-- clippy_utils/src/consts.rs | 6 +----- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 3f9110295fc6..2a85a67fa099 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -187,11 +187,7 @@ fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: D let result = cx.tcx.const_eval_resolve( cx.param_env, - ty::Unevaluated { - def: ty::WithOptConstParam::unknown(def_id), - substs, - promoted: None, - }, + ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), None, ); is_value_unfrozen_raw(cx, result, ty) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 2335d2248aa9..f5e43264a5c6 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -705,8 +705,8 @@ struct ContainsRegion<'tcx>(TyCtxt<'tcx>); impl<'tcx> TypeVisitor<'tcx> for ContainsRegion<'tcx> { type BreakTy = (); - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.0 + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.0) } fn visit_region(&mut self, _: ty::Region<'tcx>) -> ControlFlow { diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 9ba1381da659..8bf31807d55d 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -346,11 +346,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { .tcx .const_eval_resolve( self.param_env, - ty::Unevaluated { - def: ty::WithOptConstParam::unknown(def_id), - substs, - promoted: None, - }, + ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), None, ) .ok() From 4fa9e3fa7621fd5cb76543f2d30ecade5481e93d Mon Sep 17 00:00:00 2001 From: lcnr Date: Sat, 17 Jul 2021 16:43:23 +0200 Subject: [PATCH 0303/1222] add `tcx` to `fn walk` --- clippy_lints/src/escape.rs | 4 ++-- clippy_lints/src/let_underscore.rs | 2 +- clippy_lints/src/loops/same_item_push.rs | 2 +- clippy_lints/src/methods/mod.rs | 10 +++++----- clippy_lints/src/returns.rs | 2 +- clippy_lints/src/self_named_constructors.rs | 4 ++-- clippy_lints/src/unnecessary_sort_by.rs | 2 +- clippy_lints/src/use_self.rs | 2 +- clippy_utils/src/lib.rs | 4 ++-- clippy_utils/src/qualify_min_const_fn.rs | 2 +- clippy_utils/src/ty.rs | 12 ++++++------ 11 files changed, 23 insertions(+), 23 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 8b0e9e6bc9b9..685dbf26250c 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -53,7 +53,7 @@ fn is_non_trait_box(ty: Ty<'_>) -> bool { struct EscapeDelegate<'a, 'tcx> { cx: &'a LateContext<'tcx>, set: HirIdSet, - trait_self_ty: Option>, + trait_self_ty: Option>, too_large_for_stack: u64, } @@ -171,7 +171,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { // skip if there is a `self` parameter binding to a type // that contains `Self` (i.e.: `self: Box`), see #4804 if let Some(trait_self_ty) = self.trait_self_ty { - if map.name(cmt.hir_id) == kw::SelfLower && contains_ty(cmt.place.ty(), trait_self_ty) { + if map.name(cmt.hir_id) == kw::SelfLower && contains_ty(self.cx.tcx, cmt.place.ty(), trait_self_ty) { return; } } diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index 8992d25932ca..89146b4dd2c9 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -119,7 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore { if let Some(init) = local.init; then { let init_ty = cx.typeck_results().expr_ty(init); - let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() { + let contains_sync_guard = init_ty.walk(cx.tcx).any(|inner| match inner.unpack() { GenericArgKind::Type(inner_ty) => { SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path)) }, diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index 0f6cd5de761f..545498a10478 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -49,7 +49,7 @@ pub(super) fn check<'tcx>( if same_item_push_visitor.should_lint(); if let Some((vec, pushed_item)) = same_item_push_visitor.vec_push; let vec_ty = cx.typeck_results().expr_ty(vec); - let ty = vec_ty.walk().nth(1).unwrap().expect_ty(); + let ty = vec_ty.walk(cx.tcx).nth(1).unwrap().expect_ty(); if cx .tcx .lang_items() diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 91606ed3b2bb..9626cf79dc12 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1987,10 +1987,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods { // walk the return type and check for Self (this does not check associated types) if let Some(self_adt) = self_ty.ty_adt_def() { - if contains_adt_constructor(ret_ty, self_adt) { + if contains_adt_constructor(cx.tcx, ret_ty, self_adt) { return; } - } else if contains_ty(ret_ty, self_ty) { + } else if contains_ty(cx.tcx, ret_ty, self_ty) { return; } @@ -2001,10 +2001,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() { // walk the associated type and check for Self if let Some(self_adt) = self_ty.ty_adt_def() { - if contains_adt_constructor(projection_predicate.ty, self_adt) { + if contains_adt_constructor(cx.tcx, projection_predicate.ty, self_adt) { return; } - } else if contains_ty(projection_predicate.ty, self_ty) { + } else if contains_ty(cx.tcx, projection_predicate.ty, self_ty) { return; } } @@ -2053,7 +2053,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let TraitItemKind::Fn(_, _) = item.kind; let ret_ty = return_ty(cx, item.hir_id()); let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty(); - if !contains_ty(ret_ty, self_ty); + if !contains_ty(cx.tcx, ret_ty, self_ty); then { span_lint( diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index e153288aa58d..681baed8c369 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -288,7 +288,7 @@ impl<'tcx> Visitor<'tcx> for BorrowVisitor<'_, 'tcx> { .fn_sig(def_id) .output() .skip_binder() - .walk() + .walk(self.cx.tcx) .any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_))); } diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index 4472edecbed8..4ba5e1a0f535 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -62,10 +62,10 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { // Ensure method is constructor-like if let Some(self_adt) = self_ty.ty_adt_def() { - if !contains_adt_constructor(ret_ty, self_adt) { + if !contains_adt_constructor(cx.tcx, ret_ty, self_adt) { return; } - } else if !contains_ty(ret_ty, self_ty) { + } else if !contains_ty(cx.tcx, ret_ty, self_ty) { return; } diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index 6fc5707a4eef..97b1b2dae3c1 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -218,7 +218,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { fn expr_borrows(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let ty = cx.typeck_results().expr_ty(expr); - matches!(ty.kind(), ty::Ref(..)) || ty.walk().any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_))) + matches!(ty.kind(), ty::Ref(..)) || ty.walk(cx.tcx).any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_))) } impl LateLintPass<'_> for UnnecessarySortBy { diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index a3601cca2eff..9ae50e47ca4c 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -170,7 +170,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { // // See also https://github.com/rust-lang/rust-clippy/issues/2894. for (impl_hir_ty, trait_sem_ty) in impl_inputs_outputs.zip(trait_method_sig.inputs_and_output) { - if trait_sem_ty.walk().any(|inner| inner == self_ty.into()) { + if trait_sem_ty.walk(cx.tcx).any(|inner| inner == self_ty.into()) { let mut visitor = SkipTyCollector::default(); visitor.visit_ty(impl_hir_ty); types_to_skip.extend(visitor.types_to_skip); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 32a73984674a..98f3937ba3dd 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1627,7 +1627,7 @@ pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option return Some("slice".into()), rustc_ty::Array(..) => return Some("array".into()), rustc_ty::Tuple(..) => return Some("tuple".into()), @@ -1635,7 +1635,7 @@ pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option, body: &'a Body<'tcx>, msrv: Option<&Ru } fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult { - for arg in ty.walk() { + for arg in ty.walk(tcx) { let ty = match arg.unpack() { GenericArgKind::Type(ty) => ty, diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index a2221a0b283b..3cd8ed5aa2c8 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -10,7 +10,7 @@ use rustc_hir::{TyKind, Unsafety}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::ty::subst::{GenericArg, GenericArgKind}; -use rustc_middle::ty::{self, AdtDef, IntTy, Ty, TypeFoldable, UintTy}; +use rustc_middle::ty::{self, TyCtxt, AdtDef, IntTy, Ty, TypeFoldable, UintTy}; use rustc_span::sym; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::DUMMY_SP; @@ -36,8 +36,8 @@ pub fn can_partially_move_ty(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { } /// Walks into `ty` and returns `true` if any inner type is the same as `other_ty` -pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool { - ty.walk().any(|inner| match inner.unpack() { +pub fn contains_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, other_ty: Ty<'tcx>) -> bool { + ty.walk(tcx).any(|inner| match inner.unpack() { GenericArgKind::Type(inner_ty) => ty::TyS::same_type(other_ty, inner_ty), GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false, }) @@ -45,8 +45,8 @@ pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool { /// Walks into `ty` and returns `true` if any inner type is an instance of the given adt /// constructor. -pub fn contains_adt_constructor(ty: Ty<'_>, adt: &AdtDef) -> bool { - ty.walk().any(|inner| match inner.unpack() { +pub fn contains_adt_constructor<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, adt: &'tcx AdtDef) -> bool { + ty.walk(tcx).any(|inner| match inner.unpack() { GenericArgKind::Type(inner_ty) => inner_ty.ty_adt_def() == Some(adt), GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false, }) @@ -209,7 +209,7 @@ fn is_normalizable_helper<'tcx>( .iter() .all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache)) }), - _ => ty.walk().all(|generic_arg| match generic_arg.unpack() { + _ => ty.walk(cx.tcx).all(|generic_arg| match generic_arg.unpack() { GenericArgKind::Type(inner_ty) if inner_ty != ty => { is_normalizable_helper(cx, param_env, inner_ty, cache) }, From eb50f928c91402351fadc18e1253718bd2213842 Mon Sep 17 00:00:00 2001 From: lcnr Date: Sat, 17 Jul 2021 18:48:07 +0200 Subject: [PATCH 0304/1222] update `TypeFlags` to deal with missing ct substs --- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_utils/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 5e559991c169..90b2aa168962 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -117,7 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { let fn_def_id = cx.tcx.hir().local_def_id(hir_id); let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds().iter()) - .filter(|p| !p.is_global()) + .filter(|p| !p.is_global(cx.tcx)) .filter_map(|obligation| { // Note that we do not want to deal with qualified predicates here. match obligation.predicate.kind().no_bound_vars() { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 98f3937ba3dd..ddff1686ba2c 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1581,7 +1581,7 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool { .predicates_of(did) .predicates .iter() - .filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None }); + .filter_map(|(p, _)| if p.is_global(cx.tcx) { Some(*p) } else { None }); traits::impossible_predicates( cx.tcx, traits::elaborate_predicates(cx.tcx, predicates) From 77e224b6218555be92b2494af82128e50b824f2e Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 26 Aug 2021 12:46:01 +0200 Subject: [PATCH 0305/1222] Path remapping: Make behavior of diagnostics output dependent on presence of --remap-path-prefix. --- clippy_lints/src/macro_use.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index a371f8bbd3cb..39f7ade3f81f 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -47,11 +47,8 @@ pub struct MacroRefData { impl MacroRefData { pub fn new(name: String, callee: Span, cx: &LateContext<'_>) -> Self { - let mut path = cx - .sess() - .source_map() - .span_to_filename(callee) - .prefer_local() + let sm = cx.sess().source_map(); + let mut path = sm.filename_for_diagnostics(&sm.span_to_filename(callee)) .to_string(); // std lib paths are <::std::module::file type> From 1a86c49fa2987fe6a3c9c8d27c4441b3309ecaa1 Mon Sep 17 00:00:00 2001 From: inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Date: Fri, 30 Jul 2021 23:50:57 -0700 Subject: [PATCH 0306/1222] Treat macros as HIR items --- clippy_lints/src/missing_doc.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index d358e9fb876a..da86d28ee0b2 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -123,6 +123,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { hir::ItemKind::Const(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Mod(..) + | hir::ItemKind::Macro(..) | hir::ItemKind::Static(..) | hir::ItemKind::Struct(..) | hir::ItemKind::Trait(..) From aea9e43f70aa95d23992978b65c80e6a7eab77b0 Mon Sep 17 00:00:00 2001 From: inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Date: Thu, 5 Aug 2021 16:58:46 -0700 Subject: [PATCH 0307/1222] Teach tools that macros are now HIR items --- clippy_lints/src/missing_doc.rs | 2 +- clippy_lints/src/missing_inline.rs | 1 + clippy_lints/src/utils/inspector.rs | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index da86d28ee0b2..940eee7a7889 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -122,8 +122,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { }, hir::ItemKind::Const(..) | hir::ItemKind::Enum(..) - | hir::ItemKind::Mod(..) | hir::ItemKind::Macro(..) + | hir::ItemKind::Mod(..) | hir::ItemKind::Static(..) | hir::ItemKind::Struct(..) | hir::ItemKind::Trait(..) diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 977e6d966e87..667cdd830252 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -118,6 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { }, hir::ItemKind::Const(..) | hir::ItemKind::Enum(..) + | hir::ItemKind::Macro(..) | hir::ItemKind::Mod(..) | hir::ItemKind::Static(..) | hir::ItemKind::Struct(..) diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 6bf216cec167..e97983a2e145 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -381,6 +381,13 @@ fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) { let item_ty = cx.tcx.type_of(did); println!("function of type {:#?}", item_ty); }, + hir::ItemKind::Macro(ref macro_def) => { + if macro_def.macro_rules { + println!("macro introduced by `macro_rules!`"); + } else { + println!("macro introduced by `macro`"); + } + }, hir::ItemKind::Mod(..) => println!("module"), hir::ItemKind::ForeignMod { abi, .. } => println!("foreign module with abi: {}", abi), hir::ItemKind::GlobalAsm(asm) => println!("global asm: {:?}", asm), From 738b920150fc9ddce812f36321941f12bed245c4 Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 25 Aug 2021 10:21:39 +0100 Subject: [PATCH 0308/1222] rename const_evaluatable_checked to generic_const_exprs :sparkles: --- tests/ui/doc/doc.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/doc/doc.rs b/tests/ui/doc/doc.rs index 8afef6b23d47..8b20997fdf8d 100644 --- a/tests/ui/doc/doc.rs +++ b/tests/ui/doc/doc.rs @@ -2,7 +2,7 @@ #![allow(dead_code, incomplete_features)] #![warn(clippy::doc_markdown)] -#![feature(custom_inner_attributes, const_generics, const_evaluatable_checked, const_option)] +#![feature(custom_inner_attributes, const_generics, generic_const_exprs, const_option)] #![rustfmt::skip] /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) @@ -203,7 +203,7 @@ fn issue_2343() {} /// __|_ _|__||_| fn pulldown_cmark_crash() {} -// issue #7033 - const_evaluatable_checked ICE +// issue #7033 - generic_const_exprs ICE struct S where [(); N.checked_next_power_of_two().unwrap()]: { arr: [T; N.checked_next_power_of_two().unwrap()], From b9cee2f763cf22d8b9aaf9aeac542e82a5b72328 Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 27 Aug 2021 18:04:57 +0200 Subject: [PATCH 0309/1222] `feature(const_generics)` -> `feature(const_param_types)` --- tests/ui/crashes/ice-4775.rs | 3 --- tests/ui/crashes/ice-5223.rs | 3 --- tests/ui/doc/doc.rs | 2 +- tests/ui/missing_const_for_fn/cant_be_const.rs | 3 +-- .../ui/missing_const_for_fn/could_be_const.rs | 1 - .../missing_const_for_fn/could_be_const.stderr | 18 +++++++++--------- 6 files changed, 11 insertions(+), 19 deletions(-) diff --git a/tests/ui/crashes/ice-4775.rs b/tests/ui/crashes/ice-4775.rs index 31e53e846d54..405e3039e7d0 100644 --- a/tests/ui/crashes/ice-4775.rs +++ b/tests/ui/crashes/ice-4775.rs @@ -1,6 +1,3 @@ -#![feature(const_generics)] -#![allow(incomplete_features)] - pub struct ArrayWrapper([usize; N]); impl ArrayWrapper<{ N }> { diff --git a/tests/ui/crashes/ice-5223.rs b/tests/ui/crashes/ice-5223.rs index 9bb2e227fc12..e3b3b27a6fc3 100644 --- a/tests/ui/crashes/ice-5223.rs +++ b/tests/ui/crashes/ice-5223.rs @@ -1,7 +1,4 @@ // Regression test for #5233 - -#![feature(const_generics)] -#![allow(incomplete_features)] #![warn(clippy::indexing_slicing, clippy::iter_cloned_collect)] pub struct KotomineArray { diff --git a/tests/ui/doc/doc.rs b/tests/ui/doc/doc.rs index 8b20997fdf8d..8b0c0f304fce 100644 --- a/tests/ui/doc/doc.rs +++ b/tests/ui/doc/doc.rs @@ -2,7 +2,7 @@ #![allow(dead_code, incomplete_features)] #![warn(clippy::doc_markdown)] -#![feature(custom_inner_attributes, const_generics, generic_const_exprs, const_option)] +#![feature(custom_inner_attributes, generic_const_exprs, const_option)] #![rustfmt::skip] /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) diff --git a/tests/ui/missing_const_for_fn/cant_be_const.rs b/tests/ui/missing_const_for_fn/cant_be_const.rs index 6d2cbb6ad96f..aa60d0504e5e 100644 --- a/tests/ui/missing_const_for_fn/cant_be_const.rs +++ b/tests/ui/missing_const_for_fn/cant_be_const.rs @@ -5,8 +5,7 @@ // aux-build:helper.rs #![warn(clippy::missing_const_for_fn)] -#![allow(incomplete_features)] -#![feature(start, const_generics)] +#![feature(start)] #![feature(custom_inner_attributes)] extern crate helper; diff --git a/tests/ui/missing_const_for_fn/could_be_const.rs b/tests/ui/missing_const_for_fn/could_be_const.rs index 0accb516f5f6..baa7eec05462 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.rs +++ b/tests/ui/missing_const_for_fn/could_be_const.rs @@ -1,6 +1,5 @@ #![warn(clippy::missing_const_for_fn)] #![allow(incomplete_features, clippy::let_and_return)] -#![feature(const_generics)] #![feature(custom_inner_attributes)] use std::mem::transmute; diff --git a/tests/ui/missing_const_for_fn/could_be_const.stderr b/tests/ui/missing_const_for_fn/could_be_const.stderr index 63c211f39fa1..b89cc6451bb5 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.stderr +++ b/tests/ui/missing_const_for_fn/could_be_const.stderr @@ -1,5 +1,5 @@ error: this could be a `const fn` - --> $DIR/could_be_const.rs:14:5 + --> $DIR/could_be_const.rs:13:5 | LL | / pub fn new() -> Self { LL | | Self { guess: 42 } @@ -9,7 +9,7 @@ LL | | } = note: `-D clippy::missing-const-for-fn` implied by `-D warnings` error: this could be a `const fn` - --> $DIR/could_be_const.rs:18:5 + --> $DIR/could_be_const.rs:17:5 | LL | / fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] { LL | | b @@ -17,7 +17,7 @@ LL | | } | |_____^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:24:1 + --> $DIR/could_be_const.rs:23:1 | LL | / fn one() -> i32 { LL | | 1 @@ -25,7 +25,7 @@ LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:29:1 + --> $DIR/could_be_const.rs:28:1 | LL | / fn two() -> i32 { LL | | let abc = 2; @@ -34,7 +34,7 @@ LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:35:1 + --> $DIR/could_be_const.rs:34:1 | LL | / fn string() -> String { LL | | String::new() @@ -42,7 +42,7 @@ LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:40:1 + --> $DIR/could_be_const.rs:39:1 | LL | / unsafe fn four() -> i32 { LL | | 4 @@ -50,7 +50,7 @@ LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:45:1 + --> $DIR/could_be_const.rs:44:1 | LL | / fn generic(t: T) -> T { LL | | t @@ -58,7 +58,7 @@ LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:68:9 + --> $DIR/could_be_const.rs:67:9 | LL | / pub fn b(self, a: &A) -> B { LL | | B @@ -66,7 +66,7 @@ LL | | } | |_________^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:78:5 + --> $DIR/could_be_const.rs:77:5 | LL | / fn const_fn_stabilized_before_msrv(byte: u8) { LL | | byte.is_ascii_digit(); From ae3f5ac8a89fb16dbc0f6006694de03af62adcbf Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sun, 25 Jul 2021 18:27:44 -0500 Subject: [PATCH 0310/1222] Fix clippy for let-else --- clippy_lints/src/non_expressive_names.rs | 7 +++++-- clippy_utils/src/ast_utils.rs | 12 +++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index ac21eb5275f0..2ffc00b449d0 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -316,8 +316,11 @@ impl<'a, 'b> SimilarNamesLocalVisitor<'a, 'b> { impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> { fn visit_local(&mut self, local: &'tcx Local) { - if let Some(ref init) = local.init { - self.apply(|this| walk_expr(this, &**init)); + if let Some((init, els)) = &local.kind.init_else_opt() { + self.apply(|this| walk_expr(this, init)); + if let Some(els) = els { + self.apply(|this| walk_block(this, els)); + } } // add the pattern after the expression because the bindings aren't available // yet in the init diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 7ea07a15aea5..133f6c29f7d2 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -221,7 +221,7 @@ pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool { (Local(l), Local(r)) => { eq_pat(&l.pat, &r.pat) && both(&l.ty, &r.ty, |l, r| eq_ty(l, r)) - && eq_expr_opt(&l.init, &r.init) + && eq_local_kind(&l.kind, &r.kind) && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)) }, (Item(l), Item(r)) => eq_item(l, r, eq_item_kind), @@ -234,6 +234,16 @@ pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool { } } +pub fn eq_local_kind(l: &LocalKind, r: &LocalKind) -> bool { + use LocalKind::*; + match (l, r) { + (Decl, Decl) => true, + (Init(l), Init(r)) => eq_expr(l, r), + (InitElse(li, le), InitElse(ri, re)) => eq_expr(li, ri) && eq_block(le, re), + _ => false, + } +} + pub fn eq_item(l: &Item, r: &Item, mut eq_kind: impl FnMut(&K, &K) -> bool) -> bool { eq_id(l.ident, r.ident) && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)) From dab48179a4e788db49fdb74098f95e17918409cb Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 30 Aug 2021 17:38:27 +0300 Subject: [PATCH 0311/1222] rustc_target: move `LayoutOf` to `ty::layout`. --- clippy_lints/src/casts/cast_ptr_alignment.rs | 2 +- clippy_lints/src/escape.rs | 5 +++-- clippy_lints/src/invalid_upcast_comparisons.rs | 2 +- clippy_lints/src/large_const_arrays.rs | 2 +- clippy_lints/src/large_enum_variant.rs | 2 +- clippy_lints/src/large_stack_arrays.rs | 3 +-- clippy_lints/src/methods/manual_saturating_arithmetic.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/types/vec_box.rs | 2 +- clippy_lints/src/vec.rs | 2 +- clippy_lints/src/zero_sized_map_values.rs | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index 62a119d662bb..5dcf1824ef0b 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -3,9 +3,9 @@ use clippy_utils::is_hir_ty_cfg_dependant; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind, GenericArg}; use rustc_lint::LateContext; +use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, Ty}; use rustc_span::symbol::sym; -use rustc_target::abi::LayoutOf; use super::CAST_PTR_ALIGNMENT; diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 685dbf26250c..1ba241d37761 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -5,11 +5,11 @@ use rustc_hir::{self, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKi use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::FakeReadCause; +use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, TraitRef, Ty}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; use rustc_span::symbol::kw; -use rustc_target::abi::LayoutOf; use rustc_target::spec::abi::Abi; use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; @@ -171,7 +171,8 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { // skip if there is a `self` parameter binding to a type // that contains `Self` (i.e.: `self: Box`), see #4804 if let Some(trait_self_ty) = self.trait_self_ty { - if map.name(cmt.hir_id) == kw::SelfLower && contains_ty(self.cx.tcx, cmt.place.ty(), trait_self_ty) { + if map.name(cmt.hir_id) == kw::SelfLower && contains_ty(self.cx.tcx, cmt.place.ty(), trait_self_ty) + { return; } } diff --git a/clippy_lints/src/invalid_upcast_comparisons.rs b/clippy_lints/src/invalid_upcast_comparisons.rs index 3b28b1212048..b1f70b30c12c 100644 --- a/clippy_lints/src/invalid_upcast_comparisons.rs +++ b/clippy_lints/src/invalid_upcast_comparisons.rs @@ -2,10 +2,10 @@ use std::cmp::Ordering; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, IntTy, UintTy}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Span; -use rustc_target::abi::LayoutOf; use clippy_utils::comparisons::Rel; use clippy_utils::consts::{constant, Constant}; diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index 5d4e06c2af08..10281496c11c 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -1,10 +1,10 @@ -use crate::rustc_target::abi::LayoutOf; use clippy_utils::diagnostics::span_lint_and_then; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::interpret::ConstValue; +use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, ConstKind}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{BytePos, Pos, Span}; diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index cde2336b690f..e4b8e7546283 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -6,8 +6,8 @@ use rustc_errors::Applicability; use rustc_hir::{Item, ItemKind, VariantData}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; +use rustc_middle::ty::layout::LayoutOf; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_target::abi::LayoutOf; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index 7088630bfdbb..bbb6c1f902ce 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -4,11 +4,10 @@ use if_chain::if_chain; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::interpret::ConstValue; +use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, ConstKind}; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use crate::rustc_target::abi::LayoutOf; - declare_clippy_lint! { /// ### What it does /// Checks for local arrays that may be too large. diff --git a/clippy_lints/src/methods/manual_saturating_arithmetic.rs b/clippy_lints/src/methods/manual_saturating_arithmetic.rs index 2fddea7068d9..7ecafa1f3ba5 100644 --- a/clippy_lints/src/methods/manual_saturating_arithmetic.rs +++ b/clippy_lints/src/methods/manual_saturating_arithmetic.rs @@ -6,7 +6,7 @@ use rustc_ast::ast; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; -use rustc_target::abi::LayoutOf; +use rustc_middle::ty::layout::LayoutOf; pub fn check( cx: &LateContext<'_>, diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 157b18c1f6b1..6229b9608b3c 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -13,10 +13,10 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{BindingAnnotation, Body, FnDecl, HirId, Impl, ItemKind, MutTy, Mutability, Node, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; +use rustc_middle::ty::layout::LayoutOf; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::def_id::LocalDefId; use rustc_span::{sym, Span}; -use rustc_target::abi::LayoutOf; use rustc_target::spec::abi::Abi; use rustc_target::spec::Target; diff --git a/clippy_lints/src/types/vec_box.rs b/clippy_lints/src/types/vec_box.rs index 7a444174626f..e7e2016d8f2f 100644 --- a/clippy_lints/src/types/vec_box.rs +++ b/clippy_lints/src/types/vec_box.rs @@ -5,9 +5,9 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{self as hir, def_id::DefId, GenericArg, QPath, TyKind}; use rustc_lint::LateContext; +use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::TypeFoldable; use rustc_span::symbol::sym; -use rustc_target::abi::LayoutOf; use rustc_typeck::hir_ty_to_ty; use super::VEC_BOX; diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index 95a45fa937f1..e76d5f81c964 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -1,4 +1,3 @@ -use crate::rustc_target::abi::LayoutOf; use clippy_utils::consts::{constant, Constant}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::higher; @@ -8,6 +7,7 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability}; use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 2fbe27f94798..8e1cd655b611 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -3,10 +3,10 @@ use clippy_utils::ty::{is_normalizable, is_type_diagnostic_item}; use if_chain::if_chain; use rustc_hir::{self as hir, HirId, ItemKind, Node}; use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::{Adt, Ty, TypeFoldable}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; -use rustc_target::abi::LayoutOf as _; use rustc_typeck::hir_ty_to_ty; declare_clippy_lint! { From ca4b8b38b9cec50ffa5f1eb1d1fba02fe89900ff Mon Sep 17 00:00:00 2001 From: yukang Date: Sat, 4 Sep 2021 19:26:25 +0800 Subject: [PATCH 0312/1222] Fix #88256, remove duplicated diagnostic --- tests/ui/match_same_arms.stderr | 20 +------------------ tests/ui/modulo_one.stderr | 8 +------- .../ui/suspicious_operation_groupings.stderr | 8 +------- 3 files changed, 3 insertions(+), 33 deletions(-) diff --git a/tests/ui/match_same_arms.stderr b/tests/ui/match_same_arms.stderr index e48451acfe8f..7752a8a6ff2b 100644 --- a/tests/ui/match_same_arms.stderr +++ b/tests/ui/match_same_arms.stderr @@ -106,24 +106,6 @@ LL | 1 => 2, | ^ = help: ...or consider changing the match arm bodies -error: this `match` has identical arm bodies - --> $DIR/match_same_arms.rs:33:14 - | -LL | 3 => 2, //~ ERROR 3rd matched arms have same body - | ^ - | -note: same as this - --> $DIR/match_same_arms.rs:32:14 - | -LL | 2 => 2, //~ ERROR 2nd matched arms have same body - | ^ -help: consider refactoring into `2 | 3` - --> $DIR/match_same_arms.rs:32:9 - | -LL | 2 => 2, //~ ERROR 2nd matched arms have same body - | ^ - = help: ...or consider changing the match arm bodies - error: this `match` has identical arm bodies --> $DIR/match_same_arms.rs:50:55 | @@ -142,5 +124,5 @@ LL | CommandInfo::BuiltIn { name, .. } => name.to_string(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: ...or consider changing the match arm bodies -error: aborting due to 8 previous errors +error: aborting due to 7 previous errors diff --git a/tests/ui/modulo_one.stderr b/tests/ui/modulo_one.stderr index 2b2c69973385..34f762bbb923 100644 --- a/tests/ui/modulo_one.stderr +++ b/tests/ui/modulo_one.stderr @@ -46,12 +46,6 @@ LL | const ONE: u32 = 1 * 1; | = note: `-D clippy::identity-op` implied by `-D warnings` -error: the operation is ineffective. Consider reducing it to `1` - --> $DIR/modulo_one.rs:13:22 - | -LL | const ONE: u32 = 1 * 1; - | ^^^^^ - error: any number modulo 1 will be 0 --> $DIR/modulo_one.rs:17:5 | @@ -70,5 +64,5 @@ error: any number modulo -1 will panic/overflow or result in 0 LL | INT_MIN % NEG_ONE; // also caught by rustc | ^^^^^^^^^^^^^^^^^ -error: aborting due to 11 previous errors +error: aborting due to 10 previous errors diff --git a/tests/ui/suspicious_operation_groupings.stderr b/tests/ui/suspicious_operation_groupings.stderr index 96065699d321..dd6f2f6641d6 100644 --- a/tests/ui/suspicious_operation_groupings.stderr +++ b/tests/ui/suspicious_operation_groupings.stderr @@ -6,12 +6,6 @@ LL | self.x == other.y && self.y == other.y && self.z == other.z | = note: `-D clippy::suspicious-operation-groupings` implied by `-D warnings` -error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:14:9 - | -LL | self.x == other.y && self.y == other.y && self.z == other.z - | ^^^^^^^^^^^^^^^^^ help: did you mean: `self.x == other.x` - error: this sequence of operators looks suspiciously like a bug --> $DIR/suspicious_operation_groupings.rs:27:20 | @@ -162,5 +156,5 @@ error: this sequence of operators looks suspiciously like a bug LL | -(if -s1.a < -s2.a && -s1.a < -s2.b { s1.c } else { s2.a }) | ^^^^^^^^^^^^^ help: did you mean: `-s1.b < -s2.b` -error: aborting due to 27 previous errors +error: aborting due to 26 previous errors From b1d9973212aa620051ae0ff6fdccbcf641400e51 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 6 Sep 2021 23:30:04 -0700 Subject: [PATCH 0313/1222] fix(clippy): update loop lints to use arg.span Adapts clippy for fe1a7f71fbf3cf845a09a9b333a6adcf7e839607 --- clippy_lints/src/loops/for_kv_map.rs | 3 +-- clippy_lints/src/loops/iter_next_loop.rs | 4 ++-- clippy_lints/src/loops/mod.rs | 8 ++++---- clippy_lints/src/loops/needless_range_loop.rs | 4 ++-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/loops/for_kv_map.rs b/clippy_lints/src/loops/for_kv_map.rs index 82bf49f5b49a..e2f2e770fc25 100644 --- a/clippy_lints/src/loops/for_kv_map.rs +++ b/clippy_lints/src/loops/for_kv_map.rs @@ -15,7 +15,6 @@ pub(super) fn check<'tcx>( pat: &'tcx Pat<'_>, arg: &'tcx Expr<'_>, body: &'tcx Expr<'_>, - expr: &'tcx Expr<'_>, ) { let pat_span = pat.span; @@ -43,7 +42,7 @@ pub(super) fn check<'tcx>( span_lint_and_then( cx, FOR_KV_MAP, - expr.span, + arg_span, &format!("you seem to want to iterate on a map's {}s", kind), |diag| { let map = sugg::Sugg::hir(cx, arg, "map"); diff --git a/clippy_lints/src/loops/iter_next_loop.rs b/clippy_lints/src/loops/iter_next_loop.rs index 9148fbfd497a..e640c62ebdac 100644 --- a/clippy_lints/src/loops/iter_next_loop.rs +++ b/clippy_lints/src/loops/iter_next_loop.rs @@ -5,12 +5,12 @@ use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_span::sym; -pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>, expr: &Expr<'_>) -> bool { +pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>) -> bool { if is_trait_method(cx, arg, sym::Iterator) { span_lint( cx, ITER_NEXT_LOOP, - expr.span, + arg.span, "you are iterating over `Iterator::next()` which is an Option; this will compile but is \ probably not what you want", ); diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index bd9de5e08d73..86bce75bdb2d 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -601,15 +601,15 @@ fn check_for_loop<'tcx>( needless_range_loop::check(cx, pat, arg, body, expr); explicit_counter_loop::check(cx, pat, arg, body, expr); } - check_for_loop_arg(cx, pat, arg, expr); - for_kv_map::check(cx, pat, arg, body, expr); + check_for_loop_arg(cx, pat, arg); + for_kv_map::check(cx, pat, arg, body); mut_range_bound::check(cx, arg, body); single_element_loop::check(cx, pat, arg, body, expr); same_item_push::check(cx, pat, arg, body, expr); manual_flatten::check(cx, pat, arg, body, span); } -fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, expr: &Expr<'_>) { +fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) { let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used if let ExprKind::MethodCall(method, _, [self_arg], _) = arg.kind { @@ -622,7 +622,7 @@ fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, expr: explicit_into_iter_loop::check(cx, self_arg, arg); }, "next" => { - next_loop_linted = iter_next_loop::check(cx, arg, expr); + next_loop_linted = iter_next_loop::check(cx, arg); }, _ => {}, } diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 3f77e7af927a..bdb042421e9c 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -146,7 +146,7 @@ pub(super) fn check<'tcx>( span_lint_and_then( cx, NEEDLESS_RANGE_LOOP, - expr.span, + arg.span, &format!("the loop variable `{}` is used to index `{}`", ident.name, indexed), |diag| { multispan_sugg( @@ -172,7 +172,7 @@ pub(super) fn check<'tcx>( span_lint_and_then( cx, NEEDLESS_RANGE_LOOP, - expr.span, + arg.span, &format!("the loop variable `{}` is only used to index `{}`", ident.name, indexed), |diag| { multispan_sugg( From 1afdcbe056b6ddf54343ca0abfa95540adf65109 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 5 Jan 2021 19:53:07 +0100 Subject: [PATCH 0314/1222] Move the dataflow framework to its own crate. --- clippy_lints/src/lib.rs | 2 +- clippy_lints/src/redundant_clone.rs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 19719502870b..3c6faf117fde 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -31,7 +31,7 @@ extern crate rustc_infer; extern crate rustc_lexer; extern crate rustc_lint; extern crate rustc_middle; -extern crate rustc_mir; +extern crate rustc_mir_dataflow; extern crate rustc_parse; extern crate rustc_parse_format; extern crate rustc_session; diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index f5e43264a5c6..7041e4f980ef 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -15,7 +15,7 @@ use rustc_middle::mir::{ Mutability, }; use rustc_middle::ty::{self, fold::TypeVisitor, Ty, TyCtxt}; -use rustc_mir::dataflow::{Analysis, AnalysisDomain, GenKill, GenKillAnalysis, ResultsCursor}; +use rustc_mir_dataflow::{Analysis, AnalysisDomain, GenKill, GenKillAnalysis, ResultsCursor}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::{BytePos, Span}; use rustc_span::sym; @@ -625,7 +625,10 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { .flat_map(HybridBitSet::iter) .collect(); - if ContainsRegion(self.cx.tcx).visit_ty(self.body.local_decls[*dest].ty).is_break() { + if ContainsRegion(self.cx.tcx) + .visit_ty(self.body.local_decls[*dest].ty) + .is_break() + { mutable_variables.push(*dest); } From 9ba2c5a58e1715a487759a6327eee77f472b79c3 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 5 Jan 2021 20:08:11 +0100 Subject: [PATCH 0315/1222] Rename rustc_mir to rustc_const_eval. --- clippy_utils/src/lib.rs | 2 +- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index ddff1686ba2c..0906f958cfb1 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -17,6 +17,7 @@ extern crate rustc_ast; extern crate rustc_ast_pretty; extern crate rustc_attr; +extern crate rustc_const_eval; extern crate rustc_data_structures; extern crate rustc_errors; extern crate rustc_hir; @@ -24,7 +25,6 @@ extern crate rustc_infer; extern crate rustc_lexer; extern crate rustc_lint; extern crate rustc_middle; -extern crate rustc_mir; extern crate rustc_session; extern crate rustc_span; extern crate rustc_target; diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index e5bbf75c3b0a..4fb9e6b07e71 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -366,7 +366,7 @@ fn check_terminator( } fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<&RustcVersion>) -> bool { - rustc_mir::const_eval::is_const_fn(tcx, def_id) + rustc_const_eval::const_eval::is_const_fn(tcx, def_id) && tcx.lookup_const_stability(def_id).map_or(true, |const_stab| { if let rustc_attr::StabilityLevel::Stable { since } = const_stab.level { // Checking MSRV is manually necessary because `rustc` has no such concept. This entire From 8f54b5cce82a777f8f8f7986de13f4075829ad53 Mon Sep 17 00:00:00 2001 From: "Samuel E. Moelius III" Date: Wed, 1 Sep 2021 18:31:42 -0400 Subject: [PATCH 0316/1222] Prep for upgrade to cargo_metadata 0.14.0 --- clippy_lints/src/cargo_common_metadata.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/cargo_common_metadata.rs b/clippy_lints/src/cargo_common_metadata.rs index bd5426ba707a..162911b77d61 100644 --- a/clippy_lints/src/cargo_common_metadata.rs +++ b/clippy_lints/src/cargo_common_metadata.rs @@ -1,7 +1,5 @@ //! lint on missing cargo common metadata -use std::path::PathBuf; - use clippy_utils::{diagnostics::span_lint, is_lint_allowed}; use rustc_hir::{hir_id::CRATE_HIR_ID, Crate}; use rustc_lint::{LateContext, LateLintPass}; @@ -69,12 +67,8 @@ fn missing_warning(cx: &LateContext<'_>, package: &cargo_metadata::Package, fiel span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, &message); } -fn is_empty_str(value: &Option) -> bool { - value.as_ref().map_or(true, String::is_empty) -} - -fn is_empty_path(value: &Option) -> bool { - value.as_ref().and_then(|x| x.to_str()).map_or(true, str::is_empty) +fn is_empty_str>(value: &Option) -> bool { + value.as_ref().map_or(true, |s| s.as_ref().is_empty()) } fn is_empty_vec(value: &[String]) -> bool { @@ -98,7 +92,7 @@ impl LateLintPass<'_> for CargoCommonMetadata { missing_warning(cx, &package, "package.description"); } - if is_empty_str(&package.license) && is_empty_path(&package.license_file) { + if is_empty_str(&package.license) && is_empty_str(&package.license_file) { missing_warning(cx, &package, "either package.license or package.license_file"); } @@ -106,7 +100,7 @@ impl LateLintPass<'_> for CargoCommonMetadata { missing_warning(cx, &package, "package.repository"); } - if is_empty_path(&package.readme) { + if is_empty_str(&package.readme) { missing_warning(cx, &package, "package.readme"); } From a0c041726a01789778af8e74263734c71b98ff94 Mon Sep 17 00:00:00 2001 From: "Samuel E. Moelius III" Date: Thu, 9 Sep 2021 05:19:03 -0400 Subject: [PATCH 0317/1222] Update dependencies --- Cargo.toml | 22 ++++++++++------------ clippy_dev/Cargo.toml | 6 +++--- clippy_dummy/Cargo.toml | 2 +- clippy_lints/Cargo.toml | 14 +++++++------- clippy_utils/Cargo.toml | 4 ++-- lintcheck/Cargo.toml | 18 +++++++++--------- 6 files changed, 32 insertions(+), 34 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2310370fb9fb..40aaa5924df5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,37 +21,35 @@ name = "clippy-driver" path = "src/driver.rs" [dependencies] -# begin automatic update -clippy_lints = { version = "0.1.50", path = "clippy_lints" } -# end automatic update +clippy_lints = { version = "0.1", path = "clippy_lints" } semver = "0.11" -rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util" } -tempfile = { version = "3.1.0", optional = true } +rustc_tools_util = { version = "0.2", path = "rustc_tools_util" } +tempfile = { version = "3.2", optional = true } [dev-dependencies] cargo_metadata = "0.12" -compiletest_rs = { version = "0.6.0", features = ["tmp"] } +compiletest_rs = { version = "0.7", features = ["tmp"] } tester = "0.9" -regex = "1.4" +regex = "1.5" # 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.0" +rustc-workspace-hack = "1.0" # UI test dependencies clippy_utils = { path = "clippy_utils" } derive-new = "0.5" if_chain = "1.0" -itertools = "0.10.1" -quote = "1" +itertools = "0.10" +quote = "1.0" serde = { version = "1.0", features = ["derive"] } -syn = { version = "1", features = ["full"] } +syn = { version = "1.0", features = ["full"] } [build-dependencies] -rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util" } +rustc_tools_util = { version = "0.2", path = "rustc_tools_util" } [features] deny-warnings = ["clippy_lints/deny-warnings"] diff --git a/clippy_dev/Cargo.toml b/clippy_dev/Cargo.toml index 0fae8c7b9afc..d7d2655026b4 100644 --- a/clippy_dev/Cargo.toml +++ b/clippy_dev/Cargo.toml @@ -6,11 +6,11 @@ edition = "2018" [dependencies] bytecount = "0.6" clap = "2.33" -itertools = "0.9" +itertools = "0.10" opener = "0.5" -regex = "1" +regex = "1.5" shell-escape = "0.1" -walkdir = "2" +walkdir = "2.3" [features] deny-warnings = [] diff --git a/clippy_dummy/Cargo.toml b/clippy_dummy/Cargo.toml index a1707bad5c26..c206a1eb07b5 100644 --- a/clippy_dummy/Cargo.toml +++ b/clippy_dummy/Cargo.toml @@ -13,4 +13,4 @@ keywords = ["clippy", "lint", "plugin"] categories = ["development-tools", "development-tools::cargo-plugins"] [build-dependencies] -term = "0.6" +term = "0.7" diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 3c28024bf926..e59175a55e18 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -11,21 +11,21 @@ edition = "2018" [dependencies] cargo_metadata = "0.12" clippy_utils = { path = "../clippy_utils" } -if_chain = "1.0.0" -itertools = "0.9" +if_chain = "1.0" +itertools = "0.10" pulldown-cmark = { version = "0.8", default-features = false } -quine-mc_cluskey = "0.2.2" +quine-mc_cluskey = "0.2" regex-syntax = "0.6" serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0", optional = true } -toml = "0.5.3" +toml = "0.5" unicode-normalization = "0.1" -unicode-script = { version = "0.5.3", default-features = false } +unicode-script = { version = "0.5", default-features = false } semver = "0.11" -rustc-semver = "1.1.0" +rustc-semver = "1.1" # NOTE: cargo requires serde feat in its url dep # see -url = { version = "2.1.0", features = ["serde"] } +url = { version = "2.2", features = ["serde"] } [features] deny-warnings = ["clippy_utils/deny-warnings"] diff --git a/clippy_utils/Cargo.toml b/clippy_utils/Cargo.toml index 4c038a997952..7c24e830e71d 100644 --- a/clippy_utils/Cargo.toml +++ b/clippy_utils/Cargo.toml @@ -5,8 +5,8 @@ edition = "2018" publish = false [dependencies] -if_chain = "1.0.0" -rustc-semver="1.1.0" +if_chain = "1.0" +rustc-semver = "1.1" [features] deny-warnings = [] diff --git a/lintcheck/Cargo.toml b/lintcheck/Cargo.toml index ada033de6e3a..f33f1b65eabd 100644 --- a/lintcheck/Cargo.toml +++ b/lintcheck/Cargo.toml @@ -11,15 +11,15 @@ publish = false [dependencies] clap = "2.33" -flate2 = {version = "1.0.19"} -fs_extra = {version = "1.2.0"} -rayon = {version = "1.5.0"} -serde = {version = "1.0", features = ["derive"]} -serde_json = {version = "1.0"} -tar = {version = "0.4.30"} -toml = {version = "0.5"} -ureq = {version = "2.0.0-rc3"} -walkdir = {version = "2.3.2"} +flate2 = "1.0" +fs_extra = "1.2" +rayon = "1.5" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +tar = "0.4" +toml = "0.5" +ureq = "2.2" +walkdir = "2.3" [features] deny-warnings = [] From 585a4c7ea9364ca213b8a014cf4d69f5b1290071 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Fri, 21 May 2021 19:35:49 +0200 Subject: [PATCH 0318/1222] Ignore automatically derived impls of `Clone` and `Debug` in dead code analysis --- clippy_lints/src/macro_use.rs | 29 +++++++---------------------- clippy_lints/src/regex.rs | 8 ++------ tests/ui/default_trait_access.fixed | 2 +- tests/ui/default_trait_access.rs | 2 +- 4 files changed, 11 insertions(+), 30 deletions(-) diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index 7627e0fb2895..41e6ad12d058 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -29,36 +29,21 @@ declare_clippy_lint! { "#[macro_use] is no longer needed" } -const BRACKETS: &[char] = &['<', '>']; - #[derive(Clone, Debug, PartialEq, Eq)] struct PathAndSpan { path: String, span: Span, } -/// `MacroRefData` includes the name of the macro -/// and the path from `SourceMap::span_to_filename`. +/// `MacroRefData` includes the name of the macro. #[derive(Debug, Clone)] pub struct MacroRefData { name: String, - path: String, } impl MacroRefData { - pub fn new(name: String, callee: Span, cx: &LateContext<'_>) -> Self { - let sm = cx.sess().source_map(); - let mut path = sm.filename_for_diagnostics(&sm.span_to_filename(callee)).to_string(); - - // std lib paths are <::std::module::file type> - // so remove brackets, space and type. - if path.contains('<') { - path = path.replace(BRACKETS, ""); - } - if path.contains(' ') { - path = path.split(' ').next().unwrap().to_string(); - } - Self { name, path } + pub fn new(name: String) -> Self { + Self { name } } } @@ -78,7 +63,7 @@ impl MacroUseImports { fn push_unique_macro(&mut self, cx: &LateContext<'_>, span: Span) { let call_site = span.source_callsite(); let name = snippet(cx, cx.sess().source_map().span_until_char(call_site, '!'), "_"); - if let Some(callee) = span.source_callee() { + if let Some(_callee) = span.source_callee() { if !self.collected.contains(&call_site) { let name = if name.contains("::") { name.split("::").last().unwrap().to_string() @@ -86,7 +71,7 @@ impl MacroUseImports { name.to_string() }; - self.mac_refs.push(MacroRefData::new(name, callee.def_site, cx)); + self.mac_refs.push(MacroRefData::new(name)); self.collected.insert(call_site); } } @@ -95,10 +80,10 @@ impl MacroUseImports { fn push_unique_macro_pat_ty(&mut self, cx: &LateContext<'_>, span: Span) { let call_site = span.source_callsite(); let name = snippet(cx, cx.sess().source_map().span_until_char(call_site, '!'), "_"); - if let Some(callee) = span.source_callee() { + if let Some(_callee) = span.source_callee() { if !self.collected.contains(&call_site) { self.mac_refs - .push(MacroRefData::new(name.to_string(), callee.def_site, cx)); + .push(MacroRefData::new(name.to_string())); self.collected.insert(call_site); } } diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index eab097337306..89be7bf844f3 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -3,8 +3,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_ast::ast::{LitKind, StrStyle}; -use rustc_data_structures::fx::FxHashSet; -use rustc_hir::{BorrowKind, Expr, ExprKind, HirId}; +use rustc_hir::{BorrowKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::{BytePos, Span}; @@ -53,10 +52,7 @@ declare_clippy_lint! { } #[derive(Clone, Default)] -pub struct Regex { - spans: FxHashSet, - last: Option, -} +pub struct Regex {} impl_lint_pass!(Regex => [INVALID_REGEX, TRIVIAL_REGEX]); diff --git a/tests/ui/default_trait_access.fixed b/tests/ui/default_trait_access.fixed index 4c80cabc7230..f1f9c123dc84 100644 --- a/tests/ui/default_trait_access.fixed +++ b/tests/ui/default_trait_access.fixed @@ -1,6 +1,6 @@ // run-rustfix -#![allow(unused_imports)] +#![allow(unused_imports,dead_code)] #![deny(clippy::default_trait_access)] use std::default; diff --git a/tests/ui/default_trait_access.rs b/tests/ui/default_trait_access.rs index a68b6455c041..7f3dfc7f0136 100644 --- a/tests/ui/default_trait_access.rs +++ b/tests/ui/default_trait_access.rs @@ -1,6 +1,6 @@ // run-rustfix -#![allow(unused_imports)] +#![allow(unused_imports,dead_code)] #![deny(clippy::default_trait_access)] use std::default; From e184cdca1923cedcf72c38aad241a4a9d24efee9 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 18 Apr 2021 14:27:04 +0200 Subject: [PATCH 0319/1222] Keep a parent LocalDefId in SpanData. --- clippy_lints/src/attrs.rs | 4 ++-- clippy_lints/src/cognitive_complexity.rs | 2 +- clippy_lints/src/copies.rs | 2 +- clippy_lints/src/doc.rs | 1 + clippy_lints/src/implicit_hasher.rs | 4 ++-- clippy_lints/src/large_const_arrays.rs | 1 + clippy_lints/src/regex.rs | 2 +- clippy_lints/src/tabs_in_doc_comments.rs | 1 + 8 files changed, 10 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index c9ff468874b5..2ef7dcc1775a 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -527,8 +527,8 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::It return; } - let begin_of_attr_to_item = Span::new(attr.span.lo(), item.span.lo(), item.span.ctxt()); - let end_of_attr_to_item = Span::new(attr.span.hi(), item.span.lo(), item.span.ctxt()); + 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()); if let Some(snippet) = snippet_opt(cx, end_of_attr_to_item) { let lines = snippet.split('\n').collect::>(); diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index 96c30d57ee19..2203d1c39f17 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -95,7 +95,7 @@ impl CognitiveComplexity { }); if let Some((low, high)) = pos { - Span::new(low, high, header_span.ctxt()) + Span::new(low, high, header_span.ctxt(), header_span.parent()) } else { return; } diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index d58e49491203..6ded2f233efe 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -472,7 +472,7 @@ fn emit_branches_sharing_code_lint( let mut span = moved_start.to(span_end); // Improve formatting if the inner block has indention (i.e. normal Rust formatting) - let test_span = Span::new(span.lo() - BytePos(4), span.lo(), span.ctxt()); + let test_span = Span::new(span.lo() - BytePos(4), span.lo(), span.ctxt(), span.parent()); if snippet_opt(cx, test_span) .map(|snip| snip == " ") .unwrap_or_default() diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index cb2b7f5be70a..0b61909ddd82 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -665,6 +665,7 @@ fn check_text(cx: &LateContext<'_>, valid_idents: &FxHashSet, text: &str span.lo() + BytePos::from_usize(offset), span.lo() + BytePos::from_usize(offset + word.len()), span.ctxt(), + span.parent(), ); check_word(cx, word, span); diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 6b407c7bb672..2fe32fcf6651 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -130,7 +130,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { let pos = snippet_opt(cx, item.span.until(target.span())) .and_then(|snip| Some(item.span.lo() + BytePos(snip.find("impl")? as u32 + 4))); if let Some(pos) = pos { - Span::new(pos, pos, item.span.data().ctxt) + Span::new(pos, pos, item.span.ctxt(), item.span.parent()) } else { return; } @@ -173,7 +173,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { Some(item.span.lo() + BytePos((i + (&snip[i..]).find('(')?) as u32)) }) .expect("failed to create span for type parameters"); - Span::new(pos, pos, item.span.data().ctxt) + Span::new(pos, pos, item.span.ctxt(), item.span.parent()) }); let mut ctr_vis = ImplicitHasherConstructorVisitor::new(cx, target); diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index 10281496c11c..fe6814e35d0c 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -63,6 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays { hi_pos - BytePos::from_usize("const".len()), hi_pos, item.span.ctxt(), + item.span.parent(), ); span_lint_and_then( cx, diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index eab097337306..0e25e3f1a524 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -91,7 +91,7 @@ fn str_span(base: Span, c: regex_syntax::ast::Span, offset: u16) -> Span { let end = base.lo() + BytePos(u32::try_from(c.end.offset).expect("offset too large") + offset); let start = base.lo() + BytePos(u32::try_from(c.start.offset).expect("offset too large") + offset); assert!(start <= end); - Span::new(start, end, base.ctxt()) + Span::new(start, end, base.ctxt(), base.parent()) } fn const_str<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> Option { diff --git a/clippy_lints/src/tabs_in_doc_comments.rs b/clippy_lints/src/tabs_in_doc_comments.rs index 6a73b94d87e4..4a67cabf323a 100644 --- a/clippy_lints/src/tabs_in_doc_comments.rs +++ b/clippy_lints/src/tabs_in_doc_comments.rs @@ -69,6 +69,7 @@ impl TabsInDocComments { attr.span.lo() + BytePos(3 + lo), attr.span.lo() + BytePos(3 + hi), attr.span.ctxt(), + attr.span.parent(), ); span_lint_and_sugg( cx, From a51a15626f4278d1d9ee3250cdef0ab5e34b7e23 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 5 Sep 2021 23:37:15 +0300 Subject: [PATCH 0320/1222] rustc: Remove local variable IDs from `Export`s Local variables can never be exported. --- clippy_utils/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index da259511fe0b..3a94f4729839 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -520,7 +520,7 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Res { } }; } - fn item_child_by_name<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, name: &str) -> Option<&'tcx Export> { + fn item_child_by_name<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, name: &str) -> Option<&'tcx Export> { tcx.item_children(def_id) .iter() .find(|item| item.ident.name.as_str() == name) @@ -557,7 +557,7 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Res { None } }); - try_res!(last).res + try_res!(last).res.expect_non_local() } /// Convenience function to get the `DefId` of a trait by path. From e458b9e72b5bff81a672a3fff024afdaf6622b7e Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 10 Sep 2021 19:57:06 +0200 Subject: [PATCH 0321/1222] Rebase fallout. --- clippy_lints/src/methods/manual_split_once.rs | 2 +- clippy_lints/src/module_style.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/methods/manual_split_once.rs b/clippy_lints/src/methods/manual_split_once.rs index e273186d0519..001676503242 100644 --- a/clippy_lints/src/methods/manual_split_once.rs +++ b/clippy_lints/src/methods/manual_split_once.rs @@ -182,7 +182,7 @@ fn parse_iter_usage( }, _, ) => { - let parent_span = e.span.parent().unwrap(); + let parent_span = e.span.parent_callsite().unwrap(); if parent_span.ctxt() == ctxt { (Some(UnwrapKind::QuestionMark), parent_span) } else { diff --git a/clippy_lints/src/module_style.rs b/clippy_lints/src/module_style.rs index 80a930d0c547..f351d0098b75 100644 --- a/clippy_lints/src/module_style.rs +++ b/clippy_lints/src/module_style.rs @@ -120,7 +120,7 @@ impl EarlyLintPass for ModStyle { correct.push("mod.rs"); cx.struct_span_lint( SELF_NAMED_MODULE_FILES, - Span::new(file.start_pos, file.start_pos, SyntaxContext::root()), + Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None), |build| { let mut lint = build.build(&format!("`mod.rs` files are required, found `{}`", path.display())); @@ -167,7 +167,7 @@ fn check_self_named_mod_exists(cx: &EarlyContext<'_>, path: &Path, file: &Source cx.struct_span_lint( MOD_MODULE_FILES, - Span::new(file.start_pos, file.start_pos, SyntaxContext::root()), + Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None), |build| { let mut lint = build.build(&format!("`mod.rs` files are not allowed, found `{}`", path.display())); lint.help(&format!("move `{}` to `{}`", path.display(), mod_file.display(),)); From 13cae03e8bc2ce895d35cb22bf660028d95e2ba3 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Tue, 7 Sep 2021 16:06:07 +0100 Subject: [PATCH 0322/1222] Introduce NullOp::AlignOf --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 8f14b590d274..e9a9895cb746 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -192,7 +192,7 @@ fn check_rvalue(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, rvalue: &Rv )) } }, - Rvalue::NullaryOp(NullOp::SizeOf, _) => Ok(()), + Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) => Ok(()), Rvalue::NullaryOp(NullOp::Box, _) => Err((span, "heap allocations are not allowed in const fn".into())), Rvalue::UnaryOp(_, operand) => { let ty = operand.ty(body, tcx); From a7d3bc1be26bab60d1d88c244306220cf4886304 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 13 Sep 2021 21:27:53 +0200 Subject: [PATCH 0323/1222] Update permissions path for clippy lint --- clippy_utils/src/paths.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index d7e46c2d3eb9..80be4350c3c1 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -104,7 +104,7 @@ pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 2] = ["parking_lot", "RwLockWri pub const PATH_BUF_AS_PATH: [&str; 4] = ["std", "path", "PathBuf", "as_path"]; pub const PATH_TO_PATH_BUF: [&str; 4] = ["std", "path", "Path", "to_path_buf"]; pub const PERMISSIONS: [&str; 3] = ["std", "fs", "Permissions"]; -pub const PERMISSIONS_FROM_MODE: [&str; 7] = ["std", "os", "imp", "unix", "fs", "PermissionsExt", "from_mode"]; +pub const PERMISSIONS_FROM_MODE: [&str; 6] = ["std", "os", "unix", "fs", "PermissionsExt", "from_mode"]; pub const POLL: [&str; 4] = ["core", "task", "poll", "Poll"]; pub const POLL_PENDING: [&str; 5] = ["core", "task", "poll", "Poll", "Pending"]; pub const POLL_READY: [&str; 5] = ["core", "task", "poll", "Poll", "Ready"]; From 0b6ddd2dcb30ad9f008bfe6da6e30199716c3c12 Mon Sep 17 00:00:00 2001 From: asquared31415 <34665709+asquared31415@users.noreply.github.com> Date: Fri, 10 Sep 2021 09:33:06 -0400 Subject: [PATCH 0324/1222] update test --- tests/ui/def_id_nocore.rs | 5 +++-- tests/ui/def_id_nocore.stderr | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/ui/def_id_nocore.rs b/tests/ui/def_id_nocore.rs index cba7666c2d8a..1ed78547a60c 100644 --- a/tests/ui/def_id_nocore.rs +++ b/tests/ui/def_id_nocore.rs @@ -15,11 +15,12 @@ pub trait Copy {} pub unsafe trait Freeze {} #[lang = "start"] -#[start] -fn start(_argc: isize, _argv: *const *const u8) -> isize { +fn start(_main: fn() -> T, _argc: isize, _argv: *const *const u8) -> isize { 0 } +fn main() {} + struct A; impl A { diff --git a/tests/ui/def_id_nocore.stderr b/tests/ui/def_id_nocore.stderr index 702684f6b43a..6210d7c6cfd8 100644 --- a/tests/ui/def_id_nocore.stderr +++ b/tests/ui/def_id_nocore.stderr @@ -1,5 +1,5 @@ error: methods called `as_*` usually take `self` by reference or `self` by mutable reference - --> $DIR/def_id_nocore.rs:26:19 + --> $DIR/def_id_nocore.rs:27:19 | LL | pub fn as_ref(self) -> &'static str { | ^^^^ From df385c5d2280f3544628d0551d6c33a09d54fbaf Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 15 Sep 2021 10:03:03 +0000 Subject: [PATCH 0325/1222] Move is_const_fn to under TyCtxt --- clippy_utils/src/lib.rs | 1 - clippy_utils/src/qualify_min_const_fn.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 3a94f4729839..beddc6f09be8 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -18,7 +18,6 @@ extern crate rustc_ast; extern crate rustc_ast_pretty; extern crate rustc_attr; -extern crate rustc_const_eval; extern crate rustc_data_structures; extern crate rustc_errors; extern crate rustc_hir; diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index e9a9895cb746..67dda33e9daa 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -364,7 +364,7 @@ fn check_terminator( } fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<&RustcVersion>) -> bool { - rustc_const_eval::const_eval::is_const_fn(tcx, def_id) + tcx.is_const_fn(def_id) && tcx.lookup_const_stability(def_id).map_or(true, |const_stab| { if let rustc_attr::StabilityLevel::Stable { since } = const_stab.level { // Checking MSRV is manually necessary because `rustc` has no such concept. This entire From 9f1c257a9afc9745c18d2c621daaf8e611751c7a Mon Sep 17 00:00:00 2001 From: jackh726 Date: Thu, 16 Sep 2021 00:12:56 -0400 Subject: [PATCH 0326/1222] Fix clippy --- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/methods/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 1ba241d37761..6bbac6d9a246 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { // be sure we have `self` parameter in this function if let AssocItemKind::Fn { has_self: true } = trait_item.kind { trait_self_ty = - Some(TraitRef::identity(cx.tcx, trait_item.id.def_id.to_def_id()).self_ty()); + Some(TraitRef::identity(cx.tcx, trait_item.id.def_id.to_def_id()).self_ty().skip_binder()); } } } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index e89b2d295b92..a04b325b56e3 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2061,7 +2061,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { then { let first_arg_span = first_arg_ty.span; let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty); - let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty(); + let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty().skip_binder(); wrong_self_convention::check( cx, &item.ident.name.as_str(), @@ -2078,7 +2078,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if item.ident.name == sym::new; if let TraitItemKind::Fn(_, _) = item.kind; let ret_ty = return_ty(cx, item.hir_id()); - let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty(); + let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty().skip_binder(); if !contains_ty(cx.tcx, ret_ty, self_ty); then { From 982cdfd805f06008b6a3fac07ca65bab3bd38966 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sat, 18 Sep 2021 15:48:07 -0500 Subject: [PATCH 0327/1222] Remove needless hir Map ref --- clippy_utils/src/higher.rs | 3 +-- clippy_utils/src/lib.rs | 15 +++++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index 05a4a0143195..94b3cd371bd0 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -105,8 +105,7 @@ impl<'hir> IfLet<'hir> { if_else, ) = expr.kind { - let hir = cx.tcx.hir(); - let mut iter = hir.parent_iter(expr.hir_id); + let mut iter = cx.tcx.hir().parent_iter(expr.hir_id); if let Some((_, Node::Block(Block { stmts: [], .. }))) = iter.next() { if let Some(( _, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 3a94f4729839..7f5a1bf9c074 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -833,12 +833,11 @@ pub fn capture_local_usage(cx: &LateContext<'tcx>, e: &Expr<'_>) -> CaptureKind ExprKind::Path(QPath::Resolved(None, Path { res: Res::Local(_), .. })) )); - let map = cx.tcx.hir(); let mut child_id = e.hir_id; let mut capture = CaptureKind::Value; let mut capture_expr_ty = e; - for (parent_id, parent) in map.parent_iter(e.hir_id) { + for (parent_id, parent) in cx.tcx.hir().parent_iter(e.hir_id) { if let [Adjustment { kind: Adjust::Deref(_) | Adjust::Borrow(AutoBorrow::Ref(..)), target, @@ -1224,8 +1223,7 @@ pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio /// Gets the loop or closure enclosing the given expression, if any. pub fn get_enclosing_loop_or_closure(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -> Option<&'tcx Expr<'tcx>> { - let map = tcx.hir(); - for (_, node) in map.parent_iter(expr.hir_id) { + for (_, node) in tcx.hir().parent_iter(expr.hir_id) { match node { Node::Expr( e @@ -1244,8 +1242,7 @@ pub fn get_enclosing_loop_or_closure(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -> Opti /// Gets the parent node if it's an impl block. pub fn get_parent_as_impl(tcx: TyCtxt<'_>, id: HirId) -> Option<&Impl<'_>> { - let map = tcx.hir(); - match map.parent_iter(id).next() { + match tcx.hir().parent_iter(id).next() { Some(( _, Node::Item(Item { @@ -1259,8 +1256,7 @@ pub fn get_parent_as_impl(tcx: TyCtxt<'_>, id: HirId) -> Option<&Impl<'_>> { /// Checks if the given expression is the else clause of either an `if` or `if let` expression. pub fn is_else_clause(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { - let map = tcx.hir(); - let mut iter = map.parent_iter(expr.hir_id); + let mut iter = tcx.hir().parent_iter(expr.hir_id); match iter.next() { Some(( _, @@ -1794,9 +1790,8 @@ pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool /// Gets the node where an expression is either used, or it's type is unified with another branch. pub fn get_expr_use_or_unification_node(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -> Option> { - let map = tcx.hir(); let mut child_id = expr.hir_id; - let mut iter = map.parent_iter(child_id); + let mut iter = tcx.hir().parent_iter(child_id); loop { match iter.next() { None => break None, From 142282846a39919bc3c6a6ac7e6630213c250d75 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 15 Jul 2021 22:19:39 +0200 Subject: [PATCH 0328/1222] Do not store visibility in *ItemRef. --- clippy_lints/src/fallible_impl_from.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 7e4d1b3ef9f0..f22f52b949e1 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -65,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom { } } -fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[hir::ImplItemRef<'_>]) { +fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[hir::ImplItemRef]) { use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::{Expr, ExprKind, ImplItemKind, QPath}; From 1cac4debbc6ea53d49902347fd65dc87a6e61d25 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 18 Sep 2021 17:37:24 -0400 Subject: [PATCH 0329/1222] Enable 2021 compatibility lints for all in-tree code This just applies the suggested fixes from the compatibility warnings, leaving any that are in practice spurious in. This is primarily intended to provide a starting point to identify possible fixes to the migrations (e.g., by avoiding spurious warnings). A secondary commit cleans these up where they are false positives (as is true in many of the cases). --- clippy_utils/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 3a94f4729839..5c505f6851af 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -990,7 +990,10 @@ pub fn can_move_expr_to_closure(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> captures: HirIdMap::default(), }; v.visit_expr(expr); - v.allow_closure.then(|| v.captures) + v.allow_closure.then(|| { + let _ = &v; + v.captures + }) } /// Returns the method names and argument list of nested method call expressions that make up From baf4669503a971082fc10ef7adac3f7b4ae5f03b Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sun, 19 Sep 2021 13:46:05 -0400 Subject: [PATCH 0330/1222] Remove Drop-caused migration-added captures All of these were added due to insignificant Drop types being present. --- clippy_utils/src/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 5c505f6851af..3a94f4729839 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -990,10 +990,7 @@ pub fn can_move_expr_to_closure(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> captures: HirIdMap::default(), }; v.visit_expr(expr); - v.allow_closure.then(|| { - let _ = &v; - v.captures - }) + v.allow_closure.then(|| v.captures) } /// Returns the method names and argument list of nested method call expressions that make up From e8be3167c35a49dc12ef8fbc1da0b599f4212d04 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Tue, 21 Sep 2021 00:56:45 -0500 Subject: [PATCH 0331/1222] Use ZST for fmt unsafety This allows the format_args! macro to keep the pre-expansion code out of the unsafe block without doing gymnastics with nested `match` expressions. This reduces codegen. --- clippy_utils/src/higher.rs | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index 05a4a0143195..ff55ff35a134 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -524,28 +524,12 @@ impl FormatArgsExpn<'tcx> { if let ExpnKind::Macro(_, name) = expr.span.ctxt().outer_expn_data().kind; let name = name.as_str(); if name.ends_with("format_args") || name.ends_with("format_args_nl"); - - if let ExprKind::Match(inner_match, [arm], _) = expr.kind; - - // `match match`, if you will - if let ExprKind::Match(args, [inner_arm], _) = inner_match.kind; - if let ExprKind::Tup(value_args) = args.kind; - if let Some(value_args) = value_args - .iter() - .map(|e| match e.kind { - ExprKind::AddrOf(_, _, e) => Some(e), - _ => None, - }) - .collect(); - if let ExprKind::Array(args) = inner_arm.body.kind; - - if let ExprKind::Block(Block { stmts: [], expr: Some(expr), .. }, _) = arm.body.kind; - if let ExprKind::Call(_, call_args) = expr.kind; - if let Some((strs_ref, fmt_expr)) = match call_args { + if let ExprKind::Call(_, args) = expr.kind; + if let Some((strs_ref, args, fmt_expr)) = match args { // Arguments::new_v1 - [strs_ref, _] => Some((strs_ref, None)), + [strs_ref, args] => Some((strs_ref, args, None)), // Arguments::new_v1_formatted - [strs_ref, _, fmt_expr] => Some((strs_ref, Some(fmt_expr))), + [strs_ref, args, fmt_expr, _unsafe_arg] => Some((strs_ref, args, Some(fmt_expr))), _ => None, }; if let ExprKind::AddrOf(BorrowKind::Ref, _, strs_arr) = strs_ref.kind; @@ -561,6 +545,17 @@ impl FormatArgsExpn<'tcx> { None }) .collect(); + if let ExprKind::AddrOf(BorrowKind::Ref, _, args) = args.kind; + if let ExprKind::Match(args, [arm], _) = args.kind; + if let ExprKind::Tup(value_args) = args.kind; + if let Some(value_args) = value_args + .iter() + .map(|e| match e.kind { + ExprKind::AddrOf(_, _, e) => Some(e), + _ => None, + }) + .collect(); + if let ExprKind::Array(args) = arm.body.kind; then { Some(FormatArgsExpn { format_string_span: strs_ref.span, From 8d558c65cba914d51680358b76da2ccf29596cee Mon Sep 17 00:00:00 2001 From: r00ster91 Date: Fri, 24 Sep 2021 12:44:28 +0200 Subject: [PATCH 0332/1222] consistent big O notation --- clippy_lints/src/methods/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index e89b2d295b92..e4d34524f720 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -995,7 +995,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does /// Checks for use of `.iter().nth()` (and the related - /// `.iter_mut().nth()`) on standard library types with O(1) element access. + /// `.iter_mut().nth()`) on standard library types with *O*(1) element access. /// /// ### Why is this bad? /// `.get()` and `.get_mut()` are more efficient and more From 01fe255feb4bd7396e18a92c3db68c8fbcb658a1 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 6 Sep 2021 18:33:23 +0100 Subject: [PATCH 0333/1222] Introduce `Rvalue::ShallowInitBox` --- clippy_utils/src/qualify_min_const_fn.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index e9a9895cb746..e2f2e2008bb2 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -194,6 +194,7 @@ fn check_rvalue(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, rvalue: &Rv }, Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) => Ok(()), Rvalue::NullaryOp(NullOp::Box, _) => Err((span, "heap allocations are not allowed in const fn".into())), + Rvalue::ShallowInitBox(_, _) => Ok(()), Rvalue::UnaryOp(_, operand) => { let ty = operand.ty(body, tcx); if ty.is_integral() || ty.is_bool() { From fa23ecd2784048a40c5a0b8614793f78c633a729 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 12 Sep 2021 01:11:22 +0200 Subject: [PATCH 0334/1222] Avoid more invocations of hir_crate query. --- clippy_lints/src/missing_doc.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 940eee7a7889..578fddbd7728 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -78,9 +78,7 @@ impl MissingDoc { return; } - let has_doc = attrs - .iter() - .any(|a| a.doc_str().is_some()); + let has_doc = attrs.iter().any(|a| a.doc_str().is_some()); if !has_doc { span_lint( cx, @@ -104,9 +102,9 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { self.doc_hidden_stack.pop().expect("empty doc_hidden_stack"); } - fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) { + fn check_crate(&mut self, cx: &LateContext<'tcx>, _: &'tcx hir::Crate<'_>) { let attrs = cx.tcx.hir().attrs(hir::CRATE_HIR_ID); - self.check_missing_docs_attrs(cx, attrs, krate.module().inner, "the", "crate"); + self.check_missing_docs_attrs(cx, attrs, cx.tcx.hir().root_module().inner, "the", "crate"); } fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) { From a2631c6782aabb51456b479866d09b8ec80650a9 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 12 Sep 2021 11:58:27 +0200 Subject: [PATCH 0335/1222] Do not pass hir::Crate to lints. --- clippy_lints/src/cargo_common_metadata.rs | 4 ++-- clippy_lints/src/disallowed_method.rs | 4 ++-- clippy_lints/src/disallowed_type.rs | 4 ++-- clippy_lints/src/doc.rs | 2 +- clippy_lints/src/feature_name.rs | 4 ++-- clippy_lints/src/inherent_impl.rs | 4 ++-- clippy_lints/src/macro_use.rs | 2 +- clippy_lints/src/main_recursion.rs | 4 ++-- clippy_lints/src/missing_doc.rs | 5 +++-- clippy_lints/src/missing_enforced_import_rename.rs | 4 ++-- clippy_lints/src/multiple_crate_versions.rs | 4 ++-- clippy_lints/src/same_name_method.rs | 6 +++--- clippy_lints/src/wildcard_dependencies.rs | 4 ++-- 13 files changed, 26 insertions(+), 25 deletions(-) diff --git a/clippy_lints/src/cargo_common_metadata.rs b/clippy_lints/src/cargo_common_metadata.rs index 162911b77d61..ff619c59b6e2 100644 --- a/clippy_lints/src/cargo_common_metadata.rs +++ b/clippy_lints/src/cargo_common_metadata.rs @@ -1,7 +1,7 @@ //! lint on missing cargo common metadata use clippy_utils::{diagnostics::span_lint, is_lint_allowed}; -use rustc_hir::{hir_id::CRATE_HIR_ID, Crate}; +use rustc_hir::hir_id::CRATE_HIR_ID; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::DUMMY_SP; @@ -77,7 +77,7 @@ fn is_empty_vec(value: &[String]) -> bool { } impl LateLintPass<'_> for CargoCommonMetadata { - fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { + fn check_crate(&mut self, cx: &LateContext<'_>) { if is_lint_allowed(cx, CARGO_COMMON_METADATA, CRATE_HIR_ID) { return; } diff --git a/clippy_lints/src/disallowed_method.rs b/clippy_lints/src/disallowed_method.rs index 1167b26c8f15..22d726cdcb7b 100644 --- a/clippy_lints/src/disallowed_method.rs +++ b/clippy_lints/src/disallowed_method.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::fn_def_id; -use rustc_hir::{def::Res, def_id::DefIdMap, Crate, Expr}; +use rustc_hir::{def::Res, def_id::DefIdMap, Expr}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -70,7 +70,7 @@ impl DisallowedMethod { impl_lint_pass!(DisallowedMethod => [DISALLOWED_METHOD]); impl<'tcx> LateLintPass<'tcx> for DisallowedMethod { - fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { + fn check_crate(&mut self, cx: &LateContext<'_>) { for conf in &self.conf_disallowed { let (path, reason) = match conf { conf::DisallowedMethod::Simple(path) => (path, None), diff --git a/clippy_lints/src/disallowed_type.rs b/clippy_lints/src/disallowed_type.rs index 6c861fb33a97..87124f093a86 100644 --- a/clippy_lints/src/disallowed_type.rs +++ b/clippy_lints/src/disallowed_type.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_data_structures::fx::FxHashSet; use rustc_hir::{ - def::Res, def_id::DefId, Crate, Item, ItemKind, PolyTraitRef, PrimTy, TraitBoundModifier, Ty, TyKind, UseKind, + def::Res, def_id::DefId, Item, ItemKind, PolyTraitRef, PrimTy, TraitBoundModifier, Ty, TyKind, UseKind, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -75,7 +75,7 @@ impl DisallowedType { impl_lint_pass!(DisallowedType => [DISALLOWED_TYPE]); impl<'tcx> LateLintPass<'tcx> for DisallowedType { - fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { + fn check_crate(&mut self, cx: &LateContext<'_>) { for path in &self.disallowed { let segs = path.iter().map(ToString::to_string).collect::>(); match clippy_utils::path_to_res(cx, &segs.iter().map(String::as_str).collect::>()) { diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 0b61909ddd82..84f3b76a3c7d 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -212,7 +212,7 @@ impl_lint_pass!(DocMarkdown => ); impl<'tcx> LateLintPass<'tcx> for DocMarkdown { - fn check_crate(&mut self, cx: &LateContext<'tcx>, _: &'tcx hir::Crate<'_>) { + fn check_crate(&mut self, cx: &LateContext<'tcx>) { let attrs = cx.tcx.hir().attrs(hir::CRATE_HIR_ID); check_attrs(cx, &self.valid_idents, attrs); } diff --git a/clippy_lints/src/feature_name.rs b/clippy_lints/src/feature_name.rs index eef1407a80cf..f534327f7a0c 100644 --- a/clippy_lints/src/feature_name.rs +++ b/clippy_lints/src/feature_name.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::{diagnostics::span_lint, is_lint_allowed}; -use rustc_hir::{Crate, CRATE_HIR_ID}; +use rustc_hir::CRATE_HIR_ID; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::DUMMY_SP; @@ -110,7 +110,7 @@ fn lint(cx: &LateContext<'_>, feature: &str, substring: &str, is_prefix: bool) { } impl LateLintPass<'_> for FeatureName { - fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { + fn check_crate(&mut self, cx: &LateContext<'_>) { if is_lint_allowed(cx, REDUNDANT_FEATURE_NAMES, CRATE_HIR_ID) && is_lint_allowed(cx, NEGATIVE_FEATURE_NAMES, CRATE_HIR_ID) { diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index d87055c842c8..0d23bec27a3a 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_note; use clippy_utils::{in_macro, is_lint_allowed}; use rustc_data_structures::fx::FxHashMap; -use rustc_hir::{def_id::LocalDefId, Crate, Item, ItemKind, Node}; +use rustc_hir::{def_id::LocalDefId, Item, ItemKind, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Span; @@ -44,7 +44,7 @@ declare_clippy_lint! { declare_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]); impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { - fn check_crate_post(&mut self, cx: &LateContext<'tcx>, _: &'tcx Crate<'_>) { + fn check_crate_post(&mut self, cx: &LateContext<'tcx>) { // Map from a type to it's first impl block. Needed to distinguish generic arguments. // e.g. `Foo` and `Foo` let mut type_map = FxHashMap::default(); diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index aff6b3853a46..c38162743a3e 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -135,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports { } } #[allow(clippy::too_many_lines)] - fn check_crate_post(&mut self, cx: &LateContext<'_>, _krate: &hir::Crate<'_>) { + fn check_crate_post(&mut self, cx: &LateContext<'_>) { let mut used = FxHashMap::default(); let mut check_dup = vec![]; for (import, span) in &self.imports { diff --git a/clippy_lints/src/main_recursion.rs b/clippy_lints/src/main_recursion.rs index 776e4b3fe768..23b3ba2296ea 100644 --- a/clippy_lints/src/main_recursion.rs +++ b/clippy_lints/src/main_recursion.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::snippet; use clippy_utils::{is_entrypoint_fn, is_no_std_crate}; use if_chain::if_chain; -use rustc_hir::{Crate, Expr, ExprKind, QPath}; +use rustc_hir::{Expr, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -33,7 +33,7 @@ pub struct MainRecursion { impl_lint_pass!(MainRecursion => [MAIN_RECURSION]); impl LateLintPass<'_> for MainRecursion { - fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { + fn check_crate(&mut self, cx: &LateContext<'_>) { self.has_no_std_attr = is_no_std_crate(cx); } diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 578fddbd7728..564f021268cc 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -12,6 +12,7 @@ use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::ty; use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::def_id::CRATE_DEF_ID; use rustc_span::source_map::Span; use rustc_span::sym; @@ -102,9 +103,9 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { self.doc_hidden_stack.pop().expect("empty doc_hidden_stack"); } - fn check_crate(&mut self, cx: &LateContext<'tcx>, _: &'tcx hir::Crate<'_>) { + fn check_crate(&mut self, cx: &LateContext<'tcx>) { let attrs = cx.tcx.hir().attrs(hir::CRATE_HIR_ID); - self.check_missing_docs_attrs(cx, attrs, cx.tcx.hir().root_module().inner, "the", "crate"); + self.check_missing_docs_attrs(cx, attrs, cx.tcx.def_span(CRATE_DEF_ID), "the", "crate"); } fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) { diff --git a/clippy_lints/src/missing_enforced_import_rename.rs b/clippy_lints/src/missing_enforced_import_rename.rs index 9d27870321ca..448bfc2fdd67 100644 --- a/clippy_lints/src/missing_enforced_import_rename.rs +++ b/clippy_lints/src/missing_enforced_import_rename.rs @@ -2,7 +2,7 @@ use clippy_utils::{diagnostics::span_lint_and_sugg, source::snippet_opt}; use rustc_data_structures::fx::FxHashMap; use rustc_errors::Applicability; -use rustc_hir::{def::Res, def_id::DefId, Crate, Item, ItemKind, UseKind}; +use rustc_hir::{def::Res, def_id::DefId, Item, ItemKind, UseKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Symbol; @@ -55,7 +55,7 @@ impl ImportRename { impl_lint_pass!(ImportRename => [MISSING_ENFORCED_IMPORT_RENAMES]); impl LateLintPass<'_> for ImportRename { - fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { + fn check_crate(&mut self, cx: &LateContext<'_>) { for Rename { path, rename } in &self.conf_renames { if let Res::Def(_, id) = clippy_utils::path_to_res(cx, &path.split("::").collect::>()) { self.renames.insert(id, Symbol::intern(rename)); diff --git a/clippy_lints/src/multiple_crate_versions.rs b/clippy_lints/src/multiple_crate_versions.rs index 1c61970fdc8b..816b2f275fb5 100644 --- a/clippy_lints/src/multiple_crate_versions.rs +++ b/clippy_lints/src/multiple_crate_versions.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint; use clippy_utils::is_lint_allowed; use rustc_hir::def_id::LOCAL_CRATE; -use rustc_hir::{Crate, CRATE_HIR_ID}; +use rustc_hir::CRATE_HIR_ID; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::DUMMY_SP; @@ -41,7 +41,7 @@ declare_clippy_lint! { declare_lint_pass!(MultipleCrateVersions => [MULTIPLE_CRATE_VERSIONS]); impl LateLintPass<'_> for MultipleCrateVersions { - fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { + fn check_crate(&mut self, cx: &LateContext<'_>) { if is_lint_allowed(cx, MULTIPLE_CRATE_VERSIONS, CRATE_HIR_ID) { return; } diff --git a/clippy_lints/src/same_name_method.rs b/clippy_lints/src/same_name_method.rs index 014898e6dab1..737ff634e449 100644 --- a/clippy_lints/src/same_name_method.rs +++ b/clippy_lints/src/same_name_method.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{Crate, Impl, ItemKind, Node, Path, QPath, TraitRef, TyKind}; +use rustc_hir::{Impl, ItemKind, Node, Path, QPath, TraitRef, TyKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::AssocKind; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -46,10 +46,10 @@ struct ExistingName { } impl<'tcx> LateLintPass<'tcx> for SameNameMethod { - fn check_crate_post(&mut self, cx: &LateContext<'tcx>, krate: &'tcx Crate<'tcx>) { + fn check_crate_post(&mut self, cx: &LateContext<'tcx>) { let mut map = FxHashMap::::default(); - for item in krate.items() { + for item in cx.tcx.hir().items() { if let ItemKind::Impl(Impl { items, of_trait, diff --git a/clippy_lints/src/wildcard_dependencies.rs b/clippy_lints/src/wildcard_dependencies.rs index fd3872bacbe2..d0c98b6bd798 100644 --- a/clippy_lints/src/wildcard_dependencies.rs +++ b/clippy_lints/src/wildcard_dependencies.rs @@ -1,5 +1,5 @@ use clippy_utils::{diagnostics::span_lint, is_lint_allowed}; -use rustc_hir::{hir_id::CRATE_HIR_ID, Crate}; +use rustc_hir::hir_id::CRATE_HIR_ID; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::DUMMY_SP; @@ -28,7 +28,7 @@ declare_clippy_lint! { declare_lint_pass!(WildcardDependencies => [WILDCARD_DEPENDENCIES]); impl LateLintPass<'_> for WildcardDependencies { - fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { + fn check_crate(&mut self, cx: &LateContext<'_>) { if is_lint_allowed(cx, WILDCARD_DEPENDENCIES, CRATE_HIR_ID) { return; } From 6acefcb7e9e4b82c65cf6dc7a54b55e270d55dfc Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Thu, 19 Aug 2021 16:57:15 -0500 Subject: [PATCH 0336/1222] Add desugaring mark to while loop --- tests/ui/crashes/issues_loop_mut_cond.rs | 1 - tests/ui/infinite_loop.rs | 2 -- tests/ui/infinite_loop.stderr | 22 +++++++++++----------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/tests/ui/crashes/issues_loop_mut_cond.rs b/tests/ui/crashes/issues_loop_mut_cond.rs index 553c840f9b08..bb238c81ebc0 100644 --- a/tests/ui/crashes/issues_loop_mut_cond.rs +++ b/tests/ui/crashes/issues_loop_mut_cond.rs @@ -1,4 +1,3 @@ -#![allow(clippy::blocks_in_if_conditions)] #![allow(dead_code)] /// Issue: https://github.com/rust-lang/rust-clippy/issues/2596 diff --git a/tests/ui/infinite_loop.rs b/tests/ui/infinite_loop.rs index e86bd7bcf4fa..38e64b9ac0ad 100644 --- a/tests/ui/infinite_loop.rs +++ b/tests/ui/infinite_loop.rs @@ -1,5 +1,3 @@ -#![allow(clippy::blocks_in_if_conditions)] - fn fn_val(i: i32) -> i32 { unimplemented!() } diff --git a/tests/ui/infinite_loop.stderr b/tests/ui/infinite_loop.stderr index 69309b0da877..4ec7d900ade3 100644 --- a/tests/ui/infinite_loop.stderr +++ b/tests/ui/infinite_loop.stderr @@ -1,5 +1,5 @@ error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:22:11 + --> $DIR/infinite_loop.rs:20:11 | LL | while y < 10 { | ^^^^^^ @@ -8,7 +8,7 @@ LL | while y < 10 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:27:11 + --> $DIR/infinite_loop.rs:25:11 | LL | while y < 10 && x < 3 { | ^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | while y < 10 && x < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:34:11 + --> $DIR/infinite_loop.rs:32:11 | LL | while !cond { | ^^^^^ @@ -24,7 +24,7 @@ LL | while !cond { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:78:11 + --> $DIR/infinite_loop.rs:76:11 | LL | while i < 3 { | ^^^^^ @@ -32,7 +32,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:83:11 + --> $DIR/infinite_loop.rs:81:11 | LL | while i < 3 && j > 0 { | ^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | while i < 3 && j > 0 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:87:11 + --> $DIR/infinite_loop.rs:85:11 | LL | while i < 3 { | ^^^^^ @@ -48,7 +48,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:102:11 + --> $DIR/infinite_loop.rs:100:11 | LL | while i < 3 { | ^^^^^ @@ -56,7 +56,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:107:11 + --> $DIR/infinite_loop.rs:105:11 | LL | while i < 3 { | ^^^^^ @@ -64,7 +64,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:173:15 + --> $DIR/infinite_loop.rs:171:15 | LL | while self.count < n { | ^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | while self.count < n { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:181:11 + --> $DIR/infinite_loop.rs:179:11 | LL | while y < 10 { | ^^^^^^ @@ -82,7 +82,7 @@ LL | while y < 10 { = help: rewrite it as `if cond { loop { } }` error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:188:11 + --> $DIR/infinite_loop.rs:186:11 | LL | while y < 10 { | ^^^^^^ From de697b0b75fa015bc4b7246975a859a4350eaf94 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sat, 2 Oct 2021 18:51:01 -0500 Subject: [PATCH 0337/1222] Make diangostic item names consistent --- clippy_lints/src/booleans.rs | 4 ++-- .../src/case_sensitive_file_extension_comparisons.rs | 2 +- clippy_lints/src/cognitive_complexity.rs | 2 +- clippy_lints/src/doc.rs | 8 ++++---- clippy_lints/src/fallible_impl_from.rs | 6 +++--- clippy_lints/src/format.rs | 2 +- clippy_lints/src/from_over_into.rs | 2 +- clippy_lints/src/from_str_radix_10.rs | 2 +- clippy_lints/src/functions/result_unit_err.rs | 2 +- clippy_lints/src/future_not_send.rs | 2 +- clippy_lints/src/get_last_with_len.rs | 2 +- clippy_lints/src/if_let_mutex.rs | 3 ++- clippy_lints/src/implicit_hasher.rs | 8 ++++---- clippy_lints/src/infinite_iter.rs | 8 ++++---- clippy_lints/src/inherent_to_string.rs | 2 +- clippy_lints/src/len_zero.rs | 4 ++-- clippy_lints/src/loops/explicit_iter_loop.rs | 8 ++++---- clippy_lints/src/loops/for_kv_map.rs | 2 +- clippy_lints/src/loops/for_loops_over_fallibles.rs | 4 ++-- clippy_lints/src/loops/manual_memcpy.rs | 2 +- clippy_lints/src/loops/needless_collect.rs | 10 +++++----- clippy_lints/src/loops/same_item_push.rs | 2 +- clippy_lints/src/manual_map.rs | 4 ++-- clippy_lints/src/manual_ok_or.rs | 2 +- clippy_lints/src/manual_unwrap_or.rs | 4 ++-- clippy_lints/src/map_clone.rs | 2 +- clippy_lints/src/map_unit_fn.rs | 4 ++-- clippy_lints/src/match_on_vec_items.rs | 2 +- clippy_lints/src/match_result_ok.rs | 2 +- clippy_lints/src/matches.rs | 8 ++++---- clippy_lints/src/methods/bytes_nth.rs | 2 +- clippy_lints/src/methods/cloned_instead_of_copied.rs | 2 +- clippy_lints/src/methods/expect_fun_call.rs | 8 ++++---- clippy_lints/src/methods/expect_used.rs | 4 ++-- clippy_lints/src/methods/extend_with_drain.rs | 4 ++-- clippy_lints/src/methods/filter_map.rs | 6 +++--- clippy_lints/src/methods/flat_map_option.rs | 2 +- clippy_lints/src/methods/get_unwrap.rs | 6 +++--- clippy_lints/src/methods/inefficient_to_string.rs | 2 +- clippy_lints/src/methods/iter_cloned_collect.rs | 2 +- clippy_lints/src/methods/iter_count.rs | 8 ++++---- clippy_lints/src/methods/iter_next_slice.rs | 2 +- clippy_lints/src/methods/iter_nth.rs | 4 ++-- clippy_lints/src/methods/manual_split_once.rs | 4 ++-- clippy_lints/src/methods/manual_str_repeat.rs | 6 +++--- clippy_lints/src/methods/map_collect_result_unit.rs | 2 +- clippy_lints/src/methods/map_flatten.rs | 6 +++--- clippy_lints/src/methods/map_identity.rs | 4 ++-- clippy_lints/src/methods/map_unwrap_or.rs | 4 ++-- clippy_lints/src/methods/ok_expect.rs | 6 +++--- clippy_lints/src/methods/option_as_ref_deref.rs | 2 +- clippy_lints/src/methods/option_map_or_none.rs | 4 ++-- clippy_lints/src/methods/option_map_unwrap_or.rs | 2 +- clippy_lints/src/methods/or_fun_call.rs | 2 +- clippy_lints/src/methods/search_is_some.rs | 2 +- clippy_lints/src/methods/string_extend_chars.rs | 4 ++-- clippy_lints/src/methods/unnecessary_filter_map.rs | 2 +- clippy_lints/src/methods/unnecessary_lazy_eval.rs | 4 ++-- clippy_lints/src/methods/unwrap_or_else_default.rs | 4 ++-- clippy_lints/src/methods/unwrap_used.rs | 4 ++-- clippy_lints/src/methods/utils.rs | 2 +- clippy_lints/src/mut_key.rs | 10 +++++----- clippy_lints/src/mut_mutex_lock.rs | 3 ++- clippy_lints/src/mutex_atomic.rs | 3 ++- clippy_lints/src/needless_option_as_deref.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- clippy_lints/src/option_if_let_else.rs | 2 +- clippy_lints/src/panic_in_result_fn.rs | 2 +- clippy_lints/src/ptr.rs | 4 ++-- clippy_lints/src/question_mark.rs | 2 +- clippy_lints/src/redundant_clone.rs | 2 +- clippy_lints/src/ref_option_ref.rs | 2 +- clippy_lints/src/repeat_once.rs | 2 +- clippy_lints/src/slow_vector_initialization.rs | 2 +- clippy_lints/src/strings.rs | 4 ++-- clippy_lints/src/swap.rs | 6 +++--- .../src/transmute/unsound_collection_transmute.rs | 8 ++++---- clippy_lints/src/try_err.rs | 8 ++++---- clippy_lints/src/types/box_collection.rs | 6 +++--- clippy_lints/src/types/option_option.rs | 4 ++-- clippy_lints/src/types/rc_buffer.rs | 6 +++--- clippy_lints/src/types/rc_mutex.rs | 2 +- clippy_lints/src/types/vec_box.rs | 2 +- clippy_lints/src/unnecessary_sort_by.rs | 2 +- clippy_lints/src/unnecessary_wraps.rs | 4 ++-- clippy_lints/src/unwrap.rs | 6 +++--- clippy_lints/src/unwrap_in_result.rs | 12 ++++++------ clippy_lints/src/useless_conversion.rs | 8 ++++---- clippy_lints/src/utils/internal_lints.rs | 2 +- clippy_lints/src/vec_init_then_push.rs | 4 ++-- clippy_lints/src/zero_sized_map_values.rs | 2 +- clippy_utils/src/eager_or_lazy.rs | 2 +- clippy_utils/src/lib.rs | 10 +++++----- clippy_utils/src/paths.rs | 4 ++-- clippy_utils/src/ty.rs | 12 ++++++------ tests/ui-internal/match_type_on_diag_item.stderr | 4 ++-- 96 files changed, 196 insertions(+), 193 deletions(-) diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 6f12d34e66b6..8282800c8190 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -260,8 +260,8 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { }, ExprKind::MethodCall(path, _, args, _) if args.len() == 1 => { let type_of_receiver = cx.typeck_results().expr_ty(&args[0]); - if !is_type_diagnostic_item(cx, type_of_receiver, sym::option_type) - && !is_type_diagnostic_item(cx, type_of_receiver, sym::result_type) + if !is_type_diagnostic_item(cx, type_of_receiver, sym::Option) + && !is_type_diagnostic_item(cx, type_of_receiver, sym::Result) { return None; } diff --git a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs index 86b32475cebd..c876553c165b 100644 --- a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs +++ b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs @@ -55,7 +55,7 @@ fn check_case_sensitive_file_extension_comparison(ctx: &LateContext<'_>, expr: & return Some(span); }, ty::Adt(&ty::AdtDef { did, .. }, _) => { - if ctx.tcx.is_diagnostic_item(sym::string_type, did) { + if ctx.tcx.is_diagnostic_item(sym::String, did) { return Some(span); } }, diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index 2203d1c39f17..1ccb8c5d880f 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -67,7 +67,7 @@ impl CognitiveComplexity { helper.visit_expr(expr); let CcHelper { cc, returns } = helper; let ret_ty = cx.typeck_results().node_type(expr.hir_id); - let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym::result_type) { + let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym::Result) { returns } else { #[allow(clippy::integer_division)] diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 84f3b76a3c7d..33ed6273ad2c 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -307,7 +307,7 @@ fn lint_for_missing_headers<'tcx>( } if !headers.errors { let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); - if is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::result_type) { + if is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::Result) { span_lint( cx, MISSING_ERRORS_DOC, @@ -325,7 +325,7 @@ fn lint_for_missing_headers<'tcx>( if let ty::Opaque(_, subs) = ret_ty.kind(); if let Some(gen) = subs.types().next(); if let ty::Generator(_, subs, _) = gen.kind(); - if is_type_diagnostic_item(cx, subs.as_generator().return_ty(), sym::result_type); + if is_type_diagnostic_item(cx, subs.as_generator().return_ty(), sym::Result); then { span_lint( cx, @@ -760,8 +760,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> { // check for `unwrap` if let Some(arglists) = method_chain_args(expr, &["unwrap"]) { let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); - if is_type_diagnostic_item(self.cx, reciever_ty, sym::option_type) - || is_type_diagnostic_item(self.cx, reciever_ty, sym::result_type) + if is_type_diagnostic_item(self.cx, reciever_ty, sym::Option) + || is_type_diagnostic_item(self.cx, reciever_ty, sym::Result) { self.panic_span = Some(expr.span); } diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index f22f52b949e1..70337f5bbeb0 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -57,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom { if_chain! { if let hir::ItemKind::Impl(impl_) = &item.kind; if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id); - if cx.tcx.is_diagnostic_item(sym::from_trait, impl_trait_ref.def_id); + if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.def_id); then { lint_impl_body(cx, item.span, impl_.items); } @@ -94,8 +94,8 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h // check for `unwrap` if let Some(arglists) = method_chain_args(expr, &["unwrap"]) { let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); - if is_type_diagnostic_item(self.lcx, reciever_ty, sym::option_type) - || is_type_diagnostic_item(self.lcx, reciever_ty, sym::result_type) + if is_type_diagnostic_item(self.lcx, reciever_ty, sym::Option) + || is_type_diagnostic_item(self.lcx, reciever_ty, sym::Result) { self.result.push(expr.span); } diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 508cac33848f..129a8475e1c2 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -65,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat { if_chain! { if format_args.format_string_symbols == [kw::Empty]; if match cx.typeck_results().expr_ty(value).peel_refs().kind() { - ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(sym::string_type, adt.did), + ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(sym::String, adt.did), ty::Str => true, _ => false, }; diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index 623546cd1dea..347c6eb12cbc 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -61,7 +61,7 @@ impl LateLintPass<'_> for FromOverInto { if_chain! { if let hir::ItemKind::Impl{ .. } = &item.kind; if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id); - if cx.tcx.is_diagnostic_item(sym::into_trait, impl_trait_ref.def_id); + if cx.tcx.is_diagnostic_item(sym::Into, impl_trait_ref.def_id); then { span_lint_and_help( diff --git a/clippy_lints/src/from_str_radix_10.rs b/clippy_lints/src/from_str_radix_10.rs index cc4bb85c50f7..98ce3db025ca 100644 --- a/clippy_lints/src/from_str_radix_10.rs +++ b/clippy_lints/src/from_str_radix_10.rs @@ -98,5 +98,5 @@ impl LateLintPass<'tcx> for FromStrRadix10 { /// Checks if a Ty is `String` or `&str` fn is_ty_stringish(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { - is_type_diagnostic_item(cx, ty, sym::string_type) || is_type_diagnostic_item(cx, ty, sym::str) + is_type_diagnostic_item(cx, ty, sym::String) || is_type_diagnostic_item(cx, ty, sym::str) } diff --git a/clippy_lints/src/functions/result_unit_err.rs b/clippy_lints/src/functions/result_unit_err.rs index 13863ec8381b..71f6f87ae602 100644 --- a/clippy_lints/src/functions/result_unit_err.rs +++ b/clippy_lints/src/functions/result_unit_err.rs @@ -48,7 +48,7 @@ fn check_result_unit_err(cx: &LateContext<'_>, decl: &hir::FnDecl<'_>, item_span if !in_external_macro(cx.sess(), item_span); if let hir::FnRetTy::Return(ty) = decl.output; let ty = hir_ty_to_ty(cx.tcx, ty); - if is_type_diagnostic_item(cx, ty, sym::result_type); + if is_type_diagnostic_item(cx, ty, sym::Result); if let ty::Adt(_, substs) = ty.kind(); let err_ty = substs.type_at(1); if err_ty.is_unit(); diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 3e35ada7b2a1..e18442515b8f 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { } } if is_future { - let send_trait = cx.tcx.get_diagnostic_item(sym::send_trait).unwrap(); + let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap(); let span = decl.output.span(); let send_result = cx.tcx.infer_ctxt().enter(|infcx| { let cause = traits::ObligationCause::misc(span, hir_id); diff --git a/clippy_lints/src/get_last_with_len.rs b/clippy_lints/src/get_last_with_len.rs index ced35030de83..f3929b0f1e61 100644 --- a/clippy_lints/src/get_last_with_len.rs +++ b/clippy_lints/src/get_last_with_len.rs @@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for GetLastWithLen { // Argument 0 (the struct we're calling the method on) is a vector if let Some(struct_calling_on) = args.get(0); let struct_ty = cx.typeck_results().expr_ty(struct_calling_on); - if is_type_diagnostic_item(cx, struct_ty, sym::vec_type); + if is_type_diagnostic_item(cx, struct_ty, sym::Vec); // Argument to "get" is a subtraction if let Some(get_index_arg) = args.get(1); diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index ef72b88b3c77..a4118bf54b68 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -8,6 +8,7 @@ use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::sym; declare_clippy_lint! { /// ### What it does @@ -141,7 +142,7 @@ fn is_mutex_lock_call<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Opt if let ExprKind::MethodCall(path, _span, [self_arg, ..], _) = &expr.kind; if path.ident.as_str() == "lock"; let ty = cx.typeck_results().expr_ty(self_arg); - if is_type_diagnostic_item(cx, ty, sym!(mutex_type)); + if is_type_diagnostic_item(cx, ty, sym::Mutex); then { Some(self_arg) } else { diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 2fe32fcf6651..9da06d1418e2 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -225,14 +225,14 @@ impl<'tcx> ImplicitHasherType<'tcx> { let ty = hir_ty_to_ty(cx.tcx, hir_ty); - if is_type_diagnostic_item(cx, ty, sym::hashmap_type) && params_len == 2 { + if is_type_diagnostic_item(cx, ty, sym::HashMap) && params_len == 2 { Some(ImplicitHasherType::HashMap( hir_ty.span, ty, snippet(cx, params[0].span, "K"), snippet(cx, params[1].span, "V"), )) - } else if is_type_diagnostic_item(cx, ty, sym::hashset_type) && params_len == 1 { + } else if is_type_diagnostic_item(cx, ty, sym::HashSet) && params_len == 1 { Some(ImplicitHasherType::HashSet( hir_ty.span, ty, @@ -347,7 +347,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't return; } - if self.cx.tcx.is_diagnostic_item(sym::hashmap_type, ty_did) { + if self.cx.tcx.is_diagnostic_item(sym::HashMap, ty_did) { if method.ident.name == sym::new { self.suggestions .insert(e.span, "HashMap::default()".to_string()); @@ -360,7 +360,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't ), ); } - } else if self.cx.tcx.is_diagnostic_item(sym::hashset_type, ty_did) { + } else if self.cx.tcx.is_diagnostic_item(sym::HashSet, ty_did) { if method.ident.name == sym::new { self.suggestions .insert(e.span, "HashSet::default()".to_string()); diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index 58646385def5..68c1fa35fcc4 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -210,11 +210,11 @@ const INFINITE_COLLECTORS: &[Symbol] = &[ sym::BinaryHeap, sym::BTreeMap, sym::BTreeSet, - sym::hashmap_type, - sym::hashset_type, + sym::HashMap, + sym::HashSet, sym::LinkedList, - sym::vec_type, - sym::vecdeque_type, + sym::Vec, + sym::VecDeque, ]; fn complete_infinite_iter(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index b62fad4bd395..3c40ca50a098 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString { if impl_item.generics.params.is_empty(); // Check if return type is String - if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::string_type); + if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::String); // Filters instances of to_string which are required by a trait if trait_ref_of_method(cx, impl_item.hir_id()).is_none(); diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index a519ad90df54..de46e50a68a1 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -245,10 +245,10 @@ enum LenOutput<'tcx> { fn parse_len_output(cx: &LateContext<'_>, sig: FnSig<'tcx>) -> Option> { match *sig.output().kind() { ty::Int(_) | ty::Uint(_) => Some(LenOutput::Integral), - ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::option_type, adt.did) => { + ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Option, adt.did) => { subs.type_at(0).is_integral().then(|| LenOutput::Option(adt.did)) }, - ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::result_type, adt.did) => subs + ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Result, adt.did) => subs .type_at(0) .is_integral() .then(|| LenOutput::Result(adt.did, subs.type_at(1))), diff --git a/clippy_lints/src/loops/explicit_iter_loop.rs b/clippy_lints/src/loops/explicit_iter_loop.rs index 50bc096ba228..5ac69d106ceb 100644 --- a/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_iter_loop.rs @@ -54,11 +54,11 @@ fn is_ref_iterable_type(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { // will allow further borrows afterwards let ty = cx.typeck_results().expr_ty(e); is_iterable_array(ty, cx) || - is_type_diagnostic_item(cx, ty, sym::vec_type) || + is_type_diagnostic_item(cx, ty, sym::Vec) || is_type_diagnostic_item(cx, ty, sym::LinkedList) || - is_type_diagnostic_item(cx, ty, sym::hashmap_type) || - is_type_diagnostic_item(cx, ty, sym::hashset_type) || - is_type_diagnostic_item(cx, ty, sym::vecdeque_type) || + is_type_diagnostic_item(cx, ty, sym::HashMap) || + is_type_diagnostic_item(cx, ty, sym::HashSet) || + is_type_diagnostic_item(cx, ty, sym::VecDeque) || is_type_diagnostic_item(cx, ty, sym::BinaryHeap) || is_type_diagnostic_item(cx, ty, sym::BTreeMap) || is_type_diagnostic_item(cx, ty, sym::BTreeSet) diff --git a/clippy_lints/src/loops/for_kv_map.rs b/clippy_lints/src/loops/for_kv_map.rs index dd60e460d21f..bee0e1d76831 100644 --- a/clippy_lints/src/loops/for_kv_map.rs +++ b/clippy_lints/src/loops/for_kv_map.rs @@ -33,7 +33,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx _ => arg, }; - if is_type_diagnostic_item(cx, ty, sym::hashmap_type) || is_type_diagnostic_item(cx, ty, sym::BTreeMap) { + if is_type_diagnostic_item(cx, ty, sym::HashMap) || is_type_diagnostic_item(cx, ty, sym::BTreeMap) { span_lint_and_then( cx, FOR_KV_MAP, diff --git a/clippy_lints/src/loops/for_loops_over_fallibles.rs b/clippy_lints/src/loops/for_loops_over_fallibles.rs index d49b0517dcf3..90530ebf0031 100644 --- a/clippy_lints/src/loops/for_loops_over_fallibles.rs +++ b/clippy_lints/src/loops/for_loops_over_fallibles.rs @@ -9,7 +9,7 @@ use rustc_span::symbol::sym; /// Checks for `for` loops over `Option`s and `Result`s. pub(super) fn check(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) { let ty = cx.typeck_results().expr_ty(arg); - if is_type_diagnostic_item(cx, ty, sym::option_type) { + if is_type_diagnostic_item(cx, ty, sym::Option) { span_lint_and_help( cx, FOR_LOOPS_OVER_FALLIBLES, @@ -26,7 +26,7 @@ pub(super) fn check(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) { snippet(cx, arg.span, "_") ), ); - } else if is_type_diagnostic_item(cx, ty, sym::result_type) { + } else if is_type_diagnostic_item(cx, ty, sym::Result) { span_lint_and_help( cx, FOR_LOOPS_OVER_FALLIBLES, diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index 2296842e86f5..72027a163af8 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -332,7 +332,7 @@ fn is_slice_like<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'_>) -> bool { _ => false, }; - is_slice || is_type_diagnostic_item(cx, ty, sym::vec_type) || is_type_diagnostic_item(cx, ty, sym::vecdeque_type) + is_slice || is_type_diagnostic_item(cx, ty, sym::Vec) || is_type_diagnostic_item(cx, ty, sym::VecDeque) } fn fetch_cloned_expr<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { diff --git a/clippy_lints/src/loops/needless_collect.rs b/clippy_lints/src/loops/needless_collect.rs index f90ed7397e18..e87f4b669124 100644 --- a/clippy_lints/src/loops/needless_collect.rs +++ b/clippy_lints/src/loops/needless_collect.rs @@ -29,8 +29,8 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont let mut applicability = Applicability::MaybeIncorrect; let is_empty_sugg = "next().is_none()".to_string(); let method_name = &*method.ident.name.as_str(); - let sugg = if is_type_diagnostic_item(cx, ty, sym::vec_type) || - is_type_diagnostic_item(cx, ty, sym::vecdeque_type) || + let sugg = if is_type_diagnostic_item(cx, ty, sym::Vec) || + is_type_diagnostic_item(cx, ty, sym::VecDeque) || is_type_diagnostic_item(cx, ty, sym::LinkedList) || is_type_diagnostic_item(cx, ty, sym::BinaryHeap) { match method_name { @@ -47,7 +47,7 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont } } else if is_type_diagnostic_item(cx, ty, sym::BTreeMap) || - is_type_diagnostic_item(cx, ty, sym::hashmap_type) { + is_type_diagnostic_item(cx, ty, sym::HashMap) { match method_name { "is_empty" => is_empty_sugg, _ => return, @@ -79,8 +79,8 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo if let ExprKind::MethodCall(method_name, collect_span, &[ref iter_source], ..) = init_expr.kind; if method_name.ident.name == sym!(collect) && is_trait_method(cx, init_expr, sym::Iterator); let ty = cx.typeck_results().expr_ty(init_expr); - if is_type_diagnostic_item(cx, ty, sym::vec_type) || - is_type_diagnostic_item(cx, ty, sym::vecdeque_type) || + if is_type_diagnostic_item(cx, ty, sym::Vec) || + is_type_diagnostic_item(cx, ty, sym::VecDeque) || is_type_diagnostic_item(cx, ty, sym::BinaryHeap) || is_type_diagnostic_item(cx, ty, sym::LinkedList); if let Some(iter_calls) = detect_iter_and_into_iters(block, id); diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index 545498a10478..2eb247de9f42 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -192,7 +192,7 @@ fn get_vec_push<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) -> Option<(& if let Some(self_expr) = args.get(0); if let Some(pushed_item) = args.get(1); // Check that the method being called is push() on a Vec - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(self_expr), sym::vec_type); + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(self_expr), sym::Vec); if path.ident.name.as_str() == "push"; then { return Some((self_expr, pushed_item)) diff --git a/clippy_lints/src/manual_map.rs b/clippy_lints/src/manual_map.rs index b5f573cb104e..96df3d0a490f 100644 --- a/clippy_lints/src/manual_map.rs +++ b/clippy_lints/src/manual_map.rs @@ -61,8 +61,8 @@ impl LateLintPass<'_> for ManualMap { let (scrutinee_ty, ty_ref_count, ty_mutability) = peel_mid_ty_refs_is_mutable(cx.typeck_results().expr_ty(scrutinee)); - if !(is_type_diagnostic_item(cx, scrutinee_ty, sym::option_type) - && is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::option_type)) + if !(is_type_diagnostic_item(cx, scrutinee_ty, sym::Option) + && is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::Option)) { return; } diff --git a/clippy_lints/src/manual_ok_or.rs b/clippy_lints/src/manual_ok_or.rs index b2f287af6971..cf641d0ce862 100644 --- a/clippy_lints/src/manual_ok_or.rs +++ b/clippy_lints/src/manual_ok_or.rs @@ -51,7 +51,7 @@ impl LateLintPass<'_> for ManualOkOr { if args.len() == 3; let method_receiver = &args[0]; let ty = cx.typeck_results().expr_ty(method_receiver); - if is_type_diagnostic_item(cx, ty, sym::option_type); + if is_type_diagnostic_item(cx, ty, sym::Option); let or_expr = &args[1]; if is_ok_wrapping(cx, &args[2]); if let ExprKind::Call(Expr { kind: ExprKind::Path(err_path), .. }, &[ref err_arg]) = or_expr.kind; diff --git a/clippy_lints/src/manual_unwrap_or.rs b/clippy_lints/src/manual_unwrap_or.rs index 426789742d51..2ae9cb4f9c13 100644 --- a/clippy_lints/src/manual_unwrap_or.rs +++ b/clippy_lints/src/manual_unwrap_or.rs @@ -82,9 +82,9 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if_chain! { if let ExprKind::Match(scrutinee, match_arms, _) = expr.kind; let ty = cx.typeck_results().expr_ty(scrutinee); - if let Some(ty_name) = if is_type_diagnostic_item(cx, ty, sym::option_type) { + if let Some(ty_name) = if is_type_diagnostic_item(cx, ty, sym::Option) { Some("Option") - } else if is_type_diagnostic_item(cx, ty, sym::result_type) { + } else if is_type_diagnostic_item(cx, ty, sym::Result) { Some("Result") } else { None diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 394606200bb0..7db5c7e52ea4 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone { if args.len() == 2; if method.ident.name == sym::map; let ty = cx.typeck_results().expr_ty(&args[0]); - if is_type_diagnostic_item(cx, ty, sym::option_type) || is_trait_method(cx, e, sym::Iterator); + if is_type_diagnostic_item(cx, ty, sym::Option) || is_trait_method(cx, e, sym::Iterator); if let hir::ExprKind::Closure(_, _, body_id, _, _) = args[1].kind; then { let closure_body = cx.tcx.hir().body(body_id); diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index fd40590d077f..952e250bb9e6 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -206,9 +206,9 @@ fn lint_map_unit_fn(cx: &LateContext<'_>, stmt: &hir::Stmt<'_>, expr: &hir::Expr let var_arg = &map_args[0]; let (map_type, variant, lint) = - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(var_arg), sym::option_type) { + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(var_arg), sym::Option) { ("Option", "Some", OPTION_MAP_UNIT_FN) - } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(var_arg), sym::result_type) { + } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(var_arg), sym::Result) { ("Result", "Ok", RESULT_MAP_UNIT_FN) } else { return; diff --git a/clippy_lints/src/match_on_vec_items.rs b/clippy_lints/src/match_on_vec_items.rs index e66a35452f0d..552c9a588977 100644 --- a/clippy_lints/src/match_on_vec_items.rs +++ b/clippy_lints/src/match_on_vec_items.rs @@ -93,7 +93,7 @@ fn is_vec_indexing<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Opti fn is_vector(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let ty = cx.typeck_results().expr_ty(expr); let ty = ty.peel_refs(); - is_type_diagnostic_item(cx, ty, sym::vec_type) + is_type_diagnostic_item(cx, ty, sym::Vec) } fn is_full_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { diff --git a/clippy_lints/src/match_result_ok.rs b/clippy_lints/src/match_result_ok.rs index c7de06f0815a..3db1f0421ea7 100644 --- a/clippy_lints/src/match_result_ok.rs +++ b/clippy_lints/src/match_result_ok.rs @@ -60,7 +60,7 @@ impl<'tcx> LateLintPass<'tcx> for MatchResultOk { if let ExprKind::MethodCall(_, ok_span, [ref result_types_0, ..], _) = let_expr.kind; //check is expr.ok() has type Result.ok(, _) if let PatKind::TupleStruct(QPath::Resolved(_, x), y, _) = let_pat.kind; //get operation if method_chain_args(let_expr, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized; - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(result_types_0), sym::result_type); + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(result_types_0), sym::Result); if rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(x, false)) == "Some"; then { diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index d878fbc35fdc..a685c1eaa2cd 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -948,7 +948,7 @@ fn check_overlapping_arms<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'_>, arms fn check_wild_err_arm<'tcx>(cx: &LateContext<'tcx>, ex: &Expr<'tcx>, arms: &[Arm<'tcx>]) { let ex_ty = cx.typeck_results().expr_ty(ex).peel_refs(); - if is_type_diagnostic_item(cx, ex_ty, sym::result_type) { + if is_type_diagnostic_item(cx, ex_ty, sym::Result) { for arm in arms { if let PatKind::TupleStruct(ref path, inner, _) = arm.pat.kind { let path_str = rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false)); @@ -1025,8 +1025,8 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) let adt_def = match ty.kind() { ty::Adt(adt_def, _) if adt_def.is_enum() - && !(is_type_diagnostic_item(cx, ty, sym::option_type) - || is_type_diagnostic_item(cx, ty, sym::result_type)) => + && !(is_type_diagnostic_item(cx, ty, sym::Option) + || is_type_diagnostic_item(cx, ty, sym::Result)) => { adt_def }, @@ -1869,7 +1869,7 @@ mod redundant_pattern_match { } } // Check for std types which implement drop, but only for memory allocation. - else if is_type_diagnostic_item(cx, ty, sym::vec_type) + else if is_type_diagnostic_item(cx, ty, sym::Vec) || is_type_lang_item(cx, ty, LangItem::OwnedBox) || is_type_diagnostic_item(cx, ty, sym::Rc) || is_type_diagnostic_item(cx, ty, sym::Arc) diff --git a/clippy_lints/src/methods/bytes_nth.rs b/clippy_lints/src/methods/bytes_nth.rs index 2ad3e673c574..76eaedea8a0d 100644 --- a/clippy_lints/src/methods/bytes_nth.rs +++ b/clippy_lints/src/methods/bytes_nth.rs @@ -12,7 +12,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, recv: &'tcx E let ty = cx.typeck_results().expr_ty(recv).peel_refs(); let caller_type = if ty.is_str() { "str" - } else if is_type_diagnostic_item(cx, ty, sym::string_type) { + } else if is_type_diagnostic_item(cx, ty, sym::String) { "String" } else { return; diff --git a/clippy_lints/src/methods/cloned_instead_of_copied.rs b/clippy_lints/src/methods/cloned_instead_of_copied.rs index f5b4b6bf8ea2..6fe69b8f01f9 100644 --- a/clippy_lints/src/methods/cloned_instead_of_copied.rs +++ b/clippy_lints/src/methods/cloned_instead_of_copied.rs @@ -15,7 +15,7 @@ pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span: Span, let inner_ty = match recv_ty.kind() { // `Option` -> `T` ty::Adt(adt, subst) - if cx.tcx.is_diagnostic_item(sym::option_type, adt.did) && meets_msrv(msrv, &msrvs::OPTION_COPIED) => + if cx.tcx.is_diagnostic_item(sym::Option, adt.did) && meets_msrv(msrv, &msrvs::OPTION_COPIED) => { subst.type_at(0) }, diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index f8ee31a00df8..0ec9387f9c46 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -28,7 +28,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, method_span: Spa && { let arg_type = cx.typeck_results().expr_ty(&call_args[0]); let base_type = arg_type.peel_refs(); - *base_type.kind() == ty::Str || is_type_diagnostic_item(cx, base_type, sym::string_type) + *base_type.kind() == ty::Str || is_type_diagnostic_item(cx, base_type, sym::String) } { &call_args[0] @@ -46,7 +46,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, method_span: Spa // converted to string. fn requires_to_string(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool { let arg_ty = cx.typeck_results().expr_ty(arg); - if is_type_diagnostic_item(cx, arg_ty, sym::string_type) { + if is_type_diagnostic_item(cx, arg_ty, sym::String) { return false; } if let ty::Ref(_, ty, ..) = arg_ty.kind() { @@ -113,9 +113,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, method_span: Spa } let receiver_type = cx.typeck_results().expr_ty_adjusted(&args[0]); - let closure_args = if is_type_diagnostic_item(cx, receiver_type, sym::option_type) { + let closure_args = if is_type_diagnostic_item(cx, receiver_type, sym::Option) { "||" - } else if is_type_diagnostic_item(cx, receiver_type, sym::result_type) { + } else if is_type_diagnostic_item(cx, receiver_type, sym::Result) { "|_|" } else { return; diff --git a/clippy_lints/src/methods/expect_used.rs b/clippy_lints/src/methods/expect_used.rs index 63a834fdce0c..55be513c5bb1 100644 --- a/clippy_lints/src/methods/expect_used.rs +++ b/clippy_lints/src/methods/expect_used.rs @@ -10,9 +10,9 @@ use super::EXPECT_USED; pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) { let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs(); - let mess = if is_type_diagnostic_item(cx, obj_ty, sym::option_type) { + let mess = if is_type_diagnostic_item(cx, obj_ty, sym::Option) { Some((EXPECT_USED, "an Option", "None")) - } else if is_type_diagnostic_item(cx, obj_ty, sym::result_type) { + } else if is_type_diagnostic_item(cx, obj_ty, sym::Result) { Some((EXPECT_USED, "a Result", "Err")) } else { None diff --git a/clippy_lints/src/methods/extend_with_drain.rs b/clippy_lints/src/methods/extend_with_drain.rs index 8829b8c5f4df..687636f8237f 100644 --- a/clippy_lints/src/methods/extend_with_drain.rs +++ b/clippy_lints/src/methods/extend_with_drain.rs @@ -12,7 +12,7 @@ use super::EXTEND_WITH_DRAIN; pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: &Expr<'_>) { let ty = cx.typeck_results().expr_ty(recv).peel_refs(); if_chain! { - if is_type_diagnostic_item(cx, ty, sym::vec_type); + if is_type_diagnostic_item(cx, ty, sym::Vec); //check source object if let ExprKind::MethodCall(src_method, _, [drain_vec, drain_arg], _) = &arg.kind; if src_method.ident.as_str() == "drain"; @@ -20,7 +20,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: //check if actual src type is mutable for code suggestion let immutable = src_ty.is_mutable_ptr(); let src_ty = src_ty.peel_refs(); - if is_type_diagnostic_item(cx, src_ty, sym::vec_type); + if is_type_diagnostic_item(cx, src_ty, sym::Vec); //check drain range if let src_ty_range = cx.typeck_results().expr_ty(drain_arg).peel_refs(); if is_type_lang_item(cx, src_ty_range, LangItem::RangeFull); diff --git a/clippy_lints/src/methods/filter_map.rs b/clippy_lints/src/methods/filter_map.rs index 35fae450eeb9..c96c817bb8bd 100644 --- a/clippy_lints/src/methods/filter_map.rs +++ b/clippy_lints/src/methods/filter_map.rs @@ -61,7 +61,7 @@ fn lint_filter_some_map_unwrap( methods_span: Span, ) { let iterator = is_trait_method(cx, expr, sym::Iterator); - let option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(filter_recv), sym::option_type); + let option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(filter_recv), sym::Option); if (iterator || option) && is_option_filter_map(cx, filter_arg, map_arg) { let msg = "`filter` for `Some` followed by `unwrap`"; let help = "consider using `flatten` instead"; @@ -120,9 +120,9 @@ pub(super) fn check<'tcx>( if let PatKind::Binding(_, filter_param_id, _, None) = filter_pat.kind; if let ExprKind::MethodCall(path, _, [filter_arg], _) = filter_body.value.kind; if let Some(opt_ty) = cx.typeck_results().expr_ty(filter_arg).ty_adt_def(); - if let Some(is_result) = if cx.tcx.is_diagnostic_item(sym::option_type, opt_ty.did) { + if let Some(is_result) = if cx.tcx.is_diagnostic_item(sym::Option, opt_ty.did) { Some(false) - } else if cx.tcx.is_diagnostic_item(sym::result_type, opt_ty.did) { + } else if cx.tcx.is_diagnostic_item(sym::Result, opt_ty.did) { Some(true) } else { None diff --git a/clippy_lints/src/methods/flat_map_option.rs b/clippy_lints/src/methods/flat_map_option.rs index 32d40d97bf41..615bde941334 100644 --- a/clippy_lints/src/methods/flat_map_option.rs +++ b/clippy_lints/src/methods/flat_map_option.rs @@ -19,7 +19,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, arg _ if arg_ty.is_fn() => arg_ty.fn_sig(cx.tcx), _ => return, }; - if !is_type_diagnostic_item(cx, sig.output().skip_binder(), sym::option_type) { + if !is_type_diagnostic_item(cx, sig.output().skip_binder(), sym::Option) { return; } span_lint_and_sugg( diff --git a/clippy_lints/src/methods/get_unwrap.rs b/clippy_lints/src/methods/get_unwrap.rs index 66fb85deae5e..18e08d6ee232 100644 --- a/clippy_lints/src/methods/get_unwrap.rs +++ b/clippy_lints/src/methods/get_unwrap.rs @@ -27,13 +27,13 @@ pub(super) fn check<'tcx>( let caller_type = if derefs_to_slice(cx, recv, expr_ty).is_some() { needs_ref = get_args_str.parse::().is_ok(); "slice" - } else if is_type_diagnostic_item(cx, expr_ty, sym::vec_type) { + } else if is_type_diagnostic_item(cx, expr_ty, sym::Vec) { needs_ref = get_args_str.parse::().is_ok(); "Vec" - } else if is_type_diagnostic_item(cx, expr_ty, sym::vecdeque_type) { + } else if is_type_diagnostic_item(cx, expr_ty, sym::VecDeque) { needs_ref = get_args_str.parse::().is_ok(); "VecDeque" - } else if !is_mut && is_type_diagnostic_item(cx, expr_ty, sym::hashmap_type) { + } else if !is_mut && is_type_diagnostic_item(cx, expr_ty, sym::HashMap) { needs_ref = true; "HashMap" } else if !is_mut && is_type_diagnostic_item(cx, expr_ty, sym::BTreeMap) { diff --git a/clippy_lints/src/methods/inefficient_to_string.rs b/clippy_lints/src/methods/inefficient_to_string.rs index 950ec62c9fe4..c0f66feb48ae 100644 --- a/clippy_lints/src/methods/inefficient_to_string.rs +++ b/clippy_lints/src/methods/inefficient_to_string.rs @@ -55,7 +55,7 @@ fn specializes_tostring(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { return true; } - if is_type_diagnostic_item(cx, ty, sym::string_type) { + if is_type_diagnostic_item(cx, ty, sym::String) { return true; } diff --git a/clippy_lints/src/methods/iter_cloned_collect.rs b/clippy_lints/src/methods/iter_cloned_collect.rs index 739f313716e9..dd4ef6e4b58e 100644 --- a/clippy_lints/src/methods/iter_cloned_collect.rs +++ b/clippy_lints/src/methods/iter_cloned_collect.rs @@ -11,7 +11,7 @@ use super::ITER_CLONED_COLLECT; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, recv: &'tcx hir::Expr<'_>) { if_chain! { - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::vec_type); + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::Vec); if let Some(slice) = derefs_to_slice(cx, recv, cx.typeck_results().expr_ty(recv)); if let Some(to_replace) = expr.span.trim_start(slice.span.source_callsite()); diff --git a/clippy_lints/src/methods/iter_count.rs b/clippy_lints/src/methods/iter_count.rs index b69f57f50e0f..052be3d8ee7c 100644 --- a/clippy_lints/src/methods/iter_count.rs +++ b/clippy_lints/src/methods/iter_count.rs @@ -13,13 +13,13 @@ pub(crate) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, recv: &'tcx E let ty = cx.typeck_results().expr_ty(recv); let caller_type = if derefs_to_slice(cx, recv, ty).is_some() { "slice" - } else if is_type_diagnostic_item(cx, ty, sym::vec_type) { + } else if is_type_diagnostic_item(cx, ty, sym::Vec) { "Vec" - } else if is_type_diagnostic_item(cx, ty, sym::vecdeque_type) { + } else if is_type_diagnostic_item(cx, ty, sym::VecDeque) { "VecDeque" - } else if is_type_diagnostic_item(cx, ty, sym::hashset_type) { + } else if is_type_diagnostic_item(cx, ty, sym::HashSet) { "HashSet" - } else if is_type_diagnostic_item(cx, ty, sym::hashmap_type) { + } else if is_type_diagnostic_item(cx, ty, sym::HashMap) { "HashMap" } else if is_type_diagnostic_item(cx, ty, sym::BTreeMap) { "BTreeMap" diff --git a/clippy_lints/src/methods/iter_next_slice.rs b/clippy_lints/src/methods/iter_next_slice.rs index 6954da67e32c..d053ff567565 100644 --- a/clippy_lints/src/methods/iter_next_slice.rs +++ b/clippy_lints/src/methods/iter_next_slice.rs @@ -64,6 +64,6 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, cal } fn is_vec_or_array<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) -> bool { - is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::vec_type) + is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::Vec) || matches!(&cx.typeck_results().expr_ty(expr).peel_refs().kind(), ty::Array(_, _)) } diff --git a/clippy_lints/src/methods/iter_nth.rs b/clippy_lints/src/methods/iter_nth.rs index c2232239fe43..80ca4c94219f 100644 --- a/clippy_lints/src/methods/iter_nth.rs +++ b/clippy_lints/src/methods/iter_nth.rs @@ -19,9 +19,9 @@ pub(super) fn check<'tcx>( let mut_str = if is_mut { "_mut" } else { "" }; let caller_type = if derefs_to_slice(cx, iter_recv, cx.typeck_results().expr_ty(iter_recv)).is_some() { "slice" - } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(iter_recv), sym::vec_type) { + } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(iter_recv), sym::Vec) { "Vec" - } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(iter_recv), sym::vecdeque_type) { + } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(iter_recv), sym::VecDeque) { "VecDeque" } else { iter_nth_zero::check(cx, expr, nth_recv, nth_arg); diff --git a/clippy_lints/src/methods/manual_split_once.rs b/clippy_lints/src/methods/manual_split_once.rs index 55688677e1d1..13eb72251bb1 100644 --- a/clippy_lints/src/methods/manual_split_once.rs +++ b/clippy_lints/src/methods/manual_split_once.rs @@ -123,7 +123,7 @@ fn parse_iter_usage( return if_chain! { if match_def_path(cx, did, &paths::ITERTOOLS_NEXT_TUPLE); if let ty::Adt(adt_def, subs) = cx.typeck_results().expr_ty(e).kind(); - if cx.tcx.is_diagnostic_item(sym::option_type, adt_def.did); + if cx.tcx.is_diagnostic_item(sym::Option, adt_def.did); if let ty::Tuple(subs) = subs.type_at(0).kind(); if subs.len() == 2; then { @@ -193,7 +193,7 @@ fn parse_iter_usage( && cx .typeck_results() .type_dependent_def_id(e.hir_id) - .map_or(false, |id| is_diag_item_method(cx, id, sym::option_type)) => + .map_or(false, |id| is_diag_item_method(cx, id, sym::Option)) => { (Some(UnwrapKind::Unwrap), e.span) }, diff --git a/clippy_lints/src/methods/manual_str_repeat.rs b/clippy_lints/src/methods/manual_str_repeat.rs index 919e2628c523..d74c910b6767 100644 --- a/clippy_lints/src/methods/manual_str_repeat.rs +++ b/clippy_lints/src/methods/manual_str_repeat.rs @@ -36,14 +36,14 @@ fn parse_repeat_arg(cx: &LateContext<'_>, e: &Expr<'_>) -> Option { } } else { let ty = cx.typeck_results().expr_ty(e); - if is_type_diagnostic_item(cx, ty, sym::string_type) + if is_type_diagnostic_item(cx, ty, sym::String) || (is_type_lang_item(cx, ty, LangItem::OwnedBox) && get_ty_param(ty).map_or(false, TyS::is_str)) || (match_type(cx, ty, &paths::COW) && get_ty_param(ty).map_or(false, TyS::is_str)) { Some(RepeatKind::String) } else { let ty = ty.peel_refs(); - (ty.is_str() || is_type_diagnostic_item(cx, ty, sym::string_type)).then(|| RepeatKind::String) + (ty.is_str() || is_type_diagnostic_item(cx, ty, sym::String)).then(|| RepeatKind::String) } } } @@ -58,7 +58,7 @@ pub(super) fn check( if_chain! { if let ExprKind::Call(repeat_fn, [repeat_arg]) = take_self_arg.kind; if is_expr_path_def_path(cx, repeat_fn, &paths::ITER_REPEAT); - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(collect_expr), sym::string_type); + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(collect_expr), sym::String); if let Some(collect_id) = cx.typeck_results().type_dependent_def_id(collect_expr.hir_id); if let Some(take_id) = cx.typeck_results().type_dependent_def_id(take_expr.hir_id); if let Some(iter_trait_id) = cx.tcx.get_diagnostic_item(sym::Iterator); diff --git a/clippy_lints/src/methods/map_collect_result_unit.rs b/clippy_lints/src/methods/map_collect_result_unit.rs index 82063ad70b53..d420f144eea1 100644 --- a/clippy_lints/src/methods/map_collect_result_unit.rs +++ b/clippy_lints/src/methods/map_collect_result_unit.rs @@ -23,7 +23,7 @@ pub(super) fn check( if is_trait_method(cx, collect_recv, sym::Iterator); // return of collect `Result<(),_>` let collect_ret_ty = cx.typeck_results().expr_ty(expr); - if is_type_diagnostic_item(cx, collect_ret_ty, sym::result_type); + if is_type_diagnostic_item(cx, collect_ret_ty, sym::Result); if let ty::Adt(_, substs) = collect_ret_ty.kind(); if let Some(result_t) = substs.types().next(); if result_t.is_unit(); diff --git a/clippy_lints/src/methods/map_flatten.rs b/clippy_lints/src/methods/map_flatten.rs index 08d3a7ce92bb..6782f64f2ca4 100644 --- a/clippy_lints/src/methods/map_flatten.rs +++ b/clippy_lints/src/methods/map_flatten.rs @@ -27,7 +27,7 @@ pub(super) fn check<'tcx>( _ => map_closure_ty.fn_sig(cx.tcx), }; let map_closure_return_ty = cx.tcx.erase_late_bound_regions(map_closure_sig.output()); - is_type_diagnostic_item(cx, map_closure_return_ty, sym::option_type) + is_type_diagnostic_item(cx, map_closure_return_ty, sym::Option) }, _ => false, }; @@ -55,9 +55,9 @@ pub(super) fn check<'tcx>( // lint if caller of `.map().flatten()` is an Option or Result let caller_type = match cx.typeck_results().expr_ty(recv).kind() { ty::Adt(adt, _) => { - if cx.tcx.is_diagnostic_item(sym::option_type, adt.did) { + if cx.tcx.is_diagnostic_item(sym::Option, adt.did) { "Option" - } else if cx.tcx.is_diagnostic_item(sym::result_type, adt.did) { + } else if cx.tcx.is_diagnostic_item(sym::Result, adt.did) { "Result" } else { return; diff --git a/clippy_lints/src/methods/map_identity.rs b/clippy_lints/src/methods/map_identity.rs index 538a12566e30..f112b500d3d2 100644 --- a/clippy_lints/src/methods/map_identity.rs +++ b/clippy_lints/src/methods/map_identity.rs @@ -19,8 +19,8 @@ pub(super) fn check( if_chain! { if is_trait_method(cx, expr, sym::Iterator) - || is_type_diagnostic_item(cx, caller_ty, sym::result_type) - || is_type_diagnostic_item(cx, caller_ty, sym::option_type); + || is_type_diagnostic_item(cx, caller_ty, sym::Result) + || is_type_diagnostic_item(cx, caller_ty, sym::Option); if is_expr_identity_function(cx, map_arg); if let Some(sugg_span) = expr.span.trim_start(caller.span); then { diff --git a/clippy_lints/src/methods/map_unwrap_or.rs b/clippy_lints/src/methods/map_unwrap_or.rs index 4d8365fcda12..9ec84e76519a 100644 --- a/clippy_lints/src/methods/map_unwrap_or.rs +++ b/clippy_lints/src/methods/map_unwrap_or.rs @@ -22,8 +22,8 @@ pub(super) fn check<'tcx>( msrv: Option<&RustcVersion>, ) -> bool { // lint if the caller of `map()` is an `Option` - let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::option_type); - let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::result_type); + let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option); + let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result); if is_result && !meets_msrv(msrv, &msrvs::RESULT_MAP_OR_ELSE) { return false; diff --git a/clippy_lints/src/methods/ok_expect.rs b/clippy_lints/src/methods/ok_expect.rs index d0b1b4b84be5..d64a9f320d90 100644 --- a/clippy_lints/src/methods/ok_expect.rs +++ b/clippy_lints/src/methods/ok_expect.rs @@ -12,7 +12,7 @@ use super::OK_EXPECT; pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) { if_chain! { // lint if the caller of `ok()` is a `Result` - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::result_type); + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result); let result_type = cx.typeck_results().expr_ty(recv); if let Some(error_type) = get_error_type(cx, result_type); if has_debug_impl(error_type, cx); @@ -33,7 +33,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr /// Given a `Result` type, return its error type (`E`). fn get_error_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option> { match ty.kind() { - ty::Adt(_, substs) if is_type_diagnostic_item(cx, ty, sym::result_type) => substs.types().nth(1), + ty::Adt(_, substs) if is_type_diagnostic_item(cx, ty, sym::Result) => substs.types().nth(1), _ => None, } } @@ -41,6 +41,6 @@ fn get_error_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option> { /// This checks whether a given type is known to implement Debug. fn has_debug_impl<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool { cx.tcx - .get_diagnostic_item(sym::debug_trait) + .get_diagnostic_item(sym::Debug) .map_or(false, |debug| implements_trait(cx, ty, debug, &[])) } diff --git a/clippy_lints/src/methods/option_as_ref_deref.rs b/clippy_lints/src/methods/option_as_ref_deref.rs index 5a57135038fd..d3f40d262080 100644 --- a/clippy_lints/src/methods/option_as_ref_deref.rs +++ b/clippy_lints/src/methods/option_as_ref_deref.rs @@ -28,7 +28,7 @@ pub(super) fn check<'tcx>( let same_mutability = |m| (is_mut && m == &hir::Mutability::Mut) || (!is_mut && m == &hir::Mutability::Not); let option_ty = cx.typeck_results().expr_ty(as_ref_recv); - if !is_type_diagnostic_item(cx, option_ty, sym::option_type) { + if !is_type_diagnostic_item(cx, option_ty, sym::Option) { return; } diff --git a/clippy_lints/src/methods/option_map_or_none.rs b/clippy_lints/src/methods/option_map_or_none.rs index 36a1c13d5be1..e99b6b07d156 100644 --- a/clippy_lints/src/methods/option_map_or_none.rs +++ b/clippy_lints/src/methods/option_map_or_none.rs @@ -19,8 +19,8 @@ pub(super) fn check<'tcx>( def_arg: &'tcx hir::Expr<'_>, map_arg: &'tcx hir::Expr<'_>, ) { - let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::option_type); - let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::result_type); + let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option); + let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result); // There are two variants of this `map_or` lint: // (1) using `map_or` as an adapter from `Result` to `Option` diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 5bca49dec241..2faa6a69f81d 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -25,7 +25,7 @@ pub(super) fn check<'tcx>( map_span: Span, ) { // lint if the caller of `map()` is an `Option` - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::option_type) { + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option) { if !is_copy(cx, cx.typeck_results().expr_ty(unwrap_arg)) { // Do not lint if the `map` argument uses identifiers in the `map` // argument that are also used in the `unwrap_or` argument diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index 30ed1d665a90..cabbb8400767 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -105,7 +105,7 @@ pub(super) fn check<'tcx>( _ => (), } - if is_type_diagnostic_item(cx, ty, sym::vec_type) { + if is_type_diagnostic_item(cx, ty, sym::Vec) { return; } } diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs index ecec6fc3bb7f..0f2e58d8983f 100644 --- a/clippy_lints/src/methods/search_is_some.rs +++ b/clippy_lints/src/methods/search_is_some.rs @@ -101,7 +101,7 @@ pub(super) fn check<'tcx>( else if search_method == "find" { let is_string_or_str_slice = |e| { let self_ty = cx.typeck_results().expr_ty(e).peel_refs(); - if is_type_diagnostic_item(cx, self_ty, sym::string_type) { + if is_type_diagnostic_item(cx, self_ty, sym::String) { true } else { *self_ty.kind() == ty::Str diff --git a/clippy_lints/src/methods/string_extend_chars.rs b/clippy_lints/src/methods/string_extend_chars.rs index 6e7890a3080e..d06658f2a5e6 100644 --- a/clippy_lints/src/methods/string_extend_chars.rs +++ b/clippy_lints/src/methods/string_extend_chars.rs @@ -12,7 +12,7 @@ use super::STRING_EXTEND_CHARS; pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>) { let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs(); - if !is_type_diagnostic_item(cx, obj_ty, sym::string_type) { + if !is_type_diagnostic_item(cx, obj_ty, sym::String) { return; } if let Some(arglists) = method_chain_args(arg, &["chars"]) { @@ -20,7 +20,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr let self_ty = cx.typeck_results().expr_ty(target).peel_refs(); let ref_str = if *self_ty.kind() == ty::Str { "" - } else if is_type_diagnostic_item(cx, self_ty, sym::string_type) { + } else if is_type_diagnostic_item(cx, self_ty, sym::String) { "&" } else { return; diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index 8b66587bfd16..a9d3764d92d4 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -35,7 +35,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr< let in_ty = cx.typeck_results().node_type(body.params[0].hir_id); match cx.typeck_results().expr_ty(&body.value).kind() { ty::Adt(adt, subst) - if cx.tcx.is_diagnostic_item(sym::option_type, adt.did) + if cx.tcx.is_diagnostic_item(sym::Option, adt.did) && TyS::same_type(in_ty, subst.type_at(0)) => { "filter" diff --git a/clippy_lints/src/methods/unnecessary_lazy_eval.rs b/clippy_lints/src/methods/unnecessary_lazy_eval.rs index b7380883a5ee..740af750b48a 100644 --- a/clippy_lints/src/methods/unnecessary_lazy_eval.rs +++ b/clippy_lints/src/methods/unnecessary_lazy_eval.rs @@ -18,8 +18,8 @@ pub(super) fn check<'tcx>( arg: &'tcx hir::Expr<'_>, simplify_using: &str, ) { - let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::option_type); - let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::result_type); + let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option); + let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result); if is_option || is_result { if let hir::ExprKind::Closure(_, _, eid, _, _) = arg.kind { diff --git a/clippy_lints/src/methods/unwrap_or_else_default.rs b/clippy_lints/src/methods/unwrap_or_else_default.rs index 677aa80e1b76..276467b1dfdb 100644 --- a/clippy_lints/src/methods/unwrap_or_else_default.rs +++ b/clippy_lints/src/methods/unwrap_or_else_default.rs @@ -19,8 +19,8 @@ pub(super) fn check<'tcx>( // ^^^^^^^^^- recv ^^^^^^^^^^^^^^^^- u_arg // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- expr let recv_ty = cx.typeck_results().expr_ty(recv); - let is_option = is_type_diagnostic_item(cx, recv_ty, sym::option_type); - let is_result = is_type_diagnostic_item(cx, recv_ty, sym::result_type); + let is_option = is_type_diagnostic_item(cx, recv_ty, sym::Option); + let is_result = is_type_diagnostic_item(cx, recv_ty, sym::Result); if_chain! { if is_option || is_result; diff --git a/clippy_lints/src/methods/unwrap_used.rs b/clippy_lints/src/methods/unwrap_used.rs index 7fd1948594d7..44676d78c607 100644 --- a/clippy_lints/src/methods/unwrap_used.rs +++ b/clippy_lints/src/methods/unwrap_used.rs @@ -10,9 +10,9 @@ use super::UNWRAP_USED; pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) { let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs(); - let mess = if is_type_diagnostic_item(cx, obj_ty, sym::option_type) { + let mess = if is_type_diagnostic_item(cx, obj_ty, sym::Option) { Some((UNWRAP_USED, "an Option", "None")) - } else if is_type_diagnostic_item(cx, obj_ty, sym::result_type) { + } else if is_type_diagnostic_item(cx, obj_ty, sym::Result) { Some((UNWRAP_USED, "a Result", "Err")) } else { None diff --git a/clippy_lints/src/methods/utils.rs b/clippy_lints/src/methods/utils.rs index 30d6665a920b..ba2ce73a1165 100644 --- a/clippy_lints/src/methods/utils.rs +++ b/clippy_lints/src/methods/utils.rs @@ -17,7 +17,7 @@ pub(super) fn derefs_to_slice<'tcx>( match ty.kind() { ty::Slice(_) => true, ty::Adt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()), - ty::Adt(..) => is_type_diagnostic_item(cx, ty, sym::vec_type), + ty::Adt(..) => is_type_diagnostic_item(cx, ty, sym::Vec), ty::Array(_, size) => size.try_eval_usize(cx.tcx, cx.param_env).is_some(), ty::Ref(_, inner, _) => may_slice(cx, inner), _ => false, diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index cb17e4dbfd0d..8476257f086f 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -122,7 +122,7 @@ fn check_sig<'tcx>(cx: &LateContext<'tcx>, item_hir_id: hir::HirId, decl: &hir:: fn check_ty<'tcx>(cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) { let ty = ty.peel_refs(); if let Adt(def, substs) = ty.kind() { - let is_keyed_type = [sym::hashmap_type, sym::BTreeMap, sym::hashset_type, sym::BTreeSet] + let is_keyed_type = [sym::HashMap, sym::BTreeMap, sym::HashSet, sym::BTreeSet] .iter() .any(|diag_item| cx.tcx.is_diagnostic_item(*diag_item, def.did)); if is_keyed_type && is_interior_mutable_type(cx, substs.type_at(0), span) { @@ -147,11 +147,11 @@ fn is_interior_mutable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Sp // that of their type parameters. Note: we don't include `HashSet` and `HashMap` // because they have no impl for `Hash` or `Ord`. let is_std_collection = [ - sym::option_type, - sym::result_type, + sym::Option, + sym::Result, sym::LinkedList, - sym::vec_type, - sym::vecdeque_type, + sym::Vec, + sym::VecDeque, sym::BTreeMap, sym::BTreeSet, sym::Rc, diff --git a/clippy_lints/src/mut_mutex_lock.rs b/clippy_lints/src/mut_mutex_lock.rs index e9dcc7b227d7..b96fa4774cbb 100644 --- a/clippy_lints/src/mut_mutex_lock.rs +++ b/clippy_lints/src/mut_mutex_lock.rs @@ -6,6 +6,7 @@ use rustc_hir::{Expr, ExprKind, Mutability}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::sym; declare_clippy_lint! { /// ### What it does @@ -51,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for MutMutexLock { if path.ident.name == sym!(lock); let ty = cx.typeck_results().expr_ty(self_arg); if let ty::Ref(_, inner_ty, Mutability::Mut) = ty.kind(); - if is_type_diagnostic_item(cx, inner_ty, sym!(mutex_type)); + if is_type_diagnostic_item(cx, inner_ty, sym::Mutex); then { span_lint_and_sugg( cx, diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index 436ceec6cfa0..5feddcbfc610 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -8,6 +8,7 @@ use rustc_hir::Expr; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::sym; declare_clippy_lint! { /// ### What it does @@ -74,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for Mutex { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { let ty = cx.typeck_results().expr_ty(expr); if let ty::Adt(_, subst) = ty.kind() { - if is_type_diagnostic_item(cx, ty, sym!(mutex_type)) { + if is_type_diagnostic_item(cx, ty, sym::Mutex) { let mutex_param = subst.type_at(0); if let Some(atomic_name) = get_atomic_name(mutex_param) { let msg = format!( diff --git a/clippy_lints/src/needless_option_as_deref.rs b/clippy_lints/src/needless_option_as_deref.rs index 5024a881d2aa..fbdaaf51f748 100644 --- a/clippy_lints/src/needless_option_as_deref.rs +++ b/clippy_lints/src/needless_option_as_deref.rs @@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for OptionNeedlessDeref { let outer_ty = typeck.expr_ty(expr); if_chain! { - if is_type_diagnostic_item(cx,outer_ty,sym::option_type); + if is_type_diagnostic_item(cx,outer_ty,sym::Option); if let ExprKind::MethodCall(path, _, [sub_expr], _) = expr.kind; let symbol = path.ident.as_str(); if symbol=="as_deref" || symbol=="as_deref_mut"; diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 90b2aa168962..352dc6f8bec3 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -206,7 +206,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { let deref_span = spans_need_deref.get(&canonical_id); if_chain! { - if is_type_diagnostic_item(cx, ty, sym::vec_type); + if is_type_diagnostic_item(cx, ty, sym::Vec); if let Some(clone_spans) = get_spans(cx, Some(body.id()), idx, &[("clone", ".to_owned()")]); if let TyKind::Path(QPath::Resolved(_, path)) = input.kind; @@ -245,7 +245,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { } } - if is_type_diagnostic_item(cx, ty, sym::string_type) { + if is_type_diagnostic_item(cx, ty, sym::String) { if let Some(clone_spans) = get_spans(cx, Some(body.id()), idx, &[("clone", ".to_string()"), ("as_str", "")]) { diag.span_suggestion( diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index 15f6dcae8870..a62eb0699891 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -70,7 +70,7 @@ declare_lint_pass!(OptionIfLetElse => [OPTION_IF_LET_ELSE]); fn is_result_ok(cx: &LateContext<'_>, expr: &'_ Expr<'_>) -> bool { if let ExprKind::MethodCall(path, _, &[ref receiver], _) = &expr.kind { path.ident.name.as_str() == "ok" - && is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(receiver), sym::result_type) + && is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(receiver), sym::Result) } else { false } diff --git a/clippy_lints/src/panic_in_result_fn.rs b/clippy_lints/src/panic_in_result_fn.rs index e2b6ba8e2d2f..583c42b65631 100644 --- a/clippy_lints/src/panic_in_result_fn.rs +++ b/clippy_lints/src/panic_in_result_fn.rs @@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for PanicInResultFn { span: Span, hir_id: hir::HirId, ) { - if !matches!(fn_kind, FnKind::Closure) && is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::result_type) { + if !matches!(fn_kind, FnKind::Closure) && is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::Result) { lint_impl_body(cx, span, body); } } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index d696e17d656d..d180d6f92271 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -258,7 +258,7 @@ fn check_fn(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_id: } if let ty::Ref(_, ty, Mutability::Not) = ty.kind() { - if is_type_diagnostic_item(cx, ty, sym::vec_type) { + if is_type_diagnostic_item(cx, ty, sym::Vec) { if let Some(spans) = get_spans(cx, opt_body_id, idx, &[("clone", ".to_owned()")]) { span_lint_and_then( cx, @@ -288,7 +288,7 @@ fn check_fn(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_id: }, ); } - } else if is_type_diagnostic_item(cx, ty, sym::string_type) { + } else if is_type_diagnostic_item(cx, ty, sym::String) { if let Some(spans) = get_spans(cx, opt_body_id, idx, &[("clone", ".to_string()"), ("as_str", "")]) { span_lint_and_then( cx, diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index e79cd7ed4ec4..aa6d254e7a54 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -143,7 +143,7 @@ impl QuestionMark { fn is_option(cx: &LateContext<'_>, expression: &Expr<'_>) -> bool { let expr_ty = cx.typeck_results().expr_ty(expression); - is_type_diagnostic_item(cx, expr_ty, sym::option_type) + is_type_diagnostic_item(cx, expr_ty, sym::Option) } fn expression_returns_none(cx: &LateContext<'_>, expression: &Expr<'_>) -> bool { diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 7041e4f980ef..f7711b6fe947 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -123,7 +123,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone { let from_borrow = match_def_path(cx, fn_def_id, &paths::CLONE_TRAIT_METHOD) || match_def_path(cx, fn_def_id, &paths::TO_OWNED_METHOD) || (match_def_path(cx, fn_def_id, &paths::TO_STRING_METHOD) - && is_type_diagnostic_item(cx, arg_ty, sym::string_type)); + && is_type_diagnostic_item(cx, arg_ty, sym::String)); let from_deref = !from_borrow && (match_def_path(cx, fn_def_id, &paths::PATH_TO_PATH_BUF) diff --git a/clippy_lints/src/ref_option_ref.rs b/clippy_lints/src/ref_option_ref.rs index 65ab6cac4421..d543832e314e 100644 --- a/clippy_lints/src/ref_option_ref.rs +++ b/clippy_lints/src/ref_option_ref.rs @@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for RefOptionRef { if let Some(res) = last.res; if let Some(def_id) = res.opt_def_id(); - if cx.tcx.is_diagnostic_item(sym::option_type, def_id); + if cx.tcx.is_diagnostic_item(sym::Option, def_id); if let Some(params) = last_path_segment(qpath).args ; if !params.parenthesized; if let Some(inner_ty) = params.args.iter().find_map(|arg| match arg { diff --git a/clippy_lints/src/repeat_once.rs b/clippy_lints/src/repeat_once.rs index 54b9c8b3275c..5fd0d1527639 100644 --- a/clippy_lints/src/repeat_once.rs +++ b/clippy_lints/src/repeat_once.rs @@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for RepeatOnce { format!("{}.to_vec()", snippet(cx, receiver.span, r#""...""#)), Applicability::MachineApplicable, ); - } else if is_type_diagnostic_item(cx, ty, sym::string_type) { + } else if is_type_diagnostic_item(cx, ty, sym::String) { span_lint_and_sugg( cx, REPEAT_ONCE, diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 3d039e130656..3608fe1472dd 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -120,7 +120,7 @@ impl SlowVectorInit { if let ExprKind::Call(func, [arg]) = expr.kind; if let ExprKind::Path(QPath::TypeRelative(ty, name)) = func.kind; if name.ident.as_str() == "with_capacity"; - if is_type_diagnostic_item(cx, cx.typeck_results().node_type(ty.hir_id), sym::vec_type); + if is_type_diagnostic_item(cx, cx.typeck_results().node_type(ty.hir_id), sym::Vec); then { Some(arg) } else { diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 13d8f954c441..35b6bde56964 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -157,7 +157,7 @@ impl<'tcx> LateLintPass<'tcx> for StringAdd { } fn is_string(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { - is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(e).peel_refs(), sym::string_type) + is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(e).peel_refs(), sym::String) } fn is_add(cx: &LateContext<'_>, src: &Expr<'_>, target: &Expr<'_>) -> bool { @@ -397,7 +397,7 @@ impl LateLintPass<'_> for StringToString { if let ExprKind::MethodCall(path, _, [self_arg, ..], _) = &expr.kind; if path.ident.name == sym!(to_string); let ty = cx.typeck_results().expr_ty(self_arg); - if is_type_diagnostic_item(cx, ty, sym::string_type); + if is_type_diagnostic_item(cx, ty, sym::String); then { span_lint_and_help( cx, diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index f126908e84b0..ef26de5b6b93 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -86,8 +86,8 @@ fn generate_swap_warning(cx: &LateContext<'_>, e1: &Expr<'_>, e2: &Expr<'_>, spa if matches!(ty.kind(), ty::Slice(_)) || matches!(ty.kind(), ty::Array(_, _)) - || is_type_diagnostic_item(cx, ty, sym::vec_type) - || is_type_diagnostic_item(cx, ty, sym::vecdeque_type) + || is_type_diagnostic_item(cx, ty, sym::Vec) + || is_type_diagnostic_item(cx, ty, sym::VecDeque) { let slice = Sugg::hir_with_applicability(cx, lhs1, "", &mut applicability); span_lint_and_sugg( @@ -231,7 +231,7 @@ fn check_xor_swap(cx: &LateContext<'_>, block: &Block<'_>) { } } -/// Returns the lhs and rhs of an xor assignment statement. +/// Returns the lhs and rhs of an xor assignment statement. fn extract_sides_of_xor_assign<'a, 'hir>(stmt: &'a Stmt<'hir>) -> Option<(&'a Expr<'hir>, &'a Expr<'hir>)> { if let StmtKind::Semi(expr) = stmt.kind { if let ExprKind::AssignOp( diff --git a/clippy_lints/src/transmute/unsound_collection_transmute.rs b/clippy_lints/src/transmute/unsound_collection_transmute.rs index 868c41aab43b..2ce8d4031d77 100644 --- a/clippy_lints/src/transmute/unsound_collection_transmute.rs +++ b/clippy_lints/src/transmute/unsound_collection_transmute.rs @@ -9,13 +9,13 @@ use rustc_span::symbol::{sym, Symbol}; // used to check for UNSOUND_COLLECTION_TRANSMUTE static COLLECTIONS: &[Symbol] = &[ - sym::vec_type, - sym::vecdeque_type, + sym::Vec, + sym::VecDeque, sym::BinaryHeap, sym::BTreeSet, sym::BTreeMap, - sym::hashset_type, - sym::hashmap_type, + sym::HashSet, + sym::HashMap, ]; /// Checks for `unsound_collection_transmute` lint. diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs index 1196271d5dd1..e9ec120a7f95 100644 --- a/clippy_lints/src/try_err.rs +++ b/clippy_lints/src/try_err.rs @@ -143,7 +143,7 @@ fn find_return_type<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx ExprKind<'_>) -> O fn result_error_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option> { if_chain! { if let ty::Adt(_, subst) = ty.kind(); - if is_type_diagnostic_item(cx, ty, sym::result_type); + if is_type_diagnostic_item(cx, ty, sym::Result); then { Some(subst.type_at(1)) } else { @@ -160,7 +160,7 @@ fn poll_result_error_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option< let ready_ty = subst.type_at(0); if let ty::Adt(ready_def, ready_subst) = ready_ty.kind(); - if cx.tcx.is_diagnostic_item(sym::result_type, ready_def.did); + if cx.tcx.is_diagnostic_item(sym::Result, ready_def.did); then { Some(ready_subst.type_at(1)) } else { @@ -177,11 +177,11 @@ fn poll_option_result_error_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> let ready_ty = subst.type_at(0); if let ty::Adt(ready_def, ready_subst) = ready_ty.kind(); - if cx.tcx.is_diagnostic_item(sym::option_type, ready_def.did); + if cx.tcx.is_diagnostic_item(sym::Option, ready_def.did); let some_ty = ready_subst.type_at(0); if let ty::Adt(some_def, some_subst) = some_ty.kind(); - if cx.tcx.is_diagnostic_item(sym::result_type, some_def.did); + if cx.tcx.is_diagnostic_item(sym::Result, some_def.did); then { Some(some_subst.type_at(1)) } else { diff --git a/clippy_lints/src/types/box_collection.rs b/clippy_lints/src/types/box_collection.rs index b28da29c91ce..538c10a5b204 100644 --- a/clippy_lints/src/types/box_collection.rs +++ b/clippy_lints/src/types/box_collection.rs @@ -38,11 +38,11 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_ } fn get_std_collection(cx: &LateContext<'_>, qpath: &QPath<'_>) -> Option<&'static str> { - if is_ty_param_diagnostic_item(cx, qpath, sym::vec_type).is_some() { + if is_ty_param_diagnostic_item(cx, qpath, sym::Vec).is_some() { Some("Vec") - } else if is_ty_param_diagnostic_item(cx, qpath, sym::string_type).is_some() { + } else if is_ty_param_diagnostic_item(cx, qpath, sym::String).is_some() { Some("String") - } else if is_ty_param_diagnostic_item(cx, qpath, sym::hashmap_type).is_some() { + } else if is_ty_param_diagnostic_item(cx, qpath, sym::HashMap).is_some() { Some("HashMap") } else { None diff --git a/clippy_lints/src/types/option_option.rs b/clippy_lints/src/types/option_option.rs index b2692c48076b..4f50284e941a 100644 --- a/clippy_lints/src/types/option_option.rs +++ b/clippy_lints/src/types/option_option.rs @@ -7,8 +7,8 @@ use rustc_span::symbol::sym; use super::OPTION_OPTION; pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool { - if cx.tcx.is_diagnostic_item(sym::option_type, def_id) - && is_ty_param_diagnostic_item(cx, qpath, sym::option_type).is_some() + if cx.tcx.is_diagnostic_item(sym::Option, def_id) + && is_ty_param_diagnostic_item(cx, qpath, sym::Option).is_some() { span_lint( cx, diff --git a/clippy_lints/src/types/rc_buffer.rs b/clippy_lints/src/types/rc_buffer.rs index ef629a35d107..31c4abdfc95e 100644 --- a/clippy_lints/src/types/rc_buffer.rs +++ b/clippy_lints/src/types/rc_buffer.rs @@ -20,7 +20,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_ format!("Rc<{}>", alternate), Applicability::MachineApplicable, ); - } else if let Some(ty) = is_ty_param_diagnostic_item(cx, qpath, sym::vec_type) { + } else if let Some(ty) = is_ty_param_diagnostic_item(cx, qpath, sym::Vec) { let qpath = match &ty.kind { TyKind::Path(qpath) => qpath, _ => return false, @@ -55,7 +55,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_ format!("Arc<{}>", alternate), Applicability::MachineApplicable, ); - } else if let Some(ty) = is_ty_param_diagnostic_item(cx, qpath, sym::vec_type) { + } else if let Some(ty) = is_ty_param_diagnostic_item(cx, qpath, sym::Vec) { let qpath = match &ty.kind { TyKind::Path(qpath) => qpath, _ => return false, @@ -85,7 +85,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_ } fn match_buffer_type(cx: &LateContext<'_>, qpath: &QPath<'_>) -> Option<&'static str> { - if is_ty_param_diagnostic_item(cx, qpath, sym::string_type).is_some() { + if is_ty_param_diagnostic_item(cx, qpath, sym::String).is_some() { Some("str") } else if is_ty_param_diagnostic_item(cx, qpath, sym::OsString).is_some() { Some("std::ffi::OsStr") diff --git a/clippy_lints/src/types/rc_mutex.rs b/clippy_lints/src/types/rc_mutex.rs index 12db7afb81ca..d54608a07bb2 100644 --- a/clippy_lints/src/types/rc_mutex.rs +++ b/clippy_lints/src/types/rc_mutex.rs @@ -10,7 +10,7 @@ use super::RC_MUTEX; pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool { if_chain! { if cx.tcx.is_diagnostic_item(sym::Rc, def_id) ; - if let Some(_) = is_ty_param_diagnostic_item(cx, qpath, sym!(mutex_type)) ; + if let Some(_) = is_ty_param_diagnostic_item(cx, qpath, sym::Mutex) ; then { span_lint_and_help( cx, diff --git a/clippy_lints/src/types/vec_box.rs b/clippy_lints/src/types/vec_box.rs index e7e2016d8f2f..c632f822544a 100644 --- a/clippy_lints/src/types/vec_box.rs +++ b/clippy_lints/src/types/vec_box.rs @@ -19,7 +19,7 @@ pub(super) fn check( def_id: DefId, box_size_threshold: u64, ) -> bool { - if cx.tcx.is_diagnostic_item(sym::vec_type, def_id) { + if cx.tcx.is_diagnostic_item(sym::Vec, def_id) { if_chain! { // Get the _ part of Vec<_> if let Some(last) = last_path_segment(qpath).args; diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index 61670fe124e3..dd74bf367f3a 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -168,7 +168,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { if let name = name_ident.ident.name.to_ident_string(); if name == "sort_by" || name == "sort_unstable_by"; if let [vec, Expr { kind: ExprKind::Closure(_, _, closure_body_id, _, _), .. }] = args; - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(vec), sym::vec_type); + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(vec), sym::Vec); if let closure_body = cx.tcx.hir().body(*closure_body_id); if let &[ Param { pat: Pat { kind: PatKind::Binding(_, _, left_ident, _), .. }, ..}, diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index 5ca861a14bf2..c940cf077d11 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -101,9 +101,9 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { // Get the wrapper and inner types, if can't, abort. let (return_type_label, lang_item, inner_type) = if let ty::Adt(adt_def, subst) = return_ty(cx, hir_id).kind() { - if cx.tcx.is_diagnostic_item(sym::option_type, adt_def.did) { + if cx.tcx.is_diagnostic_item(sym::Option, adt_def.did) { ("Option", OptionSome, subst.type_at(0)) - } else if cx.tcx.is_diagnostic_item(sym::result_type, adt_def.did) { + } else if cx.tcx.is_diagnostic_item(sym::Result, adt_def.did) { ("Result", ResultOk, subst.type_at(0)) } else { return; diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index b2ab300c2e93..ebaa9dcbbf85 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -132,11 +132,11 @@ fn collect_unwrap_info<'tcx>( is_entire_condition: bool, ) -> Vec> { fn is_relevant_option_call(cx: &LateContext<'_>, ty: Ty<'_>, method_name: &str) -> bool { - is_type_diagnostic_item(cx, ty, sym::option_type) && ["is_some", "is_none"].contains(&method_name) + is_type_diagnostic_item(cx, ty, sym::Option) && ["is_some", "is_none"].contains(&method_name) } fn is_relevant_result_call(cx: &LateContext<'_>, ty: Ty<'_>, method_name: &str) -> bool { - is_type_diagnostic_item(cx, ty, sym::result_type) && ["is_ok", "is_err"].contains(&method_name) + is_type_diagnostic_item(cx, ty, sym::Result) && ["is_ok", "is_err"].contains(&method_name) } if let ExprKind::Binary(op, left, right) = &expr.kind { @@ -165,7 +165,7 @@ fn collect_unwrap_info<'tcx>( _ => unreachable!(), }; let safe_to_unwrap = unwrappable != invert; - let kind = if is_type_diagnostic_item(cx, ty, sym::option_type) { + let kind = if is_type_diagnostic_item(cx, ty, sym::Option) { UnwrappableKind::Option } else { UnwrappableKind::Result diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs index 6eadd1fc1c93..a4680ae137b3 100644 --- a/clippy_lints/src/unwrap_in_result.rs +++ b/clippy_lints/src/unwrap_in_result.rs @@ -64,8 +64,8 @@ impl<'tcx> LateLintPass<'tcx> for UnwrapInResult { // first check if it's a method or function if let hir::ImplItemKind::Fn(ref _signature, _) = impl_item.kind; // checking if its return type is `result` or `option` - if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::result_type) - || is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::option_type); + if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::Result) + || is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::Option); then { lint_impl_body(cx, impl_item.span, impl_item); } @@ -86,8 +86,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindExpectUnwrap<'a, 'tcx> { // check for `expect` if let Some(arglists) = method_chain_args(expr, &["expect"]) { let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); - if is_type_diagnostic_item(self.lcx, reciever_ty, sym::option_type) - || is_type_diagnostic_item(self.lcx, reciever_ty, sym::result_type) + if is_type_diagnostic_item(self.lcx, reciever_ty, sym::Option) + || is_type_diagnostic_item(self.lcx, reciever_ty, sym::Result) { self.result.push(expr.span); } @@ -96,8 +96,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindExpectUnwrap<'a, 'tcx> { // check for `unwrap` if let Some(arglists) = method_chain_args(expr, &["unwrap"]) { let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); - if is_type_diagnostic_item(self.lcx, reciever_ty, sym::option_type) - || is_type_diagnostic_item(self.lcx, reciever_ty, sym::result_type) + if is_type_diagnostic_item(self.lcx, reciever_ty, sym::Option) + || is_type_diagnostic_item(self.lcx, reciever_ty, sym::Result) { self.result.push(expr.span); } diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 2861b4329190..88f11542072b 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -63,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { }, ExprKind::MethodCall(name, .., args, _) => { - if is_trait_method(cx, e, sym::into_trait) && &*name.ident.as_str() == "into" { + if is_trait_method(cx, e, sym::Into) && &*name.ident.as_str() == "into" { let a = cx.typeck_results().expr_ty(e); let b = cx.typeck_results().expr_ty(&args[0]); if same_type_and_consts(a, b) { @@ -103,10 +103,10 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { } } if_chain! { - if is_trait_method(cx, e, sym::try_into_trait) && name.ident.name == sym::try_into; + if is_trait_method(cx, e, sym::TryInto) && name.ident.name == sym::try_into; let a = cx.typeck_results().expr_ty(e); let b = cx.typeck_results().expr_ty(&args[0]); - if is_type_diagnostic_item(cx, a, sym::result_type); + if is_type_diagnostic_item(cx, a, sym::Result); if let ty::Adt(_, substs) = a.kind(); if let Some(a_type) = substs.types().next(); if same_type_and_consts(a_type, b); @@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { let b = cx.typeck_results().expr_ty(&args[0]); if_chain! { if match_def_path(cx, def_id, &paths::TRY_FROM); - if is_type_diagnostic_item(cx, a, sym::result_type); + if is_type_diagnostic_item(cx, a, sym::Result); if let ty::Adt(_, substs) = a.kind(); if let Some(a_type) = substs.types().next(); if same_type_and_consts(a_type, b); diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 3e2a4e9748db..59c40050522b 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -242,7 +242,7 @@ declare_clippy_lint! { /// /// Good: /// ```rust,ignore - /// utils::is_type_diagnostic_item(cx, ty, sym::vec_type) + /// utils::is_type_diagnostic_item(cx, ty, sym::Vec) /// ``` pub MATCH_TYPE_ON_DIAGNOSTIC_ITEM, internal, diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs index 0413c02b230e..d8e241d72af4 100644 --- a/clippy_lints/src/vec_init_then_push.rs +++ b/clippy_lints/src/vec_init_then_push.rs @@ -157,7 +157,7 @@ fn get_vec_init_kind<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Op if let ExprKind::Call(func, args) = expr.kind { match func.kind { ExprKind::Path(QPath::TypeRelative(ty, name)) - if is_type_diagnostic_item(cx, cx.typeck_results().node_type(ty.hir_id), sym::vec_type) => + if is_type_diagnostic_item(cx, cx.typeck_results().node_type(ty.hir_id), sym::Vec) => { if name.ident.name == sym::new { return Some(VecInitKind::New); @@ -177,7 +177,7 @@ fn get_vec_init_kind<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Op } ExprKind::Path(QPath::Resolved(_, path)) if match_def_path(cx, path.res.opt_def_id()?, &paths::DEFAULT_TRAIT_METHOD) - && is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::vec_type) => + && is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::Vec) => { return Some(VecInitKind::New); } diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 8e1cd655b611..aa6b2614bbc9 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -49,7 +49,7 @@ impl LateLintPass<'_> for ZeroSizedMapValues { if !hir_ty.span.from_expansion(); if !in_trait_impl(cx, hir_ty.hir_id); let ty = ty_from_hir_ty(cx, hir_ty); - if is_type_diagnostic_item(cx, ty, sym::hashmap_type) || is_type_diagnostic_item(cx, ty, sym::BTreeMap); + if is_type_diagnostic_item(cx, ty, sym::HashMap) || is_type_diagnostic_item(cx, ty, sym::BTreeMap); if let Adt(_, substs) = ty.kind(); let ty = substs.type_at(1); // Fixes https://github.com/rust-lang/rust-clippy/issues/7447 because of diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 9650294fc7b8..1ea7ccfb7521 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -101,7 +101,7 @@ fn identify_some_potentially_expensive_patterns<'tcx>(cx: &LateContext<'tcx>, ex ExprKind::Call(..) => !is_ctor_or_promotable_const_function(self.cx, expr), ExprKind::Index(obj, _) => { let ty = self.cx.typeck_results().expr_ty(obj); - is_type_diagnostic_item(self.cx, ty, sym::hashmap_type) + is_type_diagnostic_item(self.cx, ty, sym::HashMap) || is_type_diagnostic_item(self.cx, ty, sym::BTreeMap) }, ExprKind::MethodCall(..) => true, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 03f77f36b460..00123fdba249 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -647,13 +647,13 @@ pub fn can_mut_borrow_both(cx: &LateContext<'_>, e1: &Expr<'_>, e2: &Expr<'_>) - /// constructor from the std library fn is_default_equivalent_ctor(cx: &LateContext<'_>, def_id: DefId, path: &QPath<'_>) -> bool { let std_types_symbols = &[ - sym::string_type, - sym::vec_type, - sym::vecdeque_type, + sym::String, + sym::Vec, + sym::VecDeque, sym::LinkedList, - sym::hashmap_type, + sym::HashMap, sym::BTreeMap, - sym::hashset_type, + sym::HashSet, sym::BTreeSet, sym::BinaryHeap, ]; diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index 7a8208c12c0d..5e0182ec1b8e 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -88,7 +88,7 @@ pub const MEM_SIZE_OF_VAL: [&str; 3] = ["core", "mem", "size_of_val"]; pub const MUTEX_GUARD: [&str; 4] = ["std", "sync", "mutex", "MutexGuard"]; pub const OPEN_OPTIONS: [&str; 3] = ["std", "fs", "OpenOptions"]; pub const OPS_MODULE: [&str; 2] = ["core", "ops"]; -/// Preferably use the diagnostic item `sym::option_type` where possible +/// Preferably use the diagnostic item `sym::Option` where possible pub const OPTION: [&str; 3] = ["core", "option", "Option"]; pub const OPTION_NONE: [&str; 4] = ["core", "option", "Option", "None"]; pub const OPTION_SOME: [&str; 4] = ["core", "option", "Option", "Some"]; @@ -135,7 +135,7 @@ pub const REGEX_BYTES_NEW: [&str; 4] = ["regex", "re_bytes", "Regex", "new"]; pub const REGEX_BYTES_SET_NEW: [&str; 5] = ["regex", "re_set", "bytes", "RegexSet", "new"]; pub const REGEX_NEW: [&str; 4] = ["regex", "re_unicode", "Regex", "new"]; pub const REGEX_SET_NEW: [&str; 5] = ["regex", "re_set", "unicode", "RegexSet", "new"]; -/// Preferably use the diagnostic item `sym::result_type` where possible +/// Preferably use the diagnostic item `sym::Result` where possible pub const RESULT: [&str; 3] = ["core", "result", "Result"]; pub const RESULT_ERR: [&str; 4] = ["core", "result", "Result", "Err"]; pub const RESULT_OK: [&str; 4] = ["core", "result", "Result", "Ok"]; diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index d6f9ebe89bc7..96cb8a4dae43 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -77,16 +77,16 @@ pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option< // exists and has the desired signature. Unfortunately FnCtxt is not exported // so we can't use its `lookup_method` method. let into_iter_collections: &[Symbol] = &[ - sym::vec_type, - sym::option_type, - sym::result_type, + sym::Vec, + sym::Option, + sym::Result, sym::BTreeMap, sym::BTreeSet, - sym::vecdeque_type, + sym::VecDeque, sym::LinkedList, sym::BinaryHeap, - sym::hashset_type, - sym::hashmap_type, + sym::HashSet, + sym::HashMap, sym::PathBuf, sym::Path, sym::Receiver, diff --git a/tests/ui-internal/match_type_on_diag_item.stderr b/tests/ui-internal/match_type_on_diag_item.stderr index f5d92fc615c2..bf1d67e6054a 100644 --- a/tests/ui-internal/match_type_on_diag_item.stderr +++ b/tests/ui-internal/match_type_on_diag_item.stderr @@ -2,7 +2,7 @@ error: usage of `clippy_utils::ty::match_type()` on a type diagnostic item --> $DIR/match_type_on_diag_item.rs:30:17 | LL | let _ = match_type(cx, ty, &OPTION); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clippy_utils::ty::is_type_diagnostic_item(cx, ty, sym::option_type)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clippy_utils::ty::is_type_diagnostic_item(cx, ty, sym::Option)` | note: the lint level is defined here --> $DIR/match_type_on_diag_item.rs:1:9 @@ -15,7 +15,7 @@ error: usage of `clippy_utils::ty::match_type()` on a type diagnostic item --> $DIR/match_type_on_diag_item.rs:31:17 | LL | let _ = match_type(cx, ty, &["core", "result", "Result"]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clippy_utils::ty::is_type_diagnostic_item(cx, ty, sym::result_type)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clippy_utils::ty::is_type_diagnostic_item(cx, ty, sym::Result)` error: usage of `clippy_utils::ty::match_type()` on a type diagnostic item --> $DIR/match_type_on_diag_item.rs:34:17 From c79498d2eebbcb80c923deddbb9927c5d073235e Mon Sep 17 00:00:00 2001 From: flip1995 Date: Mon, 11 Oct 2021 10:10:16 +0200 Subject: [PATCH 0338/1222] Deprecate mem_discriminant_non_enum This lint has been uplifted and is now included in enum_intrinsics_non_enums. --- CHANGELOG.md | 5 +- clippy_lints/src/lib.register_all.rs | 1 - clippy_lints/src/lib.register_correctness.rs | 1 - clippy_lints/src/lib.register_lints.rs | 1 - clippy_lints/src/lib.rs | 3 +- clippy_lints/src/mem_discriminant.rs | 82 ----------------- tests/ui/mem_discriminant.fixed | 45 ---------- tests/ui/mem_discriminant.rs | 45 ---------- tests/ui/mem_discriminant.stderr | 94 -------------------- tests/ui/mem_discriminant_unfixable.rs | 16 ---- tests/ui/mem_discriminant_unfixable.stderr | 20 ----- tests/ui/rename.fixed | 1 + tests/ui/rename.rs | 1 + tests/ui/rename.stderr | 14 ++- 14 files changed, 15 insertions(+), 314 deletions(-) delete mode 100644 clippy_lints/src/mem_discriminant.rs delete mode 100644 tests/ui/mem_discriminant.fixed delete mode 100644 tests/ui/mem_discriminant.rs delete mode 100644 tests/ui/mem_discriminant.stderr delete mode 100644 tests/ui/mem_discriminant_unfixable.rs delete mode 100644 tests/ui/mem_discriminant_unfixable.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fdb300c9774..e700e5f0d736 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1873,10 +1873,10 @@ Released 2019-01-17 [2e26fdc2...b2601be](https://github.com/rust-lang/rust-clippy/compare/2e26fdc2...b2601be) -* New lints: [`slow_vector_initialization`], [`mem_discriminant_non_enum`], +* New lints: [`slow_vector_initialization`], `mem_discriminant_non_enum`, [`redundant_clone`], [`wildcard_dependencies`], [`into_iter_on_ref`], `into_iter_on_array`, [`deprecated_cfg_attr`], - [`mem_discriminant_non_enum`], [`cargo_common_metadata`] + [`cargo_common_metadata`] * Add support for `u128` and `i128` to integer related lints * Add float support to `mistyped_literal_suffixes` * Fix false positives in `use_self` @@ -2839,7 +2839,6 @@ Released 2018-09-13 [`match_wild_err_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_wild_err_arm [`match_wildcard_for_single_variants`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_wildcard_for_single_variants [`maybe_infinite_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#maybe_infinite_iter -[`mem_discriminant_non_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_discriminant_non_enum [`mem_forget`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_forget [`mem_replace_option_with_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_option_with_none [`mem_replace_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default diff --git a/clippy_lints/src/lib.register_all.rs b/clippy_lints/src/lib.register_all.rs index 3e6e0244754f..6a3ee35b41a4 100644 --- a/clippy_lints/src/lib.register_all.rs +++ b/clippy_lints/src/lib.register_all.rs @@ -127,7 +127,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![ LintId::of(matches::REDUNDANT_PATTERN_MATCHING), LintId::of(matches::SINGLE_MATCH), LintId::of(matches::WILDCARD_IN_OR_PATTERNS), - LintId::of(mem_discriminant::MEM_DISCRIMINANT_NON_ENUM), LintId::of(mem_replace::MEM_REPLACE_OPTION_WITH_NONE), LintId::of(mem_replace::MEM_REPLACE_WITH_DEFAULT), LintId::of(mem_replace::MEM_REPLACE_WITH_UNINIT), diff --git a/clippy_lints/src/lib.register_correctness.rs b/clippy_lints/src/lib.register_correctness.rs index e0ef7b3b8af9..bbe47a0e772f 100644 --- a/clippy_lints/src/lib.register_correctness.rs +++ b/clippy_lints/src/lib.register_correctness.rs @@ -36,7 +36,6 @@ store.register_group(true, "clippy::correctness", Some("clippy_correctness"), ve LintId::of(loops::ITER_NEXT_LOOP), LintId::of(loops::NEVER_LOOP), LintId::of(loops::WHILE_IMMUTABLE_CONDITION), - LintId::of(mem_discriminant::MEM_DISCRIMINANT_NON_ENUM), LintId::of(mem_replace::MEM_REPLACE_WITH_UNINIT), LintId::of(methods::CLONE_DOUBLE_REF), LintId::of(methods::ITERATOR_STEP_BY_ZERO), diff --git a/clippy_lints/src/lib.register_lints.rs b/clippy_lints/src/lib.register_lints.rs index 2ba2b3da55cd..b0be3b653664 100644 --- a/clippy_lints/src/lib.register_lints.rs +++ b/clippy_lints/src/lib.register_lints.rs @@ -241,7 +241,6 @@ store.register_lints(&[ matches::SINGLE_MATCH_ELSE, matches::WILDCARD_ENUM_MATCH_ARM, matches::WILDCARD_IN_OR_PATTERNS, - mem_discriminant::MEM_DISCRIMINANT_NON_ENUM, mem_forget::MEM_FORGET, mem_replace::MEM_REPLACE_OPTION_WITH_NONE, mem_replace::MEM_REPLACE_WITH_DEFAULT, diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 9fc6a9e0ccca..5534f9c94f36 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -266,7 +266,6 @@ mod map_unit_fn; mod match_on_vec_items; mod match_result_ok; mod matches; -mod mem_discriminant; mod mem_forget; mod mem_replace; mod methods; @@ -600,7 +599,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: let doc_valid_idents = conf.doc_valid_idents.iter().cloned().collect::>(); store.register_late_pass(move || Box::new(doc::DocMarkdown::new(doc_valid_idents.clone()))); store.register_late_pass(|| Box::new(neg_multiply::NegMultiply)); - store.register_late_pass(|| Box::new(mem_discriminant::MemDiscriminant)); store.register_late_pass(|| Box::new(mem_forget::MemForget)); store.register_late_pass(|| Box::new(arithmetic::Arithmetic::default())); store.register_late_pass(|| Box::new(assign_ops::AssignOps)); @@ -850,6 +848,7 @@ pub fn register_renamed(ls: &mut rustc_lint::LintStore) { ls.register_renamed("clippy::panic_params", "non_fmt_panics"); ls.register_renamed("clippy::unknown_clippy_lints", "unknown_lints"); ls.register_renamed("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"); + ls.register_renamed("clippy::mem_discriminant_non_enum", "enum_intrinsics_non_enums"); } // only exists to let the dogfood integration test works. diff --git a/clippy_lints/src/mem_discriminant.rs b/clippy_lints/src/mem_discriminant.rs deleted file mode 100644 index 59176c4b8466..000000000000 --- a/clippy_lints/src/mem_discriminant.rs +++ /dev/null @@ -1,82 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::snippet; -use clippy_utils::ty::walk_ptrs_ty_depth; -use clippy_utils::{match_def_path, paths}; -use if_chain::if_chain; -use rustc_errors::Applicability; -use rustc_hir::{BorrowKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// ### What it does - /// Checks for calls of `mem::discriminant()` on a non-enum type. - /// - /// ### Why is this bad? - /// The value of `mem::discriminant()` on non-enum types - /// is unspecified. - /// - /// ### Example - /// ```rust - /// use std::mem; - /// - /// mem::discriminant(&"hello"); - /// mem::discriminant(&&Some(2)); - /// ``` - pub MEM_DISCRIMINANT_NON_ENUM, - correctness, - "calling `mem::descriminant` on non-enum type" -} - -declare_lint_pass!(MemDiscriminant => [MEM_DISCRIMINANT_NON_ENUM]); - -impl<'tcx> LateLintPass<'tcx> for MemDiscriminant { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if_chain! { - if let ExprKind::Call(func, func_args) = expr.kind; - // is `mem::discriminant` - if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); - if match_def_path(cx, def_id, &paths::MEM_DISCRIMINANT); - // type is non-enum - let ty_param = cx.typeck_results().node_substs(func.hir_id).type_at(0); - if !ty_param.is_enum(); - - then { - span_lint_and_then( - cx, - MEM_DISCRIMINANT_NON_ENUM, - expr.span, - &format!("calling `mem::discriminant` on non-enum type `{}`", ty_param), - |diag| { - // if this is a reference to an enum, suggest dereferencing - let (base_ty, ptr_depth) = walk_ptrs_ty_depth(ty_param); - if ptr_depth >= 1 && base_ty.is_enum() { - let param = &func_args[0]; - - // cancel out '&'s first - let mut derefs_needed = ptr_depth; - let mut cur_expr = param; - while derefs_needed > 0 { - if let ExprKind::AddrOf(BorrowKind::Ref, _, inner_expr) = cur_expr.kind { - derefs_needed -= 1; - cur_expr = inner_expr; - } else { - break; - } - } - - let derefs = "*".repeat(derefs_needed); - diag.span_suggestion( - param.span, - "try dereferencing", - format!("{}{}", derefs, snippet(cx, cur_expr.span, "")), - Applicability::MachineApplicable, - ); - } - }, - ) - } - } - } -} diff --git a/tests/ui/mem_discriminant.fixed b/tests/ui/mem_discriminant.fixed deleted file mode 100644 index 69a8f286d050..000000000000 --- a/tests/ui/mem_discriminant.fixed +++ /dev/null @@ -1,45 +0,0 @@ -// run-rustfix - -#![deny(clippy::mem_discriminant_non_enum)] - -use std::mem; - -enum Foo { - One(usize), - Two(u8), -} - -fn main() { - // bad - mem::discriminant(&Some(2)); - mem::discriminant(&None::); - mem::discriminant(&Foo::One(5)); - mem::discriminant(&Foo::Two(5)); - - let ro = &Some(3); - let rro = &ro; - mem::discriminant(ro); - mem::discriminant(*rro); - mem::discriminant(*rro); - - macro_rules! mem_discriminant_but_in_a_macro { - ($param:expr) => { - mem::discriminant($param) - }; - } - - mem_discriminant_but_in_a_macro!(*rro); - - let rrrrro = &&&rro; - mem::discriminant(****rrrrro); - mem::discriminant(****rrrrro); - - // ok - mem::discriminant(&Some(2)); - mem::discriminant(&None::); - mem::discriminant(&Foo::One(5)); - mem::discriminant(&Foo::Two(5)); - mem::discriminant(ro); - mem::discriminant(*rro); - mem::discriminant(****rrrrro); -} diff --git a/tests/ui/mem_discriminant.rs b/tests/ui/mem_discriminant.rs deleted file mode 100644 index 55db50fcdc73..000000000000 --- a/tests/ui/mem_discriminant.rs +++ /dev/null @@ -1,45 +0,0 @@ -// run-rustfix - -#![deny(clippy::mem_discriminant_non_enum)] - -use std::mem; - -enum Foo { - One(usize), - Two(u8), -} - -fn main() { - // bad - mem::discriminant(&&Some(2)); - mem::discriminant(&&None::); - mem::discriminant(&&Foo::One(5)); - mem::discriminant(&&Foo::Two(5)); - - let ro = &Some(3); - let rro = &ro; - mem::discriminant(&ro); - mem::discriminant(rro); - mem::discriminant(&rro); - - macro_rules! mem_discriminant_but_in_a_macro { - ($param:expr) => { - mem::discriminant($param) - }; - } - - mem_discriminant_but_in_a_macro!(&rro); - - let rrrrro = &&&rro; - mem::discriminant(&rrrrro); - mem::discriminant(*rrrrro); - - // ok - mem::discriminant(&Some(2)); - mem::discriminant(&None::); - mem::discriminant(&Foo::One(5)); - mem::discriminant(&Foo::Two(5)); - mem::discriminant(ro); - mem::discriminant(*rro); - mem::discriminant(****rrrrro); -} diff --git a/tests/ui/mem_discriminant.stderr b/tests/ui/mem_discriminant.stderr deleted file mode 100644 index 36a225b75948..000000000000 --- a/tests/ui/mem_discriminant.stderr +++ /dev/null @@ -1,94 +0,0 @@ -error: calling `mem::discriminant` on non-enum type `&std::option::Option` - --> $DIR/mem_discriminant.rs:14:5 - | -LL | mem::discriminant(&&Some(2)); - | ^^^^^^^^^^^^^^^^^^---------^ - | | - | help: try dereferencing: `&Some(2)` - | -note: the lint level is defined here - --> $DIR/mem_discriminant.rs:3:9 - | -LL | #![deny(clippy::mem_discriminant_non_enum)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: calling `mem::discriminant` on non-enum type `&std::option::Option` - --> $DIR/mem_discriminant.rs:15:5 - | -LL | mem::discriminant(&&None::); - | ^^^^^^^^^^^^^^^^^^------------^ - | | - | help: try dereferencing: `&None::` - -error: calling `mem::discriminant` on non-enum type `&Foo` - --> $DIR/mem_discriminant.rs:16:5 - | -LL | mem::discriminant(&&Foo::One(5)); - | ^^^^^^^^^^^^^^^^^^-------------^ - | | - | help: try dereferencing: `&Foo::One(5)` - -error: calling `mem::discriminant` on non-enum type `&Foo` - --> $DIR/mem_discriminant.rs:17:5 - | -LL | mem::discriminant(&&Foo::Two(5)); - | ^^^^^^^^^^^^^^^^^^-------------^ - | | - | help: try dereferencing: `&Foo::Two(5)` - -error: calling `mem::discriminant` on non-enum type `&std::option::Option` - --> $DIR/mem_discriminant.rs:21:5 - | -LL | mem::discriminant(&ro); - | ^^^^^^^^^^^^^^^^^^---^ - | | - | help: try dereferencing: `ro` - -error: calling `mem::discriminant` on non-enum type `&std::option::Option` - --> $DIR/mem_discriminant.rs:22:5 - | -LL | mem::discriminant(rro); - | ^^^^^^^^^^^^^^^^^^---^ - | | - | help: try dereferencing: `*rro` - -error: calling `mem::discriminant` on non-enum type `&&std::option::Option` - --> $DIR/mem_discriminant.rs:23:5 - | -LL | mem::discriminant(&rro); - | ^^^^^^^^^^^^^^^^^^----^ - | | - | help: try dereferencing: `*rro` - -error: calling `mem::discriminant` on non-enum type `&&std::option::Option` - --> $DIR/mem_discriminant.rs:27:13 - | -LL | mem::discriminant($param) - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | mem_discriminant_but_in_a_macro!(&rro); - | --------------------------------------- - | | | - | | help: try dereferencing: `*rro` - | in this macro invocation - | - = note: this error originates in the macro `mem_discriminant_but_in_a_macro` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: calling `mem::discriminant` on non-enum type `&&&&&std::option::Option` - --> $DIR/mem_discriminant.rs:34:5 - | -LL | mem::discriminant(&rrrrro); - | ^^^^^^^^^^^^^^^^^^-------^ - | | - | help: try dereferencing: `****rrrrro` - -error: calling `mem::discriminant` on non-enum type `&&&std::option::Option` - --> $DIR/mem_discriminant.rs:35:5 - | -LL | mem::discriminant(*rrrrro); - | ^^^^^^^^^^^^^^^^^^-------^ - | | - | help: try dereferencing: `****rrrrro` - -error: aborting due to 10 previous errors - diff --git a/tests/ui/mem_discriminant_unfixable.rs b/tests/ui/mem_discriminant_unfixable.rs deleted file mode 100644 index e245d3257d55..000000000000 --- a/tests/ui/mem_discriminant_unfixable.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![deny(clippy::mem_discriminant_non_enum)] - -use std::mem; - -enum Foo { - One(usize), - Two(u8), -} - -struct A(Foo); - -fn main() { - // bad - mem::discriminant(&"hello"); - mem::discriminant(&A(Foo::One(0))); -} diff --git a/tests/ui/mem_discriminant_unfixable.stderr b/tests/ui/mem_discriminant_unfixable.stderr deleted file mode 100644 index e2de3776f2c9..000000000000 --- a/tests/ui/mem_discriminant_unfixable.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: calling `mem::discriminant` on non-enum type `&str` - --> $DIR/mem_discriminant_unfixable.rs:14:5 - | -LL | mem::discriminant(&"hello"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/mem_discriminant_unfixable.rs:1:9 - | -LL | #![deny(clippy::mem_discriminant_non_enum)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: calling `mem::discriminant` on non-enum type `A` - --> $DIR/mem_discriminant_unfixable.rs:15:5 - | -LL | mem::discriminant(&A(Foo::One(0))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index 13fbb6e2a6ee..a66c2e587c87 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -8,6 +8,7 @@ #![allow(clippy::redundant_static_lifetimes)] // warn for the old lint name here, to test if the renaming worked #![warn(clippy::cognitive_complexity)] +#![warn(enum_intrinsics_non_enums)] #[warn(clippy::module_name_repetitions)] fn main() {} diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index cbd3b1e91666..fa81201a2daf 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -8,6 +8,7 @@ #![allow(clippy::redundant_static_lifetimes)] // warn for the old lint name here, to test if the renaming worked #![warn(clippy::cyclomatic_complexity)] +#![warn(clippy::mem_discriminant_non_enum)] #[warn(clippy::stutter)] fn main() {} diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index c5d633ff86bf..05c7854074c6 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -6,23 +6,29 @@ LL | #![warn(clippy::cyclomatic_complexity)] | = note: `-D renamed-and-removed-lints` implied by `-D warnings` +error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` + --> $DIR/rename.rs:11:9 + | +LL | #![warn(clippy::mem_discriminant_non_enum)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` + error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:12:8 + --> $DIR/rename.rs:13:8 | LL | #[warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:15:8 + --> $DIR/rename.rs:16:8 | LL | #[warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:18:8 + --> $DIR/rename.rs:19:8 | LL | #[warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` -error: aborting due to 4 previous errors +error: aborting due to 5 previous errors From 9bd345ad0082f58dadef7049e66e9e662f0cb20a Mon Sep 17 00:00:00 2001 From: John Kugelman Date: Mon, 11 Oct 2021 10:13:50 -0400 Subject: [PATCH 0339/1222] Add #[must_use] to From::from and Into::into --- tests/ui/cast_lossless_float.fixed | 22 ++--- tests/ui/cast_lossless_float.rs | 22 ++--- tests/ui/cast_lossless_float.stderr | 66 +++++++-------- tests/ui/cast_lossless_integer.fixed | 38 ++++----- tests/ui/cast_lossless_integer.rs | 38 ++++----- tests/ui/cast_lossless_integer.stderr | 114 +++++++++++++------------- 6 files changed, 150 insertions(+), 150 deletions(-) diff --git a/tests/ui/cast_lossless_float.fixed b/tests/ui/cast_lossless_float.fixed index 709d58b596c8..32a9c1c4ae1a 100644 --- a/tests/ui/cast_lossless_float.fixed +++ b/tests/ui/cast_lossless_float.fixed @@ -6,24 +6,24 @@ fn main() { // Test clippy::cast_lossless with casts to floating-point types let x0 = 1i8; - f32::from(x0); - f64::from(x0); + let _ = f32::from(x0); + let _ = f64::from(x0); let x1 = 1u8; - f32::from(x1); - f64::from(x1); + let _ = f32::from(x1); + let _ = f64::from(x1); let x2 = 1i16; - f32::from(x2); - f64::from(x2); + let _ = f32::from(x2); + let _ = f64::from(x2); let x3 = 1u16; - f32::from(x3); - f64::from(x3); + let _ = f32::from(x3); + let _ = f64::from(x3); let x4 = 1i32; - f64::from(x4); + let _ = f64::from(x4); let x5 = 1u32; - f64::from(x5); + let _ = f64::from(x5); // Test with casts from floating-point types - f64::from(1.0f32); + let _ = f64::from(1.0f32); } // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const, diff --git a/tests/ui/cast_lossless_float.rs b/tests/ui/cast_lossless_float.rs index eb0aab886429..6f5ddcfe09c8 100644 --- a/tests/ui/cast_lossless_float.rs +++ b/tests/ui/cast_lossless_float.rs @@ -6,24 +6,24 @@ fn main() { // Test clippy::cast_lossless with casts to floating-point types let x0 = 1i8; - x0 as f32; - x0 as f64; + let _ = x0 as f32; + let _ = x0 as f64; let x1 = 1u8; - x1 as f32; - x1 as f64; + let _ = x1 as f32; + let _ = x1 as f64; let x2 = 1i16; - x2 as f32; - x2 as f64; + let _ = x2 as f32; + let _ = x2 as f64; let x3 = 1u16; - x3 as f32; - x3 as f64; + let _ = x3 as f32; + let _ = x3 as f64; let x4 = 1i32; - x4 as f64; + let _ = x4 as f64; let x5 = 1u32; - x5 as f64; + let _ = x5 as f64; // Test with casts from floating-point types - 1.0f32 as f64; + let _ = 1.0f32 as f64; } // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const, diff --git a/tests/ui/cast_lossless_float.stderr b/tests/ui/cast_lossless_float.stderr index 0ed09f3083c2..8326d40be716 100644 --- a/tests/ui/cast_lossless_float.stderr +++ b/tests/ui/cast_lossless_float.stderr @@ -1,70 +1,70 @@ error: casting `i8` to `f32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:9:5 + --> $DIR/cast_lossless_float.rs:9:13 | -LL | x0 as f32; - | ^^^^^^^^^ help: try: `f32::from(x0)` +LL | let _ = x0 as f32; + | ^^^^^^^^^ help: try: `f32::from(x0)` | = note: `-D clippy::cast-lossless` implied by `-D warnings` error: casting `i8` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:10:5 + --> $DIR/cast_lossless_float.rs:10:13 | -LL | x0 as f64; - | ^^^^^^^^^ help: try: `f64::from(x0)` +LL | let _ = x0 as f64; + | ^^^^^^^^^ help: try: `f64::from(x0)` error: casting `u8` to `f32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:12:5 + --> $DIR/cast_lossless_float.rs:12:13 | -LL | x1 as f32; - | ^^^^^^^^^ help: try: `f32::from(x1)` +LL | let _ = x1 as f32; + | ^^^^^^^^^ help: try: `f32::from(x1)` error: casting `u8` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:13:5 + --> $DIR/cast_lossless_float.rs:13:13 | -LL | x1 as f64; - | ^^^^^^^^^ help: try: `f64::from(x1)` +LL | let _ = x1 as f64; + | ^^^^^^^^^ help: try: `f64::from(x1)` error: casting `i16` to `f32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:15:5 + --> $DIR/cast_lossless_float.rs:15:13 | -LL | x2 as f32; - | ^^^^^^^^^ help: try: `f32::from(x2)` +LL | let _ = x2 as f32; + | ^^^^^^^^^ help: try: `f32::from(x2)` error: casting `i16` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:16:5 + --> $DIR/cast_lossless_float.rs:16:13 | -LL | x2 as f64; - | ^^^^^^^^^ help: try: `f64::from(x2)` +LL | let _ = x2 as f64; + | ^^^^^^^^^ help: try: `f64::from(x2)` error: casting `u16` to `f32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:18:5 + --> $DIR/cast_lossless_float.rs:18:13 | -LL | x3 as f32; - | ^^^^^^^^^ help: try: `f32::from(x3)` +LL | let _ = x3 as f32; + | ^^^^^^^^^ help: try: `f32::from(x3)` error: casting `u16` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:19:5 + --> $DIR/cast_lossless_float.rs:19:13 | -LL | x3 as f64; - | ^^^^^^^^^ help: try: `f64::from(x3)` +LL | let _ = x3 as f64; + | ^^^^^^^^^ help: try: `f64::from(x3)` error: casting `i32` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:21:5 + --> $DIR/cast_lossless_float.rs:21:13 | -LL | x4 as f64; - | ^^^^^^^^^ help: try: `f64::from(x4)` +LL | let _ = x4 as f64; + | ^^^^^^^^^ help: try: `f64::from(x4)` error: casting `u32` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:23:5 + --> $DIR/cast_lossless_float.rs:23:13 | -LL | x5 as f64; - | ^^^^^^^^^ help: try: `f64::from(x5)` +LL | let _ = x5 as f64; + | ^^^^^^^^^ help: try: `f64::from(x5)` error: casting `f32` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:26:5 + --> $DIR/cast_lossless_float.rs:26:13 | -LL | 1.0f32 as f64; - | ^^^^^^^^^^^^^ help: try: `f64::from(1.0f32)` +LL | let _ = 1.0f32 as f64; + | ^^^^^^^^^^^^^ help: try: `f64::from(1.0f32)` error: aborting due to 11 previous errors diff --git a/tests/ui/cast_lossless_integer.fixed b/tests/ui/cast_lossless_integer.fixed index 03e49adb117d..72a708b40737 100644 --- a/tests/ui/cast_lossless_integer.fixed +++ b/tests/ui/cast_lossless_integer.fixed @@ -5,27 +5,27 @@ fn main() { // Test clippy::cast_lossless with casts to integer types - i16::from(1i8); - i32::from(1i8); - i64::from(1i8); - i16::from(1u8); - i32::from(1u8); - i64::from(1u8); - u16::from(1u8); - u32::from(1u8); - u64::from(1u8); - i32::from(1i16); - i64::from(1i16); - i32::from(1u16); - i64::from(1u16); - u32::from(1u16); - u64::from(1u16); - i64::from(1i32); - i64::from(1u32); - u64::from(1u32); + let _ = i16::from(1i8); + let _ = i32::from(1i8); + let _ = i64::from(1i8); + let _ = i16::from(1u8); + let _ = i32::from(1u8); + let _ = i64::from(1u8); + let _ = u16::from(1u8); + let _ = u32::from(1u8); + let _ = u64::from(1u8); + let _ = i32::from(1i16); + let _ = i64::from(1i16); + let _ = i32::from(1u16); + let _ = i64::from(1u16); + let _ = u32::from(1u16); + let _ = u64::from(1u16); + let _ = i64::from(1i32); + let _ = i64::from(1u32); + let _ = u64::from(1u32); // Test with an expression wrapped in parens - u16::from(1u8 + 1u8); + let _ = u16::from(1u8 + 1u8); } // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const, diff --git a/tests/ui/cast_lossless_integer.rs b/tests/ui/cast_lossless_integer.rs index 6a984d245963..34bb47181e69 100644 --- a/tests/ui/cast_lossless_integer.rs +++ b/tests/ui/cast_lossless_integer.rs @@ -5,27 +5,27 @@ fn main() { // Test clippy::cast_lossless with casts to integer types - 1i8 as i16; - 1i8 as i32; - 1i8 as i64; - 1u8 as i16; - 1u8 as i32; - 1u8 as i64; - 1u8 as u16; - 1u8 as u32; - 1u8 as u64; - 1i16 as i32; - 1i16 as i64; - 1u16 as i32; - 1u16 as i64; - 1u16 as u32; - 1u16 as u64; - 1i32 as i64; - 1u32 as i64; - 1u32 as u64; + let _ = 1i8 as i16; + let _ = 1i8 as i32; + let _ = 1i8 as i64; + let _ = 1u8 as i16; + let _ = 1u8 as i32; + let _ = 1u8 as i64; + let _ = 1u8 as u16; + let _ = 1u8 as u32; + let _ = 1u8 as u64; + let _ = 1i16 as i32; + let _ = 1i16 as i64; + let _ = 1u16 as i32; + let _ = 1u16 as i64; + let _ = 1u16 as u32; + let _ = 1u16 as u64; + let _ = 1i32 as i64; + let _ = 1u32 as i64; + let _ = 1u32 as u64; // Test with an expression wrapped in parens - (1u8 + 1u8) as u16; + let _ = (1u8 + 1u8) as u16; } // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const, diff --git a/tests/ui/cast_lossless_integer.stderr b/tests/ui/cast_lossless_integer.stderr index 8e2890f9c28d..721b94876cb2 100644 --- a/tests/ui/cast_lossless_integer.stderr +++ b/tests/ui/cast_lossless_integer.stderr @@ -1,118 +1,118 @@ error: casting `i8` to `i16` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:8:5 + --> $DIR/cast_lossless_integer.rs:8:13 | -LL | 1i8 as i16; - | ^^^^^^^^^^ help: try: `i16::from(1i8)` +LL | let _ = 1i8 as i16; + | ^^^^^^^^^^ help: try: `i16::from(1i8)` | = note: `-D clippy::cast-lossless` implied by `-D warnings` error: casting `i8` to `i32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:9:5 + --> $DIR/cast_lossless_integer.rs:9:13 | -LL | 1i8 as i32; - | ^^^^^^^^^^ help: try: `i32::from(1i8)` +LL | let _ = 1i8 as i32; + | ^^^^^^^^^^ help: try: `i32::from(1i8)` error: casting `i8` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:10:5 + --> $DIR/cast_lossless_integer.rs:10:13 | -LL | 1i8 as i64; - | ^^^^^^^^^^ help: try: `i64::from(1i8)` +LL | let _ = 1i8 as i64; + | ^^^^^^^^^^ help: try: `i64::from(1i8)` error: casting `u8` to `i16` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:11:5 + --> $DIR/cast_lossless_integer.rs:11:13 | -LL | 1u8 as i16; - | ^^^^^^^^^^ help: try: `i16::from(1u8)` +LL | let _ = 1u8 as i16; + | ^^^^^^^^^^ help: try: `i16::from(1u8)` error: casting `u8` to `i32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:12:5 + --> $DIR/cast_lossless_integer.rs:12:13 | -LL | 1u8 as i32; - | ^^^^^^^^^^ help: try: `i32::from(1u8)` +LL | let _ = 1u8 as i32; + | ^^^^^^^^^^ help: try: `i32::from(1u8)` error: casting `u8` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:13:5 + --> $DIR/cast_lossless_integer.rs:13:13 | -LL | 1u8 as i64; - | ^^^^^^^^^^ help: try: `i64::from(1u8)` +LL | let _ = 1u8 as i64; + | ^^^^^^^^^^ help: try: `i64::from(1u8)` error: casting `u8` to `u16` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:14:5 + --> $DIR/cast_lossless_integer.rs:14:13 | -LL | 1u8 as u16; - | ^^^^^^^^^^ help: try: `u16::from(1u8)` +LL | let _ = 1u8 as u16; + | ^^^^^^^^^^ help: try: `u16::from(1u8)` error: casting `u8` to `u32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:15:5 + --> $DIR/cast_lossless_integer.rs:15:13 | -LL | 1u8 as u32; - | ^^^^^^^^^^ help: try: `u32::from(1u8)` +LL | let _ = 1u8 as u32; + | ^^^^^^^^^^ help: try: `u32::from(1u8)` error: casting `u8` to `u64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:16:5 + --> $DIR/cast_lossless_integer.rs:16:13 | -LL | 1u8 as u64; - | ^^^^^^^^^^ help: try: `u64::from(1u8)` +LL | let _ = 1u8 as u64; + | ^^^^^^^^^^ help: try: `u64::from(1u8)` error: casting `i16` to `i32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:17:5 + --> $DIR/cast_lossless_integer.rs:17:13 | -LL | 1i16 as i32; - | ^^^^^^^^^^^ help: try: `i32::from(1i16)` +LL | let _ = 1i16 as i32; + | ^^^^^^^^^^^ help: try: `i32::from(1i16)` error: casting `i16` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:18:5 + --> $DIR/cast_lossless_integer.rs:18:13 | -LL | 1i16 as i64; - | ^^^^^^^^^^^ help: try: `i64::from(1i16)` +LL | let _ = 1i16 as i64; + | ^^^^^^^^^^^ help: try: `i64::from(1i16)` error: casting `u16` to `i32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:19:5 + --> $DIR/cast_lossless_integer.rs:19:13 | -LL | 1u16 as i32; - | ^^^^^^^^^^^ help: try: `i32::from(1u16)` +LL | let _ = 1u16 as i32; + | ^^^^^^^^^^^ help: try: `i32::from(1u16)` error: casting `u16` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:20:5 + --> $DIR/cast_lossless_integer.rs:20:13 | -LL | 1u16 as i64; - | ^^^^^^^^^^^ help: try: `i64::from(1u16)` +LL | let _ = 1u16 as i64; + | ^^^^^^^^^^^ help: try: `i64::from(1u16)` error: casting `u16` to `u32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:21:5 + --> $DIR/cast_lossless_integer.rs:21:13 | -LL | 1u16 as u32; - | ^^^^^^^^^^^ help: try: `u32::from(1u16)` +LL | let _ = 1u16 as u32; + | ^^^^^^^^^^^ help: try: `u32::from(1u16)` error: casting `u16` to `u64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:22:5 + --> $DIR/cast_lossless_integer.rs:22:13 | -LL | 1u16 as u64; - | ^^^^^^^^^^^ help: try: `u64::from(1u16)` +LL | let _ = 1u16 as u64; + | ^^^^^^^^^^^ help: try: `u64::from(1u16)` error: casting `i32` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:23:5 + --> $DIR/cast_lossless_integer.rs:23:13 | -LL | 1i32 as i64; - | ^^^^^^^^^^^ help: try: `i64::from(1i32)` +LL | let _ = 1i32 as i64; + | ^^^^^^^^^^^ help: try: `i64::from(1i32)` error: casting `u32` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:24:5 + --> $DIR/cast_lossless_integer.rs:24:13 | -LL | 1u32 as i64; - | ^^^^^^^^^^^ help: try: `i64::from(1u32)` +LL | let _ = 1u32 as i64; + | ^^^^^^^^^^^ help: try: `i64::from(1u32)` error: casting `u32` to `u64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:25:5 + --> $DIR/cast_lossless_integer.rs:25:13 | -LL | 1u32 as u64; - | ^^^^^^^^^^^ help: try: `u64::from(1u32)` +LL | let _ = 1u32 as u64; + | ^^^^^^^^^^^ help: try: `u64::from(1u32)` error: casting `u8` to `u16` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:28:5 + --> $DIR/cast_lossless_integer.rs:28:13 | -LL | (1u8 + 1u8) as u16; - | ^^^^^^^^^^^^^^^^^^ help: try: `u16::from(1u8 + 1u8)` +LL | let _ = (1u8 + 1u8) as u16; + | ^^^^^^^^^^^^^^^^^^ help: try: `u16::from(1u8 + 1u8)` error: aborting due to 19 previous errors From a726948e1dcc1775fcac461553a0891df84742b3 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 13 Oct 2021 11:06:14 +0000 Subject: [PATCH 0340/1222] Update clippy ui output --- tests/ui/crashes/ice-6256.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/crashes/ice-6256.stderr b/tests/ui/crashes/ice-6256.stderr index d35d459168f2..ae4e6cad3328 100644 --- a/tests/ui/crashes/ice-6256.stderr +++ b/tests/ui/crashes/ice-6256.stderr @@ -6,7 +6,7 @@ LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types | = note: expected reference `&(dyn TT + 'static)` found reference `&dyn TT` -note: the anonymous lifetime #1 defined on the body at 13:13... +note: the anonymous lifetime #1 defined here... --> $DIR/ice-6256.rs:13:13 | LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types From dc76b60477517c0b62914bbc1123585114a99f1c Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Thu, 14 Oct 2021 13:28:30 -0500 Subject: [PATCH 0341/1222] Fix clippy with changed macro statement spans --- clippy_lints/src/copies.rs | 18 ++++---- clippy_lints/src/format.rs | 7 +-- clippy_lints/src/needless_continue.rs | 13 +++--- .../conf_nonstandard_macro_braces.stderr | 6 +-- tests/ui/asm_syntax.stderr | 10 ++--- tests/ui/assertions_on_constants.stderr | 18 ++++---- tests/ui/bool_assert_comparison.stderr | 44 +++++++++---------- .../checked_unwrap/simple_conditionals.stderr | 2 +- tests/ui/collapsible_match2.stderr | 2 +- tests/ui/crashes/ice-6255.stderr | 2 +- .../others.stderr | 2 +- .../traits.stderr | 2 +- tests/ui/default_numeric_fallback_f64.stderr | 2 +- tests/ui/default_numeric_fallback_i32.stderr | 2 +- tests/ui/doc_unsafe.stderr | 2 +- tests/ui/eq_op_macros.stderr | 8 ++-- tests/ui/fallible_impl_from.stderr | 8 ++-- tests/ui/format.stderr | 26 +++++------ tests/ui/implicit_hasher.stderr | 6 +-- tests/ui/item_after_statement.stderr | 2 +- tests/ui/mem_replace_macro.stderr | 2 +- tests/ui/missing_panics_doc.stderr | 4 +- tests/ui/panic_in_result_fn.stderr | 12 ++--- tests/ui/panic_in_result_fn_assertions.stderr | 6 +-- tests/ui/panicking_macros.stderr | 32 +++++++------- tests/ui/pattern_type_mismatch/syntax.stderr | 2 +- tests/ui/toplevel_ref_arg.stderr | 2 +- tests/ui/toplevel_ref_arg_non_rustfix.stderr | 2 +- tests/ui/try_err.stderr | 4 +- tests/ui/unit_cmp.stderr | 8 ++-- 30 files changed, 126 insertions(+), 130 deletions(-) diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 6ded2f233efe..b7385dcfbca1 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -9,7 +9,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::{Block, Expr, ExprKind, HirId}; -use rustc_lint::{LateContext, LateLintPass}; +use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{source_map::Span, symbol::Symbol, BytePos}; @@ -432,10 +432,11 @@ fn emit_branches_sharing_code_lint( let mut add_expr_note = false; // Construct suggestions + let sm = cx.sess().source_map(); if start_stmts > 0 { let block = blocks[0]; let span_start = first_line_of_span(cx, if_expr.span).shrink_to_lo(); - let span_end = block.stmts[start_stmts - 1].span.source_callsite(); + let span_end = sm.stmt_span(block.stmts[start_stmts - 1].span, block.span); let cond_span = first_line_of_span(cx, if_expr.span).until(block.span); let cond_snippet = reindent_multiline(snippet(cx, cond_span, "_"), false, None); @@ -454,15 +455,16 @@ fn emit_branches_sharing_code_lint( let span_end = block.span.shrink_to_hi(); let moved_start = if end_stmts == 0 && block.expr.is_some() { - block.expr.unwrap().span + block.expr.unwrap().span.source_callsite() } else { - block.stmts[block.stmts.len() - end_stmts].span - } - .source_callsite(); + sm.stmt_span(block.stmts[block.stmts.len() - end_stmts].span, block.span) + }; let moved_end = block .expr - .map_or_else(|| block.stmts[block.stmts.len() - 1].span, |expr| expr.span) - .source_callsite(); + .map_or_else( + || sm.stmt_span(block.stmts[block.stmts.len() - 1].span, block.span), + |expr| expr.span.source_callsite(), + ); let moved_span = moved_start.to(moved_end); let moved_snipped = reindent_multiline(snippet(cx, moved_span, "_"), true, None); diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 8df7f91ce59f..37d9ea3bdc11 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -90,12 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat { } } -fn span_useless_format(cx: &LateContext<'_>, span: Span, mut sugg: String, mut applicability: Applicability) { - // The callsite span contains the statement semicolon for some reason. - if snippet_with_applicability(cx, span, "..", &mut applicability).ends_with(';') { - sugg.push(';'); - } - +fn span_useless_format(cx: &LateContext<'_>, span: Span, sugg: String, applicability: Applicability) { span_lint_and_sugg( cx, USELESS_FORMAT, diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs index 5a50cc48d61b..7aa93ed78392 100644 --- a/clippy_lints/src/needless_continue.rs +++ b/clippy_lints/src/needless_continue.rs @@ -36,9 +36,8 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::{indent_of, snippet, snippet_block}; use rustc_ast::ast; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::{original_sp, DUMMY_SP}; use rustc_span::Span; declare_clippy_lint! { @@ -270,7 +269,7 @@ struct LintData<'a> { /// The 0-based index of the `if` statement in the containing loop block. stmt_idx: usize, /// The statements of the loop block. - block_stmts: &'a [ast::Stmt], + loop_block: &'a ast::Block, } const MSG_REDUNDANT_CONTINUE_EXPRESSION: &str = "this `continue` expression is redundant"; @@ -343,10 +342,10 @@ fn suggestion_snippet_for_continue_inside_else<'a>(cx: &EarlyContext<'_>, data: let indent = span_of_first_expr_in_block(data.if_block) .and_then(|span| indent_of(cx, span)) .unwrap_or(0); - let to_annex = data.block_stmts[data.stmt_idx + 1..] + let to_annex = data.loop_block.stmts[data.stmt_idx + 1..] .iter() - .map(|stmt| original_sp(stmt.span, DUMMY_SP)) - .map(|span| { + .map(|stmt| { + let span = cx.sess().source_map().stmt_span(stmt.span, data.loop_block.span); let snip = snippet_block(cx, span, "..", None).into_owned(); snip.lines() .map(|line| format!("{}{}", " ".repeat(indent), line)) @@ -393,7 +392,7 @@ fn check_and_warn<'a>(cx: &EarlyContext<'_>, expr: &'a ast::Expr) { if_cond: cond, if_block: then_block, else_expr, - block_stmts: &loop_block.stmts, + loop_block, }; if needless_continue_in_else(else_expr, label) { emit_warning( diff --git a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr index 87e962b9228c..039b23b1bdb2 100644 --- a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr +++ b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr @@ -82,13 +82,13 @@ error: use of irregular braces for `eprint!` macro --> $DIR/conf_nonstandard_macro_braces.rs:57:5 | LL | eprint!("test if user config overrides defaults"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -help: consider writing `eprint!["test if user config overrides defaults"];` +help: consider writing `eprint!["test if user config overrides defaults"]` --> $DIR/conf_nonstandard_macro_braces.rs:57:5 | LL | eprint!("test if user config overrides defaults"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 7 previous errors diff --git a/tests/ui/asm_syntax.stderr b/tests/ui/asm_syntax.stderr index e3abbe086586..409f4db76bc2 100644 --- a/tests/ui/asm_syntax.stderr +++ b/tests/ui/asm_syntax.stderr @@ -2,7 +2,7 @@ error: Intel x86 assembly syntax used --> $DIR/asm_syntax.rs:9:9 | LL | asm!(""); - | ^^^^^^^^^ + | ^^^^^^^^ | = note: `-D clippy::inline-asm-x86-intel-syntax` implied by `-D warnings` = help: use AT&T x86 assembly syntax @@ -11,7 +11,7 @@ error: Intel x86 assembly syntax used --> $DIR/asm_syntax.rs:10:9 | LL | asm!("", options()); - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ | = help: use AT&T x86 assembly syntax @@ -19,7 +19,7 @@ error: Intel x86 assembly syntax used --> $DIR/asm_syntax.rs:11:9 | LL | asm!("", options(nostack)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use AT&T x86 assembly syntax @@ -27,7 +27,7 @@ error: AT&T x86 assembly syntax used --> $DIR/asm_syntax.rs:23:9 | LL | asm!("", options(att_syntax)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::inline-asm-x86-att-syntax` implied by `-D warnings` = help: use Intel x86 assembly syntax @@ -36,7 +36,7 @@ error: AT&T x86 assembly syntax used --> $DIR/asm_syntax.rs:24:9 | LL | asm!("", options(nostack, att_syntax)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use Intel x86 assembly syntax diff --git a/tests/ui/assertions_on_constants.stderr b/tests/ui/assertions_on_constants.stderr index 1eb87d89fad0..4ca1e6f6e88c 100644 --- a/tests/ui/assertions_on_constants.stderr +++ b/tests/ui/assertions_on_constants.stderr @@ -2,7 +2,7 @@ error: `assert!(true)` will be optimized out by the compiler --> $DIR/assertions_on_constants.rs:11:5 | LL | assert!(true); - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ | = note: `-D clippy::assertions-on-constants` implied by `-D warnings` = help: remove it @@ -12,7 +12,7 @@ error: `assert!(false)` should probably be replaced --> $DIR/assertions_on_constants.rs:12:5 | LL | assert!(false); - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ | = help: use `panic!()` or `unreachable!()` = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -21,7 +21,7 @@ error: `assert!(true)` will be optimized out by the compiler --> $DIR/assertions_on_constants.rs:13:5 | LL | assert!(true, "true message"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: remove it = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -30,7 +30,7 @@ error: `assert!(false, "false message")` should probably be replaced --> $DIR/assertions_on_constants.rs:14:5 | LL | assert!(false, "false message"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `panic!("false message")` or `unreachable!("false message")` = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -39,7 +39,7 @@ error: `assert!(false, msg.to_uppercase())` should probably be replaced --> $DIR/assertions_on_constants.rs:17:5 | LL | assert!(false, msg.to_uppercase()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `panic!(msg.to_uppercase())` or `unreachable!(msg.to_uppercase())` = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -48,7 +48,7 @@ error: `assert!(true)` will be optimized out by the compiler --> $DIR/assertions_on_constants.rs:20:5 | LL | assert!(B); - | ^^^^^^^^^^^ + | ^^^^^^^^^^ | = help: remove it = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -57,7 +57,7 @@ error: `assert!(false)` should probably be replaced --> $DIR/assertions_on_constants.rs:23:5 | LL | assert!(C); - | ^^^^^^^^^^^ + | ^^^^^^^^^^ | = help: use `panic!()` or `unreachable!()` = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -66,7 +66,7 @@ error: `assert!(false, "C message")` should probably be replaced --> $DIR/assertions_on_constants.rs:24:5 | LL | assert!(C, "C message"); - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `panic!("C message")` or `unreachable!("C message")` = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -75,7 +75,7 @@ error: `debug_assert!(true)` will be optimized out by the compiler --> $DIR/assertions_on_constants.rs:26:5 | LL | debug_assert!(true); - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ | = help: remove it = note: this error originates in the macro `$crate::assert` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/bool_assert_comparison.stderr b/tests/ui/bool_assert_comparison.stderr index da9b56aa7795..377d51be4cde 100644 --- a/tests/ui/bool_assert_comparison.stderr +++ b/tests/ui/bool_assert_comparison.stderr @@ -2,7 +2,7 @@ error: used `assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:69:5 | LL | assert_eq!("a".is_empty(), false); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` | = note: `-D clippy::bool-assert-comparison` implied by `-D warnings` @@ -10,127 +10,127 @@ error: used `assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:70:5 | LL | assert_eq!("".is_empty(), true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:71:5 | LL | assert_eq!(true, "".is_empty()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:76:5 | LL | assert_eq!(b, true); - | ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `assert_ne!` with a literal bool --> $DIR/bool_assert_comparison.rs:79:5 | LL | assert_ne!("a".is_empty(), false); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `assert_ne!` with a literal bool --> $DIR/bool_assert_comparison.rs:80:5 | LL | assert_ne!("".is_empty(), true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `assert_ne!` with a literal bool --> $DIR/bool_assert_comparison.rs:81:5 | LL | assert_ne!(true, "".is_empty()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `assert_ne!` with a literal bool --> $DIR/bool_assert_comparison.rs:86:5 | LL | assert_ne!(b, true); - | ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `debug_assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:89:5 | LL | debug_assert_eq!("a".is_empty(), false); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:90:5 | LL | debug_assert_eq!("".is_empty(), true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:91:5 | LL | debug_assert_eq!(true, "".is_empty()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:96:5 | LL | debug_assert_eq!(b, true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_ne!` with a literal bool --> $DIR/bool_assert_comparison.rs:99:5 | LL | debug_assert_ne!("a".is_empty(), false); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_ne!` with a literal bool --> $DIR/bool_assert_comparison.rs:100:5 | LL | debug_assert_ne!("".is_empty(), true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_ne!` with a literal bool --> $DIR/bool_assert_comparison.rs:101:5 | LL | debug_assert_ne!(true, "".is_empty()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_ne!` with a literal bool --> $DIR/bool_assert_comparison.rs:106:5 | LL | debug_assert_ne!(b, true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:111:5 | LL | assert_eq!("a".is_empty(), false, "tadam {}", 1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:112:5 | LL | assert_eq!("a".is_empty(), false, "tadam {}", true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:113:5 | LL | assert_eq!(false, "a".is_empty(), "tadam {}", true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `debug_assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:118:5 | LL | debug_assert_eq!("a".is_empty(), false, "tadam {}", 1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:119:5 | LL | debug_assert_eq!("a".is_empty(), false, "tadam {}", true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:120:5 | LL | debug_assert_eq!(false, "a".is_empty(), "tadam {}", true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: aborting due to 22 previous errors diff --git a/tests/ui/checked_unwrap/simple_conditionals.stderr b/tests/ui/checked_unwrap/simple_conditionals.stderr index 82f269543800..341315928021 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.stderr +++ b/tests/ui/checked_unwrap/simple_conditionals.stderr @@ -71,7 +71,7 @@ LL | $a.unwrap(); // unnecessary | ^^^^^^^^^^^ ... LL | m!(x); - | ------ in this macro invocation + | ----- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/collapsible_match2.stderr b/tests/ui/collapsible_match2.stderr index 55e70dce208a..46b645aea135 100644 --- a/tests/ui/collapsible_match2.stderr +++ b/tests/ui/collapsible_match2.stderr @@ -46,7 +46,7 @@ LL | | }, | |_____________________^ ... LL | mac!(res_opt => Ok(val), val => Some(n), foo(n)); - | ------------------------------------------------- in this macro invocation + | ------------------------------------------------ in this macro invocation | help: the outer pattern can be modified to include the inner pattern --> $DIR/collapsible_match2.rs:46:28 diff --git a/tests/ui/crashes/ice-6255.stderr b/tests/ui/crashes/ice-6255.stderr index 5dbf9d440dd7..db0cb25e34a0 100644 --- a/tests/ui/crashes/ice-6255.stderr +++ b/tests/ui/crashes/ice-6255.stderr @@ -5,7 +5,7 @@ LL | extern crate std as core; | ^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | define_other_core!(); - | --------------------- in this macro invocation + | -------------------- in this macro invocation | = note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/declare_interior_mutable_const/others.stderr b/tests/ui/declare_interior_mutable_const/others.stderr index 7c9d705fa989..fd0689dfc4c9 100644 --- a/tests/ui/declare_interior_mutable_const/others.stderr +++ b/tests/ui/declare_interior_mutable_const/others.stderr @@ -31,7 +31,7 @@ LL | const $name: $ty = $e; | ^^^^^^^^^^^^^^^^^^^^^^ ... LL | declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable - | ------------------------------------------ in this macro invocation + | ----------------------------------------- in this macro invocation | = note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/declare_interior_mutable_const/traits.stderr b/tests/ui/declare_interior_mutable_const/traits.stderr index bed385b5273a..7debe059ff4e 100644 --- a/tests/ui/declare_interior_mutable_const/traits.stderr +++ b/tests/ui/declare_interior_mutable_const/traits.stderr @@ -13,7 +13,7 @@ LL | const $name: $ty = $e; | ^^^^^^^^^^^^^^^^^^^^^^ ... LL | declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); //~ ERROR interior mutable - | ----------------------------------------------------------- in this macro invocation + | ---------------------------------------------------------- in this macro invocation | = note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/default_numeric_fallback_f64.stderr b/tests/ui/default_numeric_fallback_f64.stderr index 961c7cb57c52..f8a2407b6933 100644 --- a/tests/ui/default_numeric_fallback_f64.stderr +++ b/tests/ui/default_numeric_fallback_f64.stderr @@ -139,7 +139,7 @@ LL | let x = 22.; | ^^^ help: consider adding suffix: `22.0_f64` ... LL | internal_macro!(); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: this error originates in the macro `internal_macro` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/default_numeric_fallback_i32.stderr b/tests/ui/default_numeric_fallback_i32.stderr index 5edf48b20208..6f9e124704b2 100644 --- a/tests/ui/default_numeric_fallback_i32.stderr +++ b/tests/ui/default_numeric_fallback_i32.stderr @@ -151,7 +151,7 @@ LL | let x = 22; | ^^ help: consider adding suffix: `22_i32` ... LL | internal_macro!(); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: this error originates in the macro `internal_macro` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/doc_unsafe.stderr b/tests/ui/doc_unsafe.stderr index 34ca37a6efdc..d68b8a0c67be 100644 --- a/tests/ui/doc_unsafe.stderr +++ b/tests/ui/doc_unsafe.stderr @@ -47,7 +47,7 @@ LL | | } | |_________^ ... LL | very_unsafe!(); - | --------------- in this macro invocation + | -------------- in this macro invocation | = note: this error originates in the macro `very_unsafe` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/eq_op_macros.stderr b/tests/ui/eq_op_macros.stderr index a28961e7568e..885415b42c78 100644 --- a/tests/ui/eq_op_macros.stderr +++ b/tests/ui/eq_op_macros.stderr @@ -5,7 +5,7 @@ LL | assert_eq!(a, a); | ^^^^ ... LL | assert_in_macro_def!(); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: `-D clippy::eq-op` implied by `-D warnings` = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -17,7 +17,7 @@ LL | assert_ne!(a, a); | ^^^^ ... LL | assert_in_macro_def!(); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -52,7 +52,7 @@ LL | debug_assert_eq!(a, a); | ^^^^ ... LL | assert_in_macro_def!(); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -63,7 +63,7 @@ LL | debug_assert_ne!(a, a); | ^^^^ ... LL | assert_in_macro_def!(); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/fallible_impl_from.stderr b/tests/ui/fallible_impl_from.stderr index 8b8054586e69..f5d0b98c1086 100644 --- a/tests/ui/fallible_impl_from.stderr +++ b/tests/ui/fallible_impl_from.stderr @@ -37,7 +37,7 @@ note: potential failure(s) --> $DIR/fallible_impl_from.rs:30:13 | LL | panic!(); - | ^^^^^^^^^ + | ^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: consider implementing `TryFrom` instead @@ -60,11 +60,11 @@ LL | let s = s.unwrap(); | ^^^^^^^^^^ LL | if !s.is_empty() { LL | panic!("42"); - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^^^ LL | } else if s.parse::().unwrap() != 42 { | ^^^^^^^^^^^^^^^^^^^^^^^^^ LL | panic!("{:?}", s); - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: consider implementing `TryFrom` instead @@ -86,7 +86,7 @@ note: potential failure(s) LL | if s.parse::().ok().unwrap() != 42 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | panic!("{:?}", s); - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 4 previous errors diff --git a/tests/ui/format.stderr b/tests/ui/format.stderr index 496a083497df..701399b32d62 100644 --- a/tests/ui/format.stderr +++ b/tests/ui/format.stderr @@ -2,7 +2,7 @@ error: useless use of `format!` --> $DIR/format.rs:13:5 | LL | format!("foo"); - | ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string();` + | ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` | = note: `-D clippy::useless-format` implied by `-D warnings` @@ -10,13 +10,13 @@ error: useless use of `format!` --> $DIR/format.rs:14:5 | LL | format!("{{}}"); - | ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{}".to_string();` + | ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{}".to_string()` error: useless use of `format!` --> $DIR/format.rs:15:5 | LL | format!("{{}} abc {{}}"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string();` + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string()` error: useless use of `format!` --> $DIR/format.rs:16:5 @@ -25,61 +25,61 @@ LL | / format!( LL | | r##"foo {{}} LL | | " bar"## LL | | ); - | |______^ + | |_____^ | help: consider using `.to_string()` | LL ~ r##"foo {} -LL + " bar"##.to_string(); +LL ~ " bar"##.to_string(); | error: useless use of `format!` --> $DIR/format.rs:21:5 | LL | format!("{}", "foo"); - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string();` + | ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` error: useless use of `format!` --> $DIR/format.rs:25:5 | LL | format!("{:+}", "foo"); // Warn when the format makes no difference. - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string();` + | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` error: useless use of `format!` --> $DIR/format.rs:26:5 | LL | format!("{:<}", "foo"); // Warn when the format makes no difference. - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string();` + | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` error: useless use of `format!` --> $DIR/format.rs:31:5 | LL | format!("{}", arg); - | ^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string();` + | ^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()` error: useless use of `format!` --> $DIR/format.rs:35:5 | LL | format!("{:+}", arg); // Warn when the format makes no difference. - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string();` + | ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()` error: useless use of `format!` --> $DIR/format.rs:36:5 | LL | format!("{:<}", arg); // Warn when the format makes no difference. - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string();` + | ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()` error: useless use of `format!` --> $DIR/format.rs:63:5 | LL | format!("{}", 42.to_string()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string();` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string()` error: useless use of `format!` --> $DIR/format.rs:65:5 | LL | format!("{}", x.display().to_string()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string();` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string()` error: useless use of `format!` --> $DIR/format.rs:69:18 diff --git a/tests/ui/implicit_hasher.stderr b/tests/ui/implicit_hasher.stderr index dad5ab71f157..3f5f56b923fe 100644 --- a/tests/ui/implicit_hasher.stderr +++ b/tests/ui/implicit_hasher.stderr @@ -107,7 +107,7 @@ LL | impl Foo for HashMap { | ^^^^^^^^^^^^^ ... LL | gen!(impl); - | ----------- in this macro invocation + | ---------- in this macro invocation | = note: this error originates in the macro `gen` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider adding a type parameter @@ -126,7 +126,7 @@ LL | pub fn $name(_map: &mut HashMap, _set: &mut HashSet) | ^^^^^^^^^^^^^^^^^ ... LL | gen!(fn bar); - | ------------- in this macro invocation + | ------------ in this macro invocation | = note: this error originates in the macro `gen` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider adding a type parameter @@ -141,7 +141,7 @@ LL | pub fn $name(_map: &mut HashMap, _set: &mut HashSet) | ^^^^^^^^^^^^ ... LL | gen!(fn bar); - | ------------- in this macro invocation + | ------------ in this macro invocation | = note: this error originates in the macro `gen` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider adding a type parameter diff --git a/tests/ui/item_after_statement.stderr b/tests/ui/item_after_statement.stderr index bcb163d4bc12..ab4a6374c73c 100644 --- a/tests/ui/item_after_statement.stderr +++ b/tests/ui/item_after_statement.stderr @@ -25,7 +25,7 @@ LL | | } | |_____________^ ... LL | b!(); - | ----- in this macro invocation + | ---- in this macro invocation | = note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/mem_replace_macro.stderr b/tests/ui/mem_replace_macro.stderr index b4963acc4553..dd69ab8b5efb 100644 --- a/tests/ui/mem_replace_macro.stderr +++ b/tests/ui/mem_replace_macro.stderr @@ -5,7 +5,7 @@ LL | std::mem::replace($s, Default::default()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | take!(s); - | --------- in this macro invocation + | -------- in this macro invocation | = note: `-D clippy::mem-replace-with-default` implied by `-D warnings` = note: this error originates in the macro `take` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/missing_panics_doc.stderr b/tests/ui/missing_panics_doc.stderr index 8d882cc6e0d0..b863063b626d 100644 --- a/tests/ui/missing_panics_doc.stderr +++ b/tests/ui/missing_panics_doc.stderr @@ -91,7 +91,7 @@ note: first possible panic found here --> $DIR/missing_panics_doc.rs:39:5 | LL | assert_eq!(x, 0); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) error: docs for function which may panic missing `# Panics` section @@ -107,7 +107,7 @@ note: first possible panic found here --> $DIR/missing_panics_doc.rs:45:5 | LL | assert_ne!(x, 0); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ = note: this error originates in the macro `assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 7 previous errors diff --git a/tests/ui/panic_in_result_fn.stderr b/tests/ui/panic_in_result_fn.stderr index 8d6e40c30a10..f56c2d03c664 100644 --- a/tests/ui/panic_in_result_fn.stderr +++ b/tests/ui/panic_in_result_fn.stderr @@ -13,7 +13,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn.rs:9:9 | LL | panic!("error"); - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` @@ -30,7 +30,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn.rs:14:9 | LL | unimplemented!(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` @@ -47,7 +47,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn.rs:19:9 | LL | unreachable!(); - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ = note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` @@ -64,7 +64,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn.rs:24:9 | LL | todo!("Finish this"); - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` @@ -81,7 +81,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn.rs:55:5 | LL | panic!("error"); - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` @@ -98,7 +98,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn.rs:69:5 | LL | todo!("finish main method"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 6 previous errors diff --git a/tests/ui/panic_in_result_fn_assertions.stderr b/tests/ui/panic_in_result_fn_assertions.stderr index 4c39b37d8798..7501d6d85edd 100644 --- a/tests/ui/panic_in_result_fn_assertions.stderr +++ b/tests/ui/panic_in_result_fn_assertions.stderr @@ -14,7 +14,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn_assertions.rs:9:9 | LL | assert!(x == 5, "wrong argument"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` @@ -32,7 +32,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn_assertions.rs:15:9 | LL | assert_eq!(x, 5); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` @@ -50,7 +50,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn_assertions.rs:21:9 | LL | assert_ne!(x, 1); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ = note: this error originates in the macro `assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 3 previous errors diff --git a/tests/ui/panicking_macros.stderr b/tests/ui/panicking_macros.stderr index 2e83c305a67e..2b607ff58889 100644 --- a/tests/ui/panicking_macros.stderr +++ b/tests/ui/panicking_macros.stderr @@ -2,7 +2,7 @@ error: `panic` should not be present in production code --> $DIR/panicking_macros.rs:8:5 | LL | panic!(); - | ^^^^^^^^^ + | ^^^^^^^^ | = note: `-D clippy::panic` implied by `-D warnings` @@ -10,19 +10,19 @@ error: `panic` should not be present in production code --> $DIR/panicking_macros.rs:9:5 | LL | panic!("message"); - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ error: `panic` should not be present in production code --> $DIR/panicking_macros.rs:10:5 | LL | panic!("{} {}", "panic with", "multiple arguments"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `todo` should not be present in production code --> $DIR/panicking_macros.rs:16:5 | LL | todo!(); - | ^^^^^^^^ + | ^^^^^^^ | = note: `-D clippy::todo` implied by `-D warnings` = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -31,7 +31,7 @@ error: `todo` should not be present in production code --> $DIR/panicking_macros.rs:17:5 | LL | todo!("message"); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -39,7 +39,7 @@ error: `todo` should not be present in production code --> $DIR/panicking_macros.rs:18:5 | LL | todo!("{} {}", "panic with", "multiple arguments"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -47,7 +47,7 @@ error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:24:5 | LL | unimplemented!(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::unimplemented` implied by `-D warnings` = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -56,7 +56,7 @@ error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:25:5 | LL | unimplemented!("message"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -64,7 +64,7 @@ error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:26:5 | LL | unimplemented!("{} {}", "panic with", "multiple arguments"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -72,7 +72,7 @@ error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:32:5 | LL | unreachable!(); - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ | = note: `-D clippy::unreachable` implied by `-D warnings` = note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -81,7 +81,7 @@ error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:33:5 | LL | unreachable!("message"); - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `$crate::unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -89,7 +89,7 @@ error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:34:5 | LL | unreachable!("{} {}", "panic with", "multiple arguments"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -97,13 +97,13 @@ error: `panic` should not be present in production code --> $DIR/panicking_macros.rs:40:5 | LL | panic!(); - | ^^^^^^^^^ + | ^^^^^^^^ error: `todo` should not be present in production code --> $DIR/panicking_macros.rs:41:5 | LL | todo!(); - | ^^^^^^^^ + | ^^^^^^^ | = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -111,7 +111,7 @@ error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:42:5 | LL | unimplemented!(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -119,7 +119,7 @@ error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:43:5 | LL | unreachable!(); - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ | = note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/pattern_type_mismatch/syntax.stderr b/tests/ui/pattern_type_mismatch/syntax.stderr index f309b2739829..12b3d3a8bd07 100644 --- a/tests/ui/pattern_type_mismatch/syntax.stderr +++ b/tests/ui/pattern_type_mismatch/syntax.stderr @@ -70,7 +70,7 @@ LL | Some(_) => (), | ^^^^^^^ ... LL | matching_macro!(value); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings = note: this error originates in the macro `matching_macro` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/toplevel_ref_arg.stderr b/tests/ui/toplevel_ref_arg.stderr index 48e7d9ddd5ae..9c853020ab01 100644 --- a/tests/ui/toplevel_ref_arg.stderr +++ b/tests/ui/toplevel_ref_arg.stderr @@ -37,7 +37,7 @@ LL | let ref _y = 42; | ----^^^^^^------ help: try: `let _y = &42;` ... LL | gen_binding!(); - | --------------- in this macro invocation + | -------------- in this macro invocation | = note: this error originates in the macro `gen_binding` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/toplevel_ref_arg_non_rustfix.stderr b/tests/ui/toplevel_ref_arg_non_rustfix.stderr index 31f8c103ede5..e97011c7fd51 100644 --- a/tests/ui/toplevel_ref_arg_non_rustfix.stderr +++ b/tests/ui/toplevel_ref_arg_non_rustfix.stderr @@ -13,7 +13,7 @@ LL | fn fun_example(ref _x: usize) {} | ^^^^^^ ... LL | gen_function!(); - | ---------------- in this macro invocation + | --------------- in this macro invocation | = note: this error originates in the macro `gen_function` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/try_err.stderr b/tests/ui/try_err.stderr index 09efc16c154e..0cb1328fbfcf 100644 --- a/tests/ui/try_err.stderr +++ b/tests/ui/try_err.stderr @@ -35,7 +35,7 @@ LL | Err(_) => Err(1)?, | ^^^^^^^ help: try this: `return Err(1)` ... LL | try_validation!(Ok::<_, i32>(5)); - | --------------------------------- in this macro invocation + | -------------------------------- in this macro invocation | = note: this error originates in the macro `try_validation` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -46,7 +46,7 @@ LL | Err(_) => Err(ret_one!())?, | ^^^^^^^^^^^^^^^^ help: try this: `return Err(ret_one!())` ... LL | try_validation_in_macro!(Ok::<_, i32>(5)); - | ------------------------------------------ in this macro invocation + | ----------------------------------------- in this macro invocation | = note: this error originates in the macro `try_validation_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/unit_cmp.stderr b/tests/ui/unit_cmp.stderr index 75017cab0577..2b5a7b348b98 100644 --- a/tests/ui/unit_cmp.stderr +++ b/tests/ui/unit_cmp.stderr @@ -32,7 +32,7 @@ LL | | }, ... | LL | | } LL | | ); - | |______^ + | |_____^ | = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -46,7 +46,7 @@ LL | | }, ... | LL | | } LL | | ); - | |______^ + | |_____^ | = note: this error originates in the macro `$crate::assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -60,7 +60,7 @@ LL | | }, ... | LL | | } LL | | ); - | |______^ + | |_____^ | = note: this error originates in the macro `assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -74,7 +74,7 @@ LL | | }, ... | LL | | } LL | | ); - | |______^ + | |_____^ | = note: this error originates in the macro `$crate::assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info) From ad76271133d1b3563f3c14dced256467ad98d1f1 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Thu, 14 Oct 2021 16:41:46 -0500 Subject: [PATCH 0342/1222] Fix clippy with for loop span change --- clippy_lints/src/vec.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index d124d948b5e6..d3234b5758a5 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -63,13 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec { if is_copy(cx, vec_type(cx.typeck_results().expr_ty_adjusted(arg))); then { // report the error around the `vec!` not inside `:` - let span = arg.span - .ctxt() - .outer_expn_data() - .call_site - .ctxt() - .outer_expn_data() - .call_site; + let span = arg.span.ctxt().outer_expn_data().call_site; self.check_vec_macro(cx, &vec_args, Mutability::Not, span); } } From 5c0ca64ee45ba0a313f16b2b23e93f9c39cbca6b Mon Sep 17 00:00:00 2001 From: r00ster91 Date: Sun, 17 Oct 2021 12:04:01 +0200 Subject: [PATCH 0343/1222] Some "parenthesis" and "parentheses" fixes --- clippy_lints/src/manual_unwrap_or.rs | 2 +- clippy_utils/src/sugg.rs | 6 +++--- tests/ui/manual_unwrap_or.fixed | 4 ++-- tests/ui/manual_unwrap_or.rs | 4 ++-- tests/ui/useless_conversion.fixed | 2 +- tests/ui/useless_conversion.rs | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/manual_unwrap_or.rs b/clippy_lints/src/manual_unwrap_or.rs index 2ae9cb4f9c13..42478e3416ec 100644 --- a/clippy_lints/src/manual_unwrap_or.rs +++ b/clippy_lints/src/manual_unwrap_or.rs @@ -98,7 +98,7 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { reindent_multiline(or_body_snippet.into(), true, Some(indent)); let suggestion = if scrutinee.span.from_expansion() { - // we don't want parenthesis around macro, e.g. `(some_macro!()).unwrap_or(0)` + // we don't want parentheses around macro, e.g. `(some_macro!()).unwrap_or(0)` sugg::Sugg::hir_with_macro_callsite(cx, scrutinee, "..") } else { diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 5b0efb1fd713..01fb944cc36f 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -16,10 +16,10 @@ use std::convert::TryInto; use std::fmt::Display; use std::ops::{Add, Neg, Not, Sub}; -/// A helper type to build suggestion correctly handling parenthesis. +/// A helper type to build suggestion correctly handling parentheses. #[derive(Clone, PartialEq)] pub enum Sugg<'a> { - /// An expression that never needs parenthesis such as `1337` or `[0; 42]`. + /// An expression that never needs parentheses such as `1337` or `[0; 42]`. NonParen(Cow<'a, str>), /// An expression that does not fit in other variants. MaybeParen(Cow<'a, str>), @@ -283,7 +283,7 @@ impl<'a> Sugg<'a> { } } - /// Adds parenthesis to any expression that might need them. Suitable to the + /// Adds parentheses to any expression that might need them. Suitable to the /// `self` argument of a method call /// (e.g., to build `bar.foo()` or `(1 + 2).foo()`). pub fn maybe_par(self) -> Self { diff --git a/tests/ui/manual_unwrap_or.fixed b/tests/ui/manual_unwrap_or.fixed index 3717f962745f..05d6c56f2aca 100644 --- a/tests/ui/manual_unwrap_or.fixed +++ b/tests/ui/manual_unwrap_or.fixed @@ -74,10 +74,10 @@ fn result_unwrap_or() { let a = Ok::(1); a.unwrap_or(42); - // int case, suggestion must surround Result expr with parenthesis + // int case, suggestion must surround Result expr with parentheses (Ok(1) as Result).unwrap_or(42); - // method call case, suggestion must not surround Result expr `s.method()` with parenthesis + // method call case, suggestion must not surround Result expr `s.method()` with parentheses struct S {} impl S { fn method(self) -> Option { diff --git a/tests/ui/manual_unwrap_or.rs b/tests/ui/manual_unwrap_or.rs index 989adde1f5bb..09f62c69b71d 100644 --- a/tests/ui/manual_unwrap_or.rs +++ b/tests/ui/manual_unwrap_or.rs @@ -95,13 +95,13 @@ fn result_unwrap_or() { Err(_) => 42, }; - // int case, suggestion must surround Result expr with parenthesis + // int case, suggestion must surround Result expr with parentheses match Ok(1) as Result { Ok(i) => i, Err(_) => 42, }; - // method call case, suggestion must not surround Result expr `s.method()` with parenthesis + // method call case, suggestion must not surround Result expr `s.method()` with parentheses struct S {} impl S { fn method(self) -> Option { diff --git a/tests/ui/useless_conversion.fixed b/tests/ui/useless_conversion.fixed index 76aa82068d62..70ff08f36551 100644 --- a/tests/ui/useless_conversion.fixed +++ b/tests/ui/useless_conversion.fixed @@ -66,7 +66,7 @@ fn main() { let _ = vec![1, 2, 3].into_iter(); let _: String = format!("Hello {}", "world"); - // keep parenthesis around `a + b` for suggestion (see #4750) + // keep parentheses around `a + b` for suggestion (see #4750) let a: i32 = 1; let b: i32 = 1; let _ = (a + b) * 3; diff --git a/tests/ui/useless_conversion.rs b/tests/ui/useless_conversion.rs index ccee7abb404e..f2444a8f436b 100644 --- a/tests/ui/useless_conversion.rs +++ b/tests/ui/useless_conversion.rs @@ -66,7 +66,7 @@ fn main() { let _ = vec![1, 2, 3].into_iter().into_iter(); let _: String = format!("Hello {}", "world").into(); - // keep parenthesis around `a + b` for suggestion (see #4750) + // keep parentheses around `a + b` for suggestion (see #4750) let a: i32 = 1; let b: i32 = 1; let _ = i32::from(a + b) * 3; From acb4e33ac5acdd234abf8b6ea6a93b1e5b30afd3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 17 Oct 2021 23:20:30 +0300 Subject: [PATCH 0344/1222] rustc_span: `Ident::invalid` -> `Ident::empty` The equivalent for `Symbol`s was renamed some time ago (`kw::Invalid` -> `kw::Empty`), and it makes sense to do the same thing for `Ident`s. --- tests/ui-internal/unnecessary_symbol_str.fixed | 4 ++-- tests/ui-internal/unnecessary_symbol_str.rs | 4 ++-- tests/ui-internal/unnecessary_symbol_str.stderr | 9 ++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/ui-internal/unnecessary_symbol_str.fixed b/tests/ui-internal/unnecessary_symbol_str.fixed index 2ec0efe4c10a..95b8c6dfe89e 100644 --- a/tests/ui-internal/unnecessary_symbol_str.fixed +++ b/tests/ui-internal/unnecessary_symbol_str.fixed @@ -11,6 +11,6 @@ fn main() { Symbol::intern("foo") == rustc_span::sym::clippy; Symbol::intern("foo") == rustc_span::symbol::kw::SelfLower; Symbol::intern("foo") != rustc_span::symbol::kw::SelfUpper; - Ident::invalid().name == rustc_span::sym::clippy; - rustc_span::sym::clippy == Ident::invalid().name; + Ident::empty().name == rustc_span::sym::clippy; + rustc_span::sym::clippy == Ident::empty().name; } diff --git a/tests/ui-internal/unnecessary_symbol_str.rs b/tests/ui-internal/unnecessary_symbol_str.rs index 87e1b3a2ee76..ad6937cf60a6 100644 --- a/tests/ui-internal/unnecessary_symbol_str.rs +++ b/tests/ui-internal/unnecessary_symbol_str.rs @@ -11,6 +11,6 @@ fn main() { Symbol::intern("foo").as_str() == "clippy"; Symbol::intern("foo").to_string() == "self"; Symbol::intern("foo").to_ident_string() != "Self"; - &*Ident::invalid().as_str() == "clippy"; - "clippy" == Ident::invalid().to_string(); + &*Ident::empty().as_str() == "clippy"; + "clippy" == Ident::empty().to_string(); } diff --git a/tests/ui-internal/unnecessary_symbol_str.stderr b/tests/ui-internal/unnecessary_symbol_str.stderr index b1284b7c8ffd..8e04d447fbca 100644 --- a/tests/ui-internal/unnecessary_symbol_str.stderr +++ b/tests/ui-internal/unnecessary_symbol_str.stderr @@ -26,14 +26,13 @@ LL | Symbol::intern("foo").to_ident_string() != "Self"; error: unnecessary `Symbol` to string conversion --> $DIR/unnecessary_symbol_str.rs:14:5 | -LL | &*Ident::invalid().as_str() == "clippy"; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Ident::invalid().name == rustc_span::sym::clippy` +LL | &*Ident::empty().as_str() == "clippy"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Ident::empty().name == rustc_span::sym::clippy` error: unnecessary `Symbol` to string conversion --> $DIR/unnecessary_symbol_str.rs:15:5 | -LL | "clippy" == Ident::invalid().to_string(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::clippy == Ident::invalid().name` +LL | "clippy" == Ident::empty().to_string(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::clippy == Ident::empty().name` error: aborting due to 5 previous errors - From d4ae41d6b2eaf56983b4d772bbba4b070226b9b1 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Tue, 19 Oct 2021 13:58:58 +0100 Subject: [PATCH 0345/1222] Remove begin_panic_fmt from clippy --- clippy_utils/src/higher.rs | 1 - clippy_utils/src/lib.rs | 1 - clippy_utils/src/paths.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index ba4d50bf7446..74cf323720cb 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -619,7 +619,6 @@ impl PanicExpn<'tcx> { if let Some(init) = block.expr; if let ExprKind::Call(_, [format_args]) = init.kind; let expn_data = expr.span.ctxt().outer_expn_data(); - if let ExprKind::AddrOf(_, _, format_args) = format_args.kind; if let Some(format_args) = FormatArgsExpn::parse(format_args); then { Some(PanicExpn { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index c47aa9170e54..8e94d16a33a0 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1646,7 +1646,6 @@ pub fn match_panic_def_id(cx: &LateContext<'_>, did: DefId) -> bool { did, &[ &paths::BEGIN_PANIC, - &paths::BEGIN_PANIC_FMT, &paths::PANIC_ANY, &paths::PANICKING_PANIC, &paths::PANICKING_PANIC_FMT, diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index e43c57560214..81aff585ded1 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -20,7 +20,6 @@ pub const ARC_PTR_EQ: [&str; 4] = ["alloc", "sync", "Arc", "ptr_eq"]; pub const ASMUT_TRAIT: [&str; 3] = ["core", "convert", "AsMut"]; pub const ASREF_TRAIT: [&str; 3] = ["core", "convert", "AsRef"]; pub(super) const BEGIN_PANIC: [&str; 3] = ["std", "panicking", "begin_panic"]; -pub(super) const BEGIN_PANIC_FMT: [&str; 3] = ["std", "panicking", "begin_panic_fmt"]; /// Preferably use the diagnostic item `sym::Borrow` where possible pub const BORROW_TRAIT: [&str; 3] = ["core", "borrow", "Borrow"]; pub const BTREEMAP_CONTAINS_KEY: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "contains_key"]; From b4b7bd439739baf4aaeb52dfa4cffacf83af92ee Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sun, 26 Sep 2021 17:38:05 +0100 Subject: [PATCH 0346/1222] Remove NullOp::Box --- clippy_utils/src/qualify_min_const_fn.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index e6d8ba3f02eb..789418c743ff 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -193,7 +193,6 @@ fn check_rvalue(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, rvalue: &Rv } }, Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) | Rvalue::ShallowInitBox(_, _) => Ok(()), - Rvalue::NullaryOp(NullOp::Box, _) => Err((span, "heap allocations are not allowed in const fn".into())), Rvalue::UnaryOp(_, operand) => { let ty = operand.ty(body, tcx); if ty.is_integral() || ty.is_bool() { From 1c54acc8999f97cf096237d6ec995d2bc09cdb5b Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Fri, 1 Oct 2021 18:09:31 +0000 Subject: [PATCH 0347/1222] Always sort suggestions before emitting them --- tests/ui/nonminimal_bool.stderr | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/ui/nonminimal_bool.stderr b/tests/ui/nonminimal_bool.stderr index 1d39bce935db..bb93cbbd5e19 100644 --- a/tests/ui/nonminimal_bool.stderr +++ b/tests/ui/nonminimal_bool.stderr @@ -50,10 +50,10 @@ LL | let _ = a == b && c == 5 && a == b; | help: try | -LL | let _ = a == b && c == 5; - | ~~~~~~~~~~~~~~~~ LL | let _ = !(a != b || c != 5); | ~~~~~~~~~~~~~~~~~~~ +LL | let _ = a == b && c == 5; + | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified --> $DIR/nonminimal_bool.rs:28:13 @@ -63,10 +63,10 @@ LL | let _ = a == b || c == 5 || a == b; | help: try | -LL | let _ = a == b || c == 5; - | ~~~~~~~~~~~~~~~~ LL | let _ = !(a != b && c != 5); | ~~~~~~~~~~~~~~~~~~~ +LL | let _ = a == b || c == 5; + | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified --> $DIR/nonminimal_bool.rs:29:13 @@ -76,10 +76,10 @@ LL | let _ = a == b && c == 5 && b == a; | help: try | -LL | let _ = a == b && c == 5; - | ~~~~~~~~~~~~~~~~ LL | let _ = !(a != b || c != 5); | ~~~~~~~~~~~~~~~~~~~ +LL | let _ = a == b && c == 5; + | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified --> $DIR/nonminimal_bool.rs:30:13 @@ -89,10 +89,10 @@ LL | let _ = a != b || !(a != b || c == d); | help: try | -LL | let _ = a != b || c != d; - | ~~~~~~~~~~~~~~~~ LL | let _ = !(a == b && c == d); | ~~~~~~~~~~~~~~~~~~~ +LL | let _ = a != b || c != d; + | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified --> $DIR/nonminimal_bool.rs:31:13 @@ -102,10 +102,10 @@ LL | let _ = a != b && !(a != b && c == d); | help: try | -LL | let _ = a != b && c != d; - | ~~~~~~~~~~~~~~~~ LL | let _ = !(a == b || c == d); | ~~~~~~~~~~~~~~~~~~~ +LL | let _ = a != b && c != d; + | ~~~~~~~~~~~~~~~~ error: aborting due to 12 previous errors From db4408af01649a02d4f8bd278ddab547f3e48bf7 Mon Sep 17 00:00:00 2001 From: John Kugelman Date: Mon, 11 Oct 2021 16:15:50 -0400 Subject: [PATCH 0348/1222] Add #[must_use] to len and is_empty --- tests/ui/iter_count.fixed | 7 +++-- tests/ui/iter_count.rs | 7 +++-- tests/ui/iter_count.stderr | 62 +++++++++++++++++++------------------- 3 files changed, 39 insertions(+), 37 deletions(-) diff --git a/tests/ui/iter_count.fixed b/tests/ui/iter_count.fixed index 97c5929783d8..90a6eef75261 100644 --- a/tests/ui/iter_count.fixed +++ b/tests/ui/iter_count.fixed @@ -33,6 +33,7 @@ impl HasIter { } } +#[allow(unused_must_use)] fn main() { let mut vec = vec![0, 1, 2, 3]; let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); @@ -50,7 +51,7 @@ fn main() { linked_list.push_back(1); binary_heap.push(1); - let _ = &vec[..].len(); + &vec[..].len(); vec.len(); boxed_slice.len(); vec_deque.len(); @@ -62,13 +63,13 @@ fn main() { binary_heap.len(); vec.len(); - let _ = &vec[..].len(); + &vec[..].len(); vec_deque.len(); hash_map.len(); b_tree_map.len(); linked_list.len(); - let _ = &vec[..].len(); + &vec[..].len(); vec.len(); vec_deque.len(); hash_set.len(); diff --git a/tests/ui/iter_count.rs b/tests/ui/iter_count.rs index 70bb734763f0..6681a480a28c 100644 --- a/tests/ui/iter_count.rs +++ b/tests/ui/iter_count.rs @@ -33,6 +33,7 @@ impl HasIter { } } +#[allow(unused_must_use)] fn main() { let mut vec = vec![0, 1, 2, 3]; let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); @@ -50,7 +51,7 @@ fn main() { linked_list.push_back(1); binary_heap.push(1); - let _ = &vec[..].iter().count(); + &vec[..].iter().count(); vec.iter().count(); boxed_slice.iter().count(); vec_deque.iter().count(); @@ -62,13 +63,13 @@ fn main() { binary_heap.iter().count(); vec.iter_mut().count(); - let _ = &vec[..].iter_mut().count(); + &vec[..].iter_mut().count(); vec_deque.iter_mut().count(); hash_map.iter_mut().count(); b_tree_map.iter_mut().count(); linked_list.iter_mut().count(); - let _ = &vec[..].into_iter().count(); + &vec[..].into_iter().count(); vec.into_iter().count(); vec_deque.into_iter().count(); hash_set.into_iter().count(); diff --git a/tests/ui/iter_count.stderr b/tests/ui/iter_count.stderr index 1d2c22f9dfad..2e3d7fc35de9 100644 --- a/tests/ui/iter_count.stderr +++ b/tests/ui/iter_count.stderr @@ -1,151 +1,151 @@ error: called `.iter().count()` on a `slice` - --> $DIR/iter_count.rs:53:14 + --> $DIR/iter_count.rs:54:6 | -LL | let _ = &vec[..].iter().count(); - | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` +LL | &vec[..].iter().count(); + | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` | = note: `-D clippy::iter-count` implied by `-D warnings` error: called `.iter().count()` on a `Vec` - --> $DIR/iter_count.rs:54:5 + --> $DIR/iter_count.rs:55:5 | LL | vec.iter().count(); | ^^^^^^^^^^^^^^^^^^ help: try: `vec.len()` error: called `.iter().count()` on a `slice` - --> $DIR/iter_count.rs:55:5 + --> $DIR/iter_count.rs:56:5 | LL | boxed_slice.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice.len()` error: called `.iter().count()` on a `VecDeque` - --> $DIR/iter_count.rs:56:5 + --> $DIR/iter_count.rs:57:5 | LL | vec_deque.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()` error: called `.iter().count()` on a `HashSet` - --> $DIR/iter_count.rs:57:5 + --> $DIR/iter_count.rs:58:5 | LL | hash_set.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_set.len()` error: called `.iter().count()` on a `HashMap` - --> $DIR/iter_count.rs:58:5 + --> $DIR/iter_count.rs:59:5 | LL | hash_map.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()` error: called `.iter().count()` on a `BTreeMap` - --> $DIR/iter_count.rs:59:5 + --> $DIR/iter_count.rs:60:5 | LL | b_tree_map.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()` error: called `.iter().count()` on a `BTreeSet` - --> $DIR/iter_count.rs:60:5 + --> $DIR/iter_count.rs:61:5 | LL | b_tree_set.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_set.len()` error: called `.iter().count()` on a `LinkedList` - --> $DIR/iter_count.rs:61:5 + --> $DIR/iter_count.rs:62:5 | LL | linked_list.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()` error: called `.iter().count()` on a `BinaryHeap` - --> $DIR/iter_count.rs:62:5 + --> $DIR/iter_count.rs:63:5 | LL | binary_heap.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `binary_heap.len()` error: called `.iter_mut().count()` on a `Vec` - --> $DIR/iter_count.rs:64:5 + --> $DIR/iter_count.rs:65:5 | LL | vec.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()` error: called `.iter_mut().count()` on a `slice` - --> $DIR/iter_count.rs:65:14 + --> $DIR/iter_count.rs:66:6 | -LL | let _ = &vec[..].iter_mut().count(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` +LL | &vec[..].iter_mut().count(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` error: called `.iter_mut().count()` on a `VecDeque` - --> $DIR/iter_count.rs:66:5 + --> $DIR/iter_count.rs:67:5 | LL | vec_deque.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()` error: called `.iter_mut().count()` on a `HashMap` - --> $DIR/iter_count.rs:67:5 + --> $DIR/iter_count.rs:68:5 | LL | hash_map.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()` error: called `.iter_mut().count()` on a `BTreeMap` - --> $DIR/iter_count.rs:68:5 + --> $DIR/iter_count.rs:69:5 | LL | b_tree_map.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()` error: called `.iter_mut().count()` on a `LinkedList` - --> $DIR/iter_count.rs:69:5 + --> $DIR/iter_count.rs:70:5 | LL | linked_list.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()` error: called `.into_iter().count()` on a `slice` - --> $DIR/iter_count.rs:71:14 + --> $DIR/iter_count.rs:72:6 | -LL | let _ = &vec[..].into_iter().count(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` +LL | &vec[..].into_iter().count(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` error: called `.into_iter().count()` on a `Vec` - --> $DIR/iter_count.rs:72:5 + --> $DIR/iter_count.rs:73:5 | LL | vec.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()` error: called `.into_iter().count()` on a `VecDeque` - --> $DIR/iter_count.rs:73:5 + --> $DIR/iter_count.rs:74:5 | LL | vec_deque.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()` error: called `.into_iter().count()` on a `HashSet` - --> $DIR/iter_count.rs:74:5 + --> $DIR/iter_count.rs:75:5 | LL | hash_set.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_set.len()` error: called `.into_iter().count()` on a `HashMap` - --> $DIR/iter_count.rs:75:5 + --> $DIR/iter_count.rs:76:5 | LL | hash_map.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()` error: called `.into_iter().count()` on a `BTreeMap` - --> $DIR/iter_count.rs:76:5 + --> $DIR/iter_count.rs:77:5 | LL | b_tree_map.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()` error: called `.into_iter().count()` on a `BTreeSet` - --> $DIR/iter_count.rs:77:5 + --> $DIR/iter_count.rs:78:5 | LL | b_tree_set.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_set.len()` error: called `.into_iter().count()` on a `LinkedList` - --> $DIR/iter_count.rs:78:5 + --> $DIR/iter_count.rs:79:5 | LL | linked_list.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()` error: called `.into_iter().count()` on a `BinaryHeap` - --> $DIR/iter_count.rs:79:5 + --> $DIR/iter_count.rs:80:5 | LL | binary_heap.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `binary_heap.len()` From 4f5016cbe7e5acac3f3e1f6ca597d4a5dbfdfb8e Mon Sep 17 00:00:00 2001 From: xFrednet Date: Tue, 2 Nov 2021 14:19:31 +0100 Subject: [PATCH 0349/1222] Update clippy dependencies * semver = "0.11" -> "1.0" * cargo_metadata = "0.12" -> "0.14" --- Cargo.toml | 4 ++-- clippy_lints/Cargo.toml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ed7fb1440139..d475aaa3ee06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,12 +22,12 @@ path = "src/driver.rs" [dependencies] clippy_lints = { version = "0.1", path = "clippy_lints" } -semver = "0.11" +semver = "1.0" rustc_tools_util = { version = "0.2", path = "rustc_tools_util" } tempfile = { version = "3.2", optional = true } [dev-dependencies] -cargo_metadata = "0.12" +cargo_metadata = "0.14" compiletest_rs = { version = "0.7", features = ["tmp"] } tester = "0.9" regex = "1.5" diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index aaf9ac83d490..281480b8d949 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -9,7 +9,7 @@ keywords = ["clippy", "lint", "plugin"] edition = "2021" [dependencies] -cargo_metadata = "0.12" +cargo_metadata = "0.14" clippy_utils = { path = "../clippy_utils" } if_chain = "1.0" itertools = "0.10" @@ -21,7 +21,7 @@ serde_json = { version = "1.0", optional = true } toml = "0.5" unicode-normalization = "0.1" unicode-script = { version = "0.5", default-features = false } -semver = "0.11" +semver = "1.0" rustc-semver = "1.1" # NOTE: cargo requires serde feat in its url dep # see From 6b017df9e9fbfdde2c953778f7f1a3cf3eecff5b Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sat, 6 Nov 2021 16:03:32 -0500 Subject: [PATCH 0350/1222] Fix Clippy with changed format_args! --- clippy_utils/src/higher.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index b3a9a1de2ec9..733cc97c8459 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -3,12 +3,12 @@ #![deny(clippy::missing_docs_in_private_items)] use crate::ty::is_type_diagnostic_item; -use crate::{is_expn_of, last_path_segment, match_def_path, path_to_local_id, paths}; +use crate::{is_expn_of, last_path_segment, match_def_path, paths}; use if_chain::if_chain; use rustc_ast::ast::{self, LitKind}; use rustc_hir as hir; use rustc_hir::{ - Arm, Block, BorrowKind, Expr, ExprKind, HirId, LoopSource, MatchSource, Node, Pat, PatKind, QPath, StmtKind, UnOp, + Arm, Block, BorrowKind, Expr, ExprKind, HirId, LoopSource, MatchSource, Node, Pat, QPath, StmtKind, UnOp, }; use rustc_lint::LateContext; use rustc_span::{sym, symbol, ExpnKind, Span, Symbol}; @@ -513,8 +513,6 @@ pub struct FormatArgsExpn<'tcx> { pub format_string_parts: &'tcx [Expr<'tcx>], /// Symbols corresponding to [`Self::format_string_parts`] pub format_string_symbols: Vec, - /// Match arm patterns, the `arg0`, etc. from the next field `args` - pub arg_names: &'tcx [Pat<'tcx>], /// Expressions like `ArgumentV1::new(arg0, Debug::fmt)` pub args: &'tcx [Expr<'tcx>], /// The final argument passed to `Arguments::new_v1_formatted`, if applicable @@ -559,7 +557,6 @@ impl FormatArgsExpn<'tcx> { _ => None, }) .collect(); - if let PatKind::Tuple(arg_names, None) = arm.pat.kind; if let ExprKind::Array(args) = arm.body.kind; then { Some(FormatArgsExpn { @@ -567,7 +564,6 @@ impl FormatArgsExpn<'tcx> { value_args, format_string_parts, format_string_symbols, - arg_names, args, fmt_expr, }) @@ -594,10 +590,8 @@ impl FormatArgsExpn<'tcx> { if let Ok(i) = usize::try_from(position); let arg = &self.args[i]; if let ExprKind::Call(_, [arg_name, _]) = arg.kind; - if let Some(j) = self - .arg_names - .iter() - .position(|pat| path_to_local_id(arg_name, pat.hir_id)); + if let ExprKind::Field(_, j) = arg_name.kind; + if let Ok(j) = j.name.as_str().parse::(); then { Some(FormatArgsArg { value: self.value_args[j], arg, fmt: Some(fmt) }) } else { From 66b8915a8ec691daba2e6e242e61ff1faa658c60 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 2 Oct 2021 12:59:26 +0100 Subject: [PATCH 0351/1222] Give inline const separate DefKind --- clippy_lints/src/matches.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index eb311983b292..7142df98c3f1 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -1065,7 +1065,10 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) PatKind::Path(path) => { #[allow(clippy::match_same_arms)] let id = match cx.qpath_res(path, pat.hir_id) { - Res::Def(DefKind::Const | DefKind::ConstParam | DefKind::AnonConst, _) => return, + Res::Def( + DefKind::Const | DefKind::ConstParam | DefKind::AnonConst | DefKind::InlineConst, + _, + ) => return, Res::Def(_, id) => id, _ => return, }; From 529cc973bedb5668167e8a0c3cdfa7857c696032 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 7 Nov 2021 16:43:49 +0800 Subject: [PATCH 0352/1222] ast: Fix naming conventions in AST structures TraitKind -> Trait TyAliasKind -> TyAlias ImplKind -> Impl FnKind -> Fn All `*Kind`s in AST are supposed to be enums. Tuple structs are converted to braced structs for the types above, and fields are reordered in syntactic order. Also, mutable AST visitor now correctly visit spans in defaultness, unsafety, impl polarity and constness. --- clippy_lints/src/doc.rs | 4 ++-- clippy_lints/src/excessive_bools.rs | 12 ++++++------ clippy_lints/src/non_expressive_names.rs | 6 +++--- clippy_lints/src/write.rs | 4 ++-- clippy_utils/src/ast_utils.rs | 25 +++++++++++++++--------- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 87ad5178ff08..d4ba072807f8 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -5,7 +5,7 @@ use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; use clippy_utils::{is_entrypoint_fn, is_expn_of, match_panic_def_id, method_chain_args, return_ty}; use if_chain::if_chain; use itertools::Itertools; -use rustc_ast::ast::{Async, AttrKind, Attribute, FnKind, FnRetTy, ItemKind}; +use rustc_ast::ast::{Async, AttrKind, Attribute, Fn, FnRetTy, ItemKind}; use rustc_ast::token::CommentKind; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; @@ -639,7 +639,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) => return false, // We found a main function ... - ItemKind::Fn(box FnKind(_, sig, _, Some(block))) if item.ident.name == sym::main => { + ItemKind::Fn(box Fn { sig, body: Some(block), .. }) if item.ident.name == sym::main => { let is_async = matches!(sig.header.asyncness, Async::Yes { .. }); let returns_nothing = match &sig.decl.output { FnRetTy::Default(..) => true, diff --git a/clippy_lints/src/excessive_bools.rs b/clippy_lints/src/excessive_bools.rs index 476e6d23f121..09b6e2008388 100644 --- a/clippy_lints/src/excessive_bools.rs +++ b/clippy_lints/src/excessive_bools.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::in_macro; -use rustc_ast::ast::{AssocItemKind, Extern, FnKind, FnSig, ImplKind, Item, ItemKind, TraitKind, Ty, TyKind}; +use rustc_ast::ast::{AssocItemKind, Extern, Fn, FnSig, Impl, Item, ItemKind, Trait, Ty, TyKind}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{sym, Span}; @@ -162,17 +162,17 @@ impl EarlyLintPass for ExcessiveBools { ); } }, - ItemKind::Impl(box ImplKind { + ItemKind::Impl(box Impl { of_trait: None, items, .. }) - | ItemKind::Trait(box TraitKind(.., items)) => { + | ItemKind::Trait(box Trait { items, .. }) => { for item in items { - if let AssocItemKind::Fn(box FnKind(_, fn_sig, _, _)) = &item.kind { - self.check_fn_sig(cx, fn_sig, item.span); + if let AssocItemKind::Fn(box Fn { sig, .. }) = &item.kind { + self.check_fn_sig(cx, sig, item.span); } } }, - ItemKind::Fn(box FnKind(_, fn_sig, _, _)) => self.check_fn_sig(cx, fn_sig, item.span), + ItemKind::Fn(box Fn { sig, .. }) => self.check_fn_sig(cx, sig, item.span), _ => (), } } diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 5b254bc8133d..e28cc49bf2a1 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; use rustc_ast::ast::{ - Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, FnKind, Item, ItemKind, Local, Pat, PatKind, + self, Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Item, ItemKind, Local, Pat, PatKind, }; use rustc_ast::visit::{walk_block, walk_expr, walk_pat, Visitor}; use rustc_lint::{EarlyContext, EarlyLintPass}; @@ -357,7 +357,7 @@ impl EarlyLintPass for NonExpressiveNames { return; } - if let ItemKind::Fn(box FnKind(_, ref sig, _, Some(ref blk))) = item.kind { + if let ItemKind::Fn(box ast::Fn { ref sig, body: Some(ref blk), .. }) = item.kind { do_check(self, cx, &item.attrs, &sig.decl, blk); } } @@ -367,7 +367,7 @@ impl EarlyLintPass for NonExpressiveNames { return; } - if let AssocItemKind::Fn(box FnKind(_, ref sig, _, Some(ref blk))) = item.kind { + if let AssocItemKind::Fn(box ast::Fn { ref sig, body: Some(ref blk), .. }) = item.kind { do_check(self, cx, &item.attrs, &sig.decl, blk); } } diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 85d1f65c51f0..b412e15ae4f8 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -4,7 +4,7 @@ use std::ops::{Deref, Range}; use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::{snippet_opt, snippet_with_applicability}; -use rustc_ast::ast::{Expr, ExprKind, ImplKind, Item, ItemKind, MacCall, Path, StrLit, StrStyle}; +use rustc_ast::ast::{Expr, ExprKind, Impl, Item, ItemKind, MacCall, Path, StrLit, StrStyle}; use rustc_ast::token::{self, LitKind}; use rustc_ast::tokenstream::TokenStream; use rustc_errors::Applicability; @@ -243,7 +243,7 @@ impl_lint_pass!(Write => [ impl EarlyLintPass for Write { fn check_item(&mut self, _: &EarlyContext<'_>, item: &Item) { - if let ItemKind::Impl(box ImplKind { + if let ItemKind::Impl(box Impl { of_trait: Some(trait_ref), .. }) = &item.kind diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 2fa98831c774..1b05a8a35046 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -250,7 +250,8 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { (Use(l), Use(r)) => eq_use_tree(l, r), (Static(lt, lm, le), Static(rt, rm, re)) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), (Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), - (Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => { + (Fn(box ast::Fn { defaultness: ld, sig: lf, generics: lg, body: lb }), + Fn(box ast::Fn { defaultness: rd, sig: rf, generics: rg, body: rb })) => { eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r)) }, (Mod(lu, lmk), Mod(ru, rmk)) => { @@ -266,7 +267,8 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { (ForeignMod(l), ForeignMod(r)) => { both(&l.abi, &r.abi, eq_str_lit) && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_foreign_item_kind)) }, - (TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => { + (TyAlias(box ast::TyAlias { defaultness: ld, generics: lg, bounds: lb, ty: lt }), + TyAlias(box ast::TyAlias { defaultness: rd, generics: rg, bounds: rb, ty: rt })) => { eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound) @@ -276,7 +278,8 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { (Struct(lv, lg), Struct(rv, rg)) | (Union(lv, lg), Union(rv, rg)) => { eq_variant_data(lv, rv) && eq_generics(lg, rg) }, - (Trait(box TraitKind(la, lu, lg, lb, li)), Trait(box TraitKind(ra, ru, rg, rb, ri))) => { + (Trait(box ast::Trait { is_auto: la, unsafety: lu, generics: lg, bounds: lb, items: li }), + Trait(box ast::Trait { is_auto: ra, unsafety: ru, generics: rg, bounds: rb, items: ri })) => { la == ra && matches!(lu, Unsafe::No) == matches!(ru, Unsafe::No) && eq_generics(lg, rg) @@ -285,7 +288,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { }, (TraitAlias(lg, lb), TraitAlias(rg, rb)) => eq_generics(lg, rg) && over(lb, rb, eq_generic_bound), ( - Impl(box ImplKind { + Impl(box ast::Impl { unsafety: lu, polarity: lp, defaultness: ld, @@ -295,7 +298,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { self_ty: lst, items: li, }), - Impl(box ImplKind { + Impl(box ast::Impl { unsafety: ru, polarity: rp, defaultness: rd, @@ -325,10 +328,12 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { use ForeignItemKind::*; match (l, r) { (Static(lt, lm, le), Static(rt, rm, re)) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), - (Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => { + (Fn(box ast::Fn { defaultness: ld, sig: lf, generics: lg, body: lb }), + Fn(box ast::Fn { defaultness: rd, sig: rf, generics: rg, body: rb })) => { eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r)) }, - (TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => { + (TyAlias(box ast::TyAlias { defaultness: ld, generics: lg, bounds: lb, ty: lt }), + TyAlias(box ast::TyAlias { defaultness: rd, generics: rg, bounds: rb, ty: rt })) => { eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound) @@ -343,10 +348,12 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { use AssocItemKind::*; match (l, r) { (Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), - (Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => { + (Fn(box ast::Fn { defaultness: ld, sig: lf, generics: lg, body: lb }), + Fn(box ast::Fn { defaultness: rd, sig: rf, generics: rg, body: rb })) => { eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r)) }, - (TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => { + (TyAlias(box ast::TyAlias { defaultness: ld, generics: lg, bounds: lb, ty: lt }), + TyAlias(box ast::TyAlias { defaultness: rd, generics: rg, bounds: rb, ty: rt })) => { eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound) From 666cdb2152d64dba8aee2fe33db9e4b93458e4d6 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 20 Jul 2021 23:23:22 -0400 Subject: [PATCH 0353/1222] Don't abort compilation after giving a lint error The only reason to use `abort_if_errors` is when the program is so broken that either: 1. later passes get confused and ICE 2. any diagnostics from later passes would be noise This is never the case for lints, because the compiler has to be able to deal with `allow`-ed lints. So it can continue to lint and compile even if there are lint errors. --- .../ui-toml/lint_decimal_readability/test.rs | 1 + .../lint_decimal_readability/test.stderr | 2 +- tests/ui/deref_addrof.fixed | 4 +- tests/ui/deref_addrof.rs | 4 +- tests/ui/double_neg.rs | 1 + tests/ui/double_neg.stderr | 2 +- tests/ui/fn_params_excessive_bools.rs | 1 + tests/ui/fn_params_excessive_bools.stderr | 12 ++--- tests/ui/formatting.rs | 1 + tests/ui/formatting.stderr | 12 ++--- tests/ui/literals.rs | 2 +- tests/ui/many_single_char_names.rs | 1 + tests/ui/many_single_char_names.stderr | 10 ++-- tests/ui/mistyped_literal_suffix.fixed | 2 +- tests/ui/mistyped_literal_suffix.rs | 2 +- tests/ui/mistyped_literal_suffix.stderr | 18 +++---- .../needless_arbitrary_self_type_unfixable.rs | 1 + ...dless_arbitrary_self_type_unfixable.stderr | 2 +- tests/ui/needless_continue.rs | 1 + tests/ui/needless_continue.stderr | 16 +++--- tests/ui/non_expressive_names.rs | 4 +- tests/ui/non_expressive_names.stderr | 12 ++--- tests/ui/redundant_closure_call_early.rs | 1 + tests/ui/redundant_else.rs | 4 +- tests/ui/similar_names.rs | 7 ++- tests/ui/similar_names.stderr | 28 +++++----- tests/ui/suspicious_else_formatting.rs | 1 + tests/ui/suspicious_else_formatting.stderr | 18 +++---- tests/ui/suspicious_operation_groupings.rs | 3 +- .../ui/suspicious_operation_groupings.stderr | 52 +++++++++---------- 30 files changed, 123 insertions(+), 102 deletions(-) diff --git a/tests/ui-toml/lint_decimal_readability/test.rs b/tests/ui-toml/lint_decimal_readability/test.rs index 9377eb69b233..2498672d77fb 100644 --- a/tests/ui-toml/lint_decimal_readability/test.rs +++ b/tests/ui-toml/lint_decimal_readability/test.rs @@ -1,3 +1,4 @@ +#![allow(clippy::excessive_precision)] #[deny(clippy::unreadable_literal)] fn allow_inconsistent_digit_grouping() { diff --git a/tests/ui-toml/lint_decimal_readability/test.stderr b/tests/ui-toml/lint_decimal_readability/test.stderr index 9119ef19a7be..be505bda4792 100644 --- a/tests/ui-toml/lint_decimal_readability/test.stderr +++ b/tests/ui-toml/lint_decimal_readability/test.stderr @@ -1,5 +1,5 @@ error: digits grouped inconsistently by underscores - --> $DIR/test.rs:18:18 + --> $DIR/test.rs:19:18 | LL | let _fail1 = 100_200_300.123456789; | ^^^^^^^^^^^^^^^^^^^^^ help: consider: `100_200_300.123_456_789` diff --git a/tests/ui/deref_addrof.fixed b/tests/ui/deref_addrof.fixed index d4832daa6895..9a150c67a21e 100644 --- a/tests/ui/deref_addrof.fixed +++ b/tests/ui/deref_addrof.fixed @@ -52,12 +52,14 @@ macro_rules! m_mut { }; } +#[derive(Copy, Clone)] pub struct S; impl S { pub fn f(&self) -> &Self { m!(self) } - pub fn f_mut(&self) -> &Self { + #[allow(unused_mut)] // mut will be unused, once the macro is fixed + pub fn f_mut(mut self) -> Self { m_mut!(self) } } diff --git a/tests/ui/deref_addrof.rs b/tests/ui/deref_addrof.rs index be7cc669b5b6..80ba7e9bd0b8 100644 --- a/tests/ui/deref_addrof.rs +++ b/tests/ui/deref_addrof.rs @@ -52,12 +52,14 @@ macro_rules! m_mut { }; } +#[derive(Copy, Clone)] pub struct S; impl S { pub fn f(&self) -> &Self { m!(self) } - pub fn f_mut(&self) -> &Self { + #[allow(unused_mut)] // mut will be unused, once the macro is fixed + pub fn f_mut(mut self) -> Self { m_mut!(self) } } diff --git a/tests/ui/double_neg.rs b/tests/ui/double_neg.rs index d47dfcb5ba1e..38a8fbd74dcf 100644 --- a/tests/ui/double_neg.rs +++ b/tests/ui/double_neg.rs @@ -1,4 +1,5 @@ #[warn(clippy::double_neg)] +#[allow(clippy::no_effect)] fn main() { let x = 1; -x; diff --git a/tests/ui/double_neg.stderr b/tests/ui/double_neg.stderr index d82ed05f0543..7cdb040b6873 100644 --- a/tests/ui/double_neg.stderr +++ b/tests/ui/double_neg.stderr @@ -1,5 +1,5 @@ error: `--x` could be misinterpreted as pre-decrement by C programmers, is usually a no-op - --> $DIR/double_neg.rs:6:5 + --> $DIR/double_neg.rs:7:5 | LL | --x; | ^^^ diff --git a/tests/ui/fn_params_excessive_bools.rs b/tests/ui/fn_params_excessive_bools.rs index 7d6fd607e654..1442ee08e754 100644 --- a/tests/ui/fn_params_excessive_bools.rs +++ b/tests/ui/fn_params_excessive_bools.rs @@ -1,4 +1,5 @@ #![warn(clippy::fn_params_excessive_bools)] +#![allow(clippy::too_many_arguments)] extern "C" { fn f(_: bool, _: bool, _: bool, _: bool); diff --git a/tests/ui/fn_params_excessive_bools.stderr b/tests/ui/fn_params_excessive_bools.stderr index 4e5dbc261d66..cd9d07fa115d 100644 --- a/tests/ui/fn_params_excessive_bools.stderr +++ b/tests/ui/fn_params_excessive_bools.stderr @@ -1,5 +1,5 @@ error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:17:1 + --> $DIR/fn_params_excessive_bools.rs:18:1 | LL | fn g(_: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | fn g(_: bool, _: bool, _: bool, _: bool) {} = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:20:1 + --> $DIR/fn_params_excessive_bools.rs:21:1 | LL | fn t(_: S, _: S, _: Box, _: Vec, _: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | fn t(_: S, _: S, _: Box, _: Vec, _: bool, _: bool, _: bool, _: bool = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:24:5 + --> $DIR/fn_params_excessive_bools.rs:25:5 | LL | fn f(_: bool, _: bool, _: bool, _: bool); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | fn f(_: bool, _: bool, _: bool, _: bool); = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:29:5 + --> $DIR/fn_params_excessive_bools.rs:30:5 | LL | fn f(&self, _: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | fn f(&self, _: bool, _: bool, _: bool, _: bool) {} = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:41:5 + --> $DIR/fn_params_excessive_bools.rs:42:5 | LL | / fn n(_: bool, _: u32, _: bool, _: Box, _: bool, _: bool) { LL | | fn nn(_: bool, _: bool, _: bool, _: bool) {} @@ -42,7 +42,7 @@ LL | | } = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:42:9 + --> $DIR/fn_params_excessive_bools.rs:43:9 | LL | fn nn(_: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/formatting.rs b/tests/ui/formatting.rs index 0d14807ff1cf..471a8e0de6e1 100644 --- a/tests/ui/formatting.rs +++ b/tests/ui/formatting.rs @@ -3,6 +3,7 @@ #![allow(unused_assignments)] #![allow(clippy::if_same_then_else)] #![allow(clippy::deref_addrof)] +#![allow(clippy::nonminimal_bool)] fn foo() -> bool { true diff --git a/tests/ui/formatting.stderr b/tests/ui/formatting.stderr index bde434c7e2e7..9272cd604844 100644 --- a/tests/ui/formatting.stderr +++ b/tests/ui/formatting.stderr @@ -1,5 +1,5 @@ error: this looks like you are trying to use `.. -= ..`, but you really are doing `.. = (- ..)` - --> $DIR/formatting.rs:15:6 + --> $DIR/formatting.rs:16:6 | LL | a =- 35; | ^^^^ @@ -8,7 +8,7 @@ LL | a =- 35; = note: to remove this lint, use either `-=` or `= -` error: this looks like you are trying to use `.. *= ..`, but you really are doing `.. = (* ..)` - --> $DIR/formatting.rs:16:6 + --> $DIR/formatting.rs:17:6 | LL | a =* &191; | ^^^^ @@ -16,7 +16,7 @@ LL | a =* &191; = note: to remove this lint, use either `*=` or `= *` error: this looks like you are trying to use `.. != ..`, but you really are doing `.. = (! ..)` - --> $DIR/formatting.rs:19:6 + --> $DIR/formatting.rs:20:6 | LL | b =! false; | ^^^^ @@ -24,7 +24,7 @@ LL | b =! false; = note: to remove this lint, use either `!=` or `= !` error: possibly missing a comma here - --> $DIR/formatting.rs:28:19 + --> $DIR/formatting.rs:29:19 | LL | -1, -2, -3 // <= no comma here | ^ @@ -33,7 +33,7 @@ LL | -1, -2, -3 // <= no comma here = note: to remove this lint, add a comma or write the expr in a single line error: possibly missing a comma here - --> $DIR/formatting.rs:32:19 + --> $DIR/formatting.rs:33:19 | LL | -1, -2, -3 // <= no comma here | ^ @@ -41,7 +41,7 @@ LL | -1, -2, -3 // <= no comma here = note: to remove this lint, add a comma or write the expr in a single line error: possibly missing a comma here - --> $DIR/formatting.rs:69:11 + --> $DIR/formatting.rs:70:11 | LL | -1 | ^ diff --git a/tests/ui/literals.rs b/tests/ui/literals.rs index e60ce8492fc7..0cadd5a3da19 100644 --- a/tests/ui/literals.rs +++ b/tests/ui/literals.rs @@ -4,7 +4,7 @@ #![warn(clippy::zero_prefixed_literal)] #![warn(clippy::unseparated_literal_suffix)] #![warn(clippy::separated_literal_suffix)] -#![allow(dead_code)] +#![allow(dead_code, overflowing_literals)] fn main() { let ok1 = 0xABCD; diff --git a/tests/ui/many_single_char_names.rs b/tests/ui/many_single_char_names.rs index 65769819110e..88fcce66873a 100644 --- a/tests/ui/many_single_char_names.rs +++ b/tests/ui/many_single_char_names.rs @@ -1,3 +1,4 @@ +#![allow(clippy::too_many_arguments, clippy::diverging_sub_expression)] #![warn(clippy::many_single_char_names)] fn bla() { diff --git a/tests/ui/many_single_char_names.stderr b/tests/ui/many_single_char_names.stderr index 27e62e641ade..ade0f84bc506 100644 --- a/tests/ui/many_single_char_names.stderr +++ b/tests/ui/many_single_char_names.stderr @@ -1,5 +1,5 @@ error: 5 bindings with single-character names in scope - --> $DIR/many_single_char_names.rs:4:9 + --> $DIR/many_single_char_names.rs:5:9 | LL | let a: i32; | ^ @@ -12,7 +12,7 @@ LL | let e: i32; = note: `-D clippy::many-single-char-names` implied by `-D warnings` error: 6 bindings with single-character names in scope - --> $DIR/many_single_char_names.rs:4:9 + --> $DIR/many_single_char_names.rs:5:9 | LL | let a: i32; | ^ @@ -25,7 +25,7 @@ LL | let f: i32; | ^ error: 5 bindings with single-character names in scope - --> $DIR/many_single_char_names.rs:4:9 + --> $DIR/many_single_char_names.rs:5:9 | LL | let a: i32; | ^ @@ -36,13 +36,13 @@ LL | e => panic!(), | ^ error: 8 bindings with single-character names in scope - --> $DIR/many_single_char_names.rs:29:13 + --> $DIR/many_single_char_names.rs:30:13 | LL | fn bindings(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) {} | ^ ^ ^ ^ ^ ^ ^ ^ error: 8 bindings with single-character names in scope - --> $DIR/many_single_char_names.rs:32:10 + --> $DIR/many_single_char_names.rs:33:10 | LL | let (a, b, c, d, e, f, g, h): (bool, bool, bool, bool, bool, bool, bool, bool) = unimplemented!(); | ^ ^ ^ ^ ^ ^ ^ ^ diff --git a/tests/ui/mistyped_literal_suffix.fixed b/tests/ui/mistyped_literal_suffix.fixed index 70cdb067d913..5d57638af434 100644 --- a/tests/ui/mistyped_literal_suffix.fixed +++ b/tests/ui/mistyped_literal_suffix.fixed @@ -3,6 +3,7 @@ #![allow( dead_code, unused_variables, + overflowing_literals, clippy::excessive_precision, clippy::inconsistent_digit_grouping )] @@ -21,7 +22,6 @@ fn main() { let fail25 = 1E2_f32; let fail26 = 43E7_f64; let fail27 = 243E17_f32; - #[allow(overflowing_literals)] let fail28 = 241_251_235E723_f64; let ok29 = 42279.911_32; diff --git a/tests/ui/mistyped_literal_suffix.rs b/tests/ui/mistyped_literal_suffix.rs index 729990af3998..12171452885d 100644 --- a/tests/ui/mistyped_literal_suffix.rs +++ b/tests/ui/mistyped_literal_suffix.rs @@ -3,6 +3,7 @@ #![allow( dead_code, unused_variables, + overflowing_literals, clippy::excessive_precision, clippy::inconsistent_digit_grouping )] @@ -21,7 +22,6 @@ fn main() { let fail25 = 1E2_32; let fail26 = 43E7_64; let fail27 = 243E17_32; - #[allow(overflowing_literals)] let fail28 = 241251235E723_64; let ok29 = 42279.911_32; diff --git a/tests/ui/mistyped_literal_suffix.stderr b/tests/ui/mistyped_literal_suffix.stderr index b338b8aa6228..d24543c26e4b 100644 --- a/tests/ui/mistyped_literal_suffix.stderr +++ b/tests/ui/mistyped_literal_suffix.stderr @@ -1,5 +1,5 @@ error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:11:18 + --> $DIR/mistyped_literal_suffix.rs:12:18 | LL | let fail14 = 2_32; | ^^^^ help: did you mean to write: `2_i32` @@ -7,49 +7,49 @@ LL | let fail14 = 2_32; = note: `#[deny(clippy::mistyped_literal_suffixes)]` on by default error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:12:18 + --> $DIR/mistyped_literal_suffix.rs:13:18 | LL | let fail15 = 4_64; | ^^^^ help: did you mean to write: `4_i64` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:13:18 + --> $DIR/mistyped_literal_suffix.rs:14:18 | LL | let fail16 = 7_8; // | ^^^ help: did you mean to write: `7_i8` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:14:18 + --> $DIR/mistyped_literal_suffix.rs:15:18 | LL | let fail17 = 23_16; // | ^^^^^ help: did you mean to write: `23_i16` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:17:18 + --> $DIR/mistyped_literal_suffix.rs:18:18 | LL | let fail20 = 2__8; // | ^^^^ help: did you mean to write: `2_i8` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:18:18 + --> $DIR/mistyped_literal_suffix.rs:19:18 | LL | let fail21 = 4___16; // | ^^^^^^ help: did you mean to write: `4_i16` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:21:18 + --> $DIR/mistyped_literal_suffix.rs:22:18 | LL | let fail25 = 1E2_32; | ^^^^^^ help: did you mean to write: `1E2_f32` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:22:18 + --> $DIR/mistyped_literal_suffix.rs:23:18 | LL | let fail26 = 43E7_64; | ^^^^^^^ help: did you mean to write: `43E7_f64` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:23:18 + --> $DIR/mistyped_literal_suffix.rs:24:18 | LL | let fail27 = 243E17_32; | ^^^^^^^^^ help: did you mean to write: `243E17_f32` diff --git a/tests/ui/needless_arbitrary_self_type_unfixable.rs b/tests/ui/needless_arbitrary_self_type_unfixable.rs index a39d96109f17..ad0d694a2174 100644 --- a/tests/ui/needless_arbitrary_self_type_unfixable.rs +++ b/tests/ui/needless_arbitrary_self_type_unfixable.rs @@ -38,6 +38,7 @@ mod issue_6089 { // fn call_with_mut_self<'life0>(self: &'life0 mut Self) {} #[rename_my_lifetimes] impl T2 for S2 { + #[allow(clippy::needless_lifetimes)] fn call_with_mut_self(self: &mut Self) {} } } diff --git a/tests/ui/needless_arbitrary_self_type_unfixable.stderr b/tests/ui/needless_arbitrary_self_type_unfixable.stderr index 44a0e6ddeace..b2edbfe4323e 100644 --- a/tests/ui/needless_arbitrary_self_type_unfixable.stderr +++ b/tests/ui/needless_arbitrary_self_type_unfixable.stderr @@ -1,5 +1,5 @@ error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type_unfixable.rs:41:31 + --> $DIR/needless_arbitrary_self_type_unfixable.rs:42:31 | LL | fn call_with_mut_self(self: &mut Self) {} | ^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&'_ mut self` diff --git a/tests/ui/needless_continue.rs b/tests/ui/needless_continue.rs index 83ee27f4887a..f105d3d659ac 100644 --- a/tests/ui/needless_continue.rs +++ b/tests/ui/needless_continue.rs @@ -12,6 +12,7 @@ macro_rules! nonzero { }; } +#[allow(clippy::nonminimal_bool)] fn main() { let mut i = 1; while i < 10 { diff --git a/tests/ui/needless_continue.stderr b/tests/ui/needless_continue.stderr index 22b86f25e8f0..b8657c74caa6 100644 --- a/tests/ui/needless_continue.stderr +++ b/tests/ui/needless_continue.stderr @@ -1,5 +1,5 @@ error: this `else` block is redundant - --> $DIR/needless_continue.rs:28:16 + --> $DIR/needless_continue.rs:29:16 | LL | } else { | ________________^ @@ -35,7 +35,7 @@ LL | | } } error: there is no need for an explicit `else` block for this `if` expression - --> $DIR/needless_continue.rs:43:9 + --> $DIR/needless_continue.rs:44:9 | LL | / if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { LL | | continue; @@ -55,7 +55,7 @@ LL | | } } error: this `continue` expression is redundant - --> $DIR/needless_continue.rs:56:9 + --> $DIR/needless_continue.rs:57:9 | LL | continue; // should lint here | ^^^^^^^^^ @@ -63,7 +63,7 @@ LL | continue; // should lint here = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> $DIR/needless_continue.rs:63:9 + --> $DIR/needless_continue.rs:64:9 | LL | continue; // should lint here | ^^^^^^^^^ @@ -71,7 +71,7 @@ LL | continue; // should lint here = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> $DIR/needless_continue.rs:70:9 + --> $DIR/needless_continue.rs:71:9 | LL | continue // should lint here | ^^^^^^^^ @@ -79,7 +79,7 @@ LL | continue // should lint here = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> $DIR/needless_continue.rs:78:9 + --> $DIR/needless_continue.rs:79:9 | LL | continue // should lint here | ^^^^^^^^ @@ -87,7 +87,7 @@ LL | continue // should lint here = help: consider dropping the `continue` expression error: this `else` block is redundant - --> $DIR/needless_continue.rs:128:24 + --> $DIR/needless_continue.rs:129:24 | LL | } else { | ________________________^ @@ -110,7 +110,7 @@ LL | | } } error: there is no need for an explicit `else` block for this `if` expression - --> $DIR/needless_continue.rs:134:17 + --> $DIR/needless_continue.rs:135:17 | LL | / if condition() { LL | | continue; // should lint here diff --git a/tests/ui/non_expressive_names.rs b/tests/ui/non_expressive_names.rs index 961f6f409ddd..9937005d68d8 100644 --- a/tests/ui/non_expressive_names.rs +++ b/tests/ui/non_expressive_names.rs @@ -1,5 +1,5 @@ #![warn(clippy::all)] -#![allow(unused, clippy::println_empty_string)] +#![allow(unused, clippy::println_empty_string, non_snake_case)] #[derive(Clone, Debug)] enum MaybeInst { @@ -14,6 +14,7 @@ struct InstSplit { impl MaybeInst { fn fill(&mut self) { + #[allow(non_fmt_panics)] let filled = match *self { MaybeInst::Split1(goto1) => panic!("1"), MaybeInst::Split2(goto2) => panic!("2"), @@ -36,6 +37,7 @@ fn issue2927() { } fn issue3078() { + #[allow(clippy::single_match)] match "a" { stringify!(a) => {}, _ => {}, diff --git a/tests/ui/non_expressive_names.stderr b/tests/ui/non_expressive_names.stderr index a0ca46f0efc6..116d5da8729c 100644 --- a/tests/ui/non_expressive_names.stderr +++ b/tests/ui/non_expressive_names.stderr @@ -1,5 +1,5 @@ error: consider choosing a more descriptive name - --> $DIR/non_expressive_names.rs:27:9 + --> $DIR/non_expressive_names.rs:28:9 | LL | let _1 = 1; //~ERROR Consider a more descriptive name | ^^ @@ -7,31 +7,31 @@ LL | let _1 = 1; //~ERROR Consider a more descriptive name = note: `-D clippy::just-underscores-and-digits` implied by `-D warnings` error: consider choosing a more descriptive name - --> $DIR/non_expressive_names.rs:28:9 + --> $DIR/non_expressive_names.rs:29:9 | LL | let ____1 = 1; //~ERROR Consider a more descriptive name | ^^^^^ error: consider choosing a more descriptive name - --> $DIR/non_expressive_names.rs:29:9 + --> $DIR/non_expressive_names.rs:30:9 | LL | let __1___2 = 12; //~ERROR Consider a more descriptive name | ^^^^^^^ error: consider choosing a more descriptive name - --> $DIR/non_expressive_names.rs:49:13 + --> $DIR/non_expressive_names.rs:51:13 | LL | let _1 = 1; | ^^ error: consider choosing a more descriptive name - --> $DIR/non_expressive_names.rs:50:13 + --> $DIR/non_expressive_names.rs:52:13 | LL | let ____1 = 1; | ^^^^^ error: consider choosing a more descriptive name - --> $DIR/non_expressive_names.rs:51:13 + --> $DIR/non_expressive_names.rs:53:13 | LL | let __1___2 = 12; | ^^^^^^^ diff --git a/tests/ui/redundant_closure_call_early.rs b/tests/ui/redundant_closure_call_early.rs index 3dd365620ccb..5649d8dd14c4 100644 --- a/tests/ui/redundant_closure_call_early.rs +++ b/tests/ui/redundant_closure_call_early.rs @@ -15,5 +15,6 @@ fn main() { #[allow(clippy::needless_return)] (|| return 2)(); (|| -> Option { None? })(); + #[allow(clippy::try_err)] (|| -> Result { Err(2)? })(); } diff --git a/tests/ui/redundant_else.rs b/tests/ui/redundant_else.rs index 737c8a9f8db4..e8a6e940c01c 100644 --- a/tests/ui/redundant_else.rs +++ b/tests/ui/redundant_else.rs @@ -1,5 +1,5 @@ #![warn(clippy::redundant_else)] -#![allow(clippy::needless_return)] +#![allow(clippy::needless_return, clippy::if_same_then_else)] fn main() { loop { @@ -105,7 +105,7 @@ fn main() { 1 }; // assign - let a; + let mut a; a = if foo() { return; } else { diff --git a/tests/ui/similar_names.rs b/tests/ui/similar_names.rs index daa073414577..76f6ce9ee6b4 100644 --- a/tests/ui/similar_names.rs +++ b/tests/ui/similar_names.rs @@ -1,5 +1,10 @@ #![warn(clippy::similar_names)] -#![allow(unused, clippy::println_empty_string)] +#![allow( + unused, + clippy::println_empty_string, + clippy::empty_loop, + clippy::diverging_sub_expression +)] struct Foo { apple: i32, diff --git a/tests/ui/similar_names.stderr b/tests/ui/similar_names.stderr index f621595abaea..faf572b0c6bc 100644 --- a/tests/ui/similar_names.stderr +++ b/tests/ui/similar_names.stderr @@ -1,84 +1,84 @@ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:15:9 + --> $DIR/similar_names.rs:20:9 | LL | let bpple: i32; | ^^^^^ | = note: `-D clippy::similar-names` implied by `-D warnings` note: existing binding defined here - --> $DIR/similar_names.rs:13:9 + --> $DIR/similar_names.rs:18:9 | LL | let apple: i32; | ^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:17:9 + --> $DIR/similar_names.rs:22:9 | LL | let cpple: i32; | ^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:13:9 + --> $DIR/similar_names.rs:18:9 | LL | let apple: i32; | ^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:41:9 + --> $DIR/similar_names.rs:46:9 | LL | let bluby: i32; | ^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:40:9 + --> $DIR/similar_names.rs:45:9 | LL | let blubx: i32; | ^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:45:9 + --> $DIR/similar_names.rs:50:9 | LL | let coke: i32; | ^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:43:9 + --> $DIR/similar_names.rs:48:9 | LL | let cake: i32; | ^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:63:9 + --> $DIR/similar_names.rs:68:9 | LL | let xyzeabc: i32; | ^^^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:61:9 + --> $DIR/similar_names.rs:66:9 | LL | let xyz1abc: i32; | ^^^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:67:9 + --> $DIR/similar_names.rs:72:9 | LL | let parsee: i32; | ^^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:65:9 + --> $DIR/similar_names.rs:70:9 | LL | let parser: i32; | ^^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:88:16 + --> $DIR/similar_names.rs:93:16 | LL | bpple: sprang, | ^^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:87:16 + --> $DIR/similar_names.rs:92:16 | LL | apple: spring, | ^^^^^^ diff --git a/tests/ui/suspicious_else_formatting.rs b/tests/ui/suspicious_else_formatting.rs index be8bc22bf98a..fcd827a91c7f 100644 --- a/tests/ui/suspicious_else_formatting.rs +++ b/tests/ui/suspicious_else_formatting.rs @@ -1,6 +1,7 @@ // aux-build:proc_macro_suspicious_else_formatting.rs #![warn(clippy::suspicious_else_formatting)] +#![allow(clippy::if_same_then_else)] extern crate proc_macro_suspicious_else_formatting; use proc_macro_suspicious_else_formatting::DeriveBadSpan; diff --git a/tests/ui/suspicious_else_formatting.stderr b/tests/ui/suspicious_else_formatting.stderr index d1db195cbb87..ee68eb5a791c 100644 --- a/tests/ui/suspicious_else_formatting.stderr +++ b/tests/ui/suspicious_else_formatting.stderr @@ -1,5 +1,5 @@ error: this looks like an `else {..}` but the `else` is missing - --> $DIR/suspicious_else_formatting.rs:16:6 + --> $DIR/suspicious_else_formatting.rs:17:6 | LL | } { | ^ @@ -8,7 +8,7 @@ LL | } { = note: to remove this lint, add the missing `else` or add a new line before the next block error: this looks like an `else if` but the `else` is missing - --> $DIR/suspicious_else_formatting.rs:20:6 + --> $DIR/suspicious_else_formatting.rs:21:6 | LL | } if foo() { | ^ @@ -16,7 +16,7 @@ LL | } if foo() { = note: to remove this lint, add the missing `else` or add a new line before the second `if` error: this looks like an `else if` but the `else` is missing - --> $DIR/suspicious_else_formatting.rs:27:10 + --> $DIR/suspicious_else_formatting.rs:28:10 | LL | } if foo() { | ^ @@ -24,7 +24,7 @@ LL | } if foo() { = note: to remove this lint, add the missing `else` or add a new line before the second `if` error: this looks like an `else if` but the `else` is missing - --> $DIR/suspicious_else_formatting.rs:35:10 + --> $DIR/suspicious_else_formatting.rs:36:10 | LL | } if foo() { | ^ @@ -32,7 +32,7 @@ LL | } if foo() { = note: to remove this lint, add the missing `else` or add a new line before the second `if` error: this is an `else {..}` but the formatting might hide it - --> $DIR/suspicious_else_formatting.rs:44:6 + --> $DIR/suspicious_else_formatting.rs:45:6 | LL | } else | ______^ @@ -42,7 +42,7 @@ LL | | { = note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}` error: this is an `else if` but the formatting might hide it - --> $DIR/suspicious_else_formatting.rs:56:6 + --> $DIR/suspicious_else_formatting.rs:57:6 | LL | } else | ______^ @@ -52,7 +52,7 @@ LL | | if foo() { // the span of the above error should continue here = note: to remove this lint, remove the `else` or remove the new line between `else` and `if` error: this is an `else if` but the formatting might hide it - --> $DIR/suspicious_else_formatting.rs:61:6 + --> $DIR/suspicious_else_formatting.rs:62:6 | LL | } | ______^ @@ -63,7 +63,7 @@ LL | | if foo() { // the span of the above error should continue here = note: to remove this lint, remove the `else` or remove the new line between `else` and `if` error: this is an `else {..}` but the formatting might hide it - --> $DIR/suspicious_else_formatting.rs:88:6 + --> $DIR/suspicious_else_formatting.rs:89:6 | LL | } | ______^ @@ -75,7 +75,7 @@ LL | | { = note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}` error: this is an `else {..}` but the formatting might hide it - --> $DIR/suspicious_else_formatting.rs:96:6 + --> $DIR/suspicious_else_formatting.rs:97:6 | LL | } | ______^ diff --git a/tests/ui/suspicious_operation_groupings.rs b/tests/ui/suspicious_operation_groupings.rs index 2f8c7cec50f8..3201d5de0f35 100644 --- a/tests/ui/suspicious_operation_groupings.rs +++ b/tests/ui/suspicious_operation_groupings.rs @@ -1,4 +1,5 @@ #![warn(clippy::suspicious_operation_groupings)] +#![allow(clippy::eq_op)] struct Vec3 { x: f64, @@ -187,7 +188,7 @@ fn inside_fn_with_similar_expression(s1: &S, s2: &S, strict: bool) -> bool { } } -fn inside_an_if_statement(s1: &S, s2: &S) { +fn inside_an_if_statement(s1: &mut S, s2: &S) { // There's no `s1.b` if s1.a < s2.a && s1.a < s2.b { s1.c = s2.c; diff --git a/tests/ui/suspicious_operation_groupings.stderr b/tests/ui/suspicious_operation_groupings.stderr index dd6f2f6641d6..baf9bc74b000 100644 --- a/tests/ui/suspicious_operation_groupings.stderr +++ b/tests/ui/suspicious_operation_groupings.stderr @@ -1,5 +1,5 @@ error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:14:9 + --> $DIR/suspicious_operation_groupings.rs:15:9 | LL | self.x == other.y && self.y == other.y && self.z == other.z | ^^^^^^^^^^^^^^^^^ help: did you mean: `self.x == other.x` @@ -7,151 +7,151 @@ LL | self.x == other.y && self.y == other.y && self.z == other.z = note: `-D clippy::suspicious-operation-groupings` implied by `-D warnings` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:27:20 + --> $DIR/suspicious_operation_groupings.rs:28:20 | LL | s1.a < s2.a && s1.a < s2.b | ^^^^^^^^^^^ help: did you mean: `s1.b < s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:75:33 + --> $DIR/suspicious_operation_groupings.rs:76:33 | LL | s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:80:19 + --> $DIR/suspicious_operation_groupings.rs:81:19 | LL | s1.a * s2.a + s1.b * s2.c + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:80:19 + --> $DIR/suspicious_operation_groupings.rs:81:19 | LL | s1.a * s2.a + s1.b * s2.c + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:85:19 + --> $DIR/suspicious_operation_groupings.rs:86:19 | LL | s1.a * s2.a + s2.b * s2.b + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:90:19 + --> $DIR/suspicious_operation_groupings.rs:91:19 | LL | s1.a * s2.a + s1.b * s1.b + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:95:5 + --> $DIR/suspicious_operation_groupings.rs:96:5 | LL | s1.a * s1.a + s1.b * s2.b + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.a * s2.a` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:100:33 + --> $DIR/suspicious_operation_groupings.rs:101:33 | LL | s1.a * s2.a + s1.b * s2.b + s1.c * s1.c | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:113:20 + --> $DIR/suspicious_operation_groupings.rs:114:20 | LL | (s1.a * s2.a + s1.b * s1.b) | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:118:34 + --> $DIR/suspicious_operation_groupings.rs:119:34 | LL | (s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:123:38 + --> $DIR/suspicious_operation_groupings.rs:124:38 | LL | (s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:128:39 + --> $DIR/suspicious_operation_groupings.rs:129:39 | LL | ((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d)) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:133:42 + --> $DIR/suspicious_operation_groupings.rs:134:42 | LL | (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.b) + (s1.d * s2.d))) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:133:42 + --> $DIR/suspicious_operation_groupings.rs:134:42 | LL | (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.b) + (s1.d * s2.d))) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:138:40 + --> $DIR/suspicious_operation_groupings.rs:139:40 | LL | (((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b)) + (s1.d * s2.d)) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:143:40 + --> $DIR/suspicious_operation_groupings.rs:144:40 | LL | ((s1.a * s2.a) + ((s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d))) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:148:20 + --> $DIR/suspicious_operation_groupings.rs:149:20 | LL | (s1.a * s2.a + s2.b * s2.b) / 2 | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:153:35 + --> $DIR/suspicious_operation_groupings.rs:154:35 | LL | i32::swap_bytes(s1.a * s2.a + s2.b * s2.b) | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:158:29 + --> $DIR/suspicious_operation_groupings.rs:159:29 | LL | s1.a > 0 && s1.b > 0 && s1.d == s2.c && s1.d == s2.d | ^^^^^^^^^^^^ help: did you mean: `s1.c == s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:163:17 + --> $DIR/suspicious_operation_groupings.rs:164:17 | LL | s1.a > 0 && s1.d == s2.c && s1.b > 0 && s1.d == s2.d | ^^^^^^^^^^^^ help: did you mean: `s1.c == s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:172:77 + --> $DIR/suspicious_operation_groupings.rs:173:77 | LL | (n1.inner.0).0 == (n2.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.1).0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `(n1.inner.2).0 == (n2.inner.2).0` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:186:25 + --> $DIR/suspicious_operation_groupings.rs:187:25 | LL | s1.a <= s2.a && s1.a <= s2.b | ^^^^^^^^^^^^ help: did you mean: `s1.b <= s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:192:23 + --> $DIR/suspicious_operation_groupings.rs:193:23 | LL | if s1.a < s2.a && s1.a < s2.b { | ^^^^^^^^^^^ help: did you mean: `s1.b < s2.b` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:199:48 + --> $DIR/suspicious_operation_groupings.rs:200:48 | LL | -(-(-s1.a * -s2.a) + (-(-s1.b * -s2.b) + -(-s1.c * -s2.b) + -(-s1.d * -s2.d))) | ^^^^^^^^^^^^^ help: did you mean: `-s1.c * -s2.c` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:204:27 + --> $DIR/suspicious_operation_groupings.rs:205:27 | LL | -(if -s1.a < -s2.a && -s1.a < -s2.b { s1.c } else { s2.a }) | ^^^^^^^^^^^^^ help: did you mean: `-s1.b < -s2.b` From 8313b44fc3254e1e0d35826c24672543eeb16efa Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Mon, 8 Nov 2021 23:35:23 +0800 Subject: [PATCH 0354/1222] Make select_* methods return Vec for TraitEngine --- clippy_lints/src/future_not_send.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index e18442515b8f..6b2ac985555d 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -77,13 +77,13 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { if is_future { let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap(); let span = decl.output.span(); - let send_result = cx.tcx.infer_ctxt().enter(|infcx| { + let send_errors = cx.tcx.infer_ctxt().enter(|infcx| { let cause = traits::ObligationCause::misc(span, hir_id); let mut fulfillment_cx = traits::FulfillmentContext::new(); fulfillment_cx.register_bound(&infcx, cx.param_env, ret_ty, send_trait, cause); fulfillment_cx.select_all_or_error(&infcx) }); - if let Err(send_errors) = send_result { + if !send_errors.is_empty() { span_lint_and_then( cx, FUTURE_NOT_SEND, From ed8c27457052302d0cefe741f2b4331ace976fad Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 18 Nov 2021 13:25:27 +0800 Subject: [PATCH 0355/1222] rustc: Remove `#[rustc_synthetic]` This function parameter attribute was introduced in https://github.com/rust-lang/rust/pull/44866 as an intermediate step in implementing `impl Trait`, it's not necessary or used anywhere by itself. --- clippy_lints/src/types/borrowed_box.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/types/borrowed_box.rs b/clippy_lints/src/types/borrowed_box.rs index bdeff035e5ec..63ad65b8afd9 100644 --- a/clippy_lints/src/types/borrowed_box.rs +++ b/clippy_lints/src/types/borrowed_box.rs @@ -3,10 +3,8 @@ use clippy_utils::source::snippet; use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::{ - self as hir, GenericArg, GenericBounds, GenericParamKind, HirId, Lifetime, MutTy, Mutability, Node, QPath, - SyntheticTyParamKind, TyKind, -}; +use rustc_hir::{self as hir, GenericArg, GenericBounds, GenericParamKind}; +use rustc_hir::{HirId, Lifetime, MutTy, Mutability, Node, QPath, TyKind}; use rustc_lint::LateContext; use super::BORROWED_BOX; @@ -105,7 +103,7 @@ fn get_bounds_if_impl_trait<'tcx>(cx: &LateContext<'tcx>, qpath: &QPath<'_>, id: if let Some(did) = cx.qpath_res(qpath, id).opt_def_id(); if let Some(Node::GenericParam(generic_param)) = cx.tcx.hir().get_if_local(did); if let GenericParamKind::Type { synthetic, .. } = generic_param.kind; - if synthetic == Some(SyntheticTyParamKind::ImplTrait); + if synthetic; then { Some(generic_param.bounds) } else { From 0c0ef6e395942cec785aaf9a8361d65f17953ea6 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Wed, 27 Oct 2021 09:48:06 -0500 Subject: [PATCH 0356/1222] Fix Clippy with changed for loop desugar --- .../src/loops/explicit_counter_loop.rs | 8 +-- clippy_lints/src/loops/manual_memcpy.rs | 4 +- clippy_lints/src/loops/mod.rs | 19 +++++- clippy_lints/src/loops/never_loop.rs | 58 +++++++++-------- clippy_lints/src/loops/single_element_loop.rs | 5 +- clippy_lints/src/loops/utils.rs | 12 ---- clippy_lints/src/misc.rs | 5 +- clippy_lints/src/unit_types/let_unit_value.rs | 4 -- clippy_utils/src/higher.rs | 62 +++++-------------- tests/ui/author/for_loop.stdout | 53 ++++++---------- 10 files changed, 90 insertions(+), 140 deletions(-) diff --git a/clippy_lints/src/loops/explicit_counter_loop.rs b/clippy_lints/src/loops/explicit_counter_loop.rs index 98e60f7ed85c..6f213d7a6990 100644 --- a/clippy_lints/src/loops/explicit_counter_loop.rs +++ b/clippy_lints/src/loops/explicit_counter_loop.rs @@ -1,6 +1,4 @@ -use super::{ - get_span_of_entire_for_loop, make_iterator_snippet, IncrementVisitor, InitializeVisitor, EXPLICIT_COUNTER_LOOP, -}; +use super::{make_iterator_snippet, IncrementVisitor, InitializeVisitor, EXPLICIT_COUNTER_LOOP}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::{get_enclosing_block, is_integer_const}; @@ -37,12 +35,10 @@ pub(super) fn check<'tcx>( then { let mut applicability = Applicability::MachineApplicable; - let for_span = get_span_of_entire_for_loop(expr); - span_lint_and_sugg( cx, EXPLICIT_COUNTER_LOOP, - for_span.with_hi(arg.span.hi()), + expr.span.with_hi(arg.span.hi()), &format!("the variable `{}` is used as a loop counter", name), "consider using", format!( diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index 72027a163af8..2362b4b20670 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -1,4 +1,4 @@ -use super::{get_span_of_entire_for_loop, IncrementVisitor, InitializeVisitor, MANUAL_MEMCPY}; +use super::{IncrementVisitor, InitializeVisitor, MANUAL_MEMCPY}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::sugg::Sugg; @@ -86,7 +86,7 @@ pub(super) fn check<'tcx>( span_lint_and_sugg( cx, MANUAL_MEMCPY, - get_span_of_entire_for_loop(expr), + expr.span, "it looks like you're manually copying between slices", "try replacing the loop by", big_sugg, diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index 5df1b7964016..fd4881b29474 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -23,7 +23,7 @@ use rustc_hir::{Expr, ExprKind, LoopSource, Pat}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; -use utils::{get_span_of_entire_for_loop, make_iterator_snippet, IncrementVisitor, InitializeVisitor}; +use utils::{make_iterator_snippet, IncrementVisitor, InitializeVisitor}; declare_clippy_lint! { /// ### What it does @@ -566,7 +566,15 @@ declare_lint_pass!(Loops => [ impl<'tcx> LateLintPass<'tcx> for Loops { #[allow(clippy::too_many_lines)] fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let Some(higher::ForLoop { pat, arg, body, span }) = higher::ForLoop::hir(expr) { + let for_loop = higher::ForLoop::hir(expr); + if let Some(higher::ForLoop { + pat, + arg, + body, + loop_id, + span, + }) = for_loop + { // we don't want to check expanded macros // this check is not at the top of the function // since higher::for_loop expressions are marked as expansions @@ -574,6 +582,9 @@ impl<'tcx> LateLintPass<'tcx> for Loops { return; } check_for_loop(cx, pat, arg, body, expr, span); + if let ExprKind::Block(block, _) = body.kind { + never_loop::check(cx, block, loop_id, span, for_loop.as_ref()); + } } // we don't want to check expanded macros @@ -582,7 +593,9 @@ impl<'tcx> LateLintPass<'tcx> for Loops { } // check for never_loop - never_loop::check(cx, expr); + if let ExprKind::Loop(block, ..) = expr.kind { + never_loop::check(cx, block, expr.hir_id, expr.span, None); + } // check for `loop { if let {} else break }` that could be `while let` // (also matches an explicit "match" instead of "if let") diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index c0fde5e51663..86b7d6d989ac 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -4,35 +4,41 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::higher::ForLoop; use clippy_utils::source::snippet; use rustc_errors::Applicability; -use rustc_hir::{Block, Expr, ExprKind, HirId, InlineAsmOperand, LoopSource, Node, Pat, Stmt, StmtKind}; +use rustc_hir::{Block, Expr, ExprKind, HirId, InlineAsmOperand, Pat, Stmt, StmtKind}; use rustc_lint::LateContext; +use rustc_span::Span; use std::iter::{once, Iterator}; -pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Loop(block, _, source, _) = expr.kind { - match never_loop_block(block, expr.hir_id) { - NeverLoopResult::AlwaysBreak => { - span_lint_and_then(cx, NEVER_LOOP, expr.span, "this loop never actually loops", |diag| { - if_chain! { - if source == LoopSource::ForLoop; - if let Some((_, Node::Expr(parent_match))) = cx.tcx.hir().parent_iter(expr.hir_id).nth(1); - if let Some(ForLoop { arg: iterator, pat, span: for_span, .. }) = ForLoop::hir(parent_match); - then { - // Suggests using an `if let` instead. This is `Unspecified` because the - // loop may (probably) contain `break` statements which would be invalid - // in an `if let`. - diag.span_suggestion_verbose( - for_span.with_hi(iterator.span.hi()), - "if you need the first element of the iterator, try writing", - for_to_if_let_sugg(cx, iterator, pat), - Applicability::Unspecified, - ); - } - }; - }); - }, - NeverLoopResult::MayContinueMainLoop | NeverLoopResult::Otherwise => (), - } +pub(super) fn check( + cx: &LateContext<'tcx>, + block: &'tcx Block<'_>, + loop_id: HirId, + span: Span, + for_loop: Option<&ForLoop<'_>>, +) { + match never_loop_block(block, loop_id) { + NeverLoopResult::AlwaysBreak => { + span_lint_and_then(cx, NEVER_LOOP, span, "this loop never actually loops", |diag| { + if let Some(ForLoop { + arg: iterator, + pat, + span: for_span, + .. + }) = for_loop + { + // Suggests using an `if let` instead. This is `Unspecified` because the + // loop may (probably) contain `break` statements which would be invalid + // in an `if let`. + diag.span_suggestion_verbose( + for_span.with_hi(iterator.span.hi()), + "if you need the first element of the iterator, try writing", + for_to_if_let_sugg(cx, iterator, pat), + Applicability::Unspecified, + ); + } + }); + }, + NeverLoopResult::MayContinueMainLoop | NeverLoopResult::Otherwise => (), } } diff --git a/clippy_lints/src/loops/single_element_loop.rs b/clippy_lints/src/loops/single_element_loop.rs index 0fd09ff7197a..e39605f3e7d6 100644 --- a/clippy_lints/src/loops/single_element_loop.rs +++ b/clippy_lints/src/loops/single_element_loop.rs @@ -1,4 +1,4 @@ -use super::{get_span_of_entire_for_loop, SINGLE_ELEMENT_LOOP}; +use super::SINGLE_ELEMENT_LOOP; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::single_segment_path; use clippy_utils::source::{indent_of, snippet}; @@ -30,7 +30,6 @@ pub(super) fn check<'tcx>( if !block.stmts.is_empty(); then { - let for_span = get_span_of_entire_for_loop(expr); let mut block_str = snippet(cx, block.span, "..").into_owned(); block_str.remove(0); block_str.pop(); @@ -39,7 +38,7 @@ pub(super) fn check<'tcx>( span_lint_and_sugg( cx, SINGLE_ELEMENT_LOOP, - for_span, + expr.span, "for loop over a single element", "try", format!("{{\n{}let {} = &{};{}}}", " ".repeat(indent_of(cx, block.stmts[0].span).unwrap_or(0)), target.name, list_item_name, block_str), diff --git a/clippy_lints/src/loops/utils.rs b/clippy_lints/src/loops/utils.rs index f9f515cc40a0..c3939a66c6ac 100644 --- a/clippy_lints/src/loops/utils.rs +++ b/clippy_lints/src/loops/utils.rs @@ -7,7 +7,6 @@ use rustc_hir::HirIdMap; use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, Mutability, Pat, PatKind, Stmt, StmtKind}; use rustc_lint::LateContext; use rustc_middle::hir::map::Map; -use rustc_span::source_map::Span; use rustc_span::symbol::{sym, Symbol}; use std::iter::Iterator; @@ -300,17 +299,6 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor { } } -// this function assumes the given expression is a `for` loop. -pub(super) fn get_span_of_entire_for_loop(expr: &Expr<'_>) -> Span { - // for some reason this is the only way to get the `Span` - // of the entire `for` loop - if let ExprKind::Match(_, arms, _) = &expr.kind { - arms[0].body.span - } else { - unreachable!() - } -} - /// If `arg` was the argument to a `for` loop, return the "cleanest" way of writing the /// actual `Iterator` that the loop uses. pub(super) fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic_ref: &mut Applicability) -> String { diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 0f32cd9164e2..78183add9cc7 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -20,8 +20,8 @@ use rustc_span::symbol::sym; use clippy_utils::consts::{constant, Constant}; use clippy_utils::sugg::Sugg; use clippy_utils::{ - expr_path_res, get_item_name, get_parent_expr, higher, in_constant, is_diag_trait_item, is_integer_const, - iter_input_pats, last_path_segment, match_any_def_paths, paths, unsext, SpanlessEq, + expr_path_res, get_item_name, get_parent_expr, in_constant, is_diag_trait_item, is_integer_const, iter_input_pats, + last_path_segment, match_any_def_paths, paths, unsext, SpanlessEq, }; declare_clippy_lint! { @@ -312,7 +312,6 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints { if let StmtKind::Local(local) = stmt.kind; if let PatKind::Binding(an, .., name, None) = local.pat.kind; if let Some(init) = local.init; - if !higher::is_from_for_desugar(local); if an == BindingAnnotation::Ref || an == BindingAnnotation::RefMut; then { // use the macro callsite when the init span (but not the whole local span) diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index fad647dfb266..b25a6e3375bb 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -1,5 +1,4 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::higher; use clippy_utils::source::snippet_with_macro_callsite; use rustc_errors::Applicability; use rustc_hir::{Stmt, StmtKind}; @@ -14,9 +13,6 @@ pub(super) fn check(cx: &LateContext<'_>, stmt: &Stmt<'_>) { if in_external_macro(cx.sess(), stmt.span) || local.pat.span.from_expansion() { return; } - if higher::is_from_for_desugar(local) { - return; - } span_lint_and_then( cx, LET_UNIT_VALUE, diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index 733cc97c8459..7297265d08cf 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -22,31 +22,31 @@ pub struct ForLoop<'tcx> { pub arg: &'tcx hir::Expr<'tcx>, /// `for` loop body pub body: &'tcx hir::Expr<'tcx>, + /// Compare this against `hir::Destination.target` + pub loop_id: HirId, /// entire `for` loop span pub span: Span, } impl<'tcx> ForLoop<'tcx> { - #[inline] /// Parses a desugared `for` loop pub fn hir(expr: &Expr<'tcx>) -> Option { if_chain! { - if let hir::ExprKind::Match(iterexpr, arms, hir::MatchSource::ForLoopDesugar) = expr.kind; - if let Some(first_arm) = arms.get(0); - if let hir::ExprKind::Call(_, iterargs) = iterexpr.kind; - if let Some(first_arg) = iterargs.get(0); - if iterargs.len() == 1 && arms.len() == 1 && first_arm.guard.is_none(); - if let hir::ExprKind::Loop(block, ..) = first_arm.body.kind; - if block.expr.is_none(); - if let [ _, _, ref let_stmt, ref body ] = *block.stmts; - if let hir::StmtKind::Local(local) = let_stmt.kind; - if let hir::StmtKind::Expr(body_expr) = body.kind; + if let hir::ExprKind::DropTemps(e) = expr.kind; + if let hir::ExprKind::Match(iterexpr, [arm], hir::MatchSource::ForLoopDesugar) = e.kind; + if let hir::ExprKind::Call(_, [arg]) = iterexpr.kind; + if let hir::ExprKind::Loop(block, ..) = arm.body.kind; + if let [stmt] = &*block.stmts; + if let hir::StmtKind::Expr(e) = stmt.kind; + if let hir::ExprKind::Match(_, [_, some_arm], _) = e.kind; + if let hir::PatKind::Struct(_, [field], _) = some_arm.pat.kind; then { return Some(Self { - pat: &*local.pat, - arg: first_arg, - body: body_expr, - span: first_arm.span + pat: field.pat, + arg, + body: some_arm.body, + loop_id: arm.body.hir_id, + span: expr.span.ctxt().outer_expn_data().call_site, }); } } @@ -678,38 +678,6 @@ impl<'tcx> FormatArgsArg<'tcx> { } } -/// Checks if a `let` statement is from a `for` loop desugaring. -pub fn is_from_for_desugar(local: &hir::Local<'_>) -> bool { - // This will detect plain for-loops without an actual variable binding: - // - // ``` - // for x in some_vec { - // // do stuff - // } - // ``` - if_chain! { - if let Some(expr) = local.init; - if let hir::ExprKind::Match(_, _, hir::MatchSource::ForLoopDesugar) = expr.kind; - then { - return true; - } - } - - // This detects a variable binding in for loop to avoid `let_unit_value` - // lint (see issue #1964). - // - // ``` - // for _ in vec![()] { - // // anything - // } - // ``` - if let hir::LocalSource::ForLoopDesugar = local.source { - return true; - } - - false -} - /// A parsed `panic!` expansion pub struct PanicExpn<'tcx> { /// Span of `panic!(..)` diff --git a/tests/ui/author/for_loop.stdout b/tests/ui/author/for_loop.stdout index f1b4d4e096ec..4d0e13c833fd 100644 --- a/tests/ui/author/for_loop.stdout +++ b/tests/ui/author/for_loop.stdout @@ -11,11 +11,8 @@ if_chain! { // unimplemented: field checks if arms.len() == 1; if let ExprKind::Loop(ref body, ref label, LoopSource::ForLoop) = arms[0].body.kind; - if body.stmts.len() == 4; - if let StmtKind::Local(ref local) = body.stmts[0].kind; - if let PatKind::Binding(BindingAnnotation::Mutable, _, name, None) = local.pat.kind; - if name.as_str() == "__next"; - if let StmtKind::Expr(ref e, _) = body.stmts[1].kind + if body.stmts.len() == 1; + if let StmtKind::Expr(ref e, _) = body.stmts[0].kind if let ExprKind::Match(ref expr2, ref arms1, MatchSource::ForLoopDesugar) = e.kind; if let ExprKind::Call(ref func1, ref args1) = expr2.kind; if let ExprKind::Path(ref path2) = func1.kind; @@ -25,39 +22,27 @@ if_chain! { if let ExprKind::Path(ref path3) = inner.kind; if match_qpath(path3, &["iter"]); if arms1.len() == 2; - if let ExprKind::Assign(ref target, ref value, ref _span) = arms1[0].body.kind; - if let ExprKind::Path(ref path4) = target.kind; - if match_qpath(path4, &["__next"]); - if let ExprKind::Path(ref path5) = value.kind; - if match_qpath(path5, &["val"]); - if let PatKind::Struct(ref path6, ref fields1, false) = arms1[0].pat.kind; - if matches!(path6, QPath::LangItem(LangItem::OptionSome, _)); - if fields1.len() == 1; - // unimplemented: field checks - if let ExprKind::Break(ref destination, None) = arms1[1].body.kind; - if let PatKind::Struct(ref path7, ref fields2, false) = arms1[1].pat.kind; - if matches!(path7, QPath::LangItem(LangItem::OptionNone, _)); - if fields2.len() == 0; + if let ExprKind::Break(ref destination, None) = arms1[0].body.kind; + if let PatKind::Struct(ref path4, ref fields1, false) = arms1[0].pat.kind; + if matches!(path4, QPath::LangItem(LangItem::OptionNone, _)); + if fields1.len() == 0; // unimplemented: field checks - if let StmtKind::Local(ref local1) = body.stmts[2].kind; - if let Some(ref init) = local1.init; - if let ExprKind::Path(ref path8) = init.kind; - if match_qpath(path8, &["__next"]); - if let PatKind::Binding(BindingAnnotation::Unannotated, _, name1, None) = local1.pat.kind; - if name1.as_str() == "y"; - if let StmtKind::Expr(ref e1, _) = body.stmts[3].kind - if let ExprKind::Block(ref block) = e1.kind; + if let ExprKind::Block(ref block) = arms1[1].body.kind; if block.stmts.len() == 1; - if let StmtKind::Local(ref local2) = block.stmts[0].kind; - if let Some(ref init1) = local2.init; - if let ExprKind::Path(ref path9) = init1.kind; - if match_qpath(path9, &["y"]); - if let PatKind::Binding(BindingAnnotation::Unannotated, _, name2, None) = local2.pat.kind; - if name2.as_str() == "z"; + if let StmtKind::Local(ref local) = block.stmts[0].kind; + if let Some(ref init) = local.init; + if let ExprKind::Path(ref path5) = init.kind; + if match_qpath(path5, &["y"]); + if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = local.pat.kind; + if name.as_str() == "z"; if block.expr.is_none(); + if let PatKind::Struct(ref path6, ref fields2, false) = arms1[1].pat.kind; + if matches!(path6, QPath::LangItem(LangItem::OptionSome, _)); + if fields2.len() == 1; + // unimplemented: field checks if body.expr.is_none(); - if let PatKind::Binding(BindingAnnotation::Mutable, _, name3, None) = arms[0].pat.kind; - if name3.as_str() == "iter"; + if let PatKind::Binding(BindingAnnotation::Mutable, _, name1, None) = arms[0].pat.kind; + if name1.as_str() == "iter"; then { // report your lint here } From 3725a1432c24b46b250e29cbd703a526a130da3f Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Fri, 19 Nov 2021 12:23:52 -0600 Subject: [PATCH 0357/1222] clippy: Fix pattern_type_mismatch for loop --- clippy_lints/src/pattern_type_mismatch.rs | 207 +++++----------------- 1 file changed, 43 insertions(+), 164 deletions(-) diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index e7bc24465908..018e6d611db7 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -1,16 +1,12 @@ use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::last_path_segment; use rustc_hir::{ - intravisit, Body, Expr, ExprKind, FnDecl, HirId, LocalSource, MatchSource, Mutability, Pat, PatField, PatKind, - QPath, Stmt, StmtKind, + intravisit, Body, Expr, ExprKind, FnDecl, HirId, LocalSource, Mutability, Pat, PatKind, Stmt, StmtKind, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::subst::SubstsRef; -use rustc_middle::ty::{AdtDef, FieldDef, Ty, TyKind, VariantDef}; +use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; -use std::iter; declare_clippy_lint! { /// ### What it does @@ -87,43 +83,28 @@ declare_lint_pass!(PatternTypeMismatch => [PATTERN_TYPE_MISMATCH]); impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { if let StmtKind::Local(local) = stmt.kind { - if let Some(init) = &local.init { - if let Some(init_ty) = cx.typeck_results().node_type_opt(init.hir_id) { - let pat = &local.pat; - if in_external_macro(cx.sess(), pat.span) { - return; - } - let deref_possible = match local.source { - LocalSource::Normal => DerefPossible::Possible, - _ => DerefPossible::Impossible, - }; - apply_lint(cx, pat, init_ty, deref_possible); - } + if in_external_macro(cx.sess(), local.pat.span) { + return; } + let deref_possible = match local.source { + LocalSource::Normal => DerefPossible::Possible, + _ => DerefPossible::Impossible, + }; + apply_lint(cx, local.pat, deref_possible); } } fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Match(scrutinee, arms, MatchSource::Normal) = expr.kind { - if let Some(expr_ty) = cx.typeck_results().node_type_opt(scrutinee.hir_id) { - 'pattern_checks: for arm in arms { - let pat = &arm.pat; - if in_external_macro(cx.sess(), pat.span) { - continue 'pattern_checks; - } - if apply_lint(cx, pat, expr_ty, DerefPossible::Possible) { - break 'pattern_checks; - } + if let ExprKind::Match(_, arms, _) = expr.kind { + for arm in arms { + let pat = &arm.pat; + if apply_lint(cx, pat, DerefPossible::Possible) { + break; } } } - if let ExprKind::Let(let_pat, let_expr, _) = expr.kind { - if let Some(expr_ty) = cx.typeck_results().node_type_opt(let_expr.hir_id) { - if in_external_macro(cx.sess(), let_pat.span) { - return; - } - apply_lint(cx, let_pat, expr_ty, DerefPossible::Possible); - } + if let ExprKind::Let(let_pat, ..) = expr.kind { + apply_lint(cx, let_pat, DerefPossible::Possible); } } @@ -134,12 +115,10 @@ impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch { _: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, _: Span, - hir_id: HirId, + _: HirId, ) { - if let Some(fn_sig) = cx.typeck_results().liberated_fn_sigs().get(hir_id) { - for (param, ty) in iter::zip(body.params, fn_sig.inputs()) { - apply_lint(cx, param.pat, ty, DerefPossible::Impossible); - } + for param in body.params { + apply_lint(cx, param.pat, DerefPossible::Impossible); } } } @@ -150,8 +129,8 @@ enum DerefPossible { Impossible, } -fn apply_lint<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'_>, expr_ty: Ty<'tcx>, deref_possible: DerefPossible) -> bool { - let maybe_mismatch = find_first_mismatch(cx, pat, expr_ty, Level::Top); +fn apply_lint<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'_>, deref_possible: DerefPossible) -> bool { + let maybe_mismatch = find_first_mismatch(cx, pat); if let Some((span, mutability, level)) = maybe_mismatch { span_lint_and_help( cx, @@ -184,132 +163,32 @@ enum Level { } #[allow(rustc::usage_of_ty_tykind)] -fn find_first_mismatch<'tcx>( - cx: &LateContext<'tcx>, - pat: &Pat<'_>, - ty: Ty<'tcx>, - level: Level, -) -> Option<(Span, Mutability, Level)> { - if let PatKind::Ref(sub_pat, _) = pat.kind { - if let TyKind::Ref(_, sub_ty, _) = ty.kind() { - return find_first_mismatch(cx, sub_pat, sub_ty, Level::Lower); - } - } - - if let TyKind::Ref(_, _, mutability) = *ty.kind() { - if is_non_ref_pattern(&pat.kind) { - return Some((pat.span, mutability, level)); - } - } - - if let PatKind::Struct(ref qpath, field_pats, _) = pat.kind { - if let TyKind::Adt(adt_def, substs_ref) = ty.kind() { - if let Some(variant) = get_variant(adt_def, qpath) { - let field_defs = &variant.fields; - return find_first_mismatch_in_struct(cx, field_pats, field_defs, substs_ref); - } +fn find_first_mismatch<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'_>) -> Option<(Span, Mutability, Level)> { + let mut result = None; + pat.walk(|p| { + if result.is_some() { + return false; } - } - - if let PatKind::TupleStruct(ref qpath, pats, _) = pat.kind { - if let TyKind::Adt(adt_def, substs_ref) = ty.kind() { - if let Some(variant) = get_variant(adt_def, qpath) { - let field_defs = &variant.fields; - let ty_iter = field_defs.iter().map(|field_def| field_def.ty(cx.tcx, substs_ref)); - return find_first_mismatch_in_tuple(cx, pats, ty_iter); - } - } - } - - if let PatKind::Tuple(pats, _) = pat.kind { - if let TyKind::Tuple(..) = ty.kind() { - return find_first_mismatch_in_tuple(cx, pats, ty.tuple_fields()); + if in_external_macro(cx.sess(), p.span) { + return true; } - } - - if let PatKind::Or(sub_pats) = pat.kind { - for pat in sub_pats { - let maybe_mismatch = find_first_mismatch(cx, pat, ty, level); - if let Some(mismatch) = maybe_mismatch { - return Some(mismatch); - } - } - } - - None -} - -fn get_variant<'a>(adt_def: &'a AdtDef, qpath: &QPath<'_>) -> Option<&'a VariantDef> { - if adt_def.is_struct() { - if let Some(variant) = adt_def.variants.iter().next() { - return Some(variant); - } - } - - if adt_def.is_enum() { - let pat_ident = last_path_segment(qpath).ident; - for variant in &adt_def.variants { - if variant.ident == pat_ident { - return Some(variant); - } - } - } - - None -} - -fn find_first_mismatch_in_tuple<'tcx, I>( - cx: &LateContext<'tcx>, - pats: &[Pat<'_>], - ty_iter_src: I, -) -> Option<(Span, Mutability, Level)> -where - I: IntoIterator>, -{ - let mut field_tys = ty_iter_src.into_iter(); - 'fields: for pat in pats { - let field_ty = if let Some(ty) = field_tys.next() { - ty - } else { - break 'fields; + let adjust_pat = match p.kind { + PatKind::Or([p, ..]) => p, + _ => p, }; - - let maybe_mismatch = find_first_mismatch(cx, pat, field_ty, Level::Lower); - if let Some(mismatch) = maybe_mismatch { - return Some(mismatch); - } - } - - None -} - -fn find_first_mismatch_in_struct<'tcx>( - cx: &LateContext<'tcx>, - field_pats: &[PatField<'_>], - field_defs: &[FieldDef], - substs_ref: SubstsRef<'tcx>, -) -> Option<(Span, Mutability, Level)> { - for field_pat in field_pats { - 'definitions: for field_def in field_defs { - if field_pat.ident == field_def.ident { - let field_ty = field_def.ty(cx.tcx, substs_ref); - let pat = &field_pat.pat; - let maybe_mismatch = find_first_mismatch(cx, pat, field_ty, Level::Lower); - if let Some(mismatch) = maybe_mismatch { - return Some(mismatch); + if let Some(adjustments) = cx.typeck_results().pat_adjustments().get(adjust_pat.hir_id) { + if let [first, ..] = **adjustments { + if let ty::Ref(.., mutability) = *first.kind() { + let level = if p.hir_id == pat.hir_id { + Level::Top + } else { + Level::Lower + }; + result = Some((p.span, mutability, level)); } - break 'definitions; } } - } - - None -} - -fn is_non_ref_pattern(pat_kind: &PatKind<'_>) -> bool { - match pat_kind { - PatKind::Struct(..) | PatKind::Tuple(..) | PatKind::TupleStruct(..) | PatKind::Path(..) => true, - PatKind::Or(sub_pats) => sub_pats.iter().any(|pat| is_non_ref_pattern(&pat.kind)), - _ => false, - } + result.is_none() + }); + result } From bf75f9e932d697032ef9b23a54690a94b3f02b37 Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Thu, 25 Nov 2021 18:39:32 +0000 Subject: [PATCH 0358/1222] Fix clippy test --- tests/ui/crashes/ice-6250.stderr | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/ui/crashes/ice-6250.stderr b/tests/ui/crashes/ice-6250.stderr index 439884b7d274..0d7713aa9a27 100644 --- a/tests/ui/crashes/ice-6250.stderr +++ b/tests/ui/crashes/ice-6250.stderr @@ -24,6 +24,9 @@ LL | | } error[E0308]: mismatched types --> $DIR/ice-6250.rs:12:14 | +LL | for reference in vec![1, 2, 3] { + | --------- expected due to the type of this binding +... LL | Some(reference) = cache.data.get(key) { | ^^^^^^^^^ expected integer, found `&i32` | From 8fdca3403fd11baeab38644d7ebbb20f0eb90879 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Wed, 24 Nov 2021 17:20:52 -0600 Subject: [PATCH 0359/1222] Visit `param_env` field in Obligation's `TypeFoldable` impl This oversight appears to have gone unnoticed for a long time without causing issues, but it should still be fixed. --- tests/ui/crashes/ice-6252.stderr | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index c8239897f3ab..abca7af30a00 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -21,16 +21,15 @@ LL | impl TypeVal for Multiply where N: TypeVal {} | | | help: you might be missing a type parameter: `, VAL` -error[E0046]: not all trait items implemented, missing: `VAL` - --> $DIR/ice-6252.rs:10:1 +error[E0283]: type annotations needed + --> $DIR/ice-6252.rs:10:12 | -LL | const VAL: T; - | ------------- `VAL` from trait -... LL | impl TypeVal for Multiply where N: TypeVal {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation + | ^^^^^^^^^^^^^^ cannot infer type for struct `Multiply` + | + = note: cannot satisfy `Multiply: TypeVal` error: aborting due to 3 previous errors -Some errors have detailed explanations: E0046, E0412. -For more information about an error, try `rustc --explain E0046`. +Some errors have detailed explanations: E0283, E0412. +For more information about an error, try `rustc --explain E0283`. From e46b9b0eab0753c272e85f3bd0604e2fa5ee4415 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Fri, 26 Nov 2021 09:14:16 -0600 Subject: [PATCH 0360/1222] Only check for errors in predicate when skipping impl assembly Prior to PR #91205, checking for errors in the overall obligation would check checking the `ParamEnv`, due to an incorrect `super_visit_with` impl. With this bug fixed, we will now bail out of impl candidate assembly if the `ParamEnv` contains any error types. In practice, this appears to be overly conservative - when an error occurs early in compilation, we end up giving up early for some predicates that we could have successfully evaluated without overflow. By only checking for errors in the predicate itself, we avoid causing additional spurious 'type annotations needed' errors after a 'real' error has already occurred. With this PR, the diagnostic changes caused by PR #91205 are reverted. --- tests/ui/crashes/ice-6252.stderr | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index abca7af30a00..c8239897f3ab 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -21,15 +21,16 @@ LL | impl TypeVal for Multiply where N: TypeVal {} | | | help: you might be missing a type parameter: `, VAL` -error[E0283]: type annotations needed - --> $DIR/ice-6252.rs:10:12 +error[E0046]: not all trait items implemented, missing: `VAL` + --> $DIR/ice-6252.rs:10:1 | +LL | const VAL: T; + | ------------- `VAL` from trait +... LL | impl TypeVal for Multiply where N: TypeVal {} - | ^^^^^^^^^^^^^^ cannot infer type for struct `Multiply` - | - = note: cannot satisfy `Multiply: TypeVal` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation error: aborting due to 3 previous errors -Some errors have detailed explanations: E0283, E0412. -For more information about an error, try `rustc --explain E0283`. +Some errors have detailed explanations: E0046, E0412. +For more information about an error, try `rustc --explain E0046`. From fcf743c10403dcff7e9b383f16440db4b2d14009 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 20 Oct 2021 22:38:10 +0200 Subject: [PATCH 0361/1222] Take a LocalDefId in expect_*item. --- clippy_lints/src/derive.rs | 8 +------- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/non_copy_const.rs | 4 ++-- clippy_lints/src/self_named_constructors.rs | 2 +- clippy_lints/src/unused_self.rs | 2 +- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 24ac5917dcb0..94b35ad88af2 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -3,7 +3,6 @@ use clippy_utils::paths; use clippy_utils::ty::{implements_trait, is_copy}; 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}; use rustc_hir::{ BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, HirId, Impl, Item, ItemKind, TraitRef, UnsafeSource, Unsafety, @@ -343,11 +342,6 @@ fn check_unsafe_derive_deserialize<'tcx>( trait_ref: &TraitRef<'_>, ty: Ty<'tcx>, ) { - fn item_from_def_id<'tcx>(cx: &LateContext<'tcx>, def_id: DefId) -> &'tcx Item<'tcx> { - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); - cx.tcx.hir().expect_item(hir_id) - } - fn has_unsafe<'tcx>(cx: &LateContext<'tcx>, item: &'tcx Item<'_>) -> bool { let mut visitor = UnsafeVisitor { cx, has_unsafe: false }; walk_item(&mut visitor, item); @@ -363,7 +357,7 @@ fn check_unsafe_derive_deserialize<'tcx>( 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)) + .map(|imp_did| cx.tcx.hir().expect_item(imp_did.expect_local())) .any(|imp| has_unsafe(cx, imp)); then { span_lint_and_help( diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 26c29fbb289c..e46739fea34b 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1939,7 +1939,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { return; } let name = impl_item.ident.name.as_str(); - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); + let parent = cx.tcx.hir().get_parent_did(impl_item.hir_id()); let item = cx.tcx.hir().expect_item(parent); let self_ty = cx.tcx.type_of(item.def_id); diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 2a85a67fa099..2ea97eb88f78 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -279,8 +279,8 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { if let ImplItemKind::Const(hir_ty, body_id) = &impl_item.kind { - let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id()); - let item = cx.tcx.hir().expect_item(item_hir_id); + let item_def_id = cx.tcx.hir().get_parent_did(impl_item.hir_id()); + let item = cx.tcx.hir().expect_item(item_def_id); match &item.kind { ItemKind::Impl(Impl { diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index 4ba5e1a0f535..9390378d789c 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { _ => return, } - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); + let parent = cx.tcx.hir().get_parent_did(impl_item.hir_id()); let item = cx.tcx.hir().expect_item(parent); let self_ty = cx.tcx.type_of(item.def_id); let ret_ty = return_ty(cx, impl_item.hir_id()); diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index e7e249c79a2f..c961f9956679 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -41,7 +41,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf { if impl_item.span.from_expansion() { return; } - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); + let parent = cx.tcx.hir().get_parent_did(impl_item.hir_id()); let parent_item = cx.tcx.hir().expect_item(parent); let assoc_item = cx.tcx.associated_item(impl_item.def_id); if_chain! { From 79ee82c1749fed6ed2442f8861086f1a8e2f811a Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Mon, 29 Nov 2021 20:42:16 +0800 Subject: [PATCH 0362/1222] Fix tools --- clippy_lints/src/future_not_send.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 6b2ac985555d..a9297adb426a 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -67,8 +67,8 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { let mut is_future = false; for &(p, _span) in preds { let p = p.subst(cx.tcx, subst); - if let Some(trait_ref) = p.to_opt_poly_trait_ref() { - if Some(trait_ref.value.def_id()) == cx.tcx.lang_items().future_trait() { + if let Some(trait_pred) = p.to_opt_poly_trait_pred() { + if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() { is_future = true; break; } From 45f9e8c284fe2a8f38e66cb1ed4547df3b00062e Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 3 Dec 2021 10:11:21 -0300 Subject: [PATCH 0363/1222] Revert "Auto merge of #91354 - fee1-dead:const_env, r=spastorino" This reverts commit 18bb8c61a975fff6424cda831ace5b0404277145, reversing changes made to d9baa361902b172be716f96619b909f340802dea. --- clippy_lints/src/future_not_send.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index a9297adb426a..6b2ac985555d 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -67,8 +67,8 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { let mut is_future = false; for &(p, _span) in preds { let p = p.subst(cx.tcx, subst); - if let Some(trait_pred) = p.to_opt_poly_trait_pred() { - if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() { + if let Some(trait_ref) = p.to_opt_poly_trait_ref() { + if Some(trait_ref.value.def_id()) == cx.tcx.lang_items().future_trait() { is_future = true; break; } From 0ea1f49baf8f3ef34285e5f5296f353f89d1933f Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Mon, 30 Aug 2021 01:23:33 +0100 Subject: [PATCH 0364/1222] Add initial AST and MIR support for unwinding from inline assembly --- clippy_lints/src/redundant_clone.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index f7711b6fe947..0eba6633ee19 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -15,7 +15,7 @@ use rustc_middle::mir::{ Mutability, }; use rustc_middle::ty::{self, fold::TypeVisitor, Ty, TyCtxt}; -use rustc_mir_dataflow::{Analysis, AnalysisDomain, GenKill, GenKillAnalysis, ResultsCursor}; +use rustc_mir_dataflow::{Analysis, AnalysisDomain, CallReturnPlaces, GenKill, GenKillAnalysis, ResultsCursor}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::{BytePos, Span}; use rustc_span::sym; @@ -499,11 +499,9 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeStorageLive { fn call_return_effect( &self, - _in_out: &mut impl GenKill, + _trans: &mut impl GenKill, _block: mir::BasicBlock, - _func: &mir::Operand<'tcx>, - _args: &[mir::Operand<'tcx>], - _return_place: mir::Place<'tcx>, + _return_places: CallReturnPlaces<'_, 'tcx>, ) { // Nothing to do when a call returns successfully } From d261655edd4278b3914e48f207f0ce9947ac8b82 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 3 Sep 2021 12:36:33 +0200 Subject: [PATCH 0365/1222] Use IntoIterator for array impl everywhere. --- clippy_lints/src/matches.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 7142df98c3f1..48e459e01659 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -13,7 +13,6 @@ use clippy_utils::{ remove_blocks, strip_pat_refs, }; use clippy_utils::{paths, search_same, SpanlessEq, SpanlessHash}; -use core::array; use core::iter::{once, ExactSizeIterator}; use if_chain::if_chain; use rustc_ast::ast::{Attribute, LitKind}; @@ -1306,7 +1305,7 @@ fn check_match_like_matches<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) return find_matches_sugg( cx, let_expr, - array::IntoIter::new([(&[][..], Some(let_pat), if_then, None), (&[][..], None, if_else, None)]), + IntoIterator::into_iter([(&[][..], Some(let_pat), if_then, None), (&[][..], None, if_else, None)]), expr, true, ); From dc6cfaa156e5c80e4af9c0fbaf326687a42e2d75 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 12 Dec 2021 12:34:46 +0800 Subject: [PATCH 0366/1222] Revert "Auto merge of #91491 - spastorino:revert-91354, r=oli-obk" This reverts commit ff2439b7b9bafcfdff86b7847128014699df8442, reversing changes made to 2a9e0831d6603d87220cedd1b1293e2eb82ef55c. --- clippy_lints/src/future_not_send.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index fefdcfed42f5..43911a313d5a 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -68,8 +68,8 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { let mut is_future = false; for &(p, _span) in preds { let p = p.subst(cx.tcx, subst); - if let Some(trait_ref) = p.to_opt_poly_trait_ref() { - if Some(trait_ref.value.def_id()) == cx.tcx.lang_items().future_trait() { + if let Some(trait_pred) = p.to_opt_poly_trait_pred() { + if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() { is_future = true; break; } From 539595d0b670c1fd2739e33e04166cd30e30ed01 Mon Sep 17 00:00:00 2001 From: Ellen Date: Sun, 12 Dec 2021 12:34:21 +0000 Subject: [PATCH 0367/1222] clippy owo --- tests/ui/trailing_empty_array.rs | 1 - tests/ui/trailing_empty_array.stderr | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/ui/trailing_empty_array.rs b/tests/ui/trailing_empty_array.rs index 501c9eb7651f..c39b0bcaf227 100644 --- a/tests/ui/trailing_empty_array.rs +++ b/tests/ui/trailing_empty_array.rs @@ -1,5 +1,4 @@ #![warn(clippy::trailing_empty_array)] -#![feature(const_generics_defaults)] // Do lint: diff --git a/tests/ui/trailing_empty_array.stderr b/tests/ui/trailing_empty_array.stderr index d88aa0504b53..9e2bd31d9fa5 100644 --- a/tests/ui/trailing_empty_array.stderr +++ b/tests/ui/trailing_empty_array.stderr @@ -1,5 +1,5 @@ error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:6:1 + --> $DIR/trailing_empty_array.rs:5:1 | LL | / struct RarelyUseful { LL | | field: i32, @@ -11,7 +11,7 @@ LL | | } = help: consider annotating `RarelyUseful` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:11:1 + --> $DIR/trailing_empty_array.rs:10:1 | LL | / struct OnlyField { LL | | first_and_last: [usize; 0], @@ -21,7 +21,7 @@ LL | | } = help: consider annotating `OnlyField` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:15:1 + --> $DIR/trailing_empty_array.rs:14:1 | LL | / struct GenericArrayType { LL | | field: i32, @@ -32,7 +32,7 @@ LL | | } = help: consider annotating `GenericArrayType` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:21:1 + --> $DIR/trailing_empty_array.rs:20:1 | LL | / struct OnlyAnotherAttribute { LL | | field: i32, @@ -43,7 +43,7 @@ LL | | } = help: consider annotating `OnlyAnotherAttribute` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:27:1 + --> $DIR/trailing_empty_array.rs:26:1 | LL | / struct OnlyADeriveAttribute { LL | | field: i32, @@ -54,7 +54,7 @@ LL | | } = help: consider annotating `OnlyADeriveAttribute` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:33:1 + --> $DIR/trailing_empty_array.rs:32:1 | LL | / struct ZeroSizedWithConst { LL | | field: i32, @@ -65,7 +65,7 @@ LL | | } = help: consider annotating `ZeroSizedWithConst` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:42:1 + --> $DIR/trailing_empty_array.rs:41:1 | LL | / struct ZeroSizedWithConstFunction { LL | | field: i32, @@ -76,7 +76,7 @@ LL | | } = help: consider annotating `ZeroSizedWithConstFunction` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:50:1 + --> $DIR/trailing_empty_array.rs:49:1 | LL | / struct ZeroSizedWithConstFunction2 { LL | | field: i32, @@ -87,7 +87,7 @@ LL | | } = help: consider annotating `ZeroSizedWithConstFunction2` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:55:1 + --> $DIR/trailing_empty_array.rs:54:1 | LL | struct ZeroSizedArrayWrapper([usize; 0]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -95,7 +95,7 @@ LL | struct ZeroSizedArrayWrapper([usize; 0]); = help: consider annotating `ZeroSizedArrayWrapper` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:57:1 + --> $DIR/trailing_empty_array.rs:56:1 | LL | struct TupleStruct(i32, [usize; 0]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -103,7 +103,7 @@ LL | struct TupleStruct(i32, [usize; 0]); = help: consider annotating `TupleStruct` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:59:1 + --> $DIR/trailing_empty_array.rs:58:1 | LL | / struct LotsOfFields { LL | | f1: u32, From 262bccb6284d868b5bcd9a3813e711e71cb2bed1 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Mon, 13 Dec 2021 00:00:51 +0000 Subject: [PATCH 0368/1222] Fix clippy tests --- tests/ui/asm_syntax.rs | 4 ++-- tests/ui/asm_syntax.stderr | 6 ++--- tests/ui/entry.fixed | 2 +- tests/ui/entry.rs | 2 +- tests/ui/missing-doc.rs | 3 ++- tests/ui/missing-doc.stderr | 48 ++++++++++++++++++------------------- 6 files changed, 33 insertions(+), 32 deletions(-) diff --git a/tests/ui/asm_syntax.rs b/tests/ui/asm_syntax.rs index 4a62f6f2909f..0220bf3331f5 100644 --- a/tests/ui/asm_syntax.rs +++ b/tests/ui/asm_syntax.rs @@ -1,11 +1,10 @@ // only-x86_64 // ignore-aarch64 -#![feature(asm)] - #[warn(clippy::inline_asm_x86_intel_syntax)] mod warn_intel { pub(super) unsafe fn use_asm() { + use std::arch::asm; asm!(""); asm!("", options()); asm!("", options(nostack)); @@ -17,6 +16,7 @@ mod warn_intel { #[warn(clippy::inline_asm_x86_att_syntax)] mod warn_att { pub(super) unsafe fn use_asm() { + use std::arch::asm; asm!(""); asm!("", options()); asm!("", options(nostack)); diff --git a/tests/ui/asm_syntax.stderr b/tests/ui/asm_syntax.stderr index 409f4db76bc2..e9b150121aa3 100644 --- a/tests/ui/asm_syntax.stderr +++ b/tests/ui/asm_syntax.stderr @@ -1,5 +1,5 @@ error: Intel x86 assembly syntax used - --> $DIR/asm_syntax.rs:9:9 + --> $DIR/asm_syntax.rs:8:9 | LL | asm!(""); | ^^^^^^^^ @@ -8,7 +8,7 @@ LL | asm!(""); = help: use AT&T x86 assembly syntax error: Intel x86 assembly syntax used - --> $DIR/asm_syntax.rs:10:9 + --> $DIR/asm_syntax.rs:9:9 | LL | asm!("", options()); | ^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | asm!("", options()); = help: use AT&T x86 assembly syntax error: Intel x86 assembly syntax used - --> $DIR/asm_syntax.rs:11:9 + --> $DIR/asm_syntax.rs:10:9 | LL | asm!("", options(nostack)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/entry.fixed b/tests/ui/entry.fixed index 8a36ec833d76..e43635abcd11 100644 --- a/tests/ui/entry.fixed +++ b/tests/ui/entry.fixed @@ -2,8 +2,8 @@ #![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)] #![warn(clippy::map_entry)] -#![feature(asm)] +use std::arch::asm; use std::collections::HashMap; use std::hash::Hash; diff --git a/tests/ui/entry.rs b/tests/ui/entry.rs index d972a201ad76..d999b3b7dc80 100644 --- a/tests/ui/entry.rs +++ b/tests/ui/entry.rs @@ -2,8 +2,8 @@ #![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)] #![warn(clippy::map_entry)] -#![feature(asm)] +use std::arch::asm; use std::collections::HashMap; use std::hash::Hash; diff --git a/tests/ui/missing-doc.rs b/tests/ui/missing-doc.rs index 148531c285d3..6e2e710e21c8 100644 --- a/tests/ui/missing-doc.rs +++ b/tests/ui/missing-doc.rs @@ -2,10 +2,11 @@ // When denying at the crate level, be sure to not get random warnings from the // injected intrinsics by the compiler. #![allow(dead_code)] -#![feature(global_asm)] //! Some garbage docs for the crate here #![doc = "More garbage"] +use std::arch::global_asm; + type Typedef = String; pub type PubTypedef = String; diff --git a/tests/ui/missing-doc.stderr b/tests/ui/missing-doc.stderr index 7a3a448c9d6c..a876dc078ebf 100644 --- a/tests/ui/missing-doc.stderr +++ b/tests/ui/missing-doc.stderr @@ -1,5 +1,5 @@ error: missing documentation for a type alias - --> $DIR/missing-doc.rs:9:1 + --> $DIR/missing-doc.rs:10:1 | LL | type Typedef = String; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -7,37 +7,37 @@ LL | type Typedef = String; = note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` error: missing documentation for a type alias - --> $DIR/missing-doc.rs:10:1 + --> $DIR/missing-doc.rs:11:1 | LL | pub type PubTypedef = String; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a module - --> $DIR/missing-doc.rs:12:1 + --> $DIR/missing-doc.rs:13:1 | LL | mod module_no_dox {} | ^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a module - --> $DIR/missing-doc.rs:13:1 + --> $DIR/missing-doc.rs:14:1 | LL | pub mod pub_module_no_dox {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing-doc.rs:17:1 + --> $DIR/missing-doc.rs:18:1 | LL | pub fn foo2() {} | ^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing-doc.rs:18:1 + --> $DIR/missing-doc.rs:19:1 | LL | fn foo3() {} | ^^^^^^^^^^^^ error: missing documentation for an enum - --> $DIR/missing-doc.rs:32:1 + --> $DIR/missing-doc.rs:33:1 | LL | / enum Baz { LL | | BazA { a: isize, b: isize }, @@ -46,31 +46,31 @@ LL | | } | |_^ error: missing documentation for a variant - --> $DIR/missing-doc.rs:33:5 + --> $DIR/missing-doc.rs:34:5 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a struct field - --> $DIR/missing-doc.rs:33:12 + --> $DIR/missing-doc.rs:34:12 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^ error: missing documentation for a struct field - --> $DIR/missing-doc.rs:33:22 + --> $DIR/missing-doc.rs:34:22 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^ error: missing documentation for a variant - --> $DIR/missing-doc.rs:34:5 + --> $DIR/missing-doc.rs:35:5 | LL | BarB, | ^^^^ error: missing documentation for an enum - --> $DIR/missing-doc.rs:37:1 + --> $DIR/missing-doc.rs:38:1 | LL | / pub enum PubBaz { LL | | PubBazA { a: isize }, @@ -78,43 +78,43 @@ LL | | } | |_^ error: missing documentation for a variant - --> $DIR/missing-doc.rs:38:5 + --> $DIR/missing-doc.rs:39:5 | LL | PubBazA { a: isize }, | ^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a struct field - --> $DIR/missing-doc.rs:38:15 + --> $DIR/missing-doc.rs:39:15 | LL | PubBazA { a: isize }, | ^^^^^^^^ error: missing documentation for a constant - --> $DIR/missing-doc.rs:58:1 + --> $DIR/missing-doc.rs:59:1 | LL | const FOO: u32 = 0; | ^^^^^^^^^^^^^^^^^^^ error: missing documentation for a constant - --> $DIR/missing-doc.rs:65:1 + --> $DIR/missing-doc.rs:66:1 | LL | pub const FOO4: u32 = 0; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a static - --> $DIR/missing-doc.rs:67:1 + --> $DIR/missing-doc.rs:68:1 | LL | static BAR: u32 = 0; | ^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a static - --> $DIR/missing-doc.rs:74:1 + --> $DIR/missing-doc.rs:75:1 | LL | pub static BAR4: u32 = 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a module - --> $DIR/missing-doc.rs:76:1 + --> $DIR/missing-doc.rs:77:1 | LL | / mod internal_impl { LL | | /// dox @@ -126,31 +126,31 @@ LL | | } | |_^ error: missing documentation for a function - --> $DIR/missing-doc.rs:79:5 + --> $DIR/missing-doc.rs:80:5 | LL | pub fn undocumented1() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing-doc.rs:80:5 + --> $DIR/missing-doc.rs:81:5 | LL | pub fn undocumented2() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing-doc.rs:81:5 + --> $DIR/missing-doc.rs:82:5 | LL | fn undocumented3() {} | ^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing-doc.rs:86:9 + --> $DIR/missing-doc.rs:87:9 | LL | pub fn also_undocumented1() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing-doc.rs:87:9 + --> $DIR/missing-doc.rs:88:9 | LL | fn also_undocumented2() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ From 9daf3f2dfa4904ac2402a4c7557fc92e167f9272 Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Wed, 13 Oct 2021 18:44:47 +1100 Subject: [PATCH 0369/1222] let-else: use hir::Let in clippy fix clippy format using `cargo fmt -p clippy_{lints,utils}` manually revert rustfmt line truncations rename to hir::Let in clippy Undo the shadowing of various `expr` variables after renaming `scrutinee` reduce destructuring of hir::Let to avoid `expr` collisions cargo fmt -p clippy_{lints,utils} bless new clippy::author output --- clippy_lints/src/equatable_if_let.rs | 16 ++++++++-------- clippy_lints/src/loops/never_loop.rs | 2 +- clippy_lints/src/manual_assert.rs | 2 +- clippy_lints/src/pattern_type_mismatch.rs | 6 +++--- clippy_lints/src/utils/author.rs | 17 ++++++++++++----- clippy_lints/src/utils/inspector.rs | 7 +++++-- clippy_utils/src/higher.rs | 14 ++++++++++++-- clippy_utils/src/hir_utils.rs | 13 +++++++++---- clippy_utils/src/lib.rs | 4 ++-- tests/ui/author/if.stdout | 6 +++--- 10 files changed, 56 insertions(+), 31 deletions(-) diff --git a/clippy_lints/src/equatable_if_let.rs b/clippy_lints/src/equatable_if_let.rs index 8905cc0de457..06d128f5527b 100644 --- a/clippy_lints/src/equatable_if_let.rs +++ b/clippy_lints/src/equatable_if_let.rs @@ -67,20 +67,20 @@ fn is_structural_partial_eq(cx: &LateContext<'tcx>, ty: Ty<'tcx>, other: Ty<'tcx impl<'tcx> LateLintPass<'tcx> for PatternEquality { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if_chain! { - if let ExprKind::Let(pat, exp, _) = expr.kind; - if unary_pattern(pat); - let exp_ty = cx.typeck_results().expr_ty(exp); - let pat_ty = cx.typeck_results().pat_ty(pat); + if let ExprKind::Let(let_expr) = expr.kind; + if unary_pattern(let_expr.pat); + let exp_ty = cx.typeck_results().expr_ty(let_expr.init); + let pat_ty = cx.typeck_results().pat_ty(let_expr.pat); if is_structural_partial_eq(cx, exp_ty, pat_ty); then { let mut applicability = Applicability::MachineApplicable; - let pat_str = match pat.kind { + let pat_str = match let_expr.pat.kind { PatKind::Struct(..) => format!( "({})", - snippet_with_context(cx, pat.span, expr.span.ctxt(), "..", &mut applicability).0, + snippet_with_context(cx, let_expr.pat.span, expr.span.ctxt(), "..", &mut applicability).0, ), - _ => snippet_with_context(cx, pat.span, expr.span.ctxt(), "..", &mut applicability).0.to_string(), + _ => snippet_with_context(cx, let_expr.pat.span, expr.span.ctxt(), "..", &mut applicability).0.to_string(), }; span_lint_and_sugg( cx, @@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for PatternEquality { "try", format!( "{} == {}", - snippet_with_context(cx, exp.span, expr.span.ctxt(), "..", &mut applicability).0, + snippet_with_context(cx, let_expr.init.span, expr.span.ctxt(), "..", &mut applicability).0, pat_str, ), applicability, diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index 86b7d6d989ac..2044af6be563 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -117,12 +117,12 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { | ExprKind::Unary(_, e) | ExprKind::Cast(e, _) | ExprKind::Type(e, _) - | ExprKind::Let(_, e, _) | ExprKind::Field(e, _) | ExprKind::AddrOf(_, _, e) | ExprKind::Struct(_, _, Some(e)) | ExprKind::Repeat(e, _) | ExprKind::DropTemps(e) => never_loop_expr(e, main_loop_id), + ExprKind::Let(let_expr) => never_loop_expr(let_expr.init, main_loop_id), ExprKind::Array(es) | ExprKind::MethodCall(_, _, es, _) | ExprKind::Tup(es) => { never_loop_expr_all(&mut es.iter(), main_loop_id) }, diff --git a/clippy_lints/src/manual_assert.rs b/clippy_lints/src/manual_assert.rs index ed3166086f7e..5a2a965716cc 100644 --- a/clippy_lints/src/manual_assert.rs +++ b/clippy_lints/src/manual_assert.rs @@ -50,7 +50,7 @@ impl LateLintPass<'_> for ManualAssert { .. } = &expr; if is_expn_of(stmt.span, "panic").is_some(); - if !matches!(cond.kind, ExprKind::Let(_, _, _)); + if !matches!(cond.kind, ExprKind::Let(_)); if let StmtKind::Semi(semi) = stmt.kind; if !cx.tcx.sess.source_map().is_multiline(cond.span); diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index c7d77d30927f..be319ee110d2 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir::{ - intravisit, Body, Expr, ExprKind, FnDecl, HirId, LocalSource, Mutability, Pat, PatKind, Stmt, StmtKind, + intravisit, Body, Expr, ExprKind, FnDecl, HirId, Let, LocalSource, Mutability, Pat, PatKind, Stmt, StmtKind, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; @@ -104,8 +104,8 @@ impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch { } } } - if let ExprKind::Let(let_pat, ..) = expr.kind { - apply_lint(cx, let_pat, DerefPossible::Possible); + if let ExprKind::Let(Let { pat, .. }) = expr.kind { + apply_lint(cx, pat, DerefPossible::Possible); } } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index d20bf3413185..e105eece3d51 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -373,11 +373,18 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { } match expr.value.kind { - ExprKind::Let(pat, expr, _) => { - bind!(self, pat, expr); - kind!("Let({pat}, {expr}, _)"); - self.pat(pat); - self.expr(expr); + ExprKind::Let(let_expr) => { + bind!(self, let_expr); + kind!("Let({let_expr})"); + self.pat(field!(let_expr.pat)); + // Does what ExprKind::Cast does, only adds a clause for the type + // if it's a path + if let Some(TyKind::Path(ref qpath)) = let_expr.value.ty.as_ref().map(|ty| &ty.kind) { + bind!(self, qpath); + out!("if let TyKind::Path(ref {qpath}) = {let_expr}.ty.kind;"); + self.qpath(qpath); + } + self.expr(field!(let_expr.init)); }, ExprKind::Box(inner) => { bind!(self, inner); diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 43590cc78623..abf4826a0691 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -142,9 +142,12 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { print_expr(cx, arg, indent + 1); } }, - hir::ExprKind::Let(pat, expr, _) => { + hir::ExprKind::Let(hir::Let { pat, init, ty, .. }) => { print_pat(cx, pat, indent + 1); - print_expr(cx, expr, indent + 1); + if let Some(ty) = ty { + println!("{} type annotation: {:?}", ind, ty); + } + print_expr(cx, init, indent + 1); }, hir::ExprKind::MethodCall(path, _, args, _) => { println!("{}MethodCall", ind); diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index 7297265d08cf..3f11dd801f9d 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -101,7 +101,12 @@ impl<'hir> IfLet<'hir> { pub fn hir(cx: &LateContext<'_>, expr: &Expr<'hir>) -> Option { if let ExprKind::If( Expr { - kind: ExprKind::Let(let_pat, let_expr, _), + kind: + ExprKind::Let(hir::Let { + pat: let_pat, + init: let_expr, + .. + }), .. }, if_then, @@ -368,7 +373,12 @@ impl<'hir> WhileLet<'hir> { kind: ExprKind::If( Expr { - kind: ExprKind::Let(let_pat, let_expr, _), + kind: + ExprKind::Let(hir::Let { + pat: let_pat, + init: let_expr, + .. + }), .. }, if_then, diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 7438b6eabf9e..5f5d878597e6 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -7,7 +7,7 @@ use rustc_hir::def::Res; use rustc_hir::HirIdMap; use rustc_hir::{ BinOpKind, Block, BodyId, Expr, ExprField, ExprKind, FnRetTy, GenericArg, GenericArgs, Guard, HirId, - InlineAsmOperand, Lifetime, LifetimeName, ParamName, Pat, PatField, PatKind, Path, PathSegment, QPath, Stmt, + InlineAsmOperand, Let, Lifetime, LifetimeName, ParamName, Pat, PatField, PatKind, Path, PathSegment, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding, }; use rustc_lexer::{tokenize, TokenKind}; @@ -232,7 +232,9 @@ impl HirEqInterExpr<'_, '_, '_> { (&ExprKind::If(lc, lt, ref le), &ExprKind::If(rc, rt, ref re)) => { self.eq_expr(lc, rc) && self.eq_expr(&**lt, &**rt) && both(le, re, |l, r| self.eq_expr(l, r)) }, - (&ExprKind::Let(lp, le, _), &ExprKind::Let(rp, re, _)) => self.eq_pat(lp, rp) && self.eq_expr(le, re), + (&ExprKind::Let(l), &ExprKind::Let(r)) => { + self.eq_pat(l.pat, r.pat) && both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r)) && self.eq_expr(l.init, r.init) + }, (&ExprKind::Lit(ref l), &ExprKind::Lit(ref r)) => l.node == r.node, (&ExprKind::Loop(lb, ref ll, ref lls, _), &ExprKind::Loop(rb, ref rl, ref rls, _)) => { lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.name == r.ident.name) @@ -666,8 +668,11 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } }, - ExprKind::Let(pat, expr, _) => { - self.hash_expr(expr); + ExprKind::Let(Let { pat, init, ty, .. }) => { + self.hash_expr(init); + if let Some(ty) = ty { + self.hash_ty(ty); + } self.hash_pat(pat); }, ExprKind::LlvmInlineAsm(..) | ExprKind::Err => {}, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index f011380c127a..32d9a9a42ed3 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -871,8 +871,8 @@ pub fn capture_local_usage(cx: &LateContext<'tcx>, e: &Expr<'_>) -> CaptureKind capture_expr_ty = e; } }, - ExprKind::Let(pat, ..) => { - let mutability = match pat_capture_kind(cx, pat) { + ExprKind::Let(let_expr) => { + let mutability = match pat_capture_kind(cx, let_expr.pat) { CaptureKind::Value => Mutability::Not, CaptureKind::Ref(m) => m, }; diff --git a/tests/ui/author/if.stdout b/tests/ui/author/if.stdout index 75ff3faf29ae..8d92849b3668 100644 --- a/tests/ui/author/if.stdout +++ b/tests/ui/author/if.stdout @@ -32,11 +32,11 @@ if_chain! { } if_chain! { if let ExprKind::If(cond, then, Some(else_expr)) = expr.kind; - if let ExprKind::Let(pat, expr1, _) = cond.kind; - if let PatKind::Lit(lit_expr) = pat.kind; + if let ExprKind::Let(let_expr) = cond.kind; + if let PatKind::Lit(lit_expr) = let_expr.pat.kind; if let ExprKind::Lit(ref lit) = lit_expr.kind; if let LitKind::Bool(true) = lit.node; - if let ExprKind::Path(ref qpath) = expr1.kind; + if let ExprKind::Path(ref qpath) = let_expr.init.kind; if match_qpath(qpath, &["a"]); if let ExprKind::Block(block, None) = then.kind; if block.stmts.is_empty(); From 3869544bb04bd993d227d275d84793efc9b3b74e Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Tue, 16 Nov 2021 20:44:25 +0000 Subject: [PATCH 0370/1222] Fix clippy uses of QPath::LangItem --- clippy_lints/src/methods/str_splitn.rs | 2 +- clippy_lints/src/needless_question_mark.rs | 2 +- clippy_lints/src/strings.rs | 2 +- clippy_lints/src/try_err.rs | 2 +- clippy_lints/src/unused_io_amount.rs | 2 +- clippy_lints/src/utils/author.rs | 2 +- clippy_utils/src/higher.rs | 12 ++++++------ clippy_utils/src/hir_utils.rs | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 2595f734f115..e5fafdb075c6 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -204,7 +204,7 @@ fn parse_iter_usage( match e.kind { ExprKind::Call( Expr { - kind: ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, _)), + kind: ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, ..)), .. }, _, diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index 1ffed6a05249..0e7ae43ce2dd 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -105,7 +105,7 @@ fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { }; if let ExprKind::Match(inner_expr_with_q, _, MatchSource::TryDesugar) = &arg.kind; if let ExprKind::Call(called, [inner_expr]) = &inner_expr_with_q.kind; - if let ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, _)) = &called.kind; + if let ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, ..)) = &called.kind; if expr.span.ctxt() == inner_expr.span.ctxt(); let expr_ty = cx.typeck_results().expr_ty(expr); let inner_ty = cx.typeck_results().expr_ty(inner_expr); diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 368274440d5d..c2163a24b7f4 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -260,7 +260,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { if method_names[0] == sym!(as_bytes); // Check for slicer - if let ExprKind::Struct(QPath::LangItem(LangItem::Range, _), _, _) = right.kind; + if let ExprKind::Struct(QPath::LangItem(LangItem::Range, ..), _, _) = right.kind; then { let mut applicability = Applicability::MachineApplicable; diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs index e0e7ec9a452c..4da32c52e750 100644 --- a/clippy_lints/src/try_err.rs +++ b/clippy_lints/src/try_err.rs @@ -65,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for TryErr { if let ExprKind::Match(match_arg, _, MatchSource::TryDesugar) = expr.kind; if let ExprKind::Call(match_fun, try_args) = match_arg.kind; if let ExprKind::Path(ref match_fun_path) = match_fun.kind; - if matches!(match_fun_path, QPath::LangItem(LangItem::TryTraitBranch, _)); + if matches!(match_fun_path, QPath::LangItem(LangItem::TryTraitBranch, ..)); if let Some(try_arg) = try_args.get(0); if let ExprKind::Call(err_fun, err_args) = try_arg.kind; if let Some(err_arg) = err_args.get(0); diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index d4b5c9770a27..111413e51930 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount { if let hir::ExprKind::Call(func, [ref arg_0, ..]) = res.kind { if matches!( func.kind, - hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::TryTraitBranch, _)) + hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::TryTraitBranch, ..)) ) { check_map_error(cx, arg_0, expr); } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index d20bf3413185..f186e1f05a0b 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -260,7 +260,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { } fn qpath(&self, qpath: &Binding<&QPath<'_>>) { - if let QPath::LangItem(lang_item, _) = *qpath.value { + if let QPath::LangItem(lang_item, ..) = *qpath.value { out!("if matches!({qpath}, QPath::LangItem(LangItem::{lang_item:?}, _));"); } else { out!("if match_qpath({qpath}, &[{}]);", path_to_string(qpath.value)); diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index 7297265d08cf..fc32e49420e4 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -218,7 +218,7 @@ impl<'a> Range<'a> { hir::ExprKind::Call(path, args) if matches!( path.kind, - hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::RangeInclusiveNew, _)) + hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::RangeInclusiveNew, ..)) ) => { Some(Range { @@ -228,27 +228,27 @@ impl<'a> Range<'a> { }) }, hir::ExprKind::Struct(path, fields, None) => match &path { - hir::QPath::LangItem(hir::LangItem::RangeFull, _) => Some(Range { + hir::QPath::LangItem(hir::LangItem::RangeFull, ..) => Some(Range { start: None, end: None, limits: ast::RangeLimits::HalfOpen, }), - hir::QPath::LangItem(hir::LangItem::RangeFrom, _) => Some(Range { + hir::QPath::LangItem(hir::LangItem::RangeFrom, ..) => Some(Range { start: Some(get_field("start", fields)?), end: None, limits: ast::RangeLimits::HalfOpen, }), - hir::QPath::LangItem(hir::LangItem::Range, _) => Some(Range { + hir::QPath::LangItem(hir::LangItem::Range, ..) => Some(Range { start: Some(get_field("start", fields)?), end: Some(get_field("end", fields)?), limits: ast::RangeLimits::HalfOpen, }), - hir::QPath::LangItem(hir::LangItem::RangeToInclusive, _) => Some(Range { + hir::QPath::LangItem(hir::LangItem::RangeToInclusive, ..) => Some(Range { start: None, end: Some(get_field("end", fields)?), limits: ast::RangeLimits::Closed, }), - hir::QPath::LangItem(hir::LangItem::RangeTo, _) => Some(Range { + hir::QPath::LangItem(hir::LangItem::RangeTo, ..) => Some(Range { start: None, end: Some(get_field("end", fields)?), limits: ast::RangeLimits::HalfOpen, diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 7438b6eabf9e..5b059e378869 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -346,7 +346,7 @@ impl HirEqInterExpr<'_, '_, '_> { (&QPath::TypeRelative(lty, lseg), &QPath::TypeRelative(rty, rseg)) => { self.eq_ty(lty, rty) && self.eq_path_segment(lseg, rseg) }, - (&QPath::LangItem(llang_item, _), &QPath::LangItem(rlang_item, _)) => llang_item == rlang_item, + (&QPath::LangItem(llang_item, ..), &QPath::LangItem(rlang_item, ..)) => llang_item == rlang_item, _ => false, } } From 02dc46967b8e268a015736c4ef8a0e78e8fbac83 Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Tue, 16 Nov 2021 22:06:25 +0000 Subject: [PATCH 0371/1222] Fix rebase and clippy tests --- clippy_lints/src/needless_late_init.rs | 11 +++++-- tests/ui/needless_late_init_fixable.fixed | 38 ---------------------- tests/ui/needless_late_init_fixable.rs | 2 -- tests/ui/needless_late_init_fixable.stderr | 26 ++++++++------- 4 files changed, 22 insertions(+), 55 deletions(-) delete mode 100644 tests/ui/needless_late_init_fixable.fixed diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs index e0522f3fe0b1..5b098659377c 100644 --- a/clippy_lints/src/needless_late_init.rs +++ b/clippy_lints/src/needless_late_init.rs @@ -73,7 +73,7 @@ fn contains_assign_expr<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'tcx>) -> seen } -#[derive(Debug)] +#[derive(Debug, Clone)] struct LocalAssign { lhs_id: HirId, lhs_span: Span, @@ -154,9 +154,14 @@ fn assignment_suggestions<'tcx>( assignments.push(assign); } - let suggestions = assignments + let suggestions = assignments.clone() .into_iter() - .map(|assignment| Some((assignment.span, snippet_opt(cx, assignment.rhs_span)?))) + .map(|assignment| Some((assignment.span.until(assignment.rhs_span), String::new()))) + .chain( + assignments + .into_iter() + .map(|assignment| Some((assignment.rhs_span.shrink_to_hi().with_hi(assignment.span.hi()), String::new()))) + ) .collect::>>()?; let applicability = if suggestions.len() > 1 { diff --git a/tests/ui/needless_late_init_fixable.fixed b/tests/ui/needless_late_init_fixable.fixed deleted file mode 100644 index 32d5d04fde4d..000000000000 --- a/tests/ui/needless_late_init_fixable.fixed +++ /dev/null @@ -1,38 +0,0 @@ -// run-rustfix - -#![allow(unused, clippy::assign_op_pattern)] - -fn main() { - - let a = "zero"; - - - - let b = 1; - let c = 2; - - - let d: usize = 1; - - - let mut e = 1; - e = 2; - - - let f = match 1 { - 1 => "three", - _ => return, - }; // has semi - - - let g: usize = if true { - 5 - } else { - panic!(); - }; - - - let h = format!("{}", e); - - println!("{}", a); -} diff --git a/tests/ui/needless_late_init_fixable.rs b/tests/ui/needless_late_init_fixable.rs index 6bc85f686325..76099df0e068 100644 --- a/tests/ui/needless_late_init_fixable.rs +++ b/tests/ui/needless_late_init_fixable.rs @@ -1,5 +1,3 @@ -// run-rustfix - #![allow(unused, clippy::assign_op_pattern)] fn main() { diff --git a/tests/ui/needless_late_init_fixable.stderr b/tests/ui/needless_late_init_fixable.stderr index a0ce4f812f4e..728e19252ea7 100644 --- a/tests/ui/needless_late_init_fixable.stderr +++ b/tests/ui/needless_late_init_fixable.stderr @@ -1,5 +1,5 @@ error: unneeded late initalization - --> $DIR/needless_late_init_fixable.rs:6:5 + --> $DIR/needless_late_init_fixable.rs:4:5 | LL | let a; | ^^^^^^ @@ -11,7 +11,7 @@ LL | let a = "zero"; | ~~~~~ error: unneeded late initalization - --> $DIR/needless_late_init_fixable.rs:9:5 + --> $DIR/needless_late_init_fixable.rs:7:5 | LL | let b; | ^^^^^^ @@ -22,7 +22,7 @@ LL | let b = 1; | ~~~~~ error: unneeded late initalization - --> $DIR/needless_late_init_fixable.rs:10:5 + --> $DIR/needless_late_init_fixable.rs:8:5 | LL | let c; | ^^^^^^ @@ -33,7 +33,7 @@ LL | let c = 2; | ~~~~~ error: unneeded late initalization - --> $DIR/needless_late_init_fixable.rs:14:5 + --> $DIR/needless_late_init_fixable.rs:12:5 | LL | let d: usize; | ^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | let d: usize = 1; | ~~~~~~~~~~~~ error: unneeded late initalization - --> $DIR/needless_late_init_fixable.rs:17:5 + --> $DIR/needless_late_init_fixable.rs:15:5 | LL | let mut e; | ^^^^^^^^^^ @@ -55,7 +55,7 @@ LL | let mut e = 1; | ~~~~~~~~~ error: unneeded late initalization - --> $DIR/needless_late_init_fixable.rs:21:5 + --> $DIR/needless_late_init_fixable.rs:19:5 | LL | let f; | ^^^^^^ @@ -66,11 +66,12 @@ LL | let f = match 1 { | +++++++ help: remove the assignments from the `match` arms | -LL | 1 => "three", - | ~~~~~~~ +LL - 1 => f = "three", +LL + 1 => "three", + | error: unneeded late initalization - --> $DIR/needless_late_init_fixable.rs:27:5 + --> $DIR/needless_late_init_fixable.rs:25:5 | LL | let g: usize; | ^^^^^^^^^^^^^ @@ -81,15 +82,16 @@ LL | let g: usize = if true { | ++++++++++++++ help: remove the assignments from the branches | -LL | 5 - | +LL - g = 5; +LL + 5 + | help: add a semicolon after the `if` expression | LL | }; | + error: unneeded late initalization - --> $DIR/needless_late_init_fixable.rs:34:5 + --> $DIR/needless_late_init_fixable.rs:32:5 | LL | let h; | ^^^^^^ From bd4c8ec7cff9f84dd923a44f86f627edba03e53c Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Fri, 10 Dec 2021 17:20:57 +0000 Subject: [PATCH 0372/1222] fix clippy tests --- tests/ui/future_not_send.stderr | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/ui/future_not_send.stderr b/tests/ui/future_not_send.stderr index 3cc05e2fdbec..a9f2ad36d0ab 100644 --- a/tests/ui/future_not_send.stderr +++ b/tests/ui/future_not_send.stderr @@ -6,22 +6,22 @@ LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { | = note: `-D clippy::future-not-send` implied by `-D warnings` note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:8:5 + --> $DIR/future_not_send.rs:8:19 | LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { | -- has type `std::rc::Rc<[u8]>` which is not `Send` LL | async { true }.await - | ^^^^^^^^^^^^^^^^^^^^ await occurs here, with `rc` maybe used later + | ^^^^^^ await occurs here, with `rc` maybe used later LL | } | - `rc` is later dropped here = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:8:5 + --> $DIR/future_not_send.rs:8:19 | LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { | ---- has type `&std::cell::Cell` which is not `Send` LL | async { true }.await - | ^^^^^^^^^^^^^^^^^^^^ await occurs here, with `cell` maybe used later + | ^^^^^^ await occurs here, with `cell` maybe used later LL | } | - `cell` is later dropped here = note: `std::cell::Cell` doesn't implement `std::marker::Sync` @@ -33,12 +33,12 @@ LL | pub async fn public_future(rc: Rc<[u8]>) { | ^ future returned by `public_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:12:5 + --> $DIR/future_not_send.rs:12:19 | LL | pub async fn public_future(rc: Rc<[u8]>) { | -- has type `std::rc::Rc<[u8]>` which is not `Send` LL | async { true }.await; - | ^^^^^^^^^^^^^^^^^^^^ await occurs here, with `rc` maybe used later + | ^^^^^^ await occurs here, with `rc` maybe used later LL | } | - `rc` is later dropped here = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` @@ -82,12 +82,12 @@ LL | async fn private_future(&self) -> usize { | ^^^^^ future returned by `private_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:35:9 + --> $DIR/future_not_send.rs:35:23 | LL | async fn private_future(&self) -> usize { | ----- has type `&Dummy` which is not `Send` LL | async { true }.await; - | ^^^^^^^^^^^^^^^^^^^^ await occurs here, with `&self` maybe used later + | ^^^^^^ await occurs here, with `&self` maybe used later LL | self.rc.len() LL | } | - `&self` is later dropped here @@ -100,12 +100,12 @@ LL | pub async fn public_future(&self) { | ^ future returned by `public_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:40:9 + --> $DIR/future_not_send.rs:40:30 | LL | pub async fn public_future(&self) { | ----- has type `&Dummy` which is not `Send` LL | self.private_future().await; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ await occurs here, with `&self` maybe used later + | ^^^^^^ await occurs here, with `&self` maybe used later LL | } | - `&self` is later dropped here = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` @@ -117,12 +117,12 @@ LL | async fn generic_future(t: T) -> T | ^ future returned by `generic_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:54:5 + --> $DIR/future_not_send.rs:54:19 | LL | let rt = &t; | -- has type `&T` which is not `Send` LL | async { true }.await; - | ^^^^^^^^^^^^^^^^^^^^ await occurs here, with `rt` maybe used later + | ^^^^^^ await occurs here, with `rt` maybe used later LL | t LL | } | - `rt` is later dropped here From 59882c9ca9335ed10e4270fe374df94a0f9e5b00 Mon Sep 17 00:00:00 2001 From: PFPoitras Date: Tue, 14 Dec 2021 18:10:57 -0400 Subject: [PATCH 0373/1222] Remove iter::zip feature gate from clippy --- clippy_lints/src/lib.rs | 1 - clippy_utils/src/lib.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index bd9710ec4075..77b7fee63892 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -3,7 +3,6 @@ #![feature(box_patterns)] #![feature(drain_filter)] #![feature(in_band_lifetimes)] -#![feature(iter_zip)] #![feature(once_cell)] #![feature(rustc_private)] #![feature(stmt_expr_attributes)] diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index f011380c127a..8413b8c8280a 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1,6 +1,5 @@ #![feature(box_patterns)] #![feature(in_band_lifetimes)] -#![feature(iter_zip)] #![feature(let_else)] #![feature(rustc_private)] #![feature(control_flow_enum)] From fc55e3b63fcb60d534a77564e0f5d62cef9d874b Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 15 Dec 2021 08:32:21 +1100 Subject: [PATCH 0374/1222] Remove `SymbolStr`. By changing `as_str()` to take `&self` instead of `self`, we can just return `&str`. We're still lying about lifetimes, but it's a smaller lie than before, where `SymbolStr` contained a (fake) `&'static str`! --- clippy_lints/src/attrs.rs | 12 ++++++------ clippy_lints/src/match_str_case_mismatch.rs | 10 +++++----- clippy_lints/src/methods/mod.rs | 10 +++++----- clippy_lints/src/misc.rs | 4 +++- clippy_lints/src/multiple_crate_versions.rs | 4 ++-- clippy_utils/src/consts.rs | 4 ++-- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 1edb7c950e7b..06a99ff5418f 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -17,7 +17,7 @@ use rustc_semver::RustcVersion; use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; use rustc_span::sym; -use rustc_span::symbol::{Symbol, SymbolStr}; +use rustc_span::symbol::Symbol; use semver::Version; static UNIX_SYSTEMS: &[&str] = &[ @@ -310,8 +310,8 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { || is_word(lint, sym::deprecated) || is_word(lint, sym!(unreachable_pub)) || is_word(lint, sym!(unused)) - || extract_clippy_lint(lint).map_or(false, |s| s == "wildcard_imports") - || extract_clippy_lint(lint).map_or(false, |s| s == "enum_glob_use") + || extract_clippy_lint(lint).map_or(false, |s| s.as_str() == "wildcard_imports") + || extract_clippy_lint(lint).map_or(false, |s| s.as_str() == "enum_glob_use") { return; } @@ -370,7 +370,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { } /// Returns the lint name if it is clippy lint. -fn extract_clippy_lint(lint: &NestedMetaItem) -> Option { +fn extract_clippy_lint(lint: &NestedMetaItem) -> Option { if_chain! { if let Some(meta_item) = lint.meta_item(); if meta_item.path.segments.len() > 1; @@ -378,7 +378,7 @@ fn extract_clippy_lint(lint: &NestedMetaItem) -> Option { if tool_name.name == sym::clippy; then { let lint_name = meta_item.path.segments.last().unwrap().ident.name; - return Some(lint_name.as_str()); + return Some(lint_name); } } None @@ -387,7 +387,7 @@ fn extract_clippy_lint(lint: &NestedMetaItem) -> Option { fn check_clippy_lint_names(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem]) { for lint in items { if let Some(lint_name) = extract_clippy_lint(lint) { - if lint_name == "restriction" && name != sym::allow { + if lint_name.as_str() == "restriction" && name != sym::allow { span_lint_and_help( cx, BLANKET_CLIPPY_RESTRICTION_LINTS, diff --git a/clippy_lints/src/match_str_case_mismatch.rs b/clippy_lints/src/match_str_case_mismatch.rs index 3316ebf40510..241283851899 100644 --- a/clippy_lints/src/match_str_case_mismatch.rs +++ b/clippy_lints/src/match_str_case_mismatch.rs @@ -9,7 +9,7 @@ use rustc_middle::hir::map::Map; use rustc_middle::lint::in_external_macro; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::symbol::SymbolStr; +use rustc_span::symbol::Symbol; use rustc_span::{sym, Span}; declare_clippy_lint! { @@ -71,8 +71,8 @@ impl LateLintPass<'_> for MatchStrCaseMismatch { visitor.visit_expr(match_expr); if let Some(case_method) = visitor.case_method { - if let Some((bad_case_span, bad_case_str)) = verify_case(&case_method, arms) { - lint(cx, &case_method, bad_case_span, &bad_case_str); + if let Some((bad_case_span, bad_case_sym)) = verify_case(&case_method, arms) { + lint(cx, &case_method, bad_case_span, bad_case_sym.as_str()); } } } @@ -126,7 +126,7 @@ fn get_case_method(segment_ident_str: &str) -> Option { } } -fn verify_case<'a>(case_method: &'a CaseMethod, arms: &'a [Arm<'_>]) -> Option<(Span, SymbolStr)> { +fn verify_case<'a>(case_method: &'a CaseMethod, arms: &'a [Arm<'_>]) -> Option<(Span, Symbol)> { let case_check = match case_method { CaseMethod::LowerCase => |input: &str| -> bool { input.chars().all(|c| c.to_lowercase().next() == Some(c)) }, CaseMethod::AsciiLowerCase => |input: &str| -> bool { !input.chars().any(|c| c.is_ascii_uppercase()) }, @@ -144,7 +144,7 @@ fn verify_case<'a>(case_method: &'a CaseMethod, arms: &'a [Arm<'_>]) -> Option<( let input = symbol.as_str(); if !case_check(&input); then { - return Some((lit.span, input)); + return Some((lit.span, symbol)); } } } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 58ec22135356..e1b1828f7fe8 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -78,7 +78,7 @@ use rustc_middle::lint::in_external_macro; use rustc_middle::ty::{self, TraitRef, Ty, TyS}; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::symbol::SymbolStr; +use rustc_span::symbol::Symbol; use rustc_span::{sym, Span}; use rustc_typeck::hir_ty_to_ty; @@ -1968,21 +1968,21 @@ impl_lint_pass!(Methods => [ ]); /// Extracts a method call name, args, and `Span` of the method name. -fn method_call<'tcx>(recv: &'tcx hir::Expr<'tcx>) -> Option<(SymbolStr, &'tcx [hir::Expr<'tcx>], Span)> { +fn method_call<'tcx>(recv: &'tcx hir::Expr<'tcx>) -> Option<(Symbol, &'tcx [hir::Expr<'tcx>], Span)> { if let ExprKind::MethodCall(path, span, args, _) = recv.kind { if !args.iter().any(|e| e.span.from_expansion()) { - return Some((path.ident.name.as_str(), args, span)); + return Some((path.ident.name, args, span)); } } None } -/// Same as `method_call` but the `SymbolStr` is dereferenced into a temporary `&str` +/// Same as `method_call` but the `Symbol` is dereferenced into a temporary `&str` macro_rules! method_call { ($expr:expr) => { method_call($expr) .as_ref() - .map(|&(ref name, args, span)| (&**name, args, span)) + .map(|&(ref name, args, span)| (name.as_str(), args, span)) }; } diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 2299a0999109..401dc27811dc 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -407,6 +407,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints { // Don't lint things expanded by #[derive(...)], etc or `await` desugaring return; } + let sym; let binding = match expr.kind { ExprKind::Path(ref qpath) if !matches!(qpath, hir::QPath::LangItem(..)) => { let binding = last_path_segment(qpath).ident.as_str(); @@ -423,7 +424,8 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints { } }, ExprKind::Field(_, ident) => { - let name = ident.as_str(); + sym = ident.name; + let name = sym.as_str(); if name.starts_with('_') && !name.starts_with("__") { Some(name) } else { diff --git a/clippy_lints/src/multiple_crate_versions.rs b/clippy_lints/src/multiple_crate_versions.rs index e45cc86d417a..1f9db39cf8ca 100644 --- a/clippy_lints/src/multiple_crate_versions.rs +++ b/clippy_lints/src/multiple_crate_versions.rs @@ -48,7 +48,7 @@ impl LateLintPass<'_> for MultipleCrateVersions { } let metadata = unwrap_cargo_metadata!(cx, MULTIPLE_CRATE_VERSIONS, true); - let local_name = cx.tcx.crate_name(LOCAL_CRATE).as_str(); + let local_name = cx.tcx.crate_name(LOCAL_CRATE); let mut packages = metadata.packages; packages.sort_by(|a, b| a.name.cmp(&b.name)); @@ -56,7 +56,7 @@ impl LateLintPass<'_> for MultipleCrateVersions { if let Some(resolve) = &metadata.resolve; if let Some(local_id) = packages .iter() - .find_map(|p| if p.name == *local_name { Some(&p.id) } else { None }); + .find_map(|p| if p.name == local_name.as_str() { Some(&p.id) } else { None }); then { for (name, group) in &packages.iter().group_by(|p| p.name.clone()) { let group: Vec<&Package> = group.collect(); diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 04347672e0fb..dc5ec5f22951 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -319,8 +319,8 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { if let ExprKind::Path(qpath) = &callee.kind; let res = self.typeck_results.qpath_res(qpath, callee.hir_id); if let Some(def_id) = res.opt_def_id(); - let def_path: Vec<_> = self.lcx.get_def_path(def_id).into_iter().map(Symbol::as_str).collect(); - let def_path: Vec<&str> = def_path.iter().take(4).map(|s| &**s).collect(); + let def_path = self.lcx.get_def_path(def_id); + let def_path: Vec<&str> = def_path.iter().take(4).map(|s| s.as_str()).collect(); if let ["core", "num", int_impl, "max_value"] = *def_path; then { let value = match int_impl { From c60023c477c5e0b5254e7342d7159208d26a9cad Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Wed, 3 Nov 2021 02:50:57 -0400 Subject: [PATCH 0375/1222] Stabilize `destructuring_assignment` --- tests/ui/crashes/ice-6250.stderr | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/tests/ui/crashes/ice-6250.stderr b/tests/ui/crashes/ice-6250.stderr index 0d7713aa9a27..7ffbd7a64b34 100644 --- a/tests/ui/crashes/ice-6250.stderr +++ b/tests/ui/crashes/ice-6250.stderr @@ -1,14 +1,3 @@ -error[E0658]: destructuring assignments are unstable - --> $DIR/ice-6250.rs:12:25 - | -LL | Some(reference) = cache.data.get(key) { - | --------------- ^ - | | - | cannot assign to this expression - | - = note: see issue #71126 for more information - = help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable - error[E0601]: `main` function not found in crate `ice_6250` --> $DIR/ice-6250.rs:4:1 | @@ -41,7 +30,7 @@ error[E0308]: mismatched types LL | Some(reference) = cache.data.get(key) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()` -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0308, E0601, E0658. +Some errors have detailed explanations: E0308, E0601. For more information about an error, try `rustc --explain E0308`. From 79c995676263a30cd6bfd1e3427bffa52f52ceda Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 15 Dec 2021 14:39:23 +1100 Subject: [PATCH 0376/1222] Remove unnecessary sigils around `Symbol::as_str()` calls. --- clippy_lints/src/attrs.rs | 4 ++-- clippy_lints/src/booleans.rs | 2 +- clippy_lints/src/checked_conversions.rs | 8 ++++---- clippy_lints/src/doc.rs | 2 +- clippy_lints/src/enum_variants.rs | 2 +- clippy_lints/src/float_literal.rs | 2 +- clippy_lints/src/floating_point_arithmetic.rs | 2 +- clippy_lints/src/iter_not_returning_iterator.rs | 2 +- clippy_lints/src/loops/needless_collect.rs | 4 ++-- clippy_lints/src/matches.rs | 2 +- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/missing_enforced_import_rename.rs | 2 +- clippy_lints/src/non_expressive_names.rs | 4 ++-- clippy_lints/src/nonstandard_macro_braces.rs | 2 +- clippy_lints/src/path_buf_push_overwrite.rs | 2 +- clippy_lints/src/regex.rs | 2 +- clippy_lints/src/stable_sort_primitive.rs | 2 +- clippy_lints/src/strings.rs | 2 +- clippy_lints/src/unit_types/unit_cmp.rs | 2 +- clippy_lints/src/unused_unit.rs | 2 +- clippy_lints/src/write.rs | 10 +++++----- clippy_utils/src/attrs.rs | 2 +- clippy_utils/src/eager_or_lazy.rs | 2 +- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 24 files changed, 34 insertions(+), 34 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 06a99ff5418f..489945b513da 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -486,7 +486,7 @@ fn check_attrs(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Attribut fn check_semver(cx: &LateContext<'_>, span: Span, lit: &Lit) { if let LitKind::Str(is, _) = lit.kind { - if Version::parse(&is.as_str()).is_ok() { + if Version::parse(is.as_str()).is_ok() { return; } } @@ -619,7 +619,7 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) { MetaItemKind::Word => { if_chain! { if let Some(ident) = meta.ident(); - if let Some(os) = find_os(&*ident.name.as_str()); + if let Some(os) = find_os(ident.name.as_str()); then { mismatched.push((os, ident.span)); } diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 51835ee7488f..43ad0f7605c1 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -272,7 +272,7 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { .copied() .flat_map(|(a, b)| vec![(a, b), (b, a)]) .find(|&(a, _)| { - let path: &str = &path.ident.name.as_str(); + let path: &str = path.ident.name.as_str(); a == path }) .and_then(|(_, neg_method)| Some(format!("{}.{}()", snippet_opt(cx, args[0].span)?, neg_method))) diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs index ffe6340bd77a..31cc3698592b 100644 --- a/clippy_lints/src/checked_conversions.rs +++ b/clippy_lints/src/checked_conversions.rs @@ -321,8 +321,8 @@ fn get_implementing_type<'a>(path: &QPath<'_>, candidates: &'a [&str], function: if let TyKind::Path(QPath::Resolved(None, tp)) = &ty.kind; if let [int] = &*tp.segments; then { - let name = &int.ident.name.as_str(); - candidates.iter().find(|c| name == *c).copied() + let name = int.ident.name.as_str(); + candidates.iter().find(|c| &name == *c).copied() } else { None } @@ -335,8 +335,8 @@ fn int_ty_to_sym<'tcx>(path: &QPath<'_>) -> Option<&'tcx str> { if let QPath::Resolved(_, path) = *path; if let [ty] = &*path.segments; then { - let name = &ty.ident.name.as_str(); - INTS.iter().find(|c| name == *c).copied() + let name = ty.ident.name.as_str(); + INTS.iter().find(|c| &name == *c).copied() } else { None } diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 2cdd59c56919..3650e4f91a00 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -437,7 +437,7 @@ fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs for attr in attrs { if let AttrKind::DocComment(comment_kind, comment) = attr.kind { - let (comment, current_spans) = strip_doc_comment_decoration(&comment.as_str(), comment_kind, attr.span); + let (comment, current_spans) = strip_doc_comment_decoration(comment.as_str(), comment_kind, attr.span); spans.extend_from_slice(¤t_spans); doc.push_str(&comment); } else if attr.has_name(sym::doc) { diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index fc3a35efaf84..689ac6184bff 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -153,7 +153,7 @@ fn check_variant( ); } } - let first = &def.variants[0].ident.name.as_str(); + let first = def.variants[0].ident.name.as_str(); let mut pre = &first[..str_utils::camel_case_until(&*first).byte_index]; let mut post = &first[str_utils::camel_case_start(&*first).byte_index..]; for var in def.variants { diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index d30dede833cb..6903073fbcd8 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral { if let LitKind::Float(sym, lit_float_ty) = lit.node; then { let sym_str = sym.as_str(); - let formatter = FloatFormat::new(&sym_str); + let formatter = FloatFormat::new(sym_str); // Try to bail out if the float is for sure fine. // If its within the 2 decimal digits of being out of precision we // check if the parsed representation is the same as the string diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index 3df511ea8e78..5098ea349f9a 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -696,7 +696,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatingPointArithmetic { let recv_ty = cx.typeck_results().expr_ty(&args[0]); if recv_ty.is_floating_point() { - match &*path.ident.name.as_str() { + match path.ident.name.as_str() { "ln" => check_ln1p(cx, expr, args), "log" => check_log_base(cx, expr, args), "powf" => check_powf(cx, expr, args), diff --git a/clippy_lints/src/iter_not_returning_iterator.rs b/clippy_lints/src/iter_not_returning_iterator.rs index 968bbc524b25..0af6b3b7d464 100644 --- a/clippy_lints/src/iter_not_returning_iterator.rs +++ b/clippy_lints/src/iter_not_returning_iterator.rs @@ -42,7 +42,7 @@ declare_lint_pass!(IterNotReturningIterator => [ITER_NOT_RETURNING_ITERATOR]); impl LateLintPass<'_> for IterNotReturningIterator { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'tcx>) { - let name: &str = &impl_item.ident.name.as_str(); + let name = impl_item.ident.name.as_str(); if_chain! { if let ImplItemKind::Fn(fn_sig, _) = &impl_item.kind; let ret_ty = return_ty(cx, impl_item.hir_id()); diff --git a/clippy_lints/src/loops/needless_collect.rs b/clippy_lints/src/loops/needless_collect.rs index 6f3acb45ba4f..ba895f35faa2 100644 --- a/clippy_lints/src/loops/needless_collect.rs +++ b/clippy_lints/src/loops/needless_collect.rs @@ -31,7 +31,7 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont let ty = cx.typeck_results().expr_ty(&args[0]); let mut applicability = Applicability::MaybeIncorrect; let is_empty_sugg = "next().is_none()".to_string(); - let method_name = &*method.ident.name.as_str(); + let method_name = method.ident.name.as_str(); let sugg = if is_type_diagnostic_item(cx, ty, sym::Vec) || is_type_diagnostic_item(cx, ty, sym::VecDeque) || is_type_diagnostic_item(cx, ty, sym::LinkedList) || @@ -210,7 +210,7 @@ impl<'tcx> Visitor<'tcx> for IterFunctionVisitor<'_, 'tcx> { if let Some(hir_id) = self.current_statement_hir_id { self.hir_id_uses_map.insert(hir_id, self.uses.len()); } - match &*method_name.ident.name.as_str() { + match method_name.ident.name.as_str() { "into_iter" => self.uses.push(Some(IterFunction { func: IterFunctionKind::IntoIter, span: expr.span, diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index eacbfa54cf70..98acd1c1a75b 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -966,7 +966,7 @@ fn check_wild_err_arm<'tcx>(cx: &LateContext<'tcx>, ex: &Expr<'tcx>, arms: &[Arm for pat in inner.iter() { if let PatKind::Binding(_, id, ident, None) = pat.kind { if ident.as_str().starts_with('_') && !is_local_used(cx, arm.body, id) { - ident_bind_name = (&ident.name.as_str()).to_string(); + ident_bind_name = ident.name.as_str().to_string(); matching_wild = true; } } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index e1b1828f7fe8..6ae334d90299 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2154,7 +2154,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty().skip_binder(); wrong_self_convention::check( cx, - &item.ident.name.as_str(), + item.ident.name.as_str(), self_ty, first_arg_ty, first_arg_span, diff --git a/clippy_lints/src/missing_enforced_import_rename.rs b/clippy_lints/src/missing_enforced_import_rename.rs index 68d49e0f1503..566e15ab2a6d 100644 --- a/clippy_lints/src/missing_enforced_import_rename.rs +++ b/clippy_lints/src/missing_enforced_import_rename.rs @@ -75,7 +75,7 @@ impl LateLintPass<'_> for ImportRename { if let Some(import) = match snip.split_once(" as ") { None => Some(snip.as_str()), Some((import, rename)) => { - if rename.trim() == &*name.as_str() { + if rename.trim() == name.as_str() { None } else { Some(import.trim()) diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 5559fac0a8a1..25fbcb3c6094 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -224,14 +224,14 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> { match existing_name.len.cmp(&count) { Ordering::Greater => { if existing_name.len - count != 1 - || levenstein_not_1(&interned_name, &existing_name.interned.as_str()) + || levenstein_not_1(&interned_name, existing_name.interned.as_str()) { continue; } }, Ordering::Less => { if count - existing_name.len != 1 - || levenstein_not_1(&existing_name.interned.as_str(), &interned_name) + || levenstein_not_1(existing_name.interned.as_str(), &interned_name) { continue; } diff --git a/clippy_lints/src/nonstandard_macro_braces.rs b/clippy_lints/src/nonstandard_macro_braces.rs index a04d589f880f..4722c031006b 100644 --- a/clippy_lints/src/nonstandard_macro_braces.rs +++ b/clippy_lints/src/nonstandard_macro_braces.rs @@ -104,7 +104,7 @@ fn is_offending_macro<'a>(cx: &EarlyContext<'_>, span: Span, mac_braces: &'a Mac }; if_chain! { if let ExpnKind::Macro(MacroKind::Bang, mac_name) = span.ctxt().outer_expn_data().kind; - let name = &*mac_name.as_str(); + let name = mac_name.as_str(); if let Some(braces) = mac_braces.macro_braces.get(name); if let Some(snip) = snippet_opt(cx, span.ctxt().outer_expn_data().call_site); // we must check only invocation sites diff --git a/clippy_lints/src/path_buf_push_overwrite.rs b/clippy_lints/src/path_buf_push_overwrite.rs index 8ebee9bd04d3..e58ca95fa042 100644 --- a/clippy_lints/src/path_buf_push_overwrite.rs +++ b/clippy_lints/src/path_buf_push_overwrite.rs @@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for PathBufPushOverwrite { if let Some(get_index_arg) = args.get(1); if let ExprKind::Lit(ref lit) = get_index_arg.kind; if let LitKind::Str(ref path_lit, _) = lit.node; - if let pushed_path = Path::new(&*path_lit.as_str()); + if let pushed_path = Path::new(path_lit.as_str()); if let Some(pushed_path_lit) = pushed_path.to_str(); if pushed_path.has_root(); if let Some(root) = pushed_path.components().next(); diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index 8e5983b4773a..b6d04334de9e 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -150,7 +150,7 @@ fn check_regex<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, utf8: bool) { if let ExprKind::Lit(ref lit) = expr.kind { if let LitKind::Str(ref r, style) = lit.node { - let r = &r.as_str(); + let r = r.as_str(); let offset = if let StrStyle::Raw(n) = style { 2 + n } else { 1 }; match parser.parse(r) { Ok(r) => { diff --git a/clippy_lints/src/stable_sort_primitive.rs b/clippy_lints/src/stable_sort_primitive.rs index 953d21e07a39..20e38dc564eb 100644 --- a/clippy_lints/src/stable_sort_primitive.rs +++ b/clippy_lints/src/stable_sort_primitive.rs @@ -89,7 +89,7 @@ fn detect_stable_sort_primitive(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option if_chain! { if let ExprKind::MethodCall(method_name, _, args, _) = &expr.kind; if let Some(slice) = &args.get(0); - if let Some(method) = SortingKind::from_stable_name(&method_name.ident.name.as_str()); + if let Some(method) = SortingKind::from_stable_name(method_name.ident.name.as_str()); if let Some(slice_type) = is_slice_of_primitives(cx, slice); then { let args_str = args.iter().skip(1).map(|arg| Sugg::hir(cx, arg, "..").to_string()).collect::>().join(", "); diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 368274440d5d..60f0ffde0940 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -330,7 +330,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { if let ExprKind::MethodCall(path, _, [recv], _) = &e.kind; if path.ident.name == sym!(into_bytes); if let ExprKind::MethodCall(path, _, [recv], _) = &recv.kind; - if matches!(&*path.ident.name.as_str(), "to_owned" | "to_string"); + if matches!(path.ident.name.as_str(), "to_owned" | "to_string"); if let ExprKind::Lit(lit) = &recv.kind; if let LitKind::Str(lit_content, _) = &lit.node; diff --git a/clippy_lints/src/unit_types/unit_cmp.rs b/clippy_lints/src/unit_types/unit_cmp.rs index 85257f3113cb..6d9aff474214 100644 --- a/clippy_lints/src/unit_types/unit_cmp.rs +++ b/clippy_lints/src/unit_types/unit_cmp.rs @@ -12,7 +12,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { if let ExprKind::Binary(ref cmp, left, _) = expr.kind { let op = cmp.node; if op.is_comparison() && cx.typeck_results().expr_ty(left).is_unit() { - let result = match &*symbol.as_str() { + let result = match symbol.as_str() { "assert_eq" | "debug_assert_eq" => "succeed", "assert_ne" | "debug_assert_ne" => "fail", _ => return, diff --git a/clippy_lints/src/unused_unit.rs b/clippy_lints/src/unused_unit.rs index 48c17fa2a40b..bfd17a687499 100644 --- a/clippy_lints/src/unused_unit.rs +++ b/clippy_lints/src/unused_unit.rs @@ -94,7 +94,7 @@ impl EarlyLintPass for UnusedUnit { if_chain! { if segments.len() == 1; - if ["Fn", "FnMut", "FnOnce"].contains(&&*segments[0].ident.name.as_str()); + if ["Fn", "FnMut", "FnOnce"].contains(&segments[0].ident.name.as_str()); if let Some(args) = &segments[0].args; if let ast::GenericArgs::Parenthesized(generic_args) = &**args; if let ast::FnRetTy::Ty(ty) = &generic_args.output; diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 5bf0cffdbad1..f9add927b49b 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -371,9 +371,9 @@ impl EarlyLintPass for Write { /// Return this and a boolean indicating whether it only consisted of a newline. fn newline_span(fmtstr: &StrLit) -> (Span, bool) { let sp = fmtstr.span; - let contents = &fmtstr.symbol.as_str(); + let contents = fmtstr.symbol.as_str(); - if *contents == r"\n" { + if contents == r"\n" { return (sp, true); } @@ -484,7 +484,7 @@ impl Write { StrStyle::Raw(n) => Some(n as usize), }; - let mut parser = Parser::new(&str_sym, style, snippet_opt(cx, str_lit.span), false, ParseMode::Format); + let mut parser = Parser::new(str_sym, style, snippet_opt(cx, str_lit.span), false, ParseMode::Format); let mut args = SimpleFormatArgs::default(); while let Some(arg) = parser.next() { @@ -589,7 +589,7 @@ impl Write { lit.token.symbol.as_str().replace('{', "{{").replace('}', "}}") }, LitKind::StrRaw(_) | LitKind::Str | LitKind::ByteStrRaw(_) | LitKind::ByteStr => continue, - LitKind::Byte | LitKind::Char => match &*lit.token.symbol.as_str() { + LitKind::Byte | LitKind::Char => match lit.token.symbol.as_str() { "\"" if matches!(fmtstr.style, StrStyle::Cooked) => "\\\"", "\"" if matches!(fmtstr.style, StrStyle::Raw(0)) => continue, "\\\\" if matches!(fmtstr.style, StrStyle::Raw(_)) => "\\", @@ -671,7 +671,7 @@ fn check_newlines(fmtstr: &StrLit) -> bool { let mut last_was_cr = false; let mut should_lint = false; - let contents = &fmtstr.symbol.as_str(); + let contents = fmtstr.symbol.as_str(); let mut cb = |r: Range, c: Result| { let c = c.unwrap(); diff --git a/clippy_utils/src/attrs.rs b/clippy_utils/src/attrs.rs index 7ae9615d560b..25a84d166508 100644 --- a/clippy_utils/src/attrs.rs +++ b/clippy_utils/src/attrs.rs @@ -113,7 +113,7 @@ pub fn get_attr<'a>( fn parse_attrs(sess: &Session, attrs: &[ast::Attribute], name: &'static str, mut f: F) { for attr in get_attr(sess, attrs, name) { if let Some(ref value) = attr.value_str() { - if let Ok(value) = FromStr::from_str(&value.as_str()) { + if let Ok(value) = FromStr::from_str(value.as_str()) { f(value); } else { sess.span_err(attr.span, "not a number"); diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index c2645ac730a4..61e529a6079c 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -47,7 +47,7 @@ impl ops::BitOrAssign for EagernessSuggestion { /// Determine the eagerness of the given function call. fn fn_eagerness(cx: &LateContext<'tcx>, fn_id: DefId, name: Symbol, args: &'tcx [Expr<'_>]) -> EagernessSuggestion { use EagernessSuggestion::{Eager, Lazy, NoChange}; - let name = &*name.as_str(); + let name = name.as_str(); let ty = match cx.tcx.impl_of_method(fn_id) { Some(id) => cx.tcx.type_of(id), diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index e6d8ba3f02eb..1a4da1627b78 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -372,7 +372,7 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<&RustcVersion>) -> b // as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262. crate::meets_msrv( msrv, - &RustcVersion::parse(&since.as_str()) + &RustcVersion::parse(since.as_str()) .expect("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted"), ) } else { From ed8339e3e77658b7a327278d1e31a38f8ef7428a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 15 Dec 2021 16:13:11 +1100 Subject: [PATCH 0377/1222] Remove unnecessary sigils around `Ident::as_str()` calls. --- clippy_lints/src/duration_subsec.rs | 2 +- clippy_lints/src/floating_point_arithmetic.rs | 2 +- clippy_lints/src/loops/mod.rs | 2 +- clippy_lints/src/match_str_case_mismatch.rs | 2 +- clippy_lints/src/matches.rs | 2 +- clippy_lints/src/methods/manual_saturating_arithmetic.rs | 2 +- clippy_lints/src/methods/mod.rs | 4 ++-- clippy_lints/src/methods/str_splitn.rs | 4 ++-- clippy_lints/src/mut_reference.rs | 2 +- clippy_lints/src/needless_option_as_deref.rs | 2 +- clippy_lints/src/open_options.rs | 2 +- clippy_lints/src/serde_api.rs | 2 +- clippy_lints/src/unused_io_amount.rs | 6 +++--- clippy_lints/src/unwrap.rs | 2 +- clippy_lints/src/upper_case_acronyms.rs | 2 +- clippy_lints/src/useless_conversion.rs | 2 +- 16 files changed, 20 insertions(+), 20 deletions(-) diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index 3070d105014f..50dd0d84fda5 100644 --- a/clippy_lints/src/duration_subsec.rs +++ b/clippy_lints/src/duration_subsec.rs @@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for DurationSubsec { if match_type(cx, cx.typeck_results().expr_ty(&args[0]).peel_refs(), &paths::DURATION); if let Some((Constant::Int(divisor), _)) = constant(cx, cx.typeck_results(), right); then { - let suggested_fn = match (method_path.ident.as_str().as_ref(), divisor) { + let suggested_fn = match (method_path.ident.as_str(), divisor) { ("subsec_micros", 1_000) | ("subsec_nanos", 1_000_000) => "subsec_millis", ("subsec_nanos", 1_000) => "subsec_micros", _ => return, diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index 5098ea349f9a..f21ec9a876ff 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -599,7 +599,7 @@ fn are_same_base_logs(cx: &LateContext<'_>, expr_a: &Expr<'_>, expr_b: &Expr<'_> return method_name_a.as_str() == method_name_b.as_str() && args_a.len() == args_b.len() && ( - ["ln", "log2", "log10"].contains(&&*method_name_a.as_str()) || + ["ln", "log2", "log10"].contains(&method_name_a.as_str()) || method_name_a.as_str() == "log" && args_a.len() == 2 && eq_expr_value(cx, &args_a[1], &args_b[1]) ); } diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index e2f9aee063dd..b03445b8cd6b 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -659,7 +659,7 @@ fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) { let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used if let ExprKind::MethodCall(method, _, [self_arg], _) = arg.kind { - let method_name = &*method.ident.as_str(); + let method_name = method.ident.as_str(); // check for looping over x.iter() or x.iter_mut(), could use &x or &mut x match method_name { "iter" | "iter_mut" => explicit_iter_loop::check(cx, self_arg, arg, method_name), diff --git a/clippy_lints/src/match_str_case_mismatch.rs b/clippy_lints/src/match_str_case_mismatch.rs index 241283851899..dbf103143d93 100644 --- a/clippy_lints/src/match_str_case_mismatch.rs +++ b/clippy_lints/src/match_str_case_mismatch.rs @@ -95,7 +95,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MatchExprVisitor<'a, 'tcx> { fn visit_expr(&mut self, ex: &'tcx Expr<'_>) { match ex.kind { ExprKind::MethodCall(segment, _, [receiver], _) - if self.case_altered(&*segment.ident.as_str(), receiver) => {}, + if self.case_altered(segment.ident.as_str(), receiver) => {}, _ => walk_expr(self, ex), } } diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 98acd1c1a75b..4ca1b3f01671 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -1127,7 +1127,7 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) if let CommonPrefixSearcher::Path(path_prefix) = path_prefix { let mut s = String::new(); for seg in path_prefix { - s.push_str(&seg.ident.as_str()); + s.push_str(seg.ident.as_str()); s.push_str("::"); } s diff --git a/clippy_lints/src/methods/manual_saturating_arithmetic.rs b/clippy_lints/src/methods/manual_saturating_arithmetic.rs index 7ecafa1f3ba5..4307cbf00507 100644 --- a/clippy_lints/src/methods/manual_saturating_arithmetic.rs +++ b/clippy_lints/src/methods/manual_saturating_arithmetic.rs @@ -81,7 +81,7 @@ fn is_min_or_max<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>) -> Option return Some(MinMax::Max), "min_value" => return Some(MinMax::Min), _ => {} diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 6ae334d90299..f2d843818879 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1999,8 +1999,8 @@ impl<'tcx> LateLintPass<'tcx> for Methods { from_iter_instead_of_collect::check(cx, expr, args, func); }, hir::ExprKind::MethodCall(method_call, ref method_span, args, _) => { - or_fun_call::check(cx, expr, *method_span, &method_call.ident.as_str(), args); - expect_fun_call::check(cx, expr, *method_span, &method_call.ident.as_str(), args); + or_fun_call::check(cx, expr, *method_span, method_call.ident.as_str(), args); + expect_fun_call::check(cx, expr, *method_span, method_call.ident.as_str(), args); clone_on_copy::check(cx, expr, method_call.ident.name, args); clone_on_ref_ptr::check(cx, expr, method_call.ident.name, args); inefficient_to_string::check(cx, expr, method_call.ident.name, args); diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 2595f734f115..e57f5f6f6ed8 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -140,7 +140,7 @@ fn parse_iter_usage( let did = cx.typeck_results().type_dependent_def_id(e.hir_id)?; let iter_id = cx.tcx.get_diagnostic_item(sym::Iterator)?; - match (&*name.ident.as_str(), args) { + match (name.ident.as_str(), args) { ("next", []) if cx.tcx.trait_of_item(did) == Some(iter_id) => { if reverse { (IterUsageKind::Second, e.span) @@ -298,7 +298,7 @@ fn check_iter( if let Some(did) = cx.typeck_results().type_dependent_def_id(e.hir_id); if let Some(iter_id) = cx.tcx.get_diagnostic_item(sym::Iterator); then { - match (&*name.ident.as_str(), args) { + match (name.ident.as_str(), args) { ("next", []) if cx.tcx.trait_of_item(did) == Some(iter_id) => { return true; }, diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 63a1cf7b7d5b..22834cf61ee0 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed { let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap(); let substs = cx.typeck_results().node_substs(e.hir_id); let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs); - check_arguments(cx, arguments, method_type, &path.ident.as_str(), "method"); + check_arguments(cx, arguments, method_type, path.ident.as_str(), "method"); }, _ => (), } diff --git a/clippy_lints/src/needless_option_as_deref.rs b/clippy_lints/src/needless_option_as_deref.rs index a28b08c33ec4..0931fec149eb 100644 --- a/clippy_lints/src/needless_option_as_deref.rs +++ b/clippy_lints/src/needless_option_as_deref.rs @@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for OptionNeedlessDeref { if is_type_diagnostic_item(cx,outer_ty,sym::Option); if let ExprKind::MethodCall(path, _, [sub_expr], _) = expr.kind; let symbol = path.ident.as_str(); - if symbol=="as_deref" || symbol=="as_deref_mut"; + if symbol == "as_deref" || symbol == "as_deref_mut"; if TyS::same_type( outer_ty, typeck.expr_ty(sub_expr) ); then{ span_lint_and_sugg( diff --git a/clippy_lints/src/open_options.rs b/clippy_lints/src/open_options.rs index 2c77100bdcfc..1b9285c2298d 100644 --- a/clippy_lints/src/open_options.rs +++ b/clippy_lints/src/open_options.rs @@ -82,7 +82,7 @@ fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec _ => Argument::Unknown, }; - match &*path.ident.as_str() { + match path.ident.as_str() { "create" => { options.push((OpenOption::Create, argument_option)); }, diff --git a/clippy_lints/src/serde_api.rs b/clippy_lints/src/serde_api.rs index a38b3c4ab69b..398e2c200de3 100644 --- a/clippy_lints/src/serde_api.rs +++ b/clippy_lints/src/serde_api.rs @@ -37,7 +37,7 @@ impl<'tcx> LateLintPass<'tcx> for SerdeApi { let mut seen_str = None; let mut seen_string = None; for item in items { - match &*item.ident.as_str() { + match item.ident.as_str() { "visit_str" => seen_str = Some(item.span), "visit_string" => seen_string = Some(item.span), _ => {}, diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index d4b5c9770a27..f930fc9c55ba 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -57,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount { check_map_error(cx, res, expr); } }, - hir::ExprKind::MethodCall(path, _, [ref arg_0, ..], _) => match &*path.ident.as_str() { + hir::ExprKind::MethodCall(path, _, [ref arg_0, ..], _) => match path.ident.as_str() { "expect" | "unwrap" | "unwrap_or" | "unwrap_or_else" => { check_map_error(cx, arg_0, expr); }, @@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount { fn check_map_error(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) { let mut call = call; while let hir::ExprKind::MethodCall(path, _, args, _) = call.kind { - if matches!(&*path.ident.as_str(), "or" | "or_else" | "ok") { + if matches!(path.ident.as_str(), "or" | "or_else" | "ok") { call = &args[0]; } else { break; @@ -82,7 +82,7 @@ fn check_map_error(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr< fn check_method_call(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) { if let hir::ExprKind::MethodCall(path, _, _, _) = call.kind { - let symbol = &*path.ident.as_str(); + let symbol = path.ident.as_str(); let read_trait = match_trait_method(cx, call, &paths::IO_READ); let write_trait = match_trait_method(cx, call, &paths::IO_WRITE); diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 71771aae44b2..01a5691223bf 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -158,7 +158,7 @@ fn collect_unwrap_info<'tcx>( if let Some(local_id) = path_to_local(&args[0]); let ty = cx.typeck_results().expr_ty(&args[0]); let name = method_name.ident.as_str(); - if is_relevant_option_call(cx, ty, &name) || is_relevant_result_call(cx, ty, &name); + if is_relevant_option_call(cx, ty, name) || is_relevant_result_call(cx, ty, name); then { assert!(args.len() == 1); let unwrappable = match name.as_ref() { diff --git a/clippy_lints/src/upper_case_acronyms.rs b/clippy_lints/src/upper_case_acronyms.rs index 4773e3507605..0c62161e53d4 100644 --- a/clippy_lints/src/upper_case_acronyms.rs +++ b/clippy_lints/src/upper_case_acronyms.rs @@ -79,7 +79,7 @@ fn correct_ident(ident: &str) -> String { fn check_ident(cx: &LateContext<'_>, ident: &Ident, be_aggressive: bool) { let span = ident.span; - let ident = &ident.as_str(); + let ident = ident.as_str(); let corrected = correct_ident(ident); // warn if we have pure-uppercase idents // assume that two-letter words are some kind of valid abbreviation like FP for false positive diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 0e4b32541c97..abd8a3623703 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { }, ExprKind::MethodCall(name, .., args, _) => { - if is_trait_method(cx, e, sym::Into) && &*name.ident.as_str() == "into" { + if is_trait_method(cx, e, sym::Into) && name.ident.as_str() == "into" { let a = cx.typeck_results().expr_ty(e); let b = cx.typeck_results().expr_ty(&args[0]); if same_type_and_consts(a, b) { From 134d8c86574045e507b6e014280f04b030899c9f Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 22 Dec 2021 17:25:44 +0100 Subject: [PATCH 0378/1222] Bless clippy test. --- tests/ui/missing_panics_doc.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/missing_panics_doc.stderr b/tests/ui/missing_panics_doc.stderr index 60282939ef03..8bccbaefe23c 100644 --- a/tests/ui/missing_panics_doc.stderr +++ b/tests/ui/missing_panics_doc.stderr @@ -42,7 +42,7 @@ note: first possible panic found here | LL | todo!() | ^^^^^^^ - = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: docs for function which may panic missing `# Panics` section --> $DIR/missing_panics_doc.rs:22:1 From 4e96fac7d7236e4ba089bcc633a70db67159fcb1 Mon Sep 17 00:00:00 2001 From: lcnr Date: Thu, 23 Dec 2021 10:02:05 +0100 Subject: [PATCH 0379/1222] fix clippy --- clippy_lints/src/trailing_empty_array.rs | 1 + clippy_lints/src/utils/author.rs | 11 +++++-- clippy_lints/src/utils/inspector.rs | 9 ++++-- clippy_utils/src/hir_utils.rs | 39 ++++++++++++++++-------- clippy_utils/src/lib.rs | 7 +++-- tests/ui/author/repeat.stdout | 3 +- 6 files changed, 50 insertions(+), 20 deletions(-) diff --git a/clippy_lints/src/trailing_empty_array.rs b/clippy_lints/src/trailing_empty_array.rs index 47c0a84cd463..af36f7267004 100644 --- a/clippy_lints/src/trailing_empty_array.rs +++ b/clippy_lints/src/trailing_empty_array.rs @@ -59,6 +59,7 @@ fn is_struct_with_trailing_zero_sized_array(cx: &LateContext<'tcx>, item: &'tcx if let ItemKind::Struct(data, _) = &item.kind; if let Some(last_field) = data.fields().last(); if let rustc_hir::TyKind::Array(_, length) = last_field.ty.kind; + if let rustc_hir::ArrayLen::Body(length) = length; // Then check if that that array zero-sized let length_ldid = cx.tcx.hir().local_def_id(length.hir_id); diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index c1b811c21744..9b06ca4e8249 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -6,7 +6,7 @@ use rustc_ast::ast::{LitFloatType, LitKind}; use rustc_ast::LitIntType; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; -use rustc_hir::{ExprKind, FnRetTy, HirId, Lit, PatKind, QPath, StmtKind, TyKind}; +use rustc_hir::{ArrayLen, ExprKind, FnRetTy, HirId, Lit, PatKind, QPath, StmtKind, TyKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::{Ident, Symbol}; @@ -567,7 +567,14 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { bind!(self, value, length); kind!("Repeat({value}, {length})"); self.expr(value); - self.body(field!(length.body)); + match length.value { + ArrayLen::Infer(..) => out!("if let ArrayLen::Infer(..) = length;"), + ArrayLen::Body(anon_const) => { + bind!(self, anon_const); + out!("if let ArrayLen::Body({anon_const}) = {length};"); + self.body(field!(anon_const.body)); + } + } }, ExprKind::Err => kind!("Err"), ExprKind::DropTemps(expr) => { diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index abf4826a0691..c96766e56784 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -334,12 +334,17 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { println!("{}anon_const:", ind); print_expr(cx, &cx.tcx.hir().body(anon_const.body).value, indent + 1); }, - hir::ExprKind::Repeat(val, ref anon_const) => { + hir::ExprKind::Repeat(val, length) => { println!("{}Repeat", ind); println!("{}value:", ind); print_expr(cx, val, indent + 1); println!("{}repeat count:", ind); - print_expr(cx, &cx.tcx.hir().body(anon_const.body).value, indent + 1); + match length { + hir::ArrayLen::Infer(_, _) => println!("{}repeat count: _", ind), + hir::ArrayLen::Body(anon_const) => { + print_expr(cx, &cx.tcx.hir().body(anon_const.body).value, indent + 1) + } + } }, hir::ExprKind::Err => { println!("{}Err", ind); diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index ad50759effaf..ac2b1a0259e3 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -8,7 +8,7 @@ use rustc_hir::HirIdMap; use rustc_hir::{ BinOpKind, Block, BodyId, Expr, ExprField, ExprKind, FnRetTy, GenericArg, GenericArgs, Guard, HirId, InlineAsmOperand, Let, Lifetime, LifetimeName, ParamName, Pat, PatField, PatKind, Path, PathSegment, QPath, Stmt, - StmtKind, Ty, TyKind, TypeBinding, + StmtKind, Ty, TyKind, TypeBinding, ArrayLen }; use rustc_lexer::{tokenize, TokenKind}; use rustc_lint::LateContext; @@ -170,6 +170,14 @@ impl HirEqInterExpr<'_, '_, '_> { } } + pub fn eq_array_length(&mut self, left: ArrayLen, right: ArrayLen) -> bool { + match (left, right) { + (ArrayLen::Infer(..), ArrayLen::Infer(..)) => true, + (ArrayLen::Body(l_ct), ArrayLen::Body(r_ct)) => self.eq_body(l_ct.body, r_ct.body), + (_, _) => false, + } + } + pub fn eq_body(&mut self, left: BodyId, right: BodyId) -> bool { let cx = self.inner.cx; let eval_const = |body| constant_context(cx, cx.tcx.typeck_body(body)).expr(&cx.tcx.hir().body(body).value); @@ -194,8 +202,8 @@ impl HirEqInterExpr<'_, '_, '_> { } let is_eq = match ( - &reduce_exprkind(self.inner.cx, &left.kind), - &reduce_exprkind(self.inner.cx, &right.kind), + reduce_exprkind(self.inner.cx, &left.kind), + reduce_exprkind(self.inner.cx, &right.kind), ) { (&ExprKind::AddrOf(lb, l_mut, le), &ExprKind::AddrOf(rb, r_mut, re)) => { lb == rb && l_mut == r_mut && self.eq_expr(le, re) @@ -232,7 +240,7 @@ impl HirEqInterExpr<'_, '_, '_> { }, (&ExprKind::Index(la, li), &ExprKind::Index(ra, ri)) => self.eq_expr(la, ra) && self.eq_expr(li, ri), (&ExprKind::If(lc, lt, ref le), &ExprKind::If(rc, rt, ref re)) => { - self.eq_expr(lc, rc) && self.eq_expr(&**lt, &**rt) && both(le, re, |l, r| self.eq_expr(l, r)) + self.eq_expr(lc, rc) && self.eq_expr(lt, rt) && both(le, re, |l, r| self.eq_expr(l, r)) }, (&ExprKind::Let(l), &ExprKind::Let(r)) => { self.eq_pat(l.pat, r.pat) && both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r)) && self.eq_expr(l.init, r.init) @@ -253,8 +261,8 @@ impl HirEqInterExpr<'_, '_, '_> { (&ExprKind::MethodCall(l_path, _, l_args, _), &ExprKind::MethodCall(r_path, _, r_args, _)) => { self.inner.allow_side_effects && self.eq_path_segment(l_path, r_path) && self.eq_exprs(l_args, r_args) }, - (&ExprKind::Repeat(le, ref ll_id), &ExprKind::Repeat(re, ref rl_id)) => { - self.eq_expr(le, re) && self.eq_body(ll_id.body, rl_id.body) + (&ExprKind::Repeat(le, ll), &ExprKind::Repeat(re, rl)) => { + self.eq_expr(le, re) && self.eq_array_length(ll, rl) }, (&ExprKind::Ret(ref l), &ExprKind::Ret(ref r)) => both(l, r, |l, r| self.eq_expr(l, r)), (&ExprKind::Path(ref l), &ExprKind::Path(ref r)) => self.eq_qpath(l, r), @@ -391,8 +399,8 @@ impl HirEqInterExpr<'_, '_, '_> { fn eq_ty(&mut self, left: &Ty<'_>, right: &Ty<'_>) -> bool { match (&left.kind, &right.kind) { (&TyKind::Slice(l_vec), &TyKind::Slice(r_vec)) => self.eq_ty(l_vec, r_vec), - (&TyKind::Array(lt, ref ll_id), &TyKind::Array(rt, ref rl_id)) => { - self.eq_ty(lt, rt) && self.eq_body(ll_id.body, rl_id.body) + (&TyKind::Array(lt, ll), &TyKind::Array(rt, rl)) => { + self.eq_ty(lt, rt) && self.eq_array_length(ll, rl) }, (&TyKind::Ptr(ref l_mut), &TyKind::Ptr(ref r_mut)) => { l_mut.mutbl == r_mut.mutbl && self.eq_ty(&*l_mut.ty, &*r_mut.ty) @@ -714,9 +722,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { ExprKind::ConstBlock(ref l_id) => { self.hash_body(l_id.body); }, - ExprKind::Repeat(e, ref l_id) => { + ExprKind::Repeat(e, len) => { self.hash_expr(e); - self.hash_body(l_id.body); + self.hash_array_length(len); }, ExprKind::Ret(ref e) => { if let Some(e) = *e { @@ -906,9 +914,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { TyKind::Slice(ty) => { self.hash_ty(ty); }, - TyKind::Array(ty, anon_const) => { + &TyKind::Array(ty, len) => { self.hash_ty(ty); - self.hash_body(anon_const.body); + self.hash_array_length(len); }, TyKind::Ptr(ref mut_ty) => { self.hash_ty(mut_ty.ty); @@ -953,6 +961,13 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } + pub fn hash_array_length(&mut self, length: ArrayLen) { + match length { + ArrayLen::Infer(..) => {} + ArrayLen::Body(anon_const) => self.hash_body(anon_const.body), + } + } + pub fn hash_body(&mut self, body_id: BodyId) { // swap out TypeckResults when hashing a body let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body_id)); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 7e054a54c3c0..be8558f36ca7 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -75,7 +75,7 @@ use rustc_hir::{ def, Arm, BindingAnnotation, Block, BlockCheckMode, Body, Constness, Destination, Expr, ExprKind, FnDecl, ForeignItem, GenericArgs, HirId, Impl, ImplItem, ImplItemKind, IsAsync, Item, ItemKind, LangItem, Local, MatchSource, Mutability, Node, Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, - TraitItemKind, TraitRef, TyKind, UnOp, + TraitItemKind, TraitRef, TyKind, UnOp, ArrayLen }; use rustc_lint::{LateContext, Level, Lint, LintContext}; use rustc_middle::hir::exports::Export; @@ -675,8 +675,9 @@ pub fn is_default_equivalent(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { _ => false, }, ExprKind::Tup(items) | ExprKind::Array(items) => items.iter().all(|x| is_default_equivalent(cx, x)), - ExprKind::Repeat(x, y) => if_chain! { - if let ExprKind::Lit(ref const_lit) = cx.tcx.hir().body(y.body).value.kind; + ExprKind::Repeat(x, len) => if_chain! { + if let ArrayLen::Body(len) = len; + if let ExprKind::Lit(ref const_lit) = cx.tcx.hir().body(len.body).value.kind; if let LitKind::Int(v, _) = const_lit.node; if v <= 32 && is_default_equivalent(cx, x); then { diff --git a/tests/ui/author/repeat.stdout b/tests/ui/author/repeat.stdout index f16350e4b5e6..471bbce4f418 100644 --- a/tests/ui/author/repeat.stdout +++ b/tests/ui/author/repeat.stdout @@ -2,7 +2,8 @@ if_chain! { if let ExprKind::Repeat(value, length) = expr.kind; if let ExprKind::Lit(ref lit) = value.kind; if let LitKind::Int(1, LitIntType::Unsigned(UintTy::U8)) = lit.node; - let expr1 = &cx.tcx.hir().body(length.body).value; + if let ArrayLen::Body(anon_const) = length; + let expr1 = &cx.tcx.hir().body(anon_const.body).value; if let ExprKind::Lit(ref lit1) = expr1.kind; if let LitKind::Int(5, LitIntType::Unsuffixed) = lit1.node; then { From 33f6a8134a14718635a10271dd885a3dabfc45ac Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 28 Dec 2021 16:19:23 +0100 Subject: [PATCH 0380/1222] Update pulldown-cmark version in clippy --- clippy_lints/Cargo.toml | 2 +- clippy_lints/src/doc.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 0661c2803864..7d2a3e4f639c 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -13,7 +13,7 @@ cargo_metadata = "0.14" clippy_utils = { path = "../clippy_utils" } if_chain = "1.0" itertools = "0.10" -pulldown-cmark = { version = "0.8", default-features = false } +pulldown-cmark = { version = "0.9", default-features = false } quine-mc_cluskey = "0.2" regex-syntax = "0.6" serde = { version = "1.0", features = ["derive"] } diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 3650e4f91a00..7c2717733578 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -542,16 +542,16 @@ fn check_doc<'a, Events: Iterator, Range in_link = Some(url), End(Link(..)) => in_link = None, - Start(Heading(_) | Paragraph | Item) => { - if let Start(Heading(_)) = event { + Start(Heading(_, _, _) | Paragraph | Item) => { + if let Start(Heading(_, _, _)) = event { in_heading = true; } ticks_unbalanced = false; let (_, span) = get_current_span(spans, range.start); paragraph_span = first_line_of_span(cx, span); }, - End(Heading(_) | Paragraph | Item) => { - if let End(Heading(_)) = event { + End(Heading(_, _, _) | Paragraph | Item) => { + if let End(Heading(_, _, _)) = event { in_heading = false; } if ticks_unbalanced { From 5b8d5860cfcd7e4bb9b46a4695c61582d4cbfe10 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 31 Dec 2021 21:13:07 -0800 Subject: [PATCH 0381/1222] Make tidy check for magic numbers that spell things Remove existing problematic cases. --- tests/ui/unreadable_literal.fixed | 2 +- tests/ui/unreadable_literal.rs | 2 +- tests/ui/unreadable_literal.stderr | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/ui/unreadable_literal.fixed b/tests/ui/unreadable_literal.fixed index c2e38037addd..e726b652ef1e 100644 --- a/tests/ui/unreadable_literal.fixed +++ b/tests/ui/unreadable_literal.fixed @@ -30,7 +30,7 @@ fn main() { 1_234.123_f32, 1.123_4_f32, ); - let _bad = (0b11_0110_i64, 0xcafe_babe_usize, 123_456_f32, 1.234_567_f32); + let _bad = (0b11_0110_i64, 0x1234_5678_usize, 123_456_f32, 1.234_567_f32); let _good_sci = 1.1234e1; let _bad_sci = 1.123_456e1; diff --git a/tests/ui/unreadable_literal.rs b/tests/ui/unreadable_literal.rs index 8296945b25eb..5bbb2fc9dc13 100644 --- a/tests/ui/unreadable_literal.rs +++ b/tests/ui/unreadable_literal.rs @@ -30,7 +30,7 @@ fn main() { 1_234.123_f32, 1.123_4_f32, ); - let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); + let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); let _good_sci = 1.1234e1; let _bad_sci = 1.123456e1; diff --git a/tests/ui/unreadable_literal.stderr b/tests/ui/unreadable_literal.stderr index 8436aac17acf..ee5466fd517f 100644 --- a/tests/ui/unreadable_literal.stderr +++ b/tests/ui/unreadable_literal.stderr @@ -9,7 +9,7 @@ LL | 0x1_234_567, error: long literal lacking separators --> $DIR/unreadable_literal.rs:33:17 | -LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); +LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^^^ help: consider: `0b11_0110_i64` | = note: `-D clippy::unreadable-literal` implied by `-D warnings` @@ -17,19 +17,19 @@ LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); error: long literal lacking separators --> $DIR/unreadable_literal.rs:33:31 | -LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); - | ^^^^^^^^^^^^^^^^ help: consider: `0xcafe_babe_usize` +LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); + | ^^^^^^^^^^^^^^^^ help: consider: `0x1234_5678_usize` error: long literal lacking separators --> $DIR/unreadable_literal.rs:33:49 | -LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); +LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^ help: consider: `123_456_f32` error: long literal lacking separators --> $DIR/unreadable_literal.rs:33:61 | -LL | let _bad = (0b110110_i64, 0xcafebabe_usize, 123456_f32, 1.234567_f32); +LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^^^ help: consider: `1.234_567_f32` error: long literal lacking separators From 60bfd7def3ed152579df0f0243a5da5d06f7e4a5 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Thu, 18 Nov 2021 22:33:49 +0000 Subject: [PATCH 0382/1222] Update clippy for associated item changes --- clippy_lints/src/len_zero.rs | 12 +++++++----- clippy_lints/src/non_copy_const.rs | 11 ++++++----- clippy_lints/src/use_self.rs | 7 +++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 20e6220ec7d3..64f6d62fbdcd 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -214,14 +214,14 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items { let mut current_and_super_traits = DefIdSet::default(); fill_trait_set(visited_trait.def_id.to_def_id(), &mut current_and_super_traits, cx); + let is_empty = sym!(is_empty); let is_empty_method_found = current_and_super_traits .iter() - .flat_map(|&i| cx.tcx.associated_items(i).in_definition_order()) + .flat_map(|&i| cx.tcx.associated_items(i).filter_by_name_unhygienic(is_empty)) .any(|i| { i.kind == ty::AssocKind::Fn && i.fn_has_self_parameter - && i.ident.name == sym!(is_empty) && cx.tcx.fn_sig(i.def_id).inputs().skip_binder().len() == 1 }); @@ -458,7 +458,7 @@ fn is_empty_array(expr: &Expr<'_>) -> bool { fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { /// Gets an `AssocItem` and return true if it matches `is_empty(self)`. fn is_is_empty(cx: &LateContext<'_>, item: &ty::AssocItem) -> bool { - if item.kind == ty::AssocKind::Fn && item.ident.name.as_str() == "is_empty" { + if item.kind == ty::AssocKind::Fn { let sig = cx.tcx.fn_sig(item.def_id); let ty = sig.skip_binder(); ty.inputs().len() == 1 @@ -469,10 +469,11 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { /// Checks the inherent impl's items for an `is_empty(self)` method. fn has_is_empty_impl(cx: &LateContext<'_>, id: DefId) -> bool { + let is_empty = sym!(is_empty); cx.tcx.inherent_impls(id).iter().any(|imp| { cx.tcx .associated_items(*imp) - .in_definition_order() + .filter_by_name_unhygienic(is_empty) .any(|item| is_is_empty(cx, item)) }) } @@ -480,9 +481,10 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let ty = &cx.typeck_results().expr_ty(expr).peel_refs(); match ty.kind() { ty::Dynamic(tt, ..) => tt.principal().map_or(false, |principal| { + let is_empty = sym!(is_empty); cx.tcx .associated_items(principal.def_id()) - .in_definition_order() + .filter_by_name_unhygienic(is_empty) .any(|item| is_is_empty(cx, item)) }), ty::Projection(ref proj) => has_is_empty_impl(cx, proj.item_def_id), diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 074ba9e92ba4..7d2ff083b7e0 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -12,11 +12,10 @@ use rustc_hir::def_id::DefId; use rustc_hir::{ BodyId, Expr, ExprKind, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind, UnOp, }; -use rustc_infer::traits::specialization_graph; use rustc_lint::{LateContext, LateLintPass, Lint}; use rustc_middle::mir::interpret::{ConstValue, ErrorHandled}; use rustc_middle::ty::adjustment::Adjust; -use rustc_middle::ty::{self, AssocKind, Const, Ty}; +use rustc_middle::ty::{self, Const, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{InnerSpan, Span, DUMMY_SP}; use rustc_typeck::hir_ty_to_ty; @@ -293,8 +292,10 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { // Lint a trait impl item only when the definition is a generic type, // assuming an assoc const is not meant to be an interior mutable type. if let Some(of_trait_def_id) = of_trait_ref.trait_def_id(); - if let Some(of_assoc_item) = specialization_graph::Node::Trait(of_trait_def_id) - .item(cx.tcx, impl_item.ident, AssocKind::Const, of_trait_def_id); + if let Some(of_assoc_item) = cx + .tcx + .associated_item(impl_item.def_id) + .trait_item_def_id; if cx .tcx .layout_of(cx.tcx.param_env(of_trait_def_id).and( @@ -303,7 +304,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { // and, in that case, the definition is *not* generic. cx.tcx.normalize_erasing_regions( cx.tcx.param_env(of_trait_def_id), - cx.tcx.type_of(of_assoc_item.def_id), + cx.tcx.type_of(of_assoc_item), ), )) .is_err(); diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 059f7f647f88..a86db58741eb 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -13,7 +13,6 @@ use rustc_hir::{ }; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::hir::map::Map; -use rustc_middle::ty::AssocKind; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; @@ -143,10 +142,10 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { // trait, not in the impl of the trait. let trait_method = cx .tcx - .associated_items(impl_trait_ref.def_id) - .find_by_name_and_kind(cx.tcx, impl_item.ident, AssocKind::Fn, impl_trait_ref.def_id) + .associated_item(impl_item.def_id) + .trait_item_def_id .expect("impl method matches a trait method"); - let trait_method_sig = cx.tcx.fn_sig(trait_method.def_id); + let trait_method_sig = cx.tcx.fn_sig(trait_method); let trait_method_sig = cx.tcx.erase_late_bound_regions(trait_method_sig); // `impl_inputs_outputs` is an iterator over the types (`hir::Ty`) declared in the From f2a03c5474910b943fb0fb2ac9cac197b112946c Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 9 Oct 2021 22:11:13 +0100 Subject: [PATCH 0383/1222] Remove span from UpvarCapture::ByValue This span is unused and is superseded by capture_kind_expr_id in CaptureInfo --- clippy_utils/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 9179e67c4f4e..5ce68bc4d1d5 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -969,7 +969,7 @@ pub fn can_move_expr_to_closure(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> }; if !self.locals.contains(&local_id) { let capture = match capture.info.capture_kind { - UpvarCapture::ByValue(_) => CaptureKind::Value, + UpvarCapture::ByValue => CaptureKind::Value, UpvarCapture::ByRef(borrow) => match borrow.kind { BorrowKind::ImmBorrow => CaptureKind::Ref(Mutability::Not), BorrowKind::UniqueImmBorrow | BorrowKind::MutBorrow => { From 00514cd46ff751cb20c6838533a8aac66816da65 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Wed, 13 Oct 2021 21:20:10 +0100 Subject: [PATCH 0384/1222] Remove region from UpvarCapture and move it to CapturedPlace Region info is completely unnecessary for upvar capture kind computation and is only needed to create the final upvar tuple ty. Doing so makes creation of UpvarCapture very cheap and expose further cleanup opportunity. --- clippy_utils/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 5ce68bc4d1d5..2a06cf121ff0 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -970,7 +970,7 @@ pub fn can_move_expr_to_closure(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> if !self.locals.contains(&local_id) { let capture = match capture.info.capture_kind { UpvarCapture::ByValue => CaptureKind::Value, - UpvarCapture::ByRef(borrow) => match borrow.kind { + UpvarCapture::ByRef(kind) => match kind { BorrowKind::ImmBorrow => CaptureKind::Ref(Mutability::Not), BorrowKind::UniqueImmBorrow | BorrowKind::MutBorrow => { CaptureKind::Ref(Mutability::Mut) From 720402f0e527566e7b25b398a216ab40b3ad21f0 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 18 Dec 2021 20:07:58 +0800 Subject: [PATCH 0385/1222] rustc_metadata: Optimize and document module children decoding --- clippy_utils/src/lib.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 9179e67c4f4e..bd6851d1fbba 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -82,7 +82,6 @@ use rustc_hir::{ TraitItemKind, TraitRef, TyKind, UnOp, ArrayLen }; use rustc_lint::{LateContext, Level, Lint, LintContext}; -use rustc_middle::hir::exports::Export; use rustc_middle::hir::map::Map; use rustc_middle::hir::place::PlaceBase; use rustc_middle::ty as rustc_ty; @@ -523,10 +522,21 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Res { } }; } - fn item_child_by_name<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, name: &str) -> Option<&'tcx Export> { - tcx.item_children(def_id) - .iter() - .find(|item| item.ident.name.as_str() == name) + fn item_child_by_name<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, name: &str) -> Option { + match tcx.def_kind(def_id) { + DefKind::Mod | DefKind::Enum | DefKind::Trait => tcx + .item_children(def_id) + .iter() + .find(|item| item.ident.name.as_str() == name) + .map(|child| child.res.expect_non_local()), + DefKind::Impl => tcx + .associated_item_def_ids(def_id) + .iter() + .copied() + .find(|assoc_def_id| tcx.item_name(*assoc_def_id).as_str() == name) + .map(|assoc_def_id| Res::Def(tcx.def_kind(assoc_def_id), assoc_def_id)), + _ => None, + } } let (krate, first, path) = match *path { @@ -543,15 +553,12 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Res { let last = path .iter() .copied() - // `get_def_path` seems to generate these empty segments for extern blocks. - // We can just ignore them. - .filter(|segment| !segment.is_empty()) // for each segment, find the child item - .try_fold(first, |item, segment| { - let def_id = item.res.def_id(); + .try_fold(first, |res, segment| { + let def_id = res.def_id(); if let Some(item) = item_child_by_name(tcx, def_id, segment) { Some(item) - } else if matches!(item.res, Res::Def(DefKind::Enum | DefKind::Struct, _)) { + } else if matches!(res, Res::Def(DefKind::Enum | DefKind::Struct, _)) { // it is not a child item so check inherent impl items tcx.inherent_impls(def_id) .iter() @@ -560,7 +567,7 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Res { None } }); - try_res!(last).res.expect_non_local() + try_res!(last).expect_non_local() } /// Convenience function to get the `DefId` of a trait by path. From bfbc7e79c6849c85a4d246d71ff7d0a449bef74a Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 23 Dec 2021 16:12:34 +0800 Subject: [PATCH 0386/1222] rustc_metadata: Rename `item_children(_untracked)` to `module_children(_untracked)` And `each_child_of_item` to `for_each_module_child` --- clippy_lints/src/macro_use.rs | 2 +- clippy_lints/src/utils/internal_lints.rs | 4 ++-- clippy_utils/src/lib.rs | 2 +- tests/ui/macro_use_imports.fixed | 2 +- tests/ui/macro_use_imports.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index 50d80e6a1d22..41f5a913b316 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports { if let Res::Def(DefKind::Mod, id) = path.res; if !id.is_local(); then { - for kid in cx.tcx.item_children(id).iter() { + for kid in cx.tcx.module_children(id).iter() { if let Res::Def(DefKind::Macro(_mac_type), mac_id) = kid.res { let span = mac_attr.span; let def_path = cx.tcx.def_path_str(mac_id); diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index e98dcd3cf983..7d196af7a53f 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -924,7 +924,7 @@ pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool { let lang_item_path = cx.get_def_path(*item_def_id); if path_syms.starts_with(&lang_item_path) { if let [item] = &path_syms[lang_item_path.len()..] { - for child in cx.tcx.item_children(*item_def_id) { + for child in cx.tcx.module_children(*item_def_id) { if child.ident.name == *item { return true; } @@ -984,7 +984,7 @@ impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol { for &module in &[&paths::KW_MODULE, &paths::SYM_MODULE] { if let Some(def_id) = path_to_res(cx, module).opt_def_id() { - for item in cx.tcx.item_children(def_id).iter() { + for item in cx.tcx.module_children(def_id).iter() { if_chain! { if let Res::Def(DefKind::Const, item_def_id) = item.res; let ty = cx.tcx.type_of(item_def_id); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index bd6851d1fbba..91ebc7ea89cc 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -525,7 +525,7 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Res { fn item_child_by_name<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, name: &str) -> Option { match tcx.def_kind(def_id) { DefKind::Mod | DefKind::Enum | DefKind::Trait => tcx - .item_children(def_id) + .module_children(def_id) .iter() .find(|item| item.ident.name.as_str() == name) .map(|child| child.res.expect_non_local()), diff --git a/tests/ui/macro_use_imports.fixed b/tests/ui/macro_use_imports.fixed index 9171558f3a2d..306ea50258da 100644 --- a/tests/ui/macro_use_imports.fixed +++ b/tests/ui/macro_use_imports.fixed @@ -40,7 +40,7 @@ mod a { } } -// issue #7015, ICE due to calling `item_children` with local `DefId` +// issue #7015, ICE due to calling `module_children` with local `DefId` #[macro_use] use a as b; diff --git a/tests/ui/macro_use_imports.rs b/tests/ui/macro_use_imports.rs index cd01fd43f6d3..e26a7545ea6f 100644 --- a/tests/ui/macro_use_imports.rs +++ b/tests/ui/macro_use_imports.rs @@ -40,7 +40,7 @@ mod a { } } -// issue #7015, ICE due to calling `item_children` with local `DefId` +// issue #7015, ICE due to calling `module_children` with local `DefId` #[macro_use] use a as b; From b9bb630ea3636a41614e6b081a1935e7ef21029a Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 10 Jan 2022 11:34:07 -0800 Subject: [PATCH 0387/1222] Update rayon and rustc-rayon --- lintcheck/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lintcheck/Cargo.toml b/lintcheck/Cargo.toml index f33f1b65eabd..c694037021a5 100644 --- a/lintcheck/Cargo.toml +++ b/lintcheck/Cargo.toml @@ -13,7 +13,7 @@ publish = false clap = "2.33" flate2 = "1.0" fs_extra = "1.2" -rayon = "1.5" +rayon = "1.5.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" tar = "0.4" From ba40d0263f08711e2c511260466bb2e919eb4d8d Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sun, 2 Jan 2022 22:37:05 -0500 Subject: [PATCH 0388/1222] Store a `Symbol` instead of an `Ident` in `VariantDef`/`FieldDef` The field is also renamed from `ident` to `name. In most cases, we don't actually need the `Span`. A new `ident` method is added to `VariantDef` and `FieldDef`, which constructs the full `Ident` using `tcx.def_ident_span()`. This method is used in the cases where we actually need an `Ident`. This makes incremental compilation properly track changes to the `Span`, without all of the invalidations caused by storing a `Span` directly via an `Ident`. --- clippy_lints/src/default.rs | 2 +- clippy_lints/src/default_numeric_fallback.rs | 2 +- clippy_lints/src/inconsistent_struct_constructor.rs | 2 +- clippy_lints/src/matches.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index a0b137efe221..6422f5aabe5e 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -198,7 +198,7 @@ impl LateLintPass<'_> for Default { let ext_with_default = !variant .fields .iter() - .all(|field| assigned_fields.iter().any(|(a, _)| a == &field.ident.name)); + .all(|field| assigned_fields.iter().any(|(a, _)| a == &field.name)); let field_list = assigned_fields .into_iter() diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index 3573ea5f0267..15215ac15cdb 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -161,7 +161,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { fields_def .iter() .find_map(|f_def| { - if f_def.ident == field.ident + if f_def.ident(self.cx.tcx) == field.ident { Some(self.cx.tcx.type_of(f_def.did)) } else { None } }); diff --git a/clippy_lints/src/inconsistent_struct_constructor.rs b/clippy_lints/src/inconsistent_struct_constructor.rs index 1debdef9d86c..388bb3727f96 100644 --- a/clippy_lints/src/inconsistent_struct_constructor.rs +++ b/clippy_lints/src/inconsistent_struct_constructor.rs @@ -76,7 +76,7 @@ impl LateLintPass<'_> for InconsistentStructConstructor { then { let mut def_order_map = FxHashMap::default(); for (idx, field) in variant.fields.iter().enumerate() { - def_order_map.insert(field.ident.name, idx); + def_order_map.insert(field.name, idx); } if is_consistent_order(fields, &def_order_map) { diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 22970507f964..5fa8f249e701 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -1136,7 +1136,7 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) s.push_str("::"); s }, - variant.ident.name, + variant.name, match variant.ctor_kind { CtorKind::Fn if variant.fields.len() == 1 => "(_)", CtorKind::Fn => "(..)", From 04dd676ed5b0541bdb19484195ea928335bcb6ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Wed, 12 Jan 2022 00:00:00 +0000 Subject: [PATCH 0389/1222] Remove LLVM-style inline assembly from clippy --- clippy_lints/src/dereference.rs | 1 - clippy_lints/src/entry.rs | 2 +- clippy_lints/src/loops/never_loop.rs | 1 - clippy_lints/src/suspicious_operation_groupings.rs | 1 - clippy_lints/src/utils/author.rs | 4 ---- clippy_lints/src/utils/inspector.rs | 13 ------------- clippy_utils/src/eager_or_lazy.rs | 1 - clippy_utils/src/hir_utils.rs | 2 +- clippy_utils/src/lib.rs | 3 +-- clippy_utils/src/qualify_min_const_fn.rs | 2 -- clippy_utils/src/sugg.rs | 2 -- 11 files changed, 3 insertions(+), 29 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index fa2b348591be..7319e95b0ac6 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -449,7 +449,6 @@ fn is_linted_explicit_deref_position(parent: Option>, child_id: HirId, | ExprKind::Continue(..) | ExprKind::Ret(..) | ExprKind::InlineAsm(..) - | ExprKind::LlvmInlineAsm(..) | ExprKind::Struct(..) | ExprKind::Repeat(..) | ExprKind::Yield(..) => true, diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 3d92eb16870e..b51496641b6c 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -504,7 +504,7 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> { self.loops.pop(); }, ExprKind::Block(block, _) => self.visit_block(block), - ExprKind::InlineAsm(_) | ExprKind::LlvmInlineAsm(_) => { + ExprKind::InlineAsm(_) => { self.can_use_entry = false; }, _ => { diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index a3aa6be6afd6..55ff54b2e12d 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -181,7 +181,6 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { ExprKind::Struct(_, _, None) | ExprKind::Yield(_, _) | ExprKind::Closure(_, _, _, _, _) - | ExprKind::LlvmInlineAsm(_) | ExprKind::Path(_) | ExprKind::ConstBlock(_) | ExprKind::Lit(_) diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index faf43fd9fc1a..613b6976a13c 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -567,7 +567,6 @@ fn ident_difference_expr_with_base_location( | (Repeat(_, _), Repeat(_, _)) | (Struct(_), Struct(_)) | (MacCall(_), MacCall(_)) - | (LlvmInlineAsm(_), LlvmInlineAsm(_)) | (InlineAsm(_), InlineAsm(_)) | (Ret(_), Ret(_)) | (Continue(_), Continue(_)) diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 9b06ca4e8249..b0085da2206b 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -547,10 +547,6 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { kind!("InlineAsm(_)"); out!("// unimplemented: `ExprKind::InlineAsm` is not further destructured at the moment"); }, - ExprKind::LlvmInlineAsm(_) => { - kind!("LlvmInlineAsm(_)"); - out!("// unimplemented: `ExprKind::LlvmInlineAsm` is not further destructured at the moment"); - }, ExprKind::Struct(qpath, fields, base) => { bind!(self, qpath, fields); opt_bind!(self, base); diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index c96766e56784..fd3e51c2b32c 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -304,19 +304,6 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { } } }, - hir::ExprKind::LlvmInlineAsm(asm) => { - let inputs = &asm.inputs_exprs; - let outputs = &asm.outputs_exprs; - println!("{}LlvmInlineAsm", ind); - println!("{}inputs:", ind); - for e in inputs.iter() { - print_expr(cx, e, indent + 1); - } - println!("{}outputs:", ind); - for e in outputs.iter() { - print_expr(cx, e, indent + 1); - } - }, hir::ExprKind::Struct(path, fields, ref base) => { println!("{}Struct", ind); println!("{}path: {:?}", ind, path); diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 61e529a6079c..fd18ba8842fb 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -175,7 +175,6 @@ fn expr_eagerness(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessSuggest | ExprKind::Continue(_) | ExprKind::Ret(_) | ExprKind::InlineAsm(_) - | ExprKind::LlvmInlineAsm(_) | ExprKind::Yield(..) | ExprKind::Err => { self.eagerness = ForceNoChange; diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index ac2b1a0259e3..c4f19f6d966c 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -685,7 +685,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } self.hash_pat(pat); }, - ExprKind::LlvmInlineAsm(..) | ExprKind::Err => {}, + ExprKind::Err => {}, ExprKind::Lit(ref l) => { l.node.hash(&mut self.s); }, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 91ebc7ea89cc..79219ce19ac3 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -777,8 +777,7 @@ pub fn can_move_expr_to_closure_no_visit( | ExprKind::Continue(_) | ExprKind::Ret(_) | ExprKind::Yield(..) - | ExprKind::InlineAsm(_) - | ExprKind::LlvmInlineAsm(_) => false, + | ExprKind::InlineAsm(_) => false, // Accessing a field of a local value can only be done if the type isn't // partially moved. ExprKind::Field( diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 836558b07cb0..5cf33155cd2e 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -222,8 +222,6 @@ fn check_statement(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, statemen // just an assignment StatementKind::SetDiscriminant { place, .. } => check_place(tcx, **place, span, body), - StatementKind::LlvmInlineAsm { .. } => Err((span, "cannot use inline assembly in const fn".into())), - StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping { dst, src, count }) => { check_operand(tcx, dst, span, body)?; check_operand(tcx, src, span, body)?; diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 92662c59226a..cedc16dea31f 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -147,7 +147,6 @@ impl<'a> Sugg<'a> { | hir::ExprKind::Field(..) | hir::ExprKind::Index(..) | hir::ExprKind::InlineAsm(..) - | hir::ExprKind::LlvmInlineAsm(..) | hir::ExprKind::ConstBlock(..) | hir::ExprKind::Lit(..) | hir::ExprKind::Loop(..) @@ -205,7 +204,6 @@ impl<'a> Sugg<'a> { | ast::ExprKind::ForLoop(..) | ast::ExprKind::Index(..) | ast::ExprKind::InlineAsm(..) - | ast::ExprKind::LlvmInlineAsm(..) | ast::ExprKind::ConstBlock(..) | ast::ExprKind::Lit(..) | ast::ExprKind::Loop(..) From ab1ceba3e9ed8cf5dc0bf70cd15ead4aeecb77f3 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 13 Jan 2022 13:37:24 +0100 Subject: [PATCH 0390/1222] Fix Clippy sync fallout --- clippy_utils/src/macros.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs index a3e336d701ca..b7a242cf90a4 100644 --- a/clippy_utils/src/macros.rs +++ b/clippy_utils/src/macros.rs @@ -191,13 +191,13 @@ impl<'a> PanicExpn<'a> { if !macro_backtrace(expr.span).any(|macro_call| is_panic(cx, macro_call.def_id)) { return None; } - let ExprKind::Call(callee, [arg]) = expr.kind else { return None }; - let ExprKind::Path(QPath::Resolved(_, path)) = callee.kind else { return None }; + let ExprKind::Call(callee, [arg]) = &expr.kind else { return None }; + let ExprKind::Path(QPath::Resolved(_, path)) = &callee.kind else { return None }; let result = match path.segments.last().unwrap().ident.as_str() { "panic" if arg.span.ctxt() == expr.span.ctxt() => Self::Empty, "panic" | "panic_str" => Self::Str(arg), "panic_display" => { - let ExprKind::AddrOf(_, _, e) = arg.kind else { return None }; + let ExprKind::AddrOf(_, _, e) = &arg.kind else { return None }; Self::Display(e) }, "panic_fmt" => Self::Format(FormatArgsExpn::parse(cx, arg)?), From 13fb81173b08b418aa4698387135fe25cbcd5ac1 Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 12 Jan 2022 03:19:52 +0000 Subject: [PATCH 0391/1222] initial revert --- clippy_lints/src/escape.rs | 5 ++--- clippy_lints/src/let_underscore.rs | 2 +- clippy_lints/src/loops/same_item_push.rs | 2 +- clippy_lints/src/methods/mod.rs | 10 +++++----- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/non_copy_const.rs | 6 +++++- clippy_lints/src/non_send_fields_in_send_ty.rs | 8 ++++---- clippy_lints/src/redundant_clone.rs | 15 ++++++--------- clippy_lints/src/returns.rs | 2 +- clippy_lints/src/self_named_constructors.rs | 4 ++-- clippy_lints/src/unnecessary_sort_by.rs | 2 +- clippy_lints/src/use_self.rs | 2 +- clippy_utils/src/consts.rs | 6 +++++- clippy_utils/src/lib.rs | 6 +++--- clippy_utils/src/qualify_min_const_fn.rs | 2 +- clippy_utils/src/ty.rs | 10 +++++----- 16 files changed, 44 insertions(+), 40 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index bc5d2f6278de..336d098799ac 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -54,7 +54,7 @@ fn is_non_trait_box(ty: Ty<'_>) -> bool { struct EscapeDelegate<'a, 'tcx> { cx: &'a LateContext<'tcx>, set: HirIdSet, - trait_self_ty: Option>, + trait_self_ty: Option>, too_large_for_stack: u64, } @@ -175,8 +175,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { // skip if there is a `self` parameter binding to a type // that contains `Self` (i.e.: `self: Box`), see #4804 if let Some(trait_self_ty) = self.trait_self_ty { - if map.name(cmt.hir_id) == kw::SelfLower && contains_ty(self.cx.tcx, cmt.place.ty(), trait_self_ty) - { + if map.name(cmt.hir_id) == kw::SelfLower && contains_ty(cmt.place.ty(), trait_self_ty) { return; } } diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index d03276f7f98b..cb1ef01f5ba9 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -124,7 +124,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore { if let Some(init) = local.init; then { let init_ty = cx.typeck_results().expr_ty(init); - let contains_sync_guard = init_ty.walk(cx.tcx).any(|inner| match inner.unpack() { + let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() { GenericArgKind::Type(inner_ty) => { SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path)) }, diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index 2eb247de9f42..ab83291461fb 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -49,7 +49,7 @@ pub(super) fn check<'tcx>( if same_item_push_visitor.should_lint(); if let Some((vec, pushed_item)) = same_item_push_visitor.vec_push; let vec_ty = cx.typeck_results().expr_ty(vec); - let ty = vec_ty.walk(cx.tcx).nth(1).unwrap().expect_ty(); + let ty = vec_ty.walk().nth(1).unwrap().expect_ty(); if cx .tcx .lang_items() diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 1041f644e32e..a13b15518612 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2129,10 +2129,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods { // walk the return type and check for Self (this does not check associated types) if let Some(self_adt) = self_ty.ty_adt_def() { - if contains_adt_constructor(cx.tcx, ret_ty, self_adt) { + if contains_adt_constructor(ret_ty, self_adt) { return; } - } else if contains_ty(cx.tcx, ret_ty, self_ty) { + } else if contains_ty(ret_ty, self_ty) { return; } @@ -2143,10 +2143,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() { // walk the associated type and check for Self if let Some(self_adt) = self_ty.ty_adt_def() { - if contains_adt_constructor(cx.tcx, projection_predicate.ty, self_adt) { + if contains_adt_constructor(projection_predicate.ty, self_adt) { return; } - } else if contains_ty(cx.tcx, projection_predicate.ty, self_ty) { + } else if contains_ty(projection_predicate.ty, self_ty) { return; } } @@ -2195,7 +2195,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let TraitItemKind::Fn(_, _) = item.kind; let ret_ty = return_ty(cx, item.hir_id()); let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty().skip_binder(); - if !contains_ty(cx.tcx, ret_ty, self_ty); + if !contains_ty(ret_ty, self_ty); then { span_lint( diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 35877d51c0c1..ebd4fb0bf51c 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -118,7 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { let fn_def_id = cx.tcx.hir().local_def_id(hir_id); let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds().iter()) - .filter(|p| !p.is_global(cx.tcx)) + .filter(|p| !p.is_global()) .filter_map(|obligation| { // Note that we do not want to deal with qualified predicates here. match obligation.predicate.kind().no_bound_vars() { diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 7d2ff083b7e0..88e5f5366b62 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -188,7 +188,11 @@ fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: D let result = cx.tcx.const_eval_resolve( cx.param_env, - ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), + ty::Unevaluated { + def: ty::WithOptConstParam::unknown(def_id), + substs, + promoted: None, + }, None, ); is_value_unfrozen_raw(cx, result, ty) diff --git a/clippy_lints/src/non_send_fields_in_send_ty.rs b/clippy_lints/src/non_send_fields_in_send_ty.rs index 203f03d3603c..ab1559c85d8b 100644 --- a/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy { non_send_fields.push(NonSendField { def: field_def, ty: field_ty, - generic_params: collect_generic_params(cx, field_ty), + generic_params: collect_generic_params(field_ty), }) } } @@ -171,8 +171,8 @@ impl<'tcx> NonSendField<'tcx> { /// Given a type, collect all of its generic parameters. /// Example: `MyStruct>` => `vec![P, Q, R]` -fn collect_generic_params<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Vec> { - ty.walk(cx.tcx) +fn collect_generic_params(ty: Ty<'_>) -> Vec> { + ty.walk() .filter_map(|inner| match inner.unpack() { GenericArgKind::Type(inner_ty) => Some(inner_ty), _ => None, @@ -226,7 +226,7 @@ fn ty_allowed_with_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t /// Checks if the type contains any pointer-like types in substs (including nested ones) fn contains_pointer_like<'tcx>(cx: &LateContext<'tcx>, target_ty: Ty<'tcx>) -> bool { - for ty_node in target_ty.walk(cx.tcx) { + for ty_node in target_ty.walk() { if let GenericArgKind::Type(inner_ty) = ty_node.unpack() { match inner_ty.kind() { ty::RawPtr(_) => { diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 1991a01fb60b..dce1f66107a6 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -14,7 +14,7 @@ use rustc_middle::mir::{ visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor as _}, Mutability, }; -use rustc_middle::ty::{self, fold::TypeVisitor, Ty, TyCtxt}; +use rustc_middle::ty::{self, fold::TypeVisitor, Ty}; use rustc_mir_dataflow::{Analysis, AnalysisDomain, CallReturnPlaces, GenKill, GenKillAnalysis, ResultsCursor}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::{BytePos, Span}; @@ -575,7 +575,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { self.possible_borrower.add(borrowed.local, lhs); }, other => { - if ContainsRegion(self.cx.tcx) + if ContainsRegion .visit_ty(place.ty(&self.body.local_decls, self.cx.tcx).ty) .is_continue() { @@ -624,7 +624,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { .flat_map(HybridBitSet::iter) .collect(); - if ContainsRegion(self.cx.tcx) + if ContainsRegion .visit_ty(self.body.local_decls[*dest].ty) .is_break() { @@ -703,15 +703,12 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleOriginVisitor<'a, 'tcx> { } } -struct ContainsRegion<'tcx>(TyCtxt<'tcx>); +struct ContainsRegion; -impl<'tcx> TypeVisitor<'tcx> for ContainsRegion<'tcx> { +impl TypeVisitor<'_> for ContainsRegion { type BreakTy = (); - fn tcx_for_anon_const_substs(&self) -> Option> { - Some(self.0) - } - fn visit_region(&mut self, _: ty::Region<'tcx>) -> ControlFlow { + fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow { ControlFlow::BREAK } } diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 112ccdcdd420..52e708f628a2 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -301,7 +301,7 @@ impl<'tcx> Visitor<'tcx> for BorrowVisitor<'_, 'tcx> { .fn_sig(def_id) .output() .skip_binder() - .walk(self.cx.tcx) + .walk() .any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_))); } diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index d386663e4985..9516a1ee8726 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -63,10 +63,10 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { // Ensure method is constructor-like if let Some(self_adt) = self_ty.ty_adt_def() { - if !contains_adt_constructor(cx.tcx, ret_ty, self_adt) { + if !contains_adt_constructor(ret_ty, self_adt) { return; } - } else if !contains_ty(cx.tcx, ret_ty, self_ty) { + } else if !contains_ty(ret_ty, self_ty) { return; } diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index d024577f4853..32adccdbd1ce 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -226,7 +226,7 @@ fn expr_borrows(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let ty = cx.typeck_results().expr_ty(expr); matches!(ty.kind(), ty::Ref(..)) || ty - .walk(cx.tcx) + .walk() .any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_))) } diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index a86db58741eb..cf9a4a5e6d37 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -170,7 +170,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { // // See also https://github.com/rust-lang/rust-clippy/issues/2894. for (impl_hir_ty, trait_sem_ty) in impl_inputs_outputs.zip(trait_method_sig.inputs_and_output) { - if trait_sem_ty.walk(cx.tcx).any(|inner| inner == self_ty.into()) { + if trait_sem_ty.walk().any(|inner| inner == self_ty.into()) { let mut visitor = SkipTyCollector::default(); visitor.visit_ty(impl_hir_ty); types_to_skip.extend(visitor.types_to_skip); diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 34c5af848a6d..d8f04d0284f1 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -413,7 +413,11 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { .tcx .const_eval_resolve( self.param_env, - ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), + ty::Unevaluated { + def: ty::WithOptConstParam::unknown(def_id), + substs, + promoted: None, + }, None, ) .ok() diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 57183b58b2a1..e89c218e2fa6 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1956,7 +1956,7 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool { .predicates_of(did) .predicates .iter() - .filter_map(|(p, _)| if p.is_global(cx.tcx) { Some(*p) } else { None }); + .filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None }); traits::impossible_predicates( cx.tcx, traits::elaborate_predicates(cx.tcx, predicates) @@ -2002,7 +2002,7 @@ pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option return Some("slice".into()), rustc_ty::Array(..) => return Some("array".into()), rustc_ty::Tuple(..) => return Some("tuple".into()), @@ -2010,7 +2010,7 @@ pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: } fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult { - for arg in ty.walk(tcx) { + for arg in ty.walk() { let ty = match arg.unpack() { GenericArgKind::Type(ty) => ty, diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 72317447159a..f109b7845b4b 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -37,8 +37,8 @@ pub fn can_partially_move_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool } /// Walks into `ty` and returns `true` if any inner type is the same as `other_ty` -pub fn contains_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, other_ty: Ty<'tcx>) -> bool { - ty.walk(tcx).any(|inner| match inner.unpack() { +pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool { + ty.walk().any(|inner| match inner.unpack() { GenericArgKind::Type(inner_ty) => ty::TyS::same_type(other_ty, inner_ty), GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false, }) @@ -46,8 +46,8 @@ pub fn contains_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, other_ty: Ty<'tcx>) -> /// Walks into `ty` and returns `true` if any inner type is an instance of the given adt /// constructor. -pub fn contains_adt_constructor<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, adt: &'tcx AdtDef) -> bool { - ty.walk(tcx).any(|inner| match inner.unpack() { +pub fn contains_adt_constructor(ty: Ty<'_>, adt: &AdtDef) -> bool { + ty.walk().any(|inner| match inner.unpack() { GenericArgKind::Type(inner_ty) => inner_ty.ty_adt_def() == Some(adt), GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false, }) @@ -221,7 +221,7 @@ fn is_normalizable_helper<'tcx>( .iter() .all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache)) }), - _ => ty.walk(cx.tcx).all(|generic_arg| match generic_arg.unpack() { + _ => ty.walk().all(|generic_arg| match generic_arg.unpack() { GenericArgKind::Type(inner_ty) if inner_ty != ty => { is_normalizable_helper(cx, param_env, inner_ty, cache) }, From d652812a804340185bb04effcfc23dc56d7ca450 Mon Sep 17 00:00:00 2001 From: Ellen Date: Thu, 13 Jan 2022 09:26:27 +0000 Subject: [PATCH 0392/1222] nyahggdshjjghsdfhgsf --- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/non_copy_const.rs | 7 +++---- clippy_utils/src/consts.rs | 7 +++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 336d098799ac..d6e2bb806887 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -54,7 +54,7 @@ fn is_non_trait_box(ty: Ty<'_>) -> bool { struct EscapeDelegate<'a, 'tcx> { cx: &'a LateContext<'tcx>, set: HirIdSet, - trait_self_ty: Option>, + trait_self_ty: Option>, too_large_for_stack: u64, } diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 88e5f5366b62..435f3071c809 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -188,11 +188,10 @@ fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: D let result = cx.tcx.const_eval_resolve( cx.param_env, - ty::Unevaluated { - def: ty::WithOptConstParam::unknown(def_id), + ty::Unevaluated::new( + ty::WithOptConstParam::unknown(def_id), substs, - promoted: None, - }, + ), None, ); is_value_unfrozen_raw(cx, result, ty) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index d8f04d0284f1..e09a663538dd 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -413,11 +413,10 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { .tcx .const_eval_resolve( self.param_env, - ty::Unevaluated { - def: ty::WithOptConstParam::unknown(def_id), + ty::Unevaluated::new( + ty::WithOptConstParam::unknown(def_id), substs, - promoted: None, - }, + ), None, ) .ok() From 2e3752d0219d4ec510139f64f7bcb077256ab796 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 21 Oct 2021 19:41:47 +0200 Subject: [PATCH 0393/1222] Return a LocalDefId in get_parent_item. --- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/exit.rs | 5 ++--- clippy_lints/src/functions/must_use.rs | 2 +- clippy_lints/src/functions/result_unit_err.rs | 2 +- clippy_lints/src/inherent_to_string.rs | 2 +- clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/loops/needless_range_loop.rs | 6 ++---- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/missing_const_for_fn.rs | 2 +- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/new_without_default.rs | 2 +- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/ptr.rs | 2 +- clippy_lints/src/self_named_constructors.rs | 2 +- clippy_lints/src/suspicious_trait_impl.rs | 2 +- clippy_lints/src/types/mod.rs | 14 +++++++------- clippy_lints/src/unused_self.rs | 2 +- clippy_lints/src/zero_sized_map_values.rs | 6 +++++- clippy_utils/src/lib.rs | 19 +++++++++---------- 19 files changed, 39 insertions(+), 39 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index bc5d2f6278de..5f95333a7740 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { } let parent_id = cx.tcx.hir().get_parent_item(hir_id); - let parent_node = cx.tcx.hir().find(parent_id); + let parent_node = cx.tcx.hir().find_by_def_id(parent_id); let mut trait_self_ty = None; if let Some(Node::Item(item)) = parent_node { diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index d64cc61916c5..cbf52d19334c 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -34,11 +34,10 @@ impl<'tcx> LateLintPass<'tcx> for Exit { if let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::EXIT); let parent = cx.tcx.hir().get_parent_item(e.hir_id); - if let Some(Node::Item(Item{kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find(parent); + if let Some(Node::Item(Item{kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find_by_def_id(parent); // If the next item up is a function we check if it is an entry point // and only then emit a linter warning - let def_id = cx.tcx.hir().local_def_id(parent); - if !is_entrypoint_fn(cx, def_id.to_def_id()); + if !is_entrypoint_fn(cx, parent.to_def_id()); then { span_lint(cx, EXIT, e.span, "usage of `process::exit`"); } diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index f2b4aefaead5..bf59103e3f4d 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -48,7 +48,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp let attr = must_use_attr(attrs); if let Some(attr) = attr { check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr); - } else if is_public && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.hir_id()).is_none() { + } else if is_public && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.def_id).is_none() { check_must_use_candidate( cx, sig.decl, diff --git a/clippy_lints/src/functions/result_unit_err.rs b/clippy_lints/src/functions/result_unit_err.rs index 73f08a049897..120fcb2619c7 100644 --- a/clippy_lints/src/functions/result_unit_err.rs +++ b/clippy_lints/src/functions/result_unit_err.rs @@ -27,7 +27,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, item: &hir::ImplItem<'_>) { if let hir::ImplItemKind::Fn(ref sig, _) = item.kind { let is_public = cx.access_levels.is_exported(item.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); - if is_public && trait_ref_of_method(cx, item.hir_id()).is_none() { + if is_public && trait_ref_of_method(cx, item.def_id).is_none() { check_result_unit_err(cx, sig.decl, item.span, fn_header_span); } } diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index 60d234cd6f08..55c04a1186fc 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -116,7 +116,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString { if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::String); // Filters instances of to_string which are required by a trait - if trait_ref_of_method(cx, impl_item.hir_id()).is_none(); + if trait_ref_of_method(cx, impl_item.def_id).is_none(); then { show_lint(cx, impl_item); diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 0e2b78609c2c..6dd7b22ff94b 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { if let ImplItemKind::Fn(ref sig, id) = item.kind { - let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id()).is_none(); + let report_extra_lifetimes = trait_ref_of_method(cx, item.def_id).is_none(); check_fn_inner( cx, sig.decl, diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 172d9fc39a29..33abd2a72d88 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -58,8 +58,7 @@ pub(super) fn check<'tcx>( // ensure that the indexed variable was declared before the loop, see #601 if let Some(indexed_extent) = indexed_extent { - let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id); - let parent_def_id = cx.tcx.hir().local_def_id(parent_id); + let parent_def_id = cx.tcx.hir().get_parent_item(expr.hir_id); let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id); let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id); if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) { @@ -263,8 +262,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { let res = self.cx.qpath_res(seqpath, seqexpr.hir_id); match res { Res::Local(hir_id) => { - let parent_id = self.cx.tcx.hir().get_parent_item(expr.hir_id); - let parent_def_id = self.cx.tcx.hir().local_def_id(parent_id); + let parent_def_id = self.cx.tcx.hir().get_parent_item(expr.hir_id); let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id); if index_used_directly { self.indexed_directly.insert( diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 1041f644e32e..cd038ecd5ce1 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2053,7 +2053,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { return; } let name = impl_item.ident.name.as_str(); - let parent = cx.tcx.hir().get_parent_did(impl_item.hir_id()); + let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); let item = cx.tcx.hir().expect_item(parent); let self_ty = cx.tcx.type_of(item.def_id); diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index a8d410508563..77849e1800f6 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -121,7 +121,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { } }, FnKind::Method(_, sig, ..) => { - if trait_ref_of_method(cx, hir_id).is_some() + if trait_ref_of_method(cx, def_id).is_some() || already_const(sig.header) || method_accepts_dropable(cx, sig.decl.inputs) { diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 5fe887a4573c..1bdd805f6585 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'tcx>) { if let hir::ImplItemKind::Fn(ref sig, ..) = item.kind { - if trait_ref_of_method(cx, item.hir_id()).is_none() { + if trait_ref_of_method(cx, item.def_id).is_none() { check_sig(cx, item.hir_id(), sig.decl); } } diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index f0c0c89ca8f3..aec95530bba6 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -101,7 +101,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { if sig.decl.inputs.is_empty(); if name == sym::new; if cx.access_levels.is_reachable(impl_item.def_id); - let self_def_id = cx.tcx.hir().local_def_id(cx.tcx.hir().get_parent_item(id)); + let self_def_id = cx.tcx.hir().get_parent_item(id); let self_ty = cx.tcx.type_of(self_def_id); if TyS::same_type(self_ty, return_ty(cx, id)); if let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default); diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 7d2ff083b7e0..21ac6548b017 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -280,7 +280,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { if let ImplItemKind::Const(hir_ty, body_id) = &impl_item.kind { - let item_def_id = cx.tcx.hir().get_parent_did(impl_item.hir_id()); + let item_def_id = cx.tcx.hir().get_parent_item(impl_item.hir_id()); let item = cx.tcx.hir().expect_item(item_def_id); match &item.kind { diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index c08a19d520b6..63de117a6f1d 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -164,7 +164,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { if let ImplItemKind::Fn(ref sig, body_id) = item.kind { let parent_item = cx.tcx.hir().get_parent_item(item.hir_id()); - if let Some(Node::Item(it)) = cx.tcx.hir().find(parent_item) { + if let Some(Node::Item(it)) = cx.tcx.hir().find_by_def_id(parent_item) { if let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = it.kind { return; // ignore trait impls } diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index d386663e4985..9673d975cb4d 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -51,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { _ => return, } - let parent = cx.tcx.hir().get_parent_did(impl_item.hir_id()); + let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); let item = cx.tcx.hir().expect_item(parent); let self_ty = cx.tcx.type_of(item.def_id); let ret_ty = return_ty(cx, impl_item.hir_id()); diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index a3195de81d15..92494159deeb 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl { // Check for more than one binary operation in the implemented function // Linting when multiple operations are involved can result in false positives let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id); - if let hir::Node::ImplItem(impl_item) = cx.tcx.hir().get(parent_fn); + if let hir::Node::ImplItem(impl_item) = cx.tcx.hir().get_by_def_id(parent_fn); if let hir::ImplItemKind::Fn(_, body_id) = impl_item.kind; let body = cx.tcx.hir().body(body_id); let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id); diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 9d57505e55ed..67cc89133189 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -312,12 +312,12 @@ impl_lint_pass!(Types => [BOX_COLLECTION, VEC_BOX, OPTION_OPTION, LINKEDLIST, BO impl<'tcx> LateLintPass<'tcx> for Types { fn check_fn(&mut self, cx: &LateContext<'_>, _: FnKind<'_>, decl: &FnDecl<'_>, _: &Body<'_>, _: Span, id: HirId) { - let is_in_trait_impl = if let Some(hir::Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_item(id)) - { - matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) - } else { - false - }; + let is_in_trait_impl = + if let Some(hir::Node::Item(item)) = cx.tcx.hir().find_by_def_id(cx.tcx.hir().get_parent_item(id)) { + matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) + } else { + false + }; let is_exported = cx.access_levels.is_exported(cx.tcx.hir().local_def_id(id)); @@ -353,7 +353,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { match item.kind { ImplItemKind::Const(ty, _) => { let is_in_trait_impl = if let Some(hir::Node::Item(item)) = - cx.tcx.hir().find(cx.tcx.hir().get_parent_item(item.hir_id())) + cx.tcx.hir().find_by_def_id(cx.tcx.hir().get_parent_item(item.hir_id())) { matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) } else { diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index aa105580ee35..fd9d5b52e501 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -42,7 +42,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf { if impl_item.span.from_expansion() { return; } - let parent = cx.tcx.hir().get_parent_did(impl_item.hir_id()); + let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); let parent_item = cx.tcx.hir().expect_item(parent); let assoc_item = cx.tcx.associated_item(impl_item.def_id); if_chain! { diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index eb8436a501d5..70b0560e6760 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -69,7 +69,11 @@ impl LateLintPass<'_> for ZeroSizedMapValues { fn in_trait_impl(cx: &LateContext<'_>, hir_id: HirId) -> bool { let parent_id = cx.tcx.hir().get_parent_item(hir_id); - if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_item(parent_id)) { + let second_parent_id = cx + .tcx + .hir() + .get_parent_item(cx.tcx.hir().local_def_id_to_hir_id(parent_id)); + if let Some(Node::Item(item)) = cx.tcx.hir().find_by_def_id(second_parent_id) { if let ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind { return true; } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 57183b58b2a1..e55817f13eb1 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -70,7 +70,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::unhash::UnhashMap; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{CrateNum, DefId}; +use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_ID}; use rustc_hir::hir_id::{HirIdMap, HirIdSet}; use rustc_hir::intravisit::{walk_expr, ErasedMap, FnKind, NestedVisitorMap, Visitor}; use rustc_hir::itemlikevisit::ItemLikeVisitor; @@ -90,7 +90,6 @@ use rustc_middle::ty::binding::BindingMode; use rustc_middle::ty::{layout::IntegerExt, BorrowKind, DefIdTree, Ty, TyCtxt, TypeAndMut, TypeFoldable, UpvarCapture}; use rustc_semver::RustcVersion; use rustc_session::Session; -use rustc_span::def_id::LocalDefId; use rustc_span::hygiene::{ExpnKind, MacroKind}; use rustc_span::source_map::original_sp; use rustc_span::sym; @@ -216,7 +215,7 @@ pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option< /// ``` pub fn in_constant(cx: &LateContext<'_>, id: HirId) -> bool { let parent_id = cx.tcx.hir().get_parent_item(id); - match cx.tcx.hir().get(parent_id) { + match cx.tcx.hir().get_by_def_id(parent_id) { Node::Item(&Item { kind: ItemKind::Const(..) | ItemKind::Static(..), .. @@ -607,12 +606,13 @@ pub fn get_trait_def_id(cx: &LateContext<'_>, path: &[&str]) -> Option { /// } /// } /// ``` -pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx TraitRef<'tcx>> { +pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, def_id: LocalDefId) -> Option<&'tcx TraitRef<'tcx>> { // Get the implemented trait for the current function + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); let parent_impl = cx.tcx.hir().get_parent_item(hir_id); if_chain! { - if parent_impl != hir::CRATE_HIR_ID; - if let hir::Node::Item(item) = cx.tcx.hir().get(parent_impl); + if parent_impl != CRATE_DEF_ID; + if let hir::Node::Item(item) = cx.tcx.hir().get_by_def_id(parent_impl); if let hir::ItemKind::Impl(impl_) = &item.kind; then { return impl_.of_trait.as_ref(); } } @@ -1122,14 +1122,13 @@ pub fn is_entrypoint_fn(cx: &LateContext<'_>, def_id: DefId) -> bool { /// Returns `true` if the expression is in the program's `#[panic_handler]`. pub fn is_in_panic_handler(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { let parent = cx.tcx.hir().get_parent_item(e.hir_id); - let def_id = cx.tcx.hir().local_def_id(parent).to_def_id(); - Some(def_id) == cx.tcx.lang_items().panic_impl() + Some(parent.to_def_id()) == cx.tcx.lang_items().panic_impl() } /// Gets the name of the item the expression is in, if available. pub fn get_item_name(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id); - match cx.tcx.hir().find(parent_id) { + match cx.tcx.hir().find_by_def_id(parent_id) { Some( Node::Item(Item { ident, .. }) | Node::TraitItem(TraitItem { ident, .. }) @@ -1639,7 +1638,7 @@ pub fn any_parent_has_attr(tcx: TyCtxt<'_>, node: HirId, symbol: Symbol) -> bool return true; } prev_enclosing_node = Some(enclosing_node); - enclosing_node = map.get_parent_item(enclosing_node); + enclosing_node = map.local_def_id_to_hir_id(map.get_parent_item(enclosing_node)); } false From cad0798d1420fe7437ae9e92c602efea31c0158f Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sun, 16 Jan 2022 15:58:54 -0600 Subject: [PATCH 0394/1222] Format clippy --- clippy_lints/src/non_copy_const.rs | 5 +---- clippy_lints/src/redundant_clone.rs | 5 +---- clippy_lints/src/unnecessary_sort_by.rs | 5 +---- clippy_utils/src/consts.rs | 5 +---- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index afc356d1ab25..21ac6548b017 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -188,10 +188,7 @@ fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: D let result = cx.tcx.const_eval_resolve( cx.param_env, - ty::Unevaluated::new( - ty::WithOptConstParam::unknown(def_id), - substs, - ), + ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), None, ); is_value_unfrozen_raw(cx, result, ty) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index dce1f66107a6..3e0e32857f1d 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -624,10 +624,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { .flat_map(HybridBitSet::iter) .collect(); - if ContainsRegion - .visit_ty(self.body.local_decls[*dest].ty) - .is_break() - { + if ContainsRegion.visit_ty(self.body.local_decls[*dest].ty).is_break() { mutable_variables.push(*dest); } diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index 32adccdbd1ce..7d75ff36e971 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -224,10 +224,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { fn expr_borrows(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let ty = cx.typeck_results().expr_ty(expr); - matches!(ty.kind(), ty::Ref(..)) - || ty - .walk() - .any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_))) + matches!(ty.kind(), ty::Ref(..)) || ty.walk().any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_))) } impl LateLintPass<'_> for UnnecessarySortBy { diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index e09a663538dd..34c5af848a6d 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -413,10 +413,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { .tcx .const_eval_resolve( self.param_env, - ty::Unevaluated::new( - ty::WithOptConstParam::unknown(def_id), - substs, - ), + ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), None, ) .ok() From e1b88f7cf531135dc7e4378ff1e66834c3084887 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sat, 15 Jan 2022 16:07:52 -0600 Subject: [PATCH 0395/1222] Fix Visitor::NestedFilter in Clippy --- clippy_lints/src/assign_ops.rs | 8 +---- clippy_lints/src/blocks_in_if_conditions.rs | 8 +---- clippy_lints/src/booleans.rs | 13 +------- clippy_lints/src/cognitive_complexity.rs | 8 +---- clippy_lints/src/copies.rs | 10 +++--- clippy_lints/src/default_numeric_fallback.rs | 9 +----- clippy_lints/src/derive.rs | 10 +++--- clippy_lints/src/doc.rs | 10 +++--- clippy_lints/src/entry.rs | 7 +--- clippy_lints/src/eval_order_dependence.rs | 13 +------- clippy_lints/src/fallible_impl_from.rs | 9 +----- clippy_lints/src/functions/must_use.rs | 7 ---- .../src/functions/not_unsafe_ptr_arg_deref.rs | 8 +---- clippy_lints/src/if_let_mutex.rs | 15 +-------- clippy_lints/src/implicit_hasher.rs | 16 +++------- clippy_lints/src/index_refutable_slice.rs | 10 +++--- clippy_lints/src/lifetimes.rs | 20 +----------- clippy_lints/src/loops/mut_range_bound.rs | 9 +----- clippy_lints/src/loops/needless_collect.rs | 15 +++------ clippy_lints/src/loops/needless_range_loop.rs | 8 +---- clippy_lints/src/loops/same_item_push.rs | 9 +----- clippy_lints/src/loops/utils.rs | 21 +++--------- .../src/loops/while_immutable_condition.rs | 15 +-------- .../src/loops/while_let_on_iterator.rs | 18 +---------- clippy_lints/src/manual_strip.rs | 8 +---- clippy_lints/src/match_str_case_mismatch.rs | 9 +----- clippy_lints/src/matches.rs | 7 +--- .../src/methods/option_map_unwrap_or.rs | 16 +++++----- .../src/methods/unnecessary_filter_map.rs | 9 +----- .../src/methods/unnecessary_iter_cloned.rs | 11 ++++--- clippy_lints/src/mut_mut.rs | 6 ---- clippy_lints/src/mutable_debug_assertion.rs | 10 +++--- clippy_lints/src/needless_for_each.rs | 9 +----- clippy_lints/src/redundant_closure_call.rs | 8 ++--- clippy_lints/src/returns.rs | 9 +----- .../src/slow_vector_initialization.rs | 9 +----- clippy_lints/src/suspicious_trait_impl.rs | 9 +----- clippy_lints/src/types/type_complexity.rs | 8 +---- .../src/undocumented_unsafe_blocks.rs | 9 +----- clippy_lints/src/unused_async.rs | 10 +++--- clippy_lints/src/unwrap.rs | 10 +++--- clippy_lints/src/unwrap_in_result.rs | 9 +----- clippy_lints/src/use_self.rs | 9 +----- clippy_lints/src/utils/internal_lints.rs | 9 +++--- .../internal_lints/metadata_collector.rs | 19 ++++++----- clippy_utils/src/eager_or_lazy.rs | 7 +--- clippy_utils/src/lib.rs | 13 +------- clippy_utils/src/usage.rs | 14 +++----- clippy_utils/src/visitors.rs | 32 +++++++------------ 49 files changed, 126 insertions(+), 419 deletions(-) diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index e16f4369da9f..12c1bddf79d5 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -6,9 +6,8 @@ use clippy_utils::{eq_expr_value, trait_ref_of_method}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { @@ -220,8 +219,6 @@ struct ExprVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { if eq_expr_value(self.cx, self.assignee, expr) { self.counter += 1; @@ -229,7 +226,4 @@ impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> { walk_expr(self, expr); } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } diff --git a/clippy_lints/src/blocks_in_if_conditions.rs b/clippy_lints/src/blocks_in_if_conditions.rs index 475fdb440d4e..b3f9c1b29767 100644 --- a/clippy_lints/src/blocks_in_if_conditions.rs +++ b/clippy_lints/src/blocks_in_if_conditions.rs @@ -5,10 +5,9 @@ use clippy_utils::ty::implements_trait; use clippy_utils::{differing_macro_contexts, get_parent_expr}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{BlockCheckMode, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; @@ -55,8 +54,6 @@ struct ExVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { if let ExprKind::Closure(_, _, eid, _, _) = expr.kind { // do not lint if the closure is called using an iterator (see #1141) @@ -82,9 +79,6 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> { } walk_expr(self, expr); } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } const BRACED_EXPR_MESSAGE: &str = "omit braces around single expression condition"; diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 43ad0f7605c1..7ffc8ecd31e5 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -5,10 +5,9 @@ use clippy_utils::{eq_expr_value, get_trait_def_id, paths}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_expr, FnKind, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, UnOp}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::sym; @@ -452,8 +451,6 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, e: &'tcx Expr<'_>) { if !e.span.from_expansion() { match &e.kind { @@ -470,9 +467,6 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { } walk_expr(self, e); } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } fn implements_ord<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool { @@ -485,8 +479,6 @@ struct NotSimplificationVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind { if let Some(suggestion) = simplify_not(self.cx, inner) { @@ -504,7 +496,4 @@ impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> { walk_expr(self, expr); } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index 84a2373efe15..85f952375491 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -5,10 +5,9 @@ use clippy_utils::source::snippet_opt; use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::LimitStack; use rustc_ast::ast::Attribute; -use rustc_hir::intravisit::{walk_expr, FnKind, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId}; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; use rustc_span::{sym, BytePos}; @@ -149,8 +148,6 @@ struct CcHelper { } impl<'tcx> Visitor<'tcx> for CcHelper { - type Map = Map<'tcx>; - fn visit_expr(&mut self, e: &'tcx Expr<'_>) { walk_expr(self, e); match e.kind { @@ -167,7 +164,4 @@ impl<'tcx> Visitor<'tcx> for CcHelper { _ => {}, } } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 73ce656ad151..39456e25ff4e 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -7,10 +7,10 @@ use clippy_utils::{ use if_chain::if_chain; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{Applicability, DiagnosticBuilder}; -use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{Block, Expr, ExprKind, HirId}; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; +use rustc_middle::hir::nested_filter; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{source_map::Span, symbol::Symbol, BytePos}; use std::borrow::Cow; @@ -561,10 +561,10 @@ impl<'a, 'tcx> UsedValueFinderVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for UsedValueFinderVisitor<'a, 'tcx> { - type Map = Map<'tcx>; + type NestedFilter = nested_filter::All; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::All(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } fn visit_local(&mut self, l: &'tcx rustc_hir::Local<'tcx>) { diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index 66b5f49817d8..78acdb5dfd58 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -5,12 +5,11 @@ use if_chain::if_chain; use rustc_ast::ast::{LitFloatType, LitIntType, LitKind}; use rustc_errors::Applicability; use rustc_hir::{ - intravisit::{walk_expr, walk_stmt, NestedVisitorMap, Visitor}, + intravisit::{walk_expr, walk_stmt, Visitor}, Body, Expr, ExprKind, HirId, Lit, Stmt, StmtKind, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::{ - hir::map::Map, lint::in_external_macro, ty::{self, FloatTy, IntTy, PolyFnSig, Ty}, }; @@ -117,8 +116,6 @@ impl<'a, 'tcx> NumericFallbackVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - #[allow(clippy::too_many_lines)] fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { match &expr.kind { @@ -209,10 +206,6 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { walk_stmt(self, stmt); self.ty_bounds.pop(); } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option> { diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 097cb65f56e4..6d3df260ca25 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -3,12 +3,12 @@ use clippy_utils::paths; use clippy_utils::ty::{implements_trait, is_copy}; use clippy_utils::{get_trait_def_id, is_automatically_derived, is_lint_allowed, match_def_path}; use if_chain::if_chain; -use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, Visitor}; use rustc_hir::{ BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, HirId, Impl, Item, ItemKind, TraitRef, UnsafeSource, Unsafety, }; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; +use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; @@ -382,7 +382,7 @@ struct UnsafeVisitor<'a, 'tcx> { } impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> { - type Map = Map<'tcx>; + type NestedFilter = nested_filter::All; fn visit_fn(&mut self, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body_id: BodyId, span: Span, id: HirId) { if self.has_unsafe { @@ -414,7 +414,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> { walk_expr(self, expr); } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::All(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } } diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index cb7d5ac73941..a00361e6062a 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -13,10 +13,10 @@ use rustc_data_structures::sync::Lrc; use rustc_errors::emitter::EmitterWriter; use rustc_errors::{Applicability, Handler, SuggestionStyle}; use rustc_hir as hir; -use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{AnonConst, Expr}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; +use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; use rustc_middle::ty; use rustc_parse::maybe_new_parser_from_source_str; @@ -799,7 +799,7 @@ struct FindPanicUnwrap<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> { - type Map = Map<'tcx>; + type NestedFilter = nested_filter::OnlyBodies; fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if self.panic_span.is_some() { @@ -834,7 +834,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> { // Panics in const blocks will cause compilation to fail. fn visit_anon_const(&mut self, _: &'tcx AnonConst) {} - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } } diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 3ce239273e25..a574c307a015 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -10,7 +10,7 @@ use core::fmt::Write; use rustc_errors::Applicability; use rustc_hir::{ hir_id::HirIdSet, - intravisit::{walk_expr, ErasedMap, NestedVisitorMap, Visitor}, + intravisit::{walk_expr, Visitor}, Block, Expr, ExprKind, Guard, HirId, Pat, Stmt, StmtKind, UnOp, }; use rustc_lint::{LateContext, LateLintPass}; @@ -370,11 +370,6 @@ impl<'tcx> InsertSearcher<'_, 'tcx> { } } impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> { - type Map = ErasedMap<'tcx>; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } - fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { match stmt.kind { StmtKind::Semi(e) => { diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index cdac9f3e6e17..65599a0587d4 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -1,10 +1,9 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_note}; use clippy_utils::{get_parent_expr, path_to_local, path_to_local_id}; use if_chain::if_chain; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Guard, HirId, Local, Node, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -133,8 +132,6 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, e: &'tcx Expr<'_>) { match e.kind { ExprKind::Continue(_) | ExprKind::Break(_, _) | ExprKind::Ret(_) => self.report_diverging_sub_expr(e), @@ -167,9 +164,6 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { fn visit_block(&mut self, _: &'tcx Block<'_>) { // don't continue over blocks, LateLintPass already does that } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } /// Walks up the AST from the given write expression (`vis.write_expr`) looking @@ -299,8 +293,6 @@ struct ReadVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if expr.hir_id == self.last_expr.hir_id { return; @@ -343,9 +335,6 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> { walk_expr(self, expr); } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } /// Returns `true` if `expr` is the LHS of an assignment, like `expr = ...`. diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 02f1baf27fae..574678b55421 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -5,7 +5,6 @@ use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; @@ -68,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom { } fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[hir::ImplItemRef]) { - use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; + use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{Expr, ImplItemKind}; struct FindPanicUnwrap<'a, 'tcx> { @@ -78,8 +77,6 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h } impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if let Some(macro_call) = root_macro_call_first_node(self.lcx, expr) { if is_panic(self.lcx, macro_call.def_id) { @@ -100,10 +97,6 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h // and check sub-expressions intravisit::walk_expr(self, expr); } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } for impl_item in impl_items { diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index bf59103e3f4d..2610f0ff384e 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -4,7 +4,6 @@ use rustc_hir::def_id::{DefIdSet, LocalDefId}; use rustc_hir::{self as hir, def::Res, intravisit, QPath}; use rustc_lint::{LateContext, LintContext}; use rustc_middle::{ - hir::map::Map, lint::in_external_macro, ty::{self, Ty}, }; @@ -211,8 +210,6 @@ struct StaticMutVisitor<'a, 'tcx> { } impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { use hir::ExprKind::{AddrOf, Assign, AssignOp, Call, MethodCall}; @@ -244,10 +241,6 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { _ => {}, } } - - fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap { - intravisit::NestedVisitorMap::None - } } fn is_mutated_static(e: &hir::Expr<'_>) -> bool { diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index 6d829a18b2e0..8902ee14572f 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -1,6 +1,6 @@ use rustc_hir::{self as hir, intravisit, HirIdSet}; use rustc_lint::LateContext; -use rustc_middle::{hir::map::Map, ty}; +use rustc_middle::ty; use rustc_span::def_id::LocalDefId; use clippy_utils::diagnostics::span_lint; @@ -74,8 +74,6 @@ struct DerefVisitor<'a, 'tcx> { } impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { match expr.kind { hir::ExprKind::Call(f, args) => { @@ -103,10 +101,6 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { intravisit::walk_expr(self, expr); } - - fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap { - intravisit::NestedVisitorMap::None - } } impl<'a, 'tcx> DerefVisitor<'a, 'tcx> { diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index e20741d2407e..0cc697d84255 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -3,10 +3,9 @@ use clippy_utils::higher; use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::SpanlessEq; use if_chain::if_chain; -use rustc_hir::intravisit::{self as visit, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{self as visit, Visitor}; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; @@ -91,8 +90,6 @@ pub struct OppVisitor<'a, 'tcx> { } impl<'tcx> Visitor<'tcx> for OppVisitor<'_, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if let Some(mutex) = is_mutex_lock_call(self.cx, expr) { self.found_mutex = Some(mutex); @@ -101,10 +98,6 @@ impl<'tcx> Visitor<'tcx> for OppVisitor<'_, 'tcx> { } visit::walk_expr(self, expr); } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } /// Checks if `Mutex::lock` is called in any of the branches. @@ -115,8 +108,6 @@ pub struct ArmVisitor<'a, 'tcx> { } impl<'tcx> Visitor<'tcx> for ArmVisitor<'_, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { if let Some(mutex) = is_mutex_lock_call(self.cx, expr) { self.found_mutex = Some(mutex); @@ -125,10 +116,6 @@ impl<'tcx> Visitor<'tcx> for ArmVisitor<'_, 'tcx> { } visit::walk_expr(self, expr); } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } impl<'tcx, 'l> ArmVisitor<'tcx, 'l> { diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 6358228dd47f..104de0ff62f8 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -3,10 +3,10 @@ use std::collections::BTreeMap; use rustc_errors::DiagnosticBuilder; use rustc_hir as hir; -use rustc_hir::intravisit::{walk_body, walk_expr, walk_inf, walk_ty, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_body, walk_expr, walk_inf, walk_ty, Visitor}; use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; +use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::{Ty, TyS, TypeckResults}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -294,8 +294,6 @@ impl<'a, 'tcx> ImplicitHasherTypeVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_ty(&mut self, t: &'tcx hir::Ty<'_>) { if let Some(target) = ImplicitHasherType::new(self.cx, t) { self.found.push(target); @@ -311,10 +309,6 @@ impl<'a, 'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> { walk_inf(self, inf); } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } /// Looks for default-hasher-dependent constructors like `HashMap::new`. @@ -337,7 +331,7 @@ impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { } impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { - type Map = Map<'tcx>; + type NestedFilter = nested_filter::OnlyBodies; fn visit_body(&mut self, body: &'tcx Body<'_>) { let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body.id())); @@ -389,7 +383,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't walk_expr(self, e); } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } } diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index 073313e2bad4..4615122bbf9e 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -7,9 +7,9 @@ use if_chain::if_chain; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::Applicability; use rustc_hir as hir; -use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{self, Visitor}; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; +use rustc_middle::hir::nested_filter; use rustc_middle::ty; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -230,10 +230,10 @@ struct SliceIndexLintingVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> { - type Map = Map<'tcx>; + type NestedFilter = nested_filter::OnlyBodies; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 6dd7b22ff94b..565057140454 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -2,8 +2,7 @@ use clippy_utils::diagnostics::span_lint; use clippy_utils::trait_ref_of_method; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::intravisit::{ - walk_fn_decl, walk_generic_param, walk_generics, walk_item, walk_param_bound, walk_poly_trait_ref, walk_ty, - NestedVisitorMap, Visitor, + walk_fn_decl, walk_generic_param, walk_generics, walk_item, walk_param_bound, walk_poly_trait_ref, walk_ty, Visitor, }; use rustc_hir::FnRetTy::Return; use rustc_hir::{ @@ -12,7 +11,6 @@ use rustc_hir::{ TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WhereClause, WherePredicate, }; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::symbol::{kw, Symbol}; @@ -354,8 +352,6 @@ impl<'a, 'tcx> RefVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - // for lifetimes as parameters of generics fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { self.record(&Some(*lifetime)); @@ -409,9 +405,6 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { } walk_ty(self, ty); } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } /// Are any lifetimes mentioned in the `where` clause? If so, we don't try to @@ -457,8 +450,6 @@ struct LifetimeChecker { } impl<'tcx> Visitor<'tcx> for LifetimeChecker { - type Map = Map<'tcx>; - // for lifetimes as parameters of generics fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { self.map.remove(&lifetime.name.ident().name); @@ -474,9 +465,6 @@ impl<'tcx> Visitor<'tcx> for LifetimeChecker { walk_generic_param(self, param); } } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } fn report_extra_lifetimes<'tcx>(cx: &LateContext<'tcx>, func: &'tcx FnDecl<'_>, generics: &'tcx Generics<'_>) { @@ -508,16 +496,10 @@ struct BodyLifetimeChecker { } impl<'tcx> Visitor<'tcx> for BodyLifetimeChecker { - type Map = Map<'tcx>; - // for lifetimes as parameters of generics fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { if lifetime.name.ident().name != kw::Empty && lifetime.name.ident().name != kw::StaticLifetime { self.lifetimes_used_in_body = true; } } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index 37a57d8feb1d..9d8679d77c6d 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -2,11 +2,10 @@ use super::MUT_RANGE_BOUND; use clippy_utils::diagnostics::span_lint_and_note; use clippy_utils::{get_enclosing_block, higher, path_to_local}; use if_chain::if_chain; -use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{BindingAnnotation, Expr, ExprKind, HirId, Node, PatKind}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; -use rustc_middle::hir::map::Map; use rustc_middle::{mir::FakeReadCause, ty}; use rustc_span::source_map::Span; use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; @@ -148,12 +147,6 @@ impl BreakAfterExprVisitor { } impl<'tcx> intravisit::Visitor<'tcx> for BreakAfterExprVisitor { - type Map = Map<'tcx>; - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } - fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { if self.past_candidate { return; diff --git a/clippy_lints/src/loops/needless_collect.rs b/clippy_lints/src/loops/needless_collect.rs index 6248680aa621..f7d3227af017 100644 --- a/clippy_lints/src/loops/needless_collect.rs +++ b/clippy_lints/src/loops/needless_collect.rs @@ -7,10 +7,10 @@ use clippy_utils::{can_move_expr_to_closure, is_trait_method, path_to_local, pat use if_chain::if_chain; use rustc_data_structures::fx::FxHashMap; use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_block, walk_expr, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_block, walk_expr, Visitor}; use rustc_hir::{Block, Expr, ExprKind, HirId, HirIdSet, Local, Mutability, Node, PatKind, Stmt, StmtKind}; use rustc_lint::LateContext; -use rustc_middle::hir::map::Map; +use rustc_middle::hir::nested_filter; use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::{self, TyS}; use rustc_span::sym; @@ -262,11 +262,6 @@ impl<'tcx> Visitor<'tcx> for IterFunctionVisitor<'_, 'tcx> { walk_expr(self, expr); } } - - type Map = Map<'tcx>; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } impl<'tcx> IterFunctionVisitor<'_, 'tcx> { @@ -298,7 +293,7 @@ struct UsedCountVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for UsedCountVisitor<'a, 'tcx> { - type Map = Map<'tcx>; + type NestedFilter = nested_filter::OnlyBodies; fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if path_to_local_id(expr, self.id) { @@ -308,8 +303,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UsedCountVisitor<'a, 'tcx> { } } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } } diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 33abd2a72d88..22da21bc6bc4 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -8,10 +8,9 @@ use if_chain::if_chain; use rustc_ast::ast; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, Mutability, Pat, PatKind, QPath}; use rustc_lint::LateContext; -use rustc_middle::hir::map::Map; use rustc_middle::middle::region; use rustc_middle::ty::{self, Ty}; use rustc_span::symbol::{sym, Symbol}; @@ -294,8 +293,6 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if_chain! { // a range index op @@ -374,7 +371,4 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { } self.prefer_mutable = old; } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index ab83291461fb..c61b411708c2 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -6,10 +6,9 @@ use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; use if_chain::if_chain; use rustc_data_structures::fx::FxHashSet; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Node, Pat, PatKind, Stmt, StmtKind}; use rustc_lint::LateContext; -use rustc_middle::hir::map::Map; use rustc_span::symbol::sym; use std::iter::Iterator; @@ -134,8 +133,6 @@ impl<'a, 'tcx> SameItemPushVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for SameItemPushVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { match &expr.kind { // Non-determinism may occur ... don't give a lint @@ -175,10 +172,6 @@ impl<'a, 'tcx> Visitor<'tcx> for SameItemPushVisitor<'a, 'tcx> { } } } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } // Given some statement, determine if that statement is a push on a Vec. If it is, return diff --git a/clippy_lints/src/loops/utils.rs b/clippy_lints/src/loops/utils.rs index f6b7e1bc353f..eac0f03b142a 100644 --- a/clippy_lints/src/loops/utils.rs +++ b/clippy_lints/src/loops/utils.rs @@ -3,10 +3,10 @@ use clippy_utils::{get_parent_expr, is_integer_const, path_to_local, path_to_loc use if_chain::if_chain; use rustc_ast::ast::{LitIntType, LitKind}; use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_expr, walk_local, walk_pat, walk_stmt, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, walk_local, walk_pat, walk_stmt, Visitor}; use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, Local, Mutability, Pat, PatKind, Stmt}; use rustc_lint::LateContext; -use rustc_middle::hir::map::Map; +use rustc_middle::hir::nested_filter; use rustc_middle::ty::Ty; use rustc_span::source_map::Spanned; use rustc_span::symbol::{sym, Symbol}; @@ -50,8 +50,6 @@ impl<'a, 'tcx> IncrementVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if self.done { return; @@ -102,9 +100,6 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> { walk_expr(self, expr); } } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } enum InitializeVisitorState<'hir> { @@ -151,7 +146,7 @@ impl<'a, 'tcx> InitializeVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { - type Map = Map<'tcx>; + type NestedFilter = nested_filter::OnlyBodies; fn visit_local(&mut self, l: &'tcx Local<'_>) { // Look for declarations of the variable @@ -254,8 +249,8 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { } } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } } @@ -283,8 +278,6 @@ pub(super) struct LoopNestVisitor { } impl<'tcx> Visitor<'tcx> for LoopNestVisitor { - type Map = Map<'tcx>; - fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { if stmt.hir_id == self.hir_id { self.nesting = LookFurther; @@ -323,10 +316,6 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor { } walk_pat(self, pat); } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } /// If `arg` was the argument to a `for` loop, return the "cleanest" way of writing the diff --git a/clippy_lints/src/loops/while_immutable_condition.rs b/clippy_lints/src/loops/while_immutable_condition.rs index 5f9ebad25e89..5dcfed65c78a 100644 --- a/clippy_lints/src/loops/while_immutable_condition.rs +++ b/clippy_lints/src/loops/while_immutable_condition.rs @@ -5,11 +5,10 @@ use clippy_utils::usage::mutated_variables; use if_chain::if_chain; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefIdMap; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::HirIdSet; use rustc_hir::{Expr, ExprKind, QPath}; use rustc_lint::LateContext; -use rustc_middle::hir::map::Map; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) { if constant(cx, cx.typeck_results(), cond).is_some() { @@ -67,8 +66,6 @@ struct HasBreakOrReturnVisitor { } impl<'tcx> Visitor<'tcx> for HasBreakOrReturnVisitor { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if self.has_break_or_return { return; @@ -84,10 +81,6 @@ impl<'tcx> Visitor<'tcx> for HasBreakOrReturnVisitor { walk_expr(self, expr); } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } /// Collects the set of variables in an expression @@ -123,8 +116,6 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for VarCollectorVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, ex: &'tcx Expr<'_>) { match ex.kind { ExprKind::Path(_) => self.insert_def_id(ex), @@ -134,8 +125,4 @@ impl<'a, 'tcx> Visitor<'tcx> for VarCollectorVisitor<'a, 'tcx> { _ => walk_expr(self, ex), } } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index 750328d1d01a..e0b235c35598 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -7,7 +7,7 @@ use clippy_utils::{ }; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_expr, ErasedMap, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{def::Res, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, UnOp}; use rustc_lint::LateContext; use rustc_middle::ty::adjustment::Adjust; @@ -211,11 +211,6 @@ fn uses_iter<'tcx>(cx: &LateContext<'tcx>, iter_expr: &IterExpr, container: &'tc uses_iter: bool, } impl<'tcx> Visitor<'tcx> for V<'_, '_, 'tcx> { - type Map = ErasedMap<'tcx>; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } - fn visit_expr(&mut self, e: &'tcx Expr<'_>) { if self.uses_iter { // return @@ -254,11 +249,6 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: & used_iter: bool, } impl<'tcx> Visitor<'tcx> for AfterLoopVisitor<'_, '_, 'tcx> { - type Map = ErasedMap<'tcx>; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } - fn visit_expr(&mut self, e: &'tcx Expr<'_>) { if self.used_iter { return; @@ -293,12 +283,6 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: & used_after: bool, } impl<'a, 'b, 'tcx> Visitor<'tcx> for NestedLoopVisitor<'a, 'b, 'tcx> { - type Map = ErasedMap<'tcx>; - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } - fn visit_local(&mut self, l: &'tcx Local<'_>) { if !self.after_loop { l.pat.each_binding_or_first(&mut |_, id, _, _| { diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index f8e28f1671f0..039cb3aafdb7 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -6,11 +6,10 @@ use clippy_utils::{eq_expr_value, higher, match_def_path, meets_msrv, msrvs, pat use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_hir::def::Res; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::BinOpKind; use rustc_hir::{BorrowKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; use rustc_middle::ty; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -203,11 +202,6 @@ fn find_stripping<'tcx>( } impl<'a, 'tcx> Visitor<'tcx> for StrippingFinder<'a, 'tcx> { - type Map = Map<'tcx>; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } - fn visit_expr(&mut self, ex: &'tcx Expr<'_>) { if_chain! { if is_ref_str(self.cx, ex); diff --git a/clippy_lints/src/match_str_case_mismatch.rs b/clippy_lints/src/match_str_case_mismatch.rs index 1fc7eb721428..b0eebf35e274 100644 --- a/clippy_lints/src/match_str_case_mismatch.rs +++ b/clippy_lints/src/match_str_case_mismatch.rs @@ -2,10 +2,9 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::ty::is_type_diagnostic_item; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{Arm, Expr, ExprKind, MatchSource, PatKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; use rustc_middle::lint::in_external_macro; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -86,12 +85,6 @@ struct MatchExprVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for MatchExprVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } - fn visit_expr(&mut self, ex: &'tcx Expr<'_>) { match ex.kind { ExprKind::MethodCall(segment, _, [receiver], _) if self.case_altered(segment.ident.as_str(), receiver) => { diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 60dd957db01f..33d022c73a5e 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -1776,7 +1776,7 @@ mod redundant_pattern_match { use rustc_errors::Applicability; use rustc_hir::LangItem::{OptionNone, OptionSome, PollPending, PollReady, ResultErr, ResultOk}; use rustc_hir::{ - intravisit::{walk_expr, ErasedMap, NestedVisitorMap, Visitor}, + intravisit::{walk_expr, Visitor}, Arm, Block, Expr, ExprKind, LangItem, MatchSource, Node, Pat, PatKind, QPath, UnOp, }; use rustc_lint::LateContext; @@ -1880,11 +1880,6 @@ mod redundant_pattern_match { res: bool, } impl<'a, 'tcx> Visitor<'tcx> for V<'a, 'tcx> { - type Map = ErasedMap<'tcx>; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } - fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { match expr.kind { // Taking the reference of a value leaves a temporary diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 2faa6a69f81d..9c6f42110318 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -5,10 +5,10 @@ use clippy_utils::ty::is_copy; use clippy_utils::ty::is_type_diagnostic_item; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_path, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_path, Visitor}; use rustc_hir::{self, HirId, Path}; use rustc_lint::LateContext; -use rustc_middle::hir::map::Map; +use rustc_middle::hir::nested_filter; use rustc_span::source_map::Span; use rustc_span::{sym, Symbol}; @@ -97,15 +97,15 @@ struct UnwrapVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for UnwrapVisitor<'a, 'tcx> { - type Map = Map<'tcx>; + type NestedFilter = nested_filter::All; fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) { self.identifiers.insert(ident(path)); walk_path(self, path); } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::All(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } } @@ -116,7 +116,7 @@ struct MapExprVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for MapExprVisitor<'a, 'tcx> { - type Map = Map<'tcx>; + type NestedFilter = nested_filter::All; fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) { if self.identifiers.contains(&ident(path)) { @@ -126,8 +126,8 @@ impl<'a, 'tcx> Visitor<'tcx> for MapExprVisitor<'a, 'tcx> { walk_path(self, path); } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::All(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } } diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index 59bdfb923ed4..784014f0d874 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -2,10 +2,9 @@ use clippy_utils::diagnostics::span_lint; use clippy_utils::usage::mutated_variables; use clippy_utils::{is_lang_ctor, is_trait_method, path_to_local_id}; use rustc_hir as hir; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::LangItem::{OptionNone, OptionSome}; use rustc_lint::LateContext; -use rustc_middle::hir::map::Map; use rustc_middle::ty::{self, TyS}; use rustc_span::sym; @@ -113,8 +112,6 @@ impl<'a, 'tcx> ReturnVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for ReturnVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { if let hir::ExprKind::Ret(Some(expr)) = &expr.kind { let (found_mapping, found_filtering) = check_expression(self.cx, self.arg_id, expr); @@ -124,8 +121,4 @@ impl<'a, 'tcx> Visitor<'tcx> for ReturnVisitor<'a, 'tcx> { walk_expr(self, expr); } } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } diff --git a/clippy_lints/src/methods/unnecessary_iter_cloned.rs b/clippy_lints/src/methods/unnecessary_iter_cloned.rs index 5999245ea7d0..5fee18c5129a 100644 --- a/clippy_lints/src/methods/unnecessary_iter_cloned.rs +++ b/clippy_lints/src/methods/unnecessary_iter_cloned.rs @@ -4,10 +4,11 @@ use clippy_utils::source::snippet_opt; use clippy_utils::ty::{get_associated_type, get_iterator_item_ty, implements_trait}; use clippy_utils::{fn_def_id, get_parent_expr, path_to_local_id, usage}; use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{def_id::DefId, BorrowKind, Expr, ExprKind, HirId, LangItem, Mutability, Pat}; use rustc_lint::LateContext; -use rustc_middle::{hir::map::Map, ty}; +use rustc_middle::hir::nested_filter; +use rustc_middle::ty; use rustc_span::{sym, Symbol}; use super::UNNECESSARY_TO_OWNED; @@ -139,10 +140,10 @@ struct CloneOrCopyVisitor<'cx, 'tcx> { } impl<'cx, 'tcx> Visitor<'tcx> for CloneOrCopyVisitor<'cx, 'tcx> { - type Map = Map<'tcx>; + type NestedFilter = nested_filter::OnlyBodies; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index bcbea8f1e66b..cb16f00047a3 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -3,7 +3,6 @@ use clippy_utils::higher; use rustc_hir as hir; use rustc_hir::intravisit; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; use rustc_middle::lint::in_external_macro; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -47,8 +46,6 @@ pub struct MutVisitor<'a, 'tcx> { } impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { if in_external_macro(self.cx.sess(), expr.span) { return; @@ -114,7 +111,4 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { intravisit::walk_ty(self, ty); } - fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap { - intravisit::NestedVisitorMap::None - } } diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index 842959ce36b0..cd1bc2023702 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -1,9 +1,9 @@ use clippy_utils::diagnostics::span_lint; use clippy_utils::macros::{find_assert_eq_args, root_macro_call_first_node}; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{BorrowKind, Expr, ExprKind, MatchSource, Mutability}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; +use rustc_middle::hir::nested_filter; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Span; @@ -84,7 +84,7 @@ impl<'a, 'tcx> MutArgVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> { - type Map = Map<'tcx>; + type NestedFilter = nested_filter::OnlyBodies; fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { match expr.kind { @@ -115,7 +115,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> { walk_expr(self, expr); } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } } diff --git a/clippy_lints/src/needless_for_each.rs b/clippy_lints/src/needless_for_each.rs index 19d58f7474b0..44c4b70524d9 100644 --- a/clippy_lints/src/needless_for_each.rs +++ b/clippy_lints/src/needless_for_each.rs @@ -1,10 +1,9 @@ use rustc_errors::Applicability; use rustc_hir::{ - intravisit::{walk_expr, NestedVisitorMap, Visitor}, + intravisit::{walk_expr, Visitor}, Expr, ExprKind, Stmt, StmtKind, }; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{source_map::Span, sym, Symbol}; @@ -136,8 +135,6 @@ struct RetCollector { } impl<'tcx> Visitor<'tcx> for RetCollector { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &Expr<'_>) { match expr.kind { ExprKind::Ret(..) => { @@ -160,8 +157,4 @@ impl<'tcx> Visitor<'tcx> for RetCollector { walk_expr(self, expr); } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 0de282542fc3..0c77cf5e77dd 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -9,7 +9,7 @@ use rustc_hir as hir; use rustc_hir::intravisit as hir_visit; use rustc_hir::intravisit::Visitor as HirVisitor; use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; +use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -106,7 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { count: usize, } impl<'a, 'tcx> hir_visit::Visitor<'tcx> for ClosureUsageCount<'a, 'tcx> { - type Map = Map<'tcx>; + type NestedFilter = nested_filter::OnlyBodies; fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { if_chain! { @@ -121,8 +121,8 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { hir_visit::walk_expr(self, expr); } - fn nested_visit_map(&mut self) -> hir_visit::NestedVisitorMap { - hir_visit::NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } } let mut closure_usage_count = ClosureUsageCount { cx, path, count: 0 }; diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 52e708f628a2..8068fa22d9cc 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -4,10 +4,9 @@ use clippy_utils::{fn_def_id, path_to_local_id}; use if_chain::if_chain; use rustc_ast::ast::Attribute; use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_expr, FnKind, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, HirId, MatchSource, PatKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::subst::GenericArgKind; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -287,8 +286,6 @@ struct BorrowVisitor<'a, 'tcx> { } impl<'tcx> Visitor<'tcx> for BorrowVisitor<'_, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if self.borrows { return; @@ -307,8 +304,4 @@ impl<'tcx> Visitor<'tcx> for BorrowVisitor<'_, 'tcx> { walk_expr(self, expr); } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 1ae772ef70b1..607fa847dae5 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -5,10 +5,9 @@ use clippy_utils::{get_enclosing_block, is_expr_path_def_path, path_to_local, pa use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_block, walk_expr, walk_stmt, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_block, walk_expr, walk_stmt, Visitor}; use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, PatKind, QPath, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; @@ -270,8 +269,6 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for VectorInitializationVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { if self.initialization_found { match stmt.kind { @@ -308,8 +305,4 @@ impl<'a, 'tcx> Visitor<'tcx> for VectorInitializationVisitor<'a, 'tcx> { walk_expr(self, expr); } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index 92494159deeb..4294464dbf61 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -2,9 +2,8 @@ use clippy_utils::diagnostics::span_lint; use clippy_utils::{binop_traits, trait_ref_of_method, BINOP_TRAITS, OP_ASSIGN_TRAITS}; use if_chain::if_chain; use rustc_hir as hir; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { @@ -104,8 +103,6 @@ struct BinaryExprVisitor { } impl<'tcx> Visitor<'tcx> for BinaryExprVisitor { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { match expr.kind { hir::ExprKind::Binary(..) @@ -116,8 +113,4 @@ impl<'tcx> Visitor<'tcx> for BinaryExprVisitor { walk_expr(self, expr); } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } diff --git a/clippy_lints/src/types/type_complexity.rs b/clippy_lints/src/types/type_complexity.rs index 20c136407a1b..5ca4023aa5c1 100644 --- a/clippy_lints/src/types/type_complexity.rs +++ b/clippy_lints/src/types/type_complexity.rs @@ -1,9 +1,8 @@ use clippy_utils::diagnostics::span_lint; use rustc_hir as hir; -use rustc_hir::intravisit::{walk_inf, walk_ty, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_inf, walk_ty, Visitor}; use rustc_hir::{GenericParamKind, TyKind}; use rustc_lint::LateContext; -use rustc_middle::hir::map::Map; use rustc_target::spec::abi::Abi; use super::TYPE_COMPLEXITY; @@ -37,8 +36,6 @@ struct TypeComplexityVisitor { } impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor { - type Map = Map<'tcx>; - fn visit_infer(&mut self, inf: &'tcx hir::InferArg) { self.score += 1; walk_inf(self, inf); @@ -78,7 +75,4 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor { walk_ty(self, ty); self.nest -= sub_nest; } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index 697ed267e2f3..e42c6c63ede0 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -2,11 +2,10 @@ use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg}; use clippy_utils::is_lint_allowed; use clippy_utils::source::{indent_of, reindent_multiline, snippet}; use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{Block, BlockCheckMode, Expr, ExprKind, HirId, Local, UnsafeSource}; use rustc_lexer::TokenKind; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::TyCtxt; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -114,12 +113,6 @@ impl LateLintPass<'_> for UndocumentedUnsafeBlocks { } impl<'v> Visitor<'v> for UndocumentedUnsafeBlocks { - type Map = Map<'v>; - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } - fn visit_expr(&mut self, ex: &'v Expr<'v>) { match ex.kind { ExprKind::Block(_, _) => self.local_level = self.local_level.saturating_add(1), diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index 1ccb78425c29..2b89398ecd6a 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -1,8 +1,8 @@ use clippy_utils::diagnostics::span_lint_and_help; -use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, Visitor}; use rustc_hir::{Body, Expr, ExprKind, FnDecl, FnHeader, HirId, IsAsync, YieldSource}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; +use rustc_middle::hir::nested_filter; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Span; @@ -43,7 +43,7 @@ struct AsyncFnVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for AsyncFnVisitor<'a, 'tcx> { - type Map = Map<'tcx>; + type NestedFilter = nested_filter::OnlyBodies; fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) { if let ExprKind::Yield(_, YieldSource::Await { .. }) = ex.kind { @@ -52,8 +52,8 @@ impl<'a, 'tcx> Visitor<'tcx> for AsyncFnVisitor<'a, 'tcx> { walk_expr(self, ex); } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } } diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 918fa5f7dc12..0a728d7700b3 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -4,10 +4,10 @@ use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::{differing_macro_contexts, path_to_local, usage::is_potentially_mutated}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, Visitor}; use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, PathSegment, UnOp}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; +use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::Ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -215,7 +215,7 @@ impl<'a, 'tcx> UnwrappableVariablesVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> { - type Map = Map<'tcx>; + type NestedFilter = nested_filter::OnlyBodies; fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { // Shouldn't lint when `expr` is in macro. @@ -297,8 +297,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> { } } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } } diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs index 994df85cb8ac..2c13f1049b59 100644 --- a/clippy_lints/src/unwrap_in_result.rs +++ b/clippy_lints/src/unwrap_in_result.rs @@ -3,10 +3,9 @@ use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::{method_chain_args, return_ty}; use if_chain::if_chain; use rustc_hir as hir; -use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{Expr, ImplItemKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; @@ -81,8 +80,6 @@ struct FindExpectUnwrap<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for FindExpectUnwrap<'a, 'tcx> { - type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { // check for `expect` if let Some(arglists) = method_chain_args(expr, &["expect"]) { @@ -107,10 +104,6 @@ impl<'a, 'tcx> Visitor<'tcx> for FindExpectUnwrap<'a, 'tcx> { // and check sub-expressions intravisit::walk_expr(self, expr); } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_item: &'tcx hir::ImplItem<'_>) { diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index cf9a4a5e6d37..6c5a5fe1434f 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -8,11 +8,10 @@ use rustc_hir::{ self as hir, def::{CtorOf, DefKind, Res}, def_id::LocalDefId, - intravisit::{walk_inf, walk_ty, NestedVisitorMap, Visitor}, + intravisit::{walk_inf, walk_ty, Visitor}, Expr, ExprKind, FnRetTy, FnSig, GenericArg, HirId, Impl, ImplItemKind, Item, ItemKind, Path, QPath, TyKind, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; @@ -262,8 +261,6 @@ struct SkipTyCollector { } impl<'tcx> Visitor<'tcx> for SkipTyCollector { - type Map = Map<'tcx>; - fn visit_infer(&mut self, inf: &hir::InferArg) { self.types_to_skip.push(inf.hir_id); @@ -274,10 +271,6 @@ impl<'tcx> Visitor<'tcx> for SkipTyCollector { walk_ty(self, hir_ty); } - - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } fn span_lint(cx: &LateContext<'_>, span: Span) { diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 9c3dcc8e96a0..02fa866db523 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -17,13 +17,12 @@ use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::hir_id::CRATE_HIR_ID; -use rustc_hir::intravisit::{NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::Visitor; use rustc_hir::{ BinOpKind, Block, Expr, ExprKind, HirId, Item, Local, MutTy, Mutability, Node, Path, Stmt, StmtKind, Ty, TyKind, UnOp, }; use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; use rustc_middle::mir::interpret::ConstValue; use rustc_middle::ty; use rustc_semver::RustcVersion; @@ -544,7 +543,7 @@ struct LintCollector<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for LintCollector<'a, 'tcx> { - type Map = Map<'tcx>; + type NestedFilter = nested_filter::All; fn visit_path(&mut self, path: &'tcx Path<'_>, _: HirId) { if path.segments.len() == 1 { @@ -552,8 +551,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LintCollector<'a, 'tcx> { } } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::All(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } } diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index 4e46d79dc087..8485c14bfe72 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -19,7 +19,6 @@ use rustc_hir::{ self as hir, def::DefKind, intravisit, intravisit::Visitor, ExprKind, Item, ItemKind, Mutability, QPath, }; use rustc_lint::{CheckLintNameResult, LateContext, LateLintPass, LintContext, LintId}; -use rustc_middle::hir::map::Map; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{sym, Loc, Span, Symbol}; use serde::{ser::SerializeStruct, Serialize, Serializer}; @@ -738,10 +737,10 @@ impl<'a, 'hir> LintResolver<'a, 'hir> { } impl<'a, 'hir> intravisit::Visitor<'hir> for LintResolver<'a, 'hir> { - type Map = Map<'hir>; + type NestedFilter = nested_filter::All; - fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap { - intravisit::NestedVisitorMap::All(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } fn visit_expr(&mut self, expr: &'hir hir::Expr<'hir>) { @@ -792,10 +791,10 @@ impl<'a, 'hir> ApplicabilityResolver<'a, 'hir> { } impl<'a, 'hir> intravisit::Visitor<'hir> for ApplicabilityResolver<'a, 'hir> { - type Map = Map<'hir>; + type NestedFilter = nested_filter::All; - fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap { - intravisit::NestedVisitorMap::All(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } fn visit_path(&mut self, path: &'hir hir::Path<'hir>, _id: hir::HirId) { @@ -875,10 +874,10 @@ impl<'a, 'hir> IsMultiSpanScanner<'a, 'hir> { } impl<'a, 'hir> intravisit::Visitor<'hir> for IsMultiSpanScanner<'a, 'hir> { - type Map = Map<'hir>; + type NestedFilter = nested_filter::All; - fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap { - intravisit::NestedVisitorMap::All(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } fn visit_expr(&mut self, expr: &'hir hir::Expr<'hir>) { diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index c3936ec95d46..1f9c7363bbcb 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -12,7 +12,7 @@ use crate::ty::{all_predicates_of, is_copy}; use crate::visitors::is_const_evaluatable; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::intravisit::{walk_expr, ErasedMap, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{def_id::DefId, Block, Expr, ExprKind, QPath, UnOp}; use rustc_lint::LateContext; use rustc_middle::ty::{self, PredicateKind}; @@ -104,11 +104,6 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS } impl<'cx, 'tcx> Visitor<'tcx> for V<'cx, 'tcx> { - type Map = ErasedMap<'tcx>; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } - fn visit_expr(&mut self, e: &'tcx Expr<'_>) { use EagernessSuggestion::{ForceNoChange, Lazy, NoChange}; if self.eagerness == ForceNoChange { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index c11594002702..9e5e53a768b8 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -72,7 +72,7 @@ use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_ID}; use rustc_hir::hir_id::{HirIdMap, HirIdSet}; -use rustc_hir::intravisit::{walk_expr, ErasedMap, FnKind, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::LangItem::{OptionNone, ResultErr, ResultOk}; use rustc_hir::{ @@ -82,7 +82,6 @@ use rustc_hir::{ Target, TraitItem, TraitItemKind, TraitRef, TyKind, UnOp, }; use rustc_lint::{LateContext, Level, Lint, LintContext}; -use rustc_middle::hir::map::Map; use rustc_middle::hir::place::PlaceBase; use rustc_middle::ty as rustc_ty; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; @@ -982,11 +981,6 @@ pub fn can_move_expr_to_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<' captures: HirIdMap, } impl<'tcx> Visitor<'tcx> for V<'_, 'tcx> { - type Map = ErasedMap<'tcx>; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } - fn visit_expr(&mut self, e: &'tcx Expr<'_>) { if !self.allow_closure { return; @@ -1144,16 +1138,11 @@ pub struct ContainsName { } impl<'tcx> Visitor<'tcx> for ContainsName { - type Map = Map<'tcx>; - fn visit_name(&mut self, _: Span, name: Symbol) { if self.name == name { self.result = true; } } - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } } /// Checks if an `Expr` contains a certain name. diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index 2066915e1d18..405e306359bc 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -6,7 +6,7 @@ use rustc_hir::HirIdSet; use rustc_hir::{Expr, ExprKind, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; -use rustc_middle::hir::map::Map; +use rustc_middle::hir::nested_filter; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty; use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; @@ -96,18 +96,12 @@ impl<'tcx> ParamBindingIdCollector { } } impl<'tcx> intravisit::Visitor<'tcx> for ParamBindingIdCollector { - type Map = Map<'tcx>; - fn visit_pat(&mut self, pat: &'tcx hir::Pat<'tcx>) { if let hir::PatKind::Binding(_, hir_id, ..) = pat.kind { self.binding_hir_ids.push(hir_id); } intravisit::walk_pat(self, pat); } - - fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap { - intravisit::NestedVisitorMap::None - } } pub struct BindingUsageFinder<'a, 'tcx> { @@ -127,7 +121,7 @@ impl<'a, 'tcx> BindingUsageFinder<'a, 'tcx> { } } impl<'a, 'tcx> intravisit::Visitor<'tcx> for BindingUsageFinder<'a, 'tcx> { - type Map = Map<'tcx>; + type NestedFilter = nested_filter::OnlyBodies; fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { if !self.usage_found { @@ -143,8 +137,8 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for BindingUsageFinder<'a, 'tcx> { } } - fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap { - intravisit::NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } } diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index b60cd4736f32..40451b17a9c6 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -1,12 +1,13 @@ use crate::path_to_local_id; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::intravisit::{self, walk_block, walk_expr, NestedVisitorMap, Visitor}; +use rustc_hir::intravisit::{self, walk_block, walk_expr, Visitor}; use rustc_hir::{ Arm, Block, BlockCheckMode, Body, BodyId, Expr, ExprKind, HirId, ItemId, ItemKind, Stmt, UnOp, Unsafety, }; use rustc_lint::LateContext; use rustc_middle::hir::map::Map; +use rustc_middle::hir::nested_filter; use rustc_middle::ty; /// Convenience method for creating a `Visitor` with just `visit_expr` overridden and nested @@ -19,9 +20,9 @@ pub fn expr_visitor<'tcx>(cx: &LateContext<'tcx>, f: impl FnMut(&'tcx Expr<'tcx> f: F, } impl<'tcx, F: FnMut(&'tcx Expr<'tcx>) -> bool> Visitor<'tcx> for V<'tcx, F> { - type Map = Map<'tcx>; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.hir) + type NestedFilter = nested_filter::OnlyBodies; + fn nested_visit_map(&mut self) -> Self::Map { + self.hir } fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { @@ -40,11 +41,6 @@ pub fn expr_visitor<'tcx>(cx: &LateContext<'tcx>, f: impl FnMut(&'tcx Expr<'tcx> pub fn expr_visitor_no_bodies<'tcx>(f: impl FnMut(&'tcx Expr<'tcx>) -> bool) -> impl Visitor<'tcx> { struct V(F); impl<'tcx, F: FnMut(&'tcx Expr<'tcx>) -> bool> Visitor<'tcx> for V { - type Map = intravisit::ErasedMap<'tcx>; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } - fn visit_expr(&mut self, e: &'tcx Expr<'_>) { if (self.0)(e) { walk_expr(self, e); @@ -113,12 +109,6 @@ where } impl<'hir, F: FnMut(&'hir hir::Expr<'hir>) -> bool> intravisit::Visitor<'hir> for RetFinder { - type Map = Map<'hir>; - - fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap { - intravisit::NestedVisitorMap::None - } - fn visit_stmt(&mut self, stmt: &'hir hir::Stmt<'_>) { intravisit::walk_stmt(&mut *self.inside_stmt(true), stmt); } @@ -237,9 +227,9 @@ pub fn is_const_evaluatable<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> is_const: bool, } impl<'tcx> Visitor<'tcx> for V<'_, 'tcx> { - type Map = Map<'tcx>; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) + type NestedFilter = nested_filter::OnlyBodies; + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } fn visit_expr(&mut self, e: &'tcx Expr<'_>) { @@ -327,9 +317,9 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool { is_unsafe: bool, } impl<'tcx> Visitor<'tcx> for V<'_, 'tcx> { - type Map = Map<'tcx>; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) + type NestedFilter = nested_filter::OnlyBodies; + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() } fn visit_expr(&mut self, e: &'tcx Expr<'_>) { if self.is_unsafe { From 7688dd42ba64e639f2b170031ce4df97414705fc Mon Sep 17 00:00:00 2001 From: kadmin Date: Fri, 30 Jul 2021 08:56:45 +0000 Subject: [PATCH 0396/1222] add eq constraints on associated constants --- clippy_utils/src/ast_utils.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 3d3180521ab7..d4f037677e08 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -645,12 +645,13 @@ pub fn eq_generic_bound(l: &GenericBound, r: &GenericBound) -> bool { } } -pub fn eq_assoc_constraint(l: &AssocTyConstraint, r: &AssocTyConstraint) -> bool { - use AssocTyConstraintKind::*; +pub fn eq_assoc_constraint(l: &AssocConstraint, r: &AssocConstraint) -> bool { + use AssocConstraintKind::*; eq_id(l.ident, r.ident) && match (&l.kind, &r.kind) { (Equality { ty: l }, Equality { ty: r }) => eq_ty(l, r), (Bound { bounds: l }, Bound { bounds: r }) => over(l, r, eq_generic_bound), + (ConstEquality { c: l }, ConstEquality { c: r }) => eq_anon_const(l, r), _ => false, } } From 3915e26a9a2e2778e74bcdd215abce1a3168707c Mon Sep 17 00:00:00 2001 From: kadmin Date: Fri, 7 Jan 2022 03:58:32 +0000 Subject: [PATCH 0397/1222] Add term Instead of having a separate enum variant for types and consts have one but have either a const or type. --- clippy_utils/src/ast_utils.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index d4f037677e08..604c95d2bc81 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -645,13 +645,20 @@ pub fn eq_generic_bound(l: &GenericBound, r: &GenericBound) -> bool { } } +fn eq_term(l: &Term, r: &Term) -> bool { + match (l, r) { + (Term::Ty(l), Term::Ty(r)) => eq_ty(l,r), + (Term::Const(l), Term::Const(r)) => eq_anon_const(l,r), + _ => false, + } +} + pub fn eq_assoc_constraint(l: &AssocConstraint, r: &AssocConstraint) -> bool { use AssocConstraintKind::*; eq_id(l.ident, r.ident) && match (&l.kind, &r.kind) { - (Equality { ty: l }, Equality { ty: r }) => eq_ty(l, r), + (Equality { term: l }, Equality { term: r }) => eq_term(l, r), (Bound { bounds: l }, Bound { bounds: r }) => over(l, r, eq_generic_bound), - (ConstEquality { c: l }, ConstEquality { c: r }) => eq_anon_const(l, r), _ => false, } } From b41bd293c6aecdb83760c50b6a671760c2c4c641 Mon Sep 17 00:00:00 2001 From: kadmin Date: Sat, 8 Jan 2022 09:28:12 +0000 Subject: [PATCH 0398/1222] Use Term in ProjectionPredicate ProjectionPredicate should be able to handle both associated types and consts so this adds the first step of that. It mainly just pipes types all the way down, not entirely sure how to handle consts, but hopefully that'll come with time. --- clippy_lints/src/manual_async_fn.rs | 4 ++-- clippy_lints/src/methods/mod.rs | 4 ++-- clippy_lints/src/methods/unnecessary_to_owned.rs | 2 +- clippy_lints/src/unit_return_expecting_ord.rs | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 86819752f90f..2af3555e370a 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -6,7 +6,7 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{ - AsyncGeneratorKind, Block, Body, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound, HirId, + Term, AsyncGeneratorKind, Block, Body, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound, HirId, IsAsync, ItemKind, LifetimeName, TraitRef, Ty, TyKind, TypeBindingKind, }; use rustc_lint::{LateContext, LateLintPass}; @@ -140,7 +140,7 @@ fn future_output_ty<'tcx>(trait_ref: &'tcx TraitRef<'tcx>) -> Option<&'tcx Ty<'t if args.bindings.len() == 1; let binding = &args.bindings[0]; if binding.ident.name == sym::Output; - if let TypeBindingKind::Equality{ty: output} = binding.kind; + if let TypeBindingKind::Equality{term: Term::Ty(output)} = binding.kind; then { return Some(output) } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index ed5136e7d00f..c0e65e520f23 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2143,10 +2143,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() { // walk the associated type and check for Self if let Some(self_adt) = self_ty.ty_adt_def() { - if contains_adt_constructor(projection_predicate.ty, self_adt) { + if contains_adt_constructor(projection_predicate.term.ty(), self_adt) { return; } - } else if contains_ty(projection_predicate.ty, self_ty) { + } else if contains_ty(projection_predicate.term.ty(), self_ty) { return; } } diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index e5b6d296b2d2..865a36a5cd1d 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -243,7 +243,7 @@ fn check_other_call_arg<'tcx>( if if trait_predicate.def_id() == deref_trait_id { if let [projection_predicate] = projection_predicates[..] { let normalized_ty = - cx.tcx.subst_and_normalize_erasing_regions(call_substs, cx.param_env, projection_predicate.ty); + cx.tcx.subst_and_normalize_erasing_regions(call_substs, cx.param_env, projection_predicate.term.ty()); implements_trait(cx, receiver_ty, deref_trait_id, &[]) && get_associated_type(cx, receiver_ty, deref_trait_id, "Target") == Some(normalized_ty) } else { diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index fe35ff33d35a..09f9e1ee0999 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -98,9 +98,9 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve if trait_pred.self_ty() == inp; if let Some(return_ty_pred) = get_projection_pred(cx, generics, *trait_pred); then { - if ord_preds.iter().any(|ord| ord.self_ty() == return_ty_pred.ty) { + if ord_preds.iter().any(|ord| ord.self_ty() == return_ty_pred.term.ty()) { args_to_check.push((i, "Ord".to_string())); - } else if partial_ord_preds.iter().any(|pord| pord.self_ty() == return_ty_pred.ty) { + } else if partial_ord_preds.iter().any(|pord| pord.self_ty() == return_ty_pred.term.ty()) { args_to_check.push((i, "PartialOrd".to_string())); } } From 25304463eb3aa8d22973214888f66400e646f25a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 17 Jan 2022 11:04:41 -0800 Subject: [PATCH 0399/1222] Bless clippy ui tests after format_args change --- tests/ui/to_string_in_display.stderr | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/ui/to_string_in_display.stderr b/tests/ui/to_string_in_display.stderr index 5f26ef413e23..80189ca1f0ae 100644 --- a/tests/ui/to_string_in_display.stderr +++ b/tests/ui/to_string_in_display.stderr @@ -6,5 +6,14 @@ LL | write!(f, "{}", self.to_string()) | = note: `-D clippy::to-string-in-display` implied by `-D warnings` -error: aborting due to previous error +error: unnecessary use of `to_string` + --> $DIR/to_string_in_display.rs:55:50 + | +LL | Self::E(string) => write!(f, "E {}", string.to_string()), + | ^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::unnecessary-to-owned` implied by `-D warnings` + = note: this error originates in the macro `$crate::format_args` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 2 previous errors From 535613a62e425756b3b0e987c52a30fa0a0d4264 Mon Sep 17 00:00:00 2001 From: kadmin Date: Mon, 10 Jan 2022 23:39:21 +0000 Subject: [PATCH 0400/1222] Update term for use in more places Replace use of `ty()` on term and use it in more places. This will allow more flexibility in the future, but slightly worried it allows items which are consts which only accept types. --- clippy_lints/src/methods/mod.rs | 8 ++++++-- clippy_lints/src/methods/unnecessary_to_owned.rs | 5 +++-- clippy_lints/src/unit_return_expecting_ord.rs | 5 +++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index c0e65e520f23..ca8bbbd8f916 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2141,12 +2141,16 @@ impl<'tcx> LateLintPass<'tcx> for Methods { // one of the associated types must be Self for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) { if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() { + let assoc_ty = match projection_predicate.term { + ty::Term::Ty(ty) => ty, + ty::Term::Const(c) => c.ty, + }; // walk the associated type and check for Self if let Some(self_adt) = self_ty.ty_adt_def() { - if contains_adt_constructor(projection_predicate.term.ty(), self_adt) { + if contains_adt_constructor(assoc_ty, self_adt) { return; } - } else if contains_ty(projection_predicate.term.ty(), self_ty) { + } else if contains_ty(assoc_ty, self_ty) { return; } } diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 865a36a5cd1d..9162de3cceaf 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -243,9 +243,10 @@ fn check_other_call_arg<'tcx>( if if trait_predicate.def_id() == deref_trait_id { if let [projection_predicate] = projection_predicates[..] { let normalized_ty = - cx.tcx.subst_and_normalize_erasing_regions(call_substs, cx.param_env, projection_predicate.term.ty()); + cx.tcx.subst_and_normalize_erasing_regions(call_substs, cx.param_env, projection_predicate.term); implements_trait(cx, receiver_ty, deref_trait_id, &[]) - && get_associated_type(cx, receiver_ty, deref_trait_id, "Target") == Some(normalized_ty) + && get_associated_type(cx, receiver_ty, deref_trait_id, + "Target").map_or(false, |ty| ty::Term::Ty(ty) == normalized_ty) } else { false } diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 09f9e1ee0999..68156df2ecea 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -98,9 +98,10 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve if trait_pred.self_ty() == inp; if let Some(return_ty_pred) = get_projection_pred(cx, generics, *trait_pred); then { - if ord_preds.iter().any(|ord| ord.self_ty() == return_ty_pred.term.ty()) { + if ord_preds.iter().any(|ord| Some(ord.self_ty()) == + return_ty_pred.term.ty()) { args_to_check.push((i, "Ord".to_string())); - } else if partial_ord_preds.iter().any(|pord| pord.self_ty() == return_ty_pred.term.ty()) { + } else if partial_ord_preds.iter().any(|pord| pord.self_ty() == return_ty_pred.term.ty().unwrap()) { args_to_check.push((i, "PartialOrd".to_string())); } } From fb8ba7fd534e21bdf3861ebae7759add3e07957b Mon Sep 17 00:00:00 2001 From: kadmin Date: Tue, 11 Jan 2022 19:18:18 +0000 Subject: [PATCH 0401/1222] Update w/ comments Removes uses of ty() where a method is implemented on TypeFoldable, and also directly formats a Term. --- clippy_lints/src/methods/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index ca8bbbd8f916..d5b928de4a81 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2143,7 +2143,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() { let assoc_ty = match projection_predicate.term { ty::Term::Ty(ty) => ty, - ty::Term::Const(c) => c.ty, + ty::Term::Const(_c) => continue, }; // walk the associated type and check for Self if let Some(self_adt) = self_ty.ty_adt_def() { From 40fdb4e316255c4125b639c68041629b43be4050 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Wed, 12 Jan 2022 21:15:51 -0500 Subject: [PATCH 0402/1222] Store a `Symbol` instead of an `Ident` in `AssocItem` This is the same idea as #92533, but for `AssocItem` instead of `VariantDef`/`FieldDef`. With this change, we no longer have any uses of `#[stable_hasher(project(...))]` --- clippy_lints/src/same_name_method.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/same_name_method.rs b/clippy_lints/src/same_name_method.rs index 1bbaa104e60b..22b458969551 100644 --- a/clippy_lints/src/same_name_method.rs +++ b/clippy_lints/src/same_name_method.rs @@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod { .filter(|assoc_item| { matches!(assoc_item.kind, AssocKind::Fn) }) - .map(|assoc_item| assoc_item.ident.name) + .map(|assoc_item| assoc_item.name) .collect() }else{ BTreeSet::new() From 3ee196ff8916712171d83d29123e62601fba8db0 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Wed, 1 Dec 2021 11:17:50 -0600 Subject: [PATCH 0403/1222] Remove a span from hir::ExprKind::MethodCall --- clippy_lints/src/blocks_in_if_conditions.rs | 2 +- clippy_lints/src/booleans.rs | 2 +- clippy_lints/src/bytecount.rs | 6 +++--- ...ase_sensitive_file_extension_comparisons.rs | 2 +- .../src/casts/cast_possible_truncation.rs | 6 +++--- clippy_lints/src/casts/cast_ptr_alignment.rs | 2 +- clippy_lints/src/casts/cast_sign_loss.rs | 4 ++-- clippy_lints/src/default_numeric_fallback.rs | 2 +- clippy_lints/src/dereference.rs | 4 ++-- clippy_lints/src/duration_subsec.rs | 2 +- clippy_lints/src/entry.rs | 3 +-- clippy_lints/src/eta_reduction.rs | 2 +- clippy_lints/src/explicit_write.rs | 4 ++-- clippy_lints/src/floating_point_arithmetic.rs | 18 ++++++++---------- clippy_lints/src/format_args.rs | 2 +- clippy_lints/src/functions/must_use.rs | 2 +- .../src/functions/not_unsafe_ptr_arg_deref.rs | 2 +- clippy_lints/src/get_last_with_len.rs | 4 ++-- clippy_lints/src/if_let_mutex.rs | 2 +- clippy_lints/src/infinite_iter.rs | 4 ++-- clippy_lints/src/len_zero.rs | 2 +- clippy_lints/src/loops/manual_memcpy.rs | 4 ++-- clippy_lints/src/loops/mod.rs | 2 +- clippy_lints/src/loops/needless_collect.rs | 12 ++++++------ clippy_lints/src/loops/needless_range_loop.rs | 6 +++--- clippy_lints/src/loops/never_loop.rs | 2 +- clippy_lints/src/loops/same_item_push.rs | 2 +- clippy_lints/src/loops/single_element_loop.rs | 2 +- .../src/loops/while_let_on_iterator.rs | 2 +- clippy_lints/src/manual_ok_or.rs | 2 +- clippy_lints/src/manual_strip.rs | 4 ++-- clippy_lints/src/map_clone.rs | 4 ++-- clippy_lints/src/map_err_ignore.rs | 2 +- clippy_lints/src/map_unit_fn.rs | 2 +- clippy_lints/src/match_result_ok.rs | 4 ++-- clippy_lints/src/match_str_case_mismatch.rs | 3 +-- clippy_lints/src/matches.rs | 4 ++-- .../src/methods/bind_instead_of_map.rs | 4 ++-- clippy_lints/src/methods/clone_on_copy.rs | 4 ++-- clippy_lints/src/methods/expect_fun_call.rs | 2 +- clippy_lints/src/methods/extend_with_drain.rs | 2 +- clippy_lints/src/methods/filter_map.rs | 6 +++--- clippy_lints/src/methods/mod.rs | 13 +++++++------ .../src/methods/option_as_ref_deref.rs | 2 +- clippy_lints/src/methods/str_splitn.rs | 8 ++++---- .../src/methods/unnecessary_iter_cloned.rs | 4 ++-- .../src/methods/unnecessary_to_owned.rs | 2 +- clippy_lints/src/methods/useless_asref.rs | 4 ++-- clippy_lints/src/methods/utils.rs | 2 +- clippy_lints/src/minmax.rs | 2 +- clippy_lints/src/misc.rs | 2 +- clippy_lints/src/mut_mutex_lock.rs | 4 ++-- clippy_lints/src/mut_reference.rs | 2 +- clippy_lints/src/needless_for_each.rs | 4 ++-- clippy_lints/src/needless_option_as_deref.rs | 2 +- clippy_lints/src/non_octal_unix_permissions.rs | 2 +- clippy_lints/src/open_options.rs | 4 ++-- clippy_lints/src/option_if_let_else.rs | 2 +- clippy_lints/src/path_buf_push_overwrite.rs | 2 +- clippy_lints/src/ptr_offset_with_cast.rs | 2 +- clippy_lints/src/question_mark.rs | 2 +- clippy_lints/src/ranges.rs | 6 +++--- clippy_lints/src/repeat_once.rs | 2 +- clippy_lints/src/size_of_in_element_count.rs | 2 +- clippy_lints/src/slow_vector_initialization.rs | 6 +++--- clippy_lints/src/stable_sort_primitive.rs | 2 +- clippy_lints/src/strings.rs | 10 +++++----- clippy_lints/src/strlen_on_c_strings.rs | 2 +- clippy_lints/src/to_digit_is_some.rs | 4 ++-- clippy_lints/src/to_string_in_display.rs | 2 +- clippy_lints/src/uninit_vec.rs | 4 ++-- clippy_lints/src/unit_hash.rs | 2 +- clippy_lints/src/unit_return_expecting_ord.rs | 2 +- clippy_lints/src/unit_types/unit_arg.rs | 2 +- clippy_lints/src/unnecessary_sort_by.rs | 9 +++------ clippy_lints/src/unused_io_amount.rs | 6 +++--- clippy_lints/src/unwrap.rs | 4 ++-- clippy_lints/src/utils/author.rs | 4 ++-- clippy_lints/src/utils/inspector.rs | 2 +- clippy_lints/src/utils/internal_lints.rs | 6 +++--- .../utils/internal_lints/metadata_collector.rs | 2 +- clippy_lints/src/vec_init_then_push.rs | 2 +- clippy_lints/src/vec_resize_to_zero.rs | 2 +- clippy_lints/src/verbose_file_reads.rs | 4 ++-- clippy_utils/src/eager_or_lazy.rs | 2 +- clippy_utils/src/hir_utils.rs | 4 ++-- clippy_utils/src/lib.rs | 8 ++++---- clippy_utils/src/ptr.rs | 2 +- clippy_utils/src/sugg.rs | 6 +++--- doc/common_tools_writing_lints.md | 2 +- tests/ui/author/struct.stdout | 2 +- 91 files changed, 162 insertions(+), 168 deletions(-) diff --git a/clippy_lints/src/blocks_in_if_conditions.rs b/clippy_lints/src/blocks_in_if_conditions.rs index b3f9c1b29767..c4956bacf436 100644 --- a/clippy_lints/src/blocks_in_if_conditions.rs +++ b/clippy_lints/src/blocks_in_if_conditions.rs @@ -59,7 +59,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> { // do not lint if the closure is called using an iterator (see #1141) if_chain! { if let Some(parent) = get_parent_expr(self.cx, expr); - if let ExprKind::MethodCall(_, _, [self_arg, ..], _) = &parent.kind; + if let ExprKind::MethodCall(_, [self_arg, ..], _) = &parent.kind; let caller = self.cx.typeck_results().expr_ty(self_arg); if let Some(iter_id) = self.cx.tcx.get_diagnostic_item(sym::Iterator); if implements_trait(self.cx, caller, iter_id, &[]); diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 7ffc8ecd31e5..f7449c8dc72e 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -259,7 +259,7 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { )) }) }, - ExprKind::MethodCall(path, _, args, _) if args.len() == 1 => { + ExprKind::MethodCall(path, args, _) if args.len() == 1 => { let type_of_receiver = cx.typeck_results().expr_ty(&args[0]); if !is_type_diagnostic_item(cx, type_of_receiver, sym::Option) && !is_type_diagnostic_item(cx, type_of_receiver, sym::Result) diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index 92336a54e27e..02d97bf43df8 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -41,9 +41,9 @@ declare_lint_pass!(ByteCount => [NAIVE_BYTECOUNT]); impl<'tcx> LateLintPass<'tcx> for ByteCount { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { - if let ExprKind::MethodCall(count, _, [count_recv], _) = expr.kind; + if let ExprKind::MethodCall(count, [count_recv], _) = expr.kind; if count.ident.name == sym::count; - if let ExprKind::MethodCall(filter, _, [filter_recv, filter_arg], _) = count_recv.kind; + if let ExprKind::MethodCall(filter, [filter_recv, filter_arg], _) = count_recv.kind; if filter.ident.name == sym!(filter); if let ExprKind::Closure(_, _, body_id, _, _) = filter_arg.kind; let body = cx.tcx.hir().body(body_id); @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount { if ty::Uint(UintTy::U8) == *cx.typeck_results().expr_ty(needle).peel_refs().kind(); if !is_local_used(cx, needle, arg_id); then { - let haystack = if let ExprKind::MethodCall(path, _, args, _) = + let haystack = if let ExprKind::MethodCall(path, args, _) = filter_recv.kind { let p = path.ident.name; if (p == sym::iter || p == sym!(iter_mut)) && args.len() == 1 { diff --git a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs index e8f39cd37090..e71f110820c0 100644 --- a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs +++ b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs @@ -37,7 +37,7 @@ declare_lint_pass!(CaseSensitiveFileExtensionComparisons => [CASE_SENSITIVE_FILE fn check_case_sensitive_file_extension_comparison(ctx: &LateContext<'_>, expr: &Expr<'_>) -> Option { if_chain! { - if let ExprKind::MethodCall(PathSegment { ident, .. }, _, [obj, extension, ..], span) = expr.kind; + if let ExprKind::MethodCall(PathSegment { ident, .. }, [obj, extension, ..], span) = expr.kind; if ident.as_str() == "ends_with"; if let ExprKind::Lit(Spanned { node: LitKind::Str(ext_literal, ..), ..}) = extension.kind; if (2..=6).contains(&ext_literal.as_str().len()); diff --git a/clippy_lints/src/casts/cast_possible_truncation.rs b/clippy_lints/src/casts/cast_possible_truncation.rs index 4af412ccaf35..ea74d5acbda0 100644 --- a/clippy_lints/src/casts/cast_possible_truncation.rs +++ b/clippy_lints/src/casts/cast_possible_truncation.rs @@ -43,7 +43,7 @@ fn apply_reductions(cx: &LateContext<'_>, nbits: u64, expr: &Expr<'_>, signed: b }, _ => nbits, }, - ExprKind::MethodCall(method, _, [left, right], _) => { + ExprKind::MethodCall(method, [left, right], _) => { if signed { return nbits; } @@ -54,7 +54,7 @@ fn apply_reductions(cx: &LateContext<'_>, nbits: u64, expr: &Expr<'_>, signed: b }; apply_reductions(cx, nbits, left, signed).min(max_bits.unwrap_or(u64::max_value())) }, - ExprKind::MethodCall(method, _, [_, lo, hi], _) => { + ExprKind::MethodCall(method, [_, lo, hi], _) => { if method.ident.as_str() == "clamp" { //FIXME: make this a diagnostic item if let (Some(lo_bits), Some(hi_bits)) = (get_constant_bits(cx, lo), get_constant_bits(cx, hi)) { @@ -63,7 +63,7 @@ fn apply_reductions(cx: &LateContext<'_>, nbits: u64, expr: &Expr<'_>, signed: b } nbits }, - ExprKind::MethodCall(method, _, [_value], _) => { + ExprKind::MethodCall(method, [_value], _) => { if method.ident.name.as_str() == "signum" { 0 // do not lint if cast comes from a `signum` function } else { diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index b9de5510455b..079b7ff0675b 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -19,7 +19,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { cx.typeck_results().expr_ty(expr), ); lint_cast_ptr_alignment(cx, expr, cast_from, cast_to); - } else if let ExprKind::MethodCall(method_path, _, [self_arg, ..], _) = &expr.kind { + } else if let ExprKind::MethodCall(method_path, [self_arg, ..], _) = &expr.kind { if_chain! { if method_path.ident.name == sym!(cast); if let Some(generic_args) = method_path.args; diff --git a/clippy_lints/src/casts/cast_sign_loss.rs b/clippy_lints/src/casts/cast_sign_loss.rs index c9c111a2847a..75f70b77ed4e 100644 --- a/clippy_lints/src/casts/cast_sign_loss.rs +++ b/clippy_lints/src/casts/cast_sign_loss.rs @@ -41,14 +41,14 @@ fn should_lint(cx: &LateContext<'_>, cast_op: &Expr<'_>, cast_from: Ty<'_>, cast } // Don't lint for the result of methods that always return non-negative values. - if let ExprKind::MethodCall(path, _, _, _) = cast_op.kind { + if let ExprKind::MethodCall(path, _, _) = cast_op.kind { let mut method_name = path.ident.name.as_str(); let allowed_methods = ["abs", "checked_abs", "rem_euclid", "checked_rem_euclid"]; if_chain! { if method_name == "unwrap"; if let Some(arglist) = method_chain_args(cast_op, &["unwrap"]); - if let ExprKind::MethodCall(inner_path, _, _, _) = &arglist[0][0].kind; + if let ExprKind::MethodCall(inner_path, _, _) = &arglist[0][0].kind; then { method_name = inner_path.ident.name.as_str(); } diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index 78acdb5dfd58..fb201d2c012b 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -131,7 +131,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { } }, - ExprKind::MethodCall(_, _, args, _) => { + ExprKind::MethodCall(_, args, _) => { if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) { let fn_sig = self.cx.tcx.fn_sig(def_id).skip_binder(); for (expr, bound) in iter::zip(*args, fn_sig.inputs()) { diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index af46e99c6446..feb5f100de5d 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -361,7 +361,7 @@ fn try_parse_ref_op<'tcx>( expr: &'tcx Expr<'_>, ) -> Option<(RefOp, &'tcx Expr<'tcx>)> { let (def_id, arg) = match expr.kind { - ExprKind::MethodCall(_, _, [arg], _) => (typeck.type_dependent_def_id(expr.hir_id)?, arg), + ExprKind::MethodCall(_, [arg], _) => (typeck.type_dependent_def_id(expr.hir_id)?, arg), ExprKind::Call( Expr { kind: ExprKind::Path(path), @@ -408,7 +408,7 @@ fn is_linted_explicit_deref_position(parent: Option>, child_id: HirId, match parent.kind { // Leave deref calls in the middle of a method chain. // e.g. x.deref().foo() - ExprKind::MethodCall(_, _, [self_arg, ..], _) if self_arg.hir_id == child_id => false, + ExprKind::MethodCall(_, [self_arg, ..], _) if self_arg.hir_id == child_id => false, // Leave deref calls resulting in a called function // e.g. (x.deref())() diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index 50dd0d84fda5..24e32c09f44b 100644 --- a/clippy_lints/src/duration_subsec.rs +++ b/clippy_lints/src/duration_subsec.rs @@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for DurationSubsec { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, left, right) = expr.kind; - if let ExprKind::MethodCall(method_path, _ , args, _) = left.kind; + if let ExprKind::MethodCall(method_path, args, _) = left.kind; if match_type(cx, cx.typeck_results().expr_ty(&args[0]).peel_refs(), &paths::DURATION); if let Some((Constant::Int(divisor), _)) = constant(cx, cx.typeck_results(), right); then { diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 9c0a966b0bee..1ae2e20c1e06 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -244,7 +244,6 @@ fn try_parse_contains<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Optio }); match expr.kind { ExprKind::MethodCall( - _, _, [ map, @@ -281,7 +280,7 @@ struct InsertExpr<'tcx> { value: &'tcx Expr<'tcx>, } fn try_parse_insert<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option> { - if let ExprKind::MethodCall(_, _, [map, key, value], _) = expr.kind { + if let ExprKind::MethodCall(_, [map, key, value], _) = expr.kind { let id = cx.typeck_results().type_dependent_def_id(expr.hir_id)?; if match_def_path(cx, id, &paths::BTREEMAP_INSERT) || match_def_path(cx, id, &paths::HASHMAP_INSERT) { Some(InsertExpr { map, key, value }) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index b22515a39079..263bff4873ca 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { ); if_chain!( - if let ExprKind::MethodCall(path, _, args, _) = body.value.kind; + if let ExprKind::MethodCall(path, args, _) = body.value.kind; if check_inputs(cx, body.params, args); let method_def_id = cx.typeck_results().type_dependent_def_id(body.value.hir_id).unwrap(); let substs = cx.typeck_results().node_substs(body.value.hir_id); diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 98e5234e0aa9..f326fd83d18e 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -35,10 +35,10 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { // match call to unwrap - if let ExprKind::MethodCall(unwrap_fun, _, [write_call], _) = expr.kind; + if let ExprKind::MethodCall(unwrap_fun, [write_call], _) = expr.kind; if unwrap_fun.ident.name == sym::unwrap; // match call to write_fmt - if let ExprKind::MethodCall(write_fun, _, [write_recv, write_arg], _) = write_call.kind; + if let ExprKind::MethodCall(write_fun, [write_recv, write_arg], _) = write_call.kind; if write_fun.ident.name == sym!(write_fmt); // match calls to std::io::stdout() / std::io::stderr () if let Some(dest_name) = if match_function_call(cx, write_recv, &paths::STDOUT).is_some() { diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index 6dcbaf68dfdb..79ce53f7a5f2 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -303,7 +303,7 @@ fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { if value == Int(2) { if let Some(parent) = get_parent_expr(cx, expr) { if let Some(grandparent) = get_parent_expr(cx, parent) { - if let ExprKind::MethodCall(PathSegment { ident: method_name, .. }, _, args, _) = grandparent.kind { + if let ExprKind::MethodCall(PathSegment { ident: method_name, .. }, args, _) = grandparent.kind { if method_name.as_str() == "sqrt" && detect_hypot(cx, args).is_some() { return; } @@ -364,13 +364,11 @@ fn detect_hypot(cx: &LateContext<'_>, args: &[Expr<'_>]) -> Option { if_chain! { if let ExprKind::MethodCall( PathSegment { ident: lmethod_name, .. }, - _lspan, [largs_0, largs_1, ..], _ ) = &add_lhs.kind; if let ExprKind::MethodCall( PathSegment { ident: rmethod_name, .. }, - _rspan, [rargs_0, rargs_1, ..], _ ) = &add_rhs.kind; @@ -409,7 +407,7 @@ fn check_expm1(cx: &LateContext<'_>, expr: &Expr<'_>) { if cx.typeck_results().expr_ty(lhs).is_floating_point(); if let Some((value, _)) = constant(cx, cx.typeck_results(), rhs); if F32(1.0) == value || F64(1.0) == value; - if let ExprKind::MethodCall(path, _, [self_arg, ..], _) = &lhs.kind; + if let ExprKind::MethodCall(path, [self_arg, ..], _) = &lhs.kind; if cx.typeck_results().expr_ty(self_arg).is_floating_point(); if path.ident.name.as_str() == "exp"; then { @@ -453,7 +451,7 @@ fn check_mul_add(cx: &LateContext<'_>, expr: &Expr<'_>) { ) = &expr.kind { if let Some(parent) = get_parent_expr(cx, expr) { - if let ExprKind::MethodCall(PathSegment { ident: method_name, .. }, _, args, _) = parent.kind { + if let ExprKind::MethodCall(PathSegment { ident: method_name, .. }, args, _) = parent.kind { if method_name.as_str() == "sqrt" && detect_hypot(cx, args).is_some() { return; } @@ -589,8 +587,8 @@ fn check_custom_abs(cx: &LateContext<'_>, expr: &Expr<'_>) { fn are_same_base_logs(cx: &LateContext<'_>, expr_a: &Expr<'_>, expr_b: &Expr<'_>) -> bool { if_chain! { - if let ExprKind::MethodCall(PathSegment { ident: method_name_a, .. }, _, args_a, _) = expr_a.kind; - if let ExprKind::MethodCall(PathSegment { ident: method_name_b, .. }, _, args_b, _) = expr_b.kind; + if let ExprKind::MethodCall(PathSegment { ident: method_name_a, .. }, args_a, _) = expr_a.kind; + if let ExprKind::MethodCall(PathSegment { ident: method_name_b, .. }, args_b, _) = expr_b.kind; then { return method_name_a.as_str() == method_name_b.as_str() && args_a.len() == args_b.len() && @@ -615,8 +613,8 @@ fn check_log_division(cx: &LateContext<'_>, expr: &Expr<'_>) { rhs, ) = &expr.kind; if are_same_base_logs(cx, lhs, rhs); - if let ExprKind::MethodCall(_, _, [largs_self, ..], _) = &lhs.kind; - if let ExprKind::MethodCall(_, _, [rargs_self, ..], _) = &rhs.kind; + if let ExprKind::MethodCall(_, [largs_self, ..], _) = &lhs.kind; + if let ExprKind::MethodCall(_, [rargs_self, ..], _) = &rhs.kind; then { span_lint_and_sugg( cx, @@ -714,7 +712,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatingPointArithmetic { return; } - if let ExprKind::MethodCall(path, _, args, _) = &expr.kind { + if let ExprKind::MethodCall(path, args, _) = &expr.kind { let recv_ty = cx.typeck_results().expr_ty(&args[0]); if recv_ty.is_floating_point() { diff --git a/clippy_lints/src/format_args.rs b/clippy_lints/src/format_args.rs index ae423d799d71..17b0749a4a99 100644 --- a/clippy_lints/src/format_args.rs +++ b/clippy_lints/src/format_args.rs @@ -149,7 +149,7 @@ fn check_format_in_format_args(cx: &LateContext<'_>, call_site: Span, name: Symb fn check_to_string_in_format_args(cx: &LateContext<'_>, name: Symbol, value: &Expr<'_>) { if_chain! { if !value.span.from_expansion(); - if let ExprKind::MethodCall(_, _, [receiver], _) = value.kind; + if let ExprKind::MethodCall(_, [receiver], _) = value.kind; if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(value.hir_id); if is_diag_trait_item(cx, method_def_id, sym::ToString); let receiver_ty = cx.typeck_results().expr_ty(receiver); diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 2610f0ff384e..3e3718b9445f 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -217,7 +217,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { return; } match expr.kind { - Call(_, args) | MethodCall(_, _, args, _) => { + Call(_, args) | MethodCall(_, args, _) => { let mut tys = DefIdSet::default(); for arg in args { if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id()) diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index ab3dae4b67f9..830e3b32cfa2 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -88,7 +88,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { } } }, - hir::ExprKind::MethodCall(_, _, args, _) => { + hir::ExprKind::MethodCall(_, args, _) => { let def_id = self.typeck_results.type_dependent_def_id(expr.hir_id).unwrap(); let base_type = self.cx.tcx.type_of(def_id); diff --git a/clippy_lints/src/get_last_with_len.rs b/clippy_lints/src/get_last_with_len.rs index edca701869e0..df29d9308e71 100644 --- a/clippy_lints/src/get_last_with_len.rs +++ b/clippy_lints/src/get_last_with_len.rs @@ -51,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for GetLastWithLen { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { // Is a method call - if let ExprKind::MethodCall(path, _, args, _) = expr.kind; + if let ExprKind::MethodCall(path, args, _) = expr.kind; // Method name is "get" if path.ident.name == sym!(get); @@ -73,7 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for GetLastWithLen { ) = &get_index_arg.kind; // LHS of subtraction is "x.len()" - if let ExprKind::MethodCall(arg_lhs_path, _, lhs_args, _) = &lhs.kind; + if let ExprKind::MethodCall(arg_lhs_path, lhs_args, _) = &lhs.kind; if arg_lhs_path.ident.name == sym::len; if let Some(arg_lhs_struct) = lhs_args.get(0); diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index 0cc697d84255..e95017007849 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -127,7 +127,7 @@ impl<'tcx, 'l> ArmVisitor<'tcx, 'l> { fn is_mutex_lock_call<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { if_chain! { - if let ExprKind::MethodCall(path, _span, [self_arg, ..], _) = &expr.kind; + if let ExprKind::MethodCall(path, [self_arg, ..], _) = &expr.kind; if path.ident.as_str() == "lock"; let ty = cx.typeck_results().expr_ty(self_arg); if is_type_diagnostic_item(cx, ty, sym::Mutex); diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index c7db47a552b2..3008e86ef8b2 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -145,7 +145,7 @@ const HEURISTICS: [(&str, usize, Heuristic, Finiteness); 19] = [ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { match expr.kind { - ExprKind::MethodCall(method, _, args, _) => { + ExprKind::MethodCall(method, args, _) => { for &(name, len, heuristic, cap) in &HEURISTICS { if method.ident.name.as_str() == name && args.len() == len { return (match heuristic { @@ -221,7 +221,7 @@ const INFINITE_COLLECTORS: &[Symbol] = &[ fn complete_infinite_iter(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { match expr.kind { - ExprKind::MethodCall(method, _, args, _) => { + ExprKind::MethodCall(method, args, _) => { for &(name, len) in &COMPLETING_METHODS { if method.ident.name.as_str() == name && args.len() == len { return is_infinite(cx, &args[0]); diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index e1168c3f6022..530b0a90ebd8 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -370,7 +370,7 @@ fn check_for_is_empty( } fn check_cmp(cx: &LateContext<'_>, span: Span, method: &Expr<'_>, lit: &Expr<'_>, op: &str, compare_to: u32) { - if let (&ExprKind::MethodCall(method_path, _, args, _), &ExprKind::Lit(ref lit)) = (&method.kind, &lit.kind) { + if let (&ExprKind::MethodCall(method_path, args, _), &ExprKind::Lit(ref lit)) = (&method.kind, &lit.kind) { // check if we are in an is_empty() method if let Some(name) = get_item_name(cx, method) { if name.as_str() == "is_empty" { diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index 48c4015e07b6..ef0221639aa9 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -119,7 +119,7 @@ fn build_manual_memcpy_suggestion<'tcx>( let print_limit = |end: &Expr<'_>, end_str: &str, base: &Expr<'_>, sugg: MinifyingSugg<'static>| { if_chain! { - if let ExprKind::MethodCall(method, _, len_args, _) = end.kind; + if let ExprKind::MethodCall(method, len_args, _) = end.kind; if method.ident.name == sym::len; if len_args.len() == 1; if let Some(arg) = len_args.get(0); @@ -343,7 +343,7 @@ fn get_slice_like_element_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Opti fn fetch_cloned_expr<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { if_chain! { - if let ExprKind::MethodCall(method, _, args, _) = expr.kind; + if let ExprKind::MethodCall(method, args, _) = expr.kind; if method.ident.name == sym::clone; if args.len() == 1; if let Some(arg) = args.get(0); diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index b03445b8cd6b..5bc32acf56ec 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -658,7 +658,7 @@ fn check_for_loop<'tcx>( fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) { let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used - if let ExprKind::MethodCall(method, _, [self_arg], _) = arg.kind { + if let ExprKind::MethodCall(method, [self_arg], _) = arg.kind { let method_name = method.ident.as_str(); // check for looping over x.iter() or x.iter_mut(), could use &x or &mut x match method_name { diff --git a/clippy_lints/src/loops/needless_collect.rs b/clippy_lints/src/loops/needless_collect.rs index f7d3227af017..f57dcc2f5c45 100644 --- a/clippy_lints/src/loops/needless_collect.rs +++ b/clippy_lints/src/loops/needless_collect.rs @@ -24,8 +24,8 @@ pub(super) fn check<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) { } fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) { if_chain! { - if let ExprKind::MethodCall(method, _, args, _) = expr.kind; - if let ExprKind::MethodCall(chain_method, method0_span, _, _) = args[0].kind; + if let ExprKind::MethodCall(method, args, _) = expr.kind; + if let ExprKind::MethodCall(chain_method, _, _) = args[0].kind; if chain_method.ident.name == sym!(collect) && is_trait_method(cx, &args[0], sym::Iterator); then { let ty = cx.typeck_results().expr_ty(&args[0]); @@ -62,7 +62,7 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont span_lint_and_sugg( cx, NEEDLESS_COLLECT, - method0_span.with_hi(expr.span.hi()), + chain_method.ident.span.with_hi(expr.span.hi()), NEEDLESS_COLLECT_MSG, "replace with", sugg, @@ -79,7 +79,7 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo if let StmtKind::Local(local) = stmt.kind; if let PatKind::Binding(_, id, ..) = local.pat.kind; if let Some(init_expr) = local.init; - if let ExprKind::MethodCall(method_name, collect_span, &[ref iter_source], ..) = init_expr.kind; + if let ExprKind::MethodCall(method_name, &[ref iter_source], ..) = init_expr.kind; if method_name.ident.name == sym!(collect) && is_trait_method(cx, init_expr, sym::Iterator); let ty = cx.typeck_results().expr_ty(init_expr); if is_type_diagnostic_item(cx, ty, sym::Vec) || @@ -101,7 +101,7 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo } // Suggest replacing iter_call with iter_replacement, and removing stmt - let mut span = MultiSpan::from_span(collect_span); + let mut span = MultiSpan::from_span(method_name.ident.span); span.push_span_label(iter_call.span, "the iterator could be used here instead".into()); span_lint_hir_and_then( cx, @@ -193,7 +193,7 @@ impl<'tcx> Visitor<'tcx> for IterFunctionVisitor<'_, 'tcx> { fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { // Check function calls on our collection - if let ExprKind::MethodCall(method_name, _, [recv, args @ ..], _) = &expr.kind { + if let ExprKind::MethodCall(method_name, [recv, args @ ..], _) = &expr.kind { if method_name.ident.name == sym!(collect) && is_trait_method(self.cx, expr, sym::Iterator) { self.current_mutably_captured_ids = get_captured_ids(self.cx, self.cx.typeck_results().expr_ty(recv)); self.visit_expr(recv); diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 22da21bc6bc4..9d335073e4fb 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -186,7 +186,7 @@ pub(super) fn check<'tcx>( fn is_len_call(expr: &Expr<'_>, var: Symbol) -> bool { if_chain! { - if let ExprKind::MethodCall(method, _, len_args, _) = expr.kind; + if let ExprKind::MethodCall(method, len_args, _) = expr.kind; if len_args.len() == 1; if method.ident.name == sym::len; if let ExprKind::Path(QPath::Resolved(_, path)) = len_args[0].kind; @@ -296,7 +296,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if_chain! { // a range index op - if let ExprKind::MethodCall(meth, _, [args_0, args_1, ..], _) = &expr.kind; + if let ExprKind::MethodCall(meth, [args_0, args_1, ..], _) = &expr.kind; if (meth.ident.name == sym::index && match_trait_method(self.cx, expr, &paths::INDEX)) || (meth.ident.name == sym::index_mut && match_trait_method(self.cx, expr, &paths::INDEX_MUT)); if !self.check(args_1, args_0, expr); @@ -351,7 +351,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { self.visit_expr(expr); } }, - ExprKind::MethodCall(_, _, args, _) => { + ExprKind::MethodCall(_, args, _) => { let def_id = self.cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap(); for (ty, expr) in iter::zip(self.cx.tcx.fn_sig(def_id).inputs().skip_binder(), args) { self.prefer_mutable = false; diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index 3bfc62b19ef2..a0b2302662e6 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -121,7 +121,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { | ExprKind::Repeat(e, _) | ExprKind::DropTemps(e) => never_loop_expr(e, main_loop_id), ExprKind::Let(let_expr) => never_loop_expr(let_expr.init, main_loop_id), - ExprKind::Array(es) | ExprKind::MethodCall(_, _, es, _) | ExprKind::Tup(es) => { + ExprKind::Array(es) | ExprKind::MethodCall(_, es, _) | ExprKind::Tup(es) => { never_loop_expr_all(&mut es.iter(), main_loop_id) }, ExprKind::Call(e, es) => never_loop_expr_all(&mut once(e).chain(es.iter()), main_loop_id), diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index c61b411708c2..e048d744fc3b 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -180,7 +180,7 @@ fn get_vec_push<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) -> Option<(& if_chain! { // Extract method being called if let StmtKind::Semi(semi_stmt) = &stmt.kind; - if let ExprKind::MethodCall(path, _, args, _) = &semi_stmt.kind; + if let ExprKind::MethodCall(path, args, _) = &semi_stmt.kind; // Figure out the parameters for the method call if let Some(self_expr) = args.get(0); if let Some(pushed_item) = args.get(1); diff --git a/clippy_lints/src/loops/single_element_loop.rs b/clippy_lints/src/loops/single_element_loop.rs index e39605f3e7d6..15f419e4410c 100644 --- a/clippy_lints/src/loops/single_element_loop.rs +++ b/clippy_lints/src/loops/single_element_loop.rs @@ -16,7 +16,7 @@ pub(super) fn check<'tcx>( ) { let arg_expr = match arg.kind { ExprKind::AddrOf(BorrowKind::Ref, _, ref_arg) => ref_arg, - ExprKind::MethodCall(method, _, args, _) if args.len() == 1 && method.ident.name == rustc_span::sym::iter => { + ExprKind::MethodCall(method, args, _) if args.len() == 1 && method.ident.name == rustc_span::sym::iter => { &args[0] }, _ => return, diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index e0b235c35598..20a8294a0d1a 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -21,7 +21,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let Res::Def(_, pat_did) = pat_path.res; if match_def_path(cx, pat_did, &paths::OPTION_SOME); // check for call to `Iterator::next` - if let ExprKind::MethodCall(method_name, _, [iter_expr], _) = let_expr.kind; + if let ExprKind::MethodCall(method_name, [iter_expr], _) = let_expr.kind; if method_name.ident.name == sym::next; if is_trait_method(cx, let_expr, sym::Iterator); if let Some(iter_expr_struct) = try_parse_iter_expr(cx, iter_expr); diff --git a/clippy_lints/src/manual_ok_or.rs b/clippy_lints/src/manual_ok_or.rs index bd083e3e9e20..bf4ab29d9087 100644 --- a/clippy_lints/src/manual_ok_or.rs +++ b/clippy_lints/src/manual_ok_or.rs @@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualOkOr { } if_chain! { - if let ExprKind::MethodCall(method_segment, _, args, _) = scrutinee.kind; + if let ExprKind::MethodCall(method_segment, args, _) = scrutinee.kind; if method_segment.ident.name == sym!(map_or); if args.len() == 3; let method_receiver = &args[0]; diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index 039cb3aafdb7..c814e013c631 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { if_chain! { if let Some(higher::If { cond, then, .. }) = higher::If::hir(expr); - if let ExprKind::MethodCall(_, _, [target_arg, pattern], _) = cond.kind; + if let ExprKind::MethodCall(_, [target_arg, pattern], _) = cond.kind; if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(cond.hir_id); if let ExprKind::Path(target_path) = &target_arg.kind; then { @@ -132,7 +132,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { // Returns `Some(arg)` if `expr` matches `arg.len()` and `None` otherwise. fn len_arg<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { if_chain! { - if let ExprKind::MethodCall(_, _, [arg], _) = expr.kind; + if let ExprKind::MethodCall(_, [arg], _) = expr.kind; if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if match_def_path(cx, method_def_id, &paths::STR_LEN); then { diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 174c7da28d3e..22a2552b283a 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -51,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone { } if_chain! { - if let hir::ExprKind::MethodCall(method, _, args, _) = e.kind; + if let hir::ExprKind::MethodCall(method, args, _) = e.kind; if args.len() == 2; if method.ident.name == sym::map; let ty = cx.typeck_results().expr_ty(&args[0]); @@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone { } } }, - hir::ExprKind::MethodCall(method, _, [obj], _) => if_chain! { + hir::ExprKind::MethodCall(method, [obj], _) => if_chain! { if ident_eq(name, obj) && method.ident.name == sym::clone; if let Some(fn_id) = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id); if let Some(trait_id) = cx.tcx.trait_of_item(fn_id); diff --git a/clippy_lints/src/map_err_ignore.rs b/clippy_lints/src/map_err_ignore.rs index 61f21d532c50..e3a42de0b7c1 100644 --- a/clippy_lints/src/map_err_ignore.rs +++ b/clippy_lints/src/map_err_ignore.rs @@ -113,7 +113,7 @@ impl<'tcx> LateLintPass<'tcx> for MapErrIgnore { } // check if this is a method call (e.g. x.foo()) - if let ExprKind::MethodCall(method, _t_span, args, _) = e.kind { + if let ExprKind::MethodCall(method, args, _) = e.kind { // only work if the method name is `map_err` and there are only 2 arguments (e.g. x.map_err(|_|[1] // Enum::Variant[2])) if method.ident.as_str() == "map_err" && args.len() == 2 { diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 58c686d95b3f..0f6ac4784324 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -129,7 +129,7 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_>, expr: &'a hir::Expr<'_>) -> } match expr.kind { - hir::ExprKind::Call(_, _) | hir::ExprKind::MethodCall(_, _, _, _) => { + hir::ExprKind::Call(_, _) | hir::ExprKind::MethodCall(..) => { // Calls can't be reduced any more Some(expr.span) }, diff --git a/clippy_lints/src/match_result_ok.rs b/clippy_lints/src/match_result_ok.rs index b1839f00aaee..77a4917ec58f 100644 --- a/clippy_lints/src/match_result_ok.rs +++ b/clippy_lints/src/match_result_ok.rs @@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for MatchResultOk { }; if_chain! { - if let ExprKind::MethodCall(_, ok_span, [ref result_types_0, ..], _) = let_expr.kind; //check is expr.ok() has type Result.ok(, _) + if let ExprKind::MethodCall(ok_path, [ref result_types_0, ..], _) = let_expr.kind; //check is expr.ok() has type Result.ok(, _) if let PatKind::TupleStruct(QPath::Resolved(_, x), y, _) = let_pat.kind; //get operation if method_chain_args(let_expr, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized; if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(result_types_0), sym::Result); @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for MatchResultOk { let mut applicability = Applicability::MachineApplicable; let some_expr_string = snippet_with_applicability(cx, y[0].span, "", &mut applicability); - let trimmed_ok = snippet_with_applicability(cx, let_expr.span.until(ok_span), "", &mut applicability); + let trimmed_ok = snippet_with_applicability(cx, let_expr.span.until(ok_path.ident.span), "", &mut applicability); let sugg = format!( "{} let Ok({}) = {}", ifwhile, diff --git a/clippy_lints/src/match_str_case_mismatch.rs b/clippy_lints/src/match_str_case_mismatch.rs index b0eebf35e274..85aec93670b9 100644 --- a/clippy_lints/src/match_str_case_mismatch.rs +++ b/clippy_lints/src/match_str_case_mismatch.rs @@ -87,8 +87,7 @@ struct MatchExprVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for MatchExprVisitor<'a, 'tcx> { fn visit_expr(&mut self, ex: &'tcx Expr<'_>) { match ex.kind { - ExprKind::MethodCall(segment, _, [receiver], _) if self.case_altered(segment.ident.as_str(), receiver) => { - }, + ExprKind::MethodCall(segment, [receiver], _) if self.case_altered(segment.ident.as_str(), receiver) => {}, _ => walk_expr(self, ex), } } diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 33d022c73a5e..411a797b6cb5 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -1909,7 +1909,7 @@ mod redundant_pattern_match { }, // Method calls can take self by reference. // e.g. In `String::new().len()` the string is a temporary value. - ExprKind::MethodCall(_, _, [self_arg, args @ ..], _) => { + ExprKind::MethodCall(_, [self_arg, args @ ..], _) => { if !matches!(self_arg.kind, ExprKind::Path(_)) { let self_by_ref = self .cx @@ -2020,7 +2020,7 @@ mod redundant_pattern_match { // check that `while_let_on_iterator` lint does not trigger if_chain! { if keyword == "while"; - if let ExprKind::MethodCall(method_path, _, _, _) = let_expr.kind; + if let ExprKind::MethodCall(method_path, _, _) = let_expr.kind; if method_path.ident.name == sym::next; if is_trait_method(cx, let_expr, sym::Iterator); then { diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs index 150bafc0f5db..ce958b8ac9f5 100644 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/clippy_lints/src/methods/bind_instead_of_map.rs @@ -121,9 +121,9 @@ pub(crate) trait BindInsteadOfMap { }); let (span, msg) = if_chain! { if can_sugg; - if let hir::ExprKind::MethodCall(_, span, ..) = expr.kind; + if let hir::ExprKind::MethodCall(segment, ..) = expr.kind; if let Some(msg) = Self::lint_msg(cx); - then { (span, msg) } else { return false; } + then { (segment.ident.span, msg) } else { return false; } }; span_lint_and_then(cx, BIND_INSTEAD_OF_MAP, expr.span, &msg, |diag| { multispan_sugg_with_applicability( diff --git a/clippy_lints/src/methods/clone_on_copy.rs b/clippy_lints/src/methods/clone_on_copy.rs index b4dacb2580c3..0b38a07204e8 100644 --- a/clippy_lints/src/methods/clone_on_copy.rs +++ b/clippy_lints/src/methods/clone_on_copy.rs @@ -81,12 +81,12 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol, // &*x is a nop, &x.clone() is not ExprKind::AddrOf(..) => return, // (*x).func() is useless, x.clone().func() can work in case func borrows self - ExprKind::MethodCall(_, _, [self_arg, ..], _) + ExprKind::MethodCall(_, [self_arg, ..], _) if expr.hir_id == self_arg.hir_id && ty != cx.typeck_results().expr_ty_adjusted(expr) => { return; }, - ExprKind::MethodCall(_, _, [self_arg, ..], _) if expr.hir_id == self_arg.hir_id => true, + ExprKind::MethodCall(_, [self_arg, ..], _) if expr.hir_id == self_arg.hir_id => true, ExprKind::Match(_, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar) | ExprKind::Field(..) | ExprKind::Index(..) => true, diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index 0f39470f3426..e7d2d550a303 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -28,7 +28,7 @@ pub(super) fn check<'tcx>( loop { arg_root = match &arg_root.kind { hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, expr) => expr, - hir::ExprKind::MethodCall(method_name, _, call_args, _) => { + hir::ExprKind::MethodCall(method_name, call_args, _) => { if call_args.len() == 1 && (method_name.ident.name == sym::as_str || method_name.ident.name == sym!(as_ref)) && { diff --git a/clippy_lints/src/methods/extend_with_drain.rs b/clippy_lints/src/methods/extend_with_drain.rs index 687636f8237f..a15fe6094022 100644 --- a/clippy_lints/src/methods/extend_with_drain.rs +++ b/clippy_lints/src/methods/extend_with_drain.rs @@ -14,7 +14,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: if_chain! { if is_type_diagnostic_item(cx, ty, sym::Vec); //check source object - if let ExprKind::MethodCall(src_method, _, [drain_vec, drain_arg], _) = &arg.kind; + if let ExprKind::MethodCall(src_method, [drain_vec, drain_arg], _) = &arg.kind; if src_method.ident.as_str() == "drain"; let src_ty = cx.typeck_results().expr_ty(drain_vec); //check if actual src type is mutable for code suggestion diff --git a/clippy_lints/src/methods/filter_map.rs b/clippy_lints/src/methods/filter_map.rs index 6d8733c08b43..ba1af9f3d62b 100644 --- a/clippy_lints/src/methods/filter_map.rs +++ b/clippy_lints/src/methods/filter_map.rs @@ -28,7 +28,7 @@ fn is_method<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, method_name: Sy let closure_expr = peel_blocks(&body.value); let arg_id = body.params[0].pat.hir_id; match closure_expr.kind { - hir::ExprKind::MethodCall(hir::PathSegment { ident, .. }, _, args, _) => { + hir::ExprKind::MethodCall(hir::PathSegment { ident, .. }, args, _) => { if_chain! { if ident.name == method_name; if let hir::ExprKind::Path(path) = &args[0].kind; @@ -118,7 +118,7 @@ pub(super) fn check<'tcx>( }; // closure ends with is_some() or is_ok() if let PatKind::Binding(_, filter_param_id, _, None) = filter_pat.kind; - if let ExprKind::MethodCall(path, _, [filter_arg], _) = filter_body.value.kind; + if let ExprKind::MethodCall(path, [filter_arg], _) = filter_body.value.kind; if let Some(opt_ty) = cx.typeck_results().expr_ty(filter_arg).ty_adt_def(); if let Some(is_result) = if cx.tcx.is_diagnostic_item(sym::Option, opt_ty.did) { Some(false) @@ -135,7 +135,7 @@ pub(super) fn check<'tcx>( if let [map_param] = map_body.params; if let PatKind::Binding(_, map_param_id, map_param_ident, None) = map_param.pat.kind; // closure ends with expect() or unwrap() - if let ExprKind::MethodCall(seg, _, [map_arg, ..], _) = map_body.value.kind; + if let ExprKind::MethodCall(seg, [map_arg, ..], _) = map_body.value.kind; if matches!(seg.ident.name, sym::expect | sym::unwrap | sym::unwrap_or); let eq_fallback = |a: &Expr<'_>, b: &Expr<'_>| { diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index a9a06c3db755..137c9628eb45 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2039,10 +2039,10 @@ impl_lint_pass!(Methods => [ /// Extracts a method call name, args, and `Span` of the method name. fn method_call<'tcx>(recv: &'tcx hir::Expr<'tcx>) -> Option<(&'tcx str, &'tcx [hir::Expr<'tcx>], Span)> { - if let ExprKind::MethodCall(path, span, args, _) = recv.kind { + if let ExprKind::MethodCall(path, args, _) = recv.kind { if !args.iter().any(|e| e.span.from_expansion()) { let name = path.ident.name.as_str(); - return Some((name, args, span)); + return Some((name, args, path.ident.span)); } } None @@ -2060,14 +2060,15 @@ impl<'tcx> LateLintPass<'tcx> for Methods { hir::ExprKind::Call(func, args) => { from_iter_instead_of_collect::check(cx, expr, args, func); }, - hir::ExprKind::MethodCall(method_call, ref method_span, args, _) => { - or_fun_call::check(cx, expr, *method_span, method_call.ident.as_str(), args); - expect_fun_call::check(cx, expr, *method_span, method_call.ident.as_str(), args); + hir::ExprKind::MethodCall(method_call, args, _) => { + let method_span = method_call.ident.span; + or_fun_call::check(cx, expr, method_span, method_call.ident.as_str(), args); + expect_fun_call::check(cx, expr, method_span, method_call.ident.as_str(), args); clone_on_copy::check(cx, expr, method_call.ident.name, args); clone_on_ref_ptr::check(cx, expr, method_call.ident.name, args); inefficient_to_string::check(cx, expr, method_call.ident.name, args); single_char_add_str::check(cx, expr, args); - into_iter_on_ref::check(cx, expr, *method_span, method_call.ident.name, args); + into_iter_on_ref::check(cx, expr, method_span, method_call.ident.name, args); single_char_pattern::check(cx, expr, method_call.ident.name, args); unnecessary_to_owned::check(cx, expr, method_call.ident.name, args); }, diff --git a/clippy_lints/src/methods/option_as_ref_deref.rs b/clippy_lints/src/methods/option_as_ref_deref.rs index fa74a8f3dc36..ba2d2914315f 100644 --- a/clippy_lints/src/methods/option_as_ref_deref.rs +++ b/clippy_lints/src/methods/option_as_ref_deref.rs @@ -56,7 +56,7 @@ pub(super) fn check<'tcx>( let closure_expr = peel_blocks(&closure_body.value); match &closure_expr.kind { - hir::ExprKind::MethodCall(_, _, args, _) => { + hir::ExprKind::MethodCall(_, args, _) => { if_chain! { if args.len() == 1; if path_to_local_id(&args[0], closure_body.params[0].pat.hir_id); diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 514bdadc442e..b2f624ed480e 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -132,7 +132,7 @@ fn parse_iter_usage<'tcx>( ) -> Option { let (kind, span) = match iter.next() { Some((_, Node::Expr(e))) if e.span.ctxt() == ctxt => { - let (name, args) = if let ExprKind::MethodCall(name, _, [_, args @ ..], _) = e.kind { + let (name, args) = if let ExprKind::MethodCall(name, [_, args @ ..], _) = e.kind { (name, args) } else { return None; @@ -173,7 +173,7 @@ fn parse_iter_usage<'tcx>( } else { if_chain! { if let Some((_, Node::Expr(next_expr))) = iter.next(); - if let ExprKind::MethodCall(next_name, _, [_], _) = next_expr.kind; + if let ExprKind::MethodCall(next_name, [_], _) = next_expr.kind; if next_name.ident.name == sym::next; if next_expr.span.ctxt() == ctxt; if let Some(next_id) = cx.typeck_results().type_dependent_def_id(next_expr.hir_id); @@ -217,7 +217,7 @@ fn parse_iter_usage<'tcx>( } }, _ if e.span.ctxt() != ctxt => (None, span), - ExprKind::MethodCall(name, _, [_], _) + ExprKind::MethodCall(name, [_], _) if name.ident.name == sym::unwrap && cx .typeck_results() @@ -289,7 +289,7 @@ fn check_iter<'tcx>( ) -> bool { match iter.next() { Some((_, Node::Expr(e))) if e.span.ctxt() == ctxt => { - let (name, args) = if let ExprKind::MethodCall(name, _, [_, args @ ..], _) = e.kind { + let (name, args) = if let ExprKind::MethodCall(name, [_, args @ ..], _) = e.kind { (name, args) } else { return false; diff --git a/clippy_lints/src/methods/unnecessary_iter_cloned.rs b/clippy_lints/src/methods/unnecessary_iter_cloned.rs index 5fee18c5129a..65e94c5f44a9 100644 --- a/clippy_lints/src/methods/unnecessary_iter_cloned.rs +++ b/clippy_lints/src/methods/unnecessary_iter_cloned.rs @@ -45,7 +45,7 @@ pub fn check_for_loop_iter( if let Some(receiver_snippet) = snippet_opt(cx, receiver.span); then { let snippet = if_chain! { - if let ExprKind::MethodCall(maybe_iter_method_name, _, [collection], _) = receiver.kind; + if let ExprKind::MethodCall(maybe_iter_method_name, [collection], _) = receiver.kind; if maybe_iter_method_name.ident.name == sym::iter; if let Some(iterator_trait_id) = cx.tcx.get_diagnostic_item(sym::Iterator); @@ -155,7 +155,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for CloneOrCopyVisitor<'cx, 'tcx> { self.addr_of_exprs.push(parent); return; }, - ExprKind::MethodCall(_, _, args, _) => { + ExprKind::MethodCall(_, args, _) => { if_chain! { if args.iter().skip(1).all(|arg| !self.is_binding(arg)); if let Some(method_def_id) = self.cx.typeck_results().type_dependent_def_id(parent.hir_id); diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 9162de3cceaf..b67bfb6597b0 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -313,7 +313,7 @@ fn get_callee_substs_and_args<'tcx>( } } if_chain! { - if let ExprKind::MethodCall(_, _, args, _) = expr.kind; + if let ExprKind::MethodCall(_, args, _) = expr.kind; if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); then { let substs = cx.typeck_results().node_substs(expr.hir_id); diff --git a/clippy_lints/src/methods/useless_asref.rs b/clippy_lints/src/methods/useless_asref.rs index e0b1de68b37d..ca5d33ee8b07 100644 --- a/clippy_lints/src/methods/useless_asref.rs +++ b/clippy_lints/src/methods/useless_asref.rs @@ -23,8 +23,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str, // allow the `as_ref` or `as_mut` if it is followed by another method call if_chain! { if let Some(parent) = get_parent_expr(cx, expr); - if let hir::ExprKind::MethodCall(_, ref span, _, _) = parent.kind; - if span != &expr.span; + if let hir::ExprKind::MethodCall(segment, ..) = parent.kind; + if segment.ident.span != expr.span; then { return; } diff --git a/clippy_lints/src/methods/utils.rs b/clippy_lints/src/methods/utils.rs index 24b44f819f41..c4cf994aacaa 100644 --- a/clippy_lints/src/methods/utils.rs +++ b/clippy_lints/src/methods/utils.rs @@ -24,7 +24,7 @@ pub(super) fn derefs_to_slice<'tcx>( } } - if let hir::ExprKind::MethodCall(path, _, [self_arg, ..], _) = &expr.kind { + if let hir::ExprKind::MethodCall(path, [self_arg, ..], _) = &expr.kind { if path.ident.name == sym::iter && may_slice(cx, cx.typeck_results().expr_ty(self_arg)) { Some(self_arg) } else { diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index a6450aec4f7d..cf9770f5c1fd 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -86,7 +86,7 @@ fn min_max<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(MinMax, Cons None } }, - ExprKind::MethodCall(path, _, args, _) => { + ExprKind::MethodCall(path, args, _) => { if_chain! { if let [obj, _] = args; if cx.typeck_results().expr_ty(obj).is_floating_point() || match_trait_method(cx, expr, &paths::ORD); diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 8db71d1e9676..3918bdbdf438 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -523,7 +523,7 @@ fn is_signum(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { } if_chain! { - if let ExprKind::MethodCall(method_name, _, [ref self_arg, ..], _) = expr.kind; + if let ExprKind::MethodCall(method_name, [ref self_arg, ..], _) = expr.kind; if sym!(signum) == method_name.ident.name; // Check that the receiver of the signum() is a float (expressions[0] is the receiver of // the method call) diff --git a/clippy_lints/src/mut_mutex_lock.rs b/clippy_lints/src/mut_mutex_lock.rs index b1e6308d2e1a..7871be41d629 100644 --- a/clippy_lints/src/mut_mutex_lock.rs +++ b/clippy_lints/src/mut_mutex_lock.rs @@ -49,7 +49,7 @@ declare_lint_pass!(MutMutexLock => [MUT_MUTEX_LOCK]); impl<'tcx> LateLintPass<'tcx> for MutMutexLock { fn check_expr(&mut self, cx: &LateContext<'tcx>, ex: &'tcx Expr<'tcx>) { if_chain! { - if let ExprKind::MethodCall(path, method_span, [self_arg, ..], _) = &ex.kind; + if let ExprKind::MethodCall(path, [self_arg, ..], _) = &ex.kind; if path.ident.name == sym!(lock); let ty = cx.typeck_results().expr_ty(self_arg); if let ty::Ref(_, inner_ty, Mutability::Mut) = ty.kind(); @@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for MutMutexLock { span_lint_and_sugg( cx, MUT_MUTEX_LOCK, - *method_span, + path.ident.span, "calling `&mut Mutex::lock` unnecessarily locks an exclusive (mutable) reference", "change this to", "get_mut".to_owned(), diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 22834cf61ee0..5c3e505c06c4 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed { ); } }, - ExprKind::MethodCall(path, _, arguments, _) => { + ExprKind::MethodCall(path, arguments, _) => { let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap(); let substs = cx.typeck_results().node_substs(e.hir_id); let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs); diff --git a/clippy_lints/src/needless_for_each.rs b/clippy_lints/src/needless_for_each.rs index 44c4b70524d9..6cf513b214e6 100644 --- a/clippy_lints/src/needless_for_each.rs +++ b/clippy_lints/src/needless_for_each.rs @@ -56,12 +56,12 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessForEach { if_chain! { // Check the method name is `for_each`. - if let ExprKind::MethodCall(method_name, _, [for_each_recv, for_each_arg], _) = expr.kind; + if let ExprKind::MethodCall(method_name, [for_each_recv, for_each_arg], _) = expr.kind; if method_name.ident.name == Symbol::intern("for_each"); // Check `for_each` is an associated function of `Iterator`. if is_trait_method(cx, expr, sym::Iterator); // Checks the receiver of `for_each` is also a method call. - if let ExprKind::MethodCall(_, _, [iter_recv], _) = for_each_recv.kind; + if let ExprKind::MethodCall(_, [iter_recv], _) = for_each_recv.kind; // Skip the lint if the call chain is too long. e.g. `v.field.iter().for_each()` or // `v.foo().iter().for_each()` must be skipped. if matches!( diff --git a/clippy_lints/src/needless_option_as_deref.rs b/clippy_lints/src/needless_option_as_deref.rs index 0931fec149eb..21d8263390af 100644 --- a/clippy_lints/src/needless_option_as_deref.rs +++ b/clippy_lints/src/needless_option_as_deref.rs @@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for OptionNeedlessDeref { if_chain! { if is_type_diagnostic_item(cx,outer_ty,sym::Option); - if let ExprKind::MethodCall(path, _, [sub_expr], _) = expr.kind; + if let ExprKind::MethodCall(path, [sub_expr], _) = expr.kind; let symbol = path.ident.as_str(); if symbol == "as_deref" || symbol == "as_deref_mut"; if TyS::same_type( outer_ty, typeck.expr_ty(sub_expr) ); diff --git a/clippy_lints/src/non_octal_unix_permissions.rs b/clippy_lints/src/non_octal_unix_permissions.rs index e46fee4cac5e..ed022b9d5291 100644 --- a/clippy_lints/src/non_octal_unix_permissions.rs +++ b/clippy_lints/src/non_octal_unix_permissions.rs @@ -43,7 +43,7 @@ declare_lint_pass!(NonOctalUnixPermissions => [NON_OCTAL_UNIX_PERMISSIONS]); impl<'tcx> LateLintPass<'tcx> for NonOctalUnixPermissions { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { match &expr.kind { - ExprKind::MethodCall(path, _, [func, param], _) => { + ExprKind::MethodCall(path, [func, param], _) => { let obj_ty = cx.typeck_results().expr_ty(func).peel_refs(); if_chain! { diff --git a/clippy_lints/src/open_options.rs b/clippy_lints/src/open_options.rs index 1b9285c2298d..5a0b5042018b 100644 --- a/clippy_lints/src/open_options.rs +++ b/clippy_lints/src/open_options.rs @@ -32,7 +32,7 @@ declare_lint_pass!(OpenOptions => [NONSENSICAL_OPEN_OPTIONS]); impl<'tcx> LateLintPass<'tcx> for OpenOptions { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if let ExprKind::MethodCall(path, _, [self_arg, ..], _) = &e.kind { + if let ExprKind::MethodCall(path, [self_arg, ..], _) = &e.kind { let obj_ty = cx.typeck_results().expr_ty(self_arg).peel_refs(); if path.ident.name == sym!(open) && match_type(cx, obj_ty, &paths::OPEN_OPTIONS) { let mut options = Vec::new(); @@ -60,7 +60,7 @@ enum OpenOption { } fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec<(OpenOption, Argument)>) { - if let ExprKind::MethodCall(path, _, arguments, _) = argument.kind { + if let ExprKind::MethodCall(path, arguments, _) = argument.kind { let obj_ty = cx.typeck_results().expr_ty(&arguments[0]).peel_refs(); // Only proceed if this is a call on some object of type std::fs::OpenOptions diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index 953de0f72a86..c9f807f2aa3a 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -68,7 +68,7 @@ declare_lint_pass!(OptionIfLetElse => [OPTION_IF_LET_ELSE]); /// Returns true iff the given expression is the result of calling `Result::ok` fn is_result_ok(cx: &LateContext<'_>, expr: &'_ Expr<'_>) -> bool { - if let ExprKind::MethodCall(path, _, &[ref receiver], _) = &expr.kind { + if let ExprKind::MethodCall(path, &[ref receiver], _) = &expr.kind { path.ident.name.as_str() == "ok" && is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(receiver), sym::Result) } else { diff --git a/clippy_lints/src/path_buf_push_overwrite.rs b/clippy_lints/src/path_buf_push_overwrite.rs index e58ca95fa042..3f940ce61c03 100644 --- a/clippy_lints/src/path_buf_push_overwrite.rs +++ b/clippy_lints/src/path_buf_push_overwrite.rs @@ -46,7 +46,7 @@ declare_lint_pass!(PathBufPushOverwrite => [PATH_BUF_PUSH_OVERWRITE]); impl<'tcx> LateLintPass<'tcx> for PathBufPushOverwrite { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { - if let ExprKind::MethodCall(path, _, args, _) = expr.kind; + if let ExprKind::MethodCall(path, args, _) = expr.kind; if path.ident.name == sym!(push); if args.len() == 2; if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&args[0]).peel_refs(), sym::PathBuf); diff --git a/clippy_lints/src/ptr_offset_with_cast.rs b/clippy_lints/src/ptr_offset_with_cast.rs index 964564b57946..b907f38afbb9 100644 --- a/clippy_lints/src/ptr_offset_with_cast.rs +++ b/clippy_lints/src/ptr_offset_with_cast.rs @@ -93,7 +93,7 @@ fn expr_as_ptr_offset_call<'tcx>( cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, ) -> Option<(&'tcx Expr<'tcx>, &'tcx Expr<'tcx>, Method)> { - if let ExprKind::MethodCall(path_segment, _, [arg_0, arg_1, ..], _) = &expr.kind { + if let ExprKind::MethodCall(path_segment, [arg_0, arg_1, ..], _) = &expr.kind { if is_expr_ty_raw_ptr(cx, arg_0) { if path_segment.ident.name == sym::offset { return Some((arg_0, arg_1, Method::Offset)); diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index c765c8962cf7..6f634ded5fef 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -58,7 +58,7 @@ impl QuestionMark { fn check_is_none_or_err_and_early_return(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let Some(higher::If { cond, then, r#else }) = higher::If::hir(expr); - if let ExprKind::MethodCall(segment, _, args, _) = &cond.kind; + if let ExprKind::MethodCall(segment, args, _) = &cond.kind; if let Some(subject) = args.get(0); if (Self::option_check_and_early_return(cx, subject, then) && segment.ident.name == sym!(is_none)) || (Self::result_check_and_early_return(cx, subject, then) && segment.ident.name == sym!(is_err)); diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index c8cbfefb63d6..52d47e6d9786 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -190,7 +190,7 @@ impl_lint_pass!(Ranges => [ impl<'tcx> LateLintPass<'tcx> for Ranges { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { match expr.kind { - ExprKind::MethodCall(path, _, args, _) => { + ExprKind::MethodCall(path, args, _) => { check_range_zip_with_len(cx, path, args, expr.span); }, ExprKind::Binary(ref op, l, r) => { @@ -331,13 +331,13 @@ fn check_range_zip_with_len(cx: &LateContext<'_>, path: &PathSegment<'_>, args: if path.ident.as_str() == "zip"; if let [iter, zip_arg] = args; // `.iter()` call - if let ExprKind::MethodCall(iter_path, _, iter_args, _) = iter.kind; + if let ExprKind::MethodCall(iter_path, iter_args, _) = iter.kind; if iter_path.ident.name == sym::iter; // range expression in `.zip()` call: `0..x.len()` if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::Range::hir(zip_arg); if is_integer_const(cx, start, 0); // `.len()` call - if let ExprKind::MethodCall(len_path, _, len_args, _) = end.kind; + if let ExprKind::MethodCall(len_path, len_args, _) = end.kind; if len_path.ident.name == sym::len && len_args.len() == 1; // `.iter()` and `.len()` called on same `Path` if let ExprKind::Path(QPath::Resolved(_, iter_path)) = iter_args[0].kind; diff --git a/clippy_lints/src/repeat_once.rs b/clippy_lints/src/repeat_once.rs index b5dd2de63374..898c70ace66f 100644 --- a/clippy_lints/src/repeat_once.rs +++ b/clippy_lints/src/repeat_once.rs @@ -46,7 +46,7 @@ declare_lint_pass!(RepeatOnce => [REPEAT_ONCE]); impl<'tcx> LateLintPass<'tcx> for RepeatOnce { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'tcx Expr<'_>) { if_chain! { - if let ExprKind::MethodCall(path, _, [receiver, count], _) = &expr.kind; + if let ExprKind::MethodCall(path, [receiver, count], _) = &expr.kind; if path.ident.name == sym!(repeat); if constant_context(cx, cx.typeck_results()).expr(count) == Some(Constant::Int(1)); if !receiver.span.from_expansion(); diff --git a/clippy_lints/src/size_of_in_element_count.rs b/clippy_lints/src/size_of_in_element_count.rs index 9b195f3c0a22..c7c57ab426d9 100644 --- a/clippy_lints/src/size_of_in_element_count.rs +++ b/clippy_lints/src/size_of_in_element_count.rs @@ -108,7 +108,7 @@ fn get_pointee_ty_and_count_expr<'tcx>( }; if_chain! { // Find calls to copy_{from,to}{,_nonoverlapping} and write_bytes methods - if let ExprKind::MethodCall(method_path, _, [ptr_self, .., count], _) = expr.kind; + if let ExprKind::MethodCall(method_path, [ptr_self, .., count], _) = expr.kind; let method_ident = method_path.ident.as_str(); if METHODS.iter().any(|m| *m == &*method_ident); diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 607fa847dae5..b4ad5dcbe3e9 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -197,7 +197,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { fn search_slow_extend_filling(&mut self, expr: &'tcx Expr<'_>) { if_chain! { if self.initialization_found; - if let ExprKind::MethodCall(path, _, [self_arg, extend_arg], _) = expr.kind; + if let ExprKind::MethodCall(path, [self_arg, extend_arg], _) = expr.kind; if path_to_local_id(self_arg, self.vec_alloc.local_id); if path.ident.name == sym!(extend); if self.is_repeat_take(extend_arg); @@ -212,7 +212,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { fn search_slow_resize_filling(&mut self, expr: &'tcx Expr<'_>) { if_chain! { if self.initialization_found; - if let ExprKind::MethodCall(path, _, [self_arg, len_arg, fill_arg], _) = expr.kind; + if let ExprKind::MethodCall(path, [self_arg, len_arg, fill_arg], _) = expr.kind; if path_to_local_id(self_arg, self.vec_alloc.local_id); if path.ident.name == sym!(resize); @@ -232,7 +232,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { /// Returns `true` if give expression is `repeat(0).take(...)` fn is_repeat_take(&self, expr: &Expr<'_>) -> bool { if_chain! { - if let ExprKind::MethodCall(take_path, _, take_args, _) = expr.kind; + if let ExprKind::MethodCall(take_path, take_args, _) = expr.kind; if take_path.ident.name == sym!(take); // Check that take is applied to `repeat(0)` diff --git a/clippy_lints/src/stable_sort_primitive.rs b/clippy_lints/src/stable_sort_primitive.rs index 20e38dc564eb..bcd28b429784 100644 --- a/clippy_lints/src/stable_sort_primitive.rs +++ b/clippy_lints/src/stable_sort_primitive.rs @@ -87,7 +87,7 @@ struct LintDetection { fn detect_stable_sort_primitive(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { if_chain! { - if let ExprKind::MethodCall(method_name, _, args, _) = &expr.kind; + if let ExprKind::MethodCall(method_name, args, _) = &expr.kind; if let Some(slice) = &args.get(0); if let Some(method) = SortingKind::from_stable_name(method_name.ident.name.as_str()); if let Some(slice_type) = is_slice_of_primitives(cx, slice); diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index b4a71aefd437..3573f632a367 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -282,7 +282,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { } if_chain! { - if let ExprKind::MethodCall(path, _, args, _) = &e.kind; + if let ExprKind::MethodCall(path, args, _) = &e.kind; if path.ident.name == sym!(as_bytes); if let ExprKind::Lit(lit) = &args[0].kind; if let LitKind::Str(lit_content, _) = &lit.node; @@ -324,9 +324,9 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { } if_chain! { - if let ExprKind::MethodCall(path, _, [recv], _) = &e.kind; + if let ExprKind::MethodCall(path, [recv], _) = &e.kind; if path.ident.name == sym!(into_bytes); - if let ExprKind::MethodCall(path, _, [recv], _) = &recv.kind; + if let ExprKind::MethodCall(path, [recv], _) = &recv.kind; if matches!(path.ident.name.as_str(), "to_owned" | "to_string"); if let ExprKind::Lit(lit) = &recv.kind; if let LitKind::Str(lit_content, _) = &lit.node; @@ -384,7 +384,7 @@ declare_lint_pass!(StrToString => [STR_TO_STRING]); impl<'tcx> LateLintPass<'tcx> for StrToString { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) { if_chain! { - if let ExprKind::MethodCall(path, _, [self_arg, ..], _) = &expr.kind; + if let ExprKind::MethodCall(path, [self_arg, ..], _) = &expr.kind; if path.ident.name == sym!(to_string); let ty = cx.typeck_results().expr_ty(self_arg); if let ty::Ref(_, ty, ..) = ty.kind(); @@ -434,7 +434,7 @@ declare_lint_pass!(StringToString => [STRING_TO_STRING]); impl<'tcx> LateLintPass<'tcx> for StringToString { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) { if_chain! { - if let ExprKind::MethodCall(path, _, [self_arg, ..], _) = &expr.kind; + if let ExprKind::MethodCall(path, [self_arg, ..], _) = &expr.kind; if path.ident.name == sym!(to_string); let ty = cx.typeck_results().expr_ty(self_arg); if is_type_diagnostic_item(cx, ty, sym::String); diff --git a/clippy_lints/src/strlen_on_c_strings.rs b/clippy_lints/src/strlen_on_c_strings.rs index d6e948a75607..7bc9cf742e65 100644 --- a/clippy_lints/src/strlen_on_c_strings.rs +++ b/clippy_lints/src/strlen_on_c_strings.rs @@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for StrlenOnCStrings { if let ExprKind::Path(path) = &func.kind; if let Some(did) = cx.qpath_res(path, func.hir_id).opt_def_id(); if match_libc_symbol(cx, did, "strlen"); - if let ExprKind::MethodCall(path, _, [self_arg], _) = recv.kind; + if let ExprKind::MethodCall(path, [self_arg], _) = recv.kind; if !recv.span.from_expansion(); if path.ident.name == sym::as_ptr; then { diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs index 5eb58b478382..aa6c01b3a7cd 100644 --- a/clippy_lints/src/to_digit_is_some.rs +++ b/clippy_lints/src/to_digit_is_some.rs @@ -39,12 +39,12 @@ declare_lint_pass!(ToDigitIsSome => [TO_DIGIT_IS_SOME]); impl<'tcx> LateLintPass<'tcx> for ToDigitIsSome { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if_chain! { - if let hir::ExprKind::MethodCall(is_some_path, _, is_some_args, _) = &expr.kind; + if let hir::ExprKind::MethodCall(is_some_path, is_some_args, _) = &expr.kind; if is_some_path.ident.name.as_str() == "is_some"; if let [to_digit_expr] = &**is_some_args; then { let match_result = match &to_digit_expr.kind { - hir::ExprKind::MethodCall(to_digits_path, _, to_digit_args, _) => { + hir::ExprKind::MethodCall(to_digits_path, to_digit_args, _) => { if_chain! { if let [char_arg, radix_arg] = &**to_digit_args; if to_digits_path.ident.name.as_str() == "to_digit"; diff --git a/clippy_lints/src/to_string_in_display.rs b/clippy_lints/src/to_string_in_display.rs index f8b6bdcd3e15..03060d78fc5a 100644 --- a/clippy_lints/src/to_string_in_display.rs +++ b/clippy_lints/src/to_string_in_display.rs @@ -93,7 +93,7 @@ impl LateLintPass<'_> for ToStringInDisplay { if_chain! { if self.in_display_impl; if let Some(self_hir_id) = self.self_hir_id; - if let ExprKind::MethodCall(path, _, [ref self_arg, ..], _) = expr.kind; + if let ExprKind::MethodCall(path, [ref self_arg, ..], _) = expr.kind; if path.ident.name == sym!(to_string); if let Some(expr_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if is_diag_trait_item(cx, expr_def_id, sym::ToString); diff --git a/clippy_lints/src/uninit_vec.rs b/clippy_lints/src/uninit_vec.rs index 2ffaf24f942a..6d909c34690d 100644 --- a/clippy_lints/src/uninit_vec.rs +++ b/clippy_lints/src/uninit_vec.rs @@ -177,7 +177,7 @@ fn extract_init_or_reserve_target<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt }); } }, - ExprKind::MethodCall(path, _, [self_expr, _], _) if is_reserve(cx, path, self_expr) => { + ExprKind::MethodCall(path, [self_expr, _], _) if is_reserve(cx, path, self_expr) => { return Some(TargetVec { location: VecLocation::Expr(self_expr), init_kind: None, @@ -211,7 +211,7 @@ fn extract_set_len_self<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Opt } }); match expr.kind { - ExprKind::MethodCall(path, _, [self_expr, _], _) => { + ExprKind::MethodCall(path, [self_expr, _], _) => { let self_type = cx.typeck_results().expr_ty(self_expr).peel_refs(); if is_type_diagnostic_item(cx, self_type, sym::Vec) && path.ident.name.as_str() == "set_len" { Some((self_expr, expr.span)) diff --git a/clippy_lints/src/unit_hash.rs b/clippy_lints/src/unit_hash.rs index dcf8a9d7c84d..88ca0cb20a12 100644 --- a/clippy_lints/src/unit_hash.rs +++ b/clippy_lints/src/unit_hash.rs @@ -49,7 +49,7 @@ declare_lint_pass!(UnitHash => [UNIT_HASH]); impl<'tcx> LateLintPass<'tcx> for UnitHash { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if_chain! { - if let ExprKind::MethodCall(name_ident, _, args, _) = &expr.kind; + if let ExprKind::MethodCall(name_ident, args, _) = &expr.kind; if name_ident.ident.name == sym::hash; if let [recv, state_param] = args; if cx.typeck_results().expr_ty(recv).is_unit(); diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 68156df2ecea..141f26048726 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -142,7 +142,7 @@ fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Spa impl<'tcx> LateLintPass<'tcx> for UnitReturnExpectingOrd { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - if let ExprKind::MethodCall(_, _, args, _) = expr.kind { + if let ExprKind::MethodCall(_, args, _) = expr.kind { let arg_indices = get_args_to_check(cx, expr); for (i, trait_name) in arg_indices { if i < args.len() { diff --git a/clippy_lints/src/unit_types/unit_arg.rs b/clippy_lints/src/unit_types/unit_arg.rs index 57be2d2f674c..97d92f10e1cb 100644 --- a/clippy_lints/src/unit_types/unit_arg.rs +++ b/clippy_lints/src/unit_types/unit_arg.rs @@ -30,7 +30,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { } match expr.kind { - ExprKind::Call(_, args) | ExprKind::MethodCall(_, _, args, _) => { + ExprKind::Call(_, args) | ExprKind::MethodCall(_, args, _) => { let args_to_recover = args .iter() .filter(|arg| { diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index 7d75ff36e971..e6c260ed96a9 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -93,10 +93,7 @@ fn mirrored_exprs( // The two exprs are method calls. // Check to see that the function is the same and the arguments are mirrored // This is enough because the receiver of the method is listed in the arguments - ( - ExprKind::MethodCall(left_segment, _, left_args, _), - ExprKind::MethodCall(right_segment, _, right_args, _), - ) => { + (ExprKind::MethodCall(left_segment, left_args, _), ExprKind::MethodCall(right_segment, right_args, _)) => { left_segment.ident == right_segment.ident && iter::zip(*left_args, *right_args) .all(|(left, right)| mirrored_exprs(cx, left, a_ident, right, b_ident)) @@ -165,7 +162,7 @@ fn mirrored_exprs( fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { if_chain! { - if let ExprKind::MethodCall(name_ident, _, args, _) = &expr.kind; + if let ExprKind::MethodCall(name_ident, args, _) = &expr.kind; if let name = name_ident.ident.name.to_ident_string(); if name == "sort_by" || name == "sort_unstable_by"; if let [vec, Expr { kind: ExprKind::Closure(_, _, closure_body_id, _, _), .. }] = args; @@ -175,7 +172,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { Param { pat: Pat { kind: PatKind::Binding(_, _, left_ident, _), .. }, ..}, Param { pat: Pat { kind: PatKind::Binding(_, _, right_ident, _), .. }, .. } ] = &closure_body.params; - if let ExprKind::MethodCall(method_path, _, [ref left_expr, ref right_expr], _) = &closure_body.value.kind; + if let ExprKind::MethodCall(method_path, [ref left_expr, ref right_expr], _) = &closure_body.value.kind; if method_path.ident.name == sym::cmp; then { let (closure_body, closure_arg, reverse) = if mirrored_exprs( diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index 287ac5b4a908..323cf83ffcff 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount { check_map_error(cx, res, expr); } }, - hir::ExprKind::MethodCall(path, _, [ref arg_0, ..], _) => match path.ident.as_str() { + hir::ExprKind::MethodCall(path, [ref arg_0, ..], _) => match path.ident.as_str() { "expect" | "unwrap" | "unwrap_or" | "unwrap_or_else" => { check_map_error(cx, arg_0, expr); }, @@ -94,7 +94,7 @@ fn try_remove_await<'a>(expr: &'a hir::Expr<'a>) -> Option<&hir::Expr<'a>> { fn check_map_error(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) { let mut call = call; - while let hir::ExprKind::MethodCall(path, _, args, _) = call.kind { + while let hir::ExprKind::MethodCall(path, args, _) = call.kind { if matches!(path.ident.as_str(), "or" | "or_else" | "ok") { call = &args[0]; } else { @@ -110,7 +110,7 @@ fn check_map_error(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr< } fn check_method_call(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>, is_await: bool) { - if let hir::ExprKind::MethodCall(path, _, _, _) = call.kind { + if let hir::ExprKind::MethodCall(path, _, _) = call.kind { let symbol = path.ident.as_str(); let read_trait = if is_await { match_trait_method(cx, call, &paths::FUTURES_IO_ASYNCREADEXT) diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 0a728d7700b3..e98404870134 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -154,7 +154,7 @@ fn collect_unwrap_info<'tcx>( return collect_unwrap_info(cx, if_expr, expr, branch, !invert, false); } else { if_chain! { - if let ExprKind::MethodCall(method_name, _, args, _) = &expr.kind; + if let ExprKind::MethodCall(method_name, args, _) = &expr.kind; if let Some(local_id) = path_to_local(&args[0]); let ty = cx.typeck_results().expr_ty(&args[0]); let name = method_name.ident.as_str(); @@ -231,7 +231,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> { } else { // find `unwrap[_err]()` calls: if_chain! { - if let ExprKind::MethodCall(method_name, _, [self_arg, ..], _) = expr.kind; + if let ExprKind::MethodCall(method_name, [self_arg, ..], _) = expr.kind; if let Some(id) = path_to_local(self_arg); if [sym::unwrap, sym::expect, sym!(unwrap_err)].contains(&method_name.ident.name); let call_to_unwrap = [sym::unwrap, sym::expect].contains(&method_name.ident.name); diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 1d7bb2430260..d23c85c033b2 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -402,9 +402,9 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { self.expr(func); self.slice(args, |e| self.expr(e)); }, - ExprKind::MethodCall(method_name, _, args, _) => { + ExprKind::MethodCall(method_name, args, _) => { bind!(self, method_name, args); - kind!("MethodCall({method_name}, _, {args}, _)"); + kind!("MethodCall({method_name}, {args}, _)"); self.ident(field!(method_name.ident)); self.slice(args, |e| self.expr(e)); }, diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 89eae06fef79..b58325ac73ee 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -149,7 +149,7 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { } print_expr(cx, init, indent + 1); }, - hir::ExprKind::MethodCall(path, _, args, _) => { + hir::ExprKind::MethodCall(path, args, _) => { println!("{}MethodCall", ind); println!("{}method name: {}", ind, path.ident.name); for arg in args { diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 02fa866db523..ec1b5a499d47 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -583,7 +583,7 @@ impl<'tcx> LateLintPass<'tcx> for CompilerLintFunctions { } if_chain! { - if let ExprKind::MethodCall(path, _, [self_arg, ..], _) = &expr.kind; + if let ExprKind::MethodCall(path, [self_arg, ..], _) = &expr.kind; let fn_name = path.ident; if let Some(sugg) = self.map.get(&*fn_name.as_str()); let ty = cx.typeck_results().expr_ty(self_arg).peel_refs(); @@ -665,7 +665,7 @@ impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls { if let ExprKind::Closure(_, _, body_id, _, _) = &and_then_args[4].kind; let body = cx.tcx.hir().body(*body_id); let only_expr = peel_blocks_with_stmt(&body.value); - if let ExprKind::MethodCall(ps, _, span_call_args, _) = &only_expr.kind; + if let ExprKind::MethodCall(ps, span_call_args, _) = &only_expr.kind; then { let and_then_snippets = get_and_then_snippets(cx, and_then_args); let mut sle = SpanlessEq::new(cx).deny_side_effects(); @@ -1097,7 +1097,7 @@ impl InterningDefinedSymbol { }; if_chain! { // is a method call - if let ExprKind::MethodCall(_, _, [item], _) = call.kind; + if let ExprKind::MethodCall(_, [item], _) = call.kind; if let Some(did) = cx.typeck_results().type_dependent_def_id(call.hir_id); let ty = cx.typeck_results().expr_ty(item); // ...on either an Ident or a Symbol diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index 8485c14bfe72..5ee3146eaab1 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -896,7 +896,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for IsMultiSpanScanner<'a, 'hir> { self.add_single_span_suggestion(); } }, - ExprKind::MethodCall(path, _path_span, arg, _arg_span) => { + ExprKind::MethodCall(path, arg, _arg_span) => { let (self_ty, _) = walk_ptrs_ty_depth(self.cx.typeck_results().expr_ty(&arg[0])); if match_type(self.cx, self_ty, &paths::DIAGNOSTIC_BUILDER) { let called_method = path.ident.name.as_str().to_string(); diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs index 43474da3450e..fbf2b3e081b8 100644 --- a/clippy_lints/src/vec_init_then_push.rs +++ b/clippy_lints/src/vec_init_then_push.rs @@ -125,7 +125,7 @@ impl<'tcx> LateLintPass<'tcx> for VecInitThenPush { if let Some(searcher) = self.searcher.take() { if_chain! { if let StmtKind::Expr(expr) | StmtKind::Semi(expr) = stmt.kind; - if let ExprKind::MethodCall(path, _, [self_arg, _], _) = expr.kind; + if let ExprKind::MethodCall(path, [self_arg, _], _) = expr.kind; if path_to_local_id(self_arg, searcher.local_id); if path.ident.name.as_str() == "push"; then { diff --git a/clippy_lints/src/vec_resize_to_zero.rs b/clippy_lints/src/vec_resize_to_zero.rs index 3441d9ccdfa2..4d86abd0fa12 100644 --- a/clippy_lints/src/vec_resize_to_zero.rs +++ b/clippy_lints/src/vec_resize_to_zero.rs @@ -31,7 +31,7 @@ declare_lint_pass!(VecResizeToZero => [VEC_RESIZE_TO_ZERO]); impl<'tcx> LateLintPass<'tcx> for VecResizeToZero { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { - if let hir::ExprKind::MethodCall(path_segment, _, args, _) = expr.kind; + if let hir::ExprKind::MethodCall(path_segment, args, _) = expr.kind; if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if match_def_path(cx, method_def_id, &paths::VEC_RESIZE) && args.len() == 3; if let ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = args[1].kind; diff --git a/clippy_lints/src/verbose_file_reads.rs b/clippy_lints/src/verbose_file_reads.rs index ebdaff1e676b..8e2ddd225fdb 100644 --- a/clippy_lints/src/verbose_file_reads.rs +++ b/clippy_lints/src/verbose_file_reads.rs @@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for VerboseFileReads { fn is_file_read_to_end<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool { if_chain! { - if let ExprKind::MethodCall(method_name, _, exprs, _) = expr.kind; + if let ExprKind::MethodCall(method_name, exprs, _) = expr.kind; if method_name.ident.as_str() == "read_to_end"; if let ExprKind::Path(QPath::Resolved(None, _)) = &exprs[0].kind; let ty = cx.typeck_results().expr_ty(&exprs[0]); @@ -75,7 +75,7 @@ fn is_file_read_to_end<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> fn is_file_read_to_string<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool { if_chain! { - if let ExprKind::MethodCall(method_name, _, exprs, _) = expr.kind; + if let ExprKind::MethodCall(method_name, exprs, _) = expr.kind; if method_name.ident.as_str() == "read_to_string"; if let ExprKind::Path(QPath::Resolved(None, _)) = &exprs[0].kind; let ty = cx.typeck_results().expr_ty(&exprs[0]); diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 8bdc59a7175b..eb9efec3f161 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -141,7 +141,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS self.eagerness |= NoChange; return; }, - ExprKind::MethodCall(name, _, args, _) => { + ExprKind::MethodCall(name, args, _) => { self.eagerness |= self .cx .typeck_results() diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index b0fee46f8247..ed573ad90561 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -258,7 +258,7 @@ impl HirEqInterExpr<'_, '_, '_> { && self.eq_expr(l.body, r.body) }) }, - (&ExprKind::MethodCall(l_path, _, l_args, _), &ExprKind::MethodCall(r_path, _, r_args, _)) => { + (&ExprKind::MethodCall(l_path, l_args, _), &ExprKind::MethodCall(r_path, r_args, _)) => { self.inner.allow_side_effects && self.eq_path_segment(l_path, r_path) && self.eq_exprs(l_args, r_args) }, (&ExprKind::Repeat(le, ll), &ExprKind::Repeat(re, rl)) => { @@ -713,7 +713,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { s.hash(&mut self.s); }, - ExprKind::MethodCall(path, ref _tys, args, ref _fn_span) => { + ExprKind::MethodCall(path, args, ref _fn_span) => { self.hash_name(path.ident.name); self.hash_exprs(args); }, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 5c0800d2f038..8386aaeaf444 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1059,13 +1059,13 @@ pub fn method_calls<'tcx>( let mut current = expr; for _ in 0..max_depth { - if let ExprKind::MethodCall(path, span, args, _) = ¤t.kind { + if let ExprKind::MethodCall(path, args, _) = ¤t.kind { if args.iter().any(|e| e.span.from_expansion()) { break; } method_names.push(path.ident.name); arg_lists.push(&**args); - spans.push(*span); + spans.push(path.ident.span); current = &args[0]; } else { break; @@ -1086,7 +1086,7 @@ pub fn method_chain_args<'a>(expr: &'a Expr<'_>, methods: &[&str]) -> Option first - if let ExprKind::MethodCall(path, _, args, _) = current.kind { + if let ExprKind::MethodCall(path, args, _) = current.kind { if path.ident.name.as_str() == *method_name { if args.iter().any(|e| e.span.from_expansion()) { return None; @@ -1780,7 +1780,7 @@ pub fn is_must_use_func_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { None } }, - ExprKind::MethodCall(_, _, _, _) => cx.typeck_results().type_dependent_def_id(expr.hir_id), + ExprKind::MethodCall(..) => cx.typeck_results().type_dependent_def_id(expr.hir_id), _ => None, }; diff --git a/clippy_utils/src/ptr.rs b/clippy_utils/src/ptr.rs index 17d9a505bc9d..649b7b9940af 100644 --- a/clippy_utils/src/ptr.rs +++ b/clippy_utils/src/ptr.rs @@ -36,7 +36,7 @@ fn extract_clone_suggestions<'tcx>( if abort { return false; } - if let ExprKind::MethodCall(seg, _, [recv], _) = expr.kind { + if let ExprKind::MethodCall(seg, [recv], _) = expr.kind { if path_to_local_id(recv, id) { if seg.ident.name.as_str() == "capacity" { abort = true; diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 563edd32d251..48525f9a5725 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -863,7 +863,7 @@ impl<'tcx> DerefDelegate<'_, 'tcx> { /// indicates whether the function from `parent_expr` takes its args by double reference fn func_takes_arg_by_double_ref(&self, parent_expr: &'tcx hir::Expr<'_>, cmt_hir_id: HirId) -> bool { let (call_args, inputs) = match parent_expr.kind { - ExprKind::MethodCall(_, _, call_args, _) => { + ExprKind::MethodCall(_, call_args, _) => { if let Some(method_did) = self.cx.typeck_results().type_dependent_def_id(parent_expr.hir_id) { (call_args, self.cx.tcx.fn_sig(method_did).skip_binder().inputs()) } else { @@ -915,7 +915,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> { match &parent_expr.kind { // given expression is the self argument and will be handled completely by the compiler // i.e.: `|x| x.is_something()` - ExprKind::MethodCall(_, _, [self_expr, ..], _) if self_expr.hir_id == cmt.hir_id => { + ExprKind::MethodCall(_, [self_expr, ..], _) if self_expr.hir_id == cmt.hir_id => { self.suggestion_start .push_str(&format!("{}{}", start_snip, ident_str_with_proj)); self.next_pos = span.hi(); @@ -923,7 +923,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> { }, // item is used in a call // i.e.: `Call`: `|x| please(x)` or `MethodCall`: `|x| [1, 2, 3].contains(x)` - ExprKind::Call(_, [call_args @ ..]) | ExprKind::MethodCall(_, _, [_, call_args @ ..], _) => { + ExprKind::Call(_, [call_args @ ..]) | ExprKind::MethodCall(_, [_, call_args @ ..], _) => { let expr = self.cx.tcx.hir().expect_expr(cmt.hir_id); let arg_ty_kind = self.cx.typeck_results().expr_ty(expr).kind(); diff --git a/doc/common_tools_writing_lints.md b/doc/common_tools_writing_lints.md index 207b0be15488..6c8a3dc418b1 100644 --- a/doc/common_tools_writing_lints.md +++ b/doc/common_tools_writing_lints.md @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for MyStructLint { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if_chain! { // Check our expr is calling a method - if let hir::ExprKind::MethodCall(path, _, [_self_arg, ..], _) = &expr.kind; + if let hir::ExprKind::MethodCall(path, _, [_self_arg, ..]) = &expr.kind; // Check the name of this method is `some_method` if path.ident.name == sym!(some_method); // Optionally, check the type of the self argument. diff --git a/tests/ui/author/struct.stdout b/tests/ui/author/struct.stdout index ded5abd8d334..5e78b7c9de7e 100644 --- a/tests/ui/author/struct.stdout +++ b/tests/ui/author/struct.stdout @@ -53,7 +53,7 @@ if_chain! { } } if_chain! { - if let ExprKind::MethodCall(method_name, _, args, _) = expr.kind; + if let ExprKind::MethodCall(method_name, args, _) = expr.kind; if method_name.ident.as_str() == "test"; if args.len() == 1; if let ExprKind::Path(ref qpath) = args[0].kind; From 0199a7a186d9cf1358ce354f173a84dd786d82dc Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 29 Sep 2021 01:17:54 +0300 Subject: [PATCH 0404/1222] rustc_lint: Reuse the set of registered tools from resolver --- clippy_lints/src/utils/internal_lints/metadata_collector.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index 5ee3146eaab1..512c39389c1b 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -580,7 +580,7 @@ fn get_lint_group_and_level_or_lint( ) -> Option<(String, &'static str)> { let result = cx .lint_store - .check_lint_name(cx.sess(), lint_name, Some(sym::clippy), &[]); + .check_lint_name(lint_name, Some(sym::clippy), &[]); if let CheckLintNameResult::Tool(Ok(lint_lst)) = result { if let Some(group) = get_lint_group(cx, lint_lst[0]) { if EXCLUDED_LINT_GROUPS.contains(&group.as_str()) { From 2868cce1046a8200f2295e6bbd069d0dada59a53 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 4 Dec 2021 23:09:15 +0800 Subject: [PATCH 0405/1222] Update clippy --- clippy_lints/src/approx_const.rs | 2 +- clippy_lints/src/as_conversions.rs | 4 ++-- clippy_lints/src/disallowed_script_idents.rs | 4 ++-- clippy_lints/src/else_if_without_else.rs | 4 ++-- clippy_lints/src/formatting.rs | 6 +++--- clippy_lints/src/from_over_into.rs | 2 +- clippy_lints/src/index_refutable_slice.rs | 2 +- clippy_lints/src/items_after_statements.rs | 6 +++--- clippy_lints/src/literal_representation.rs | 6 +++--- clippy_lints/src/manual_non_exhaustive.rs | 6 +++--- clippy_lints/src/manual_strip.rs | 2 +- clippy_lints/src/matches.rs | 2 +- clippy_lints/src/mem_replace.rs | 2 +- clippy_lints/src/misc_early/mod.rs | 4 ++-- clippy_lints/src/missing_const_for_fn.rs | 2 +- clippy_lints/src/module_style.rs | 4 ++-- clippy_lints/src/non_expressive_names.rs | 6 +++--- clippy_lints/src/octal_escapes.rs | 4 ++-- clippy_lints/src/ranges.rs | 2 +- clippy_lints/src/redundant_closure_call.rs | 4 ++-- clippy_lints/src/redundant_else.rs | 4 ++-- clippy_lints/src/redundant_field_names.rs | 4 ++-- .../src/single_char_lifetime_names.rs | 4 ++-- .../src/single_component_path_imports.rs | 4 ++-- clippy_lints/src/use_self.rs | 2 +- clippy_lints/src/write.rs | 6 +++--- clippy_utils/src/lib.rs | 20 +++++-------------- 27 files changed, 54 insertions(+), 64 deletions(-) diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index 5061c9d1eaf6..e109ee0009ee 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::{meets_msrv, msrvs}; use rustc_ast::ast::{FloatTy, LitFloatType, LitKind}; use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass}; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::symbol; diff --git a/clippy_lints/src/as_conversions.rs b/clippy_lints/src/as_conversions.rs index 53704da1046b..88b91d589074 100644 --- a/clippy_lints/src/as_conversions.rs +++ b/clippy_lints/src/as_conversions.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::ast::{Expr, ExprKind}; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -48,7 +48,7 @@ declare_lint_pass!(AsConversions => [AS_CONVERSIONS]); impl EarlyLintPass for AsConversions { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - if in_external_macro(cx.sess, expr.span) { + if in_external_macro(cx.sess(), expr.span) { return; } diff --git a/clippy_lints/src/disallowed_script_idents.rs b/clippy_lints/src/disallowed_script_idents.rs index 3c3f3631849e..0c27c3f9255f 100644 --- a/clippy_lints/src/disallowed_script_idents.rs +++ b/clippy_lints/src/disallowed_script_idents.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_ast::ast; use rustc_data_structures::fx::FxHashSet; -use rustc_lint::{EarlyContext, EarlyLintPass, Level}; +use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use unicode_script::{Script, UnicodeScript}; @@ -72,7 +72,7 @@ impl EarlyLintPass for DisallowedScriptIdents { return; } - let symbols = cx.sess.parse_sess.symbol_gallery.symbols.lock(); + let symbols = cx.sess().parse_sess.symbol_gallery.symbols.lock(); // Sort by `Span` so that error messages make sense with respect to the // order of identifier locations in the code. let mut symbols: Vec<_> = symbols.iter().collect(); diff --git a/clippy_lints/src/else_if_without_else.rs b/clippy_lints/src/else_if_without_else.rs index 92c56c762aad..0b9f54231c59 100644 --- a/clippy_lints/src/else_if_without_else.rs +++ b/clippy_lints/src/else_if_without_else.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::ast::{Expr, ExprKind}; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -50,7 +50,7 @@ declare_lint_pass!(ElseIfWithoutElse => [ELSE_IF_WITHOUT_ELSE]); impl EarlyLintPass for ElseIfWithoutElse { fn check_expr(&mut self, cx: &EarlyContext<'_>, mut item: &Expr) { - if in_external_macro(cx.sess, item.span) { + if in_external_macro(cx.sess(), item.span) { return; } diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index 3e85c8a9c807..ae18f8081bcc 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -3,7 +3,7 @@ use clippy_utils::differing_macro_contexts; use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_ast::ast::{BinOpKind, Block, Expr, ExprKind, StmtKind, UnOp}; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; @@ -207,7 +207,7 @@ fn check_else(cx: &EarlyContext<'_>, expr: &Expr) { if let ExprKind::If(_, then, Some(else_)) = &expr.kind; if is_block(else_) || is_if(else_); if !differing_macro_contexts(then.span, else_.span); - if !then.span.from_expansion() && !in_external_macro(cx.sess, expr.span); + if !then.span.from_expansion() && !in_external_macro(cx.sess(), expr.span); // workaround for rust-lang/rust#43081 if expr.span.lo().0 != 0 && expr.span.hi().0 != 0; @@ -259,7 +259,7 @@ fn has_unary_equivalent(bin_op: BinOpKind) -> bool { } fn indentation(cx: &EarlyContext<'_>, span: Span) -> usize { - cx.sess.source_map().lookup_char_pos(span.lo()).col.0 + cx.sess().source_map().lookup_char_pos(span.lo()).col.0 } /// Implementation of the `POSSIBLE_MISSING_COMMA` lint for array diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index 5ece2cc5ac4f..c2f52605151e 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::{meets_msrv, msrvs}; use if_chain::if_chain; use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass}; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::symbol::sym; diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index 4615122bbf9e..667652106987 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -8,7 +8,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::intravisit::{self, Visitor}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::ty; use rustc_semver::RustcVersion; diff --git a/clippy_lints/src/items_after_statements.rs b/clippy_lints/src/items_after_statements.rs index b118d3c8b872..cdefe627efda 100644 --- a/clippy_lints/src/items_after_statements.rs +++ b/clippy_lints/src/items_after_statements.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_ast::ast::{Block, ItemKind, StmtKind}; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -55,7 +55,7 @@ declare_lint_pass!(ItemsAfterStatements => [ITEMS_AFTER_STATEMENTS]); impl EarlyLintPass for ItemsAfterStatements { fn check_block(&mut self, cx: &EarlyContext<'_>, item: &Block) { - if in_external_macro(cx.sess, item.span) { + if in_external_macro(cx.sess(), item.span) { return; } @@ -69,7 +69,7 @@ impl EarlyLintPass for ItemsAfterStatements { // lint on all further items for stmt in stmts { if let StmtKind::Item(ref it) = *stmt { - if in_external_macro(cx.sess, it.span) { + if in_external_macro(cx.sess(), it.span) { return; } if let ItemKind::MacroDef(..) = it.kind { diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index 130543bbbee8..b7430f49229a 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -7,7 +7,7 @@ use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_ast::ast::{Expr, ExprKind, Lit, LitKind}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_tool_lint, impl_lint_pass}; use std::iter; @@ -225,7 +225,7 @@ impl_lint_pass!(LiteralDigitGrouping => [ impl EarlyLintPass for LiteralDigitGrouping { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - if in_external_macro(cx.sess, expr.span) { + if in_external_macro(cx.sess(), expr.span) { return; } @@ -418,7 +418,7 @@ impl_lint_pass!(DecimalLiteralRepresentation => [DECIMAL_LITERAL_REPRESENTATION] impl EarlyLintPass for DecimalLiteralRepresentation { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - if in_external_macro(cx.sess, expr.span) { + if in_external_macro(cx.sess(), expr.span) { return; } diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 63a72d4fddeb..33d1bb2985f4 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -5,7 +5,7 @@ use clippy_utils::{meets_msrv, msrvs}; use if_chain::if_chain; use rustc_ast::ast::{FieldDef, Item, ItemKind, Variant, VariantData, VisibilityKind}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{sym, Span}; @@ -116,7 +116,7 @@ fn check_manual_non_exhaustive_enum(cx: &EarlyContext<'_>, item: &Item, variants |diag| { if_chain! { if !item.attrs.iter().any(|attr| attr.has_name(sym::non_exhaustive)); - let header_span = cx.sess.source_map().span_until_char(item.span, '{'); + let header_span = cx.sess().source_map().span_until_char(item.span, '{'); if let Some(snippet) = snippet_opt(cx, header_span); then { diag.span_suggestion( @@ -149,7 +149,7 @@ fn check_manual_non_exhaustive_struct(cx: &EarlyContext<'_>, item: &Item, data: VariantData::Unit(_) => unreachable!("`VariantData::Unit` is already handled above"), }; - cx.sess.source_map().span_until_char(item.span, delimiter) + cx.sess().source_map().span_until_char(item.span, delimiter) } let fields = data.fields(); diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index c814e013c631..aacabf303a70 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -9,7 +9,7 @@ use rustc_hir::def::Res; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::BinOpKind; use rustc_hir::{BorrowKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 411a797b6cb5..dfb450c8848a 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -25,7 +25,7 @@ use rustc_hir::{ Mutability, Node, Pat, PatKind, PathSegment, QPath, RangeEnd, TyKind, }; use rustc_hir::{HirIdMap, HirIdSet}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, Ty, TyS, VariantDef}; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 7fc39f17232f..a184806d021b 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -6,7 +6,7 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::LangItem::OptionNone; use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, QPath}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; diff --git a/clippy_lints/src/misc_early/mod.rs b/clippy_lints/src/misc_early/mod.rs index 6e09e25109fb..d955fad7d41a 100644 --- a/clippy_lints/src/misc_early/mod.rs +++ b/clippy_lints/src/misc_early/mod.rs @@ -12,7 +12,7 @@ use clippy_utils::source::snippet_opt; use rustc_ast::ast::{Expr, ExprKind, Generics, Lit, LitFloatType, LitIntType, LitKind, NodeId, Pat, PatKind}; use rustc_ast::visit::FnKind; use rustc_data_structures::fx::FxHashMap; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; @@ -342,7 +342,7 @@ impl EarlyLintPass for MiscEarlyLints { } fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - if in_external_macro(cx.sess, expr.span) { + if in_external_macro(cx.sess(), expr.span) { return; } diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 77849e1800f6..bad9e0be82e6 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -5,7 +5,7 @@ use clippy_utils::{fn_has_unsatisfiable_preds, is_entrypoint_fn, meets_msrv, msr use rustc_hir as hir; use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, Constness, FnDecl, GenericParamKind, HirId}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; diff --git a/clippy_lints/src/module_style.rs b/clippy_lints/src/module_style.rs index 3b65f80cba20..b8dfe9968806 100644 --- a/clippy_lints/src/module_style.rs +++ b/clippy_lints/src/module_style.rs @@ -80,9 +80,9 @@ impl EarlyLintPass for ModStyle { return; } - let files = cx.sess.source_map().files(); + let files = cx.sess().source_map().files(); - let trim_to_src = if let RealFileName::LocalPath(p) = &cx.sess.opts.working_dir { + let trim_to_src = if let RealFileName::LocalPath(p) = &cx.sess().opts.working_dir { p.to_string_lossy() } else { return; diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 39a37e3e378e..0d0c88b02c78 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -3,7 +3,7 @@ use rustc_ast::ast::{ self, Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Item, ItemKind, Local, Pat, PatKind, }; use rustc_ast::visit::{walk_block, walk_expr, walk_pat, Visitor}; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; @@ -356,7 +356,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> { impl EarlyLintPass for NonExpressiveNames { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { - if in_external_macro(cx.sess, item.span) { + if in_external_macro(cx.sess(), item.span) { return; } @@ -371,7 +371,7 @@ impl EarlyLintPass for NonExpressiveNames { } fn check_impl_item(&mut self, cx: &EarlyContext<'_>, item: &AssocItem) { - if in_external_macro(cx.sess, item.span) { + if in_external_macro(cx.sess(), item.span) { return; } diff --git a/clippy_lints/src/octal_escapes.rs b/clippy_lints/src/octal_escapes.rs index e0da12f77fcc..d81481ade044 100644 --- a/clippy_lints/src/octal_escapes.rs +++ b/clippy_lints/src/octal_escapes.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use rustc_ast::ast::{Expr, ExprKind}; use rustc_ast::token::{Lit, LitKind}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Span; @@ -51,7 +51,7 @@ declare_lint_pass!(OctalEscapes => [OCTAL_ESCAPES]); impl EarlyLintPass for OctalEscapes { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - if in_external_macro(cx.sess, expr.span) { + if in_external_macro(cx.sess(), expr.span) { return; } diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 52d47e6d9786..027ab70014fc 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -8,7 +8,7 @@ use if_chain::if_chain; use rustc_ast::ast::RangeLimits; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, PathSegment, QPath}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 0c77cf5e77dd..5a25008e95e5 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -8,7 +8,7 @@ use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::intravisit as hir_visit; use rustc_hir::intravisit::Visitor as HirVisitor; -use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}; use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -62,7 +62,7 @@ impl<'ast> ast_visit::Visitor<'ast> for ReturnVisitor { impl EarlyLintPass for RedundantClosureCall { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { - if in_external_macro(cx.sess, expr.span) { + if in_external_macro(cx.sess(), expr.span) { return; } if_chain! { diff --git a/clippy_lints/src/redundant_else.rs b/clippy_lints/src/redundant_else.rs index 93dbe936d584..73088ce1a87e 100644 --- a/clippy_lints/src/redundant_else.rs +++ b/clippy_lints/src/redundant_else.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::ast::{Block, Expr, ExprKind, Stmt, StmtKind}; use rustc_ast::visit::{walk_expr, Visitor}; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -46,7 +46,7 @@ declare_lint_pass!(RedundantElse => [REDUNDANT_ELSE]); impl EarlyLintPass for RedundantElse { fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &Stmt) { - if in_external_macro(cx.sess, stmt.span) { + if in_external_macro(cx.sess(), stmt.span) { return; } // Only look at expressions that are a whole statement diff --git a/clippy_lints/src/redundant_field_names.rs b/clippy_lints/src/redundant_field_names.rs index 0dea4a784b21..40a62fd6d201 100644 --- a/clippy_lints/src/redundant_field_names.rs +++ b/clippy_lints/src/redundant_field_names.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::{meets_msrv, msrvs}; use rustc_ast::ast::{Expr, ExprKind}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -55,7 +55,7 @@ impl EarlyLintPass for RedundantFieldNames { return; } - if in_external_macro(cx.sess, expr.span) { + if in_external_macro(cx.sess(), expr.span) { return; } if let ExprKind::Struct(ref se) = expr.kind { diff --git a/clippy_lints/src/single_char_lifetime_names.rs b/clippy_lints/src/single_char_lifetime_names.rs index ee82666b5aff..aa306a630c46 100644 --- a/clippy_lints/src/single_char_lifetime_names.rs +++ b/clippy_lints/src/single_char_lifetime_names.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::ast::{GenericParam, GenericParamKind}; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -43,7 +43,7 @@ declare_lint_pass!(SingleCharLifetimeNames => [SINGLE_CHAR_LIFETIME_NAMES]); impl EarlyLintPass for SingleCharLifetimeNames { fn check_generic_param(&mut self, ctx: &EarlyContext<'_>, param: &GenericParam) { - if in_external_macro(ctx.sess, param.ident.span) { + if in_external_macro(ctx.sess(), param.ident.span) { return; } diff --git a/clippy_lints/src/single_component_path_imports.rs b/clippy_lints/src/single_component_path_imports.rs index 28d32203da9d..961cdb317e76 100644 --- a/clippy_lints/src/single_component_path_imports.rs +++ b/clippy_lints/src/single_component_path_imports.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg}; use rustc_ast::{ptr::P, Crate, Item, ItemKind, MacroDef, ModKind, UseTreeKind, VisibilityKind}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{edition::Edition, symbol::kw, Span, Symbol}; @@ -37,7 +37,7 @@ declare_lint_pass!(SingleComponentPathImports => [SINGLE_COMPONENT_PATH_IMPORTS] impl EarlyLintPass for SingleComponentPathImports { fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &Crate) { - if cx.sess.opts.edition < Edition::Edition2018 { + if cx.sess().opts.edition < Edition::Edition2018 { return; } check_mod(cx, &krate.items); diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 6c5a5fe1434f..be20282b3b88 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -11,7 +11,7 @@ use rustc_hir::{ intravisit::{walk_inf, walk_ty, Visitor}, Expr, ExprKind, FnRetTy, FnSig, GenericArg, HirId, Impl, ImplItemKind, Item, ItemKind, Path, QPath, TyKind, }; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass}; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index f9add927b49b..b0044695ea8a 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -9,7 +9,7 @@ use rustc_ast::token::{self, LitKind}; use rustc_ast::tokenstream::TokenStream; use rustc_errors::Applicability; use rustc_lexer::unescape::{self, EscapeError}; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_parse::parser; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::symbol::{kw, Symbol}; @@ -290,7 +290,7 @@ impl EarlyLintPass for Write { fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &MacCall) { fn is_build_script(cx: &EarlyContext<'_>) -> bool { // Cargo sets the crate name for build scripts to `build_script_build` - cx.sess + cx.sess() .opts .crate_name .as_ref() @@ -529,7 +529,7 @@ impl Write { /// ``` #[allow(clippy::too_many_lines)] fn check_tts<'a>(&self, cx: &EarlyContext<'a>, tts: TokenStream, is_write: bool) -> (Option, Option) { - let mut parser = parser::Parser::new(&cx.sess.parse_sess, tts, false, None); + let mut parser = parser::Parser::new(&cx.sess().parse_sess, tts, false, None); let expr = if is_write { match parser .parse_expr() diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 8386aaeaf444..9233903e98a0 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -117,25 +117,15 @@ pub fn meets_msrv(msrv: Option<&RustcVersion>, lint_msrv: &RustcVersion) -> bool #[macro_export] macro_rules! extract_msrv_attr { - (LateContext) => { - extract_msrv_attr!(@LateContext, ()); - }; - (EarlyContext) => { - extract_msrv_attr!(@EarlyContext); - }; - (@$context:ident$(, $call:tt)?) => { + ($context:ident) => { fn enter_lint_attrs(&mut self, cx: &rustc_lint::$context<'_>, attrs: &[rustc_ast::ast::Attribute]) { - use $crate::get_unique_inner_attr; - match get_unique_inner_attr(cx.sess$($call)?, attrs, "msrv") { + let sess = rustc_lint::LintContext::sess(cx); + match $crate::get_unique_inner_attr(sess, attrs, "msrv") { Some(msrv_attr) => { if let Some(msrv) = msrv_attr.value_str() { - self.msrv = $crate::parse_msrv( - &msrv.to_string(), - Some(cx.sess$($call)?), - Some(msrv_attr.span), - ); + self.msrv = $crate::parse_msrv(&msrv.to_string(), Some(sess), Some(msrv_attr.span)); } else { - cx.sess$($call)?.span_err(msrv_attr.span, "bad clippy attribute"); + sess.span_err(msrv_attr.span, "bad clippy attribute"); } }, _ => (), From f7a1f48dc528c1c940dde6dc6c2572a5aa963b6c Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 18 Oct 2021 00:41:57 +0100 Subject: [PATCH 0406/1222] Create `core::fmt::ArgumentV1` with generics instead of fn pointer --- clippy_utils/src/macros.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs index b7a242cf90a4..a75f6b86a9ba 100644 --- a/clippy_utils/src/macros.rs +++ b/clippy_utils/src/macros.rs @@ -339,15 +339,13 @@ impl<'tcx> FormatArgsExpn<'tcx> { expr_visitor_no_bodies(|e| { // if we're still inside of the macro definition... if e.span.ctxt() == expr.span.ctxt() { - // ArgumnetV1::new(, ::fmt) + // ArgumnetV1::new_() if_chain! { - if let ExprKind::Call(callee, [val, fmt_path]) = e.kind; + if let ExprKind::Call(callee, [val]) = e.kind; if let ExprKind::Path(QPath::TypeRelative(ty, seg)) = callee.kind; - if seg.ident.name == sym::new; if let hir::TyKind::Path(QPath::Resolved(_, path)) = ty.kind; if path.segments.last().unwrap().ident.name == sym::ArgumentV1; - if let ExprKind::Path(QPath::Resolved(_, path)) = fmt_path.kind; - if let [.., fmt_trait, _fmt] = path.segments; + if seg.ident.name.as_str().starts_with("new_"); then { let val_idx = if_chain! { if val.span.ctxt() == expr.span.ctxt(); @@ -361,7 +359,19 @@ impl<'tcx> FormatArgsExpn<'tcx> { formatters.len() } }; - formatters.push((val_idx, fmt_trait.ident.name)); + let fmt_trait = match seg.ident.name.as_str() { + "new_display" => "Display", + "new_debug" => "Debug", + "new_lower_exp" => "LowerExp", + "new_upper_exp" => "UpperExp", + "new_octal" => "Octal", + "new_pointer" => "Pointer", + "new_binary" => "Binary", + "new_lower_hex" => "LowerHex", + "new_upper_hex" => "UpperHex", + _ => unreachable!(), + }; + formatters.push((val_idx, Symbol::intern(fmt_trait))); } } if let ExprKind::Struct(QPath::Resolved(_, path), ..) = e.kind { From 12fcd3934f897f510efd6c535b109e16a4957eae Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 8 Jan 2022 01:56:13 +0000 Subject: [PATCH 0407/1222] Change index_refutable_slice to use FxIndexMap This will prevent unstable order when HirIds are pertubated. --- clippy_lints/src/index_refutable_slice.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index 4615122bbf9e..8819fa1bef84 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -4,7 +4,7 @@ use clippy_utils::higher::IfLet; use clippy_utils::ty::is_copy; use clippy_utils::{is_expn_of, is_lint_allowed, meets_msrv, msrvs, path_to_local}; use if_chain::if_chain; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::intravisit::{self, Visitor}; @@ -92,9 +92,9 @@ impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice { extract_msrv_attr!(LateContext); } -fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxHashMap { +fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap { let mut removed_pat: FxHashSet = FxHashSet::default(); - let mut slices: FxHashMap = FxHashMap::default(); + let mut slices: FxIndexMap = FxIndexMap::default(); pat.walk_always(|pat| { if let hir::PatKind::Binding(binding, value_hir_id, ident, sub_pat) = pat.kind { // We'll just ignore mut and ref mut for simplicity sake right now @@ -208,10 +208,10 @@ impl SliceLintInformation { fn filter_lintable_slices<'a, 'tcx>( cx: &'a LateContext<'tcx>, - slice_lint_info: FxHashMap, + slice_lint_info: FxIndexMap, max_suggested_slice: u64, scope: &'tcx hir::Expr<'tcx>, -) -> FxHashMap { +) -> FxIndexMap { let mut visitor = SliceIndexLintingVisitor { cx, slice_lint_info, @@ -225,7 +225,7 @@ fn filter_lintable_slices<'a, 'tcx>( struct SliceIndexLintingVisitor<'a, 'tcx> { cx: &'a LateContext<'tcx>, - slice_lint_info: FxHashMap, + slice_lint_info: FxIndexMap, max_suggested_slice: u64, } From 33740ffb0df4737fbec2fdbebd5369922bafee17 Mon Sep 17 00:00:00 2001 From: lcnr Date: Tue, 1 Feb 2022 10:13:32 +0100 Subject: [PATCH 0408/1222] silence lint in clippy --- tests/ui/non_send_fields_in_send_ty.rs | 1 + tests/ui/non_send_fields_in_send_ty.stderr | 52 +++++++++++----------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/tests/ui/non_send_fields_in_send_ty.rs b/tests/ui/non_send_fields_in_send_ty.rs index 828248d922f8..514fb25c8cfd 100644 --- a/tests/ui/non_send_fields_in_send_ty.rs +++ b/tests/ui/non_send_fields_in_send_ty.rs @@ -1,4 +1,5 @@ #![warn(clippy::non_send_fields_in_send_ty)] +#![allow(suspicious_auto_trait_impls)] #![feature(extern_types)] use std::cell::UnsafeCell; diff --git a/tests/ui/non_send_fields_in_send_ty.stderr b/tests/ui/non_send_fields_in_send_ty.stderr index 60df4e226e4f..b6c904a147a5 100644 --- a/tests/ui/non_send_fields_in_send_ty.stderr +++ b/tests/ui/non_send_fields_in_send_ty.stderr @@ -1,167 +1,167 @@ error: some fields in `RingBuffer` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:16:1 + --> $DIR/non_send_fields_in_send_ty.rs:17:1 | LL | unsafe impl Send for RingBuffer {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings` note: it is not safe to send field `data` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:11:5 + --> $DIR/non_send_fields_in_send_ty.rs:12:5 | LL | data: Vec>, | ^^^^^^^^^^^^^^^^^^^^^^^^ = help: add bounds on type parameter `T` that satisfy `Vec>: Send` error: some fields in `MvccRwLock` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:24:1 + --> $DIR/non_send_fields_in_send_ty.rs:25:1 | LL | unsafe impl Send for MvccRwLock {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `lock` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:21:5 + --> $DIR/non_send_fields_in_send_ty.rs:22:5 | LL | lock: Mutex>, | ^^^^^^^^^^^^^^^^^^^ = help: add bounds on type parameter `T` that satisfy `Mutex>: Send` error: some fields in `ArcGuard` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:32:1 + --> $DIR/non_send_fields_in_send_ty.rs:33:1 | LL | unsafe impl Send for ArcGuard {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `head` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:29:5 + --> $DIR/non_send_fields_in_send_ty.rs:30:5 | LL | head: Arc, | ^^^^^^^^^^^^^ = help: add bounds on type parameter `RC` that satisfy `Arc: Send` error: some fields in `DeviceHandle` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:48:1 + --> $DIR/non_send_fields_in_send_ty.rs:49:1 | LL | unsafe impl Send for DeviceHandle {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `context` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:44:5 + --> $DIR/non_send_fields_in_send_ty.rs:45:5 | LL | context: T, | ^^^^^^^^^^ = help: add `T: Send` bound in `Send` impl error: some fields in `NoGeneric` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:55:1 + --> $DIR/non_send_fields_in_send_ty.rs:56:1 | LL | unsafe impl Send for NoGeneric {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `rc_is_not_send` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:52:5 + --> $DIR/non_send_fields_in_send_ty.rs:53:5 | LL | rc_is_not_send: Rc, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` error: some fields in `MultiField` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:63:1 + --> $DIR/non_send_fields_in_send_ty.rs:64:1 | LL | unsafe impl Send for MultiField {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:58:5 + --> $DIR/non_send_fields_in_send_ty.rs:59:5 | LL | field1: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl note: it is not safe to send field `field2` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:59:5 + --> $DIR/non_send_fields_in_send_ty.rs:60:5 | LL | field2: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl note: it is not safe to send field `field3` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:60:5 + --> $DIR/non_send_fields_in_send_ty.rs:61:5 | LL | field3: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl error: some fields in `MyOption` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:70:1 + --> $DIR/non_send_fields_in_send_ty.rs:71:1 | LL | unsafe impl Send for MyOption {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `0` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:66:12 + --> $DIR/non_send_fields_in_send_ty.rs:67:12 | LL | MySome(T), | ^ = help: add `T: Send` bound in `Send` impl error: some fields in `MultiParam` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:82:1 + --> $DIR/non_send_fields_in_send_ty.rs:83:1 | LL | unsafe impl Send for MultiParam {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `vec` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:79:5 + --> $DIR/non_send_fields_in_send_ty.rs:80:5 | LL | vec: Vec<(A, B)>, | ^^^^^^^^^^^^^^^^ = help: add bounds on type parameters `A, B` that satisfy `Vec<(A, B)>: Send` error: some fields in `HeuristicTest` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:100:1 + --> $DIR/non_send_fields_in_send_ty.rs:101:1 | LL | unsafe impl Send for HeuristicTest {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field4` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:95:5 + --> $DIR/non_send_fields_in_send_ty.rs:96:5 | LL | field4: (*const NonSend, Rc), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` error: some fields in `AttrTest3` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:119:1 + --> $DIR/non_send_fields_in_send_ty.rs:120:1 | LL | unsafe impl Send for AttrTest3 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `0` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:114:11 + --> $DIR/non_send_fields_in_send_ty.rs:115:11 | LL | Enum2(T), | ^ = help: add `T: Send` bound in `Send` impl error: some fields in `Complex` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:127:1 + --> $DIR/non_send_fields_in_send_ty.rs:128:1 | LL | unsafe impl

Send for Complex {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:123:5 + --> $DIR/non_send_fields_in_send_ty.rs:124:5 | LL | field1: A, | ^^^^^^^^^ = help: add `P: Send` bound in `Send` impl error: some fields in `Complex>` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:130:1 + --> $DIR/non_send_fields_in_send_ty.rs:131:1 | LL | unsafe impl Send for Complex> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field2` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:124:5 + --> $DIR/non_send_fields_in_send_ty.rs:125:5 | LL | field2: B, | ^^^^^^^^^ From 01542668cd94c6705867ec346686484b0a139a27 Mon Sep 17 00:00:00 2001 From: lcnr Date: Tue, 25 Jan 2022 08:42:52 +0100 Subject: [PATCH 0409/1222] remove `TyS::same_type` it ignored regions and constants in adts, but didn't do so for references or any other types. This seemed quite weird --- clippy_lints/src/dereference.rs | 4 ++-- clippy_lints/src/implicit_hasher.rs | 4 ++-- clippy_lints/src/len_zero.rs | 4 ++-- clippy_lints/src/loops/explicit_into_iter_loop.rs | 3 +-- clippy_lints/src/loops/explicit_iter_loop.rs | 4 ++-- clippy_lints/src/matches.rs | 4 ++-- clippy_lints/src/methods/filter_map.rs | 3 +-- clippy_lints/src/methods/implicit_clone.rs | 3 +-- clippy_lints/src/methods/mod.rs | 4 ++-- clippy_lints/src/methods/unnecessary_filter_map.rs | 4 ++-- clippy_lints/src/needless_option_as_deref.rs | 3 +-- clippy_lints/src/needless_question_mark.rs | 3 +-- clippy_lints/src/new_without_default.rs | 3 +-- clippy_lints/src/redundant_slicing.rs | 3 +-- clippy_lints/src/size_of_in_element_count.rs | 4 ++-- clippy_utils/src/hir_utils.rs | 2 +- clippy_utils/src/ty.rs | 2 +- 17 files changed, 25 insertions(+), 32 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index c0adab790f0d..6d0851d804c2 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -12,7 +12,7 @@ use rustc_hir::{ }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability}; -use rustc_middle::ty::{self, Ty, TyCtxt, TyS, TypeckResults}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeckResults}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{symbol::sym, Span}; @@ -448,7 +448,7 @@ fn try_parse_ref_op<'tcx>( // the reference. fn deref_method_same_type(result_ty: Ty<'_>, arg_ty: Ty<'_>) -> bool { match (result_ty.kind(), arg_ty.kind()) { - (ty::Ref(_, result_ty, _), ty::Ref(_, arg_ty, _)) => TyS::same_type(result_ty, arg_ty), + (ty::Ref(_, result_ty, _), ty::Ref(_, arg_ty, _)) => result_ty == arg_ty, // The result type for a deref method is always a reference // Not matching the previous pattern means the argument type is not a reference diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index eed25e9bc0ea..a2f943b03ef4 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -8,7 +8,7 @@ use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind} use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{Ty, TyS, TypeckResults}; +use rustc_middle::ty::{Ty, TypeckResults}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::symbol::sym; @@ -346,7 +346,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't if let TyKind::Path(QPath::Resolved(None, ty_path)) = ty.kind; if let Some(ty_did) = ty_path.res.opt_def_id(); then { - if !TyS::same_type(self.target.ty(), self.maybe_typeck_results.unwrap().expr_ty(e)) { + if self.target.ty() != self.maybe_typeck_results.unwrap().expr_ty(e) { return; } diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 530b0a90ebd8..3418d276c535 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -10,7 +10,7 @@ use rustc_hir::{ ItemKind, Mutability, Node, TraitItemRef, TyKind, }; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, AssocKind, FnSig, Ty, TyS}; +use rustc_middle::ty::{self, AssocKind, FnSig, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{ source_map::{Span, Spanned, Symbol}, @@ -265,7 +265,7 @@ impl LenOutput<'_> { (_, &ty::Bool) => true, (Self::Option(id), &ty::Adt(adt, subs)) if id == adt.did => subs.type_at(0).is_bool(), (Self::Result(id, err_ty), &ty::Adt(adt, subs)) if id == adt.did => { - subs.type_at(0).is_bool() && TyS::same_type(subs.type_at(1), err_ty) + subs.type_at(0).is_bool() && subs.type_at(1) == err_ty }, _ => false, } diff --git a/clippy_lints/src/loops/explicit_into_iter_loop.rs b/clippy_lints/src/loops/explicit_into_iter_loop.rs index 17246cc5426a..175e2b382e3f 100644 --- a/clippy_lints/src/loops/explicit_into_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_into_iter_loop.rs @@ -5,13 +5,12 @@ use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; -use rustc_middle::ty::TyS; use rustc_span::symbol::sym; pub(super) fn check(cx: &LateContext<'_>, self_arg: &Expr<'_>, call_expr: &Expr<'_>) { let self_ty = cx.typeck_results().expr_ty(self_arg); let self_ty_adjusted = cx.typeck_results().expr_ty_adjusted(self_arg); - if !(TyS::same_type(self_ty, self_ty_adjusted) && is_trait_method(cx, call_expr, sym::IntoIterator)) { + if !(self_ty == self_ty_adjusted && is_trait_method(cx, call_expr, sym::IntoIterator)) { return; } diff --git a/clippy_lints/src/loops/explicit_iter_loop.rs b/clippy_lints/src/loops/explicit_iter_loop.rs index 5ac69d106ceb..5f5beccd030c 100644 --- a/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_iter_loop.rs @@ -6,7 +6,7 @@ use clippy_utils::ty::is_type_diagnostic_item; use rustc_errors::Applicability; use rustc_hir::{Expr, Mutability}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty, TyS}; +use rustc_middle::ty::{self, Ty}; use rustc_span::sym; pub(super) fn check(cx: &LateContext<'_>, self_arg: &Expr<'_>, arg: &Expr<'_>, method_name: &str) { @@ -22,7 +22,7 @@ pub(super) fn check(cx: &LateContext<'_>, self_arg: &Expr<'_>, arg: &Expr<'_>, m mutbl: Mutability::Not, }, ); - TyS::same_type(receiver_ty_adjusted, ref_receiver_ty) + receiver_ty_adjusted == ref_receiver_ty }, _ => false, }; diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 2579404fb18c..e61cb4d22736 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -26,7 +26,7 @@ use rustc_hir::{ }; use rustc_hir::{HirIdMap, HirIdSet}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, Ty, TyS, VariantDef}; +use rustc_middle::ty::{self, Ty, VariantDef}; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::{Span, Spanned}; @@ -2262,7 +2262,7 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) { }; // the names technically don't have to match; this makes the lint more conservative if cx.tcx.hir().name(a_id) == cx.tcx.hir().name(b_id); - if TyS::same_type(cx.typeck_results().expr_ty(a), cx.typeck_results().expr_ty(b)); + if cx.typeck_results().expr_ty(a) == cx.typeck_results().expr_ty(b); if pat_contains_local(lhs.pat, a_id); if pat_contains_local(rhs.pat, b_id); then { diff --git a/clippy_lints/src/methods/filter_map.rs b/clippy_lints/src/methods/filter_map.rs index ba1af9f3d62b..30c68186b3ae 100644 --- a/clippy_lints/src/methods/filter_map.rs +++ b/clippy_lints/src/methods/filter_map.rs @@ -8,7 +8,6 @@ use rustc_hir as hir; use rustc_hir::def::Res; use rustc_hir::{Expr, ExprKind, PatKind, QPath, UnOp}; use rustc_lint::LateContext; -use rustc_middle::ty::TyS; use rustc_span::source_map::Span; use rustc_span::symbol::{sym, Symbol}; use std::borrow::Cow; @@ -149,7 +148,7 @@ pub(super) fn check<'tcx>( if_chain! { if path_to_local_id(a_path, filter_param_id); if path_to_local_id(b, map_param_id); - if TyS::same_type(cx.typeck_results().expr_ty_adjusted(a), cx.typeck_results().expr_ty_adjusted(b)); + if cx.typeck_results().expr_ty_adjusted(a) == cx.typeck_results().expr_ty_adjusted(b); then { return true; } diff --git a/clippy_lints/src/methods/implicit_clone.rs b/clippy_lints/src/methods/implicit_clone.rs index 865e7702b715..7a255baffd74 100644 --- a/clippy_lints/src/methods/implicit_clone.rs +++ b/clippy_lints/src/methods/implicit_clone.rs @@ -6,7 +6,6 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; -use rustc_middle::ty::TyS; use rustc_span::sym; use super::IMPLICIT_CLONE; @@ -19,7 +18,7 @@ pub fn check(cx: &LateContext<'_>, method_name: &str, expr: &hir::Expr<'_>, recv let input_type = cx.typeck_results().expr_ty(recv); let (input_type, ref_count) = peel_mid_ty_refs(input_type); if let Some(ty_name) = input_type.ty_adt_def().map(|adt_def| cx.tcx.item_name(adt_def.did)); - if TyS::same_type(return_type, input_type); + if return_type == input_type; then { let mut app = Applicability::MachineApplicable; let recv_snip = snippet_with_context(cx, recv.span, expr.span.ctxt(), "..", &mut app).0; diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 4b43448bf7b9..80e1eb86e6c6 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -78,7 +78,7 @@ use rustc_hir::def::Res; use rustc_hir::{Expr, ExprKind, PrimTy, QPath, TraitItem, TraitItemKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, TraitRef, Ty, TyS}; +use rustc_middle::ty::{self, TraitRef, Ty}; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{sym, Span}; @@ -2195,7 +2195,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { } } - if name == "new" && !TyS::same_type(ret_ty, self_ty) { + if name == "new" && ret_ty != self_ty { span_lint( cx, NEW_RET_NO_SELF, diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index 784014f0d874..ccfce31713f9 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -5,7 +5,7 @@ use rustc_hir as hir; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::LangItem::{OptionNone, OptionSome}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, TyS}; +use rustc_middle::ty; use rustc_span::sym; use super::UNNECESSARY_FILTER_MAP; @@ -34,7 +34,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr< let in_ty = cx.typeck_results().node_type(body.params[0].hir_id); match cx.typeck_results().expr_ty(&body.value).kind() { ty::Adt(adt, subst) - if cx.tcx.is_diagnostic_item(sym::Option, adt.did) && TyS::same_type(in_ty, subst.type_at(0)) => + if cx.tcx.is_diagnostic_item(sym::Option, adt.did) && in_ty == subst.type_at(0) => { "filter" }, diff --git a/clippy_lints/src/needless_option_as_deref.rs b/clippy_lints/src/needless_option_as_deref.rs index 21d8263390af..9d3d7d1f24cb 100644 --- a/clippy_lints/src/needless_option_as_deref.rs +++ b/clippy_lints/src/needless_option_as_deref.rs @@ -4,7 +4,6 @@ use clippy_utils::ty::is_type_diagnostic_item; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::TyS; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; @@ -49,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for OptionNeedlessDeref { if let ExprKind::MethodCall(path, [sub_expr], _) = expr.kind; let symbol = path.ident.as_str(); if symbol == "as_deref" || symbol == "as_deref_mut"; - if TyS::same_type( outer_ty, typeck.expr_ty(sub_expr) ); + if outer_ty == typeck.expr_ty(sub_expr); then{ span_lint_and_sugg( cx, diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index d4c823d1c1ab..8f85b00596c0 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -6,7 +6,6 @@ use rustc_errors::Applicability; use rustc_hir::LangItem::{OptionSome, ResultOk}; use rustc_hir::{AsyncGeneratorKind, Block, Body, Expr, ExprKind, GeneratorKind, LangItem, MatchSource, QPath}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::TyS; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { @@ -128,7 +127,7 @@ fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { if expr.span.ctxt() == inner_expr.span.ctxt(); let expr_ty = cx.typeck_results().expr_ty(expr); let inner_ty = cx.typeck_results().expr_ty(inner_expr); - if TyS::same_type(expr_ty, inner_ty); + if expr_ty == inner_ty; then { span_lint_and_sugg( cx, diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index aec95530bba6..f86af7a7bb6e 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -8,7 +8,6 @@ use rustc_hir as hir; use rustc_hir::HirIdSet; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::TyS; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::sym; @@ -103,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { if cx.access_levels.is_reachable(impl_item.def_id); let self_def_id = cx.tcx.hir().get_parent_item(id); let self_ty = cx.tcx.type_of(self_def_id); - if TyS::same_type(self_ty, return_ty(cx, id)); + if self_ty == return_ty(cx, id); if let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default); then { if self.impling_types.is_none() { diff --git a/clippy_lints/src/redundant_slicing.rs b/clippy_lints/src/redundant_slicing.rs index 7c88b42ea319..cd3aee556553 100644 --- a/clippy_lints/src/redundant_slicing.rs +++ b/clippy_lints/src/redundant_slicing.rs @@ -6,7 +6,6 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::TyS; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { @@ -54,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing { if addressee.span.ctxt() == ctxt; if let ExprKind::Index(indexed, range) = addressee.kind; if is_type_lang_item(cx, cx.typeck_results().expr_ty_adjusted(range), LangItem::RangeFull); - if TyS::same_type(cx.typeck_results().expr_ty(expr), cx.typeck_results().expr_ty(indexed)); + if cx.typeck_results().expr_ty(expr) == cx.typeck_results().expr_ty(indexed); then { let mut app = Applicability::MachineApplicable; let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0; diff --git a/clippy_lints/src/size_of_in_element_count.rs b/clippy_lints/src/size_of_in_element_count.rs index c7c57ab426d9..971729e5c54b 100644 --- a/clippy_lints/src/size_of_in_element_count.rs +++ b/clippy_lints/src/size_of_in_element_count.rs @@ -7,7 +7,7 @@ use if_chain::if_chain; use rustc_hir::BinOpKind; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, Ty, TyS, TypeAndMut}; +use rustc_middle::ty::{self, Ty, TypeAndMut}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { @@ -138,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for SizeOfInElementCount { // Find a size_of call in the count parameter expression and // check that it's the same type if let Some(ty_used_for_size_of) = get_size_of_ty(cx, count_expr, false); - if TyS::same_type(pointee_ty, ty_used_for_size_of); + if pointee_ty == ty_used_for_size_of; then { span_lint_and_help( cx, diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index ed573ad90561..7b5c5af8f79b 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -102,7 +102,7 @@ impl HirEqInterExpr<'_, '_, '_> { if let Some(typeck) = self.inner.maybe_typeck_results { let l_ty = typeck.pat_ty(l.pat); let r_ty = typeck.pat_ty(r.pat); - if !rustc_middle::ty::TyS::same_type(l_ty, r_ty) { + if l_ty != r_ty { return false; } } diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index d057da73302a..819ff917b633 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -42,7 +42,7 @@ pub fn can_partially_move_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool /// Walks into `ty` and returns `true` if any inner type is the same as `other_ty` pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool { ty.walk().any(|inner| match inner.unpack() { - GenericArgKind::Type(inner_ty) => ty::TyS::same_type(other_ty, inner_ty), + GenericArgKind::Type(inner_ty) => other_ty == inner_ty, GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false, }) } From 0f41059e7214935e6829e7d9a75c6b83034086f2 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 20 Aug 2021 14:47:12 +0000 Subject: [PATCH 0410/1222] Lazily resolve type-alias-impl-trait defining uses by using an opaque type obligation to bubble up comparisons between opaque types and other types Also uses proper obligation causes so that the body id works, because out of some reason nll uses body ids for logic instead of just diagnostics. --- clippy_utils/src/qualify_min_const_fn.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 7512039a480b..5407b5e8ed93 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -32,6 +32,7 @@ pub fn is_min_const_fn<'a, 'tcx>(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: | ty::PredicateKind::Projection(_) | ty::PredicateKind::ConstEvaluatable(..) | ty::PredicateKind::ConstEquate(..) + | ty::PredicateKind::OpaqueType(..) | ty::PredicateKind::TypeWellFormedFromEnv(..) => continue, ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate), ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate), From f41f3d1f9b0bcd355e2c48335fa8dacd0b772f57 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 2 Feb 2022 12:44:51 +0100 Subject: [PATCH 0411/1222] Remove defaultness from ImplItem. --- clippy_lints/src/utils/inspector.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index b58325ac73ee..869114831370 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -54,9 +54,6 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector { ), hir::VisibilityKind::Inherited => println!("visibility inherited from outer item"), } - if item.defaultness.is_default() { - println!("default"); - } match item.kind { hir::ImplItemKind::Const(_, body_id) => { println!("associated constant"); From c79f5713ff114a44e86f0e0766d42acc6a37ae33 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 10 Feb 2022 19:52:01 +0100 Subject: [PATCH 0412/1222] Clippy: Fix botstrap fallout --- clippy_lints/src/lib.rs | 3 +- .../src/transmute/transmute_undefined_repr.rs | 42 ++++++++++--------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 9999cd3f8243..5c45012ef068 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -5,7 +5,6 @@ #![feature(control_flow_enum)] #![feature(drain_filter)] #![feature(iter_intersperse)] -#![feature(let_chains)] #![feature(let_else)] #![feature(once_cell)] #![feature(rustc_private)] @@ -19,7 +18,7 @@ // warn on rustc internal lints #![warn(rustc::internal)] // Disable this rustc lint for now, as it was also done in rustc -#![allow(rustc::potential_query_instability)] +#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))] // FIXME: switch to something more ergonomic here, once available. // (Currently there is no way to opt into sysroot crates without `extern crate`.) diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index c91bc3245e41..030d2c237848 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -111,19 +111,21 @@ pub(super) fn check<'tcx>( from_ty_orig, to_ty_orig ), |diag| { - if let (Some(from_def), Some(to_def)) = (from_ty.ty_adt_def(), to_ty.ty_adt_def()) - && from_def == to_def - { - diag.note(&format!( - "two instances of the same generic type (`{}`) may have different layouts", - cx.tcx.item_name(from_def.did) - )); - } else { - if from_ty_orig.peel_refs() != from_ty { - diag.note(&format!("the contained type `{}` has an undefined layout", from_ty)); - } - if to_ty_orig.peel_refs() != to_ty { - diag.note(&format!("the contained type `{}` has an undefined layout", to_ty)); + if_chain! { + if let (Some(from_def), Some(to_def)) = (from_ty.ty_adt_def(), to_ty.ty_adt_def()); + if from_def == to_def; + then { + diag.note(&format!( + "two instances of the same generic type (`{}`) may have different layouts", + cx.tcx.item_name(from_def.did) + )); + } else { + if from_ty_orig.peel_refs() != from_ty { + diag.note(&format!("the contained type `{}` has an undefined layout", from_ty)); + } + if to_ty_orig.peel_refs() != to_ty { + diag.note(&format!("the contained type `{}` has an undefined layout", to_ty)); + } } } }, @@ -279,11 +281,13 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> } fn is_zero_sized_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { - if let Ok(ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, ty) - && let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty)) - { - layout.layout.size.bytes() == 0 - } else { - false + if_chain! { + if let Ok(ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, ty); + if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty)); + then { + layout.layout.size.bytes() == 0 + } else { + false + } } } From 1dfe260a6ed5b860f2eae60a3001aefb7ccfc973 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 11 Feb 2022 07:18:06 +0000 Subject: [PATCH 0413/1222] Revert "Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis" This reverts commit e7cc3bddbe0d0e374d05e7003e662bba1742dbae, reversing changes made to 734368a200904ef9c21db86c595dc04263c87be0. --- clippy_utils/src/qualify_min_const_fn.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 5407b5e8ed93..7512039a480b 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -32,7 +32,6 @@ pub fn is_min_const_fn<'a, 'tcx>(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: | ty::PredicateKind::Projection(_) | ty::PredicateKind::ConstEvaluatable(..) | ty::PredicateKind::ConstEquate(..) - | ty::PredicateKind::OpaqueType(..) | ty::PredicateKind::TypeWellFormedFromEnv(..) => continue, ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate), ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate), From b5603b817c5367c217c2d3b8172fcbdfaaba1f50 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 28 Jan 2022 18:14:18 +0100 Subject: [PATCH 0414/1222] Bless clippy test. --- tests/ui/manual_async_fn.fixed | 1 + tests/ui/manual_async_fn.rs | 1 + tests/ui/manual_async_fn.stderr | 2 +- tests/ui/needless_lifetimes.stderr | 8 +++++++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/ui/manual_async_fn.fixed b/tests/ui/manual_async_fn.fixed index 136cc96be70c..e9ca66f125d8 100644 --- a/tests/ui/manual_async_fn.fixed +++ b/tests/ui/manual_async_fn.fixed @@ -80,6 +80,7 @@ fn elided_not_bound(_: &i32) -> impl Future { async { 42 } } +#[allow(clippy::needless_lifetimes)] async fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> i32 { 42 } // should be ignored diff --git a/tests/ui/manual_async_fn.rs b/tests/ui/manual_async_fn.rs index ddc453ffdb75..c3fa846485ba 100644 --- a/tests/ui/manual_async_fn.rs +++ b/tests/ui/manual_async_fn.rs @@ -98,6 +98,7 @@ fn elided_not_bound(_: &i32) -> impl Future { async { 42 } } +#[allow(clippy::needless_lifetimes)] fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { async { 42 } } diff --git a/tests/ui/manual_async_fn.stderr b/tests/ui/manual_async_fn.stderr index 7435f46074c8..b83abfccd4e1 100644 --- a/tests/ui/manual_async_fn.stderr +++ b/tests/ui/manual_async_fn.stderr @@ -140,7 +140,7 @@ LL | fn elided(_: &i32) -> impl Future + '_ { 42 } | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:101:1 + --> $DIR/manual_async_fn.rs:102:1 | LL | fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/needless_lifetimes.stderr b/tests/ui/needless_lifetimes.stderr index ffa152427a97..8df50d79ca57 100644 --- a/tests/ui/needless_lifetimes.stderr +++ b/tests/ui/needless_lifetimes.stderr @@ -18,6 +18,12 @@ error: explicit lifetimes given in parameter types where they could be elided (o LL | fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) + --> $DIR/needless_lifetimes.rs:37:1 + | +LL | async fn func<'a>(args: &[&'a str]) -> Option<&'a str> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) --> $DIR/needless_lifetimes.rs:56:1 | @@ -192,5 +198,5 @@ error: explicit lifetimes given in parameter types where they could be elided (o LL | fn lifetime_elsewhere_provided<'a>(self: Box, here: &'a ()) -> &'a () { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 32 previous errors +error: aborting due to 33 previous errors From 79702f237d2029c556e1500c1545446dd4a46dbf Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 9 Feb 2022 11:03:27 +0000 Subject: [PATCH 0415/1222] change to a struct variant --- clippy_lints/src/trait_bounds.rs | 2 +- clippy_lints/src/use_self.rs | 4 ++-- clippy_utils/src/lib.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 5257f5302cd9..bca95b7f2563 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { if let WherePredicate::BoundPredicate(ref bound_predicate) = predicate; if !bound_predicate.span.from_expansion(); if let TyKind::Path(QPath::Resolved(_, Path { segments, .. })) = bound_predicate.bounded_ty.kind; - if let Some(PathSegment { res: Some(Res::SelfTy(Some(def_id), _)), .. }) = segments.first(); + if let Some(PathSegment { res: Some(Res::SelfTy{ trait_: Some(def_id), alias_to: _ }), .. }) = segments.first(); if let Some( Node::Item( diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index be20282b3b88..80164c59ba74 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -204,7 +204,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { ref types_to_skip, }) = self.stack.last(); if let TyKind::Path(QPath::Resolved(_, path)) = hir_ty.kind; - if !matches!(path.res, Res::SelfTy(..) | Res::Def(DefKind::TyParam, _)); + if !matches!(path.res, Res::SelfTy { .. } | Res::Def(DefKind::TyParam, _)); if !types_to_skip.contains(&hir_ty.hir_id); let ty = if in_body > 0 { cx.typeck_results().node_type(hir_ty.hir_id) @@ -231,7 +231,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { } match expr.kind { ExprKind::Struct(QPath::Resolved(_, path), ..) => match path.res { - Res::SelfTy(..) => (), + Res::SelfTy { .. } => (), Res::Def(DefKind::Variant, _) => lint_path_to_variant(cx, path), _ => span_lint(cx, path.span), }, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 42955080c966..f775cdd3bc28 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1460,7 +1460,7 @@ pub fn is_self(slf: &Param<'_>) -> bool { pub fn is_self_ty(slf: &hir::Ty<'_>) -> bool { if let TyKind::Path(QPath::Resolved(None, path)) = slf.kind { - if let Res::SelfTy(..) = path.res { + if let Res::SelfTy { .. } = path.res { return true; } } From a4616f9e86895bd4ff3ae016b0dc55096cd60ccf Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 25 Jan 2022 14:13:38 +1100 Subject: [PATCH 0416/1222] Overhaul `TyS` and `Ty`. Specifically, change `Ty` from this: ``` pub type Ty<'tcx> = &'tcx TyS<'tcx>; ``` to this ``` pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>); ``` There are two benefits to this. - It's now a first class type, so we can define methods on it. This means we can move a lot of methods away from `TyS`, leaving `TyS` as a barely-used type, which is appropriate given that it's not meant to be used directly. - The uniqueness requirement is now explicit, via the `Interned` type. E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather than via `TyS`, which wasn't obvious at all. Much of this commit is boring churn. The interesting changes are in these files: - compiler/rustc_middle/src/arena.rs - compiler/rustc_middle/src/mir/visit.rs - compiler/rustc_middle/src/ty/context.rs - compiler/rustc_middle/src/ty/mod.rs Specifically: - Most mentions of `TyS` are removed. It's very much a dumb struct now; `Ty` has all the smarts. - `TyS` now has `crate` visibility instead of `pub`. - `TyS::make_for_test` is removed in favour of the static `BOOL_TY`, which just works better with the new structure. - The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned` (pointer-based, for the `Equal` case) and partly on `TyS` (contents-based, for the other cases). - There are many tedious sigil adjustments, i.e. adding or removing `*` or `&`. They seem to be unavoidable. --- .../case_sensitive_file_extension_comparisons.rs | 2 +- clippy_lints/src/default_numeric_fallback.rs | 6 +++--- clippy_lints/src/eq_op.rs | 8 ++++---- clippy_lints/src/format_args.rs | 2 +- clippy_lints/src/index_refutable_slice.rs | 2 +- clippy_lints/src/large_const_arrays.rs | 2 +- clippy_lints/src/large_stack_arrays.rs | 2 +- clippy_lints/src/len_zero.rs | 2 +- clippy_lints/src/loops/explicit_counter_loop.rs | 4 ++-- clippy_lints/src/loops/manual_memcpy.rs | 4 ++-- clippy_lints/src/loops/needless_collect.rs | 6 +++--- clippy_lints/src/loops/utils.rs | 2 +- clippy_lints/src/map_clone.rs | 2 +- .../src/matches/redundant_pattern_match.rs | 2 +- clippy_lints/src/matches/single_match.rs | 6 +++--- .../src/methods/cloned_instead_of_copied.rs | 2 +- .../src/methods/iter_overeager_cloned.rs | 2 +- clippy_lints/src/methods/manual_str_repeat.rs | 6 +++--- clippy_lints/src/methods/mod.rs | 6 +++--- clippy_lints/src/methods/unnecessary_to_owned.rs | 4 ++-- clippy_lints/src/methods/utils.rs | 4 ++-- .../src/methods/wrong_self_convention.rs | 8 ++++---- clippy_lints/src/methods/zst_offset.rs | 2 +- clippy_lints/src/modulo_arithmetic.rs | 4 ++-- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/mut_mutex_lock.rs | 2 +- clippy_lints/src/non_send_fields_in_send_ty.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 4 ++-- clippy_lints/src/size_of_in_element_count.rs | 2 +- .../src/transmute/transmute_ptr_to_ref.rs | 2 +- .../src/transmute/transmute_ref_to_ref.rs | 4 ++-- .../src/transmute/transmute_undefined_repr.rs | 16 ++++++++-------- clippy_lints/src/transmute/useless_transmute.rs | 2 +- clippy_lints/src/unit_return_expecting_ord.rs | 3 ++- clippy_utils/src/lib.rs | 4 ++-- clippy_utils/src/qualify_min_const_fn.rs | 2 +- clippy_utils/src/ty.rs | 16 ++++++++-------- doc/common_tools_writing_lints.md | 4 ++-- 38 files changed, 78 insertions(+), 77 deletions(-) diff --git a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs index e71f110820c0..7637666d059e 100644 --- a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs +++ b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs @@ -47,7 +47,7 @@ fn check_case_sensitive_file_extension_comparison(ctx: &LateContext<'_>, expr: & then { let mut ty = ctx.typeck_results().expr_ty(obj); ty = match ty.kind() { - ty::Ref(_, ty, ..) => ty, + ty::Ref(_, ty, ..) => *ty, _ => ty }; diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index fb201d2c012b..b80d55dd192a 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -123,7 +123,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { if let Some(fn_sig) = fn_sig_opt(self.cx, func.hir_id) { for (expr, bound) in iter::zip(*args, fn_sig.skip_binder().inputs()) { // Push found arg type, then visit arg. - self.ty_bounds.push(TyBound::Ty(bound)); + self.ty_bounds.push(TyBound::Ty(*bound)); self.visit_expr(expr); self.ty_bounds.pop(); } @@ -135,7 +135,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) { let fn_sig = self.cx.tcx.fn_sig(def_id).skip_binder(); for (expr, bound) in iter::zip(*args, fn_sig.inputs()) { - self.ty_bounds.push(TyBound::Ty(bound)); + self.ty_bounds.push(TyBound::Ty(*bound)); self.visit_expr(expr); self.ty_bounds.pop(); } @@ -210,7 +210,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option> { let node_ty = cx.typeck_results().node_type_opt(hir_id)?; - // We can't use `TyS::fn_sig` because it automatically performs substs, this may result in FNs. + // We can't use `Ty::fn_sig` because it automatically performs substs, this may result in FNs. match node_ty.kind() { ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(*def_id)), ty::FnPtr(fn_sig) => Some(*fn_sig), diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 24d7613e6f8c..ea547793b1ea 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -7,10 +7,10 @@ use clippy_utils::{ast_utils::is_useless_with_eq_exprs, eq_expr_value, is_in_tes use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{ - def::Res, def_id::DefId, BinOpKind, BorrowKind, Expr, ExprKind, GenericArg, ItemKind, QPath, Ty, TyKind, + def::Res, def_id::DefId, BinOpKind, BorrowKind, Expr, ExprKind, GenericArg, ItemKind, QPath, TyKind, }; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, TyS}; +use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { @@ -279,7 +279,7 @@ impl<'tcx> LateLintPass<'tcx> for EqOp { } } -fn in_impl<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, bin_op: DefId) -> Option<(&'tcx Ty<'tcx>, &'tcx Ty<'tcx>)> { +fn in_impl<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, bin_op: DefId) -> Option<(&'tcx rustc_hir::Ty<'tcx>, &'tcx rustc_hir::Ty<'tcx>)> { if_chain! { if let Some(block) = get_enclosing_block(cx, e.hir_id); if let Some(impl_def_id) = cx.tcx.impl_of_method(block.hir_id.owner.to_def_id()); @@ -301,7 +301,7 @@ fn in_impl<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, bin_op: DefId) -> Op } } -fn are_equal<'tcx>(cx: &LateContext<'tcx>, middle_ty: &TyS<'_>, hir_ty: &Ty<'_>) -> bool { +fn are_equal<'tcx>(cx: &LateContext<'tcx>, middle_ty: Ty<'_>, hir_ty: &rustc_hir::Ty<'_>) -> bool { if_chain! { if let ty::Adt(adt_def, _) = middle_ty.kind(); if let Some(local_did) = adt_def.did.as_local(); diff --git a/clippy_lints/src/format_args.rs b/clippy_lints/src/format_args.rs index 17b0749a4a99..503aac8ccd02 100644 --- a/clippy_lints/src/format_args.rs +++ b/clippy_lints/src/format_args.rs @@ -211,7 +211,7 @@ where if overloaded_deref.is_some() { n_needed = n_total; } - ty = target; + ty = *target; } else { return (n_needed, ty); } diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index 2a4bcd773c68..6b62748ffef2 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -118,7 +118,7 @@ fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap LateLintPass<'tcx> for LargeConstArrays { if let ty::Array(element_type, cst) = ty.kind(); if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val; if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx); - if let Ok(element_size) = cx.layout_of(element_type).map(|l| l.size.bytes()); + if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()); if self.maximum_allowed_size < element_count * element_size; then { diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index 1cc2c28c04ad..b9e246290ff7 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays { if let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind(); if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val; if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx); - if let Ok(element_size) = cx.layout_of(element_type).map(|l| l.size.bytes()); + if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()); if self.maximum_allowed_size < element_count * element_size; then { span_lint_and_help( diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 3418d276c535..35d10d53112e 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -294,7 +294,7 @@ impl LenOutput<'_> { /// Checks if the given signature matches the expectations for `is_empty` fn check_is_empty_sig(sig: FnSig<'_>, self_kind: ImplicitSelfKind, len_output: LenOutput<'_>) -> bool { match &**sig.inputs_and_output { - [arg, res] if len_output.matches_is_empty_output(res) => { + [arg, res] if len_output.matches_is_empty_output(*res) => { matches!( (arg.kind(), self_kind), (ty::Ref(_, _, Mutability::Not), ImplicitSelfKind::ImmRef) diff --git a/clippy_lints/src/loops/explicit_counter_loop.rs b/clippy_lints/src/loops/explicit_counter_loop.rs index e0150990cfe5..fc50e8addcce 100644 --- a/clippy_lints/src/loops/explicit_counter_loop.rs +++ b/clippy_lints/src/loops/explicit_counter_loop.rs @@ -7,7 +7,7 @@ use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_block, walk_expr}; use rustc_hir::{Expr, Pat}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, UintTy}; +use rustc_middle::ty::{self, Ty, UintTy}; // To trigger the EXPLICIT_COUNTER_LOOP lint, a variable must be // incremented exactly once in the loop body, and initialized to zero @@ -36,7 +36,7 @@ pub(super) fn check<'tcx>( then { let mut applicability = Applicability::MachineApplicable; - let int_name = match ty.map(ty::TyS::kind) { + let int_name = match ty.map(Ty::kind) { // usize or inferred Some(ty::Uint(UintTy::Usize)) | None => { span_lint_and_sugg( diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index ef0221639aa9..f6ef87264c0a 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -335,8 +335,8 @@ struct Start<'hir> { fn get_slice_like_element_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option> { match ty.kind() { ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Vec, adt.did) => Some(subs.type_at(0)), - ty::Ref(_, subty, _) => get_slice_like_element_ty(cx, subty), - ty::Slice(ty) | ty::Array(ty, _) => Some(ty), + ty::Ref(_, subty, _) => get_slice_like_element_ty(cx, *subty), + ty::Slice(ty) | ty::Array(ty, _) => Some(*ty), _ => None, } } diff --git a/clippy_lints/src/loops/needless_collect.rs b/clippy_lints/src/loops/needless_collect.rs index f57dcc2f5c45..06190850bb00 100644 --- a/clippy_lints/src/loops/needless_collect.rs +++ b/clippy_lints/src/loops/needless_collect.rs @@ -12,7 +12,7 @@ use rustc_hir::{Block, Expr, ExprKind, HirId, HirIdSet, Local, Mutability, Node, use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; use rustc_middle::ty::subst::GenericArgKind; -use rustc_middle::ty::{self, TyS}; +use rustc_middle::ty::{self, Ty}; use rustc_span::sym; use rustc_span::{MultiSpan, Span}; @@ -334,8 +334,8 @@ fn detect_iter_and_into_iters<'tcx: 'a, 'a>( } } -fn get_captured_ids(cx: &LateContext<'_>, ty: &'_ TyS<'_>) -> HirIdSet { - fn get_captured_ids_recursive(cx: &LateContext<'_>, ty: &'_ TyS<'_>, set: &mut HirIdSet) { +fn get_captured_ids(cx: &LateContext<'_>, ty: Ty<'_>) -> HirIdSet { + fn get_captured_ids_recursive(cx: &LateContext<'_>, ty: Ty<'_>, set: &mut HirIdSet) { match ty.kind() { ty::Adt(_, generics) => { for generic in *generics { diff --git a/clippy_lints/src/loops/utils.rs b/clippy_lints/src/loops/utils.rs index b6c746d3e397..772d251b620a 100644 --- a/clippy_lints/src/loops/utils.rs +++ b/clippy_lints/src/loops/utils.rs @@ -334,7 +334,7 @@ pub(super) fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic // (&mut x).into_iter() ==> x.iter_mut() let arg_ty = cx.typeck_results().expr_ty_adjusted(arg); match &arg_ty.kind() { - ty::Ref(_, inner_ty, mutbl) if has_iter_method(cx, inner_ty).is_some() => { + ty::Ref(_, inner_ty, mutbl) if has_iter_method(cx, *inner_ty).is_some() => { let method_name = match mutbl { Mutability::Mut => "iter_mut", Mutability::Not => "iter", diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 3f8eeb736fbd..e233300e26ab 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -100,7 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone { let obj_ty = cx.typeck_results().expr_ty(obj); if let ty::Ref(_, ty, mutability) = obj_ty.kind() { if matches!(mutability, Mutability::Not) { - let copy = is_copy(cx, ty); + let copy = is_copy(cx, *ty); self.lint_explicit_closure(cx, e.span, args[0].span, copy); } } else { diff --git a/clippy_lints/src/matches/redundant_pattern_match.rs b/clippy_lints/src/matches/redundant_pattern_match.rs index 61c5fa0872f6..e195fddefaba 100644 --- a/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/clippy_lints/src/matches/redundant_pattern_match.rs @@ -59,7 +59,7 @@ fn type_needs_ordered_drop_inner<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, see // Check if any component type has any. match ty.kind() { ty::Tuple(_) => ty.tuple_fields().any(|ty| type_needs_ordered_drop_inner(cx, ty, seen)), - ty::Array(ty, _) => type_needs_ordered_drop_inner(cx, ty, seen), + ty::Array(ty, _) => type_needs_ordered_drop_inner(cx, *ty, seen), ty::Adt(adt, subs) => adt .all_fields() .map(|f| f.ty(cx.tcx, subs)) diff --git a/clippy_lints/src/matches/single_match.rs b/clippy_lints/src/matches/single_match.rs index 6ba279eaf122..0c4cb45d147c 100644 --- a/clippy_lints/src/matches/single_match.rs +++ b/clippy_lints/src/matches/single_match.rs @@ -8,7 +8,7 @@ use core::cmp::max; use rustc_errors::Applicability; use rustc_hir::{Arm, BindingAnnotation, Block, Expr, ExprKind, Pat, PatKind}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty, TyS}; +use rustc_middle::ty::{self, Ty}; use super::{MATCH_BOOL, SINGLE_MATCH, SINGLE_MATCH_ELSE}; @@ -162,10 +162,10 @@ fn check_opt_like<'a>( return; } - let in_candidate_enum = |path_info: &(String, &TyS<'_>)| -> bool { + let in_candidate_enum = |path_info: &(String, Ty<'_>)| -> bool { let (path, ty) = path_info; for &(ty_path, pat_path) in candidates { - if path == pat_path && match_type(cx, ty, ty_path) { + if path == pat_path && match_type(cx, *ty, ty_path) { return true; } } diff --git a/clippy_lints/src/methods/cloned_instead_of_copied.rs b/clippy_lints/src/methods/cloned_instead_of_copied.rs index 6fe69b8f01f9..67a585edc255 100644 --- a/clippy_lints/src/methods/cloned_instead_of_copied.rs +++ b/clippy_lints/src/methods/cloned_instead_of_copied.rs @@ -30,7 +30,7 @@ pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span: Span, }; match inner_ty.kind() { // &T where T: Copy - ty::Ref(_, ty, _) if is_copy(cx, ty) => {}, + ty::Ref(_, ty, _) if is_copy(cx, *ty) => {}, _ => return, }; span_lint_and_sugg( diff --git a/clippy_lints/src/methods/iter_overeager_cloned.rs b/clippy_lints/src/methods/iter_overeager_cloned.rs index ca33bfc643da..b93f1399eaee 100644 --- a/clippy_lints/src/methods/iter_overeager_cloned.rs +++ b/clippy_lints/src/methods/iter_overeager_cloned.rs @@ -26,7 +26,7 @@ pub(super) fn check<'tcx>( }; match inner_ty.kind() { - ty::Ref(_, ty, _) if !is_copy(cx, ty) => {}, + ty::Ref(_, ty, _) if !is_copy(cx, *ty) => {}, _ => return, }; diff --git a/clippy_lints/src/methods/manual_str_repeat.rs b/clippy_lints/src/methods/manual_str_repeat.rs index d74c910b6767..68a75667914a 100644 --- a/clippy_lints/src/methods/manual_str_repeat.rs +++ b/clippy_lints/src/methods/manual_str_repeat.rs @@ -8,7 +8,7 @@ use rustc_ast::LitKind; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, LangItem}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty, TyS}; +use rustc_middle::ty::{self, Ty}; use rustc_span::symbol::sym; use std::borrow::Cow; @@ -37,8 +37,8 @@ fn parse_repeat_arg(cx: &LateContext<'_>, e: &Expr<'_>) -> Option { } else { let ty = cx.typeck_results().expr_ty(e); if is_type_diagnostic_item(cx, ty, sym::String) - || (is_type_lang_item(cx, ty, LangItem::OwnedBox) && get_ty_param(ty).map_or(false, TyS::is_str)) - || (match_type(cx, ty, &paths::COW) && get_ty_param(ty).map_or(false, TyS::is_str)) + || (is_type_lang_item(cx, ty, LangItem::OwnedBox) && get_ty_param(ty).map_or(false, Ty::is_str)) + || (match_type(cx, ty, &paths::COW) && get_ty_param(ty).map_or(false, Ty::is_str)) { Some(RepeatKind::String) } else { diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index c2202cb1e577..3021a40fae14 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2106,7 +2106,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { let method_sig = cx.tcx.fn_sig(impl_item.def_id); let method_sig = cx.tcx.erase_late_bound_regions(method_sig); - let first_arg_ty = &method_sig.inputs().iter().next(); + let first_arg_ty = method_sig.inputs().iter().next(); // check conventions w.r.t. conversion method names and predicates if let Some(first_arg_ty) = first_arg_ty; @@ -2119,7 +2119,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if name == method_config.method_name && sig.decl.inputs.len() == method_config.param_count && method_config.output_type.matches(&sig.decl.output) && - method_config.self_kind.matches(cx, self_ty, first_arg_ty) && + method_config.self_kind.matches(cx, self_ty, *first_arg_ty) && fn_header_equals(method_config.fn_header, sig.header) && method_config.lifetime_param_cond(impl_item) { @@ -2151,7 +2151,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { cx, name, self_ty, - first_arg_ty, + *first_arg_ty, first_arg.pat.span, implements_trait, false diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index b67bfb6597b0..7916fb8e3b45 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -105,7 +105,7 @@ fn check_addr_of_expr( if is_copy(cx, receiver_ty) || is_cow_into_owned(cx, method_name, method_def_id); if let Some(receiver_snippet) = snippet_opt(cx, receiver.span); then { - let (target_ty, n_target_refs) = peel_mid_ty_refs(target_ty); + let (target_ty, n_target_refs) = peel_mid_ty_refs(*target_ty); let (receiver_ty, n_receiver_refs) = peel_mid_ty_refs(receiver_ty); if receiver_ty == target_ty && n_target_refs >= n_receiver_refs { span_lint_and_sugg( @@ -228,7 +228,7 @@ fn check_other_call_arg<'tcx>( let fn_sig = cx.tcx.fn_sig(callee_def_id).skip_binder(); if let Some(i) = call_args.iter().position(|arg| arg.hir_id == maybe_arg.hir_id); if let Some(input) = fn_sig.inputs().get(i); - let (input, n_refs) = peel_mid_ty_refs(input); + let (input, n_refs) = peel_mid_ty_refs(*input); if let (trait_predicates, projection_predicates) = get_input_traits_and_projections(cx, callee_def_id, input); if let Some(sized_def_id) = cx.tcx.lang_items().sized_trait(); if let [trait_predicate] = trait_predicates diff --git a/clippy_lints/src/methods/utils.rs b/clippy_lints/src/methods/utils.rs index c4cf994aacaa..63c3273bd681 100644 --- a/clippy_lints/src/methods/utils.rs +++ b/clippy_lints/src/methods/utils.rs @@ -19,7 +19,7 @@ pub(super) fn derefs_to_slice<'tcx>( ty::Adt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()), ty::Adt(..) => is_type_diagnostic_item(cx, ty, sym::Vec), ty::Array(_, size) => size.try_eval_usize(cx.tcx, cx.param_env).is_some(), - ty::Ref(_, inner, _) => may_slice(cx, inner), + ty::Ref(_, inner, _) => may_slice(cx, *inner), _ => false, } } @@ -35,7 +35,7 @@ pub(super) fn derefs_to_slice<'tcx>( ty::Slice(_) => Some(expr), ty::Adt(def, _) if def.is_box() && may_slice(cx, ty.boxed_ty()) => Some(expr), ty::Ref(_, inner, _) => { - if may_slice(cx, inner) { + if may_slice(cx, *inner) { Some(expr) } else { None diff --git a/clippy_lints/src/methods/wrong_self_convention.rs b/clippy_lints/src/methods/wrong_self_convention.rs index a2e09e5ecec1..aecfea9c141c 100644 --- a/clippy_lints/src/methods/wrong_self_convention.rs +++ b/clippy_lints/src/methods/wrong_self_convention.rs @@ -2,7 +2,7 @@ use crate::methods::SelfKind; use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::is_copy; use rustc_lint::LateContext; -use rustc_middle::ty::TyS; +use rustc_middle::ty::Ty; use rustc_span::source_map::Span; use std::fmt; @@ -41,7 +41,7 @@ impl Convention { fn check<'tcx>( &self, cx: &LateContext<'tcx>, - self_ty: &'tcx TyS<'tcx>, + self_ty: Ty<'tcx>, other: &str, implements_trait: bool, is_trait_item: bool, @@ -84,8 +84,8 @@ impl fmt::Display for Convention { pub(super) fn check<'tcx>( cx: &LateContext<'tcx>, item_name: &str, - self_ty: &'tcx TyS<'tcx>, - first_arg_ty: &'tcx TyS<'tcx>, + self_ty: Ty<'tcx>, + first_arg_ty: Ty<'tcx>, first_arg_span: Span, implements_trait: bool, is_trait_item: bool, diff --git a/clippy_lints/src/methods/zst_offset.rs b/clippy_lints/src/methods/zst_offset.rs index 866cf616679c..e9f268da6915 100644 --- a/clippy_lints/src/methods/zst_offset.rs +++ b/clippy_lints/src/methods/zst_offset.rs @@ -9,7 +9,7 @@ use super::ZST_OFFSET; pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) { if_chain! { if let ty::RawPtr(ty::TypeAndMut { ty, .. }) = cx.typeck_results().expr_ty(recv).kind(); - if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty)); + if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(*ty)); if layout.is_zst(); then { span_lint(cx, ZST_OFFSET, expr.span, "offset calculation on zero-sized value"); diff --git a/clippy_lints/src/modulo_arithmetic.rs b/clippy_lints/src/modulo_arithmetic.rs index d182a7d52497..195b2e5c2ee0 100644 --- a/clippy_lints/src/modulo_arithmetic.rs +++ b/clippy_lints/src/modulo_arithmetic.rs @@ -4,7 +4,7 @@ use clippy_utils::sext; use if_chain::if_chain; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; +use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::fmt::Display; @@ -77,7 +77,7 @@ fn floating_point_operand_info>(f: &T) -> Op } } -fn might_have_negative_value(t: &ty::TyS<'_>) -> bool { +fn might_have_negative_value(t: Ty<'_>) -> bool { t.is_signed() || t.is_floating_point() } diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 1bdd805f6585..b4e29101b396 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -113,7 +113,7 @@ fn check_sig<'tcx>(cx: &LateContext<'tcx>, item_hir_id: hir::HirId, decl: &hir:: let fn_def_id = cx.tcx.hir().local_def_id(item_hir_id); let fn_sig = cx.tcx.fn_sig(fn_def_id); for (hir_ty, ty) in iter::zip(decl.inputs, fn_sig.inputs().skip_binder()) { - check_ty(cx, hir_ty.span, ty); + check_ty(cx, hir_ty.span, *ty); } check_ty(cx, decl.output.span(), cx.tcx.erase_late_bound_regions(fn_sig.output())); } diff --git a/clippy_lints/src/mut_mutex_lock.rs b/clippy_lints/src/mut_mutex_lock.rs index 7871be41d629..b7f981faa2d4 100644 --- a/clippy_lints/src/mut_mutex_lock.rs +++ b/clippy_lints/src/mut_mutex_lock.rs @@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for MutMutexLock { if path.ident.name == sym!(lock); let ty = cx.typeck_results().expr_ty(self_arg); if let ty::Ref(_, inner_ty, Mutability::Mut) = ty.kind(); - if is_type_diagnostic_item(cx, inner_ty, sym::Mutex); + if is_type_diagnostic_item(cx, *inner_ty, sym::Mutex); then { span_lint_and_sugg( cx, diff --git a/clippy_lints/src/non_send_fields_in_send_ty.rs b/clippy_lints/src/non_send_fields_in_send_ty.rs index ab1559c85d8b..f4de999a9281 100644 --- a/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -205,7 +205,7 @@ fn ty_allowed_with_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t ty::Tuple(_) => ty .tuple_fields() .all(|ty| ty_allowed_with_raw_pointer_heuristic(cx, ty, send_trait)), - ty::Array(ty, _) | ty::Slice(ty) => ty_allowed_with_raw_pointer_heuristic(cx, ty, send_trait), + ty::Array(ty, _) | ty::Slice(ty) => ty_allowed_with_raw_pointer_heuristic(cx, *ty, send_trait), ty::Adt(_, substs) => { if contains_pointer_like(cx, ty) { // descends only if ADT contains any raw pointers diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 3092ab8392a7..d59249d7f13d 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -167,8 +167,8 @@ impl<'tcx> PassByRefOrValue { if_chain! { if !output_lts.contains(input_lt); - if is_copy(cx, ty); - if let Some(size) = cx.layout_of(ty).ok().map(|l| l.size.bytes()); + if is_copy(cx, *ty); + if let Some(size) = cx.layout_of(*ty).ok().map(|l| l.size.bytes()); if size <= self.ref_min_size; if let hir::TyKind::Rptr(_, MutTy { ty: decl_ty, .. }) = input.kind; then { diff --git a/clippy_lints/src/size_of_in_element_count.rs b/clippy_lints/src/size_of_in_element_count.rs index 971729e5c54b..f3515ea3c2dd 100644 --- a/clippy_lints/src/size_of_in_element_count.rs +++ b/clippy_lints/src/size_of_in_element_count.rs @@ -116,7 +116,7 @@ fn get_pointee_ty_and_count_expr<'tcx>( if let ty::RawPtr(TypeAndMut { ty: pointee_ty, .. }) = cx.typeck_results().expr_ty(ptr_self).kind(); then { - return Some((pointee_ty, count)); + return Some((*pointee_ty, count)); } }; None diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs index 5699f8e92cfc..f3653199b375 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs @@ -38,7 +38,7 @@ pub(super) fn check<'tcx>( let arg = if from_ptr_ty.ty == *to_ref_ty { arg } else { - arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_ref_ty))) + arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, *to_ref_ty))) }; diag.span_suggestion( diff --git a/clippy_lints/src/transmute/transmute_ref_to_ref.rs b/clippy_lints/src/transmute/transmute_ref_to_ref.rs index fdef8bac7f9b..7570bc2a7a8f 100644 --- a/clippy_lints/src/transmute/transmute_ref_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ref_to_ref.rs @@ -56,10 +56,10 @@ pub(super) fn check<'tcx>( "transmute from a reference to a reference", |diag| if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) { let ty_from_and_mut = ty::TypeAndMut { - ty: ty_from, + ty: *ty_from, mutbl: *from_mutbl }; - let ty_to_and_mut = ty::TypeAndMut { ty: ty_to, mutbl: *to_mutbl }; + let ty_to_and_mut = ty::TypeAndMut { ty: *ty_to, mutbl: *to_mutbl }; let sugg_paren = arg .as_ty(cx.tcx.mk_ptr(ty_from_and_mut)) .as_ty(cx.tcx.mk_ptr(ty_to_and_mut)); diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index 030d2c237848..9ed5952a109a 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -200,27 +200,27 @@ fn reduce_refs<'tcx>( loop { return match (from_ty.kind(), to_ty.kind()) { ( - ty::Ref(_, from_sub_ty, _) | ty::RawPtr(TypeAndMut { ty: from_sub_ty, .. }), - ty::Ref(_, to_sub_ty, _) | ty::RawPtr(TypeAndMut { ty: to_sub_ty, .. }), + &ty::Ref(_, from_sub_ty, _) | &ty::RawPtr(TypeAndMut { ty: from_sub_ty, .. }), + &ty::Ref(_, to_sub_ty, _) | &ty::RawPtr(TypeAndMut { ty: to_sub_ty, .. }), ) => { from_ty = from_sub_ty; to_ty = to_sub_ty; continue; }, - (ty::Ref(_, unsized_ty, _) | ty::RawPtr(TypeAndMut { ty: unsized_ty, .. }), _) + (&ty::Ref(_, unsized_ty, _) | &ty::RawPtr(TypeAndMut { ty: unsized_ty, .. }), _) if !unsized_ty.is_sized(cx.tcx.at(span), cx.param_env) => { ReducedTys::FromFatPtr { unsized_ty } }, - (_, ty::Ref(_, unsized_ty, _) | ty::RawPtr(TypeAndMut { ty: unsized_ty, .. })) + (_, &ty::Ref(_, unsized_ty, _) | &ty::RawPtr(TypeAndMut { ty: unsized_ty, .. })) if !unsized_ty.is_sized(cx.tcx.at(span), cx.param_env) => { ReducedTys::ToFatPtr { unsized_ty } }, - (ty::Ref(_, from_ty, _) | ty::RawPtr(TypeAndMut { ty: from_ty, .. }), _) => { + (&ty::Ref(_, from_ty, _) | &ty::RawPtr(TypeAndMut { ty: from_ty, .. }), _) => { ReducedTys::FromPtr { from_ty, to_ty } }, - (_, ty::Ref(_, to_ty, _) | ty::RawPtr(TypeAndMut { ty: to_ty, .. })) => { + (_, &ty::Ref(_, to_ty, _) | &ty::RawPtr(TypeAndMut { ty: to_ty, .. })) => { ReducedTys::ToPtr { from_ty, to_ty } }, _ => ReducedTys::Other { from_ty, to_ty }, @@ -247,7 +247,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> }, ty::Tuple(args) => { let mut iter = args.iter().map(GenericArg::expect_ty); - let Some(sized_ty) = iter.find(|ty| !is_zero_sized_ty(cx, ty)) else { + let Some(sized_ty) = iter.find(|ty| !is_zero_sized_ty(cx, *ty)) else { return ReducedTy::OrderedFields(ty); }; if iter.all(|ty| is_zero_sized_ty(cx, ty)) { @@ -265,7 +265,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> .fields .iter() .map(|f| cx.tcx.type_of(f.did).subst(cx.tcx, substs)); - let Some(sized_ty) = iter.find(|ty| !is_zero_sized_ty(cx, ty)) else { + let Some(sized_ty) = iter.find(|ty| !is_zero_sized_ty(cx, *ty)) else { return ReducedTy::OrderedFields(ty); }; if iter.all(|ty| is_zero_sized_ty(cx, ty)) { diff --git a/clippy_lints/src/transmute/useless_transmute.rs b/clippy_lints/src/transmute/useless_transmute.rs index 998f97eb5d8c..3cc3d40a143d 100644 --- a/clippy_lints/src/transmute/useless_transmute.rs +++ b/clippy_lints/src/transmute/useless_transmute.rs @@ -34,7 +34,7 @@ pub(super) fn check<'tcx>( |diag| { if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) { let rty_and_mut = ty::TypeAndMut { - ty: rty, + ty: *rty, mutbl: *rty_mutbl, }; diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index eee1229e1ef0..7c39a08a336b 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -84,7 +84,8 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve let partial_ord_preds = get_trait_predicates_for_trait_id(cx, generics, cx.tcx.lang_items().partial_ord_trait()); // Trying to call erase_late_bound_regions on fn_sig.inputs() gives the following error - // The trait `rustc::ty::TypeFoldable<'_>` is not implemented for `&[&rustc::ty::TyS<'_>]` + // The trait `rustc::ty::TypeFoldable<'_>` is not implemented for + // `&[rustc_middle::ty::Ty<'_>]` let inputs_output = cx.tcx.erase_late_bound_regions(fn_sig.inputs_and_output()); inputs_output .iter() diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index f775cdd3bc28..4bb401273c40 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1911,10 +1911,10 @@ pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option is_recursively_primitive_type(element_type), + rustc_ty::Slice(element_type) => is_recursively_primitive_type(*element_type), rustc_ty::Ref(_, inner_ty, _) if matches!(inner_ty.kind(), &rustc_ty::Slice(_)) => { if let rustc_ty::Slice(element_type) = inner_ty.kind() { - is_recursively_primitive_type(element_type) + is_recursively_primitive_type(*element_type) } else { unreachable!() } diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 7512039a480b..c039fec955db 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -149,7 +149,7 @@ fn check_rvalue<'tcx>( Rvalue::Cast(CastKind::Misc, operand, cast_ty) => { use rustc_middle::ty::cast::CastTy; let cast_in = CastTy::from_ty(operand.ty(body, tcx)).expect("bad input type for cast"); - let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast"); + let cast_out = CastTy::from_ty(*cast_ty).expect("bad output type for cast"); match (cast_in, cast_out) { (CastTy::Ptr(_) | CastTy::FnPtr, CastTy::Int(_)) => { Err((span, "casting pointers to ints is unstable in const fn".into())) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 958e6d1ec461..b44899e6bd58 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -103,7 +103,7 @@ pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option< ]; let ty_to_check = match probably_ref_ty.kind() { - ty::Ref(_, ty_to_check, _) => ty_to_check, + ty::Ref(_, ty_to_check, _) => *ty_to_check, _ => probably_ref_ty, }; @@ -209,7 +209,7 @@ fn is_normalizable_helper<'tcx>( ty: Ty<'tcx>, cache: &mut FxHashMap, bool>, ) -> bool { - if let Some(&cached_result) = cache.get(ty) { + if let Some(&cached_result) = cache.get(&ty) { return cached_result; } // prevent recursive loops, false-negative is better than endless loop leading to stack overflow @@ -252,7 +252,7 @@ pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool { match ty.kind() { ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => true, ty::Ref(_, inner, _) if *inner.kind() == ty::Str => true, - ty::Array(inner_type, _) | ty::Slice(inner_type) => is_recursively_primitive_type(inner_type), + ty::Array(inner_type, _) | ty::Slice(inner_type) => is_recursively_primitive_type(*inner_type), ty::Tuple(inner_types) => inner_types.types().all(is_recursively_primitive_type), _ => false, } @@ -318,7 +318,7 @@ pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool { pub fn peel_mid_ty_refs(ty: Ty<'_>) -> (Ty<'_>, usize) { fn peel(ty: Ty<'_>, count: usize) -> (Ty<'_>, usize) { if let ty::Ref(_, ty, _) = ty.kind() { - peel(ty, count + 1) + peel(*ty, count + 1) } else { (ty, count) } @@ -331,8 +331,8 @@ pub fn peel_mid_ty_refs(ty: Ty<'_>) -> (Ty<'_>, usize) { pub fn peel_mid_ty_refs_is_mutable(ty: Ty<'_>) -> (Ty<'_>, usize, Mutability) { fn f(ty: Ty<'_>, count: usize, mutability: Mutability) -> (Ty<'_>, usize, Mutability) { match ty.kind() { - ty::Ref(_, ty, Mutability::Mut) => f(ty, count + 1, mutability), - ty::Ref(_, ty, Mutability::Not) => f(ty, count + 1, Mutability::Not), + ty::Ref(_, ty, Mutability::Mut) => f(*ty, count + 1, mutability), + ty::Ref(_, ty, Mutability::Not) => f(*ty, count + 1, Mutability::Not), _ => (ty, count, mutability), } } @@ -360,7 +360,7 @@ pub fn walk_ptrs_hir_ty<'tcx>(ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> { pub fn walk_ptrs_ty_depth(ty: Ty<'_>) -> (Ty<'_>, usize) { fn inner(ty: Ty<'_>, depth: usize) -> (Ty<'_>, usize) { match ty.kind() { - ty::Ref(_, ty, _) => inner(ty, depth + 1), + ty::Ref(_, ty, _) => inner(*ty, depth + 1), _ => (ty, depth), } } @@ -394,7 +394,7 @@ pub fn same_type_and_consts<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool { /// Checks if a given type looks safe to be uninitialized. pub fn is_uninit_value_valid_for_ty(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { match ty.kind() { - ty::Array(component, _) => is_uninit_value_valid_for_ty(cx, component), + ty::Array(component, _) => is_uninit_value_valid_for_ty(cx, *component), ty::Tuple(types) => types.types().all(|ty| is_uninit_value_valid_for_ty(cx, ty)), ty::Adt(adt, _) => cx.tcx.lang_items().maybe_uninit() == Some(adt.did), _ => false, diff --git a/doc/common_tools_writing_lints.md b/doc/common_tools_writing_lints.md index 36c454745ba0..828bf4cbef94 100644 --- a/doc/common_tools_writing_lints.md +++ b/doc/common_tools_writing_lints.md @@ -26,7 +26,7 @@ Sometimes you may want to retrieve the type `Ty` of an expression `Expr`, for ex - does it implement a trait? This operation is performed using the [`expr_ty()`][expr_ty] method from the [`TypeckResults`][TypeckResults] struct, -that gives you access to the underlying structure [`TyS`][TyS]. +that gives you access to the underlying structure [`Ty`][Ty]. Example of use: ```rust @@ -259,7 +259,7 @@ expression with a different context from `a`. assert_eq!(x_is_some_span.ctxt(), x_unwrap_span.ctxt()); ``` -[TyS]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyS.html +[Ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html [TyKind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html [TypeckResults]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html [expr_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html#method.expr_ty From 5b6b58ac7af032d84ffcee1100e0aacfb1d801b4 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 28 Jan 2022 11:25:15 +1100 Subject: [PATCH 0417/1222] Overhaul `RegionKind` and `Region`. Specifically, change `Region` from this: ``` pub type Region<'tcx> = &'tcx RegionKind; ``` to this: ``` pub struct Region<'tcx>(&'tcx Interned); ``` This now matches `Ty` and `Predicate` more closely. Things to note - Regions have always been interned, but we haven't been using pointer-based `Eq` and `Hash`. This is now happening. - I chose to impl `Deref` for `Region` because it makes pattern matching a lot nicer, and `Region` can be viewed as just a smart wrapper for `RegionKind`. - Various methods are moved from `RegionKind` to `Region`. - There is a lot of tedious sigil changes. - A couple of types like `HighlightBuilder`, `RegionHighlightMode` now have a `'tcx` lifetime because they hold a `Ty<'tcx>`, so they can call `mk_region`. - A couple of test outputs change slightly, I'm not sure why, but the new outputs are a little better. --- clippy_lints/src/methods/expect_fun_call.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index d813edab687e..c3cb02329a11 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -73,7 +73,7 @@ pub(super) fn check<'tcx>( match cx.qpath_res(p, fun.hir_id) { hir::def::Res::Def(hir::def::DefKind::Fn | hir::def::DefKind::AssocFn, def_id) => matches!( cx.tcx.fn_sig(def_id).output().skip_binder().kind(), - ty::Ref(ty::ReStatic, ..) + ty::Ref(re, ..) if re.is_static(), ), _ => false, } @@ -87,7 +87,7 @@ pub(super) fn check<'tcx>( .map_or(false, |method_id| { matches!( cx.tcx.fn_sig(method_id).output().skip_binder().kind(), - ty::Ref(ty::ReStatic, ..) + ty::Ref(re, ..) if re.is_static() ) }) }, From 22e4d9038a5238d0d1785657e02c860562c714d3 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 2 Feb 2022 14:24:45 +1100 Subject: [PATCH 0418/1222] Overhaul `Const`. Specifically, rename the `Const` struct as `ConstS` and re-introduce `Const` as this: ``` pub struct Const<'tcx>(&'tcx Interned); ``` This now matches `Ty` and `Predicate` more closely, including using pointer-based `eq` and `hash`. Notable changes: - `mk_const` now takes a `ConstS`. - `Const` was copy, despite being 48 bytes. Now `ConstS` is not, so need a we need separate arena for it, because we can't use the `Dropless` one any more. - Many `&'tcx Const<'tcx>`/`&Const<'tcx>` to `Const<'tcx>` changes - Many `ct.ty` to `ct.ty()` and `ct.val` to `ct.val()` changes. - Lots of tedious sigil fiddling. --- clippy_lints/src/large_const_arrays.rs | 2 +- clippy_lints/src/large_stack_arrays.rs | 2 +- clippy_lints/src/non_copy_const.rs | 6 +++--- clippy_utils/src/consts.rs | 14 +++++++------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index 663977a57a07..27db63881361 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays { if let ItemKind::Const(hir_ty, _) = &item.kind; let ty = hir_ty_to_ty(cx.tcx, hir_ty); if let ty::Array(element_type, cst) = ty.kind(); - if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val; + if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val(); if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx); if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()); if self.maximum_allowed_size < element_count * element_size; diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index b9e246290ff7..57b0d709acd4 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays { if_chain! { if let ExprKind::Repeat(_, _) = expr.kind; if let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind(); - if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val; + if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val(); if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx); if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()); if self.maximum_allowed_size < element_count * element_size; diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 21ac6548b017..3ba99403f06d 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -136,14 +136,14 @@ fn is_value_unfrozen_raw<'tcx>( result: Result, ErrorHandled>, ty: Ty<'tcx>, ) -> bool { - fn inner<'tcx>(cx: &LateContext<'tcx>, val: &'tcx Const<'tcx>) -> bool { - match val.ty.kind() { + fn inner<'tcx>(cx: &LateContext<'tcx>, val: Const<'tcx>) -> bool { + match val.ty().kind() { // the fact that we have to dig into every structs to search enums // leads us to the point checking `UnsafeCell` directly is the only option. ty::Adt(ty_def, ..) if Some(ty_def.did) == cx.tcx.lang_items().unsafe_cell_type() => true, ty::Array(..) | ty::Adt(..) | ty::Tuple(..) => { let val = cx.tcx.destructure_const(cx.param_env.and(val)); - val.fields.iter().any(|field| inner(cx, field)) + val.fields.iter().any(|field| inner(cx, *field)) }, _ => false, } diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 3f604d5166bf..d40583c47dd7 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -567,11 +567,11 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { } } -pub fn miri_to_const(result: &ty::Const<'_>) -> Option { +pub fn miri_to_const(result: ty::Const<'_>) -> Option { use rustc_middle::mir::interpret::ConstValue; - match result.val { + match result.val() { ty::ConstKind::Value(ConstValue::Scalar(Scalar::Int(int))) => { - match result.ty.kind() { + match result.ty().kind() { ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)), ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.assert_bits(int.size()))), ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits( @@ -590,7 +590,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option { _ => None, } }, - ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => match result.ty.kind() { + ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => match result.ty().kind() { ty::Ref(_, tam, _) => match tam.kind() { ty::Str => String::from_utf8( data.inspect_with_uninit_and_ptr_outside_interpreter(start..end) @@ -602,9 +602,9 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option { }, _ => None, }, - ty::ConstKind::Value(ConstValue::ByRef { alloc, offset: _ }) => match result.ty.kind() { + ty::ConstKind::Value(ConstValue::ByRef { alloc, offset: _ }) => match result.ty().kind() { ty::Array(sub_type, len) => match sub_type.kind() { - ty::Float(FloatTy::F32) => match miri_to_const(len) { + ty::Float(FloatTy::F32) => match miri_to_const(*len) { Some(Constant::Int(len)) => alloc .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * len as usize)) .to_owned() @@ -618,7 +618,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option { .map(Constant::Vec), _ => None, }, - ty::Float(FloatTy::F64) => match miri_to_const(len) { + ty::Float(FloatTy::F64) => match miri_to_const(*len) { Some(Constant::Int(len)) => alloc .inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * len as usize)) .to_owned() From bd45e3ec006015cfac884ceedcd244689ab1bd6b Mon Sep 17 00:00:00 2001 From: flip1995 Date: Tue, 15 Feb 2022 10:54:38 +0100 Subject: [PATCH 0419/1222] Move transmute_undefined_repr back to nursery There's still open discussion if this lint is ready to be enabled by default. We want to give us more time to figure this out and prevent this lint from getting to stable as an enabled-by-default lint. --- clippy_lints/src/lib.register_all.rs | 1 - clippy_lints/src/lib.register_correctness.rs | 1 - clippy_lints/src/lib.register_nursery.rs | 1 + clippy_lints/src/transmute/mod.rs | 2 +- 4 files changed, 2 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/lib.register_all.rs b/clippy_lints/src/lib.register_all.rs index d93e34e76b49..4721b7f2b472 100644 --- a/clippy_lints/src/lib.register_all.rs +++ b/clippy_lints/src/lib.register_all.rs @@ -277,7 +277,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![ LintId::of(transmute::TRANSMUTE_INT_TO_FLOAT), LintId::of(transmute::TRANSMUTE_NUM_TO_BYTES), LintId::of(transmute::TRANSMUTE_PTR_TO_REF), - LintId::of(transmute::TRANSMUTE_UNDEFINED_REPR), LintId::of(transmute::UNSOUND_COLLECTION_TRANSMUTE), LintId::of(transmute::WRONG_TRANSMUTE), LintId::of(transmuting_null::TRANSMUTING_NULL), diff --git a/clippy_lints/src/lib.register_correctness.rs b/clippy_lints/src/lib.register_correctness.rs index d013daa8e082..4217fd3a3ea7 100644 --- a/clippy_lints/src/lib.register_correctness.rs +++ b/clippy_lints/src/lib.register_correctness.rs @@ -58,7 +58,6 @@ store.register_group(true, "clippy::correctness", Some("clippy_correctness"), ve LintId::of(size_of_in_element_count::SIZE_OF_IN_ELEMENT_COUNT), LintId::of(swap::ALMOST_SWAPPED), LintId::of(to_string_in_display::TO_STRING_IN_DISPLAY), - LintId::of(transmute::TRANSMUTE_UNDEFINED_REPR), LintId::of(transmute::UNSOUND_COLLECTION_TRANSMUTE), LintId::of(transmute::WRONG_TRANSMUTE), LintId::of(transmuting_null::TRANSMUTING_NULL), diff --git a/clippy_lints/src/lib.register_nursery.rs b/clippy_lints/src/lib.register_nursery.rs index a73537901002..8d4dde42bbec 100644 --- a/clippy_lints/src/lib.register_nursery.rs +++ b/clippy_lints/src/lib.register_nursery.rs @@ -26,6 +26,7 @@ store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![ LintId::of(strings::STRING_LIT_AS_BYTES), LintId::of(suspicious_operation_groupings::SUSPICIOUS_OPERATION_GROUPINGS), LintId::of(trailing_empty_array::TRAILING_EMPTY_ARRAY), + LintId::of(transmute::TRANSMUTE_UNDEFINED_REPR), LintId::of(transmute::USELESS_TRANSMUTE), LintId::of(use_self::USE_SELF), ]) diff --git a/clippy_lints/src/transmute/mod.rs b/clippy_lints/src/transmute/mod.rs index 4c320deecc28..5e94ab6d0482 100644 --- a/clippy_lints/src/transmute/mod.rs +++ b/clippy_lints/src/transmute/mod.rs @@ -376,7 +376,7 @@ declare_clippy_lint! { /// ``` #[clippy::version = "1.60.0"] pub TRANSMUTE_UNDEFINED_REPR, - correctness, + nursery, "transmute to or from a type with an undefined representation" } From 30d4a37483f4afc31c48aae3cf6afa3bfc44b389 Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Wed, 16 Feb 2022 00:38:04 +0000 Subject: [PATCH 0420/1222] Correctly mark the span of captured arguments in `format_args!()` It should only include the identifier, or misspelling suggestions will be wrong. --- clippy_lints/src/write.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index b0044695ea8a..1fa6301ebd73 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -453,7 +453,7 @@ impl SimpleFormatArgs { } } }, - ArgumentNamed(n) => { + ArgumentNamed(n, _) => { if let Some(x) = self.named.iter_mut().find(|x| x.0 == n) { match x.1.as_slice() { // A non-empty format string has been seen already. From 17a19bce3ee5c99be4483316b5e972e84d402f6d Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Wed, 16 Feb 2022 23:14:39 -0500 Subject: [PATCH 0421/1222] Don't lint `needless_borrow` in method receiver positions --- clippy_lints/src/dereference.rs | 2 +- tests/ui/needless_borrow.fixed | 6 +++--- tests/ui/needless_borrow.rs | 6 +++--- tests/ui/needless_borrow.stderr | 20 +------------------- 4 files changed, 8 insertions(+), 26 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 6d0851d804c2..fe3911983421 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -528,7 +528,7 @@ fn is_auto_reborrow_position(parent: Option>) -> bool { fn is_auto_borrow_position(parent: Option>, child_id: HirId) -> bool { if let Some(Node::Expr(parent)) = parent { match parent.kind { - ExprKind::MethodCall(_, [self_arg, ..], _) => self_arg.hir_id == child_id, + // ExprKind::MethodCall(_, [self_arg, ..], _) => self_arg.hir_id == child_id, ExprKind::Field(..) => true, ExprKind::Call(f, _) => f.hir_id == child_id, _ => false, diff --git a/tests/ui/needless_borrow.fixed b/tests/ui/needless_borrow.fixed index b856f1375d30..efeb5cf5b2b2 100644 --- a/tests/ui/needless_borrow.fixed +++ b/tests/ui/needless_borrow.fixed @@ -64,9 +64,9 @@ fn main() { *x = 5; let s = String::new(); - let _ = s.len(); - let _ = s.capacity(); - let _ = s.capacity(); + // let _ = (&s).len(); + // let _ = (&s).capacity(); + // let _ = (&&s).capacity(); let x = (1, 2); let _ = x.0; diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs index 0bfe222a3dc1..3e416a0eb84a 100644 --- a/tests/ui/needless_borrow.rs +++ b/tests/ui/needless_borrow.rs @@ -64,9 +64,9 @@ fn main() { *x = 5; let s = String::new(); - let _ = (&s).len(); - let _ = (&s).capacity(); - let _ = (&&s).capacity(); + // let _ = (&s).len(); + // let _ = (&s).capacity(); + // let _ = (&&s).capacity(); let x = (1, 2); let _ = (&x).0; diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr index b90e8448db0a..05591ce4117b 100644 --- a/tests/ui/needless_borrow.stderr +++ b/tests/ui/needless_borrow.stderr @@ -84,24 +84,6 @@ error: this expression creates a reference which is immediately dereferenced by LL | let y: &mut i32 = &mut &mut x; | ^^^^^^^^^^^ help: change this to: `x` -error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:67:13 - | -LL | let _ = (&s).len(); - | ^^^^ help: change this to: `s` - -error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:68:13 - | -LL | let _ = (&s).capacity(); - | ^^^^ help: change this to: `s` - -error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:69:13 - | -LL | let _ = (&&s).capacity(); - | ^^^^^ help: change this to: `s` - error: this expression borrows a value the compiler would automatically borrow --> $DIR/needless_borrow.rs:72:13 | @@ -114,5 +96,5 @@ error: this expression borrows a value the compiler would automatically borrow LL | let _ = unsafe { (&*x).0 }; | ^^^^^ help: change this to: `(*x)` -error: aborting due to 19 previous errors +error: aborting due to 16 previous errors From b1b564c2054b1e3b2fa3217f07145060cbb465a0 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 17 Feb 2022 16:00:04 +0000 Subject: [PATCH 0422/1222] Revert "Auto merge of #91403 - cjgillot:inherit-async, r=oli-obk" This reverts commit 3cfa4def7c87d571bd46d92fed608edf8fad236e, reversing changes made to 5d8767cb229b097fedb1dd4bd9420d463c37774f. --- tests/ui/manual_async_fn.fixed | 1 - tests/ui/manual_async_fn.rs | 1 - tests/ui/manual_async_fn.stderr | 2 +- tests/ui/needless_lifetimes.stderr | 8 +------- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/tests/ui/manual_async_fn.fixed b/tests/ui/manual_async_fn.fixed index e9ca66f125d8..136cc96be70c 100644 --- a/tests/ui/manual_async_fn.fixed +++ b/tests/ui/manual_async_fn.fixed @@ -80,7 +80,6 @@ fn elided_not_bound(_: &i32) -> impl Future { async { 42 } } -#[allow(clippy::needless_lifetimes)] async fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> i32 { 42 } // should be ignored diff --git a/tests/ui/manual_async_fn.rs b/tests/ui/manual_async_fn.rs index c3fa846485ba..ddc453ffdb75 100644 --- a/tests/ui/manual_async_fn.rs +++ b/tests/ui/manual_async_fn.rs @@ -98,7 +98,6 @@ fn elided_not_bound(_: &i32) -> impl Future { async { 42 } } -#[allow(clippy::needless_lifetimes)] fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { async { 42 } } diff --git a/tests/ui/manual_async_fn.stderr b/tests/ui/manual_async_fn.stderr index b83abfccd4e1..7435f46074c8 100644 --- a/tests/ui/manual_async_fn.stderr +++ b/tests/ui/manual_async_fn.stderr @@ -140,7 +140,7 @@ LL | fn elided(_: &i32) -> impl Future + '_ { 42 } | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:102:1 + --> $DIR/manual_async_fn.rs:101:1 | LL | fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/needless_lifetimes.stderr b/tests/ui/needless_lifetimes.stderr index 8df50d79ca57..ffa152427a97 100644 --- a/tests/ui/needless_lifetimes.stderr +++ b/tests/ui/needless_lifetimes.stderr @@ -18,12 +18,6 @@ error: explicit lifetimes given in parameter types where they could be elided (o LL | fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:37:1 - | -LL | async fn func<'a>(args: &[&'a str]) -> Option<&'a str> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) --> $DIR/needless_lifetimes.rs:56:1 | @@ -198,5 +192,5 @@ error: explicit lifetimes given in parameter types where they could be elided (o LL | fn lifetime_elsewhere_provided<'a>(self: Box, here: &'a ()) -> &'a () { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 33 previous errors +error: aborting due to 32 previous errors From 411cbe27112ac899a06c45385594f15721949fa5 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 7 Feb 2022 16:06:55 +0100 Subject: [PATCH 0423/1222] update clippy --- clippy_lints/src/functions/must_use.rs | 2 +- .../src/matches/redundant_pattern_match.rs | 4 ++-- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/non_send_fields_in_send_ty.rs | 4 ++-- .../src/transmute/transmute_undefined_repr.rs | 7 +++---- clippy_utils/src/ty.rs | 18 +++++++++--------- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 3e3718b9445f..ea9b68d1a40e 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -193,7 +193,7 @@ fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, tys: &m || KNOWN_WRAPPER_TYS.iter().any(|path| match_def_path(cx, adt.did, path)) && substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)) }, - ty::Tuple(substs) => substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)), + ty::Tuple(substs) => substs.iter().any(|ty| is_mutable_ty(cx, ty, span, tys)), ty::Array(ty, _) | ty::Slice(ty) => is_mutable_ty(cx, ty, span, tys), ty::RawPtr(ty::TypeAndMut { ty, mutbl }) | ty::Ref(_, ty, mutbl) => { mutbl == hir::Mutability::Mut || is_mutable_ty(cx, ty, span, tys) diff --git a/clippy_lints/src/matches/redundant_pattern_match.rs b/clippy_lints/src/matches/redundant_pattern_match.rs index e195fddefaba..677b8cdf2ba0 100644 --- a/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/clippy_lints/src/matches/redundant_pattern_match.rs @@ -58,8 +58,8 @@ fn type_needs_ordered_drop_inner<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, see // This type doesn't implement drop, so no side effects here. // Check if any component type has any. match ty.kind() { - ty::Tuple(_) => ty.tuple_fields().any(|ty| type_needs_ordered_drop_inner(cx, ty, seen)), - ty::Array(ty, _) => type_needs_ordered_drop_inner(cx, *ty, seen), + ty::Tuple(fields) => fields.iter().any(|ty| type_needs_ordered_drop_inner(cx, ty, seen)), + &ty::Array(ty, _) => type_needs_ordered_drop_inner(cx, ty, seen), ty::Adt(adt, subs) => adt .all_fields() .map(|f| f.ty(cx.tcx, subs)) diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index b4e29101b396..ce9ca15430e4 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -142,7 +142,7 @@ fn is_interior_mutable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Sp size.try_eval_usize(cx.tcx, cx.param_env).map_or(true, |u| u != 0) && is_interior_mutable_type(cx, inner_ty, span) }, - Tuple(..) => ty.tuple_fields().any(|ty| is_interior_mutable_type(cx, ty, span)), + Tuple(fields) => fields.iter().any(|ty| is_interior_mutable_type(cx, ty, span)), Adt(def, substs) => { // Special case for collections in `std` who's impl of `Hash` or `Ord` delegates to // that of their type parameters. Note: we don't include `HashSet` and `HashMap` diff --git a/clippy_lints/src/non_send_fields_in_send_ty.rs b/clippy_lints/src/non_send_fields_in_send_ty.rs index f4de999a9281..5168ca67b6ab 100644 --- a/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -202,8 +202,8 @@ fn ty_allowed_with_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t // The type is known to be `!Send` and `!Copy` match ty.kind() { - ty::Tuple(_) => ty - .tuple_fields() + ty::Tuple(fields) => fields + .iter() .all(|ty| ty_allowed_with_raw_pointer_heuristic(cx, ty, send_trait)), ty::Array(ty, _) | ty::Slice(ty) => ty_allowed_with_raw_pointer_heuristic(cx, *ty, send_trait), ty::Adt(_, substs) => { diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index 9ed5952a109a..a57c819cb225 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -2,7 +2,7 @@ use super::TRANSMUTE_UNDEFINED_REPR; use clippy_utils::diagnostics::span_lint_and_then; use rustc_hir::Expr; use rustc_lint::LateContext; -use rustc_middle::ty::subst::{GenericArg, Subst}; +use rustc_middle::ty::subst::Subst; use rustc_middle::ty::{self, Ty, TypeAndMut}; use rustc_span::Span; @@ -246,11 +246,10 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> continue; }, ty::Tuple(args) => { - let mut iter = args.iter().map(GenericArg::expect_ty); - let Some(sized_ty) = iter.find(|ty| !is_zero_sized_ty(cx, *ty)) else { + let Some(sized_ty) = args.iter().find(|&ty| !is_zero_sized_ty(cx, ty)) else { return ReducedTy::OrderedFields(ty); }; - if iter.all(|ty| is_zero_sized_ty(cx, ty)) { + if args.iter().all(|ty| is_zero_sized_ty(cx, ty)) { ty = sized_ty; continue; } diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index b44899e6bd58..0d39226d9703 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -169,7 +169,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { // because we don't want to lint functions returning empty arrays is_must_use_ty(cx, *ty) }, - ty::Tuple(substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), + ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { if let ty::PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() { @@ -249,11 +249,11 @@ pub fn is_non_aggregate_primitive_type(ty: Ty<'_>) -> bool { /// Returns `true` if the given type is a primitive (a `bool` or `char`, any integer or /// floating-point number type, a `str`, or an array, slice, or tuple of those types). pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool { - match ty.kind() { + match *ty.kind() { ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => true, ty::Ref(_, inner, _) if *inner.kind() == ty::Str => true, - ty::Array(inner_type, _) | ty::Slice(inner_type) => is_recursively_primitive_type(*inner_type), - ty::Tuple(inner_types) => inner_types.types().all(is_recursively_primitive_type), + ty::Array(inner_type, _) | ty::Slice(inner_type) => is_recursively_primitive_type(inner_type), + ty::Tuple(inner_types) => inner_types.iter().all(is_recursively_primitive_type), _ => false, } } @@ -393,9 +393,9 @@ pub fn same_type_and_consts<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool { /// Checks if a given type looks safe to be uninitialized. pub fn is_uninit_value_valid_for_ty(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { - match ty.kind() { - ty::Array(component, _) => is_uninit_value_valid_for_ty(cx, *component), - ty::Tuple(types) => types.types().all(|ty| is_uninit_value_valid_for_ty(cx, ty)), + match *ty.kind() { + ty::Array(component, _) => is_uninit_value_valid_for_ty(cx, component), + ty::Tuple(types) => types.iter().all(|ty| is_uninit_value_valid_for_ty(cx, ty)), ty::Adt(adt, _) => cx.tcx.lang_items().maybe_uninit() == Some(adt.did), _ => false, } @@ -426,8 +426,8 @@ impl<'tcx> ExprFnSig<'tcx> { pub fn input(self, i: usize) -> Binder<'tcx, Ty<'tcx>> { match self { Self::Sig(sig) => sig.input(i), - Self::Closure(sig) => sig.input(0).map_bound(|ty| ty.tuple_element_ty(i).unwrap()), - Self::Trait(inputs, _) => inputs.map_bound(|ty| ty.tuple_element_ty(i).unwrap()), + Self::Closure(sig) => sig.input(0).map_bound(|ty| ty.tuple_fields()[i]), + Self::Trait(inputs, _) => inputs.map_bound(|ty| ty.tuple_fields()[i]), } } From 2ef4ea0d2083c8f04d061a4776c55039c4e4fed8 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 23 Jan 2022 20:41:46 +0000 Subject: [PATCH 0424/1222] Replace `&mut DiagnosticBuilder`, in signatures, with `&mut Diagnostic`. --- clippy_lints/src/copies.rs | 4 ++-- clippy_lints/src/implicit_hasher.rs | 4 ++-- clippy_lints/src/inline_fn_without_body.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- clippy_lints/src/new_without_default.rs | 2 +- clippy_utils/src/diagnostics.rs | 12 ++++++------ clippy_utils/src/sugg.rs | 6 +++--- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 8b79f1600aeb..a20aa12c9ff4 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -6,7 +6,7 @@ use clippy_utils::{ }; use if_chain::if_chain; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diagnostic}; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{Block, Expr, ExprKind, HirId}; use rustc_lint::{LateContext, LateLintPass, LintContext}; @@ -489,7 +489,7 @@ fn emit_branches_sharing_code_lint( add_expr_note = !cx.typeck_results().expr_ty(if_expr).is_unit(); } - let add_optional_msgs = |diag: &mut DiagnosticBuilder<'_>| { + let add_optional_msgs = |diag: &mut Diagnostic| { if add_expr_note { diag.note("The end suggestion probably needs some adjustments to use the expression result correctly"); } diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 5e4cde553b52..d5430a8c9175 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use std::collections::BTreeMap; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diagnostic; use rustc_hir as hir; use rustc_hir::intravisit::{walk_body, walk_expr, walk_inf, walk_ty, Visitor}; use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind}; @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { fn suggestion<'tcx>( cx: &LateContext<'tcx>, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diagnostic, generics_span: Span, generics_suggestion_span: Span, target: &ImplicitHasherType<'_>, diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index df69d3dcc516..dd7177e0131c 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -1,7 +1,7 @@ //! checks for `#[inline]` on trait methods without bodies use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::sugg::DiagnosticBuilderExt; +use clippy_utils::sugg::DiagnosticExt; use rustc_ast::ast::Attribute; use rustc_errors::Applicability; use rustc_hir::{TraitFn, TraitItem, TraitItemKind}; diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index ebd4fb0bf51c..91d7274f5f5a 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -6,7 +6,7 @@ use clippy_utils::{get_trait_def_id, is_self, paths}; use if_chain::if_chain; use rustc_ast::ast::Attribute; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diagnostic}; use rustc_hir::intravisit::FnKind; use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, Impl, ItemKind, Node, PatKind, QPath, TyKind}; use rustc_hir::{HirIdMap, HirIdSet}; @@ -196,7 +196,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { } // Dereference suggestion - let sugg = |diag: &mut DiagnosticBuilder<'_>| { + let sugg = |diag: &mut Diagnostic| { if let ty::Adt(def, ..) = ty.kind() { if let Some(span) = cx.tcx.hir().span_if_local(def.did) { if can_type_implement_copy(cx.tcx, cx.param_env, ty).is_ok() { diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index f86af7a7bb6e..4cb79648ae36 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::return_ty; use clippy_utils::source::snippet; -use clippy_utils::sugg::DiagnosticBuilderExt; +use clippy_utils::sugg::DiagnosticExt; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs index ca222c3d6699..a927788e6a44 100644 --- a/clippy_utils/src/diagnostics.rs +++ b/clippy_utils/src/diagnostics.rs @@ -8,13 +8,13 @@ //! Thank you! //! ~The `INTERNAL_METADATA_COLLECTOR` lint -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diagnostic}; use rustc_hir::HirId; use rustc_lint::{LateContext, Lint, LintContext}; use rustc_span::source_map::{MultiSpan, Span}; use std::env; -fn docs_link(diag: &mut DiagnosticBuilder<'_>, lint: &'static Lint) { +fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) { if env::var("CLIPPY_DISABLE_DOCS_LINKS").is_err() { if let Some(lint) = lint.name_lower().strip_prefix("clippy::") { diag.help(&format!( @@ -145,7 +145,7 @@ pub fn span_lint_and_then(cx: &C, lint: &'static Lint, sp: S, msg: &str where C: LintContext, S: Into, - F: FnOnce(&mut DiagnosticBuilder<'_>), + F: FnOnce(&mut Diagnostic), { cx.struct_span_lint(lint, sp, |diag| { let mut diag = diag.build(msg); @@ -169,7 +169,7 @@ pub fn span_lint_hir_and_then( hir_id: HirId, sp: impl Into, msg: &str, - f: impl FnOnce(&mut DiagnosticBuilder<'_>), + f: impl FnOnce(&mut Diagnostic), ) { cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| { let mut diag = diag.build(msg); @@ -219,7 +219,7 @@ pub fn span_lint_and_sugg<'a, T: LintContext>( /// appear once per /// replacement. In human-readable format though, it only appears once before /// the whole suggestion. -pub fn multispan_sugg(diag: &mut DiagnosticBuilder<'_>, help_msg: &str, sugg: I) +pub fn multispan_sugg(diag: &mut Diagnostic, help_msg: &str, sugg: I) where I: IntoIterator, { @@ -232,7 +232,7 @@ where /// multiple spans. This is tracked in issue [rustfix#141](https://github.com/rust-lang/rustfix/issues/141). /// Suggestions with multiple spans will be silently ignored. pub fn multispan_sugg_with_applicability( - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diagnostic, help_msg: &str, applicability: Applicability, sugg: I, diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index fa63ddff253c..63c442e70085 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -673,8 +673,8 @@ fn indentation(cx: &T, span: Span) -> Option { }) } -/// Convenience extension trait for `DiagnosticBuilder`. -pub trait DiagnosticBuilderExt { +/// Convenience extension trait for `Diagnostic`. +pub trait DiagnosticExt { /// Suggests to add an attribute to an item. /// /// Correctly handles indentation of the attribute and item. @@ -721,7 +721,7 @@ pub trait DiagnosticBuilderExt { fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str, applicability: Applicability); } -impl DiagnosticBuilderExt for rustc_errors::DiagnosticBuilder<'_> { +impl DiagnosticExt for rustc_errors::Diagnostic { fn suggest_item_with_attr( &mut self, cx: &T, From 5443b3f4e4a2ab9ad89ad329ef07ec7967f7ee67 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 26 Jan 2022 03:39:14 +0000 Subject: [PATCH 0425/1222] rustc_errors: take `self` by value in `DiagnosticBuilder::cancel`. --- clippy_lints/src/doc.rs | 6 ++---- clippy_lints/src/write.rs | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index a00361e6062a..16173580fd46 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -628,9 +628,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) { Ok(p) => p, Err(errs) => { - for mut err in errs { - err.cancel(); - } + drop(errs); return false; }, }; @@ -668,7 +666,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { _ => {}, }, Ok(None) => break, - Err(mut e) => { + Err(e) => { e.cancel(); return false; }, diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 1fa6301ebd73..a328ddda5ae7 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -534,7 +534,7 @@ impl Write { match parser .parse_expr() .map(rustc_ast::ptr::P::into_inner) - .map_err(|mut e| e.cancel()) + .map_err(|e| e.cancel()) { // write!(e, ...) Ok(p) if parser.eat(&token::Comma) => Some(p), @@ -563,7 +563,7 @@ impl Write { } let comma_span = parser.prev_token.span; - let token_expr = if let Ok(expr) = parser.parse_expr().map_err(|mut err| err.cancel()) { + let token_expr = if let Ok(expr) = parser.parse_expr().map_err(|err| err.cancel()) { expr } else { return (Some(fmtstr), None); From fe312fa18dc132616a32f8ebe7fba75b5b66e80a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 6 Feb 2022 13:03:28 -0800 Subject: [PATCH 0426/1222] better ObligationCause for normalization errors in can_type_implement_copy --- clippy_lints/src/needless_pass_by_value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index ebd4fb0bf51c..d27e1383d012 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -199,7 +199,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { let sugg = |diag: &mut DiagnosticBuilder<'_>| { if let ty::Adt(def, ..) = ty.kind() { if let Some(span) = cx.tcx.hir().span_if_local(def.did) { - if can_type_implement_copy(cx.tcx, cx.param_env, ty).is_ok() { + if can_type_implement_copy(cx.tcx, cx.param_env, ty, traits::ObligationCause::dummy_with_span(span)).is_ok() { diag.span_help(span, "consider marking this type as `Copy`"); } } From 6cbe0043e27b796d858055dd7ee0293ebf5ff616 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 11 Dec 2021 19:52:23 +0800 Subject: [PATCH 0427/1222] resolve: Fix incorrect results of `opt_def_kind` query for some built-in macros Previously it always returned `MacroKind::Bang` while some of those macros are actually attributes and derives --- clippy_lints/src/utils/inspector.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 869114831370..dc48ea3f4f99 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -373,7 +373,7 @@ fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) { let item_ty = cx.tcx.type_of(did); println!("function of type {:#?}", item_ty); }, - hir::ItemKind::Macro(ref macro_def) => { + hir::ItemKind::Macro(ref macro_def, _) => { if macro_def.macro_rules { println!("macro introduced by `macro_rules!`"); } else { From 5225476b6c7957ca153750bf6b9d773c13584362 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 5 Feb 2022 10:07:13 +0800 Subject: [PATCH 0428/1222] Update clippy tests --- tests/ui/macro_use_imports.fixed | 2 +- tests/ui/macro_use_imports.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/macro_use_imports.fixed b/tests/ui/macro_use_imports.fixed index 306ea50258da..a83c8ba0b642 100644 --- a/tests/ui/macro_use_imports.fixed +++ b/tests/ui/macro_use_imports.fixed @@ -15,7 +15,7 @@ extern crate macro_use_helper as mac; extern crate proc_macro_derive as mini_mac; mod a { - use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro}; + use mac::{pub_macro, function_macro, ty_macro, inner_mod_macro, pub_in_private_macro}; use mac; use mini_mac::ClippyMiniMacroTest; use mini_mac; diff --git a/tests/ui/macro_use_imports.stderr b/tests/ui/macro_use_imports.stderr index f8c86c8d9179..9028a636e7f7 100644 --- a/tests/ui/macro_use_imports.stderr +++ b/tests/ui/macro_use_imports.stderr @@ -2,7 +2,7 @@ error: `macro_use` attributes are no longer needed in the Rust 2018 edition --> $DIR/macro_use_imports.rs:18:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro};` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{pub_macro, function_macro, ty_macro, inner_mod_macro, pub_in_private_macro};` | = note: `-D clippy::macro-use-imports` implied by `-D warnings` From 6d24c748140a0b064361f7d517755632e676e1f4 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Wed, 23 Feb 2022 08:06:22 -0500 Subject: [PATCH 0429/1222] Switch bootstrap cfgs --- clippy_lints/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 5c45012ef068..85256ff0e995 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -18,7 +18,7 @@ // warn on rustc internal lints #![warn(rustc::internal)] // Disable this rustc lint for now, as it was also done in rustc -#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))] +#![allow(rustc::potential_query_instability)] // FIXME: switch to something more ergonomic here, once available. // (Currently there is no way to opt into sysroot crates without `extern crate`.) From 87a1936f72452751bd9a3e215754663e48c2e577 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Tue, 15 Feb 2022 10:54:38 +0100 Subject: [PATCH 0430/1222] Move transmute_undefined_repr back to nursery There's still open discussion if this lint is ready to be enabled by default. We want to give us more time to figure this out and prevent this lint from getting to stable as an enabled-by-default lint. --- clippy_lints/src/lib.register_all.rs | 1 - clippy_lints/src/lib.register_correctness.rs | 1 - clippy_lints/src/lib.register_nursery.rs | 1 + clippy_lints/src/transmute/mod.rs | 2 +- 4 files changed, 2 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/lib.register_all.rs b/clippy_lints/src/lib.register_all.rs index f6d467941e3e..abfb46035376 100644 --- a/clippy_lints/src/lib.register_all.rs +++ b/clippy_lints/src/lib.register_all.rs @@ -281,7 +281,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![ LintId::of(transmute::TRANSMUTE_INT_TO_FLOAT), LintId::of(transmute::TRANSMUTE_NUM_TO_BYTES), LintId::of(transmute::TRANSMUTE_PTR_TO_REF), - LintId::of(transmute::TRANSMUTE_UNDEFINED_REPR), LintId::of(transmute::UNSOUND_COLLECTION_TRANSMUTE), LintId::of(transmute::WRONG_TRANSMUTE), LintId::of(transmuting_null::TRANSMUTING_NULL), diff --git a/clippy_lints/src/lib.register_correctness.rs b/clippy_lints/src/lib.register_correctness.rs index 35b1e644a8a7..d7bf91eb6921 100644 --- a/clippy_lints/src/lib.register_correctness.rs +++ b/clippy_lints/src/lib.register_correctness.rs @@ -58,7 +58,6 @@ store.register_group(true, "clippy::correctness", Some("clippy_correctness"), ve LintId::of(serde_api::SERDE_API_MISUSE), LintId::of(size_of_in_element_count::SIZE_OF_IN_ELEMENT_COUNT), LintId::of(swap::ALMOST_SWAPPED), - LintId::of(transmute::TRANSMUTE_UNDEFINED_REPR), LintId::of(transmute::UNSOUND_COLLECTION_TRANSMUTE), LintId::of(transmute::WRONG_TRANSMUTE), LintId::of(transmuting_null::TRANSMUTING_NULL), diff --git a/clippy_lints/src/lib.register_nursery.rs b/clippy_lints/src/lib.register_nursery.rs index a73537901002..8d4dde42bbec 100644 --- a/clippy_lints/src/lib.register_nursery.rs +++ b/clippy_lints/src/lib.register_nursery.rs @@ -26,6 +26,7 @@ store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![ LintId::of(strings::STRING_LIT_AS_BYTES), LintId::of(suspicious_operation_groupings::SUSPICIOUS_OPERATION_GROUPINGS), LintId::of(trailing_empty_array::TRAILING_EMPTY_ARRAY), + LintId::of(transmute::TRANSMUTE_UNDEFINED_REPR), LintId::of(transmute::USELESS_TRANSMUTE), LintId::of(use_self::USE_SELF), ]) diff --git a/clippy_lints/src/transmute/mod.rs b/clippy_lints/src/transmute/mod.rs index 22a8c53a5852..1da3b7659048 100644 --- a/clippy_lints/src/transmute/mod.rs +++ b/clippy_lints/src/transmute/mod.rs @@ -377,7 +377,7 @@ declare_clippy_lint! { /// ``` #[clippy::version = "1.60.0"] pub TRANSMUTE_UNDEFINED_REPR, - correctness, + nursery, "transmute to or from a type with an undefined representation" } From 4bea0b3a682204bb2e4ffcf132051ca38030be24 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 2 Mar 2022 19:20:27 -0500 Subject: [PATCH 0431/1222] bless clippy --- tests/ui/modulo_one.stderr | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ui/modulo_one.stderr b/tests/ui/modulo_one.stderr index 34f762bbb923..03f460897fce 100644 --- a/tests/ui/modulo_one.stderr +++ b/tests/ui/modulo_one.stderr @@ -1,18 +1,18 @@ -error: this arithmetic operation will overflow +error: this operation will panic at runtime --> $DIR/modulo_one.rs:11:5 | LL | i32::MIN % (-1); // also caught by rustc | ^^^^^^^^^^^^^^^ attempt to compute the remainder of `i32::MIN % -1_i32`, which would overflow | - = note: `#[deny(arithmetic_overflow)]` on by default + = note: `#[deny(unconditional_panic)]` on by default -error: this arithmetic operation will overflow +error: this operation will panic at runtime --> $DIR/modulo_one.rs:21:5 | LL | INT_MIN % NEG_ONE; // also caught by rustc | ^^^^^^^^^^^^^^^^^ attempt to compute the remainder of `i64::MIN % -1_i64`, which would overflow -error: this arithmetic operation will overflow +error: this operation will panic at runtime --> $DIR/modulo_one.rs:22:5 | LL | INT_MIN % STATIC_NEG_ONE; // ONLY caught by rustc From 50f61259e3a922fca7df23344bbc36c66727e3b6 Mon Sep 17 00:00:00 2001 From: pierwill Date: Fri, 4 Mar 2022 11:54:28 -0600 Subject: [PATCH 0432/1222] Update `itertools` Update to 0.10.1 --- Cargo.toml | 2 +- clippy_dev/Cargo.toml | 2 +- clippy_lints/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5cc5530f874d..d4ca9480bec6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ rustc-workspace-hack = "1.0" clippy_utils = { path = "clippy_utils" } derive-new = "0.5" if_chain = "1.0" -itertools = "0.10" +itertools = "0.10.1" quote = "1.0" serde = { version = "1.0", features = ["derive"] } syn = { version = "1.0", features = ["full"] } diff --git a/clippy_dev/Cargo.toml b/clippy_dev/Cargo.toml index d350d9a00182..d133e8cddabc 100644 --- a/clippy_dev/Cargo.toml +++ b/clippy_dev/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" bytecount = "0.6" clap = "2.33" indoc = "1.0" -itertools = "0.10" +itertools = "0.10.1" opener = "0.5" regex = "1.5" shell-escape = "0.1" diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 40d7dd702628..66e61660d313 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -12,7 +12,7 @@ edition = "2021" cargo_metadata = "0.14" clippy_utils = { path = "../clippy_utils" } if_chain = "1.0" -itertools = "0.10" +itertools = "0.10.1" pulldown-cmark = { version = "0.9", default-features = false } quine-mc_cluskey = "0.2" regex-syntax = "0.6" From 2ce089e7d07aa3848aea8301eef5c3342a15ba37 Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Fri, 21 Jan 2022 00:15:39 +0000 Subject: [PATCH 0433/1222] Do not point at whole file missing `fn main` Only point at the end of the crate. We could try making it point at the beginning of the crate, but that is confused with `DUMMY_SP`, causing the output to be *worse*. This change will make it so that VSCode will *not* underline the whole file when `main` is missing, so other errors will be visible. --- tests/ui/crashes/ice-6250.stderr | 12 +++--------- tests/ui/crashes/ice-6251.stderr | 8 +++----- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/tests/ui/crashes/ice-6250.stderr b/tests/ui/crashes/ice-6250.stderr index 7ffbd7a64b34..878897c410cf 100644 --- a/tests/ui/crashes/ice-6250.stderr +++ b/tests/ui/crashes/ice-6250.stderr @@ -1,14 +1,8 @@ error[E0601]: `main` function not found in crate `ice_6250` - --> $DIR/ice-6250.rs:4:1 + --> $DIR/ice-6250.rs:16:2 | -LL | / pub struct Cache { -LL | | data: Vec, -LL | | } -LL | | -... | -LL | | } -LL | | } - | |_^ consider adding a `main` function to `$DIR/ice-6250.rs` +LL | } + | ^ consider adding a `main` function to `$DIR/ice-6250.rs` error[E0308]: mismatched types --> $DIR/ice-6250.rs:12:14 diff --git a/tests/ui/crashes/ice-6251.stderr b/tests/ui/crashes/ice-6251.stderr index 14c71e884b6e..77a3c2ba4ad0 100644 --- a/tests/ui/crashes/ice-6251.stderr +++ b/tests/ui/crashes/ice-6251.stderr @@ -1,10 +1,8 @@ error[E0601]: `main` function not found in crate `ice_6251` - --> $DIR/ice-6251.rs:4:1 + --> $DIR/ice-6251.rs:6:2 | -LL | / fn bug() -> impl Iterator { -LL | | std::iter::empty() -LL | | } - | |_^ consider adding a `main` function to `$DIR/ice-6251.rs` +LL | } + | ^ consider adding a `main` function to `$DIR/ice-6251.rs` error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/ice-6251.rs:4:45 From fc585b6ab2bc2b255a1a17dc4a55c5252b98057e Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Tue, 19 Oct 2021 18:45:48 -0400 Subject: [PATCH 0434/1222] Change syntax for TyAlias where clauses --- clippy_utils/src/ast_utils.rs | 48 +++++------------------------------ 1 file changed, 6 insertions(+), 42 deletions(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 3f4043ad052a..3a47845ec82c 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -279,20 +279,8 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { (ForeignMod(l), ForeignMod(r)) => { both(&l.abi, &r.abi, eq_str_lit) && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_foreign_item_kind)) }, - ( - TyAlias(box ast::TyAlias { - defaultness: ld, - generics: lg, - bounds: lb, - ty: lt, - }), - TyAlias(box ast::TyAlias { - defaultness: rd, - generics: rg, - bounds: rb, - ty: rt, - }), - ) => { + (TyAlias(box ast::TyAlias { defaultness: ld, generics: lg, bounds: lb, ty: lt, .. }), + TyAlias(box ast::TyAlias { defaultness: rd, generics: rg, bounds: rb, ty: rt, .. })) => { eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound) @@ -382,20 +370,8 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { ) => { eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r)) }, - ( - TyAlias(box ast::TyAlias { - defaultness: ld, - generics: lg, - bounds: lb, - ty: lt, - }), - TyAlias(box ast::TyAlias { - defaultness: rd, - generics: rg, - bounds: rb, - ty: rt, - }), - ) => { + (TyAlias(box ast::TyAlias { defaultness: ld, generics: lg, bounds: lb, ty: lt, .. }), + TyAlias(box ast::TyAlias { defaultness: rd, generics: rg, bounds: rb, ty: rt, .. })) => { eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound) @@ -426,20 +402,8 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { ) => { eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r)) }, - ( - TyAlias(box ast::TyAlias { - defaultness: ld, - generics: lg, - bounds: lb, - ty: lt, - }), - TyAlias(box ast::TyAlias { - defaultness: rd, - generics: rg, - bounds: rb, - ty: rt, - }), - ) => { + (TyAlias(box ast::TyAlias { defaultness: ld, generics: lg, bounds: lb, ty: lt, .. }), + TyAlias(box ast::TyAlias { defaultness: rd, generics: rg, bounds: rb, ty: rt, .. })) => { eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound) From ce3af640c9f4d63b1ed47fbea144135b6270a79d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 2 Mar 2022 07:15:04 +1100 Subject: [PATCH 0435/1222] Introduce `ConstAllocation`. Currently some `Allocation`s are interned, some are not, and it's very hard to tell at a use point which is which. This commit introduces `ConstAllocation` for the known-interned ones, which makes the division much clearer. `ConstAllocation::inner()` is used to get the underlying `Allocation`. In some places it's natural to use an `Allocation`, in some it's natural to use a `ConstAllocation`, and in some places there's no clear choice. I've tried to make things look as nice as possible, while generally favouring `ConstAllocation`, which is the type that embodies more information. This does require quite a few calls to `inner()`. The commit also tweaks how `PartialOrd` works for `Interned`. The previous code was too clever by half, building on `T: Ord` to make the code shorter. That caused problems with deriving `PartialOrd` and `Ord` for `ConstAllocation`, so I changed it to build on `T: PartialOrd`, which is slightly more verbose but much more standard and avoided the problems. --- clippy_utils/src/consts.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index d40583c47dd7..42b9e692d3ff 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -593,7 +593,7 @@ pub fn miri_to_const(result: ty::Const<'_>) -> Option { ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => match result.ty().kind() { ty::Ref(_, tam, _) => match tam.kind() { ty::Str => String::from_utf8( - data.inspect_with_uninit_and_ptr_outside_interpreter(start..end) + data.inner().inspect_with_uninit_and_ptr_outside_interpreter(start..end) .to_owned(), ) .ok() @@ -605,7 +605,7 @@ pub fn miri_to_const(result: ty::Const<'_>) -> Option { ty::ConstKind::Value(ConstValue::ByRef { alloc, offset: _ }) => match result.ty().kind() { ty::Array(sub_type, len) => match sub_type.kind() { ty::Float(FloatTy::F32) => match miri_to_const(*len) { - Some(Constant::Int(len)) => alloc + Some(Constant::Int(len)) => alloc.inner() .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * len as usize)) .to_owned() .chunks(4) @@ -619,7 +619,7 @@ pub fn miri_to_const(result: ty::Const<'_>) -> Option { _ => None, }, ty::Float(FloatTy::F64) => match miri_to_const(*len) { - Some(Constant::Int(len)) => alloc + Some(Constant::Int(len)) => alloc.inner() .inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * len as usize)) .to_owned() .chunks(8) From 463facf4a8bfe3efef92ec9f470fe502f9b93560 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 4 Mar 2022 13:46:56 +1100 Subject: [PATCH 0436/1222] Clarify `Layout` interning. `Layout` is another type that is sometimes interned, sometimes not, and we always use references to refer to it so we can't take any advantage of the uniqueness properties for hashing or equality checks. This commit renames `Layout` as `LayoutS`, and then introduces a new `Layout` that is a newtype around an `Interned`. It also interns more layouts than before. Previously layouts within layouts (via the `variants` field) were never interned, but now they are. Hence the lifetime on the new `Layout` type. Unlike other interned types, these ones are in `rustc_target` instead of `rustc_middle`. This reflects the existing structure of the code, which does layout-specific stuff in `rustc_target` while `TyAndLayout` is generic over the `Ty`, allowing the type-specific stuff to occur in `rustc_middle`. The commit also adds a `HashStable` impl for `Interned`, which was needed. It hashes the contents, unlike the `Hash` impl which hashes the pointer. --- clippy_lints/src/transmute/transmute_undefined_repr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index 05eadab3e6cc..81076776ed3d 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -326,7 +326,7 @@ fn is_zero_sized_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { if let Ok(ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, ty); if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty)); then { - layout.layout.size.bytes() == 0 + layout.layout.size().bytes() == 0 } else { false } From bceee327745f31944fe256d19d3d875e609d369a Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Tue, 8 Feb 2022 16:33:15 -0800 Subject: [PATCH 0437/1222] Stabilize const_fn_fn_ptr_basics and const_fn_trait_bound --- clippy_utils/src/qualify_min_const_fn.rs | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index c039fec955db..891531951c1a 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -32,32 +32,12 @@ pub fn is_min_const_fn<'a, 'tcx>(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: | ty::PredicateKind::Projection(_) | ty::PredicateKind::ConstEvaluatable(..) | ty::PredicateKind::ConstEquate(..) + | ty::PredicateKind::Trait(..) | ty::PredicateKind::TypeWellFormedFromEnv(..) => continue, ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate), ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate), ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate), ty::PredicateKind::Coerce(_) => panic!("coerce predicate on function: {:#?}", predicate), - ty::PredicateKind::Trait(pred) => { - if Some(pred.def_id()) == tcx.lang_items().sized_trait() { - continue; - } - match pred.self_ty().kind() { - ty::Param(ref p) => { - let generics = tcx.generics_of(current); - let def = generics.type_param(p, tcx); - let span = tcx.def_span(def.def_id); - return Err(( - span, - "trait bounds other than `Sized` \ - on const fn parameters are unstable" - .into(), - )); - }, - // other kinds of bounds are either tautologies - // or cause errors in other passes - _ => continue, - } - }, } } match predicates.parent { From 584166483849950198ba68fcc170e1bdfaf3bd12 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Thu, 10 Feb 2022 19:23:43 -0800 Subject: [PATCH 0438/1222] Update and fix clippy tests --- clippy_lints/src/missing_const_for_fn.rs | 13 +++++++++++++ tests/ui/missing_const_for_fn/could_be_const.rs | 2 -- .../ui/missing_const_for_fn/could_be_const.stderr | 14 +++++++++++--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index bad9e0be82e6..ecc9acf4445d 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -3,6 +3,7 @@ use clippy_utils::qualify_min_const_fn::is_min_const_fn; use clippy_utils::ty::has_drop; use clippy_utils::{fn_has_unsatisfiable_preds, is_entrypoint_fn, meets_msrv, msrvs, trait_ref_of_method}; use rustc_hir as hir; +use rustc_hir::def_id::CRATE_DEF_ID; use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, Constness, FnDecl, GenericParamKind, HirId}; use rustc_lint::{LateContext, LateLintPass}; @@ -131,6 +132,18 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { FnKind::Closure => return, } + // Const fns are not allowed as methods in a trait. + { + let parent = cx.tcx.hir().get_parent_item(hir_id); + if parent != CRATE_DEF_ID { + if let hir::Node::Item(item) = cx.tcx.hir().get_by_def_id(parent) { + if let hir::ItemKind::Trait(..) = &item.kind { + return; + } + } + } + } + let mir = cx.tcx.optimized_mir(def_id); if let Err((span, err)) = is_min_const_fn(cx.tcx, mir, self.msrv.as_ref()) { diff --git a/tests/ui/missing_const_for_fn/could_be_const.rs b/tests/ui/missing_const_for_fn/could_be_const.rs index baa7eec05462..88f6935d224a 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.rs +++ b/tests/ui/missing_const_for_fn/could_be_const.rs @@ -49,8 +49,6 @@ fn sub(x: u32) -> usize { unsafe { transmute(&x) } } -// NOTE: This is currently not yet allowed to be const -// Once implemented, Clippy should be able to suggest this as const, too. fn generic_arr(t: [T; 1]) -> T { t[0] } diff --git a/tests/ui/missing_const_for_fn/could_be_const.stderr b/tests/ui/missing_const_for_fn/could_be_const.stderr index b89cc6451bb5..3eb52b682747 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.stderr +++ b/tests/ui/missing_const_for_fn/could_be_const.stderr @@ -58,7 +58,15 @@ LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:67:9 + --> $DIR/could_be_const.rs:52:1 + | +LL | / fn generic_arr(t: [T; 1]) -> T { +LL | | t[0] +LL | | } + | |_^ + +error: this could be a `const fn` + --> $DIR/could_be_const.rs:65:9 | LL | / pub fn b(self, a: &A) -> B { LL | | B @@ -66,12 +74,12 @@ LL | | } | |_________^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:77:5 + --> $DIR/could_be_const.rs:75:5 | LL | / fn const_fn_stabilized_before_msrv(byte: u8) { LL | | byte.is_ascii_digit(); LL | | } | |_____^ -error: aborting due to 9 previous errors +error: aborting due to 10 previous errors From f4377202489932f3f616dcd27eb0e3124575641f Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Fri, 25 Feb 2022 17:13:53 -0800 Subject: [PATCH 0439/1222] Update clippy to new ExprUseVisitor delegate --- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/loops/mut_range_bound.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_utils/src/sugg.rs | 2 +- clippy_utils/src/usage.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index af591dd71aa1..5974b67eb728 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -154,7 +154,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { } } - fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) { + fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind, _is_autoref: bool) { if cmt.place.projections.is_empty() { if let PlaceBase::Local(lid) = cmt.place.base { self.set.remove(&lid); diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index 9d8679d77c6d..4b3d7c1ef247 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -90,7 +90,7 @@ struct MutatePairDelegate<'a, 'tcx> { impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> { fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {} - fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: ty::BorrowKind) { + fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: ty::BorrowKind, _is_autoref: bool) { if bk == ty::BorrowKind::MutBorrow { if let PlaceBase::Local(id) = cmt.place.base { if Some(id) == self.hir_id_low && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index ebfd908a6fb7..ccd355f480a6 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -332,7 +332,7 @@ impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt { self.move_common(cmt); } - fn borrow(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {} + fn borrow(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind, _is_autoref: bool) {} fn mutate(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId) {} diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 63c442e70085..0e97d837ec59 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -886,7 +886,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> { fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {} #[allow(clippy::too_many_lines)] - fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) { + fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind, _is_autoref: bool) { if let PlaceBase::Local(id) = cmt.place.base { let map = self.cx.tcx.hir(); let span = map.span(cmt.hir_id); diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index 405e306359bc..ae4ca77e48c3 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -64,7 +64,7 @@ impl<'tcx> MutVarsDelegate { impl<'tcx> Delegate<'tcx> for MutVarsDelegate { fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {} - fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, bk: ty::BorrowKind) { + fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, bk: ty::BorrowKind, _is_autoref: bool) { if bk == ty::BorrowKind::MutBorrow { self.update(cmt); } From 5a92f15618b744fc7fce1f281b640b359021210f Mon Sep 17 00:00:00 2001 From: lcnr Date: Tue, 8 Mar 2022 15:39:52 +0100 Subject: [PATCH 0440/1222] add `#[rustc_pass_by_value]` to more types --- clippy_lints/src/redundant_clone.rs | 8 ++++---- clippy_utils/src/lib.rs | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index b3988973256c..1f134be2cbc8 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -543,10 +543,10 @@ impl<'a, 'tcx> PossibleBorrowerVisitor<'a, 'tcx> { continue; } - let borrowers = self.possible_borrower.reachable_from(&row); + let borrowers = self.possible_borrower.reachable_from(row); if !borrowers.is_empty() { let mut bs = HybridBitSet::new_empty(self.body.local_decls.len()); - for &c in borrowers { + for c in borrowers { if c != mir::Local::from_usize(0) { bs.insert(c); } @@ -663,10 +663,10 @@ impl<'a, 'tcx> PossibleOriginVisitor<'a, 'tcx> { continue; } - let borrowers = self.possible_origin.reachable_from(&row); + let borrowers = self.possible_origin.reachable_from(row); if !borrowers.is_empty() { let mut bs = HybridBitSet::new_empty(self.body.local_decls.len()); - for &c in borrowers { + for c in borrowers { if c != mir::Local::from_usize(0) { bs.insert(c); } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 397783e309e8..8c14f0dd761a 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -489,7 +489,8 @@ pub fn def_path_res(cx: &LateContext<'_>, path: &[&str]) -> Res { fn find_crate(tcx: TyCtxt<'_>, name: &str) -> Option { tcx.crates(()) .iter() - .find(|&&num| tcx.crate_name(num).as_str() == name) + .copied() + .find(|&num| tcx.crate_name(num).as_str() == name) .map(CrateNum::as_def_id) } From 34d3344937533ad79dc504a8c212811dde912500 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Thu, 10 Mar 2022 17:24:08 -0800 Subject: [PATCH 0441/1222] Remove is_autoref parameter --- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/loops/mut_range_bound.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_utils/src/sugg.rs | 2 +- clippy_utils/src/usage.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 5974b67eb728..af591dd71aa1 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -154,7 +154,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { } } - fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind, _is_autoref: bool) { + fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) { if cmt.place.projections.is_empty() { if let PlaceBase::Local(lid) = cmt.place.base { self.set.remove(&lid); diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index 4b3d7c1ef247..9d8679d77c6d 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -90,7 +90,7 @@ struct MutatePairDelegate<'a, 'tcx> { impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> { fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {} - fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: ty::BorrowKind, _is_autoref: bool) { + fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: ty::BorrowKind) { if bk == ty::BorrowKind::MutBorrow { if let PlaceBase::Local(id) = cmt.place.base { if Some(id) == self.hir_id_low && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index ccd355f480a6..ebfd908a6fb7 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -332,7 +332,7 @@ impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt { self.move_common(cmt); } - fn borrow(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind, _is_autoref: bool) {} + fn borrow(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {} fn mutate(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId) {} diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 0e97d837ec59..63c442e70085 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -886,7 +886,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> { fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {} #[allow(clippy::too_many_lines)] - fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind, _is_autoref: bool) { + fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) { if let PlaceBase::Local(id) = cmt.place.base { let map = self.cx.tcx.hir(); let span = map.span(cmt.hir_id); diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index ae4ca77e48c3..405e306359bc 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -64,7 +64,7 @@ impl<'tcx> MutVarsDelegate { impl<'tcx> Delegate<'tcx> for MutVarsDelegate { fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {} - fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, bk: ty::BorrowKind, _is_autoref: bool) { + fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, bk: ty::BorrowKind) { if bk == ty::BorrowKind::MutBorrow { self.update(cmt); } From 7ea90321ed1af2067c8990a80ca86fb47fd2ad2f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sat, 5 Mar 2022 07:28:41 +1100 Subject: [PATCH 0442/1222] Improve `AdtDef` interning. This commit makes `AdtDef` use `Interned`. Much the commit is tedious changes to introduce getter functions. The interesting changes are in `compiler/rustc_middle/src/ty/adt.rs`. --- clippy_lints/src/await_holding_invalid.rs | 4 +-- ...se_sensitive_file_extension_comparisons.rs | 3 ++- .../src/casts/cast_possible_truncation.rs | 8 +++--- clippy_lints/src/casts/utils.rs | 4 +-- clippy_lints/src/default.rs | 6 ++--- clippy_lints/src/default_numeric_fallback.rs | 2 +- clippy_lints/src/derivable_impls.rs | 2 +- clippy_lints/src/derive.rs | 6 ++--- clippy_lints/src/empty_enum.rs | 2 +- clippy_lints/src/enum_clike.rs | 2 +- clippy_lints/src/eq_op.rs | 2 +- clippy_lints/src/eta_reduction.rs | 2 +- clippy_lints/src/format.rs | 2 +- clippy_lints/src/functions/must_use.rs | 4 +-- .../src/inconsistent_struct_constructor.rs | 2 +- clippy_lints/src/large_enum_variant.rs | 4 +-- clippy_lints/src/len_zero.rs | 14 +++++----- clippy_lints/src/loops/manual_memcpy.rs | 2 +- clippy_lints/src/matches/match_wild_enum.rs | 6 ++--- .../src/methods/bind_instead_of_map.rs | 2 +- .../src/methods/cloned_instead_of_copied.rs | 2 +- clippy_lints/src/methods/filter_map.rs | 4 +-- clippy_lints/src/methods/implicit_clone.rs | 2 +- .../src/methods/inefficient_to_string.rs | 2 +- clippy_lints/src/methods/map_flatten.rs | 4 +-- clippy_lints/src/methods/str_splitn.rs | 2 +- .../src/methods/unnecessary_filter_map.rs | 2 +- clippy_lints/src/mut_key.rs | 6 ++--- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/needless_update.rs | 2 +- clippy_lints/src/new_without_default.rs | 4 +-- clippy_lints/src/non_copy_const.rs | 2 +- .../src/non_send_fields_in_send_ty.rs | 4 +-- clippy_lints/src/ptr.rs | 10 +++---- clippy_lints/src/self_named_constructors.rs | 2 +- .../src/transmute/transmute_undefined_repr.rs | 6 ++--- .../transmute/unsound_collection_transmute.rs | 4 +-- clippy_lints/src/try_err.rs | 10 +++---- clippy_lints/src/unnecessary_wraps.rs | 4 +-- clippy_utils/src/eager_or_lazy.rs | 2 +- clippy_utils/src/lib.rs | 4 +-- clippy_utils/src/ty.rs | 26 +++++++++---------- 42 files changed, 93 insertions(+), 92 deletions(-) diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index f0979840ff8d..4592ca727488 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -149,7 +149,7 @@ impl LateLintPass<'_> for AwaitHolding { fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorTypeCause<'_>], span: Span) { for ty_cause in ty_causes { if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind() { - if is_mutex_guard(cx, adt.did) { + if is_mutex_guard(cx, adt.did()) { span_lint_and_then( cx, AWAIT_HOLDING_LOCK, @@ -167,7 +167,7 @@ fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorType }, ); } - if is_refcell_ref(cx, adt.did) { + if is_refcell_ref(cx, adt.did()) { span_lint_and_then( cx, AWAIT_HOLDING_REFCELL_REF, diff --git a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs index 7637666d059e..df780747a0c7 100644 --- a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs +++ b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs @@ -1,6 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_ast::ast::LitKind; +use rustc_data_structures::intern::Interned; use rustc_hir::{Expr, ExprKind, PathSegment}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; @@ -55,7 +56,7 @@ fn check_case_sensitive_file_extension_comparison(ctx: &LateContext<'_>, expr: & ty::Str => { return Some(span); }, - ty::Adt(&ty::AdtDef { did, .. }, _) => { + ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did, .. }, _)), _) => { if ctx.tcx.is_diagnostic_item(sym::String, did) { return Some(span); } diff --git a/clippy_lints/src/casts/cast_possible_truncation.rs b/clippy_lints/src/casts/cast_possible_truncation.rs index 9b189ea1ef8f..421bd6f53f71 100644 --- a/clippy_lints/src/casts/cast_possible_truncation.rs +++ b/clippy_lints/src/casts/cast_possible_truncation.rs @@ -116,15 +116,15 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, && let Res::Def(DefKind::Ctor(..), id) = cx.qpath_res(p, cast_expr.hir_id) { let i = def.variant_index_with_ctor_id(id); - let variant = &def.variants[i]; - let nbits = utils::enum_value_nbits(get_discriminant_value(cx.tcx, def, i)); + let variant = def.variant(i); + let nbits = utils::enum_value_nbits(get_discriminant_value(cx.tcx, *def, i)); (nbits, Some(variant)) } else { - (utils::enum_ty_to_nbits(def, cx.tcx), None) + (utils::enum_ty_to_nbits(*def, cx.tcx), None) }; let to_nbits = utils::int_ty_to_nbits(cast_to, cx.tcx); - let cast_from_ptr_size = def.repr.int.map_or(true, |ty| { + let cast_from_ptr_size = def.repr().int.map_or(true, |ty| { matches!( ty, IntType::SignedInt(ast::IntTy::Isize) | IntType::UnsignedInt(ast::UintTy::Usize) diff --git a/clippy_lints/src/casts/utils.rs b/clippy_lints/src/casts/utils.rs index bbed766c47a8..5a4f20f09906 100644 --- a/clippy_lints/src/casts/utils.rs +++ b/clippy_lints/src/casts/utils.rs @@ -34,10 +34,10 @@ pub(super) fn enum_value_nbits(value: EnumValue) -> u64 { .into() } -pub(super) fn enum_ty_to_nbits(adt: &AdtDef, tcx: TyCtxt<'_>) -> u64 { +pub(super) fn enum_ty_to_nbits(adt: AdtDef<'_>, tcx: TyCtxt<'_>) -> u64 { let mut explicit = 0i128; let (start, end) = adt - .variants + .variants() .iter() .fold((0, i128::MIN), |(start, end), variant| match variant.discr { VariantDiscr::Relative(x) => match explicit.checked_add(i128::from(x)) { diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index 06e6bf986c2a..f7e4bc24321c 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { then { // TODO: Work out a way to put "whatever the imported way of referencing // this type in this file" rather than a fully-qualified type. - let replacement = format!("{}::default()", cx.tcx.def_path_str(def.did)); + let replacement = format!("{}::default()", cx.tcx.def_path_str(def.did())); span_lint_and_sugg( cx, DEFAULT_TRAIT_ACCESS, @@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { if let Some(adt) = binding_type.ty_adt_def(); if adt.is_struct(); let variant = adt.non_enum_variant(); - if adt.did.is_local() || !variant.is_field_list_non_exhaustive(); + if adt.did().is_local() || !variant.is_field_list_non_exhaustive(); let module_did = cx.tcx.parent_module(stmt.hir_id).to_def_id(); if variant .fields @@ -216,7 +216,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { if let ty::Adt(adt_def, substs) = binding_type.kind(); if !substs.is_empty(); then { - let adt_def_ty_name = cx.tcx.item_name(adt_def.did); + let adt_def_ty_name = cx.tcx.item_name(adt_def.did()); let generic_args = substs.iter().collect::>(); let tys_str = generic_args .iter() diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index b80d55dd192a..f3996e5b44d7 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -148,7 +148,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { if_chain! { if let Some(adt_def) = ty.ty_adt_def(); if adt_def.is_struct(); - if let Some(variant) = adt_def.variants.iter().next(); + if let Some(variant) = adt_def.variants().iter().next(); then { let fields_def = &variant.fields; diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index eccb18982f30..14098340745b 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -103,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { _ => false, }; if should_emit { - let path_string = cx.tcx.def_path_str(adt_def.did); + let path_string = cx.tcx.def_path_str(adt_def.did()); span_lint_and_help( cx, DERIVABLE_IMPLS, diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 7277e4080c5c..557e101494e3 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -315,7 +315,7 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &T let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(©_id).map_or(false, |impls| { impls .iter() - .any(|&id| matches!(cx.tcx.type_of(id).kind(), ty::Adt(adt, _) if ty_adt.did == adt.did)) + .any(|&id| matches!(cx.tcx.type_of(id).kind(), ty::Adt(adt, _) if ty_adt.did() == adt.did())) }); if !has_copy_impl { return; @@ -357,10 +357,10 @@ fn check_unsafe_derive_deserialize<'tcx>( if let Some(trait_def_id) = trait_ref.trait_def_id(); if match_def_path(cx, trait_def_id, &paths::SERDE_DESERIALIZE); if let ty::Adt(def, _) = ty.kind(); - if let Some(local_def_id) = def.did.as_local(); + 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_lint_allowed(cx, UNSAFE_DERIVE_DESERIALIZE, adt_hir_id); - if cx.tcx.inherent_impls(def.did) + if cx.tcx.inherent_impls(def.did()) .iter() .map(|imp_did| cx.tcx.hir().expect_item(imp_did.expect_local())) .any(|imp| has_unsafe(cx, imp)); diff --git a/clippy_lints/src/empty_enum.rs b/clippy_lints/src/empty_enum.rs index af9e65e63613..b5d6b3c7524b 100644 --- a/clippy_lints/src/empty_enum.rs +++ b/clippy_lints/src/empty_enum.rs @@ -52,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for EmptyEnum { if let ItemKind::Enum(..) = item.kind { let ty = cx.tcx.type_of(item.def_id); let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); - if adt.variants.is_empty() { + if adt.variants().is_empty() { span_lint_and_help( cx, EMPTY_ENUM, diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index 3b6661c817be..e2a5430da08c 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant { if let Some(Constant::Int(val)) = constant.and_then(miri_to_const) { if let ty::Adt(adt, _) = ty.kind() { if adt.is_enum() { - ty = adt.repr.discr_type().to_ty(cx.tcx); + ty = adt.repr().discr_type().to_ty(cx.tcx); } } match ty.kind() { diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 6490231fed8a..51c811b304ca 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -306,7 +306,7 @@ fn in_impl<'tcx>( fn are_equal<'tcx>(cx: &LateContext<'tcx>, middle_ty: Ty<'_>, hir_ty: &rustc_hir::Ty<'_>) -> bool { if_chain! { if let ty::Adt(adt_def, _) = middle_ty.kind(); - if let Some(local_did) = adt_def.did.as_local(); + if let Some(local_did) = adt_def.did().as_local(); let item = cx.tcx.hir().expect_item(local_did); let middle_ty_id = item.def_id.to_def_id(); if let TyKind::Path(QPath::Resolved(_, path)) = hir_ty.kind; diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index d23c0c225e19..845863bd209c 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -224,7 +224,7 @@ fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: DefId) -> String { ty::ImplContainer(def_id) => { let ty = cx.tcx.type_of(def_id); match ty.kind() { - ty::Adt(adt, _) => cx.tcx.def_path_str(adt.did), + ty::Adt(adt, _) => cx.tcx.def_path_str(adt.did()), _ => ty.to_string(), } }, diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 395c920c9974..64c41b565878 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat { if_chain! { if format_args.format_string_parts == [kw::Empty]; if match cx.typeck_results().expr_ty(value).peel_refs().kind() { - ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(sym::String, adt.did), + ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(sym::String, adt.did()), ty::Str => true, _ => false, }; diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index ea9b68d1a40e..0709580c8adf 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -189,8 +189,8 @@ fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, tys: &m // primitive types are never mutable ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false, ty::Adt(adt, substs) => { - tys.insert(adt.did) && !ty.is_freeze(cx.tcx.at(span), cx.param_env) - || KNOWN_WRAPPER_TYS.iter().any(|path| match_def_path(cx, adt.did, path)) + tys.insert(adt.did()) && !ty.is_freeze(cx.tcx.at(span), cx.param_env) + || KNOWN_WRAPPER_TYS.iter().any(|path| match_def_path(cx, adt.did(), path)) && substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)) }, ty::Tuple(substs) => substs.iter().any(|ty| is_mutable_ty(cx, ty, span, tys)), diff --git a/clippy_lints/src/inconsistent_struct_constructor.rs b/clippy_lints/src/inconsistent_struct_constructor.rs index 3d44a669d8f0..c8ec2f451370 100644 --- a/clippy_lints/src/inconsistent_struct_constructor.rs +++ b/clippy_lints/src/inconsistent_struct_constructor.rs @@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for InconsistentStructConstructor { let ty = cx.typeck_results().expr_ty(expr); if let Some(adt_def) = ty.ty_adt_def(); if adt_def.is_struct(); - if let Some(variant) = adt_def.variants.iter().next(); + if let Some(variant) = adt_def.variants().iter().next(); if fields.iter().all(|f| f.is_shorthand); then { let mut def_order_map = FxHashMap::default(); diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index d1dc6b775c56..0f3889a29361 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -81,11 +81,11 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant { if let ItemKind::Enum(ref def, _) = item.kind { let ty = cx.tcx.type_of(item.def_id); let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); - if adt.variants.len() <= 1 { + if adt.variants().len() <= 1 { return; } let mut variants_size: Vec = Vec::new(); - for (i, variant) in adt.variants.iter().enumerate() { + for (i, variant) in adt.variants().iter().enumerate() { let mut fields_size = Vec::new(); for (i, f) in variant.fields.iter().enumerate() { let ty = cx.tcx.type_of(f.did); diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 35d10d53112e..dabbb8375f0a 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -248,13 +248,13 @@ enum LenOutput<'tcx> { fn parse_len_output<'tcx>(cx: &LateContext<'_>, sig: FnSig<'tcx>) -> Option> { match *sig.output().kind() { ty::Int(_) | ty::Uint(_) => Some(LenOutput::Integral), - ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Option, adt.did) => { - subs.type_at(0).is_integral().then(|| LenOutput::Option(adt.did)) + ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Option, adt.did()) => { + subs.type_at(0).is_integral().then(|| LenOutput::Option(adt.did())) }, - ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Result, adt.did) => subs + ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Result, adt.did()) => subs .type_at(0) .is_integral() - .then(|| LenOutput::Result(adt.did, subs.type_at(1))), + .then(|| LenOutput::Result(adt.did(), subs.type_at(1))), _ => None, } } @@ -263,8 +263,8 @@ impl LenOutput<'_> { fn matches_is_empty_output(self, ty: Ty<'_>) -> bool { match (self, ty.kind()) { (_, &ty::Bool) => true, - (Self::Option(id), &ty::Adt(adt, subs)) if id == adt.did => subs.type_at(0).is_bool(), - (Self::Result(id, err_ty), &ty::Adt(adt, subs)) if id == adt.did => { + (Self::Option(id), &ty::Adt(adt, subs)) if id == adt.did() => subs.type_at(0).is_bool(), + (Self::Result(id, err_ty), &ty::Adt(adt, subs)) if id == adt.did() => { subs.type_at(0).is_bool() && subs.type_at(1) == err_ty }, _ => false, @@ -488,7 +488,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { .any(|item| is_is_empty(cx, item)) }), ty::Projection(ref proj) => has_is_empty_impl(cx, proj.item_def_id), - ty::Adt(id, _) => has_is_empty_impl(cx, id.did), + ty::Adt(id, _) => has_is_empty_impl(cx, id.did()), ty::Array(..) | ty::Slice(..) | ty::Str => true, _ => false, } diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index f6ef87264c0a..b31015d195b5 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -334,7 +334,7 @@ struct Start<'hir> { fn get_slice_like_element_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option> { match ty.kind() { - ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Vec, adt.did) => Some(subs.type_at(0)), + ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Vec, adt.did()) => Some(subs.type_at(0)), ty::Ref(_, subty, _) => get_slice_like_element_ty(cx, *subty), ty::Slice(ty) | ty::Array(ty, _) => Some(*ty), _ => None, diff --git a/clippy_lints/src/matches/match_wild_enum.rs b/clippy_lints/src/matches/match_wild_enum.rs index 3515286d5b4a..93bf0dc62e07 100644 --- a/clippy_lints/src/matches/match_wild_enum.rs +++ b/clippy_lints/src/matches/match_wild_enum.rs @@ -45,8 +45,8 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { // Accumulate the variants which should be put in place of the wildcard because they're not // already covered. - let has_hidden = adt_def.variants.iter().any(|x| is_hidden(cx, x)); - let mut missing_variants: Vec<_> = adt_def.variants.iter().filter(|x| !is_hidden(cx, x)).collect(); + let has_hidden = adt_def.variants().iter().any(|x| is_hidden(cx, x)); + let mut missing_variants: Vec<_> = adt_def.variants().iter().filter(|x| !is_hidden(cx, x)).collect(); let mut path_prefix = CommonPrefixSearcher::None; for arm in arms { @@ -118,7 +118,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { } s } else { - let mut s = cx.tcx.def_path_str(adt_def.did); + let mut s = cx.tcx.def_path_str(adt_def.did()); s.push_str("::"); s }, diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs index ce958b8ac9f5..eec232e6d098 100644 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/clippy_lints/src/methods/bind_instead_of_map.rs @@ -145,7 +145,7 @@ pub(crate) trait BindInsteadOfMap { if_chain! { if let Some(adt) = cx.typeck_results().expr_ty(recv).ty_adt_def(); if let Ok(vid) = cx.tcx.lang_items().require(Self::VARIANT_LANG_ITEM); - if Some(adt.did) == cx.tcx.parent(vid); + if Some(adt.did()) == cx.tcx.parent(vid); then {} else { return false; } } diff --git a/clippy_lints/src/methods/cloned_instead_of_copied.rs b/clippy_lints/src/methods/cloned_instead_of_copied.rs index 67a585edc255..6d30bb5a278b 100644 --- a/clippy_lints/src/methods/cloned_instead_of_copied.rs +++ b/clippy_lints/src/methods/cloned_instead_of_copied.rs @@ -15,7 +15,7 @@ pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span: Span, let inner_ty = match recv_ty.kind() { // `Option` -> `T` ty::Adt(adt, subst) - if cx.tcx.is_diagnostic_item(sym::Option, adt.did) && meets_msrv(msrv, &msrvs::OPTION_COPIED) => + if cx.tcx.is_diagnostic_item(sym::Option, adt.did()) && meets_msrv(msrv, &msrvs::OPTION_COPIED) => { subst.type_at(0) }, diff --git a/clippy_lints/src/methods/filter_map.rs b/clippy_lints/src/methods/filter_map.rs index 30c68186b3ae..558cb6bd64e7 100644 --- a/clippy_lints/src/methods/filter_map.rs +++ b/clippy_lints/src/methods/filter_map.rs @@ -119,9 +119,9 @@ pub(super) fn check<'tcx>( if let PatKind::Binding(_, filter_param_id, _, None) = filter_pat.kind; if let ExprKind::MethodCall(path, [filter_arg], _) = filter_body.value.kind; if let Some(opt_ty) = cx.typeck_results().expr_ty(filter_arg).ty_adt_def(); - if let Some(is_result) = if cx.tcx.is_diagnostic_item(sym::Option, opt_ty.did) { + if let Some(is_result) = if cx.tcx.is_diagnostic_item(sym::Option, opt_ty.did()) { Some(false) - } else if cx.tcx.is_diagnostic_item(sym::Result, opt_ty.did) { + } else if cx.tcx.is_diagnostic_item(sym::Result, opt_ty.did()) { Some(true) } else { None diff --git a/clippy_lints/src/methods/implicit_clone.rs b/clippy_lints/src/methods/implicit_clone.rs index 7a255baffd74..6e64e7f62220 100644 --- a/clippy_lints/src/methods/implicit_clone.rs +++ b/clippy_lints/src/methods/implicit_clone.rs @@ -17,7 +17,7 @@ pub fn check(cx: &LateContext<'_>, method_name: &str, expr: &hir::Expr<'_>, recv let return_type = cx.typeck_results().expr_ty(expr); let input_type = cx.typeck_results().expr_ty(recv); let (input_type, ref_count) = peel_mid_ty_refs(input_type); - if let Some(ty_name) = input_type.ty_adt_def().map(|adt_def| cx.tcx.item_name(adt_def.did)); + if let Some(ty_name) = input_type.ty_adt_def().map(|adt_def| cx.tcx.item_name(adt_def.did())); if return_type == input_type; then { let mut app = Applicability::MachineApplicable; diff --git a/clippy_lints/src/methods/inefficient_to_string.rs b/clippy_lints/src/methods/inefficient_to_string.rs index c0f66feb48ae..06ead144afa2 100644 --- a/clippy_lints/src/methods/inefficient_to_string.rs +++ b/clippy_lints/src/methods/inefficient_to_string.rs @@ -60,7 +60,7 @@ fn specializes_tostring(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { } if let ty::Adt(adt, substs) = ty.kind() { - match_def_path(cx, adt.did, &paths::COW) && substs.type_at(1).is_str() + match_def_path(cx, adt.did(), &paths::COW) && substs.type_at(1).is_str() } else { false } diff --git a/clippy_lints/src/methods/map_flatten.rs b/clippy_lints/src/methods/map_flatten.rs index 6782f64f2ca4..e1212c31cfb0 100644 --- a/clippy_lints/src/methods/map_flatten.rs +++ b/clippy_lints/src/methods/map_flatten.rs @@ -55,9 +55,9 @@ pub(super) fn check<'tcx>( // lint if caller of `.map().flatten()` is an Option or Result let caller_type = match cx.typeck_results().expr_ty(recv).kind() { ty::Adt(adt, _) => { - if cx.tcx.is_diagnostic_item(sym::Option, adt.did) { + if cx.tcx.is_diagnostic_item(sym::Option, adt.did()) { "Option" - } else if cx.tcx.is_diagnostic_item(sym::Result, adt.did) { + } else if cx.tcx.is_diagnostic_item(sym::Result, adt.did()) { "Result" } else { return; diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 926c25b4b40a..8125930b3046 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -152,7 +152,7 @@ fn parse_iter_usage<'tcx>( return if_chain! { if match_def_path(cx, did, &paths::ITERTOOLS_NEXT_TUPLE); if let ty::Adt(adt_def, subs) = cx.typeck_results().expr_ty(e).kind(); - if cx.tcx.is_diagnostic_item(sym::Option, adt_def.did); + if cx.tcx.is_diagnostic_item(sym::Option, adt_def.did()); if let ty::Tuple(subs) = subs.type_at(0).kind(); if subs.len() == 2; then { diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index 12ad3d8d6903..a307e33875eb 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -33,7 +33,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr< } else if !found_mapping && !mutates_arg { let in_ty = cx.typeck_results().node_type(body.params[0].hir_id); match cx.typeck_results().expr_ty(&body.value).kind() { - ty::Adt(adt, subst) if cx.tcx.is_diagnostic_item(sym::Option, adt.did) && in_ty == subst.type_at(0) => { + ty::Adt(adt, subst) if cx.tcx.is_diagnostic_item(sym::Option, adt.did()) && in_ty == subst.type_at(0) => { "filter" }, _ => return, diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index ce9ca15430e4..cba54e14212d 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -125,7 +125,7 @@ fn check_ty<'tcx>(cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) { if let Adt(def, substs) = ty.kind() { let is_keyed_type = [sym::HashMap, sym::BTreeMap, sym::HashSet, sym::BTreeSet] .iter() - .any(|diag_item| cx.tcx.is_diagnostic_item(*diag_item, def.did)); + .any(|diag_item| cx.tcx.is_diagnostic_item(*diag_item, def.did())); if is_keyed_type && is_interior_mutable_type(cx, substs.type_at(0), span) { span_lint(cx, MUTABLE_KEY_TYPE, span, "mutable key type"); } @@ -159,8 +159,8 @@ fn is_interior_mutable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Sp sym::Arc, ] .iter() - .any(|diag_item| cx.tcx.is_diagnostic_item(*diag_item, def.did)); - let is_box = Some(def.did) == cx.tcx.lang_items().owned_box(); + .any(|diag_item| cx.tcx.is_diagnostic_item(*diag_item, def.did())); + let is_box = Some(def.did()) == cx.tcx.lang_items().owned_box(); if is_std_collection || is_box { // The type is mutable if any of its type parameters are substs.types().any(|ty| is_interior_mutable_type(cx, ty, span)) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index ebfd908a6fb7..a57dc2b27986 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -198,7 +198,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { // Dereference suggestion let sugg = |diag: &mut Diagnostic| { if let ty::Adt(def, ..) = ty.kind() { - if let Some(span) = cx.tcx.hir().span_if_local(def.did) { + if let Some(span) = cx.tcx.hir().span_if_local(def.did()) { if can_type_implement_copy(cx.tcx, cx.param_env, ty, traits::ObligationCause::dummy_with_span(span)).is_ok() { diag.span_help(span, "consider marking this type as `Copy`"); } diff --git a/clippy_lints/src/needless_update.rs b/clippy_lints/src/needless_update.rs index ed315efaa2fa..c87c174ef732 100644 --- a/clippy_lints/src/needless_update.rs +++ b/clippy_lints/src/needless_update.rs @@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessUpdate { let ty = cx.typeck_results().expr_ty(expr); if let ty::Adt(def, _) = ty.kind() { if fields.len() == def.non_enum_variant().fields.len() - && !def.variants[0_usize.into()].is_field_list_non_exhaustive() + && !def.variant(0_usize.into()).is_field_list_non_exhaustive() { span_lint( cx, diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 6c68c1bc48df..9419056be143 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -113,7 +113,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { let mut impls = HirIdSet::default(); cx.tcx.for_each_impl(default_trait_id, |d| { if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() { - if let Some(local_def_id) = ty_def.did.as_local() { + if let Some(local_def_id) = ty_def.did().as_local() { impls.insert(cx.tcx.hir().local_def_id_to_hir_id(local_def_id)); } } @@ -126,7 +126,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { if_chain! { if let Some(ref impling_types) = self.impling_types; if let Some(self_def) = cx.tcx.type_of(self_def_id).ty_adt_def(); - if let Some(self_local_did) = self_def.did.as_local(); + if let Some(self_local_did) = self_def.did().as_local(); let self_id = cx.tcx.hir().local_def_id_to_hir_id(self_local_did); if impling_types.contains(&self_id); then { diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 3ba99403f06d..8db41ba6ee29 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -140,7 +140,7 @@ fn is_value_unfrozen_raw<'tcx>( match val.ty().kind() { // the fact that we have to dig into every structs to search enums // leads us to the point checking `UnsafeCell` directly is the only option. - ty::Adt(ty_def, ..) if Some(ty_def.did) == cx.tcx.lang_items().unsafe_cell_type() => true, + ty::Adt(ty_def, ..) if Some(ty_def.did()) == cx.tcx.lang_items().unsafe_cell_type() => true, ty::Array(..) | ty::Adt(..) | ty::Tuple(..) => { let val = cx.tcx.destructure_const(cx.param_env.and(val)); val.fields.iter().any(|field| inner(cx, *field)) diff --git a/clippy_lints/src/non_send_fields_in_send_ty.rs b/clippy_lints/src/non_send_fields_in_send_ty.rs index 5168ca67b6ab..ddef7352de88 100644 --- a/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy { let mut non_send_fields = Vec::new(); let hir_map = cx.tcx.hir(); - for variant in &adt_def.variants { + for variant in adt_def.variants() { for field in &variant.fields { if_chain! { if let Some(field_hir_id) = field @@ -233,7 +233,7 @@ fn contains_pointer_like<'tcx>(cx: &LateContext<'tcx>, target_ty: Ty<'tcx>) -> b return true; }, ty::Adt(adt_def, _) => { - if match_def_path(cx, adt_def.did, &paths::PTR_NON_NULL) { + if match_def_path(cx, adt_def.did(), &paths::PTR_NON_NULL) { return true; } }, diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 2c328195f24e..9c776437d7fe 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -405,13 +405,13 @@ fn check_fn_args<'cx, 'tcx: 'cx>( // Check that the name as typed matches the actual name of the type. // e.g. `fn foo(_: &Foo)` shouldn't trigger the lint when `Foo` is an alias for `Vec` if let [.., name] = path.segments; - if cx.tcx.item_name(adt.did) == name.ident.name; + if cx.tcx.item_name(adt.did()) == name.ident.name; if !is_lint_allowed(cx, PTR_ARG, hir_ty.hir_id); if params.get(i).map_or(true, |p| !is_lint_allowed(cx, PTR_ARG, p.hir_id)); then { - let (method_renames, deref_ty, deref_impl_id) = match cx.tcx.get_diagnostic_name(adt.did) { + let (method_renames, deref_ty, deref_impl_id) = match cx.tcx.get_diagnostic_name(adt.did()) { Some(sym::Vec) => ( [("clone", ".to_owned()")].as_slice(), DerefTy::Slice( @@ -462,7 +462,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>( return Some(PtrArg { idx: i, span: hir_ty.span, - ty_did: adt.did, + ty_did: adt.did(), ty_name: name.ident.name, method_renames, ref_prefix: RefPrefix { @@ -570,7 +570,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: .map(|sig| sig.input(i).skip_binder().peel_refs()) .map_or(true, |ty| match *ty.kind() { ty::Param(_) => true, - ty::Adt(def, _) => def.did == args.ty_did, + ty::Adt(def, _) => def.did() == args.ty_did, _ => false, }) { @@ -607,7 +607,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: // If the types match check for methods which exist on both types. e.g. `Vec::len` and // `slice::len` ty::Adt(def, _) - if def.did == args.ty_did + if def.did() == args.ty_did && (i != 0 || self.cx.tcx.trait_of_item(id).is_some() || !args.deref_assoc_items.map_or(false, |(id, items)| { diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index 123d0ad0457d..d07c26d7c897 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { if_chain! { if let Some(self_def) = self_ty.ty_adt_def(); - if let Some(self_local_did) = self_def.did.as_local(); + if let Some(self_local_did) = self_def.did().as_local(); let self_id = cx.tcx.hir().local_def_id_to_hir_id(self_local_did); if let Some(Node::Item(x)) = cx.tcx.hir().find(self_id); let type_name = x.ident.name.as_str().to_lowercase(); diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index 81076776ed3d..6edff2240920 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -141,7 +141,7 @@ pub(super) fn check<'tcx>( then { diag.note(&format!( "two instances of the same generic type (`{}`) may have different layouts", - cx.tcx.item_name(from_def.did) + cx.tcx.item_name(from_def.did()) )); } else { if from_ty_orig.peel_refs() != from_ty { @@ -304,13 +304,13 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> ty = sized_ty; continue; } - if def.repr.inhibit_struct_field_reordering_opt() { + if def.repr().inhibit_struct_field_reordering_opt() { ReducedTy::OrderedFields(ty) } else { ReducedTy::UnorderedFields(ty) } }, - ty::Adt(def, _) if def.is_enum() && (def.variants.is_empty() || is_c_void(cx, ty)) => { + ty::Adt(def, _) if def.is_enum() && (def.variants().is_empty() || is_c_void(cx, ty)) => { ReducedTy::TypeErasure }, ty::Foreign(_) => ReducedTy::TypeErasure, diff --git a/clippy_lints/src/transmute/unsound_collection_transmute.rs b/clippy_lints/src/transmute/unsound_collection_transmute.rs index 2d67401a15f2..831b0d450d20 100644 --- a/clippy_lints/src/transmute/unsound_collection_transmute.rs +++ b/clippy_lints/src/transmute/unsound_collection_transmute.rs @@ -11,11 +11,11 @@ use rustc_span::symbol::sym; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> bool { match (&from_ty.kind(), &to_ty.kind()) { (ty::Adt(from_adt, from_substs), ty::Adt(to_adt, to_substs)) => { - if from_adt.did != to_adt.did { + if from_adt.did() != to_adt.did() { return false; } if !matches!( - cx.tcx.get_diagnostic_name(to_adt.did), + cx.tcx.get_diagnostic_name(to_adt.did()), Some( sym::BTreeMap | sym::BTreeSet diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs index 4da32c52e750..80d6f3c63367 100644 --- a/clippy_lints/src/try_err.rs +++ b/clippy_lints/src/try_err.rs @@ -151,11 +151,11 @@ fn result_error_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option> { if_chain! { if let ty::Adt(def, subst) = ty.kind(); - if match_def_path(cx, def.did, &paths::POLL); + if match_def_path(cx, def.did(), &paths::POLL); let ready_ty = subst.type_at(0); if let ty::Adt(ready_def, ready_subst) = ready_ty.kind(); - if cx.tcx.is_diagnostic_item(sym::Result, ready_def.did); + if cx.tcx.is_diagnostic_item(sym::Result, ready_def.did()); then { Some(ready_subst.type_at(1)) } else { @@ -168,15 +168,15 @@ fn poll_result_error_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option< fn poll_option_result_error_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option> { if_chain! { if let ty::Adt(def, subst) = ty.kind(); - if match_def_path(cx, def.did, &paths::POLL); + if match_def_path(cx, def.did(), &paths::POLL); let ready_ty = subst.type_at(0); if let ty::Adt(ready_def, ready_subst) = ready_ty.kind(); - if cx.tcx.is_diagnostic_item(sym::Option, ready_def.did); + if cx.tcx.is_diagnostic_item(sym::Option, ready_def.did()); let some_ty = ready_subst.type_at(0); if let ty::Adt(some_def, some_subst) = some_ty.kind(); - if cx.tcx.is_diagnostic_item(sym::Result, some_def.did); + if cx.tcx.is_diagnostic_item(sym::Result, some_def.did()); then { Some(some_subst.type_at(1)) } else { diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index 1728533f18b8..f4f5a4336a39 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -102,9 +102,9 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { // Get the wrapper and inner types, if can't, abort. let (return_type_label, lang_item, inner_type) = if let ty::Adt(adt_def, subst) = return_ty(cx, hir_id).kind() { - if cx.tcx.is_diagnostic_item(sym::Option, adt_def.did) { + if cx.tcx.is_diagnostic_item(sym::Option, adt_def.did()) { ("Option", OptionSome, subst.type_at(0)) - } else if cx.tcx.is_diagnostic_item(sym::Result, adt_def.did) { + } else if cx.tcx.is_diagnostic_item(sym::Result, adt_def.did()) { ("Result", ResultOk, subst.type_at(0)) } else { return; diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index eb9efec3f161..a6ef6d79fc02 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -73,7 +73,7 @@ fn fn_eagerness<'tcx>( // than marker traits. // Due to the limited operations on these types functions should be fairly cheap. if def - .variants + .variants() .iter() .flat_map(|v| v.fields.iter()) .any(|x| matches!(cx.tcx.type_of(x.did).peel_refs().kind(), ty::Param(_))) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 8c14f0dd761a..cd20abd94ed2 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -268,7 +268,7 @@ pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str]) pub fn is_diag_item_method(cx: &LateContext<'_>, def_id: DefId, diag_item: Symbol) -> bool { if let Some(impl_did) = cx.tcx.impl_of_method(def_id) { if let Some(adt) = cx.tcx.type_of(impl_did).ty_adt_def() { - return cx.tcx.is_diagnostic_item(diag_item, adt.did); + return cx.tcx.is_diagnostic_item(diag_item, adt.did()); } } false @@ -657,7 +657,7 @@ fn is_default_equivalent_ctor(cx: &LateContext<'_>, def_id: DefId, path: &QPath< if let Some(adt) = cx.tcx.type_of(impl_did).ty_adt_def() { return std_types_symbols .iter() - .any(|&symbol| cx.tcx.is_diagnostic_item(symbol, adt.did)); + .any(|&symbol| cx.tcx.is_diagnostic_item(symbol, adt.did())); } } } diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 0646d1524a76..3645a9a5228c 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -51,7 +51,7 @@ pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool { /// Walks into `ty` and returns `true` if any inner type is an instance of the given adt /// constructor. -pub fn contains_adt_constructor(ty: Ty<'_>, adt: &AdtDef) -> bool { +pub fn contains_adt_constructor(ty: Ty<'_>, adt: AdtDef<'_>) -> bool { ty.walk().any(|inner| match inner.unpack() { GenericArgKind::Type(inner_ty) => inner_ty.ty_adt_def() == Some(adt), GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false, @@ -112,7 +112,7 @@ pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option< let def_id = match ty_to_check.kind() { ty::Array(..) => return Some(sym::array), ty::Slice(..) => return Some(sym::slice), - ty::Adt(adt, _) => adt.did, + ty::Adt(adt, _) => adt.did(), _ => return None, }; @@ -164,7 +164,7 @@ pub fn has_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { // Returns whether the type has #[must_use] attribute pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { match ty.kind() { - ty::Adt(adt, _) => must_use_attr(cx.tcx.get_attrs(adt.did)).is_some(), + ty::Adt(adt, _) => must_use_attr(cx.tcx.get_attrs(adt.did())).is_some(), ty::Foreign(ref did) => must_use_attr(cx.tcx.get_attrs(*did)).is_some(), ty::Slice(ty) | ty::Array(ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) | ty::Ref(_, ty, _) => { // for the Array case we don't need to care for the len == 0 case @@ -220,7 +220,7 @@ fn is_normalizable_helper<'tcx>( let cause = rustc_middle::traits::ObligationCause::dummy(); if infcx.at(&cause, param_env).normalize(ty).is_ok() { match ty.kind() { - ty::Adt(def, substs) => def.variants.iter().all(|variant| { + ty::Adt(def, substs) => def.variants().iter().all(|variant| { variant .fields .iter() @@ -264,7 +264,7 @@ pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool { pub fn is_type_ref_to_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symbol) -> bool { match ty.kind() { ty::Ref(_, ref_ty, _) => match ref_ty.kind() { - ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(diag_item, adt.did), + ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(diag_item, adt.did()), _ => false, }, _ => false, @@ -284,7 +284,7 @@ pub fn is_type_ref_to_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_ite /// [Diagnostic Items]: https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-items.html pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symbol) -> bool { match ty.kind() { - ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(diag_item, adt.did), + ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(diag_item, adt.did()), _ => false, } } @@ -294,7 +294,7 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symb /// Returns `false` if the `LangItem` is not defined. pub fn is_type_lang_item(cx: &LateContext<'_>, ty: Ty<'_>, lang_item: hir::LangItem) -> bool { match ty.kind() { - ty::Adt(adt, _) => cx.tcx.lang_items().require(lang_item).map_or(false, |li| li == adt.did), + ty::Adt(adt, _) => cx.tcx.lang_items().require(lang_item).map_or(false, |li| li == adt.did()), _ => false, } } @@ -310,7 +310,7 @@ pub fn is_isize_or_usize(typ: Ty<'_>) -> bool { /// If you change the signature, remember to update the internal lint `MatchTypeOnDiagItem` pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool { match ty.kind() { - ty::Adt(adt, _) => match_def_path(cx, adt.did, path), + ty::Adt(adt, _) => match_def_path(cx, adt.did(), path), _ => false, } } @@ -398,7 +398,7 @@ pub fn is_uninit_value_valid_for_ty(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { match *ty.kind() { ty::Array(component, _) => is_uninit_value_valid_for_ty(cx, component), ty::Tuple(types) => types.iter().all(|ty| is_uninit_value_valid_for_ty(cx, ty)), - ty::Adt(adt, _) => cx.tcx.lang_items().maybe_uninit() == Some(adt.did), + ty::Adt(adt, _) => cx.tcx.lang_items().maybe_uninit() == Some(adt.did()), _ => false, } } @@ -562,11 +562,11 @@ pub fn read_explicit_enum_value(tcx: TyCtxt<'_>, id: DefId) -> Option } /// Gets the value of the given variant. -pub fn get_discriminant_value(tcx: TyCtxt<'_>, adt: &'_ AdtDef, i: VariantIdx) -> EnumValue { - let variant = &adt.variants[i]; +pub fn get_discriminant_value(tcx: TyCtxt<'_>, adt: AdtDef<'_>, i: VariantIdx) -> EnumValue { + let variant = &adt.variant(i); match variant.discr { VariantDiscr::Explicit(id) => read_explicit_enum_value(tcx, id).unwrap(), - VariantDiscr::Relative(x) => match adt.variants[(i.as_usize() - x as usize).into()].discr { + VariantDiscr::Relative(x) => match adt.variant((i.as_usize() - x as usize).into()).discr { VariantDiscr::Explicit(id) => read_explicit_enum_value(tcx, id).unwrap() + x, VariantDiscr::Relative(_) => EnumValue::Unsigned(x.into()), }, @@ -577,7 +577,7 @@ pub fn get_discriminant_value(tcx: TyCtxt<'_>, adt: &'_ AdtDef, i: VariantIdx) - /// platform specific `libc::::c_void` types in libc. pub fn is_c_void(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { if let ty::Adt(adt, _) = ty.kind() - && let &[krate, .., name] = &*cx.get_def_path(adt.did) + && let &[krate, .., name] = &*cx.get_def_path(adt.did()) && let sym::libc | sym::core | sym::std = krate && name.as_str() == "c_void" { From 94cffd88fb4e9d9c9b416839d5c6598cf2086891 Mon Sep 17 00:00:00 2001 From: Dylan DPC Date: Tue, 15 Mar 2022 02:00:08 +0100 Subject: [PATCH 0443/1222] fix typos --- .github/ISSUE_TEMPLATE/ice.yml | 2 +- clippy_lints/src/upper_case_acronyms.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/ice.yml b/.github/ISSUE_TEMPLATE/ice.yml index 2a5b8b3c8914..81bd9c5e0327 100644 --- a/.github/ISSUE_TEMPLATE/ice.yml +++ b/.github/ISSUE_TEMPLATE/ice.yml @@ -10,7 +10,7 @@ body: attributes: label: Summary description: | - If possible, try to provide a minimal verifiable example. You can read ["Rust Bug Minimization Patterns"][mve] for how to create smaller examples. Otherwise, provide the crate where the ICE occured. + If possible, try to provide a minimal verifiable example. You can read ["Rust Bug Minimization Patterns"][mve] for how to create smaller examples. Otherwise, provide the crate where the ICE occurred. [mve]: http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/ validations: diff --git a/clippy_lints/src/upper_case_acronyms.rs b/clippy_lints/src/upper_case_acronyms.rs index 7286d0a7bf99..02bf09ed5068 100644 --- a/clippy_lints/src/upper_case_acronyms.rs +++ b/clippy_lints/src/upper_case_acronyms.rs @@ -114,7 +114,7 @@ impl LateLintPass<'_> for UpperCaseAcronyms { check_ident(cx, &it.ident, self.upper_case_acronyms_aggressive); }, ItemKind::Enum(ref enumdef, _) => { - // check enum variants seperately because again we only want to lint on private enums and + // check enum variants separately because again we only want to lint on private enums and // the fn check_variant does not know about the vis of the enum of its variants enumdef .variants From b81a29b5660fd3435fa76b50841f78488210a9d3 Mon Sep 17 00:00:00 2001 From: codehorseman Date: Wed, 16 Mar 2022 20:12:30 +0800 Subject: [PATCH 0444/1222] resolve the conflict in compiler/rustc_session/src/parse.rs Signed-off-by: codehorseman --- clippy_lints/src/copies.rs | 2 +- clippy_lints/src/fallible_impl_from.rs | 6 +++--- clippy_lints/src/float_equality_without_abs.rs | 6 +++--- clippy_lints/src/only_used_in_recursion.rs | 2 +- clippy_lints/src/suspicious_operation_groupings.rs | 10 +++++----- clippy_lints/src/trailing_empty_array.rs | 2 +- clippy_lints/src/trait_bounds.rs | 2 +- clippy_lints/src/unwrap_in_result.rs | 12 ++++++------ tests/lint_message_convention.rs | 2 +- tests/ui/manual_memcpy/with_loop_counters.rs | 2 +- tests/workspace.rs | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index a20aa12c9ff4..e6a0162fd027 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -126,7 +126,7 @@ declare_clippy_lint! { /// Duplicate code is less maintainable. /// /// ### Known problems - /// * The lint doesn't check if the moved expressions modify values that are beeing used in + /// * The lint doesn't check if the moved expressions modify values that are being 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) /// diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 574678b55421..088d9996516e 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -86,9 +86,9 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h // check for `unwrap` if let Some(arglists) = method_chain_args(expr, &["unwrap"]) { - let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); - if is_type_diagnostic_item(self.lcx, reciever_ty, sym::Option) - || is_type_diagnostic_item(self.lcx, reciever_ty, sym::Result) + let receiver_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); + if is_type_diagnostic_item(self.lcx, receiver_ty, sym::Option) + || is_type_diagnostic_item(self.lcx, receiver_ty, sym::Result) { self.result.push(expr.span); } diff --git a/clippy_lints/src/float_equality_without_abs.rs b/clippy_lints/src/float_equality_without_abs.rs index ca8886228de2..98aee7592ae8 100644 --- a/clippy_lints/src/float_equality_without_abs.rs +++ b/clippy_lints/src/float_equality_without_abs.rs @@ -20,7 +20,7 @@ declare_clippy_lint! { /// /// ### Known problems /// If the user can ensure that b is larger than a, the `.abs()` is - /// technically unneccessary. However, it will make the code more robust and doesn't have any + /// technically unnecessary. However, it will make the code more robust and doesn't have any /// large performance implications. If the abs call was deliberately left out for performance /// reasons, it is probably better to state this explicitly in the code, which then can be done /// with an allow. @@ -69,7 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatEqualityWithoutAbs { if_chain! { - // left hand side is a substraction + // left hand side is a subtraction if let ExprKind::Binary( Spanned { node: BinOpKind::Sub, @@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatEqualityWithoutAbs { if let Res::Def(DefKind::AssocConst, def_id) = cx.qpath_res(epsilon_path, rhs.hir_id); if match_def_path(cx, def_id, &paths::F32_EPSILON) || match_def_path(cx, def_id, &paths::F64_EPSILON); - // values of the substractions on the left hand side are of the type float + // values of the subtractions on the left hand side are of the type float let t_val_l = cx.typeck_results().expr_ty(val_l); let t_val_r = cx.typeck_results().expr_ty(val_r); if let ty::Float(_) = t_val_l.kind(); diff --git a/clippy_lints/src/only_used_in_recursion.rs b/clippy_lints/src/only_used_in_recursion.rs index b828d9334ee0..8e61f2347767 100644 --- a/clippy_lints/src/only_used_in_recursion.rs +++ b/clippy_lints/src/only_used_in_recursion.rs @@ -224,7 +224,7 @@ pub fn is_array(ty: Ty<'_>) -> bool { /// This builds the graph of side effect. /// The edge `a -> b` means if `a` has side effect, `b` will have side effect. /// -/// There are some exmaple in following code: +/// There are some example in following code: /// ```rust, ignore /// let b = 1; /// let a = b; // a -> b diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index 940a8428f779..b5dd27ff80de 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -290,7 +290,7 @@ fn ident_swap_sugg( // used instead, in these cases. *applicability = Applicability::MaybeIncorrect; - // We arbitraily choose one side to suggest changing, + // We arbitrarily choose one side to suggest changing, // since we don't have a better guess. If the user // ends up duplicating a clause, the `logic_bug` lint // should catch it. @@ -374,19 +374,19 @@ fn strip_non_ident_wrappers(expr: &Expr) -> &Expr { } fn extract_related_binops(kind: &ExprKind) -> Option>> { - append_opt_vecs(chained_binops(kind), if_statment_binops(kind)) + append_opt_vecs(chained_binops(kind), if_statement_binops(kind)) } -fn if_statment_binops(kind: &ExprKind) -> Option>> { +fn if_statement_binops(kind: &ExprKind) -> Option>> { match kind { ExprKind::If(ref condition, _, _) => chained_binops(&condition.kind), - ExprKind::Paren(ref e) => if_statment_binops(&e.kind), + ExprKind::Paren(ref e) => if_statement_binops(&e.kind), ExprKind::Block(ref block, _) => { let mut output = None; for stmt in &block.stmts { match stmt.kind { StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => { - output = append_opt_vecs(output, if_statment_binops(&e.kind)); + output = append_opt_vecs(output, if_statement_binops(&e.kind)); }, _ => {}, } diff --git a/clippy_lints/src/trailing_empty_array.rs b/clippy_lints/src/trailing_empty_array.rs index c9b2ce476e89..58cc057a39ed 100644 --- a/clippy_lints/src/trailing_empty_array.rs +++ b/clippy_lints/src/trailing_empty_array.rs @@ -10,7 +10,7 @@ declare_clippy_lint! { /// Displays a warning when a struct with a trailing zero-sized array is declared without a `repr` attribute. /// /// ### Why is this bad? - /// Zero-sized arrays aren't very useful in Rust itself, so such a struct is likely being created to pass to C code or in some other situation where control over memory layout matters (for example, in conjuction with manual allocation to make it easy to compute the offset of the array). Either way, `#[repr(C)]` (or another `repr` attribute) is needed. + /// Zero-sized arrays aren't very useful in Rust itself, so such a struct is likely being created to pass to C code or in some other situation where control over memory layout matters (for example, in conjunction with manual allocation to make it easy to compute the offset of the array). Either way, `#[repr(C)]` (or another `repr` attribute) is needed. /// /// ### Example /// ```rust diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index be9d538c3626..43e0132a7ec7 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -46,7 +46,7 @@ declare_clippy_lint! { /// /// ### Why is this bad? /// Duplicate bounds makes the code - /// less readable than specifing them only once. + /// less readable than specifying them only once. /// /// ### Example /// ```rust diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs index 2c13f1049b59..b32be238cd55 100644 --- a/clippy_lints/src/unwrap_in_result.rs +++ b/clippy_lints/src/unwrap_in_result.rs @@ -83,9 +83,9 @@ impl<'a, 'tcx> Visitor<'tcx> for FindExpectUnwrap<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { // check for `expect` if let Some(arglists) = method_chain_args(expr, &["expect"]) { - let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); - if is_type_diagnostic_item(self.lcx, reciever_ty, sym::Option) - || is_type_diagnostic_item(self.lcx, reciever_ty, sym::Result) + let receiver_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); + if is_type_diagnostic_item(self.lcx, receiver_ty, sym::Option) + || is_type_diagnostic_item(self.lcx, receiver_ty, sym::Result) { self.result.push(expr.span); } @@ -93,9 +93,9 @@ impl<'a, 'tcx> Visitor<'tcx> for FindExpectUnwrap<'a, 'tcx> { // check for `unwrap` if let Some(arglists) = method_chain_args(expr, &["unwrap"]) { - let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); - if is_type_diagnostic_item(self.lcx, reciever_ty, sym::Option) - || is_type_diagnostic_item(self.lcx, reciever_ty, sym::Result) + let receiver_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); + if is_type_diagnostic_item(self.lcx, receiver_ty, sym::Option) + || is_type_diagnostic_item(self.lcx, receiver_ty, sym::Result) { self.result.push(expr.span); } diff --git a/tests/lint_message_convention.rs b/tests/lint_message_convention.rs index b4d94dc983fe..dc82ba891fb1 100644 --- a/tests/lint_message_convention.rs +++ b/tests/lint_message_convention.rs @@ -16,7 +16,7 @@ impl Message { fn new(path: PathBuf) -> Self { let content: String = std::fs::read_to_string(&path).unwrap(); // we don't want the first letter after "error: ", "help: " ... to be capitalized - // also no puncutation (except for "?" ?) at the end of a line + // also no punctuation (except for "?" ?) at the end of a line let regex_set: RegexSet = RegexSet::new(&[ r"error: [A-Z]", r"help: [A-Z]", diff --git a/tests/ui/manual_memcpy/with_loop_counters.rs b/tests/ui/manual_memcpy/with_loop_counters.rs index ba388a05a285..c826b082adff 100644 --- a/tests/ui/manual_memcpy/with_loop_counters.rs +++ b/tests/ui/manual_memcpy/with_loop_counters.rs @@ -59,7 +59,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) } // make sure parentheses are added properly to bitwise operators, which have lower precedence than - // arithmetric ones + // arithmetic ones let mut count = 0 << 1; for i in 0..1 << 1 { dst[count] = src[i + 2]; diff --git a/tests/workspace.rs b/tests/workspace.rs index 677b4a4d5699..e13efb3e0164 100644 --- a/tests/workspace.rs +++ b/tests/workspace.rs @@ -93,7 +93,7 @@ fn test_no_deps_ignores_path_deps_in_workspaces() { output }; - // Trigger a sucessful build, so Cargo would like to cache the build result. + // Trigger a successful build, so Cargo would like to cache the build result. successful_build(); // Make sure there's no spurious rebuild when nothing changes. From 07b29a58f10e768f4146a4e39e403d5b1007d9b1 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 20 Mar 2022 18:26:09 +0100 Subject: [PATCH 0445/1222] Take &mut Diagnostic in emit_diagnostic. Taking a Diagnostic by move would break the usual pattern `diag.label(..).emit()`. --- src/driver.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index 8f8f1140a3da..855a6a6ef6ad 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -178,8 +178,8 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { // a .span_bug or .bug call has already printed what // it wants to print. if !info.payload().is::() { - let d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic"); - handler.emit_diagnostic(&d); + let mut d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic"); + handler.emit_diagnostic(&mut d); } let version_info = rustc_tools_util::get_version_info!(); From a71eebd594dc367c9b80a4933463054acc4dfa52 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 24 Mar 2022 11:27:07 +0000 Subject: [PATCH 0446/1222] update clippy stderr file --- tests/ui/crashes/ice-5497.stderr | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/ui/crashes/ice-5497.stderr diff --git a/tests/ui/crashes/ice-5497.stderr b/tests/ui/crashes/ice-5497.stderr new file mode 100644 index 000000000000..e75e7dc91367 --- /dev/null +++ b/tests/ui/crashes/ice-5497.stderr @@ -0,0 +1,10 @@ +error: this operation will panic at runtime + --> $DIR/ice-5497.rs:9:22 + | +LL | const OOB: i32 = [1][1] + T::OOB; + | ^^^^^^ index out of bounds: the length is 1 but the index is 1 + | + = note: `#[deny(unconditional_panic)]` on by default + +error: aborting due to previous error + From d577d7ed0c338025218b9aca12f2d4c36474a1f6 Mon Sep 17 00:00:00 2001 From: Grisha Vartanyan Date: Fri, 25 Mar 2022 15:05:27 +0100 Subject: [PATCH 0447/1222] Update clippy helper function types --- clippy_lints/src/regex.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index b6d04334de9e..a92097e1d24c 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -81,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for Regex { #[allow(clippy::cast_possible_truncation)] // truncation very unlikely here #[must_use] -fn str_span(base: Span, c: regex_syntax::ast::Span, offset: u16) -> Span { +fn str_span(base: Span, c: regex_syntax::ast::Span, offset: u8) -> Span { let offset = u32::from(offset); let end = base.lo() + BytePos(u32::try_from(c.end.offset).expect("offset too large") + offset); let start = base.lo() + BytePos(u32::try_from(c.start.offset).expect("offset too large") + offset); From d63c63792dcc1e2daf1c886904c34872013ce8b9 Mon Sep 17 00:00:00 2001 From: Jendrik Date: Sat, 26 Mar 2022 15:37:48 +0100 Subject: [PATCH 0448/1222] add #[must_use] to functions of slice and its iterators. --- tests/ui/bytes_nth.fixed | 4 ++-- tests/ui/bytes_nth.rs | 4 ++-- tests/ui/iter_next_slice.fixed | 8 ++++---- tests/ui/iter_next_slice.rs | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/ui/bytes_nth.fixed b/tests/ui/bytes_nth.fixed index 46b7833f4280..b1fb2e16bd58 100644 --- a/tests/ui/bytes_nth.fixed +++ b/tests/ui/bytes_nth.fixed @@ -5,7 +5,7 @@ fn main() { let s = String::from("String"); - s.as_bytes().get(3); + let _ = s.as_bytes().get(3); let _ = &s.as_bytes().get(3); - s[..].as_bytes().get(3); + let _ = s[..].as_bytes().get(3); } diff --git a/tests/ui/bytes_nth.rs b/tests/ui/bytes_nth.rs index c5e983d4d4e0..034c54e6a420 100644 --- a/tests/ui/bytes_nth.rs +++ b/tests/ui/bytes_nth.rs @@ -5,7 +5,7 @@ fn main() { let s = String::from("String"); - s.bytes().nth(3); + let _ = s.bytes().nth(3); let _ = &s.bytes().nth(3); - s[..].bytes().nth(3); + let _ = s[..].bytes().nth(3); } diff --git a/tests/ui/iter_next_slice.fixed b/tests/ui/iter_next_slice.fixed index 79c1db87ac3c..11ffc8edb149 100644 --- a/tests/ui/iter_next_slice.fixed +++ b/tests/ui/iter_next_slice.fixed @@ -6,16 +6,16 @@ fn main() { let s = [1, 2, 3]; let v = vec![1, 2, 3]; - s.get(0); + let _ = s.get(0); // Should be replaced by s.get(0) - s.get(2); + let _ = s.get(2); // Should be replaced by s.get(2) - v.get(5); + let _ = v.get(5); // Should be replaced by v.get(5) - v.get(0); + let _ = v.get(0); // Should be replaced by v.get(0) let o = Some(5); diff --git a/tests/ui/iter_next_slice.rs b/tests/ui/iter_next_slice.rs index ef9a55f3d997..e0d3aabd54ac 100644 --- a/tests/ui/iter_next_slice.rs +++ b/tests/ui/iter_next_slice.rs @@ -6,16 +6,16 @@ fn main() { let s = [1, 2, 3]; let v = vec![1, 2, 3]; - s.iter().next(); + let _ = s.iter().next(); // Should be replaced by s.get(0) - s[2..].iter().next(); + let _ = s[2..].iter().next(); // Should be replaced by s.get(2) - v[5..].iter().next(); + let _ = v[5..].iter().next(); // Should be replaced by v.get(5) - v.iter().next(); + let _ = v.iter().next(); // Should be replaced by v.get(0) let o = Some(5); From a539da7fce92125a5ca534cbefbfd6a8c00b438e Mon Sep 17 00:00:00 2001 From: Jendrik Date: Sat, 26 Mar 2022 15:47:22 +0100 Subject: [PATCH 0449/1222] add #[must_use] to functions of slice and its iterators. From 655ec905916044f9ef3f721a7b9edd426e262434 Mon Sep 17 00:00:00 2001 From: Jendrik Date: Sat, 26 Mar 2022 16:19:47 +0100 Subject: [PATCH 0450/1222] add #[must_use] to functions of slice and its iterators. --- tests/ui/bytes_nth.stderr | 12 ++++++------ tests/ui/iter_next_slice.stderr | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/ui/bytes_nth.stderr b/tests/ui/bytes_nth.stderr index 536decf5e7fc..8a7afa934502 100644 --- a/tests/ui/bytes_nth.stderr +++ b/tests/ui/bytes_nth.stderr @@ -1,8 +1,8 @@ error: called `.byte().nth()` on a `String` - --> $DIR/bytes_nth.rs:8:5 + --> $DIR/bytes_nth.rs:8:13 | -LL | s.bytes().nth(3); - | ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)` +LL | let _ = s.bytes().nth(3); + | ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)` | = note: `-D clippy::bytes-nth` implied by `-D warnings` @@ -13,10 +13,10 @@ LL | let _ = &s.bytes().nth(3); | ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)` error: called `.byte().nth()` on a `str` - --> $DIR/bytes_nth.rs:10:5 + --> $DIR/bytes_nth.rs:10:13 | -LL | s[..].bytes().nth(3); - | ^^^^^^^^^^^^^^^^^^^^ help: try: `s[..].as_bytes().get(3)` +LL | let _ = s[..].bytes().nth(3); + | ^^^^^^^^^^^^^^^^^^^^ help: try: `s[..].as_bytes().get(3)` error: aborting due to 3 previous errors diff --git a/tests/ui/iter_next_slice.stderr b/tests/ui/iter_next_slice.stderr index 8c10a252ee01..a78d2c2d5e83 100644 --- a/tests/ui/iter_next_slice.stderr +++ b/tests/ui/iter_next_slice.stderr @@ -1,28 +1,28 @@ error: using `.iter().next()` on an array - --> $DIR/iter_next_slice.rs:9:5 + --> $DIR/iter_next_slice.rs:9:13 | -LL | s.iter().next(); - | ^^^^^^^^^^^^^^^ help: try calling: `s.get(0)` +LL | let _ = s.iter().next(); + | ^^^^^^^^^^^^^^^ help: try calling: `s.get(0)` | = note: `-D clippy::iter-next-slice` implied by `-D warnings` error: using `.iter().next()` on a Slice without end index - --> $DIR/iter_next_slice.rs:12:5 + --> $DIR/iter_next_slice.rs:12:13 | -LL | s[2..].iter().next(); - | ^^^^^^^^^^^^^^^^^^^^ help: try calling: `s.get(2)` +LL | let _ = s[2..].iter().next(); + | ^^^^^^^^^^^^^^^^^^^^ help: try calling: `s.get(2)` error: using `.iter().next()` on a Slice without end index - --> $DIR/iter_next_slice.rs:15:5 + --> $DIR/iter_next_slice.rs:15:13 | -LL | v[5..].iter().next(); - | ^^^^^^^^^^^^^^^^^^^^ help: try calling: `v.get(5)` +LL | let _ = v[5..].iter().next(); + | ^^^^^^^^^^^^^^^^^^^^ help: try calling: `v.get(5)` error: using `.iter().next()` on an array - --> $DIR/iter_next_slice.rs:18:5 + --> $DIR/iter_next_slice.rs:18:13 | -LL | v.iter().next(); - | ^^^^^^^^^^^^^^^ help: try calling: `v.get(0)` +LL | let _ = v.iter().next(); + | ^^^^^^^^^^^^^^^ help: try calling: `v.get(0)` error: aborting due to 4 previous errors From 19b3f5cdc275574b3413568c98cd557f607c3473 Mon Sep 17 00:00:00 2001 From: Jendrik Date: Sat, 26 Mar 2022 16:23:55 +0100 Subject: [PATCH 0451/1222] add #[must_use] to functions of slice and its iterators. From bdde556969b2579c015ec75f354400415db545a4 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 29 Mar 2022 17:11:12 +0200 Subject: [PATCH 0452/1222] Remember mutability in `DefKind::Static`. This allows to compute the `BodyOwnerKind` from `DefKind` only, and removes a direct dependency of some MIR queries onto HIR. As a side effect, it also simplifies metadata, since we don't need 4 flavours of `EntryKind::*Static` any more. --- clippy_lints/src/arithmetic.rs | 4 ++-- clippy_lints/src/loops/needless_range_loop.rs | 2 +- clippy_lints/src/loops/while_immutable_condition.rs | 2 +- clippy_lints/src/methods/expect_fun_call.rs | 2 +- clippy_lints/src/shadow.rs | 10 ++++++++-- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs index e0c1d6ab6e12..c5948707c812 100644 --- a/clippy_lints/src/arithmetic.rs +++ b/clippy_lints/src/arithmetic.rs @@ -139,11 +139,11 @@ impl<'tcx> LateLintPass<'tcx> for Arithmetic { } fn check_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { - let body_owner = cx.tcx.hir().body_owner(body.id()); + let body_owner = cx.tcx.hir().body_owner_def_id(body.id()); match cx.tcx.hir().body_owner_kind(body_owner) { hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const => { - let body_span = cx.tcx.hir().span(body_owner); + let body_span = cx.tcx.def_span(body_owner); if let Some(span) = self.const_span { if span.contains(body_span) { diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 9d335073e4fb..72e86804ed2c 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -273,7 +273,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { } return false; // no need to walk further *on the variable* } - Res::Def(DefKind::Static | DefKind::Const, ..) => { + Res::Def(DefKind::Static (_)| DefKind::Const, ..) => { if index_used_directly { self.indexed_directly.insert( seqvar.segments[0].ident.name, diff --git a/clippy_lints/src/loops/while_immutable_condition.rs b/clippy_lints/src/loops/while_immutable_condition.rs index 5dcfed65c78a..a63422d2a36a 100644 --- a/clippy_lints/src/loops/while_immutable_condition.rs +++ b/clippy_lints/src/loops/while_immutable_condition.rs @@ -104,7 +104,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> { Res::Local(hir_id) => { self.ids.insert(hir_id); }, - Res::Def(DefKind::Static, def_id) => { + Res::Def(DefKind::Static(_), def_id) => { let mutable = self.cx.tcx.is_mutable_static(def_id); self.def_ids.insert(def_id, mutable); }, diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index c3cb02329a11..6f2307d8f18f 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -93,7 +93,7 @@ pub(super) fn check<'tcx>( }, hir::ExprKind::Path(ref p) => matches!( cx.qpath_res(p, arg.hir_id), - hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static, _) + hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static(_), _) ), _ => false, } diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index ce05c5a6164f..118825850446 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -139,14 +139,20 @@ impl<'tcx> LateLintPass<'tcx> for Shadow { fn check_body(&mut self, cx: &LateContext<'_>, body: &Body<'_>) { let hir = cx.tcx.hir(); - if !matches!(hir.body_owner_kind(hir.body_owner(body.id())), BodyOwnerKind::Closure) { + if !matches!( + hir.body_owner_kind(hir.body_owner_def_id(body.id())), + BodyOwnerKind::Closure + ) { self.bindings.push(FxHashMap::default()); } } fn check_body_post(&mut self, cx: &LateContext<'_>, body: &Body<'_>) { let hir = cx.tcx.hir(); - if !matches!(hir.body_owner_kind(hir.body_owner(body.id())), BodyOwnerKind::Closure) { + if !matches!( + hir.body_owner_kind(hir.body_owner_def_id(body.id())), + BodyOwnerKind::Closure + ) { self.bindings.pop(); } } From b7cb3412cd19302216d3ebbaeddc5438836a077e Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 18 Mar 2022 13:33:40 +0100 Subject: [PATCH 0453/1222] get clippy to compile again --- clippy_lints/src/implicit_saturating_sub.rs | 18 +++++------------- clippy_lints/src/methods/implicit_clone.rs | 9 +++++---- clippy_lints/src/methods/suspicious_splitn.rs | 8 ++++---- clippy_lints/src/ptr.rs | 18 +++--------------- clippy_utils/src/lib.rs | 14 ++++++-------- .../conf_disallowed_methods.rs | 4 ++-- .../conf_disallowed_methods.stderr | 14 +------------- 7 files changed, 26 insertions(+), 59 deletions(-) diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index 6515975fbffd..ae4158662d46 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -3,7 +3,7 @@ use clippy_utils::{higher, peel_blocks_with_stmt, SpanlessEq}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; -use rustc_hir::{lang_items::LangItem, BinOpKind, Expr, ExprKind, QPath}; +use rustc_hir::{BinOpKind, Expr, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -82,14 +82,6 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { // Get the variable name let var_name = ares_path.segments[0].ident.name.as_str(); - const INT_TYPES: [LangItem; 5] = [ - LangItem::I8, - LangItem::I16, - LangItem::I32, - LangItem::I64, - LangItem::Isize - ]; - match cond_num_val.kind { ExprKind::Lit(ref cond_lit) => { // Check if the constant is zero @@ -105,8 +97,8 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { if name.ident.as_str() == "MIN"; if let Some(const_id) = cx.typeck_results().type_dependent_def_id(cond_num_val.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(const_id); - let mut int_ids = INT_TYPES.iter().filter_map(|&ty| cx.tcx.lang_items().require(ty).ok()); - if int_ids.any(|int_id| int_id == impl_id); + if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl + if cx.tcx.type_of(impl_id).is_integral(); then { print_lint_and_sugg(cx, var_name, expr) } @@ -118,8 +110,8 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { if name.ident.as_str() == "min_value"; if let Some(func_id) = cx.typeck_results().type_dependent_def_id(func.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(func_id); - let mut int_ids = INT_TYPES.iter().filter_map(|&ty| cx.tcx.lang_items().require(ty).ok()); - if int_ids.any(|int_id| int_id == impl_id); + if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl + if cx.tcx.type_of(impl_id).is_integral(); then { print_lint_and_sugg(cx, var_name, expr) } diff --git a/clippy_lints/src/methods/implicit_clone.rs b/clippy_lints/src/methods/implicit_clone.rs index 6e64e7f62220..c98cdfbca434 100644 --- a/clippy_lints/src/methods/implicit_clone.rs +++ b/clippy_lints/src/methods/implicit_clone.rs @@ -49,10 +49,11 @@ pub fn is_clone_like(cx: &LateContext<'_>, method_name: &str, method_def_id: hir "to_owned" => is_diag_trait_item(cx, method_def_id, sym::ToOwned), "to_path_buf" => is_diag_item_method(cx, method_def_id, sym::Path), "to_vec" => { - cx.tcx - .impl_of_method(method_def_id) - .map(|impl_did| Some(impl_did) == cx.tcx.lang_items().slice_alloc_impl()) - == Some(true) + cx.tcx.impl_of_method(method_def_id) + .filter(|&impl_did| { + cx.tcx.type_of(impl_did).is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none() + }) + .is_some() }, _ => false, } diff --git a/clippy_lints/src/methods/suspicious_splitn.rs b/clippy_lints/src/methods/suspicious_splitn.rs index 1c546a15bf62..55567d8625e5 100644 --- a/clippy_lints/src/methods/suspicious_splitn.rs +++ b/clippy_lints/src/methods/suspicious_splitn.rs @@ -12,13 +12,13 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se if count <= 1; if let Some(call_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(call_id); - let lang_items = cx.tcx.lang_items(); - if lang_items.slice_impl() == Some(impl_id) || lang_items.str_impl() == Some(impl_id); + if cx.tcx.impl_trait_ref(impl_id).is_none(); + let self_ty = cx.tcx.type_of(impl_id); + if self_ty.is_slice() || self_ty.is_str(); then { // Ignore empty slice and string literals when used with a literal count. if matches!(self_arg.kind, ExprKind::Array([])) || matches!(self_arg.kind, ExprKind::Lit(Spanned { node: LitKind::Str(s, _), .. }) if s.is_empty()) - { return; } @@ -28,7 +28,7 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se "the resulting iterator will always return `None`") } else { (format!("`{}` called with `1` split", method_name), - if lang_items.slice_impl() == Some(impl_id) { + if self_ty.is_slice() { "the resulting iterator will always return the entire slice followed by `None`" } else { "the resulting iterator will always return the entire string followed by `None`" diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index ba1997e70e13..9d4313827f7c 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -16,7 +16,7 @@ use rustc_hir::{ }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; -use rustc_middle::ty::{self, AssocItems, AssocKind, Ty}; +use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::symbol::Symbol; @@ -308,7 +308,6 @@ struct PtrArg<'tcx> { method_renames: &'static [(&'static str, &'static str)], ref_prefix: RefPrefix, deref_ty: DerefTy<'tcx>, - deref_assoc_items: Option<(DefId, &'tcx AssocItems<'tcx>)>, } impl PtrArg<'_> { fn build_msg(&self) -> String { @@ -411,7 +410,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>( if params.get(i).map_or(true, |p| !is_lint_allowed(cx, PTR_ARG, p.hir_id)); then { - let (method_renames, deref_ty, deref_impl_id) = match cx.tcx.get_diagnostic_name(adt.did()) { + let (method_renames, deref_ty) = match cx.tcx.get_diagnostic_name(adt.did()) { Some(sym::Vec) => ( [("clone", ".to_owned()")].as_slice(), DerefTy::Slice( @@ -424,17 +423,14 @@ fn check_fn_args<'cx, 'tcx: 'cx>( }), substs.type_at(0), ), - cx.tcx.lang_items().slice_impl() ), Some(sym::String) => ( [("clone", ".to_owned()"), ("as_str", "")].as_slice(), DerefTy::Str, - cx.tcx.lang_items().str_impl() ), Some(sym::PathBuf) => ( [("clone", ".to_path_buf()"), ("as_path", "")].as_slice(), DerefTy::Path, - None, ), Some(sym::Cow) if mutability == Mutability::Not => { let ty_name = name.args @@ -470,7 +466,6 @@ fn check_fn_args<'cx, 'tcx: 'cx>( mutability, }, deref_ty, - deref_assoc_items: deref_impl_id.map(|id| (id, cx.tcx.associated_items(id))), }); } } @@ -607,14 +602,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: // If the types match check for methods which exist on both types. e.g. `Vec::len` and // `slice::len` ty::Adt(def, _) - if def.did() == args.ty_did - && (i != 0 - || self.cx.tcx.trait_of_item(id).is_some() - || !args.deref_assoc_items.map_or(false, |(id, items)| { - items - .find_by_name_and_kind(self.cx.tcx, name.ident, AssocKind::Fn, id) - .is_some() - })) => + if def.did() == args.ty_did => { set_skip_flag(); }, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index cd20abd94ed2..b55075943b29 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -77,9 +77,9 @@ use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::LangItem::{OptionNone, ResultErr, ResultOk}; use rustc_hir::{ - def, lang_items, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Constness, Destination, Expr, + def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Constness, Destination, Expr, ExprKind, FnDecl, ForeignItem, HirId, Impl, ImplItem, ImplItemKind, IsAsync, Item, ItemKind, LangItem, Local, - MatchSource, Mutability, Node, Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, Target, + MatchSource, Mutability, Node, Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitRef, TyKind, UnOp, }; use rustc_lint::{LateContext, Level, Lint, LintContext}; @@ -479,12 +479,10 @@ pub fn def_path_res(cx: &LateContext<'_>, path: &[&str]) -> Res { _ => None, } } - fn find_primitive(tcx: TyCtxt<'_>, name: &str) -> Option { - if let Some(&(index, Target::Impl)) = lang_items::ITEM_REFS.get(&Symbol::intern(name)) { - tcx.lang_items().items()[index] - } else { - None - } + fn find_primitive(_tcx: TyCtxt<'_>, _name: &str) -> Option { + // FIXME: Deal with this without relying on lang items or by only + // looking at a single impl. + None } fn find_crate(tcx: TyCtxt<'_>, name: &str) -> Option { tcx.crates(()) diff --git a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs index 338b3b5b28f4..f8086bd2e4d0 100644 --- a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs +++ b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs @@ -10,8 +10,8 @@ fn main() { let mut a = vec![1, 2, 3, 4]; a.iter().sum::(); - a.sort_unstable(); + a.sort_unstable(); // FIXME: Warn here - let _ = 2.0f32.clamp(3.0f32, 4.0f32); + let _ = 2.0f32.clamp(3.0f32, 4.0f32); // FIXME: Warn here let _ = 2.0f64.clamp(3.0f64, 4.0f64); } diff --git a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr index 5533676aea28..999ead10d518 100644 --- a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr +++ b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr @@ -20,17 +20,5 @@ error: use of a disallowed method `std::iter::Iterator::sum` LL | a.iter().sum::(); | ^^^^^^^^^^^^^^^^^^^^^ -error: use of a disallowed method `slice::sort_unstable` - --> $DIR/conf_disallowed_methods.rs:13:5 - | -LL | a.sort_unstable(); - | ^^^^^^^^^^^^^^^^^ - -error: use of a disallowed method `f32::clamp` - --> $DIR/conf_disallowed_methods.rs:15:13 - | -LL | let _ = 2.0f32.clamp(3.0f32, 4.0f32); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 5 previous errors +error: aborting due to 3 previous errors From aefc4d2a8c128ceecab8d1400ea10dc8072b1076 Mon Sep 17 00:00:00 2001 From: lcnr Date: Wed, 30 Mar 2022 11:57:53 +0200 Subject: [PATCH 0454/1222] clippy: nameres for primitive type impls --- clippy_utils/src/lib.rs | 95 ++++++++++++------- .../conf_disallowed_methods.rs | 4 +- .../conf_disallowed_methods.stderr | 14 ++- 3 files changed, 75 insertions(+), 38 deletions(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index b55075943b29..62e144398012 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -87,6 +87,8 @@ use rustc_middle::hir::place::PlaceBase; use rustc_middle::ty as rustc_ty; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; use rustc_middle::ty::binding::BindingMode; +use rustc_middle::ty::{IntTy, UintTy, FloatTy}; +use rustc_middle::ty::fast_reject::SimplifiedTypeGen::*; use rustc_middle::ty::{layout::IntegerExt, BorrowKind, DefIdTree, Ty, TyCtxt, TypeAndMut, TypeFoldable, UpvarCapture}; use rustc_semver::RustcVersion; use rustc_session::Session; @@ -455,14 +457,6 @@ pub fn path_def_id<'tcx>(cx: &LateContext<'_>, maybe_path: &impl MaybePath<'tcx> /// Resolves a def path like `std::vec::Vec`. /// This function is expensive and should be used sparingly. pub fn def_path_res(cx: &LateContext<'_>, path: &[&str]) -> Res { - macro_rules! try_res { - ($e:expr) => { - match $e { - Some(e) => e, - None => return Res::Err, - } - }; - } fn item_child_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: &str) -> Option { match tcx.def_kind(def_id) { DefKind::Mod | DefKind::Enum | DefKind::Trait => tcx @@ -479,10 +473,36 @@ pub fn def_path_res(cx: &LateContext<'_>, path: &[&str]) -> Res { _ => None, } } - fn find_primitive(_tcx: TyCtxt<'_>, _name: &str) -> Option { - // FIXME: Deal with this without relying on lang items or by only - // looking at a single impl. - None + fn find_primitive<'tcx>(tcx: TyCtxt<'tcx>, name: &str) -> impl Iterator + 'tcx { + let single = |ty| tcx.incoherent_impls(ty).iter().copied(); + let empty = || [].iter().copied(); + match name { + "bool" => single(BoolSimplifiedType), + "char" => single(CharSimplifiedType), + "str" => single(StrSimplifiedType), + "array" => single(ArraySimplifiedType), + "slice" => single(SliceSimplifiedType), + // FIXME: rustdoc documents these two using just `pointer`. + // + // Maybe this is something we should do here too. + "const_ptr" => single(PtrSimplifiedType(Mutability::Not)), + "mut_ptr" => single(PtrSimplifiedType(Mutability::Mut)), + "isize" => single(IntSimplifiedType(IntTy::Isize)), + "i8" => single(IntSimplifiedType(IntTy::I8)), + "i16" => single(IntSimplifiedType(IntTy::I16)), + "i32" => single(IntSimplifiedType(IntTy::I32)), + "i64" => single(IntSimplifiedType(IntTy::I64)), + "i128" => single(IntSimplifiedType(IntTy::I128)), + "usize" => single(UintSimplifiedType(UintTy::Usize)), + "u8" => single(UintSimplifiedType(UintTy::U8)), + "u16" => single(UintSimplifiedType(UintTy::U16)), + "u32" => single(UintSimplifiedType(UintTy::U32)), + "u64" => single(UintSimplifiedType(UintTy::U64)), + "u128" => single(UintSimplifiedType(UintTy::U128)), + "f32" => single(FloatSimplifiedType(FloatTy::F32)), + "f64" => single(FloatSimplifiedType(FloatTy::F64)), + _ => empty(), + } } fn find_crate(tcx: TyCtxt<'_>, name: &str) -> Option { tcx.crates(()) @@ -500,30 +520,35 @@ pub fn def_path_res(cx: &LateContext<'_>, path: &[&str]) -> Res { _ => return Res::Err, }; let tcx = cx.tcx; - let first = try_res!( - find_primitive(tcx, base) - .or_else(|| find_crate(tcx, base)) - .and_then(|id| item_child_by_name(tcx, id, first)) - ); + let starts = find_primitive(tcx, base) + .chain(find_crate(tcx, base)) + .flat_map(|id| item_child_by_name(tcx, id, first)); - let last = path - .iter() - .copied() - // for each segment, find the child item - .try_fold(first, |res, segment| { - let def_id = res.def_id(); - if let Some(item) = item_child_by_name(tcx, def_id, segment) { - Some(item) - } else if matches!(res, Res::Def(DefKind::Enum | DefKind::Struct, _)) { - // it is not a child item so check inherent impl items - tcx.inherent_impls(def_id) - .iter() - .find_map(|&impl_def_id| item_child_by_name(tcx, impl_def_id, segment)) - } else { - None - } - }); - try_res!(last).expect_non_local() + for first in starts { + let last = path + .iter() + .copied() + // for each segment, find the child item + .try_fold(first, |res, segment| { + let def_id = res.def_id(); + if let Some(item) = item_child_by_name(tcx, def_id, segment) { + Some(item) + } else if matches!(res, Res::Def(DefKind::Enum | DefKind::Struct, _)) { + // it is not a child item so check inherent impl items + tcx.inherent_impls(def_id) + .iter() + .find_map(|&impl_def_id| item_child_by_name(tcx, impl_def_id, segment)) + } else { + None + } + }); + + if let Some(last) = last { + return last; + } + } + + Res::Err } /// Convenience function to get the `DefId` of a trait by path. diff --git a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs index f8086bd2e4d0..338b3b5b28f4 100644 --- a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs +++ b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs @@ -10,8 +10,8 @@ fn main() { let mut a = vec![1, 2, 3, 4]; a.iter().sum::(); - a.sort_unstable(); // FIXME: Warn here + a.sort_unstable(); - let _ = 2.0f32.clamp(3.0f32, 4.0f32); // FIXME: Warn here + let _ = 2.0f32.clamp(3.0f32, 4.0f32); let _ = 2.0f64.clamp(3.0f64, 4.0f64); } diff --git a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr index 999ead10d518..5533676aea28 100644 --- a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr +++ b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr @@ -20,5 +20,17 @@ error: use of a disallowed method `std::iter::Iterator::sum` LL | a.iter().sum::(); | ^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 3 previous errors +error: use of a disallowed method `slice::sort_unstable` + --> $DIR/conf_disallowed_methods.rs:13:5 + | +LL | a.sort_unstable(); + | ^^^^^^^^^^^^^^^^^ + +error: use of a disallowed method `f32::clamp` + --> $DIR/conf_disallowed_methods.rs:15:13 + | +LL | let _ = 2.0f32.clamp(3.0f32, 4.0f32); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 5 previous errors From 904f44344001a1413dbc3dbcaf870ddbc4e287b8 Mon Sep 17 00:00:00 2001 From: b-naber Date: Fri, 25 Mar 2022 10:06:10 +0100 Subject: [PATCH 0455/1222] rebase and use ty::Const in patterns again --- clippy_lints/src/matches/overlapping_arms.rs | 17 +++++++---------- clippy_lints/src/neg_multiply.rs | 2 +- clippy_utils/src/consts.rs | 4 ++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/matches/overlapping_arms.rs b/clippy_lints/src/matches/overlapping_arms.rs index 7e6581266902..b5fa847451d1 100644 --- a/clippy_lints/src/matches/overlapping_arms.rs +++ b/clippy_lints/src/matches/overlapping_arms.rs @@ -1,4 +1,4 @@ -use clippy_utils::consts::{constant, constant_full_int, miri_to_const, FullInt}; +use clippy_utils::consts::{constant, constant_full_int, FullInt}; use clippy_utils::diagnostics::span_lint_and_note; use core::cmp::Ordering; use rustc_hir::{Arm, Expr, PatKind, RangeEnd}; @@ -32,18 +32,15 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>) .filter_map(|arm| { if let Arm { pat, guard: None, .. } = *arm { if let PatKind::Range(ref lhs, ref rhs, range_end) = pat.kind { - let lhs_const = match lhs { - Some(lhs) => constant(cx, cx.typeck_results(), lhs)?.0, - None => miri_to_const(ty.numeric_min_val(cx.tcx)?)?, + let lhs_val = match lhs { + Some(lhs) => constant(cx, cx.typeck_results(), lhs)?.0.int_value(cx, ty)?, + None => FullInt::U(ty.numeric_min_val(cx.tcx)?), }; - let rhs_const = match rhs { - Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0, - None => miri_to_const(ty.numeric_max_val(cx.tcx)?)?, + let rhs_val = match rhs { + Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0.int_value(cx, ty)?, + None => FullInt::U(ty.numeric_max_val(cx.tcx)?), }; - let lhs_val = lhs_const.int_value(cx, ty)?; - let rhs_val = rhs_const.int_value(cx, ty)?; - let rhs_bound = match range_end { RangeEnd::Included => EndBound::Included(rhs_val), RangeEnd::Excluded => EndBound::Excluded(rhs_val), diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index 0d05c83ffe45..6ba9ba0753d4 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for NegMultiply { fn check_mul(cx: &LateContext<'_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_>) { if_chain! { if let ExprKind::Lit(ref l) = lit.kind; - if consts::lit_to_constant(&l.node, cx.typeck_results().expr_ty_opt(lit)) == Constant::Int(1); + if consts::lit_to_mir_constant(&l.node, cx.typeck_results().expr_ty_opt(lit)) == Constant::Int(1); if cx.typeck_results().expr_ty(exp).is_integral(); then { diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 1d6f7acab139..be46b791aa4b 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -179,7 +179,7 @@ impl Constant { } /// Parses a `LitKind` to a `Constant`. -pub fn lit_to_constant(lit: &LitKind, ty: Option>) -> Constant { +pub fn lit_to_mir_constant(lit: &LitKind, ty: Option>) -> Constant { match *lit { LitKind::Str(ref is, _) => Constant::Str(is.to_string()), LitKind::Byte(b) => Constant::Int(u128::from(b)), @@ -301,7 +301,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { if is_direct_expn_of(e.span, "cfg").is_some() { None } else { - Some(lit_to_constant(&lit.node, self.typeck_results.expr_ty_opt(e))) + Some(lit_to_mir_constant(&lit.node, self.typeck_results.expr_ty_opt(e))) } }, ExprKind::Array(vec) => self.multi(vec).map(Constant::Vec), From 83d11caade72009f9f8e737f74fbc82fe4863785 Mon Sep 17 00:00:00 2001 From: David Wood Date: Thu, 24 Mar 2022 02:03:04 +0000 Subject: [PATCH 0456/1222] span: move `MultiSpan` `MultiSpan` contains labels, which are more complicated with the introduction of diagnostic translation and will use types from `rustc_errors` - however, `rustc_errors` depends on `rustc_span` so `rustc_span` cannot use types like `DiagnosticMessage` without dependency cycles. Introduce a new `rustc_error_messages` crate that can contain `DiagnosticMessage` and `MultiSpan`. Signed-off-by: David Wood --- clippy_lints/src/collapsible_match.rs | 3 ++- clippy_lints/src/doc.rs | 4 ++-- clippy_lints/src/loops/needless_collect.rs | 4 ++-- clippy_lints/src/ptr.rs | 4 ++-- clippy_utils/src/diagnostics.rs | 21 ++++++++++++++++----- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/collapsible_match.rs b/clippy_lints/src/collapsible_match.rs index c71e9f10f79e..acb3c917d624 100644 --- a/clippy_lints/src/collapsible_match.rs +++ b/clippy_lints/src/collapsible_match.rs @@ -3,11 +3,12 @@ use clippy_utils::higher::IfLetOrMatch; use clippy_utils::visitors::is_local_used; use clippy_utils::{is_lang_ctor, is_unit_expr, path_to_local, peel_blocks_with_stmt, peel_ref_operators, SpanlessEq}; use if_chain::if_chain; +use rustc_errors::MultiSpan; use rustc_hir::LangItem::OptionNone; use rustc_hir::{Arm, Expr, Guard, HirId, Pat, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::{MultiSpan, Span}; +use rustc_span::Span; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 703aa458f44e..d67c03714e38 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -11,7 +11,7 @@ use rustc_ast::token::CommentKind; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; use rustc_errors::emitter::EmitterWriter; -use rustc_errors::{Applicability, Handler, SuggestionStyle}; +use rustc_errors::{Applicability, Handler, MultiSpan, SuggestionStyle}; use rustc_hir as hir; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{AnonConst, Expr}; @@ -25,7 +25,7 @@ use rustc_session::parse::ParseSess; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::def_id::LocalDefId; use rustc_span::edition::Edition; -use rustc_span::source_map::{BytePos, FilePathMapping, MultiSpan, SourceMap, Span}; +use rustc_span::source_map::{BytePos, FilePathMapping, SourceMap, Span}; use rustc_span::{sym, FileName, Pos}; use std::io; use std::ops::Range; diff --git a/clippy_lints/src/loops/needless_collect.rs b/clippy_lints/src/loops/needless_collect.rs index 06190850bb00..c7772e483adb 100644 --- a/clippy_lints/src/loops/needless_collect.rs +++ b/clippy_lints/src/loops/needless_collect.rs @@ -6,7 +6,7 @@ use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::{can_move_expr_to_closure, is_trait_method, path_to_local, path_to_local_id, CaptureKind}; use if_chain::if_chain; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::Applicability; +use rustc_errors::{Applicability, MultiSpan}; use rustc_hir::intravisit::{walk_block, walk_expr, Visitor}; use rustc_hir::{Block, Expr, ExprKind, HirId, HirIdSet, Local, Mutability, Node, PatKind, Stmt, StmtKind}; use rustc_lint::LateContext; @@ -14,7 +14,7 @@ use rustc_middle::hir::nested_filter; use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::{self, Ty}; use rustc_span::sym; -use rustc_span::{MultiSpan, Span}; +use rustc_span::Span; const NEEDLESS_COLLECT_MSG: &str = "avoid using `collect()` when not needed"; diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 9d4313827f7c..5f453dc16555 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -5,7 +5,7 @@ use clippy_utils::source::snippet_opt; use clippy_utils::ty::expr_sig; use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_id, path_to_local, paths}; use if_chain::if_chain; -use rustc_errors::Applicability; +use rustc_errors::{Applicability, MultiSpan}; use rustc_hir::def_id::DefId; use rustc_hir::hir_id::HirIdMap; use rustc_hir::intravisit::{walk_expr, Visitor}; @@ -19,8 +19,8 @@ use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; +use rustc_span::sym; use rustc_span::symbol::Symbol; -use rustc_span::{sym, MultiSpan}; use std::fmt; use std::iter; diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs index 625a53899df9..b142397f71b9 100644 --- a/clippy_utils/src/diagnostics.rs +++ b/clippy_utils/src/diagnostics.rs @@ -8,10 +8,10 @@ //! Thank you! //! ~The `INTERNAL_METADATA_COLLECTOR` lint -use rustc_errors::{emitter::MAX_SUGGESTION_HIGHLIGHT_LINES, Applicability, Diagnostic}; +use rustc_errors::{emitter::MAX_SUGGESTION_HIGHLIGHT_LINES, Applicability, Diagnostic, MultiSpan}; use rustc_hir::HirId; use rustc_lint::{LateContext, Lint, LintContext}; -use rustc_span::source_map::{MultiSpan, Span}; +use rustc_span::source_map::Span; use std::env; fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) { @@ -155,7 +155,13 @@ where }); } -pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) { +pub fn span_lint_hir( + cx: &LateContext<'_>, + lint: &'static Lint, + hir_id: HirId, + sp: Span, + msg: &str, +) { cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| { let mut diag = diag.build(msg); docs_link(&mut diag, lint); @@ -272,9 +278,14 @@ pub fn span_lint_and_sugg_for_edges( let sugg_lines_count = sugg.lines().count(); if sugg_lines_count > MAX_SUGGESTION_HIGHLIGHT_LINES { let sm = cx.sess().source_map(); - if let (Ok(line_upper), Ok(line_bottom)) = (sm.lookup_line(sp.lo()), sm.lookup_line(sp.hi())) { + if let (Ok(line_upper), Ok(line_bottom)) = + (sm.lookup_line(sp.lo()), sm.lookup_line(sp.hi())) + { let split_idx = MAX_SUGGESTION_HIGHLIGHT_LINES / 2; - let span_upper = sm.span_until_char(sp.with_hi(line_upper.sf.lines[line_upper.line + split_idx]), '\n'); + let span_upper = sm.span_until_char( + sp.with_hi(line_upper.sf.lines[line_upper.line + split_idx]), + '\n', + ); let span_bottom = sp.with_lo(line_bottom.sf.lines[line_bottom.line - split_idx]); let sugg_lines_vec = sugg.lines().collect::>(); From 4ebe6e4d2a0eeb05ea9e2fb37833f4e701a67864 Mon Sep 17 00:00:00 2001 From: David Wood Date: Sat, 26 Mar 2022 07:27:43 +0000 Subject: [PATCH 0457/1222] errors: implement fallback diagnostic translation This commit updates the signatures of all diagnostic functions to accept types that can be converted into a `DiagnosticMessage`. This enables existing diagnostic calls to continue to work as before and Fluent identifiers to be provided. The `SessionDiagnostic` derive just generates normal diagnostic calls, so these APIs had to be modified to accept Fluent identifiers. In addition, loading of the "fallback" Fluent bundle, which contains the built-in English messages, has been implemented. Each diagnostic now has "arguments" which correspond to variables in the Fluent messages (necessary to render a Fluent message) but no API for adding arguments has been added yet. Therefore, diagnostics (that do not require interpolation) can be converted to use Fluent identifiers and will be output as before. --- clippy_lints/src/collapsible_match.rs | 4 ++-- clippy_lints/src/doc.rs | 12 +++++++++++- clippy_lints/src/loops/needless_collect.rs | 2 +- clippy_lints/src/missing_const_for_fn.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 10 ++++++---- src/driver.rs | 4 +++- 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/collapsible_match.rs b/clippy_lints/src/collapsible_match.rs index acb3c917d624..cc354b50afa3 100644 --- a/clippy_lints/src/collapsible_match.rs +++ b/clippy_lints/src/collapsible_match.rs @@ -130,8 +130,8 @@ fn check_arm<'tcx>( &msg, |diag| { let mut help_span = MultiSpan::from_spans(vec![binding_span, inner_then_pat.span]); - help_span.push_span_label(binding_span, "replace this binding".into()); - help_span.push_span_label(inner_then_pat.span, "with this pattern".into()); + help_span.push_span_label(binding_span, "replace this binding"); + help_span.push_span_label(inner_then_pat.span, "with this pattern"); diag.span_help(help_span, "the outer pattern can be modified to include the inner pattern"); }, ); diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index d67c03714e38..b836363b31b5 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -621,7 +621,17 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { let filename = FileName::anon_source_code(&code); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let emitter = EmitterWriter::new(Box::new(io::sink()), None, false, false, false, None, false); + let fallback_bundle = rustc_errors::fallback_fluent_bundle(); + let emitter = EmitterWriter::new( + Box::new(io::sink()), + None, + fallback_bundle, + false, + false, + false, + None, + false, + ); let handler = Handler::with_emitter(false, None, Box::new(emitter)); let sess = ParseSess::with_span_handler(handler, sm); diff --git a/clippy_lints/src/loops/needless_collect.rs b/clippy_lints/src/loops/needless_collect.rs index c7772e483adb..ddaffc751880 100644 --- a/clippy_lints/src/loops/needless_collect.rs +++ b/clippy_lints/src/loops/needless_collect.rs @@ -102,7 +102,7 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo // Suggest replacing iter_call with iter_replacement, and removing stmt let mut span = MultiSpan::from_span(method_name.ident.span); - span.push_span_label(iter_call.span, "the iterator could be used here instead".into()); + span.push_span_label(iter_call.span, "the iterator could be used here instead"); span_lint_hir_and_then( cx, super::NEEDLESS_COLLECT, diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index ecc9acf4445d..06209bfe7b08 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -148,7 +148,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { if let Err((span, err)) = is_min_const_fn(cx.tcx, mir, self.msrv.as_ref()) { if cx.tcx.is_const_fn_raw(def_id.to_def_id()) { - cx.tcx.sess.span_err(span, &err); + cx.tcx.sess.span_err(span, err.as_ref()); } } else { span_lint(cx, MISSING_CONST_FOR_FN, span, "this could be a `const fn`"); diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 5eb7b0f0521e..d29d07da7b0f 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -235,11 +235,12 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { for (span, suggestion) in clone_spans { diag.span_suggestion( span, - &snippet_opt(cx, span) + snippet_opt(cx, span) .map_or( "change the call to".into(), |x| Cow::from(format!("change `{}` to", x)), - ), + ) + .as_ref(), suggestion.into(), Applicability::Unspecified, ); @@ -264,11 +265,12 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { for (span, suggestion) in clone_spans { diag.span_suggestion( span, - &snippet_opt(cx, span) + snippet_opt(cx, span) .map_or( "change the call to".into(), |x| Cow::from(format!("change `{}` to", x)) - ), + ) + .as_ref(), suggestion.into(), Applicability::Unspecified, ); diff --git a/src/driver.rs b/src/driver.rs index 855a6a6ef6ad..bfce787af5ea 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -165,9 +165,11 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { // Separate the output with an empty line eprintln!(); + let fallback_bundle = rustc_errors::fallback_fluent_bundle(); let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr( rustc_errors::ColorConfig::Auto, None, + fallback_bundle, false, false, None, @@ -191,7 +193,7 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { ]; for note in &xs { - handler.note_without_error(note); + handler.note_without_error(note.as_ref()); } // If backtraces are enabled, also print the query stack From 78c80da4ecd640df5402d3bba52cba701d3b7d38 Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 28 Mar 2022 09:36:20 +0100 Subject: [PATCH 0458/1222] errors: implement sysroot/testing bundle loading Extend loading of Fluent bundles so that bundles can be loaded from the sysroot based on the language requested by the user, or using a nightly flag. Sysroot bundles are loaded from `$sysroot/share/locale/$locale/*.ftl`. Signed-off-by: David Wood --- clippy_lints/src/doc.rs | 4 +++- src/driver.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index b836363b31b5..e08e9e499938 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -621,10 +621,12 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { let filename = FileName::anon_source_code(&code); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let fallback_bundle = rustc_errors::fallback_fluent_bundle(); + let fallback_bundle = rustc_errors::fallback_fluent_bundle() + .expect("failed to load fallback fluent bundle"); let emitter = EmitterWriter::new( Box::new(io::sink()), None, + None, fallback_bundle, false, false, diff --git a/src/driver.rs b/src/driver.rs index bfce787af5ea..f04535b2bea0 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -165,10 +165,12 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { // Separate the output with an empty line eprintln!(); - let fallback_bundle = rustc_errors::fallback_fluent_bundle(); + let fallback_bundle = rustc_errors::fallback_fluent_bundle() + .expect("failed to load fallback fluent bundle"); let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr( rustc_errors::ColorConfig::Auto, None, + None, fallback_bundle, false, false, From 9def598306392c176806094c0cc7b200c5ac2001 Mon Sep 17 00:00:00 2001 From: David Wood Date: Sun, 3 Apr 2022 04:53:01 +0100 Subject: [PATCH 0459/1222] session: opt for enabling directionality markers Add an option for enabling and disabling Fluent's directionality isolation markers in output. Disabled by default as these can render in some terminals and applications. Signed-off-by: David Wood --- clippy_lints/src/doc.rs | 2 +- src/driver.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index e08e9e499938..92cf82bcd6a3 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -621,7 +621,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { let filename = FileName::anon_source_code(&code); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let fallback_bundle = rustc_errors::fallback_fluent_bundle() + let fallback_bundle = rustc_errors::fallback_fluent_bundle(false) .expect("failed to load fallback fluent bundle"); let emitter = EmitterWriter::new( Box::new(io::sink()), diff --git a/src/driver.rs b/src/driver.rs index f04535b2bea0..bc1b0d745755 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -165,7 +165,7 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { // Separate the output with an empty line eprintln!(); - let fallback_bundle = rustc_errors::fallback_fluent_bundle() + let fallback_bundle = rustc_errors::fallback_fluent_bundle(false) .expect("failed to load fallback fluent bundle"); let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr( rustc_errors::ColorConfig::Auto, From d75a70eb13d4f1f7b915b76abaced822d429abf6 Mon Sep 17 00:00:00 2001 From: b-naber Date: Wed, 6 Apr 2022 10:12:42 +0200 Subject: [PATCH 0460/1222] get rid of visit_constant in thir visitor --- clippy_lints/src/matches/overlapping_arms.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/matches/overlapping_arms.rs b/clippy_lints/src/matches/overlapping_arms.rs index b5fa847451d1..c0b3e95b1852 100644 --- a/clippy_lints/src/matches/overlapping_arms.rs +++ b/clippy_lints/src/matches/overlapping_arms.rs @@ -1,4 +1,4 @@ -use clippy_utils::consts::{constant, constant_full_int, FullInt}; +use clippy_utils::consts::{constant, constant_full_int, miri_to_const, FullInt}; use clippy_utils::diagnostics::span_lint_and_note; use core::cmp::Ordering; use rustc_hir::{Arm, Expr, PatKind, RangeEnd}; @@ -32,15 +32,16 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>) .filter_map(|arm| { if let Arm { pat, guard: None, .. } = *arm { if let PatKind::Range(ref lhs, ref rhs, range_end) = pat.kind { - let lhs_val = match lhs { - Some(lhs) => constant(cx, cx.typeck_results(), lhs)?.0.int_value(cx, ty)?, - None => FullInt::U(ty.numeric_min_val(cx.tcx)?), + let lhs_const = match lhs { + Some(lhs) => constant(cx, cx.typeck_results(), lhs)?.0, + None => miri_to_const(ty.numeric_min_val(cx.tcx)?)?, }; - let rhs_val = match rhs { - Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0.int_value(cx, ty)?, - None => FullInt::U(ty.numeric_max_val(cx.tcx)?), + let rhs_const = match rhs { + Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0, + None => miri_to_const(ty.numeric_max_val(cx.tcx)?)?, }; - + let lhs_val = lhs_const.int_value(cx, ty)?; + let rhs_val = rhs_const.int_value(cx, ty)?; let rhs_bound = match range_end { RangeEnd::Included => EndBound::Included(rhs_val), RangeEnd::Excluded => EndBound::Excluded(rhs_val), From bfc70c157271baf3b089da4d39bad3c27da0457d Mon Sep 17 00:00:00 2001 From: flip1995 Date: Fri, 8 Apr 2022 10:41:55 +0100 Subject: [PATCH 0461/1222] Update Cargo.lock --- clippy_dev/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_dev/Cargo.toml b/clippy_dev/Cargo.toml index c2ebba0683ca..81faa5fe5e14 100644 --- a/clippy_dev/Cargo.toml +++ b/clippy_dev/Cargo.toml @@ -9,7 +9,7 @@ indoc = "1.0" itertools = "0.10.1" opener = "0.5" shell-escape = "0.1" -tempfile = "3.3" +tempfile = "3.2" walkdir = "2.3" [features] From 5fab7bc3e2aa6b0f857ab62a0b0183d9ba6b53ad Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 8 Apr 2022 15:57:44 +0000 Subject: [PATCH 0462/1222] Avoid looking at the internals of Interned directly --- .../src/case_sensitive_file_extension_comparisons.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs index df780747a0c7..a8f9c189adec 100644 --- a/clippy_lints/src/case_sensitive_file_extension_comparisons.rs +++ b/clippy_lints/src/case_sensitive_file_extension_comparisons.rs @@ -1,7 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; use rustc_ast::ast::LitKind; -use rustc_data_structures::intern::Interned; use rustc_hir::{Expr, ExprKind, PathSegment}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; @@ -56,8 +55,8 @@ fn check_case_sensitive_file_extension_comparison(ctx: &LateContext<'_>, expr: & ty::Str => { return Some(span); }, - ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did, .. }, _)), _) => { - if ctx.tcx.is_diagnostic_item(sym::String, did) { + ty::Adt(def, _) => { + if ctx.tcx.is_diagnostic_item(sym::String, def.did()) { return Some(span); } }, From 66883ef3200081ae6e3257aa3fdf91ec3627b3d6 Mon Sep 17 00:00:00 2001 From: Miguel Guarniz Date: Sun, 3 Apr 2022 15:50:33 -0400 Subject: [PATCH 0463/1222] Refactor HIR item-like traversal (part 1) - Create hir_crate_items query which traverses tcx.hir_crate(()).owners to return a hir::ModuleItems - use tcx.hir_crate_items in tcx.hir().items() to return an iterator of hir::ItemId - add par_items(impl Fn(hir::ItemId)) to traverse all items in parallel Signed-off-by: Miguel Guarniz --- clippy_lints/src/same_name_method.rs | 3 ++- tests/ui/same_name_method.stderr | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/same_name_method.rs b/clippy_lints/src/same_name_method.rs index 22b458969551..c76061867145 100644 --- a/clippy_lints/src/same_name_method.rs +++ b/clippy_lints/src/same_name_method.rs @@ -50,7 +50,8 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod { fn check_crate_post(&mut self, cx: &LateContext<'tcx>) { let mut map = FxHashMap::::default(); - for item in cx.tcx.hir().items() { + for id in cx.tcx.hir().items() { + let item = cx.tcx.hir().item(id); if let ItemKind::Impl(Impl { items, of_trait, diff --git a/tests/ui/same_name_method.stderr b/tests/ui/same_name_method.stderr index c32c3dd9880f..cf06eb32e0c7 100644 --- a/tests/ui/same_name_method.stderr +++ b/tests/ui/same_name_method.stderr @@ -11,6 +11,19 @@ note: existing `foo` defined here LL | fn foo() {} | ^^^^^^^^^^^ +error: method's name is the same as an existing method in a trait + --> $DIR/same_name_method.rs:34:13 + | +LL | fn clone() {} + | ^^^^^^^^^^^^^ + | +note: existing `clone` defined here + --> $DIR/same_name_method.rs:30:18 + | +LL | #[derive(Clone)] + | ^^^^^ + = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) + error: method's name is the same as an existing method in a trait --> $DIR/same_name_method.rs:44:13 | @@ -47,18 +60,5 @@ note: existing `foo` defined here LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ -error: method's name is the same as an existing method in a trait - --> $DIR/same_name_method.rs:34:13 - | -LL | fn clone() {} - | ^^^^^^^^^^^^^ - | -note: existing `clone` defined here - --> $DIR/same_name_method.rs:30:18 - | -LL | #[derive(Clone)] - | ^^^^^ - = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) - error: aborting due to 5 previous errors From ed214a9d11ce4f2d6799df34df3acb0ef086600f Mon Sep 17 00:00:00 2001 From: Miguel Guarniz Date: Thu, 7 Apr 2022 16:47:40 -0400 Subject: [PATCH 0464/1222] remove CheckVisitor, CollectExternCrateVisitor and ItemLikeVisitor impls Signed-off-by: Miguel Guarniz --- clippy_lints/src/same_name_method.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clippy_lints/src/same_name_method.rs b/clippy_lints/src/same_name_method.rs index c76061867145..a01e2f2db3af 100644 --- a/clippy_lints/src/same_name_method.rs +++ b/clippy_lints/src/same_name_method.rs @@ -51,6 +51,10 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod { let mut map = FxHashMap::::default(); for id in cx.tcx.hir().items() { + if !matches!(cx.tcx.hir().def_kind(id.def_id), DefKind::Impl) { + continue; + } + let item = cx.tcx.hir().item(id); if let ItemKind::Impl(Impl { items, From 1228f11163264dfbc099cfd0b9d589f4d29cf071 Mon Sep 17 00:00:00 2001 From: Jakob Degen Date: Tue, 5 Apr 2022 17:14:59 -0400 Subject: [PATCH 0465/1222] Add new `Deinit` statement kind --- clippy_utils/src/qualify_min_const_fn.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 891531951c1a..fe4112204848 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -211,7 +211,8 @@ fn check_statement<'tcx>( StatementKind::FakeRead(box (_, place)) => check_place(tcx, *place, span, body), // just an assignment - StatementKind::SetDiscriminant { place, .. } => check_place(tcx, **place, span, body), + StatementKind::SetDiscriminant { place, .. } | StatementKind::Deinit(place) => + check_place(tcx, **place, span, body), StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping { dst, src, count }) => { check_operand(tcx, dst, span, body)?; From c537fab01c915830df9d980d77a8c4aca8b1437f Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 12 Apr 2022 09:34:40 +0100 Subject: [PATCH 0466/1222] errors: lazily load fallback fluent bundle Loading the fallback bundle in compilation sessions that won't go on to emit any errors unnecessarily degrades compile time performance, so lazily create the Fluent bundle when it is first required. Signed-off-by: David Wood --- clippy_lints/src/doc.rs | 6 ++++-- src/driver.rs | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 28d0c75fde6b..503cef76775e 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -621,8 +621,10 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { let filename = FileName::anon_source_code(&code); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let fallback_bundle = - rustc_errors::fallback_fluent_bundle(false).expect("failed to load fallback fluent bundle"); + let fallback_bundle = rustc_errors::fallback_fluent_bundle( + rustc_errors::DEFAULT_LOCALE_RESOURCES, + false + ); let emitter = EmitterWriter::new( Box::new(io::sink()), None, diff --git a/src/driver.rs b/src/driver.rs index 00dc916b217c..32a09fdb9d9f 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -165,7 +165,8 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { // Separate the output with an empty line eprintln!(); - let fallback_bundle = rustc_errors::fallback_fluent_bundle(false).expect("failed to load fallback fluent bundle"); + let fallback_bundle = + rustc_errors::fallback_fluent_bundle(rustc_errors::DEFAULT_LOCALE_RESOURCES, false); let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr( rustc_errors::ColorConfig::Auto, None, From 717f0034127ea177956c1565afc7cf69049ed6c1 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Tue, 1 Mar 2022 00:50:56 +0000 Subject: [PATCH 0467/1222] Reimplement lowering of sym operands for asm! so that it also works with global_asm! --- clippy_lints/src/loops/never_loop.rs | 7 ++++--- clippy_lints/src/utils/inspector.rs | 23 ++++++++++++++++++++--- clippy_utils/src/hir_utils.rs | 3 ++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index a0b2302662e6..9ba9642fcc83 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -169,13 +169,14 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { .iter() .map(|(o, _)| match o { InlineAsmOperand::In { expr, .. } - | InlineAsmOperand::InOut { expr, .. } - | InlineAsmOperand::Sym { expr } => never_loop_expr(expr, main_loop_id), + | InlineAsmOperand::InOut { expr, .. } => never_loop_expr(expr, main_loop_id), InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter(), main_loop_id), InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { never_loop_expr_all(&mut once(in_expr).chain(out_expr.iter()), main_loop_id) }, - InlineAsmOperand::Const { .. } => NeverLoopResult::Otherwise, + InlineAsmOperand::Const { .. } + | InlineAsmOperand::SymFn { .. } + | InlineAsmOperand::SymStatic { .. } => NeverLoopResult::Otherwise, }) .fold(NeverLoopResult::Otherwise, combine_both), ExprKind::Struct(_, _, None) diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index dc48ea3f4f99..a04288e0a413 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -281,8 +281,9 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { for (op, _op_sp) in asm.operands { match op { hir::InlineAsmOperand::In { expr, .. } - | hir::InlineAsmOperand::InOut { expr, .. } - | hir::InlineAsmOperand::Sym { expr } => print_expr(cx, expr, indent + 1), + | hir::InlineAsmOperand::InOut { expr, .. } => { + print_expr(cx, expr, indent + 1); + } hir::InlineAsmOperand::Out { expr, .. } => { if let Some(expr) = expr { print_expr(cx, expr, indent + 1); @@ -294,10 +295,26 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { print_expr(cx, out_expr, indent + 1); } }, - hir::InlineAsmOperand::Const { anon_const } => { + hir::InlineAsmOperand::Const { anon_const } + | hir::InlineAsmOperand::SymFn { anon_const } => { println!("{}anon_const:", ind); print_expr(cx, &cx.tcx.hir().body(anon_const.body).value, indent + 1); }, + hir::InlineAsmOperand::SymStatic { path, .. } => { + match path { + hir::QPath::Resolved(ref ty, path) => { + println!("{}Resolved Path, {:?}", ind, ty); + println!("{}path: {:?}", ind, path); + }, + hir::QPath::TypeRelative(ty, seg) => { + println!("{}Relative Path, {:?}", ind, ty); + println!("{}seg: {:?}", ind, seg); + }, + hir::QPath::LangItem(lang_item, ..) => { + println!("{}Lang Item Path, {:?}", ind, lang_item.name()); + }, + } + } } } }, diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 00594f4d42ad..c05317f59b71 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -675,7 +675,8 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } }, InlineAsmOperand::Const { anon_const } => self.hash_body(anon_const.body), - InlineAsmOperand::Sym { expr } => self.hash_expr(expr), + InlineAsmOperand::SymFn { anon_const } => self.hash_body(anon_const.body), + InlineAsmOperand::SymStatic { path, def_id: _ } => self.hash_qpath(path), } } }, From 35d7cae7f53849bebbcdeac421d1d96f082d5584 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Thu, 14 Apr 2022 23:42:15 +0300 Subject: [PATCH 0468/1222] Update issue-92893.stderr --- clippy_lints/src/loops/needless_range_loop.rs | 4 ++-- clippy_lints/src/shadow.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 72e86804ed2c..6ed141fa4a5a 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -59,7 +59,7 @@ pub(super) fn check<'tcx>( if let Some(indexed_extent) = indexed_extent { let parent_def_id = cx.tcx.hir().get_parent_item(expr.hir_id); let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id); - let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id); + let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id).unwrap(); if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) { return; } @@ -262,7 +262,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { match res { Res::Local(hir_id) => { let parent_def_id = self.cx.tcx.hir().get_parent_item(expr.hir_id); - let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id); + let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id).unwrap(); if index_used_directly { self.indexed_directly.insert( seqvar.segments[0].ident.name, diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 118825850446..1ab7f52110ce 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -160,8 +160,8 @@ impl<'tcx> LateLintPass<'tcx> for Shadow { fn is_shadow(cx: &LateContext<'_>, owner: LocalDefId, first: ItemLocalId, second: ItemLocalId) -> bool { let scope_tree = cx.tcx.region_scope_tree(owner.to_def_id()); - let first_scope = scope_tree.var_scope(first); - let second_scope = scope_tree.var_scope(second); + let first_scope = scope_tree.var_scope(first).unwrap(); + let second_scope = scope_tree.var_scope(second).unwrap(); scope_tree.is_subscope_of(second_scope, first_scope) } From 2157b006458fad11ef0b7c65c818b85d74624ea8 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 15 Apr 2022 16:52:58 +0300 Subject: [PATCH 0469/1222] clippy: Update full path to `CString` --- clippy_utils/src/paths.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index 79e6e92dc0aa..e5fa6deefc5d 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -23,7 +23,7 @@ pub const BTREEMAP_ENTRY: [&str; 6] = ["alloc", "collections", "btree", "map", " pub const BTREEMAP_INSERT: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "insert"]; pub const CLONE_TRAIT_METHOD: [&str; 4] = ["core", "clone", "Clone", "clone"]; pub const COW: [&str; 3] = ["alloc", "borrow", "Cow"]; -pub const CSTRING_AS_C_STR: [&str; 5] = ["std", "ffi", "c_str", "CString", "as_c_str"]; +pub const CSTRING_AS_C_STR: [&str; 5] = ["alloc", "ffi", "c_str", "CString", "as_c_str"]; pub const DEFAULT_TRAIT_METHOD: [&str; 4] = ["core", "default", "Default", "default"]; pub const DEREF_MUT_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "DerefMut", "deref_mut"]; /// Preferably use the diagnostic item `sym::deref_method` where possible From ade24abd5455e06bb5b155539c95baa91103286a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 1 Apr 2022 19:18:10 +0200 Subject: [PATCH 0470/1222] Bless clippy. --- tests/ui/unused_unit.stderr | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/ui/unused_unit.stderr b/tests/ui/unused_unit.stderr index 02038b5fb6b5..0d2cb77855be 100644 --- a/tests/ui/unused_unit.stderr +++ b/tests/ui/unused_unit.stderr @@ -1,8 +1,8 @@ error: unneeded unit return type - --> $DIR/unused_unit.rs:19:28 + --> $DIR/unused_unit.rs:19:58 | LL | pub fn get_unit (), G>(&self, f: F, _g: G) -> () - | ^^^^^^ help: remove the `-> ()` + | ^^^^^^ help: remove the `-> ()` | note: the lint level is defined here --> $DIR/unused_unit.rs:12:9 @@ -11,16 +11,16 @@ LL | #![deny(clippy::unused_unit)] | ^^^^^^^^^^^^^^^^^^^ error: unneeded unit return type - --> $DIR/unused_unit.rs:20:18 + --> $DIR/unused_unit.rs:19:28 | -LL | where G: Fn() -> () { - | ^^^^^^ help: remove the `-> ()` +LL | pub fn get_unit (), G>(&self, f: F, _g: G) -> () + | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> $DIR/unused_unit.rs:19:58 + --> $DIR/unused_unit.rs:20:18 | -LL | pub fn get_unit (), G>(&self, f: F, _g: G) -> () - | ^^^^^^ help: remove the `-> ()` +LL | where G: Fn() -> () { + | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type --> $DIR/unused_unit.rs:21:26 From 8e7bce71a3d4a7aae4e327859d6273458ee8255a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 15 Apr 2022 19:27:53 +0200 Subject: [PATCH 0471/1222] Stop using CRATE_DEF_INDEX. `CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want. --- clippy_lints/src/missing_doc.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index fc0483a929a7..5816a95dcebf 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -10,7 +10,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_ast::ast; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::ty; +use rustc_middle::ty::{self, DefIdTree}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::def_id::CRATE_DEF_ID; use rustc_span::source_map::Span; @@ -114,8 +114,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { hir::ItemKind::Fn(..) => { // ignore main() if it.ident.name == sym::main { - let def_key = cx.tcx.hir().def_key(it.def_id); - if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) { + let at_root = cx.tcx.local_parent(it.def_id) == Some(CRATE_DEF_ID); + if at_root { return; } } From 857b9172d62695a427f68ed96c2148f1fb30641c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 13 Feb 2022 15:40:08 +0100 Subject: [PATCH 0472/1222] Stop visiting visibility. --- clippy_lints/src/cognitive_complexity.rs | 2 +- clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs | 4 ++-- clippy_lints/src/functions/too_many_arguments.rs | 3 +-- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/return_self_not_must_use.rs | 2 +- clippy_lints/src/unused_async.rs | 2 +- clippy_utils/src/lib.rs | 2 +- 8 files changed, 9 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index 85f952375491..2bf7f8689054 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -82,7 +82,7 @@ impl CognitiveComplexity { if rust_cc > self.limit.limit() { let fn_span = match kind { - FnKind::ItemFn(ident, _, _, _) | FnKind::Method(ident, _, _) => ident.span, + FnKind::ItemFn(ident, _, _) | FnKind::Method(ident, _) => ident.span, FnKind::Closure => { let header_span = body_span.with_hi(decl.output.span().lo()); let pos = snippet_opt(cx, header_span).and_then(|snip| { diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index 830e3b32cfa2..565a1c871d75 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -17,8 +17,8 @@ pub(super) fn check_fn<'tcx>( hir_id: hir::HirId, ) { let unsafety = match kind { - intravisit::FnKind::ItemFn(_, _, hir::FnHeader { unsafety, .. }, _) => unsafety, - intravisit::FnKind::Method(_, sig, _) => sig.header.unsafety, + intravisit::FnKind::ItemFn(_, _, hir::FnHeader { unsafety, .. }) => unsafety, + intravisit::FnKind::Method(_, sig) => sig.header.unsafety, intravisit::FnKind::Closure => return, }; diff --git a/clippy_lints/src/functions/too_many_arguments.rs b/clippy_lints/src/functions/too_many_arguments.rs index 3af960491ed0..5c8d8b8e7552 100644 --- a/clippy_lints/src/functions/too_many_arguments.rs +++ b/clippy_lints/src/functions/too_many_arguments.rs @@ -26,9 +26,8 @@ pub(super) fn check_fn( header: hir::FnHeader { abi: Abi::Rust, .. }, .. }, - _, ) - | intravisit::FnKind::ItemFn(_, _, hir::FnHeader { abi: Abi::Rust, .. }, _) => check_arg_number( + | intravisit::FnKind::ItemFn(_, _, hir::FnHeader { abi: Abi::Rust, .. }) => check_arg_number( cx, decl, span.with_hi(decl.output.span().hi()), diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index d29d07da7b0f..9c734221ebce 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -85,7 +85,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { } match kind { - FnKind::ItemFn(.., header, _) => { + FnKind::ItemFn(.., header) => { let attrs = cx.tcx.hir().attrs(hir_id); if header.abi != Abi::Rust || requires_exact_signature(attrs) { return; diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index d59249d7f13d..9af3059a37f9 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -251,7 +251,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { } match kind { - FnKind::ItemFn(.., header, _) => { + FnKind::ItemFn(.., header) => { if header.abi != Abi::Rust { return; } diff --git a/clippy_lints/src/return_self_not_must_use.rs b/clippy_lints/src/return_self_not_must_use.rs index 79f104eac0be..91e5e1e8b289 100644 --- a/clippy_lints/src/return_self_not_must_use.rs +++ b/clippy_lints/src/return_self_not_must_use.rs @@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for ReturnSelfNotMustUse { ) { if_chain! { // We are only interested in methods, not in functions or associated functions. - if matches!(kind, FnKind::Method(_, _, _)); + if matches!(kind, FnKind::Method(_, _)); if let Some(fn_def) = cx.tcx.hir().opt_local_def_id(hir_id); if let Some(impl_def) = cx.tcx.impl_of_method(fn_def.to_def_id()); // We don't want this method to be te implementation of a trait because the diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index 2b89398ecd6a..41333bb2addf 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync { span: Span, hir_id: HirId, ) { - if let FnKind::ItemFn(_, _, FnHeader { asyncness, .. }, _) = &fn_kind { + if let FnKind::ItemFn(_, _, FnHeader { asyncness, .. }) = &fn_kind { if matches!(asyncness, IsAsync::Async) { let mut visitor = AsyncFnVisitor { cx, found_await: false }; walk_fn(&mut visitor, fn_kind, fn_decl, body.id(), span, hir_id); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index a275bac4ce63..74978720424d 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1690,7 +1690,7 @@ pub fn if_sequence<'tcx>(mut expr: &'tcx Expr<'tcx>) -> (Vec<&'tcx Expr<'tcx>>, /// Checks if the given function kind is an async function. pub fn is_async_fn(kind: FnKind<'_>) -> bool { - matches!(kind, FnKind::ItemFn(_, _, header, _) if header.asyncness == IsAsync::Async) + matches!(kind, FnKind::ItemFn(_, _, header) if header.asyncness == IsAsync::Async) } /// Peels away all the compiler generated code surrounding the body of an async function, From 05d40b7bdb495343ff63bd2ceed817d50cba22c6 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 13 Feb 2022 01:54:13 +0100 Subject: [PATCH 0473/1222] Drop vis in FieldDef. --- clippy_lints/src/exhaustive_items.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/exhaustive_items.rs b/clippy_lints/src/exhaustive_items.rs index b0f50b5c144b..173d41b4b050 100644 --- a/clippy_lints/src/exhaustive_items.rs +++ b/clippy_lints/src/exhaustive_items.rs @@ -78,7 +78,10 @@ impl LateLintPass<'_> for ExhaustiveItems { if !attrs.iter().any(|a| a.has_name(sym::non_exhaustive)); then { let (lint, msg) = if let ItemKind::Struct(ref v, ..) = item.kind { - if v.fields().iter().any(|f| !f.vis.node.is_pub()) { + if v.fields().iter().any(|f| { + let def_id = cx.tcx.hir().local_def_id(f.hir_id); + !cx.tcx.visibility(def_id).is_public() + }) { // skip structs with private fields return; } From 5e64fba3fc528a94ec2afb4b2c737d9cecb3a45c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 13 Feb 2022 10:54:07 +0100 Subject: [PATCH 0474/1222] Drop vis in ImplItem. --- clippy_lints/src/utils/inspector.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index a04288e0a413..dd94a8d64901 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -4,6 +4,7 @@ use clippy_utils::get_attr; use rustc_ast::ast::{Attribute, InlineAsmTemplatePiece}; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_middle::ty; use rustc_session::Session; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -45,14 +46,10 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector { return; } println!("impl item `{}`", item.ident.name); - match item.vis.node { - hir::VisibilityKind::Public => println!("public"), - hir::VisibilityKind::Crate(_) => println!("visible crate wide"), - hir::VisibilityKind::Restricted { path, .. } => println!( - "visible in module `{}`", - rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(path, false)) - ), - hir::VisibilityKind::Inherited => println!("visibility inherited from outer item"), + match cx.tcx.visibility(item.def_id) { + ty::Visibility::Public => println!("public"), + ty::Visibility::Restricted(def_id) => println!("visible in module `{}`", cx.tcx.def_path_str(def_id)), + ty::Visibility::Invisible => println!("invisible"), } match item.kind { hir::ImplItemKind::Const(_, body_id) => { From 903c543f01154a39206c4d332cf1ba8f2f87d4bd Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 13 Feb 2022 11:30:48 +0100 Subject: [PATCH 0475/1222] Drop vis in Item. --- clippy_lints/src/enum_variants.rs | 2 +- clippy_lints/src/redundant_pub_crate.rs | 8 +++++--- clippy_lints/src/utils/inspector.rs | 12 ++++-------- clippy_lints/src/wildcard_imports.rs | 4 +++- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index 1f4353fa4f72..346d03ca5568 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -260,7 +260,7 @@ impl LateLintPass<'_> for EnumVariantNames { } // The `module_name_repetitions` lint should only trigger if the item has the module in its // name. Having the same name is accepted. - if item.vis.node.is_pub() && item_camel.len() > mod_camel.len() { + if cx.tcx.visibility(item.def_id).is_public() && item_camel.len() > mod_camel.len() { let matching = count_match_start(mod_camel, &item_camel); let rmatching = count_match_end(mod_camel, &item_camel); let nchars = mod_camel.chars().count(); diff --git a/clippy_lints/src/redundant_pub_crate.rs b/clippy_lints/src/redundant_pub_crate.rs index 2cee3c14d7f3..e2e2400f8e26 100644 --- a/clippy_lints/src/redundant_pub_crate.rs +++ b/clippy_lints/src/redundant_pub_crate.rs @@ -1,8 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_then; use rustc_errors::Applicability; -use rustc_hir::{Item, ItemKind, VisibilityKind}; +use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty; use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::def_id::CRATE_DEF_ID; declare_clippy_lint! { /// ### What it does @@ -41,7 +43,7 @@ impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]); impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { - if let VisibilityKind::Crate { .. } = item.vis.node { + if cx.tcx.visibility(item.def_id) == ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()) { if !cx.access_levels.is_exported(item.def_id) && self.is_exported.last() == Some(&false) { let span = item.span.with_hi(item.ident.span.hi()); let descr = cx.tcx.def_kind(item.def_id).descr(item.def_id.to_def_id()); @@ -52,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { &format!("pub(crate) {} inside private module", descr), |diag| { diag.span_suggestion( - item.vis.span, + item.vis_span, "consider using", "pub".to_string(), Applicability::MachineApplicable, diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index dd94a8d64901..e4abfd07866a 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -357,14 +357,10 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) { fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) { let did = item.def_id; println!("item `{}`", item.ident.name); - match item.vis.node { - hir::VisibilityKind::Public => println!("public"), - hir::VisibilityKind::Crate(_) => println!("visible crate wide"), - hir::VisibilityKind::Restricted { path, .. } => println!( - "visible in module `{}`", - rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(path, false)) - ), - hir::VisibilityKind::Inherited => println!("visibility inherited from outer item"), + match cx.tcx.visibility(item.def_id) { + ty::Visibility::Public => println!("public"), + ty::Visibility::Restricted(def_id) => println!("visible in module `{}`", cx.tcx.def_path_str(def_id)), + ty::Visibility::Invisible => println!("invisible"), } match item.kind { hir::ItemKind::ExternCrate(ref _renamed_from) => { diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 832da66a5369..2f74eaf3cf5c 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -8,6 +8,7 @@ use rustc_hir::{ Item, ItemKind, PathSegment, UseKind, }; use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::symbol::kw; use rustc_span::{sym, BytePos}; @@ -115,7 +116,8 @@ impl LateLintPass<'_> for WildcardImports { if is_test_module_or_function(cx.tcx, item) { self.test_modules_deep = self.test_modules_deep.saturating_add(1); } - if item.vis.node.is_pub() || item.vis.node.is_pub_restricted() { + let module = cx.tcx.parent_module_from_def_id(item.def_id); + if cx.tcx.visibility(item.def_id) != ty::Visibility::Restricted(module.to_def_id()) { return; } if_chain! { From 71359051058193657c4ddf7a473d9660b9396d9b Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 14 Feb 2022 13:20:47 +0100 Subject: [PATCH 0476/1222] Make clippy inspector more precise. --- clippy_lints/src/utils/inspector.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index e4abfd07866a..37b114a0cfbc 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -48,7 +48,13 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector { println!("impl item `{}`", item.ident.name); match cx.tcx.visibility(item.def_id) { ty::Visibility::Public => println!("public"), - ty::Visibility::Restricted(def_id) => println!("visible in module `{}`", cx.tcx.def_path_str(def_id)), + ty::Visibility::Restricted(def_id) => { + if def_id.is_top_level_module() { + println!("visible crate wide") + } else { + println!("visible in module `{}`", cx.tcx.def_path_str(def_id)) + } + }, ty::Visibility::Invisible => println!("invisible"), } match item.kind { @@ -359,7 +365,13 @@ fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) { println!("item `{}`", item.ident.name); match cx.tcx.visibility(item.def_id) { ty::Visibility::Public => println!("public"), - ty::Visibility::Restricted(def_id) => println!("visible in module `{}`", cx.tcx.def_path_str(def_id)), + ty::Visibility::Restricted(def_id) => { + if def_id.is_top_level_module() { + println!("visible crate wide") + } else { + println!("visible in module `{}`", cx.tcx.def_path_str(def_id)) + } + }, ty::Visibility::Invisible => println!("invisible"), } match item.kind { From 597d24c280f2c3ec89b7cbc0c41f3c5a79d60d90 Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 26 Apr 2022 06:17:33 +0100 Subject: [PATCH 0477/1222] errors: `span_suggestion` takes `impl ToString` Change `span_suggestion` (and variants) to take `impl ToString` rather than `String` for the suggested code, as this simplifies the requirements on the diagnostic derive. Signed-off-by: David Wood --- clippy_lints/src/functions/must_use.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 0709580c8adf..5462d913fb44 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -108,7 +108,7 @@ fn check_needless_must_use( diag.span_suggestion( attr.span, "remove the attribute", - "".into(), + "", Applicability::MachineApplicable, ); }, diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 9c734221ebce..4034079a90c0 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -241,7 +241,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { |x| Cow::from(format!("change `{}` to", x)), ) .as_ref(), - suggestion.into(), + suggestion, Applicability::Unspecified, ); } @@ -271,7 +271,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { |x| Cow::from(format!("change `{}` to", x)) ) .as_ref(), - suggestion.into(), + suggestion, Applicability::Unspecified, ); } From 8441739f4a744a1e7d506844032031330840033d Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 5 Feb 2022 15:26:49 +0100 Subject: [PATCH 0478/1222] Box HIR Generics and Impl. --- clippy_lints/src/new_without_default.rs | 2 +- clippy_lints/src/partialeq_ne_impl.rs | 2 +- clippy_lints/src/serde_api.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 9419056be143..96c00c205ff2 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { .. }) = item.kind { - for assoc_item in items { + for assoc_item in *items { if assoc_item.kind == (hir::AssocItemKind::Fn { has_self: false }) { let impl_item = cx.tcx.hir().impl_item(assoc_item.id); if in_external_macro(cx.sess(), impl_item.span) { diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index e827cdaae872..1469cb434c00 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -42,7 +42,7 @@ impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl { if let Some(eq_trait) = cx.tcx.lang_items().eq_trait(); if trait_ref.path.res.def_id() == eq_trait; then { - for impl_item in impl_items { + for impl_item in *impl_items { if impl_item.ident.name == sym::ne { span_lint_hir( cx, diff --git a/clippy_lints/src/serde_api.rs b/clippy_lints/src/serde_api.rs index 398e2c200de3..fc1c2af9257b 100644 --- a/clippy_lints/src/serde_api.rs +++ b/clippy_lints/src/serde_api.rs @@ -36,7 +36,7 @@ impl<'tcx> LateLintPass<'tcx> for SerdeApi { if did == visit_did { let mut seen_str = None; let mut seen_string = None; - for item in items { + for item in *items { match item.ident.as_str() { "visit_str" => seen_str = Some(item.span), "visit_string" => seen_string = Some(item.span), From db641223cd0b2a549e0f83a58773d55bf46364d0 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 5 Feb 2022 15:48:02 +0100 Subject: [PATCH 0479/1222] Inline WhereClause into Generics. --- clippy_lints/src/lifetimes.rs | 8 ++++---- clippy_lints/src/trait_bounds.rs | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index b09c23f31e97..4ec7c2362f08 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -8,7 +8,7 @@ use rustc_hir::FnRetTy::Return; use rustc_hir::{ BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, ImplItem, ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, ParamName, PolyTraitRef, TraitBoundModifier, - TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WhereClause, WherePredicate, + TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -130,7 +130,7 @@ fn check_fn_inner<'tcx>( span: Span, report_extra_lifetimes: bool, ) { - if span.from_expansion() || has_where_lifetimes(cx, &generics.where_clause) { + if span.from_expansion() || has_where_lifetimes(cx, generics) { return; } @@ -445,8 +445,8 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { /// Are any lifetimes mentioned in the `where` clause? If so, we don't try to /// reason about elision. -fn has_where_lifetimes<'tcx>(cx: &LateContext<'tcx>, where_clause: &'tcx WhereClause<'_>) -> bool { - for predicate in where_clause.predicates { +fn has_where_lifetimes<'tcx>(cx: &LateContext<'tcx>, generics: &'tcx Generics<'_>) -> bool { + for predicate in generics.predicates { match *predicate { WherePredicate::RegionPredicate(..) => return true, WherePredicate::BoundPredicate(ref pred) => { diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 43e0132a7ec7..c388d2854cc2 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -90,10 +90,9 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { } fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'tcx>) { - let Generics { where_clause, .. } = &item.generics; let mut self_bounds_map = FxHashMap::default(); - for predicate in where_clause.predicates { + for predicate in item.generics.predicates { if_chain! { if let WherePredicate::BoundPredicate(ref bound_predicate) = predicate; if !bound_predicate.span.from_expansion(); @@ -166,7 +165,7 @@ impl TraitBounds { } let mut map: UnhashMap, Vec<&GenericBound<'_>>> = UnhashMap::default(); let mut applicability = Applicability::MaybeIncorrect; - for bound in gen.where_clause.predicates { + for bound in gen.predicates { if_chain! { if let WherePredicate::BoundPredicate(ref p) = bound; if p.bounds.len() as u64 <= self.max_trait_bounds; @@ -216,7 +215,7 @@ impl TraitBounds { } fn check_trait_bound_duplication(cx: &LateContext<'_>, gen: &'_ Generics<'_>) { - if gen.span.from_expansion() || gen.params.is_empty() || gen.where_clause.predicates.is_empty() { + if gen.span.from_expansion() || gen.params.is_empty() || gen.predicates.is_empty() { return; } @@ -232,7 +231,7 @@ fn check_trait_bound_duplication(cx: &LateContext<'_>, gen: &'_ Generics<'_>) { } } - for predicate in gen.where_clause.predicates { + for predicate in gen.predicates { if_chain! { if let WherePredicate::BoundPredicate(ref bound_predicate) = predicate; if !bound_predicate.span.from_expansion(); From 2927cf868cd915fdd16e33b028eafc8d0813e1c1 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 7 Feb 2022 22:58:30 +0100 Subject: [PATCH 0480/1222] Store all generic bounds as where predicates. --- clippy_lints/src/lifetimes.rs | 53 ++++++++++++++------------ clippy_lints/src/trait_bounds.rs | 27 +++++-------- clippy_lints/src/types/borrowed_box.rs | 4 +- 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 4ec7c2362f08..662a561f171e 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -139,28 +139,35 @@ fn check_fn_inner<'tcx>( .iter() .filter(|param| matches!(param.kind, GenericParamKind::Type { .. })); for typ in types { - for bound in typ.bounds { - let mut visitor = RefVisitor::new(cx); - walk_param_bound(&mut visitor, bound); - if visitor.lts.iter().any(|lt| matches!(lt, RefLt::Named(_))) { - return; + for pred in generics.bounds_for_param(cx.tcx.hir().local_def_id(typ.hir_id)) { + if pred.in_where_clause { + // has_where_lifetimes checked that this predicate contains no lifetime. + continue; } - if let GenericBound::Trait(ref trait_ref, _) = *bound { - let params = &trait_ref - .trait_ref - .path - .segments - .last() - .expect("a path must have at least one segment") - .args; - if let Some(params) = *params { - let lifetimes = params.args.iter().filter_map(|arg| match arg { - GenericArg::Lifetime(lt) => Some(lt), - _ => None, - }); - for bound in lifetimes { - if bound.name != LifetimeName::Static && !bound.is_elided() { - return; + + for bound in pred.bounds { + let mut visitor = RefVisitor::new(cx); + walk_param_bound(&mut visitor, bound); + if visitor.lts.iter().any(|lt| matches!(lt, RefLt::Named(_))) { + return; + } + if let GenericBound::Trait(ref trait_ref, _) = *bound { + let params = &trait_ref + .trait_ref + .path + .segments + .last() + .expect("a path must have at least one segment") + .args; + if let Some(params) = *params { + let lifetimes = params.args.iter().filter_map(|arg| match arg { + GenericArg::Lifetime(lt) => Some(lt), + _ => None, + }); + for bound in lifetimes { + if bound.name != LifetimeName::Static && !bound.is_elided() { + return; + } } } } @@ -322,9 +329,7 @@ fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxHashSet { let mut allowed_lts = FxHashSet::default(); for par in named_generics.iter() { if let GenericParamKind::Lifetime { .. } = par.kind { - if par.bounds.is_empty() { - allowed_lts.insert(RefLt::Named(par.name.ident().name)); - } + allowed_lts.insert(RefLt::Named(par.name.ident().name)); } } allowed_lts.insert(RefLt::Unnamed); diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index c388d2854cc2..3d1b2ee925bc 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -8,8 +8,7 @@ use rustc_data_structures::unhash::UnhashMap; use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::{ - GenericBound, Generics, Item, ItemKind, Node, ParamName, Path, PathSegment, QPath, TraitItem, Ty, TyKind, - WherePredicate, + GenericBound, Generics, Item, ItemKind, Node, Path, PathSegment, QPath, TraitItem, Ty, TyKind, WherePredicate, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -219,30 +218,19 @@ fn check_trait_bound_duplication(cx: &LateContext<'_>, gen: &'_ Generics<'_>) { return; } - let mut map = FxHashMap::default(); - for param in gen.params { - if let ParamName::Plain(ref ident) = param.name { - let res = param - .bounds - .iter() - .filter_map(get_trait_info_from_bound) - .collect::>(); - map.insert(*ident, res); - } - } - + let mut map = FxHashMap::<_, Vec<_>>::default(); for predicate in gen.predicates { if_chain! { if let WherePredicate::BoundPredicate(ref bound_predicate) = predicate; if !bound_predicate.span.from_expansion(); if let TyKind::Path(QPath::Resolved(_, Path { segments, .. })) = bound_predicate.bounded_ty.kind; if let Some(segment) = segments.first(); - if let Some(trait_resolutions_direct) = map.get(&segment.ident); then { - for (res_where, _, _) in bound_predicate.bounds.iter().filter_map(get_trait_info_from_bound) { - if let Some((_, _, span_direct)) = trait_resolutions_direct + for (res_where, _, span_where) in bound_predicate.bounds.iter().filter_map(get_trait_info_from_bound) { + let trait_resolutions_direct = map.entry(segment.ident).or_default(); + if let Some((_, span_direct)) = trait_resolutions_direct .iter() - .find(|(res_direct, _, _)| *res_direct == res_where) { + .find(|(res_direct, _)| *res_direct == res_where) { span_lint_and_help( cx, TRAIT_DUPLICATION_IN_BOUNDS, @@ -252,6 +240,9 @@ fn check_trait_bound_duplication(cx: &LateContext<'_>, gen: &'_ Generics<'_>) { "consider removing this trait bound", ); } + else { + trait_resolutions_direct.push((res_where, span_where)) + } } } } diff --git a/clippy_lints/src/types/borrowed_box.rs b/clippy_lints/src/types/borrowed_box.rs index 7c06906293b1..f35f44eda567 100644 --- a/clippy_lints/src/types/borrowed_box.rs +++ b/clippy_lints/src/types/borrowed_box.rs @@ -104,8 +104,10 @@ fn get_bounds_if_impl_trait<'tcx>(cx: &LateContext<'tcx>, qpath: &QPath<'_>, id: if let Some(Node::GenericParam(generic_param)) = cx.tcx.hir().get_if_local(did); if let GenericParamKind::Type { synthetic, .. } = generic_param.kind; if synthetic; + if let Some(generics) = cx.tcx.hir().get_generics(id.owner); + if let Some(pred) = generics.bounds_for_param(did.expect_local()).next(); then { - Some(generic_param.bounds) + Some(pred.bounds) } else { None } From 97588c2b376bdcd3f78a7db244598cd1101c9406 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 14 Mar 2022 15:56:37 +0100 Subject: [PATCH 0481/1222] Bless tests. --- tests/ui/extra_unused_lifetimes.stderr | 8 +------- tests/ui/needless_lifetimes.stderr | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/tests/ui/extra_unused_lifetimes.stderr b/tests/ui/extra_unused_lifetimes.stderr index ebdb8e749520..9143fb2c208a 100644 --- a/tests/ui/extra_unused_lifetimes.stderr +++ b/tests/ui/extra_unused_lifetimes.stderr @@ -6,12 +6,6 @@ LL | fn unused_lt<'a>(x: u8) {} | = note: `-D clippy::extra-unused-lifetimes` implied by `-D warnings` -error: this lifetime isn't used in the function definition - --> $DIR/extra_unused_lifetimes.rs:16:25 - | -LL | fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) { - | ^^ - error: this lifetime isn't used in the function definition --> $DIR/extra_unused_lifetimes.rs:41:10 | @@ -24,5 +18,5 @@ error: this lifetime isn't used in the function definition LL | fn unused_lt<'a>(x: u8) {} | ^^ -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors diff --git a/tests/ui/needless_lifetimes.stderr b/tests/ui/needless_lifetimes.stderr index ffa152427a97..a488bc01fffa 100644 --- a/tests/ui/needless_lifetimes.stderr +++ b/tests/ui/needless_lifetimes.stderr @@ -108,12 +108,6 @@ error: explicit lifetimes given in parameter types where they could be elided (o LL | fn baz<'a>(&'a self) -> impl Foo + 'a { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) - --> $DIR/needless_lifetimes.rs:307:5 - | -LL | fn impl_trait_elidable_nested_named_lifetimes<'a>(i: &'a i32, f: impl for<'b> Fn(&'b i32) -> &'b i32) -> &'a i32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) --> $DIR/needless_lifetimes.rs:310:5 | @@ -192,5 +186,5 @@ error: explicit lifetimes given in parameter types where they could be elided (o LL | fn lifetime_elsewhere_provided<'a>(self: Box, here: &'a ()) -> &'a () { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 32 previous errors +error: aborting due to 31 previous errors From 283bfc1229f1e04c8a032ece4df14a1515972468 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 24 Apr 2022 19:08:23 -0700 Subject: [PATCH 0482/1222] Fix the clippy build --- clippy_utils/src/sugg.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 1fc9979f3dd7..794d2e1026f8 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -214,6 +214,7 @@ impl<'a> Sugg<'a> { | ast::ExprKind::Path(..) | ast::ExprKind::Repeat(..) | ast::ExprKind::Ret(..) + | ast::ExprKind::Yeet(..) | ast::ExprKind::Struct(..) | ast::ExprKind::Try(..) | ast::ExprKind::TryBlock(..) From 925953081ea0d942a595220bdc239fc8da5ee85a Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 25 Apr 2022 22:08:45 +0300 Subject: [PATCH 0483/1222] rustc: Panic by default in `DefIdTree::parent` Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root. So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root. Same applies to `local_parent`/`opt_local_parent`. --- clippy_lints/src/matches/redundant_pattern_match.rs | 2 +- clippy_lints/src/methods/bind_instead_of_map.rs | 8 ++++---- clippy_lints/src/methods/chars_cmp.rs | 2 +- clippy_lints/src/methods/option_map_or_none.rs | 2 +- clippy_lints/src/missing_doc.rs | 2 +- clippy_utils/src/lib.rs | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/matches/redundant_pattern_match.rs b/clippy_lints/src/matches/redundant_pattern_match.rs index 777ec9b75bc2..aa3552001f46 100644 --- a/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/clippy_lints/src/matches/redundant_pattern_match.rs @@ -193,7 +193,7 @@ fn find_sugg_for_if_let<'tcx>( PatKind::TupleStruct(ref qpath, [sub_pat], _) => { if let PatKind::Wild = sub_pat.kind { let res = cx.typeck_results().qpath_res(qpath, check_pat.hir_id); - let Some(id) = res.opt_def_id().and_then(|ctor_id| cx.tcx.parent(ctor_id)) else { return }; + let Some(id) = res.opt_def_id().map(|ctor_id| cx.tcx.parent(ctor_id)) else { return }; let lang_items = cx.tcx.lang_items(); if Some(id) == lang_items.result_ok_variant() { ("is_ok()", try_get_generic_ty(op_ty, 0).unwrap_or(op_ty)) diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs index eec232e6d098..b88ec0963f2b 100644 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/clippy_lints/src/methods/bind_instead_of_map.rs @@ -42,7 +42,7 @@ pub(crate) trait BindInsteadOfMap { fn no_op_msg(cx: &LateContext<'_>) -> Option { let variant_id = cx.tcx.lang_items().require(Self::VARIANT_LANG_ITEM).ok()?; - let item_id = cx.tcx.parent(variant_id)?; + let item_id = cx.tcx.parent(variant_id); Some(format!( "using `{}.{}({})`, which is a no-op", cx.tcx.item_name(item_id), @@ -53,7 +53,7 @@ pub(crate) trait BindInsteadOfMap { fn lint_msg(cx: &LateContext<'_>) -> Option { let variant_id = cx.tcx.lang_items().require(Self::VARIANT_LANG_ITEM).ok()?; - let item_id = cx.tcx.parent(variant_id)?; + let item_id = cx.tcx.parent(variant_id); Some(format!( "using `{}.{}(|x| {}(y))`, which is more succinctly expressed as `{}(|x| y)`", cx.tcx.item_name(item_id), @@ -145,7 +145,7 @@ pub(crate) trait BindInsteadOfMap { if_chain! { if let Some(adt) = cx.typeck_results().expr_ty(recv).ty_adt_def(); if let Ok(vid) = cx.tcx.lang_items().require(Self::VARIANT_LANG_ITEM); - if Some(adt.did()) == cx.tcx.parent(vid); + if adt.did() == cx.tcx.parent(vid); then {} else { return false; } } @@ -182,7 +182,7 @@ pub(crate) trait BindInsteadOfMap { fn is_variant(cx: &LateContext<'_>, res: Res) -> bool { if let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Fn), id) = res { if let Ok(variant_id) = cx.tcx.lang_items().require(Self::VARIANT_LANG_ITEM) { - return cx.tcx.parent(id) == Some(variant_id); + return cx.tcx.parent(id) == variant_id; } } false diff --git a/clippy_lints/src/methods/chars_cmp.rs b/clippy_lints/src/methods/chars_cmp.rs index 2cf2c5641bf1..f7b79f0839ba 100644 --- a/clippy_lints/src/methods/chars_cmp.rs +++ b/clippy_lints/src/methods/chars_cmp.rs @@ -19,7 +19,7 @@ pub(super) fn check( if_chain! { if let Some(args) = method_chain_args(info.chain, chain_methods); if let hir::ExprKind::Call(fun, [arg_char]) = info.other.kind; - if let Some(id) = path_def_id(cx, fun).and_then(|ctor_id| cx.tcx.parent(ctor_id)); + if let Some(id) = path_def_id(cx, fun).map(|ctor_id| cx.tcx.parent(ctor_id)); if Some(id) == cx.tcx.lang_items().option_some_variant(); then { let mut applicability = Applicability::MachineApplicable; diff --git a/clippy_lints/src/methods/option_map_or_none.rs b/clippy_lints/src/methods/option_map_or_none.rs index 2a5ab6e625c1..76bc9466ed81 100644 --- a/clippy_lints/src/methods/option_map_or_none.rs +++ b/clippy_lints/src/methods/option_map_or_none.rs @@ -75,7 +75,7 @@ pub(super) fn check<'tcx>( let arg_snippet = snippet(cx, span, ".."); let body = cx.tcx.hir().body(id); if let Some((func, [arg_char])) = reduce_unit_expression(&body.value); - if let Some(id) = path_def_id(cx, func).and_then(|ctor_id| cx.tcx.parent(ctor_id)); + if let Some(id) = path_def_id(cx, func).map(|ctor_id| cx.tcx.parent(ctor_id)); if Some(id) == cx.tcx.lang_items().option_some_variant(); then { let func_snippet = snippet(cx, arg_char.span, ".."); diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 5816a95dcebf..a20377f320b2 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { hir::ItemKind::Fn(..) => { // ignore main() if it.ident.name == sym::main { - let at_root = cx.tcx.local_parent(it.def_id) == Some(CRATE_DEF_ID); + let at_root = cx.tcx.local_parent(it.def_id) == CRATE_DEF_ID; if at_root { return; } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 74978720424d..7d46952d9718 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -235,7 +235,7 @@ pub fn is_lang_ctor(cx: &LateContext<'_>, qpath: &QPath<'_>, lang_item: LangItem if let QPath::Resolved(_, path) = qpath { if let Res::Def(DefKind::Ctor(..), ctor_id) = path.res { if let Ok(item_id) = cx.tcx.lang_items().require(lang_item) { - return cx.tcx.parent(ctor_id) == Some(item_id); + return cx.tcx.parent(ctor_id) == item_id; } } } From 8049cd63a4ac5ebfc8794a9e659a70856cb54f92 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 29 Apr 2022 18:48:58 +0200 Subject: [PATCH 0484/1222] Make rustc_parse_format compile on stable This allows it to be used by lightweight formatting systems and may allow it to be used by rust-analyzer. --- clippy_lints/src/write.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index f3d818cc3485..54b93a20a057 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -13,7 +13,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_parse::parser; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::symbol::{kw, Symbol}; -use rustc_span::{sym, BytePos, Span, DUMMY_SP}; +use rustc_span::{sym, BytePos, InnerSpan, Span, DUMMY_SP}; declare_clippy_lint! { /// ### What it does @@ -454,6 +454,7 @@ impl SimpleFormatArgs { } }, ArgumentNamed(n, _) => { + let n = Symbol::intern(n); if let Some(x) = self.named.iter_mut().find(|x| x.0 == n) { match x.1.as_slice() { // A non-empty format string has been seen already. @@ -495,7 +496,7 @@ impl Write { let span = parser .arg_places .last() - .map_or(DUMMY_SP, |&x| str_lit.span.from_inner(x)); + .map_or(DUMMY_SP, |&x| str_lit.span.from_inner(InnerSpan::new(x.start, x.end))); if !self.in_debug_impl && arg.format.ty == "?" { // FIXME: modify rustc's fmt string parser to give us the current span From 29837e45a5d058ea1b69a714789f381815056dbb Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 29 Apr 2022 06:52:01 +1000 Subject: [PATCH 0485/1222] Overhaul `MacArgs::Eq`. The value in `MacArgs::Eq` is currently represented as a `Token`. Because of `TokenKind::Interpolated`, `Token` can be either a token or an arbitrary AST fragment. In practice, a `MacArgs::Eq` starts out as a literal or macro call AST fragment, and then is later lowered to a literal token. But this is very non-obvious. `Token` is a much more general type than what is needed. This commit restricts things, by introducing a new type `MacArgsEqKind` that is either an AST expression (pre-lowering) or an AST literal (post-lowering). The downside is that the code is a bit more verbose in a few places. The benefit is that makes it much clearer what the possibilities are (though also shorter in some other places). Also, it removes one use of `TokenKind::Interpolated`, taking us a step closer to removing that variant, which will let us make `Token` impl `Copy` and remove many "handle Interpolated" code paths in the parser. Things to note: - Error messages have improved. Messages like this: ``` unexpected token: `"bug" + "found"` ``` now say "unexpected expression", which makes more sense. Although arbitrary expressions can exist within tokens thanks to `TokenKind::Interpolated`, that's not obvious to anyone who doesn't know compiler internals. - In `parse_mac_args_common`, we no longer need to collect tokens for the value expression. --- clippy_utils/src/ast_utils.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 3fce4987679a..7919800483f5 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -688,7 +688,8 @@ pub fn eq_mac_args(l: &MacArgs, r: &MacArgs) -> bool { match (l, r) { (Empty, Empty) => true, (Delimited(_, ld, lts), Delimited(_, rd, rts)) => ld == rd && lts.eq_unspanned(rts), - (Eq(_, lt), Eq(_, rt)) => lt.kind == rt.kind, + (Eq(_, MacArgsEq::Ast(le)), Eq(_, MacArgsEq::Ast(re))) => eq_expr(le, re), + (Eq(_, MacArgsEq::Hir(ll)), Eq(_, MacArgsEq::Hir(rl))) => ll.kind == rl.kind, _ => false, } } From 016009492e807c21090a544d9c9660f4bb44a454 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Thu, 5 May 2022 14:27:11 +0100 Subject: [PATCH 0486/1222] Bless clippy error msg --- tests/ui/indexing_slicing_index.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/indexing_slicing_index.stderr b/tests/ui/indexing_slicing_index.stderr index 83a36f407d5d..6ae700753f06 100644 --- a/tests/ui/indexing_slicing_index.stderr +++ b/tests/ui/indexing_slicing_index.stderr @@ -1,4 +1,4 @@ -error[E0080]: evaluation of `main::{constant#3}::<&i32>` failed +error[E0080]: evaluation of `main::{constant#3}` failed --> $DIR/indexing_slicing_index.rs:31:14 | LL | const { &ARR[idx4()] }; // Ok, let rustc handle const contexts. From 03a24cea410c3d4d83a6ff074fb880935e7233b6 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 5 May 2022 15:20:07 +0100 Subject: [PATCH 0487/1222] (Partially) Revert "HACK: Move buggy lints to nursery" This reverts commit bb01aca86f66954b80798213711e8eadc4b26902. Partial: Keep regression tests --- clippy_lints/src/lib.register_nursery.rs | 2 -- clippy_lints/src/lib.register_pedantic.rs | 2 ++ clippy_lints/src/trait_bounds.rs | 4 ++-- tests/ui/trait_duplication_in_bounds.stderr | 10 +--------- tests/ui/type_repetition_in_bounds.stderr | 10 +--------- 5 files changed, 6 insertions(+), 22 deletions(-) diff --git a/clippy_lints/src/lib.register_nursery.rs b/clippy_lints/src/lib.register_nursery.rs index ec187563b3f6..18904a945389 100644 --- a/clippy_lints/src/lib.register_nursery.rs +++ b/clippy_lints/src/lib.register_nursery.rs @@ -28,8 +28,6 @@ store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![ LintId::of(strings::STRING_LIT_AS_BYTES), LintId::of(suspicious_operation_groupings::SUSPICIOUS_OPERATION_GROUPINGS), LintId::of(trailing_empty_array::TRAILING_EMPTY_ARRAY), - LintId::of(trait_bounds::TRAIT_DUPLICATION_IN_BOUNDS), - LintId::of(trait_bounds::TYPE_REPETITION_IN_BOUNDS), LintId::of(transmute::TRANSMUTE_UNDEFINED_REPR), LintId::of(transmute::USELESS_TRANSMUTE), LintId::of(use_self::USE_SELF), diff --git a/clippy_lints/src/lib.register_pedantic.rs b/clippy_lints/src/lib.register_pedantic.rs index 2ee2c6e3358c..63232fd41130 100644 --- a/clippy_lints/src/lib.register_pedantic.rs +++ b/clippy_lints/src/lib.register_pedantic.rs @@ -84,6 +84,8 @@ store.register_group(true, "clippy::pedantic", Some("clippy_pedantic"), vec![ LintId::of(semicolon_if_nothing_returned::SEMICOLON_IF_NOTHING_RETURNED), LintId::of(stable_sort_primitive::STABLE_SORT_PRIMITIVE), LintId::of(strings::STRING_ADD_ASSIGN), + LintId::of(trait_bounds::TRAIT_DUPLICATION_IN_BOUNDS), + LintId::of(trait_bounds::TYPE_REPETITION_IN_BOUNDS), LintId::of(transmute::TRANSMUTE_PTR_TO_PTR), LintId::of(types::LINKEDLIST), LintId::of(types::OPTION_OPTION), diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 78e388a49af1..c0aca2d517cf 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -35,7 +35,7 @@ declare_clippy_lint! { /// ``` #[clippy::version = "1.38.0"] pub TYPE_REPETITION_IN_BOUNDS, - nursery, + pedantic, "Types are repeated unnecessary in trait bounds use `+` instead of using `T: _, T: _`" } @@ -65,7 +65,7 @@ declare_clippy_lint! { /// ``` #[clippy::version = "1.47.0"] pub TRAIT_DUPLICATION_IN_BOUNDS, - nursery, + pedantic, "Check if the same trait bounds are specified twice during a function declaration" } diff --git a/tests/ui/trait_duplication_in_bounds.stderr b/tests/ui/trait_duplication_in_bounds.stderr index d0a4cfb88370..6f8c8e47dfbf 100644 --- a/tests/ui/trait_duplication_in_bounds.stderr +++ b/tests/ui/trait_duplication_in_bounds.stderr @@ -67,13 +67,5 @@ LL | Self: Iterator, | = help: consider removing this trait bound -error: this trait bound is already specified in the where clause - --> $DIR/trait_duplication_in_bounds.rs:99:23 - | -LL | fn impl_trait(_: impl AsRef, _: impl AsRef) {} - | ^^^^^^^^^^ - | - = help: consider removing this trait bound - -error: aborting due to 9 previous errors +error: aborting due to 8 previous errors diff --git a/tests/ui/type_repetition_in_bounds.stderr b/tests/ui/type_repetition_in_bounds.stderr index abc25e59496b..148c19c7d070 100644 --- a/tests/ui/type_repetition_in_bounds.stderr +++ b/tests/ui/type_repetition_in_bounds.stderr @@ -19,13 +19,5 @@ LL | Self: Copy + Default + Ord, | = help: consider combining the bounds: `Self: Clone + Copy + Default + Ord` -error: this type has already been used as a bound predicate - --> $DIR/type_repetition_in_bounds.rs:83:43 - | -LL | fn impl_trait(_: impl AsRef, _: impl AsRef) {} - | ^^^^^^^^^^ - | - = help: consider combining the bounds: `impl AsRef: AsRef + AsRef` - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors From 0ad3e2e00ec61bbbf7241233ca379d765983b1ea Mon Sep 17 00:00:00 2001 From: Miguel Guarniz Date: Fri, 29 Apr 2022 13:11:22 -0400 Subject: [PATCH 0488/1222] use def_span and def_kind queries instead of calling tcx.hir() methods Signed-off-by: Miguel Guarniz --- clippy_lints/src/same_name_method.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/same_name_method.rs b/clippy_lints/src/same_name_method.rs index f63925a2f143..c5c174cc8f61 100644 --- a/clippy_lints/src/same_name_method.rs +++ b/clippy_lints/src/same_name_method.rs @@ -51,14 +51,14 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod { let mut map = FxHashMap::::default(); for id in cx.tcx.hir().items() { - if matches!(cx.tcx.hir().def_kind(id.def_id), DefKind::Impl) + if matches!(cx.tcx.def_kind(id.def_id), DefKind::Impl) && let item = cx.tcx.hir().item(id) && let ItemKind::Impl(Impl { - items, - of_trait, - self_ty, - .. - }) = &item.kind + items, + of_trait, + self_ty, + .. + }) = &item.kind && let TyKind::Path(QPath::Resolved(_, Path { res, .. })) = self_ty.kind { if !map.contains_key(res) { From 248bb288b2e53e380081481602604bdebd98ae09 Mon Sep 17 00:00:00 2001 From: Preston From Date: Fri, 18 Feb 2022 00:02:22 -0600 Subject: [PATCH 0489/1222] Lint for significant drops who may have surprising lifetimes #1 author Preston From 1645164142 -0600 committer Preston From 1650005351 -0600 --- CHANGELOG.md | 1 + clippy_lints/src/lib.register_lints.rs | 1 + clippy_lints/src/lib.register_nursery.rs | 1 + clippy_lints/src/lib.rs | 2 + .../src/significant_drop_in_scrutinee.rs | 408 ++++++++++++++ clippy_utils/src/attrs.rs | 1 + tests/ui/significant_drop_in_scrutinee.rs | 526 ++++++++++++++++++ tests/ui/significant_drop_in_scrutinee.stderr | 261 +++++++++ 8 files changed, 1201 insertions(+) create mode 100644 clippy_lints/src/significant_drop_in_scrutinee.rs create mode 100644 tests/ui/significant_drop_in_scrutinee.rs create mode 100644 tests/ui/significant_drop_in_scrutinee.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 751f9fccd88d..d25ad0ac6fa1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3696,6 +3696,7 @@ Released 2018-09-13 [`skip_while_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#skip_while_next [`slow_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#slow_vector_initialization [`stable_sort_primitive`]: https://rust-lang.github.io/rust-clippy/master/index.html#stable_sort_primitive +[`significant_drop_in_scrutinee`]: https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_in_scrutinee [`str_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#str_to_string [`string_add`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_add [`string_add_assign`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_add_assign diff --git a/clippy_lints/src/lib.register_lints.rs b/clippy_lints/src/lib.register_lints.rs index 5768edc50188..c888a5feda2a 100644 --- a/clippy_lints/src/lib.register_lints.rs +++ b/clippy_lints/src/lib.register_lints.rs @@ -475,6 +475,7 @@ store.register_lints(&[ size_of_in_element_count::SIZE_OF_IN_ELEMENT_COUNT, slow_vector_initialization::SLOW_VECTOR_INITIALIZATION, stable_sort_primitive::STABLE_SORT_PRIMITIVE, + significant_drop_in_scrutinee::SIGNIFICANT_DROP_IN_SCRUTINEE, strings::STRING_ADD, strings::STRING_ADD_ASSIGN, strings::STRING_FROM_UTF8_AS_BYTES, diff --git a/clippy_lints/src/lib.register_nursery.rs b/clippy_lints/src/lib.register_nursery.rs index ec187563b3f6..d43c7e03533c 100644 --- a/clippy_lints/src/lib.register_nursery.rs +++ b/clippy_lints/src/lib.register_nursery.rs @@ -25,6 +25,7 @@ store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![ LintId::of(path_buf_push_overwrite::PATH_BUF_PUSH_OVERWRITE), LintId::of(redundant_pub_crate::REDUNDANT_PUB_CRATE), LintId::of(regex::TRIVIAL_REGEX), + LintId::of(significant_drop_in_scrutinee::SIGNIFICANT_DROP_IN_SCRUTINEE), LintId::of(strings::STRING_LIT_AS_BYTES), LintId::of(suspicious_operation_groupings::SUSPICIOUS_OPERATION_GROUPINGS), LintId::of(trailing_empty_array::TRAILING_EMPTY_ARRAY), diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 3bb821a14829..09071a255c5e 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -364,6 +364,7 @@ mod self_named_constructors; mod semicolon_if_nothing_returned; mod serde_api; mod shadow; +mod significant_drop_in_scrutinee; mod single_char_lifetime_names; mod single_component_path_imports; mod size_of_in_element_count; @@ -874,6 +875,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_late_pass(move || Box::new(manual_bits::ManualBits::new(msrv))); store.register_late_pass(|| Box::new(default_union_representation::DefaultUnionRepresentation)); store.register_late_pass(|| Box::new(only_used_in_recursion::OnlyUsedInRecursion)); + store.register_late_pass(|| Box::new(significant_drop_in_scrutinee::SignificantDropInScrutinee)); store.register_late_pass(|| Box::new(dbg_macro::DbgMacro)); let cargo_ignore_publish = conf.cargo_ignore_publish; store.register_late_pass(move || { diff --git a/clippy_lints/src/significant_drop_in_scrutinee.rs b/clippy_lints/src/significant_drop_in_scrutinee.rs new file mode 100644 index 000000000000..94ae0c8f5a65 --- /dev/null +++ b/clippy_lints/src/significant_drop_in_scrutinee.rs @@ -0,0 +1,408 @@ +use crate::FxHashSet; +use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::get_attr; +use clippy_utils::source::{indent_of, snippet}; +use rustc_errors::{Applicability, Diagnostic}; +use rustc_hir::intravisit::{walk_expr, Visitor}; +use rustc_hir::{Expr, ExprKind}; +use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_middle::ty::subst::GenericArgKind; +use rustc_middle::ty::{Ty, TypeAndMut}; +use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::Span; + +declare_clippy_lint! { + /// ### What it does + /// Check for temporaries returned from function calls in a match scrutinee that have the + /// `clippy::has_significant_drop` attribute. + /// + /// ### Why is this bad? + /// The `clippy::has_significant_drop` attribute can be added to types whose Drop impls have + /// an important side-effect, such as unlocking a mutex, making it important for users to be + /// able to accurately understand their lifetimes. When a temporary is returned in a function + /// call in a match scrutinee, its lifetime lasts until the end of the match block, which may + /// be surprising. + /// + /// For `Mutex`es this can lead to a deadlock. This happens when the match scrutinee uses a + /// function call that returns a `MutexGuard` and then tries to lock again in one of the match + /// arms. In that case the `MutexGuard` in the scrutinee will not be dropped until the end of + /// the match block and thus will not unlock. + /// + /// ### Example + /// ```rust + /// # use std::sync::Mutex; + /// + /// # struct State {} + /// + /// # impl State { + /// # fn foo(&self) -> bool { + /// # true + /// # } + /// + /// # fn bar(&self) {} + /// # } + /// + /// + /// let mutex = Mutex::new(State {}); + /// + /// match mutex.lock().unwrap().foo() { + /// true => { + /// mutex.lock().unwrap().bar(); // Deadlock! + /// } + /// false => {} + /// }; + /// + /// println!("All done!"); + /// + /// ``` + /// Use instead: + /// ```rust + /// # use std::sync::Mutex; + /// + /// # struct State {} + /// + /// # impl State { + /// # fn foo(&self) -> bool { + /// # true + /// # } + /// + /// # fn bar(&self) {} + /// # } + /// + /// let mutex = Mutex::new(State {}); + /// + /// let is_foo = mutex.lock().unwrap().foo(); + /// match is_foo { + /// true => { + /// mutex.lock().unwrap().bar(); + /// } + /// false => {} + /// }; + /// + /// println!("All done!"); + /// ``` + #[clippy::version = "1.60.0"] + pub SIGNIFICANT_DROP_IN_SCRUTINEE, + nursery, + "warns when a temporary of a type with a drop with a significant side-effect might have a surprising lifetime" +} + +declare_lint_pass!(SignificantDropInScrutinee => [SIGNIFICANT_DROP_IN_SCRUTINEE]); + +impl<'tcx> LateLintPass<'tcx> for SignificantDropInScrutinee { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { + if let Some(suggestions) = has_significant_drop_in_scrutinee(cx, expr) { + for found in suggestions { + span_lint_and_then( + cx, + SIGNIFICANT_DROP_IN_SCRUTINEE, + found.found_span, + "temporary with significant drop in match scrutinee", + |diag| set_diagnostic(diag, cx, expr, found), + ) + } + } + } +} + +fn set_diagnostic<'tcx>(diag: &mut Diagnostic, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, found: FoundSigDrop) { + if found.lint_suggestion == LintSuggestion::MoveAndClone { + // If our suggestion is to move and clone, then we want to leave it to the user to + // decide how to address this lint, since it may be that cloning is inappropriate. + // Therefore, we won't to emit a suggestion. + return; + } + + let original = snippet(cx, found.found_span, ".."); + let trailing_indent = " ".repeat(indent_of(cx, found.found_span).unwrap_or(0)); + + let replacement = if found.lint_suggestion == LintSuggestion::MoveAndDerefToCopy { + format!("let value = *{};\n{}", original, trailing_indent) + } else if found.is_unit_return_val { + // If the return value of the expression to be moved is unit, then we don't need to + // capture the result in a temporary -- we can just replace it completely with `()`. + format!("{};\n{}", original, trailing_indent) + } else { + format!("let value = {};\n{}", original, trailing_indent) + }; + + let suggestion_message = if found.lint_suggestion == LintSuggestion::MoveOnly { + "try moving the temporary above the match" + } else { + "try moving the temporary above the match and create a copy" + }; + + let scrutinee_replacement = if found.is_unit_return_val { + "()".to_owned() + } else { + "value".to_owned() + }; + + diag.multipart_suggestion( + suggestion_message, + vec![ + (expr.span.shrink_to_lo(), replacement), + (found.found_span, scrutinee_replacement), + ], + Applicability::MaybeIncorrect, + ); +} + +/// If the expression is an ExprKind::Match, check if the scrutinee has a significant drop that may +/// have a surprising lifetime. +fn has_significant_drop_in_scrutinee<'tcx, 'a>( + cx: &'a LateContext<'tcx>, + expr: &'tcx Expr<'tcx>, +) -> Option> { + let mut helper = SigDropHelper::new(cx); + match expr.kind { + ExprKind::Match(match_expr, _, _) => helper.find_sig_drop(match_expr), + _ => None, + } +} + +struct SigDropHelper<'a, 'tcx> { + cx: &'a LateContext<'tcx>, + is_chain_end: bool, + seen_types: FxHashSet>, + has_significant_drop: bool, + current_sig_drop: Option, + sig_drop_spans: Option>, + special_handling_for_binary_op: bool, +} + +#[derive(Debug, PartialEq, Eq, Clone, Copy)] +enum LintSuggestion { + MoveOnly, + MoveAndDerefToCopy, + MoveAndClone, +} + +#[derive(Clone, Copy)] +struct FoundSigDrop { + found_span: Span, + is_unit_return_val: bool, + lint_suggestion: LintSuggestion, +} + +impl<'a, 'tcx> SigDropHelper<'a, 'tcx> { + fn new(cx: &'a LateContext<'tcx>) -> SigDropHelper<'a, 'tcx> { + SigDropHelper { + cx, + is_chain_end: true, + seen_types: FxHashSet::default(), + has_significant_drop: false, + current_sig_drop: None, + sig_drop_spans: None, + special_handling_for_binary_op: false, + } + } + + fn find_sig_drop(&mut self, match_expr: &'tcx Expr<'_>) -> Option> { + self.visit_expr(match_expr); + + // If sig drop spans is empty but we found a significant drop, it means that we didn't find + // a type that was trivially copyable as we moved up the chain after finding a significant + // drop, so move the entire scrutinee. + if self.has_significant_drop && self.sig_drop_spans.is_none() { + self.try_setting_current_suggestion(match_expr, true); + self.move_current_suggestion(); + } + + self.sig_drop_spans.take() + } + + /// This will try to set the current suggestion (so it can be moved into the suggestions vec + /// later). If allow_move_and_clone is false, the suggestion *won't* be set -- this gives us + /// an opportunity to look for another type in the chain that will be trivially copyable. + /// However, if we are at the the end of the chain, we want to accept whatever is there. (The + /// suggestion won't actually be output, but the diagnostic message will be output, so the user + /// can determine the best way to handle the lint.) + fn try_setting_current_suggestion(&mut self, expr: &'tcx Expr<'_>, allow_move_and_clone: bool) { + if self.current_sig_drop.is_some() { + return; + } + let ty = self.get_type(expr); + if ty.is_ref() { + // We checked that the type was ref, so builtin_deref will return Some TypeAndMut, + // but let's avoid any chance of an ICE + if let Some(TypeAndMut { ty, .. }) = ty.builtin_deref(true) { + if ty.is_trivially_pure_clone_copy() { + self.current_sig_drop.replace(FoundSigDrop { + found_span: expr.span, + is_unit_return_val: false, + lint_suggestion: LintSuggestion::MoveAndDerefToCopy, + }); + } else if allow_move_and_clone { + self.current_sig_drop.replace(FoundSigDrop { + found_span: expr.span, + is_unit_return_val: false, + lint_suggestion: LintSuggestion::MoveAndClone, + }); + } + } + } else if ty.is_trivially_pure_clone_copy() { + self.current_sig_drop.replace(FoundSigDrop { + found_span: expr.span, + is_unit_return_val: false, + lint_suggestion: LintSuggestion::MoveOnly, + }); + } + } + + fn move_current_suggestion(&mut self) { + if let Some(current) = self.current_sig_drop.take() { + self.sig_drop_spans.get_or_insert_with(Vec::new).push(current); + } + } + + fn get_type(&self, ex: &'tcx Expr<'_>) -> Ty<'tcx> { + self.cx.typeck_results().expr_ty(ex) + } + + fn has_seen_type(&mut self, ty: Ty<'tcx>) -> bool { + !self.seen_types.insert(ty) + } + + fn visit_exprs_for_binary_ops( + &mut self, + left: &'tcx Expr<'_>, + right: &'tcx Expr<'_>, + is_unit_return_val: bool, + span: Span, + ) { + self.special_handling_for_binary_op = true; + self.visit_expr(left); + self.visit_expr(right); + + // If either side had a significant drop, suggest moving the entire scrutinee to avoid + // unnecessary copies and to simplify cases where both sides have significant drops. + if self.has_significant_drop { + self.current_sig_drop.replace(FoundSigDrop { + found_span: span, + is_unit_return_val, + lint_suggestion: LintSuggestion::MoveOnly, + }); + } + + self.special_handling_for_binary_op = false; + } + + fn has_sig_drop_attr(&mut self, cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { + if let Some(adt) = ty.ty_adt_def() { + if get_attr(cx.sess(), cx.tcx.get_attrs(adt.did()), "has_significant_drop").count() > 0 { + return true; + } + } + + match ty.kind() { + rustc_middle::ty::Adt(a, b) => { + for f in a.all_fields() { + let ty = f.ty(cx.tcx, b); + if !self.has_seen_type(ty) && self.has_sig_drop_attr(cx, ty) { + return true; + } + } + + for generic_arg in b.iter() { + if let GenericArgKind::Type(ty) = generic_arg.unpack() { + if self.has_sig_drop_attr(cx, ty) { + return true; + } + } + } + false + }, + rustc_middle::ty::Array(ty, _) => self.has_sig_drop_attr(cx, *ty), + rustc_middle::ty::RawPtr(TypeAndMut { ty, .. }) => self.has_sig_drop_attr(cx, *ty), + rustc_middle::ty::Ref(_, ty, _) => self.has_sig_drop_attr(cx, *ty), + rustc_middle::ty::Slice(ty) => self.has_sig_drop_attr(cx, *ty), + _ => false, + } + } +} + +impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> { + fn visit_expr(&mut self, ex: &'tcx Expr<'_>) { + if !self.is_chain_end && self.has_sig_drop_attr(self.cx, self.get_type(ex)) { + self.has_significant_drop = true; + return; + } + self.is_chain_end = false; + + match ex.kind { + ExprKind::MethodCall(_, [ref expr, ..], _) => { + self.visit_expr(expr) + } + ExprKind::Binary(_, left, right) => { + self.visit_exprs_for_binary_ops(left, right, false, ex.span); + } + ExprKind::Assign(left, right, _) => { + self.visit_exprs_for_binary_ops(left, right, true, ex.span); + } + ExprKind::AssignOp(_, left, right) => { + self.visit_exprs_for_binary_ops(left, right, true, ex.span); + } + ExprKind::Tup(exprs) => { + for expr in exprs { + self.visit_expr(expr); + if self.has_significant_drop { + // We may have not have set current_sig_drop if all the suggestions were + // MoveAndClone, so add this tuple item's full expression in that case. + if self.current_sig_drop.is_none() { + self.try_setting_current_suggestion(expr, true); + } + + // Now we are guaranteed to have something, so add it to the final vec. + self.move_current_suggestion(); + } + // Reset `has_significant_drop` after each tuple expression so we can look for + // additional cases. + self.has_significant_drop = false; + } + if self.sig_drop_spans.is_some() { + self.has_significant_drop = true; + } + } + ExprKind::Box(..) | + ExprKind::Array(..) | + ExprKind::Call(..) | + ExprKind::Unary(..) | + ExprKind::If(..) | + ExprKind::Match(..) | + ExprKind::Field(..) | + ExprKind::Index(..) | + ExprKind::Ret(..) | + ExprKind::Repeat(..) | + ExprKind::Yield(..) | + ExprKind::MethodCall(..) => walk_expr(self, ex), + ExprKind::AddrOf(_, _, _) | + ExprKind::Block(_, _) | + ExprKind::Break(_, _) | + ExprKind::Cast(_, _) | + // Don't want to check the closure itself, only invocation, which is covered by MethodCall + ExprKind::Closure(_, _, _, _, _) | + ExprKind::ConstBlock(_) | + ExprKind::Continue(_) | + ExprKind::DropTemps(_) | + ExprKind::Err | + ExprKind::InlineAsm(_) | + ExprKind::Let(_) | + ExprKind::Lit(_) | + ExprKind::Loop(_, _, _, _) | + ExprKind::Path(_) | + ExprKind::Struct(_, _, _) | + ExprKind::Type(_, _) => { + return; + } + } + + // Once a significant temporary has been found, we need to go back up at least 1 level to + // find the span to extract for replacement, so the temporary gets dropped. However, for + // binary ops, we want to move the whole scrutinee so we avoid unnecessary copies and to + // simplify cases where both sides have significant drops. + if self.has_significant_drop && !self.special_handling_for_binary_op { + self.try_setting_current_suggestion(ex, false); + } + } +} diff --git a/clippy_utils/src/attrs.rs b/clippy_utils/src/attrs.rs index 25a84d166508..7f448175e326 100644 --- a/clippy_utils/src/attrs.rs +++ b/clippy_utils/src/attrs.rs @@ -22,6 +22,7 @@ pub const BUILTIN_ATTRIBUTES: &[(&str, DeprecationStatus)] = &[ ("cyclomatic_complexity", DeprecationStatus::Replaced("cognitive_complexity")), ("dump", DeprecationStatus::None), ("msrv", DeprecationStatus::None), + ("has_significant_drop", DeprecationStatus::None), ]; pub struct LimitStack { diff --git a/tests/ui/significant_drop_in_scrutinee.rs b/tests/ui/significant_drop_in_scrutinee.rs new file mode 100644 index 000000000000..c4a3301e7226 --- /dev/null +++ b/tests/ui/significant_drop_in_scrutinee.rs @@ -0,0 +1,526 @@ +// FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 +// // run-rustfix + +#![warn(clippy::significant_drop_in_scrutinee)] +#![allow(clippy::single_match)] +#![allow(clippy::match_single_binding)] +#![allow(unused_assignments)] +#![allow(dead_code)] + +use std::ops::Deref; +use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::{Mutex, MutexGuard}; + +struct State {} + +impl State { + fn foo(&self) -> bool { + true + } + + fn bar(&self) {} +} + +fn should_not_trigger_lint_with_mutex_guard_outside_match() { + let mutex = Mutex::new(State {}); + + // Should not trigger lint because the temporary should drop at the `;` on line before the match + let is_foo = mutex.lock().unwrap().foo(); + match is_foo { + true => { + mutex.lock().unwrap().bar(); + } + false => {} + }; +} + +fn should_not_trigger_lint_with_mutex_guard_when_taking_ownership_in_match() { + let mutex = Mutex::new(State {}); + + // Should not trigger lint because the scrutinee is explicitly returning the MutexGuard, + // so its lifetime should not be surprising. + match mutex.lock() { + Ok(guard) => { + guard.foo(); + mutex.lock().unwrap().bar(); + } + _ => {} + }; +} + +fn should_trigger_lint_with_mutex_guard_in_match_scrutinee() { + let mutex = Mutex::new(State {}); + + // Should trigger lint because the lifetime of the temporary MutexGuard is surprising because it + // is preserved until the end of the match, but there is no clear indication that this is the + // case. + match mutex.lock().unwrap().foo() { + true => { + mutex.lock().unwrap().bar(); + } + false => {} + }; +} + +fn should_not_trigger_lint_for_insignificant_drop() { + // Should not trigger lint because there are no temporaries whose drops have a significant + // side effect. + match 1u64.to_string().is_empty() { + true => { + println!("It was empty") + } + false => { + println!("It was not empty") + } + } +} + +struct StateWithMutex { + m: Mutex, +} + +struct MutexGuardWrapper<'a> { + mg: MutexGuard<'a, u64>, +} + +impl<'a> MutexGuardWrapper<'a> { + fn get_the_value(&self) -> u64 { + *self.mg.deref() + } +} + +struct MutexGuardWrapperWrapper<'a> { + mg: MutexGuardWrapper<'a>, +} + +impl<'a> MutexGuardWrapperWrapper<'a> { + fn get_the_value(&self) -> u64 { + *self.mg.mg.deref() + } +} + +impl StateWithMutex { + fn lock_m(&self) -> MutexGuardWrapper<'_> { + MutexGuardWrapper { + mg: self.m.lock().unwrap(), + } + } + + fn lock_m_m(&self) -> MutexGuardWrapperWrapper<'_> { + MutexGuardWrapperWrapper { + mg: MutexGuardWrapper { + mg: self.m.lock().unwrap(), + }, + } + } + + fn foo(&self) -> bool { + true + } + + fn bar(&self) {} +} + +fn should_trigger_lint_with_wrapped_mutex() { + let s = StateWithMutex { m: Mutex::new(1) }; + + // Should trigger lint because a temporary contains a type with a significant drop and its + // lifetime is not obvious. Additionally, it is not obvious from looking at the scrutinee that + // the temporary contains such a type, making it potentially even more surprising. + match s.lock_m().get_the_value() { + 1 => { + println!("Got 1. Is it still 1?"); + println!("{}", s.lock_m().get_the_value()); + } + 2 => { + println!("Got 2. Is it still 2?"); + println!("{}", s.lock_m().get_the_value()); + } + _ => {} + } + println!("All done!"); +} + +fn should_trigger_lint_with_double_wrapped_mutex() { + let s = StateWithMutex { m: Mutex::new(1) }; + + // Should trigger lint because a temporary contains a type which further contains a type with a + // significant drop and its lifetime is not obvious. Additionally, it is not obvious from + // looking at the scrutinee that the temporary contains such a type, making it potentially even + // more surprising. + match s.lock_m_m().get_the_value() { + 1 => { + println!("Got 1. Is it still 1?"); + println!("{}", s.lock_m().get_the_value()); + } + 2 => { + println!("Got 2. Is it still 2?"); + println!("{}", s.lock_m().get_the_value()); + } + _ => {} + } + println!("All done!"); +} + +struct Counter { + i: AtomicU64, +} + +#[clippy::has_significant_drop] +struct CounterWrapper<'a> { + counter: &'a Counter, +} + +impl<'a> CounterWrapper<'a> { + fn new(counter: &Counter) -> CounterWrapper { + counter.i.fetch_add(1, Ordering::Relaxed); + CounterWrapper { counter } + } +} + +impl<'a> Drop for CounterWrapper<'a> { + fn drop(&mut self) { + self.counter.i.fetch_sub(1, Ordering::Relaxed); + } +} + +impl Counter { + fn temp_increment(&self) -> Vec { + vec![CounterWrapper::new(self), CounterWrapper::new(self)] + } +} + +fn should_trigger_lint_for_vec() { + let counter = Counter { i: AtomicU64::new(0) }; + + // Should trigger lint because the temporary in the scrutinee returns a collection of types + // which have significant drops. The types with significant drops are also non-obvious when + // reading the expression in the scrutinee. + match counter.temp_increment().len() { + 2 => { + let current_count = counter.i.load(Ordering::Relaxed); + println!("Current count {}", current_count); + assert_eq!(current_count, 0); + } + 1 => {} + 3 => {} + _ => {} + }; +} + +struct StateWithField { + s: String, +} + +// Should trigger lint only on the type in the tuple which is created using a temporary +// with a significant drop. Additionally, this test ensures that the format of the tuple +// is preserved correctly in the suggestion. +fn should_trigger_lint_for_tuple_in_scrutinee() { + let mutex1 = Mutex::new(StateWithField { s: "one".to_owned() }); + + { + match (mutex1.lock().unwrap().s.len(), true) { + (3, _) => { + println!("started"); + mutex1.lock().unwrap().s.len(); + println!("done"); + } + (_, _) => {} + }; + + match (true, mutex1.lock().unwrap().s.len(), true) { + (_, 3, _) => { + println!("started"); + mutex1.lock().unwrap().s.len(); + println!("done"); + } + (_, _, _) => {} + }; + + let mutex2 = Mutex::new(StateWithField { s: "two".to_owned() }); + match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { + (3, _, 3) => { + println!("started"); + mutex1.lock().unwrap().s.len(); + mutex2.lock().unwrap().s.len(); + println!("done"); + } + (_, _, _) => {} + }; + + let mutex3 = Mutex::new(StateWithField { s: "three".to_owned() }); + match mutex3.lock().unwrap().s.as_str() { + "three" => { + println!("started"); + mutex1.lock().unwrap().s.len(); + mutex2.lock().unwrap().s.len(); + println!("done"); + } + _ => {} + }; + + + match (true, mutex3.lock().unwrap().s.as_str()) { + (_, "three") => { + println!("started"); + mutex1.lock().unwrap().s.len(); + mutex2.lock().unwrap().s.len(); + println!("done"); + } + (_, _) => {} + }; + } +} + +// Should trigger lint when either side of a binary operation creates a temporary with a +// significant drop. +// To avoid potential unnecessary copies or creating references that would trigger the significant +// drop problem, the lint recommends moving the entire binary operation. +fn should_trigger_lint_for_accessing_field_in_mutex_in_one_side_of_binary_op() { + let mutex = Mutex::new(StateWithField { s: "state".to_owned() }); + + match mutex.lock().unwrap().s.len() > 1 { + true => { + mutex.lock().unwrap().s.len(); + } + false => {} + }; + + match 1 < mutex.lock().unwrap().s.len() { + true => { + mutex.lock().unwrap().s.len(); + } + false => {} + }; +} + +// Should trigger lint when both sides of a binary operation creates a temporary with a +// significant drop. +// To avoid potential unnecessary copies or creating references that would trigger the significant +// drop problem, the lint recommends moving the entire binary operation. +fn should_trigger_lint_for_accessing_fields_in_mutex_in_both_sides_of_binary_op() { + let mutex1 = Mutex::new(StateWithField { s: "state".to_owned() }); + let mutex2 = Mutex::new(StateWithField { s: "statewithfield".to_owned() }); + + match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() { + true => { + println!("{} < {}", mutex1.lock().unwrap().s.len(), mutex2.lock().unwrap().s.len()); + } + false => {} + }; + + match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() { + true => { + println!("{} >= {}", mutex1.lock().unwrap().s.len(), mutex2.lock().unwrap().s.len()); + } + false => {} + }; +} + +fn should_not_trigger_lint_for_closure_in_scrutinee() { + let mutex1 = Mutex::new(StateWithField { s: "one".to_owned() }); + + let get_mutex_guard = || mutex1.lock().unwrap().s.len(); + + // Should not trigger lint because the temporary with a significant drop will be dropped + // at the end of the closure, so the MutexGuard will be unlocked and not have a potentially + // surprising lifetime. + match get_mutex_guard() > 1 { + true => { + mutex1.lock().unwrap().s.len(); + } + false => {} + }; +} + +fn should_trigger_lint_for_return_from_closure_in_scrutinee() { + let mutex1 = Mutex::new(StateWithField { s: "one".to_owned() }); + + let get_mutex_guard = || mutex1.lock().unwrap(); + + // Should trigger lint because the temporary with a significant drop is returned from the + // closure but not used directly in any match arms, so it has a potentially surprising lifetime. + match get_mutex_guard().s.len() > 1 { + true => { + mutex1.lock().unwrap().s.len(); + } + false => {} + }; +} + +fn should_trigger_lint_for_return_from_match_in_scrutinee() { + let mutex1 = Mutex::new(StateWithField { s: "one".to_owned() }); + let mutex2 = Mutex::new(StateWithField { s: "two".to_owned() }); + + let i = 100; + + // Should trigger lint because the nested match within the scrutinee returns a temporary with a + // significant drop is but not used directly in any match arms, so it has a potentially + // surprising lifetime. + match match i { 100 => mutex1.lock().unwrap(), _ => mutex2.lock().unwrap() }.s.len() > 1 { + true => { + mutex1.lock().unwrap().s.len(); + } + false => { + println!("nothing to do here"); + } + }; +} + +fn should_trigger_lint_for_return_from_if_in_scrutinee() { + let mutex1 = Mutex::new(StateWithField { s: "one".to_owned() }); + let mutex2 = Mutex::new(StateWithField { s: "two".to_owned() }); + + let i = 100; + + // Should trigger lint because the nested if-expression within the scrutinee returns a temporary + // with a significant drop is but not used directly in any match arms, so it has a potentially + // surprising lifetime. + match if i > 1 { mutex1.lock().unwrap() } else { mutex2.lock().unwrap() }.s.len() > 1 { + true => { + mutex1.lock().unwrap().s.len(); + } + false => {} + }; +} + +fn should_not_trigger_lint_for_if_in_scrutinee() { + let mutex = Mutex::new(StateWithField { s: "state".to_owned() }); + + let i = 100; + + // Should not trigger the lint because the temporary with a significant drop *is* dropped within + // the body of the if-expression nested within the match scrutinee, and therefore does not have + // a potentially surprising lifetime. + match if i > 1 { mutex.lock().unwrap().s.len() > 1 } else { false } { + true => { + mutex.lock().unwrap().s.len(); + } + false => {} + }; +} + +struct StateWithBoxedMutexGuard { + u: Mutex, +} + +impl StateWithBoxedMutexGuard { + fn new() -> StateWithBoxedMutexGuard { + StateWithBoxedMutexGuard { u: Mutex::new(42) } + } + fn lock(&self) -> Box> { + Box::new(self.u.lock().unwrap()) + } +} + +fn should_trigger_lint_for_boxed_mutex_guard() { + let s = StateWithBoxedMutexGuard::new(); + + // Should trigger lint because a temporary Box holding a type with a significant drop in a match + // scrutinee may have a potentially surprising lifetime. + match s.lock().deref().deref() { + 0 | 1 => println!("Value was less than 2"), + _ => println!("Value is {}", s.lock().deref()), + }; +} + +struct StateStringWithBoxedMutexGuard { + s: Mutex, +} + +impl StateStringWithBoxedMutexGuard { + fn new() -> StateStringWithBoxedMutexGuard { + StateStringWithBoxedMutexGuard { s: Mutex::new("A String".to_owned()) } + } + fn lock(&self) -> Box> { + Box::new(self.s.lock().unwrap()) + } +} + +fn should_trigger_lint_for_boxed_mutex_guard_holding_string() { + let s = StateStringWithBoxedMutexGuard::new(); + + let matcher = String::from("A String"); + + // Should trigger lint because a temporary Box holding a type with a significant drop in a match + // scrutinee may have a potentially surprising lifetime. + match s.lock().deref().deref() { + matcher => println!("Value is {}", s.lock().deref()), + _ => println!("Value was not a match"), + }; +} + + +struct StateWithIntField { + i: u64, +} + +// Should trigger lint when either side of an assign expression contains a temporary with a +// significant drop, because the temporary's lifetime will be extended to the end of the match. +// To avoid potential unnecessary copies or creating references that would trigger the significant +// drop problem, the lint recommends moving the entire binary operation. +fn should_trigger_lint_in_assign_expr() { + let mutex = Mutex::new(StateWithIntField { i: 10 }); + + let mut i = 100; + + match mutex.lock().unwrap().i = i { + _ => { + println!("{}", mutex.lock().unwrap().i); + } + }; + + match i = mutex.lock().unwrap().i { + _ => { + println!("{}", mutex.lock().unwrap().i); + } + }; + + match mutex.lock().unwrap().i += 1 { + _ => { + println!("{}", mutex.lock().unwrap().i); + } + }; + + match i += mutex.lock().unwrap().i { + _ => { + println!("{}", mutex.lock().unwrap().i); + } + }; +} + +#[derive(Debug)] +enum RecursiveEnum { + Foo(Option>) +} + +#[derive(Debug)] +enum GenericRecursiveEnum { + Foo(T, Option>>) +} + +fn should_not_cause_stack_overflow() { + // Test that when a type recursively contains itself, a stack overflow does not occur when + // checking sub-types for significant drops. + let f = RecursiveEnum::Foo(Some(Box::new(RecursiveEnum::Foo(None)))); + match f { + RecursiveEnum::Foo(Some(f)) => { + println!("{:?}", f) + } + RecursiveEnum::Foo(f) => { + println!("{:?}", f) + } + } + + let f = GenericRecursiveEnum::Foo(1u64, Some(Box::new(GenericRecursiveEnum::Foo(2u64, None)))); + match f { + GenericRecursiveEnum::Foo(i, Some(f)) => { + println!("{} {:?}", i, f) + } + GenericRecursiveEnum::Foo(i, f) => { + println!("{} {:?}", i, f) + } + } +} + +fn main() {} diff --git a/tests/ui/significant_drop_in_scrutinee.stderr b/tests/ui/significant_drop_in_scrutinee.stderr new file mode 100644 index 000000000000..c442e93f539a --- /dev/null +++ b/tests/ui/significant_drop_in_scrutinee.stderr @@ -0,0 +1,261 @@ +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:57:11 + | +LL | match mutex.lock().unwrap().foo() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::significant-drop-in-scrutinee` implied by `-D warnings` +help: try moving the temporary above the match + | +LL ~ let value = mutex.lock().unwrap().foo(); +LL ~ match value { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:130:11 + | +LL | match s.lock_m().get_the_value() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ let value = s.lock_m().get_the_value(); +LL ~ match value { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:151:11 + | +LL | match s.lock_m_m().get_the_value() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ let value = s.lock_m_m().get_the_value(); +LL ~ match value { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:199:11 + | +LL | match counter.temp_increment().len() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ let value = counter.temp_increment().len(); +LL ~ match value { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:222:16 + | +LL | match (mutex1.lock().unwrap().s.len(), true) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ let value = mutex1.lock().unwrap().s.len(); +LL ~ match (value, true) { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:231:22 + | +LL | match (true, mutex1.lock().unwrap().s.len(), true) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ let value = mutex1.lock().unwrap().s.len(); +LL ~ match (true, value, true) { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:241:16 + | +LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ let value = mutex1.lock().unwrap().s.len(); +LL ~ match (value, true, mutex2.lock().unwrap().s.len()) { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:241:54 + | +LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ let value = mutex2.lock().unwrap().s.len(); +LL ~ match (mutex1.lock().unwrap().s.len(), true, value) { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:252:15 + | +LL | match mutex3.lock().unwrap().s.as_str() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:263:22 + | +LL | match (true, mutex3.lock().unwrap().s.as_str()) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:282:11 + | +LL | match mutex.lock().unwrap().s.len() > 1 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ let value = mutex.lock().unwrap().s.len() > 1; +LL ~ match value { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:289:11 + | +LL | match 1 < mutex.lock().unwrap().s.len() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ let value = 1 < mutex.lock().unwrap().s.len(); +LL ~ match value { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:305:11 + | +LL | match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ let value = mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len(); +LL ~ match value { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:312:11 + | +LL | match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ let value = mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len(); +LL ~ match value { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:343:11 + | +LL | match get_mutex_guard().s.len() > 1 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ let value = get_mutex_guard().s.len() > 1; +LL ~ match value { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:360:11 + | +LL | match match i { 100 => mutex1.lock().unwrap(), _ => mutex2.lock().unwrap() }.s.len() > 1 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ let value = match i { 100 => mutex1.lock().unwrap(), _ => mutex2.lock().unwrap() }.s.len() > 1; +LL ~ match value { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:379:11 + | +LL | match if i > 1 { mutex1.lock().unwrap() } else { mutex2.lock().unwrap() }.s.len() > 1 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ let value = if i > 1 { mutex1.lock().unwrap() } else { mutex2.lock().unwrap() }.s.len() > 1; +LL ~ match value { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:421:11 + | +LL | match s.lock().deref().deref() { + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match and create a copy + | +LL ~ let value = *s.lock().deref().deref(); +LL ~ match value { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:447:11 + | +LL | match s.lock().deref().deref() { + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:467:11 + | +LL | match mutex.lock().unwrap().i = i { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ mutex.lock().unwrap().i = i; +LL ~ match () { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:473:11 + | +LL | match i = mutex.lock().unwrap().i { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ i = mutex.lock().unwrap().i; +LL ~ match () { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:479:11 + | +LL | match mutex.lock().unwrap().i += 1 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ mutex.lock().unwrap().i += 1; +LL ~ match () { + | + +error: temporary with significant drop in match scrutinee + --> $DIR/significant_drop_in_scrutinee.rs:485:11 + | +LL | match i += mutex.lock().unwrap().i { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try moving the temporary above the match + | +LL ~ i += mutex.lock().unwrap().i; +LL ~ match () { + | + +error: aborting due to 23 previous errors + From 1a2a3e78bd81481e76278d5501baf9a37a8fc2f7 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 5 May 2022 15:50:11 +0100 Subject: [PATCH 0490/1222] Track if a where bound comes from a impl Trait desugar With #93803 `impl Trait` function arguments get desugared to hidden where bounds. However, Clippy needs to know if a bound was originally a impl Trait or an actual bound. This adds a field to the `WhereBoundPredicate` struct to keep track of this information during HIR lowering. --- clippy_lints/src/lifetimes.rs | 6 +++--- clippy_lints/src/trait_bounds.rs | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index ab5d3fa7b6d9..51d5b510ab93 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -9,8 +9,8 @@ use rustc_hir::intravisit::{ use rustc_hir::FnRetTy::Return; use rustc_hir::{ BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl, ImplItem, - ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, ParamName, PolyTraitRef, TraitBoundModifier, - TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate, + ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, ParamName, PolyTraitRef, PredicateOrigin, + TraitBoundModifier, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter as middle_nested_filter; @@ -145,7 +145,7 @@ fn check_fn_inner<'tcx>( .filter(|param| matches!(param.kind, GenericParamKind::Type { .. })); for typ in types { for pred in generics.bounds_for_param(cx.tcx.hir().local_def_id(typ.hir_id)) { - if pred.in_where_clause { + if pred.origin == PredicateOrigin::WhereClause { // has_where_lifetimes checked that this predicate contains no lifetime. continue; } diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index c0aca2d517cf..911da3997ae4 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -8,7 +8,8 @@ use rustc_data_structures::unhash::UnhashMap; use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::{ - GenericBound, Generics, Item, ItemKind, Node, Path, PathSegment, QPath, TraitItem, Ty, TyKind, WherePredicate, + GenericBound, Generics, Item, ItemKind, Node, Path, PathSegment, PredicateOrigin, QPath, TraitItem, Ty, TyKind, + WherePredicate, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -95,6 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { for predicate in item.generics.predicates { if_chain! { if let WherePredicate::BoundPredicate(ref bound_predicate) = predicate; + if bound_predicate.origin != PredicateOrigin::ImplTrait; if !bound_predicate.span.from_expansion(); if let TyKind::Path(QPath::Resolved(_, Path { segments, .. })) = bound_predicate.bounded_ty.kind; if let Some(PathSegment { @@ -168,6 +170,7 @@ impl TraitBounds { for bound in gen.predicates { if_chain! { if let WherePredicate::BoundPredicate(ref p) = bound; + if p.origin != PredicateOrigin::ImplTrait; if p.bounds.len() as u64 <= self.max_trait_bounds; if !p.span.from_expansion(); if let Some(ref v) = map.insert( @@ -223,6 +226,7 @@ fn check_trait_bound_duplication(cx: &LateContext<'_>, gen: &'_ Generics<'_>) { for predicate in gen.predicates { if_chain! { if let WherePredicate::BoundPredicate(ref bound_predicate) = predicate; + if bound_predicate.origin != PredicateOrigin::ImplTrait; if !bound_predicate.span.from_expansion(); if let TyKind::Path(QPath::Resolved(_, Path { segments, .. })) = bound_predicate.bounded_ty.kind; if let Some(segment) = segments.first(); From 2197f89be6f1fb3f089d7f8c01f76aec13f007c8 Mon Sep 17 00:00:00 2001 From: xFrednet Date: Thu, 31 Mar 2022 21:49:50 +0200 Subject: [PATCH 0491/1222] Test `expect` attribute for tool lints, clippy edition (RFC 2383) --- tests/ui/expect_tool_lint_rfc_2383.rs | 142 ++++++++++++++++++++++ tests/ui/expect_tool_lint_rfc_2383.stderr | 40 ++++++ 2 files changed, 182 insertions(+) create mode 100644 tests/ui/expect_tool_lint_rfc_2383.rs create mode 100644 tests/ui/expect_tool_lint_rfc_2383.stderr diff --git a/tests/ui/expect_tool_lint_rfc_2383.rs b/tests/ui/expect_tool_lint_rfc_2383.rs new file mode 100644 index 000000000000..28b37f96e911 --- /dev/null +++ b/tests/ui/expect_tool_lint_rfc_2383.rs @@ -0,0 +1,142 @@ +// check-pass +#![feature(lint_reasons)] +//! This file tests the `#[expect]` attribute implementation for tool lints. The same +//! file is used to test clippy and rustdoc. Any changes to this file should be synced +//! to the other test files as well. +//! +//! Expectations: +//! * rustc: only rustc lint expectations are emitted +//! * clippy: rustc and Clippy's expectations are emitted +//! * rustdoc: only rustdoc lint expectations are emitted +//! +//! This test can't cover every lint from Clippy, rustdoc and potentially other +//! tools that will be developed. This therefore only tests a small subset of lints +#![expect(rustdoc::missing_crate_level_docs)] + +mod rustc_ok { + //! See + + #[expect(dead_code)] + pub fn rustc_lints() { + let x = 42.0; + + #[expect(illegal_floating_point_literal_pattern)] + match x { + 5.0 => {} + 6.0 => {} + _ => {} + } + } +} + +mod rustc_warn { + //! See + + #[expect(dead_code)] + pub fn rustc_lints() { + let x = 42; + + #[expect(illegal_floating_point_literal_pattern)] + match x { + 5 => {} + 6 => {} + _ => {} + } + } +} + +pub mod rustdoc_ok { + //! See + + #[expect(rustdoc::broken_intra_doc_links)] + /// I want to link to [`Nonexistent`] but it doesn't exist! + pub fn foo() {} + + #[expect(rustdoc::invalid_html_tags)] + ///

+ pub fn bar() {} + + #[expect(rustdoc::bare_urls)] + /// http://example.org + pub fn baz() {} +} + +pub mod rustdoc_warn { + //! See + + #[expect(rustdoc::broken_intra_doc_links)] + /// I want to link to [`bar`] but it doesn't exist! + pub fn foo() {} + + #[expect(rustdoc::invalid_html_tags)] + ///

+ pub fn bar() {} + + #[expect(rustdoc::bare_urls)] + /// + pub fn baz() {} +} + +mod clippy_ok { + //! See + + #[expect(clippy::almost_swapped)] + fn foo() { + let mut a = 0; + let mut b = 9; + a = b; + b = a; + } + + #[expect(clippy::bytes_nth)] + fn bar() { + let _ = "Hello".bytes().nth(3); + } + + #[expect(clippy::if_same_then_else)] + fn baz() { + let _ = if true { 42 } else { 42 }; + } + + #[expect(clippy::logic_bug)] + fn burger() { + let a = false; + let b = true; + + if a && b || a {} + } +} + +mod clippy_warn { + //! See + + #[expect(clippy::almost_swapped)] + fn foo() { + let mut a = 0; + let mut b = 9; + a = b; + } + + #[expect(clippy::bytes_nth)] + fn bar() { + let _ = "Hello".as_bytes().get(3); + } + + #[expect(clippy::if_same_then_else)] + fn baz() { + let _ = if true { 33 } else { 42 }; + } + + #[expect(clippy::logic_bug)] + fn burger() { + let a = false; + let b = true; + let c = false; + + if a && b || c {} + } +} + +fn main() { + rustc_warn::rustc_lints(); +} diff --git a/tests/ui/expect_tool_lint_rfc_2383.stderr b/tests/ui/expect_tool_lint_rfc_2383.stderr new file mode 100644 index 000000000000..db29e85a8219 --- /dev/null +++ b/tests/ui/expect_tool_lint_rfc_2383.stderr @@ -0,0 +1,40 @@ +error: this lint expectation is unfulfilled + --> $DIR/expect_tool_lint_rfc_2383.rs:35:14 + | +LL | #[expect(dead_code)] + | ^^^^^^^^^ + | + = note: `-D unfulfilled-lint-expectations` implied by `-D warnings` + +error: this lint expectation is unfulfilled + --> $DIR/expect_tool_lint_rfc_2383.rs:39:18 + | +LL | #[expect(illegal_floating_point_literal_pattern)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this lint expectation is unfulfilled + --> $DIR/expect_tool_lint_rfc_2383.rs:113:14 + | +LL | #[expect(clippy::almost_swapped)] + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: this lint expectation is unfulfilled + --> $DIR/expect_tool_lint_rfc_2383.rs:120:14 + | +LL | #[expect(clippy::bytes_nth)] + | ^^^^^^^^^^^^^^^^^ + +error: this lint expectation is unfulfilled + --> $DIR/expect_tool_lint_rfc_2383.rs:125:14 + | +LL | #[expect(clippy::if_same_then_else)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this lint expectation is unfulfilled + --> $DIR/expect_tool_lint_rfc_2383.rs:130:14 + | +LL | #[expect(clippy::logic_bug)] + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 6 previous errors + From 534bc066c7fdc6ec104e68b73840439ba895e083 Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Mon, 9 May 2022 21:48:57 +0800 Subject: [PATCH 0492/1222] fix clippy --- clippy_lints/src/collapsible_match.rs | 4 ++-- clippy_lints/src/entry.rs | 4 ++-- clippy_lints/src/only_used_in_recursion.rs | 2 +- clippy_lints/src/utils/author.rs | 10 +++++----- clippy_utils/src/hir_utils.rs | 6 ++++-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/collapsible_match.rs b/clippy_lints/src/collapsible_match.rs index cc354b50afa3..826eb0ae6b13 100644 --- a/clippy_lints/src/collapsible_match.rs +++ b/clippy_lints/src/collapsible_match.rs @@ -5,7 +5,7 @@ use clippy_utils::{is_lang_ctor, is_unit_expr, path_to_local, peel_blocks_with_s use if_chain::if_chain; use rustc_errors::MultiSpan; use rustc_hir::LangItem::OptionNone; -use rustc_hir::{Arm, Expr, Guard, HirId, Pat, PatKind}; +use rustc_hir::{Arm, Expr, Guard, HirId, Let, Pat, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Span; @@ -109,7 +109,7 @@ fn check_arm<'tcx>( (Some(a), Some(b)) => SpanlessEq::new(cx).eq_expr(a, b), }; // the binding must not be used in the if guard - if outer_guard.map_or(true, |(Guard::If(e) | Guard::IfLet(_, e))| !is_local_used(cx, *e, binding_id)); + if outer_guard.map_or(true, |(Guard::If(e) | Guard::IfLet(Let { init: e, .. }))| !is_local_used(cx, *e, binding_id)); // ...or anywhere in the inner expression if match inner { IfLetOrMatch::IfLet(_, _, body, els) => { diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 1ae2e20c1e06..d3d3ed2c2357 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -11,7 +11,7 @@ use rustc_errors::Applicability; use rustc_hir::{ hir_id::HirIdSet, intravisit::{walk_expr, Visitor}, - Block, Expr, ExprKind, Guard, HirId, Pat, Stmt, StmtKind, UnOp, + Block, Expr, ExprKind, Guard, HirId, Let, Pat, Stmt, StmtKind, UnOp, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -478,7 +478,7 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> { let mut is_map_used = self.is_map_used; for arm in arms { self.visit_pat(arm.pat); - if let Some(Guard::If(guard) | Guard::IfLet(_, guard)) = arm.guard { + if let Some(Guard::If(guard) | Guard::IfLet(&Let { init: guard, .. })) = arm.guard { self.visit_non_tail_expr(guard); } is_map_used |= self.visit_cond_arm(arm.body); diff --git a/clippy_lints/src/only_used_in_recursion.rs b/clippy_lints/src/only_used_in_recursion.rs index beb812793f81..d66698f8adc6 100644 --- a/clippy_lints/src/only_used_in_recursion.rs +++ b/clippy_lints/src/only_used_in_recursion.rs @@ -596,7 +596,7 @@ impl<'tcx> SideEffectVisit<'tcx> { let mut vars = std::mem::take(&mut self.ret_vars); let _ = arm.guard.as_ref().map(|guard| { self.visit_expr(match guard { - Guard::If(expr) | Guard::IfLet(_, expr) => expr, + Guard::If(expr) | Guard::IfLet(Let { init: expr, .. }) => expr, }); vars.append(&mut self.ret_vars); }); diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index ff5be825b781..3f4d0fd199d0 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -315,11 +315,11 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { out!("if let Some(Guard::If({expr})) = {arm}.guard;"); self.expr(expr); }, - Some(hir::Guard::IfLet(pat, expr)) => { - bind!(self, pat, expr); - out!("if let Some(Guard::IfLet({pat}, {expr}) = {arm}.guard;"); - self.pat(pat); - self.expr(expr); + Some(hir::Guard::IfLet(let_expr)) => { + bind!(self, let_expr); + out!("if let Some(Guard::IfLet({let_expr}) = {arm}.guard;"); + self.pat(field!(let_expr.pat)); + self.expr(field!(let_expr.init)); }, } self.expr(field!(arm.body)); diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index f4da625f1e30..aa21f15ee5d9 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -301,7 +301,9 @@ impl HirEqInterExpr<'_, '_, '_> { fn eq_guard(&mut self, left: &Guard<'_>, right: &Guard<'_>) -> bool { match (left, right) { (Guard::If(l), Guard::If(r)) => self.eq_expr(l, r), - (Guard::IfLet(lp, le), Guard::IfLet(rp, re)) => self.eq_pat(lp, rp) && self.eq_expr(le, re), + (Guard::IfLet(l), Guard::IfLet(r)) => { + self.eq_pat(l.pat, r.pat) && both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r)) && self.eq_expr(l.init, r.init) + }, _ => false, } } @@ -894,7 +896,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { pub fn hash_guard(&mut self, g: &Guard<'_>) { match g { - Guard::If(expr) | Guard::IfLet(_, expr) => { + Guard::If(expr) | Guard::IfLet(Let { init: expr, .. }) => { self.hash_expr(expr); }, } From 7894a7a15f0f8c8b9d501a912688486b43e5e7f8 Mon Sep 17 00:00:00 2001 From: lcnr Date: Tue, 26 Apr 2022 14:04:23 +0200 Subject: [PATCH 0493/1222] update clippy --- clippy_lints/src/derivable_impls.rs | 6 +++--- clippy_lints/src/derive.rs | 10 +++++----- clippy_lints/src/functions/must_use.rs | 8 ++++---- clippy_lints/src/manual_non_exhaustive.rs | 3 +-- clippy_lints/src/matches/match_wild_enum.rs | 3 +-- clippy_lints/src/new_without_default.rs | 2 +- clippy_lints/src/partialeq_ne_impl.rs | 4 +--- clippy_lints/src/significant_drop_in_scrutinee.rs | 2 +- clippy_utils/src/attrs.rs | 7 ++----- clippy_utils/src/lib.rs | 15 ++------------- clippy_utils/src/ty.rs | 12 ++++++------ 11 files changed, 27 insertions(+), 45 deletions(-) diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index 14098340745b..34a5f8444dea 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::{is_automatically_derived, is_default_equivalent, peel_blocks}; +use clippy_utils::{is_default_equivalent, peel_blocks}; use rustc_hir::{ def::{DefKind, Res}, Body, Expr, ExprKind, GenericArg, Impl, ImplItemKind, Item, ItemKind, Node, PathSegment, QPath, TyKind, @@ -71,8 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { self_ty, .. }) = item.kind; - if let attrs = cx.tcx.hir().attrs(item.hir_id()); - if !is_automatically_derived(attrs); + if !cx.tcx.has_attr(item.def_id.to_def_id(), sym::automatically_derived); if !item.span.from_expansion(); if let Some(def_id) = trait_ref.trait_def_id(); if cx.tcx.is_diagnostic_item(sym::Default, def_id); @@ -81,6 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { if let ImplItemKind::Fn(_, b) = &impl_item.kind; if let Body { value: func_expr, .. } = cx.tcx.hir().body(*b); if let Some(adt_def) = cx.tcx.type_of(item.def_id).ty_adt_def(); + if let attrs = cx.tcx.hir().attrs(item.hir_id()); if !attrs.iter().any(|attr| attr.doc_str().is_some()); if let child_attrs = cx.tcx.hir().attrs(impl_item_hir); if !child_attrs.iter().any(|attr| attr.doc_str().is_some()); diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 557e101494e3..545bc7d21033 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -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::{is_automatically_derived, is_lint_allowed, match_def_path}; +use clippy_utils::{is_lint_allowed, match_def_path}; use if_chain::if_chain; use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, Visitor}; use rustc_hir::{ @@ -171,8 +171,8 @@ impl<'tcx> LateLintPass<'tcx> for Derive { }) = item.kind { let ty = cx.tcx.type_of(item.def_id); - let attrs = cx.tcx.hir().attrs(item.hir_id()); - let is_automatically_derived = is_automatically_derived(attrs); + let is_automatically_derived = + cx.tcx.has_attr(item.def_id.to_def_id(), sym::automatically_derived); check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived); check_ord_partial_ord(cx, item.span, trait_ref, ty, is_automatically_derived); @@ -201,7 +201,7 @@ fn check_hash_peq<'tcx>( then { // Look for the PartialEq implementations for `ty` cx.tcx.for_each_relevant_impl(peq_trait_def_id, ty, |impl_id| { - let peq_is_automatically_derived = is_automatically_derived(cx.tcx.get_attrs(impl_id)); + let peq_is_automatically_derived = cx.tcx.has_attr(impl_id, sym::automatically_derived); if peq_is_automatically_derived == hash_is_automatically_derived { return; @@ -255,7 +255,7 @@ fn check_ord_partial_ord<'tcx>( then { // Look for the PartialOrd implementations for `ty` cx.tcx.for_each_relevant_impl(partial_ord_trait_def_id, ty, |impl_id| { - let partial_ord_is_automatically_derived = is_automatically_derived(cx.tcx.get_attrs(impl_id)); + let partial_ord_is_automatically_derived = cx.tcx.has_attr(impl_id, sym::automatically_derived); if partial_ord_is_automatically_derived == ord_is_automatically_derived { return; diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 38e943d2eb87..6672a6cb0b58 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -13,13 +13,13 @@ use clippy_utils::attrs::is_proc_macro; use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then}; use clippy_utils::source::snippet_opt; use clippy_utils::ty::is_must_use_ty; -use clippy_utils::{match_def_path, must_use_attr, return_ty, trait_ref_of_method}; +use clippy_utils::{match_def_path, return_ty, trait_ref_of_method}; use super::{DOUBLE_MUST_USE, MUST_USE_CANDIDATE, MUST_USE_UNIT}; pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { let attrs = cx.tcx.hir().attrs(item.hir_id()); - let attr = must_use_attr(attrs); + let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use); if let hir::ItemKind::Fn(ref sig, _generics, ref body_id) = item.kind { let is_public = cx.access_levels.is_exported(item.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); @@ -44,7 +44,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp let is_public = cx.access_levels.is_exported(item.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let attrs = cx.tcx.hir().attrs(item.hir_id()); - let attr = must_use_attr(attrs); + let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use); if let Some(attr) = attr { check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr); } else if is_public && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.def_id).is_none() { @@ -67,7 +67,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let attrs = cx.tcx.hir().attrs(item.hir_id()); - let attr = must_use_attr(attrs); + let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use); if let Some(attr) = attr { check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr); } else if let hir::TraitFn::Provided(eid) = *eid { diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index b8d620d81713..09164690700e 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -1,4 +1,3 @@ -use clippy_utils::attrs::is_doc_hidden; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_opt; use clippy_utils::{is_lint_allowed, meets_msrv, msrvs}; @@ -161,7 +160,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum { let id = cx.tcx.hir().local_def_id(v.id); (matches!(v.data, hir::VariantData::Unit(_)) && v.ident.as_str().starts_with('_') - && is_doc_hidden(cx.tcx.get_attrs(id.to_def_id()))) + && cx.tcx.is_doc_hidden(id.to_def_id())) .then(|| (id, v.span)) }); if let Some((id, span)) = iter.next() diff --git a/clippy_lints/src/matches/match_wild_enum.rs b/clippy_lints/src/matches/match_wild_enum.rs index 93bf0dc62e07..fc45ccee1852 100644 --- a/clippy_lints/src/matches/match_wild_enum.rs +++ b/clippy_lints/src/matches/match_wild_enum.rs @@ -193,6 +193,5 @@ impl<'a> CommonPrefixSearcher<'a> { } fn is_hidden(cx: &LateContext<'_>, variant_def: &VariantDef) -> bool { - let attrs = cx.tcx.get_attrs(variant_def.def_id); - clippy_utils::attrs::is_doc_hidden(attrs) || clippy_utils::attrs::is_unstable(attrs) + cx.tcx.is_doc_hidden(variant_def.def_id) || cx.tcx.has_attr(variant_def.def_id, sym::unstable) } diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 2f733f221d57..2bdccb425071 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -85,7 +85,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { // can't be implemented for unsafe new return; } - if clippy_utils::is_doc_hidden(cx.tcx.hir().attrs(id)) { + if cx.tcx.is_doc_hidden(impl_item.def_id) { // shouldn't be implemented when it is hidden in docs return; } diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index 1469cb434c00..09ac514d014e 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -1,5 +1,4 @@ use clippy_utils::diagnostics::span_lint_hir; -use clippy_utils::is_automatically_derived; use if_chain::if_chain; use rustc_hir::{Impl, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; @@ -37,8 +36,7 @@ impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if_chain! { if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), items: impl_items, .. }) = item.kind; - let attrs = cx.tcx.hir().attrs(item.hir_id()); - if !is_automatically_derived(attrs); + if !cx.tcx.has_attr(item.def_id.to_def_id(), sym::automatically_derived); if let Some(eq_trait) = cx.tcx.lang_items().eq_trait(); if trait_ref.path.res.def_id() == eq_trait; then { diff --git a/clippy_lints/src/significant_drop_in_scrutinee.rs b/clippy_lints/src/significant_drop_in_scrutinee.rs index 94ae0c8f5a65..f300acf0fb2b 100644 --- a/clippy_lints/src/significant_drop_in_scrutinee.rs +++ b/clippy_lints/src/significant_drop_in_scrutinee.rs @@ -290,7 +290,7 @@ impl<'a, 'tcx> SigDropHelper<'a, 'tcx> { fn has_sig_drop_attr(&mut self, cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { if let Some(adt) = ty.ty_adt_def() { - if get_attr(cx.sess(), cx.tcx.get_attrs(adt.did()), "has_significant_drop").count() > 0 { + if get_attr(cx.sess(), cx.tcx.get_attrs_unchecked(adt.did()), "has_significant_drop").count() > 0 { return true; } } diff --git a/clippy_utils/src/attrs.rs b/clippy_utils/src/attrs.rs index 7f448175e326..904b1a05ccc3 100644 --- a/clippy_utils/src/attrs.rs +++ b/clippy_utils/src/attrs.rs @@ -1,6 +1,7 @@ -use rustc_ast::{ast, attr}; +use rustc_ast::ast; use rustc_errors::Applicability; use rustc_session::Session; +use rustc_ast::attr; use rustc_span::sym; use std::str::FromStr; @@ -158,7 +159,3 @@ pub fn is_doc_hidden(attrs: &[ast::Attribute]) -> bool { .any(|l| attr::list_contains_name(&l, sym::hidden)) } -/// Return true if the attributes contain `#[unstable]` -pub fn is_unstable(attrs: &[ast::Attribute]) -> bool { - attrs.iter().any(|attr| attr.has_name(sym::unstable)) -} diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 7d46952d9718..98a073d122e3 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -66,7 +66,7 @@ use std::lazy::SyncOnceCell; use std::sync::{Mutex, MutexGuard}; use if_chain::if_chain; -use rustc_ast::ast::{self, Attribute, LitKind}; +use rustc_ast::ast::{self, LitKind}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::unhash::UnhashMap; use rustc_hir as hir; @@ -1472,12 +1472,6 @@ pub fn recurse_or_patterns<'tcx, F: FnMut(&'tcx Pat<'tcx>)>(pat: &'tcx Pat<'tcx> } } -/// Checks for the `#[automatically_derived]` attribute all `#[derive]`d -/// implementations have. -pub fn is_automatically_derived(attrs: &[ast::Attribute]) -> bool { - has_attr(attrs, sym::automatically_derived) -} - pub fn is_self(slf: &Param<'_>) -> bool { if let PatKind::Binding(.., name, _) = slf.pat.kind { name.name == kw::SelfLower @@ -1724,11 +1718,6 @@ pub fn get_async_fn_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Option<&'t None } -// Finds the `#[must_use]` attribute, if any -pub fn must_use_attr(attrs: &[Attribute]) -> Option<&Attribute> { - attrs.iter().find(|a| a.has_name(sym::must_use)) -} - // check if expr is calling method or function with #[must_use] attribute pub fn is_must_use_func_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let did = match expr.kind { @@ -1745,7 +1734,7 @@ pub fn is_must_use_func_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { _ => None, }; - did.map_or(false, |did| must_use_attr(cx.tcx.get_attrs(did)).is_some()) + did.map_or(false, |did| cx.tcx.has_attr(did, sym::must_use)) } /// Checks if an expression represents the identity function diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 901e3e5390c5..7f14a306d0e5 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -22,7 +22,7 @@ use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::query::normalize::AtExt; use std::iter; -use crate::{match_def_path, must_use_attr, path_res, paths}; +use crate::{match_def_path, path_res, paths}; // Checks if the given type implements copy. pub fn is_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { @@ -178,18 +178,18 @@ pub fn has_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { // Returns whether the type has #[must_use] attribute pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { match ty.kind() { - ty::Adt(adt, _) => must_use_attr(cx.tcx.get_attrs(adt.did())).is_some(), - ty::Foreign(ref did) => must_use_attr(cx.tcx.get_attrs(*did)).is_some(), + ty::Adt(adt, _) => cx.tcx.has_attr(adt.did(), sym::must_use), + ty::Foreign(did) => cx.tcx.has_attr(*did, sym::must_use), ty::Slice(ty) | ty::Array(ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) | ty::Ref(_, ty, _) => { // for the Array case we don't need to care for the len == 0 case // because we don't want to lint functions returning empty arrays is_must_use_ty(cx, *ty) }, ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), - ty::Opaque(ref def_id, _) => { + ty::Opaque(def_id, _) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { if let ty::PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() { - if must_use_attr(cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() { + if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) { return true; } } @@ -199,7 +199,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { ty::Dynamic(binder, _) => { for predicate in binder.iter() { if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() { - if must_use_attr(cx.tcx.get_attrs(trait_ref.def_id)).is_some() { + if cx.tcx.has_attr(trait_ref.def_id, sym::must_use) { return true; } } From 0c28e0d93f9021282bdd8b2f46017ab450a891b8 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Tue, 10 May 2022 14:20:34 -0700 Subject: [PATCH 0494/1222] Update clippy to new rake_read signature --- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/loops/mut_range_bound.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_utils/src/sugg.rs | 2 +- clippy_utils/src/usage.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index af591dd71aa1..807ecd2ddd16 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -187,7 +187,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { } } - fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _: HirId) {} + fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {} } impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> { diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index 9d8679d77c6d..d20df8304558 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -114,7 +114,7 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> { } } - fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _: HirId) {} + fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {} } impl MutatePairDelegate<'_, '_> { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 4034079a90c0..303ce7a5075a 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -343,5 +343,5 @@ impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt { fn mutate(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId) {} - fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _: HirId) {} + fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {} } diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 18915553e61c..db5299c2c05f 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -1033,7 +1033,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> { fn mutate(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {} - fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _: HirId) {} + fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {} } #[cfg(test)] diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index 4236e3aae2fb..b7b9d54d0b2c 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -74,7 +74,7 @@ impl<'tcx> Delegate<'tcx> for MutVarsDelegate { self.update(cmt); } - fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _: HirId) {} + fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {} } pub struct ParamBindingIdCollector { From d9e2f22106fdd5b23d9309e2f0c5054c2e7bc3c1 Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Sun, 8 May 2022 01:17:58 -0400 Subject: [PATCH 0495/1222] Introduce EarlyBinder --- clippy_lints/src/eta_reduction.rs | 4 ++-- clippy_lints/src/future_not_send.rs | 4 ++-- clippy_lints/src/mut_reference.rs | 4 ++-- clippy_lints/src/transmute/transmute_undefined_repr.rs | 4 ++-- clippy_utils/src/consts.rs | 4 ++-- clippy_utils/src/ty.rs | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 1b19868e4c70..b7776b3f0c38 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -12,7 +12,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; use rustc_middle::ty::binding::BindingMode; use rustc_middle::ty::subst::Subst; -use rustc_middle::ty::{self, ClosureKind, Ty, TypeFoldable}; +use rustc_middle::ty::{self, ClosureKind, EarlyBinder, Ty, TypeFoldable}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; @@ -150,7 +150,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { if check_inputs(cx, body.params, args); let method_def_id = cx.typeck_results().type_dependent_def_id(body.value.hir_id).unwrap(); let substs = cx.typeck_results().node_substs(body.value.hir_id); - let call_ty = cx.tcx.type_of(method_def_id).subst(cx.tcx, substs); + let call_ty = EarlyBinder(cx.tcx.type_of(method_def_id)).subst(cx.tcx, substs); if check_sig(cx, closure_ty, call_ty); then { span_lint_and_then(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure", |diag| { diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 43911a313d5a..5c46d6c7df70 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -5,7 +5,7 @@ use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::subst::Subst; -use rustc_middle::ty::{Opaque, PredicateKind::Trait}; +use rustc_middle::ty::{EarlyBinder, Opaque, PredicateKind::Trait}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt; @@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { let preds = cx.tcx.explicit_item_bounds(id); let mut is_future = false; for &(p, _span) in preds { - let p = p.subst(cx.tcx, subst); + let p = EarlyBinder(p).subst(cx.tcx, subst); if let Some(trait_pred) = p.to_opt_poly_trait_pred() { if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() { is_future = true; diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 5c3e505c06c4..a323737ae404 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::subst::Subst; -use rustc_middle::ty::{self, Ty}; +use rustc_middle::ty::{self, EarlyBinder, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::iter; @@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed { ExprKind::MethodCall(path, arguments, _) => { let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap(); let substs = cx.typeck_results().node_substs(e.hir_id); - let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs); + let method_type = EarlyBinder(cx.tcx.type_of(def_id)).subst(cx.tcx, substs); check_arguments(cx, arguments, method_type, path.ident.as_str(), "method"); }, _ => (), diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index f5e21267a897..0bb577b7620b 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -4,7 +4,7 @@ use clippy_utils::ty::is_c_void; use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_middle::ty::subst::{Subst, SubstsRef}; -use rustc_middle::ty::{self, IntTy, Ty, TypeAndMut, UintTy}; +use rustc_middle::ty::{self, EarlyBinder, IntTy, Ty, TypeAndMut, UintTy}; use rustc_span::Span; #[allow(clippy::too_many_lines)] @@ -307,7 +307,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> .non_enum_variant() .fields .iter() - .map(|f| cx.tcx.type_of(f.did).subst(cx.tcx, substs)); + .map(|f| EarlyBinder(cx.tcx.type_of(f.did)).subst(cx.tcx, substs)); let Some(sized_ty) = iter.find(|&ty| !is_zero_sized_ty(cx, ty)) else { return ReducedTy::TypeErasure; }; diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index fdb822c3e5b6..a80c7ee49295 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -9,7 +9,7 @@ use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, Item, ItemKind, use rustc_lint::LateContext; use rustc_middle::mir::interpret::Scalar; use rustc_middle::ty::subst::{Subst, SubstsRef}; -use rustc_middle::ty::{self, FloatTy, ScalarInt, Ty, TyCtxt}; +use rustc_middle::ty::{self, EarlyBinder, FloatTy, ScalarInt, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; use rustc_span::symbol::Symbol; use std::cmp::Ordering::{self, Equal}; @@ -420,7 +420,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let substs = if self.substs.is_empty() { substs } else { - substs.subst(self.lcx.tcx, self.substs) + EarlyBinder(substs).subst(self.lcx.tcx, self.substs) }; let result = self diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 901e3e5390c5..b46a7b86a759 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -13,7 +13,7 @@ use rustc_lint::LateContext; use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst}; use rustc_middle::ty::{ - self, AdtDef, Binder, FnSig, IntTy, Predicate, PredicateKind, Ty, TyCtxt, TypeFoldable, UintTy, VariantDiscr, + self, AdtDef, Binder, EarlyBinder, FnSig, IntTy, Predicate, PredicateKind, Ty, TyCtxt, TypeFoldable, UintTy, VariantDiscr, }; use rustc_span::symbol::Ident; use rustc_span::{sym, Span, Symbol, DUMMY_SP}; @@ -520,7 +520,7 @@ pub fn expr_sig<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option Some(ExprFnSig::Closure(subs.as_closure().sig())), - ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.fn_sig(id).subst(cx.tcx, subs))), + ty::FnDef(id, subs) => Some(ExprFnSig::Sig(EarlyBinder(cx.tcx.fn_sig(id)).subst(cx.tcx, subs))), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig)), ty::Dynamic(bounds, _) => { let lang_items = cx.tcx.lang_items(); From 7e6d2bdb95bcaf335c6d71a466f05d0a6dedaa74 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 11 May 2022 18:51:14 +0200 Subject: [PATCH 0496/1222] Bless clippy. --- tests/ui/crashes/ice-6252.stderr | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index c8239897f3ab..d930d486fde6 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -30,7 +30,15 @@ LL | const VAL: T; LL | impl TypeVal for Multiply where N: TypeVal {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation -error: aborting due to 3 previous errors +error: constant expression depends on a generic parameter + --> $DIR/ice-6252.rs:13:9 + | +LL | [1; >::VAL]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this may fail depending on what value the parameter takes + +error: aborting due to 4 previous errors Some errors have detailed explanations: E0046, E0412. For more information about an error, try `rustc --explain E0046`. From 8e7fedc5bf58a4d0eda045a85fdd3b25a75f380a Mon Sep 17 00:00:00 2001 From: Miguel Guarniz Date: Sat, 7 May 2022 14:51:05 -0400 Subject: [PATCH 0497/1222] remove TestItemNamesVisitor Signed-off-by: Miguel Guarniz --- clippy_utils/src/lib.rs | 58 ++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 98a073d122e3..6db7f247a992 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -74,11 +74,10 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_ID}; use rustc_hir::hir_id::{HirIdMap, HirIdSet}; use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; -use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::LangItem::{OptionNone, ResultErr, ResultOk}; use rustc_hir::{ def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Constness, Destination, Expr, ExprKind, FnDecl, - ForeignItem, HirId, Impl, ImplItem, ImplItemKind, IsAsync, Item, ItemKind, LangItem, Local, MatchSource, + HirId, Impl, ImplItem, ImplItemKind, IsAsync, Item, ItemKind, LangItem, Local, MatchSource, Mutability, Node, Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitRef, TyKind, UnOp, }; @@ -2068,35 +2067,6 @@ pub fn is_hir_ty_cfg_dependant(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool { false } -struct TestItemNamesVisitor<'tcx> { - tcx: TyCtxt<'tcx>, - names: Vec, -} - -impl<'hir> ItemLikeVisitor<'hir> for TestItemNamesVisitor<'hir> { - fn visit_item(&mut self, item: &Item<'_>) { - if let ItemKind::Const(ty, _body) = item.kind { - if let TyKind::Path(QPath::Resolved(_, path)) = ty.kind { - // We could also check for the type name `test::TestDescAndFn` - if let Res::Def(DefKind::Struct, _) = path.res { - let has_test_marker = self - .tcx - .hir() - .attrs(item.hir_id()) - .iter() - .any(|a| a.has_name(sym::rustc_test_marker)); - if has_test_marker { - self.names.push(item.ident.name); - } - } - } - } - } - fn visit_trait_item(&mut self, _: &TraitItem<'_>) {} - fn visit_impl_item(&mut self, _: &ImplItem<'_>) {} - fn visit_foreign_item(&mut self, _: &ForeignItem<'_>) {} -} - static TEST_ITEM_NAMES_CACHE: SyncOnceCell>>> = SyncOnceCell::new(); fn with_test_item_names<'tcx>(tcx: TyCtxt<'tcx>, module: LocalDefId, f: impl Fn(&[Symbol]) -> bool) -> bool { @@ -2105,10 +2075,28 @@ fn with_test_item_names<'tcx>(tcx: TyCtxt<'tcx>, module: LocalDefId, f: impl Fn( match map.entry(module) { Entry::Occupied(entry) => f(entry.get()), Entry::Vacant(entry) => { - let mut visitor = TestItemNamesVisitor { tcx, names: Vec::new() }; - tcx.hir().visit_item_likes_in_module(module, &mut visitor); - visitor.names.sort_unstable(); - f(&*entry.insert(visitor.names)) + let mut names = Vec::new(); + for id in tcx.hir().module_items(module) { + if matches!(tcx.def_kind(id.def_id), DefKind::Const) + && let item = tcx.hir().item(id) + && let ItemKind::Const(ty, _body) = item.kind { + if let TyKind::Path(QPath::Resolved(_, path)) = ty.kind { + // We could also check for the type name `test::TestDescAndFn` + if let Res::Def(DefKind::Struct, _) = path.res { + let has_test_marker = tcx + .hir() + .attrs(item.hir_id()) + .iter() + .any(|a| a.has_name(sym::rustc_test_marker)); + if has_test_marker { + names.push(item.ident.name); + } + } + } + } + } + names.sort_unstable(); + f(&*entry.insert(names)) }, } } From 511eba53882e52f6363d97ef4d53f595121b3d27 Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Sun, 8 May 2022 15:12:56 -0400 Subject: [PATCH 0498/1222] Add bound_type_of --- clippy_lints/src/eta_reduction.rs | 4 ++-- clippy_lints/src/mut_reference.rs | 4 ++-- clippy_lints/src/transmute/transmute_undefined_repr.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index b7776b3f0c38..530d6d4de35f 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -12,7 +12,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; use rustc_middle::ty::binding::BindingMode; use rustc_middle::ty::subst::Subst; -use rustc_middle::ty::{self, ClosureKind, EarlyBinder, Ty, TypeFoldable}; +use rustc_middle::ty::{self, ClosureKind, Ty, TypeFoldable}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; @@ -150,7 +150,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { if check_inputs(cx, body.params, args); let method_def_id = cx.typeck_results().type_dependent_def_id(body.value.hir_id).unwrap(); let substs = cx.typeck_results().node_substs(body.value.hir_id); - let call_ty = EarlyBinder(cx.tcx.type_of(method_def_id)).subst(cx.tcx, substs); + let call_ty = cx.tcx.bound_type_of(method_def_id).subst(cx.tcx, substs); if check_sig(cx, closure_ty, call_ty); then { span_lint_and_then(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure", |diag| { diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index a323737ae404..9d8f8999ce40 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::subst::Subst; -use rustc_middle::ty::{self, EarlyBinder, Ty}; +use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::iter; @@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed { ExprKind::MethodCall(path, arguments, _) => { let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap(); let substs = cx.typeck_results().node_substs(e.hir_id); - let method_type = EarlyBinder(cx.tcx.type_of(def_id)).subst(cx.tcx, substs); + let method_type = cx.tcx.bound_type_of(def_id).subst(cx.tcx, substs); check_arguments(cx, arguments, method_type, path.ident.as_str(), "method"); }, _ => (), diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index 0bb577b7620b..be6277332db4 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -4,7 +4,7 @@ use clippy_utils::ty::is_c_void; use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_middle::ty::subst::{Subst, SubstsRef}; -use rustc_middle::ty::{self, EarlyBinder, IntTy, Ty, TypeAndMut, UintTy}; +use rustc_middle::ty::{self, IntTy, Ty, TypeAndMut, UintTy}; use rustc_span::Span; #[allow(clippy::too_many_lines)] @@ -307,7 +307,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> .non_enum_variant() .fields .iter() - .map(|f| EarlyBinder(cx.tcx.type_of(f.did)).subst(cx.tcx, substs)); + .map(|f| cx.tcx.bound_type_of(f.did).subst(cx.tcx, substs)); let Some(sized_ty) = iter.find(|&ty| !is_zero_sized_ty(cx, ty)) else { return ReducedTy::TypeErasure; }; From 3f80db28ed862abbcf4423f4571bba9a07798f11 Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Sun, 8 May 2022 15:43:18 -0400 Subject: [PATCH 0499/1222] Add bound_fn_sig --- clippy_utils/src/ty.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index b46a7b86a759..8d99f3002b87 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -13,7 +13,7 @@ use rustc_lint::LateContext; use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst}; use rustc_middle::ty::{ - self, AdtDef, Binder, EarlyBinder, FnSig, IntTy, Predicate, PredicateKind, Ty, TyCtxt, TypeFoldable, UintTy, VariantDiscr, + self, AdtDef, Binder, FnSig, IntTy, Predicate, PredicateKind, Ty, TyCtxt, TypeFoldable, UintTy, VariantDiscr, }; use rustc_span::symbol::Ident; use rustc_span::{sym, Span, Symbol, DUMMY_SP}; @@ -520,7 +520,7 @@ pub fn expr_sig<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option Some(ExprFnSig::Closure(subs.as_closure().sig())), - ty::FnDef(id, subs) => Some(ExprFnSig::Sig(EarlyBinder(cx.tcx.fn_sig(id)).subst(cx.tcx, subs))), + ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs))), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig)), ty::Dynamic(bounds, _) => { let lang_items = cx.tcx.lang_items(); From 57c1a6fae8fb2e324e95c2fc4ec871aab9c41d4f Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 13 May 2022 13:50:21 +0000 Subject: [PATCH 0500/1222] Add a query for checking whether a function is an intrinsic. --- clippy_utils/src/qualify_min_const_fn.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 75808b1b1746..66d373a1bf81 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -14,7 +14,6 @@ use rustc_middle::ty::{self, adjustment::PointerCast, Ty, TyCtxt}; use rustc_semver::RustcVersion; use rustc_span::symbol::sym; use rustc_span::Span; -use rustc_target::spec::abi::Abi::RustIntrinsic; use std::borrow::Cow; type McfResult = Result<(), (Span, Cow<'static, str>)>; @@ -323,7 +322,7 @@ fn check_terminator<'a, 'tcx>( // within const fns. `transmute` is allowed in all other const contexts. // This won't really scale to more intrinsics or functions. Let's allow const // transmutes in const fn before we add more hacks to this. - if tcx.fn_sig(fn_def_id).abi() == RustIntrinsic && tcx.item_name(fn_def_id) == sym::transmute { + if tcx.is_intrinsic(fn_def_id) && tcx.item_name(fn_def_id) == sym::transmute { return Err(( span, "can only call `transmute` from const items, not `const fn`".into(), From b08435b557741281aa812babedd4b5abaa049784 Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Tue, 17 May 2022 08:41:01 +0800 Subject: [PATCH 0501/1222] Change `Successors` to `impl Iterator` --- clippy_lints/src/redundant_clone.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 1507c75ff612..37aac8b2a497 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone { } // Give up on loops - if terminator.successors().any(|s| *s == bb) { + if terminator.successors().any(|s| s == bb) { continue; } @@ -440,7 +440,7 @@ fn visit_clone_usage(cloned: mir::Local, clone: mir::Local, mir: &mir::Body<'_>, // Short-circuit if (usage.cloned_used && usage.clone_consumed_or_mutated) || // Give up on loops - tdata.terminator().successors().any(|s| *s == bb) + tdata.terminator().successors().any(|s| s == bb) { return CloneUsage { cloned_used: true, From 759e5ed21c74e70fa953f17927c67dea23ecb49e Mon Sep 17 00:00:00 2001 From: xFrednet Date: Sat, 21 May 2022 13:50:11 +0200 Subject: [PATCH 0502/1222] Fix lint registration --- clippy_lints/src/lib.register_lints.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_lints/src/lib.register_lints.rs b/clippy_lints/src/lib.register_lints.rs index 3350697ed7a4..5552ea8aa80a 100644 --- a/clippy_lints/src/lib.register_lints.rs +++ b/clippy_lints/src/lib.register_lints.rs @@ -479,7 +479,6 @@ store.register_lints(&[ size_of_in_element_count::SIZE_OF_IN_ELEMENT_COUNT, slow_vector_initialization::SLOW_VECTOR_INITIALIZATION, stable_sort_primitive::STABLE_SORT_PRIMITIVE, - significant_drop_in_scrutinee::SIGNIFICANT_DROP_IN_SCRUTINEE, strings::STRING_ADD, strings::STRING_ADD_ASSIGN, strings::STRING_FROM_UTF8_AS_BYTES, From b78006c7915bf49c76fd8b8a18b870dbf62012b1 Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Sat, 21 May 2022 13:53:26 -0400 Subject: [PATCH 0503/1222] Remove feature: `crate` visibility modifier --- clippy_utils/src/ast_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 7919800483f5..9aa379352089 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -545,7 +545,7 @@ pub fn eq_defaultness(l: Defaultness, r: Defaultness) -> bool { pub fn eq_vis(l: &Visibility, r: &Visibility) -> bool { use VisibilityKind::*; match (&l.kind, &r.kind) { - (Public, Public) | (Inherited, Inherited) | (Crate(_), Crate(_)) => true, + (Public, Public) | (Inherited, Inherited) | (Crate, Crate) => true, (Restricted { path: l, .. }, Restricted { path: r, .. }) => eq_path(l, r), _ => false, } From 8a83c828bff570a5c127b6ad6dc7a4c17c6dd7ca Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Sat, 21 May 2022 14:45:14 -0400 Subject: [PATCH 0504/1222] Merge crate and restricted visibilities --- clippy_utils/src/ast_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 9aa379352089..09e8fa4be41f 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -545,7 +545,7 @@ pub fn eq_defaultness(l: Defaultness, r: Defaultness) -> bool { pub fn eq_vis(l: &Visibility, r: &Visibility) -> bool { use VisibilityKind::*; match (&l.kind, &r.kind) { - (Public, Public) | (Inherited, Inherited) | (Crate, Crate) => true, + (Public, Public) | (Inherited, Inherited) => true, (Restricted { path: l, .. }, Restricted { path: r, .. }) => eq_path(l, r), _ => false, } From f4f771bccfa0276f9f53d33516df6aeec7c43e9c Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Fri, 1 Apr 2022 21:12:18 +0800 Subject: [PATCH 0505/1222] factor out the rvalue lifetime rule remove region_scope_tree from RegionCtxt Apply suggestions from code review Co-authored-by: Niko Matsakis --- clippy_lints/src/loops/needless_range_loop.rs | 76 +++++++++++++------ clippy_lints/src/shadow.rs | 46 +++++------ 2 files changed, 76 insertions(+), 46 deletions(-) diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 09f9c05b4fce..e2b82f9fd02a 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -3,7 +3,9 @@ use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_then}; use clippy_utils::source::snippet; use clippy_utils::ty::has_iter_method; use clippy_utils::visitors::is_local_used; -use clippy_utils::{contains_name, higher, is_integer_const, match_trait_method, paths, sugg, SpanlessEq}; +use clippy_utils::{ + contains_name, higher, is_integer_const, match_trait_method, paths, sugg, SpanlessEq, +}; use if_chain::if_chain; use rustc_ast::ast; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; @@ -27,12 +29,7 @@ pub(super) fn check<'tcx>( body: &'tcx Expr<'_>, expr: &'tcx Expr<'_>, ) { - if let Some(higher::Range { - start: Some(start), - ref end, - limits, - }) = higher::Range::hir(arg) - { + if let Some(higher::Range { start: Some(start), ref end, limits }) = higher::Range::hir(arg) { // the var must be a single name if let PatKind::Binding(_, canonical_id, ident, _) = pat.kind { let mut visitor = VarVisitor { @@ -58,7 +55,11 @@ pub(super) fn check<'tcx>( // ensure that the indexed variable was declared before the loop, see #601 if let Some(indexed_extent) = indexed_extent { let parent_def_id = cx.tcx.hir().get_parent_item(expr.hir_id); - let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id); + let parent_body_id = cx + .tcx + .hir() + .body_owned_by(cx.tcx.hir().local_def_id_to_hir_id(parent_def_id)); + let region_scope_tree = &cx.tcx.typeck_body(parent_body_id).region_scope_tree; let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id).unwrap(); if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) { return; @@ -107,17 +108,22 @@ pub(super) fn check<'tcx>( } } - if is_len_call(end, indexed) || is_end_eq_array_len(cx, end, limits, indexed_ty) { + if is_len_call(end, indexed) || is_end_eq_array_len(cx, end, limits, indexed_ty) + { String::new() - } else if visitor.indexed_mut.contains(&indexed) && contains_name(indexed, take_expr) { + } else if visitor.indexed_mut.contains(&indexed) + && contains_name(indexed, take_expr) + { return; } else { match limits { ast::RangeLimits::Closed => { let take_expr = sugg::Sugg::hir(cx, take_expr, ""); format!(".take({})", take_expr + sugg::ONE) - }, - ast::RangeLimits::HalfOpen => format!(".take({})", snippet(cx, take_expr.span, "..")), + } + ast::RangeLimits::HalfOpen => { + format!(".take({})", snippet(cx, take_expr.span, "..")) + } } } } else { @@ -143,7 +149,10 @@ pub(super) fn check<'tcx>( cx, NEEDLESS_RANGE_LOOP, arg.span, - &format!("the loop variable `{}` is used to index `{}`", ident.name, indexed), + &format!( + "the loop variable `{}` is used to index `{}`", + ident.name, indexed + ), |diag| { multispan_sugg( diag, @@ -152,7 +161,10 @@ pub(super) fn check<'tcx>( (pat.span, format!("({}, )", ident.name)), ( arg.span, - format!("{}.{}().enumerate(){}{}", indexed, method, method_1, method_2), + format!( + "{}.{}().enumerate(){}{}", + indexed, method, method_1, method_2 + ), ), ], ); @@ -169,7 +181,10 @@ pub(super) fn check<'tcx>( cx, NEEDLESS_RANGE_LOOP, arg.span, - &format!("the loop variable `{}` is only used to index `{}`", ident.name, indexed), + &format!( + "the loop variable `{}` is only used to index `{}`", + ident.name, indexed + ), |diag| { multispan_sugg( diag, @@ -246,7 +261,12 @@ struct VarVisitor<'a, 'tcx> { } impl<'a, 'tcx> VarVisitor<'a, 'tcx> { - fn check(&mut self, idx: &'tcx Expr<'_>, seqexpr: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) -> bool { + fn check( + &mut self, + idx: &'tcx Expr<'_>, + seqexpr: &'tcx Expr<'_>, + expr: &'tcx Expr<'_>, + ) -> bool { if_chain! { // the indexed container is referenced by a name if let ExprKind::Path(ref seqpath) = seqexpr.kind; @@ -262,7 +282,16 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { match res { Res::Local(hir_id) => { let parent_def_id = self.cx.tcx.hir().get_parent_item(expr.hir_id); - let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id).unwrap(); + let parent_body_id = self.cx + .tcx + .hir() + .body_owned_by(self.cx.tcx.hir().local_def_id_to_hir_id(parent_def_id)); + let extent = self.cx + .tcx + .typeck_body(parent_body_id) + .region_scope_tree + .var_scope(hir_id.local_id) + .unwrap(); if index_used_directly { self.indexed_directly.insert( seqvar.segments[0].ident.name, @@ -331,13 +360,13 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { self.visit_expr(lhs); self.prefer_mutable = false; self.visit_expr(rhs); - }, + } ExprKind::AddrOf(BorrowKind::Ref, mutbl, expr) => { if mutbl == Mutability::Mut { self.prefer_mutable = true; } self.visit_expr(expr); - }, + } ExprKind::Call(f, args) => { self.visit_expr(f); for expr in args { @@ -350,10 +379,11 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { } self.visit_expr(expr); } - }, + } ExprKind::MethodCall(_, args, _) => { let def_id = self.cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap(); - for (ty, expr) in iter::zip(self.cx.tcx.fn_sig(def_id).inputs().skip_binder(), args) { + for (ty, expr) in iter::zip(self.cx.tcx.fn_sig(def_id).inputs().skip_binder(), args) + { self.prefer_mutable = false; if let ty::Ref(_, _, mutbl) = *ty.kind() { if mutbl == Mutability::Mut { @@ -362,11 +392,11 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { } self.visit_expr(expr); } - }, + } ExprKind::Closure(_, _, body_id, ..) => { let body = self.cx.tcx.hir().body(body_id); self.visit_expr(&body.value); - }, + } _ => walk_expr(self, expr), } self.prefer_mutable = old; diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 1ab7f52110ce..db32b8d740b3 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -5,7 +5,9 @@ use rustc_data_structures::fx::FxHashMap; use rustc_hir::def::Res; use rustc_hir::def_id::LocalDefId; use rustc_hir::hir_id::ItemLocalId; -use rustc_hir::{Block, Body, BodyOwnerKind, Expr, ExprKind, HirId, Let, Node, Pat, PatKind, QPath, UnOp}; +use rustc_hir::{ + Block, Body, BodyOwnerKind, Expr, ExprKind, HirId, Let, Node, Pat, PatKind, QPath, UnOp, +}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{Span, Symbol}; @@ -139,27 +141,31 @@ impl<'tcx> LateLintPass<'tcx> for Shadow { fn check_body(&mut self, cx: &LateContext<'_>, body: &Body<'_>) { let hir = cx.tcx.hir(); - if !matches!( - hir.body_owner_kind(hir.body_owner_def_id(body.id())), - BodyOwnerKind::Closure - ) { + if !matches!(hir.body_owner_kind(hir.body_owner_def_id(body.id())), BodyOwnerKind::Closure) + { self.bindings.push(FxHashMap::default()); } } fn check_body_post(&mut self, cx: &LateContext<'_>, body: &Body<'_>) { let hir = cx.tcx.hir(); - if !matches!( - hir.body_owner_kind(hir.body_owner_def_id(body.id())), - BodyOwnerKind::Closure - ) { + if !matches!(hir.body_owner_kind(hir.body_owner_def_id(body.id())), BodyOwnerKind::Closure) + { self.bindings.pop(); } } } -fn is_shadow(cx: &LateContext<'_>, owner: LocalDefId, first: ItemLocalId, second: ItemLocalId) -> bool { - let scope_tree = cx.tcx.region_scope_tree(owner.to_def_id()); +fn is_shadow( + cx: &LateContext<'_>, + owner: LocalDefId, + first: ItemLocalId, + second: ItemLocalId, +) -> bool { + let scope_tree = &cx + .tcx + .typeck_body(cx.tcx.hir().body_owned_by(cx.tcx.hir().local_def_id_to_hir_id(owner))) + .region_scope_tree; let first_scope = scope_tree.var_scope(first).unwrap(); let second_scope = scope_tree.var_scope(second).unwrap(); scope_tree.is_subscope_of(second_scope, first_scope) @@ -174,15 +180,16 @@ fn lint_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, shadowed: HirId, span: Span) snippet(cx, expr.span, "..") ); (SHADOW_SAME, msg) - }, + } Some(expr) if is_local_used(cx, expr, shadowed) => { let msg = format!("`{}` is shadowed", snippet(cx, pat.span, "_")); (SHADOW_REUSE, msg) - }, + } _ => { - let msg = format!("`{}` shadows a previous, unrelated binding", snippet(cx, pat.span, "_")); + let msg = + format!("`{}` shadows a previous, unrelated binding", snippet(cx, pat.span, "_")); (SHADOW_UNRELATED, msg) - }, + } }; span_lint_and_note( cx, @@ -211,14 +218,7 @@ fn is_self_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, mut expr: &Expr<'_>, hir_ expr = match expr.kind { ExprKind::Box(e) | ExprKind::AddrOf(_, _, e) - | ExprKind::Block( - &Block { - stmts: [], - expr: Some(e), - .. - }, - _, - ) + | ExprKind::Block(&Block { stmts: [], expr: Some(e), .. }, _) | ExprKind::Unary(UnOp::Deref, e) => e, ExprKind::Path(QPath::Resolved(None, path)) => break path.res == Res::Local(hir_id), _ => break false, From ed959abd53d6df6c587a434bef16a9fe76734415 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 22 May 2022 17:39:44 -0700 Subject: [PATCH 0506/1222] Fix clippy explicit_write lint for new writeln implementation --- clippy_lints/src/explicit_write.rs | 36 ++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 3e2217c28da3..d8f765b288a6 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -4,7 +4,8 @@ use clippy_utils::source::snippet_with_applicability; use clippy_utils::{is_expn_of, match_function_call, paths}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind}; +use rustc_hir::def::Res; +use rustc_hir::{BindingAnnotation, Block, BlockCheckMode, Expr, ExprKind, Node, PatKind, QPath, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; @@ -39,7 +40,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite { if let ExprKind::MethodCall(unwrap_fun, [write_call], _) = expr.kind; if unwrap_fun.ident.name == sym::unwrap; // match call to write_fmt - if let ExprKind::MethodCall(write_fun, [write_recv, write_arg], _) = write_call.kind; + if let ExprKind::MethodCall(write_fun, [write_recv, write_arg], _) = look_in_block(cx, &write_call.kind); if write_fun.ident.name == sym!(write_fmt); // match calls to std::io::stdout() / std::io::stderr () if let Some(dest_name) = if match_function_call(cx, write_recv, &paths::STDOUT).is_some() { @@ -100,3 +101,34 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite { } } } + +/// If `kind` is a block that looks like `{ let result = $expr; result }` then +/// returns $expr. Otherwise returns `kind`. +fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>) -> &'tcx ExprKind<'hir> { + if_chain! { + if let ExprKind::Block(block, _label @ None) = kind; + if let Block { + stmts: [Stmt { kind: StmtKind::Local(local), .. }], + expr: Some(expr_end_of_block), + rules: BlockCheckMode::DefaultBlock, + .. + } = block; + + // Find id of the local that expr_end_of_block resolves to + if let ExprKind::Path(QPath::Resolved(None, expr_path)) = expr_end_of_block.kind; + if let Res::Local(expr_res) = expr_path.res; + if let Some(Node::Binding(res_pat)) = cx.tcx.hir().find(expr_res); + + // Find id of the local we found in the block + if let PatKind::Binding(BindingAnnotation::Unannotated, local_hir_id, _ident, None) = local.pat.kind; + + // If those two are the same hir id + if res_pat.hir_id == local_hir_id; + + if let Some(init) = local.init; + then { + return &init.kind; + } + } + kind +} From 812120f4de6a813bcd1b32c22aa9322e5e8af0f2 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 23 May 2022 08:48:17 -0700 Subject: [PATCH 0507/1222] Lifetime variance fixes for clippy --- clippy_lints/src/casts/unnecessary_cast.rs | 12 ++++++------ clippy_lints/src/dereference.rs | 10 +++++----- clippy_lints/src/len_zero.rs | 12 ++++++------ clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/ptr.rs | 6 +++--- .../src/transmute/transmute_undefined_repr.rs | 2 +- clippy_utils/src/ty.rs | 4 ++-- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/clippy_lints/src/casts/unnecessary_cast.rs b/clippy_lints/src/casts/unnecessary_cast.rs index af56ec11ef8a..fff7da8e33f2 100644 --- a/clippy_lints/src/casts/unnecessary_cast.rs +++ b/clippy_lints/src/casts/unnecessary_cast.rs @@ -12,12 +12,12 @@ use rustc_middle::ty::{self, FloatTy, InferTy, Ty}; use super::UNNECESSARY_CAST; -pub(super) fn check( - cx: &LateContext<'_>, - expr: &Expr<'_>, - cast_expr: &Expr<'_>, - cast_from: Ty<'_>, - cast_to: Ty<'_>, +pub(super) fn check<'tcx>( + cx: &LateContext<'tcx>, + expr: &Expr<'tcx>, + cast_expr: &Expr<'tcx>, + cast_from: Ty<'tcx>, + cast_to: Ty<'tcx>, ) -> bool { // skip non-primitive type cast if_chain! { diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index ea4c0207bb01..8288f7a8b9b6 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -446,7 +446,7 @@ fn try_parse_ref_op<'tcx>( // Checks whether the type for a deref call actually changed the type, not just the mutability of // the reference. -fn deref_method_same_type(result_ty: Ty<'_>, arg_ty: Ty<'_>) -> bool { +fn deref_method_same_type<'tcx>(result_ty: Ty<'tcx>, arg_ty: Ty<'tcx>) -> bool { match (result_ty.kind(), arg_ty.kind()) { (ty::Ref(_, result_ty, _), ty::Ref(_, arg_ty, _)) => result_ty == arg_ty, @@ -541,8 +541,8 @@ fn is_auto_borrow_position(parent: Option>, child_id: HirId) -> bool { /// Adjustments are sometimes made in the parent block rather than the expression itself. fn find_adjustments<'tcx>( tcx: TyCtxt<'tcx>, - typeck: &'tcx TypeckResults<'_>, - expr: &'tcx Expr<'_>, + typeck: &'tcx TypeckResults<'tcx>, + expr: &'tcx Expr<'tcx>, ) -> &'tcx [Adjustment<'tcx>] { let map = tcx.hir(); let mut iter = map.parent_iter(expr.hir_id); @@ -581,7 +581,7 @@ fn find_adjustments<'tcx>( } #[expect(clippy::needless_pass_by_value)] -fn report(cx: &LateContext<'_>, expr: &Expr<'_>, state: State, data: StateData) { +fn report<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, state: State, data: StateData) { match state { State::DerefMethod { ty_changed_count, @@ -656,7 +656,7 @@ fn report(cx: &LateContext<'_>, expr: &Expr<'_>, state: State, data: StateData) } impl Dereferencing { - fn check_local_usage(&mut self, cx: &LateContext<'_>, e: &Expr<'_>, local: HirId) { + fn check_local_usage<'tcx>(&mut self, cx: &LateContext<'tcx>, e: &Expr<'tcx>, local: HirId) { if let Some(outer_pat) = self.ref_locals.get_mut(&local) { if let Some(pat) = outer_pat { // Check for auto-deref diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index dabbb8375f0a..246f5aad8fba 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -259,8 +259,8 @@ fn parse_len_output<'tcx>(cx: &LateContext<'_>, sig: FnSig<'tcx>) -> Option { - fn matches_is_empty_output(self, ty: Ty<'_>) -> bool { +impl<'tcx> LenOutput<'tcx> { + fn matches_is_empty_output(self, ty: Ty<'tcx>) -> bool { match (self, ty.kind()) { (_, &ty::Bool) => true, (Self::Option(id), &ty::Adt(adt, subs)) if id == adt.did() => subs.type_at(0).is_bool(), @@ -292,7 +292,7 @@ impl LenOutput<'_> { } /// Checks if the given signature matches the expectations for `is_empty` -fn check_is_empty_sig(sig: FnSig<'_>, self_kind: ImplicitSelfKind, len_output: LenOutput<'_>) -> bool { +fn check_is_empty_sig<'tcx>(sig: FnSig<'tcx>, self_kind: ImplicitSelfKind, len_output: LenOutput<'tcx>) -> bool { match &**sig.inputs_and_output { [arg, res] if len_output.matches_is_empty_output(*res) => { matches!( @@ -306,11 +306,11 @@ fn check_is_empty_sig(sig: FnSig<'_>, self_kind: ImplicitSelfKind, len_output: L } /// Checks if the given type has an `is_empty` method with the appropriate signature. -fn check_for_is_empty( - cx: &LateContext<'_>, +fn check_for_is_empty<'tcx>( + cx: &LateContext<'tcx>, span: Span, self_kind: ImplicitSelfKind, - output: LenOutput<'_>, + output: LenOutput<'tcx>, impl_ty: DefId, item_name: Symbol, item_kind: &str, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 35fc452ed7cf..3bf48e18019d 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2843,7 +2843,7 @@ enum SelfKind { impl SelfKind { fn matches<'a>(self, cx: &LateContext<'a>, parent_ty: Ty<'a>, ty: Ty<'a>) -> bool { - fn matches_value<'a>(cx: &LateContext<'a>, parent_ty: Ty<'_>, ty: Ty<'_>) -> bool { + fn matches_value<'a>(cx: &LateContext<'a>, parent_ty: Ty<'a>, ty: Ty<'a>) -> bool { if ty == parent_ty { true } else if ty.is_box() { diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 86460c1b27e3..548f7b2528b1 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -395,9 +395,9 @@ impl<'tcx> DerefTy<'tcx> { fn check_fn_args<'cx, 'tcx: 'cx>( cx: &'cx LateContext<'tcx>, - tys: &'tcx [Ty<'_>], - hir_tys: &'tcx [hir::Ty<'_>], - params: &'tcx [Param<'_>], + tys: &'tcx [Ty<'tcx>], + hir_tys: &'tcx [hir::Ty<'tcx>], + params: &'tcx [Param<'tcx>], ) -> impl Iterator> + 'cx { tys.iter() .zip(hir_tys.iter()) diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index be6277332db4..20b348fc14f7 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -358,7 +358,7 @@ fn is_size_pair(ty: Ty<'_>) -> bool { } } -fn same_except_params(subs1: SubstsRef<'_>, subs2: SubstsRef<'_>) -> bool { +fn same_except_params<'tcx>(subs1: SubstsRef<'tcx>, subs2: SubstsRef<'tcx>) -> bool { // TODO: check const parameters as well. Currently this will consider `Array<5>` the same as // `Array<6>` for (ty1, ty2) in subs1.types().zip(subs2.types()).filter(|(ty1, ty2)| ty1 != ty2) { diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 07d3d2807634..75d27d3b5948 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -42,7 +42,7 @@ pub fn can_partially_move_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool } /// Walks into `ty` and returns `true` if any inner type is the same as `other_ty` -pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool { +pub fn contains_ty<'tcx>(ty: Ty<'tcx>, other_ty: Ty<'tcx>) -> bool { ty.walk().any(|inner| match inner.unpack() { GenericArgKind::Type(inner_ty) => other_ty == inner_ty, GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false, @@ -51,7 +51,7 @@ pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool { /// Walks into `ty` and returns `true` if any inner type is an instance of the given adt /// constructor. -pub fn contains_adt_constructor(ty: Ty<'_>, adt: AdtDef<'_>) -> bool { +pub fn contains_adt_constructor<'tcx>(ty: Ty<'tcx>, adt: AdtDef<'tcx>) -> bool { ty.walk().any(|inner| match inner.unpack() { GenericArgKind::Type(inner_ty) => inner_ty.ty_adt_def() == Some(adt), GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false, From 24c6e87201a152ddcd76aee2d34f35d1bbf44e2c Mon Sep 17 00:00:00 2001 From: Jakob Degen Date: Sat, 16 Apr 2022 09:27:54 -0400 Subject: [PATCH 0508/1222] Refactor call terminator to always hold a destination place --- clippy_lints/src/redundant_clone.rs | 4 ++-- clippy_utils/src/qualify_min_const_fn.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 0004b8afdd37..ab16fe47d4df 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -292,7 +292,7 @@ fn is_call_with_ref_arg<'tcx>( if let (inner_ty, 1) = walk_ptrs_ty_depth(args[0].ty(&*mir, cx.tcx)); if !is_copy(cx, inner_ty); then { - Some((def_id, *local, inner_ty, destination.as_ref().map(|(dest, _)| dest)?.as_local()?)) + Some((def_id, *local, inner_ty, destination.as_local()?)) } else { None } @@ -584,7 +584,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { fn visit_terminator(&mut self, terminator: &mir::Terminator<'_>, _loc: mir::Location) { if let mir::TerminatorKind::Call { args, - destination: Some((mir::Place { local: dest, .. }, _)), + destination: mir::Place { local: dest, .. }, .. } = &terminator.kind { diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index a6d7042fabc2..78d8f1e213af 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -301,6 +301,7 @@ fn check_terminator<'a, 'tcx>( args, from_hir_call: _, destination: _, + target: _, cleanup: _, fn_span: _, } => { From 15096ea85712e0f4f5e6cbe19b62bd80ae0ffd0f Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Wed, 25 May 2022 13:52:32 +0800 Subject: [PATCH 0509/1222] try to cache region_scope_tree as a query --- clippy_lints/src/loops/needless_range_loop.rs | 13 ++----------- clippy_lints/src/shadow.rs | 5 +---- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index e2b82f9fd02a..4f85364965b6 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -55,11 +55,7 @@ pub(super) fn check<'tcx>( // ensure that the indexed variable was declared before the loop, see #601 if let Some(indexed_extent) = indexed_extent { let parent_def_id = cx.tcx.hir().get_parent_item(expr.hir_id); - let parent_body_id = cx - .tcx - .hir() - .body_owned_by(cx.tcx.hir().local_def_id_to_hir_id(parent_def_id)); - let region_scope_tree = &cx.tcx.typeck_body(parent_body_id).region_scope_tree; + let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id); let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id).unwrap(); if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) { return; @@ -282,14 +278,9 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { match res { Res::Local(hir_id) => { let parent_def_id = self.cx.tcx.hir().get_parent_item(expr.hir_id); - let parent_body_id = self.cx - .tcx - .hir() - .body_owned_by(self.cx.tcx.hir().local_def_id_to_hir_id(parent_def_id)); let extent = self.cx .tcx - .typeck_body(parent_body_id) - .region_scope_tree + .region_scope_tree(parent_def_id) .var_scope(hir_id.local_id) .unwrap(); if index_used_directly { diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index db32b8d740b3..2a80e6f918de 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -162,10 +162,7 @@ fn is_shadow( first: ItemLocalId, second: ItemLocalId, ) -> bool { - let scope_tree = &cx - .tcx - .typeck_body(cx.tcx.hir().body_owned_by(cx.tcx.hir().local_def_id_to_hir_id(owner))) - .region_scope_tree; + let scope_tree = cx.tcx.region_scope_tree(owner); let first_scope = scope_tree.var_scope(first).unwrap(); let second_scope = scope_tree.var_scope(second).unwrap(); scope_tree.is_subscope_of(second_scope, first_scope) From 0f10b4b977e054dbb28f7371a2e6ee8815e1b161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Tue, 31 May 2022 00:00:00 +0000 Subject: [PATCH 0510/1222] Add a pointer to address cast kind A pointer to address cast are often special-cased. Introduce a dedicated cast kind to make them easy distinguishable. --- clippy_utils/src/qualify_min_const_fn.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 78d8f1e213af..283b20fc24d8 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -125,16 +125,11 @@ fn check_rvalue<'tcx>( Rvalue::Len(place) | Rvalue::Discriminant(place) | Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => { check_place(tcx, *place, span, body) }, - Rvalue::Cast(CastKind::Misc, operand, cast_ty) => { - use rustc_middle::ty::cast::CastTy; - let cast_in = CastTy::from_ty(operand.ty(body, tcx)).expect("bad input type for cast"); - let cast_out = CastTy::from_ty(*cast_ty).expect("bad output type for cast"); - match (cast_in, cast_out) { - (CastTy::Ptr(_) | CastTy::FnPtr, CastTy::Int(_)) => { - Err((span, "casting pointers to ints is unstable in const fn".into())) - }, - _ => check_operand(tcx, operand, span, body), - } + Rvalue::Cast(CastKind::PointerAddress, _, _) => { + Err((span, "casting pointers to ints is unstable in const fn".into())) + }, + Rvalue::Cast(CastKind::Misc, operand, _) => { + check_operand(tcx, operand, span, body) }, Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer | PointerCast::ArrayToPointer), operand, _) => { check_operand(tcx, operand, span, body) From 510858a9ce6caacf443bd34553612e69fae7e2ed Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 30 May 2022 15:59:45 +1000 Subject: [PATCH 0511/1222] Lazify `SourceFile::lines`. `SourceFile::lines` is a big part of metadata. It's stored in a compressed form (a difference list) to save disk space. Decoding it is a big fraction of compile time for very small crates/programs. This commit introduces a new type `SourceFileLines` which has a `Lines` form and a `Diffs` form. The latter is used when the metadata is first read, and it is only decoded into the `Lines` form when line data is actually needed. This avoids the decoding cost for many files, especially in `std`. It's a performance win of up to 15% for tiny crates/programs where metadata decoding is a high part of compilation costs. A `Lock` is needed because the methods that access lines data (which can trigger decoding) take `&self` rather than `&mut self`. To allow for this, `SourceFile::lines` now takes a `FnMut` that operates on the lines slice rather than returning the lines slice. --- .../src/undocumented_unsafe_blocks.rs | 36 +++++++++++-------- clippy_utils/src/diagnostics.rs | 4 +-- clippy_utils/src/lib.rs | 2 +- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index 5a8677f90be4..025dd57e83aa 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -187,11 +187,13 @@ fn item_has_safety_comment(cx: &LateContext<'_>, item: &hir::Item<'_>) -> bool { && Lrc::ptr_eq(&unsafe_line.sf, &comment_start_line.sf) && let Some(src) = unsafe_line.sf.src.as_deref() { - comment_start_line.line < unsafe_line.line && text_has_safety_comment( - src, - &unsafe_line.sf.lines[comment_start_line.line + 1..=unsafe_line.line], - unsafe_line.sf.start_pos.to_usize(), - ) + unsafe_line.sf.lines(|lines| { + comment_start_line.line < unsafe_line.line && text_has_safety_comment( + src, + &lines[comment_start_line.line + 1..=unsafe_line.line], + unsafe_line.sf.start_pos.to_usize(), + ) + }) } else { // Problem getting source text. Pretend a comment was found. true @@ -249,11 +251,13 @@ fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span && Lrc::ptr_eq(&unsafe_line.sf, ¯o_line.sf) && let Some(src) = unsafe_line.sf.src.as_deref() { - macro_line.line < unsafe_line.line && text_has_safety_comment( - src, - &unsafe_line.sf.lines[macro_line.line + 1..=unsafe_line.line], - unsafe_line.sf.start_pos.to_usize(), - ) + unsafe_line.sf.lines(|lines| { + macro_line.line < unsafe_line.line && text_has_safety_comment( + src, + &lines[macro_line.line + 1..=unsafe_line.line], + unsafe_line.sf.start_pos.to_usize(), + ) + }) } else { // Problem getting source text. Pretend a comment was found. true @@ -276,11 +280,13 @@ fn span_in_body_has_safety_comment(cx: &LateContext<'_>, span: Span) -> bool { // Get the text from the start of function body to the unsafe block. // fn foo() { some_stuff; unsafe { stuff }; other_stuff; } // ^-------------^ - body_line.line < unsafe_line.line && text_has_safety_comment( - src, - &unsafe_line.sf.lines[body_line.line + 1..=unsafe_line.line], - unsafe_line.sf.start_pos.to_usize(), - ) + unsafe_line.sf.lines(|lines| { + body_line.line < unsafe_line.line && text_has_safety_comment( + src, + &lines[body_line.line + 1..=unsafe_line.line], + unsafe_line.sf.start_pos.to_usize(), + ) + }) } else { // Problem getting source text. Pretend a comment was found. true diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs index 4e037d88494d..39595f589c70 100644 --- a/clippy_utils/src/diagnostics.rs +++ b/clippy_utils/src/diagnostics.rs @@ -283,10 +283,10 @@ pub fn span_lint_and_sugg_for_edges( { let split_idx = MAX_SUGGESTION_HIGHLIGHT_LINES / 2; let span_upper = sm.span_until_char( - sp.with_hi(line_upper.sf.lines[line_upper.line + split_idx]), + sp.with_hi(line_upper.sf.lines(|lines| lines[line_upper.line + split_idx])), '\n', ); - let span_bottom = sp.with_lo(line_bottom.sf.lines[line_bottom.line - split_idx]); + let span_bottom = sp.with_lo(line_bottom.sf.lines(|lines| lines[line_bottom.line - split_idx])); let sugg_lines_vec = sugg.lines().collect::>(); let sugg_upper = sugg_lines_vec[..split_idx].join("\n"); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index adb37cc9d751..833f8cde63ab 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1149,7 +1149,7 @@ fn line_span(cx: &T, span: Span) -> Span { let span = original_sp(span, DUMMY_SP); let source_map_and_line = cx.sess().source_map().lookup_line(span.lo()).unwrap(); let line_no = source_map_and_line.line; - let line_start = source_map_and_line.sf.lines[line_no]; + let line_start = source_map_and_line.sf.lines(|lines| lines[line_no]); span.with_lo(line_start) } From 1f7757d7f4334d9de189b90ba1a12abf0e766fda Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 1 Jun 2022 13:24:44 -0400 Subject: [PATCH 0512/1222] =?UTF-8?q?rename=20PointerAddress=20=E2=86=92?= =?UTF-8?q?=20PointerExposeAddress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 283b20fc24d8..b1c82ac76e8e 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -125,7 +125,7 @@ fn check_rvalue<'tcx>( Rvalue::Len(place) | Rvalue::Discriminant(place) | Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => { check_place(tcx, *place, span, body) }, - Rvalue::Cast(CastKind::PointerAddress, _, _) => { + Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => { Err((span, "casting pointers to ints is unstable in const fn".into())) }, Rvalue::Cast(CastKind::Misc, operand, _) => { From 0ff1fa96579ff4e3bcaa68b05c352f6ee2d280b3 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 2 Jun 2022 09:05:37 -0400 Subject: [PATCH 0513/1222] add cast kind of from_exposed_addr (int-to-ptr casts) --- clippy_utils/src/qualify_min_const_fn.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index b1c82ac76e8e..58abef38ea8b 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -131,7 +131,12 @@ fn check_rvalue<'tcx>( Rvalue::Cast(CastKind::Misc, operand, _) => { check_operand(tcx, operand, span, body) }, - Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer | PointerCast::ArrayToPointer), operand, _) => { + Rvalue::Cast( + CastKind::PointerFromExposedAddress + | CastKind::Pointer(PointerCast::MutToConstPointer | PointerCast::ArrayToPointer), + operand, + _ + ) => { check_operand(tcx, operand, span, body) }, Rvalue::Cast( From 76f07155b95476bdd01c90ab6031e164a0a5da66 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 27 Apr 2022 22:15:58 +0200 Subject: [PATCH 0514/1222] Manipulate lifetimes by LocalDefId for region resolution. --- clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/ptr.rs | 2 +- clippy_utils/src/hir_utils.rs | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 51d5b510ab93..070c7e591420 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -371,7 +371,7 @@ impl<'a, 'tcx> RefVisitor<'a, 'tcx> { if let Some(ref lt) = *lifetime { if lt.name == LifetimeName::Static { self.lts.push(RefLt::Static); - } else if let LifetimeName::Param(ParamName::Fresh(_)) = lt.name { + } else if let LifetimeName::Param(_, ParamName::Fresh) = lt.name { // Fresh lifetimes generated should be ignored. } else if lt.is_elided() { self.lts.push(RefLt::Unnamed); diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 548f7b2528b1..0b96f6ff6835 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -343,7 +343,7 @@ impl fmt::Display for RefPrefix { use fmt::Write; f.write_char('&')?; match self.lt { - LifetimeName::Param(ParamName::Plain(name)) => { + LifetimeName::Param(_, ParamName::Plain(name)) => { name.fmt(f)?; f.write_char(' ')?; }, diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index c440793b90e0..fc1a4e1f6025 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -902,16 +902,14 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { pub fn hash_lifetime(&mut self, lifetime: Lifetime) { std::mem::discriminant(&lifetime.name).hash(&mut self.s); - if let LifetimeName::Param(ref name) = lifetime.name { + if let LifetimeName::Param(param_id, ref name) = lifetime.name { std::mem::discriminant(name).hash(&mut self.s); + param_id.hash(&mut self.s); match name { ParamName::Plain(ref ident) => { ident.name.hash(&mut self.s); }, - ParamName::Fresh(ref size) => { - size.hash(&mut self.s); - }, - ParamName::Error => {}, + ParamName::Fresh | ParamName::Error => {}, } } } From 8a13784241511d6b870ac28a5077324554c234a4 Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Fri, 1 Apr 2022 13:13:25 -0400 Subject: [PATCH 0515/1222] Fully stabilize NLL --- tests/ui/crashes/ice-6256.stderr | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tests/ui/crashes/ice-6256.stderr b/tests/ui/crashes/ice-6256.stderr index ae4e6cad3328..9cfcccf1e3cd 100644 --- a/tests/ui/crashes/ice-6256.stderr +++ b/tests/ui/crashes/ice-6256.stderr @@ -1,18 +1,14 @@ -error[E0308]: mismatched types - --> $DIR/ice-6256.rs:13:28 +error[E0521]: borrowed data escapes outside of closure + --> $DIR/ice-6256.rs:13:26 | LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types - | ^^^^ lifetime mismatch - | - = note: expected reference `&(dyn TT + 'static)` - found reference `&dyn TT` -note: the anonymous lifetime #1 defined here... - --> $DIR/ice-6256.rs:13:13 - | -LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types - | ^^^^^^^^^^^^^^^^^^^^^ - = note: ...does not necessarily outlive the static lifetime + | - - ^^^^^^^^ + | | | | + | | | `x` escapes the closure body here + | | | argument requires that `'1` must outlive `'static` + | | let's call the lifetime of this reference `'1` + | `x` is a reference that is only valid in the closure body error: aborting due to previous error -For more information about this error, try `rustc --explain E0308`. +For more information about this error, try `rustc --explain E0521`. From cb27407dff8c2a1f9e3e4d1d3f6e51cb5d619605 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Sat, 4 Jun 2022 14:04:35 +0200 Subject: [PATCH 0516/1222] Remove unnecessary clap_derive dependency added in 9ee211af The fixed issue in this commit can be tested without depending on clap/clap_derive. This updates the test case to do so. --- Cargo.toml | 1 - tests/compile-test.rs | 3 --- tests/ui/auxiliary/proc_macro_attr.rs | 5 +++++ tests/ui/empty_line_after_outer_attribute.rs | 9 +++------ tests/ui/empty_line_after_outer_attribute.stderr | 12 ++++++------ 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d23d681df00c..3c8b758d53dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,6 @@ filetime = "0.2" rustc-workspace-hack = "1.0" # UI test dependencies -clap = { version = "3.1", features = ["derive"] } clippy_utils = { path = "clippy_utils" } derive-new = "0.5" if_chain = "1.0" diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 7d2198357232..04c2eeff08b6 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -23,7 +23,6 @@ const RUN_INTERNAL_TESTS: bool = cfg!(feature = "internal"); /// All crates used in UI tests are listed here static TEST_DEPENDENCIES: &[&str] = &[ - "clap", "clippy_utils", "derive_new", "futures", @@ -42,8 +41,6 @@ static TEST_DEPENDENCIES: &[&str] = &[ // Test dependencies may need an `extern crate` here to ensure that they show up // in the depinfo file (otherwise cargo thinks they are unused) #[allow(unused_extern_crates)] -extern crate clap; -#[allow(unused_extern_crates)] extern crate clippy_utils; #[allow(unused_extern_crates)] extern crate derive_new; diff --git a/tests/ui/auxiliary/proc_macro_attr.rs b/tests/ui/auxiliary/proc_macro_attr.rs index e370a98df1ac..ae2cc2492f41 100644 --- a/tests/ui/auxiliary/proc_macro_attr.rs +++ b/tests/ui/auxiliary/proc_macro_attr.rs @@ -19,6 +19,11 @@ use syn::{ parse_quote, FnArg, ImplItem, ItemImpl, ItemTrait, Lifetime, Pat, PatIdent, PatType, Signature, TraitItem, Type, }; +#[proc_macro_attribute] +pub fn dummy(_args: TokenStream, input: TokenStream) -> TokenStream { + input +} + #[proc_macro_attribute] pub fn fake_async_trait(_args: TokenStream, input: TokenStream) -> TokenStream { let mut item = parse_macro_input!(input as ItemTrait); diff --git a/tests/ui/empty_line_after_outer_attribute.rs b/tests/ui/empty_line_after_outer_attribute.rs index d15c84d7438a..697412c00275 100644 --- a/tests/ui/empty_line_after_outer_attribute.rs +++ b/tests/ui/empty_line_after_outer_attribute.rs @@ -4,9 +4,6 @@ #![feature(custom_inner_attributes)] #![rustfmt::skip] -#[macro_use] -extern crate clap; - #[macro_use] extern crate proc_macro_attr; @@ -113,10 +110,10 @@ pub trait Bazz { } } -#[derive(clap::Parser)] -#[clap(after_help = "This ia a help message. +#[derive(Clone, Copy)] +#[dummy(string = "first line -You're welcome. +second line ")] pub struct Args; diff --git a/tests/ui/empty_line_after_outer_attribute.stderr b/tests/ui/empty_line_after_outer_attribute.stderr index acc3edef9b92..594fca44a321 100644 --- a/tests/ui/empty_line_after_outer_attribute.stderr +++ b/tests/ui/empty_line_after_outer_attribute.stderr @@ -1,5 +1,5 @@ error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:14:1 + --> $DIR/empty_line_after_outer_attribute.rs:11:1 | LL | / #[crate_type = "lib"] LL | | @@ -10,7 +10,7 @@ LL | | fn with_one_newline_and_comment() { assert!(true) } = note: `-D clippy::empty-line-after-outer-attr` implied by `-D warnings` error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:26:1 + --> $DIR/empty_line_after_outer_attribute.rs:23:1 | LL | / #[crate_type = "lib"] LL | | @@ -18,7 +18,7 @@ LL | | fn with_one_newline() { assert!(true) } | |_ error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:31:1 + --> $DIR/empty_line_after_outer_attribute.rs:28:1 | LL | / #[crate_type = "lib"] LL | | @@ -27,7 +27,7 @@ LL | | fn with_two_newlines() { assert!(true) } | |_ error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:38:1 + --> $DIR/empty_line_after_outer_attribute.rs:35:1 | LL | / #[crate_type = "lib"] LL | | @@ -35,7 +35,7 @@ LL | | enum Baz { | |_ error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:46:1 + --> $DIR/empty_line_after_outer_attribute.rs:43:1 | LL | / #[crate_type = "lib"] LL | | @@ -43,7 +43,7 @@ LL | | struct Foo { | |_ error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? - --> $DIR/empty_line_after_outer_attribute.rs:54:1 + --> $DIR/empty_line_after_outer_attribute.rs:51:1 | LL | / #[crate_type = "lib"] LL | | From e02f3de1371173b1a93790425e7e832d397b1916 Mon Sep 17 00:00:00 2001 From: Ikko Ashimine Date: Mon, 6 Jun 2022 21:16:31 +0900 Subject: [PATCH 0517/1222] Fix typo in redundant_pattern_match.rs alway -> always --- clippy_lints/src/matches/redundant_pattern_match.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/matches/redundant_pattern_match.rs b/clippy_lints/src/matches/redundant_pattern_match.rs index 1a8b9d15f370..b1728b0ae18c 100644 --- a/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/clippy_lints/src/matches/redundant_pattern_match.rs @@ -68,7 +68,7 @@ fn temporaries_need_ordered_drop<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr< } } }, - // the base type is alway taken by reference. + // the base type is always taken by reference. // e.g. In `(vec![0])[0]` the vector is a temporary value. ExprKind::Index(base, index) => { if !matches!(base.kind, ExprKind::Path(_)) { From 4f118ecbaf112f23c29839372dccadad9496b885 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 2 Jun 2022 11:38:15 +1000 Subject: [PATCH 0518/1222] Folding revamp. This commit makes type folding more like the way chalk does it. Currently, `TypeFoldable` has `fold_with` and `super_fold_with` methods. - `fold_with` is the standard entry point, and defaults to calling `super_fold_with`. - `super_fold_with` does the actual work of traversing a type. - For a few types of interest (`Ty`, `Region`, etc.) `fold_with` instead calls into a `TypeFolder`, which can then call back into `super_fold_with`. With the new approach, `TypeFoldable` has `fold_with` and `TypeSuperFoldable` has `super_fold_with`. - `fold_with` is still the standard entry point, *and* it does the actual work of traversing a type, for all types except types of interest. - `super_fold_with` is only implemented for the types of interest. Benefits of the new model. - I find it easier to understand. The distinction between types of interest and other types is clearer, and `super_fold_with` doesn't exist for most types. - With the current model is easy to get confused and implement a `super_fold_with` method that should be left defaulted. (Some of the precursor commits fixed such cases.) - With the current model it's easy to call `super_fold_with` within `TypeFolder` impls where `fold_with` should be called. The new approach makes this mistake impossible, and this commit fixes a number of such cases. - It's potentially faster, because it avoids the `fold_with` -> `super_fold_with` call in all cases except types of interest. A lot of the time the compile would inline those away, but not necessarily always. --- clippy_lints/src/unit_types/let_unit_value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index d86002c926ef..27678c8ba3c4 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::{Expr, ExprKind, PatKind, Stmt, StmtKind}; use rustc_lint::{LateContext, LintContext}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, Ty, TypeFoldable, TypeVisitor}; +use rustc_middle::ty::{self, Ty, TypeFoldable, TypeSuperFoldable, TypeVisitor}; use super::LET_UNIT_VALUE; From d3d8ef2ff1cca8ca74973f9b8501f94271b92632 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 11 Jun 2022 21:25:25 +0200 Subject: [PATCH 0519/1222] Make `ExprKind::Closure` a struct variant. --- clippy_lints/src/blocks_in_if_conditions.rs | 4 +- clippy_lints/src/bytecount.rs | 4 +- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/eta_reduction.rs | 2 +- clippy_lints/src/infinite_iter.rs | 4 +- clippy_lints/src/loops/needless_range_loop.rs | 4 +- clippy_lints/src/loops/never_loop.rs | 2 +- .../src/loops/while_let_on_iterator.rs | 6 +-- clippy_lints/src/manual_async_fn.rs | 4 +- clippy_lints/src/manual_ok_or.rs | 4 +- clippy_lints/src/map_clone.rs | 4 +- clippy_lints/src/map_err_ignore.rs | 17 +++++--- clippy_lints/src/map_unit_fn.rs | 8 ++-- .../src/matches/match_single_binding.rs | 2 +- .../matches/significant_drop_in_scrutinee.rs | 2 +- .../src/methods/bind_instead_of_map.rs | 6 +-- clippy_lints/src/methods/filter_map.rs | 8 ++-- .../src/methods/option_as_ref_deref.rs | 4 +- .../src/methods/option_map_or_none.rs | 41 +++++++++---------- clippy_lints/src/methods/search_is_some.rs | 4 +- .../src/methods/unnecessary_filter_map.rs | 4 +- clippy_lints/src/methods/unnecessary_fold.rs | 4 +- .../src/methods/unnecessary_lazy_eval.rs | 4 +- .../src/mixed_read_write_in_expression.rs | 6 +-- clippy_lints/src/needless_for_each.rs | 4 +- clippy_lints/src/no_effect.rs | 2 +- clippy_lints/src/only_used_in_recursion.rs | 4 +- clippy_lints/src/redundant_closure_call.rs | 2 +- clippy_lints/src/unit_return_expecting_ord.rs | 8 ++-- clippy_lints/src/unnecessary_sort_by.rs | 2 +- clippy_lints/src/utils/author.rs | 10 ++++- clippy_utils/src/eager_or_lazy.rs | 2 +- clippy_utils/src/hir_utils.rs | 8 ++-- clippy_utils/src/lib.rs | 8 ++-- clippy_utils/src/sugg.rs | 8 ++-- clippy_utils/src/usage.rs | 2 +- 36 files changed, 112 insertions(+), 98 deletions(-) diff --git a/clippy_lints/src/blocks_in_if_conditions.rs b/clippy_lints/src/blocks_in_if_conditions.rs index 5bd7a342389f..4b3a04f1255b 100644 --- a/clippy_lints/src/blocks_in_if_conditions.rs +++ b/clippy_lints/src/blocks_in_if_conditions.rs @@ -51,7 +51,7 @@ struct ExVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { - if let ExprKind::Closure(_, _, eid, _, _) = expr.kind { + if let ExprKind::Closure { body, .. } = expr.kind { // do not lint if the closure is called using an iterator (see #1141) if_chain! { if let Some(parent) = get_parent_expr(self.cx, expr); @@ -64,7 +64,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> { } } - let body = self.cx.tcx.hir().body(eid); + let body = self.cx.tcx.hir().body(body); let ex = &body.value; if let ExprKind::Block(block, _) = ex.kind { if !body.value.span.from_expansion() && !block.stmts.is_empty() { diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index bfdbaf2413a2..4e530256321c 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -51,8 +51,8 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount { if count.ident.name == sym::count; if let ExprKind::MethodCall(filter, [filter_recv, filter_arg], _) = count_recv.kind; if filter.ident.name == sym!(filter); - if let ExprKind::Closure(_, _, body_id, _, _) = filter_arg.kind; - let body = cx.tcx.hir().body(body_id); + if let ExprKind::Closure { body, .. } = filter_arg.kind; + let body = cx.tcx.hir().body(body); if let [param] = body.params; if let PatKind::Binding(_, arg_id, _, _) = strip_pat_refs(param.pat).kind; if let ExprKind::Binary(ref op, l, r) = body.value.kind; diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 8288f7a8b9b6..527529965a96 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -498,7 +498,7 @@ fn is_linted_explicit_deref_position(parent: Option>, child_id: HirId, | ExprKind::Loop(..) | ExprKind::Match(..) | ExprKind::Let(..) - | ExprKind::Closure(..) + | ExprKind::Closure{..} | ExprKind::Block(..) | ExprKind::Assign(..) | ExprKind::AssignOp(..) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 530d6d4de35f..197cac86a57d 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { return; } let body = match expr.kind { - ExprKind::Closure(_, _, id, _, _) => cx.tcx.hir().body(id), + ExprKind::Closure { body, .. } => cx.tcx.hir().body(body), _ => return, }; if body.value.span.from_expansion() { diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index b2b9889f5dc7..41e1fc4e3c20 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -158,8 +158,8 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { } } if method.ident.name == sym!(flat_map) && args.len() == 2 { - if let ExprKind::Closure(_, _, body_id, _, _) = args[1].kind { - let body = cx.tcx.hir().body(body_id); + if let ExprKind::Closure { body, .. } = args[1].kind { + let body = cx.tcx.hir().body(body); return is_infinite(cx, &body.value); } } diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index a348bb465c88..0b6d9adb553e 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -369,8 +369,8 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { self.visit_expr(expr); } }, - ExprKind::Closure(_, _, body_id, ..) => { - let body = self.cx.tcx.hir().body(body_id); + ExprKind::Closure { body, .. } => { + let body = self.cx.tcx.hir().body(body); self.visit_expr(&body.value); }, _ => walk_expr(self, expr), diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index c025f5972d51..99d214669359 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -182,7 +182,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { .fold(NeverLoopResult::Otherwise, combine_both), ExprKind::Struct(_, _, None) | ExprKind::Yield(_, _) - | ExprKind::Closure(_, _, _, _, _) + | ExprKind::Closure { .. } | ExprKind::Path(_) | ExprKind::ConstBlock(_) | ExprKind::Lit(_) diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index 82760607ba29..a57159750664 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -220,7 +220,7 @@ fn uses_iter<'tcx>(cx: &LateContext<'tcx>, iter_expr: &IterExpr, container: &'tc if let Some(e) = e { self.visit_expr(e); } - } else if let ExprKind::Closure(_, _, id, _, _) = e.kind { + } else if let ExprKind::Closure { body: id, .. } = e.kind { if is_res_used(self.cx, self.iter_expr.path, id) { self.uses_iter = true; } @@ -260,7 +260,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: & if let Some(e) = e { self.visit_expr(e); } - } else if let ExprKind::Closure(_, _, id, _, _) = e.kind { + } else if let ExprKind::Closure { body: id, .. } = e.kind { self.used_iter = is_res_used(self.cx, self.iter_expr.path, id); } else { walk_expr(self, e); @@ -307,7 +307,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: & if let Some(e) = e { self.visit_expr(e); } - } else if let ExprKind::Closure(_, _, id, _, _) = e.kind { + } else if let ExprKind::Closure { body: id, .. } = e.kind { self.used_after = is_res_used(self.cx, self.iter_expr.path, id); } else { walk_expr(self, e); diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index babc6fab3c0f..818410d27937 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -177,8 +177,8 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) if let Some(block_expr) = block.expr; if let Some(args) = match_function_call(cx, block_expr, &FUTURE_FROM_GENERATOR); if args.len() == 1; - if let Expr{kind: ExprKind::Closure(_, _, body_id, ..), ..} = args[0]; - let closure_body = cx.tcx.hir().body(body_id); + if let Expr{kind: ExprKind::Closure { body, .. }, ..} = args[0]; + let closure_body = cx.tcx.hir().body(body); if closure_body.generator_kind == Some(GeneratorKind::Async(AsyncGeneratorKind::Block)); then { return Some(closure_body); diff --git a/clippy_lints/src/manual_ok_or.rs b/clippy_lints/src/manual_ok_or.rs index bf4ab29d9087..18cfd0037678 100644 --- a/clippy_lints/src/manual_ok_or.rs +++ b/clippy_lints/src/manual_ok_or.rs @@ -88,8 +88,8 @@ fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool { } } if_chain! { - if let ExprKind::Closure(_, _, body_id, ..) = map_expr.kind; - let body = cx.tcx.hir().body(body_id); + if let ExprKind::Closure { body, .. } = map_expr.kind; + let body = cx.tcx.hir().body(body); if let PatKind::Binding(_, param_id, ..) = body.params[0].pat.kind; if let ExprKind::Call(Expr { kind: ExprKind::Path(ok_path), .. }, &[ref ok_arg]) = body.value.kind; if is_lang_ctor(cx, ok_path, ResultOk); diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index a13d191375bf..3533de54a1e3 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -67,9 +67,9 @@ impl<'tcx> LateLintPass<'tcx> for MapClone { if method.ident.name == sym::map; let ty = cx.typeck_results().expr_ty(&args[0]); if is_type_diagnostic_item(cx, ty, sym::Option) || is_trait_method(cx, e, sym::Iterator); - if let hir::ExprKind::Closure(_, _, body_id, _, _) = args[1].kind; + if let hir::ExprKind::Closure { body, .. } = args[1].kind; then { - let closure_body = cx.tcx.hir().body(body_id); + let closure_body = cx.tcx.hir().body(body); let closure_expr = peel_blocks(&closure_body.value); match closure_body.params[0].pat.kind { hir::PatKind::Ref(inner, hir::Mutability::Not) => if let hir::PatKind::Binding( diff --git a/clippy_lints/src/map_err_ignore.rs b/clippy_lints/src/map_err_ignore.rs index e3a42de0b7c1..0c2214410487 100644 --- a/clippy_lints/src/map_err_ignore.rs +++ b/clippy_lints/src/map_err_ignore.rs @@ -117,12 +117,19 @@ impl<'tcx> LateLintPass<'tcx> for MapErrIgnore { // only work if the method name is `map_err` and there are only 2 arguments (e.g. x.map_err(|_|[1] // Enum::Variant[2])) if method.ident.as_str() == "map_err" && args.len() == 2 { - // make sure the first argument is a closure, and grab the CaptureRef, body_id, and body_span fields - if let ExprKind::Closure(capture, _, body_id, body_span, _) = args[1].kind { + // make sure the first argument is a closure, and grab the CaptureRef, BodyId, and fn_decl_span + // fields + if let ExprKind::Closure { + capture_clause, + body, + fn_decl_span, + .. + } = args[1].kind + { // check if this is by Reference (meaning there's no move statement) - if capture == CaptureBy::Ref { + if capture_clause == CaptureBy::Ref { // Get the closure body to check the parameters and values - let closure_body = cx.tcx.hir().body(body_id); + let closure_body = cx.tcx.hir().body(body); // make sure there's only one parameter (`|_|`) if closure_body.params.len() == 1 { // make sure that parameter is the wild token (`_`) @@ -132,7 +139,7 @@ impl<'tcx> LateLintPass<'tcx> for MapErrIgnore { span_lint_and_help( cx, MAP_ERR_IGNORE, - body_span, + fn_decl_span, "`map_err(|_|...` wildcard pattern discards the original error", None, "consider storing the original error as a source in the new error, or silence this warning using an ignored identifier (`.map_err(|_foo| ...`)", diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index f552d5c1afab..663246b4c862 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -169,12 +169,12 @@ fn unit_closure<'tcx>( expr: &hir::Expr<'_>, ) -> Option<(&'tcx hir::Param<'tcx>, &'tcx hir::Expr<'tcx>)> { if_chain! { - if let hir::ExprKind::Closure(_, decl, inner_expr_id, _, _) = expr.kind; - let body = cx.tcx.hir().body(inner_expr_id); + if let hir::ExprKind::Closure { fn_decl, body, .. } = expr.kind; + let body = cx.tcx.hir().body(body); let body_expr = &body.value; - if decl.inputs.len() == 1; + if fn_decl.inputs.len() == 1; if is_unit_expression(cx, body_expr); - if let Some(binding) = iter_input_pats(decl, body).next(); + if let Some(binding) = iter_input_pats(fn_decl, body).next(); then { return Some((binding, body_expr)); } diff --git a/clippy_lints/src/matches/match_single_binding.rs b/clippy_lints/src/matches/match_single_binding.rs index a59711d4cace..9df2db45dcf8 100644 --- a/clippy_lints/src/matches/match_single_binding.rs +++ b/clippy_lints/src/matches/match_single_binding.rs @@ -177,7 +177,7 @@ fn sugg_with_curlies<'a>( let (mut cbrace_start, mut cbrace_end) = (String::new(), String::new()); if let Some(parent_expr) = get_parent_expr(cx, match_expr) { - if let ExprKind::Closure(..) = parent_expr.kind { + if let ExprKind::Closure { .. } = parent_expr.kind { cbrace_end = format!("\n{}}}", indent); // Fix body indent due to the closure indent = " ".repeat(indent_of(cx, bind_names).unwrap_or(0)); diff --git a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index a211dc18f9e1..dcaf6f865de3 100644 --- a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -305,7 +305,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> { ExprKind::Break(_, _) | ExprKind::Cast(_, _) | // Don't want to check the closure itself, only invocation, which is covered by MethodCall - ExprKind::Closure(_, _, _, _, _) | + ExprKind::Closure { .. } | ExprKind::ConstBlock(_) | ExprKind::Continue(_) | ExprKind::DropTemps(_) | diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs index b88ec0963f2b..d31b736982b3 100644 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/clippy_lints/src/methods/bind_instead_of_map.rs @@ -150,11 +150,11 @@ pub(crate) trait BindInsteadOfMap { } match arg.kind { - hir::ExprKind::Closure(_, _, body_id, closure_args_span, _) => { - let closure_body = cx.tcx.hir().body(body_id); + hir::ExprKind::Closure { body, fn_decl_span, .. } => { + let closure_body = cx.tcx.hir().body(body); let closure_expr = peel_blocks(&closure_body.value); - if Self::lint_closure_autofixable(cx, expr, recv, closure_expr, closure_args_span) { + if Self::lint_closure_autofixable(cx, expr, recv, closure_expr, fn_decl_span) { true } else { Self::lint_closure(cx, expr, closure_expr) diff --git a/clippy_lints/src/methods/filter_map.rs b/clippy_lints/src/methods/filter_map.rs index 558cb6bd64e7..3efccd703a65 100644 --- a/clippy_lints/src/methods/filter_map.rs +++ b/clippy_lints/src/methods/filter_map.rs @@ -22,8 +22,8 @@ fn is_method<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, method_name: Sy hir::ExprKind::Path(QPath::Resolved(_, segments)) => { segments.segments.last().unwrap().ident.name == method_name }, - hir::ExprKind::Closure(_, _, c, _, _) => { - let body = cx.tcx.hir().body(*c); + hir::ExprKind::Closure { body, .. } => { + let body = cx.tcx.hir().body(*body); let closure_expr = peel_blocks(&body.value); let arg_id = body.params[0].pat.hir_id; match closure_expr.kind { @@ -106,7 +106,7 @@ pub(super) fn check<'tcx>( if is_trait_method(cx, map_recv, sym::Iterator); // filter(|x| ...is_some())... - if let ExprKind::Closure(_, _, filter_body_id, ..) = filter_arg.kind; + if let ExprKind::Closure { body: filter_body_id, .. } = filter_arg.kind; let filter_body = cx.tcx.hir().body(filter_body_id); if let [filter_param] = filter_body.params; // optional ref pattern: `filter(|&x| ..)` @@ -129,7 +129,7 @@ pub(super) fn check<'tcx>( if path.ident.name.as_str() == if is_result { "is_ok" } else { "is_some" }; // ...map(|x| ...unwrap()) - if let ExprKind::Closure(_, _, map_body_id, ..) = map_arg.kind; + if let ExprKind::Closure { body: map_body_id, .. } = map_arg.kind; let map_body = cx.tcx.hir().body(map_body_id); if let [map_param] = map_body.params; if let PatKind::Binding(_, map_param_id, map_param_ident, None) = map_param.pat.kind; diff --git a/clippy_lints/src/methods/option_as_ref_deref.rs b/clippy_lints/src/methods/option_as_ref_deref.rs index b50a173d8359..912499bf96b9 100644 --- a/clippy_lints/src/methods/option_as_ref_deref.rs +++ b/clippy_lints/src/methods/option_as_ref_deref.rs @@ -51,8 +51,8 @@ pub(super) fn check<'tcx>( .map_or(false, |fun_def_id| { deref_aliases.iter().any(|path| match_def_path(cx, fun_def_id, path)) }), - hir::ExprKind::Closure(_, _, body_id, _, _) => { - let closure_body = cx.tcx.hir().body(body_id); + hir::ExprKind::Closure { body, .. } => { + let closure_body = cx.tcx.hir().body(body); let closure_expr = peel_blocks(&closure_body.value); match &closure_expr.kind { diff --git a/clippy_lints/src/methods/option_map_or_none.rs b/clippy_lints/src/methods/option_map_or_none.rs index 8989db54f6c5..2d71bd6f240f 100644 --- a/clippy_lints/src/methods/option_map_or_none.rs +++ b/clippy_lints/src/methods/option_map_or_none.rs @@ -71,27 +71,26 @@ pub(super) fn check<'tcx>( if is_option { let self_snippet = snippet(cx, recv.span, ".."); if_chain! { - if let hir::ExprKind::Closure(_, _, id, span, _) = map_arg.kind; - let arg_snippet = snippet(cx, span, ".."); - let body = cx.tcx.hir().body(id); - if let Some((func, [arg_char])) = reduce_unit_expression(&body.value); - if let Some(id) = path_def_id(cx, func).map(|ctor_id| cx.tcx.parent(ctor_id)); - if Some(id) == cx.tcx.lang_items().option_some_variant(); - then { - let func_snippet = snippet(cx, arg_char.span, ".."); - let msg = "called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling \ - `map(..)` instead"; - return span_lint_and_sugg( - cx, - OPTION_MAP_OR_NONE, - expr.span, - msg, - "try using `map` instead", - format!("{0}.map({1} {2})", self_snippet, arg_snippet,func_snippet), - Applicability::MachineApplicable, - ); - } - + if let hir::ExprKind::Closure { body, fn_decl_span, .. } = map_arg.kind; + let arg_snippet = snippet(cx, fn_decl_span, ".."); + let body = cx.tcx.hir().body(body); + if let Some((func, [arg_char])) = reduce_unit_expression(&body.value); + if let Some(id) = path_def_id(cx, func).map(|ctor_id| cx.tcx.parent(ctor_id)); + if Some(id) == cx.tcx.lang_items().option_some_variant(); + then { + let func_snippet = snippet(cx, arg_char.span, ".."); + let msg = "called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling \ + `map(..)` instead"; + return span_lint_and_sugg( + cx, + OPTION_MAP_OR_NONE, + expr.span, + msg, + "try using `map` instead", + format!("{0}.map({1} {2})", self_snippet, arg_snippet,func_snippet), + Applicability::MachineApplicable, + ); + } } let func_snippet = snippet(cx, map_arg.span, ".."); diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs index 5ed4ba94884e..b11f4531a912 100644 --- a/clippy_lints/src/methods/search_is_some.rs +++ b/clippy_lints/src/methods/search_is_some.rs @@ -41,8 +41,8 @@ pub(super) fn check<'tcx>( let mut applicability = Applicability::MachineApplicable; let any_search_snippet = if_chain! { if search_method == "find"; - if let hir::ExprKind::Closure(_, _, body_id, ..) = search_arg.kind; - let closure_body = cx.tcx.hir().body(body_id); + if let hir::ExprKind::Closure { body, .. } = search_arg.kind; + let closure_body = cx.tcx.hir().body(body); if let Some(closure_arg) = closure_body.params.get(0); then { if let hir::PatKind::Ref(..) = closure_arg.pat.kind { diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index 2fda254ca98e..a405467f5e8a 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -18,8 +18,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr< return; } - if let hir::ExprKind::Closure(_, _, body_id, ..) = arg.kind { - let body = cx.tcx.hir().body(body_id); + if let hir::ExprKind::Closure { body, .. } = arg.kind { + let body = cx.tcx.hir().body(body); let arg_id = body.params[0].pat.hir_id; let mutates_arg = mutated_variables(&body.value, cx).map_or(true, |used_mutably| used_mutably.contains(&arg_id)); diff --git a/clippy_lints/src/methods/unnecessary_fold.rs b/clippy_lints/src/methods/unnecessary_fold.rs index 47a811996085..913c4dbedc30 100644 --- a/clippy_lints/src/methods/unnecessary_fold.rs +++ b/clippy_lints/src/methods/unnecessary_fold.rs @@ -29,8 +29,8 @@ pub(super) fn check( ) { if_chain! { // Extract the body of the closure passed to fold - if let hir::ExprKind::Closure(_, _, body_id, _, _) = acc.kind; - let closure_body = cx.tcx.hir().body(body_id); + if let hir::ExprKind::Closure { body, .. } = acc.kind; + let closure_body = cx.tcx.hir().body(body); let closure_expr = peel_blocks(&closure_body.value); // Check if the closure body is of the form `acc some_expr(x)` diff --git a/clippy_lints/src/methods/unnecessary_lazy_eval.rs b/clippy_lints/src/methods/unnecessary_lazy_eval.rs index 2369be708129..865f6d0318eb 100644 --- a/clippy_lints/src/methods/unnecessary_lazy_eval.rs +++ b/clippy_lints/src/methods/unnecessary_lazy_eval.rs @@ -22,8 +22,8 @@ pub(super) fn check<'tcx>( let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result); if is_option || is_result { - if let hir::ExprKind::Closure(_, _, eid, _, _) = arg.kind { - let body = cx.tcx.hir().body(eid); + if let hir::ExprKind::Closure { body, .. } = arg.kind { + let body = cx.tcx.hir().body(body); let body_expr = &body.value; if usage::BindingUsageFinder::are_params_used(cx, body) { diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs index 024bd0760715..c3b850fbb9dc 100644 --- a/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/clippy_lints/src/mixed_read_write_in_expression.rs @@ -112,7 +112,7 @@ struct DivergenceVisitor<'a, 'tcx> { impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> { fn maybe_walk_expr(&mut self, e: &'tcx Expr<'_>) { match e.kind { - ExprKind::Closure(..) => {}, + ExprKind::Closure { .. } => {}, ExprKind::Match(e, arms, _) => { self.visit_expr(e); for arm in arms { @@ -243,7 +243,7 @@ fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr<'_>) - walk_expr(vis, expr); } }, - ExprKind::Closure(_, _, _, _, _) => { + ExprKind::Closure { .. } => { // Either // // * `var` is defined in the closure body, in which case we've reached the top of the enclosing @@ -315,7 +315,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> { // We're about to descend a closure. Since we don't know when (or // if) the closure will be evaluated, any reads in it might not // occur here (or ever). Like above, bail to avoid false positives. - ExprKind::Closure(_, _, _, _, _) | + ExprKind::Closure{..} | // We want to avoid a false positive when a variable name occurs // only to have its address taken, so we stop here. Technically, diff --git a/clippy_lints/src/needless_for_each.rs b/clippy_lints/src/needless_for_each.rs index 6cf513b214e6..48ac695f2acf 100644 --- a/clippy_lints/src/needless_for_each.rs +++ b/clippy_lints/src/needless_for_each.rs @@ -72,8 +72,8 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessForEach { if has_iter_method(cx, cx.typeck_results().expr_ty(iter_recv)).is_some(); // Skip the lint if the body is not block because this is simpler than `for` loop. // e.g. `v.iter().for_each(f)` is simpler and clearer than using `for` loop. - if let ExprKind::Closure(_, _, body_id, ..) = for_each_arg.kind; - let body = cx.tcx.hir().body(body_id); + if let ExprKind::Closure { body, .. } = for_each_arg.kind; + let body = cx.tcx.hir().body(body); if let ExprKind::Block(..) = body.value.kind; then { let mut ret_collector = RetCollector::default(); diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 5bf8a1ba1ca3..6598413c77ec 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -116,7 +116,7 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { return false; } match peel_blocks(expr).kind { - ExprKind::Lit(..) | ExprKind::Closure(..) => true, + ExprKind::Lit(..) | ExprKind::Closure { .. } => true, ExprKind::Path(..) => !has_drop(cx, cx.typeck_results().expr_ty(expr)), ExprKind::Index(a, b) | ExprKind::Binary(_, a, b) => has_no_effect(cx, a) && has_no_effect(cx, b), ExprKind::Array(v) | ExprKind::Tup(v) => v.iter().all(|val| has_no_effect(cx, val)), diff --git a/clippy_lints/src/only_used_in_recursion.rs b/clippy_lints/src/only_used_in_recursion.rs index d66698f8adc6..de5f77f3ad97 100644 --- a/clippy_lints/src/only_used_in_recursion.rs +++ b/clippy_lints/src/only_used_in_recursion.rs @@ -298,8 +298,8 @@ impl<'tcx> Visitor<'tcx> for SideEffectVisit<'tcx> { }, ExprKind::Match(expr, arms, _) => self.visit_match(expr, arms), // since analysing the closure is not easy, just set all variables in it to side-effect - ExprKind::Closure(_, _, body_id, _, _) => { - let body = self.tcx.hir().body(body_id); + ExprKind::Closure { body, .. } => { + let body = self.tcx.hir().body(body); self.visit_body(body); let vars = std::mem::take(&mut self.ret_vars); self.add_side_effect(vars); diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 5a25008e95e5..4c2016fe3f72 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { if_chain! { if let hir::StmtKind::Local(local) = w[0].kind; if let Option::Some(t) = local.init; - if let hir::ExprKind::Closure(..) = t.kind; + if let hir::ExprKind::Closure { .. } = t.kind; if let hir::PatKind::Binding(_, _, ident, _) = local.pat.kind; if let hir::StmtKind::Semi(second) = w[1].kind; if let hir::ExprKind::Assign(_, call, _) = second.kind; diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 7c39a08a336b..f58da7ce9b42 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -116,13 +116,13 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Span, Option)> { if_chain! { - if let ExprKind::Closure(_, _fn_decl, body_id, span, _) = arg.kind; + if let ExprKind::Closure { body, fn_decl_span, .. } = arg.kind; if let ty::Closure(_def_id, substs) = &cx.typeck_results().node_type(arg.hir_id).kind(); let ret_ty = substs.as_closure().sig().output(); let ty = cx.tcx.erase_late_bound_regions(ret_ty); if ty.is_unit(); then { - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir().body(body); if_chain! { if let ExprKind::Block(block, _) = body.value.kind; if block.expr.is_none(); @@ -131,9 +131,9 @@ fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Spa then { let data = stmt.span.data(); // Make a span out of the semicolon for the help message - Some((span, Some(data.with_lo(data.hi-BytePos(1))))) + Some((fn_decl_span, Some(data.with_lo(data.hi-BytePos(1))))) } else { - Some((span, None)) + Some((fn_decl_span, None)) } } } else { diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index d371cafb16b1..7d4373b2a57b 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -155,7 +155,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { if let ExprKind::MethodCall(name_ident, args, _) = &expr.kind; if let name = name_ident.ident.name.to_ident_string(); if name == "sort_by" || name == "sort_unstable_by"; - if let [vec, Expr { kind: ExprKind::Closure(_, _, closure_body_id, _, _), .. }] = args; + if let [vec, Expr { kind: ExprKind::Closure{ body: closure_body_id, .. }, .. }] = args; if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(vec), sym::Vec); if let closure_body = cx.tcx.hir().body(*closure_body_id); if let &[ diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 3f4d0fd199d0..2c8820eb7e1a 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -466,7 +466,13 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { self.expr(scrutinee); self.slice(arms, |arm| self.arm(arm)); }, - ExprKind::Closure(capture_by, fn_decl, body_id, _, movability) => { + ExprKind::Closure { + capture_clause, + fn_decl, + body: body_id, + movability, + .. + } => { let movability = OptionPat::new(movability.map(|m| format!("Movability::{m:?}"))); let ret_ty = match fn_decl.output { @@ -475,7 +481,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { }; bind!(self, fn_decl, body_id); - kind!("Closure(CaptureBy::{capture_by:?}, {fn_decl}, {body_id}, _, {movability})"); + kind!("Closure(CaptureBy::{capture_clause:?}, {fn_decl}, {body_id}, _, {movability})"); out!("if let {ret_ty} = {fn_decl}.output;"); self.body(body_id); }, diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 1a784b6cdda4..730724b95b96 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -198,7 +198,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS | ExprKind::Let(..) | ExprKind::If(..) | ExprKind::Match(..) - | ExprKind::Closure(..) + | ExprKind::Closure { .. } | ExprKind::Field(..) | ExprKind::Path(_) | ExprKind::AddrOf(..) diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 0603471c3431..12931c56df61 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -622,10 +622,12 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_expr(e); self.hash_ty(ty); }, - ExprKind::Closure(cap, _, eid, _, _) => { - std::mem::discriminant(&cap).hash(&mut self.s); + ExprKind::Closure { + capture_clause, body, .. + } => { + std::mem::discriminant(&capture_clause).hash(&mut self.s); // closures inherit TypeckResults - self.hash_expr(&self.cx.tcx.hir().body(eid).value); + self.hash_expr(&self.cx.tcx.hir().body(body).value); }, ExprKind::Field(e, ref f) => { self.hash_expr(e); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 5f051e3f444c..0cf23ca626c7 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -962,7 +962,7 @@ pub fn can_move_expr_to_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<' self.captures.entry(l).and_modify(|e| *e |= cap).or_insert(cap); } }, - ExprKind::Closure(..) => { + ExprKind::Closure { .. } => { let closure_id = self.cx.tcx.hir().local_def_id(e.hir_id).to_def_id(); for capture in self.cx.typeck_results().closure_min_captures_flattened(closure_id) { let local_id = match capture.place.base { @@ -1200,7 +1200,7 @@ pub fn get_enclosing_loop_or_closure<'tcx>(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) - match node { Node::Expr( e @ Expr { - kind: ExprKind::Loop(..) | ExprKind::Closure(..), + kind: ExprKind::Loop(..) | ExprKind::Closure { .. }, .. }, ) => return Some(e), @@ -1693,7 +1693,7 @@ pub fn get_async_fn_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Option<&'t _, &[ Expr { - kind: ExprKind::Closure(_, _, body, _, _), + kind: ExprKind::Closure { body, .. }, .. }, ], @@ -1780,7 +1780,7 @@ pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool } match expr.kind { - ExprKind::Closure(_, _, body_id, _, _) => is_body_identity_function(cx, cx.tcx.hir().body(body_id)), + ExprKind::Closure { body, .. } => is_body_identity_function(cx, cx.tcx.hir().body(body)), _ => path_def_id(cx, expr).map_or(false, |id| match_def_path(cx, id, &paths::CONVERT_IDENTITY)), } } diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 4f3757f1ec67..4d21ba8bd1d1 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -134,7 +134,7 @@ impl<'a> Sugg<'a> { | hir::ExprKind::Box(..) | hir::ExprKind::If(..) | hir::ExprKind::Let(..) - | hir::ExprKind::Closure(..) + | hir::ExprKind::Closure { .. } | hir::ExprKind::Unary(..) | hir::ExprKind::Match(..) => Sugg::MaybeParen(get_snippet(expr.span)), hir::ExprKind::Continue(..) @@ -188,7 +188,7 @@ impl<'a> Sugg<'a> { match expr.kind { ast::ExprKind::AddrOf(..) | ast::ExprKind::Box(..) - | ast::ExprKind::Closure(..) + | ast::ExprKind::Closure { .. } | ast::ExprKind::If(..) | ast::ExprKind::Let(..) | ast::ExprKind::Unary(..) @@ -790,8 +790,8 @@ pub struct DerefClosure { /// /// note: this only works on single line immutable closures with exactly one input parameter. pub fn deref_closure_args<'tcx>(cx: &LateContext<'_>, closure: &'tcx hir::Expr<'_>) -> Option { - if let hir::ExprKind::Closure(_, fn_decl, body_id, ..) = closure.kind { - let closure_body = cx.tcx.hir().body(body_id); + if let hir::ExprKind::Closure { fn_decl, body, .. } = closure.kind { + let closure_body = cx.tcx.hir().body(body); // is closure arg a type annotated double reference (i.e.: `|x: &&i32| ...`) // a type annotation is present if param `kind` is different from `TyKind::Infer` let closure_arg_is_type_annotated_double_ref = if let TyKind::Rptr(_, MutTy { ty, .. }) = fn_decl.inputs[0].kind diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index 9819778540cc..3af5dfb62f97 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -185,7 +185,7 @@ pub fn local_used_after_expr(cx: &LateContext<'_>, local_id: HirId, after: &Expr matches!( node, Node::Expr(Expr { - kind: ExprKind::Loop(..) | ExprKind::Closure(..), + kind: ExprKind::Loop(..) | ExprKind::Closure { .. }, .. }) ) From f25fb5ea7fb555c4ecc77c7f270cd59235960a9b Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Mon, 13 Jun 2022 15:48:40 +0900 Subject: [PATCH 0520/1222] remove unnecessary `to_string` and `String::new` --- clippy_lints/src/almost_complete_letter_range.rs | 2 +- clippy_lints/src/as_underscore.rs | 2 +- clippy_lints/src/empty_structs_with_brackets.rs | 2 +- clippy_lints/src/large_const_arrays.rs | 2 +- clippy_lints/src/manual_async_fn.rs | 2 +- clippy_lints/src/matches/match_same_arms.rs | 2 +- clippy_lints/src/methods/str_splitn.rs | 4 ++-- clippy_lints/src/methods/unnecessary_iter_cloned.rs | 2 +- clippy_lints/src/needless_late_init.rs | 4 ++-- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/redundant_clone.rs | 2 +- clippy_lints/src/transmute/transmute_float_to_int.rs | 2 +- clippy_lints/src/transmute/transmute_ptr_to_ptr.rs | 2 +- clippy_lints/src/transmute/transmute_ref_to_ref.rs | 2 +- clippy_lints/src/transmute/useless_transmute.rs | 4 ++-- clippy_utils/src/attrs.rs | 2 +- 16 files changed, 19 insertions(+), 19 deletions(-) diff --git a/clippy_lints/src/almost_complete_letter_range.rs b/clippy_lints/src/almost_complete_letter_range.rs index b364a370efab..59a7c5354006 100644 --- a/clippy_lints/src/almost_complete_letter_range.rs +++ b/clippy_lints/src/almost_complete_letter_range.rs @@ -90,7 +90,7 @@ fn check_range(cx: &EarlyContext<'_>, span: Span, start: &Expr, end: &Expr, sugg diag.span_suggestion( span, "use an inclusive range", - sugg.to_owned(), + sugg, Applicability::MaybeIncorrect, ); } diff --git a/clippy_lints/src/as_underscore.rs b/clippy_lints/src/as_underscore.rs index 464be4218dd4..0bdef9d0a7e8 100644 --- a/clippy_lints/src/as_underscore.rs +++ b/clippy_lints/src/as_underscore.rs @@ -63,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for AsUnderscore { diag.span_suggestion( ty.span, "consider giving the type explicitly", - format!("{}", ty_resolved), + ty_resolved, Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/empty_structs_with_brackets.rs b/clippy_lints/src/empty_structs_with_brackets.rs index 8430e7b4c827..08bf80a42290 100644 --- a/clippy_lints/src/empty_structs_with_brackets.rs +++ b/clippy_lints/src/empty_structs_with_brackets.rs @@ -44,7 +44,7 @@ impl EarlyLintPass for EmptyStructsWithBrackets { diagnostic.span_suggestion_hidden( span_after_ident, "remove the brackets", - ";".to_string(), + ";", Applicability::MachineApplicable); }, ); diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index 27db63881361..14f84a832aa3 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays { diag.span_suggestion( sugg_span, "make this a static item", - "static".to_string(), + "static", Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index babc6fab3c0f..c70b1c261b61 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -86,7 +86,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn { diag.span_suggestion( block.span, "move the body of the async block to the enclosing function", - body_snip.to_string(), + body_snip, Applicability::MachineApplicable ); } diff --git a/clippy_lints/src/matches/match_same_arms.rs b/clippy_lints/src/matches/match_same_arms.rs index a96a7fe55f3a..4f8baf7efb0b 100644 --- a/clippy_lints/src/matches/match_same_arms.rs +++ b/clippy_lints/src/matches/match_same_arms.rs @@ -113,7 +113,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) { diag.span_suggestion( arm1.span, "try removing the arm", - String::new(), + "", Applicability::MaybeIncorrect, ) .help("or try changing either arm body") diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 90651a6ba045..4ac738272d08 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -176,13 +176,13 @@ fn check_manual_split_once_indirect( diag.span_suggestion( first.span, &remove_msg, - String::new(), + "", app, ); diag.span_suggestion( second.span, &remove_msg, - String::new(), + "", app, ); }); diff --git a/clippy_lints/src/methods/unnecessary_iter_cloned.rs b/clippy_lints/src/methods/unnecessary_iter_cloned.rs index 7a39557ad575..19037093e20a 100644 --- a/clippy_lints/src/methods/unnecessary_iter_cloned.rs +++ b/clippy_lints/src/methods/unnecessary_iter_cloned.rs @@ -85,7 +85,7 @@ pub fn check_for_loop_iter( match addr_of_expr.kind { ExprKind::AddrOf(_, _, referent) => { let span = addr_of_expr.span.with_hi(referent.span.lo()); - diag.span_suggestion(span, "remove this `&`", String::new(), applicability); + diag.span_suggestion(span, "remove this `&`", "", applicability); } _ => unreachable!(), } diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs index 26c694a71fed..d8982ffcf666 100644 --- a/clippy_lints/src/needless_late_init.rs +++ b/clippy_lints/src/needless_late_init.rs @@ -318,7 +318,7 @@ fn check<'tcx>( diag.span_suggestion( usage.stmt.span.shrink_to_hi(), "add a semicolon after the `if` expression", - ";".to_string(), + ";", applicability, ); } @@ -353,7 +353,7 @@ fn check<'tcx>( diag.span_suggestion( usage.stmt.span.shrink_to_hi(), "add a semicolon after the `match` expression", - ";".to_string(), + ";", applicability, ); } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index f423be4b67a6..8b273aca7d02 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -258,7 +258,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { diag.span_suggestion( input.span, "consider changing the type to", - "&str".to_string(), + "&str", Applicability::Unspecified, ); diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 249f11f98508..3b11cbc37606 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -255,7 +255,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone { diag.span_suggestion( sugg_span, "remove this", - String::new(), + "", app, ); if clone_usage.cloned_used { diff --git a/clippy_lints/src/transmute/transmute_float_to_int.rs b/clippy_lints/src/transmute/transmute_float_to_int.rs index d5ef86dc4e57..1bde977cfa27 100644 --- a/clippy_lints/src/transmute/transmute_float_to_int.rs +++ b/clippy_lints/src/transmute/transmute_float_to_int.rs @@ -55,7 +55,7 @@ pub(super) fn check<'tcx>( sugg }; - diag.span_suggestion(e.span, "consider using", sugg.to_string(), Applicability::Unspecified); + diag.span_suggestion(e.span, "consider using", sugg, Applicability::Unspecified); }, ); true diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs index d712b33de9e1..31a9b69ca158 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs @@ -25,7 +25,7 @@ pub(super) fn check<'tcx>( |diag| { if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) { let sugg = arg.as_ty(cx.tcx.mk_ptr(*to_ty)); - diag.span_suggestion(e.span, "try", sugg.to_string(), Applicability::Unspecified); + diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified); } }, ); diff --git a/clippy_lints/src/transmute/transmute_ref_to_ref.rs b/clippy_lints/src/transmute/transmute_ref_to_ref.rs index 786e7bfc56f6..707a11d361c0 100644 --- a/clippy_lints/src/transmute/transmute_ref_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ref_to_ref.rs @@ -73,7 +73,7 @@ pub(super) fn check<'tcx>( diag.span_suggestion( e.span, "try", - sugg.to_string(), + sugg, Applicability::Unspecified, ); }, diff --git a/clippy_lints/src/transmute/useless_transmute.rs b/clippy_lints/src/transmute/useless_transmute.rs index a0d104e23904..fc9227b76f02 100644 --- a/clippy_lints/src/transmute/useless_transmute.rs +++ b/clippy_lints/src/transmute/useless_transmute.rs @@ -46,7 +46,7 @@ pub(super) fn check<'tcx>( arg.as_ty(cx.tcx.mk_ptr(rty_and_mut)).as_ty(to_ty) }; - diag.span_suggestion(e.span, "try", sugg.to_string(), Applicability::Unspecified); + diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified); } }, ); @@ -64,7 +64,7 @@ pub(super) fn check<'tcx>( diag.span_suggestion( e.span, "try", - arg.as_ty(&to_ty.to_string()).to_string(), + arg.as_ty(&to_ty.to_string()), Applicability::Unspecified, ); } diff --git a/clippy_utils/src/attrs.rs b/clippy_utils/src/attrs.rs index 49318849d580..186bba09d201 100644 --- a/clippy_utils/src/attrs.rs +++ b/clippy_utils/src/attrs.rs @@ -92,7 +92,7 @@ pub fn get_attr<'a>( diag.span_suggestion( attr_segments[1].ident.span, "consider using", - new_name.to_string(), + new_name, Applicability::MachineApplicable, ); diag.emit(); From 4160676dc84c7959cf69f5b2763026a2b82487f9 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Mon, 13 Jun 2022 16:01:16 +0900 Subject: [PATCH 0521/1222] remove unnecessary `to_string` and `String::new` for `tool_only_span_suggestion` --- clippy_lints/src/needless_late_init.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs index d8982ffcf666..1f8c4c85cc2e 100644 --- a/clippy_lints/src/needless_late_init.rs +++ b/clippy_lints/src/needless_late_init.rs @@ -281,7 +281,7 @@ fn check<'tcx>( diag.tool_only_span_suggestion( local_stmt.span, "remove the local", - String::new(), + "", Applicability::MachineApplicable, ); From a53709811686e847e7caaec47fc174994e0ed9f9 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 10 Jun 2022 11:18:06 +1000 Subject: [PATCH 0522/1222] Rename the `ConstS::val` field as `kind`. And likewise for the `Const::val` method. Because its type is called `ConstKind`. Also `val` is a confusing name because `ConstKind` is an enum with seven variants, one of which is called `Value`. Also, this gives consistency with `TyS` and `PredicateS` which have `kind` fields. The commit also renames a few `Const` variables from `val` to `c`, to avoid confusion with the `ConstKind::Value` variant. --- clippy_lints/src/large_const_arrays.rs | 2 +- clippy_lints/src/large_stack_arrays.rs | 2 +- clippy_utils/src/consts.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index 14f84a832aa3..ed47490e230c 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays { if let ItemKind::Const(hir_ty, _) = &item.kind; let ty = hir_ty_to_ty(cx.tcx, hir_ty); if let ty::Array(element_type, cst) = ty.kind(); - if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val(); + if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.kind(); if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx); if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()); if self.maximum_allowed_size < element_count * element_size; diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index 57b0d709acd4..4ca69465fad4 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays { if_chain! { if let ExprKind::Repeat(_, _) = expr.kind; if let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind(); - if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val(); + if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.kind(); if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx); if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()); if self.maximum_allowed_size < element_count * element_size; diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index d487868cafe5..159c5d53d029 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -582,7 +582,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { pub fn miri_to_const(result: ty::Const<'_>) -> Option { use rustc_middle::mir::interpret::ConstValue; - match result.val() { + match result.kind() { ty::ConstKind::Value(ConstValue::Scalar(Scalar::Int(int))) => { match result.ty().kind() { ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)), From 632ee33d118813da2916ce4bbaf679c2a0569620 Mon Sep 17 00:00:00 2001 From: b-naber Date: Wed, 16 Feb 2022 10:56:01 +0100 Subject: [PATCH 0523/1222] implement valtrees as the type-system representation for constant values --- clippy_lints/src/enum_clike.rs | 6 +- clippy_lints/src/large_const_arrays.rs | 5 +- clippy_lints/src/large_stack_arrays.rs | 5 +- clippy_lints/src/matches/overlapping_arms.rs | 4 +- clippy_lints/src/non_copy_const.rs | 12 +- clippy_utils/src/consts.rs | 116 +++++++++---------- 6 files changed, 67 insertions(+), 81 deletions(-) diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index 10be245b3629..5d687d06f6f4 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -48,10 +48,10 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant { let mut ty = cx.tcx.type_of(def_id.to_def_id()); let constant = cx .tcx - .const_eval_poly(def_id.to_def_id()) + .const_eval_poly_for_typeck(def_id.to_def_id()) .ok() - .map(|val| rustc_middle::ty::Const::from_value(cx.tcx, val, ty)); - if let Some(Constant::Int(val)) = constant.and_then(miri_to_const) { + .and_then(|val| val.map(|valtree| rustc_middle::ty::Const::from_value(cx.tcx, valtree, ty))); + if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx.tcx, c)) { if let ty::Adt(adt, _) = ty.kind() { if adt.is_enum() { ty = adt.repr().discr_type().to_ty(cx.tcx); diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index ed47490e230c..e10993ba7ddc 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -3,7 +3,6 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::mir::interpret::ConstValue; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, ConstKind}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -53,8 +52,8 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays { if let ItemKind::Const(hir_ty, _) = &item.kind; let ty = hir_ty_to_ty(cx.tcx, hir_ty); if let ty::Array(element_type, cst) = ty.kind(); - if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.kind(); - if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx); + if let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind(); + if let Ok(element_count) = element_count.try_to_machine_usize(cx.tcx); if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()); if self.maximum_allowed_size < element_count * element_size; diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index 4ca69465fad4..0acbd81aec34 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -3,7 +3,6 @@ use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::mir::interpret::ConstValue; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, ConstKind}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -43,8 +42,8 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays { if_chain! { if let ExprKind::Repeat(_, _) = expr.kind; if let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind(); - if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.kind(); - if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx); + if let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind(); + if let Ok(element_count) = element_count.try_to_machine_usize(cx.tcx); if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()); if self.maximum_allowed_size < element_count * element_size; then { diff --git a/clippy_lints/src/matches/overlapping_arms.rs b/clippy_lints/src/matches/overlapping_arms.rs index c0b3e95b1852..afca7530556b 100644 --- a/clippy_lints/src/matches/overlapping_arms.rs +++ b/clippy_lints/src/matches/overlapping_arms.rs @@ -34,11 +34,11 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>) if let PatKind::Range(ref lhs, ref rhs, range_end) = pat.kind { let lhs_const = match lhs { Some(lhs) => constant(cx, cx.typeck_results(), lhs)?.0, - None => miri_to_const(ty.numeric_min_val(cx.tcx)?)?, + None => miri_to_const(cx.tcx, ty.numeric_min_val(cx.tcx)?)?, }; let rhs_const = match rhs { Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0, - None => miri_to_const(ty.numeric_max_val(cx.tcx)?)?, + None => miri_to_const(cx.tcx, ty.numeric_max_val(cx.tcx)?)?, }; let lhs_val = lhs_const.int_value(cx, ty)?; let rhs_val = rhs_const.int_value(cx, ty)?; diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 8db41ba6ee29..9f6fca27b229 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -13,7 +13,7 @@ use rustc_hir::{ BodyId, Expr, ExprKind, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind, UnOp, }; use rustc_lint::{LateContext, LateLintPass, Lint}; -use rustc_middle::mir::interpret::{ConstValue, ErrorHandled}; +use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::ty::adjustment::Adjust; use rustc_middle::ty::{self, Const, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -133,7 +133,7 @@ fn is_unfrozen<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { fn is_value_unfrozen_raw<'tcx>( cx: &LateContext<'tcx>, - result: Result, ErrorHandled>, + result: Result>, ErrorHandled>, ty: Ty<'tcx>, ) -> bool { fn inner<'tcx>(cx: &LateContext<'tcx>, val: Const<'tcx>) -> bool { @@ -142,7 +142,7 @@ fn is_value_unfrozen_raw<'tcx>( // leads us to the point checking `UnsafeCell` directly is the only option. ty::Adt(ty_def, ..) if Some(ty_def.did()) == cx.tcx.lang_items().unsafe_cell_type() => true, ty::Array(..) | ty::Adt(..) | ty::Tuple(..) => { - let val = cx.tcx.destructure_const(cx.param_env.and(val)); + let val = cx.tcx.destructure_const(val); val.fields.iter().any(|field| inner(cx, *field)) }, _ => false, @@ -174,19 +174,19 @@ fn is_value_unfrozen_raw<'tcx>( // I chose this way because unfrozen enums as assoc consts are rare (or, hopefully, none). err == ErrorHandled::TooGeneric }, - |val| inner(cx, Const::from_value(cx.tcx, val, ty)), + |val| val.map_or(false, |val| inner(cx, Const::from_value(cx.tcx, val, ty))), ) } fn is_value_unfrozen_poly<'tcx>(cx: &LateContext<'tcx>, body_id: BodyId, ty: Ty<'tcx>) -> bool { - let result = cx.tcx.const_eval_poly(body_id.hir_id.owner.to_def_id()); + let result = cx.tcx.const_eval_poly_for_typeck(body_id.hir_id.owner.to_def_id()); is_value_unfrozen_raw(cx, result, ty) } fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: DefId, ty: Ty<'tcx>) -> bool { let substs = cx.typeck_results().node_substs(hir_id); - let result = cx.tcx.const_eval_resolve( + let result = cx.tcx.const_eval_resolve_for_typeck( cx.param_env, ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), None, diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 159c5d53d029..c31c560f427f 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -7,7 +7,6 @@ use rustc_data_structures::sync::Lrc; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, Item, ItemKind, Node, QPath, UnOp}; use rustc_lint::LateContext; -use rustc_middle::mir::interpret::Scalar; use rustc_middle::ty::subst::{Subst, SubstsRef}; use rustc_middle::ty::{self, EarlyBinder, FloatTy, ScalarInt, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; @@ -423,14 +422,14 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let result = self .lcx .tcx - .const_eval_resolve( + .const_eval_resolve_for_typeck( self.param_env, ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), None, ) .ok() - .map(|val| rustc_middle::ty::Const::from_value(self.lcx.tcx, val, ty))?; - let result = miri_to_const(result); + .and_then(|val| val.map(|val| rustc_middle::ty::Const::from_value(self.lcx.tcx, val, ty)))?; + let result = miri_to_const(self.lcx.tcx, result); if result.is_some() { self.needed_resolution = true; } @@ -580,80 +579,69 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { } } -pub fn miri_to_const(result: ty::Const<'_>) -> Option { - use rustc_middle::mir::interpret::ConstValue; +pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: ty::Const<'tcx>) -> Option { match result.kind() { - ty::ConstKind::Value(ConstValue::Scalar(Scalar::Int(int))) => { - match result.ty().kind() { - ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)), - ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.assert_bits(int.size()))), - ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits( + ty::ConstKind::Value(valtree) => { + match (valtree, result.ty().kind()) { + (ty::ValTree::Leaf(int), ty::Bool) => Some(Constant::Bool(int == ScalarInt::TRUE)), + (ty::ValTree::Leaf(int), ty::Uint(_) | ty::Int(_)) => Some(Constant::Int(int.assert_bits(int.size()))), + (ty::ValTree::Leaf(int), ty::Float(FloatTy::F32)) => Some(Constant::F32(f32::from_bits( int.try_into().expect("invalid f32 bit representation"), ))), - ty::Float(FloatTy::F64) => Some(Constant::F64(f64::from_bits( + (ty::ValTree::Leaf(int), ty::Float(FloatTy::F64)) => Some(Constant::F64(f64::from_bits( int.try_into().expect("invalid f64 bit representation"), ))), - ty::RawPtr(type_and_mut) => { + (ty::ValTree::Leaf(int), ty::RawPtr(type_and_mut)) => { if let ty::Uint(_) = type_and_mut.ty.kind() { return Some(Constant::RawPtr(int.assert_bits(int.size()))); } None }, - // FIXME: implement other conversions. - _ => None, - } - }, - ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => match result.ty().kind() { - ty::Ref(_, tam, _) => match tam.kind() { - ty::Str => String::from_utf8( - data.inner() - .inspect_with_uninit_and_ptr_outside_interpreter(start..end) - .to_owned(), - ) - .ok() - .map(Constant::Str), - _ => None, - }, - _ => None, - }, - ty::ConstKind::Value(ConstValue::ByRef { alloc, offset: _ }) => match result.ty().kind() { - ty::Array(sub_type, len) => match sub_type.kind() { - ty::Float(FloatTy::F32) => match miri_to_const(*len) { - Some(Constant::Int(len)) => alloc - .inner() - .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * len as usize)) - .to_owned() - .chunks(4) - .map(|chunk| { - Some(Constant::F32(f32::from_le_bytes( - chunk.try_into().expect("this shouldn't happen"), - ))) - }) - .collect::>>() - .map(Constant::Vec), - _ => None, - }, - ty::Float(FloatTy::F64) => match miri_to_const(*len) { - Some(Constant::Int(len)) => alloc - .inner() - .inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * len as usize)) - .to_owned() - .chunks(8) - .map(|chunk| { - Some(Constant::F64(f64::from_le_bytes( - chunk.try_into().expect("this shouldn't happen"), - ))) - }) - .collect::>>() - .map(Constant::Vec), + (ty::ValTree::Branch(_), ty::Ref(_, inner_ty, _)) if *inner_ty == tcx.types.str_ => valtree + .try_to_raw_bytes(tcx, result.ty()) + .and_then(|bytes| String::from_utf8(bytes.to_owned()).ok().map(Constant::Str)), + (ty::ValTree::Branch(_), ty::Array(arr_ty, len)) => match arr_ty.kind() { + ty::Float(float_ty) => { + let chunk_size = match float_ty { + FloatTy::F32 => 4, + FloatTy::F64 => 8, + }; + + match miri_to_const(tcx, *len) { + Some(Constant::Int(_)) => valtree.try_to_raw_bytes(tcx, result.ty()).and_then(|bytes| { + bytes + .to_owned() + .chunks(chunk_size) + .map(|chunk| match float_ty { + FloatTy::F32 => { + let float = f32::from_le_bytes( + chunk + .try_into() + .expect(&format!("expected to construct f32 from {:?}", chunk)), + ); + Some(Constant::F32(float)) + }, + FloatTy::F64 => { + let float = f64::from_le_bytes( + chunk + .try_into() + .expect(&format!("expected to construct f64 from {:?}", chunk)), + ); + Some(Constant::F64(float)) + }, + }) + .collect::>>() + .map(Constant::Vec) + }), + _ => None, + } + }, _ => None, }, - // FIXME: implement other array type conversions. + // FIXME: implement other conversions. _ => None, - }, - _ => None, + } }, - // FIXME: implement other conversions. _ => None, } } From 56b8b828e5b2d5e7187e1efcf4520b02bb1863c7 Mon Sep 17 00:00:00 2001 From: b-naber Date: Thu, 2 Jun 2022 15:15:01 +0200 Subject: [PATCH 0524/1222] fix clippy test failures --- clippy_lints/src/enum_clike.rs | 4 +- clippy_lints/src/matches/overlapping_arms.rs | 19 ++- clippy_lints/src/non_copy_const.rs | 18 +-- clippy_utils/src/consts.rs | 125 +++++++++++-------- 4 files changed, 102 insertions(+), 64 deletions(-) diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index 5d687d06f6f4..b326d864d4bf 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -48,9 +48,9 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant { let mut ty = cx.tcx.type_of(def_id.to_def_id()); let constant = cx .tcx - .const_eval_poly_for_typeck(def_id.to_def_id()) + .const_eval_poly(def_id.to_def_id()) .ok() - .and_then(|val| val.map(|valtree| rustc_middle::ty::Const::from_value(cx.tcx, valtree, ty))); + .and_then(|val| Some(rustc_middle::mir::ConstantKind::from_value(val, ty))); if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx.tcx, c)) { if let ty::Adt(adt, _) = ty.kind() { if adt.is_enum() { diff --git a/clippy_lints/src/matches/overlapping_arms.rs b/clippy_lints/src/matches/overlapping_arms.rs index afca7530556b..ae69ca8a3393 100644 --- a/clippy_lints/src/matches/overlapping_arms.rs +++ b/clippy_lints/src/matches/overlapping_arms.rs @@ -3,6 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_note; use core::cmp::Ordering; use rustc_hir::{Arm, Expr, PatKind, RangeEnd}; use rustc_lint::LateContext; +use rustc_middle::mir; use rustc_middle::ty::Ty; use rustc_span::Span; @@ -34,11 +35,25 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>) if let PatKind::Range(ref lhs, ref rhs, range_end) = pat.kind { let lhs_const = match lhs { Some(lhs) => constant(cx, cx.typeck_results(), lhs)?.0, - None => miri_to_const(cx.tcx, ty.numeric_min_val(cx.tcx)?)?, + None => { + let min_val_const = ty.numeric_min_val(cx.tcx)?; + let min_constant = mir::ConstantKind::from_value( + cx.tcx.valtree_to_const_val((ty, min_val_const.to_valtree())), + ty, + ); + miri_to_const(cx.tcx, min_constant)? + }, }; let rhs_const = match rhs { Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0, - None => miri_to_const(cx.tcx, ty.numeric_max_val(cx.tcx)?)?, + None => { + let max_val_const = ty.numeric_max_val(cx.tcx)?; + let max_constant = mir::ConstantKind::from_value( + cx.tcx.valtree_to_const_val((ty, max_val_const.to_valtree())), + ty, + ); + miri_to_const(cx.tcx, max_constant)? + }, }; let lhs_val = lhs_const.int_value(cx, ty)?; let rhs_val = rhs_const.int_value(cx, ty)?; diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 9f6fca27b229..7163cfe5e3a2 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -13,9 +13,10 @@ use rustc_hir::{ BodyId, Expr, ExprKind, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind, UnOp, }; use rustc_lint::{LateContext, LateLintPass, Lint}; -use rustc_middle::mir::interpret::ErrorHandled; +use rustc_middle::mir; +use rustc_middle::mir::interpret::{ConstValue, ErrorHandled}; use rustc_middle::ty::adjustment::Adjust; -use rustc_middle::ty::{self, Const, Ty}; +use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{InnerSpan, Span, DUMMY_SP}; use rustc_typeck::hir_ty_to_ty; @@ -133,22 +134,21 @@ fn is_unfrozen<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { fn is_value_unfrozen_raw<'tcx>( cx: &LateContext<'tcx>, - result: Result>, ErrorHandled>, + result: Result, ErrorHandled>, ty: Ty<'tcx>, ) -> bool { - fn inner<'tcx>(cx: &LateContext<'tcx>, val: Const<'tcx>) -> bool { + fn inner<'tcx>(cx: &LateContext<'tcx>, val: mir::ConstantKind<'tcx>) -> bool { match val.ty().kind() { // the fact that we have to dig into every structs to search enums // leads us to the point checking `UnsafeCell` directly is the only option. ty::Adt(ty_def, ..) if Some(ty_def.did()) == cx.tcx.lang_items().unsafe_cell_type() => true, ty::Array(..) | ty::Adt(..) | ty::Tuple(..) => { - let val = cx.tcx.destructure_const(val); + let val = cx.tcx.destructure_mir_constant(cx.param_env, val); val.fields.iter().any(|field| inner(cx, *field)) }, _ => false, } } - result.map_or_else( |err| { // Consider `TooGeneric` cases as being unfrozen. @@ -174,19 +174,19 @@ fn is_value_unfrozen_raw<'tcx>( // I chose this way because unfrozen enums as assoc consts are rare (or, hopefully, none). err == ErrorHandled::TooGeneric }, - |val| val.map_or(false, |val| inner(cx, Const::from_value(cx.tcx, val, ty))), + |val| inner(cx, mir::ConstantKind::from_value(val, ty)), ) } fn is_value_unfrozen_poly<'tcx>(cx: &LateContext<'tcx>, body_id: BodyId, ty: Ty<'tcx>) -> bool { - let result = cx.tcx.const_eval_poly_for_typeck(body_id.hir_id.owner.to_def_id()); + let result = cx.tcx.const_eval_poly(body_id.hir_id.owner.to_def_id()); is_value_unfrozen_raw(cx, result, ty) } fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: DefId, ty: Ty<'tcx>) -> bool { let substs = cx.typeck_results().node_substs(hir_id); - let result = cx.tcx.const_eval_resolve_for_typeck( + let result = cx.tcx.const_eval_resolve( cx.param_env, ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), None, diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index c31c560f427f..ec323806fbf9 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -7,6 +7,8 @@ use rustc_data_structures::sync::Lrc; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, Item, ItemKind, Node, QPath, UnOp}; use rustc_lint::LateContext; +use rustc_middle::mir; +use rustc_middle::mir::interpret::Scalar; use rustc_middle::ty::subst::{Subst, SubstsRef}; use rustc_middle::ty::{self, EarlyBinder, FloatTy, ScalarInt, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; @@ -422,13 +424,13 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let result = self .lcx .tcx - .const_eval_resolve_for_typeck( + .const_eval_resolve( self.param_env, ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), None, ) .ok() - .and_then(|val| val.map(|val| rustc_middle::ty::Const::from_value(self.lcx.tcx, val, ty)))?; + .and_then(|val| Some(rustc_middle::mir::ConstantKind::from_value(val, ty)))?; let result = miri_to_const(self.lcx.tcx, result); if result.is_some() { self.needed_resolution = true; @@ -579,69 +581,90 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { } } -pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: ty::Const<'tcx>) -> Option { - match result.kind() { +fn try_const_to_constant<'tcx>(tcx: TyCtxt<'tcx>, c: ty::Const<'tcx>) -> Option { + match c.kind() { ty::ConstKind::Value(valtree) => { - match (valtree, result.ty().kind()) { - (ty::ValTree::Leaf(int), ty::Bool) => Some(Constant::Bool(int == ScalarInt::TRUE)), - (ty::ValTree::Leaf(int), ty::Uint(_) | ty::Int(_)) => Some(Constant::Int(int.assert_bits(int.size()))), - (ty::ValTree::Leaf(int), ty::Float(FloatTy::F32)) => Some(Constant::F32(f32::from_bits( + let const_val = tcx.valtree_to_const_val((c.ty(), valtree)); + miri_to_const(tcx, mir::ConstantKind::from_value(const_val, c.ty())) + }, + _ => None, + } +} + +pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) -> Option { + use rustc_middle::mir::interpret::ConstValue; + match result { + mir::ConstantKind::Val(ConstValue::Scalar(Scalar::Int(int)), _) => { + match result.ty().kind() { + ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)), + ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.assert_bits(int.size()))), + ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits( int.try_into().expect("invalid f32 bit representation"), ))), - (ty::ValTree::Leaf(int), ty::Float(FloatTy::F64)) => Some(Constant::F64(f64::from_bits( + ty::Float(FloatTy::F64) => Some(Constant::F64(f64::from_bits( int.try_into().expect("invalid f64 bit representation"), ))), - (ty::ValTree::Leaf(int), ty::RawPtr(type_and_mut)) => { + ty::RawPtr(type_and_mut) => { if let ty::Uint(_) = type_and_mut.ty.kind() { return Some(Constant::RawPtr(int.assert_bits(int.size()))); } None }, - (ty::ValTree::Branch(_), ty::Ref(_, inner_ty, _)) if *inner_ty == tcx.types.str_ => valtree - .try_to_raw_bytes(tcx, result.ty()) - .and_then(|bytes| String::from_utf8(bytes.to_owned()).ok().map(Constant::Str)), - (ty::ValTree::Branch(_), ty::Array(arr_ty, len)) => match arr_ty.kind() { - ty::Float(float_ty) => { - let chunk_size = match float_ty { - FloatTy::F32 => 4, - FloatTy::F64 => 8, - }; - - match miri_to_const(tcx, *len) { - Some(Constant::Int(_)) => valtree.try_to_raw_bytes(tcx, result.ty()).and_then(|bytes| { - bytes - .to_owned() - .chunks(chunk_size) - .map(|chunk| match float_ty { - FloatTy::F32 => { - let float = f32::from_le_bytes( - chunk - .try_into() - .expect(&format!("expected to construct f32 from {:?}", chunk)), - ); - Some(Constant::F32(float)) - }, - FloatTy::F64 => { - let float = f64::from_le_bytes( - chunk - .try_into() - .expect(&format!("expected to construct f64 from {:?}", chunk)), - ); - Some(Constant::F64(float)) - }, - }) - .collect::>>() - .map(Constant::Vec) - }), - _ => None, - } - }, - _ => None, - }, // FIXME: implement other conversions. _ => None, } }, + mir::ConstantKind::Val(ConstValue::Slice { data, start, end }, _) => match result.ty().kind() { + ty::Ref(_, tam, _) => match tam.kind() { + ty::Str => String::from_utf8( + data.inner() + .inspect_with_uninit_and_ptr_outside_interpreter(start..end) + .to_owned(), + ) + .ok() + .map(Constant::Str), + _ => None, + }, + _ => None, + }, + mir::ConstantKind::Val(ConstValue::ByRef { alloc, offset: _ }, _) => match result.ty().kind() { + ty::Array(sub_type, len) => match sub_type.kind() { + ty::Float(FloatTy::F32) => match try_const_to_constant(tcx, *len) { + Some(Constant::Int(len)) => alloc + .inner() + .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * len as usize)) + .to_owned() + .chunks(4) + .map(|chunk| { + Some(Constant::F32(f32::from_le_bytes( + chunk.try_into().expect("this shouldn't happen"), + ))) + }) + .collect::>>() + .map(Constant::Vec), + _ => None, + }, + ty::Float(FloatTy::F64) => match try_const_to_constant(tcx, *len) { + Some(Constant::Int(len)) => alloc + .inner() + .inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * len as usize)) + .to_owned() + .chunks(8) + .map(|chunk| { + Some(Constant::F64(f64::from_le_bytes( + chunk.try_into().expect("this shouldn't happen"), + ))) + }) + .collect::>>() + .map(Constant::Vec), + _ => None, + }, + // FIXME: implement other array type conversions. + _ => None, + }, + _ => None, + }, + // FIXME: implement other conversions. _ => None, } } From aed714c7871e0bc5cad2bcdfdf04999bd7085e1f Mon Sep 17 00:00:00 2001 From: b-naber Date: Fri, 3 Jun 2022 20:42:35 +0200 Subject: [PATCH 0525/1222] address review --- clippy_lints/src/enum_clike.rs | 2 +- clippy_utils/src/consts.rs | 20 +++++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index b326d864d4bf..da67888827d1 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant { .tcx .const_eval_poly(def_id.to_def_id()) .ok() - .and_then(|val| Some(rustc_middle::mir::ConstantKind::from_value(val, ty))); + .map(|val| rustc_middle::mir::ConstantKind::from_value(val, ty)); if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx.tcx, c)) { if let ty::Adt(adt, _) = ty.kind() { if adt.is_enum() { diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index ec323806fbf9..6709ac13a432 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -430,7 +430,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { None, ) .ok() - .and_then(|val| Some(rustc_middle::mir::ConstantKind::from_value(val, ty)))?; + .map(|val| rustc_middle::mir::ConstantKind::from_value(val, ty))?; let result = miri_to_const(self.lcx.tcx, result); if result.is_some() { self.needed_resolution = true; @@ -581,16 +581,6 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { } } -fn try_const_to_constant<'tcx>(tcx: TyCtxt<'tcx>, c: ty::Const<'tcx>) -> Option { - match c.kind() { - ty::ConstKind::Value(valtree) => { - let const_val = tcx.valtree_to_const_val((c.ty(), valtree)); - miri_to_const(tcx, mir::ConstantKind::from_value(const_val, c.ty())) - }, - _ => None, - } -} - pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) -> Option { use rustc_middle::mir::interpret::ConstValue; match result { @@ -629,8 +619,8 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) - }, mir::ConstantKind::Val(ConstValue::ByRef { alloc, offset: _ }, _) => match result.ty().kind() { ty::Array(sub_type, len) => match sub_type.kind() { - ty::Float(FloatTy::F32) => match try_const_to_constant(tcx, *len) { - Some(Constant::Int(len)) => alloc + ty::Float(FloatTy::F32) => match len.try_eval_usize(tcx, ty::ParamEnv::empty()) { + Some(len) => alloc .inner() .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * len as usize)) .to_owned() @@ -644,8 +634,8 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) - .map(Constant::Vec), _ => None, }, - ty::Float(FloatTy::F64) => match try_const_to_constant(tcx, *len) { - Some(Constant::Int(len)) => alloc + ty::Float(FloatTy::F64) => match len.try_eval_usize(tcx, ty::ParamEnv::empty()) { + Some(len) => alloc .inner() .inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * len as usize)) .to_owned() From 2a36b10fc5e5d34c65da948cdb03b195b2e7b37b Mon Sep 17 00:00:00 2001 From: b-naber Date: Fri, 3 Jun 2022 21:41:01 +0200 Subject: [PATCH 0526/1222] fix wrong evaluation in clippy --- clippy_utils/src/consts.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 6709ac13a432..5d0ce6cc620a 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -619,7 +619,7 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) - }, mir::ConstantKind::Val(ConstValue::ByRef { alloc, offset: _ }, _) => match result.ty().kind() { ty::Array(sub_type, len) => match sub_type.kind() { - ty::Float(FloatTy::F32) => match len.try_eval_usize(tcx, ty::ParamEnv::empty()) { + ty::Float(FloatTy::F32) => match len.to_valtree().try_to_machine_usize(tcx) { Some(len) => alloc .inner() .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * len as usize)) @@ -634,7 +634,7 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) - .map(Constant::Vec), _ => None, }, - ty::Float(FloatTy::F64) => match len.try_eval_usize(tcx, ty::ParamEnv::empty()) { + ty::Float(FloatTy::F64) => match len.to_valtree().try_to_machine_usize(tcx) { Some(len) => alloc .inner() .inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * len as usize)) From b8969046a557a8e7d7469550d58970d564b1466d Mon Sep 17 00:00:00 2001 From: klensy Date: Wed, 15 Jun 2022 14:15:54 +0300 Subject: [PATCH 0527/1222] bless clippy tests --- tests/ui/eprint_with_newline.stderr | 16 ++++++++-------- tests/ui/manual_split_once.stderr | 20 ++++++++++---------- tests/ui/map_unwrap_or.stderr | 8 ++++---- tests/ui/needless_late_init.stderr | 4 ++-- tests/ui/print_literal.stderr | 22 +++++++++++----------- tests/ui/print_with_newline.stderr | 16 ++++++++-------- tests/ui/unnecessary_iter_cloned.stderr | 4 ++-- tests/ui/unnecessary_to_owned.stderr | 2 +- tests/ui/write_literal.stderr | 22 +++++++++++----------- tests/ui/write_literal_2.stderr | 10 +++++----- tests/ui/write_with_newline.stderr | 16 ++++++++-------- 11 files changed, 70 insertions(+), 70 deletions(-) diff --git a/tests/ui/eprint_with_newline.stderr b/tests/ui/eprint_with_newline.stderr index 090dae3733d9..f137787bff0c 100644 --- a/tests/ui/eprint_with_newline.stderr +++ b/tests/ui/eprint_with_newline.stderr @@ -9,7 +9,7 @@ help: use `eprintln!` instead | LL - eprint!("Hello/n"); LL + eprintln!("Hello"); - | + | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:6:5 @@ -21,7 +21,7 @@ help: use `eprintln!` instead | LL - eprint!("Hello {}/n", "world"); LL + eprintln!("Hello {}", "world"); - | + | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:7:5 @@ -33,7 +33,7 @@ help: use `eprintln!` instead | LL - eprint!("Hello {} {}/n", "world", "#2"); LL + eprintln!("Hello {} {}", "world", "#2"); - | + | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:8:5 @@ -45,7 +45,7 @@ help: use `eprintln!` instead | LL - eprint!("{}/n", 1265); LL + eprintln!("{}", 1265); - | + | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:9:5 @@ -57,7 +57,7 @@ help: use `eprintln!` instead | LL - eprint!("/n"); LL + eprintln!(); - | + | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:28:5 @@ -69,7 +69,7 @@ help: use `eprintln!` instead | LL - eprint!("//n"); // should fail LL + eprintln!("/"); // should fail - | + | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:35:5 @@ -111,7 +111,7 @@ help: use `eprintln!` instead | LL - eprint!("/r/n"); //~ ERROR LL + eprintln!("/r"); //~ ERROR - | + | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:48:5 @@ -123,7 +123,7 @@ help: use `eprintln!` instead | LL - eprint!("foo/rbar/n") // ~ ERROR LL + eprintln!("foo/rbar") // ~ ERROR - | + | error: aborting due to 10 previous errors diff --git a/tests/ui/manual_split_once.stderr b/tests/ui/manual_split_once.stderr index 2563a6904b77..2696694680ad 100644 --- a/tests/ui/manual_split_once.stderr +++ b/tests/ui/manual_split_once.stderr @@ -96,12 +96,12 @@ help: remove the `iter` usages | LL - let l = iter.next().unwrap(); LL + - | + | help: remove the `iter` usages | LL - let r = iter.next().unwrap(); LL + - | + | error: manual implementation of `split_once` --> $DIR/manual_split_once.rs:49:5 @@ -121,12 +121,12 @@ help: remove the `iter` usages | LL - let l = iter.next()?; LL + - | + | help: remove the `iter` usages | LL - let r = iter.next()?; LL + - | + | error: manual implementation of `rsplit_once` --> $DIR/manual_split_once.rs:53:5 @@ -146,12 +146,12 @@ help: remove the `iter` usages | LL - let r = iter.next().unwrap(); LL + - | + | help: remove the `iter` usages | LL - let l = iter.next().unwrap(); LL + - | + | error: manual implementation of `rsplit_once` --> $DIR/manual_split_once.rs:57:5 @@ -171,12 +171,12 @@ help: remove the `iter` usages | LL - let r = iter.next()?; LL + - | + | help: remove the `iter` usages | LL - let l = iter.next()?; LL + - | + | error: manual implementation of `split_once` --> $DIR/manual_split_once.rs:142:13 @@ -202,12 +202,12 @@ help: remove the `iter` usages | LL - let a = iter.next().unwrap(); LL + - | + | help: remove the `iter` usages | LL - let b = iter.next().unwrap(); LL + - | + | error: aborting due to 19 previous errors diff --git a/tests/ui/map_unwrap_or.stderr b/tests/ui/map_unwrap_or.stderr index 954000b8b76d..abc9c1ece327 100644 --- a/tests/ui/map_unwrap_or.stderr +++ b/tests/ui/map_unwrap_or.stderr @@ -12,7 +12,7 @@ help: use `map_or(
, )` instead | LL - let _ = opt.map(|x| x + 1) LL + let _ = opt.map_or(0, |x| x + 1); - | + | error: called `map().unwrap_or()` on an `Option` value. This can be done more directly by calling `map_or(, )` instead --> $DIR/map_unwrap_or.rs:20:13 @@ -59,7 +59,7 @@ help: use `and_then()` instead | LL - let _ = opt.map(|x| Some(x + 1)).unwrap_or(None); LL + let _ = opt.and_then(|x| Some(x + 1)); - | + | error: called `map().unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then()` instead --> $DIR/map_unwrap_or.rs:31:13 @@ -92,7 +92,7 @@ help: use `and_then()` instead | LL - .map(|x| Some(x + 1)) LL + .and_then(|x| Some(x + 1)); - | + | error: called `map().unwrap_or()` on an `Option` value. This can be done more directly by calling `map_or(, )` instead --> $DIR/map_unwrap_or.rs:46:13 @@ -104,7 +104,7 @@ help: use `map_or(, )` instead | LL - let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id); LL + let _ = Some("prefix").map_or(id, |p| format!("{}.", p)); - | + | error: called `map().unwrap_or_else()` on an `Option` value. This can be done more directly by calling `map_or_else(, )` instead --> $DIR/map_unwrap_or.rs:50:13 diff --git a/tests/ui/needless_late_init.stderr b/tests/ui/needless_late_init.stderr index f320b5b9cbb3..313cdbbeba18 100644 --- a/tests/ui/needless_late_init.stderr +++ b/tests/ui/needless_late_init.stderr @@ -164,7 +164,7 @@ help: remove the assignments from the `match` arms | LL - 1 => f = "three", LL + 1 => "three", - | + | error: unneeded late initialization --> $DIR/needless_late_init.rs:76:5 @@ -180,7 +180,7 @@ help: remove the assignments from the branches | LL - g = 5; LL + 5 - | + | help: add a semicolon after the `if` expression | LL | }; diff --git a/tests/ui/print_literal.stderr b/tests/ui/print_literal.stderr index a10cac04411c..72aae0756033 100644 --- a/tests/ui/print_literal.stderr +++ b/tests/ui/print_literal.stderr @@ -9,7 +9,7 @@ help: try this | LL - print!("Hello {}", "world"); LL + print!("Hello world"); - | + | error: literal with an empty format string --> $DIR/print_literal.rs:26:36 @@ -21,7 +21,7 @@ help: try this | LL - println!("Hello {} {}", world, "world"); LL + println!("Hello {} world", world); - | + | error: literal with an empty format string --> $DIR/print_literal.rs:27:26 @@ -33,7 +33,7 @@ help: try this | LL - println!("Hello {}", "world"); LL + println!("Hello world"); - | + | error: literal with an empty format string --> $DIR/print_literal.rs:32:25 @@ -45,7 +45,7 @@ help: try this | LL - println!("{0} {1}", "hello", "world"); LL + println!("hello {1}", "world"); - | + | error: literal with an empty format string --> $DIR/print_literal.rs:32:34 @@ -57,7 +57,7 @@ help: try this | LL - println!("{0} {1}", "hello", "world"); LL + println!("{0} world", "hello"); - | + | error: literal with an empty format string --> $DIR/print_literal.rs:33:25 @@ -69,7 +69,7 @@ help: try this | LL - println!("{1} {0}", "hello", "world"); LL + println!("{1} hello", "world"); - | + | error: literal with an empty format string --> $DIR/print_literal.rs:33:34 @@ -81,7 +81,7 @@ help: try this | LL - println!("{1} {0}", "hello", "world"); LL + println!("world {0}", "hello"); - | + | error: literal with an empty format string --> $DIR/print_literal.rs:36:29 @@ -93,7 +93,7 @@ help: try this | LL - println!("{foo} {bar}", foo = "hello", bar = "world"); LL + println!("hello {bar}", bar = "world"); - | + | error: literal with an empty format string --> $DIR/print_literal.rs:36:44 @@ -105,7 +105,7 @@ help: try this | LL - println!("{foo} {bar}", foo = "hello", bar = "world"); LL + println!("{foo} world", foo = "hello"); - | + | error: literal with an empty format string --> $DIR/print_literal.rs:37:29 @@ -117,7 +117,7 @@ help: try this | LL - println!("{bar} {foo}", foo = "hello", bar = "world"); LL + println!("{bar} hello", bar = "world"); - | + | error: literal with an empty format string --> $DIR/print_literal.rs:37:44 @@ -129,7 +129,7 @@ help: try this | LL - println!("{bar} {foo}", foo = "hello", bar = "world"); LL + println!("world {foo}", foo = "hello"); - | + | error: aborting due to 11 previous errors diff --git a/tests/ui/print_with_newline.stderr b/tests/ui/print_with_newline.stderr index d409bee30ece..edbaa1cdf979 100644 --- a/tests/ui/print_with_newline.stderr +++ b/tests/ui/print_with_newline.stderr @@ -9,7 +9,7 @@ help: use `println!` instead | LL - print!("Hello/n"); LL + println!("Hello"); - | + | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:9:5 @@ -21,7 +21,7 @@ help: use `println!` instead | LL - print!("Hello {}/n", "world"); LL + println!("Hello {}", "world"); - | + | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:10:5 @@ -33,7 +33,7 @@ help: use `println!` instead | LL - print!("Hello {} {}/n", "world", "#2"); LL + println!("Hello {} {}", "world", "#2"); - | + | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:11:5 @@ -45,7 +45,7 @@ help: use `println!` instead | LL - print!("{}/n", 1265); LL + println!("{}", 1265); - | + | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:12:5 @@ -57,7 +57,7 @@ help: use `println!` instead | LL - print!("/n"); LL + println!(); - | + | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:31:5 @@ -69,7 +69,7 @@ help: use `println!` instead | LL - print!("//n"); // should fail LL + println!("/"); // should fail - | + | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:38:5 @@ -111,7 +111,7 @@ help: use `println!` instead | LL - print!("/r/n"); //~ ERROR LL + println!("/r"); //~ ERROR - | + | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:51:5 @@ -123,7 +123,7 @@ help: use `println!` instead | LL - print!("foo/rbar/n") // ~ ERROR LL + println!("foo/rbar") // ~ ERROR - | + | error: aborting due to 10 previous errors diff --git a/tests/ui/unnecessary_iter_cloned.stderr b/tests/ui/unnecessary_iter_cloned.stderr index e44379f8aa04..8f151e620a25 100644 --- a/tests/ui/unnecessary_iter_cloned.stderr +++ b/tests/ui/unnecessary_iter_cloned.stderr @@ -13,7 +13,7 @@ help: remove this `&` | LL - let other = match get_file_path(&t) { LL + let other = match get_file_path(t) { - | + | error: unnecessary use of `copied` --> $DIR/unnecessary_iter_cloned.rs:46:22 @@ -29,7 +29,7 @@ help: remove this `&` | LL - let other = match get_file_path(&t) { LL + let other = match get_file_path(t) { - | + | error: aborting due to 2 previous errors diff --git a/tests/ui/unnecessary_to_owned.stderr b/tests/ui/unnecessary_to_owned.stderr index af7e7b41fb00..243b4599dba4 100644 --- a/tests/ui/unnecessary_to_owned.stderr +++ b/tests/ui/unnecessary_to_owned.stderr @@ -489,7 +489,7 @@ help: remove this `&` | LL - let path = match get_file_path(&t) { LL + let path = match get_file_path(t) { - | + | error: unnecessary use of `to_vec` --> $DIR/unnecessary_to_owned.rs:221:14 diff --git a/tests/ui/write_literal.stderr b/tests/ui/write_literal.stderr index 593e9493ec59..3c5ec91d3e0f 100644 --- a/tests/ui/write_literal.stderr +++ b/tests/ui/write_literal.stderr @@ -9,7 +9,7 @@ help: try this | LL - write!(v, "Hello {}", "world"); LL + write!(v, "Hello world"); - | + | error: literal with an empty format string --> $DIR/write_literal.rs:31:39 @@ -21,7 +21,7 @@ help: try this | LL - writeln!(v, "Hello {} {}", world, "world"); LL + writeln!(v, "Hello {} world", world); - | + | error: literal with an empty format string --> $DIR/write_literal.rs:32:29 @@ -33,7 +33,7 @@ help: try this | LL - writeln!(v, "Hello {}", "world"); LL + writeln!(v, "Hello world"); - | + | error: literal with an empty format string --> $DIR/write_literal.rs:37:28 @@ -45,7 +45,7 @@ help: try this | LL - writeln!(v, "{0} {1}", "hello", "world"); LL + writeln!(v, "hello {1}", "world"); - | + | error: literal with an empty format string --> $DIR/write_literal.rs:37:37 @@ -57,7 +57,7 @@ help: try this | LL - writeln!(v, "{0} {1}", "hello", "world"); LL + writeln!(v, "{0} world", "hello"); - | + | error: literal with an empty format string --> $DIR/write_literal.rs:38:28 @@ -69,7 +69,7 @@ help: try this | LL - writeln!(v, "{1} {0}", "hello", "world"); LL + writeln!(v, "{1} hello", "world"); - | + | error: literal with an empty format string --> $DIR/write_literal.rs:38:37 @@ -81,7 +81,7 @@ help: try this | LL - writeln!(v, "{1} {0}", "hello", "world"); LL + writeln!(v, "world {0}", "hello"); - | + | error: literal with an empty format string --> $DIR/write_literal.rs:41:32 @@ -93,7 +93,7 @@ help: try this | LL - writeln!(v, "{foo} {bar}", foo = "hello", bar = "world"); LL + writeln!(v, "hello {bar}", bar = "world"); - | + | error: literal with an empty format string --> $DIR/write_literal.rs:41:47 @@ -105,7 +105,7 @@ help: try this | LL - writeln!(v, "{foo} {bar}", foo = "hello", bar = "world"); LL + writeln!(v, "{foo} world", foo = "hello"); - | + | error: literal with an empty format string --> $DIR/write_literal.rs:42:32 @@ -117,7 +117,7 @@ help: try this | LL - writeln!(v, "{bar} {foo}", foo = "hello", bar = "world"); LL + writeln!(v, "{bar} hello", bar = "world"); - | + | error: literal with an empty format string --> $DIR/write_literal.rs:42:47 @@ -129,7 +129,7 @@ help: try this | LL - writeln!(v, "{bar} {foo}", foo = "hello", bar = "world"); LL + writeln!(v, "world {foo}", foo = "hello"); - | + | error: aborting due to 11 previous errors diff --git a/tests/ui/write_literal_2.stderr b/tests/ui/write_literal_2.stderr index fc40fbfa9e23..9ff297069c40 100644 --- a/tests/ui/write_literal_2.stderr +++ b/tests/ui/write_literal_2.stderr @@ -9,7 +9,7 @@ help: try this | LL - writeln!(v, "{}", "{hello}"); LL + writeln!(v, "{{hello}}"); - | + | error: literal with an empty format string --> $DIR/write_literal_2.rs:10:24 @@ -21,7 +21,7 @@ help: try this | LL - writeln!(v, r"{}", r"{hello}"); LL + writeln!(v, r"{{hello}}"); - | + | error: literal with an empty format string --> $DIR/write_literal_2.rs:11:23 @@ -33,7 +33,7 @@ help: try this | LL - writeln!(v, "{}", '/''); LL + writeln!(v, "'"); - | + | error: literal with an empty format string --> $DIR/write_literal_2.rs:12:23 @@ -45,7 +45,7 @@ help: try this | LL - writeln!(v, "{}", '"'); LL + writeln!(v, "/""); - | + | error: literal with an empty format string --> $DIR/write_literal_2.rs:14:24 @@ -57,7 +57,7 @@ help: try this | LL - writeln!(v, r"{}", '/''); LL + writeln!(v, r"'"); - | + | error: literal with an empty format string --> $DIR/write_literal_2.rs:18:9 diff --git a/tests/ui/write_with_newline.stderr b/tests/ui/write_with_newline.stderr index 3314a2a6e242..5f55431be0bd 100644 --- a/tests/ui/write_with_newline.stderr +++ b/tests/ui/write_with_newline.stderr @@ -9,7 +9,7 @@ help: use `writeln!()` instead | LL - write!(v, "Hello/n"); LL + writeln!(v, "Hello"); - | + | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:14:5 @@ -21,7 +21,7 @@ help: use `writeln!()` instead | LL - write!(v, "Hello {}/n", "world"); LL + writeln!(v, "Hello {}", "world"); - | + | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:15:5 @@ -33,7 +33,7 @@ help: use `writeln!()` instead | LL - write!(v, "Hello {} {}/n", "world", "#2"); LL + writeln!(v, "Hello {} {}", "world", "#2"); - | + | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:16:5 @@ -45,7 +45,7 @@ help: use `writeln!()` instead | LL - write!(v, "{}/n", 1265); LL + writeln!(v, "{}", 1265); - | + | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:17:5 @@ -57,7 +57,7 @@ help: use `writeln!()` instead | LL - write!(v, "/n"); LL + writeln!(v); - | + | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:36:5 @@ -69,7 +69,7 @@ help: use `writeln!()` instead | LL - write!(v, "//n"); // should fail LL + writeln!(v, "/"); // should fail - | + | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:43:5 @@ -115,7 +115,7 @@ help: use `writeln!()` instead | LL - write!(v, "/r/n"); //~ ERROR LL + writeln!(v, "/r"); //~ ERROR - | + | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:58:5 @@ -127,7 +127,7 @@ help: use `writeln!()` instead | LL - write!(v, "foo/rbar/n"); LL + writeln!(v, "foo/rbar"); - | + | error: aborting due to 10 previous errors From d427fbdb974f7446511d55b02f3543cbab34615a Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 16 Jun 2022 18:00:32 +0400 Subject: [PATCH 0528/1222] bless clippy ui tests --- tests/ui/bind_instead_of_map_multipart.stderr | 18 ++++++++ .../shared_at_top_and_bottom.stderr | 3 +- tests/ui/entry.stderr | 41 ++++++++++++++++--- tests/ui/entry_with_else.stderr | 17 ++++++-- tests/ui/let_unit.stderr | 3 +- tests/ui/manual_async_fn.stderr | 9 +++- tests/ui/needless_for_each_unfixable.stderr | 3 +- tests/ui/new_without_default.stderr | 3 +- tests/ui/ptr_arg.stderr | 3 +- tests/ui/significant_drop_in_scrutinee.stderr | 9 +++- tests/ui/unit_arg.stderr | 8 +++- tests/ui/unnecessary_wraps.stderr | 6 ++- 12 files changed, 102 insertions(+), 21 deletions(-) diff --git a/tests/ui/bind_instead_of_map_multipart.stderr b/tests/ui/bind_instead_of_map_multipart.stderr index f822b6f49fa3..0152a93feee4 100644 --- a/tests/ui/bind_instead_of_map_multipart.stderr +++ b/tests/ui/bind_instead_of_map_multipart.stderr @@ -56,7 +56,25 @@ LL | if s == "43" { LL ~ return 43; LL | } LL | s == "42" +LL | } { +LL ~ return 45; +LL | } +LL | match s.len() { +LL ~ 10 => 2, +LL | 20 => { ... +LL | if foo() { +LL ~ return 20; +LL | } +LL | println!("foo"); +LL ~ 3 +LL | }; +LL | } +LL ~ 20 +LL | }, +LL ~ 40 => 30, +LL ~ _ => 1, + | error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` --> $DIR/bind_instead_of_map_multipart.rs:61:13 diff --git a/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr b/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr index 1db2343d3fe9..37fe2f76f4a0 100644 --- a/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr +++ b/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr @@ -98,7 +98,8 @@ LL + id: e_id, LL + name: "Player 1".to_string(), LL + some_data: vec![0x12, 0x34, 0x56, 0x78, 0x90], LL + }; - ... +LL + process_data(pack); + | error: all if blocks contain the same code at the start and the end. Here at the start --> $DIR/shared_at_top_and_bottom.rs:94:5 diff --git a/tests/ui/entry.stderr b/tests/ui/entry.stderr index 1076500498d3..2ef9966525ce 100644 --- a/tests/ui/entry.stderr +++ b/tests/ui/entry.stderr @@ -28,7 +28,8 @@ LL + v LL + } else { LL + v2 LL + } - ... +LL + }); + | error: usage of `contains_key` followed by `insert` on a `HashMap` --> $DIR/entry.rs:38:5 @@ -50,7 +51,8 @@ LL + v LL + } else { LL + v2 LL + } - ... +LL + }); + | error: usage of `contains_key` followed by `insert` on a `HashMap` --> $DIR/entry.rs:47:5 @@ -72,7 +74,9 @@ LL + e.insert(v); LL + } else { LL + e.insert(v2); LL + return; - ... +LL + } +LL + } + | error: usage of `contains_key` followed by `insert` on a `HashMap` --> $DIR/entry.rs:57:5 @@ -111,7 +115,11 @@ LL + 1 if true => { LL + v LL + }, LL + _ => { - ... +LL + v2 +LL + }, +LL + } +LL + }); + | error: usage of `contains_key` followed by `insert` on a `HashMap` --> $DIR/entry.rs:75:5 @@ -133,7 +141,9 @@ LL + 0 => foo(), LL + _ => { LL + e.insert(v2); LL + }, - ... +LL + }; +LL + } + | error: usage of `contains_key` followed by `insert` on a `HashMap` --> $DIR/entry.rs:85:5 @@ -155,7 +165,26 @@ LL + match 0 { LL + 0 if false => { LL + v LL + }, - ... +LL + 1 => { +LL + foo(); +LL + v +LL + }, +LL + 2 | 3 => { +LL + for _ in 0..2 { +LL + foo(); +LL + } +LL + if true { +LL + v +LL + } else { +LL + v2 +LL + } +LL + }, +LL + _ => { +LL + v2 +LL + }, +LL + } +LL + }); + | error: usage of `contains_key` followed by `insert` on a `HashMap` --> $DIR/entry.rs:119:5 diff --git a/tests/ui/entry_with_else.stderr b/tests/ui/entry_with_else.stderr index 7279efc59595..e0f6671b460e 100644 --- a/tests/ui/entry_with_else.stderr +++ b/tests/ui/entry_with_else.stderr @@ -17,7 +17,9 @@ LL + e.insert(v); LL + } LL + std::collections::hash_map::Entry::Occupied(mut e) => { LL + e.insert(v2); - ... +LL + } +LL + } + | error: usage of `contains_key` followed by `insert` on a `HashMap` --> $DIR/entry_with_else.rs:22:5 @@ -37,7 +39,9 @@ LL + e.insert(v); LL + } LL + std::collections::hash_map::Entry::Vacant(e) => { LL + e.insert(v2); - ... +LL + } +LL + } + | error: usage of `contains_key` followed by `insert` on a `HashMap` --> $DIR/entry_with_else.rs:28:5 @@ -95,7 +99,9 @@ LL + e.insert(v); LL + } LL + std::collections::hash_map::Entry::Occupied(mut e) => { LL + e.insert(v2); - ... +LL + } +LL + } + | error: usage of `contains_key` followed by `insert` on a `HashMap` --> $DIR/entry_with_else.rs:46:5 @@ -115,7 +121,10 @@ LL + if true { Some(e.insert(v)) } else { Some(e.insert(v2)) } LL + } LL + std::collections::hash_map::Entry::Vacant(e) => { LL + e.insert(v); - ... +LL + None +LL + } +LL ~ }; + | error: usage of `contains_key` followed by `insert` on a `HashMap` --> $DIR/entry_with_else.rs:52:5 diff --git a/tests/ui/let_unit.stderr b/tests/ui/let_unit.stderr index 13ec11a6d33e..45bf67acdb73 100644 --- a/tests/ui/let_unit.stderr +++ b/tests/ui/let_unit.stderr @@ -32,7 +32,8 @@ LL + .map(|i| i * 2) LL + .filter(|i| i % 2 == 0) LL + .map(|_| ()) LL + .next() - ... +LL + .unwrap(); + | error: this let-binding has unit value --> $DIR/let_unit.rs:80:5 diff --git a/tests/ui/manual_async_fn.stderr b/tests/ui/manual_async_fn.stderr index 7435f46074c8..0a903ed6fd43 100644 --- a/tests/ui/manual_async_fn.stderr +++ b/tests/ui/manual_async_fn.stderr @@ -122,7 +122,14 @@ LL + let a = 42; LL + let b = 21; LL + if a < b { LL + let c = 21; - ... +LL + let d = 42; +LL + if c < d { +LL + let _ = 42; +LL + } +LL + } +LL + 42 +LL + } + | error: this function can be simplified using the `async fn` syntax --> $DIR/manual_async_fn.rs:92:1 diff --git a/tests/ui/needless_for_each_unfixable.stderr b/tests/ui/needless_for_each_unfixable.stderr index f607e0a430e2..7893ff31a6fd 100644 --- a/tests/ui/needless_for_each_unfixable.stderr +++ b/tests/ui/needless_for_each_unfixable.stderr @@ -19,7 +19,8 @@ LL + return; LL + } else { LL + println!("{}", v); LL + } - ... +LL + } + | help: ...and replace `return` with `continue` | LL | continue; diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 19572dfe8b07..212a69ab94e6 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -117,7 +117,8 @@ LL + Self::new() LL + } LL + } LL + - ... +LL ~ impl Foo { + | error: aborting due to 7 previous errors diff --git a/tests/ui/ptr_arg.stderr b/tests/ui/ptr_arg.stderr index a9613daadde1..7ec4a566ff34 100644 --- a/tests/ui/ptr_arg.stderr +++ b/tests/ui/ptr_arg.stderr @@ -56,7 +56,8 @@ LL | let f = e.clone(); // OK LL | let g = x; LL ~ let h = g.to_owned(); LL | let i = (e).clone(); - ... +LL ~ x.to_owned() + | error: writing `&String` instead of `&str` involves a new object where a slice will do --> $DIR/ptr_arg.rs:57:18 diff --git a/tests/ui/significant_drop_in_scrutinee.stderr b/tests/ui/significant_drop_in_scrutinee.stderr index 303f3c1df033..5ce952044163 100644 --- a/tests/ui/significant_drop_in_scrutinee.stderr +++ b/tests/ui/significant_drop_in_scrutinee.stderr @@ -188,7 +188,9 @@ LL + _ => mutex2.lock().unwrap(), LL + } LL + .s LL + .len() - ... +LL + > 1; +LL ~ match value + | error: temporary with significant drop in match scrutinee --> $DIR/significant_drop_in_scrutinee.rs:397:11 @@ -211,7 +213,10 @@ LL + } else { LL + mutex2.lock().unwrap() LL + } LL + .s - ... +LL + .len() +LL + > 1; +LL ~ match value + | error: temporary with significant drop in match scrutinee --> $DIR/significant_drop_in_scrutinee.rs:451:11 diff --git a/tests/ui/unit_arg.stderr b/tests/ui/unit_arg.stderr index 394dee29dc96..11cfe66a30e8 100644 --- a/tests/ui/unit_arg.stderr +++ b/tests/ui/unit_arg.stderr @@ -137,7 +137,13 @@ LL + foo(1); LL + }; LL + { LL + foo(2); - ... +LL + foo(3); +LL + }; +LL + taking_multiple_units( +LL + (), +LL + (), +LL ~ ); + | error: passing a unit value to a function --> $DIR/unit_arg.rs:85:13 diff --git a/tests/ui/unnecessary_wraps.stderr b/tests/ui/unnecessary_wraps.stderr index 8e31db395024..a6a0b22cf689 100644 --- a/tests/ui/unnecessary_wraps.stderr +++ b/tests/ui/unnecessary_wraps.stderr @@ -23,7 +23,8 @@ LL | if a { LL | Some(-1); LL ~ 2 LL | } else { - ... +LL ~ return 1337; + | error: this function's return value is unnecessarily wrapped by `Option` --> $DIR/unnecessary_wraps.rs:21:1 @@ -122,7 +123,8 @@ LL | if a { LL | Some(()); LL ~ LL | } else { - ... +LL ~ return ; + | error: this function's return value is unnecessary --> $DIR/unnecessary_wraps.rs:117:1 From 8eeea1bf60478309220492ca763aabcfe83931b3 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 16 Jun 2022 19:39:39 +0400 Subject: [PATCH 0529/1222] Move/rename `lazy::Sync{OnceCell,Lazy}` to `sync::{Once,Lazy}Lock` --- clippy_dev/src/bless.rs | 6 +++--- clippy_utils/src/lib.rs | 4 ++-- src/driver.rs | 6 +++--- tests/compile-test.rs | 4 ++-- tests/test_utils/mod.rs | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/clippy_dev/src/bless.rs b/clippy_dev/src/bless.rs index 8e5c739afe05..f5c51b9474fc 100644 --- a/clippy_dev/src/bless.rs +++ b/clippy_dev/src/bless.rs @@ -4,12 +4,12 @@ use crate::cargo_clippy_path; use std::ffi::OsStr; use std::fs; -use std::lazy::SyncLazy; use std::path::{Path, PathBuf}; +use std::sync::LazyLock; use walkdir::{DirEntry, WalkDir}; -static CLIPPY_BUILD_TIME: SyncLazy> = - SyncLazy::new(|| cargo_clippy_path().metadata().ok()?.modified().ok()); +static CLIPPY_BUILD_TIME: LazyLock> = + LazyLock::new(|| cargo_clippy_path().metadata().ok()?.modified().ok()); /// # Panics /// diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 0cf23ca626c7..052d9756c515 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -62,7 +62,7 @@ pub use self::hir_utils::{both, count_eq, eq_expr_value, over, SpanlessEq, Spanl use std::collections::hash_map::Entry; use std::hash::BuildHasherDefault; -use std::lazy::SyncOnceCell; +use std::sync::OnceLock; use std::sync::{Mutex, MutexGuard}; use if_chain::if_chain; @@ -2078,7 +2078,7 @@ pub fn is_hir_ty_cfg_dependant(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool { false } -static TEST_ITEM_NAMES_CACHE: SyncOnceCell>>> = SyncOnceCell::new(); +static TEST_ITEM_NAMES_CACHE: OnceLock>>> = OnceLock::new(); fn with_test_item_names<'tcx>(tcx: TyCtxt<'tcx>, module: LocalDefId, f: impl Fn(&[Symbol]) -> bool) -> bool { let cache = TEST_ITEM_NAMES_CACHE.get_or_init(|| Mutex::new(FxHashMap::default())); diff --git a/src/driver.rs b/src/driver.rs index 7de40fe63ac2..67467f89b475 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -21,11 +21,11 @@ use rustc_tools_util::VersionInfo; use std::borrow::Cow; use std::env; -use std::lazy::SyncLazy; use std::ops::Deref; use std::panic; use std::path::{Path, PathBuf}; use std::process::{exit, Command}; +use std::sync::LazyLock; /// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If /// true, then return it. The parameter is assumed to be either `--arg=value` or `--arg value`. @@ -152,7 +152,7 @@ You can use tool lints to allow or deny lints from your code, eg.: const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust-clippy/issues/new"; -static ICE_HOOK: SyncLazy) + Sync + Send + 'static>> = SyncLazy::new(|| { +static ICE_HOOK: LazyLock) + Sync + Send + 'static>> = LazyLock::new(|| { let hook = panic::take_hook(); panic::set_hook(Box::new(|info| report_clippy_ice(info, BUG_REPORT_URL))); hook @@ -219,7 +219,7 @@ fn toolchain_path(home: Option, toolchain: Option) -> Option = env::args().collect(); diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 04c2eeff08b6..061cda7e01e5 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -12,8 +12,8 @@ use std::env::{self, remove_var, set_var, var_os}; use std::ffi::{OsStr, OsString}; use std::fs; use std::io; -use std::lazy::SyncLazy; use std::path::{Path, PathBuf}; +use std::sync::LazyLock; use test_utils::IS_RUSTC_TEST_SUITE; mod test_utils; @@ -69,7 +69,7 @@ extern crate tokio; /// dependencies must be added to Cargo.toml at the project root. Test /// dependencies that are not *directly* used by this test module require an /// `extern crate` declaration. -static EXTERN_FLAGS: SyncLazy = SyncLazy::new(|| { +static EXTERN_FLAGS: LazyLock = LazyLock::new(|| { let current_exe_depinfo = { let mut path = env::current_exe().unwrap(); path.set_extension("d"); diff --git a/tests/test_utils/mod.rs b/tests/test_utils/mod.rs index 8a4de3f6def9..ea8c54e08b33 100644 --- a/tests/test_utils/mod.rs +++ b/tests/test_utils/mod.rs @@ -1,9 +1,9 @@ #![allow(dead_code)] // see https://github.com/rust-lang/rust/issues/46379 -use std::lazy::SyncLazy; use std::path::PathBuf; +use std::sync::LazyLock; -pub static CARGO_CLIPPY_PATH: SyncLazy = SyncLazy::new(|| { +pub static CARGO_CLIPPY_PATH: LazyLock = LazyLock::new(|| { let mut path = std::env::current_exe().unwrap(); assert!(path.pop()); // deps path.set_file_name("cargo-clippy"); From b528e22309f29d2a0256c50f64311b5a158563e3 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Fri, 17 Jun 2022 18:48:09 +0900 Subject: [PATCH 0530/1222] remove the rest of unnecessary `to_string` --- clippy_utils/src/sugg.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 4d21ba8bd1d1..aa119539b1b3 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -771,7 +771,7 @@ impl DiagnosticExt for rustc_errors::Diagnostic { } } - self.span_suggestion(remove_span, msg, String::new(), applicability); + self.span_suggestion(remove_span, msg, "", applicability); } } From 7f0458b92204e632e5b0e28f3435511d135a3a73 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sun, 19 Jun 2022 23:21:14 +0400 Subject: [PATCH 0531/1222] remove `span_lint_and_sugg_for_edges` from clippy utils --- clippy_lints/src/methods/map_flatten.rs | 11 +-- .../internal_lints/metadata_collector.rs | 1 - clippy_utils/src/diagnostics.rs | 91 +------------------ tests/ui/map_flatten.stderr | 25 ++--- tests/ui/map_flatten_fixable.fixed | 2 - tests/ui/map_flatten_fixable.stderr | 54 ++--------- 6 files changed, 23 insertions(+), 161 deletions(-) diff --git a/clippy_lints/src/methods/map_flatten.rs b/clippy_lints/src/methods/map_flatten.rs index f447940ea3b5..8ae84dbb3dcf 100644 --- a/clippy_lints/src/methods/map_flatten.rs +++ b/clippy_lints/src/methods/map_flatten.rs @@ -1,4 +1,4 @@ -use clippy_utils::diagnostics::span_lint_and_sugg_for_edges; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::is_trait_method; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; @@ -14,17 +14,14 @@ use super::MAP_FLATTEN; pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, map_arg: &Expr<'_>, map_span: Span) { if let Some((caller_ty_name, method_to_use)) = try_get_caller_ty_name_and_method_name(cx, expr, recv, map_arg) { let mut applicability = Applicability::MachineApplicable; - let help_msgs = [ - &format!("try replacing `map` with `{}`", method_to_use), - "and remove the `.flatten()`", - ]; + let closure_snippet = snippet_with_applicability(cx, map_arg.span, "..", &mut applicability); - span_lint_and_sugg_for_edges( + span_lint_and_sugg( cx, MAP_FLATTEN, expr.span.with_lo(map_span.lo()), &format!("called `map(..).flatten()` on `{}`", caller_ty_name), - &help_msgs, + &format!("try replacing `map` with `{}` and remove the `.flatten()`", method_to_use), format!("{}({})", method_to_use, closure_snippet), applicability, ); diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index 99e9e3275ab5..2564099f4dbc 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -112,7 +112,6 @@ const LINT_EMISSION_FUNCTIONS: [&[&str]; 8] = [ &["clippy_utils", "diagnostics", "span_lint_and_sugg"], &["clippy_utils", "diagnostics", "span_lint_and_then"], &["clippy_utils", "diagnostics", "span_lint_hir_and_then"], - &["clippy_utils", "diagnostics", "span_lint_and_sugg_for_edges"], ]; const SUGGESTION_DIAGNOSTIC_BUILDER_METHODS: [(&str, bool); 9] = [ ("span_suggestion", false), diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs index 39595f589c70..7f55db3b31f7 100644 --- a/clippy_utils/src/diagnostics.rs +++ b/clippy_utils/src/diagnostics.rs @@ -8,7 +8,7 @@ //! Thank you! //! ~The `INTERNAL_METADATA_COLLECTOR` lint -use rustc_errors::{emitter::MAX_SUGGESTION_HIGHLIGHT_LINES, Applicability, Diagnostic, MultiSpan}; +use rustc_errors::{Applicability, Diagnostic, MultiSpan}; use rustc_hir::HirId; use rustc_lint::{LateContext, Lint, LintContext}; use rustc_span::source_map::Span; @@ -219,95 +219,6 @@ pub fn span_lint_and_sugg<'a, T: LintContext>( }); } -/// Like [`span_lint_and_sugg`] with a focus on the edges. The output will either -/// emit single span or multispan suggestion depending on the number of its lines. -/// -/// If the given suggestion string has more lines than the maximum display length defined by -/// [`MAX_SUGGESTION_HIGHLIGHT_LINES`][`rustc_errors::emitter::MAX_SUGGESTION_HIGHLIGHT_LINES`], -/// this function will split the suggestion and span to showcase the change for the top and -/// bottom edge of the code. For normal suggestions, in one display window, the help message -/// will be combined with a colon. -/// -/// Multipart suggestions like the one being created here currently cannot be -/// applied by rustfix (See [rustfix#141](https://github.com/rust-lang/rustfix/issues/141)). -/// Testing rustfix with this lint emission function might require a file with -/// suggestions that can be fixed and those that can't. See -/// [clippy#8520](https://github.com/rust-lang/rust-clippy/pull/8520/files) for -/// an example and of this. -/// -/// # Example for a long suggestion -/// -/// ```text -/// error: called `map(..).flatten()` on `Option` -/// --> $DIR/map_flatten.rs:8:10 -/// | -/// LL | .map(|x| { -/// | __________^ -/// LL | | if x <= 5 { -/// LL | | Some(x) -/// LL | | } else { -/// ... | -/// LL | | }) -/// LL | | .flatten(); -/// | |__________________^ -/// | -/// = note: `-D clippy::map-flatten` implied by `-D warnings` -/// help: try replacing `map` with `and_then` -/// | -/// LL ~ .and_then(|x| { -/// LL + if x <= 5 { -/// LL + Some(x) -/// | -/// help: and remove the `.flatten()` -/// | -/// LL + None -/// LL + } -/// LL ~ }); -/// | -/// ``` -pub fn span_lint_and_sugg_for_edges( - cx: &LateContext<'_>, - lint: &'static Lint, - sp: Span, - msg: &str, - helps: &[&str; 2], - sugg: String, - applicability: Applicability, -) { - span_lint_and_then(cx, lint, sp, msg, |diag| { - let sugg_lines_count = sugg.lines().count(); - if sugg_lines_count > MAX_SUGGESTION_HIGHLIGHT_LINES { - let sm = cx.sess().source_map(); - if let (Ok(line_upper), Ok(line_bottom)) = - (sm.lookup_line(sp.lo()), sm.lookup_line(sp.hi())) - { - let split_idx = MAX_SUGGESTION_HIGHLIGHT_LINES / 2; - let span_upper = sm.span_until_char( - sp.with_hi(line_upper.sf.lines(|lines| lines[line_upper.line + split_idx])), - '\n', - ); - let span_bottom = sp.with_lo(line_bottom.sf.lines(|lines| lines[line_bottom.line - split_idx])); - - let sugg_lines_vec = sugg.lines().collect::>(); - let sugg_upper = sugg_lines_vec[..split_idx].join("\n"); - let sugg_bottom = sugg_lines_vec[sugg_lines_count - split_idx..].join("\n"); - - diag.span_suggestion(span_upper, helps[0], sugg_upper, applicability); - diag.span_suggestion(span_bottom, helps[1], sugg_bottom, applicability); - - return; - } - } - diag.span_suggestion_with_style( - sp, - &helps.join(", "), - sugg, - applicability, - rustc_errors::SuggestionStyle::ShowAlways, - ); - }); -} - /// Create a suggestion made from several `span → replacement`. /// /// Note: in the JSON format (used by `compiletest_rs`), the help message will diff --git a/tests/ui/map_flatten.stderr b/tests/ui/map_flatten.stderr index c9c60df838f6..4b2630d68584 100644 --- a/tests/ui/map_flatten.stderr +++ b/tests/ui/map_flatten.stderr @@ -12,14 +12,12 @@ LL | | .flatten(); | |__________________^ | = note: `-D clippy::map-flatten` implied by `-D warnings` -help: try replacing `map` with `and_then` +help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|x| { LL + if x <= 5 { LL + Some(x) - | -help: and remove the `.flatten()` - | +LL + } else { LL + None LL + } LL ~ }); @@ -38,14 +36,12 @@ LL | | }) LL | | .flatten(); | |__________________^ | -help: try replacing `map` with `and_then` +help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|x| { LL + if x == 1 { LL + Ok(x) - | -help: and remove the `.flatten()` - | +LL + } else { LL + Err(0) LL + } LL ~ }); @@ -64,14 +60,13 @@ LL | | }) LL | | .flatten(); | |__________________^ | -help: try replacing `map` with `and_then` +help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|res| { LL + if res > 0 { LL + do_something(); - | -help: and remove the `.flatten()` - | +LL + Ok(res) +LL + } else { LL + Err(0) LL + } LL ~ }); @@ -90,14 +85,12 @@ LL | | }) LL | | .flatten() | |__________________^ | -help: try replacing `map` with `filter_map` +help: try replacing `map` with `filter_map` and remove the `.flatten()` | LL ~ .filter_map(|some_value| { LL + if some_value > 3 { LL + Some(some_value) - | -help: and remove the `.flatten()` - | +LL + } else { LL + None LL + } LL + }) diff --git a/tests/ui/map_flatten_fixable.fixed b/tests/ui/map_flatten_fixable.fixed index 928e5bd509c3..e9b41354c58f 100644 --- a/tests/ui/map_flatten_fixable.fixed +++ b/tests/ui/map_flatten_fixable.fixed @@ -59,8 +59,6 @@ fn issue8878() { .and_then(|_| { // we need some newlines // so that the span is big enough -// we need some newlines -// so that the span is big enough // for a splitted output of the diagnostic Some("") // whitespace beforehand is important as well diff --git a/tests/ui/map_flatten_fixable.stderr b/tests/ui/map_flatten_fixable.stderr index 828e24acaad6..f3b82ad08d0f 100644 --- a/tests/ui/map_flatten_fixable.stderr +++ b/tests/ui/map_flatten_fixable.stderr @@ -2,79 +2,45 @@ error: called `map(..).flatten()` on `Iterator` --> $DIR/map_flatten_fixable.rs:18:47 | LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(option_id)` | = note: `-D clippy::map-flatten` implied by `-D warnings` -help: try replacing `map` with `filter_map`, and remove the `.flatten()` - | -LL | let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id).collect(); - | ~~~~~~~~~~~~~~~~~~~~~ error: called `map(..).flatten()` on `Iterator` --> $DIR/map_flatten_fixable.rs:19:47 | LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_ref).flatten().collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: try replacing `map` with `filter_map`, and remove the `.flatten()` - | -LL | let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id_ref).collect(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(option_id_ref)` error: called `map(..).flatten()` on `Iterator` --> $DIR/map_flatten_fixable.rs:20:47 | LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_closure).flatten().collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: try replacing `map` with `filter_map`, and remove the `.flatten()` - | -LL | let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id_closure).collect(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(option_id_closure)` error: called `map(..).flatten()` on `Iterator` --> $DIR/map_flatten_fixable.rs:21:47 | LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| x.checked_add(1)).flatten().collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: try replacing `map` with `filter_map`, and remove the `.flatten()` - | -LL | let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(|x| x.checked_add(1)).collect(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(|x| x.checked_add(1))` error: called `map(..).flatten()` on `Iterator` --> $DIR/map_flatten_fixable.rs:24:47 | LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^ - | -help: try replacing `map` with `flat_map`, and remove the `.flatten()` - | -LL | let _: Vec<_> = vec![5_i8; 6].into_iter().flat_map(|x| 0..x).collect(); - | ~~~~~~~~~~~~~~~~~~ + | ^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `flat_map` and remove the `.flatten()`: `flat_map(|x| 0..x)` error: called `map(..).flatten()` on `Option` --> $DIR/map_flatten_fixable.rs:27:40 | LL | let _: Option<_> = (Some(Some(1))).map(|x| x).flatten(); - | ^^^^^^^^^^^^^^^^^^^^ - | -help: try replacing `map` with `and_then`, and remove the `.flatten()` - | -LL | let _: Option<_> = (Some(Some(1))).and_then(|x| x); - | ~~~~~~~~~~~~~~~ + | ^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|x| x)` error: called `map(..).flatten()` on `Result` --> $DIR/map_flatten_fixable.rs:30:42 | LL | let _: Result<_, &str> = (Ok(Ok(1))).map(|x| x).flatten(); - | ^^^^^^^^^^^^^^^^^^^^ - | -help: try replacing `map` with `and_then`, and remove the `.flatten()` - | -LL | let _: Result<_, &str> = (Ok(Ok(1))).and_then(|x| x); - | ~~~~~~~~~~~~~~~ + | ^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|x| x)` error: called `map(..).flatten()` on `Option` --> $DIR/map_flatten_fixable.rs:59:10 @@ -89,14 +55,12 @@ LL | | }) LL | | .flatten(); | |__________________^ | -help: try replacing `map` with `and_then` +help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|_| { LL + // we need some newlines LL + // so that the span is big enough - | -help: and remove the `.flatten()` - | +LL + // for a splitted output of the diagnostic LL + Some("") LL + // whitespace beforehand is important as well LL ~ }); From 2866a57613222c8b98a5b8ce43405658e8a864a2 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 20 Jun 2022 00:25:07 +0400 Subject: [PATCH 0532/1222] remove last use of MAX_SUGGESTION_HIGHLIGHT_LINES --- clippy_lints/src/methods/or_fun_call.rs | 13 ++----- tests/ui/or_fun_call.fixed | 6 ++-- tests/ui/or_fun_call.stderr | 46 +++++++++++++++++++++---- 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index 448dc4e6147f..3d1208824fa3 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -4,7 +4,6 @@ use clippy_utils::source::{snippet, snippet_with_applicability, snippet_with_mac use clippy_utils::ty::{implements_trait, match_type}; use clippy_utils::{contains_return, is_trait_item, last_path_segment, paths}; use if_chain::if_chain; -use rustc_errors::emitter::MAX_SUGGESTION_HIGHLIGHT_LINES; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; @@ -33,7 +32,6 @@ pub(super) fn check<'tcx>( arg: &hir::Expr<'_>, or_has_args: bool, span: Span, - method_span: Span, ) -> bool { let is_default_default = || is_trait_item(cx, fun, sym::Default); @@ -56,19 +54,14 @@ pub(super) fn check<'tcx>( then { let mut applicability = Applicability::MachineApplicable; let hint = "unwrap_or_default()"; - let mut sugg_span = span; + let sugg_span = span; - let mut sugg: String = format!( + let sugg: String = format!( "{}.{}", snippet_with_applicability(cx, self_expr.span, "..", &mut applicability), hint ); - if sugg.lines().count() > MAX_SUGGESTION_HIGHLIGHT_LINES { - sugg_span = method_span.with_hi(span.hi()); - sugg = hint.to_string(); - } - span_lint_and_sugg( cx, OR_FUN_CALL, @@ -178,7 +171,7 @@ pub(super) fn check<'tcx>( match inner_arg.kind { hir::ExprKind::Call(fun, or_args) => { let or_has_args = !or_args.is_empty(); - if !check_unwrap_or_default(cx, name, fun, self_arg, arg, or_has_args, expr.span, method_span) { + if !check_unwrap_or_default(cx, name, fun, self_arg, arg, or_has_args, expr.span) { let fun_span = if or_has_args { None } else { Some(fun.span) }; check_general_case(cx, name, method_span, self_arg, arg, expr.span, fun_span); } diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed index 3208048e0d53..123aed40251e 100644 --- a/tests/ui/or_fun_call.fixed +++ b/tests/ui/or_fun_call.fixed @@ -185,8 +185,7 @@ mod issue8239 { .reduce(|mut acc, f| { acc.push_str(&f); acc - }) - .unwrap_or_default(); + }).unwrap_or_default(); } fn more_to_max_suggestion_highest_lines_1() { @@ -198,8 +197,7 @@ mod issue8239 { let _ = ""; acc.push_str(&f); acc - }) - .unwrap_or_default(); + }).unwrap_or_default(); } fn equal_to_max_suggestion_highest_lines() { diff --git a/tests/ui/or_fun_call.stderr b/tests/ui/or_fun_call.stderr index 549b00ae3c45..dfe15654bc32 100644 --- a/tests/ui/or_fun_call.stderr +++ b/tests/ui/or_fun_call.stderr @@ -109,16 +109,50 @@ LL | None.unwrap_or( unsafe { ptr_to_ref(s) } ); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })` error: use of `unwrap_or` followed by a call to `new` - --> $DIR/or_fun_call.rs:189:14 + --> $DIR/or_fun_call.rs:182:9 + | +LL | / frames +LL | | .iter() +LL | | .map(|f: &String| f.to_lowercase()) +LL | | .reduce(|mut acc, f| { +... | +LL | | }) +LL | | .unwrap_or(String::new()); + | |_____________________________________^ + | +help: try this + | +LL ~ frames +LL + .iter() +LL + .map(|f: &String| f.to_lowercase()) +LL + .reduce(|mut acc, f| { +LL + acc.push_str(&f); +LL + acc +LL ~ }).unwrap_or_default(); | -LL | .unwrap_or(String::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()` error: use of `unwrap_or` followed by a call to `new` - --> $DIR/or_fun_call.rs:202:14 + --> $DIR/or_fun_call.rs:195:9 + | +LL | / iter.map(|f: &String| f.to_lowercase()) +LL | | .reduce(|mut acc, f| { +LL | | let _ = ""; +LL | | let _ = ""; +... | +LL | | }) +LL | | .unwrap_or(String::new()); + | |_____________________________________^ + | +help: try this + | +LL ~ iter.map(|f: &String| f.to_lowercase()) +LL + .reduce(|mut acc, f| { +LL + let _ = ""; +LL + let _ = ""; +LL + acc.push_str(&f); +LL + acc +LL ~ }).unwrap_or_default(); | -LL | .unwrap_or(String::new()); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()` error: use of `unwrap_or` followed by a call to `new` --> $DIR/or_fun_call.rs:208:9 From 8485a92a832eeaf291a143c53f4a43c7da833d61 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Tue, 28 Jun 2022 13:15:30 -0500 Subject: [PATCH 0533/1222] Factor out hir::Node::Binding --- clippy_lints/src/escape.rs | 16 +++++----------- clippy_lints/src/explicit_write.rs | 2 +- clippy_lints/src/loops/mut_range_bound.rs | 2 +- clippy_lints/src/loops/same_item_push.rs | 2 +- clippy_lints/src/manual_rem_euclid.rs | 3 +-- clippy_lints/src/methods/iter_skip_next.rs | 2 +- clippy_utils/src/lib.rs | 2 +- 7 files changed, 11 insertions(+), 18 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 7a65b849a664..1ac7bfba06ba 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_hir; use clippy_utils::ty::contains_ty; use rustc_hir::intravisit; -use rustc_hir::{self, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node}; +use rustc_hir::{self, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node, Pat, PatKind}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::FakeReadCause; @@ -132,7 +132,10 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { // TODO: Replace with Map::is_argument(..) when it's fixed fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool { match map.find(id) { - Some(Node::Binding(_)) => (), + Some(Node::Pat(Pat { + kind: PatKind::Binding(..), + .. + })) => (), _ => return false, } @@ -144,15 +147,6 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { if cmt.place.projections.is_empty() { if let PlaceBase::Local(lid) = cmt.place.base { self.set.remove(&lid); - let map = &self.cx.tcx.hir(); - if let Some(Node::Binding(_)) = map.find(cmt.hir_id) { - if self.set.contains(&lid) { - // let y = x where x is known - // remove x, insert y - self.set.insert(cmt.hir_id); - self.set.remove(&lid); - } - } } } } diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 12d636cf4101..5bf4313b41a4 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -125,7 +125,7 @@ fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>) // Find id of the local that expr_end_of_block resolves to if let ExprKind::Path(QPath::Resolved(None, expr_path)) = expr_end_of_block.kind; if let Res::Local(expr_res) = expr_path.res; - if let Some(Node::Binding(res_pat)) = cx.tcx.hir().find(expr_res); + if let Some(Node::Pat(res_pat)) = cx.tcx.hir().find(expr_res); // Find id of the local we found in the block if let PatKind::Binding(BindingAnnotation::Unannotated, local_hir_id, _ident, None) = local.pat.kind; diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index d20df8304558..aedf3810b23e 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -43,7 +43,7 @@ fn mut_warn_with_span(cx: &LateContext<'_>, span: Option) { fn check_for_mutability(cx: &LateContext<'_>, bound: &Expr<'_>) -> Option { if_chain! { if let Some(hir_id) = path_to_local(bound); - if let Node::Binding(pat) = cx.tcx.hir().get(hir_id); + if let Node::Pat(pat) = cx.tcx.hir().get(hir_id); if let PatKind::Binding(BindingAnnotation::Mutable, ..) = pat.kind; then { return Some(hir_id); diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index e048d744fc3b..1439f1f4c75d 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -63,7 +63,7 @@ pub(super) fn check<'tcx>( Res::Local(hir_id) => { let node = cx.tcx.hir().get(hir_id); if_chain! { - if let Node::Binding(pat) = node; + if let Node::Pat(pat) = node; if let PatKind::Binding(bind_ann, ..) = pat.kind; if !matches!(bind_ann, BindingAnnotation::RefMut | BindingAnnotation::Mutable); let parent_node = cx.tcx.hir().get_parent_node(hir_id); diff --git a/clippy_lints/src/manual_rem_euclid.rs b/clippy_lints/src/manual_rem_euclid.rs index b5698965fc3d..2ce9d0e77c1f 100644 --- a/clippy_lints/src/manual_rem_euclid.rs +++ b/clippy_lints/src/manual_rem_euclid.rs @@ -71,8 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid { && let Some(const3) = check_for_unsigned_int_constant(cx, right) // Also ensures the const is nonzero since zero can't be a divisor && const1 == const2 && const2 == const3 - && let Some(hir_id) = path_to_local(expr3) - && let Some(Node::Binding(_)) = cx.tcx.hir().find(hir_id) { + && let Some(hir_id) = path_to_local(expr3) { // Apply only to params or locals with annotated types match cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { Some(Node::Param(..)) => (), diff --git a/clippy_lints/src/methods/iter_skip_next.rs b/clippy_lints/src/methods/iter_skip_next.rs index f5410c7fd7fc..43e9451f7d37 100644 --- a/clippy_lints/src/methods/iter_skip_next.rs +++ b/clippy_lints/src/methods/iter_skip_next.rs @@ -22,7 +22,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr |diag| { if_chain! { if let Some(id) = path_to_local(recv); - if let Node::Binding(pat) = cx.tcx.hir().get(id); + if let Node::Pat(pat) = cx.tcx.hir().get(id); if let PatKind::Binding(ann, _, _, _) = pat.kind; if ann != BindingAnnotation::Mutable; then { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 9fa28e137f97..5cfd02232dec 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -183,7 +183,7 @@ pub fn expr_or_init<'a, 'b, 'tcx: 'b>(cx: &LateContext<'tcx>, mut expr: &'a Expr pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<'tcx>> { let hir = cx.tcx.hir(); if_chain! { - if let Some(Node::Binding(pat)) = hir.find(hir_id); + if let Some(Node::Pat(pat)) = hir.find(hir_id); if matches!(pat.kind, PatKind::Binding(BindingAnnotation::Unannotated, ..)); let parent = hir.get_parent_node(hir_id); if let Some(Node::Local(local)) = hir.find(parent); From f1e84fe7c3d3f32b822c1b87b9758d0fe83f9fc1 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 13 Feb 2022 16:27:59 +0100 Subject: [PATCH 0534/1222] Shorten def_span for more items. --- clippy_lints/src/operators/numeric_arithmetic.rs | 9 +++++---- tests/ui/crashes/ice-6252.stderr | 2 +- tests/ui/derive_hash_xor_eq.stderr | 16 ++++------------ tests/ui/derive_ord_xor_partial_ord.stderr | 16 ++++------------ tests/ui/needless_pass_by_value.stderr | 8 ++++---- 5 files changed, 18 insertions(+), 33 deletions(-) diff --git a/clippy_lints/src/operators/numeric_arithmetic.rs b/clippy_lints/src/operators/numeric_arithmetic.rs index 82f454d02f71..b6097710dc68 100644 --- a/clippy_lints/src/operators/numeric_arithmetic.rs +++ b/clippy_lints/src/operators/numeric_arithmetic.rs @@ -96,11 +96,12 @@ impl Context { } pub fn enter_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { - let body_owner = cx.tcx.hir().body_owner_def_id(body.id()); + let body_owner = cx.tcx.hir().body_owner(body.id()); + let body_owner_def_id = cx.tcx.hir().local_def_id(body_owner); - match cx.tcx.hir().body_owner_kind(body_owner) { + match cx.tcx.hir().body_owner_kind(body_owner_def_id) { hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const => { - let body_span = cx.tcx.def_span(body_owner); + let body_span = cx.tcx.hir().span_with_body(body_owner); if let Some(span) = self.const_span { if span.contains(body_span) { @@ -115,7 +116,7 @@ impl Context { pub fn body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { let body_owner = cx.tcx.hir().body_owner(body.id()); - let body_span = cx.tcx.hir().span(body_owner); + let body_span = cx.tcx.hir().span_with_body(body_owner); if let Some(span) = self.const_span { if span.contains(body_span) { diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index d930d486fde6..a6a767483ed4 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -25,7 +25,7 @@ error[E0046]: not all trait items implemented, missing: `VAL` --> $DIR/ice-6252.rs:10:1 | LL | const VAL: T; - | ------------- `VAL` from trait + | ------------ `VAL` from trait ... LL | impl TypeVal for Multiply where N: TypeVal {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation diff --git a/tests/ui/derive_hash_xor_eq.stderr b/tests/ui/derive_hash_xor_eq.stderr index e5184bd1407c..2a4abb0c5193 100644 --- a/tests/ui/derive_hash_xor_eq.stderr +++ b/tests/ui/derive_hash_xor_eq.stderr @@ -8,12 +8,8 @@ LL | #[derive(Hash)] note: `PartialEq` implemented here --> $DIR/derive_hash_xor_eq.rs:15:1 | -LL | / impl PartialEq for Bar { -LL | | fn eq(&self, _: &Bar) -> bool { -LL | | true -LL | | } -LL | | } - | |_^ +LL | impl PartialEq for Bar { + | ^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `Hash` but have implemented `PartialEq` explicitly @@ -25,12 +21,8 @@ LL | #[derive(Hash)] note: `PartialEq` implemented here --> $DIR/derive_hash_xor_eq.rs:24:1 | -LL | / impl PartialEq for Baz { -LL | | fn eq(&self, _: &Baz) -> bool { -LL | | true -LL | | } -LL | | } - | |_^ +LL | impl PartialEq for Baz { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are implementing `Hash` explicitly but have derived `PartialEq` diff --git a/tests/ui/derive_ord_xor_partial_ord.stderr b/tests/ui/derive_ord_xor_partial_ord.stderr index 32896c99dad0..baf8341aba90 100644 --- a/tests/ui/derive_ord_xor_partial_ord.stderr +++ b/tests/ui/derive_ord_xor_partial_ord.stderr @@ -8,12 +8,8 @@ LL | #[derive(Ord, PartialEq, Eq)] note: `PartialOrd` implemented here --> $DIR/derive_ord_xor_partial_ord.rs:24:1 | -LL | / impl PartialOrd for DeriveOrd { -LL | | fn partial_cmp(&self, other: &Self) -> Option { -LL | | Some(other.cmp(self)) -LL | | } -LL | | } - | |_^ +LL | impl PartialOrd for DeriveOrd { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `Ord` but have implemented `PartialOrd` explicitly @@ -25,12 +21,8 @@ LL | #[derive(Ord, PartialEq, Eq)] note: `PartialOrd` implemented here --> $DIR/derive_ord_xor_partial_ord.rs:33:1 | -LL | / impl PartialOrd for DeriveOrdWithExplicitTypeVariable { -LL | | fn partial_cmp(&self, other: &Self) -> Option { -LL | | Some(other.cmp(self)) -LL | | } -LL | | } - | |_^ +LL | impl PartialOrd for DeriveOrdWithExplicitTypeVariable { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are implementing `Ord` explicitly but have derived `PartialOrd` diff --git a/tests/ui/needless_pass_by_value.stderr b/tests/ui/needless_pass_by_value.stderr index d960c86a9f0e..38f33c53f128 100644 --- a/tests/ui/needless_pass_by_value.stderr +++ b/tests/ui/needless_pass_by_value.stderr @@ -124,7 +124,7 @@ help: consider marking this type as `Copy` --> $DIR/needless_pass_by_value.rs:123:1 | LL | struct CopyWrapper(u32); - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body --> $DIR/needless_pass_by_value.rs:131:29 @@ -136,7 +136,7 @@ help: consider marking this type as `Copy` --> $DIR/needless_pass_by_value.rs:123:1 | LL | struct CopyWrapper(u32); - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body --> $DIR/needless_pass_by_value.rs:131:45 @@ -148,7 +148,7 @@ help: consider marking this type as `Copy` --> $DIR/needless_pass_by_value.rs:123:1 | LL | struct CopyWrapper(u32); - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body --> $DIR/needless_pass_by_value.rs:131:61 @@ -160,7 +160,7 @@ help: consider marking this type as `Copy` --> $DIR/needless_pass_by_value.rs:123:1 | LL | struct CopyWrapper(u32); - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body --> $DIR/needless_pass_by_value.rs:143:40 From 3bde313f62ec529a615fc67ad0dd8e19b6688290 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Sat, 2 Jul 2022 18:25:55 +0100 Subject: [PATCH 0535/1222] ast: Add span to `Extern` --- clippy_lints/src/excessive_bools.rs | 2 +- clippy_utils/src/ast_utils.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/excessive_bools.rs b/clippy_lints/src/excessive_bools.rs index f7a92bc07956..453471c8cdda 100644 --- a/clippy_lints/src/excessive_bools.rs +++ b/clippy_lints/src/excessive_bools.rs @@ -94,7 +94,7 @@ impl ExcessiveBools { fn check_fn_sig(&self, cx: &EarlyContext<'_>, fn_sig: &FnSig, span: Span) { match fn_sig.header.ext { - Extern::Implicit | Extern::Explicit(_) => return, + Extern::Implicit(_) | Extern::Explicit(_, _) => return, Extern::None => (), } diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 6487199172e0..177e754ee091 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -600,8 +600,8 @@ pub fn eq_ty(l: &Ty, r: &Ty) -> bool { pub fn eq_ext(l: &Extern, r: &Extern) -> bool { use Extern::*; match (l, r) { - (None, None) | (Implicit, Implicit) => true, - (Explicit(l), Explicit(r)) => eq_str_lit(l, r), + (None, None) | (Implicit(_), Implicit(_)) => true, + (Explicit(l,_), Explicit(r,_)) => eq_str_lit(l, r), _ => false, } } From 83abce595c5f387ef6baabea7008b8854c07ab1b Mon Sep 17 00:00:00 2001 From: Alan Egerton Date: Fri, 17 Jun 2022 13:10:07 +0100 Subject: [PATCH 0536/1222] Relax constrained generics to TypeVisitable --- clippy_utils/src/ty.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 6ca36eed4e65..a426fa1b0ffc 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -15,7 +15,7 @@ use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst}; use rustc_middle::ty::{ self, AdtDef, Binder, BoundRegion, DefIdTree, FnSig, IntTy, ParamEnv, Predicate, PredicateKind, ProjectionTy, - Region, RegionKind, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitor, UintTy, VariantDef, VariantDiscr, + Region, RegionKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy, VariantDef, VariantDiscr, }; use rustc_span::symbol::Ident; use rustc_span::{sym, Span, Symbol, DUMMY_SP}; @@ -765,7 +765,7 @@ pub fn for_each_top_level_late_bound_region( ControlFlow::Continue(()) } } - fn visit_binder>(&mut self, t: &Binder<'tcx, T>) -> ControlFlow { + fn visit_binder>(&mut self, t: &Binder<'tcx, T>) -> ControlFlow { self.index += 1; let res = t.super_visit_with(self); self.index -= 1; From da36e9ba122d93785eb8e5b802eb664da49d91a2 Mon Sep 17 00:00:00 2001 From: Alan Egerton Date: Fri, 17 Jun 2022 13:15:00 +0100 Subject: [PATCH 0537/1222] Update TypeVisitor paths --- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/eta_reduction.rs | 2 +- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/redundant_clone.rs | 2 +- clippy_lints/src/transmute/transmute_ptr_to_ref.rs | 2 +- clippy_lints/src/transmute/useless_transmute.rs | 2 +- clippy_lints/src/types/vec_box.rs | 2 +- clippy_lints/src/unit_types/let_unit_value.rs | 2 +- clippy_lints/src/zero_sized_map_values.rs | 2 +- clippy_utils/src/lib.rs | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 59dcc1ebf191..0f4a2f79ac5d 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -15,7 +15,7 @@ use rustc_hir::{ use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability}; -use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeckResults}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitable, TypeckResults}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{symbol::sym, Span, Symbol}; use rustc_trait_selection::infer::InferCtxtExt; diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index a5a763c37d1b..42fac550ec69 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -12,7 +12,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; use rustc_middle::ty::binding::BindingMode; use rustc_middle::ty::subst::Subst; -use rustc_middle::ty::{self, ClosureKind, Ty, TypeFoldable}; +use rustc_middle::ty::{self, ClosureKind, Ty, TypeVisitable}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 7e2531c7ca5f..4db103bbc130 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint; use clippy_utils::trait_ref_of_method; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::TypeFoldable; +use rustc_middle::ty::TypeVisitable; use rustc_middle::ty::{Adt, Array, Ref, Slice, Tuple, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 8b273aca7d02..0cbef1c95fe9 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -13,7 +13,7 @@ use rustc_hir::{HirIdMap, HirIdSet}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::FakeReadCause; -use rustc_middle::ty::{self, TypeFoldable}; +use rustc_middle::ty::{self, TypeVisitable}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::kw; use rustc_span::{sym, Span}; diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 3b11cbc37606..6d0b9a0f03fa 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -14,7 +14,7 @@ use rustc_middle::mir::{ visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor as _}, Mutability, }; -use rustc_middle::ty::{self, fold::TypeVisitor, Ty}; +use rustc_middle::ty::{self, visit::TypeVisitor, Ty}; use rustc_mir_dataflow::{Analysis, AnalysisDomain, CallReturnPlaces, GenKill, GenKillAnalysis, ResultsCursor}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::{BytePos, Span}; diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs index 3ed5d5c69508..5eb03275b8ec 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs @@ -5,7 +5,7 @@ use clippy_utils::{meets_msrv, msrvs, sugg}; use rustc_errors::Applicability; use rustc_hir::{self as hir, Expr, GenericArg, Mutability, Path, TyKind}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty, TypeFoldable}; +use rustc_middle::ty::{self, Ty, TypeVisitable}; use rustc_semver::RustcVersion; /// Checks for `transmute_ptr_to_ref` lint. diff --git a/clippy_lints/src/transmute/useless_transmute.rs b/clippy_lints/src/transmute/useless_transmute.rs index 8ea985a89843..8122cd716e01 100644 --- a/clippy_lints/src/transmute/useless_transmute.rs +++ b/clippy_lints/src/transmute/useless_transmute.rs @@ -4,7 +4,7 @@ use clippy_utils::sugg; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty, TypeFoldable}; +use rustc_middle::ty::{self, Ty, TypeVisitable}; /// Checks for `useless_transmute` lint. /// Returns `true` if it's triggered, otherwise returns `false`. diff --git a/clippy_lints/src/types/vec_box.rs b/clippy_lints/src/types/vec_box.rs index c632f822544a..b2f536ca7815 100644 --- a/clippy_lints/src/types/vec_box.rs +++ b/clippy_lints/src/types/vec_box.rs @@ -6,7 +6,7 @@ use rustc_errors::Applicability; use rustc_hir::{self as hir, def_id::DefId, GenericArg, QPath, TyKind}; use rustc_lint::LateContext; use rustc_middle::ty::layout::LayoutOf; -use rustc_middle::ty::TypeFoldable; +use rustc_middle::ty::TypeVisitable; use rustc_span::symbol::sym; use rustc_typeck::hir_ty_to_ty; diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index 27678c8ba3c4..cf509455aad0 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::{Expr, ExprKind, PatKind, Stmt, StmtKind}; use rustc_lint::{LateContext, LintContext}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, Ty, TypeFoldable, TypeSuperFoldable, TypeVisitor}; +use rustc_middle::ty::{self, Ty, TypeVisitable, TypeSuperVisitable, TypeVisitor}; use super::LET_UNIT_VALUE; diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 70b0560e6760..8dc43c0e2943 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -4,7 +4,7 @@ use if_chain::if_chain; use rustc_hir::{self as hir, HirId, ItemKind, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::layout::LayoutOf as _; -use rustc_middle::ty::{Adt, Ty, TypeFoldable}; +use rustc_middle::ty::{Adt, Ty, TypeVisitable}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; use rustc_typeck::hir_ty_to_ty; diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 5cfd02232dec..1b32f0aaeb8d 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -93,7 +93,7 @@ use rustc_middle::ty::fast_reject::SimplifiedTypeGen::{ ArraySimplifiedType, BoolSimplifiedType, CharSimplifiedType, FloatSimplifiedType, IntSimplifiedType, PtrSimplifiedType, SliceSimplifiedType, StrSimplifiedType, UintSimplifiedType, }; -use rustc_middle::ty::{layout::IntegerExt, BorrowKind, DefIdTree, Ty, TyCtxt, TypeAndMut, TypeFoldable, UpvarCapture}; +use rustc_middle::ty::{layout::IntegerExt, BorrowKind, DefIdTree, Ty, TyCtxt, TypeAndMut, TypeVisitable, UpvarCapture}; use rustc_middle::ty::{FloatTy, IntTy, UintTy}; use rustc_semver::RustcVersion; use rustc_session::Session; From a218978bc6c789116c6fbda31d5af0513a16c963 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Sun, 3 Jul 2022 17:35:24 +0200 Subject: [PATCH 0538/1222] Build the Clippy book as part of x.py doc --- book/src/README.md | 2 +- book/src/development/adding_lints.md | 33 ++++++++++--------- book/src/development/basics.md | 2 +- .../development/common_tools_writing_lints.md | 2 +- book/src/usage.md | 2 +- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/book/src/README.md b/book/src/README.md index d941f8b65e8e..6248d588a890 100644 --- a/book/src/README.md +++ b/book/src/README.md @@ -1,7 +1,7 @@ # Clippy [![Clippy Test](https://github.com/rust-lang/rust-clippy/workflows/Clippy%20Test/badge.svg?branch=auto&event=push)](https://github.com/rust-lang/rust-clippy/actions?query=workflow%3A%22Clippy+Test%22+event%3Apush+branch%3Aauto) -[![License: MIT OR Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](#license) +[![License: MIT OR Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](https://github.com/rust-lang/rust-clippy#license) A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. diff --git a/book/src/development/adding_lints.md b/book/src/development/adding_lints.md index 3da07fcb9686..d06297f2e079 100644 --- a/book/src/development/adding_lints.md +++ b/book/src/development/adding_lints.md @@ -13,7 +13,6 @@ because that's clearly a non-descriptive name. - [Testing](#testing) - [Cargo lints](#cargo-lints) - [Rustfix tests](#rustfix-tests) - - [Edition 2018 tests](#edition-2018-tests) - [Testing manually](#testing-manually) - [Lint declaration](#lint-declaration) - [Lint registration](#lint-registration) @@ -402,9 +401,8 @@ need to ensure that the MSRV configured for the project is >= the MSRV of the required Rust feature. If multiple features are required, just use the one with a lower MSRV. -First, add an MSRV alias for the required feature in -[`clippy_utils::msrvs`](/clippy_utils/src/msrvs.rs). This can be accessed later -as `msrvs::STR_STRIP_PREFIX`, for example. +First, add an MSRV alias for the required feature in [`clippy_utils::msrvs`]. +This can be accessed later as `msrvs::STR_STRIP_PREFIX`, for example. ```rust msrv_aliases! { @@ -468,6 +466,8 @@ define_Conf! { } ``` +[`clippy_utils::msrvs`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/msrvs/index.html + ## Author lint If you have trouble implementing your lint, there is also the internal `author` @@ -583,8 +583,7 @@ the workspace 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: -1. Adding a new configuration entry to - [clippy_lints::utils::conf](/clippy_lints/src/utils/conf.rs) like this: +1. Adding a new configuration entry to [`clippy_lints::utils::conf`] like this: ```rust /// Lint: LINT_NAME. @@ -635,9 +634,9 @@ for some users. Adding a configuration is done in the following steps: ``` 3. Passing the configuration value to the lint impl struct: - First find the struct construction in the [clippy_lints lib - file](/clippy_lints/src/lib.rs). The configuration value is now cloned or - copied into a local value that is then passed to the impl struct like this: + First find the struct construction in the [`clippy_lints` lib file]. The + configuration value is now cloned or copied into a local value that is then + passed to the impl struct like this: ```rust // Default generated registration: @@ -653,12 +652,16 @@ for some users. Adding a configuration is done in the following steps: 4. Adding tests: 1. The default configured value can be tested like any normal lint in - [`tests/ui`](/tests/ui). - 2. The configuration itself will be tested separately in - [`tests/ui-toml`](/tests/ui-toml). Simply add a new subfolder with a - fitting name. This folder contains a `clippy.toml` file with the - configuration value and a rust file that should be linted by Clippy. The - test can otherwise be written as usual. + [`tests/ui`]. + 2. The configuration itself will be tested separately in [`tests/ui-toml`]. + Simply add a new subfolder with a fitting name. This folder contains a + `clippy.toml` file with the configuration value and a rust file that + should be linted by Clippy. The test can otherwise be written as usual. + +[`clippy_lints::utils::conf`]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/utils/conf.rs +[`clippy_lints` lib file]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/lib.rs +[`tests/ui`]: https://github.com/rust-lang/rust-clippy/blob/master/tests/ui +[`tests/ui-toml`]: https://github.com/rust-lang/rust-clippy/blob/master/tests/ui-toml ## Cheat Sheet diff --git a/book/src/development/basics.md b/book/src/development/basics.md index 78c429ea0132..605897ff49cd 100644 --- a/book/src/development/basics.md +++ b/book/src/development/basics.md @@ -98,7 +98,7 @@ cargo dev setup intellij ``` More about intellij command usage and reasons -[here](../CONTRIBUTING.md#intellij-rust) +[here](https://github.com/rust-lang/rust-clippy/blob/master/CONTRIBUTING.md#intellij-rust) ## lintcheck diff --git a/book/src/development/common_tools_writing_lints.md b/book/src/development/common_tools_writing_lints.md index e1ed89262f67..15e00c7d7ce4 100644 --- a/book/src/development/common_tools_writing_lints.md +++ b/book/src/development/common_tools_writing_lints.md @@ -276,4 +276,4 @@ functions to deal with macros: [LateContext]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LateContext.html [TyCtxt]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html [pat_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TypeckResults.html#method.pat_ty -[paths]: ../clippy_utils/src/paths.rs +[paths]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/paths/index.html diff --git a/book/src/usage.md b/book/src/usage.md index 337680aa3139..5d858e0da468 100644 --- a/book/src/usage.md +++ b/book/src/usage.md @@ -148,4 +148,4 @@ clippy-driver --edition 2018 -Cpanic=abort foo.rs > that are not optimized as expected, for example. [Installation]: installation.md -[CI]: continuous_integration +[CI]: continuous_integration/index.md From 865554ef90ebd0b8666f3f9a66874d43547c5cab Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Wed, 6 Jul 2022 10:47:29 +0900 Subject: [PATCH 0539/1222] fix miri-opt tests --- tests/ui/crashes/ice-6252.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index a6a767483ed4..a1e37e7317b2 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -28,7 +28,7 @@ LL | const VAL: T; | ------------ `VAL` from trait ... LL | impl TypeVal for Multiply where N: TypeVal {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation error: constant expression depends on a generic parameter --> $DIR/ice-6252.rs:13:9 From 561474a8297009378acacb3120d29a670819e81a Mon Sep 17 00:00:00 2001 From: xFrednet Date: Sun, 26 Jun 2022 00:00:47 +0200 Subject: [PATCH 0540/1222] Fix `#[expect]` and `#[allow]` for `clippy::duplicate_mod` --- clippy_lints/src/duplicate_mod.rs | 22 +++++++++++++++++-- tests/ui-cargo/duplicate_mod/fail/src/d.rs | 0 tests/ui-cargo/duplicate_mod/fail/src/main.rs | 13 +++++++++++ .../duplicate_mod/fail/src/main.stderr | 19 ++++++++++++---- 4 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 tests/ui-cargo/duplicate_mod/fail/src/d.rs diff --git a/clippy_lints/src/duplicate_mod.rs b/clippy_lints/src/duplicate_mod.rs index c6c7b959d4f4..4f49bb879f50 100644 --- a/clippy_lints/src/duplicate_mod.rs +++ b/clippy_lints/src/duplicate_mod.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::ast::{Crate, Inline, Item, ItemKind, ModKind}; use rustc_errors::MultiSpan; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext, Level}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{FileName, Span}; use std::collections::BTreeMap; @@ -49,6 +49,7 @@ declare_clippy_lint! { struct Modules { local_path: PathBuf, spans: Vec, + lint_levels: Vec, } #[derive(Default)] @@ -70,13 +71,30 @@ impl EarlyLintPass for DuplicateMod { let modules = self.modules.entry(absolute_path).or_insert(Modules { local_path, spans: Vec::new(), + lint_levels: Vec::new(), }); modules.spans.push(item.span_with_attributes()); + modules.lint_levels.push(cx.get_lint_level(DUPLICATE_MOD)); } } fn check_crate_post(&mut self, cx: &EarlyContext<'_>, _: &Crate) { - for Modules { local_path, spans } in self.modules.values() { + for Modules { local_path, spans, lint_levels } in self.modules.values() { + if spans.len() < 2 { + continue; + } + + // At this point the lint would be emitted + assert_eq!(spans.len(), lint_levels.len()); + let spans: Vec<_> = spans.into_iter().zip(lint_levels).filter_map(|(span, lvl)|{ + if let Some(id) = lvl.get_expectation_id() { + cx.fulfill_expectation(id); + } + + (!matches!(lvl, Level::Allow | Level::Expect(_))).then_some(*span) + }) + .collect(); + if spans.len() < 2 { continue; } diff --git a/tests/ui-cargo/duplicate_mod/fail/src/d.rs b/tests/ui-cargo/duplicate_mod/fail/src/d.rs new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/ui-cargo/duplicate_mod/fail/src/main.rs b/tests/ui-cargo/duplicate_mod/fail/src/main.rs index 79b343da2470..99ca538b6e4a 100644 --- a/tests/ui-cargo/duplicate_mod/fail/src/main.rs +++ b/tests/ui-cargo/duplicate_mod/fail/src/main.rs @@ -1,3 +1,5 @@ +#[feature(lint_reasons)] + mod a; mod b; @@ -13,4 +15,15 @@ mod c3; mod from_other_module; mod other_module; +mod d; +#[path = "d.rs"] +mod d2; +#[path = "d.rs"] +#[expect(clippy::duplicate_mod)] +mod d3; +#[path = "d.rs"] +#[allow(clippy::duplicate_mod)] +mod d4; + + fn main() {} diff --git a/tests/ui-cargo/duplicate_mod/fail/src/main.stderr b/tests/ui-cargo/duplicate_mod/fail/src/main.stderr index 00d7739c8a2e..61df1ad5d501 100644 --- a/tests/ui-cargo/duplicate_mod/fail/src/main.stderr +++ b/tests/ui-cargo/duplicate_mod/fail/src/main.stderr @@ -1,5 +1,5 @@ error: file is loaded as a module multiple times: `$DIR/b.rs` - --> $DIR/main.rs:3:1 + --> $DIR/main.rs:5:1 | LL | mod b; | ^^^^^^ first loaded here @@ -11,7 +11,7 @@ LL | | mod b2; = help: replace all but one `mod` item with `use` items error: file is loaded as a module multiple times: `$DIR/c.rs` - --> $DIR/main.rs:7:1 + --> $DIR/main.rs:9:1 | LL | mod c; | ^^^^^^ first loaded here @@ -25,7 +25,7 @@ LL | | mod c3; = help: replace all but one `mod` item with `use` items error: file is loaded as a module multiple times: `$DIR/from_other_module.rs` - --> $DIR/main.rs:13:1 + --> $DIR/main.rs:15:1 | LL | mod from_other_module; | ^^^^^^^^^^^^^^^^^^^^^^ first loaded here @@ -38,5 +38,16 @@ LL | | mod m; | = help: replace all but one `mod` item with `use` items -error: aborting due to 3 previous errors +error: file is loaded as a module multiple times: `$DIR/b.rs` + --> $DIR/main.rs:18:1 + | +LL | mod d; + | ^^^^^^ first loaded here +LL | / #[path = "d.rs"] +LL | | mod d2; + | |_______^ loaded again here + | + = help: replace all but one `mod` item with `use` items + +error: aborting due to 4 previous errors From a5305c3ff8438849e311be9f98a43c41b4c3583c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Tue, 5 Jul 2022 00:00:00 +0000 Subject: [PATCH 0541/1222] Move `predecessors` from Body to BasicBlocks --- clippy_lints/src/redundant_clone.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 6d0b9a0f03fa..eddca6045757 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -161,7 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone { // `arg` is a reference as it is `.deref()`ed in the previous block. // Look into the predecessor block and find out the source of deref. - let ps = &mir.predecessors()[bb]; + let ps = &mir.basic_blocks.predecessors()[bb]; if ps.len() != 1 { continue; } From 33d69b6efa777776cd9b8db7184845cf91259378 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 27 Jun 2022 07:45:35 +0200 Subject: [PATCH 0542/1222] Shorten span for closures. --- tests/ui/crashes/ice-6251.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/crashes/ice-6251.stderr b/tests/ui/crashes/ice-6251.stderr index 77a3c2ba4ad0..8da2965c6351 100644 --- a/tests/ui/crashes/ice-6251.stderr +++ b/tests/ui/crashes/ice-6251.stderr @@ -33,7 +33,7 @@ LL | fn bug() -> impl Iterator { | ^^^^^^^^^^^ expected `usize`, found closure | = note: expected type `usize` - found closure `[closure@$DIR/ice-6251.rs:4:44: 4:55]` + found closure `[closure@$DIR/ice-6251.rs:4:44: 4:53]` error: aborting due to 4 previous errors From 43fd43b2b8c68bc7d202e0ffb2b19319bd4c9048 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 7 Jul 2022 10:46:22 +0000 Subject: [PATCH 0543/1222] `UnsafeCell` now has no niches, ever. --- clippy_lints/src/non_copy_const.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index a1ef32ae6080..6bce5fbd4c1f 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -148,7 +148,7 @@ fn is_value_unfrozen_raw<'tcx>( match val.ty().kind() { // the fact that we have to dig into every structs to search enums // leads us to the point checking `UnsafeCell` directly is the only option. - ty::Adt(ty_def, ..) if Some(ty_def.did()) == cx.tcx.lang_items().unsafe_cell_type() => true, + ty::Adt(ty_def, ..) if ty_def.is_unsafe_cell() => true, ty::Array(..) | ty::Adt(..) | ty::Tuple(..) => { let val = cx.tcx.destructure_mir_constant(cx.param_env, val); val.fields.iter().any(|field| inner(cx, *field)) From 2ee9cff2b2a67da8219888c40620faeb1bc11b2e Mon Sep 17 00:00:00 2001 From: Andrea Nall Date: Thu, 7 Jul 2022 19:30:37 +0000 Subject: [PATCH 0544/1222] Add test for and fix rust-lang/rust-clippy#9131 This lint seems to have been broken by #98446 --- clippy_lints/src/misc.rs | 2 +- tests/ui/used_underscore_binding.rs | 6 ++++++ tests/ui/used_underscore_binding.stderr | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index df2430ced6b6..be7df08d89f0 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -301,7 +301,7 @@ fn in_attributes_expansion(expr: &Expr<'_>) -> bool { use rustc_span::hygiene::MacroKind; if expr.span.from_expansion() { let data = expr.span.ctxt().outer_expn_data(); - matches!(data.kind, ExpnKind::Macro(MacroKind::Attr, _)) + matches!(data.kind, ExpnKind::Macro(MacroKind::Attr|MacroKind::Derive, _)) } else { false } diff --git a/tests/ui/used_underscore_binding.rs b/tests/ui/used_underscore_binding.rs index 21d66d5df79e..d20977d55d29 100644 --- a/tests/ui/used_underscore_binding.rs +++ b/tests/ui/used_underscore_binding.rs @@ -44,6 +44,12 @@ fn in_struct_field() { s._underscore_field += 1; } +/// Tests that we do not lint if the struct field is used in code created with derive. +#[derive(Clone, Debug)] +pub struct UnderscoreInStruct { + _foo: u32, +} + /// Tests that we do not lint if the underscore is not a prefix fn non_prefix_underscore(some_foo: u32) -> u32 { some_foo + 1 diff --git a/tests/ui/used_underscore_binding.stderr b/tests/ui/used_underscore_binding.stderr index 790b849210c9..61a9161d212d 100644 --- a/tests/ui/used_underscore_binding.stderr +++ b/tests/ui/used_underscore_binding.stderr @@ -31,7 +31,7 @@ LL | s._underscore_field += 1; | ^^^^^^^^^^^^^^^^^^^ error: used binding `_i` which is prefixed with an underscore. A leading underscore signals that a binding will not be used - --> $DIR/used_underscore_binding.rs:99:16 + --> $DIR/used_underscore_binding.rs:105:16 | LL | uses_i(_i); | ^^ From 1295ea1fd1a8b1e00bf222b8254c81e8e02e6b16 Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Mon, 9 May 2022 15:18:53 -0700 Subject: [PATCH 0545/1222] add opt in attribute for stable-in-unstable items --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 498dcbb89006..0e19b0296f6e 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -353,7 +353,7 @@ fn check_terminator<'a, 'tcx>( fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option) -> bool { tcx.is_const_fn(def_id) && tcx.lookup_const_stability(def_id).map_or(true, |const_stab| { - if let rustc_attr::StabilityLevel::Stable { since } = const_stab.level { + if let rustc_attr::StabilityLevel::Stable { since, .. } = const_stab.level { // Checking MSRV is manually necessary because `rustc` has no such concept. This entire // function could be removed if `rustc` provided a MSRV-aware version of `is_const_fn`. // as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262. From ab5fdf141913c2ebc606ca45ff1d1ae086e28d90 Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Thu, 2 Jun 2022 22:39:47 +0800 Subject: [PATCH 0546/1222] lower let-else in MIR instead --- clippy_lints/src/attrs.rs | 2 +- clippy_lints/src/copies.rs | 6 +++--- clippy_lints/src/default.rs | 2 +- clippy_lints/src/default_numeric_fallback.rs | 2 +- clippy_lints/src/entry.rs | 2 +- clippy_lints/src/explicit_write.rs | 2 +- clippy_lints/src/let_if_seq.rs | 2 +- clippy_lints/src/let_underscore.rs | 4 ++-- clippy_lints/src/loops/needless_collect.rs | 4 ++-- clippy_lints/src/loops/never_loop.rs | 2 +- clippy_lints/src/loops/utils.rs | 6 +++--- clippy_lints/src/loops/while_let_loop.rs | 2 +- clippy_lints/src/loops/while_let_on_iterator.rs | 4 ++-- clippy_lints/src/map_unit_fn.rs | 2 +- clippy_lints/src/matches/mod.rs | 12 +++++++++--- clippy_lints/src/methods/str_splitn.rs | 2 +- clippy_lints/src/misc.rs | 2 +- clippy_lints/src/mixed_read_write_in_expression.rs | 4 ++-- clippy_lints/src/mut_key.rs | 7 ++++++- clippy_lints/src/needless_late_init.rs | 4 ++-- clippy_lints/src/no_effect.rs | 3 ++- clippy_lints/src/only_used_in_recursion.rs | 4 ++-- clippy_lints/src/pattern_type_mismatch.rs | 2 +- clippy_lints/src/read_zero_byte_vec.rs | 2 +- clippy_lints/src/redundant_closure_call.rs | 2 +- clippy_lints/src/returns.rs | 7 ++----- clippy_lints/src/slow_vector_initialization.rs | 2 +- clippy_lints/src/swap.rs | 2 +- clippy_lints/src/types/mod.rs | 4 ++-- clippy_lints/src/uninit_vec.rs | 2 +- clippy_lints/src/unit_types/let_unit_value.rs | 2 +- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/vec_init_then_push.rs | 2 +- clippy_utils/src/hir_utils.rs | 8 ++++++-- clippy_utils/src/lib.rs | 2 +- 35 files changed, 66 insertions(+), 53 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 4bcbeacf9feb..93ce3b30fb1d 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -505,7 +505,7 @@ fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_ .as_ref() .map_or(false, |e| is_relevant_expr(cx, typeck_results, e)), |stmt| match &stmt.kind { - StmtKind::Local(_) => true, + StmtKind::Local(_, _) => true, StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, typeck_results, expr), StmtKind::Item(_) => false, }, diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 1deff9684a14..0b9fdb891b15 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -324,7 +324,7 @@ impl BlockEq { /// If the statement is a local, checks if the bound names match the expected list of names. fn eq_binding_names(s: &Stmt<'_>, names: &[(HirId, Symbol)]) -> bool { - if let StmtKind::Local(l) = s.kind { + if let StmtKind::Local(l, _) = s.kind { let mut i = 0usize; let mut res = true; l.pat.each_binding_or_first(&mut |_, _, _, name| { @@ -349,7 +349,7 @@ fn eq_stmts( eq: &mut HirEqInterExpr<'_, '_, '_>, moved_bindings: &mut Vec<(HirId, Symbol)>, ) -> bool { - (if let StmtKind::Local(l) = stmt.kind { + (if let StmtKind::Local(l, _) = stmt.kind { let old_count = moved_bindings.len(); l.pat.each_binding_or_first(&mut |_, id, _, name| { moved_bindings.push((id, name.name)); @@ -435,7 +435,7 @@ fn scan_block_for_eq(cx: &LateContext<'_>, _conds: &[&Expr<'_>], block: &Block<' // Clear out all locals seen at the end so far. None of them can be moved. let stmts = &blocks[0].stmts; for stmt in &stmts[stmts.len() - init..=stmts.len() - offset] { - if let StmtKind::Local(l) = stmt.kind { + if let StmtKind::Local(l, _) = stmt.kind { l.pat.each_binding_or_first(&mut |_, id, _, _| { eq.locals.remove(&id); }); diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index d99a1aa29694..7fe3443858a0 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -126,7 +126,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { // checked and the name of the bound variable let (local, variant, binding_name, binding_type, span) = if_chain! { // only take `let ...` statements - if let StmtKind::Local(local) = stmt.kind; + if let StmtKind::Local(local, _) = stmt.kind; if let Some(expr) = local.init; if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id); if !expr.span.from_expansion(); diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index fb418a3251f5..0f374d12a84f 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -192,7 +192,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { match stmt.kind { - StmtKind::Local(local) => { + StmtKind::Local(local, _) => { if local.ty.is_some() { self.ty_bounds.push(TyBound::Any); } else { diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 27743a0ebec7..e0986b710c50 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -386,7 +386,7 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> { } }, StmtKind::Expr(e) => self.visit_expr(e), - StmtKind::Local(l) => { + StmtKind::Local(l, _) => { self.visit_pat(l.pat); if let Some(e) = l.init { self.allow_insert_closure &= !self.in_tail_pos; diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 5bf4313b41a4..bd1ac3371b06 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -116,7 +116,7 @@ fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>) if_chain! { if let ExprKind::Block(block, _label @ None) = kind; if let Block { - stmts: [Stmt { kind: StmtKind::Local(local), .. }], + stmts: [Stmt { kind: StmtKind::Local(local, _), .. }], expr: Some(expr_end_of_block), rules: BlockCheckMode::DefaultBlock, .. diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 56bbbbbc819e..5dcb86feb762 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq { while let Some(stmt) = it.next() { if_chain! { if let Some(expr) = it.peek(); - if let hir::StmtKind::Local(local) = stmt.kind; + if let hir::StmtKind::Local(local, _) = stmt.kind; if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.kind; if let hir::StmtKind::Expr(if_) = expr.kind; if let hir::ExprKind::If(hir::Expr { kind: hir::ExprKind::DropTemps(cond), ..}, then, else_) = if_.kind; diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index 176787497ebf..a37dfb7b7151 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::{is_must_use_ty, match_type}; use clippy_utils::{is_must_use_func_call, paths}; use if_chain::if_chain; -use rustc_hir::{Local, PatKind}; +use rustc_hir::{Block, Local, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::subst::GenericArgKind; @@ -109,7 +109,7 @@ const SYNC_GUARD_PATHS: [&[&str]; 6] = [ ]; impl<'tcx> LateLintPass<'tcx> for LetUnderscore { - fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) { + fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>, _: Option<&Block<'_>>) { if in_external_macro(cx.tcx.sess, local.span) { return; } diff --git a/clippy_lints/src/loops/needless_collect.rs b/clippy_lints/src/loops/needless_collect.rs index ddaffc751880..ba0f01d9ed25 100644 --- a/clippy_lints/src/loops/needless_collect.rs +++ b/clippy_lints/src/loops/needless_collect.rs @@ -76,7 +76,7 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo if let ExprKind::Block(block, _) = expr.kind { for stmt in block.stmts { if_chain! { - if let StmtKind::Local(local) = stmt.kind; + if let StmtKind::Local(local, _) = stmt.kind; if let PatKind::Binding(_, id, ..) = local.pat.kind; if let Some(init_expr) = local.init; if let ExprKind::MethodCall(method_name, &[ref iter_source], ..) = init_expr.kind; @@ -276,7 +276,7 @@ fn get_expr_and_hir_id_from_stmt<'v>(stmt: &'v Stmt<'v>) -> Option<(&'v Expr<'v> match stmt.kind { StmtKind::Expr(expr) | StmtKind::Semi(expr) => Some((expr, None)), StmtKind::Item(..) => None, - StmtKind::Local(Local { init, pat, .. }) => { + StmtKind::Local(Local { init, pat, .. }, _) => { if let PatKind::Binding(_, hir_id, ..) = pat.kind { init.map(|init_expr| (init_expr, Some(hir_id))) } else { diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index 32de20f6531f..c60d55180606 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -104,7 +104,7 @@ fn never_loop_expr_seq<'a, T: Iterator>>(es: &mut T, main_lo fn stmt_to_expr<'tcx>(stmt: &Stmt<'tcx>) -> Option<&'tcx Expr<'tcx>> { match stmt.kind { StmtKind::Semi(e, ..) | StmtKind::Expr(e, ..) => Some(e), - StmtKind::Local(local) => local.init, + StmtKind::Local(local, _) => local.init, StmtKind::Item(..) => None, } } diff --git a/clippy_lints/src/loops/utils.rs b/clippy_lints/src/loops/utils.rs index 4801a84eb92c..661af8fe642f 100644 --- a/clippy_lints/src/loops/utils.rs +++ b/clippy_lints/src/loops/utils.rs @@ -4,7 +4,7 @@ use if_chain::if_chain; use rustc_ast::ast::{LitIntType, LitKind}; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_expr, walk_local, walk_pat, walk_stmt, Visitor}; -use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, Local, Mutability, Pat, PatKind, Stmt}; +use rustc_hir::{BinOpKind, Block, BorrowKind, Expr, ExprKind, HirId, HirIdMap, Local, Mutability, Pat, PatKind, Stmt}; use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, Ty}; @@ -148,7 +148,7 @@ impl<'a, 'tcx> InitializeVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { type NestedFilter = nested_filter::OnlyBodies; - fn visit_local(&mut self, l: &'tcx Local<'_>) { + fn visit_local(&mut self, l: &'tcx Local<'_>, e: Option<&'tcx Block<'_>>) { // Look for declarations of the variable if_chain! { if l.pat.hir_id == self.var_id; @@ -166,7 +166,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { } } - walk_local(self, l); + walk_local(self, l, e); } fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { diff --git a/clippy_lints/src/loops/while_let_loop.rs b/clippy_lints/src/loops/while_let_loop.rs index 45af6be2653f..8c3524942520 100644 --- a/clippy_lints/src/loops/while_let_loop.rs +++ b/clippy_lints/src/loops/while_let_loop.rs @@ -11,7 +11,7 @@ use rustc_lint::LateContext; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) { let (init, has_trailing_exprs) = match (loop_block.stmts, loop_block.expr) { ([stmt, stmts @ ..], expr) => { - if let StmtKind::Local(&Local { init: Some(e), .. }) | StmtKind::Semi(e) | StmtKind::Expr(e) = stmt.kind { + if let StmtKind::Local(&Local { init: Some(e), .. }, None) | StmtKind::Semi(e) | StmtKind::Expr(e) = stmt.kind { (e, !stmts.is_empty() || expr.is_some()) } else { return; diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index a57159750664..1abdfaac7ec6 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -8,7 +8,7 @@ use clippy_utils::{ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::{def::Res, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, UnOp}; +use rustc_hir::{def::Res, Block, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, UnOp}; use rustc_lint::LateContext; use rustc_middle::ty::adjustment::Adjust; use rustc_span::{symbol::sym, Symbol}; @@ -283,7 +283,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: & used_after: bool, } impl<'a, 'b, 'tcx> Visitor<'tcx> for NestedLoopVisitor<'a, 'b, 'tcx> { - fn visit_local(&mut self, l: &'tcx Local<'_>) { + fn visit_local(&mut self, l: &'tcx Local<'_>, _: Option<&'tcx Block<'_>>) { if !self.after_loop { l.pat.each_binding_or_first(&mut |_, id, _, _| { if id == self.local_id { diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 663246b4c862..3bfe5428133f 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -144,7 +144,7 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_>, expr: &'a hir::Expr<'_>) -> // If block only contains statements, // reduce `{ X; }` to `X` or `X;` match inner_stmt.kind { - hir::StmtKind::Local(local) => Some(local.span), + hir::StmtKind::Local(local, _) => Some(local.span), hir::StmtKind::Expr(e) => Some(e.span), hir::StmtKind::Semi(..) => Some(inner_stmt.span), hir::StmtKind::Item(..) => None, diff --git a/clippy_lints/src/matches/mod.rs b/clippy_lints/src/matches/mod.rs index b2a873ef5823..cc8674a20065 100644 --- a/clippy_lints/src/matches/mod.rs +++ b/clippy_lints/src/matches/mod.rs @@ -1,6 +1,6 @@ use clippy_utils::source::{snippet_opt, span_starts_with, walk_span_to_context}; use clippy_utils::{higher, in_constant, meets_msrv, msrvs}; -use rustc_hir::{Arm, Expr, ExprKind, Local, MatchSource, Pat}; +use rustc_hir::{Arm, Block, Expr, ExprKind, Local, MatchSource, Pat}; use rustc_lexer::{tokenize, TokenKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; @@ -1040,8 +1040,14 @@ impl<'tcx> LateLintPass<'tcx> for Matches { } } - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'_>) { - self.infallible_destructuring_match_linted |= infallible_destructuring_match::check(cx, local); + fn check_local( + &mut self, + cx: &LateContext<'tcx>, + local: &'tcx Local<'_>, + els: Option<&'tcx Block<'_>>, + ) { + self.infallible_destructuring_match_linted |= + els.is_none() && infallible_destructuring_match::check(cx, local); } fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 4ac738272d08..80dbd14b2c56 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -220,7 +220,7 @@ fn indirect_usage<'tcx>( init: Some(init_expr), hir_id: local_hir_id, .. - }) = stmt.kind + }, _) = stmt.kind { let mut path_to_binding = None; expr_visitor(cx, |expr| { diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index be7df08d89f0..2ad7ac60b925 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -161,7 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { if_chain! { if !in_external_macro(cx.tcx.sess, stmt.span); - if let StmtKind::Local(local) = stmt.kind; + if let StmtKind::Local(local, _) = stmt.kind; if let PatKind::Binding(an, .., name, None) = local.pat.kind; if let Some(init) = local.init; if an == BindingAnnotation::Ref || an == BindingAnnotation::RefMut; diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs index a2419c277e9c..de993c3c0a47 100644 --- a/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/clippy_lints/src/mixed_read_write_in_expression.rs @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for EvalOrderDependence { } fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { match stmt.kind { - StmtKind::Local(local) => { + StmtKind::Local(local, _) => { if let Local { init: Some(e), .. } = local { DivergenceVisitor { cx }.visit_expr(e); } @@ -273,7 +273,7 @@ fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt<'_>) - StmtKind::Expr(expr) | StmtKind::Semi(expr) => check_expr(vis, expr), // If the declaration is of a local variable, check its initializer // expression if it has one. Otherwise, keep going. - StmtKind::Local(local) => local + StmtKind::Local(local, _) => local .init .as_ref() .map_or(StopEarly::KeepGoing, |expr| check_expr(vis, expr)), diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 4db103bbc130..251181165b02 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -101,7 +101,12 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType { } } - fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::Local<'_>) { + fn check_local( + &mut self, + cx: &LateContext<'_>, + local: &hir::Local<'_>, + _: Option<&hir::Block<'_>>, + ) { if let hir::PatKind::Wild = local.pat.kind { return; } diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs index ff2999b1f4a5..fa1c09d8f903 100644 --- a/clippy_lints/src/needless_late_init.rs +++ b/clippy_lints/src/needless_late_init.rs @@ -92,7 +92,7 @@ fn contains_let(cond: &Expr<'_>) -> bool { } fn stmt_needs_ordered_drop(cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool { - let StmtKind::Local(local) = stmt.kind else { return false }; + let StmtKind::Local(local, _) = stmt.kind else { return false }; !local.pat.walk_short(|pat| { if let PatKind::Binding(.., None) = pat.kind { !needs_ordered_drop(cx, cx.typeck_results().pat_ty(pat)) @@ -367,7 +367,7 @@ fn check<'tcx>( } impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit { - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>, _: Option<&'tcx Block<'tcx>>) { let mut parents = cx.tcx.hir().parent_iter(local.hir_id); if_chain! { if let Local { diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 6598413c77ec..105e145ac306 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -88,10 +88,11 @@ fn check_no_effect(cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool { span_lint_hir(cx, NO_EFFECT, expr.hir_id, stmt.span, "statement with no effect"); return true; } - } else if let StmtKind::Local(local) = stmt.kind { + } else if let StmtKind::Local(local, els) = stmt.kind { if_chain! { if !is_lint_allowed(cx, NO_EFFECT_UNDERSCORE_BINDING, local.hir_id); if let Some(init) = local.init; + if els.is_none(); if !local.pat.span.from_expansion(); if has_no_effect(cx, init); if let PatKind::Binding(_, _, ident, _) = local.pat.kind; diff --git a/clippy_lints/src/only_used_in_recursion.rs b/clippy_lints/src/only_used_in_recursion.rs index 677ac998b568..c7f8f2f8d704 100644 --- a/clippy_lints/src/only_used_in_recursion.rs +++ b/clippy_lints/src/only_used_in_recursion.rs @@ -261,13 +261,13 @@ impl<'tcx> Visitor<'tcx> for SideEffectVisit<'tcx> { match s.kind { StmtKind::Local(Local { pat, init: Some(init), .. - }) => { + }, _) => { self.visit_pat_expr(pat, init, false); }, StmtKind::Item(_) | StmtKind::Expr(_) | StmtKind::Semi(_) => { walk_stmt(self, s); }, - StmtKind::Local(_) => {}, + StmtKind::Local(_, _) => {}, } self.ret_vars.clear(); } diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index a4d265111f9a..83e18e207117 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -83,7 +83,7 @@ declare_lint_pass!(PatternTypeMismatch => [PATTERN_TYPE_MISMATCH]); impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { - if let StmtKind::Local(local) = stmt.kind { + if let StmtKind::Local(local, _) = stmt.kind { if in_external_macro(cx.sess(), local.pat.span) { return; } diff --git a/clippy_lints/src/read_zero_byte_vec.rs b/clippy_lints/src/read_zero_byte_vec.rs index 9538a8104739..8316efad1ffe 100644 --- a/clippy_lints/src/read_zero_byte_vec.rs +++ b/clippy_lints/src/read_zero_byte_vec.rs @@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for ReadZeroByteVec { for (idx, stmt) in block.stmts.iter().enumerate() { if !stmt.span.from_expansion() // matches `let v = Vec::new();` - && let StmtKind::Local(local) = stmt.kind + && let StmtKind::Local(local, _) = stmt.kind && let Local { pat, init: Some(init), .. } = local && let PatKind::Binding(_, _, ident, _) = pat.kind && let Some(vec_init_kind) = get_vec_init_kind(cx, init) diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 65ed798867d1..48bf14d511c7 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -133,7 +133,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { for w in block.stmts.windows(2) { if_chain! { - if let hir::StmtKind::Local(local) = w[0].kind; + if let hir::StmtKind::Local(local, _) = w[0].kind; if let Option::Some(t) = local.init; if let hir::ExprKind::Closure { .. } = t.kind; if let hir::PatKind::Binding(_, _, ident, _) = local.pat.kind; diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 5ae04947b82d..b2ec32abb442 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -10,7 +10,6 @@ use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::subst::GenericArgKind; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::hygiene::DesugaringKind; use rustc_span::source_map::Span; use rustc_span::sym; @@ -83,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for Return { if_chain! { if let Some(retexpr) = block.expr; if let Some(stmt) = block.stmts.iter().last(); - if let StmtKind::Local(local) = &stmt.kind; + if let StmtKind::Local(local, _) = &stmt.kind; if local.ty.is_none(); if cx.tcx.hir().attrs(local.hir_id).is_empty(); if let Some(initexpr) = &local.init; @@ -203,9 +202,7 @@ fn check_final_expr<'tcx>( check_block_return(cx, ifblock); } if let Some(else_clause) = else_clause_opt { - if expr.span.desugaring_kind() != Some(DesugaringKind::LetElse) { - check_final_expr(cx, else_clause, None, RetReplacement::Empty); - } + check_final_expr(cx, else_clause, None, RetReplacement::Empty); } }, // a match expr, check all arms diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 2c8aa17e80db..3d7ef747a86c 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for SlowVectorInit { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { // Matches statements which initializes vectors. For example: `let mut vec = Vec::with_capacity(10)` if_chain! { - if let StmtKind::Local(local) = stmt.kind; + if let StmtKind::Local(local, _) = stmt.kind; if let PatKind::Binding(BindingAnnotation::Mutable, local_id, _, None) = local.pat.kind; if let Some(init) = local.init; if let Some(len_arg) = Self::is_vec_with_capacity(cx, init); diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index 1885f3ca414d..a8c96543c7c6 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -141,7 +141,7 @@ fn check_manual_swap(cx: &LateContext<'_>, block: &Block<'_>) { for w in block.stmts.windows(3) { if_chain! { // let t = foo(); - if let StmtKind::Local(tmp) = w[0].kind; + if let StmtKind::Local(tmp, _) = w[0].kind; if let Some(tmp_init) = tmp.init; if let PatKind::Binding(.., ident, None) = tmp.pat.kind; diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 353a6f6b899e..2a7d5f2623e2 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -12,7 +12,7 @@ mod vec_box; use rustc_hir as hir; use rustc_hir::intravisit::FnKind; use rustc_hir::{ - Body, FnDecl, FnRetTy, GenericArg, HirId, ImplItem, ImplItemKind, Item, ItemKind, Local, MutTy, QPath, TraitItem, + Block, Body, FnDecl, FnRetTy, GenericArg, HirId, ImplItem, ImplItemKind, Item, ItemKind, Local, MutTy, QPath, TraitItem, TraitItemKind, TyKind, }; use rustc_lint::{LateContext, LateLintPass}; @@ -406,7 +406,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { } } - fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) { + fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>, _: Option<&Block<'_>>) { if let Some(ty) = local.ty { self.check_ty( cx, diff --git a/clippy_lints/src/uninit_vec.rs b/clippy_lints/src/uninit_vec.rs index 9f4c5555f11b..eab3b9b7b01c 100644 --- a/clippy_lints/src/uninit_vec.rs +++ b/clippy_lints/src/uninit_vec.rs @@ -155,7 +155,7 @@ impl<'tcx> VecLocation<'tcx> { /// or `self` expression for `Vec::reserve()`. fn extract_init_or_reserve_target<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'tcx>) -> Option> { match stmt.kind { - StmtKind::Local(local) => { + StmtKind::Local(local, _) => { if_chain! { if let Some(init_expr) = local.init; if let PatKind::Binding(_, hir_id, _, None) = local.pat.kind; diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index cf509455aad0..80e7b8de392c 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -12,7 +12,7 @@ use rustc_middle::ty::{self, Ty, TypeVisitable, TypeSuperVisitable, TypeVisitor} use super::LET_UNIT_VALUE; pub(super) fn check(cx: &LateContext<'_>, stmt: &Stmt<'_>) { - if let StmtKind::Local(local) = stmt.kind + if let StmtKind::Local(local, _) = stmt.kind && let Some(init) = local.init && !local.pat.span.from_expansion() && !in_external_macro(cx.sess(), stmt.span) diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 2c8820eb7e1a..99ac84fbaaba 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -685,7 +685,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { } match stmt.value.kind { - StmtKind::Local(local) => { + StmtKind::Local(local, _) => { bind!(self, local); kind!("Local({local})"); self.option(field!(local.init), "init", |init| { diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs index 35db45e2b0c9..c71bacfa29a7 100644 --- a/clippy_lints/src/vec_init_then_push.rs +++ b/clippy_lints/src/vec_init_then_push.rs @@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for VecInitThenPush { self.searcher = None; } - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>, _: Option<&'tcx Block<'tcx>>) { if let Some(init_expr) = local.init && let PatKind::Binding(BindingAnnotation::Mutable, id, name, None) = local.pat.kind && !in_external_macro(cx.sess(), local.span) diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 793e3cc58c21..0b5325adfed2 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -102,7 +102,7 @@ pub struct HirEqInterExpr<'a, 'b, 'tcx> { impl HirEqInterExpr<'_, '_, '_> { pub fn eq_stmt(&mut self, left: &Stmt<'_>, right: &Stmt<'_>) -> bool { match (&left.kind, &right.kind) { - (&StmtKind::Local(l), &StmtKind::Local(r)) => { + (&StmtKind::Local(l, le), &StmtKind::Local(r, re)) => { // This additional check ensures that the type of the locals are equivalent even if the init // expression or type have some inferred parts. if let Some((typeck_lhs, typeck_rhs)) = self.inner.maybe_typeck_results { @@ -117,6 +117,7 @@ impl HirEqInterExpr<'_, '_, '_> { // these only get added if the init and type is equal. both(&l.init, &r.init, |l, r| self.eq_expr(l, r)) && both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r)) + && both(&le, &re, |l, r| self.eq_block(l, r)) && self.eq_pat(l.pat, r.pat) }, (&StmtKind::Expr(l), &StmtKind::Expr(r)) | (&StmtKind::Semi(l), &StmtKind::Semi(r)) => self.eq_expr(l, r), @@ -921,11 +922,14 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { std::mem::discriminant(&b.kind).hash(&mut self.s); match &b.kind { - StmtKind::Local(local) => { + StmtKind::Local(local, els) => { self.hash_pat(local.pat); if let Some(init) = local.init { self.hash_expr(init); } + if let Some(els) = els { + self.hash_block(els); + } }, StmtKind::Item(..) => {}, StmtKind::Expr(expr) | StmtKind::Semi(expr) => { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 1b32f0aaeb8d..ac6490cfd2c7 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1826,7 +1826,7 @@ pub fn is_expr_used_or_unified(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { .. }, .. - }), + }, _), .. }), _ From fc7cf4f955f485da35ec620d9b2a7d3628418a07 Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Tue, 5 Jul 2022 23:31:18 +0200 Subject: [PATCH 0547/1222] move else block into the `Local` struct --- clippy_lints/src/attrs.rs | 2 +- clippy_lints/src/copies.rs | 6 +++--- clippy_lints/src/default.rs | 2 +- clippy_lints/src/default_numeric_fallback.rs | 2 +- clippy_lints/src/entry.rs | 2 +- clippy_lints/src/explicit_write.rs | 2 +- clippy_lints/src/let_if_seq.rs | 2 +- clippy_lints/src/let_underscore.rs | 4 ++-- clippy_lints/src/loops/needless_collect.rs | 4 ++-- clippy_lints/src/loops/never_loop.rs | 2 +- clippy_lints/src/loops/utils.rs | 6 +++--- clippy_lints/src/loops/while_let_loop.rs | 2 +- clippy_lints/src/loops/while_let_on_iterator.rs | 4 ++-- clippy_lints/src/map_unit_fn.rs | 2 +- clippy_lints/src/matches/mod.rs | 11 +++-------- clippy_lints/src/methods/str_splitn.rs | 2 +- clippy_lints/src/misc.rs | 2 +- clippy_lints/src/mixed_read_write_in_expression.rs | 4 ++-- clippy_lints/src/mut_key.rs | 7 +------ clippy_lints/src/needless_late_init.rs | 4 ++-- clippy_lints/src/no_effect.rs | 4 ++-- clippy_lints/src/only_used_in_recursion.rs | 4 ++-- clippy_lints/src/pattern_type_mismatch.rs | 2 +- clippy_lints/src/read_zero_byte_vec.rs | 2 +- clippy_lints/src/redundant_closure_call.rs | 2 +- clippy_lints/src/returns.rs | 2 +- clippy_lints/src/slow_vector_initialization.rs | 2 +- clippy_lints/src/swap.rs | 2 +- clippy_lints/src/types/mod.rs | 4 ++-- clippy_lints/src/uninit_vec.rs | 2 +- clippy_lints/src/unit_types/let_unit_value.rs | 2 +- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/vec_init_then_push.rs | 2 +- clippy_utils/src/hir_utils.rs | 8 ++++---- clippy_utils/src/lib.rs | 2 +- 35 files changed, 52 insertions(+), 62 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 93ce3b30fb1d..4bcbeacf9feb 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -505,7 +505,7 @@ fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_ .as_ref() .map_or(false, |e| is_relevant_expr(cx, typeck_results, e)), |stmt| match &stmt.kind { - StmtKind::Local(_, _) => true, + StmtKind::Local(_) => true, StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, typeck_results, expr), StmtKind::Item(_) => false, }, diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 0b9fdb891b15..1deff9684a14 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -324,7 +324,7 @@ impl BlockEq { /// If the statement is a local, checks if the bound names match the expected list of names. fn eq_binding_names(s: &Stmt<'_>, names: &[(HirId, Symbol)]) -> bool { - if let StmtKind::Local(l, _) = s.kind { + if let StmtKind::Local(l) = s.kind { let mut i = 0usize; let mut res = true; l.pat.each_binding_or_first(&mut |_, _, _, name| { @@ -349,7 +349,7 @@ fn eq_stmts( eq: &mut HirEqInterExpr<'_, '_, '_>, moved_bindings: &mut Vec<(HirId, Symbol)>, ) -> bool { - (if let StmtKind::Local(l, _) = stmt.kind { + (if let StmtKind::Local(l) = stmt.kind { let old_count = moved_bindings.len(); l.pat.each_binding_or_first(&mut |_, id, _, name| { moved_bindings.push((id, name.name)); @@ -435,7 +435,7 @@ fn scan_block_for_eq(cx: &LateContext<'_>, _conds: &[&Expr<'_>], block: &Block<' // Clear out all locals seen at the end so far. None of them can be moved. let stmts = &blocks[0].stmts; for stmt in &stmts[stmts.len() - init..=stmts.len() - offset] { - if let StmtKind::Local(l, _) = stmt.kind { + if let StmtKind::Local(l) = stmt.kind { l.pat.each_binding_or_first(&mut |_, id, _, _| { eq.locals.remove(&id); }); diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index 7fe3443858a0..d99a1aa29694 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -126,7 +126,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { // checked and the name of the bound variable let (local, variant, binding_name, binding_type, span) = if_chain! { // only take `let ...` statements - if let StmtKind::Local(local, _) = stmt.kind; + if let StmtKind::Local(local) = stmt.kind; if let Some(expr) = local.init; if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id); if !expr.span.from_expansion(); diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index 0f374d12a84f..fb418a3251f5 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -192,7 +192,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { match stmt.kind { - StmtKind::Local(local, _) => { + StmtKind::Local(local) => { if local.ty.is_some() { self.ty_bounds.push(TyBound::Any); } else { diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index e0986b710c50..27743a0ebec7 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -386,7 +386,7 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> { } }, StmtKind::Expr(e) => self.visit_expr(e), - StmtKind::Local(l, _) => { + StmtKind::Local(l) => { self.visit_pat(l.pat); if let Some(e) = l.init { self.allow_insert_closure &= !self.in_tail_pos; diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index bd1ac3371b06..5bf4313b41a4 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -116,7 +116,7 @@ fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>) if_chain! { if let ExprKind::Block(block, _label @ None) = kind; if let Block { - stmts: [Stmt { kind: StmtKind::Local(local, _), .. }], + stmts: [Stmt { kind: StmtKind::Local(local), .. }], expr: Some(expr_end_of_block), rules: BlockCheckMode::DefaultBlock, .. diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 5dcb86feb762..56bbbbbc819e 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq { while let Some(stmt) = it.next() { if_chain! { if let Some(expr) = it.peek(); - if let hir::StmtKind::Local(local, _) = stmt.kind; + if let hir::StmtKind::Local(local) = stmt.kind; if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.kind; if let hir::StmtKind::Expr(if_) = expr.kind; if let hir::ExprKind::If(hir::Expr { kind: hir::ExprKind::DropTemps(cond), ..}, then, else_) = if_.kind; diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index a37dfb7b7151..176787497ebf 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::{is_must_use_ty, match_type}; use clippy_utils::{is_must_use_func_call, paths}; use if_chain::if_chain; -use rustc_hir::{Block, Local, PatKind}; +use rustc_hir::{Local, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::subst::GenericArgKind; @@ -109,7 +109,7 @@ const SYNC_GUARD_PATHS: [&[&str]; 6] = [ ]; impl<'tcx> LateLintPass<'tcx> for LetUnderscore { - fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>, _: Option<&Block<'_>>) { + fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) { if in_external_macro(cx.tcx.sess, local.span) { return; } diff --git a/clippy_lints/src/loops/needless_collect.rs b/clippy_lints/src/loops/needless_collect.rs index ba0f01d9ed25..ddaffc751880 100644 --- a/clippy_lints/src/loops/needless_collect.rs +++ b/clippy_lints/src/loops/needless_collect.rs @@ -76,7 +76,7 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo if let ExprKind::Block(block, _) = expr.kind { for stmt in block.stmts { if_chain! { - if let StmtKind::Local(local, _) = stmt.kind; + if let StmtKind::Local(local) = stmt.kind; if let PatKind::Binding(_, id, ..) = local.pat.kind; if let Some(init_expr) = local.init; if let ExprKind::MethodCall(method_name, &[ref iter_source], ..) = init_expr.kind; @@ -276,7 +276,7 @@ fn get_expr_and_hir_id_from_stmt<'v>(stmt: &'v Stmt<'v>) -> Option<(&'v Expr<'v> match stmt.kind { StmtKind::Expr(expr) | StmtKind::Semi(expr) => Some((expr, None)), StmtKind::Item(..) => None, - StmtKind::Local(Local { init, pat, .. }, _) => { + StmtKind::Local(Local { init, pat, .. }) => { if let PatKind::Binding(_, hir_id, ..) = pat.kind { init.map(|init_expr| (init_expr, Some(hir_id))) } else { diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index c60d55180606..32de20f6531f 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -104,7 +104,7 @@ fn never_loop_expr_seq<'a, T: Iterator>>(es: &mut T, main_lo fn stmt_to_expr<'tcx>(stmt: &Stmt<'tcx>) -> Option<&'tcx Expr<'tcx>> { match stmt.kind { StmtKind::Semi(e, ..) | StmtKind::Expr(e, ..) => Some(e), - StmtKind::Local(local, _) => local.init, + StmtKind::Local(local) => local.init, StmtKind::Item(..) => None, } } diff --git a/clippy_lints/src/loops/utils.rs b/clippy_lints/src/loops/utils.rs index 661af8fe642f..4801a84eb92c 100644 --- a/clippy_lints/src/loops/utils.rs +++ b/clippy_lints/src/loops/utils.rs @@ -4,7 +4,7 @@ use if_chain::if_chain; use rustc_ast::ast::{LitIntType, LitKind}; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_expr, walk_local, walk_pat, walk_stmt, Visitor}; -use rustc_hir::{BinOpKind, Block, BorrowKind, Expr, ExprKind, HirId, HirIdMap, Local, Mutability, Pat, PatKind, Stmt}; +use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, Local, Mutability, Pat, PatKind, Stmt}; use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, Ty}; @@ -148,7 +148,7 @@ impl<'a, 'tcx> InitializeVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { type NestedFilter = nested_filter::OnlyBodies; - fn visit_local(&mut self, l: &'tcx Local<'_>, e: Option<&'tcx Block<'_>>) { + fn visit_local(&mut self, l: &'tcx Local<'_>) { // Look for declarations of the variable if_chain! { if l.pat.hir_id == self.var_id; @@ -166,7 +166,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { } } - walk_local(self, l, e); + walk_local(self, l); } fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { diff --git a/clippy_lints/src/loops/while_let_loop.rs b/clippy_lints/src/loops/while_let_loop.rs index 8c3524942520..ca617859db49 100644 --- a/clippy_lints/src/loops/while_let_loop.rs +++ b/clippy_lints/src/loops/while_let_loop.rs @@ -11,7 +11,7 @@ use rustc_lint::LateContext; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) { let (init, has_trailing_exprs) = match (loop_block.stmts, loop_block.expr) { ([stmt, stmts @ ..], expr) => { - if let StmtKind::Local(&Local { init: Some(e), .. }, None) | StmtKind::Semi(e) | StmtKind::Expr(e) = stmt.kind { + if let StmtKind::Local(&Local { init: Some(e), els: None, .. }) | StmtKind::Semi(e) | StmtKind::Expr(e) = stmt.kind { (e, !stmts.is_empty() || expr.is_some()) } else { return; diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index 1abdfaac7ec6..a57159750664 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -8,7 +8,7 @@ use clippy_utils::{ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::{def::Res, Block, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, UnOp}; +use rustc_hir::{def::Res, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, UnOp}; use rustc_lint::LateContext; use rustc_middle::ty::adjustment::Adjust; use rustc_span::{symbol::sym, Symbol}; @@ -283,7 +283,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: & used_after: bool, } impl<'a, 'b, 'tcx> Visitor<'tcx> for NestedLoopVisitor<'a, 'b, 'tcx> { - fn visit_local(&mut self, l: &'tcx Local<'_>, _: Option<&'tcx Block<'_>>) { + fn visit_local(&mut self, l: &'tcx Local<'_>) { if !self.after_loop { l.pat.each_binding_or_first(&mut |_, id, _, _| { if id == self.local_id { diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 3bfe5428133f..663246b4c862 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -144,7 +144,7 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_>, expr: &'a hir::Expr<'_>) -> // If block only contains statements, // reduce `{ X; }` to `X` or `X;` match inner_stmt.kind { - hir::StmtKind::Local(local, _) => Some(local.span), + hir::StmtKind::Local(local) => Some(local.span), hir::StmtKind::Expr(e) => Some(e.span), hir::StmtKind::Semi(..) => Some(inner_stmt.span), hir::StmtKind::Item(..) => None, diff --git a/clippy_lints/src/matches/mod.rs b/clippy_lints/src/matches/mod.rs index cc8674a20065..3077b999f4ee 100644 --- a/clippy_lints/src/matches/mod.rs +++ b/clippy_lints/src/matches/mod.rs @@ -1,6 +1,6 @@ use clippy_utils::source::{snippet_opt, span_starts_with, walk_span_to_context}; use clippy_utils::{higher, in_constant, meets_msrv, msrvs}; -use rustc_hir::{Arm, Block, Expr, ExprKind, Local, MatchSource, Pat}; +use rustc_hir::{Arm, Expr, ExprKind, Local, MatchSource, Pat}; use rustc_lexer::{tokenize, TokenKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; @@ -1040,14 +1040,9 @@ impl<'tcx> LateLintPass<'tcx> for Matches { } } - fn check_local( - &mut self, - cx: &LateContext<'tcx>, - local: &'tcx Local<'_>, - els: Option<&'tcx Block<'_>>, - ) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'_>) { self.infallible_destructuring_match_linted |= - els.is_none() && infallible_destructuring_match::check(cx, local); + local.els.is_none() && infallible_destructuring_match::check(cx, local); } fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 80dbd14b2c56..4ac738272d08 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -220,7 +220,7 @@ fn indirect_usage<'tcx>( init: Some(init_expr), hir_id: local_hir_id, .. - }, _) = stmt.kind + }) = stmt.kind { let mut path_to_binding = None; expr_visitor(cx, |expr| { diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 2ad7ac60b925..be7df08d89f0 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -161,7 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { if_chain! { if !in_external_macro(cx.tcx.sess, stmt.span); - if let StmtKind::Local(local, _) = stmt.kind; + if let StmtKind::Local(local) = stmt.kind; if let PatKind::Binding(an, .., name, None) = local.pat.kind; if let Some(init) = local.init; if an == BindingAnnotation::Ref || an == BindingAnnotation::RefMut; diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs index de993c3c0a47..a2419c277e9c 100644 --- a/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/clippy_lints/src/mixed_read_write_in_expression.rs @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for EvalOrderDependence { } fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { match stmt.kind { - StmtKind::Local(local, _) => { + StmtKind::Local(local) => { if let Local { init: Some(e), .. } = local { DivergenceVisitor { cx }.visit_expr(e); } @@ -273,7 +273,7 @@ fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt<'_>) - StmtKind::Expr(expr) | StmtKind::Semi(expr) => check_expr(vis, expr), // If the declaration is of a local variable, check its initializer // expression if it has one. Otherwise, keep going. - StmtKind::Local(local, _) => local + StmtKind::Local(local) => local .init .as_ref() .map_or(StopEarly::KeepGoing, |expr| check_expr(vis, expr)), diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 251181165b02..4db103bbc130 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -101,12 +101,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType { } } - fn check_local( - &mut self, - cx: &LateContext<'_>, - local: &hir::Local<'_>, - _: Option<&hir::Block<'_>>, - ) { + fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::Local<'_>) { if let hir::PatKind::Wild = local.pat.kind { return; } diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs index fa1c09d8f903..ff2999b1f4a5 100644 --- a/clippy_lints/src/needless_late_init.rs +++ b/clippy_lints/src/needless_late_init.rs @@ -92,7 +92,7 @@ fn contains_let(cond: &Expr<'_>) -> bool { } fn stmt_needs_ordered_drop(cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool { - let StmtKind::Local(local, _) = stmt.kind else { return false }; + let StmtKind::Local(local) = stmt.kind else { return false }; !local.pat.walk_short(|pat| { if let PatKind::Binding(.., None) = pat.kind { !needs_ordered_drop(cx, cx.typeck_results().pat_ty(pat)) @@ -367,7 +367,7 @@ fn check<'tcx>( } impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit { - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>, _: Option<&'tcx Block<'tcx>>) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { let mut parents = cx.tcx.hir().parent_iter(local.hir_id); if_chain! { if let Local { diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 105e145ac306..819646bb6780 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -88,11 +88,11 @@ fn check_no_effect(cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool { span_lint_hir(cx, NO_EFFECT, expr.hir_id, stmt.span, "statement with no effect"); return true; } - } else if let StmtKind::Local(local, els) = stmt.kind { + } else if let StmtKind::Local(local) = stmt.kind { if_chain! { if !is_lint_allowed(cx, NO_EFFECT_UNDERSCORE_BINDING, local.hir_id); if let Some(init) = local.init; - if els.is_none(); + if local.els.is_none(); if !local.pat.span.from_expansion(); if has_no_effect(cx, init); if let PatKind::Binding(_, _, ident, _) = local.pat.kind; diff --git a/clippy_lints/src/only_used_in_recursion.rs b/clippy_lints/src/only_used_in_recursion.rs index c7f8f2f8d704..677ac998b568 100644 --- a/clippy_lints/src/only_used_in_recursion.rs +++ b/clippy_lints/src/only_used_in_recursion.rs @@ -261,13 +261,13 @@ impl<'tcx> Visitor<'tcx> for SideEffectVisit<'tcx> { match s.kind { StmtKind::Local(Local { pat, init: Some(init), .. - }, _) => { + }) => { self.visit_pat_expr(pat, init, false); }, StmtKind::Item(_) | StmtKind::Expr(_) | StmtKind::Semi(_) => { walk_stmt(self, s); }, - StmtKind::Local(_, _) => {}, + StmtKind::Local(_) => {}, } self.ret_vars.clear(); } diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index 83e18e207117..a4d265111f9a 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -83,7 +83,7 @@ declare_lint_pass!(PatternTypeMismatch => [PATTERN_TYPE_MISMATCH]); impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { - if let StmtKind::Local(local, _) = stmt.kind { + if let StmtKind::Local(local) = stmt.kind { if in_external_macro(cx.sess(), local.pat.span) { return; } diff --git a/clippy_lints/src/read_zero_byte_vec.rs b/clippy_lints/src/read_zero_byte_vec.rs index 8316efad1ffe..9538a8104739 100644 --- a/clippy_lints/src/read_zero_byte_vec.rs +++ b/clippy_lints/src/read_zero_byte_vec.rs @@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for ReadZeroByteVec { for (idx, stmt) in block.stmts.iter().enumerate() { if !stmt.span.from_expansion() // matches `let v = Vec::new();` - && let StmtKind::Local(local, _) = stmt.kind + && let StmtKind::Local(local) = stmt.kind && let Local { pat, init: Some(init), .. } = local && let PatKind::Binding(_, _, ident, _) = pat.kind && let Some(vec_init_kind) = get_vec_init_kind(cx, init) diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 48bf14d511c7..65ed798867d1 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -133,7 +133,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { for w in block.stmts.windows(2) { if_chain! { - if let hir::StmtKind::Local(local, _) = w[0].kind; + if let hir::StmtKind::Local(local) = w[0].kind; if let Option::Some(t) = local.init; if let hir::ExprKind::Closure { .. } = t.kind; if let hir::PatKind::Binding(_, _, ident, _) = local.pat.kind; diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index b2ec32abb442..1d9a2abf7066 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for Return { if_chain! { if let Some(retexpr) = block.expr; if let Some(stmt) = block.stmts.iter().last(); - if let StmtKind::Local(local, _) = &stmt.kind; + if let StmtKind::Local(local) = &stmt.kind; if local.ty.is_none(); if cx.tcx.hir().attrs(local.hir_id).is_empty(); if let Some(initexpr) = &local.init; diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 3d7ef747a86c..2c8aa17e80db 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for SlowVectorInit { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { // Matches statements which initializes vectors. For example: `let mut vec = Vec::with_capacity(10)` if_chain! { - if let StmtKind::Local(local, _) = stmt.kind; + if let StmtKind::Local(local) = stmt.kind; if let PatKind::Binding(BindingAnnotation::Mutable, local_id, _, None) = local.pat.kind; if let Some(init) = local.init; if let Some(len_arg) = Self::is_vec_with_capacity(cx, init); diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index a8c96543c7c6..1885f3ca414d 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -141,7 +141,7 @@ fn check_manual_swap(cx: &LateContext<'_>, block: &Block<'_>) { for w in block.stmts.windows(3) { if_chain! { // let t = foo(); - if let StmtKind::Local(tmp, _) = w[0].kind; + if let StmtKind::Local(tmp) = w[0].kind; if let Some(tmp_init) = tmp.init; if let PatKind::Binding(.., ident, None) = tmp.pat.kind; diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 2a7d5f2623e2..353a6f6b899e 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -12,7 +12,7 @@ mod vec_box; use rustc_hir as hir; use rustc_hir::intravisit::FnKind; use rustc_hir::{ - Block, Body, FnDecl, FnRetTy, GenericArg, HirId, ImplItem, ImplItemKind, Item, ItemKind, Local, MutTy, QPath, TraitItem, + Body, FnDecl, FnRetTy, GenericArg, HirId, ImplItem, ImplItemKind, Item, ItemKind, Local, MutTy, QPath, TraitItem, TraitItemKind, TyKind, }; use rustc_lint::{LateContext, LateLintPass}; @@ -406,7 +406,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { } } - fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>, _: Option<&Block<'_>>) { + fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) { if let Some(ty) = local.ty { self.check_ty( cx, diff --git a/clippy_lints/src/uninit_vec.rs b/clippy_lints/src/uninit_vec.rs index eab3b9b7b01c..9f4c5555f11b 100644 --- a/clippy_lints/src/uninit_vec.rs +++ b/clippy_lints/src/uninit_vec.rs @@ -155,7 +155,7 @@ impl<'tcx> VecLocation<'tcx> { /// or `self` expression for `Vec::reserve()`. fn extract_init_or_reserve_target<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'tcx>) -> Option> { match stmt.kind { - StmtKind::Local(local, _) => { + StmtKind::Local(local) => { if_chain! { if let Some(init_expr) = local.init; if let PatKind::Binding(_, hir_id, _, None) = local.pat.kind; diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index 80e7b8de392c..cf509455aad0 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -12,7 +12,7 @@ use rustc_middle::ty::{self, Ty, TypeVisitable, TypeSuperVisitable, TypeVisitor} use super::LET_UNIT_VALUE; pub(super) fn check(cx: &LateContext<'_>, stmt: &Stmt<'_>) { - if let StmtKind::Local(local, _) = stmt.kind + if let StmtKind::Local(local) = stmt.kind && let Some(init) = local.init && !local.pat.span.from_expansion() && !in_external_macro(cx.sess(), stmt.span) diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 99ac84fbaaba..2c8820eb7e1a 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -685,7 +685,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { } match stmt.value.kind { - StmtKind::Local(local, _) => { + StmtKind::Local(local) => { bind!(self, local); kind!("Local({local})"); self.option(field!(local.init), "init", |init| { diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs index c71bacfa29a7..35db45e2b0c9 100644 --- a/clippy_lints/src/vec_init_then_push.rs +++ b/clippy_lints/src/vec_init_then_push.rs @@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for VecInitThenPush { self.searcher = None; } - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>, _: Option<&'tcx Block<'tcx>>) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { if let Some(init_expr) = local.init && let PatKind::Binding(BindingAnnotation::Mutable, id, name, None) = local.pat.kind && !in_external_macro(cx.sess(), local.span) diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 0b5325adfed2..942f14ddd3d5 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -102,7 +102,7 @@ pub struct HirEqInterExpr<'a, 'b, 'tcx> { impl HirEqInterExpr<'_, '_, '_> { pub fn eq_stmt(&mut self, left: &Stmt<'_>, right: &Stmt<'_>) -> bool { match (&left.kind, &right.kind) { - (&StmtKind::Local(l, le), &StmtKind::Local(r, re)) => { + (&StmtKind::Local(l, ), &StmtKind::Local(r, )) => { // This additional check ensures that the type of the locals are equivalent even if the init // expression or type have some inferred parts. if let Some((typeck_lhs, typeck_rhs)) = self.inner.maybe_typeck_results { @@ -117,7 +117,7 @@ impl HirEqInterExpr<'_, '_, '_> { // these only get added if the init and type is equal. both(&l.init, &r.init, |l, r| self.eq_expr(l, r)) && both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r)) - && both(&le, &re, |l, r| self.eq_block(l, r)) + && both(&l.els, &r.els, |l, r| self.eq_block(l, r)) && self.eq_pat(l.pat, r.pat) }, (&StmtKind::Expr(l), &StmtKind::Expr(r)) | (&StmtKind::Semi(l), &StmtKind::Semi(r)) => self.eq_expr(l, r), @@ -922,12 +922,12 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { std::mem::discriminant(&b.kind).hash(&mut self.s); match &b.kind { - StmtKind::Local(local, els) => { + StmtKind::Local(local, ) => { self.hash_pat(local.pat); if let Some(init) = local.init { self.hash_expr(init); } - if let Some(els) = els { + if let Some(els) = local.els { self.hash_block(els); } }, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index ac6490cfd2c7..1b32f0aaeb8d 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1826,7 +1826,7 @@ pub fn is_expr_used_or_unified(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { .. }, .. - }, _), + }), .. }), _ From d084f85b4e8b9c6742661b61fb14bf580b0a39ab Mon Sep 17 00:00:00 2001 From: ouz-a Date: Mon, 13 Jun 2022 16:37:41 +0300 Subject: [PATCH 0548/1222] add new rval, pull deref early --- clippy_utils/src/qualify_min_const_fn.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 498dcbb89006..f3283588c732 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -124,6 +124,7 @@ fn check_rvalue<'tcx>( Rvalue::Len(place) | Rvalue::Discriminant(place) | Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => { check_place(tcx, *place, span, body) }, + Rvalue::CopyForDeref(place) => check_place(tcx, *place, span, body), Rvalue::Repeat(operand, _) | Rvalue::Use(operand) | Rvalue::Cast( From 327354527f61fbe606d7a55723523fba47ce4b08 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 30 Jun 2022 14:18:51 +0400 Subject: [PATCH 0549/1222] Fix clippy build --- clippy_lints/src/blocks_in_if_conditions.rs | 4 ++-- clippy_lints/src/bytecount.rs | 4 ++-- clippy_lints/src/eta_reduction.rs | 4 ++-- clippy_lints/src/infinite_iter.rs | 4 ++-- clippy_lints/src/loops/needless_range_loop.rs | 4 ++-- clippy_lints/src/loops/while_let_on_iterator.rs | 8 ++++---- clippy_lints/src/manual_async_fn.rs | 4 ++-- clippy_lints/src/manual_ok_or.rs | 4 ++-- clippy_lints/src/manual_retain.rs | 2 +- clippy_lints/src/map_clone.rs | 2 +- clippy_lints/src/map_err_ignore.rs | 6 +++--- clippy_lints/src/map_unit_fn.rs | 2 +- clippy_lints/src/methods/bind_instead_of_map.rs | 2 +- clippy_lints/src/methods/filter_map.rs | 10 +++++----- clippy_lints/src/methods/option_as_ref_deref.rs | 2 +- clippy_lints/src/methods/option_map_or_none.rs | 2 +- clippy_lints/src/methods/search_is_some.rs | 2 +- clippy_lints/src/methods/unnecessary_filter_map.rs | 2 +- clippy_lints/src/methods/unnecessary_fold.rs | 2 +- clippy_lints/src/methods/unnecessary_lazy_eval.rs | 2 +- clippy_lints/src/needless_for_each.rs | 4 ++-- clippy_lints/src/only_used_in_recursion.rs | 4 ++-- clippy_lints/src/redundant_closure_call.rs | 2 +- clippy_lints/src/suspicious_operation_groupings.rs | 2 +- clippy_lints/src/unit_return_expecting_ord.rs | 4 ++-- clippy_lints/src/unnecessary_sort_by.rs | 4 ++-- clippy_lints/src/utils/author.rs | 6 +++--- clippy_utils/src/ast_utils.rs | 13 +++++++++++-- clippy_utils/src/hir_utils.rs | 6 +++--- clippy_utils/src/lib.rs | 12 ++++++------ clippy_utils/src/sugg.rs | 4 ++-- 31 files changed, 71 insertions(+), 62 deletions(-) diff --git a/clippy_lints/src/blocks_in_if_conditions.rs b/clippy_lints/src/blocks_in_if_conditions.rs index 4b3a04f1255b..ad206b5fb304 100644 --- a/clippy_lints/src/blocks_in_if_conditions.rs +++ b/clippy_lints/src/blocks_in_if_conditions.rs @@ -6,7 +6,7 @@ use clippy_utils::ty::implements_trait; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::{BlockCheckMode, Expr, ExprKind}; +use rustc_hir::{BlockCheckMode, Closure, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -51,7 +51,7 @@ struct ExVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { - if let ExprKind::Closure { body, .. } = expr.kind { + if let ExprKind::Closure(&Closure { body, .. }) = expr.kind { // do not lint if the closure is called using an iterator (see #1141) if_chain! { if let Some(parent) = get_parent_expr(self.cx, expr); diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index 4e530256321c..326ce34082af 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -5,7 +5,7 @@ use clippy_utils::visitors::is_local_used; use clippy_utils::{path_to_local_id, paths, peel_blocks, peel_ref_operators, strip_pat_refs}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::{BinOpKind, Expr, ExprKind, PatKind}; +use rustc_hir::{BinOpKind, Closure, Expr, ExprKind, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, UintTy}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -51,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount { if count.ident.name == sym::count; if let ExprKind::MethodCall(filter, [filter_recv, filter_arg], _) = count_recv.kind; if filter.ident.name == sym!(filter); - if let ExprKind::Closure { body, .. } = filter_arg.kind; + if let ExprKind::Closure(&Closure { body, .. }) = filter_arg.kind; let body = cx.tcx.hir().body(body); if let [param] = body.params; if let PatKind::Binding(_, arg_id, _, _) = strip_pat_refs(param.pat).kind; diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 42fac550ec69..80c84014bfde 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -7,7 +7,7 @@ use clippy_utils::{higher, is_adjusted, path_to_local, path_to_local_id}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; -use rustc_hir::{Expr, ExprKind, Param, PatKind, Unsafety}; +use rustc_hir::{Closure, Expr, ExprKind, Param, PatKind, Unsafety}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; use rustc_middle::ty::binding::BindingMode; @@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { return; } let body = match expr.kind { - ExprKind::Closure { body, .. } => cx.tcx.hir().body(body), + ExprKind::Closure(&Closure { body, .. }) => cx.tcx.hir().body(body), _ => return, }; if body.value.span.from_expansion() { diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index 78b5ec8ec1ef..01c7eef4e04d 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; use clippy_utils::{higher, match_def_path, path_def_id, paths}; -use rustc_hir::{BorrowKind, Expr, ExprKind}; +use rustc_hir::{BorrowKind, Closure, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::{sym, Symbol}; @@ -159,7 +159,7 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { } } if method.ident.name == sym!(flat_map) && args.len() == 2 { - if let ExprKind::Closure { body, .. } = args[1].kind { + if let ExprKind::Closure(&Closure { body, .. }) = args[1].kind { let body = cx.tcx.hir().body(body); return is_infinite(cx, &body.value); } diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 0b6d9adb553e..a7ef562b21fc 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -9,7 +9,7 @@ use rustc_ast::ast; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, Mutability, Pat, PatKind, QPath}; +use rustc_hir::{BinOpKind, BorrowKind, Closure, Expr, ExprKind, HirId, Mutability, Pat, PatKind, QPath}; use rustc_lint::LateContext; use rustc_middle::middle::region; use rustc_middle::ty::{self, Ty}; @@ -369,7 +369,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { self.visit_expr(expr); } }, - ExprKind::Closure { body, .. } => { + ExprKind::Closure(&Closure { body, .. }) => { let body = self.cx.tcx.hir().body(body); self.visit_expr(&body.value); }, diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index a57159750664..b94bbd2bd417 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -8,7 +8,7 @@ use clippy_utils::{ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::{def::Res, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, UnOp}; +use rustc_hir::{Closure, def::Res, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, UnOp}; use rustc_lint::LateContext; use rustc_middle::ty::adjustment::Adjust; use rustc_span::{symbol::sym, Symbol}; @@ -220,7 +220,7 @@ fn uses_iter<'tcx>(cx: &LateContext<'tcx>, iter_expr: &IterExpr, container: &'tc if let Some(e) = e { self.visit_expr(e); } - } else if let ExprKind::Closure { body: id, .. } = e.kind { + } else if let ExprKind::Closure(&Closure { body: id, .. }) = e.kind { if is_res_used(self.cx, self.iter_expr.path, id) { self.uses_iter = true; } @@ -260,7 +260,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: & if let Some(e) = e { self.visit_expr(e); } - } else if let ExprKind::Closure { body: id, .. } = e.kind { + } else if let ExprKind::Closure(&Closure { body: id, .. }) = e.kind { self.used_iter = is_res_used(self.cx, self.iter_expr.path, id); } else { walk_expr(self, e); @@ -307,7 +307,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: & if let Some(e) = e { self.visit_expr(e); } - } else if let ExprKind::Closure { body: id, .. } = e.kind { + } else if let ExprKind::Closure(&Closure { body: id, .. }) = e.kind { self.used_after = is_res_used(self.cx, self.iter_expr.path, id); } else { walk_expr(self, e); diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index d7d8a5921528..93a34f452f6d 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -6,7 +6,7 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{ - AsyncGeneratorKind, Block, Body, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound, HirId, + AsyncGeneratorKind, Block, Body, Closure, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound, HirId, IsAsync, ItemKind, LifetimeName, Term, TraitRef, Ty, TyKind, TypeBindingKind, }; use rustc_lint::{LateContext, LateLintPass}; @@ -177,7 +177,7 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) if let Some(block_expr) = block.expr; if let Some(args) = match_function_call(cx, block_expr, &FUTURE_FROM_GENERATOR); if args.len() == 1; - if let Expr{kind: ExprKind::Closure { body, .. }, ..} = args[0]; + if let Expr{kind: ExprKind::Closure(&Closure { body, .. }), ..} = args[0]; let closure_body = cx.tcx.hir().body(body); if closure_body.generator_kind == Some(GeneratorKind::Async(AsyncGeneratorKind::Block)); then { diff --git a/clippy_lints/src/manual_ok_or.rs b/clippy_lints/src/manual_ok_or.rs index 18cfd0037678..9abf2507b921 100644 --- a/clippy_lints/src/manual_ok_or.rs +++ b/clippy_lints/src/manual_ok_or.rs @@ -5,7 +5,7 @@ use clippy_utils::{is_lang_ctor, path_to_local_id}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::LangItem::{ResultErr, ResultOk}; -use rustc_hir::{Expr, ExprKind, PatKind}; +use rustc_hir::{Closure, Expr, ExprKind, PatKind}; use rustc_lint::LintContext; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; @@ -88,7 +88,7 @@ fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool { } } if_chain! { - if let ExprKind::Closure { body, .. } = map_expr.kind; + if let ExprKind::Closure(&Closure { body, .. }) = map_expr.kind; let body = cx.tcx.hir().body(body); if let PatKind::Binding(_, param_id, ..) = body.params[0].pat.kind; if let ExprKind::Call(Expr { kind: ExprKind::Path(ok_path), .. }, &[ref ok_arg]) = body.value.kind; diff --git a/clippy_lints/src/manual_retain.rs b/clippy_lints/src/manual_retain.rs index c35e1e021ef1..42d2577cc316 100644 --- a/clippy_lints/src/manual_retain.rs +++ b/clippy_lints/src/manual_retain.rs @@ -148,7 +148,7 @@ fn check_to_owned( fn suggest(cx: &LateContext<'_>, parent_expr: &hir::Expr<'_>, left_expr: &hir::Expr<'_>, filter_expr: &hir::Expr<'_>) { if let hir::ExprKind::MethodCall(_, [_, closure], _) = filter_expr.kind - && let hir::ExprKind::Closure{ body, ..} = closure.kind + && let hir::ExprKind::Closure(&hir::Closure { body, ..}) = closure.kind && let filter_body = cx.tcx.hir().body(body) && let [filter_params] = filter_body.params && let Some(sugg) = match filter_params.pat.kind { diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 3533de54a1e3..95c312f1fe26 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone { if method.ident.name == sym::map; let ty = cx.typeck_results().expr_ty(&args[0]); if is_type_diagnostic_item(cx, ty, sym::Option) || is_trait_method(cx, e, sym::Iterator); - if let hir::ExprKind::Closure { body, .. } = args[1].kind; + if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = args[1].kind; then { let closure_body = cx.tcx.hir().body(body); let closure_expr = peel_blocks(&closure_body.value); diff --git a/clippy_lints/src/map_err_ignore.rs b/clippy_lints/src/map_err_ignore.rs index 0c2214410487..21d0e19eb0a4 100644 --- a/clippy_lints/src/map_err_ignore.rs +++ b/clippy_lints/src/map_err_ignore.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_help; -use rustc_hir::{CaptureBy, Expr, ExprKind, PatKind}; +use rustc_hir::{CaptureBy, Closure, Expr, ExprKind, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -119,12 +119,12 @@ impl<'tcx> LateLintPass<'tcx> for MapErrIgnore { if method.ident.as_str() == "map_err" && args.len() == 2 { // make sure the first argument is a closure, and grab the CaptureRef, BodyId, and fn_decl_span // fields - if let ExprKind::Closure { + if let ExprKind::Closure(&Closure { capture_clause, body, fn_decl_span, .. - } = args[1].kind + }) = args[1].kind { // check if this is by Reference (meaning there's no move statement) if capture_clause == CaptureBy::Ref { diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 663246b4c862..af9d948af00e 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -169,7 +169,7 @@ fn unit_closure<'tcx>( expr: &hir::Expr<'_>, ) -> Option<(&'tcx hir::Param<'tcx>, &'tcx hir::Expr<'tcx>)> { if_chain! { - if let hir::ExprKind::Closure { fn_decl, body, .. } = expr.kind; + if let hir::ExprKind::Closure(&hir::Closure { fn_decl, body, .. }) = expr.kind; let body = cx.tcx.hir().body(body); let body_expr = &body.value; if fn_decl.inputs.len() == 1; diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs index d31b736982b3..2f117e4dcc37 100644 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/clippy_lints/src/methods/bind_instead_of_map.rs @@ -150,7 +150,7 @@ pub(crate) trait BindInsteadOfMap { } match arg.kind { - hir::ExprKind::Closure { body, fn_decl_span, .. } => { + hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }) => { let closure_body = cx.tcx.hir().body(body); let closure_expr = peel_blocks(&closure_body.value); diff --git a/clippy_lints/src/methods/filter_map.rs b/clippy_lints/src/methods/filter_map.rs index 58c3e52e138c..7dbfd95c50db 100644 --- a/clippy_lints/src/methods/filter_map.rs +++ b/clippy_lints/src/methods/filter_map.rs @@ -6,7 +6,7 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::Res; -use rustc_hir::{Expr, ExprKind, PatKind, PathSegment, QPath, UnOp}; +use rustc_hir::{Closure, Expr, ExprKind, PatKind, PathSegment, QPath, UnOp}; use rustc_lint::LateContext; use rustc_span::source_map::Span; use rustc_span::symbol::{sym, Symbol}; @@ -22,8 +22,8 @@ fn is_method<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, method_name: Sy hir::ExprKind::Path(QPath::Resolved(_, segments)) => { segments.segments.last().unwrap().ident.name == method_name }, - hir::ExprKind::Closure { body, .. } => { - let body = cx.tcx.hir().body(*body); + hir::ExprKind::Closure(&hir::Closure { body, .. }) => { + let body = cx.tcx.hir().body(body); let closure_expr = peel_blocks(&body.value); let arg_id = body.params[0].pat.hir_id; match closure_expr.kind { @@ -106,7 +106,7 @@ pub(super) fn check<'tcx>( if is_trait_method(cx, map_recv, sym::Iterator); // filter(|x| ...is_some())... - if let ExprKind::Closure { body: filter_body_id, .. } = filter_arg.kind; + if let ExprKind::Closure(&Closure { body: filter_body_id, .. }) = filter_arg.kind; let filter_body = cx.tcx.hir().body(filter_body_id); if let [filter_param] = filter_body.params; // optional ref pattern: `filter(|&x| ..)` @@ -129,7 +129,7 @@ pub(super) fn check<'tcx>( if path.ident.name.as_str() == if is_result { "is_ok" } else { "is_some" }; // ...map(|x| ...unwrap()) - if let ExprKind::Closure { body: map_body_id, .. } = map_arg.kind; + if let ExprKind::Closure(&Closure { body: map_body_id, .. }) = map_arg.kind; let map_body = cx.tcx.hir().body(map_body_id); if let [map_param] = map_body.params; if let PatKind::Binding(_, map_param_id, map_param_ident, None) = map_param.pat.kind; diff --git a/clippy_lints/src/methods/option_as_ref_deref.rs b/clippy_lints/src/methods/option_as_ref_deref.rs index 912499bf96b9..20cad0f181e9 100644 --- a/clippy_lints/src/methods/option_as_ref_deref.rs +++ b/clippy_lints/src/methods/option_as_ref_deref.rs @@ -51,7 +51,7 @@ pub(super) fn check<'tcx>( .map_or(false, |fun_def_id| { deref_aliases.iter().any(|path| match_def_path(cx, fun_def_id, path)) }), - hir::ExprKind::Closure { body, .. } => { + hir::ExprKind::Closure(&hir::Closure { body, .. }) => { let closure_body = cx.tcx.hir().body(body); let closure_expr = peel_blocks(&closure_body.value); diff --git a/clippy_lints/src/methods/option_map_or_none.rs b/clippy_lints/src/methods/option_map_or_none.rs index 2d71bd6f240f..5a39b82b027d 100644 --- a/clippy_lints/src/methods/option_map_or_none.rs +++ b/clippy_lints/src/methods/option_map_or_none.rs @@ -71,7 +71,7 @@ pub(super) fn check<'tcx>( if is_option { let self_snippet = snippet(cx, recv.span, ".."); if_chain! { - if let hir::ExprKind::Closure { body, fn_decl_span, .. } = map_arg.kind; + if let hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }) = map_arg.kind; let arg_snippet = snippet(cx, fn_decl_span, ".."); let body = cx.tcx.hir().body(body); if let Some((func, [arg_char])) = reduce_unit_expression(&body.value); diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs index b11f4531a912..7572ba3fe9a9 100644 --- a/clippy_lints/src/methods/search_is_some.rs +++ b/clippy_lints/src/methods/search_is_some.rs @@ -41,7 +41,7 @@ pub(super) fn check<'tcx>( let mut applicability = Applicability::MachineApplicable; let any_search_snippet = if_chain! { if search_method == "find"; - if let hir::ExprKind::Closure { body, .. } = search_arg.kind; + if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = search_arg.kind; let closure_body = cx.tcx.hir().body(body); if let Some(closure_arg) = closure_body.params.get(0); then { diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index a405467f5e8a..bafa6fc584d4 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -18,7 +18,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr< return; } - if let hir::ExprKind::Closure { body, .. } = arg.kind { + if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = arg.kind { let body = cx.tcx.hir().body(body); let arg_id = body.params[0].pat.hir_id; let mutates_arg = diff --git a/clippy_lints/src/methods/unnecessary_fold.rs b/clippy_lints/src/methods/unnecessary_fold.rs index 913c4dbedc30..c3531d4d0511 100644 --- a/clippy_lints/src/methods/unnecessary_fold.rs +++ b/clippy_lints/src/methods/unnecessary_fold.rs @@ -29,7 +29,7 @@ pub(super) fn check( ) { if_chain! { // Extract the body of the closure passed to fold - if let hir::ExprKind::Closure { body, .. } = acc.kind; + if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = acc.kind; let closure_body = cx.tcx.hir().body(body); let closure_expr = peel_blocks(&closure_body.value); diff --git a/clippy_lints/src/methods/unnecessary_lazy_eval.rs b/clippy_lints/src/methods/unnecessary_lazy_eval.rs index 865f6d0318eb..21767d74c87b 100644 --- a/clippy_lints/src/methods/unnecessary_lazy_eval.rs +++ b/clippy_lints/src/methods/unnecessary_lazy_eval.rs @@ -22,7 +22,7 @@ pub(super) fn check<'tcx>( let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result); if is_option || is_result { - if let hir::ExprKind::Closure { body, .. } = arg.kind { + if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = arg.kind { let body = cx.tcx.hir().body(body); let body_expr = &body.value; diff --git a/clippy_lints/src/needless_for_each.rs b/clippy_lints/src/needless_for_each.rs index 48ac695f2acf..10e188ecb79a 100644 --- a/clippy_lints/src/needless_for_each.rs +++ b/clippy_lints/src/needless_for_each.rs @@ -1,7 +1,7 @@ use rustc_errors::Applicability; use rustc_hir::{ intravisit::{walk_expr, Visitor}, - Expr, ExprKind, Stmt, StmtKind, + Closure, Expr, ExprKind, Stmt, StmtKind, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessForEach { if has_iter_method(cx, cx.typeck_results().expr_ty(iter_recv)).is_some(); // Skip the lint if the body is not block because this is simpler than `for` loop. // e.g. `v.iter().for_each(f)` is simpler and clearer than using `for` loop. - if let ExprKind::Closure { body, .. } = for_each_arg.kind; + if let ExprKind::Closure(&Closure { body, .. }) = for_each_arg.kind; let body = cx.tcx.hir().body(body); if let ExprKind::Block(..) = body.value.kind; then { diff --git a/clippy_lints/src/only_used_in_recursion.rs b/clippy_lints/src/only_used_in_recursion.rs index 677ac998b568..d461668077e0 100644 --- a/clippy_lints/src/only_used_in_recursion.rs +++ b/clippy_lints/src/only_used_in_recursion.rs @@ -11,7 +11,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData}; use rustc_hir::intravisit::{walk_expr, walk_stmt, FnKind, Visitor}; use rustc_hir::{ - Arm, Block, Body, Expr, ExprKind, Guard, HirId, ImplicitSelfKind, Let, Local, Pat, PatKind, Path, PathSegment, + Arm, Closure, Block, Body, Expr, ExprKind, Guard, HirId, ImplicitSelfKind, Let, Local, Pat, PatKind, Path, PathSegment, QPath, Stmt, StmtKind, TyKind, UnOp, }; use rustc_lint::{LateContext, LateLintPass}; @@ -298,7 +298,7 @@ impl<'tcx> Visitor<'tcx> for SideEffectVisit<'tcx> { }, ExprKind::Match(expr, arms, _) => self.visit_match(expr, arms), // since analysing the closure is not easy, just set all variables in it to side-effect - ExprKind::Closure { body, .. } => { + ExprKind::Closure(&Closure { body, .. }) => { let body = self.tcx.hir().body(body); self.visit_body(body); let vars = std::mem::take(&mut self.ret_vars); diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 65ed798867d1..f5a93cebab8c 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -69,7 +69,7 @@ impl EarlyLintPass for RedundantClosureCall { if_chain! { if let ast::ExprKind::Call(ref paren, _) = expr.kind; if let ast::ExprKind::Paren(ref closure) = paren.kind; - if let ast::ExprKind::Closure(_, _, _, ref decl, ref block, _) = closure.kind; + if let ast::ExprKind::Closure(_, _, _, _, ref decl, ref block, _) = closure.kind; then { let mut visitor = ReturnVisitor::new(); visitor.visit_expr(block); diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index c4c1aa11004a..fe8859905953 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -582,7 +582,7 @@ fn ident_difference_expr_with_base_location( | (Await(_), Await(_)) | (Async(_, _, _), Async(_, _, _)) | (Block(_, _), Block(_, _)) - | (Closure(_, _, _, _, _, _), Closure(_, _, _, _, _, _)) + | (Closure(_, _, _, _, _, _, _), Closure(_, _, _, _, _, _, _)) | (Match(_, _), Match(_, _)) | (Loop(_, _), Loop(_, _)) | (ForLoop(_, _, _, _), ForLoop(_, _, _, _)) diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index f58da7ce9b42..b0fce91abeb7 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; use clippy_utils::{get_trait_def_id, paths}; use if_chain::if_chain; use rustc_hir::def_id::DefId; -use rustc_hir::{Expr, ExprKind, StmtKind}; +use rustc_hir::{Closure, Expr, ExprKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_middle::ty::{GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate}; @@ -116,7 +116,7 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Span, Option)> { if_chain! { - if let ExprKind::Closure { body, fn_decl_span, .. } = arg.kind; + if let ExprKind::Closure(&Closure { body, fn_decl_span, .. }) = arg.kind; if let ty::Closure(_def_id, substs) = &cx.typeck_results().node_type(arg.hir_id).kind(); let ret_ty = substs.as_closure().sig().output(); let ty = cx.tcx.erase_late_bound_regions(ret_ty); diff --git a/clippy_lints/src/unnecessary_sort_by.rs b/clippy_lints/src/unnecessary_sort_by.rs index 7d4373b2a57b..ea5aadbbca1c 100644 --- a/clippy_lints/src/unnecessary_sort_by.rs +++ b/clippy_lints/src/unnecessary_sort_by.rs @@ -3,7 +3,7 @@ use clippy_utils::sugg::Sugg; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, Mutability, Param, Pat, PatKind, Path, PathSegment, QPath}; +use rustc_hir::{Closure, Expr, ExprKind, Mutability, Param, Pat, PatKind, Path, PathSegment, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, subst::GenericArgKind}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -155,7 +155,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { if let ExprKind::MethodCall(name_ident, args, _) = &expr.kind; if let name = name_ident.ident.name.to_ident_string(); if name == "sort_by" || name == "sort_unstable_by"; - if let [vec, Expr { kind: ExprKind::Closure{ body: closure_body_id, .. }, .. }] = args; + if let [vec, Expr { kind: ExprKind::Closure(Closure { body: closure_body_id, .. }), .. }] = args; if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(vec), sym::Vec); if let closure_body = cx.tcx.hir().body(*closure_body_id); if let &[ diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 2c8820eb7e1a..bbb04c9945a0 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -6,7 +6,7 @@ use rustc_ast::ast::{LitFloatType, LitKind}; use rustc_ast::LitIntType; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; -use rustc_hir::{ArrayLen, ExprKind, FnRetTy, HirId, Lit, PatKind, QPath, StmtKind, TyKind}; +use rustc_hir::{ArrayLen, Closure, ExprKind, FnRetTy, HirId, Lit, PatKind, QPath, StmtKind, TyKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::{Ident, Symbol}; @@ -466,13 +466,13 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { self.expr(scrutinee); self.slice(arms, |arm| self.arm(arm)); }, - ExprKind::Closure { + ExprKind::Closure(&Closure { capture_clause, fn_decl, body: body_id, movability, .. - } => { + }) => { let movability = OptionPat::new(movability.map(|m| format!("Movability::{m:?}"))); let ret_ty = match fn_decl.output { diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 177e754ee091..431b09d53c33 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -168,8 +168,8 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (AssignOp(lo, lp, lv), AssignOp(ro, rp, rv)) => lo.node == ro.node && eq_expr(lp, rp) && eq_expr(lv, rv), (Field(lp, lf), Field(rp, rf)) => eq_id(*lf, *rf) && eq_expr(lp, rp), (Match(ls, la), Match(rs, ra)) => eq_expr(ls, rs) && over(la, ra, eq_arm), - (Closure(lc, la, lm, lf, lb, _), Closure(rc, ra, rm, rf, rb, _)) => { - lc == rc && la.is_async() == ra.is_async() && lm == rm && eq_fn_decl(lf, rf) && eq_expr(lb, rb) + (Closure(lb, lc, la, lm, lf, le, _), Closure(rb, rc, ra, rm, rf, re, _)) => { + eq_closure_binder(lb, rb) && lc == rc && la.is_async() == ra.is_async() && lm == rm && eq_fn_decl(lf, rf) && eq_expr(le, re) }, (Async(lc, _, lb), Async(rc, _, rb)) => lc == rc && eq_block(lb, rb), (Range(lf, lt, ll), Range(rf, rt, rl)) => ll == rl && eq_expr_opt(lf, rf) && eq_expr_opt(lt, rt), @@ -561,6 +561,15 @@ pub fn eq_fn_decl(l: &FnDecl, r: &FnDecl) -> bool { }) } +pub fn eq_closure_binder(l: &ClosureBinder, r: &ClosureBinder) -> bool { + match (l, r) { + (ClosureBinder::NotPresent, ClosureBinder::NotPresent) => true, + (ClosureBinder::For { generic_params: lp, .. }, ClosureBinder::For { generic_params: rp, .. }) => + lp.len() == rp.len() && std::iter::zip(lp.iter(), rp.iter()).all(|(l, r)| eq_generic_param(l, r)), + _ => false, + } +} + pub fn eq_fn_ret_ty(l: &FnRetTy, r: &FnRetTy) -> bool { match (l, r) { (FnRetTy::Default(_), FnRetTy::Default(_)) => true, diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 793e3cc58c21..4e5c3850f86a 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHasher; use rustc_hir::def::Res; use rustc_hir::HirIdMap; use rustc_hir::{ - ArrayLen, BinOpKind, Block, BodyId, Expr, ExprField, ExprKind, FnRetTy, GenericArg, GenericArgs, Guard, HirId, + ArrayLen, BinOpKind, Closure, Block, BodyId, Expr, ExprField, ExprKind, FnRetTy, GenericArg, GenericArgs, Guard, HirId, InlineAsmOperand, Let, Lifetime, LifetimeName, ParamName, Pat, PatField, PatKind, Path, PathSegment, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding, }; @@ -662,9 +662,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_expr(e); self.hash_ty(ty); }, - ExprKind::Closure { + ExprKind::Closure(&Closure { capture_clause, body, .. - } => { + }) => { std::mem::discriminant(&capture_clause).hash(&mut self.s); // closures inherit TypeckResults self.hash_expr(&self.cx.tcx.hir().body(body).value); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 1b32f0aaeb8d..242d4315378e 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -79,10 +79,10 @@ use rustc_hir::hir_id::{HirIdMap, HirIdSet}; use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; use rustc_hir::LangItem::{OptionNone, ResultErr, ResultOk}; use rustc_hir::{ - def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Constness, Destination, Expr, ExprKind, FnDecl, - HirId, Impl, ImplItem, ImplItemKind, IsAsync, Item, ItemKind, LangItem, Local, MatchSource, Mutability, Node, - Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitRef, TyKind, - UnOp, + def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Closure, Constness, Destination, Expr, + ExprKind, FnDecl, HirId, Impl, ImplItem, ImplItemKind, IsAsync, Item, ItemKind, LangItem, Local, MatchSource, + Mutability, Node, Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, + TraitRef, TyKind, UnOp, }; use rustc_lint::{LateContext, Level, Lint, LintContext}; use rustc_middle::hir::place::PlaceBase; @@ -1699,7 +1699,7 @@ pub fn get_async_fn_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Option<&'t _, &[ Expr { - kind: ExprKind::Closure { body, .. }, + kind: ExprKind::Closure(&Closure { body, .. }), .. }, ], @@ -1786,7 +1786,7 @@ pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool } match expr.kind { - ExprKind::Closure { body, .. } => is_body_identity_function(cx, cx.tcx.hir().body(body)), + ExprKind::Closure(&Closure { body, .. }) => is_body_identity_function(cx, cx.tcx.hir().body(body)), _ => path_def_id(cx, expr).map_or(false, |id| match_def_path(cx, id, &paths::CONVERT_IDENTITY)), } } diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index aa119539b1b3..4326a103d44b 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -8,7 +8,7 @@ use rustc_ast::{ast, token}; use rustc_ast_pretty::pprust::token_kind_to_string; use rustc_errors::Applicability; use rustc_hir as hir; -use rustc_hir::{ExprKind, HirId, MutTy, TyKind}; +use rustc_hir::{Closure, ExprKind, HirId, MutTy, TyKind}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{EarlyContext, LateContext, LintContext}; use rustc_middle::hir::place::ProjectionKind; @@ -790,7 +790,7 @@ pub struct DerefClosure { /// /// note: this only works on single line immutable closures with exactly one input parameter. pub fn deref_closure_args<'tcx>(cx: &LateContext<'_>, closure: &'tcx hir::Expr<'_>) -> Option { - if let hir::ExprKind::Closure { fn_decl, body, .. } = closure.kind { + if let hir::ExprKind::Closure(&Closure { fn_decl, body, .. }) = closure.kind { let closure_body = cx.tcx.hir().body(body); // is closure arg a type annotated double reference (i.e.: `|x: &&i32| ...`) // a type annotation is present if param `kind` is different from `TyKind::Infer` From 0eb33bb64cd765193d3b281eaea6f0e4f9cdf0a1 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 4 Jun 2022 14:17:00 +0200 Subject: [PATCH 0550/1222] Clippy fallout. --- clippy_lints/src/inherent_to_string.rs | 4 ++-- clippy_lints/src/lifetimes.rs | 10 +++++++--- clippy_lints/src/ptr.rs | 3 ++- clippy_lints/src/types/borrowed_box.rs | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index 39f68a8a1b48..94db1773fda6 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; use clippy_utils::{get_trait_def_id, paths, return_ty, trait_ref_of_method}; use if_chain::if_chain; -use rustc_hir::{ImplItem, ImplItemKind}; +use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; @@ -102,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString { let decl = &signature.decl; if decl.implicit_self.has_implicit_self(); if decl.inputs.len() == 1; - if impl_item.generics.params.is_empty(); + if impl_item.generics.params.iter().all(|p| matches!(p.kind, GenericParamKind::Lifetime { .. })); // Check if return type is String if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::String); diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 5c0bd57ac509..083c437a293c 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -9,8 +9,8 @@ use rustc_hir::intravisit::{ use rustc_hir::FnRetTy::Return; use rustc_hir::{ BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl, ImplItem, - ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, ParamName, PolyTraitRef, PredicateOrigin, - TraitBoundModifier, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate, + ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, LifetimeParamKind, ParamName, PolyTraitRef, + PredicateOrigin, TraitBoundModifier, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter as middle_nested_filter; @@ -338,7 +338,10 @@ fn could_use_elision<'tcx>( fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxHashSet { let mut allowed_lts = FxHashSet::default(); for par in named_generics.iter() { - if let GenericParamKind::Lifetime { .. } = par.kind { + if let GenericParamKind::Lifetime { + kind: LifetimeParamKind::Explicit, + } = par.kind + { allowed_lts.insert(RefLt::Named(par.name.ident().name)); } } @@ -379,6 +382,7 @@ impl<'a, 'tcx> RefVisitor<'a, 'tcx> { self.lts.push(RefLt::Static); } else if let LifetimeName::Param(_, ParamName::Fresh) = lt.name { // Fresh lifetimes generated should be ignored. + self.lts.push(RefLt::Unnamed); } else if lt.is_elided() { self.lts.push(RefLt::Unnamed); } else { diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 25b73918c0a2..8571607054a0 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -495,12 +495,13 @@ fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Optio if let FnRetTy::Return(ty) = sig.decl.output && let Some((out, Mutability::Mut, _)) = get_rptr_lm(ty) { + let out_region = cx.tcx.named_region(out.hir_id); let args: Option> = sig .decl .inputs .iter() .filter_map(get_rptr_lm) - .filter(|&(lt, _, _)| lt.name == out.name) + .filter(|&(lt, _, _)| cx.tcx.named_region(lt.hir_id) == out_region) .map(|(_, mutability, span)| (mutability == Mutability::Not).then(|| span)) .collect(); if let Some(args) = args diff --git a/clippy_lints/src/types/borrowed_box.rs b/clippy_lints/src/types/borrowed_box.rs index f35f44eda567..94945b2e1a9e 100644 --- a/clippy_lints/src/types/borrowed_box.rs +++ b/clippy_lints/src/types/borrowed_box.rs @@ -31,7 +31,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m return false; } - let ltopt = if lt.is_elided() { + let ltopt = if lt.name.is_anonymous() { String::new() } else { format!("{} ", lt.name.ident().as_str()) From 8f6c73b8f164d7e137216163f2924544fdd86b8e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 30 Jun 2022 10:17:49 -0400 Subject: [PATCH 0551/1222] add array tests, cleanup, tidy, and bless --- tests/ui/derive.rs | 2 +- tests/ui/no_effect.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/derive.rs b/tests/ui/derive.rs index 4e46bf139917..b276c384c04e 100644 --- a/tests/ui/derive.rs +++ b/tests/ui/derive.rs @@ -1,7 +1,7 @@ -#![feature(untagged_unions)] #![allow(dead_code)] #![warn(clippy::expl_impl_clone_on_copy)] + #[derive(Copy)] struct Qux; diff --git a/tests/ui/no_effect.rs b/tests/ui/no_effect.rs index 7ece66a1ccb6..f0c59b4080be 100644 --- a/tests/ui/no_effect.rs +++ b/tests/ui/no_effect.rs @@ -4,7 +4,7 @@ #![allow(path_statements)] #![allow(clippy::deref_addrof)] #![allow(clippy::redundant_field_names)] -#![feature(untagged_unions)] + struct Unit; struct Tuple(i32); From 07a720292f326f85435423fd679aa26190b416db Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 6 Jul 2022 07:44:47 -0500 Subject: [PATCH 0552/1222] Rename `debugging_opts` to `unstable_opts` This is no longer used only for debugging options (e.g. `-Zoutput-width`, `-Zallow-features`). Rename it to be more clear. --- src/driver.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver.rs b/src/driver.rs index 96d542cfe105..c219c7de830e 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -117,7 +117,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks { // run on the unoptimized MIR. On the other hand this results in some false negatives. If // MIR passes can be enabled / disabled separately, we should figure out, what passes to // use for Clippy. - config.opts.debugging_opts.mir_opt_level = Some(0); + config.opts.unstable_opts.mir_opt_level = Some(0); } } From 5c3125eafd491633e95a2c41311ddf015e712031 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 22 Jun 2022 15:28:28 +0000 Subject: [PATCH 0553/1222] Introduce opaque type to hidden type projection --- clippy_utils/src/qualify_min_const_fn.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 3bf75bcbee83..9690ad277717 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -252,6 +252,7 @@ fn check_place<'tcx>(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &B } }, ProjectionElem::ConstantIndex { .. } + | ProjectionElem::OpaqueCast(..) | ProjectionElem::Downcast(..) | ProjectionElem::Subslice { .. } | ProjectionElem::Deref From 9d35c7cf03bd79b30e24afbf857445dbd4e2a061 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Sun, 17 Jul 2022 04:09:20 +0900 Subject: [PATCH 0554/1222] avoid some `Symbol` to `String` conversions --- clippy_lints/src/format.rs | 2 +- clippy_lints/src/inherent_to_string.rs | 2 +- clippy_lints/src/methods/unnecessary_to_owned.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 3084c70589fa..0aa085fc71bf 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat { then { let is_new_string = match value.kind { ExprKind::Binary(..) => true, - ExprKind::MethodCall(path, ..) => path.ident.name.as_str() == "to_string", + ExprKind::MethodCall(path, ..) => path.ident.name == sym::to_string, _ => false, }; let sugg = if format_args.format_string_span.contains(value.span) { diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index 39f68a8a1b48..694f646c707c 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString { if_chain! { // Check if item is a method, called to_string and has a parameter 'self' if let ImplItemKind::Fn(ref signature, _) = impl_item.kind; - if impl_item.ident.name.as_str() == "to_string"; + if impl_item.ident.name == sym::to_string; let decl = &signature.decl; if decl.implicit_self.has_implicit_self(); if decl.inputs.len() == 1; diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index b4c6bfb31ed1..b3276f1394ed 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -427,5 +427,5 @@ fn is_cow_into_owned(cx: &LateContext<'_>, method_name: Symbol, method_def_id: D /// Returns true if the named method is `ToString::to_string`. fn is_to_string(cx: &LateContext<'_>, method_name: Symbol, method_def_id: DefId) -> bool { - method_name.as_str() == "to_string" && is_diag_trait_item(cx, method_def_id, sym::ToString) + method_name == sym::to_string && is_diag_trait_item(cx, method_def_id, sym::ToString) } From ce113931a3da94ce3a71af41e91f089d2ca91cc9 Mon Sep 17 00:00:00 2001 From: Caio Date: Tue, 12 Jul 2022 15:36:59 -0300 Subject: [PATCH 0555/1222] Stabilize `let_chains` --- clippy_dev/src/lib.rs | 2 +- clippy_lints/src/lib.rs | 2 +- clippy_utils/src/lib.rs | 2 +- tests/ui/needless_late_init.fixed | 1 - tests/ui/needless_late_init.rs | 1 - tests/ui/needless_late_init.stderr | 32 +++++++++++++++--------------- 6 files changed, 19 insertions(+), 21 deletions(-) diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index 81e807cf10c7..fe69284ab10e 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(let_chains)] +#![cfg_attr(bootstrap, feature(let_chains))] #![feature(let_else)] #![feature(once_cell)] #![feature(rustc_private)] diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 172fdf8c8526..884baaea0292 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -4,7 +4,7 @@ #![feature(control_flow_enum)] #![feature(drain_filter)] #![feature(iter_intersperse)] -#![feature(let_chains)] +#![cfg_attr(bootstrap, feature(let_chains))] #![feature(let_else)] #![feature(lint_reasons)] #![feature(never_type)] diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 242d4315378e..0089e1b64006 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1,7 +1,7 @@ #![feature(box_patterns)] #![feature(control_flow_enum)] #![feature(let_else)] -#![feature(let_chains)] +#![cfg_attr(bootstrap, feature(let_chains))] #![feature(lint_reasons)] #![feature(once_cell)] #![feature(rustc_private)] diff --git a/tests/ui/needless_late_init.fixed b/tests/ui/needless_late_init.fixed index fee8e3030b80..4c98e1827bdb 100644 --- a/tests/ui/needless_late_init.fixed +++ b/tests/ui/needless_late_init.fixed @@ -1,5 +1,4 @@ // run-rustfix -#![feature(let_chains)] #![allow( unused, clippy::assign_op_pattern, diff --git a/tests/ui/needless_late_init.rs b/tests/ui/needless_late_init.rs index 402d9f9ef7f8..25e1e0214fb4 100644 --- a/tests/ui/needless_late_init.rs +++ b/tests/ui/needless_late_init.rs @@ -1,5 +1,4 @@ // run-rustfix -#![feature(let_chains)] #![allow( unused, clippy::assign_op_pattern, diff --git a/tests/ui/needless_late_init.stderr b/tests/ui/needless_late_init.stderr index 313cdbbeba18..97f0f7019a9d 100644 --- a/tests/ui/needless_late_init.stderr +++ b/tests/ui/needless_late_init.stderr @@ -1,5 +1,5 @@ error: unneeded late initialization - --> $DIR/needless_late_init.rs:23:5 + --> $DIR/needless_late_init.rs:22:5 | LL | let a; | ^^^^^^ created here @@ -13,7 +13,7 @@ LL | let a = "zero"; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:26:5 + --> $DIR/needless_late_init.rs:25:5 | LL | let b; | ^^^^^^ created here @@ -27,7 +27,7 @@ LL | let b = 1; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:27:5 + --> $DIR/needless_late_init.rs:26:5 | LL | let c; | ^^^^^^ created here @@ -41,7 +41,7 @@ LL | let c = 2; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:31:5 + --> $DIR/needless_late_init.rs:30:5 | LL | let d: usize; | ^^^^^^^^^^^^^ created here @@ -54,7 +54,7 @@ LL | let d: usize = 1; | ~~~~~~~~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:34:5 + --> $DIR/needless_late_init.rs:33:5 | LL | let e; | ^^^^^^ created here @@ -67,7 +67,7 @@ LL | let e = format!("{}", d); | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:39:5 + --> $DIR/needless_late_init.rs:38:5 | LL | let a; | ^^^^^^ @@ -88,7 +88,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:48:5 + --> $DIR/needless_late_init.rs:47:5 | LL | let b; | ^^^^^^ @@ -109,7 +109,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:55:5 + --> $DIR/needless_late_init.rs:54:5 | LL | let d; | ^^^^^^ @@ -130,7 +130,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:63:5 + --> $DIR/needless_late_init.rs:62:5 | LL | let e; | ^^^^^^ @@ -151,7 +151,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:70:5 + --> $DIR/needless_late_init.rs:69:5 | LL | let f; | ^^^^^^ @@ -167,7 +167,7 @@ LL + 1 => "three", | error: unneeded late initialization - --> $DIR/needless_late_init.rs:76:5 + --> $DIR/needless_late_init.rs:75:5 | LL | let g: usize; | ^^^^^^^^^^^^^ @@ -187,7 +187,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:84:5 + --> $DIR/needless_late_init.rs:83:5 | LL | let x; | ^^^^^^ created here @@ -201,7 +201,7 @@ LL | let x = 1; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:88:5 + --> $DIR/needless_late_init.rs:87:5 | LL | let x; | ^^^^^^ created here @@ -215,7 +215,7 @@ LL | let x = SignificantDrop; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:92:5 + --> $DIR/needless_late_init.rs:91:5 | LL | let x; | ^^^^^^ created here @@ -229,7 +229,7 @@ LL | let x = SignificantDrop; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:111:5 + --> $DIR/needless_late_init.rs:110:5 | LL | let a; | ^^^^^^ @@ -250,7 +250,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:128:5 + --> $DIR/needless_late_init.rs:127:5 | LL | let a; | ^^^^^^ From e0e794847f652354deded59bdf6efd8f96d1205d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 20 Jun 2022 19:25:52 -0700 Subject: [PATCH 0556/1222] Mention first and last macro in backtrace --- tests/ui/diverging_sub_expression.stderr | 2 +- tests/ui/fallible_impl_from.stderr | 6 +++--- tests/ui/issue-7447.stderr | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/ui/diverging_sub_expression.stderr b/tests/ui/diverging_sub_expression.stderr index c712a6a7e38e..9c91d935716d 100644 --- a/tests/ui/diverging_sub_expression.stderr +++ b/tests/ui/diverging_sub_expression.stderr @@ -36,7 +36,7 @@ error: sub-expression diverges LL | _ => true || panic!("boo"), | ^^^^^^^^^^^^^ | - = note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: sub-expression diverges --> $DIR/diverging_sub_expression.rs:38:26 diff --git a/tests/ui/fallible_impl_from.stderr b/tests/ui/fallible_impl_from.stderr index 4e0f08a1215c..d637dbce5d79 100644 --- a/tests/ui/fallible_impl_from.stderr +++ b/tests/ui/fallible_impl_from.stderr @@ -38,7 +38,7 @@ note: potential failure(s) | LL | panic!(); | ^^^^^^^^ - = note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: consider implementing `TryFrom` instead --> $DIR/fallible_impl_from.rs:35:1 @@ -65,7 +65,7 @@ LL | } else if s.parse::().unwrap() != 42 { | ^^^^^^^^^^^^^^^^^^^^^^^^^ LL | panic!("{:?}", s); | ^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: consider implementing `TryFrom` instead --> $DIR/fallible_impl_from.rs:53:1 @@ -87,7 +87,7 @@ LL | if s.parse::().ok().unwrap() != 42 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | panic!("{:?}", s); | ^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 4 previous errors diff --git a/tests/ui/issue-7447.stderr b/tests/ui/issue-7447.stderr index 463a48b24a32..8d8c29f13858 100644 --- a/tests/ui/issue-7447.stderr +++ b/tests/ui/issue-7447.stderr @@ -5,7 +5,7 @@ LL | byte_view(panic!()); | ^^^^^^^^ | = note: `-D clippy::diverging-sub-expression` implied by `-D warnings` - = note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: sub-expression diverges --> $DIR/issue-7447.rs:24:19 @@ -13,7 +13,7 @@ error: sub-expression diverges LL | group_entries(panic!()); | ^^^^^^^^ | - = note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors From 0b4cf83112e7fd454cc2301eb8b6b283bad801f7 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 20 Jul 2022 07:55:58 +0000 Subject: [PATCH 0557/1222] Revert "Rollup merge of #98582 - oli-obk:unconstrained_opaque_type, r=estebank" This reverts commit 6f8fb911ad504b77549cf3256a09465621beab9d, reversing changes made to 7210e46dc69a4b197a313d093fe145722c248b7d. --- clippy_utils/src/qualify_min_const_fn.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 9690ad277717..3bf75bcbee83 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -252,7 +252,6 @@ fn check_place<'tcx>(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &B } }, ProjectionElem::ConstantIndex { .. } - | ProjectionElem::OpaqueCast(..) | ProjectionElem::Downcast(..) | ProjectionElem::Subslice { .. } | ProjectionElem::Deref From 25366ca2152d76fea1568b45a55bece158815fe2 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 15 Jul 2022 05:37:32 +0000 Subject: [PATCH 0558/1222] Do not resolve associated const when there is no provided value --- tests/ui/crashes/ice-6252.stderr | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index a1e37e7317b2..638e4a548493 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -30,15 +30,7 @@ LL | const VAL: T; LL | impl TypeVal for Multiply where N: TypeVal {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation -error: constant expression depends on a generic parameter - --> $DIR/ice-6252.rs:13:9 - | -LL | [1; >::VAL]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0046, E0412. For more information about an error, try `rustc --explain E0046`. From 676f1886018b492e00f3e3073aab4a5b13ef4a3c Mon Sep 17 00:00:00 2001 From: Preston From Date: Sat, 16 Jul 2022 15:13:14 -0600 Subject: [PATCH 0559/1222] Generate correct suggestion with named arguments used positionally Address issue #99265 by checking each positionally used argument to see if the argument is named and adding a lint to use the name instead. This way, when named arguments are used positionally in a different order than their argument order, the suggested lint is correct. For example: ``` println!("{b} {}", a=1, b=2); ``` This will now generate the suggestion: ``` println!("{b} {a}", a=1, b=2); ``` Additionally, this check now also correctly replaces or inserts only where the positional argument is (or would be if implicit). Also, width and precision are replaced with their argument names when they exists. Since the issues were so closely related, this fix for issue #99265 also fixes issue #99266. Fixes #99265 Fixes #99266 --- clippy_lints/src/write.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 08b889475201..3a99d1b417fe 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -441,7 +441,7 @@ impl SimpleFormatArgs { }; match arg.position { - ArgumentIs(n) | ArgumentImplicitlyIs(n) => { + ArgumentIs(n, _) | ArgumentImplicitlyIs(n) => { if self.unnamed.len() <= n { // Use a dummy span to mark all unseen arguments. self.unnamed.resize_with(n, || vec![DUMMY_SP]); From c22641f7702938e30bfe2e5a0a94ead9e2740f20 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 6 Jun 2022 20:26:41 +0200 Subject: [PATCH 0560/1222] Clippy fallout. --- clippy_lints/src/lifetimes.rs | 78 +++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 083c437a293c..826353aafc06 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -9,12 +9,14 @@ use rustc_hir::intravisit::{ use rustc_hir::FnRetTy::Return; use rustc_hir::{ BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl, ImplItem, - ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, LifetimeParamKind, ParamName, PolyTraitRef, - PredicateOrigin, TraitBoundModifier, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate, + ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, ParamName, PolyTraitRef, PredicateOrigin, + TraitBoundModifier, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter as middle_nested_filter; +use rustc_middle::ty::TyCtxt; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::def_id::LocalDefId; use rustc_span::source_map::Span; use rustc_span::symbol::{kw, Ident, Symbol}; @@ -129,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes { enum RefLt { Unnamed, Static, - Named(Symbol), + Named(LocalDefId), } fn check_fn_inner<'tcx>( @@ -232,7 +234,7 @@ fn could_use_elision<'tcx>( // level of the current item. // check named LTs - let allowed_lts = allowed_lts_from(named_generics); + let allowed_lts = allowed_lts_from(cx.tcx, named_generics); // these will collect all the lifetimes for references in arg/return types let mut input_visitor = RefVisitor::new(cx); @@ -254,22 +256,6 @@ fn could_use_elision<'tcx>( return false; } - if allowed_lts - .intersection( - &input_visitor - .nested_elision_site_lts - .iter() - .chain(output_visitor.nested_elision_site_lts.iter()) - .cloned() - .filter(|v| matches!(v, RefLt::Named(_))) - .collect(), - ) - .next() - .is_some() - { - return false; - } - let input_lts = input_visitor.lts; let output_lts = output_visitor.lts; @@ -303,6 +289,31 @@ fn could_use_elision<'tcx>( } } + // check for higher-ranked trait bounds + if !input_visitor.nested_elision_site_lts.is_empty() || !output_visitor.nested_elision_site_lts.is_empty() { + let allowed_lts: FxHashSet<_> = allowed_lts + .iter() + .filter_map(|lt| match lt { + RefLt::Named(def_id) => Some(cx.tcx.item_name(def_id.to_def_id())), + _ => None, + }) + .collect(); + for lt in input_visitor.nested_elision_site_lts { + if let RefLt::Named(def_id) = lt { + if allowed_lts.contains(&cx.tcx.item_name(def_id.to_def_id())) { + return false; + } + } + } + for lt in output_visitor.nested_elision_site_lts { + if let RefLt::Named(def_id) = lt { + if allowed_lts.contains(&cx.tcx.item_name(def_id.to_def_id())) { + return false; + } + } + } + } + // no input lifetimes? easy case! if input_lts.is_empty() { false @@ -335,14 +346,11 @@ fn could_use_elision<'tcx>( } } -fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxHashSet { +fn allowed_lts_from(tcx: TyCtxt<'_>, named_generics: &[GenericParam<'_>]) -> FxHashSet { let mut allowed_lts = FxHashSet::default(); for par in named_generics.iter() { - if let GenericParamKind::Lifetime { - kind: LifetimeParamKind::Explicit, - } = par.kind - { - allowed_lts.insert(RefLt::Named(par.name.ident().name)); + if let GenericParamKind::Lifetime { .. } = par.kind { + allowed_lts.insert(RefLt::Named(tcx.hir().local_def_id(par.hir_id))); } } allowed_lts.insert(RefLt::Unnamed); @@ -385,8 +393,10 @@ impl<'a, 'tcx> RefVisitor<'a, 'tcx> { self.lts.push(RefLt::Unnamed); } else if lt.is_elided() { self.lts.push(RefLt::Unnamed); + } else if let LifetimeName::Param(def_id, _) = lt.name { + self.lts.push(RefLt::Named(def_id)); } else { - self.lts.push(RefLt::Named(lt.name.ident().name)); + self.lts.push(RefLt::Unnamed); } } else { self.lts.push(RefLt::Unnamed); @@ -434,10 +444,15 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { TyKind::OpaqueDef(item, bounds) => { let map = self.cx.tcx.hir(); let item = map.item(item); + let len = self.lts.len(); walk_item(self, item); - walk_ty(self, ty); + self.lts.truncate(len); self.lts.extend(bounds.iter().filter_map(|bound| match bound { - GenericArg::Lifetime(l) => Some(RefLt::Named(l.name.ident().name)), + GenericArg::Lifetime(l) => Some(if let LifetimeName::Param(def_id, _) = l.name { + RefLt::Named(def_id) + } else { + RefLt::Unnamed + }), _ => None, })); }, @@ -456,9 +471,8 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { } return; }, - _ => (), + _ => walk_ty(self, ty), } - walk_ty(self, ty); } } @@ -477,7 +491,7 @@ fn has_where_lifetimes<'tcx>(cx: &LateContext<'tcx>, generics: &'tcx Generics<'_ return true; } // if the bounds define new lifetimes, they are fine to occur - let allowed_lts = allowed_lts_from(pred.bound_generic_params); + let allowed_lts = allowed_lts_from(cx.tcx, pred.bound_generic_params); // now walk the bounds for bound in pred.bounds.iter() { walk_param_bound(&mut visitor, bound); From 6f64654404593bf9c98d5d9cdd302fcc23c959ca Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 13 Jun 2022 08:22:06 +0200 Subject: [PATCH 0561/1222] Replace LifetimeRes::Anonymous by LifetimeRes::Infer. --- clippy_lints/src/manual_async_fn.rs | 2 +- clippy_lints/src/ptr.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 945880d21471..a0ca7e6ff1e2 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -166,7 +166,7 @@ fn captures_all_lifetimes(inputs: &[Ty<'_>], output_lifetimes: &[LifetimeName]) // - There's only one output lifetime bound using `+ '_` // - All input lifetimes are explicitly bound to the output input_lifetimes.is_empty() - || (output_lifetimes.len() == 1 && matches!(output_lifetimes[0], LifetimeName::Underscore)) + || (output_lifetimes.len() == 1 && matches!(output_lifetimes[0], LifetimeName::Infer)) || input_lifetimes .iter() .all(|in_lt| output_lifetimes.iter().any(|out_lt| in_lt == out_lt)) diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 8534d8a29f10..3c5ea2d94144 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -351,7 +351,7 @@ impl fmt::Display for RefPrefix { name.fmt(f)?; f.write_char(' ')?; }, - LifetimeName::Underscore => f.write_str("'_ ")?, + LifetimeName::Infer => f.write_str("'_ ")?, LifetimeName::Static => f.write_str("'static ")?, _ => (), } From c01a24d3521b4a046a685d778f22084827e6d201 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 13 Jun 2022 11:53:31 +0200 Subject: [PATCH 0562/1222] Clippy fallout. --- clippy_lints/src/lifetimes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 826353aafc06..3f69cc203883 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -615,7 +615,7 @@ struct BodyLifetimeChecker { impl<'tcx> Visitor<'tcx> for BodyLifetimeChecker { // for lifetimes as parameters of generics fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { - if lifetime.name.ident().name != kw::Empty && lifetime.name.ident().name != kw::StaticLifetime { + if lifetime.name.ident().name != kw::UnderscoreLifetime && lifetime.name.ident().name != kw::StaticLifetime { self.lifetimes_used_in_body = true; } } From 89664d06d88e2cf06b81a5f0154dafcef6a603c8 Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 25 Jul 2022 13:02:39 +0100 Subject: [PATCH 0563/1222] lint: add bad opt access internal lint Some command-line options accessible through `sess.opts` are best accessed through wrapper functions on `Session`, `TyCtxt` or otherwise, rather than through field access on the option struct in the `Session`. Adds a new lint which triggers on those options that should be accessed through a wrapper function so that this is prohibited. Options are annotated with a new attribute `rustc_lint_opt_deny_field_access` which can specify the error message (i.e. "use this other function instead") to be emitted. A simpler alternative would be to simply rename the options in the option type so that it is clear they should not be used, however this doesn't prevent uses, just discourages them. Another alternative would be to make the option fields private, and adding accessor functions on the option types, however the wrapper functions sometimes rely on additional state from `Session` or `TyCtxt` which wouldn't be available in an function on the option type, so the accessor would simply make the field available and its use would be discouraged too. Signed-off-by: David Wood --- src/driver.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/driver.rs b/src/driver.rs index c219c7de830e..c1ec2bd5bd66 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -94,6 +94,8 @@ struct ClippyCallbacks { } impl rustc_driver::Callbacks for ClippyCallbacks { + // JUSTIFICATION: necessary in clippy driver to set `mir_opt_level` + #[cfg_attr(not(bootstrap), allow(rustc::bad_opt_access))] fn config(&mut self, config: &mut interface::Config) { let previous = config.register_lints.take(); let clippy_args_var = self.clippy_args_var.take(); From 68523899e8f9125f001b56db5edead9d791c188d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 28 Jul 2022 10:31:04 +1000 Subject: [PATCH 0564/1222] Remove `TreeAndSpacing`. A `TokenStream` contains a `Lrc>`. But this is not quite right. `Spacing` makes sense for `TokenTree::Token`, but does not make sense for `TokenTree::Delimited`, because a `TokenTree::Delimited` cannot be joined with another `TokenTree`. This commit fixes this problem, by adding `Spacing` to `TokenTree::Token`, changing `TokenStream` to contain a `Lrc>`, and removing the `TreeAndSpacing` typedef. The commit removes these two impls: - `impl From for TokenStream` - `impl From for TreeAndSpacing` These were useful, but also resulted in code with many `.into()` calls that was hard to read, particularly for anyone not highly familiar with the relevant types. This commit makes some other changes to compensate: - `TokenTree::token()` becomes `TokenTree::token_{alone,joint}()`. - `TokenStream::token_{alone,joint}()` are added. - `TokenStream::delimited` is added. This results in things like this: ```rust TokenTree::token(token::Semi, stmt.span).into() ``` changing to this: ```rust TokenStream::token_alone(token::Semi, stmt.span) ``` This makes the type of the result, and its spacing, clearer. These changes also simplifies `Cursor` and `CursorRef`, because they no longer need to distinguish between `next` and `next_with_spacing`. --- clippy_lints/src/crate_in_macro_def.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/crate_in_macro_def.rs b/clippy_lints/src/crate_in_macro_def.rs index f6ec8fe7edc1..454ec23388af 100644 --- a/clippy_lints/src/crate_in_macro_def.rs +++ b/clippy_lints/src/crate_in_macro_def.rs @@ -110,14 +110,14 @@ fn contains_unhygienic_crate_reference(tts: &TokenStream) -> Option { fn is_crate_keyword(tt: &TokenTree) -> Option { if_chain! { - if let TokenTree::Token(Token { kind: TokenKind::Ident(symbol, _), span }) = tt; + if let TokenTree::Token(Token { kind: TokenKind::Ident(symbol, _), span }, _) = tt; if symbol.as_str() == "crate"; then { Some(*span) } else { None } } } fn is_token(tt: &TokenTree, kind: &TokenKind) -> bool { - if let TokenTree::Token(Token { kind: other, .. }) = tt { + if let TokenTree::Token(Token { kind: other, .. }, _) = tt { kind == other } else { false From c0f68d98710c78addcf11ecaacbd02475b6bdaed Mon Sep 17 00:00:00 2001 From: Miguel Guarniz Date: Fri, 15 Jul 2022 23:13:04 -0400 Subject: [PATCH 0565/1222] Change maybe_body_owned_by to take local def id Signed-off-by: Miguel Guarniz --- clippy_lints/src/utils/author.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index bbb04c9945a0..59e07313f549 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -138,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for Author { fn check_item(cx: &LateContext<'_>, hir_id: HirId) { let hir = cx.tcx.hir(); - if let Some(body_id) = hir.maybe_body_owned_by(hir_id) { + if let Some(body_id) = hir.maybe_body_owned_by(hir.local_def_id(hir_id)) { check_node(cx, hir_id, |v| { v.expr(&v.bind("expr", &hir.body(body_id).value)); }); From 9c3d017754db0ef2bc8508b262bfc28242872883 Mon Sep 17 00:00:00 2001 From: Miguel Guarniz Date: Tue, 19 Jul 2022 17:06:52 -0400 Subject: [PATCH 0566/1222] Rename local_did to def_id Signed-off-by: Miguel Guarniz --- clippy_lints/src/utils/author.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 59e07313f549..c0726868f77e 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -138,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for Author { fn check_item(cx: &LateContext<'_>, hir_id: HirId) { let hir = cx.tcx.hir(); - if let Some(body_id) = hir.maybe_body_owned_by(hir.local_def_id(hir_id)) { + if let Some(body_id) = hir.maybe_body_owned_by(hir_id.expect_owner()) { check_node(cx, hir_id, |v| { v.expr(&v.bind("expr", &hir.body(body_id).value)); }); From 81a2b811ad7e4ab4edc087b6688e05412468de2a Mon Sep 17 00:00:00 2001 From: Miguel Guarniz Date: Tue, 19 Jul 2022 17:47:49 -0400 Subject: [PATCH 0567/1222] Change enclosing_body_owner to return LocalDefId Signed-off-by: Miguel Guarniz --- clippy_utils/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 34a1cdaf1d52..50bb008098dc 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1353,7 +1353,7 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool if is_integer_literal(e, value) { return true; } - let enclosing_body = cx.tcx.hir().local_def_id(cx.tcx.hir().enclosing_body_owner(e.hir_id)); + let enclosing_body = cx.tcx.hir().enclosing_body_owner(e.hir_id); if let Some((Constant::Int(v), _)) = constant(cx, cx.tcx.typeck(enclosing_body), e) { return value == v; } From 8761f682e341da4e93ab46e1adc34bca89514dee Mon Sep 17 00:00:00 2001 From: Miguel Guarniz Date: Tue, 19 Jul 2022 22:51:52 -0400 Subject: [PATCH 0568/1222] Avoid ICE when fetching LocalDefId Signed-off-by: Miguel Guarniz --- clippy_lints/src/methods/suspicious_map.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/methods/suspicious_map.rs b/clippy_lints/src/methods/suspicious_map.rs index 18ded291915e..9c3375bf35e7 100644 --- a/clippy_lints/src/methods/suspicious_map.rs +++ b/clippy_lints/src/methods/suspicious_map.rs @@ -12,7 +12,8 @@ pub fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, count_recv: &hi if_chain! { if is_trait_method(cx, count_recv, sym::Iterator); let closure = expr_or_init(cx, map_arg); - if let Some(body_id) = cx.tcx.hir().maybe_body_owned_by(closure.hir_id); + if let Some(def_id) = cx.tcx.hir().opt_local_def_id(closure.hir_id); + if let Some(body_id) = cx.tcx.hir().maybe_body_owned_by(def_id); let closure_body = cx.tcx.hir().body(body_id); if !cx.typeck_results().expr_ty(&closure_body.value).is_unit(); then { From bf47c484dbae3bdcc7ed0042a13c7f281e8bbc10 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Tue, 12 Jul 2022 09:10:22 -0500 Subject: [PATCH 0569/1222] Use LocalDefId for closures more --- clippy_utils/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 34a1cdaf1d52..018059facbd1 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -968,7 +968,7 @@ pub fn can_move_expr_to_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<' } }, ExprKind::Closure { .. } => { - let closure_id = self.cx.tcx.hir().local_def_id(e.hir_id).to_def_id(); + let closure_id = self.cx.tcx.hir().local_def_id(e.hir_id); for capture in self.cx.typeck_results().closure_min_captures_flattened(closure_id) { let local_id = match capture.place.base { PlaceBase::Local(id) => id, From 56110ff407226379b37266ca85043891184cc8c3 Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Sun, 31 Jul 2022 15:11:00 +0000 Subject: [PATCH 0570/1222] Always include a position span in rustc_parse_format::Argument --- clippy_lints/src/write.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 3a99d1b417fe..32718200c0b3 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -441,7 +441,7 @@ impl SimpleFormatArgs { }; match arg.position { - ArgumentIs(n, _) | ArgumentImplicitlyIs(n) => { + ArgumentIs(n) | ArgumentImplicitlyIs(n) => { if self.unnamed.len() <= n { // Use a dummy span to mark all unseen arguments. self.unnamed.resize_with(n, || vec![DUMMY_SP]); @@ -462,7 +462,7 @@ impl SimpleFormatArgs { } } }, - ArgumentNamed(n, _) => { + ArgumentNamed(n) => { let n = Symbol::intern(n); if let Some(x) = self.named.iter_mut().find(|x| x.0 == n) { match x.1.as_slice() { From 3681a6a6c4bdf0acb91e469cb0873ba0669fa639 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 27 Jul 2022 13:59:30 +1000 Subject: [PATCH 0571/1222] Shrink `Token`. From 72 bytes to 12 bytes (on x86-64). There are two parts to this: - Changing various source code offsets from 64-bit to 32-bit. This is not a problem because the rest of rustc also uses 32-bit source code offsets. This means `Token` is no longer `Copy` but this causes no problems. - Removing the `RawStrError` from `LiteralKind`. Raw string literal invalidity is now indicated by a `None` value within `RawStr`/`RawByteStr`, and the new `validate_raw_str` function can be used to re-lex an invalid raw string literal to get the `RawStrError`. There is one very small change in behaviour. Previously, if a raw string literal matched both the `InvalidStarter` and `TooManyHashes` cases, the latter would override the former. This has now changed, because `raw_double_quoted_string` now uses `?` and so returns immediately upon detecting the `InvalidStarter` case. I think this is a slight improvement to report the earlier-detected error, and it explains the change in the `test_too_many_hashes` test. The commit also removes a couple of comments that refer to #77629 and say that the size of these types don't affect performance. These comments are wrong, though the performance effect is small. --- clippy_lints/src/matches/mod.rs | 2 +- clippy_lints/src/undocumented_unsafe_blocks.rs | 2 +- clippy_utils/src/hir_utils.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/matches/mod.rs b/clippy_lints/src/matches/mod.rs index b638f2716028..e9e13aece18f 100644 --- a/clippy_lints/src/matches/mod.rs +++ b/clippy_lints/src/matches/mod.rs @@ -1112,7 +1112,7 @@ fn span_contains_cfg(cx: &LateContext<'_>, s: Span) -> bool { let mut pos = 0usize; let mut iter = tokenize(&snip).map(|t| { let start = pos; - pos += t.len; + pos += t.len as usize; (t.kind, start..pos) }); diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index 04f16fd2161c..d2e675a783ea 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -345,7 +345,7 @@ fn text_has_safety_comment(src: &str, line_starts: &[BytePos], offset: usize) -> if line.starts_with("/*") { let src = src[line_start..line_starts.last().unwrap().to_usize() - offset].trim_start(); let mut tokens = tokenize(src); - return src[..tokens.next().unwrap().len] + return src[..tokens.next().unwrap().len as usize] .to_ascii_uppercase() .contains("SAFETY:") && tokens.all(|t| t.kind == TokenKind::Whitespace); diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index eaf260ddfb83..1834e2a2de87 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -141,7 +141,7 @@ impl HirEqInterExpr<'_, '_, '_> { let mut left_pos = 0; let left = tokenize(&left) .map(|t| { - let end = left_pos + t.len; + let end = left_pos + t.len as usize; let s = &left[left_pos..end]; left_pos = end; (t, s) @@ -156,7 +156,7 @@ impl HirEqInterExpr<'_, '_, '_> { let mut right_pos = 0; let right = tokenize(&right) .map(|t| { - let end = right_pos + t.len; + let end = right_pos + t.len as usize; let s = &right[right_pos..end]; right_pos = end; (t, s) From 153623d6d53be893288b849eda4644a25ab7cc3e Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 12 Mar 2022 19:36:11 +0100 Subject: [PATCH 0572/1222] Store associated item defaultness in impl_defaultness. --- clippy_lints/src/missing_inline.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 0d9532991898..9e14ccd34334 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { match tit_.kind { hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => {}, hir::TraitItemKind::Fn(..) => { - if tit.defaultness.has_value() { + if cx.tcx.impl_defaultness(tit.id.def_id).has_value() { // trait method with default body needs inline in case // an impl is not provided let desc = "a default trait method"; From 7bfa9b1344675dc5434fd804f2bb611840cdd623 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 13 Mar 2022 00:52:25 +0100 Subject: [PATCH 0573/1222] Remove DefId from AssocItemContainer. --- clippy_lints/src/eta_reduction.rs | 8 +++++--- clippy_lints/src/missing_doc.rs | 15 +++++++-------- clippy_lints/src/missing_inline.rs | 8 +++++--- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 80c84014bfde..4f9ff97f1fd1 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -220,9 +220,11 @@ fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure_ty: Ty<'tcx>, call_ty: Ty<'tc } fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: DefId) -> String { - match cx.tcx.associated_item(method_def_id).container { - ty::TraitContainer(def_id) => cx.tcx.def_path_str(def_id), - ty::ImplContainer(def_id) => { + let assoc_item = cx.tcx.associated_item(method_def_id); + let def_id = assoc_item.container_id(cx.tcx); + match assoc_item.container { + ty::TraitContainer => cx.tcx.def_path_str(def_id), + ty::ImplContainer => { let ty = cx.tcx.type_of(def_id); match ty.kind() { ty::Adt(adt, _) => cx.tcx.def_path_str(adt.did()), diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index a20377f320b2..88ba002927a9 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -10,7 +10,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_ast::ast; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::ty::{self, DefIdTree}; +use rustc_middle::ty::DefIdTree; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::def_id::CRATE_DEF_ID; use rustc_span::source_map::Span; @@ -153,13 +153,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { // If the method is an impl for a trait, don't doc. - match cx.tcx.associated_item(impl_item.def_id).container { - ty::TraitContainer(_) => return, - ty::ImplContainer(cid) => { - if cx.tcx.impl_trait_ref(cid).is_some() { - return; - } - }, + if let Some(cid) = cx.tcx.associated_item(impl_item.def_id).impl_container(cx.tcx) { + if cx.tcx.impl_trait_ref(cid).is_some() { + return; + } + } else { + return; } let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id()); diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 9e14ccd34334..07bc2ca5d3cd 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -151,9 +151,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) => return, }; - let trait_def_id = match cx.tcx.associated_item(impl_item.def_id).container { - TraitContainer(cid) => Some(cid), - ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id), + let assoc_item = cx.tcx.associated_item(impl_item.def_id); + let container_id = assoc_item.container_id(cx.tcx); + let trait_def_id = match assoc_item.container { + TraitContainer => Some(container_id), + ImplContainer => cx.tcx.impl_trait_ref(container_id).map(|t| t.def_id), }; if let Some(trait_def_id) = trait_def_id { From b8f3e0a4927e76056e8c9cbfe415f09d88666771 Mon Sep 17 00:00:00 2001 From: tabokie Date: Mon, 1 Aug 2022 13:22:16 +0800 Subject: [PATCH 0574/1222] move [`assertions_on_result_states`] to restriction Signed-off-by: tabokie --- clippy_lints/src/assertions_on_result_states.rs | 5 ++++- clippy_lints/src/lib.register_all.rs | 1 - clippy_lints/src/lib.register_restriction.rs | 1 + clippy_lints/src/lib.register_style.rs | 1 - 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/assertions_on_result_states.rs b/clippy_lints/src/assertions_on_result_states.rs index b6affdee5236..4caab6230909 100644 --- a/clippy_lints/src/assertions_on_result_states.rs +++ b/clippy_lints/src/assertions_on_result_states.rs @@ -19,6 +19,9 @@ declare_clippy_lint! { /// ### Why is this bad? /// An assertion failure cannot output an useful message of the error. /// + /// ### Known problems + /// The suggested replacement decreases the readability of code and log output. + /// /// ### Example /// ```rust,ignore /// # let r = Ok::<_, ()>(()); @@ -28,7 +31,7 @@ declare_clippy_lint! { /// ``` #[clippy::version = "1.64.0"] pub ASSERTIONS_ON_RESULT_STATES, - style, + restriction, "`assert!(r.is_ok())`/`assert!(r.is_err())` gives worse error message than directly calling `r.unwrap()`/`r.unwrap_err()`" } diff --git a/clippy_lints/src/lib.register_all.rs b/clippy_lints/src/lib.register_all.rs index 5be1c417bf8f..0ba9b7ae7e58 100644 --- a/clippy_lints/src/lib.register_all.rs +++ b/clippy_lints/src/lib.register_all.rs @@ -6,7 +6,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![ LintId::of(almost_complete_letter_range::ALMOST_COMPLETE_LETTER_RANGE), LintId::of(approx_const::APPROX_CONSTANT), LintId::of(assertions_on_constants::ASSERTIONS_ON_CONSTANTS), - LintId::of(assertions_on_result_states::ASSERTIONS_ON_RESULT_STATES), LintId::of(async_yields_async::ASYNC_YIELDS_ASYNC), LintId::of(attrs::BLANKET_CLIPPY_RESTRICTION_LINTS), LintId::of(attrs::DEPRECATED_CFG_ATTR), diff --git a/clippy_lints/src/lib.register_restriction.rs b/clippy_lints/src/lib.register_restriction.rs index 495abd8387e8..a7339ef27217 100644 --- a/clippy_lints/src/lib.register_restriction.rs +++ b/clippy_lints/src/lib.register_restriction.rs @@ -7,6 +7,7 @@ store.register_group(true, "clippy::restriction", Some("clippy_restriction"), ve LintId::of(as_underscore::AS_UNDERSCORE), LintId::of(asm_syntax::INLINE_ASM_X86_ATT_SYNTAX), LintId::of(asm_syntax::INLINE_ASM_X86_INTEL_SYNTAX), + LintId::of(assertions_on_result_states::ASSERTIONS_ON_RESULT_STATES), LintId::of(attrs::ALLOW_ATTRIBUTES_WITHOUT_REASON), LintId::of(casts::FN_TO_NUMERIC_CAST_ANY), LintId::of(create_dir::CREATE_DIR), diff --git a/clippy_lints/src/lib.register_style.rs b/clippy_lints/src/lib.register_style.rs index e029a5235e72..e95bab1d0454 100644 --- a/clippy_lints/src/lib.register_style.rs +++ b/clippy_lints/src/lib.register_style.rs @@ -4,7 +4,6 @@ store.register_group(true, "clippy::style", Some("clippy_style"), vec![ LintId::of(assertions_on_constants::ASSERTIONS_ON_CONSTANTS), - LintId::of(assertions_on_result_states::ASSERTIONS_ON_RESULT_STATES), LintId::of(blacklisted_name::BLACKLISTED_NAME), LintId::of(blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS), LintId::of(bool_assert_comparison::BOOL_ASSERT_COMPARISON), From f1f92a99461ea9e46451c44e1030be0ee9ae6dc6 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Mon, 25 Jul 2022 22:36:03 +0200 Subject: [PATCH 0575/1222] Warn about dead tuple struct fields --- .../auxiliary/helper.rs | 1 + tests/ui/format.fixed | 1 + tests/ui/format.rs | 1 + tests/ui/format.stderr | 38 +++++++++---------- tests/ui/from_iter_instead_of_collect.fixed | 2 +- tests/ui/from_iter_instead_of_collect.rs | 2 +- tests/ui/must_use_candidates.fixed | 2 +- tests/ui/must_use_candidates.rs | 2 +- tests/ui/numbered_fields.fixed | 1 + tests/ui/numbered_fields.rs | 1 + tests/ui/numbered_fields.stderr | 4 +- tests/ui/option_if_let_else.fixed | 1 + tests/ui/option_if_let_else.rs | 1 + tests/ui/option_if_let_else.stderr | 30 +++++++-------- tests/ui/unreadable_literal.fixed | 1 + tests/ui/unreadable_literal.rs | 1 + tests/ui/unreadable_literal.stderr | 22 +++++------ 17 files changed, 60 insertions(+), 51 deletions(-) diff --git a/tests/ui/borrow_interior_mutable_const/auxiliary/helper.rs b/tests/ui/borrow_interior_mutable_const/auxiliary/helper.rs index 2289f7875f04..f13733af3d0d 100644 --- a/tests/ui/borrow_interior_mutable_const/auxiliary/helper.rs +++ b/tests/ui/borrow_interior_mutable_const/auxiliary/helper.rs @@ -2,6 +2,7 @@ // As the most common case is the `http` crate, it replicates `http::HeadewrName`'s structure. #![allow(clippy::declare_interior_mutable_const)] +#![allow(unused_tuple_struct_fields)] use std::sync::atomic::AtomicUsize; diff --git a/tests/ui/format.fixed b/tests/ui/format.fixed index f4db2d20c713..6b754f3bd710 100644 --- a/tests/ui/format.fixed +++ b/tests/ui/format.fixed @@ -1,6 +1,7 @@ // run-rustfix #![allow( + unused_tuple_struct_fields, clippy::print_literal, clippy::redundant_clone, clippy::to_string_in_format_args, diff --git a/tests/ui/format.rs b/tests/ui/format.rs index bf687cb1e96c..ca9826b356ec 100644 --- a/tests/ui/format.rs +++ b/tests/ui/format.rs @@ -1,6 +1,7 @@ // run-rustfix #![allow( + unused_tuple_struct_fields, clippy::print_literal, clippy::redundant_clone, clippy::to_string_in_format_args, diff --git a/tests/ui/format.stderr b/tests/ui/format.stderr index a0f8e7d19379..6c35caeb034d 100644 --- a/tests/ui/format.stderr +++ b/tests/ui/format.stderr @@ -1,5 +1,5 @@ error: useless use of `format!` - --> $DIR/format.rs:18:5 + --> $DIR/format.rs:19:5 | LL | format!("foo"); | ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` @@ -7,19 +7,19 @@ LL | format!("foo"); = note: `-D clippy::useless-format` implied by `-D warnings` error: useless use of `format!` - --> $DIR/format.rs:19:5 + --> $DIR/format.rs:20:5 | LL | format!("{{}}"); | ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{}".to_string()` error: useless use of `format!` - --> $DIR/format.rs:20:5 + --> $DIR/format.rs:21:5 | LL | format!("{{}} abc {{}}"); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string()` error: useless use of `format!` - --> $DIR/format.rs:21:5 + --> $DIR/format.rs:22:5 | LL | / format!( LL | | r##"foo {{}} @@ -34,91 +34,91 @@ LL ~ " bar"##.to_string(); | error: useless use of `format!` - --> $DIR/format.rs:26:13 + --> $DIR/format.rs:27:13 | LL | let _ = format!(""); | ^^^^^^^^^^^ help: consider using `String::new()`: `String::new()` error: useless use of `format!` - --> $DIR/format.rs:28:5 + --> $DIR/format.rs:29:5 | LL | format!("{}", "foo"); | ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` error: useless use of `format!` - --> $DIR/format.rs:32:5 + --> $DIR/format.rs:33:5 | LL | format!("{:+}", "foo"); // Warn when the format makes no difference. | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` error: useless use of `format!` - --> $DIR/format.rs:33:5 + --> $DIR/format.rs:34:5 | LL | format!("{:<}", "foo"); // Warn when the format makes no difference. | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` error: useless use of `format!` - --> $DIR/format.rs:38:5 + --> $DIR/format.rs:39:5 | LL | format!("{}", arg); | ^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()` error: useless use of `format!` - --> $DIR/format.rs:42:5 + --> $DIR/format.rs:43:5 | LL | format!("{:+}", arg); // Warn when the format makes no difference. | ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()` error: useless use of `format!` - --> $DIR/format.rs:43:5 + --> $DIR/format.rs:44:5 | LL | format!("{:<}", arg); // Warn when the format makes no difference. | ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()` error: useless use of `format!` - --> $DIR/format.rs:70:5 + --> $DIR/format.rs:71:5 | LL | format!("{}", 42.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string()` error: useless use of `format!` - --> $DIR/format.rs:72:5 + --> $DIR/format.rs:73:5 | LL | format!("{}", x.display().to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string()` error: useless use of `format!` - --> $DIR/format.rs:76:18 + --> $DIR/format.rs:77:18 | LL | let _ = Some(format!("{}", a + "bar")); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `a + "bar"` error: useless use of `format!` - --> $DIR/format.rs:80:22 + --> $DIR/format.rs:81:22 | LL | let _s: String = format!("{}", &*v.join("/n")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `(&*v.join("/n")).to_string()` error: useless use of `format!` - --> $DIR/format.rs:86:13 + --> $DIR/format.rs:87:13 | LL | let _ = format!("{x}"); | ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()` error: useless use of `format!` - --> $DIR/format.rs:88:13 + --> $DIR/format.rs:89:13 | LL | let _ = format!("{y}", y = x); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()` error: useless use of `format!` - --> $DIR/format.rs:92:13 + --> $DIR/format.rs:93:13 | LL | let _ = format!("{abc}"); | ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `abc.to_string()` error: useless use of `format!` - --> $DIR/format.rs:94:13 + --> $DIR/format.rs:95:13 | LL | let _ = format!("{xx}"); | ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `xx.to_string()` diff --git a/tests/ui/from_iter_instead_of_collect.fixed b/tests/ui/from_iter_instead_of_collect.fixed index 403c3b3e4438..48f8093311cb 100644 --- a/tests/ui/from_iter_instead_of_collect.fixed +++ b/tests/ui/from_iter_instead_of_collect.fixed @@ -1,7 +1,7 @@ // run-rustfix #![warn(clippy::from_iter_instead_of_collect)] -#![allow(unused_imports)] +#![allow(unused_imports, unused_tuple_struct_fields)] use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque}; diff --git a/tests/ui/from_iter_instead_of_collect.rs b/tests/ui/from_iter_instead_of_collect.rs index fefc7b01a65b..ebe0ad278be3 100644 --- a/tests/ui/from_iter_instead_of_collect.rs +++ b/tests/ui/from_iter_instead_of_collect.rs @@ -1,7 +1,7 @@ // run-rustfix #![warn(clippy::from_iter_instead_of_collect)] -#![allow(unused_imports)] +#![allow(unused_imports, unused_tuple_struct_fields)] use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque}; diff --git a/tests/ui/must_use_candidates.fixed b/tests/ui/must_use_candidates.fixed index 9556f6f82cc6..04a74a009e09 100644 --- a/tests/ui/must_use_candidates.fixed +++ b/tests/ui/must_use_candidates.fixed @@ -1,6 +1,6 @@ // run-rustfix #![feature(never_type)] -#![allow(unused_mut, clippy::redundant_allocation)] +#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)] #![warn(clippy::must_use_candidate)] use std::rc::Rc; use std::sync::atomic::{AtomicBool, Ordering}; diff --git a/tests/ui/must_use_candidates.rs b/tests/ui/must_use_candidates.rs index 373242201710..f04122f4eeab 100644 --- a/tests/ui/must_use_candidates.rs +++ b/tests/ui/must_use_candidates.rs @@ -1,6 +1,6 @@ // run-rustfix #![feature(never_type)] -#![allow(unused_mut, clippy::redundant_allocation)] +#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)] #![warn(clippy::must_use_candidate)] use std::rc::Rc; use std::sync::atomic::{AtomicBool, Ordering}; diff --git a/tests/ui/numbered_fields.fixed b/tests/ui/numbered_fields.fixed index 3710b3e9c81e..68c987eb4c67 100644 --- a/tests/ui/numbered_fields.fixed +++ b/tests/ui/numbered_fields.fixed @@ -1,5 +1,6 @@ //run-rustfix #![warn(clippy::init_numbered_fields)] +#![allow(unused_tuple_struct_fields)] #[derive(Default)] struct TupleStruct(u32, u32, u8); diff --git a/tests/ui/numbered_fields.rs b/tests/ui/numbered_fields.rs index 2af84bc0642a..2ef4fb4de537 100644 --- a/tests/ui/numbered_fields.rs +++ b/tests/ui/numbered_fields.rs @@ -1,5 +1,6 @@ //run-rustfix #![warn(clippy::init_numbered_fields)] +#![allow(unused_tuple_struct_fields)] #[derive(Default)] struct TupleStruct(u32, u32, u8); diff --git a/tests/ui/numbered_fields.stderr b/tests/ui/numbered_fields.stderr index 01691c8b141e..60c0d7898063 100644 --- a/tests/ui/numbered_fields.stderr +++ b/tests/ui/numbered_fields.stderr @@ -1,5 +1,5 @@ error: used a field initializer for a tuple struct - --> $DIR/numbered_fields.rs:18:13 + --> $DIR/numbered_fields.rs:19:13 | LL | let _ = TupleStruct { | _____________^ @@ -12,7 +12,7 @@ LL | | }; = note: `-D clippy::init-numbered-fields` implied by `-D warnings` error: used a field initializer for a tuple struct - --> $DIR/numbered_fields.rs:25:13 + --> $DIR/numbered_fields.rs:26:13 | LL | let _ = TupleStruct { | _____________^ diff --git a/tests/ui/option_if_let_else.fixed b/tests/ui/option_if_let_else.fixed index e12e13a57f1f..b6d5e106f057 100644 --- a/tests/ui/option_if_let_else.fixed +++ b/tests/ui/option_if_let_else.fixed @@ -1,6 +1,7 @@ // run-rustfix #![warn(clippy::option_if_let_else)] #![allow( + unused_tuple_struct_fields, clippy::redundant_closure, clippy::ref_option_ref, clippy::equatable_if_let, diff --git a/tests/ui/option_if_let_else.rs b/tests/ui/option_if_let_else.rs index b5206fc26a9e..35bae1593435 100644 --- a/tests/ui/option_if_let_else.rs +++ b/tests/ui/option_if_let_else.rs @@ -1,6 +1,7 @@ // run-rustfix #![warn(clippy::option_if_let_else)] #![allow( + unused_tuple_struct_fields, clippy::redundant_closure, clippy::ref_option_ref, clippy::equatable_if_let, diff --git a/tests/ui/option_if_let_else.stderr b/tests/ui/option_if_let_else.stderr index 40aef977b989..daba606004e1 100644 --- a/tests/ui/option_if_let_else.stderr +++ b/tests/ui/option_if_let_else.stderr @@ -1,5 +1,5 @@ error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:11:5 + --> $DIR/option_if_let_else.rs:12:5 | LL | / if let Some(x) = string { LL | | (true, x) @@ -11,19 +11,19 @@ LL | | } = note: `-D clippy::option-if-let-else` implied by `-D warnings` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:29:13 + --> $DIR/option_if_let_else.rs:30:13 | LL | let _ = if let Some(s) = *string { s.len() } else { 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.map_or(0, |s| s.len())` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:30:13 + --> $DIR/option_if_let_else.rs:31:13 | LL | let _ = if let Some(s) = &num { s } else { &0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:31:13 + --> $DIR/option_if_let_else.rs:32:13 | LL | let _ = if let Some(s) = &mut num { | _____________^ @@ -43,13 +43,13 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:37:13 + --> $DIR/option_if_let_else.rs:38:13 | LL | let _ = if let Some(ref s) = num { s } else { &0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:38:13 + --> $DIR/option_if_let_else.rs:39:13 | LL | let _ = if let Some(mut s) = num { | _____________^ @@ -69,7 +69,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:44:13 + --> $DIR/option_if_let_else.rs:45:13 | LL | let _ = if let Some(ref mut s) = num { | _____________^ @@ -89,7 +89,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:53:5 + --> $DIR/option_if_let_else.rs:54:5 | LL | / if let Some(x) = arg { LL | | let y = x * x; @@ -108,7 +108,7 @@ LL + }) | error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:66:13 + --> $DIR/option_if_let_else.rs:67:13 | LL | let _ = if let Some(x) = arg { | _____________^ @@ -120,7 +120,7 @@ LL | | }; | |_____^ help: try: `arg.map_or_else(|| side_effect(), |x| x)` error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:75:13 + --> $DIR/option_if_let_else.rs:76:13 | LL | let _ = if let Some(x) = arg { | _____________^ @@ -143,7 +143,7 @@ LL ~ }, |x| x * x * x * x); | error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:108:13 + --> $DIR/option_if_let_else.rs:109:13 | LL | / if let Some(idx) = s.find('.') { LL | | vec![s[..idx].to_string(), s[idx..].to_string()] @@ -153,13 +153,13 @@ LL | | } | |_____________^ help: try: `s.find('.').map_or_else(|| vec![s.to_string()], |idx| vec![s[..idx].to_string(), s[idx..].to_string()])` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:132:13 + --> $DIR/option_if_let_else.rs:133:13 | LL | let _ = if let Some(x) = optional { x + 2 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:141:13 + --> $DIR/option_if_let_else.rs:142:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ @@ -181,13 +181,13 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:169:13 + --> $DIR/option_if_let_else.rs:170:13 | LL | let _ = if let Some(x) = Some(0) { s.len() + x } else { s.len() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(0).map_or(s.len(), |x| s.len() + x)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:173:13 + --> $DIR/option_if_let_else.rs:174:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ diff --git a/tests/ui/unreadable_literal.fixed b/tests/ui/unreadable_literal.fixed index e726b652ef1e..a67363b09ea5 100644 --- a/tests/ui/unreadable_literal.fixed +++ b/tests/ui/unreadable_literal.fixed @@ -1,6 +1,7 @@ // run-rustfix #![warn(clippy::unreadable_literal)] +#![allow(unused_tuple_struct_fields)] struct Foo(u64); diff --git a/tests/ui/unreadable_literal.rs b/tests/ui/unreadable_literal.rs index 5bbb2fc9dc13..82f04e7ced52 100644 --- a/tests/ui/unreadable_literal.rs +++ b/tests/ui/unreadable_literal.rs @@ -1,6 +1,7 @@ // run-rustfix #![warn(clippy::unreadable_literal)] +#![allow(unused_tuple_struct_fields)] struct Foo(u64); diff --git a/tests/ui/unreadable_literal.stderr b/tests/ui/unreadable_literal.stderr index ee5466fd517f..b51130c6a6ab 100644 --- a/tests/ui/unreadable_literal.stderr +++ b/tests/ui/unreadable_literal.stderr @@ -1,5 +1,5 @@ error: digits of hex or binary literal not grouped by four - --> $DIR/unreadable_literal.rs:25:9 + --> $DIR/unreadable_literal.rs:26:9 | LL | 0x1_234_567, | ^^^^^^^^^^^ help: consider: `0x0123_4567` @@ -7,7 +7,7 @@ LL | 0x1_234_567, = note: `-D clippy::unusual-byte-groupings` implied by `-D warnings` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:33:17 + --> $DIR/unreadable_literal.rs:34:17 | LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^^^ help: consider: `0b11_0110_i64` @@ -15,55 +15,55 @@ LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); = note: `-D clippy::unreadable-literal` implied by `-D warnings` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:33:31 + --> $DIR/unreadable_literal.rs:34:31 | LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^^^^^^^ help: consider: `0x1234_5678_usize` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:33:49 + --> $DIR/unreadable_literal.rs:34:49 | LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^ help: consider: `123_456_f32` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:33:61 + --> $DIR/unreadable_literal.rs:34:61 | LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^^^ help: consider: `1.234_567_f32` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:35:20 + --> $DIR/unreadable_literal.rs:36:20 | LL | let _bad_sci = 1.123456e1; | ^^^^^^^^^^ help: consider: `1.123_456e1` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:37:18 + --> $DIR/unreadable_literal.rs:38:18 | LL | let _fail1 = 0xabcdef; | ^^^^^^^^ help: consider: `0x00ab_cdef` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:38:23 + --> $DIR/unreadable_literal.rs:39:23 | LL | let _fail2: u32 = 0xBAFEBAFE; | ^^^^^^^^^^ help: consider: `0xBAFE_BAFE` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:39:18 + --> $DIR/unreadable_literal.rs:40:18 | LL | let _fail3 = 0xabcdeff; | ^^^^^^^^^ help: consider: `0x0abc_deff` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:40:24 + --> $DIR/unreadable_literal.rs:41:24 | LL | let _fail4: i128 = 0xabcabcabcabcabcabc; | ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:41:18 + --> $DIR/unreadable_literal.rs:42:18 | LL | let _fail5 = 1.100300400; | ^^^^^^^^^^^ help: consider: `1.100_300_400` From 27f633a5bac18bf7035675c8529de3757f6e5cf0 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 2 Aug 2022 06:02:04 +0000 Subject: [PATCH 0576/1222] Add `traits::fully_solve_obligation` that acts like `traits::fully_normalize` It spawns up a trait engine, registers the single obligation, then fully solves it --- clippy_lints/src/future_not_send.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 5c46d6c7df70..ef7d75aa8ed9 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -9,7 +9,7 @@ use rustc_middle::ty::{EarlyBinder, Opaque, PredicateKind::Trait}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt; -use rustc_trait_selection::traits::{self, FulfillmentError, TraitEngine}; +use rustc_trait_selection::traits::{self, FulfillmentError}; declare_clippy_lint! { /// ### What it does @@ -80,9 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { let span = decl.output.span(); let send_errors = cx.tcx.infer_ctxt().enter(|infcx| { let cause = traits::ObligationCause::misc(span, hir_id); - let mut fulfillment_cx = traits::FulfillmentContext::new(); - fulfillment_cx.register_bound(&infcx, cx.param_env, ret_ty, send_trait, cause); - fulfillment_cx.select_all_or_error(&infcx) + traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait) }); if !send_errors.is_empty() { span_lint_and_then( From 568ea0d939fac90551da29ca846e18129845d6ef Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 7 Aug 2022 15:21:11 +0200 Subject: [PATCH 0577/1222] Do not consider method call receiver as an argument in AST. --- clippy_lints/src/double_parens.rs | 5 ++--- clippy_lints/src/option_env_unwrap.rs | 4 ++-- clippy_lints/src/precedence.rs | 4 ++-- clippy_lints/src/suspicious_operation_groupings.rs | 2 +- clippy_lints/src/unused_rounding.rs | 5 ++--- clippy_utils/src/ast_utils.rs | 4 +++- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/double_parens.rs b/clippy_lints/src/double_parens.rs index a33ef5ce6e37..0f1d701865e7 100644 --- a/clippy_lints/src/double_parens.rs +++ b/clippy_lints/src/double_parens.rs @@ -61,9 +61,8 @@ impl EarlyLintPass for DoubleParens { } } }, - ExprKind::MethodCall(_, ref params, _) => { - if params.len() == 2 { - let param = ¶ms[1]; + ExprKind::MethodCall(_, _, ref params, _) => { + if let [ref param] = params[..] { if let ExprKind::Paren(_) = param.kind { span_lint(cx, DOUBLE_PARENS, param.span, msg); } diff --git a/clippy_lints/src/option_env_unwrap.rs b/clippy_lints/src/option_env_unwrap.rs index 3f5286ba097b..d9ee031c9f97 100644 --- a/clippy_lints/src/option_env_unwrap.rs +++ b/clippy_lints/src/option_env_unwrap.rs @@ -37,9 +37,9 @@ declare_lint_pass!(OptionEnvUnwrap => [OPTION_ENV_UNWRAP]); impl EarlyLintPass for OptionEnvUnwrap { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { if_chain! { - if let ExprKind::MethodCall(path_segment, args, _) = &expr.kind; + if let ExprKind::MethodCall(path_segment, receiver, _, _) = &expr.kind; if matches!(path_segment.ident.name, sym::expect | sym::unwrap); - if let ExprKind::Call(caller, _) = &args[0].kind; + if let ExprKind::Call(caller, _) = &receiver.kind; if is_direct_expn_of(caller.span, "option_env").is_some(); then { span_lint_and_help( diff --git a/clippy_lints/src/precedence.rs b/clippy_lints/src/precedence.rs index cc0533c9f5d1..e6e3ad05ad70 100644 --- a/clippy_lints/src/precedence.rs +++ b/clippy_lints/src/precedence.rs @@ -109,12 +109,12 @@ impl EarlyLintPass for Precedence { let mut arg = operand; let mut all_odd = true; - while let ExprKind::MethodCall(path_segment, args, _) = &arg.kind { + while let ExprKind::MethodCall(path_segment, receiver, _, _) = &arg.kind { let path_segment_str = path_segment.ident.name.as_str(); all_odd &= ALLOWED_ODD_FUNCTIONS .iter() .any(|odd_function| **odd_function == *path_segment_str); - arg = args.first().expect("A method always has a receiver."); + arg = receiver; } if_chain! { diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index fe8859905953..5d36f0f5ff8b 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -595,7 +595,7 @@ fn ident_difference_expr_with_base_location( | (Unary(_, _), Unary(_, _)) | (Binary(_, _, _), Binary(_, _, _)) | (Tup(_), Tup(_)) - | (MethodCall(_, _, _), MethodCall(_, _, _)) + | (MethodCall(_, _, _, _), MethodCall(_, _, _, _)) | (Call(_, _), Call(_, _)) | (ConstBlock(_), ConstBlock(_)) | (Array(_), Array(_)) diff --git a/clippy_lints/src/unused_rounding.rs b/clippy_lints/src/unused_rounding.rs index 306afe441484..e1ec357838db 100644 --- a/clippy_lints/src/unused_rounding.rs +++ b/clippy_lints/src/unused_rounding.rs @@ -30,11 +30,10 @@ declare_clippy_lint! { declare_lint_pass!(UnusedRounding => [UNUSED_ROUNDING]); fn is_useless_rounding(expr: &Expr) -> Option<(&str, String)> { - if let ExprKind::MethodCall(name_ident, args, _) = &expr.kind + if let ExprKind::MethodCall(name_ident, receiver, _, _) = &expr.kind && let method_name = name_ident.ident.name.as_str() && (method_name == "ceil" || method_name == "round" || method_name == "floor") - && !args.is_empty() - && let ExprKind::Lit(spanned) = &args[0].kind + && let ExprKind::Lit(spanned) = &receiver.kind && let LitKind::Float(symbol, ty) = spanned.kind { let f = symbol.as_str().parse::().unwrap(); let f_str = symbol.to_string() + if let LitFloatType::Suffixed(ty) = ty { diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index b226026323be..9f74729bdfa1 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -147,7 +147,9 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (Array(l), Array(r)) | (Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)), (Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value), (Call(lc, la), Call(rc, ra)) => eq_expr(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)), - (MethodCall(lc, la, _), MethodCall(rc, ra, _)) => eq_path_seg(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)), + (MethodCall(lc, ls, la, _), MethodCall(rc, rs, ra, _)) => { + eq_path_seg(lc, rc) && eq_expr(ls, rs) && over(la, ra, |l, r| eq_expr(l, r)) + }, (Binary(lo, ll, lr), Binary(ro, rl, rr)) => lo.node == ro.node && eq_expr(ll, rl) && eq_expr(lr, rr), (Unary(lo, l), Unary(ro, r)) => mem::discriminant(lo) == mem::discriminant(ro) && eq_expr(l, r), (Lit(l), Lit(r)) => l.kind == r.kind, From 8876e8cb64bee29c488bb06e1833c4f01d92d467 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 11 Aug 2022 11:05:26 +1000 Subject: [PATCH 0578/1222] Simplify `rustc_ast::visit::Visitor::visit_poly_trait_ref`. It is passed an argument that is never used. --- clippy_lints/src/unused_unit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/unused_unit.rs b/clippy_lints/src/unused_unit.rs index 52585e59566c..cd1d90e860b9 100644 --- a/clippy_lints/src/unused_unit.rs +++ b/clippy_lints/src/unused_unit.rs @@ -89,7 +89,7 @@ impl EarlyLintPass for UnusedUnit { } } - fn check_poly_trait_ref(&mut self, cx: &EarlyContext<'_>, poly: &ast::PolyTraitRef, _: &ast::TraitBoundModifier) { + fn check_poly_trait_ref(&mut self, cx: &EarlyContext<'_>, poly: &ast::PolyTraitRef) { let segments = &poly.trait_ref.path.segments; if_chain! { From ccb668f7e88342e40e0144e25353a495078538a6 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 31 Jul 2022 14:22:27 -0700 Subject: [PATCH 0579/1222] Update clippy for introduction of Node::ExprField --- clippy_lints/src/dereference.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 5d41c63928df..59f10247a11d 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then}; use clippy_utils::source::{snippet_with_applicability, snippet_with_context}; use clippy_utils::sugg::has_enclosing_paren; use clippy_utils::ty::{expr_sig, peel_mid_ty_refs, ty_sig, variant_of_res}; -use clippy_utils::{get_parent_expr, is_lint_allowed, path_to_local, walk_to_expr_usage}; +use clippy_utils::{get_parent_expr, get_parent_expr_for_hir, is_lint_allowed, path_to_local, walk_to_expr_usage}; use rustc_ast::util::parser::{PREC_POSTFIX, PREC_PREFIX}; use rustc_data_structures::fx::FxIndexMap; use rustc_errors::Applicability; @@ -699,6 +699,19 @@ fn walk_parents<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> (Position, & Some(ty_auto_deref_stability(cx, output, precedence).position_for_result(cx)) }, + Node::ExprField(field) if field.span.ctxt() == ctxt => match get_parent_expr_for_hir(cx, field.hir_id) { + Some(Expr { + hir_id, + kind: ExprKind::Struct(path, ..), + .. + }) => variant_of_res(cx, cx.qpath_res(path, *hir_id)) + .and_then(|variant| variant.fields.iter().find(|f| f.name == field.ident.name)) + .map(|field_def| { + ty_auto_deref_stability(cx, cx.tcx.type_of(field_def.did), precedence).position_for_arg() + }), + _ => None, + }, + Node::Expr(parent) if parent.span.ctxt() == ctxt => match parent.kind { ExprKind::Ret(_) => { let owner_id = cx.tcx.hir().body_owner(cx.enclosing_body.unwrap()); @@ -788,17 +801,6 @@ fn walk_parents<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> (Position, & } }) }, - ExprKind::Struct(path, fields, _) => { - let variant = variant_of_res(cx, cx.qpath_res(path, parent.hir_id)); - fields - .iter() - .find(|f| f.expr.hir_id == child_id) - .zip(variant) - .and_then(|(field, variant)| variant.fields.iter().find(|f| f.name == field.ident.name)) - .map(|field| { - ty_auto_deref_stability(cx, cx.tcx.type_of(field.did), precedence).position_for_arg() - }) - }, ExprKind::Field(child, name) if child.hir_id == e.hir_id => Some(Position::FieldAccess(name.name)), ExprKind::Unary(UnOp::Deref, child) if child.hir_id == e.hir_id => Some(Position::Deref), ExprKind::Match(child, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar) From d0e558cf800ff735d7888e13e5be054f9c872bfd Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 9 Aug 2022 09:56:13 -0400 Subject: [PATCH 0580/1222] Adjust cfgs --- clippy_dev/src/lib.rs | 1 - clippy_lints/src/lib.rs | 1 - clippy_utils/src/lib.rs | 1 - src/driver.rs | 2 +- 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index 8536e2429926..8a6bd1cbdf56 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -1,4 +1,3 @@ -#![cfg_attr(bootstrap, feature(let_chains))] #![feature(let_else)] #![feature(once_cell)] #![feature(rustc_private)] diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 2975399a8bbb..e6a405f8170d 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -4,7 +4,6 @@ #![feature(control_flow_enum)] #![feature(drain_filter)] #![feature(iter_intersperse)] -#![cfg_attr(bootstrap, feature(let_chains))] #![feature(let_else)] #![feature(lint_reasons)] #![feature(never_type)] diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 2616a578bb88..dc772e5efeef 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -2,7 +2,6 @@ #![feature(box_patterns)] #![feature(control_flow_enum)] #![feature(let_else)] -#![cfg_attr(bootstrap, feature(let_chains))] #![feature(lint_reasons)] #![feature(once_cell)] #![feature(rustc_private)] diff --git a/src/driver.rs b/src/driver.rs index c1ec2bd5bd66..235eae5af1ec 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -95,7 +95,7 @@ struct ClippyCallbacks { impl rustc_driver::Callbacks for ClippyCallbacks { // JUSTIFICATION: necessary in clippy driver to set `mir_opt_level` - #[cfg_attr(not(bootstrap), allow(rustc::bad_opt_access))] + #[allow(rustc::bad_opt_access)] fn config(&mut self, config: &mut interface::Config) { let previous = config.register_lints.take(); let clippy_args_var = self.clippy_args_var.take(); From 32f0a1c1e1ce916a7bb02b1fd3422f75950c4ef7 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 11 Aug 2022 21:06:11 +1000 Subject: [PATCH 0581/1222] Shrink `ast::Attribute`. --- clippy_lints/src/crate_in_macro_def.rs | 4 ++-- clippy_utils/src/ast_utils.rs | 2 +- clippy_utils/src/attrs.rs | 4 ++-- clippy_utils/src/lib.rs | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/crate_in_macro_def.rs b/clippy_lints/src/crate_in_macro_def.rs index 454ec23388af..20cc330e035f 100644 --- a/clippy_lints/src/crate_in_macro_def.rs +++ b/clippy_lints/src/crate_in_macro_def.rs @@ -74,8 +74,8 @@ impl EarlyLintPass for CrateInMacroDef { fn is_macro_export(attr: &Attribute) -> bool { if_chain! { - if let AttrKind::Normal(attr_item, _) = &attr.kind; - if let [segment] = attr_item.path.segments.as_slice(); + if let AttrKind::Normal(normal) = &attr.kind; + if let [segment] = normal.item.path.segments.as_slice(); then { segment.ident.name == sym::macro_export } else { diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 9f74729bdfa1..493991f30e87 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -695,7 +695,7 @@ pub fn eq_attr(l: &Attribute, r: &Attribute) -> bool { l.style == r.style && match (&l.kind, &r.kind) { (DocComment(l1, l2), DocComment(r1, r2)) => l1 == r1 && l2 == r2, - (Normal(l, _), Normal(r, _)) => eq_path(&l.path, &r.path) && eq_mac_args(&l.args, &r.args), + (Normal(l), Normal(r)) => eq_path(&l.item.path, &r.item.path) && eq_mac_args(&l.item.args, &r.item.args), _ => false, } } diff --git a/clippy_utils/src/attrs.rs b/clippy_utils/src/attrs.rs index 186bba09d201..8ab77c881663 100644 --- a/clippy_utils/src/attrs.rs +++ b/clippy_utils/src/attrs.rs @@ -59,8 +59,8 @@ pub fn get_attr<'a>( name: &'static str, ) -> impl Iterator { attrs.iter().filter(move |attr| { - let attr = if let ast::AttrKind::Normal(ref attr, _) = attr.kind { - attr + let attr = if let ast::AttrKind::Normal(ref normal) = attr.kind { + &normal.item } else { return false; }; diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index dc772e5efeef..f716f009ff3f 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1893,8 +1893,8 @@ pub fn std_or_core(cx: &LateContext<'_>) -> Option<&'static str> { pub fn is_no_std_crate(cx: &LateContext<'_>) -> bool { cx.tcx.hir().attrs(hir::CRATE_HIR_ID).iter().any(|attr| { - if let ast::AttrKind::Normal(ref attr, _) = attr.kind { - attr.path == sym::no_std + if let ast::AttrKind::Normal(ref normal) = attr.kind { + normal.item.path == sym::no_std } else { false } @@ -1903,8 +1903,8 @@ pub fn is_no_std_crate(cx: &LateContext<'_>) -> bool { pub fn is_no_core_crate(cx: &LateContext<'_>) -> bool { cx.tcx.hir().attrs(hir::CRATE_HIR_ID).iter().any(|attr| { - if let ast::AttrKind::Normal(ref attr, _) = attr.kind { - attr.path == sym::no_core + if let ast::AttrKind::Normal(ref normal) = attr.kind { + normal.item.path == sym::no_core } else { false } From 1006fe3fcfaed6c7f508e468462deebc055c4314 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 1 Aug 2022 16:46:08 +1000 Subject: [PATCH 0582/1222] Rename some things related to literals. - Rename `ast::Lit::token` as `ast::Lit::token_lit`, because its type is `token::Lit`, which is not a token. (This has been confusing me for a long time.) reasonable because we have an `ast::token::Lit` inside an `ast::Lit`. - Rename `LitKind::{from,to}_lit_token` as `LitKind::{from,to}_token_lit`, to match the above change and `token::Lit`. --- clippy_lints/src/octal_escapes.rs | 8 ++++---- clippy_lints/src/write.rs | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/octal_escapes.rs b/clippy_lints/src/octal_escapes.rs index 6ad6837f0e35..bffbf20b4d28 100644 --- a/clippy_lints/src/octal_escapes.rs +++ b/clippy_lints/src/octal_escapes.rs @@ -57,10 +57,10 @@ impl EarlyLintPass for OctalEscapes { } if let ExprKind::Lit(lit) = &expr.kind { - if matches!(lit.token.kind, LitKind::Str) { - check_lit(cx, &lit.token, lit.span, true); - } else if matches!(lit.token.kind, LitKind::ByteStr) { - check_lit(cx, &lit.token, lit.span, false); + if matches!(lit.token_lit.kind, LitKind::Str) { + check_lit(cx, &lit.token_lit, lit.span, true); + } else if matches!(lit.token_lit.kind, LitKind::ByteStr) { + check_lit(cx, &lit.token_lit, lit.span, false); } } } diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 32718200c0b3..fa2383066f3f 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -589,12 +589,12 @@ impl Write { }, }; - let replacement: String = match lit.token.kind { + let replacement: String = match lit.token_lit.kind { LitKind::StrRaw(_) | LitKind::ByteStrRaw(_) if matches!(fmtstr.style, StrStyle::Raw(_)) => { - lit.token.symbol.as_str().replace('{', "{{").replace('}', "}}") + lit.token_lit.symbol.as_str().replace('{', "{{").replace('}', "}}") }, LitKind::Str | LitKind::ByteStr if matches!(fmtstr.style, StrStyle::Cooked) => { - lit.token.symbol.as_str().replace('{', "{{").replace('}', "}}") + lit.token_lit.symbol.as_str().replace('{', "{{").replace('}', "}}") }, LitKind::StrRaw(_) | LitKind::Str @@ -603,7 +603,7 @@ impl Write { | LitKind::Integer | LitKind::Float | LitKind::Err => continue, - LitKind::Byte | LitKind::Char => match lit.token.symbol.as_str() { + LitKind::Byte | LitKind::Char => match lit.token_lit.symbol.as_str() { "\"" if matches!(fmtstr.style, StrStyle::Cooked) => "\\\"", "\"" if matches!(fmtstr.style, StrStyle::Raw(0)) => continue, "\\\\" if matches!(fmtstr.style, StrStyle::Raw(_)) => "\\", @@ -614,7 +614,7 @@ impl Write { x => x, } .into(), - LitKind::Bool => lit.token.symbol.as_str().deref().into(), + LitKind::Bool => lit.token_lit.symbol.as_str().deref().into(), }; if !fmt_spans.is_empty() { From f19533632310c24fd57a32f2743c4db69c26fd46 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 22 Aug 2022 13:27:52 +1000 Subject: [PATCH 0583/1222] Remove the symbol from `ast::LitKind::Err`. Because it's never used meaningfully. --- clippy_lints/src/matches/match_same_arms.rs | 2 +- clippy_lints/src/utils/author.rs | 2 +- clippy_utils/src/consts.rs | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/matches/match_same_arms.rs b/clippy_lints/src/matches/match_same_arms.rs index 582782f245fc..e32ef9933afe 100644 --- a/clippy_lints/src/matches/match_same_arms.rs +++ b/clippy_lints/src/matches/match_same_arms.rs @@ -290,7 +290,7 @@ impl<'a> NormalizedPat<'a> { LitKind::Char(val) => Self::LitInt(val.into()), LitKind::Int(val, _) => Self::LitInt(val), LitKind::Bool(val) => Self::LitBool(val), - LitKind::Float(..) | LitKind::Err(_) => Self::Wild, + LitKind::Float(..) | LitKind::Err => Self::Wild, }, _ => Self::Wild, }, diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index c0726868f77e..429c64ac1564 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -276,7 +276,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { match lit.value.node { LitKind::Bool(val) => kind!("Bool({val:?})"), LitKind::Char(c) => kind!("Char({c:?})"), - LitKind::Err(val) => kind!("Err({val})"), + LitKind::Err => kind!("Err"), LitKind::Byte(b) => kind!("Byte({b})"), LitKind::Int(i, suffix) => { let int_ty = match suffix { diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 351a3f4aec8c..e053708edd50 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -45,7 +45,7 @@ pub enum Constant { /// A reference Ref(Box), /// A literal with syntax error. - Err(Symbol), + Err, } impl PartialEq for Constant { @@ -118,9 +118,7 @@ impl Hash for Constant { Self::Ref(ref r) => { r.hash(state); }, - Self::Err(ref s) => { - s.hash(state); - }, + Self::Err => {}, } } } @@ -194,7 +192,7 @@ pub fn lit_to_mir_constant(lit: &LitKind, ty: Option>) -> Constant { _ => bug!(), }, LitKind::Bool(b) => Constant::Bool(b), - LitKind::Err(s) => Constant::Err(s), + LitKind::Err => Constant::Err, } } From cba1c2c0d8a8e113fd8dd438d3d501a4c9435003 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 14 Jul 2022 08:30:38 -0500 Subject: [PATCH 0584/1222] Stabilize `#![feature(label_break_value)]` # Stabilization proposal The feature was implemented in https://github.com/rust-lang/rust/pull/50045 by est31 and has been in nightly since 2018-05-16 (over 4 years now). There are [no open issues][issue-label] other than the tracking issue. There is a strong consensus that `break` is the right keyword and we should not use `return`. There have been several concerns raised about this feature on the tracking issue (other than the one about tests, which has been fixed, and an interaction with try blocks, which has been fixed). 1. nrc's original comment about cost-benefit analysis: https://github.com/rust-lang/rust/issues/48594#issuecomment-422235234 2. joshtriplett's comments about seeing use cases: https://github.com/rust-lang/rust/issues/48594#issuecomment-422281176 3. withoutboats's comments that Rust does not need more control flow constructs: https://github.com/rust-lang/rust/issues/48594#issuecomment-450050630 Many different examples of code that's simpler using this feature have been provided: - A lexer by rpjohnst which must repeat code without label-break-value: https://github.com/rust-lang/rust/issues/48594#issuecomment-422502014 - A snippet by SergioBenitez which avoids using a new function and adding several new return points to a function: https://github.com/rust-lang/rust/issues/48594#issuecomment-427628251. This particular case would also work if `try` blocks were stabilized (at the cost of making the code harder to optimize). - Several examples by JohnBSmith: https://github.com/rust-lang/rust/issues/48594#issuecomment-434651395 - Several examples by Centril: https://github.com/rust-lang/rust/issues/48594#issuecomment-440154733 - An example by petrochenkov where this is used in the compiler itself to avoid duplicating error checking code: https://github.com/rust-lang/rust/issues/48594#issuecomment-443557569 - Amanieu recently provided another example related to complex conditions, where try blocks would not have helped: https://github.com/rust-lang/rust/issues/48594#issuecomment-1184213006 Additionally, petrochenkov notes that this is strictly more powerful than labelled loops due to macros which accidentally exit a loop instead of being consumed by the macro matchers: https://github.com/rust-lang/rust/issues/48594#issuecomment-450246249 nrc later resolved their concern, mostly because of the aforementioned macro problems. joshtriplett suggested that macros could be able to generate IR directly (https://github.com/rust-lang/rust/issues/48594#issuecomment-451685983) but there are no open RFCs, and the design space seems rather speculative. joshtriplett later resolved his concerns, due to a symmetry between this feature and existing labelled break: https://github.com/rust-lang/rust/issues/48594#issuecomment-632960804 withoutboats has regrettably left the language team. joshtriplett later posted that the lang team would consider starting an FCP given a stabilization report: https://github.com/rust-lang/rust/issues/48594#issuecomment-1111269353 [issue-label]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AF-label_break_value+ ## Report + Feature gate: - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/src/test/ui/feature-gates/feature-gate-label_break_value.rs + Diagnostics: - https://github.com/rust-lang/rust/blob/6b2d3d5f3cd1e553d87b5496632132565b6779d3/compiler/rustc_parse/src/parser/diagnostics.rs#L2629 - https://github.com/rust-lang/rust/blob/f65bf0b2bb1a99f73095c01a118f3c37d3ee614c/compiler/rustc_resolve/src/diagnostics.rs#L749 - https://github.com/rust-lang/rust/blob/f65bf0b2bb1a99f73095c01a118f3c37d3ee614c/compiler/rustc_resolve/src/diagnostics.rs#L1001 - https://github.com/rust-lang/rust/blob/111df9e6eda1d752233482c1309d00d20a4bbf98/compiler/rustc_passes/src/loops.rs#L254 - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/compiler/rustc_parse/src/parser/expr.rs#L2079 - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/compiler/rustc_parse/src/parser/expr.rs#L1569 + Tests: - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_continue.rs - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_unlabeled_break.rs - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_illegal_uses.rs - https://github.com/rust-lang/rust/blob/master/src/test/ui/lint/unused_labels.rs - https://github.com/rust-lang/rust/blob/master/src/test/ui/run-pass/for-loop-while/label_break_value.rs ## Interactions with other features Labels follow the hygiene of local variables. label-break-value is permitted within `try` blocks: ```rust let _: Result<(), ()> = try { 'foo: { Err(())?; break 'foo; } }; ``` label-break-value is disallowed within closures, generators, and async blocks: ```rust 'a: { || break 'a //~^ ERROR use of unreachable label `'a` //~| ERROR `break` inside of a closure } ``` label-break-value is disallowed on [_BlockExpression_]; it can only occur as a [_LoopExpression_]: ```rust fn labeled_match() { match false 'b: { //~ ERROR block label not supported here _ => {} } } macro_rules! m { ($b:block) => { 'lab: $b; //~ ERROR cannot use a `block` macro fragment here unsafe $b; //~ ERROR cannot use a `block` macro fragment here |x: u8| -> () $b; //~ ERROR cannot use a `block` macro fragment here } } fn foo() { m!({}); } ``` [_BlockExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/block-expr.html [_LoopExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/loop-expr.html --- tests/ui/semicolon_if_nothing_returned.rs | 1 - tests/ui/semicolon_if_nothing_returned.stderr | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/ui/semicolon_if_nothing_returned.rs b/tests/ui/semicolon_if_nothing_returned.rs index 91916e7480fe..c3235f06779b 100644 --- a/tests/ui/semicolon_if_nothing_returned.rs +++ b/tests/ui/semicolon_if_nothing_returned.rs @@ -1,6 +1,5 @@ #![warn(clippy::semicolon_if_nothing_returned)] #![allow(clippy::redundant_closure)] -#![feature(label_break_value)] #![feature(let_else)] fn get_unit() {} diff --git a/tests/ui/semicolon_if_nothing_returned.stderr b/tests/ui/semicolon_if_nothing_returned.stderr index 41d2c1cfb87a..78813e7cc1c3 100644 --- a/tests/ui/semicolon_if_nothing_returned.stderr +++ b/tests/ui/semicolon_if_nothing_returned.stderr @@ -1,5 +1,5 @@ error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:10:5 + --> $DIR/semicolon_if_nothing_returned.rs:9:5 | LL | println!("Hello") | ^^^^^^^^^^^^^^^^^ help: add a `;` here: `println!("Hello");` @@ -7,25 +7,25 @@ LL | println!("Hello") = note: `-D clippy::semicolon-if-nothing-returned` implied by `-D warnings` error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:14:5 + --> $DIR/semicolon_if_nothing_returned.rs:13:5 | LL | get_unit() | ^^^^^^^^^^ help: add a `;` here: `get_unit();` error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:19:5 + --> $DIR/semicolon_if_nothing_returned.rs:18:5 | LL | y = x + 1 | ^^^^^^^^^ help: add a `;` here: `y = x + 1;` error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:25:9 + --> $DIR/semicolon_if_nothing_returned.rs:24:9 | LL | hello() | ^^^^^^^ help: add a `;` here: `hello();` error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:36:9 + --> $DIR/semicolon_if_nothing_returned.rs:35:9 | LL | ptr::drop_in_place(s.as_mut_ptr()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `ptr::drop_in_place(s.as_mut_ptr());` From 08d22fadebba9bad9de0dcc826d694ac6defaba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Tue, 5 Jul 2022 00:00:00 +0000 Subject: [PATCH 0585/1222] Replace `Body::basic_blocks()` with field access --- clippy_lints/src/redundant_clone.rs | 6 +++--- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index eddca6045757..9fd86331ec75 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone { vis.into_map(cx, maybe_storage_live_result) }; - for (bb, bbdata) in mir.basic_blocks().iter_enumerated() { + for (bb, bbdata) in mir.basic_blocks.iter_enumerated() { let terminator = bbdata.terminator(); if terminator.source_info.span.from_expansion() { @@ -186,7 +186,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone { unwrap_or_continue!(find_stmt_assigns_to(cx, mir, pred_arg, true, ps[0])); let loc = mir::Location { block: bb, - statement_index: mir.basic_blocks()[bb].statements.len(), + statement_index: mir.basic_blocks[bb].statements.len(), }; // This can be turned into `res = move local` if `arg` and `cloned` are not borrowed @@ -310,7 +310,7 @@ fn find_stmt_assigns_to<'tcx>( by_ref: bool, bb: mir::BasicBlock, ) -> Option<(mir::Local, CannotMoveOut)> { - let rvalue = mir.basic_blocks()[bb].statements.iter().rev().find_map(|stmt| { + let rvalue = mir.basic_blocks[bb].statements.iter().rev().find_map(|stmt| { if let mir::StatementKind::Assign(box (mir::Place { local, .. }, v)) = &stmt.kind { return if *local == to_local { Some(v) } else { None }; } diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 3bf75bcbee83..74c222bbcbeb 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -55,7 +55,7 @@ pub fn is_min_const_fn<'a, 'tcx>(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: body.local_decls.iter().next().unwrap().source_info.span, )?; - for bb in body.basic_blocks() { + for bb in body.basic_blocks.iter() { check_terminator(tcx, body, bb.terminator(), msrv)?; for stmt in &bb.statements { check_statement(tcx, body, def_id, stmt)?; From c36f20ff541ee2f505f7e36fd0192fe550b42df0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 26 Aug 2022 15:43:00 +1000 Subject: [PATCH 0586/1222] Use `&'hir Expr` everywhere. For consistency, and because it makes HIR measurement simpler and more accurate. --- clippy_lints/src/loops/never_loop.rs | 4 ++-- clippy_lints/src/utils/author.rs | 2 +- clippy_utils/src/lib.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index 32de20f6531f..5448360049d2 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -178,9 +178,9 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { InlineAsmOperand::In { expr, .. } | InlineAsmOperand::InOut { expr, .. } => { never_loop_expr(expr, main_loop_id) }, - InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter(), main_loop_id), + InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter().copied(), main_loop_id), InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { - never_loop_expr_all(&mut once(in_expr).chain(out_expr.iter()), main_loop_id) + never_loop_expr_all(&mut once(*in_expr).chain(out_expr.iter().copied()), main_loop_id) }, InlineAsmOperand::Const { .. } | InlineAsmOperand::SymFn { .. } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 429c64ac1564..3ffcaa90af3e 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -595,7 +595,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { } fn body(&self, body_id: &Binding) { - let expr = &self.cx.tcx.hir().body(body_id.value).value; + let expr = self.cx.tcx.hir().body(body_id.value).value; bind!(self, expr); out!("let {expr} = &cx.tcx.hir().body({body_id}).value;"); self.expr(expr); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index f716f009ff3f..dd1ceb6a4dc4 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1804,7 +1804,7 @@ pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool } }; - let mut expr = &func.value; + let mut expr = func.value; loop { match expr.kind { #[rustfmt::skip] From 1f1eea3ed2f9c9bf1c1b70a5ef65fa94c364d727 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 26 Aug 2022 15:57:44 +1000 Subject: [PATCH 0587/1222] Use `&'hir Ty` everywhere. For consistency, and because it makes HIR measurement simpler and more accurate. --- clippy_lints/src/manual_bits.rs | 2 +- clippy_utils/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/manual_bits.rs b/clippy_lints/src/manual_bits.rs index 60bbcde4f1de..940601a44fb0 100644 --- a/clippy_lints/src/manual_bits.rs +++ b/clippy_lints/src/manual_bits.rs @@ -105,7 +105,7 @@ fn get_size_of_ty<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option< if let Some(def_id) = cx.qpath_res(count_func_qpath, count_func.hir_id).opt_def_id(); if cx.tcx.is_diagnostic_item(sym::mem_size_of, def_id); then { - cx.typeck_results().node_substs(count_func.hir_id).types().next().map(|resolved_ty| (real_ty, resolved_ty)) + cx.typeck_results().node_substs(count_func.hir_id).types().next().map(|resolved_ty| (*real_ty, resolved_ty)) } else { None } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index dd1ceb6a4dc4..42ce3b6bf0fc 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -333,7 +333,7 @@ pub fn qpath_generic_tys<'tcx>(qpath: &QPath<'tcx>) -> impl Iterator Some(ty), + hir::GenericArg::Type(ty) => Some(*ty), _ => None, }) } From af3dcb6f7476fce8ac5fac84b7682f0a5a0892ba Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sat, 20 Aug 2022 20:40:08 +0200 Subject: [PATCH 0588/1222] Revert let_chains stabilization This reverts commit 326646074940222d602f3683d0559088690830f4. This is the revert against master, the beta revert was already done in #100538. --- clippy_dev/src/lib.rs | 1 + clippy_lints/src/lib.rs | 1 + clippy_utils/src/lib.rs | 1 + tests/ui/needless_late_init.fixed | 1 + tests/ui/needless_late_init.rs | 1 + tests/ui/needless_late_init.stderr | 32 +++++++++++++++--------------- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index 8a6bd1cbdf56..82574a8e64b0 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(let_chains)] #![feature(let_else)] #![feature(once_cell)] #![feature(rustc_private)] diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index e6a405f8170d..ec5c73c13576 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -4,6 +4,7 @@ #![feature(control_flow_enum)] #![feature(drain_filter)] #![feature(iter_intersperse)] +#![feature(let_chains)] #![feature(let_else)] #![feature(lint_reasons)] #![feature(never_type)] diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index f716f009ff3f..313f1f1d9a6f 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -2,6 +2,7 @@ #![feature(box_patterns)] #![feature(control_flow_enum)] #![feature(let_else)] +#![feature(let_chains)] #![feature(lint_reasons)] #![feature(once_cell)] #![feature(rustc_private)] diff --git a/tests/ui/needless_late_init.fixed b/tests/ui/needless_late_init.fixed index 4c98e1827bdb..fee8e3030b80 100644 --- a/tests/ui/needless_late_init.fixed +++ b/tests/ui/needless_late_init.fixed @@ -1,4 +1,5 @@ // run-rustfix +#![feature(let_chains)] #![allow( unused, clippy::assign_op_pattern, diff --git a/tests/ui/needless_late_init.rs b/tests/ui/needless_late_init.rs index 25e1e0214fb4..402d9f9ef7f8 100644 --- a/tests/ui/needless_late_init.rs +++ b/tests/ui/needless_late_init.rs @@ -1,4 +1,5 @@ // run-rustfix +#![feature(let_chains)] #![allow( unused, clippy::assign_op_pattern, diff --git a/tests/ui/needless_late_init.stderr b/tests/ui/needless_late_init.stderr index 97f0f7019a9d..313cdbbeba18 100644 --- a/tests/ui/needless_late_init.stderr +++ b/tests/ui/needless_late_init.stderr @@ -1,5 +1,5 @@ error: unneeded late initialization - --> $DIR/needless_late_init.rs:22:5 + --> $DIR/needless_late_init.rs:23:5 | LL | let a; | ^^^^^^ created here @@ -13,7 +13,7 @@ LL | let a = "zero"; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:25:5 + --> $DIR/needless_late_init.rs:26:5 | LL | let b; | ^^^^^^ created here @@ -27,7 +27,7 @@ LL | let b = 1; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:26:5 + --> $DIR/needless_late_init.rs:27:5 | LL | let c; | ^^^^^^ created here @@ -41,7 +41,7 @@ LL | let c = 2; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:30:5 + --> $DIR/needless_late_init.rs:31:5 | LL | let d: usize; | ^^^^^^^^^^^^^ created here @@ -54,7 +54,7 @@ LL | let d: usize = 1; | ~~~~~~~~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:33:5 + --> $DIR/needless_late_init.rs:34:5 | LL | let e; | ^^^^^^ created here @@ -67,7 +67,7 @@ LL | let e = format!("{}", d); | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:38:5 + --> $DIR/needless_late_init.rs:39:5 | LL | let a; | ^^^^^^ @@ -88,7 +88,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:47:5 + --> $DIR/needless_late_init.rs:48:5 | LL | let b; | ^^^^^^ @@ -109,7 +109,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:54:5 + --> $DIR/needless_late_init.rs:55:5 | LL | let d; | ^^^^^^ @@ -130,7 +130,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:62:5 + --> $DIR/needless_late_init.rs:63:5 | LL | let e; | ^^^^^^ @@ -151,7 +151,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:69:5 + --> $DIR/needless_late_init.rs:70:5 | LL | let f; | ^^^^^^ @@ -167,7 +167,7 @@ LL + 1 => "three", | error: unneeded late initialization - --> $DIR/needless_late_init.rs:75:5 + --> $DIR/needless_late_init.rs:76:5 | LL | let g: usize; | ^^^^^^^^^^^^^ @@ -187,7 +187,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:83:5 + --> $DIR/needless_late_init.rs:84:5 | LL | let x; | ^^^^^^ created here @@ -201,7 +201,7 @@ LL | let x = 1; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:87:5 + --> $DIR/needless_late_init.rs:88:5 | LL | let x; | ^^^^^^ created here @@ -215,7 +215,7 @@ LL | let x = SignificantDrop; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:91:5 + --> $DIR/needless_late_init.rs:92:5 | LL | let x; | ^^^^^^ created here @@ -229,7 +229,7 @@ LL | let x = SignificantDrop; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:110:5 + --> $DIR/needless_late_init.rs:111:5 | LL | let a; | ^^^^^^ @@ -250,7 +250,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:127:5 + --> $DIR/needless_late_init.rs:128:5 | LL | let a; | ^^^^^^ From 5dc6962b0ea068398eb77c6b824bebe4a7455b8e Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Mon, 29 Aug 2022 21:28:35 +0100 Subject: [PATCH 0589/1222] Fix tests due to stricter invalid_value --- tests/ui/uninit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/uninit.rs b/tests/ui/uninit.rs index dac5ce272c02..211317317086 100644 --- a/tests/ui/uninit.rs +++ b/tests/ui/uninit.rs @@ -1,5 +1,5 @@ #![feature(stmt_expr_attributes)] -#![allow(clippy::let_unit_value)] +#![allow(clippy::let_unit_value, invalid_value)] use std::mem::{self, MaybeUninit}; From 5d3a77b802c376f6eb93578b02231185203f919f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 31 Aug 2022 15:24:40 +0200 Subject: [PATCH 0590/1222] fix a clippy test --- tests/ui/indexing_slicing_index.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/indexing_slicing_index.rs b/tests/ui/indexing_slicing_index.rs index 45a430edcb58..7ebf6ee993cb 100644 --- a/tests/ui/indexing_slicing_index.rs +++ b/tests/ui/indexing_slicing_index.rs @@ -3,7 +3,7 @@ // We also check the out_of_bounds_indexing lint here, because it lints similar things and // we want to avoid false positives. #![warn(clippy::out_of_bounds_indexing)] -#![allow(const_err, clippy::no_effect, clippy::unnecessary_operation)] +#![allow(const_err, unconditional_panic, clippy::no_effect, clippy::unnecessary_operation)] const ARR: [i32; 2] = [1, 2]; const REF: &i32 = &ARR[idx()]; // Ok, should not produce stderr. From 554541feaa42baa70ea99eb3809338a8b01460e0 Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Wed, 31 Aug 2022 09:33:32 -0400 Subject: [PATCH 0591/1222] Use `CountIsStart` in clippy --- clippy_lints/src/write.rs | 4 ++-- clippy_utils/src/macros.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 5533840b166f..347165d9704a 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -526,7 +526,7 @@ impl SimpleFormatArgs { str_lit_span: Span, fmt_span: Span, ) { - use rustc_parse_format::{ArgumentImplicitlyIs, ArgumentIs, CountIsParam}; + use rustc_parse_format::{ArgumentImplicitlyIs, ArgumentIs, CountIsParam, CountIsStar}; let snippet = snippet_opt(cx, fmt_span); @@ -540,7 +540,7 @@ impl SimpleFormatArgs { self.push_to_complex(span, n); }; - if let (CountIsParam(n), Some(span)) = (arg.format.precision, arg.format.precision_span) { + if let (CountIsParam(n) | CountIsStar(n), Some(span)) = (arg.format.precision, arg.format.precision_span) { // We need to do this hack as precision spans should be converted from .* to .foo$ let hack = if snippet.as_ref().and_then(|s| s.find('*')).is_some() { 0 diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs index e5ca35455404..43e53f3feebd 100644 --- a/clippy_utils/src/macros.rs +++ b/clippy_utils/src/macros.rs @@ -644,7 +644,7 @@ impl<'tcx> Count<'tcx> { span, values, )?), - rpf::Count::CountIsParam(_) => { + rpf::Count::CountIsParam(_) | rpf::Count::CountIsStar(_) => { Self::Param(FormatParam::new(FormatParamKind::Numbered, position?, inner?, values)?) }, rpf::Count::CountImplied => Self::Implied, From 80feb27fc8dd09e752b9992605cba6d8a4925440 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Tue, 30 Aug 2022 17:36:53 -0500 Subject: [PATCH 0592/1222] clippy: BindingAnnotation change --- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/explicit_write.rs | 2 +- clippy_lints/src/index_refutable_slice.rs | 16 ++++++++------- clippy_lints/src/let_if_seq.rs | 4 ++-- clippy_lints/src/loops/manual_find.rs | 2 +- clippy_lints/src/loops/mut_range_bound.rs | 2 +- clippy_lints/src/loops/same_item_push.rs | 4 ++-- clippy_lints/src/matches/manual_map.rs | 2 +- clippy_lints/src/matches/match_as_ref.rs | 20 +++++++++---------- clippy_lints/src/matches/needless_match.rs | 5 ++--- clippy_lints/src/matches/single_match.rs | 2 +- clippy_lints/src/methods/clone_on_copy.rs | 9 ++------- clippy_lints/src/methods/iter_skip_next.rs | 2 +- clippy_lints/src/methods/map_clone.rs | 4 ++-- clippy_lints/src/methods/str_splitn.rs | 11 +++++----- clippy_lints/src/misc.rs | 11 +++++----- .../src/misc_early/redundant_pattern.rs | 12 +++-------- .../src/needless_arbitrary_self_type.rs | 6 +++--- clippy_lints/src/needless_borrowed_ref.rs | 2 +- clippy_lints/src/needless_late_init.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 10 ++++------ clippy_lints/src/option_if_let_else.rs | 4 ++-- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/ptr.rs | 4 ++-- clippy_lints/src/question_mark.rs | 7 +++---- .../src/slow_vector_initialization.rs | 2 +- clippy_lints/src/unnested_or_patterns.rs | 4 ++-- clippy_lints/src/utils/author.rs | 14 ++++++++++--- clippy_lints/src/vec_init_then_push.rs | 2 +- clippy_utils/src/hir_utils.rs | 11 +++++----- clippy_utils/src/lib.rs | 2 +- tests/ui/author.stdout | 2 +- tests/ui/author/blocks.stdout | 6 +++--- tests/ui/author/loop.stdout | 4 ++-- tests/ui/author/matches.stdout | 4 ++-- 35 files changed, 95 insertions(+), 103 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 1506ea604f0d..3de188d96ce8 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -503,7 +503,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing { } fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { - if let PatKind::Binding(BindingAnnotation::Ref, id, name, _) = pat.kind { + if let PatKind::Binding(BindingAnnotation::REF, id, name, _) = pat.kind { if let Some(opt_prev_pat) = self.ref_locals.get_mut(&id) { // This binding id has been seen before. Add this pattern to the list of changes. if let Some(prev_pat) = opt_prev_pat { diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 5bf4313b41a4..502f0b583c41 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -128,7 +128,7 @@ fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>) if let Some(Node::Pat(res_pat)) = cx.tcx.hir().find(expr_res); // Find id of the local we found in the block - if let PatKind::Binding(BindingAnnotation::Unannotated, local_hir_id, _ident, None) = local.pat.kind; + if let PatKind::Binding(BindingAnnotation::NONE, local_hir_id, _ident, None) = local.pat.kind; // If those two are the same hir id if res_pat.hir_id == local_hir_id; diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index d0c6495e35a7..0dd7f5bf000d 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -95,12 +95,14 @@ fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap = FxHashSet::default(); let mut slices: FxIndexMap = FxIndexMap::default(); pat.walk_always(|pat| { - if let hir::PatKind::Binding(binding, value_hir_id, ident, sub_pat) = pat.kind { - // We'll just ignore mut and ref mut for simplicity sake right now - if let hir::BindingAnnotation::Mutable | hir::BindingAnnotation::RefMut = binding { - return; - } - + // We'll just ignore mut and ref mut for simplicity sake right now + if let hir::PatKind::Binding( + hir::BindingAnnotation(by_ref, hir::Mutability::Not), + value_hir_id, + ident, + sub_pat, + ) = pat.kind + { // This block catches bindings with sub patterns. It would be hard to build a correct suggestion // for them and it's likely that the user knows what they are doing in such a case. if removed_pat.contains(&value_hir_id) { @@ -116,7 +118,7 @@ fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap LateLintPass<'tcx> for LetIfSeq { }; let mutability = match mode { - BindingAnnotation::RefMut | BindingAnnotation::Mutable => " ", + BindingAnnotation(_, Mutability::Mut) => " ", _ => "", }; diff --git a/clippy_lints/src/loops/manual_find.rs b/clippy_lints/src/loops/manual_find.rs index 215c83a7edf6..09b2376d5c04 100644 --- a/clippy_lints/src/loops/manual_find.rs +++ b/clippy_lints/src/loops/manual_find.rs @@ -106,7 +106,7 @@ fn get_binding(pat: &Pat<'_>) -> Option { hir_id = None; return; } - if let BindingAnnotation::Unannotated = annotation { + if let BindingAnnotation::NONE = annotation { hir_id = Some(id); } }); diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index aedf3810b23e..fce2d54639cb 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -44,7 +44,7 @@ fn check_for_mutability(cx: &LateContext<'_>, bound: &Expr<'_>) -> Option if_chain! { if let Some(hir_id) = path_to_local(bound); if let Node::Pat(pat) = cx.tcx.hir().get(hir_id); - if let PatKind::Binding(BindingAnnotation::Mutable, ..) = pat.kind; + if let PatKind::Binding(BindingAnnotation::MUT, ..) = pat.kind; then { return Some(hir_id); } diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index 1439f1f4c75d..98f73c428ebf 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -7,7 +7,7 @@ use if_chain::if_chain; use rustc_data_structures::fx::FxHashSet; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Node, Pat, PatKind, Stmt, StmtKind}; +use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Mutability, Node, Pat, PatKind, Stmt, StmtKind}; use rustc_lint::LateContext; use rustc_span::symbol::sym; use std::iter::Iterator; @@ -65,7 +65,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Node::Pat(pat) = node; if let PatKind::Binding(bind_ann, ..) = pat.kind; - if !matches!(bind_ann, BindingAnnotation::RefMut | BindingAnnotation::Mutable); + if !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut)); let parent_node = cx.tcx.hir().get_parent_node(hir_id); if let Some(Node::Local(parent_let_expr)) = cx.tcx.hir().find(parent_node); if let Some(init) = parent_let_expr.init; diff --git a/clippy_lints/src/matches/manual_map.rs b/clippy_lints/src/matches/manual_map.rs index 8f98b43b9e5c..b0198e856d5b 100644 --- a/clippy_lints/src/matches/manual_map.rs +++ b/clippy_lints/src/matches/manual_map.rs @@ -165,7 +165,7 @@ fn check<'tcx>( } // `ref` and `ref mut` annotations were handled earlier. - let annotation = if matches!(annotation, BindingAnnotation::Mutable) { + let annotation = if matches!(annotation, BindingAnnotation::MUT) { "mut " } else { "" diff --git a/clippy_lints/src/matches/match_as_ref.rs b/clippy_lints/src/matches/match_as_ref.rs index a0efdecec67f..91d17f481e2d 100644 --- a/clippy_lints/src/matches/match_as_ref.rs +++ b/clippy_lints/src/matches/match_as_ref.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::{is_lang_ctor, peel_blocks}; use rustc_errors::Applicability; -use rustc_hir::{Arm, BindingAnnotation, Expr, ExprKind, LangItem, PatKind, QPath}; +use rustc_hir::{Arm, BindingAnnotation, ByRef, Expr, ExprKind, LangItem, Mutability, PatKind, QPath}; use rustc_lint::LateContext; use rustc_middle::ty; @@ -10,18 +10,17 @@ use super::MATCH_AS_REF; pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { if arms.len() == 2 && arms[0].guard.is_none() && arms[1].guard.is_none() { - let arm_ref: Option = if is_none_arm(cx, &arms[0]) { + let arm_ref_mut = if is_none_arm(cx, &arms[0]) { is_ref_some_arm(cx, &arms[1]) } else if is_none_arm(cx, &arms[1]) { is_ref_some_arm(cx, &arms[0]) } else { None }; - if let Some(rb) = arm_ref { - let suggestion = if rb == BindingAnnotation::Ref { - "as_ref" - } else { - "as_mut" + if let Some(rb) = arm_ref_mut { + let suggestion = match rb { + Mutability::Not => "as_ref", + Mutability::Mut => "as_mut", }; let output_ty = cx.typeck_results().expr_ty(expr); @@ -66,19 +65,18 @@ fn is_none_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool { } // Checks if arm has the form `Some(ref v) => Some(v)` (checks for `ref` and `ref mut`) -fn is_ref_some_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> Option { +fn is_ref_some_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> Option { if_chain! { if let PatKind::TupleStruct(ref qpath, [first_pat, ..], _) = arm.pat.kind; if is_lang_ctor(cx, qpath, LangItem::OptionSome); - if let PatKind::Binding(rb, .., ident, _) = first_pat.kind; - if rb == BindingAnnotation::Ref || rb == BindingAnnotation::RefMut; + if let PatKind::Binding(BindingAnnotation(ByRef::Yes, mutabl), .., ident, _) = first_pat.kind; if let ExprKind::Call(e, [arg]) = peel_blocks(arm.body).kind; if let ExprKind::Path(ref some_path) = e.kind; if is_lang_ctor(cx, some_path, LangItem::OptionSome); if let ExprKind::Path(QPath::Resolved(_, path2)) = arg.kind; if path2.segments.len() == 1 && ident.name == path2.segments[0].ident.name; then { - return Some(rb) + return Some(mutabl) } } None diff --git a/clippy_lints/src/matches/needless_match.rs b/clippy_lints/src/matches/needless_match.rs index 6f037339ec75..634eef82e532 100644 --- a/clippy_lints/src/matches/needless_match.rs +++ b/clippy_lints/src/matches/needless_match.rs @@ -8,7 +8,7 @@ use clippy_utils::{ }; use rustc_errors::Applicability; use rustc_hir::LangItem::OptionNone; -use rustc_hir::{Arm, BindingAnnotation, Expr, ExprKind, FnRetTy, Guard, Node, Pat, PatKind, Path, QPath}; +use rustc_hir::{Arm, BindingAnnotation, ByRef, Expr, ExprKind, FnRetTy, Guard, Node, Pat, PatKind, Path, QPath}; use rustc_lint::LateContext; use rustc_span::sym; use rustc_typeck::hir_ty_to_ty; @@ -189,8 +189,7 @@ fn pat_same_as_expr(pat: &Pat<'_>, expr: &Expr<'_>) -> bool { }, )), ) => { - return !matches!(annot, BindingAnnotation::Ref | BindingAnnotation::RefMut) - && pat_ident.name == first_seg.ident.name; + return !matches!(annot, BindingAnnotation(ByRef::Yes, _)) && pat_ident.name == first_seg.ident.name; }, // Example: `Custom::TypeA => Custom::TypeB`, or `None => None` (PatKind::Path(QPath::Resolved(_, p_path)), ExprKind::Path(QPath::Resolved(_, e_path))) => { diff --git a/clippy_lints/src/matches/single_match.rs b/clippy_lints/src/matches/single_match.rs index 92091a0c3395..95478af45b4b 100644 --- a/clippy_lints/src/matches/single_match.rs +++ b/clippy_lints/src/matches/single_match.rs @@ -175,7 +175,7 @@ fn collect_pat_paths<'a>(acc: &mut Vec>, cx: &LateContext<'a>, pat: &Pat< let p_ty = cx.typeck_results().pat_ty(p); collect_pat_paths(acc, cx, p, p_ty); }), - PatKind::TupleStruct(..) | PatKind::Binding(BindingAnnotation::Unannotated, .., None) | PatKind::Path(_) => { + PatKind::TupleStruct(..) | PatKind::Binding(BindingAnnotation::NONE, .., None) | PatKind::Path(_) => { acc.push(ty); }, _ => {}, diff --git a/clippy_lints/src/methods/clone_on_copy.rs b/clippy_lints/src/methods/clone_on_copy.rs index 60e1355f9b92..2c3683a09e32 100644 --- a/clippy_lints/src/methods/clone_on_copy.rs +++ b/clippy_lints/src/methods/clone_on_copy.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet_with_context; use clippy_utils::sugg; use clippy_utils::ty::is_copy; use rustc_errors::Applicability; -use rustc_hir::{BindingAnnotation, Expr, ExprKind, MatchSource, Node, PatKind, QPath}; +use rustc_hir::{BindingAnnotation, ByRef, Expr, ExprKind, MatchSource, Node, PatKind, QPath}; use rustc_lint::LateContext; use rustc_middle::ty::{self, adjustment::Adjust}; use rustc_span::symbol::{sym, Symbol}; @@ -98,12 +98,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol, _ => false, }, // local binding capturing a reference - Some(Node::Local(l)) - if matches!( - l.pat.kind, - PatKind::Binding(BindingAnnotation::Ref | BindingAnnotation::RefMut, ..) - ) => - { + Some(Node::Local(l)) if matches!(l.pat.kind, PatKind::Binding(BindingAnnotation(ByRef::Yes, _), ..)) => { return; }, _ => false, diff --git a/clippy_lints/src/methods/iter_skip_next.rs b/clippy_lints/src/methods/iter_skip_next.rs index 43e9451f7d37..beb772100aff 100644 --- a/clippy_lints/src/methods/iter_skip_next.rs +++ b/clippy_lints/src/methods/iter_skip_next.rs @@ -24,7 +24,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr if let Some(id) = path_to_local(recv); if let Node::Pat(pat) = cx.tcx.hir().get(id); if let PatKind::Binding(ann, _, _, _) = pat.kind; - if ann != BindingAnnotation::Mutable; + if ann != BindingAnnotation::MUT; then { application = Applicability::Unspecified; diag.span_help( diff --git a/clippy_lints/src/methods/map_clone.rs b/clippy_lints/src/methods/map_clone.rs index ffedda95ff8e..a13541ad48d8 100644 --- a/clippy_lints/src/methods/map_clone.rs +++ b/clippy_lints/src/methods/map_clone.rs @@ -33,13 +33,13 @@ pub(super) fn check<'tcx>( let closure_expr = peel_blocks(&closure_body.value); match closure_body.params[0].pat.kind { hir::PatKind::Ref(inner, hir::Mutability::Not) => if let hir::PatKind::Binding( - hir::BindingAnnotation::Unannotated, .., name, None + hir::BindingAnnotation::NONE, .., name, None ) = inner.kind { if ident_eq(name, closure_expr) { lint_explicit_closure(cx, e.span, recv.span, true, msrv); } }, - hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, .., name, None) => { + hir::PatKind::Binding(hir::BindingAnnotation::NONE, .., name, None) => { match closure_expr.kind { hir::ExprKind::Unary(hir::UnOp::Deref, inner) => { if ident_eq(name, inner) { diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 4ac738272d08..c5da8c8b0fec 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -130,7 +130,7 @@ fn check_manual_split_once_indirect( let ctxt = expr.span.ctxt(); let mut parents = cx.tcx.hir().parent_iter(expr.hir_id); if let (_, Node::Local(local)) = parents.next()? - && let PatKind::Binding(BindingAnnotation::Mutable, iter_binding_id, iter_ident, None) = local.pat.kind + && let PatKind::Binding(BindingAnnotation::MUT, iter_binding_id, iter_ident, None) = local.pat.kind && let (iter_stmt_id, Node::Stmt(_)) = parents.next()? && let (_, Node::Block(enclosing_block)) = parents.next()? @@ -212,11 +212,10 @@ fn indirect_usage<'tcx>( ctxt: SyntaxContext, ) -> Option> { if let StmtKind::Local(Local { - pat: - Pat { - kind: PatKind::Binding(BindingAnnotation::Unannotated, _, ident, None), - .. - }, + pat: Pat { + kind: PatKind::Binding(BindingAnnotation::NONE, _, ident, None), + .. + }, init: Some(init_expr), hir_id: local_hir_id, .. diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 8224e80c9ccb..ea245edd7704 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -5,8 +5,8 @@ use rustc_ast::ast::LitKind; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{ - self as hir, def, BinOpKind, BindingAnnotation, Body, Expr, ExprKind, FnDecl, HirId, Mutability, PatKind, Stmt, - StmtKind, TyKind, + self as hir, def, BinOpKind, BindingAnnotation, Body, ByRef, Expr, ExprKind, FnDecl, HirId, Mutability, PatKind, + Stmt, StmtKind, TyKind, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; @@ -146,7 +146,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints { return; } for arg in iter_input_pats(decl, body) { - if let PatKind::Binding(BindingAnnotation::Ref | BindingAnnotation::RefMut, ..) = arg.pat.kind { + if let PatKind::Binding(BindingAnnotation(ByRef::Yes, _), ..) = arg.pat.kind { span_lint( cx, TOPLEVEL_REF_ARG, @@ -162,9 +162,8 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints { if_chain! { if !in_external_macro(cx.tcx.sess, stmt.span); if let StmtKind::Local(local) = stmt.kind; - if let PatKind::Binding(an, .., name, None) = local.pat.kind; + if let PatKind::Binding(BindingAnnotation(ByRef::Yes, mutabl), .., name, None) = local.pat.kind; if let Some(init) = local.init; - if an == BindingAnnotation::Ref || an == BindingAnnotation::RefMut; then { // use the macro callsite when the init span (but not the whole local span) // comes from an expansion like `vec![1, 2, 3]` in `let ref _ = vec![1, 2, 3];` @@ -173,7 +172,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints { } else { Sugg::hir(cx, init, "..") }; - let (mutopt, initref) = if an == BindingAnnotation::RefMut { + let (mutopt, initref) = if mutabl == Mutability::Mut { ("mut ", sugg_init.mut_addr()) } else { ("", sugg_init.addr()) diff --git a/clippy_lints/src/misc_early/redundant_pattern.rs b/clippy_lints/src/misc_early/redundant_pattern.rs index 525dbf7757c1..d7bb0616acb0 100644 --- a/clippy_lints/src/misc_early/redundant_pattern.rs +++ b/clippy_lints/src/misc_early/redundant_pattern.rs @@ -1,18 +1,12 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use rustc_ast::ast::{BindingMode, Mutability, Pat, PatKind}; +use rustc_ast::ast::{Pat, PatKind}; use rustc_errors::Applicability; use rustc_lint::EarlyContext; use super::REDUNDANT_PATTERN; pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) { - if let PatKind::Ident(left, ident, Some(ref right)) = pat.kind { - let left_binding = match left { - BindingMode::ByRef(Mutability::Mut) => "ref mut ", - BindingMode::ByRef(Mutability::Not) => "ref ", - BindingMode::ByValue(..) => "", - }; - + if let PatKind::Ident(ann, ident, Some(ref right)) = pat.kind { if let PatKind::Wild = right.kind { span_lint_and_sugg( cx, @@ -23,7 +17,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) { ident.name, ident.name, ), "try", - format!("{}{}", left_binding, ident.name), + format!("{}{}", ann.prefix_str(), ident.name), Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/needless_arbitrary_self_type.rs b/clippy_lints/src/needless_arbitrary_self_type.rs index 9838d3cad9f0..f2ffac85bf40 100644 --- a/clippy_lints/src/needless_arbitrary_self_type.rs +++ b/clippy_lints/src/needless_arbitrary_self_type.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use if_chain::if_chain; -use rustc_ast::ast::{BindingMode, Lifetime, Mutability, Param, PatKind, Path, TyKind}; +use rustc_ast::ast::{BindingAnnotation, ByRef, Lifetime, Mutability, Param, PatKind, Path, TyKind}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -120,14 +120,14 @@ impl EarlyLintPass for NeedlessArbitrarySelfType { match &p.ty.kind { TyKind::Path(None, path) => { - if let PatKind::Ident(BindingMode::ByValue(mutbl), _, _) = p.pat.kind { + if let PatKind::Ident(BindingAnnotation(ByRef::No, mutbl), _, _) = p.pat.kind { check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Value, mutbl); } }, TyKind::Rptr(lifetime, mut_ty) => { if_chain! { if let TyKind::Path(None, path) = &mut_ty.ty.kind; - if let PatKind::Ident(BindingMode::ByValue(Mutability::Not), _, _) = p.pat.kind; + if let PatKind::Ident(BindingAnnotation::NONE, _, _) = p.pat.kind; then { check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Ref(*lifetime), mut_ty.mutbl); } diff --git a/clippy_lints/src/needless_borrowed_ref.rs b/clippy_lints/src/needless_borrowed_ref.rs index 05c012b92e87..b8855e5adbff 100644 --- a/clippy_lints/src/needless_borrowed_ref.rs +++ b/clippy_lints/src/needless_borrowed_ref.rs @@ -59,7 +59,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowedRef { if let PatKind::Ref(sub_pat, Mutability::Not) = pat.kind; // Check sub_pat got a `ref` keyword (excluding `ref mut`). - if let PatKind::Binding(BindingAnnotation::Ref, .., spanned_name, _) = sub_pat.kind; + if let PatKind::Binding(BindingAnnotation::REF, .., spanned_name, _) = sub_pat.kind; let parent_id = cx.tcx.hir().get_parent_node(pat.hir_id); if let Some(parent_node) = cx.tcx.hir().find(parent_id); then { diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs index ff2999b1f4a5..de99f1d7078e 100644 --- a/clippy_lints/src/needless_late_init.rs +++ b/clippy_lints/src/needless_late_init.rs @@ -373,7 +373,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit { if let Local { init: None, pat: &Pat { - kind: PatKind::Binding(BindingAnnotation::Unannotated, binding_id, _, None), + kind: PatKind::Binding(BindingAnnotation::NONE, binding_id, _, None), .. }, source: LocalSource::Normal, diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 0cbef1c95fe9..6d17c7a7346f 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -8,7 +8,9 @@ use rustc_ast::ast::Attribute; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{Applicability, Diagnostic}; use rustc_hir::intravisit::FnKind; -use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, Impl, ItemKind, Node, PatKind, QPath, TyKind}; +use rustc_hir::{ + BindingAnnotation, Body, FnDecl, GenericArg, HirId, Impl, ItemKind, Mutability, Node, PatKind, QPath, TyKind, +}; use rustc_hir::{HirIdMap, HirIdSet}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; @@ -188,13 +190,9 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { if !implements_borrow_trait; if !all_borrowable_trait; - if let PatKind::Binding(mode, canonical_id, ..) = arg.pat.kind; + if let PatKind::Binding(BindingAnnotation(_, Mutability::Not), canonical_id, ..) = arg.pat.kind; if !moved_vars.contains(&canonical_id); then { - if mode == BindingAnnotation::Mutable || mode == BindingAnnotation::RefMut { - continue; - } - // Dereference suggestion let sugg = |diag: &mut Diagnostic| { if let ty::Adt(def, ..) = ty.kind() { diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index 9602d0d1d2ea..0315678bf97a 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -130,7 +130,7 @@ fn try_get_option_occurence<'tcx>( .filter_map(|(id, &c)| none_captures.get(id).map(|&c2| (c, c2))) .all(|(x, y)| x.is_imm_ref() && y.is_imm_ref()); then { - let capture_mut = if bind_annotation == BindingAnnotation::Mutable { "mut " } else { "" }; + let capture_mut = if bind_annotation == BindingAnnotation::MUT { "mut " } else { "" }; let some_body = peel_blocks(if_then); let none_body = peel_blocks(if_else); let method_sugg = if eager_or_lazy::switch_to_eager_eval(cx, none_body) { "map_or" } else { "map_or_else" }; @@ -138,7 +138,7 @@ fn try_get_option_occurence<'tcx>( let (as_ref, as_mut) = match &expr.kind { ExprKind::AddrOf(_, Mutability::Not, _) => (true, false), ExprKind::AddrOf(_, Mutability::Mut, _) => (false, true), - _ => (bind_annotation == BindingAnnotation::Ref, bind_annotation == BindingAnnotation::RefMut), + _ => (bind_annotation == BindingAnnotation::REF, bind_annotation == BindingAnnotation::REF_MUT), }; // Check if captures the closure will need conflict with borrows made in the scrutinee. diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 5fa4fd74853f..0960b050c240 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -221,7 +221,7 @@ impl<'tcx> PassByRefOrValue { // if function has a body and parameter is annotated with mut, ignore if let Some(param) = fn_body.and_then(|body| body.params.get(index)) { match param.pat.kind { - PatKind::Binding(BindingAnnotation::Unannotated, _, _, _) => {}, + PatKind::Binding(BindingAnnotation::NONE, _, _, _) => {}, _ => continue, } } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 3c5ea2d94144..47b5ff7e0f04 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -571,7 +571,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: Some((Node::Stmt(_), _)) => (), Some((Node::Local(l), _)) => { // Only trace simple bindings. e.g `let x = y;` - if let PatKind::Binding(BindingAnnotation::Unannotated, id, _, None) = l.pat.kind { + if let PatKind::Binding(BindingAnnotation::NONE, id, _, None) = l.pat.kind { self.bindings.insert(id, args_idx); } else { set_skip_flag(); @@ -644,7 +644,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: .filter_map(|(i, arg)| { let param = &body.params[arg.idx]; match param.pat.kind { - PatKind::Binding(BindingAnnotation::Unannotated, id, _, None) + PatKind::Binding(BindingAnnotation::NONE, id, _, None) if !is_lint_allowed(cx, PTR_ARG, param.hir_id) => { Some((id, i)) diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index b432ccb1ee32..98a62e1b8670 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -9,7 +9,7 @@ use clippy_utils::{ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk}; -use rustc_hir::{BindingAnnotation, Expr, ExprKind, Node, PatKind, PathSegment, QPath}; +use rustc_hir::{BindingAnnotation, ByRef, Expr, ExprKind, Node, PatKind, PathSegment, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::Ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -123,7 +123,7 @@ fn check_if_let_some_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr: if let Some(higher::IfLet { let_pat, let_expr, if_then, if_else }) = higher::IfLet::hir(cx, expr); if !is_else_clause(cx.tcx, expr); if let PatKind::TupleStruct(ref path1, [field], None) = let_pat.kind; - if let PatKind::Binding(annot, bind_id, ident, None) = field.kind; + if let PatKind::Binding(BindingAnnotation(by_ref, _), bind_id, ident, None) = field.kind; let caller_ty = cx.typeck_results().expr_ty(let_expr); let if_block = IfBlockType::IfLet(path1, caller_ty, ident.name, let_expr, if_then, if_else); if (is_early_return(sym::Option, cx, &if_block) && path_to_local_id(peel_blocks(if_then), bind_id)) @@ -132,12 +132,11 @@ fn check_if_let_some_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr: then { let mut applicability = Applicability::MachineApplicable; let receiver_str = snippet_with_applicability(cx, let_expr.span, "..", &mut applicability); - let by_ref = matches!(annot, BindingAnnotation::Ref | BindingAnnotation::RefMut); let requires_semi = matches!(get_parent_node(cx.tcx, expr.hir_id), Some(Node::Stmt(_))); let sugg = format!( "{}{}?{}", receiver_str, - if by_ref { ".as_ref()" } else { "" }, + if by_ref == ByRef::Yes { ".as_ref()" } else { "" }, if requires_semi { ";" } else { "" } ); span_lint_and_sugg( diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index b59a25e3a400..3437d196b5d5 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -99,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for SlowVectorInit { // Matches statements which initializes vectors. For example: `let mut vec = Vec::with_capacity(10)` if_chain! { if let StmtKind::Local(local) = stmt.kind; - if let PatKind::Binding(BindingAnnotation::Mutable, local_id, _, None) = local.pat.kind; + if let PatKind::Binding(BindingAnnotation::MUT, local_id, _, None) = local.pat.kind; if let Some(init) = local.init; if let Some(len_arg) = Self::is_vec_with_capacity(cx, init); diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 04e2f301bfd8..fb73c386640b 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -137,12 +137,12 @@ fn insert_necessary_parens(pat: &mut P) { struct Visitor; impl MutVisitor for Visitor { fn visit_pat(&mut self, pat: &mut P) { - use ast::{BindingMode::*, Mutability::*}; + use ast::BindingAnnotation; noop_visit_pat(pat, self); let target = match &mut pat.kind { // `i @ a | b`, `box a | b`, and `& mut? a | b`. Ident(.., Some(p)) | Box(p) | Ref(p, _) if matches!(&p.kind, Or(ps) if ps.len() > 1) => p, - Ref(p, Not) if matches!(p.kind, Ident(ByValue(Mut), ..)) => p, // `&(mut x)` + Ref(p, Mutability::Not) if matches!(p.kind, Ident(BindingAnnotation::MUT, ..)) => p, // `&(mut x)` _ => return, }; target.kind = Paren(P(take_pat(target))); diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 429c64ac1564..a298c00caed0 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -6,7 +6,9 @@ use rustc_ast::ast::{LitFloatType, LitKind}; use rustc_ast::LitIntType; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; -use rustc_hir::{ArrayLen, Closure, ExprKind, FnRetTy, HirId, Lit, PatKind, QPath, StmtKind, TyKind}; +use rustc_hir::{ + ArrayLen, BindingAnnotation, Closure, ExprKind, FnRetTy, HirId, Lit, PatKind, QPath, StmtKind, TyKind, +}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::{Ident, Symbol}; @@ -609,10 +611,16 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { match pat.value.kind { PatKind::Wild => kind!("Wild"), - PatKind::Binding(anno, .., name, sub) => { + PatKind::Binding(ann, _, name, sub) => { bind!(self, name); opt_bind!(self, sub); - kind!("Binding(BindingAnnotation::{anno:?}, _, {name}, {sub})"); + let ann = match ann { + BindingAnnotation::NONE => "NONE", + BindingAnnotation::REF => "REF", + BindingAnnotation::MUT => "MUT", + BindingAnnotation::REF_MUT => "REF_MUT", + }; + kind!("Binding(BindingAnnotation::{ann}, _, {name}, {sub})"); self.ident(name); sub.if_some(|p| self.pat(p)); }, diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs index 35db45e2b0c9..627f65107002 100644 --- a/clippy_lints/src/vec_init_then_push.rs +++ b/clippy_lints/src/vec_init_then_push.rs @@ -157,7 +157,7 @@ impl<'tcx> LateLintPass<'tcx> for VecInitThenPush { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { if let Some(init_expr) = local.init - && let PatKind::Binding(BindingAnnotation::Mutable, id, name, None) = local.pat.kind + && let PatKind::Binding(BindingAnnotation::MUT, id, name, None) = local.pat.kind && !in_external_macro(cx.sess(), local.span) && let Some(init) = get_vec_init_kind(cx, init_expr) && !matches!(init, VecInitKind::WithExprCapacity(_)) diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 1834e2a2de87..e531dc29dccf 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -6,9 +6,9 @@ use rustc_data_structures::fx::FxHasher; use rustc_hir::def::Res; use rustc_hir::HirIdMap; use rustc_hir::{ - ArrayLen, BinOpKind, Block, BodyId, Closure, Expr, ExprField, ExprKind, FnRetTy, GenericArg, GenericArgs, Guard, - HirId, InlineAsmOperand, Let, Lifetime, LifetimeName, ParamName, Pat, PatField, PatKind, Path, PathSegment, QPath, - Stmt, StmtKind, Ty, TyKind, TypeBinding, + ArrayLen, BinOpKind, BindingAnnotation, Block, BodyId, Closure, Expr, ExprField, ExprKind, FnRetTy, GenericArg, + GenericArgs, Guard, HirId, InlineAsmOperand, Let, Lifetime, LifetimeName, ParamName, Pat, PatField, PatKind, Path, + PathSegment, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding, }; use rustc_lexer::{tokenize, TokenKind}; use rustc_lint::LateContext; @@ -815,8 +815,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { pub fn hash_pat(&mut self, pat: &Pat<'_>) { std::mem::discriminant(&pat.kind).hash(&mut self.s); match pat.kind { - PatKind::Binding(ann, _, _, pat) => { - std::mem::discriminant(&ann).hash(&mut self.s); + PatKind::Binding(BindingAnnotation(by_ref, mutability), _, _, pat) => { + std::mem::discriminant(&by_ref).hash(&mut self.s); + std::mem::discriminant(&mutability).hash(&mut self.s); if let Some(pat) = pat { self.hash_pat(pat); } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 997e773b5da4..839e6292f381 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -192,7 +192,7 @@ pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option< let hir = cx.tcx.hir(); if_chain! { if let Some(Node::Pat(pat)) = hir.find(hir_id); - if matches!(pat.kind, PatKind::Binding(BindingAnnotation::Unannotated, ..)); + if matches!(pat.kind, PatKind::Binding(BindingAnnotation::NONE, ..)); let parent = hir.get_parent_node(hir_id); if let Some(Node::Local(local)) = hir.find(parent); then { diff --git a/tests/ui/author.stdout b/tests/ui/author.stdout index 3125863036bb..597318a556b8 100644 --- a/tests/ui/author.stdout +++ b/tests/ui/author.stdout @@ -6,7 +6,7 @@ if_chain! { if match_qpath(qpath, &["char"]); if let ExprKind::Lit(ref lit) = expr.kind; if let LitKind::Int(69, LitIntType::Unsuffixed) = lit.node; - if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = local.pat.kind; + if let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind; if name.as_str() == "x"; then { // report your lint here diff --git a/tests/ui/author/blocks.stdout b/tests/ui/author/blocks.stdout index 2fc4a7d1f7fe..a529981e2e68 100644 --- a/tests/ui/author/blocks.stdout +++ b/tests/ui/author/blocks.stdout @@ -5,13 +5,13 @@ if_chain! { if let Some(init) = local.init; if let ExprKind::Lit(ref lit) = init.kind; if let LitKind::Int(42, LitIntType::Signed(IntTy::I32)) = lit.node; - if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = local.pat.kind; + if let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind; if name.as_str() == "x"; if let StmtKind::Local(local1) = block.stmts[1].kind; if let Some(init1) = local1.init; if let ExprKind::Lit(ref lit1) = init1.kind; if let LitKind::Float(_, LitFloatType::Suffixed(FloatTy::F32)) = lit1.node; - if let PatKind::Binding(BindingAnnotation::Unannotated, _, name1, None) = local1.pat.kind; + if let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local1.pat.kind; if name1.as_str() == "_t"; if let StmtKind::Semi(e) = block.stmts[2].kind; if let ExprKind::Unary(UnOp::Neg, inner) = e.kind; @@ -31,7 +31,7 @@ if_chain! { if let ExprKind::Path(ref qpath) = func.kind; if match_qpath(qpath, &["String", "new"]); if args.is_empty(); - if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = local.pat.kind; + if let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind; if name.as_str() == "expr"; if let Some(trailing_expr) = block.expr; if let ExprKind::Call(func1, args1) = trailing_expr.kind; diff --git a/tests/ui/author/loop.stdout b/tests/ui/author/loop.stdout index 3d9560f697a7..ceb53fcd4963 100644 --- a/tests/ui/author/loop.stdout +++ b/tests/ui/author/loop.stdout @@ -1,6 +1,6 @@ if_chain! { if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr); - if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = pat.kind; + if let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = pat.kind; if name.as_str() == "y"; if let ExprKind::Struct(qpath, fields, None) = arg.kind; if matches!(qpath, QPath::LangItem(LangItem::Range, _)); @@ -17,7 +17,7 @@ if_chain! { if let Some(init) = local.init; if let ExprKind::Path(ref qpath1) = init.kind; if match_qpath(qpath1, &["y"]); - if let PatKind::Binding(BindingAnnotation::Unannotated, _, name1, None) = local.pat.kind; + if let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local.pat.kind; if name1.as_str() == "z"; if block.expr.is_none(); then { diff --git a/tests/ui/author/matches.stdout b/tests/ui/author/matches.stdout index 38444a0094ca..2cf69a035b4c 100644 --- a/tests/ui/author/matches.stdout +++ b/tests/ui/author/matches.stdout @@ -21,7 +21,7 @@ if_chain! { if let Some(init1) = local1.init; if let ExprKind::Lit(ref lit4) = init1.kind; if let LitKind::Int(3, LitIntType::Unsuffixed) = lit4.node; - if let PatKind::Binding(BindingAnnotation::Unannotated, _, name, None) = local1.pat.kind; + if let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local1.pat.kind; if name.as_str() == "x"; if let Some(trailing_expr) = block.expr; if let ExprKind::Path(ref qpath) = trailing_expr.kind; @@ -30,7 +30,7 @@ if_chain! { if arms[2].guard.is_none(); if let ExprKind::Lit(ref lit5) = arms[2].body.kind; if let LitKind::Int(1, LitIntType::Unsuffixed) = lit5.node; - if let PatKind::Binding(BindingAnnotation::Unannotated, _, name1, None) = local.pat.kind; + if let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local.pat.kind; if name1.as_str() == "a"; then { // report your lint here From f2ccd07de0c628f0cfcbac177b51c9846c4b88f4 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 30 Aug 2022 15:10:28 +1000 Subject: [PATCH 0593/1222] Make `hir::PathSegment::res` non-optional. --- clippy_lints/src/operators/op_ref.rs | 2 +- clippy_lints/src/ref_option_ref.rs | 3 +-- clippy_lints/src/trait_bounds.rs | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/operators/op_ref.rs b/clippy_lints/src/operators/op_ref.rs index 1805672e3725..1085e6089441 100644 --- a/clippy_lints/src/operators/op_ref.rs +++ b/clippy_lints/src/operators/op_ref.rs @@ -185,7 +185,7 @@ fn in_impl<'tcx>( if let ItemKind::Impl(item) = &item.kind; if let Some(of_trait) = &item.of_trait; if let Some(seg) = of_trait.path.segments.last(); - if let Some(Res::Def(_, trait_id)) = seg.res; + if let Res::Def(_, trait_id) = seg.res; if trait_id == bin_op; if let Some(generic_args) = seg.args; if let Some(GenericArg::Type(other_ty)) = generic_args.args.last(); diff --git a/clippy_lints/src/ref_option_ref.rs b/clippy_lints/src/ref_option_ref.rs index 909d6971a549..42514f861be1 100644 --- a/clippy_lints/src/ref_option_ref.rs +++ b/clippy_lints/src/ref_option_ref.rs @@ -43,8 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for RefOptionRef { if mut_ty.mutbl == Mutability::Not; if let TyKind::Path(ref qpath) = &mut_ty.ty.kind; let last = last_path_segment(qpath); - if let Some(res) = last.res; - if let Some(def_id) = res.opt_def_id(); + if let Some(def_id) = last.res.opt_def_id(); if cx.tcx.is_diagnostic_item(sym::Option, def_id); if let Some(params) = last_path_segment(qpath).args ; diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 2ffa022b04f7..a25be93b8d61 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -128,7 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { if !bound_predicate.span.from_expansion(); if let TyKind::Path(QPath::Resolved(_, Path { segments, .. })) = bound_predicate.bounded_ty.kind; if let Some(PathSegment { - res: Some(Res::SelfTy{ trait_: Some(def_id), alias_to: _ }), .. + res: Res::SelfTy{ trait_: Some(def_id), alias_to: _ }, .. }) = segments.first(); if let Some( Node::Item( From d5ecb162ac91602bdf41f73cc2318fcb123fc291 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 5 Sep 2022 14:03:53 +1000 Subject: [PATCH 0594/1222] Pack `Term` in the same way as `GenericArg`. This shrinks the `PredicateS` type, which is instanted frequently. --- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/methods/mod.rs | 6 +++--- clippy_lints/src/methods/unnecessary_to_owned.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 1506ea604f0d..7e29257e36a3 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1174,7 +1174,7 @@ fn replace_types<'tcx>( if replaced.insert(param_ty.index) { for projection_predicate in projection_predicates { if projection_predicate.projection_ty.self_ty() == param_ty.to_ty(cx.tcx) - && let ty::Term::Ty(term_ty) = projection_predicate.term + && let Some(term_ty) = projection_predicate.term.ty() && let ty::Param(term_param_ty) = term_ty.kind() { let item_def_id = projection_predicate.projection_ty.item_def_id; diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index a0d190a58aff..46ffe59b2d14 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3302,9 +3302,9 @@ impl<'tcx> LateLintPass<'tcx> for Methods { // one of the associated types must be Self for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) { if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() { - let assoc_ty = match projection_predicate.term { - ty::Term::Ty(ty) => ty, - ty::Term::Const(_c) => continue, + let assoc_ty = match projection_predicate.term.unpack() { + ty::TermKind::Ty(ty) => ty, + ty::TermKind::Const(_c) => continue, }; // walk the associated type and check for Self if let Some(self_adt) = self_ty.ty_adt_def() { diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 44bf84352943..2dcb191555a4 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -268,7 +268,7 @@ fn check_other_call_arg<'tcx>( .subst_and_normalize_erasing_regions(call_substs, cx.param_env, projection_predicate.term); implements_trait(cx, receiver_ty, deref_trait_id, &[]) && get_associated_type(cx, receiver_ty, deref_trait_id, "Target") - .map_or(false, |ty| ty::Term::Ty(ty) == normalized_ty) + .map_or(false, |ty| ty::TermKind::Ty(ty) == normalized_ty.unpack()) } else { false } From 81f5658e12ffe193e79a03dafe35aeefa15ed6b2 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Thu, 1 Sep 2022 18:43:35 +0900 Subject: [PATCH 0595/1222] separate the receiver from arguments in HIR under /clippy --- .../development/common_tools_writing_lints.md | 2 +- .../src/assertions_on_result_states.rs | 2 +- clippy_lints/src/blocks_in_if_conditions.rs | 5 +- clippy_lints/src/booleans.rs | 6 +- .../src/casts/cast_abs_to_unsigned.rs | 4 +- .../src/casts/cast_possible_truncation.rs | 6 +- clippy_lints/src/casts/cast_ptr_alignment.rs | 4 +- clippy_lints/src/casts/cast_sign_loss.rs | 4 +- clippy_lints/src/default_numeric_fallback.rs | 23 ++-- clippy_lints/src/dereference.rs | 47 ++++---- clippy_lints/src/doc.rs | 2 +- clippy_lints/src/entry.rs | 4 +- clippy_lints/src/eta_reduction.rs | 25 +++-- clippy_lints/src/explicit_write.rs | 4 +- clippy_lints/src/fallible_impl_from.rs | 2 +- clippy_lints/src/floating_point_arithmetic.rs | 79 +++++++------- clippy_lints/src/format_args.rs | 20 ++-- clippy_lints/src/format_impl.rs | 2 +- clippy_lints/src/format_push_string.rs | 2 +- clippy_lints/src/functions/must_use.rs | 20 +++- .../src/functions/not_unsafe_ptr_arg_deref.rs | 3 +- clippy_lints/src/if_let_mutex.rs | 2 +- clippy_lints/src/infinite_iter.rs | 100 +++++++++--------- clippy_lints/src/len_zero.rs | 10 +- clippy_lints/src/loops/manual_memcpy.rs | 4 +- clippy_lints/src/loops/missing_spin_loop.rs | 2 +- clippy_lints/src/loops/mod.rs | 2 +- clippy_lints/src/loops/needless_collect.rs | 14 +-- clippy_lints/src/loops/needless_range_loop.rs | 11 +- clippy_lints/src/loops/never_loop.rs | 5 +- clippy_lints/src/loops/same_item_push.rs | 5 +- clippy_lints/src/loops/single_element_loop.rs | 33 +++--- clippy_lints/src/loops/while_let_loop.rs | 9 +- .../src/loops/while_let_on_iterator.rs | 2 +- clippy_lints/src/manual_bits.rs | 2 +- clippy_lints/src/manual_retain.rs | 22 ++-- clippy_lints/src/manual_string_new.rs | 13 +-- clippy_lints/src/manual_strip.rs | 4 +- clippy_lints/src/map_unit_fn.rs | 11 +- clippy_lints/src/match_result_ok.rs | 2 +- .../src/matches/match_str_case_mismatch.rs | 2 +- .../src/matches/redundant_pattern_match.rs | 2 +- .../matches/significant_drop_in_scrutinee.rs | 5 +- clippy_lints/src/methods/bytecount.rs | 6 +- clippy_lints/src/methods/chars_cmp.rs | 4 +- .../src/methods/chars_cmp_with_unwrap.rs | 2 +- clippy_lints/src/methods/clone_on_copy.rs | 14 ++- clippy_lints/src/methods/clone_on_ref_ptr.rs | 12 ++- .../src/methods/collapsible_str_replace.rs | 6 +- clippy_lints/src/methods/expect_fun_call.rs | 24 ++--- clippy_lints/src/methods/extend_with_drain.rs | 2 +- clippy_lints/src/methods/filter_map.rs | 12 +-- clippy_lints/src/methods/get_last_with_len.rs | 2 +- .../src/methods/inefficient_to_string.rs | 14 ++- clippy_lints/src/methods/into_iter_on_ref.rs | 4 +- clippy_lints/src/methods/iter_with_drain.rs | 2 +- clippy_lints/src/methods/map_clone.rs | 2 +- clippy_lints/src/methods/mod.rs | 96 +++++++++-------- clippy_lints/src/methods/open_options.rs | 10 +- .../src/methods/option_as_ref_deref.rs | 7 +- clippy_lints/src/methods/or_fun_call.rs | 7 +- .../src/methods/range_zip_with_len.rs | 2 +- .../src/methods/single_char_add_str.rs | 6 +- .../src/methods/single_char_insert_string.rs | 8 +- .../src/methods/single_char_pattern.rs | 58 +++++----- .../src/methods/single_char_push_string.rs | 6 +- clippy_lints/src/methods/str_splitn.rs | 6 +- .../src/methods/string_extend_chars.rs | 2 +- .../src/methods/unnecessary_iter_cloned.rs | 2 +- .../src/methods/unnecessary_lazy_eval.rs | 2 +- .../src/methods/unnecessary_sort_by.rs | 8 +- .../src/methods/unnecessary_to_owned.rs | 22 ++-- clippy_lints/src/methods/utils.rs | 6 +- clippy_lints/src/minmax.rs | 35 +++--- clippy_lints/src/mut_reference.rs | 14 ++- clippy_lints/src/needless_for_each.rs | 4 +- .../src/non_octal_unix_permissions.rs | 2 +- clippy_lints/src/only_used_in_recursion.rs | 4 +- clippy_lints/src/operators/cmp_owned.rs | 2 +- clippy_lints/src/operators/duration_subsec.rs | 2 +- clippy_lints/src/operators/float_cmp.rs | 2 +- clippy_lints/src/ptr.rs | 7 +- clippy_lints/src/ptr_offset_with_cast.rs | 2 +- clippy_lints/src/question_mark.rs | 2 +- clippy_lints/src/read_zero_byte_vec.rs | 2 +- clippy_lints/src/size_of_in_element_count.rs | 2 +- .../src/slow_vector_initialization.rs | 10 +- clippy_lints/src/strings.rs | 28 ++--- clippy_lints/src/strlen_on_c_strings.rs | 2 +- clippy_lints/src/to_digit_is_some.rs | 10 +- clippy_lints/src/uninit_vec.rs | 4 +- clippy_lints/src/unit_return_expecting_ord.rs | 3 +- clippy_lints/src/unit_types/let_unit_value.rs | 13 ++- clippy_lints/src/unit_types/unit_arg.rs | 39 +++---- clippy_lints/src/unused_io_amount.rs | 8 +- clippy_lints/src/unused_peekable.rs | 3 +- clippy_lints/src/unwrap.rs | 10 +- clippy_lints/src/unwrap_in_result.rs | 4 +- clippy_lints/src/useless_conversion.rs | 2 +- clippy_lints/src/utils/author.rs | 7 +- clippy_lints/src/utils/internal_lints.rs | 2 +- clippy_lints/src/vec_init_then_push.rs | 4 +- clippy_utils/src/check_proc_macro.rs | 4 +- clippy_utils/src/diagnostics.rs | 8 +- clippy_utils/src/eager_or_lazy.rs | 18 ++-- clippy_utils/src/hir_utils.rs | 13 ++- clippy_utils/src/lib.rs | 26 ++--- clippy_utils/src/ptr.rs | 2 +- clippy_utils/src/sugg.rs | 24 +++-- clippy_utils/src/visitors.rs | 8 +- tests/ui/author/struct.stdout | 6 +- 111 files changed, 662 insertions(+), 558 deletions(-) diff --git a/book/src/development/common_tools_writing_lints.md b/book/src/development/common_tools_writing_lints.md index 15e00c7d7ce4..2bc275ceff0b 100644 --- a/book/src/development/common_tools_writing_lints.md +++ b/book/src/development/common_tools_writing_lints.md @@ -66,7 +66,7 @@ Starting with an `expr`, you can check whether it is calling a specific method impl<'tcx> LateLintPass<'tcx> for MyStructLint { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { // Check our expr is calling a method - if let hir::ExprKind::MethodCall(path, _, [_self_arg, ..]) = &expr.kind + if let hir::ExprKind::MethodCall(path, _, _self_arg, ..) = &expr.kind // Check the name of this method is `some_method` && path.ident.name == sym!(some_method) // Optionally, check the type of the self argument. diff --git a/clippy_lints/src/assertions_on_result_states.rs b/clippy_lints/src/assertions_on_result_states.rs index 6a6554f968b3..7cd198ace86c 100644 --- a/clippy_lints/src/assertions_on_result_states.rs +++ b/clippy_lints/src/assertions_on_result_states.rs @@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates { && matches!(cx.tcx.get_diagnostic_name(macro_call.def_id), Some(sym::assert_macro)) && let Some((condition, panic_expn)) = find_assert_args(cx, e, macro_call.expn) && matches!(panic_expn, PanicExpn::Empty) - && let ExprKind::MethodCall(method_segment, [recv], _) = condition.kind + && let ExprKind::MethodCall(method_segment, recv, [], _) = condition.kind && let result_type_with_refs = cx.typeck_results().expr_ty(recv) && let result_type = result_type_with_refs.peel_refs() && is_type_diagnostic_item(cx, result_type, sym::Result) diff --git a/clippy_lints/src/blocks_in_if_conditions.rs b/clippy_lints/src/blocks_in_if_conditions.rs index ad206b5fb304..d9e2c9c8578f 100644 --- a/clippy_lints/src/blocks_in_if_conditions.rs +++ b/clippy_lints/src/blocks_in_if_conditions.rs @@ -55,7 +55,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> { // do not lint if the closure is called using an iterator (see #1141) if_chain! { if let Some(parent) = get_parent_expr(self.cx, expr); - if let ExprKind::MethodCall(_, [self_arg, ..], _) = &parent.kind; + if let ExprKind::MethodCall(_, self_arg, ..) = &parent.kind; let caller = self.cx.typeck_results().expr_ty(self_arg); if let Some(iter_id) = self.cx.tcx.get_diagnostic_item(sym::Iterator); if implements_trait(self.cx, caller, iter_id, &[]); @@ -117,7 +117,8 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInIfConditions { ); } } else { - let span = block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span); + 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; } diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 6eb78d21e826..656d639f0efd 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -270,8 +270,8 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { )) }) }, - ExprKind::MethodCall(path, args, _) if args.len() == 1 => { - let type_of_receiver = cx.typeck_results().expr_ty(&args[0]); + ExprKind::MethodCall(path, receiver, [], _) => { + let type_of_receiver = cx.typeck_results().expr_ty(receiver); if !is_type_diagnostic_item(cx, type_of_receiver, sym::Option) && !is_type_diagnostic_item(cx, type_of_receiver, sym::Result) { @@ -285,7 +285,7 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { let path: &str = path.ident.name.as_str(); a == path }) - .and_then(|(_, neg_method)| Some(format!("{}.{}()", snippet_opt(cx, args[0].span)?, neg_method))) + .and_then(|(_, neg_method)| Some(format!("{}.{}()", snippet_opt(cx, receiver.span)?, neg_method))) }, _ => None, } diff --git a/clippy_lints/src/casts/cast_abs_to_unsigned.rs b/clippy_lints/src/casts/cast_abs_to_unsigned.rs index 6426e8c25ac1..3f1edabe6c50 100644 --- a/clippy_lints/src/casts/cast_abs_to_unsigned.rs +++ b/clippy_lints/src/casts/cast_abs_to_unsigned.rs @@ -20,7 +20,7 @@ pub(super) fn check( if meets_msrv(msrv, msrvs::UNSIGNED_ABS) && let ty::Int(from) = cast_from.kind() && let ty::Uint(to) = cast_to.kind() - && let ExprKind::MethodCall(method_path, args, _) = cast_expr.kind + && let ExprKind::MethodCall(method_path, receiver, ..) = cast_expr.kind && method_path.ident.name.as_str() == "abs" { let span = if from.bit_width() == to.bit_width() { @@ -37,7 +37,7 @@ pub(super) fn check( span, &format!("casting the result of `{cast_from}::abs()` to {cast_to}"), "replace with", - format!("{}.unsigned_abs()", Sugg::hir(cx, &args[0], "..").maybe_par()), + format!("{}.unsigned_abs()", Sugg::hir(cx, receiver, "..").maybe_par()), Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/casts/cast_possible_truncation.rs b/clippy_lints/src/casts/cast_possible_truncation.rs index 64f87c80f8d1..406547a4454e 100644 --- a/clippy_lints/src/casts/cast_possible_truncation.rs +++ b/clippy_lints/src/casts/cast_possible_truncation.rs @@ -44,7 +44,7 @@ fn apply_reductions(cx: &LateContext<'_>, nbits: u64, expr: &Expr<'_>, signed: b .saturating_sub(constant_int(cx, right).map_or(0, |s| u64::try_from(s).expect("shift too high"))), _ => nbits, }, - ExprKind::MethodCall(method, [left, right], _) => { + ExprKind::MethodCall(method, left, [right], _) => { if signed { return nbits; } @@ -55,7 +55,7 @@ fn apply_reductions(cx: &LateContext<'_>, nbits: u64, expr: &Expr<'_>, signed: b }; apply_reductions(cx, nbits, left, signed).min(max_bits.unwrap_or(u64::max_value())) }, - ExprKind::MethodCall(method, [_, lo, hi], _) => { + ExprKind::MethodCall(method, _, [lo, hi], _) => { if method.ident.as_str() == "clamp" { //FIXME: make this a diagnostic item if let (Some(lo_bits), Some(hi_bits)) = (get_constant_bits(cx, lo), get_constant_bits(cx, hi)) { @@ -64,7 +64,7 @@ fn apply_reductions(cx: &LateContext<'_>, nbits: u64, expr: &Expr<'_>, signed: b } nbits }, - ExprKind::MethodCall(method, [_value], _) => { + ExprKind::MethodCall(method, _value, [], _) => { if method.ident.name.as_str() == "signum" { 0 // do not lint if cast comes from a `signum` function } else { diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index d476a1a7646c..da7b12f67266 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -18,7 +18,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { cx.typeck_results().expr_ty(expr), ); lint_cast_ptr_alignment(cx, expr, cast_from, cast_to); - } else if let ExprKind::MethodCall(method_path, [self_arg, ..], _) = &expr.kind { + } else if let ExprKind::MethodCall(method_path, self_arg, ..) = &expr.kind { if method_path.ident.name == sym!(cast) && let Some(generic_args) = method_path.args && let [GenericArg::Type(cast_to)] = generic_args.args @@ -64,7 +64,7 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { return false; }; match parent.kind { - ExprKind::MethodCall(name, [self_arg, ..], _) if self_arg.hir_id == e.hir_id => { + ExprKind::MethodCall(name, self_arg, ..) if self_arg.hir_id == e.hir_id => { if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned") && let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id) && let Some(def_id) = cx.tcx.impl_of_method(def_id) diff --git a/clippy_lints/src/casts/cast_sign_loss.rs b/clippy_lints/src/casts/cast_sign_loss.rs index 75f70b77ed4e..5b59350be042 100644 --- a/clippy_lints/src/casts/cast_sign_loss.rs +++ b/clippy_lints/src/casts/cast_sign_loss.rs @@ -41,14 +41,14 @@ fn should_lint(cx: &LateContext<'_>, cast_op: &Expr<'_>, cast_from: Ty<'_>, cast } // Don't lint for the result of methods that always return non-negative values. - if let ExprKind::MethodCall(path, _, _) = cast_op.kind { + if let ExprKind::MethodCall(path, ..) = cast_op.kind { let mut method_name = path.ident.name.as_str(); let allowed_methods = ["abs", "checked_abs", "rem_euclid", "checked_rem_euclid"]; if_chain! { if method_name == "unwrap"; if let Some(arglist) = method_chain_args(cast_op, &["unwrap"]); - if let ExprKind::MethodCall(inner_path, _, _) = &arglist[0][0].kind; + if let ExprKind::MethodCall(inner_path, ..) = &arglist[0].0.kind; then { method_name = inner_path.ident.name.as_str(); } diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index fb418a3251f5..64c5de510420 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -69,10 +69,7 @@ struct NumericFallbackVisitor<'a, 'tcx> { impl<'a, 'tcx> NumericFallbackVisitor<'a, 'tcx> { fn new(cx: &'a LateContext<'tcx>) -> Self { - Self { - ty_bounds: vec![TyBound::Nothing], - cx, - } + Self { ty_bounds: vec![TyBound::Nothing], cx } } /// Check whether a passed literal has potential to cause fallback or not. @@ -129,19 +126,21 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { } return; } - }, + } - ExprKind::MethodCall(_, args, _) => { + ExprKind::MethodCall(_, receiver, args, _) => { if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) { let fn_sig = self.cx.tcx.fn_sig(def_id).skip_binder(); - for (expr, bound) in iter::zip(*args, fn_sig.inputs()) { + for (expr, bound) in + iter::zip(std::iter::once(*receiver).chain(args.iter()), fn_sig.inputs()) + { self.ty_bounds.push(TyBound::Ty(*bound)); self.visit_expr(expr); self.ty_bounds.pop(); } return; } - }, + } ExprKind::Struct(_, fields, base) => { let ty = self.cx.typeck_results().expr_ty(expr); @@ -176,15 +175,15 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { return; } } - }, + } ExprKind::Lit(lit) => { let ty = self.cx.typeck_results().expr_ty(expr); self.check_lit(lit, ty, expr.hir_id); return; - }, + } - _ => {}, + _ => {} } walk_expr(self, expr); @@ -198,7 +197,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { } else { self.ty_bounds.push(TyBound::Nothing); } - }, + } _ => self.ty_bounds.push(TyBound::Nothing), } diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 1506ea604f0d..fd6ed36cb192 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -581,7 +581,7 @@ fn try_parse_ref_op<'tcx>( expr: &'tcx Expr<'_>, ) -> Option<(RefOp, &'tcx Expr<'tcx>)> { let (def_id, arg) = match expr.kind { - ExprKind::MethodCall(_, [arg], _) => (typeck.type_dependent_def_id(expr.hir_id)?, arg), + ExprKind::MethodCall(_, arg, [], _) => (typeck.type_dependent_def_id(expr.hir_id)?, arg), ExprKind::Call( Expr { kind: ExprKind::Path(path), @@ -796,16 +796,19 @@ fn walk_parents<'tcx>( }, }) }), - ExprKind::MethodCall(_, args, _) => { + ExprKind::MethodCall(_, receiver, args, _) => { let id = cx.typeck_results().type_dependent_def_id(parent.hir_id).unwrap(); - args.iter().position(|arg| arg.hir_id == child_id).map(|i| { - if i == 0 { - // Check for calls to trait methods where the trait is implemented on a reference. - // Two cases need to be handled: - // * `self` methods on `&T` will never have auto-borrow - // * `&self` methods on `&T` can have auto-borrow, but `&self` methods on `T` will take - // priority. - if e.hir_id != child_id { + std::iter::once(receiver) + .chain(args.iter()) + .position(|arg| arg.hir_id == child_id) + .map(|i| { + if i == 0 { + // Check for calls to trait methods where the trait is implemented on a reference. + // Two cases need to be handled: + // * `self` methods on `&T` will never have auto-borrow + // * `&self` methods on `&T` can have auto-borrow, but `&self` methods on `T` will take + // priority. + if e.hir_id != child_id { Position::ReborrowStable(precedence) } else if let Some(trait_id) = cx.tcx.trait_of_item(id) && let arg_ty = cx.tcx.erase_regions(cx.typeck_results().expr_ty_adjusted(e)) @@ -834,20 +837,20 @@ fn walk_parents<'tcx>( } else { Position::MethodReceiver } - } else { - let ty = cx.tcx.fn_sig(id).skip_binder().inputs()[i]; - if let ty::Param(param_ty) = ty.kind() { - needless_borrow_impl_arg_position(cx, parent, i, *param_ty, e, precedence, msrv) } else { - ty_auto_deref_stability( - cx, - cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).input(i)), - precedence, - ) - .position_for_arg() + let ty = cx.tcx.fn_sig(id).skip_binder().inputs()[i]; + if let ty::Param(param_ty) = ty.kind() { + needless_borrow_impl_arg_position(cx, parent, i, *param_ty, e, precedence, msrv) + } else { + ty_auto_deref_stability( + cx, + cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).input(i)), + precedence, + ) + .position_for_arg() + } } - } - }) + }) }, ExprKind::Field(child, name) if child.hir_id == e.hir_id => Some(Position::FieldAccess(name.name)), ExprKind::Unary(UnOp::Deref, child) if child.hir_id == e.hir_id => Some(Position::Deref), diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index da111e7378ea..512872cedc1e 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -828,7 +828,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> { // check for `unwrap` if let Some(arglists) = method_chain_args(expr, &["unwrap"]) { - let receiver_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); + let receiver_ty = self.typeck_results.expr_ty(&arglists[0].0).peel_refs(); if is_type_diagnostic_item(self.cx, receiver_ty, sym::Option) || is_type_diagnostic_item(self.cx, receiver_ty, sym::Result) { diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 4e3ae4c96141..e70df3f53c75 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -245,8 +245,8 @@ fn try_parse_contains<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Optio match expr.kind { ExprKind::MethodCall( _, + map, [ - map, Expr { kind: ExprKind::AddrOf(_, _, key), span: key_span, @@ -280,7 +280,7 @@ struct InsertExpr<'tcx> { value: &'tcx Expr<'tcx>, } fn try_parse_insert<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option> { - if let ExprKind::MethodCall(_, [map, key, value], _) = expr.kind { + if let ExprKind::MethodCall(_, map, [key, value], _) = expr.kind { let id = cx.typeck_results().type_dependent_def_id(expr.hir_id)?; if match_def_path(cx, id, &paths::BTREEMAP_INSERT) || match_def_path(cx, id, &paths::HASHMAP_INSERT) { Some(InsertExpr { map, key, value }) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 4f9ff97f1fd1..1c0a93c71fde 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -106,7 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { if !is_adjusted(cx, &body.value); if let ExprKind::Call(callee, args) = body.value.kind; if let ExprKind::Path(_) = callee.kind; - if check_inputs(cx, body.params, args); + if check_inputs(cx, body.params, None, args); let callee_ty = cx.typeck_results().expr_ty_adjusted(callee); let call_ty = cx.typeck_results().type_dependent_def_id(body.value.hir_id) .map_or(callee_ty, |id| cx.tcx.type_of(id)); @@ -146,8 +146,8 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { if_chain!( if !is_adjusted(cx, &body.value); - if let ExprKind::MethodCall(path, args, _) = body.value.kind; - if check_inputs(cx, body.params, args); + if let ExprKind::MethodCall(path, receiver, args, _) = body.value.kind; + if check_inputs(cx, body.params, Some(receiver), args); let method_def_id = cx.typeck_results().type_dependent_def_id(body.value.hir_id).unwrap(); let substs = cx.typeck_results().node_substs(body.value.hir_id); let call_ty = cx.tcx.bound_type_of(method_def_id).subst(cx.tcx, substs); @@ -167,12 +167,17 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { } } -fn check_inputs(cx: &LateContext<'_>, params: &[Param<'_>], call_args: &[Expr<'_>]) -> bool { - if params.len() != call_args.len() { +fn check_inputs( + cx: &LateContext<'_>, + params: &[Param<'_>], + receiver: Option<&Expr<'_>>, + call_args: &[Expr<'_>], +) -> bool { + if receiver.map_or(params.len() != call_args.len(), |_| params.len() != call_args.len() + 1) { return false; } let binding_modes = cx.typeck_results().pat_binding_modes(); - std::iter::zip(params, call_args).all(|(param, arg)| { + let check_inputs = |param: &Param<'_>, arg| { match param.pat.kind { PatKind::Binding(_, id, ..) if path_to_local_id(arg, id) => {}, _ => return false, @@ -200,7 +205,13 @@ fn check_inputs(cx: &LateContext<'_>, params: &[Param<'_>], call_args: &[Expr<'_ }, _ => false, } - }) + }; + if let Some(receiver) = receiver { + std::iter::zip(params, std::iter::once(receiver).chain(call_args.iter())) + .all(|(param, arg)| check_inputs(param, arg)) + } else { + std::iter::zip(params, call_args).all(|(param, arg)| check_inputs(param, arg)) + } } fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure_ty: Ty<'tcx>, call_ty: Ty<'tcx>) -> bool { diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 5bf4313b41a4..9c76f63f5f75 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -45,10 +45,10 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if_chain! { // match call to unwrap - if let ExprKind::MethodCall(unwrap_fun, [write_call], _) = expr.kind; + if let ExprKind::MethodCall(unwrap_fun, write_call, [], _) = expr.kind; if unwrap_fun.ident.name == sym::unwrap; // match call to write_fmt - if let ExprKind::MethodCall(write_fun, [write_recv, write_arg], _) = look_in_block(cx, &write_call.kind); + if let ExprKind::MethodCall(write_fun, write_recv, [write_arg], _) = look_in_block(cx, &write_call.kind); if write_fun.ident.name == sym!(write_fmt); // match calls to std::io::stdout() / std::io::stderr () if let Some(dest_name) = if match_function_call(cx, write_recv, &paths::STDOUT).is_some() { diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index b88e53aeca69..790eea63f58c 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -84,7 +84,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h // check for `unwrap` if let Some(arglists) = method_chain_args(expr, &["unwrap"]) { - let receiver_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); + let receiver_ty = self.typeck_results.expr_ty(&arglists[0].0).peel_refs(); if is_type_diagnostic_item(self.lcx, receiver_ty, sym::Option) || is_type_diagnostic_item(self.lcx, receiver_ty, sym::Result) { diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs index bb50e8fcabbb..728db41d6004 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -164,15 +164,15 @@ fn prepare_receiver_sugg<'a>(cx: &LateContext<'_>, mut expr: &'a Expr<'a>) -> Su suggestion.maybe_par() } -fn check_log_base(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { - if let Some(method) = get_specialized_log_method(cx, &args[1]) { +fn check_log_base(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args: &[Expr<'_>]) { + if let Some(method) = get_specialized_log_method(cx, &args[0]) { span_lint_and_sugg( cx, SUBOPTIMAL_FLOPS, expr.span, "logarithm for bases 2, 10 and e can be computed more accurately", "consider using", - format!("{}.{}()", Sugg::hir(cx, &args[0], "..").maybe_par(), method), + format!("{}.{}()", Sugg::hir(cx, receiver, "..").maybe_par(), method), Applicability::MachineApplicable, ); } @@ -180,14 +180,14 @@ fn check_log_base(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { // TODO: Lint expressions of the form `(x + y).ln()` where y > 1 and // suggest usage of `(x + (y - 1)).ln_1p()` instead -fn check_ln1p(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { +fn check_ln1p(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>) { if let ExprKind::Binary( Spanned { node: BinOpKind::Add, .. }, lhs, rhs, - ) = &args[0].kind + ) = receiver.kind { let recv = match ( constant(cx, cx.typeck_results(), lhs), @@ -235,9 +235,9 @@ fn get_integer_from_float_constant(value: &Constant) -> Option { } } -fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { +fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args: &[Expr<'_>]) { // Check receiver - if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[0]) { + if let Some((value, _)) = constant(cx, cx.typeck_results(), receiver) { let method = if F32(f32_consts::E) == value || F64(f64_consts::E) == value { "exp" } else if F32(2.0) == value || F64(2.0) == value { @@ -252,24 +252,24 @@ fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { expr.span, "exponent for bases 2 and e can be computed more accurately", "consider using", - format!("{}.{}()", prepare_receiver_sugg(cx, &args[1]), method), + format!("{}.{}()", prepare_receiver_sugg(cx, &args[0]), method), Applicability::MachineApplicable, ); } // Check argument - if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[1]) { + if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[0]) { let (lint, help, suggestion) = if F32(1.0 / 2.0) == value || F64(1.0 / 2.0) == value { ( SUBOPTIMAL_FLOPS, "square-root of a number can be computed more efficiently and accurately", - format!("{}.sqrt()", Sugg::hir(cx, &args[0], "..").maybe_par()), + format!("{}.sqrt()", Sugg::hir(cx, receiver, "..").maybe_par()), ) } else if F32(1.0 / 3.0) == value || F64(1.0 / 3.0) == value { ( IMPRECISE_FLOPS, "cube-root of a number can be computed more accurately", - format!("{}.cbrt()", Sugg::hir(cx, &args[0], "..").maybe_par()), + format!("{}.cbrt()", Sugg::hir(cx, receiver, "..").maybe_par()), ) } else if let Some(exponent) = get_integer_from_float_constant(&value) { ( @@ -277,7 +277,7 @@ fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { "exponentiation with integer powers can be computed more efficiently", format!( "{}.powi({})", - Sugg::hir(cx, &args[0], "..").maybe_par(), + Sugg::hir(cx, receiver, "..").maybe_par(), numeric_literal::format(&exponent.to_string(), None, false) ), ) @@ -297,13 +297,14 @@ fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { } } -fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { - if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[1]) { +fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args: &[Expr<'_>]) { + if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[0]) { if value == Int(2) { if let Some(parent) = get_parent_expr(cx, expr) { if let Some(grandparent) = get_parent_expr(cx, parent) { - if let ExprKind::MethodCall(PathSegment { ident: method_name, .. }, args, _) = grandparent.kind { - if method_name.as_str() == "sqrt" && detect_hypot(cx, args).is_some() { + if let ExprKind::MethodCall(PathSegment { ident: method_name, .. }, receiver, ..) = grandparent.kind + { + if method_name.as_str() == "sqrt" && detect_hypot(cx, receiver).is_some() { return; } } @@ -327,8 +328,8 @@ fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { "consider using", format!( "{}.mul_add({}, {})", - Sugg::hir(cx, &args[0], "..").maybe_par(), - Sugg::hir(cx, &args[0], ".."), + Sugg::hir(cx, receiver, "..").maybe_par(), + Sugg::hir(cx, receiver, ".."), Sugg::hir(cx, other_addend, ".."), ), Applicability::MachineApplicable, @@ -339,14 +340,14 @@ fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { } } -fn detect_hypot(cx: &LateContext<'_>, args: &[Expr<'_>]) -> Option { +fn detect_hypot(cx: &LateContext<'_>, receiver: &Expr<'_>) -> Option { if let ExprKind::Binary( Spanned { node: BinOpKind::Add, .. }, add_lhs, add_rhs, - ) = args[0].kind + ) = receiver.kind { // check if expression of the form x * x + y * y if_chain! { @@ -363,12 +364,12 @@ fn detect_hypot(cx: &LateContext<'_>, args: &[Expr<'_>]) -> Option { if_chain! { if let ExprKind::MethodCall( PathSegment { ident: lmethod_name, .. }, - [largs_0, largs_1, ..], + largs_0, [largs_1, ..], _ ) = &add_lhs.kind; if let ExprKind::MethodCall( PathSegment { ident: rmethod_name, .. }, - [rargs_0, rargs_1, ..], + rargs_0, [rargs_1, ..], _ ) = &add_rhs.kind; if lmethod_name.as_str() == "powi" && rmethod_name.as_str() == "powi"; @@ -384,8 +385,8 @@ fn detect_hypot(cx: &LateContext<'_>, args: &[Expr<'_>]) -> Option { None } -fn check_hypot(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) { - if let Some(message) = detect_hypot(cx, args) { +fn check_hypot(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>) { + if let Some(message) = detect_hypot(cx, receiver) { span_lint_and_sugg( cx, IMPRECISE_FLOPS, @@ -406,7 +407,7 @@ fn check_expm1(cx: &LateContext<'_>, expr: &Expr<'_>) { if cx.typeck_results().expr_ty(lhs).is_floating_point(); if let Some((value, _)) = constant(cx, cx.typeck_results(), rhs); if F32(1.0) == value || F64(1.0) == value; - if let ExprKind::MethodCall(path, [self_arg, ..], _) = &lhs.kind; + if let ExprKind::MethodCall(path, self_arg, ..) = &lhs.kind; if cx.typeck_results().expr_ty(self_arg).is_floating_point(); if path.ident.name.as_str() == "exp"; then { @@ -450,8 +451,8 @@ fn check_mul_add(cx: &LateContext<'_>, expr: &Expr<'_>) { ) = &expr.kind { if let Some(parent) = get_parent_expr(cx, expr) { - if let ExprKind::MethodCall(PathSegment { ident: method_name, .. }, args, _) = parent.kind { - if method_name.as_str() == "sqrt" && detect_hypot(cx, args).is_some() { + if let ExprKind::MethodCall(PathSegment { ident: method_name, .. }, receiver, ..) = parent.kind { + if method_name.as_str() == "sqrt" && detect_hypot(cx, receiver).is_some() { return; } } @@ -586,14 +587,14 @@ fn check_custom_abs(cx: &LateContext<'_>, expr: &Expr<'_>) { fn are_same_base_logs(cx: &LateContext<'_>, expr_a: &Expr<'_>, expr_b: &Expr<'_>) -> bool { if_chain! { - if let ExprKind::MethodCall(PathSegment { ident: method_name_a, .. }, args_a, _) = expr_a.kind; - if let ExprKind::MethodCall(PathSegment { ident: method_name_b, .. }, args_b, _) = expr_b.kind; + if let ExprKind::MethodCall(PathSegment { ident: method_name_a, .. }, _, args_a, _) = expr_a.kind; + if let ExprKind::MethodCall(PathSegment { ident: method_name_b, .. }, _, args_b, _) = expr_b.kind; then { return method_name_a.as_str() == method_name_b.as_str() && args_a.len() == args_b.len() && ( ["ln", "log2", "log10"].contains(&method_name_a.as_str()) || - method_name_a.as_str() == "log" && args_a.len() == 2 && eq_expr_value(cx, &args_a[1], &args_b[1]) + method_name_a.as_str() == "log" && args_a.len() == 1 && eq_expr_value(cx, &args_a[0], &args_b[0]) ); } } @@ -612,8 +613,8 @@ fn check_log_division(cx: &LateContext<'_>, expr: &Expr<'_>) { rhs, ) = &expr.kind; if are_same_base_logs(cx, lhs, rhs); - if let ExprKind::MethodCall(_, [largs_self, ..], _) = &lhs.kind; - if let ExprKind::MethodCall(_, [rargs_self, ..], _) = &rhs.kind; + if let ExprKind::MethodCall(_, largs_self, ..) = &lhs.kind; + if let ExprKind::MethodCall(_, rargs_self, ..) = &rhs.kind; then { span_lint_and_sugg( cx, @@ -711,16 +712,16 @@ impl<'tcx> LateLintPass<'tcx> for FloatingPointArithmetic { return; } - if let ExprKind::MethodCall(path, args, _) = &expr.kind { - let recv_ty = cx.typeck_results().expr_ty(&args[0]); + if let ExprKind::MethodCall(path, receiver, args, _) = &expr.kind { + let recv_ty = cx.typeck_results().expr_ty(receiver); if recv_ty.is_floating_point() { match path.ident.name.as_str() { - "ln" => check_ln1p(cx, expr, args), - "log" => check_log_base(cx, expr, args), - "powf" => check_powf(cx, expr, args), - "powi" => check_powi(cx, expr, args), - "sqrt" => check_hypot(cx, expr, args), + "ln" => check_ln1p(cx, expr, receiver), + "log" => check_log_base(cx, expr, receiver, args), + "powf" => check_powf(cx, expr, receiver, args), + "powi" => check_powi(cx, expr, receiver, args), + "sqrt" => check_hypot(cx, expr, receiver), _ => {}, } } diff --git a/clippy_lints/src/format_args.rs b/clippy_lints/src/format_args.rs index 9fb9fd99748b..2a55c48cf773 100644 --- a/clippy_lints/src/format_args.rs +++ b/clippy_lints/src/format_args.rs @@ -99,7 +99,12 @@ fn outermost_expn_data(expn_data: ExpnData) -> ExpnData { } } -fn check_format_in_format_args(cx: &LateContext<'_>, call_site: Span, name: Symbol, arg: &Expr<'_>) { +fn check_format_in_format_args( + cx: &LateContext<'_>, + call_site: Span, + name: Symbol, + arg: &Expr<'_>, +) { let expn_data = arg.span.ctxt().outer_expn_data(); if expn_data.call_site.from_expansion() { return; @@ -126,7 +131,7 @@ fn check_format_in_format_args(cx: &LateContext<'_>, call_site: Span, name: Symb fn check_to_string_in_format_args(cx: &LateContext<'_>, name: Symbol, value: &Expr<'_>) { if_chain! { if !value.span.from_expansion(); - if let ExprKind::MethodCall(_, [receiver], _) = value.kind; + if let ExprKind::MethodCall(_, receiver, [], _) = value.kind; if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(value.hir_id); if is_diag_trait_item(cx, method_def_id, sym::ToString); let receiver_ty = cx.typeck_results().expr_ty(receiver); @@ -177,10 +182,7 @@ fn check_to_string_in_format_args(cx: &LateContext<'_>, name: Symbol, value: &Ex // Returns true if `hir_id` is referred to by multiple format params fn is_aliased(args: &FormatArgsExpn<'_>, hir_id: HirId) -> bool { - args.params() - .filter(|param| param.value.hir_id == hir_id) - .at_most_one() - .is_err() + args.params().filter(|param| param.value.hir_id == hir_id).at_most_one().is_err() } fn count_needed_derefs<'tcx, I>(mut ty: Ty<'tcx>, mut iter: I) -> (usize, Ty<'tcx>) @@ -190,11 +192,7 @@ where let mut n_total = 0; let mut n_needed = 0; loop { - if let Some(Adjustment { - kind: Adjust::Deref(overloaded_deref), - target, - }) = iter.next() - { + if let Some(Adjustment { kind: Adjust::Deref(overloaded_deref), target }) = iter.next() { n_total += 1; if overloaded_deref.is_some() { n_needed = n_total; diff --git a/clippy_lints/src/format_impl.rs b/clippy_lints/src/format_impl.rs index d8bc0bf08f2b..b628fd9f7581 100644 --- a/clippy_lints/src/format_impl.rs +++ b/clippy_lints/src/format_impl.rs @@ -139,7 +139,7 @@ impl<'tcx> LateLintPass<'tcx> for FormatImpl { fn check_to_string_in_display(cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { // Get the hir_id of the object we are calling the method on - if let ExprKind::MethodCall(path, [ref self_arg, ..], _) = expr.kind; + if let ExprKind::MethodCall(path, self_arg, ..) = expr.kind; // Is the method to_string() ? if path.ident.name == sym::to_string; // Is the method a part of the ToString trait? (i.e. not to_string() implemented diff --git a/clippy_lints/src/format_push_string.rs b/clippy_lints/src/format_push_string.rs index ebf5ab086dce..9b9f1872bfc1 100644 --- a/clippy_lints/src/format_push_string.rs +++ b/clippy_lints/src/format_push_string.rs @@ -54,7 +54,7 @@ fn is_format(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { impl<'tcx> LateLintPass<'tcx> for FormatPushString { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { let arg = match expr.kind { - ExprKind::MethodCall(_, [_, arg], _) => { + ExprKind::MethodCall(_, _, [arg], _) => { if let Some(fn_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) && match_def_path(cx, fn_def_id, &paths::PUSH_STR) { arg diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 6672a6cb0b58..a17b23f5edc8 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -212,7 +212,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { return; } match expr.kind { - Call(_, args) | MethodCall(_, args, _) => { + Call(_, args) => { let mut tys = DefIdSet::default(); for arg in args { if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id()) @@ -230,6 +230,24 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { tys.clear(); } }, + MethodCall(_, receiver, args, _) => { + let mut tys = DefIdSet::default(); + for arg in std::iter::once(receiver).chain(args.iter()) { + if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id()) + && is_mutable_ty( + self.cx, + self.cx.tcx.typeck(arg.hir_id.owner).expr_ty(arg), + arg.span, + &mut tys, + ) + && is_mutated_static(arg) + { + self.mutates_static = true; + return; + } + tys.clear(); + } + }, Assign(target, ..) | AssignOp(_, target, _) | AddrOf(_, hir::Mutability::Mut, target) => { self.mutates_static |= is_mutated_static(target); }, diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index 565a1c871d75..3bbfa52e8103 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -88,11 +88,12 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { } } }, - hir::ExprKind::MethodCall(_, args, _) => { + hir::ExprKind::MethodCall(_, receiver, args, _) => { let def_id = self.typeck_results.type_dependent_def_id(expr.hir_id).unwrap(); let base_type = self.cx.tcx.type_of(def_id); if type_is_unsafe_function(self.cx, base_type) { + self.check_arg(receiver); for arg in args { self.check_arg(arg); } diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index 4d703d691acc..9ea8c494cfcd 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -129,7 +129,7 @@ impl<'tcx, 'l> ArmVisitor<'tcx, 'l> { fn is_mutex_lock_call<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { if_chain! { - if let ExprKind::MethodCall(path, [self_arg, ..], _) = &expr.kind; + if let ExprKind::MethodCall(path, self_arg, ..) = &expr.kind; if path.ident.as_str() == "lock"; let ty = cx.typeck_results().expr_ty(self_arg).peel_refs(); if is_type_diagnostic_item(cx, ty, sym::Mutex); diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index 01c7eef4e04d..fca3cb46a2e9 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -123,43 +123,43 @@ use self::Heuristic::{All, Always, Any, First}; /// is an upper bound, e.g., some methods can return a possibly /// infinite iterator at worst, e.g., `take_while`. const HEURISTICS: [(&str, usize, Heuristic, Finiteness); 19] = [ - ("zip", 2, All, Infinite), - ("chain", 2, Any, Infinite), - ("cycle", 1, Always, Infinite), - ("map", 2, First, Infinite), - ("by_ref", 1, First, Infinite), - ("cloned", 1, First, Infinite), - ("rev", 1, First, Infinite), - ("inspect", 1, First, Infinite), - ("enumerate", 1, First, Infinite), - ("peekable", 2, First, Infinite), - ("fuse", 1, First, Infinite), - ("skip", 2, First, Infinite), - ("skip_while", 1, First, Infinite), - ("filter", 2, First, Infinite), - ("filter_map", 2, First, Infinite), - ("flat_map", 2, First, Infinite), - ("unzip", 1, First, Infinite), - ("take_while", 2, First, MaybeInfinite), - ("scan", 3, First, MaybeInfinite), + ("zip", 1, All, Infinite), + ("chain", 1, Any, Infinite), + ("cycle", 0, Always, Infinite), + ("map", 1, First, Infinite), + ("by_ref", 0, First, Infinite), + ("cloned", 0, First, Infinite), + ("rev", 0, First, Infinite), + ("inspect", 0, First, Infinite), + ("enumerate", 0, First, Infinite), + ("peekable", 1, First, Infinite), + ("fuse", 0, First, Infinite), + ("skip", 1, First, Infinite), + ("skip_while", 0, First, Infinite), + ("filter", 1, First, Infinite), + ("filter_map", 1, First, Infinite), + ("flat_map", 1, First, Infinite), + ("unzip", 0, First, Infinite), + ("take_while", 1, First, MaybeInfinite), + ("scan", 2, First, MaybeInfinite), ]; fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { match expr.kind { - ExprKind::MethodCall(method, args, _) => { + ExprKind::MethodCall(method, receiver, args, _) => { for &(name, len, heuristic, cap) in &HEURISTICS { if method.ident.name.as_str() == name && args.len() == len { return (match heuristic { Always => Infinite, - First => is_infinite(cx, &args[0]), - Any => is_infinite(cx, &args[0]).or(is_infinite(cx, &args[1])), - All => is_infinite(cx, &args[0]).and(is_infinite(cx, &args[1])), + First => is_infinite(cx, receiver), + Any => is_infinite(cx, receiver).or(is_infinite(cx, &args[0])), + All => is_infinite(cx, receiver).and(is_infinite(cx, &args[0])), }) .and(cap); } } - if method.ident.name == sym!(flat_map) && args.len() == 2 { - if let ExprKind::Closure(&Closure { body, .. }) = args[1].kind { + if method.ident.name == sym!(flat_map) && args.len() == 1 { + if let ExprKind::Closure(&Closure { body, .. }) = args[0].kind { let body = cx.tcx.hir().body(body); return is_infinite(cx, &body.value); } @@ -179,29 +179,29 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { /// the names and argument lengths of methods that *may* exhaust their /// iterators const POSSIBLY_COMPLETING_METHODS: [(&str, usize); 6] = [ - ("find", 2), - ("rfind", 2), - ("position", 2), - ("rposition", 2), - ("any", 2), - ("all", 2), + ("find", 1), + ("rfind", 1), + ("position", 1), + ("rposition", 1), + ("any", 1), + ("all", 1), ]; /// the names and argument lengths of methods that *always* exhaust /// their iterators const COMPLETING_METHODS: [(&str, usize); 12] = [ - ("count", 1), - ("fold", 3), - ("for_each", 2), - ("partition", 2), - ("max", 1), - ("max_by", 2), - ("max_by_key", 2), - ("min", 1), - ("min_by", 2), - ("min_by_key", 2), - ("sum", 1), - ("product", 1), + ("count", 0), + ("fold", 2), + ("for_each", 1), + ("partition", 1), + ("max", 0), + ("max_by", 1), + ("max_by_key", 1), + ("min", 0), + ("min_by", 1), + ("min_by_key", 1), + ("sum", 0), + ("product", 0), ]; /// the paths of types that are known to be infinitely allocating @@ -218,26 +218,26 @@ const INFINITE_COLLECTORS: &[Symbol] = &[ fn complete_infinite_iter(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { match expr.kind { - ExprKind::MethodCall(method, args, _) => { + ExprKind::MethodCall(method, receiver, args, _) => { for &(name, len) in &COMPLETING_METHODS { if method.ident.name.as_str() == name && args.len() == len { - return is_infinite(cx, &args[0]); + return is_infinite(cx, receiver); } } for &(name, len) in &POSSIBLY_COMPLETING_METHODS { if method.ident.name.as_str() == name && args.len() == len { - return MaybeInfinite.and(is_infinite(cx, &args[0])); + return MaybeInfinite.and(is_infinite(cx, receiver)); } } - if method.ident.name == sym!(last) && args.len() == 1 { + if method.ident.name == sym!(last) { let not_double_ended = cx .tcx .get_diagnostic_item(sym::DoubleEndedIterator) .map_or(false, |id| { - !implements_trait(cx, cx.typeck_results().expr_ty(&args[0]), id, &[]) + !implements_trait(cx, cx.typeck_results().expr_ty(receiver), id, &[]) }); if not_double_ended { - return is_infinite(cx, &args[0]); + return is_infinite(cx, receiver); } } else if method.ident.name == sym!(collect) { let ty = cx.typeck_results().expr_ty(expr); @@ -245,7 +245,7 @@ fn complete_infinite_iter(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { .iter() .any(|diag_item| is_type_diagnostic_item(cx, ty, *diag_item)) { - return is_infinite(cx, &args[0]); + return is_infinite(cx, receiver); } } }, diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 246f5aad8fba..25f366bfe6a8 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -370,7 +370,7 @@ fn check_for_is_empty<'tcx>( } fn check_cmp(cx: &LateContext<'_>, span: Span, method: &Expr<'_>, lit: &Expr<'_>, op: &str, compare_to: u32) { - if let (&ExprKind::MethodCall(method_path, args, _), &ExprKind::Lit(ref lit)) = (&method.kind, &lit.kind) { + if let (&ExprKind::MethodCall(method_path, receiver, ..), &ExprKind::Lit(ref lit)) = (&method.kind, &lit.kind) { // check if we are in an is_empty() method if let Some(name) = get_item_name(cx, method) { if name.as_str() == "is_empty" { @@ -378,7 +378,7 @@ fn check_cmp(cx: &LateContext<'_>, span: Span, method: &Expr<'_>, lit: &Expr<'_> } } - check_len(cx, span, method_path.ident.name, args, &lit.node, op, compare_to); + check_len(cx, span, method_path.ident.name, receiver, &lit.node, op, compare_to); } else { check_empty_expr(cx, span, method, lit, op); } @@ -388,7 +388,7 @@ fn check_len( cx: &LateContext<'_>, span: Span, method_name: Symbol, - args: &[Expr<'_>], + receiver: &Expr<'_>, lit: &LitKind, op: &str, compare_to: u32, @@ -399,7 +399,7 @@ fn check_len( return; } - if method_name == sym::len && args.len() == 1 && has_is_empty(cx, &args[0]) { + if method_name == sym::len && has_is_empty(cx, receiver) { let mut applicability = Applicability::MachineApplicable; span_lint_and_sugg( cx, @@ -410,7 +410,7 @@ fn check_len( format!( "{}{}.is_empty()", op, - snippet_with_applicability(cx, args[0].span, "_", &mut applicability) + snippet_with_applicability(cx, receiver.span, "_", &mut applicability) ), applicability, ); diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index a65df48e413e..3fc569af89ec 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -119,7 +119,7 @@ fn build_manual_memcpy_suggestion<'tcx>( let print_limit = |end: &Expr<'_>, end_str: &str, base: &Expr<'_>, sugg: MinifyingSugg<'static>| { if_chain! { - if let ExprKind::MethodCall(method, [recv], _) = end.kind; + if let ExprKind::MethodCall(method, recv, [], _) = end.kind; if method.ident.name == sym::len; if path_to_local(recv) == path_to_local(base); then { @@ -341,7 +341,7 @@ fn get_slice_like_element_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Opti fn fetch_cloned_expr<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { if_chain! { - if let ExprKind::MethodCall(method, [arg], _) = expr.kind; + if let ExprKind::MethodCall(method, arg, [], _) = expr.kind; if method.ident.name == sym::clone; then { arg } else { expr } } diff --git a/clippy_lints/src/loops/missing_spin_loop.rs b/clippy_lints/src/loops/missing_spin_loop.rs index 0696afa39225..8412875b11b7 100644 --- a/clippy_lints/src/loops/missing_spin_loop.rs +++ b/clippy_lints/src/loops/missing_spin_loop.rs @@ -33,7 +33,7 @@ fn unpack_cond<'tcx>(cond: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, body: &'tcx Expr<'_>) { if_chain! { if let ExprKind::Block(Block { stmts: [], expr: None, ..}, _) = body.kind; - if let ExprKind::MethodCall(method, [callee, ..], _) = unpack_cond(cond).kind; + if let ExprKind::MethodCall(method, callee, ..) = unpack_cond(cond).kind; if [sym::load, sym::compare_exchange, sym::compare_exchange_weak].contains(&method.ident.name); if let ty::Adt(def, _substs) = cx.typeck_results().expr_ty(callee).kind(); if cx.tcx.is_diagnostic_item(sym::AtomicBool, def.did()); diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index ed270bd490d7..74f3bda9f43e 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -742,7 +742,7 @@ fn check_for_loop<'tcx>( fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) { let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used - if let ExprKind::MethodCall(method, [self_arg], _) = arg.kind { + if let ExprKind::MethodCall(method, self_arg, [], _) = arg.kind { let method_name = method.ident.as_str(); // check for looping over x.iter() or x.iter_mut(), could use &x or &mut x match method_name { diff --git a/clippy_lints/src/loops/needless_collect.rs b/clippy_lints/src/loops/needless_collect.rs index 6d987f393fa5..6e6faa79adc9 100644 --- a/clippy_lints/src/loops/needless_collect.rs +++ b/clippy_lints/src/loops/needless_collect.rs @@ -25,11 +25,11 @@ pub(super) fn check<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) { } fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) { if_chain! { - if let ExprKind::MethodCall(method, args, _) = expr.kind; - if let ExprKind::MethodCall(chain_method, _, _) = args[0].kind; - if chain_method.ident.name == sym!(collect) && is_trait_method(cx, &args[0], sym::Iterator); + if let ExprKind::MethodCall(method, receiver, args, _) = expr.kind; + if let ExprKind::MethodCall(chain_method, ..) = receiver.kind; + if chain_method.ident.name == sym!(collect) && is_trait_method(cx, receiver, sym::Iterator); then { - let ty = cx.typeck_results().expr_ty(&args[0]); + let ty = cx.typeck_results().expr_ty(receiver); let mut applicability = Applicability::MaybeIncorrect; let is_empty_sugg = "next().is_none()".to_string(); let method_name = method.ident.name.as_str(); @@ -41,7 +41,7 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont "len" => "count()".to_string(), "is_empty" => is_empty_sugg, "contains" => { - let contains_arg = snippet_with_applicability(cx, args[1].span, "??", &mut applicability); + let contains_arg = snippet_with_applicability(cx, args[0].span, "??", &mut applicability); let (arg, pred) = contains_arg .strip_prefix('&') .map_or(("&x", &*contains_arg), |s| ("x", s)); @@ -80,7 +80,7 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo if let StmtKind::Local(local) = stmt.kind; if let PatKind::Binding(_, id, ..) = local.pat.kind; if let Some(init_expr) = local.init; - if let ExprKind::MethodCall(method_name, &[ref iter_source], ..) = init_expr.kind; + if let ExprKind::MethodCall(method_name, iter_source, [], ..) = init_expr.kind; if method_name.ident.name == sym!(collect) && is_trait_method(cx, init_expr, sym::Iterator); let ty = cx.typeck_results().expr_ty(init_expr); if is_type_diagnostic_item(cx, ty, sym::Vec) || @@ -203,7 +203,7 @@ impl<'tcx> Visitor<'tcx> for IterFunctionVisitor<'_, 'tcx> { fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { // Check function calls on our collection - if let ExprKind::MethodCall(method_name, [recv, args @ ..], _) = &expr.kind { + if let ExprKind::MethodCall(method_name, recv, [args @ ..], _) = &expr.kind { if method_name.ident.name == sym!(collect) && is_trait_method(self.cx, expr, sym::Iterator) { self.current_mutably_captured_ids = get_captured_ids(self.cx, self.cx.typeck_results().expr_ty(recv)); self.visit_expr(recv); diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 7ca4a7c4ebfc..ffcf83e4605e 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -188,7 +188,7 @@ pub(super) fn check<'tcx>( fn is_len_call(expr: &Expr<'_>, var: Symbol) -> bool { if_chain! { - if let ExprKind::MethodCall(method, [recv], _) = expr.kind; + if let ExprKind::MethodCall(method, recv, [], _) = expr.kind; if method.ident.name == sym::len; if let ExprKind::Path(QPath::Resolved(_, path)) = recv.kind; if path.segments.len() == 1; @@ -301,7 +301,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if_chain! { // a range index op - if let ExprKind::MethodCall(meth, [args_0, args_1, ..], _) = &expr.kind; + if let ExprKind::MethodCall(meth, args_0, [args_1, ..], _) = &expr.kind; if (meth.ident.name == sym::index && match_trait_method(self.cx, expr, &paths::INDEX)) || (meth.ident.name == sym::index_mut && match_trait_method(self.cx, expr, &paths::INDEX_MUT)); if !self.check(args_1, args_0, expr); @@ -356,9 +356,12 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { self.visit_expr(expr); } }, - ExprKind::MethodCall(_, args, _) => { + ExprKind::MethodCall(_, receiver, args, _) => { let def_id = self.cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap(); - for (ty, expr) in iter::zip(self.cx.tcx.fn_sig(def_id).inputs().skip_binder(), args) { + for (ty, expr) in iter::zip( + self.cx.tcx.fn_sig(def_id).inputs().skip_binder(), + std::iter::once(receiver).chain(args.iter()), + ) { self.prefer_mutable = false; if let ty::Ref(_, _, mutbl) = *ty.kind() { if mutbl == Mutability::Mut { diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index 5448360049d2..116e589cad6f 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -120,8 +120,9 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { | ExprKind::Repeat(e, _) | ExprKind::DropTemps(e) => never_loop_expr(e, main_loop_id), ExprKind::Let(let_expr) => never_loop_expr(let_expr.init, main_loop_id), - ExprKind::Array(es) | ExprKind::MethodCall(_, es, _) | ExprKind::Tup(es) => { - never_loop_expr_all(&mut es.iter(), main_loop_id) + ExprKind::Array(es) | ExprKind::Tup(es) => never_loop_expr_all(&mut es.iter(), main_loop_id), + ExprKind::MethodCall(_, receiver, es, _) => { + never_loop_expr_all(&mut std::iter::once(receiver).chain(es.iter()), main_loop_id) }, ExprKind::Struct(_, fields, base) => { let fields = never_loop_expr_all(&mut fields.iter().map(|f| f.expr), main_loop_id); diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index 1439f1f4c75d..23f47091f77f 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -180,10 +180,9 @@ fn get_vec_push<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) -> Option<(& if_chain! { // Extract method being called if let StmtKind::Semi(semi_stmt) = &stmt.kind; - if let ExprKind::MethodCall(path, args, _) = &semi_stmt.kind; + if let ExprKind::MethodCall(path, self_expr, args, _) = &semi_stmt.kind; // Figure out the parameters for the method call - if let Some(self_expr) = args.get(0); - if let Some(pushed_item) = args.get(1); + if let Some(pushed_item) = args.get(0); // Check that the method being called is push() on a Vec if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(self_expr), sym::Vec); if path.ident.name.as_str() == "push"; diff --git a/clippy_lints/src/loops/single_element_loop.rs b/clippy_lints/src/loops/single_element_loop.rs index a0bd7ad0ac64..f4b47808dfaa 100644 --- a/clippy_lints/src/loops/single_element_loop.rs +++ b/clippy_lints/src/loops/single_element_loop.rs @@ -35,32 +35,29 @@ pub(super) fn check<'tcx>( ) => (arg, "&mut "), ExprKind::MethodCall( method, - [ - Expr { - kind: ExprKind::Array([arg]), - .. - }, - ], + Expr { + kind: ExprKind::Array([arg]), + .. + }, + [], _, ) if method.ident.name == rustc_span::sym::iter => (arg, "&"), ExprKind::MethodCall( method, - [ - Expr { - kind: ExprKind::Array([arg]), - .. - }, - ], + Expr { + kind: ExprKind::Array([arg]), + .. + }, + [], _, ) if method.ident.name.as_str() == "iter_mut" => (arg, "&mut "), ExprKind::MethodCall( method, - [ - Expr { - kind: ExprKind::Array([arg]), - .. - }, - ], + Expr { + kind: ExprKind::Array([arg]), + .. + }, + [], _, ) if method.ident.name == rustc_span::sym::into_iter => (arg, ""), // Only check for arrays edition 2021 or later, as this case will trigger a compiler error otherwise. diff --git a/clippy_lints/src/loops/while_let_loop.rs b/clippy_lints/src/loops/while_let_loop.rs index ca617859db49..735d704a43ce 100644 --- a/clippy_lints/src/loops/while_let_loop.rs +++ b/clippy_lints/src/loops/while_let_loop.rs @@ -11,7 +11,14 @@ use rustc_lint::LateContext; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) { let (init, has_trailing_exprs) = match (loop_block.stmts, loop_block.expr) { ([stmt, stmts @ ..], expr) => { - if let StmtKind::Local(&Local { init: Some(e), els: None, .. }) | StmtKind::Semi(e) | StmtKind::Expr(e) = stmt.kind { + if let StmtKind::Local(&Local { + init: Some(e), + els: None, + .. + }) + | StmtKind::Semi(e) + | StmtKind::Expr(e) = stmt.kind + { (e, !stmts.is_empty() || expr.is_some()) } else { return; diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index e9e215e662f1..2c54033f8597 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -23,7 +23,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let Res::Def(_, pat_did) = pat_path.res; if match_def_path(cx, pat_did, &paths::OPTION_SOME); // check for call to `Iterator::next` - if let ExprKind::MethodCall(method_name, [iter_expr], _) = let_expr.kind; + if let ExprKind::MethodCall(method_name, iter_expr, [], _) = let_expr.kind; if method_name.ident.name == sym::next; if is_trait_method(cx, let_expr, sym::Iterator); if let Some(iter_expr_struct) = try_parse_iter_expr(cx, iter_expr); diff --git a/clippy_lints/src/manual_bits.rs b/clippy_lints/src/manual_bits.rs index 940601a44fb0..6655c92b1da8 100644 --- a/clippy_lints/src/manual_bits.rs +++ b/clippy_lints/src/manual_bits.rs @@ -134,7 +134,7 @@ fn create_sugg(cx: &LateContext<'_>, expr: &Expr<'_>, base_sugg: String) -> Stri fn is_ty_conversion(expr: &Expr<'_>) -> bool { if let ExprKind::Cast(..) = expr.kind { true - } else if let ExprKind::MethodCall(path, [_], _) = expr.kind + } else if let ExprKind::MethodCall(path, _, [], _) = expr.kind && path.ident.name == rustc_span::sym::try_into { // This is only called for `usize` which implements `TryInto`. Therefore, diff --git a/clippy_lints/src/manual_retain.rs b/clippy_lints/src/manual_retain.rs index 42d2577cc316..f28c37d3dca7 100644 --- a/clippy_lints/src/manual_retain.rs +++ b/clippy_lints/src/manual_retain.rs @@ -66,9 +66,9 @@ impl<'tcx> LateLintPass<'tcx> for ManualRetain { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if let Some(parent_expr) = get_parent_expr(cx, expr) && let Assign(left_expr, collect_expr, _) = &parent_expr.kind - && let hir::ExprKind::MethodCall(seg, _, _) = &collect_expr.kind + && let hir::ExprKind::MethodCall(seg, ..) = &collect_expr.kind && seg.args.is_none() - && let hir::ExprKind::MethodCall(_, [target_expr], _) = &collect_expr.kind + && let hir::ExprKind::MethodCall(_, target_expr, [], _) = &collect_expr.kind && let Some(collect_def_id) = cx.typeck_results().type_dependent_def_id(collect_expr.hir_id) && match_def_path(cx, collect_def_id, &paths::CORE_ITER_COLLECT) { check_into_iter(cx, parent_expr, left_expr, target_expr, self.msrv); @@ -87,10 +87,10 @@ fn check_into_iter( target_expr: &hir::Expr<'_>, msrv: Option, ) { - if let hir::ExprKind::MethodCall(_, [into_iter_expr, _], _) = &target_expr.kind + if let hir::ExprKind::MethodCall(_, into_iter_expr, [_], _) = &target_expr.kind && let Some(filter_def_id) = cx.typeck_results().type_dependent_def_id(target_expr.hir_id) && match_def_path(cx, filter_def_id, &paths::CORE_ITER_FILTER) - && let hir::ExprKind::MethodCall(_, [struct_expr], _) = &into_iter_expr.kind + && let hir::ExprKind::MethodCall(_, struct_expr, [], _) = &into_iter_expr.kind && let Some(into_iter_def_id) = cx.typeck_results().type_dependent_def_id(into_iter_expr.hir_id) && match_def_path(cx, into_iter_def_id, &paths::CORE_ITER_INTO_ITER) && match_acceptable_type(cx, left_expr, msrv) @@ -106,14 +106,14 @@ fn check_iter( target_expr: &hir::Expr<'_>, msrv: Option, ) { - if let hir::ExprKind::MethodCall(_, [filter_expr], _) = &target_expr.kind + if let hir::ExprKind::MethodCall(_, filter_expr, [], _) = &target_expr.kind && let Some(copied_def_id) = cx.typeck_results().type_dependent_def_id(target_expr.hir_id) && (match_def_path(cx, copied_def_id, &paths::CORE_ITER_COPIED) || match_def_path(cx, copied_def_id, &paths::CORE_ITER_CLONED)) - && let hir::ExprKind::MethodCall(_, [iter_expr, _], _) = &filter_expr.kind + && let hir::ExprKind::MethodCall(_, iter_expr, [_], _) = &filter_expr.kind && let Some(filter_def_id) = cx.typeck_results().type_dependent_def_id(filter_expr.hir_id) && match_def_path(cx, filter_def_id, &paths::CORE_ITER_FILTER) - && let hir::ExprKind::MethodCall(_, [struct_expr], _) = &iter_expr.kind + && let hir::ExprKind::MethodCall(_, struct_expr, [], _) = &iter_expr.kind && let Some(iter_expr_def_id) = cx.typeck_results().type_dependent_def_id(iter_expr.hir_id) && match_acceptable_def_path(cx, iter_expr_def_id) && match_acceptable_type(cx, left_expr, msrv) @@ -130,13 +130,13 @@ fn check_to_owned( msrv: Option, ) { if meets_msrv(msrv, msrvs::STRING_RETAIN) - && let hir::ExprKind::MethodCall(_, [filter_expr], _) = &target_expr.kind + && let hir::ExprKind::MethodCall(_, filter_expr, [], _) = &target_expr.kind && let Some(to_owned_def_id) = cx.typeck_results().type_dependent_def_id(target_expr.hir_id) && match_def_path(cx, to_owned_def_id, &paths::TO_OWNED_METHOD) - && let hir::ExprKind::MethodCall(_, [chars_expr, _], _) = &filter_expr.kind + && let hir::ExprKind::MethodCall(_, chars_expr, [_], _) = &filter_expr.kind && let Some(filter_def_id) = cx.typeck_results().type_dependent_def_id(filter_expr.hir_id) && match_def_path(cx, filter_def_id, &paths::CORE_ITER_FILTER) - && let hir::ExprKind::MethodCall(_, [str_expr], _) = &chars_expr.kind + && let hir::ExprKind::MethodCall(_, str_expr, [], _) = &chars_expr.kind && let Some(chars_expr_def_id) = cx.typeck_results().type_dependent_def_id(chars_expr.hir_id) && match_def_path(cx, chars_expr_def_id, &paths::STR_CHARS) && let ty = cx.typeck_results().expr_ty(str_expr).peel_refs() @@ -147,7 +147,7 @@ fn check_to_owned( } fn suggest(cx: &LateContext<'_>, parent_expr: &hir::Expr<'_>, left_expr: &hir::Expr<'_>, filter_expr: &hir::Expr<'_>) { - if let hir::ExprKind::MethodCall(_, [_, closure], _) = filter_expr.kind + if let hir::ExprKind::MethodCall(_, _, [closure], _) = filter_expr.kind && let hir::ExprKind::Closure(&hir::Closure { body, ..}) = closure.kind && let filter_body = cx.tcx.hir().body(body) && let [filter_params] = filter_body.params diff --git a/clippy_lints/src/manual_string_new.rs b/clippy_lints/src/manual_string_new.rs index a90eaa8fdcbe..6acfb2ae3471 100644 --- a/clippy_lints/src/manual_string_new.rs +++ b/clippy_lints/src/manual_string_new.rs @@ -55,8 +55,8 @@ impl LateLintPass<'_> for ManualStringNew { ExprKind::Call(func, args) => { parse_call(cx, expr.span, func, args); }, - ExprKind::MethodCall(path_segment, args, _) => { - parse_method_call(cx, expr.span, path_segment, args); + ExprKind::MethodCall(path_segment, receiver, ..) => { + parse_method_call(cx, expr.span, path_segment, receiver); }, _ => (), } @@ -88,14 +88,9 @@ fn warn_then_suggest(cx: &LateContext<'_>, span: Span) { } /// Tries to parse an expression as a method call, emitting the warning if necessary. -fn parse_method_call(cx: &LateContext<'_>, span: Span, path_segment: &PathSegment<'_>, args: &[Expr<'_>]) { - if args.is_empty() { - // When parsing TryFrom::try_from(...).expect(...), we will have more than 1 arg. - return; - } - +fn parse_method_call(cx: &LateContext<'_>, span: Span, path_segment: &PathSegment<'_>, receiver: &Expr<'_>) { let ident = path_segment.ident.as_str(); - let method_arg_kind = &args[0].kind; + let method_arg_kind = &receiver.kind; if ["to_string", "to_owned", "into"].contains(&ident) && is_expr_kind_empty_str(method_arg_kind) { warn_then_suggest(cx, span); } else if let ExprKind::Call(func, args) = method_arg_kind { diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index dfb3efc4e28b..7941c8c9c7e3 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { if_chain! { if let Some(higher::If { cond, then, .. }) = higher::If::hir(expr); - if let ExprKind::MethodCall(_, [target_arg, pattern], _) = cond.kind; + if let ExprKind::MethodCall(_, target_arg, [pattern], _) = cond.kind; if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(cond.hir_id); if let ExprKind::Path(target_path) = &target_arg.kind; then { @@ -132,7 +132,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { // Returns `Some(arg)` if `expr` matches `arg.len()` and `None` otherwise. fn len_arg<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { if_chain! { - if let ExprKind::MethodCall(_, [arg], _) = expr.kind; + if let ExprKind::MethodCall(_, arg, [], _) = expr.kind; if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if match_def_path(cx, method_def_id, &paths::STR_LEN); then { diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 6db852c3ffe7..33d744815299 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -200,8 +200,13 @@ fn suggestion_msg(function_type: &str, map_type: &str) -> String { ) } -fn lint_map_unit_fn(cx: &LateContext<'_>, stmt: &hir::Stmt<'_>, expr: &hir::Expr<'_>, map_args: &[hir::Expr<'_>]) { - let var_arg = &map_args[0]; +fn lint_map_unit_fn( + cx: &LateContext<'_>, + stmt: &hir::Stmt<'_>, + expr: &hir::Expr<'_>, + map_args: (&hir::Expr<'_>, &[hir::Expr<'_>]), +) { + let var_arg = &map_args.0; let (map_type, variant, lint) = if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(var_arg), sym::Option) { ("Option", "Some", OPTION_MAP_UNIT_FN) @@ -210,7 +215,7 @@ fn lint_map_unit_fn(cx: &LateContext<'_>, stmt: &hir::Stmt<'_>, expr: &hir::Expr } else { return; }; - let fn_arg = &map_args[1]; + let fn_arg = &map_args.1[0]; if is_unit_function(cx, fn_arg) { let mut applicability = Applicability::MachineApplicable; diff --git a/clippy_lints/src/match_result_ok.rs b/clippy_lints/src/match_result_ok.rs index 3349b85f1347..8588ab1ed8db 100644 --- a/clippy_lints/src/match_result_ok.rs +++ b/clippy_lints/src/match_result_ok.rs @@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for MatchResultOk { }; if_chain! { - if let ExprKind::MethodCall(ok_path, [ref result_types_0, ..], _) = let_expr.kind; //check is expr.ok() has type Result.ok(, _) + if let ExprKind::MethodCall(ok_path, result_types_0, ..) = let_expr.kind; //check is expr.ok() has type Result.ok(, _) if let PatKind::TupleStruct(QPath::Resolved(_, x), y, _) = let_pat.kind; //get operation if method_chain_args(let_expr, &["ok"]).is_some(); //test to see if using ok() method use std::marker::Sized; if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(result_types_0), sym::Result); diff --git a/clippy_lints/src/matches/match_str_case_mismatch.rs b/clippy_lints/src/matches/match_str_case_mismatch.rs index fa3b8d1fceaa..1e80b6cf2d83 100644 --- a/clippy_lints/src/matches/match_str_case_mismatch.rs +++ b/clippy_lints/src/matches/match_str_case_mismatch.rs @@ -48,7 +48,7 @@ struct MatchExprVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for MatchExprVisitor<'a, 'tcx> { fn visit_expr(&mut self, ex: &'tcx Expr<'_>) { match ex.kind { - ExprKind::MethodCall(segment, [receiver], _) if self.case_altered(segment.ident.as_str(), receiver) => {}, + ExprKind::MethodCall(segment, receiver, [], _) if self.case_altered(segment.ident.as_str(), receiver) => {}, _ => walk_expr(self, ex), } } diff --git a/clippy_lints/src/matches/redundant_pattern_match.rs b/clippy_lints/src/matches/redundant_pattern_match.rs index 8499e050af24..f7443471e31d 100644 --- a/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/clippy_lints/src/matches/redundant_pattern_match.rs @@ -120,7 +120,7 @@ fn find_sugg_for_if_let<'tcx>( // check that `while_let_on_iterator` lint does not trigger if_chain! { if keyword == "while"; - if let ExprKind::MethodCall(method_path, _, _) = let_expr.kind; + if let ExprKind::MethodCall(method_path, ..) = let_expr.kind; if method_path.ident.name == sym::next; if is_trait_method(cx, let_expr, sym::Iterator); then { diff --git a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index b0b15b3f54cd..86a9df034979 100644 --- a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -291,7 +291,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> { self.is_chain_end = false; match ex.kind { - ExprKind::MethodCall(_, [ref expr, ..], _) => { + ExprKind::MethodCall(_, expr, ..) => { self.visit_expr(expr); } ExprKind::Binary(_, left, right) => { @@ -331,8 +331,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> { ExprKind::Index(..) | ExprKind::Ret(..) | ExprKind::Repeat(..) | - ExprKind::Yield(..) | - ExprKind::MethodCall(..) => walk_expr(self, ex), + ExprKind::Yield(..) => walk_expr(self, ex), ExprKind::AddrOf(_, _, _) | ExprKind::Block(_, _) | ExprKind::Break(_, _) | diff --git a/clippy_lints/src/methods/bytecount.rs b/clippy_lints/src/methods/bytecount.rs index 6a7c63d76f72..fef90f6eba49 100644 --- a/clippy_lints/src/methods/bytecount.rs +++ b/clippy_lints/src/methods/bytecount.rs @@ -42,11 +42,11 @@ pub(super) fn check<'tcx>( if ty::Uint(UintTy::U8) == *cx.typeck_results().expr_ty(needle).peel_refs().kind(); if !is_local_used(cx, needle, arg_id); then { - let haystack = if let ExprKind::MethodCall(path, args, _) = + let haystack = if let ExprKind::MethodCall(path, receiver, [], _) = filter_recv.kind { let p = path.ident.name; - if (p == sym::iter || p == sym!(iter_mut)) && args.len() == 1 { - &args[0] + if p == sym::iter || p == sym!(iter_mut) { + receiver } else { filter_recv } diff --git a/clippy_lints/src/methods/chars_cmp.rs b/clippy_lints/src/methods/chars_cmp.rs index f7b79f0839ba..51aec21527a7 100644 --- a/clippy_lints/src/methods/chars_cmp.rs +++ b/clippy_lints/src/methods/chars_cmp.rs @@ -23,7 +23,7 @@ pub(super) fn check( if Some(id) == cx.tcx.lang_items().option_some_variant(); then { let mut applicability = Applicability::MachineApplicable; - let self_ty = cx.typeck_results().expr_ty_adjusted(&args[0][0]).peel_refs(); + let self_ty = cx.typeck_results().expr_ty_adjusted(&args[0].0).peel_refs(); if *self_ty.kind() != ty::Str { return false; @@ -37,7 +37,7 @@ pub(super) fn check( "like this", format!("{}{}.{}({})", if info.eq { "" } else { "!" }, - snippet_with_applicability(cx, args[0][0].span, "..", &mut applicability), + snippet_with_applicability(cx, args[0].0.span, "..", &mut applicability), suggest, snippet_with_applicability(cx, arg_char.span, "..", &mut applicability)), applicability, diff --git a/clippy_lints/src/methods/chars_cmp_with_unwrap.rs b/clippy_lints/src/methods/chars_cmp_with_unwrap.rs index a7c0e43923e1..b85bfec2b12b 100644 --- a/clippy_lints/src/methods/chars_cmp_with_unwrap.rs +++ b/clippy_lints/src/methods/chars_cmp_with_unwrap.rs @@ -30,7 +30,7 @@ pub(super) fn check<'tcx>( "like this", format!("{}{}.{}('{}')", if info.eq { "" } else { "!" }, - snippet_with_applicability(cx, args[0][0].span, "..", &mut applicability), + snippet_with_applicability(cx, args[0].0.span, "..", &mut applicability), suggest, c.escape_default()), applicability, diff --git a/clippy_lints/src/methods/clone_on_copy.rs b/clippy_lints/src/methods/clone_on_copy.rs index 60e1355f9b92..9ae6297ec2f6 100644 --- a/clippy_lints/src/methods/clone_on_copy.rs +++ b/clippy_lints/src/methods/clone_on_copy.rs @@ -14,9 +14,15 @@ use super::CLONE_ON_COPY; /// Checks for the `CLONE_ON_COPY` lint. #[allow(clippy::too_many_lines)] -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol, args: &[Expr<'_>]) { +pub(super) fn check( + cx: &LateContext<'_>, + expr: &Expr<'_>, + method_name: Symbol, + receiver: &Expr<'_>, + args: &[Expr<'_>], +) { let arg = match args { - [arg] if method_name == sym::clone => arg, + [] if method_name == sym::clone => receiver, _ => return, }; if cx @@ -81,7 +87,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol, // &*x is a nop, &x.clone() is not ExprKind::AddrOf(..) => return, // (*x).func() is useless, x.clone().func() can work in case func borrows self - ExprKind::MethodCall(_, [self_arg, ..], _) + ExprKind::MethodCall(_, self_arg, ..) if expr.hir_id == self_arg.hir_id && ty != cx.typeck_results().expr_ty_adjusted(expr) => { return; @@ -91,7 +97,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol, hir_callee.kind, ExprKind::Path(QPath::LangItem(rustc_hir::LangItem::TryTraitBranch, _, _)) ), - ExprKind::MethodCall(_, [self_arg, ..], _) if expr.hir_id == self_arg.hir_id => true, + ExprKind::MethodCall(_, self_arg, ..) if expr.hir_id == self_arg.hir_id => true, ExprKind::Match(_, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar) | ExprKind::Field(..) | ExprKind::Index(..) => true, diff --git a/clippy_lints/src/methods/clone_on_ref_ptr.rs b/clippy_lints/src/methods/clone_on_ref_ptr.rs index 6417bc813047..7098d564cfc8 100644 --- a/clippy_lints/src/methods/clone_on_ref_ptr.rs +++ b/clippy_lints/src/methods/clone_on_ref_ptr.rs @@ -10,11 +10,17 @@ use rustc_span::symbol::{sym, Symbol}; use super::CLONE_ON_REF_PTR; -pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, method_name: Symbol, args: &[hir::Expr<'_>]) { - if !(args.len() == 1 && method_name == sym::clone) { +pub(super) fn check( + cx: &LateContext<'_>, + expr: &hir::Expr<'_>, + method_name: Symbol, + receiver: &hir::Expr<'_>, + args: &[hir::Expr<'_>], +) { + if !(args.is_empty() && method_name == sym::clone) { return; } - let arg = &args[0]; + let arg = receiver; let obj_ty = cx.typeck_results().expr_ty(arg).peel_refs(); if let ty::Adt(_, subst) = obj_ty.kind() { diff --git a/clippy_lints/src/methods/collapsible_str_replace.rs b/clippy_lints/src/methods/collapsible_str_replace.rs index 561033be5b6a..501646863fe1 100644 --- a/clippy_lints/src/methods/collapsible_str_replace.rs +++ b/clippy_lints/src/methods/collapsible_str_replace.rs @@ -23,7 +23,7 @@ pub(super) fn check<'tcx>( // If the parent node's `to` argument is the same as the `to` argument // of the last replace call in the current chain, don't lint as it was already linted if let Some(parent) = get_parent_expr(cx, expr) - && let Some(("replace", [_, current_from, current_to], _)) = method_call(parent) + && let Some(("replace", _, [current_from, current_to], _)) = method_call(parent) && eq_expr_value(cx, to, current_to) && from_kind == cx.typeck_results().expr_ty(current_from).peel_refs().kind() { @@ -48,7 +48,7 @@ fn collect_replace_calls<'tcx>( let mut from_args = VecDeque::new(); let _: Option<()> = for_each_expr(expr, |e| { - if let Some(("replace", [_, from, to], _)) = method_call(e) { + if let Some(("replace", _, [from, to], _)) = method_call(e) { if eq_expr_value(cx, to_arg, to) && cx.typeck_results().expr_ty(from).peel_refs().is_char() { methods.push_front(e); from_args.push_front(from); @@ -78,7 +78,7 @@ fn check_consecutive_replace_calls<'tcx>( .collect(); let app = Applicability::MachineApplicable; let earliest_replace_call = replace_methods.methods.front().unwrap(); - if let Some((_, [..], span_lo)) = method_call(earliest_replace_call) { + if let Some((_, _, [..], span_lo)) = method_call(earliest_replace_call) { span_lint_and_sugg( cx, COLLAPSIBLE_STR_REPLACE, diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index 6f2307d8f18f..bd846d71d466 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -19,6 +19,7 @@ pub(super) fn check<'tcx>( expr: &hir::Expr<'_>, method_span: Span, name: &str, + receiver: &'tcx hir::Expr<'tcx>, args: &'tcx [hir::Expr<'tcx>], ) { // Strip `&`, `as_ref()` and `as_str()` off `arg` until we're left with either a `String` or @@ -28,16 +29,13 @@ pub(super) fn check<'tcx>( loop { arg_root = match &arg_root.kind { hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, expr) => expr, - hir::ExprKind::MethodCall(method_name, call_args, _) => { - if call_args.len() == 1 - && (method_name.ident.name == sym::as_str || method_name.ident.name == sym::as_ref) - && { - let arg_type = cx.typeck_results().expr_ty(&call_args[0]); - let base_type = arg_type.peel_refs(); - *base_type.kind() == ty::Str || is_type_diagnostic_item(cx, base_type, sym::String) - } - { - &call_args[0] + hir::ExprKind::MethodCall(method_name, receiver, [], ..) => { + if (method_name.ident.name == sym::as_str || method_name.ident.name == sym::as_ref) && { + let arg_type = cx.typeck_results().expr_ty(receiver); + let base_type = arg_type.peel_refs(); + *base_type.kind() == ty::Str || is_type_diagnostic_item(cx, base_type, sym::String) + } { + receiver } else { break; } @@ -114,11 +112,11 @@ pub(super) fn check<'tcx>( } } - if args.len() != 2 || name != "expect" || !is_call(&args[1].kind) { + if args.len() != 1 || name != "expect" || !is_call(&args[0].kind) { return; } - let receiver_type = cx.typeck_results().expr_ty_adjusted(&args[0]); + let receiver_type = cx.typeck_results().expr_ty_adjusted(receiver); let closure_args = if is_type_diagnostic_item(cx, receiver_type, sym::Option) { "||" } else if is_type_diagnostic_item(cx, receiver_type, sym::Result) { @@ -127,7 +125,7 @@ pub(super) fn check<'tcx>( return; }; - let arg_root = get_arg_root(cx, &args[1]); + let arg_root = get_arg_root(cx, &args[0]); let span_replace_word = method_span.with_hi(expr.span.hi()); diff --git a/clippy_lints/src/methods/extend_with_drain.rs b/clippy_lints/src/methods/extend_with_drain.rs index a15fe6094022..37b28463527c 100644 --- a/clippy_lints/src/methods/extend_with_drain.rs +++ b/clippy_lints/src/methods/extend_with_drain.rs @@ -14,7 +14,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: if_chain! { if is_type_diagnostic_item(cx, ty, sym::Vec); //check source object - if let ExprKind::MethodCall(src_method, [drain_vec, drain_arg], _) = &arg.kind; + if let ExprKind::MethodCall(src_method, drain_vec, [drain_arg], _) = &arg.kind; if src_method.ident.as_str() == "drain"; let src_ty = cx.typeck_results().expr_ty(drain_vec); //check if actual src type is mutable for code suggestion diff --git a/clippy_lints/src/methods/filter_map.rs b/clippy_lints/src/methods/filter_map.rs index 692e22a7c5cf..9dc839afc625 100644 --- a/clippy_lints/src/methods/filter_map.rs +++ b/clippy_lints/src/methods/filter_map.rs @@ -28,11 +28,11 @@ fn is_method<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, method_name: Sy let closure_expr = peel_blocks(&body.value); let arg_id = body.params[0].pat.hir_id; match closure_expr.kind { - hir::ExprKind::MethodCall(hir::PathSegment { ident, .. }, args, _) => { + hir::ExprKind::MethodCall(hir::PathSegment { ident, .. }, receiver, ..) => { if_chain! { if ident.name == method_name; - if let hir::ExprKind::Path(path) = &args[0].kind; - if let Res::Local(ref local) = cx.qpath_res(path, args[0].hir_id); + if let hir::ExprKind::Path(path) = &receiver.kind; + if let Res::Local(ref local) = cx.qpath_res(path, receiver.hir_id); then { return arg_id == *local } @@ -106,7 +106,7 @@ pub(super) fn check<'tcx>( }; // closure ends with is_some() or is_ok() if let PatKind::Binding(_, filter_param_id, _, None) = filter_pat.kind; - if let ExprKind::MethodCall(path, [filter_arg], _) = filter_body.value.kind; + if let ExprKind::MethodCall(path, filter_arg, [], _) = filter_body.value.kind; if let Some(opt_ty) = cx.typeck_results().expr_ty(filter_arg).peel_refs().ty_adt_def(); if let Some(is_result) = if cx.tcx.is_diagnostic_item(sym::Option, opt_ty.did()) { Some(false) @@ -123,13 +123,13 @@ pub(super) fn check<'tcx>( if let [map_param] = map_body.params; if let PatKind::Binding(_, map_param_id, map_param_ident, None) = map_param.pat.kind; // closure ends with expect() or unwrap() - if let ExprKind::MethodCall(seg, [map_arg, ..], _) = map_body.value.kind; + if let ExprKind::MethodCall(seg, map_arg, ..) = map_body.value.kind; if matches!(seg.ident.name, sym::expect | sym::unwrap | sym::unwrap_or); // .filter(..).map(|y| f(y).copied().unwrap()) // ~~~~ let map_arg_peeled = match map_arg.kind { - ExprKind::MethodCall(method, [original_arg], _) if acceptable_methods(method) => { + ExprKind::MethodCall(method, original_arg, [], _) if acceptable_methods(method) => { original_arg }, _ => map_arg, diff --git a/clippy_lints/src/methods/get_last_with_len.rs b/clippy_lints/src/methods/get_last_with_len.rs index 23368238ef5c..02aada87202c 100644 --- a/clippy_lints/src/methods/get_last_with_len.rs +++ b/clippy_lints/src/methods/get_last_with_len.rs @@ -22,7 +22,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: ) = arg.kind // LHS of subtraction is "x.len()" - && let ExprKind::MethodCall(lhs_path, [lhs_recv], _) = &lhs.kind + && let ExprKind::MethodCall(lhs_path, lhs_recv, [], _) = &lhs.kind && lhs_path.ident.name == sym::len // RHS of subtraction is 1 diff --git a/clippy_lints/src/methods/inefficient_to_string.rs b/clippy_lints/src/methods/inefficient_to_string.rs index f52170df662c..e1c9b5248a8a 100644 --- a/clippy_lints/src/methods/inefficient_to_string.rs +++ b/clippy_lints/src/methods/inefficient_to_string.rs @@ -12,13 +12,19 @@ use rustc_span::symbol::{sym, Symbol}; use super::INEFFICIENT_TO_STRING; /// Checks for the `INEFFICIENT_TO_STRING` lint -pub fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, method_name: Symbol, args: &[hir::Expr<'_>]) { +pub fn check<'tcx>( + cx: &LateContext<'tcx>, + expr: &hir::Expr<'_>, + method_name: Symbol, + receiver: &hir::Expr<'_>, + args: &[hir::Expr<'_>], +) { if_chain! { - if args.len() == 1 && method_name == sym::to_string; + if args.is_empty() && method_name == sym::to_string; if let Some(to_string_meth_did) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if match_def_path(cx, to_string_meth_did, &paths::TO_STRING_METHOD); if let Some(substs) = cx.typeck_results().node_substs_opt(expr.hir_id); - let arg_ty = cx.typeck_results().expr_ty_adjusted(&args[0]); + let arg_ty = cx.typeck_results().expr_ty_adjusted(receiver); let self_ty = substs.type_at(0); let (deref_self_ty, deref_count) = walk_ptrs_ty_depth(self_ty); if deref_count >= 1; @@ -35,7 +41,7 @@ pub fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, method_name: Sy self_ty, deref_self_ty )); let mut applicability = Applicability::MachineApplicable; - let arg_snippet = snippet_with_applicability(cx, args[0].span, "..", &mut applicability); + let arg_snippet = snippet_with_applicability(cx, receiver.span, "..", &mut applicability); diag.span_suggestion( expr.span, "try dereferencing the receiver", diff --git a/clippy_lints/src/methods/into_iter_on_ref.rs b/clippy_lints/src/methods/into_iter_on_ref.rs index da13b4ba37a5..11e76841e9f0 100644 --- a/clippy_lints/src/methods/into_iter_on_ref.rs +++ b/clippy_lints/src/methods/into_iter_on_ref.rs @@ -16,9 +16,9 @@ pub(super) fn check( expr: &hir::Expr<'_>, method_span: Span, method_name: Symbol, - args: &[hir::Expr<'_>], + receiver: &hir::Expr<'_>, ) { - let self_ty = cx.typeck_results().expr_ty_adjusted(&args[0]); + let self_ty = cx.typeck_results().expr_ty_adjusted(receiver); if_chain! { if let ty::Ref(..) = self_ty.kind(); if method_name == sym::into_iter; diff --git a/clippy_lints/src/methods/iter_with_drain.rs b/clippy_lints/src/methods/iter_with_drain.rs index 152072e09c77..a669cbbbcc60 100644 --- a/clippy_lints/src/methods/iter_with_drain.rs +++ b/clippy_lints/src/methods/iter_with_drain.rs @@ -35,7 +35,7 @@ fn is_full_range(cx: &LateContext<'_>, container: &Expr<'_>, range: Range<'_>) - && range.end.map_or(true, |e| { if range.limits == RangeLimits::HalfOpen && let ExprKind::Path(QPath::Resolved(None, container_path)) = container.kind - && let ExprKind::MethodCall(name, [self_arg], _) = e.kind + && let ExprKind::MethodCall(name, self_arg, [], _) = e.kind && name.ident.name == sym::len && let ExprKind::Path(QPath::Resolved(None, path)) = self_arg.kind { diff --git a/clippy_lints/src/methods/map_clone.rs b/clippy_lints/src/methods/map_clone.rs index ffedda95ff8e..e04bb1c50792 100644 --- a/clippy_lints/src/methods/map_clone.rs +++ b/clippy_lints/src/methods/map_clone.rs @@ -48,7 +48,7 @@ pub(super) fn check<'tcx>( } } }, - hir::ExprKind::MethodCall(method, [obj], _) => if_chain! { + hir::ExprKind::MethodCall(method, obj, [], _) => if_chain! { if ident_eq(name, obj) && method.ident.name == sym::clone; if let Some(fn_id) = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id); if let Some(trait_id) = cx.tcx.trait_of_item(fn_id); diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index a0d190a58aff..16fdd36c0260 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3161,11 +3161,13 @@ impl_lint_pass!(Methods => [ ]); /// Extracts a method call name, args, and `Span` of the method name. -fn method_call<'tcx>(recv: &'tcx hir::Expr<'tcx>) -> Option<(&'tcx str, &'tcx [hir::Expr<'tcx>], Span)> { - if let ExprKind::MethodCall(path, args, _) = recv.kind { - if !args.iter().any(|e| e.span.from_expansion()) { +fn method_call<'tcx>( + recv: &'tcx hir::Expr<'tcx>, +) -> Option<(&'tcx str, &'tcx hir::Expr<'tcx>, &'tcx [hir::Expr<'tcx>], Span)> { + if let ExprKind::MethodCall(path, receiver, args, _) = recv.kind { + if !args.iter().any(|e| e.span.from_expansion()) && !receiver.span.from_expansion() { let name = path.ident.name.as_str(); - return Some((name, args, path.ident.span)); + return Some((name, receiver, args, path.ident.span)); } } None @@ -3183,17 +3185,17 @@ impl<'tcx> LateLintPass<'tcx> for Methods { hir::ExprKind::Call(func, args) => { from_iter_instead_of_collect::check(cx, expr, args, func); }, - hir::ExprKind::MethodCall(method_call, args, _) => { + hir::ExprKind::MethodCall(method_call, receiver, args, _) => { let method_span = method_call.ident.span; - or_fun_call::check(cx, expr, method_span, method_call.ident.as_str(), args); - expect_fun_call::check(cx, expr, method_span, method_call.ident.as_str(), args); - clone_on_copy::check(cx, expr, method_call.ident.name, args); - clone_on_ref_ptr::check(cx, expr, method_call.ident.name, args); - inefficient_to_string::check(cx, expr, method_call.ident.name, args); - single_char_add_str::check(cx, expr, args); - into_iter_on_ref::check(cx, expr, method_span, method_call.ident.name, args); - single_char_pattern::check(cx, expr, method_call.ident.name, args); - unnecessary_to_owned::check(cx, expr, method_call.ident.name, args, self.msrv); + or_fun_call::check(cx, expr, method_span, method_call.ident.as_str(), receiver, args); + expect_fun_call::check(cx, expr, method_span, method_call.ident.as_str(), receiver, args); + clone_on_copy::check(cx, expr, method_call.ident.name, receiver, args); + clone_on_ref_ptr::check(cx, expr, method_call.ident.name, receiver, args); + inefficient_to_string::check(cx, expr, method_call.ident.name, receiver, args); + single_char_add_str::check(cx, expr, receiver, args); + into_iter_on_ref::check(cx, expr, method_span, method_call.ident.name, receiver); + single_char_pattern::check(cx, expr, method_call.ident.name, receiver, args); + unnecessary_to_owned::check(cx, expr, method_call.ident.name, receiver, args, self.msrv); }, hir::ExprKind::Binary(op, lhs, rhs) if op.node == hir::BinOpKind::Eq || op.node == hir::BinOpKind::Ne => { let mut info = BinaryExprInfo { @@ -3379,7 +3381,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { impl Methods { #[allow(clippy::too_many_lines)] fn check_methods<'tcx>(&self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let Some((name, [recv, args @ ..], span)) = method_call(expr) { + if let Some((name, recv, [args @ ..], span)) = method_call(expr) { match (name, args) { ("add" | "offset" | "sub" | "wrapping_offset" | "wrapping_add" | "wrapping_sub", [_arg]) => { zst_offset::check(cx, expr, recv); @@ -3399,13 +3401,13 @@ impl Methods { ("assume_init", []) => uninit_assumed_init::check(cx, expr, recv), ("cloned", []) => cloned_instead_of_copied::check(cx, expr, recv, span, self.msrv), ("collect", []) => match method_call(recv) { - Some((name @ ("cloned" | "copied"), [recv2], _)) => { + Some((name @ ("cloned" | "copied"), recv2, [], _)) => { iter_cloned_collect::check(cx, name, expr, recv2); }, - Some(("map", [m_recv, m_arg], _)) => { + Some(("map", m_recv, [m_arg], _)) => { map_collect_result_unit::check(cx, expr, m_recv, m_arg, recv); }, - Some(("take", [take_self_arg, take_arg], _)) => { + Some(("take", take_self_arg, [take_arg], _)) => { if meets_msrv(self.msrv, msrvs::STR_REPEAT) { manual_str_repeat::check(cx, expr, recv, take_self_arg, take_arg); } @@ -3413,26 +3415,26 @@ impl Methods { _ => {}, }, ("count", []) if is_trait_method(cx, expr, sym::Iterator) => match method_call(recv) { - Some(("cloned", [recv2], _)) => iter_overeager_cloned::check(cx, expr, recv, recv2, true, false), - Some((name2 @ ("into_iter" | "iter" | "iter_mut"), [recv2], _)) => { + Some(("cloned", recv2, [], _)) => iter_overeager_cloned::check(cx, expr, recv, recv2, true, false), + Some((name2 @ ("into_iter" | "iter" | "iter_mut"), recv2, [], _)) => { iter_count::check(cx, expr, recv2, name2); }, - Some(("map", [_, arg], _)) => suspicious_map::check(cx, expr, recv, arg), - Some(("filter", [recv2, arg], _)) => bytecount::check(cx, expr, recv2, arg), - Some(("bytes", [recv2], _)) => bytes_count_to_len::check(cx, expr, recv, recv2), + Some(("map", _, [arg], _)) => suspicious_map::check(cx, expr, recv, arg), + Some(("filter", recv2, [arg], _)) => bytecount::check(cx, expr, recv2, arg), + Some(("bytes", recv2, [], _)) => bytes_count_to_len::check(cx, expr, recv, recv2), _ => {}, }, ("drain", [arg]) => { iter_with_drain::check(cx, expr, recv, span, arg); }, ("ends_with", [arg]) => { - if let ExprKind::MethodCall(_, _, span) = expr.kind { + if let ExprKind::MethodCall(.., span) = expr.kind { case_sensitive_file_extension_comparisons::check(cx, expr, span, recv, arg); } }, ("expect", [_]) => match method_call(recv) { - Some(("ok", [recv], _)) => ok_expect::check(cx, expr, recv), - Some(("err", [recv], err_span)) => err_expect::check(cx, expr, recv, self.msrv, span, err_span), + Some(("ok", recv, [], _)) => ok_expect::check(cx, expr, recv), + Some(("err", recv, [], err_span)) => err_expect::check(cx, expr, recv, self.msrv, span, err_span), _ => expect_used::check(cx, expr, recv, false, self.allow_expect_in_tests), }, ("expect_err", [_]) => expect_used::check(cx, expr, recv, true, self.allow_expect_in_tests), @@ -3452,13 +3454,13 @@ impl Methods { flat_map_option::check(cx, expr, arg, span); }, ("flatten", []) => match method_call(recv) { - Some(("map", [recv, map_arg], map_span)) => map_flatten::check(cx, expr, recv, map_arg, map_span), - Some(("cloned", [recv2], _)) => iter_overeager_cloned::check(cx, expr, recv, recv2, false, true), + Some(("map", recv, [map_arg], map_span)) => map_flatten::check(cx, expr, recv, map_arg, map_span), + Some(("cloned", recv2, [], _)) => iter_overeager_cloned::check(cx, expr, recv, recv2, false, true), _ => {}, }, ("fold", [init, acc]) => unnecessary_fold::check(cx, expr, init, acc, span), ("for_each", [_]) => { - if let Some(("inspect", [_, _], span2)) = method_call(recv) { + if let Some(("inspect", _, [_], span2)) = method_call(recv) { inspect_for_each::check(cx, expr, span2); } }, @@ -3478,12 +3480,12 @@ impl Methods { iter_on_single_or_empty_collections::check(cx, expr, name, recv); }, ("join", [join_arg]) => { - if let Some(("collect", _, span)) = method_call(recv) { + if let Some(("collect", _, _, span)) = method_call(recv) { unnecessary_join::check(cx, expr, recv, join_arg, span); } }, ("last", []) | ("skip", [_]) => { - if let Some((name2, [recv2, args2 @ ..], _span2)) = method_call(recv) { + if let Some((name2, recv2, [args2 @ ..], _span2)) = method_call(recv) { if let ("cloned", []) = (name2, args2) { iter_overeager_cloned::check(cx, expr, recv, recv2, false, false); } @@ -3498,7 +3500,7 @@ impl Methods { } else { map_err_ignore::check(cx, expr, m_arg); } - if let Some((name, [recv2, args @ ..], span2)) = method_call(recv) { + if let Some((name, recv2, [args @ ..], span2)) = method_call(recv) { match (name, args) { ("as_mut", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, true, self.msrv), ("as_ref", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, false, self.msrv), @@ -3518,7 +3520,7 @@ impl Methods { manual_ok_or::check(cx, expr, recv, def, map); }, ("next", []) => { - if let Some((name2, [recv2, args2 @ ..], _)) = method_call(recv) { + if let Some((name2, recv2, [args2 @ ..], _)) = method_call(recv) { match (name2, args2) { ("cloned", []) => iter_overeager_cloned::check(cx, expr, recv, recv2, false, false), ("filter", [arg]) => filter_next::check(cx, expr, recv2, arg), @@ -3531,10 +3533,10 @@ impl Methods { } }, ("nth", [n_arg]) => match method_call(recv) { - Some(("bytes", [recv2], _)) => bytes_nth::check(cx, expr, recv2, n_arg), - Some(("cloned", [recv2], _)) => iter_overeager_cloned::check(cx, expr, recv, recv2, false, false), - Some(("iter", [recv2], _)) => iter_nth::check(cx, expr, recv2, recv, n_arg, false), - Some(("iter_mut", [recv2], _)) => iter_nth::check(cx, expr, recv2, recv, n_arg, true), + Some(("bytes", recv2, [], _)) => bytes_nth::check(cx, expr, recv2, n_arg), + Some(("cloned", recv2, [], _)) => iter_overeager_cloned::check(cx, expr, recv, recv2, false, false), + Some(("iter", recv2, [], _)) => iter_nth::check(cx, expr, recv2, recv, n_arg, false), + Some(("iter_mut", recv2, [], _)) => iter_nth::check(cx, expr, recv2, recv, n_arg, true), _ => iter_nth_zero::check(cx, expr, recv, n_arg), }, ("ok_or_else", [arg]) => unnecessary_lazy_eval::check(cx, expr, recv, arg, "ok_or"), @@ -3591,7 +3593,7 @@ impl Methods { }, ("step_by", [arg]) => iterator_step_by_zero::check(cx, expr, arg), ("take", [_arg]) => { - if let Some((name2, [recv2, args2 @ ..], _span2)) = method_call(recv) { + if let Some((name2, recv2, [args2 @ ..], _span2)) = method_call(recv) { if let ("cloned", []) = (name2, args2) { iter_overeager_cloned::check(cx, expr, recv, recv2, false, false); } @@ -3614,13 +3616,13 @@ impl Methods { }, ("unwrap", []) => { match method_call(recv) { - Some(("get", [recv, get_arg], _)) => { + Some(("get", recv, [get_arg], _)) => { get_unwrap::check(cx, expr, recv, get_arg, false); }, - Some(("get_mut", [recv, get_arg], _)) => { + Some(("get_mut", recv, [get_arg], _)) => { get_unwrap::check(cx, expr, recv, get_arg, true); }, - Some(("or", [recv, or_arg], or_span)) => { + Some(("or", recv, [or_arg], or_span)) => { or_then_unwrap::check(cx, expr, recv, or_arg, or_span); }, _ => {}, @@ -3629,19 +3631,19 @@ impl Methods { }, ("unwrap_err", []) => unwrap_used::check(cx, expr, recv, true, self.allow_unwrap_in_tests), ("unwrap_or", [u_arg]) => match method_call(recv) { - Some((arith @ ("checked_add" | "checked_sub" | "checked_mul"), [lhs, rhs], _)) => { + Some((arith @ ("checked_add" | "checked_sub" | "checked_mul"), lhs, [rhs], _)) => { manual_saturating_arithmetic::check(cx, expr, lhs, rhs, u_arg, &arith["checked_".len()..]); }, - Some(("map", [m_recv, m_arg], span)) => { + Some(("map", m_recv, [m_arg], span)) => { option_map_unwrap_or::check(cx, expr, m_recv, m_arg, recv, u_arg, span); }, - Some(("then_some", [t_recv, t_arg], _)) => { + Some(("then_some", t_recv, [t_arg], _)) => { obfuscated_if_else::check(cx, expr, t_recv, t_arg, u_arg); }, _ => {}, }, ("unwrap_or_else", [u_arg]) => match method_call(recv) { - Some(("map", [recv, map_arg], _)) + Some(("map", recv, [map_arg], _)) if map_unwrap_or::check(cx, expr, recv, map_arg, u_arg, self.msrv) => {}, _ => { unwrap_or_else_default::check(cx, expr, recv, u_arg); @@ -3649,7 +3651,7 @@ impl Methods { }, }, ("zip", [arg]) => { - if let ExprKind::MethodCall(name, [iter_recv], _) = recv.kind + if let ExprKind::MethodCall(name, iter_recv, [], _) = recv.kind && name.ident.name == sym::iter { range_zip_with_len::check(cx, expr, iter_recv, arg); @@ -3662,7 +3664,7 @@ impl Methods { } fn check_is_some_is_none(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, is_some: bool) { - if let Some((name @ ("find" | "position" | "rposition"), [f_recv, arg], span)) = method_call(recv) { + if let Some((name @ ("find" | "position" | "rposition"), f_recv, [arg], span)) = method_call(recv) { search_is_some::check(cx, expr, name, is_some, f_recv, arg, recv, span); } } diff --git a/clippy_lints/src/methods/open_options.rs b/clippy_lints/src/methods/open_options.rs index c3112823e346..903fa306f935 100644 --- a/clippy_lints/src/methods/open_options.rs +++ b/clippy_lints/src/methods/open_options.rs @@ -36,12 +36,12 @@ enum OpenOption { } fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec<(OpenOption, Argument)>) { - if let ExprKind::MethodCall(path, arguments, _) = argument.kind { - let obj_ty = cx.typeck_results().expr_ty(&arguments[0]).peel_refs(); + if let ExprKind::MethodCall(path, receiver, arguments, _) = argument.kind { + let obj_ty = cx.typeck_results().expr_ty(receiver).peel_refs(); // Only proceed if this is a call on some object of type std::fs::OpenOptions - if match_type(cx, obj_ty, &paths::OPEN_OPTIONS) && arguments.len() >= 2 { - let argument_option = match arguments[1].kind { + if match_type(cx, obj_ty, &paths::OPEN_OPTIONS) && arguments.len() >= 1 { + let argument_option = match arguments[0].kind { ExprKind::Lit(ref span) => { if let Spanned { node: LitKind::Bool(lit), @@ -77,7 +77,7 @@ fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec _ => (), } - get_open_options(cx, &arguments[0], options); + get_open_options(cx, receiver, options); } } } diff --git a/clippy_lints/src/methods/option_as_ref_deref.rs b/clippy_lints/src/methods/option_as_ref_deref.rs index 20cad0f181e9..81c67b4ca6a5 100644 --- a/clippy_lints/src/methods/option_as_ref_deref.rs +++ b/clippy_lints/src/methods/option_as_ref_deref.rs @@ -56,13 +56,12 @@ pub(super) fn check<'tcx>( let closure_expr = peel_blocks(&closure_body.value); match &closure_expr.kind { - hir::ExprKind::MethodCall(_, args, _) => { + hir::ExprKind::MethodCall(_, receiver, [], _) => { if_chain! { - if args.len() == 1; - if path_to_local_id(&args[0], closure_body.params[0].pat.hir_id); + if path_to_local_id(receiver, closure_body.params[0].pat.hir_id); let adj = cx .typeck_results() - .expr_adjustments(&args[0]) + .expr_adjustments(receiver) .iter() .map(|x| &x.kind) .collect::>(); diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index 6af134019a47..76876d866293 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -20,6 +20,7 @@ pub(super) fn check<'tcx>( expr: &hir::Expr<'_>, method_span: Span, name: &str, + receiver: &'tcx hir::Expr<'_>, args: &'tcx [hir::Expr<'_>], ) { /// Checks for `unwrap_or(T::new())` or `unwrap_or(T::default())`. @@ -144,7 +145,7 @@ pub(super) fn check<'tcx>( } } - if let [self_arg, arg] = args { + if let [arg] = args { let inner_arg = if let hir::ExprKind::Block( hir::Block { stmts: [], @@ -163,11 +164,11 @@ pub(super) fn check<'tcx>( let or_has_args = !or_args.is_empty(); if !check_unwrap_or_default(cx, name, fun, arg, or_has_args, expr.span, method_span) { let fun_span = if or_has_args { None } else { Some(fun.span) }; - check_general_case(cx, name, method_span, self_arg, arg, expr.span, fun_span); + check_general_case(cx, name, method_span, receiver, arg, expr.span, fun_span); } }, hir::ExprKind::Index(..) | hir::ExprKind::MethodCall(..) => { - check_general_case(cx, name, method_span, self_arg, arg, expr.span, None); + check_general_case(cx, name, method_span, receiver, arg, expr.span, None); }, _ => (), } diff --git a/clippy_lints/src/methods/range_zip_with_len.rs b/clippy_lints/src/methods/range_zip_with_len.rs index 00a2a0d14d11..867a3b402377 100644 --- a/clippy_lints/src/methods/range_zip_with_len.rs +++ b/clippy_lints/src/methods/range_zip_with_len.rs @@ -16,7 +16,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &' if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::Range::hir(zip_arg); if is_integer_const(cx, start, 0); // `.len()` call - if let ExprKind::MethodCall(len_path, [len_recv], _) = end.kind; + if let ExprKind::MethodCall(len_path, len_recv, [], _) = end.kind; if len_path.ident.name == sym::len; // `.iter()` and `.len()` called on same `Path` if let ExprKind::Path(QPath::Resolved(_, iter_path)) = recv.kind; diff --git a/clippy_lints/src/methods/single_char_add_str.rs b/clippy_lints/src/methods/single_char_add_str.rs index 9a5fabcf7cd5..81450fd8c6c3 100644 --- a/clippy_lints/src/methods/single_char_add_str.rs +++ b/clippy_lints/src/methods/single_char_add_str.rs @@ -3,12 +3,12 @@ use clippy_utils::{match_def_path, paths}; use rustc_hir as hir; use rustc_lint::LateContext; -pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { +pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, receiver: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { if let Some(fn_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) { if match_def_path(cx, fn_def_id, &paths::PUSH_STR) { - single_char_push_string::check(cx, expr, args); + single_char_push_string::check(cx, expr, receiver, args); } else if match_def_path(cx, fn_def_id, &paths::INSERT_STR) { - single_char_insert_string::check(cx, expr, args); + single_char_insert_string::check(cx, expr, receiver, args); } } } diff --git a/clippy_lints/src/methods/single_char_insert_string.rs b/clippy_lints/src/methods/single_char_insert_string.rs index 6cdc954c03be..18b6b5be175d 100644 --- a/clippy_lints/src/methods/single_char_insert_string.rs +++ b/clippy_lints/src/methods/single_char_insert_string.rs @@ -8,12 +8,12 @@ use rustc_lint::LateContext; use super::SINGLE_CHAR_ADD_STR; /// lint for length-1 `str`s as argument for `insert_str` -pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { +pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, receiver: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { let mut applicability = Applicability::MachineApplicable; - if let Some(extension_string) = get_hint_if_single_char_arg(cx, &args[2], &mut applicability) { + if let Some(extension_string) = get_hint_if_single_char_arg(cx, &args[1], &mut applicability) { let base_string_snippet = - snippet_with_applicability(cx, args[0].span.source_callsite(), "_", &mut applicability); - let pos_arg = snippet_with_applicability(cx, args[1].span, "..", &mut applicability); + snippet_with_applicability(cx, receiver.span.source_callsite(), "_", &mut applicability); + let pos_arg = snippet_with_applicability(cx, args[0].span, "..", &mut applicability); let sugg = format!("{}.insert({}, {})", base_string_snippet, pos_arg, extension_string); span_lint_and_sugg( cx, diff --git a/clippy_lints/src/methods/single_char_pattern.rs b/clippy_lints/src/methods/single_char_pattern.rs index bf9006c69062..4221c52d5cd7 100644 --- a/clippy_lints/src/methods/single_char_pattern.rs +++ b/clippy_lints/src/methods/single_char_pattern.rs @@ -10,37 +10,43 @@ use rustc_span::symbol::Symbol; use super::SINGLE_CHAR_PATTERN; const PATTERN_METHODS: [(&str, usize); 24] = [ - ("contains", 1), - ("starts_with", 1), - ("ends_with", 1), - ("find", 1), - ("rfind", 1), - ("split", 1), - ("split_inclusive", 1), - ("rsplit", 1), - ("split_terminator", 1), - ("rsplit_terminator", 1), - ("splitn", 2), - ("rsplitn", 2), - ("split_once", 1), - ("rsplit_once", 1), - ("matches", 1), - ("rmatches", 1), - ("match_indices", 1), - ("rmatch_indices", 1), - ("strip_prefix", 1), - ("strip_suffix", 1), - ("trim_start_matches", 1), - ("trim_end_matches", 1), - ("replace", 1), - ("replacen", 1), + ("contains", 0), + ("starts_with", 0), + ("ends_with", 0), + ("find", 0), + ("rfind", 0), + ("split", 0), + ("split_inclusive", 0), + ("rsplit", 0), + ("split_terminator", 0), + ("rsplit_terminator", 0), + ("splitn", 1), + ("rsplitn", 1), + ("split_once", 0), + ("rsplit_once", 0), + ("matches", 0), + ("rmatches", 0), + ("match_indices", 0), + ("rmatch_indices", 0), + ("strip_prefix", 0), + ("strip_suffix", 0), + ("trim_start_matches", 0), + ("trim_end_matches", 0), + ("replace", 0), + ("replacen", 0), ]; /// lint for length-1 `str`s for methods in `PATTERN_METHODS` -pub(super) fn check(cx: &LateContext<'_>, _expr: &hir::Expr<'_>, method_name: Symbol, args: &[hir::Expr<'_>]) { +pub(super) fn check( + cx: &LateContext<'_>, + _expr: &hir::Expr<'_>, + method_name: Symbol, + receiver: &hir::Expr<'_>, + args: &[hir::Expr<'_>], +) { for &(method, pos) in &PATTERN_METHODS { if_chain! { - if let ty::Ref(_, ty, _) = cx.typeck_results().expr_ty_adjusted(&args[0]).kind(); + if let ty::Ref(_, ty, _) = cx.typeck_results().expr_ty_adjusted(receiver).kind(); if *ty.kind() == ty::Str; if method_name.as_str() == method && args.len() > pos; let arg = &args[pos]; diff --git a/clippy_lints/src/methods/single_char_push_string.rs b/clippy_lints/src/methods/single_char_push_string.rs index 0237d39cbdb4..9ea6751956ab 100644 --- a/clippy_lints/src/methods/single_char_push_string.rs +++ b/clippy_lints/src/methods/single_char_push_string.rs @@ -8,11 +8,11 @@ use rustc_lint::LateContext; use super::SINGLE_CHAR_ADD_STR; /// lint for length-1 `str`s as argument for `push_str` -pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { +pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, receiver: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { let mut applicability = Applicability::MachineApplicable; - if let Some(extension_string) = get_hint_if_single_char_arg(cx, &args[1], &mut applicability) { + if let Some(extension_string) = get_hint_if_single_char_arg(cx, &args[0], &mut applicability) { let base_string_snippet = - snippet_with_applicability(cx, args[0].span.source_callsite(), "..", &mut applicability); + snippet_with_applicability(cx, receiver.span.source_callsite(), "..", &mut applicability); let sugg = format!("{}.push({})", base_string_snippet, extension_string); span_lint_and_sugg( cx, diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 4ac738272d08..8f2f47525147 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -292,7 +292,7 @@ fn parse_iter_usage<'tcx>( ) -> Option { let (kind, span) = match iter.next() { Some((_, Node::Expr(e))) if e.span.ctxt() == ctxt => { - let (name, args) = if let ExprKind::MethodCall(name, [_, args @ ..], _) = e.kind { + let (name, args) = if let ExprKind::MethodCall(name, _, [args @ ..], _) = e.kind { (name, args) } else { return None; @@ -327,7 +327,7 @@ fn parse_iter_usage<'tcx>( } else { if_chain! { if let Some((_, Node::Expr(next_expr))) = iter.next(); - if let ExprKind::MethodCall(next_name, [_], _) = next_expr.kind; + if let ExprKind::MethodCall(next_name, _, [], _) = next_expr.kind; if next_name.ident.name == sym::next; if next_expr.span.ctxt() == ctxt; if let Some(next_id) = cx.typeck_results().type_dependent_def_id(next_expr.hir_id); @@ -367,7 +367,7 @@ fn parse_iter_usage<'tcx>( } }, _ if e.span.ctxt() != ctxt => (None, span), - ExprKind::MethodCall(name, [_], _) + ExprKind::MethodCall(name, _, [], _) if name.ident.name == sym::unwrap && cx .typeck_results() diff --git a/clippy_lints/src/methods/string_extend_chars.rs b/clippy_lints/src/methods/string_extend_chars.rs index d06658f2a5e6..143dcee35052 100644 --- a/clippy_lints/src/methods/string_extend_chars.rs +++ b/clippy_lints/src/methods/string_extend_chars.rs @@ -16,7 +16,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr return; } if let Some(arglists) = method_chain_args(arg, &["chars"]) { - let target = &arglists[0][0]; + let target = &arglists[0].0; let self_ty = cx.typeck_results().expr_ty(target).peel_refs(); let ref_str = if *self_ty.kind() == ty::Str { "" diff --git a/clippy_lints/src/methods/unnecessary_iter_cloned.rs b/clippy_lints/src/methods/unnecessary_iter_cloned.rs index 19037093e20a..95138c0e25b0 100644 --- a/clippy_lints/src/methods/unnecessary_iter_cloned.rs +++ b/clippy_lints/src/methods/unnecessary_iter_cloned.rs @@ -43,7 +43,7 @@ pub fn check_for_loop_iter( if let Some(receiver_snippet) = snippet_opt(cx, receiver.span); then { let snippet = if_chain! { - if let ExprKind::MethodCall(maybe_iter_method_name, [collection], _) = receiver.kind; + if let ExprKind::MethodCall(maybe_iter_method_name, collection, [], _) = receiver.kind; if maybe_iter_method_name.ident.name == sym::iter; if let Some(iterator_trait_id) = cx.tcx.get_diagnostic_item(sym::Iterator); diff --git a/clippy_lints/src/methods/unnecessary_lazy_eval.rs b/clippy_lints/src/methods/unnecessary_lazy_eval.rs index 1876c7fb9d05..a187a8d6016f 100644 --- a/clippy_lints/src/methods/unnecessary_lazy_eval.rs +++ b/clippy_lints/src/methods/unnecessary_lazy_eval.rs @@ -54,7 +54,7 @@ pub(super) fn check<'tcx>( // This is a duplicate of what's happening in clippy_lints::methods::method_call, // which isn't ideal, We want to get the method call span, // but prefer to avoid changing the signature of the function itself. - if let hir::ExprKind::MethodCall(_, _, span) = expr.kind { + if let hir::ExprKind::MethodCall(.., span) = expr.kind { span_lint_and_then(cx, UNNECESSARY_LAZY_EVALUATIONS, expr.span, msg, |diag| { diag.span_suggestion( span, diff --git a/clippy_lints/src/methods/unnecessary_sort_by.rs b/clippy_lints/src/methods/unnecessary_sort_by.rs index 1966990bd774..6f25acca1de6 100644 --- a/clippy_lints/src/methods/unnecessary_sort_by.rs +++ b/clippy_lints/src/methods/unnecessary_sort_by.rs @@ -50,9 +50,13 @@ fn mirrored_exprs(a_expr: &Expr<'_>, a_ident: &Ident, b_expr: &Expr<'_>, b_ident // The two exprs are method calls. // Check to see that the function is the same and the arguments are mirrored // This is enough because the receiver of the method is listed in the arguments - (ExprKind::MethodCall(left_segment, left_args, _), ExprKind::MethodCall(right_segment, right_args, _)) => { + ( + ExprKind::MethodCall(left_segment, left_receiver, left_args, _), + ExprKind::MethodCall(right_segment, right_receiver, right_args, _), + ) => { left_segment.ident == right_segment.ident && iter::zip(*left_args, *right_args).all(|(left, right)| mirrored_exprs(left, a_ident, right, b_ident)) + && mirrored_exprs(left_receiver, a_ident, right_receiver, b_ident) }, // Two tuples with mirrored contents (ExprKind::Tup(left_exprs), ExprKind::Tup(right_exprs)) => { @@ -125,7 +129,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: &Exp Param { pat: Pat { kind: PatKind::Binding(_, _, left_ident, _), .. }, ..}, Param { pat: Pat { kind: PatKind::Binding(_, _, right_ident, _), .. }, .. } ] = &closure_body.params; - if let ExprKind::MethodCall(method_path, [left_expr, right_expr], _) = closure_body.value.kind; + if let ExprKind::MethodCall(method_path, left_expr, [right_expr], _) = closure_body.value.kind; if method_path.ident.name == sym::cmp; if is_trait_method(cx, &closure_body.value, sym::Ord); then { diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 44bf84352943..9dceb9af2f22 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -24,12 +24,13 @@ pub fn check<'tcx>( cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, method_name: Symbol, - args: &'tcx [Expr<'tcx>], + receiver: &'tcx Expr<'_>, + args: &'tcx [Expr<'_>], msrv: Option, ) { if_chain! { if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); - if let [receiver] = args; + if args.is_empty(); then { if is_cloned_or_copied(cx, method_name, method_def_id) { unnecessary_iter_cloned::check(cx, expr, method_name, receiver); @@ -245,9 +246,14 @@ fn check_other_call_arg<'tcx>( ) -> bool { if_chain! { if let Some((maybe_call, maybe_arg)) = skip_addr_of_ancestors(cx, expr); - if let Some((callee_def_id, call_substs, call_args)) = get_callee_substs_and_args(cx, maybe_call); + if let Some((callee_def_id, call_substs, call_receiver, call_args)) = get_callee_substs_and_args(cx, maybe_call); let fn_sig = cx.tcx.fn_sig(callee_def_id).skip_binder(); - if let Some(i) = call_args.iter().position(|arg| arg.hir_id == maybe_arg.hir_id); + let index = if let Some(call_receiver) = call_receiver { + std::iter::once(call_receiver).chain(call_args.iter()).position(|arg| arg.hir_id == maybe_arg.hir_id) + } else { + call_args.iter().position(|arg| arg.hir_id == maybe_arg.hir_id) + }; + if let Some(i) = index; if let Some(input) = fn_sig.inputs().get(i); let (input, n_refs) = peel_mid_ty_refs(*input); if let (trait_predicates, projection_predicates) = get_input_traits_and_projections(cx, callee_def_id, input); @@ -342,22 +348,22 @@ fn skip_addr_of_ancestors<'tcx>( fn get_callee_substs_and_args<'tcx>( cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, -) -> Option<(DefId, SubstsRef<'tcx>, &'tcx [Expr<'tcx>])> { +) -> Option<(DefId, SubstsRef<'tcx>, Option<&'tcx Expr<'tcx>>, &'tcx [Expr<'tcx>])> { if_chain! { if let ExprKind::Call(callee, args) = expr.kind; let callee_ty = cx.typeck_results().expr_ty(callee); if let ty::FnDef(callee_def_id, _) = callee_ty.kind(); then { let substs = cx.typeck_results().node_substs(callee.hir_id); - return Some((*callee_def_id, substs, args)); + return Some((*callee_def_id, substs, None, args)); } } if_chain! { - if let ExprKind::MethodCall(_, args, _) = expr.kind; + if let ExprKind::MethodCall(_, receiver, args, _) = expr.kind; if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); then { let substs = cx.typeck_results().node_substs(expr.hir_id); - return Some((method_def_id, substs, args)); + return Some((method_def_id, substs, Some(receiver), args)); } } None diff --git a/clippy_lints/src/methods/utils.rs b/clippy_lints/src/methods/utils.rs index 3015531e8439..ae6b165fdc36 100644 --- a/clippy_lints/src/methods/utils.rs +++ b/clippy_lints/src/methods/utils.rs @@ -28,7 +28,7 @@ pub(super) fn derefs_to_slice<'tcx>( } } - if let hir::ExprKind::MethodCall(path, [self_arg, ..], _) = &expr.kind { + if let hir::ExprKind::MethodCall(path, self_arg, ..) = &expr.kind { if path.ident.name == sym::iter && may_slice(cx, cx.typeck_results().expr_ty(self_arg)) { Some(self_arg) } else { @@ -139,9 +139,9 @@ impl<'cx, 'tcx> Visitor<'tcx> for CloneOrCopyVisitor<'cx, 'tcx> { self.addr_of_exprs.push(parent); return; }, - ExprKind::MethodCall(_, args, _) => { + ExprKind::MethodCall(.., args, _) => { if_chain! { - if args.iter().skip(1).all(|arg| !self.is_binding(arg)); + if args.iter().all(|arg| !self.is_binding(arg)); if let Some(method_def_id) = self.cx.typeck_results().type_dependent_def_id(parent.hir_id); let method_ty = self.cx.tcx.type_of(method_def_id); let self_ty = method_ty.fn_sig(self.cx.tcx).input(0).skip_binder(); diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index a081cde85725..c618f6b5d926 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -75,23 +75,22 @@ fn min_max<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(MinMax, Cons .qpath_res(qpath, path.hir_id) .opt_def_id() .and_then(|def_id| match cx.tcx.get_diagnostic_name(def_id) { - Some(sym::cmp_min) => fetch_const(cx, args, MinMax::Min), - Some(sym::cmp_max) => fetch_const(cx, args, MinMax::Max), + Some(sym::cmp_min) => fetch_const(cx, None, args, MinMax::Min), + Some(sym::cmp_max) => fetch_const(cx, None, args, MinMax::Max), _ => None, }) } else { None } }, - ExprKind::MethodCall(path, args, _) => { + ExprKind::MethodCall(path, receiver, args @ [_], _) => { if_chain! { - if let [obj, _] = args; - if cx.typeck_results().expr_ty(obj).is_floating_point() || match_trait_method(cx, expr, &paths::ORD); + if cx.typeck_results().expr_ty(receiver).is_floating_point() || match_trait_method(cx, expr, &paths::ORD); then { if path.ident.name == sym!(max) { - fetch_const(cx, args, MinMax::Max) + fetch_const(cx, Some(receiver), args, MinMax::Max) } else if path.ident.name == sym!(min) { - fetch_const(cx, args, MinMax::Min) + fetch_const(cx, Some(receiver), args, MinMax::Min) } else { None } @@ -104,16 +103,26 @@ fn min_max<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(MinMax, Cons } } -fn fetch_const<'a>(cx: &LateContext<'_>, args: &'a [Expr<'a>], m: MinMax) -> Option<(MinMax, Constant, &'a Expr<'a>)> { - if args.len() != 2 { +fn fetch_const<'a>( + cx: &LateContext<'_>, + receiver: Option<&'a Expr<'a>>, + args: &'a [Expr<'a>], + m: MinMax, +) -> Option<(MinMax, Constant, &'a Expr<'a>)> { + if (receiver.is_some() && args.len() != 1) || (receiver.is_none() && args.len() != 2) { return None; } - constant_simple(cx, cx.typeck_results(), &args[0]).map_or_else( - || constant_simple(cx, cx.typeck_results(), &args[1]).map(|c| (m, c, &args[0])), + let (arg0, arg1) = if let Some(receiver) = receiver { + (receiver, &args[0]) + } else { + (&args[0], &args[1]) + }; + constant_simple(cx, cx.typeck_results(), arg0).map_or_else( + || constant_simple(cx, cx.typeck_results(), arg1).map(|c| (m, c, arg0)), |c| { - if constant_simple(cx, cx.typeck_results(), &args[1]).is_none() { + if constant_simple(cx, cx.typeck_results(), arg1).is_none() { // otherwise ignore - Some((m, c, &args[1])) + Some((m, c, arg1)) } else { None } diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index f434a655f8af..82dc03ef5c5b 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -43,18 +43,24 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed { if let ExprKind::Path(ref path) = fn_expr.kind { check_arguments( cx, - arguments, + arguments.iter().collect(), cx.typeck_results().expr_ty(fn_expr), &rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false)), "function", ); } }, - ExprKind::MethodCall(path, arguments, _) => { + ExprKind::MethodCall(path, receiver, arguments, _) => { let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap(); let substs = cx.typeck_results().node_substs(e.hir_id); let method_type = cx.tcx.bound_type_of(def_id).subst(cx.tcx, substs); - check_arguments(cx, arguments, method_type, path.ident.as_str(), "method"); + check_arguments( + cx, + std::iter::once(receiver).chain(arguments.iter()).collect(), + method_type, + path.ident.as_str(), + "method", + ); }, _ => (), } @@ -63,7 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed { fn check_arguments<'tcx>( cx: &LateContext<'tcx>, - arguments: &[Expr<'_>], + arguments: Vec<&Expr<'_>>, type_definition: Ty<'tcx>, name: &str, fn_kind: &str, diff --git a/clippy_lints/src/needless_for_each.rs b/clippy_lints/src/needless_for_each.rs index 10e188ecb79a..f8cc3fbb3cdf 100644 --- a/clippy_lints/src/needless_for_each.rs +++ b/clippy_lints/src/needless_for_each.rs @@ -56,12 +56,12 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessForEach { if_chain! { // Check the method name is `for_each`. - if let ExprKind::MethodCall(method_name, [for_each_recv, for_each_arg], _) = expr.kind; + if let ExprKind::MethodCall(method_name, for_each_recv, [for_each_arg], _) = expr.kind; if method_name.ident.name == Symbol::intern("for_each"); // Check `for_each` is an associated function of `Iterator`. if is_trait_method(cx, expr, sym::Iterator); // Checks the receiver of `for_each` is also a method call. - if let ExprKind::MethodCall(_, [iter_recv], _) = for_each_recv.kind; + if let ExprKind::MethodCall(_, iter_recv, [], _) = for_each_recv.kind; // Skip the lint if the call chain is too long. e.g. `v.field.iter().for_each()` or // `v.foo().iter().for_each()` must be skipped. if matches!( diff --git a/clippy_lints/src/non_octal_unix_permissions.rs b/clippy_lints/src/non_octal_unix_permissions.rs index ed022b9d5291..25fb4f0f4cff 100644 --- a/clippy_lints/src/non_octal_unix_permissions.rs +++ b/clippy_lints/src/non_octal_unix_permissions.rs @@ -43,7 +43,7 @@ declare_lint_pass!(NonOctalUnixPermissions => [NON_OCTAL_UNIX_PERMISSIONS]); impl<'tcx> LateLintPass<'tcx> for NonOctalUnixPermissions { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { match &expr.kind { - ExprKind::MethodCall(path, [func, param], _) => { + ExprKind::MethodCall(path, func, [param], _) => { let obj_ty = cx.typeck_results().expr_ty(func).peel_refs(); if_chain! { diff --git a/clippy_lints/src/only_used_in_recursion.rs b/clippy_lints/src/only_used_in_recursion.rs index 774a3540d1e0..17d5fa2152bb 100644 --- a/clippy_lints/src/only_used_in_recursion.rs +++ b/clippy_lints/src/only_used_in_recursion.rs @@ -304,13 +304,13 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion { } return; }, - ExprKind::MethodCall(_, args, _) + ExprKind::MethodCall(_, receiver, args, _) if typeck.type_dependent_def_id(parent.hir_id).map_or(false, |id| { id == param.fn_id && has_matching_substs(param.fn_kind, typeck.node_substs(parent.hir_id)) }) => { - if let Some(idx) = args.iter().position(|arg| arg.hir_id == child_id) { + if let Some(idx) = std::iter::once(receiver).chain(args.iter()).position(|arg| arg.hir_id == child_id) { param.uses.push(Usage::new(span, idx)); } return; diff --git a/clippy_lints/src/operators/cmp_owned.rs b/clippy_lints/src/operators/cmp_owned.rs index e1f9b5906f66..638a514ff9b3 100644 --- a/clippy_lints/src/operators/cmp_owned.rs +++ b/clippy_lints/src/operators/cmp_owned.rs @@ -38,7 +38,7 @@ fn symmetric_partial_eq<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, other: Ty<'t fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool) { let typeck = cx.typeck_results(); let (arg, arg_span) = match expr.kind { - ExprKind::MethodCall(.., [arg], _) + ExprKind::MethodCall(_, arg, [], _) if typeck .type_dependent_def_id(expr.hir_id) .and_then(|id| cx.tcx.trait_of_item(id)) diff --git a/clippy_lints/src/operators/duration_subsec.rs b/clippy_lints/src/operators/duration_subsec.rs index 0d067d1e1968..827a2b267093 100644 --- a/clippy_lints/src/operators/duration_subsec.rs +++ b/clippy_lints/src/operators/duration_subsec.rs @@ -17,7 +17,7 @@ pub(crate) fn check<'tcx>( right: &'tcx Expr<'_>, ) { if op == BinOpKind::Div - && let ExprKind::MethodCall(method_path, [self_arg], _) = left.kind + && let ExprKind::MethodCall(method_path, self_arg, [], _) = left.kind && is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(self_arg).peel_refs(), sym::Duration) && let Some((Constant::Int(divisor), _)) = constant(cx, cx.typeck_results(), right) { diff --git a/clippy_lints/src/operators/float_cmp.rs b/clippy_lints/src/operators/float_cmp.rs index 0ef793443ff4..97ddcdb24799 100644 --- a/clippy_lints/src/operators/float_cmp.rs +++ b/clippy_lints/src/operators/float_cmp.rs @@ -113,7 +113,7 @@ fn is_signum(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { } if_chain! { - if let ExprKind::MethodCall(method_name, [ref self_arg, ..], _) = expr.kind; + if let ExprKind::MethodCall(method_name, self_arg, ..) = expr.kind; if sym!(signum) == method_name.ident.name; // Check that the receiver of the signum() is a float (expressions[0] is the receiver of // the method call) diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 3c5ea2d94144..63c9faf0396f 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -591,8 +591,11 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: set_skip_flag(); } }, - ExprKind::MethodCall(name, expr_args @ [self_arg, ..], _) => { - let i = expr_args.iter().position(|arg| arg.hir_id == child_id).unwrap_or(0); + ExprKind::MethodCall(name, self_arg, expr_args, _) => { + let i = std::iter::once(self_arg) + .chain(expr_args.iter()) + .position(|arg| arg.hir_id == child_id) + .unwrap_or(0); if i == 0 { // Check if the method can be renamed. let name = name.ident.as_str(); diff --git a/clippy_lints/src/ptr_offset_with_cast.rs b/clippy_lints/src/ptr_offset_with_cast.rs index b907f38afbb9..4dc65da3ea1f 100644 --- a/clippy_lints/src/ptr_offset_with_cast.rs +++ b/clippy_lints/src/ptr_offset_with_cast.rs @@ -93,7 +93,7 @@ fn expr_as_ptr_offset_call<'tcx>( cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, ) -> Option<(&'tcx Expr<'tcx>, &'tcx Expr<'tcx>, Method)> { - if let ExprKind::MethodCall(path_segment, [arg_0, arg_1, ..], _) = &expr.kind { + if let ExprKind::MethodCall(path_segment, arg_0, [arg_1, ..], _) = &expr.kind { if is_expr_ty_raw_ptr(cx, arg_0) { if path_segment.ident.name == sym::offset { return Some((arg_0, arg_1, Method::Offset)); diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index b432ccb1ee32..6fddbd419bcd 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -86,7 +86,7 @@ fn check_is_none_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr: &Ex if_chain! { if let Some(higher::If { cond, then, r#else }) = higher::If::hir(expr); if !is_else_clause(cx.tcx, expr); - if let ExprKind::MethodCall(segment, [caller, ..], _) = &cond.kind; + if let ExprKind::MethodCall(segment, caller, ..) = &cond.kind; let caller_ty = cx.typeck_results().expr_ty(caller); let if_block = IfBlockType::IfIs(caller, caller_ty, segment.ident.name, then, r#else); if is_early_return(sym::Option, cx, &if_block) || is_early_return(sym::Result, cx, &if_block); diff --git a/clippy_lints/src/read_zero_byte_vec.rs b/clippy_lints/src/read_zero_byte_vec.rs index 9538a8104739..94dec191103c 100644 --- a/clippy_lints/src/read_zero_byte_vec.rs +++ b/clippy_lints/src/read_zero_byte_vec.rs @@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for ReadZeroByteVec { // finds use of `_.read(&mut v)` let mut read_found = false; let mut visitor = expr_visitor_no_bodies(|expr| { - if let ExprKind::MethodCall(path, [_self, arg], _) = expr.kind + if let ExprKind::MethodCall(path, _self, [arg], _) = expr.kind && let PathSegment { ident: read_or_read_exact, .. } = *path && matches!(read_or_read_exact.as_str(), "read" | "read_exact") && let ExprKind::AddrOf(_, hir::Mutability::Mut, inner) = arg.kind diff --git a/clippy_lints/src/size_of_in_element_count.rs b/clippy_lints/src/size_of_in_element_count.rs index bfb9f0d01e1d..ac4e29e9dfdf 100644 --- a/clippy_lints/src/size_of_in_element_count.rs +++ b/clippy_lints/src/size_of_in_element_count.rs @@ -108,7 +108,7 @@ fn get_pointee_ty_and_count_expr<'tcx>( }; if_chain! { // Find calls to copy_{from,to}{,_nonoverlapping} and write_bytes methods - if let ExprKind::MethodCall(method_path, [ptr_self, .., count], _) = expr.kind; + if let ExprKind::MethodCall(method_path, ptr_self, [.., count], _) = expr.kind; let method_ident = method_path.ident.as_str(); if METHODS.iter().any(|m| *m == method_ident); diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index b59a25e3a400..b35782184670 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -201,7 +201,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { fn search_slow_extend_filling(&mut self, expr: &'tcx Expr<'_>) { if_chain! { if self.initialization_found; - if let ExprKind::MethodCall(path, [self_arg, extend_arg], _) = expr.kind; + if let ExprKind::MethodCall(path, self_arg, [extend_arg], _) = expr.kind; if path_to_local_id(self_arg, self.vec_alloc.local_id); if path.ident.name == sym!(extend); if self.is_repeat_take(extend_arg); @@ -215,7 +215,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { /// Checks if the given expression is resizing a vector with 0 fn search_slow_resize_filling(&mut self, expr: &'tcx Expr<'_>) { if self.initialization_found - && let ExprKind::MethodCall(path, [self_arg, len_arg, fill_arg], _) = expr.kind + && let ExprKind::MethodCall(path, self_arg, [len_arg, fill_arg], _) = expr.kind && path_to_local_id(self_arg, self.vec_alloc.local_id) && path.ident.name == sym!(resize) // Check that is filled with 0 @@ -224,7 +224,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { // Check that len expression is equals to `with_capacity` expression if SpanlessEq::new(self.cx).eq_expr(len_arg, self.vec_alloc.len_expr) { self.slow_expression = Some(InitializationType::Resize(expr)); - } else if let ExprKind::MethodCall(path, _, _) = len_arg.kind && path.ident.as_str() == "capacity" { + } else if let ExprKind::MethodCall(path, ..) = len_arg.kind && path.ident.as_str() == "capacity" { self.slow_expression = Some(InitializationType::Resize(expr)); } } @@ -233,7 +233,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { /// Returns `true` if give expression is `repeat(0).take(...)` fn is_repeat_take(&self, expr: &Expr<'_>) -> bool { if_chain! { - if let ExprKind::MethodCall(take_path, [recv, len_arg, ..], _) = expr.kind; + if let ExprKind::MethodCall(take_path, recv, [len_arg, ..], _) = expr.kind; if take_path.ident.name == sym!(take); // Check that take is applied to `repeat(0)` if self.is_repeat_zero(recv); @@ -241,7 +241,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> { // Check that len expression is equals to `with_capacity` expression if SpanlessEq::new(self.cx).eq_expr(len_arg, self.vec_alloc.len_expr) { return true; - } else if let ExprKind::MethodCall(path, _, _) = len_arg.kind && path.ident.as_str() == "capacity" { + } else if let ExprKind::MethodCall(path, ..) = len_arg.kind && path.ident.as_str() == "capacity" { return true; } } diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 22eb06b36463..662d399ca538 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -262,7 +262,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { let (method_names, expressions, _) = method_calls(left, 1); if method_names.len() == 1; if expressions.len() == 1; - if expressions[0].len() == 1; + if expressions[0].1.is_empty(); if method_names[0] == sym!(as_bytes); // Check for slicer @@ -270,7 +270,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { then { let mut applicability = Applicability::MachineApplicable; - let string_expression = &expressions[0][0]; + let string_expression = &expressions[0].0; let snippet_app = snippet_with_applicability( cx, @@ -291,12 +291,12 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { } if_chain! { - if let ExprKind::MethodCall(path, args, _) = &e.kind; + if let ExprKind::MethodCall(path, receiver, ..) = &e.kind; if path.ident.name == sym!(as_bytes); - if let ExprKind::Lit(lit) = &args[0].kind; + if let ExprKind::Lit(lit) = &receiver.kind; if let LitKind::Str(lit_content, _) = &lit.node; then { - let callsite = snippet(cx, args[0].span.source_callsite(), r#""foo""#); + let callsite = snippet(cx, receiver.span.source_callsite(), r#""foo""#); let mut applicability = Applicability::MachineApplicable; if callsite.starts_with("include_str!") { span_lint_and_sugg( @@ -305,7 +305,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { e.span, "calling `as_bytes()` on `include_str!(..)`", "consider using `include_bytes!(..)` instead", - snippet_with_applicability(cx, args[0].span, r#""foo""#, &mut applicability).replacen( + snippet_with_applicability(cx, receiver.span, r#""foo""#, &mut applicability).replacen( "include_str", "include_bytes", 1, @@ -314,7 +314,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { ); } else if lit_content.as_str().is_ascii() && lit_content.as_str().len() <= MAX_LENGTH_BYTE_STRING_LIT - && !args[0].span.from_expansion() + && !receiver.span.from_expansion() { span_lint_and_sugg( cx, @@ -324,7 +324,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { "consider using a byte string literal instead", format!( "b{}", - snippet_with_applicability(cx, args[0].span, r#""foo""#, &mut applicability) + snippet_with_applicability(cx, receiver.span, r#""foo""#, &mut applicability) ), applicability, ); @@ -333,9 +333,9 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { } if_chain! { - if let ExprKind::MethodCall(path, [recv], _) = &e.kind; + if let ExprKind::MethodCall(path, recv, [], _) = &e.kind; if path.ident.name == sym!(into_bytes); - if let ExprKind::MethodCall(path, [recv], _) = &recv.kind; + if let ExprKind::MethodCall(path, recv, [], _) = &recv.kind; if matches!(path.ident.name.as_str(), "to_owned" | "to_string"); if let ExprKind::Lit(lit) = &recv.kind; if let LitKind::Str(lit_content, _) = &lit.node; @@ -393,7 +393,7 @@ declare_lint_pass!(StrToString => [STR_TO_STRING]); impl<'tcx> LateLintPass<'tcx> for StrToString { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) { if_chain! { - if let ExprKind::MethodCall(path, [self_arg, ..], _) = &expr.kind; + if let ExprKind::MethodCall(path, self_arg, ..) = &expr.kind; if path.ident.name == sym::to_string; let ty = cx.typeck_results().expr_ty(self_arg); if let ty::Ref(_, ty, ..) = ty.kind(); @@ -443,7 +443,7 @@ declare_lint_pass!(StringToString => [STRING_TO_STRING]); impl<'tcx> LateLintPass<'tcx> for StringToString { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) { if_chain! { - if let ExprKind::MethodCall(path, [self_arg, ..], _) = &expr.kind; + if let ExprKind::MethodCall(path, self_arg, ..) = &expr.kind; if path.ident.name == sym::to_string; let ty = cx.typeck_results().expr_ty(self_arg); if is_type_diagnostic_item(cx, ty, sym::String); @@ -487,11 +487,11 @@ impl<'tcx> LateLintPass<'tcx> for TrimSplitWhitespace { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) { let tyckres = cx.typeck_results(); if_chain! { - if let ExprKind::MethodCall(path, [split_recv], split_ws_span) = expr.kind; + if let ExprKind::MethodCall(path, split_recv, [], split_ws_span) = expr.kind; if path.ident.name == sym!(split_whitespace); if let Some(split_ws_def_id) = tyckres.type_dependent_def_id(expr.hir_id); if cx.tcx.is_diagnostic_item(sym::str_split_whitespace, split_ws_def_id); - if let ExprKind::MethodCall(path, [_trim_recv], trim_span) = split_recv.kind; + if let ExprKind::MethodCall(path, _trim_recv, [], trim_span) = split_recv.kind; if let trim_fn_name @ ("trim" | "trim_start" | "trim_end") = path.ident.name.as_str(); if let Some(trim_def_id) = tyckres.type_dependent_def_id(split_recv.hir_id); if is_one_of_trim_diagnostic_items(cx, trim_def_id); diff --git a/clippy_lints/src/strlen_on_c_strings.rs b/clippy_lints/src/strlen_on_c_strings.rs index 7bc9cf742e65..78403d9fdb7e 100644 --- a/clippy_lints/src/strlen_on_c_strings.rs +++ b/clippy_lints/src/strlen_on_c_strings.rs @@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for StrlenOnCStrings { if let ExprKind::Path(path) = &func.kind; if let Some(did) = cx.qpath_res(path, func.hir_id).opt_def_id(); if match_libc_symbol(cx, did, "strlen"); - if let ExprKind::MethodCall(path, [self_arg], _) = recv.kind; + if let ExprKind::MethodCall(path, self_arg, [], _) = recv.kind; if !recv.span.from_expansion(); if path.ident.name == sym::as_ptr; then { diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs index aa6c01b3a7cd..651201f34ed2 100644 --- a/clippy_lints/src/to_digit_is_some.rs +++ b/clippy_lints/src/to_digit_is_some.rs @@ -39,19 +39,17 @@ declare_lint_pass!(ToDigitIsSome => [TO_DIGIT_IS_SOME]); impl<'tcx> LateLintPass<'tcx> for ToDigitIsSome { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if_chain! { - if let hir::ExprKind::MethodCall(is_some_path, is_some_args, _) = &expr.kind; + if let hir::ExprKind::MethodCall(is_some_path, to_digit_expr, [], _) = &expr.kind; if is_some_path.ident.name.as_str() == "is_some"; - if let [to_digit_expr] = &**is_some_args; then { let match_result = match &to_digit_expr.kind { - hir::ExprKind::MethodCall(to_digits_path, to_digit_args, _) => { + hir::ExprKind::MethodCall(to_digits_path, char_arg, [radix_arg], _) => { if_chain! { - if let [char_arg, radix_arg] = &**to_digit_args; if to_digits_path.ident.name.as_str() == "to_digit"; let char_arg_ty = cx.typeck_results().expr_ty_adjusted(char_arg); if *char_arg_ty.kind() == ty::Char; then { - Some((true, char_arg, radix_arg)) + Some((true, *char_arg, radix_arg)) } else { None } @@ -59,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for ToDigitIsSome { } hir::ExprKind::Call(to_digits_call, to_digit_args) => { if_chain! { - if let [char_arg, radix_arg] = &**to_digit_args; + if let [char_arg, radix_arg] = *to_digit_args; if let hir::ExprKind::Path(to_digits_path) = &to_digits_call.kind; if let to_digits_call_res = cx.qpath_res(to_digits_path, to_digits_call.hir_id); if let Some(to_digits_def_id) = to_digits_call_res.opt_def_id(); diff --git a/clippy_lints/src/uninit_vec.rs b/clippy_lints/src/uninit_vec.rs index 9a41603f2f4c..3f99bd3f3156 100644 --- a/clippy_lints/src/uninit_vec.rs +++ b/clippy_lints/src/uninit_vec.rs @@ -177,7 +177,7 @@ fn extract_init_or_reserve_target<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt }); } }, - ExprKind::MethodCall(path, [self_expr, _], _) if is_reserve(cx, path, self_expr) => { + ExprKind::MethodCall(path, self_expr, [_], _) if is_reserve(cx, path, self_expr) => { return Some(TargetVec { location: VecLocation::Expr(self_expr), init_kind: None, @@ -211,7 +211,7 @@ fn extract_set_len_self<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Opt } }); match expr.kind { - ExprKind::MethodCall(path, [self_expr, _], _) => { + ExprKind::MethodCall(path, self_expr, [_], _) => { let self_type = cx.typeck_results().expr_ty(self_expr).peel_refs(); if is_type_diagnostic_item(cx, self_type, sym::Vec) && path.ident.name.as_str() == "set_len" { Some((self_expr, expr.span)) diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index b0fce91abeb7..851eef7b3324 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -144,8 +144,9 @@ fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Spa impl<'tcx> LateLintPass<'tcx> for UnitReturnExpectingOrd { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - if let ExprKind::MethodCall(_, args, _) = expr.kind { + if let ExprKind::MethodCall(_, receiver, args, _) = expr.kind { let arg_indices = get_args_to_check(cx, expr); + let args = std::iter::once(receiver).chain(args.iter()).collect::>(); for (i, trait_name) in arg_indices { if i < args.len() { match check_arg(cx, &args[i]) { diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index aec028d5c482..35824b03170a 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -128,7 +128,7 @@ fn needs_inferred_result_ty( locals_to_check: &mut Vec, seen_locals: &mut HirIdSet, ) -> bool { - let (id, args) = match e.kind { + let (id, receiver, args) = match e.kind { ExprKind::Call( Expr { kind: ExprKind::Path(ref path), @@ -137,11 +137,11 @@ fn needs_inferred_result_ty( }, args, ) => match cx.qpath_res(path, *hir_id) { - Res::Def(DefKind::AssocFn | DefKind::Fn, id) => (id, args), + Res::Def(DefKind::AssocFn | DefKind::Fn, id) => (id, None, args), _ => return false, }, - ExprKind::MethodCall(_, args, _) => match cx.typeck_results().type_dependent_def_id(e.hir_id) { - Some(id) => (id, args), + ExprKind::MethodCall(_, receiver, args, _) => match cx.typeck_results().type_dependent_def_id(e.hir_id) { + Some(id) => (id, Some(receiver), args), None => return false, }, ExprKind::Path(QPath::Resolved(None, path)) => { @@ -156,6 +156,11 @@ fn needs_inferred_result_ty( }; let sig = cx.tcx.fn_sig(id).skip_binder(); if let ty::Param(output_ty) = *sig.output().kind() { + let args: Vec<&Expr<'_>> = if let Some(receiver) = receiver { + std::iter::once(receiver).chain(args.iter()).collect() + } else { + args.iter().collect() + }; sig.inputs().iter().zip(args).all(|(&ty, arg)| { !ty.is_param(output_ty.index) || each_value_source_needs_inference(cx, arg, locals_to_check, seen_locals) }) diff --git a/clippy_lints/src/unit_types/unit_arg.rs b/clippy_lints/src/unit_types/unit_arg.rs index 16da2f11b81a..7ffb53dcf455 100644 --- a/clippy_lints/src/unit_types/unit_arg.rs +++ b/clippy_lints/src/unit_types/unit_arg.rs @@ -30,26 +30,27 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { } } - match expr.kind { - ExprKind::Call(_, args) | ExprKind::MethodCall(_, args, _) => { - let args_to_recover = args - .iter() - .filter(|arg| { - if cx.typeck_results().expr_ty(arg).is_unit() && !utils::is_unit_literal(arg) { - !matches!( - &arg.kind, - ExprKind::Match(.., MatchSource::TryDesugar) | ExprKind::Path(..) - ) - } else { - false - } - }) - .collect::>(); - if !args_to_recover.is_empty() && !is_from_proc_macro(cx, expr) { - lint_unit_args(cx, expr, &args_to_recover); + let args: Vec<_> = match expr.kind { + ExprKind::Call(_, args) => args.iter().collect(), + ExprKind::MethodCall(_, receiver, args, _) => std::iter::once(receiver).chain(args.iter()).collect(), + _ => return, + }; + + let args_to_recover = args + .into_iter() + .filter(|arg| { + if cx.typeck_results().expr_ty(arg).is_unit() && !utils::is_unit_literal(arg) { + !matches!( + &arg.kind, + ExprKind::Match(.., MatchSource::TryDesugar) | ExprKind::Path(..) + ) + } else { + false } - }, - _ => (), + }) + .collect::>(); + if !args_to_recover.is_empty() && !is_from_proc_macro(cx, expr) { + lint_unit_args(cx, expr, &args_to_recover.as_slice()); } } diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index 323cf83ffcff..b38d71784fcf 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount { check_map_error(cx, res, expr); } }, - hir::ExprKind::MethodCall(path, [ref arg_0, ..], _) => match path.ident.as_str() { + hir::ExprKind::MethodCall(path, arg_0, ..) => match path.ident.as_str() { "expect" | "unwrap" | "unwrap_or" | "unwrap_or_else" => { check_map_error(cx, arg_0, expr); }, @@ -94,9 +94,9 @@ fn try_remove_await<'a>(expr: &'a hir::Expr<'a>) -> Option<&hir::Expr<'a>> { fn check_map_error(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) { let mut call = call; - while let hir::ExprKind::MethodCall(path, args, _) = call.kind { + while let hir::ExprKind::MethodCall(path, receiver, ..) = call.kind { if matches!(path.ident.as_str(), "or" | "or_else" | "ok") { - call = &args[0]; + call = receiver; } else { break; } @@ -110,7 +110,7 @@ fn check_map_error(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr< } fn check_method_call(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>, is_await: bool) { - if let hir::ExprKind::MethodCall(path, _, _) = call.kind { + if let hir::ExprKind::MethodCall(path, ..) = call.kind { let symbol = path.ident.as_str(); let read_trait = if is_await { match_trait_method(cx, call, &paths::FUTURES_IO_ASYNCREADEXT) diff --git a/clippy_lints/src/unused_peekable.rs b/clippy_lints/src/unused_peekable.rs index ac73173697e8..7fbfecf96ec3 100644 --- a/clippy_lints/src/unused_peekable.rs +++ b/clippy_lints/src/unused_peekable.rs @@ -149,7 +149,8 @@ impl<'tcx> Visitor<'_> for PeekableVisitor<'_, 'tcx> { ident: method_name_ident, .. }, - [self_arg, remaining_args @ ..], + self_arg, + [remaining_args @ ..], _, ) => { let method_name = method_name_ident.name.as_str(); diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index d3f9e5abfd73..9092156be150 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -154,13 +154,13 @@ fn collect_unwrap_info<'tcx>( return collect_unwrap_info(cx, if_expr, expr, branch, !invert, false); } else { if_chain! { - if let ExprKind::MethodCall(method_name, args, _) = &expr.kind; - if let Some(local_id) = path_to_local(&args[0]); - let ty = cx.typeck_results().expr_ty(&args[0]); + if let ExprKind::MethodCall(method_name, receiver, args, _) = &expr.kind; + if let Some(local_id) = path_to_local(receiver); + let ty = cx.typeck_results().expr_ty(receiver); let name = method_name.ident.as_str(); if is_relevant_option_call(cx, ty, name) || is_relevant_result_call(cx, ty, name); then { - assert!(args.len() == 1); + assert!(args.len() == 0); let unwrappable = match name { "is_some" | "is_ok" => true, "is_err" | "is_none" => false, @@ -231,7 +231,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> { } else { // find `unwrap[_err]()` calls: if_chain! { - if let ExprKind::MethodCall(method_name, [self_arg, ..], _) = expr.kind; + if let ExprKind::MethodCall(method_name, self_arg, ..) = expr.kind; if let Some(id) = path_to_local(self_arg); if [sym::unwrap, sym::expect, sym!(unwrap_err)].contains(&method_name.ident.name); let call_to_unwrap = [sym::unwrap, sym::expect].contains(&method_name.ident.name); diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs index b32be238cd55..b3ca15f7648b 100644 --- a/clippy_lints/src/unwrap_in_result.rs +++ b/clippy_lints/src/unwrap_in_result.rs @@ -83,7 +83,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindExpectUnwrap<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { // check for `expect` if let Some(arglists) = method_chain_args(expr, &["expect"]) { - let receiver_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); + let receiver_ty = self.typeck_results.expr_ty(&arglists[0].0).peel_refs(); if is_type_diagnostic_item(self.lcx, receiver_ty, sym::Option) || is_type_diagnostic_item(self.lcx, receiver_ty, sym::Result) { @@ -93,7 +93,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindExpectUnwrap<'a, 'tcx> { // check for `unwrap` if let Some(arglists) = method_chain_args(expr, &["unwrap"]) { - let receiver_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs(); + let receiver_ty = self.typeck_results.expr_ty(&arglists[0].0).peel_refs(); if is_type_diagnostic_item(self.lcx, receiver_ty, sym::Option) || is_type_diagnostic_item(self.lcx, receiver_ty, sym::Result) { diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index b6738e2891d3..f1b6463ad0f7 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { } }, - ExprKind::MethodCall(name, .., [recv, ..], _) => { + ExprKind::MethodCall(name, recv, ..) => { if is_trait_method(cx, e, sym::Into) && name.ident.as_str() == "into" { let a = cx.typeck_results().expr_ty(e); let b = cx.typeck_results().expr_ty(recv); diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 3ffcaa90af3e..fec4ee93e7bc 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -402,10 +402,11 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { self.expr(func); self.slice(args, |e| self.expr(e)); }, - ExprKind::MethodCall(method_name, args, _) => { - bind!(self, method_name, args); - kind!("MethodCall({method_name}, {args}, _)"); + ExprKind::MethodCall(method_name, receiver, args, _) => { + bind!(self, method_name, receiver, args); + kind!("MethodCall({method_name}, {receiver}, {args}, _)"); self.ident(field!(method_name.ident)); + self.expr(receiver); self.slice(args, |e| self.expr(e)); }, ExprKind::Tup(elements) => { diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index eb34085a2abf..ae1c11ef83c3 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -687,7 +687,7 @@ impl<'tcx> LateLintPass<'tcx> for OuterExpnDataPass { if let ["expn_data", "outer_expn"] = method_names.as_slice(); let args = arg_lists[1]; if args.len() == 1; - let self_arg = &args[0]; + let self_arg = &args.0; let self_ty = cx.typeck_results().expr_ty(self_arg).peel_refs(); if match_type(cx, self_ty, &paths::SYNTAX_CONTEXT); then { diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs index 35db45e2b0c9..542c6a37d567 100644 --- a/clippy_lints/src/vec_init_then_push.rs +++ b/clippy_lints/src/vec_init_then_push.rs @@ -100,7 +100,7 @@ impl VecPushSearcher { || get_parent_expr(cx, last_place) .map_or(false, |e| matches!(e.kind, ExprKind::AddrOf(_, Mutability::Mut, _))); }, - ExprKind::MethodCall(_, [recv, ..], _) + ExprKind::MethodCall(_, recv, ..) if recv.hir_id == e.hir_id && adjusted_mut == Mutability::Mut && !adjusted_ty.peel_refs().is_slice() => @@ -201,7 +201,7 @@ impl<'tcx> LateLintPass<'tcx> for VecInitThenPush { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { if let Some(searcher) = self.searcher.take() { if let StmtKind::Expr(expr) | StmtKind::Semi(expr) = stmt.kind - && let ExprKind::MethodCall(name, [self_arg, _], _) = expr.kind + && let ExprKind::MethodCall(name, self_arg, [_], _) = expr.kind && path_to_local_id(self_arg, searcher.local_id) && name.ident.as_str() == "push" { diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index 8335ffae81eb..e8d2d579f097 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -118,9 +118,9 @@ fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) { ExprKind::Unary(UnOp::Neg, e) => (Pat::Str("-"), expr_search_pat(tcx, e).1), ExprKind::Lit(ref lit) => lit_search_pat(&lit.node), ExprKind::Array(_) | ExprKind::Repeat(..) => (Pat::Str("["), Pat::Str("]")), - ExprKind::Call(e, []) | ExprKind::MethodCall(_, [e], _) => (expr_search_pat(tcx, e).0, Pat::Str("(")), + ExprKind::Call(e, []) | ExprKind::MethodCall(_, e, [], _) => (expr_search_pat(tcx, e).0, Pat::Str("(")), ExprKind::Call(first, [.., last]) - | ExprKind::MethodCall(_, [first, .., last], _) + | ExprKind::MethodCall(_, first, [.., last], _) | ExprKind::Binary(_, first, last) | ExprKind::Tup([first, .., last]) | ExprKind::Assign(first, last, _) diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs index 7f55db3b31f7..ad95369b9ef7 100644 --- a/clippy_utils/src/diagnostics.rs +++ b/clippy_utils/src/diagnostics.rs @@ -155,13 +155,7 @@ where }); } -pub fn span_lint_hir( - cx: &LateContext<'_>, - lint: &'static Lint, - hir_id: HirId, - sp: Span, - msg: &str, -) { +pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) { cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| { let mut diag = diag.build(msg); docs_link(&mut diag, lint); diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 730724b95b96..124a00d81784 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -45,12 +45,7 @@ impl ops::BitOrAssign for EagernessSuggestion { } /// Determine the eagerness of the given function call. -fn fn_eagerness<'tcx>( - cx: &LateContext<'tcx>, - fn_id: DefId, - name: Symbol, - args: &'tcx [Expr<'_>], -) -> EagernessSuggestion { +fn fn_eagerness<'tcx>(cx: &LateContext<'tcx>, fn_id: DefId, name: Symbol, have_one_arg: bool) -> EagernessSuggestion { use EagernessSuggestion::{Eager, Lazy, NoChange}; let name = name.as_str(); @@ -59,7 +54,7 @@ fn fn_eagerness<'tcx>( None => return Lazy, }; - if (name.starts_with("as_") || name == "len" || name == "is_empty") && args.len() == 1 { + if (name.starts_with("as_") || name == "len" || name == "is_empty") && have_one_arg { if matches!( cx.tcx.crate_name(fn_id.krate), sym::std | sym::core | sym::alloc | sym::proc_macro @@ -127,10 +122,11 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS }, Res::Def(_, id) => match path { QPath::Resolved(_, p) => { - self.eagerness |= fn_eagerness(self.cx, id, p.segments.last().unwrap().ident.name, args); + self.eagerness |= + fn_eagerness(self.cx, id, p.segments.last().unwrap().ident.name, !args.is_empty()); }, QPath::TypeRelative(_, name) => { - self.eagerness |= fn_eagerness(self.cx, id, name.ident.name, args); + self.eagerness |= fn_eagerness(self.cx, id, name.ident.name, !args.is_empty()); }, QPath::LangItem(..) => self.eagerness = Lazy, }, @@ -141,12 +137,12 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS self.eagerness |= NoChange; return; }, - ExprKind::MethodCall(name, args, _) => { + ExprKind::MethodCall(name, ..) => { self.eagerness |= self .cx .typeck_results() .type_dependent_def_id(e.hir_id) - .map_or(Lazy, |id| fn_eagerness(self.cx, id, name.ident.name, args)); + .map_or(Lazy, |id| fn_eagerness(self.cx, id, name.ident.name, true)); }, ExprKind::Index(_, e) => { let ty = self.cx.typeck_results().expr_ty_adjusted(e); diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 1834e2a2de87..6cb6544df4bc 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -282,8 +282,14 @@ impl HirEqInterExpr<'_, '_, '_> { && self.eq_expr(l.body, r.body) }) }, - (&ExprKind::MethodCall(l_path, l_args, _), &ExprKind::MethodCall(r_path, r_args, _)) => { - self.inner.allow_side_effects && self.eq_path_segment(l_path, r_path) && self.eq_exprs(l_args, r_args) + ( + &ExprKind::MethodCall(l_path, l_receiver, l_args, _), + &ExprKind::MethodCall(r_path, r_receiver, r_args, _), + ) => { + self.inner.allow_side_effects + && self.eq_path_segment(l_path, r_path) + && self.eq_expr(l_receiver, r_receiver) + && self.eq_exprs(l_args, r_args) }, (&ExprKind::Repeat(le, ll), &ExprKind::Repeat(re, rl)) => { self.eq_expr(le, re) && self.eq_array_length(ll, rl) @@ -743,8 +749,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { s.hash(&mut self.s); }, - ExprKind::MethodCall(path, args, ref _fn_span) => { + ExprKind::MethodCall(path, receiver, args, ref _fn_span) => { self.hash_name(path.ident.name); + self.hash_expr(receiver); self.hash_exprs(args); }, ExprKind::ConstBlock(ref l_id) => { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index f3a08e98688e..ed1f8af989fe 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1036,21 +1036,21 @@ pub fn can_move_expr_to_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<' pub fn method_calls<'tcx>( expr: &'tcx Expr<'tcx>, max_depth: usize, -) -> (Vec, Vec<&'tcx [Expr<'tcx>]>, Vec) { +) -> (Vec, Vec<(&'tcx Expr<'tcx>, &'tcx [Expr<'tcx>])>, Vec) { let mut method_names = Vec::with_capacity(max_depth); let mut arg_lists = Vec::with_capacity(max_depth); let mut spans = Vec::with_capacity(max_depth); let mut current = expr; for _ in 0..max_depth { - if let ExprKind::MethodCall(path, args, _) = ¤t.kind { - if args.iter().any(|e| e.span.from_expansion()) { + if let ExprKind::MethodCall(path, receiver, args, _) = ¤t.kind { + if receiver.span.from_expansion() || args.iter().any(|e| e.span.from_expansion()) { break; } method_names.push(path.ident.name); - arg_lists.push(&**args); + arg_lists.push((*receiver, &**args)); spans.push(path.ident.span); - current = &args[0]; + current = receiver; } else { break; } @@ -1065,18 +1065,18 @@ pub fn method_calls<'tcx>( /// `method_chain_args(expr, &["bar", "baz"])` will return a `Vec` /// containing the `Expr`s for /// `.bar()` and `.baz()` -pub fn method_chain_args<'a>(expr: &'a Expr<'_>, methods: &[&str]) -> Option]>> { +pub fn method_chain_args<'a>(expr: &'a Expr<'_>, methods: &[&str]) -> Option, &'a [Expr<'a>])>> { let mut current = expr; let mut matched = Vec::with_capacity(methods.len()); for method_name in methods.iter().rev() { // method chains are stored last -> first - if let ExprKind::MethodCall(path, args, _) = current.kind { + if let ExprKind::MethodCall(path, receiver, args, _) = current.kind { if path.ident.name.as_str() == *method_name { - if args.iter().any(|e| e.span.from_expansion()) { + if receiver.span.from_expansion() || args.iter().any(|e| e.span.from_expansion()) { return None; } - matched.push(args); // build up `matched` backwards - current = &args[0]; // go to parent expression + matched.push((receiver, args)); // build up `matched` backwards + current = receiver; // go to parent expression } else { return None; } @@ -1239,8 +1239,10 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>( ty_is_fn_once_param(cx.tcx, ty.skip_binder(), predicates).then_some(()) }) }, - ExprKind::MethodCall(_, args, _) => { - let i = args.iter().position(|arg| arg.hir_id == id)?; + ExprKind::MethodCall(_, receiver, args, _) => { + let i = std::iter::once(receiver) + .chain(args.iter()) + .position(|arg| arg.hir_id == id)?; let id = cx.typeck_results().type_dependent_def_id(e.hir_id)?; let ty = cx.tcx.fn_sig(id).skip_binder().inputs()[i]; ty_is_fn_once_param(cx.tcx, ty, cx.tcx.param_env(id).caller_bounds()).then_some(()) diff --git a/clippy_utils/src/ptr.rs b/clippy_utils/src/ptr.rs index 649b7b9940af..0226f74906b5 100644 --- a/clippy_utils/src/ptr.rs +++ b/clippy_utils/src/ptr.rs @@ -36,7 +36,7 @@ fn extract_clone_suggestions<'tcx>( if abort { return false; } - if let ExprKind::MethodCall(seg, [recv], _) = expr.kind { + if let ExprKind::MethodCall(seg, recv, [], _) = expr.kind { if path_to_local_id(recv, id) { if seg.ident.name.as_str() == "capacity" { abort = true; diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 081c98e2f3ce..cca71bbf76e2 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -373,12 +373,14 @@ fn binop_to_string(op: AssocOp, lhs: &str, rhs: &str) -> String { | AssocOp::LessEqual | AssocOp::NotEqual | AssocOp::Greater - | AssocOp::GreaterEqual => format!( - "{} {} {}", - lhs, - op.to_ast_binop().expect("Those are AST ops").to_string(), - rhs - ), + | AssocOp::GreaterEqual => { + format!( + "{} {} {}", + lhs, + op.to_ast_binop().expect("Those are AST ops").to_string(), + rhs + ) + }, AssocOp::Assign => format!("{} = {}", lhs, rhs), AssocOp::AssignOp(op) => { format!("{} {}= {}", lhs, token_kind_to_string(&token::BinOp(op)), rhs) @@ -868,15 +870,15 @@ impl<'tcx> DerefDelegate<'_, 'tcx> { /// indicates whether the function from `parent_expr` takes its args by double reference fn func_takes_arg_by_double_ref(&self, parent_expr: &'tcx hir::Expr<'_>, cmt_hir_id: HirId) -> bool { let ty = match parent_expr.kind { - ExprKind::MethodCall(_, call_args, _) => { + ExprKind::MethodCall(_, receiver, call_args, _) => { if let Some(sig) = self .cx .typeck_results() .type_dependent_def_id(parent_expr.hir_id) .map(|did| self.cx.tcx.fn_sig(did).skip_binder()) { - call_args - .iter() + std::iter::once(receiver) + .chain(call_args.iter()) .position(|arg| arg.hir_id == cmt_hir_id) .map(|i| sig.inputs()[i]) } else { @@ -933,14 +935,14 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> { match &parent_expr.kind { // given expression is the self argument and will be handled completely by the compiler // i.e.: `|x| x.is_something()` - ExprKind::MethodCall(_, [self_expr, ..], _) if self_expr.hir_id == cmt.hir_id => { + ExprKind::MethodCall(_, self_expr, ..) if self_expr.hir_id == cmt.hir_id => { let _ = write!(self.suggestion_start, "{}{}", start_snip, ident_str_with_proj); self.next_pos = span.hi(); return; }, // item is used in a call // i.e.: `Call`: `|x| please(x)` or `MethodCall`: `|x| [1, 2, 3].contains(x)` - ExprKind::Call(_, [call_args @ ..]) | ExprKind::MethodCall(_, [_, call_args @ ..], _) => { + ExprKind::Call(_, [call_args @ ..]) | ExprKind::MethodCall(_, _, [call_args @ ..], _) => { let expr = self.cx.tcx.hir().expect_expr(cmt.hir_id); let arg_ty_kind = self.cx.typeck_results().expr_ty(expr).kind(); diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index bae8ad9f5659..6a62002a4d12 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -620,7 +620,13 @@ pub fn for_each_unconsumed_temporary<'tcx, B>( helper(typeck, true, arg, f)?; } }, - ExprKind::MethodCall(_, args, _) | ExprKind::Tup(args) | ExprKind::Array(args) => { + ExprKind::MethodCall(_, receiver, args, _) => { + helper(typeck, true, receiver, f)?; + for arg in args { + helper(typeck, true, arg, f)?; + } + }, + ExprKind::Tup(args) | ExprKind::Array(args) => { for arg in args { helper(typeck, true, arg, f)?; } diff --git a/tests/ui/author/struct.stdout b/tests/ui/author/struct.stdout index 5e78b7c9de7e..b5bbc9e213c6 100644 --- a/tests/ui/author/struct.stdout +++ b/tests/ui/author/struct.stdout @@ -53,11 +53,11 @@ if_chain! { } } if_chain! { - if let ExprKind::MethodCall(method_name, args, _) = expr.kind; + if let ExprKind::MethodCall(method_name, receiver, args, _) = expr.kind; if method_name.ident.as_str() == "test"; - if args.len() == 1; - if let ExprKind::Path(ref qpath) = args[0].kind; + if let ExprKind::Path(ref qpath) = receiver.kind; if match_qpath(qpath, &["test_method_call"]); + if args.is_empty(); then { // report your lint here } From 79266c60c004dbdc58224f05e42e6366b697d9e0 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Fri, 2 Sep 2022 22:48:14 +0900 Subject: [PATCH 0596/1222] refactor: remove unnecessary variables --- clippy_lints/src/dereference.rs | 94 ++++++++++---------- clippy_lints/src/infinite_iter.rs | 10 +-- clippy_lints/src/len_zero.rs | 7 +- clippy_lints/src/methods/clone_on_copy.rs | 5 +- clippy_lints/src/methods/clone_on_ref_ptr.rs | 5 +- clippy_lints/src/methods/mod.rs | 10 +-- clippy_lints/src/minmax.rs | 10 +-- clippy_lints/src/unused_peekable.rs | 2 +- 8 files changed, 67 insertions(+), 76 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index fd6ed36cb192..6ee9e2e9754c 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -798,57 +798,55 @@ fn walk_parents<'tcx>( }), ExprKind::MethodCall(_, receiver, args, _) => { let id = cx.typeck_results().type_dependent_def_id(parent.hir_id).unwrap(); - std::iter::once(receiver) - .chain(args.iter()) - .position(|arg| arg.hir_id == child_id) - .map(|i| { - if i == 0 { - // Check for calls to trait methods where the trait is implemented on a reference. - // Two cases need to be handled: - // * `self` methods on `&T` will never have auto-borrow - // * `&self` methods on `&T` can have auto-borrow, but `&self` methods on `T` will take - // priority. - if e.hir_id != child_id { - Position::ReborrowStable(precedence) - } else if let Some(trait_id) = cx.tcx.trait_of_item(id) - && let arg_ty = cx.tcx.erase_regions(cx.typeck_results().expr_ty_adjusted(e)) - && let ty::Ref(_, sub_ty, _) = *arg_ty.kind() - && let subs = match cx - .typeck_results() - .node_substs_opt(parent.hir_id) - .and_then(|subs| subs.get(1..)) - { - Some(subs) => cx.tcx.mk_substs(subs.iter().copied()), - None => cx.tcx.mk_substs(std::iter::empty::>()), - } && let impl_ty = if cx.tcx.fn_sig(id).skip_binder().inputs()[0].is_ref() { - // Trait methods taking `&self` - sub_ty - } else { - // Trait methods taking `self` - arg_ty - } && impl_ty.is_ref() - && cx.tcx.infer_ctxt().enter(|infcx| - infcx - .type_implements_trait(trait_id, impl_ty, subs, cx.param_env) - .must_apply_modulo_regions() - ) + if receiver.hir_id == child_id { + // Check for calls to trait methods where the trait is implemented on a reference. + // Two cases need to be handled: + // * `self` methods on `&T` will never have auto-borrow + // * `&self` methods on `&T` can have auto-borrow, but `&self` methods on `T` will take + // priority. + if e.hir_id != child_id { + return Some(Position::ReborrowStable(precedence)) + } else if let Some(trait_id) = cx.tcx.trait_of_item(id) + && let arg_ty = cx.tcx.erase_regions(cx.typeck_results().expr_ty_adjusted(e)) + && let ty::Ref(_, sub_ty, _) = *arg_ty.kind() + && let subs = match cx + .typeck_results() + .node_substs_opt(parent.hir_id) + .and_then(|subs| subs.get(1..)) { - Position::MethodReceiverRefImpl + Some(subs) => cx.tcx.mk_substs(subs.iter().copied()), + None => cx.tcx.mk_substs(std::iter::empty::>()), + } && let impl_ty = if cx.tcx.fn_sig(id).skip_binder().inputs()[0].is_ref() { + // Trait methods taking `&self` + sub_ty } else { - Position::MethodReceiver - } + // Trait methods taking `self` + arg_ty + } && impl_ty.is_ref() + && cx.tcx.infer_ctxt().enter(|infcx| + infcx + .type_implements_trait(trait_id, impl_ty, subs, cx.param_env) + .must_apply_modulo_regions() + ) + { + return Some(Position::MethodReceiverRefImpl) + } else { + return Some(Position::MethodReceiver) + } + } + args.iter() + .position(|arg| arg.hir_id == child_id) + .map(|i| { + let ty = cx.tcx.fn_sig(id).skip_binder().inputs()[i + 1]; + if let ty::Param(param_ty) = ty.kind() { + needless_borrow_impl_arg_position(cx, parent, i + 1, *param_ty, e, precedence, msrv) } else { - let ty = cx.tcx.fn_sig(id).skip_binder().inputs()[i]; - if let ty::Param(param_ty) = ty.kind() { - needless_borrow_impl_arg_position(cx, parent, i, *param_ty, e, precedence, msrv) - } else { - ty_auto_deref_stability( - cx, - cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).input(i)), - precedence, - ) - .position_for_arg() - } + ty_auto_deref_stability( + cx, + cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).input(i + 1)), + precedence, + ) + .position_for_arg() } }) }, diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index fca3cb46a2e9..d55a8e1ead17 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -59,7 +59,7 @@ impl<'tcx> LateLintPass<'tcx> for InfiniteIter { MaybeInfinite => (MAYBE_INFINITE_ITER, "possible infinite iteration detected"), Finite => { return; - }, + } }; span_lint(cx, lint, expr.span, msg); } @@ -229,11 +229,9 @@ fn complete_infinite_iter(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { return MaybeInfinite.and(is_infinite(cx, receiver)); } } - if method.ident.name == sym!(last) { - let not_double_ended = cx - .tcx - .get_diagnostic_item(sym::DoubleEndedIterator) - .map_or(false, |id| { + if method.ident.name == sym!(last) && args.is_empty() { + let not_double_ended = + cx.tcx.get_diagnostic_item(sym::DoubleEndedIterator).map_or(false, |id| { !implements_trait(cx, cx.typeck_results().expr_ty(receiver), id, &[]) }); if not_double_ended { diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 25f366bfe6a8..3cbdaff407b0 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -370,7 +370,7 @@ fn check_for_is_empty<'tcx>( } fn check_cmp(cx: &LateContext<'_>, span: Span, method: &Expr<'_>, lit: &Expr<'_>, op: &str, compare_to: u32) { - if let (&ExprKind::MethodCall(method_path, receiver, ..), &ExprKind::Lit(ref lit)) = (&method.kind, &lit.kind) { + if let (&ExprKind::MethodCall(method_path, receiver, args, _), &ExprKind::Lit(ref lit)) = (&method.kind, &lit.kind) { // check if we are in an is_empty() method if let Some(name) = get_item_name(cx, method) { if name.as_str() == "is_empty" { @@ -378,7 +378,7 @@ fn check_cmp(cx: &LateContext<'_>, span: Span, method: &Expr<'_>, lit: &Expr<'_> } } - check_len(cx, span, method_path.ident.name, receiver, &lit.node, op, compare_to); + check_len(cx, span, method_path.ident.name, receiver, args, &lit.node, op, compare_to); } else { check_empty_expr(cx, span, method, lit, op); } @@ -389,6 +389,7 @@ fn check_len( span: Span, method_name: Symbol, receiver: &Expr<'_>, + args: &[Expr<'_>], lit: &LitKind, op: &str, compare_to: u32, @@ -399,7 +400,7 @@ fn check_len( return; } - if method_name == sym::len && has_is_empty(cx, receiver) { + if method_name == sym::len && args.is_empty() && has_is_empty(cx, receiver) { let mut applicability = Applicability::MachineApplicable; span_lint_and_sugg( cx, diff --git a/clippy_lints/src/methods/clone_on_copy.rs b/clippy_lints/src/methods/clone_on_copy.rs index 9ae6297ec2f6..25a9e6dafea1 100644 --- a/clippy_lints/src/methods/clone_on_copy.rs +++ b/clippy_lints/src/methods/clone_on_copy.rs @@ -21,10 +21,7 @@ pub(super) fn check( receiver: &Expr<'_>, args: &[Expr<'_>], ) { - let arg = match args { - [] if method_name == sym::clone => receiver, - _ => return, - }; + let arg = if method_name == sym::clone && args.is_empty() { receiver } else { return }; if cx .typeck_results() .type_dependent_def_id(expr.hir_id) diff --git a/clippy_lints/src/methods/clone_on_ref_ptr.rs b/clippy_lints/src/methods/clone_on_ref_ptr.rs index 7098d564cfc8..f82ca8912006 100644 --- a/clippy_lints/src/methods/clone_on_ref_ptr.rs +++ b/clippy_lints/src/methods/clone_on_ref_ptr.rs @@ -20,8 +20,7 @@ pub(super) fn check( if !(args.is_empty() && method_name == sym::clone) { return; } - let arg = receiver; - let obj_ty = cx.typeck_results().expr_ty(arg).peel_refs(); + let obj_ty = cx.typeck_results().expr_ty(receiver).peel_refs(); if let ty::Adt(_, subst) = obj_ty.kind() { let caller_type = if is_type_diagnostic_item(cx, obj_ty, sym::Rc) { @@ -34,7 +33,7 @@ pub(super) fn check( return; }; - let snippet = snippet_with_macro_callsite(cx, arg.span, ".."); + let snippet = snippet_with_macro_callsite(cx, receiver.span, ".."); span_lint_and_sugg( cx, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 16fdd36c0260..fc9ba15d82a4 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3381,7 +3381,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { impl Methods { #[allow(clippy::too_many_lines)] fn check_methods<'tcx>(&self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let Some((name, recv, [args @ ..], span)) = method_call(expr) { + if let Some((name, recv, args, span)) = method_call(expr) { match (name, args) { ("add" | "offset" | "sub" | "wrapping_offset" | "wrapping_add" | "wrapping_sub", [_arg]) => { zst_offset::check(cx, expr, recv); @@ -3485,7 +3485,7 @@ impl Methods { } }, ("last", []) | ("skip", [_]) => { - if let Some((name2, recv2, [args2 @ ..], _span2)) = method_call(recv) { + if let Some((name2, recv2, args2, _span2)) = method_call(recv) { if let ("cloned", []) = (name2, args2) { iter_overeager_cloned::check(cx, expr, recv, recv2, false, false); } @@ -3500,7 +3500,7 @@ impl Methods { } else { map_err_ignore::check(cx, expr, m_arg); } - if let Some((name, recv2, [args @ ..], span2)) = method_call(recv) { + if let Some((name, recv2, args, span2)) = method_call(recv) { match (name, args) { ("as_mut", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, true, self.msrv), ("as_ref", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, false, self.msrv), @@ -3520,7 +3520,7 @@ impl Methods { manual_ok_or::check(cx, expr, recv, def, map); }, ("next", []) => { - if let Some((name2, recv2, [args2 @ ..], _)) = method_call(recv) { + if let Some((name2, recv2, args2, _)) = method_call(recv) { match (name2, args2) { ("cloned", []) => iter_overeager_cloned::check(cx, expr, recv, recv2, false, false), ("filter", [arg]) => filter_next::check(cx, expr, recv2, arg), @@ -3593,7 +3593,7 @@ impl Methods { }, ("step_by", [arg]) => iterator_step_by_zero::check(cx, expr, arg), ("take", [_arg]) => { - if let Some((name2, recv2, [args2 @ ..], _span2)) = method_call(recv) { + if let Some((name2, recv2, args2, _span2)) = method_call(recv) { if let ("cloned", []) = (name2, args2) { iter_overeager_cloned::check(cx, expr, recv, recv2, false, false); } diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index c618f6b5d926..44b21e7b080d 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -109,14 +109,12 @@ fn fetch_const<'a>( args: &'a [Expr<'a>], m: MinMax, ) -> Option<(MinMax, Constant, &'a Expr<'a>)> { - if (receiver.is_some() && args.len() != 1) || (receiver.is_none() && args.len() != 2) { + let mut args = receiver.into_iter().chain(args.into_iter()); + let arg0 = args.next()?; + let arg1 = args.next()?; + if args.next().is_some() { return None; } - let (arg0, arg1) = if let Some(receiver) = receiver { - (receiver, &args[0]) - } else { - (&args[0], &args[1]) - }; constant_simple(cx, cx.typeck_results(), arg0).map_or_else( || constant_simple(cx, cx.typeck_results(), arg1).map(|c| (m, c, arg0)), |c| { diff --git a/clippy_lints/src/unused_peekable.rs b/clippy_lints/src/unused_peekable.rs index 7fbfecf96ec3..cfc181e435b9 100644 --- a/clippy_lints/src/unused_peekable.rs +++ b/clippy_lints/src/unused_peekable.rs @@ -150,7 +150,7 @@ impl<'tcx> Visitor<'_> for PeekableVisitor<'_, 'tcx> { .. }, self_arg, - [remaining_args @ ..], + remaining_args, _, ) => { let method_name = method_name_ident.name.as_str(); From 18ac5884d4e68c35a93413dbf44b849e85e7c007 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Mon, 5 Sep 2022 14:26:00 +0900 Subject: [PATCH 0597/1222] use `propagate_through_exprs` instead of `propagate_through_expr` fix `ExprKind` static_assert_size fix hir-stats --- clippy_lints/src/eta_reduction.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 1c0a93c71fde..1342a4697b99 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -206,12 +206,8 @@ fn check_inputs( _ => false, } }; - if let Some(receiver) = receiver { - std::iter::zip(params, std::iter::once(receiver).chain(call_args.iter())) - .all(|(param, arg)| check_inputs(param, arg)) - } else { - std::iter::zip(params, call_args).all(|(param, arg)| check_inputs(param, arg)) - } + std::iter::zip(params, receiver.into_iter().chain(call_args.iter())) + .all(|(param, arg)| check_inputs(param, arg)) } fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure_ty: Ty<'tcx>, call_ty: Ty<'tcx>) -> bool { From bdd799422f0780e705aba278ed1a237795d14e0d Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 30 Jun 2022 08:16:05 +0000 Subject: [PATCH 0598/1222] Lower the assume intrinsic to a MIR statement --- clippy_utils/src/qualify_min_const_fn.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 74c222bbcbeb..1c12da7f7416 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -211,6 +211,9 @@ fn check_statement<'tcx>( StatementKind::SetDiscriminant { place, .. } | StatementKind::Deinit(place) => { check_place(tcx, **place, span, body) }, + StatementKind::Assume(box op) => { + check_operand(tcx, op, span, body) + }, StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping { dst, src, count }) => { check_operand(tcx, dst, span, body)?; From d95855ceb78414b59c3accf12396f9ad3957d6c5 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 12 Jul 2022 10:05:00 +0000 Subject: [PATCH 0599/1222] Generalize the Assume intrinsic statement to a general Intrinsic statement --- clippy_utils/src/qualify_min_const_fn.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 1c12da7f7416..b22a9c817460 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -7,7 +7,7 @@ use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_middle::mir::{ Body, CastKind, NullOp, Operand, Place, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, - TerminatorKind, + TerminatorKind, NonDivergingIntrinsic }; use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::{self, adjustment::PointerCast, Ty, TyCtxt}; @@ -211,15 +211,19 @@ fn check_statement<'tcx>( StatementKind::SetDiscriminant { place, .. } | StatementKind::Deinit(place) => { check_place(tcx, **place, span, body) }, - StatementKind::Assume(box op) => { + + StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(op)) => { check_operand(tcx, op, span, body) }, - StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping { dst, src, count }) => { + StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping( + rustc_middle::mir::CopyNonOverlapping { dst, src, count }, + )) => { check_operand(tcx, dst, span, body)?; check_operand(tcx, src, span, body)?; check_operand(tcx, count, span, body) }, + // These are all NOPs StatementKind::StorageLive(_) | StatementKind::StorageDead(_) From e17c6d7648ba7b5824c34c772cd65b258e2e6626 Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Tue, 6 Sep 2022 14:23:03 -0400 Subject: [PATCH 0600/1222] Allow lint passes to be bound by `TyCtxt` --- clippy_dev/src/new_lint.rs | 6 +- clippy_lints/src/lib.rs | 414 ++++++++++++++++++------------------- 2 files changed, 211 insertions(+), 209 deletions(-) diff --git a/clippy_dev/src/new_lint.rs b/clippy_dev/src/new_lint.rs index be05e67d724d..331b76484b8a 100644 --- a/clippy_dev/src/new_lint.rs +++ b/clippy_dev/src/new_lint.rs @@ -120,15 +120,17 @@ fn add_lint(lint: &LintData<'_>, enable_msrv: bool) -> io::Result<()> { let new_lint = if enable_msrv { format!( - "store.register_{lint_pass}_pass(move || Box::new({module_name}::{camel_name}::new(msrv)));\n ", + "store.register_{lint_pass}_pass(move |{ctor_arg}| Box::new({module_name}::{camel_name}::new(msrv)));\n ", lint_pass = lint.pass, + ctor_arg = if lint.pass == "late" { "_" } else { "" }, module_name = lint.name, camel_name = to_camel_case(lint.name), ) } else { format!( - "store.register_{lint_pass}_pass(|| Box::new({module_name}::{camel_name}));\n ", + "store.register_{lint_pass}_pass(|{ctor_arg}| Box::new({module_name}::{camel_name}));\n ", lint_pass = lint.pass, + ctor_arg = if lint.pass == "late" { "_" } else { "" }, module_name = lint.name, camel_name = to_camel_case(lint.name), ) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index dfdaf90f09f4..c70aa79ac8dc 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -523,7 +523,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: #[cfg(feature = "internal")] { if std::env::var("ENABLE_METADATA_COLLECTION").eq(&Ok("1".to_string())) { - store.register_late_pass(|| Box::new(utils::internal_lints::metadata_collector::MetadataCollector::new())); + store.register_late_pass(|_| Box::new(utils::internal_lints::metadata_collector::MetadataCollector::new())); return; } } @@ -533,69 +533,69 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: { store.register_early_pass(|| Box::new(utils::internal_lints::ClippyLintsInternal)); store.register_early_pass(|| Box::new(utils::internal_lints::ProduceIce)); - store.register_late_pass(|| Box::new(utils::internal_lints::CollapsibleCalls)); - store.register_late_pass(|| Box::new(utils::internal_lints::CompilerLintFunctions::new())); - store.register_late_pass(|| Box::new(utils::internal_lints::IfChainStyle)); - store.register_late_pass(|| Box::new(utils::internal_lints::InvalidPaths)); - store.register_late_pass(|| Box::new(utils::internal_lints::InterningDefinedSymbol::default())); - store.register_late_pass(|| Box::new(utils::internal_lints::LintWithoutLintPass::default())); - store.register_late_pass(|| Box::new(utils::internal_lints::MatchTypeOnDiagItem)); - store.register_late_pass(|| Box::new(utils::internal_lints::OuterExpnDataPass)); - store.register_late_pass(|| Box::new(utils::internal_lints::MsrvAttrImpl)); + store.register_late_pass(|_| Box::new(utils::internal_lints::CollapsibleCalls)); + store.register_late_pass(|_| Box::new(utils::internal_lints::CompilerLintFunctions::new())); + store.register_late_pass(|_| Box::new(utils::internal_lints::IfChainStyle)); + store.register_late_pass(|_| Box::new(utils::internal_lints::InvalidPaths)); + store.register_late_pass(|_| Box::new(utils::internal_lints::InterningDefinedSymbol::default())); + store.register_late_pass(|_| Box::new(utils::internal_lints::LintWithoutLintPass::default())); + store.register_late_pass(|_| Box::new(utils::internal_lints::MatchTypeOnDiagItem)); + store.register_late_pass(|_| Box::new(utils::internal_lints::OuterExpnDataPass)); + store.register_late_pass(|_| Box::new(utils::internal_lints::MsrvAttrImpl)); } let arithmetic_allowed = conf.arithmetic_allowed.clone(); - store.register_late_pass(move || Box::new(operators::arithmetic::Arithmetic::new(arithmetic_allowed.clone()))); - store.register_late_pass(|| Box::new(utils::dump_hir::DumpHir)); - store.register_late_pass(|| Box::new(utils::author::Author)); + store.register_late_pass(move |_| Box::new(operators::arithmetic::Arithmetic::new(arithmetic_allowed.clone()))); + store.register_late_pass(|_| Box::new(utils::dump_hir::DumpHir)); + store.register_late_pass(|_| Box::new(utils::author::Author)); let await_holding_invalid_types = conf.await_holding_invalid_types.clone(); - store.register_late_pass(move || { + store.register_late_pass(move |_| { Box::new(await_holding_invalid::AwaitHolding::new( await_holding_invalid_types.clone(), )) }); - store.register_late_pass(|| Box::new(serde_api::SerdeApi)); + store.register_late_pass(|_| Box::new(serde_api::SerdeApi)); let vec_box_size_threshold = conf.vec_box_size_threshold; let type_complexity_threshold = conf.type_complexity_threshold; let avoid_breaking_exported_api = conf.avoid_breaking_exported_api; - store.register_late_pass(move || { + store.register_late_pass(move |_| { Box::new(types::Types::new( vec_box_size_threshold, type_complexity_threshold, avoid_breaking_exported_api, )) }); - store.register_late_pass(|| Box::new(booleans::NonminimalBool)); - store.register_late_pass(|| Box::new(enum_clike::UnportableVariant)); - store.register_late_pass(|| Box::new(float_literal::FloatLiteral)); - store.register_late_pass(|| Box::new(ptr::Ptr)); - store.register_late_pass(|| Box::new(needless_bool::NeedlessBool)); - store.register_late_pass(|| Box::new(needless_bool::BoolComparison)); - store.register_late_pass(|| Box::new(needless_for_each::NeedlessForEach)); - store.register_late_pass(|| Box::new(misc::MiscLints)); - store.register_late_pass(|| Box::new(eta_reduction::EtaReduction)); - store.register_late_pass(|| Box::new(mut_mut::MutMut)); - store.register_late_pass(|| Box::new(mut_reference::UnnecessaryMutPassed)); - store.register_late_pass(|| Box::new(len_zero::LenZero)); - store.register_late_pass(|| Box::new(attrs::Attributes)); - store.register_late_pass(|| Box::new(blocks_in_if_conditions::BlocksInIfConditions)); - store.register_late_pass(|| Box::new(unicode::Unicode)); - store.register_late_pass(|| Box::new(uninit_vec::UninitVec)); - store.register_late_pass(|| Box::new(unit_return_expecting_ord::UnitReturnExpectingOrd)); - store.register_late_pass(|| Box::new(strings::StringAdd)); - store.register_late_pass(|| Box::new(implicit_return::ImplicitReturn)); - store.register_late_pass(|| Box::new(implicit_saturating_sub::ImplicitSaturatingSub)); - store.register_late_pass(|| Box::new(default_numeric_fallback::DefaultNumericFallback)); - store.register_late_pass(|| Box::new(inconsistent_struct_constructor::InconsistentStructConstructor)); - store.register_late_pass(|| Box::new(non_octal_unix_permissions::NonOctalUnixPermissions)); + store.register_late_pass(|_| Box::new(booleans::NonminimalBool)); + store.register_late_pass(|_| Box::new(enum_clike::UnportableVariant)); + store.register_late_pass(|_| Box::new(float_literal::FloatLiteral)); + store.register_late_pass(|_| Box::new(ptr::Ptr)); + store.register_late_pass(|_| Box::new(needless_bool::NeedlessBool)); + store.register_late_pass(|_| Box::new(needless_bool::BoolComparison)); + store.register_late_pass(|_| Box::new(needless_for_each::NeedlessForEach)); + store.register_late_pass(|_| Box::new(misc::MiscLints)); + store.register_late_pass(|_| Box::new(eta_reduction::EtaReduction)); + store.register_late_pass(|_| Box::new(mut_mut::MutMut)); + store.register_late_pass(|_| Box::new(mut_reference::UnnecessaryMutPassed)); + store.register_late_pass(|_| Box::new(len_zero::LenZero)); + store.register_late_pass(|_| Box::new(attrs::Attributes)); + store.register_late_pass(|_| Box::new(blocks_in_if_conditions::BlocksInIfConditions)); + store.register_late_pass(|_| Box::new(unicode::Unicode)); + store.register_late_pass(|_| Box::new(uninit_vec::UninitVec)); + store.register_late_pass(|_| Box::new(unit_return_expecting_ord::UnitReturnExpectingOrd)); + store.register_late_pass(|_| Box::new(strings::StringAdd)); + store.register_late_pass(|_| Box::new(implicit_return::ImplicitReturn)); + store.register_late_pass(|_| Box::new(implicit_saturating_sub::ImplicitSaturatingSub)); + store.register_late_pass(|_| Box::new(default_numeric_fallback::DefaultNumericFallback)); + store.register_late_pass(|_| Box::new(inconsistent_struct_constructor::InconsistentStructConstructor)); + store.register_late_pass(|_| Box::new(non_octal_unix_permissions::NonOctalUnixPermissions)); store.register_early_pass(|| Box::new(unnecessary_self_imports::UnnecessarySelfImports)); let msrv = read_msrv(conf, sess); let avoid_breaking_exported_api = conf.avoid_breaking_exported_api; let allow_expect_in_tests = conf.allow_expect_in_tests; let allow_unwrap_in_tests = conf.allow_unwrap_in_tests; - store.register_late_pass(move || Box::new(approx_const::ApproxConstant::new(msrv))); - store.register_late_pass(move || { + store.register_late_pass(move |_| Box::new(approx_const::ApproxConstant::new(msrv))); + store.register_late_pass(move |_| { Box::new(methods::Methods::new( avoid_breaking_exported_api, msrv, @@ -603,74 +603,74 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: allow_unwrap_in_tests, )) }); - store.register_late_pass(move || Box::new(matches::Matches::new(msrv))); + store.register_late_pass(move |_| Box::new(matches::Matches::new(msrv))); store.register_early_pass(move || Box::new(manual_non_exhaustive::ManualNonExhaustiveStruct::new(msrv))); - store.register_late_pass(move || Box::new(manual_non_exhaustive::ManualNonExhaustiveEnum::new(msrv))); - store.register_late_pass(move || Box::new(manual_strip::ManualStrip::new(msrv))); + store.register_late_pass(move |_| Box::new(manual_non_exhaustive::ManualNonExhaustiveEnum::new(msrv))); + store.register_late_pass(move |_| Box::new(manual_strip::ManualStrip::new(msrv))); store.register_early_pass(move || Box::new(redundant_static_lifetimes::RedundantStaticLifetimes::new(msrv))); store.register_early_pass(move || Box::new(redundant_field_names::RedundantFieldNames::new(msrv))); - store.register_late_pass(move || Box::new(checked_conversions::CheckedConversions::new(msrv))); - store.register_late_pass(move || Box::new(mem_replace::MemReplace::new(msrv))); - store.register_late_pass(move || Box::new(ranges::Ranges::new(msrv))); - store.register_late_pass(move || Box::new(from_over_into::FromOverInto::new(msrv))); - store.register_late_pass(move || Box::new(use_self::UseSelf::new(msrv))); - store.register_late_pass(move || Box::new(missing_const_for_fn::MissingConstForFn::new(msrv))); - store.register_late_pass(move || Box::new(needless_question_mark::NeedlessQuestionMark)); - store.register_late_pass(move || Box::new(casts::Casts::new(msrv))); + store.register_late_pass(move |_| Box::new(checked_conversions::CheckedConversions::new(msrv))); + store.register_late_pass(move |_| Box::new(mem_replace::MemReplace::new(msrv))); + store.register_late_pass(move |_| Box::new(ranges::Ranges::new(msrv))); + store.register_late_pass(move |_| Box::new(from_over_into::FromOverInto::new(msrv))); + store.register_late_pass(move |_| Box::new(use_self::UseSelf::new(msrv))); + store.register_late_pass(move |_| Box::new(missing_const_for_fn::MissingConstForFn::new(msrv))); + store.register_late_pass(move |_| Box::new(needless_question_mark::NeedlessQuestionMark)); + store.register_late_pass(move |_| Box::new(casts::Casts::new(msrv))); store.register_early_pass(move || Box::new(unnested_or_patterns::UnnestedOrPatterns::new(msrv))); - store.register_late_pass(|| Box::new(size_of_in_element_count::SizeOfInElementCount)); - store.register_late_pass(|| Box::new(same_name_method::SameNameMethod)); + store.register_late_pass(|_| Box::new(size_of_in_element_count::SizeOfInElementCount)); + store.register_late_pass(|_| Box::new(same_name_method::SameNameMethod)); let max_suggested_slice_pattern_length = conf.max_suggested_slice_pattern_length; - store.register_late_pass(move || { + store.register_late_pass(move |_| { Box::new(index_refutable_slice::IndexRefutableSlice::new( max_suggested_slice_pattern_length, msrv, )) }); - store.register_late_pass(|| Box::new(shadow::Shadow::default())); - store.register_late_pass(|| Box::new(unit_types::UnitTypes)); - store.register_late_pass(|| Box::new(loops::Loops)); - store.register_late_pass(|| Box::new(main_recursion::MainRecursion::default())); - store.register_late_pass(|| Box::new(lifetimes::Lifetimes)); - store.register_late_pass(|| Box::new(entry::HashMapPass)); - store.register_late_pass(|| Box::new(minmax::MinMaxPass)); - store.register_late_pass(|| Box::new(zero_div_zero::ZeroDiv)); - store.register_late_pass(|| Box::new(mutex_atomic::Mutex)); - store.register_late_pass(|| Box::new(needless_update::NeedlessUpdate)); - store.register_late_pass(|| Box::new(needless_borrowed_ref::NeedlessBorrowedRef)); - store.register_late_pass(|| Box::new(borrow_deref_ref::BorrowDerefRef)); - store.register_late_pass(|| Box::new(no_effect::NoEffect)); - store.register_late_pass(|| Box::new(temporary_assignment::TemporaryAssignment)); - store.register_late_pass(move || Box::new(transmute::Transmute::new(msrv))); + store.register_late_pass(|_| Box::new(shadow::Shadow::default())); + store.register_late_pass(|_| Box::new(unit_types::UnitTypes)); + store.register_late_pass(|_| Box::new(loops::Loops)); + store.register_late_pass(|_| Box::new(main_recursion::MainRecursion::default())); + store.register_late_pass(|_| Box::new(lifetimes::Lifetimes)); + store.register_late_pass(|_| Box::new(entry::HashMapPass)); + store.register_late_pass(|_| Box::new(minmax::MinMaxPass)); + store.register_late_pass(|_| Box::new(zero_div_zero::ZeroDiv)); + store.register_late_pass(|_| Box::new(mutex_atomic::Mutex)); + store.register_late_pass(|_| Box::new(needless_update::NeedlessUpdate)); + store.register_late_pass(|_| Box::new(needless_borrowed_ref::NeedlessBorrowedRef)); + store.register_late_pass(|_| Box::new(borrow_deref_ref::BorrowDerefRef)); + store.register_late_pass(|_| Box::new(no_effect::NoEffect)); + store.register_late_pass(|_| Box::new(temporary_assignment::TemporaryAssignment)); + store.register_late_pass(move |_| Box::new(transmute::Transmute::new(msrv))); let cognitive_complexity_threshold = conf.cognitive_complexity_threshold; - store.register_late_pass(move || { + store.register_late_pass(move |_| { Box::new(cognitive_complexity::CognitiveComplexity::new( cognitive_complexity_threshold, )) }); let too_large_for_stack = conf.too_large_for_stack; - store.register_late_pass(move || Box::new(escape::BoxedLocal { too_large_for_stack })); - store.register_late_pass(move || Box::new(vec::UselessVec { too_large_for_stack })); - store.register_late_pass(|| Box::new(panic_unimplemented::PanicUnimplemented)); - store.register_late_pass(|| Box::new(strings::StringLitAsBytes)); - store.register_late_pass(|| Box::new(derive::Derive)); - store.register_late_pass(|| Box::new(derivable_impls::DerivableImpls)); - store.register_late_pass(|| Box::new(drop_forget_ref::DropForgetRef)); - store.register_late_pass(|| Box::new(empty_enum::EmptyEnum)); - store.register_late_pass(|| Box::new(invalid_upcast_comparisons::InvalidUpcastComparisons)); - store.register_late_pass(|| Box::new(regex::Regex)); - store.register_late_pass(|| Box::new(copies::CopyAndPaste)); - store.register_late_pass(|| Box::new(copy_iterator::CopyIterator)); - store.register_late_pass(|| Box::new(format::UselessFormat)); - store.register_late_pass(|| Box::new(swap::Swap)); - store.register_late_pass(|| Box::new(overflow_check_conditional::OverflowCheckConditional)); - store.register_late_pass(|| Box::new(new_without_default::NewWithoutDefault::default())); + store.register_late_pass(move |_| Box::new(escape::BoxedLocal { too_large_for_stack })); + store.register_late_pass(move |_| Box::new(vec::UselessVec { too_large_for_stack })); + store.register_late_pass(|_| Box::new(panic_unimplemented::PanicUnimplemented)); + store.register_late_pass(|_| Box::new(strings::StringLitAsBytes)); + store.register_late_pass(|_| Box::new(derive::Derive)); + store.register_late_pass(|_| Box::new(derivable_impls::DerivableImpls)); + store.register_late_pass(|_| Box::new(drop_forget_ref::DropForgetRef)); + store.register_late_pass(|_| Box::new(empty_enum::EmptyEnum)); + store.register_late_pass(|_| Box::new(invalid_upcast_comparisons::InvalidUpcastComparisons)); + store.register_late_pass(|_| Box::new(regex::Regex)); + store.register_late_pass(|_| Box::new(copies::CopyAndPaste)); + store.register_late_pass(|_| Box::new(copy_iterator::CopyIterator)); + store.register_late_pass(|_| Box::new(format::UselessFormat)); + store.register_late_pass(|_| Box::new(swap::Swap)); + store.register_late_pass(|_| Box::new(overflow_check_conditional::OverflowCheckConditional)); + store.register_late_pass(|_| Box::new(new_without_default::NewWithoutDefault::default())); let disallowed_names = conf.disallowed_names.iter().cloned().collect::>(); - store.register_late_pass(move || Box::new(disallowed_names::DisallowedNames::new(disallowed_names.clone()))); + store.register_late_pass(move |_| Box::new(disallowed_names::DisallowedNames::new(disallowed_names.clone()))); let too_many_arguments_threshold = conf.too_many_arguments_threshold; let too_many_lines_threshold = conf.too_many_lines_threshold; let large_error_threshold = conf.large_error_threshold; - store.register_late_pass(move || { + store.register_late_pass(move |_| { Box::new(functions::Functions::new( too_many_arguments_threshold, too_many_lines_threshold, @@ -678,73 +678,73 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: )) }); let doc_valid_idents = conf.doc_valid_idents.iter().cloned().collect::>(); - store.register_late_pass(move || Box::new(doc::DocMarkdown::new(doc_valid_idents.clone()))); - store.register_late_pass(|| Box::new(neg_multiply::NegMultiply)); - store.register_late_pass(|| Box::new(mem_forget::MemForget)); - store.register_late_pass(|| Box::new(let_if_seq::LetIfSeq)); - store.register_late_pass(|| Box::new(mixed_read_write_in_expression::EvalOrderDependence)); - store.register_late_pass(|| Box::new(missing_doc::MissingDoc::new())); - store.register_late_pass(|| Box::new(missing_inline::MissingInline)); - store.register_late_pass(move || Box::new(exhaustive_items::ExhaustiveItems)); - store.register_late_pass(|| Box::new(match_result_ok::MatchResultOk)); - store.register_late_pass(|| Box::new(partialeq_ne_impl::PartialEqNeImpl)); - store.register_late_pass(|| Box::new(unused_io_amount::UnusedIoAmount)); + store.register_late_pass(move |_| Box::new(doc::DocMarkdown::new(doc_valid_idents.clone()))); + store.register_late_pass(|_| Box::new(neg_multiply::NegMultiply)); + store.register_late_pass(|_| Box::new(mem_forget::MemForget)); + store.register_late_pass(|_| Box::new(let_if_seq::LetIfSeq)); + store.register_late_pass(|_| Box::new(mixed_read_write_in_expression::EvalOrderDependence)); + store.register_late_pass(|_| Box::new(missing_doc::MissingDoc::new())); + store.register_late_pass(|_| Box::new(missing_inline::MissingInline)); + store.register_late_pass(move |_| Box::new(exhaustive_items::ExhaustiveItems)); + store.register_late_pass(|_| Box::new(match_result_ok::MatchResultOk)); + store.register_late_pass(|_| Box::new(partialeq_ne_impl::PartialEqNeImpl)); + store.register_late_pass(|_| Box::new(unused_io_amount::UnusedIoAmount)); let enum_variant_size_threshold = conf.enum_variant_size_threshold; - store.register_late_pass(move || Box::new(large_enum_variant::LargeEnumVariant::new(enum_variant_size_threshold))); - store.register_late_pass(|| Box::new(explicit_write::ExplicitWrite)); - store.register_late_pass(|| Box::new(needless_pass_by_value::NeedlessPassByValue)); + store.register_late_pass(move |_| Box::new(large_enum_variant::LargeEnumVariant::new(enum_variant_size_threshold))); + store.register_late_pass(|_| Box::new(explicit_write::ExplicitWrite)); + store.register_late_pass(|_| Box::new(needless_pass_by_value::NeedlessPassByValue)); let pass_by_ref_or_value = pass_by_ref_or_value::PassByRefOrValue::new( conf.trivial_copy_size_limit, conf.pass_by_value_size_limit, conf.avoid_breaking_exported_api, &sess.target, ); - store.register_late_pass(move || Box::new(pass_by_ref_or_value)); - store.register_late_pass(|| Box::new(ref_option_ref::RefOptionRef)); - store.register_late_pass(|| Box::new(infinite_iter::InfiniteIter)); - store.register_late_pass(|| Box::new(inline_fn_without_body::InlineFnWithoutBody)); - store.register_late_pass(|| Box::new(useless_conversion::UselessConversion::default())); - store.register_late_pass(|| Box::new(implicit_hasher::ImplicitHasher)); - store.register_late_pass(|| Box::new(fallible_impl_from::FallibleImplFrom)); - store.register_late_pass(|| Box::new(question_mark::QuestionMark)); + store.register_late_pass(move |_| Box::new(pass_by_ref_or_value)); + store.register_late_pass(|_| Box::new(ref_option_ref::RefOptionRef)); + store.register_late_pass(|_| Box::new(infinite_iter::InfiniteIter)); + store.register_late_pass(|_| Box::new(inline_fn_without_body::InlineFnWithoutBody)); + store.register_late_pass(|_| Box::new(useless_conversion::UselessConversion::default())); + store.register_late_pass(|_| Box::new(implicit_hasher::ImplicitHasher)); + store.register_late_pass(|_| Box::new(fallible_impl_from::FallibleImplFrom)); + store.register_late_pass(|_| Box::new(question_mark::QuestionMark)); store.register_early_pass(|| Box::new(suspicious_operation_groupings::SuspiciousOperationGroupings)); - store.register_late_pass(|| Box::new(suspicious_trait_impl::SuspiciousImpl)); - store.register_late_pass(|| Box::new(map_unit_fn::MapUnit)); - store.register_late_pass(|| Box::new(inherent_impl::MultipleInherentImpl)); - store.register_late_pass(|| Box::new(neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd)); - store.register_late_pass(|| Box::new(unwrap::Unwrap)); - store.register_late_pass(|| Box::new(indexing_slicing::IndexingSlicing)); - store.register_late_pass(|| Box::new(non_copy_const::NonCopyConst)); - store.register_late_pass(|| Box::new(ptr_offset_with_cast::PtrOffsetWithCast)); - store.register_late_pass(|| Box::new(redundant_clone::RedundantClone)); - store.register_late_pass(|| Box::new(slow_vector_initialization::SlowVectorInit)); - store.register_late_pass(move || Box::new(unnecessary_wraps::UnnecessaryWraps::new(avoid_breaking_exported_api))); - store.register_late_pass(|| Box::new(assertions_on_constants::AssertionsOnConstants)); - store.register_late_pass(|| Box::new(assertions_on_result_states::AssertionsOnResultStates)); - store.register_late_pass(|| Box::new(inherent_to_string::InherentToString)); + store.register_late_pass(|_| Box::new(suspicious_trait_impl::SuspiciousImpl)); + store.register_late_pass(|_| Box::new(map_unit_fn::MapUnit)); + store.register_late_pass(|_| Box::new(inherent_impl::MultipleInherentImpl)); + store.register_late_pass(|_| Box::new(neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd)); + store.register_late_pass(|_| Box::new(unwrap::Unwrap)); + store.register_late_pass(|_| Box::new(indexing_slicing::IndexingSlicing)); + store.register_late_pass(|_| Box::new(non_copy_const::NonCopyConst)); + store.register_late_pass(|_| Box::new(ptr_offset_with_cast::PtrOffsetWithCast)); + store.register_late_pass(|_| Box::new(redundant_clone::RedundantClone)); + store.register_late_pass(|_| Box::new(slow_vector_initialization::SlowVectorInit)); + store.register_late_pass(move |_| Box::new(unnecessary_wraps::UnnecessaryWraps::new(avoid_breaking_exported_api))); + store.register_late_pass(|_| Box::new(assertions_on_constants::AssertionsOnConstants)); + store.register_late_pass(|_| Box::new(assertions_on_result_states::AssertionsOnResultStates)); + store.register_late_pass(|_| Box::new(inherent_to_string::InherentToString)); let max_trait_bounds = conf.max_trait_bounds; - store.register_late_pass(move || Box::new(trait_bounds::TraitBounds::new(max_trait_bounds))); - store.register_late_pass(|| Box::new(comparison_chain::ComparisonChain)); - store.register_late_pass(|| Box::new(mut_key::MutableKeyType)); + store.register_late_pass(move |_| Box::new(trait_bounds::TraitBounds::new(max_trait_bounds))); + store.register_late_pass(|_| Box::new(comparison_chain::ComparisonChain)); + store.register_late_pass(|_| Box::new(mut_key::MutableKeyType)); store.register_early_pass(|| Box::new(reference::DerefAddrOf)); store.register_early_pass(|| Box::new(double_parens::DoubleParens)); - store.register_late_pass(|| Box::new(format_impl::FormatImpl::new())); + store.register_late_pass(|_| Box::new(format_impl::FormatImpl::new())); store.register_early_pass(|| Box::new(unsafe_removed_from_name::UnsafeNameRemoval)); store.register_early_pass(|| Box::new(else_if_without_else::ElseIfWithoutElse)); store.register_early_pass(|| Box::new(int_plus_one::IntPlusOne)); store.register_early_pass(|| Box::new(formatting::Formatting)); store.register_early_pass(|| Box::new(misc_early::MiscEarlyLints)); store.register_early_pass(|| Box::new(redundant_closure_call::RedundantClosureCall)); - store.register_late_pass(|| Box::new(redundant_closure_call::RedundantClosureCall)); + store.register_late_pass(|_| Box::new(redundant_closure_call::RedundantClosureCall)); store.register_early_pass(|| Box::new(unused_unit::UnusedUnit)); - store.register_late_pass(|| Box::new(returns::Return)); + store.register_late_pass(|_| Box::new(returns::Return)); store.register_early_pass(|| Box::new(collapsible_if::CollapsibleIf)); store.register_early_pass(|| Box::new(items_after_statements::ItemsAfterStatements)); store.register_early_pass(|| Box::new(precedence::Precedence)); - store.register_late_pass(|| Box::new(needless_parens_on_range_literals::NeedlessParensOnRangeLiterals)); + store.register_late_pass(|_| Box::new(needless_parens_on_range_literals::NeedlessParensOnRangeLiterals)); store.register_early_pass(|| Box::new(needless_continue::NeedlessContinue)); store.register_early_pass(|| Box::new(redundant_else::RedundantElse)); - store.register_late_pass(|| Box::new(create_dir::CreateDir)); + store.register_late_pass(|_| Box::new(create_dir::CreateDir)); store.register_early_pass(|| Box::new(needless_arbitrary_self_type::NeedlessArbitrarySelfType)); let literal_representation_lint_fraction_readability = conf.unreadable_literal_lint_fractions; store.register_early_pass(move || { @@ -759,7 +759,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: )) }); let enum_variant_name_threshold = conf.enum_variant_name_threshold; - store.register_late_pass(move || { + store.register_late_pass(move |_| { Box::new(enum_variants::EnumVariantNames::new( enum_variant_name_threshold, avoid_breaking_exported_api, @@ -767,23 +767,23 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: }); store.register_early_pass(|| Box::new(tabs_in_doc_comments::TabsInDocComments)); let upper_case_acronyms_aggressive = conf.upper_case_acronyms_aggressive; - store.register_late_pass(move || { + store.register_late_pass(move |_| { Box::new(upper_case_acronyms::UpperCaseAcronyms::new( avoid_breaking_exported_api, upper_case_acronyms_aggressive, )) }); - store.register_late_pass(|| Box::new(default::Default::default())); - store.register_late_pass(move || Box::new(unused_self::UnusedSelf::new(avoid_breaking_exported_api))); - store.register_late_pass(|| Box::new(mutable_debug_assertion::DebugAssertWithMutCall)); - store.register_late_pass(|| Box::new(exit::Exit)); - store.register_late_pass(|| Box::new(to_digit_is_some::ToDigitIsSome)); + store.register_late_pass(|_| Box::new(default::Default::default())); + store.register_late_pass(move |_| Box::new(unused_self::UnusedSelf::new(avoid_breaking_exported_api))); + store.register_late_pass(|_| Box::new(mutable_debug_assertion::DebugAssertWithMutCall)); + store.register_late_pass(|_| Box::new(exit::Exit)); + store.register_late_pass(|_| Box::new(to_digit_is_some::ToDigitIsSome)); let array_size_threshold = conf.array_size_threshold; - store.register_late_pass(move || Box::new(large_stack_arrays::LargeStackArrays::new(array_size_threshold))); - store.register_late_pass(move || Box::new(large_const_arrays::LargeConstArrays::new(array_size_threshold))); - store.register_late_pass(|| Box::new(floating_point_arithmetic::FloatingPointArithmetic)); + store.register_late_pass(move |_| Box::new(large_stack_arrays::LargeStackArrays::new(array_size_threshold))); + store.register_late_pass(move |_| Box::new(large_const_arrays::LargeConstArrays::new(array_size_threshold))); + store.register_late_pass(|_| Box::new(floating_point_arithmetic::FloatingPointArithmetic)); store.register_early_pass(|| Box::new(as_conversions::AsConversions)); - store.register_late_pass(|| Box::new(let_underscore::LetUnderscore)); + store.register_late_pass(|_| Box::new(let_underscore::LetUnderscore)); store.register_early_pass(|| Box::new(single_component_path_imports::SingleComponentPathImports)); let max_fn_params_bools = conf.max_fn_params_bools; let max_struct_bools = conf.max_struct_bools; @@ -795,17 +795,17 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: }); store.register_early_pass(|| Box::new(option_env_unwrap::OptionEnvUnwrap)); let warn_on_all_wildcard_imports = conf.warn_on_all_wildcard_imports; - store.register_late_pass(move || Box::new(wildcard_imports::WildcardImports::new(warn_on_all_wildcard_imports))); - store.register_late_pass(|| Box::new(redundant_pub_crate::RedundantPubCrate::default())); - store.register_late_pass(|| Box::new(unnamed_address::UnnamedAddress)); - store.register_late_pass(move || Box::new(dereference::Dereferencing::new(msrv))); - store.register_late_pass(|| Box::new(option_if_let_else::OptionIfLetElse)); - store.register_late_pass(|| Box::new(future_not_send::FutureNotSend)); - store.register_late_pass(|| Box::new(if_let_mutex::IfLetMutex)); - store.register_late_pass(|| Box::new(if_not_else::IfNotElse)); - store.register_late_pass(|| Box::new(equatable_if_let::PatternEquality)); - store.register_late_pass(|| Box::new(manual_async_fn::ManualAsyncFn)); - store.register_late_pass(|| Box::new(panic_in_result_fn::PanicInResultFn)); + store.register_late_pass(move |_| Box::new(wildcard_imports::WildcardImports::new(warn_on_all_wildcard_imports))); + store.register_late_pass(|_| Box::new(redundant_pub_crate::RedundantPubCrate::default())); + store.register_late_pass(|_| Box::new(unnamed_address::UnnamedAddress)); + store.register_late_pass(move |_| Box::new(dereference::Dereferencing::new(msrv))); + store.register_late_pass(|_| Box::new(option_if_let_else::OptionIfLetElse)); + store.register_late_pass(|_| Box::new(future_not_send::FutureNotSend)); + store.register_late_pass(|_| Box::new(if_let_mutex::IfLetMutex)); + store.register_late_pass(|_| Box::new(if_not_else::IfNotElse)); + store.register_late_pass(|_| Box::new(equatable_if_let::PatternEquality)); + store.register_late_pass(|_| Box::new(manual_async_fn::ManualAsyncFn)); + store.register_late_pass(|_| Box::new(panic_in_result_fn::PanicInResultFn)); let single_char_binding_names_threshold = conf.single_char_binding_names_threshold; store.register_early_pass(move || { Box::new(non_expressive_names::NonExpressiveNames { @@ -814,92 +814,92 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: }); let macro_matcher = conf.standard_macro_braces.iter().cloned().collect::>(); store.register_early_pass(move || Box::new(nonstandard_macro_braces::MacroBraces::new(¯o_matcher))); - store.register_late_pass(|| Box::new(macro_use::MacroUseImports::default())); - store.register_late_pass(|| Box::new(pattern_type_mismatch::PatternTypeMismatch)); - store.register_late_pass(|| Box::new(unwrap_in_result::UnwrapInResult)); - store.register_late_pass(|| Box::new(semicolon_if_nothing_returned::SemicolonIfNothingReturned)); - store.register_late_pass(|| Box::new(async_yields_async::AsyncYieldsAsync)); + store.register_late_pass(|_| Box::new(macro_use::MacroUseImports::default())); + store.register_late_pass(|_| Box::new(pattern_type_mismatch::PatternTypeMismatch)); + store.register_late_pass(|_| Box::new(unwrap_in_result::UnwrapInResult)); + store.register_late_pass(|_| Box::new(semicolon_if_nothing_returned::SemicolonIfNothingReturned)); + store.register_late_pass(|_| Box::new(async_yields_async::AsyncYieldsAsync)); let disallowed_methods = conf.disallowed_methods.clone(); - store.register_late_pass(move || Box::new(disallowed_methods::DisallowedMethods::new(disallowed_methods.clone()))); + store.register_late_pass(move |_| Box::new(disallowed_methods::DisallowedMethods::new(disallowed_methods.clone()))); store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86AttSyntax)); store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86IntelSyntax)); - store.register_late_pass(|| Box::new(empty_drop::EmptyDrop)); - store.register_late_pass(|| Box::new(strings::StrToString)); - store.register_late_pass(|| Box::new(strings::StringToString)); - store.register_late_pass(|| Box::new(zero_sized_map_values::ZeroSizedMapValues)); - store.register_late_pass(|| Box::new(vec_init_then_push::VecInitThenPush::default())); - store.register_late_pass(|| Box::new(redundant_slicing::RedundantSlicing)); - store.register_late_pass(|| Box::new(from_str_radix_10::FromStrRadix10)); - store.register_late_pass(move || Box::new(if_then_some_else_none::IfThenSomeElseNone::new(msrv))); - store.register_late_pass(|| Box::new(bool_assert_comparison::BoolAssertComparison)); + store.register_late_pass(|_| Box::new(empty_drop::EmptyDrop)); + store.register_late_pass(|_| Box::new(strings::StrToString)); + store.register_late_pass(|_| Box::new(strings::StringToString)); + store.register_late_pass(|_| Box::new(zero_sized_map_values::ZeroSizedMapValues)); + store.register_late_pass(|_| Box::new(vec_init_then_push::VecInitThenPush::default())); + store.register_late_pass(|_| Box::new(redundant_slicing::RedundantSlicing)); + store.register_late_pass(|_| Box::new(from_str_radix_10::FromStrRadix10)); + store.register_late_pass(move |_| Box::new(if_then_some_else_none::IfThenSomeElseNone::new(msrv))); + store.register_late_pass(|_| Box::new(bool_assert_comparison::BoolAssertComparison)); store.register_early_pass(move || Box::new(module_style::ModStyle)); - store.register_late_pass(|| Box::new(unused_async::UnusedAsync)); + store.register_late_pass(|_| Box::new(unused_async::UnusedAsync)); let disallowed_types = conf.disallowed_types.clone(); - store.register_late_pass(move || Box::new(disallowed_types::DisallowedTypes::new(disallowed_types.clone()))); + store.register_late_pass(move |_| Box::new(disallowed_types::DisallowedTypes::new(disallowed_types.clone()))); let import_renames = conf.enforced_import_renames.clone(); - store.register_late_pass(move || { + store.register_late_pass(move |_| { Box::new(missing_enforced_import_rename::ImportRename::new( import_renames.clone(), )) }); let scripts = conf.allowed_scripts.clone(); store.register_early_pass(move || Box::new(disallowed_script_idents::DisallowedScriptIdents::new(&scripts))); - store.register_late_pass(|| Box::new(strlen_on_c_strings::StrlenOnCStrings)); - store.register_late_pass(move || Box::new(self_named_constructors::SelfNamedConstructors)); - store.register_late_pass(move || Box::new(iter_not_returning_iterator::IterNotReturningIterator)); - store.register_late_pass(move || Box::new(manual_assert::ManualAssert)); + store.register_late_pass(|_| Box::new(strlen_on_c_strings::StrlenOnCStrings)); + store.register_late_pass(move |_| Box::new(self_named_constructors::SelfNamedConstructors)); + store.register_late_pass(move |_| Box::new(iter_not_returning_iterator::IterNotReturningIterator)); + store.register_late_pass(move |_| Box::new(manual_assert::ManualAssert)); let enable_raw_pointer_heuristic_for_send = conf.enable_raw_pointer_heuristic_for_send; - store.register_late_pass(move || { + store.register_late_pass(move |_| { Box::new(non_send_fields_in_send_ty::NonSendFieldInSendTy::new( enable_raw_pointer_heuristic_for_send, )) }); - store.register_late_pass(move || Box::new(undocumented_unsafe_blocks::UndocumentedUnsafeBlocks)); - store.register_late_pass(move || Box::new(format_args::FormatArgs)); - store.register_late_pass(|| Box::new(trailing_empty_array::TrailingEmptyArray)); + store.register_late_pass(move |_| Box::new(undocumented_unsafe_blocks::UndocumentedUnsafeBlocks)); + store.register_late_pass(move |_| Box::new(format_args::FormatArgs)); + store.register_late_pass(|_| Box::new(trailing_empty_array::TrailingEmptyArray)); store.register_early_pass(|| Box::new(octal_escapes::OctalEscapes)); - store.register_late_pass(|| Box::new(needless_late_init::NeedlessLateInit)); - store.register_late_pass(|| Box::new(return_self_not_must_use::ReturnSelfNotMustUse)); - store.register_late_pass(|| Box::new(init_numbered_fields::NumberedFields)); + store.register_late_pass(|_| Box::new(needless_late_init::NeedlessLateInit)); + store.register_late_pass(|_| Box::new(return_self_not_must_use::ReturnSelfNotMustUse)); + store.register_late_pass(|_| Box::new(init_numbered_fields::NumberedFields)); store.register_early_pass(|| Box::new(single_char_lifetime_names::SingleCharLifetimeNames)); - store.register_late_pass(move || Box::new(manual_bits::ManualBits::new(msrv))); - store.register_late_pass(|| Box::new(default_union_representation::DefaultUnionRepresentation)); + store.register_late_pass(move |_| Box::new(manual_bits::ManualBits::new(msrv))); + store.register_late_pass(|_| Box::new(default_union_representation::DefaultUnionRepresentation)); store.register_early_pass(|| Box::new(doc_link_with_quotes::DocLinkWithQuotes)); - store.register_late_pass(|| Box::new(only_used_in_recursion::OnlyUsedInRecursion::default())); + store.register_late_pass(|_| Box::new(only_used_in_recursion::OnlyUsedInRecursion::default())); let allow_dbg_in_tests = conf.allow_dbg_in_tests; - store.register_late_pass(move || Box::new(dbg_macro::DbgMacro::new(allow_dbg_in_tests))); + store.register_late_pass(move |_| Box::new(dbg_macro::DbgMacro::new(allow_dbg_in_tests))); let cargo_ignore_publish = conf.cargo_ignore_publish; - store.register_late_pass(move || { + store.register_late_pass(move |_| { Box::new(cargo::Cargo { ignore_publish: cargo_ignore_publish, }) }); store.register_early_pass(|| Box::new(crate_in_macro_def::CrateInMacroDef)); store.register_early_pass(|| Box::new(empty_structs_with_brackets::EmptyStructsWithBrackets)); - store.register_late_pass(|| Box::new(unnecessary_owned_empty_strings::UnnecessaryOwnedEmptyStrings)); + store.register_late_pass(|_| Box::new(unnecessary_owned_empty_strings::UnnecessaryOwnedEmptyStrings)); store.register_early_pass(|| Box::new(pub_use::PubUse)); - store.register_late_pass(|| Box::new(format_push_string::FormatPushString)); + store.register_late_pass(|_| Box::new(format_push_string::FormatPushString)); let max_include_file_size = conf.max_include_file_size; - store.register_late_pass(move || Box::new(large_include_file::LargeIncludeFile::new(max_include_file_size))); - store.register_late_pass(|| Box::new(strings::TrimSplitWhitespace)); - store.register_late_pass(|| Box::new(rc_clone_in_vec_init::RcCloneInVecInit)); + store.register_late_pass(move |_| Box::new(large_include_file::LargeIncludeFile::new(max_include_file_size))); + store.register_late_pass(|_| Box::new(strings::TrimSplitWhitespace)); + store.register_late_pass(|_| Box::new(rc_clone_in_vec_init::RcCloneInVecInit)); store.register_early_pass(|| Box::new(duplicate_mod::DuplicateMod::default())); store.register_early_pass(|| Box::new(unused_rounding::UnusedRounding)); store.register_early_pass(move || Box::new(almost_complete_letter_range::AlmostCompleteLetterRange::new(msrv))); - store.register_late_pass(|| Box::new(swap_ptr_to_ref::SwapPtrToRef)); - store.register_late_pass(|| Box::new(mismatching_type_param_order::TypeParamMismatch)); - store.register_late_pass(|| Box::new(read_zero_byte_vec::ReadZeroByteVec)); - store.register_late_pass(|| Box::new(default_instead_of_iter_empty::DefaultIterEmpty)); - store.register_late_pass(move || Box::new(manual_rem_euclid::ManualRemEuclid::new(msrv))); - store.register_late_pass(move || Box::new(manual_retain::ManualRetain::new(msrv))); + store.register_late_pass(|_| Box::new(swap_ptr_to_ref::SwapPtrToRef)); + store.register_late_pass(|_| Box::new(mismatching_type_param_order::TypeParamMismatch)); + store.register_late_pass(|_| Box::new(read_zero_byte_vec::ReadZeroByteVec)); + store.register_late_pass(|_| Box::new(default_instead_of_iter_empty::DefaultIterEmpty)); + store.register_late_pass(move |_| Box::new(manual_rem_euclid::ManualRemEuclid::new(msrv))); + store.register_late_pass(move |_| Box::new(manual_retain::ManualRetain::new(msrv))); let verbose_bit_mask_threshold = conf.verbose_bit_mask_threshold; - store.register_late_pass(move || Box::new(operators::Operators::new(verbose_bit_mask_threshold))); - store.register_late_pass(|| Box::new(invalid_utf8_in_unchecked::InvalidUtf8InUnchecked)); - store.register_late_pass(|| Box::new(std_instead_of_core::StdReexports::default())); - store.register_late_pass(|| Box::new(manual_instant_elapsed::ManualInstantElapsed)); - store.register_late_pass(|| Box::new(partialeq_to_none::PartialeqToNone)); - store.register_late_pass(|| Box::new(manual_string_new::ManualStringNew)); - store.register_late_pass(|| Box::new(unused_peekable::UnusedPeekable)); + store.register_late_pass(move |_| Box::new(operators::Operators::new(verbose_bit_mask_threshold))); + store.register_late_pass(|_| Box::new(invalid_utf8_in_unchecked::InvalidUtf8InUnchecked)); + store.register_late_pass(|_| Box::new(std_instead_of_core::StdReexports::default())); + store.register_late_pass(|_| Box::new(manual_instant_elapsed::ManualInstantElapsed)); + store.register_late_pass(|_| Box::new(partialeq_to_none::PartialeqToNone)); + store.register_late_pass(|_| Box::new(manual_string_new::ManualStringNew)); + store.register_late_pass(|_| Box::new(unused_peekable::UnusedPeekable)); store.register_early_pass(|| Box::new(multi_assignments::MultiAssignments)); // add lints here, do not remove this comment, it's used in `new_lint` } From 1dc255a75299847b5d328a33e0a5e56aea79a0fd Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 28 Aug 2022 00:10:06 +0300 Subject: [PATCH 0601/1222] rustc: Parameterize `ty::Visibility` over used ID It allows using `LocalDefId` instead of `DefId` when possible, and also encode cheaper `Visibility` into metadata. --- clippy_lints/src/default.rs | 2 +- clippy_lints/src/derive.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index 74f7df611778..4e68d6810e29 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -142,7 +142,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { if adt.is_struct(); let variant = adt.non_enum_variant(); if adt.did().is_local() || !variant.is_field_list_non_exhaustive(); - let module_did = cx.tcx.parent_module(stmt.hir_id).to_def_id(); + let module_did = cx.tcx.parent_module(stmt.hir_id); if variant .fields .iter() diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 9ca443b7dff6..23c86482b46c 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -15,7 +15,7 @@ use rustc_middle::hir::nested_filter; use rustc_middle::traits::Reveal; use rustc_middle::ty::{ self, Binder, BoundConstness, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate, TraitRef, - Ty, TyCtxt, Visibility, + Ty, TyCtxt, }; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; @@ -464,7 +464,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> { fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_ref: &hir::TraitRef<'_>, ty: Ty<'tcx>) { if_chain! { if let ty::Adt(adt, substs) = ty.kind(); - if cx.tcx.visibility(adt.did()) == Visibility::Public; + if cx.tcx.visibility(adt.did()).is_public(); if let Some(eq_trait_def_id) = cx.tcx.get_diagnostic_item(sym::Eq); if let Some(def_id) = trait_ref.trait_def_id(); if cx.tcx.is_diagnostic_item(sym::PartialEq, def_id); From f8c46849853429744af509601839691980299590 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 1 Sep 2022 12:06:48 +1000 Subject: [PATCH 0602/1222] Arena-allocate `hir::Lifetime`. This shrinks `hir::Ty` from 72 to 48 bytes. `visit_lifetime` is added to the HIR stats collector because these types are now stored in memory on their own, instead of being within other types. --- clippy_utils/src/hir_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 57448f716d49..ff23ed5fffa3 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -929,7 +929,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } - pub fn hash_lifetime(&mut self, lifetime: Lifetime) { + pub fn hash_lifetime(&mut self, lifetime: &Lifetime) { std::mem::discriminant(&lifetime.name).hash(&mut self.s); if let LifetimeName::Param(param_id, ref name) = lifetime.name { std::mem::discriminant(name).hash(&mut self.s); From b1239a3d445c51e077fb6c90a0afcd700d64e971 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 1 Sep 2022 13:29:57 +1000 Subject: [PATCH 0603/1222] Introduce `DotDotPos`. This shrinks `hir::Pat` from 88 to 72 bytes. --- clippy_lints/src/equatable_if_let.rs | 4 +++- clippy_lints/src/matches/match_same_arms.rs | 4 ++-- clippy_lints/src/matches/single_match.rs | 2 ++ clippy_lints/src/question_mark.rs | 3 ++- clippy_lints/src/unit_types/let_unit_value.rs | 6 ++++-- clippy_utils/src/lib.rs | 3 ++- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/equatable_if_let.rs b/clippy_lints/src/equatable_if_let.rs index fdfb821ac789..bce49165e5b1 100644 --- a/clippy_lints/src/equatable_if_let.rs +++ b/clippy_lints/src/equatable_if_let.rs @@ -51,7 +51,9 @@ fn unary_pattern(pat: &Pat<'_>) -> bool { false }, PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)), - PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => !etc.is_some() && array_rec(a), + PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => { + !etc.as_opt_usize().is_some() && array_rec(a) + } PatKind::Ref(x, _) | PatKind::Box(x) => unary_pattern(x), PatKind::Path(_) | PatKind::Lit(_) => true, } diff --git a/clippy_lints/src/matches/match_same_arms.rs b/clippy_lints/src/matches/match_same_arms.rs index e32ef9933afe..93874b103b46 100644 --- a/clippy_lints/src/matches/match_same_arms.rs +++ b/clippy_lints/src/matches/match_same_arms.rs @@ -248,7 +248,7 @@ impl<'a> NormalizedPat<'a> { } else { (None, adt.non_enum_variant()) }; - let (front, back) = match wild_idx { + let (front, back) = match wild_idx.as_opt_usize() { Some(i) => pats.split_at(i), None => (pats, [].as_slice()), }; @@ -268,7 +268,7 @@ impl<'a> NormalizedPat<'a> { ty::Tuple(subs) => subs.len(), _ => return Self::Wild, }; - let (front, back) = match wild_idx { + let (front, back) = match wild_idx.as_opt_usize() { Some(i) => pats.split_at(i), None => (pats, [].as_slice()), }; diff --git a/clippy_lints/src/matches/single_match.rs b/clippy_lints/src/matches/single_match.rs index 95478af45b4b..1bf1c4d10789 100644 --- a/clippy_lints/src/matches/single_match.rs +++ b/clippy_lints/src/matches/single_match.rs @@ -200,6 +200,8 @@ fn form_exhaustive_matches<'a>(cx: &LateContext<'a>, ty: Ty<'a>, left: &Pat<'_>, // We don't actually know the position and the presence of the `..` (dotdot) operator // in the arms, so we need to evaluate the correct offsets here in order to iterate in // both arms at the same time. + let left_pos = left_pos.as_opt_usize(); + let right_pos = right_pos.as_opt_usize(); let len = max( left_in.len() + { if left_pos.is_some() { 1 } else { 0 } diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index f4f1fd336df7..569870ab2b7f 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -122,7 +122,8 @@ fn check_if_let_some_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr: if_chain! { if let Some(higher::IfLet { let_pat, let_expr, if_then, if_else }) = higher::IfLet::hir(cx, expr); if !is_else_clause(cx.tcx, expr); - if let PatKind::TupleStruct(ref path1, [field], None) = let_pat.kind; + if let PatKind::TupleStruct(ref path1, [field], ddpos) = let_pat.kind; + if ddpos.as_opt_usize().is_none(); if let PatKind::Binding(BindingAnnotation(by_ref, _), bind_id, ident, None) = field.kind; let caller_ty = cx.typeck_results().expr_ty(let_expr); let if_block = IfBlockType::IfLet(path1, caller_ty, ident.name, let_expr, if_then, if_else); diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index 35824b03170a..ce9ebad8c89a 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -19,10 +19,12 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>) { && cx.typeck_results().pat_ty(local.pat).is_unit() { if (local.ty.map_or(false, |ty| !matches!(ty.kind, TyKind::Infer)) - || matches!(local.pat.kind, PatKind::Tuple([], None))) + || matches!(local.pat.kind, PatKind::Tuple([], ddpos) if ddpos.as_opt_usize().is_none())) && expr_needs_inferred_result(cx, init) { - if !matches!(local.pat.kind, PatKind::Wild | PatKind::Tuple([], None)) { + if !matches!(local.pat.kind, PatKind::Wild) + && !matches!(local.pat.kind, PatKind::Tuple([], ddpos) if ddpos.as_opt_usize().is_none()) + { span_lint_and_then( cx, LET_UNIT_VALUE, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index b27439cbec27..3cf043f22df5 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1552,7 +1552,8 @@ pub fn iter_input_pats<'tcx>(decl: &FnDecl<'_>, body: &'tcx Body<'_>) -> impl It pub fn is_try<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { fn is_ok(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool { if_chain! { - if let PatKind::TupleStruct(ref path, pat, None) = arm.pat.kind; + if let PatKind::TupleStruct(ref path, pat, ddpos) = arm.pat.kind; + if ddpos.as_opt_usize().is_none(); if is_lang_ctor(cx, path, ResultOk); if let PatKind::Binding(_, hir_id, _, None) = pat[0].kind; if path_to_local_id(arm.body, hir_id); From ef8b49f61f703dfb93b963a40551024c37aa7743 Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Sun, 26 Jun 2022 15:40:45 -0400 Subject: [PATCH 0604/1222] Remove ReEmpty --- clippy_lints/src/needless_pass_by_value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 6d17c7a7346f..060037ed4969 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -173,7 +173,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { ( preds.iter().any(|t| cx.tcx.is_diagnostic_item(sym::Borrow, t.def_id())), !preds.is_empty() && { - let ty_empty_region = cx.tcx.mk_imm_ref(cx.tcx.lifetimes.re_root_empty, ty); + let ty_empty_region = cx.tcx.mk_imm_ref(cx.tcx.lifetimes.re_erased, ty); preds.iter().all(|t| { let ty_params = t.trait_ref.substs.iter().skip(1).collect::>(); implements_trait(cx, ty_empty_region, t.def_id(), &ty_params) From 0f6915206b341dc04d9c50fe01f2b60c38213e66 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 31 Aug 2022 05:29:36 +0000 Subject: [PATCH 0605/1222] Make clippy happy --- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/missing_doc.rs | 3 ++- clippy_lints/src/missing_inline.rs | 1 + clippy_utils/src/hir_utils.rs | 3 +++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index d1ab7fb67962..09a073f4234d 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -959,7 +959,7 @@ fn binding_ty_auto_deref_stability<'tcx>( )) .is_sized(cx.tcx.at(DUMMY_SP), cx.param_env.without_caller_bounds()), ), - TyKind::OpaqueDef(..) | TyKind::Infer | TyKind::Typeof(..) | TyKind::TraitObject(..) | TyKind::Err => { + TyKind::OpaqueDef(..) | TyKind::ImplTraitInTrait(..) | TyKind::Infer | TyKind::Typeof(..) | TyKind::TraitObject(..) | TyKind::Err => { Position::ReborrowStable(precedence) }, }; diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 3701fdb4adbf..9f518c7aaa39 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -147,7 +147,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { | hir::ItemKind::TraitAlias(..) | hir::ItemKind::TyAlias(..) | hir::ItemKind::Union(..) - | hir::ItemKind::OpaqueTy(..) => {}, + | hir::ItemKind::OpaqueTy(..) + | hir::ItemKind::ImplTraitPlaceholder(..) => {}, hir::ItemKind::ExternCrate(..) | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::GlobalAsm(..) diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 07bc2ca5d3cd..9fd1a475d749 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -128,6 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { | hir::ItemKind::TyAlias(..) | hir::ItemKind::Union(..) | hir::ItemKind::OpaqueTy(..) + | hir::ItemKind::ImplTraitPlaceholder(..) | hir::ItemKind::ExternCrate(..) | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::Impl { .. } diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index ff23ed5fffa3..9f8500d41a85 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -990,6 +990,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { TyKind::OpaqueDef(_, arg_list) => { self.hash_generic_args(arg_list); }, + TyKind::ImplTraitInTrait(_) => { + // Do nothing + } TyKind::TraitObject(_, lifetime, _) => { self.hash_lifetime(*lifetime); }, From d0ee5dfa772c2f22f97de70a558b252200e19174 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 6 Sep 2022 17:27:47 +0000 Subject: [PATCH 0606/1222] Appease clippy again --- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/manual_async_fn.rs | 2 +- clippy_lints/src/missing_doc.rs | 3 +-- clippy_lints/src/missing_inline.rs | 1 - clippy_utils/src/hir_utils.rs | 6 ++---- 6 files changed, 6 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 09a073f4234d..d1ab7fb67962 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -959,7 +959,7 @@ fn binding_ty_auto_deref_stability<'tcx>( )) .is_sized(cx.tcx.at(DUMMY_SP), cx.param_env.without_caller_bounds()), ), - TyKind::OpaqueDef(..) | TyKind::ImplTraitInTrait(..) | TyKind::Infer | TyKind::Typeof(..) | TyKind::TraitObject(..) | TyKind::Err => { + TyKind::OpaqueDef(..) | TyKind::Infer | TyKind::Typeof(..) | TyKind::TraitObject(..) | TyKind::Err => { Position::ReborrowStable(precedence) }, }; diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 573a7c016b8e..5995675bd969 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -441,7 +441,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { fn visit_ty(&mut self, ty: &'tcx Ty<'_>) { match ty.kind { - TyKind::OpaqueDef(item, bounds) => { + TyKind::OpaqueDef(item, bounds, _) => { let map = self.cx.tcx.hir(); let item = map.item(item); let len = self.lts.len(); diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 2502c8f880dd..754b0e78a148 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -103,7 +103,7 @@ fn future_trait_ref<'tcx>( ty: &'tcx Ty<'tcx>, ) -> Option<(&'tcx TraitRef<'tcx>, Vec)> { if_chain! { - if let TyKind::OpaqueDef(item_id, bounds) = ty.kind; + if let TyKind::OpaqueDef(item_id, bounds, false) = ty.kind; let item = cx.tcx.hir().item(item_id); if let ItemKind::OpaqueTy(opaque) = &item.kind; if let Some(trait_ref) = opaque.bounds.iter().find_map(|bound| { diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 9f518c7aaa39..3701fdb4adbf 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -147,8 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { | hir::ItemKind::TraitAlias(..) | hir::ItemKind::TyAlias(..) | hir::ItemKind::Union(..) - | hir::ItemKind::OpaqueTy(..) - | hir::ItemKind::ImplTraitPlaceholder(..) => {}, + | hir::ItemKind::OpaqueTy(..) => {}, hir::ItemKind::ExternCrate(..) | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::GlobalAsm(..) diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 9fd1a475d749..07bc2ca5d3cd 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -128,7 +128,6 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { | hir::ItemKind::TyAlias(..) | hir::ItemKind::Union(..) | hir::ItemKind::OpaqueTy(..) - | hir::ItemKind::ImplTraitPlaceholder(..) | hir::ItemKind::ExternCrate(..) | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::Impl { .. } diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 9f8500d41a85..f45cec9f0b43 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -987,12 +987,10 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } }, TyKind::Path(ref qpath) => self.hash_qpath(qpath), - TyKind::OpaqueDef(_, arg_list) => { + TyKind::OpaqueDef(_, arg_list, in_trait) => { self.hash_generic_args(arg_list); + in_trait.hash(&mut self.s); }, - TyKind::ImplTraitInTrait(_) => { - // Do nothing - } TyKind::TraitObject(_, lifetime, _) => { self.hash_lifetime(*lifetime); }, From 58fdeb675751de4ee234c04d3adad47a4a78dec1 Mon Sep 17 00:00:00 2001 From: Niklas Jonsson Date: Sat, 16 Jul 2022 15:16:57 +0200 Subject: [PATCH 0607/1222] rustc_error, rustc_private, rustc_ast: Switch to stable hash containers --- clippy_lints/src/matches/match_same_arms.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/matches/match_same_arms.rs b/clippy_lints/src/matches/match_same_arms.rs index 93874b103b46..d37f44d4a17e 100644 --- a/clippy_lints/src/matches/match_same_arms.rs +++ b/clippy_lints/src/matches/match_same_arms.rs @@ -8,11 +8,10 @@ use rustc_arena::DroplessArena; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; -use rustc_hir::{Arm, Expr, ExprKind, HirId, HirIdMap, HirIdSet, Pat, PatKind, RangeEnd}; +use rustc_hir::{Arm, Expr, ExprKind, HirId, HirIdMap, HirIdMapEntry, HirIdSet, Pat, PatKind, RangeEnd}; use rustc_lint::LateContext; use rustc_middle::ty; use rustc_span::Symbol; -use std::collections::hash_map::Entry; use super::MATCH_SAME_ARMS; @@ -71,9 +70,9 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) { if let Some(a_id) = path_to_local(a); if let Some(b_id) = path_to_local(b); let entry = match local_map.entry(a_id) { - Entry::Vacant(entry) => entry, + HirIdMapEntry::Vacant(entry) => entry, // check if using the same bindings as before - Entry::Occupied(entry) => return *entry.get() == b_id, + HirIdMapEntry::Occupied(entry) => return *entry.get() == b_id, }; // the names technically don't have to match; this makes the lint more conservative if cx.tcx.hir().name(a_id) == cx.tcx.hir().name(b_id); From b75949e665eca87c0c95c8a89a98a58bdc28e452 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 12 Sep 2022 13:13:22 +1000 Subject: [PATCH 0608/1222] Remove unused span argument from `walk_fn`. --- clippy_lints/src/derive.rs | 4 ++-- clippy_lints/src/unused_async.rs | 2 +- clippy_lints/src/unwrap.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 23c86482b46c..751ca24d5f59 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -425,7 +425,7 @@ struct UnsafeVisitor<'a, 'tcx> { impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> { type NestedFilter = nested_filter::All; - fn visit_fn(&mut self, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body_id: BodyId, span: Span, id: HirId) { + fn visit_fn(&mut self, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body_id: BodyId, _: Span, id: HirId) { if self.has_unsafe { return; } @@ -438,7 +438,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> { } } - walk_fn(self, kind, decl, body_id, span, id); + walk_fn(self, kind, decl, body_id, id); } fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index a832dfcccaf3..bf487c7ca20c 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync { ) { if !span.from_expansion() && fn_kind.asyncness() == IsAsync::Async { let mut visitor = AsyncFnVisitor { cx, found_await: false }; - walk_fn(&mut visitor, fn_kind, fn_decl, body.id(), span, hir_id); + walk_fn(&mut visitor, fn_kind, fn_decl, body.id(), hir_id); if !visitor.found_await { span_lint_and_help( cx, diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 7e451b7b7a41..3ef265580797 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -326,6 +326,6 @@ impl<'tcx> LateLintPass<'tcx> for Unwrap { unwrappables: Vec::new(), }; - walk_fn(&mut v, kind, decl, body.id(), span, fn_id); + walk_fn(&mut v, kind, decl, body.id(), fn_id); } } From a0d059a4dec95cfdcd44ee661f8c72fe0c910350 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 12 Sep 2022 13:30:15 +1000 Subject: [PATCH 0609/1222] Remove unused span argument from `visit_name`. --- clippy_utils/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index bdb858e1f938..23b51ec2d084 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1121,7 +1121,7 @@ pub struct ContainsName { } impl<'tcx> Visitor<'tcx> for ContainsName { - fn visit_name(&mut self, _: Span, name: Symbol) { + fn visit_name(&mut self, name: Symbol) { if self.name == name { self.result = true; } From a203bbc6c509990ba59c05f61cfff69686d07c3c Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 12 Sep 2022 13:37:18 +1000 Subject: [PATCH 0610/1222] Remove unused argument from `visit_poly_trait_ref`. --- clippy_lints/src/disallowed_types.rs | 4 ++-- clippy_lints/src/lifetimes.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/disallowed_types.rs b/clippy_lints/src/disallowed_types.rs index 14f89edce615..28dbfbab2e19 100644 --- a/clippy_lints/src/disallowed_types.rs +++ b/clippy_lints/src/disallowed_types.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use rustc_data_structures::fx::FxHashMap; use rustc_hir::{ - def::Res, def_id::DefId, Item, ItemKind, PolyTraitRef, PrimTy, TraitBoundModifier, Ty, TyKind, UseKind, + def::Res, def_id::DefId, Item, ItemKind, PolyTraitRef, PrimTy, Ty, TyKind, UseKind, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -120,7 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedTypes { } } - fn check_poly_trait_ref(&mut self, cx: &LateContext<'tcx>, poly: &'tcx PolyTraitRef<'tcx>, _: TraitBoundModifier) { + fn check_poly_trait_ref(&mut self, cx: &LateContext<'tcx>, poly: &'tcx PolyTraitRef<'tcx>) { self.check_res_emit(cx, &poly.trait_ref.path.res, poly.trait_ref.path.span); } } diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index f2b6e0b7ef9b..643a7cfd577b 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -10,7 +10,7 @@ use rustc_hir::FnRetTy::Return; use rustc_hir::{ BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl, ImplItem, ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, ParamName, PolyTraitRef, PredicateOrigin, - TraitBoundModifier, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate, + TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter as middle_nested_filter; @@ -422,7 +422,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { self.record(&Some(*lifetime)); } - fn visit_poly_trait_ref(&mut self, poly_tref: &'tcx PolyTraitRef<'tcx>, tbm: TraitBoundModifier) { + fn visit_poly_trait_ref(&mut self, poly_tref: &'tcx PolyTraitRef<'tcx>) { let trait_ref = &poly_tref.trait_ref; if CLOSURE_TRAIT_BOUNDS.iter().any(|&item| { self.cx @@ -435,7 +435,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { sub_visitor.visit_trait_ref(trait_ref); self.nested_elision_site_lts.append(&mut sub_visitor.all_lts()); } else { - walk_poly_trait_ref(self, poly_tref, tbm); + walk_poly_trait_ref(self, poly_tref); } } @@ -466,7 +466,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { self.unelided_trait_object_lifetime = true; } for bound in bounds { - self.visit_poly_trait_ref(bound, TraitBoundModifier::None); + self.visit_poly_trait_ref(bound); } }, _ => walk_ty(self, ty), From 9277d74cab4bc43a310d343dee1e21d90a578969 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 2 Sep 2022 01:11:20 +0200 Subject: [PATCH 0611/1222] Fix clippy. --- .../src/matches/redundant_pattern_match.rs | 81 +++++++++++++++---- 1 file changed, 65 insertions(+), 16 deletions(-) diff --git a/clippy_lints/src/matches/redundant_pattern_match.rs b/clippy_lints/src/matches/redundant_pattern_match.rs index f7443471e31d..39c8e9a93f06 100644 --- a/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/clippy_lints/src/matches/redundant_pattern_match.rs @@ -2,7 +2,7 @@ use super::REDUNDANT_PATTERN_MATCHING; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; use clippy_utils::sugg::Sugg; -use clippy_utils::ty::needs_ordered_drop; +use clippy_utils::ty::{is_type_diagnostic_item, needs_ordered_drop}; use clippy_utils::visitors::any_temporaries_need_ordered_drop; use clippy_utils::{higher, is_lang_ctor, is_trait_method, match_def_path, paths}; use if_chain::if_chain; @@ -12,7 +12,7 @@ use rustc_hir::LangItem::{OptionNone, PollPending}; use rustc_hir::{Arm, Expr, ExprKind, Node, Pat, PatKind, QPath, UnOp}; use rustc_lint::LateContext; use rustc_middle::ty::{self, subst::GenericArgKind, DefIdTree, Ty}; -use rustc_span::sym; +use rustc_span::{sym, Symbol, def_id::DefId}; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let Some(higher::WhileLet { let_pat, let_expr, .. }) = higher::WhileLet::hir(expr) { @@ -75,9 +75,9 @@ fn find_sugg_for_if_let<'tcx>( ("is_some()", op_ty) } else if Some(id) == lang_items.poll_ready_variant() { ("is_ready()", op_ty) - } else if match_def_path(cx, id, &paths::IPADDR_V4) { + } else if is_pat_variant(cx, check_pat, qpath, &paths::IPADDR_V4, Item::Diag(sym!(IpAddr), sym!(V4))) { ("is_ipv4()", op_ty) - } else if match_def_path(cx, id, &paths::IPADDR_V6) { + } else if is_pat_variant(cx, check_pat, qpath, &paths::IPADDR_V6, Item::Diag(sym!(IpAddr), sym!(V6))) { ("is_ipv6()", op_ty) } else { return; @@ -174,6 +174,7 @@ fn find_sugg_for_if_let<'tcx>( pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op: &Expr<'_>, arms: &[Arm<'_>]) { if arms.len() == 2 { + let lang_items = cx.tcx.lang_items(); let node_pair = (&arms[0].pat.kind, &arms[1].pat.kind); let found_good_method = match node_pair { @@ -188,7 +189,9 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op path_left, path_right, &paths::RESULT_OK, + Item::Lang(lang_items.result_ok_variant()), &paths::RESULT_ERR, + Item::Lang(lang_items.result_err_variant()), "is_ok()", "is_err()", ) @@ -199,7 +202,9 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op path_left, path_right, &paths::IPADDR_V4, + Item::Diag(sym!(IpAddr), sym!(V4)), &paths::IPADDR_V6, + Item::Diag(sym!(IpAddr), sym!(V6)), "is_ipv4()", "is_ipv6()", ) @@ -213,13 +218,16 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op if patterns.len() == 1 => { if let PatKind::Wild = patterns[0].kind { + find_good_method_for_match( cx, arms, path_left, path_right, &paths::OPTION_SOME, + Item::Lang(lang_items.option_some_variant()), &paths::OPTION_NONE, + Item::Lang(lang_items.option_none_variant()), "is_some()", "is_none()", ) @@ -230,7 +238,9 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op path_left, path_right, &paths::POLL_READY, + Item::Lang(lang_items.poll_ready_variant()), &paths::POLL_PENDING, + Item::Lang(lang_items.poll_pending_variant()), "is_ready()", "is_pending()", ) @@ -266,28 +276,67 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op } } +#[derive(Clone, Copy)] +enum Item { + Lang(Option), + Diag(Symbol, Symbol), +} + +fn is_pat_variant(cx: &LateContext<'_>, pat: &Pat<'_>, path: &QPath<'_>, expected_path: &[&str], expected_item: Item) -> bool { + let Some(id) = cx.typeck_results().qpath_res(path, pat.hir_id).opt_def_id() else { return false }; + + // TODO: Path matching can be removed when `IpAddr` is a diagnostic item. + if match_def_path(cx, id, expected_path) { + return true + } + + match expected_item { + Item::Lang(expected_id) => { + Some(cx.tcx.parent(id)) == expected_id + }, + Item::Diag(expected_ty, expected_variant) => { + let ty = cx.typeck_results().pat_ty(pat); + + if is_type_diagnostic_item(cx, ty, expected_ty) { + let variant = ty.ty_adt_def() + .expect("struct pattern type is not an ADT") + .variant_of_res(cx.qpath_res(path, pat.hir_id)); + + return variant.name == expected_variant + } + + false + } + } +} + #[expect(clippy::too_many_arguments)] fn find_good_method_for_match<'a>( cx: &LateContext<'_>, arms: &[Arm<'_>], path_left: &QPath<'_>, path_right: &QPath<'_>, - expected_left: &[&str], - expected_right: &[&str], + expected_path_left: &[&str], + expected_item_left: Item, + expected_path_right: &[&str], + expected_item_right: Item, should_be_left: &'a str, should_be_right: &'a str, ) -> Option<&'a str> { - let left_id = cx - .typeck_results() - .qpath_res(path_left, arms[0].pat.hir_id) - .opt_def_id()?; - let right_id = cx - .typeck_results() - .qpath_res(path_right, arms[1].pat.hir_id) - .opt_def_id()?; - let body_node_pair = if match_def_path(cx, left_id, expected_left) && match_def_path(cx, right_id, expected_right) { + let pat_left = arms[0].pat; + let pat_right = arms[1].pat; + + let body_node_pair = if ( + is_pat_variant(cx, pat_left, path_left, expected_path_left, expected_item_left) + ) && ( + is_pat_variant(cx, pat_right, path_right, expected_path_right, expected_item_right) + ) { (&arms[0].body.kind, &arms[1].body.kind) - } else if match_def_path(cx, right_id, expected_left) && match_def_path(cx, right_id, expected_right) { + } else if ( + is_pat_variant(cx, pat_left, path_left, expected_path_right, expected_item_right) + ) && ( + is_pat_variant(cx, pat_right, path_right, expected_path_left, expected_item_left) + ) { (&arms[1].body.kind, &arms[0].body.kind) } else { return None; From f109c61c090bb8d41b98b702353c356ffcd8707d Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 12 Sep 2022 19:03:24 +0200 Subject: [PATCH 0612/1222] Simplify `clippy` fix. --- .../src/matches/redundant_pattern_match.rs | 59 +++++++------------ clippy_utils/src/paths.rs | 2 - 2 files changed, 22 insertions(+), 39 deletions(-) diff --git a/clippy_lints/src/matches/redundant_pattern_match.rs b/clippy_lints/src/matches/redundant_pattern_match.rs index 39c8e9a93f06..c89784065b8b 100644 --- a/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/clippy_lints/src/matches/redundant_pattern_match.rs @@ -4,15 +4,15 @@ use clippy_utils::source::snippet; use clippy_utils::sugg::Sugg; use clippy_utils::ty::{is_type_diagnostic_item, needs_ordered_drop}; use clippy_utils::visitors::any_temporaries_need_ordered_drop; -use clippy_utils::{higher, is_lang_ctor, is_trait_method, match_def_path, paths}; +use clippy_utils::{higher, is_lang_ctor, is_trait_method}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; -use rustc_hir::LangItem::{OptionNone, PollPending}; +use rustc_hir::LangItem::{self, OptionSome, OptionNone, PollPending, PollReady, ResultOk, ResultErr}; use rustc_hir::{Arm, Expr, ExprKind, Node, Pat, PatKind, QPath, UnOp}; use rustc_lint::LateContext; use rustc_middle::ty::{self, subst::GenericArgKind, DefIdTree, Ty}; -use rustc_span::{sym, Symbol, def_id::DefId}; +use rustc_span::{sym, Symbol}; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let Some(higher::WhileLet { let_pat, let_expr, .. }) = higher::WhileLet::hir(expr) { @@ -75,9 +75,9 @@ fn find_sugg_for_if_let<'tcx>( ("is_some()", op_ty) } else if Some(id) == lang_items.poll_ready_variant() { ("is_ready()", op_ty) - } else if is_pat_variant(cx, check_pat, qpath, &paths::IPADDR_V4, Item::Diag(sym!(IpAddr), sym!(V4))) { + } else if is_pat_variant(cx, check_pat, qpath, Item::Diag(sym::IpAddr, sym!(V4))) { ("is_ipv4()", op_ty) - } else if is_pat_variant(cx, check_pat, qpath, &paths::IPADDR_V6, Item::Diag(sym!(IpAddr), sym!(V6))) { + } else if is_pat_variant(cx, check_pat, qpath, Item::Diag(sym::IpAddr, sym!(V6))) { ("is_ipv6()", op_ty) } else { return; @@ -174,7 +174,6 @@ fn find_sugg_for_if_let<'tcx>( pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op: &Expr<'_>, arms: &[Arm<'_>]) { if arms.len() == 2 { - let lang_items = cx.tcx.lang_items(); let node_pair = (&arms[0].pat.kind, &arms[1].pat.kind); let found_good_method = match node_pair { @@ -188,10 +187,8 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op arms, path_left, path_right, - &paths::RESULT_OK, - Item::Lang(lang_items.result_ok_variant()), - &paths::RESULT_ERR, - Item::Lang(lang_items.result_err_variant()), + Item::Lang(ResultOk), + Item::Lang(ResultErr), "is_ok()", "is_err()", ) @@ -201,10 +198,8 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op arms, path_left, path_right, - &paths::IPADDR_V4, - Item::Diag(sym!(IpAddr), sym!(V4)), - &paths::IPADDR_V6, - Item::Diag(sym!(IpAddr), sym!(V6)), + Item::Diag(sym::IpAddr, sym!(V4)), + Item::Diag(sym::IpAddr, sym!(V6)), "is_ipv4()", "is_ipv6()", ) @@ -224,10 +219,8 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op arms, path_left, path_right, - &paths::OPTION_SOME, - Item::Lang(lang_items.option_some_variant()), - &paths::OPTION_NONE, - Item::Lang(lang_items.option_none_variant()), + Item::Lang(OptionSome), + Item::Lang(OptionNone), "is_some()", "is_none()", ) @@ -237,10 +230,8 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op arms, path_left, path_right, - &paths::POLL_READY, - Item::Lang(lang_items.poll_ready_variant()), - &paths::POLL_PENDING, - Item::Lang(lang_items.poll_pending_variant()), + Item::Lang(PollReady), + Item::Lang(PollPending), "is_ready()", "is_pending()", ) @@ -278,21 +269,17 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op #[derive(Clone, Copy)] enum Item { - Lang(Option), + Lang(LangItem), Diag(Symbol, Symbol), } -fn is_pat_variant(cx: &LateContext<'_>, pat: &Pat<'_>, path: &QPath<'_>, expected_path: &[&str], expected_item: Item) -> bool { +fn is_pat_variant(cx: &LateContext<'_>, pat: &Pat<'_>, path: &QPath<'_>, expected_item: Item) -> bool { let Some(id) = cx.typeck_results().qpath_res(path, pat.hir_id).opt_def_id() else { return false }; - // TODO: Path matching can be removed when `IpAddr` is a diagnostic item. - if match_def_path(cx, id, expected_path) { - return true - } - match expected_item { - Item::Lang(expected_id) => { - Some(cx.tcx.parent(id)) == expected_id + Item::Lang(expected_lang_item) => { + let expected_id = cx.tcx.lang_items().require(expected_lang_item).unwrap(); + cx.tcx.parent(id) == expected_id }, Item::Diag(expected_ty, expected_variant) => { let ty = cx.typeck_results().pat_ty(pat); @@ -316,9 +303,7 @@ fn find_good_method_for_match<'a>( arms: &[Arm<'_>], path_left: &QPath<'_>, path_right: &QPath<'_>, - expected_path_left: &[&str], expected_item_left: Item, - expected_path_right: &[&str], expected_item_right: Item, should_be_left: &'a str, should_be_right: &'a str, @@ -327,15 +312,15 @@ fn find_good_method_for_match<'a>( let pat_right = arms[1].pat; let body_node_pair = if ( - is_pat_variant(cx, pat_left, path_left, expected_path_left, expected_item_left) + is_pat_variant(cx, pat_left, path_left, expected_item_left) ) && ( - is_pat_variant(cx, pat_right, path_right, expected_path_right, expected_item_right) + is_pat_variant(cx, pat_right, path_right, expected_item_right) ) { (&arms[0].body.kind, &arms[1].body.kind) } else if ( - is_pat_variant(cx, pat_left, path_left, expected_path_right, expected_item_right) + is_pat_variant(cx, pat_left, path_left, expected_item_right) ) && ( - is_pat_variant(cx, pat_right, path_right, expected_path_left, expected_item_left) + is_pat_variant(cx, pat_right, path_right, expected_item_left) ) { (&arms[1].body.kind, &arms[0].body.kind) } else { diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index fb0d34e02eec..07170e2df12a 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -66,8 +66,6 @@ pub const INDEX_MUT: [&str; 3] = ["core", "ops", "IndexMut"]; pub const INSERT_STR: [&str; 4] = ["alloc", "string", "String", "insert_str"]; pub const IO_READ: [&str; 3] = ["std", "io", "Read"]; pub const IO_WRITE: [&str; 3] = ["std", "io", "Write"]; -pub const IPADDR_V4: [&str; 5] = ["std", "net", "ip", "IpAddr", "V4"]; -pub const IPADDR_V6: [&str; 5] = ["std", "net", "ip", "IpAddr", "V6"]; pub const ITER_COUNT: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "count"]; pub const ITER_EMPTY: [&str; 5] = ["core", "iter", "sources", "empty", "Empty"]; pub const ITER_REPEAT: [&str; 5] = ["core", "iter", "sources", "repeat", "repeat"]; From 0f2e377db2d37e1e157bd3b6ec1d112506726955 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Tue, 30 Aug 2022 12:39:28 -0700 Subject: [PATCH 0613/1222] Make x.py check work --- clippy_lints/src/transmute/utils.rs | 29 ++-- clippy_utils/src/qualify_min_const_fn.rs | 141 +++++++++++-------- clippy_utils/src/ty.rs | 165 ++++++++++++++--------- 3 files changed, 204 insertions(+), 131 deletions(-) diff --git a/clippy_lints/src/transmute/utils.rs b/clippy_lints/src/transmute/utils.rs index 74927570b40e..78cc589cc291 100644 --- a/clippy_lints/src/transmute/utils.rs +++ b/clippy_lints/src/transmute/utils.rs @@ -2,11 +2,18 @@ use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_middle::ty::{cast::CastKind, Ty}; use rustc_span::DUMMY_SP; -use rustc_typeck::check::{cast::CastCheck, FnCtxt, Inherited}; +use rustc_typeck::check::{ + cast::{self, CastCheckResult}, + FnCtxt, Inherited, +}; // check if the component types of the transmuted collection and the result have different ABI, // size or alignment -pub(super) fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<'tcx>) -> bool { +pub(super) fn is_layout_incompatible<'tcx>( + cx: &LateContext<'tcx>, + from: Ty<'tcx>, + to: Ty<'tcx>, +) -> bool { if let Ok(from) = cx.tcx.try_normalize_erasing_regions(cx.param_env, from) && let Ok(to) = cx.tcx.try_normalize_erasing_regions(cx.param_env, to) && let Ok(from_layout) = cx.tcx.layout_of(cx.param_env.and(from)) @@ -29,7 +36,9 @@ pub(super) fn can_be_expressed_as_pointer_cast<'tcx>( from_ty: Ty<'tcx>, to_ty: Ty<'tcx>, ) -> bool { - use CastKind::{AddrPtrCast, ArrayPtrCast, FnPtrAddrCast, FnPtrPtrCast, PtrAddrCast, PtrPtrCast}; + use CastKind::{ + AddrPtrCast, ArrayPtrCast, FnPtrAddrCast, FnPtrPtrCast, PtrAddrCast, PtrPtrCast, + }; matches!( check_cast(cx, e, from_ty, to_ty), Some(PtrPtrCast | PtrAddrCast | AddrPtrCast | ArrayPtrCast | FnPtrPtrCast | FnPtrAddrCast) @@ -40,7 +49,12 @@ pub(super) fn can_be_expressed_as_pointer_cast<'tcx>( /// the cast. In certain cases, including some invalid casts from array references /// to pointers, this may cause additional errors to be emitted and/or ICE error /// messages. This function will panic if that occurs. -fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> Option { +fn check_cast<'tcx>( + cx: &LateContext<'tcx>, + e: &'tcx Expr<'_>, + from_ty: Ty<'tcx>, + to_ty: Ty<'tcx>, +) -> Option { let hir_id = e.hir_id; let local_def_id = hir_id.owner; @@ -48,12 +62,9 @@ fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx> let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, hir_id); // If we already have errors, we can't be sure we can pointer cast. - assert!( - !fn_ctxt.errors_reported_since_creation(), - "Newly created FnCtxt contained errors" - ); + assert!(!fn_ctxt.errors_reported_since_creation(), "Newly created FnCtxt contained errors"); - if let Ok(check) = CastCheck::new( + if let CastCheckResult::Deferred(check) = cast::check_cast( &fn_ctxt, e, from_ty, to_ty, // We won't show any error to the user, so we don't care what the span is here. DUMMY_SP, DUMMY_SP, diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index d5f64e5118f5..781744870cb9 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -18,7 +18,11 @@ use std::borrow::Cow; type McfResult = Result<(), (Span, Cow<'static, str>)>; -pub fn is_min_const_fn<'a, 'tcx>(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: Option) -> McfResult { +pub fn is_min_const_fn<'a, 'tcx>( + tcx: TyCtxt<'tcx>, + body: &'a Body<'tcx>, + msrv: Option, +) -> McfResult { let def_id = body.source.def_id(); let mut current = def_id; loop { @@ -33,10 +37,18 @@ pub fn is_min_const_fn<'a, 'tcx>(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: | ty::PredicateKind::ConstEquate(..) | ty::PredicateKind::Trait(..) | ty::PredicateKind::TypeWellFormedFromEnv(..) => continue, - ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate), - ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate), - ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate), - ty::PredicateKind::Coerce(_) => panic!("coerce predicate on function: {:#?}", predicate), + ty::PredicateKind::ObjectSafe(_) => { + panic!("object safe predicate on function: {:#?}", predicate) + } + ty::PredicateKind::ClosureKind(..) => { + panic!("closure kind predicate on function: {:#?}", predicate) + } + ty::PredicateKind::Subtype(_) => { + panic!("subtype predicate on function: {:#?}", predicate) + } + ty::PredicateKind::Coerce(_) => { + panic!("coerce predicate on function: {:#?}", predicate) + } } } match predicates.parent { @@ -77,22 +89,23 @@ fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult { match ty.kind() { ty::Ref(_, _, hir::Mutability::Mut) => { return Err((span, "mutable references in const fn are unstable".into())); - }, + } ty::Opaque(..) => return Err((span, "`impl Trait` in const fn is unstable".into())), ty::FnPtr(..) => { return Err((span, "function pointers in const fn are unstable".into())); - }, - ty::Dynamic(preds, _) => { + } + ty::Dynamic(preds, _, _) => { for pred in preds.iter() { match pred.skip_binder() { - ty::ExistentialPredicate::AutoTrait(_) | ty::ExistentialPredicate::Projection(_) => { + ty::ExistentialPredicate::AutoTrait(_) + | ty::ExistentialPredicate::Projection(_) => { return Err(( span, "trait bounds other than `Sized` \ on const fn parameters are unstable" .into(), )); - }, + } ty::ExistentialPredicate::Trait(trait_ref) => { if Some(trait_ref.def_id) != tcx.lang_items().sized_trait() { return Err(( @@ -102,11 +115,11 @@ fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult { .into(), )); } - }, + } } } - }, - _ => {}, + } + _ => {} } } Ok(()) @@ -120,10 +133,13 @@ fn check_rvalue<'tcx>( span: Span, ) -> McfResult { match rvalue { - Rvalue::ThreadLocalRef(_) => Err((span, "cannot access thread local storage in const fn".into())), - Rvalue::Len(place) | Rvalue::Discriminant(place) | Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => { - check_place(tcx, *place, span, body) - }, + Rvalue::ThreadLocalRef(_) => { + Err((span, "cannot access thread local storage in const fn".into())) + } + Rvalue::Len(place) + | Rvalue::Discriminant(place) + | Rvalue::Ref(_, _, place) + | Rvalue::AddressOf(_, place) => check_place(tcx, *place, span, body), Rvalue::CopyForDeref(place) => check_place(tcx, *place, span, body), Rvalue::Repeat(operand, _) | Rvalue::Use(operand) @@ -136,7 +152,9 @@ fn check_rvalue<'tcx>( ) => check_operand(tcx, operand, span, body), Rvalue::Cast( CastKind::Pointer( - PointerCast::UnsafeFnPointer | PointerCast::ClosureFnPointer(_) | PointerCast::ReifyFnPointer, + PointerCast::UnsafeFnPointer + | PointerCast::ClosureFnPointer(_) + | PointerCast::ReifyFnPointer, ), _, _, @@ -146,7 +164,10 @@ fn check_rvalue<'tcx>( deref_ty.ty } else { // We cannot allow this for now. - return Err((span, "unsizing casts are only allowed for references right now".into())); + return Err(( + span, + "unsizing casts are only allowed for references right now".into(), + )); }; let unsized_ty = tcx.struct_tail_erasing_lifetimes(pointee_ty, tcx.param_env(def_id)); if let ty::Slice(_) | ty::Str = unsized_ty.kind() { @@ -157,10 +178,14 @@ fn check_rvalue<'tcx>( // We just can't allow trait objects until we have figured out trait method calls. Err((span, "unsizing casts are not allowed in const fn".into())) } - }, + } Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => { Err((span, "casting pointers to ints is unstable in const fn".into())) - }, + } + Rvalue::Cast(CastKind::DynStar, _, _) => { + // FIXME(dyn-star) + unimplemented!() + } // binops are fine on integers Rvalue::BinaryOp(_, box (lhs, rhs)) | Rvalue::CheckedBinaryOp(_, box (lhs, rhs)) => { check_operand(tcx, lhs, span, body)?; @@ -169,13 +194,12 @@ fn check_rvalue<'tcx>( if ty.is_integral() || ty.is_bool() || ty.is_char() { Ok(()) } else { - Err(( - span, - "only int, `bool` and `char` operations are stable in const fn".into(), - )) + Err((span, "only int, `bool` and `char` operations are stable in const fn".into())) } - }, - Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) | Rvalue::ShallowInitBox(_, _) => Ok(()), + } + Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) | Rvalue::ShallowInitBox(_, _) => { + Ok(()) + } Rvalue::UnaryOp(_, operand) => { let ty = operand.ty(body, tcx); if ty.is_integral() || ty.is_bool() { @@ -183,13 +207,13 @@ fn check_rvalue<'tcx>( } else { Err((span, "only int and `bool` operations are stable in const fn".into())) } - }, + } Rvalue::Aggregate(_, operands) => { for operand in operands { check_operand(tcx, operand, span, body)?; } Ok(()) - }, + } } } @@ -204,7 +228,7 @@ fn check_statement<'tcx>( StatementKind::Assign(box (place, rval)) => { check_place(tcx, *place, span, body)?; check_rvalue(tcx, body, def_id, rval, span) - }, + } StatementKind::FakeRead(box (_, place)) => check_place(tcx, *place, span, body), // just an assignment @@ -214,14 +238,15 @@ fn check_statement<'tcx>( StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(op)) => check_operand(tcx, op, span, body), - StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping( - rustc_middle::mir::CopyNonOverlapping { dst, src, count }, - )) => { + StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping { + dst, + src, + count, + }) => { check_operand(tcx, dst, span, body)?; check_operand(tcx, src, span, body)?; check_operand(tcx, count, span, body) - }, - + } // These are all NOPs StatementKind::StorageLive(_) | StatementKind::StorageDead(_) @@ -232,7 +257,12 @@ fn check_statement<'tcx>( } } -fn check_operand<'tcx>(tcx: TyCtxt<'tcx>, operand: &Operand<'tcx>, span: Span, body: &Body<'tcx>) -> McfResult { +fn check_operand<'tcx>( + tcx: TyCtxt<'tcx>, + operand: &Operand<'tcx>, + span: Span, + body: &Body<'tcx>, +) -> McfResult { match operand { Operand::Move(place) | Operand::Copy(place) => check_place(tcx, *place, span, body), Operand::Constant(c) => match c.check_static_ptr(tcx) { @@ -242,7 +272,12 @@ fn check_operand<'tcx>(tcx: TyCtxt<'tcx>, operand: &Operand<'tcx>, span: Span, b } } -fn check_place<'tcx>(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &Body<'tcx>) -> McfResult { +fn check_place<'tcx>( + tcx: TyCtxt<'tcx>, + place: Place<'tcx>, + span: Span, + body: &Body<'tcx>, +) -> McfResult { let mut cursor = place.projection.as_ref(); while let [ref proj_base @ .., elem] = *cursor { cursor = proj_base; @@ -255,12 +290,12 @@ fn check_place<'tcx>(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &B return Err((span, "accessing union fields is unstable".into())); } } - }, + } ProjectionElem::ConstantIndex { .. } | ProjectionElem::Downcast(..) | ProjectionElem::Subslice { .. } | ProjectionElem::Deref - | ProjectionElem::Index(_) => {}, + | ProjectionElem::Index(_) => {} } } @@ -286,18 +321,16 @@ fn check_terminator<'a, 'tcx>( TerminatorKind::DropAndReplace { place, value, .. } => { check_place(tcx, *place, span, body)?; check_operand(tcx, value, span, body) - }, + } - TerminatorKind::SwitchInt { - discr, - switch_ty: _, - targets: _, - } => check_operand(tcx, discr, span, body), + TerminatorKind::SwitchInt { discr, switch_ty: _, targets: _ } => { + check_operand(tcx, discr, span, body) + } TerminatorKind::Abort => Err((span, "abort is not stable in const fn".into())), TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => { Err((span, "const fn generators are unstable".into())) - }, + } TerminatorKind::Call { func, @@ -342,17 +375,15 @@ fn check_terminator<'a, 'tcx>( } else { Err((span, "can only call other const fns within const fn".into())) } - }, + } - TerminatorKind::Assert { - cond, - expected: _, - msg: _, - target: _, - cleanup: _, - } => check_operand(tcx, cond, span, body), + TerminatorKind::Assert { cond, expected: _, msg: _, target: _, cleanup: _ } => { + check_operand(tcx, cond, span, body) + } - TerminatorKind::InlineAsm { .. } => Err((span, "cannot use inline assembly in const fn".into())), + TerminatorKind::InlineAsm { .. } => { + Err((span, "cannot use inline assembly in const fn".into())) + } } } diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 5a7f9568441c..99803ae93a71 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -14,8 +14,9 @@ use rustc_lint::LateContext; use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst}; use rustc_middle::ty::{ - self, AdtDef, Binder, BoundRegion, DefIdTree, FnSig, IntTy, ParamEnv, Predicate, PredicateKind, ProjectionTy, - Region, RegionKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy, VariantDef, VariantDiscr, + self, AdtDef, Binder, BoundRegion, DefIdTree, FnSig, IntTy, ParamEnv, Predicate, PredicateKind, + ProjectionTy, Region, RegionKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, + UintTy, VariantDef, VariantDiscr, }; use rustc_span::symbol::Ident; use rustc_span::{sym, Span, Symbol, DUMMY_SP}; @@ -166,9 +167,7 @@ pub fn implements_trait_with_env<'tcx>( } let ty_params = tcx.mk_substs(ty_params.iter()); tcx.infer_ctxt().enter(|infcx| { - infcx - .type_implements_trait(trait_id, ty, ty_params, param_env) - .must_apply_modulo_regions() + infcx.type_implements_trait(trait_id, ty, ty_params, param_env).must_apply_modulo_regions() }) } @@ -185,11 +184,14 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { match ty.kind() { ty::Adt(adt, _) => cx.tcx.has_attr(adt.did(), sym::must_use), ty::Foreign(did) => cx.tcx.has_attr(*did, sym::must_use), - ty::Slice(ty) | ty::Array(ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) | ty::Ref(_, ty, _) => { + ty::Slice(ty) + | ty::Array(ty, _) + | ty::RawPtr(ty::TypeAndMut { ty, .. }) + | ty::Ref(_, ty, _) => { // for the Array case we don't need to care for the len == 0 case // because we don't want to lint functions returning empty arrays is_must_use_ty(cx, *ty) - }, + } ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(def_id, _) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { @@ -200,8 +202,8 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { } } false - }, - ty::Dynamic(binder, _) => { + } + ty::Dynamic(binder, _, _) => { for predicate in binder.iter() { if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() { if cx.tcx.has_attr(trait_ref.def_id, sym::must_use) { @@ -210,7 +212,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { } } false - }, + } _ => false, } } @@ -220,7 +222,11 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { // not succeed /// Checks if `Ty` is normalizable. This function is useful /// to avoid crashes on `layout_of`. -pub fn is_normalizable<'tcx>(cx: &LateContext<'tcx>, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool { +pub fn is_normalizable<'tcx>( + cx: &LateContext<'tcx>, + param_env: ty::ParamEnv<'tcx>, + ty: Ty<'tcx>, +) -> bool { is_normalizable_helper(cx, param_env, ty, &mut FxHashMap::default()) } @@ -240,15 +246,14 @@ fn is_normalizable_helper<'tcx>( if infcx.at(&cause, param_env).normalize(ty).is_ok() { match ty.kind() { ty::Adt(def, substs) => def.variants().iter().all(|variant| { - variant - .fields - .iter() - .all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache)) + variant.fields.iter().all(|field| { + is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache) + }) }), _ => ty.walk().all(|generic_arg| match generic_arg.unpack() { GenericArgKind::Type(inner_ty) if inner_ty != ty => { is_normalizable_helper(cx, param_env, inner_ty, cache) - }, + } _ => true, // if inner_ty == ty, we've already checked it }), } @@ -273,7 +278,9 @@ pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool { match *ty.kind() { ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => true, ty::Ref(_, inner, _) if *inner.kind() == ty::Str => true, - ty::Array(inner_type, _) | ty::Slice(inner_type) => is_recursively_primitive_type(inner_type), + ty::Array(inner_type, _) | ty::Slice(inner_type) => { + is_recursively_primitive_type(inner_type) + } ty::Tuple(inner_types) => inner_types.iter().all(is_recursively_primitive_type), _ => false, } @@ -313,11 +320,9 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symb /// Returns `false` if the `LangItem` is not defined. pub fn is_type_lang_item(cx: &LateContext<'_>, ty: Ty<'_>, lang_item: hir::LangItem) -> bool { match ty.kind() { - ty::Adt(adt, _) => cx - .tcx - .lang_items() - .require(lang_item) - .map_or(false, |li| li == adt.did()), + ty::Adt(adt, _) => { + cx.tcx.lang_items().require(lang_item).map_or(false, |li| li == adt.did()) + } _ => false, } } @@ -342,7 +347,11 @@ pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool { /// deallocate memory. For these types, and composites containing them, changing the drop order /// won't result in any observable side effects. pub fn needs_ordered_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { - fn needs_ordered_drop_inner<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, seen: &mut FxHashSet>) -> bool { + fn needs_ordered_drop_inner<'tcx>( + cx: &LateContext<'tcx>, + ty: Ty<'tcx>, + seen: &mut FxHashSet>, + ) -> bool { if !seen.insert(ty) { return false; } @@ -393,11 +402,7 @@ pub fn needs_ordered_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { /// removed. pub fn peel_mid_ty_refs(ty: Ty<'_>) -> (Ty<'_>, usize) { fn peel(ty: Ty<'_>, count: usize) -> (Ty<'_>, usize) { - if let ty::Ref(_, ty, _) = ty.kind() { - peel(*ty, count + 1) - } else { - (ty, count) - } + if let ty::Ref(_, ty, _) = ty.kind() { peel(*ty, count + 1) } else { (ty, count) } } peel(ty, 0) } @@ -452,17 +457,18 @@ pub fn same_type_and_consts<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool { return false; } - substs_a - .iter() - .zip(substs_b.iter()) - .all(|(arg_a, arg_b)| match (arg_a.unpack(), arg_b.unpack()) { - (GenericArgKind::Const(inner_a), GenericArgKind::Const(inner_b)) => inner_a == inner_b, + substs_a.iter().zip(substs_b.iter()).all(|(arg_a, arg_b)| { + match (arg_a.unpack(), arg_b.unpack()) { + (GenericArgKind::Const(inner_a), GenericArgKind::Const(inner_b)) => { + inner_a == inner_b + } (GenericArgKind::Type(type_a), GenericArgKind::Type(type_b)) => { same_type_and_consts(type_a, type_b) - }, + } _ => true, - }) - }, + } + }) + } _ => a == b, } } @@ -478,7 +484,10 @@ pub fn is_uninit_value_valid_for_ty(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { } /// Gets an iterator over all predicates which apply to the given item. -pub fn all_predicates_of(tcx: TyCtxt<'_>, id: DefId) -> impl Iterator, Span)> { +pub fn all_predicates_of( + tcx: TyCtxt<'_>, + id: DefId, +) -> impl Iterator, Span)> { let mut next_id = Some(id); iter::from_fn(move || { next_id.take().map(|id| { @@ -508,7 +517,7 @@ impl<'tcx> ExprFnSig<'tcx> { } else { Some(sig.input(i)) } - }, + } Self::Closure(_, sig) => Some(sig.input(0).map_bound(|ty| ty.tuple_fields()[i])), Self::Trait(inputs, _, _) => Some(inputs.map_bound(|ty| ty.tuple_fields()[i])), } @@ -517,7 +526,10 @@ impl<'tcx> ExprFnSig<'tcx> { /// Gets the argument type at the given offset. For closures this will also get the type as /// written. This will return `None` when the index is out of bounds only for variadic /// functions, otherwise this will panic. - pub fn input_with_hir(self, i: usize) -> Option<(Option<&'tcx hir::Ty<'tcx>>, Binder<'tcx, Ty<'tcx>>)> { + pub fn input_with_hir( + self, + i: usize, + ) -> Option<(Option<&'tcx hir::Ty<'tcx>>, Binder<'tcx, Ty<'tcx>>)> { match self { Self::Sig(sig, _) => { if sig.c_variadic() { @@ -528,7 +540,7 @@ impl<'tcx> ExprFnSig<'tcx> { } else { Some((None, sig.input(i))) } - }, + } Self::Closure(decl, sig) => Some(( decl.and_then(|decl| decl.inputs.get(i)), sig.input(0).map_bound(|ty| ty.tuple_fields()[i]), @@ -547,17 +559,15 @@ impl<'tcx> ExprFnSig<'tcx> { } pub fn predicates_id(&self) -> Option { - if let ExprFnSig::Sig(_, id) | ExprFnSig::Trait(_, _, id) = *self { - id - } else { - None - } + if let ExprFnSig::Sig(_, id) | ExprFnSig::Trait(_, _, id) = *self { id } else { None } } } /// If the expression is function like, get the signature for it. pub fn expr_sig<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option> { - if let Res::Def(DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn) | DefKind::AssocFn, id) = path_res(cx, expr) { + if let Res::Def(DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn) | DefKind::AssocFn, id) = + path_res(cx, expr) + { Some(ExprFnSig::Sig(cx.tcx.fn_sig(id), Some(id))) } else { ty_sig(cx, cx.typeck_results().expr_ty_adjusted(expr).peel_refs()) @@ -571,15 +581,17 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option { - let decl = id - .as_local() - .and_then(|id| cx.tcx.hir().fn_decl_by_hir_id(cx.tcx.hir().local_def_id_to_hir_id(id))); + let decl = id.as_local().and_then(|id| { + cx.tcx.hir().fn_decl_by_hir_id(cx.tcx.hir().local_def_id_to_hir_id(id)) + }); Some(ExprFnSig::Closure(decl, subs.as_closure().sig())) - }, - ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))), + } + ty::FnDef(id, subs) => { + Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))) + } ty::Opaque(id, _) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(id), cx.tcx.opt_parent(id)), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), - ty::Dynamic(bounds, _) => { + ty::Dynamic(bounds, _, _) => { let lang_items = cx.tcx.lang_items(); match bounds.principal() { Some(bound) @@ -589,16 +601,19 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option None, } - }, + } ty::Projection(proj) => match cx.tcx.try_normalize_erasing_regions(cx.param_env, ty) { Ok(normalized_ty) if normalized_ty != ty => ty_sig(cx, normalized_ty), - _ => sig_for_projection(cx, proj).or_else(|| sig_from_bounds(cx, ty, cx.param_env.caller_bounds(), None)), + _ => sig_for_projection(cx, proj) + .or_else(|| sig_from_bounds(cx, ty, cx.param_env.caller_bounds(), None)), }, ty::Param(_) => sig_from_bounds(cx, ty, cx.param_env.caller_bounds(), None), _ => None, @@ -629,7 +644,7 @@ fn sig_from_bounds<'tcx>( return None; } inputs = Some(i); - }, + } PredicateKind::Projection(p) if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() && p.projection_ty.self_ty() == ty => @@ -639,7 +654,7 @@ fn sig_from_bounds<'tcx>( return None; } output = Some(pred.kind().rebind(p.term.ty().unwrap())); - }, + } _ => (), } } @@ -647,7 +662,10 @@ fn sig_from_bounds<'tcx>( inputs.map(|ty| ExprFnSig::Trait(ty, output, predicates_id)) } -fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> Option> { +fn sig_for_projection<'tcx>( + cx: &LateContext<'tcx>, + ty: ProjectionTy<'tcx>, +) -> Option> { let mut inputs = None; let mut output = None; let lang_items = cx.tcx.lang_items(); @@ -673,8 +691,10 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O return None; } inputs = Some(i); - }, - PredicateKind::Projection(p) if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() => { + } + PredicateKind::Projection(p) + if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() => + { if output.is_some() { // Multiple different fn trait impls. Is this even allowed? return None; @@ -683,7 +703,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O pred.map_bound(|pred| pred.kind().rebind(p.term.ty().unwrap())) .subst(cx.tcx, ty.substs), ); - }, + } _ => (), } } @@ -777,7 +797,10 @@ pub fn for_each_top_level_late_bound_region( ControlFlow::Continue(()) } } - fn visit_binder>(&mut self, t: &Binder<'tcx, T>) -> ControlFlow { + fn visit_binder>( + &mut self, + t: &Binder<'tcx, T>, + ) -> ControlFlow { self.index += 1; let res = t.super_visit_with(self); self.index -= 1; @@ -791,19 +814,27 @@ pub fn for_each_top_level_late_bound_region( pub fn variant_of_res<'tcx>(cx: &LateContext<'tcx>, res: Res) -> Option<&'tcx VariantDef> { match res { Res::Def(DefKind::Struct, id) => Some(cx.tcx.adt_def(id).non_enum_variant()), - Res::Def(DefKind::Variant, id) => Some(cx.tcx.adt_def(cx.tcx.parent(id)).variant_with_id(id)), - Res::Def(DefKind::Ctor(CtorOf::Struct, _), id) => Some(cx.tcx.adt_def(cx.tcx.parent(id)).non_enum_variant()), + Res::Def(DefKind::Variant, id) => { + Some(cx.tcx.adt_def(cx.tcx.parent(id)).variant_with_id(id)) + } + Res::Def(DefKind::Ctor(CtorOf::Struct, _), id) => { + Some(cx.tcx.adt_def(cx.tcx.parent(id)).non_enum_variant()) + } Res::Def(DefKind::Ctor(CtorOf::Variant, _), id) => { let var_id = cx.tcx.parent(id); Some(cx.tcx.adt_def(cx.tcx.parent(var_id)).variant_with_id(var_id)) - }, + } Res::SelfCtor(id) => Some(cx.tcx.type_of(id).ty_adt_def().unwrap().non_enum_variant()), _ => None, } } /// Checks if the type is a type parameter implementing `FnOnce`, but not `FnMut`. -pub fn ty_is_fn_once_param<'tcx>(tcx: TyCtxt<'_>, ty: Ty<'tcx>, predicates: &'tcx [Predicate<'_>]) -> bool { +pub fn ty_is_fn_once_param<'tcx>( + tcx: TyCtxt<'_>, + ty: Ty<'tcx>, + predicates: &'tcx [Predicate<'_>], +) -> bool { let ty::Param(ty) = *ty.kind() else { return false; }; From 3b489e2682cf60989c001d03e5eefe500f58a293 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Tue, 30 Aug 2022 12:44:00 -0700 Subject: [PATCH 0614/1222] Address code review comments --- clippy_lints/src/transmute/utils.rs | 27 ++-- clippy_utils/src/qualify_min_const_fn.rs | 136 ++++++++----------- clippy_utils/src/ty.rs | 161 +++++++++-------------- 3 files changed, 127 insertions(+), 197 deletions(-) diff --git a/clippy_lints/src/transmute/utils.rs b/clippy_lints/src/transmute/utils.rs index 78cc589cc291..8bdadf244023 100644 --- a/clippy_lints/src/transmute/utils.rs +++ b/clippy_lints/src/transmute/utils.rs @@ -2,18 +2,11 @@ use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_middle::ty::{cast::CastKind, Ty}; use rustc_span::DUMMY_SP; -use rustc_typeck::check::{ - cast::{self, CastCheckResult}, - FnCtxt, Inherited, -}; +use rustc_typeck::check::{cast::{self, CastCheckResult}, FnCtxt, Inherited}; // check if the component types of the transmuted collection and the result have different ABI, // size or alignment -pub(super) fn is_layout_incompatible<'tcx>( - cx: &LateContext<'tcx>, - from: Ty<'tcx>, - to: Ty<'tcx>, -) -> bool { +pub(super) fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<'tcx>) -> bool { if let Ok(from) = cx.tcx.try_normalize_erasing_regions(cx.param_env, from) && let Ok(to) = cx.tcx.try_normalize_erasing_regions(cx.param_env, to) && let Ok(from_layout) = cx.tcx.layout_of(cx.param_env.and(from)) @@ -36,9 +29,7 @@ pub(super) fn can_be_expressed_as_pointer_cast<'tcx>( from_ty: Ty<'tcx>, to_ty: Ty<'tcx>, ) -> bool { - use CastKind::{ - AddrPtrCast, ArrayPtrCast, FnPtrAddrCast, FnPtrPtrCast, PtrAddrCast, PtrPtrCast, - }; + use CastKind::{AddrPtrCast, ArrayPtrCast, FnPtrAddrCast, FnPtrPtrCast, PtrAddrCast, PtrPtrCast}; matches!( check_cast(cx, e, from_ty, to_ty), Some(PtrPtrCast | PtrAddrCast | AddrPtrCast | ArrayPtrCast | FnPtrPtrCast | FnPtrAddrCast) @@ -49,12 +40,7 @@ pub(super) fn can_be_expressed_as_pointer_cast<'tcx>( /// the cast. In certain cases, including some invalid casts from array references /// to pointers, this may cause additional errors to be emitted and/or ICE error /// messages. This function will panic if that occurs. -fn check_cast<'tcx>( - cx: &LateContext<'tcx>, - e: &'tcx Expr<'_>, - from_ty: Ty<'tcx>, - to_ty: Ty<'tcx>, -) -> Option { +fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> Option { let hir_id = e.hir_id; let local_def_id = hir_id.owner; @@ -62,7 +48,10 @@ fn check_cast<'tcx>( let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, hir_id); // If we already have errors, we can't be sure we can pointer cast. - assert!(!fn_ctxt.errors_reported_since_creation(), "Newly created FnCtxt contained errors"); + assert!( + !fn_ctxt.errors_reported_since_creation(), + "Newly created FnCtxt contained errors" + ); if let CastCheckResult::Deferred(check) = cast::check_cast( &fn_ctxt, e, from_ty, to_ty, diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 781744870cb9..8835b9329095 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -18,11 +18,7 @@ use std::borrow::Cow; type McfResult = Result<(), (Span, Cow<'static, str>)>; -pub fn is_min_const_fn<'a, 'tcx>( - tcx: TyCtxt<'tcx>, - body: &'a Body<'tcx>, - msrv: Option, -) -> McfResult { +pub fn is_min_const_fn<'a, 'tcx>(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: Option) -> McfResult { let def_id = body.source.def_id(); let mut current = def_id; loop { @@ -37,18 +33,10 @@ pub fn is_min_const_fn<'a, 'tcx>( | ty::PredicateKind::ConstEquate(..) | ty::PredicateKind::Trait(..) | ty::PredicateKind::TypeWellFormedFromEnv(..) => continue, - ty::PredicateKind::ObjectSafe(_) => { - panic!("object safe predicate on function: {:#?}", predicate) - } - ty::PredicateKind::ClosureKind(..) => { - panic!("closure kind predicate on function: {:#?}", predicate) - } - ty::PredicateKind::Subtype(_) => { - panic!("subtype predicate on function: {:#?}", predicate) - } - ty::PredicateKind::Coerce(_) => { - panic!("coerce predicate on function: {:#?}", predicate) - } + ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate), + ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate), + ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate), + ty::PredicateKind::Coerce(_) => panic!("coerce predicate on function: {:#?}", predicate), } } match predicates.parent { @@ -89,23 +77,22 @@ fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult { match ty.kind() { ty::Ref(_, _, hir::Mutability::Mut) => { return Err((span, "mutable references in const fn are unstable".into())); - } + }, ty::Opaque(..) => return Err((span, "`impl Trait` in const fn is unstable".into())), ty::FnPtr(..) => { return Err((span, "function pointers in const fn are unstable".into())); - } + }, ty::Dynamic(preds, _, _) => { for pred in preds.iter() { match pred.skip_binder() { - ty::ExistentialPredicate::AutoTrait(_) - | ty::ExistentialPredicate::Projection(_) => { + ty::ExistentialPredicate::AutoTrait(_) | ty::ExistentialPredicate::Projection(_) => { return Err(( span, "trait bounds other than `Sized` \ on const fn parameters are unstable" .into(), )); - } + }, ty::ExistentialPredicate::Trait(trait_ref) => { if Some(trait_ref.def_id) != tcx.lang_items().sized_trait() { return Err(( @@ -115,11 +102,11 @@ fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult { .into(), )); } - } + }, } } - } - _ => {} + }, + _ => {}, } } Ok(()) @@ -133,13 +120,10 @@ fn check_rvalue<'tcx>( span: Span, ) -> McfResult { match rvalue { - Rvalue::ThreadLocalRef(_) => { - Err((span, "cannot access thread local storage in const fn".into())) - } - Rvalue::Len(place) - | Rvalue::Discriminant(place) - | Rvalue::Ref(_, _, place) - | Rvalue::AddressOf(_, place) => check_place(tcx, *place, span, body), + Rvalue::ThreadLocalRef(_) => Err((span, "cannot access thread local storage in const fn".into())), + Rvalue::Len(place) | Rvalue::Discriminant(place) | Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => { + check_place(tcx, *place, span, body) + }, Rvalue::CopyForDeref(place) => check_place(tcx, *place, span, body), Rvalue::Repeat(operand, _) | Rvalue::Use(operand) @@ -152,9 +136,7 @@ fn check_rvalue<'tcx>( ) => check_operand(tcx, operand, span, body), Rvalue::Cast( CastKind::Pointer( - PointerCast::UnsafeFnPointer - | PointerCast::ClosureFnPointer(_) - | PointerCast::ReifyFnPointer, + PointerCast::UnsafeFnPointer | PointerCast::ClosureFnPointer(_) | PointerCast::ReifyFnPointer, ), _, _, @@ -164,10 +146,7 @@ fn check_rvalue<'tcx>( deref_ty.ty } else { // We cannot allow this for now. - return Err(( - span, - "unsizing casts are only allowed for references right now".into(), - )); + return Err((span, "unsizing casts are only allowed for references right now".into())); }; let unsized_ty = tcx.struct_tail_erasing_lifetimes(pointee_ty, tcx.param_env(def_id)); if let ty::Slice(_) | ty::Str = unsized_ty.kind() { @@ -178,14 +157,14 @@ fn check_rvalue<'tcx>( // We just can't allow trait objects until we have figured out trait method calls. Err((span, "unsizing casts are not allowed in const fn".into())) } - } + }, Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => { Err((span, "casting pointers to ints is unstable in const fn".into())) - } + }, Rvalue::Cast(CastKind::DynStar, _, _) => { // FIXME(dyn-star) unimplemented!() - } + }, // binops are fine on integers Rvalue::BinaryOp(_, box (lhs, rhs)) | Rvalue::CheckedBinaryOp(_, box (lhs, rhs)) => { check_operand(tcx, lhs, span, body)?; @@ -194,12 +173,13 @@ fn check_rvalue<'tcx>( if ty.is_integral() || ty.is_bool() || ty.is_char() { Ok(()) } else { - Err((span, "only int, `bool` and `char` operations are stable in const fn".into())) + Err(( + span, + "only int, `bool` and `char` operations are stable in const fn".into(), + )) } - } - Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) | Rvalue::ShallowInitBox(_, _) => { - Ok(()) - } + }, + Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) | Rvalue::ShallowInitBox(_, _) => Ok(()), Rvalue::UnaryOp(_, operand) => { let ty = operand.ty(body, tcx); if ty.is_integral() || ty.is_bool() { @@ -207,13 +187,13 @@ fn check_rvalue<'tcx>( } else { Err((span, "only int and `bool` operations are stable in const fn".into())) } - } + }, Rvalue::Aggregate(_, operands) => { for operand in operands { check_operand(tcx, operand, span, body)?; } Ok(()) - } + }, } } @@ -228,7 +208,7 @@ fn check_statement<'tcx>( StatementKind::Assign(box (place, rval)) => { check_place(tcx, *place, span, body)?; check_rvalue(tcx, body, def_id, rval, span) - } + }, StatementKind::FakeRead(box (_, place)) => check_place(tcx, *place, span, body), // just an assignment @@ -238,15 +218,13 @@ fn check_statement<'tcx>( StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(op)) => check_operand(tcx, op, span, body), - StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping { - dst, - src, - count, - }) => { + StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping( + rustc_middle::mir::CopyNonOverlapping { dst, src, count }, + )) => { check_operand(tcx, dst, span, body)?; check_operand(tcx, src, span, body)?; check_operand(tcx, count, span, body) - } + }, // These are all NOPs StatementKind::StorageLive(_) | StatementKind::StorageDead(_) @@ -257,12 +235,7 @@ fn check_statement<'tcx>( } } -fn check_operand<'tcx>( - tcx: TyCtxt<'tcx>, - operand: &Operand<'tcx>, - span: Span, - body: &Body<'tcx>, -) -> McfResult { +fn check_operand<'tcx>(tcx: TyCtxt<'tcx>, operand: &Operand<'tcx>, span: Span, body: &Body<'tcx>) -> McfResult { match operand { Operand::Move(place) | Operand::Copy(place) => check_place(tcx, *place, span, body), Operand::Constant(c) => match c.check_static_ptr(tcx) { @@ -272,12 +245,7 @@ fn check_operand<'tcx>( } } -fn check_place<'tcx>( - tcx: TyCtxt<'tcx>, - place: Place<'tcx>, - span: Span, - body: &Body<'tcx>, -) -> McfResult { +fn check_place<'tcx>(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &Body<'tcx>) -> McfResult { let mut cursor = place.projection.as_ref(); while let [ref proj_base @ .., elem] = *cursor { cursor = proj_base; @@ -290,12 +258,12 @@ fn check_place<'tcx>( return Err((span, "accessing union fields is unstable".into())); } } - } + }, ProjectionElem::ConstantIndex { .. } | ProjectionElem::Downcast(..) | ProjectionElem::Subslice { .. } | ProjectionElem::Deref - | ProjectionElem::Index(_) => {} + | ProjectionElem::Index(_) => {}, } } @@ -321,16 +289,18 @@ fn check_terminator<'a, 'tcx>( TerminatorKind::DropAndReplace { place, value, .. } => { check_place(tcx, *place, span, body)?; check_operand(tcx, value, span, body) - } + }, - TerminatorKind::SwitchInt { discr, switch_ty: _, targets: _ } => { - check_operand(tcx, discr, span, body) - } + TerminatorKind::SwitchInt { + discr, + switch_ty: _, + targets: _, + } => check_operand(tcx, discr, span, body), TerminatorKind::Abort => Err((span, "abort is not stable in const fn".into())), TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => { Err((span, "const fn generators are unstable".into())) - } + }, TerminatorKind::Call { func, @@ -375,15 +345,17 @@ fn check_terminator<'a, 'tcx>( } else { Err((span, "can only call other const fns within const fn".into())) } - } + }, - TerminatorKind::Assert { cond, expected: _, msg: _, target: _, cleanup: _ } => { - check_operand(tcx, cond, span, body) - } + TerminatorKind::Assert { + cond, + expected: _, + msg: _, + target: _, + cleanup: _, + } => check_operand(tcx, cond, span, body), - TerminatorKind::InlineAsm { .. } => { - Err((span, "cannot use inline assembly in const fn".into())) - } + TerminatorKind::InlineAsm { .. } => Err((span, "cannot use inline assembly in const fn".into())), } } diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 99803ae93a71..a8ad6cf4f6a3 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -14,9 +14,8 @@ use rustc_lint::LateContext; use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst}; use rustc_middle::ty::{ - self, AdtDef, Binder, BoundRegion, DefIdTree, FnSig, IntTy, ParamEnv, Predicate, PredicateKind, - ProjectionTy, Region, RegionKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, - UintTy, VariantDef, VariantDiscr, + self, AdtDef, Binder, BoundRegion, DefIdTree, FnSig, IntTy, ParamEnv, Predicate, PredicateKind, ProjectionTy, + Region, RegionKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy, VariantDef, VariantDiscr, }; use rustc_span::symbol::Ident; use rustc_span::{sym, Span, Symbol, DUMMY_SP}; @@ -167,7 +166,9 @@ pub fn implements_trait_with_env<'tcx>( } let ty_params = tcx.mk_substs(ty_params.iter()); tcx.infer_ctxt().enter(|infcx| { - infcx.type_implements_trait(trait_id, ty, ty_params, param_env).must_apply_modulo_regions() + infcx + .type_implements_trait(trait_id, ty, ty_params, param_env) + .must_apply_modulo_regions() }) } @@ -184,14 +185,11 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { match ty.kind() { ty::Adt(adt, _) => cx.tcx.has_attr(adt.did(), sym::must_use), ty::Foreign(did) => cx.tcx.has_attr(*did, sym::must_use), - ty::Slice(ty) - | ty::Array(ty, _) - | ty::RawPtr(ty::TypeAndMut { ty, .. }) - | ty::Ref(_, ty, _) => { + ty::Slice(ty) | ty::Array(ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) | ty::Ref(_, ty, _) => { // for the Array case we don't need to care for the len == 0 case // because we don't want to lint functions returning empty arrays is_must_use_ty(cx, *ty) - } + }, ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(def_id, _) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { @@ -202,7 +200,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { } } false - } + }, ty::Dynamic(binder, _, _) => { for predicate in binder.iter() { if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() { @@ -212,7 +210,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { } } false - } + }, _ => false, } } @@ -222,11 +220,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { // not succeed /// Checks if `Ty` is normalizable. This function is useful /// to avoid crashes on `layout_of`. -pub fn is_normalizable<'tcx>( - cx: &LateContext<'tcx>, - param_env: ty::ParamEnv<'tcx>, - ty: Ty<'tcx>, -) -> bool { +pub fn is_normalizable<'tcx>(cx: &LateContext<'tcx>, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool { is_normalizable_helper(cx, param_env, ty, &mut FxHashMap::default()) } @@ -246,14 +240,15 @@ fn is_normalizable_helper<'tcx>( if infcx.at(&cause, param_env).normalize(ty).is_ok() { match ty.kind() { ty::Adt(def, substs) => def.variants().iter().all(|variant| { - variant.fields.iter().all(|field| { - is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache) - }) + variant + .fields + .iter() + .all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache)) }), _ => ty.walk().all(|generic_arg| match generic_arg.unpack() { GenericArgKind::Type(inner_ty) if inner_ty != ty => { is_normalizable_helper(cx, param_env, inner_ty, cache) - } + }, _ => true, // if inner_ty == ty, we've already checked it }), } @@ -278,9 +273,7 @@ pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool { match *ty.kind() { ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => true, ty::Ref(_, inner, _) if *inner.kind() == ty::Str => true, - ty::Array(inner_type, _) | ty::Slice(inner_type) => { - is_recursively_primitive_type(inner_type) - } + ty::Array(inner_type, _) | ty::Slice(inner_type) => is_recursively_primitive_type(inner_type), ty::Tuple(inner_types) => inner_types.iter().all(is_recursively_primitive_type), _ => false, } @@ -320,9 +313,11 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symb /// Returns `false` if the `LangItem` is not defined. pub fn is_type_lang_item(cx: &LateContext<'_>, ty: Ty<'_>, lang_item: hir::LangItem) -> bool { match ty.kind() { - ty::Adt(adt, _) => { - cx.tcx.lang_items().require(lang_item).map_or(false, |li| li == adt.did()) - } + ty::Adt(adt, _) => cx + .tcx + .lang_items() + .require(lang_item) + .map_or(false, |li| li == adt.did()), _ => false, } } @@ -347,11 +342,7 @@ pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool { /// deallocate memory. For these types, and composites containing them, changing the drop order /// won't result in any observable side effects. pub fn needs_ordered_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { - fn needs_ordered_drop_inner<'tcx>( - cx: &LateContext<'tcx>, - ty: Ty<'tcx>, - seen: &mut FxHashSet>, - ) -> bool { + fn needs_ordered_drop_inner<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, seen: &mut FxHashSet>) -> bool { if !seen.insert(ty) { return false; } @@ -402,7 +393,11 @@ pub fn needs_ordered_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { /// removed. pub fn peel_mid_ty_refs(ty: Ty<'_>) -> (Ty<'_>, usize) { fn peel(ty: Ty<'_>, count: usize) -> (Ty<'_>, usize) { - if let ty::Ref(_, ty, _) = ty.kind() { peel(*ty, count + 1) } else { (ty, count) } + if let ty::Ref(_, ty, _) = ty.kind() { + peel(*ty, count + 1) + } else { + (ty, count) + } } peel(ty, 0) } @@ -457,18 +452,17 @@ pub fn same_type_and_consts<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool { return false; } - substs_a.iter().zip(substs_b.iter()).all(|(arg_a, arg_b)| { - match (arg_a.unpack(), arg_b.unpack()) { - (GenericArgKind::Const(inner_a), GenericArgKind::Const(inner_b)) => { - inner_a == inner_b - } + substs_a + .iter() + .zip(substs_b.iter()) + .all(|(arg_a, arg_b)| match (arg_a.unpack(), arg_b.unpack()) { + (GenericArgKind::Const(inner_a), GenericArgKind::Const(inner_b)) => inner_a == inner_b, (GenericArgKind::Type(type_a), GenericArgKind::Type(type_b)) => { same_type_and_consts(type_a, type_b) - } + }, _ => true, - } - }) - } + }) + }, _ => a == b, } } @@ -484,10 +478,7 @@ pub fn is_uninit_value_valid_for_ty(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { } /// Gets an iterator over all predicates which apply to the given item. -pub fn all_predicates_of( - tcx: TyCtxt<'_>, - id: DefId, -) -> impl Iterator, Span)> { +pub fn all_predicates_of(tcx: TyCtxt<'_>, id: DefId) -> impl Iterator, Span)> { let mut next_id = Some(id); iter::from_fn(move || { next_id.take().map(|id| { @@ -517,7 +508,7 @@ impl<'tcx> ExprFnSig<'tcx> { } else { Some(sig.input(i)) } - } + }, Self::Closure(_, sig) => Some(sig.input(0).map_bound(|ty| ty.tuple_fields()[i])), Self::Trait(inputs, _, _) => Some(inputs.map_bound(|ty| ty.tuple_fields()[i])), } @@ -526,10 +517,7 @@ impl<'tcx> ExprFnSig<'tcx> { /// Gets the argument type at the given offset. For closures this will also get the type as /// written. This will return `None` when the index is out of bounds only for variadic /// functions, otherwise this will panic. - pub fn input_with_hir( - self, - i: usize, - ) -> Option<(Option<&'tcx hir::Ty<'tcx>>, Binder<'tcx, Ty<'tcx>>)> { + pub fn input_with_hir(self, i: usize) -> Option<(Option<&'tcx hir::Ty<'tcx>>, Binder<'tcx, Ty<'tcx>>)> { match self { Self::Sig(sig, _) => { if sig.c_variadic() { @@ -540,7 +528,7 @@ impl<'tcx> ExprFnSig<'tcx> { } else { Some((None, sig.input(i))) } - } + }, Self::Closure(decl, sig) => Some(( decl.and_then(|decl| decl.inputs.get(i)), sig.input(0).map_bound(|ty| ty.tuple_fields()[i]), @@ -559,15 +547,17 @@ impl<'tcx> ExprFnSig<'tcx> { } pub fn predicates_id(&self) -> Option { - if let ExprFnSig::Sig(_, id) | ExprFnSig::Trait(_, _, id) = *self { id } else { None } + if let ExprFnSig::Sig(_, id) | ExprFnSig::Trait(_, _, id) = *self { + id + } else { + None + } } } /// If the expression is function like, get the signature for it. pub fn expr_sig<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option> { - if let Res::Def(DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn) | DefKind::AssocFn, id) = - path_res(cx, expr) - { + if let Res::Def(DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn) | DefKind::AssocFn, id) = path_res(cx, expr) { Some(ExprFnSig::Sig(cx.tcx.fn_sig(id), Some(id))) } else { ty_sig(cx, cx.typeck_results().expr_ty_adjusted(expr).peel_refs()) @@ -581,14 +571,12 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option { - let decl = id.as_local().and_then(|id| { - cx.tcx.hir().fn_decl_by_hir_id(cx.tcx.hir().local_def_id_to_hir_id(id)) - }); + let decl = id + .as_local() + .and_then(|id| cx.tcx.hir().fn_decl_by_hir_id(cx.tcx.hir().local_def_id_to_hir_id(id))); Some(ExprFnSig::Closure(decl, subs.as_closure().sig())) - } - ty::FnDef(id, subs) => { - Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))) - } + }, + ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))), ty::Opaque(id, _) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(id), cx.tcx.opt_parent(id)), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), ty::Dynamic(bounds, _, _) => { @@ -601,19 +589,16 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option None, } - } + }, ty::Projection(proj) => match cx.tcx.try_normalize_erasing_regions(cx.param_env, ty) { Ok(normalized_ty) if normalized_ty != ty => ty_sig(cx, normalized_ty), - _ => sig_for_projection(cx, proj) - .or_else(|| sig_from_bounds(cx, ty, cx.param_env.caller_bounds(), None)), + _ => sig_for_projection(cx, proj).or_else(|| sig_from_bounds(cx, ty, cx.param_env.caller_bounds(), None)), }, ty::Param(_) => sig_from_bounds(cx, ty, cx.param_env.caller_bounds(), None), _ => None, @@ -644,7 +629,7 @@ fn sig_from_bounds<'tcx>( return None; } inputs = Some(i); - } + }, PredicateKind::Projection(p) if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() && p.projection_ty.self_ty() == ty => @@ -654,7 +639,7 @@ fn sig_from_bounds<'tcx>( return None; } output = Some(pred.kind().rebind(p.term.ty().unwrap())); - } + }, _ => (), } } @@ -662,10 +647,7 @@ fn sig_from_bounds<'tcx>( inputs.map(|ty| ExprFnSig::Trait(ty, output, predicates_id)) } -fn sig_for_projection<'tcx>( - cx: &LateContext<'tcx>, - ty: ProjectionTy<'tcx>, -) -> Option> { +fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> Option> { let mut inputs = None; let mut output = None; let lang_items = cx.tcx.lang_items(); @@ -691,10 +673,8 @@ fn sig_for_projection<'tcx>( return None; } inputs = Some(i); - } - PredicateKind::Projection(p) - if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() => - { + }, + PredicateKind::Projection(p) if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() => { if output.is_some() { // Multiple different fn trait impls. Is this even allowed? return None; @@ -703,7 +683,7 @@ fn sig_for_projection<'tcx>( pred.map_bound(|pred| pred.kind().rebind(p.term.ty().unwrap())) .subst(cx.tcx, ty.substs), ); - } + }, _ => (), } } @@ -797,10 +777,7 @@ pub fn for_each_top_level_late_bound_region( ControlFlow::Continue(()) } } - fn visit_binder>( - &mut self, - t: &Binder<'tcx, T>, - ) -> ControlFlow { + fn visit_binder>(&mut self, t: &Binder<'tcx, T>) -> ControlFlow { self.index += 1; let res = t.super_visit_with(self); self.index -= 1; @@ -814,27 +791,19 @@ pub fn for_each_top_level_late_bound_region( pub fn variant_of_res<'tcx>(cx: &LateContext<'tcx>, res: Res) -> Option<&'tcx VariantDef> { match res { Res::Def(DefKind::Struct, id) => Some(cx.tcx.adt_def(id).non_enum_variant()), - Res::Def(DefKind::Variant, id) => { - Some(cx.tcx.adt_def(cx.tcx.parent(id)).variant_with_id(id)) - } - Res::Def(DefKind::Ctor(CtorOf::Struct, _), id) => { - Some(cx.tcx.adt_def(cx.tcx.parent(id)).non_enum_variant()) - } + Res::Def(DefKind::Variant, id) => Some(cx.tcx.adt_def(cx.tcx.parent(id)).variant_with_id(id)), + Res::Def(DefKind::Ctor(CtorOf::Struct, _), id) => Some(cx.tcx.adt_def(cx.tcx.parent(id)).non_enum_variant()), Res::Def(DefKind::Ctor(CtorOf::Variant, _), id) => { let var_id = cx.tcx.parent(id); Some(cx.tcx.adt_def(cx.tcx.parent(var_id)).variant_with_id(var_id)) - } + }, Res::SelfCtor(id) => Some(cx.tcx.type_of(id).ty_adt_def().unwrap().non_enum_variant()), _ => None, } } /// Checks if the type is a type parameter implementing `FnOnce`, but not `FnMut`. -pub fn ty_is_fn_once_param<'tcx>( - tcx: TyCtxt<'_>, - ty: Ty<'tcx>, - predicates: &'tcx [Predicate<'_>], -) -> bool { +pub fn ty_is_fn_once_param<'tcx>(tcx: TyCtxt<'_>, ty: Ty<'tcx>, predicates: &'tcx [Predicate<'_>]) -> bool { let ty::Param(ty) = *ty.kind() else { return false; }; From 0917aea424b39b10ca932603bb65d1d1f1fefca1 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Wed, 14 Sep 2022 20:13:30 +0200 Subject: [PATCH 0615/1222] Temporarily move clippy::unused_peekable to nursery --- clippy_lints/src/lib.register_all.rs | 1 - clippy_lints/src/lib.register_nursery.rs | 1 + clippy_lints/src/lib.register_suspicious.rs | 1 - clippy_lints/src/unused_peekable.rs | 2 +- 4 files changed, 2 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/lib.register_all.rs b/clippy_lints/src/lib.register_all.rs index 1f85382347aa..59d1760fe606 100644 --- a/clippy_lints/src/lib.register_all.rs +++ b/clippy_lints/src/lib.register_all.rs @@ -344,7 +344,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![ LintId::of(unnecessary_owned_empty_strings::UNNECESSARY_OWNED_EMPTY_STRINGS), LintId::of(unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME), LintId::of(unused_io_amount::UNUSED_IO_AMOUNT), - LintId::of(unused_peekable::UNUSED_PEEKABLE), LintId::of(unused_unit::UNUSED_UNIT), LintId::of(unwrap::PANICKING_UNWRAP), LintId::of(unwrap::UNNECESSARY_UNWRAP), diff --git a/clippy_lints/src/lib.register_nursery.rs b/clippy_lints/src/lib.register_nursery.rs index e319e7ee72c5..f1783dd9ddef 100644 --- a/clippy_lints/src/lib.register_nursery.rs +++ b/clippy_lints/src/lib.register_nursery.rs @@ -31,6 +31,7 @@ store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![ LintId::of(suspicious_operation_groupings::SUSPICIOUS_OPERATION_GROUPINGS), LintId::of(trailing_empty_array::TRAILING_EMPTY_ARRAY), LintId::of(transmute::TRANSMUTE_UNDEFINED_REPR), + LintId::of(unused_peekable::UNUSED_PEEKABLE), LintId::of(unused_rounding::UNUSED_ROUNDING), LintId::of(use_self::USE_SELF), ]) diff --git a/clippy_lints/src/lib.register_suspicious.rs b/clippy_lints/src/lib.register_suspicious.rs index 8f131bbf98be..bede91f183e7 100644 --- a/clippy_lints/src/lib.register_suspicious.rs +++ b/clippy_lints/src/lib.register_suspicious.rs @@ -35,6 +35,5 @@ store.register_group(true, "clippy::suspicious", Some("clippy_suspicious"), vec! LintId::of(suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL), LintId::of(suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL), LintId::of(swap_ptr_to_ref::SWAP_PTR_TO_REF), - LintId::of(unused_peekable::UNUSED_PEEKABLE), LintId::of(write::POSITIONAL_NAMED_FORMAT_PARAMETERS), ]) diff --git a/clippy_lints/src/unused_peekable.rs b/clippy_lints/src/unused_peekable.rs index cfc181e435b9..cc8656435945 100644 --- a/clippy_lints/src/unused_peekable.rs +++ b/clippy_lints/src/unused_peekable.rs @@ -38,7 +38,7 @@ declare_clippy_lint! { /// ``` #[clippy::version = "1.64.0"] pub UNUSED_PEEKABLE, - suspicious, + nursery, "creating a peekable iterator without using any of its methods" } From 2e68257b06e7bf728fddea26556bef95e14eb055 Mon Sep 17 00:00:00 2001 From: est31 Date: Fri, 4 Feb 2022 10:13:48 +0100 Subject: [PATCH 0616/1222] Fix clippy --- clippy_dev/src/lib.rs | 2 +- clippy_lints/src/lib.rs | 2 +- clippy_utils/src/lib.rs | 2 +- tests/ui/needless_return.fixed | 1 - tests/ui/needless_return.rs | 1 - tests/ui/needless_return.stderr | 74 +++++++++---------- tests/ui/semicolon_if_nothing_returned.rs | 1 - tests/ui/semicolon_if_nothing_returned.stderr | 10 +-- 8 files changed, 45 insertions(+), 48 deletions(-) diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index 82574a8e64b0..54c7456a2a3b 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -1,5 +1,5 @@ #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(once_cell)] #![feature(rustc_private)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index e984254bf291..ceaaf5c6d6ed 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -5,7 +5,7 @@ #![feature(drain_filter)] #![feature(iter_intersperse)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(lint_reasons)] #![feature(never_type)] #![feature(once_cell)] diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 23b51ec2d084..62da850a15e7 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1,9 +1,9 @@ #![feature(array_chunks)] #![feature(box_patterns)] #![feature(control_flow_enum)] -#![feature(let_else)] #![feature(let_chains)] #![feature(lint_reasons)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(once_cell)] #![feature(rustc_private)] #![recursion_limit = "512"] diff --git a/tests/ui/needless_return.fixed b/tests/ui/needless_return.fixed index 87c8fc03b3c3..695883e8dff7 100644 --- a/tests/ui/needless_return.fixed +++ b/tests/ui/needless_return.fixed @@ -1,7 +1,6 @@ // run-rustfix #![feature(lint_reasons)] -#![feature(let_else)] #![allow(unused)] #![allow( clippy::if_same_then_else, diff --git a/tests/ui/needless_return.rs b/tests/ui/needless_return.rs index 5a86e656255d..63d9fe9ecdf8 100644 --- a/tests/ui/needless_return.rs +++ b/tests/ui/needless_return.rs @@ -1,7 +1,6 @@ // run-rustfix #![feature(lint_reasons)] -#![feature(let_else)] #![allow(unused)] #![allow( clippy::if_same_then_else, diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr index 83ff07638693..cadee6e00dff 100644 --- a/tests/ui/needless_return.stderr +++ b/tests/ui/needless_return.stderr @@ -1,5 +1,5 @@ error: unneeded `return` statement - --> $DIR/needless_return.rs:27:5 + --> $DIR/needless_return.rs:26:5 | LL | return true; | ^^^^^^^^^^^^ help: remove `return`: `true` @@ -7,217 +7,217 @@ LL | return true; = note: `-D clippy::needless-return` implied by `-D warnings` error: unneeded `return` statement - --> $DIR/needless_return.rs:31:5 + --> $DIR/needless_return.rs:30:5 | LL | return true; | ^^^^^^^^^^^^ help: remove `return`: `true` error: unneeded `return` statement - --> $DIR/needless_return.rs:36:9 + --> $DIR/needless_return.rs:35:9 | LL | return true; | ^^^^^^^^^^^^ help: remove `return`: `true` error: unneeded `return` statement - --> $DIR/needless_return.rs:38:9 + --> $DIR/needless_return.rs:37:9 | LL | return false; | ^^^^^^^^^^^^^ help: remove `return`: `false` error: unneeded `return` statement - --> $DIR/needless_return.rs:44:17 + --> $DIR/needless_return.rs:43:17 | LL | true => return false, | ^^^^^^^^^^^^ help: remove `return`: `false` error: unneeded `return` statement - --> $DIR/needless_return.rs:46:13 + --> $DIR/needless_return.rs:45:13 | LL | return true; | ^^^^^^^^^^^^ help: remove `return`: `true` error: unneeded `return` statement - --> $DIR/needless_return.rs:53:9 + --> $DIR/needless_return.rs:52:9 | LL | return true; | ^^^^^^^^^^^^ help: remove `return`: `true` error: unneeded `return` statement - --> $DIR/needless_return.rs:55:16 + --> $DIR/needless_return.rs:54:16 | LL | let _ = || return true; | ^^^^^^^^^^^ help: remove `return`: `true` error: unneeded `return` statement - --> $DIR/needless_return.rs:59:5 + --> $DIR/needless_return.rs:58:5 | LL | return the_answer!(); | ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `the_answer!()` error: unneeded `return` statement - --> $DIR/needless_return.rs:63:5 + --> $DIR/needless_return.rs:62:5 | LL | return; | ^^^^^^^ help: remove `return` error: unneeded `return` statement - --> $DIR/needless_return.rs:68:9 + --> $DIR/needless_return.rs:67:9 | LL | return; | ^^^^^^^ help: remove `return` error: unneeded `return` statement - --> $DIR/needless_return.rs:70:9 + --> $DIR/needless_return.rs:69:9 | LL | return; | ^^^^^^^ help: remove `return` error: unneeded `return` statement - --> $DIR/needless_return.rs:77:14 + --> $DIR/needless_return.rs:76:14 | LL | _ => return, | ^^^^^^ help: replace `return` with a unit value: `()` error: unneeded `return` statement - --> $DIR/needless_return.rs:86:13 + --> $DIR/needless_return.rs:85:13 | LL | return; | ^^^^^^^ help: remove `return` error: unneeded `return` statement - --> $DIR/needless_return.rs:88:14 + --> $DIR/needless_return.rs:87:14 | LL | _ => return, | ^^^^^^ help: replace `return` with a unit value: `()` error: unneeded `return` statement - --> $DIR/needless_return.rs:101:9 + --> $DIR/needless_return.rs:100:9 | LL | return String::from("test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::from("test")` error: unneeded `return` statement - --> $DIR/needless_return.rs:103:9 + --> $DIR/needless_return.rs:102:9 | LL | return String::new(); | ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::new()` error: unneeded `return` statement - --> $DIR/needless_return.rs:125:32 + --> $DIR/needless_return.rs:124:32 | LL | bar.unwrap_or_else(|_| return) | ^^^^^^ help: replace `return` with an empty block: `{}` error: unneeded `return` statement - --> $DIR/needless_return.rs:130:13 + --> $DIR/needless_return.rs:129:13 | LL | return; | ^^^^^^^ help: remove `return` error: unneeded `return` statement - --> $DIR/needless_return.rs:132:20 + --> $DIR/needless_return.rs:131:20 | LL | let _ = || return; | ^^^^^^ help: replace `return` with an empty block: `{}` error: unneeded `return` statement - --> $DIR/needless_return.rs:138:32 + --> $DIR/needless_return.rs:137:32 | LL | res.unwrap_or_else(|_| return Foo) | ^^^^^^^^^^ help: remove `return`: `Foo` error: unneeded `return` statement - --> $DIR/needless_return.rs:147:5 + --> $DIR/needless_return.rs:146:5 | LL | return true; | ^^^^^^^^^^^^ help: remove `return`: `true` error: unneeded `return` statement - --> $DIR/needless_return.rs:151:5 + --> $DIR/needless_return.rs:150:5 | LL | return true; | ^^^^^^^^^^^^ help: remove `return`: `true` error: unneeded `return` statement - --> $DIR/needless_return.rs:156:9 + --> $DIR/needless_return.rs:155:9 | LL | return true; | ^^^^^^^^^^^^ help: remove `return`: `true` error: unneeded `return` statement - --> $DIR/needless_return.rs:158:9 + --> $DIR/needless_return.rs:157:9 | LL | return false; | ^^^^^^^^^^^^^ help: remove `return`: `false` error: unneeded `return` statement - --> $DIR/needless_return.rs:164:17 + --> $DIR/needless_return.rs:163:17 | LL | true => return false, | ^^^^^^^^^^^^ help: remove `return`: `false` error: unneeded `return` statement - --> $DIR/needless_return.rs:166:13 + --> $DIR/needless_return.rs:165:13 | LL | return true; | ^^^^^^^^^^^^ help: remove `return`: `true` error: unneeded `return` statement - --> $DIR/needless_return.rs:173:9 + --> $DIR/needless_return.rs:172:9 | LL | return true; | ^^^^^^^^^^^^ help: remove `return`: `true` error: unneeded `return` statement - --> $DIR/needless_return.rs:175:16 + --> $DIR/needless_return.rs:174:16 | LL | let _ = || return true; | ^^^^^^^^^^^ help: remove `return`: `true` error: unneeded `return` statement - --> $DIR/needless_return.rs:179:5 + --> $DIR/needless_return.rs:178:5 | LL | return the_answer!(); | ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `the_answer!()` error: unneeded `return` statement - --> $DIR/needless_return.rs:183:5 + --> $DIR/needless_return.rs:182:5 | LL | return; | ^^^^^^^ help: remove `return` error: unneeded `return` statement - --> $DIR/needless_return.rs:188:9 + --> $DIR/needless_return.rs:187:9 | LL | return; | ^^^^^^^ help: remove `return` error: unneeded `return` statement - --> $DIR/needless_return.rs:190:9 + --> $DIR/needless_return.rs:189:9 | LL | return; | ^^^^^^^ help: remove `return` error: unneeded `return` statement - --> $DIR/needless_return.rs:197:14 + --> $DIR/needless_return.rs:196:14 | LL | _ => return, | ^^^^^^ help: replace `return` with a unit value: `()` error: unneeded `return` statement - --> $DIR/needless_return.rs:210:9 + --> $DIR/needless_return.rs:209:9 | LL | return String::from("test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::from("test")` error: unneeded `return` statement - --> $DIR/needless_return.rs:212:9 + --> $DIR/needless_return.rs:211:9 | LL | return String::new(); | ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::new()` error: unneeded `return` statement - --> $DIR/needless_return.rs:228:5 + --> $DIR/needless_return.rs:227:5 | LL | return format!("Hello {}", "world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `format!("Hello {}", "world!")` diff --git a/tests/ui/semicolon_if_nothing_returned.rs b/tests/ui/semicolon_if_nothing_returned.rs index c3235f06779b..c4dfbd9210e0 100644 --- a/tests/ui/semicolon_if_nothing_returned.rs +++ b/tests/ui/semicolon_if_nothing_returned.rs @@ -1,6 +1,5 @@ #![warn(clippy::semicolon_if_nothing_returned)] #![allow(clippy::redundant_closure)] -#![feature(let_else)] fn get_unit() {} diff --git a/tests/ui/semicolon_if_nothing_returned.stderr b/tests/ui/semicolon_if_nothing_returned.stderr index 78813e7cc1c3..8d9a67585cf1 100644 --- a/tests/ui/semicolon_if_nothing_returned.stderr +++ b/tests/ui/semicolon_if_nothing_returned.stderr @@ -1,5 +1,5 @@ error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:9:5 + --> $DIR/semicolon_if_nothing_returned.rs:8:5 | LL | println!("Hello") | ^^^^^^^^^^^^^^^^^ help: add a `;` here: `println!("Hello");` @@ -7,25 +7,25 @@ LL | println!("Hello") = note: `-D clippy::semicolon-if-nothing-returned` implied by `-D warnings` error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:13:5 + --> $DIR/semicolon_if_nothing_returned.rs:12:5 | LL | get_unit() | ^^^^^^^^^^ help: add a `;` here: `get_unit();` error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:18:5 + --> $DIR/semicolon_if_nothing_returned.rs:17:5 | LL | y = x + 1 | ^^^^^^^^^ help: add a `;` here: `y = x + 1;` error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:24:9 + --> $DIR/semicolon_if_nothing_returned.rs:23:9 | LL | hello() | ^^^^^^^ help: add a `;` here: `hello();` error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:35:9 + --> $DIR/semicolon_if_nothing_returned.rs:34:9 | LL | ptr::drop_in_place(s.as_mut_ptr()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `ptr::drop_in_place(s.as_mut_ptr());` From 631e089b9d0c22848f8f59a4bd1b22bc78b0e9de Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 27 Jul 2022 11:58:34 +0000 Subject: [PATCH 0617/1222] Revert "Revert "Rollup merge of #98582 - oli-obk:unconstrained_opaque_type, r=estebank"" This reverts commit 4a742a691e7dd2522bad68b86fe2fd5a199d5561. --- clippy_utils/src/qualify_min_const_fn.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 8835b9329095..405f02286839 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -260,6 +260,7 @@ fn check_place<'tcx>(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &B } }, ProjectionElem::ConstantIndex { .. } + | ProjectionElem::OpaqueCast(..) | ProjectionElem::Downcast(..) | ProjectionElem::Subslice { .. } | ProjectionElem::Deref From d5d76b48299b4663d076152ec4c2cc9471258b7a Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 16 Sep 2022 15:31:10 +0200 Subject: [PATCH 0618/1222] remove the `Subst` trait, always use `EarlyBinder` --- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/eta_reduction.rs | 1 - clippy_lints/src/future_not_send.rs | 1 - clippy_lints/src/methods/unnecessary_to_owned.rs | 1 - clippy_lints/src/mut_reference.rs | 1 - clippy_lints/src/transmute/transmute_undefined_repr.rs | 2 +- clippy_utils/src/consts.rs | 2 +- clippy_utils/src/ty.rs | 2 +- 8 files changed, 4 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 88e28018e5d0..45b5d79d4452 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -20,7 +20,7 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability}; use rustc_middle::ty::{ - self, subst::Subst, Binder, BoundVariableKind, EarlyBinder, FnSig, GenericArgKind, List, ParamTy, PredicateKind, + self, Binder, BoundVariableKind, EarlyBinder, FnSig, GenericArgKind, List, ParamTy, PredicateKind, ProjectionPredicate, Ty, TyCtxt, TypeVisitable, TypeckResults, }; use rustc_semver::RustcVersion; diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 53bc617a4f5b..598f8c31859e 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -11,7 +11,6 @@ use rustc_hir::{Closure, Expr, ExprKind, Param, PatKind, Unsafety}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; use rustc_middle::ty::binding::BindingMode; -use rustc_middle::ty::subst::Subst; use rustc_middle::ty::{self, ClosureKind, Ty, TypeVisitable}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index ef7d75aa8ed9..eb2eefe0d5a1 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -4,7 +4,6 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::subst::Subst; use rustc_middle::ty::{EarlyBinder, Opaque, PredicateKind::Trait}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 763bfafecef1..8d3cede70f70 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -1,6 +1,5 @@ use super::implicit_clone::is_clone_like; use super::unnecessary_iter_cloned::{self, is_into_iter}; -use crate::rustc_middle::ty::Subst; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_opt; use clippy_utils::ty::{get_associated_type, get_iterator_item_ty, implements_trait, is_copy, peel_mid_ty_refs}; diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 82dc03ef5c5b..084c0d471dde 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -1,7 +1,6 @@ use clippy_utils::diagnostics::span_lint; use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::subst::Subst; use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::iter; diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index b6d7d9f5b42e..ae55a6bf5586 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_c_void; use rustc_hir::Expr; use rustc_lint::LateContext; -use rustc_middle::ty::subst::{Subst, SubstsRef}; +use rustc_middle::ty::SubstsRef; use rustc_middle::ty::{self, IntTy, Ty, TypeAndMut, UintTy}; use rustc_span::DUMMY_SP; diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index e053708edd50..96c55111fbaf 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -9,7 +9,7 @@ use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, Item, ItemKind, use rustc_lint::LateContext; use rustc_middle::mir; use rustc_middle::mir::interpret::Scalar; -use rustc_middle::ty::subst::{Subst, SubstsRef}; +use rustc_middle::ty::SubstsRef; use rustc_middle::ty::{self, EarlyBinder, FloatTy, ScalarInt, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; use rustc_span::symbol::Symbol; diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index a8ad6cf4f6a3..926ecf965932 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -12,7 +12,7 @@ use rustc_hir::{Expr, FnDecl, LangItem, TyKind, Unsafety}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::mir::interpret::{ConstValue, Scalar}; -use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst}; +use rustc_middle::ty::{GenericArg, GenericArgKind}; use rustc_middle::ty::{ self, AdtDef, Binder, BoundRegion, DefIdTree, FnSig, IntTy, ParamEnv, Predicate, PredicateKind, ProjectionTy, Region, RegionKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy, VariantDef, VariantDiscr, From b5c79fcd66a766896945ffc9137c99963f35de62 Mon Sep 17 00:00:00 2001 From: Steve Heindel Date: Wed, 21 Sep 2022 19:45:57 -0400 Subject: [PATCH 0619/1222] Add note to clippy::non_expressive_names doc --- clippy_lints/src/non_expressive_names.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index b96af06b8d7c..a7cd1f6d0652 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -15,6 +15,10 @@ declare_clippy_lint! { /// ### What it does /// Checks for names that are very similar and thus confusing. /// + /// Note: this lint looks for similar names throughout each + /// scope. To allow it, you need to allow it on the scope + /// level, not on the name that is reported. + /// /// ### Why is this bad? /// It's hard to distinguish between names that differ only /// by a single character. From 498b18300bedbbd47a114bc6983bec1216eb5545 Mon Sep 17 00:00:00 2001 From: b-naber Date: Mon, 19 Sep 2022 19:46:53 +0200 Subject: [PATCH 0620/1222] introduce mir::Unevaluated --- clippy_lints/src/non_copy_const.rs | 2 +- clippy_utils/src/consts.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 72c86f28bbc6..85024b0b05c8 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -195,7 +195,7 @@ fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: D let result = cx.tcx.const_eval_resolve( cx.param_env, - ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), + mir::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), None, ); is_value_unfrozen_raw(cx, result, ty) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 1b8a9c05559a..ac5bac3714f0 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -424,7 +424,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { .tcx .const_eval_resolve( self.param_env, - ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), + mir::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), None, ) .ok() From 78d63ce0014694706caef921fa0d08f14285e2f0 Mon Sep 17 00:00:00 2001 From: b-naber Date: Thu, 22 Sep 2022 12:34:23 +0200 Subject: [PATCH 0621/1222] rename Unevaluated to UnevaluatedConst --- clippy_lints/src/non_copy_const.rs | 2 +- clippy_utils/src/consts.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 85024b0b05c8..b15884527321 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -195,7 +195,7 @@ fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: D let result = cx.tcx.const_eval_resolve( cx.param_env, - mir::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), + mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs), None, ); is_value_unfrozen_raw(cx, result, ty) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index ac5bac3714f0..fa6766f7cfe1 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -424,7 +424,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { .tcx .const_eval_resolve( self.param_env, - mir::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), + mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs), None, ) .ok() From 6f46ae3537cbf5084e102b2f193c276408597452 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 22 Sep 2022 19:39:38 +0200 Subject: [PATCH 0622/1222] Bless clippy. --- tests/ui/inefficient_to_string.stderr | 8 ++++---- tests/ui/suspicious_to_owned.stderr | 8 ++++---- tests/ui/transmute_ptr_to_ref.stderr | 4 ++-- tests/ui/useless_conversion.stderr | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/ui/inefficient_to_string.stderr b/tests/ui/inefficient_to_string.stderr index 4be46161e8b7..1c0490ffa44c 100644 --- a/tests/ui/inefficient_to_string.stderr +++ b/tests/ui/inefficient_to_string.stderr @@ -35,21 +35,21 @@ LL | let _: String = rrrstring.to_string(); | = help: `&&std::string::String` implements `ToString` through a slower blanket impl, but `std::string::String` has a fast specialization of `ToString` -error: calling `to_string` on `&&std::borrow::Cow` +error: calling `to_string` on `&&std::borrow::Cow<'_, str>` --> $DIR/inefficient_to_string.rs:29:21 | LL | let _: String = rrcow.to_string(); | ^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrcow).to_string()` | - = help: `&std::borrow::Cow` implements `ToString` through a slower blanket impl, but `std::borrow::Cow` has a fast specialization of `ToString` + = help: `&std::borrow::Cow<'_, str>` implements `ToString` through a slower blanket impl, but `std::borrow::Cow<'_, str>` has a fast specialization of `ToString` -error: calling `to_string` on `&&&std::borrow::Cow` +error: calling `to_string` on `&&&std::borrow::Cow<'_, str>` --> $DIR/inefficient_to_string.rs:30:21 | LL | let _: String = rrrcow.to_string(); | ^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrcow).to_string()` | - = help: `&&std::borrow::Cow` implements `ToString` through a slower blanket impl, but `std::borrow::Cow` has a fast specialization of `ToString` + = help: `&&std::borrow::Cow<'_, str>` implements `ToString` through a slower blanket impl, but `std::borrow::Cow<'_, str>` has a fast specialization of `ToString` error: aborting due to 6 previous errors diff --git a/tests/ui/suspicious_to_owned.stderr b/tests/ui/suspicious_to_owned.stderr index 92e1024bf1f4..ae1aec34d82e 100644 --- a/tests/ui/suspicious_to_owned.stderr +++ b/tests/ui/suspicious_to_owned.stderr @@ -1,4 +1,4 @@ -error: this `to_owned` call clones the std::borrow::Cow itself and does not cause the std::borrow::Cow contents to become owned +error: this `to_owned` call clones the std::borrow::Cow<'_, str> itself and does not cause the std::borrow::Cow<'_, str> contents to become owned --> $DIR/suspicious_to_owned.rs:16:13 | LL | let _ = cow.to_owned(); @@ -6,19 +6,19 @@ LL | let _ = cow.to_owned(); | = note: `-D clippy::suspicious-to-owned` implied by `-D warnings` -error: this `to_owned` call clones the std::borrow::Cow<[char; 3]> itself and does not cause the std::borrow::Cow<[char; 3]> contents to become owned +error: this `to_owned` call clones the std::borrow::Cow<'_, [char; 3]> itself and does not cause the std::borrow::Cow<'_, [char; 3]> contents to become owned --> $DIR/suspicious_to_owned.rs:26:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ help: consider using, depending on intent: `cow.clone()` or `cow.into_owned()` -error: this `to_owned` call clones the std::borrow::Cow> itself and does not cause the std::borrow::Cow> contents to become owned +error: this `to_owned` call clones the std::borrow::Cow<'_, std::vec::Vec> itself and does not cause the std::borrow::Cow<'_, std::vec::Vec> contents to become owned --> $DIR/suspicious_to_owned.rs:36:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ help: consider using, depending on intent: `cow.clone()` or `cow.into_owned()` -error: this `to_owned` call clones the std::borrow::Cow itself and does not cause the std::borrow::Cow contents to become owned +error: this `to_owned` call clones the std::borrow::Cow<'_, str> itself and does not cause the std::borrow::Cow<'_, str> contents to become owned --> $DIR/suspicious_to_owned.rs:46:13 | LL | let _ = cow.to_owned(); diff --git a/tests/ui/transmute_ptr_to_ref.stderr b/tests/ui/transmute_ptr_to_ref.stderr index 2993e5e7b0c9..10117ee9182a 100644 --- a/tests/ui/transmute_ptr_to_ref.stderr +++ b/tests/ui/transmute_ptr_to_ref.stderr @@ -42,13 +42,13 @@ error: transmute from a pointer type (`*mut U`) to a reference type (`&T`) LL | let _: &T = std::mem::transmute(om); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(om as *const T)` -error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo`) +error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo<'_, u8>`) --> $DIR/transmute_ptr_to_ref.rs:36:32 | LL | let _: &Foo = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*raw.cast::>()` -error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo<&u8>`) +error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo<'_, &u8>`) --> $DIR/transmute_ptr_to_ref.rs:38:33 | LL | let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) }; diff --git a/tests/ui/useless_conversion.stderr b/tests/ui/useless_conversion.stderr index e6760f700f34..65ee3807fa9d 100644 --- a/tests/ui/useless_conversion.stderr +++ b/tests/ui/useless_conversion.stderr @@ -46,7 +46,7 @@ error: useless conversion to the same type: `std::string::String` LL | let _ = String::from(format!("A: {:04}", 123)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `format!("A: {:04}", 123)` -error: useless conversion to the same type: `std::str::Lines` +error: useless conversion to the same type: `std::str::Lines<'_>` --> $DIR/useless_conversion.rs:65:13 | LL | let _ = "".lines().into_iter(); From 2f1f6d7d38ccb9975e34a4a079ce18d61103d490 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Fri, 23 Sep 2022 18:03:44 +0200 Subject: [PATCH 0623/1222] Stabilize const `BTree{Map,Set}::new` Since `len` and `is_empty` are not const stable yet, this also creates a new feature for them since they previously used the same `const_btree_new` feature. --- tests/ui/crashes/ice-7126.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ui/crashes/ice-7126.rs b/tests/ui/crashes/ice-7126.rs index ca563ba09785..b2dc2248b556 100644 --- a/tests/ui/crashes/ice-7126.rs +++ b/tests/ui/crashes/ice-7126.rs @@ -1,13 +1,13 @@ // This test requires a feature gated const fn and will stop working in the future. -#![feature(const_btree_new)] +#![feature(const_btree_len)] use std::collections::BTreeMap; -struct Foo(BTreeMap); +struct Foo(usize); impl Foo { fn new() -> Self { - Self(BTreeMap::new()) + Self(BTreeMap::len(&BTreeMap::::new())) } } From 8e4ff2e83fcfcfbffd2c3a55fce299a2d090e2c4 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Fri, 23 Sep 2022 21:04:54 +0200 Subject: [PATCH 0624/1222] Fix clippy's const fn stability check for CURRENT_RUSTC_VERSION Since clippy can use a projects MSRV for its lints, it might not want to consider functions as const stable if they have been added lately. Functions that have been stabilized this version use CURRENT_RUSTC_VERSION as their version, which gets then turned into the current version, which might be something like `1.66.0-dev`. The version parser cannot deal with this version, so it has to be stripped off. --- clippy_utils/src/qualify_min_const_fn.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 405f02286839..f7ce71917726 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -367,10 +367,21 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option) -> bo // Checking MSRV is manually necessary because `rustc` has no such concept. This entire // function could be removed if `rustc` provided a MSRV-aware version of `is_const_fn`. // as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262. + + // HACK(nilstrieb): CURRENT_RUSTC_VERSION can return versions like 1.66.0-dev. `rustc-semver` doesn't accept + // the `-dev` version number so we have to strip it off. + let short_version = since + .as_str() + .split('-') + .next() + .expect("rustc_attr::StabilityLevel::Stable::since` is empty"); + + let since = rustc_span::Symbol::intern(short_version); + crate::meets_msrv( msrv, RustcVersion::parse(since.as_str()) - .expect("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted"), + .unwrap_or_else(|err| panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{since}`, {err:?}")), ) } else { // Unstable const fn with the feature enabled. From 21f1df0ee954788f03f316e324b65bd407a577f0 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Tue, 20 Sep 2022 14:11:23 +0900 Subject: [PATCH 0625/1222] separate definitions and `HIR` owners fix a ui test use `into` fix clippy ui test fix a run-make-fulldeps test implement `IntoQueryParam` for `OwnerId` use `OwnerId` for more queries change the type of `ParentOwnerIterator::Item` to `(OwnerId, OwnerNode)` --- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/doc.rs | 10 +++++----- clippy_lints/src/enum_variants.rs | 2 +- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/exhaustive_items.rs | 2 +- clippy_lints/src/exit.rs | 2 +- clippy_lints/src/fallible_impl_from.rs | 2 +- clippy_lints/src/functions/must_use.rs | 20 +++++++++---------- .../src/functions/not_unsafe_ptr_arg_deref.rs | 2 +- clippy_lints/src/functions/result.rs | 14 ++++++------- clippy_lints/src/implicit_hasher.rs | 2 +- clippy_lints/src/inherent_to_string.rs | 2 +- .../src/iter_not_returning_iterator.rs | 4 ++-- clippy_lints/src/len_zero.rs | 4 ++-- clippy_lints/src/lifetimes.rs | 4 ++-- clippy_lints/src/loops/mut_range_bound.rs | 2 +- clippy_lints/src/manual_non_exhaustive.rs | 2 +- clippy_lints/src/methods/mod.rs | 8 ++++---- clippy_lints/src/missing_const_for_fn.rs | 2 +- clippy_lints/src/missing_doc.rs | 2 +- clippy_lints/src/missing_inline.rs | 6 +++--- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/new_without_default.rs | 4 ++-- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/only_used_in_recursion.rs | 2 +- .../src/operators/assign_op_pattern.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/redundant_pub_crate.rs | 6 +++--- clippy_lints/src/return_self_not_must_use.rs | 2 +- clippy_lints/src/self_named_constructors.rs | 2 +- clippy_lints/src/suspicious_trait_impl.rs | 4 ++-- clippy_lints/src/transmute/utils.rs | 2 +- clippy_lints/src/types/borrowed_box.rs | 2 +- clippy_lints/src/types/mod.rs | 8 ++++---- clippy_lints/src/unused_self.rs | 4 ++-- clippy_lints/src/unwrap_in_result.rs | 2 +- clippy_lints/src/upper_case_acronyms.rs | 2 +- clippy_lints/src/use_self.rs | 2 +- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/wildcard_imports.rs | 6 +++--- clippy_lints/src/zero_sized_map_values.rs | 2 +- clippy_utils/src/lib.rs | 12 +++++------ clippy_utils/src/usage.rs | 2 +- 43 files changed, 85 insertions(+), 85 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 501f9ef78aeb..e54d71fc8e41 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -704,7 +704,7 @@ fn walk_parents<'tcx>( span, .. }) if span.ctxt() == ctxt => { - let ty = cx.tcx.type_of(def_id); + let ty = cx.tcx.type_of(def_id.def_id); Some(ty_auto_deref_stability(cx, ty, precedence).position_for_result(cx)) }, diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index eb158d850fa7..f48ba526d51e 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -233,11 +233,11 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { let body = cx.tcx.hir().body(body_id); let mut fpu = FindPanicUnwrap { cx, - typeck_results: cx.tcx.typeck(item.def_id), + typeck_results: cx.tcx.typeck(item.def_id.def_id), panic_span: None, }; fpu.visit_expr(body.value); - lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, Some(body_id), fpu.panic_span); + lint_for_missing_headers(cx, item.def_id.def_id, item.span, sig, headers, Some(body_id), fpu.panic_span); } }, hir::ItemKind::Impl(impl_) => { @@ -268,7 +268,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { let headers = check_attrs(cx, &self.valid_idents, attrs); if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { if !in_external_macro(cx.tcx.sess, item.span) { - lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, None, None); + lint_for_missing_headers(cx, item.def_id.def_id, item.span, sig, headers, None, None); } } } @@ -283,11 +283,11 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { let body = cx.tcx.hir().body(body_id); let mut fpu = FindPanicUnwrap { cx, - typeck_results: cx.tcx.typeck(item.def_id), + typeck_results: cx.tcx.typeck(item.def_id.def_id), panic_span: None, }; fpu.visit_expr(body.value); - lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, Some(body_id), fpu.panic_span); + lint_for_missing_headers(cx, item.def_id.def_id, item.span, sig, headers, Some(body_id), fpu.panic_span); } } } diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index cd36f9fcd729..c39a909b3ccb 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -297,7 +297,7 @@ impl LateLintPass<'_> for EnumVariantNames { } } if let ItemKind::Enum(ref def, _) = item.kind { - if !(self.avoid_breaking_exported_api && cx.access_levels.is_exported(item.def_id)) { + if !(self.avoid_breaking_exported_api && cx.access_levels.is_exported(item.def_id.def_id)) { check_variant(cx, self.threshold, def, item_name, item.span); } } diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 327865e4c858..a6ddb26e2dee 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { } } - let parent_id = cx.tcx.hir().get_parent_item(hir_id); + let parent_id = cx.tcx.hir().get_parent_item(hir_id).def_id; let parent_node = cx.tcx.hir().find_by_def_id(parent_id); let mut trait_self_ty = None; diff --git a/clippy_lints/src/exhaustive_items.rs b/clippy_lints/src/exhaustive_items.rs index 173d41b4b050..f3d9ebc5f12d 100644 --- a/clippy_lints/src/exhaustive_items.rs +++ b/clippy_lints/src/exhaustive_items.rs @@ -73,7 +73,7 @@ impl LateLintPass<'_> for ExhaustiveItems { fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { if_chain! { if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind; - if cx.access_levels.is_exported(item.def_id); + if cx.access_levels.is_exported(item.def_id.def_id); let attrs = cx.tcx.hir().attrs(item.hir_id()); if !attrs.iter().any(|a| a.has_name(sym::non_exhaustive)); then { diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index cbf52d19334c..407dd1b39575 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -33,7 +33,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit { if let ExprKind::Path(ref path) = path_expr.kind; if let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::EXIT); - let parent = cx.tcx.hir().get_parent_item(e.hir_id); + let parent = cx.tcx.hir().get_parent_item(e.hir_id).def_id; if let Some(Node::Item(Item{kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find_by_def_id(parent); // If the next item up is a function we check if it is an entry point // and only then emit a linter warning diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 1f69f34a229d..ef24a5d06ad0 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -107,7 +107,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h let body = cx.tcx.hir().body(body_id); let mut fpu = FindPanicUnwrap { lcx: cx, - typeck_results: cx.tcx.typeck(impl_item.id.def_id), + typeck_results: cx.tcx.typeck(impl_item.id.def_id.def_id), result: Vec::new(), }; fpu.visit_expr(body.value); diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 00a4937763eb..d6d33bda1738 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -21,7 +21,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_> let attrs = cx.tcx.hir().attrs(item.hir_id()); let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use); if let hir::ItemKind::Fn(ref sig, _generics, ref body_id) = item.kind { - let is_public = cx.access_levels.is_exported(item.def_id); + let is_public = cx.access_levels.is_exported(item.def_id.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); if let Some(attr) = attr { check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr); @@ -31,7 +31,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_> sig.decl, cx.tcx.hir().body(*body_id), item.span, - item.def_id, + item.def_id.def_id, item.span.with_hi(sig.decl.output.span().hi()), "this function could have a `#[must_use]` attribute", ); @@ -41,19 +41,19 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_> pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind { - let is_public = cx.access_levels.is_exported(item.def_id); + let is_public = cx.access_levels.is_exported(item.def_id.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let attrs = cx.tcx.hir().attrs(item.hir_id()); let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use); if let Some(attr) = attr { check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr); - } else if is_public && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.def_id).is_none() { + } else if is_public && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.def_id.def_id).is_none() { check_must_use_candidate( cx, sig.decl, cx.tcx.hir().body(*body_id), item.span, - item.def_id, + item.def_id.def_id, item.span.with_hi(sig.decl.output.span().hi()), "this method could have a `#[must_use]` attribute", ); @@ -63,7 +63,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { if let hir::TraitItemKind::Fn(ref sig, ref eid) = item.kind { - let is_public = cx.access_levels.is_exported(item.def_id); + let is_public = cx.access_levels.is_exported(item.def_id.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let attrs = cx.tcx.hir().attrs(item.hir_id()); @@ -78,7 +78,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr sig.decl, body, item.span, - item.def_id, + item.def_id.def_id, item.span.with_hi(sig.decl.output.span().hi()), "this method could have a `#[must_use]` attribute", ); @@ -171,7 +171,7 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut DefIdSet) return false; // ignore `_` patterns } if cx.tcx.has_typeck_results(pat.hir_id.owner.to_def_id()) { - is_mutable_ty(cx, cx.tcx.typeck(pat.hir_id.owner).pat_ty(pat), pat.span, tys) + is_mutable_ty(cx, cx.tcx.typeck(pat.hir_id.owner.def_id).pat_ty(pat), pat.span, tys) } else { false } @@ -218,7 +218,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id()) && is_mutable_ty( self.cx, - self.cx.tcx.typeck(arg.hir_id.owner).expr_ty(arg), + self.cx.tcx.typeck(arg.hir_id.owner.def_id).expr_ty(arg), arg.span, &mut tys, ) @@ -236,7 +236,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id()) && is_mutable_ty( self.cx, - self.cx.tcx.typeck(arg.hir_id.owner).expr_ty(arg), + self.cx.tcx.typeck(arg.hir_id.owner.def_id).expr_ty(arg), arg.span, &mut tys, ) diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index 3bbfa52e8103..0b50431fbaab 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -28,7 +28,7 @@ pub(super) fn check_fn<'tcx>( pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { if let hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(eid)) = item.kind { let body = cx.tcx.hir().body(eid); - check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.def_id); + check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.def_id.def_id); } } diff --git a/clippy_lints/src/functions/result.rs b/clippy_lints/src/functions/result.rs index 9591405cb06f..113c4e9f5091 100644 --- a/clippy_lints/src/functions/result.rs +++ b/clippy_lints/src/functions/result.rs @@ -34,9 +34,9 @@ fn result_err_ty<'tcx>( pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, large_err_threshold: u64) { if let hir::ItemKind::Fn(ref sig, _generics, _) = item.kind - && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id, item.span) + && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id.def_id, item.span) { - if cx.access_levels.is_exported(item.def_id) { + if cx.access_levels.is_exported(item.def_id.def_id) { let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); check_result_unit_err(cx, err_ty, fn_header_span); } @@ -47,10 +47,10 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, l pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::ImplItem<'tcx>, large_err_threshold: u64) { // Don't lint if method is a trait's implementation, we can't do anything about those if let hir::ImplItemKind::Fn(ref sig, _) = item.kind - && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id, item.span) - && trait_ref_of_method(cx, item.def_id).is_none() + && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id.def_id, item.span) + && trait_ref_of_method(cx, item.def_id.def_id).is_none() { - if cx.access_levels.is_exported(item.def_id) { + if cx.access_levels.is_exported(item.def_id.def_id) { let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); check_result_unit_err(cx, err_ty, fn_header_span); } @@ -61,8 +61,8 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::ImplItem pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::TraitItem<'tcx>, large_err_threshold: u64) { if let hir::TraitItemKind::Fn(ref sig, _) = item.kind { let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); - if let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id, item.span) { - if cx.access_levels.is_exported(item.def_id) { + if let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id.def_id, item.span) { + if cx.access_levels.is_exported(item.def_id.def_id) { check_result_unit_err(cx, err_ty, fn_header_span); } check_result_large_err(cx, err_ty, hir_ty.span, large_err_threshold); diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 4f9680f60fe8..804fdc2da088 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -112,7 +112,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { } } - if !cx.access_levels.is_exported(item.def_id) { + if !cx.access_levels.is_exported(item.def_id.def_id) { return; } diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index 17d867aacb53..cb6c2ec0fb98 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -108,7 +108,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString { if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::String); // Filters instances of to_string which are required by a trait - if trait_ref_of_method(cx, impl_item.def_id).is_none(); + if trait_ref_of_method(cx, impl_item.def_id.def_id).is_none(); then { show_lint(cx, impl_item); diff --git a/clippy_lints/src/iter_not_returning_iterator.rs b/clippy_lints/src/iter_not_returning_iterator.rs index b56d87c5348c..2027c23d328c 100644 --- a/clippy_lints/src/iter_not_returning_iterator.rs +++ b/clippy_lints/src/iter_not_returning_iterator.rs @@ -44,7 +44,7 @@ impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator { let name = item.ident.name.as_str(); if matches!(name, "iter" | "iter_mut") { if let TraitItemKind::Fn(fn_sig, _) = &item.kind { - check_sig(cx, name, fn_sig, item.def_id); + check_sig(cx, name, fn_sig, item.def_id.def_id); } } } @@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator { ) { if let ImplItemKind::Fn(fn_sig, _) = &item.kind { - check_sig(cx, name, fn_sig, item.def_id); + check_sig(cx, name, fn_sig, item.def_id.def_id); } } } diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 7ae8ef830fae..7d15dd4cb216 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero { if item.ident.name == sym::len; if let ImplItemKind::Fn(sig, _) = &item.kind; if sig.decl.implicit_self.has_implicit_self(); - if cx.access_levels.is_exported(item.def_id); + if cx.access_levels.is_exported(item.def_id.def_id); if matches!(sig.decl.output, FnRetTy::Return(_)); if let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id()); if imp.of_trait.is_none(); @@ -210,7 +210,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items } } - if cx.access_levels.is_exported(visited_trait.def_id) && trait_items.iter().any(|i| is_named_self(cx, i, sym::len)) + if cx.access_levels.is_exported(visited_trait.def_id.def_id) && trait_items.iter().any(|i| is_named_self(cx, i, sym::len)) { let mut current_and_super_traits = DefIdSet::default(); fill_trait_set(visited_trait.def_id.to_def_id(), &mut current_and_super_traits, cx); diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 643a7cfd577b..399a03187d99 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -102,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { if let ImplItemKind::Fn(ref sig, id) = item.kind { - let report_extra_lifetimes = trait_ref_of_method(cx, item.def_id).is_none(); + let report_extra_lifetimes = trait_ref_of_method(cx, item.def_id.def_id).is_none(); check_fn_inner( cx, sig.decl, @@ -276,7 +276,7 @@ fn could_use_elision<'tcx>( let mut checker = BodyLifetimeChecker { lifetimes_used_in_body: false, }; - checker.visit_expr(body.value); + checker.visit_expr(&body.value); if checker.lifetimes_used_in_body { return false; } diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index fce2d54639cb..be7f96e9bb07 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -69,7 +69,7 @@ fn check_for_mutation<'tcx>( ExprUseVisitor::new( &mut delegate, &infcx, - body.hir_id.owner, + body.hir_id.owner.def_id, cx.param_env, cx.typeck_results(), ) diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 2b04475c7a9d..53e7565bd33f 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -166,7 +166,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum { if let Some((id, span)) = iter.next() && iter.next().is_none() { - self.potential_enums.push((item.def_id, id, item.span, span)); + self.potential_enums.push((item.def_id.def_id, id, item.span, span)); } } } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index cdde4c54d637..ddb6d1ca26c9 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3250,7 +3250,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { return; } let name = impl_item.ident.name.as_str(); - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); + let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(parent); let self_ty = cx.tcx.type_of(item.def_id); @@ -3259,7 +3259,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind; if let Some(first_arg) = iter_input_pats(sig.decl, cx.tcx.hir().body(id)).next(); - let method_sig = cx.tcx.fn_sig(impl_item.def_id); + let method_sig = cx.tcx.fn_sig(impl_item.def_id.def_id); let method_sig = cx.tcx.erase_late_bound_regions(method_sig); let first_arg_ty = method_sig.inputs().iter().next(); @@ -3269,7 +3269,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { then { // if this impl block implements a trait, lint in trait definition instead - if !implements_trait && cx.access_levels.is_exported(impl_item.def_id) { + if !implements_trait && cx.access_levels.is_exported(impl_item.def_id.def_id) { // check missing trait implementations for method_config in &TRAIT_METHODS { if name == method_config.method_name && @@ -3301,7 +3301,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if sig.decl.implicit_self.has_implicit_self() && !(self.avoid_breaking_exported_api - && cx.access_levels.is_exported(impl_item.def_id)) + && cx.access_levels.is_exported(impl_item.def_id.def_id)) { wrong_self_convention::check( cx, diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index bc304c081b90..f24b41411c81 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -136,7 +136,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { // Const fns are not allowed as methods in a trait. { - let parent = cx.tcx.hir().get_parent_item(hir_id); + let parent = cx.tcx.hir().get_parent_item(hir_id).def_id; if parent != CRATE_DEF_ID { if let hir::Node::Item(item) = cx.tcx.hir().get_by_def_id(parent) { if let hir::ItemKind::Trait(..) = &item.kind { diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 3701fdb4adbf..472195566768 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -131,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { hir::ItemKind::Fn(..) => { // ignore main() if it.ident.name == sym::main { - let at_root = cx.tcx.local_parent(it.def_id) == CRATE_DEF_ID; + let at_root = cx.tcx.local_parent(it.def_id.def_id) == CRATE_DEF_ID; if at_root { return; } diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 07bc2ca5d3cd..9d5764ac0926 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -88,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { return; } - if !cx.access_levels.is_exported(it.def_id) { + if !cx.access_levels.is_exported(it.def_id.def_id) { return; } match it.kind { @@ -142,7 +142,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { } // If the item being implemented is not exported, then we don't need #[inline] - if !cx.access_levels.is_exported(impl_item.def_id) { + if !cx.access_levels.is_exported(impl_item.def_id.def_id) { return; } @@ -159,7 +159,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { }; if let Some(trait_def_id) = trait_def_id { - if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.def_id) { + if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.def_id.def_id) { // If a trait is being implemented for an item, and the // trait is not exported, we don't need #[inline] return; diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 4db103bbc130..25d6ca83a94b 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'tcx>) { if let hir::ImplItemKind::Fn(ref sig, ..) = item.kind { - if trait_ref_of_method(cx, item.def_id).is_none() { + if trait_ref_of_method(cx, item.def_id.def_id).is_none() { check_sig(cx, item.hir_id(), sig.decl); } } diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 5c45ee6d94ad..357a71693d2c 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { // can't be implemented for unsafe new return; } - if cx.tcx.is_doc_hidden(impl_item.def_id) { + if cx.tcx.is_doc_hidden(impl_item.def_id.def_id) { // shouldn't be implemented when it is hidden in docs return; } @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { if_chain! { if sig.decl.inputs.is_empty(); if name == sym::new; - if cx.access_levels.is_reachable(impl_item.def_id); + if cx.access_levels.is_reachable(impl_item.def_id.def_id); let self_def_id = cx.tcx.hir().get_parent_item(id); let self_ty = cx.tcx.type_of(self_def_id); if self_ty == return_ty(cx, id); diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index b15884527321..616ef9e2f867 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -286,7 +286,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { if let ImplItemKind::Const(hir_ty, body_id) = &impl_item.kind { - let item_def_id = cx.tcx.hir().get_parent_item(impl_item.hir_id()); + let item_def_id = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(item_def_id); match &item.kind { diff --git a/clippy_lints/src/only_used_in_recursion.rs b/clippy_lints/src/only_used_in_recursion.rs index 6217110a1f3a..d64a9cf71e17 100644 --- a/clippy_lints/src/only_used_in_recursion.rs +++ b/clippy_lints/src/only_used_in_recursion.rs @@ -243,7 +243,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion { .. })) => { #[allow(trivial_casts)] - if let Some(Node::Item(item)) = get_parent_node(cx.tcx, cx.tcx.hir().local_def_id_to_hir_id(def_id)) + if let Some(Node::Item(item)) = get_parent_node(cx.tcx, def_id.into()) && let Some(trait_ref) = cx.tcx.impl_trait_ref(item.def_id) && let Some(trait_item_id) = cx.tcx.associated_item(def_id).trait_item_def_id { diff --git a/clippy_lints/src/operators/assign_op_pattern.rs b/clippy_lints/src/operators/assign_op_pattern.rs index 945a09a647c4..2c22c8b3d081 100644 --- a/clippy_lints/src/operators/assign_op_pattern.rs +++ b/clippy_lints/src/operators/assign_op_pattern.rs @@ -28,7 +28,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some((_, lang_item)) = binop_traits(op.node); if let Ok(trait_id) = cx.tcx.lang_items().require(lang_item); - let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id); + let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id).def_id; if trait_ref_of_method(cx, parent_fn) .map_or(true, |t| t.path.res.def_id() != trait_id); if implements_trait(cx, ty, trait_id, &[rty.into()]); diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 0960b050c240..6b2eea489322 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -261,7 +261,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { } if let hir::TraitItemKind::Fn(method_sig, _) = &item.kind { - self.check_poly_fn(cx, item.def_id, method_sig.decl, None); + self.check_poly_fn(cx, item.def_id.def_id, method_sig.decl, None); } } diff --git a/clippy_lints/src/redundant_pub_crate.rs b/clippy_lints/src/redundant_pub_crate.rs index 323326381d40..3c6ca9d98975 100644 --- a/clippy_lints/src/redundant_pub_crate.rs +++ b/clippy_lints/src/redundant_pub_crate.rs @@ -46,8 +46,8 @@ impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]); impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { if_chain! { - if cx.tcx.visibility(item.def_id) == ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()); - if !cx.access_levels.is_exported(item.def_id) && self.is_exported.last() == Some(&false); + if cx.tcx.visibility(item.def_id.def_id) == ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()); + if !cx.access_levels.is_exported(item.def_id.def_id) && self.is_exported.last() == Some(&false); if is_not_macro_export(item); then { let span = item.span.with_hi(item.ident.span.hi()); @@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { } if let ItemKind::Mod { .. } = item.kind { - self.is_exported.push(cx.access_levels.is_exported(item.def_id)); + self.is_exported.push(cx.access_levels.is_exported(item.def_id.def_id)); } } diff --git a/clippy_lints/src/return_self_not_must_use.rs b/clippy_lints/src/return_self_not_must_use.rs index 60be6bd335f6..16d702a3868d 100644 --- a/clippy_lints/src/return_self_not_must_use.rs +++ b/clippy_lints/src/return_self_not_must_use.rs @@ -128,7 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for ReturnSelfNotMustUse { fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'tcx>) { if let TraitItemKind::Fn(ref sig, _) = item.kind { - check_method(cx, sig.decl, item.def_id, item.span, item.hir_id()); + check_method(cx, sig.decl, item.def_id.def_id, item.span, item.hir_id()); } } } diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index 9cea4d880671..1ac538f4c7c0 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -51,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { _ => return, } - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); + let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(parent); let self_ty = cx.tcx.type_of(item.def_id); let ret_ty = return_ty(cx, impl_item.hir_id()); diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index 6add20c1fb71..d47ed459387e 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -64,11 +64,11 @@ impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl { // Check for more than one binary operation in the implemented function // Linting when multiple operations are involved can result in false positives - let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id); + let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id; if let hir::Node::ImplItem(impl_item) = cx.tcx.hir().get_by_def_id(parent_fn); if let hir::ImplItemKind::Fn(_, body_id) = impl_item.kind; let body = cx.tcx.hir().body(body_id); - let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id); + let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id; if let Some(trait_ref) = trait_ref_of_method(cx, parent_fn); let trait_id = trait_ref.path.res.def_id(); if ![binop_trait_id, op_assign_trait_id].contains(&trait_id); diff --git a/clippy_lints/src/transmute/utils.rs b/clippy_lints/src/transmute/utils.rs index 8bdadf244023..8e90d20265ce 100644 --- a/clippy_lints/src/transmute/utils.rs +++ b/clippy_lints/src/transmute/utils.rs @@ -42,7 +42,7 @@ pub(super) fn can_be_expressed_as_pointer_cast<'tcx>( /// messages. This function will panic if that occurs. fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> Option { let hir_id = e.hir_id; - let local_def_id = hir_id.owner; + let local_def_id = hir_id.owner.def_id; Inherited::build(cx.tcx, local_def_id).enter(|inherited| { let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, hir_id); diff --git a/clippy_lints/src/types/borrowed_box.rs b/clippy_lints/src/types/borrowed_box.rs index 94945b2e1a9e..1268c23206a6 100644 --- a/clippy_lints/src/types/borrowed_box.rs +++ b/clippy_lints/src/types/borrowed_box.rs @@ -104,7 +104,7 @@ fn get_bounds_if_impl_trait<'tcx>(cx: &LateContext<'tcx>, qpath: &QPath<'_>, id: if let Some(Node::GenericParam(generic_param)) = cx.tcx.hir().get_if_local(did); if let GenericParamKind::Type { synthetic, .. } = generic_param.kind; if synthetic; - if let Some(generics) = cx.tcx.hir().get_generics(id.owner); + if let Some(generics) = cx.tcx.hir().get_generics(id.owner.def_id); if let Some(pred) = generics.bounds_for_param(did.expect_local()).next(); then { Some(pred.bounds) diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 353a6f6b899e..aca55817c525 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -313,7 +313,7 @@ impl_lint_pass!(Types => [BOX_COLLECTION, VEC_BOX, OPTION_OPTION, LINKEDLIST, BO impl<'tcx> LateLintPass<'tcx> for Types { fn check_fn(&mut self, cx: &LateContext<'_>, _: FnKind<'_>, decl: &FnDecl<'_>, _: &Body<'_>, _: Span, id: HirId) { let is_in_trait_impl = - if let Some(hir::Node::Item(item)) = cx.tcx.hir().find_by_def_id(cx.tcx.hir().get_parent_item(id)) { + if let Some(hir::Node::Item(item)) = cx.tcx.hir().find_by_def_id(cx.tcx.hir().get_parent_item(id).def_id) { matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) } else { false @@ -333,7 +333,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { } fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - let is_exported = cx.access_levels.is_exported(item.def_id); + let is_exported = cx.access_levels.is_exported(item.def_id.def_id); match item.kind { ItemKind::Static(ty, _, _) | ItemKind::Const(ty, _) => self.check_ty( @@ -353,7 +353,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { match item.kind { ImplItemKind::Const(ty, _) => { let is_in_trait_impl = if let Some(hir::Node::Item(item)) = - cx.tcx.hir().find_by_def_id(cx.tcx.hir().get_parent_item(item.hir_id())) + cx.tcx.hir().find_by_def_id(cx.tcx.hir().get_parent_item(item.hir_id()).def_id) { matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) } else { @@ -390,7 +390,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { } fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &TraitItem<'_>) { - let is_exported = cx.access_levels.is_exported(item.def_id); + let is_exported = cx.access_levels.is_exported(item.def_id.def_id); let context = CheckTyContext { is_exported, diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index 51c65d898cf5..713fe06bad43 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -54,14 +54,14 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf { if impl_item.span.from_expansion() { return; } - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); + let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; let parent_item = cx.tcx.hir().expect_item(parent); let assoc_item = cx.tcx.associated_item(impl_item.def_id); if_chain! { if let ItemKind::Impl(Impl { of_trait: None, .. }) = parent_item.kind; if assoc_item.fn_has_self_parameter; if let ImplItemKind::Fn(.., body_id) = &impl_item.kind; - if !cx.access_levels.is_exported(impl_item.def_id) || !self.avoid_breaking_exported_api; + if !cx.access_levels.is_exported(impl_item.def_id.def_id) || !self.avoid_breaking_exported_api; let body = cx.tcx.hir().body(*body_id); if let [self_param, ..] = body.params; if !is_local_used(cx, body, self_param.pat.hir_id); diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs index 46020adcaa2c..baa53ba664f6 100644 --- a/clippy_lints/src/unwrap_in_result.rs +++ b/clippy_lints/src/unwrap_in_result.rs @@ -111,7 +111,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_item: &'tc let body = cx.tcx.hir().body(body_id); let mut fpu = FindExpectUnwrap { lcx: cx, - typeck_results: cx.tcx.typeck(impl_item.def_id), + typeck_results: cx.tcx.typeck(impl_item.def_id.def_id), result: Vec::new(), }; fpu.visit_expr(body.value); diff --git a/clippy_lints/src/upper_case_acronyms.rs b/clippy_lints/src/upper_case_acronyms.rs index 02bf09ed5068..2c71f35d490c 100644 --- a/clippy_lints/src/upper_case_acronyms.rs +++ b/clippy_lints/src/upper_case_acronyms.rs @@ -105,7 +105,7 @@ impl LateLintPass<'_> for UpperCaseAcronyms { fn check_item(&mut self, cx: &LateContext<'_>, it: &Item<'_>) { // do not lint public items or in macros if in_external_macro(cx.sess(), it.span) - || (self.avoid_breaking_exported_api && cx.access_levels.is_exported(it.def_id)) + || (self.avoid_breaking_exported_api && cx.access_levels.is_exported(it.def_id.def_id)) { return; } diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 44ab9bca7959..ce51cb693fc0 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -106,7 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { if !is_from_proc_macro(cx, item); // expensive, should be last check then { StackItem::Check { - impl_id: item.def_id, + impl_id: item.def_id.def_id, in_body: 0, types_to_skip: std::iter::once(self_ty.hir_id).collect(), } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 4003fff27c00..1df3135c962d 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -140,7 +140,7 @@ impl<'tcx> LateLintPass<'tcx> for Author { fn check_item(cx: &LateContext<'_>, hir_id: HirId) { let hir = cx.tcx.hir(); - if let Some(body_id) = hir.maybe_body_owned_by(hir_id.expect_owner()) { + if let Some(body_id) = hir.maybe_body_owned_by(hir_id.expect_owner().def_id) { check_node(cx, hir_id, |v| { v.expr(&v.bind("expr", hir.body(body_id).value)); }); diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 5418eca382da..2604b1ee7c56 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -120,14 +120,14 @@ impl LateLintPass<'_> for WildcardImports { if is_test_module_or_function(cx.tcx, item) { self.test_modules_deep = self.test_modules_deep.saturating_add(1); } - let module = cx.tcx.parent_module_from_def_id(item.def_id); - if cx.tcx.visibility(item.def_id) != ty::Visibility::Restricted(module.to_def_id()) { + let module = cx.tcx.parent_module_from_def_id(item.def_id.def_id); + if cx.tcx.visibility(item.def_id.def_id) != ty::Visibility::Restricted(module.to_def_id()) { return; } if_chain! { if let ItemKind::Use(use_path, UseKind::Glob) = &item.kind; if self.warn_on_all || !self.check_exceptions(item, use_path.segments); - let used_imports = cx.tcx.names_imported_by_glob_use(item.def_id); + let used_imports = cx.tcx.names_imported_by_glob_use(item.def_id.def_id); if !used_imports.is_empty(); // Already handled by `unused_imports` then { let mut applicability = Applicability::MachineApplicable; diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 8dc43c0e2943..386f3c527f17 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -72,7 +72,7 @@ fn in_trait_impl(cx: &LateContext<'_>, hir_id: HirId) -> bool { let second_parent_id = cx .tcx .hir() - .get_parent_item(cx.tcx.hir().local_def_id_to_hir_id(parent_id)); + .get_parent_item(parent_id.into()).def_id; if let Some(Node::Item(item)) = cx.tcx.hir().find_by_def_id(second_parent_id) { if let ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind { return true; diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 62da850a15e7..9343cf457b34 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -78,7 +78,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::unhash::UnhashMap; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_ID}; +use rustc_hir::def_id::{CrateNum, DefId, LocalDefId}; use rustc_hir::hir_id::{HirIdMap, HirIdSet}; use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; use rustc_hir::LangItem::{OptionNone, ResultErr, ResultOk}; @@ -212,7 +212,7 @@ pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option< /// } /// ``` pub fn in_constant(cx: &LateContext<'_>, id: HirId) -> bool { - let parent_id = cx.tcx.hir().get_parent_item(id); + let parent_id = cx.tcx.hir().get_parent_item(id).def_id; match cx.tcx.hir().get_by_def_id(parent_id) { Node::Item(&Item { kind: ItemKind::Const(..) | ItemKind::Static(..), @@ -597,8 +597,8 @@ pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, def_id: LocalDefId) -> let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); let parent_impl = cx.tcx.hir().get_parent_item(hir_id); if_chain! { - if parent_impl != CRATE_DEF_ID; - if let hir::Node::Item(item) = cx.tcx.hir().get_by_def_id(parent_impl); + if parent_impl != hir::CRATE_OWNER_ID; + if let hir::Node::Item(item) = cx.tcx.hir().get_by_def_id(parent_impl.def_id); if let hir::ItemKind::Impl(impl_) = &item.kind; then { return impl_.of_trait.as_ref(); @@ -1104,7 +1104,7 @@ pub fn is_in_panic_handler(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { /// Gets the name of the item the expression is in, if available. pub fn get_item_name(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { - let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id); + let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id).def_id; match cx.tcx.hir().find_by_def_id(parent_id) { Some( Node::Item(Item { ident, .. }) @@ -1648,7 +1648,7 @@ pub fn any_parent_has_attr(tcx: TyCtxt<'_>, node: HirId, symbol: Symbol) -> bool return true; } prev_enclosing_node = Some(enclosing_node); - enclosing_node = map.local_def_id_to_hir_id(map.get_parent_item(enclosing_node)); + enclosing_node = map.get_parent_item(enclosing_node).into(); } false diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index 3af5dfb62f97..a7c08839f524 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -21,7 +21,7 @@ pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) -> ExprUseVisitor::new( &mut delegate, &infcx, - expr.hir_id.owner, + expr.hir_id.owner.def_id, cx.param_env, cx.typeck_results(), ) From 95d2ea44e1f13fc1ef113f5478384bd4b1a520d9 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Tue, 20 Sep 2022 15:41:42 +0200 Subject: [PATCH 0626/1222] remove cfg(bootstrap) --- clippy_dev/src/lib.rs | 1 - clippy_lints/src/lib.rs | 1 - clippy_utils/src/lib.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index 54c7456a2a3b..80bb83af43b1 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -1,5 +1,4 @@ #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(once_cell)] #![feature(rustc_private)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 298566cb5b62..00bf6445c12d 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -5,7 +5,6 @@ #![feature(drain_filter)] #![feature(iter_intersperse)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(lint_reasons)] #![feature(never_type)] #![feature(once_cell)] diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 9343cf457b34..b1abd3b04c92 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -3,7 +3,6 @@ #![feature(control_flow_enum)] #![feature(let_chains)] #![feature(lint_reasons)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(once_cell)] #![feature(rustc_private)] #![recursion_limit = "512"] From 3a7de3bd2ece4fc70de751889ba8aea1575fbd9f Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 26 Sep 2022 13:00:29 +0200 Subject: [PATCH 0627/1222] rustc_typeck to rustc_hir_analysis --- clippy_lints/src/default_union_representation.rs | 2 +- clippy_lints/src/escape.rs | 4 ++-- clippy_lints/src/implicit_hasher.rs | 2 +- clippy_lints/src/large_const_arrays.rs | 2 +- clippy_lints/src/lib.rs | 2 +- clippy_lints/src/loops/mut_range_bound.rs | 4 ++-- clippy_lints/src/loops/utils.rs | 2 +- clippy_lints/src/matches/needless_match.rs | 2 +- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/methods/unnecessary_to_owned.rs | 2 +- clippy_lints/src/missing_const_for_fn.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/operators/assign_op_pattern.rs | 2 +- clippy_lints/src/transmute/utils.rs | 2 +- clippy_lints/src/types/redundant_allocation.rs | 2 +- clippy_lints/src/types/vec_box.rs | 2 +- clippy_lints/src/use_self.rs | 2 +- clippy_lints/src/utils/internal_lints.rs | 2 +- clippy_lints/src/zero_sized_map_values.rs | 2 +- clippy_utils/src/lib.rs | 4 ++-- clippy_utils/src/sugg.rs | 4 ++-- clippy_utils/src/usage.rs | 4 ++-- tests/ui/transmutes_expressible_as_ptr_casts.fixed | 2 +- tests/ui/transmutes_expressible_as_ptr_casts.rs | 2 +- 25 files changed, 31 insertions(+), 31 deletions(-) diff --git a/clippy_lints/src/default_union_representation.rs b/clippy_lints/src/default_union_representation.rs index d559ad423df5..3905a6c2e211 100644 --- a/clippy_lints/src/default_union_representation.rs +++ b/clippy_lints/src/default_union_representation.rs @@ -4,7 +4,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::layout::LayoutOf; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; -use rustc_typeck::hir_ty_to_ty; +use rustc_hir_analysis::hir_ty_to_ty; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index a6ddb26e2dee..8ccc969646ec 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -10,7 +10,7 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; use rustc_span::symbol::kw; use rustc_target::spec::abi::Abi; -use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; +use rustc_hir_analysis::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; #[derive(Copy, Clone)] pub struct BoxedLocal { @@ -177,7 +177,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { } } - fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {} + fn fake_read(&mut self, _: &rustc_hir_analysis::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {} } impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> { diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 804fdc2da088..a920c3bba2ae 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -12,7 +12,7 @@ use rustc_middle::ty::{Ty, TypeckResults}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::symbol::sym; -use rustc_typeck::hir_ty_to_ty; +use rustc_hir_analysis::hir_ty_to_ty; use if_chain::if_chain; diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index 984c5cd4e37c..d6eb53ae29b5 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -7,7 +7,7 @@ use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, ConstKind}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{BytePos, Pos, Span}; -use rustc_typeck::hir_ty_to_ty; +use rustc_hir_analysis::hir_ty_to_ty; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 00bf6445c12d..c3db194c4ad8 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -43,7 +43,7 @@ extern crate rustc_session; extern crate rustc_span; extern crate rustc_target; extern crate rustc_trait_selection; -extern crate rustc_typeck; +extern crate rustc_hir_analysis; #[macro_use] extern crate clippy_utils; diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index be7f96e9bb07..6d585c2e45de 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -8,7 +8,7 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::{mir::FakeReadCause, ty}; use rustc_span::source_map::Span; -use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; +use rustc_hir_analysis::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>, body: &Expr<'_>) { if_chain! { @@ -114,7 +114,7 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> { } } - fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {} + fn fake_read(&mut self, _: &rustc_hir_analysis::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {} } impl MutatePairDelegate<'_, '_> { diff --git a/clippy_lints/src/loops/utils.rs b/clippy_lints/src/loops/utils.rs index 4801a84eb92c..f1f58db80b30 100644 --- a/clippy_lints/src/loops/utils.rs +++ b/clippy_lints/src/loops/utils.rs @@ -10,7 +10,7 @@ use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, Ty}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{sym, Symbol}; -use rustc_typeck::hir_ty_to_ty; +use rustc_hir_analysis::hir_ty_to_ty; use std::iter::Iterator; #[derive(Debug, PartialEq, Eq)] diff --git a/clippy_lints/src/matches/needless_match.rs b/clippy_lints/src/matches/needless_match.rs index 634eef82e532..58ea43e69d9b 100644 --- a/clippy_lints/src/matches/needless_match.rs +++ b/clippy_lints/src/matches/needless_match.rs @@ -11,7 +11,7 @@ use rustc_hir::LangItem::OptionNone; use rustc_hir::{Arm, BindingAnnotation, ByRef, Expr, ExprKind, FnRetTy, Guard, Node, Pat, PatKind, Path, QPath}; use rustc_lint::LateContext; use rustc_span::sym; -use rustc_typeck::hir_ty_to_ty; +use rustc_hir_analysis::hir_ty_to_ty; pub(crate) fn check_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { if arms.len() > 1 && expr_ty_matches_p_ty(cx, ex, expr) && check_all_arms(cx, ex, arms) { diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index ddb6d1ca26c9..428a354ec6b1 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -115,7 +115,7 @@ use rustc_middle::ty::{self, TraitRef, Ty}; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{sym, Span}; -use rustc_typeck::hir_ty_to_ty; +use rustc_hir_analysis::hir_ty_to_ty; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 79d784c342ca..559f32a563ed 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -18,7 +18,7 @@ use rustc_middle::ty::{self, ParamTy, PredicateKind, ProjectionPredicate, TraitP use rustc_semver::RustcVersion; use rustc_span::{sym, Symbol}; use rustc_trait_selection::traits::{query::evaluate_obligation::InferCtxtExt as _, Obligation, ObligationCause}; -use rustc_typeck::check::{FnCtxt, Inherited}; +use rustc_hir_analysis::check::{FnCtxt, Inherited}; use std::cmp::max; use super::UNNECESSARY_TO_OWNED; diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index f24b41411c81..00376f0d7902 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -13,7 +13,7 @@ use rustc_middle::lint::in_external_macro; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; -use rustc_typeck::hir_ty_to_ty; +use rustc_hir_analysis::hir_ty_to_ty; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 060037ed4969..4f46872439c3 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -22,7 +22,7 @@ use rustc_span::{sym, Span}; use rustc_target::spec::abi::Abi; use rustc_trait_selection::traits; use rustc_trait_selection::traits::misc::can_type_implement_copy; -use rustc_typeck::expr_use_visitor as euv; +use rustc_hir_analysis::expr_use_visitor as euv; use std::borrow::Cow; declare_clippy_lint! { @@ -341,5 +341,5 @@ impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt { fn mutate(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId) {} - fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {} + fn fake_read(&mut self, _: &rustc_hir_analysis::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {} } diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 616ef9e2f867..48ff737dae7b 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -20,7 +20,7 @@ use rustc_middle::ty::adjustment::Adjust; use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, InnerSpan, Span, DUMMY_SP}; -use rustc_typeck::hir_ty_to_ty; +use rustc_hir_analysis::hir_ty_to_ty; // FIXME: this is a correctness problem but there's no suitable // warn-by-default category. diff --git a/clippy_lints/src/operators/assign_op_pattern.rs b/clippy_lints/src/operators/assign_op_pattern.rs index 2c22c8b3d081..f134c6c4cdba 100644 --- a/clippy_lints/src/operators/assign_op_pattern.rs +++ b/clippy_lints/src/operators/assign_op_pattern.rs @@ -11,7 +11,7 @@ use rustc_lint::LateContext; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::BorrowKind; use rustc_trait_selection::infer::TyCtxtInferExt; -use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; +use rustc_hir_analysis::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use super::ASSIGN_OP_PATTERN; diff --git a/clippy_lints/src/transmute/utils.rs b/clippy_lints/src/transmute/utils.rs index 8e90d20265ce..fdf847bf4459 100644 --- a/clippy_lints/src/transmute/utils.rs +++ b/clippy_lints/src/transmute/utils.rs @@ -2,7 +2,7 @@ use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_middle::ty::{cast::CastKind, Ty}; use rustc_span::DUMMY_SP; -use rustc_typeck::check::{cast::{self, CastCheckResult}, FnCtxt, Inherited}; +use rustc_hir_analysis::check::{cast::{self, CastCheckResult}, FnCtxt, Inherited}; // check if the component types of the transmuted collection and the result have different ABI, // size or alignment diff --git a/clippy_lints/src/types/redundant_allocation.rs b/clippy_lints/src/types/redundant_allocation.rs index a1312fcda0b7..d81c5c83845d 100644 --- a/clippy_lints/src/types/redundant_allocation.rs +++ b/clippy_lints/src/types/redundant_allocation.rs @@ -5,7 +5,7 @@ use rustc_errors::Applicability; use rustc_hir::{self as hir, def_id::DefId, QPath, TyKind}; use rustc_lint::LateContext; use rustc_span::symbol::sym; -use rustc_typeck::hir_ty_to_ty; +use rustc_hir_analysis::hir_ty_to_ty; use super::{utils, REDUNDANT_ALLOCATION}; diff --git a/clippy_lints/src/types/vec_box.rs b/clippy_lints/src/types/vec_box.rs index b2f536ca7815..236f9955722d 100644 --- a/clippy_lints/src/types/vec_box.rs +++ b/clippy_lints/src/types/vec_box.rs @@ -8,7 +8,7 @@ use rustc_lint::LateContext; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::TypeVisitable; use rustc_span::symbol::sym; -use rustc_typeck::hir_ty_to_ty; +use rustc_hir_analysis::hir_ty_to_ty; use super::VEC_BOX; diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index ce51cb693fc0..6a767967ef40 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -16,7 +16,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; -use rustc_typeck::hir_ty_to_ty; +use rustc_hir_analysis::hir_ty_to_ty; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 17d9a0418576..78c036186f50 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -32,7 +32,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Spanned; use rustc_span::symbol::Symbol; use rustc_span::{sym, BytePos, Span}; -use rustc_typeck::hir_ty_to_ty; +use rustc_hir_analysis::hir_ty_to_ty; use std::borrow::{Borrow, Cow}; diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 386f3c527f17..703ba2ef4b05 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -7,7 +7,7 @@ use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::{Adt, Ty, TypeVisitable}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; -use rustc_typeck::hir_ty_to_ty; +use rustc_hir_analysis::hir_ty_to_ty; declare_clippy_lint! { /// ### What it does diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index b1abd3b04c92..627d6b51944a 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -32,7 +32,7 @@ extern crate rustc_session; extern crate rustc_span; extern crate rustc_target; extern crate rustc_trait_selection; -extern crate rustc_typeck; +extern crate rustc_hir_analysis; #[macro_use] pub mod sym_helper; @@ -1386,7 +1386,7 @@ pub fn is_integer_literal(expr: &Expr<'_>, value: u128) -> bool { /// Examples of coercions can be found in the Nomicon at /// . /// -/// See `rustc_middle::ty::adjustment::Adjustment` and `rustc_typeck::check::coercion` for more +/// See `rustc_middle::ty::adjustment::Adjustment` and `rustc_hir_analysis::check::coercion` for more /// information on adjustments and coercions. pub fn is_adjusted(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { cx.typeck_results().adjustments().get(e.hir_id).is_some() diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index f08275a4ac76..e53c40e95760 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -16,7 +16,7 @@ use rustc_middle::hir::place::ProjectionKind; use rustc_middle::mir::{FakeReadCause, Mutability}; use rustc_middle::ty; use rustc_span::source_map::{BytePos, CharPos, Pos, Span, SyntaxContext}; -use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; +use rustc_hir_analysis::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use std::borrow::Cow; use std::fmt::{Display, Write as _}; use std::ops::{Add, Neg, Not, Sub}; @@ -1056,7 +1056,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> { fn mutate(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {} - fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {} + fn fake_read(&mut self, _: &rustc_hir_analysis::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {} } #[cfg(test)] diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index a7c08839f524..76bfec75726d 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -9,7 +9,7 @@ use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty; -use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; +use rustc_hir_analysis::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; /// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined. pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) -> Option { @@ -73,7 +73,7 @@ impl<'tcx> Delegate<'tcx> for MutVarsDelegate { self.update(cmt); } - fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {} + fn fake_read(&mut self, _: &rustc_hir_analysis::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {} } pub struct ParamBindingIdCollector { diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.fixed b/tests/ui/transmutes_expressible_as_ptr_casts.fixed index 539239fc18f9..7263abac15df 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.fixed +++ b/tests/ui/transmutes_expressible_as_ptr_casts.fixed @@ -8,7 +8,7 @@ use std::mem::{size_of, transmute}; -// rustc_typeck::check::cast contains documentation about when a cast `e as U` is +// rustc_hir_analysis::check::cast contains documentation about when a cast `e as U` is // valid, which we quote from below. fn main() { // We should see an error message for each transmute, and no error messages for diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs index b9e446dc89a9..d8e4421d4c18 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -8,7 +8,7 @@ use std::mem::{size_of, transmute}; -// rustc_typeck::check::cast contains documentation about when a cast `e as U` is +// rustc_hir_analysis::check::cast contains documentation about when a cast `e as U` is // valid, which we quote from below. fn main() { // We should see an error message for each transmute, and no error messages for From 54b355bd2cbd60be51e1c4afa1c15d82e9a3874e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 16 Sep 2022 11:45:33 +1000 Subject: [PATCH 0628/1222] Shrink `hir::def::Res`. `Res::SelfTy` currently has two `Option`s. When the second one is `Some` the first one is never consulted. So we can split it into two variants, `Res::SelfTyParam` and `Res::SelfTyAlias`, reducing the size of `Res` from 24 bytes to 12. This then shrinks `hir::Path` and `hir::PathSegment`, which are the HIR types that take up the most space. --- clippy_lints/src/trait_bounds.rs | 2 +- clippy_lints/src/use_self.rs | 9 +++++++-- clippy_utils/src/lib.rs | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index a25be93b8d61..2be22884027e 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -128,7 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { if !bound_predicate.span.from_expansion(); if let TyKind::Path(QPath::Resolved(_, Path { segments, .. })) = bound_predicate.bounded_ty.kind; if let Some(PathSegment { - res: Res::SelfTy{ trait_: Some(def_id), alias_to: _ }, .. + res: Res::SelfTyParam { trait_: def_id }, .. }) = segments.first(); if let Some( Node::Item( diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 6a767967ef40..2c4f5075e980 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -206,7 +206,12 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { ref types_to_skip, }) = self.stack.last(); if let TyKind::Path(QPath::Resolved(_, path)) = hir_ty.kind; - if !matches!(path.res, Res::SelfTy { .. } | Res::Def(DefKind::TyParam, _)); + if !matches!( + path.res, + Res::SelfTyParam { .. } + | Res::SelfTyAlias { .. } + | Res::Def(DefKind::TyParam, _) + ); if !types_to_skip.contains(&hir_ty.hir_id); let ty = if in_body > 0 { cx.typeck_results().node_type(hir_ty.hir_id) @@ -230,7 +235,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { } match expr.kind { ExprKind::Struct(QPath::Resolved(_, path), ..) => match path.res { - Res::SelfTy { .. } => (), + Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => (), Res::Def(DefKind::Variant, _) => lint_path_to_variant(cx, path), _ => span_lint(cx, path.span), }, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 627d6b51944a..8f79c07c9772 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1535,7 +1535,7 @@ pub fn is_self(slf: &Param<'_>) -> bool { pub fn is_self_ty(slf: &hir::Ty<'_>) -> bool { if let TyKind::Path(QPath::Resolved(None, path)) = slf.kind { - if let Res::SelfTy { .. } = path.res { + if let Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } = path.res { return true; } } From cd56053424b9022a19e2a88e57582ef4afa7ba1e Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 16 Sep 2022 19:07:01 +0400 Subject: [PATCH 0629/1222] clippy: adopt to the new lint API --- clippy_lints/src/module_style.rs | 19 +++++++------ clippy_utils/src/diagnostics.rs | 46 ++++++++++++++------------------ 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/clippy_lints/src/module_style.rs b/clippy_lints/src/module_style.rs index 22071ab3044f..102b9fbae83c 100644 --- a/clippy_lints/src/module_style.rs +++ b/clippy_lints/src/module_style.rs @@ -117,11 +117,13 @@ impl EarlyLintPass for ModStyle { cx.struct_span_lint( SELF_NAMED_MODULE_FILES, Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None), - |build| { - let mut lint = - build.build(&format!("`mod.rs` files are required, found `{}`", path.display())); - lint.help(&format!("move `{}` to `{}`", path.display(), correct.display(),)); - lint.emit(); + format!("`mod.rs` files are required, found `{}`", path.display()), + |lint| { + lint.help(format!( + "move `{}` to `{}`", + path.display(), + correct.display(), + )) }, ); } @@ -156,11 +158,8 @@ fn check_self_named_mod_exists(cx: &EarlyContext<'_>, path: &Path, file: &Source cx.struct_span_lint( MOD_MODULE_FILES, Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None), - |build| { - let mut lint = build.build(&format!("`mod.rs` files are not allowed, found `{}`", path.display())); - lint.help(&format!("move `{}` to `{}`", path.display(), mod_file.display(),)); - lint.emit(); - }, + format!("`mod.rs` files are not allowed, found `{}`", path.display()), + |lint| lint.help(format!("move `{}` to `{}`", path.display(), mod_file.display())), ); } } diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs index ad95369b9ef7..78960d1ab1da 100644 --- a/clippy_utils/src/diagnostics.rs +++ b/clippy_utils/src/diagnostics.rs @@ -47,10 +47,9 @@ fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) { /// | ^^^^^^^^^^^^^^^^^^^^^^^ /// ``` pub fn span_lint(cx: &T, lint: &'static Lint, sp: impl Into, msg: &str) { - cx.struct_span_lint(lint, sp, |diag| { - let mut diag = diag.build(msg); - docs_link(&mut diag, lint); - diag.emit(); + cx.struct_span_lint(lint, sp, msg, |diag| { + docs_link(diag, lint); + diag }); } @@ -82,15 +81,14 @@ pub fn span_lint_and_help<'a, T: LintContext>( help_span: Option, help: &str, ) { - cx.struct_span_lint(lint, span, |diag| { - let mut diag = diag.build(msg); + cx.struct_span_lint(lint, span, msg, |diag| { if let Some(help_span) = help_span { diag.span_help(help_span, help); } else { diag.help(help); } - docs_link(&mut diag, lint); - diag.emit(); + docs_link(diag, lint); + diag }); } @@ -125,15 +123,14 @@ pub fn span_lint_and_note<'a, T: LintContext>( note_span: Option, note: &str, ) { - cx.struct_span_lint(lint, span, |diag| { - let mut diag = diag.build(msg); + cx.struct_span_lint(lint, span, msg, |diag| { if let Some(note_span) = note_span { diag.span_note(note_span, note); } else { diag.note(note); } - docs_link(&mut diag, lint); - diag.emit(); + docs_link(diag, lint); + diag }); } @@ -147,19 +144,17 @@ where S: Into, F: FnOnce(&mut Diagnostic), { - cx.struct_span_lint(lint, sp, |diag| { - let mut diag = diag.build(msg); - f(&mut diag); - docs_link(&mut diag, lint); - diag.emit(); + cx.struct_span_lint(lint, sp, msg, |diag| { + f(diag); + docs_link(diag, lint); + diag }); } pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) { - cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| { - let mut diag = diag.build(msg); - docs_link(&mut diag, lint); - diag.emit(); + cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg, |diag| { + docs_link(diag, lint); + diag }); } @@ -171,11 +166,10 @@ pub fn span_lint_hir_and_then( msg: &str, f: impl FnOnce(&mut Diagnostic), ) { - cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| { - let mut diag = diag.build(msg); - f(&mut diag); - docs_link(&mut diag, lint); - diag.emit(); + cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg, |diag| { + f(diag); + docs_link(diag, lint); + diag }); } From c5afd92eaa6c7049ce74620603db9d85ec462d94 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 22 Sep 2022 20:04:22 +0400 Subject: [PATCH 0630/1222] bless clippy --- .../await_holding_invalid_type.stderr | 2 +- .../conf_deprecated_key/conf_deprecated_key.stderr | 2 +- tests/ui-toml/expect_used/expect_used.stderr | 2 +- tests/ui-toml/fn_params_excessive_bools/test.stderr | 2 +- .../large_include_file/large_include_file.stderr | 2 +- .../conf_nonstandard_macro_braces.stderr | 2 +- .../strict_non_send_fields_in_send_ty/test.stderr | 2 +- tests/ui-toml/struct_excessive_bools/test.stderr | 2 +- tests/ui-toml/unwrap_used/unwrap_used.stderr | 2 +- tests/ui/absurd-extreme-comparisons.stderr | 2 +- tests/ui/allow_attributes_without_reason.stderr | 2 +- tests/ui/approx_const.stderr | 2 +- tests/ui/as_conversions.stderr | 2 +- tests/ui/asm_syntax.stderr | 4 ++-- tests/ui/assertions_on_constants.stderr | 2 +- tests/ui/await_holding_lock.stderr | 2 +- tests/ui/await_holding_refcell_ref.stderr | 2 +- tests/ui/blanket_clippy_restriction_lints.stderr | 2 +- tests/ui/bool_to_int_with_if.stderr | 2 +- tests/ui/borrow_interior_mutable_const/enums.stderr | 2 +- tests/ui/borrow_interior_mutable_const/others.stderr | 2 +- tests/ui/borrow_interior_mutable_const/traits.stderr | 2 +- tests/ui/box_collection.stderr | 2 +- tests/ui/branches_sharing_code/shared_at_bottom.stderr | 2 +- tests/ui/branches_sharing_code/shared_at_top.stderr | 10 +++++----- .../shared_at_top_and_bottom.stderr | 10 +++++----- tests/ui/branches_sharing_code/valid_if_blocks.stderr | 10 +++++----- .../case_sensitive_file_extension_comparisons.stderr | 2 +- tests/ui/char_lit_as_u8.stderr | 2 +- tests/ui/char_lit_as_u8_suggestions.stderr | 2 +- tests/ui/checked_unwrap/complex_conditionals.stderr | 2 +- tests/ui/cognitive_complexity.stderr | 2 +- tests/ui/cognitive_complexity_attr_used.stderr | 2 +- tests/ui/collapsible_match.stderr | 2 +- tests/ui/collapsible_match2.stderr | 2 +- tests/ui/comparison_chain.stderr | 2 +- tests/ui/copy_iterator.stderr | 2 +- tests/ui/crashes/ice-360.stderr | 2 +- tests/ui/crashes/ice-6254.stderr | 2 +- tests/ui/crashes/ice-7868.stderr | 2 +- tests/ui/crashes/ice-7869.stderr | 2 +- tests/ui/crashes/ice-9463.stderr | 2 +- .../ui/crate_level_checks/entrypoint_recursion.stderr | 2 +- tests/ui/crate_level_checks/no_std_swap.stderr | 2 +- tests/ui/crate_level_checks/std_main_recursion.stderr | 2 +- tests/ui/def_id_nocore.stderr | 2 +- tests/ui/default_union_representation.stderr | 2 +- tests/ui/derive.stderr | 2 +- tests/ui/derive_hash_xor_eq.stderr | 2 +- tests/ui/derive_ord_xor_partial_ord.stderr | 2 +- tests/ui/doc/unbalanced_ticks.stderr | 2 +- tests/ui/double_must_use.stderr | 2 +- tests/ui/drop_forget_copy.stderr | 4 ++-- tests/ui/drop_non_drop.stderr | 2 +- tests/ui/drop_ref.stderr | 2 +- tests/ui/else_if_without_else.stderr | 2 +- tests/ui/empty_enum.stderr | 2 +- tests/ui/empty_loop.stderr | 2 +- tests/ui/empty_loop_no_std.stderr | 2 +- tests/ui/expect.stderr | 2 +- tests/ui/fallible_impl_from.stderr | 10 +++++----- tests/ui/field_reassign_with_default.stderr | 2 +- tests/ui/filetype_is_file.stderr | 2 +- tests/ui/float_cmp.stderr | 2 +- tests/ui/float_cmp_const.stderr | 2 +- tests/ui/fn_params_excessive_bools.stderr | 2 +- tests/ui/for_loops_over_fallibles.stderr | 2 +- tests/ui/forget_non_drop.stderr | 2 +- tests/ui/forget_ref.stderr | 2 +- tests/ui/format_args_unfixable.stderr | 2 +- tests/ui/format_push_string.stderr | 2 +- tests/ui/formatting.stderr | 4 ++-- tests/ui/from_over_into.stderr | 2 +- tests/ui/future_not_send.stderr | 2 +- tests/ui/get_unwrap.stderr | 2 +- tests/ui/if_let_mutex.stderr | 2 +- tests/ui/if_not_else.stderr | 2 +- tests/ui/if_same_then_else.stderr | 2 +- tests/ui/if_same_then_else2.stderr | 2 +- tests/ui/if_then_some_else_none.stderr | 2 +- tests/ui/ifs_same_cond.stderr | 2 +- tests/ui/impl.stderr | 2 +- tests/ui/indexing_slicing_index.stderr | 2 +- tests/ui/indexing_slicing_slice.stderr | 2 +- tests/ui/inefficient_to_string.stderr | 2 +- tests/ui/infinite_loop.stderr | 2 +- tests/ui/inherent_to_string.stderr | 4 ++-- tests/ui/inspect_for_each.stderr | 2 +- tests/ui/integer_division.stderr | 2 +- tests/ui/issue_4266.stderr | 2 +- tests/ui/iter_nth.stderr | 2 +- tests/ui/iter_skip_next_unfixable.stderr | 2 +- tests/ui/large_stack_arrays.stderr | 2 +- tests/ui/len_without_is_empty.stderr | 2 +- tests/ui/let_if_seq.stderr | 2 +- tests/ui/let_underscore_drop.stderr | 2 +- tests/ui/let_underscore_lock.stderr | 2 +- tests/ui/let_underscore_must_use.stderr | 2 +- tests/ui/linkedlist.stderr | 2 +- tests/ui/manual_find.stderr | 2 +- tests/ui/manual_flatten.stderr | 2 +- tests/ui/manual_non_exhaustive_enum.stderr | 2 +- tests/ui/manual_non_exhaustive_struct.stderr | 2 +- tests/ui/manual_strip.stderr | 2 +- tests/ui/map_err.stderr | 2 +- tests/ui/match_overlapping_arm.stderr | 2 +- tests/ui/match_same_arms.stderr | 2 +- tests/ui/match_same_arms2.stderr | 2 +- tests/ui/match_wild_err_arm.edition2018.stderr | 2 +- tests/ui/match_wild_err_arm.edition2021.stderr | 2 +- tests/ui/min_rust_version_attr.stderr | 2 +- tests/ui/mismatched_target_os_unix.stderr | 2 +- tests/ui/mismatching_type_param_order.stderr | 2 +- tests/ui/missing_panics_doc.stderr | 2 +- tests/ui/mixed_read_write_in_expression.stderr | 2 +- tests/ui/modulo_arithmetic_float.stderr | 2 +- tests/ui/modulo_arithmetic_integral.stderr | 2 +- tests/ui/modulo_arithmetic_integral_const.stderr | 2 +- tests/ui/mut_from_ref.stderr | 2 +- tests/ui/mut_range_bound.stderr | 2 +- tests/ui/needless_continue.stderr | 2 +- tests/ui/non_send_fields_in_send_ty.stderr | 2 +- tests/ui/octal_escapes.stderr | 2 +- tests/ui/ok_expect.stderr | 2 +- tests/ui/only_used_in_recursion.stderr | 2 +- tests/ui/only_used_in_recursion2.stderr | 2 +- tests/ui/option_env_unwrap.stderr | 2 +- tests/ui/overly_complex_bool_expr.stderr | 2 +- tests/ui/panic_in_result_fn.stderr | 2 +- tests/ui/panic_in_result_fn_assertions.stderr | 2 +- tests/ui/pattern_type_mismatch/mutability.stderr | 2 +- .../pattern_type_mismatch/pattern_alternatives.stderr | 2 +- tests/ui/pattern_type_mismatch/pattern_structs.stderr | 2 +- tests/ui/pattern_type_mismatch/pattern_tuples.stderr | 2 +- tests/ui/pattern_type_mismatch/syntax.stderr | 2 +- tests/ui/proc_macro.stderr | 2 +- tests/ui/pub_use.stderr | 2 +- tests/ui/rc_clone_in_vec_init/arc.stderr | 2 +- tests/ui/rc_clone_in_vec_init/rc.stderr | 2 +- tests/ui/rc_clone_in_vec_init/weak.stderr | 2 +- tests/ui/rc_mutex.stderr | 2 +- tests/ui/redundant_allocation.stderr | 2 +- tests/ui/redundant_allocation_fixable.stderr | 2 +- tests/ui/redundant_clone.stderr | 2 +- tests/ui/redundant_else.stderr | 2 +- tests/ui/redundant_pattern_matching_drop_order.stderr | 2 +- tests/ui/regex.stderr | 2 +- tests/ui/rest_pat_in_fully_bound_structs.stderr | 2 +- tests/ui/result_large_err.stderr | 2 +- tests/ui/result_unit_error.stderr | 2 +- tests/ui/return_self_not_must_use.stderr | 2 +- tests/ui/same_functions_in_if_condition.stderr | 2 +- tests/ui/same_item_push.stderr | 2 +- tests/ui/same_name_method.stderr | 2 +- tests/ui/search_is_some.stderr | 2 +- tests/ui/shadow.stderr | 6 +++--- tests/ui/should_impl_trait/method_list_1.stderr | 2 +- tests/ui/should_impl_trait/method_list_2.stderr | 2 +- tests/ui/significant_drop_in_scrutinee.stderr | 2 +- tests/ui/similar_names.stderr | 2 +- tests/ui/single_char_lifetime_names.stderr | 2 +- .../single_component_path_imports_nested_first.stderr | 2 +- tests/ui/size_of_in_element_count/expressions.stderr | 2 +- tests/ui/size_of_in_element_count/functions.stderr | 2 +- tests/ui/skip_while_next.stderr | 2 +- tests/ui/stable_sort_primitive.stderr | 2 +- tests/ui/std_instead_of_core.stderr | 6 +++--- tests/ui/str_to_string.stderr | 2 +- tests/ui/string_to_string.stderr | 2 +- tests/ui/struct_excessive_bools.stderr | 2 +- tests/ui/suspicious_else_formatting.stderr | 2 +- tests/ui/suspicious_map.stderr | 2 +- tests/ui/suspicious_splitn.stderr | 2 +- tests/ui/suspicious_unary_op_formatting.stderr | 2 +- tests/ui/swap.stderr | 4 ++-- tests/ui/trailing_empty_array.stderr | 2 +- tests/ui/trait_duplication_in_bounds_unfixable.stderr | 2 +- tests/ui/type_repetition_in_bounds.stderr | 2 +- tests/ui/undocumented_unsafe_blocks.stderr | 2 +- tests/ui/undropped_manually_drops.stderr | 2 +- tests/ui/uninit_vec.stderr | 2 +- tests/ui/unit_hash.stderr | 2 +- tests/ui/unit_return_expecting_ord.stderr | 2 +- tests/ui/unnecessary_self_imports.stderr | 2 +- tests/ui/unnecessary_to_owned.stderr | 2 +- tests/ui/unneeded_field_pattern.stderr | 2 +- tests/ui/unsafe_derive_deserialize.stderr | 2 +- tests/ui/unused_async.stderr | 2 +- tests/ui/unused_io_amount.stderr | 2 +- tests/ui/unused_peekable.stderr | 2 +- tests/ui/unused_self.stderr | 2 +- tests/ui/unwrap.stderr | 2 +- tests/ui/unwrap_expect_used.stderr | 4 ++-- tests/ui/unwrap_in_result.stderr | 2 +- tests/ui/useless_conversion_try.stderr | 2 +- tests/ui/vec_resize_to_zero.stderr | 2 +- tests/ui/verbose_file_reads.stderr | 2 +- tests/ui/vtable_address_comparisons.stderr | 2 +- tests/ui/wild_in_or_pats.stderr | 2 +- tests/ui/wrong_self_convention.stderr | 2 +- tests/ui/wrong_self_convention2.stderr | 2 +- tests/ui/wrong_self_conventions_mut.stderr | 2 +- tests/ui/zero_div_zero.stderr | 2 +- tests/ui/zero_sized_btreemap_values.stderr | 2 +- tests/ui/zero_sized_hashmap_values.stderr | 2 +- 205 files changed, 231 insertions(+), 231 deletions(-) diff --git a/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr b/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr index 62c45b54634f..4c75998437fd 100644 --- a/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr +++ b/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr @@ -4,8 +4,8 @@ error: `std::string::String` may not be held across an `await` point per `clippy LL | let _x = String::from("hello"); | ^^ | - = note: `-D clippy::await-holding-invalid-type` implied by `-D warnings` = note: strings are bad + = note: `-D clippy::await-holding-invalid-type` implied by `-D warnings` error: `std::net::Ipv4Addr` may not be held across an `await` point per `clippy.toml` --> $DIR/await_holding_invalid_type.rs:10:9 diff --git a/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr index 4c560299ebdd..b2b57bdde89c 100644 --- a/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr +++ b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr @@ -8,8 +8,8 @@ error: the function has a cognitive complexity of (3/2) LL | fn cognitive_complexity() { | ^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::cognitive-complexity` implied by `-D warnings` = help: you could split it up into multiple smaller functions + = note: `-D clippy::cognitive-complexity` implied by `-D warnings` error: aborting due to previous error; 2 warnings emitted diff --git a/tests/ui-toml/expect_used/expect_used.stderr b/tests/ui-toml/expect_used/expect_used.stderr index c5d95cb8a147..28a08599c67c 100644 --- a/tests/ui-toml/expect_used/expect_used.stderr +++ b/tests/ui-toml/expect_used/expect_used.stderr @@ -4,8 +4,8 @@ error: used `expect()` on `an Option` value LL | let _ = opt.expect(""); | ^^^^^^^^^^^^^^ | - = note: `-D clippy::expect-used` implied by `-D warnings` = help: if this value is `None`, it will panic + = note: `-D clippy::expect-used` implied by `-D warnings` error: used `expect()` on `a Result` value --> $DIR/expect_used.rs:11:13 diff --git a/tests/ui-toml/fn_params_excessive_bools/test.stderr b/tests/ui-toml/fn_params_excessive_bools/test.stderr index d05adc3d36e3..87bdb61c6a5e 100644 --- a/tests/ui-toml/fn_params_excessive_bools/test.stderr +++ b/tests/ui-toml/fn_params_excessive_bools/test.stderr @@ -4,8 +4,8 @@ error: more than 1 bools in function parameters LL | fn g(_: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings` = help: consider refactoring bools into two-variant enums + = note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui-toml/large_include_file/large_include_file.stderr b/tests/ui-toml/large_include_file/large_include_file.stderr index 6a685a58318b..7b5fb9e87659 100644 --- a/tests/ui-toml/large_include_file/large_include_file.stderr +++ b/tests/ui-toml/large_include_file/large_include_file.stderr @@ -4,8 +4,8 @@ error: attempted to include a large file LL | const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::large-include-file` implied by `-D warnings` = note: the configuration allows a maximum size of 600 bytes + = note: `-D clippy::large-include-file` implied by `-D warnings` = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info) error: attempted to include a large file diff --git a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr index d80ad49f3086..15fa4f42f9ba 100644 --- a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr +++ b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr @@ -4,12 +4,12 @@ error: use of irregular braces for `vec!` macro LL | let _ = vec! {1, 2, 3}; | ^^^^^^^^^^^^^^ | - = note: `-D clippy::nonstandard-macro-braces` implied by `-D warnings` help: consider writing `vec![1, 2, 3]` --> $DIR/conf_nonstandard_macro_braces.rs:43:13 | LL | let _ = vec! {1, 2, 3}; | ^^^^^^^^^^^^^^ + = note: `-D clippy::nonstandard-macro-braces` implied by `-D warnings` error: use of irregular braces for `format!` macro --> $DIR/conf_nonstandard_macro_braces.rs:44:13 diff --git a/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr b/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr index 49eecf18b4c4..c72f8c6488db 100644 --- a/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr +++ b/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr @@ -4,13 +4,13 @@ error: some fields in `NoGeneric` are not safe to be sent to another thread LL | unsafe impl Send for NoGeneric {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings` note: it is not safe to send field `rc_is_not_send` to another thread --> $DIR/test.rs:8:5 | LL | rc_is_not_send: Rc, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` + = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings` error: some fields in `MultiField` are not safe to be sent to another thread --> $DIR/test.rs:19:1 diff --git a/tests/ui-toml/struct_excessive_bools/test.stderr b/tests/ui-toml/struct_excessive_bools/test.stderr index 65861d10d0fd..4e7c70d18385 100644 --- a/tests/ui-toml/struct_excessive_bools/test.stderr +++ b/tests/ui-toml/struct_excessive_bools/test.stderr @@ -6,8 +6,8 @@ LL | | a: bool, LL | | } | |_^ | - = note: `-D clippy::struct-excessive-bools` implied by `-D warnings` = help: consider using a state machine or refactoring bools into two-variant enums + = note: `-D clippy::struct-excessive-bools` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui-toml/unwrap_used/unwrap_used.stderr b/tests/ui-toml/unwrap_used/unwrap_used.stderr index 6bcfa0a8b564..681b5eaf54db 100644 --- a/tests/ui-toml/unwrap_used/unwrap_used.stderr +++ b/tests/ui-toml/unwrap_used/unwrap_used.stderr @@ -16,8 +16,8 @@ error: used `unwrap()` on `an Option` value LL | let _ = boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::unwrap-used` implied by `-D warnings` = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: `-D clippy::unwrap-used` implied by `-D warnings` error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise --> $DIR/unwrap_used.rs:36:17 diff --git a/tests/ui/absurd-extreme-comparisons.stderr b/tests/ui/absurd-extreme-comparisons.stderr index 6de554378aaa..21cb11fa1bb8 100644 --- a/tests/ui/absurd-extreme-comparisons.stderr +++ b/tests/ui/absurd-extreme-comparisons.stderr @@ -4,8 +4,8 @@ error: this comparison involving the minimum or maximum element for this type co LL | u <= 0; | ^^^^^^ | - = note: `-D clippy::absurd-extreme-comparisons` implied by `-D warnings` = help: because `0` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == 0` instead + = note: `-D clippy::absurd-extreme-comparisons` implied by `-D warnings` error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:15:5 diff --git a/tests/ui/allow_attributes_without_reason.stderr b/tests/ui/allow_attributes_without_reason.stderr index cd040a144aac..23f17e9a7afb 100644 --- a/tests/ui/allow_attributes_without_reason.stderr +++ b/tests/ui/allow_attributes_without_reason.stderr @@ -4,12 +4,12 @@ error: `allow` attribute without specifying a reason LL | #[allow(dead_code)] | ^^^^^^^^^^^^^^^^^^^ | + = help: try adding a reason at the end with `, reason = ".."` note: the lint level is defined here --> $DIR/allow_attributes_without_reason.rs:2:9 | LL | #![deny(clippy::allow_attributes_without_reason)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: try adding a reason at the end with `, reason = ".."` error: `allow` attribute without specifying a reason --> $DIR/allow_attributes_without_reason.rs:6:1 diff --git a/tests/ui/approx_const.stderr b/tests/ui/approx_const.stderr index 4da1b8215ae0..0932a2eec520 100644 --- a/tests/ui/approx_const.stderr +++ b/tests/ui/approx_const.stderr @@ -4,8 +4,8 @@ error: approximate value of `f{32, 64}::consts::E` found LL | let my_e = 2.7182; | ^^^^^^ | - = note: `-D clippy::approx-constant` implied by `-D warnings` = help: consider using the constant directly + = note: `-D clippy::approx-constant` implied by `-D warnings` error: approximate value of `f{32, 64}::consts::E` found --> $DIR/approx_const.rs:5:20 diff --git a/tests/ui/as_conversions.stderr b/tests/ui/as_conversions.stderr index d11b56171b07..f5d59e1e5d83 100644 --- a/tests/ui/as_conversions.stderr +++ b/tests/ui/as_conversions.stderr @@ -4,8 +4,8 @@ error: using a potentially dangerous silent `as` conversion LL | let i = 0u32 as u64; | ^^^^^^^^^^^ | - = note: `-D clippy::as-conversions` implied by `-D warnings` = help: consider using a safe wrapper for this conversion + = note: `-D clippy::as-conversions` implied by `-D warnings` error: using a potentially dangerous silent `as` conversion --> $DIR/as_conversions.rs:17:13 diff --git a/tests/ui/asm_syntax.stderr b/tests/ui/asm_syntax.stderr index e9b150121aa3..9c7c3ba7d87e 100644 --- a/tests/ui/asm_syntax.stderr +++ b/tests/ui/asm_syntax.stderr @@ -4,8 +4,8 @@ error: Intel x86 assembly syntax used LL | asm!(""); | ^^^^^^^^ | - = note: `-D clippy::inline-asm-x86-intel-syntax` implied by `-D warnings` = help: use AT&T x86 assembly syntax + = note: `-D clippy::inline-asm-x86-intel-syntax` implied by `-D warnings` error: Intel x86 assembly syntax used --> $DIR/asm_syntax.rs:9:9 @@ -29,8 +29,8 @@ error: AT&T x86 assembly syntax used LL | asm!("", options(att_syntax)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::inline-asm-x86-att-syntax` implied by `-D warnings` = help: use Intel x86 assembly syntax + = note: `-D clippy::inline-asm-x86-att-syntax` implied by `-D warnings` error: AT&T x86 assembly syntax used --> $DIR/asm_syntax.rs:24:9 diff --git a/tests/ui/assertions_on_constants.stderr b/tests/ui/assertions_on_constants.stderr index e1f818814d50..29fe009035f1 100644 --- a/tests/ui/assertions_on_constants.stderr +++ b/tests/ui/assertions_on_constants.stderr @@ -4,8 +4,8 @@ error: `assert!(true)` will be optimized out by the compiler LL | assert!(true); | ^^^^^^^^^^^^^ | - = note: `-D clippy::assertions-on-constants` implied by `-D warnings` = help: remove it + = note: `-D clippy::assertions-on-constants` implied by `-D warnings` error: `assert!(false)` should probably be replaced --> $DIR/assertions_on_constants.rs:11:5 diff --git a/tests/ui/await_holding_lock.stderr b/tests/ui/await_holding_lock.stderr index 976da8d92424..81a2d0524383 100644 --- a/tests/ui/await_holding_lock.stderr +++ b/tests/ui/await_holding_lock.stderr @@ -4,7 +4,6 @@ error: this `MutexGuard` is held across an `await` point LL | let guard = x.lock().unwrap(); | ^^^^^ | - = note: `-D clippy::await-holding-lock` implied by `-D warnings` = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through --> $DIR/await_holding_lock.rs:9:9 @@ -13,6 +12,7 @@ LL | / let guard = x.lock().unwrap(); LL | | baz().await LL | | } | |_____^ + = note: `-D clippy::await-holding-lock` implied by `-D warnings` error: this `MutexGuard` is held across an `await` point --> $DIR/await_holding_lock.rs:24:13 diff --git a/tests/ui/await_holding_refcell_ref.stderr b/tests/ui/await_holding_refcell_ref.stderr index 4339fca735dd..25c15ab80602 100644 --- a/tests/ui/await_holding_refcell_ref.stderr +++ b/tests/ui/await_holding_refcell_ref.stderr @@ -4,7 +4,6 @@ error: this `RefCell` reference is held across an `await` point LL | let b = x.borrow(); | ^ | - = note: `-D clippy::await-holding-refcell-ref` implied by `-D warnings` = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through --> $DIR/await_holding_refcell_ref.rs:6:5 @@ -13,6 +12,7 @@ LL | / let b = x.borrow(); LL | | baz().await LL | | } | |_^ + = note: `-D clippy::await-holding-refcell-ref` implied by `-D warnings` error: this `RefCell` reference is held across an `await` point --> $DIR/await_holding_refcell_ref.rs:11:9 diff --git a/tests/ui/blanket_clippy_restriction_lints.stderr b/tests/ui/blanket_clippy_restriction_lints.stderr index 537557f8b0af..e83eb4d605aa 100644 --- a/tests/ui/blanket_clippy_restriction_lints.stderr +++ b/tests/ui/blanket_clippy_restriction_lints.stderr @@ -4,8 +4,8 @@ error: restriction lints are not meant to be all enabled LL | #![warn(clippy::restriction)] | ^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings` = help: try enabling only the lints you really need + = note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings` error: restriction lints are not meant to be all enabled --> $DIR/blanket_clippy_restriction_lints.rs:5:9 diff --git a/tests/ui/bool_to_int_with_if.stderr b/tests/ui/bool_to_int_with_if.stderr index e695440f6682..4cb5531bef6a 100644 --- a/tests/ui/bool_to_int_with_if.stderr +++ b/tests/ui/bool_to_int_with_if.stderr @@ -8,8 +8,8 @@ LL | | 0 LL | | }; | |_____^ help: replace with from: `i32::from(a)` | - = note: `-D clippy::bool-to-int-with-if` implied by `-D warnings` = note: `a as i32` or `a.into()` can also be valid options + = note: `-D clippy::bool-to-int-with-if` implied by `-D warnings` error: boolean to int conversion using if --> $DIR/bool_to_int_with_if.rs:20:5 diff --git a/tests/ui/borrow_interior_mutable_const/enums.stderr b/tests/ui/borrow_interior_mutable_const/enums.stderr index 654a1ee7df65..b0cab977a038 100644 --- a/tests/ui/borrow_interior_mutable_const/enums.stderr +++ b/tests/ui/borrow_interior_mutable_const/enums.stderr @@ -4,8 +4,8 @@ error: a `const` item with interior mutability should not be borrowed LL | let _ = &UNFROZEN_VARIANT; //~ ERROR interior mutability | ^^^^^^^^^^^^^^^^ | - = note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings` = help: assign this const to a local or static variable, and use the variable here + = note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings` error: a `const` item with interior mutability should not be borrowed --> $DIR/enums.rs:37:18 diff --git a/tests/ui/borrow_interior_mutable_const/others.stderr b/tests/ui/borrow_interior_mutable_const/others.stderr index 9a908cf30e94..c87ad206c2ae 100644 --- a/tests/ui/borrow_interior_mutable_const/others.stderr +++ b/tests/ui/borrow_interior_mutable_const/others.stderr @@ -4,8 +4,8 @@ error: a `const` item with interior mutability should not be borrowed LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability | ^^^^^^ | - = note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings` = help: assign this const to a local or static variable, and use the variable here + = note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings` error: a `const` item with interior mutability should not be borrowed --> $DIR/others.rs:55:16 diff --git a/tests/ui/borrow_interior_mutable_const/traits.stderr b/tests/ui/borrow_interior_mutable_const/traits.stderr index 8f26403abd3e..f34ae8814c33 100644 --- a/tests/ui/borrow_interior_mutable_const/traits.stderr +++ b/tests/ui/borrow_interior_mutable_const/traits.stderr @@ -4,8 +4,8 @@ error: a `const` item with interior mutability should not be borrowed LL | let _ = &Self::ATOMIC; //~ ERROR interior mutable | ^^^^^^^^^^^^ | - = note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings` = help: assign this const to a local or static variable, and use the variable here + = note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings` error: a `const` item with interior mutability should not be borrowed --> $DIR/traits.rs:26:18 diff --git a/tests/ui/box_collection.stderr b/tests/ui/box_collection.stderr index 2b28598ded92..40b6f9be61d5 100644 --- a/tests/ui/box_collection.stderr +++ b/tests/ui/box_collection.stderr @@ -4,8 +4,8 @@ error: you seem to be trying to use `Box>`. Consider using just `Vec<..> LL | fn test1(foo: Box>) {} | ^^^^^^^^^^^^^^ | - = note: `-D clippy::box-collection` implied by `-D warnings` = help: `Vec<..>` is already on the heap, `Box>` makes an extra allocation + = note: `-D clippy::box-collection` implied by `-D warnings` error: you seem to be trying to use `Box`. Consider using just `String` --> $DIR/box_collection.rs:28:15 diff --git a/tests/ui/branches_sharing_code/shared_at_bottom.stderr b/tests/ui/branches_sharing_code/shared_at_bottom.stderr index 5e1a68d216ea..b919812e098a 100644 --- a/tests/ui/branches_sharing_code/shared_at_bottom.stderr +++ b/tests/ui/branches_sharing_code/shared_at_bottom.stderr @@ -7,12 +7,12 @@ LL | | result LL | | }; | |_____^ | + = note: the end suggestion probably needs some adjustments to use the expression result correctly note: the lint level is defined here --> $DIR/shared_at_bottom.rs:2:36 | LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: the end suggestion probably needs some adjustments to use the expression result correctly help: consider moving these statements after the if | LL ~ } diff --git a/tests/ui/branches_sharing_code/shared_at_top.stderr b/tests/ui/branches_sharing_code/shared_at_top.stderr index d890b12ecbb4..fb3da641fb5e 100644 --- a/tests/ui/branches_sharing_code/shared_at_top.stderr +++ b/tests/ui/branches_sharing_code/shared_at_top.stderr @@ -103,11 +103,6 @@ LL | | println!("This should trigger `IS_SAME_THAN_ELSE` as usual"); LL | | } else { | |_____^ | -note: the lint level is defined here - --> $DIR/shared_at_top.rs:2:9 - | -LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: same as this --> $DIR/shared_at_top.rs:98:12 | @@ -116,6 +111,11 @@ LL | } else { LL | | println!("This should trigger `IS_SAME_THAN_ELSE` as usual"); LL | | } | |_____^ +note: the lint level is defined here + --> $DIR/shared_at_top.rs:2:9 + | +LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 7 previous errors diff --git a/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr b/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr index a270f637f2b9..3edb8e53a7d4 100644 --- a/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr +++ b/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr @@ -7,17 +7,17 @@ LL | | let _overlap_start = t * 2; LL | | let _overlap_end = 2 * t; | |_________________________________^ | -note: the lint level is defined here - --> $DIR/shared_at_top_and_bottom.rs:2:36 - | -LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: this code is shared at the end --> $DIR/shared_at_top_and_bottom.rs:28:5 | LL | / let _u = 9; LL | | } | |_____^ +note: the lint level is defined here + --> $DIR/shared_at_top_and_bottom.rs:2:36 + | +LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider moving these statements before the if | LL ~ let t = 7; diff --git a/tests/ui/branches_sharing_code/valid_if_blocks.stderr b/tests/ui/branches_sharing_code/valid_if_blocks.stderr index a815995e7172..d2acd6d9735c 100644 --- a/tests/ui/branches_sharing_code/valid_if_blocks.stderr +++ b/tests/ui/branches_sharing_code/valid_if_blocks.stderr @@ -6,11 +6,6 @@ LL | if false { LL | | } else { | |_____^ | -note: the lint level is defined here - --> $DIR/valid_if_blocks.rs:2:9 - | -LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: same as this --> $DIR/valid_if_blocks.rs:105:12 | @@ -18,6 +13,11 @@ LL | } else { | ____________^ LL | | } | |_____^ +note: the lint level is defined here + --> $DIR/valid_if_blocks.rs:2:9 + | +LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `if` has identical blocks --> $DIR/valid_if_blocks.rs:115:15 diff --git a/tests/ui/case_sensitive_file_extension_comparisons.stderr b/tests/ui/case_sensitive_file_extension_comparisons.stderr index 5d9a043edb9a..a28dd8bd5ad3 100644 --- a/tests/ui/case_sensitive_file_extension_comparisons.stderr +++ b/tests/ui/case_sensitive_file_extension_comparisons.stderr @@ -4,8 +4,8 @@ error: case-sensitive file extension comparison LL | filename.ends_with(".rs") | ^^^^^^^^^^^^^^^^ | - = note: `-D clippy::case-sensitive-file-extension-comparisons` implied by `-D warnings` = help: consider using a case-insensitive comparison instead + = note: `-D clippy::case-sensitive-file-extension-comparisons` implied by `-D warnings` error: case-sensitive file extension comparison --> $DIR/case_sensitive_file_extension_comparisons.rs:17:27 diff --git a/tests/ui/char_lit_as_u8.stderr b/tests/ui/char_lit_as_u8.stderr index b9836d2f2553..39fc9d6dda67 100644 --- a/tests/ui/char_lit_as_u8.stderr +++ b/tests/ui/char_lit_as_u8.stderr @@ -4,8 +4,8 @@ error: casting a character literal to `u8` truncates LL | let _ = '❤' as u8; // no suggestion, since a byte literal won't work. | ^^^^^^^^^ | - = note: `-D clippy::char-lit-as-u8` implied by `-D warnings` = note: `char` is four bytes wide, but `u8` is a single byte + = note: `-D clippy::char-lit-as-u8` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/char_lit_as_u8_suggestions.stderr b/tests/ui/char_lit_as_u8_suggestions.stderr index bf7cb1607b4e..586174c50882 100644 --- a/tests/ui/char_lit_as_u8_suggestions.stderr +++ b/tests/ui/char_lit_as_u8_suggestions.stderr @@ -4,8 +4,8 @@ error: casting a character literal to `u8` truncates LL | let _ = 'a' as u8; | ^^^^^^^^^ help: use a byte literal instead: `b'a'` | - = note: `-D clippy::char-lit-as-u8` implied by `-D warnings` = note: `char` is four bytes wide, but `u8` is a single byte + = note: `-D clippy::char-lit-as-u8` implied by `-D warnings` error: casting a character literal to `u8` truncates --> $DIR/char_lit_as_u8_suggestions.rs:7:13 diff --git a/tests/ui/checked_unwrap/complex_conditionals.stderr b/tests/ui/checked_unwrap/complex_conditionals.stderr index 46c6f69708eb..d44d5072e485 100644 --- a/tests/ui/checked_unwrap/complex_conditionals.stderr +++ b/tests/ui/checked_unwrap/complex_conditionals.stderr @@ -6,12 +6,12 @@ LL | if x.is_ok() && y.is_err() { LL | x.unwrap(); // unnecessary | ^^^^^^^^^^ | + = help: try using `if let` or `match` note: the lint level is defined here --> $DIR/complex_conditionals.rs:1:35 | LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: try using `if let` or `match` error: this call to `unwrap_err()` will always panic --> $DIR/complex_conditionals.rs:9:9 diff --git a/tests/ui/cognitive_complexity.stderr b/tests/ui/cognitive_complexity.stderr index a0ddc673abcc..d7f2f24e52f2 100644 --- a/tests/ui/cognitive_complexity.stderr +++ b/tests/ui/cognitive_complexity.stderr @@ -4,8 +4,8 @@ error: the function has a cognitive complexity of (28/25) LL | fn main() { | ^^^^ | - = note: `-D clippy::cognitive-complexity` implied by `-D warnings` = help: you could split it up into multiple smaller functions + = note: `-D clippy::cognitive-complexity` implied by `-D warnings` error: the function has a cognitive complexity of (7/1) --> $DIR/cognitive_complexity.rs:91:4 diff --git a/tests/ui/cognitive_complexity_attr_used.stderr b/tests/ui/cognitive_complexity_attr_used.stderr index f5ff53dda603..bb48f3297486 100644 --- a/tests/ui/cognitive_complexity_attr_used.stderr +++ b/tests/ui/cognitive_complexity_attr_used.stderr @@ -4,8 +4,8 @@ error: the function has a cognitive complexity of (3/0) LL | fn kaboom() { | ^^^^^^ | - = note: `-D clippy::cognitive-complexity` implied by `-D warnings` = help: you could split it up into multiple smaller functions + = note: `-D clippy::cognitive-complexity` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/collapsible_match.stderr b/tests/ui/collapsible_match.stderr index 5f18b6935029..33562e8401ca 100644 --- a/tests/ui/collapsible_match.stderr +++ b/tests/ui/collapsible_match.stderr @@ -8,7 +8,6 @@ LL | | _ => return, LL | | }, | |_________^ | - = note: `-D clippy::collapsible-match` implied by `-D warnings` help: the outer pattern can be modified to include the inner pattern --> $DIR/collapsible_match.rs:12:12 | @@ -16,6 +15,7 @@ LL | Ok(val) => match val { | ^^^ replace this binding LL | Some(n) => foo(n), | ^^^^^^^ with this pattern + = note: `-D clippy::collapsible-match` implied by `-D warnings` error: this `match` can be collapsed into the outer `match` --> $DIR/collapsible_match.rs:21:20 diff --git a/tests/ui/collapsible_match2.stderr b/tests/ui/collapsible_match2.stderr index fe64e4693792..144dbe40a7ad 100644 --- a/tests/ui/collapsible_match2.stderr +++ b/tests/ui/collapsible_match2.stderr @@ -8,7 +8,6 @@ LL | | _ => return, LL | | }, | |_____________^ | - = note: `-D clippy::collapsible-match` implied by `-D warnings` help: the outer pattern can be modified to include the inner pattern --> $DIR/collapsible_match2.rs:13:16 | @@ -16,6 +15,7 @@ LL | Ok(val) if make() => match val { | ^^^ replace this binding LL | Some(n) => foo(n), | ^^^^^^^ with this pattern + = note: `-D clippy::collapsible-match` implied by `-D warnings` error: this `match` can be collapsed into the outer `match` --> $DIR/collapsible_match2.rs:20:24 diff --git a/tests/ui/comparison_chain.stderr b/tests/ui/comparison_chain.stderr index be25a80dde0a..2eeb50202cd4 100644 --- a/tests/ui/comparison_chain.stderr +++ b/tests/ui/comparison_chain.stderr @@ -8,8 +8,8 @@ LL | | b() LL | | } | |_____^ | - = note: `-D clippy::comparison-chain` implied by `-D warnings` = help: consider rewriting the `if` chain to use `cmp` and `match` + = note: `-D clippy::comparison-chain` implied by `-D warnings` error: `if` chain can be rewritten with `match` --> $DIR/comparison_chain.rs:27:5 diff --git a/tests/ui/copy_iterator.stderr b/tests/ui/copy_iterator.stderr index f8ce6af7961a..6bc6fd6b6fa8 100644 --- a/tests/ui/copy_iterator.stderr +++ b/tests/ui/copy_iterator.stderr @@ -10,8 +10,8 @@ LL | | } LL | | } | |_^ | - = note: `-D clippy::copy-iterator` implied by `-D warnings` = note: consider implementing `IntoIterator` instead + = note: `-D clippy::copy-iterator` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/crashes/ice-360.stderr b/tests/ui/crashes/ice-360.stderr index 0eb7bb12b354..a2e2ab8fd192 100644 --- a/tests/ui/crashes/ice-360.stderr +++ b/tests/ui/crashes/ice-360.stderr @@ -18,8 +18,8 @@ error: empty `loop {}` wastes CPU cycles LL | loop {} | ^^^^^^^ | - = note: `-D clippy::empty-loop` implied by `-D warnings` = help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body + = note: `-D clippy::empty-loop` implied by `-D warnings` error: aborting due to 2 previous errors diff --git a/tests/ui/crashes/ice-6254.stderr b/tests/ui/crashes/ice-6254.stderr index f37ab2e9b0c7..22d82a30c6aa 100644 --- a/tests/ui/crashes/ice-6254.stderr +++ b/tests/ui/crashes/ice-6254.stderr @@ -4,9 +4,9 @@ error: to use a constant of type `Foo` in a pattern, `Foo` must be annotated wit LL | FOO_REF_REF => {}, | ^^^^^^^^^^^ | - = note: `-D indirect-structural-match` implied by `-D warnings` = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #62411 + = note: `-D indirect-structural-match` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/crashes/ice-7868.stderr b/tests/ui/crashes/ice-7868.stderr index 1a33e647588f..1d8314e889fa 100644 --- a/tests/ui/crashes/ice-7868.stderr +++ b/tests/ui/crashes/ice-7868.stderr @@ -4,8 +4,8 @@ error: unsafe block missing a safety comment LL | unsafe { 0 }; | ^^^^^^^^^^^^ | - = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` = help: consider adding a safety comment on the preceding line + = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/crashes/ice-7869.stderr b/tests/ui/crashes/ice-7869.stderr index 4fa9fb27e765..35d1e8fd2957 100644 --- a/tests/ui/crashes/ice-7869.stderr +++ b/tests/ui/crashes/ice-7869.stderr @@ -8,8 +8,8 @@ LL | | TyöValmis, LL | | } | |_^ | - = note: `-D clippy::enum-variant-names` implied by `-D warnings` = help: remove the prefixes and use full paths to the variants instead of glob imports + = note: `-D clippy::enum-variant-names` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/crashes/ice-9463.stderr b/tests/ui/crashes/ice-9463.stderr index 7daa08aeb6c9..b0ce306d6838 100644 --- a/tests/ui/crashes/ice-9463.stderr +++ b/tests/ui/crashes/ice-9463.stderr @@ -22,8 +22,8 @@ error: literal out of range for `u32` LL | let _y = 1u32 >> 10000000000000u32; | ^^^^^^^^^^^^^^^^^ | - = note: `#[deny(overflowing_literals)]` on by default = note: the literal `10000000000000u32` does not fit into the type `u32` whose range is `0..=4294967295` + = note: `#[deny(overflowing_literals)]` on by default error: aborting due to 3 previous errors diff --git a/tests/ui/crate_level_checks/entrypoint_recursion.stderr b/tests/ui/crate_level_checks/entrypoint_recursion.stderr index 459cf12a1c20..3d79a115cb30 100644 --- a/tests/ui/crate_level_checks/entrypoint_recursion.stderr +++ b/tests/ui/crate_level_checks/entrypoint_recursion.stderr @@ -4,8 +4,8 @@ error: recursing into entrypoint `a` LL | a(); | ^ | - = note: `-D clippy::main-recursion` implied by `-D warnings` = help: consider using another function for this recursion + = note: `-D clippy::main-recursion` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/crate_level_checks/no_std_swap.stderr b/tests/ui/crate_level_checks/no_std_swap.stderr index 48152d8ad774..7d8ea3f76b0f 100644 --- a/tests/ui/crate_level_checks/no_std_swap.stderr +++ b/tests/ui/crate_level_checks/no_std_swap.stderr @@ -5,8 +5,8 @@ LL | / a = b; LL | | b = a; | |_________^ help: try: `core::mem::swap(&mut a, &mut b)` | - = note: `-D clippy::almost-swapped` implied by `-D warnings` = note: or maybe you should use `core::mem::replace`? + = note: `-D clippy::almost-swapped` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/crate_level_checks/std_main_recursion.stderr b/tests/ui/crate_level_checks/std_main_recursion.stderr index 0a260f9d2309..82c68bd1cfef 100644 --- a/tests/ui/crate_level_checks/std_main_recursion.stderr +++ b/tests/ui/crate_level_checks/std_main_recursion.stderr @@ -4,8 +4,8 @@ error: recursing into entrypoint `main` LL | main(); | ^^^^ | - = note: `-D clippy::main-recursion` implied by `-D warnings` = help: consider using another function for this recursion + = note: `-D clippy::main-recursion` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/def_id_nocore.stderr b/tests/ui/def_id_nocore.stderr index 6210d7c6cfd8..f8fc17e872bd 100644 --- a/tests/ui/def_id_nocore.stderr +++ b/tests/ui/def_id_nocore.stderr @@ -4,8 +4,8 @@ error: methods called `as_*` usually take `self` by reference or `self` by mutab LL | pub fn as_ref(self) -> &'static str { | ^^^^ | - = note: `-D clippy::wrong-self-convention` implied by `-D warnings` = help: consider choosing a less ambiguous name + = note: `-D clippy::wrong-self-convention` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/default_union_representation.stderr b/tests/ui/default_union_representation.stderr index 138884af868c..8b7ed94cbc61 100644 --- a/tests/ui/default_union_representation.stderr +++ b/tests/ui/default_union_representation.stderr @@ -7,8 +7,8 @@ LL | | b: u32, LL | | } | |_^ | - = note: `-D clippy::default-union-representation` implied by `-D warnings` = help: consider annotating `NoAttribute` with `#[repr(C)]` to explicitly specify memory layout + = note: `-D clippy::default-union-representation` implied by `-D warnings` error: this union has the default representation --> $DIR/default_union_representation.rs:16:1 diff --git a/tests/ui/derive.stderr b/tests/ui/derive.stderr index 82a70ceecc36..e1fbb8dcd1ee 100644 --- a/tests/ui/derive.stderr +++ b/tests/ui/derive.stderr @@ -8,7 +8,6 @@ LL | | } LL | | } | |_^ | - = note: `-D clippy::expl-impl-clone-on-copy` implied by `-D warnings` note: consider deriving `Clone` or removing `Copy` --> $DIR/derive.rs:8:1 | @@ -18,6 +17,7 @@ LL | | Qux LL | | } LL | | } | |_^ + = note: `-D clippy::expl-impl-clone-on-copy` implied by `-D warnings` error: you are implementing `Clone` explicitly on a `Copy` type --> $DIR/derive.rs:32:1 diff --git a/tests/ui/derive_hash_xor_eq.stderr b/tests/ui/derive_hash_xor_eq.stderr index 2a4abb0c5193..16c92397804e 100644 --- a/tests/ui/derive_hash_xor_eq.stderr +++ b/tests/ui/derive_hash_xor_eq.stderr @@ -4,12 +4,12 @@ error: you are deriving `Hash` but have implemented `PartialEq` explicitly LL | #[derive(Hash)] | ^^^^ | - = note: `#[deny(clippy::derive_hash_xor_eq)]` on by default note: `PartialEq` implemented here --> $DIR/derive_hash_xor_eq.rs:15:1 | LL | impl PartialEq for Bar { | ^^^^^^^^^^^^^^^^^^^^^^ + = note: `#[deny(clippy::derive_hash_xor_eq)]` on by default = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `Hash` but have implemented `PartialEq` explicitly diff --git a/tests/ui/derive_ord_xor_partial_ord.stderr b/tests/ui/derive_ord_xor_partial_ord.stderr index baf8341aba90..58efbb8541f6 100644 --- a/tests/ui/derive_ord_xor_partial_ord.stderr +++ b/tests/ui/derive_ord_xor_partial_ord.stderr @@ -4,12 +4,12 @@ error: you are deriving `Ord` but have implemented `PartialOrd` explicitly LL | #[derive(Ord, PartialEq, Eq)] | ^^^ | - = note: `-D clippy::derive-ord-xor-partial-ord` implied by `-D warnings` note: `PartialOrd` implemented here --> $DIR/derive_ord_xor_partial_ord.rs:24:1 | LL | impl PartialOrd for DeriveOrd { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::derive-ord-xor-partial-ord` implied by `-D warnings` = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `Ord` but have implemented `PartialOrd` explicitly diff --git a/tests/ui/doc/unbalanced_ticks.stderr b/tests/ui/doc/unbalanced_ticks.stderr index a462b98871a8..f2ac6bc3269a 100644 --- a/tests/ui/doc/unbalanced_ticks.stderr +++ b/tests/ui/doc/unbalanced_ticks.stderr @@ -7,8 +7,8 @@ LL | | /// Because of the initial `unbalanced_tick` pair, the error message is LL | | /// very `confusing_and_misleading`. | |____________________________________^ | - = note: `-D clippy::doc-markdown` implied by `-D warnings` = help: a backtick may be missing a pair + = note: `-D clippy::doc-markdown` implied by `-D warnings` error: backticks are unbalanced --> $DIR/unbalanced_ticks.rs:13:1 diff --git a/tests/ui/double_must_use.stderr b/tests/ui/double_must_use.stderr index 8290ece1cad1..3d34557a881b 100644 --- a/tests/ui/double_must_use.stderr +++ b/tests/ui/double_must_use.stderr @@ -4,8 +4,8 @@ error: this function has an empty `#[must_use]` attribute, but returns a type al LL | pub fn must_use_result() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::double-must-use` implied by `-D warnings` = help: either add some descriptive text or remove the attribute + = note: `-D clippy::double-must-use` implied by `-D warnings` error: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]` --> $DIR/double_must_use.rs:10:1 diff --git a/tests/ui/drop_forget_copy.stderr b/tests/ui/drop_forget_copy.stderr index 88228afae89c..21adb3b3a504 100644 --- a/tests/ui/drop_forget_copy.stderr +++ b/tests/ui/drop_forget_copy.stderr @@ -4,12 +4,12 @@ error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a LL | drop(s1); | ^^^^^^^^ | - = note: `-D clippy::drop-copy` implied by `-D warnings` note: argument has type `SomeStruct` --> $DIR/drop_forget_copy.rs:33:10 | LL | drop(s1); | ^^ + = note: `-D clippy::drop-copy` implied by `-D warnings` error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact --> $DIR/drop_forget_copy.rs:34:5 @@ -41,12 +41,12 @@ error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetti LL | forget(s1); | ^^^^^^^^^^ | - = note: `-D clippy::forget-copy` implied by `-D warnings` note: argument has type `SomeStruct` --> $DIR/drop_forget_copy.rs:39:12 | LL | forget(s1); | ^^ + = note: `-D clippy::forget-copy` implied by `-D warnings` error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact --> $DIR/drop_forget_copy.rs:40:5 diff --git a/tests/ui/drop_non_drop.stderr b/tests/ui/drop_non_drop.stderr index 30121033de7e..b86057c0c321 100644 --- a/tests/ui/drop_non_drop.stderr +++ b/tests/ui/drop_non_drop.stderr @@ -4,12 +4,12 @@ error: call to `std::mem::drop` with a value that does not implement `Drop`. Dro LL | drop(Foo); | ^^^^^^^^^ | - = note: `-D clippy::drop-non-drop` implied by `-D warnings` note: argument has type `main::Foo` --> $DIR/drop_non_drop.rs:22:10 | LL | drop(Foo); | ^^^ + = note: `-D clippy::drop-non-drop` implied by `-D warnings` error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes --> $DIR/drop_non_drop.rs:37:5 diff --git a/tests/ui/drop_ref.stderr b/tests/ui/drop_ref.stderr index 531849f0680a..4743cf79b5d3 100644 --- a/tests/ui/drop_ref.stderr +++ b/tests/ui/drop_ref.stderr @@ -4,12 +4,12 @@ error: calls to `std::mem::drop` with a reference instead of an owned value. Dro LL | drop(&SomeStruct); | ^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::drop-ref` implied by `-D warnings` note: argument has type `&SomeStruct` --> $DIR/drop_ref.rs:11:10 | LL | drop(&SomeStruct); | ^^^^^^^^^^^ + = note: `-D clippy::drop-ref` implied by `-D warnings` error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing --> $DIR/drop_ref.rs:14:5 diff --git a/tests/ui/else_if_without_else.stderr b/tests/ui/else_if_without_else.stderr index 6f47658cfb18..90ccfb4fad64 100644 --- a/tests/ui/else_if_without_else.stderr +++ b/tests/ui/else_if_without_else.stderr @@ -8,8 +8,8 @@ LL | | println!("else if"); LL | | } | |_____^ | - = note: `-D clippy::else-if-without-else` implied by `-D warnings` = help: add an `else` block here + = note: `-D clippy::else-if-without-else` implied by `-D warnings` error: `if` expression with an `else if`, but without a final `else` --> $DIR/else_if_without_else.rs:54:12 diff --git a/tests/ui/empty_enum.stderr b/tests/ui/empty_enum.stderr index 7125e5f602b7..0d9aa5818e28 100644 --- a/tests/ui/empty_enum.stderr +++ b/tests/ui/empty_enum.stderr @@ -4,8 +4,8 @@ error: enum with no variants LL | enum Empty {} | ^^^^^^^^^^^^^ | - = note: `-D clippy::empty-enum` implied by `-D warnings` = help: consider using the uninhabited type `!` (never type) or a wrapper around it to introduce a type which can't be instantiated + = note: `-D clippy::empty-enum` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/empty_loop.stderr b/tests/ui/empty_loop.stderr index 555f3d3d884a..7602412334bb 100644 --- a/tests/ui/empty_loop.stderr +++ b/tests/ui/empty_loop.stderr @@ -4,8 +4,8 @@ error: empty `loop {}` wastes CPU cycles LL | loop {} | ^^^^^^^ | - = note: `-D clippy::empty-loop` implied by `-D warnings` = help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body + = note: `-D clippy::empty-loop` implied by `-D warnings` error: empty `loop {}` wastes CPU cycles --> $DIR/empty_loop.rs:11:9 diff --git a/tests/ui/empty_loop_no_std.stderr b/tests/ui/empty_loop_no_std.stderr index 5ded35a6f0d8..71af64f49d52 100644 --- a/tests/ui/empty_loop_no_std.stderr +++ b/tests/ui/empty_loop_no_std.stderr @@ -4,8 +4,8 @@ error: empty `loop {}` wastes CPU cycles LL | loop {} | ^^^^^^^ | - = note: `-D clippy::empty-loop` implied by `-D warnings` = help: you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body + = note: `-D clippy::empty-loop` implied by `-D warnings` error: empty `loop {}` wastes CPU cycles --> $DIR/empty_loop_no_std.rs:25:5 diff --git a/tests/ui/expect.stderr b/tests/ui/expect.stderr index 904c09046452..f6738865cac1 100644 --- a/tests/ui/expect.stderr +++ b/tests/ui/expect.stderr @@ -4,8 +4,8 @@ error: used `expect()` on `an Option` value LL | let _ = opt.expect(""); | ^^^^^^^^^^^^^^ | - = note: `-D clippy::expect-used` implied by `-D warnings` = help: if this value is `None`, it will panic + = note: `-D clippy::expect-used` implied by `-D warnings` error: used `expect()` on `a Result` value --> $DIR/expect.rs:10:13 diff --git a/tests/ui/fallible_impl_from.stderr b/tests/ui/fallible_impl_from.stderr index d637dbce5d79..28a061af664d 100644 --- a/tests/ui/fallible_impl_from.stderr +++ b/tests/ui/fallible_impl_from.stderr @@ -8,17 +8,17 @@ LL | | } LL | | } | |_^ | -note: the lint level is defined here - --> $DIR/fallible_impl_from.rs:1:9 - | -LL | #![deny(clippy::fallible_impl_from)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail note: potential failure(s) --> $DIR/fallible_impl_from.rs:7:13 | LL | Foo(s.parse().unwrap()) | ^^^^^^^^^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/fallible_impl_from.rs:1:9 + | +LL | #![deny(clippy::fallible_impl_from)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider implementing `TryFrom` instead --> $DIR/fallible_impl_from.rs:26:1 diff --git a/tests/ui/field_reassign_with_default.stderr b/tests/ui/field_reassign_with_default.stderr index 3ce4b91a5486..710bb66a48a4 100644 --- a/tests/ui/field_reassign_with_default.stderr +++ b/tests/ui/field_reassign_with_default.stderr @@ -4,12 +4,12 @@ error: field assignment outside of initializer for an instance created with Defa LL | a.i = 42; | ^^^^^^^^^ | - = note: `-D clippy::field-reassign-with-default` implied by `-D warnings` note: consider initializing the variable with `main::A { i: 42, ..Default::default() }` and removing relevant reassignments --> $DIR/field_reassign_with_default.rs:62:5 | LL | let mut a: A = Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::field-reassign-with-default` implied by `-D warnings` error: field assignment outside of initializer for an instance created with Default::default() --> $DIR/field_reassign_with_default.rs:103:5 diff --git a/tests/ui/filetype_is_file.stderr b/tests/ui/filetype_is_file.stderr index cd1e3ac37fe8..e51a90d6cfd2 100644 --- a/tests/ui/filetype_is_file.stderr +++ b/tests/ui/filetype_is_file.stderr @@ -4,8 +4,8 @@ error: `FileType::is_file()` only covers regular files LL | if fs::metadata("foo.txt")?.file_type().is_file() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::filetype-is-file` implied by `-D warnings` = help: use `!FileType::is_dir()` instead + = note: `-D clippy::filetype-is-file` implied by `-D warnings` error: `!FileType::is_file()` only denies regular files --> $DIR/filetype_is_file.rs:13:8 diff --git a/tests/ui/float_cmp.stderr b/tests/ui/float_cmp.stderr index 9cc1f1b75ed4..e3e9f3949fdf 100644 --- a/tests/ui/float_cmp.stderr +++ b/tests/ui/float_cmp.stderr @@ -4,8 +4,8 @@ error: strict comparison of `f32` or `f64` LL | ONE as f64 != 2.0; | ^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE as f64 - 2.0).abs() > error_margin` | - = note: `-D clippy::float-cmp` implied by `-D warnings` = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` + = note: `-D clippy::float-cmp` implied by `-D warnings` error: strict comparison of `f32` or `f64` --> $DIR/float_cmp.rs:62:5 diff --git a/tests/ui/float_cmp_const.stderr b/tests/ui/float_cmp_const.stderr index d8182cf855b0..65c45648ab38 100644 --- a/tests/ui/float_cmp_const.stderr +++ b/tests/ui/float_cmp_const.stderr @@ -4,8 +4,8 @@ error: strict comparison of `f32` or `f64` constant LL | 1f32 == ONE; | ^^^^^^^^^^^ help: consider comparing them within some margin of error: `(1f32 - ONE).abs() < error_margin` | - = note: `-D clippy::float-cmp-const` implied by `-D warnings` = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` + = note: `-D clippy::float-cmp-const` implied by `-D warnings` error: strict comparison of `f32` or `f64` constant --> $DIR/float_cmp_const.rs:17:5 diff --git a/tests/ui/fn_params_excessive_bools.stderr b/tests/ui/fn_params_excessive_bools.stderr index cd9d07fa115d..11627105691b 100644 --- a/tests/ui/fn_params_excessive_bools.stderr +++ b/tests/ui/fn_params_excessive_bools.stderr @@ -4,8 +4,8 @@ error: more than 3 bools in function parameters LL | fn g(_: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings` = help: consider refactoring bools into two-variant enums + = note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings` error: more than 3 bools in function parameters --> $DIR/fn_params_excessive_bools.rs:21:1 diff --git a/tests/ui/for_loops_over_fallibles.stderr b/tests/ui/for_loops_over_fallibles.stderr index 8c8c022243ae..68d2735b040e 100644 --- a/tests/ui/for_loops_over_fallibles.stderr +++ b/tests/ui/for_loops_over_fallibles.stderr @@ -4,8 +4,8 @@ error: for loop over `option`, which is an `Option`. This is more readably writt LL | for x in option { | ^^^^^^ | - = note: `-D clippy::for-loops-over-fallibles` implied by `-D warnings` = help: consider replacing `for x in option` with `if let Some(x) = option` + = note: `-D clippy::for-loops-over-fallibles` implied by `-D warnings` error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement --> $DIR/for_loops_over_fallibles.rs:14:14 diff --git a/tests/ui/forget_non_drop.stderr b/tests/ui/forget_non_drop.stderr index 03fb00960a44..194e37c8b424 100644 --- a/tests/ui/forget_non_drop.stderr +++ b/tests/ui/forget_non_drop.stderr @@ -4,12 +4,12 @@ error: call to `std::mem::forget` with a value that does not implement `Drop`. F LL | forget(Foo); | ^^^^^^^^^^^ | - = note: `-D clippy::forget-non-drop` implied by `-D warnings` note: argument has type `main::Foo` --> $DIR/forget_non_drop.rs:13:12 | LL | forget(Foo); | ^^^ + = note: `-D clippy::forget-non-drop` implied by `-D warnings` error: call to `std::mem::forget` with a value that does not implement `Drop`. Forgetting such a type is the same as dropping it --> $DIR/forget_non_drop.rs:24:5 diff --git a/tests/ui/forget_ref.stderr b/tests/ui/forget_ref.stderr index df5cd8cacdb8..011cdefc665f 100644 --- a/tests/ui/forget_ref.stderr +++ b/tests/ui/forget_ref.stderr @@ -4,12 +4,12 @@ error: calls to `std::mem::forget` with a reference instead of an owned value. F LL | forget(&SomeStruct); | ^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::forget-ref` implied by `-D warnings` note: argument has type `&SomeStruct` --> $DIR/forget_ref.rs:11:12 | LL | forget(&SomeStruct); | ^^^^^^^^^^^ + = note: `-D clippy::forget-ref` implied by `-D warnings` error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing --> $DIR/forget_ref.rs:14:5 diff --git a/tests/ui/format_args_unfixable.stderr b/tests/ui/format_args_unfixable.stderr index 4476218ad58e..37a6afb1ba7b 100644 --- a/tests/ui/format_args_unfixable.stderr +++ b/tests/ui/format_args_unfixable.stderr @@ -4,9 +4,9 @@ error: `format!` in `println!` args LL | println!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::format-in-format-args` implied by `-D warnings` = help: combine the `format!(..)` arguments with the outer `println!(..)` call = help: or consider changing `format!` to `format_args!` + = note: `-D clippy::format-in-format-args` implied by `-D warnings` error: `format!` in `println!` args --> $DIR/format_args_unfixable.rs:28:5 diff --git a/tests/ui/format_push_string.stderr b/tests/ui/format_push_string.stderr index 953784bcc068..d7be9a5f206c 100644 --- a/tests/ui/format_push_string.stderr +++ b/tests/ui/format_push_string.stderr @@ -4,8 +4,8 @@ error: `format!(..)` appended to existing `String` LL | string += &format!("{:?}", 1234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::format-push-string` implied by `-D warnings` = help: consider using `write!` to avoid the extra allocation + = note: `-D clippy::format-push-string` implied by `-D warnings` error: `format!(..)` appended to existing `String` --> $DIR/format_push_string.rs:6:5 diff --git a/tests/ui/formatting.stderr b/tests/ui/formatting.stderr index 9272cd604844..caccd5cba178 100644 --- a/tests/ui/formatting.stderr +++ b/tests/ui/formatting.stderr @@ -4,8 +4,8 @@ error: this looks like you are trying to use `.. -= ..`, but you really are doin LL | a =- 35; | ^^^^ | - = note: `-D clippy::suspicious-assignment-formatting` implied by `-D warnings` = note: to remove this lint, use either `-=` or `= -` + = note: `-D clippy::suspicious-assignment-formatting` implied by `-D warnings` error: this looks like you are trying to use `.. *= ..`, but you really are doing `.. = (* ..)` --> $DIR/formatting.rs:17:6 @@ -29,8 +29,8 @@ error: possibly missing a comma here LL | -1, -2, -3 // <= no comma here | ^ | - = note: `-D clippy::possible-missing-comma` implied by `-D warnings` = note: to remove this lint, add a comma or write the expr in a single line + = note: `-D clippy::possible-missing-comma` implied by `-D warnings` error: possibly missing a comma here --> $DIR/formatting.rs:33:19 diff --git a/tests/ui/from_over_into.stderr b/tests/ui/from_over_into.stderr index 2951e6bdac43..469adadd2196 100644 --- a/tests/ui/from_over_into.stderr +++ b/tests/ui/from_over_into.stderr @@ -4,8 +4,8 @@ error: an implementation of `From` is preferred since it gives you `Into<_>` for LL | impl Into for String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::from-over-into` implied by `-D warnings` = help: consider to implement `From` instead + = note: `-D clippy::from-over-into` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/future_not_send.stderr b/tests/ui/future_not_send.stderr index a9f2ad36d0ab..5b6858e4568b 100644 --- a/tests/ui/future_not_send.stderr +++ b/tests/ui/future_not_send.stderr @@ -4,7 +4,6 @@ error: future cannot be sent between threads safely LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { | ^^^^ future returned by `private_future` is not `Send` | - = note: `-D clippy::future-not-send` implied by `-D warnings` note: future is not `Send` as this value is used across an await --> $DIR/future_not_send.rs:8:19 | @@ -25,6 +24,7 @@ LL | async { true }.await LL | } | - `cell` is later dropped here = note: `std::cell::Cell` doesn't implement `std::marker::Sync` + = note: `-D clippy::future-not-send` implied by `-D warnings` error: future cannot be sent between threads safely --> $DIR/future_not_send.rs:11:42 diff --git a/tests/ui/get_unwrap.stderr b/tests/ui/get_unwrap.stderr index ea8fec527351..937f85904083 100644 --- a/tests/ui/get_unwrap.stderr +++ b/tests/ui/get_unwrap.stderr @@ -16,8 +16,8 @@ error: used `unwrap()` on `an Option` value LL | let _ = boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::unwrap-used` implied by `-D warnings` = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: `-D clippy::unwrap-used` implied by `-D warnings` error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise --> $DIR/get_unwrap.rs:36:17 diff --git a/tests/ui/if_let_mutex.stderr b/tests/ui/if_let_mutex.stderr index 8a4d5dbac592..da0cc25f0ab5 100644 --- a/tests/ui/if_let_mutex.stderr +++ b/tests/ui/if_let_mutex.stderr @@ -13,8 +13,8 @@ LL | | do_stuff(lock); LL | | }; | |_____^ | - = note: `-D clippy::if-let-mutex` implied by `-D warnings` = help: move the lock call outside of the `if let ...` expression + = note: `-D clippy::if-let-mutex` implied by `-D warnings` error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock --> $DIR/if_let_mutex.rs:22:5 diff --git a/tests/ui/if_not_else.stderr b/tests/ui/if_not_else.stderr index 8c8cc44bb035..46671c15274f 100644 --- a/tests/ui/if_not_else.stderr +++ b/tests/ui/if_not_else.stderr @@ -8,8 +8,8 @@ LL | | println!("Bunny"); LL | | } | |_____^ | - = note: `-D clippy::if-not-else` implied by `-D warnings` = help: remove the `!` and swap the blocks of the `if`/`else` + = note: `-D clippy::if-not-else` implied by `-D warnings` error: unnecessary `!=` operation --> $DIR/if_not_else.rs:17:5 diff --git a/tests/ui/if_same_then_else.stderr b/tests/ui/if_same_then_else.stderr index 2cdf442486a3..fb23b81d36d7 100644 --- a/tests/ui/if_same_then_else.stderr +++ b/tests/ui/if_same_then_else.stderr @@ -11,7 +11,6 @@ LL | | foo(); LL | | } else { | |_____^ | - = note: `-D clippy::if-same-then-else` implied by `-D warnings` note: same as this --> $DIR/if_same_then_else.rs:31:12 | @@ -24,6 +23,7 @@ LL | | 0..10; LL | | foo(); LL | | } | |_____^ + = note: `-D clippy::if-same-then-else` implied by `-D warnings` error: this `if` has identical blocks --> $DIR/if_same_then_else.rs:67:21 diff --git a/tests/ui/if_same_then_else2.stderr b/tests/ui/if_same_then_else2.stderr index cac788f859d1..704cfd9669ac 100644 --- a/tests/ui/if_same_then_else2.stderr +++ b/tests/ui/if_same_then_else2.stderr @@ -11,7 +11,6 @@ LL | | } LL | | } else { | |_____^ | - = note: `-D clippy::if-same-then-else` implied by `-D warnings` note: same as this --> $DIR/if_same_then_else2.rs:23:12 | @@ -24,6 +23,7 @@ LL | | let bar: &Option<_> = &Some::(42); LL | | } LL | | } | |_____^ + = note: `-D clippy::if-same-then-else` implied by `-D warnings` error: this `if` has identical blocks --> $DIR/if_same_then_else2.rs:35:13 diff --git a/tests/ui/if_then_some_else_none.stderr b/tests/ui/if_then_some_else_none.stderr index c22ace30d2dc..24e0b5947f19 100644 --- a/tests/ui/if_then_some_else_none.stderr +++ b/tests/ui/if_then_some_else_none.stderr @@ -10,8 +10,8 @@ LL | | None LL | | }; | |_____^ | - = note: `-D clippy::if-then-some-else-none` implied by `-D warnings` = help: consider using `bool::then` like: `foo().then(|| { /* snippet */ "foo" })` + = note: `-D clippy::if-then-some-else-none` implied by `-D warnings` error: this could be simplified with `bool::then` --> $DIR/if_then_some_else_none.rs:14:13 diff --git a/tests/ui/ifs_same_cond.stderr b/tests/ui/ifs_same_cond.stderr index 0c8f49b8687f..4113087327a2 100644 --- a/tests/ui/ifs_same_cond.stderr +++ b/tests/ui/ifs_same_cond.stderr @@ -4,12 +4,12 @@ error: this `if` has the same condition as a previous `if` LL | } else if b { | ^ | - = note: `-D clippy::ifs-same-cond` implied by `-D warnings` note: same as this --> $DIR/ifs_same_cond.rs:8:8 | LL | if b { | ^ + = note: `-D clippy::ifs-same-cond` implied by `-D warnings` error: this `if` has the same condition as a previous `if` --> $DIR/ifs_same_cond.rs:14:15 diff --git a/tests/ui/impl.stderr b/tests/ui/impl.stderr index 8703ecac93e8..e28b1bf0cdd9 100644 --- a/tests/ui/impl.stderr +++ b/tests/ui/impl.stderr @@ -6,7 +6,6 @@ LL | | fn second() {} LL | | } | |_^ | - = note: `-D clippy::multiple-inherent-impl` implied by `-D warnings` note: first implementation here --> $DIR/impl.rs:6:1 | @@ -14,6 +13,7 @@ LL | / impl MyStruct { LL | | fn first() {} LL | | } | |_^ + = note: `-D clippy::multiple-inherent-impl` implied by `-D warnings` error: multiple implementations of this structure --> $DIR/impl.rs:24:5 diff --git a/tests/ui/indexing_slicing_index.stderr b/tests/ui/indexing_slicing_index.stderr index 6ae700753f06..a8d8b38163d0 100644 --- a/tests/ui/indexing_slicing_index.stderr +++ b/tests/ui/indexing_slicing_index.stderr @@ -16,8 +16,8 @@ error: indexing may panic LL | x[index]; | ^^^^^^^^ | - = note: `-D clippy::indexing-slicing` implied by `-D warnings` = help: consider using `.get(n)` or `.get_mut(n)` instead + = note: `-D clippy::indexing-slicing` implied by `-D warnings` error: indexing may panic --> $DIR/indexing_slicing_index.rs:38:5 diff --git a/tests/ui/indexing_slicing_slice.stderr b/tests/ui/indexing_slicing_slice.stderr index f70722b92a5b..dc54bd41365d 100644 --- a/tests/ui/indexing_slicing_slice.stderr +++ b/tests/ui/indexing_slicing_slice.stderr @@ -4,8 +4,8 @@ error: slicing may panic LL | &x[index..]; | ^^^^^^^^^^ | - = note: `-D clippy::indexing-slicing` implied by `-D warnings` = help: consider using `.get(n..)` or .get_mut(n..)` instead + = note: `-D clippy::indexing-slicing` implied by `-D warnings` error: slicing may panic --> $DIR/indexing_slicing_slice.rs:13:6 diff --git a/tests/ui/inefficient_to_string.stderr b/tests/ui/inefficient_to_string.stderr index 1c0490ffa44c..914dc92bfb65 100644 --- a/tests/ui/inefficient_to_string.stderr +++ b/tests/ui/inefficient_to_string.stderr @@ -4,12 +4,12 @@ error: calling `to_string` on `&&str` LL | let _: String = rrstr.to_string(); | ^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrstr).to_string()` | + = help: `&str` implements `ToString` through a slower blanket impl, but `str` has a fast specialization of `ToString` note: the lint level is defined here --> $DIR/inefficient_to_string.rs:2:9 | LL | #![deny(clippy::inefficient_to_string)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: `&str` implements `ToString` through a slower blanket impl, but `str` has a fast specialization of `ToString` error: calling `to_string` on `&&&str` --> $DIR/inefficient_to_string.rs:12:21 diff --git a/tests/ui/infinite_loop.stderr b/tests/ui/infinite_loop.stderr index 4ec7d900ade3..85258b9d64f9 100644 --- a/tests/ui/infinite_loop.stderr +++ b/tests/ui/infinite_loop.stderr @@ -4,8 +4,8 @@ error: variables in the condition are not mutated in the loop body LL | while y < 10 { | ^^^^^^ | - = note: `#[deny(clippy::while_immutable_condition)]` on by default = note: this may lead to an infinite or to a never running loop + = note: `#[deny(clippy::while_immutable_condition)]` on by default error: variables in the condition are not mutated in the loop body --> $DIR/infinite_loop.rs:25:11 diff --git a/tests/ui/inherent_to_string.stderr b/tests/ui/inherent_to_string.stderr index 4f331f5bec9e..443fecae1aad 100644 --- a/tests/ui/inherent_to_string.stderr +++ b/tests/ui/inherent_to_string.stderr @@ -6,8 +6,8 @@ LL | | "A.to_string()".to_string() LL | | } | |_____^ | - = note: `-D clippy::inherent-to-string` implied by `-D warnings` = help: implement trait `Display` for type `A` instead + = note: `-D clippy::inherent-to-string` implied by `-D warnings` error: type `C` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display` --> $DIR/inherent_to_string.rs:44:5 @@ -17,12 +17,12 @@ LL | | "C.to_string()".to_string() LL | | } | |_____^ | + = help: remove the inherent method from type `C` note: the lint level is defined here --> $DIR/inherent_to_string.rs:2:9 | LL | #![deny(clippy::inherent_to_string_shadow_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: remove the inherent method from type `C` error: aborting due to 2 previous errors diff --git a/tests/ui/inspect_for_each.stderr b/tests/ui/inspect_for_each.stderr index 9f976bb74584..67c2d5e53c78 100644 --- a/tests/ui/inspect_for_each.stderr +++ b/tests/ui/inspect_for_each.stderr @@ -9,8 +9,8 @@ LL | | b.push(z); LL | | }); | |______^ | - = note: `-D clippy::inspect-for-each` implied by `-D warnings` = help: move the code from `inspect(..)` to `for_each(..)` and remove the `inspect(..)` + = note: `-D clippy::inspect-for-each` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/integer_division.stderr b/tests/ui/integer_division.stderr index cbb7f8814249..ca8001279207 100644 --- a/tests/ui/integer_division.stderr +++ b/tests/ui/integer_division.stderr @@ -4,8 +4,8 @@ error: integer division LL | let n = 1 / 2; | ^^^^^ | - = note: `-D clippy::integer-division` implied by `-D warnings` = help: division of integers may cause loss of precision. consider using floats + = note: `-D clippy::integer-division` implied by `-D warnings` error: integer division --> $DIR/integer_division.rs:6:13 diff --git a/tests/ui/issue_4266.stderr b/tests/ui/issue_4266.stderr index e5042aaa776b..240f4bcc38fd 100644 --- a/tests/ui/issue_4266.stderr +++ b/tests/ui/issue_4266.stderr @@ -18,8 +18,8 @@ error: methods called `new` usually take no `self` LL | pub async fn new(&mut self) -> Self { | ^^^^^^^^^ | - = note: `-D clippy::wrong-self-convention` implied by `-D warnings` = help: consider choosing a less ambiguous name + = note: `-D clippy::wrong-self-convention` implied by `-D warnings` error: aborting due to 3 previous errors diff --git a/tests/ui/iter_nth.stderr b/tests/ui/iter_nth.stderr index d00b2fb672bb..a0fe353bcf75 100644 --- a/tests/ui/iter_nth.stderr +++ b/tests/ui/iter_nth.stderr @@ -4,8 +4,8 @@ error: called `.iter().nth()` on a Vec LL | let bad_vec = some_vec.iter().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::iter-nth` implied by `-D warnings` = help: calling `.get()` is both faster and more readable + = note: `-D clippy::iter-nth` implied by `-D warnings` error: called `.iter().nth()` on a slice --> $DIR/iter_nth.rs:34:26 diff --git a/tests/ui/iter_skip_next_unfixable.stderr b/tests/ui/iter_skip_next_unfixable.stderr index 74c327c74836..4062706f9420 100644 --- a/tests/ui/iter_skip_next_unfixable.stderr +++ b/tests/ui/iter_skip_next_unfixable.stderr @@ -4,12 +4,12 @@ error: called `skip(..).next()` on an iterator LL | let _: Vec<&str> = sp.skip(1).next().unwrap().split(' ').collect(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)` | - = note: `-D clippy::iter-skip-next` implied by `-D warnings` help: for this change `sp` has to be mutable --> $DIR/iter_skip_next_unfixable.rs:8:9 | LL | let sp = test_string.split('|').map(|s| s.trim()); | ^^ + = note: `-D clippy::iter-skip-next` implied by `-D warnings` error: called `skip(..).next()` on an iterator --> $DIR/iter_skip_next_unfixable.rs:11:29 diff --git a/tests/ui/large_stack_arrays.stderr b/tests/ui/large_stack_arrays.stderr index 0d91b65b4284..c7bf941ad009 100644 --- a/tests/ui/large_stack_arrays.stderr +++ b/tests/ui/large_stack_arrays.stderr @@ -4,8 +4,8 @@ error: allocating a local array larger than 512000 bytes LL | [0u32; 20_000_000], | ^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::large-stack-arrays` implied by `-D warnings` = help: consider allocating on the heap with `vec![0u32; 20_000_000].into_boxed_slice()` + = note: `-D clippy::large-stack-arrays` implied by `-D warnings` error: allocating a local array larger than 512000 bytes --> $DIR/large_stack_arrays.rs:24:9 diff --git a/tests/ui/len_without_is_empty.stderr b/tests/ui/len_without_is_empty.stderr index a1f48f7610b4..8e890e2e2590 100644 --- a/tests/ui/len_without_is_empty.stderr +++ b/tests/ui/len_without_is_empty.stderr @@ -92,8 +92,8 @@ error: this returns a `Result<_, ()>` LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::result-unit-err` implied by `-D warnings` = help: use a custom `Error` type instead + = note: `-D clippy::result-unit-err` implied by `-D warnings` error: this returns a `Result<_, ()>` --> $DIR/len_without_is_empty.rs:240:5 diff --git a/tests/ui/let_if_seq.stderr b/tests/ui/let_if_seq.stderr index 271ccce681c9..f2e0edb6fbc3 100644 --- a/tests/ui/let_if_seq.stderr +++ b/tests/ui/let_if_seq.stderr @@ -7,8 +7,8 @@ LL | | foo = 42; LL | | } | |_____^ help: it is more idiomatic to write: `let foo = if f() { 42 } else { 0 };` | - = note: `-D clippy::useless-let-if-seq` implied by `-D warnings` = note: you might not need `mut` at all + = note: `-D clippy::useless-let-if-seq` implied by `-D warnings` error: `if _ { .. } else { .. }` is an expression --> $DIR/let_if_seq.rs:71:5 diff --git a/tests/ui/let_underscore_drop.stderr b/tests/ui/let_underscore_drop.stderr index ee7bbe995f16..324b7cd431d4 100644 --- a/tests/ui/let_underscore_drop.stderr +++ b/tests/ui/let_underscore_drop.stderr @@ -4,8 +4,8 @@ error: non-binding `let` on a type that implements `Drop` LL | let _ = Box::new(()); | ^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::let-underscore-drop` implied by `-D warnings` = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` + = note: `-D clippy::let-underscore-drop` implied by `-D warnings` error: non-binding `let` on a type that implements `Drop` --> $DIR/let_underscore_drop.rs:18:5 diff --git a/tests/ui/let_underscore_lock.stderr b/tests/ui/let_underscore_lock.stderr index 4365b48fabb9..d7779e7b6c48 100644 --- a/tests/ui/let_underscore_lock.stderr +++ b/tests/ui/let_underscore_lock.stderr @@ -4,8 +4,8 @@ error: non-binding let on a synchronization lock LL | let _ = m.lock(); | ^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::let-underscore-lock` implied by `-D warnings` = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` + = note: `-D clippy::let-underscore-lock` implied by `-D warnings` error: non-binding let on a synchronization lock --> $DIR/let_underscore_lock.rs:10:5 diff --git a/tests/ui/let_underscore_must_use.stderr b/tests/ui/let_underscore_must_use.stderr index 5b751ea56def..bae60f2ff9b7 100644 --- a/tests/ui/let_underscore_must_use.stderr +++ b/tests/ui/let_underscore_must_use.stderr @@ -4,8 +4,8 @@ error: non-binding let on a result of a `#[must_use]` function LL | let _ = f(); | ^^^^^^^^^^^^ | - = note: `-D clippy::let-underscore-must-use` implied by `-D warnings` = help: consider explicitly using function result + = note: `-D clippy::let-underscore-must-use` implied by `-D warnings` error: non-binding let on an expression with `#[must_use]` type --> $DIR/let_underscore_must_use.rs:68:5 diff --git a/tests/ui/linkedlist.stderr b/tests/ui/linkedlist.stderr index 51327df13211..c76c94961312 100644 --- a/tests/ui/linkedlist.stderr +++ b/tests/ui/linkedlist.stderr @@ -4,8 +4,8 @@ error: you seem to be using a `LinkedList`! Perhaps you meant some other data st LL | const C: LinkedList = LinkedList::new(); | ^^^^^^^^^^^^^^^ | - = note: `-D clippy::linkedlist` implied by `-D warnings` = help: a `VecDeque` might work + = note: `-D clippy::linkedlist` implied by `-D warnings` error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? --> $DIR/linkedlist.rs:9:11 diff --git a/tests/ui/manual_find.stderr b/tests/ui/manual_find.stderr index da0fd4aaef7d..ea04bb066e61 100644 --- a/tests/ui/manual_find.stderr +++ b/tests/ui/manual_find.stderr @@ -9,8 +9,8 @@ LL | | } LL | | None | |________^ help: replace with an iterator: `strings.into_iter().find(|s| s == String::new())` | - = note: `-D clippy::manual-find` implied by `-D warnings` = note: you may need to dereference some variables + = note: `-D clippy::manual-find` implied by `-D warnings` error: manual implementation of `Iterator::find` --> $DIR/manual_find.rs:14:5 diff --git a/tests/ui/manual_flatten.stderr b/tests/ui/manual_flatten.stderr index da053c056683..180a6ff4e9a7 100644 --- a/tests/ui/manual_flatten.stderr +++ b/tests/ui/manual_flatten.stderr @@ -11,7 +11,6 @@ LL | | } LL | | } | |_____^ | - = note: `-D clippy::manual-flatten` implied by `-D warnings` help: ...and remove the `if let` statement in the for loop --> $DIR/manual_flatten.rs:8:9 | @@ -19,6 +18,7 @@ LL | / if let Some(y) = n { LL | | println!("{}", y); LL | | } | |_________^ + = note: `-D clippy::manual-flatten` implied by `-D warnings` error: unnecessary `if let` since only the `Ok` variant of the iterator element is used --> $DIR/manual_flatten.rs:15:5 diff --git a/tests/ui/manual_non_exhaustive_enum.stderr b/tests/ui/manual_non_exhaustive_enum.stderr index 144fe86df554..087f766be70d 100644 --- a/tests/ui/manual_non_exhaustive_enum.stderr +++ b/tests/ui/manual_non_exhaustive_enum.stderr @@ -13,12 +13,12 @@ LL | | _C, LL | | } | |_^ | - = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings` help: remove this variant --> $DIR/manual_non_exhaustive_enum.rs:9:5 | LL | _C, | ^^ + = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings` error: this seems like a manual implementation of the non-exhaustive pattern --> $DIR/manual_non_exhaustive_enum.rs:14:1 diff --git a/tests/ui/manual_non_exhaustive_struct.stderr b/tests/ui/manual_non_exhaustive_struct.stderr index e0766c17b758..d0bed8e11211 100644 --- a/tests/ui/manual_non_exhaustive_struct.stderr +++ b/tests/ui/manual_non_exhaustive_struct.stderr @@ -12,12 +12,12 @@ LL | | _c: (), LL | | } | |_____^ | - = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings` help: remove this field --> $DIR/manual_non_exhaustive_struct.rs:8:9 | LL | _c: (), | ^^^^^^ + = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings` error: this seems like a manual implementation of the non-exhaustive pattern --> $DIR/manual_non_exhaustive_struct.rs:13:5 diff --git a/tests/ui/manual_strip.stderr b/tests/ui/manual_strip.stderr index 896edf2ae516..2191ccb85dd5 100644 --- a/tests/ui/manual_strip.stderr +++ b/tests/ui/manual_strip.stderr @@ -4,12 +4,12 @@ error: stripping a prefix manually LL | str::to_string(&s["ab".len()..]); | ^^^^^^^^^^^^^^^^ | - = note: `-D clippy::manual-strip` implied by `-D warnings` note: the prefix was tested here --> $DIR/manual_strip.rs:6:5 | LL | if s.starts_with("ab") { | ^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::manual-strip` implied by `-D warnings` help: try using the `strip_prefix` method | LL ~ if let Some() = s.strip_prefix("ab") { diff --git a/tests/ui/map_err.stderr b/tests/ui/map_err.stderr index c035840521e4..d44403a84a56 100644 --- a/tests/ui/map_err.stderr +++ b/tests/ui/map_err.stderr @@ -4,8 +4,8 @@ error: `map_err(|_|...` wildcard pattern discards the original error LL | println!("{:?}", x.map_err(|_| Errors::Ignored)); | ^^^ | - = note: `-D clippy::map-err-ignore` implied by `-D warnings` = help: consider storing the original error as a source in the new error, or silence this warning using an ignored identifier (`.map_err(|_foo| ...`) + = note: `-D clippy::map-err-ignore` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/match_overlapping_arm.stderr b/tests/ui/match_overlapping_arm.stderr index b81bb1ecfae0..a72becbeb669 100644 --- a/tests/ui/match_overlapping_arm.stderr +++ b/tests/ui/match_overlapping_arm.stderr @@ -4,12 +4,12 @@ error: some ranges overlap LL | 0..=10 => println!("0..=10"), | ^^^^^^ | - = note: `-D clippy::match-overlapping-arm` implied by `-D warnings` note: overlaps with this --> $DIR/match_overlapping_arm.rs:14:9 | LL | 0..=11 => println!("0..=11"), | ^^^^^^ + = note: `-D clippy::match-overlapping-arm` implied by `-D warnings` error: some ranges overlap --> $DIR/match_overlapping_arm.rs:19:9 diff --git a/tests/ui/match_same_arms.stderr b/tests/ui/match_same_arms.stderr index b6d04263b37a..db85b5964e84 100644 --- a/tests/ui/match_same_arms.stderr +++ b/tests/ui/match_same_arms.stderr @@ -4,13 +4,13 @@ error: this match arm has an identical body to the `_` wildcard arm LL | Abc::A => 0, | ^^^^^^^^^^^ help: try removing the arm | - = note: `-D clippy::match-same-arms` implied by `-D warnings` = help: or try changing either arm body note: `_` wildcard arm here --> $DIR/match_same_arms.rs:13:9 | LL | _ => 0, //~ ERROR match arms have same body | ^^^^^^ + = note: `-D clippy::match-same-arms` implied by `-D warnings` error: this match arm has an identical body to another arm --> $DIR/match_same_arms.rs:17:9 diff --git a/tests/ui/match_same_arms2.stderr b/tests/ui/match_same_arms2.stderr index 14a672ba2fec..b260155d2189 100644 --- a/tests/ui/match_same_arms2.stderr +++ b/tests/ui/match_same_arms2.stderr @@ -10,7 +10,6 @@ LL | | a LL | | }, | |_________^ help: try removing the arm | - = note: `-D clippy::match-same-arms` implied by `-D warnings` = help: or try changing either arm body note: `_` wildcard arm here --> $DIR/match_same_arms2.rs:20:9 @@ -23,6 +22,7 @@ LL | | let mut a = 42 + [23].len() as i32; LL | | a LL | | }, | |_________^ + = note: `-D clippy::match-same-arms` implied by `-D warnings` error: this match arm has an identical body to another arm --> $DIR/match_same_arms2.rs:34:9 diff --git a/tests/ui/match_wild_err_arm.edition2018.stderr b/tests/ui/match_wild_err_arm.edition2018.stderr index 2d66daea8046..525533bf07bb 100644 --- a/tests/ui/match_wild_err_arm.edition2018.stderr +++ b/tests/ui/match_wild_err_arm.edition2018.stderr @@ -4,8 +4,8 @@ error: `Err(_)` matches all errors LL | Err(_) => panic!("err"), | ^^^^^^ | - = note: `-D clippy::match-wild-err-arm` implied by `-D warnings` = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable + = note: `-D clippy::match-wild-err-arm` implied by `-D warnings` error: `Err(_)` matches all errors --> $DIR/match_wild_err_arm.rs:20:9 diff --git a/tests/ui/match_wild_err_arm.edition2021.stderr b/tests/ui/match_wild_err_arm.edition2021.stderr index 2d66daea8046..525533bf07bb 100644 --- a/tests/ui/match_wild_err_arm.edition2021.stderr +++ b/tests/ui/match_wild_err_arm.edition2021.stderr @@ -4,8 +4,8 @@ error: `Err(_)` matches all errors LL | Err(_) => panic!("err"), | ^^^^^^ | - = note: `-D clippy::match-wild-err-arm` implied by `-D warnings` = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable + = note: `-D clippy::match-wild-err-arm` implied by `-D warnings` error: `Err(_)` matches all errors --> $DIR/match_wild_err_arm.rs:20:9 diff --git a/tests/ui/min_rust_version_attr.stderr b/tests/ui/min_rust_version_attr.stderr index b1c23b539ffd..6e749d2741c4 100644 --- a/tests/ui/min_rust_version_attr.stderr +++ b/tests/ui/min_rust_version_attr.stderr @@ -4,12 +4,12 @@ error: stripping a prefix manually LL | assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!"); | ^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::manual-strip` implied by `-D warnings` note: the prefix was tested here --> $DIR/min_rust_version_attr.rs:203:9 | LL | if s.starts_with("hello, ") { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::manual-strip` implied by `-D warnings` help: try using the `strip_prefix` method | LL ~ if let Some() = s.strip_prefix("hello, ") { diff --git a/tests/ui/mismatched_target_os_unix.stderr b/tests/ui/mismatched_target_os_unix.stderr index 3534b53282f9..9822c77c9dfe 100644 --- a/tests/ui/mismatched_target_os_unix.stderr +++ b/tests/ui/mismatched_target_os_unix.stderr @@ -6,8 +6,8 @@ LL | #[cfg(linux)] | | | help: try: `target_os = "linux"` | - = note: `-D clippy::mismatched-target-os` implied by `-D warnings` = help: did you mean `unix`? + = note: `-D clippy::mismatched-target-os` implied by `-D warnings` error: operating system used in target family position --> $DIR/mismatched_target_os_unix.rs:9:1 diff --git a/tests/ui/mismatching_type_param_order.stderr b/tests/ui/mismatching_type_param_order.stderr index cb720256c50e..204d49905577 100644 --- a/tests/ui/mismatching_type_param_order.stderr +++ b/tests/ui/mismatching_type_param_order.stderr @@ -4,8 +4,8 @@ error: `Foo` has a similarly named generic type parameter `B` in its declaration LL | impl Foo {} | ^ | - = note: `-D clippy::mismatching-type-param-order` implied by `-D warnings` = help: try `A`, or a name that does not conflict with `Foo`'s generic params + = note: `-D clippy::mismatching-type-param-order` implied by `-D warnings` error: `Foo` has a similarly named generic type parameter `A` in its declaration, but in a different order --> $DIR/mismatching_type_param_order.rs:11:23 diff --git a/tests/ui/missing_panics_doc.stderr b/tests/ui/missing_panics_doc.stderr index 91ebd695238b..c9ded7f1ad03 100644 --- a/tests/ui/missing_panics_doc.stderr +++ b/tests/ui/missing_panics_doc.stderr @@ -7,12 +7,12 @@ LL | | result.unwrap() LL | | } | |_^ | - = note: `-D clippy::missing-panics-doc` implied by `-D warnings` note: first possible panic found here --> $DIR/missing_panics_doc.rs:8:5 | LL | result.unwrap() | ^^^^^^^^^^^^^^^ + = note: `-D clippy::missing-panics-doc` implied by `-D warnings` error: docs for function which may panic missing `# Panics` section --> $DIR/missing_panics_doc.rs:12:1 diff --git a/tests/ui/mixed_read_write_in_expression.stderr b/tests/ui/mixed_read_write_in_expression.stderr index 2e951cdbcbfd..8cc68b0ac7b4 100644 --- a/tests/ui/mixed_read_write_in_expression.stderr +++ b/tests/ui/mixed_read_write_in_expression.stderr @@ -4,12 +4,12 @@ error: unsequenced read of `x` LL | } + x; | ^ | - = note: `-D clippy::mixed-read-write-in-expression` implied by `-D warnings` note: whether read occurs before this write depends on evaluation order --> $DIR/mixed_read_write_in_expression.rs:12:9 | LL | x = 1; | ^^^^^ + = note: `-D clippy::mixed-read-write-in-expression` implied by `-D warnings` error: unsequenced read of `x` --> $DIR/mixed_read_write_in_expression.rs:17:5 diff --git a/tests/ui/modulo_arithmetic_float.stderr b/tests/ui/modulo_arithmetic_float.stderr index 97844aaaa759..36106de31f0b 100644 --- a/tests/ui/modulo_arithmetic_float.stderr +++ b/tests/ui/modulo_arithmetic_float.stderr @@ -4,8 +4,8 @@ error: you are using modulo operator on constants with different signs: `-1.600 LL | -1.6 % 2.1; | ^^^^^^^^^^ | - = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` = note: double check for expected result especially when interoperating with different languages + = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` error: you are using modulo operator on constants with different signs: `1.600 % -2.100` --> $DIR/modulo_arithmetic_float.rs:7:5 diff --git a/tests/ui/modulo_arithmetic_integral.stderr b/tests/ui/modulo_arithmetic_integral.stderr index f71adf5b0d01..9ff676ff6bcb 100644 --- a/tests/ui/modulo_arithmetic_integral.stderr +++ b/tests/ui/modulo_arithmetic_integral.stderr @@ -4,9 +4,9 @@ error: you are using modulo operator on types that might have different signs LL | a % b; | ^^^^^ | - = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` = note: double check for expected result especially when interoperating with different languages = note: or consider using `rem_euclid` or similar function + = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` error: you are using modulo operator on types that might have different signs --> $DIR/modulo_arithmetic_integral.rs:9:5 diff --git a/tests/ui/modulo_arithmetic_integral_const.stderr b/tests/ui/modulo_arithmetic_integral_const.stderr index 11b5f77461ba..1453d44f488f 100644 --- a/tests/ui/modulo_arithmetic_integral_const.stderr +++ b/tests/ui/modulo_arithmetic_integral_const.stderr @@ -4,9 +4,9 @@ error: you are using modulo operator on constants with different signs: `-1 % 2` LL | -1 % 2; | ^^^^^^ | - = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` = note: double check for expected result especially when interoperating with different languages = note: or consider using `rem_euclid` or similar function + = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` error: you are using modulo operator on constants with different signs: `1 % -2` --> $DIR/modulo_arithmetic_integral_const.rs:12:5 diff --git a/tests/ui/mut_from_ref.stderr b/tests/ui/mut_from_ref.stderr index b76d6a13ffb9..c20ff54bf949 100644 --- a/tests/ui/mut_from_ref.stderr +++ b/tests/ui/mut_from_ref.stderr @@ -4,12 +4,12 @@ error: mutable borrow from immutable input(s) LL | fn this_wont_hurt_a_bit(&self) -> &mut Foo { | ^^^^^^^^ | - = note: `-D clippy::mut-from-ref` implied by `-D warnings` note: immutable borrow here --> $DIR/mut_from_ref.rs:7:29 | LL | fn this_wont_hurt_a_bit(&self) -> &mut Foo { | ^^^^^ + = note: `-D clippy::mut-from-ref` implied by `-D warnings` error: mutable borrow from immutable input(s) --> $DIR/mut_from_ref.rs:13:25 diff --git a/tests/ui/mut_range_bound.stderr b/tests/ui/mut_range_bound.stderr index 4b5a3fc1e418..e0c8dced382e 100644 --- a/tests/ui/mut_range_bound.stderr +++ b/tests/ui/mut_range_bound.stderr @@ -4,8 +4,8 @@ error: attempt to mutate range bound within loop LL | m = 5; | ^ | - = note: `-D clippy::mut-range-bound` implied by `-D warnings` = note: the range of the loop is unchanged + = note: `-D clippy::mut-range-bound` implied by `-D warnings` error: attempt to mutate range bound within loop --> $DIR/mut_range_bound.rs:15:9 diff --git a/tests/ui/needless_continue.stderr b/tests/ui/needless_continue.stderr index b8657c74caa6..005ba010f34f 100644 --- a/tests/ui/needless_continue.stderr +++ b/tests/ui/needless_continue.stderr @@ -7,7 +7,6 @@ LL | | continue; LL | | } | |_________^ | - = note: `-D clippy::needless-continue` implied by `-D warnings` = help: consider dropping the `else` clause and merging the code that follows (in the loop) with the `if` block if i % 2 == 0 && i % 3 == 0 { println!("{}", i); @@ -33,6 +32,7 @@ LL | | } } println!("bleh"); } + = note: `-D clippy::needless-continue` implied by `-D warnings` error: there is no need for an explicit `else` block for this `if` expression --> $DIR/needless_continue.rs:44:9 diff --git a/tests/ui/non_send_fields_in_send_ty.stderr b/tests/ui/non_send_fields_in_send_ty.stderr index b6c904a147a5..e912b59a6e7b 100644 --- a/tests/ui/non_send_fields_in_send_ty.stderr +++ b/tests/ui/non_send_fields_in_send_ty.stderr @@ -4,13 +4,13 @@ error: some fields in `RingBuffer` are not safe to be sent to another thread LL | unsafe impl Send for RingBuffer {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings` note: it is not safe to send field `data` to another thread --> $DIR/non_send_fields_in_send_ty.rs:12:5 | LL | data: Vec>, | ^^^^^^^^^^^^^^^^^^^^^^^^ = help: add bounds on type parameter `T` that satisfy `Vec>: Send` + = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings` error: some fields in `MvccRwLock` are not safe to be sent to another thread --> $DIR/non_send_fields_in_send_ty.rs:25:1 diff --git a/tests/ui/octal_escapes.stderr b/tests/ui/octal_escapes.stderr index 54f5bbb0fc43..295dc1798e36 100644 --- a/tests/ui/octal_escapes.stderr +++ b/tests/ui/octal_escapes.stderr @@ -4,8 +4,8 @@ error: octal-looking escape in string literal LL | let _bad1 = "/033[0m"; | ^^^^^^^^^ | - = note: `-D clippy::octal-escapes` implied by `-D warnings` = help: octal escapes are not supported, `/0` is always a null character + = note: `-D clippy::octal-escapes` implied by `-D warnings` help: if an octal escape was intended, use the hexadecimal representation instead | LL | let _bad1 = "/x1b[0m"; diff --git a/tests/ui/ok_expect.stderr b/tests/ui/ok_expect.stderr index b02b28e7f68c..6c40adbb53dc 100644 --- a/tests/ui/ok_expect.stderr +++ b/tests/ui/ok_expect.stderr @@ -4,8 +4,8 @@ error: called `ok().expect()` on a `Result` value LL | res.ok().expect("disaster!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::ok-expect` implied by `-D warnings` = help: you can call `expect()` directly on the `Result` + = note: `-D clippy::ok-expect` implied by `-D warnings` error: called `ok().expect()` on a `Result` value --> $DIR/ok_expect.rs:20:5 diff --git a/tests/ui/only_used_in_recursion.stderr b/tests/ui/only_used_in_recursion.stderr index 74057ddcfda4..571e5c4b5faa 100644 --- a/tests/ui/only_used_in_recursion.stderr +++ b/tests/ui/only_used_in_recursion.stderr @@ -4,12 +4,12 @@ error: parameter is only used in recursion LL | fn _one_unused(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | - = note: `-D clippy::only-used-in-recursion` implied by `-D warnings` note: parameter used here --> $DIR/only_used_in_recursion.rs:12:53 | LL | if flag == 0 { 0 } else { _one_unused(flag - 1, a) } | ^ + = note: `-D clippy::only-used-in-recursion` implied by `-D warnings` error: parameter is only used in recursion --> $DIR/only_used_in_recursion.rs:15:27 diff --git a/tests/ui/only_used_in_recursion2.stderr b/tests/ui/only_used_in_recursion2.stderr index 23f6ffd30c97..8dcbfdd612ef 100644 --- a/tests/ui/only_used_in_recursion2.stderr +++ b/tests/ui/only_used_in_recursion2.stderr @@ -4,12 +4,12 @@ error: parameter is only used in recursion LL | fn _with_inner(flag: u32, a: u32, b: u32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | - = note: `-D clippy::only-used-in-recursion` implied by `-D warnings` note: parameter used here --> $DIR/only_used_in_recursion2.rs:9:52 | LL | if flag == 0 { 0 } else { _with_inner(flag, a, b + x) } | ^ + = note: `-D clippy::only-used-in-recursion` implied by `-D warnings` error: parameter is only used in recursion --> $DIR/only_used_in_recursion2.rs:4:25 diff --git a/tests/ui/option_env_unwrap.stderr b/tests/ui/option_env_unwrap.stderr index 885ac096cc8f..bc188a07e9e0 100644 --- a/tests/ui/option_env_unwrap.stderr +++ b/tests/ui/option_env_unwrap.stderr @@ -4,8 +4,8 @@ error: this will panic at run-time if the environment variable doesn't exist at LL | let _ = option_env!("PATH").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::option-env-unwrap` implied by `-D warnings` = help: consider using the `env!` macro instead + = note: `-D clippy::option-env-unwrap` implied by `-D warnings` error: this will panic at run-time if the environment variable doesn't exist at compile-time --> $DIR/option_env_unwrap.rs:19:13 diff --git a/tests/ui/overly_complex_bool_expr.stderr b/tests/ui/overly_complex_bool_expr.stderr index 158cae8b8f37..e989f2ece308 100644 --- a/tests/ui/overly_complex_bool_expr.stderr +++ b/tests/ui/overly_complex_bool_expr.stderr @@ -4,12 +4,12 @@ error: this boolean expression contains a logic bug LL | let _ = a && b || a; | ^^^^^^^^^^^ help: it would look like the following: `a` | - = note: `-D clippy::overly-complex-bool-expr` implied by `-D warnings` help: this expression can be optimized out by applying boolean operations to the outer expression --> $DIR/overly_complex_bool_expr.rs:11:18 | LL | let _ = a && b || a; | ^ + = note: `-D clippy::overly-complex-bool-expr` implied by `-D warnings` error: this boolean expression contains a logic bug --> $DIR/overly_complex_bool_expr.rs:13:13 diff --git a/tests/ui/panic_in_result_fn.stderr b/tests/ui/panic_in_result_fn.stderr index 561503ae54fa..97787bc84e2c 100644 --- a/tests/ui/panic_in_result_fn.stderr +++ b/tests/ui/panic_in_result_fn.stderr @@ -7,13 +7,13 @@ LL | | panic!("error"); LL | | } | |_____^ | - = note: `-D clippy::panic-in-result-fn` implied by `-D warnings` = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking --> $DIR/panic_in_result_fn.rs:8:9 | LL | panic!("error"); | ^^^^^^^^^^^^^^^ + = note: `-D clippy::panic-in-result-fn` implied by `-D warnings` error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn.rs:11:5 diff --git a/tests/ui/panic_in_result_fn_assertions.stderr b/tests/ui/panic_in_result_fn_assertions.stderr index b6aa005e7b52..eb0aacbb6a44 100644 --- a/tests/ui/panic_in_result_fn_assertions.stderr +++ b/tests/ui/panic_in_result_fn_assertions.stderr @@ -8,13 +8,13 @@ LL | | Ok(true) LL | | } | |_____^ | - = note: `-D clippy::panic-in-result-fn` implied by `-D warnings` = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking --> $DIR/panic_in_result_fn_assertions.rs:9:9 | LL | assert!(x == 5, "wrong argument"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::panic-in-result-fn` implied by `-D warnings` error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn_assertions.rs:13:5 diff --git a/tests/ui/pattern_type_mismatch/mutability.stderr b/tests/ui/pattern_type_mismatch/mutability.stderr index 3421d568365c..87fb243b65ef 100644 --- a/tests/ui/pattern_type_mismatch/mutability.stderr +++ b/tests/ui/pattern_type_mismatch/mutability.stderr @@ -4,8 +4,8 @@ error: type of pattern does not match the expression type LL | Some(_) => (), | ^^^^^^^ | - = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings + = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` error: type of pattern does not match the expression type --> $DIR/mutability.rs:15:9 diff --git a/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr b/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr index d285c93782c6..a91b5ac6cf74 100644 --- a/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr @@ -4,8 +4,8 @@ error: type of pattern does not match the expression type LL | if let Value::B | Value::A(_) = ref_value {} | ^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings + = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` error: type of pattern does not match the expression type --> $DIR/pattern_alternatives.rs:16:34 diff --git a/tests/ui/pattern_type_mismatch/pattern_structs.stderr b/tests/ui/pattern_type_mismatch/pattern_structs.stderr index d428e85b0c91..8bc5c63baab5 100644 --- a/tests/ui/pattern_type_mismatch/pattern_structs.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_structs.stderr @@ -4,8 +4,8 @@ error: type of pattern does not match the expression type LL | let Struct { .. } = ref_value; | ^^^^^^^^^^^^^ | - = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings + = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` error: type of pattern does not match the expression type --> $DIR/pattern_structs.rs:14:33 diff --git a/tests/ui/pattern_type_mismatch/pattern_tuples.stderr b/tests/ui/pattern_type_mismatch/pattern_tuples.stderr index edd0074d00d3..a1ef540d2831 100644 --- a/tests/ui/pattern_type_mismatch/pattern_tuples.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_tuples.stderr @@ -4,8 +4,8 @@ error: type of pattern does not match the expression type LL | let TupleStruct(_) = ref_value; | ^^^^^^^^^^^^^^ | - = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings + = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` error: type of pattern does not match the expression type --> $DIR/pattern_tuples.rs:12:25 diff --git a/tests/ui/pattern_type_mismatch/syntax.stderr b/tests/ui/pattern_type_mismatch/syntax.stderr index 12b3d3a8bd07..f56a3a893801 100644 --- a/tests/ui/pattern_type_mismatch/syntax.stderr +++ b/tests/ui/pattern_type_mismatch/syntax.stderr @@ -4,8 +4,8 @@ error: type of pattern does not match the expression type LL | Some(_) => (), | ^^^^^^^ | - = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings + = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` error: type of pattern does not match the expression type --> $DIR/syntax.rs:30:12 diff --git a/tests/ui/proc_macro.stderr b/tests/ui/proc_macro.stderr index 48fd58c9a493..c795f6ad0d25 100644 --- a/tests/ui/proc_macro.stderr +++ b/tests/ui/proc_macro.stderr @@ -4,8 +4,8 @@ error: approximate value of `f{32, 64}::consts::PI` found LL | let _x = 3.14; | ^^^^ | - = note: `#[deny(clippy::approx_constant)]` on by default = help: consider using the constant directly + = note: `#[deny(clippy::approx_constant)]` on by default error: aborting due to previous error diff --git a/tests/ui/pub_use.stderr b/tests/ui/pub_use.stderr index 9ab710df818c..ba4ee732c05c 100644 --- a/tests/ui/pub_use.stderr +++ b/tests/ui/pub_use.stderr @@ -4,8 +4,8 @@ error: using `pub use` LL | pub use inner::Test; | ^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::pub-use` implied by `-D warnings` = help: move the exported item to a public module instead + = note: `-D clippy::pub-use` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/rc_clone_in_vec_init/arc.stderr b/tests/ui/rc_clone_in_vec_init/arc.stderr index cd7d91e12065..7814f5b54036 100644 --- a/tests/ui/rc_clone_in_vec_init/arc.stderr +++ b/tests/ui/rc_clone_in_vec_init/arc.stderr @@ -4,8 +4,8 @@ error: initializing a reference-counted pointer in `vec![elem; len]` LL | let v = vec![Arc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings` = note: each element will point to the same `Arc` instance + = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings` help: consider initializing each `Arc` element individually | LL ~ let v = { diff --git a/tests/ui/rc_clone_in_vec_init/rc.stderr b/tests/ui/rc_clone_in_vec_init/rc.stderr index fe861afe0549..80deb7cb9f24 100644 --- a/tests/ui/rc_clone_in_vec_init/rc.stderr +++ b/tests/ui/rc_clone_in_vec_init/rc.stderr @@ -4,8 +4,8 @@ error: initializing a reference-counted pointer in `vec![elem; len]` LL | let v = vec![Rc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings` = note: each element will point to the same `Rc` instance + = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings` help: consider initializing each `Rc` element individually | LL ~ let v = { diff --git a/tests/ui/rc_clone_in_vec_init/weak.stderr b/tests/ui/rc_clone_in_vec_init/weak.stderr index 4a21946ccdfa..789e14a302f6 100644 --- a/tests/ui/rc_clone_in_vec_init/weak.stderr +++ b/tests/ui/rc_clone_in_vec_init/weak.stderr @@ -4,8 +4,8 @@ error: initializing a reference-counted pointer in `vec![elem; len]` LL | let v = vec![SyncWeak::::new(); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings` = note: each element will point to the same `Weak` instance + = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings` help: consider initializing each `Weak` element individually | LL ~ let v = { diff --git a/tests/ui/rc_mutex.stderr b/tests/ui/rc_mutex.stderr index fe84361d7816..cee3bd8b224d 100644 --- a/tests/ui/rc_mutex.stderr +++ b/tests/ui/rc_mutex.stderr @@ -4,8 +4,8 @@ error: usage of `Rc>` LL | foo: Rc>, | ^^^^^^^^^^^^^^ | - = note: `-D clippy::rc-mutex` implied by `-D warnings` = help: consider using `Rc>` or `Arc>` instead + = note: `-D clippy::rc-mutex` implied by `-D warnings` error: usage of `Rc>` --> $DIR/rc_mutex.rs:26:18 diff --git a/tests/ui/redundant_allocation.stderr b/tests/ui/redundant_allocation.stderr index 54d4d88dba81..e0826fefa6cf 100644 --- a/tests/ui/redundant_allocation.stderr +++ b/tests/ui/redundant_allocation.stderr @@ -4,9 +4,9 @@ error: usage of `Box>` LL | pub fn box_test6(foo: Box>) {} | ^^^^^^^^^^ | - = note: `-D clippy::redundant-allocation` implied by `-D warnings` = note: `Rc` is already on the heap, `Box>` makes an extra allocation = help: consider using just `Box` or `Rc` + = note: `-D clippy::redundant-allocation` implied by `-D warnings` error: usage of `Box>` --> $DIR/redundant_allocation.rs:19:30 diff --git a/tests/ui/redundant_allocation_fixable.stderr b/tests/ui/redundant_allocation_fixable.stderr index fdd76ef17a55..8dd4a6a26874 100644 --- a/tests/ui/redundant_allocation_fixable.stderr +++ b/tests/ui/redundant_allocation_fixable.stderr @@ -4,8 +4,8 @@ error: usage of `Box<&T>` LL | pub fn box_test1(foo: Box<&T>) {} | ^^^^^^^ help: try: `&T` | - = note: `-D clippy::redundant-allocation` implied by `-D warnings` = note: `&T` is already a pointer, `Box<&T>` allocates a pointer on the heap + = note: `-D clippy::redundant-allocation` implied by `-D warnings` error: usage of `Box<&MyStruct>` --> $DIR/redundant_allocation_fixable.rs:28:27 diff --git a/tests/ui/redundant_clone.stderr b/tests/ui/redundant_clone.stderr index aa1dd7cbb45c..782590034d05 100644 --- a/tests/ui/redundant_clone.stderr +++ b/tests/ui/redundant_clone.stderr @@ -4,12 +4,12 @@ error: redundant clone LL | let _s = ["lorem", "ipsum"].join(" ").to_string(); | ^^^^^^^^^^^^ help: remove this | - = note: `-D clippy::redundant-clone` implied by `-D warnings` note: this value is dropped without further use --> $DIR/redundant_clone.rs:10:14 | LL | let _s = ["lorem", "ipsum"].join(" ").to_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::redundant-clone` implied by `-D warnings` error: redundant clone --> $DIR/redundant_clone.rs:13:15 diff --git a/tests/ui/redundant_else.stderr b/tests/ui/redundant_else.stderr index 9000cdc814b1..de9d00a60246 100644 --- a/tests/ui/redundant_else.stderr +++ b/tests/ui/redundant_else.stderr @@ -7,8 +7,8 @@ LL | | println!("yet don't pull down your hedge."); LL | | } | |_________^ | - = note: `-D clippy::redundant-else` implied by `-D warnings` = help: remove the `else` block and move the contents out + = note: `-D clippy::redundant-else` implied by `-D warnings` error: redundant else block --> $DIR/redundant_else.rs:17:16 diff --git a/tests/ui/redundant_pattern_matching_drop_order.stderr b/tests/ui/redundant_pattern_matching_drop_order.stderr index eb7aa70ee273..23f08103f358 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.stderr +++ b/tests/ui/redundant_pattern_matching_drop_order.stderr @@ -4,9 +4,9 @@ error: redundant pattern matching, consider using `is_ok()` LL | if let Ok(_) = m.lock() {} | -------^^^^^----------- help: try this: `if m.lock().is_ok()` | - = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important + = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` error: redundant pattern matching, consider using `is_err()` --> $DIR/redundant_pattern_matching_drop_order.rs:13:12 diff --git a/tests/ui/regex.stderr b/tests/ui/regex.stderr index 1394a9b63bc6..2424644c6f6b 100644 --- a/tests/ui/regex.stderr +++ b/tests/ui/regex.stderr @@ -4,8 +4,8 @@ error: trivial regex LL | let pipe_in_wrong_position = Regex::new("|"); | ^^^ | - = note: `-D clippy::trivial-regex` implied by `-D warnings` = help: the regex is unlikely to be useful as it is + = note: `-D clippy::trivial-regex` implied by `-D warnings` error: trivial regex --> $DIR/regex.rs:14:60 diff --git a/tests/ui/rest_pat_in_fully_bound_structs.stderr b/tests/ui/rest_pat_in_fully_bound_structs.stderr index 57ebd47f8c7a..e15633fb1a13 100644 --- a/tests/ui/rest_pat_in_fully_bound_structs.stderr +++ b/tests/ui/rest_pat_in_fully_bound_structs.stderr @@ -4,8 +4,8 @@ error: unnecessary use of `..` pattern in struct binding. All fields were alread LL | A { a: 5, b: 42, c: "", .. } => {}, // Lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::rest-pat-in-fully-bound-structs` implied by `-D warnings` = help: consider removing `..` from this binding + = note: `-D clippy::rest-pat-in-fully-bound-structs` implied by `-D warnings` error: unnecessary use of `..` pattern in struct binding. All fields were already bound --> $DIR/rest_pat_in_fully_bound_structs.rs:23:9 diff --git a/tests/ui/result_large_err.stderr b/tests/ui/result_large_err.stderr index ef19f2854ab1..bea101fe20bf 100644 --- a/tests/ui/result_large_err.stderr +++ b/tests/ui/result_large_err.stderr @@ -4,8 +4,8 @@ error: the `Err`-variant returned from this function is very large LL | pub fn large_err() -> Result<(), [u8; 512]> { | ^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes | - = note: `-D clippy::result-large-err` implied by `-D warnings` = help: try reducing the size of `[u8; 512]`, for example by boxing large elements or replacing it with `Box<[u8; 512]>` + = note: `-D clippy::result-large-err` implied by `-D warnings` error: the `Err`-variant returned from this function is very large --> $DIR/result_large_err.rs:19:21 diff --git a/tests/ui/result_unit_error.stderr b/tests/ui/result_unit_error.stderr index 8c7573eabda9..8393a4bf03bc 100644 --- a/tests/ui/result_unit_error.stderr +++ b/tests/ui/result_unit_error.stderr @@ -4,8 +4,8 @@ error: this returns a `Result<_, ()>` LL | pub fn returns_unit_error() -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::result-unit-err` implied by `-D warnings` = help: use a custom `Error` type instead + = note: `-D clippy::result-unit-err` implied by `-D warnings` error: this returns a `Result<_, ()>` --> $DIR/result_unit_error.rs:12:5 diff --git a/tests/ui/return_self_not_must_use.stderr b/tests/ui/return_self_not_must_use.stderr index 94be87dfa31c..34932fe1c2c5 100644 --- a/tests/ui/return_self_not_must_use.stderr +++ b/tests/ui/return_self_not_must_use.stderr @@ -4,8 +4,8 @@ error: missing `#[must_use]` attribute on a method returning `Self` LL | fn what(&self) -> Self; | ^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::return-self-not-must-use` implied by `-D warnings` = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type + = note: `-D clippy::return-self-not-must-use` implied by `-D warnings` error: missing `#[must_use]` attribute on a method returning `Self` --> $DIR/return_self_not_must_use.rs:18:5 diff --git a/tests/ui/same_functions_in_if_condition.stderr b/tests/ui/same_functions_in_if_condition.stderr index cd438b830401..3901546cbd65 100644 --- a/tests/ui/same_functions_in_if_condition.stderr +++ b/tests/ui/same_functions_in_if_condition.stderr @@ -4,12 +4,12 @@ error: this `if` has the same function call as a previous `if` LL | } else if function() { | ^^^^^^^^^^ | - = note: `-D clippy::same-functions-in-if-condition` implied by `-D warnings` note: same as this --> $DIR/same_functions_in_if_condition.rs:30:8 | LL | if function() { | ^^^^^^^^^^ + = note: `-D clippy::same-functions-in-if-condition` implied by `-D warnings` error: this `if` has the same function call as a previous `if` --> $DIR/same_functions_in_if_condition.rs:36:15 diff --git a/tests/ui/same_item_push.stderr b/tests/ui/same_item_push.stderr index d9ffa15780ad..1d1254d9fcc6 100644 --- a/tests/ui/same_item_push.stderr +++ b/tests/ui/same_item_push.stderr @@ -4,8 +4,8 @@ error: it looks like the same item is being pushed into this Vec LL | vec.push(item); | ^^^ | - = note: `-D clippy::same-item-push` implied by `-D warnings` = help: try using vec![item;SIZE] or vec.resize(NEW_SIZE, item) + = note: `-D clippy::same-item-push` implied by `-D warnings` error: it looks like the same item is being pushed into this Vec --> $DIR/same_item_push.rs:29:9 diff --git a/tests/ui/same_name_method.stderr b/tests/ui/same_name_method.stderr index f55ec9f3cc66..0c6908c09593 100644 --- a/tests/ui/same_name_method.stderr +++ b/tests/ui/same_name_method.stderr @@ -4,12 +4,12 @@ error: method's name is the same as an existing method in a trait LL | fn foo() {} | ^^^^^^^^^^^ | - = note: `-D clippy::same-name-method` implied by `-D warnings` note: existing `foo` defined here --> $DIR/same_name_method.rs:25:13 | LL | fn foo() {} | ^^^^^^^^^^^ + = note: `-D clippy::same-name-method` implied by `-D warnings` error: method's name is the same as an existing method in a trait --> $DIR/same_name_method.rs:35:13 diff --git a/tests/ui/search_is_some.stderr b/tests/ui/search_is_some.stderr index 54760545bced..6bea8c674779 100644 --- a/tests/ui/search_is_some.stderr +++ b/tests/ui/search_is_some.stderr @@ -8,8 +8,8 @@ LL | | } LL | | ).is_some(); | |______________________________^ | - = note: `-D clippy::search-is-some` implied by `-D warnings` = help: this is more succinctly expressed by calling `any()` + = note: `-D clippy::search-is-some` implied by `-D warnings` error: called `is_some()` after searching an `Iterator` with `position` --> $DIR/search_is_some.rs:20:13 diff --git a/tests/ui/shadow.stderr b/tests/ui/shadow.stderr index 43d76094d0e8..c3d7bc2a5360 100644 --- a/tests/ui/shadow.stderr +++ b/tests/ui/shadow.stderr @@ -4,12 +4,12 @@ error: `x` is shadowed by itself in `x` LL | let x = x; | ^ | - = note: `-D clippy::shadow-same` implied by `-D warnings` note: previous binding is here --> $DIR/shadow.rs:5:9 | LL | let x = 1; | ^ + = note: `-D clippy::shadow-same` implied by `-D warnings` error: `mut x` is shadowed by itself in `&x` --> $DIR/shadow.rs:7:13 @@ -53,12 +53,12 @@ error: `x` is shadowed LL | let x = x.0; | ^ | - = note: `-D clippy::shadow-reuse` implied by `-D warnings` note: previous binding is here --> $DIR/shadow.rs:13:9 | LL | let x = ([[0]], ()); | ^ + = note: `-D clippy::shadow-reuse` implied by `-D warnings` error: `x` is shadowed --> $DIR/shadow.rs:15:9 @@ -150,12 +150,12 @@ error: `x` shadows a previous, unrelated binding LL | let x = 2; | ^ | - = note: `-D clippy::shadow-unrelated` implied by `-D warnings` note: previous binding is here --> $DIR/shadow.rs:30:9 | LL | let x = 1; | ^ + = note: `-D clippy::shadow-unrelated` implied by `-D warnings` error: `x` shadows a previous, unrelated binding --> $DIR/shadow.rs:36:13 diff --git a/tests/ui/should_impl_trait/method_list_1.stderr b/tests/ui/should_impl_trait/method_list_1.stderr index 2b7d4628c3fa..d2f41e3f934a 100644 --- a/tests/ui/should_impl_trait/method_list_1.stderr +++ b/tests/ui/should_impl_trait/method_list_1.stderr @@ -6,8 +6,8 @@ LL | | unimplemented!() LL | | } | |_____^ | - = note: `-D clippy::should-implement-trait` implied by `-D warnings` = help: consider implementing the trait `std::ops::Add` or choosing a less ambiguous method name + = note: `-D clippy::should-implement-trait` implied by `-D warnings` error: method `as_mut` can be confused for the standard trait method `std::convert::AsMut::as_mut` --> $DIR/method_list_1.rs:29:5 diff --git a/tests/ui/should_impl_trait/method_list_2.stderr b/tests/ui/should_impl_trait/method_list_2.stderr index b6fd43569569..10bfea68ff57 100644 --- a/tests/ui/should_impl_trait/method_list_2.stderr +++ b/tests/ui/should_impl_trait/method_list_2.stderr @@ -6,8 +6,8 @@ LL | | unimplemented!() LL | | } | |_____^ | - = note: `-D clippy::should-implement-trait` implied by `-D warnings` = help: consider implementing the trait `std::cmp::PartialEq` or choosing a less ambiguous method name + = note: `-D clippy::should-implement-trait` implied by `-D warnings` error: method `from_iter` can be confused for the standard trait method `std::iter::FromIterator::from_iter` --> $DIR/method_list_2.rs:30:5 diff --git a/tests/ui/significant_drop_in_scrutinee.stderr b/tests/ui/significant_drop_in_scrutinee.stderr index 88ea6bce25b6..f1ed808ba087 100644 --- a/tests/ui/significant_drop_in_scrutinee.stderr +++ b/tests/ui/significant_drop_in_scrutinee.stderr @@ -10,8 +10,8 @@ LL | mutex.lock().unwrap().bar(); LL | }; | - temporary lives until here | - = note: `-D clippy::significant-drop-in-scrutinee` implied by `-D warnings` = note: this might lead to deadlocks or other unexpected behavior + = note: `-D clippy::significant-drop-in-scrutinee` implied by `-D warnings` help: try moving the temporary above the match | LL ~ let value = mutex.lock().unwrap().foo(); diff --git a/tests/ui/similar_names.stderr b/tests/ui/similar_names.stderr index 6e7726938973..43c5cee4b457 100644 --- a/tests/ui/similar_names.stderr +++ b/tests/ui/similar_names.stderr @@ -4,12 +4,12 @@ error: binding's name is too similar to existing binding LL | let bpple: i32; | ^^^^^ | - = note: `-D clippy::similar-names` implied by `-D warnings` note: existing binding defined here --> $DIR/similar_names.rs:19:9 | LL | let apple: i32; | ^^^^^ + = note: `-D clippy::similar-names` implied by `-D warnings` error: binding's name is too similar to existing binding --> $DIR/similar_names.rs:23:9 diff --git a/tests/ui/single_char_lifetime_names.stderr b/tests/ui/single_char_lifetime_names.stderr index 1438b3999dba..bfe6d44b5898 100644 --- a/tests/ui/single_char_lifetime_names.stderr +++ b/tests/ui/single_char_lifetime_names.stderr @@ -4,8 +4,8 @@ error: single-character lifetime names are likely uninformative LL | struct DiagnosticCtx<'a, 'b> | ^^ | - = note: `-D clippy::single-char-lifetime-names` implied by `-D warnings` = help: use a more informative name + = note: `-D clippy::single-char-lifetime-names` implied by `-D warnings` error: single-character lifetime names are likely uninformative --> $DIR/single_char_lifetime_names.rs:5:26 diff --git a/tests/ui/single_component_path_imports_nested_first.stderr b/tests/ui/single_component_path_imports_nested_first.stderr index cf990be1b9ff..633546f6419a 100644 --- a/tests/ui/single_component_path_imports_nested_first.stderr +++ b/tests/ui/single_component_path_imports_nested_first.stderr @@ -4,8 +4,8 @@ error: this import is redundant LL | use {regex, serde}; | ^^^^^ | - = note: `-D clippy::single-component-path-imports` implied by `-D warnings` = help: remove this import + = note: `-D clippy::single-component-path-imports` implied by `-D warnings` error: this import is redundant --> $DIR/single_component_path_imports_nested_first.rs:13:17 diff --git a/tests/ui/size_of_in_element_count/expressions.stderr b/tests/ui/size_of_in_element_count/expressions.stderr index 0f0dff57f51b..037f695f3ee9 100644 --- a/tests/ui/size_of_in_element_count/expressions.stderr +++ b/tests/ui/size_of_in_element_count/expressions.stderr @@ -4,8 +4,8 @@ error: found a count of bytes instead of a count of elements of `T` LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::size-of-in-element-count` implied by `-D warnings` = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type + = note: `-D clippy::size-of-in-element-count` implied by `-D warnings` error: found a count of bytes instead of a count of elements of `T` --> $DIR/expressions.rs:18:62 diff --git a/tests/ui/size_of_in_element_count/functions.stderr b/tests/ui/size_of_in_element_count/functions.stderr index c1e824167b7f..4351e6a14fe5 100644 --- a/tests/ui/size_of_in_element_count/functions.stderr +++ b/tests/ui/size_of_in_element_count/functions.stderr @@ -4,8 +4,8 @@ error: found a count of bytes instead of a count of elements of `T` LL | unsafe { copy_nonoverlapping::(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^ | - = note: `-D clippy::size-of-in-element-count` implied by `-D warnings` = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type + = note: `-D clippy::size-of-in-element-count` implied by `-D warnings` error: found a count of bytes instead of a count of elements of `T` --> $DIR/functions.rs:19:62 diff --git a/tests/ui/skip_while_next.stderr b/tests/ui/skip_while_next.stderr index 269cc13468bc..7308ab4e55c9 100644 --- a/tests/ui/skip_while_next.stderr +++ b/tests/ui/skip_while_next.stderr @@ -4,8 +4,8 @@ error: called `skip_while(

).next()` on an `Iterator` LL | let _ = v.iter().skip_while(|&x| *x < 0).next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::skip-while-next` implied by `-D warnings` = help: this is more succinctly expressed by calling `.find(!

)` instead + = note: `-D clippy::skip-while-next` implied by `-D warnings` error: called `skip_while(

).next()` on an `Iterator` --> $DIR/skip_while_next.rs:17:13 diff --git a/tests/ui/stable_sort_primitive.stderr b/tests/ui/stable_sort_primitive.stderr index c35e0c22ae89..1432fdcff77a 100644 --- a/tests/ui/stable_sort_primitive.stderr +++ b/tests/ui/stable_sort_primitive.stderr @@ -4,8 +4,8 @@ error: used `sort` on primitive type `i32` LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` | - = note: `-D clippy::stable-sort-primitive` implied by `-D warnings` = note: an unstable sort typically performs faster without any observable difference for this data type + = note: `-D clippy::stable-sort-primitive` implied by `-D warnings` error: used `sort` on primitive type `bool` --> $DIR/stable_sort_primitive.rs:9:5 diff --git a/tests/ui/std_instead_of_core.stderr b/tests/ui/std_instead_of_core.stderr index bc49dabf5868..8138ccb82a00 100644 --- a/tests/ui/std_instead_of_core.stderr +++ b/tests/ui/std_instead_of_core.stderr @@ -4,8 +4,8 @@ error: used import from `std` instead of `core` LL | use std::hash::Hasher; | ^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::std-instead-of-core` implied by `-D warnings` = help: consider importing the item from `core` + = note: `-D clippy::std-instead-of-core` implied by `-D warnings` error: used import from `std` instead of `core` --> $DIR/std_instead_of_core.rs:11:9 @@ -69,8 +69,8 @@ error: used import from `std` instead of `alloc` LL | use std::vec; | ^^^^^^^^ | - = note: `-D clippy::std-instead-of-alloc` implied by `-D warnings` = help: consider importing the item from `alloc` + = note: `-D clippy::std-instead-of-alloc` implied by `-D warnings` error: used import from `std` instead of `alloc` --> $DIR/std_instead_of_core.rs:33:9 @@ -86,8 +86,8 @@ error: used import from `alloc` instead of `core` LL | use alloc::slice::from_ref; | ^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::alloc-instead-of-core` implied by `-D warnings` = help: consider importing the item from `core` + = note: `-D clippy::alloc-instead-of-core` implied by `-D warnings` error: aborting due to 11 previous errors diff --git a/tests/ui/str_to_string.stderr b/tests/ui/str_to_string.stderr index b1f73eda5d26..1d47da571fa1 100644 --- a/tests/ui/str_to_string.stderr +++ b/tests/ui/str_to_string.stderr @@ -4,8 +4,8 @@ error: `to_string()` called on a `&str` LL | let hello = "hello world".to_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::str-to-string` implied by `-D warnings` = help: consider using `.to_owned()` + = note: `-D clippy::str-to-string` implied by `-D warnings` error: `to_string()` called on a `&str` --> $DIR/str_to_string.rs:6:5 diff --git a/tests/ui/string_to_string.stderr b/tests/ui/string_to_string.stderr index 1ebd17999bd8..e304c3e346db 100644 --- a/tests/ui/string_to_string.stderr +++ b/tests/ui/string_to_string.stderr @@ -4,8 +4,8 @@ error: `to_string()` called on a `String` LL | let mut v = message.to_string(); | ^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::string-to-string` implied by `-D warnings` = help: consider using `.clone()` + = note: `-D clippy::string-to-string` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/struct_excessive_bools.stderr b/tests/ui/struct_excessive_bools.stderr index 2941bf2983aa..e4d50043acb0 100644 --- a/tests/ui/struct_excessive_bools.stderr +++ b/tests/ui/struct_excessive_bools.stderr @@ -9,8 +9,8 @@ LL | | d: bool, LL | | } | |_^ | - = note: `-D clippy::struct-excessive-bools` implied by `-D warnings` = help: consider using a state machine or refactoring bools into two-variant enums + = note: `-D clippy::struct-excessive-bools` implied by `-D warnings` error: more than 3 bools in a struct --> $DIR/struct_excessive_bools.rs:38:5 diff --git a/tests/ui/suspicious_else_formatting.stderr b/tests/ui/suspicious_else_formatting.stderr index ee68eb5a791c..2e512b47f123 100644 --- a/tests/ui/suspicious_else_formatting.stderr +++ b/tests/ui/suspicious_else_formatting.stderr @@ -4,8 +4,8 @@ error: this looks like an `else {..}` but the `else` is missing LL | } { | ^ | - = note: `-D clippy::suspicious-else-formatting` implied by `-D warnings` = note: to remove this lint, add the missing `else` or add a new line before the next block + = note: `-D clippy::suspicious-else-formatting` implied by `-D warnings` error: this looks like an `else if` but the `else` is missing --> $DIR/suspicious_else_formatting.rs:21:6 diff --git a/tests/ui/suspicious_map.stderr b/tests/ui/suspicious_map.stderr index 3ffcd1a90317..e251674819e4 100644 --- a/tests/ui/suspicious_map.stderr +++ b/tests/ui/suspicious_map.stderr @@ -4,8 +4,8 @@ error: this call to `map()` won't have an effect on the call to `count()` LL | let _ = (0..3).map(|x| x + 2).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::suspicious-map` implied by `-D warnings` = help: make sure you did not confuse `map` with `filter`, `for_each` or `inspect` + = note: `-D clippy::suspicious-map` implied by `-D warnings` error: this call to `map()` won't have an effect on the call to `count()` --> $DIR/suspicious_map.rs:7:13 diff --git a/tests/ui/suspicious_splitn.stderr b/tests/ui/suspicious_splitn.stderr index 3bcd681fa49d..55ce63d4faa8 100644 --- a/tests/ui/suspicious_splitn.stderr +++ b/tests/ui/suspicious_splitn.stderr @@ -4,8 +4,8 @@ error: `splitn` called with `0` splits LL | let _ = "a,b".splitn(0, ','); | ^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::suspicious-splitn` implied by `-D warnings` = note: the resulting iterator will always return `None` + = note: `-D clippy::suspicious-splitn` implied by `-D warnings` error: `rsplitn` called with `0` splits --> $DIR/suspicious_splitn.rs:11:13 diff --git a/tests/ui/suspicious_unary_op_formatting.stderr b/tests/ui/suspicious_unary_op_formatting.stderr index 581527dcff8e..9f1289ccba0c 100644 --- a/tests/ui/suspicious_unary_op_formatting.stderr +++ b/tests/ui/suspicious_unary_op_formatting.stderr @@ -4,8 +4,8 @@ error: by not having a space between `>` and `-` it looks like `>-` is a single LL | if a >- 30 {} | ^^^^ | - = note: `-D clippy::suspicious-unary-op-formatting` implied by `-D warnings` = help: put a space between `>` and `-` and remove the space after `-` + = note: `-D clippy::suspicious-unary-op-formatting` implied by `-D warnings` error: by not having a space between `>=` and `-` it looks like `>=-` is a single operator --> $DIR/suspicious_unary_op_formatting.rs:9:9 diff --git a/tests/ui/swap.stderr b/tests/ui/swap.stderr index 2b556b475cee..ee4b7a508a5e 100644 --- a/tests/ui/swap.stderr +++ b/tests/ui/swap.stderr @@ -6,8 +6,8 @@ LL | | bar.a = bar.b; LL | | bar.b = temp; | |________________^ help: try: `std::mem::swap(&mut bar.a, &mut bar.b)` | - = note: `-D clippy::manual-swap` implied by `-D warnings` = note: or maybe you should use `std::mem::replace`? + = note: `-D clippy::manual-swap` implied by `-D warnings` error: this looks like you are swapping elements of `foo` manually --> $DIR/swap.rs:36:5 @@ -96,8 +96,8 @@ LL | / a = b; LL | | b = a; | |_________^ help: try: `std::mem::swap(&mut a, &mut b)` | - = note: `-D clippy::almost-swapped` implied by `-D warnings` = note: or maybe you should use `std::mem::replace`? + = note: `-D clippy::almost-swapped` implied by `-D warnings` error: this looks like you are trying to swap `c.0` and `a` --> $DIR/swap.rs:140:5 diff --git a/tests/ui/trailing_empty_array.stderr b/tests/ui/trailing_empty_array.stderr index 9e2bd31d9fa5..2e1484400352 100644 --- a/tests/ui/trailing_empty_array.stderr +++ b/tests/ui/trailing_empty_array.stderr @@ -7,8 +7,8 @@ LL | | last: [usize; 0], LL | | } | |_^ | - = note: `-D clippy::trailing-empty-array` implied by `-D warnings` = help: consider annotating `RarelyUseful` with `#[repr(C)]` or another `repr` attribute + = note: `-D clippy::trailing-empty-array` implied by `-D warnings` error: trailing zero-sized array in a struct which is not marked with a `repr` attribute --> $DIR/trailing_empty_array.rs:10:1 diff --git a/tests/ui/trait_duplication_in_bounds_unfixable.stderr b/tests/ui/trait_duplication_in_bounds_unfixable.stderr index fbd9abb005f1..4d56a94646cb 100644 --- a/tests/ui/trait_duplication_in_bounds_unfixable.stderr +++ b/tests/ui/trait_duplication_in_bounds_unfixable.stderr @@ -4,12 +4,12 @@ error: this trait bound is already specified in the where clause LL | fn bad_foo(arg0: T, arg1: Z) | ^^^^^ | + = help: consider removing this trait bound note: the lint level is defined here --> $DIR/trait_duplication_in_bounds_unfixable.rs:1:9 | LL | #![deny(clippy::trait_duplication_in_bounds)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: consider removing this trait bound error: this trait bound is already specified in the where clause --> $DIR/trait_duplication_in_bounds_unfixable.rs:6:23 diff --git a/tests/ui/type_repetition_in_bounds.stderr b/tests/ui/type_repetition_in_bounds.stderr index 1d88714814d4..70d700c1cc46 100644 --- a/tests/ui/type_repetition_in_bounds.stderr +++ b/tests/ui/type_repetition_in_bounds.stderr @@ -4,12 +4,12 @@ error: this type has already been used as a bound predicate LL | T: Clone, | ^^^^^^^^ | + = help: consider combining the bounds: `T: Copy + Clone` note: the lint level is defined here --> $DIR/type_repetition_in_bounds.rs:1:9 | LL | #![deny(clippy::type_repetition_in_bounds)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: consider combining the bounds: `T: Copy + Clone` error: this type has already been used as a bound predicate --> $DIR/type_repetition_in_bounds.rs:25:5 diff --git a/tests/ui/undocumented_unsafe_blocks.stderr b/tests/ui/undocumented_unsafe_blocks.stderr index c6a2127443be..2c466ff5c733 100644 --- a/tests/ui/undocumented_unsafe_blocks.stderr +++ b/tests/ui/undocumented_unsafe_blocks.stderr @@ -4,8 +4,8 @@ error: unsafe block missing a safety comment LL | /* Safety: */ unsafe {} | ^^^^^^^^^ | - = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` = help: consider adding a safety comment on the preceding line + = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` error: unsafe block missing a safety comment --> $DIR/undocumented_unsafe_blocks.rs:266:5 diff --git a/tests/ui/undropped_manually_drops.stderr b/tests/ui/undropped_manually_drops.stderr index 2ac0fe98697e..92611a9b7df4 100644 --- a/tests/ui/undropped_manually_drops.stderr +++ b/tests/ui/undropped_manually_drops.stderr @@ -4,8 +4,8 @@ error: the inner value of this ManuallyDrop will not be dropped LL | drop(std::mem::ManuallyDrop::new(S)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::undropped-manually-drops` implied by `-D warnings` = help: to drop a `ManuallyDrop`, use std::mem::ManuallyDrop::drop + = note: `-D clippy::undropped-manually-drops` implied by `-D warnings` error: the inner value of this ManuallyDrop will not be dropped --> $DIR/undropped_manually_drops.rs:15:5 diff --git a/tests/ui/uninit_vec.stderr b/tests/ui/uninit_vec.stderr index 520bfb26b62e..77fc689f0763 100644 --- a/tests/ui/uninit_vec.stderr +++ b/tests/ui/uninit_vec.stderr @@ -7,8 +7,8 @@ LL | unsafe { LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ | - = note: `-D clippy::uninit-vec` implied by `-D warnings` = help: initialize the buffer or wrap the content in `MaybeUninit` + = note: `-D clippy::uninit-vec` implied by `-D warnings` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values --> $DIR/uninit_vec.rs:18:5 diff --git a/tests/ui/unit_hash.stderr b/tests/ui/unit_hash.stderr index 050fa55a12be..089d1212dd17 100644 --- a/tests/ui/unit_hash.stderr +++ b/tests/ui/unit_hash.stderr @@ -4,8 +4,8 @@ error: this call to `hash` on the unit type will do nothing LL | Foo::Empty => ().hash(&mut state), | ^^^^^^^^^^^^^^^^^^^ help: remove the call to `hash` or consider using: `0_u8.hash(&mut state)` | - = note: `-D clippy::unit-hash` implied by `-D warnings` = note: the implementation of `Hash` for `()` is a no-op + = note: `-D clippy::unit-hash` implied by `-D warnings` error: this call to `hash` on the unit type will do nothing --> $DIR/unit_hash.rs:24:5 diff --git a/tests/ui/unit_return_expecting_ord.stderr b/tests/ui/unit_return_expecting_ord.stderr index e63d58746090..1d9564ce225e 100644 --- a/tests/ui/unit_return_expecting_ord.stderr +++ b/tests/ui/unit_return_expecting_ord.stderr @@ -4,12 +4,12 @@ error: this closure returns the unit type which also implements Ord LL | structs.sort_by_key(|s| { | ^^^ | - = note: `-D clippy::unit-return-expecting-ord` implied by `-D warnings` help: probably caused by this trailing semicolon --> $DIR/unit_return_expecting_ord.rs:19:24 | LL | double(s.field); | ^ + = note: `-D clippy::unit-return-expecting-ord` implied by `-D warnings` error: this closure returns the unit type which also implements PartialOrd --> $DIR/unit_return_expecting_ord.rs:22:30 diff --git a/tests/ui/unnecessary_self_imports.stderr b/tests/ui/unnecessary_self_imports.stderr index 83a5618c983d..db805eb3680b 100644 --- a/tests/ui/unnecessary_self_imports.stderr +++ b/tests/ui/unnecessary_self_imports.stderr @@ -6,8 +6,8 @@ LL | use std::fs::{self as alias}; | | | help: consider omitting `::{self}`: `fs as alias;` | - = note: `-D clippy::unnecessary-self-imports` implied by `-D warnings` = note: this will slightly change semantics; any non-module items at the same path will also be imported + = note: `-D clippy::unnecessary-self-imports` implied by `-D warnings` error: import ending with `::{self}` --> $DIR/unnecessary_self_imports.rs:8:1 diff --git a/tests/ui/unnecessary_to_owned.stderr b/tests/ui/unnecessary_to_owned.stderr index 7deb90b06f3b..02bf45a33fbe 100644 --- a/tests/ui/unnecessary_to_owned.stderr +++ b/tests/ui/unnecessary_to_owned.stderr @@ -4,12 +4,12 @@ error: redundant clone LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); | ^^^^^^^^^^^ help: remove this | - = note: `-D clippy::redundant-clone` implied by `-D warnings` note: this value is dropped without further use --> $DIR/unnecessary_to_owned.rs:151:20 | LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::redundant-clone` implied by `-D warnings` error: redundant clone --> $DIR/unnecessary_to_owned.rs:152:40 diff --git a/tests/ui/unneeded_field_pattern.stderr b/tests/ui/unneeded_field_pattern.stderr index b8d3c2945322..6f7c31545696 100644 --- a/tests/ui/unneeded_field_pattern.stderr +++ b/tests/ui/unneeded_field_pattern.stderr @@ -4,8 +4,8 @@ error: you matched a field with a wildcard pattern, consider using `..` instead LL | Foo { a: _, b: 0, .. } => {}, | ^^^^ | - = note: `-D clippy::unneeded-field-pattern` implied by `-D warnings` = help: try with `Foo { b: 0, .. }` + = note: `-D clippy::unneeded-field-pattern` implied by `-D warnings` error: all the struct fields are matched to a wildcard pattern, consider using `..` --> $DIR/unneeded_field_pattern.rs:16:9 diff --git a/tests/ui/unsafe_derive_deserialize.stderr b/tests/ui/unsafe_derive_deserialize.stderr index 18c4276c6ddf..8aaae2d7fff4 100644 --- a/tests/ui/unsafe_derive_deserialize.stderr +++ b/tests/ui/unsafe_derive_deserialize.stderr @@ -4,8 +4,8 @@ error: you are deriving `serde::Deserialize` on a type that has methods using `u LL | #[derive(Deserialize)] | ^^^^^^^^^^^ | - = note: `-D clippy::unsafe-derive-deserialize` implied by `-D warnings` = help: consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html + = note: `-D clippy::unsafe-derive-deserialize` implied by `-D warnings` = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` diff --git a/tests/ui/unused_async.stderr b/tests/ui/unused_async.stderr index 8b8ad065a4ca..cff3eccbd32b 100644 --- a/tests/ui/unused_async.stderr +++ b/tests/ui/unused_async.stderr @@ -6,8 +6,8 @@ LL | | 4 LL | | } | |_^ | - = note: `-D clippy::unused-async` implied by `-D warnings` = help: consider removing the `async` from this function + = note: `-D clippy::unused-async` implied by `-D warnings` error: unused `async` for function with no await statements --> $DIR/unused_async.rs:17:5 diff --git a/tests/ui/unused_io_amount.stderr b/tests/ui/unused_io_amount.stderr index e5bdd993aa1a..7ba7e09c0f0d 100644 --- a/tests/ui/unused_io_amount.stderr +++ b/tests/ui/unused_io_amount.stderr @@ -4,8 +4,8 @@ error: written amount is not handled LL | s.write(b"test")?; | ^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::unused-io-amount` implied by `-D warnings` = help: use `Write::write_all` instead, or handle partial writes + = note: `-D clippy::unused-io-amount` implied by `-D warnings` error: read amount is not handled --> $DIR/unused_io_amount.rs:11:5 diff --git a/tests/ui/unused_peekable.stderr b/tests/ui/unused_peekable.stderr index d557f54179db..54788f2fa2f4 100644 --- a/tests/ui/unused_peekable.stderr +++ b/tests/ui/unused_peekable.stderr @@ -4,8 +4,8 @@ error: `peek` never called on `Peekable` iterator LL | let peekable = std::iter::empty::().peekable(); | ^^^^^^^^ | - = note: `-D clippy::unused-peekable` implied by `-D warnings` = help: consider removing the call to `peekable` + = note: `-D clippy::unused-peekable` implied by `-D warnings` error: `peek` never called on `Peekable` iterator --> $DIR/unused_peekable.rs:18:9 diff --git a/tests/ui/unused_self.stderr b/tests/ui/unused_self.stderr index 0534b40eabb7..23186122a9af 100644 --- a/tests/ui/unused_self.stderr +++ b/tests/ui/unused_self.stderr @@ -4,8 +4,8 @@ error: unused `self` argument LL | fn unused_self_move(self) {} | ^^^^ | - = note: `-D clippy::unused-self` implied by `-D warnings` = help: consider refactoring to a associated function + = note: `-D clippy::unused-self` implied by `-D warnings` error: unused `self` argument --> $DIR/unused_self.rs:12:28 diff --git a/tests/ui/unwrap.stderr b/tests/ui/unwrap.stderr index 78422757819d..e88d580f7bd2 100644 --- a/tests/ui/unwrap.stderr +++ b/tests/ui/unwrap.stderr @@ -4,8 +4,8 @@ error: used `unwrap()` on `an Option` value LL | let _ = opt.unwrap(); | ^^^^^^^^^^^^ | - = note: `-D clippy::unwrap-used` implied by `-D warnings` = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: `-D clippy::unwrap-used` implied by `-D warnings` error: used `unwrap()` on `a Result` value --> $DIR/unwrap.rs:10:13 diff --git a/tests/ui/unwrap_expect_used.stderr b/tests/ui/unwrap_expect_used.stderr index 1a19459b2c17..211d2be18342 100644 --- a/tests/ui/unwrap_expect_used.stderr +++ b/tests/ui/unwrap_expect_used.stderr @@ -4,8 +4,8 @@ error: used `unwrap()` on `an Option` value LL | Some(3).unwrap(); | ^^^^^^^^^^^^^^^^ | - = note: `-D clippy::unwrap-used` implied by `-D warnings` = help: if this value is `None`, it will panic + = note: `-D clippy::unwrap-used` implied by `-D warnings` error: used `expect()` on `an Option` value --> $DIR/unwrap_expect_used.rs:24:5 @@ -13,8 +13,8 @@ error: used `expect()` on `an Option` value LL | Some(3).expect("Hello world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::expect-used` implied by `-D warnings` = help: if this value is `None`, it will panic + = note: `-D clippy::expect-used` implied by `-D warnings` error: used `unwrap()` on `a Result` value --> $DIR/unwrap_expect_used.rs:31:5 diff --git a/tests/ui/unwrap_in_result.stderr b/tests/ui/unwrap_in_result.stderr index 56bc2f2d1c00..40e6bfe087e7 100644 --- a/tests/ui/unwrap_in_result.stderr +++ b/tests/ui/unwrap_in_result.stderr @@ -10,13 +10,13 @@ LL | | } LL | | } | |_____^ | - = note: `-D clippy::unwrap-in-result` implied by `-D warnings` = help: unwrap and expect should not be used in a function that returns result or option note: potential non-recoverable error(s) --> $DIR/unwrap_in_result.rs:24:17 | LL | let i = i_str.parse::().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::unwrap-in-result` implied by `-D warnings` error: used unwrap or expect in a function that returns result or option --> $DIR/unwrap_in_result.rs:32:5 diff --git a/tests/ui/useless_conversion_try.stderr b/tests/ui/useless_conversion_try.stderr index 12e74d614717..9aef9dda6f68 100644 --- a/tests/ui/useless_conversion_try.stderr +++ b/tests/ui/useless_conversion_try.stderr @@ -4,12 +4,12 @@ error: useless conversion to the same type: `T` LL | let _ = T::try_from(val).unwrap(); | ^^^^^^^^^^^^^^^^ | + = help: consider removing `T::try_from()` note: the lint level is defined here --> $DIR/useless_conversion_try.rs:1:9 | LL | #![deny(clippy::useless_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: consider removing `T::try_from()` error: useless conversion to the same type: `T` --> $DIR/useless_conversion_try.rs:5:5 diff --git a/tests/ui/vec_resize_to_zero.stderr b/tests/ui/vec_resize_to_zero.stderr index 7428cf62d6c4..8851e9f38be4 100644 --- a/tests/ui/vec_resize_to_zero.stderr +++ b/tests/ui/vec_resize_to_zero.stderr @@ -6,8 +6,8 @@ LL | v.resize(0, 5); | | | help: ...or you can empty the vector with: `clear()` | - = note: `-D clippy::vec-resize-to-zero` implied by `-D warnings` = help: the arguments may be inverted... + = note: `-D clippy::vec-resize-to-zero` implied by `-D warnings` error: aborting due to previous error diff --git a/tests/ui/verbose_file_reads.stderr b/tests/ui/verbose_file_reads.stderr index 550b6ab679f1..44266c7c01f3 100644 --- a/tests/ui/verbose_file_reads.stderr +++ b/tests/ui/verbose_file_reads.stderr @@ -4,8 +4,8 @@ error: use of `File::read_to_end` LL | f.read_to_end(&mut buffer)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::verbose-file-reads` implied by `-D warnings` = help: consider using `fs::read` instead + = note: `-D clippy::verbose-file-reads` implied by `-D warnings` error: use of `File::read_to_string` --> $DIR/verbose_file_reads.rs:26:5 diff --git a/tests/ui/vtable_address_comparisons.stderr b/tests/ui/vtable_address_comparisons.stderr index 2f1be61e5df7..14748f583f0c 100644 --- a/tests/ui/vtable_address_comparisons.stderr +++ b/tests/ui/vtable_address_comparisons.stderr @@ -4,8 +4,8 @@ error: comparing trait object pointers compares a non-unique vtable address LL | let _ = a == b; | ^^^^^^ | - = note: `-D clippy::vtable-address-comparisons` implied by `-D warnings` = help: consider extracting and comparing data pointers only + = note: `-D clippy::vtable-address-comparisons` implied by `-D warnings` error: comparing trait object pointers compares a non-unique vtable address --> $DIR/vtable_address_comparisons.rs:15:13 diff --git a/tests/ui/wild_in_or_pats.stderr b/tests/ui/wild_in_or_pats.stderr index 45b87aa0f20b..bd5860f45ca6 100644 --- a/tests/ui/wild_in_or_pats.stderr +++ b/tests/ui/wild_in_or_pats.stderr @@ -4,8 +4,8 @@ error: wildcard pattern covers any other pattern as it will match anyway LL | "bar" | _ => { | ^^^^^^^^^ | - = note: `-D clippy::wildcard-in-or-patterns` implied by `-D warnings` = help: consider handling `_` separately + = note: `-D clippy::wildcard-in-or-patterns` implied by `-D warnings` error: wildcard pattern covers any other pattern as it will match anyway --> $DIR/wild_in_or_pats.rs:16:9 diff --git a/tests/ui/wrong_self_convention.stderr b/tests/ui/wrong_self_convention.stderr index 2e7ee51d7e11..d002e55c5708 100644 --- a/tests/ui/wrong_self_convention.stderr +++ b/tests/ui/wrong_self_convention.stderr @@ -4,8 +4,8 @@ error: methods called `from_*` usually take no `self` LL | fn from_i32(self) {} | ^^^^ | - = note: `-D clippy::wrong-self-convention` implied by `-D warnings` = help: consider choosing a less ambiguous name + = note: `-D clippy::wrong-self-convention` implied by `-D warnings` error: methods called `from_*` usually take no `self` --> $DIR/wrong_self_convention.rs:22:21 diff --git a/tests/ui/wrong_self_convention2.stderr b/tests/ui/wrong_self_convention2.stderr index 5bdc47f91f65..8de10e7be69c 100644 --- a/tests/ui/wrong_self_convention2.stderr +++ b/tests/ui/wrong_self_convention2.stderr @@ -4,8 +4,8 @@ error: methods called `from_*` usually take no `self` LL | pub fn from_be_self(self) -> Self { | ^^^^ | - = note: `-D clippy::wrong-self-convention` implied by `-D warnings` = help: consider choosing a less ambiguous name + = note: `-D clippy::wrong-self-convention` implied by `-D warnings` error: methods called `from_*` usually take no `self` --> $DIR/wrong_self_convention2.rs:63:25 diff --git a/tests/ui/wrong_self_conventions_mut.stderr b/tests/ui/wrong_self_conventions_mut.stderr index 8665d8dc9a9d..3d009083cee3 100644 --- a/tests/ui/wrong_self_conventions_mut.stderr +++ b/tests/ui/wrong_self_conventions_mut.stderr @@ -4,8 +4,8 @@ error: methods with the following characteristics: (`to_*` and `self` type is no LL | pub fn to_many(&mut self) -> Option<&mut [T]> { | ^^^^^^^^^ | - = note: `-D clippy::wrong-self-convention` implied by `-D warnings` = help: consider choosing a less ambiguous name + = note: `-D clippy::wrong-self-convention` implied by `-D warnings` error: methods with the following characteristics: (`to_*` and `*_mut`) usually take `self` by mutable reference --> $DIR/wrong_self_conventions_mut.rs:22:28 diff --git a/tests/ui/zero_div_zero.stderr b/tests/ui/zero_div_zero.stderr index 86563542e060..2793d1606445 100644 --- a/tests/ui/zero_div_zero.stderr +++ b/tests/ui/zero_div_zero.stderr @@ -4,8 +4,8 @@ error: constant division of `0.0` with `0.0` will always result in NaN LL | let nan = 0.0 / 0.0; | ^^^^^^^^^ | - = note: `-D clippy::zero-divided-by-zero` implied by `-D warnings` = help: consider using `f64::NAN` if you would like a constant representing NaN + = note: `-D clippy::zero-divided-by-zero` implied by `-D warnings` error: constant division of `0.0` with `0.0` will always result in NaN --> $DIR/zero_div_zero.rs:5:19 diff --git a/tests/ui/zero_sized_btreemap_values.stderr b/tests/ui/zero_sized_btreemap_values.stderr index d924f33797d2..c6ba6fa76f05 100644 --- a/tests/ui/zero_sized_btreemap_values.stderr +++ b/tests/ui/zero_sized_btreemap_values.stderr @@ -4,8 +4,8 @@ error: map with zero-sized value type LL | const CONST_NOT_OK: Option> = None; | ^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::zero-sized-map-values` implied by `-D warnings` = help: consider using a set instead + = note: `-D clippy::zero-sized-map-values` implied by `-D warnings` error: map with zero-sized value type --> $DIR/zero_sized_btreemap_values.rs:8:30 diff --git a/tests/ui/zero_sized_hashmap_values.stderr b/tests/ui/zero_sized_hashmap_values.stderr index 79770bf90d70..75bdeb42ec0d 100644 --- a/tests/ui/zero_sized_hashmap_values.stderr +++ b/tests/ui/zero_sized_hashmap_values.stderr @@ -4,8 +4,8 @@ error: map with zero-sized value type LL | const CONST_NOT_OK: Option> = None; | ^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::zero-sized-map-values` implied by `-D warnings` = help: consider using a set instead + = note: `-D clippy::zero-sized-map-values` implied by `-D warnings` error: map with zero-sized value type --> $DIR/zero_sized_hashmap_values.rs:8:30 From 6e909b7f086c87ea0dbb2f8275c72414c3088839 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 4 Oct 2022 09:43:34 +0000 Subject: [PATCH 0631/1222] It's not about types or consts, but the lack of regions --- clippy_lints/src/dereference.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index e54d71fc8e41..f0d5ed6f594b 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1238,7 +1238,7 @@ fn ty_auto_deref_stability<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, precedenc ty::Adt(..) if ty.has_placeholders() || ty.has_opaque_types() => { Position::ReborrowStable(precedence).into() }, - ty::Adt(_, substs) if substs.has_param_types_or_consts() => { + ty::Adt(_, substs) if substs.has_non_region_param() => { TyPosition::new_deref_stable_for_result(precedence, ty) }, ty::Bool From 14f58d4538b00ad83dd371696ed8db572af7aa16 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Tue, 4 Oct 2022 21:39:43 +0300 Subject: [PATCH 0632/1222] Remove `mir::CastKind::Misc` --- clippy_utils/src/qualify_min_const_fn.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index f7ce71917726..7af27ebb9883 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -129,7 +129,12 @@ fn check_rvalue<'tcx>( | Rvalue::Use(operand) | Rvalue::Cast( CastKind::PointerFromExposedAddress - | CastKind::Misc + | CastKind::IntToInt + | CastKind::FloatToInt + | CastKind::IntToFloat + | CastKind::FloatToFloat + | CastKind::FnPtrToPtr + | CastKind::PtrToPtr | CastKind::Pointer(PointerCast::MutToConstPointer | PointerCast::ArrayToPointer), operand, _, From 36b2c4ce80595c8cef8266d29aef03b182541895 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Fri, 9 Sep 2022 15:08:06 -0500 Subject: [PATCH 0633/1222] Introduce TypeErrCtxt TypeErrCtxt optionally has a TypeckResults so that InferCtxt doesn't need to. --- clippy_lints/src/future_not_send.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index eb2eefe0d5a1..406c842a6d05 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -7,7 +7,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{EarlyBinder, Opaque, PredicateKind::Trait}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; -use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt; +use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt; use rustc_trait_selection::traits::{self, FulfillmentError}; declare_clippy_lint! { @@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { |db| { cx.tcx.infer_ctxt().enter(|infcx| { for FulfillmentError { obligation, .. } in send_errors { - infcx.maybe_note_obligation_cause_for_async_await(db, &obligation); + infcx.err_ctxt().maybe_note_obligation_cause_for_async_await(db, &obligation); if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() { db.note(&format!( "`{}` doesn't implement `{}`", From ef3272e2c4b12c40ae764780942158c861aa50ec Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Mon, 19 Sep 2022 22:03:59 -0500 Subject: [PATCH 0634/1222] Change InferCtxtBuilder from enter to build --- clippy_lints/src/dereference.rs | 14 +++--- clippy_lints/src/escape.rs | 5 +- clippy_lints/src/future_not_send.rs | 29 ++++++----- clippy_lints/src/loops/mut_range_bound.rs | 19 ++++---- .../src/methods/unnecessary_to_owned.rs | 4 +- clippy_lints/src/needless_pass_by_value.rs | 6 +-- .../src/operators/assign_op_pattern.rs | 38 +++++++-------- clippy_utils/src/sugg.rs | 7 ++- clippy_utils/src/ty.rs | 48 +++++++++---------- clippy_utils/src/usage.rs | 19 ++++---- 10 files changed, 87 insertions(+), 102 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 3cd8f236e7a5..02a16f765b73 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -831,11 +831,10 @@ fn walk_parents<'tcx>( // Trait methods taking `self` arg_ty } && impl_ty.is_ref() - && cx.tcx.infer_ctxt().enter(|infcx| - infcx - .type_implements_trait(trait_id, impl_ty, subs, cx.param_env) - .must_apply_modulo_regions() - ) + && let infcx = cx.tcx.infer_ctxt().build() + && infcx + .type_implements_trait(trait_id, impl_ty, subs, cx.param_env) + .must_apply_modulo_regions() { return Some(Position::MethodReceiverRefImpl) } @@ -1119,9 +1118,8 @@ fn needless_borrow_impl_arg_position<'tcx>( let predicate = EarlyBinder(predicate).subst(cx.tcx, &substs_with_referent_ty); let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate); - cx.tcx - .infer_ctxt() - .enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation)) + let infcx = cx.tcx.infer_ctxt().build(); + infcx.predicate_must_hold_modulo_regions(&obligation) }) }; diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 2e608fe527fd..eb0455ae404c 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -106,9 +106,8 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { }; let fn_def_id = cx.tcx.hir().local_def_id(hir_id); - cx.tcx.infer_ctxt().enter(|infcx| { - ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body); - }); + let infcx = cx.tcx.infer_ctxt().build(); + ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body); for node in v.set { span_lint_hir( diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 406c842a6d05..0519f9ac2468 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -77,10 +77,9 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { if is_future { let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap(); let span = decl.output.span(); - let send_errors = cx.tcx.infer_ctxt().enter(|infcx| { - let cause = traits::ObligationCause::misc(span, hir_id); - traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait) - }); + let infcx = cx.tcx.infer_ctxt().build(); + let cause = traits::ObligationCause::misc(span, hir_id); + let send_errors = traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait); if !send_errors.is_empty() { span_lint_and_then( cx, @@ -88,18 +87,18 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { span, "future cannot be sent between threads safely", |db| { - cx.tcx.infer_ctxt().enter(|infcx| { - for FulfillmentError { obligation, .. } in send_errors { - infcx.err_ctxt().maybe_note_obligation_cause_for_async_await(db, &obligation); - if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() { - db.note(&format!( - "`{}` doesn't implement `{}`", - trait_pred.self_ty(), - trait_pred.trait_ref.print_only_trait_path(), - )); - } + for FulfillmentError { obligation, .. } in send_errors { + infcx + .err_ctxt() + .maybe_note_obligation_cause_for_async_await(db, &obligation); + if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() { + db.note(&format!( + "`{}` doesn't implement `{}`", + trait_pred.self_ty(), + trait_pred.trait_ref.print_only_trait_path(), + )); } - }); + } }, ); } diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index 0ee42b61c9a5..db73ab55b37c 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -65,16 +65,15 @@ fn check_for_mutation<'tcx>( span_low: None, span_high: None, }; - cx.tcx.infer_ctxt().enter(|infcx| { - ExprUseVisitor::new( - &mut delegate, - &infcx, - body.hir_id.owner.def_id, - cx.param_env, - cx.typeck_results(), - ) - .walk_expr(body); - }); + let infcx = cx.tcx.infer_ctxt().build(); + ExprUseVisitor::new( + &mut delegate, + &infcx, + body.hir_id.owner.def_id, + cx.param_env, + cx.typeck_results(), + ) + .walk_expr(body); delegate.mutation_span() } diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 9ab0d6141146..6017941452c0 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -420,9 +420,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< if trait_predicates.any(|predicate| { let predicate = EarlyBinder(predicate).subst(cx.tcx, new_subst); let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate); - !cx.tcx - .infer_ctxt() - .enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation)) + !cx.tcx.infer_ctxt().build().predicate_must_hold_modulo_regions(&obligation) }) { return false; } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 178c973981b1..7f881e27dd27 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -138,10 +138,8 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { .. } = { let mut ctx = MovedVariablesCtxt::default(); - cx.tcx.infer_ctxt().enter(|infcx| { - euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()) - .consume_body(body); - }); + let infcx = cx.tcx.infer_ctxt().build(); + euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body); ctx }; diff --git a/clippy_lints/src/operators/assign_op_pattern.rs b/clippy_lints/src/operators/assign_op_pattern.rs index 26bca7c306a8..c7e964cf23e2 100644 --- a/clippy_lints/src/operators/assign_op_pattern.rs +++ b/clippy_lints/src/operators/assign_op_pattern.rs @@ -123,16 +123,15 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet } let mut s = S(hir::HirIdSet::default()); - cx.tcx.infer_ctxt().enter(|infcx| { - let mut v = ExprUseVisitor::new( - &mut s, - &infcx, - cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()), - cx.param_env, - cx.typeck_results(), - ); - v.consume_expr(e); - }); + let infcx = cx.tcx.infer_ctxt().build(); + let mut v = ExprUseVisitor::new( + &mut s, + &infcx, + cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()), + cx.param_env, + cx.typeck_results(), + ); + v.consume_expr(e); s.0 } @@ -156,15 +155,14 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet } let mut s = S(hir::HirIdSet::default()); - cx.tcx.infer_ctxt().enter(|infcx| { - let mut v = ExprUseVisitor::new( - &mut s, - &infcx, - cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()), - cx.param_env, - cx.typeck_results(), - ); - v.consume_expr(e); - }); + let infcx = cx.tcx.infer_ctxt().build(); + let mut v = ExprUseVisitor::new( + &mut s, + &infcx, + cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()), + cx.param_env, + cx.typeck_results(), + ); + v.consume_expr(e); s.0 } diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index ef836e84829b..3c5dd92b9cd6 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -821,10 +821,9 @@ pub fn deref_closure_args<'tcx>(cx: &LateContext<'_>, closure: &'tcx hir::Expr<' }; let fn_def_id = cx.tcx.hir().local_def_id(closure.hir_id); - cx.tcx.infer_ctxt().enter(|infcx| { - ExprUseVisitor::new(&mut visitor, &infcx, fn_def_id, cx.param_env, cx.typeck_results()) - .consume_body(closure_body); - }); + let infcx = cx.tcx.infer_ctxt().build(); + ExprUseVisitor::new(&mut visitor, &infcx, fn_def_id, cx.param_env, cx.typeck_results()) + .consume_body(closure_body); if !visitor.suggestion_start.is_empty() { return Some(DerefClosure { diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 934470bd135b..a15daec7c3ce 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -172,11 +172,10 @@ pub fn implements_trait_with_env<'tcx>( return false; } let ty_params = tcx.mk_substs(ty_params.iter()); - tcx.infer_ctxt().enter(|infcx| { - infcx - .type_implements_trait(trait_id, ty, ty_params, param_env) - .must_apply_modulo_regions() - }) + let infcx = tcx.infer_ctxt().build(); + infcx + .type_implements_trait(trait_id, ty, ty_params, param_env) + .must_apply_modulo_regions() } /// Checks whether this type implements `Drop`. @@ -242,27 +241,26 @@ fn is_normalizable_helper<'tcx>( } // prevent recursive loops, false-negative is better than endless loop leading to stack overflow cache.insert(ty, false); - let result = cx.tcx.infer_ctxt().enter(|infcx| { - let cause = rustc_middle::traits::ObligationCause::dummy(); - if infcx.at(&cause, param_env).normalize(ty).is_ok() { - match ty.kind() { - ty::Adt(def, substs) => def.variants().iter().all(|variant| { - variant - .fields - .iter() - .all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache)) - }), - _ => ty.walk().all(|generic_arg| match generic_arg.unpack() { - GenericArgKind::Type(inner_ty) if inner_ty != ty => { - is_normalizable_helper(cx, param_env, inner_ty, cache) - }, - _ => true, // if inner_ty == ty, we've already checked it - }), - } - } else { - false + let infcx = cx.tcx.infer_ctxt().build(); + let cause = rustc_middle::traits::ObligationCause::dummy(); + let result = if infcx.at(&cause, param_env).normalize(ty).is_ok() { + match ty.kind() { + ty::Adt(def, substs) => def.variants().iter().all(|variant| { + variant + .fields + .iter() + .all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache)) + }), + _ => ty.walk().all(|generic_arg| match generic_arg.unpack() { + GenericArgKind::Type(inner_ty) if inner_ty != ty => { + is_normalizable_helper(cx, param_env, inner_ty, cache) + }, + _ => true, // if inner_ty == ty, we've already checked it + }), } - }); + } else { + false + }; cache.insert(ty, result); result } diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index b5ec3fef3e0b..e32bae6ed1fd 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -18,16 +18,15 @@ pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) -> used_mutably: HirIdSet::default(), skip: false, }; - cx.tcx.infer_ctxt().enter(|infcx| { - ExprUseVisitor::new( - &mut delegate, - &infcx, - expr.hir_id.owner.def_id, - cx.param_env, - cx.typeck_results(), - ) - .walk_expr(expr); - }); + let infcx = cx.tcx.infer_ctxt().build(); + ExprUseVisitor::new( + &mut delegate, + &infcx, + expr.hir_id.owner.def_id, + cx.param_env, + cx.typeck_results(), + ) + .walk_expr(expr); if delegate.skip { return None; From 7f46fa2105191d6baca9e3f2c9a966bc1d668a1d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 21 Sep 2022 13:05:20 +0200 Subject: [PATCH 0635/1222] make const_err a hard error --- clippy_lints/src/indexing_slicing.rs | 1 - tests/ui/crashes/ice-9463.rs | 2 +- tests/ui/crashes/ice-9463.stderr | 2 +- tests/ui/indexing_slicing_index.rs | 2 +- tests/ui/indexing_slicing_index.stderr | 8 +++++++- tests/ui/out_of_bounds_indexing/issue-3102.rs | 2 +- tests/ui/out_of_bounds_indexing/simple.rs | 2 +- 7 files changed, 12 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index 4a375752e1d3..af40a5a8187e 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -19,7 +19,6 @@ declare_clippy_lint! { /// /// ### Example /// ```rust,no_run - /// # #![allow(const_err)] /// let x = [1, 2, 3, 4]; /// /// x[9]; diff --git a/tests/ui/crashes/ice-9463.rs b/tests/ui/crashes/ice-9463.rs index 41ef930d3233..9564e77c24b1 100644 --- a/tests/ui/crashes/ice-9463.rs +++ b/tests/ui/crashes/ice-9463.rs @@ -1,4 +1,4 @@ -#![deny(arithmetic_overflow, const_err)] +#![deny(arithmetic_overflow)] fn main() { let _x = -1_i32 >> -1; let _y = 1u32 >> 10000000000000u32; diff --git a/tests/ui/crashes/ice-9463.stderr b/tests/ui/crashes/ice-9463.stderr index b0ce306d6838..2b425e85a27b 100644 --- a/tests/ui/crashes/ice-9463.stderr +++ b/tests/ui/crashes/ice-9463.stderr @@ -7,7 +7,7 @@ LL | let _x = -1_i32 >> -1; note: the lint level is defined here --> $DIR/ice-9463.rs:1:9 | -LL | #![deny(arithmetic_overflow, const_err)] +LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ error: this arithmetic operation will overflow diff --git a/tests/ui/indexing_slicing_index.rs b/tests/ui/indexing_slicing_index.rs index 7ebf6ee993cb..4476e0eb9220 100644 --- a/tests/ui/indexing_slicing_index.rs +++ b/tests/ui/indexing_slicing_index.rs @@ -3,7 +3,7 @@ // We also check the out_of_bounds_indexing lint here, because it lints similar things and // we want to avoid false positives. #![warn(clippy::out_of_bounds_indexing)] -#![allow(const_err, unconditional_panic, clippy::no_effect, clippy::unnecessary_operation)] +#![allow(unconditional_panic, clippy::no_effect, clippy::unnecessary_operation)] const ARR: [i32; 2] = [1, 2]; const REF: &i32 = &ARR[idx()]; // Ok, should not produce stderr. diff --git a/tests/ui/indexing_slicing_index.stderr b/tests/ui/indexing_slicing_index.stderr index a8d8b38163d0..da5bc38b3b66 100644 --- a/tests/ui/indexing_slicing_index.stderr +++ b/tests/ui/indexing_slicing_index.stderr @@ -59,6 +59,12 @@ LL | v[M]; | = help: consider using `.get(n)` or `.get_mut(n)` instead -error: aborting due to 8 previous errors +error[E0080]: evaluation of constant value failed + --> $DIR/indexing_slicing_index.rs:10:24 + | +LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. + | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 + +error: aborting due to 9 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.rs b/tests/ui/out_of_bounds_indexing/issue-3102.rs index f20a0ede1137..edd2123d48a5 100644 --- a/tests/ui/out_of_bounds_indexing/issue-3102.rs +++ b/tests/ui/out_of_bounds_indexing/issue-3102.rs @@ -1,5 +1,5 @@ #![warn(clippy::out_of_bounds_indexing)] -#![allow(clippy::no_effect, const_err)] +#![allow(clippy::no_effect)] fn main() { let x = [1, 2, 3, 4]; diff --git a/tests/ui/out_of_bounds_indexing/simple.rs b/tests/ui/out_of_bounds_indexing/simple.rs index 590e578d758e..4c541c23f5f4 100644 --- a/tests/ui/out_of_bounds_indexing/simple.rs +++ b/tests/ui/out_of_bounds_indexing/simple.rs @@ -1,5 +1,5 @@ #![warn(clippy::out_of_bounds_indexing)] -#![allow(clippy::no_effect, clippy::unnecessary_operation, const_err)] +#![allow(clippy::no_effect, clippy::unnecessary_operation)] fn main() { let x = [1, 2, 3, 4]; From 8d59ebc525e0cdab02be865502442d3afc068c2d Mon Sep 17 00:00:00 2001 From: Urgau Date: Sat, 24 Sep 2022 17:22:04 +0200 Subject: [PATCH 0636/1222] Stabilize half_open_range_patterns --- tests/ui/match_overlapping_arm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/match_overlapping_arm.rs b/tests/ui/match_overlapping_arm.rs index 2f85e6357135..22b04b208f87 100644 --- a/tests/ui/match_overlapping_arm.rs +++ b/tests/ui/match_overlapping_arm.rs @@ -1,5 +1,5 @@ #![feature(exclusive_range_pattern)] -#![feature(half_open_range_patterns)] + #![warn(clippy::match_overlapping_arm)] #![allow(clippy::redundant_pattern_matching)] #![allow(clippy::if_same_then_else, clippy::equatable_if_let)] From 27d074e3ba560b426f9ef6fc9c8822fa40ef9358 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 9 Oct 2022 07:09:57 +0000 Subject: [PATCH 0637/1222] ImplItemKind::TyAlias => ImplItemKind::Type --- clippy_lints/src/missing_inline.rs | 2 +- clippy_lints/src/types/mod.rs | 2 +- clippy_utils/src/check_proc_macro.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 9d5764ac0926..ef6d1da552bf 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -148,7 +148,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { let desc = match impl_item.kind { hir::ImplItemKind::Fn(..) => "a method", - hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) => return, + hir::ImplItemKind::Const(..) | hir::ImplItemKind::Type(_) => return, }; let assoc_item = cx.tcx.associated_item(impl_item.def_id); diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index aca55817c525..33eee2a03784 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -372,7 +372,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { // Methods are covered by check_fn. // Type aliases are ignored because oftentimes it's impossible to // make type alias declaration in trait simpler, see #1013 - ImplItemKind::Fn(..) | ImplItemKind::TyAlias(..) => (), + ImplItemKind::Fn(..) | ImplItemKind::Type(..) => (), } } diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index 7a8d4e8068ed..c6bf98b7b8bb 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -220,7 +220,7 @@ fn trait_item_search_pat(item: &TraitItem<'_>) -> (Pat, Pat) { fn impl_item_search_pat(item: &ImplItem<'_>) -> (Pat, Pat) { let (start_pat, end_pat) = match &item.kind { ImplItemKind::Const(..) => (Pat::Str("const"), Pat::Str(";")), - ImplItemKind::TyAlias(..) => (Pat::Str("type"), Pat::Str(";")), + ImplItemKind::Type(..) => (Pat::Str("type"), Pat::Str(";")), ImplItemKind::Fn(sig, ..) => (fn_header_search_pat(sig.header), Pat::Str("")), }; if item.vis_span.is_empty() { From 20dab7208d4e2dff0e2d6f24a3e1a2ef1fb759eb Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 25 Aug 2022 14:03:13 +0400 Subject: [PATCH 0638/1222] Fix clippy tests that trigger `for_loop_over_fallibles` lint --- tests/ui/for_loop_unfixable.rs | 1 + tests/ui/for_loop_unfixable.stderr | 2 +- tests/ui/for_loops_over_fallibles.rs | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/ui/for_loop_unfixable.rs b/tests/ui/for_loop_unfixable.rs index efcaffce24ea..203656fa4d6c 100644 --- a/tests/ui/for_loop_unfixable.rs +++ b/tests/ui/for_loop_unfixable.rs @@ -8,6 +8,7 @@ clippy::for_kv_map )] #[allow(clippy::linkedlist, clippy::unnecessary_mut_passed, clippy::similar_names)] +#[allow(for_loop_over_fallibles)] fn main() { let vec = vec![1, 2, 3, 4]; diff --git a/tests/ui/for_loop_unfixable.stderr b/tests/ui/for_loop_unfixable.stderr index f769b4bdc941..50a86eaa68f7 100644 --- a/tests/ui/for_loop_unfixable.stderr +++ b/tests/ui/for_loop_unfixable.stderr @@ -1,5 +1,5 @@ error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want - --> $DIR/for_loop_unfixable.rs:14:15 + --> $DIR/for_loop_unfixable.rs:15:15 | LL | for _v in vec.iter().next() {} | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/for_loops_over_fallibles.rs b/tests/ui/for_loops_over_fallibles.rs index 4b2a9297d084..54661ff94f24 100644 --- a/tests/ui/for_loops_over_fallibles.rs +++ b/tests/ui/for_loops_over_fallibles.rs @@ -1,5 +1,6 @@ #![warn(clippy::for_loops_over_fallibles)] #![allow(clippy::uninlined_format_args)] +#![allow(for_loop_over_fallibles)] fn for_loops_over_fallibles() { let option = Some(1); From 129f2482978a43c9b7cf8e90c1d86613cf0bfa07 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 7 Oct 2022 15:59:39 +0000 Subject: [PATCH 0639/1222] fixup lint name --- tests/ui/for_loop_unfixable.rs | 2 +- tests/ui/for_loops_over_fallibles.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/for_loop_unfixable.rs b/tests/ui/for_loop_unfixable.rs index 203656fa4d6c..55fb3788a8b1 100644 --- a/tests/ui/for_loop_unfixable.rs +++ b/tests/ui/for_loop_unfixable.rs @@ -8,7 +8,7 @@ clippy::for_kv_map )] #[allow(clippy::linkedlist, clippy::unnecessary_mut_passed, clippy::similar_names)] -#[allow(for_loop_over_fallibles)] +#[allow(for_loops_over_fallibles)] fn main() { let vec = vec![1, 2, 3, 4]; diff --git a/tests/ui/for_loops_over_fallibles.rs b/tests/ui/for_loops_over_fallibles.rs index 54661ff94f24..75cdcc02353f 100644 --- a/tests/ui/for_loops_over_fallibles.rs +++ b/tests/ui/for_loops_over_fallibles.rs @@ -1,6 +1,6 @@ #![warn(clippy::for_loops_over_fallibles)] #![allow(clippy::uninlined_format_args)] -#![allow(for_loop_over_fallibles)] +#![allow(for_loops_over_fallibles)] fn for_loops_over_fallibles() { let option = Some(1); From 3a35879ac8a4bfa13df87a3d21024f26ef699ccb Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 7 Oct 2022 17:08:29 +0000 Subject: [PATCH 0640/1222] deprecate `clippy::for_loops_over_fallibles` --- clippy_lints/src/lib.register_all.rs | 1 - clippy_lints/src/lib.register_lints.rs | 1 - clippy_lints/src/lib.register_suspicious.rs | 1 - .../src/loops/for_loops_over_fallibles.rs | 65 ------------- clippy_lints/src/loops/iter_next_loop.rs | 5 +- clippy_lints/src/loops/mod.rs | 57 +---------- clippy_lints/src/renamed_lints.rs | 5 +- src/docs.rs | 1 - src/docs/for_loops_over_fallibles.txt | 32 ------- tests/ui/for_loops_over_fallibles.rs | 74 --------------- tests/ui/for_loops_over_fallibles.stderr | 95 ------------------- tests/ui/manual_map_option.fixed | 2 +- tests/ui/manual_map_option.rs | 2 +- tests/ui/rename.fixed | 7 +- tests/ui/rename.rs | 3 +- tests/ui/rename.stderr | 34 ++++--- 16 files changed, 34 insertions(+), 351 deletions(-) delete mode 100644 clippy_lints/src/loops/for_loops_over_fallibles.rs delete mode 100644 src/docs/for_loops_over_fallibles.txt delete mode 100644 tests/ui/for_loops_over_fallibles.rs delete mode 100644 tests/ui/for_loops_over_fallibles.stderr diff --git a/clippy_lints/src/lib.register_all.rs b/clippy_lints/src/lib.register_all.rs index 5d26e4b33601..fe1f0b56646c 100644 --- a/clippy_lints/src/lib.register_all.rs +++ b/clippy_lints/src/lib.register_all.rs @@ -109,7 +109,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![ LintId::of(loops::EMPTY_LOOP), LintId::of(loops::EXPLICIT_COUNTER_LOOP), LintId::of(loops::FOR_KV_MAP), - LintId::of(loops::FOR_LOOPS_OVER_FALLIBLES), LintId::of(loops::ITER_NEXT_LOOP), LintId::of(loops::MANUAL_FIND), LintId::of(loops::MANUAL_FLATTEN), diff --git a/clippy_lints/src/lib.register_lints.rs b/clippy_lints/src/lib.register_lints.rs index 05d927dbea79..306cb6a61c94 100644 --- a/clippy_lints/src/lib.register_lints.rs +++ b/clippy_lints/src/lib.register_lints.rs @@ -227,7 +227,6 @@ store.register_lints(&[ loops::EXPLICIT_INTO_ITER_LOOP, loops::EXPLICIT_ITER_LOOP, loops::FOR_KV_MAP, - loops::FOR_LOOPS_OVER_FALLIBLES, loops::ITER_NEXT_LOOP, loops::MANUAL_FIND, loops::MANUAL_FLATTEN, diff --git a/clippy_lints/src/lib.register_suspicious.rs b/clippy_lints/src/lib.register_suspicious.rs index 6125d0f7a862..d6d95c95c85d 100644 --- a/clippy_lints/src/lib.register_suspicious.rs +++ b/clippy_lints/src/lib.register_suspicious.rs @@ -21,7 +21,6 @@ store.register_group(true, "clippy::suspicious", Some("clippy_suspicious"), vec! LintId::of(formatting::SUSPICIOUS_ELSE_FORMATTING), LintId::of(formatting::SUSPICIOUS_UNARY_OP_FORMATTING), LintId::of(loops::EMPTY_LOOP), - LintId::of(loops::FOR_LOOPS_OVER_FALLIBLES), LintId::of(loops::MUT_RANGE_BOUND), LintId::of(methods::NO_EFFECT_REPLACE), LintId::of(methods::SUSPICIOUS_MAP), diff --git a/clippy_lints/src/loops/for_loops_over_fallibles.rs b/clippy_lints/src/loops/for_loops_over_fallibles.rs deleted file mode 100644 index 77de90fd7b94..000000000000 --- a/clippy_lints/src/loops/for_loops_over_fallibles.rs +++ /dev/null @@ -1,65 +0,0 @@ -use super::FOR_LOOPS_OVER_FALLIBLES; -use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::source::snippet; -use clippy_utils::ty::is_type_diagnostic_item; -use rustc_hir::{Expr, Pat}; -use rustc_lint::LateContext; -use rustc_span::symbol::sym; - -/// Checks for `for` loops over `Option`s and `Result`s. -pub(super) fn check(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, method_name: Option<&str>) { - let ty = cx.typeck_results().expr_ty(arg); - if is_type_diagnostic_item(cx, ty, sym::Option) { - let help_string = if let Some(method_name) = method_name { - format!( - "consider replacing `for {0} in {1}.{method_name}()` with `if let Some({0}) = {1}`", - snippet(cx, pat.span, "_"), - snippet(cx, arg.span, "_") - ) - } else { - format!( - "consider replacing `for {0} in {1}` with `if let Some({0}) = {1}`", - snippet(cx, pat.span, "_"), - snippet(cx, arg.span, "_") - ) - }; - span_lint_and_help( - cx, - FOR_LOOPS_OVER_FALLIBLES, - arg.span, - &format!( - "for loop over `{0}`, which is an `Option`. This is more readably written as an \ - `if let` statement", - snippet(cx, arg.span, "_") - ), - None, - &help_string, - ); - } else if is_type_diagnostic_item(cx, ty, sym::Result) { - let help_string = if let Some(method_name) = method_name { - format!( - "consider replacing `for {0} in {1}.{method_name}()` with `if let Ok({0}) = {1}`", - snippet(cx, pat.span, "_"), - snippet(cx, arg.span, "_") - ) - } else { - format!( - "consider replacing `for {0} in {1}` with `if let Ok({0}) = {1}`", - snippet(cx, pat.span, "_"), - snippet(cx, arg.span, "_") - ) - }; - span_lint_and_help( - cx, - FOR_LOOPS_OVER_FALLIBLES, - arg.span, - &format!( - "for loop over `{0}`, which is a `Result`. This is more readably written as an \ - `if let` statement", - snippet(cx, arg.span, "_") - ), - None, - &help_string, - ); - } -} diff --git a/clippy_lints/src/loops/iter_next_loop.rs b/clippy_lints/src/loops/iter_next_loop.rs index e640c62ebdac..b8a263817d29 100644 --- a/clippy_lints/src/loops/iter_next_loop.rs +++ b/clippy_lints/src/loops/iter_next_loop.rs @@ -5,7 +5,7 @@ use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_span::sym; -pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>) -> bool { +pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>) { if is_trait_method(cx, arg, sym::Iterator) { span_lint( cx, @@ -14,8 +14,5 @@ pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>) -> bool { "you are iterating over `Iterator::next()` which is an Option; this will compile but is \ probably not what you want", ); - true - } else { - false } } diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index c0a0444485e3..bcf278d9c833 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -3,7 +3,6 @@ mod explicit_counter_loop; mod explicit_into_iter_loop; mod explicit_iter_loop; mod for_kv_map; -mod for_loops_over_fallibles; mod iter_next_loop; mod manual_find; mod manual_flatten; @@ -173,49 +172,6 @@ declare_clippy_lint! { "for-looping over `_.next()` which is probably not intended" } -declare_clippy_lint! { - /// ### What it does - /// Checks for `for` loops over `Option` or `Result` values. - /// - /// ### Why is this bad? - /// Readability. This is more clearly expressed as an `if - /// let`. - /// - /// ### Example - /// ```rust - /// # let opt = Some(1); - /// # let res: Result = Ok(1); - /// for x in opt { - /// // .. - /// } - /// - /// for x in &res { - /// // .. - /// } - /// - /// for x in res.iter() { - /// // .. - /// } - /// ``` - /// - /// Use instead: - /// ```rust - /// # let opt = Some(1); - /// # let res: Result = Ok(1); - /// if let Some(x) = opt { - /// // .. - /// } - /// - /// if let Ok(x) = res { - /// // .. - /// } - /// ``` - #[clippy::version = "1.45.0"] - pub FOR_LOOPS_OVER_FALLIBLES, - suspicious, - "for-looping over an `Option` or a `Result`, which is more clearly expressed as an `if let`" -} - declare_clippy_lint! { /// ### What it does /// Detects `loop + match` combinations that are easier @@ -648,7 +604,6 @@ declare_lint_pass!(Loops => [ EXPLICIT_ITER_LOOP, EXPLICIT_INTO_ITER_LOOP, ITER_NEXT_LOOP, - FOR_LOOPS_OVER_FALLIBLES, WHILE_LET_LOOP, NEEDLESS_COLLECT, EXPLICIT_COUNTER_LOOP, @@ -739,30 +694,22 @@ fn check_for_loop<'tcx>( manual_find::check(cx, pat, arg, body, span, expr); } -fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) { - let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used - +fn check_for_loop_arg(cx: &LateContext<'_>, _: &Pat<'_>, arg: &Expr<'_>) { if let ExprKind::MethodCall(method, self_arg, [], _) = arg.kind { let method_name = method.ident.as_str(); // check for looping over x.iter() or x.iter_mut(), could use &x or &mut x match method_name { "iter" | "iter_mut" => { explicit_iter_loop::check(cx, self_arg, arg, method_name); - for_loops_over_fallibles::check(cx, pat, self_arg, Some(method_name)); }, "into_iter" => { explicit_iter_loop::check(cx, self_arg, arg, method_name); explicit_into_iter_loop::check(cx, self_arg, arg); - for_loops_over_fallibles::check(cx, pat, self_arg, Some(method_name)); }, "next" => { - next_loop_linted = iter_next_loop::check(cx, arg); + iter_next_loop::check(cx, arg); }, _ => {}, } } - - if !next_loop_linted { - for_loops_over_fallibles::check(cx, pat, arg, None); - } } diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index d320eea1c377..76d6ad0b23e6 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -11,8 +11,8 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::disallowed_method", "clippy::disallowed_methods"), ("clippy::disallowed_type", "clippy::disallowed_types"), ("clippy::eval_order_dependence", "clippy::mixed_read_write_in_expression"), - ("clippy::for_loop_over_option", "clippy::for_loops_over_fallibles"), - ("clippy::for_loop_over_result", "clippy::for_loops_over_fallibles"), + ("clippy::for_loop_over_option", "for_loops_over_fallibles"), + ("clippy::for_loop_over_result", "for_loops_over_fallibles"), ("clippy::identity_conversion", "clippy::useless_conversion"), ("clippy::if_let_some_result", "clippy::match_result_ok"), ("clippy::logic_bug", "clippy::overly_complex_bool_expr"), @@ -31,6 +31,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::to_string_in_display", "clippy::recursive_format_impl"), ("clippy::zero_width_space", "clippy::invisible_characters"), ("clippy::drop_bounds", "drop_bounds"), + ("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"), ("clippy::into_iter_on_array", "array_into_iter"), ("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"), ("clippy::invalid_ref", "invalid_value"), diff --git a/src/docs.rs b/src/docs.rs index 3bf488ab4779..bd27bc7938f8 100644 --- a/src/docs.rs +++ b/src/docs.rs @@ -170,7 +170,6 @@ docs! { "fn_to_numeric_cast_any", "fn_to_numeric_cast_with_truncation", "for_kv_map", - "for_loops_over_fallibles", "forget_copy", "forget_non_drop", "forget_ref", diff --git a/src/docs/for_loops_over_fallibles.txt b/src/docs/for_loops_over_fallibles.txt deleted file mode 100644 index c5a7508e45d4..000000000000 --- a/src/docs/for_loops_over_fallibles.txt +++ /dev/null @@ -1,32 +0,0 @@ -### What it does -Checks for `for` loops over `Option` or `Result` values. - -### Why is this bad? -Readability. This is more clearly expressed as an `if -let`. - -### Example -``` -for x in opt { - // .. -} - -for x in &res { - // .. -} - -for x in res.iter() { - // .. -} -``` - -Use instead: -``` -if let Some(x) = opt { - // .. -} - -if let Ok(x) = res { - // .. -} -``` \ No newline at end of file diff --git a/tests/ui/for_loops_over_fallibles.rs b/tests/ui/for_loops_over_fallibles.rs deleted file mode 100644 index 75cdcc02353f..000000000000 --- a/tests/ui/for_loops_over_fallibles.rs +++ /dev/null @@ -1,74 +0,0 @@ -#![warn(clippy::for_loops_over_fallibles)] -#![allow(clippy::uninlined_format_args)] -#![allow(for_loops_over_fallibles)] - -fn for_loops_over_fallibles() { - let option = Some(1); - let mut result = option.ok_or("x not found"); - let v = vec![0, 1, 2]; - - // check over an `Option` - for x in option { - println!("{}", x); - } - - // check over an `Option` - for x in option.iter() { - println!("{}", x); - } - - // check over a `Result` - for x in result { - println!("{}", x); - } - - // check over a `Result` - for x in result.iter_mut() { - println!("{}", x); - } - - // check over a `Result` - for x in result.into_iter() { - println!("{}", x); - } - - for x in option.ok_or("x not found") { - println!("{}", x); - } - - // make sure LOOP_OVER_NEXT lint takes clippy::precedence when next() is the last call - // in the chain - for x in v.iter().next() { - println!("{}", x); - } - - // make sure we lint when next() is not the last call in the chain - for x in v.iter().next().and(Some(0)) { - println!("{}", x); - } - - for x in v.iter().next().ok_or("x not found") { - println!("{}", x); - } - - // check for false positives - - // for loop false positive - for x in v { - println!("{}", x); - } - - // while let false positive for Option - while let Some(x) = option { - println!("{}", x); - break; - } - - // while let false positive for Result - while let Ok(x) = result { - println!("{}", x); - break; - } -} - -fn main() {} diff --git a/tests/ui/for_loops_over_fallibles.stderr b/tests/ui/for_loops_over_fallibles.stderr deleted file mode 100644 index f09adccabd1a..000000000000 --- a/tests/ui/for_loops_over_fallibles.stderr +++ /dev/null @@ -1,95 +0,0 @@ -error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement - --> $DIR/for_loops_over_fallibles.rs:10:14 - | -LL | for x in option { - | ^^^^^^ - | - = help: consider replacing `for x in option` with `if let Some(x) = option` - = note: `-D clippy::for-loops-over-fallibles` implied by `-D warnings` - -error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement - --> $DIR/for_loops_over_fallibles.rs:15:14 - | -LL | for x in option.iter() { - | ^^^^^^ - | - = help: consider replacing `for x in option.iter()` with `if let Some(x) = option` - -error: for loop over `result`, which is a `Result`. This is more readably written as an `if let` statement - --> $DIR/for_loops_over_fallibles.rs:20:14 - | -LL | for x in result { - | ^^^^^^ - | - = help: consider replacing `for x in result` with `if let Ok(x) = result` - -error: for loop over `result`, which is a `Result`. This is more readably written as an `if let` statement - --> $DIR/for_loops_over_fallibles.rs:25:14 - | -LL | for x in result.iter_mut() { - | ^^^^^^ - | - = help: consider replacing `for x in result.iter_mut()` with `if let Ok(x) = result` - -error: for loop over `result`, which is a `Result`. This is more readably written as an `if let` statement - --> $DIR/for_loops_over_fallibles.rs:30:14 - | -LL | for x in result.into_iter() { - | ^^^^^^ - | - = help: consider replacing `for x in result.into_iter()` with `if let Ok(x) = result` - -error: for loop over `option.ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement - --> $DIR/for_loops_over_fallibles.rs:34:14 - | -LL | for x in option.ok_or("x not found") { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider replacing `for x in option.ok_or("x not found")` with `if let Ok(x) = option.ok_or("x not found")` - -error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want - --> $DIR/for_loops_over_fallibles.rs:40:14 - | -LL | for x in v.iter().next() { - | ^^^^^^^^^^^^^^^ - | - = note: `#[deny(clippy::iter_next_loop)]` on by default - -error: for loop over `v.iter().next().and(Some(0))`, which is an `Option`. This is more readably written as an `if let` statement - --> $DIR/for_loops_over_fallibles.rs:45:14 - | -LL | for x in v.iter().next().and(Some(0)) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider replacing `for x in v.iter().next().and(Some(0))` with `if let Some(x) = v.iter().next().and(Some(0))` - -error: for loop over `v.iter().next().ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement - --> $DIR/for_loops_over_fallibles.rs:49:14 - | -LL | for x in v.iter().next().ok_or("x not found") { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider replacing `for x in v.iter().next().ok_or("x not found")` with `if let Ok(x) = v.iter().next().ok_or("x not found")` - -error: this loop never actually loops - --> $DIR/for_loops_over_fallibles.rs:61:5 - | -LL | / while let Some(x) = option { -LL | | println!("{}", x); -LL | | break; -LL | | } - | |_____^ - | - = note: `#[deny(clippy::never_loop)]` on by default - -error: this loop never actually loops - --> $DIR/for_loops_over_fallibles.rs:67:5 - | -LL | / while let Ok(x) = result { -LL | | println!("{}", x); -LL | | break; -LL | | } - | |_____^ - -error: aborting due to 11 previous errors - diff --git a/tests/ui/manual_map_option.fixed b/tests/ui/manual_map_option.fixed index a59da4ae10bc..e12ea7ec1450 100644 --- a/tests/ui/manual_map_option.fixed +++ b/tests/ui/manual_map_option.fixed @@ -7,7 +7,7 @@ clippy::unit_arg, clippy::match_ref_pats, clippy::redundant_pattern_matching, - clippy::for_loops_over_fallibles, + for_loops_over_fallibles, dead_code )] diff --git a/tests/ui/manual_map_option.rs b/tests/ui/manual_map_option.rs index 0bdbefa51e8b..325a6db06c4e 100644 --- a/tests/ui/manual_map_option.rs +++ b/tests/ui/manual_map_option.rs @@ -7,7 +7,7 @@ clippy::unit_arg, clippy::match_ref_pats, clippy::redundant_pattern_matching, - clippy::for_loops_over_fallibles, + for_loops_over_fallibles, dead_code )] diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index a6e7bdba77c6..8beae8dee085 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -12,7 +12,7 @@ #![allow(clippy::disallowed_methods)] #![allow(clippy::disallowed_types)] #![allow(clippy::mixed_read_write_in_expression)] -#![allow(clippy::for_loops_over_fallibles)] +#![allow(for_loops_over_fallibles)] #![allow(clippy::useless_conversion)] #![allow(clippy::match_result_ok)] #![allow(clippy::overly_complex_bool_expr)] @@ -45,8 +45,8 @@ #![warn(clippy::disallowed_methods)] #![warn(clippy::disallowed_types)] #![warn(clippy::mixed_read_write_in_expression)] -#![warn(clippy::for_loops_over_fallibles)] -#![warn(clippy::for_loops_over_fallibles)] +#![warn(for_loops_over_fallibles)] +#![warn(for_loops_over_fallibles)] #![warn(clippy::useless_conversion)] #![warn(clippy::match_result_ok)] #![warn(clippy::overly_complex_bool_expr)] @@ -65,6 +65,7 @@ #![warn(clippy::recursive_format_impl)] #![warn(clippy::invisible_characters)] #![warn(drop_bounds)] +#![warn(for_loops_over_fallibles)] #![warn(array_into_iter)] #![warn(invalid_atomic_ordering)] #![warn(invalid_value)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index e8f57597d02b..9e665047baae 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -12,7 +12,7 @@ #![allow(clippy::disallowed_methods)] #![allow(clippy::disallowed_types)] #![allow(clippy::mixed_read_write_in_expression)] -#![allow(clippy::for_loops_over_fallibles)] +#![allow(for_loops_over_fallibles)] #![allow(clippy::useless_conversion)] #![allow(clippy::match_result_ok)] #![allow(clippy::overly_complex_bool_expr)] @@ -65,6 +65,7 @@ #![warn(clippy::to_string_in_display)] #![warn(clippy::zero_width_space)] #![warn(clippy::drop_bounds)] +#![warn(clippy::for_loops_over_fallibles)] #![warn(clippy::into_iter_on_array)] #![warn(clippy::invalid_atomic_ordering)] #![warn(clippy::invalid_ref)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 31865a7f66d6..63eb565185f0 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -54,17 +54,17 @@ error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_r LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` -error: lint `clippy::for_loop_over_option` has been renamed to `clippy::for_loops_over_fallibles` +error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` --> $DIR/rename.rs:48:9 | LL | #![warn(clippy::for_loop_over_option)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::for_loops_over_fallibles` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` -error: lint `clippy::for_loop_over_result` has been renamed to `clippy::for_loops_over_fallibles` +error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` --> $DIR/rename.rs:49:9 | LL | #![warn(clippy::for_loop_over_result)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::for_loops_over_fallibles` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` --> $DIR/rename.rs:50:9 @@ -174,59 +174,65 @@ error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` -error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` +error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` --> $DIR/rename.rs:68:9 | +LL | #![warn(clippy::for_loops_over_fallibles)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` + +error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` + --> $DIR/rename.rs:69:9 + | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 38 previous errors +error: aborting due to 39 previous errors From 01c2141a4b2fef8d34873bb45d36be8e96eb16fa Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 10 Oct 2022 02:05:24 +0000 Subject: [PATCH 0641/1222] Rename AssocItemKind::TyAlias to AssocItemKind::Type --- clippy_utils/src/ast_utils.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 493991f30e87..0133997560ea 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -438,14 +438,14 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r)) }, ( - TyAlias(box ast::TyAlias { + Type(box ast::TyAlias { defaultness: ld, generics: lg, bounds: lb, ty: lt, .. }), - TyAlias(box ast::TyAlias { + Type(box ast::TyAlias { defaultness: rd, generics: rg, bounds: rb, From cc794350df5e0b6b4a1970379bed6ffef267b1a9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 10 Oct 2022 20:45:04 +0200 Subject: [PATCH 0642/1222] Fix unclosed HTML tag in clippy doc --- clippy_utils/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 42374fdd7baf..e7e3625c078a 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -2064,9 +2064,9 @@ pub fn fn_def_id(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { } } -/// Returns Option where String is a textual representation of the type encapsulated in the -/// slice iff the given expression is a slice of primitives (as defined in the -/// `is_recursively_primitive_type` function) and None otherwise. +/// Returns `Option` where String is a textual representation of the type encapsulated in +/// the slice iff the given expression is a slice of primitives (as defined in the +/// `is_recursively_primitive_type` function) and `None` otherwise. pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { let expr_type = cx.typeck_results().expr_ty_adjusted(expr); let expr_kind = expr_type.kind(); From 4a5195faf7ec19596281c044b62b433e807804c2 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 14 Sep 2022 23:42:25 +0000 Subject: [PATCH 0643/1222] Remove CastCheckResult since it's unused --- clippy_lints/src/transmute/utils.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/transmute/utils.rs b/clippy_lints/src/transmute/utils.rs index b567d92230bb..102f7541c8ce 100644 --- a/clippy_lints/src/transmute/utils.rs +++ b/clippy_lints/src/transmute/utils.rs @@ -1,15 +1,16 @@ use rustc_hir::Expr; -use rustc_hir_analysis::check::{ - cast::{self, CastCheckResult}, - FnCtxt, Inherited, -}; +use rustc_hir_analysis::check::{cast, FnCtxt, Inherited}; use rustc_lint::LateContext; use rustc_middle::ty::{cast::CastKind, Ty}; use rustc_span::DUMMY_SP; // check if the component types of the transmuted collection and the result have different ABI, // size or alignment -pub(super) fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<'tcx>) -> bool { +pub(super) fn is_layout_incompatible<'tcx>( + cx: &LateContext<'tcx>, + from: Ty<'tcx>, + to: Ty<'tcx>, +) -> bool { if let Ok(from) = cx.tcx.try_normalize_erasing_regions(cx.param_env, from) && let Ok(to) = cx.tcx.try_normalize_erasing_regions(cx.param_env, to) && let Ok(from_layout) = cx.tcx.layout_of(cx.param_env.and(from)) @@ -32,7 +33,9 @@ pub(super) fn can_be_expressed_as_pointer_cast<'tcx>( from_ty: Ty<'tcx>, to_ty: Ty<'tcx>, ) -> bool { - use CastKind::{AddrPtrCast, ArrayPtrCast, FnPtrAddrCast, FnPtrPtrCast, PtrAddrCast, PtrPtrCast}; + use CastKind::{ + AddrPtrCast, ArrayPtrCast, FnPtrAddrCast, FnPtrPtrCast, PtrAddrCast, PtrPtrCast, + }; matches!( check_cast(cx, e, from_ty, to_ty), Some(PtrPtrCast | PtrAddrCast | AddrPtrCast | ArrayPtrCast | FnPtrPtrCast | FnPtrAddrCast) @@ -43,7 +46,12 @@ pub(super) fn can_be_expressed_as_pointer_cast<'tcx>( /// the cast. In certain cases, including some invalid casts from array references /// to pointers, this may cause additional errors to be emitted and/or ICE error /// messages. This function will panic if that occurs. -fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> Option { +fn check_cast<'tcx>( + cx: &LateContext<'tcx>, + e: &'tcx Expr<'_>, + from_ty: Ty<'tcx>, + to_ty: Ty<'tcx>, +) -> Option { let hir_id = e.hir_id; let local_def_id = hir_id.owner.def_id; @@ -51,12 +59,9 @@ fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx> let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, hir_id); // If we already have errors, we can't be sure we can pointer cast. - assert!( - !fn_ctxt.errors_reported_since_creation(), - "Newly created FnCtxt contained errors" - ); + assert!(!fn_ctxt.errors_reported_since_creation(), "Newly created FnCtxt contained errors"); - if let CastCheckResult::Deferred(check) = cast::check_cast( + if let Ok(check) = cast::CastCheck::new( &fn_ctxt, e, from_ty, to_ty, // We won't show any error to the user, so we don't care what the span is here. DUMMY_SP, DUMMY_SP, From f2af8d4871e606588e3eef13d8d5b842f1c0b920 Mon Sep 17 00:00:00 2001 From: mejrs <> Date: Wed, 19 Oct 2022 00:08:20 +0200 Subject: [PATCH 0644/1222] Implement -Ztrack-diagnostics --- clippy_lints/src/doc.rs | 1 + src/driver.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 36dc7e3396b8..9e2facf0f63b 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -691,6 +691,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { false, None, false, + false, ); let handler = Handler::with_emitter(false, None, Box::new(emitter)); let sess = ParseSess::with_span_handler(handler, sm); diff --git a/src/driver.rs b/src/driver.rs index b12208ac62a8..ae54b2078a65 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -179,6 +179,7 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { false, None, false, + false, )); let handler = rustc_errors::Handler::with_emitter(true, None, emitter); From 05562e564a4d05310263d18273e0dd2e6211bbe4 Mon Sep 17 00:00:00 2001 From: yukang Date: Wed, 19 Oct 2022 11:46:26 +0800 Subject: [PATCH 0645/1222] Add testcase for next_point, fix more trivial issues in find_width_of_character_at_span --- clippy_utils/src/sugg.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 3c5dd92b9cd6..3347342e412b 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -769,8 +769,7 @@ impl DiagnosticExt for rustc_errors::Diagnostic { fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str, applicability: Applicability) { let mut remove_span = item; - let hi = cx.sess().source_map().next_point(remove_span).hi(); - let fmpos = cx.sess().source_map().lookup_byte_offset(hi); + let fmpos = cx.sess().source_map().lookup_byte_offset(remove_span.hi()); if let Some(ref src) = fmpos.sf.src { let non_whitespace_offset = src[fmpos.pos.to_usize()..].find(|c| c != ' ' && c != '\t' && c != '\n'); From 43f70285645bbb5f4a09b6513998e3205f2114e1 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 19 Oct 2022 11:34:00 -0700 Subject: [PATCH 0646/1222] Fixup a few tests needing asm support --- tests/ui/entry.fixed | 1 + tests/ui/entry.rs | 1 + tests/ui/entry.stderr | 20 ++++++++-------- tests/ui/missing_doc.rs | 1 + tests/ui/missing_doc.stderr | 48 ++++++++++++++++++------------------- 5 files changed, 37 insertions(+), 34 deletions(-) diff --git a/tests/ui/entry.fixed b/tests/ui/entry.fixed index e43635abcd11..79c29c04e059 100644 --- a/tests/ui/entry.fixed +++ b/tests/ui/entry.fixed @@ -1,3 +1,4 @@ +// needs-asm-support // run-rustfix #![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)] diff --git a/tests/ui/entry.rs b/tests/ui/entry.rs index d999b3b7dc80..2d7985457d8b 100644 --- a/tests/ui/entry.rs +++ b/tests/ui/entry.rs @@ -1,3 +1,4 @@ +// needs-asm-support // run-rustfix #![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)] diff --git a/tests/ui/entry.stderr b/tests/ui/entry.stderr index 2ef9966525ce..2c4c49d2522c 100644 --- a/tests/ui/entry.stderr +++ b/tests/ui/entry.stderr @@ -1,5 +1,5 @@ error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:24:5 + --> $DIR/entry.rs:25:5 | LL | / if !m.contains_key(&k) { LL | | m.insert(k, v); @@ -9,7 +9,7 @@ LL | | } = note: `-D clippy::map-entry` implied by `-D warnings` error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:29:5 + --> $DIR/entry.rs:30:5 | LL | / if !m.contains_key(&k) { LL | | if true { @@ -32,7 +32,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:38:5 + --> $DIR/entry.rs:39:5 | LL | / if !m.contains_key(&k) { LL | | if true { @@ -55,7 +55,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:47:5 + --> $DIR/entry.rs:48:5 | LL | / if !m.contains_key(&k) { LL | | if true { @@ -79,7 +79,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:57:5 + --> $DIR/entry.rs:58:5 | LL | / if !m.contains_key(&k) { LL | | foo(); @@ -96,7 +96,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:63:5 + --> $DIR/entry.rs:64:5 | LL | / if !m.contains_key(&k) { LL | | match 0 { @@ -122,7 +122,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:75:5 + --> $DIR/entry.rs:76:5 | LL | / if !m.contains_key(&k) { LL | | match 0 { @@ -146,7 +146,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:85:5 + --> $DIR/entry.rs:86:5 | LL | / if !m.contains_key(&k) { LL | | foo(); @@ -187,7 +187,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:119:5 + --> $DIR/entry.rs:120:5 | LL | / if !m.contains_key(&m!(k)) { LL | | m.insert(m!(k), m!(v)); @@ -195,7 +195,7 @@ LL | | } | |_____^ help: try this: `m.entry(m!(k)).or_insert_with(|| m!(v));` error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:151:5 + --> $DIR/entry.rs:152:5 | LL | / if !m.contains_key(&k) { LL | | let x = (String::new(), String::new()); diff --git a/tests/ui/missing_doc.rs b/tests/ui/missing_doc.rs index 29cc026a8fd3..590ad63c90be 100644 --- a/tests/ui/missing_doc.rs +++ b/tests/ui/missing_doc.rs @@ -1,3 +1,4 @@ +// needs-asm-support // aux-build: proc_macro_with_span.rs #![warn(clippy::missing_docs_in_private_items)] diff --git a/tests/ui/missing_doc.stderr b/tests/ui/missing_doc.stderr index 6c8e66f46437..d3bef28bf64c 100644 --- a/tests/ui/missing_doc.stderr +++ b/tests/ui/missing_doc.stderr @@ -1,5 +1,5 @@ error: missing documentation for a type alias - --> $DIR/missing_doc.rs:15:1 + --> $DIR/missing_doc.rs:16:1 | LL | type Typedef = String; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -7,37 +7,37 @@ LL | type Typedef = String; = note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` error: missing documentation for a type alias - --> $DIR/missing_doc.rs:16:1 + --> $DIR/missing_doc.rs:17:1 | LL | pub type PubTypedef = String; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a module - --> $DIR/missing_doc.rs:18:1 + --> $DIR/missing_doc.rs:19:1 | LL | mod module_no_dox {} | ^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a module - --> $DIR/missing_doc.rs:19:1 + --> $DIR/missing_doc.rs:20:1 | LL | pub mod pub_module_no_dox {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing_doc.rs:23:1 + --> $DIR/missing_doc.rs:24:1 | LL | pub fn foo2() {} | ^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing_doc.rs:24:1 + --> $DIR/missing_doc.rs:25:1 | LL | fn foo3() {} | ^^^^^^^^^^^^ error: missing documentation for an enum - --> $DIR/missing_doc.rs:38:1 + --> $DIR/missing_doc.rs:39:1 | LL | / enum Baz { LL | | BazA { a: isize, b: isize }, @@ -46,31 +46,31 @@ LL | | } | |_^ error: missing documentation for a variant - --> $DIR/missing_doc.rs:39:5 + --> $DIR/missing_doc.rs:40:5 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a struct field - --> $DIR/missing_doc.rs:39:12 + --> $DIR/missing_doc.rs:40:12 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^ error: missing documentation for a struct field - --> $DIR/missing_doc.rs:39:22 + --> $DIR/missing_doc.rs:40:22 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^ error: missing documentation for a variant - --> $DIR/missing_doc.rs:40:5 + --> $DIR/missing_doc.rs:41:5 | LL | BarB, | ^^^^ error: missing documentation for an enum - --> $DIR/missing_doc.rs:43:1 + --> $DIR/missing_doc.rs:44:1 | LL | / pub enum PubBaz { LL | | PubBazA { a: isize }, @@ -78,43 +78,43 @@ LL | | } | |_^ error: missing documentation for a variant - --> $DIR/missing_doc.rs:44:5 + --> $DIR/missing_doc.rs:45:5 | LL | PubBazA { a: isize }, | ^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a struct field - --> $DIR/missing_doc.rs:44:15 + --> $DIR/missing_doc.rs:45:15 | LL | PubBazA { a: isize }, | ^^^^^^^^ error: missing documentation for a constant - --> $DIR/missing_doc.rs:64:1 + --> $DIR/missing_doc.rs:65:1 | LL | const FOO: u32 = 0; | ^^^^^^^^^^^^^^^^^^^ error: missing documentation for a constant - --> $DIR/missing_doc.rs:71:1 + --> $DIR/missing_doc.rs:72:1 | LL | pub const FOO4: u32 = 0; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a static - --> $DIR/missing_doc.rs:73:1 + --> $DIR/missing_doc.rs:74:1 | LL | static BAR: u32 = 0; | ^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a static - --> $DIR/missing_doc.rs:80:1 + --> $DIR/missing_doc.rs:81:1 | LL | pub static BAR4: u32 = 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a module - --> $DIR/missing_doc.rs:82:1 + --> $DIR/missing_doc.rs:83:1 | LL | / mod internal_impl { LL | | /// dox @@ -126,31 +126,31 @@ LL | | } | |_^ error: missing documentation for a function - --> $DIR/missing_doc.rs:85:5 + --> $DIR/missing_doc.rs:86:5 | LL | pub fn undocumented1() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing_doc.rs:86:5 + --> $DIR/missing_doc.rs:87:5 | LL | pub fn undocumented2() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing_doc.rs:87:5 + --> $DIR/missing_doc.rs:88:5 | LL | fn undocumented3() {} | ^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing_doc.rs:92:9 + --> $DIR/missing_doc.rs:93:9 | LL | pub fn also_undocumented1() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> $DIR/missing_doc.rs:93:9 + --> $DIR/missing_doc.rs:94:9 | LL | fn also_undocumented2() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ From 330e3cbf8a8a61095cfd110c29221973b14d9467 Mon Sep 17 00:00:00 2001 From: Kevin Per Date: Tue, 11 Oct 2022 16:17:59 +0000 Subject: [PATCH 0647/1222] Implement assertions and fixes to not emit empty spans without suggestions --- clippy_lints/src/manual_assert.rs | 12 ++--- clippy_lints/src/needless_late_init.rs | 11 +++-- tests/ui/manual_assert.edition2018.stderr | 55 ++++------------------- tests/ui/manual_assert.edition2021.stderr | 55 ++++------------------- 4 files changed, 30 insertions(+), 103 deletions(-) diff --git a/clippy_lints/src/manual_assert.rs b/clippy_lints/src/manual_assert.rs index 825ec84b4a81..b8ed9b9ec18f 100644 --- a/clippy_lints/src/manual_assert.rs +++ b/clippy_lints/src/manual_assert.rs @@ -69,11 +69,13 @@ impl<'tcx> LateLintPass<'tcx> for ManualAssert { "only a `panic!` in `if`-then statement", |diag| { // comments can be noisy, do not show them to the user - diag.tool_only_span_suggestion( - expr.span.shrink_to_lo(), - "add comments back", - comments, - applicability); + if !comments.is_empty() { + diag.tool_only_span_suggestion( + expr.span.shrink_to_lo(), + "add comments back", + comments, + applicability); + } diag.span_suggestion( expr.span, "try instead", diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs index 9d26e5900866..67debe7e08af 100644 --- a/clippy_lints/src/needless_late_init.rs +++ b/clippy_lints/src/needless_late_init.rs @@ -180,10 +180,13 @@ fn assignment_suggestions<'tcx>( let suggestions = assignments .iter() .flat_map(|assignment| { - [ - assignment.span.until(assignment.rhs_span), - assignment.rhs_span.shrink_to_hi().with_hi(assignment.span.hi()), - ] + let mut spans = vec![assignment.span.until(assignment.rhs_span)]; + + if assignment.rhs_span.hi() != assignment.span.hi() { + spans.push(assignment.rhs_span.shrink_to_hi().with_hi(assignment.span.hi())); + } + + spans }) .map(|span| (span, String::new())) .collect::>(); diff --git a/tests/ui/manual_assert.edition2018.stderr b/tests/ui/manual_assert.edition2018.stderr index 7718588fdf6f..237638ee1344 100644 --- a/tests/ui/manual_assert.edition2018.stderr +++ b/tests/ui/manual_assert.edition2018.stderr @@ -4,13 +4,9 @@ error: only a `panic!` in `if`-then statement LL | / if !a.is_empty() { LL | | panic!("qaqaq{:?}", a); LL | | } - | |_____^ + | |_____^ help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);` | = note: `-D clippy::manual-assert` implied by `-D warnings` -help: try instead - | -LL | assert!(a.is_empty(), "qaqaq{:?}", a); - | error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:34:5 @@ -18,12 +14,7 @@ error: only a `panic!` in `if`-then statement LL | / if !a.is_empty() { LL | | panic!("qwqwq"); LL | | } - | |_____^ - | -help: try instead - | -LL | assert!(a.is_empty(), "qwqwq"); - | + | |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");` error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:51:5 @@ -31,12 +22,7 @@ error: only a `panic!` in `if`-then statement LL | / if b.is_empty() { LL | | panic!("panic1"); LL | | } - | |_____^ - | -help: try instead - | -LL | assert!(!b.is_empty(), "panic1"); - | + | |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");` error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:54:5 @@ -44,12 +30,7 @@ error: only a `panic!` in `if`-then statement LL | / if b.is_empty() && a.is_empty() { LL | | panic!("panic2"); LL | | } - | |_____^ - | -help: try instead - | -LL | assert!(!(b.is_empty() && a.is_empty()), "panic2"); - | + | |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");` error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:57:5 @@ -57,12 +38,7 @@ error: only a `panic!` in `if`-then statement LL | / if a.is_empty() && !b.is_empty() { LL | | panic!("panic3"); LL | | } - | |_____^ - | -help: try instead - | -LL | assert!(!(a.is_empty() && !b.is_empty()), "panic3"); - | + | |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");` error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:60:5 @@ -70,12 +46,7 @@ error: only a `panic!` in `if`-then statement LL | / if b.is_empty() || a.is_empty() { LL | | panic!("panic4"); LL | | } - | |_____^ - | -help: try instead - | -LL | assert!(!(b.is_empty() || a.is_empty()), "panic4"); - | + | |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");` error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:63:5 @@ -83,12 +54,7 @@ error: only a `panic!` in `if`-then statement LL | / if a.is_empty() || !b.is_empty() { LL | | panic!("panic5"); LL | | } - | |_____^ - | -help: try instead - | -LL | assert!(!(a.is_empty() || !b.is_empty()), "panic5"); - | + | |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");` error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:66:5 @@ -96,12 +62,7 @@ error: only a `panic!` in `if`-then statement LL | / if a.is_empty() { LL | | panic!("with expansion {}", one!()) LL | | } - | |_____^ - | -help: try instead - | -LL | assert!(!a.is_empty(), "with expansion {}", one!()); - | + | |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());` error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:73:5 diff --git a/tests/ui/manual_assert.edition2021.stderr b/tests/ui/manual_assert.edition2021.stderr index 7718588fdf6f..237638ee1344 100644 --- a/tests/ui/manual_assert.edition2021.stderr +++ b/tests/ui/manual_assert.edition2021.stderr @@ -4,13 +4,9 @@ error: only a `panic!` in `if`-then statement LL | / if !a.is_empty() { LL | | panic!("qaqaq{:?}", a); LL | | } - | |_____^ + | |_____^ help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);` | = note: `-D clippy::manual-assert` implied by `-D warnings` -help: try instead - | -LL | assert!(a.is_empty(), "qaqaq{:?}", a); - | error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:34:5 @@ -18,12 +14,7 @@ error: only a `panic!` in `if`-then statement LL | / if !a.is_empty() { LL | | panic!("qwqwq"); LL | | } - | |_____^ - | -help: try instead - | -LL | assert!(a.is_empty(), "qwqwq"); - | + | |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");` error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:51:5 @@ -31,12 +22,7 @@ error: only a `panic!` in `if`-then statement LL | / if b.is_empty() { LL | | panic!("panic1"); LL | | } - | |_____^ - | -help: try instead - | -LL | assert!(!b.is_empty(), "panic1"); - | + | |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");` error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:54:5 @@ -44,12 +30,7 @@ error: only a `panic!` in `if`-then statement LL | / if b.is_empty() && a.is_empty() { LL | | panic!("panic2"); LL | | } - | |_____^ - | -help: try instead - | -LL | assert!(!(b.is_empty() && a.is_empty()), "panic2"); - | + | |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");` error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:57:5 @@ -57,12 +38,7 @@ error: only a `panic!` in `if`-then statement LL | / if a.is_empty() && !b.is_empty() { LL | | panic!("panic3"); LL | | } - | |_____^ - | -help: try instead - | -LL | assert!(!(a.is_empty() && !b.is_empty()), "panic3"); - | + | |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");` error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:60:5 @@ -70,12 +46,7 @@ error: only a `panic!` in `if`-then statement LL | / if b.is_empty() || a.is_empty() { LL | | panic!("panic4"); LL | | } - | |_____^ - | -help: try instead - | -LL | assert!(!(b.is_empty() || a.is_empty()), "panic4"); - | + | |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");` error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:63:5 @@ -83,12 +54,7 @@ error: only a `panic!` in `if`-then statement LL | / if a.is_empty() || !b.is_empty() { LL | | panic!("panic5"); LL | | } - | |_____^ - | -help: try instead - | -LL | assert!(!(a.is_empty() || !b.is_empty()), "panic5"); - | + | |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");` error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:66:5 @@ -96,12 +62,7 @@ error: only a `panic!` in `if`-then statement LL | / if a.is_empty() { LL | | panic!("with expansion {}", one!()) LL | | } - | |_____^ - | -help: try instead - | -LL | assert!(!a.is_empty(), "with expansion {}", one!()); - | + | |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());` error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:73:5 From 2db6bd71cb2ef0f89b3ce47dcf73656c214d6d9e Mon Sep 17 00:00:00 2001 From: lcnr Date: Thu, 20 Oct 2022 17:51:48 +0200 Subject: [PATCH 0648/1222] rustc_hir_typeck: fix clippy --- clippy_lints/src/escape.rs | 4 ++-- clippy_lints/src/lib.rs | 1 + clippy_lints/src/loops/mut_range_bound.rs | 4 ++-- clippy_lints/src/methods/unnecessary_to_owned.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- clippy_lints/src/operators/assign_op_pattern.rs | 2 +- clippy_lints/src/transmute/utils.rs | 2 +- clippy_utils/src/lib.rs | 2 +- clippy_utils/src/sugg.rs | 7 +++---- clippy_utils/src/usage.rs | 7 +++---- 10 files changed, 17 insertions(+), 18 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index eb0455ae404c..c9a8307eba4f 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_hir; use rustc_hir::intravisit; use rustc_hir::{self, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node, Pat, PatKind}; -use rustc_hir_analysis::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; +use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::FakeReadCause; @@ -178,7 +178,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { fn fake_read( &mut self, - _: &rustc_hir_analysis::expr_use_visitor::PlaceWithHirId<'tcx>, + _: &rustc_hir_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId, ) { diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 2dcefd78763b..89ffca8128a9 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -32,6 +32,7 @@ extern crate rustc_driver; extern crate rustc_errors; extern crate rustc_hir; extern crate rustc_hir_analysis; +extern crate rustc_hir_typeck; extern crate rustc_hir_pretty; extern crate rustc_index; extern crate rustc_infer; diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index db73ab55b37c..91b321c44747 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -4,7 +4,7 @@ use clippy_utils::{get_enclosing_block, higher, path_to_local}; use if_chain::if_chain; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{BindingAnnotation, Expr, ExprKind, HirId, Node, PatKind}; -use rustc_hir_analysis::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; +use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::{mir::FakeReadCause, ty}; @@ -115,7 +115,7 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> { fn fake_read( &mut self, - _: &rustc_hir_analysis::expr_use_visitor::PlaceWithHirId<'tcx>, + _: &rustc_hir_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId, ) { diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 6017941452c0..5cf88bfc8880 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -8,7 +8,7 @@ use clippy_utils::{fn_def_id, get_parent_expr, is_diag_item_method, is_diag_trai use clippy_utils::{meets_msrv, msrvs}; use rustc_errors::Applicability; use rustc_hir::{def_id::DefId, BorrowKind, Expr, ExprKind, ItemKind, LangItem, Node}; -use rustc_hir_analysis::check::{FnCtxt, Inherited}; +use rustc_hir_typeck::{FnCtxt, Inherited}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::mir::Mutability; diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 7f881e27dd27..9c949a28f44d 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -12,7 +12,7 @@ use rustc_hir::{ BindingAnnotation, Body, FnDecl, GenericArg, HirId, Impl, ItemKind, Mutability, Node, PatKind, QPath, TyKind, }; use rustc_hir::{HirIdMap, HirIdSet}; -use rustc_hir_analysis::expr_use_visitor as euv; +use rustc_hir_typeck::expr_use_visitor as euv; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::FakeReadCause; @@ -342,7 +342,7 @@ impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt { fn fake_read( &mut self, - _: &rustc_hir_analysis::expr_use_visitor::PlaceWithHirId<'tcx>, + _: &rustc_hir_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId, ) { diff --git a/clippy_lints/src/operators/assign_op_pattern.rs b/clippy_lints/src/operators/assign_op_pattern.rs index c7e964cf23e2..ee9fd94064c0 100644 --- a/clippy_lints/src/operators/assign_op_pattern.rs +++ b/clippy_lints/src/operators/assign_op_pattern.rs @@ -8,7 +8,7 @@ use core::ops::ControlFlow; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; -use rustc_hir_analysis::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; +use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use rustc_lint::LateContext; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::BorrowKind; diff --git a/clippy_lints/src/transmute/utils.rs b/clippy_lints/src/transmute/utils.rs index 102f7541c8ce..70d166c4854c 100644 --- a/clippy_lints/src/transmute/utils.rs +++ b/clippy_lints/src/transmute/utils.rs @@ -1,5 +1,5 @@ use rustc_hir::Expr; -use rustc_hir_analysis::check::{cast, FnCtxt, Inherited}; +use rustc_hir_typeck::{cast, FnCtxt, Inherited}; use rustc_lint::LateContext; use rustc_middle::ty::{cast::CastKind, Ty}; use rustc_span::DUMMY_SP; diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index e7e3625c078a..7e42fcc6569b 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -24,7 +24,7 @@ extern crate rustc_attr; extern crate rustc_data_structures; extern crate rustc_errors; extern crate rustc_hir; -extern crate rustc_hir_analysis; +extern crate rustc_hir_typeck; extern crate rustc_infer; extern crate rustc_lexer; extern crate rustc_lint; diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 3347342e412b..5089987ef720 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -10,7 +10,7 @@ use rustc_ast_pretty::pprust::token_kind_to_string; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::{Closure, ExprKind, HirId, MutTy, TyKind}; -use rustc_hir_analysis::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; +use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{EarlyContext, LateContext, LintContext}; use rustc_middle::hir::place::ProjectionKind; @@ -1054,11 +1054,10 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> { fn fake_read( &mut self, - _: &rustc_hir_analysis::expr_use_visitor::PlaceWithHirId<'tcx>, + _: &rustc_hir_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId, - ) { - } + ) {} } #[cfg(test)] diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index e32bae6ed1fd..000fb51c0185 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -5,7 +5,7 @@ use rustc_hir as hir; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::HirIdSet; use rustc_hir::{Expr, ExprKind, HirId, Node}; -use rustc_hir_analysis::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; +use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; @@ -75,11 +75,10 @@ impl<'tcx> Delegate<'tcx> for MutVarsDelegate { fn fake_read( &mut self, - _: &rustc_hir_analysis::expr_use_visitor::PlaceWithHirId<'tcx>, + _: &rustc_hir_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId, - ) { - } + ) {} } pub struct ParamBindingIdCollector { From 7a6cc8457e2f3bad9f70d222e60a2821d2ee0b46 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 16 Oct 2022 18:48:28 +0000 Subject: [PATCH 0649/1222] Introduce subst_iter and subst_iter_copied on EarlyBinder --- clippy_utils/src/ty.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index a15daec7c3ce..3b5a9ba83568 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -657,21 +657,18 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O let mut output = None; let lang_items = cx.tcx.lang_items(); - for pred in cx + for (pred, _) in cx .tcx .bound_explicit_item_bounds(ty.item_def_id) - .transpose_iter() - .map(|x| x.map_bound(|(p, _)| p)) + .subst_iter_copied(cx.tcx, ty.substs) { - match pred.0.kind().skip_binder() { + match pred.kind().skip_binder() { PredicateKind::Trait(p) if (lang_items.fn_trait() == Some(p.def_id()) || lang_items.fn_mut_trait() == Some(p.def_id()) || lang_items.fn_once_trait() == Some(p.def_id())) => { - let i = pred - .map_bound(|pred| pred.kind().rebind(p.trait_ref.substs.type_at(1))) - .subst(cx.tcx, ty.substs); + let i = pred.kind().rebind(p.trait_ref.substs.type_at(1)); if inputs.map_or(false, |inputs| inputs != i) { // Multiple different fn trait impls. Is this even allowed? @@ -684,10 +681,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O // Multiple different fn trait impls. Is this even allowed? return None; } - output = Some( - pred.map_bound(|pred| pred.kind().rebind(p.term.ty().unwrap())) - .subst(cx.tcx, ty.substs), - ); + output = pred.kind().rebind(p.term.ty()).transpose(); }, _ => (), } From fe89f95c81b194b0774e39cfe46fa866d5ff3081 Mon Sep 17 00:00:00 2001 From: mejrs <> Date: Mon, 24 Oct 2022 20:52:51 +0200 Subject: [PATCH 0650/1222] Address some comments --- tests/ui/track-diagnostics.rs | 8 ++++++++ tests/ui/track-diagnostics.stderr | 10 ++++++++++ 2 files changed, 18 insertions(+) create mode 100644 tests/ui/track-diagnostics.rs create mode 100644 tests/ui/track-diagnostics.stderr diff --git a/tests/ui/track-diagnostics.rs b/tests/ui/track-diagnostics.rs new file mode 100644 index 000000000000..8c96f46d57a2 --- /dev/null +++ b/tests/ui/track-diagnostics.rs @@ -0,0 +1,8 @@ +// compile-flags: -Z track-diagnostics +// error-pattern: created at + +struct A; +struct B; +const S: A = B; + +fn main() {} diff --git a/tests/ui/track-diagnostics.stderr b/tests/ui/track-diagnostics.stderr new file mode 100644 index 000000000000..76453cfe220c --- /dev/null +++ b/tests/ui/track-diagnostics.stderr @@ -0,0 +1,10 @@ +error[E0308]: mismatched types + --> $DIR/track-diagnostics.rs:6:14 + | +LL | const S: A = B; + | ^ expected struct `A`, found struct `B` +-Ztrack-diagnostics: created at compiler/rustc_infer/src/infer/error_reporting/mod.rs:2275:31 + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. From 43256e9a24d05560e249245af9261b837b9c9c5b Mon Sep 17 00:00:00 2001 From: mejrs <> Date: Mon, 24 Oct 2022 23:19:48 +0200 Subject: [PATCH 0651/1222] Add more normalization and tests --- tests/ui/track-diagnostics.rs | 4 ++++ tests/ui/track-diagnostics.stderr | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/ui/track-diagnostics.rs b/tests/ui/track-diagnostics.rs index 8c96f46d57a2..550ccd7b3d36 100644 --- a/tests/ui/track-diagnostics.rs +++ b/tests/ui/track-diagnostics.rs @@ -1,6 +1,10 @@ // compile-flags: -Z track-diagnostics // error-pattern: created at +// Normalize the emitted location so this doesn't need +// updating everytime someone adds or removes a line. +// normalize-stderr-test ".rs:\d+:\d+" -> ".rs:$$LINE::$$COL" + struct A; struct B; const S: A = B; diff --git a/tests/ui/track-diagnostics.stderr b/tests/ui/track-diagnostics.stderr index 76453cfe220c..5a0982ff731a 100644 --- a/tests/ui/track-diagnostics.stderr +++ b/tests/ui/track-diagnostics.stderr @@ -1,9 +1,9 @@ error[E0308]: mismatched types - --> $DIR/track-diagnostics.rs:6:14 + --> $DIR/track-diagnostics.rs:$LINE::$COL | LL | const S: A = B; | ^ expected struct `A`, found struct `B` --Ztrack-diagnostics: created at compiler/rustc_infer/src/infer/error_reporting/mod.rs:2275:31 +-Ztrack-diagnostics: created at compiler/rustc_infer/src/infer/error_reporting/mod.rs:$LINE::$COL error: aborting due to previous error From ffb0b20a30b90c358406eed0288e04bdd93e823b Mon Sep 17 00:00:00 2001 From: mejrs <> Date: Wed, 26 Oct 2022 13:41:57 +0200 Subject: [PATCH 0652/1222] Adjust normalization --- tests/ui/track-diagnostics.rs | 2 +- tests/ui/track-diagnostics.stderr | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ui/track-diagnostics.rs b/tests/ui/track-diagnostics.rs index 550ccd7b3d36..fa9221ed02d7 100644 --- a/tests/ui/track-diagnostics.rs +++ b/tests/ui/track-diagnostics.rs @@ -3,7 +3,7 @@ // Normalize the emitted location so this doesn't need // updating everytime someone adds or removes a line. -// normalize-stderr-test ".rs:\d+:\d+" -> ".rs:$$LINE::$$COL" +// normalize-stderr-test ".rs:\d+:\d+" -> ".rs:LL:CC" struct A; struct B; diff --git a/tests/ui/track-diagnostics.stderr b/tests/ui/track-diagnostics.stderr index 5a0982ff731a..ec3031862531 100644 --- a/tests/ui/track-diagnostics.stderr +++ b/tests/ui/track-diagnostics.stderr @@ -1,9 +1,9 @@ error[E0308]: mismatched types - --> $DIR/track-diagnostics.rs:$LINE::$COL + --> $DIR/track-diagnostics.rs:LL:CC | LL | const S: A = B; | ^ expected struct `A`, found struct `B` --Ztrack-diagnostics: created at compiler/rustc_infer/src/infer/error_reporting/mod.rs:$LINE::$COL +-Ztrack-diagnostics: created at compiler/rustc_infer/src/infer/error_reporting/mod.rs:LL:CC error: aborting due to previous error From 9a06914a386b5447f934713e9f1f1152eb2803e8 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 22 Sep 2022 16:19:53 +0300 Subject: [PATCH 0653/1222] privacy: Rename "accessibility levels" to "effective visibilities" And a couple of other naming tweaks Related to https://github.com/rust-lang/rust/issues/48054 --- clippy_lints/src/doc.rs | 2 +- clippy_lints/src/enum_variants.rs | 2 +- clippy_lints/src/exhaustive_items.rs | 2 +- clippy_lints/src/functions/must_use.rs | 8 ++++---- clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs | 2 +- clippy_lints/src/functions/result.rs | 6 +++--- clippy_lints/src/implicit_hasher.rs | 2 +- clippy_lints/src/len_zero.rs | 6 +++--- clippy_lints/src/methods/mod.rs | 4 ++-- clippy_lints/src/missing_inline.rs | 6 +++--- clippy_lints/src/new_without_default.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/redundant_pub_crate.rs | 4 ++-- clippy_lints/src/return_self_not_must_use.rs | 2 +- clippy_lints/src/types/mod.rs | 8 ++++---- clippy_lints/src/unnecessary_wraps.rs | 2 +- clippy_lints/src/unused_self.rs | 2 +- clippy_lints/src/upper_case_acronyms.rs | 2 +- 18 files changed, 32 insertions(+), 32 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 36dc7e3396b8..b47fa6c7ecf5 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -345,7 +345,7 @@ fn lint_for_missing_headers<'tcx>( body_id: Option, panic_span: Option, ) { - if !cx.access_levels.is_exported(def_id) { + if !cx.effective_visibilities.is_exported(def_id) { return; // Private functions do not require doc comments } diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index b019d07d53d1..2c3487a6e10f 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -296,7 +296,7 @@ impl LateLintPass<'_> for EnumVariantNames { } } if let ItemKind::Enum(ref def, _) = item.kind { - if !(self.avoid_breaking_exported_api && cx.access_levels.is_exported(item.def_id.def_id)) { + if !(self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(item.def_id.def_id)) { check_variant(cx, self.threshold, def, item_name, item.span); } } diff --git a/clippy_lints/src/exhaustive_items.rs b/clippy_lints/src/exhaustive_items.rs index be6242bd20b8..bb07b29b0763 100644 --- a/clippy_lints/src/exhaustive_items.rs +++ b/clippy_lints/src/exhaustive_items.rs @@ -73,7 +73,7 @@ impl LateLintPass<'_> for ExhaustiveItems { fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { if_chain! { if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind; - if cx.access_levels.is_exported(item.def_id.def_id); + if cx.effective_visibilities.is_exported(item.def_id.def_id); let attrs = cx.tcx.hir().attrs(item.hir_id()); if !attrs.iter().any(|a| a.has_name(sym::non_exhaustive)); then { diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 3064b6c9d22f..32cba5e608ad 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -24,7 +24,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_> let attrs = cx.tcx.hir().attrs(item.hir_id()); let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use); if let hir::ItemKind::Fn(ref sig, _generics, ref body_id) = item.kind { - let is_public = cx.access_levels.is_exported(item.def_id.def_id); + let is_public = cx.effective_visibilities.is_exported(item.def_id.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); if let Some(attr) = attr { check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr); @@ -44,7 +44,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_> pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind { - let is_public = cx.access_levels.is_exported(item.def_id.def_id); + let is_public = cx.effective_visibilities.is_exported(item.def_id.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let attrs = cx.tcx.hir().attrs(item.hir_id()); let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use); @@ -67,7 +67,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { if let hir::TraitItemKind::Fn(ref sig, ref eid) = item.kind { - let is_public = cx.access_levels.is_exported(item.def_id.def_id); + let is_public = cx.effective_visibilities.is_exported(item.def_id.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let attrs = cx.tcx.hir().attrs(item.hir_id()); @@ -137,7 +137,7 @@ fn check_must_use_candidate<'tcx>( || mutates_static(cx, body) || in_external_macro(cx.sess(), item_span) || returns_unit(decl) - || !cx.access_levels.is_exported(item_id) + || !cx.effective_visibilities.is_exported(item_id) || is_must_use_ty(cx, return_ty(cx, cx.tcx.hir().local_def_id_to_hir_id(item_id))) { return; diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index b7595d101e0f..0831b5cc38bd 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -42,7 +42,7 @@ fn check_raw_ptr<'tcx>( body: &'tcx hir::Body<'tcx>, def_id: LocalDefId, ) { - if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(def_id) { + if unsafety == hir::Unsafety::Normal && cx.effective_visibilities.is_exported(def_id) { let raw_ptrs = iter_input_pats(decl, body) .filter_map(|arg| raw_ptr_arg(cx, arg)) .collect::(); diff --git a/clippy_lints/src/functions/result.rs b/clippy_lints/src/functions/result.rs index 113c4e9f5091..c5ce56dd2cef 100644 --- a/clippy_lints/src/functions/result.rs +++ b/clippy_lints/src/functions/result.rs @@ -36,7 +36,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, l if let hir::ItemKind::Fn(ref sig, _generics, _) = item.kind && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id.def_id, item.span) { - if cx.access_levels.is_exported(item.def_id.def_id) { + if cx.effective_visibilities.is_exported(item.def_id.def_id) { let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); check_result_unit_err(cx, err_ty, fn_header_span); } @@ -50,7 +50,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::ImplItem && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id.def_id, item.span) && trait_ref_of_method(cx, item.def_id.def_id).is_none() { - if cx.access_levels.is_exported(item.def_id.def_id) { + if cx.effective_visibilities.is_exported(item.def_id.def_id) { let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); check_result_unit_err(cx, err_ty, fn_header_span); } @@ -62,7 +62,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::TraitIt if let hir::TraitItemKind::Fn(ref sig, _) = item.kind { let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); if let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id.def_id, item.span) { - if cx.access_levels.is_exported(item.def_id.def_id) { + if cx.effective_visibilities.is_exported(item.def_id.def_id) { check_result_unit_err(cx, err_ty, fn_header_span); } check_result_large_err(cx, err_ty, hir_ty.span, large_err_threshold); diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 93efe957b1dc..6415f35ddd03 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { } } - if !cx.access_levels.is_exported(item.def_id.def_id) { + if !cx.effective_visibilities.is_exported(item.def_id.def_id) { return; } diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 3a563736fb07..6e31812d7053 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero { if item.ident.name == sym::len; if let ImplItemKind::Fn(sig, _) = &item.kind; if sig.decl.implicit_self.has_implicit_self(); - if cx.access_levels.is_exported(item.def_id.def_id); + if cx.effective_visibilities.is_exported(item.def_id.def_id); if matches!(sig.decl.output, FnRetTy::Return(_)); if let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id()); if imp.of_trait.is_none(); @@ -210,7 +210,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items } } - if cx.access_levels.is_exported(visited_trait.def_id.def_id) + if cx.effective_visibilities.is_exported(visited_trait.def_id.def_id) && trait_items.iter().any(|i| is_named_self(cx, i, sym::len)) { let mut current_and_super_traits = DefIdSet::default(); @@ -331,7 +331,7 @@ fn check_for_is_empty<'tcx>( None, None, ), - Some(is_empty) if !cx.access_levels.is_exported(is_empty.def_id.expect_local()) => ( + Some(is_empty) if !cx.effective_visibilities.is_exported(is_empty.def_id.expect_local()) => ( format!( "{item_kind} `{}` has a public `len` method, but a private `is_empty` method", item_name.as_str(), diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index fb92779be2a7..adfa7426607f 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3258,7 +3258,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { let method_sig = cx.tcx.erase_late_bound_regions(method_sig); let first_arg_ty_opt = method_sig.inputs().iter().next().copied(); // if this impl block implements a trait, lint in trait definition instead - if !implements_trait && cx.access_levels.is_exported(impl_item.def_id.def_id) { + if !implements_trait && cx.effective_visibilities.is_exported(impl_item.def_id.def_id) { // check missing trait implementations for method_config in &TRAIT_METHODS { if name == method_config.method_name @@ -3292,7 +3292,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if sig.decl.implicit_self.has_implicit_self() && !(self.avoid_breaking_exported_api - && cx.access_levels.is_exported(impl_item.def_id.def_id)) + && cx.effective_visibilities.is_exported(impl_item.def_id.def_id)) && let Some(first_arg) = iter_input_pats(sig.decl, cx.tcx.hir().body(id)).next() && let Some(first_arg_ty) = first_arg_ty_opt { diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 01c87f058ade..ed9da2d92173 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -88,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { return; } - if !cx.access_levels.is_exported(it.def_id.def_id) { + if !cx.effective_visibilities.is_exported(it.def_id.def_id) { return; } match it.kind { @@ -142,7 +142,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { } // If the item being implemented is not exported, then we don't need #[inline] - if !cx.access_levels.is_exported(impl_item.def_id.def_id) { + if !cx.effective_visibilities.is_exported(impl_item.def_id.def_id) { return; } @@ -159,7 +159,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { }; if let Some(trait_def_id) = trait_def_id { - if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.def_id.def_id) { + if trait_def_id.is_local() && !cx.effective_visibilities.is_exported(impl_item.def_id.def_id) { // If a trait is being implemented for an item, and the // trait is not exported, we don't need #[inline] return; diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 6017117e1ecc..99166c68936c 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { if_chain! { if sig.decl.inputs.is_empty(); if name == sym::new; - if cx.access_levels.is_reachable(impl_item.def_id.def_id); + if cx.effective_visibilities.is_reachable(impl_item.def_id.def_id); let self_def_id = cx.tcx.hir().get_parent_item(id); let self_ty = cx.tcx.type_of(self_def_id); if self_ty == return_ty(cx, id); diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 45e98de10ace..c55985275db6 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -139,7 +139,7 @@ impl<'tcx> PassByRefOrValue { } fn check_poly_fn(&mut self, cx: &LateContext<'tcx>, def_id: LocalDefId, decl: &FnDecl<'_>, span: Option) { - if self.avoid_breaking_exported_api && cx.access_levels.is_exported(def_id) { + if self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(def_id) { return; } diff --git a/clippy_lints/src/redundant_pub_crate.rs b/clippy_lints/src/redundant_pub_crate.rs index 464f6827e1d5..bc73613a1502 100644 --- a/clippy_lints/src/redundant_pub_crate.rs +++ b/clippy_lints/src/redundant_pub_crate.rs @@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { if_chain! { if cx.tcx.visibility(item.def_id.def_id) == ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()); - if !cx.access_levels.is_exported(item.def_id.def_id) && self.is_exported.last() == Some(&false); + if !cx.effective_visibilities.is_exported(item.def_id.def_id) && self.is_exported.last() == Some(&false); if is_not_macro_export(item); then { let span = item.span.with_hi(item.ident.span.hi()); @@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { } if let ItemKind::Mod { .. } = item.kind { - self.is_exported.push(cx.access_levels.is_exported(item.def_id.def_id)); + self.is_exported.push(cx.effective_visibilities.is_exported(item.def_id.def_id)); } } diff --git a/clippy_lints/src/return_self_not_must_use.rs b/clippy_lints/src/return_self_not_must_use.rs index 16d702a3868d..7f34be5e7fd8 100644 --- a/clippy_lints/src/return_self_not_must_use.rs +++ b/clippy_lints/src/return_self_not_must_use.rs @@ -74,7 +74,7 @@ fn check_method(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_def: LocalDefId, spa if !in_external_macro(cx.sess(), span); if decl.implicit_self.has_implicit_self(); // We only show this warning for public exported methods. - if cx.access_levels.is_exported(fn_def); + if cx.effective_visibilities.is_exported(fn_def); // We don't want to emit this lint if the `#[must_use]` attribute is already there. if !cx.tcx.hir().attrs(hir_id).iter().any(|attr| attr.has_name(sym::must_use)); if cx.tcx.visibility(fn_def.to_def_id()).is_public(); diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index a06d1fffd8bd..40cdcc3865ba 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -319,7 +319,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { false }; - let is_exported = cx.access_levels.is_exported(cx.tcx.hir().local_def_id(id)); + let is_exported = cx.effective_visibilities.is_exported(cx.tcx.hir().local_def_id(id)); self.check_fn_decl( cx, @@ -333,7 +333,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { } fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - let is_exported = cx.access_levels.is_exported(item.def_id.def_id); + let is_exported = cx.effective_visibilities.is_exported(item.def_id.def_id); match item.kind { ItemKind::Static(ty, _, _) | ItemKind::Const(ty, _) => self.check_ty( @@ -379,7 +379,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { } fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) { - let is_exported = cx.access_levels.is_exported(cx.tcx.hir().local_def_id(field.hir_id)); + let is_exported = cx.effective_visibilities.is_exported(cx.tcx.hir().local_def_id(field.hir_id)); self.check_ty( cx, @@ -392,7 +392,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { } fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &TraitItem<'_>) { - let is_exported = cx.access_levels.is_exported(item.def_id.def_id); + let is_exported = cx.effective_visibilities.is_exported(item.def_id.def_id); let context = CheckTyContext { is_exported, diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index 7211e6864f3a..60b46854b4ff 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -83,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { match fn_kind { FnKind::ItemFn(..) | FnKind::Method(..) => { let def_id = cx.tcx.hir().local_def_id(hir_id); - if self.avoid_breaking_exported_api && cx.access_levels.is_exported(def_id) { + if self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(def_id) { return; } }, diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index 713fe06bad43..62ab927d2f5c 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf { if let ItemKind::Impl(Impl { of_trait: None, .. }) = parent_item.kind; if assoc_item.fn_has_self_parameter; if let ImplItemKind::Fn(.., body_id) = &impl_item.kind; - if !cx.access_levels.is_exported(impl_item.def_id.def_id) || !self.avoid_breaking_exported_api; + if !cx.effective_visibilities.is_exported(impl_item.def_id.def_id) || !self.avoid_breaking_exported_api; let body = cx.tcx.hir().body(*body_id); if let [self_param, ..] = body.params; if !is_local_used(cx, body, self_param.pat.hir_id); diff --git a/clippy_lints/src/upper_case_acronyms.rs b/clippy_lints/src/upper_case_acronyms.rs index 654ea306793b..7a20148c70a5 100644 --- a/clippy_lints/src/upper_case_acronyms.rs +++ b/clippy_lints/src/upper_case_acronyms.rs @@ -105,7 +105,7 @@ impl LateLintPass<'_> for UpperCaseAcronyms { fn check_item(&mut self, cx: &LateContext<'_>, it: &Item<'_>) { // do not lint public items or in macros if in_external_macro(cx.sess(), it.span) - || (self.avoid_breaking_exported_api && cx.access_levels.is_exported(it.def_id.def_id)) + || (self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(it.def_id.def_id)) { return; } From fce45b9d07b188cd9820f9de264aa97f82d64a6d Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 27 Oct 2022 18:32:17 +0400 Subject: [PATCH 0654/1222] Update tooling --- clippy_lints/src/casts/ptr_as_ptr.rs | 2 +- clippy_lints/src/dereference.rs | 10 +- clippy_lints/src/functions/must_use.rs | 2 +- clippy_lints/src/let_if_seq.rs | 2 +- clippy_lints/src/mut_key.rs | 10 +- clippy_lints/src/needless_pass_by_value.rs | 4 +- clippy_lints/src/non_copy_const.rs | 4 +- clippy_lints/src/question_mark.rs | 2 +- .../src/transmute/transmute_undefined_repr.rs | 165 +++++++++++------- .../src/types/redundant_allocation.rs | 18 +- clippy_lints/src/types/vec_box.rs | 2 +- clippy_utils/src/ty.rs | 4 +- 12 files changed, 134 insertions(+), 91 deletions(-) diff --git a/clippy_lints/src/casts/ptr_as_ptr.rs b/clippy_lints/src/casts/ptr_as_ptr.rs index c2b9253ec35d..b9509ca656f7 100644 --- a/clippy_lints/src/casts/ptr_as_ptr.rs +++ b/clippy_lints/src/casts/ptr_as_ptr.rs @@ -26,7 +26,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Option( cx.typeck_results().node_type(ty.ty.hir_id), binder_args, )) - .is_sized(cx.tcx.at(DUMMY_SP), cx.param_env.without_caller_bounds()), + .is_sized(cx.tcx, cx.param_env.without_caller_bounds()), ) } }, @@ -1005,7 +1005,7 @@ fn binding_ty_auto_deref_stability<'tcx>( cx.typeck_results().node_type(ty.ty.hir_id), binder_args, )) - .is_sized(cx.tcx.at(DUMMY_SP), cx.param_env.without_caller_bounds()), + .is_sized(cx.tcx, cx.param_env.without_caller_bounds()), ), TyKind::OpaqueDef(..) | TyKind::Infer | TyKind::Typeof(..) | TyKind::TraitObject(..) | TyKind::Err => { Position::ReborrowStable(precedence) @@ -1297,7 +1297,7 @@ impl<'tcx> TyPosition<'tcx> { fn position_for_result(self, cx: &LateContext<'tcx>) -> Position { match (self.position, self.ty) { (Position::ReborrowStable(precedence), Some(ty)) => { - Position::DerefStable(precedence, ty.is_sized(cx.tcx.at(DUMMY_SP), cx.param_env)) + Position::DerefStable(precedence, ty.is_sized(cx.tcx, cx.param_env)) }, (position, _) => position, } @@ -1348,7 +1348,7 @@ fn ty_auto_deref_stability<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, precedenc | ty::Tuple(_) | ty::Projection(_) => Position::DerefStable( precedence, - ty.is_sized(cx.tcx.at(DUMMY_SP), cx.param_env.without_caller_bounds()), + ty.is_sized(cx.tcx, cx.param_env.without_caller_bounds()), ) .into(), }; diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 3064b6c9d22f..922190a87d8c 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -188,7 +188,7 @@ fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, tys: &m // primitive types are never mutable ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false, ty::Adt(adt, substs) => { - tys.insert(adt.did()) && !ty.is_freeze(cx.tcx.at(span), cx.param_env) + tys.insert(adt.did()) && !ty.is_freeze(cx.tcx, cx.param_env) || KNOWN_WRAPPER_TYS .iter() .any(|&sym| cx.tcx.is_diagnostic_item(sym, adt.did())) diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 13071d64441a..db41bc67da1a 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq { let span = stmt.span.to(if_.span); let has_interior_mutability = !cx.typeck_results().node_type(canonical_id).is_freeze( - cx.tcx.at(span), + cx.tcx, cx.param_env, ); if has_interior_mutability { return; } diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 25d6ca83a94b..1d0744b631c6 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -136,12 +136,14 @@ fn check_ty<'tcx>(cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) { /// [`Hash`] or [`Ord`]. fn is_interior_mutable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span) -> bool { match *ty.kind() { - Ref(_, inner_ty, mutbl) => mutbl == hir::Mutability::Mut || is_interior_mutable_type(cx, inner_ty, span), + Ref(_, inner_ty, mutbl) => { + mutbl == hir::Mutability::Mut || is_interior_mutable_type(cx, inner_ty, span) + } Slice(inner_ty) => is_interior_mutable_type(cx, inner_ty, span), Array(inner_ty, size) => { size.try_eval_usize(cx.tcx, cx.param_env).map_or(true, |u| u != 0) && is_interior_mutable_type(cx, inner_ty, span) - }, + } Tuple(fields) => fields.iter().any(|ty| is_interior_mutable_type(cx, ty, span)), Adt(def, substs) => { // Special case for collections in `std` who's impl of `Hash` or `Ord` delegates to @@ -167,9 +169,9 @@ fn is_interior_mutable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Sp } else { !ty.has_escaping_bound_vars() && cx.tcx.layout_of(cx.param_env.and(ty)).is_ok() - && !ty.is_freeze(cx.tcx.at(span), cx.param_env) + && !ty.is_freeze(cx.tcx, cx.param_env) } - }, + } _ => false, } } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 9c949a28f44d..b2e9ce5c94d6 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -19,7 +19,7 @@ use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::{self, TypeVisitable}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::kw; -use rustc_span::{sym, Span, DUMMY_SP}; +use rustc_span::{sym, Span}; use rustc_target::spec::abi::Abi; use rustc_trait_selection::traits; use rustc_trait_selection::traits::misc::can_type_implement_copy; @@ -184,7 +184,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { if !is_self(arg); if !ty.is_mutable_ptr(); if !is_copy(cx, ty); - if ty.is_sized(cx.tcx.at(DUMMY_SP), cx.param_env); + if ty.is_sized(cx.tcx, cx.param_env); if !allowed_traits.iter().any(|&t| implements_trait(cx, ty, t, &[])); if !implements_borrow_trait; if !all_borrowable_trait; diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index a6742824bc56..671c16953aed 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -20,7 +20,7 @@ use rustc_middle::mir::interpret::{ConstValue, ErrorHandled}; use rustc_middle::ty::adjustment::Adjust; use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::{sym, InnerSpan, Span, DUMMY_SP}; +use rustc_span::{sym, InnerSpan, Span}; // FIXME: this is a correctness problem but there's no suitable // warn-by-default category. @@ -136,7 +136,7 @@ fn is_unfrozen<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { // since it works when a pointer indirection involves (`Cell<*const T>`). // Making up a `ParamEnv` where every generic params and assoc types are `Freeze`is another option; // but I'm not sure whether it's a decent way, if possible. - cx.tcx.layout_of(cx.param_env.and(ty)).is_ok() && !ty.is_freeze(cx.tcx.at(DUMMY_SP), cx.param_env) + cx.tcx.layout_of(cx.param_env.and(ty)).is_ok() && !ty.is_freeze(cx.tcx, cx.param_env) } fn is_value_unfrozen_raw<'tcx>( diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 328371fd602f..bb86fb3b7d42 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -94,7 +94,7 @@ fn check_is_none_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr: &Ex then { let mut applicability = Applicability::MachineApplicable; let receiver_str = snippet_with_applicability(cx, caller.span, "..", &mut applicability); - let by_ref = !caller_ty.is_copy_modulo_regions(cx.tcx.at(caller.span), cx.param_env) && + let by_ref = !caller_ty.is_copy_modulo_regions(cx.tcx, cx.param_env) && !matches!(caller.kind, ExprKind::Call(..) | ExprKind::MethodCall(..)); let sugg = if let Some(else_inner) = r#else { if eq_expr_value(cx, caller, peel_blocks(else_inner)) { diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index 1c99a02e6c71..3d4bbbf648c6 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -5,7 +5,6 @@ use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_middle::ty::SubstsRef; use rustc_middle::ty::{self, IntTy, Ty, TypeAndMut, UintTy}; -use rustc_span::DUMMY_SP; #[expect(clippy::too_many_lines)] pub(super) fn check<'tcx>( @@ -28,24 +27,32 @@ pub(super) fn check<'tcx>( // `Repr(C)` <-> unordered type. // If the first field of the `Repr(C)` type matches then the transmute is ok - (ReducedTy::OrderedFields(_, Some(from_sub_ty)), ReducedTy::UnorderedFields(to_sub_ty)) - | (ReducedTy::UnorderedFields(from_sub_ty), ReducedTy::OrderedFields(_, Some(to_sub_ty))) => { + ( + ReducedTy::OrderedFields(_, Some(from_sub_ty)), + ReducedTy::UnorderedFields(to_sub_ty), + ) + | ( + ReducedTy::UnorderedFields(from_sub_ty), + ReducedTy::OrderedFields(_, Some(to_sub_ty)), + ) => { from_ty = from_sub_ty; to_ty = to_sub_ty; continue; - }, - (ReducedTy::OrderedFields(_, Some(from_sub_ty)), ReducedTy::Other(to_sub_ty)) if reduced_tys.to_fat_ptr => { + } + (ReducedTy::OrderedFields(_, Some(from_sub_ty)), ReducedTy::Other(to_sub_ty)) + if reduced_tys.to_fat_ptr => + { from_ty = from_sub_ty; to_ty = to_sub_ty; continue; - }, + } (ReducedTy::Other(from_sub_ty), ReducedTy::OrderedFields(_, Some(to_sub_ty))) if reduced_tys.from_fat_ptr => { from_ty = from_sub_ty; to_ty = to_sub_ty; continue; - }, + } // ptr <-> ptr (ReducedTy::Other(from_sub_ty), ReducedTy::Other(to_sub_ty)) @@ -55,19 +62,19 @@ pub(super) fn check<'tcx>( from_ty = from_sub_ty; to_ty = to_sub_ty; continue; - }, + } // fat ptr <-> (*size, *size) (ReducedTy::Other(_), ReducedTy::UnorderedFields(to_ty)) if reduced_tys.from_fat_ptr && is_size_pair(to_ty) => { return false; - }, + } (ReducedTy::UnorderedFields(from_ty), ReducedTy::Other(_)) if reduced_tys.to_fat_ptr && is_size_pair(from_ty) => { return false; - }, + } // fat ptr -> some struct | some struct -> fat ptr (ReducedTy::Other(_), _) if reduced_tys.from_fat_ptr => { @@ -78,12 +85,14 @@ pub(super) fn check<'tcx>( &format!("transmute from `{from_ty_orig}` which has an undefined layout"), |diag| { if from_ty_orig.peel_refs() != from_ty.peel_refs() { - diag.note(&format!("the contained type `{from_ty}` has an undefined layout")); + diag.note(&format!( + "the contained type `{from_ty}` has an undefined layout" + )); } }, ); return true; - }, + } (_, ReducedTy::Other(_)) if reduced_tys.to_fat_ptr => { span_lint_and_then( cx, @@ -92,14 +101,18 @@ pub(super) fn check<'tcx>( &format!("transmute to `{to_ty_orig}` which has an undefined layout"), |diag| { if to_ty_orig.peel_refs() != to_ty.peel_refs() { - diag.note(&format!("the contained type `{to_ty}` has an undefined layout")); + diag.note(&format!( + "the contained type `{to_ty}` has an undefined layout" + )); } }, ); return true; - }, + } - (ReducedTy::UnorderedFields(from_ty), ReducedTy::UnorderedFields(to_ty)) if from_ty != to_ty => { + (ReducedTy::UnorderedFields(from_ty), ReducedTy::UnorderedFields(to_ty)) + if from_ty != to_ty => + { let same_adt_did = if let (ty::Adt(from_def, from_subs), ty::Adt(to_def, to_subs)) = (from_ty.kind(), to_ty.kind()) && from_def == to_def @@ -126,19 +139,25 @@ pub(super) fn check<'tcx>( )); } else { if from_ty_orig.peel_refs() != from_ty { - diag.note(&format!("the contained type `{from_ty}` has an undefined layout")); + diag.note(&format!( + "the contained type `{from_ty}` has an undefined layout" + )); } if to_ty_orig.peel_refs() != to_ty { - diag.note(&format!("the contained type `{to_ty}` has an undefined layout")); + diag.note(&format!( + "the contained type `{to_ty}` has an undefined layout" + )); } } }, ); return true; - }, + } ( ReducedTy::UnorderedFields(from_ty), - ReducedTy::Other(_) | ReducedTy::OrderedFields(..) | ReducedTy::TypeErasure { raw_ptr_only: true }, + ReducedTy::Other(_) + | ReducedTy::OrderedFields(..) + | ReducedTy::TypeErasure { raw_ptr_only: true }, ) => { span_lint_and_then( cx, @@ -147,14 +166,18 @@ pub(super) fn check<'tcx>( &format!("transmute from `{from_ty_orig}` which has an undefined layout"), |diag| { if from_ty_orig.peel_refs() != from_ty { - diag.note(&format!("the contained type `{from_ty}` has an undefined layout")); + diag.note(&format!( + "the contained type `{from_ty}` has an undefined layout" + )); } }, ); return true; - }, + } ( - ReducedTy::Other(_) | ReducedTy::OrderedFields(..) | ReducedTy::TypeErasure { raw_ptr_only: true }, + ReducedTy::Other(_) + | ReducedTy::OrderedFields(..) + | ReducedTy::TypeErasure { raw_ptr_only: true }, ReducedTy::UnorderedFields(to_ty), ) => { span_lint_and_then( @@ -164,19 +187,25 @@ pub(super) fn check<'tcx>( &format!("transmute into `{to_ty_orig}` which has an undefined layout"), |diag| { if to_ty_orig.peel_refs() != to_ty { - diag.note(&format!("the contained type `{to_ty}` has an undefined layout")); + diag.note(&format!( + "the contained type `{to_ty}` has an undefined layout" + )); } }, ); return true; - }, + } ( - ReducedTy::OrderedFields(..) | ReducedTy::Other(_) | ReducedTy::TypeErasure { raw_ptr_only: true }, - ReducedTy::OrderedFields(..) | ReducedTy::Other(_) | ReducedTy::TypeErasure { raw_ptr_only: true }, + ReducedTy::OrderedFields(..) + | ReducedTy::Other(_) + | ReducedTy::TypeErasure { raw_ptr_only: true }, + ReducedTy::OrderedFields(..) + | ReducedTy::Other(_) + | ReducedTy::TypeErasure { raw_ptr_only: true }, ) | (ReducedTy::UnorderedFields(_), ReducedTy::UnorderedFields(_)) => { break; - }, + } } } @@ -194,42 +223,38 @@ struct ReducedTys<'tcx> { } /// Remove references so long as both types are references. -fn reduce_refs<'tcx>(cx: &LateContext<'tcx>, mut from_ty: Ty<'tcx>, mut to_ty: Ty<'tcx>) -> ReducedTys<'tcx> { +fn reduce_refs<'tcx>( + cx: &LateContext<'tcx>, + mut from_ty: Ty<'tcx>, + mut to_ty: Ty<'tcx>, +) -> ReducedTys<'tcx> { let mut from_raw_ptr = false; let mut to_raw_ptr = false; - let (from_fat_ptr, to_fat_ptr) = loop { - break match (from_ty.kind(), to_ty.kind()) { - ( - &(ty::Ref(_, from_sub_ty, _) | ty::RawPtr(TypeAndMut { ty: from_sub_ty, .. })), - &(ty::Ref(_, to_sub_ty, _) | ty::RawPtr(TypeAndMut { ty: to_sub_ty, .. })), - ) => { - from_raw_ptr = matches!(*from_ty.kind(), ty::RawPtr(_)); - from_ty = from_sub_ty; - to_raw_ptr = matches!(*to_ty.kind(), ty::RawPtr(_)); - to_ty = to_sub_ty; - continue; - }, - (&(ty::Ref(_, unsized_ty, _) | ty::RawPtr(TypeAndMut { ty: unsized_ty, .. })), _) - if !unsized_ty.is_sized(cx.tcx.at(DUMMY_SP), cx.param_env) => - { - (true, false) - }, - (_, &(ty::Ref(_, unsized_ty, _) | ty::RawPtr(TypeAndMut { ty: unsized_ty, .. }))) - if !unsized_ty.is_sized(cx.tcx.at(DUMMY_SP), cx.param_env) => - { - (false, true) - }, - _ => (false, false), + let (from_fat_ptr, to_fat_ptr) = + loop { + break match (from_ty.kind(), to_ty.kind()) { + ( + &(ty::Ref(_, from_sub_ty, _) | ty::RawPtr(TypeAndMut { ty: from_sub_ty, .. })), + &(ty::Ref(_, to_sub_ty, _) | ty::RawPtr(TypeAndMut { ty: to_sub_ty, .. })), + ) => { + from_raw_ptr = matches!(*from_ty.kind(), ty::RawPtr(_)); + from_ty = from_sub_ty; + to_raw_ptr = matches!(*to_ty.kind(), ty::RawPtr(_)); + to_ty = to_sub_ty; + continue; + } + ( + &(ty::Ref(_, unsized_ty, _) | ty::RawPtr(TypeAndMut { ty: unsized_ty, .. })), + _, + ) if !unsized_ty.is_sized(cx.tcx, cx.param_env) => (true, false), + ( + _, + &(ty::Ref(_, unsized_ty, _) | ty::RawPtr(TypeAndMut { ty: unsized_ty, .. })), + ) if !unsized_ty.is_sized(cx.tcx, cx.param_env) => (false, true), + _ => (false, false), + }; }; - }; - ReducedTys { - from_ty, - to_ty, - from_raw_ptr, - to_raw_ptr, - from_fat_ptr, - to_fat_ptr, - } + ReducedTys { from_ty, to_ty, from_raw_ptr, to_raw_ptr, from_fat_ptr, to_fat_ptr } } enum ReducedTy<'tcx> { @@ -252,11 +277,11 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> return match *ty.kind() { ty::Array(sub_ty, _) if matches!(sub_ty.kind(), ty::Int(_) | ty::Uint(_)) => { ReducedTy::TypeErasure { raw_ptr_only: false } - }, + } ty::Array(sub_ty, _) | ty::Slice(sub_ty) => { ty = sub_ty; continue; - }, + } ty::Tuple(args) if args.is_empty() => ReducedTy::TypeErasure { raw_ptr_only: false }, ty::Tuple(args) => { let mut iter = args.iter(); @@ -268,7 +293,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> continue; } ReducedTy::UnorderedFields(ty) - }, + } ty::Adt(def, substs) if def.is_struct() => { let mut iter = def .non_enum_variant() @@ -287,10 +312,12 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> } else { ReducedTy::UnorderedFields(ty) } - }, - ty::Adt(def, _) if def.is_enum() && (def.variants().is_empty() || is_c_void(cx, ty)) => { + } + ty::Adt(def, _) + if def.is_enum() && (def.variants().is_empty() || is_c_void(cx, ty)) => + { ReducedTy::TypeErasure { raw_ptr_only: false } - }, + } // TODO: Check if the conversion to or from at least one of a union's fields is valid. ty::Adt(def, _) if def.is_union() => ReducedTy::TypeErasure { raw_ptr_only: false }, ty::Foreign(_) | ty::Param(_) => ReducedTy::TypeErasure { raw_ptr_only: false }, @@ -329,7 +356,11 @@ fn same_except_params<'tcx>(subs1: SubstsRef<'tcx>, subs2: SubstsRef<'tcx>) -> b for (ty1, ty2) in subs1.types().zip(subs2.types()).filter(|(ty1, ty2)| ty1 != ty2) { match (ty1.kind(), ty2.kind()) { (ty::Param(_), _) | (_, ty::Param(_)) => (), - (ty::Adt(adt1, subs1), ty::Adt(adt2, subs2)) if adt1 == adt2 && same_except_params(subs1, subs2) => (), + (ty::Adt(adt1, subs1), ty::Adt(adt2, subs2)) + if adt1 == adt2 && same_except_params(subs1, subs2) => + { + () + } _ => return false, } } diff --git a/clippy_lints/src/types/redundant_allocation.rs b/clippy_lints/src/types/redundant_allocation.rs index 7883353e3fef..2b964b64a330 100644 --- a/clippy_lints/src/types/redundant_allocation.rs +++ b/clippy_lints/src/types/redundant_allocation.rs @@ -9,7 +9,12 @@ use rustc_span::symbol::sym; use super::{utils, REDUNDANT_ALLOCATION}; -pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool { +pub(super) fn check( + cx: &LateContext<'_>, + hir_ty: &hir::Ty<'_>, + qpath: &QPath<'_>, + def_id: DefId, +) -> bool { let mut applicability = Applicability::MaybeIncorrect; let outer_sym = if Some(def_id) == cx.tcx.lang_items().owned_box() { "Box" @@ -29,7 +34,12 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_ hir_ty.span, &format!("usage of `{outer_sym}<{generic_snippet}>`"), |diag| { - diag.span_suggestion(hir_ty.span, "try", format!("{generic_snippet}"), applicability); + diag.span_suggestion( + hir_ty.span, + "try", + format!("{generic_snippet}"), + applicability, + ); diag.note(&format!( "`{generic_snippet}` is already a pointer, `{outer_sym}<{generic_snippet}>` allocates a pointer on the heap" )); @@ -55,11 +65,11 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_ // Reallocation of a fat pointer causes it to become thin. `hir_ty_to_ty` is safe to use // here because `mod.rs` guarantees this lint is only run on types outside of bodies and // is not run on locals. - if !hir_ty_to_ty(cx.tcx, ty).is_sized(cx.tcx.at(ty.span), cx.param_env) { + if !hir_ty_to_ty(cx.tcx, ty).is_sized(cx.tcx, cx.param_env) { return false; } ty.span - }, + } None => return false, }; if inner_sym == outer_sym { diff --git a/clippy_lints/src/types/vec_box.rs b/clippy_lints/src/types/vec_box.rs index 6c329d8cdf19..9ad2cb853d39 100644 --- a/clippy_lints/src/types/vec_box.rs +++ b/clippy_lints/src/types/vec_box.rs @@ -40,7 +40,7 @@ pub(super) fn check( }); let ty_ty = hir_ty_to_ty(cx.tcx, boxed_ty); if !ty_ty.has_escaping_bound_vars(); - if ty_ty.is_sized(cx.tcx.at(ty.span), cx.param_env); + if ty_ty.is_sized(cx.tcx, cx.param_env); if let Ok(ty_ty_size) = cx.layout_of(ty_ty).map(|l| l.size.bytes()); if ty_ty_size <= box_size_threshold; then { diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 3b5a9ba83568..4e024ce40179 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -18,7 +18,7 @@ use rustc_middle::ty::{ }; use rustc_middle::ty::{GenericArg, GenericArgKind}; use rustc_span::symbol::Ident; -use rustc_span::{sym, Span, Symbol, DUMMY_SP}; +use rustc_span::{sym, Span, Symbol}; use rustc_target::abi::{Size, VariantIdx}; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::query::normalize::AtExt; @@ -28,7 +28,7 @@ use crate::{match_def_path, path_res, paths}; // Checks if the given type implements copy. pub fn is_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { - ty.is_copy_modulo_regions(cx.tcx.at(DUMMY_SP), cx.param_env) + ty.is_copy_modulo_regions(cx.tcx, cx.param_env) } /// This checks whether a given type is known to implement Debug. From f414a554d0deb692d0e9ad4c99e7ab8e3144b7b9 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Thu, 27 Oct 2022 22:24:24 +0200 Subject: [PATCH 0655/1222] Move clippy::uninlined_format_args back to pedantic --- clippy_lints/src/format_args.rs | 2 +- clippy_lints/src/lib.register_all.rs | 1 - clippy_lints/src/lib.register_pedantic.rs | 1 + clippy_lints/src/lib.register_style.rs | 1 - 4 files changed, 2 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/format_args.rs b/clippy_lints/src/format_args.rs index 32073536b45b..f0fe845d3303 100644 --- a/clippy_lints/src/format_args.rs +++ b/clippy_lints/src/format_args.rs @@ -115,7 +115,7 @@ declare_clippy_lint! { /// nothing will be suggested, e.g. `println!("{0}={1}", var, 1+2)`. #[clippy::version = "1.65.0"] pub UNINLINED_FORMAT_ARGS, - style, + pedantic, "using non-inlined variables in `format!` calls" } diff --git a/clippy_lints/src/lib.register_all.rs b/clippy_lints/src/lib.register_all.rs index f5ad52ba1892..c455e1561b71 100644 --- a/clippy_lints/src/lib.register_all.rs +++ b/clippy_lints/src/lib.register_all.rs @@ -72,7 +72,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![ LintId::of(format::USELESS_FORMAT), LintId::of(format_args::FORMAT_IN_FORMAT_ARGS), LintId::of(format_args::TO_STRING_IN_FORMAT_ARGS), - LintId::of(format_args::UNINLINED_FORMAT_ARGS), LintId::of(format_args::UNUSED_FORMAT_SPECS), LintId::of(format_impl::PRINT_IN_FORMAT_IMPL), LintId::of(format_impl::RECURSIVE_FORMAT_IMPL), diff --git a/clippy_lints/src/lib.register_pedantic.rs b/clippy_lints/src/lib.register_pedantic.rs index 060d3bdc7c6f..44e969585b50 100644 --- a/clippy_lints/src/lib.register_pedantic.rs +++ b/clippy_lints/src/lib.register_pedantic.rs @@ -29,6 +29,7 @@ store.register_group(true, "clippy::pedantic", Some("clippy_pedantic"), vec![ LintId::of(eta_reduction::REDUNDANT_CLOSURE_FOR_METHOD_CALLS), LintId::of(excessive_bools::FN_PARAMS_EXCESSIVE_BOOLS), LintId::of(excessive_bools::STRUCT_EXCESSIVE_BOOLS), + LintId::of(format_args::UNINLINED_FORMAT_ARGS), LintId::of(functions::MUST_USE_CANDIDATE), LintId::of(functions::TOO_MANY_LINES), LintId::of(if_not_else::IF_NOT_ELSE), diff --git a/clippy_lints/src/lib.register_style.rs b/clippy_lints/src/lib.register_style.rs index 6894d69e928a..3312f5648552 100644 --- a/clippy_lints/src/lib.register_style.rs +++ b/clippy_lints/src/lib.register_style.rs @@ -25,7 +25,6 @@ store.register_group(true, "clippy::style", Some("clippy_style"), vec![ LintId::of(enum_variants::MODULE_INCEPTION), LintId::of(eta_reduction::REDUNDANT_CLOSURE), LintId::of(float_literal::EXCESSIVE_PRECISION), - LintId::of(format_args::UNINLINED_FORMAT_ARGS), LintId::of(from_over_into::FROM_OVER_INTO), LintId::of(from_str_radix_10::FROM_STR_RADIX_10), LintId::of(functions::DOUBLE_MUST_USE), From 7061f3483eee3999932b792f40752b3cfc9db187 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Fri, 28 Oct 2022 11:46:12 +0000 Subject: [PATCH 0656/1222] Retain ParamEnv constness when running deferred cast checks Fixes #103677. --- clippy_lints/src/transmute/utils.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/transmute/utils.rs b/clippy_lints/src/transmute/utils.rs index 2f190e594a83..641cdf5d330e 100644 --- a/clippy_lints/src/transmute/utils.rs +++ b/clippy_lints/src/transmute/utils.rs @@ -3,6 +3,7 @@ use rustc_hir_typeck::{cast, FnCtxt, Inherited}; use rustc_lint::LateContext; use rustc_middle::ty::{cast::CastKind, Ty}; use rustc_span::DUMMY_SP; +use rustc_hir as hir; // check if the component types of the transmuted collection and the result have different ABI, // size or alignment @@ -56,7 +57,7 @@ fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx> if let Ok(check) = cast::CastCheck::new( &fn_ctxt, e, from_ty, to_ty, // We won't show any error to the user, so we don't care what the span is here. - DUMMY_SP, DUMMY_SP, + DUMMY_SP, DUMMY_SP, hir::Constness::NotConst, ) { let res = check.do_check(&fn_ctxt); From faa3b7570fdc1b936e9a9788a1512a76b42ced27 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 27 Oct 2022 14:02:18 +1100 Subject: [PATCH 0657/1222] Rename some `OwnerId` fields. spastorino noticed some silly expressions like `item_id.def_id.def_id`. This commit renames several `def_id: OwnerId` fields as `owner_id`, so those expressions become `item_id.owner_id.def_id`. `item_id.owner_id.local_def_id` would be even clearer, but the use of `def_id` for values of type `LocalDefId` is *very* widespread, so I left that alone. --- clippy_lints/src/copy_iterator.rs | 2 +- .../src/default_union_representation.rs | 2 +- clippy_lints/src/dereference.rs | 16 +++++++-------- clippy_lints/src/derivable_impls.rs | 4 ++-- clippy_lints/src/derive.rs | 4 ++-- clippy_lints/src/doc.rs | 12 +++++------ clippy_lints/src/empty_enum.rs | 2 +- clippy_lints/src/enum_variants.rs | 4 ++-- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/exhaustive_items.rs | 2 +- clippy_lints/src/fallible_impl_from.rs | 4 ++-- clippy_lints/src/from_over_into.rs | 2 +- clippy_lints/src/functions/must_use.rs | 20 +++++++++---------- .../src/functions/not_unsafe_ptr_arg_deref.rs | 2 +- clippy_lints/src/functions/result.rs | 14 ++++++------- clippy_lints/src/implicit_hasher.rs | 2 +- clippy_lints/src/inherent_to_string.rs | 4 ++-- .../src/iter_not_returning_iterator.rs | 4 ++-- clippy_lints/src/large_enum_variant.rs | 2 +- clippy_lints/src/len_zero.rs | 10 +++++----- clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/manual_non_exhaustive.rs | 2 +- clippy_lints/src/methods/mod.rs | 12 +++++------ clippy_lints/src/missing_doc.rs | 10 +++++----- clippy_lints/src/missing_inline.rs | 10 +++++----- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/new_without_default.rs | 4 ++-- clippy_lints/src/non_copy_const.rs | 2 +- .../src/non_send_fields_in_send_ty.rs | 2 +- clippy_lints/src/only_used_in_recursion.rs | 16 +++++++-------- clippy_lints/src/operators/op_ref.rs | 2 +- clippy_lints/src/partialeq_ne_impl.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/ptr.rs | 8 ++++---- clippy_lints/src/redundant_pub_crate.rs | 8 ++++---- clippy_lints/src/return_self_not_must_use.rs | 2 +- clippy_lints/src/same_name_method.rs | 2 +- clippy_lints/src/self_named_constructors.rs | 2 +- clippy_lints/src/trailing_empty_array.rs | 2 +- clippy_lints/src/types/mod.rs | 4 ++-- clippy_lints/src/unused_self.rs | 4 ++-- clippy_lints/src/unwrap_in_result.rs | 2 +- clippy_lints/src/upper_case_acronyms.rs | 2 +- clippy_lints/src/use_self.rs | 4 ++-- clippy_lints/src/wildcard_imports.rs | 6 +++--- clippy_utils/src/lib.rs | 2 +- 46 files changed, 115 insertions(+), 115 deletions(-) diff --git a/clippy_lints/src/copy_iterator.rs b/clippy_lints/src/copy_iterator.rs index 026683f60062..e38f77268530 100644 --- a/clippy_lints/src/copy_iterator.rs +++ b/clippy_lints/src/copy_iterator.rs @@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyIterator { of_trait: Some(ref trait_ref), .. }) = item.kind; - let ty = cx.tcx.type_of(item.def_id); + let ty = cx.tcx.type_of(item.owner_id); if is_copy(cx, ty); if let Some(trait_id) = trait_ref.trait_def_id(); if cx.tcx.is_diagnostic_item(sym::Iterator, trait_id); diff --git a/clippy_lints/src/default_union_representation.rs b/clippy_lints/src/default_union_representation.rs index 741edc131960..dec357ab75c3 100644 --- a/clippy_lints/src/default_union_representation.rs +++ b/clippy_lints/src/default_union_representation.rs @@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultUnionRepresentation { None, &format!( "consider annotating `{}` with `#[repr(C)]` to explicitly specify memory layout", - cx.tcx.def_path_str(item.def_id.to_def_id()) + cx.tcx.def_path_str(item.owner_id.to_def_id()) ), ); } diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index a95d9f5390de..c029031363bb 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -715,47 +715,47 @@ fn walk_parents<'tcx>( }, Node::Item(&Item { kind: ItemKind::Static(..) | ItemKind::Const(..), - def_id, + owner_id, span, .. }) | Node::TraitItem(&TraitItem { kind: TraitItemKind::Const(..), - def_id, + owner_id, span, .. }) | Node::ImplItem(&ImplItem { kind: ImplItemKind::Const(..), - def_id, + owner_id, span, .. }) if span.ctxt() == ctxt => { - let ty = cx.tcx.type_of(def_id.def_id); + let ty = cx.tcx.type_of(owner_id.def_id); Some(ty_auto_deref_stability(cx, ty, precedence).position_for_result(cx)) }, Node::Item(&Item { kind: ItemKind::Fn(..), - def_id, + owner_id, span, .. }) | Node::TraitItem(&TraitItem { kind: TraitItemKind::Fn(..), - def_id, + owner_id, span, .. }) | Node::ImplItem(&ImplItem { kind: ImplItemKind::Fn(..), - def_id, + owner_id, span, .. }) if span.ctxt() == ctxt => { let output = cx .tcx - .erase_late_bound_regions(cx.tcx.fn_sig(def_id.to_def_id()).output()); + .erase_late_bound_regions(cx.tcx.fn_sig(owner_id.to_def_id()).output()); Some(ty_auto_deref_stability(cx, output, precedence).position_for_result(cx)) }, diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index 06ae5abeaeb9..ae8f6b794499 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { self_ty, .. }) = item.kind; - if !cx.tcx.has_attr(item.def_id.to_def_id(), sym::automatically_derived); + if !cx.tcx.has_attr(item.owner_id.to_def_id(), sym::automatically_derived); if !item.span.from_expansion(); if let Some(def_id) = trait_ref.trait_def_id(); if cx.tcx.is_diagnostic_item(sym::Default, def_id); @@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { if let Some(Node::ImplItem(impl_item)) = cx.tcx.hir().find(impl_item_hir); if let ImplItemKind::Fn(_, b) = &impl_item.kind; if let Body { value: func_expr, .. } = cx.tcx.hir().body(*b); - if let Some(adt_def) = cx.tcx.type_of(item.def_id).ty_adt_def(); + if let Some(adt_def) = cx.tcx.type_of(item.owner_id).ty_adt_def(); if let attrs = cx.tcx.hir().attrs(item.hir_id()); if !attrs.iter().any(|attr| attr.doc_str().is_some()); if let child_attrs = cx.tcx.hir().attrs(impl_item_hir); diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index fad984d05ca9..102a02138bc8 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -210,8 +210,8 @@ impl<'tcx> LateLintPass<'tcx> for Derive { .. }) = item.kind { - let ty = cx.tcx.type_of(item.def_id); - let is_automatically_derived = cx.tcx.has_attr(item.def_id.to_def_id(), sym::automatically_derived); + let ty = cx.tcx.type_of(item.owner_id); + let is_automatically_derived = cx.tcx.has_attr(item.owner_id.to_def_id(), sym::automatically_derived); check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived); check_ord_partial_ord(cx, item.span, trait_ref, ty, is_automatically_derived); diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index b47fa6c7ecf5..24d6a6951af8 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -257,17 +257,17 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { let headers = check_attrs(cx, &self.valid_idents, attrs); match item.kind { hir::ItemKind::Fn(ref sig, _, body_id) => { - if !(is_entrypoint_fn(cx, item.def_id.to_def_id()) || in_external_macro(cx.tcx.sess, item.span)) { + if !(is_entrypoint_fn(cx, item.owner_id.to_def_id()) || in_external_macro(cx.tcx.sess, item.span)) { let body = cx.tcx.hir().body(body_id); let mut fpu = FindPanicUnwrap { cx, - typeck_results: cx.tcx.typeck(item.def_id.def_id), + typeck_results: cx.tcx.typeck(item.owner_id.def_id), panic_span: None, }; fpu.visit_expr(body.value); lint_for_missing_headers( cx, - item.def_id.def_id, + item.owner_id.def_id, item.span, sig, headers, @@ -304,7 +304,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { let headers = check_attrs(cx, &self.valid_idents, attrs); if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { if !in_external_macro(cx.tcx.sess, item.span) { - lint_for_missing_headers(cx, item.def_id.def_id, item.span, sig, headers, None, None); + lint_for_missing_headers(cx, item.owner_id.def_id, item.span, sig, headers, None, None); } } } @@ -319,13 +319,13 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { let body = cx.tcx.hir().body(body_id); let mut fpu = FindPanicUnwrap { cx, - typeck_results: cx.tcx.typeck(item.def_id.def_id), + typeck_results: cx.tcx.typeck(item.owner_id.def_id), panic_span: None, }; fpu.visit_expr(body.value); lint_for_missing_headers( cx, - item.def_id.def_id, + item.owner_id.def_id, item.span, sig, headers, diff --git a/clippy_lints/src/empty_enum.rs b/clippy_lints/src/empty_enum.rs index bbebc0244141..0570c2a10138 100644 --- a/clippy_lints/src/empty_enum.rs +++ b/clippy_lints/src/empty_enum.rs @@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for EmptyEnum { } if let ItemKind::Enum(..) = item.kind { - let ty = cx.tcx.type_of(item.def_id); + let ty = cx.tcx.type_of(item.owner_id); let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); if adt.variants().is_empty() { span_lint_and_help( diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index 2c3487a6e10f..223545fa7984 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -265,7 +265,7 @@ impl LateLintPass<'_> for EnumVariantNames { } // The `module_name_repetitions` lint should only trigger if the item has the module in its // name. Having the same name is accepted. - if cx.tcx.visibility(item.def_id).is_public() && item_camel.len() > mod_camel.len() { + if cx.tcx.visibility(item.owner_id).is_public() && item_camel.len() > mod_camel.len() { let matching = count_match_start(mod_camel, &item_camel); let rmatching = count_match_end(mod_camel, &item_camel); let nchars = mod_camel.chars().count(); @@ -296,7 +296,7 @@ impl LateLintPass<'_> for EnumVariantNames { } } if let ItemKind::Enum(ref def, _) = item.kind { - if !(self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(item.def_id.def_id)) { + if !(self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(item.owner_id.def_id)) { check_variant(cx, self.threshold, def, item_name, item.span); } } diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index c9a8307eba4f..7f1a4c4beb1f 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -88,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { // be sure we have `self` parameter in this function if trait_item.kind == (AssocItemKind::Fn { has_self: true }) { trait_self_ty = Some( - TraitRef::identity(cx.tcx, trait_item.id.def_id.to_def_id()) + TraitRef::identity(cx.tcx, trait_item.id.owner_id.to_def_id()) .self_ty() .skip_binder(), ); diff --git a/clippy_lints/src/exhaustive_items.rs b/clippy_lints/src/exhaustive_items.rs index bb07b29b0763..1fece5d1c480 100644 --- a/clippy_lints/src/exhaustive_items.rs +++ b/clippy_lints/src/exhaustive_items.rs @@ -73,7 +73,7 @@ impl LateLintPass<'_> for ExhaustiveItems { fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { if_chain! { if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind; - if cx.effective_visibilities.is_exported(item.def_id.def_id); + if cx.effective_visibilities.is_exported(item.owner_id.def_id); let attrs = cx.tcx.hir().attrs(item.hir_id()); if !attrs.iter().any(|a| a.has_name(sym::non_exhaustive)); then { diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index ef24a5d06ad0..0a633f242a5f 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom { // check for `impl From for ..` if_chain! { if let hir::ItemKind::Impl(impl_) = &item.kind; - if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id); + if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id); if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.def_id); then { lint_impl_body(cx, item.span, impl_.items); @@ -107,7 +107,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h let body = cx.tcx.hir().body(body_id); let mut fpu = FindPanicUnwrap { lcx: cx, - typeck_results: cx.tcx.typeck(impl_item.id.def_id.def_id), + typeck_results: cx.tcx.typeck(impl_item.id.owner_id.def_id), result: Vec::new(), }; fpu.visit_expr(body.value); diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index 95eda4ea8827..8b24a4962fb2 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto { && let Some(into_trait_seg) = hir_trait_ref.path.segments.last() // `impl Into for self_ty` && let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args - && let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.def_id) + && let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id) && cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id) { span_lint_and_then( diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 32cba5e608ad..3c7ab9c3182c 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -22,9 +22,9 @@ use super::{DOUBLE_MUST_USE, MUST_USE_CANDIDATE, MUST_USE_UNIT}; pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { let attrs = cx.tcx.hir().attrs(item.hir_id()); - let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use); + let attr = cx.tcx.get_attr(item.owner_id.to_def_id(), sym::must_use); if let hir::ItemKind::Fn(ref sig, _generics, ref body_id) = item.kind { - let is_public = cx.effective_visibilities.is_exported(item.def_id.def_id); + let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); if let Some(attr) = attr { check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr); @@ -34,7 +34,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_> sig.decl, cx.tcx.hir().body(*body_id), item.span, - item.def_id.def_id, + item.owner_id.def_id, item.span.with_hi(sig.decl.output.span().hi()), "this function could have a `#[must_use]` attribute", ); @@ -44,20 +44,20 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_> pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind { - let is_public = cx.effective_visibilities.is_exported(item.def_id.def_id); + let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let attrs = cx.tcx.hir().attrs(item.hir_id()); - let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use); + let attr = cx.tcx.get_attr(item.owner_id.to_def_id(), sym::must_use); if let Some(attr) = attr { check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr); - } else if is_public && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.def_id.def_id).is_none() + } else if is_public && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.owner_id.def_id).is_none() { check_must_use_candidate( cx, sig.decl, cx.tcx.hir().body(*body_id), item.span, - item.def_id.def_id, + item.owner_id.def_id, item.span.with_hi(sig.decl.output.span().hi()), "this method could have a `#[must_use]` attribute", ); @@ -67,11 +67,11 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { if let hir::TraitItemKind::Fn(ref sig, ref eid) = item.kind { - let is_public = cx.effective_visibilities.is_exported(item.def_id.def_id); + let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let attrs = cx.tcx.hir().attrs(item.hir_id()); - let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use); + let attr = cx.tcx.get_attr(item.owner_id.to_def_id(), sym::must_use); if let Some(attr) = attr { check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr); } else if let hir::TraitFn::Provided(eid) = *eid { @@ -82,7 +82,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr sig.decl, body, item.span, - item.def_id.def_id, + item.owner_id.def_id, item.span.with_hi(sig.decl.output.span().hi()), "this method could have a `#[must_use]` attribute", ); diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index 0831b5cc38bd..2c0bf551fd7e 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -31,7 +31,7 @@ pub(super) fn check_fn<'tcx>( pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { if let hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(eid)) = item.kind { let body = cx.tcx.hir().body(eid); - check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.def_id.def_id); + check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.owner_id.def_id); } } diff --git a/clippy_lints/src/functions/result.rs b/clippy_lints/src/functions/result.rs index c5ce56dd2cef..5c63fb2acb11 100644 --- a/clippy_lints/src/functions/result.rs +++ b/clippy_lints/src/functions/result.rs @@ -34,9 +34,9 @@ fn result_err_ty<'tcx>( pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, large_err_threshold: u64) { if let hir::ItemKind::Fn(ref sig, _generics, _) = item.kind - && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id.def_id, item.span) + && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.owner_id.def_id, item.span) { - if cx.effective_visibilities.is_exported(item.def_id.def_id) { + if cx.effective_visibilities.is_exported(item.owner_id.def_id) { let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); check_result_unit_err(cx, err_ty, fn_header_span); } @@ -47,10 +47,10 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, l pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::ImplItem<'tcx>, large_err_threshold: u64) { // Don't lint if method is a trait's implementation, we can't do anything about those if let hir::ImplItemKind::Fn(ref sig, _) = item.kind - && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id.def_id, item.span) - && trait_ref_of_method(cx, item.def_id.def_id).is_none() + && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.owner_id.def_id, item.span) + && trait_ref_of_method(cx, item.owner_id.def_id).is_none() { - if cx.effective_visibilities.is_exported(item.def_id.def_id) { + if cx.effective_visibilities.is_exported(item.owner_id.def_id) { let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); check_result_unit_err(cx, err_ty, fn_header_span); } @@ -61,8 +61,8 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::ImplItem pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::TraitItem<'tcx>, large_err_threshold: u64) { if let hir::TraitItemKind::Fn(ref sig, _) = item.kind { let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); - if let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id.def_id, item.span) { - if cx.effective_visibilities.is_exported(item.def_id.def_id) { + if let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.owner_id.def_id, item.span) { + if cx.effective_visibilities.is_exported(item.owner_id.def_id) { check_result_unit_err(cx, err_ty, fn_header_span); } check_result_large_err(cx, err_ty, hir_ty.span, large_err_threshold); diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 6415f35ddd03..94e06cf704ba 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { } } - if !cx.effective_visibilities.is_exported(item.def_id.def_id) { + if !cx.effective_visibilities.is_exported(item.owner_id.def_id) { return; } diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index 676136df572b..14a37f535b46 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -108,7 +108,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString { if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::String); // Filters instances of to_string which are required by a trait - if trait_ref_of_method(cx, impl_item.def_id.def_id).is_none(); + if trait_ref_of_method(cx, impl_item.owner_id.def_id).is_none(); then { show_lint(cx, impl_item); @@ -124,7 +124,7 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) { .expect("Failed to get trait ID of `Display`!"); // Get the real type of 'self' - let self_type = cx.tcx.fn_sig(item.def_id).input(0); + let self_type = cx.tcx.fn_sig(item.owner_id).input(0); let self_type = self_type.skip_binder().peel_refs(); // Emit either a warning or an error diff --git a/clippy_lints/src/iter_not_returning_iterator.rs b/clippy_lints/src/iter_not_returning_iterator.rs index ea9f046fb973..e76de77f195d 100644 --- a/clippy_lints/src/iter_not_returning_iterator.rs +++ b/clippy_lints/src/iter_not_returning_iterator.rs @@ -44,7 +44,7 @@ impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator { let name = item.ident.name.as_str(); if matches!(name, "iter" | "iter_mut") { if let TraitItemKind::Fn(fn_sig, _) = &item.kind { - check_sig(cx, name, fn_sig, item.def_id.def_id); + check_sig(cx, name, fn_sig, item.owner_id.def_id); } } } @@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator { ) { if let ImplItemKind::Fn(fn_sig, _) = &item.kind { - check_sig(cx, name, fn_sig, item.def_id.def_id); + check_sig(cx, name, fn_sig, item.owner_id.def_id); } } } diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index 8ed7e4bb196c..06e957285499 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -123,7 +123,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant { return; } if let ItemKind::Enum(ref def, _) = item.kind { - let ty = cx.tcx.type_of(item.def_id); + let ty = cx.tcx.type_of(item.owner_id); let Adt(adt, subst) = ty.kind() else { panic!("already checked whether this is an enum") }; diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 6e31812d7053..b0cba40c27a5 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero { if item.ident.name == sym::len; if let ImplItemKind::Fn(sig, _) = &item.kind; if sig.decl.implicit_self.has_implicit_self(); - if cx.effective_visibilities.is_exported(item.def_id.def_id); + if cx.effective_visibilities.is_exported(item.owner_id.def_id); if matches!(sig.decl.output, FnRetTy::Return(_)); if let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id()); if imp.of_trait.is_none(); @@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero { if let Some(local_id) = ty_id.as_local(); let ty_hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_id); if !is_lint_allowed(cx, LEN_WITHOUT_IS_EMPTY, ty_hir_id); - if let Some(output) = parse_len_output(cx, cx.tcx.fn_sig(item.def_id).skip_binder()); + if let Some(output) = parse_len_output(cx, cx.tcx.fn_sig(item.owner_id).skip_binder()); then { let (name, kind) = match cx.tcx.hir().find(ty_hir_id) { Some(Node::ForeignItem(x)) => (x.ident.name, "extern type"), @@ -195,7 +195,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items fn is_named_self(cx: &LateContext<'_>, item: &TraitItemRef, name: Symbol) -> bool { item.ident.name == name && if let AssocItemKind::Fn { has_self } = item.kind { - has_self && { cx.tcx.fn_sig(item.id.def_id).inputs().skip_binder().len() == 1 } + has_self && { cx.tcx.fn_sig(item.id.owner_id).inputs().skip_binder().len() == 1 } } else { false } @@ -210,11 +210,11 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items } } - if cx.effective_visibilities.is_exported(visited_trait.def_id.def_id) + if cx.effective_visibilities.is_exported(visited_trait.owner_id.def_id) && trait_items.iter().any(|i| is_named_self(cx, i, sym::len)) { let mut current_and_super_traits = DefIdSet::default(); - fill_trait_set(visited_trait.def_id.to_def_id(), &mut current_and_super_traits, cx); + fill_trait_set(visited_trait.owner_id.to_def_id(), &mut current_and_super_traits, cx); let is_empty = sym!(is_empty); let is_empty_method_found = current_and_super_traits diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index aef253303a8f..3bf2d7e4ea4e 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -102,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { if let ImplItemKind::Fn(ref sig, id) = item.kind { - let report_extra_lifetimes = trait_ref_of_method(cx, item.def_id.def_id).is_none(); + let report_extra_lifetimes = trait_ref_of_method(cx, item.owner_id.def_id).is_none(); check_fn_inner( cx, sig.decl, diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 6a42275322b4..6806c1466968 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -166,7 +166,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum { if let Some((id, span)) = iter.next() && iter.next().is_none() { - self.potential_enums.push((item.def_id.def_id, id, item.span, span)); + self.potential_enums.push((item.owner_id.def_id, id, item.span, span)); } } } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index adfa7426607f..8a76ba0b064b 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3250,15 +3250,15 @@ impl<'tcx> LateLintPass<'tcx> for Methods { let name = impl_item.ident.name.as_str(); let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(parent); - let self_ty = cx.tcx.type_of(item.def_id); + let self_ty = cx.tcx.type_of(item.owner_id); let implements_trait = matches!(item.kind, hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })); if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind { - let method_sig = cx.tcx.fn_sig(impl_item.def_id); + let method_sig = cx.tcx.fn_sig(impl_item.owner_id); let method_sig = cx.tcx.erase_late_bound_regions(method_sig); let first_arg_ty_opt = method_sig.inputs().iter().next().copied(); // if this impl block implements a trait, lint in trait definition instead - if !implements_trait && cx.effective_visibilities.is_exported(impl_item.def_id.def_id) { + if !implements_trait && cx.effective_visibilities.is_exported(impl_item.owner_id.def_id) { // check missing trait implementations for method_config in &TRAIT_METHODS { if name == method_config.method_name @@ -3292,7 +3292,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if sig.decl.implicit_self.has_implicit_self() && !(self.avoid_breaking_exported_api - && cx.effective_visibilities.is_exported(impl_item.def_id.def_id)) + && cx.effective_visibilities.is_exported(impl_item.owner_id.def_id)) && let Some(first_arg) = iter_input_pats(sig.decl, cx.tcx.hir().body(id)).next() && let Some(first_arg_ty) = first_arg_ty_opt { @@ -3370,7 +3370,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { then { let first_arg_span = first_arg_ty.span; let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty); - let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()) + let self_ty = TraitRef::identity(cx.tcx, item.owner_id.to_def_id()) .self_ty() .skip_binder(); wrong_self_convention::check( @@ -3389,7 +3389,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if item.ident.name == sym::new; if let TraitItemKind::Fn(_, _) = item.kind; let ret_ty = return_ty(cx, item.hir_id()); - let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()) + let self_ty = TraitRef::identity(cx.tcx, item.owner_id.to_def_id()) .self_ty() .skip_binder(); if !ret_ty.contains(self_ty); diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index b3f1553cfea9..2a63681db60e 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -131,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { hir::ItemKind::Fn(..) => { // ignore main() if it.ident.name == sym::main { - let at_root = cx.tcx.local_parent(it.def_id.def_id) == CRATE_DEF_ID; + let at_root = cx.tcx.local_parent(it.owner_id.def_id) == CRATE_DEF_ID; if at_root { return; } @@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { | hir::ItemKind::Use(..) => return, }; - let (article, desc) = cx.tcx.article_and_description(it.def_id.to_def_id()); + let (article, desc) = cx.tcx.article_and_description(it.owner_id.to_def_id()); let attrs = cx.tcx.hir().attrs(it.hir_id()); if !is_from_proc_macro(cx, it) { @@ -164,7 +164,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { } fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) { - let (article, desc) = cx.tcx.article_and_description(trait_item.def_id.to_def_id()); + let (article, desc) = cx.tcx.article_and_description(trait_item.owner_id.to_def_id()); let attrs = cx.tcx.hir().attrs(trait_item.hir_id()); if !is_from_proc_macro(cx, trait_item) { @@ -174,7 +174,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { // If the method is an impl for a trait, don't doc. - if let Some(cid) = cx.tcx.associated_item(impl_item.def_id).impl_container(cx.tcx) { + if let Some(cid) = cx.tcx.associated_item(impl_item.owner_id).impl_container(cx.tcx) { if cx.tcx.impl_trait_ref(cid).is_some() { return; } @@ -182,7 +182,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { return; } - let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id()); + let (article, desc) = cx.tcx.article_and_description(impl_item.owner_id.to_def_id()); let attrs = cx.tcx.hir().attrs(impl_item.hir_id()); if !is_from_proc_macro(cx, impl_item) { self.check_missing_docs_attrs(cx, attrs, impl_item.span, article, desc); diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index ed9da2d92173..758ce47cf114 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -88,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { return; } - if !cx.effective_visibilities.is_exported(it.def_id.def_id) { + if !cx.effective_visibilities.is_exported(it.owner_id.def_id) { return; } match it.kind { @@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { match tit_.kind { hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => {}, hir::TraitItemKind::Fn(..) => { - if cx.tcx.impl_defaultness(tit.id.def_id).has_value() { + if cx.tcx.impl_defaultness(tit.id.owner_id).has_value() { // trait method with default body needs inline in case // an impl is not provided let desc = "a default trait method"; @@ -142,7 +142,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { } // If the item being implemented is not exported, then we don't need #[inline] - if !cx.effective_visibilities.is_exported(impl_item.def_id.def_id) { + if !cx.effective_visibilities.is_exported(impl_item.owner_id.def_id) { return; } @@ -151,7 +151,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { hir::ImplItemKind::Const(..) | hir::ImplItemKind::Type(_) => return, }; - let assoc_item = cx.tcx.associated_item(impl_item.def_id); + let assoc_item = cx.tcx.associated_item(impl_item.owner_id); let container_id = assoc_item.container_id(cx.tcx); let trait_def_id = match assoc_item.container { TraitContainer => Some(container_id), @@ -159,7 +159,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { }; if let Some(trait_def_id) = trait_def_id { - if trait_def_id.is_local() && !cx.effective_visibilities.is_exported(impl_item.def_id.def_id) { + if trait_def_id.is_local() && !cx.effective_visibilities.is_exported(impl_item.owner_id.def_id) { // If a trait is being implemented for an item, and the // trait is not exported, we don't need #[inline] return; diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 25d6ca83a94b..8a2e77980b36 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'tcx>) { if let hir::ImplItemKind::Fn(ref sig, ..) = item.kind { - if trait_ref_of_method(cx, item.def_id.def_id).is_none() { + if trait_ref_of_method(cx, item.owner_id.def_id).is_none() { check_sig(cx, item.hir_id(), sig.decl); } } diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 99166c68936c..54a3c82b713d 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { // can't be implemented for unsafe new return; } - if cx.tcx.is_doc_hidden(impl_item.def_id.def_id) { + if cx.tcx.is_doc_hidden(impl_item.owner_id.def_id) { // shouldn't be implemented when it is hidden in docs return; } @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { if_chain! { if sig.decl.inputs.is_empty(); if name == sym::new; - if cx.effective_visibilities.is_reachable(impl_item.def_id.def_id); + if cx.effective_visibilities.is_reachable(impl_item.owner_id.def_id); let self_def_id = cx.tcx.hir().get_parent_item(id); let self_ty = cx.tcx.type_of(self_def_id); if self_ty == return_ty(cx, id); diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index a6742824bc56..938560b625ee 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -303,7 +303,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { if let Some(of_trait_def_id) = of_trait_ref.trait_def_id(); if let Some(of_assoc_item) = cx .tcx - .associated_item(impl_item.def_id) + .associated_item(impl_item.owner_id) .trait_item_def_id; if cx .tcx diff --git a/clippy_lints/src/non_send_fields_in_send_ty.rs b/clippy_lints/src/non_send_fields_in_send_ty.rs index ddef7352de88..714c0ff227bf 100644 --- a/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy { if let Some(trait_id) = trait_ref.trait_def_id(); if send_trait == trait_id; if hir_impl.polarity == ImplPolarity::Positive; - if let Some(ty_trait_ref) = cx.tcx.impl_trait_ref(item.def_id); + if let Some(ty_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id); if let self_ty = ty_trait_ref.self_ty(); if let ty::Adt(adt_def, impl_trait_substs) = self_ty.kind(); then { diff --git a/clippy_lints/src/only_used_in_recursion.rs b/clippy_lints/src/only_used_in_recursion.rs index d64a9cf71e17..7722a476d7b4 100644 --- a/clippy_lints/src/only_used_in_recursion.rs +++ b/clippy_lints/src/only_used_in_recursion.rs @@ -227,25 +227,25 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion { // `skip_params` is either `0` or `1` to skip the `self` parameter in trait functions. // It can't be renamed, and it can't be removed without removing it from multiple functions. let (fn_id, fn_kind, skip_params) = match get_parent_node(cx.tcx, body.value.hir_id) { - Some(Node::Item(i)) => (i.def_id.to_def_id(), FnKind::Fn, 0), + Some(Node::Item(i)) => (i.owner_id.to_def_id(), FnKind::Fn, 0), Some(Node::TraitItem(&TraitItem { kind: TraitItemKind::Fn(ref sig, _), - def_id, + owner_id, .. })) => ( - def_id.to_def_id(), + owner_id.to_def_id(), FnKind::TraitFn, usize::from(sig.decl.implicit_self.has_implicit_self()), ), Some(Node::ImplItem(&ImplItem { kind: ImplItemKind::Fn(ref sig, _), - def_id, + owner_id, .. })) => { #[allow(trivial_casts)] - if let Some(Node::Item(item)) = get_parent_node(cx.tcx, def_id.into()) - && let Some(trait_ref) = cx.tcx.impl_trait_ref(item.def_id) - && let Some(trait_item_id) = cx.tcx.associated_item(def_id).trait_item_def_id + if let Some(Node::Item(item)) = get_parent_node(cx.tcx, owner_id.into()) + && let Some(trait_ref) = cx.tcx.impl_trait_ref(item.owner_id) + && let Some(trait_item_id) = cx.tcx.associated_item(owner_id).trait_item_def_id { ( trait_item_id, @@ -253,7 +253,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion { usize::from(sig.decl.implicit_self.has_implicit_self()), ) } else { - (def_id.to_def_id(), FnKind::Fn, 0) + (owner_id.to_def_id(), FnKind::Fn, 0) } }, _ => return, diff --git a/clippy_lints/src/operators/op_ref.rs b/clippy_lints/src/operators/op_ref.rs index 1085e6089441..71b31b5e4a56 100644 --- a/clippy_lints/src/operators/op_ref.rs +++ b/clippy_lints/src/operators/op_ref.rs @@ -204,7 +204,7 @@ fn are_equal<'tcx>(cx: &LateContext<'tcx>, middle_ty: Ty<'_>, hir_ty: &rustc_hir if let ty::Adt(adt_def, _) = middle_ty.kind(); if let Some(local_did) = adt_def.did().as_local(); let item = cx.tcx.hir().expect_item(local_did); - let middle_ty_id = item.def_id.to_def_id(); + let middle_ty_id = item.owner_id.to_def_id(); if let TyKind::Path(QPath::Resolved(_, path)) = hir_ty.kind; if let Res::Def(_, hir_ty_id) = path.res; diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index 09ac514d014e..5aa3c6f2f934 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -36,7 +36,7 @@ impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if_chain! { if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), items: impl_items, .. }) = item.kind; - if !cx.tcx.has_attr(item.def_id.to_def_id(), sym::automatically_derived); + if !cx.tcx.has_attr(item.owner_id.to_def_id(), sym::automatically_derived); if let Some(eq_trait) = cx.tcx.lang_items().eq_trait(); if trait_ref.path.res.def_id() == eq_trait; then { diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index c55985275db6..f9fd3645668a 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -261,7 +261,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { } if let hir::TraitItemKind::Fn(method_sig, _) = &item.kind { - self.check_poly_fn(cx, item.def_id.def_id, method_sig.decl, None); + self.check_poly_fn(cx, item.owner_id.def_id, method_sig.decl, None); } } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 40db315bf272..0d74c90a834f 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -164,7 +164,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { check_mut_from_ref(cx, sig, None); for arg in check_fn_args( cx, - cx.tcx.fn_sig(item.def_id).skip_binder().inputs(), + cx.tcx.fn_sig(item.owner_id).skip_binder().inputs(), sig.decl.inputs, &[], ) @@ -188,7 +188,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { let (item_id, sig, is_trait_item) = match parents.next() { Some((_, Node::Item(i))) => { if let ItemKind::Fn(sig, ..) = &i.kind { - (i.def_id, sig, false) + (i.owner_id, sig, false) } else { return; } @@ -200,14 +200,14 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { return; } if let ImplItemKind::Fn(sig, _) = &i.kind { - (i.def_id, sig, false) + (i.owner_id, sig, false) } else { return; } }, Some((_, Node::TraitItem(i))) => { if let TraitItemKind::Fn(sig, _) = &i.kind { - (i.def_id, sig, true) + (i.owner_id, sig, true) } else { return; } diff --git a/clippy_lints/src/redundant_pub_crate.rs b/clippy_lints/src/redundant_pub_crate.rs index bc73613a1502..26075e9f70fa 100644 --- a/clippy_lints/src/redundant_pub_crate.rs +++ b/clippy_lints/src/redundant_pub_crate.rs @@ -46,12 +46,12 @@ impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]); impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { if_chain! { - if cx.tcx.visibility(item.def_id.def_id) == ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()); - if !cx.effective_visibilities.is_exported(item.def_id.def_id) && self.is_exported.last() == Some(&false); + if cx.tcx.visibility(item.owner_id.def_id) == ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()); + if !cx.effective_visibilities.is_exported(item.owner_id.def_id) && self.is_exported.last() == Some(&false); if is_not_macro_export(item); then { let span = item.span.with_hi(item.ident.span.hi()); - let descr = cx.tcx.def_kind(item.def_id).descr(item.def_id.to_def_id()); + let descr = cx.tcx.def_kind(item.owner_id).descr(item.owner_id.to_def_id()); span_lint_and_then( cx, REDUNDANT_PUB_CRATE, @@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { } if let ItemKind::Mod { .. } = item.kind { - self.is_exported.push(cx.effective_visibilities.is_exported(item.def_id.def_id)); + self.is_exported.push(cx.effective_visibilities.is_exported(item.owner_id.def_id)); } } diff --git a/clippy_lints/src/return_self_not_must_use.rs b/clippy_lints/src/return_self_not_must_use.rs index 7f34be5e7fd8..b77faf7322bd 100644 --- a/clippy_lints/src/return_self_not_must_use.rs +++ b/clippy_lints/src/return_self_not_must_use.rs @@ -128,7 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for ReturnSelfNotMustUse { fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'tcx>) { if let TraitItemKind::Fn(ref sig, _) = item.kind { - check_method(cx, sig.decl, item.def_id.def_id, item.span, item.hir_id()); + check_method(cx, sig.decl, item.owner_id.def_id, item.span, item.hir_id()); } } } diff --git a/clippy_lints/src/same_name_method.rs b/clippy_lints/src/same_name_method.rs index 4249063d2d47..caab5851bafc 100644 --- a/clippy_lints/src/same_name_method.rs +++ b/clippy_lints/src/same_name_method.rs @@ -52,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod { let mut map = FxHashMap::::default(); for id in cx.tcx.hir().items() { - if matches!(cx.tcx.def_kind(id.def_id), DefKind::Impl) + if matches!(cx.tcx.def_kind(id.owner_id), DefKind::Impl) && let item = cx.tcx.hir().item(id) && let ItemKind::Impl(Impl { items, diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index 1ac538f4c7c0..71b387c66a33 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(parent); - let self_ty = cx.tcx.type_of(item.def_id); + let self_ty = cx.tcx.type_of(item.owner_id); let ret_ty = return_ty(cx, impl_item.hir_id()); // Do not check trait impls diff --git a/clippy_lints/src/trailing_empty_array.rs b/clippy_lints/src/trailing_empty_array.rs index 58cc057a39ed..8cf3efc8dc73 100644 --- a/clippy_lints/src/trailing_empty_array.rs +++ b/clippy_lints/src/trailing_empty_array.rs @@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for TrailingEmptyArray { None, &format!( "consider annotating `{}` with `#[repr(C)]` or another `repr` attribute", - cx.tcx.def_path_str(item.def_id.to_def_id()) + cx.tcx.def_path_str(item.owner_id.to_def_id()) ), ); } diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 40cdcc3865ba..f6de87b0526c 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -333,7 +333,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { } fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - let is_exported = cx.effective_visibilities.is_exported(item.def_id.def_id); + let is_exported = cx.effective_visibilities.is_exported(item.owner_id.def_id); match item.kind { ItemKind::Static(ty, _, _) | ItemKind::Const(ty, _) => self.check_ty( @@ -392,7 +392,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { } fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &TraitItem<'_>) { - let is_exported = cx.effective_visibilities.is_exported(item.def_id.def_id); + let is_exported = cx.effective_visibilities.is_exported(item.owner_id.def_id); let context = CheckTyContext { is_exported, diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index 62ab927d2f5c..42bccc7212b3 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -56,12 +56,12 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf { } let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; let parent_item = cx.tcx.hir().expect_item(parent); - let assoc_item = cx.tcx.associated_item(impl_item.def_id); + let assoc_item = cx.tcx.associated_item(impl_item.owner_id); if_chain! { if let ItemKind::Impl(Impl { of_trait: None, .. }) = parent_item.kind; if assoc_item.fn_has_self_parameter; if let ImplItemKind::Fn(.., body_id) = &impl_item.kind; - if !cx.effective_visibilities.is_exported(impl_item.def_id.def_id) || !self.avoid_breaking_exported_api; + if !cx.effective_visibilities.is_exported(impl_item.owner_id.def_id) || !self.avoid_breaking_exported_api; let body = cx.tcx.hir().body(*body_id); if let [self_param, ..] = body.params; if !is_local_used(cx, body, self_param.pat.hir_id); diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs index a69719b127b2..f3611d174340 100644 --- a/clippy_lints/src/unwrap_in_result.rs +++ b/clippy_lints/src/unwrap_in_result.rs @@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for UnwrapInResult { fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_item: &'tcx hir::ImplItem<'_>) { if let ImplItemKind::Fn(_, body_id) = impl_item.kind { let body = cx.tcx.hir().body(body_id); - let typeck = cx.tcx.typeck(impl_item.def_id.def_id); + let typeck = cx.tcx.typeck(impl_item.owner_id.def_id); let mut result = Vec::new(); let _: Option = for_each_expr(body.value, |e| { // check for `expect` diff --git a/clippy_lints/src/upper_case_acronyms.rs b/clippy_lints/src/upper_case_acronyms.rs index 7a20148c70a5..1d2d3eb12e11 100644 --- a/clippy_lints/src/upper_case_acronyms.rs +++ b/clippy_lints/src/upper_case_acronyms.rs @@ -105,7 +105,7 @@ impl LateLintPass<'_> for UpperCaseAcronyms { fn check_item(&mut self, cx: &LateContext<'_>, it: &Item<'_>) { // do not lint public items or in macros if in_external_macro(cx.sess(), it.span) - || (self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(it.def_id.def_id)) + || (self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(it.owner_id.def_id)) { return; } diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 65f1b5462081..c6cdf3f85fc3 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -106,7 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { if !is_from_proc_macro(cx, item); // expensive, should be last check then { StackItem::Check { - impl_id: item.def_id.def_id, + impl_id: item.owner_id.def_id, in_body: 0, types_to_skip: std::iter::once(self_ty.hir_id).collect(), } @@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { // trait, not in the impl of the trait. let trait_method = cx .tcx - .associated_item(impl_item.def_id) + .associated_item(impl_item.owner_id) .trait_item_def_id .expect("impl method matches a trait method"); let trait_method_sig = cx.tcx.fn_sig(trait_method); diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 301eed9a1fbf..be98344470b9 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -120,14 +120,14 @@ impl LateLintPass<'_> for WildcardImports { if is_test_module_or_function(cx.tcx, item) { self.test_modules_deep = self.test_modules_deep.saturating_add(1); } - let module = cx.tcx.parent_module_from_def_id(item.def_id.def_id); - if cx.tcx.visibility(item.def_id.def_id) != ty::Visibility::Restricted(module.to_def_id()) { + let module = cx.tcx.parent_module_from_def_id(item.owner_id.def_id); + if cx.tcx.visibility(item.owner_id.def_id) != ty::Visibility::Restricted(module.to_def_id()) { return; } if_chain! { if let ItemKind::Use(use_path, UseKind::Glob) = &item.kind; if self.warn_on_all || !self.check_exceptions(item, use_path.segments); - let used_imports = cx.tcx.names_imported_by_glob_use(item.def_id.def_id); + let used_imports = cx.tcx.names_imported_by_glob_use(item.owner_id.def_id); if !used_imports.is_empty(); // Already handled by `unused_imports` then { let mut applicability = Applicability::MachineApplicable; diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 052db3f3a039..3ebfc5e00e14 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -2281,7 +2281,7 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalDefId, f: impl Fn(&[Symbol Entry::Vacant(entry) => { let mut names = Vec::new(); for id in tcx.hir().module_items(module) { - if matches!(tcx.def_kind(id.def_id), DefKind::Const) + if matches!(tcx.def_kind(id.owner_id), DefKind::Const) && let item = tcx.hir().item(id) && let ItemKind::Const(ty, _body) = item.kind { if let TyKind::Path(QPath::Resolved(_, path)) = ty.kind { From 5b802d1241f71ca58e2975cde69558745e5bd747 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Wed, 26 Oct 2022 17:01:00 -0500 Subject: [PATCH 0658/1222] Use LanguageItems::require less --- clippy_lints/src/lifetimes.rs | 15 +++++---------- clippy_lints/src/manual_retain.rs | 2 +- clippy_lints/src/methods/bind_instead_of_map.rs | 8 ++++---- .../src/methods/unnecessary_iter_cloned.rs | 4 ++-- clippy_lints/src/methods/unnecessary_to_owned.rs | 4 ++-- clippy_lints/src/operators/assign_op_pattern.rs | 2 +- clippy_lints/src/suspicious_trait_impl.rs | 6 +++--- .../src/unnecessary_owned_empty_strings.rs | 4 ++-- clippy_lints/src/unused_peekable.rs | 5 ++--- clippy_lints/src/useless_conversion.rs | 4 ++-- .../utils/internal_lints/unnecessary_def_path.rs | 4 ++-- clippy_utils/src/lib.rs | 4 ++-- clippy_utils/src/ty.rs | 6 +----- 13 files changed, 29 insertions(+), 39 deletions(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 3bf2d7e4ea4e..54c316358a14 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -6,11 +6,12 @@ use rustc_hir::intravisit::{ walk_fn_decl, walk_generic_param, walk_generics, walk_impl_item_ref, walk_item, walk_param_bound, walk_poly_trait_ref, walk_trait_ref, walk_ty, Visitor, }; +use rustc_hir::lang_items; use rustc_hir::FnRetTy::Return; use rustc_hir::{ BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl, ImplItem, - ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, ParamName, PolyTraitRef, PredicateOrigin, TraitFn, - TraitItem, TraitItemKind, Ty, TyKind, WherePredicate, + ImplItemKind, Item, ItemKind, Lifetime, LifetimeName, ParamName, PolyTraitRef, PredicateOrigin, TraitFn, TraitItem, + TraitItemKind, Ty, TyKind, WherePredicate, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter as middle_nested_filter; @@ -364,8 +365,6 @@ fn unique_lifetimes(lts: &[RefLt]) -> usize { lts.iter().collect::>().len() } -const CLOSURE_TRAIT_BOUNDS: [LangItem; 3] = [LangItem::Fn, LangItem::FnMut, LangItem::FnOnce]; - /// A visitor usable for `rustc_front::visit::walk_ty()`. struct RefVisitor<'a, 'tcx> { cx: &'a LateContext<'tcx>, @@ -424,12 +423,8 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { fn visit_poly_trait_ref(&mut self, poly_tref: &'tcx PolyTraitRef<'tcx>) { let trait_ref = &poly_tref.trait_ref; - if CLOSURE_TRAIT_BOUNDS.iter().any(|&item| { - self.cx - .tcx - .lang_items() - .require(item) - .map_or(false, |id| Some(id) == trait_ref.trait_def_id()) + if let Some(id) = trait_ref.trait_def_id() && lang_items::FN_TRAITS.iter().any(|&item| { + self.cx.tcx.lang_items().get(item) == Some(id) }) { let mut sub_visitor = RefVisitor::new(self.cx); sub_visitor.visit_trait_ref(trait_ref); diff --git a/clippy_lints/src/manual_retain.rs b/clippy_lints/src/manual_retain.rs index 3181bc86d179..6abbab278feb 100644 --- a/clippy_lints/src/manual_retain.rs +++ b/clippy_lints/src/manual_retain.rs @@ -92,7 +92,7 @@ fn check_into_iter( && match_def_path(cx, filter_def_id, &paths::CORE_ITER_FILTER) && let hir::ExprKind::MethodCall(_, struct_expr, [], _) = &into_iter_expr.kind && let Some(into_iter_def_id) = cx.typeck_results().type_dependent_def_id(into_iter_expr.hir_id) - && cx.tcx.lang_items().require(hir::LangItem::IntoIterIntoIter).ok() == Some(into_iter_def_id) + && Some(into_iter_def_id) == cx.tcx.lang_items().into_iter_fn() && match_acceptable_type(cx, left_expr, msrv) && SpanlessEq::new(cx).eq_expr(left_expr, struct_expr) { suggest(cx, parent_expr, left_expr, target_expr); diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs index cc26b0f7fa82..4720a6e6888b 100644 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/clippy_lints/src/methods/bind_instead_of_map.rs @@ -41,7 +41,7 @@ pub(crate) trait BindInsteadOfMap { const GOOD_METHOD_NAME: &'static str; fn no_op_msg(cx: &LateContext<'_>) -> Option { - let variant_id = cx.tcx.lang_items().require(Self::VARIANT_LANG_ITEM).ok()?; + let variant_id = cx.tcx.lang_items().get(Self::VARIANT_LANG_ITEM)?; let item_id = cx.tcx.parent(variant_id); Some(format!( "using `{}.{}({})`, which is a no-op", @@ -52,7 +52,7 @@ pub(crate) trait BindInsteadOfMap { } fn lint_msg(cx: &LateContext<'_>) -> Option { - let variant_id = cx.tcx.lang_items().require(Self::VARIANT_LANG_ITEM).ok()?; + let variant_id = cx.tcx.lang_items().get(Self::VARIANT_LANG_ITEM)?; let item_id = cx.tcx.parent(variant_id); Some(format!( "using `{}.{}(|x| {}(y))`, which is more succinctly expressed as `{}(|x| y)`", @@ -144,7 +144,7 @@ pub(crate) trait BindInsteadOfMap { fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>) -> bool { if_chain! { if let Some(adt) = cx.typeck_results().expr_ty(recv).ty_adt_def(); - if let Ok(vid) = cx.tcx.lang_items().require(Self::VARIANT_LANG_ITEM); + if let Some(vid) = cx.tcx.lang_items().get(Self::VARIANT_LANG_ITEM); if adt.did() == cx.tcx.parent(vid); then {} else { return false; } } @@ -181,7 +181,7 @@ pub(crate) trait BindInsteadOfMap { fn is_variant(cx: &LateContext<'_>, res: Res) -> bool { if let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Fn), id) = res { - if let Ok(variant_id) = cx.tcx.lang_items().require(Self::VARIANT_LANG_ITEM) { + if let Some(variant_id) = cx.tcx.lang_items().get(Self::VARIANT_LANG_ITEM) { return cx.tcx.parent(id) == variant_id; } } diff --git a/clippy_lints/src/methods/unnecessary_iter_cloned.rs b/clippy_lints/src/methods/unnecessary_iter_cloned.rs index 1966a85f7a73..4eb579af7a12 100644 --- a/clippy_lints/src/methods/unnecessary_iter_cloned.rs +++ b/clippy_lints/src/methods/unnecessary_iter_cloned.rs @@ -5,7 +5,7 @@ use clippy_utils::source::snippet_opt; use clippy_utils::ty::{get_associated_type, get_iterator_item_ty, implements_trait}; use clippy_utils::{fn_def_id, get_parent_expr}; use rustc_errors::Applicability; -use rustc_hir::{def_id::DefId, Expr, ExprKind, LangItem}; +use rustc_hir::{def_id::DefId, Expr, ExprKind}; use rustc_lint::LateContext; use rustc_span::{sym, Symbol}; @@ -100,5 +100,5 @@ pub fn check_for_loop_iter( /// Returns true if the named method is `IntoIterator::into_iter`. pub fn is_into_iter(cx: &LateContext<'_>, callee_def_id: DefId) -> bool { - cx.tcx.lang_items().require(LangItem::IntoIterIntoIter) == Ok(callee_def_id) + Some(callee_def_id) == cx.tcx.lang_items().into_iter_fn() } diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 3566fe9a0bbc..642a64ae77b6 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -7,7 +7,7 @@ use clippy_utils::visitors::find_all_ret_expressions; use clippy_utils::{fn_def_id, get_parent_expr, is_diag_item_method, is_diag_trait_item, return_ty}; use clippy_utils::{meets_msrv, msrvs}; use rustc_errors::Applicability; -use rustc_hir::{def_id::DefId, BorrowKind, Expr, ExprKind, ItemKind, LangItem, Node}; +use rustc_hir::{def_id::DefId, BorrowKind, Expr, ExprKind, ItemKind, Node}; use rustc_hir_typeck::{FnCtxt, Inherited}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; @@ -378,7 +378,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< Node::Expr(parent_expr) => { if let Some((callee_def_id, call_substs, recv, call_args)) = get_callee_substs_and_args(cx, parent_expr) { - if cx.tcx.lang_items().require(LangItem::IntoFutureIntoFuture) == Ok(callee_def_id) { + if Some(callee_def_id) == cx.tcx.lang_items().into_future_fn() { return false; } diff --git a/clippy_lints/src/operators/assign_op_pattern.rs b/clippy_lints/src/operators/assign_op_pattern.rs index ee9fd94064c0..9bbf385fb599 100644 --- a/clippy_lints/src/operators/assign_op_pattern.rs +++ b/clippy_lints/src/operators/assign_op_pattern.rs @@ -28,7 +28,7 @@ pub(super) fn check<'tcx>( let rty = cx.typeck_results().expr_ty(rhs); if_chain! { if let Some((_, lang_item)) = binop_traits(op.node); - if let Ok(trait_id) = cx.tcx.lang_items().require(lang_item); + if let Some(trait_id) = cx.tcx.lang_items().get(lang_item); let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id).def_id; if trait_ref_of_method(cx, parent_fn) .map_or(true, |t| t.path.res.def_id() != trait_id); diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index b57b484bdc89..6271ea027314 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -60,8 +60,8 @@ impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl { if_chain! { if let hir::ExprKind::Binary(binop, _, _) | hir::ExprKind::AssignOp(binop, ..) = expr.kind; if let Some((binop_trait_lang, op_assign_trait_lang)) = binop_traits(binop.node); - if let Ok(binop_trait_id) = cx.tcx.lang_items().require(binop_trait_lang); - if let Ok(op_assign_trait_id) = cx.tcx.lang_items().require(op_assign_trait_lang); + if let Some(binop_trait_id) = cx.tcx.lang_items().get(binop_trait_lang); + if let Some(op_assign_trait_id) = cx.tcx.lang_items().get(op_assign_trait_lang); // Check for more than one binary operation in the implemented function // Linting when multiple operations are involved can result in false positives @@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl { (&OP_ASSIGN_TRAITS, SUSPICIOUS_OP_ASSIGN_IMPL), ] .iter() - .find(|&(ts, _)| ts.iter().any(|&t| Ok(trait_id) == cx.tcx.lang_items().require(t))); + .find(|&(ts, _)| ts.iter().any(|&t| Some(trait_id) == cx.tcx.lang_items().get(t))); if count_binops(body.value) == 1; then { span_lint( diff --git a/clippy_lints/src/unnecessary_owned_empty_strings.rs b/clippy_lints/src/unnecessary_owned_empty_strings.rs index 016aacbf9da3..ab73f0fc44f4 100644 --- a/clippy_lints/src/unnecessary_owned_empty_strings.rs +++ b/clippy_lints/src/unnecessary_owned_empty_strings.rs @@ -3,7 +3,7 @@ use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; -use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability}; +use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryOwnedEmptyStrings { ); } else { if_chain! { - if cx.tcx.lang_items().require(LangItem::FromFrom).ok() == Some(fun_def_id); + if Some(fun_def_id) == cx.tcx.lang_items().from_fn(); if let [.., last_arg] = args; if let ExprKind::Lit(spanned) = &last_arg.kind; if let LitKind::Str(symbol, _) = spanned.node; diff --git a/clippy_lints/src/unused_peekable.rs b/clippy_lints/src/unused_peekable.rs index f1cebf0f9923..b452be084094 100644 --- a/clippy_lints/src/unused_peekable.rs +++ b/clippy_lints/src/unused_peekable.rs @@ -3,7 +3,6 @@ use clippy_utils::ty::{match_type, peel_mid_ty_refs_is_mutable}; use clippy_utils::{fn_def_id, is_trait_method, path_to_local_id, paths, peel_ref_operators}; use rustc_ast::Mutability; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::lang_items::LangItem; use rustc_hir::{Block, Expr, ExprKind, HirId, Local, Node, PatKind, PathSegment, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter::OnlyBodies; @@ -132,11 +131,11 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> { // If the Peekable is passed to a function, stop ExprKind::Call(_, args) => { if let Some(func_did) = fn_def_id(self.cx, expr) - && let Ok(into_iter_did) = self + && let Some(into_iter_did) = self .cx .tcx .lang_items() - .require(LangItem::IntoIterIntoIter) + .into_iter_fn() && func_did == into_iter_did { // Probably a for loop desugar, stop searching diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 1f69db1cbca4..3743d5d97a73 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -5,7 +5,7 @@ use clippy_utils::ty::{is_type_diagnostic_item, same_type_and_consts}; use clippy_utils::{get_parent_expr, is_trait_method, match_def_path, paths}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, HirId, LangItem, MatchSource}; +use rustc_hir::{Expr, ExprKind, HirId, MatchSource}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -153,7 +153,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { } if_chain! { - if cx.tcx.lang_items().require(LangItem::FromFrom).ok() == Some(def_id); + if Some(def_id) == cx.tcx.lang_items().from_fn(); if same_type_and_consts(a, b); then { diff --git a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs index 4cf76f536255..2a028c8141fc 100644 --- a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs +++ b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs @@ -152,7 +152,7 @@ impl UnnecessaryDefPath { has_ctor, ), (0, Item::LangItem(item)) => ( - format!("{cx_snip}.tcx.lang_items().require(LangItem::{item}).ok() == Some({def_snip})"), + format!("{cx_snip}.tcx.lang_items().get(LangItem::{item}) == Some({def_snip})"), has_ctor, ), // match_trait_method @@ -184,7 +184,7 @@ impl UnnecessaryDefPath { (3, Item::LangItem(item)) => ( format!( "path_res({cx_snip}, {def_snip}).opt_def_id()\ - .map_or(false, |id| {cx_snip}.tcx.lang_items().require(LangItem::{item}).ok() == Some(id))", + .map_or(false, |id| {cx_snip}.tcx.lang_items().get(LangItem::{item}) == Some(id))", ), false, ), diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 3ebfc5e00e14..d32cf1a79367 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -247,7 +247,7 @@ pub fn in_constant(cx: &LateContext<'_>, id: HirId) -> bool { /// For example, use this to check whether a function call or a pattern is `Some(..)`. pub fn is_res_lang_ctor(cx: &LateContext<'_>, res: Res, lang_item: LangItem) -> bool { if let Res::Def(DefKind::Ctor(..), id) = res - && let Ok(lang_id) = cx.tcx.lang_items().require(lang_item) + && let Some(lang_id) = cx.tcx.lang_items().get(lang_item) && let Some(id) = cx.tcx.opt_parent(id) { id == lang_id @@ -303,7 +303,7 @@ pub fn is_lang_item_or_ctor(cx: &LateContext<'_>, did: DefId, item: LangItem) -> _ => did, }; - cx.tcx.lang_items().require(item).map_or(false, |id| id == did) + cx.tcx.lang_items().get(item) == Some(did) } pub fn is_unit_expr(expr: &Expr<'_>) -> bool { diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 4e024ce40179..3a144c2bb223 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -318,11 +318,7 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symb /// Returns `false` if the `LangItem` is not defined. pub fn is_type_lang_item(cx: &LateContext<'_>, ty: Ty<'_>, lang_item: hir::LangItem) -> bool { match ty.kind() { - ty::Adt(adt, _) => cx - .tcx - .lang_items() - .require(lang_item) - .map_or(false, |li| li == adt.did()), + ty::Adt(adt, _) => cx.tcx.lang_items().get(lang_item) == Some(adt.did()), _ => false, } } From 862520feb5b69a90ce576551f619b6686ae3d3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20=C3=96zkan?= Date: Fri, 28 Oct 2022 10:20:51 +0300 Subject: [PATCH 0659/1222] improve `filesearch::get_or_default_sysroot` r=ozkanonur MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onur Özkan --- src/driver.rs | 79 ++++----------------------------------------------- 1 file changed, 5 insertions(+), 74 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index b12208ac62a8..46afea2c4b5a 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -23,8 +23,8 @@ use std::borrow::Cow; use std::env; use std::ops::Deref; use std::panic; -use std::path::{Path, PathBuf}; -use std::process::{exit, Command}; +use std::path::Path; +use std::process::exit; use std::sync::LazyLock; /// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If @@ -209,17 +209,6 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { interface::try_print_query_stack(&handler, num_frames); } -fn toolchain_path(home: Option, toolchain: Option) -> Option { - home.and_then(|home| { - toolchain.map(|toolchain| { - let mut path = PathBuf::from(home); - path.push("toolchains"); - path.push(toolchain); - path - }) - }) -} - #[allow(clippy::too_many_lines)] pub fn main() { rustc_driver::init_rustc_env_logger(); @@ -227,51 +216,6 @@ pub fn main() { exit(rustc_driver::catch_with_exit_code(move || { let mut orig_args: Vec = env::args().collect(); - // Get the sysroot, looking from most specific to this invocation to the least: - // - command line - // - runtime environment - // - SYSROOT - // - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN - // - sysroot from rustc in the path - // - compile-time environment - // - SYSROOT - // - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN - let sys_root_arg = arg_value(&orig_args, "--sysroot", |_| true); - let have_sys_root_arg = sys_root_arg.is_some(); - let sys_root = sys_root_arg - .map(PathBuf::from) - .or_else(|| std::env::var("SYSROOT").ok().map(PathBuf::from)) - .or_else(|| { - let home = std::env::var("RUSTUP_HOME") - .or_else(|_| std::env::var("MULTIRUST_HOME")) - .ok(); - let toolchain = std::env::var("RUSTUP_TOOLCHAIN") - .or_else(|_| std::env::var("MULTIRUST_TOOLCHAIN")) - .ok(); - toolchain_path(home, toolchain) - }) - .or_else(|| { - Command::new("rustc") - .arg("--print") - .arg("sysroot") - .output() - .ok() - .and_then(|out| String::from_utf8(out.stdout).ok()) - .map(|s| PathBuf::from(s.trim())) - }) - .or_else(|| option_env!("SYSROOT").map(PathBuf::from)) - .or_else(|| { - let home = option_env!("RUSTUP_HOME") - .or(option_env!("MULTIRUST_HOME")) - .map(ToString::to_string); - let toolchain = option_env!("RUSTUP_TOOLCHAIN") - .or(option_env!("MULTIRUST_TOOLCHAIN")) - .map(ToString::to_string); - toolchain_path(home, toolchain) - }) - .map(|pb| pb.to_string_lossy().to_string()) - .expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust"); - // make "clippy-driver --rustc" work like a subcommand that passes further args to "rustc" // for example `clippy-driver --rustc --version` will print the rustc version that clippy-driver // uses @@ -279,13 +223,7 @@ pub fn main() { orig_args.remove(pos); orig_args[0] = "rustc".to_string(); - // if we call "rustc", we need to pass --sysroot here as well - let mut args: Vec = orig_args.clone(); - if !have_sys_root_arg { - args.extend(vec!["--sysroot".into(), sys_root]); - }; - - return rustc_driver::RunCompiler::new(&args, &mut DefaultCallbacks).run(); + return rustc_driver::RunCompiler::new(&orig_args, &mut DefaultCallbacks).run(); } if orig_args.iter().any(|a| a == "--version" || a == "-V") { @@ -308,14 +246,6 @@ pub fn main() { exit(0); } - // this conditional check for the --sysroot flag is there so users can call - // `clippy_driver` directly - // without having to pass --sysroot or anything - let mut args: Vec = orig_args.clone(); - if !have_sys_root_arg { - args.extend(vec!["--sysroot".into(), sys_root]); - }; - let mut no_deps = false; let clippy_args_var = env::var("CLIPPY_ARGS").ok(); let clippy_args = clippy_args_var @@ -344,10 +274,11 @@ pub fn main() { let clippy_enabled = !cap_lints_allow && (!no_deps || in_primary_package); if clippy_enabled { + let mut args: Vec = orig_args.clone(); args.extend(clippy_args); rustc_driver::RunCompiler::new(&args, &mut ClippyCallbacks { clippy_args_var }).run() } else { - rustc_driver::RunCompiler::new(&args, &mut RustcCallbacks { clippy_args_var }).run() + rustc_driver::RunCompiler::new(&orig_args, &mut RustcCallbacks { clippy_args_var }).run() } })) } From b996632f507f02eac7216ffa71ae31a69f1d14db Mon Sep 17 00:00:00 2001 From: yukang Date: Wed, 9 Nov 2022 19:23:23 +0800 Subject: [PATCH 0660/1222] bless clippy --- tests/ui/crashes/ice-6250.stderr | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/ui/crashes/ice-6250.stderr b/tests/ui/crashes/ice-6250.stderr index 878897c410cf..4506d1550bd4 100644 --- a/tests/ui/crashes/ice-6250.stderr +++ b/tests/ui/crashes/ice-6250.stderr @@ -23,6 +23,11 @@ error[E0308]: mismatched types | LL | Some(reference) = cache.data.get(key) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()` + | +help: consider adding `let` + | +LL | let Some(reference) = cache.data.get(key) { + | +++ error: aborting due to 3 previous errors From e3fb5045e3f4abd85a2c5e7a3667e6b7890636fc Mon Sep 17 00:00:00 2001 From: clubby789 Date: Mon, 31 Oct 2022 18:30:09 +0000 Subject: [PATCH 0661/1222] Introduce `ExprKind::IncludedBytes` --- clippy_utils/src/sugg.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index aad7da61a8a5..eefba8cd29c4 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -207,6 +207,7 @@ impl<'a> Sugg<'a> { | ast::ExprKind::InlineAsm(..) | ast::ExprKind::ConstBlock(..) | ast::ExprKind::Lit(..) + | ast::ExprKind::IncludedBytes(..) | ast::ExprKind::Loop(..) | ast::ExprKind::MacCall(..) | ast::ExprKind::MethodCall(..) From 4e30f78fccf73fcc5b6663441c89b77c6e36fa78 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 6 Nov 2022 19:46:55 +0000 Subject: [PATCH 0662/1222] Store a LocalDefId in hir::Variant & hir::Field. --- clippy_lints/src/manual_non_exhaustive.rs | 6 +++--- clippy_lints/src/missing_doc.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 6806c1466968..4877cee0cc1e 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -157,10 +157,10 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum { && def.variants.len() > 1 { let mut iter = def.variants.iter().filter_map(|v| { - let id = cx.tcx.hir().local_def_id(v.id); - (matches!(v.data, hir::VariantData::Unit(_)) + let id = cx.tcx.hir().local_def_id(v.hir_id); + (matches!(v.data, hir::VariantData::Unit(..)) && v.ident.as_str().starts_with('_') - && is_doc_hidden(cx.tcx.hir().attrs(v.id))) + && is_doc_hidden(cx.tcx.hir().attrs(v.hir_id))) .then_some((id, v.span)) }); if let Some((id, span)) = iter.next() diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 2a63681db60e..6fd100762b49 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -199,7 +199,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { } fn check_variant(&mut self, cx: &LateContext<'tcx>, v: &'tcx hir::Variant<'_>) { - let attrs = cx.tcx.hir().attrs(v.id); + let attrs = cx.tcx.hir().attrs(v.hir_id); if !is_from_proc_macro(cx, v) { self.check_missing_docs_attrs(cx, attrs, v.span, "a", "variant"); } From d57b919fac45557889b03e7d3efa9ff054d5c8c3 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sun, 13 Nov 2022 22:58:20 +0000 Subject: [PATCH 0663/1222] Fix clippy and rustdoc please, please, don't match on `Symbol::as_str`s, every time you do, somewhere in the world another waffle becomes sad... --- clippy_utils/src/macros.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs index 9a682fbe604f..d13b34a66cca 100644 --- a/clippy_utils/src/macros.rs +++ b/clippy_utils/src/macros.rs @@ -199,12 +199,12 @@ pub fn first_node_in_macro(cx: &LateContext<'_>, node: &impl HirNode) -> Option< pub fn is_panic(cx: &LateContext<'_>, def_id: DefId) -> bool { let Some(name) = cx.tcx.get_diagnostic_name(def_id) else { return false }; matches!( - name.as_str(), - "core_panic_macro" - | "std_panic_macro" - | "core_panic_2015_macro" - | "std_panic_2015_macro" - | "core_panic_2021_macro" + name, + sym::core_panic_macro + | sym::std_panic_macro + | sym::core_panic_2015_macro + | sym::std_panic_2015_macro + | sym::core_panic_2021_macro ) } From 03d2eb419613f67075aa26ccd44c4836dd63dec8 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 10 Oct 2022 13:40:56 +1100 Subject: [PATCH 0664/1222] Use `token::Lit` in `ast::ExprKind::Lit`. Instead of `ast::Lit`. Literal lowering now happens at two different times. Expression literals are lowered when HIR is crated. Attribute literals are lowered during parsing. This commit changes the language very slightly. Some programs that used to not compile now will compile. This is because some invalid literals that are removed by `cfg` or attribute macros will no longer trigger errors. See this comment for more details: https://github.com/rust-lang/rust/pull/102944#issuecomment-1277476773 --- .../src/almost_complete_letter_range.rs | 19 +++++++--- clippy_lints/src/int_plus_one.rs | 23 ++++++------ clippy_lints/src/literal_representation.rs | 36 ++++++++++--------- clippy_lints/src/misc_early/literal_suffix.rs | 8 ++--- .../src/misc_early/mixed_case_hex_literals.rs | 6 ++-- clippy_lints/src/misc_early/mod.rs | 24 +++++++------ .../src/misc_early/zero_prefixed_literal.rs | 10 +++--- clippy_lints/src/octal_escapes.rs | 10 +++--- clippy_lints/src/precedence.rs | 5 +-- clippy_lints/src/unused_rounding.rs | 18 +++++----- clippy_utils/src/ast_utils.rs | 2 +- clippy_utils/src/numeric_literal.rs | 6 +--- 12 files changed, 90 insertions(+), 77 deletions(-) diff --git a/clippy_lints/src/almost_complete_letter_range.rs b/clippy_lints/src/almost_complete_letter_range.rs index 073e4af1318e..df92579a85df 100644 --- a/clippy_lints/src/almost_complete_letter_range.rs +++ b/clippy_lints/src/almost_complete_letter_range.rs @@ -73,12 +73,21 @@ impl EarlyLintPass for AlmostCompleteLetterRange { } fn check_range(cx: &EarlyContext<'_>, span: Span, start: &Expr, end: &Expr, sugg: Option<(Span, &str)>) { - if let ExprKind::Lit(start_lit) = &start.peel_parens().kind - && let ExprKind::Lit(end_lit) = &end.peel_parens().kind + if let ExprKind::Lit(start_token_lit) = start.peel_parens().kind + && let ExprKind::Lit(end_token_lit) = end.peel_parens().kind && matches!( - (&start_lit.kind, &end_lit.kind), - (LitKind::Byte(b'a') | LitKind::Char('a'), LitKind::Byte(b'z') | LitKind::Char('z')) - | (LitKind::Byte(b'A') | LitKind::Char('A'), LitKind::Byte(b'Z') | LitKind::Char('Z')) + ( + LitKind::from_token_lit(start_token_lit), + LitKind::from_token_lit(end_token_lit), + ), + ( + Ok(LitKind::Byte(b'a') | LitKind::Char('a')), + Ok(LitKind::Byte(b'z') | LitKind::Char('z')) + ) + | ( + Ok(LitKind::Byte(b'A') | LitKind::Char('A')), + Ok(LitKind::Byte(b'Z') | LitKind::Char('Z')), + ) ) && !in_external_macro(cx.sess(), span) { diff --git a/clippy_lints/src/int_plus_one.rs b/clippy_lints/src/int_plus_one.rs index 33491da3fc5a..f793abdfda34 100644 --- a/clippy_lints/src/int_plus_one.rs +++ b/clippy_lints/src/int_plus_one.rs @@ -2,7 +2,8 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_opt; -use rustc_ast::ast::{BinOpKind, Expr, ExprKind, Lit, LitKind}; +use rustc_ast::ast::{BinOpKind, Expr, ExprKind, LitKind}; +use rustc_ast::token; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -52,8 +53,8 @@ enum Side { impl IntPlusOne { #[expect(clippy::cast_sign_loss)] - fn check_lit(lit: &Lit, target_value: i128) -> bool { - if let LitKind::Int(value, ..) = lit.kind { + fn check_lit(token_lit: token::Lit, target_value: i128) -> bool { + if let Ok(LitKind::Int(value, ..)) = LitKind::from_token_lit(token_lit) { return value == (target_value as u128); } false @@ -65,11 +66,11 @@ impl IntPlusOne { (BinOpKind::Ge, &ExprKind::Binary(ref lhskind, ref lhslhs, ref lhsrhs), _) => { match (lhskind.node, &lhslhs.kind, &lhsrhs.kind) { // `-1 + x` - (BinOpKind::Add, &ExprKind::Lit(ref lit), _) if Self::check_lit(lit, -1) => { + (BinOpKind::Add, &ExprKind::Lit(lit), _) if Self::check_lit(lit, -1) => { Self::generate_recommendation(cx, binop, lhsrhs, rhs, Side::Lhs) }, // `x - 1` - (BinOpKind::Sub, _, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 1) => { + (BinOpKind::Sub, _, &ExprKind::Lit(lit)) if Self::check_lit(lit, 1) => { Self::generate_recommendation(cx, binop, lhslhs, rhs, Side::Lhs) }, _ => None, @@ -81,10 +82,10 @@ impl IntPlusOne { { match (&rhslhs.kind, &rhsrhs.kind) { // `y + 1` and `1 + y` - (&ExprKind::Lit(ref lit), _) if Self::check_lit(lit, 1) => { + (&ExprKind::Lit(lit), _) if Self::check_lit(lit, 1) => { Self::generate_recommendation(cx, binop, rhsrhs, lhs, Side::Rhs) }, - (_, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 1) => { + (_, &ExprKind::Lit(lit)) if Self::check_lit(lit, 1) => { Self::generate_recommendation(cx, binop, rhslhs, lhs, Side::Rhs) }, _ => None, @@ -96,10 +97,10 @@ impl IntPlusOne { { match (&lhslhs.kind, &lhsrhs.kind) { // `1 + x` and `x + 1` - (&ExprKind::Lit(ref lit), _) if Self::check_lit(lit, 1) => { + (&ExprKind::Lit(lit), _) if Self::check_lit(lit, 1) => { Self::generate_recommendation(cx, binop, lhsrhs, rhs, Side::Lhs) }, - (_, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 1) => { + (_, &ExprKind::Lit(lit)) if Self::check_lit(lit, 1) => { Self::generate_recommendation(cx, binop, lhslhs, rhs, Side::Lhs) }, _ => None, @@ -109,11 +110,11 @@ impl IntPlusOne { (BinOpKind::Le, _, &ExprKind::Binary(ref rhskind, ref rhslhs, ref rhsrhs)) => { match (rhskind.node, &rhslhs.kind, &rhsrhs.kind) { // `-1 + y` - (BinOpKind::Add, &ExprKind::Lit(ref lit), _) if Self::check_lit(lit, -1) => { + (BinOpKind::Add, &ExprKind::Lit(lit), _) if Self::check_lit(lit, -1) => { Self::generate_recommendation(cx, binop, rhsrhs, lhs, Side::Rhs) }, // `y - 1` - (BinOpKind::Sub, _, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 1) => { + (BinOpKind::Sub, _, &ExprKind::Lit(lit)) if Self::check_lit(lit, 1) => { Self::generate_recommendation(cx, binop, rhslhs, lhs, Side::Rhs) }, _ => None, diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index 25f19b9c6e6c..3a7b7835c990 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -5,11 +5,13 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::numeric_literal::{NumericLiteral, Radix}; use clippy_utils::source::snippet_opt; use if_chain::if_chain; -use rustc_ast::ast::{Expr, ExprKind, Lit, LitKind}; +use rustc_ast::ast::{Expr, ExprKind, LitKind}; +use rustc_ast::token; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::Span; use std::iter; declare_clippy_lint! { @@ -236,8 +238,8 @@ impl EarlyLintPass for LiteralDigitGrouping { return; } - if let ExprKind::Lit(ref lit) = expr.kind { - self.check_lit(cx, lit); + if let ExprKind::Lit(lit) = expr.kind { + self.check_lit(cx, lit, expr.span); } } } @@ -252,12 +254,13 @@ impl LiteralDigitGrouping { } } - fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) { + fn check_lit(self, cx: &EarlyContext<'_>, lit: token::Lit, span: Span) { if_chain! { - if let Some(src) = snippet_opt(cx, lit.span); - if let Some(mut num_lit) = NumericLiteral::from_lit(&src, lit); + if let Some(src) = snippet_opt(cx, span); + if let Ok(lit_kind) = LitKind::from_token_lit(lit); + if let Some(mut num_lit) = NumericLiteral::from_lit_kind(&src, &lit_kind); then { - if !Self::check_for_mistyped_suffix(cx, lit.span, &mut num_lit) { + if !Self::check_for_mistyped_suffix(cx, span, &mut num_lit) { return; } @@ -293,14 +296,14 @@ impl LiteralDigitGrouping { | WarningType::InconsistentDigitGrouping | WarningType::UnusualByteGroupings | WarningType::LargeDigitGroups => { - !lit.span.from_expansion() + !span.from_expansion() } WarningType::DecimalRepresentation | WarningType::MistypedLiteralSuffix => { true } }; if should_warn { - warning_type.display(num_lit.format(), cx, lit.span); + warning_type.display(num_lit.format(), cx, span); } } } @@ -458,8 +461,8 @@ impl EarlyLintPass for DecimalLiteralRepresentation { return; } - if let ExprKind::Lit(ref lit) = expr.kind { - self.check_lit(cx, lit); + if let ExprKind::Lit(lit) = expr.kind { + self.check_lit(cx, lit, expr.span); } } } @@ -469,19 +472,20 @@ impl DecimalLiteralRepresentation { pub fn new(threshold: u64) -> Self { Self { threshold } } - fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) { + fn check_lit(self, cx: &EarlyContext<'_>, lit: token::Lit, span: Span) { // Lint integral literals. if_chain! { - if let LitKind::Int(val, _) = lit.kind; - if let Some(src) = snippet_opt(cx, lit.span); - if let Some(num_lit) = NumericLiteral::from_lit(&src, lit); + if let Ok(lit_kind) = LitKind::from_token_lit(lit); + if let LitKind::Int(val, _) = lit_kind; + if let Some(src) = snippet_opt(cx, span); + if let Some(num_lit) = NumericLiteral::from_lit_kind(&src, &lit_kind); if num_lit.radix == Radix::Decimal; if val >= u128::from(self.threshold); then { let hex = format!("{val:#X}"); let num_lit = NumericLiteral::new(&hex, num_lit.suffix, false); let _ = Self::do_lint(num_lit.integer).map_err(|warning_type| { - warning_type.display(num_lit.format(), cx, lit.span); + warning_type.display(num_lit.format(), cx, span); }); } } diff --git a/clippy_lints/src/misc_early/literal_suffix.rs b/clippy_lints/src/misc_early/literal_suffix.rs index 27e7f8505eb5..eda4376f200e 100644 --- a/clippy_lints/src/misc_early/literal_suffix.rs +++ b/clippy_lints/src/misc_early/literal_suffix.rs @@ -1,11 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use rustc_ast::ast::Lit; use rustc_errors::Applicability; use rustc_lint::EarlyContext; +use rustc_span::Span; use super::{SEPARATED_LITERAL_SUFFIX, UNSEPARATED_LITERAL_SUFFIX}; -pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, lit_snip: &str, suffix: &str, sugg_type: &str) { +pub(super) fn check(cx: &EarlyContext<'_>, lit_span: Span, lit_snip: &str, suffix: &str, sugg_type: &str) { let Some(maybe_last_sep_idx) = lit_snip.len().checked_sub(suffix.len() + 1) else { return; // It's useless so shouldn't lint. }; @@ -15,7 +15,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, lit_snip: &str, suffix: &s span_lint_and_sugg( cx, SEPARATED_LITERAL_SUFFIX, - lit.span, + lit_span, &format!("{sugg_type} type suffix should not be separated by an underscore"), "remove the underscore", format!("{}{suffix}", &lit_snip[..maybe_last_sep_idx]), @@ -25,7 +25,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, lit_snip: &str, suffix: &s span_lint_and_sugg( cx, UNSEPARATED_LITERAL_SUFFIX, - lit.span, + lit_span, &format!("{sugg_type} type suffix should be separated by an underscore"), "add an underscore", format!("{}_{suffix}", &lit_snip[..=maybe_last_sep_idx]), diff --git a/clippy_lints/src/misc_early/mixed_case_hex_literals.rs b/clippy_lints/src/misc_early/mixed_case_hex_literals.rs index 263ee1e945a2..ddb8b9173a53 100644 --- a/clippy_lints/src/misc_early/mixed_case_hex_literals.rs +++ b/clippy_lints/src/misc_early/mixed_case_hex_literals.rs @@ -1,10 +1,10 @@ use clippy_utils::diagnostics::span_lint; -use rustc_ast::ast::Lit; use rustc_lint::EarlyContext; +use rustc_span::Span; use super::MIXED_CASE_HEX_LITERALS; -pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, suffix: &str, lit_snip: &str) { +pub(super) fn check(cx: &EarlyContext<'_>, lit_span: Span, suffix: &str, lit_snip: &str) { let Some(maybe_last_sep_idx) = lit_snip.len().checked_sub(suffix.len() + 1) else { return; // It's useless so shouldn't lint. }; @@ -23,7 +23,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, suffix: &str, lit_snip: &s span_lint( cx, MIXED_CASE_HEX_LITERALS, - lit.span, + lit_span, "inconsistent casing in hexadecimal literal", ); break; diff --git a/clippy_lints/src/misc_early/mod.rs b/clippy_lints/src/misc_early/mod.rs index c8227ca44505..78be6b9e23fa 100644 --- a/clippy_lints/src/misc_early/mod.rs +++ b/clippy_lints/src/misc_early/mod.rs @@ -9,7 +9,8 @@ mod zero_prefixed_literal; use clippy_utils::diagnostics::span_lint; use clippy_utils::source::snippet_opt; -use rustc_ast::ast::{Expr, ExprKind, Generics, Lit, LitFloatType, LitIntType, LitKind, NodeId, Pat, PatKind}; +use rustc_ast::ast::{Expr, ExprKind, Generics, LitFloatType, LitIntType, LitKind, NodeId, Pat, PatKind}; +use rustc_ast::token; use rustc_ast::visit::FnKind; use rustc_data_structures::fx::FxHashMap; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; @@ -374,42 +375,43 @@ impl EarlyLintPass for MiscEarlyLints { return; } - if let ExprKind::Lit(ref lit) = expr.kind { - MiscEarlyLints::check_lit(cx, lit); + if let ExprKind::Lit(lit) = expr.kind { + MiscEarlyLints::check_lit(cx, lit, expr.span); } double_neg::check(cx, expr); } } impl MiscEarlyLints { - fn check_lit(cx: &EarlyContext<'_>, lit: &Lit) { + fn check_lit(cx: &EarlyContext<'_>, lit: token::Lit, span: Span) { // We test if first character in snippet is a number, because the snippet could be an expansion // from a built-in macro like `line!()` or a proc-macro like `#[wasm_bindgen]`. // Note that this check also covers special case that `line!()` is eagerly expanded by compiler. // See for a regression. // FIXME: Find a better way to detect those cases. - let lit_snip = match snippet_opt(cx, lit.span) { + let lit_snip = match snippet_opt(cx, span) { Some(snip) if snip.chars().next().map_or(false, |c| c.is_ascii_digit()) => snip, _ => return, }; - if let LitKind::Int(value, lit_int_type) = lit.kind { + let lit_kind = LitKind::from_token_lit(lit); + if let Ok(LitKind::Int(value, lit_int_type)) = lit_kind { let suffix = match lit_int_type { LitIntType::Signed(ty) => ty.name_str(), LitIntType::Unsigned(ty) => ty.name_str(), LitIntType::Unsuffixed => "", }; - literal_suffix::check(cx, lit, &lit_snip, suffix, "integer"); + literal_suffix::check(cx, span, &lit_snip, suffix, "integer"); if lit_snip.starts_with("0x") { - mixed_case_hex_literals::check(cx, lit, suffix, &lit_snip); + mixed_case_hex_literals::check(cx, span, suffix, &lit_snip); } else if lit_snip.starts_with("0b") || lit_snip.starts_with("0o") { // nothing to do } else if value != 0 && lit_snip.starts_with('0') { - zero_prefixed_literal::check(cx, lit, &lit_snip); + zero_prefixed_literal::check(cx, span, &lit_snip); } - } else if let LitKind::Float(_, LitFloatType::Suffixed(float_ty)) = lit.kind { + } else if let Ok(LitKind::Float(_, LitFloatType::Suffixed(float_ty))) = lit_kind { let suffix = float_ty.name_str(); - literal_suffix::check(cx, lit, &lit_snip, suffix, "float"); + literal_suffix::check(cx, span, &lit_snip, suffix, "float"); } } } diff --git a/clippy_lints/src/misc_early/zero_prefixed_literal.rs b/clippy_lints/src/misc_early/zero_prefixed_literal.rs index 9ead43ea4a47..4f9578d1b257 100644 --- a/clippy_lints/src/misc_early/zero_prefixed_literal.rs +++ b/clippy_lints/src/misc_early/zero_prefixed_literal.rs @@ -1,20 +1,20 @@ use clippy_utils::diagnostics::span_lint_and_then; -use rustc_ast::ast::Lit; use rustc_errors::Applicability; use rustc_lint::EarlyContext; +use rustc_span::Span; use super::ZERO_PREFIXED_LITERAL; -pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, lit_snip: &str) { +pub(super) fn check(cx: &EarlyContext<'_>, lit_span: Span, lit_snip: &str) { let trimmed_lit_snip = lit_snip.trim_start_matches(|c| c == '_' || c == '0'); span_lint_and_then( cx, ZERO_PREFIXED_LITERAL, - lit.span, + lit_span, "this is a decimal constant", |diag| { diag.span_suggestion( - lit.span, + lit_span, "if you mean to use a decimal constant, remove the `0` to avoid confusion", trimmed_lit_snip.to_string(), Applicability::MaybeIncorrect, @@ -22,7 +22,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, lit_snip: &str) { // do not advise to use octal form if the literal cannot be expressed in base 8. if !lit_snip.contains(|c| c == '8' || c == '9') { diag.span_suggestion( - lit.span, + lit_span, "if you mean to use an octal constant, use `0o`", format!("0o{trimmed_lit_snip}"), Applicability::MaybeIncorrect, diff --git a/clippy_lints/src/octal_escapes.rs b/clippy_lints/src/octal_escapes.rs index f380a5065827..2a7159764e46 100644 --- a/clippy_lints/src/octal_escapes.rs +++ b/clippy_lints/src/octal_escapes.rs @@ -56,11 +56,11 @@ impl EarlyLintPass for OctalEscapes { return; } - if let ExprKind::Lit(lit) = &expr.kind { - if matches!(lit.token_lit.kind, LitKind::Str) { - check_lit(cx, &lit.token_lit, lit.span, true); - } else if matches!(lit.token_lit.kind, LitKind::ByteStr) { - check_lit(cx, &lit.token_lit, lit.span, false); + if let ExprKind::Lit(token_lit) = &expr.kind { + if matches!(token_lit.kind, LitKind::Str) { + check_lit(cx, &token_lit, expr.span, true); + } else if matches!(token_lit.kind, LitKind::ByteStr) { + check_lit(cx, &token_lit, expr.span, false); } } } diff --git a/clippy_lints/src/precedence.rs b/clippy_lints/src/precedence.rs index e6e3ad05ad70..bee4a33fb4a0 100644 --- a/clippy_lints/src/precedence.rs +++ b/clippy_lints/src/precedence.rs @@ -1,7 +1,8 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; -use rustc_ast::ast::{BinOpKind, Expr, ExprKind, LitKind, UnOp}; +use rustc_ast::ast::{BinOpKind, Expr, ExprKind, UnOp}; +use rustc_ast::token; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -120,7 +121,7 @@ impl EarlyLintPass for Precedence { if_chain! { if !all_odd; if let ExprKind::Lit(lit) = &arg.kind; - if let LitKind::Int(..) | LitKind::Float(..) = &lit.kind; + if let token::LitKind::Integer | token::LitKind::Float = &lit.kind; then { let mut applicability = Applicability::MachineApplicable; span_lint_and_sugg( diff --git a/clippy_lints/src/unused_rounding.rs b/clippy_lints/src/unused_rounding.rs index 3164937293b6..3c1998d0237d 100644 --- a/clippy_lints/src/unused_rounding.rs +++ b/clippy_lints/src/unused_rounding.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use rustc_ast::ast::{Expr, ExprKind, LitFloatType, LitKind}; +use rustc_ast::ast::{Expr, ExprKind}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -33,14 +33,14 @@ fn is_useless_rounding(expr: &Expr) -> Option<(&str, String)> { if let ExprKind::MethodCall(name_ident, receiver, _, _) = &expr.kind && let method_name = name_ident.ident.name.as_str() && (method_name == "ceil" || method_name == "round" || method_name == "floor") - && let ExprKind::Lit(spanned) = &receiver.kind - && let LitKind::Float(symbol, ty) = spanned.kind { - let f = symbol.as_str().parse::().unwrap(); - let f_str = symbol.to_string() + if let LitFloatType::Suffixed(ty) = ty { - ty.name_str() - } else { - "" - }; + && let ExprKind::Lit(token_lit) = &receiver.kind + && token_lit.is_semantic_float() { + let f = token_lit.symbol.as_str().parse::().unwrap(); + let mut f_str = token_lit.symbol.to_string(); + match token_lit.suffix { + Some(suffix) => f_str.push_str(suffix.as_str()), + None => {} + } if f.fract() == 0.0 { Some((method_name, f_str)) } else { diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 0133997560ea..73d1ba727c82 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -152,7 +152,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { }, (Binary(lo, ll, lr), Binary(ro, rl, rr)) => lo.node == ro.node && eq_expr(ll, rl) && eq_expr(lr, rr), (Unary(lo, l), Unary(ro, r)) => mem::discriminant(lo) == mem::discriminant(ro) && eq_expr(l, r), - (Lit(l), Lit(r)) => l.kind == r.kind, + (Lit(l), Lit(r)) => l == r, (Cast(l, lt), Cast(r, rt)) | (Type(l, lt), Type(r, rt)) => eq_expr(l, r) && eq_ty(lt, rt), (Let(lp, le, _), Let(rp, re, _)) => eq_pat(lp, rp) && eq_expr(le, re), (If(lc, lt, le), If(rc, rt, re)) => eq_expr(lc, rc) && eq_block(lt, rt) && eq_expr_opt(le, re), diff --git a/clippy_utils/src/numeric_literal.rs b/clippy_utils/src/numeric_literal.rs index c5dcd7b31f58..42bdfd4827f1 100644 --- a/clippy_utils/src/numeric_literal.rs +++ b/clippy_utils/src/numeric_literal.rs @@ -1,4 +1,4 @@ -use rustc_ast::ast::{Lit, LitFloatType, LitIntType, LitKind}; +use rustc_ast::ast::{LitFloatType, LitIntType, LitKind}; use std::iter; #[derive(Debug, PartialEq, Eq, Copy, Clone)] @@ -46,10 +46,6 @@ pub struct NumericLiteral<'a> { } impl<'a> NumericLiteral<'a> { - pub fn from_lit(src: &'a str, lit: &Lit) -> Option> { - NumericLiteral::from_lit_kind(src, &lit.kind) - } - pub fn from_lit_kind(src: &'a str, lit_kind: &LitKind) -> Option> { let unsigned_src = src.strip_prefix('-').map_or(src, |s| s); if lit_kind.is_numeric() From 0328a15447997f22709aee07dd9f1581798446d2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 15 Nov 2022 12:06:20 +0100 Subject: [PATCH 0665/1222] cleanup and dedupe CTFE and Miri error reporting --- tests/ui/indexing_slicing_index.stderr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ui/indexing_slicing_index.stderr b/tests/ui/indexing_slicing_index.stderr index da5bc38b3b66..d8b6e3f1262b 100644 --- a/tests/ui/indexing_slicing_index.stderr +++ b/tests/ui/indexing_slicing_index.stderr @@ -4,11 +4,11 @@ error[E0080]: evaluation of `main::{constant#3}` failed LL | const { &ARR[idx4()] }; // Ok, let rustc handle const contexts. | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 -error[E0080]: erroneous constant used +note: erroneous constant used --> $DIR/indexing_slicing_index.rs:31:5 | LL | const { &ARR[idx4()] }; // Ok, let rustc handle const contexts. - | ^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors + | ^^^^^^^^^^^^^^^^^^^^^^ error: indexing may panic --> $DIR/indexing_slicing_index.rs:22:5 @@ -65,6 +65,6 @@ error[E0080]: evaluation of constant value failed LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 -error: aborting due to 9 previous errors +error: aborting due to 8 previous errors For more information about this error, try `rustc --explain E0080`. From 5640cf9ce7a4b3b57285dff4aa8317ea028d9d56 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 9 Nov 2022 10:49:28 +0000 Subject: [PATCH 0666/1222] Convert predicates into Predicate in the Obligation constructor --- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/methods/unnecessary_to_owned.rs | 2 +- clippy_lints/src/ptr.rs | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index a37ee82d4c8a..218dbeaddcad 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1156,7 +1156,7 @@ fn needless_borrow_impl_arg_position<'tcx>( } let predicate = EarlyBinder(predicate).subst(cx.tcx, &substs_with_referent_ty); - let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate); + let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate); let infcx = cx.tcx.infer_ctxt().build(); infcx.predicate_must_hold_modulo_regions(&obligation) }) diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 642a64ae77b6..c7775313ecd0 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -419,7 +419,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< if trait_predicates.any(|predicate| { let predicate = EarlyBinder(predicate).subst(cx.tcx, new_subst); - let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate); + let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate); !cx.tcx.infer_ctxt().build().predicate_must_hold_modulo_regions(&obligation) }) { return false; diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 0d74c90a834f..c8c6f32c6c98 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -695,6 +695,7 @@ fn matches_preds<'tcx>( .type_implements_trait(p.def_id, ty, p.substs, cx.param_env) .must_apply_modulo_regions(), ExistentialPredicate::Projection(p) => infcx.predicate_must_hold_modulo_regions(&Obligation::new( + cx.tcx, ObligationCause::dummy(), cx.param_env, cx.tcx.mk_predicate(Binder::bind_with_vars( From 75a3082f44c97a90fbee3a176605d99f10e4c2c8 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 8 Sep 2022 10:52:51 +1000 Subject: [PATCH 0667/1222] Box `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and patterns. --- clippy_lints/src/double_parens.rs | 8 ++--- clippy_lints/src/option_env_unwrap.rs | 6 ++-- clippy_lints/src/precedence.rs | 8 ++--- clippy_lints/src/redundant_closure_call.rs | 12 +++---- .../src/suspicious_operation_groupings.rs | 4 +-- clippy_lints/src/unnested_or_patterns.rs | 2 +- clippy_lints/src/unused_rounding.rs | 6 ++-- clippy_utils/src/ast_utils.rs | 32 ++++++++++++++++--- 8 files changed, 50 insertions(+), 28 deletions(-) diff --git a/clippy_lints/src/double_parens.rs b/clippy_lints/src/double_parens.rs index 0f1d701865e7..29425b2e5541 100644 --- a/clippy_lints/src/double_parens.rs +++ b/clippy_lints/src/double_parens.rs @@ -61,10 +61,10 @@ impl EarlyLintPass for DoubleParens { } } }, - ExprKind::MethodCall(_, _, ref params, _) => { - if let [ref param] = params[..] { - if let ExprKind::Paren(_) = param.kind { - span_lint(cx, DOUBLE_PARENS, param.span, msg); + ExprKind::MethodCall(ref call) => { + if let [ref arg] = call.args[..] { + if let ExprKind::Paren(_) = arg.kind { + span_lint(cx, DOUBLE_PARENS, arg.span, msg); } } }, diff --git a/clippy_lints/src/option_env_unwrap.rs b/clippy_lints/src/option_env_unwrap.rs index d9ee031c9f97..377bddeaa5fe 100644 --- a/clippy_lints/src/option_env_unwrap.rs +++ b/clippy_lints/src/option_env_unwrap.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::is_direct_expn_of; use if_chain::if_chain; -use rustc_ast::ast::{Expr, ExprKind}; +use rustc_ast::ast::{Expr, ExprKind, MethodCall}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; @@ -37,8 +37,8 @@ declare_lint_pass!(OptionEnvUnwrap => [OPTION_ENV_UNWRAP]); impl EarlyLintPass for OptionEnvUnwrap { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { if_chain! { - if let ExprKind::MethodCall(path_segment, receiver, _, _) = &expr.kind; - if matches!(path_segment.ident.name, sym::expect | sym::unwrap); + if let ExprKind::MethodCall(box MethodCall { seg, receiver, .. }) = &expr.kind; + if matches!(seg.ident.name, sym::expect | sym::unwrap); if let ExprKind::Call(caller, _) = &receiver.kind; if is_direct_expn_of(caller.span, "option_env").is_some(); then { diff --git a/clippy_lints/src/precedence.rs b/clippy_lints/src/precedence.rs index bee4a33fb4a0..057b7e30642e 100644 --- a/clippy_lints/src/precedence.rs +++ b/clippy_lints/src/precedence.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use if_chain::if_chain; -use rustc_ast::ast::{BinOpKind, Expr, ExprKind, UnOp}; +use rustc_ast::ast::{BinOpKind, Expr, ExprKind, MethodCall, UnOp}; use rustc_ast::token; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; @@ -110,11 +110,11 @@ impl EarlyLintPass for Precedence { let mut arg = operand; let mut all_odd = true; - while let ExprKind::MethodCall(path_segment, receiver, _, _) = &arg.kind { - let path_segment_str = path_segment.ident.name.as_str(); + while let ExprKind::MethodCall(box MethodCall { seg, receiver, .. }) = &arg.kind { + let seg_str = seg.ident.name.as_str(); all_odd &= ALLOWED_ODD_FUNCTIONS .iter() - .any(|odd_function| **odd_function == *path_segment_str); + .any(|odd_function| **odd_function == *seg_str); arg = receiver; } diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 74eea6de4bbe..4cbe9597c539 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -69,10 +69,10 @@ impl EarlyLintPass for RedundantClosureCall { if_chain! { if let ast::ExprKind::Call(ref paren, _) = expr.kind; if let ast::ExprKind::Paren(ref closure) = paren.kind; - if let ast::ExprKind::Closure(_, _, ref r#async, _, ref decl, ref block, _) = closure.kind; + if let ast::ExprKind::Closure(box ast::Closure { ref asyncness, ref fn_decl, ref body, .. }) = closure.kind; then { let mut visitor = ReturnVisitor::new(); - visitor.visit_expr(block); + visitor.visit_expr(body); if !visitor.found_return { span_lint_and_then( cx, @@ -80,13 +80,13 @@ impl EarlyLintPass for RedundantClosureCall { expr.span, "try not to call a closure in the expression where it is declared", |diag| { - if decl.inputs.is_empty() { + if fn_decl.inputs.is_empty() { let app = Applicability::MachineApplicable; - let mut hint = Sugg::ast(cx, block, ".."); + let mut hint = Sugg::ast(cx, body, ".."); - if r#async.is_async() { + if asyncness.is_async() { // `async x` is a syntax error, so it becomes `async { x }` - if !matches!(block.kind, ast::ExprKind::Block(_, _)) { + if !matches!(body.kind, ast::ExprKind::Block(_, _)) { hint = hint.blockify(); } diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index eef9bdc78494..78e83880e1a6 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -580,7 +580,7 @@ fn ident_difference_expr_with_base_location( | (Await(_), Await(_)) | (Async(_, _, _), Async(_, _, _)) | (Block(_, _), Block(_, _)) - | (Closure(_, _, _, _, _, _, _), Closure(_, _, _, _, _, _, _)) + | (Closure(_), Closure(_)) | (Match(_, _), Match(_, _)) | (Loop(_, _), Loop(_, _)) | (ForLoop(_, _, _, _), ForLoop(_, _, _, _)) @@ -593,7 +593,7 @@ fn ident_difference_expr_with_base_location( | (Unary(_, _), Unary(_, _)) | (Binary(_, _, _), Binary(_, _, _)) | (Tup(_), Tup(_)) - | (MethodCall(_, _, _, _), MethodCall(_, _, _, _)) + | (MethodCall(_), MethodCall(_)) | (Call(_, _), Call(_, _)) | (ConstBlock(_), ConstBlock(_)) | (Array(_), Array(_)) diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index b305dae76084..bb6fb38e9690 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -292,7 +292,7 @@ fn transform_with_focus_on_idx(alternatives: &mut Vec>, focus_idx: usize) /// So when we fixate on some `ident_k: pat_k`, we try to find `ident_k` in the other pattern /// and check that all `fp_i` where `i ∈ ((0...n) \ k)` between two patterns are equal. fn extend_with_struct_pat( - qself1: &Option, + qself1: &Option>, path1: &ast::Path, fps1: &mut [ast::PatField], rest1: bool, diff --git a/clippy_lints/src/unused_rounding.rs b/clippy_lints/src/unused_rounding.rs index 3c1998d0237d..5ab351bc29ca 100644 --- a/clippy_lints/src/unused_rounding.rs +++ b/clippy_lints/src/unused_rounding.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use rustc_ast::ast::{Expr, ExprKind}; +use rustc_ast::ast::{Expr, ExprKind, MethodCall}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -30,8 +30,8 @@ declare_clippy_lint! { declare_lint_pass!(UnusedRounding => [UNUSED_ROUNDING]); fn is_useless_rounding(expr: &Expr) -> Option<(&str, String)> { - if let ExprKind::MethodCall(name_ident, receiver, _, _) = &expr.kind - && let method_name = name_ident.ident.name.as_str() + if let ExprKind::MethodCall(box MethodCall { seg, receiver, .. }) = &expr.kind + && let method_name = seg.ident.name.as_str() && (method_name == "ceil" || method_name == "round" || method_name == "floor") && let ExprKind::Lit(token_lit) = &receiver.kind && token_lit.is_semantic_float() { diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 73d1ba727c82..23aed4b5ba2f 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -75,11 +75,11 @@ pub fn eq_field_pat(l: &PatField, r: &PatField) -> bool { && over(&l.attrs, &r.attrs, eq_attr) } -pub fn eq_qself(l: &QSelf, r: &QSelf) -> bool { +pub fn eq_qself(l: &P, r: &P) -> bool { l.position == r.position && eq_ty(&l.ty, &r.ty) } -pub fn eq_maybe_qself(l: &Option, r: &Option) -> bool { +pub fn eq_maybe_qself(l: &Option>, r: &Option>) -> bool { match (l, r) { (Some(l), Some(r)) => eq_qself(l, r), (None, None) => true, @@ -147,8 +147,11 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (Array(l), Array(r)) | (Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)), (Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value), (Call(lc, la), Call(rc, ra)) => eq_expr(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)), - (MethodCall(lc, ls, la, _), MethodCall(rc, rs, ra, _)) => { - eq_path_seg(lc, rc) && eq_expr(ls, rs) && over(la, ra, |l, r| eq_expr(l, r)) + ( + MethodCall(box ast::MethodCall { seg: ls, receiver: lr, args: la, .. }), + MethodCall(box ast::MethodCall { seg: rs, receiver: rr, args: ra, .. }) + ) => { + eq_path_seg(ls, rs) && eq_expr(lr, rr) && over(la, ra, |l, r| eq_expr(l, r)) }, (Binary(lo, ll, lr), Binary(ro, rl, rr)) => lo.node == ro.node && eq_expr(ll, rl) && eq_expr(lr, rr), (Unary(lo, l), Unary(ro, r)) => mem::discriminant(lo) == mem::discriminant(ro) && eq_expr(l, r), @@ -170,7 +173,26 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (AssignOp(lo, lp, lv), AssignOp(ro, rp, rv)) => lo.node == ro.node && eq_expr(lp, rp) && eq_expr(lv, rv), (Field(lp, lf), Field(rp, rf)) => eq_id(*lf, *rf) && eq_expr(lp, rp), (Match(ls, la), Match(rs, ra)) => eq_expr(ls, rs) && over(la, ra, eq_arm), - (Closure(lb, lc, la, lm, lf, le, _), Closure(rb, rc, ra, rm, rf, re, _)) => { + ( + Closure(box ast::Closure { + binder: lb, + capture_clause: lc, + asyncness: la, + movability: lm, + fn_decl: lf, + body: le, + .. + }), + Closure(box ast::Closure { + binder: rb, + capture_clause: rc, + asyncness: ra, + movability: rm, + fn_decl: rf, + body: re, + .. + }) + ) => { eq_closure_binder(lb, rb) && lc == rc && la.is_async() == ra.is_async() From 42ce14f32c2d1353451e603c2454f098aeb934c2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 17 Nov 2022 16:17:26 +0100 Subject: [PATCH 0668/1222] empty commit to go through bors From 6b8d7e04a6c07401a8e87e9e6d0d199bdd548685 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Sat, 5 Nov 2022 15:08:37 +0100 Subject: [PATCH 0669/1222] Add variant_name function to `LangItem` Clippy has an internal lint that checks for the usage of hardcoded def paths and suggests to replace them with a lang or diagnostic item, if possible. This was implemented with a hack, by getting all the variants of the `LangItem` enum and then index into it with the position of the `LangItem` in the `items` list. This is no longer possible, because the `items` list can't be accessed anymore. --- .../src/utils/internal_lints/invalid_paths.rs | 12 +++++------ .../internal_lints/unnecessary_def_path.rs | 19 +++++------------- tests/ui-internal/unnecessary_def_path.fixed | 6 +++--- tests/ui-internal/unnecessary_def_path.stderr | 6 +++--- ...unnecessary_def_path_hardcoded_path.stderr | 20 +++++++++---------- 5 files changed, 27 insertions(+), 36 deletions(-) diff --git a/clippy_lints/src/utils/internal_lints/invalid_paths.rs b/clippy_lints/src/utils/internal_lints/invalid_paths.rs index 25532dd4e268..22a5aa5351ad 100644 --- a/clippy_lints/src/utils/internal_lints/invalid_paths.rs +++ b/clippy_lints/src/utils/internal_lints/invalid_paths.rs @@ -79,22 +79,22 @@ pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool { SimplifiedTypeGen::StrSimplifiedType, ] .iter() - .flat_map(|&ty| cx.tcx.incoherent_impls(ty)); - for item_def_id in lang_items.items().iter().flatten().chain(incoherent_impls) { - let lang_item_path = cx.get_def_path(*item_def_id); + .flat_map(|&ty| cx.tcx.incoherent_impls(ty).iter().copied()); + for item_def_id in lang_items.iter().map(|(_, def_id)| def_id).chain(incoherent_impls) { + let lang_item_path = cx.get_def_path(item_def_id); if path_syms.starts_with(&lang_item_path) { if let [item] = &path_syms[lang_item_path.len()..] { if matches!( - cx.tcx.def_kind(*item_def_id), + cx.tcx.def_kind(item_def_id), DefKind::Mod | DefKind::Enum | DefKind::Trait ) { - for child in cx.tcx.module_children(*item_def_id) { + for child in cx.tcx.module_children(item_def_id) { if child.ident.name == *item { return true; } } } else { - for child in cx.tcx.associated_item_def_ids(*item_def_id) { + for child in cx.tcx.associated_item_def_ids(item_def_id) { if cx.tcx.item_name(*child) == *item { return true; } diff --git a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs index 2a028c8141fc..cfba7fa8791d 100644 --- a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs +++ b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs @@ -6,7 +6,7 @@ use rustc_ast::ast::LitKind; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir as hir; -use rustc_hir::def::{DefKind, Namespace, Res}; +use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind, Local, Mutability, Node}; use rustc_lint::{LateContext, LateLintPass}; @@ -91,7 +91,7 @@ impl UnnecessaryDefPath { #[allow(clippy::too_many_lines)] fn check_call(&mut self, cx: &LateContext<'_>, func: &Expr<'_>, args: &[Expr<'_>], span: Span) { enum Item { - LangItem(Symbol), + LangItem(&'static str), DiagnosticItem(Symbol), } static PATHS: &[&[&str]] = &[ @@ -325,18 +325,9 @@ fn inherent_def_path_res(cx: &LateContext<'_>, segments: &[&str]) -> Option, def_id: DefId) -> Option { - if let Some(lang_item) = cx.tcx.lang_items().items().iter().position(|id| *id == Some(def_id)) { - let lang_items = def_path_res(cx, &["rustc_hir", "lang_items", "LangItem"], Some(Namespace::TypeNS)).def_id(); - let item_name = cx - .tcx - .adt_def(lang_items) - .variants() - .iter() - .nth(lang_item) - .unwrap() - .name; - Some(item_name) +fn get_lang_item_name(cx: &LateContext<'_>, def_id: DefId) -> Option<&'static str> { + if let Some((lang_item, _)) = cx.tcx.lang_items().iter().find(|(_, id)| *id == def_id) { + Some(lang_item.variant_name()) } else { None } diff --git a/tests/ui-internal/unnecessary_def_path.fixed b/tests/ui-internal/unnecessary_def_path.fixed index cbbb46523064..e474f370a5d1 100644 --- a/tests/ui-internal/unnecessary_def_path.fixed +++ b/tests/ui-internal/unnecessary_def_path.fixed @@ -48,14 +48,14 @@ fn _f<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, did: DefId, expr: &Expr<'_>) { let _ = is_type_lang_item(cx, ty, LangItem::OwnedBox); let _ = is_type_diagnostic_item(cx, ty, sym::maybe_uninit_uninit); - let _ = cx.tcx.lang_items().require(LangItem::OwnedBox).ok() == Some(did); + let _ = cx.tcx.lang_items().get(LangItem::OwnedBox) == Some(did); let _ = cx.tcx.is_diagnostic_item(sym::Option, did); - let _ = cx.tcx.lang_items().require(LangItem::OptionSome).ok() == Some(did); + let _ = cx.tcx.lang_items().get(LangItem::OptionSome) == Some(did); let _ = is_trait_method(cx, expr, sym::AsRef); let _ = is_path_diagnostic_item(cx, expr, sym::Option); - let _ = path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().require(LangItem::IteratorNext).ok() == Some(id)); + let _ = path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().get(LangItem::IteratorNext) == Some(id)); let _ = is_res_lang_ctor(cx, path_res(cx, expr), LangItem::OptionSome); } diff --git a/tests/ui-internal/unnecessary_def_path.stderr b/tests/ui-internal/unnecessary_def_path.stderr index a99a8f71fa6a..3ca29f099771 100644 --- a/tests/ui-internal/unnecessary_def_path.stderr +++ b/tests/ui-internal/unnecessary_def_path.stderr @@ -57,7 +57,7 @@ error: use of a def path to a `LangItem` --> $DIR/unnecessary_def_path.rs:51:13 | LL | let _ = match_def_path(cx, did, &["alloc", "boxed", "Box"]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().require(LangItem::OwnedBox).ok() == Some(did)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().get(LangItem::OwnedBox) == Some(did)` error: use of a def path to a diagnostic item --> $DIR/unnecessary_def_path.rs:52:13 @@ -69,7 +69,7 @@ error: use of a def path to a `LangItem` --> $DIR/unnecessary_def_path.rs:53:13 | LL | let _ = match_def_path(cx, did, &["core", "option", "Option", "Some"]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().require(LangItem::OptionSome).ok() == Some(did)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().get(LangItem::OptionSome) == Some(did)` | = help: if this `DefId` came from a constructor expression or pattern then the parent `DefId` should be used instead @@ -89,7 +89,7 @@ error: use of a def path to a `LangItem` --> $DIR/unnecessary_def_path.rs:58:13 | LL | let _ = is_expr_path_def_path(cx, expr, &["core", "iter", "traits", "Iterator", "next"]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().require(LangItem::IteratorNext).ok() == Some(id))` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().get(LangItem::IteratorNext) == Some(id))` error: use of a def path to a `LangItem` --> $DIR/unnecessary_def_path.rs:59:13 diff --git a/tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr b/tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr index af46d87bf676..2a240cc249b0 100644 --- a/tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr +++ b/tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr @@ -1,10 +1,10 @@ -error: hardcoded path to a language item - --> $DIR/unnecessary_def_path_hardcoded_path.rs:11:40 +error: hardcoded path to a diagnostic item + --> $DIR/unnecessary_def_path_hardcoded_path.rs:10:36 | -LL | const DEREF_MUT_TRAIT: [&str; 4] = ["core", "ops", "deref", "DerefMut"]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const DEREF_TRAIT: [&str; 4] = ["core", "ops", "deref", "Deref"]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: convert all references to use `LangItem::DerefMut` + = help: convert all references to use `sym::Deref` = note: `-D clippy::unnecessary-def-path` implied by `-D warnings` error: hardcoded path to a diagnostic item @@ -15,13 +15,13 @@ LL | const DEREF_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "Deref", | = help: convert all references to use `sym::deref_method` -error: hardcoded path to a diagnostic item - --> $DIR/unnecessary_def_path_hardcoded_path.rs:10:36 +error: hardcoded path to a language item + --> $DIR/unnecessary_def_path_hardcoded_path.rs:11:40 | -LL | const DEREF_TRAIT: [&str; 4] = ["core", "ops", "deref", "Deref"]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const DEREF_MUT_TRAIT: [&str; 4] = ["core", "ops", "deref", "DerefMut"]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: convert all references to use `sym::Deref` + = help: convert all references to use `LangItem::DerefMut` error: aborting due to 3 previous errors From b0d29df036b5fb91eeeeb0404e4981cf1254629a Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Tue, 5 Jul 2022 16:56:16 +0000 Subject: [PATCH 0670/1222] Rm diagnostic item, use lang item --- clippy_lints/src/format.rs | 2 +- clippy_lints/src/format_push_string.rs | 6 ++-- clippy_lints/src/from_str_radix_10.rs | 6 ++-- clippy_lints/src/inherent_to_string.rs | 6 ++-- clippy_lints/src/manual_retain.rs | 4 +-- clippy_lints/src/manual_string_new.rs | 2 +- .../src/matches/match_str_case_mismatch.rs | 8 ++--- .../src/methods/bytes_count_to_len.rs | 5 ++-- clippy_lints/src/methods/bytes_nth.rs | 7 ++--- ...se_sensitive_file_extension_comparisons.rs | 8 ++--- clippy_lints/src/methods/expect_fun_call.rs | 6 ++-- .../src/methods/inefficient_to_string.rs | 6 ++-- clippy_lints/src/methods/manual_str_repeat.rs | 6 ++-- clippy_lints/src/methods/no_effect_replace.rs | 7 ++--- clippy_lints/src/methods/repeat_once.rs | 7 ++--- clippy_lints/src/methods/search_is_some.rs | 4 +-- .../src/methods/string_extend_chars.rs | 7 ++--- clippy_lints/src/methods/unnecessary_join.rs | 8 ++--- clippy_lints/src/needless_pass_by_value.rs | 6 ++-- clippy_lints/src/ptr.rs | 2 +- clippy_lints/src/redundant_clone.rs | 6 ++-- clippy_lints/src/strings.rs | 8 ++--- clippy_lints/src/types/box_collection.rs | 29 ++++++++++--------- clippy_lints/src/types/rc_buffer.rs | 8 ++--- .../src/unnecessary_owned_empty_strings.rs | 7 ++--- clippy_utils/src/lib.rs | 15 ++++++++-- 26 files changed, 95 insertions(+), 91 deletions(-) diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index bc0c68f535a9..d0fab6949604 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -73,7 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat { if format_args.format_string.parts == [kw::Empty]; if arg.format.is_default(); if match cx.typeck_results().expr_ty(value).peel_refs().kind() { - ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(sym::String, adt.did()), + ty::Adt(adt, _) => Some(adt.did()) == cx.tcx.lang_items().string(), ty::Str => true, _ => false, }; diff --git a/clippy_lints/src/format_push_string.rs b/clippy_lints/src/format_push_string.rs index 9b9f1872bfc1..68c5c3673fe1 100644 --- a/clippy_lints/src/format_push_string.rs +++ b/clippy_lints/src/format_push_string.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::ty::is_type_lang_item; use clippy_utils::{match_def_path, paths, peel_hir_expr_refs}; -use rustc_hir::{BinOpKind, Expr, ExprKind}; +use rustc_hir::{BinOpKind, Expr, ExprKind, LangItem}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; @@ -41,7 +41,7 @@ declare_clippy_lint! { declare_lint_pass!(FormatPushString => [FORMAT_PUSH_STRING]); fn is_string(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { - is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(e).peel_refs(), sym::String) + is_type_lang_item(cx, cx.typeck_results().expr_ty(e).peel_refs(), LangItem::String) } fn is_format(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { if let Some(macro_def_id) = e.span.ctxt().outer_expn_data().macro_def_id { diff --git a/clippy_lints/src/from_str_radix_10.rs b/clippy_lints/src/from_str_radix_10.rs index cf8b7acd66d2..74a60b6a0d24 100644 --- a/clippy_lints/src/from_str_radix_10.rs +++ b/clippy_lints/src/from_str_radix_10.rs @@ -1,10 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::is_integer_literal; use clippy_utils::sugg::Sugg; -use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::{def, Expr, ExprKind, PrimTy, QPath, TyKind}; +use rustc_hir::{def, Expr, ExprKind, LangItem, PrimTy, QPath, TyKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::Ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -98,5 +98,5 @@ impl<'tcx> LateLintPass<'tcx> for FromStrRadix10 { /// Checks if a Ty is `String` or `&str` fn is_ty_stringish(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { - is_type_diagnostic_item(cx, ty, sym::String) || is_type_diagnostic_item(cx, ty, sym::str) + is_type_lang_item(cx, ty, LangItem::String) || is_type_diagnostic_item(cx, ty, sym::str) } diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index 14a37f535b46..aaecc4fa8f25 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -1,8 +1,8 @@ use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; +use clippy_utils::ty::{implements_trait, is_type_lang_item}; use clippy_utils::{return_ty, trait_ref_of_method}; use if_chain::if_chain; -use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind}; +use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind, LangItem}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; @@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString { if impl_item.generics.params.iter().all(|p| matches!(p.kind, GenericParamKind::Lifetime { .. })); // Check if return type is String - if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::String); + if is_type_lang_item(cx, return_ty(cx, impl_item.hir_id()), LangItem::String); // Filters instances of to_string which are required by a trait if trait_ref_of_method(cx, impl_item.owner_id.def_id).is_none(); diff --git a/clippy_lints/src/manual_retain.rs b/clippy_lints/src/manual_retain.rs index 6abbab278feb..d6438ca7fec2 100644 --- a/clippy_lints/src/manual_retain.rs +++ b/clippy_lints/src/manual_retain.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; -use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item}; use clippy_utils::{get_parent_expr, match_def_path, paths, SpanlessEq}; use clippy_utils::{meets_msrv, msrvs}; use rustc_errors::Applicability; @@ -140,7 +140,7 @@ fn check_to_owned( && let Some(chars_expr_def_id) = cx.typeck_results().type_dependent_def_id(chars_expr.hir_id) && match_def_path(cx, chars_expr_def_id, &paths::STR_CHARS) && let ty = cx.typeck_results().expr_ty(str_expr).peel_refs() - && is_type_diagnostic_item(cx, ty, sym::String) + && is_type_lang_item(cx, ty, hir::LangItem::String) && SpanlessEq::new(cx).eq_expr(left_expr, str_expr) { suggest(cx, parent_expr, left_expr, filter_expr); } diff --git a/clippy_lints/src/manual_string_new.rs b/clippy_lints/src/manual_string_new.rs index 6acfb2ae3471..c20d7959fc4a 100644 --- a/clippy_lints/src/manual_string_new.rs +++ b/clippy_lints/src/manual_string_new.rs @@ -44,7 +44,7 @@ impl LateLintPass<'_> for ManualStringNew { let ty = cx.typeck_results().expr_ty(expr); match ty.kind() { ty::Adt(adt_def, _) if adt_def.is_struct() => { - if !cx.tcx.is_diagnostic_item(sym::String, adt_def.did()) { + if cx.tcx.lang_items().string() != Some(adt_def.did()) { return; } }, diff --git a/clippy_lints/src/matches/match_str_case_mismatch.rs b/clippy_lints/src/matches/match_str_case_mismatch.rs index 6647322caa37..675a85ae5553 100644 --- a/clippy_lints/src/matches/match_str_case_mismatch.rs +++ b/clippy_lints/src/matches/match_str_case_mismatch.rs @@ -1,13 +1,13 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::ty::is_type_lang_item; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::{Arm, Expr, ExprKind, PatKind}; +use rustc_hir::{Arm, Expr, ExprKind, LangItem, PatKind}; use rustc_lint::LateContext; use rustc_middle::ty; use rustc_span::symbol::Symbol; -use rustc_span::{sym, Span}; +use rustc_span::Span; use super::MATCH_STR_CASE_MISMATCH; @@ -59,7 +59,7 @@ impl<'a, 'tcx> MatchExprVisitor<'a, 'tcx> { if let Some(case_method) = get_case_method(segment_ident) { let ty = self.cx.typeck_results().expr_ty(receiver).peel_refs(); - if is_type_diagnostic_item(self.cx, ty, sym::String) || ty.kind() == &ty::Str { + if is_type_lang_item(self.cx, ty, LangItem::String) || ty.kind() == &ty::Str { self.case_method = Some(case_method); return true; } diff --git a/clippy_lints/src/methods/bytes_count_to_len.rs b/clippy_lints/src/methods/bytes_count_to_len.rs index fcfc25b523da..89aaad359d4a 100644 --- a/clippy_lints/src/methods/bytes_count_to_len.rs +++ b/clippy_lints/src/methods/bytes_count_to_len.rs @@ -1,11 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; -use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::ty::is_type_lang_item; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; -use rustc_span::sym; use super::BYTES_COUNT_TO_LEN; @@ -20,7 +19,7 @@ pub(super) fn check<'tcx>( if let Some(impl_id) = cx.tcx.impl_of_method(bytes_id); if cx.tcx.type_of(impl_id).is_str(); let ty = cx.typeck_results().expr_ty(bytes_recv).peel_refs(); - if ty.is_str() || is_type_diagnostic_item(cx, ty, sym::String); + if ty.is_str() || is_type_lang_item(cx, ty, hir::LangItem::String); then { let mut applicability = Applicability::MachineApplicable; span_lint_and_sugg( diff --git a/clippy_lints/src/methods/bytes_nth.rs b/clippy_lints/src/methods/bytes_nth.rs index 2e96346be977..d512cc4eeae1 100644 --- a/clippy_lints/src/methods/bytes_nth.rs +++ b/clippy_lints/src/methods/bytes_nth.rs @@ -1,10 +1,9 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; -use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::ty::is_type_lang_item; use rustc_errors::Applicability; -use rustc_hir::Expr; +use rustc_hir::{Expr, LangItem}; use rustc_lint::LateContext; -use rustc_span::sym; use super::BYTES_NTH; @@ -12,7 +11,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, recv: &'tcx E let ty = cx.typeck_results().expr_ty(recv).peel_refs(); let caller_type = if ty.is_str() { "str" - } else if is_type_diagnostic_item(cx, ty, sym::String) { + } else if is_type_lang_item(cx, ty, LangItem::String) { "String" } else { return; diff --git a/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs b/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs index b3c2c7c9a2dc..d226c0bba659 100644 --- a/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs +++ b/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs @@ -1,10 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::ty::is_type_lang_item; use if_chain::if_chain; use rustc_ast::ast::LitKind; -use rustc_hir::{Expr, ExprKind}; +use rustc_hir::{Expr, ExprKind, LangItem}; use rustc_lint::LateContext; -use rustc_span::{source_map::Spanned, symbol::sym, Span}; +use rustc_span::{source_map::Spanned, Span}; use super::CASE_SENSITIVE_FILE_EXTENSION_COMPARISONS; @@ -26,7 +26,7 @@ pub(super) fn check<'tcx>( if ext_str.chars().skip(1).all(|c| c.is_uppercase() || c.is_ascii_digit()) || ext_str.chars().skip(1).all(|c| c.is_lowercase() || c.is_ascii_digit()); let recv_ty = cx.typeck_results().expr_ty(recv).peel_refs(); - if recv_ty.is_str() || is_type_diagnostic_item(cx, recv_ty, sym::String); + if recv_ty.is_str() || is_type_lang_item(cx, recv_ty, LangItem::String); then { span_lint_and_help( cx, diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index d0cf411dfd34..a9189b31c571 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::macros::{root_macro_call_first_node, FormatArgsExpn}; use clippy_utils::source::snippet_with_applicability; -use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; @@ -33,7 +33,7 @@ pub(super) fn check<'tcx>( if (method_name.ident.name == sym::as_str || method_name.ident.name == sym::as_ref) && { let arg_type = cx.typeck_results().expr_ty(receiver); let base_type = arg_type.peel_refs(); - *base_type.kind() == ty::Str || is_type_diagnostic_item(cx, base_type, sym::String) + *base_type.kind() == ty::Str || is_type_lang_item(cx, base_type, hir::LangItem::String) } { receiver } else { @@ -50,7 +50,7 @@ pub(super) fn check<'tcx>( // converted to string. fn requires_to_string(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool { let arg_ty = cx.typeck_results().expr_ty(arg); - if is_type_diagnostic_item(cx, arg_ty, sym::String) { + if is_type_lang_item(cx, arg_ty, hir::LangItem::String) { return false; } if let ty::Ref(_, ty, ..) = arg_ty.kind() { diff --git a/clippy_lints/src/methods/inefficient_to_string.rs b/clippy_lints/src/methods/inefficient_to_string.rs index ede3b8bb74e9..4f4f543e8a91 100644 --- a/clippy_lints/src/methods/inefficient_to_string.rs +++ b/clippy_lints/src/methods/inefficient_to_string.rs @@ -1,13 +1,13 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_with_applicability; -use clippy_utils::ty::{is_type_diagnostic_item, walk_ptrs_ty_depth}; +use clippy_utils::ty::{is_type_lang_item, walk_ptrs_ty_depth}; use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_middle::ty::{self, Ty}; -use rustc_span::symbol::{sym, Symbol}; +use rustc_span::symbol::{Symbol, sym}; use super::INEFFICIENT_TO_STRING; @@ -60,7 +60,7 @@ fn specializes_tostring(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { return true; } - if is_type_diagnostic_item(cx, ty, sym::String) { + if is_type_lang_item(cx, ty, hir::LangItem::String) { return true; } diff --git a/clippy_lints/src/methods/manual_str_repeat.rs b/clippy_lints/src/methods/manual_str_repeat.rs index 8b6b8f1bf16c..13c47c03a80d 100644 --- a/clippy_lints/src/methods/manual_str_repeat.rs +++ b/clippy_lints/src/methods/manual_str_repeat.rs @@ -36,14 +36,14 @@ fn parse_repeat_arg(cx: &LateContext<'_>, e: &Expr<'_>) -> Option { } } else { let ty = cx.typeck_results().expr_ty(e); - if is_type_diagnostic_item(cx, ty, sym::String) + if is_type_lang_item(cx, ty, LangItem::String) || (is_type_lang_item(cx, ty, LangItem::OwnedBox) && get_ty_param(ty).map_or(false, Ty::is_str)) || (is_type_diagnostic_item(cx, ty, sym::Cow) && get_ty_param(ty).map_or(false, Ty::is_str)) { Some(RepeatKind::String) } else { let ty = ty.peel_refs(); - (ty.is_str() || is_type_diagnostic_item(cx, ty, sym::String)).then_some(RepeatKind::String) + (ty.is_str() || is_type_lang_item(cx, ty, LangItem::String)).then_some(RepeatKind::String) } } } @@ -58,7 +58,7 @@ pub(super) fn check( if_chain! { if let ExprKind::Call(repeat_fn, [repeat_arg]) = take_self_arg.kind; if is_path_diagnostic_item(cx, repeat_fn, sym::iter_repeat); - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(collect_expr), sym::String); + if is_type_lang_item(cx, cx.typeck_results().expr_ty(collect_expr), LangItem::String); if let Some(collect_id) = cx.typeck_results().type_dependent_def_id(collect_expr.hir_id); if let Some(take_id) = cx.typeck_results().type_dependent_def_id(take_expr.hir_id); if let Some(iter_trait_id) = cx.tcx.get_diagnostic_item(sym::Iterator); diff --git a/clippy_lints/src/methods/no_effect_replace.rs b/clippy_lints/src/methods/no_effect_replace.rs index a76341855b6d..01655e860c43 100644 --- a/clippy_lints/src/methods/no_effect_replace.rs +++ b/clippy_lints/src/methods/no_effect_replace.rs @@ -1,11 +1,10 @@ use clippy_utils::diagnostics::span_lint; -use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::ty::is_type_lang_item; use clippy_utils::SpanlessEq; use if_chain::if_chain; use rustc_ast::LitKind; -use rustc_hir::ExprKind; +use rustc_hir::{ExprKind, LangItem}; use rustc_lint::LateContext; -use rustc_span::sym; use super::NO_EFFECT_REPLACE; @@ -16,7 +15,7 @@ pub(super) fn check<'tcx>( arg2: &'tcx rustc_hir::Expr<'_>, ) { let ty = cx.typeck_results().expr_ty(expr).peel_refs(); - if !(ty.is_str() || is_type_diagnostic_item(cx, ty, sym::String)) { + if !(ty.is_str() || is_type_lang_item(cx, ty, LangItem::String)) { return; } diff --git a/clippy_lints/src/methods/repeat_once.rs b/clippy_lints/src/methods/repeat_once.rs index 0a14f9216ab3..a345ec813ff5 100644 --- a/clippy_lints/src/methods/repeat_once.rs +++ b/clippy_lints/src/methods/repeat_once.rs @@ -1,11 +1,10 @@ use clippy_utils::consts::{constant_context, Constant}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; -use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::ty::is_type_lang_item; use rustc_errors::Applicability; -use rustc_hir::Expr; +use rustc_hir::{Expr, LangItem}; use rustc_lint::LateContext; -use rustc_span::sym; use super::REPEAT_ONCE; @@ -37,7 +36,7 @@ pub(super) fn check<'tcx>( format!("{}.to_vec()", snippet(cx, recv.span, r#""...""#)), Applicability::MachineApplicable, ); - } else if is_type_diagnostic_item(cx, ty, sym::String) { + } else if is_type_lang_item(cx, ty, LangItem::String) { span_lint_and_sugg( cx, REPEAT_ONCE, diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs index 324c9c17b5a9..1c031ad6acba 100644 --- a/clippy_lints/src/methods/search_is_some.rs +++ b/clippy_lints/src/methods/search_is_some.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg}; use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::sugg::deref_closure_args; -use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::ty::is_type_lang_item; use clippy_utils::{is_trait_method, strip_pat_refs}; use if_chain::if_chain; use rustc_errors::Applicability; @@ -105,7 +105,7 @@ pub(super) fn check<'tcx>( else if search_method == "find" { let is_string_or_str_slice = |e| { let self_ty = cx.typeck_results().expr_ty(e).peel_refs(); - if is_type_diagnostic_item(cx, self_ty, sym::String) { + if is_type_lang_item(cx, self_ty, hir::LangItem::String) { true } else { *self_ty.kind() == ty::Str diff --git a/clippy_lints/src/methods/string_extend_chars.rs b/clippy_lints/src/methods/string_extend_chars.rs index 6974260f70db..6f4cec546e96 100644 --- a/clippy_lints/src/methods/string_extend_chars.rs +++ b/clippy_lints/src/methods/string_extend_chars.rs @@ -1,18 +1,17 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::method_chain_args; use clippy_utils::source::snippet_with_applicability; -use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::ty::is_type_lang_item; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_middle::ty; -use rustc_span::symbol::sym; use super::STRING_EXTEND_CHARS; pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>) { let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs(); - if !is_type_diagnostic_item(cx, obj_ty, sym::String) { + if !is_type_lang_item(cx, obj_ty, hir::LangItem::String) { return; } if let Some(arglists) = method_chain_args(arg, &["chars"]) { @@ -20,7 +19,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr let self_ty = cx.typeck_results().expr_ty(target).peel_refs(); let ref_str = if *self_ty.kind() == ty::Str { "" - } else if is_type_diagnostic_item(cx, self_ty, sym::String) { + } else if is_type_lang_item(cx, self_ty, hir::LangItem::String) { "&" } else { return; diff --git a/clippy_lints/src/methods/unnecessary_join.rs b/clippy_lints/src/methods/unnecessary_join.rs index 973b8a7e6bf6..c9b87bc6bf29 100644 --- a/clippy_lints/src/methods/unnecessary_join.rs +++ b/clippy_lints/src/methods/unnecessary_join.rs @@ -1,10 +1,10 @@ -use clippy_utils::{diagnostics::span_lint_and_sugg, ty::is_type_diagnostic_item}; +use clippy_utils::{diagnostics::span_lint_and_sugg, ty::is_type_lang_item}; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind}; +use rustc_hir::{Expr, ExprKind, LangItem}; use rustc_lint::LateContext; use rustc_middle::ty::{Ref, Slice}; -use rustc_span::{sym, Span}; +use rustc_span::Span; use super::UNNECESSARY_JOIN; @@ -21,7 +21,7 @@ pub(super) fn check<'tcx>( // the turbofish for collect is ::> if let Ref(_, ref_type, _) = collect_output_adjusted_type.kind(); if let Slice(slice) = ref_type.kind(); - if is_type_diagnostic_item(cx, *slice, sym::String); + if is_type_lang_item(cx, *slice, LangItem::String); // the argument for join is "" if let ExprKind::Lit(spanned) = &join_arg.kind; if let LitKind::Str(symbol, _) = spanned.node; diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index b2e9ce5c94d6..79aa15b06ef4 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_then}; use clippy_utils::ptr::get_spans; use clippy_utils::source::{snippet, snippet_opt}; -use clippy_utils::ty::{implements_trait, is_copy, is_type_diagnostic_item}; +use clippy_utils::ty::{implements_trait, is_copy, is_type_diagnostic_item, is_type_lang_item}; use clippy_utils::{get_trait_def_id, is_self, paths}; use if_chain::if_chain; use rustc_ast::ast::Attribute; @@ -11,7 +11,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{ BindingAnnotation, Body, FnDecl, GenericArg, HirId, Impl, ItemKind, Mutability, Node, PatKind, QPath, TyKind, }; -use rustc_hir::{HirIdMap, HirIdSet}; +use rustc_hir::{HirIdMap, HirIdSet, LangItem}; use rustc_hir_typeck::expr_use_visitor as euv; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; @@ -249,7 +249,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { } } - if is_type_diagnostic_item(cx, ty, sym::String) { + if is_type_lang_item(cx, ty, LangItem::String) { if let Some(clone_spans) = get_spans(cx, Some(body.id()), idx, &[("clone", ".to_string()"), ("as_str", "")]) { diag.span_suggestion( diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 0d74c90a834f..612ee8a55a66 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -450,7 +450,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>( substs.type_at(0), ), ), - Some(sym::String) => ( + _ if Some(adt.did()) == cx.tcx.lang_items().string() => ( [("clone", ".to_owned()"), ("as_str", "")].as_slice(), DerefTy::Str, ), diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index aedbe08e3e46..c1677fb3da1c 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -1,12 +1,12 @@ use clippy_utils::diagnostics::{span_lint_hir, span_lint_hir_and_then}; use clippy_utils::mir::{visit_local_usage, LocalUsage, PossibleBorrowerMap}; use clippy_utils::source::snippet_opt; -use clippy_utils::ty::{has_drop, is_copy, is_type_diagnostic_item, walk_ptrs_ty_depth}; +use clippy_utils::ty::{has_drop, is_copy, is_type_diagnostic_item, is_type_lang_item, walk_ptrs_ty_depth}; use clippy_utils::{fn_has_unsatisfiable_preds, match_def_path, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; -use rustc_hir::{def_id, Body, FnDecl, HirId}; +use rustc_hir::{def_id, Body, FnDecl, HirId, LangItem}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir; use rustc_middle::ty::{self, Ty}; @@ -102,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone { let from_borrow = match_def_path(cx, fn_def_id, &paths::CLONE_TRAIT_METHOD) || match_def_path(cx, fn_def_id, &paths::TO_OWNED_METHOD) || (match_def_path(cx, fn_def_id, &paths::TO_STRING_METHOD) - && is_type_diagnostic_item(cx, arg_ty, sym::String)); + && is_type_lang_item(cx, arg_ty, LangItem::String)); let from_deref = !from_borrow && (match_def_path(cx, fn_def_id, &paths::PATH_TO_PATH_BUF) diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index d356c99c8fc4..f4705481d4e6 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg}; use clippy_utils::source::{snippet, snippet_with_applicability}; -use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::ty::is_type_lang_item; use clippy_utils::{get_parent_expr, is_lint_allowed, match_function_call, method_calls, paths}; use clippy_utils::{peel_blocks, SpanlessEq}; use if_chain::if_chain; @@ -190,7 +190,7 @@ impl<'tcx> LateLintPass<'tcx> for StringAdd { }, ExprKind::Index(target, _idx) => { let e_ty = cx.typeck_results().expr_ty(target).peel_refs(); - if matches!(e_ty.kind(), ty::Str) || is_type_diagnostic_item(cx, e_ty, sym::String) { + if matches!(e_ty.kind(), ty::Str) || is_type_lang_item(cx, e_ty, LangItem::String) { span_lint( cx, STRING_SLICE, @@ -205,7 +205,7 @@ impl<'tcx> LateLintPass<'tcx> for StringAdd { } fn is_string(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { - is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(e).peel_refs(), sym::String) + is_type_lang_item(cx, cx.typeck_results().expr_ty(e).peel_refs(), LangItem::String) } fn is_add(cx: &LateContext<'_>, src: &Expr<'_>, target: &Expr<'_>) -> bool { @@ -446,7 +446,7 @@ impl<'tcx> LateLintPass<'tcx> for StringToString { if let ExprKind::MethodCall(path, self_arg, ..) = &expr.kind; if path.ident.name == sym::to_string; let ty = cx.typeck_results().expr_ty(self_arg); - if is_type_diagnostic_item(cx, ty, sym::String); + if is_type_lang_item(cx, ty, LangItem::String); then { span_lint_and_help( cx, diff --git a/clippy_lints/src/types/box_collection.rs b/clippy_lints/src/types/box_collection.rs index 08020ce66381..802415e163df 100644 --- a/clippy_lints/src/types/box_collection.rs +++ b/clippy_lints/src/types/box_collection.rs @@ -37,18 +37,19 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_ fn get_std_collection(cx: &LateContext<'_>, qpath: &QPath<'_>) -> Option { let param = qpath_generic_tys(qpath).next()?; let id = path_def_id(cx, param)?; - cx.tcx.get_diagnostic_name(id).filter(|&name| { - matches!( - name, - sym::HashMap - | sym::String - | sym::Vec - | sym::HashSet - | sym::VecDeque - | sym::LinkedList - | sym::BTreeMap - | sym::BTreeSet - | sym::BinaryHeap - ) - }) + cx.tcx + .get_diagnostic_name(id) + .filter(|&name| matches!(name, sym::HashMap | sym::Vec | sym::HashSet + | sym::VecDeque + | sym::LinkedList + | sym::BTreeMap + | sym::BTreeSet + | sym::BinaryHeap)) + .or_else(|| { + cx.tcx + .lang_items() + .string() + .filter(|did| id == *did) + .map(|_| sym::String) + }) } diff --git a/clippy_lints/src/types/rc_buffer.rs b/clippy_lints/src/types/rc_buffer.rs index fa567b9b2d24..855137b14d84 100644 --- a/clippy_lints/src/types/rc_buffer.rs +++ b/clippy_lints/src/types/rc_buffer.rs @@ -91,10 +91,10 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_ fn match_buffer_type(cx: &LateContext<'_>, qpath: &QPath<'_>) -> Option<&'static str> { let ty = qpath_generic_tys(qpath).next()?; let id = path_def_id(cx, ty)?; - let path = match cx.tcx.get_diagnostic_name(id)? { - sym::String => "str", - sym::OsString => "std::ffi::OsStr", - sym::PathBuf => "std::path::Path", + let path = match cx.tcx.get_diagnostic_name(id) { + Some(sym::OsString) => "std::ffi::OsStr", + Some(sym::PathBuf) => "std::path::Path", + _ if Some(id) == cx.tcx.lang_items().string() => "str", _ => return None, }; Some(path) diff --git a/clippy_lints/src/unnecessary_owned_empty_strings.rs b/clippy_lints/src/unnecessary_owned_empty_strings.rs index ab73f0fc44f4..9f207d32fcff 100644 --- a/clippy_lints/src/unnecessary_owned_empty_strings.rs +++ b/clippy_lints/src/unnecessary_owned_empty_strings.rs @@ -1,13 +1,12 @@ -use clippy_utils::{diagnostics::span_lint_and_sugg, ty::is_type_diagnostic_item}; +use clippy_utils::{diagnostics::span_lint_and_sugg, ty::is_type_lang_item}; use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; -use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability}; +use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; declare_clippy_lint! { /// ### What it does @@ -61,7 +60,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryOwnedEmptyStrings { if let LitKind::Str(symbol, _) = spanned.node; if symbol.is_empty(); let inner_expr_type = cx.typeck_results().expr_ty(inner_expr); - if is_type_diagnostic_item(cx, inner_expr_type, sym::String); + if is_type_lang_item(cx, inner_expr_type, LangItem::String); then { span_lint_and_sugg( cx, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index d32cf1a79367..fac91dfdbda0 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -434,6 +434,16 @@ pub fn is_expr_path_def_path(cx: &LateContext<'_>, expr: &Expr<'_>, segments: &[ path_def_id(cx, expr).map_or(false, |id| match_def_path(cx, id, segments)) } +/// If `maybe_path` is a path node which resolves to an item, resolves it to a `DefId` and checks if +/// it matches the given lang item. +pub fn is_path_lang_item<'tcx>( + cx: &LateContext<'_>, + maybe_path: &impl MaybePath<'tcx>, + lang_item: LangItem, +) -> bool { + path_def_id(cx, maybe_path).map_or(false, |id| cx.tcx.lang_items().get(lang_item) == Some(id)) +} + /// If `maybe_path` is a path node which resolves to an item, resolves it to a `DefId` and checks if /// it matches the given diagnostic item. pub fn is_path_diagnostic_item<'tcx>( @@ -760,7 +770,6 @@ pub fn can_mut_borrow_both(cx: &LateContext<'_>, e1: &Expr<'_>, e2: &Expr<'_>) - /// constructor from the std library fn is_default_equivalent_ctor(cx: &LateContext<'_>, def_id: DefId, path: &QPath<'_>) -> bool { let std_types_symbols = &[ - sym::String, sym::Vec, sym::VecDeque, sym::LinkedList, @@ -777,7 +786,7 @@ fn is_default_equivalent_ctor(cx: &LateContext<'_>, def_id: DefId, path: &QPath< if let Some(adt) = cx.tcx.type_of(impl_did).ty_adt_def() { return std_types_symbols .iter() - .any(|&symbol| cx.tcx.is_diagnostic_item(symbol, adt.did())); + .any(|&symbol| cx.tcx.is_diagnostic_item(symbol, adt.did()) || Some(adt.did()) == cx.tcx.lang_items().string()); } } } @@ -834,7 +843,7 @@ fn is_default_equivalent_from(cx: &LateContext<'_>, from_func: &Expr<'_>, arg: & ExprKind::Lit(hir::Lit { node: LitKind::Str(ref sym, _), .. - }) => return sym.is_empty() && is_path_diagnostic_item(cx, ty, sym::String), + }) => return sym.is_empty() && is_path_lang_item(cx, ty, LangItem::String), ExprKind::Array([]) => return is_path_diagnostic_item(cx, ty, sym::Vec), ExprKind::Repeat(_, ArrayLen::Body(len)) => { if let ExprKind::Lit(ref const_lit) = cx.tcx.hir().body(len.body).value.kind && From 1db64aeb474c7255cd97d37f0f023fb428b19505 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 19 Nov 2022 02:22:24 +0000 Subject: [PATCH 0671/1222] drive-by: Add is_async fn to hir::IsAsync --- clippy_lints/src/manual_async_fn.rs | 4 ++-- clippy_lints/src/unused_async.rs | 4 ++-- clippy_utils/src/lib.rs | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 090f9f8ff73c..5c6a342b3d07 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -6,7 +6,7 @@ use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{ AsyncGeneratorKind, Block, Body, Closure, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound, - HirId, IsAsync, ItemKind, LifetimeName, Term, TraitRef, Ty, TyKind, TypeBindingKind, + HirId, ItemKind, LifetimeName, Term, TraitRef, Ty, TyKind, TypeBindingKind, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn { ) { if_chain! { if let Some(header) = kind.header(); - if header.asyncness == IsAsync::NotAsync; + if !header.asyncness.is_async(); // Check that this function returns `impl Future` if let FnRetTy::Return(ret_ty) = decl.output; if let Some((trait_ref, output_lifetimes)) = future_trait_ref(cx, ret_ty); diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index bf487c7ca20c..3538bef6e061 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, Visitor}; -use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, IsAsync, YieldSource}; +use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, YieldSource}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync { span: Span, hir_id: HirId, ) { - if !span.from_expansion() && fn_kind.asyncness() == IsAsync::Async { + if !span.from_expansion() && fn_kind.asyncness().is_async() { let mut visitor = AsyncFnVisitor { cx, found_await: false }; walk_fn(&mut visitor, fn_kind, fn_decl, body.id(), hir_id); if !visitor.found_await { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index d32cf1a79367..bb91317d67f5 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -87,10 +87,10 @@ use rustc_hir::hir_id::{HirIdMap, HirIdSet}; use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; use rustc_hir::LangItem::{OptionNone, ResultErr, ResultOk}; use rustc_hir::{ - def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Closure, Constness, Destination, Expr, - ExprKind, FnDecl, HirId, Impl, ImplItem, ImplItemKind, IsAsync, Item, ItemKind, LangItem, Local, MatchSource, - Mutability, Node, Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, - TraitRef, TyKind, UnOp, + def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Closure, Constness, + Destination, Expr, ExprKind, FnDecl, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, + LangItem, Local, MatchSource, Mutability, Node, Param, Pat, PatKind, Path, PathSegment, PrimTy, + QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitRef, TyKind, UnOp, }; use rustc_lexer::{tokenize, TokenKind}; use rustc_lint::{LateContext, Level, Lint, LintContext}; @@ -1861,7 +1861,7 @@ pub fn if_sequence<'tcx>(mut expr: &'tcx Expr<'tcx>) -> (Vec<&'tcx Expr<'tcx>>, /// Checks if the given function kind is an async function. pub fn is_async_fn(kind: FnKind<'_>) -> bool { - matches!(kind, FnKind::ItemFn(_, _, header) if header.asyncness == IsAsync::Async) + matches!(kind, FnKind::ItemFn(_, _, header) if header.asyncness.is_async()) } /// Peels away all the compiler generated code surrounding the body of an async function, From b06f0a3c39b62e808c36ce05912f07684ab5aed5 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 19 Nov 2022 03:28:56 +0000 Subject: [PATCH 0672/1222] drive-by: PolyExistentialPredicate --- clippy_lints/src/ptr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index c8c6f32c6c98..180d534636e0 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -687,7 +687,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: fn matches_preds<'tcx>( cx: &LateContext<'tcx>, ty: Ty<'tcx>, - preds: &'tcx [Binder<'tcx, ExistentialPredicate<'tcx>>], + preds: &'tcx [ty::PolyExistentialPredicate<'tcx>], ) -> bool { let infcx = cx.tcx.infer_ctxt().build(); preds.iter().all(|&p| match cx.tcx.erase_late_bound_regions(p) { From 4f04670249375dbceb565ed3cb7b23891380a7d9 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 2 Nov 2022 15:10:05 +0000 Subject: [PATCH 0673/1222] Add an always-ambiguous predicate to make sure that we don't accidentlally allow trait resolution to prove false things during coherence --- clippy_utils/src/qualify_min_const_fn.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 45b63a4aa5df..b48bacb9ace6 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -37,6 +37,7 @@ pub fn is_min_const_fn<'a, 'tcx>(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {predicate:#?}"), ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {predicate:#?}"), ty::PredicateKind::Coerce(_) => panic!("coerce predicate on function: {predicate:#?}"), + ty::PredicateKind::Ambiguous => panic!("ambiguous predicate on function: {predicate:#?}"), } } match predicates.parent { From 6a21cbcce0a65c258432ac7dfe104aca42db27b3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 25 Oct 2022 20:15:15 +0400 Subject: [PATCH 0674/1222] Unreserve braced enum variants in value namespace --- clippy_lints/src/matches/match_wild_enum.rs | 14 +++++++------- .../utils/internal_lints/unnecessary_def_path.rs | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/matches/match_wild_enum.rs b/clippy_lints/src/matches/match_wild_enum.rs index 6f8d766aef7c..7f8d124838cb 100644 --- a/clippy_lints/src/matches/match_wild_enum.rs +++ b/clippy_lints/src/matches/match_wild_enum.rs @@ -65,14 +65,14 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { _ => return, }; if arm.guard.is_none() { - missing_variants.retain(|e| e.ctor_def_id != Some(id)); + missing_variants.retain(|e| e.ctor_def_id() != Some(id)); } path }, PatKind::TupleStruct(path, patterns, ..) => { if let Some(id) = cx.qpath_res(path, pat.hir_id).opt_def_id() { if arm.guard.is_none() && patterns.iter().all(|p| !is_refutable(cx, p)) { - missing_variants.retain(|e| e.ctor_def_id != Some(id)); + missing_variants.retain(|e| e.ctor_def_id() != Some(id)); } } path @@ -122,11 +122,11 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { s }, variant.name, - match variant.ctor_kind { - CtorKind::Fn if variant.fields.len() == 1 => "(_)", - CtorKind::Fn => "(..)", - CtorKind::Const => "", - CtorKind::Fictive => "{ .. }", + match variant.ctor_kind() { + Some(CtorKind::Fn) if variant.fields.len() == 1 => "(_)", + Some(CtorKind::Fn) => "(..)", + Some(CtorKind::Const) => "", + None => "{ .. }", } ) }; diff --git a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs index cfba7fa8791d..f2276395fed0 100644 --- a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs +++ b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs @@ -133,11 +133,11 @@ impl UnnecessaryDefPath { let has_ctor = match cx.tcx.def_kind(def_id) { DefKind::Struct => { let variant = cx.tcx.adt_def(def_id).non_enum_variant(); - variant.ctor_def_id.is_some() && variant.fields.iter().all(|f| f.vis.is_public()) + variant.ctor.is_some() && variant.fields.iter().all(|f| f.vis.is_public()) }, DefKind::Variant => { let variant = cx.tcx.adt_def(cx.tcx.parent(def_id)).variant_with_id(def_id); - variant.ctor_def_id.is_some() && variant.fields.iter().all(|f| f.vis.is_public()) + variant.ctor.is_some() && variant.fields.iter().all(|f| f.vis.is_public()) }, _ => false, }; From 2c1fbd8a4f6ada56fba7a2d4eb39a92ee12679c3 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Mon, 21 Nov 2022 20:52:12 +0100 Subject: [PATCH 0675/1222] Fix declare_clippy_lint crate --- declare_clippy_lint/Cargo.toml | 3 +++ declare_clippy_lint/src/lib.rs | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/declare_clippy_lint/Cargo.toml b/declare_clippy_lint/Cargo.toml index 578109840fb7..082570f1fe5d 100644 --- a/declare_clippy_lint/Cargo.toml +++ b/declare_clippy_lint/Cargo.toml @@ -11,3 +11,6 @@ proc-macro = true itertools = "0.10.1" quote = "1.0.21" syn = "1.0.100" + +[features] +deny-warnings = [] diff --git a/declare_clippy_lint/src/lib.rs b/declare_clippy_lint/src/lib.rs index 962766916dd1..26210556d652 100644 --- a/declare_clippy_lint/src/lib.rs +++ b/declare_clippy_lint/src/lib.rs @@ -1,5 +1,7 @@ #![feature(let_chains)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] +// warn on lints, that are included in `rust-lang/rust`s bootstrap +#![warn(rust_2018_idioms, unused_lifetimes)] use proc_macro::TokenStream; use quote::{format_ident, quote}; @@ -29,7 +31,7 @@ struct ClippyLint { } impl Parse for ClippyLint { - fn parse(input: ParseStream) -> Result { + fn parse(input: ParseStream<'_>) -> Result { let attrs = input.call(Attribute::parse_outer)?; let mut in_code = false; From 1fe17422ab6eb45597871bca444e37d9df45064c Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Mon, 21 Nov 2022 21:04:59 +0100 Subject: [PATCH 0676/1222] Clippy: Don't import GenericParamDefKind --- clippy_utils/src/ty.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 897edfc5495f..a26cdf647164 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -13,9 +13,9 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::ty::{ - self, AdtDef, AssocKind, Binder, BoundRegion, DefIdTree, FnSig, GenericParamDefKind, IntTy, List, ParamEnv, - Predicate, PredicateKind, ProjectionTy, Region, RegionKind, SubstsRef, Ty, TyCtxt, TypeSuperVisitable, - TypeVisitable, TypeVisitor, UintTy, VariantDef, VariantDiscr, + self, AdtDef, AssocKind, Binder, BoundRegion, DefIdTree, FnSig, IntTy, List, ParamEnv, Predicate, PredicateKind, + ProjectionTy, Region, RegionKind, SubstsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy, + VariantDef, VariantDiscr, }; use rustc_middle::ty::{GenericArg, GenericArgKind}; use rustc_span::symbol::Ident; @@ -1011,7 +1011,7 @@ pub fn make_projection<'tcx>( assoc_item.def_id, substs.len(), generic_count, - params.map(GenericParamDefKind::descr).collect::>(), + params.map(ty::GenericParamDefKind::descr).collect::>(), substs, ); @@ -1022,9 +1022,9 @@ pub fn make_projection<'tcx>( .find(|(_, (param, arg))| { !matches!( (param, arg), - (GenericParamDefKind::Lifetime, GenericArgKind::Lifetime(_)) - | (GenericParamDefKind::Type { .. }, GenericArgKind::Type(_)) - | (GenericParamDefKind::Const { .. }, GenericArgKind::Const(_)) + (ty::GenericParamDefKind::Lifetime, GenericArgKind::Lifetime(_)) + | (ty::GenericParamDefKind::Type { .. }, GenericArgKind::Type(_)) + | (ty::GenericParamDefKind::Const { .. }, GenericArgKind::Const(_)) ) }) { @@ -1036,7 +1036,7 @@ pub fn make_projection<'tcx>( idx, param.descr(), arg, - params.map(GenericParamDefKind::descr).collect::>(), + params.map(ty::GenericParamDefKind::descr).collect::>(), substs, ); } From 539592322b0b48a1ef012d1b35b3f77588cad4e0 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 17 Nov 2022 13:00:35 +0000 Subject: [PATCH 0677/1222] Allow iterators instead of requiring slices that will get turned into iterators --- clippy_lints/src/bool_assert_comparison.rs | 2 +- clippy_lints/src/dereference.rs | 2 +- clippy_utils/src/ty.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/bool_assert_comparison.rs b/clippy_lints/src/bool_assert_comparison.rs index 4bd55c1429c3..82d368bb8bc2 100644 --- a/clippy_lints/src/bool_assert_comparison.rs +++ b/clippy_lints/src/bool_assert_comparison.rs @@ -59,7 +59,7 @@ fn is_impl_not_trait_with_bool_out(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { ) }) .map_or(false, |assoc_item| { - let proj = cx.tcx.mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(ty, &[])); + let proj = cx.tcx.mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(ty, [])); let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj); nty.is_bool() diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 218dbeaddcad..03d865af374a 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1263,7 +1263,7 @@ fn replace_types<'tcx>( let item_def_id = projection_predicate.projection_ty.item_def_id; let assoc_item = cx.tcx.associated_item(item_def_id); let projection = cx.tcx - .mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(new_ty, &[])); + .mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(new_ty, [])); if let Ok(projected_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, projection) && substs[term_param_ty.index as usize] != ty::GenericArg::from(projected_ty) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 3a144c2bb223..a1698a61e601 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -79,7 +79,7 @@ pub fn get_associated_type<'tcx>( .associated_items(trait_id) .find_by_name_and_kind(cx.tcx, Ident::from_str(name), ty::AssocKind::Type, trait_id) .and_then(|assoc| { - let proj = cx.tcx.mk_projection(assoc.def_id, cx.tcx.mk_substs_trait(ty, &[])); + let proj = cx.tcx.mk_projection(assoc.def_id, cx.tcx.mk_substs_trait(ty, [])); cx.tcx.try_normalize_erasing_regions(cx.param_env, proj).ok() }) } From 49baf46493046005fb9a414b80b47e9bd740f77e Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 18 Nov 2022 19:58:07 +0000 Subject: [PATCH 0678/1222] Fix clippy's missing substs --- clippy_lints/src/derive.rs | 4 ++-- clippy_lints/src/eta_reduction.rs | 4 +++- clippy_lints/src/methods/unnecessary_to_owned.rs | 4 ++-- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- clippy_lints/src/neg_cmp_op_on_partial_ord.rs | 2 +- clippy_utils/src/ty.rs | 14 +++++++++----- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 102a02138bc8..1d9af7cdbd35 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -466,12 +466,12 @@ fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_r if let Some(def_id) = trait_ref.trait_def_id(); if cx.tcx.is_diagnostic_item(sym::PartialEq, def_id); let param_env = param_env_for_derived_eq(cx.tcx, adt.did(), eq_trait_def_id); - if !implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, &[]); + if !implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, []); // If all of our fields implement `Eq`, we can implement `Eq` too if adt .all_fields() .map(|f| f.ty(cx.tcx, substs)) - .all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, &[])); + .all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, [])); then { span_lint_and_sugg( cx, diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 7b9786d7e570..ea4e5e052d02 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -119,11 +119,13 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { let callee_ty_unadjusted = cx.typeck_results().expr_ty(callee).peel_refs(); if !is_type_diagnostic_item(cx, callee_ty_unadjusted, sym::Arc); if !is_type_diagnostic_item(cx, callee_ty_unadjusted, sym::Rc); + if let ty::Closure(_, substs) = *closure_ty.kind(); then { span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure", |diag| { if let Some(mut snippet) = snippet_opt(cx, callee.span) { if let Some(fn_mut_id) = cx.tcx.lang_items().fn_mut_trait() - && implements_trait(cx, callee_ty.peel_refs(), fn_mut_id, &[]) + && let args = cx.tcx.erase_late_bound_regions(ty::ClosureSubsts { substs }.sig()).inputs() + && implements_trait(cx, callee_ty.peel_refs(), fn_mut_id, &args.iter().copied().map(Into::into).collect::>()) && path_to_local(callee).map_or(false, |l| local_used_after_expr(cx, l, expr)) { // Mutable closure is used after current expr; we cannot consume it. diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index c7775313ecd0..375ebc903b40 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -474,7 +474,7 @@ fn is_cow_into_owned(cx: &LateContext<'_>, method_name: Symbol, method_def_id: D } /// Returns true if the named method is `ToString::to_string` and it's called on a type that -/// is string-like i.e. implements `AsRef` or `Deref`. +/// is string-like i.e. implements `AsRef` or `Deref`. fn is_to_string_on_string_like<'a>( cx: &LateContext<'_>, call_expr: &'a Expr<'a>, @@ -490,7 +490,7 @@ fn is_to_string_on_string_like<'a>( && let GenericArgKind::Type(ty) = generic_arg.unpack() && let Some(deref_trait_id) = cx.tcx.get_diagnostic_item(sym::Deref) && let Some(as_ref_trait_id) = cx.tcx.get_diagnostic_item(sym::AsRef) - && (implements_trait(cx, ty, deref_trait_id, &[cx.tcx.types.str_.into()]) || + && (get_associated_type(cx, ty, deref_trait_id, "Target") == Some(cx.tcx.types.str_) || implements_trait(cx, ty, as_ref_trait_id, &[cx.tcx.types.str_.into()])) { true } else { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 79aa15b06ef4..eeff15bbfb42 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_then}; use clippy_utils::ptr::get_spans; use clippy_utils::source::{snippet, snippet_opt}; -use clippy_utils::ty::{implements_trait, is_copy, is_type_diagnostic_item, is_type_lang_item}; +use clippy_utils::ty::{implements_trait, implements_trait_with_env, is_copy, is_type_diagnostic_item, is_type_lang_item}; use clippy_utils::{get_trait_def_id, is_self, paths}; use if_chain::if_chain; use rustc_ast::ast::Attribute; @@ -185,7 +185,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { if !ty.is_mutable_ptr(); if !is_copy(cx, ty); if ty.is_sized(cx.tcx, cx.param_env); - if !allowed_traits.iter().any(|&t| implements_trait(cx, ty, t, &[])); + if !allowed_traits.iter().any(|&t| implements_trait_with_env(cx.tcx, cx.param_env, ty, t, [None])); if !implements_borrow_trait; if !all_borrowable_trait; diff --git a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs index 5c2b96f5b2ce..a022fc156fca 100644 --- a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs @@ -65,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for NoNegCompOpForPartialOrd { let implements_partial_ord = { if let Some(id) = cx.tcx.lang_items().partial_ord_trait() { - implements_trait(cx, ty, id, &[]) + implements_trait(cx, ty, id, &[ty.into()]) } else { return; } diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index a1698a61e601..a8047fe9e5ea 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -9,7 +9,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, FnDecl, LangItem, TyKind, Unsafety}; -use rustc_infer::infer::TyCtxtInferExt; +use rustc_infer::infer::{TyCtxtInferExt, type_variable::{TypeVariableOrigin, TypeVariableOriginKind}}; use rustc_lint::LateContext; use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::ty::{ @@ -18,7 +18,7 @@ use rustc_middle::ty::{ }; use rustc_middle::ty::{GenericArg, GenericArgKind}; use rustc_span::symbol::Ident; -use rustc_span::{sym, Span, Symbol}; +use rustc_span::{sym, Span, Symbol, DUMMY_SP}; use rustc_target::abi::{Size, VariantIdx}; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::query::normalize::AtExt; @@ -153,7 +153,7 @@ pub fn implements_trait<'tcx>( trait_id: DefId, ty_params: &[GenericArg<'tcx>], ) -> bool { - implements_trait_with_env(cx.tcx, cx.param_env, ty, trait_id, ty_params) + implements_trait_with_env(cx.tcx, cx.param_env, ty, trait_id, ty_params.iter().map(|&arg| Some(arg))) } /// Same as `implements_trait` but allows using a `ParamEnv` different from the lint context. @@ -162,7 +162,7 @@ pub fn implements_trait_with_env<'tcx>( param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, trait_id: DefId, - ty_params: &[GenericArg<'tcx>], + ty_params: impl IntoIterator>>, ) -> bool { // Clippy shouldn't have infer types assert!(!ty.needs_infer()); @@ -171,8 +171,12 @@ pub fn implements_trait_with_env<'tcx>( if ty.has_escaping_bound_vars() { return false; } - let ty_params = tcx.mk_substs(ty_params.iter()); let infcx = tcx.infer_ctxt().build(); + let orig = TypeVariableOrigin { + kind: TypeVariableOriginKind::MiscVariable, + span: DUMMY_SP, + }; + let ty_params = tcx.mk_substs(ty_params.into_iter().map(|arg| arg.unwrap_or_else(|| infcx.next_ty_var(orig).into()))); infcx .type_implements_trait(trait_id, ty, ty_params, param_env) .must_apply_modulo_regions() From 3c7253d36c95e812dda82781db836df5e3ee9f78 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 21 Nov 2022 12:24:53 +0000 Subject: [PATCH 0679/1222] Stop passing the self-type as a separate argument. --- clippy_lints/src/dereference.rs | 12 ++++-------- clippy_lints/src/ptr.rs | 4 ++-- clippy_utils/src/ty.rs | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 03d865af374a..c4e7f8bfe1e2 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -842,14 +842,10 @@ fn walk_parents<'tcx>( } else if let Some(trait_id) = cx.tcx.trait_of_item(id) && let arg_ty = cx.tcx.erase_regions(cx.typeck_results().expr_ty_adjusted(e)) && let ty::Ref(_, sub_ty, _) = *arg_ty.kind() - && let subs = match cx + && let subs = cx .typeck_results() - .node_substs_opt(parent.hir_id) - .and_then(|subs| subs.get(1..)) - { - Some(subs) => cx.tcx.mk_substs(subs.iter().copied()), - None => cx.tcx.mk_substs(std::iter::empty::>()), - } && let impl_ty = if cx.tcx.fn_sig(id).skip_binder().inputs()[0].is_ref() { + .node_substs_opt(parent.hir_id).map(|subs| &subs[1..]).unwrap_or_default() + && let impl_ty = if cx.tcx.fn_sig(id).skip_binder().inputs()[0].is_ref() { // Trait methods taking `&self` sub_ty } else { @@ -858,7 +854,7 @@ fn walk_parents<'tcx>( } && impl_ty.is_ref() && let infcx = cx.tcx.infer_ctxt().build() && infcx - .type_implements_trait(trait_id, impl_ty, subs, cx.param_env) + .type_implements_trait(trait_id, [impl_ty.into()].into_iter().chain(subs.iter().copied()), cx.param_env) .must_apply_modulo_regions() { return Some(Position::MethodReceiverRefImpl) diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index ea00650d42aa..5420a0e782ea 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -692,7 +692,7 @@ fn matches_preds<'tcx>( let infcx = cx.tcx.infer_ctxt().build(); preds.iter().all(|&p| match cx.tcx.erase_late_bound_regions(p) { ExistentialPredicate::Trait(p) => infcx - .type_implements_trait(p.def_id, ty, p.substs, cx.param_env) + .type_implements_trait(p.def_id, [ty.into()].into_iter().chain(p.substs.iter()), cx.param_env) .must_apply_modulo_regions(), ExistentialPredicate::Projection(p) => infcx.predicate_must_hold_modulo_regions(&Obligation::new( cx.tcx, @@ -704,7 +704,7 @@ fn matches_preds<'tcx>( )), )), ExistentialPredicate::AutoTrait(p) => infcx - .type_implements_trait(p, ty, List::empty(), cx.param_env) + .type_implements_trait(p, [ty], cx.param_env) .must_apply_modulo_regions(), }) } diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index a8047fe9e5ea..5ec6f29fe916 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -178,7 +178,7 @@ pub fn implements_trait_with_env<'tcx>( }; let ty_params = tcx.mk_substs(ty_params.into_iter().map(|arg| arg.unwrap_or_else(|| infcx.next_ty_var(orig).into()))); infcx - .type_implements_trait(trait_id, ty, ty_params, param_env) + .type_implements_trait(trait_id, [ty.into()].into_iter().chain(ty_params), param_env) .must_apply_modulo_regions() } From f3d126ee6c663b31944f7da2d03364b054e33c5c Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 21 Nov 2022 16:52:01 +0100 Subject: [PATCH 0680/1222] Use `as_closure` helper method Co-authored-by: lcnr --- clippy_lints/src/eta_reduction.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index ea4e5e052d02..f34cbee03558 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -124,7 +124,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure", |diag| { if let Some(mut snippet) = snippet_opt(cx, callee.span) { if let Some(fn_mut_id) = cx.tcx.lang_items().fn_mut_trait() - && let args = cx.tcx.erase_late_bound_regions(ty::ClosureSubsts { substs }.sig()).inputs() + && let args = cx.tcx.erase_late_bound_regions(substs.as_closure().sig()).inputs() && implements_trait(cx, callee_ty.peel_refs(), fn_mut_id, &args.iter().copied().map(Into::into).collect::>()) && path_to_local(callee).map_or(false, |l| local_used_after_expr(cx, l, expr)) { From a6dce1c9f5479aff54cc7628446099897091d7e2 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 18 Nov 2022 11:24:21 +1100 Subject: [PATCH 0681/1222] Split `MacArgs` in two. `MacArgs` is an enum with three variants: `Empty`, `Delimited`, and `Eq`. It's used in two ways: - For representing attribute macro arguments (e.g. in `AttrItem`), where all three variants are used. - For representing function-like macros (e.g. in `MacCall` and `MacroDef`), where only the `Delimited` variant is used. In other words, `MacArgs` is used in two quite different places due to them having partial overlap. I find this makes the code hard to read. It also leads to various unreachable code paths, and allows invalid values (such as accidentally using `MacArgs::Empty` in a `MacCall`). This commit splits `MacArgs` in two: - `DelimArgs` is a new struct just for the "delimited arguments" case. It is now used in `MacCall` and `MacroDef`. - `AttrArgs` is a renaming of the old `MacArgs` enum for the attribute macro case. Its `Delimited` variant now contains a `DelimArgs`. Various other related things are renamed as well. These changes make the code clearer, avoids several unreachable paths, and disallows the invalid values. --- clippy_lints/src/crate_in_macro_def.rs | 2 +- clippy_utils/src/ast_utils.rs | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/crate_in_macro_def.rs b/clippy_lints/src/crate_in_macro_def.rs index 20cc330e035f..b2fe0386f945 100644 --- a/clippy_lints/src/crate_in_macro_def.rs +++ b/clippy_lints/src/crate_in_macro_def.rs @@ -55,7 +55,7 @@ impl EarlyLintPass for CrateInMacroDef { if_chain! { if item.attrs.iter().any(is_macro_export); if let ItemKind::MacroDef(macro_def) = &item.kind; - let tts = macro_def.body.inner_tokens(); + let tts = macro_def.body.tokens.clone(); if let Some(span) = contains_unhygienic_crate_reference(&tts); then { span_lint_and_sugg( diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 23aed4b5ba2f..87b378bfd198 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -388,7 +388,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { && over(li, ri, |l, r| eq_item(l, r, eq_assoc_item_kind)) }, (MacCall(l), MacCall(r)) => eq_mac_call(l, r), - (MacroDef(l), MacroDef(r)) => l.macro_rules == r.macro_rules && eq_mac_args(&l.body, &r.body), + (MacroDef(l), MacroDef(r)) => l.macro_rules == r.macro_rules && eq_delim_args(&l.body, &r.body), _ => false, } } @@ -709,7 +709,7 @@ pub fn eq_assoc_constraint(l: &AssocConstraint, r: &AssocConstraint) -> bool { } pub fn eq_mac_call(l: &MacCall, r: &MacCall) -> bool { - eq_path(&l.path, &r.path) && eq_mac_args(&l.args, &r.args) + eq_path(&l.path, &r.path) && eq_delim_args(&l.args, &r.args) } pub fn eq_attr(l: &Attribute, r: &Attribute) -> bool { @@ -717,18 +717,22 @@ pub fn eq_attr(l: &Attribute, r: &Attribute) -> bool { l.style == r.style && match (&l.kind, &r.kind) { (DocComment(l1, l2), DocComment(r1, r2)) => l1 == r1 && l2 == r2, - (Normal(l), Normal(r)) => eq_path(&l.item.path, &r.item.path) && eq_mac_args(&l.item.args, &r.item.args), + (Normal(l), Normal(r)) => eq_path(&l.item.path, &r.item.path) && eq_attr_args(&l.item.args, &r.item.args), _ => false, } } -pub fn eq_mac_args(l: &MacArgs, r: &MacArgs) -> bool { - use MacArgs::*; +pub fn eq_attr_args(l: &AttrArgs, r: &AttrArgs) -> bool { + use AttrArgs::*; match (l, r) { (Empty, Empty) => true, - (Delimited(_, ld, lts), Delimited(_, rd, rts)) => ld == rd && lts.eq_unspanned(rts), - (Eq(_, MacArgsEq::Ast(le)), Eq(_, MacArgsEq::Ast(re))) => eq_expr(le, re), - (Eq(_, MacArgsEq::Hir(ll)), Eq(_, MacArgsEq::Hir(rl))) => ll.kind == rl.kind, + (Delimited(la), Delimited(ra)) => eq_delim_args(la, ra), + (Eq(_, AttrArgsEq::Ast(le)), Eq(_, AttrArgsEq::Ast(re))) => eq_expr(le, re), + (Eq(_, AttrArgsEq::Hir(ll)), Eq(_, AttrArgsEq::Hir(rl))) => ll.kind == rl.kind, _ => false, } } + +pub fn eq_delim_args(l: &DelimArgs, r: &DelimArgs) -> bool { + l.delim == r.delim && l.tokens.eq_unspanned(&r.tokens) +} From 292b369437513e8910e682dd63fe852c96c2dc41 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Tue, 22 Nov 2022 14:30:29 +0100 Subject: [PATCH 0682/1222] Clippy: Workaround for let_chains issue --- src/driver.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index ee2a3ad20d3e..ad6132a49baa 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -90,11 +90,12 @@ fn track_files(parse_sess: &mut ParseSess, conf_path_string: Option) { // During development track the `clippy-driver` executable so that cargo will re-run clippy whenever // it is rebuilt - if cfg!(debug_assertions) - && let Ok(current_exe) = env::current_exe() - && let Some(current_exe) = current_exe.to_str() - { - file_depinfo.insert(Symbol::intern(current_exe)); + if cfg!(debug_assertions) { + if let Ok(current_exe) = env::current_exe() + && let Some(current_exe) = current_exe.to_str() + { + file_depinfo.insert(Symbol::intern(current_exe)); + } } } From 4dad5fbe12a5daf3af880136f455edc9cd53acc6 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Tue, 22 Nov 2022 19:52:46 +0000 Subject: [PATCH 0683/1222] Move `get_associated_type` from `clippy` to `rustc_lint` --- .../src/methods/iter_overeager_cloned.rs | 4 +-- .../src/methods/unnecessary_iter_cloned.rs | 4 +-- .../src/methods/unnecessary_to_owned.rs | 27 ++++++++++++------- clippy_utils/src/ty.rs | 19 +------------ 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/clippy_lints/src/methods/iter_overeager_cloned.rs b/clippy_lints/src/methods/iter_overeager_cloned.rs index 06a39c5997e2..b4210d875104 100644 --- a/clippy_lints/src/methods/iter_overeager_cloned.rs +++ b/clippy_lints/src/methods/iter_overeager_cloned.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_opt; -use clippy_utils::ty::{get_associated_type, implements_trait, is_copy}; +use clippy_utils::ty::{implements_trait, is_copy}; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; @@ -25,7 +25,7 @@ pub(super) fn check<'tcx>( && let Some(method_id) = typeck.type_dependent_def_id(cloned_call.hir_id) && cx.tcx.trait_of_item(method_id) == Some(iter_id) && let cloned_recv_ty = typeck.expr_ty_adjusted(cloned_recv) - && let Some(iter_assoc_ty) = get_associated_type(cx, cloned_recv_ty, iter_id, "Item") + && let Some(iter_assoc_ty) = cx.get_associated_type(cloned_recv_ty, iter_id, "Item") && matches!(*iter_assoc_ty.kind(), ty::Ref(_, ty, _) if !is_copy(cx, ty)) { if needs_into_iter diff --git a/clippy_lints/src/methods/unnecessary_iter_cloned.rs b/clippy_lints/src/methods/unnecessary_iter_cloned.rs index 4eb579af7a12..52a4ff7d1ae4 100644 --- a/clippy_lints/src/methods/unnecessary_iter_cloned.rs +++ b/clippy_lints/src/methods/unnecessary_iter_cloned.rs @@ -2,7 +2,7 @@ use super::utils::clone_or_copy_needed; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::higher::ForLoop; use clippy_utils::source::snippet_opt; -use clippy_utils::ty::{get_associated_type, get_iterator_item_ty, implements_trait}; +use clippy_utils::ty::{get_iterator_item_ty, implements_trait}; use clippy_utils::{fn_def_id, get_parent_expr}; use rustc_errors::Applicability; use rustc_hir::{def_id::DefId, Expr, ExprKind}; @@ -54,7 +54,7 @@ pub fn check_for_loop_iter( if let Some(into_iterator_trait_id) = cx.tcx.get_diagnostic_item(sym::IntoIterator); let collection_ty = cx.typeck_results().expr_ty(collection); if implements_trait(cx, collection_ty, into_iterator_trait_id, &[]); - if let Some(into_iter_item_ty) = get_associated_type(cx, collection_ty, into_iterator_trait_id, "Item"); + if let Some(into_iter_item_ty) = cx.get_associated_type(collection_ty, into_iterator_trait_id, "Item"); if iter_item_ty == into_iter_item_ty; if let Some(collection_snippet) = snippet_opt(cx, collection.span); diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 375ebc903b40..8b000cd754cd 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -2,9 +2,11 @@ use super::implicit_clone::is_clone_like; use super::unnecessary_iter_cloned::{self, is_into_iter}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_opt; -use clippy_utils::ty::{get_associated_type, get_iterator_item_ty, implements_trait, is_copy, peel_mid_ty_refs}; +use clippy_utils::ty::{get_iterator_item_ty, implements_trait, is_copy, peel_mid_ty_refs}; use clippy_utils::visitors::find_all_ret_expressions; -use clippy_utils::{fn_def_id, get_parent_expr, is_diag_item_method, is_diag_trait_item, return_ty}; +use clippy_utils::{ + fn_def_id, get_parent_expr, is_diag_item_method, is_diag_trait_item, return_ty, +}; use clippy_utils::{meets_msrv, msrvs}; use rustc_errors::Applicability; use rustc_hir::{def_id::DefId, BorrowKind, Expr, ExprKind, ItemKind, Node}; @@ -18,7 +20,9 @@ use rustc_middle::ty::EarlyBinder; use rustc_middle::ty::{self, ParamTy, PredicateKind, ProjectionPredicate, TraitPredicate, Ty}; use rustc_semver::RustcVersion; use rustc_span::{sym, Symbol}; -use rustc_trait_selection::traits::{query::evaluate_obligation::InferCtxtExt as _, Obligation, ObligationCause}; +use rustc_trait_selection::traits::{ + query::evaluate_obligation::InferCtxtExt as _, Obligation, ObligationCause, +}; use std::cmp::max; use super::UNNECESSARY_TO_OWNED; @@ -146,7 +150,7 @@ fn check_addr_of_expr( if_chain! { if let Some(deref_trait_id) = cx.tcx.get_diagnostic_item(sym::Deref); if implements_trait(cx, receiver_ty, deref_trait_id, &[]); - if get_associated_type(cx, receiver_ty, deref_trait_id, "Target") == Some(target_ty); + if cx.get_associated_type(receiver_ty, deref_trait_id, "Target") == Some(target_ty); then { if n_receiver_refs > 0 { span_lint_and_sugg( @@ -341,13 +345,13 @@ fn get_input_traits_and_projections<'tcx>( if trait_predicate.trait_ref.self_ty() == input { trait_predicates.push(trait_predicate); } - }, + } PredicateKind::Projection(projection_predicate) => { if projection_predicate.projection_ty.self_ty() == input { projection_predicates.push(projection_predicate); } - }, - _ => {}, + } + _ => {} } } (trait_predicates, projection_predicates) @@ -462,7 +466,12 @@ fn is_cloned_or_copied(cx: &LateContext<'_>, method_name: Symbol, method_def_id: /// Returns true if the named method can be used to convert the receiver to its "owned" /// representation. -fn is_to_owned_like<'a>(cx: &LateContext<'a>, call_expr: &Expr<'a>, method_name: Symbol, method_def_id: DefId) -> bool { +fn is_to_owned_like<'a>( + cx: &LateContext<'a>, + call_expr: &Expr<'a>, + method_name: Symbol, + method_def_id: DefId, +) -> bool { is_clone_like(cx, method_name.as_str(), method_def_id) || is_cow_into_owned(cx, method_name, method_def_id) || is_to_string_on_string_like(cx, call_expr, method_name, method_def_id) @@ -490,7 +499,7 @@ fn is_to_string_on_string_like<'a>( && let GenericArgKind::Type(ty) = generic_arg.unpack() && let Some(deref_trait_id) = cx.tcx.get_diagnostic_item(sym::Deref) && let Some(as_ref_trait_id) = cx.tcx.get_diagnostic_item(sym::AsRef) - && (get_associated_type(cx, ty, deref_trait_id, "Target") == Some(cx.tcx.types.str_) || + && (cx.get_associated_type(ty, deref_trait_id, "Target") == Some(cx.tcx.types.str_) || implements_trait(cx, ty, as_ref_trait_id, &[cx.tcx.types.str_.into()])) { true } else { diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 1b65b701409e..8284dc5c28c0 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -117,24 +117,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' pub fn get_iterator_item_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option> { cx.tcx .get_diagnostic_item(sym::Iterator) - .and_then(|iter_did| get_associated_type(cx, ty, iter_did, "Item")) -} - -/// Returns the associated type `name` for `ty` as an implementation of `trait_id`. -/// Do not invoke without first verifying that the type implements the trait. -pub fn get_associated_type<'tcx>( - cx: &LateContext<'tcx>, - ty: Ty<'tcx>, - trait_id: DefId, - name: &str, -) -> Option> { - cx.tcx - .associated_items(trait_id) - .find_by_name_and_kind(cx.tcx, Ident::from_str(name), ty::AssocKind::Type, trait_id) - .and_then(|assoc| { - let proj = cx.tcx.mk_projection(assoc.def_id, cx.tcx.mk_substs_trait(ty, [])); - cx.tcx.try_normalize_erasing_regions(cx.param_env, proj).ok() - }) + .and_then(|iter_did| cx.get_associated_type(ty, iter_did, "Item")) } /// Get the diagnostic name of a type, e.g. `sym::HashMap`. To check if a type From faf596058eb33bd538e9dedafd34bbe6b2415cee Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 5 Nov 2022 22:41:07 +0000 Subject: [PATCH 0684/1222] Separate lifetime ident from resolution in HIR. --- clippy_lints/src/lifetimes.rs | 26 ++++++++++---------------- clippy_lints/src/manual_async_fn.rs | 4 ++-- clippy_lints/src/ptr.rs | 19 +++++++------------ clippy_lints/src/types/borrowed_box.rs | 4 ++-- clippy_utils/src/hir_utils.rs | 16 +++++----------- 5 files changed, 26 insertions(+), 43 deletions(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 0bb9eca15287..5df8b486f332 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -10,7 +10,7 @@ use rustc_hir::lang_items; use rustc_hir::FnRetTy::Return; use rustc_hir::{ BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl, ImplItem, - ImplItemKind, Item, ItemKind, Lifetime, LifetimeName, ParamName, PolyTraitRef, PredicateOrigin, TraitFn, TraitItem, + ImplItemKind, Item, ItemKind, Lifetime, LifetimeName, PolyTraitRef, PredicateOrigin, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate, }; use rustc_lint::{LateContext, LateLintPass}; @@ -180,7 +180,7 @@ fn check_fn_inner<'tcx>( _ => None, }); for bound in lifetimes { - if bound.name != LifetimeName::Static && !bound.is_elided() { + if !bound.is_static() && !bound.is_elided() { return; } } @@ -414,17 +414,13 @@ impl<'a, 'tcx> RefVisitor<'a, 'tcx> { fn record(&mut self, lifetime: &Option) { if let Some(ref lt) = *lifetime { - if lt.name == LifetimeName::Static { + if lt.is_static() { self.lts.push(RefLt::Static); - } else if let LifetimeName::Param(_, ParamName::Fresh) = lt.name { + } else if lt.is_anonymous() { // Fresh lifetimes generated should be ignored. self.lts.push(RefLt::Unnamed); - } else if lt.is_elided() { - self.lts.push(RefLt::Unnamed); - } else if let LifetimeName::Param(def_id, _) = lt.name { + } else if let LifetimeName::Param(def_id) = lt.res { self.lts.push(RefLt::Named(def_id)); - } else { - self.lts.push(RefLt::Unnamed); } } else { self.lts.push(RefLt::Unnamed); @@ -472,7 +468,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { walk_item(self, item); self.lts.truncate(len); self.lts.extend(bounds.iter().filter_map(|bound| match bound { - GenericArg::Lifetime(l) => Some(if let LifetimeName::Param(def_id, _) = l.name { + GenericArg::Lifetime(l) => Some(if let LifetimeName::Param(def_id) = l.res { RefLt::Named(def_id) } else { RefLt::Unnamed @@ -498,10 +494,8 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { } fn visit_generic_arg(&mut self, generic_arg: &'tcx GenericArg<'tcx>) { - if let GenericArg::Lifetime(l) = generic_arg - && let LifetimeName::Param(def_id, _) = l.name - { - self.lifetime_generic_arg_spans.entry(def_id).or_insert(l.span); + if let GenericArg::Lifetime(l) = generic_arg && let LifetimeName::Param(def_id) = l.res { + self.lifetime_generic_arg_spans.entry(def_id).or_insert(l.ident.span); } // Replace with `walk_generic_arg` if/when https://github.com/rust-lang/rust/pull/103692 lands. // walk_generic_arg(self, generic_arg); @@ -577,7 +571,7 @@ where // for lifetimes as parameters of generics fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { - self.map.remove(&lifetime.name.ident().name); + self.map.remove(&lifetime.ident.name); } fn visit_generic_param(&mut self, param: &'tcx GenericParam<'_>) { @@ -653,7 +647,7 @@ struct BodyLifetimeChecker { impl<'tcx> Visitor<'tcx> for BodyLifetimeChecker { // for lifetimes as parameters of generics fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { - if lifetime.name.ident().name != kw::UnderscoreLifetime && lifetime.name.ident().name != kw::StaticLifetime { + if lifetime.ident.name != kw::UnderscoreLifetime && lifetime.ident.name != kw::StaticLifetime { self.lifetimes_used_in_body = true; } } diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 5c6a342b3d07..553980ebf797 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -118,7 +118,7 @@ fn future_trait_ref<'tcx>( .iter() .filter_map(|bound| { if let GenericArg::Lifetime(lt) = bound { - Some(lt.name) + Some(lt.res) } else { None } @@ -153,7 +153,7 @@ fn captures_all_lifetimes(inputs: &[Ty<'_>], output_lifetimes: &[LifetimeName]) .iter() .filter_map(|ty| { if let TyKind::Rptr(lt, _) = ty.kind { - Some(lt.name) + Some(lt.res) } else { None } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 5420a0e782ea..ab960edb7576 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -12,8 +12,8 @@ use rustc_hir::hir_id::HirIdMap; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{ self as hir, AnonConst, BinOpKind, BindingAnnotation, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg, - ImplItemKind, ItemKind, Lifetime, LifetimeName, Mutability, Node, Param, ParamName, PatKind, QPath, TraitFn, - TraitItem, TraitItemKind, TyKind, Unsafety, + ImplItemKind, ItemKind, Lifetime, Mutability, Node, Param, PatKind, QPath, TraitFn, TraitItem, TraitItemKind, + TyKind, Unsafety, }; use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::traits::{Obligation, ObligationCause}; @@ -343,21 +343,16 @@ impl PtrArg<'_> { } struct RefPrefix { - lt: LifetimeName, + lt: Lifetime, mutability: Mutability, } impl fmt::Display for RefPrefix { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use fmt::Write; f.write_char('&')?; - match self.lt { - LifetimeName::Param(_, ParamName::Plain(name)) => { - name.fmt(f)?; - f.write_char(' ')?; - }, - LifetimeName::Infer => f.write_str("'_ ")?, - LifetimeName::Static => f.write_str("'static ")?, - _ => (), + if !self.lt.is_anonymous() { + self.lt.ident.fmt(f)?; + f.write_char(' ')?; } f.write_str(self.mutability.prefix_str()) } @@ -495,7 +490,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>( ty_name: name.ident.name, method_renames, ref_prefix: RefPrefix { - lt: lt.name, + lt: lt.clone(), mutability, }, deref_ty, diff --git a/clippy_lints/src/types/borrowed_box.rs b/clippy_lints/src/types/borrowed_box.rs index 9c6629958401..65dfe7637ea9 100644 --- a/clippy_lints/src/types/borrowed_box.rs +++ b/clippy_lints/src/types/borrowed_box.rs @@ -31,10 +31,10 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m return false; } - let ltopt = if lt.name.is_anonymous() { + let ltopt = if lt.is_anonymous() { String::new() } else { - format!("{} ", lt.name.ident().as_str()) + format!("{} ", lt.ident.as_str()) }; if mut_ty.mutbl == Mutability::Mut { diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 0231a51adf48..48982517751e 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -7,7 +7,7 @@ use rustc_hir::def::Res; use rustc_hir::HirIdMap; use rustc_hir::{ ArrayLen, BinOpKind, BindingAnnotation, Block, BodyId, Closure, Expr, ExprField, ExprKind, FnRetTy, GenericArg, - GenericArgs, Guard, HirId, InlineAsmOperand, Let, Lifetime, LifetimeName, ParamName, Pat, PatField, PatKind, Path, + GenericArgs, Guard, HirId, InlineAsmOperand, Let, Lifetime, LifetimeName, Pat, PatField, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding, }; use rustc_lexer::{tokenize, TokenKind}; @@ -337,7 +337,7 @@ impl HirEqInterExpr<'_, '_, '_> { } fn eq_lifetime(left: &Lifetime, right: &Lifetime) -> bool { - left.name == right.name + left.res == right.res } fn eq_pat_field(&mut self, left: &PatField<'_>, right: &PatField<'_>) -> bool { @@ -925,16 +925,10 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } pub fn hash_lifetime(&mut self, lifetime: &Lifetime) { - std::mem::discriminant(&lifetime.name).hash(&mut self.s); - if let LifetimeName::Param(param_id, ref name) = lifetime.name { - std::mem::discriminant(name).hash(&mut self.s); + lifetime.ident.name.hash(&mut self.s); + std::mem::discriminant(&lifetime.res).hash(&mut self.s); + if let LifetimeName::Param(param_id) = lifetime.res { param_id.hash(&mut self.s); - match name { - ParamName::Plain(ref ident) => { - ident.name.hash(&mut self.s); - }, - ParamName::Fresh | ParamName::Error => {}, - } } } From 15950437c3223cd370008bebccb75f29462d75fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 3 Nov 2022 09:19:23 -0700 Subject: [PATCH 0685/1222] Fix clippy code --- clippy_lints/src/suspicious_operation_groupings.rs | 2 +- clippy_utils/src/ast_utils.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index 78e83880e1a6..e111c7d22915 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -582,7 +582,7 @@ fn ident_difference_expr_with_base_location( | (Block(_, _), Block(_, _)) | (Closure(_), Closure(_)) | (Match(_, _), Match(_, _)) - | (Loop(_, _), Loop(_, _)) + | (Loop(_, _, _), Loop(_, _, _)) | (ForLoop(_, _, _, _), ForLoop(_, _, _, _)) | (While(_, _, _), While(_, _, _)) | (If(_, _, _), If(_, _, _)) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 5c595f74eff2..6bcf0bbd7eb7 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -171,7 +171,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (ForLoop(lp, li, lt, ll), ForLoop(rp, ri, rt, rl)) => { eq_label(ll, rl) && eq_pat(lp, rp) && eq_expr(li, ri) && eq_block(lt, rt) }, - (Loop(lt, ll), Loop(rt, rl)) => eq_label(ll, rl) && eq_block(lt, rt), + (Loop(lt, ll, _), Loop(rt, rl, _)) => eq_label(ll, rl) && eq_block(lt, rt), (Block(lb, ll), Block(rb, rl)) => eq_label(ll, rl) && eq_block(lb, rb), (TryBlock(l), TryBlock(r)) => eq_block(l, r), (Yield(l), Yield(r)) | (Ret(l), Ret(r)) => eq_expr_opt(l, r), From 76a64fa25840ad366db36543491d15559231f7c6 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Fri, 18 Nov 2022 22:56:22 +0100 Subject: [PATCH 0686/1222] Avoid `GenFuture` shim when compiling async constructs Previously, async constructs would be lowered to "normal" generators, with an additional `from_generator` / `GenFuture` shim in between to convert from `Generator` to `Future`. The compiler will now special-case these generators internally so that async constructs will *directly* implement `Future` without the need to go through the `from_generator` / `GenFuture` shim. The primary motivation for this change was hiding this implementation detail in stack traces and debuginfo, but it can in theory also help the optimizer as there is less abstractions to see through. --- clippy_lints/src/doc.rs | 4 +--- clippy_lints/src/manual_async_fn.rs | 2 +- tests/ui/author/blocks.stdout | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 4557e4328854..ae5f9424b232 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -427,9 +427,7 @@ fn lint_for_missing_headers( let body = cx.tcx.hir().body(body_id); let ret_ty = typeck.expr_ty(body.value); if implements_trait(cx, ret_ty, future, &[]); - if let ty::Opaque(_, subs) = ret_ty.kind(); - if let Some(gen) = subs.types().next(); - if let ty::Generator(_, subs, _) = gen.kind(); + if let ty::Generator(_, subs, _) = ret_ty.kind(); if is_type_diagnostic_item(cx, subs.as_generator().return_ty(), sym::Result); then { span_lint( diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 5c6a342b3d07..6a98df499125 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -177,7 +177,7 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) if let Some(args) = cx .tcx .lang_items() - .from_generator_fn() + .identity_future_fn() .and_then(|def_id| match_function_call_with_def_id(cx, block_expr, def_id)); if args.len() == 1; if let Expr { diff --git a/tests/ui/author/blocks.stdout b/tests/ui/author/blocks.stdout index 9de0550d81d0..c6acf24c21ec 100644 --- a/tests/ui/author/blocks.stdout +++ b/tests/ui/author/blocks.stdout @@ -45,7 +45,7 @@ if let ExprKind::Closure(CaptureBy::Value, fn_decl, body_id, _, None) = expr.kin && expr1 = &cx.tcx.hir().body(body_id).value && let ExprKind::Call(func, args) = expr1.kind && let ExprKind::Path(ref qpath) = func.kind - && matches!(qpath, QPath::LangItem(LangItem::FromGenerator, _)) + && matches!(qpath, QPath::LangItem(LangItem::IdentityFuture, _)) && args.len() == 1 && let ExprKind::Closure(CaptureBy::Value, fn_decl1, body_id1, _, Some(Movability::Static)) = args[0].kind && let FnRetTy::DefaultReturn(_) = fn_decl1.output From 19e25439db4d91079d5d3efb58d9d8dfeeb4cf8d Mon Sep 17 00:00:00 2001 From: hkalbasi Date: Tue, 1 Nov 2022 19:50:30 +0330 Subject: [PATCH 0687/1222] move some layout logic to rustc_target::abi::layout --- clippy_lints/src/casts/cast_possible_truncation.rs | 5 ++--- clippy_lints/src/lib.rs | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/casts/cast_possible_truncation.rs b/clippy_lints/src/casts/cast_possible_truncation.rs index 88deb4565eb2..adbcfd3189b7 100644 --- a/clippy_lints/src/casts/cast_possible_truncation.rs +++ b/clippy_lints/src/casts/cast_possible_truncation.rs @@ -2,12 +2,11 @@ use clippy_utils::consts::{constant, Constant}; use clippy_utils::diagnostics::span_lint; use clippy_utils::expr_or_init; use clippy_utils::ty::{get_discriminant_value, is_isize_or_usize}; -use rustc_ast::ast; -use rustc_attr::IntType; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty::{self, FloatTy, Ty}; +use rustc_target::abi::IntegerType; use super::{utils, CAST_ENUM_TRUNCATION, CAST_POSSIBLE_TRUNCATION}; @@ -122,7 +121,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, let cast_from_ptr_size = def.repr().int.map_or(true, |ty| { matches!( ty, - IntType::SignedInt(ast::IntTy::Isize) | IntType::UnsignedInt(ast::UintTy::Usize) + IntegerType::Pointer(_), ) }); let suffix = match (cast_from_ptr_size, is_isize_or_usize(cast_to)) { diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index b481314abedc..601990cd6a31 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -26,7 +26,6 @@ extern crate rustc_arena; extern crate rustc_ast; extern crate rustc_ast_pretty; -extern crate rustc_attr; extern crate rustc_data_structures; extern crate rustc_driver; extern crate rustc_errors; From 7f33824787f2afd221a13d608b66c2de7ac117a9 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 6 Nov 2022 11:40:31 +0000 Subject: [PATCH 0688/1222] Use kw::Empty for elided lifetimes in path. --- clippy_lints/src/lifetimes.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 5df8b486f332..220941dcd5db 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -10,8 +10,8 @@ use rustc_hir::lang_items; use rustc_hir::FnRetTy::Return; use rustc_hir::{ BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl, ImplItem, - ImplItemKind, Item, ItemKind, Lifetime, LifetimeName, PolyTraitRef, PredicateOrigin, TraitFn, TraitItem, - TraitItemKind, Ty, TyKind, WherePredicate, + ImplItemKind, Item, ItemKind, Lifetime, LifetimeName, LifetimeParamKind, PolyTraitRef, PredicateOrigin, TraitFn, + TraitItem, TraitItemKind, Ty, TyKind, WherePredicate, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter as middle_nested_filter; @@ -595,7 +595,9 @@ fn report_extra_lifetimes<'tcx>(cx: &LateContext<'tcx>, func: &'tcx FnDecl<'_>, .params .iter() .filter_map(|par| match par.kind { - GenericParamKind::Lifetime { .. } => Some((par.name.ident().name, par.span)), + GenericParamKind::Lifetime { + kind: LifetimeParamKind::Explicit, + } => Some((par.name.ident().name, par.span)), _ => None, }) .collect(); @@ -620,7 +622,9 @@ fn report_extra_impl_lifetimes<'tcx>(cx: &LateContext<'tcx>, impl_: &'tcx Impl<' .params .iter() .filter_map(|par| match par.kind { - GenericParamKind::Lifetime { .. } => Some((par.name.ident().name, par.span)), + GenericParamKind::Lifetime { + kind: LifetimeParamKind::Explicit, + } => Some((par.name.ident().name, par.span)), _ => None, }) .collect(); @@ -647,7 +651,7 @@ struct BodyLifetimeChecker { impl<'tcx> Visitor<'tcx> for BodyLifetimeChecker { // for lifetimes as parameters of generics fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) { - if lifetime.ident.name != kw::UnderscoreLifetime && lifetime.ident.name != kw::StaticLifetime { + if !lifetime.is_anonymous() && lifetime.ident.name != kw::StaticLifetime { self.lifetimes_used_in_body = true; } } From 9e9008f167ca6e56586ca51cc228555088b97be8 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 18 Nov 2022 21:29:26 +0000 Subject: [PATCH 0689/1222] Simplify a bunch of trait ref obligation creations --- clippy_lints/src/ptr.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 5420a0e782ea..8c4cff66f554 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -698,9 +698,8 @@ fn matches_preds<'tcx>( cx.tcx, ObligationCause::dummy(), cx.param_env, - cx.tcx.mk_predicate(Binder::bind_with_vars( + cx.tcx.mk_predicate(Binder::dummy( PredicateKind::Projection(p.with_self_ty(cx.tcx, ty)), - List::empty(), )), )), ExistentialPredicate::AutoTrait(p) => infcx From 0c6e8dbe1902479348f1c86dbf54892eac375783 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 24 Nov 2022 18:14:58 -0300 Subject: [PATCH 0690/1222] Introduce PredicateKind::Clause --- clippy_lints/src/dereference.rs | 8 ++++---- clippy_lints/src/derive.rs | 8 ++++---- clippy_lints/src/future_not_send.rs | 4 ++-- clippy_lints/src/methods/unnecessary_to_owned.rs | 8 ++++---- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/ptr.rs | 4 ++-- clippy_lints/src/unit_return_expecting_ord.rs | 6 +++--- clippy_utils/src/eager_or_lazy.rs | 2 +- clippy_utils/src/qualify_min_const_fn.rs | 8 ++++---- clippy_utils/src/ty.rs | 16 ++++++++-------- 10 files changed, 33 insertions(+), 33 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 18e742a85b34..47ea98956be2 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -25,7 +25,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::{Rvalue, StatementKind}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability}; use rustc_middle::ty::{ - self, Binder, BoundVariableKind, EarlyBinder, FnSig, GenericArgKind, List, ParamTy, PredicateKind, + self, Binder, BoundVariableKind, Clause, EarlyBinder, FnSig, GenericArgKind, List, ParamTy, PredicateKind, ProjectionPredicate, Ty, TyCtxt, TypeVisitable, TypeckResults, }; use rustc_semver::RustcVersion; @@ -1097,7 +1097,7 @@ fn needless_borrow_impl_arg_position<'tcx>( let projection_predicates = predicates .iter() .filter_map(|predicate| { - if let PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() { + if let PredicateKind::Clause(Clause::Projection(projection_predicate)) = predicate.kind().skip_binder() { Some(projection_predicate) } else { None @@ -1111,7 +1111,7 @@ fn needless_borrow_impl_arg_position<'tcx>( if predicates .iter() .filter_map(|predicate| { - if let PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() + if let PredicateKind::Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() && trait_predicate.trait_ref.self_ty() == param_ty.to_ty(cx.tcx) { Some(trait_predicate.trait_ref.def_id) @@ -1173,7 +1173,7 @@ fn needless_borrow_impl_arg_position<'tcx>( } predicates.iter().all(|predicate| { - if let PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() + if let PredicateKind::Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() && cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_predicate.trait_ref.def_id) && let ty::Param(param_ty) = trait_predicate.self_ty().kind() && let GenericArgKind::Type(ty) = substs_with_referent_ty[param_ty.index as usize].unpack() diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 1d9af7cdbd35..d870e0ceef47 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -14,7 +14,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::traits::Reveal; use rustc_middle::ty::{ - self, Binder, BoundConstness, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate, TraitRef, + self, Binder, BoundConstness, Clause, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate, TraitRef, Ty, TyCtxt, }; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -499,7 +499,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> let ty_predicates = tcx.predicates_of(did).predicates; for (p, _) in ty_predicates { - if let PredicateKind::Trait(p) = p.kind().skip_binder() + if let PredicateKind::Clause(Clause::Trait(p)) = p.kind().skip_binder() && p.trait_ref.def_id == eq_trait_id && let ty::Param(self_ty) = p.trait_ref.self_ty().kind() && p.constness == BoundConstness::NotConst @@ -512,14 +512,14 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> ParamEnv::new( tcx.mk_predicates(ty_predicates.iter().map(|&(p, _)| p).chain( params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| { - tcx.mk_predicate(Binder::dummy(PredicateKind::Trait(TraitPredicate { + tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate { trait_ref: TraitRef::new( eq_trait_id, tcx.mk_substs(std::iter::once(tcx.mk_param_from_def(param))), ), constness: BoundConstness::NotConst, polarity: ImplPolarity::Positive, - }))) + })))) }), )), Reveal::UserFacing, diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 0519f9ac2468..a9425a40f885 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{EarlyBinder, Opaque, PredicateKind::Trait}; +use rustc_middle::ty::{Clause, EarlyBinder, Opaque, PredicateKind}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt; @@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { infcx .err_ctxt() .maybe_note_obligation_cause_for_async_await(db, &obligation); - if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() { + if let PredicateKind::Clause(Clause::Trait(trait_pred)) = obligation.predicate.kind().skip_binder() { db.note(&format!( "`{}` doesn't implement `{}`", trait_pred.self_ty(), diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 8b000cd754cd..7ff13b95626b 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -17,7 +17,7 @@ use rustc_middle::mir::Mutability; use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef}; use rustc_middle::ty::EarlyBinder; -use rustc_middle::ty::{self, ParamTy, PredicateKind, ProjectionPredicate, TraitPredicate, Ty}; +use rustc_middle::ty::{self, Clause, ParamTy, PredicateKind, ProjectionPredicate, TraitPredicate, Ty}; use rustc_semver::RustcVersion; use rustc_span::{sym, Symbol}; use rustc_trait_selection::traits::{ @@ -341,12 +341,12 @@ fn get_input_traits_and_projections<'tcx>( let mut projection_predicates = Vec::new(); for predicate in cx.tcx.param_env(callee_def_id).caller_bounds() { match predicate.kind().skip_binder() { - PredicateKind::Trait(trait_predicate) => { + PredicateKind::Clause(Clause::Trait(trait_predicate)) => { if trait_predicate.trait_ref.self_ty() == input { trait_predicates.push(trait_predicate); } } - PredicateKind::Projection(projection_predicate) => { + PredicateKind::Clause(Clause::Projection(projection_predicate)) => { if projection_predicate.projection_ty.self_ty() == input { projection_predicates.push(projection_predicate); } @@ -403,7 +403,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< let mut trait_predicates = cx.tcx.param_env(callee_def_id) .caller_bounds().iter().filter(|predicate| { - if let PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() + if let PredicateKind::Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() && trait_predicate.trait_ref.self_ty() == *param_ty { true } else { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 55599cd03ebe..75e12715458f 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -124,7 +124,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { .filter_map(|obligation| { // Note that we do not want to deal with qualified predicates here. match obligation.predicate.kind().no_bound_vars() { - Some(ty::PredicateKind::Trait(pred)) if pred.def_id() != sized_trait => Some(pred), + Some(ty::PredicateKind::Clause(ty::Clause::Trait(pred))) if pred.def_id() != sized_trait => Some(pred), _ => None, } }) diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 8c4cff66f554..d28e97b79435 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -19,7 +19,7 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::traits::{Obligation, ObligationCause}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; -use rustc_middle::ty::{self, Binder, ExistentialPredicate, List, PredicateKind, Ty}; +use rustc_middle::ty::{self, Binder, Clause, ExistentialPredicate, List, PredicateKind, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::sym; @@ -699,7 +699,7 @@ fn matches_preds<'tcx>( ObligationCause::dummy(), cx.param_env, cx.tcx.mk_predicate(Binder::dummy( - PredicateKind::Projection(p.with_self_ty(cx.tcx, ty)), + PredicateKind::Clause(Clause::Projection(p.with_self_ty(cx.tcx, ty))), )), )), ExistentialPredicate::AutoTrait(p) => infcx diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 1307288623f9..a138a4baa9b3 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -4,7 +4,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::{Closure, Expr, ExprKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; -use rustc_middle::ty::{GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate}; +use rustc_middle::ty::{Clause, GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, BytePos, Span}; @@ -45,7 +45,7 @@ fn get_trait_predicates_for_trait_id<'tcx>( let mut preds = Vec::new(); for (pred, _) in generics.predicates { if_chain! { - if let PredicateKind::Trait(poly_trait_pred) = pred.kind().skip_binder(); + if let PredicateKind::Clause(Clause::Trait(poly_trait_pred)) = pred.kind().skip_binder(); let trait_pred = cx.tcx.erase_late_bound_regions(pred.kind().rebind(poly_trait_pred)); if let Some(trait_def_id) = trait_id; if trait_def_id == trait_pred.trait_ref.def_id; @@ -63,7 +63,7 @@ fn get_projection_pred<'tcx>( trait_pred: TraitPredicate<'tcx>, ) -> Option> { generics.predicates.iter().find_map(|(proj_pred, _)| { - if let ty::PredicateKind::Projection(pred) = proj_pred.kind().skip_binder() { + if let ty::PredicateKind::Clause(Clause::Projection(pred)) = proj_pred.kind().skip_binder() { let projection_pred = cx.tcx.erase_late_bound_regions(proj_pred.kind().rebind(pred)); if projection_pred.projection_ty.substs == trait_pred.trait_ref.substs { return Some(projection_pred); diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 95b3e651e2b5..f74f7dadfa90 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -73,7 +73,7 @@ fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg: .flat_map(|v| v.fields.iter()) .any(|x| matches!(cx.tcx.type_of(x.did).peel_refs().kind(), ty::Param(_))) && all_predicates_of(cx.tcx, fn_id).all(|(pred, _)| match pred.kind().skip_binder() { - PredicateKind::Trait(pred) => cx.tcx.trait_def(pred.trait_ref.def_id).is_marker, + PredicateKind::Clause(ty::Clause::Trait(pred)) => cx.tcx.trait_def(pred.trait_ref.def_id).is_marker, _ => true, }) && subs.types().all(|x| matches!(x.peel_refs().kind(), ty::Param(_))) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index d183e28f667c..b8c2dd5ab9ea 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -25,13 +25,13 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: Option< let predicates = tcx.predicates_of(current); for (predicate, _) in predicates.predicates { match predicate.kind().skip_binder() { - ty::PredicateKind::RegionOutlives(_) - | ty::PredicateKind::TypeOutlives(_) + ty::PredicateKind::Clause(ty::Clause::RegionOutlives(_)) + | ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_)) | ty::PredicateKind::WellFormed(_) - | ty::PredicateKind::Projection(_) + | ty::PredicateKind::Clause(ty::Clause::Projection(_)) | ty::PredicateKind::ConstEvaluatable(..) | ty::PredicateKind::ConstEquate(..) - | ty::PredicateKind::Trait(..) + | ty::PredicateKind::Clause(ty::Clause::Trait(..)) | ty::PredicateKind::TypeWellFormedFromEnv(..) => continue, ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {predicate:#?}"), ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {predicate:#?}"), diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 8284dc5c28c0..f4459e3e6633 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -81,7 +81,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' match predicate.kind().skip_binder() { // For `impl Trait`, it will register a predicate of `T: Trait`, so we go through // and check substituions to find `U`. - ty::PredicateKind::Trait(trait_predicate) => { + ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) => { if trait_predicate .trait_ref .substs @@ -94,7 +94,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' }, // For `impl Trait`, it will register a predicate of `::Assoc = U`, // so we check the term for `U`. - ty::PredicateKind::Projection(projection_predicate) => { + ty::PredicateKind::Clause(ty::Clause::Projection(projection_predicate)) => { if let ty::TermKind::Ty(ty) = projection_predicate.term.unpack() { if contains_ty_adt_constructor_opaque(cx, ty, needle) { return true; @@ -239,7 +239,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(def_id, _) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { - if let ty::PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() { + if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() { if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) { return true; } @@ -658,7 +658,7 @@ fn sig_from_bounds<'tcx>( for pred in predicates { match pred.kind().skip_binder() { - PredicateKind::Trait(p) + PredicateKind::Clause(ty::Clause::Trait(p)) if (lang_items.fn_trait() == Some(p.def_id()) || lang_items.fn_mut_trait() == Some(p.def_id()) || lang_items.fn_once_trait() == Some(p.def_id())) @@ -671,7 +671,7 @@ fn sig_from_bounds<'tcx>( } inputs = Some(i); }, - PredicateKind::Projection(p) + PredicateKind::Clause(ty::Clause::Projection(p)) if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() && p.projection_ty.self_ty() == ty => { @@ -699,7 +699,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O .subst_iter_copied(cx.tcx, ty.substs) { match pred.kind().skip_binder() { - PredicateKind::Trait(p) + PredicateKind::Clause(ty::Clause::Trait(p)) if (lang_items.fn_trait() == Some(p.def_id()) || lang_items.fn_mut_trait() == Some(p.def_id()) || lang_items.fn_once_trait() == Some(p.def_id())) => @@ -712,7 +712,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O } inputs = Some(i); }, - PredicateKind::Projection(p) if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() => { + PredicateKind::Clause(ty::Clause::Projection(p)) if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() => { if output.is_some() { // Multiple different fn trait impls. Is this even allowed? return None; @@ -887,7 +887,7 @@ pub fn ty_is_fn_once_param<'tcx>(tcx: TyCtxt<'_>, ty: Ty<'tcx>, predicates: &'tc predicates .iter() .try_fold(false, |found, p| { - if let PredicateKind::Trait(p) = p.kind().skip_binder() + if let PredicateKind::Clause(ty::Clause::Trait(p)) = p.kind().skip_binder() && let ty::Param(self_ty) = p.trait_ref.self_ty().kind() && ty.index == self_ty.index { From 5d4d692388d4060b11508c72d4368c5ce89280d1 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 25 Nov 2022 08:47:59 +0100 Subject: [PATCH 0691/1222] RefCell::get_mut: fix typo and fix the same typo in a bunch of other places --- clippy_dev/src/setup/git_hook.rs | 2 +- clippy_utils/src/hir_utils.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_dev/src/setup/git_hook.rs b/clippy_dev/src/setup/git_hook.rs index 1de5b1940bae..c7c53bc69d0b 100644 --- a/clippy_dev/src/setup/git_hook.rs +++ b/clippy_dev/src/setup/git_hook.rs @@ -6,7 +6,7 @@ use super::verify_inside_clippy_dir; /// Rusts setup uses `git rev-parse --git-common-dir` to get the root directory of the repo. /// I've decided against this for the sake of simplicity and to make sure that it doesn't install /// the hook if `clippy_dev` would be used in the rust tree. The hook also references this tool -/// for formatting and should therefor only be used in a normal clone of clippy +/// for formatting and should therefore only be used in a normal clone of clippy const REPO_GIT_DIR: &str = ".git"; const HOOK_SOURCE_FILE: &str = "util/etc/pre-commit.sh"; const HOOK_TARGET_FILE: &str = ".git/hooks/pre-commit"; diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index cf24ec8b67b9..abe10f3c81e5 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -113,7 +113,7 @@ impl HirEqInterExpr<'_, '_, '_> { } } - // eq_pat adds the HirIds to the locals map. We therefor call it last to make sure that + // eq_pat adds the HirIds to the locals map. We therefore call it last to make sure that // these only get added if the init and type is equal. both(&l.init, &r.init, |l, r| self.eq_expr(l, r)) && both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r)) From fad94ee7e5c7002cb006b4a331c44171b22870f3 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 23 Nov 2022 15:39:42 +1100 Subject: [PATCH 0692/1222] Rename `ast::Lit` as `ast::MetaItemLit`. --- clippy_lints/src/attrs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index ecf8e83375db..018f10f25886 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -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, MetaItemKind, NestedMetaItem}; +use rustc_ast::{AttrKind, AttrStyle, Attribute, LitKind, MetaItemKind, MetaItemLit, NestedMetaItem}; use rustc_errors::Applicability; use rustc_hir::{ Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind, @@ -576,7 +576,7 @@ fn check_attrs(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Attribut } } -fn check_semver(cx: &LateContext<'_>, span: Span, lit: &Lit) { +fn check_semver(cx: &LateContext<'_>, span: Span, lit: &MetaItemLit) { if let LitKind::Str(is, _) = lit.kind { if Version::parse(is.as_str()).is_ok() { return; From 589b4dad5afed2a8d35bd80b3be936e7651cbf53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 28 Nov 2022 00:41:31 -0800 Subject: [PATCH 0693/1222] fix clippy tests --- tests/ui/async_yields_async.stderr | 20 ++++++++++---------- tests/ui/result_map_unit_fn_unfixable.stderr | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/ui/async_yields_async.stderr b/tests/ui/async_yields_async.stderr index b0c4215e7ddf..92ba35929678 100644 --- a/tests/ui/async_yields_async.stderr +++ b/tests/ui/async_yields_async.stderr @@ -2,14 +2,14 @@ error: an async construct yields a type which is itself awaitable --> $DIR/async_yields_async.rs:39:9 | LL | let _h = async { - | ____________________- -LL | | async { - | |_________^ + | _____________________- +LL | | async { + | | _________^ LL | || 3 LL | || } | ||_________^ awaitable value not awaited -LL | | }; - | |_____- outer async construct +LL | | }; + | |______- outer async construct | = note: `-D clippy::async-yields-async` implied by `-D warnings` help: consider awaiting this value @@ -36,14 +36,14 @@ error: an async construct yields a type which is itself awaitable --> $DIR/async_yields_async.rs:50:9 | LL | let _j = async || { - | _______________________- -LL | | async { - | |_________^ + | ________________________- +LL | | async { + | | _________^ LL | || 3 LL | || } | ||_________^ awaitable value not awaited -LL | | }; - | |_____- outer async construct +LL | | }; + | |______- outer async construct | help: consider awaiting this value | diff --git a/tests/ui/result_map_unit_fn_unfixable.stderr b/tests/ui/result_map_unit_fn_unfixable.stderr index 88e4efdb0f05..2e1eb8eb1806 100644 --- a/tests/ui/result_map_unit_fn_unfixable.stderr +++ b/tests/ui/result_map_unit_fn_unfixable.stderr @@ -20,14 +20,14 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns --> $DIR/result_map_unit_fn_unfixable.rs:29:5 | LL | x.field.map(|value| { - | _____^ - | |_____| + | ______^ + | | _____| | || LL | || do_nothing(value); LL | || do_nothing(value) LL | || }); | ||______^- help: try this: `if let Ok(value) = x.field { ... }` - | |_______| + | |______| | error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` From 4d1dbe1a5a87538ceae932d0572ebb73c3e602f7 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 25 Nov 2022 17:11:15 +0000 Subject: [PATCH 0694/1222] partially_normalize_... -> At::normalize --- clippy_utils/src/ty.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index f4459e3e6633..82496f120e37 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -22,6 +22,7 @@ use rustc_span::symbol::Ident; use rustc_span::{sym, Span, Symbol, DUMMY_SP}; use rustc_target::abi::{Size, VariantIdx}; use rustc_trait_selection::infer::InferCtxtExt; +use rustc_trait_selection::traits::NormalizeExt; use rustc_trait_selection::traits::query::normalize::AtExt; use std::iter; From 69a105d86bbe7b90064c5b3f949691d1c4fee21b Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 25 Nov 2022 17:28:50 +0000 Subject: [PATCH 0695/1222] FnCtxt normalization stuff --- clippy_utils/src/ty.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 82496f120e37..2ceda3511fe4 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -22,8 +22,7 @@ use rustc_span::symbol::Ident; use rustc_span::{sym, Span, Symbol, DUMMY_SP}; use rustc_target::abi::{Size, VariantIdx}; use rustc_trait_selection::infer::InferCtxtExt; -use rustc_trait_selection::traits::NormalizeExt; -use rustc_trait_selection::traits::query::normalize::AtExt; +use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt; use std::iter; use crate::{match_def_path, path_res, paths}; @@ -284,7 +283,7 @@ fn is_normalizable_helper<'tcx>( cache.insert(ty, false); let infcx = cx.tcx.infer_ctxt().build(); let cause = rustc_middle::traits::ObligationCause::dummy(); - let result = if infcx.at(&cause, param_env).normalize(ty).is_ok() { + let result = if infcx.at(&cause, param_env).query_normalize(ty).is_ok() { match ty.kind() { ty::Adt(def, substs) => def.variants().iter().all(|variant| { variant From dea821a743d9358c4ac7626f87b1f997eac1b96b Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 25 Nov 2022 11:26:36 +0300 Subject: [PATCH 0696/1222] rustc_hir: Relax lifetime requirements on `Visitor::visit_path` --- clippy_lints/src/from_over_into.rs | 2 +- clippy_lints/src/methods/option_map_unwrap_or.rs | 4 ++-- .../src/utils/internal_lints/lint_without_lint_pass.rs | 2 +- clippy_lints/src/utils/internal_lints/metadata_collector.rs | 2 +- clippy_utils/src/usage.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index 8b24a4962fb2..6d9ede5f73bb 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -126,7 +126,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SelfFinder<'a, 'tcx> { self.cx.tcx.hir() } - fn visit_path(&mut self, path: &'tcx Path<'tcx>, _id: HirId) { + fn visit_path(&mut self, path: &Path<'tcx>, _id: HirId) { for segment in path.segments { match segment.ident.name { kw::SelfLower => self.lower.push(segment.ident.span), diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 30421a6dd5af..910ee14855e2 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -97,7 +97,7 @@ struct UnwrapVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for UnwrapVisitor<'a, 'tcx> { type NestedFilter = nested_filter::All; - fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) { + fn visit_path(&mut self, path: &Path<'tcx>, _id: HirId) { self.identifiers.insert(ident(path)); walk_path(self, path); } @@ -116,7 +116,7 @@ struct MapExprVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for MapExprVisitor<'a, 'tcx> { type NestedFilter = nested_filter::All; - fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) { + fn visit_path(&mut self, path: &Path<'tcx>, _id: HirId) { if self.identifiers.contains(&ident(path)) { self.found_identifier = true; return; diff --git a/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs b/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs index 1aebb8b3104b..786d9608c851 100644 --- a/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs +++ b/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs @@ -330,7 +330,7 @@ struct LintCollector<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for LintCollector<'a, 'tcx> { type NestedFilter = nested_filter::All; - fn visit_path(&mut self, path: &'tcx Path<'_>, _: HirId) { + fn visit_path(&mut self, path: &Path<'_>, _: HirId) { if path.segments.len() == 1 { self.output.insert(path.segments[0].ident.name); } diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index d06a616e4b30..857abe77e21f 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -1019,7 +1019,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for ApplicabilityResolver<'a, 'hir> { self.cx.tcx.hir() } - fn visit_path(&mut self, path: &'hir hir::Path<'hir>, _id: hir::HirId) { + fn visit_path(&mut self, path: &hir::Path<'hir>, _id: hir::HirId) { for (index, enum_value) in paths::APPLICABILITY_VALUES.iter().enumerate() { if match_path(path, enum_value) { self.add_new_index(index); diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index 797722cfc1fc..ab3976a13bdb 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -128,7 +128,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for BindingUsageFinder<'a, 'tcx> { } } - fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, _: hir::HirId) { + fn visit_path(&mut self, path: &hir::Path<'tcx>, _: hir::HirId) { if let hir::def::Res::Local(id) = path.res { if self.binding_ids.contains(&id) { self.usage_found = true; From a887fb5f5030b8d26b652cf78e4038557cf815f0 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 25 Nov 2022 17:39:38 +0300 Subject: [PATCH 0697/1222] rustc_hir: Change representation of import paths to support multiple resolutions --- clippy_lints/src/disallowed_types.rs | 4 +- clippy_lints/src/macro_use.rs | 5 +- .../src/missing_enforced_import_rename.rs | 59 ++++++++++--------- clippy_lints/src/redundant_pub_crate.rs | 2 +- clippy_lints/src/wildcard_imports.rs | 3 +- 5 files changed, 41 insertions(+), 32 deletions(-) diff --git a/clippy_lints/src/disallowed_types.rs b/clippy_lints/src/disallowed_types.rs index aee3d8c4f085..1f56d0118a40 100644 --- a/clippy_lints/src/disallowed_types.rs +++ b/clippy_lints/src/disallowed_types.rs @@ -106,7 +106,9 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedTypes { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { if let ItemKind::Use(path, UseKind::Single) = &item.kind { - self.check_res_emit(cx, &path.res, item.span); + for res in &path.res { + self.check_res_emit(cx, res, item.span); + } } } diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index 594f6af76b3d..e2e6a87a3015 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -94,7 +94,10 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports { let hir_id = item.hir_id(); let attrs = cx.tcx.hir().attrs(hir_id); if let Some(mac_attr) = attrs.iter().find(|attr| attr.has_name(sym::macro_use)); - if let Res::Def(DefKind::Mod, id) = path.res; + if let Some(id) = path.res.iter().find_map(|res| match res { + Res::Def(DefKind::Mod, id) => Some(id), + _ => None, + }); if !id.is_local(); then { for kid in cx.tcx.module_children(id).iter() { diff --git a/clippy_lints/src/missing_enforced_import_rename.rs b/clippy_lints/src/missing_enforced_import_rename.rs index 4712846939e6..773174679dbd 100644 --- a/clippy_lints/src/missing_enforced_import_rename.rs +++ b/clippy_lints/src/missing_enforced_import_rename.rs @@ -66,35 +66,38 @@ impl LateLintPass<'_> for ImportRename { } fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { - if_chain! { - if let ItemKind::Use(path, UseKind::Single) = &item.kind; - if let Res::Def(_, id) = path.res; - if let Some(name) = self.renames.get(&id); - // Remove semicolon since it is not present for nested imports - let span_without_semi = cx.sess().source_map().span_until_char(item.span, ';'); - if let Some(snip) = snippet_opt(cx, span_without_semi); - if let Some(import) = match snip.split_once(" as ") { - None => Some(snip.as_str()), - Some((import, rename)) => { - if rename.trim() == name.as_str() { - None - } else { - Some(import.trim()) + if let ItemKind::Use(path, UseKind::Single) = &item.kind { + for &res in &path.res { + if_chain! { + if let Res::Def(_, id) = res; + if let Some(name) = self.renames.get(&id); + // Remove semicolon since it is not present for nested imports + let span_without_semi = cx.sess().source_map().span_until_char(item.span, ';'); + if let Some(snip) = snippet_opt(cx, span_without_semi); + if let Some(import) = match snip.split_once(" as ") { + None => Some(snip.as_str()), + Some((import, rename)) => { + if rename.trim() == name.as_str() { + None + } else { + Some(import.trim()) + } + }, + }; + then { + span_lint_and_sugg( + cx, + MISSING_ENFORCED_IMPORT_RENAMES, + span_without_semi, + "this import should be renamed", + "try", + format!( + "{import} as {name}", + ), + Applicability::MachineApplicable, + ); } - }, - }; - then { - span_lint_and_sugg( - cx, - MISSING_ENFORCED_IMPORT_RENAMES, - span_without_semi, - "this import should be renamed", - "try", - format!( - "{import} as {name}", - ), - Applicability::MachineApplicable, - ); + } } } } diff --git a/clippy_lints/src/redundant_pub_crate.rs b/clippy_lints/src/redundant_pub_crate.rs index 833dc4913b46..d612d249c2f0 100644 --- a/clippy_lints/src/redundant_pub_crate.rs +++ b/clippy_lints/src/redundant_pub_crate.rs @@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { fn is_not_macro_export<'tcx>(item: &'tcx Item<'tcx>) -> bool { if let ItemKind::Use(path, _) = item.kind { - if let Res::Def(DefKind::Macro(MacroKind::Bang), _) = path.res { + if path.res.iter().all(|res| matches!(res, Res::Def(DefKind::Macro(MacroKind::Bang), _))) { return false; } } else if let ItemKind::Macro(..) = item.kind { diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index be98344470b9..e4d1ee195c4d 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -176,7 +176,8 @@ impl LateLintPass<'_> for WildcardImports { format!("{import_source_snippet}::{imports_string}") }; - let (lint, message) = if let Res::Def(DefKind::Enum, _) = use_path.res { + // Glob imports always have a single resolution. + let (lint, message) = if let Res::Def(DefKind::Enum, _) = use_path.res[0] { (ENUM_GLOB_USE, "usage of wildcard import for enum variants") } else { (WILDCARD_IMPORTS, "usage of wildcard import") From e501f336e18d85923a7768f6f928bad236209a6f Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 1 Dec 2022 18:51:20 +0300 Subject: [PATCH 0698/1222] rustc_ast_lowering: Stop lowering imports into multiple items Lower them into a single item with multiple resolutions instead. This also allows to remove additional `NodId`s and `DefId`s related to those additional items. --- clippy_lints/src/single_component_path_imports.rs | 4 ++-- clippy_lints/src/unnecessary_self_imports.rs | 2 +- clippy_lints/src/unsafe_removed_from_name.rs | 4 ++-- clippy_utils/src/ast_utils.rs | 2 +- tests/ui/macro_use_imports.stderr | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/single_component_path_imports.rs b/clippy_lints/src/single_component_path_imports.rs index 2036e85db7e8..d46f6a6352c6 100644 --- a/clippy_lints/src/single_component_path_imports.rs +++ b/clippy_lints/src/single_component_path_imports.rs @@ -149,7 +149,7 @@ impl SingleComponentPathImports { // keep track of `use some_module;` usages if segments.len() == 1 { - if let UseTreeKind::Simple(None, _, _) = use_tree.kind { + if let UseTreeKind::Simple(None) = use_tree.kind { let name = segments[0].ident.name; if !macros.contains(&name) { single_use_usages.push(SingleUse { @@ -169,7 +169,7 @@ impl SingleComponentPathImports { for tree in trees { let segments = &tree.0.prefix.segments; if segments.len() == 1 { - if let UseTreeKind::Simple(None, _, _) = tree.0.kind { + if let UseTreeKind::Simple(None) = tree.0.kind { let name = segments[0].ident.name; if !macros.contains(&name) { single_use_usages.push(SingleUse { diff --git a/clippy_lints/src/unnecessary_self_imports.rs b/clippy_lints/src/unnecessary_self_imports.rs index bc0dd263d88a..397633f533b2 100644 --- a/clippy_lints/src/unnecessary_self_imports.rs +++ b/clippy_lints/src/unnecessary_self_imports.rs @@ -57,7 +57,7 @@ impl EarlyLintPass for UnnecessarySelfImports { format!( "{}{};", last_segment.ident, - if let UseTreeKind::Simple(Some(alias), ..) = self_tree.kind { format!(" as {alias}") } else { String::new() }, + if let UseTreeKind::Simple(Some(alias)) = self_tree.kind { format!(" as {alias}") } else { String::new() }, ), Applicability::MaybeIncorrect, ); diff --git a/clippy_lints/src/unsafe_removed_from_name.rs b/clippy_lints/src/unsafe_removed_from_name.rs index 952586527689..7ee785804f0a 100644 --- a/clippy_lints/src/unsafe_removed_from_name.rs +++ b/clippy_lints/src/unsafe_removed_from_name.rs @@ -39,7 +39,7 @@ impl EarlyLintPass for UnsafeNameRemoval { fn check_use_tree(use_tree: &UseTree, cx: &EarlyContext<'_>, span: Span) { match use_tree.kind { - UseTreeKind::Simple(Some(new_name), ..) => { + UseTreeKind::Simple(Some(new_name)) => { let old_name = use_tree .prefix .segments @@ -48,7 +48,7 @@ fn check_use_tree(use_tree: &UseTree, cx: &EarlyContext<'_>, span: Span) { .ident; unsafe_to_safe_check(old_name, new_name, cx, span); }, - UseTreeKind::Simple(None, ..) | UseTreeKind::Glob => {}, + UseTreeKind::Simple(None) | UseTreeKind::Glob => {}, UseTreeKind::Nested(ref nested_use_tree) => { for (use_tree, _) in nested_use_tree { check_use_tree(use_tree, cx, span); diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 6bcf0bbd7eb7..49e5f283db08 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -566,7 +566,7 @@ pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool { use UseTreeKind::*; match (l, r) { (Glob, Glob) => true, - (Simple(l, _, _), Simple(r, _, _)) => both(l, r, |l, r| eq_id(*l, *r)), + (Simple(l), Simple(r)) => both(l, r, |l, r| eq_id(*l, *r)), (Nested(l), Nested(r)) => over(l, r, |(l, _), (r, _)| eq_use_tree(l, r)), _ => false, } diff --git a/tests/ui/macro_use_imports.stderr b/tests/ui/macro_use_imports.stderr index bf7b6edd0e31..61843124ccd9 100644 --- a/tests/ui/macro_use_imports.stderr +++ b/tests/ui/macro_use_imports.stderr @@ -1,8 +1,8 @@ error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:23:5 + --> $DIR/macro_use_imports.rs:25:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::foofoo, inner::try_err};` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;` | = note: `-D clippy::macro-use-imports` implied by `-D warnings` @@ -13,10 +13,10 @@ LL | #[macro_use] | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;` error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:25:5 + --> $DIR/macro_use_imports.rs:23:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::foofoo, inner::try_err};` error: `macro_use` attributes are no longer needed in the Rust 2018 edition --> $DIR/macro_use_imports.rs:19:5 From c2cf492c502a9cd8239f3fcd771489f75ca32999 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 29 Nov 2022 13:35:44 +1100 Subject: [PATCH 0699/1222] Add `StrStyle` to `ast::LitKind::ByteStr`. This is required to distinguish between cooked and raw byte string literals in an `ast::LitKind`, without referring to an adjacent `token::Lit`. It's a prerequisite for the next commit. --- clippy_lints/src/invalid_utf8_in_unchecked.rs | 2 +- clippy_lints/src/large_include_file.rs | 2 +- clippy_lints/src/matches/match_same_arms.rs | 2 +- clippy_lints/src/utils/author.rs | 2 +- clippy_utils/src/check_proc_macro.rs | 4 +++- clippy_utils/src/consts.rs | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/invalid_utf8_in_unchecked.rs b/clippy_lints/src/invalid_utf8_in_unchecked.rs index e0a607f9a95b..6a4861747d26 100644 --- a/clippy_lints/src/invalid_utf8_in_unchecked.rs +++ b/clippy_lints/src/invalid_utf8_in_unchecked.rs @@ -33,7 +33,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidUtf8InUnchecked { if let Some([arg]) = match_function_call(cx, expr, &paths::STR_FROM_UTF8_UNCHECKED) { match &arg.kind { ExprKind::Lit(Spanned { node: lit, .. }) => { - if let LitKind::ByteStr(bytes) = &lit + if let LitKind::ByteStr(bytes, _) = &lit && std::str::from_utf8(bytes).is_err() { lint(cx, expr.span); diff --git a/clippy_lints/src/large_include_file.rs b/clippy_lints/src/large_include_file.rs index 84dd61a1e4b0..424c0d9e7982 100644 --- a/clippy_lints/src/large_include_file.rs +++ b/clippy_lints/src/large_include_file.rs @@ -60,7 +60,7 @@ impl LateLintPass<'_> for LargeIncludeFile { then { let len = match &lit.node { // include_bytes - LitKind::ByteStr(bstr) => bstr.len(), + LitKind::ByteStr(bstr, _) => bstr.len(), // include_str LitKind::Str(sym, _) => sym.as_str().len(), _ => return, diff --git a/clippy_lints/src/matches/match_same_arms.rs b/clippy_lints/src/matches/match_same_arms.rs index 168c1e4d2e60..158e6caa4de5 100644 --- a/clippy_lints/src/matches/match_same_arms.rs +++ b/clippy_lints/src/matches/match_same_arms.rs @@ -282,7 +282,7 @@ impl<'a> NormalizedPat<'a> { // TODO: Handle negative integers. They're currently treated as a wild match. ExprKind::Lit(lit) => match lit.node { LitKind::Str(sym, _) => Self::LitStr(sym), - LitKind::ByteStr(ref bytes) => Self::LitBytes(bytes), + LitKind::ByteStr(ref bytes, _) => Self::LitBytes(bytes), LitKind::Byte(val) => Self::LitInt(val.into()), LitKind::Char(val) => Self::LitInt(val.into()), LitKind::Int(val, _) => Self::LitInt(val), diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 0c052d86eda4..bd7daf0773ca 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -299,7 +299,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { }; kind!("Float(_, {float_ty})"); }, - LitKind::ByteStr(ref vec) => { + LitKind::ByteStr(ref vec, _) => { bind!(self, vec); kind!("ByteStr(ref {vec})"); chain!(self, "let [{:?}] = **{vec}", vec.value); diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index c6bf98b7b8bb..43f0df145f0e 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -69,7 +69,9 @@ fn lit_search_pat(lit: &LitKind) -> (Pat, Pat) { LitKind::Str(_, StrStyle::Cooked) => (Pat::Str("\""), Pat::Str("\"")), LitKind::Str(_, StrStyle::Raw(0)) => (Pat::Str("r"), Pat::Str("\"")), LitKind::Str(_, StrStyle::Raw(_)) => (Pat::Str("r#"), Pat::Str("#")), - LitKind::ByteStr(_) => (Pat::Str("b\""), Pat::Str("\"")), + LitKind::ByteStr(_, StrStyle::Cooked) => (Pat::Str("b\""), Pat::Str("\"")), + LitKind::ByteStr(_, StrStyle::Raw(0)) => (Pat::Str("br\""), Pat::Str("\"")), + LitKind::ByteStr(_, StrStyle::Raw(_)) => (Pat::Str("br#\""), Pat::Str("#")), LitKind::Byte(_) => (Pat::Str("b'"), Pat::Str("'")), LitKind::Char(_) => (Pat::Str("'"), Pat::Str("'")), LitKind::Int(_, LitIntType::Signed(IntTy::Isize)) => (Pat::Num, Pat::Str("isize")), diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 315aea9aa091..7a637d32babe 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -210,7 +210,7 @@ pub fn lit_to_mir_constant(lit: &LitKind, ty: Option>) -> Constant { match *lit { LitKind::Str(ref is, _) => Constant::Str(is.to_string()), LitKind::Byte(b) => Constant::Int(u128::from(b)), - LitKind::ByteStr(ref s) => Constant::Binary(Lrc::clone(s)), + LitKind::ByteStr(ref s, _) => Constant::Binary(Lrc::clone(s)), LitKind::Char(c) => Constant::Char(c), LitKind::Int(n, _) => Constant::Int(n), LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty { From 15f0d1e7a5f846f93b363b3461d1fb18513abb75 Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Fri, 2 Dec 2022 20:41:29 -0500 Subject: [PATCH 0700/1222] Fix #10021 --- clippy_lints/src/methods/unnecessary_to_owned.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 17b0507682ae..9263f0519724 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -386,14 +386,12 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< Node::Expr(parent_expr) => { if let Some((callee_def_id, call_substs, recv, call_args)) = get_callee_substs_and_args(cx, parent_expr) { - if Some(callee_def_id) == cx.tcx.lang_items().into_future_fn() { - return false; - } - let fn_sig = cx.tcx.fn_sig(callee_def_id).skip_binder(); if let Some(arg_index) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == expr.hir_id) && let Some(param_ty) = fn_sig.inputs().get(arg_index) && let ty::Param(ParamTy { index: param_index , ..}) = param_ty.kind() + // https://github.com/rust-lang/rust-clippy/issues/9504 and https://github.com/rust-lang/rust-clippy/issues/10021 + && (*param_index as usize) < call_substs.len() { if fn_sig .inputs() From dd943927852f3cecab746f3cbef9e8005d904ce9 Mon Sep 17 00:00:00 2001 From: Jakob Degen Date: Sat, 3 Dec 2022 16:03:27 -0800 Subject: [PATCH 0701/1222] Remove unneeded field from `SwitchTargets` --- clippy_utils/src/qualify_min_const_fn.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 480e8e55cf39..e053a9dc8881 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -303,7 +303,6 @@ fn check_terminator<'tcx>( TerminatorKind::SwitchInt { discr, - switch_ty: _, targets: _, } => check_operand(tcx, discr, span, body), From 22b5b9145509c7b9fbe0e71ad72a45a15ede51e3 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 26 Nov 2022 21:09:39 +0000 Subject: [PATCH 0702/1222] Use ty::OpaqueTy everywhere --- clippy_lints/src/future_not_send.rs | 8 ++++---- clippy_utils/src/ty.rs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 61934a914263..8a7a65c86001 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{Clause, EarlyBinder, Opaque, PredicateKind}; +use rustc_middle::ty::{Clause, EarlyBinder, Opaque, OpaqueTy, PredicateKind}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt; @@ -62,11 +62,11 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { return; } let ret_ty = return_ty(cx, hir_id); - if let Opaque(id, subst) = *ret_ty.kind() { - let preds = cx.tcx.explicit_item_bounds(id); + if let Opaque(OpaqueTy { def_id, substs }) = *ret_ty.kind() { + let preds = cx.tcx.explicit_item_bounds(def_id); let mut is_future = false; for &(p, _span) in preds { - let p = EarlyBinder(p).subst(cx.tcx, subst); + let p = EarlyBinder(p).subst(cx.tcx, substs); if let Some(trait_pred) = p.to_opt_poly_trait_pred() { if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() { is_future = true; diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index bfb2d472a393..f5f70b195c98 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -79,7 +79,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' return true; } - if let ty::Opaque(def_id, _) = *inner_ty.kind() { + if let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = *inner_ty.kind() { for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) { match predicate.kind().skip_binder() { // For `impl Trait`, it will register a predicate of `T: Trait`, so we go through @@ -250,7 +250,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { is_must_use_ty(cx, *ty) }, ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), - ty::Opaque(def_id, _) => { + ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() { if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) { @@ -631,7 +631,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))), - ty::Opaque(id, _) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(id), cx.tcx.opt_parent(id)), + ty::Opaque(ty::OpaqueTy{ def_id, substs: _ }) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id)), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), ty::Dynamic(bounds, _, _) => { let lang_items = cx.tcx.lang_items(); From 8bf69acf6d5efb6d3df65d6842af6fb77319152a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 26 Nov 2022 21:21:20 +0000 Subject: [PATCH 0703/1222] ProjectionTy.item_def_id -> ProjectionTy.def_id --- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/len_zero.rs | 2 +- clippy_lints/src/methods/needless_collect.rs | 2 +- clippy_utils/src/ty.rs | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 38329659e02b..ad5a1b2beb70 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1330,7 +1330,7 @@ fn replace_types<'tcx>( && let Some(term_ty) = projection_predicate.term.ty() && let ty::Param(term_param_ty) = term_ty.kind() { - let item_def_id = projection_predicate.projection_ty.item_def_id; + let item_def_id = projection_predicate.projection_ty.def_id; let assoc_item = cx.tcx.associated_item(item_def_id); let projection = cx.tcx .mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(new_ty, [])); diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 4c133c06a157..982f99c27163 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -493,7 +493,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { .filter_by_name_unhygienic(is_empty) .any(|item| is_is_empty(cx, item)) }), - ty::Projection(ref proj) => has_is_empty_impl(cx, proj.item_def_id), + ty::Projection(ref proj) => has_is_empty_impl(cx, proj.def_id), ty::Adt(id, _) => has_is_empty_impl(cx, id.did()), ty::Array(..) | ty::Slice(..) | ty::Str => true, _ => false, diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index b088e642e0e9..f4d3ef3b7425 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -151,7 +151,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty: && let Some(into_iter_item_proj) = make_projection(cx.tcx, into_iter_trait, item, [collect_ty]) && let Ok(into_iter_item_ty) = cx.tcx.try_normalize_erasing_regions( cx.param_env, - cx.tcx.mk_projection(into_iter_item_proj.item_def_id, into_iter_item_proj.substs) + cx.tcx.mk_projection(into_iter_item_proj.def_id, into_iter_item_proj.substs) ) { iter_item_ty == into_iter_item_ty diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index f5f70b195c98..11e41d1958ce 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -685,7 +685,7 @@ fn sig_from_bounds<'tcx>( inputs = Some(i); }, PredicateKind::Clause(ty::Clause::Projection(p)) - if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() + if Some(p.projection_ty.def_id) == lang_items.fn_once_output() && p.projection_ty.self_ty() == ty => { if output.is_some() { @@ -708,7 +708,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O for (pred, _) in cx .tcx - .bound_explicit_item_bounds(ty.item_def_id) + .bound_explicit_item_bounds(ty.def_id) .subst_iter_copied(cx.tcx, ty.substs) { match pred.kind().skip_binder() { @@ -726,7 +726,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O inputs = Some(i); }, PredicateKind::Clause(ty::Clause::Projection(p)) - if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() => + if Some(p.projection_ty.def_id) == lang_items.fn_once_output() => { if output.is_some() { // Multiple different fn trait impls. Is this even allowed? @@ -1041,7 +1041,7 @@ pub fn make_projection<'tcx>( Some(ProjectionTy { substs, - item_def_id: assoc_item.def_id, + def_id: assoc_item.def_id, }) } helper( @@ -1081,7 +1081,7 @@ pub fn make_normalized_projection<'tcx>( ); return None; } - match tcx.try_normalize_erasing_regions(param_env, tcx.mk_projection(ty.item_def_id, ty.substs)) { + match tcx.try_normalize_erasing_regions(param_env, tcx.mk_projection(ty.def_id, ty.substs)) { Ok(ty) => Some(ty), Err(e) => { debug_assert!(false, "failed to normalize type `{ty}`: {e:#?}"); From 34d9437bd93bc09e446a274af63929121b51e937 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 26 Nov 2022 21:32:01 +0000 Subject: [PATCH 0704/1222] squash OpaqueTy and ProjectionTy into AliasTy --- clippy_lints/src/future_not_send.rs | 4 ++-- clippy_utils/src/ty.rs | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 8a7a65c86001..3ff774867b1e 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{Clause, EarlyBinder, Opaque, OpaqueTy, PredicateKind}; +use rustc_middle::ty::{AliasTy, Clause, EarlyBinder, Opaque, PredicateKind}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt; @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { return; } let ret_ty = return_ty(cx, hir_id); - if let Opaque(OpaqueTy { def_id, substs }) = *ret_ty.kind() { + if let Opaque(AliasTy { def_id, substs }) = *ret_ty.kind() { let preds = cx.tcx.explicit_item_bounds(def_id); let mut is_future = false; for &(p, _span) in preds { diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 11e41d1958ce..bddab7eca53b 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -17,7 +17,7 @@ use rustc_lint::LateContext; use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::ty::{ self, AdtDef, AssocKind, Binder, BoundRegion, DefIdTree, FnSig, IntTy, List, ParamEnv, Predicate, PredicateKind, - ProjectionTy, Region, RegionKind, SubstsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy, + AliasTy, Region, RegionKind, SubstsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy, VariantDef, VariantDiscr, }; use rustc_middle::ty::{GenericArg, GenericArgKind}; @@ -79,7 +79,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' return true; } - if let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = *inner_ty.kind() { + if let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = *inner_ty.kind() { for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) { match predicate.kind().skip_binder() { // For `impl Trait`, it will register a predicate of `T: Trait`, so we go through @@ -250,7 +250,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { is_must_use_ty(cx, *ty) }, ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), - ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) => { + ty::Opaque(ty::AliasTy { def_id, substs: _ }) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() { if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) { @@ -631,7 +631,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))), - ty::Opaque(ty::OpaqueTy{ def_id, substs: _ }) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id)), + ty::Opaque(ty::AliasTy { def_id, substs: _ }) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id)), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), ty::Dynamic(bounds, _, _) => { let lang_items = cx.tcx.lang_items(); @@ -701,7 +701,7 @@ fn sig_from_bounds<'tcx>( inputs.map(|ty| ExprFnSig::Trait(ty, output, predicates_id)) } -fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> Option> { +fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option> { let mut inputs = None; let mut output = None; let lang_items = cx.tcx.lang_items(); @@ -980,13 +980,13 @@ pub fn make_projection<'tcx>( container_id: DefId, assoc_ty: Symbol, substs: impl IntoIterator>>, -) -> Option> { +) -> Option> { fn helper<'tcx>( tcx: TyCtxt<'tcx>, container_id: DefId, assoc_ty: Symbol, substs: SubstsRef<'tcx>, - ) -> Option> { + ) -> Option> { let Some(assoc_item) = tcx .associated_items(container_id) .find_by_name_and_kind(tcx, Ident::with_dummy_span(assoc_ty), AssocKind::Type, container_id) @@ -1039,7 +1039,7 @@ pub fn make_projection<'tcx>( } } - Some(ProjectionTy { + Some(AliasTy { substs, def_id: assoc_item.def_id, }) @@ -1065,7 +1065,7 @@ pub fn make_normalized_projection<'tcx>( assoc_ty: Symbol, substs: impl IntoIterator>>, ) -> Option> { - fn helper<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: ProjectionTy<'tcx>) -> Option> { + fn helper<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: AliasTy<'tcx>) -> Option> { #[cfg(debug_assertions)] if let Some((i, subst)) = ty .substs From a67fc7fd4db3088fa7aaaca5c70361873987db37 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 26 Nov 2022 21:51:55 +0000 Subject: [PATCH 0705/1222] Combine projection and opaque into alias --- clippy_lints/src/dereference.rs | 8 ++++---- clippy_lints/src/future_not_send.rs | 4 ++-- clippy_lints/src/len_zero.rs | 2 +- clippy_utils/src/qualify_min_const_fn.rs | 2 +- clippy_utils/src/ty.rs | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index ad5a1b2beb70..31183266acfc 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1244,7 +1244,7 @@ fn is_mixed_projection_predicate<'tcx>( let mut projection_ty = projection_predicate.projection_ty; loop { match projection_ty.self_ty().kind() { - ty::Projection(inner_projection_ty) => { + ty::Alias(ty::Projection, inner_projection_ty) => { projection_ty = *inner_projection_ty; } ty::Param(param_ty) => { @@ -1390,8 +1390,8 @@ fn ty_auto_deref_stability<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, precedenc continue; }, ty::Param(_) => TyPosition::new_deref_stable_for_result(precedence, ty), - ty::Projection(_) if ty.has_non_region_param() => TyPosition::new_deref_stable_for_result(precedence, ty), - ty::Infer(_) | ty::Error(_) | ty::Bound(..) | ty::Opaque(..) | ty::Placeholder(_) | ty::Dynamic(..) => { + ty::Alias(ty::Projection, _) if ty.has_non_region_param() => TyPosition::new_deref_stable_for_result(precedence, ty), + ty::Infer(_) | ty::Error(_) | ty::Bound(..) | ty::Alias(ty::Opaque, ..) | ty::Placeholder(_) | ty::Dynamic(..) => { Position::ReborrowStable(precedence).into() }, ty::Adt(..) if ty.has_placeholders() || ty.has_opaque_types() => { @@ -1417,7 +1417,7 @@ fn ty_auto_deref_stability<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, precedenc | ty::Closure(..) | ty::Never | ty::Tuple(_) - | ty::Projection(_) => { + | ty::Alias(ty::Projection, _) => { Position::DerefStable(precedence, ty.is_sized(cx.tcx, cx.param_env.without_caller_bounds())).into() }, }; diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 3ff774867b1e..fcdac90fc237 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{AliasTy, Clause, EarlyBinder, Opaque, PredicateKind}; +use rustc_middle::ty::{self, AliasTy, Clause, EarlyBinder, PredicateKind}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt; @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { return; } let ret_ty = return_ty(cx, hir_id); - if let Opaque(AliasTy { def_id, substs }) = *ret_ty.kind() { + if let ty::Alias(ty::Opaque, AliasTy { def_id, substs }) = *ret_ty.kind() { let preds = cx.tcx.explicit_item_bounds(def_id); let mut is_future = false; for &(p, _span) in preds { diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 982f99c27163..73841f9aa9a2 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -493,7 +493,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { .filter_by_name_unhygienic(is_empty) .any(|item| is_is_empty(cx, item)) }), - ty::Projection(ref proj) => has_is_empty_impl(cx, proj.def_id), + ty::Alias(ty::Projection, ref proj) => has_is_empty_impl(cx, proj.def_id), ty::Adt(id, _) => has_is_empty_impl(cx, id.did()), ty::Array(..) | ty::Slice(..) | ty::Str => true, _ => false, diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index e053a9dc8881..8bf542ada04d 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -82,7 +82,7 @@ fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult { ty::Ref(_, _, hir::Mutability::Mut) => { return Err((span, "mutable references in const fn are unstable".into())); }, - ty::Opaque(..) => return Err((span, "`impl Trait` in const fn is unstable".into())), + ty::Alias(ty::Opaque, ..) => return Err((span, "`impl Trait` in const fn is unstable".into())), ty::FnPtr(..) => { return Err((span, "function pointers in const fn are unstable".into())); }, diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index bddab7eca53b..33f3b3af3dc0 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -79,7 +79,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' return true; } - if let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = *inner_ty.kind() { + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *inner_ty.kind() { for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) { match predicate.kind().skip_binder() { // For `impl Trait`, it will register a predicate of `T: Trait`, so we go through @@ -250,7 +250,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { is_must_use_ty(cx, *ty) }, ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), - ty::Opaque(ty::AliasTy { def_id, substs: _ }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() { if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) { @@ -631,7 +631,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))), - ty::Opaque(ty::AliasTy { def_id, substs: _ }) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id)), + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id)), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), ty::Dynamic(bounds, _, _) => { let lang_items = cx.tcx.lang_items(); @@ -650,7 +650,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option None, } }, - ty::Projection(proj) => match cx.tcx.try_normalize_erasing_regions(cx.param_env, ty) { + ty::Alias(ty::Projection, proj) => match cx.tcx.try_normalize_erasing_regions(cx.param_env, ty) { Ok(normalized_ty) if normalized_ty != ty => ty_sig(cx, normalized_ty), _ => sig_for_projection(cx, proj).or_else(|| sig_from_bounds(cx, ty, cx.param_env.caller_bounds(), None)), }, From fa588dfff00db570099a7142f6990deabce94677 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 13 Dec 2022 11:07:42 +0000 Subject: [PATCH 0706/1222] Ensure no one constructs `AliasTy`s themselves --- clippy_lints/src/future_not_send.rs | 2 +- clippy_utils/src/ty.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index fcdac90fc237..989f83cf80d5 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { return; } let ret_ty = return_ty(cx, hir_id); - if let ty::Alias(ty::Opaque, AliasTy { def_id, substs }) = *ret_ty.kind() { + if let ty::Alias(ty::Opaque, AliasTy { def_id, substs, .. }) = *ret_ty.kind() { let preds = cx.tcx.explicit_item_bounds(def_id); let mut is_future = false; for &(p, _span) in preds { diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 33f3b3af3dc0..a6bcb134d408 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -79,7 +79,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' return true; } - if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *inner_ty.kind() { + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *inner_ty.kind() { for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) { match predicate.kind().skip_binder() { // For `impl Trait`, it will register a predicate of `T: Trait`, so we go through @@ -250,7 +250,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { is_must_use_ty(cx, *ty) }, ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), - ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() { if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) { @@ -631,7 +631,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))), - ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id)), + ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id)), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), ty::Dynamic(bounds, _, _) => { let lang_items = cx.tcx.lang_items(); @@ -1039,10 +1039,10 @@ pub fn make_projection<'tcx>( } } - Some(AliasTy { + Some(tcx.mk_alias_ty( + assoc_item.def_id, substs, - def_id: assoc_item.def_id, - }) + )) } helper( tcx, From fbf70b348e276c2aa9c3092082f127c171ad2b4f Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 13 Dec 2022 11:25:31 +0000 Subject: [PATCH 0707/1222] Remove TraitRef::new --- clippy_lints/src/derive.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 9e596ca8157e..3f0b165f2b60 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -15,7 +15,7 @@ use rustc_middle::hir::nested_filter; use rustc_middle::traits::Reveal; use rustc_middle::ty::{ self, Binder, BoundConstness, Clause, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate, - TraitRef, Ty, TyCtxt, + Ty, TyCtxt, }; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; @@ -513,9 +513,9 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> tcx.mk_predicates(ty_predicates.iter().map(|&(p, _)| p).chain( params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| { tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate { - trait_ref: TraitRef::new( + trait_ref: tcx.mk_trait_ref( eq_trait_id, - tcx.mk_substs(std::iter::once(tcx.mk_param_from_def(param))), + [tcx.mk_param_from_def(param)], ), constness: BoundConstness::NotConst, polarity: ImplPolarity::Positive, From f5049f75696eee7e4ff0d91a49e4f0eda1504746 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 15 Dec 2022 15:13:19 +1100 Subject: [PATCH 0708/1222] Merge `SimplifiedTypeGen` into `SimplifiedType`. `SimplifiedTypeGen` is the only instantiation used, so we don't need the generic parameter. --- clippy_utils/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 90192f46cbfa..652f8b4d3c56 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -97,7 +97,7 @@ use rustc_middle::hir::place::PlaceBase; use rustc_middle::ty as rustc_ty; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; use rustc_middle::ty::binding::BindingMode; -use rustc_middle::ty::fast_reject::SimplifiedTypeGen::{ +use rustc_middle::ty::fast_reject::SimplifiedType::{ ArraySimplifiedType, BoolSimplifiedType, CharSimplifiedType, FloatSimplifiedType, IntSimplifiedType, PtrSimplifiedType, SliceSimplifiedType, StrSimplifiedType, UintSimplifiedType, }; From 8d5e00854fe7e6c63c1dc424d134b2efcd890918 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 16 Dec 2022 03:06:21 +0000 Subject: [PATCH 0709/1222] Make Clippy test no longer unsound --- tests/ui/borrow_interior_mutable_const/others.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/borrow_interior_mutable_const/others.rs b/tests/ui/borrow_interior_mutable_const/others.rs index eefeb1decb69..7c57864245a9 100644 --- a/tests/ui/borrow_interior_mutable_const/others.rs +++ b/tests/ui/borrow_interior_mutable_const/others.rs @@ -42,7 +42,7 @@ impl StaticRef { impl std::ops::Deref for StaticRef { type Target = T; - fn deref(&self) -> &'static T { + fn deref(&self) -> &T { unsafe { &*self.ptr } } } From 06c56f86e6a509e2abed0baf3f64c72f0fb96224 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Wed, 28 Dec 2022 18:06:11 +0100 Subject: [PATCH 0710/1222] Rename `Rptr` to `Ref` in AST and HIR The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already as well. --- clippy_lints/src/dereference.rs | 4 ++-- clippy_lints/src/manual_async_fn.rs | 2 +- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/mut_mut.rs | 4 ++-- clippy_lints/src/needless_arbitrary_self_type.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/ptr.rs | 10 +++++----- clippy_lints/src/redundant_static_lifetimes.rs | 2 +- clippy_lints/src/ref_option_ref.rs | 4 ++-- clippy_lints/src/transmute/transmute_ptr_to_ref.rs | 2 +- clippy_lints/src/types/mod.rs | 2 +- clippy_lints/src/types/type_complexity.rs | 2 +- clippy_lints/src/types/utils.rs | 2 +- .../src/utils/internal_lints/lint_without_lint_pass.rs | 2 +- clippy_utils/src/ast_utils.rs | 2 +- clippy_utils/src/hir_utils.rs | 4 ++-- clippy_utils/src/lib.rs | 2 +- clippy_utils/src/sugg.rs | 4 ++-- clippy_utils/src/ty.rs | 2 +- 19 files changed, 28 insertions(+), 28 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 7b43d8ccc67d..05f2b92c0370 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -969,14 +969,14 @@ fn binding_ty_auto_deref_stability<'tcx>( precedence: i8, binder_args: &'tcx List, ) -> Position { - let TyKind::Rptr(_, ty) = &ty.kind else { + let TyKind::Ref(_, ty) = &ty.kind else { return Position::Other(precedence); }; let mut ty = ty; loop { break match ty.ty.kind { - TyKind::Rptr(_, ref ref_ty) => { + TyKind::Ref(_, ref ref_ty) => { ty = ref_ty; continue; }, diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 075ecbe7eded..676a37e04f60 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -152,7 +152,7 @@ fn captures_all_lifetimes(inputs: &[Ty<'_>], output_lifetimes: &[LifetimeName]) let input_lifetimes: Vec = inputs .iter() .filter_map(|ty| { - if let TyKind::Rptr(lt, _) = ty.kind { + if let TyKind::Ref(lt, _) = ty.kind { Some(lt.res) } else { None diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 561e4336593b..77be61b47934 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3986,7 +3986,7 @@ impl OutType { (Self::Unit, &hir::FnRetTy::Return(ty)) if is_unit(ty) => true, (Self::Bool, &hir::FnRetTy::Return(ty)) if is_bool(ty) => true, (Self::Any, &hir::FnRetTy::Return(ty)) if !is_unit(ty) => true, - (Self::Ref, &hir::FnRetTy::Return(ty)) => matches!(ty.kind, hir::TyKind::Rptr(_, _)), + (Self::Ref, &hir::FnRetTy::Return(ty)) => matches!(ty.kind, hir::TyKind::Ref(_, _)), _ => false, } } diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index bc90e131b7f3..64d8333a093b 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -86,7 +86,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { return; } - if let hir::TyKind::Rptr( + if let hir::TyKind::Ref( _, hir::MutTy { ty: pty, @@ -94,7 +94,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { }, ) = ty.kind { - if let hir::TyKind::Rptr( + if let hir::TyKind::Ref( _, hir::MutTy { mutbl: hir::Mutability::Mut, diff --git a/clippy_lints/src/needless_arbitrary_self_type.rs b/clippy_lints/src/needless_arbitrary_self_type.rs index f2ffac85bf40..5457eeec4eac 100644 --- a/clippy_lints/src/needless_arbitrary_self_type.rs +++ b/clippy_lints/src/needless_arbitrary_self_type.rs @@ -124,7 +124,7 @@ impl EarlyLintPass for NeedlessArbitrarySelfType { check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Value, mutbl); } }, - TyKind::Rptr(lifetime, mut_ty) => { + TyKind::Ref(lifetime, mut_ty) => { if_chain! { if let TyKind::Path(None, path) = &mut_ty.ty.kind; if let PatKind::Ident(BindingAnnotation::NONE, _, _) = p.pat.kind; diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index f9fd3645668a..75add4ee4aad 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -184,7 +184,7 @@ impl<'tcx> PassByRefOrValue { if is_copy(cx, ty) && let Some(size) = cx.layout_of(ty).ok().map(|l| l.size.bytes()) && size <= self.ref_min_size - && let hir::TyKind::Rptr(_, MutTy { ty: decl_ty, .. }) = input.kind + && let hir::TyKind::Ref(_, MutTy { ty: decl_ty, .. }) = input.kind { if let Some(typeck) = cx.maybe_typeck_results() { // Don't lint if an unsafe pointer is created. diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index e395ff54cb15..262953042581 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -421,7 +421,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>( if let ty::Ref(_, ty, mutability) = *ty.kind(); if let ty::Adt(adt, substs) = *ty.kind(); - if let TyKind::Rptr(lt, ref ty) = hir_ty.kind; + if let TyKind::Ref(lt, ref ty) = hir_ty.kind; if let TyKind::Path(QPath::Resolved(None, path)) = ty.ty.kind; // Check that the name as typed matches the actual name of the type. @@ -503,14 +503,14 @@ fn check_fn_args<'cx, 'tcx: 'cx>( fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Option<&'tcx Body<'_>>) { if let FnRetTy::Return(ty) = sig.decl.output - && let Some((out, Mutability::Mut, _)) = get_rptr_lm(ty) + && let Some((out, Mutability::Mut, _)) = get_ref_lm(ty) { let out_region = cx.tcx.named_region(out.hir_id); let args: Option> = sig .decl .inputs .iter() - .filter_map(get_rptr_lm) + .filter_map(get_ref_lm) .filter(|&(lt, _, _)| cx.tcx.named_region(lt.hir_id) == out_region) .map(|(_, mutability, span)| (mutability == Mutability::Not).then_some(span)) .collect(); @@ -704,8 +704,8 @@ fn matches_preds<'tcx>( }) } -fn get_rptr_lm<'tcx>(ty: &'tcx hir::Ty<'tcx>) -> Option<(&'tcx Lifetime, Mutability, Span)> { - if let TyKind::Rptr(lt, ref m) = ty.kind { +fn get_ref_lm<'tcx>(ty: &'tcx hir::Ty<'tcx>) -> Option<(&'tcx Lifetime, Mutability, Span)> { + if let TyKind::Ref(lt, ref m) = ty.kind { Some((lt, m.mutbl, ty.span)) } else { None diff --git a/clippy_lints/src/redundant_static_lifetimes.rs b/clippy_lints/src/redundant_static_lifetimes.rs index 41f991a967bf..44bf824aa0e2 100644 --- a/clippy_lints/src/redundant_static_lifetimes.rs +++ b/clippy_lints/src/redundant_static_lifetimes.rs @@ -59,7 +59,7 @@ impl RedundantStaticLifetimes { } }, // This is what we are looking for ! - TyKind::Rptr(ref optional_lifetime, ref borrow_type) => { + TyKind::Ref(ref optional_lifetime, ref borrow_type) => { // Match the 'static lifetime if let Some(lifetime) = *optional_lifetime { match borrow_type.ty.kind { diff --git a/clippy_lints/src/ref_option_ref.rs b/clippy_lints/src/ref_option_ref.rs index f21b3ea6c3b0..448a32b77c03 100644 --- a/clippy_lints/src/ref_option_ref.rs +++ b/clippy_lints/src/ref_option_ref.rs @@ -39,7 +39,7 @@ declare_lint_pass!(RefOptionRef => [REF_OPTION_REF]); impl<'tcx> LateLintPass<'tcx> for RefOptionRef { fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx Ty<'tcx>) { if_chain! { - if let TyKind::Rptr(_, ref mut_ty) = ty.kind; + if let TyKind::Ref(_, ref mut_ty) = ty.kind; if mut_ty.mutbl == Mutability::Not; if let TyKind::Path(ref qpath) = &mut_ty.ty.kind; let last = last_path_segment(qpath); @@ -52,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for RefOptionRef { GenericArg::Type(inner_ty) => Some(inner_ty), _ => None, }); - if let TyKind::Rptr(_, ref inner_mut_ty) = inner_ty.kind; + if let TyKind::Ref(_, ref inner_mut_ty) = inner_ty.kind; if inner_mut_ty.mutbl == Mutability::Not; then { diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs index 3dde4eee6717..54ac04df1c12 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs @@ -71,7 +71,7 @@ pub(super) fn check<'tcx>( /// Gets the type `Bar` in `…::transmute`. fn get_explicit_type<'tcx>(path: &'tcx Path<'tcx>) -> Option<&'tcx hir::Ty<'tcx>> { if let GenericArg::Type(ty) = path.segments.last()?.args?.args.get(1)? - && let TyKind::Rptr(_, ty) = &ty.kind + && let TyKind::Ref(_, ty) = &ty.kind { Some(ty.ty) } else { diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 20978e81dc58..c14f056a1f2d 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -539,7 +539,7 @@ impl Types { QPath::LangItem(..) => {}, } }, - TyKind::Rptr(lt, ref mut_ty) => { + TyKind::Ref(lt, ref mut_ty) => { context.is_nested_call = true; if !borrowed_box::check(cx, hir_ty, lt, mut_ty) { self.check_ty(cx, mut_ty.ty, context); diff --git a/clippy_lints/src/types/type_complexity.rs b/clippy_lints/src/types/type_complexity.rs index 5ca4023aa5c1..0aa50c99c169 100644 --- a/clippy_lints/src/types/type_complexity.rs +++ b/clippy_lints/src/types/type_complexity.rs @@ -44,7 +44,7 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor { fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) { let (add_score, sub_nest) = match ty.kind { // _, &x and *x have only small overhead; don't mess with nesting level - TyKind::Infer | TyKind::Ptr(..) | TyKind::Rptr(..) => (1, 0), + TyKind::Infer | TyKind::Ptr(..) | TyKind::Ref(..) => (1, 0), // the "normal" components of a type: named types, arrays/tuples TyKind::Path(..) | TyKind::Slice(..) | TyKind::Tup(..) | TyKind::Array(..) => (10 * self.nest, 1), diff --git a/clippy_lints/src/types/utils.rs b/clippy_lints/src/types/utils.rs index 0fa75f8f0a9b..7f43b7841ff3 100644 --- a/clippy_lints/src/types/utils.rs +++ b/clippy_lints/src/types/utils.rs @@ -13,7 +13,7 @@ pub(super) fn match_borrows_parameter(_cx: &LateContext<'_>, qpath: &QPath<'_>) GenericArg::Type(ty) => Some(ty), _ => None, }); - if let TyKind::Rptr(..) = ty.kind; + if let TyKind::Ref(..) = ty.kind; then { return Some(ty.span); } diff --git a/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs b/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs index 786d9608c851..4c3b1b131fd4 100644 --- a/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs +++ b/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs @@ -257,7 +257,7 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { } pub(super) fn is_lint_ref_type(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool { - if let TyKind::Rptr( + if let TyKind::Ref( _, MutTy { ty: inner, diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 49e5f283db08..9d0263e93be7 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -625,7 +625,7 @@ pub fn eq_ty(l: &Ty, r: &Ty) -> bool { (Slice(l), Slice(r)) => eq_ty(l, r), (Array(le, ls), Array(re, rs)) => eq_ty(le, re) && eq_expr(&ls.value, &rs.value), (Ptr(l), Ptr(r)) => l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty), - (Rptr(ll, l), Rptr(rl, r)) => { + (Ref(ll, l), Ref(rl, r)) => { both(ll, rl, |l, r| eq_id(l.ident, r.ident)) && l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty) }, (BareFn(l), BareFn(r)) => { diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 07fb6af91ba0..2bbe1a19b625 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -430,7 +430,7 @@ impl HirEqInterExpr<'_, '_, '_> { (&TyKind::Slice(l_vec), &TyKind::Slice(r_vec)) => self.eq_ty(l_vec, r_vec), (&TyKind::Array(lt, ll), &TyKind::Array(rt, rl)) => self.eq_ty(lt, rt) && self.eq_array_length(ll, rl), (TyKind::Ptr(l_mut), TyKind::Ptr(r_mut)) => l_mut.mutbl == r_mut.mutbl && self.eq_ty(l_mut.ty, r_mut.ty), - (TyKind::Rptr(_, l_rmut), TyKind::Rptr(_, r_rmut)) => { + (TyKind::Ref(_, l_rmut), TyKind::Ref(_, r_rmut)) => { l_rmut.mutbl == r_rmut.mutbl && self.eq_ty(l_rmut.ty, r_rmut.ty) }, (TyKind::Path(l), TyKind::Path(r)) => self.eq_qpath(l, r), @@ -950,7 +950,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_ty(mut_ty.ty); mut_ty.mutbl.hash(&mut self.s); }, - TyKind::Rptr(lifetime, ref mut_ty) => { + TyKind::Ref(lifetime, ref mut_ty) => { self.hash_lifetime(lifetime); self.hash_ty(mut_ty.ty); mut_ty.mutbl.hash(&mut self.s); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 43e2d1ec826c..d863609b6a72 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -2264,7 +2264,7 @@ pub fn peel_hir_ty_refs<'a>(mut ty: &'a hir::Ty<'a>) -> (&'a hir::Ty<'a>, usize) let mut count = 0; loop { match &ty.kind { - TyKind::Rptr(_, ref_ty) => { + TyKind::Ref(_, ref_ty) => { ty = ref_ty.ty; count += 1; }, diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index b66604f33db1..a203a7afddf8 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -813,9 +813,9 @@ pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Opti let closure_body = cx.tcx.hir().body(body); // is closure arg a type annotated double reference (i.e.: `|x: &&i32| ...`) // a type annotation is present if param `kind` is different from `TyKind::Infer` - let closure_arg_is_type_annotated_double_ref = if let TyKind::Rptr(_, MutTy { ty, .. }) = fn_decl.inputs[0].kind + let closure_arg_is_type_annotated_double_ref = if let TyKind::Ref(_, MutTy { ty, .. }) = fn_decl.inputs[0].kind { - matches!(ty.kind, TyKind::Rptr(_, MutTy { .. })) + matches!(ty.kind, TyKind::Ref(_, MutTy { .. })) } else { false }; diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 2773da70d788..c8d56a3be5cf 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -496,7 +496,7 @@ pub fn type_is_unsafe_function<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bo /// Returns the base type for HIR references and pointers. pub fn walk_ptrs_hir_ty<'tcx>(ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> { match ty.kind { - TyKind::Ptr(ref mut_ty) | TyKind::Rptr(_, ref mut_ty) => walk_ptrs_hir_ty(mut_ty.ty), + TyKind::Ptr(ref mut_ty) | TyKind::Ref(_, ref mut_ty) => walk_ptrs_hir_ty(mut_ty.ty), _ => ty, } } From e8872563b764ab14c00e74dc9dd293797d902894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 27 Dec 2022 11:03:59 -0800 Subject: [PATCH 0711/1222] Account for multiple multiline spans with empty padding Instead of ``` LL | fn oom( | __^ | | _| | || LL | || ) { | ||_- LL | | } | |__^ ``` emit ``` LL | // fn oom( LL | || ) { | ||_- LL | | } | |__^ ``` --- tests/ui/async_yields_async.stderr | 6 ++---- tests/ui/result_map_unit_fn_unfixable.stderr | 5 +---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/ui/async_yields_async.stderr b/tests/ui/async_yields_async.stderr index 92ba35929678..22ce1c6f6471 100644 --- a/tests/ui/async_yields_async.stderr +++ b/tests/ui/async_yields_async.stderr @@ -3,8 +3,7 @@ error: an async construct yields a type which is itself awaitable | LL | let _h = async { | _____________________- -LL | | async { - | | _________^ +LL | |/ async { LL | || 3 LL | || } | ||_________^ awaitable value not awaited @@ -37,8 +36,7 @@ error: an async construct yields a type which is itself awaitable | LL | let _j = async || { | ________________________- -LL | | async { - | | _________^ +LL | |/ async { LL | || 3 LL | || } | ||_________^ awaitable value not awaited diff --git a/tests/ui/result_map_unit_fn_unfixable.stderr b/tests/ui/result_map_unit_fn_unfixable.stderr index 2e1eb8eb1806..d0e534f63568 100644 --- a/tests/ui/result_map_unit_fn_unfixable.stderr +++ b/tests/ui/result_map_unit_fn_unfixable.stderr @@ -19,10 +19,7 @@ LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` --> $DIR/result_map_unit_fn_unfixable.rs:29:5 | -LL | x.field.map(|value| { - | ______^ - | | _____| - | || +LL | // x.field.map(|value| { LL | || do_nothing(value); LL | || do_nothing(value) LL | || }); From 2afb198feb8cbd6af9f04ee8b7c90eec46f079e5 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 3 Jan 2023 07:31:04 +0000 Subject: [PATCH 0712/1222] rename get_parent_node to parent_id --- clippy_lints/src/escape.rs | 6 +++--- clippy_lints/src/index_refutable_slice.rs | 4 ++-- clippy_lints/src/loops/same_item_push.rs | 2 +- clippy_lints/src/manual_rem_euclid.rs | 2 +- clippy_lints/src/matches/match_single_binding.rs | 6 +++--- clippy_lints/src/mixed_read_write_in_expression.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/unit_types/unit_arg.rs | 4 ++-- clippy_lints/src/unnecessary_wraps.rs | 2 +- clippy_lints/src/utils/internal_lints/metadata_collector.rs | 2 +- .../src/utils/internal_lints/unnecessary_def_path.rs | 2 +- clippy_utils/src/lib.rs | 4 ++-- 14 files changed, 21 insertions(+), 21 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 1d09adec12f3..58b7b9829a10 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -131,7 +131,7 @@ fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool { _ => return false, } - matches!(map.find(map.get_parent_node(id)), Some(Node::Param(_))) + matches!(map.find(map.parent_id(id)), Some(Node::Param(_))) } impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { @@ -156,8 +156,8 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { let map = &self.cx.tcx.hir(); if is_argument(*map, cmt.hir_id) { // Skip closure arguments - let parent_id = map.get_parent_node(cmt.hir_id); - if let Some(Node::Expr(..)) = map.find(map.get_parent_node(parent_id)) { + let parent_id = map.parent_id(cmt.hir_id); + if let Some(Node::Expr(..)) = map.find(map.parent_id(parent_id)) { return; } diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index cf35b1f175c6..bdeddf44df7b 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -251,7 +251,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> { let map = cx.tcx.hir(); // Checking for slice indexing - let parent_id = map.get_parent_node(expr.hir_id); + let parent_id = map.parent_id(expr.hir_id); if let Some(hir::Node::Expr(parent_expr)) = map.find(parent_id); if let hir::ExprKind::Index(_, index_expr) = parent_expr.kind; if let Some((Constant::Int(index_value), _)) = constant(cx, cx.typeck_results(), index_expr); @@ -259,7 +259,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> { if index_value < max_suggested_slice; // Make sure that this slice index is read only - let maybe_addrof_id = map.get_parent_node(parent_id); + let maybe_addrof_id = map.parent_id(parent_id); if let Some(hir::Node::Expr(maybe_addrof_expr)) = map.find(maybe_addrof_id); if let hir::ExprKind::AddrOf(_kind, hir::Mutability::Not, _inner_expr) = maybe_addrof_expr.kind; then { diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index 07edee46fa65..540656a2cd99 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -63,7 +63,7 @@ pub(super) fn check<'tcx>( if let Node::Pat(pat) = node; if let PatKind::Binding(bind_ann, ..) = pat.kind; if !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut)); - let parent_node = cx.tcx.hir().get_parent_node(hir_id); + let parent_node = cx.tcx.hir().parent_id(hir_id); if let Some(Node::Local(parent_let_expr)) = cx.tcx.hir().find(parent_node); if let Some(init) = parent_let_expr.init; then { diff --git a/clippy_lints/src/manual_rem_euclid.rs b/clippy_lints/src/manual_rem_euclid.rs index 8d447c37150b..494fde395e93 100644 --- a/clippy_lints/src/manual_rem_euclid.rs +++ b/clippy_lints/src/manual_rem_euclid.rs @@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid { && let Some(hir_id) = path_to_local(expr3) && let Some(Node::Pat(_)) = cx.tcx.hir().find(hir_id) { // Apply only to params or locals with annotated types - match cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { + match cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) { Some(Node::Param(..)) => (), Some(Node::Local(local)) => { let Some(ty) = local.ty else { return }; diff --git a/clippy_lints/src/matches/match_single_binding.rs b/clippy_lints/src/matches/match_single_binding.rs index c94a1f763306..abe9d231f4aa 100644 --- a/clippy_lints/src/matches/match_single_binding.rs +++ b/clippy_lints/src/matches/match_single_binding.rs @@ -140,8 +140,8 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e fn opt_parent_assign_span<'a>(cx: &LateContext<'a>, ex: &Expr<'a>) -> Option { let map = &cx.tcx.hir(); - if let Some(Node::Expr(parent_arm_expr)) = map.find(map.get_parent_node(ex.hir_id)) { - return match map.find(map.get_parent_node(parent_arm_expr.hir_id)) { + if let Some(Node::Expr(parent_arm_expr)) = map.find(map.parent_id(ex.hir_id)) { + return match map.find(map.parent_id(parent_arm_expr.hir_id)) { Some(Node::Local(parent_let_expr)) => Some(AssignmentExpr::Local { span: parent_let_expr.span, pat_span: parent_let_expr.pat.span(), @@ -183,7 +183,7 @@ fn sugg_with_curlies<'a>( // If the parent is already an arm, and the body is another match statement, // we need curly braces around suggestion - let parent_node_id = cx.tcx.hir().get_parent_node(match_expr.hir_id); + let parent_node_id = cx.tcx.hir().parent_id(match_expr.hir_id); if let Node::Arm(arm) = &cx.tcx.hir().get(parent_node_id) { if let ExprKind::Match(..) = arm.body.kind { cbrace_end = format!("\n{indent}}}"); diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs index 321fa4b7f999..f0be7771bb1a 100644 --- a/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/clippy_lints/src/mixed_read_write_in_expression.rs @@ -186,7 +186,7 @@ fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) { let map = &vis.cx.tcx.hir(); let mut cur_id = vis.write_expr.hir_id; loop { - let parent_id = map.get_parent_node(cur_id); + let parent_id = map.parent_id(cur_id); if parent_id == cur_id { break; } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 2f0b7ce16e51..58c54280a234 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -100,7 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { } // Exclude non-inherent impls - if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { + if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) { if matches!( item.kind, ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 2a3bd4ee6ce6..07fd321d69fc 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -366,7 +366,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { let mut dereferenced_expr = expr; let mut needs_check_adjustment = true; loop { - let parent_id = cx.tcx.hir().get_parent_node(cur_expr.hir_id); + let parent_id = cx.tcx.hir().parent_id(cur_expr.hir_id); if parent_id == cur_expr.hir_id { break; } diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 75add4ee4aad..f96a19b27235 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -299,7 +299,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { } // Exclude non-inherent impls - if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { + if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) { if matches!( item.kind, ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) diff --git a/clippy_lints/src/unit_types/unit_arg.rs b/clippy_lints/src/unit_types/unit_arg.rs index ef9f740f7047..ac4f8789a434 100644 --- a/clippy_lints/src/unit_types/unit_arg.rs +++ b/clippy_lints/src/unit_types/unit_arg.rs @@ -21,7 +21,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { return; } let map = &cx.tcx.hir(); - let opt_parent_node = map.find(map.get_parent_node(expr.hir_id)); + let opt_parent_node = map.find(map.parent_id(expr.hir_id)); if_chain! { if let Some(hir::Node::Expr(parent_expr)) = opt_parent_node; if is_questionmark_desugar_marked_call(parent_expr); @@ -192,7 +192,7 @@ fn fmt_stmts_and_call( let mut stmts_and_call_snippet = stmts_and_call.join(&format!("{}{}", ";\n", " ".repeat(call_expr_indent))); // expr is not in a block statement or result expression position, wrap in a block - let parent_node = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(call_expr.hir_id)); + let parent_node = cx.tcx.hir().find(cx.tcx.hir().parent_id(call_expr.hir_id)); if !matches!(parent_node, Some(Node::Block(_))) && !matches!(parent_node, Some(Node::Stmt(_))) { let block_indent = call_expr_indent + 4; stmts_and_call_snippet = diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index 60b46854b4ff..63f4f01b0877 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { } // Abort if the method is implementing a trait or of it a trait method. - if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { + if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) { if matches!( item.kind, ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index 929544cd69d5..a177ae507bbe 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -1058,7 +1058,7 @@ fn get_parent_local<'hir>(cx: &LateContext<'hir>, expr: &'hir hir::Expr<'hir>) - fn get_parent_local_hir_id<'hir>(cx: &LateContext<'hir>, hir_id: hir::HirId) -> Option<&'hir hir::Local<'hir>> { let map = cx.tcx.hir(); - match map.find(map.get_parent_node(hir_id)) { + match map.find(map.parent_id(hir_id)) { Some(hir::Node::Local(local)) => Some(local), Some(hir::Node::Pat(pattern)) => get_parent_local_hir_id(cx, pattern.hir_id), _ => None, diff --git a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs index 393988dbad38..7144363637a0 100644 --- a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs +++ b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs @@ -219,7 +219,7 @@ fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option match cx.qpath_res(qpath, expr.hir_id) { Res::Local(hir_id) => { - let parent_id = cx.tcx.hir().get_parent_node(hir_id); + let parent_id = cx.tcx.hir().parent_id(hir_id); if let Some(Node::Local(Local { init: Some(init), .. })) = cx.tcx.hir().find(parent_id) { path_to_matched_type(cx, init) } else { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index d863609b6a72..63d0938169a8 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -174,7 +174,7 @@ pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option< if_chain! { if let Some(Node::Pat(pat)) = hir.find(hir_id); if matches!(pat.kind, PatKind::Binding(BindingAnnotation::NONE, ..)); - let parent = hir.get_parent_node(hir_id); + let parent = hir.parent_id(hir_id); if let Some(Node::Local(local)) = hir.find(parent); then { return local.init; @@ -2075,7 +2075,7 @@ pub fn is_no_core_crate(cx: &LateContext<'_>) -> bool { /// } /// ``` pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool { - if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { + if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) { matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) } else { false From 727468881fb809aa75045013c24f884ae8ca74f6 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 3 Jan 2023 07:31:33 +0000 Subject: [PATCH 0713/1222] rename find_parent_node to opt_parent_id --- clippy_lints/src/casts/cast_slice_different_sizes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/casts/cast_slice_different_sizes.rs b/clippy_lints/src/casts/cast_slice_different_sizes.rs index c8e54d7b8e0c..27cc5a1c3f04 100644 --- a/clippy_lints/src/casts/cast_slice_different_sizes.rs +++ b/clippy_lints/src/casts/cast_slice_different_sizes.rs @@ -68,7 +68,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv fn is_child_of_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let map = cx.tcx.hir(); if_chain! { - if let Some(parent_id) = map.find_parent_node(expr.hir_id); + if let Some(parent_id) = map.opt_parent_id(expr.hir_id); if let Some(parent) = map.find(parent_id); then { let expr = match parent { From 0110b0a1f79d9223ac1d63c4ae549500a26f82ab Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 3 Jan 2023 17:30:35 +0000 Subject: [PATCH 0714/1222] get_parent and find_parent --- clippy_lints/src/escape.rs | 4 ++-- clippy_lints/src/manual_rem_euclid.rs | 2 +- clippy_lints/src/matches/match_single_binding.rs | 7 +++---- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/unit_types/unit_arg.rs | 4 ++-- clippy_lints/src/unnecessary_wraps.rs | 2 +- .../src/utils/internal_lints/metadata_collector.rs | 2 +- clippy_utils/src/lib.rs | 4 ++-- 9 files changed, 14 insertions(+), 15 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 58b7b9829a10..dfb43893326e 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -131,7 +131,7 @@ fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool { _ => return false, } - matches!(map.find(map.parent_id(id)), Some(Node::Param(_))) + matches!(map.find_parent(id), Some(Node::Param(_))) } impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { @@ -157,7 +157,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { if is_argument(*map, cmt.hir_id) { // Skip closure arguments let parent_id = map.parent_id(cmt.hir_id); - if let Some(Node::Expr(..)) = map.find(map.parent_id(parent_id)) { + if let Some(Node::Expr(..)) = map.find_parent(parent_id) { return; } diff --git a/clippy_lints/src/manual_rem_euclid.rs b/clippy_lints/src/manual_rem_euclid.rs index 494fde395e93..38f41d077c16 100644 --- a/clippy_lints/src/manual_rem_euclid.rs +++ b/clippy_lints/src/manual_rem_euclid.rs @@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid { && let Some(hir_id) = path_to_local(expr3) && let Some(Node::Pat(_)) = cx.tcx.hir().find(hir_id) { // Apply only to params or locals with annotated types - match cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) { + match cx.tcx.hir().find_parent(hir_id) { Some(Node::Param(..)) => (), Some(Node::Local(local)) => { let Some(ty) = local.ty else { return }; diff --git a/clippy_lints/src/matches/match_single_binding.rs b/clippy_lints/src/matches/match_single_binding.rs index abe9d231f4aa..065a5c72621c 100644 --- a/clippy_lints/src/matches/match_single_binding.rs +++ b/clippy_lints/src/matches/match_single_binding.rs @@ -140,8 +140,8 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e fn opt_parent_assign_span<'a>(cx: &LateContext<'a>, ex: &Expr<'a>) -> Option { let map = &cx.tcx.hir(); - if let Some(Node::Expr(parent_arm_expr)) = map.find(map.parent_id(ex.hir_id)) { - return match map.find(map.parent_id(parent_arm_expr.hir_id)) { + if let Some(Node::Expr(parent_arm_expr)) = map.find_parent(ex.hir_id) { + return match map.find_parent(parent_arm_expr.hir_id) { Some(Node::Local(parent_let_expr)) => Some(AssignmentExpr::Local { span: parent_let_expr.span, pat_span: parent_let_expr.pat.span(), @@ -183,8 +183,7 @@ fn sugg_with_curlies<'a>( // If the parent is already an arm, and the body is another match statement, // we need curly braces around suggestion - let parent_node_id = cx.tcx.hir().parent_id(match_expr.hir_id); - if let Node::Arm(arm) = &cx.tcx.hir().get(parent_node_id) { + if let Node::Arm(arm) = &cx.tcx.hir().get_parent(match_expr.hir_id) { if let ExprKind::Match(..) = arm.body.kind { cbrace_end = format!("\n{indent}}}"); // Fix body indent due to the match diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 58c54280a234..1249db5dc479 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -100,7 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { } // Exclude non-inherent impls - if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) { + if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) { if matches!( item.kind, ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index f96a19b27235..870a1c7d88d5 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -299,7 +299,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { } // Exclude non-inherent impls - if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) { + if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) { if matches!( item.kind, ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) diff --git a/clippy_lints/src/unit_types/unit_arg.rs b/clippy_lints/src/unit_types/unit_arg.rs index ac4f8789a434..dd120599c04e 100644 --- a/clippy_lints/src/unit_types/unit_arg.rs +++ b/clippy_lints/src/unit_types/unit_arg.rs @@ -21,7 +21,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { return; } let map = &cx.tcx.hir(); - let opt_parent_node = map.find(map.parent_id(expr.hir_id)); + let opt_parent_node = map.find_parent(expr.hir_id); if_chain! { if let Some(hir::Node::Expr(parent_expr)) = opt_parent_node; if is_questionmark_desugar_marked_call(parent_expr); @@ -192,7 +192,7 @@ fn fmt_stmts_and_call( let mut stmts_and_call_snippet = stmts_and_call.join(&format!("{}{}", ";\n", " ".repeat(call_expr_indent))); // expr is not in a block statement or result expression position, wrap in a block - let parent_node = cx.tcx.hir().find(cx.tcx.hir().parent_id(call_expr.hir_id)); + let parent_node = cx.tcx.hir().find_parent(call_expr.hir_id); if !matches!(parent_node, Some(Node::Block(_))) && !matches!(parent_node, Some(Node::Stmt(_))) { let block_indent = call_expr_indent + 4; stmts_and_call_snippet = diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index 63f4f01b0877..84ec0d0fb1cf 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { } // Abort if the method is implementing a trait or of it a trait method. - if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) { + if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) { if matches!( item.kind, ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index a177ae507bbe..c86f24cbd378 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -1058,7 +1058,7 @@ fn get_parent_local<'hir>(cx: &LateContext<'hir>, expr: &'hir hir::Expr<'hir>) - fn get_parent_local_hir_id<'hir>(cx: &LateContext<'hir>, hir_id: hir::HirId) -> Option<&'hir hir::Local<'hir>> { let map = cx.tcx.hir(); - match map.find(map.parent_id(hir_id)) { + match map.find_parent((hir_id)) { Some(hir::Node::Local(local)) => Some(local), Some(hir::Node::Pat(pattern)) => get_parent_local_hir_id(cx, pattern.hir_id), _ => None, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 63d0938169a8..8290fe9ecb4c 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1287,7 +1287,7 @@ pub fn contains_return(expr: &hir::Expr<'_>) -> bool { /// Gets the parent node, if any. pub fn get_parent_node(tcx: TyCtxt<'_>, id: HirId) -> Option> { - tcx.hir().parent_iter(id).next().map(|(_, node)| node) + tcx.hir().find_parent(id) } /// Gets the parent expression, if any –- this is useful to constrain a lint. @@ -2075,7 +2075,7 @@ pub fn is_no_core_crate(cx: &LateContext<'_>) -> bool { /// } /// ``` pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool { - if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) { + if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) { matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) } else { false From 0ca5f8d076e347aec14b31e687809539ed14369d Mon Sep 17 00:00:00 2001 From: Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> Date: Thu, 5 Jan 2023 09:45:44 +0100 Subject: [PATCH 0715/1222] Change `src/test` to `tests` in source files, fix tidy and tests --- tests/ui/crashes/ice-6254.rs | 2 +- tests/ui/crashes/ice-6255.rs | 2 +- tests/ui/crashes/ice-6256.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ui/crashes/ice-6254.rs b/tests/ui/crashes/ice-6254.rs index a2a60a169153..8af60890390e 100644 --- a/tests/ui/crashes/ice-6254.rs +++ b/tests/ui/crashes/ice-6254.rs @@ -1,4 +1,4 @@ -// originally from ./src/test/ui/pattern/usefulness/consts-opaque.rs +// originally from ./tests/ui/pattern/usefulness/consts-opaque.rs // panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', // compiler/rustc_mir_build/src/thir/pattern/_match.rs:2030:5 diff --git a/tests/ui/crashes/ice-6255.rs b/tests/ui/crashes/ice-6255.rs index bd4a81d98e2e..ccde6aa2b0f7 100644 --- a/tests/ui/crashes/ice-6255.rs +++ b/tests/ui/crashes/ice-6255.rs @@ -1,4 +1,4 @@ -// originally from rustc ./src/test/ui/macros/issue-78325-inconsistent-resolution.rs +// originally from rustc ./tests/ui/macros/issue-78325-inconsistent-resolution.rs // inconsistent resolution for a macro macro_rules! define_other_core { diff --git a/tests/ui/crashes/ice-6256.rs b/tests/ui/crashes/ice-6256.rs index 67308263dadd..f9ee3e058c11 100644 --- a/tests/ui/crashes/ice-6256.rs +++ b/tests/ui/crashes/ice-6256.rs @@ -1,4 +1,4 @@ -// originally from rustc ./src/test/ui/regions/issue-78262.rs +// originally from rustc ./tests/ui/regions/issue-78262.rs // ICE: to get the signature of a closure, use substs.as_closure().sig() not fn_sig() #![allow(clippy::upper_case_acronyms)] From 776a2f36644d65bc77b97ad34cc5738688caca1e Mon Sep 17 00:00:00 2001 From: asquared31415 <34665709+asquared31415@users.noreply.github.com> Date: Fri, 23 Dec 2022 13:54:14 -0500 Subject: [PATCH 0716/1222] add checks for the signature of the lang item --- tests/ui/def_id_nocore.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/def_id_nocore.rs b/tests/ui/def_id_nocore.rs index a7da8f89aa3d..1af77d1a25b2 100644 --- a/tests/ui/def_id_nocore.rs +++ b/tests/ui/def_id_nocore.rs @@ -15,7 +15,7 @@ pub trait Copy {} pub unsafe trait Freeze {} #[lang = "start"] -fn start(_main: fn() -> T, _argc: isize, _argv: *const *const u8) -> isize { +fn start(_main: fn() -> T, _argc: isize, _argv: *const *const u8, _sigpipe: u8) -> isize { 0 } From 0b13c142670db99152f0a02c45641b4a48a555a0 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 11 Jan 2023 21:42:08 +0100 Subject: [PATCH 0717/1222] Make clippy compile. --- clippy_utils/src/sugg.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index e7879bb196e4..2d1044af17e8 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -219,6 +219,7 @@ impl<'a> Sugg<'a> { | ast::ExprKind::Repeat(..) | ast::ExprKind::Ret(..) | ast::ExprKind::Yeet(..) + | ast::ExprKind::FormatArgs(..) | ast::ExprKind::Struct(..) | ast::ExprKind::Try(..) | ast::ExprKind::TryBlock(..) From e6ccba315bd4de71de3c3a78d8d2bd9e7fff8b4c Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Thu, 12 Jan 2023 00:25:09 +0100 Subject: [PATCH 0718/1222] Update clippy for new format_args!() lang items. --- clippy_lints/src/format_args.rs | 6 ++-- clippy_utils/src/macros.rs | 54 +++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/clippy_lints/src/format_args.rs b/clippy_lints/src/format_args.rs index 043112bbc959..70a80d40f464 100644 --- a/clippy_lints/src/format_args.rs +++ b/clippy_lints/src/format_args.rs @@ -7,14 +7,14 @@ use clippy_utils::macros::{ }; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::source::snippet_opt; -use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; +use clippy_utils::ty::{implements_trait, is_type_lang_item}; use if_chain::if_chain; use itertools::Itertools; use rustc_errors::{ Applicability, SuggestionStyle::{CompletelyHidden, ShowCode}, }; -use rustc_hir::{Expr, ExprKind, HirId, QPath}; +use rustc_hir::{Expr, ExprKind, HirId, LangItem, QPath}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::ty::adjustment::{Adjust, Adjustment}; use rustc_middle::ty::Ty; @@ -237,7 +237,7 @@ fn check_unused_format_specifier(cx: &LateContext<'_>, arg: &FormatArg<'_>) { ); } - if is_type_diagnostic_item(cx, param_ty, sym::Arguments) && !arg.format.is_default_for_trait() { + if is_type_lang_item(cx, param_ty, LangItem::FormatArguments) && !arg.format.is_default_for_trait() { span_lint_and_then( cx, UNUSED_FORMAT_SPECS, diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs index 77c5f1155423..a8f8da67b517 100644 --- a/clippy_utils/src/macros.rs +++ b/clippy_utils/src/macros.rs @@ -1,6 +1,5 @@ #![allow(clippy::similar_names)] // `expr` and `expn` -use crate::is_path_diagnostic_item; use crate::source::snippet_opt; use crate::visitors::{for_each_expr, Descend}; @@ -8,7 +7,7 @@ use arrayvec::ArrayVec; use itertools::{izip, Either, Itertools}; use rustc_ast::ast::LitKind; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::{self as hir, Expr, ExprField, ExprKind, HirId, Node, QPath}; +use rustc_hir::{self as hir, Expr, ExprField, ExprKind, HirId, LangItem, Node, QPath, TyKind}; use rustc_lexer::unescape::unescape_literal; use rustc_lexer::{tokenize, unescape, LiteralKind, TokenKind}; use rustc_lint::LateContext; @@ -439,8 +438,7 @@ impl<'tcx> FormatArgsValues<'tcx> { // ArgumentV1::from_usize() if let ExprKind::Call(callee, [val]) = expr.kind && let ExprKind::Path(QPath::TypeRelative(ty, _)) = callee.kind - && let hir::TyKind::Path(QPath::Resolved(_, path)) = ty.kind - && path.segments.last().unwrap().ident.name == sym::ArgumentV1 + && let TyKind::Path(QPath::LangItem(LangItem::FormatArgument, _, _)) = ty.kind { let val_idx = if val.span.ctxt() == expr.span.ctxt() && let ExprKind::Field(_, field) = val.kind @@ -486,20 +484,6 @@ struct ParamPosition { impl<'tcx> Visitor<'tcx> for ParamPosition { fn visit_expr_field(&mut self, field: &'tcx ExprField<'tcx>) { - fn parse_count(expr: &Expr<'_>) -> Option { - // ::core::fmt::rt::v1::Count::Param(1usize), - if let ExprKind::Call(ctor, [val]) = expr.kind - && let ExprKind::Path(QPath::Resolved(_, path)) = ctor.kind - && path.segments.last()?.ident.name == sym::Param - && let ExprKind::Lit(lit) = &val.kind - && let LitKind::Int(pos, _) = lit.node - { - Some(pos as usize) - } else { - None - } - } - match field.ident.name { sym::position => { if let ExprKind::Lit(lit) = &field.expr.kind @@ -519,15 +503,41 @@ impl<'tcx> Visitor<'tcx> for ParamPosition { } } +fn parse_count(expr: &Expr<'_>) -> Option { + // <::core::fmt::rt::v1::Count>::Param(1usize), + if let ExprKind::Call(ctor, [val]) = expr.kind + && let ExprKind::Path(QPath::TypeRelative(_, path)) = ctor.kind + && path.ident.name == sym::Param + && let ExprKind::Lit(lit) = &val.kind + && let LitKind::Int(pos, _) = lit.node + { + Some(pos as usize) + } else { + None + } +} + /// Parses the `fmt` arg of `Arguments::new_v1_formatted(pieces, args, fmt, _)` fn parse_rt_fmt<'tcx>(fmt_arg: &'tcx Expr<'tcx>) -> Option + 'tcx> { if let ExprKind::AddrOf(.., array) = fmt_arg.kind && let ExprKind::Array(specs) = array.kind { Some(specs.iter().map(|spec| { - let mut position = ParamPosition::default(); - position.visit_expr(spec); - position + if let ExprKind::Call(f, args) = spec.kind + && let ExprKind::Path(QPath::TypeRelative(ty, f)) = f.kind + && let TyKind::Path(QPath::LangItem(LangItem::FormatPlaceholder, _, _)) = ty.kind + && f.ident.name == sym::new + && let [position, _fill, _align, _flags, precision, width] = args + && let ExprKind::Lit(position) = &position.kind + && let LitKind::Int(position, _) = position.node { + ParamPosition { + value: position as usize, + width: parse_count(width), + precision: parse_count(precision), + } + } else { + ParamPosition::default() + } })) } else { None @@ -890,7 +900,7 @@ impl<'tcx> FormatArgsExpn<'tcx> { // ::core::fmt::Arguments::new_v1_formatted(pieces, args, fmt, _unsafe_arg) if let ExprKind::Call(callee, [pieces, args, rest @ ..]) = expr.kind && let ExprKind::Path(QPath::TypeRelative(ty, seg)) = callee.kind - && is_path_diagnostic_item(cx, ty, sym::Arguments) + && let TyKind::Path(QPath::LangItem(LangItem::FormatArguments, _, _)) = ty.kind && matches!(seg.ident.as_str(), "new_v1" | "new_v1_formatted") { let format_string = FormatString::new(cx, pieces)?; From 70c53ecff0683f11b91b17460023d73f47fd8e33 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 5 Dec 2022 17:52:17 +0000 Subject: [PATCH 0719/1222] Feed the `features_query` instead of grabbing it from the session lazily --- clippy_lints/src/attrs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 0710ac0bb0a7..751c262673b1 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -472,7 +472,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_>, name: Symbol, items: &[NestedMe fn check_lint_reason(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem], attr: &'_ Attribute) { // Check for the feature - if !cx.tcx.sess.features_untracked().lint_reasons { + if !cx.tcx.features().lint_reasons { return; } From a609b800843a71123029d9bc5e7161eabec24fa1 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 8 Jan 2023 23:27:22 +0000 Subject: [PATCH 0720/1222] Don't suggest dyn as parameter to add --- tests/ui/crashes/ice-6252.stderr | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index 638e4a548493..efdd56dd47d3 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -17,9 +17,12 @@ error[E0412]: cannot find type `VAL` in this scope --> $DIR/ice-6252.rs:10:63 | LL | impl TypeVal for Multiply where N: TypeVal {} - | - ^^^ not found in this scope - | | - | help: you might be missing a type parameter: `, VAL` + | ^^^ not found in this scope + | +help: you might be missing a type parameter + | +LL | impl TypeVal for Multiply where N: TypeVal {} + | +++++ error[E0046]: not all trait items implemented, missing: `VAL` --> $DIR/ice-6252.rs:10:1 From 213b7b4a0e52460fa782aef9885111820e179058 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 30 Nov 2022 20:41:02 +0000 Subject: [PATCH 0721/1222] Check ADT fields for copy implementations considering regions --- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 1249db5dc479..8c9d4c5cfe66 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -24,7 +24,7 @@ use rustc_span::symbol::kw; use rustc_span::{sym, Span}; use rustc_target::spec::abi::Abi; use rustc_trait_selection::traits; -use rustc_trait_selection::traits::misc::can_type_implement_copy; +use rustc_trait_selection::traits::misc::type_allowed_to_implement_copy; use std::borrow::Cow; declare_clippy_lint! { @@ -200,7 +200,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { let sugg = |diag: &mut Diagnostic| { if let ty::Adt(def, ..) = ty.kind() { if let Some(span) = cx.tcx.hir().span_if_local(def.did()) { - if can_type_implement_copy( + if type_allowed_to_implement_copy( cx.tcx, cx.param_env, ty, From 5c96512ed7e692519ffa8edb0580e0013f08f7fd Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Tue, 10 Jan 2023 14:22:52 -0700 Subject: [PATCH 0722/1222] change usages of impl_trait_ref to bound_impl_trait_ref --- clippy_lints/src/derive.rs | 8 ++++---- clippy_lints/src/fallible_impl_from.rs | 4 ++-- clippy_lints/src/from_over_into.rs | 2 +- clippy_lints/src/implicit_saturating_sub.rs | 4 ++-- clippy_lints/src/methods/implicit_clone.rs | 2 +- clippy_lints/src/methods/suspicious_splitn.rs | 2 +- clippy_lints/src/missing_doc.rs | 2 +- clippy_lints/src/missing_inline.rs | 2 +- clippy_lints/src/non_send_fields_in_send_ty.rs | 4 ++-- clippy_lints/src/only_used_in_recursion.rs | 2 +- clippy_lints/src/use_self.rs | 4 ++-- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index f4b15e0916db..6b2b18fff76e 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -247,11 +247,11 @@ fn check_hash_peq<'tcx>( return; } - let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation"); + let trait_ref = cx.tcx.bound_impl_trait_ref(impl_id).expect("must be a trait implementation"); // Only care about `impl PartialEq for Foo` // For `impl PartialEq for A, input_types is [A, B] - if trait_ref.substs.type_at(1) == ty { + if trait_ref.subst_identity().substs.type_at(1) == ty { span_lint_and_then( cx, DERIVED_HASH_WITH_MANUAL_EQ, @@ -295,11 +295,11 @@ fn check_ord_partial_ord<'tcx>( return; } - let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation"); + let trait_ref = cx.tcx.bound_impl_trait_ref(impl_id).expect("must be a trait implementation"); // Only care about `impl PartialOrd for Foo` // For `impl PartialOrd for A, input_types is [A, B] - if trait_ref.substs.type_at(1) == ty { + if trait_ref.subst_identity().substs.type_at(1) == ty { let mess = if partial_ord_is_automatically_derived { "you are implementing `Ord` explicitly but have derived `PartialOrd`" } else { diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 9a1058470e18..a8085122ccf9 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -55,8 +55,8 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom { // check for `impl From for ..` if_chain! { if let hir::ItemKind::Impl(impl_) = &item.kind; - if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id); - if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.def_id); + if let Some(impl_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()); + if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.skip_binder().def_id); then { lint_impl_body(cx, item.span, impl_.items); } diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index a92f7548ff25..97d414bfa95e 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto { && let Some(into_trait_seg) = hir_trait_ref.path.segments.last() // `impl Into for self_ty` && let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args - && let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id) + && let Some(middle_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).map(ty::EarlyBinder::subst_identity) && cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id) && !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Alias(ty::Opaque, _)) { diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index 29d59c26d92c..37e33529a9a6 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -101,7 +101,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { if name.ident.as_str() == "MIN"; if let Some(const_id) = cx.typeck_results().type_dependent_def_id(cond_num_val.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(const_id); - if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl + if let None = cx.tcx.bound_impl_trait_ref(impl_id); // An inherent impl if cx.tcx.type_of(impl_id).is_integral(); then { print_lint_and_sugg(cx, var_name, expr) @@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { if name.ident.as_str() == "min_value"; if let Some(func_id) = cx.typeck_results().type_dependent_def_id(func.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(func_id); - if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl + if let None = cx.tcx.bound_impl_trait_ref(impl_id); // An inherent impl if cx.tcx.type_of(impl_id).is_integral(); then { print_lint_and_sugg(cx, var_name, expr) diff --git a/clippy_lints/src/methods/implicit_clone.rs b/clippy_lints/src/methods/implicit_clone.rs index 06ecbce4e70e..16a25a98800d 100644 --- a/clippy_lints/src/methods/implicit_clone.rs +++ b/clippy_lints/src/methods/implicit_clone.rs @@ -53,7 +53,7 @@ pub fn is_clone_like(cx: &LateContext<'_>, method_name: &str, method_def_id: hir "to_vec" => cx .tcx .impl_of_method(method_def_id) - .filter(|&impl_did| cx.tcx.type_of(impl_did).is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none()) + .filter(|&impl_did| cx.tcx.type_of(impl_did).is_slice() && cx.tcx.bound_impl_trait_ref(impl_did).is_none()) .is_some(), _ => false, } diff --git a/clippy_lints/src/methods/suspicious_splitn.rs b/clippy_lints/src/methods/suspicious_splitn.rs index 219a9edd6576..dba0663467b7 100644 --- a/clippy_lints/src/methods/suspicious_splitn.rs +++ b/clippy_lints/src/methods/suspicious_splitn.rs @@ -12,7 +12,7 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se if count <= 1; if let Some(call_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(call_id); - if cx.tcx.impl_trait_ref(impl_id).is_none(); + if cx.tcx.bound_impl_trait_ref(impl_id).is_none(); let self_ty = cx.tcx.type_of(impl_id); if self_ty.is_slice() || self_ty.is_str(); then { diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 6fd100762b49..d0c99b352452 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -175,7 +175,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { // If the method is an impl for a trait, don't doc. if let Some(cid) = cx.tcx.associated_item(impl_item.owner_id).impl_container(cx.tcx) { - if cx.tcx.impl_trait_ref(cid).is_some() { + if cx.tcx.bound_impl_trait_ref(cid).is_some() { return; } } else { diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 758ce47cf114..0594fb175458 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { let container_id = assoc_item.container_id(cx.tcx); let trait_def_id = match assoc_item.container { TraitContainer => Some(container_id), - ImplContainer => cx.tcx.impl_trait_ref(container_id).map(|t| t.def_id), + ImplContainer => cx.tcx.bound_impl_trait_ref(container_id).map(|t| t.skip_binder().def_id), }; if let Some(trait_def_id) = trait_def_id { diff --git a/clippy_lints/src/non_send_fields_in_send_ty.rs b/clippy_lints/src/non_send_fields_in_send_ty.rs index 714c0ff227bf..9c112ade948f 100644 --- a/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -89,8 +89,8 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy { if let Some(trait_id) = trait_ref.trait_def_id(); if send_trait == trait_id; if hir_impl.polarity == ImplPolarity::Positive; - if let Some(ty_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id); - if let self_ty = ty_trait_ref.self_ty(); + if let Some(ty_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()); + if let self_ty = ty_trait_ref.subst_identity().self_ty(); if let ty::Adt(adt_def, impl_trait_substs) = self_ty.kind(); then { let mut non_send_fields = Vec::new(); diff --git a/clippy_lints/src/only_used_in_recursion.rs b/clippy_lints/src/only_used_in_recursion.rs index 7722a476d7b4..82b1716a216e 100644 --- a/clippy_lints/src/only_used_in_recursion.rs +++ b/clippy_lints/src/only_used_in_recursion.rs @@ -244,7 +244,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion { })) => { #[allow(trivial_casts)] if let Some(Node::Item(item)) = get_parent_node(cx.tcx, owner_id.into()) - && let Some(trait_ref) = cx.tcx.impl_trait_ref(item.owner_id) + && let Some(trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).map(|t| t.subst_identity()) && let Some(trait_item_id) = cx.tcx.associated_item(owner_id).trait_item_def_id { ( diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 4c755d812a0e..9f31a13aa984 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -133,11 +133,11 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { ref mut types_to_skip, .. }) = self.stack.last_mut(); - if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_id); + if let Some(impl_trait_ref) = cx.tcx.bound_impl_trait_ref(impl_id.to_def_id()); then { // `self_ty` is the semantic self type of `impl for `. This cannot be // `Self`. - let self_ty = impl_trait_ref.self_ty(); + let self_ty = impl_trait_ref.subst_identity().self_ty(); // `trait_method_sig` is the signature of the function, how it is declared in the // trait, not in the impl of the trait. From 08d000503a70b82e8ec1988b4c191f391a19f3c4 Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Tue, 10 Jan 2023 14:57:22 -0700 Subject: [PATCH 0723/1222] change impl_trait_ref query to return EarlyBinder; remove bound_impl_trait_ref query; add EarlyBinder to impl_trait_ref in metadata --- clippy_lints/src/derive.rs | 4 ++-- clippy_lints/src/fallible_impl_from.rs | 2 +- clippy_lints/src/from_over_into.rs | 2 +- clippy_lints/src/implicit_saturating_sub.rs | 4 ++-- clippy_lints/src/methods/implicit_clone.rs | 2 +- clippy_lints/src/methods/suspicious_splitn.rs | 2 +- clippy_lints/src/missing_doc.rs | 2 +- clippy_lints/src/missing_inline.rs | 2 +- clippy_lints/src/non_send_fields_in_send_ty.rs | 2 +- clippy_lints/src/only_used_in_recursion.rs | 2 +- clippy_lints/src/use_self.rs | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 6b2b18fff76e..248d73884106 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -247,7 +247,7 @@ fn check_hash_peq<'tcx>( return; } - let trait_ref = cx.tcx.bound_impl_trait_ref(impl_id).expect("must be a trait implementation"); + let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation"); // Only care about `impl PartialEq for Foo` // For `impl PartialEq for A, input_types is [A, B] @@ -295,7 +295,7 @@ fn check_ord_partial_ord<'tcx>( return; } - let trait_ref = cx.tcx.bound_impl_trait_ref(impl_id).expect("must be a trait implementation"); + let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation"); // Only care about `impl PartialOrd for Foo` // For `impl PartialOrd for A, input_types is [A, B] diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index a8085122ccf9..2ef547526d4f 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom { // check for `impl From for ..` if_chain! { if let hir::ItemKind::Impl(impl_) = &item.kind; - if let Some(impl_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()); + if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id); if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.skip_binder().def_id); then { lint_impl_body(cx, item.span, impl_.items); diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index 97d414bfa95e..bd66ace4500a 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto { && let Some(into_trait_seg) = hir_trait_ref.path.segments.last() // `impl Into for self_ty` && let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args - && let Some(middle_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).map(ty::EarlyBinder::subst_identity) + && let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id).map(ty::EarlyBinder::subst_identity) && cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id) && !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Alias(ty::Opaque, _)) { diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index 37e33529a9a6..29d59c26d92c 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -101,7 +101,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { if name.ident.as_str() == "MIN"; if let Some(const_id) = cx.typeck_results().type_dependent_def_id(cond_num_val.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(const_id); - if let None = cx.tcx.bound_impl_trait_ref(impl_id); // An inherent impl + if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl if cx.tcx.type_of(impl_id).is_integral(); then { print_lint_and_sugg(cx, var_name, expr) @@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { if name.ident.as_str() == "min_value"; if let Some(func_id) = cx.typeck_results().type_dependent_def_id(func.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(func_id); - if let None = cx.tcx.bound_impl_trait_ref(impl_id); // An inherent impl + if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl if cx.tcx.type_of(impl_id).is_integral(); then { print_lint_and_sugg(cx, var_name, expr) diff --git a/clippy_lints/src/methods/implicit_clone.rs b/clippy_lints/src/methods/implicit_clone.rs index 16a25a98800d..06ecbce4e70e 100644 --- a/clippy_lints/src/methods/implicit_clone.rs +++ b/clippy_lints/src/methods/implicit_clone.rs @@ -53,7 +53,7 @@ pub fn is_clone_like(cx: &LateContext<'_>, method_name: &str, method_def_id: hir "to_vec" => cx .tcx .impl_of_method(method_def_id) - .filter(|&impl_did| cx.tcx.type_of(impl_did).is_slice() && cx.tcx.bound_impl_trait_ref(impl_did).is_none()) + .filter(|&impl_did| cx.tcx.type_of(impl_did).is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none()) .is_some(), _ => false, } diff --git a/clippy_lints/src/methods/suspicious_splitn.rs b/clippy_lints/src/methods/suspicious_splitn.rs index dba0663467b7..219a9edd6576 100644 --- a/clippy_lints/src/methods/suspicious_splitn.rs +++ b/clippy_lints/src/methods/suspicious_splitn.rs @@ -12,7 +12,7 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se if count <= 1; if let Some(call_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(call_id); - if cx.tcx.bound_impl_trait_ref(impl_id).is_none(); + if cx.tcx.impl_trait_ref(impl_id).is_none(); let self_ty = cx.tcx.type_of(impl_id); if self_ty.is_slice() || self_ty.is_str(); then { diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index d0c99b352452..6fd100762b49 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -175,7 +175,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { // If the method is an impl for a trait, don't doc. if let Some(cid) = cx.tcx.associated_item(impl_item.owner_id).impl_container(cx.tcx) { - if cx.tcx.bound_impl_trait_ref(cid).is_some() { + if cx.tcx.impl_trait_ref(cid).is_some() { return; } } else { diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 0594fb175458..5a459548153a 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { let container_id = assoc_item.container_id(cx.tcx); let trait_def_id = match assoc_item.container { TraitContainer => Some(container_id), - ImplContainer => cx.tcx.bound_impl_trait_ref(container_id).map(|t| t.skip_binder().def_id), + ImplContainer => cx.tcx.impl_trait_ref(container_id).map(|t| t.skip_binder().def_id), }; if let Some(trait_def_id) = trait_def_id { diff --git a/clippy_lints/src/non_send_fields_in_send_ty.rs b/clippy_lints/src/non_send_fields_in_send_ty.rs index 9c112ade948f..839c3a3815c2 100644 --- a/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy { if let Some(trait_id) = trait_ref.trait_def_id(); if send_trait == trait_id; if hir_impl.polarity == ImplPolarity::Positive; - if let Some(ty_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()); + if let Some(ty_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id); if let self_ty = ty_trait_ref.subst_identity().self_ty(); if let ty::Adt(adt_def, impl_trait_substs) = self_ty.kind(); then { diff --git a/clippy_lints/src/only_used_in_recursion.rs b/clippy_lints/src/only_used_in_recursion.rs index 82b1716a216e..7b1d974f2f87 100644 --- a/clippy_lints/src/only_used_in_recursion.rs +++ b/clippy_lints/src/only_used_in_recursion.rs @@ -244,7 +244,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion { })) => { #[allow(trivial_casts)] if let Some(Node::Item(item)) = get_parent_node(cx.tcx, owner_id.into()) - && let Some(trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).map(|t| t.subst_identity()) + && let Some(trait_ref) = cx.tcx.impl_trait_ref(item.owner_id).map(|t| t.subst_identity()) && let Some(trait_item_id) = cx.tcx.associated_item(owner_id).trait_item_def_id { ( diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 9f31a13aa984..6ae9d9d63538 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -133,7 +133,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { ref mut types_to_skip, .. }) = self.stack.last_mut(); - if let Some(impl_trait_ref) = cx.tcx.bound_impl_trait_ref(impl_id.to_def_id()); + if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_id); then { // `self_ty` is the semantic self type of `impl for `. This cannot be // `Self`. From df1916d975488a1f306bf4b47d9b4fce46b0b2aa Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Mon, 16 Jan 2023 14:50:11 -0700 Subject: [PATCH 0724/1222] change usages of item_bounds query to bound_item_bounds --- clippy_utils/src/ty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index c8d56a3be5cf..9525c78312b4 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -648,7 +648,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))), ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { - sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id)) + sig_from_bounds(cx, ty, cx.tcx.bound_item_bounds(def_id).subst_identity(), cx.tcx.opt_parent(def_id)) }, ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), ty::Dynamic(bounds, _, _) => { From 3bc7e8a0a8e7f987a97b022fecb2247940c1dfe2 Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Mon, 16 Jan 2023 15:07:23 -0700 Subject: [PATCH 0725/1222] change item_bounds query to return EarlyBinder; remove bound_item_bounds query --- clippy_utils/src/ty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 9525c78312b4..1d2a469ca6ca 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -648,7 +648,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))), ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { - sig_from_bounds(cx, ty, cx.tcx.bound_item_bounds(def_id).subst_identity(), cx.tcx.opt_parent(def_id)) + sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id).subst_identity(), cx.tcx.opt_parent(def_id)) }, ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), ty::Dynamic(bounds, _, _) => { From 3411c73b0d13a8c6cfbdeb899ec9a83fe3892e00 Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Tue, 17 Jan 2023 08:54:07 -0700 Subject: [PATCH 0726/1222] fix missing subst in clippy utils --- clippy_utils/src/ty.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 1d2a469ca6ca..99fba4fe741a 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -647,8 +647,8 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))), - ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { - sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id).subst_identity(), cx.tcx.opt_parent(def_id)) + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => { + sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id).subst(cx.tcx, substs), cx.tcx.opt_parent(def_id)) }, ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), ty::Dynamic(bounds, _, _) => { From fdef798b41bbc51bd746895d22734c89f7a05fd8 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 2 Dec 2022 16:27:25 +0100 Subject: [PATCH 0727/1222] Use UnordSet instead of FxHashSet in define_id_collections!(). --- clippy_lints/src/len_zero.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 9eba46756299..3c70c9cf19a5 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -219,7 +219,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items let is_empty = sym!(is_empty); let is_empty_method_found = current_and_super_traits - .iter() + .items() .flat_map(|&i| cx.tcx.associated_items(i).filter_by_name_unhygienic(is_empty)) .any(|i| { i.kind == ty::AssocKind::Fn From 63fbc38e90e5b5b369fa05893a53620edbfea98a Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 17 Jan 2023 12:05:01 +0100 Subject: [PATCH 0728/1222] Use UnordMap instead of FxHashMap in define_id_collections!(). --- clippy_lints/src/inherent_impl.rs | 26 +++++++++---------- .../src/loops/while_immutable_condition.rs | 2 +- clippy_lints/src/missing_trait_methods.rs | 26 ++++++++++--------- clippy_lints/src/pass_by_ref_or_value.rs | 4 +-- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index c5abcc462545..81b37ce5dfc2 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -52,21 +52,19 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { // List of spans to lint. (lint_span, first_span) let mut lint_spans = Vec::new(); - for (_, impl_ids) in cx + let inherent_impls = cx .tcx - .crate_inherent_impls(()) - .inherent_impls - .iter() - .filter(|(&id, impls)| { - impls.len() > 1 - // Check for `#[allow]` on the type definition - && !is_lint_allowed( - cx, - MULTIPLE_INHERENT_IMPL, - cx.tcx.hir().local_def_id_to_hir_id(id), - ) - }) - { + .with_stable_hashing_context(|hcx| cx.tcx.crate_inherent_impls(()).inherent_impls.to_sorted(&hcx)); + + for (_, impl_ids) in inherent_impls.into_iter().filter(|(&id, impls)| { + impls.len() > 1 + // Check for `#[allow]` on the type definition + && !is_lint_allowed( + cx, + MULTIPLE_INHERENT_IMPL, + cx.tcx.hir().local_def_id_to_hir_id(id), + ) + }) { for impl_id in impl_ids.iter().map(|id| id.expect_local()) { match type_map.entry(cx.tcx.type_of(impl_id)) { Entry::Vacant(e) => { diff --git a/clippy_lints/src/loops/while_immutable_condition.rs b/clippy_lints/src/loops/while_immutable_condition.rs index a63422d2a36a..d1a1f773f87b 100644 --- a/clippy_lints/src/loops/while_immutable_condition.rs +++ b/clippy_lints/src/loops/while_immutable_condition.rs @@ -35,7 +35,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, expr: &' } else { return; }; - let mutable_static_in_cond = var_visitor.def_ids.iter().any(|(_, v)| *v); + let mutable_static_in_cond = var_visitor.def_ids.items().any(|(_, v)| *v); let mut has_break_or_return_visitor = HasBreakOrReturnVisitor { has_break_or_return: false, diff --git a/clippy_lints/src/missing_trait_methods.rs b/clippy_lints/src/missing_trait_methods.rs index 68af8a672f6a..1c61c6e551c3 100644 --- a/clippy_lints/src/missing_trait_methods.rs +++ b/clippy_lints/src/missing_trait_methods.rs @@ -80,19 +80,21 @@ impl<'tcx> LateLintPass<'tcx> for MissingTraitMethods { } } - for assoc in provided.values() { - let source_map = cx.tcx.sess.source_map(); - let definition_span = source_map.guess_head_span(cx.tcx.def_span(assoc.def_id)); + cx.tcx.with_stable_hashing_context(|hcx| { + for assoc in provided.values_sorted(&hcx) { + let source_map = cx.tcx.sess.source_map(); + let definition_span = source_map.guess_head_span(cx.tcx.def_span(assoc.def_id)); - span_lint_and_help( - cx, - MISSING_TRAIT_METHODS, - source_map.guess_head_span(item.span), - &format!("missing trait method provided by default: `{}`", assoc.name), - Some(definition_span), - "implement the method", - ); - } + span_lint_and_help( + cx, + MISSING_TRAIT_METHODS, + source_map.guess_head_span(item.span), + &format!("missing trait method provided by default: `{}`", assoc.name), + Some(definition_span), + "implement the method", + ); + } + }) } } } diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 870a1c7d88d5..2d21aaa4f7fd 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -190,10 +190,10 @@ impl<'tcx> PassByRefOrValue { // Don't lint if an unsafe pointer is created. // TODO: Limit the check only to unsafe pointers to the argument (or part of the argument) // which escape the current function. - if typeck.node_types().iter().any(|(_, &ty)| ty.is_unsafe_ptr()) + if typeck.node_types().items().any(|(_, &ty)| ty.is_unsafe_ptr()) || typeck .adjustments() - .iter() + .items() .flat_map(|(_, a)| a) .any(|a| matches!(a.kind, Adjust::Pointer(PointerCast::UnsafeFnPointer))) { From 3be186457f8e6bd7f13268d5298e2c88facdc3a5 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 18 Jan 2023 10:47:31 +0100 Subject: [PATCH 0729/1222] Allow for more efficient sorting when exporting Unord collections. --- clippy_lints/src/inherent_impl.rs | 2 +- clippy_lints/src/missing_trait_methods.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index 81b37ce5dfc2..e9b2e31a769a 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { let inherent_impls = cx .tcx - .with_stable_hashing_context(|hcx| cx.tcx.crate_inherent_impls(()).inherent_impls.to_sorted(&hcx)); + .with_stable_hashing_context(|hcx| cx.tcx.crate_inherent_impls(()).inherent_impls.to_sorted(&hcx, true)); for (_, impl_ids) in inherent_impls.into_iter().filter(|(&id, impls)| { impls.len() > 1 diff --git a/clippy_lints/src/missing_trait_methods.rs b/clippy_lints/src/missing_trait_methods.rs index 1c61c6e551c3..3371b4cce32c 100644 --- a/clippy_lints/src/missing_trait_methods.rs +++ b/clippy_lints/src/missing_trait_methods.rs @@ -81,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingTraitMethods { } cx.tcx.with_stable_hashing_context(|hcx| { - for assoc in provided.values_sorted(&hcx) { + for assoc in provided.values_sorted(&hcx, true) { let source_map = cx.tcx.sess.source_map(); let definition_span = source_map.guess_head_span(cx.tcx.def_span(assoc.def_id)); From af520e69409bf6857ff32df32673b6aeea79ea00 Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Fri, 13 Jan 2023 00:04:28 +0000 Subject: [PATCH 0730/1222] Move `unchecked_duration_subtraction` to pedantic --- clippy_lints/src/instant_subtraction.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/instant_subtraction.rs b/clippy_lints/src/instant_subtraction.rs index dd1b23e7d9d2..9f6e89405713 100644 --- a/clippy_lints/src/instant_subtraction.rs +++ b/clippy_lints/src/instant_subtraction.rs @@ -61,7 +61,7 @@ declare_clippy_lint! { /// [`Instant::now()`]: std::time::Instant::now; #[clippy::version = "1.65.0"] pub UNCHECKED_DURATION_SUBTRACTION, - suspicious, + pedantic, "finds unchecked subtraction of a 'Duration' from an 'Instant'" } From 37eceeaef6b3ec76867bca7669c976f7f977659f Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Thu, 19 Jan 2023 21:45:38 +0100 Subject: [PATCH 0731/1222] fix overlapping spans for `clippy::uninlined_format_args` --- clippy_lints/src/format_args.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clippy_lints/src/format_args.rs b/clippy_lints/src/format_args.rs index 043112bbc959..bb7fa3087b74 100644 --- a/clippy_lints/src/format_args.rs +++ b/clippy_lints/src/format_args.rs @@ -311,6 +311,10 @@ fn check_uninlined_args( // in those cases, make the code suggestion hidden let multiline_fix = fixes.iter().any(|(span, _)| cx.sess().source_map().is_multiline(*span)); + // Suggest removing each argument only once, for example in `format!("{0} {0}", arg)`. + fixes.sort_unstable_by_key(|(span, _)| *span); + fixes.dedup_by_key(|(span, _)| *span); + span_lint_and_then( cx, UNINLINED_FORMAT_ARGS, From ff540f61e061ef9309814f79a79a99824185a0d5 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Sun, 15 Jan 2023 12:58:46 +0100 Subject: [PATCH 0732/1222] fix: use LocalDefId instead of HirId in trait res use LocalDefId instead of HirId in trait resolution to simplify the obligation clause resolution Signed-off-by: Vincenzo Palazzo --- clippy_lints/src/future_not_send.rs | 3 ++- clippy_lints/src/methods/unnecessary_to_owned.rs | 2 +- clippy_lints/src/transmute/utils.rs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 989f83cf80d5..2a79b18b8299 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -78,7 +78,8 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap(); let span = decl.output.span(); let infcx = cx.tcx.infer_ctxt().build(); - let cause = traits::ObligationCause::misc(span, hir_id); + let def_id = cx.tcx.hir().local_def_id(hir_id); + let cause = traits::ObligationCause::misc(span, def_id); let send_errors = traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait); if !send_errors.is_empty() { span_lint_and_then( diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 9263f0519724..b812e81cb107 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -371,7 +371,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< && let output_ty = return_ty(cx, item.hir_id()) && let local_def_id = cx.tcx.hir().local_def_id(item.hir_id()) && Inherited::build(cx.tcx, local_def_id).enter(|inherited| { - let fn_ctxt = FnCtxt::new(inherited, cx.param_env, item.hir_id()); + let fn_ctxt = FnCtxt::new(inherited, cx.param_env, local_def_id); fn_ctxt.can_coerce(ty, output_ty) }) { if has_lifetime(output_ty) && has_lifetime(ty) { diff --git a/clippy_lints/src/transmute/utils.rs b/clippy_lints/src/transmute/utils.rs index 49d863ec03f1..b59d52dfc4d3 100644 --- a/clippy_lints/src/transmute/utils.rs +++ b/clippy_lints/src/transmute/utils.rs @@ -46,7 +46,7 @@ fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx> let local_def_id = hir_id.owner.def_id; Inherited::build(cx.tcx, local_def_id).enter(|inherited| { - let fn_ctxt = FnCtxt::new(inherited, cx.param_env, hir_id); + let fn_ctxt = FnCtxt::new(inherited, cx.param_env, local_def_id); // If we already have errors, we can't be sure we can pointer cast. assert!( From 12f8fce377848b6ade944434d33caaf838445f2d Mon Sep 17 00:00:00 2001 From: Bryan Garza <1396101+bryangarza@users.noreply.github.com> Date: Thu, 29 Dec 2022 23:50:53 +0000 Subject: [PATCH 0733/1222] Update Clippy for ConstEvalCounter --- clippy_utils/src/qualify_min_const_fn.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index e5d7da682813..d127b896deac 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -240,6 +240,7 @@ fn check_statement<'tcx>( | StatementKind::Retag { .. } | StatementKind::AscribeUserType(..) | StatementKind::Coverage(..) + | StatementKind::ConstEvalCounter | StatementKind::Nop => Ok(()), } } From 323b88f514cb2b0e57384437bfa13f63d5783edf Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Wed, 18 Jan 2023 15:43:20 -0700 Subject: [PATCH 0734/1222] replace usages of fn_sig query with bound_fn_sig --- clippy_lints/src/casts/as_ptr_cast_mut.rs | 2 +- clippy_lints/src/default_numeric_fallback.rs | 4 ++-- clippy_lints/src/dereference.rs | 14 +++++++------- .../src/functions/not_unsafe_ptr_arg_deref.rs | 2 +- clippy_lints/src/functions/result.rs | 2 +- clippy_lints/src/inherent_to_string.rs | 2 +- clippy_lints/src/iter_not_returning_iterator.rs | 2 +- clippy_lints/src/len_zero.rs | 10 +++++----- clippy_lints/src/loops/needless_range_loop.rs | 2 +- clippy_lints/src/map_unit_fn.rs | 2 +- clippy_lints/src/methods/expect_fun_call.rs | 4 ++-- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/methods/needless_collect.rs | 4 ++-- clippy_lints/src/methods/unnecessary_to_owned.rs | 4 ++-- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/ptr.rs | 6 +++--- clippy_lints/src/returns.rs | 3 ++- clippy_lints/src/unit_return_expecting_ord.rs | 2 +- clippy_lints/src/unit_types/let_unit_value.rs | 2 +- clippy_lints/src/use_self.rs | 2 +- clippy_utils/src/eager_or_lazy.rs | 2 +- clippy_utils/src/lib.rs | 6 +++--- clippy_utils/src/qualify_min_const_fn.rs | 2 +- clippy_utils/src/sugg.rs | 2 +- clippy_utils/src/ty.rs | 2 +- clippy_utils/src/visitors.rs | 4 ++-- 28 files changed, 48 insertions(+), 47 deletions(-) diff --git a/clippy_lints/src/casts/as_ptr_cast_mut.rs b/clippy_lints/src/casts/as_ptr_cast_mut.rs index 9409f4844f54..2a0e0857c561 100644 --- a/clippy_lints/src/casts/as_ptr_cast_mut.rs +++ b/clippy_lints/src/casts/as_ptr_cast_mut.rs @@ -17,7 +17,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, && let ExprKind::MethodCall(method_name, receiver, [], _) = cast_expr.peel_blocks().kind && method_name.ident.name == rustc_span::sym::as_ptr && let Some(as_ptr_did) = cx.typeck_results().type_dependent_def_id(cast_expr.peel_blocks().hir_id) - && let as_ptr_sig = cx.tcx.fn_sig(as_ptr_did) + && let as_ptr_sig = cx.tcx.bound_fn_sig(as_ptr_did).subst_identity() && let Some(first_param_ty) = as_ptr_sig.skip_binder().inputs().iter().next() && let ty::Ref(_, _, Mutability::Not) = first_param_ty.kind() && let Some(recv) = snippet_opt(cx, receiver.span) diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index 03460689e19a..9c5a9f583743 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -141,7 +141,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { ExprKind::MethodCall(_, receiver, args, _) => { if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) { - let fn_sig = self.cx.tcx.fn_sig(def_id).skip_binder(); + let fn_sig = self.cx.tcx.bound_fn_sig(def_id).subst_identity().skip_binder(); for (expr, bound) in iter::zip(std::iter::once(*receiver).chain(args.iter()), fn_sig.inputs()) { self.ty_bounds.push((*bound).into()); self.visit_expr(expr); @@ -215,7 +215,7 @@ fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option Some(cx.tcx.fn_sig(*def_id)), + ty::FnDef(def_id, _) => Some(cx.tcx.bound_fn_sig(*def_id).subst_identity()), ty::FnPtr(fn_sig) => Some(*fn_sig), _ => None, } diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 05f2b92c0370..25620f45b8a9 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -759,7 +759,7 @@ fn walk_parents<'tcx>( }) if span.ctxt() == ctxt => { let output = cx .tcx - .erase_late_bound_regions(cx.tcx.fn_sig(owner_id.to_def_id()).output()); + .erase_late_bound_regions(cx.tcx.bound_fn_sig(owner_id.to_def_id()).subst_identity().output()); Some(ty_auto_deref_stability(cx, output, precedence).position_for_result(cx)) }, @@ -791,7 +791,7 @@ fn walk_parents<'tcx>( } else { let output = cx .tcx - .erase_late_bound_regions(cx.tcx.fn_sig(cx.tcx.hir().local_def_id(owner_id)).output()); + .erase_late_bound_regions(cx.tcx.bound_fn_sig(cx.tcx.hir().local_def_id(owner_id).into()).subst_identity().output()); ty_auto_deref_stability(cx, output, precedence).position_for_result(cx) }, ) @@ -858,7 +858,7 @@ fn walk_parents<'tcx>( && let subs = cx .typeck_results() .node_substs_opt(parent.hir_id).map(|subs| &subs[1..]).unwrap_or_default() - && let impl_ty = if cx.tcx.fn_sig(id).skip_binder().inputs()[0].is_ref() { + && let impl_ty = if cx.tcx.bound_fn_sig(id).subst_identity().skip_binder().inputs()[0].is_ref() { // Trait methods taking `&self` sub_ty } else { @@ -879,7 +879,7 @@ fn walk_parents<'tcx>( return Some(Position::MethodReceiver); } args.iter().position(|arg| arg.hir_id == child_id).map(|i| { - let ty = cx.tcx.fn_sig(id).skip_binder().inputs()[i + 1]; + let ty = cx.tcx.bound_fn_sig(id).subst_identity().skip_binder().inputs()[i + 1]; // `e.hir_id == child_id` for https://github.com/rust-lang/rust-clippy/issues/9739 // `method.args.is_none()` for https://github.com/rust-lang/rust-clippy/issues/9782 if e.hir_id == child_id && method.args.is_none() && let ty::Param(param_ty) = ty.kind() { @@ -896,7 +896,7 @@ fn walk_parents<'tcx>( } else { ty_auto_deref_stability( cx, - cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).input(i + 1)), + cx.tcx.erase_late_bound_regions(cx.tcx.bound_fn_sig(id).subst_identity().input(i + 1)), precedence, ) .position_for_arg() @@ -1093,7 +1093,7 @@ fn needless_borrow_impl_arg_position<'tcx>( let sized_trait_def_id = cx.tcx.lang_items().sized_trait(); let Some(callee_def_id) = fn_def_id(cx, parent) else { return Position::Other(precedence) }; - let fn_sig = cx.tcx.fn_sig(callee_def_id).skip_binder(); + let fn_sig = cx.tcx.bound_fn_sig(callee_def_id).subst_identity().skip_binder(); let substs_with_expr_ty = cx .typeck_results() .node_substs(if let ExprKind::Call(callee, _) = parent.kind { @@ -1221,7 +1221,7 @@ fn has_ref_mut_self_method(cx: &LateContext<'_>, trait_def_id: DefId) -> bool { .in_definition_order() .any(|assoc_item| { if assoc_item.fn_has_self_parameter { - let self_ty = cx.tcx.fn_sig(assoc_item.def_id).skip_binder().inputs()[0]; + let self_ty = cx.tcx.bound_fn_sig(assoc_item.def_id).subst_identity().skip_binder().inputs()[0]; matches!(self_ty.kind(), ty::Ref(_, _, Mutability::Mut)) } else { false diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index 2c0bf551fd7e..4f0371c027c2 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -58,7 +58,7 @@ fn check_raw_ptr<'tcx>( }, hir::ExprKind::MethodCall(_, recv, args, _) => { let def_id = typeck.type_dependent_def_id(e.hir_id).unwrap(); - if cx.tcx.fn_sig(def_id).skip_binder().unsafety == hir::Unsafety::Unsafe { + if cx.tcx.bound_fn_sig(def_id).skip_binder().skip_binder().unsafety == hir::Unsafety::Unsafe { check_arg(cx, &raw_ptrs, recv); for arg in args { check_arg(cx, &raw_ptrs, arg); diff --git a/clippy_lints/src/functions/result.rs b/clippy_lints/src/functions/result.rs index 23da145d0382..21de62581f1c 100644 --- a/clippy_lints/src/functions/result.rs +++ b/clippy_lints/src/functions/result.rs @@ -21,7 +21,7 @@ fn result_err_ty<'tcx>( ) -> Option<(&'tcx hir::Ty<'tcx>, Ty<'tcx>)> { if !in_external_macro(cx.sess(), item_span) && let hir::FnRetTy::Return(hir_ty) = decl.output - && let ty = cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).output()) + && let ty = cx.tcx.erase_late_bound_regions(cx.tcx.bound_fn_sig(id.into()).subst_identity().output()) && is_type_diagnostic_item(cx, ty, sym::Result) && let ty::Adt(_, substs) = ty.kind() { diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index aaecc4fa8f25..d971684a3aa9 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -124,7 +124,7 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) { .expect("Failed to get trait ID of `Display`!"); // Get the real type of 'self' - let self_type = cx.tcx.fn_sig(item.owner_id).input(0); + let self_type = cx.tcx.bound_fn_sig(item.owner_id.to_def_id()).skip_binder().input(0); let self_type = self_type.skip_binder().peel_refs(); // Emit either a warning or an error diff --git a/clippy_lints/src/iter_not_returning_iterator.rs b/clippy_lints/src/iter_not_returning_iterator.rs index e76de77f195d..131af2fd9c38 100644 --- a/clippy_lints/src/iter_not_returning_iterator.rs +++ b/clippy_lints/src/iter_not_returning_iterator.rs @@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator { fn check_sig(cx: &LateContext<'_>, name: &str, sig: &FnSig<'_>, fn_id: LocalDefId) { if sig.decl.implicit_self.has_implicit_self() { - let ret_ty = cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(fn_id).output()); + let ret_ty = cx.tcx.erase_late_bound_regions(cx.tcx.bound_fn_sig(fn_id.into()).subst_identity().output()); let ret_ty = cx .tcx .try_normalize_erasing_regions(cx.param_env, ret_ty) diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 3c70c9cf19a5..121d6b9f0fe7 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero { if let Some(local_id) = ty_id.as_local(); let ty_hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_id); if !is_lint_allowed(cx, LEN_WITHOUT_IS_EMPTY, ty_hir_id); - if let Some(output) = parse_len_output(cx, cx.tcx.fn_sig(item.owner_id).skip_binder()); + if let Some(output) = parse_len_output(cx, cx.tcx.bound_fn_sig(item.owner_id.to_def_id()).subst_identity().skip_binder()); then { let (name, kind) = match cx.tcx.hir().find(ty_hir_id) { Some(Node::ForeignItem(x)) => (x.ident.name, "extern type"), @@ -196,7 +196,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items fn is_named_self(cx: &LateContext<'_>, item: &TraitItemRef, name: Symbol) -> bool { item.ident.name == name && if let AssocItemKind::Fn { has_self } = item.kind { - has_self && { cx.tcx.fn_sig(item.id.owner_id).inputs().skip_binder().len() == 1 } + has_self && { cx.tcx.bound_fn_sig(item.id.owner_id.to_def_id()).skip_binder().inputs().skip_binder().len() == 1 } } else { false } @@ -224,7 +224,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items .any(|i| { i.kind == ty::AssocKind::Fn && i.fn_has_self_parameter - && cx.tcx.fn_sig(i.def_id).inputs().skip_binder().len() == 1 + && cx.tcx.bound_fn_sig(i.def_id).skip_binder().inputs().skip_binder().len() == 1 }); if !is_empty_method_found { @@ -342,7 +342,7 @@ fn check_for_is_empty<'tcx>( ), Some(is_empty) if !(is_empty.fn_has_self_parameter - && check_is_empty_sig(cx.tcx.fn_sig(is_empty.def_id).skip_binder(), self_kind, output)) => + && check_is_empty_sig(cx.tcx.bound_fn_sig(is_empty.def_id).subst_identity().skip_binder(), self_kind, output)) => { ( format!( @@ -473,7 +473,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { /// Gets an `AssocItem` and return true if it matches `is_empty(self)`. fn is_is_empty(cx: &LateContext<'_>, item: &ty::AssocItem) -> bool { if item.kind == ty::AssocKind::Fn { - let sig = cx.tcx.fn_sig(item.def_id); + let sig = cx.tcx.bound_fn_sig(item.def_id).skip_binder(); let ty = sig.skip_binder(); ty.inputs().len() == 1 } else { diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 3bca93d80aa7..3e025bc0e716 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -370,7 +370,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { ExprKind::MethodCall(_, receiver, args, _) => { let def_id = self.cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap(); for (ty, expr) in iter::zip( - self.cx.tcx.fn_sig(def_id).inputs().skip_binder(), + self.cx.tcx.bound_fn_sig(def_id).subst_identity().inputs().skip_binder(), std::iter::once(receiver).chain(args.iter()), ) { self.prefer_mutable = false; diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 59195d1ae4e0..a179dd091e42 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -104,7 +104,7 @@ fn is_unit_function(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { let ty = cx.typeck_results().expr_ty(expr); if let ty::FnDef(id, _) = *ty.kind() { - if let Some(fn_type) = cx.tcx.fn_sig(id).no_bound_vars() { + if let Some(fn_type) = cx.tcx.bound_fn_sig(id).subst_identity().no_bound_vars() { return is_unit_type(fn_type.output()); } } diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index a9189b31c571..3f670ebc9178 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -70,7 +70,7 @@ pub(super) fn check<'tcx>( if let hir::ExprKind::Path(ref p) = fun.kind { match cx.qpath_res(p, fun.hir_id) { hir::def::Res::Def(hir::def::DefKind::Fn | hir::def::DefKind::AssocFn, def_id) => matches!( - cx.tcx.fn_sig(def_id).output().skip_binder().kind(), + cx.tcx.bound_fn_sig(def_id).subst_identity().output().skip_binder().kind(), ty::Ref(re, ..) if re.is_static(), ), _ => false, @@ -84,7 +84,7 @@ pub(super) fn check<'tcx>( .type_dependent_def_id(arg.hir_id) .map_or(false, |method_id| { matches!( - cx.tcx.fn_sig(method_id).output().skip_binder().kind(), + cx.tcx.bound_fn_sig(method_id).subst_identity().output().skip_binder().kind(), ty::Ref(re, ..) if re.is_static() ) }) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 77be61b47934..6002ef1340be 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3352,7 +3352,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { let implements_trait = matches!(item.kind, hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })); if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind { - let method_sig = cx.tcx.fn_sig(impl_item.owner_id); + let method_sig = cx.tcx.bound_fn_sig(impl_item.owner_id.to_def_id()).subst_identity(); let method_sig = cx.tcx.erase_late_bound_regions(method_sig); let first_arg_ty_opt = method_sig.inputs().iter().next().copied(); // if this impl block implements a trait, lint in trait definition instead diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index f4d3ef3b7425..1a1715d03a7c 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -137,7 +137,7 @@ pub(super) fn check<'tcx>( /// Checks if the given method call matches the expected signature of `([&[mut]] self) -> bool` fn is_is_empty_sig(cx: &LateContext<'_>, call_id: HirId) -> bool { cx.typeck_results().type_dependent_def_id(call_id).map_or(false, |id| { - let sig = cx.tcx.fn_sig(id).skip_binder(); + let sig = cx.tcx.bound_fn_sig(id).subst_identity().skip_binder(); sig.inputs().len() == 1 && sig.output().is_bool() }) } @@ -165,7 +165,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty: fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) -> bool { let typeck = cx.typeck_results(); if let Some(id) = typeck.type_dependent_def_id(call_id) - && let sig = cx.tcx.fn_sig(id) + && let sig = cx.tcx.bound_fn_sig(id).subst_identity() && sig.skip_binder().output().is_bool() && let [_, search_ty] = *sig.skip_binder().inputs() && let ty::Ref(_, search_ty, Mutability::Not) = *cx.tcx.erase_late_bound_regions(sig.rebind(search_ty)).kind() diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index b812e81cb107..8036e787aaec 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -246,7 +246,7 @@ fn check_other_call_arg<'tcx>( if_chain! { if let Some((maybe_call, maybe_arg)) = skip_addr_of_ancestors(cx, expr); if let Some((callee_def_id, _, recv, call_args)) = get_callee_substs_and_args(cx, maybe_call); - let fn_sig = cx.tcx.fn_sig(callee_def_id).skip_binder(); + let fn_sig = cx.tcx.bound_fn_sig(callee_def_id).subst_identity().skip_binder(); if let Some(i) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == maybe_arg.hir_id); if let Some(input) = fn_sig.inputs().get(i); let (input, n_refs) = peel_mid_ty_refs(*input); @@ -386,7 +386,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< Node::Expr(parent_expr) => { if let Some((callee_def_id, call_substs, recv, call_args)) = get_callee_substs_and_args(cx, parent_expr) { - let fn_sig = cx.tcx.fn_sig(callee_def_id).skip_binder(); + let fn_sig = cx.tcx.bound_fn_sig(callee_def_id).subst_identity().skip_binder(); if let Some(arg_index) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == expr.hir_id) && let Some(param_ty) = fn_sig.inputs().get(arg_index) && let ty::Param(ParamTy { index: param_index , ..}) = param_ty.kind() diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index a651020ca656..a2868883673f 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -138,7 +138,7 @@ impl MutableKeyType { fn check_sig(&self, cx: &LateContext<'_>, item_hir_id: hir::HirId, decl: &hir::FnDecl<'_>) { let fn_def_id = cx.tcx.hir().local_def_id(item_hir_id); - let fn_sig = cx.tcx.fn_sig(fn_def_id); + let fn_sig = cx.tcx.bound_fn_sig(fn_def_id.into()).subst_identity(); for (hir_ty, ty) in iter::zip(decl.inputs, fn_sig.inputs().skip_binder()) { self.check_ty_(cx, hir_ty.span, *ty); } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 8c9d4c5cfe66..e3d25603a715 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { ctx }; - let fn_sig = cx.tcx.fn_sig(fn_def_id); + let fn_sig = cx.tcx.bound_fn_sig(fn_def_id.into()).subst_identity(); let fn_sig = cx.tcx.erase_late_bound_regions(fn_sig); for (idx, ((input, &ty), arg)) in decl.inputs.iter().zip(fn_sig.inputs()).zip(body.params).enumerate() { diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 2d21aaa4f7fd..5512109c6cbb 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -143,7 +143,7 @@ impl<'tcx> PassByRefOrValue { return; } - let fn_sig = cx.tcx.fn_sig(def_id); + let fn_sig = cx.tcx.bound_fn_sig(def_id.into()).subst_identity(); let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir().body(id)); // Gather all the lifetimes found in the output type which may affect whether diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 262953042581..0a2d35015f57 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -164,7 +164,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { check_mut_from_ref(cx, sig, None); for arg in check_fn_args( cx, - cx.tcx.fn_sig(item.owner_id).skip_binder().inputs(), + cx.tcx.bound_fn_sig(item.owner_id.to_def_id()).subst_identity().skip_binder().inputs(), sig.decl.inputs, &[], ) @@ -217,7 +217,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { check_mut_from_ref(cx, sig, Some(body)); let decl = sig.decl; - let sig = cx.tcx.fn_sig(item_id).skip_binder(); + let sig = cx.tcx.bound_fn_sig(item_id.to_def_id()).subst_identity().skip_binder(); let lint_args: Vec<_> = check_fn_args(cx, sig.inputs(), decl.inputs, body.params) .filter(|arg| !is_trait_item || arg.mutability() == Mutability::Not) .collect(); @@ -624,7 +624,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: return; }; - match *self.cx.tcx.fn_sig(id).skip_binder().inputs()[i].peel_refs().kind() { + match *self.cx.tcx.bound_fn_sig(id).subst_identity().skip_binder().inputs()[i].peel_refs().kind() { ty::Dynamic(preds, _, _) if !matches_preds(self.cx, args.deref_ty.ty(self.cx), preds) => { set_skip_flag(); }, diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index bbbd9e4989e9..f3c503306043 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -287,7 +287,8 @@ fn last_statement_borrows<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) if let Some(def_id) = fn_def_id(cx, e) && cx .tcx - .fn_sig(def_id) + .bound_fn_sig(def_id) + .subst_identity() .skip_binder() .output() .walk() diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index a138a4baa9b3..5df26d8b0a38 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -76,7 +76,7 @@ fn get_projection_pred<'tcx>( fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Vec<(usize, String)> { let mut args_to_check = Vec::new(); if let Some(def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) { - let fn_sig = cx.tcx.fn_sig(def_id); + let fn_sig = cx.tcx.bound_fn_sig(def_id).subst_identity(); let generics = cx.tcx.predicates_of(def_id); let fn_mut_preds = get_trait_predicates_for_trait_id(cx, generics, cx.tcx.lang_items().fn_mut_trait()); let ord_preds = get_trait_predicates_for_trait_id(cx, generics, cx.tcx.get_diagnostic_item(sym::Ord)); diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index ce9ebad8c89a..681e59a1575d 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -156,7 +156,7 @@ fn needs_inferred_result_ty( }, _ => return false, }; - let sig = cx.tcx.fn_sig(id).skip_binder(); + let sig = cx.tcx.bound_fn_sig(id).subst_identity().skip_binder(); if let ty::Param(output_ty) = *sig.output().kind() { let args: Vec<&Expr<'_>> = if let Some(receiver) = receiver { std::iter::once(receiver).chain(args.iter()).collect() diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 6ae9d9d63538..09324fd92943 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -146,7 +146,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { .associated_item(impl_item.owner_id) .trait_item_def_id .expect("impl method matches a trait method"); - let trait_method_sig = cx.tcx.fn_sig(trait_method); + let trait_method_sig = cx.tcx.bound_fn_sig(trait_method).subst_identity(); let trait_method_sig = cx.tcx.erase_late_bound_regions(trait_method_sig); // `impl_inputs_outputs` is an iterator over the types (`hir::Ty`) declared in the diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 96711936968b..38588e32dbfe 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -79,7 +79,7 @@ fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg: && subs.types().all(|x| matches!(x.peel_refs().kind(), ty::Param(_))) { // Limit the function to either `(self) -> bool` or `(&self) -> bool` - match &**cx.tcx.fn_sig(fn_id).skip_binder().inputs_and_output { + match &**cx.tcx.bound_fn_sig(fn_id).subst_identity().skip_binder().inputs_and_output { [arg, res] if !arg.is_mutable_ptr() && arg.peel_refs() == ty && res.is_bool() => NoChange, _ => Lazy, } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 7a4a9036dd36..ccc5f3503d2f 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1379,7 +1379,7 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>( .chain(args.iter()) .position(|arg| arg.hir_id == id)?; let id = cx.typeck_results().type_dependent_def_id(e.hir_id)?; - let ty = cx.tcx.fn_sig(id).skip_binder().inputs()[i]; + let ty = cx.tcx.bound_fn_sig(id).subst_identity().skip_binder().inputs()[i]; ty_is_fn_once_param(cx.tcx, ty, cx.tcx.param_env(id).caller_bounds()).then_some(()) }, _ => None, @@ -1580,14 +1580,14 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option { /// Convenience function to get the return type of a function. pub fn return_ty<'tcx>(cx: &LateContext<'tcx>, fn_item: hir::HirId) -> Ty<'tcx> { let fn_def_id = cx.tcx.hir().local_def_id(fn_item); - let ret_ty = cx.tcx.fn_sig(fn_def_id).output(); + let ret_ty = cx.tcx.bound_fn_sig(fn_def_id.into()).subst_identity().output(); cx.tcx.erase_late_bound_regions(ret_ty) } /// Convenience function to get the nth argument type of a function. pub fn nth_arg<'tcx>(cx: &LateContext<'tcx>, fn_item: hir::HirId, nth: usize) -> Ty<'tcx> { let fn_def_id = cx.tcx.hir().local_def_id(fn_item); - let arg = cx.tcx.fn_sig(fn_def_id).input(nth); + let arg = cx.tcx.bound_fn_sig(fn_def_id.into()).subst_identity().input(nth); cx.tcx.erase_late_bound_regions(arg) } diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index e5d7da682813..1552e343582e 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -55,7 +55,7 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv) // impl trait is gone in MIR, so check the return type manually check_ty( tcx, - tcx.fn_sig(def_id).output().skip_binder(), + tcx.bound_fn_sig(def_id).subst_identity().output().skip_binder(), body.local_decls.iter().next().unwrap().source_info.span, )?; diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 2d1044af17e8..d6a698bbeaa8 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -885,7 +885,7 @@ impl<'tcx> DerefDelegate<'_, 'tcx> { .cx .typeck_results() .type_dependent_def_id(parent_expr.hir_id) - .map(|did| self.cx.tcx.fn_sig(did).skip_binder()) + .map(|did| self.cx.tcx.bound_fn_sig(did).subst_identity().skip_binder()) { std::iter::once(receiver) .chain(call_args.iter()) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 99fba4fe741a..14fc2c100170 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -628,7 +628,7 @@ impl<'tcx> ExprFnSig<'tcx> { /// If the expression is function like, get the signature for it. pub fn expr_sig<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option> { if let Res::Def(DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn) | DefKind::AssocFn, id) = path_res(cx, expr) { - Some(ExprFnSig::Sig(cx.tcx.fn_sig(id), Some(id))) + Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst_identity(), Some(id))) } else { ty_sig(cx, cx.typeck_results().expr_ty_adjusted(expr).peel_refs()) } diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index 14c01a60b4c3..1680a40206a3 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -392,12 +392,12 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool { .cx .typeck_results() .type_dependent_def_id(e.hir_id) - .map_or(false, |id| self.cx.tcx.fn_sig(id).unsafety() == Unsafety::Unsafe) => + .map_or(false, |id| self.cx.tcx.bound_fn_sig(id).skip_binder().unsafety() == Unsafety::Unsafe) => { self.is_unsafe = true; }, ExprKind::Call(func, _) => match *self.cx.typeck_results().expr_ty(func).peel_refs().kind() { - ty::FnDef(id, _) if self.cx.tcx.fn_sig(id).unsafety() == Unsafety::Unsafe => self.is_unsafe = true, + ty::FnDef(id, _) if self.cx.tcx.bound_fn_sig(id).skip_binder().unsafety() == Unsafety::Unsafe => self.is_unsafe = true, ty::FnPtr(sig) if sig.unsafety() == Unsafety::Unsafe => self.is_unsafe = true, _ => walk_expr(self, e), }, From 5b35a6b5b8306a1013d505cd40a7cb4b58f4b52a Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Wed, 18 Jan 2023 16:52:47 -0700 Subject: [PATCH 0735/1222] change fn_sig query to use EarlyBinder; remove bound_fn_sig query; add EarlyBinder to fn_sig in metadata --- clippy_lints/src/casts/as_ptr_cast_mut.rs | 2 +- clippy_lints/src/default_numeric_fallback.rs | 4 ++-- clippy_lints/src/dereference.rs | 14 +++++++------- .../src/functions/not_unsafe_ptr_arg_deref.rs | 2 +- clippy_lints/src/functions/result.rs | 2 +- clippy_lints/src/inherent_to_string.rs | 2 +- clippy_lints/src/iter_not_returning_iterator.rs | 2 +- clippy_lints/src/len_zero.rs | 10 +++++----- clippy_lints/src/loops/needless_range_loop.rs | 2 +- clippy_lints/src/map_unit_fn.rs | 2 +- clippy_lints/src/methods/expect_fun_call.rs | 4 ++-- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/methods/needless_collect.rs | 4 ++-- clippy_lints/src/methods/unnecessary_to_owned.rs | 4 ++-- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/ptr.rs | 6 +++--- clippy_lints/src/returns.rs | 2 +- clippy_lints/src/unit_return_expecting_ord.rs | 2 +- clippy_lints/src/unit_types/let_unit_value.rs | 2 +- clippy_lints/src/use_self.rs | 2 +- clippy_utils/src/eager_or_lazy.rs | 2 +- clippy_utils/src/lib.rs | 6 +++--- clippy_utils/src/qualify_min_const_fn.rs | 2 +- clippy_utils/src/sugg.rs | 2 +- clippy_utils/src/ty.rs | 4 ++-- clippy_utils/src/visitors.rs | 4 ++-- 28 files changed, 48 insertions(+), 48 deletions(-) diff --git a/clippy_lints/src/casts/as_ptr_cast_mut.rs b/clippy_lints/src/casts/as_ptr_cast_mut.rs index 2a0e0857c561..1633ffd589c3 100644 --- a/clippy_lints/src/casts/as_ptr_cast_mut.rs +++ b/clippy_lints/src/casts/as_ptr_cast_mut.rs @@ -17,7 +17,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, && let ExprKind::MethodCall(method_name, receiver, [], _) = cast_expr.peel_blocks().kind && method_name.ident.name == rustc_span::sym::as_ptr && let Some(as_ptr_did) = cx.typeck_results().type_dependent_def_id(cast_expr.peel_blocks().hir_id) - && let as_ptr_sig = cx.tcx.bound_fn_sig(as_ptr_did).subst_identity() + && let as_ptr_sig = cx.tcx.fn_sig(as_ptr_did).subst_identity() && let Some(first_param_ty) = as_ptr_sig.skip_binder().inputs().iter().next() && let ty::Ref(_, _, Mutability::Not) = first_param_ty.kind() && let Some(recv) = snippet_opt(cx, receiver.span) diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index 9c5a9f583743..f806ba238c7c 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -141,7 +141,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { ExprKind::MethodCall(_, receiver, args, _) => { if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) { - let fn_sig = self.cx.tcx.bound_fn_sig(def_id).subst_identity().skip_binder(); + let fn_sig = self.cx.tcx.fn_sig(def_id).subst_identity().skip_binder(); for (expr, bound) in iter::zip(std::iter::once(*receiver).chain(args.iter()), fn_sig.inputs()) { self.ty_bounds.push((*bound).into()); self.visit_expr(expr); @@ -215,7 +215,7 @@ fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option Some(cx.tcx.bound_fn_sig(*def_id).subst_identity()), + ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(*def_id).subst_identity()), ty::FnPtr(fn_sig) => Some(*fn_sig), _ => None, } diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 25620f45b8a9..fa3e5aa6b721 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -759,7 +759,7 @@ fn walk_parents<'tcx>( }) if span.ctxt() == ctxt => { let output = cx .tcx - .erase_late_bound_regions(cx.tcx.bound_fn_sig(owner_id.to_def_id()).subst_identity().output()); + .erase_late_bound_regions(cx.tcx.fn_sig(owner_id).subst_identity().output()); Some(ty_auto_deref_stability(cx, output, precedence).position_for_result(cx)) }, @@ -791,7 +791,7 @@ fn walk_parents<'tcx>( } else { let output = cx .tcx - .erase_late_bound_regions(cx.tcx.bound_fn_sig(cx.tcx.hir().local_def_id(owner_id).into()).subst_identity().output()); + .erase_late_bound_regions(cx.tcx.fn_sig(cx.tcx.hir().local_def_id(owner_id)).subst_identity().output()); ty_auto_deref_stability(cx, output, precedence).position_for_result(cx) }, ) @@ -858,7 +858,7 @@ fn walk_parents<'tcx>( && let subs = cx .typeck_results() .node_substs_opt(parent.hir_id).map(|subs| &subs[1..]).unwrap_or_default() - && let impl_ty = if cx.tcx.bound_fn_sig(id).subst_identity().skip_binder().inputs()[0].is_ref() { + && let impl_ty = if cx.tcx.fn_sig(id).subst_identity().skip_binder().inputs()[0].is_ref() { // Trait methods taking `&self` sub_ty } else { @@ -879,7 +879,7 @@ fn walk_parents<'tcx>( return Some(Position::MethodReceiver); } args.iter().position(|arg| arg.hir_id == child_id).map(|i| { - let ty = cx.tcx.bound_fn_sig(id).subst_identity().skip_binder().inputs()[i + 1]; + let ty = cx.tcx.fn_sig(id).subst_identity().skip_binder().inputs()[i + 1]; // `e.hir_id == child_id` for https://github.com/rust-lang/rust-clippy/issues/9739 // `method.args.is_none()` for https://github.com/rust-lang/rust-clippy/issues/9782 if e.hir_id == child_id && method.args.is_none() && let ty::Param(param_ty) = ty.kind() { @@ -896,7 +896,7 @@ fn walk_parents<'tcx>( } else { ty_auto_deref_stability( cx, - cx.tcx.erase_late_bound_regions(cx.tcx.bound_fn_sig(id).subst_identity().input(i + 1)), + cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).subst_identity().input(i + 1)), precedence, ) .position_for_arg() @@ -1093,7 +1093,7 @@ fn needless_borrow_impl_arg_position<'tcx>( let sized_trait_def_id = cx.tcx.lang_items().sized_trait(); let Some(callee_def_id) = fn_def_id(cx, parent) else { return Position::Other(precedence) }; - let fn_sig = cx.tcx.bound_fn_sig(callee_def_id).subst_identity().skip_binder(); + let fn_sig = cx.tcx.fn_sig(callee_def_id).subst_identity().skip_binder(); let substs_with_expr_ty = cx .typeck_results() .node_substs(if let ExprKind::Call(callee, _) = parent.kind { @@ -1221,7 +1221,7 @@ fn has_ref_mut_self_method(cx: &LateContext<'_>, trait_def_id: DefId) -> bool { .in_definition_order() .any(|assoc_item| { if assoc_item.fn_has_self_parameter { - let self_ty = cx.tcx.bound_fn_sig(assoc_item.def_id).subst_identity().skip_binder().inputs()[0]; + let self_ty = cx.tcx.fn_sig(assoc_item.def_id).subst_identity().skip_binder().inputs()[0]; matches!(self_ty.kind(), ty::Ref(_, _, Mutability::Mut)) } else { false diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index 4f0371c027c2..cdb5e22e7598 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -58,7 +58,7 @@ fn check_raw_ptr<'tcx>( }, hir::ExprKind::MethodCall(_, recv, args, _) => { let def_id = typeck.type_dependent_def_id(e.hir_id).unwrap(); - if cx.tcx.bound_fn_sig(def_id).skip_binder().skip_binder().unsafety == hir::Unsafety::Unsafe { + if cx.tcx.fn_sig(def_id).skip_binder().skip_binder().unsafety == hir::Unsafety::Unsafe { check_arg(cx, &raw_ptrs, recv); for arg in args { check_arg(cx, &raw_ptrs, arg); diff --git a/clippy_lints/src/functions/result.rs b/clippy_lints/src/functions/result.rs index 21de62581f1c..fa2a9b30c058 100644 --- a/clippy_lints/src/functions/result.rs +++ b/clippy_lints/src/functions/result.rs @@ -21,7 +21,7 @@ fn result_err_ty<'tcx>( ) -> Option<(&'tcx hir::Ty<'tcx>, Ty<'tcx>)> { if !in_external_macro(cx.sess(), item_span) && let hir::FnRetTy::Return(hir_ty) = decl.output - && let ty = cx.tcx.erase_late_bound_regions(cx.tcx.bound_fn_sig(id.into()).subst_identity().output()) + && let ty = cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).subst_identity().output()) && is_type_diagnostic_item(cx, ty, sym::Result) && let ty::Adt(_, substs) = ty.kind() { diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index d971684a3aa9..612c3ea8fdfd 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -124,7 +124,7 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) { .expect("Failed to get trait ID of `Display`!"); // Get the real type of 'self' - let self_type = cx.tcx.bound_fn_sig(item.owner_id.to_def_id()).skip_binder().input(0); + let self_type = cx.tcx.fn_sig(item.owner_id).skip_binder().input(0); let self_type = self_type.skip_binder().peel_refs(); // Emit either a warning or an error diff --git a/clippy_lints/src/iter_not_returning_iterator.rs b/clippy_lints/src/iter_not_returning_iterator.rs index 131af2fd9c38..7557a9ce13f1 100644 --- a/clippy_lints/src/iter_not_returning_iterator.rs +++ b/clippy_lints/src/iter_not_returning_iterator.rs @@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator { fn check_sig(cx: &LateContext<'_>, name: &str, sig: &FnSig<'_>, fn_id: LocalDefId) { if sig.decl.implicit_self.has_implicit_self() { - let ret_ty = cx.tcx.erase_late_bound_regions(cx.tcx.bound_fn_sig(fn_id.into()).subst_identity().output()); + let ret_ty = cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(fn_id).subst_identity().output()); let ret_ty = cx .tcx .try_normalize_erasing_regions(cx.param_env, ret_ty) diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 121d6b9f0fe7..80ed2862a419 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero { if let Some(local_id) = ty_id.as_local(); let ty_hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_id); if !is_lint_allowed(cx, LEN_WITHOUT_IS_EMPTY, ty_hir_id); - if let Some(output) = parse_len_output(cx, cx.tcx.bound_fn_sig(item.owner_id.to_def_id()).subst_identity().skip_binder()); + if let Some(output) = parse_len_output(cx, cx.tcx.fn_sig(item.owner_id).subst_identity().skip_binder()); then { let (name, kind) = match cx.tcx.hir().find(ty_hir_id) { Some(Node::ForeignItem(x)) => (x.ident.name, "extern type"), @@ -196,7 +196,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items fn is_named_self(cx: &LateContext<'_>, item: &TraitItemRef, name: Symbol) -> bool { item.ident.name == name && if let AssocItemKind::Fn { has_self } = item.kind { - has_self && { cx.tcx.bound_fn_sig(item.id.owner_id.to_def_id()).skip_binder().inputs().skip_binder().len() == 1 } + has_self && { cx.tcx.fn_sig(item.id.owner_id).skip_binder().inputs().skip_binder().len() == 1 } } else { false } @@ -224,7 +224,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items .any(|i| { i.kind == ty::AssocKind::Fn && i.fn_has_self_parameter - && cx.tcx.bound_fn_sig(i.def_id).skip_binder().inputs().skip_binder().len() == 1 + && cx.tcx.fn_sig(i.def_id).skip_binder().inputs().skip_binder().len() == 1 }); if !is_empty_method_found { @@ -342,7 +342,7 @@ fn check_for_is_empty<'tcx>( ), Some(is_empty) if !(is_empty.fn_has_self_parameter - && check_is_empty_sig(cx.tcx.bound_fn_sig(is_empty.def_id).subst_identity().skip_binder(), self_kind, output)) => + && check_is_empty_sig(cx.tcx.fn_sig(is_empty.def_id).subst_identity().skip_binder(), self_kind, output)) => { ( format!( @@ -473,7 +473,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { /// Gets an `AssocItem` and return true if it matches `is_empty(self)`. fn is_is_empty(cx: &LateContext<'_>, item: &ty::AssocItem) -> bool { if item.kind == ty::AssocKind::Fn { - let sig = cx.tcx.bound_fn_sig(item.def_id).skip_binder(); + let sig = cx.tcx.fn_sig(item.def_id).skip_binder(); let ty = sig.skip_binder(); ty.inputs().len() == 1 } else { diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 3e025bc0e716..e6ed4ea7a5db 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -370,7 +370,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { ExprKind::MethodCall(_, receiver, args, _) => { let def_id = self.cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap(); for (ty, expr) in iter::zip( - self.cx.tcx.bound_fn_sig(def_id).subst_identity().inputs().skip_binder(), + self.cx.tcx.fn_sig(def_id).subst_identity().inputs().skip_binder(), std::iter::once(receiver).chain(args.iter()), ) { self.prefer_mutable = false; diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index a179dd091e42..edcab6968cbe 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -104,7 +104,7 @@ fn is_unit_function(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { let ty = cx.typeck_results().expr_ty(expr); if let ty::FnDef(id, _) = *ty.kind() { - if let Some(fn_type) = cx.tcx.bound_fn_sig(id).subst_identity().no_bound_vars() { + if let Some(fn_type) = cx.tcx.fn_sig(id).subst_identity().no_bound_vars() { return is_unit_type(fn_type.output()); } } diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index 3f670ebc9178..aed0ad5d9b5a 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -70,7 +70,7 @@ pub(super) fn check<'tcx>( if let hir::ExprKind::Path(ref p) = fun.kind { match cx.qpath_res(p, fun.hir_id) { hir::def::Res::Def(hir::def::DefKind::Fn | hir::def::DefKind::AssocFn, def_id) => matches!( - cx.tcx.bound_fn_sig(def_id).subst_identity().output().skip_binder().kind(), + cx.tcx.fn_sig(def_id).subst_identity().output().skip_binder().kind(), ty::Ref(re, ..) if re.is_static(), ), _ => false, @@ -84,7 +84,7 @@ pub(super) fn check<'tcx>( .type_dependent_def_id(arg.hir_id) .map_or(false, |method_id| { matches!( - cx.tcx.bound_fn_sig(method_id).subst_identity().output().skip_binder().kind(), + cx.tcx.fn_sig(method_id).subst_identity().output().skip_binder().kind(), ty::Ref(re, ..) if re.is_static() ) }) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 6002ef1340be..a7e45d5126ab 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3352,7 +3352,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { let implements_trait = matches!(item.kind, hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })); if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind { - let method_sig = cx.tcx.bound_fn_sig(impl_item.owner_id.to_def_id()).subst_identity(); + let method_sig = cx.tcx.fn_sig(impl_item.owner_id).subst_identity(); let method_sig = cx.tcx.erase_late_bound_regions(method_sig); let first_arg_ty_opt = method_sig.inputs().iter().next().copied(); // if this impl block implements a trait, lint in trait definition instead diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index 1a1715d03a7c..82d3b830d4f3 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -137,7 +137,7 @@ pub(super) fn check<'tcx>( /// Checks if the given method call matches the expected signature of `([&[mut]] self) -> bool` fn is_is_empty_sig(cx: &LateContext<'_>, call_id: HirId) -> bool { cx.typeck_results().type_dependent_def_id(call_id).map_or(false, |id| { - let sig = cx.tcx.bound_fn_sig(id).subst_identity().skip_binder(); + let sig = cx.tcx.fn_sig(id).subst_identity().skip_binder(); sig.inputs().len() == 1 && sig.output().is_bool() }) } @@ -165,7 +165,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty: fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) -> bool { let typeck = cx.typeck_results(); if let Some(id) = typeck.type_dependent_def_id(call_id) - && let sig = cx.tcx.bound_fn_sig(id).subst_identity() + && let sig = cx.tcx.fn_sig(id).subst_identity() && sig.skip_binder().output().is_bool() && let [_, search_ty] = *sig.skip_binder().inputs() && let ty::Ref(_, search_ty, Mutability::Not) = *cx.tcx.erase_late_bound_regions(sig.rebind(search_ty)).kind() diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 8036e787aaec..12e053cb2134 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -246,7 +246,7 @@ fn check_other_call_arg<'tcx>( if_chain! { if let Some((maybe_call, maybe_arg)) = skip_addr_of_ancestors(cx, expr); if let Some((callee_def_id, _, recv, call_args)) = get_callee_substs_and_args(cx, maybe_call); - let fn_sig = cx.tcx.bound_fn_sig(callee_def_id).subst_identity().skip_binder(); + let fn_sig = cx.tcx.fn_sig(callee_def_id).subst_identity().skip_binder(); if let Some(i) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == maybe_arg.hir_id); if let Some(input) = fn_sig.inputs().get(i); let (input, n_refs) = peel_mid_ty_refs(*input); @@ -386,7 +386,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< Node::Expr(parent_expr) => { if let Some((callee_def_id, call_substs, recv, call_args)) = get_callee_substs_and_args(cx, parent_expr) { - let fn_sig = cx.tcx.bound_fn_sig(callee_def_id).subst_identity().skip_binder(); + let fn_sig = cx.tcx.fn_sig(callee_def_id).subst_identity().skip_binder(); if let Some(arg_index) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == expr.hir_id) && let Some(param_ty) = fn_sig.inputs().get(arg_index) && let ty::Param(ParamTy { index: param_index , ..}) = param_ty.kind() diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index a2868883673f..16947cd5e354 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -138,7 +138,7 @@ impl MutableKeyType { fn check_sig(&self, cx: &LateContext<'_>, item_hir_id: hir::HirId, decl: &hir::FnDecl<'_>) { let fn_def_id = cx.tcx.hir().local_def_id(item_hir_id); - let fn_sig = cx.tcx.bound_fn_sig(fn_def_id.into()).subst_identity(); + let fn_sig = cx.tcx.fn_sig(fn_def_id).subst_identity(); for (hir_ty, ty) in iter::zip(decl.inputs, fn_sig.inputs().skip_binder()) { self.check_ty_(cx, hir_ty.span, *ty); } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index e3d25603a715..25ec9082c707 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { ctx }; - let fn_sig = cx.tcx.bound_fn_sig(fn_def_id.into()).subst_identity(); + let fn_sig = cx.tcx.fn_sig(fn_def_id).subst_identity(); let fn_sig = cx.tcx.erase_late_bound_regions(fn_sig); for (idx, ((input, &ty), arg)) in decl.inputs.iter().zip(fn_sig.inputs()).zip(body.params).enumerate() { diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 5512109c6cbb..954eeba751ff 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -143,7 +143,7 @@ impl<'tcx> PassByRefOrValue { return; } - let fn_sig = cx.tcx.bound_fn_sig(def_id.into()).subst_identity(); + let fn_sig = cx.tcx.fn_sig(def_id).subst_identity(); let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir().body(id)); // Gather all the lifetimes found in the output type which may affect whether diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 0a2d35015f57..8afe286fbd5d 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -164,7 +164,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { check_mut_from_ref(cx, sig, None); for arg in check_fn_args( cx, - cx.tcx.bound_fn_sig(item.owner_id.to_def_id()).subst_identity().skip_binder().inputs(), + cx.tcx.fn_sig(item.owner_id).subst_identity().skip_binder().inputs(), sig.decl.inputs, &[], ) @@ -217,7 +217,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { check_mut_from_ref(cx, sig, Some(body)); let decl = sig.decl; - let sig = cx.tcx.bound_fn_sig(item_id.to_def_id()).subst_identity().skip_binder(); + let sig = cx.tcx.fn_sig(item_id).subst_identity().skip_binder(); let lint_args: Vec<_> = check_fn_args(cx, sig.inputs(), decl.inputs, body.params) .filter(|arg| !is_trait_item || arg.mutability() == Mutability::Not) .collect(); @@ -624,7 +624,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: return; }; - match *self.cx.tcx.bound_fn_sig(id).subst_identity().skip_binder().inputs()[i].peel_refs().kind() { + match *self.cx.tcx.fn_sig(id).subst_identity().skip_binder().inputs()[i].peel_refs().kind() { ty::Dynamic(preds, _, _) if !matches_preds(self.cx, args.deref_ty.ty(self.cx), preds) => { set_skip_flag(); }, diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index f3c503306043..dc1275a3686d 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -287,7 +287,7 @@ fn last_statement_borrows<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) if let Some(def_id) = fn_def_id(cx, e) && cx .tcx - .bound_fn_sig(def_id) + .fn_sig(def_id) .subst_identity() .skip_binder() .output() diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 5df26d8b0a38..289ca4e9bed3 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -76,7 +76,7 @@ fn get_projection_pred<'tcx>( fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Vec<(usize, String)> { let mut args_to_check = Vec::new(); if let Some(def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) { - let fn_sig = cx.tcx.bound_fn_sig(def_id).subst_identity(); + let fn_sig = cx.tcx.fn_sig(def_id).subst_identity(); let generics = cx.tcx.predicates_of(def_id); let fn_mut_preds = get_trait_predicates_for_trait_id(cx, generics, cx.tcx.lang_items().fn_mut_trait()); let ord_preds = get_trait_predicates_for_trait_id(cx, generics, cx.tcx.get_diagnostic_item(sym::Ord)); diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index 681e59a1575d..d6167a62169d 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -156,7 +156,7 @@ fn needs_inferred_result_ty( }, _ => return false, }; - let sig = cx.tcx.bound_fn_sig(id).subst_identity().skip_binder(); + let sig = cx.tcx.fn_sig(id).subst_identity().skip_binder(); if let ty::Param(output_ty) = *sig.output().kind() { let args: Vec<&Expr<'_>> = if let Some(receiver) = receiver { std::iter::once(receiver).chain(args.iter()).collect() diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 09324fd92943..3cd35838961f 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -146,7 +146,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { .associated_item(impl_item.owner_id) .trait_item_def_id .expect("impl method matches a trait method"); - let trait_method_sig = cx.tcx.bound_fn_sig(trait_method).subst_identity(); + let trait_method_sig = cx.tcx.fn_sig(trait_method).subst_identity(); let trait_method_sig = cx.tcx.erase_late_bound_regions(trait_method_sig); // `impl_inputs_outputs` is an iterator over the types (`hir::Ty`) declared in the diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 38588e32dbfe..5c89dd3e49f4 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -79,7 +79,7 @@ fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg: && subs.types().all(|x| matches!(x.peel_refs().kind(), ty::Param(_))) { // Limit the function to either `(self) -> bool` or `(&self) -> bool` - match &**cx.tcx.bound_fn_sig(fn_id).subst_identity().skip_binder().inputs_and_output { + match &**cx.tcx.fn_sig(fn_id).subst_identity().skip_binder().inputs_and_output { [arg, res] if !arg.is_mutable_ptr() && arg.peel_refs() == ty && res.is_bool() => NoChange, _ => Lazy, } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index ccc5f3503d2f..23791ebe9225 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1379,7 +1379,7 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>( .chain(args.iter()) .position(|arg| arg.hir_id == id)?; let id = cx.typeck_results().type_dependent_def_id(e.hir_id)?; - let ty = cx.tcx.bound_fn_sig(id).subst_identity().skip_binder().inputs()[i]; + let ty = cx.tcx.fn_sig(id).subst_identity().skip_binder().inputs()[i]; ty_is_fn_once_param(cx.tcx, ty, cx.tcx.param_env(id).caller_bounds()).then_some(()) }, _ => None, @@ -1580,14 +1580,14 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option { /// Convenience function to get the return type of a function. pub fn return_ty<'tcx>(cx: &LateContext<'tcx>, fn_item: hir::HirId) -> Ty<'tcx> { let fn_def_id = cx.tcx.hir().local_def_id(fn_item); - let ret_ty = cx.tcx.bound_fn_sig(fn_def_id.into()).subst_identity().output(); + let ret_ty = cx.tcx.fn_sig(fn_def_id).subst_identity().output(); cx.tcx.erase_late_bound_regions(ret_ty) } /// Convenience function to get the nth argument type of a function. pub fn nth_arg<'tcx>(cx: &LateContext<'tcx>, fn_item: hir::HirId, nth: usize) -> Ty<'tcx> { let fn_def_id = cx.tcx.hir().local_def_id(fn_item); - let arg = cx.tcx.bound_fn_sig(fn_def_id.into()).subst_identity().input(nth); + let arg = cx.tcx.fn_sig(fn_def_id).subst_identity().input(nth); cx.tcx.erase_late_bound_regions(arg) } diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 1552e343582e..13de780b7109 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -55,7 +55,7 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv) // impl trait is gone in MIR, so check the return type manually check_ty( tcx, - tcx.bound_fn_sig(def_id).subst_identity().output().skip_binder(), + tcx.fn_sig(def_id).subst_identity().output().skip_binder(), body.local_decls.iter().next().unwrap().source_info.span, )?; diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index d6a698bbeaa8..8d767f9d44d3 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -885,7 +885,7 @@ impl<'tcx> DerefDelegate<'_, 'tcx> { .cx .typeck_results() .type_dependent_def_id(parent_expr.hir_id) - .map(|did| self.cx.tcx.bound_fn_sig(did).subst_identity().skip_binder()) + .map(|did| self.cx.tcx.fn_sig(did).subst_identity().skip_binder()) { std::iter::once(receiver) .chain(call_args.iter()) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 14fc2c100170..1d5d55d5b54c 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -628,7 +628,7 @@ impl<'tcx> ExprFnSig<'tcx> { /// If the expression is function like, get the signature for it. pub fn expr_sig<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option> { if let Res::Def(DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn) | DefKind::AssocFn, id) = path_res(cx, expr) { - Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst_identity(), Some(id))) + Some(ExprFnSig::Sig(cx.tcx.fn_sig(id).subst_identity(), Some(id))) } else { ty_sig(cx, cx.typeck_results().expr_ty_adjusted(expr).peel_refs()) } @@ -646,7 +646,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))), + ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.fn_sig(id).subst(cx.tcx, subs), Some(id))), ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => { sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id).subst(cx.tcx, substs), cx.tcx.opt_parent(def_id)) }, diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index 1680a40206a3..d18b62d1bf16 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -392,12 +392,12 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool { .cx .typeck_results() .type_dependent_def_id(e.hir_id) - .map_or(false, |id| self.cx.tcx.bound_fn_sig(id).skip_binder().unsafety() == Unsafety::Unsafe) => + .map_or(false, |id| self.cx.tcx.fn_sig(id).skip_binder().unsafety() == Unsafety::Unsafe) => { self.is_unsafe = true; }, ExprKind::Call(func, _) => match *self.cx.typeck_results().expr_ty(func).peel_refs().kind() { - ty::FnDef(id, _) if self.cx.tcx.bound_fn_sig(id).skip_binder().unsafety() == Unsafety::Unsafe => self.is_unsafe = true, + ty::FnDef(id, _) if self.cx.tcx.fn_sig(id).skip_binder().unsafety() == Unsafety::Unsafe => self.is_unsafe = true, ty::FnPtr(sig) if sig.unsafety() == Unsafety::Unsafe => self.is_unsafe = true, _ => walk_expr(self, e), }, From 0abfad035c2dcef5a4971c73bf599d69d6840725 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 13 Jan 2023 13:56:51 +0100 Subject: [PATCH 0736/1222] Update clippy for restructured format flags fields. --- clippy_utils/src/macros.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs index a8f8da67b517..659063b97e74 100644 --- a/clippy_utils/src/macros.rs +++ b/clippy_utils/src/macros.rs @@ -711,8 +711,8 @@ pub struct FormatSpec<'tcx> { pub fill: Option, /// Optionally specified alignment. pub align: Alignment, - /// Packed version of various flags provided, see [`rustc_parse_format::Flag`]. - pub flags: u32, + /// Whether all flag options are set to default (no flags specified). + pub no_flags: bool, /// Represents either the maximum width or the integer precision. pub precision: Count<'tcx>, /// The minimum width, will be padded according to `width`/`align` @@ -728,7 +728,7 @@ impl<'tcx> FormatSpec<'tcx> { Some(Self { fill: spec.fill, align: spec.align, - flags: spec.flags, + no_flags: spec.sign.is_none() && !spec.alternate && !spec.zero_pad && spec.debug_hex.is_none(), precision: Count::new( FormatParamUsage::Precision, spec.precision, @@ -773,7 +773,7 @@ impl<'tcx> FormatSpec<'tcx> { self.width.is_implied() && self.precision.is_implied() && self.align == Alignment::AlignUnknown - && self.flags == 0 + && self.no_flags } } From 7e4e469acc3aaac8a6db178361b3828a55cf8a6f Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 1 Oct 2022 14:56:24 +0200 Subject: [PATCH 0737/1222] Introduce GeneratorWitnessMIR. --- clippy_lints/src/dereference.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index fa3e5aa6b721..8e921839e8b2 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1419,6 +1419,7 @@ fn ty_auto_deref_stability<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, precedenc | ty::FnDef(..) | ty::Generator(..) | ty::GeneratorWitness(..) + | ty::GeneratorWitnessMIR(..) | ty::Closure(..) | ty::Never | ty::Tuple(_) From 9a02ec3d5da9febb939a4b9c3fc943adc5b77fef Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Fri, 27 Jan 2023 20:02:51 -0800 Subject: [PATCH 0738/1222] Remove from librustdoc and clippy too --- clippy_lints/src/lib.rs | 1 - clippy_lints/src/methods/collapsible_str_replace.rs | 2 +- clippy_utils/src/lib.rs | 1 - clippy_utils/src/macros.rs | 2 +- clippy_utils/src/mir/possible_borrower.rs | 2 +- 5 files changed, 3 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 5c4b60410441..d06830397761 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -1,7 +1,6 @@ #![feature(array_windows)] #![feature(binary_heap_into_iter_sorted)] #![feature(box_patterns)] -#![feature(control_flow_enum)] #![feature(drain_filter)] #![feature(iter_intersperse)] #![feature(let_chains)] diff --git a/clippy_lints/src/methods/collapsible_str_replace.rs b/clippy_lints/src/methods/collapsible_str_replace.rs index ac61b4377885..5e01ed90ff09 100644 --- a/clippy_lints/src/methods/collapsible_str_replace.rs +++ b/clippy_lints/src/methods/collapsible_str_replace.rs @@ -54,7 +54,7 @@ fn collect_replace_calls<'tcx>( from_args.push_front(from); ControlFlow::Continue(()) } else { - ControlFlow::BREAK + ControlFlow::Break(()) } } else { ControlFlow::Continue(()) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index e2965146cfe6..a246291f9a9b 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1,6 +1,5 @@ #![feature(array_chunks)] #![feature(box_patterns)] -#![feature(control_flow_enum)] #![feature(let_chains)] #![feature(lint_reasons)] #![feature(never_type)] diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs index 659063b97e74..d7f466c19763 100644 --- a/clippy_utils/src/macros.rs +++ b/clippy_utils/src/macros.rs @@ -327,7 +327,7 @@ fn is_assert_arg(cx: &LateContext<'_>, expr: &Expr<'_>, assert_expn: ExpnId) -> } else { match cx.tcx.item_name(macro_call.def_id) { // `cfg!(debug_assertions)` in `debug_assert!` - sym::cfg => ControlFlow::CONTINUE, + sym::cfg => ControlFlow::Continue(()), // assert!(other_macro!(..)) _ => ControlFlow::Break(true), } diff --git a/clippy_utils/src/mir/possible_borrower.rs b/clippy_utils/src/mir/possible_borrower.rs index 9adae7733894..5836eb73bd94 100644 --- a/clippy_utils/src/mir/possible_borrower.rs +++ b/clippy_utils/src/mir/possible_borrower.rs @@ -140,7 +140,7 @@ impl TypeVisitor<'_> for ContainsRegion { type BreakTy = (); fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow { - ControlFlow::BREAK + ControlFlow::Break(()) } } From 2a970de61569bd98a165356e007d60d84938d552 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 22 Jan 2023 18:00:33 +0000 Subject: [PATCH 0739/1222] Take a LocalDefId in hir::Visitor::visit_fn. --- clippy_lints/src/booleans.rs | 5 +-- clippy_lints/src/cognitive_complexity.rs | 6 ++-- clippy_lints/src/derive.rs | 5 +-- clippy_lints/src/doc.rs | 18 +++++----- clippy_lints/src/escape.rs | 12 ++++--- clippy_lints/src/excessive_bools.rs | 6 ++-- clippy_lints/src/exhaustive_items.rs | 3 +- .../src/functions/misnamed_getters.rs | 3 +- clippy_lints/src/functions/mod.rs | 8 +++-- clippy_lints/src/functions/must_use.rs | 22 ++++++------- .../src/functions/not_unsafe_ptr_arg_deref.rs | 4 +-- clippy_lints/src/future_not_send.rs | 10 +++--- clippy_lints/src/implicit_return.rs | 3 +- clippy_lints/src/inherent_to_string.rs | 2 +- clippy_lints/src/lifetimes.rs | 11 +++---- clippy_lints/src/manual_async_fn.rs | 5 +-- clippy_lints/src/manual_non_exhaustive.rs | 3 +- clippy_lints/src/methods/mod.rs | 4 +-- clippy_lints/src/methods/suspicious_map.rs | 5 ++- .../src/methods/unnecessary_to_owned.rs | 7 ++-- clippy_lints/src/misc.rs | 7 ++-- clippy_lints/src/missing_const_for_fn.rs | 9 ++--- clippy_lints/src/mut_key.rs | 10 +++--- clippy_lints/src/needless_pass_by_value.rs | 7 ++-- clippy_lints/src/new_without_default.rs | 6 ++-- .../src/operators/arithmetic_side_effects.rs | 3 +- .../src/operators/numeric_arithmetic.rs | 2 +- clippy_lints/src/panic_in_result_fn.rs | 9 +++-- clippy_lints/src/pass_by_ref_or_value.rs | 7 ++-- clippy_lints/src/pattern_type_mismatch.rs | 7 ++-- clippy_lints/src/redundant_clone.rs | 9 +++-- clippy_lints/src/return_self_not_must_use.rs | 18 +++++----- clippy_lints/src/returns.rs | 5 +-- clippy_lints/src/self_named_constructors.rs | 2 +- clippy_lints/src/trailing_empty_array.rs | 3 +- clippy_lints/src/types/mod.rs | 33 +++++++++++++------ clippy_lints/src/unnecessary_wraps.rs | 26 ++++++++------- clippy_lints/src/unused_async.rs | 7 ++-- clippy_lints/src/unwrap.rs | 3 +- clippy_lints/src/unwrap_in_result.rs | 4 +-- clippy_utils/src/lib.rs | 3 +- 41 files changed, 175 insertions(+), 147 deletions(-) diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 939bdbcdc7cd..e8106beec374 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -6,9 +6,10 @@ use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; -use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, UnOp}; +use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::def_id::LocalDefId; use rustc_span::source_map::Span; use rustc_span::sym; @@ -82,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for NonminimalBool { _: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, _: Span, - _: HirId, + _: LocalDefId, ) { NonminimalBoolVisitor { cx }.visit_body(body); } diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index 1c3a89a97824..e8531157e0f7 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -8,9 +8,10 @@ use clippy_utils::{get_async_fn_body, is_async_fn, LimitStack}; use core::ops::ControlFlow; use rustc_ast::ast::Attribute; use rustc_hir::intravisit::FnKind; -use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId}; +use rustc_hir::{Body, Expr, ExprKind, FnDecl}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::def_id::LocalDefId; use rustc_span::source_map::Span; use rustc_span::{sym, BytePos}; @@ -140,9 +141,8 @@ impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity { decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, span: Span, - hir_id: HirId, + def_id: LocalDefId, ) { - let def_id = cx.tcx.hir().local_def_id(hir_id); if !cx.tcx.has_attr(def_id.to_def_id(), sym::test) { let expr = if is_async_fn(kind) { match get_async_fn_body(cx.tcx, body) { diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 248d73884106..f8fc726d603f 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -7,7 +7,7 @@ use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, Visitor}; use rustc_hir::{ - self as hir, BlockCheckMode, BodyId, Constness, Expr, ExprKind, FnDecl, HirId, Impl, Item, ItemKind, UnsafeSource, + self as hir, BlockCheckMode, BodyId, Constness, Expr, ExprKind, FnDecl, Impl, Item, ItemKind, UnsafeSource, Unsafety, }; use rustc_lint::{LateContext, LateLintPass}; @@ -18,6 +18,7 @@ use rustc_middle::ty::{ TraitPredicate, Ty, TyCtxt, }; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::def_id::LocalDefId; use rustc_span::source_map::Span; use rustc_span::sym; @@ -425,7 +426,7 @@ struct UnsafeVisitor<'a, 'tcx> { impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> { type NestedFilter = nested_filter::All; - fn visit_fn(&mut self, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body_id: BodyId, _: Span, id: HirId) { + fn visit_fn(&mut self, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body_id: BodyId, _: Span, id: LocalDefId) { if self.has_unsafe { return; } diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index f7a3d6d53f71..127201b72e27 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -23,7 +23,6 @@ use rustc_parse::maybe_new_parser_from_source_str; use rustc_parse::parser::ForceCollect; use rustc_session::parse::ParseSess; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::def_id::LocalDefId; use rustc_span::edition::Edition; use rustc_span::source_map::{BytePos, FilePathMapping, SourceMap, Span}; use rustc_span::{sym, FileName, Pos}; @@ -302,7 +301,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { panic_span: None, }; fpu.visit_expr(body.value); - lint_for_missing_headers(cx, item.owner_id.def_id, sig, headers, Some(body_id), fpu.panic_span); + lint_for_missing_headers(cx, item.owner_id, sig, headers, Some(body_id), fpu.panic_span); } }, hir::ItemKind::Impl(impl_) => { @@ -338,7 +337,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else { return }; if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { if !in_external_macro(cx.tcx.sess, item.span) { - lint_for_missing_headers(cx, item.owner_id.def_id, sig, headers, None, None); + lint_for_missing_headers(cx, item.owner_id, sig, headers, None, None); } } } @@ -357,20 +356,20 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { panic_span: None, }; fpu.visit_expr(body.value); - lint_for_missing_headers(cx, item.owner_id.def_id, sig, headers, Some(body_id), fpu.panic_span); + lint_for_missing_headers(cx, item.owner_id, sig, headers, Some(body_id), fpu.panic_span); } } } fn lint_for_missing_headers( cx: &LateContext<'_>, - def_id: LocalDefId, + owner_id: hir::OwnerId, sig: &hir::FnSig<'_>, headers: DocHeaders, body_id: Option, panic_span: Option, ) { - if !cx.effective_visibilities.is_exported(def_id) { + if !cx.effective_visibilities.is_exported(owner_id.def_id) { return; // Private functions do not require doc comments } @@ -378,13 +377,13 @@ fn lint_for_missing_headers( if cx .tcx .hir() - .parent_iter(cx.tcx.hir().local_def_id_to_hir_id(def_id)) + .parent_iter(owner_id.into()) .any(|(id, _node)| is_doc_hidden(cx.tcx.hir().attrs(id))) { return; } - let span = cx.tcx.def_span(def_id); + let span = cx.tcx.def_span(owner_id); match (headers.safety, sig.header.unsafety) { (false, hir::Unsafety::Unsafe) => span_lint( cx, @@ -411,8 +410,7 @@ fn lint_for_missing_headers( ); } if !headers.errors { - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); - if is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::Result) { + if is_type_diagnostic_item(cx, return_ty(cx, owner_id), sym::Result) { span_lint( cx, MISSING_ERRORS_DOC, diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index dfb43893326e..d6ab4c25e83e 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -8,6 +8,7 @@ use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, TraitRef, Ty}; use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::def_id::LocalDefId; use rustc_span::source_map::Span; use rustc_span::symbol::kw; use rustc_target::spec::abi::Abi; @@ -63,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { _: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, _: Span, - hir_id: HirId, + fn_def_id: LocalDefId, ) { if let Some(header) = fn_kind.header() { if header.abi != Abi::Rust { @@ -71,7 +72,11 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { } } - let parent_id = cx.tcx.hir().get_parent_item(hir_id).def_id; + let parent_id = cx + .tcx + .hir() + .get_parent_item(cx.tcx.hir().local_def_id_to_hir_id(fn_def_id)) + .def_id; let parent_node = cx.tcx.hir().find_by_def_id(parent_id); let mut trait_self_ty = None; @@ -84,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { // find `self` ty for this trait if relevant if let ItemKind::Trait(_, _, _, _, items) = item.kind { for trait_item in items { - if trait_item.id.hir_id() == hir_id { + if trait_item.id.owner_id.def_id == fn_def_id { // be sure we have `self` parameter in this function if trait_item.kind == (AssocItemKind::Fn { has_self: true }) { trait_self_ty = Some( @@ -105,7 +110,6 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { too_large_for_stack: self.too_large_for_stack, }; - let fn_def_id = cx.tcx.hir().local_def_id(hir_id); let infcx = cx.tcx.infer_ctxt().build(); ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body); diff --git a/clippy_lints/src/excessive_bools.rs b/clippy_lints/src/excessive_bools.rs index fc2912f696e0..9d089fcad70e 100644 --- a/clippy_lints/src/excessive_bools.rs +++ b/clippy_lints/src/excessive_bools.rs @@ -1,10 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::{get_parent_as_impl, has_repr_attr, is_bool}; use rustc_hir::intravisit::FnKind; -use rustc_hir::{Body, FnDecl, HirId, Item, ItemKind, TraitFn, TraitItem, TraitItemKind, Ty}; +use rustc_hir::{Body, FnDecl, Item, ItemKind, TraitFn, TraitItem, TraitItemKind, Ty}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; +use rustc_span::def_id::LocalDefId; use rustc_target::spec::abi::Abi; declare_clippy_lint! { @@ -168,8 +169,9 @@ impl<'tcx> LateLintPass<'tcx> for ExcessiveBools { fn_decl: &'tcx FnDecl<'tcx>, _: &'tcx Body<'tcx>, span: Span, - hir_id: HirId, + def_id: LocalDefId, ) { + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); if let Some(fn_header) = fn_kind.header() && fn_header.abi == Abi::Rust && get_parent_as_impl(cx.tcx, hir_id) diff --git a/clippy_lints/src/exhaustive_items.rs b/clippy_lints/src/exhaustive_items.rs index 1fece5d1c480..9fd13084dc9e 100644 --- a/clippy_lints/src/exhaustive_items.rs +++ b/clippy_lints/src/exhaustive_items.rs @@ -79,8 +79,7 @@ impl LateLintPass<'_> for ExhaustiveItems { then { let (lint, msg) = if let ItemKind::Struct(ref v, ..) = item.kind { if v.fields().iter().any(|f| { - let def_id = cx.tcx.hir().local_def_id(f.hir_id); - !cx.tcx.visibility(def_id).is_public() + !cx.tcx.visibility(f.def_id).is_public() }) { // skip structs with private fields return; diff --git a/clippy_lints/src/functions/misnamed_getters.rs b/clippy_lints/src/functions/misnamed_getters.rs index 27acad45ccf7..d6b50537c2e1 100644 --- a/clippy_lints/src/functions/misnamed_getters.rs +++ b/clippy_lints/src/functions/misnamed_getters.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; use rustc_errors::Applicability; -use rustc_hir::{intravisit::FnKind, Body, ExprKind, FnDecl, HirId, ImplicitSelfKind, Unsafety}; +use rustc_hir::{intravisit::FnKind, Body, ExprKind, FnDecl, ImplicitSelfKind, Unsafety}; use rustc_lint::LateContext; use rustc_middle::ty; use rustc_span::Span; @@ -16,7 +16,6 @@ pub fn check_fn( decl: &FnDecl<'_>, body: &Body<'_>, span: Span, - _hir_id: HirId, ) { let FnKind::Method(ref ident, sig) = kind else { return; diff --git a/clippy_lints/src/functions/mod.rs b/clippy_lints/src/functions/mod.rs index 9dbce3f889be..4399c68e130f 100644 --- a/clippy_lints/src/functions/mod.rs +++ b/clippy_lints/src/functions/mod.rs @@ -9,6 +9,7 @@ use rustc_hir as hir; use rustc_hir::intravisit; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::def_id::LocalDefId; use rustc_span::Span; declare_clippy_lint! { @@ -363,12 +364,13 @@ impl<'tcx> LateLintPass<'tcx> for Functions { decl: &'tcx hir::FnDecl<'_>, body: &'tcx hir::Body<'_>, span: Span, - hir_id: hir::HirId, + def_id: LocalDefId, ) { + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); too_many_arguments::check_fn(cx, kind, decl, span, hir_id, self.too_many_arguments_threshold); too_many_lines::check_fn(cx, kind, span, body, self.too_many_lines_threshold); - not_unsafe_ptr_arg_deref::check_fn(cx, kind, decl, body, hir_id); - misnamed_getters::check_fn(cx, kind, decl, body, span, hir_id); + not_unsafe_ptr_arg_deref::check_fn(cx, kind, decl, body, def_id); + misnamed_getters::check_fn(cx, kind, decl, body, span); } fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index d22bede36b41..29bdc46b647d 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -1,6 +1,6 @@ use rustc_ast::ast::Attribute; use rustc_errors::Applicability; -use rustc_hir::def_id::{DefIdSet, LocalDefId}; +use rustc_hir::def_id::DefIdSet; use rustc_hir::{self as hir, def::Res, QPath}; use rustc_lint::{LateContext, LintContext}; use rustc_middle::{ @@ -27,14 +27,14 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_> let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); if let Some(attr) = attr { - check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr); + check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr); } else if is_public && !is_proc_macro(cx.sess(), attrs) && !attrs.iter().any(|a| a.has_name(sym::no_mangle)) { check_must_use_candidate( cx, sig.decl, cx.tcx.hir().body(*body_id), item.span, - item.owner_id.def_id, + item.owner_id, item.span.with_hi(sig.decl.output.span().hi()), "this function could have a `#[must_use]` attribute", ); @@ -49,7 +49,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp let attrs = cx.tcx.hir().attrs(item.hir_id()); let attr = cx.tcx.get_attr(item.owner_id.to_def_id(), sym::must_use); if let Some(attr) = attr { - check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr); + check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr); } else if is_public && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.owner_id.def_id).is_none() @@ -59,7 +59,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp sig.decl, cx.tcx.hir().body(*body_id), item.span, - item.owner_id.def_id, + item.owner_id, item.span.with_hi(sig.decl.output.span().hi()), "this method could have a `#[must_use]` attribute", ); @@ -75,7 +75,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr let attrs = cx.tcx.hir().attrs(item.hir_id()); let attr = cx.tcx.get_attr(item.owner_id.to_def_id(), sym::must_use); if let Some(attr) = attr { - check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr); + check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr); } else if let hir::TraitFn::Provided(eid) = *eid { let body = cx.tcx.hir().body(eid); if attr.is_none() && is_public && !is_proc_macro(cx.sess(), attrs) { @@ -84,7 +84,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr sig.decl, body, item.span, - item.owner_id.def_id, + item.owner_id, item.span.with_hi(sig.decl.output.span().hi()), "this method could have a `#[must_use]` attribute", ); @@ -96,7 +96,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr fn check_needless_must_use( cx: &LateContext<'_>, decl: &hir::FnDecl<'_>, - item_id: hir::HirId, + item_id: hir::OwnerId, item_span: Span, fn_header_span: Span, attr: &Attribute, @@ -131,7 +131,7 @@ fn check_must_use_candidate<'tcx>( decl: &'tcx hir::FnDecl<'_>, body: &'tcx hir::Body<'_>, item_span: Span, - item_id: LocalDefId, + item_id: hir::OwnerId, fn_span: Span, msg: &str, ) { @@ -139,8 +139,8 @@ fn check_must_use_candidate<'tcx>( || mutates_static(cx, body) || in_external_macro(cx.sess(), item_span) || returns_unit(decl) - || !cx.effective_visibilities.is_exported(item_id) - || is_must_use_ty(cx, return_ty(cx, cx.tcx.hir().local_def_id_to_hir_id(item_id))) + || !cx.effective_visibilities.is_exported(item_id.def_id) + || is_must_use_ty(cx, return_ty(cx, item_id)) { return; } diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index cdb5e22e7598..a13909a2cdb8 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -17,7 +17,7 @@ pub(super) fn check_fn<'tcx>( kind: intravisit::FnKind<'tcx>, decl: &'tcx hir::FnDecl<'tcx>, body: &'tcx hir::Body<'tcx>, - hir_id: hir::HirId, + def_id: LocalDefId, ) { let unsafety = match kind { intravisit::FnKind::ItemFn(_, _, hir::FnHeader { unsafety, .. }) => unsafety, @@ -25,7 +25,7 @@ pub(super) fn check_fn<'tcx>( intravisit::FnKind::Closure => return, }; - check_raw_ptr(cx, unsafety, decl, body, cx.tcx.hir().local_def_id(hir_id)); + check_raw_ptr(cx, unsafety, decl, body, def_id) } pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 2a79b18b8299..9fb73a371b8f 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -1,11 +1,12 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::return_ty; use rustc_hir::intravisit::FnKind; -use rustc_hir::{Body, FnDecl, HirId}; +use rustc_hir::{Body, FnDecl}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, AliasTy, Clause, EarlyBinder, PredicateKind}; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::def_id::LocalDefId; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt; use rustc_trait_selection::traits::{self, FulfillmentError}; @@ -56,12 +57,12 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { decl: &'tcx FnDecl<'tcx>, _: &'tcx Body<'tcx>, _: Span, - hir_id: HirId, + fn_def_id: LocalDefId, ) { if let FnKind::Closure = kind { return; } - let ret_ty = return_ty(cx, hir_id); + let ret_ty = return_ty(cx, cx.tcx.hir().local_def_id_to_hir_id(fn_def_id).expect_owner()); if let ty::Alias(ty::Opaque, AliasTy { def_id, substs, .. }) = *ret_ty.kind() { let preds = cx.tcx.explicit_item_bounds(def_id); let mut is_future = false; @@ -78,8 +79,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap(); let span = decl.output.span(); let infcx = cx.tcx.infer_ctxt().build(); - let def_id = cx.tcx.hir().local_def_id(hir_id); - let cause = traits::ObligationCause::misc(span, def_id); + let cause = traits::ObligationCause::misc(span, fn_def_id); let send_errors = traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait); if !send_errors.is_empty() { span_lint_and_then( diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index 946d04eff6f9..372b6ead3fe4 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -11,6 +11,7 @@ use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, FnRetTy, HirId}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::def_id::LocalDefId; use rustc_span::{Span, SyntaxContext}; declare_clippy_lint! { @@ -223,7 +224,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitReturn { decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, span: Span, - _: HirId, + _: LocalDefId, ) { if (!matches!(kind, FnKind::Closure) && matches!(decl.output, FnRetTy::DefaultReturn(_))) || span.ctxt() != body.value.span.ctxt() diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index 612c3ea8fdfd..d43e5cc9b2c3 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString { if impl_item.generics.params.iter().all(|p| matches!(p.kind, GenericParamKind::Lifetime { .. })); // Check if return type is String - if is_type_lang_item(cx, return_ty(cx, impl_item.hir_id()), LangItem::String); + if is_type_lang_item(cx, return_ty(cx, impl_item.owner_id), LangItem::String); // Filters instances of to_string which are required by a trait if trait_ref_of_method(cx, impl_item.owner_id.def_id).is_none(); diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 7cf1a6b8084a..747a94ba5a6e 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -15,7 +15,6 @@ use rustc_hir::{ }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter as middle_nested_filter; -use rustc_middle::ty::TyCtxt; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; use rustc_span::source_map::Span; @@ -154,7 +153,7 @@ fn check_fn_inner<'tcx>( .filter(|param| matches!(param.kind, GenericParamKind::Type { .. })); for typ in types { - for pred in generics.bounds_for_param(cx.tcx.hir().local_def_id(typ.hir_id)) { + for pred in generics.bounds_for_param(typ.def_id) { if pred.origin == PredicateOrigin::WhereClause { // has_where_lifetimes checked that this predicate contains no lifetime. continue; @@ -251,7 +250,7 @@ fn could_use_elision<'tcx>( // level of the current item. // check named LTs - let allowed_lts = allowed_lts_from(cx.tcx, named_generics); + let allowed_lts = allowed_lts_from(named_generics); // these will collect all the lifetimes for references in arg/return types let mut input_visitor = RefVisitor::new(cx); @@ -360,11 +359,11 @@ fn could_use_elision<'tcx>( } } -fn allowed_lts_from(tcx: TyCtxt<'_>, named_generics: &[GenericParam<'_>]) -> FxHashSet { +fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxHashSet { let mut allowed_lts = FxHashSet::default(); for par in named_generics.iter() { if let GenericParamKind::Lifetime { .. } = par.kind { - allowed_lts.insert(RefLt::Named(tcx.hir().local_def_id(par.hir_id))); + allowed_lts.insert(RefLt::Named(par.def_id)); } } allowed_lts.insert(RefLt::Unnamed); @@ -516,7 +515,7 @@ fn has_where_lifetimes<'tcx>(cx: &LateContext<'tcx>, generics: &'tcx Generics<'_ return true; } // if the bounds define new lifetimes, they are fine to occur - let allowed_lts = allowed_lts_from(cx.tcx, pred.bound_generic_params); + let allowed_lts = allowed_lts_from(pred.bound_generic_params); // now walk the bounds for bound in pred.bounds.iter() { walk_param_bound(&mut visitor, bound); diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 63212beaa63d..3778eb4c732d 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -6,10 +6,11 @@ use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{ AsyncGeneratorKind, Block, Body, Closure, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound, - HirId, ItemKind, LifetimeName, Term, TraitRef, Ty, TyKind, TypeBindingKind, + ItemKind, LifetimeName, Term, TraitRef, Ty, TyKind, TypeBindingKind, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::def_id::LocalDefId; use rustc_span::{sym, Span}; declare_clippy_lint! { @@ -45,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn { decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, span: Span, - _: HirId, + _: LocalDefId, ) { if_chain! { if let Some(header) = kind.header(); diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index bca193be9e71..7dfa155c5c35 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -157,11 +157,10 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum { && def.variants.len() > 1 { let mut iter = def.variants.iter().filter_map(|v| { - let id = cx.tcx.hir().local_def_id(v.hir_id); (matches!(v.data, hir::VariantData::Unit(..)) && v.ident.as_str().starts_with('_') && is_doc_hidden(cx.tcx.hir().attrs(v.hir_id))) - .then_some((id, v.span)) + .then_some((v.def_id, v.span)) }); if let Some((id, span)) = iter.next() && iter.next().is_none() diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 0c465e5daf9f..fb94dfa5980b 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3412,7 +3412,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { } if let hir::ImplItemKind::Fn(_, _) = impl_item.kind { - let ret_ty = return_ty(cx, impl_item.hir_id()); + let ret_ty = return_ty(cx, impl_item.owner_id); if contains_ty_adt_constructor_opaque(cx, ret_ty, self_ty) { return; @@ -3460,7 +3460,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if_chain! { if item.ident.name == sym::new; if let TraitItemKind::Fn(_, _) = item.kind; - let ret_ty = return_ty(cx, item.hir_id()); + let ret_ty = return_ty(cx, item.owner_id); let self_ty = TraitRef::identity(cx.tcx, item.owner_id.to_def_id()) .self_ty() .skip_binder(); diff --git a/clippy_lints/src/methods/suspicious_map.rs b/clippy_lints/src/methods/suspicious_map.rs index 2ac0786b37b1..6050226434f2 100644 --- a/clippy_lints/src/methods/suspicious_map.rs +++ b/clippy_lints/src/methods/suspicious_map.rs @@ -12,9 +12,8 @@ pub fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, count_recv: &hir::Expr< if_chain! { if is_trait_method(cx, count_recv, sym::Iterator); let closure = expr_or_init(cx, map_arg); - if let Some(def_id) = cx.tcx.hir().opt_local_def_id(closure.hir_id); - if let Some(body_id) = cx.tcx.hir().maybe_body_owned_by(def_id); - let closure_body = cx.tcx.hir().body(body_id); + if let hir::ExprKind::Closure(closure) = closure.kind; + let closure_body = cx.tcx.hir().body(closure.body); if !cx.typeck_results().expr_ty(closure_body.value).is_unit(); then { if let Some(map_mutated_vars) = mutated_variables(closure_body.value, cx) { diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 12e053cb2134..4e5af1c7c712 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -368,10 +368,9 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< Node::Block(..) => continue, Node::Item(item) => { if let ItemKind::Fn(_, _, body_id) = &item.kind - && let output_ty = return_ty(cx, item.hir_id()) - && let local_def_id = cx.tcx.hir().local_def_id(item.hir_id()) - && Inherited::build(cx.tcx, local_def_id).enter(|inherited| { - let fn_ctxt = FnCtxt::new(inherited, cx.param_env, local_def_id); + && let output_ty = return_ty(cx, item.owner_id) + && Inherited::build(cx.tcx, item.owner_id.def_id).enter(|inherited| { + let fn_ctxt = FnCtxt::new(inherited, cx.param_env, item.owner_id.def_id); fn_ctxt.can_coerce(ty, output_ty) }) { if has_lifetime(output_ty) && has_lifetime(ty) { diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 9f4beb92b9d2..0705029a613b 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -4,12 +4,13 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{ - self as hir, def, BinOpKind, BindingAnnotation, Body, ByRef, Expr, ExprKind, FnDecl, HirId, Mutability, PatKind, - Stmt, StmtKind, TyKind, + self as hir, def, BinOpKind, BindingAnnotation, Body, ByRef, Expr, ExprKind, FnDecl, Mutability, PatKind, Stmt, + StmtKind, TyKind, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::def_id::LocalDefId; use rustc_span::hygiene::DesugaringKind; use rustc_span::source_map::{ExpnKind, Span}; @@ -151,7 +152,7 @@ impl<'tcx> LateLintPass<'tcx> for LintPass { decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, span: Span, - _: HirId, + _: LocalDefId, ) { if let FnKind::Closure = k { // Does not apply to closures diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 5bc04bc17fb4..87bd007a26a2 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -6,11 +6,12 @@ use clippy_utils::{fn_has_unsatisfiable_preds, is_entrypoint_fn, is_from_proc_ma use rustc_hir as hir; use rustc_hir::def_id::CRATE_DEF_ID; use rustc_hir::intravisit::FnKind; -use rustc_hir::{Body, Constness, FnDecl, GenericParamKind, HirId}; +use rustc_hir::{Body, Constness, FnDecl, GenericParamKind}; use rustc_hir_analysis::hir_ty_to_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::def_id::LocalDefId; use rustc_span::Span; declare_clippy_lint! { @@ -91,14 +92,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { _: &FnDecl<'_>, body: &Body<'tcx>, span: Span, - hir_id: HirId, + def_id: LocalDefId, ) { if !self.msrv.meets(msrvs::CONST_IF_MATCH) { return; } - let def_id = cx.tcx.hir().local_def_id(hir_id); - if in_external_macro(cx.tcx.sess, span) || is_entrypoint_fn(cx, def_id.to_def_id()) { return; } @@ -132,6 +131,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { FnKind::Closure => return, } + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); + // Const fns are not allowed as methods in a trait. { let parent = cx.tcx.hir().get_parent_item(hir_id).def_id; diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 16947cd5e354..5f7aac21e6eb 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -6,6 +6,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::TypeVisitable; use rustc_middle::ty::{Adt, Array, Ref, Slice, Tuple, Ty}; use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::def_id::LocalDefId; use rustc_span::source_map::Span; use rustc_span::symbol::sym; use std::iter; @@ -102,21 +103,21 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) { if let hir::ItemKind::Fn(ref sig, ..) = item.kind { - self.check_sig(cx, item.hir_id(), sig.decl); + self.check_sig(cx, item.owner_id.def_id, sig.decl); } } fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'tcx>) { if let hir::ImplItemKind::Fn(ref sig, ..) = item.kind { if trait_ref_of_method(cx, item.owner_id.def_id).is_none() { - self.check_sig(cx, item.hir_id(), sig.decl); + self.check_sig(cx, item.owner_id.def_id, sig.decl); } } } fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'tcx>) { if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { - self.check_sig(cx, item.hir_id(), sig.decl); + self.check_sig(cx, item.owner_id.def_id, sig.decl); } } @@ -136,8 +137,7 @@ impl MutableKeyType { } } - fn check_sig(&self, cx: &LateContext<'_>, item_hir_id: hir::HirId, decl: &hir::FnDecl<'_>) { - let fn_def_id = cx.tcx.hir().local_def_id(item_hir_id); + fn check_sig(&self, cx: &LateContext<'_>, fn_def_id: LocalDefId, decl: &hir::FnDecl<'_>) { let fn_sig = cx.tcx.fn_sig(fn_def_id).subst_identity(); for (hir_ty, ty) in iter::zip(decl.inputs, fn_sig.inputs().skip_binder()) { self.check_ty_(cx, hir_ty.span, *ty); diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 25ec9082c707..996ea6ed7231 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -20,6 +20,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::{self, TypeVisitable}; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::def_id::LocalDefId; use rustc_span::symbol::kw; use rustc_span::{sym, Span}; use rustc_target::spec::abi::Abi; @@ -82,12 +83,14 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, span: Span, - hir_id: HirId, + fn_def_id: LocalDefId, ) { if span.from_expansion() { return; } + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(fn_def_id); + match kind { FnKind::ItemFn(.., header) => { let attrs = cx.tcx.hir().attrs(hir_id); @@ -119,8 +122,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { let sized_trait = need!(cx.tcx.lang_items().sized_trait()); - let fn_def_id = cx.tcx.hir().local_def_id(hir_id); - let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds().iter()) .filter(|p| !p.is_global()) .filter_map(|obligation| { diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 54a3c82b713d..faf9ec61ec50 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { } if let hir::ImplItemKind::Fn(ref sig, _) = impl_item.kind { let name = impl_item.ident.name; - let id = impl_item.hir_id(); + let id = impl_item.owner_id; if sig.header.constness == hir::Constness::Const { // can't be implemented by default return; @@ -97,7 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { if sig.decl.inputs.is_empty(); if name == sym::new; if cx.effective_visibilities.is_reachable(impl_item.owner_id.def_id); - let self_def_id = cx.tcx.hir().get_parent_item(id); + let self_def_id = cx.tcx.hir().get_parent_item(id.into()); let self_ty = cx.tcx.type_of(self_def_id); if self_ty == return_ty(cx, id); if let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default); @@ -133,7 +133,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { span_lint_hir_and_then( cx, NEW_WITHOUT_DEFAULT, - id, + id.into(), impl_item.span, &format!( "you should consider adding a `Default` implementation for `{self_type_snip}`" diff --git a/clippy_lints/src/operators/arithmetic_side_effects.rs b/clippy_lints/src/operators/arithmetic_side_effects.rs index cff82b875f11..d592f6e814c1 100644 --- a/clippy_lints/src/operators/arithmetic_side_effects.rs +++ b/clippy_lints/src/operators/arithmetic_side_effects.rs @@ -209,7 +209,8 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects { fn check_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { let body_owner = cx.tcx.hir().body_owner(body.id()); - let body_owner_def_id = cx.tcx.hir().local_def_id(body_owner); + let body_owner_def_id = cx.tcx.hir().body_owner_def_id(body.id()); + let body_owner_kind = cx.tcx.hir().body_owner_kind(body_owner_def_id); if let hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) = body_owner_kind { let body_span = cx.tcx.hir().span_with_body(body_owner); diff --git a/clippy_lints/src/operators/numeric_arithmetic.rs b/clippy_lints/src/operators/numeric_arithmetic.rs index 0830a106f556..777395f452c9 100644 --- a/clippy_lints/src/operators/numeric_arithmetic.rs +++ b/clippy_lints/src/operators/numeric_arithmetic.rs @@ -96,7 +96,7 @@ impl Context { pub fn enter_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { let body_owner = cx.tcx.hir().body_owner(body.id()); - let body_owner_def_id = cx.tcx.hir().local_def_id(body_owner); + let body_owner_def_id = cx.tcx.hir().body_owner_def_id(body.id()); match cx.tcx.hir().body_owner_kind(body_owner_def_id) { hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const => { diff --git a/clippy_lints/src/panic_in_result_fn.rs b/clippy_lints/src/panic_in_result_fn.rs index efec12489a9b..849cd03dd7bf 100644 --- a/clippy_lints/src/panic_in_result_fn.rs +++ b/clippy_lints/src/panic_in_result_fn.rs @@ -8,6 +8,7 @@ use rustc_hir as hir; use rustc_hir::intravisit::FnKind; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::def_id::LocalDefId; use rustc_span::{sym, Span}; declare_clippy_lint! { @@ -49,9 +50,13 @@ impl<'tcx> LateLintPass<'tcx> for PanicInResultFn { _: &'tcx hir::FnDecl<'tcx>, body: &'tcx hir::Body<'tcx>, span: Span, - hir_id: hir::HirId, + def_id: LocalDefId, ) { - if !matches!(fn_kind, FnKind::Closure) && is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::Result) { + if matches!(fn_kind, FnKind::Closure) { + return; + } + let owner = cx.tcx.hir().local_def_id_to_hir_id(def_id).expect_owner(); + if is_type_diagnostic_item(cx, return_ty(cx, owner), sym::Result) { lint_impl_body(cx, span, body); } } diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 954eeba751ff..0d78c3048ba1 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -12,7 +12,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::intravisit::FnKind; -use rustc_hir::{BindingAnnotation, Body, FnDecl, HirId, Impl, ItemKind, MutTy, Mutability, Node, PatKind}; +use rustc_hir::{BindingAnnotation, Body, FnDecl, Impl, ItemKind, MutTy, Mutability, Node, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, PointerCast}; use rustc_middle::ty::layout::LayoutOf; @@ -272,12 +272,13 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { decl: &'tcx FnDecl<'_>, _body: &'tcx Body<'_>, span: Span, - hir_id: HirId, + def_id: LocalDefId, ) { if span.from_expansion() { return; } + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); match kind { FnKind::ItemFn(.., header) => { if header.abi != Abi::Rust { @@ -308,6 +309,6 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { } } - self.check_poly_fn(cx, cx.tcx.hir().local_def_id(hir_id), decl, Some(span)); + self.check_poly_fn(cx, def_id, decl, Some(span)); } } diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index 97b5a4ce3641..9f98195d311f 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -1,11 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_help; -use rustc_hir::{ - intravisit, Body, Expr, ExprKind, FnDecl, HirId, Let, LocalSource, Mutability, Pat, PatKind, Stmt, StmtKind, -}; +use rustc_hir::{intravisit, Body, Expr, ExprKind, FnDecl, Let, LocalSource, Mutability, Pat, PatKind, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::def_id::LocalDefId; use rustc_span::source_map::Span; declare_clippy_lint! { @@ -116,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch { _: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, _: Span, - _: HirId, + _: LocalDefId, ) { for param in body.params { apply_lint(cx, param.pat, DerefPossible::Impossible); diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index c1677fb3da1c..944a33cc3e53 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -6,11 +6,12 @@ use clippy_utils::{fn_has_unsatisfiable_preds, match_def_path, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; -use rustc_hir::{def_id, Body, FnDecl, HirId, LangItem}; +use rustc_hir::{def_id, Body, FnDecl, LangItem}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir; use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::def_id::LocalDefId; use rustc_span::source_map::{BytePos, Span}; use rustc_span::sym; @@ -69,12 +70,10 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone { cx: &LateContext<'tcx>, _: FnKind<'tcx>, _: &'tcx FnDecl<'_>, - body: &'tcx Body<'_>, + _: &'tcx Body<'_>, _: Span, - _: HirId, + def_id: LocalDefId, ) { - let def_id = cx.tcx.hir().body_owner_def_id(body.id()); - // Building MIR for `fn`s with unsatisfiable preds results in ICE. if fn_has_unsatisfiable_preds(cx, def_id.to_def_id()) { return; diff --git a/clippy_lints/src/return_self_not_must_use.rs b/clippy_lints/src/return_self_not_must_use.rs index b77faf7322bd..8c39b4fc5691 100644 --- a/clippy_lints/src/return_self_not_must_use.rs +++ b/clippy_lints/src/return_self_not_must_use.rs @@ -3,7 +3,7 @@ use clippy_utils::ty::is_must_use_ty; use clippy_utils::{nth_arg, return_ty}; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::FnKind; -use rustc_hir::{Body, FnDecl, HirId, TraitItem, TraitItemKind}; +use rustc_hir::{Body, FnDecl, OwnerId, TraitItem, TraitItemKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -68,7 +68,7 @@ declare_clippy_lint! { declare_lint_pass!(ReturnSelfNotMustUse => [RETURN_SELF_NOT_MUST_USE]); -fn check_method(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_def: LocalDefId, span: Span, hir_id: HirId) { +fn check_method(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_def: LocalDefId, span: Span, owner_id: OwnerId) { if_chain! { // If it comes from an external macro, better ignore it. if !in_external_macro(cx.sess(), span); @@ -76,10 +76,10 @@ fn check_method(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_def: LocalDefId, spa // We only show this warning for public exported methods. if cx.effective_visibilities.is_exported(fn_def); // We don't want to emit this lint if the `#[must_use]` attribute is already there. - if !cx.tcx.hir().attrs(hir_id).iter().any(|attr| attr.has_name(sym::must_use)); + if !cx.tcx.hir().attrs(owner_id.into()).iter().any(|attr| attr.has_name(sym::must_use)); if cx.tcx.visibility(fn_def.to_def_id()).is_public(); - let ret_ty = return_ty(cx, hir_id); - let self_arg = nth_arg(cx, hir_id, 0); + let ret_ty = return_ty(cx, owner_id.into()); + let self_arg = nth_arg(cx, owner_id.into(), 0); // If `Self` has the same type as the returned type, then we want to warn. // // For this check, we don't want to remove the reference on the returned type because if @@ -109,26 +109,26 @@ impl<'tcx> LateLintPass<'tcx> for ReturnSelfNotMustUse { decl: &'tcx FnDecl<'tcx>, _: &'tcx Body<'tcx>, span: Span, - hir_id: HirId, + fn_def: LocalDefId, ) { if_chain! { // We are only interested in methods, not in functions or associated functions. if matches!(kind, FnKind::Method(_, _)); - if let Some(fn_def) = cx.tcx.hir().opt_local_def_id(hir_id); if let Some(impl_def) = cx.tcx.impl_of_method(fn_def.to_def_id()); // We don't want this method to be te implementation of a trait because the // `#[must_use]` should be put on the trait definition directly. if cx.tcx.trait_id_of_impl(impl_def).is_none(); then { - check_method(cx, decl, fn_def, span, hir_id); + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(fn_def); + check_method(cx, decl, fn_def, span, hir_id.expect_owner()); } } } fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'tcx>) { if let TraitItemKind::Fn(ref sig, _) = item.kind { - check_method(cx, sig.decl, item.owner_id.def_id, item.span, item.hir_id()); + check_method(cx, sig.decl, item.owner_id.def_id, item.span, item.owner_id); } } } diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index a3e0811700be..84a0c6b95585 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -6,11 +6,12 @@ use core::ops::ControlFlow; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; -use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, HirId, LangItem, MatchSource, PatKind, QPath, StmtKind}; +use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, LangItem, MatchSource, PatKind, QPath, StmtKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::subst::GenericArgKind; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::def_id::LocalDefId; use rustc_span::source_map::Span; use rustc_span::{BytePos, Pos}; @@ -152,7 +153,7 @@ impl<'tcx> LateLintPass<'tcx> for Return { _: &'tcx FnDecl<'tcx>, body: &'tcx Body<'tcx>, sp: Span, - _: HirId, + _: LocalDefId, ) { match kind { FnKind::Closure => { diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index 71b387c66a33..3ce030cd721a 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(parent); let self_ty = cx.tcx.type_of(item.owner_id); - let ret_ty = return_ty(cx, impl_item.hir_id()); + let ret_ty = return_ty(cx, impl_item.owner_id); // Do not check trait impls if matches!(item.kind, ItemKind::Impl(Impl { of_trait: Some(_), .. })) { diff --git a/clippy_lints/src/trailing_empty_array.rs b/clippy_lints/src/trailing_empty_array.rs index 63b326048a48..de0c5d56e415 100644 --- a/clippy_lints/src/trailing_empty_array.rs +++ b/clippy_lints/src/trailing_empty_array.rs @@ -61,8 +61,7 @@ fn is_struct_with_trailing_zero_sized_array(cx: &LateContext<'_>, item: &Item<'_ if let rustc_hir::TyKind::Array(_, rustc_hir::ArrayLen::Body(length)) = last_field.ty.kind; // Then check if that that array zero-sized - let length_ldid = cx.tcx.hir().local_def_id(length.hir_id); - let length = Const::from_anon_const(cx.tcx, length_ldid); + let length = Const::from_anon_const(cx.tcx, length.def_id); let length = length.try_eval_usize(cx.tcx, cx.param_env); if let Some(length) = length; then { diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 229478b7ce3c..585e2075fa90 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -12,11 +12,12 @@ mod vec_box; use rustc_hir as hir; use rustc_hir::intravisit::FnKind; use rustc_hir::{ - Body, FnDecl, FnRetTy, GenericArg, HirId, ImplItem, ImplItemKind, Item, ItemKind, Local, MutTy, QPath, TraitItem, + Body, FnDecl, FnRetTy, GenericArg, ImplItem, ImplItemKind, Item, ItemKind, Local, MutTy, QPath, TraitItem, TraitItemKind, TyKind, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::def_id::LocalDefId; use rustc_span::source_map::Span; declare_clippy_lint! { @@ -311,15 +312,27 @@ pub struct Types { impl_lint_pass!(Types => [BOX_COLLECTION, VEC_BOX, OPTION_OPTION, LINKEDLIST, BORROWED_BOX, REDUNDANT_ALLOCATION, RC_BUFFER, RC_MUTEX, TYPE_COMPLEXITY]); impl<'tcx> LateLintPass<'tcx> for Types { - fn check_fn(&mut self, cx: &LateContext<'_>, _: FnKind<'_>, decl: &FnDecl<'_>, _: &Body<'_>, _: Span, id: HirId) { - let is_in_trait_impl = - if let Some(hir::Node::Item(item)) = cx.tcx.hir().find_by_def_id(cx.tcx.hir().get_parent_item(id).def_id) { - matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) - } else { - false - }; + fn check_fn( + &mut self, + cx: &LateContext<'_>, + _: FnKind<'_>, + decl: &FnDecl<'_>, + _: &Body<'_>, + _: Span, + def_id: LocalDefId, + ) { + let is_in_trait_impl = if let Some(hir::Node::Item(item)) = cx.tcx.hir().find_by_def_id( + cx.tcx + .hir() + .get_parent_item(cx.tcx.hir().local_def_id_to_hir_id(def_id)) + .def_id, + ) { + matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) + } else { + false + }; - let is_exported = cx.effective_visibilities.is_exported(cx.tcx.hir().local_def_id(id)); + let is_exported = cx.effective_visibilities.is_exported(def_id); self.check_fn_decl( cx, @@ -381,7 +394,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) { let is_exported = cx .effective_visibilities - .is_exported(cx.tcx.hir().local_def_id(field.hir_id)); + .is_exported(field.def_id); self.check_ty( cx, diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index 84ec0d0fb1cf..8b0e0ce5a300 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -5,10 +5,11 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::LangItem::{OptionSome, ResultOk}; -use rustc_hir::{Body, ExprKind, FnDecl, HirId, Impl, ItemKind, Node}; +use rustc_hir::{Body, ExprKind, FnDecl, Impl, ItemKind, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::def_id::LocalDefId; use rustc_span::symbol::sym; use rustc_span::Span; @@ -77,12 +78,11 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { fn_decl: &FnDecl<'tcx>, body: &Body<'tcx>, span: Span, - hir_id: HirId, + def_id: LocalDefId, ) { // Abort if public function/method or closure. match fn_kind { FnKind::ItemFn(..) | FnKind::Method(..) => { - let def_id = cx.tcx.hir().local_def_id(hir_id); if self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(def_id) { return; } @@ -91,6 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { } // Abort if the method is implementing a trait or of it a trait method. + let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) { if matches!( item.kind, @@ -101,17 +102,18 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { } // Get the wrapper and inner types, if can't, abort. - let (return_type_label, lang_item, inner_type) = if let ty::Adt(adt_def, subst) = return_ty(cx, hir_id).kind() { - if cx.tcx.is_diagnostic_item(sym::Option, adt_def.did()) { - ("Option", OptionSome, subst.type_at(0)) - } else if cx.tcx.is_diagnostic_item(sym::Result, adt_def.did()) { - ("Result", ResultOk, subst.type_at(0)) + let (return_type_label, lang_item, inner_type) = + if let ty::Adt(adt_def, subst) = return_ty(cx, hir_id.expect_owner()).kind() { + if cx.tcx.is_diagnostic_item(sym::Option, adt_def.did()) { + ("Option", OptionSome, subst.type_at(0)) + } else if cx.tcx.is_diagnostic_item(sym::Result, adt_def.did()) { + ("Result", ResultOk, subst.type_at(0)) + } else { + return; + } } else { return; - } - } else { - return; - }; + }; // Check if all return expression respect the following condition and collect them. let mut suggs = Vec::new(); diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index 3538bef6e061..55651a28be92 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -1,9 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, Visitor}; -use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, YieldSource}; +use rustc_hir::{Body, Expr, ExprKind, FnDecl, YieldSource}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::def_id::LocalDefId; use rustc_span::Span; declare_clippy_lint! { @@ -66,11 +67,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync { fn_decl: &'tcx FnDecl<'tcx>, body: &Body<'tcx>, span: Span, - hir_id: HirId, + def_id: LocalDefId, ) { if !span.from_expansion() && fn_kind.asyncness().is_async() { let mut visitor = AsyncFnVisitor { cx, found_await: false }; - walk_fn(&mut visitor, fn_kind, fn_decl, body.id(), hir_id); + walk_fn(&mut visitor, fn_kind, fn_decl, body.id(), def_id); if !visitor.found_await { span_lint_and_help( cx, diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index ea878043c04e..377d3fb6f4e1 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -11,6 +11,7 @@ use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::Ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::def_id::LocalDefId; use rustc_span::source_map::Span; use rustc_span::sym; @@ -312,7 +313,7 @@ impl<'tcx> LateLintPass<'tcx> for Unwrap { decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, span: Span, - fn_id: HirId, + fn_id: LocalDefId, ) { if span.from_expansion() { return; diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs index f3611d174340..3a1845425a25 100644 --- a/clippy_lints/src/unwrap_in_result.rs +++ b/clippy_lints/src/unwrap_in_result.rs @@ -64,8 +64,8 @@ impl<'tcx> LateLintPass<'tcx> for UnwrapInResult { // first check if it's a method or function if let hir::ImplItemKind::Fn(ref _signature, _) = impl_item.kind; // checking if its return type is `result` or `option` - if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::Result) - || is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::Option); + if is_type_diagnostic_item(cx, return_ty(cx, impl_item.owner_id), sym::Result) + || is_type_diagnostic_item(cx, return_ty(cx, impl_item.owner_id), sym::Option); then { lint_impl_body(cx, impl_item.span, impl_item); } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index e2965146cfe6..81c1a052b586 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1578,8 +1578,7 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option { } /// Convenience function to get the return type of a function. -pub fn return_ty<'tcx>(cx: &LateContext<'tcx>, fn_item: hir::HirId) -> Ty<'tcx> { - let fn_def_id = cx.tcx.hir().local_def_id(fn_item); +pub fn return_ty<'tcx>(cx: &LateContext<'tcx>, fn_def_id: hir::OwnerId) -> Ty<'tcx> { let ret_ty = cx.tcx.fn_sig(fn_def_id).subst_identity().output(); cx.tcx.erase_late_bound_regions(ret_ty) } From 31ca564b7bf2c946f6db4923e1313ec9bd584c31 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 5 Nov 2022 15:33:58 +0000 Subject: [PATCH 0740/1222] Remove `HirId -> LocalDefId` map from HIR. --- clippy_lints/src/dereference.rs | 6 +++--- clippy_lints/src/manual_non_exhaustive.rs | 2 +- clippy_lints/src/methods/suspicious_map.rs | 3 +-- clippy_utils/src/lib.rs | 8 +++----- clippy_utils/src/sugg.rs | 6 ++---- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 8e921839e8b2..6c333afacc64 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -778,20 +778,20 @@ fn walk_parents<'tcx>( Node::Expr(parent) if parent.span.ctxt() == ctxt => match parent.kind { ExprKind::Ret(_) => { - let owner_id = cx.tcx.hir().body_owner(cx.enclosing_body.unwrap()); + let owner_id = cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()); Some( if let Node::Expr( closure_expr @ Expr { kind: ExprKind::Closure(closure), .. }, - ) = cx.tcx.hir().get(owner_id) + ) = cx.tcx.hir().get_by_def_id(owner_id) { closure_result_position(cx, closure, cx.typeck_results().expr_ty(closure_expr), precedence) } else { let output = cx .tcx - .erase_late_bound_regions(cx.tcx.fn_sig(cx.tcx.hir().local_def_id(owner_id)).subst_identity().output()); + .erase_late_bound_regions(cx.tcx.fn_sig(owner_id).subst_identity().output()); ty_auto_deref_stability(cx, output, precedence).position_for_result(cx) }, ) diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 7dfa155c5c35..9a84068d4487 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -157,7 +157,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum { && def.variants.len() > 1 { let mut iter = def.variants.iter().filter_map(|v| { - (matches!(v.data, hir::VariantData::Unit(..)) + (matches!(v.data, hir::VariantData::Unit(_, _)) && v.ident.as_str().starts_with('_') && is_doc_hidden(cx.tcx.hir().attrs(v.hir_id))) .then_some((v.def_id, v.span)) diff --git a/clippy_lints/src/methods/suspicious_map.rs b/clippy_lints/src/methods/suspicious_map.rs index 6050226434f2..0dc7fe2a2c5a 100644 --- a/clippy_lints/src/methods/suspicious_map.rs +++ b/clippy_lints/src/methods/suspicious_map.rs @@ -11,8 +11,7 @@ use super::SUSPICIOUS_MAP; pub fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, count_recv: &hir::Expr<'_>, map_arg: &hir::Expr<'_>) { if_chain! { if is_trait_method(cx, count_recv, sym::Iterator); - let closure = expr_or_init(cx, map_arg); - if let hir::ExprKind::Closure(closure) = closure.kind; + if let hir::ExprKind::Closure(closure) = expr_or_init(cx, map_arg).kind; let closure_body = cx.tcx.hir().body(closure.body); if !cx.typeck_results().expr_ty(closure_body.value).is_unit(); then { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 81c1a052b586..0db3b93e7cc9 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1119,9 +1119,8 @@ pub fn can_move_expr_to_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<' self.captures.entry(l).and_modify(|e| *e |= cap).or_insert(cap); } }, - ExprKind::Closure { .. } => { - let closure_id = self.cx.tcx.hir().local_def_id(e.hir_id); - for capture in self.cx.typeck_results().closure_min_captures_flattened(closure_id) { + ExprKind::Closure(closure) => { + for capture in self.cx.typeck_results().closure_min_captures_flattened(closure.def_id) { let local_id = match capture.place.base { PlaceBase::Local(id) => id, PlaceBase::Upvar(var) => var.var_path.hir_id, @@ -1584,8 +1583,7 @@ pub fn return_ty<'tcx>(cx: &LateContext<'tcx>, fn_def_id: hir::OwnerId) -> Ty<'t } /// Convenience function to get the nth argument type of a function. -pub fn nth_arg<'tcx>(cx: &LateContext<'tcx>, fn_item: hir::HirId, nth: usize) -> Ty<'tcx> { - let fn_def_id = cx.tcx.hir().local_def_id(fn_item); +pub fn nth_arg<'tcx>(cx: &LateContext<'tcx>, fn_def_id: hir::OwnerId, nth: usize) -> Ty<'tcx> { let arg = cx.tcx.fn_sig(fn_def_id).subst_identity().input(nth); cx.tcx.erase_late_bound_regions(arg) } diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 8d767f9d44d3..b8c87aa5e1e4 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -809,7 +809,7 @@ pub struct DerefClosure { /// /// note: this only works on single line immutable closures with exactly one input parameter. pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Option { - if let hir::ExprKind::Closure(&Closure { fn_decl, body, .. }) = closure.kind { + if let hir::ExprKind::Closure(&Closure { fn_decl, def_id, body, .. }) = closure.kind { let closure_body = cx.tcx.hir().body(body); // is closure arg a type annotated double reference (i.e.: `|x: &&i32| ...`) // a type annotation is present if param `kind` is different from `TyKind::Infer` @@ -829,10 +829,8 @@ pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Opti applicability: Applicability::MachineApplicable, }; - let fn_def_id = cx.tcx.hir().local_def_id(closure.hir_id); let infcx = cx.tcx.infer_ctxt().build(); - ExprUseVisitor::new(&mut visitor, &infcx, fn_def_id, cx.param_env, cx.typeck_results()) - .consume_body(closure_body); + ExprUseVisitor::new(&mut visitor, &infcx, def_id, cx.param_env, cx.typeck_results()).consume_body(closure_body); if !visitor.suggestion_start.is_empty() { return Some(DerefClosure { From 5e392c286e47839069fb1bfb0227b500fe1e6fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 2 Jan 2023 18:00:33 -0800 Subject: [PATCH 0741/1222] Modify primary span label for E0308 The previous output was unintuitive to users. --- tests/ui/track-diagnostics.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/track-diagnostics.stderr b/tests/ui/track-diagnostics.stderr index ec3031862531..39418d359288 100644 --- a/tests/ui/track-diagnostics.stderr +++ b/tests/ui/track-diagnostics.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/track-diagnostics.rs:LL:CC | LL | const S: A = B; - | ^ expected struct `A`, found struct `B` + | ^ expected `A`, found `B` -Ztrack-diagnostics: created at compiler/rustc_infer/src/infer/error_reporting/mod.rs:LL:CC error: aborting due to previous error From a87bd692ab3b36e9082910199de9f3e4a258490f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 9 Feb 2023 10:16:00 +0000 Subject: [PATCH 0742/1222] Introduce `-Zterminal-urls` to use OSC8 for error codes Terminals supporting the OSC8 Hyperlink Extension can support inline anchors where the text is user defineable but clicking on it opens a browser to a specified URLs, just like `` does in HTML. https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda --- clippy_lints/src/doc.rs | 3 ++- src/driver.rs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 127201b72e27..0b31e20fc87c 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -11,7 +11,7 @@ use rustc_ast::token::CommentKind; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; use rustc_errors::emitter::EmitterWriter; -use rustc_errors::{Applicability, Handler, SuggestionStyle}; +use rustc_errors::{Applicability, Handler, SuggestionStyle, TerminalUrl}; use rustc_hir as hir; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{AnonConst, Expr}; @@ -717,6 +717,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { None, false, false, + TerminalUrl::No, ); let handler = Handler::with_emitter(false, None, Box::new(emitter)); let sess = ParseSess::with_span_handler(handler, sm); diff --git a/src/driver.rs b/src/driver.rs index d521e8d88398..e45835efe746 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -220,6 +220,7 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { None, false, false, + rustc_errors::TerminalUrl::No, )); let handler = rustc_errors::Handler::with_emitter(true, None, emitter); From 8ff424a40faceb66c899f41d4eaae415e6ac715d Mon Sep 17 00:00:00 2001 From: Boxy Date: Fri, 10 Feb 2023 13:43:29 +0000 Subject: [PATCH 0743/1222] add `AliasEq` to `PredicateKind` --- clippy_utils/src/qualify_min_const_fn.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 727058780752..26b1d0197499 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -36,6 +36,7 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv) | ty::PredicateKind::ConstEvaluatable(..) | ty::PredicateKind::ConstEquate(..) | ty::PredicateKind::TypeWellFormedFromEnv(..) => continue, + ty::PredicateKind::AliasEq(..) => panic!("alias eq predicate on function: {predicate:#?}"), ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {predicate:#?}"), ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {predicate:#?}"), ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {predicate:#?}"), From 7b563587f5801f32bd4266a28452ceba550dd502 Mon Sep 17 00:00:00 2001 From: Alan Egerton Date: Thu, 9 Feb 2023 14:02:47 +0000 Subject: [PATCH 0744/1222] Alias folding/visiting traits instead of re-export --- clippy_utils/src/mir/possible_borrower.rs | 2 +- clippy_utils/src/ty.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/mir/possible_borrower.rs b/clippy_utils/src/mir/possible_borrower.rs index 5836eb73bd94..fd9c83759a9c 100644 --- a/clippy_utils/src/mir/possible_borrower.rs +++ b/clippy_utils/src/mir/possible_borrower.rs @@ -4,7 +4,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_index::bit_set::{BitSet, HybridBitSet}; use rustc_lint::LateContext; use rustc_middle::mir::{self, visit::Visitor as _, Mutability}; -use rustc_middle::ty::{self, visit::TypeVisitor}; +use rustc_middle::ty::{self, visit::ir::TypeVisitor}; use rustc_mir_dataflow::{impls::MaybeStorageLive, Analysis, ResultsCursor}; use std::borrow::Cow; use std::ops::ControlFlow; diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index c48d27b05f04..1635b75f718f 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -17,7 +17,7 @@ use rustc_lint::LateContext; use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::ty::{ self, AdtDef, AliasTy, AssocKind, Binder, BoundRegion, DefIdTree, FnSig, IntTy, List, ParamEnv, Predicate, - PredicateKind, Region, RegionKind, SubstsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy, + PredicateKind, Region, RegionKind, SubstsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, ir::TypeVisitor, UintTy, VariantDef, VariantDiscr, }; use rustc_middle::ty::{GenericArg, GenericArgKind}; From b993f89c0e86aba8475042549b942f4b2aad2a43 Mon Sep 17 00:00:00 2001 From: Alan Egerton Date: Thu, 9 Feb 2023 19:38:07 +0000 Subject: [PATCH 0745/1222] Make visiting traits generic over the Interner --- clippy_utils/src/mir/possible_borrower.rs | 4 ++-- clippy_utils/src/ty.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_utils/src/mir/possible_borrower.rs b/clippy_utils/src/mir/possible_borrower.rs index fd9c83759a9c..e9dc7351b58e 100644 --- a/clippy_utils/src/mir/possible_borrower.rs +++ b/clippy_utils/src/mir/possible_borrower.rs @@ -4,7 +4,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_index::bit_set::{BitSet, HybridBitSet}; use rustc_lint::LateContext; use rustc_middle::mir::{self, visit::Visitor as _, Mutability}; -use rustc_middle::ty::{self, visit::ir::TypeVisitor}; +use rustc_middle::ty::{self, visit::ir::TypeVisitor, TyCtxt}; use rustc_mir_dataflow::{impls::MaybeStorageLive, Analysis, ResultsCursor}; use std::borrow::Cow; use std::ops::ControlFlow; @@ -136,7 +136,7 @@ impl<'a, 'b, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'b, struct ContainsRegion; -impl TypeVisitor<'_> for ContainsRegion { +impl TypeVisitor> for ContainsRegion { type BreakTy = (); fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow { diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 1635b75f718f..c785d89e2801 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -838,7 +838,7 @@ pub fn for_each_top_level_late_bound_region( index: u32, f: F, } - impl<'tcx, B, F: FnMut(BoundRegion) -> ControlFlow> TypeVisitor<'tcx> for V { + impl<'tcx, B, F: FnMut(BoundRegion) -> ControlFlow> TypeVisitor> for V { type BreakTy = B; fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow { if let RegionKind::ReLateBound(idx, bound) = r.kind() && idx.as_u32() == self.index { From e4f32ce002ccc1a46560f0fbe7768c63808bf7a7 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 13 Feb 2023 18:33:44 +0000 Subject: [PATCH 0746/1222] Use is_str instead of string kind comparison --- clippy_lints/src/methods/expect_fun_call.rs | 4 ++-- clippy_lints/src/methods/search_is_some.rs | 3 +-- clippy_lints/src/methods/single_char_pattern.rs | 2 +- clippy_lints/src/methods/string_extend_chars.rs | 3 +-- clippy_lints/src/strings.rs | 4 ++-- clippy_lints/src/transmute/transmute_ref_to_ref.rs | 3 ++- clippy_utils/src/ty.rs | 2 +- 7 files changed, 10 insertions(+), 11 deletions(-) diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index aed0ad5d9b5a..a22285058d48 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -33,7 +33,7 @@ pub(super) fn check<'tcx>( if (method_name.ident.name == sym::as_str || method_name.ident.name == sym::as_ref) && { let arg_type = cx.typeck_results().expr_ty(receiver); let base_type = arg_type.peel_refs(); - *base_type.kind() == ty::Str || is_type_lang_item(cx, base_type, hir::LangItem::String) + base_type.is_str() || is_type_lang_item(cx, base_type, hir::LangItem::String) } { receiver } else { @@ -54,7 +54,7 @@ pub(super) fn check<'tcx>( return false; } if let ty::Ref(_, ty, ..) = arg_ty.kind() { - if *ty.kind() == ty::Str && can_be_static_str(cx, arg) { + if ty.is_str() && can_be_static_str(cx, arg) { return false; } }; diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs index 1c031ad6acba..afdb8ce94ac4 100644 --- a/clippy_lints/src/methods/search_is_some.rs +++ b/clippy_lints/src/methods/search_is_some.rs @@ -8,7 +8,6 @@ use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::PatKind; use rustc_lint::LateContext; -use rustc_middle::ty; use rustc_span::source_map::Span; use rustc_span::symbol::sym; @@ -108,7 +107,7 @@ pub(super) fn check<'tcx>( if is_type_lang_item(cx, self_ty, hir::LangItem::String) { true } else { - *self_ty.kind() == ty::Str + self_ty.is_str() } }; if_chain! { diff --git a/clippy_lints/src/methods/single_char_pattern.rs b/clippy_lints/src/methods/single_char_pattern.rs index 4221c52d5cd7..4d704ec39ebb 100644 --- a/clippy_lints/src/methods/single_char_pattern.rs +++ b/clippy_lints/src/methods/single_char_pattern.rs @@ -47,7 +47,7 @@ pub(super) fn check( for &(method, pos) in &PATTERN_METHODS { if_chain! { if let ty::Ref(_, ty, _) = cx.typeck_results().expr_ty_adjusted(receiver).kind(); - if *ty.kind() == ty::Str; + if ty.is_str(); if method_name.as_str() == method && args.len() > pos; let arg = &args[pos]; let mut applicability = Applicability::MachineApplicable; diff --git a/clippy_lints/src/methods/string_extend_chars.rs b/clippy_lints/src/methods/string_extend_chars.rs index f35d81cee8e9..2c20c6d752d7 100644 --- a/clippy_lints/src/methods/string_extend_chars.rs +++ b/clippy_lints/src/methods/string_extend_chars.rs @@ -5,7 +5,6 @@ use clippy_utils::ty::is_type_lang_item; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; -use rustc_middle::ty; use super::STRING_EXTEND_CHARS; @@ -17,7 +16,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr if let Some(arglists) = method_chain_args(arg, &["chars"]) { let target = &arglists[0].0; let self_ty = cx.typeck_results().expr_ty(target).peel_refs(); - let ref_str = if *self_ty.kind() == ty::Str { + let ref_str = if self_ty.is_str() { if matches!(target.kind, hir::ExprKind::Index(..)) { "&" } else { diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index bc18cad6d381..b2f4b310915a 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -190,7 +190,7 @@ impl<'tcx> LateLintPass<'tcx> for StringAdd { }, ExprKind::Index(target, _idx) => { let e_ty = cx.typeck_results().expr_ty(target).peel_refs(); - if matches!(e_ty.kind(), ty::Str) || is_type_lang_item(cx, e_ty, LangItem::String) { + if e_ty.is_str() || is_type_lang_item(cx, e_ty, LangItem::String) { span_lint( cx, STRING_SLICE, @@ -407,7 +407,7 @@ impl<'tcx> LateLintPass<'tcx> for StrToString { if path.ident.name == sym::to_string; let ty = cx.typeck_results().expr_ty(self_arg); if let ty::Ref(_, ty, ..) = ty.kind(); - if *ty.kind() == ty::Str; + if ty.is_str(); then { span_lint_and_help( cx, diff --git a/clippy_lints/src/transmute/transmute_ref_to_ref.rs b/clippy_lints/src/transmute/transmute_ref_to_ref.rs index afb7f2e13269..426c7253806e 100644 --- a/clippy_lints/src/transmute/transmute_ref_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ref_to_ref.rs @@ -22,7 +22,8 @@ pub(super) fn check<'tcx>( if let (ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) = (&from_ty.kind(), &to_ty.kind()) { if_chain! { - if let (&ty::Slice(slice_ty), &ty::Str) = (&ty_from.kind(), &ty_to.kind()); + if let ty::Slice(slice_ty) = *ty_from.kind(); + if ty_to.is_str(); if let ty::Uint(ty::UintTy::U8) = slice_ty.kind(); if from_mutbl == to_mutbl; then { diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index c48d27b05f04..f293a7a3baee 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -346,7 +346,7 @@ pub fn is_non_aggregate_primitive_type(ty: Ty<'_>) -> bool { pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool { match *ty.kind() { ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => true, - ty::Ref(_, inner, _) if *inner.kind() == ty::Str => true, + ty::Ref(_, inner, _) if inner.is_str() => true, ty::Array(inner_type, _) | ty::Slice(inner_type) => is_recursively_primitive_type(inner_type), ty::Tuple(inner_types) => inner_types.iter().all(is_recursively_primitive_type), _ => false, From 11f1c51b42a30b59bf150c1d33dd73a8287a53f6 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 14 Feb 2023 08:51:19 +0000 Subject: [PATCH 0747/1222] s/eval_usize/eval_target_usize/ for clarity --- clippy_lints/src/indexing_slicing.rs | 2 +- clippy_lints/src/loops/explicit_iter_loop.rs | 2 +- clippy_lints/src/loops/needless_range_loop.rs | 2 +- clippy_lints/src/methods/utils.rs | 2 +- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/trailing_empty_array.rs | 2 +- clippy_utils/src/consts.rs | 2 +- clippy_utils/src/ty.rs | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index eebfb753a0c5..c384172fbde8 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -109,7 +109,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { if let Some(range) = higher::Range::hir(index) { // Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..] if let ty::Array(_, s) = ty.kind() { - let size: u128 = if let Some(size) = s.try_eval_usize(cx.tcx, cx.param_env) { + let size: u128 = if let Some(size) = s.try_eval_target_usize(cx.tcx, cx.param_env) { size.into() } else { return; diff --git a/clippy_lints/src/loops/explicit_iter_loop.rs b/clippy_lints/src/loops/explicit_iter_loop.rs index b1f2941622ab..151c7f1d5d25 100644 --- a/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_iter_loop.rs @@ -68,7 +68,7 @@ fn is_iterable_array<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool { // IntoIterator is currently only implemented for array sizes <= 32 in rustc match ty.kind() { ty::Array(_, n) => n - .try_eval_usize(cx.tcx, cx.param_env) + .try_eval_target_usize(cx.tcx, cx.param_env) .map_or(false, |val| (0..=32).contains(&val)), _ => false, } diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 25a1a5842f77..5c317c2a5bbb 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -211,7 +211,7 @@ fn is_end_eq_array_len<'tcx>( if let ExprKind::Lit(ref lit) = end.kind; if let ast::LitKind::Int(end_int, _) = lit.node; if let ty::Array(_, arr_len_const) = indexed_ty.kind(); - if let Some(arr_len) = arr_len_const.try_eval_usize(cx.tcx, cx.param_env); + if let Some(arr_len) = arr_len_const.try_eval_target_usize(cx.tcx, cx.param_env); then { return match limits { ast::RangeLimits::Closed => end_int + 1 >= arr_len.into(), diff --git a/clippy_lints/src/methods/utils.rs b/clippy_lints/src/methods/utils.rs index ae6b165fdc36..d50346c166ae 100644 --- a/clippy_lints/src/methods/utils.rs +++ b/clippy_lints/src/methods/utils.rs @@ -22,7 +22,7 @@ pub(super) fn derefs_to_slice<'tcx>( ty::Slice(_) => true, ty::Adt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()), ty::Adt(..) => is_type_diagnostic_item(cx, ty, sym::Vec), - ty::Array(_, size) => size.try_eval_usize(cx.tcx, cx.param_env).is_some(), + ty::Array(_, size) => size.try_eval_target_usize(cx.tcx, cx.param_env).is_some(), ty::Ref(_, inner, _) => may_slice(cx, *inner), _ => false, } diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 5f7aac21e6eb..3cc765108d7c 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -166,7 +166,7 @@ impl MutableKeyType { Ref(_, inner_ty, mutbl) => mutbl == hir::Mutability::Mut || self.is_interior_mutable_type(cx, inner_ty), Slice(inner_ty) => self.is_interior_mutable_type(cx, inner_ty), Array(inner_ty, size) => { - size.try_eval_usize(cx.tcx, cx.param_env).map_or(true, |u| u != 0) + size.try_eval_target_usize(cx.tcx, cx.param_env).map_or(true, |u| u != 0) && self.is_interior_mutable_type(cx, inner_ty) }, Tuple(fields) => fields.iter().any(|ty| self.is_interior_mutable_type(cx, ty)), diff --git a/clippy_lints/src/trailing_empty_array.rs b/clippy_lints/src/trailing_empty_array.rs index de0c5d56e415..1382c1a40da2 100644 --- a/clippy_lints/src/trailing_empty_array.rs +++ b/clippy_lints/src/trailing_empty_array.rs @@ -62,7 +62,7 @@ fn is_struct_with_trailing_zero_sized_array(cx: &LateContext<'_>, item: &Item<'_ // Then check if that that array zero-sized let length = Const::from_anon_const(cx.tcx, length.def_id); - let length = length.try_eval_usize(cx.tcx, cx.param_env); + let length = length.try_eval_target_usize(cx.tcx, cx.param_env); if let Some(length) = length; then { length == 0 diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index a67bd8d46006..9d812fbdcc37 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -335,7 +335,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { ExprKind::Tup(tup) => self.multi(tup).map(Constant::Tuple), ExprKind::Repeat(value, _) => { let n = match self.typeck_results.expr_ty(e).kind() { - ty::Array(_, n) => n.try_eval_usize(self.lcx.tcx, self.lcx.param_env)?, + ty::Array(_, n) => n.try_eval_target_usize(self.lcx.tcx, self.lcx.param_env)?, _ => span_bug!(e.span, "typeck error"), }; self.expr(value).map(|v| Constant::Repeat(Box::new(v), n)) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index c785d89e2801..0d763a2c5cf6 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -949,7 +949,7 @@ pub fn approx_ty_size<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> u64 { (Ok(size), _) => size, (Err(_), ty::Tuple(list)) => list.as_substs().types().map(|t| approx_ty_size(cx, t)).sum(), (Err(_), ty::Array(t, n)) => { - n.try_eval_usize(cx.tcx, cx.param_env).unwrap_or_default() * approx_ty_size(cx, *t) + n.try_eval_target_usize(cx.tcx, cx.param_env).unwrap_or_default() * approx_ty_size(cx, *t) }, (Err(_), ty::Adt(def, subst)) if def.is_struct() => def .variants() From a13ab622331ddbda26f400d1c6b1383261a025e5 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 12 Feb 2023 18:26:47 +0000 Subject: [PATCH 0748/1222] Add `of_trait` to DefKind::Impl. --- clippy_lints/src/same_name_method.rs | 2 +- clippy_utils/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/same_name_method.rs b/clippy_lints/src/same_name_method.rs index 17763128cd14..a37e2772d355 100644 --- a/clippy_lints/src/same_name_method.rs +++ b/clippy_lints/src/same_name_method.rs @@ -52,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod { let mut map = FxHashMap::::default(); for id in cx.tcx.hir().items() { - if matches!(cx.tcx.def_kind(id.owner_id), DefKind::Impl) + if matches!(cx.tcx.def_kind(id.owner_id), DefKind::Impl { .. }) && let item = cx.tcx.hir().item(id) && let ItemKind::Impl(Impl { items, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 26f279f55855..3b8713e2b108 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -552,7 +552,7 @@ fn non_local_item_children_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) .filter(|item| item.ident.name == name) .map(|child| child.res.expect_non_local()) .collect(), - DefKind::Impl => tcx + DefKind::Impl { .. } => tcx .associated_item_def_ids(def_id) .iter() .copied() From 4c13c225f617b01cb0247cbc76ed59aa0412cbd6 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 14 Feb 2023 14:31:26 +0000 Subject: [PATCH 0749/1222] Use target instead of machine for mir interpreter integer handling. The naming of `machine` only makes sense from a mir interpreter internals perspective, but outside users talk about the `target` platform --- clippy_lints/src/large_const_arrays.rs | 2 +- clippy_lints/src/large_stack_arrays.rs | 2 +- clippy_utils/src/consts.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index db637dfc068d..4dc750c03b48 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays { let ty = hir_ty_to_ty(cx.tcx, hir_ty); if let ty::Array(element_type, cst) = ty.kind(); if let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind(); - if let Ok(element_count) = element_count.try_to_machine_usize(cx.tcx); + if let Ok(element_count) = element_count.try_to_target_usize(cx.tcx); if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()); if self.maximum_allowed_size < u128::from(element_count) * u128::from(element_size); diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index 89ae83d48f53..32c6312e0694 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -41,7 +41,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays { if let ExprKind::Repeat(_, _) = expr.kind && let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind() && let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind() - && let Ok(element_count) = element_count.try_to_machine_usize(cx.tcx) + && let Ok(element_count) = element_count.try_to_target_usize(cx.tcx) && let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()) && !cx.tcx.hir().parent_iter(expr.hir_id) .any(|(_, node)| matches!(node, Node::Item(Item { kind: ItemKind::Static(..), .. }))) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 9d812fbdcc37..8b00ce2cc258 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -640,7 +640,7 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) - }, mir::ConstantKind::Val(ConstValue::ByRef { alloc, offset: _ }, _) => match result.ty().kind() { ty::Array(sub_type, len) => match sub_type.kind() { - ty::Float(FloatTy::F32) => match len.kind().try_to_machine_usize(tcx) { + ty::Float(FloatTy::F32) => match len.kind().try_to_target_usize(tcx) { Some(len) => alloc .inner() .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * usize::try_from(len).unwrap())) @@ -651,7 +651,7 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) - .map(Constant::Vec), _ => None, }, - ty::Float(FloatTy::F64) => match len.kind().try_to_machine_usize(tcx) { + ty::Float(FloatTy::F64) => match len.kind().try_to_target_usize(tcx) { Some(len) => alloc .inner() .inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * usize::try_from(len).unwrap())) From b6fe8dfaaffdc4cccbd8908f7e58c24626acfe0f Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 6 Feb 2023 18:38:52 +0000 Subject: [PATCH 0750/1222] Rename some region-specific stuff --- clippy_lints/src/ptr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index d88409c356e9..fc550936165e 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -505,13 +505,13 @@ fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Optio if let FnRetTy::Return(ty) = sig.decl.output && let Some((out, Mutability::Mut, _)) = get_ref_lm(ty) { - let out_region = cx.tcx.named_region(out.hir_id); + let out_region = cx.tcx.named_bound_var(out.hir_id); let args: Option> = sig .decl .inputs .iter() .filter_map(get_ref_lm) - .filter(|&(lt, _, _)| cx.tcx.named_region(lt.hir_id) == out_region) + .filter(|&(lt, _, _)| cx.tcx.named_bound_var(lt.hir_id) == out_region) .map(|(_, mutability, span)| (mutability == Mutability::Not).then_some(span)) .collect(); if let Some(args) = args From 25866ffa0a7ee7c996212b5754910a9f25b1265f Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Mon, 6 Feb 2023 17:48:12 -0700 Subject: [PATCH 0751/1222] change usages of type_of to bound_type_of --- clippy_lints/src/casts/cast_ptr_alignment.rs | 2 +- clippy_lints/src/copy_iterator.rs | 2 +- clippy_lints/src/default.rs | 2 +- clippy_lints/src/default_numeric_fallback.rs | 2 +- clippy_lints/src/dereference.rs | 4 ++-- clippy_lints/src/derivable_impls.rs | 2 +- clippy_lints/src/derive.rs | 4 ++-- clippy_lints/src/empty_enum.rs | 2 +- clippy_lints/src/enum_clike.rs | 2 +- clippy_lints/src/eta_reduction.rs | 4 ++-- clippy_lints/src/functions/misnamed_getters.rs | 2 +- clippy_lints/src/implicit_saturating_sub.rs | 4 ++-- clippy_lints/src/inherent_impl.rs | 3 ++- clippy_lints/src/large_enum_variant.rs | 2 +- .../src/matches/rest_pat_in_fully_bound_struct.rs | 2 +- clippy_lints/src/methods/bytes_count_to_len.rs | 2 +- .../methods/case_sensitive_file_extension_comparisons.rs | 2 +- clippy_lints/src/methods/get_first.rs | 2 +- clippy_lints/src/methods/implicit_clone.rs | 2 +- clippy_lints/src/methods/manual_ok_or.rs | 2 +- clippy_lints/src/methods/map_clone.rs | 2 +- clippy_lints/src/methods/map_err_ignore.rs | 2 +- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/methods/mut_mutex_lock.rs | 2 +- clippy_lints/src/methods/open_options.rs | 2 +- clippy_lints/src/methods/path_buf_push_overwrite.rs | 2 +- clippy_lints/src/methods/stable_sort_primitive.rs | 2 +- clippy_lints/src/methods/suspicious_splitn.rs | 2 +- clippy_lints/src/methods/unnecessary_sort_by.rs | 2 +- clippy_lints/src/methods/utils.rs | 2 +- clippy_lints/src/methods/vec_resize_to_zero.rs | 2 +- clippy_lints/src/new_without_default.rs | 8 +++++--- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/self_named_constructors.rs | 2 +- clippy_lints/src/use_self.rs | 6 +++--- .../src/utils/internal_lints/interning_defined_symbol.rs | 2 +- clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs | 3 ++- .../src/utils/internal_lints/unnecessary_def_path.rs | 4 ++-- clippy_utils/src/eager_or_lazy.rs | 4 ++-- clippy_utils/src/lib.rs | 4 ++-- clippy_utils/src/ty.rs | 4 ++-- 41 files changed, 57 insertions(+), 53 deletions(-) diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index 97054a0d1015..58d4cfff06f5 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -66,7 +66,7 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned") && let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id) && let Some(def_id) = cx.tcx.impl_of_method(def_id) - && cx.tcx.type_of(def_id).is_unsafe_ptr() + && cx.tcx.bound_type_of(def_id).subst_identity().is_unsafe_ptr() { true } else { diff --git a/clippy_lints/src/copy_iterator.rs b/clippy_lints/src/copy_iterator.rs index e38f77268530..023f9e64deb9 100644 --- a/clippy_lints/src/copy_iterator.rs +++ b/clippy_lints/src/copy_iterator.rs @@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyIterator { of_trait: Some(ref trait_ref), .. }) = item.kind; - let ty = cx.tcx.type_of(item.owner_id); + let ty = cx.tcx.bound_type_of(item.owner_id).subst_identity(); if is_copy(cx, ty); if let Some(trait_id) = trait_ref.trait_def_id(); if cx.tcx.is_diagnostic_item(sym::Iterator, trait_id); diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index a04693f4637a..b6b7eaae0686 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -150,7 +150,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { .fields .iter() .all(|field| { - is_copy(cx, cx.tcx.type_of(field.did)) + is_copy(cx, cx.tcx.bound_type_of(field.did).subst_identity()) }); if !has_drop(cx, binding_type) || all_fields_are_copy; then { diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index f806ba238c7c..e368efe944cf 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -167,7 +167,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { .iter() .find_map(|f_def| { if f_def.ident(self.cx.tcx) == field.ident - { Some(self.cx.tcx.type_of(f_def.did)) } + { Some(self.cx.tcx.bound_type_of(f_def.did).subst_identity()) } else { None } }); self.ty_bounds.push(bound.into()); diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 6c333afacc64..4c9f4f7f8cca 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -735,7 +735,7 @@ fn walk_parents<'tcx>( span, .. }) if span.ctxt() == ctxt => { - let ty = cx.tcx.type_of(owner_id.def_id); + let ty = cx.tcx.bound_type_of(owner_id.def_id).subst_identity(); Some(ty_auto_deref_stability(cx, ty, precedence).position_for_result(cx)) }, @@ -771,7 +771,7 @@ fn walk_parents<'tcx>( }) => variant_of_res(cx, cx.qpath_res(path, *hir_id)) .and_then(|variant| variant.fields.iter().find(|f| f.name == field.ident.name)) .map(|field_def| { - ty_auto_deref_stability(cx, cx.tcx.type_of(field_def.did), precedence).position_for_arg() + ty_auto_deref_stability(cx, cx.tcx.bound_type_of(field_def.did).subst_identity(), precedence).position_for_arg() }), _ => None, }, diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index bc18e2e5ed5f..f1d2db448718 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -184,7 +184,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { if let Some(Node::ImplItem(impl_item)) = cx.tcx.hir().find(impl_item_hir); if let ImplItemKind::Fn(_, b) = &impl_item.kind; if let Body { value: func_expr, .. } = cx.tcx.hir().body(*b); - if let Some(adt_def) = cx.tcx.type_of(item.owner_id).ty_adt_def(); + if let Some(adt_def) = cx.tcx.bound_type_of(item.owner_id).subst_identity().ty_adt_def(); if let attrs = cx.tcx.hir().attrs(item.hir_id()); if !attrs.iter().any(|attr| attr.doc_str().is_some()); if let child_attrs = cx.tcx.hir().attrs(impl_item_hir); diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index f8fc726d603f..0181b164f057 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -211,7 +211,7 @@ impl<'tcx> LateLintPass<'tcx> for Derive { .. }) = item.kind { - let ty = cx.tcx.type_of(item.owner_id); + let ty = cx.tcx.bound_type_of(item.owner_id).subst_identity(); let is_automatically_derived = cx.tcx.has_attr(item.owner_id.to_def_id(), sym::automatically_derived); check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived); @@ -347,7 +347,7 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &h let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(©_id).map_or(false, |impls| { impls .iter() - .any(|&id| matches!(cx.tcx.type_of(id).kind(), ty::Adt(adt, _) if ty_adt.did() == adt.did())) + .any(|&id| matches!(cx.tcx.bound_type_of(id).subst_identity().kind(), ty::Adt(adt, _) if ty_adt.did() == adt.did())) }); if !has_copy_impl { return; diff --git a/clippy_lints/src/empty_enum.rs b/clippy_lints/src/empty_enum.rs index 0570c2a10138..8c0112ca4a1c 100644 --- a/clippy_lints/src/empty_enum.rs +++ b/clippy_lints/src/empty_enum.rs @@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for EmptyEnum { } if let ItemKind::Enum(..) = item.kind { - let ty = cx.tcx.type_of(item.owner_id); + let ty = cx.tcx.bound_type_of(item.owner_id).subst_identity(); let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); if adt.variants().is_empty() { span_lint_and_help( diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index da67888827d1..e5289c177f3e 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant { for var in def.variants { if let Some(anon_const) = &var.disr_expr { let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body); - let mut ty = cx.tcx.type_of(def_id.to_def_id()); + let mut ty = cx.tcx.bound_type_of(def_id.to_def_id()).subst_identity(); let constant = cx .tcx .const_eval_poly(def_id.to_def_id()) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 3543910c3b55..a41ad735fb81 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -108,7 +108,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { if check_inputs(cx, body.params, None, args); let callee_ty = cx.typeck_results().expr_ty_adjusted(callee); let call_ty = cx.typeck_results().type_dependent_def_id(body.value.hir_id) - .map_or(callee_ty, |id| cx.tcx.type_of(id)); + .map_or(callee_ty, |id| cx.tcx.bound_type_of(id).subst_identity()); if check_sig(cx, closure_ty, call_ty); let substs = cx.typeck_results().node_substs(callee.hir_id); // This fixes some false positives that I don't entirely understand @@ -233,7 +233,7 @@ fn get_ufcs_type_name<'tcx>(cx: &LateContext<'tcx>, method_def_id: DefId, substs match assoc_item.container { ty::TraitContainer => cx.tcx.def_path_str(def_id), ty::ImplContainer => { - let ty = cx.tcx.type_of(def_id); + let ty = cx.tcx.bound_type_of(def_id).skip_binder(); match ty.kind() { ty::Adt(adt, _) => cx.tcx.def_path_str(adt.did()), ty::Array(..) diff --git a/clippy_lints/src/functions/misnamed_getters.rs b/clippy_lints/src/functions/misnamed_getters.rs index 8b53ee68ebdf..1405316c9bc0 100644 --- a/clippy_lints/src/functions/misnamed_getters.rs +++ b/clippy_lints/src/functions/misnamed_getters.rs @@ -101,7 +101,7 @@ pub fn check_fn(cx: &LateContext<'_>, kind: FnKind<'_>, decl: &FnDecl<'_>, body: return; }; - if cx.tcx.type_of(used_field.did) == cx.tcx.type_of(correct_field.did) { + if cx.tcx.bound_type_of(used_field.did) == cx.tcx.bound_type_of(correct_field.did) { let left_span = block_expr.span.until(used_ident.span); let snippet = snippet(cx, left_span, ".."); let sugg = format!("{snippet}{name}"); diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index 29d59c26d92c..bff3cd4e3a19 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -102,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { if let Some(const_id) = cx.typeck_results().type_dependent_def_id(cond_num_val.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(const_id); if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl - if cx.tcx.type_of(impl_id).is_integral(); + if cx.tcx.bound_type_of(impl_id).subst_identity().is_integral(); then { print_lint_and_sugg(cx, var_name, expr) } @@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { if let Some(func_id) = cx.typeck_results().type_dependent_def_id(func.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(func_id); if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl - if cx.tcx.type_of(impl_id).is_integral(); + if cx.tcx.bound_type_of(impl_id).subst_identity().is_integral(); then { print_lint_and_sugg(cx, var_name, expr) } diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index e9b2e31a769a..1a959809073e 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -66,7 +66,8 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { ) }) { for impl_id in impl_ids.iter().map(|id| id.expect_local()) { - match type_map.entry(cx.tcx.type_of(impl_id)) { + let impl_ty = cx.tcx.bound_type_of(impl_id).subst_identity(); + match type_map.entry(impl_ty) { Entry::Vacant(e) => { // Store the id for the first impl block of this type. The span is retrieved lazily. e.insert(IdOrSpan::Id(impl_id)); diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index b8d4abdbb781..a7c526692bb7 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -83,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant { return; } if let ItemKind::Enum(ref def, _) = item.kind { - let ty = cx.tcx.type_of(item.owner_id); + let ty = cx.tcx.bound_type_of(item.owner_id).subst_identity(); let Adt(adt, subst) = ty.kind() else { panic!("already checked whether this is an enum") }; diff --git a/clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs b/clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs index 0aadb482acdd..e3e4c9a5bbe8 100644 --- a/clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs +++ b/clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs @@ -10,7 +10,7 @@ pub(crate) fn check(cx: &LateContext<'_>, pat: &Pat<'_>) { if !pat.span.from_expansion(); if let PatKind::Struct(QPath::Resolved(_, path), fields, true) = pat.kind; if let Some(def_id) = path.res.opt_def_id(); - let ty = cx.tcx.type_of(def_id); + let ty = cx.tcx.bound_type_of(def_id).subst_identity(); if let ty::Adt(def, _) = ty.kind(); if def.is_struct() || def.is_union(); if fields.len() == def.non_enum_variant().fields.len(); diff --git a/clippy_lints/src/methods/bytes_count_to_len.rs b/clippy_lints/src/methods/bytes_count_to_len.rs index 89aaad359d4a..5b27145ac226 100644 --- a/clippy_lints/src/methods/bytes_count_to_len.rs +++ b/clippy_lints/src/methods/bytes_count_to_len.rs @@ -17,7 +17,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(bytes_id) = cx.typeck_results().type_dependent_def_id(count_recv.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(bytes_id); - if cx.tcx.type_of(impl_id).is_str(); + if cx.tcx.bound_type_of(impl_id).subst_identity().is_str(); let ty = cx.typeck_results().expr_ty(bytes_recv).peel_refs(); if ty.is_str() || is_type_lang_item(cx, ty, hir::LangItem::String); then { diff --git a/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs b/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs index 0b3bf22743fa..052f2097899f 100644 --- a/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs +++ b/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs @@ -30,7 +30,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if cx.tcx.type_of(impl_id).is_str(); + if cx.tcx.bound_type_of(impl_id).subst_identity().is_str(); if let ExprKind::Lit(Spanned { node: LitKind::Str(ext_literal, ..), ..}) = arg.kind; if (2..=6).contains(&ext_literal.as_str().len()); let ext_str = ext_literal.as_str(); diff --git a/clippy_lints/src/methods/get_first.rs b/clippy_lints/src/methods/get_first.rs index cb17af608a3f..a29c008e3d03 100644 --- a/clippy_lints/src/methods/get_first.rs +++ b/clippy_lints/src/methods/get_first.rs @@ -19,7 +19,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if cx.tcx.type_of(impl_id).is_slice(); + if cx.tcx.bound_type_of(impl_id).subst_identity().is_slice(); if let Some(_) = is_slice_of_primitives(cx, recv); if let hir::ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = arg.kind; then { diff --git a/clippy_lints/src/methods/implicit_clone.rs b/clippy_lints/src/methods/implicit_clone.rs index 06ecbce4e70e..0065806ba2da 100644 --- a/clippy_lints/src/methods/implicit_clone.rs +++ b/clippy_lints/src/methods/implicit_clone.rs @@ -53,7 +53,7 @@ pub fn is_clone_like(cx: &LateContext<'_>, method_name: &str, method_def_id: hir "to_vec" => cx .tcx .impl_of_method(method_def_id) - .filter(|&impl_did| cx.tcx.type_of(impl_did).is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none()) + .filter(|&impl_did| cx.tcx.bound_type_of(impl_did).subst_identity().is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none()) .is_some(), _ => false, } diff --git a/clippy_lints/src/methods/manual_ok_or.rs b/clippy_lints/src/methods/manual_ok_or.rs index 5b758f1e6547..b780a66374e9 100644 --- a/clippy_lints/src/methods/manual_ok_or.rs +++ b/clippy_lints/src/methods/manual_ok_or.rs @@ -21,7 +21,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id), sym::Option); + if is_type_diagnostic_item(cx, cx.tcx.bound_type_of(impl_id).subst_identity(), sym::Option); if let ExprKind::Call(err_path, [err_arg]) = or_expr.kind; if is_res_lang_ctor(cx, path_res(cx, err_path), ResultErr); if is_ok_wrapping(cx, map_expr); diff --git a/clippy_lints/src/methods/map_clone.rs b/clippy_lints/src/methods/map_clone.rs index 52cc1e0464bf..57004b4aea47 100644 --- a/clippy_lints/src/methods/map_clone.rs +++ b/clippy_lints/src/methods/map_clone.rs @@ -19,7 +19,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_ if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id); if cx.tcx.impl_of_method(method_id) - .map_or(false, |id| is_type_diagnostic_item(cx, cx.tcx.type_of(id), sym::Option)) + .map_or(false, |id| is_type_diagnostic_item(cx, cx.tcx.bound_type_of(id).subst_identity(), sym::Option)) || is_diag_trait_item(cx, method_id, sym::Iterator); if let hir::ExprKind::Closure(&hir::Closure{ body, .. }) = arg.kind; then { diff --git a/clippy_lints/src/methods/map_err_ignore.rs b/clippy_lints/src/methods/map_err_ignore.rs index b773b3e423f4..71fc5341b702 100644 --- a/clippy_lints/src/methods/map_err_ignore.rs +++ b/clippy_lints/src/methods/map_err_ignore.rs @@ -9,7 +9,7 @@ use super::MAP_ERR_IGNORE; pub(super) fn check(cx: &LateContext<'_>, e: &Expr<'_>, arg: &Expr<'_>) { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) && let Some(impl_id) = cx.tcx.impl_of_method(method_id) - && is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id), sym::Result) + && is_type_diagnostic_item(cx, cx.tcx.bound_type_of(impl_id).subst_identity(), sym::Result) && let ExprKind::Closure(&Closure { capture_clause: CaptureBy::Ref, body, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index f1e8be7f2b87..a665f48c151d 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3349,7 +3349,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { let name = impl_item.ident.name.as_str(); let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(parent); - let self_ty = cx.tcx.type_of(item.owner_id); + let self_ty = cx.tcx.bound_type_of(item.owner_id).subst_identity(); let implements_trait = matches!(item.kind, hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })); if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind { diff --git a/clippy_lints/src/methods/mut_mutex_lock.rs b/clippy_lints/src/methods/mut_mutex_lock.rs index b9593b3687d9..aa1a4c8075b8 100644 --- a/clippy_lints/src/methods/mut_mutex_lock.rs +++ b/clippy_lints/src/methods/mut_mutex_lock.rs @@ -15,7 +15,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'tcx>, recv: &' if let ty::Ref(_, _, Mutability::Mut) = cx.typeck_results().expr_ty(recv).kind(); if let Some(method_id) = cx.typeck_results().type_dependent_def_id(ex.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id), sym::Mutex); + if is_type_diagnostic_item(cx, cx.tcx.bound_type_of(impl_id).subst_identity(), sym::Mutex); then { span_lint_and_sugg( cx, diff --git a/clippy_lints/src/methods/open_options.rs b/clippy_lints/src/methods/open_options.rs index 597af853dc68..e77bc6af4734 100644 --- a/clippy_lints/src/methods/open_options.rs +++ b/clippy_lints/src/methods/open_options.rs @@ -11,7 +11,7 @@ use super::NONSENSICAL_OPEN_OPTIONS; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) && let Some(impl_id) = cx.tcx.impl_of_method(method_id) - && match_type(cx, cx.tcx.type_of(impl_id), &paths::OPEN_OPTIONS) + && match_type(cx, cx.tcx.bound_type_of(impl_id).subst_identity(), &paths::OPEN_OPTIONS) { let mut options = Vec::new(); get_open_options(cx, recv, &mut options); diff --git a/clippy_lints/src/methods/path_buf_push_overwrite.rs b/clippy_lints/src/methods/path_buf_push_overwrite.rs index 0cc28c0dcb3d..4522bf453902 100644 --- a/clippy_lints/src/methods/path_buf_push_overwrite.rs +++ b/clippy_lints/src/methods/path_buf_push_overwrite.rs @@ -14,7 +14,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arg: &'t if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id), sym::PathBuf); + if is_type_diagnostic_item(cx, cx.tcx.bound_type_of(impl_id).subst_identity(), sym::PathBuf); if let ExprKind::Lit(ref lit) = arg.kind; if let LitKind::Str(ref path_lit, _) = lit.node; if let pushed_path = Path::new(path_lit.as_str()); diff --git a/clippy_lints/src/methods/stable_sort_primitive.rs b/clippy_lints/src/methods/stable_sort_primitive.rs index 09c8ca4cbe44..6a0bf1560c33 100644 --- a/clippy_lints/src/methods/stable_sort_primitive.rs +++ b/clippy_lints/src/methods/stable_sort_primitive.rs @@ -10,7 +10,7 @@ use super::STABLE_SORT_PRIMITIVE; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) && let Some(impl_id) = cx.tcx.impl_of_method(method_id) - && cx.tcx.type_of(impl_id).is_slice() + && cx.tcx.bound_type_of(impl_id).subst_identity().is_slice() && let Some(slice_type) = is_slice_of_primitives(cx, recv) { span_lint_and_then( diff --git a/clippy_lints/src/methods/suspicious_splitn.rs b/clippy_lints/src/methods/suspicious_splitn.rs index 219a9edd6576..17f422d0e699 100644 --- a/clippy_lints/src/methods/suspicious_splitn.rs +++ b/clippy_lints/src/methods/suspicious_splitn.rs @@ -13,7 +13,7 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se if let Some(call_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(call_id); if cx.tcx.impl_trait_ref(impl_id).is_none(); - let self_ty = cx.tcx.type_of(impl_id); + let self_ty = cx.tcx.bound_type_of(impl_id).subst_identity(); if self_ty.is_slice() || self_ty.is_str(); then { // Ignore empty slice and string literals when used with a literal count. diff --git a/clippy_lints/src/methods/unnecessary_sort_by.rs b/clippy_lints/src/methods/unnecessary_sort_by.rs index ed5a75b0f3ce..436e637201a0 100644 --- a/clippy_lints/src/methods/unnecessary_sort_by.rs +++ b/clippy_lints/src/methods/unnecessary_sort_by.rs @@ -122,7 +122,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: &Exp if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if cx.tcx.type_of(impl_id).is_slice(); + if cx.tcx.bound_type_of(impl_id).subst_identity().is_slice(); if let ExprKind::Closure(&Closure { body, .. }) = arg.kind; if let closure_body = cx.tcx.hir().body(body); if let &[ diff --git a/clippy_lints/src/methods/utils.rs b/clippy_lints/src/methods/utils.rs index d50346c166ae..5959fdb6625f 100644 --- a/clippy_lints/src/methods/utils.rs +++ b/clippy_lints/src/methods/utils.rs @@ -143,7 +143,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for CloneOrCopyVisitor<'cx, 'tcx> { if_chain! { if args.iter().all(|arg| !self.is_binding(arg)); if let Some(method_def_id) = self.cx.typeck_results().type_dependent_def_id(parent.hir_id); - let method_ty = self.cx.tcx.type_of(method_def_id); + let method_ty = self.cx.tcx.bound_type_of(method_def_id).subst_identity(); let self_ty = method_ty.fn_sig(self.cx.tcx).input(0).skip_binder(); if matches!(self_ty.kind(), ty::Ref(_, _, Mutability::Not)); then { diff --git a/clippy_lints/src/methods/vec_resize_to_zero.rs b/clippy_lints/src/methods/vec_resize_to_zero.rs index 02d8364cb295..8c461b2629d7 100644 --- a/clippy_lints/src/methods/vec_resize_to_zero.rs +++ b/clippy_lints/src/methods/vec_resize_to_zero.rs @@ -20,7 +20,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id), sym::Vec); + if is_type_diagnostic_item(cx, cx.tcx.bound_type_of(impl_id).subst_identity(), sym::Vec); if let ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = count_arg.kind; if let ExprKind::Lit(Spanned { node: LitKind::Int(..), .. }) = default_arg.kind; then { diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index faf9ec61ec50..47dc4b276a27 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -98,14 +98,15 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { if name == sym::new; if cx.effective_visibilities.is_reachable(impl_item.owner_id.def_id); let self_def_id = cx.tcx.hir().get_parent_item(id.into()); - let self_ty = cx.tcx.type_of(self_def_id); + let self_ty = cx.tcx.bound_type_of(self_def_id).subst_identity(); if self_ty == return_ty(cx, id); if let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default); then { if self.impling_types.is_none() { let mut impls = HirIdSet::default(); cx.tcx.for_each_impl(default_trait_id, |d| { - if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() { + let ty = cx.tcx.bound_type_of(d).subst_identity(); + if let Some(ty_def) = ty.ty_adt_def() { if let Some(local_def_id) = ty_def.did().as_local() { impls.insert(cx.tcx.hir().local_def_id_to_hir_id(local_def_id)); } @@ -118,7 +119,8 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { // generics if_chain! { if let Some(ref impling_types) = self.impling_types; - if let Some(self_def) = cx.tcx.type_of(self_def_id).ty_adt_def(); + let self_def = cx.tcx.bound_type_of(self_def_id).subst_identity(); + if let Some(self_def) = self_def.ty_adt_def(); if let Some(self_local_did) = self_def.did().as_local(); let self_id = cx.tcx.hir().local_def_id_to_hir_id(self_local_did); if impling_types.contains(&self_id); diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 07fd321d69fc..a076bed50d1b 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -313,7 +313,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { // and, in that case, the definition is *not* generic. cx.tcx.normalize_erasing_regions( cx.tcx.param_env(of_trait_def_id), - cx.tcx.type_of(of_assoc_item), + cx.tcx.bound_type_of(of_assoc_item).subst_identity(), ), )) .is_err(); diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index 3ce030cd721a..df834962673d 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(parent); - let self_ty = cx.tcx.type_of(item.owner_id); + let self_ty = cx.tcx.bound_type_of(item.owner_id).subst_identity(); let ret_ty = return_ty(cx, impl_item.owner_id); // Do not check trait impls diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 3cd35838961f..a50b38c54dca 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -218,7 +218,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { } else { hir_ty_to_ty(cx.tcx, hir_ty) }; - if same_type_and_consts(ty, cx.tcx.type_of(impl_id)); + if same_type_and_consts(ty, cx.tcx.bound_type_of(impl_id).subst_identity()); then { span_lint(cx, hir_ty.span); } @@ -230,7 +230,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { if !expr.span.from_expansion(); if self.msrv.meets(msrvs::TYPE_ALIAS_ENUM_VARIANTS); if let Some(&StackItem::Check { impl_id, .. }) = self.stack.last(); - if cx.typeck_results().expr_ty(expr) == cx.tcx.type_of(impl_id); + if cx.typeck_results().expr_ty(expr) == cx.tcx.bound_type_of(impl_id).subst_identity(); then {} else { return; } } match expr.kind { @@ -254,7 +254,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { if let PatKind::Path(QPath::Resolved(_, path)) | PatKind::TupleStruct(QPath::Resolved(_, path), _, _) | PatKind::Struct(QPath::Resolved(_, path), _, _) = pat.kind; - if cx.typeck_results().pat_ty(pat) == cx.tcx.type_of(impl_id); + if cx.typeck_results().pat_ty(pat) == cx.tcx.bound_type_of(impl_id).subst_identity(); then { check_path(cx, path); } diff --git a/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs b/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs index 4b33d492a0e4..f62bfa4f2217 100644 --- a/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs +++ b/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs @@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol { for item in cx.tcx.module_children(def_id).iter() { if_chain! { if let Res::Def(DefKind::Const, item_def_id) = item.res; - let ty = cx.tcx.type_of(item_def_id); + let ty = cx.tcx.bound_type_of(item_def_id).subst_identity(); if match_type(cx, ty, &paths::SYMBOL); if let Ok(ConstValue::Scalar(value)) = cx.tcx.const_eval_poly(item_def_id); if let Ok(value) = value.to_u32(); diff --git a/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs b/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs index 9876a8a765cc..3249b8633914 100644 --- a/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs +++ b/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs @@ -38,7 +38,8 @@ impl LateLintPass<'_> for MsrvAttrImpl { if self_ty_def.is_struct(); if self_ty_def.all_fields().any(|f| { cx.tcx - .type_of(f.did) + .bound_type_of(f.did) + .subst_identity() .walk() .filter(|t| matches!(t.unpack(), GenericArgKind::Type(_))) .any(|t| match_type(cx, t.expect_ty(), &paths::MSRV)) diff --git a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs index 7144363637a0..3f08566dbcc7 100644 --- a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs +++ b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs @@ -229,11 +229,11 @@ fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option read_mir_alloc_def_path( cx, cx.tcx.eval_static_initializer(def_id).ok()?.inner(), - cx.tcx.type_of(def_id), + cx.tcx.bound_type_of(def_id).subst_identity(), ), Res::Def(DefKind::Const, def_id) => match cx.tcx.const_eval_poly(def_id).ok()? { ConstValue::ByRef { alloc, offset } if offset.bytes() == 0 => { - read_mir_alloc_def_path(cx, alloc.inner(), cx.tcx.type_of(def_id)) + read_mir_alloc_def_path(cx, alloc.inner(), cx.tcx.bound_type_of(def_id).subst_identity()) }, _ => None, }, diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 5c89dd3e49f4..97b2cc382b0d 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -50,7 +50,7 @@ fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg: let name = name.as_str(); let ty = match cx.tcx.impl_of_method(fn_id) { - Some(id) => cx.tcx.type_of(id), + Some(id) => cx.tcx.bound_type_of(id).subst_identity(), None => return Lazy, }; @@ -71,7 +71,7 @@ fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg: .variants() .iter() .flat_map(|v| v.fields.iter()) - .any(|x| matches!(cx.tcx.type_of(x.did).peel_refs().kind(), ty::Param(_))) + .any(|x| matches!(cx.tcx.bound_type_of(x.did).subst_identity().peel_refs().kind(), ty::Param(_))) && all_predicates_of(cx.tcx, fn_id).all(|(pred, _)| match pred.kind().skip_binder() { PredicateKind::Clause(ty::Clause::Trait(pred)) => cx.tcx.trait_def(pred.trait_ref.def_id).is_marker, _ => true, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 3b8713e2b108..168055657755 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -317,7 +317,7 @@ pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str]) /// Checks if a method is defined in an impl of a diagnostic item pub fn is_diag_item_method(cx: &LateContext<'_>, def_id: DefId, diag_item: Symbol) -> bool { if let Some(impl_did) = cx.tcx.impl_of_method(def_id) { - if let Some(adt) = cx.tcx.type_of(impl_did).ty_adt_def() { + if let Some(adt) = cx.tcx.bound_type_of(impl_did).subst_identity().ty_adt_def() { return cx.tcx.is_diagnostic_item(diag_item, adt.did()); } } @@ -812,7 +812,7 @@ fn is_default_equivalent_ctor(cx: &LateContext<'_>, def_id: DefId, path: &QPath< if let QPath::TypeRelative(_, method) = path { if method.ident.name == sym::new { if let Some(impl_did) = cx.tcx.impl_of_method(def_id) { - if let Some(adt) = cx.tcx.type_of(impl_did).ty_adt_def() { + if let Some(adt) = cx.tcx.bound_type_of(impl_did).subst_identity().ty_adt_def() { return std_types_symbols.iter().any(|&symbol| { cx.tcx.is_diagnostic_item(symbol, adt.did()) || Some(adt.did()) == cx.tcx.lang_items().string() }); diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index d6af7a948a5c..6987d1d2d65a 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -780,7 +780,7 @@ impl core::ops::Add for EnumValue { #[expect(clippy::cast_possible_truncation, clippy::cast_possible_wrap)] pub fn read_explicit_enum_value(tcx: TyCtxt<'_>, id: DefId) -> Option { if let Ok(ConstValue::Scalar(Scalar::Int(value))) = tcx.const_eval_poly(id) { - match tcx.type_of(id).kind() { + match tcx.bound_type_of(id).subst_identity().kind() { ty::Int(_) => Some(EnumValue::Signed(match value.size().bytes() { 1 => i128::from(value.assert_bits(Size::from_bytes(1)) as u8 as i8), 2 => i128::from(value.assert_bits(Size::from_bytes(2)) as u16 as i16), @@ -903,7 +903,7 @@ pub fn variant_of_res<'tcx>(cx: &LateContext<'tcx>, res: Res) -> Option<&'tcx Va let var_id = cx.tcx.parent(id); Some(cx.tcx.adt_def(cx.tcx.parent(var_id)).variant_with_id(var_id)) }, - Res::SelfCtor(id) => Some(cx.tcx.type_of(id).ty_adt_def().unwrap().non_enum_variant()), + Res::SelfCtor(id) => Some(cx.tcx.bound_type_of(id).subst_identity().ty_adt_def().unwrap().non_enum_variant()), _ => None, } } From a0fdad6651682cd4a31370e2af35a0b904a8bff9 Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Tue, 7 Feb 2023 01:29:48 -0700 Subject: [PATCH 0752/1222] remove bound_type_of query; make type_of return EarlyBinder; change type_of in metadata --- clippy_lints/src/casts/cast_ptr_alignment.rs | 2 +- clippy_lints/src/copy_iterator.rs | 2 +- clippy_lints/src/default.rs | 2 +- clippy_lints/src/default_numeric_fallback.rs | 2 +- clippy_lints/src/dereference.rs | 4 ++-- clippy_lints/src/derivable_impls.rs | 2 +- clippy_lints/src/derive.rs | 4 ++-- clippy_lints/src/empty_enum.rs | 2 +- clippy_lints/src/enum_clike.rs | 2 +- clippy_lints/src/eta_reduction.rs | 6 +++--- clippy_lints/src/functions/misnamed_getters.rs | 2 +- clippy_lints/src/implicit_saturating_sub.rs | 4 ++-- clippy_lints/src/inherent_impl.rs | 2 +- clippy_lints/src/large_enum_variant.rs | 2 +- clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs | 2 +- clippy_lints/src/methods/bytes_count_to_len.rs | 2 +- .../methods/case_sensitive_file_extension_comparisons.rs | 2 +- clippy_lints/src/methods/get_first.rs | 2 +- clippy_lints/src/methods/implicit_clone.rs | 2 +- clippy_lints/src/methods/manual_ok_or.rs | 2 +- clippy_lints/src/methods/map_clone.rs | 2 +- clippy_lints/src/methods/map_err_ignore.rs | 2 +- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/methods/mut_mutex_lock.rs | 2 +- clippy_lints/src/methods/open_options.rs | 2 +- clippy_lints/src/methods/path_buf_push_overwrite.rs | 2 +- clippy_lints/src/methods/stable_sort_primitive.rs | 2 +- clippy_lints/src/methods/suspicious_splitn.rs | 2 +- clippy_lints/src/methods/unnecessary_sort_by.rs | 2 +- clippy_lints/src/methods/utils.rs | 2 +- clippy_lints/src/methods/vec_resize_to_zero.rs | 2 +- clippy_lints/src/mut_reference.rs | 2 +- clippy_lints/src/new_without_default.rs | 6 +++--- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/self_named_constructors.rs | 2 +- clippy_lints/src/transmute/transmute_undefined_repr.rs | 2 +- clippy_lints/src/use_self.rs | 6 +++--- .../src/utils/internal_lints/interning_defined_symbol.rs | 2 +- clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs | 2 +- .../src/utils/internal_lints/unnecessary_def_path.rs | 4 ++-- clippy_utils/src/eager_or_lazy.rs | 4 ++-- clippy_utils/src/lib.rs | 4 ++-- clippy_utils/src/ty.rs | 4 ++-- 43 files changed, 56 insertions(+), 56 deletions(-) diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index 58d4cfff06f5..6c8ee296c751 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -66,7 +66,7 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned") && let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id) && let Some(def_id) = cx.tcx.impl_of_method(def_id) - && cx.tcx.bound_type_of(def_id).subst_identity().is_unsafe_ptr() + && cx.tcx.type_of(def_id).subst_identity().is_unsafe_ptr() { true } else { diff --git a/clippy_lints/src/copy_iterator.rs b/clippy_lints/src/copy_iterator.rs index 023f9e64deb9..0fc11523298f 100644 --- a/clippy_lints/src/copy_iterator.rs +++ b/clippy_lints/src/copy_iterator.rs @@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyIterator { of_trait: Some(ref trait_ref), .. }) = item.kind; - let ty = cx.tcx.bound_type_of(item.owner_id).subst_identity(); + let ty = cx.tcx.type_of(item.owner_id).subst_identity(); if is_copy(cx, ty); if let Some(trait_id) = trait_ref.trait_def_id(); if cx.tcx.is_diagnostic_item(sym::Iterator, trait_id); diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index b6b7eaae0686..080d44e6398c 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -150,7 +150,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { .fields .iter() .all(|field| { - is_copy(cx, cx.tcx.bound_type_of(field.did).subst_identity()) + is_copy(cx, cx.tcx.type_of(field.did).subst_identity()) }); if !has_drop(cx, binding_type) || all_fields_are_copy; then { diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index e368efe944cf..4e1a6cd4d735 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -167,7 +167,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { .iter() .find_map(|f_def| { if f_def.ident(self.cx.tcx) == field.ident - { Some(self.cx.tcx.bound_type_of(f_def.did).subst_identity()) } + { Some(self.cx.tcx.type_of(f_def.did).subst_identity()) } else { None } }); self.ty_bounds.push(bound.into()); diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 4c9f4f7f8cca..b4543aa2544f 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -735,7 +735,7 @@ fn walk_parents<'tcx>( span, .. }) if span.ctxt() == ctxt => { - let ty = cx.tcx.bound_type_of(owner_id.def_id).subst_identity(); + let ty = cx.tcx.type_of(owner_id.def_id).subst_identity(); Some(ty_auto_deref_stability(cx, ty, precedence).position_for_result(cx)) }, @@ -771,7 +771,7 @@ fn walk_parents<'tcx>( }) => variant_of_res(cx, cx.qpath_res(path, *hir_id)) .and_then(|variant| variant.fields.iter().find(|f| f.name == field.ident.name)) .map(|field_def| { - ty_auto_deref_stability(cx, cx.tcx.bound_type_of(field_def.did).subst_identity(), precedence).position_for_arg() + ty_auto_deref_stability(cx, cx.tcx.type_of(field_def.did).subst_identity(), precedence).position_for_arg() }), _ => None, }, diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index f1d2db448718..f95b8ccf067b 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -184,7 +184,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { if let Some(Node::ImplItem(impl_item)) = cx.tcx.hir().find(impl_item_hir); if let ImplItemKind::Fn(_, b) = &impl_item.kind; if let Body { value: func_expr, .. } = cx.tcx.hir().body(*b); - if let Some(adt_def) = cx.tcx.bound_type_of(item.owner_id).subst_identity().ty_adt_def(); + if let Some(adt_def) = cx.tcx.type_of(item.owner_id).subst_identity().ty_adt_def(); if let attrs = cx.tcx.hir().attrs(item.hir_id()); if !attrs.iter().any(|attr| attr.doc_str().is_some()); if let child_attrs = cx.tcx.hir().attrs(impl_item_hir); diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 0181b164f057..1cdcccd5f146 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -211,7 +211,7 @@ impl<'tcx> LateLintPass<'tcx> for Derive { .. }) = item.kind { - let ty = cx.tcx.bound_type_of(item.owner_id).subst_identity(); + let ty = cx.tcx.type_of(item.owner_id).subst_identity(); let is_automatically_derived = cx.tcx.has_attr(item.owner_id.to_def_id(), sym::automatically_derived); check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived); @@ -347,7 +347,7 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &h let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(©_id).map_or(false, |impls| { impls .iter() - .any(|&id| matches!(cx.tcx.bound_type_of(id).subst_identity().kind(), ty::Adt(adt, _) if ty_adt.did() == adt.did())) + .any(|&id| matches!(cx.tcx.type_of(id).subst_identity().kind(), ty::Adt(adt, _) if ty_adt.did() == adt.did())) }); if !has_copy_impl { return; diff --git a/clippy_lints/src/empty_enum.rs b/clippy_lints/src/empty_enum.rs index 8c0112ca4a1c..d94664daa561 100644 --- a/clippy_lints/src/empty_enum.rs +++ b/clippy_lints/src/empty_enum.rs @@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for EmptyEnum { } if let ItemKind::Enum(..) = item.kind { - let ty = cx.tcx.bound_type_of(item.owner_id).subst_identity(); + let ty = cx.tcx.type_of(item.owner_id).subst_identity(); let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); if adt.variants().is_empty() { span_lint_and_help( diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index e5289c177f3e..e275efaba25f 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant { for var in def.variants { if let Some(anon_const) = &var.disr_expr { let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body); - let mut ty = cx.tcx.bound_type_of(def_id.to_def_id()).subst_identity(); + let mut ty = cx.tcx.type_of(def_id.to_def_id()).subst_identity(); let constant = cx .tcx .const_eval_poly(def_id.to_def_id()) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index a41ad735fb81..ddade65c515c 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -108,7 +108,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { if check_inputs(cx, body.params, None, args); let callee_ty = cx.typeck_results().expr_ty_adjusted(callee); let call_ty = cx.typeck_results().type_dependent_def_id(body.value.hir_id) - .map_or(callee_ty, |id| cx.tcx.bound_type_of(id).subst_identity()); + .map_or(callee_ty, |id| cx.tcx.type_of(id).subst_identity()); if check_sig(cx, closure_ty, call_ty); let substs = cx.typeck_results().node_substs(callee.hir_id); // This fixes some false positives that I don't entirely understand @@ -153,7 +153,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { if check_inputs(cx, body.params, Some(receiver), args); let method_def_id = cx.typeck_results().type_dependent_def_id(body.value.hir_id).unwrap(); let substs = cx.typeck_results().node_substs(body.value.hir_id); - let call_ty = cx.tcx.bound_type_of(method_def_id).subst(cx.tcx, substs); + let call_ty = cx.tcx.type_of(method_def_id).subst(cx.tcx, substs); if check_sig(cx, closure_ty, call_ty); then { span_lint_and_then(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure", |diag| { @@ -233,7 +233,7 @@ fn get_ufcs_type_name<'tcx>(cx: &LateContext<'tcx>, method_def_id: DefId, substs match assoc_item.container { ty::TraitContainer => cx.tcx.def_path_str(def_id), ty::ImplContainer => { - let ty = cx.tcx.bound_type_of(def_id).skip_binder(); + let ty = cx.tcx.type_of(def_id).skip_binder(); match ty.kind() { ty::Adt(adt, _) => cx.tcx.def_path_str(adt.did()), ty::Array(..) diff --git a/clippy_lints/src/functions/misnamed_getters.rs b/clippy_lints/src/functions/misnamed_getters.rs index 1405316c9bc0..8b53ee68ebdf 100644 --- a/clippy_lints/src/functions/misnamed_getters.rs +++ b/clippy_lints/src/functions/misnamed_getters.rs @@ -101,7 +101,7 @@ pub fn check_fn(cx: &LateContext<'_>, kind: FnKind<'_>, decl: &FnDecl<'_>, body: return; }; - if cx.tcx.bound_type_of(used_field.did) == cx.tcx.bound_type_of(correct_field.did) { + if cx.tcx.type_of(used_field.did) == cx.tcx.type_of(correct_field.did) { let left_span = block_expr.span.until(used_ident.span); let snippet = snippet(cx, left_span, ".."); let sugg = format!("{snippet}{name}"); diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index bff3cd4e3a19..0c7aea6da8fe 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -102,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { if let Some(const_id) = cx.typeck_results().type_dependent_def_id(cond_num_val.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(const_id); if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl - if cx.tcx.bound_type_of(impl_id).subst_identity().is_integral(); + if cx.tcx.type_of(impl_id).subst_identity().is_integral(); then { print_lint_and_sugg(cx, var_name, expr) } @@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { if let Some(func_id) = cx.typeck_results().type_dependent_def_id(func.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(func_id); if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl - if cx.tcx.bound_type_of(impl_id).subst_identity().is_integral(); + if cx.tcx.type_of(impl_id).subst_identity().is_integral(); then { print_lint_and_sugg(cx, var_name, expr) } diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index 1a959809073e..7c41699f307a 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { ) }) { for impl_id in impl_ids.iter().map(|id| id.expect_local()) { - let impl_ty = cx.tcx.bound_type_of(impl_id).subst_identity(); + let impl_ty = cx.tcx.type_of(impl_id).subst_identity(); match type_map.entry(impl_ty) { Entry::Vacant(e) => { // Store the id for the first impl block of this type. The span is retrieved lazily. diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index a7c526692bb7..1c99bd2f3d02 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -83,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant { return; } if let ItemKind::Enum(ref def, _) = item.kind { - let ty = cx.tcx.bound_type_of(item.owner_id).subst_identity(); + let ty = cx.tcx.type_of(item.owner_id).subst_identity(); let Adt(adt, subst) = ty.kind() else { panic!("already checked whether this is an enum") }; diff --git a/clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs b/clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs index e3e4c9a5bbe8..d06bcdaa27f0 100644 --- a/clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs +++ b/clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs @@ -10,7 +10,7 @@ pub(crate) fn check(cx: &LateContext<'_>, pat: &Pat<'_>) { if !pat.span.from_expansion(); if let PatKind::Struct(QPath::Resolved(_, path), fields, true) = pat.kind; if let Some(def_id) = path.res.opt_def_id(); - let ty = cx.tcx.bound_type_of(def_id).subst_identity(); + let ty = cx.tcx.type_of(def_id).subst_identity(); if let ty::Adt(def, _) = ty.kind(); if def.is_struct() || def.is_union(); if fields.len() == def.non_enum_variant().fields.len(); diff --git a/clippy_lints/src/methods/bytes_count_to_len.rs b/clippy_lints/src/methods/bytes_count_to_len.rs index 5b27145ac226..46a20ad412ba 100644 --- a/clippy_lints/src/methods/bytes_count_to_len.rs +++ b/clippy_lints/src/methods/bytes_count_to_len.rs @@ -17,7 +17,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(bytes_id) = cx.typeck_results().type_dependent_def_id(count_recv.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(bytes_id); - if cx.tcx.bound_type_of(impl_id).subst_identity().is_str(); + if cx.tcx.type_of(impl_id).subst_identity().is_str(); let ty = cx.typeck_results().expr_ty(bytes_recv).peel_refs(); if ty.is_str() || is_type_lang_item(cx, ty, hir::LangItem::String); then { diff --git a/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs b/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs index 052f2097899f..7711aa78b239 100644 --- a/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs +++ b/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs @@ -30,7 +30,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if cx.tcx.bound_type_of(impl_id).subst_identity().is_str(); + if cx.tcx.type_of(impl_id).subst_identity().is_str(); if let ExprKind::Lit(Spanned { node: LitKind::Str(ext_literal, ..), ..}) = arg.kind; if (2..=6).contains(&ext_literal.as_str().len()); let ext_str = ext_literal.as_str(); diff --git a/clippy_lints/src/methods/get_first.rs b/clippy_lints/src/methods/get_first.rs index a29c008e3d03..945bbf53bcf3 100644 --- a/clippy_lints/src/methods/get_first.rs +++ b/clippy_lints/src/methods/get_first.rs @@ -19,7 +19,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if cx.tcx.bound_type_of(impl_id).subst_identity().is_slice(); + if cx.tcx.type_of(impl_id).subst_identity().is_slice(); if let Some(_) = is_slice_of_primitives(cx, recv); if let hir::ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = arg.kind; then { diff --git a/clippy_lints/src/methods/implicit_clone.rs b/clippy_lints/src/methods/implicit_clone.rs index 0065806ba2da..374eb29fc527 100644 --- a/clippy_lints/src/methods/implicit_clone.rs +++ b/clippy_lints/src/methods/implicit_clone.rs @@ -53,7 +53,7 @@ pub fn is_clone_like(cx: &LateContext<'_>, method_name: &str, method_def_id: hir "to_vec" => cx .tcx .impl_of_method(method_def_id) - .filter(|&impl_did| cx.tcx.bound_type_of(impl_did).subst_identity().is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none()) + .filter(|&impl_did| cx.tcx.type_of(impl_did).subst_identity().is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none()) .is_some(), _ => false, } diff --git a/clippy_lints/src/methods/manual_ok_or.rs b/clippy_lints/src/methods/manual_ok_or.rs index b780a66374e9..b9a0ec779961 100644 --- a/clippy_lints/src/methods/manual_ok_or.rs +++ b/clippy_lints/src/methods/manual_ok_or.rs @@ -21,7 +21,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if is_type_diagnostic_item(cx, cx.tcx.bound_type_of(impl_id).subst_identity(), sym::Option); + if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).subst_identity(), sym::Option); if let ExprKind::Call(err_path, [err_arg]) = or_expr.kind; if is_res_lang_ctor(cx, path_res(cx, err_path), ResultErr); if is_ok_wrapping(cx, map_expr); diff --git a/clippy_lints/src/methods/map_clone.rs b/clippy_lints/src/methods/map_clone.rs index 57004b4aea47..2b26ef014109 100644 --- a/clippy_lints/src/methods/map_clone.rs +++ b/clippy_lints/src/methods/map_clone.rs @@ -19,7 +19,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_ if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id); if cx.tcx.impl_of_method(method_id) - .map_or(false, |id| is_type_diagnostic_item(cx, cx.tcx.bound_type_of(id).subst_identity(), sym::Option)) + .map_or(false, |id| is_type_diagnostic_item(cx, cx.tcx.type_of(id).subst_identity(), sym::Option)) || is_diag_trait_item(cx, method_id, sym::Iterator); if let hir::ExprKind::Closure(&hir::Closure{ body, .. }) = arg.kind; then { diff --git a/clippy_lints/src/methods/map_err_ignore.rs b/clippy_lints/src/methods/map_err_ignore.rs index 71fc5341b702..a5beb291f326 100644 --- a/clippy_lints/src/methods/map_err_ignore.rs +++ b/clippy_lints/src/methods/map_err_ignore.rs @@ -9,7 +9,7 @@ use super::MAP_ERR_IGNORE; pub(super) fn check(cx: &LateContext<'_>, e: &Expr<'_>, arg: &Expr<'_>) { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) && let Some(impl_id) = cx.tcx.impl_of_method(method_id) - && is_type_diagnostic_item(cx, cx.tcx.bound_type_of(impl_id).subst_identity(), sym::Result) + && is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).subst_identity(), sym::Result) && let ExprKind::Closure(&Closure { capture_clause: CaptureBy::Ref, body, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index a665f48c151d..6301b3ded20d 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3349,7 +3349,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { let name = impl_item.ident.name.as_str(); let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(parent); - let self_ty = cx.tcx.bound_type_of(item.owner_id).subst_identity(); + let self_ty = cx.tcx.type_of(item.owner_id).subst_identity(); let implements_trait = matches!(item.kind, hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })); if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind { diff --git a/clippy_lints/src/methods/mut_mutex_lock.rs b/clippy_lints/src/methods/mut_mutex_lock.rs index aa1a4c8075b8..d0aa39d06275 100644 --- a/clippy_lints/src/methods/mut_mutex_lock.rs +++ b/clippy_lints/src/methods/mut_mutex_lock.rs @@ -15,7 +15,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'tcx>, recv: &' if let ty::Ref(_, _, Mutability::Mut) = cx.typeck_results().expr_ty(recv).kind(); if let Some(method_id) = cx.typeck_results().type_dependent_def_id(ex.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if is_type_diagnostic_item(cx, cx.tcx.bound_type_of(impl_id).subst_identity(), sym::Mutex); + if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).subst_identity(), sym::Mutex); then { span_lint_and_sugg( cx, diff --git a/clippy_lints/src/methods/open_options.rs b/clippy_lints/src/methods/open_options.rs index e77bc6af4734..c6a27cdd6fac 100644 --- a/clippy_lints/src/methods/open_options.rs +++ b/clippy_lints/src/methods/open_options.rs @@ -11,7 +11,7 @@ use super::NONSENSICAL_OPEN_OPTIONS; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) && let Some(impl_id) = cx.tcx.impl_of_method(method_id) - && match_type(cx, cx.tcx.bound_type_of(impl_id).subst_identity(), &paths::OPEN_OPTIONS) + && match_type(cx, cx.tcx.type_of(impl_id).subst_identity(), &paths::OPEN_OPTIONS) { let mut options = Vec::new(); get_open_options(cx, recv, &mut options); diff --git a/clippy_lints/src/methods/path_buf_push_overwrite.rs b/clippy_lints/src/methods/path_buf_push_overwrite.rs index 4522bf453902..e3f2de3cd466 100644 --- a/clippy_lints/src/methods/path_buf_push_overwrite.rs +++ b/clippy_lints/src/methods/path_buf_push_overwrite.rs @@ -14,7 +14,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arg: &'t if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if is_type_diagnostic_item(cx, cx.tcx.bound_type_of(impl_id).subst_identity(), sym::PathBuf); + if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).subst_identity(), sym::PathBuf); if let ExprKind::Lit(ref lit) = arg.kind; if let LitKind::Str(ref path_lit, _) = lit.node; if let pushed_path = Path::new(path_lit.as_str()); diff --git a/clippy_lints/src/methods/stable_sort_primitive.rs b/clippy_lints/src/methods/stable_sort_primitive.rs index 6a0bf1560c33..b5fd0ad8ce52 100644 --- a/clippy_lints/src/methods/stable_sort_primitive.rs +++ b/clippy_lints/src/methods/stable_sort_primitive.rs @@ -10,7 +10,7 @@ use super::STABLE_SORT_PRIMITIVE; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) && let Some(impl_id) = cx.tcx.impl_of_method(method_id) - && cx.tcx.bound_type_of(impl_id).subst_identity().is_slice() + && cx.tcx.type_of(impl_id).subst_identity().is_slice() && let Some(slice_type) = is_slice_of_primitives(cx, recv) { span_lint_and_then( diff --git a/clippy_lints/src/methods/suspicious_splitn.rs b/clippy_lints/src/methods/suspicious_splitn.rs index 17f422d0e699..90ca66bd70c5 100644 --- a/clippy_lints/src/methods/suspicious_splitn.rs +++ b/clippy_lints/src/methods/suspicious_splitn.rs @@ -13,7 +13,7 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se if let Some(call_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(call_id); if cx.tcx.impl_trait_ref(impl_id).is_none(); - let self_ty = cx.tcx.bound_type_of(impl_id).subst_identity(); + let self_ty = cx.tcx.type_of(impl_id).subst_identity(); if self_ty.is_slice() || self_ty.is_str(); then { // Ignore empty slice and string literals when used with a literal count. diff --git a/clippy_lints/src/methods/unnecessary_sort_by.rs b/clippy_lints/src/methods/unnecessary_sort_by.rs index 436e637201a0..5201da52bbf1 100644 --- a/clippy_lints/src/methods/unnecessary_sort_by.rs +++ b/clippy_lints/src/methods/unnecessary_sort_by.rs @@ -122,7 +122,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: &Exp if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if cx.tcx.bound_type_of(impl_id).subst_identity().is_slice(); + if cx.tcx.type_of(impl_id).subst_identity().is_slice(); if let ExprKind::Closure(&Closure { body, .. }) = arg.kind; if let closure_body = cx.tcx.hir().body(body); if let &[ diff --git a/clippy_lints/src/methods/utils.rs b/clippy_lints/src/methods/utils.rs index 5959fdb6625f..c96d69226972 100644 --- a/clippy_lints/src/methods/utils.rs +++ b/clippy_lints/src/methods/utils.rs @@ -143,7 +143,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for CloneOrCopyVisitor<'cx, 'tcx> { if_chain! { if args.iter().all(|arg| !self.is_binding(arg)); if let Some(method_def_id) = self.cx.typeck_results().type_dependent_def_id(parent.hir_id); - let method_ty = self.cx.tcx.bound_type_of(method_def_id).subst_identity(); + let method_ty = self.cx.tcx.type_of(method_def_id).subst_identity(); let self_ty = method_ty.fn_sig(self.cx.tcx).input(0).skip_binder(); if matches!(self_ty.kind(), ty::Ref(_, _, Mutability::Not)); then { diff --git a/clippy_lints/src/methods/vec_resize_to_zero.rs b/clippy_lints/src/methods/vec_resize_to_zero.rs index 8c461b2629d7..b0cfc163fd08 100644 --- a/clippy_lints/src/methods/vec_resize_to_zero.rs +++ b/clippy_lints/src/methods/vec_resize_to_zero.rs @@ -20,7 +20,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if is_type_diagnostic_item(cx, cx.tcx.bound_type_of(impl_id).subst_identity(), sym::Vec); + if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).subst_identity(), sym::Vec); if let ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = count_arg.kind; if let ExprKind::Lit(Spanned { node: LitKind::Int(..), .. }) = default_arg.kind; then { diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 4547ed7eafc8..e91aac41bc48 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -52,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed { ExprKind::MethodCall(path, receiver, arguments, _) => { let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap(); let substs = cx.typeck_results().node_substs(e.hir_id); - let method_type = cx.tcx.bound_type_of(def_id).subst(cx.tcx, substs); + let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs); check_arguments( cx, std::iter::once(receiver).chain(arguments.iter()).collect(), diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 47dc4b276a27..653b1a8a05f6 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -98,14 +98,14 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { if name == sym::new; if cx.effective_visibilities.is_reachable(impl_item.owner_id.def_id); let self_def_id = cx.tcx.hir().get_parent_item(id.into()); - let self_ty = cx.tcx.bound_type_of(self_def_id).subst_identity(); + let self_ty = cx.tcx.type_of(self_def_id).subst_identity(); if self_ty == return_ty(cx, id); if let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default); then { if self.impling_types.is_none() { let mut impls = HirIdSet::default(); cx.tcx.for_each_impl(default_trait_id, |d| { - let ty = cx.tcx.bound_type_of(d).subst_identity(); + let ty = cx.tcx.type_of(d).subst_identity(); if let Some(ty_def) = ty.ty_adt_def() { if let Some(local_def_id) = ty_def.did().as_local() { impls.insert(cx.tcx.hir().local_def_id_to_hir_id(local_def_id)); @@ -119,7 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { // generics if_chain! { if let Some(ref impling_types) = self.impling_types; - let self_def = cx.tcx.bound_type_of(self_def_id).subst_identity(); + let self_def = cx.tcx.type_of(self_def_id).subst_identity(); if let Some(self_def) = self_def.ty_adt_def(); if let Some(self_local_did) = self_def.did().as_local(); let self_id = cx.tcx.hir().local_def_id_to_hir_id(self_local_did); diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index a076bed50d1b..0bedab05eec6 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -313,7 +313,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { // and, in that case, the definition is *not* generic. cx.tcx.normalize_erasing_regions( cx.tcx.param_env(of_trait_def_id), - cx.tcx.bound_type_of(of_assoc_item).subst_identity(), + cx.tcx.type_of(of_assoc_item).subst_identity(), ), )) .is_err(); diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index df834962673d..beca203c868d 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(parent); - let self_ty = cx.tcx.bound_type_of(item.owner_id).subst_identity(); + let self_ty = cx.tcx.type_of(item.owner_id).subst_identity(); let ret_ty = return_ty(cx, impl_item.owner_id); // Do not check trait impls diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index af0242348ac2..5e24213d07fd 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -273,7 +273,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> .non_enum_variant() .fields .iter() - .map(|f| cx.tcx.bound_type_of(f.did).subst(cx.tcx, substs)); + .map(|f| cx.tcx.type_of(f.did).subst(cx.tcx, substs)); let Some(sized_ty) = iter.find(|&ty| !is_zero_sized_ty(cx, ty)) else { return ReducedTy::TypeErasure { raw_ptr_only: false }; }; diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index a50b38c54dca..e7c54000684a 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -218,7 +218,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { } else { hir_ty_to_ty(cx.tcx, hir_ty) }; - if same_type_and_consts(ty, cx.tcx.bound_type_of(impl_id).subst_identity()); + if same_type_and_consts(ty, cx.tcx.type_of(impl_id).subst_identity()); then { span_lint(cx, hir_ty.span); } @@ -230,7 +230,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { if !expr.span.from_expansion(); if self.msrv.meets(msrvs::TYPE_ALIAS_ENUM_VARIANTS); if let Some(&StackItem::Check { impl_id, .. }) = self.stack.last(); - if cx.typeck_results().expr_ty(expr) == cx.tcx.bound_type_of(impl_id).subst_identity(); + if cx.typeck_results().expr_ty(expr) == cx.tcx.type_of(impl_id).subst_identity(); then {} else { return; } } match expr.kind { @@ -254,7 +254,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { if let PatKind::Path(QPath::Resolved(_, path)) | PatKind::TupleStruct(QPath::Resolved(_, path), _, _) | PatKind::Struct(QPath::Resolved(_, path), _, _) = pat.kind; - if cx.typeck_results().pat_ty(pat) == cx.tcx.bound_type_of(impl_id).subst_identity(); + if cx.typeck_results().pat_ty(pat) == cx.tcx.type_of(impl_id).subst_identity(); then { check_path(cx, path); } diff --git a/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs b/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs index f62bfa4f2217..688a8b865f32 100644 --- a/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs +++ b/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs @@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol { for item in cx.tcx.module_children(def_id).iter() { if_chain! { if let Res::Def(DefKind::Const, item_def_id) = item.res; - let ty = cx.tcx.bound_type_of(item_def_id).subst_identity(); + let ty = cx.tcx.type_of(item_def_id).subst_identity(); if match_type(cx, ty, &paths::SYMBOL); if let Ok(ConstValue::Scalar(value)) = cx.tcx.const_eval_poly(item_def_id); if let Ok(value) = value.to_u32(); diff --git a/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs b/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs index 3249b8633914..09f0f0d0adb6 100644 --- a/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs +++ b/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs @@ -38,7 +38,7 @@ impl LateLintPass<'_> for MsrvAttrImpl { if self_ty_def.is_struct(); if self_ty_def.all_fields().any(|f| { cx.tcx - .bound_type_of(f.did) + .type_of(f.did) .subst_identity() .walk() .filter(|t| matches!(t.unpack(), GenericArgKind::Type(_))) diff --git a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs index 3f08566dbcc7..ee5e42bae0f1 100644 --- a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs +++ b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs @@ -229,11 +229,11 @@ fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option read_mir_alloc_def_path( cx, cx.tcx.eval_static_initializer(def_id).ok()?.inner(), - cx.tcx.bound_type_of(def_id).subst_identity(), + cx.tcx.type_of(def_id).subst_identity(), ), Res::Def(DefKind::Const, def_id) => match cx.tcx.const_eval_poly(def_id).ok()? { ConstValue::ByRef { alloc, offset } if offset.bytes() == 0 => { - read_mir_alloc_def_path(cx, alloc.inner(), cx.tcx.bound_type_of(def_id).subst_identity()) + read_mir_alloc_def_path(cx, alloc.inner(), cx.tcx.type_of(def_id).subst_identity()) }, _ => None, }, diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 97b2cc382b0d..6ff7728374f8 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -50,7 +50,7 @@ fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg: let name = name.as_str(); let ty = match cx.tcx.impl_of_method(fn_id) { - Some(id) => cx.tcx.bound_type_of(id).subst_identity(), + Some(id) => cx.tcx.type_of(id).subst_identity(), None => return Lazy, }; @@ -71,7 +71,7 @@ fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg: .variants() .iter() .flat_map(|v| v.fields.iter()) - .any(|x| matches!(cx.tcx.bound_type_of(x.did).subst_identity().peel_refs().kind(), ty::Param(_))) + .any(|x| matches!(cx.tcx.type_of(x.did).subst_identity().peel_refs().kind(), ty::Param(_))) && all_predicates_of(cx.tcx, fn_id).all(|(pred, _)| match pred.kind().skip_binder() { PredicateKind::Clause(ty::Clause::Trait(pred)) => cx.tcx.trait_def(pred.trait_ref.def_id).is_marker, _ => true, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 168055657755..b2edd1bbfef4 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -317,7 +317,7 @@ pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str]) /// Checks if a method is defined in an impl of a diagnostic item pub fn is_diag_item_method(cx: &LateContext<'_>, def_id: DefId, diag_item: Symbol) -> bool { if let Some(impl_did) = cx.tcx.impl_of_method(def_id) { - if let Some(adt) = cx.tcx.bound_type_of(impl_did).subst_identity().ty_adt_def() { + if let Some(adt) = cx.tcx.type_of(impl_did).subst_identity().ty_adt_def() { return cx.tcx.is_diagnostic_item(diag_item, adt.did()); } } @@ -812,7 +812,7 @@ fn is_default_equivalent_ctor(cx: &LateContext<'_>, def_id: DefId, path: &QPath< if let QPath::TypeRelative(_, method) = path { if method.ident.name == sym::new { if let Some(impl_did) = cx.tcx.impl_of_method(def_id) { - if let Some(adt) = cx.tcx.bound_type_of(impl_did).subst_identity().ty_adt_def() { + if let Some(adt) = cx.tcx.type_of(impl_did).subst_identity().ty_adt_def() { return std_types_symbols.iter().any(|&symbol| { cx.tcx.is_diagnostic_item(symbol, adt.did()) || Some(adt.did()) == cx.tcx.lang_items().string() }); diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 6987d1d2d65a..2ed301fcc229 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -780,7 +780,7 @@ impl core::ops::Add for EnumValue { #[expect(clippy::cast_possible_truncation, clippy::cast_possible_wrap)] pub fn read_explicit_enum_value(tcx: TyCtxt<'_>, id: DefId) -> Option { if let Ok(ConstValue::Scalar(Scalar::Int(value))) = tcx.const_eval_poly(id) { - match tcx.bound_type_of(id).subst_identity().kind() { + match tcx.type_of(id).subst_identity().kind() { ty::Int(_) => Some(EnumValue::Signed(match value.size().bytes() { 1 => i128::from(value.assert_bits(Size::from_bytes(1)) as u8 as i8), 2 => i128::from(value.assert_bits(Size::from_bytes(2)) as u16 as i16), @@ -903,7 +903,7 @@ pub fn variant_of_res<'tcx>(cx: &LateContext<'tcx>, res: Res) -> Option<&'tcx Va let var_id = cx.tcx.parent(id); Some(cx.tcx.adt_def(cx.tcx.parent(var_id)).variant_with_id(var_id)) }, - Res::SelfCtor(id) => Some(cx.tcx.bound_type_of(id).subst_identity().ty_adt_def().unwrap().non_enum_variant()), + Res::SelfCtor(id) => Some(cx.tcx.type_of(id).subst_identity().ty_adt_def().unwrap().non_enum_variant()), _ => None, } } From 9100014787ec499a0bb31d15bdca80ea82648ad1 Mon Sep 17 00:00:00 2001 From: Boxy Date: Thu, 16 Feb 2023 11:55:58 +0000 Subject: [PATCH 0753/1222] Add `Clause::ConstArgHasType` variant --- clippy_utils/src/qualify_min_const_fn.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 26b1d0197499..1a35fe05067f 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -30,7 +30,8 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv) ty::Clause::RegionOutlives(_) | ty::Clause::TypeOutlives(_) | ty::Clause::Projection(_) - | ty::Clause::Trait(..), + | ty::Clause::Trait(..) + | ty::Clause::ConstArgHasType(..), ) | ty::PredicateKind::WellFormed(_) | ty::PredicateKind::ConstEvaluatable(..) From a88be08a4d5cb781b00bd3362169d88a74136773 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 16 Feb 2023 11:47:50 +1100 Subject: [PATCH 0754/1222] Replace `mk_foo` calls with `infer_foo` where possible. There are several `mk_foo`/`intern_foo` pairs, where the former takes an iterator and the latter takes a slice. (This naming convention is bad, but that's a fix for another PR.) This commit changes several `mk_foo` occurrences into `intern_foo`, avoiding the need for some `.iter()`/`.into_iter()` calls. Affected cases: - mk_type_list - mk_tup - mk_substs - mk_const_list --- clippy_lints/src/methods/needless_collect.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index 82d3b830d4f3..8ddbacc3d7ad 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -173,7 +173,7 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) - && let Some(iter_item) = cx.tcx .associated_items(iter_trait) .find_by_name_and_kind(cx.tcx, Ident::with_dummy_span(Symbol::intern("Item")), AssocKind::Type, iter_trait) - && let substs = cx.tcx.mk_substs([GenericArg::from(typeck.expr_ty_adjusted(iter_expr))].into_iter()) + && let substs = cx.tcx.intern_substs(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))]) && let proj_ty = cx.tcx.mk_projection(iter_item.def_id, substs) && let Ok(item_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, proj_ty) { From aa1b4ac945cb0b7f9b69399a48ccc9c5fadd7ea8 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 16 Feb 2023 16:27:05 +1100 Subject: [PATCH 0755/1222] Replace more `mk_foo` calls with `infer_foo`. --- clippy_lints/src/redundant_slicing.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/clippy_lints/src/redundant_slicing.rs b/clippy_lints/src/redundant_slicing.rs index 245a02ea26e6..398329e455bf 100644 --- a/clippy_lints/src/redundant_slicing.rs +++ b/clippy_lints/src/redundant_slicing.rs @@ -11,8 +11,6 @@ use rustc_middle::ty::adjustment::{Adjust, AutoBorrow, AutoBorrowMutability}; use rustc_middle::ty::subst::GenericArg; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use std::iter; - declare_clippy_lint! { /// ### What it does /// Checks for redundant slicing expressions which use the full range, and @@ -136,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing { } else if let Some(target_id) = cx.tcx.lang_items().deref_target() { if let Ok(deref_ty) = cx.tcx.try_normalize_erasing_regions( cx.param_env, - cx.tcx.mk_projection(target_id, cx.tcx.mk_substs(iter::once(GenericArg::from(indexed_ty)))), + cx.tcx.mk_projection(target_id, cx.tcx.intern_substs(&[GenericArg::from(indexed_ty)])), ) { if deref_ty == expr_ty { let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0; From 91b4f7b07392a1f5aec059ed745269ac92541b10 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 23 Nov 2022 11:55:16 +1100 Subject: [PATCH 0756/1222] Use `ThinVec` in various AST types. This commit changes the sequence parsers to produce `ThinVec`, which triggers numerous conversions. --- clippy_lints/src/lib.rs | 1 + clippy_lints/src/unnested_or_patterns.rs | 50 ++++++++++++++++-------- clippy_utils/src/ast_utils.rs | 3 +- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 565c5b7af006..9011f0896a05 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -42,6 +42,7 @@ extern crate rustc_session; extern crate rustc_span; extern crate rustc_target; extern crate rustc_trait_selection; +extern crate thin_vec; #[macro_use] extern crate clippy_utils; diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 7355260ae4af..06d248204c1f 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -12,9 +12,9 @@ use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::DUMMY_SP; - use std::cell::Cell; use std::mem; +use thin_vec::{thin_vec, ThinVec}; declare_clippy_lint! { /// ### What it does @@ -214,7 +214,7 @@ macro_rules! always_pat { /// Focus on `focus_idx` in `alternatives`, /// attempting to extend it with elements of the same constructor `C` /// in `alternatives[focus_idx + 1..]`. -fn transform_with_focus_on_idx(alternatives: &mut Vec>, focus_idx: usize) -> bool { +fn transform_with_focus_on_idx(alternatives: &mut ThinVec>, focus_idx: usize) -> bool { // Extract the kind; we'll need to make some changes in it. let mut focus_kind = mem::replace(&mut alternatives[focus_idx].kind, PatKind::Wild); // We'll focus on `alternatives[focus_idx]`, @@ -296,7 +296,7 @@ fn extend_with_struct_pat( fps1: &mut [ast::PatField], rest1: bool, start: usize, - alternatives: &mut Vec>, + alternatives: &mut ThinVec>, ) -> bool { (0..fps1.len()).any(|idx| { let pos_in_2 = Cell::new(None); // The element `k`. @@ -336,9 +336,9 @@ fn extend_with_struct_pat( fn extend_with_matching_product( targets: &mut [P], start: usize, - alternatives: &mut Vec>, + alternatives: &mut ThinVec>, predicate: impl Fn(&PatKind, &[P], usize) -> bool, - extract: impl Fn(PatKind) -> Vec>, + extract: impl Fn(PatKind) -> ThinVec>, ) -> bool { (0..targets.len()).any(|idx| { let tail_or = drain_matching( @@ -365,14 +365,14 @@ fn take_pat(from: &mut Pat) -> Pat { /// Extend `target` as an or-pattern with the alternatives /// in `tail_or` if there are any and return if there were. -fn extend_with_tail_or(target: &mut Pat, tail_or: Vec>) -> bool { - fn extend(target: &mut Pat, mut tail_or: Vec>) { +fn extend_with_tail_or(target: &mut Pat, tail_or: ThinVec>) -> bool { + fn extend(target: &mut Pat, mut tail_or: ThinVec>) { match target { // On an existing or-pattern in the target, append to it. Pat { kind: Or(ps), .. } => ps.append(&mut tail_or), // Otherwise convert the target to an or-pattern. target => { - let mut init_or = vec![P(take_pat(target))]; + let mut init_or = thin_vec![P(take_pat(target))]; init_or.append(&mut tail_or); target.kind = Or(init_or); }, @@ -391,26 +391,42 @@ fn extend_with_tail_or(target: &mut Pat, tail_or: Vec>) -> bool { // Only elements beginning with `start` are considered for extraction. fn drain_matching( start: usize, - alternatives: &mut Vec>, + alternatives: &mut ThinVec>, predicate: impl Fn(&PatKind) -> bool, extract: impl Fn(PatKind) -> P, -) -> Vec> { - let mut tail_or = vec![]; +) -> ThinVec> { + let mut tail_or = ThinVec::new(); let mut idx = 0; - for pat in alternatives.drain_filter(|p| { - // Check if we should extract, but only if `idx >= start`. + + // If `ThinVec` had the `drain_filter` method, this loop could be rewritten + // like so: + // + // for pat in alternatives.drain_filter(|p| { + // // Check if we should extract, but only if `idx >= start`. + // idx += 1; + // idx > start && predicate(&p.kind) + // }) { + // tail_or.push(extract(pat.into_inner().kind)); + // } + let mut i = 0; + while i < alternatives.len() { idx += 1; - idx > start && predicate(&p.kind) - }) { - tail_or.push(extract(pat.into_inner().kind)); + // Check if we should extract, but only if `idx >= start`. + if idx > start && predicate(&alternatives[i].kind) { + let pat = alternatives.remove(i); + tail_or.push(extract(pat.into_inner().kind)); + } else { + i += 1; + } } + tail_or } fn extend_with_matching( target: &mut Pat, start: usize, - alternatives: &mut Vec>, + alternatives: &mut ThinVec>, predicate: impl Fn(&PatKind) -> bool, extract: impl Fn(PatKind) -> P, ) -> bool { diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 9d0263e93be7..d82098523e3b 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -144,7 +144,8 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (_, Paren(r)) => eq_expr(l, r), (Err, Err) => true, (Box(l), Box(r)) | (Try(l), Try(r)) | (Await(l), Await(r)) => eq_expr(l, r), - (Array(l), Array(r)) | (Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)), + (Array(l), Array(r)) => over(l, r, |l, r| eq_expr(l, r)), + (Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)), (Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value), (Call(lc, la), Call(rc, ra)) => eq_expr(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)), ( From 1502bd3d424f1e7d2a19987b44445dd3d98e1737 Mon Sep 17 00:00:00 2001 From: David Wood Date: Thu, 13 Oct 2022 10:13:02 +0100 Subject: [PATCH 0757/1222] errors: generate typed identifiers in each crate Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter. Signed-off-by: David Wood --- clippy_lints/src/doc.rs | 2 +- src/driver.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 0b31e20fc87c..660dd8391a30 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -705,7 +705,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let fallback_bundle = - rustc_errors::fallback_fluent_bundle(rustc_errors::DEFAULT_LOCALE_RESOURCES, false); + rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES, false); let emitter = EmitterWriter::new( Box::new(io::sink()), None, diff --git a/src/driver.rs b/src/driver.rs index e45835efe746..45209fb8519e 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -209,7 +209,7 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { // Separate the output with an empty line eprintln!(); - let fallback_bundle = rustc_errors::fallback_fluent_bundle(rustc_errors::DEFAULT_LOCALE_RESOURCES, false); + let fallback_bundle = rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES, false); let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr( rustc_errors::ColorConfig::Auto, None, From 596d6b52109549e2eb8eecec865ee44587bb340b Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 17 Oct 2022 14:11:26 +0100 Subject: [PATCH 0758/1222] various: translation resources from cg backend Extend `CodegenBackend` trait with a function returning the translation resources from the codegen backend, which can be added to the complete list of resources provided to the emitter. Signed-off-by: David Wood --- clippy_lints/src/doc.rs | 6 ++++-- src/driver.rs | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 660dd8391a30..6fdb7de25ccc 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -704,8 +704,10 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { let filename = FileName::anon_source_code(&code); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let fallback_bundle = - rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES, false); + let fallback_bundle = rustc_errors::fallback_fluent_bundle( + rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), + false + ); let emitter = EmitterWriter::new( Box::new(io::sink()), None, diff --git a/src/driver.rs b/src/driver.rs index 45209fb8519e..9ac849aecf1a 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -209,7 +209,10 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { // Separate the output with an empty line eprintln!(); - let fallback_bundle = rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES, false); + let fallback_bundle = rustc_errors::fallback_fluent_bundle( + rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), + false + ); let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr( rustc_errors::ColorConfig::Auto, None, From 5a73334f0fed9a01f960af100838e645b7220944 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 21 Feb 2023 14:12:02 -0700 Subject: [PATCH 0759/1222] clippy: update clippy to use new `TyCtxt::def_descr` --- tests/ui/missing_doc_impl.stderr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/missing_doc_impl.stderr b/tests/ui/missing_doc_impl.stderr index f22fa19dbcab..b410f56e1671 100644 --- a/tests/ui/missing_doc_impl.stderr +++ b/tests/ui/missing_doc_impl.stderr @@ -51,13 +51,13 @@ LL | | fn foo_with_impl(&self) {} LL | | } | |_^ -error: missing documentation for an associated function +error: missing documentation for a method --> $DIR/missing_doc_impl.rs:44:5 | LL | fn foo(&self); | ^^^^^^^^^^^^^^ -error: missing documentation for an associated function +error: missing documentation for a method --> $DIR/missing_doc_impl.rs:45:5 | LL | fn foo_with_impl(&self) {} From 30ecfa35d0fce05ad5779452fcb4d31dc1e01ea6 Mon Sep 17 00:00:00 2001 From: Alan Egerton Date: Wed, 22 Feb 2023 02:18:40 +0000 Subject: [PATCH 0760/1222] Remove type-traversal trait aliases --- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/eta_reduction.rs | 2 +- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/transmute/transmute_ptr_to_ref.rs | 2 +- clippy_lints/src/transmute/useless_transmute.rs | 2 +- clippy_lints/src/types/redundant_allocation.rs | 2 +- clippy_lints/src/types/vec_box.rs | 2 +- clippy_lints/src/zero_sized_map_values.rs | 2 +- clippy_utils/src/lib.rs | 2 +- clippy_utils/src/mir/possible_borrower.rs | 2 +- clippy_utils/src/ty.rs | 6 +++--- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index b4543aa2544f..ef46e23123b9 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -27,7 +27,7 @@ use rustc_middle::mir::{Rvalue, StatementKind}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability}; use rustc_middle::ty::{ self, Binder, BoundVariableKind, Clause, EarlyBinder, FnSig, GenericArgKind, List, ParamTy, PredicateKind, - ProjectionPredicate, Ty, TyCtxt, TypeVisitable, TypeckResults, + ProjectionPredicate, Ty, TyCtxt, TypeVisitableExt, TypeckResults, }; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{symbol::sym, Span, Symbol}; diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index ddade65c515c..b2071f4dcb1e 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -11,7 +11,7 @@ use rustc_hir::{Closure, Expr, ExprKind, Param, PatKind, Unsafety}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; use rustc_middle::ty::binding::BindingMode; -use rustc_middle::ty::{self, EarlyBinder, SubstsRef, Ty, TypeVisitable}; +use rustc_middle::ty::{self, EarlyBinder, SubstsRef, Ty, TypeVisitableExt}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 3cc765108d7c..5a533261cad8 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -3,7 +3,7 @@ use clippy_utils::{def_path_def_ids, trait_ref_of_method}; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::TypeVisitable; +use rustc_middle::ty::TypeVisitableExt; use rustc_middle::ty::{Adt, Array, Ref, Slice, Tuple, Ty}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::def_id::LocalDefId; diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 996ea6ed7231..da3b6fa9899d 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -18,7 +18,7 @@ use rustc_hir_typeck::expr_use_visitor as euv; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::FakeReadCause; -use rustc_middle::ty::{self, TypeVisitable}; +use rustc_middle::ty::{self, TypeVisitableExt}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::kw; diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs index 54ac04df1c12..6bdb9aa5a26d 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs @@ -6,7 +6,7 @@ use clippy_utils::sugg; use rustc_errors::Applicability; use rustc_hir::{self as hir, Expr, GenericArg, Mutability, Path, TyKind}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty, TypeVisitable}; +use rustc_middle::ty::{self, Ty, TypeVisitableExt}; /// Checks for `transmute_ptr_to_ref` lint. /// Returns `true` if it's triggered, otherwise returns `false`. diff --git a/clippy_lints/src/transmute/useless_transmute.rs b/clippy_lints/src/transmute/useless_transmute.rs index 871c3fadbba7..56207fe767c5 100644 --- a/clippy_lints/src/transmute/useless_transmute.rs +++ b/clippy_lints/src/transmute/useless_transmute.rs @@ -4,7 +4,7 @@ use clippy_utils::sugg; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty, TypeVisitable}; +use rustc_middle::ty::{self, Ty, TypeVisitableExt}; /// Checks for `useless_transmute` lint. /// Returns `true` if it's triggered, otherwise returns `false`. diff --git a/clippy_lints/src/types/redundant_allocation.rs b/clippy_lints/src/types/redundant_allocation.rs index f9b9a66b5fa4..f7adc9d35558 100644 --- a/clippy_lints/src/types/redundant_allocation.rs +++ b/clippy_lints/src/types/redundant_allocation.rs @@ -5,7 +5,7 @@ use rustc_errors::Applicability; use rustc_hir::{self as hir, def_id::DefId, QPath, TyKind}; use rustc_hir_analysis::hir_ty_to_ty; use rustc_lint::LateContext; -use rustc_middle::ty::TypeVisitable; +use rustc_middle::ty::TypeVisitableExt; use rustc_span::symbol::sym; use super::{utils, REDUNDANT_ALLOCATION}; diff --git a/clippy_lints/src/types/vec_box.rs b/clippy_lints/src/types/vec_box.rs index 7a3c7cd8a99f..d3062f3d2e36 100644 --- a/clippy_lints/src/types/vec_box.rs +++ b/clippy_lints/src/types/vec_box.rs @@ -7,7 +7,7 @@ use rustc_hir::{self as hir, def_id::DefId, GenericArg, QPath, TyKind}; use rustc_hir_analysis::hir_ty_to_ty; use rustc_lint::LateContext; use rustc_middle::ty::layout::LayoutOf; -use rustc_middle::ty::TypeVisitable; +use rustc_middle::ty::TypeVisitableExt; use rustc_span::symbol::sym; use super::VEC_BOX; diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 6cf2a955fd5c..93e4b023c5c7 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -5,7 +5,7 @@ use rustc_hir::{self as hir, HirId, ItemKind, Node}; use rustc_hir_analysis::hir_ty_to_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::layout::LayoutOf as _; -use rustc_middle::ty::{Adt, Ty, TypeVisitable}; +use rustc_middle::ty::{Adt, Ty, TypeVisitableExt}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index b2edd1bbfef4..f02f8ecb43d7 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -104,7 +104,7 @@ use rustc_middle::ty::fast_reject::SimplifiedType::{ PtrSimplifiedType, SliceSimplifiedType, StrSimplifiedType, UintSimplifiedType, }; use rustc_middle::ty::{ - layout::IntegerExt, BorrowKind, ClosureKind, DefIdTree, Ty, TyCtxt, TypeAndMut, TypeVisitable, UpvarCapture, + layout::IntegerExt, BorrowKind, ClosureKind, DefIdTree, Ty, TyCtxt, TypeAndMut, TypeVisitableExt, UpvarCapture, }; use rustc_middle::ty::{FloatTy, IntTy, UintTy}; use rustc_span::hygiene::{ExpnKind, MacroKind}; diff --git a/clippy_utils/src/mir/possible_borrower.rs b/clippy_utils/src/mir/possible_borrower.rs index e9dc7351b58e..920ce8e655be 100644 --- a/clippy_utils/src/mir/possible_borrower.rs +++ b/clippy_utils/src/mir/possible_borrower.rs @@ -4,7 +4,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_index::bit_set::{BitSet, HybridBitSet}; use rustc_lint::LateContext; use rustc_middle::mir::{self, visit::Visitor as _, Mutability}; -use rustc_middle::ty::{self, visit::ir::TypeVisitor, TyCtxt}; +use rustc_middle::ty::{self, visit::TypeVisitor, TyCtxt}; use rustc_mir_dataflow::{impls::MaybeStorageLive, Analysis, ResultsCursor}; use std::borrow::Cow; use std::ops::ControlFlow; diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 2ed301fcc229..34b9bb5994ef 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -17,8 +17,8 @@ use rustc_lint::LateContext; use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::ty::{ self, AdtDef, AliasTy, AssocKind, Binder, BoundRegion, DefIdTree, FnSig, IntTy, List, ParamEnv, Predicate, - PredicateKind, Region, RegionKind, SubstsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, ir::TypeVisitor, UintTy, - VariantDef, VariantDiscr, + PredicateKind, Region, RegionKind, SubstsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy, + VariantDef, VariantDiscr, TypeVisitableExt, }; use rustc_middle::ty::{GenericArg, GenericArgKind}; use rustc_span::symbol::Ident; @@ -847,7 +847,7 @@ pub fn for_each_top_level_late_bound_region( ControlFlow::Continue(()) } } - fn visit_binder>(&mut self, t: &Binder<'tcx, T>) -> ControlFlow { + fn visit_binder>>(&mut self, t: &Binder<'tcx, T>) -> ControlFlow { self.index += 1; let res = t.super_visit_with(self); self.index -= 1; From 074197161025abf8f6e4ad7a6fafdf9d6513e7f6 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 17 Feb 2023 14:33:08 +1100 Subject: [PATCH 0761/1222] Rename many interner functions. (This is a large commit. The changes to `compiler/rustc_middle/src/ty/context.rs` are the most important ones.) The current naming scheme is a mess, with a mix of `_intern_`, `intern_` and `mk_` prefixes, with little consistency. In particular, in many cases it's easy to use an iterator interner when a (preferable) slice interner is available. The guiding principles of the new naming system: - No `_intern_` prefixes. - The `intern_` prefix is for internal operations. - The `mk_` prefix is for external operations. - For cases where there is a slice interner and an iterator interner, the former is `mk_foo` and the latter is `mk_foo_from_iter`. Also, `slice_interners!` and `direct_interners!` can now be `pub` or non-`pub`, which helps enforce the internal/external operations division. It's not perfect, but I think it's a clear improvement. The following lists show everything that was renamed. slice_interners - const_list - mk_const_list -> mk_const_list_from_iter - intern_const_list -> mk_const_list - substs - mk_substs -> mk_substs_from_iter - intern_substs -> mk_substs - check_substs -> check_and_mk_substs (this is a weird one) - canonical_var_infos - intern_canonical_var_infos -> mk_canonical_var_infos - poly_existential_predicates - mk_poly_existential_predicates -> mk_poly_existential_predicates_from_iter - intern_poly_existential_predicates -> mk_poly_existential_predicates - _intern_poly_existential_predicates -> intern_poly_existential_predicates - predicates - mk_predicates -> mk_predicates_from_iter - intern_predicates -> mk_predicates - _intern_predicates -> intern_predicates - projs - intern_projs -> mk_projs - place_elems - mk_place_elems -> mk_place_elems_from_iter - intern_place_elems -> mk_place_elems - bound_variable_kinds - mk_bound_variable_kinds -> mk_bound_variable_kinds_from_iter - intern_bound_variable_kinds -> mk_bound_variable_kinds direct_interners - region - intern_region (unchanged) - const - mk_const_internal -> intern_const - const_allocation - intern_const_alloc -> mk_const_alloc - layout - intern_layout -> mk_layout - adt_def - intern_adt_def -> mk_adt_def_from_data (unusual case, hard to avoid) - alloc_adt_def(!) -> mk_adt_def - external_constraints - intern_external_constraints -> mk_external_constraints Other - type_list - mk_type_list -> mk_type_list_from_iter - intern_type_list -> mk_type_list - tup - mk_tup -> mk_tup_from_iter - intern_tup -> mk_tup --- clippy_lints/src/derive.rs | 2 +- clippy_lints/src/methods/needless_collect.rs | 2 +- clippy_lints/src/methods/unnecessary_to_owned.rs | 2 +- clippy_lints/src/redundant_slicing.rs | 2 +- clippy_utils/src/consts.rs | 4 ++-- clippy_utils/src/ty.rs | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 1cdcccd5f146..b8428d66a5dc 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -514,7 +514,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> } ParamEnv::new( - tcx.mk_predicates(ty_predicates.iter().map(|&(p, _)| p).chain( + tcx.mk_predicates_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain( params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| { tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate { trait_ref: tcx.mk_trait_ref(eq_trait_id, [tcx.mk_param_from_def(param)]), diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index 8ddbacc3d7ad..0b0c6adc5045 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -173,7 +173,7 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) - && let Some(iter_item) = cx.tcx .associated_items(iter_trait) .find_by_name_and_kind(cx.tcx, Ident::with_dummy_span(Symbol::intern("Item")), AssocKind::Type, iter_trait) - && let substs = cx.tcx.intern_substs(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))]) + && let substs = cx.tcx.mk_substs(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))]) && let proj_ty = cx.tcx.mk_projection(iter_item.def_id, substs) && let Ok(item_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, proj_ty) { diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 4e5af1c7c712..df26b36b7b32 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -414,7 +414,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< } }); - let new_subst = cx.tcx.mk_substs( + let new_subst = cx.tcx.mk_substs_from_iter( call_substs.iter() .enumerate() .map(|(i, t)| diff --git a/clippy_lints/src/redundant_slicing.rs b/clippy_lints/src/redundant_slicing.rs index 398329e455bf..2fdd775ad489 100644 --- a/clippy_lints/src/redundant_slicing.rs +++ b/clippy_lints/src/redundant_slicing.rs @@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing { } else if let Some(target_id) = cx.tcx.lang_items().deref_target() { if let Ok(deref_ty) = cx.tcx.try_normalize_erasing_regions( cx.param_env, - cx.tcx.mk_projection(target_id, cx.tcx.intern_substs(&[GenericArg::from(indexed_ty)])), + cx.tcx.mk_projection(target_id, cx.tcx.mk_substs(&[GenericArg::from(indexed_ty)])), ) { if deref_ty == expr_ty { let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0; diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 8b00ce2cc258..e3bfffacb525 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -237,7 +237,7 @@ pub fn constant<'tcx>( typeck_results, param_env: lcx.param_env, needed_resolution: false, - substs: lcx.tcx.intern_substs(&[]), + substs: lcx.tcx.mk_substs(&[]), }; cx.expr(e).map(|cst| (cst, cx.needed_resolution)) } @@ -306,7 +306,7 @@ pub fn constant_context<'a, 'tcx>( typeck_results, param_env: lcx.param_env, needed_resolution: false, - substs: lcx.tcx.intern_substs(&[]), + substs: lcx.tcx.mk_substs(&[]), } } diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 34b9bb5994ef..f8ec4bb54930 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -237,7 +237,7 @@ pub fn implements_trait_with_env<'tcx>( kind: TypeVariableOriginKind::MiscVariable, span: DUMMY_SP, }; - let ty_params = tcx.mk_substs( + let ty_params = tcx.mk_substs_from_iter( ty_params .into_iter() .map(|arg| arg.unwrap_or_else(|| infcx.next_ty_var(orig).into())), @@ -1065,7 +1065,7 @@ pub fn make_projection<'tcx>( tcx, container_id, assoc_ty, - tcx.mk_substs(substs.into_iter().map(Into::into)), + tcx.mk_substs_from_iter(substs.into_iter().map(Into::into)), ) } From d41659b01da3292b740779d26bd1e2fb0aae630f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 20 Feb 2023 14:52:23 +1100 Subject: [PATCH 0762/1222] Use `List::empty()` instead of `mk_substs(&[])`. --- clippy_utils/src/consts.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index e3bfffacb525..bb8890dcaf98 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -237,7 +237,7 @@ pub fn constant<'tcx>( typeck_results, param_env: lcx.param_env, needed_resolution: false, - substs: lcx.tcx.mk_substs(&[]), + substs: ty::List::empty(), }; cx.expr(e).map(|cst| (cst, cx.needed_resolution)) } @@ -306,7 +306,7 @@ pub fn constant_context<'a, 'tcx>( typeck_results, param_env: lcx.param_env, needed_resolution: false, - substs: lcx.tcx.mk_substs(&[]), + substs: ty::List::empty(), } } From 1d2825ce9917b1c92bb33b87db2f01261efc2e94 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 23 Feb 2023 02:46:49 +0000 Subject: [PATCH 0763/1222] Make clippy happy --- clippy_lints/src/dereference.rs | 4 ++-- clippy_lints/src/loops/never_loop.rs | 2 +- clippy_lints/src/matches/significant_drop_in_scrutinee.rs | 2 +- clippy_lints/src/utils/author.rs | 2 +- clippy_utils/src/eager_or_lazy.rs | 2 +- clippy_utils/src/hir_utils.rs | 4 ++-- clippy_utils/src/sugg.rs | 2 +- clippy_utils/src/visitors.rs | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index ef46e23123b9..644604a2e3f8 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1022,7 +1022,7 @@ fn binding_ty_auto_deref_stability<'tcx>( )) .is_sized(cx.tcx, cx.param_env.without_caller_bounds()), ), - TyKind::OpaqueDef(..) | TyKind::Infer | TyKind::Typeof(..) | TyKind::TraitObject(..) | TyKind::Err => { + TyKind::OpaqueDef(..) | TyKind::Infer | TyKind::Typeof(..) | TyKind::TraitObject(..) | TyKind::Err(_) => { Position::ReborrowStable(precedence) }, }; @@ -1038,7 +1038,7 @@ fn ty_contains_infer(ty: &hir::Ty<'_>) -> bool { if self.0 || matches!( ty.kind, - TyKind::OpaqueDef(..) | TyKind::Infer | TyKind::Typeof(_) | TyKind::Err + TyKind::OpaqueDef(..) | TyKind::Infer | TyKind::Typeof(_) | TyKind::Err(_) ) { self.0 = true; diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index 14f161f51026..d7e000473124 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -224,7 +224,7 @@ fn never_loop_expr(expr: &Expr<'_>, ignore_ids: &mut Vec, main_loop_id: H | ExprKind::Path(_) | ExprKind::ConstBlock(_) | ExprKind::Lit(_) - | ExprKind::Err => NeverLoopResult::Otherwise, + | ExprKind::Err(_) => NeverLoopResult::Otherwise, } } diff --git a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index f587c69f7302..b33a24781729 100644 --- a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -341,7 +341,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> { ExprKind::ConstBlock(_) | ExprKind::Continue(_) | ExprKind::DropTemps(_) | - ExprKind::Err | + ExprKind::Err(_) | ExprKind::InlineAsm(_) | ExprKind::Let(_) | ExprKind::Lit(_) | diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index bd7daf0773ca..c37e5bb6716e 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -588,7 +588,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { }, } }, - ExprKind::Err => kind!("Err"), + ExprKind::Err(_) => kind!("Err"), ExprKind::DropTemps(expr) => { bind!(self, expr); kind!("DropTemps({expr})"); diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 6ff7728374f8..ee2f816f181b 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -193,7 +193,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS | ExprKind::Ret(_) | ExprKind::InlineAsm(_) | ExprKind::Yield(..) - | ExprKind::Err => { + | ExprKind::Err(_) => { self.eagerness = ForceNoChange; return; }, diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 2bbe1a19b625..0603755f8a94 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -714,7 +714,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } self.hash_pat(pat); }, - ExprKind::Err => {}, + ExprKind::Err(_) => {}, ExprKind::Lit(ref l) => { l.node.hash(&mut self.s); }, @@ -986,7 +986,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { TyKind::Typeof(anon_const) => { self.hash_body(anon_const.body); }, - TyKind::Err | TyKind::Infer | TyKind::Never => {}, + TyKind::Err(_) | TyKind::Infer | TyKind::Never => {}, } } diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 78fb2e0eb7e6..11ca81cfe6c1 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -157,7 +157,7 @@ impl<'a> Sugg<'a> { | hir::ExprKind::Ret(..) | hir::ExprKind::Struct(..) | hir::ExprKind::Tup(..) - | hir::ExprKind::Err => Sugg::NonParen(get_snippet(expr.span)), + | hir::ExprKind::Err(_) => Sugg::NonParen(get_snippet(expr.span)), hir::ExprKind::DropTemps(inner) => Self::hir_from_snippet(inner, get_snippet), hir::ExprKind::Assign(lhs, rhs, _) => { Sugg::BinOp(AssocOp::Assign, get_snippet(lhs.span), get_snippet(rhs.span)) diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index 00073bcd82af..d27a20bd4dfa 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -665,7 +665,7 @@ pub fn for_each_unconsumed_temporary<'tcx, B>( | ExprKind::Path(_) | ExprKind::Continue(_) | ExprKind::InlineAsm(_) - | ExprKind::Err => (), + | ExprKind::Err(_) => (), } ControlFlow::Continue(()) } From 23a869422de07c630fbac16ebd87e3f43e4367c6 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 26 Feb 2023 08:45:32 +0000 Subject: [PATCH 0764/1222] Remove `from_fn` lang item It was probably a leftover from the old `?` desugaring but anyways, it's unused now except for clippy, which can just use a diagnostics item. --- clippy_lints/src/operators/cmp_owned.rs | 6 +++--- clippy_lints/src/unnecessary_owned_empty_strings.rs | 3 ++- clippy_lints/src/useless_conversion.rs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/operators/cmp_owned.rs b/clippy_lints/src/operators/cmp_owned.rs index 24aeb82a37f3..d3de9699fe9d 100644 --- a/clippy_lints/src/operators/cmp_owned.rs +++ b/clippy_lints/src/operators/cmp_owned.rs @@ -49,10 +49,10 @@ fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool) (arg, arg.span) }, ExprKind::Call(path, [arg]) - if path_def_id(cx, path).map_or(false, |id| { - if match_def_path(cx, id, &paths::FROM_STR_METHOD) { + if path_def_id(cx, path).map_or(false, |did| { + if match_def_path(cx, did, &paths::FROM_STR_METHOD) { true - } else if cx.tcx.lang_items().from_fn() == Some(id) { + } else if cx.tcx.is_diagnostic_item(sym::from_fn, did) { !is_copy(cx, typeck.expr_ty(expr)) } else { false diff --git a/clippy_lints/src/unnecessary_owned_empty_strings.rs b/clippy_lints/src/unnecessary_owned_empty_strings.rs index 9f207d32fcff..6e802794f5aa 100644 --- a/clippy_lints/src/unnecessary_owned_empty_strings.rs +++ b/clippy_lints/src/unnecessary_owned_empty_strings.rs @@ -7,6 +7,7 @@ use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::symbol::sym; declare_clippy_lint! { /// ### What it does @@ -54,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryOwnedEmptyStrings { ); } else { if_chain! { - if Some(fun_def_id) == cx.tcx.lang_items().from_fn(); + if cx.tcx.is_diagnostic_item(sym::from_fn, fun_def_id); if let [.., last_arg] = args; if let ExprKind::Lit(spanned) = &last_arg.kind; if let LitKind::Str(symbol, _) = spanned.node; diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index a95e7b613746..fede625f72a8 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -161,7 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { } if_chain! { - if Some(def_id) == cx.tcx.lang_items().from_fn(); + if cx.tcx.is_diagnostic_item(sym::from_fn, def_id); if same_type_and_consts(a, b); then { From c16357aea57dc5d28f0dc84c4f38c2b8b047ad09 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 21 Feb 2023 15:18:10 +0100 Subject: [PATCH 0765/1222] Use UnordSet instead of FxHashSet for names_imported_by_glob_use query. --- clippy_lints/src/wildcard_imports.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index e4d1ee195c4d..e105452e1c5f 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -155,14 +155,10 @@ impl LateLintPass<'_> for WildcardImports { ) }; - let imports_string = if used_imports.len() == 1 { - used_imports.iter().next().unwrap().to_string() + let mut imports = used_imports.items().map(ToString::to_string).into_sorted_stable_ord(false); + let imports_string = if imports.len() == 1 { + imports.pop().unwrap() } else { - let mut imports = used_imports - .iter() - .map(ToString::to_string) - .collect::>(); - imports.sort(); if braced_glob { imports.join(", ") } else { From 1c16844cc84226c7302c5e9261704c3d5f9ca840 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Mon, 27 Feb 2023 01:32:07 +0000 Subject: [PATCH 0766/1222] Restrict `#[rustc_box]` to `Box::new` calls --- clippy_utils/src/higher.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index 4604ae5c2c7f..50bef3709309 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -287,15 +287,12 @@ impl<'a> VecArgs<'a> { Some(VecArgs::Repeat(&args[0], &args[1])) } else if match_def_path(cx, fun_def_id, &paths::SLICE_INTO_VEC) && args.len() == 1 { // `vec![a, b, c]` case - if_chain! { - if let hir::ExprKind::Box(boxed) = args[0].kind; - if let hir::ExprKind::Array(args) = boxed.kind; - then { - return Some(VecArgs::Vec(args)); - } + if let hir::ExprKind::Call(_, [arg]) = &args[0].kind + && let hir::ExprKind::Array(args) = arg.kind { + Some(VecArgs::Vec(args)) + } else { + None } - - None } else if match_def_path(cx, fun_def_id, &paths::VEC_NEW) && args.is_empty() { Some(VecArgs::Vec(&[])) } else { From 0e4551afc98d8bf6f381cd93900f59d8bc6e3623 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 22 Feb 2023 19:51:17 +0400 Subject: [PATCH 0767/1222] rustc_middle: Remove trait `DefIdTree` This trait was a way to generalize over both `TyCtxt` and `Resolver`, but now `Resolver` has access to `TyCtxt`, so this trait is no longer necessary. --- clippy_lints/src/derivable_impls.rs | 2 +- clippy_lints/src/loops/manual_flatten.rs | 2 +- clippy_lints/src/manual_non_exhaustive.rs | 1 - clippy_lints/src/matches/manual_unwrap_or.rs | 1 - clippy_lints/src/matches/redundant_pattern_match.rs | 2 +- clippy_lints/src/methods/bind_instead_of_map.rs | 1 - clippy_lints/src/methods/chars_cmp.rs | 2 +- clippy_lints/src/methods/option_map_or_none.rs | 1 - clippy_lints/src/missing_doc.rs | 2 +- clippy_lints/src/needless_question_mark.rs | 1 - clippy_lints/src/std_instead_of_core.rs | 1 - .../src/utils/internal_lints/interning_defined_symbol.rs | 2 +- clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs | 2 +- clippy_utils/src/lib.rs | 2 +- clippy_utils/src/ty.rs | 2 +- 15 files changed, 9 insertions(+), 15 deletions(-) diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index f95b8ccf067b..c5f4e943f4f0 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -8,7 +8,7 @@ use rustc_hir::{ Body, Expr, ExprKind, GenericArg, Impl, ImplItemKind, Item, ItemKind, Node, PathSegment, QPath, Ty, TyKind, }; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{AdtDef, DefIdTree}; +use rustc_middle::ty::AdtDef; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::sym; diff --git a/clippy_lints/src/loops/manual_flatten.rs b/clippy_lints/src/loops/manual_flatten.rs index 8c27c09404b1..1e02a30e35fe 100644 --- a/clippy_lints/src/loops/manual_flatten.rs +++ b/clippy_lints/src/loops/manual_flatten.rs @@ -9,7 +9,7 @@ use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{Expr, Pat, PatKind}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, DefIdTree}; +use rustc_middle::ty; use rustc_span::source_map::Span; /// Check for unnecessary `if let` usage in a for loop where only the `Some` or `Ok` variant of the diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 9a84068d4487..0e22485db2c5 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -8,7 +8,6 @@ use rustc_errors::Applicability; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::{self as hir, Expr, ExprKind, QPath}; use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}; -use rustc_middle::ty::DefIdTree; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::{sym, Span}; diff --git a/clippy_lints/src/matches/manual_unwrap_or.rs b/clippy_lints/src/matches/manual_unwrap_or.rs index 587c926dc01c..6447899f2b94 100644 --- a/clippy_lints/src/matches/manual_unwrap_or.rs +++ b/clippy_lints/src/matches/manual_unwrap_or.rs @@ -10,7 +10,6 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::LangItem::{OptionNone, ResultErr}; use rustc_hir::{Arm, Expr, PatKind}; use rustc_lint::LateContext; -use rustc_middle::ty::DefIdTree; use rustc_span::sym; use super::MANUAL_UNWRAP_OR; diff --git a/clippy_lints/src/matches/redundant_pattern_match.rs b/clippy_lints/src/matches/redundant_pattern_match.rs index 81bebff34c82..df0ea7f5b863 100644 --- a/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/clippy_lints/src/matches/redundant_pattern_match.rs @@ -12,7 +12,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::LangItem::{self, OptionNone, OptionSome, PollPending, PollReady, ResultErr, ResultOk}; use rustc_hir::{Arm, Expr, ExprKind, Node, Pat, PatKind, QPath, UnOp}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, subst::GenericArgKind, DefIdTree, Ty}; +use rustc_middle::ty::{self, subst::GenericArgKind, Ty}; use rustc_span::{sym, Symbol}; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs index 4720a6e6888b..8e1130cf8dfa 100644 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/clippy_lints/src/methods/bind_instead_of_map.rs @@ -8,7 +8,6 @@ use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::{LangItem, QPath}; use rustc_lint::LateContext; -use rustc_middle::ty::DefIdTree; use rustc_span::Span; pub(crate) struct OptionAndThenSome; diff --git a/clippy_lints/src/methods/chars_cmp.rs b/clippy_lints/src/methods/chars_cmp.rs index 56b7fbb9d4bc..079df2226d1e 100644 --- a/clippy_lints/src/methods/chars_cmp.rs +++ b/clippy_lints/src/methods/chars_cmp.rs @@ -6,7 +6,7 @@ use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_lint::Lint; -use rustc_middle::ty::{self, DefIdTree}; +use rustc_middle::ty; /// Wrapper fn for `CHARS_NEXT_CMP` and `CHARS_LAST_CMP` lints. pub(super) fn check( diff --git a/clippy_lints/src/methods/option_map_or_none.rs b/clippy_lints/src/methods/option_map_or_none.rs index 3a23ecc50dc1..41ceef19e3a9 100644 --- a/clippy_lints/src/methods/option_map_or_none.rs +++ b/clippy_lints/src/methods/option_map_or_none.rs @@ -6,7 +6,6 @@ use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::LangItem::{OptionNone, OptionSome}; use rustc_lint::LateContext; -use rustc_middle::ty::DefIdTree; use rustc_span::symbol::sym; use super::OPTION_MAP_OR_NONE; diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 9659ca8ced2e..5b1f03fc16c2 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -13,7 +13,7 @@ use if_chain::if_chain; use rustc_ast::ast::{self, MetaItem, MetaItemKind}; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::ty::{DefIdTree, Visibility}; +use rustc_middle::ty::Visibility; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::def_id::CRATE_DEF_ID; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index 97c8cfbd3eb7..e2a7ba02a043 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -6,7 +6,6 @@ use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{AsyncGeneratorKind, Block, Body, Expr, ExprKind, GeneratorKind, LangItem, MatchSource, QPath}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::DefIdTree; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { diff --git a/clippy_lints/src/std_instead_of_core.rs b/clippy_lints/src/std_instead_of_core.rs index d6b336bef943..a13bc7a51887 100644 --- a/clippy_lints/src/std_instead_of_core.rs +++ b/clippy_lints/src/std_instead_of_core.rs @@ -2,7 +2,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir::def_id::DefId; use rustc_hir::{def::Res, HirId, Path, PathSegment}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::DefIdTree; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{sym, symbol::kw, Span}; diff --git a/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs b/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs index 688a8b865f32..f8978e30a8e2 100644 --- a/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs +++ b/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs @@ -11,7 +11,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::interpret::ConstValue; -use rustc_middle::ty::{self}; +use rustc_middle::ty; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::symbol::Symbol; diff --git a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs index b59ef4086cd8..14ed1368e03e 100644 --- a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs +++ b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs @@ -11,7 +11,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind, Local, Mutability, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::interpret::{Allocation, ConstValue, GlobalAlloc}; -use rustc_middle::ty::{self, DefIdTree, Ty}; +use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::symbol::Symbol; use rustc_span::Span; diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index f02f8ecb43d7..bcfedd07ed11 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -104,7 +104,7 @@ use rustc_middle::ty::fast_reject::SimplifiedType::{ PtrSimplifiedType, SliceSimplifiedType, StrSimplifiedType, UintSimplifiedType, }; use rustc_middle::ty::{ - layout::IntegerExt, BorrowKind, ClosureKind, DefIdTree, Ty, TyCtxt, TypeAndMut, TypeVisitableExt, UpvarCapture, + layout::IntegerExt, BorrowKind, ClosureKind, Ty, TyCtxt, TypeAndMut, TypeVisitableExt, UpvarCapture, }; use rustc_middle::ty::{FloatTy, IntTy, UintTy}; use rustc_span::hygiene::{ExpnKind, MacroKind}; diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 25654e6957b9..41e34eba0ad3 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -16,7 +16,7 @@ use rustc_infer::infer::{ use rustc_lint::LateContext; use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::ty::{ - self, AdtDef, AliasTy, AssocKind, Binder, BoundRegion, DefIdTree, FnSig, IntTy, List, ParamEnv, Predicate, + self, AdtDef, AliasTy, AssocKind, Binder, BoundRegion, FnSig, IntTy, List, ParamEnv, Predicate, PredicateKind, Region, RegionKind, SubstsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, UintTy, VariantDef, VariantDiscr, }; From 2ff2374c8c64dc6989ccac0c2d7b61973353cf8c Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Tue, 28 Feb 2023 12:45:19 +0000 Subject: [PATCH 0768/1222] Fix array-size-threshold config deserialization error --- book/src/lint_configuration.md | 2 +- clippy_lints/src/lib.rs | 2 +- clippy_lints/src/utils/conf.rs | 2 +- tests/ui/crashes/ice-10044.rs | 3 --- tests/ui/crashes/ice-10044.stderr | 10 ---------- tests/ui/large_stack_arrays.rs | 1 + tests/ui/large_stack_arrays.stderr | 10 +++++++++- 7 files changed, 13 insertions(+), 17 deletions(-) delete mode 100644 tests/ui/crashes/ice-10044.rs delete mode 100644 tests/ui/crashes/ice-10044.stderr diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index 33f2b5c1de99..995dd2f04b1e 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -306,7 +306,7 @@ The maximum number of lines a function or method can have ### array-size-threshold The maximum allowed size for arrays on the stack -**Default Value:** `512000` (`u128`) +**Default Value:** `512000` (`u64`) * [large_stack_arrays](https://rust-lang.github.io/rust-clippy/master/index.html#large_stack_arrays) * [large_const_arrays](https://rust-lang.github.io/rust-clippy/master/index.html#large_const_arrays) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 145cf524652f..c626e0bd9985 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -777,7 +777,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_late_pass(|_| Box::new(mutable_debug_assertion::DebugAssertWithMutCall)); store.register_late_pass(|_| Box::new(exit::Exit)); store.register_late_pass(|_| Box::new(to_digit_is_some::ToDigitIsSome)); - let array_size_threshold = conf.array_size_threshold; + let array_size_threshold = u128::from(conf.array_size_threshold); store.register_late_pass(move |_| Box::new(large_stack_arrays::LargeStackArrays::new(array_size_threshold))); store.register_late_pass(move |_| Box::new(large_const_arrays::LargeConstArrays::new(array_size_threshold))); store.register_late_pass(|_| Box::new(floating_point_arithmetic::FloatingPointArithmetic)); diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index 5f74de5a2886..1c7f3e96db89 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -334,7 +334,7 @@ define_Conf! { /// Lint: LARGE_STACK_ARRAYS, LARGE_CONST_ARRAYS. /// /// The maximum allowed size for arrays on the stack - (array_size_threshold: u128 = 512_000), + (array_size_threshold: u64 = 512_000), /// Lint: VEC_BOX. /// /// The size of the boxed type in bytes, where boxing in a `Vec` is allowed diff --git a/tests/ui/crashes/ice-10044.rs b/tests/ui/crashes/ice-10044.rs deleted file mode 100644 index 65f38fe71188..000000000000 --- a/tests/ui/crashes/ice-10044.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - [0; usize::MAX]; -} diff --git a/tests/ui/crashes/ice-10044.stderr b/tests/ui/crashes/ice-10044.stderr deleted file mode 100644 index 731f8265ad6c..000000000000 --- a/tests/ui/crashes/ice-10044.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: statement with no effect - --> $DIR/ice-10044.rs:2:5 - | -LL | [0; usize::MAX]; - | ^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::no-effect` implied by `-D warnings` - -error: aborting due to previous error - diff --git a/tests/ui/large_stack_arrays.rs b/tests/ui/large_stack_arrays.rs index 6790765f803e..99787ffd3d39 100644 --- a/tests/ui/large_stack_arrays.rs +++ b/tests/ui/large_stack_arrays.rs @@ -24,6 +24,7 @@ fn main() { [S { data: [0; 32] }; 5000], [Some(""); 20_000_000], [E::T(0); 5000], + [0u8; usize::MAX], ); let good = ( diff --git a/tests/ui/large_stack_arrays.stderr b/tests/ui/large_stack_arrays.stderr index c7bf941ad009..24e90094982a 100644 --- a/tests/ui/large_stack_arrays.stderr +++ b/tests/ui/large_stack_arrays.stderr @@ -31,5 +31,13 @@ LL | [E::T(0); 5000], | = help: consider allocating on the heap with `vec![E::T(0); 5000].into_boxed_slice()` -error: aborting due to 4 previous errors +error: allocating a local array larger than 512000 bytes + --> $DIR/large_stack_arrays.rs:27:9 + | +LL | [0u8; usize::MAX], + | ^^^^^^^^^^^^^^^^^ + | + = help: consider allocating on the heap with `vec![0u8; usize::MAX].into_boxed_slice()` + +error: aborting due to 5 previous errors From 8340dbb2461e27b65c4946c6cad3aacb3ad60599 Mon Sep 17 00:00:00 2001 From: Giacomo Pasini Date: Sun, 5 Mar 2023 21:02:14 +0100 Subject: [PATCH 0769/1222] Remove DropAndReplace terminator PR 107844 made DropAndReplace unused, let's remove it completely from the codebase. --- clippy_utils/src/qualify_min_const_fn.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 1a35fe05067f..c00800291dbd 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -299,10 +299,6 @@ fn check_terminator<'tcx>( | TerminatorKind::Unreachable => Ok(()), TerminatorKind::Drop { place, .. } => check_place(tcx, *place, span, body), - TerminatorKind::DropAndReplace { place, value, .. } => { - check_place(tcx, *place, span, body)?; - check_operand(tcx, value, span, body) - }, TerminatorKind::SwitchInt { discr, targets: _ } => check_operand(tcx, discr, span, body), From 0b136316f6027d18366471b6af4e19f9a61242e9 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Wed, 8 Mar 2023 14:17:16 +0100 Subject: [PATCH 0770/1222] move clippy tests back to their intended directory --- .../array_size_threshold.rs | 10 +++++++ .../array_size_threshold.stderr | 29 +++++++++++++++++++ .../ui-toml/array_size_threshold/clippy.toml | 1 + 3 files changed, 40 insertions(+) create mode 100644 tests/ui-toml/array_size_threshold/array_size_threshold.rs create mode 100644 tests/ui-toml/array_size_threshold/array_size_threshold.stderr create mode 100644 tests/ui-toml/array_size_threshold/clippy.toml diff --git a/tests/ui-toml/array_size_threshold/array_size_threshold.rs b/tests/ui-toml/array_size_threshold/array_size_threshold.rs new file mode 100644 index 000000000000..7f623c7a9ec5 --- /dev/null +++ b/tests/ui-toml/array_size_threshold/array_size_threshold.rs @@ -0,0 +1,10 @@ +#![allow(unused)] +#![warn(clippy::large_const_arrays, clippy::large_stack_arrays)] + +const ABOVE: [u8; 11] = [0; 11]; +const BELOW: [u8; 10] = [0; 10]; + +fn main() { + let above = [0u8; 11]; + let below = [0u8; 10]; +} diff --git a/tests/ui-toml/array_size_threshold/array_size_threshold.stderr b/tests/ui-toml/array_size_threshold/array_size_threshold.stderr new file mode 100644 index 000000000000..ac017b20916d --- /dev/null +++ b/tests/ui-toml/array_size_threshold/array_size_threshold.stderr @@ -0,0 +1,29 @@ +error: large array defined as const + --> $DIR/array_size_threshold.rs:4:1 + | +LL | const ABOVE: [u8; 11] = [0; 11]; + | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | help: make this a static item: `static` + | + = note: `-D clippy::large-const-arrays` implied by `-D warnings` + +error: allocating a local array larger than 10 bytes + --> $DIR/array_size_threshold.rs:4:25 + | +LL | const ABOVE: [u8; 11] = [0; 11]; + | ^^^^^^^ + | + = help: consider allocating on the heap with `vec![0; 11].into_boxed_slice()` + = note: `-D clippy::large-stack-arrays` implied by `-D warnings` + +error: allocating a local array larger than 10 bytes + --> $DIR/array_size_threshold.rs:8:17 + | +LL | let above = [0u8; 11]; + | ^^^^^^^^^ + | + = help: consider allocating on the heap with `vec![0u8; 11].into_boxed_slice()` + +error: aborting due to 3 previous errors + diff --git a/tests/ui-toml/array_size_threshold/clippy.toml b/tests/ui-toml/array_size_threshold/clippy.toml new file mode 100644 index 000000000000..3f1fe9a12099 --- /dev/null +++ b/tests/ui-toml/array_size_threshold/clippy.toml @@ -0,0 +1 @@ +array-size-threshold = 10 From e51e4f6a30767a2c1a4dad9dfd2039d74d7889d3 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Thu, 24 Nov 2022 17:58:32 +0100 Subject: [PATCH 0771/1222] Remove `identity_future` indirection This was previously needed because the indirection used to hide some unexplained lifetime errors, which it turned out were related to the `min_choice` algorithm. Removing the indirection also solves a couple of cycle errors, large moves and makes async blocks support the `#[track_caller]` annotation. --- clippy_lints/src/manual_async_fn.rs | 9 +-------- clippy_utils/src/lib.rs | 11 +---------- tests/ui/author/blocks.stdout | 6 +----- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 3778eb4c732d..f97c6bcb5d18 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -1,5 +1,4 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::match_function_call_with_def_id; use clippy_utils::source::{position_before_rarrow, snippet_block, snippet_opt}; use if_chain::if_chain; use rustc_errors::Applicability; @@ -175,16 +174,10 @@ fn captures_all_lifetimes(inputs: &[Ty<'_>], output_lifetimes: &[LifetimeName]) fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) -> Option<&'tcx Body<'tcx>> { if_chain! { if let Some(block_expr) = block.expr; - if let Some(args) = cx - .tcx - .lang_items() - .identity_future_fn() - .and_then(|def_id| match_function_call_with_def_id(cx, block_expr, def_id)); - if args.len() == 1; if let Expr { kind: ExprKind::Closure(&Closure { body, .. }), .. - } = args[0]; + } = block_expr; let closure_body = cx.tcx.hir().body(body); if closure_body.generator_kind == Some(GeneratorKind::Async(AsyncGeneratorKind::Block)); then { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index f02f8ecb43d7..8edfd2eff729 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1904,16 +1904,7 @@ pub fn is_async_fn(kind: FnKind<'_>) -> bool { /// Peels away all the compiler generated code surrounding the body of an async function, pub fn get_async_fn_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Option<&'tcx Expr<'tcx>> { - if let ExprKind::Call( - _, - &[ - Expr { - kind: ExprKind::Closure(&Closure { body, .. }), - .. - }, - ], - ) = body.value.kind - { + if let ExprKind::Closure(&Closure { body, .. }) = body.value.kind { if let ExprKind::Block( Block { stmts: [], diff --git a/tests/ui/author/blocks.stdout b/tests/ui/author/blocks.stdout index c6acf24c21ec..eb3e5189c823 100644 --- a/tests/ui/author/blocks.stdout +++ b/tests/ui/author/blocks.stdout @@ -43,11 +43,7 @@ if let ExprKind::Block(block, None) = expr.kind if let ExprKind::Closure(CaptureBy::Value, fn_decl, body_id, _, None) = expr.kind && let FnRetTy::DefaultReturn(_) = fn_decl.output && expr1 = &cx.tcx.hir().body(body_id).value - && let ExprKind::Call(func, args) = expr1.kind - && let ExprKind::Path(ref qpath) = func.kind - && matches!(qpath, QPath::LangItem(LangItem::IdentityFuture, _)) - && args.len() == 1 - && let ExprKind::Closure(CaptureBy::Value, fn_decl1, body_id1, _, Some(Movability::Static)) = args[0].kind + && let ExprKind::Closure(CaptureBy::Value, fn_decl1, body_id1, _, Some(Movability::Static)) = expr1.kind && let FnRetTy::DefaultReturn(_) = fn_decl1.output && expr2 = &cx.tcx.hir().body(body_id1).value && let ExprKind::Block(block, None) = expr2.kind From d68ddf718f22a5109f2b8f2405172c060a5a2ccd Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 7 Mar 2023 17:51:48 +0000 Subject: [PATCH 0772/1222] Fortify clippy tests. --- tests/ui/erasing_op.rs | 8 +++++--- tests/ui/erasing_op.stderr | 10 +++++----- tests/ui/integer_arithmetic.rs | 2 +- tests/ui/overflow_check_conditional.rs | 9 +++++---- tests/ui/overflow_check_conditional.stderr | 16 ++++++++-------- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/tests/ui/erasing_op.rs b/tests/ui/erasing_op.rs index ae2fad0086da..74985029e008 100644 --- a/tests/ui/erasing_op.rs +++ b/tests/ui/erasing_op.rs @@ -31,9 +31,7 @@ impl core::ops::Mul for Vec1 { #[allow(clippy::no_effect)] #[warn(clippy::erasing_op)] -fn main() { - let x: u8 = 0; - +fn test(x: u8) { x * 0; 0 & x; 0 / x; @@ -41,3 +39,7 @@ fn main() { 0 * Vec1 { x: 5 }; Vec1 { x: 5 } * 0; } + +fn main() { + test(0) +} diff --git a/tests/ui/erasing_op.stderr b/tests/ui/erasing_op.stderr index 165ed9bfe58b..97941252355a 100644 --- a/tests/ui/erasing_op.stderr +++ b/tests/ui/erasing_op.stderr @@ -1,5 +1,5 @@ error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:37:5 + --> $DIR/erasing_op.rs:35:5 | LL | x * 0; | ^^^^^ @@ -7,25 +7,25 @@ LL | x * 0; = note: `-D clippy::erasing-op` implied by `-D warnings` error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:38:5 + --> $DIR/erasing_op.rs:36:5 | LL | 0 & x; | ^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:39:5 + --> $DIR/erasing_op.rs:37:5 | LL | 0 / x; | ^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:41:5 + --> $DIR/erasing_op.rs:39:5 | LL | 0 * Vec1 { x: 5 }; | ^^^^^^^^^^^^^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:42:5 + --> $DIR/erasing_op.rs:40:5 | LL | Vec1 { x: 5 } * 0; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/integer_arithmetic.rs b/tests/ui/integer_arithmetic.rs index 67f24b4548aa..8dfdee662b9d 100644 --- a/tests/ui/integer_arithmetic.rs +++ b/tests/ui/integer_arithmetic.rs @@ -4,7 +4,7 @@ #[rustfmt::skip] fn main() { let mut i = 1i32; - let mut var1 = 0i32; + let mut var1 = 13i32; let mut var2 = -1i32; 1 + i; i * 2; diff --git a/tests/ui/overflow_check_conditional.rs b/tests/ui/overflow_check_conditional.rs index 5db75f5291be..e1e30114081e 100644 --- a/tests/ui/overflow_check_conditional.rs +++ b/tests/ui/overflow_check_conditional.rs @@ -1,9 +1,6 @@ #![warn(clippy::overflow_check_conditional)] -fn main() { - let a: u32 = 1; - let b: u32 = 2; - let c: u32 = 3; +fn test(a: u32, b: u32, c: u32) { if a + b < a {} if a > a + b {} if a + b < b {} @@ -23,3 +20,7 @@ fn main() { if i > i + j {} if i - j < i {} } + +fn main() { + test(1, 2, 3) +} diff --git a/tests/ui/overflow_check_conditional.stderr b/tests/ui/overflow_check_conditional.stderr index 1b8b146b60ae..92d1d8ef911e 100644 --- a/tests/ui/overflow_check_conditional.stderr +++ b/tests/ui/overflow_check_conditional.stderr @@ -1,5 +1,5 @@ error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:7:8 + --> $DIR/overflow_check_conditional.rs:4:8 | LL | if a + b < a {} | ^^^^^^^^^ @@ -7,43 +7,43 @@ LL | if a + b < a {} = note: `-D clippy::overflow-check-conditional` implied by `-D warnings` error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:8:8 + --> $DIR/overflow_check_conditional.rs:5:8 | LL | if a > a + b {} | ^^^^^^^^^ error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:9:8 + --> $DIR/overflow_check_conditional.rs:6:8 | LL | if a + b < b {} | ^^^^^^^^^ error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:10:8 + --> $DIR/overflow_check_conditional.rs:7:8 | LL | if b > a + b {} | ^^^^^^^^^ error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:11:8 + --> $DIR/overflow_check_conditional.rs:8:8 | LL | if a - b > b {} | ^^^^^^^^^ error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:12:8 + --> $DIR/overflow_check_conditional.rs:9:8 | LL | if b < a - b {} | ^^^^^^^^^ error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:13:8 + --> $DIR/overflow_check_conditional.rs:10:8 | LL | if a - b > a {} | ^^^^^^^^^ error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:14:8 + --> $DIR/overflow_check_conditional.rs:11:8 | LL | if a < a - b {} | ^^^^^^^^^ From 31136f51bebc95686821e92e06d8643523f999a6 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Tue, 15 Nov 2022 12:09:31 +0100 Subject: [PATCH 0773/1222] avoid reuse tripping over copyright notices --- COPYRIGHT | 4 ++++ README.md | 4 ++++ rustc_tools_util/README.md | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/COPYRIGHT b/COPYRIGHT index a6be75b5e310..82703b18fd7d 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -1,3 +1,5 @@ +// REUSE-IgnoreStart + Copyright 2014-2022 The Rust Project Developers Licensed under the Apache License, Version 2.0 or the MIT license , at your option. All files in the project carrying such notice may not be copied, modified, or distributed except according to those terms. + +// REUSE-IgnoreEnd diff --git a/README.md b/README.md index 3e7379ace7ea..b69ed8900a49 100644 --- a/README.md +++ b/README.md @@ -275,6 +275,8 @@ If you want to contribute to Clippy, you can find more information in [CONTRIBUT ## License + + Copyright 2014-2022 The Rust Project Developers Licensed under the Apache License, Version 2.0 , at your option. Files in the project may not be copied, modified, or distributed except according to those terms. + + diff --git a/rustc_tools_util/README.md b/rustc_tools_util/README.md index eefc661f9635..e197ea048a0a 100644 --- a/rustc_tools_util/README.md +++ b/rustc_tools_util/README.md @@ -49,6 +49,8 @@ The changelog for `rustc_tools_util` is available under: ## License + + Copyright 2014-2022 The Rust Project Developers Licensed under the Apache License, Version 2.0 or the MIT license , at your option. All files in the project carrying such notice may not be copied, modified, or distributed except according to those terms. + + From 65e5164adf613b1d96ef81ba121edc59264d1a5d Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 6 Sep 2022 18:41:01 +0200 Subject: [PATCH 0774/1222] Introduce a no-op PlaceMention statement for `let _ =`. --- clippy_utils/src/qualify_min_const_fn.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index c00800291dbd..24403e8b6f34 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -241,6 +241,7 @@ fn check_statement<'tcx>( | StatementKind::StorageDead(_) | StatementKind::Retag { .. } | StatementKind::AscribeUserType(..) + | StatementKind::PlaceMention(..) | StatementKind::Coverage(..) | StatementKind::ConstEvalCounter | StatementKind::Nop => Ok(()), From 117b87c92f8ba444c4c5cc4411f7586eab535d9c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 9 Mar 2023 19:53:59 +0000 Subject: [PATCH 0775/1222] Directly construct Inherited. --- .../src/methods/unnecessary_to_owned.rs | 8 +-- clippy_lints/src/transmute/utils.rs | 57 +++++++++---------- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index df26b36b7b32..4c4c003ca469 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -369,10 +369,10 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< Node::Item(item) => { if let ItemKind::Fn(_, _, body_id) = &item.kind && let output_ty = return_ty(cx, item.owner_id) - && Inherited::build(cx.tcx, item.owner_id.def_id).enter(|inherited| { - let fn_ctxt = FnCtxt::new(inherited, cx.param_env, item.owner_id.def_id); - fn_ctxt.can_coerce(ty, output_ty) - }) { + && let inherited = Inherited::new(cx.tcx, item.owner_id.def_id) + && let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, item.owner_id.def_id) + && fn_ctxt.can_coerce(ty, output_ty) + { if has_lifetime(output_ty) && has_lifetime(ty) { return false; } diff --git a/clippy_lints/src/transmute/utils.rs b/clippy_lints/src/transmute/utils.rs index cddaf9450eab..62efd13b8d90 100644 --- a/clippy_lints/src/transmute/utils.rs +++ b/clippy_lints/src/transmute/utils.rs @@ -33,38 +33,37 @@ pub(super) fn check_cast<'tcx>( let hir_id = e.hir_id; let local_def_id = hir_id.owner.def_id; - Inherited::build(cx.tcx, local_def_id).enter(|inherited| { - let fn_ctxt = FnCtxt::new(inherited, cx.param_env, local_def_id); + let inherited = Inherited::new(cx.tcx, local_def_id); + let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, local_def_id); - // If we already have errors, we can't be sure we can pointer cast. + // If we already have errors, we can't be sure we can pointer cast. + assert!( + !fn_ctxt.errors_reported_since_creation(), + "Newly created FnCtxt contained errors" + ); + + if let Ok(check) = cast::CastCheck::new( + &fn_ctxt, + e, + from_ty, + to_ty, + // We won't show any error to the user, so we don't care what the span is here. + DUMMY_SP, + DUMMY_SP, + hir::Constness::NotConst, + ) { + let res = check.do_check(&fn_ctxt); + + // do_check's documentation says that it might return Ok and create + // errors in the fcx instead of returning Err in some cases. Those cases + // should be filtered out before getting here. assert!( !fn_ctxt.errors_reported_since_creation(), - "Newly created FnCtxt contained errors" + "`fn_ctxt` contained errors after cast check!" ); - if let Ok(check) = cast::CastCheck::new( - &fn_ctxt, - e, - from_ty, - to_ty, - // We won't show any error to the user, so we don't care what the span is here. - DUMMY_SP, - DUMMY_SP, - hir::Constness::NotConst, - ) { - let res = check.do_check(&fn_ctxt); - - // do_check's documentation says that it might return Ok and create - // errors in the fcx instead of returning Err in some cases. Those cases - // should be filtered out before getting here. - assert!( - !fn_ctxt.errors_reported_since_creation(), - "`fn_ctxt` contained errors after cast check!" - ); - - res.ok() - } else { - None - } - }) + res.ok() + } else { + None + } } From c2ff0e288b8d207cc8b8d7b5acef0a4471c85d78 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Mon, 27 Feb 2023 13:07:44 +0000 Subject: [PATCH 0776/1222] Remove uses of `box_syntax` in rustc and tools --- tests/ui/boxed_local.rs | 35 +++++++------------- tests/ui/boxed_local.stderr | 8 ++--- tests/ui/no_effect.rs | 3 +- tests/ui/no_effect.stderr | 38 ++++++++++------------ tests/ui/unnecessary_operation.fixed | 2 -- tests/ui/unnecessary_operation.rs | 2 -- tests/ui/unnecessary_operation.stderr | 46 ++++++++++++--------------- 7 files changed, 53 insertions(+), 81 deletions(-) diff --git a/tests/ui/boxed_local.rs b/tests/ui/boxed_local.rs index 4639f00a8d83..79b6d33fc77c 100644 --- a/tests/ui/boxed_local.rs +++ b/tests/ui/boxed_local.rs @@ -1,4 +1,3 @@ -#![feature(box_syntax)] #![feature(lint_reasons)] #![allow( clippy::borrowed_box, @@ -34,7 +33,7 @@ fn ok_box_trait(boxed_trait: &Box) { } fn warn_call() { - let x = box A; + let x = Box::new(A); x.foo(); } @@ -43,41 +42,41 @@ fn warn_arg(x: Box) { } fn nowarn_closure_arg() { - let x = Some(box A); + let x = Some(Box::new(A)); x.map_or((), |x| take_ref(&x)); } fn warn_rename_call() { - let x = box A; + let x = Box::new(A); let y = x; y.foo(); // via autoderef } fn warn_notuse() { - let bz = box A; + let bz = Box::new(A); } fn warn_pass() { - let bz = box A; + let bz = Box::new(A); take_ref(&bz); // via deref coercion } fn nowarn_return() -> Box { - box A // moved out, "escapes" + Box::new(A) // moved out, "escapes" } fn nowarn_move() { - let bx = box A; + let bx = Box::new(A); drop(bx) // moved in, "escapes" } fn nowarn_call() { - let bx = box A; + let bx = Box::new(A); bx.clone(); // method only available to Box, not via autoderef } fn nowarn_pass() { - let bx = box A; + let bx = Box::new(A); take_box(&bx); // fn needs &Box } @@ -86,30 +85,20 @@ fn take_ref(x: &A) {} fn nowarn_ref_take() { // false positive, should actually warn - let x = box A; + let x = Box::new(A); let y = &x; take_box(y); } fn nowarn_match() { - let x = box A; // moved into a match + let x = Box::new(A); // moved into a match match x { y => drop(y), } } fn warn_match() { - let x = box A; - match &x { - // not moved - y => (), - } -} - -fn nowarn_large_array() { - // should not warn, is large array - // and should not be on stack - let x = box [1; 10000]; + let x = Box::new(A); match &x { // not moved y => (), diff --git a/tests/ui/boxed_local.stderr b/tests/ui/boxed_local.stderr index 9036529f39c5..10d78fbc0abb 100644 --- a/tests/ui/boxed_local.stderr +++ b/tests/ui/boxed_local.stderr @@ -1,5 +1,5 @@ error: local variable doesn't need to be boxed here - --> $DIR/boxed_local.rs:41:13 + --> $DIR/boxed_local.rs:40:13 | LL | fn warn_arg(x: Box) { | ^ @@ -7,19 +7,19 @@ LL | fn warn_arg(x: Box) { = note: `-D clippy::boxed-local` implied by `-D warnings` error: local variable doesn't need to be boxed here - --> $DIR/boxed_local.rs:132:12 + --> $DIR/boxed_local.rs:121:12 | LL | pub fn new(_needs_name: Box>) -> () {} | ^^^^^^^^^^^ error: local variable doesn't need to be boxed here - --> $DIR/boxed_local.rs:196:44 + --> $DIR/boxed_local.rs:185:44 | LL | fn default_impl_x(self: Box, x: Box) -> u32 { | ^ error: local variable doesn't need to be boxed here - --> $DIR/boxed_local.rs:203:16 + --> $DIR/boxed_local.rs:192:16 | LL | fn foo(x: Box) {} | ^ diff --git a/tests/ui/no_effect.rs b/tests/ui/no_effect.rs index f08eb092e6b2..ec8a5aa28c59 100644 --- a/tests/ui/no_effect.rs +++ b/tests/ui/no_effect.rs @@ -1,4 +1,4 @@ -#![feature(box_syntax, fn_traits, unboxed_closures)] +#![feature(fn_traits, unboxed_closures)] #![warn(clippy::no_effect_underscore_binding)] #![allow(dead_code, path_statements)] #![allow(clippy::deref_addrof, clippy::redundant_field_names, clippy::uninlined_format_args)] @@ -102,7 +102,6 @@ fn main() { *&42; &6; (5, 6, 7); - box 42; ..; 5..; ..5; diff --git a/tests/ui/no_effect.stderr b/tests/ui/no_effect.stderr index 6a1e636f9a61..92f6dbfbdba1 100644 --- a/tests/ui/no_effect.stderr +++ b/tests/ui/no_effect.stderr @@ -81,83 +81,77 @@ LL | (5, 6, 7); error: statement with no effect --> $DIR/no_effect.rs:105:5 | -LL | box 42; - | ^^^^^^^ - -error: statement with no effect - --> $DIR/no_effect.rs:106:5 - | LL | ..; | ^^^ error: statement with no effect - --> $DIR/no_effect.rs:107:5 + --> $DIR/no_effect.rs:106:5 | LL | 5..; | ^^^^ error: statement with no effect - --> $DIR/no_effect.rs:108:5 + --> $DIR/no_effect.rs:107:5 | LL | ..5; | ^^^^ error: statement with no effect - --> $DIR/no_effect.rs:109:5 + --> $DIR/no_effect.rs:108:5 | LL | 5..6; | ^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:110:5 + --> $DIR/no_effect.rs:109:5 | LL | 5..=6; | ^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:111:5 + --> $DIR/no_effect.rs:110:5 | LL | [42, 55]; | ^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:112:5 + --> $DIR/no_effect.rs:111:5 | LL | [42, 55][1]; | ^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:113:5 + --> $DIR/no_effect.rs:112:5 | LL | (42, 55).1; | ^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:114:5 + --> $DIR/no_effect.rs:113:5 | LL | [42; 55]; | ^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:115:5 + --> $DIR/no_effect.rs:114:5 | LL | [42; 55][13]; | ^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:117:5 + --> $DIR/no_effect.rs:116:5 | LL | || x += 5; | ^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:119:5 + --> $DIR/no_effect.rs:118:5 | LL | FooString { s: s }; | ^^^^^^^^^^^^^^^^^^^ error: binding to `_` prefixed variable with no side-effect - --> $DIR/no_effect.rs:120:5 + --> $DIR/no_effect.rs:119:5 | LL | let _unused = 1; | ^^^^^^^^^^^^^^^^ @@ -165,22 +159,22 @@ LL | let _unused = 1; = note: `-D clippy::no-effect-underscore-binding` implied by `-D warnings` error: binding to `_` prefixed variable with no side-effect - --> $DIR/no_effect.rs:121:5 + --> $DIR/no_effect.rs:120:5 | LL | let _penguin = || println!("Some helpful closure"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: binding to `_` prefixed variable with no side-effect - --> $DIR/no_effect.rs:122:5 + --> $DIR/no_effect.rs:121:5 | LL | let _duck = Struct { field: 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: binding to `_` prefixed variable with no side-effect - --> $DIR/no_effect.rs:123:5 + --> $DIR/no_effect.rs:122:5 | LL | let _cat = [2, 4, 6, 8][2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 30 previous errors +error: aborting due to 29 previous errors diff --git a/tests/ui/unnecessary_operation.fixed b/tests/ui/unnecessary_operation.fixed index d37163570abe..65d9c910b828 100644 --- a/tests/ui/unnecessary_operation.fixed +++ b/tests/ui/unnecessary_operation.fixed @@ -1,6 +1,5 @@ // run-rustfix -#![feature(box_syntax)] #![allow(clippy::deref_addrof, dead_code, unused, clippy::no_effect)] #![warn(clippy::unnecessary_operation)] @@ -59,7 +58,6 @@ fn main() { 5;6;get_number(); get_number(); get_number(); - get_number(); 5;get_number(); 42;get_number(); assert!([42, 55].len() > get_usize()); diff --git a/tests/ui/unnecessary_operation.rs b/tests/ui/unnecessary_operation.rs index a14fd4bca0ef..4e2acd59f04a 100644 --- a/tests/ui/unnecessary_operation.rs +++ b/tests/ui/unnecessary_operation.rs @@ -1,6 +1,5 @@ // run-rustfix -#![feature(box_syntax)] #![allow(clippy::deref_addrof, dead_code, unused, clippy::no_effect)] #![warn(clippy::unnecessary_operation)] @@ -57,7 +56,6 @@ fn main() { *&get_number(); &get_number(); (5, 6, get_number()); - box get_number(); get_number()..; ..get_number(); 5..get_number(); diff --git a/tests/ui/unnecessary_operation.stderr b/tests/ui/unnecessary_operation.stderr index f66d08ecb828..44cf2e01ff73 100644 --- a/tests/ui/unnecessary_operation.stderr +++ b/tests/ui/unnecessary_operation.stderr @@ -1,5 +1,5 @@ error: unnecessary operation - --> $DIR/unnecessary_operation.rs:51:5 + --> $DIR/unnecessary_operation.rs:50:5 | LL | Tuple(get_number()); | ^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` @@ -7,109 +7,103 @@ LL | Tuple(get_number()); = note: `-D clippy::unnecessary-operation` implied by `-D warnings` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:52:5 + --> $DIR/unnecessary_operation.rs:51:5 | LL | Struct { field: get_number() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:53:5 + --> $DIR/unnecessary_operation.rs:52:5 | LL | Struct { ..get_struct() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_struct();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:54:5 + --> $DIR/unnecessary_operation.rs:53:5 | LL | Enum::Tuple(get_number()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:55:5 + --> $DIR/unnecessary_operation.rs:54:5 | LL | Enum::Struct { field: get_number() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:56:5 + --> $DIR/unnecessary_operation.rs:55:5 | LL | 5 + get_number(); | ^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5;get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:57:5 + --> $DIR/unnecessary_operation.rs:56:5 | LL | *&get_number(); | ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:58:5 + --> $DIR/unnecessary_operation.rs:57:5 | LL | &get_number(); | ^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:59:5 + --> $DIR/unnecessary_operation.rs:58:5 | LL | (5, 6, get_number()); | ^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5;6;get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:60:5 - | -LL | box get_number(); - | ^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` - -error: unnecessary operation - --> $DIR/unnecessary_operation.rs:61:5 + --> $DIR/unnecessary_operation.rs:59:5 | LL | get_number()..; | ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:62:5 + --> $DIR/unnecessary_operation.rs:60:5 | LL | ..get_number(); | ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:63:5 + --> $DIR/unnecessary_operation.rs:61:5 | LL | 5..get_number(); | ^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5;get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:64:5 + --> $DIR/unnecessary_operation.rs:62:5 | LL | [42, get_number()]; | ^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `42;get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:65:5 + --> $DIR/unnecessary_operation.rs:63:5 | LL | [42, 55][get_usize()]; | ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42, 55].len() > get_usize());` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:66:5 + --> $DIR/unnecessary_operation.rs:64:5 | LL | (42, get_number()).1; | ^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `42;get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:67:5 + --> $DIR/unnecessary_operation.rs:65:5 | LL | [get_number(); 55]; | ^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:68:5 + --> $DIR/unnecessary_operation.rs:66:5 | LL | [42; 55][get_usize()]; | ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42; 55].len() > get_usize());` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:69:5 + --> $DIR/unnecessary_operation.rs:67:5 | LL | / { LL | | get_number() @@ -117,12 +111,12 @@ LL | | }; | |______^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:72:5 + --> $DIR/unnecessary_operation.rs:70:5 | LL | / FooString { LL | | s: String::from("blah"), LL | | }; | |______^ help: statement can be reduced to: `String::from("blah");` -error: aborting due to 20 previous errors +error: aborting due to 19 previous errors From 4bbde1a52bb7d990fdc970d4edc6cf5a7626d574 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Mon, 27 Feb 2023 13:17:29 +0000 Subject: [PATCH 0777/1222] Remove `box_syntax` from AST and use in tools --- clippy_lints/src/suspicious_operation_groupings.rs | 3 +-- clippy_utils/src/ast_utils.rs | 2 +- clippy_utils/src/sugg.rs | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index e111c7d22915..8aa47b62ebff 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -596,8 +596,7 @@ fn ident_difference_expr_with_base_location( | (MethodCall(_), MethodCall(_)) | (Call(_, _), Call(_, _)) | (ConstBlock(_), ConstBlock(_)) - | (Array(_), Array(_)) - | (Box(_), Box(_)) => { + | (Array(_), Array(_)) => { // keep going }, _ => { diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index d82098523e3b..809d654603a6 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -143,7 +143,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (Paren(l), _) => eq_expr(l, r), (_, Paren(r)) => eq_expr(l, r), (Err, Err) => true, - (Box(l), Box(r)) | (Try(l), Try(r)) | (Await(l), Await(r)) => eq_expr(l, r), + (Try(l), Try(r)) | (Await(l), Await(r)) => eq_expr(l, r), (Array(l), Array(r)) => over(l, r, |l, r| eq_expr(l, r)), (Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)), (Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value), diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 07feadca2b0c..85bf28b708b7 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -188,7 +188,6 @@ impl<'a> Sugg<'a> { match expr.kind { _ if expr.span.ctxt() != ctxt => Sugg::NonParen(snippet_with_context(cx, expr.span, ctxt, default, app).0), ast::ExprKind::AddrOf(..) - | ast::ExprKind::Box(..) | ast::ExprKind::Closure { .. } | ast::ExprKind::If(..) | ast::ExprKind::Let(..) From 64856ad9c1c2255bcc324f8c200c913ae5e1033a Mon Sep 17 00:00:00 2001 From: clubby789 Date: Tue, 14 Mar 2023 17:18:26 +0000 Subject: [PATCH 0778/1222] Remove box expressions from HIR --- clippy_lints/src/infinite_iter.rs | 2 +- clippy_lints/src/loops/never_loop.rs | 3 +-- clippy_lints/src/matches/significant_drop_in_scrutinee.rs | 1 - clippy_lints/src/methods/unnecessary_sort_by.rs | 4 ---- clippy_lints/src/no_effect.rs | 6 ++---- clippy_lints/src/shadow.rs | 3 +-- clippy_lints/src/significant_drop_tightening.rs | 1 - clippy_lints/src/utils/author.rs | 5 ----- clippy_utils/src/check_proc_macro.rs | 1 - clippy_utils/src/eager_or_lazy.rs | 3 +-- clippy_utils/src/hir_utils.rs | 3 +-- clippy_utils/src/sugg.rs | 1 - clippy_utils/src/visitors.rs | 1 - 13 files changed, 7 insertions(+), 27 deletions(-) diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index d1d2db27c6fc..fe28c526be35 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -167,7 +167,7 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { Finite }, ExprKind::Block(block, _) => block.expr.as_ref().map_or(Finite, |e| is_infinite(cx, e)), - ExprKind::Box(e) | ExprKind::AddrOf(BorrowKind::Ref, _, e) => is_infinite(cx, e), + ExprKind::AddrOf(BorrowKind::Ref, _, e) => is_infinite(cx, e), ExprKind::Call(path, _) => { if let ExprKind::Path(ref qpath) = path.kind { cx.qpath_res(qpath, path.hir_id) diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index b1bc10802e1b..f0a1b1dfe562 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -124,8 +124,7 @@ fn stmt_to_expr<'tcx>(stmt: &Stmt<'tcx>) -> Option<(&'tcx Expr<'tcx>, Option<&'t #[allow(clippy::too_many_lines)] fn never_loop_expr(expr: &Expr<'_>, ignore_ids: &mut Vec, main_loop_id: HirId) -> NeverLoopResult { match expr.kind { - ExprKind::Box(e) - | ExprKind::Unary(_, e) + ExprKind::Unary(_, e) | ExprKind::Cast(e, _) | ExprKind::Type(e, _) | ExprKind::Field(e, _) diff --git a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index b33a24781729..04225beeb704 100644 --- a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -321,7 +321,6 @@ impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> { self.has_significant_drop = true; } } - ExprKind::Box(..) | ExprKind::Array(..) | ExprKind::Call(..) | ExprKind::Unary(..) | diff --git a/clippy_lints/src/methods/unnecessary_sort_by.rs b/clippy_lints/src/methods/unnecessary_sort_by.rs index 5201da52bbf1..67618f7038ad 100644 --- a/clippy_lints/src/methods/unnecessary_sort_by.rs +++ b/clippy_lints/src/methods/unnecessary_sort_by.rs @@ -33,10 +33,6 @@ struct SortByKeyDetection { /// contains a and the other replaces it with b) fn mirrored_exprs(a_expr: &Expr<'_>, a_ident: &Ident, b_expr: &Expr<'_>, b_ident: &Ident) -> bool { match (&a_expr.kind, &b_expr.kind) { - // Two boxes with mirrored contents - (ExprKind::Box(left_expr), ExprKind::Box(right_expr)) => { - mirrored_exprs(left_expr, a_ident, right_expr, b_ident) - }, // Two arrays with mirrored contents (ExprKind::Array(left_exprs), ExprKind::Array(right_exprs)) => { iter::zip(*left_exprs, *right_exprs).all(|(left, right)| mirrored_exprs(left, a_ident, right, b_ident)) diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 79c1ae4861e8..e3712190e672 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -127,8 +127,7 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { | ExprKind::Type(inner, _) | ExprKind::Unary(_, inner) | ExprKind::Field(inner, _) - | ExprKind::AddrOf(_, _, inner) - | ExprKind::Box(inner) => has_no_effect(cx, inner), + | ExprKind::AddrOf(_, _, inner) => has_no_effect(cx, inner), ExprKind::Struct(_, fields, ref base) => { !has_drop(cx, cx.typeck_results().expr_ty(expr)) && fields.iter().all(|field| has_no_effect(cx, field.expr)) @@ -234,8 +233,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option reduce_expression(cx, inner).or_else(|| Some(vec![inner])), + | ExprKind::AddrOf(_, _, inner) => reduce_expression(cx, inner).or_else(|| Some(vec![inner])), ExprKind::Struct(_, fields, ref base) => { if has_drop(cx, cx.typeck_results().expr_ty(expr)) { None diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 87f966ced0df..ae7d19624ba6 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -213,8 +213,7 @@ fn is_self_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, mut expr: &Expr<'_>, hir_ } loop { expr = match expr.kind { - ExprKind::Box(e) - | ExprKind::AddrOf(_, _, e) + ExprKind::AddrOf(_, _, e) | ExprKind::Block( &Block { stmts: [], diff --git a/clippy_lints/src/significant_drop_tightening.rs b/clippy_lints/src/significant_drop_tightening.rs index e2d90edec5a4..e12681c0a0ca 100644 --- a/clippy_lints/src/significant_drop_tightening.rs +++ b/clippy_lints/src/significant_drop_tightening.rs @@ -380,7 +380,6 @@ impl<'cx, 'sdt, 'tcx> Visitor<'tcx> for SigDropFinder<'cx, 'sdt, 'tcx> { | hir::ExprKind::Assign(..) | hir::ExprKind::AssignOp(..) | hir::ExprKind::Binary(..) - | hir::ExprKind::Box(..) | hir::ExprKind::Call(..) | hir::ExprKind::Field(..) | hir::ExprKind::If(..) diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index f31c3fdb0959..bc4adf1596d4 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -395,11 +395,6 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { } self.expr(field!(let_expr.init)); }, - ExprKind::Box(inner) => { - bind!(self, inner); - kind!("Box({inner})"); - self.expr(inner); - }, ExprKind::Array(elements) => { bind!(self, elements); kind!("Array({elements})"); diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index 43f0df145f0e..d3a6929f67e2 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -112,7 +112,6 @@ fn qpath_search_pat(path: &QPath<'_>) -> (Pat, Pat) { /// Get the search patterns to use for the given expression fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) { match e.kind { - ExprKind::Box(e) => (Pat::Str("box"), expr_search_pat(tcx, e).1), ExprKind::ConstBlock(_) => (Pat::Str("const"), Pat::Str("}")), ExprKind::Tup([]) => (Pat::Str(")"), Pat::Str("(")), ExprKind::Unary(UnOp::Deref, e) => (Pat::Str("*"), expr_search_pat(tcx, e).1), diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index ee2f816f181b..babbc7294a17 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -199,8 +199,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS }, // Memory allocation, custom operator, loop, or call to an unknown function - ExprKind::Box(_) - | ExprKind::Unary(..) + ExprKind::Unary(..) | ExprKind::Binary(..) | ExprKind::Loop(..) | ExprKind::Call(..) => self.eagerness = Lazy, diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 0603755f8a94..3a6d23ca5c10 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -249,7 +249,6 @@ impl HirEqInterExpr<'_, '_, '_> { both(&li.label, &ri.label, |l, r| l.ident.name == r.ident.name) && both(le, re, |l, r| self.eq_expr(l, r)) }, - (&ExprKind::Box(l), &ExprKind::Box(r)) => self.eq_expr(l, r), (&ExprKind::Call(l_fun, l_args), &ExprKind::Call(r_fun, r_args)) => { self.inner.allow_side_effects && self.eq_expr(l_fun, r_fun) && self.eq_exprs(l_args, r_args) }, @@ -628,7 +627,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_expr(j); } }, - ExprKind::Box(e) | ExprKind::DropTemps(e) | ExprKind::Yield(e, _) => { + ExprKind::DropTemps(e) | ExprKind::Yield(e, _) => { self.hash_expr(e); }, ExprKind::Call(fun, args) => { diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 85bf28b708b7..44cb5d5756ad 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -133,7 +133,6 @@ impl<'a> Sugg<'a> { match expr.kind { hir::ExprKind::AddrOf(..) - | hir::ExprKind::Box(..) | hir::ExprKind::If(..) | hir::ExprKind::Let(..) | hir::ExprKind::Closure { .. } diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index d27a20bd4dfa..86a93f64fb71 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -600,7 +600,6 @@ pub fn for_each_unconsumed_temporary<'tcx, B>( helper(typeck, false, e, f)?; }, ExprKind::Block(&Block { expr: Some(e), .. }, _) - | ExprKind::Box(e) | ExprKind::Cast(e, _) | ExprKind::Unary(_, e) => { helper(typeck, true, e, f)?; From 70b54ee3bdab99c275e7f8ae943587e9a996dd54 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Thu, 16 Mar 2023 12:08:07 +0100 Subject: [PATCH 0779/1222] Fix clippy. --- clippy_utils/src/macros.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs index e135bd9feee5..c0e32068ecac 100644 --- a/clippy_utils/src/macros.rs +++ b/clippy_utils/src/macros.rs @@ -533,6 +533,14 @@ struct FormatArgsValues<'tcx> { } impl<'tcx> FormatArgsValues<'tcx> { + fn new_empty(format_string_span: SpanData) -> Self { + Self { + value_args: Vec::new(), + pos_to_value_index: Vec::new(), + format_string_span, + } + } + fn new(args: &'tcx Expr<'tcx>, format_string_span: SpanData) -> Self { let mut pos_to_value_index = Vec::new(); let mut value_args = Vec::new(); @@ -997,12 +1005,13 @@ impl<'tcx> FormatArgsExpn<'tcx> { .find(|&name| matches!(name, sym::const_format_args | sym::format_args | sym::format_args_nl))?; let newline = macro_name == sym::format_args_nl; + // ::core::fmt::Arguments::new_const(pieces) // ::core::fmt::Arguments::new_v1(pieces, args) // ::core::fmt::Arguments::new_v1_formatted(pieces, args, fmt, _unsafe_arg) - if let ExprKind::Call(callee, [pieces, args, rest @ ..]) = expr.kind + if let ExprKind::Call(callee, [pieces, rest @ ..]) = expr.kind && let ExprKind::Path(QPath::TypeRelative(ty, seg)) = callee.kind && let TyKind::Path(QPath::LangItem(LangItem::FormatArguments, _, _)) = ty.kind - && matches!(seg.ident.as_str(), "new_v1" | "new_v1_formatted") + && matches!(seg.ident.as_str(), "new_const" | "new_v1" | "new_v1_formatted") { let format_string = FormatString::new(cx, pieces)?; @@ -1026,7 +1035,7 @@ impl<'tcx> FormatArgsExpn<'tcx> { return None; } - let positions = if let Some(fmt_arg) = rest.first() { + let positions = if let Some(fmt_arg) = rest.get(1) { // If the argument contains format specs, `new_v1_formatted(_, _, fmt, _)`, parse // them. @@ -1042,7 +1051,11 @@ impl<'tcx> FormatArgsExpn<'tcx> { })) }; - let values = FormatArgsValues::new(args, format_string.span.data()); + let values = if let Some(args) = rest.first() { + FormatArgsValues::new(args, format_string.span.data()) + } else { + FormatArgsValues::new_empty(format_string.span.data()) + }; let args = izip!(positions, parsed_args, parser.arg_places) .map(|(position, parsed_arg, arg_span)| { From aaeb2cf59b72bfeba647d67a63f03e273b442d3d Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Tue, 31 Jan 2023 22:13:25 +0100 Subject: [PATCH 0780/1222] Remove the `NodeId` of `ast::ExprKind::Async` --- clippy_lints/src/redundant_async_block.rs | 2 +- clippy_lints/src/suspicious_operation_groupings.rs | 2 +- clippy_utils/src/ast_utils.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/redundant_async_block.rs b/clippy_lints/src/redundant_async_block.rs index 27ad43086374..56be8c07e924 100644 --- a/clippy_lints/src/redundant_async_block.rs +++ b/clippy_lints/src/redundant_async_block.rs @@ -42,7 +42,7 @@ impl EarlyLintPass for RedundantAsyncBlock { if expr.span.from_expansion() { return; } - if let ExprKind::Async(_, _, block) = &expr.kind && block.stmts.len() == 1 && + if let ExprKind::Async(_, block) = &expr.kind && block.stmts.len() == 1 && let Some(Stmt { kind: StmtKind::Expr(last), .. }) = block.stmts.last() && let ExprKind::Await(future) = &last.kind && !future.span.from_expansion() && diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index 8aa47b62ebff..fab8e9c2ec1c 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -578,7 +578,7 @@ fn ident_difference_expr_with_base_location( | (Assign(_, _, _), Assign(_, _, _)) | (TryBlock(_), TryBlock(_)) | (Await(_), Await(_)) - | (Async(_, _, _), Async(_, _, _)) + | (Async(_, _), Async(_, _)) | (Block(_, _), Block(_, _)) | (Closure(_), Closure(_)) | (Match(_, _), Match(_, _)) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 809d654603a6..d2dedc204395 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -209,7 +209,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { && eq_fn_decl(lf, rf) && eq_expr(le, re) }, - (Async(lc, _, lb), Async(rc, _, rb)) => lc == rc && eq_block(lb, rb), + (Async(lc, lb), Async(rc, rb)) => lc == rc && eq_block(lb, rb), (Range(lf, lt, ll), Range(rf, rt, rl)) => ll == rl && eq_expr_opt(lf, rf) && eq_expr_opt(lt, rt), (AddrOf(lbk, lm, le), AddrOf(rbk, rm, re)) => lbk == rbk && lm == rm && eq_expr(le, re), (Path(lq, lp), Path(rq, rp)) => both(lq, rq, eq_qself) && eq_path(lp, rp), From 230d9e41bd8b8c9fedfc23313477670f242faa61 Mon Sep 17 00:00:00 2001 From: lcnr Date: Tue, 14 Mar 2023 14:19:06 +0100 Subject: [PATCH 0781/1222] remove some trait solver helpers they add more complexity then they are worth. It's confusing which of these helpers should be used in which context. --- clippy_lints/src/future_not_send.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 9fb73a371b8f..ed0bd58c770c 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -9,7 +9,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt; -use rustc_trait_selection::traits::{self, FulfillmentError}; +use rustc_trait_selection::traits::{self, FulfillmentError, ObligationCtxt}; declare_clippy_lint! { /// ### What it does @@ -79,8 +79,10 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap(); let span = decl.output.span(); let infcx = cx.tcx.infer_ctxt().build(); + let ocx = ObligationCtxt::new(&infcx); let cause = traits::ObligationCause::misc(span, fn_def_id); - let send_errors = traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait); + ocx.register_bound(cause, cx.param_env, ret_ty, send_trait); + let send_errors = ocx.select_all_or_error(); if !send_errors.is_empty() { span_lint_and_then( cx, From b8d4c93ac72e087c175178e643eb05f91a8c9ec6 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 13 Mar 2023 18:54:05 +0000 Subject: [PATCH 0782/1222] Use local key in providers --- clippy_lints/src/cognitive_complexity.rs | 2 +- clippy_lints/src/derivable_impls.rs | 2 +- clippy_lints/src/derive.rs | 2 +- clippy_lints/src/functions/must_use.rs | 6 +++--- clippy_lints/src/partialeq_ne_impl.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index e8531157e0f7..a8926b29ac83 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity { span: Span, def_id: LocalDefId, ) { - if !cx.tcx.has_attr(def_id.to_def_id(), sym::test) { + if !cx.tcx.has_attr(def_id, sym::test) { let expr = if is_async_fn(kind) { match get_async_fn_body(cx.tcx, body) { Some(b) => b, diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index 8a5a28c6b3d8..8f68f90a2a13 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -181,7 +181,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { self_ty, .. }) = item.kind; - if !cx.tcx.has_attr(item.owner_id.to_def_id(), sym::automatically_derived); + if !cx.tcx.has_attr(item.owner_id, sym::automatically_derived); if !item.span.from_expansion(); if let Some(def_id) = trait_ref.trait_def_id(); if cx.tcx.is_diagnostic_item(sym::Default, def_id); diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index b8428d66a5dc..715348e869ef 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -212,7 +212,7 @@ impl<'tcx> LateLintPass<'tcx> for Derive { }) = item.kind { let ty = cx.tcx.type_of(item.owner_id).subst_identity(); - let is_automatically_derived = cx.tcx.has_attr(item.owner_id.to_def_id(), sym::automatically_derived); + let is_automatically_derived = cx.tcx.has_attr(item.owner_id, sym::automatically_derived); check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived); check_ord_partial_ord(cx, item.span, trait_ref, ty, is_automatically_derived); diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 29bdc46b647d..eacbf6c6ec9b 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -22,7 +22,7 @@ use super::{DOUBLE_MUST_USE, MUST_USE_CANDIDATE, MUST_USE_UNIT}; pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { let attrs = cx.tcx.hir().attrs(item.hir_id()); - let attr = cx.tcx.get_attr(item.owner_id.to_def_id(), sym::must_use); + let attr = cx.tcx.get_attr(item.owner_id, sym::must_use); if let hir::ItemKind::Fn(ref sig, _generics, ref body_id) = item.kind { let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); @@ -47,7 +47,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let attrs = cx.tcx.hir().attrs(item.hir_id()); - let attr = cx.tcx.get_attr(item.owner_id.to_def_id(), sym::must_use); + let attr = cx.tcx.get_attr(item.owner_id, sym::must_use); if let Some(attr) = attr { check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr); } else if is_public @@ -73,7 +73,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); let attrs = cx.tcx.hir().attrs(item.hir_id()); - let attr = cx.tcx.get_attr(item.owner_id.to_def_id(), sym::must_use); + let attr = cx.tcx.get_attr(item.owner_id, sym::must_use); if let Some(attr) = attr { check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr); } else if let hir::TraitFn::Provided(eid) = *eid { diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index 5aa3c6f2f934..a8c4823fe538 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -36,7 +36,7 @@ impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if_chain! { if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), items: impl_items, .. }) = item.kind; - if !cx.tcx.has_attr(item.owner_id.to_def_id(), sym::automatically_derived); + if !cx.tcx.has_attr(item.owner_id, sym::automatically_derived); if let Some(eq_trait) = cx.tcx.lang_items().eq_trait(); if trait_ref.path.res.def_id() == eq_trait; then { From 4f790953e64b0cbe6a32fdf587137720c3e3253e Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 19 Mar 2023 21:32:34 +0400 Subject: [PATCH 0783/1222] rustc: Remove unused `Session` argument from some attribute functions --- clippy_lints/src/functions/must_use.rs | 6 +++--- clippy_utils/src/attrs.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index eacbf6c6ec9b..67877780c0e9 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -28,7 +28,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_> let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); if let Some(attr) = attr { check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr); - } else if is_public && !is_proc_macro(cx.sess(), attrs) && !attrs.iter().any(|a| a.has_name(sym::no_mangle)) { + } else if is_public && !is_proc_macro(attrs) && !attrs.iter().any(|a| a.has_name(sym::no_mangle)) { check_must_use_candidate( cx, sig.decl, @@ -51,7 +51,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp if let Some(attr) = attr { check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr); } else if is_public - && !is_proc_macro(cx.sess(), attrs) + && !is_proc_macro(attrs) && trait_ref_of_method(cx, item.owner_id.def_id).is_none() { check_must_use_candidate( @@ -78,7 +78,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr); } else if let hir::TraitFn::Provided(eid) = *eid { let body = cx.tcx.hir().body(eid); - if attr.is_none() && is_public && !is_proc_macro(cx.sess(), attrs) { + if attr.is_none() && is_public && !is_proc_macro(attrs) { check_must_use_candidate( cx, sig.decl, diff --git a/clippy_utils/src/attrs.rs b/clippy_utils/src/attrs.rs index 7987a233bdc1..bc3d774540a5 100644 --- a/clippy_utils/src/attrs.rs +++ b/clippy_utils/src/attrs.rs @@ -145,8 +145,8 @@ pub fn get_unique_attr<'a>( /// Return true if the attributes contain any of `proc_macro`, /// `proc_macro_derive` or `proc_macro_attribute`, false otherwise -pub fn is_proc_macro(sess: &Session, attrs: &[ast::Attribute]) -> bool { - attrs.iter().any(|attr| sess.is_proc_macro_attr(attr)) +pub fn is_proc_macro(attrs: &[ast::Attribute]) -> bool { + attrs.iter().any(|attr| attr.is_proc_macro_attr()) } /// Return true if the attributes contain `#[doc(hidden)]` From da77d421ad50c13e6671653f809deee38493ae5e Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Fri, 24 Feb 2023 18:32:52 -0800 Subject: [PATCH 0784/1222] Add `CastKind::Transmute` to MIR Updates `interpret`, `codegen_ssa`, and `codegen_cranelift` to consume the new cast instead of the intrinsic. Includes `CastTransmute` for custom MIR building, to be able to test the extra UB. --- clippy_utils/src/qualify_min_const_fn.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 24403e8b6f34..ff492a5104d1 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -176,6 +176,9 @@ fn check_rvalue<'tcx>( // FIXME(dyn-star) unimplemented!() }, + Rvalue::Cast(CastKind::Transmute, _, _) => { + Err((span, "transmute can attempt to turn pointers into integers, so is unstable in const fn".into())) + }, // binops are fine on integers Rvalue::BinaryOp(_, box (lhs, rhs)) | Rvalue::CheckedBinaryOp(_, box (lhs, rhs)) => { check_operand(tcx, lhs, span, body)?; From d1161531cfd371ad9cfa1d4c512a6f4aa23b6fa9 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 21 Mar 2023 22:11:40 +0000 Subject: [PATCH 0785/1222] Rename AliasEq -> AliasRelate --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 24403e8b6f34..58f7742ab876 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -37,7 +37,7 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv) | ty::PredicateKind::ConstEvaluatable(..) | ty::PredicateKind::ConstEquate(..) | ty::PredicateKind::TypeWellFormedFromEnv(..) => continue, - ty::PredicateKind::AliasEq(..) => panic!("alias eq predicate on function: {predicate:#?}"), + ty::PredicateKind::AliasRelate(..) => panic!("alias relate predicate on function: {predicate:#?}"), ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {predicate:#?}"), ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {predicate:#?}"), ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {predicate:#?}"), From f73902e7970eefa2d144a244a14fd71e083108e4 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Thu, 10 Nov 2022 11:37:28 -0500 Subject: [PATCH 0786/1222] A MIR transform that checks pointers are aligned --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 9f6adf3e3fab..cd9cc8bccb6e 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -169,7 +169,7 @@ fn check_rvalue<'tcx>( Err((span, "unsizing casts are not allowed in const fn".into())) } }, - Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => { + Rvalue::Cast(CastKind::PointerExposeAddress | CastKind::PointerAddress, _, _) => { Err((span, "casting pointers to ints is unstable in const fn".into())) }, Rvalue::Cast(CastKind::DynStar, _, _) => { From 4821983972b428c7da6a953c95957a7277df9cb3 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Thu, 23 Mar 2023 20:19:45 -0400 Subject: [PATCH 0787/1222] Fix clippy --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index cd9cc8bccb6e..9f6adf3e3fab 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -169,7 +169,7 @@ fn check_rvalue<'tcx>( Err((span, "unsizing casts are not allowed in const fn".into())) } }, - Rvalue::Cast(CastKind::PointerExposeAddress | CastKind::PointerAddress, _, _) => { + Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => { Err((span, "casting pointers to ints is unstable in const fn".into())) }, Rvalue::Cast(CastKind::DynStar, _, _) => { From 3e922e3b23eceab8d1f43c9e0560b3f320034e87 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 26 Mar 2023 20:33:54 +0000 Subject: [PATCH 0788/1222] Don't elaborate non-obligations into obligations --- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- clippy_utils/src/lib.rs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 1ab81aee7b8d..327e090d38be 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -124,9 +124,9 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds().iter()) .filter(|p| !p.is_global()) - .filter_map(|obligation| { + .filter_map(|pred| { // Note that we do not want to deal with qualified predicates here. - match obligation.predicate.kind().no_bound_vars() { + match pred.kind().no_bound_vars() { Some(ty::PredicateKind::Clause(ty::Clause::Trait(pred))) if pred.def_id() != sized_trait => { Some(pred) }, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 29830557a445..fd06c0b86775 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -2106,7 +2106,6 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool { traits::impossible_predicates( cx.tcx, traits::elaborate_predicates(cx.tcx, predicates) - .map(|o| o.predicate) .collect::>(), ) } From ffcd566c37eac8ece8fdcf1c17d6242bac279a47 Mon Sep 17 00:00:00 2001 From: Jamen Marz Date: Mon, 27 Mar 2023 10:14:08 -0400 Subject: [PATCH 0789/1222] Add notes to non-structural const in pattern error message --- tests/ui/crashes/ice-6254.stderr | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/ui/crashes/ice-6254.stderr b/tests/ui/crashes/ice-6254.stderr index 22d82a30c6aa..263c27d3d646 100644 --- a/tests/ui/crashes/ice-6254.stderr +++ b/tests/ui/crashes/ice-6254.stderr @@ -6,6 +6,8 @@ LL | FOO_REF_REF => {}, | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #62411 + = note: the traits must be derived, manual `impl`s are not sufficient + = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details = note: `-D indirect-structural-match` implied by `-D warnings` error: aborting due to previous error From 7ac3fd5cf4a84421863709a71a9bd12d06bffcda Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 16 Mar 2023 22:00:08 +0000 Subject: [PATCH 0790/1222] Add `(..)` syntax for RTN --- clippy_lints/src/ref_option_ref.rs | 4 ++-- clippy_lints/src/types/borrowed_box.rs | 2 +- clippy_lints/src/types/utils.rs | 4 ++-- clippy_lints/src/use_self.rs | 5 +++-- clippy_utils/src/hir_utils.rs | 7 +------ 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/ref_option_ref.rs b/clippy_lints/src/ref_option_ref.rs index 448a32b77c03..c984a8286eb8 100644 --- a/clippy_lints/src/ref_option_ref.rs +++ b/clippy_lints/src/ref_option_ref.rs @@ -3,7 +3,7 @@ use clippy_utils::last_path_segment; use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::{GenericArg, Mutability, Ty, TyKind}; +use rustc_hir::{GenericArg, GenericArgsParentheses, Mutability, Ty, TyKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; @@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for RefOptionRef { if cx.tcx.is_diagnostic_item(sym::Option, def_id); if let Some(params) = last_path_segment(qpath).args ; - if !params.parenthesized; + if params.parenthesized == GenericArgsParentheses::No; if let Some(inner_ty) = params.args.iter().find_map(|arg| match arg { GenericArg::Type(inner_ty) => Some(inner_ty), _ => None, diff --git a/clippy_lints/src/types/borrowed_box.rs b/clippy_lints/src/types/borrowed_box.rs index 65dfe7637ea9..acdf54710691 100644 --- a/clippy_lints/src/types/borrowed_box.rs +++ b/clippy_lints/src/types/borrowed_box.rs @@ -20,7 +20,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m if let QPath::Resolved(None, path) = *qpath; if let [ref bx] = *path.segments; if let Some(params) = bx.args; - if !params.parenthesized; + if params.parenthesized == hir::GenericArgsParentheses::No; if let Some(inner) = params.args.iter().find_map(|arg| match arg { GenericArg::Type(ty) => Some(ty), _ => None, diff --git a/clippy_lints/src/types/utils.rs b/clippy_lints/src/types/utils.rs index 7f43b7841ff3..a30748db88fc 100644 --- a/clippy_lints/src/types/utils.rs +++ b/clippy_lints/src/types/utils.rs @@ -1,6 +1,6 @@ use clippy_utils::last_path_segment; use if_chain::if_chain; -use rustc_hir::{GenericArg, QPath, TyKind}; +use rustc_hir::{GenericArg, GenericArgsParentheses, QPath, TyKind}; use rustc_lint::LateContext; use rustc_span::source_map::Span; @@ -8,7 +8,7 @@ pub(super) fn match_borrows_parameter(_cx: &LateContext<'_>, qpath: &QPath<'_>) let last = last_path_segment(qpath); if_chain! { if let Some(params) = last.args; - if !params.parenthesized; + if params.parenthesized == GenericArgsParentheses::No; if let Some(ty) = params.args.iter().find_map(|arg| match arg { GenericArg::Type(ty) => Some(ty), _ => None, diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 8ea5475fb252..7dfb0956077e 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -10,7 +10,7 @@ use rustc_hir::{ def::{CtorOf, DefKind, Res}, def_id::LocalDefId, intravisit::{walk_inf, walk_ty, Visitor}, - Expr, ExprKind, FnRetTy, FnSig, GenericArg, GenericParam, GenericParamKind, HirId, Impl, ImplItemKind, Item, + Expr, ExprKind, FnRetTy, FnSig, GenericArg, GenericArgsParentheses, GenericParam, GenericParamKind, HirId, Impl, ImplItemKind, Item, ItemKind, Pat, PatKind, Path, QPath, Ty, TyKind, }; use rustc_hir_analysis::hir_ty_to_ty; @@ -100,7 +100,8 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { if let TyKind::Path(QPath::Resolved(_, item_path)) = self_ty.kind; let parameters = &item_path.segments.last().expect(SEGMENTS_MSG).args; if parameters.as_ref().map_or(true, |params| { - !params.parenthesized && !params.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_))) + params.parenthesized == GenericArgsParentheses::No + && !params.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_))) }); if !item.span.from_expansion(); if !is_from_proc_macro(cx, item); // expensive, should be last check diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 3a6d23ca5c10..3ee7147828bd 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -401,14 +401,9 @@ impl HirEqInterExpr<'_, '_, '_> { } fn eq_path_parameters(&mut self, left: &GenericArgs<'_>, right: &GenericArgs<'_>) -> bool { - if !(left.parenthesized || right.parenthesized) { + if left.parenthesized == right.parenthesized { over(left.args, right.args, |l, r| self.eq_generic_arg(l, r)) // FIXME(flip1995): may not work && over(left.bindings, right.bindings, |l, r| self.eq_type_binding(l, r)) - } else if left.parenthesized && right.parenthesized { - over(left.inputs(), right.inputs(), |l, r| self.eq_ty(l, r)) - && both(&Some(&left.bindings[0].ty()), &Some(&right.bindings[0].ty()), |l, r| { - self.eq_ty(l, r) - }) } else { false } From f9677cc931923ad2c9e3ed1eb7be5a9f3caa1440 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 12 Dec 2022 00:42:45 -0500 Subject: [PATCH 0791/1222] Stabilize a portion of 'once_cell' Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try' --- clippy_dev/src/lib.rs | 1 - clippy_lints/src/lib.rs | 1 - clippy_utils/src/lib.rs | 1 - src/driver.rs | 2 +- tests/compile-test.rs | 2 +- tests/dogfood.rs | 2 +- tests/lint_message_convention.rs | 2 +- tests/workspace.rs | 2 +- 8 files changed, 5 insertions(+), 8 deletions(-) diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index e70488165b99..8871873c6612 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -1,5 +1,4 @@ #![feature(let_chains)] -#![feature(once_cell)] #![feature(rustc_private)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] // warn on lints, that are included in `rust-lang/rust`s bootstrap diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index c9210bf73f89..3da7f95c1b9f 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -7,7 +7,6 @@ #![feature(let_chains)] #![feature(lint_reasons)] #![feature(never_type)] -#![feature(once_cell)] #![feature(rustc_private)] #![feature(stmt_expr_attributes)] #![recursion_limit = "512"] diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index fd06c0b86775..619aa9f4bf6f 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -3,7 +3,6 @@ #![feature(let_chains)] #![feature(lint_reasons)] #![feature(never_type)] -#![feature(once_cell)] #![feature(rustc_private)] #![recursion_limit = "512"] #![cfg_attr(feature = "deny-warnings", deny(warnings))] diff --git a/src/driver.rs b/src/driver.rs index f08393c303ef..9e0822404b6b 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -1,6 +1,6 @@ #![feature(rustc_private)] #![feature(let_chains)] -#![feature(once_cell)] +#![feature(lazy_cell)] #![feature(lint_reasons)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] // warn on lints, that are included in `rust-lang/rust`s bootstrap diff --git a/tests/compile-test.rs b/tests/compile-test.rs index c10ee969c014..57890ff31737 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -1,5 +1,5 @@ #![feature(test)] // compiletest_rs requires this attribute -#![feature(once_cell)] +#![feature(lazy_cell)] #![feature(is_sorted)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] #![warn(rust_2018_idioms, unused_lifetimes)] diff --git a/tests/dogfood.rs b/tests/dogfood.rs index 3a5d478fa314..68a878e9a3d3 100644 --- a/tests/dogfood.rs +++ b/tests/dogfood.rs @@ -3,7 +3,7 @@ //! //! See [Eating your own dog food](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) for context -#![feature(once_cell)] +#![feature(lazy_cell)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] #![warn(rust_2018_idioms, unused_lifetimes)] diff --git a/tests/lint_message_convention.rs b/tests/lint_message_convention.rs index abd0d1bc5934..8feea800fdbe 100644 --- a/tests/lint_message_convention.rs +++ b/tests/lint_message_convention.rs @@ -1,4 +1,4 @@ -#![feature(once_cell)] +#![feature(lazy_cell)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] #![warn(rust_2018_idioms, unused_lifetimes)] diff --git a/tests/workspace.rs b/tests/workspace.rs index 95325e060378..c9cbc50546cf 100644 --- a/tests/workspace.rs +++ b/tests/workspace.rs @@ -1,4 +1,4 @@ -#![feature(once_cell)] +#![feature(lazy_cell)] use std::path::PathBuf; use std::process::Command; From 37caa74e8d90e5475386c05412b1713bbd566719 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 29 Mar 2023 08:37:47 +0000 Subject: [PATCH 0792/1222] rust-analyzer guided enum variant structification --- clippy_lints/src/redundant_static_lifetimes.rs | 4 ++-- clippy_utils/src/ast_utils.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/redundant_static_lifetimes.rs b/clippy_lints/src/redundant_static_lifetimes.rs index 44bf824aa0e2..d2f03f2a97fb 100644 --- a/clippy_lints/src/redundant_static_lifetimes.rs +++ b/clippy_lints/src/redundant_static_lifetimes.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::source::snippet; -use rustc_ast::ast::{Item, ItemKind, Ty, TyKind}; +use rustc_ast::ast::{Item, ItemKind, Ty, TyKind, Static}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -106,7 +106,7 @@ impl EarlyLintPass for RedundantStaticLifetimes { // #2438) } - if let ItemKind::Static(ref var_type, _, _) = item.kind { + if let ItemKind::Static(Static(ref var_type, _, _)) = item.kind { Self::visit_type(var_type, cx, "statics have by default a `'static` lifetime"); } } diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index d2dedc204395..30be129ad75a 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -286,7 +286,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { match (l, r) { (ExternCrate(l), ExternCrate(r)) => l == r, (Use(l), Use(r)) => eq_use_tree(l, r), - (Static(lt, lm, le), Static(rt, rm, re)) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), + (Static(ast::Static(lt, lm, le)), Static(ast::Static(rt, rm, re))) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), (Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), ( Fn(box ast::Fn { From bb89a12fd26bfb59cc0c2142ad5a4511496743cc Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 29 Mar 2023 08:50:04 +0000 Subject: [PATCH 0793/1222] rust-analyzer guided tuple field to named field --- clippy_lints/src/redundant_static_lifetimes.rs | 2 +- clippy_utils/src/ast_utils.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/redundant_static_lifetimes.rs b/clippy_lints/src/redundant_static_lifetimes.rs index d2f03f2a97fb..434f00113319 100644 --- a/clippy_lints/src/redundant_static_lifetimes.rs +++ b/clippy_lints/src/redundant_static_lifetimes.rs @@ -106,7 +106,7 @@ impl EarlyLintPass for RedundantStaticLifetimes { // #2438) } - if let ItemKind::Static(Static(ref var_type, _, _)) = item.kind { + if let ItemKind::Static(Static{ ty: ref var_type,.. }) = item.kind { Self::visit_type(var_type, cx, "statics have by default a `'static` lifetime"); } } diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 30be129ad75a..258207639a17 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -286,7 +286,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { match (l, r) { (ExternCrate(l), ExternCrate(r)) => l == r, (Use(l), Use(r)) => eq_use_tree(l, r), - (Static(ast::Static(lt, lm, le)), Static(ast::Static(rt, rm, re))) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), + (Static(ast::Static{ ty: lt, mutability: lm, expr: le}), Static(ast::Static { ty: rt, mutability: rm, expr: re})) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), (Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), ( Fn(box ast::Fn { From bdcf54b0f1699e00a44b91c5dfbdef93ec7d9c6b Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 29 Mar 2023 09:20:45 +0000 Subject: [PATCH 0794/1222] Split out ast::ItemKind::Const into its own struct --- clippy_lints/src/redundant_static_lifetimes.rs | 4 ++-- clippy_utils/src/ast_utils.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/redundant_static_lifetimes.rs b/clippy_lints/src/redundant_static_lifetimes.rs index 434f00113319..d41f79f81315 100644 --- a/clippy_lints/src/redundant_static_lifetimes.rs +++ b/clippy_lints/src/redundant_static_lifetimes.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::source::snippet; -use rustc_ast::ast::{Item, ItemKind, Ty, TyKind, Static}; +use rustc_ast::ast::{Item, ItemKind, Ty, TyKind, Static, ConstItem}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -100,7 +100,7 @@ impl EarlyLintPass for RedundantStaticLifetimes { } if !item.span.from_expansion() { - if let ItemKind::Const(_, ref var_type, _) = item.kind { + if let ItemKind::Const(ConstItem { ty: ref var_type, .. }) = item.kind { Self::visit_type(var_type, cx, "constants have by default a `'static` lifetime"); // Don't check associated consts because `'static` cannot be elided on those (issue // #2438) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 258207639a17..be841098dba3 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -287,7 +287,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { (ExternCrate(l), ExternCrate(r)) => l == r, (Use(l), Use(r)) => eq_use_tree(l, r), (Static(ast::Static{ ty: lt, mutability: lm, expr: le}), Static(ast::Static { ty: rt, mutability: rm, expr: re})) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), - (Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), + (Const(ast::ConstItem { defaultness: ld, ty: lt, expr: le}), Const(ast::ConstItem { defaultness: rd, ty: rt, expr: re} )) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), ( Fn(box ast::Fn { defaultness: ld, @@ -451,7 +451,7 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { use AssocItemKind::*; match (l, r) { - (Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), + (Const(ast::ConstItem { defaultness: ld, ty: lt, expr: le}), Const(ast::ConstItem { defaultness: rd, ty: rt, expr: re})) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), ( Fn(box ast::Fn { defaultness: ld, From f2dc316018f3e866011498b66fdb5b523fb1503a Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 29 Mar 2023 12:34:05 +0000 Subject: [PATCH 0795/1222] box a bunch of large types --- clippy_lints/src/redundant_static_lifetimes.rs | 4 ++-- clippy_utils/src/ast_utils.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/redundant_static_lifetimes.rs b/clippy_lints/src/redundant_static_lifetimes.rs index d41f79f81315..aa47f3aed54d 100644 --- a/clippy_lints/src/redundant_static_lifetimes.rs +++ b/clippy_lints/src/redundant_static_lifetimes.rs @@ -100,13 +100,13 @@ impl EarlyLintPass for RedundantStaticLifetimes { } if !item.span.from_expansion() { - if let ItemKind::Const(ConstItem { ty: ref var_type, .. }) = item.kind { + if let ItemKind::Const(box ConstItem { ty: ref var_type, .. }) = item.kind { Self::visit_type(var_type, cx, "constants have by default a `'static` lifetime"); // Don't check associated consts because `'static` cannot be elided on those (issue // #2438) } - if let ItemKind::Static(Static{ ty: ref var_type,.. }) = item.kind { + if let ItemKind::Static(box Static { ty: ref var_type,.. }) = item.kind { Self::visit_type(var_type, cx, "statics have by default a `'static` lifetime"); } } diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index be841098dba3..0d2a7440c465 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -286,8 +286,8 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { match (l, r) { (ExternCrate(l), ExternCrate(r)) => l == r, (Use(l), Use(r)) => eq_use_tree(l, r), - (Static(ast::Static{ ty: lt, mutability: lm, expr: le}), Static(ast::Static { ty: rt, mutability: rm, expr: re})) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), - (Const(ast::ConstItem { defaultness: ld, ty: lt, expr: le}), Const(ast::ConstItem { defaultness: rd, ty: rt, expr: re} )) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), + (Static(box ast::Static{ ty: lt, mutability: lm, expr: le}), Static(box ast::Static { ty: rt, mutability: rm, expr: re})) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), + (Const(box ast::ConstItem { defaultness: ld, ty: lt, expr: le}), Const(box ast::ConstItem { defaultness: rd, ty: rt, expr: re} )) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), ( Fn(box ast::Fn { defaultness: ld, @@ -451,7 +451,7 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { use AssocItemKind::*; match (l, r) { - (Const(ast::ConstItem { defaultness: ld, ty: lt, expr: le}), Const(ast::ConstItem { defaultness: rd, ty: rt, expr: re})) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), + (Const(box ast::ConstItem { defaultness: ld, ty: lt, expr: le}), Const(box ast::ConstItem { defaultness: rd, ty: rt, expr: re})) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), ( Fn(box ast::Fn { defaultness: ld, From 5f961709c8570548bc14e091d07d5875c87598c8 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 29 Mar 2023 14:14:11 +0000 Subject: [PATCH 0796/1222] Rename `ast::Static` to `ast::StaticItem` to match `ast::ConstItem` --- clippy_lints/src/redundant_static_lifetimes.rs | 4 ++-- clippy_utils/src/ast_utils.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/redundant_static_lifetimes.rs b/clippy_lints/src/redundant_static_lifetimes.rs index aa47f3aed54d..11b908e7e53d 100644 --- a/clippy_lints/src/redundant_static_lifetimes.rs +++ b/clippy_lints/src/redundant_static_lifetimes.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::source::snippet; -use rustc_ast::ast::{Item, ItemKind, Ty, TyKind, Static, ConstItem}; +use rustc_ast::ast::{Item, ItemKind, Ty, TyKind, StaticItem, ConstItem}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -106,7 +106,7 @@ impl EarlyLintPass for RedundantStaticLifetimes { // #2438) } - if let ItemKind::Static(box Static { ty: ref var_type,.. }) = item.kind { + if let ItemKind::Static(box StaticItem { ty: ref var_type,.. }) = item.kind { Self::visit_type(var_type, cx, "statics have by default a `'static` lifetime"); } } diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 0d2a7440c465..c5b58b0c060c 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -286,7 +286,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { match (l, r) { (ExternCrate(l), ExternCrate(r)) => l == r, (Use(l), Use(r)) => eq_use_tree(l, r), - (Static(box ast::Static{ ty: lt, mutability: lm, expr: le}), Static(box ast::Static { ty: rt, mutability: rm, expr: re})) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), + (Static(box ast::StaticItem { ty: lt, mutability: lm, expr: le}), Static(box ast::StaticItem { ty: rt, mutability: rm, expr: re})) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), (Const(box ast::ConstItem { defaultness: ld, ty: lt, expr: le}), Const(box ast::ConstItem { defaultness: rd, ty: rt, expr: re} )) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), ( Fn(box ast::Fn { From 6ae4b4dab7b8a46499603dd21c805fa82bee380f Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 8 Oct 2022 23:47:59 +0100 Subject: [PATCH 0797/1222] Refactor unwind from Option to a new enum --- clippy_utils/src/qualify_min_const_fn.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index d66640ba0b7a..ff195cd72880 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -318,7 +318,7 @@ fn check_terminator<'tcx>( from_hir_call: _, destination: _, target: _, - cleanup: _, + unwind: _, fn_span: _, } => { let fn_ty = func.ty(body, tcx); @@ -361,7 +361,7 @@ fn check_terminator<'tcx>( expected: _, msg: _, target: _, - cleanup: _, + unwind: _, } => check_operand(tcx, cond, span, body), TerminatorKind::InlineAsm { .. } => Err((span, "cannot use inline assembly in const fn".into())), From bbef59b4817f6558401c01a34e5a2916e373ec42 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 10 Oct 2022 23:17:07 +0100 Subject: [PATCH 0798/1222] Fix tools --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index ff195cd72880..354b6d71aa46 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -301,13 +301,13 @@ fn check_terminator<'tcx>( | TerminatorKind::Goto { .. } | TerminatorKind::Return | TerminatorKind::Resume + | TerminatorKind::Terminate | TerminatorKind::Unreachable => Ok(()), TerminatorKind::Drop { place, .. } => check_place(tcx, *place, span, body), TerminatorKind::SwitchInt { discr, targets: _ } => check_operand(tcx, discr, span, body), - TerminatorKind::Abort => Err((span, "abort is not stable in const fn".into())), TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => { Err((span, "const fn generators are unstable".into())) }, From c7cdd22f0b0f236c662677e9114404efbebb7c2b Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 6 Apr 2023 23:11:19 +0000 Subject: [PATCH 0799/1222] Make elaborator generic --- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_utils/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 327e090d38be..0bb1775aae9c 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -122,7 +122,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { let sized_trait = need!(cx.tcx.lang_items().sized_trait()); - let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds().iter()) + let preds = traits::elaborate(cx.tcx, cx.param_env.caller_bounds().iter()) .filter(|p| !p.is_global()) .filter_map(|pred| { // Note that we do not want to deal with qualified predicates here. diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 619aa9f4bf6f..9051cf51658d 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -2104,7 +2104,7 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool { .filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None }); traits::impossible_predicates( cx.tcx, - traits::elaborate_predicates(cx.tcx, predicates) + traits::elaborate(cx.tcx, predicates) .collect::>(), ) } From 2b81cd6d356d940e68509a4971bd493fcc139f7b Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 10 Apr 2023 19:07:57 +0300 Subject: [PATCH 0800/1222] resolve: Pre-compute non-reexport module children Instead of repeating the same logic by walking HIR during metadata encoding. The only difference is that we are no longer encoding `macro_rules` items, but we never currently need them as a part of this list. They can be encoded separately if this need ever arises. `module_reexports` is also un-querified, because I don't see any reasons to make it a query, only overhead. --- tests/ui/macro_use_imports.fixed | 2 +- tests/ui/macro_use_imports.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/macro_use_imports.fixed b/tests/ui/macro_use_imports.fixed index 15f7a099a7de..a395e4f5653f 100644 --- a/tests/ui/macro_use_imports.fixed +++ b/tests/ui/macro_use_imports.fixed @@ -16,7 +16,7 @@ extern crate macro_use_helper as mac; extern crate proc_macro_derive as mini_mac; mod a { - use mac::{pub_macro, function_macro, ty_macro, inner_mod_macro, pub_in_private_macro}; + use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro}; use mac; use mini_mac::ClippyMiniMacroTest; use mini_mac; diff --git a/tests/ui/macro_use_imports.stderr b/tests/ui/macro_use_imports.stderr index 68d558dede05..6fd338cef868 100644 --- a/tests/ui/macro_use_imports.stderr +++ b/tests/ui/macro_use_imports.stderr @@ -22,7 +22,7 @@ error: `macro_use` attributes are no longer needed in the Rust 2018 edition --> $DIR/macro_use_imports.rs:19:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{pub_macro, function_macro, ty_macro, inner_mod_macro, pub_in_private_macro};` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro};` error: aborting due to 4 previous errors From d86579a200a59fba97762cae57d0b4eb5d94eaf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 18 Mar 2023 02:18:39 +0000 Subject: [PATCH 0801/1222] Tweak output for 'add line' suggestion --- tests/ui/crashes/ice-6252.stderr | 9 ++++++--- tests/ui/derivable_impls.stderr | 24 ++++++++++++++++-------- tests/ui/new_without_default.stderr | 6 ++++++ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index efdd56dd47d3..3c7e08ebeae8 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -6,11 +6,14 @@ LL | _n: PhantomData, | help: consider importing one of these items | -LL | use core::marker::PhantomData; +LL + use core::marker::PhantomData; +LL | trait TypeVal { | -LL | use serde::__private::PhantomData; +LL + use serde::__private::PhantomData; +LL | trait TypeVal { | -LL | use std::marker::PhantomData; +LL + use std::marker::PhantomData; +LL | trait TypeVal { | error[E0412]: cannot find type `VAL` in this scope diff --git a/tests/ui/derivable_impls.stderr b/tests/ui/derivable_impls.stderr index 81963c3be5b5..8089f5ea0fcb 100644 --- a/tests/ui/derivable_impls.stderr +++ b/tests/ui/derivable_impls.stderr @@ -14,7 +14,8 @@ LL | | } = help: remove the manual implementation... help: ...and instead derive it | -LL | #[derive(Default)] +LL + #[derive(Default)] +LL | struct FooDefault<'a> { | error: this `impl` can be derived @@ -30,7 +31,8 @@ LL | | } = help: remove the manual implementation... help: ...and instead derive it | -LL | #[derive(Default)] +LL + #[derive(Default)] +LL | struct TupleDefault(bool, i32, u64); | error: this `impl` can be derived @@ -46,7 +48,8 @@ LL | | } = help: remove the manual implementation... help: ...and instead derive it | -LL | #[derive(Default)] +LL + #[derive(Default)] +LL | struct StrDefault<'a>(&'a str); | error: this `impl` can be derived @@ -62,7 +65,8 @@ LL | | } = help: remove the manual implementation... help: ...and instead derive it | -LL | #[derive(Default)] +LL + #[derive(Default)] +LL | struct Y(u32); | error: this `impl` can be derived @@ -78,7 +82,8 @@ LL | | } = help: remove the manual implementation... help: ...and instead derive it | -LL | #[derive(Default)] +LL + #[derive(Default)] +LL | struct WithoutSelfCurly { | error: this `impl` can be derived @@ -94,7 +99,8 @@ LL | | } = help: remove the manual implementation... help: ...and instead derive it | -LL | #[derive(Default)] +LL + #[derive(Default)] +LL | struct WithoutSelfParan(bool); | error: this `impl` can be derived @@ -110,7 +116,8 @@ LL | | } = help: remove the manual implementation... help: ...and instead derive it | -LL | #[derive(Default)] +LL + #[derive(Default)] +LL | pub struct RepeatDefault1 { | error: this `impl` can be derived @@ -126,7 +133,8 @@ LL | | } = help: remove the manual implementation... help: ...and instead derive it... | -LL | #[derive(Default)] +LL + #[derive(Default)] +LL | pub enum SimpleEnum { | help: ...and mark the default variant | diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 583dd327d6a5..9b0a2f6ca5bf 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -14,6 +14,7 @@ LL + fn default() -> Self { LL + Self::new() LL + } LL + } +LL | impl Foo { | error: you should consider adding a `Default` implementation for `Bar` @@ -31,6 +32,7 @@ LL + fn default() -> Self { LL + Self::new() LL + } LL + } +LL | impl Bar { | error: you should consider adding a `Default` implementation for `LtKo<'c>` @@ -48,6 +50,7 @@ LL + fn default() -> Self { LL + Self::new() LL + } LL + } +LL | impl<'c> LtKo<'c> { | error: you should consider adding a `Default` implementation for `NewNotEqualToDerive` @@ -65,6 +68,7 @@ LL + fn default() -> Self { LL + Self::new() LL + } LL + } +LL | impl NewNotEqualToDerive { | error: you should consider adding a `Default` implementation for `FooGenerics` @@ -82,6 +86,7 @@ LL + fn default() -> Self { LL + Self::new() LL + } LL + } +LL | impl FooGenerics { | error: you should consider adding a `Default` implementation for `BarGenerics` @@ -99,6 +104,7 @@ LL + fn default() -> Self { LL + Self::new() LL + } LL + } +LL | impl BarGenerics { | error: you should consider adding a `Default` implementation for `Foo` From e18a88ffb20877c0f6b6b3f0d7828320d809c596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 10 Apr 2023 16:46:12 +0000 Subject: [PATCH 0802/1222] Special-case item attributes in the suggestion output --- tests/ui/crashes/ice-6252.stderr | 3 --- tests/ui/new_without_default.stderr | 6 ------ 2 files changed, 9 deletions(-) diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index 3c7e08ebeae8..4787282f504a 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -7,13 +7,10 @@ LL | _n: PhantomData, help: consider importing one of these items | LL + use core::marker::PhantomData; -LL | trait TypeVal { | LL + use serde::__private::PhantomData; -LL | trait TypeVal { | LL + use std::marker::PhantomData; -LL | trait TypeVal { | error[E0412]: cannot find type `VAL` in this scope diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 9b0a2f6ca5bf..583dd327d6a5 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -14,7 +14,6 @@ LL + fn default() -> Self { LL + Self::new() LL + } LL + } -LL | impl Foo { | error: you should consider adding a `Default` implementation for `Bar` @@ -32,7 +31,6 @@ LL + fn default() -> Self { LL + Self::new() LL + } LL + } -LL | impl Bar { | error: you should consider adding a `Default` implementation for `LtKo<'c>` @@ -50,7 +48,6 @@ LL + fn default() -> Self { LL + Self::new() LL + } LL + } -LL | impl<'c> LtKo<'c> { | error: you should consider adding a `Default` implementation for `NewNotEqualToDerive` @@ -68,7 +65,6 @@ LL + fn default() -> Self { LL + Self::new() LL + } LL + } -LL | impl NewNotEqualToDerive { | error: you should consider adding a `Default` implementation for `FooGenerics` @@ -86,7 +82,6 @@ LL + fn default() -> Self { LL + Self::new() LL + } LL + } -LL | impl FooGenerics { | error: you should consider adding a `Default` implementation for `BarGenerics` @@ -104,7 +99,6 @@ LL + fn default() -> Self { LL + Self::new() LL + } LL + } -LL | impl BarGenerics { | error: you should consider adding a `Default` implementation for `Foo` From b35ade9cf1acfb12b9cdd9fe98d0437ac741a0d6 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sat, 25 Mar 2023 10:12:35 +0000 Subject: [PATCH 0803/1222] Alloc `hir::Lit` in an arena to remove the destructor from `Expr` This allows allocating `Expr`s into a dropless arena, which is useful for using length prefixed thing slices in HIR, since these can only be allocated in the dropless arena and not in a typed arena. This is something I'm working on. --- clippy_lints/src/bool_assert_comparison.rs | 2 +- clippy_lints/src/manual_strip.rs | 2 +- clippy_lints/src/matches/match_like_matches.rs | 2 +- clippy_lints/src/methods/open_options.rs | 2 +- clippy_lints/src/utils/author.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/bool_assert_comparison.rs b/clippy_lints/src/bool_assert_comparison.rs index 1d9096ea64d1..8c3ad24eeed4 100644 --- a/clippy_lints/src/bool_assert_comparison.rs +++ b/clippy_lints/src/bool_assert_comparison.rs @@ -41,7 +41,7 @@ fn extract_bool_lit(e: &Expr<'_>) -> Option { }) = e.kind && !e.span.from_expansion() { - Some(b) + Some(*b) } else { None } diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index c795c1d9a16c..7d28c1116245 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -159,7 +159,7 @@ fn eq_pattern_length<'tcx>(cx: &LateContext<'tcx>, pattern: &Expr<'_>, expr: &'t .. }) = expr.kind { - constant_length(cx, pattern).map_or(false, |length| length == n) + constant_length(cx, pattern).map_or(false, |length| length == *n) } else { len_arg(cx, expr).map_or(false, |arg| eq_expr_value(cx, pattern, arg)) } diff --git a/clippy_lints/src/matches/match_like_matches.rs b/clippy_lints/src/matches/match_like_matches.rs index 107fad32393c..33bc20dad6b7 100644 --- a/clippy_lints/src/matches/match_like_matches.rs +++ b/clippy_lints/src/matches/match_like_matches.rs @@ -162,7 +162,7 @@ fn find_bool_lit(ex: &ExprKind<'_>) -> Option { node: LitKind::Bool(b), .. }) = exp.kind { - Some(b) + Some(*b) } else { None } diff --git a/clippy_lints/src/methods/open_options.rs b/clippy_lints/src/methods/open_options.rs index c6a27cdd6fac..23d23f25f14c 100644 --- a/clippy_lints/src/methods/open_options.rs +++ b/clippy_lints/src/methods/open_options.rs @@ -48,7 +48,7 @@ fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec .. } = *span { - if lit { Argument::True } else { Argument::False } + if *lit { Argument::True } else { Argument::False } } else { // The function is called with a literal which is not a boolean literal. // This is theoretically possible, but not very likely. diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index bc4adf1596d4..2dac807c420e 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -430,7 +430,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { kind!("Unary(UnOp::{op:?}, {inner})"); self.expr(inner); }, - ExprKind::Lit(ref lit) => { + ExprKind::Lit(lit) => { bind!(self, lit); kind!("Lit(ref {lit})"); self.lit(lit); From f5bc05bbcf9d2d1e696891e8c529b5cf239aed66 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 17 Apr 2023 13:45:11 +0200 Subject: [PATCH 0804/1222] Force -Zflatten-format-args=no in Clippy. --- src/driver.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/driver.rs b/src/driver.rs index 718bc41fb992..205905d50913 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -160,6 +160,9 @@ impl rustc_driver::Callbacks for ClippyCallbacks { // MIR passes can be enabled / disabled separately, we should figure out, what passes to // use for Clippy. config.opts.unstable_opts.mir_opt_level = Some(0); + + // Disable flattening and inlining of format_args!(), so the HIR matches with the AST. + config.opts.unstable_opts.flatten_format_args = false; } } From ca4336fe00218b9329df49d6f22e9f89388de66d Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Tue, 18 Apr 2023 17:39:08 +0000 Subject: [PATCH 0805/1222] Remove very useless `as_substs` usage from clippy --- clippy_utils/src/ty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 9449f0b55674..8b996c188161 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -975,7 +975,7 @@ pub fn approx_ty_size<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> u64 { } match (cx.layout_of(ty).map(|layout| layout.size.bytes()), ty.kind()) { (Ok(size), _) => size, - (Err(_), ty::Tuple(list)) => list.as_substs().types().map(|t| approx_ty_size(cx, t)).sum(), + (Err(_), ty::Tuple(list)) => list.iter().map(|t| approx_ty_size(cx, t)).sum(), (Err(_), ty::Array(t, n)) => { n.try_eval_target_usize(cx.tcx, cx.param_env).unwrap_or_default() * approx_ty_size(cx, *t) }, From 7f714be1b1ded5cd872510580ad5e59ffbb1c792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 18 Apr 2023 18:15:06 +0200 Subject: [PATCH 0806/1222] clippy: add test for https://github.com/rust-lang/rust-clippy/issues/10645 --- tests/ui/crashes/ice-5207.rs | 5 ++++- tests/ui/crashes/ice-5207.stderr | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/ui/crashes/ice-5207.stderr diff --git a/tests/ui/crashes/ice-5207.rs b/tests/ui/crashes/ice-5207.rs index f463f78a99ab..893c15f5d731 100644 --- a/tests/ui/crashes/ice-5207.rs +++ b/tests/ui/crashes/ice-5207.rs @@ -1,5 +1,8 @@ -// Regression test for https://github.com/rust-lang/rust-clippy/issues/5207 +// compile-flags: --cap-lints=warn +// ^ for https://github.com/rust-lang/rust-clippy/issues/10645 +// Regression test for https://github.com/rust-lang/rust-clippy/issues/5207 +#![warn(clippy::future_not_send)] pub async fn bar<'a, T: 'a>(_: T) {} fn main() {} diff --git a/tests/ui/crashes/ice-5207.stderr b/tests/ui/crashes/ice-5207.stderr new file mode 100644 index 000000000000..367e9a08b756 --- /dev/null +++ b/tests/ui/crashes/ice-5207.stderr @@ -0,0 +1,16 @@ +warning: future cannot be sent between threads safely + --> $DIR/ice-5207.rs:6:35 + | +LL | pub async fn bar<'a, T: 'a>(_: T) {} + | ^ future returned by `bar` is not `Send` + | +note: captured value is not `Send` + --> $DIR/ice-5207.rs:6:29 + | +LL | pub async fn bar<'a, T: 'a>(_: T) {} + | ^ has type `T` which is not `Send` + = note: `T` doesn't implement `std::marker::Send` + = note: `-D clippy::future-not-send` implied by `-D warnings` + +warning: 1 warning emitted + From a7426365e7b3e6be6feb8465c78f7fe1bea72454 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 8 May 2022 15:53:19 +0200 Subject: [PATCH 0807/1222] Remove WithOptconstParam. --- clippy_lints/src/non_copy_const.rs | 8 +++----- clippy_utils/src/consts.rs | 6 +----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 0bedab05eec6..eed0f1f19918 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -196,11 +196,9 @@ fn is_value_unfrozen_poly<'tcx>(cx: &LateContext<'tcx>, body_id: BodyId, ty: Ty< fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: DefId, ty: Ty<'tcx>) -> bool { let substs = cx.typeck_results().node_substs(hir_id); - let result = cx.tcx.const_eval_resolve( - cx.param_env, - mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs), - None, - ); + let result = cx + .tcx + .const_eval_resolve(cx.param_env, mir::UnevaluatedConst::new(def_id, substs), None); is_value_unfrozen_raw(cx, result, ty) } diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index bb8890dcaf98..99bfc4b5717c 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -450,11 +450,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let result = self .lcx .tcx - .const_eval_resolve( - self.param_env, - mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs), - None, - ) + .const_eval_resolve(self.param_env, mir::UnevaluatedConst::new(def_id, substs), None) .ok() .map(|val| rustc_middle::mir::ConstantKind::from_value(val, ty))?; let result = miri_to_const(self.lcx.tcx, result); From 3950e747dfdab15b8d71a0c90d72230dd715376c Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Mon, 17 Apr 2023 15:57:29 -0600 Subject: [PATCH 0808/1222] change usages of explicit_item_bounds to bound_explicit_item_bounds --- clippy_lints/src/future_not_send.rs | 7 +++---- clippy_utils/src/ty.rs | 5 +++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index ed0bd58c770c..73ae2406f9db 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, AliasTy, Clause, EarlyBinder, PredicateKind}; +use rustc_middle::ty::{self, AliasTy, Clause, PredicateKind}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; use rustc_span::{sym, Span}; @@ -64,10 +64,9 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { } let ret_ty = return_ty(cx, cx.tcx.hir().local_def_id_to_hir_id(fn_def_id).expect_owner()); if let ty::Alias(ty::Opaque, AliasTy { def_id, substs, .. }) = *ret_ty.kind() { - let preds = cx.tcx.explicit_item_bounds(def_id); + let preds = cx.tcx.bound_explicit_item_bounds(def_id); let mut is_future = false; - for &(p, _span) in preds { - let p = EarlyBinder(p).subst(cx.tcx, substs); + for (p, _span) in preds.subst_iter_copied(cx.tcx, substs) { if let Some(trait_pred) = p.to_opt_poly_trait_pred() { if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() { is_future = true; diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 8b996c188161..058f6b0306dc 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -90,7 +90,8 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' return false; } - for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) { + for bound in cx.tcx.bound_explicit_item_bounds(def_id).transpose_iter() { + let (predicate, _span) = bound.map_bound(|b| *b).subst_identity(); match predicate.kind().skip_binder() { // For `impl Trait`, it will register a predicate of `T: Trait`, so we go through // and check substituions to find `U`. @@ -267,7 +268,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { }, ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { - for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { + for (predicate, _) in cx.tcx.bound_explicit_item_bounds(*def_id).skip_binder() { if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() { if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) { return true; From a5b0e499ad62bc4268dda114160951640551b196 Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Mon, 17 Apr 2023 16:43:46 -0600 Subject: [PATCH 0809/1222] add EarlyBinder to output of explicit_item_bounds; replace bound_explicit_item_bounds usages; remove bound_explicit_item_bounds query --- clippy_lints/src/future_not_send.rs | 2 +- clippy_utils/src/ty.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 73ae2406f9db..ff838c2d56e4 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { } let ret_ty = return_ty(cx, cx.tcx.hir().local_def_id_to_hir_id(fn_def_id).expect_owner()); if let ty::Alias(ty::Opaque, AliasTy { def_id, substs, .. }) = *ret_ty.kind() { - let preds = cx.tcx.bound_explicit_item_bounds(def_id); + let preds = cx.tcx.explicit_item_bounds(def_id); let mut is_future = false; for (p, _span) in preds.subst_iter_copied(cx.tcx, substs) { if let Some(trait_pred) = p.to_opt_poly_trait_pred() { diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 058f6b0306dc..5f768928adf0 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -90,7 +90,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' return false; } - for bound in cx.tcx.bound_explicit_item_bounds(def_id).transpose_iter() { + for bound in cx.tcx.explicit_item_bounds(def_id).transpose_iter() { let (predicate, _span) = bound.map_bound(|b| *b).subst_identity(); match predicate.kind().skip_binder() { // For `impl Trait`, it will register a predicate of `T: Trait`, so we go through @@ -268,7 +268,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { }, ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { - for (predicate, _) in cx.tcx.bound_explicit_item_bounds(*def_id).skip_binder() { + for (predicate, _) in cx.tcx.explicit_item_bounds(def_id).skip_binder() { if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() { if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) { return true; @@ -744,7 +744,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option for (pred, _) in cx .tcx - .bound_explicit_item_bounds(ty.def_id) + .explicit_item_bounds(ty.def_id) .subst_iter_copied(cx.tcx, ty.substs) { match pred.kind().skip_binder() { From 35765968edb3ca283a5ffe335af9c5cd83f349b6 Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Mon, 17 Apr 2023 17:19:08 -0600 Subject: [PATCH 0810/1222] add subst_identity_iter and subst_identity_iter_copied methods on EarlyBinder; use this to simplify some EarlyBinder noise around explicit_item_bounds calls --- clippy_utils/src/ty.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 5f768928adf0..cb700126c2bd 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -90,8 +90,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' return false; } - for bound in cx.tcx.explicit_item_bounds(def_id).transpose_iter() { - let (predicate, _span) = bound.map_bound(|b| *b).subst_identity(); + for (predicate, _span) in cx.tcx.explicit_item_bounds(def_id).subst_identity_iter_copied() { match predicate.kind().skip_binder() { // For `impl Trait`, it will register a predicate of `T: Trait`, so we go through // and check substituions to find `U`. From 5be0bdd7aa7b119929744a2d7b8219fbe71ddb14 Mon Sep 17 00:00:00 2001 From: DrMeepster <19316085+DrMeepster@users.noreply.github.com> Date: Sun, 11 Sep 2022 00:37:49 -0700 Subject: [PATCH 0811/1222] offset_of --- clippy_lints/src/loops/never_loop.rs | 3 ++- .../src/matches/significant_drop_in_scrutinee.rs | 1 + clippy_lints/src/utils/author.rs | 4 ++++ clippy_utils/src/eager_or_lazy.rs | 3 ++- clippy_utils/src/hir_utils.rs | 9 +++++++++ clippy_utils/src/qualify_min_const_fn.rs | 2 +- clippy_utils/src/sugg.rs | 2 ++ clippy_utils/src/visitors.rs | 1 + 8 files changed, 22 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index f0a1b1dfe562..5f1fdf00be8c 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -226,7 +226,8 @@ fn never_loop_expr(expr: &Expr<'_>, ignore_ids: &mut Vec, main_loop_id: H | InlineAsmOperand::SymStatic { .. } => NeverLoopResult::Otherwise, }) .fold(NeverLoopResult::Otherwise, combine_seq), - ExprKind::Yield(_, _) + ExprKind::OffsetOf(_, _) + | ExprKind::Yield(_, _) | ExprKind::Closure { .. } | ExprKind::Path(_) | ExprKind::ConstBlock(_) diff --git a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index 04225beeb704..7945275393c0 100644 --- a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -342,6 +342,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> { ExprKind::DropTemps(_) | ExprKind::Err(_) | ExprKind::InlineAsm(_) | + ExprKind::OffsetOf(_, _) | ExprKind::Let(_) | ExprKind::Lit(_) | ExprKind::Loop(_, _, _, _) | diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 2dac807c420e..01927b6b5f10 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -558,6 +558,10 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { kind!("InlineAsm(_)"); out!("// unimplemented: `ExprKind::InlineAsm` is not further destructured at the moment"); }, + ExprKind::OffsetOf(container, ref fields) => { + bind!(self, container, fields); + kind!("OffsetOf({container}, {fields})"); + } ExprKind::Struct(qpath, fields, base) => { bind!(self, qpath, fields); opt_bind!(self, base); diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 28c857170613..3df40942e7b5 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -218,7 +218,8 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS | ExprKind::AddrOf(..) | ExprKind::Struct(..) | ExprKind::Repeat(..) - | ExprKind::Block(Block { stmts: [], .. }, _) => (), + | ExprKind::Block(Block { stmts: [], .. }, _) + | ExprKind::OffsetOf(..) => (), // Assignment might be to a local defined earlier, so don't eagerly evaluate. // Blocks with multiple statements might be expensive, so don't eagerly evaluate. diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 3ee7147828bd..d972ed82c258 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -301,6 +301,9 @@ impl HirEqInterExpr<'_, '_, '_> { (&ExprKind::Unary(l_op, le), &ExprKind::Unary(r_op, re)) => l_op == r_op && self.eq_expr(le, re), (&ExprKind::Array(l), &ExprKind::Array(r)) => self.eq_exprs(l, r), (&ExprKind::DropTemps(le), &ExprKind::DropTemps(re)) => self.eq_expr(le, re), + (&ExprKind::OffsetOf(l_container, ref l_fields), &ExprKind::OffsetOf(r_container, ref r_fields)) => { + self.eq_ty(l_container, r_container) && over(l_fields, r_fields, |l, r| l.name == r.name) + }, _ => false, }; (is_eq && (!self.should_ignore(left) || !self.should_ignore(right))) @@ -701,6 +704,12 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } }, + ExprKind::OffsetOf(container, fields) => { + self.hash_ty(container); + for field in fields { + self.hash_name(field.name); + } + }, ExprKind::Let(Let { pat, init, ty, .. }) => { self.hash_expr(init); if let Some(ty) = ty { diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 354b6d71aa46..ecd712f32dc1 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -194,7 +194,7 @@ fn check_rvalue<'tcx>( )) } }, - Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) | Rvalue::ShallowInitBox(_, _) => Ok(()), + Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_), _) | Rvalue::ShallowInitBox(_, _) => Ok(()), Rvalue::UnaryOp(_, operand) => { let ty = operand.ty(body, tcx); if ty.is_integral() || ty.is_bool() { diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index a5a4a921d94e..e81eadceec0a 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -139,6 +139,7 @@ impl<'a> Sugg<'a> { | hir::ExprKind::Field(..) | hir::ExprKind::Index(..) | hir::ExprKind::InlineAsm(..) + | hir::ExprKind::OffsetOf(..) | hir::ExprKind::ConstBlock(..) | hir::ExprKind::Lit(..) | hir::ExprKind::Loop(..) @@ -197,6 +198,7 @@ impl<'a> Sugg<'a> { | ast::ExprKind::ForLoop(..) | ast::ExprKind::Index(..) | ast::ExprKind::InlineAsm(..) + | ast::ExprKind::OffsetOf(..) | ast::ExprKind::ConstBlock(..) | ast::ExprKind::Lit(..) | ast::ExprKind::IncludedBytes(..) diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index 1dc19bac9844..5dcd71cef127 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -662,6 +662,7 @@ pub fn for_each_unconsumed_temporary<'tcx, B>( | ExprKind::Path(_) | ExprKind::Continue(_) | ExprKind::InlineAsm(_) + | ExprKind::OffsetOf(..) | ExprKind::Err(_) => (), } ControlFlow::Continue(()) From 486ea4009e1c5968881783589a1f80fea0ddfb56 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 24 Nov 2022 19:09:27 +0000 Subject: [PATCH 0812/1222] Evaluate place expression in `PlaceMention`. --- tests/ui/option_if_let_else.fixed | 4 ++-- tests/ui/option_if_let_else.rs | 4 ++-- tests/ui/option_if_let_else.stderr | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/ui/option_if_let_else.fixed b/tests/ui/option_if_let_else.fixed index 0456005dce49..35ce89c79864 100644 --- a/tests/ui/option_if_let_else.fixed +++ b/tests/ui/option_if_let_else.fixed @@ -25,7 +25,7 @@ fn else_if_option(string: Option<&str>) -> Option<(bool, &str)> { fn unop_bad(string: &Option<&str>, mut num: Option) { let _ = string.map_or(0, |s| s.len()); let _ = num.as_ref().map_or(&0, |s| s); - let _ = num.as_mut().map_or(&mut 0, |s| { + let _ = num.as_mut().map_or(&0, |s| { *s += 1; s }); @@ -34,7 +34,7 @@ fn unop_bad(string: &Option<&str>, mut num: Option) { s += 1; s }); - let _ = num.as_mut().map_or(&mut 0, |s| { + let _ = num.as_mut().map_or(&0, |s| { *s += 1; s }); diff --git a/tests/ui/option_if_let_else.rs b/tests/ui/option_if_let_else.rs index 23b148752cbf..c8683e5aae2d 100644 --- a/tests/ui/option_if_let_else.rs +++ b/tests/ui/option_if_let_else.rs @@ -33,7 +33,7 @@ fn unop_bad(string: &Option<&str>, mut num: Option) { *s += 1; s } else { - &mut 0 + &0 }; let _ = if let Some(ref s) = num { s } else { &0 }; let _ = if let Some(mut s) = num { @@ -46,7 +46,7 @@ fn unop_bad(string: &Option<&str>, mut num: Option) { *s += 1; s } else { - &mut 0 + &0 }; } diff --git a/tests/ui/option_if_let_else.stderr b/tests/ui/option_if_let_else.stderr index a5dbf6e1f221..f5e4affb6722 100644 --- a/tests/ui/option_if_let_else.stderr +++ b/tests/ui/option_if_let_else.stderr @@ -30,13 +30,13 @@ LL | let _ = if let Some(s) = &mut num { LL | | *s += 1; LL | | s LL | | } else { -LL | | &mut 0 +LL | | &0 LL | | }; | |_____^ | help: try | -LL ~ let _ = num.as_mut().map_or(&mut 0, |s| { +LL ~ let _ = num.as_mut().map_or(&0, |s| { LL + *s += 1; LL + s LL ~ }); @@ -76,13 +76,13 @@ LL | let _ = if let Some(ref mut s) = num { LL | | *s += 1; LL | | s LL | | } else { -LL | | &mut 0 +LL | | &0 LL | | }; | |_____^ | help: try | -LL ~ let _ = num.as_mut().map_or(&mut 0, |s| { +LL ~ let _ = num.as_mut().map_or(&0, |s| { LL + *s += 1; LL + s LL ~ }); From fa309a72fba17258fe63e9ff5f9b99ab01cfe6fd Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 16 Feb 2023 09:25:11 +0000 Subject: [PATCH 0813/1222] Allow `LocalDefId` as the argument to `def_path_str` --- clippy_lints/src/default_union_representation.rs | 2 +- clippy_lints/src/trailing_empty_array.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/default_union_representation.rs b/clippy_lints/src/default_union_representation.rs index dec357ab75c3..03b5a2d6d082 100644 --- a/clippy_lints/src/default_union_representation.rs +++ b/clippy_lints/src/default_union_representation.rs @@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultUnionRepresentation { None, &format!( "consider annotating `{}` with `#[repr(C)]` to explicitly specify memory layout", - cx.tcx.def_path_str(item.owner_id.to_def_id()) + cx.tcx.def_path_str(item.owner_id) ), ); } diff --git a/clippy_lints/src/trailing_empty_array.rs b/clippy_lints/src/trailing_empty_array.rs index 1382c1a40da2..98f5b47f7a0e 100644 --- a/clippy_lints/src/trailing_empty_array.rs +++ b/clippy_lints/src/trailing_empty_array.rs @@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for TrailingEmptyArray { None, &format!( "consider annotating `{}` with `#[repr(C)]` or another `repr` attribute", - cx.tcx.def_path_str(item.owner_id.to_def_id()) + cx.tcx.def_path_str(item.owner_id) ), ); } From af0d87165f828c36e6d05692ba2b3d63c7eca676 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Mon, 24 Apr 2023 09:47:54 +0200 Subject: [PATCH 0814/1222] Clippy book: hotfix for broken link --- book/src/development/lint_passes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/development/lint_passes.md b/book/src/development/lint_passes.md index c41b6ea0de8f..131f6455fdea 100644 --- a/book/src/development/lint_passes.md +++ b/book/src/development/lint_passes.md @@ -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](define_lints.md#name-the-lint) chapter. +define new lints 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 From efa029c8ad9e1274522c9b3bd0800629eb4402b3 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Tue, 25 Apr 2023 16:31:51 +0000 Subject: [PATCH 0815/1222] Use `ty::TraitRef::new` in clippy --- clippy_lints/src/derive.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index f425dd5fb70b..8f5d319cd4fc 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -517,7 +517,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> tcx.mk_predicates_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain( params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| { tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate { - trait_ref: tcx.mk_trait_ref(eq_trait_id, [tcx.mk_param_from_def(param)]), + trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]), constness: BoundConstness::NotConst, polarity: ImplPolarity::Positive, })))) From 86f67c7b9799fff7bad58c5e653a00ac4463c903 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 26 Apr 2023 13:48:56 +0000 Subject: [PATCH 0816/1222] Fix uses of `TraitRef::identity` in clippy and rustdoc --- clippy_lints/src/escape.rs | 3 +-- clippy_lints/src/methods/mod.rs | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index d6ab4c25e83e..6615f9c99537 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -94,8 +94,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { if trait_item.kind == (AssocItemKind::Fn { has_self: true }) { trait_self_ty = Some( TraitRef::identity(cx.tcx, trait_item.id.owner_id.to_def_id()) - .self_ty() - .skip_binder(), + .self_ty(), ); } } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 9cafbc2e5f5a..09e097285730 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3500,8 +3500,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { let first_arg_span = first_arg_ty.span; let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty); let self_ty = TraitRef::identity(cx.tcx, item.owner_id.to_def_id()) - .self_ty() - .skip_binder(); + .self_ty(); wrong_self_convention::check( cx, item.ident.name.as_str(), @@ -3519,8 +3518,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let TraitItemKind::Fn(_, _) = item.kind; let ret_ty = return_ty(cx, item.owner_id); let self_ty = TraitRef::identity(cx.tcx, item.owner_id.to_def_id()) - .self_ty() - .skip_binder(); + .self_ty(); if !ret_ty.contains(self_ty); then { From f1ed07e39d11bfa40b0b7f985d6fe8a96163ddd3 Mon Sep 17 00:00:00 2001 From: Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> Date: Wed, 4 Jan 2023 14:16:55 +0100 Subject: [PATCH 0817/1222] Make `{Arc,Rc,Weak}::ptr_eq` ignore pointer metadata --- clippy_lints/src/unnamed_address.rs | 4 +--- clippy_utils/src/paths.rs | 2 -- tests/ui/vtable_address_comparisons.rs | 12 ++++++------ tests/ui/vtable_address_comparisons.stderr | 18 +----------------- 4 files changed, 8 insertions(+), 28 deletions(-) diff --git a/clippy_lints/src/unnamed_address.rs b/clippy_lints/src/unnamed_address.rs index 0bcafde658a4..0f5cdb6aaea1 100644 --- a/clippy_lints/src/unnamed_address.rs +++ b/clippy_lints/src/unnamed_address.rs @@ -96,9 +96,7 @@ impl LateLintPass<'_> for UnnamedAddress { if let ExprKind::Call(func, [ref _left, ref _right]) = expr.kind; if let ExprKind::Path(ref func_qpath) = func.kind; if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); - if match_def_path(cx, def_id, &paths::PTR_EQ) || - match_def_path(cx, def_id, &paths::RC_PTR_EQ) || - match_def_path(cx, def_id, &paths::ARC_PTR_EQ); + if match_def_path(cx, def_id, &paths::PTR_EQ); let ty_param = cx.typeck_results().node_substs(func.hir_id).type_at(0); if ty_param.is_trait(); then { diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index 9be2d0eae80a..126356c96826 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -15,7 +15,6 @@ pub const APPLICABILITY_VALUES: [[&str; 3]; 4] = [ ]; #[cfg(feature = "internal")] pub const DIAGNOSTIC_BUILDER: [&str; 3] = ["rustc_errors", "diagnostic_builder", "DiagnosticBuilder"]; -pub const ARC_PTR_EQ: [&str; 4] = ["alloc", "sync", "Arc", "ptr_eq"]; pub const BTREEMAP_CONTAINS_KEY: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "contains_key"]; pub const BTREEMAP_INSERT: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "insert"]; pub const BTREESET_ITER: [&str; 6] = ["alloc", "collections", "btree", "set", "BTreeSet", "iter"]; @@ -93,7 +92,6 @@ pub const PTR_WRITE_UNALIGNED: [&str; 3] = ["core", "ptr", "write_unaligned"]; pub const PTR_WRITE_VOLATILE: [&str; 3] = ["core", "ptr", "write_volatile"]; pub const PUSH_STR: [&str; 4] = ["alloc", "string", "String", "push_str"]; pub const RANGE_ARGUMENT_TRAIT: [&str; 3] = ["core", "ops", "RangeBounds"]; -pub const RC_PTR_EQ: [&str; 4] = ["alloc", "rc", "Rc", "ptr_eq"]; pub const REFCELL_REF: [&str; 3] = ["core", "cell", "Ref"]; pub const REFCELL_REFMUT: [&str; 3] = ["core", "cell", "RefMut"]; pub const REGEX_BUILDER_NEW: [&str; 5] = ["regex", "re_builder", "unicode", "RegexBuilder", "new"]; diff --git a/tests/ui/vtable_address_comparisons.rs b/tests/ui/vtable_address_comparisons.rs index a9a4a0f5a6b5..99c3f468f04a 100644 --- a/tests/ui/vtable_address_comparisons.rs +++ b/tests/ui/vtable_address_comparisons.rs @@ -23,12 +23,6 @@ fn main() { let b = &1 as &dyn Debug; ptr::eq(a, b); - let a: Rc = Rc::new(1); - Rc::ptr_eq(&a, &a); - - let a: Arc = Arc::new(1); - Arc::ptr_eq(&a, &a); - // These should be fine: let a = &1; ptr::eq(a, a); @@ -39,6 +33,12 @@ fn main() { let a = Arc::new(1); Arc::ptr_eq(&a, &a); + let a: Rc = Rc::new(1); + Rc::ptr_eq(&a, &a); + + let a: Arc = Arc::new(1); + Arc::ptr_eq(&a, &a); + let a: &[u8] = b""; ptr::eq(a, a); } diff --git a/tests/ui/vtable_address_comparisons.stderr b/tests/ui/vtable_address_comparisons.stderr index 14748f583f0c..7b866d274d58 100644 --- a/tests/ui/vtable_address_comparisons.stderr +++ b/tests/ui/vtable_address_comparisons.stderr @@ -63,21 +63,5 @@ LL | ptr::eq(a, b); | = help: consider extracting and comparing data pointers only -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:27:5 - | -LL | Rc::ptr_eq(&a, &a); - | ^^^^^^^^^^^^^^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:30:5 - | -LL | Arc::ptr_eq(&a, &a); - | ^^^^^^^^^^^^^^^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: aborting due to 10 previous errors +error: aborting due to 8 previous errors From a4d8c2e111100c847a7bb5f8a4746643fdaad7f6 Mon Sep 17 00:00:00 2001 From: Boxy Date: Thu, 27 Apr 2023 08:34:11 +0100 Subject: [PATCH 0818/1222] rename `needs_infer` to `has_infer` --- clippy_utils/src/ty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index cb700126c2bd..a65720116440 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -226,7 +226,7 @@ pub fn implements_trait_with_env<'tcx>( ty_params: impl IntoIterator>>, ) -> bool { // Clippy shouldn't have infer types - assert!(!ty.needs_infer()); + assert!(!ty.has_infer()); let ty = tcx.erase_regions(ty); if ty.has_escaping_bound_vars() { From dbfed1b403422be32dbaf6a37ad2789c794b97a7 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 25 Apr 2023 19:52:17 +0000 Subject: [PATCH 0819/1222] Make clippy happy --- .../src/suspicious_operation_groupings.rs | 2 +- clippy_utils/src/ast_utils.rs | 2 +- tests/ui/future_not_send.stderr | 24 +++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index fab8e9c2ec1c..e2cdc48b583c 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -577,7 +577,7 @@ fn ident_difference_expr_with_base_location( | (AssignOp(_, _, _), AssignOp(_, _, _)) | (Assign(_, _, _), Assign(_, _, _)) | (TryBlock(_), TryBlock(_)) - | (Await(_), Await(_)) + | (Await(_, _), Await(_, _)) | (Async(_, _), Async(_, _)) | (Block(_, _), Block(_, _)) | (Closure(_), Closure(_)) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 1f15598db36d..8cc01f1ef974 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -143,7 +143,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (Paren(l), _) => eq_expr(l, r), (_, Paren(r)) => eq_expr(l, r), (Err, Err) => true, - (Try(l), Try(r)) | (Await(l), Await(r)) => eq_expr(l, r), + (Try(l), Try(r)) | (Await(l, _), Await(r, _)) => eq_expr(l, r), (Array(l), Array(r)) => over(l, r, |l, r| eq_expr(l, r)), (Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)), (Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value), diff --git a/tests/ui/future_not_send.stderr b/tests/ui/future_not_send.stderr index 5b6858e4568b..5c6348962a5e 100644 --- a/tests/ui/future_not_send.stderr +++ b/tests/ui/future_not_send.stderr @@ -5,22 +5,22 @@ LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { | ^^^^ future returned by `private_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:8:19 + --> $DIR/future_not_send.rs:8:20 | LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { | -- has type `std::rc::Rc<[u8]>` which is not `Send` LL | async { true }.await - | ^^^^^^ await occurs here, with `rc` maybe used later + | ^^^^^ await occurs here, with `rc` maybe used later LL | } | - `rc` is later dropped here = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:8:19 + --> $DIR/future_not_send.rs:8:20 | LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { | ---- has type `&std::cell::Cell` which is not `Send` LL | async { true }.await - | ^^^^^^ await occurs here, with `cell` maybe used later + | ^^^^^ await occurs here, with `cell` maybe used later LL | } | - `cell` is later dropped here = note: `std::cell::Cell` doesn't implement `std::marker::Sync` @@ -33,12 +33,12 @@ LL | pub async fn public_future(rc: Rc<[u8]>) { | ^ future returned by `public_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:12:19 + --> $DIR/future_not_send.rs:12:20 | LL | pub async fn public_future(rc: Rc<[u8]>) { | -- has type `std::rc::Rc<[u8]>` which is not `Send` LL | async { true }.await; - | ^^^^^^ await occurs here, with `rc` maybe used later + | ^^^^^ await occurs here, with `rc` maybe used later LL | } | - `rc` is later dropped here = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` @@ -82,12 +82,12 @@ LL | async fn private_future(&self) -> usize { | ^^^^^ future returned by `private_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:35:23 + --> $DIR/future_not_send.rs:35:24 | LL | async fn private_future(&self) -> usize { | ----- has type `&Dummy` which is not `Send` LL | async { true }.await; - | ^^^^^^ await occurs here, with `&self` maybe used later + | ^^^^^ await occurs here, with `&self` maybe used later LL | self.rc.len() LL | } | - `&self` is later dropped here @@ -100,12 +100,12 @@ LL | pub async fn public_future(&self) { | ^ future returned by `public_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:40:30 + --> $DIR/future_not_send.rs:40:31 | LL | pub async fn public_future(&self) { | ----- has type `&Dummy` which is not `Send` LL | self.private_future().await; - | ^^^^^^ await occurs here, with `&self` maybe used later + | ^^^^^ await occurs here, with `&self` maybe used later LL | } | - `&self` is later dropped here = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` @@ -117,12 +117,12 @@ LL | async fn generic_future(t: T) -> T | ^ future returned by `generic_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:54:19 + --> $DIR/future_not_send.rs:54:20 | LL | let rt = &t; | -- has type `&T` which is not `Send` LL | async { true }.await; - | ^^^^^^ await occurs here, with `rt` maybe used later + | ^^^^^ await occurs here, with `rt` maybe used later LL | t LL | } | - `rt` is later dropped here From bfa3b5fcaa23e32a387775ef1cef2a8dd58e21c4 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Fri, 28 Apr 2023 17:17:46 +0000 Subject: [PATCH 0820/1222] uplift `clippy::clone_double_ref` as `suspicious_double_ref_op` --- clippy_lints/src/declared_lints.rs | 1 - clippy_lints/src/methods/clone_on_copy.rs | 40 +--------- clippy_lints/src/methods/mod.rs | 24 ------ clippy_lints/src/renamed_lints.rs | 1 + tests/ui/explicit_deref_methods.fixed | 2 +- tests/ui/explicit_deref_methods.rs | 2 +- tests/ui/rename.fixed | 2 + tests/ui/rename.rs | 2 + tests/ui/rename.stderr | 92 ++++++++++++----------- tests/ui/unnecessary_clone.rs | 13 ---- tests/ui/unnecessary_clone.stderr | 52 +------------ 11 files changed, 61 insertions(+), 170 deletions(-) diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 0c66d36a1d63..fa726a649370 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -313,7 +313,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::methods::CHARS_NEXT_CMP_INFO, crate::methods::CLEAR_WITH_DRAIN_INFO, crate::methods::CLONED_INSTEAD_OF_COPIED_INFO, - crate::methods::CLONE_DOUBLE_REF_INFO, crate::methods::CLONE_ON_COPY_INFO, crate::methods::CLONE_ON_REF_PTR_INFO, crate::methods::COLLAPSIBLE_STR_REPLACE_INFO, diff --git a/clippy_lints/src/methods/clone_on_copy.rs b/clippy_lints/src/methods/clone_on_copy.rs index 3795c0ec2509..65fd50dff584 100644 --- a/clippy_lints/src/methods/clone_on_copy.rs +++ b/clippy_lints/src/methods/clone_on_copy.rs @@ -1,7 +1,6 @@ -use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::get_parent_node; use clippy_utils::source::snippet_with_context; -use clippy_utils::sugg; use clippy_utils::ty::is_copy; use rustc_errors::Applicability; use rustc_hir::{BindingAnnotation, ByRef, Expr, ExprKind, MatchSource, Node, PatKind, QPath}; @@ -9,7 +8,6 @@ use rustc_lint::LateContext; use rustc_middle::ty::{self, adjustment::Adjust, print::with_forced_trimmed_paths}; use rustc_span::symbol::{sym, Symbol}; -use super::CLONE_DOUBLE_REF; use super::CLONE_ON_COPY; /// Checks for the `CLONE_ON_COPY` lint. @@ -42,41 +40,7 @@ pub(super) fn check( let ty = cx.typeck_results().expr_ty(expr); if let ty::Ref(_, inner, _) = arg_ty.kind() { - if let ty::Ref(_, innermost, _) = inner.kind() { - span_lint_and_then( - cx, - CLONE_DOUBLE_REF, - expr.span, - &with_forced_trimmed_paths!(format!( - "using `clone` on a double-reference; \ - this will copy the reference of type `{ty}` instead of cloning the inner type" - )), - |diag| { - if let Some(snip) = sugg::Sugg::hir_opt(cx, arg) { - let mut ty = innermost; - let mut n = 0; - while let ty::Ref(_, inner, _) = ty.kind() { - ty = inner; - n += 1; - } - let refs = "&".repeat(n + 1); - let derefs = "*".repeat(n); - let explicit = with_forced_trimmed_paths!(format!("<{refs}{ty}>::clone({snip})")); - diag.span_suggestion( - expr.span, - "try dereferencing it", - with_forced_trimmed_paths!(format!("{refs}({derefs}{}).clone()", snip.deref())), - Applicability::MaybeIncorrect, - ); - diag.span_suggestion( - expr.span, - "or try being explicit if you are sure, that you want to clone a reference", - explicit, - Applicability::MaybeIncorrect, - ); - } - }, - ); + if let ty::Ref(..) = inner.kind() { return; // don't report clone_on_copy } } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 9cafbc2e5f5a..e4a659d3ce73 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -984,29 +984,6 @@ declare_clippy_lint! { "using 'clone' on a ref-counted pointer" } -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of `.clone()` on an `&&T`. - /// - /// ### Why is this bad? - /// Cloning an `&&T` copies the inner `&T`, instead of - /// cloning the underlying `T`. - /// - /// ### Example - /// ```rust - /// fn main() { - /// let x = vec![1]; - /// let y = &&x; - /// let z = y.clone(); - /// println!("{:p} {:p}", *y, z); // prints out the same pointer - /// } - /// ``` - #[clippy::version = "pre 1.29.0"] - pub CLONE_DOUBLE_REF, - correctness, - "using `clone` on `&&T`" -} - declare_clippy_lint! { /// ### What it does /// Checks for usage of `.to_string()` on an `&&T` where @@ -3258,7 +3235,6 @@ impl_lint_pass!(Methods => [ CHARS_LAST_CMP, CLONE_ON_COPY, CLONE_ON_REF_PTR, - CLONE_DOUBLE_REF, COLLAPSIBLE_STR_REPLACE, ITER_OVEREAGER_CLONED, CLONED_INSTEAD_OF_COPIED, diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index 9f487dedb8cb..5e81a01a461a 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -30,6 +30,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::stutter", "clippy::module_name_repetitions"), ("clippy::to_string_in_display", "clippy::recursive_format_impl"), ("clippy::zero_width_space", "clippy::invisible_characters"), + ("clippy::clone_double_ref", "suspicious_double_ref_op"), ("clippy::drop_bounds", "drop_bounds"), ("clippy::for_loop_over_option", "for_loops_over_fallibles"), ("clippy::for_loop_over_result", "for_loops_over_fallibles"), diff --git a/tests/ui/explicit_deref_methods.fixed b/tests/ui/explicit_deref_methods.fixed index 77e9f5fc1fdf..60482c66da7c 100644 --- a/tests/ui/explicit_deref_methods.fixed +++ b/tests/ui/explicit_deref_methods.fixed @@ -3,7 +3,7 @@ #![allow(unused_variables)] #![allow( clippy::borrow_deref_ref, - clippy::clone_double_ref, + suspicious_double_ref_op, clippy::explicit_auto_deref, clippy::needless_borrow, clippy::uninlined_format_args diff --git a/tests/ui/explicit_deref_methods.rs b/tests/ui/explicit_deref_methods.rs index 0c2cc7c2c3a6..e3613e216bb2 100644 --- a/tests/ui/explicit_deref_methods.rs +++ b/tests/ui/explicit_deref_methods.rs @@ -3,7 +3,7 @@ #![allow(unused_variables)] #![allow( clippy::borrow_deref_ref, - clippy::clone_double_ref, + suspicious_double_ref_op, clippy::explicit_auto_deref, clippy::needless_borrow, clippy::uninlined_format_args diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index e8a00a9e7f71..ff19a042825d 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -36,6 +36,7 @@ #![allow(enum_intrinsics_non_enums)] #![allow(non_fmt_panics)] #![allow(named_arguments_used_positionally)] +#![allow(suspicious_double_ref_op)] #![allow(temporary_cstring_as_ptr)] #![allow(unknown_lints)] #![allow(unused_labels)] @@ -67,6 +68,7 @@ #![warn(clippy::module_name_repetitions)] #![warn(clippy::recursive_format_impl)] #![warn(clippy::invisible_characters)] +#![warn(suspicious_double_ref_op)] #![warn(drop_bounds)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index c8ea70c2bcb1..38b1647c0cca 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -36,6 +36,7 @@ #![allow(enum_intrinsics_non_enums)] #![allow(non_fmt_panics)] #![allow(named_arguments_used_positionally)] +#![allow(suspicious_double_ref_op)] #![allow(temporary_cstring_as_ptr)] #![allow(unknown_lints)] #![allow(unused_labels)] @@ -67,6 +68,7 @@ #![warn(clippy::stutter)] #![warn(clippy::to_string_in_display)] #![warn(clippy::zero_width_space)] +#![warn(clippy::clone_double_ref)] #![warn(clippy::drop_bounds)] #![warn(clippy::for_loop_over_option)] #![warn(clippy::for_loop_over_result)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 27a0263292ef..70d15408b9fc 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> $DIR/rename.rs:42:9 + --> $DIR/rename.rs:43:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -7,250 +7,256 @@ LL | #![warn(clippy::almost_complete_letter_range)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> $DIR/rename.rs:43:9 + --> $DIR/rename.rs:44:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:44:9 + --> $DIR/rename.rs:45:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:45:9 + --> $DIR/rename.rs:46:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> $DIR/rename.rs:46:9 + --> $DIR/rename.rs:47:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:47:9 + --> $DIR/rename.rs:48:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:48:9 + --> $DIR/rename.rs:49:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> $DIR/rename.rs:49:9 + --> $DIR/rename.rs:50:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> $DIR/rename.rs:50:9 + --> $DIR/rename.rs:51:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> $DIR/rename.rs:51:9 + --> $DIR/rename.rs:52:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> $DIR/rename.rs:52:9 + --> $DIR/rename.rs:53:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> $DIR/rename.rs:53:9 + --> $DIR/rename.rs:54:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> $DIR/rename.rs:54:9 + --> $DIR/rename.rs:55:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:55:9 + --> $DIR/rename.rs:56:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:56:9 + --> $DIR/rename.rs:57:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:57:9 + --> $DIR/rename.rs:58:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:58:9 + --> $DIR/rename.rs:59:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:59:9 + --> $DIR/rename.rs:60:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:60:9 + --> $DIR/rename.rs:61:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:61:9 + --> $DIR/rename.rs:62:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:62:9 + --> $DIR/rename.rs:63:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:63:9 + --> $DIR/rename.rs:64:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:64:9 + --> $DIR/rename.rs:65:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:65:9 + --> $DIR/rename.rs:66:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:66:9 + --> $DIR/rename.rs:67:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:67:9 + --> $DIR/rename.rs:68:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:69:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` +error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op` + --> $DIR/rename.rs:71:9 + | +LL | #![warn(clippy::clone_double_ref)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op` + error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:79:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:80:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:83:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 42 previous errors +error: aborting due to 43 previous errors diff --git a/tests/ui/unnecessary_clone.rs b/tests/ui/unnecessary_clone.rs index 8b1629b19a76..7ceed3c75fd8 100644 --- a/tests/ui/unnecessary_clone.rs +++ b/tests/ui/unnecessary_clone.rs @@ -42,14 +42,6 @@ fn clone_on_copy_generic(t: T) { Some(t).clone(); } -fn clone_on_double_ref() { - let x = vec![1]; - let y = &&x; - let z: &Vec<_> = y.clone(); - - println!("{:p} {:p}", *y, z); -} - mod many_derefs { struct A; struct B; @@ -84,11 +76,6 @@ mod many_derefs { let _: E = a.clone(); let _: E = *****a; } - - fn check(mut encoded: &[u8]) { - let _ = &mut encoded.clone(); - let _ = &encoded.clone(); - } } mod issue2076 { diff --git a/tests/ui/unnecessary_clone.stderr b/tests/ui/unnecessary_clone.stderr index 6022d9fa4c5c..5686ab6b4531 100644 --- a/tests/ui/unnecessary_clone.stderr +++ b/tests/ui/unnecessary_clone.stderr @@ -44,63 +44,17 @@ error: using `clone` on type `Option` which implements the `Copy` trait LL | Some(t).clone(); | ^^^^^^^^^^^^^^^ help: try removing the `clone` call: `Some(t)` -error: using `clone` on a double-reference; this will copy the reference of type `&Vec` instead of cloning the inner type - --> $DIR/unnecessary_clone.rs:48:22 - | -LL | let z: &Vec<_> = y.clone(); - | ^^^^^^^^^ - | - = note: `#[deny(clippy::clone_double_ref)]` on by default -help: try dereferencing it - | -LL | let z: &Vec<_> = &(*y).clone(); - | ~~~~~~~~~~~~~ -help: or try being explicit if you are sure, that you want to clone a reference - | -LL | let z: &Vec<_> = <&Vec>::clone(y); - | ~~~~~~~~~~~~~~~~~~~~~ - error: using `clone` on type `E` which implements the `Copy` trait - --> $DIR/unnecessary_clone.rs:84:20 + --> $DIR/unnecessary_clone.rs:76:20 | LL | let _: E = a.clone(); | ^^^^^^^^^ help: try dereferencing it: `*****a` -error: using `clone` on a double-reference; this will copy the reference of type `&[u8]` instead of cloning the inner type - --> $DIR/unnecessary_clone.rs:89:22 - | -LL | let _ = &mut encoded.clone(); - | ^^^^^^^^^^^^^^^ - | -help: try dereferencing it - | -LL | let _ = &mut &(*encoded).clone(); - | ~~~~~~~~~~~~~~~~~~~ -help: or try being explicit if you are sure, that you want to clone a reference - | -LL | let _ = &mut <&[u8]>::clone(encoded); - | ~~~~~~~~~~~~~~~~~~~~~~~ - -error: using `clone` on a double-reference; this will copy the reference of type `&[u8]` instead of cloning the inner type - --> $DIR/unnecessary_clone.rs:90:18 - | -LL | let _ = &encoded.clone(); - | ^^^^^^^^^^^^^^^ - | -help: try dereferencing it - | -LL | let _ = &&(*encoded).clone(); - | ~~~~~~~~~~~~~~~~~~~ -help: or try being explicit if you are sure, that you want to clone a reference - | -LL | let _ = &<&[u8]>::clone(encoded); - | ~~~~~~~~~~~~~~~~~~~~~~~ - error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:108:14 + --> $DIR/unnecessary_clone.rs:95:14 | LL | Some(try_opt!(Some(rc)).clone()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `Rc::::clone(&try_opt!(Some(rc)))` -error: aborting due to 12 previous errors +error: aborting due to 9 previous errors From 74405b5361cac733a518b548353a46ff3a35ef3d Mon Sep 17 00:00:00 2001 From: yukang Date: Wed, 15 Mar 2023 00:23:34 +0800 Subject: [PATCH 0821/1222] clean up Colon from clippy --- clippy_utils/src/sugg.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index e81eadceec0a..03cd8e48b9a5 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -163,7 +163,8 @@ impl<'a> Sugg<'a> { get_snippet(rhs.span), ), hir::ExprKind::Cast(lhs, ty) => Sugg::BinOp(AssocOp::As, get_snippet(lhs.span), get_snippet(ty.span)), - hir::ExprKind::Type(lhs, ty) => Sugg::BinOp(AssocOp::Colon, get_snippet(lhs.span), get_snippet(ty.span)), + //FIXME(chenyukang), remove this after type ascription is removed from AST + hir::ExprKind::Type(lhs, ty) => Sugg::BinOp(AssocOp::As, get_snippet(lhs.span), get_snippet(ty.span)), } } @@ -258,8 +259,9 @@ impl<'a> Sugg<'a> { snippet_with_context(cx, lhs.span, ctxt, default, app).0, snippet_with_context(cx, ty.span, ctxt, default, app).0, ), + //FIXME(chenyukang), remove this after type ascription is removed from AST ast::ExprKind::Type(ref lhs, ref ty) => Sugg::BinOp( - AssocOp::Colon, + AssocOp::As, snippet_with_context(cx, lhs.span, ctxt, default, app).0, snippet_with_context(cx, ty.span, ctxt, default, app).0, ), @@ -392,7 +394,6 @@ fn binop_to_string(op: AssocOp, lhs: &str, rhs: &str) -> String { AssocOp::As => format!("{lhs} as {rhs}"), AssocOp::DotDot => format!("{lhs}..{rhs}"), AssocOp::DotDotEq => format!("{lhs}..={rhs}"), - AssocOp::Colon => format!("{lhs}: {rhs}"), } } @@ -602,13 +603,13 @@ enum Associativity { #[must_use] fn associativity(op: AssocOp) -> Associativity { use rustc_ast::util::parser::AssocOp::{ - Add, As, Assign, AssignOp, BitAnd, BitOr, BitXor, Colon, Divide, DotDot, DotDotEq, Equal, Greater, + Add, As, Assign, AssignOp, BitAnd, BitOr, BitXor, Divide, DotDot, DotDotEq, Equal, Greater, GreaterEqual, LAnd, LOr, Less, LessEqual, Modulus, Multiply, NotEqual, ShiftLeft, ShiftRight, Subtract, }; match op { Assign | AssignOp(_) => Associativity::Right, - Add | BitAnd | BitOr | BitXor | LAnd | LOr | Multiply | As | Colon => Associativity::Both, + Add | BitAnd | BitOr | BitXor | LAnd | LOr | Multiply | As => Associativity::Both, Divide | Equal | Greater | GreaterEqual | Less | LessEqual | Modulus | NotEqual | ShiftLeft | ShiftRight | Subtract => Associativity::Left, DotDot | DotDotEq => Associativity::None, From d79cc3d9be3c680aaee65fbb73548c5a092c3314 Mon Sep 17 00:00:00 2001 From: jyn Date: Sat, 29 Apr 2023 06:29:07 -0500 Subject: [PATCH 0822/1222] Make the BUG_REPORT_URL configurable by tools This greatly simplifies how hard it is to set a custom bug report url; previously tools had to copy the entire hook implementation. - Switch clippy to the new hook This also adds a `extra_info` callback so clippy can include its own version number, which differs from rustc's. - Call `install_ice_hook` in rustfmt --- src/driver.rs | 70 +++++++-------------------------------------------- 1 file changed, 9 insertions(+), 61 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index 205905d50913..59bf447a7cd0 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -11,7 +11,6 @@ // FIXME: switch to something more ergonomic here, once available. // (Currently there is no way to opt into sysroot crates without `extern crate`.) extern crate rustc_driver; -extern crate rustc_errors; extern crate rustc_interface; extern crate rustc_session; extern crate rustc_span; @@ -20,13 +19,10 @@ use rustc_interface::interface; use rustc_session::parse::ParseSess; use rustc_span::symbol::Symbol; -use std::borrow::Cow; use std::env; use std::ops::Deref; -use std::panic; use std::path::Path; use std::process::exit; -use std::sync::LazyLock; /// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If /// true, then return it. The parameter is assumed to be either `--arg=value` or `--arg value`. @@ -198,66 +194,18 @@ You can use tool lints to allow or deny lints from your code, eg.: const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust-clippy/issues/new"; -type PanicCallback = dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static; -static ICE_HOOK: LazyLock> = LazyLock::new(|| { - let hook = panic::take_hook(); - panic::set_hook(Box::new(|info| report_clippy_ice(info, BUG_REPORT_URL))); - hook -}); - -fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { - // Invoke our ICE handler, which prints the actual panic message and optionally a backtrace - (*ICE_HOOK)(info); - - // Separate the output with an empty line - eprintln!(); - - let fallback_bundle = rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false); - let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr( - rustc_errors::ColorConfig::Auto, - None, - None, - fallback_bundle, - false, - false, - None, - false, - false, - rustc_errors::TerminalUrl::No, - )); - let handler = rustc_errors::Handler::with_emitter(true, None, emitter); - - // a .span_bug or .bug call has already printed what - // it wants to print. - if !info.payload().is::() { - let mut d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic"); - handler.emit_diagnostic(&mut d); - } - - let version_info = rustc_tools_util::get_version_info!(); - - let xs: Vec> = vec![ - "the compiler unexpectedly panicked. this is a bug.".into(), - format!("we would appreciate a bug report: {bug_report_url}").into(), - format!("Clippy version: {version_info}").into(), - ]; - - for note in &xs { - handler.note_without_error(note.as_ref()); - } - - // If backtraces are enabled, also print the query stack - let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0"); - - let num_frames = if backtrace { None } else { Some(2) }; - - interface::try_print_query_stack(&handler, num_frames); -} - #[allow(clippy::too_many_lines)] pub fn main() { rustc_driver::init_rustc_env_logger(); - LazyLock::force(&ICE_HOOK); + + rustc_driver::install_ice_hook(BUG_REPORT_URL, |handler| { + // FIXME: this macro calls unwrap internally but is called in a panicking context! It's not + // as simple as moving the call from the hook to main, because `install_ice_hook` doesn't + // accept a generic closure. + let version_info = rustc_tools_util::get_version_info!(); + handler.note_without_error(format!("Clippy version: {version_info}")); + }); + exit(rustc_driver::catch_with_exit_code(move || { let mut orig_args: Vec = env::args().collect(); let has_sysroot_arg = arg_value(&orig_args, "--sysroot", |_| true).is_some(); From 0b7b67bbab2e04b65988e0850b5cfe06be43d49f Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 5 Mar 2023 15:03:22 +0000 Subject: [PATCH 0823/1222] initial step towards implementing C string literals --- clippy_lints/src/matches/match_same_arms.rs | 1 + clippy_lints/src/utils/author.rs | 5 +++++ clippy_utils/src/consts.rs | 1 + 3 files changed, 7 insertions(+) diff --git a/clippy_lints/src/matches/match_same_arms.rs b/clippy_lints/src/matches/match_same_arms.rs index 158e6caa4de5..a48f4c77f857 100644 --- a/clippy_lints/src/matches/match_same_arms.rs +++ b/clippy_lints/src/matches/match_same_arms.rs @@ -284,6 +284,7 @@ impl<'a> NormalizedPat<'a> { LitKind::Str(sym, _) => Self::LitStr(sym), LitKind::ByteStr(ref bytes, _) => Self::LitBytes(bytes), LitKind::Byte(val) => Self::LitInt(val.into()), + LitKind::CStr(ref bytes, _) => Self::LitBytes(bytes), LitKind::Char(val) => Self::LitInt(val.into()), LitKind::Int(val, _) => Self::LitInt(val), LitKind::Bool(val) => Self::LitBool(val), diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 01927b6b5f10..f75dff46624e 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -304,6 +304,11 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { kind!("ByteStr(ref {vec})"); chain!(self, "let [{:?}] = **{vec}", vec.value); }, + LitKind::CStr(ref vec, _) => { + bind!(self, vec); + kind!("CStr(ref {vec})"); + chain!(self, "let [{:?}] = **{vec}", vec.value); + } LitKind::Str(s, _) => { bind!(self, s); kind!("Str({s}, _)"); diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 99bfc4b5717c..7c7ec6d334d9 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -211,6 +211,7 @@ pub fn lit_to_mir_constant(lit: &LitKind, ty: Option>) -> Constant { LitKind::Str(ref is, _) => Constant::Str(is.to_string()), LitKind::Byte(b) => Constant::Int(u128::from(b)), LitKind::ByteStr(ref s, _) => Constant::Binary(Lrc::clone(s)), + LitKind::CStr(ref s, _) => Constant::Binary(Lrc::clone(s)), LitKind::Char(c) => Constant::Char(c), LitKind::Int(n, _) => Constant::Int(n), LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty { From 8357cfc923ea8f1d101128c32a765badc0f62815 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Mon, 6 Mar 2023 14:09:28 +0000 Subject: [PATCH 0824/1222] rm diag item, use lang item --- clippy_lints/src/strlen_on_c_strings.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/strlen_on_c_strings.rs b/clippy_lints/src/strlen_on_c_strings.rs index 03324c66e8ef..2f2e84fa35a1 100644 --- a/clippy_lints/src/strlen_on_c_strings.rs +++ b/clippy_lints/src/strlen_on_c_strings.rs @@ -1,11 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_context; -use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item}; use clippy_utils::visitors::is_expr_unsafe; use clippy_utils::{get_parent_node, match_libc_symbol}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::{Block, BlockCheckMode, Expr, ExprKind, Node, UnsafeSource}; +use rustc_hir::{Block, BlockCheckMode, Expr, ExprKind, LangItem, Node, UnsafeSource}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; @@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for StrlenOnCStrings { let val_name = snippet_with_context(cx, self_arg.span, ctxt, "..", &mut app).0; let method_name = if is_type_diagnostic_item(cx, ty, sym::cstring_type) { "as_bytes" - } else if is_type_diagnostic_item(cx, ty, sym::CStr) { + } else if is_type_lang_item(cx, ty, LangItem::CStr) { "to_bytes" } else { return; From edb0639c84fe89112aa538f8c6af6f05f2a4e78f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 20 Apr 2023 13:26:58 +1000 Subject: [PATCH 0825/1222] Restrict `From` for `{D,Subd}iagnosticMessage`. Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile. --- clippy_lints/src/future_not_send.rs | 2 +- clippy_lints/src/lib.rs | 2 +- clippy_lints/src/methods/str_splitn.rs | 4 ++-- clippy_lints/src/non_send_fields_in_send_ty.rs | 6 +++--- clippy_utils/src/attrs.rs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index ff838c2d56e4..d1314795f580 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { if let PredicateKind::Clause(Clause::Trait(trait_pred)) = obligation.predicate.kind().skip_binder() { - db.note(&format!( + db.note(format!( "`{}` doesn't implement `{}`", trait_pred.self_ty(), trait_pred.trait_ref.print_only_trait_path(), diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 573ffe349ec2..9e65f9ecd166 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -353,7 +353,7 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, sess: &Se pub fn read_conf(sess: &Session, path: &io::Result<(Option, Vec)>) -> Conf { if let Ok((_, warnings)) = path { for warning in warnings { - sess.warn(warning); + sess.warn(warning.clone()); } } let file_name = match path { diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index d00708e828ea..91f7ce1dbe58 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -175,13 +175,13 @@ fn check_manual_split_once_indirect( let remove_msg = format!("remove the `{iter_ident}` usages"); diag.span_suggestion( first.span, - &remove_msg, + remove_msg.clone(), "", app, ); diag.span_suggestion( second.span, - &remove_msg, + remove_msg, "", app, ); diff --git a/clippy_lints/src/non_send_fields_in_send_ty.rs b/clippy_lints/src/non_send_fields_in_send_ty.rs index 839c3a3815c2..7eaa7db78a47 100644 --- a/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -131,13 +131,13 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy { for field in non_send_fields { diag.span_note( field.def.span, - &format!("it is not safe to send field `{}` to another thread", field.def.ident.name), + format!("it is not safe to send field `{}` to another thread", field.def.ident.name), ); match field.generic_params.len() { 0 => diag.help("use a thread-safe type that implements `Send`"), - 1 if is_ty_param(field.ty) => diag.help(&format!("add `{}: Send` bound in `Send` impl", field.ty)), - _ => diag.help(&format!( + 1 if is_ty_param(field.ty) => diag.help(format!("add `{}: Send` bound in `Send` impl", field.ty)), + _ => diag.help(format!( "add bounds on type parameter{} `{}` that satisfy `{}: Send`", if field.generic_params.len() > 1 { "s" } else { "" }, field.generic_params_string(), diff --git a/clippy_utils/src/attrs.rs b/clippy_utils/src/attrs.rs index b4ad42a50279..49cb9718ef66 100644 --- a/clippy_utils/src/attrs.rs +++ b/clippy_utils/src/attrs.rs @@ -133,7 +133,7 @@ pub fn get_unique_attr<'a>( let mut unique_attr: Option<&ast::Attribute> = None; for attr in get_attr(sess, attrs, name) { if let Some(duplicate) = unique_attr { - sess.struct_span_err(attr.span, &format!("`{name}` is defined multiple times")) + sess.struct_span_err(attr.span, format!("`{name}` is defined multiple times")) .span_note(duplicate.span, "first definition found here") .emit(); } else { From ef7e8502375d7e5165ff3a59628261c8f0c31867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Tue, 21 Mar 2023 01:46:52 +0100 Subject: [PATCH 0826/1222] IAT: Introduce AliasKind::Inherent --- clippy_lints/src/dereference.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 7f3f26bed7c7..b27ffe73ffda 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1424,6 +1424,7 @@ fn ty_auto_deref_stability<'tcx>( continue; }, ty::Param(_) => TyPosition::new_deref_stable_for_result(precedence, ty), + ty::Alias(ty::Inherent, _) => unreachable!("inherent projection should have been normalized away above"), ty::Alias(ty::Projection, _) if ty.has_non_region_param() => { TyPosition::new_deref_stable_for_result(precedence, ty) }, From 19a5fec068d7469f374d91179f3db069478181a2 Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Mon, 20 Feb 2023 12:46:39 -0700 Subject: [PATCH 0827/1222] make (try_)subst_and_normalize_erasing_regions take EarlyBinder --- clippy_lints/src/methods/unnecessary_to_owned.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 4c4c003ca469..87641c686dcf 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -435,7 +435,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< let output_ty = fn_sig.output(); if output_ty.contains(*param_ty) { if let Ok(new_ty) = cx.tcx.try_subst_and_normalize_erasing_regions( - new_subst, cx.param_env, output_ty) { + new_subst, cx.param_env, EarlyBinder(output_ty)) { expr = parent_expr; ty = new_ty; continue; From 776eef2663c3edbefe3eaa878f97ad8a836dea7b Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Sat, 6 May 2023 22:56:51 -0600 Subject: [PATCH 0828/1222] changes from review: add FIXME to clippy and change subst_identity to skip_binder in mir subst methods --- clippy_lints/src/methods/unnecessary_to_owned.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 87641c686dcf..67b7d3691dc0 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -385,6 +385,9 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< Node::Expr(parent_expr) => { if let Some((callee_def_id, call_substs, recv, call_args)) = get_callee_substs_and_args(cx, parent_expr) { + // FIXME: the `subst_identity()` below seems incorrect, since we eventually + // call `tcx.try_subst_and_normalize_erasing_regions` further down + // (i.e., we are explicitly not in the identity context). let fn_sig = cx.tcx.fn_sig(callee_def_id).subst_identity().skip_binder(); if let Some(arg_index) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == expr.hir_id) && let Some(param_ty) = fn_sig.inputs().get(arg_index) From d85768f8842efb6702799a6f7c01985416cec2c2 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sun, 26 Mar 2023 16:18:43 +0200 Subject: [PATCH 0829/1222] Drop uplifted clippy::drop_ref --- clippy_lints/src/declared_lints.rs | 1 - clippy_lints/src/drop_forget_ref.rs | 30 +----- clippy_lints/src/renamed_lints.rs | 1 + tests/ui/drop_forget_copy.rs | 2 +- tests/ui/drop_ref.rs | 97 ------------------ tests/ui/drop_ref.stderr | 147 ---------------------------- tests/ui/rename.fixed | 2 + tests/ui/rename.rs | 2 + tests/ui/rename.stderr | 94 +++++++++--------- 9 files changed, 58 insertions(+), 318 deletions(-) delete mode 100644 tests/ui/drop_ref.rs delete mode 100644 tests/ui/drop_ref.stderr diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 79d0f6f36079..07978d971db5 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -134,7 +134,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::double_parens::DOUBLE_PARENS_INFO, crate::drop_forget_ref::DROP_COPY_INFO, crate::drop_forget_ref::DROP_NON_DROP_INFO, - crate::drop_forget_ref::DROP_REF_INFO, crate::drop_forget_ref::FORGET_COPY_INFO, crate::drop_forget_ref::FORGET_NON_DROP_INFO, crate::drop_forget_ref::FORGET_REF_INFO, diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 11e1bcdf12d1..55d7c3247cdd 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -7,30 +7,6 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; -declare_clippy_lint! { - /// ### What it does - /// Checks for calls to `std::mem::drop` with a reference - /// instead of an owned value. - /// - /// ### Why is this bad? - /// Calling `drop` on a reference will only drop the - /// reference itself, which is a no-op. It will not call the `drop` method (from - /// the `Drop` trait implementation) on the underlying referenced value, which - /// is likely what was intended. - /// - /// ### Example - /// ```ignore - /// let mut lock_guard = mutex.lock(); - /// std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex - /// // still locked - /// operation_that_requires_mutex_to_be_unlocked(); - /// ``` - #[clippy::version = "pre 1.29.0"] - pub DROP_REF, - correctness, - "calls to `std::mem::drop` with a reference instead of an owned value" -} - declare_clippy_lint! { /// ### What it does /// Checks for calls to `std::mem::forget` with a reference @@ -172,8 +148,6 @@ declare_clippy_lint! { "use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value" } -const DROP_REF_SUMMARY: &str = "calls to `std::mem::drop` with a reference instead of an owned value. \ - Dropping a reference does nothing"; const FORGET_REF_SUMMARY: &str = "calls to `std::mem::forget` with a reference instead of an owned value. \ Forgetting a reference does nothing"; const DROP_COPY_SUMMARY: &str = "calls to `std::mem::drop` with a value that implements `Copy`. \ @@ -186,7 +160,6 @@ const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value t Forgetting such a type is the same as dropping it"; declare_lint_pass!(DropForgetRef => [ - DROP_REF, FORGET_REF, DROP_COPY, FORGET_COPY, @@ -206,7 +179,8 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { let is_copy = is_copy(cx, arg_ty); let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); let (lint, msg) = match fn_name { - sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => (DROP_REF, DROP_REF_SUMMARY), + // early return for uplifted lints: drop_ref + sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return, sym::mem_forget if arg_ty.is_ref() => (FORGET_REF, FORGET_REF_SUMMARY), sym::mem_drop if is_copy && !drop_is_single_call_in_arm => (DROP_COPY, DROP_COPY_SUMMARY), sym::mem_forget if is_copy => (FORGET_COPY, FORGET_COPY_SUMMARY), diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index 5e81a01a461a..c55eaa809cf0 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -32,6 +32,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::zero_width_space", "clippy::invisible_characters"), ("clippy::clone_double_ref", "suspicious_double_ref_op"), ("clippy::drop_bounds", "drop_bounds"), + ("clippy::drop_ref", "drop_ref"), ("clippy::for_loop_over_option", "for_loops_over_fallibles"), ("clippy::for_loop_over_result", "for_loops_over_fallibles"), ("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"), diff --git a/tests/ui/drop_forget_copy.rs b/tests/ui/drop_forget_copy.rs index a7276dd59f43..04293eb16bb7 100644 --- a/tests/ui/drop_forget_copy.rs +++ b/tests/ui/drop_forget_copy.rs @@ -1,5 +1,5 @@ #![warn(clippy::drop_copy, clippy::forget_copy)] -#![allow(clippy::toplevel_ref_arg, clippy::drop_ref, clippy::forget_ref, unused_mut)] +#![allow(clippy::toplevel_ref_arg, drop_ref, clippy::forget_ref, unused_mut)] use std::mem::{drop, forget}; use std::vec::Vec; diff --git a/tests/ui/drop_ref.rs b/tests/ui/drop_ref.rs deleted file mode 100644 index 10044e65f115..000000000000 --- a/tests/ui/drop_ref.rs +++ /dev/null @@ -1,97 +0,0 @@ -#![warn(clippy::drop_ref)] -#![allow(clippy::toplevel_ref_arg)] -#![allow(clippy::map_err_ignore)] -#![allow(clippy::unnecessary_wraps, clippy::drop_non_drop)] - -use std::mem::drop; - -struct SomeStruct; - -fn main() { - drop(&SomeStruct); - - let mut owned1 = SomeStruct; - drop(&owned1); - drop(&&owned1); - drop(&mut owned1); - drop(owned1); //OK - - let reference1 = &SomeStruct; - drop(reference1); - - let reference2 = &mut SomeStruct; - drop(reference2); - - let ref reference3 = SomeStruct; - drop(reference3); -} - -#[allow(dead_code)] -fn test_generic_fn_drop(val: T) { - drop(&val); - drop(val); //OK -} - -#[allow(dead_code)] -fn test_similarly_named_function() { - fn drop(_val: T) {} - drop(&SomeStruct); //OK; call to unrelated function which happens to have the same name - std::mem::drop(&SomeStruct); -} - -#[derive(Copy, Clone)] -pub struct Error; -fn produce_half_owl_error() -> Result<(), Error> { - Ok(()) -} - -fn produce_half_owl_ok() -> Result { - Ok(true) -} - -#[allow(dead_code)] -fn test_owl_result() -> Result<(), ()> { - produce_half_owl_error().map_err(|_| ())?; - produce_half_owl_ok().map(|_| ())?; - // the following should not be linted, - // we should not force users to use toilet closures - // to produce owl results when drop is more convenient - produce_half_owl_error().map_err(drop)?; - produce_half_owl_ok().map_err(drop)?; - Ok(()) -} - -#[allow(dead_code)] -fn test_owl_result_2() -> Result { - produce_half_owl_error().map_err(|_| ())?; - produce_half_owl_ok().map(|_| ())?; - // the following should not be linted, - // we should not force users to use toilet closures - // to produce owl results when drop is more convenient - produce_half_owl_error().map_err(drop)?; - produce_half_owl_ok().map(drop)?; - Ok(1) -} - -#[allow(unused)] -#[allow(clippy::unit_cmp)] -fn issue10122(x: u8) { - // This is a function which returns a reference and has a side-effect, which means - // that calling drop() on the function is considered an idiomatic way of achieving the side-effect - // in a match arm. - fn println_and(t: &T) -> &T { - println!("foo"); - t - } - - match x { - 0 => drop(println_and(&12)), // Don't lint (copy type), we only care about side-effects - 1 => drop(println_and(&String::new())), // Don't lint (no copy type), we only care about side-effects - 2 => { - drop(println_and(&13)); // Lint, even if we only care about the side-effect, it's already in a block - }, - 3 if drop(println_and(&14)) == () => (), // Lint, idiomatic use is only in body of `Arm` - 4 => drop(&2), // Lint, not a fn/method call - _ => (), - } -} diff --git a/tests/ui/drop_ref.stderr b/tests/ui/drop_ref.stderr deleted file mode 100644 index 293b9f6de832..000000000000 --- a/tests/ui/drop_ref.stderr +++ /dev/null @@ -1,147 +0,0 @@ -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:11:5 - | -LL | drop(&SomeStruct); - | ^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:11:10 - | -LL | drop(&SomeStruct); - | ^^^^^^^^^^^ - = note: `-D clippy::drop-ref` implied by `-D warnings` - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:14:5 - | -LL | drop(&owned1); - | ^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:14:10 - | -LL | drop(&owned1); - | ^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:15:5 - | -LL | drop(&&owned1); - | ^^^^^^^^^^^^^^ - | -note: argument has type `&&SomeStruct` - --> $DIR/drop_ref.rs:15:10 - | -LL | drop(&&owned1); - | ^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:16:5 - | -LL | drop(&mut owned1); - | ^^^^^^^^^^^^^^^^^ - | -note: argument has type `&mut SomeStruct` - --> $DIR/drop_ref.rs:16:10 - | -LL | drop(&mut owned1); - | ^^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:20:5 - | -LL | drop(reference1); - | ^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:20:10 - | -LL | drop(reference1); - | ^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:23:5 - | -LL | drop(reference2); - | ^^^^^^^^^^^^^^^^ - | -note: argument has type `&mut SomeStruct` - --> $DIR/drop_ref.rs:23:10 - | -LL | drop(reference2); - | ^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:26:5 - | -LL | drop(reference3); - | ^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:26:10 - | -LL | drop(reference3); - | ^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:31:5 - | -LL | drop(&val); - | ^^^^^^^^^^ - | -note: argument has type `&T` - --> $DIR/drop_ref.rs:31:10 - | -LL | drop(&val); - | ^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:39:5 - | -LL | std::mem::drop(&SomeStruct); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:39:20 - | -LL | std::mem::drop(&SomeStruct); - | ^^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:91:13 - | -LL | drop(println_and(&13)); // Lint, even if we only care about the side-effect, it's already in a block - | ^^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&i32` - --> $DIR/drop_ref.rs:91:18 - | -LL | drop(println_and(&13)); // Lint, even if we only care about the side-effect, it's already in a block - | ^^^^^^^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:93:14 - | -LL | 3 if drop(println_and(&14)) == () => (), // Lint, idiomatic use is only in body of `Arm` - | ^^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&i32` - --> $DIR/drop_ref.rs:93:19 - | -LL | 3 if drop(println_and(&14)) == () => (), // Lint, idiomatic use is only in body of `Arm` - | ^^^^^^^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:94:14 - | -LL | 4 => drop(&2), // Lint, not a fn/method call - | ^^^^^^^^ - | -note: argument has type `&i32` - --> $DIR/drop_ref.rs:94:19 - | -LL | 4 => drop(&2), // Lint, not a fn/method call - | ^^ - -error: aborting due to 12 previous errors - diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index 42a59f6d43df..1beb878fc75a 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -29,6 +29,7 @@ #![allow(clippy::invisible_characters)] #![allow(suspicious_double_ref_op)] #![allow(drop_bounds)] +#![allow(drop_ref)] #![allow(for_loops_over_fallibles)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] @@ -71,6 +72,7 @@ #![warn(clippy::invisible_characters)] #![warn(suspicious_double_ref_op)] #![warn(drop_bounds)] +#![warn(drop_ref)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index 4d173e8cbbfa..7034daffdd6b 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -29,6 +29,7 @@ #![allow(clippy::invisible_characters)] #![allow(suspicious_double_ref_op)] #![allow(drop_bounds)] +#![allow(drop_ref)] #![allow(for_loops_over_fallibles)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] @@ -71,6 +72,7 @@ #![warn(clippy::zero_width_space)] #![warn(clippy::clone_double_ref)] #![warn(clippy::drop_bounds)] +#![warn(clippy::drop_ref)] #![warn(clippy::for_loop_over_option)] #![warn(clippy::for_loop_over_result)] #![warn(clippy::for_loops_over_fallibles)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 0da4ed7520c8..7cf5562a7e3b 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> $DIR/rename.rs:44:9 + --> $DIR/rename.rs:45:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -7,256 +7,262 @@ LL | #![warn(clippy::almost_complete_letter_range)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> $DIR/rename.rs:45:9 + --> $DIR/rename.rs:46:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:46:9 + --> $DIR/rename.rs:47:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:47:9 + --> $DIR/rename.rs:48:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> $DIR/rename.rs:48:9 + --> $DIR/rename.rs:49:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:49:9 + --> $DIR/rename.rs:50:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:50:9 + --> $DIR/rename.rs:51:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> $DIR/rename.rs:51:9 + --> $DIR/rename.rs:52:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> $DIR/rename.rs:52:9 + --> $DIR/rename.rs:53:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> $DIR/rename.rs:53:9 + --> $DIR/rename.rs:54:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> $DIR/rename.rs:54:9 + --> $DIR/rename.rs:55:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> $DIR/rename.rs:55:9 + --> $DIR/rename.rs:56:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> $DIR/rename.rs:56:9 + --> $DIR/rename.rs:57:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:57:9 + --> $DIR/rename.rs:58:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:58:9 + --> $DIR/rename.rs:59:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:59:9 + --> $DIR/rename.rs:60:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:60:9 + --> $DIR/rename.rs:61:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:61:9 + --> $DIR/rename.rs:62:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:62:9 + --> $DIR/rename.rs:63:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:63:9 + --> $DIR/rename.rs:64:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:64:9 + --> $DIR/rename.rs:65:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:65:9 + --> $DIR/rename.rs:66:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:66:9 + --> $DIR/rename.rs:67:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:67:9 + --> $DIR/rename.rs:68:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:69:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::clone_double_ref)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` +error: lint `clippy::drop_ref` has been renamed to `drop_ref` + --> $DIR/rename.rs:75:9 + | +LL | #![warn(clippy::drop_ref)] + | ^^^^^^^^^^^^^^^^ help: use the new name: `drop_ref` + error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:79:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:80:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:83:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:84:9 + --> $DIR/rename.rs:86:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:85:9 + --> $DIR/rename.rs:87:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:86:9 + --> $DIR/rename.rs:88:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 43 previous errors +error: aborting due to 44 previous errors From 578b91bd4c889dc3b42d383454f6934ed1e5e7c9 Mon Sep 17 00:00:00 2001 From: Urgau Date: Mon, 27 Mar 2023 21:05:43 +0200 Subject: [PATCH 0830/1222] Drop uplifted clippy::drop_copy --- clippy_lints/src/declared_lints.rs | 1 - clippy_lints/src/drop_forget_ref.rs | 29 +------ clippy_lints/src/renamed_lints.rs | 1 + tests/ui/drop_forget_copy.rs | 2 +- tests/ui/drop_forget_copy.stderr | 80 +++++++++---------- tests/ui/multiple_unsafe_ops_per_block.rs | 2 +- tests/ui/rename.fixed | 2 + tests/ui/rename.rs | 2 + tests/ui/rename.stderr | 96 ++++++++++++----------- tests/ui/unknown_clippy_lints.fixed | 2 +- tests/ui/unknown_clippy_lints.stderr | 2 +- 11 files changed, 102 insertions(+), 117 deletions(-) diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 07978d971db5..81288ca91015 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -132,7 +132,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::doc::NEEDLESS_DOCTEST_MAIN_INFO, crate::doc::UNNECESSARY_SAFETY_DOC_INFO, crate::double_parens::DOUBLE_PARENS_INFO, - crate::drop_forget_ref::DROP_COPY_INFO, crate::drop_forget_ref::DROP_NON_DROP_INFO, crate::drop_forget_ref::FORGET_COPY_INFO, crate::drop_forget_ref::FORGET_NON_DROP_INFO, diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 55d7c3247cdd..9858243f3397 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -29,28 +29,6 @@ declare_clippy_lint! { "calls to `std::mem::forget` with a reference instead of an owned value" } -declare_clippy_lint! { - /// ### What it does - /// Checks for calls to `std::mem::drop` with a value - /// that derives the Copy trait - /// - /// ### Why is this bad? - /// Calling `std::mem::drop` [does nothing for types that - /// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html), since the - /// value will be copied and moved into the function on invocation. - /// - /// ### Example - /// ```rust - /// let x: i32 = 42; // i32 implements Copy - /// std::mem::drop(x) // A copy of x is passed to the function, leaving the - /// // original unaffected - /// ``` - #[clippy::version = "pre 1.29.0"] - pub DROP_COPY, - correctness, - "calls to `std::mem::drop` with a value that implements Copy" -} - declare_clippy_lint! { /// ### What it does /// Checks for calls to `std::mem::forget` with a value that @@ -150,8 +128,6 @@ declare_clippy_lint! { const FORGET_REF_SUMMARY: &str = "calls to `std::mem::forget` with a reference instead of an owned value. \ Forgetting a reference does nothing"; -const DROP_COPY_SUMMARY: &str = "calls to `std::mem::drop` with a value that implements `Copy`. \ - Dropping a copy leaves the original intact"; const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements `Copy`. \ Forgetting a copy leaves the original intact"; const DROP_NON_DROP_SUMMARY: &str = "call to `std::mem::drop` with a value that does not implement `Drop`. \ @@ -161,7 +137,6 @@ const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value t declare_lint_pass!(DropForgetRef => [ FORGET_REF, - DROP_COPY, FORGET_COPY, DROP_NON_DROP, FORGET_NON_DROP, @@ -179,10 +154,10 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { let is_copy = is_copy(cx, arg_ty); let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); let (lint, msg) = match fn_name { - // early return for uplifted lints: drop_ref + // early return for uplifted lints: drop_ref, drop_copy sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return, sym::mem_forget if arg_ty.is_ref() => (FORGET_REF, FORGET_REF_SUMMARY), - sym::mem_drop if is_copy && !drop_is_single_call_in_arm => (DROP_COPY, DROP_COPY_SUMMARY), + sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return, sym::mem_forget if is_copy => (FORGET_COPY, FORGET_COPY_SUMMARY), sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => { span_lint_and_help( diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index c55eaa809cf0..31c9f39c9bf0 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -32,6 +32,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::zero_width_space", "clippy::invisible_characters"), ("clippy::clone_double_ref", "suspicious_double_ref_op"), ("clippy::drop_bounds", "drop_bounds"), + ("clippy::drop_copy", "drop_copy"), ("clippy::drop_ref", "drop_ref"), ("clippy::for_loop_over_option", "for_loops_over_fallibles"), ("clippy::for_loop_over_result", "for_loops_over_fallibles"), diff --git a/tests/ui/drop_forget_copy.rs b/tests/ui/drop_forget_copy.rs index 04293eb16bb7..f723b03a979c 100644 --- a/tests/ui/drop_forget_copy.rs +++ b/tests/ui/drop_forget_copy.rs @@ -1,4 +1,4 @@ -#![warn(clippy::drop_copy, clippy::forget_copy)] +#![warn(drop_copy, clippy::forget_copy)] #![allow(clippy::toplevel_ref_arg, drop_ref, clippy::forget_ref, unused_mut)] use std::mem::{drop, forget}; diff --git a/tests/ui/drop_forget_copy.stderr b/tests/ui/drop_forget_copy.stderr index 90bef1c3c439..3b19cf3968f6 100644 --- a/tests/ui/drop_forget_copy.stderr +++ b/tests/ui/drop_forget_copy.stderr @@ -1,40 +1,3 @@ -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact - --> $DIR/drop_forget_copy.rs:33:5 - | -LL | drop(s1); - | ^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:33:10 - | -LL | drop(s1); - | ^^ - = note: `-D clippy::drop-copy` implied by `-D warnings` - -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact - --> $DIR/drop_forget_copy.rs:34:5 - | -LL | drop(s2); - | ^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:34:10 - | -LL | drop(s2); - | ^^ - -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact - --> $DIR/drop_forget_copy.rs:36:5 - | -LL | drop(s4); - | ^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:36:10 - | -LL | drop(s4); - | ^^ - error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact --> $DIR/drop_forget_copy.rs:39:5 | @@ -72,7 +35,44 @@ note: argument has type `SomeStruct` LL | forget(s4); | ^^ -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact +error: calls to `std::mem::drop` with a value that implements `Copy`. + --> $DIR/drop_forget_copy.rs:33:5 + | +LL | drop(s1); + | ^^^^^^^^ + | +note: argument has type `SomeStruct` + --> $DIR/drop_forget_copy.rs:33:10 + | +LL | drop(s1); + | ^^ + = note: `-D drop-copy` implied by `-D warnings` + +error: calls to `std::mem::drop` with a value that implements `Copy`. + --> $DIR/drop_forget_copy.rs:34:5 + | +LL | drop(s2); + | ^^^^^^^^ + | +note: argument has type `SomeStruct` + --> $DIR/drop_forget_copy.rs:34:10 + | +LL | drop(s2); + | ^^ + +error: calls to `std::mem::drop` with a value that implements `Copy`. + --> $DIR/drop_forget_copy.rs:36:5 + | +LL | drop(s4); + | ^^^^^^^^ + | +note: argument has type `SomeStruct` + --> $DIR/drop_forget_copy.rs:36:10 + | +LL | drop(s4); + | ^^ + +error: calls to `std::mem::drop` with a value that implements `Copy`. --> $DIR/drop_forget_copy.rs:80:13 | LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block @@ -84,7 +84,7 @@ note: argument has type `i32` LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block | ^^^^^^^^^^^^^^^ -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact +error: calls to `std::mem::drop` with a value that implements `Copy`. --> $DIR/drop_forget_copy.rs:82:14 | LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm` @@ -96,7 +96,7 @@ note: argument has type `i32` LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm` | ^^^^^^^^^^^^^^^ -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact +error: calls to `std::mem::drop` with a value that implements `Copy`. --> $DIR/drop_forget_copy.rs:83:14 | LL | 4 => drop(2), // Lint, not a fn/method call diff --git a/tests/ui/multiple_unsafe_ops_per_block.rs b/tests/ui/multiple_unsafe_ops_per_block.rs index 73ef35c8c366..f28153e56b0f 100644 --- a/tests/ui/multiple_unsafe_ops_per_block.rs +++ b/tests/ui/multiple_unsafe_ops_per_block.rs @@ -2,7 +2,7 @@ #![allow(unused)] #![allow(deref_nullptr)] #![allow(clippy::unnecessary_operation)] -#![allow(clippy::drop_copy)] +#![allow(drop_copy)] #![warn(clippy::multiple_unsafe_ops_per_block)] extern crate proc_macros; diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index 1beb878fc75a..a618dcd806fb 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -29,6 +29,7 @@ #![allow(clippy::invisible_characters)] #![allow(suspicious_double_ref_op)] #![allow(drop_bounds)] +#![allow(drop_copy)] #![allow(drop_ref)] #![allow(for_loops_over_fallibles)] #![allow(array_into_iter)] @@ -72,6 +73,7 @@ #![warn(clippy::invisible_characters)] #![warn(suspicious_double_ref_op)] #![warn(drop_bounds)] +#![warn(drop_copy)] #![warn(drop_ref)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index 7034daffdd6b..bca0cba7ee80 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -29,6 +29,7 @@ #![allow(clippy::invisible_characters)] #![allow(suspicious_double_ref_op)] #![allow(drop_bounds)] +#![allow(drop_copy)] #![allow(drop_ref)] #![allow(for_loops_over_fallibles)] #![allow(array_into_iter)] @@ -72,6 +73,7 @@ #![warn(clippy::zero_width_space)] #![warn(clippy::clone_double_ref)] #![warn(clippy::drop_bounds)] +#![warn(clippy::drop_copy)] #![warn(clippy::drop_ref)] #![warn(clippy::for_loop_over_option)] #![warn(clippy::for_loop_over_result)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 7cf5562a7e3b..1f1cc932b38f 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> $DIR/rename.rs:45:9 + --> $DIR/rename.rs:46:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -7,262 +7,268 @@ LL | #![warn(clippy::almost_complete_letter_range)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> $DIR/rename.rs:46:9 + --> $DIR/rename.rs:47:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:47:9 + --> $DIR/rename.rs:48:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:48:9 + --> $DIR/rename.rs:49:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> $DIR/rename.rs:49:9 + --> $DIR/rename.rs:50:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:50:9 + --> $DIR/rename.rs:51:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:51:9 + --> $DIR/rename.rs:52:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> $DIR/rename.rs:52:9 + --> $DIR/rename.rs:53:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> $DIR/rename.rs:53:9 + --> $DIR/rename.rs:54:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> $DIR/rename.rs:54:9 + --> $DIR/rename.rs:55:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> $DIR/rename.rs:55:9 + --> $DIR/rename.rs:56:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> $DIR/rename.rs:56:9 + --> $DIR/rename.rs:57:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> $DIR/rename.rs:57:9 + --> $DIR/rename.rs:58:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:58:9 + --> $DIR/rename.rs:59:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:59:9 + --> $DIR/rename.rs:60:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:60:9 + --> $DIR/rename.rs:61:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:61:9 + --> $DIR/rename.rs:62:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:62:9 + --> $DIR/rename.rs:63:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:63:9 + --> $DIR/rename.rs:64:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:64:9 + --> $DIR/rename.rs:65:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:65:9 + --> $DIR/rename.rs:66:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:66:9 + --> $DIR/rename.rs:67:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:67:9 + --> $DIR/rename.rs:68:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:69:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::clone_double_ref)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` +error: lint `clippy::drop_copy` has been renamed to `drop_copy` + --> $DIR/rename.rs:76:9 + | +LL | #![warn(clippy::drop_copy)] + | ^^^^^^^^^^^^^^^^^ help: use the new name: `drop_copy` + error: lint `clippy::drop_ref` has been renamed to `drop_ref` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::drop_ref)] | ^^^^^^^^^^^^^^^^ help: use the new name: `drop_ref` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:79:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:80:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:83:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:84:9 + --> $DIR/rename.rs:86:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:85:9 + --> $DIR/rename.rs:87:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:86:9 + --> $DIR/rename.rs:88:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:87:9 + --> $DIR/rename.rs:89:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:88:9 + --> $DIR/rename.rs:90:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 44 previous errors +error: aborting due to 45 previous errors diff --git a/tests/ui/unknown_clippy_lints.fixed b/tests/ui/unknown_clippy_lints.fixed index 0c269d650c8c..49c0e4dc7eb1 100644 --- a/tests/ui/unknown_clippy_lints.fixed +++ b/tests/ui/unknown_clippy_lints.fixed @@ -10,7 +10,7 @@ #[warn(clippy::unnecessary_cast)] #[warn(clippy::useless_transmute)] // Shouldn't suggest rustc lint name(`dead_code`) -#[warn(clippy::drop_copy)] +#[warn(clippy::eq_op)] // Shouldn't suggest removed/deprecated clippy lint name(`unused_collect`) #[warn(clippy::unused_self)] // Shouldn't suggest renamed clippy lint name(`const_static_lifetime`) diff --git a/tests/ui/unknown_clippy_lints.stderr b/tests/ui/unknown_clippy_lints.stderr index 421bf5ffa9a7..584c428932fe 100644 --- a/tests/ui/unknown_clippy_lints.stderr +++ b/tests/ui/unknown_clippy_lints.stderr @@ -34,7 +34,7 @@ error: unknown lint: `clippy::dead_cod` --> $DIR/unknown_clippy_lints.rs:13:8 | LL | #[warn(clippy::dead_cod)] - | ^^^^^^^^^^^^^^^^ help: did you mean: `clippy::drop_copy` + | ^^^^^^^^^^^^^^^^ help: did you mean: `clippy::eq_op` error: unknown lint: `clippy::unused_colle` --> $DIR/unknown_clippy_lints.rs:15:8 From e0c5c3c46c3e59d770323550672b8da1e4e4918a Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 28 Mar 2023 18:40:54 +0200 Subject: [PATCH 0831/1222] Drop uplifted clippy::forget_ref --- clippy_lints/src/declared_lints.rs | 1 - clippy_lints/src/drop_forget_ref.rs | 29 +------- clippy_lints/src/renamed_lints.rs | 1 + tests/ui/drop_forget_copy.rs | 2 +- tests/ui/forget_ref.rs | 50 ------------- tests/ui/forget_ref.stderr | 111 ---------------------------- tests/ui/rename.fixed | 2 + tests/ui/rename.rs | 2 + tests/ui/rename.stderr | 98 ++++++++++++------------ 9 files changed, 60 insertions(+), 236 deletions(-) delete mode 100644 tests/ui/forget_ref.rs delete mode 100644 tests/ui/forget_ref.stderr diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 81288ca91015..255df2b7e466 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -135,7 +135,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::drop_forget_ref::DROP_NON_DROP_INFO, crate::drop_forget_ref::FORGET_COPY_INFO, crate::drop_forget_ref::FORGET_NON_DROP_INFO, - crate::drop_forget_ref::FORGET_REF_INFO, crate::drop_forget_ref::UNDROPPED_MANUALLY_DROPS_INFO, crate::duplicate_mod::DUPLICATE_MOD_INFO, crate::else_if_without_else::ELSE_IF_WITHOUT_ELSE_INFO, diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 9858243f3397..23ec7f15aaa7 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -7,28 +7,6 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; -declare_clippy_lint! { - /// ### What it does - /// Checks for calls to `std::mem::forget` with a reference - /// instead of an owned value. - /// - /// ### Why is this bad? - /// Calling `forget` on a reference will only forget the - /// reference itself, which is a no-op. It will not forget the underlying - /// referenced - /// value, which is likely what was intended. - /// - /// ### Example - /// ```rust - /// let x = Box::new(1); - /// std::mem::forget(&x) // Should have been forget(x), x will still be dropped - /// ``` - #[clippy::version = "pre 1.29.0"] - pub FORGET_REF, - correctness, - "calls to `std::mem::forget` with a reference instead of an owned value" -} - declare_clippy_lint! { /// ### What it does /// Checks for calls to `std::mem::forget` with a value that @@ -126,8 +104,6 @@ declare_clippy_lint! { "use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value" } -const FORGET_REF_SUMMARY: &str = "calls to `std::mem::forget` with a reference instead of an owned value. \ - Forgetting a reference does nothing"; const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements `Copy`. \ Forgetting a copy leaves the original intact"; const DROP_NON_DROP_SUMMARY: &str = "call to `std::mem::drop` with a value that does not implement `Drop`. \ @@ -136,7 +112,6 @@ const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value t Forgetting such a type is the same as dropping it"; declare_lint_pass!(DropForgetRef => [ - FORGET_REF, FORGET_COPY, DROP_NON_DROP, FORGET_NON_DROP, @@ -154,9 +129,9 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { let is_copy = is_copy(cx, arg_ty); let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); let (lint, msg) = match fn_name { - // early return for uplifted lints: drop_ref, drop_copy + // early return for uplifted lints: drop_ref, drop_copy, forget_ref sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return, - sym::mem_forget if arg_ty.is_ref() => (FORGET_REF, FORGET_REF_SUMMARY), + sym::mem_forget if arg_ty.is_ref() => return, sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return, sym::mem_forget if is_copy => (FORGET_COPY, FORGET_COPY_SUMMARY), sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => { diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index 31c9f39c9bf0..d5b1883e0b27 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -37,6 +37,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::for_loop_over_option", "for_loops_over_fallibles"), ("clippy::for_loop_over_result", "for_loops_over_fallibles"), ("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"), + ("clippy::forget_ref", "forget_ref"), ("clippy::into_iter_on_array", "array_into_iter"), ("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"), ("clippy::invalid_ref", "invalid_value"), diff --git a/tests/ui/drop_forget_copy.rs b/tests/ui/drop_forget_copy.rs index f723b03a979c..ebe60ebbd304 100644 --- a/tests/ui/drop_forget_copy.rs +++ b/tests/ui/drop_forget_copy.rs @@ -1,5 +1,5 @@ #![warn(drop_copy, clippy::forget_copy)] -#![allow(clippy::toplevel_ref_arg, drop_ref, clippy::forget_ref, unused_mut)] +#![allow(clippy::toplevel_ref_arg, drop_ref, forget_ref, unused_mut)] use std::mem::{drop, forget}; use std::vec::Vec; diff --git a/tests/ui/forget_ref.rs b/tests/ui/forget_ref.rs deleted file mode 100644 index 031b415f56ff..000000000000 --- a/tests/ui/forget_ref.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![warn(clippy::forget_ref)] -#![allow(clippy::toplevel_ref_arg)] -#![allow(clippy::unnecessary_wraps, clippy::forget_non_drop)] -#![allow(clippy::borrow_deref_ref)] - -use std::mem::forget; - -struct SomeStruct; - -fn main() { - forget(&SomeStruct); - - let mut owned = SomeStruct; - forget(&owned); - forget(&&owned); - forget(&mut owned); - forget(owned); //OK - - let reference1 = &SomeStruct; - forget(&*reference1); - - let reference2 = &mut SomeStruct; - forget(reference2); - - let ref reference3 = SomeStruct; - forget(reference3); -} - -#[allow(dead_code)] -fn test_generic_fn_forget(val: T) { - forget(&val); - forget(val); //OK -} - -#[allow(dead_code)] -fn test_similarly_named_function() { - fn forget(_val: T) {} - forget(&SomeStruct); //OK; call to unrelated function which happens to have the same name - std::mem::forget(&SomeStruct); -} - -#[derive(Copy, Clone)] -pub struct Error; -fn produce_half_owl_error() -> Result<(), Error> { - Ok(()) -} - -fn produce_half_owl_ok() -> Result { - Ok(true) -} diff --git a/tests/ui/forget_ref.stderr b/tests/ui/forget_ref.stderr deleted file mode 100644 index 011cdefc665f..000000000000 --- a/tests/ui/forget_ref.stderr +++ /dev/null @@ -1,111 +0,0 @@ -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:11:5 - | -LL | forget(&SomeStruct); - | ^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:11:12 - | -LL | forget(&SomeStruct); - | ^^^^^^^^^^^ - = note: `-D clippy::forget-ref` implied by `-D warnings` - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:14:5 - | -LL | forget(&owned); - | ^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:14:12 - | -LL | forget(&owned); - | ^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:15:5 - | -LL | forget(&&owned); - | ^^^^^^^^^^^^^^^ - | -note: argument has type `&&SomeStruct` - --> $DIR/forget_ref.rs:15:12 - | -LL | forget(&&owned); - | ^^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:16:5 - | -LL | forget(&mut owned); - | ^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&mut SomeStruct` - --> $DIR/forget_ref.rs:16:12 - | -LL | forget(&mut owned); - | ^^^^^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:20:5 - | -LL | forget(&*reference1); - | ^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:20:12 - | -LL | forget(&*reference1); - | ^^^^^^^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:23:5 - | -LL | forget(reference2); - | ^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&mut SomeStruct` - --> $DIR/forget_ref.rs:23:12 - | -LL | forget(reference2); - | ^^^^^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:26:5 - | -LL | forget(reference3); - | ^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:26:12 - | -LL | forget(reference3); - | ^^^^^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:31:5 - | -LL | forget(&val); - | ^^^^^^^^^^^^ - | -note: argument has type `&T` - --> $DIR/forget_ref.rs:31:12 - | -LL | forget(&val); - | ^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:39:5 - | -LL | std::mem::forget(&SomeStruct); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:39:22 - | -LL | std::mem::forget(&SomeStruct); - | ^^^^^^^^^^^ - -error: aborting due to 9 previous errors - diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index a618dcd806fb..6cb2f82c117a 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -32,6 +32,7 @@ #![allow(drop_copy)] #![allow(drop_ref)] #![allow(for_loops_over_fallibles)] +#![allow(forget_ref)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] @@ -78,6 +79,7 @@ #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] +#![warn(forget_ref)] #![warn(array_into_iter)] #![warn(invalid_atomic_ordering)] #![warn(invalid_value)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index bca0cba7ee80..72acc312d548 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -32,6 +32,7 @@ #![allow(drop_copy)] #![allow(drop_ref)] #![allow(for_loops_over_fallibles)] +#![allow(forget_ref)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] @@ -78,6 +79,7 @@ #![warn(clippy::for_loop_over_option)] #![warn(clippy::for_loop_over_result)] #![warn(clippy::for_loops_over_fallibles)] +#![warn(clippy::forget_ref)] #![warn(clippy::into_iter_on_array)] #![warn(clippy::invalid_atomic_ordering)] #![warn(clippy::invalid_ref)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 1f1cc932b38f..2847cdbba5df 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> $DIR/rename.rs:46:9 + --> $DIR/rename.rs:47:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -7,268 +7,274 @@ LL | #![warn(clippy::almost_complete_letter_range)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> $DIR/rename.rs:47:9 + --> $DIR/rename.rs:48:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:48:9 + --> $DIR/rename.rs:49:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:49:9 + --> $DIR/rename.rs:50:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> $DIR/rename.rs:50:9 + --> $DIR/rename.rs:51:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:51:9 + --> $DIR/rename.rs:52:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:52:9 + --> $DIR/rename.rs:53:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> $DIR/rename.rs:53:9 + --> $DIR/rename.rs:54:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> $DIR/rename.rs:54:9 + --> $DIR/rename.rs:55:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> $DIR/rename.rs:55:9 + --> $DIR/rename.rs:56:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> $DIR/rename.rs:56:9 + --> $DIR/rename.rs:57:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> $DIR/rename.rs:57:9 + --> $DIR/rename.rs:58:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> $DIR/rename.rs:58:9 + --> $DIR/rename.rs:59:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:59:9 + --> $DIR/rename.rs:60:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:60:9 + --> $DIR/rename.rs:61:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:61:9 + --> $DIR/rename.rs:62:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:62:9 + --> $DIR/rename.rs:63:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:63:9 + --> $DIR/rename.rs:64:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:64:9 + --> $DIR/rename.rs:65:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:65:9 + --> $DIR/rename.rs:66:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:66:9 + --> $DIR/rename.rs:67:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:67:9 + --> $DIR/rename.rs:68:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:69:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::clone_double_ref)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` error: lint `clippy::drop_copy` has been renamed to `drop_copy` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::drop_copy)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `drop_copy` error: lint `clippy::drop_ref` has been renamed to `drop_ref` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::drop_ref)] | ^^^^^^^^^^^^^^^^ help: use the new name: `drop_ref` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:79:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:80:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` +error: lint `clippy::forget_ref` has been renamed to `forget_ref` + --> $DIR/rename.rs:82:9 + | +LL | #![warn(clippy::forget_ref)] + | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forget_ref` + error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:83:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:84:9 + --> $DIR/rename.rs:86:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:85:9 + --> $DIR/rename.rs:87:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:86:9 + --> $DIR/rename.rs:88:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:87:9 + --> $DIR/rename.rs:89:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:88:9 + --> $DIR/rename.rs:90:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:89:9 + --> $DIR/rename.rs:91:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:90:9 + --> $DIR/rename.rs:92:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 45 previous errors +error: aborting due to 46 previous errors From fd784bbc55bb1173a72ee8c7d375a6990d6c1d14 Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 28 Mar 2023 19:26:35 +0200 Subject: [PATCH 0832/1222] Drop uplifted clippy::forget_copy --- clippy_lints/src/declared_lints.rs | 1 - clippy_lints/src/drop_forget_ref.rs | 35 +-------- clippy_lints/src/renamed_lints.rs | 1 + tests/ui/drop_forget_copy.rs | 86 --------------------- tests/ui/drop_forget_copy.stderr | 112 ---------------------------- tests/ui/mem_forget.rs | 2 +- tests/ui/rename.fixed | 2 + tests/ui/rename.rs | 2 + tests/ui/rename.stderr | 100 +++++++++++++------------ 9 files changed, 61 insertions(+), 280 deletions(-) delete mode 100644 tests/ui/drop_forget_copy.rs delete mode 100644 tests/ui/drop_forget_copy.stderr diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 255df2b7e466..04993e492879 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -133,7 +133,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::doc::UNNECESSARY_SAFETY_DOC_INFO, crate::double_parens::DOUBLE_PARENS_INFO, crate::drop_forget_ref::DROP_NON_DROP_INFO, - crate::drop_forget_ref::FORGET_COPY_INFO, crate::drop_forget_ref::FORGET_NON_DROP_INFO, crate::drop_forget_ref::UNDROPPED_MANUALLY_DROPS_INFO, crate::duplicate_mod::DUPLICATE_MOD_INFO, diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 23ec7f15aaa7..b2f7d026cc8b 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -7,34 +7,6 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; -declare_clippy_lint! { - /// ### What it does - /// Checks for calls to `std::mem::forget` with a value that - /// derives the Copy trait - /// - /// ### Why is this bad? - /// Calling `std::mem::forget` [does nothing for types that - /// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the - /// value will be copied and moved into the function on invocation. - /// - /// An alternative, but also valid, explanation is that Copy types do not - /// implement - /// the Drop trait, which means they have no destructors. Without a destructor, - /// there - /// is nothing for `std::mem::forget` to ignore. - /// - /// ### Example - /// ```rust - /// let x: i32 = 42; // i32 implements Copy - /// std::mem::forget(x) // A copy of x is passed to the function, leaving the - /// // original unaffected - /// ``` - #[clippy::version = "pre 1.29.0"] - pub FORGET_COPY, - correctness, - "calls to `std::mem::forget` with a value that implements Copy" -} - declare_clippy_lint! { /// ### What it does /// Checks for calls to `std::mem::drop` with a value that does not implement `Drop`. @@ -104,15 +76,12 @@ declare_clippy_lint! { "use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value" } -const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements `Copy`. \ - Forgetting a copy leaves the original intact"; const DROP_NON_DROP_SUMMARY: &str = "call to `std::mem::drop` with a value that does not implement `Drop`. \ Dropping such a type only extends its contained lifetimes"; const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value that does not implement `Drop`. \ Forgetting such a type is the same as dropping it"; declare_lint_pass!(DropForgetRef => [ - FORGET_COPY, DROP_NON_DROP, FORGET_NON_DROP, UNDROPPED_MANUALLY_DROPS @@ -129,11 +98,11 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { let is_copy = is_copy(cx, arg_ty); let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); let (lint, msg) = match fn_name { - // early return for uplifted lints: drop_ref, drop_copy, forget_ref + // early return for uplifted lints: drop_ref, drop_copy, forget_ref, forget_copy sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return, sym::mem_forget if arg_ty.is_ref() => return, sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return, - sym::mem_forget if is_copy => (FORGET_COPY, FORGET_COPY_SUMMARY), + sym::mem_forget if is_copy => return, sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => { span_lint_and_help( cx, diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index d5b1883e0b27..52e22c0c6303 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -37,6 +37,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::for_loop_over_option", "for_loops_over_fallibles"), ("clippy::for_loop_over_result", "for_loops_over_fallibles"), ("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"), + ("clippy::forget_copy", "forget_copy"), ("clippy::forget_ref", "forget_ref"), ("clippy::into_iter_on_array", "array_into_iter"), ("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"), diff --git a/tests/ui/drop_forget_copy.rs b/tests/ui/drop_forget_copy.rs deleted file mode 100644 index ebe60ebbd304..000000000000 --- a/tests/ui/drop_forget_copy.rs +++ /dev/null @@ -1,86 +0,0 @@ -#![warn(drop_copy, clippy::forget_copy)] -#![allow(clippy::toplevel_ref_arg, drop_ref, forget_ref, unused_mut)] - -use std::mem::{drop, forget}; -use std::vec::Vec; - -#[derive(Copy, Clone)] -struct SomeStruct; - -struct AnotherStruct { - x: u8, - y: u8, - z: Vec, -} - -impl Clone for AnotherStruct { - fn clone(&self) -> AnotherStruct { - AnotherStruct { - x: self.x, - y: self.y, - z: self.z.clone(), - } - } -} - -fn main() { - let s1 = SomeStruct {}; - let s2 = s1; - let s3 = &s1; - let mut s4 = s1; - let ref s5 = s1; - - drop(s1); - drop(s2); - drop(s3); - drop(s4); - drop(s5); - - forget(s1); - forget(s2); - forget(s3); - forget(s4); - forget(s5); - - let a1 = AnotherStruct { - x: 255, - y: 0, - z: vec![1, 2, 3], - }; - let a2 = &a1; - let mut a3 = a1.clone(); - let ref a4 = a1; - let a5 = a1.clone(); - - drop(a2); - drop(a3); - drop(a4); - drop(a5); - - forget(a2); - let a3 = &a1; - forget(a3); - forget(a4); - let a5 = a1.clone(); - forget(a5); -} - -#[allow(unused)] -#[allow(clippy::unit_cmp)] -fn issue9482(x: u8) { - fn println_and(t: T) -> T { - println!("foo"); - t - } - - match x { - 0 => drop(println_and(12)), // Don't lint (copy type), we only care about side-effects - 1 => drop(println_and(String::new())), // Don't lint (no copy type), we only care about side-effects - 2 => { - drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block - }, - 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm` - 4 => drop(2), // Lint, not a fn/method call - _ => (), - } -} diff --git a/tests/ui/drop_forget_copy.stderr b/tests/ui/drop_forget_copy.stderr deleted file mode 100644 index 3b19cf3968f6..000000000000 --- a/tests/ui/drop_forget_copy.stderr +++ /dev/null @@ -1,112 +0,0 @@ -error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact - --> $DIR/drop_forget_copy.rs:39:5 - | -LL | forget(s1); - | ^^^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:39:12 - | -LL | forget(s1); - | ^^ - = note: `-D clippy::forget-copy` implied by `-D warnings` - -error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact - --> $DIR/drop_forget_copy.rs:40:5 - | -LL | forget(s2); - | ^^^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:40:12 - | -LL | forget(s2); - | ^^ - -error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact - --> $DIR/drop_forget_copy.rs:42:5 - | -LL | forget(s4); - | ^^^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:42:12 - | -LL | forget(s4); - | ^^ - -error: calls to `std::mem::drop` with a value that implements `Copy`. - --> $DIR/drop_forget_copy.rs:33:5 - | -LL | drop(s1); - | ^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:33:10 - | -LL | drop(s1); - | ^^ - = note: `-D drop-copy` implied by `-D warnings` - -error: calls to `std::mem::drop` with a value that implements `Copy`. - --> $DIR/drop_forget_copy.rs:34:5 - | -LL | drop(s2); - | ^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:34:10 - | -LL | drop(s2); - | ^^ - -error: calls to `std::mem::drop` with a value that implements `Copy`. - --> $DIR/drop_forget_copy.rs:36:5 - | -LL | drop(s4); - | ^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:36:10 - | -LL | drop(s4); - | ^^ - -error: calls to `std::mem::drop` with a value that implements `Copy`. - --> $DIR/drop_forget_copy.rs:80:13 - | -LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block - | ^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `i32` - --> $DIR/drop_forget_copy.rs:80:18 - | -LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block - | ^^^^^^^^^^^^^^^ - -error: calls to `std::mem::drop` with a value that implements `Copy`. - --> $DIR/drop_forget_copy.rs:82:14 - | -LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm` - | ^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `i32` - --> $DIR/drop_forget_copy.rs:82:19 - | -LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm` - | ^^^^^^^^^^^^^^^ - -error: calls to `std::mem::drop` with a value that implements `Copy`. - --> $DIR/drop_forget_copy.rs:83:14 - | -LL | 4 => drop(2), // Lint, not a fn/method call - | ^^^^^^^ - | -note: argument has type `i32` - --> $DIR/drop_forget_copy.rs:83:19 - | -LL | 4 => drop(2), // Lint, not a fn/method call - | ^ - -error: aborting due to 9 previous errors - diff --git a/tests/ui/mem_forget.rs b/tests/ui/mem_forget.rs index e5b35c098a23..5137448a6d4b 100644 --- a/tests/ui/mem_forget.rs +++ b/tests/ui/mem_forget.rs @@ -5,7 +5,7 @@ use std::mem as memstuff; use std::mem::forget as forgetSomething; #[warn(clippy::mem_forget)] -#[allow(clippy::forget_copy)] +#[allow(forget_copy)] fn main() { let five: i32 = 5; forgetSomething(five); diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index 6cb2f82c117a..9036f8926128 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -32,6 +32,7 @@ #![allow(drop_copy)] #![allow(drop_ref)] #![allow(for_loops_over_fallibles)] +#![allow(forget_copy)] #![allow(forget_ref)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] @@ -79,6 +80,7 @@ #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] +#![warn(forget_copy)] #![warn(forget_ref)] #![warn(array_into_iter)] #![warn(invalid_atomic_ordering)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index 72acc312d548..43cabe810f34 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -32,6 +32,7 @@ #![allow(drop_copy)] #![allow(drop_ref)] #![allow(for_loops_over_fallibles)] +#![allow(forget_copy)] #![allow(forget_ref)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] @@ -79,6 +80,7 @@ #![warn(clippy::for_loop_over_option)] #![warn(clippy::for_loop_over_result)] #![warn(clippy::for_loops_over_fallibles)] +#![warn(clippy::forget_copy)] #![warn(clippy::forget_ref)] #![warn(clippy::into_iter_on_array)] #![warn(clippy::invalid_atomic_ordering)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 2847cdbba5df..1ad7cf412c89 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> $DIR/rename.rs:47:9 + --> $DIR/rename.rs:48:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -7,274 +7,280 @@ LL | #![warn(clippy::almost_complete_letter_range)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> $DIR/rename.rs:48:9 + --> $DIR/rename.rs:49:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:49:9 + --> $DIR/rename.rs:50:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:50:9 + --> $DIR/rename.rs:51:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> $DIR/rename.rs:51:9 + --> $DIR/rename.rs:52:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:52:9 + --> $DIR/rename.rs:53:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:53:9 + --> $DIR/rename.rs:54:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> $DIR/rename.rs:54:9 + --> $DIR/rename.rs:55:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> $DIR/rename.rs:55:9 + --> $DIR/rename.rs:56:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> $DIR/rename.rs:56:9 + --> $DIR/rename.rs:57:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> $DIR/rename.rs:57:9 + --> $DIR/rename.rs:58:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> $DIR/rename.rs:58:9 + --> $DIR/rename.rs:59:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> $DIR/rename.rs:59:9 + --> $DIR/rename.rs:60:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:60:9 + --> $DIR/rename.rs:61:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:61:9 + --> $DIR/rename.rs:62:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:62:9 + --> $DIR/rename.rs:63:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:63:9 + --> $DIR/rename.rs:64:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:64:9 + --> $DIR/rename.rs:65:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:65:9 + --> $DIR/rename.rs:66:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:66:9 + --> $DIR/rename.rs:67:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:67:9 + --> $DIR/rename.rs:68:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:69:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::clone_double_ref)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` error: lint `clippy::drop_copy` has been renamed to `drop_copy` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::drop_copy)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `drop_copy` error: lint `clippy::drop_ref` has been renamed to `drop_ref` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:79:9 | LL | #![warn(clippy::drop_ref)] | ^^^^^^^^^^^^^^^^ help: use the new name: `drop_ref` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:80:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` +error: lint `clippy::forget_copy` has been renamed to `forget_copy` + --> $DIR/rename.rs:83:9 + | +LL | #![warn(clippy::forget_copy)] + | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forget_copy` + error: lint `clippy::forget_ref` has been renamed to `forget_ref` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::forget_ref)] | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forget_ref` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:84:9 + --> $DIR/rename.rs:86:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:85:9 + --> $DIR/rename.rs:87:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:86:9 + --> $DIR/rename.rs:88:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:87:9 + --> $DIR/rename.rs:89:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:88:9 + --> $DIR/rename.rs:90:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:89:9 + --> $DIR/rename.rs:91:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:90:9 + --> $DIR/rename.rs:92:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:91:9 + --> $DIR/rename.rs:93:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:92:9 + --> $DIR/rename.rs:94:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 46 previous errors +error: aborting due to 47 previous errors From 7c191376dc5de4d7d0d6cce34d6d65486e433aa9 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 14 May 2023 07:58:06 -0700 Subject: [PATCH 0833/1222] Exposes false negative in clippy's diverging_sub_expression --- tests/ui/diverging_sub_expression.stderr | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/ui/diverging_sub_expression.stderr b/tests/ui/diverging_sub_expression.stderr index 9c91d935716d..51a3b0d972e6 100644 --- a/tests/ui/diverging_sub_expression.stderr +++ b/tests/ui/diverging_sub_expression.stderr @@ -30,19 +30,11 @@ error: sub-expression diverges LL | 3 => true || diverge(), | ^^^^^^^^^ -error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:36:30 - | -LL | _ => true || panic!("boo"), - | ^^^^^^^^^^^^^ - | - = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) - error: sub-expression diverges --> $DIR/diverging_sub_expression.rs:38:26 | LL | _ => true || break, | ^^^^^ -error: aborting due to 7 previous errors +error: aborting due to 6 previous errors From be886d289cb1d2bf11dc0f88c9f9e55b21f08f74 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Tue, 16 May 2023 19:23:38 +0200 Subject: [PATCH 0834/1222] Remove `LangItems::require` It's just a short wrapper used by `tcx.require_lang_item`. Deleting it gives us a negative diff. --- clippy_lints/src/matches/redundant_pattern_match.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/matches/redundant_pattern_match.rs b/clippy_lints/src/matches/redundant_pattern_match.rs index af121f317cd1..0809837d1fd7 100644 --- a/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/clippy_lints/src/matches/redundant_pattern_match.rs @@ -289,10 +289,11 @@ fn is_pat_variant(cx: &LateContext<'_>, pat: &Pat<'_>, path: &QPath<'_>, expecte let Some(id) = cx.typeck_results().qpath_res(path, pat.hir_id).opt_def_id() else { return false }; match expected_item { - Item::Lang(expected_lang_item) => { - let expected_id = cx.tcx.lang_items().require(expected_lang_item).unwrap(); - cx.tcx.parent(id) == expected_id - }, + Item::Lang(expected_lang_item) => cx + .tcx + .lang_items() + .get(expected_lang_item) + .map_or(false, |expected_id| cx.tcx.parent(id) == expected_id), Item::Diag(expected_ty, expected_variant) => { let ty = cx.typeck_results().pat_ty(pat); From 821ae34b01dd34fdc2b1d3ea2945450b18b646ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Wed, 17 May 2023 19:47:23 +0200 Subject: [PATCH 0835/1222] Exclude inherent projections from some alias ty matches --- tests/ui/issue-111399.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/ui/issue-111399.rs diff --git a/tests/ui/issue-111399.rs b/tests/ui/issue-111399.rs new file mode 100644 index 000000000000..b65e6c7261a5 --- /dev/null +++ b/tests/ui/issue-111399.rs @@ -0,0 +1,13 @@ +#![feature(inherent_associated_types)] +#![allow(incomplete_features)] + +// Check that rustc doesn't crash on the trait bound `Self::Ty: std::marker::Freeze`. + +pub struct Struct; + +impl Struct { + pub type Ty = usize; + pub const CT: Self::Ty = 42; +} + +fn main() {} From 00aea6b22e9e98c60174884f9f0571837aec6a2e Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 19 May 2023 11:14:55 +0200 Subject: [PATCH 0836/1222] Rename `drop_copy` lint to `dropping_copy_types` --- clippy_lints/src/drop_forget_ref.rs | 2 +- clippy_lints/src/renamed_lints.rs | 2 +- tests/ui/multiple_unsafe_ops_per_block.rs | 2 +- tests/ui/rename.fixed | 4 ++-- tests/ui/rename.rs | 2 +- tests/ui/rename.stderr | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index b2f7d026cc8b..9a7b39e1544e 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { let is_copy = is_copy(cx, arg_ty); let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); let (lint, msg) = match fn_name { - // early return for uplifted lints: drop_ref, drop_copy, forget_ref, forget_copy + // early return for uplifted lints: drop_ref, dropping_copy_types, forget_ref, forget_copy sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return, sym::mem_forget if arg_ty.is_ref() => return, sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return, diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index a2c3465cde4a..308e40abf6a2 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -33,7 +33,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::zero_width_space", "clippy::invisible_characters"), ("clippy::clone_double_ref", "suspicious_double_ref_op"), ("clippy::drop_bounds", "drop_bounds"), - ("clippy::drop_copy", "drop_copy"), + ("clippy::drop_copy", "dropping_copy_types"), ("clippy::drop_ref", "drop_ref"), ("clippy::for_loop_over_option", "for_loops_over_fallibles"), ("clippy::for_loop_over_result", "for_loops_over_fallibles"), diff --git a/tests/ui/multiple_unsafe_ops_per_block.rs b/tests/ui/multiple_unsafe_ops_per_block.rs index f28153e56b0f..4ef6f0ca92f2 100644 --- a/tests/ui/multiple_unsafe_ops_per_block.rs +++ b/tests/ui/multiple_unsafe_ops_per_block.rs @@ -2,7 +2,7 @@ #![allow(unused)] #![allow(deref_nullptr)] #![allow(clippy::unnecessary_operation)] -#![allow(drop_copy)] +#![allow(dropping_copy_types)] #![warn(clippy::multiple_unsafe_ops_per_block)] extern crate proc_macros; diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index 7c2acf43fe83..8633e422805a 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -30,7 +30,7 @@ #![allow(clippy::invisible_characters)] #![allow(suspicious_double_ref_op)] #![allow(drop_bounds)] -#![allow(drop_copy)] +#![allow(dropping_copy_types)] #![allow(drop_ref)] #![allow(for_loops_over_fallibles)] #![allow(forget_copy)] @@ -77,7 +77,7 @@ #![warn(clippy::invisible_characters)] #![warn(suspicious_double_ref_op)] #![warn(drop_bounds)] -#![warn(drop_copy)] +#![warn(dropping_copy_types)] #![warn(drop_ref)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index 8d334b0d0501..07b33b4da95b 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -30,7 +30,7 @@ #![allow(clippy::invisible_characters)] #![allow(suspicious_double_ref_op)] #![allow(drop_bounds)] -#![allow(drop_copy)] +#![allow(dropping_copy_types)] #![allow(drop_ref)] #![allow(for_loops_over_fallibles)] #![allow(forget_copy)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index fbf8d3d7e4e8..20e7d96b7209 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -186,11 +186,11 @@ error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` -error: lint `clippy::drop_copy` has been renamed to `drop_copy` +error: lint `clippy::drop_copy` has been renamed to `dropping_copy_types` --> $DIR/rename.rs:80:9 | LL | #![warn(clippy::drop_copy)] - | ^^^^^^^^^^^^^^^^^ help: use the new name: `drop_copy` + | ^^^^^^^^^^^^^^^^^ help: use the new name: `dropping_copy_types` error: lint `clippy::drop_ref` has been renamed to `drop_ref` --> $DIR/rename.rs:81:9 From 3123fe5d2321f970f08fa9b76c892299c88ec119 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 19 May 2023 11:19:31 +0200 Subject: [PATCH 0837/1222] Rename `forget_copy` lint to `forgetting_copy_types` --- clippy_lints/src/drop_forget_ref.rs | 2 +- clippy_lints/src/renamed_lints.rs | 2 +- tests/ui/mem_forget.rs | 2 +- tests/ui/rename.fixed | 4 ++-- tests/ui/rename.rs | 2 +- tests/ui/rename.stderr | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 9a7b39e1544e..db1b8494890e 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { let is_copy = is_copy(cx, arg_ty); let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); let (lint, msg) = match fn_name { - // early return for uplifted lints: drop_ref, dropping_copy_types, forget_ref, forget_copy + // early return for uplifted lints: drop_ref, dropping_copy_types, forget_ref, forgetting_copy_types sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return, sym::mem_forget if arg_ty.is_ref() => return, sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return, diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index 308e40abf6a2..a81dbb9b2599 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -38,7 +38,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::for_loop_over_option", "for_loops_over_fallibles"), ("clippy::for_loop_over_result", "for_loops_over_fallibles"), ("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"), - ("clippy::forget_copy", "forget_copy"), + ("clippy::forget_copy", "forgetting_copy_types"), ("clippy::forget_ref", "forget_ref"), ("clippy::into_iter_on_array", "array_into_iter"), ("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"), diff --git a/tests/ui/mem_forget.rs b/tests/ui/mem_forget.rs index 5137448a6d4b..edb9d87d032e 100644 --- a/tests/ui/mem_forget.rs +++ b/tests/ui/mem_forget.rs @@ -5,7 +5,7 @@ use std::mem as memstuff; use std::mem::forget as forgetSomething; #[warn(clippy::mem_forget)] -#[allow(forget_copy)] +#[allow(forgetting_copy_types)] fn main() { let five: i32 = 5; forgetSomething(five); diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index 8633e422805a..8df63fd9b233 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -33,7 +33,7 @@ #![allow(dropping_copy_types)] #![allow(drop_ref)] #![allow(for_loops_over_fallibles)] -#![allow(forget_copy)] +#![allow(forgetting_copy_types)] #![allow(forget_ref)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] @@ -82,7 +82,7 @@ #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] -#![warn(forget_copy)] +#![warn(forgetting_copy_types)] #![warn(forget_ref)] #![warn(array_into_iter)] #![warn(invalid_atomic_ordering)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index 07b33b4da95b..7206e19f1e02 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -33,7 +33,7 @@ #![allow(dropping_copy_types)] #![allow(drop_ref)] #![allow(for_loops_over_fallibles)] -#![allow(forget_copy)] +#![allow(forgetting_copy_types)] #![allow(forget_ref)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 20e7d96b7209..c2a7c0dd7eb1 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -216,11 +216,11 @@ error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_ov LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` -error: lint `clippy::forget_copy` has been renamed to `forget_copy` +error: lint `clippy::forget_copy` has been renamed to `forgetting_copy_types` --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::forget_copy)] - | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forget_copy` + | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_copy_types` error: lint `clippy::forget_ref` has been renamed to `forget_ref` --> $DIR/rename.rs:86:9 From c40b232b8ed8b60a0c400bbf1d5dccdedf77b1f5 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 19 May 2023 11:25:35 +0200 Subject: [PATCH 0838/1222] Rename `drop_ref` lint to `dropping_references` --- clippy_lints/src/drop_forget_ref.rs | 2 +- clippy_lints/src/renamed_lints.rs | 2 +- tests/ui/rename.fixed | 4 ++-- tests/ui/rename.rs | 2 +- tests/ui/rename.stderr | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index db1b8494890e..00211d65094e 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { let is_copy = is_copy(cx, arg_ty); let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); let (lint, msg) = match fn_name { - // early return for uplifted lints: drop_ref, dropping_copy_types, forget_ref, forgetting_copy_types + // early return for uplifted lints: dropping_references, dropping_copy_types, forget_ref, forgetting_copy_types sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return, sym::mem_forget if arg_ty.is_ref() => return, sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return, diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index a81dbb9b2599..4d1a462d110c 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -34,7 +34,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::clone_double_ref", "suspicious_double_ref_op"), ("clippy::drop_bounds", "drop_bounds"), ("clippy::drop_copy", "dropping_copy_types"), - ("clippy::drop_ref", "drop_ref"), + ("clippy::drop_ref", "dropping_references"), ("clippy::for_loop_over_option", "for_loops_over_fallibles"), ("clippy::for_loop_over_result", "for_loops_over_fallibles"), ("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"), diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index 8df63fd9b233..a4fb4fbffdfc 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -31,7 +31,7 @@ #![allow(suspicious_double_ref_op)] #![allow(drop_bounds)] #![allow(dropping_copy_types)] -#![allow(drop_ref)] +#![allow(dropping_references)] #![allow(for_loops_over_fallibles)] #![allow(forgetting_copy_types)] #![allow(forget_ref)] @@ -78,7 +78,7 @@ #![warn(suspicious_double_ref_op)] #![warn(drop_bounds)] #![warn(dropping_copy_types)] -#![warn(drop_ref)] +#![warn(dropping_references)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index 7206e19f1e02..bb833c953468 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -31,7 +31,7 @@ #![allow(suspicious_double_ref_op)] #![allow(drop_bounds)] #![allow(dropping_copy_types)] -#![allow(drop_ref)] +#![allow(dropping_references)] #![allow(for_loops_over_fallibles)] #![allow(forgetting_copy_types)] #![allow(forget_ref)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index c2a7c0dd7eb1..8bbd046bbf31 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -192,11 +192,11 @@ error: lint `clippy::drop_copy` has been renamed to `dropping_copy_types` LL | #![warn(clippy::drop_copy)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `dropping_copy_types` -error: lint `clippy::drop_ref` has been renamed to `drop_ref` +error: lint `clippy::drop_ref` has been renamed to `dropping_references` --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::drop_ref)] - | ^^^^^^^^^^^^^^^^ help: use the new name: `drop_ref` + | ^^^^^^^^^^^^^^^^ help: use the new name: `dropping_references` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` --> $DIR/rename.rs:82:9 From f9fdb31f6af610ad3479798e790323bc03918731 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 19 May 2023 11:30:11 +0200 Subject: [PATCH 0839/1222] Rename `forget_ref` lint to `forgetting_references` --- clippy_lints/src/drop_forget_ref.rs | 2 +- clippy_lints/src/renamed_lints.rs | 2 +- tests/ui/rename.fixed | 4 ++-- tests/ui/rename.rs | 2 +- tests/ui/rename.stderr | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 00211d65094e..9c60edb17941 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { let is_copy = is_copy(cx, arg_ty); let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); let (lint, msg) = match fn_name { - // early return for uplifted lints: dropping_references, dropping_copy_types, forget_ref, forgetting_copy_types + // early return for uplifted lints: dropping_references, dropping_copy_types, forgetting_references, forgetting_copy_types sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return, sym::mem_forget if arg_ty.is_ref() => return, sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return, diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index 4d1a462d110c..b0db56bb417e 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -39,7 +39,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::for_loop_over_result", "for_loops_over_fallibles"), ("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"), ("clippy::forget_copy", "forgetting_copy_types"), - ("clippy::forget_ref", "forget_ref"), + ("clippy::forget_ref", "forgetting_references"), ("clippy::into_iter_on_array", "array_into_iter"), ("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"), ("clippy::invalid_ref", "invalid_value"), diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index a4fb4fbffdfc..dfe45dec8a74 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -34,7 +34,7 @@ #![allow(dropping_references)] #![allow(for_loops_over_fallibles)] #![allow(forgetting_copy_types)] -#![allow(forget_ref)] +#![allow(forgetting_references)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] @@ -83,7 +83,7 @@ #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] #![warn(forgetting_copy_types)] -#![warn(forget_ref)] +#![warn(forgetting_references)] #![warn(array_into_iter)] #![warn(invalid_atomic_ordering)] #![warn(invalid_value)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index bb833c953468..ce8eca5a3081 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -34,7 +34,7 @@ #![allow(dropping_references)] #![allow(for_loops_over_fallibles)] #![allow(forgetting_copy_types)] -#![allow(forget_ref)] +#![allow(forgetting_references)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 8bbd046bbf31..3fca60aa2ebd 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -222,11 +222,11 @@ error: lint `clippy::forget_copy` has been renamed to `forgetting_copy_types` LL | #![warn(clippy::forget_copy)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_copy_types` -error: lint `clippy::forget_ref` has been renamed to `forget_ref` +error: lint `clippy::forget_ref` has been renamed to `forgetting_references` --> $DIR/rename.rs:86:9 | LL | #![warn(clippy::forget_ref)] - | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forget_ref` + | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` --> $DIR/rename.rs:87:9 From ecfa093f84231273d4e5b563d01738a223d32b1f Mon Sep 17 00:00:00 2001 From: Urgau Date: Sat, 13 May 2023 18:11:27 +0200 Subject: [PATCH 0840/1222] Drop uplifted clippy::invalid_utf8_in_unchecked --- clippy_lints/src/declared_lints.rs | 1 - clippy_lints/src/invalid_utf8_in_unchecked.rs | 74 ------------- clippy_lints/src/lib.rs | 2 - clippy_lints/src/renamed_lints.rs | 1 + tests/ui/invalid_utf8_in_unchecked.rs | 20 ---- tests/ui/invalid_utf8_in_unchecked.stderr | 22 ---- tests/ui/rename.fixed | 2 + tests/ui/rename.rs | 2 + tests/ui/rename.stderr | 104 +++++++++--------- 9 files changed, 60 insertions(+), 168 deletions(-) delete mode 100644 clippy_lints/src/invalid_utf8_in_unchecked.rs delete mode 100644 tests/ui/invalid_utf8_in_unchecked.rs delete mode 100644 tests/ui/invalid_utf8_in_unchecked.stderr diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 423eee47742e..0ae95b045e03 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -212,7 +212,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::instant_subtraction::UNCHECKED_DURATION_SUBTRACTION_INFO, crate::int_plus_one::INT_PLUS_ONE_INFO, crate::invalid_upcast_comparisons::INVALID_UPCAST_COMPARISONS_INFO, - crate::invalid_utf8_in_unchecked::INVALID_UTF8_IN_UNCHECKED_INFO, crate::items_after_statements::ITEMS_AFTER_STATEMENTS_INFO, crate::items_after_test_module::ITEMS_AFTER_TEST_MODULE_INFO, crate::iter_not_returning_iterator::ITER_NOT_RETURNING_ITERATOR_INFO, diff --git a/clippy_lints/src/invalid_utf8_in_unchecked.rs b/clippy_lints/src/invalid_utf8_in_unchecked.rs deleted file mode 100644 index 6a4861747d26..000000000000 --- a/clippy_lints/src/invalid_utf8_in_unchecked.rs +++ /dev/null @@ -1,74 +0,0 @@ -use clippy_utils::diagnostics::span_lint; -use clippy_utils::{match_function_call, paths}; -use rustc_ast::{BorrowKind, LitKind}; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Spanned; -use rustc_span::Span; - -declare_clippy_lint! { - /// ### What it does - /// Checks for `std::str::from_utf8_unchecked` with an invalid UTF-8 literal - /// - /// ### Why is this bad? - /// Creating such a `str` would result in undefined behavior - /// - /// ### Example - /// ```rust - /// # #[allow(unused)] - /// unsafe { - /// std::str::from_utf8_unchecked(b"cl\x82ippy"); - /// } - /// ``` - #[clippy::version = "1.64.0"] - pub INVALID_UTF8_IN_UNCHECKED, - correctness, - "using a non UTF-8 literal in `std::std::from_utf8_unchecked`" -} -declare_lint_pass!(InvalidUtf8InUnchecked => [INVALID_UTF8_IN_UNCHECKED]); - -impl<'tcx> LateLintPass<'tcx> for InvalidUtf8InUnchecked { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - if let Some([arg]) = match_function_call(cx, expr, &paths::STR_FROM_UTF8_UNCHECKED) { - match &arg.kind { - ExprKind::Lit(Spanned { node: lit, .. }) => { - if let LitKind::ByteStr(bytes, _) = &lit - && std::str::from_utf8(bytes).is_err() - { - lint(cx, expr.span); - } - }, - ExprKind::AddrOf(BorrowKind::Ref, _, Expr { kind: ExprKind::Array(args), .. }) => { - let elements = args.iter().map(|e|{ - match &e.kind { - ExprKind::Lit(Spanned { node: lit, .. }) => match lit { - LitKind::Byte(b) => Some(*b), - #[allow(clippy::cast_possible_truncation)] - LitKind::Int(b, _) => Some(*b as u8), - _ => None - } - _ => None - } - }).collect::>>(); - - if let Some(elements) = elements - && std::str::from_utf8(&elements).is_err() - { - lint(cx, expr.span); - } - } - _ => {} - } - } - } -} - -fn lint(cx: &LateContext<'_>, span: Span) { - span_lint( - cx, - INVALID_UTF8_IN_UNCHECKED, - span, - "non UTF-8 literal in `std::str::from_utf8_unchecked`", - ); -} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index b442a4ac5f61..fcca595c2bc4 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -157,7 +157,6 @@ mod inline_fn_without_body; mod instant_subtraction; mod int_plus_one; mod invalid_upcast_comparisons; -mod invalid_utf8_in_unchecked; mod items_after_statements; mod items_after_test_module; mod iter_not_returning_iterator; @@ -937,7 +936,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_late_pass(move |_| Box::new(manual_retain::ManualRetain::new(msrv()))); let verbose_bit_mask_threshold = conf.verbose_bit_mask_threshold; store.register_late_pass(move |_| Box::new(operators::Operators::new(verbose_bit_mask_threshold))); - store.register_late_pass(|_| Box::new(invalid_utf8_in_unchecked::InvalidUtf8InUnchecked)); store.register_late_pass(|_| Box::::default()); store.register_late_pass(move |_| Box::new(instant_subtraction::InstantSubtraction::new(msrv()))); store.register_late_pass(|_| Box::new(partialeq_to_none::PartialeqToNone)); diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index b0db56bb417e..7c2a100efdac 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -43,6 +43,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::into_iter_on_array", "array_into_iter"), ("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"), ("clippy::invalid_ref", "invalid_value"), + ("clippy::invalid_utf8_in_unchecked", "invalid_from_utf8_unchecked"), ("clippy::let_underscore_drop", "let_underscore_drop"), ("clippy::mem_discriminant_non_enum", "enum_intrinsics_non_enums"), ("clippy::panic_params", "non_fmt_panics"), diff --git a/tests/ui/invalid_utf8_in_unchecked.rs b/tests/ui/invalid_utf8_in_unchecked.rs deleted file mode 100644 index 3dc096d3197f..000000000000 --- a/tests/ui/invalid_utf8_in_unchecked.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![warn(clippy::invalid_utf8_in_unchecked)] - -fn main() { - // Valid - unsafe { - std::str::from_utf8_unchecked(&[99, 108, 105, 112, 112, 121]); - std::str::from_utf8_unchecked(&[b'c', b'l', b'i', b'p', b'p', b'y']); - std::str::from_utf8_unchecked(b"clippy"); - - let x = 0xA0; - std::str::from_utf8_unchecked(&[0xC0, x]); - } - - // Invalid - unsafe { - std::str::from_utf8_unchecked(&[99, 108, 130, 105, 112, 112, 121]); - std::str::from_utf8_unchecked(&[b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']); - std::str::from_utf8_unchecked(b"cl\x82ippy"); - } -} diff --git a/tests/ui/invalid_utf8_in_unchecked.stderr b/tests/ui/invalid_utf8_in_unchecked.stderr deleted file mode 100644 index c89cd2758ee9..000000000000 --- a/tests/ui/invalid_utf8_in_unchecked.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: non UTF-8 literal in `std::str::from_utf8_unchecked` - --> $DIR/invalid_utf8_in_unchecked.rs:16:9 - | -LL | std::str::from_utf8_unchecked(&[99, 108, 130, 105, 112, 112, 121]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-utf8-in-unchecked` implied by `-D warnings` - -error: non UTF-8 literal in `std::str::from_utf8_unchecked` - --> $DIR/invalid_utf8_in_unchecked.rs:17:9 - | -LL | std::str::from_utf8_unchecked(&[b'c', b'l', b'/x82', b'i', b'p', b'p', b'y']); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: non UTF-8 literal in `std::str::from_utf8_unchecked` - --> $DIR/invalid_utf8_in_unchecked.rs:18:9 - | -LL | std::str::from_utf8_unchecked(b"cl/x82ippy"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index dfe45dec8a74..53ac65473b82 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -38,6 +38,7 @@ #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] +#![allow(invalid_from_utf8_unchecked)] #![allow(let_underscore_drop)] #![allow(enum_intrinsics_non_enums)] #![allow(non_fmt_panics)] @@ -87,6 +88,7 @@ #![warn(array_into_iter)] #![warn(invalid_atomic_ordering)] #![warn(invalid_value)] +#![warn(invalid_from_utf8_unchecked)] #![warn(let_underscore_drop)] #![warn(enum_intrinsics_non_enums)] #![warn(non_fmt_panics)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index ce8eca5a3081..722c0b3eb275 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -38,6 +38,7 @@ #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] +#![allow(invalid_from_utf8_unchecked)] #![allow(let_underscore_drop)] #![allow(enum_intrinsics_non_enums)] #![allow(non_fmt_panics)] @@ -87,6 +88,7 @@ #![warn(clippy::into_iter_on_array)] #![warn(clippy::invalid_atomic_ordering)] #![warn(clippy::invalid_ref)] +#![warn(clippy::invalid_utf8_in_unchecked)] #![warn(clippy::let_underscore_drop)] #![warn(clippy::mem_discriminant_non_enum)] #![warn(clippy::panic_params)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 3fca60aa2ebd..1ff839176602 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> $DIR/rename.rs:49:9 + --> $DIR/rename.rs:50:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -7,286 +7,292 @@ LL | #![warn(clippy::almost_complete_letter_range)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> $DIR/rename.rs:50:9 + --> $DIR/rename.rs:51:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:51:9 + --> $DIR/rename.rs:52:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:52:9 + --> $DIR/rename.rs:53:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> $DIR/rename.rs:53:9 + --> $DIR/rename.rs:54:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:54:9 + --> $DIR/rename.rs:55:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:55:9 + --> $DIR/rename.rs:56:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> $DIR/rename.rs:56:9 + --> $DIR/rename.rs:57:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> $DIR/rename.rs:57:9 + --> $DIR/rename.rs:58:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> $DIR/rename.rs:58:9 + --> $DIR/rename.rs:59:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> $DIR/rename.rs:59:9 + --> $DIR/rename.rs:60:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> $DIR/rename.rs:60:9 + --> $DIR/rename.rs:61:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> $DIR/rename.rs:61:9 + --> $DIR/rename.rs:62:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::integer_arithmetic` has been renamed to `clippy::arithmetic_side_effects` - --> $DIR/rename.rs:62:9 + --> $DIR/rename.rs:63:9 | LL | #![warn(clippy::integer_arithmetic)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::arithmetic_side_effects` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:63:9 + --> $DIR/rename.rs:64:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:64:9 + --> $DIR/rename.rs:65:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:65:9 + --> $DIR/rename.rs:66:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:66:9 + --> $DIR/rename.rs:67:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:67:9 + --> $DIR/rename.rs:68:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:69:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:79:9 | LL | #![warn(clippy::clone_double_ref)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:80:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` error: lint `clippy::drop_copy` has been renamed to `dropping_copy_types` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::drop_copy)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `dropping_copy_types` error: lint `clippy::drop_ref` has been renamed to `dropping_references` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::drop_ref)] | ^^^^^^^^^^^^^^^^ help: use the new name: `dropping_references` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:83:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:84:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::forget_copy` has been renamed to `forgetting_copy_types` - --> $DIR/rename.rs:85:9 + --> $DIR/rename.rs:86:9 | LL | #![warn(clippy::forget_copy)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_copy_types` error: lint `clippy::forget_ref` has been renamed to `forgetting_references` - --> $DIR/rename.rs:86:9 + --> $DIR/rename.rs:87:9 | LL | #![warn(clippy::forget_ref)] | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:87:9 + --> $DIR/rename.rs:88:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:88:9 + --> $DIR/rename.rs:89:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:89:9 + --> $DIR/rename.rs:90:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` +error: lint `clippy::invalid_utf8_in_unchecked` has been renamed to `invalid_from_utf8_unchecked` + --> $DIR/rename.rs:91:9 + | +LL | #![warn(clippy::invalid_utf8_in_unchecked)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_from_utf8_unchecked` + error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:90:9 + --> $DIR/rename.rs:92:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:91:9 + --> $DIR/rename.rs:93:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:92:9 + --> $DIR/rename.rs:94:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:93:9 + --> $DIR/rename.rs:95:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:94:9 + --> $DIR/rename.rs:96:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:95:9 + --> $DIR/rename.rs:97:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:96:9 + --> $DIR/rename.rs:98:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 48 previous errors +error: aborting due to 49 previous errors From 107a362eb21dcb3d3750599f7b1eae8d0588cbb0 Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Fri, 26 May 2023 11:19:35 -0600 Subject: [PATCH 0841/1222] Replace EarlyBinder(x) with EarlyBinder::new(x) --- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/eta_reduction.rs | 2 +- clippy_lints/src/methods/needless_collect.rs | 2 +- clippy_lints/src/methods/unnecessary_to_owned.rs | 4 ++-- clippy_utils/src/consts.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index b27ffe73ffda..a418a910ba8e 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1219,7 +1219,7 @@ fn needless_borrow_impl_arg_position<'tcx>( return false; } - let predicate = EarlyBinder(predicate).subst(cx.tcx, &substs_with_referent_ty); + let predicate = EarlyBinder::new(predicate).subst(cx.tcx, &substs_with_referent_ty); let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate); let infcx = cx.tcx.infer_ctxt().build(); infcx.predicate_must_hold_modulo_regions(&obligation) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index b2071f4dcb1e..af2aac6ac0d0 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -243,7 +243,7 @@ fn get_ufcs_type_name<'tcx>(cx: &LateContext<'tcx>, method_def_id: DefId, substs | ty::Ref(..) | ty::Slice(_) | ty::Tuple(_) => { - format!("<{}>", EarlyBinder(ty).subst(cx.tcx, substs)) + format!("<{}>", EarlyBinder::new(ty).subst(cx.tcx, substs)) }, _ => ty.to_string(), } diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index 6841aaf626ca..d4cc14bb8563 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -241,7 +241,7 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) - && let proj_ty = cx.tcx.mk_projection(iter_item.def_id, substs) && let Ok(item_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, proj_ty) { - item_ty == EarlyBinder(search_ty).subst(cx.tcx, cx.typeck_results().node_substs(call_id)) + item_ty == EarlyBinder::new(search_ty).subst(cx.tcx, cx.typeck_results().node_substs(call_id)) } else { false } diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 67b7d3691dc0..fdacfa49e92d 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -428,7 +428,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< })); if trait_predicates.any(|predicate| { - let predicate = EarlyBinder(predicate).subst(cx.tcx, new_subst); + let predicate = EarlyBinder::new(predicate).subst(cx.tcx, new_subst); let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate); !cx.tcx.infer_ctxt().build().predicate_must_hold_modulo_regions(&obligation) }) { @@ -438,7 +438,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< let output_ty = fn_sig.output(); if output_ty.contains(*param_ty) { if let Ok(new_ty) = cx.tcx.try_subst_and_normalize_erasing_regions( - new_subst, cx.param_env, EarlyBinder(output_ty)) { + new_subst, cx.param_env, EarlyBinder::new(output_ty)) { expr = parent_expr; ty = new_ty; continue; diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index fb772644c0d6..843538e1eb2d 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -462,7 +462,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let substs = if self.substs.is_empty() { substs } else { - EarlyBinder(substs).subst(self.lcx.tcx, self.substs) + EarlyBinder::new(substs).subst(self.lcx.tcx, self.substs) }; let result = self From 7667412ec3487e7100c0bc5556f762551760f387 Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Fri, 26 May 2023 12:14:48 -0600 Subject: [PATCH 0842/1222] Make EarlyBinder's inner value private; and fix all of the resulting errors --- clippy_lints/src/multiple_unsafe_ops_per_block.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/multiple_unsafe_ops_per_block.rs b/clippy_lints/src/multiple_unsafe_ops_per_block.rs index 2abdfacd2763..e6fd65f001a6 100644 --- a/clippy_lints/src/multiple_unsafe_ops_per_block.rs +++ b/clippy_lints/src/multiple_unsafe_ops_per_block.rs @@ -138,7 +138,7 @@ fn collect_unsafe_exprs<'tcx>( .type_dependent_def_id(expr.hir_id) .map(|def_id| cx.tcx.fn_sig(def_id)) { - if sig.0.unsafety() == Unsafety::Unsafe { + if sig.skip_binder().unsafety() == Unsafety::Unsafe { unsafe_ops.push(("unsafe method call occurs here", expr.span)); } } From 207d6f2dc75d002e14ab27dda985e50c0a92512f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 4 May 2023 10:55:21 +1000 Subject: [PATCH 0843/1222] Use `Cow` in `{D,Subd}iagnosticMessage`. Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment: ``` // FIXME(davidtwco): can a `Cow<'static, str>` be used here? ``` This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging. This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths. Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile. --- clippy_lints/src/missing_const_for_fn.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 11 ++++------- clippy_lints/src/unnecessary_wraps.rs | 2 +- clippy_utils/src/diagnostics.rs | 22 ++++++++++++---------- clippy_utils/src/sugg.rs | 6 +++--- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index f1831a30461a..3b7eccad79df 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -154,7 +154,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { if let Err((span, err)) = is_min_const_fn(cx.tcx, mir, &self.msrv) { if cx.tcx.is_const_fn_raw(def_id.to_def_id()) { - cx.tcx.sess.span_err(span, err.as_ref()); + cx.tcx.sess.span_err(span, err); } } else { span_lint(cx, MISSING_CONST_FOR_FN, span, "this could be a `const fn`"); diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 0bb1775aae9c..7d53fe65658a 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -26,7 +26,6 @@ use rustc_span::{sym, Span}; use rustc_target::spec::abi::Abi; use rustc_trait_selection::traits; use rustc_trait_selection::traits::misc::type_allowed_to_implement_copy; -use std::borrow::Cow; declare_clippy_lint! { /// ### What it does @@ -240,9 +239,8 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { snippet_opt(cx, span) .map_or( "change the call to".into(), - |x| Cow::from(format!("change `{x}` to")), - ) - .as_ref(), + |x| format!("change `{x}` to"), + ), suggestion, Applicability::Unspecified, ); @@ -270,9 +268,8 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { snippet_opt(cx, span) .map_or( "change the call to".into(), - |x| Cow::from(format!("change `{x}` to")) - ) - .as_ref(), + |x| format!("change `{x}` to") + ), suggestion, Applicability::Unspecified, ); diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index 8b0e0ce5a300..5073eb02bd84 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -163,7 +163,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { span_lint_and_then(cx, UNNECESSARY_WRAPS, span, lint_msg.as_str(), |diag| { diag.span_suggestion( fn_decl.output.span(), - return_type_sugg_msg.as_str(), + return_type_sugg_msg, return_type_sugg, Applicability::MaybeIncorrect, ); diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs index 812f6fe71a0a..edd87546a5f8 100644 --- a/clippy_utils/src/diagnostics.rs +++ b/clippy_utils/src/diagnostics.rs @@ -46,7 +46,7 @@ fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) { /// | ^^^^^^^^^^^^^^^^^^^^^^^ /// ``` pub fn span_lint(cx: &T, lint: &'static Lint, sp: impl Into, msg: &str) { - cx.struct_span_lint(lint, sp, msg, |diag| { + cx.struct_span_lint(lint, sp, msg.to_string(), |diag| { docs_link(diag, lint); diag }); @@ -80,11 +80,12 @@ pub fn span_lint_and_help( help_span: Option, help: &str, ) { - cx.struct_span_lint(lint, span, msg, |diag| { + cx.struct_span_lint(lint, span, msg.to_string(), |diag| { + let help = help.to_string(); if let Some(help_span) = help_span { - diag.span_help(help_span, help); + diag.span_help(help_span, help.to_string()); } else { - diag.help(help); + diag.help(help.to_string()); } docs_link(diag, lint); diag @@ -122,7 +123,8 @@ pub fn span_lint_and_note( note_span: Option, note: &str, ) { - cx.struct_span_lint(lint, span, msg, |diag| { + cx.struct_span_lint(lint, span, msg.to_string(), |diag| { + let note = note.to_string(); if let Some(note_span) = note_span { diag.span_note(note_span, note); } else { @@ -143,7 +145,7 @@ where S: Into, F: FnOnce(&mut Diagnostic), { - cx.struct_span_lint(lint, sp, msg, |diag| { + cx.struct_span_lint(lint, sp, msg.to_string(), |diag| { f(diag); docs_link(diag, lint); diag @@ -151,7 +153,7 @@ where } pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) { - cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg, |diag| { + cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg.to_string(), |diag| { docs_link(diag, lint); diag }); @@ -165,7 +167,7 @@ pub fn span_lint_hir_and_then( msg: &str, f: impl FnOnce(&mut Diagnostic), ) { - cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg, |diag| { + cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg.to_string(), |diag| { f(diag); docs_link(diag, lint); diag @@ -202,7 +204,7 @@ pub fn span_lint_and_sugg( applicability: Applicability, ) { span_lint_and_then(cx, lint, sp, msg, |diag| { - diag.span_suggestion(sp, help, sugg, applicability); + diag.span_suggestion(sp, help.to_string(), sugg, applicability); }); } @@ -232,5 +234,5 @@ pub fn multispan_sugg_with_applicability( ) where I: IntoIterator, { - diag.multipart_suggestion(help_msg, sugg.into_iter().collect(), applicability); + diag.multipart_suggestion(help_msg.to_string(), sugg.into_iter().collect(), applicability); } diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 14f7f03016fb..f477524eec5c 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -741,7 +741,7 @@ impl DiagnosticExt for rustc_errors::Diagnostic { if let Some(indent) = indentation(cx, item) { let span = item.with_hi(item.lo()); - self.span_suggestion(span, msg, format!("{attr}\n{indent}"), applicability); + self.span_suggestion(span, msg.to_string(), format!("{attr}\n{indent}"), applicability); } } @@ -762,7 +762,7 @@ impl DiagnosticExt for rustc_errors::Diagnostic { }) .collect::(); - self.span_suggestion(span, msg, format!("{new_item}\n{indent}"), applicability); + self.span_suggestion(span, msg.to_string(), format!("{new_item}\n{indent}"), applicability); } } @@ -779,7 +779,7 @@ impl DiagnosticExt for rustc_errors::Diagnostic { } } - self.span_suggestion(remove_span, msg, "", applicability); + self.span_suggestion(remove_span, msg.to_string(), "", applicability); } } From 0379c672b3016bfac84b5c4af6ee56b90f0a9730 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 29 May 2023 13:46:10 +0200 Subject: [PATCH 0844/1222] EarlyBinder::new -> EarlyBinder::bind --- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/eta_reduction.rs | 2 +- clippy_lints/src/methods/needless_collect.rs | 2 +- clippy_lints/src/methods/unnecessary_to_owned.rs | 4 ++-- clippy_utils/src/consts.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index a418a910ba8e..a1d2147cb496 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1219,7 +1219,7 @@ fn needless_borrow_impl_arg_position<'tcx>( return false; } - let predicate = EarlyBinder::new(predicate).subst(cx.tcx, &substs_with_referent_ty); + let predicate = EarlyBinder::bind(predicate).subst(cx.tcx, &substs_with_referent_ty); let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate); let infcx = cx.tcx.infer_ctxt().build(); infcx.predicate_must_hold_modulo_regions(&obligation) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index af2aac6ac0d0..c919b4de65de 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -243,7 +243,7 @@ fn get_ufcs_type_name<'tcx>(cx: &LateContext<'tcx>, method_def_id: DefId, substs | ty::Ref(..) | ty::Slice(_) | ty::Tuple(_) => { - format!("<{}>", EarlyBinder::new(ty).subst(cx.tcx, substs)) + format!("<{}>", EarlyBinder::bind(ty).subst(cx.tcx, substs)) }, _ => ty.to_string(), } diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index d4cc14bb8563..99f810c27cf8 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -241,7 +241,7 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) - && let proj_ty = cx.tcx.mk_projection(iter_item.def_id, substs) && let Ok(item_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, proj_ty) { - item_ty == EarlyBinder::new(search_ty).subst(cx.tcx, cx.typeck_results().node_substs(call_id)) + item_ty == EarlyBinder::bind(search_ty).subst(cx.tcx, cx.typeck_results().node_substs(call_id)) } else { false } diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index fdacfa49e92d..309d2157b76e 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -428,7 +428,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< })); if trait_predicates.any(|predicate| { - let predicate = EarlyBinder::new(predicate).subst(cx.tcx, new_subst); + let predicate = EarlyBinder::bind(predicate).subst(cx.tcx, new_subst); let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate); !cx.tcx.infer_ctxt().build().predicate_must_hold_modulo_regions(&obligation) }) { @@ -438,7 +438,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< let output_ty = fn_sig.output(); if output_ty.contains(*param_ty) { if let Ok(new_ty) = cx.tcx.try_subst_and_normalize_erasing_regions( - new_subst, cx.param_env, EarlyBinder::new(output_ty)) { + new_subst, cx.param_env, EarlyBinder::bind(output_ty)) { expr = parent_expr; ty = new_ty; continue; diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 843538e1eb2d..cc3183759ae7 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -462,7 +462,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let substs = if self.substs.is_empty() { substs } else { - EarlyBinder::new(substs).subst(self.lcx.tcx, self.substs) + EarlyBinder::bind(substs).subst(self.lcx.tcx, self.substs) }; let result = self From 88fc6af614501504f1d55019e7cc222917a80052 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sun, 14 May 2023 18:35:13 +0200 Subject: [PATCH 0845/1222] Drop uplifted clippy::cast_ref_to_mut --- clippy_lints/src/casts/cast_ref_to_mut.rs | 26 ------ clippy_lints/src/casts/mod.rs | 38 -------- clippy_lints/src/declared_lints.rs | 1 - clippy_lints/src/renamed_lints.rs | 1 + tests/ui/cast_ref_to_mut.rs | 31 ------- tests/ui/cast_ref_to_mut.stderr | 22 ----- tests/ui/rename.fixed | 2 + tests/ui/rename.rs | 2 + tests/ui/rename.stderr | 106 ++++++++++++---------- 9 files changed, 61 insertions(+), 168 deletions(-) delete mode 100644 clippy_lints/src/casts/cast_ref_to_mut.rs delete mode 100644 tests/ui/cast_ref_to_mut.rs delete mode 100644 tests/ui/cast_ref_to_mut.stderr diff --git a/clippy_lints/src/casts/cast_ref_to_mut.rs b/clippy_lints/src/casts/cast_ref_to_mut.rs deleted file mode 100644 index 15f2f81f4079..000000000000 --- a/clippy_lints/src/casts/cast_ref_to_mut.rs +++ /dev/null @@ -1,26 +0,0 @@ -use clippy_utils::diagnostics::span_lint; -use if_chain::if_chain; -use rustc_hir::{Expr, ExprKind, MutTy, Mutability, TyKind, UnOp}; -use rustc_lint::LateContext; -use rustc_middle::ty; - -use super::CAST_REF_TO_MUT; - -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::Unary(UnOp::Deref, e) = &expr.kind; - if let ExprKind::Cast(e, t) = &e.kind; - if let TyKind::Ptr(MutTy { mutbl: Mutability::Mut, .. }) = t.kind; - if let ExprKind::Cast(e, t) = &e.kind; - if let TyKind::Ptr(MutTy { mutbl: Mutability::Not, .. }) = t.kind; - if let ty::Ref(..) = cx.typeck_results().node_type(e.hir_id).kind(); - then { - span_lint( - cx, - CAST_REF_TO_MUT, - expr.span, - "casting `&T` to `&mut T` may cause undefined behavior, consider instead using an `UnsafeCell`", - ); - } - } -} diff --git a/clippy_lints/src/casts/mod.rs b/clippy_lints/src/casts/mod.rs index cfeb75eed3bb..0c175372aab8 100644 --- a/clippy_lints/src/casts/mod.rs +++ b/clippy_lints/src/casts/mod.rs @@ -9,7 +9,6 @@ mod cast_possible_truncation; mod cast_possible_wrap; mod cast_precision_loss; mod cast_ptr_alignment; -mod cast_ref_to_mut; mod cast_sign_loss; mod cast_slice_different_sizes; mod cast_slice_from_raw_parts; @@ -330,41 +329,6 @@ declare_clippy_lint! { "casting a function pointer to any integer type" } -declare_clippy_lint! { - /// ### What it does - /// Checks for casts of `&T` to `&mut T` anywhere in the code. - /// - /// ### Why is this bad? - /// It’s basically guaranteed to be undefined behavior. - /// `UnsafeCell` is the only way to obtain aliasable data that is considered - /// mutable. - /// - /// ### Example - /// ```rust,ignore - /// fn x(r: &i32) { - /// unsafe { - /// *(r as *const _ as *mut _) += 1; - /// } - /// } - /// ``` - /// - /// Instead consider using interior mutability types. - /// - /// ```rust - /// use std::cell::UnsafeCell; - /// - /// fn x(r: &UnsafeCell) { - /// unsafe { - /// *r.get() += 1; - /// } - /// } - /// ``` - #[clippy::version = "1.33.0"] - pub CAST_REF_TO_MUT, - correctness, - "a cast of reference to a mutable pointer" -} - declare_clippy_lint! { /// ### What it does /// Checks for expressions where a character literal is cast @@ -680,7 +644,6 @@ impl_lint_pass!(Casts => [ CAST_POSSIBLE_TRUNCATION, CAST_POSSIBLE_WRAP, CAST_LOSSLESS, - CAST_REF_TO_MUT, CAST_PTR_ALIGNMENT, CAST_SLICE_DIFFERENT_SIZES, UNNECESSARY_CAST, @@ -747,7 +710,6 @@ impl<'tcx> LateLintPass<'tcx> for Casts { } } - cast_ref_to_mut::check(cx, expr); cast_ptr_alignment::check(cx, expr); char_lit_as_u8::check(cx, expr); ptr_as_ptr::check(cx, expr, &self.msrv); diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 0ae95b045e03..212e809d4c56 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -81,7 +81,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::casts::CAST_POSSIBLE_WRAP_INFO, crate::casts::CAST_PRECISION_LOSS_INFO, crate::casts::CAST_PTR_ALIGNMENT_INFO, - crate::casts::CAST_REF_TO_MUT_INFO, crate::casts::CAST_SIGN_LOSS_INFO, crate::casts::CAST_SLICE_DIFFERENT_SIZES_INFO, crate::casts::CAST_SLICE_FROM_RAW_PARTS_INFO, diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index 7c2a100efdac..4cb418300233 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -31,6 +31,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::stutter", "clippy::module_name_repetitions"), ("clippy::to_string_in_display", "clippy::recursive_format_impl"), ("clippy::zero_width_space", "clippy::invisible_characters"), + ("clippy::cast_ref_to_mut", "cast_ref_to_mut"), ("clippy::clone_double_ref", "suspicious_double_ref_op"), ("clippy::drop_bounds", "drop_bounds"), ("clippy::drop_copy", "dropping_copy_types"), diff --git a/tests/ui/cast_ref_to_mut.rs b/tests/ui/cast_ref_to_mut.rs deleted file mode 100644 index c48a734ba32c..000000000000 --- a/tests/ui/cast_ref_to_mut.rs +++ /dev/null @@ -1,31 +0,0 @@ -#![warn(clippy::cast_ref_to_mut)] -#![allow(clippy::no_effect, clippy::borrow_as_ptr)] - -extern "C" { - // N.B., mutability can be easily incorrect in FFI calls -- as - // in C, the default is mutable pointers. - fn ffi(c: *mut u8); - fn int_ffi(c: *mut i32); -} - -fn main() { - let s = String::from("Hello"); - let a = &s; - unsafe { - let num = &3i32; - let mut_num = &mut 3i32; - // Should be warned against - (*(a as *const _ as *mut String)).push_str(" world"); - *(a as *const _ as *mut _) = String::from("Replaced"); - *(a as *const _ as *mut String) += " world"; - // Shouldn't be warned against - println!("{}", *(num as *const _ as *const i16)); - println!("{}", *(mut_num as *mut _ as *mut i16)); - ffi(a.as_ptr() as *mut _); - int_ffi(num as *const _ as *mut _); - int_ffi(&3 as *const _ as *mut _); - let mut value = 3; - let value: *const i32 = &mut value; - *(value as *const i16 as *mut i16) = 42; - } -} diff --git a/tests/ui/cast_ref_to_mut.stderr b/tests/ui/cast_ref_to_mut.stderr deleted file mode 100644 index aacd99437d9f..000000000000 --- a/tests/ui/cast_ref_to_mut.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: casting `&T` to `&mut T` may cause undefined behavior, consider instead using an `UnsafeCell` - --> $DIR/cast_ref_to_mut.rs:18:9 - | -LL | (*(a as *const _ as *mut String)).push_str(" world"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::cast-ref-to-mut` implied by `-D warnings` - -error: casting `&T` to `&mut T` may cause undefined behavior, consider instead using an `UnsafeCell` - --> $DIR/cast_ref_to_mut.rs:19:9 - | -LL | *(a as *const _ as *mut _) = String::from("Replaced"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: casting `&T` to `&mut T` may cause undefined behavior, consider instead using an `UnsafeCell` - --> $DIR/cast_ref_to_mut.rs:20:9 - | -LL | *(a as *const _ as *mut String) += " world"; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index 53ac65473b82..f7854b89ee4e 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -29,6 +29,7 @@ #![allow(clippy::recursive_format_impl)] #![allow(clippy::invisible_characters)] #![allow(suspicious_double_ref_op)] +#![allow(cast_ref_to_mut)] #![allow(drop_bounds)] #![allow(dropping_copy_types)] #![allow(dropping_references)] @@ -76,6 +77,7 @@ #![warn(clippy::module_name_repetitions)] #![warn(clippy::recursive_format_impl)] #![warn(clippy::invisible_characters)] +#![warn(cast_ref_to_mut)] #![warn(suspicious_double_ref_op)] #![warn(drop_bounds)] #![warn(dropping_copy_types)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index 722c0b3eb275..fa347d395ef5 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -29,6 +29,7 @@ #![allow(clippy::recursive_format_impl)] #![allow(clippy::invisible_characters)] #![allow(suspicious_double_ref_op)] +#![allow(cast_ref_to_mut)] #![allow(drop_bounds)] #![allow(dropping_copy_types)] #![allow(dropping_references)] @@ -76,6 +77,7 @@ #![warn(clippy::stutter)] #![warn(clippy::to_string_in_display)] #![warn(clippy::zero_width_space)] +#![warn(clippy::cast_ref_to_mut)] #![warn(clippy::clone_double_ref)] #![warn(clippy::drop_bounds)] #![warn(clippy::drop_copy)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 1ff839176602..9dffe51e5d7d 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> $DIR/rename.rs:50:9 + --> $DIR/rename.rs:51:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -7,292 +7,298 @@ LL | #![warn(clippy::almost_complete_letter_range)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> $DIR/rename.rs:51:9 + --> $DIR/rename.rs:52:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:52:9 + --> $DIR/rename.rs:53:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:53:9 + --> $DIR/rename.rs:54:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> $DIR/rename.rs:54:9 + --> $DIR/rename.rs:55:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:55:9 + --> $DIR/rename.rs:56:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:56:9 + --> $DIR/rename.rs:57:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> $DIR/rename.rs:57:9 + --> $DIR/rename.rs:58:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> $DIR/rename.rs:58:9 + --> $DIR/rename.rs:59:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> $DIR/rename.rs:59:9 + --> $DIR/rename.rs:60:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> $DIR/rename.rs:60:9 + --> $DIR/rename.rs:61:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> $DIR/rename.rs:61:9 + --> $DIR/rename.rs:62:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> $DIR/rename.rs:62:9 + --> $DIR/rename.rs:63:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::integer_arithmetic` has been renamed to `clippy::arithmetic_side_effects` - --> $DIR/rename.rs:63:9 + --> $DIR/rename.rs:64:9 | LL | #![warn(clippy::integer_arithmetic)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::arithmetic_side_effects` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:64:9 + --> $DIR/rename.rs:65:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:65:9 + --> $DIR/rename.rs:66:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:66:9 + --> $DIR/rename.rs:67:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:67:9 + --> $DIR/rename.rs:68:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:69:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:79:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` +error: lint `clippy::cast_ref_to_mut` has been renamed to `cast_ref_to_mut` + --> $DIR/rename.rs:80:9 + | +LL | #![warn(clippy::cast_ref_to_mut)] + | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `cast_ref_to_mut` + error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::clone_double_ref)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` error: lint `clippy::drop_copy` has been renamed to `dropping_copy_types` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:83:9 | LL | #![warn(clippy::drop_copy)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `dropping_copy_types` error: lint `clippy::drop_ref` has been renamed to `dropping_references` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::drop_ref)] | ^^^^^^^^^^^^^^^^ help: use the new name: `dropping_references` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:84:9 + --> $DIR/rename.rs:86:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:85:9 + --> $DIR/rename.rs:87:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::forget_copy` has been renamed to `forgetting_copy_types` - --> $DIR/rename.rs:86:9 + --> $DIR/rename.rs:88:9 | LL | #![warn(clippy::forget_copy)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_copy_types` error: lint `clippy::forget_ref` has been renamed to `forgetting_references` - --> $DIR/rename.rs:87:9 + --> $DIR/rename.rs:89:9 | LL | #![warn(clippy::forget_ref)] | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:88:9 + --> $DIR/rename.rs:90:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:89:9 + --> $DIR/rename.rs:91:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:90:9 + --> $DIR/rename.rs:92:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::invalid_utf8_in_unchecked` has been renamed to `invalid_from_utf8_unchecked` - --> $DIR/rename.rs:91:9 + --> $DIR/rename.rs:93:9 | LL | #![warn(clippy::invalid_utf8_in_unchecked)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_from_utf8_unchecked` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:92:9 + --> $DIR/rename.rs:94:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:93:9 + --> $DIR/rename.rs:95:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:94:9 + --> $DIR/rename.rs:96:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:95:9 + --> $DIR/rename.rs:97:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:96:9 + --> $DIR/rename.rs:98:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:97:9 + --> $DIR/rename.rs:99:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:98:9 + --> $DIR/rename.rs:100:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 49 previous errors +error: aborting due to 50 previous errors From 413cd145cec63c21554f7842f3f11f3620845e2c Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Thu, 1 Jun 2023 06:14:06 +0000 Subject: [PATCH 0846/1222] Rename `impl_defaultness` to `defaultness` --- clippy_lints/src/missing_inline.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 5a459548153a..a41d5a9ce8d2 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { match tit_.kind { hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => {}, hir::TraitItemKind::Fn(..) => { - if cx.tcx.impl_defaultness(tit.id.owner_id).has_value() { + if cx.tcx.defaultness(tit.id.owner_id).has_value() { // trait method with default body needs inline in case // an impl is not provided let desc = "a default trait method"; From f67dcf5832fa7e62b09a72289bc40c1a81c5a232 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 17 May 2023 10:30:14 +0000 Subject: [PATCH 0847/1222] Use translatable diagnostics in `rustc_const_eval` --- tests/ui/modulo_one.stderr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ui/modulo_one.stderr b/tests/ui/modulo_one.stderr index 04ecdef5e994..83a76f81d4e7 100644 --- a/tests/ui/modulo_one.stderr +++ b/tests/ui/modulo_one.stderr @@ -2,7 +2,7 @@ error: this operation will panic at runtime --> $DIR/modulo_one.rs:11:5 | LL | i32::MIN % (-1); // also caught by rustc - | ^^^^^^^^^^^^^^^ attempt to compute the remainder of `i32::MIN % -1_i32`, which would overflow + | ^^^^^^^^^^^^^^^ attempt to compute `i32::MIN % -1_i32`, which would overflow | = note: `#[deny(unconditional_panic)]` on by default @@ -10,13 +10,13 @@ error: this operation will panic at runtime --> $DIR/modulo_one.rs:21:5 | LL | INT_MIN % NEG_ONE; // also caught by rustc - | ^^^^^^^^^^^^^^^^^ attempt to compute the remainder of `i64::MIN % -1_i64`, which would overflow + | ^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow error: this operation will panic at runtime --> $DIR/modulo_one.rs:22:5 | LL | INT_MIN % STATIC_NEG_ONE; // ONLY caught by rustc - | ^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute the remainder of `i64::MIN % -1_i64`, which would overflow + | ^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow error: any number modulo 1 will be 0 --> $DIR/modulo_one.rs:8:5 From ae9147442fd71ceac1ac125ebf11429e8b416082 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 17 May 2023 04:05:46 +0000 Subject: [PATCH 0848/1222] Implement custom diagnostic for ConstParamTy --- tests/ui/same_functions_in_if_condition.rs | 4 +++- .../ui/same_functions_in_if_condition.stderr | 24 +++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/tests/ui/same_functions_in_if_condition.rs b/tests/ui/same_functions_in_if_condition.rs index aea1507cc5bd..08916398cbb2 100644 --- a/tests/ui/same_functions_in_if_condition.rs +++ b/tests/ui/same_functions_in_if_condition.rs @@ -10,6 +10,8 @@ clippy::uninlined_format_args )] +use std::marker::ConstParamTy; + fn function() -> bool { true } @@ -96,7 +98,7 @@ fn main() { }; println!("{}", os); - #[derive(PartialEq, Eq)] + #[derive(PartialEq, Eq, ConstParamTy)] enum E { A, B, diff --git a/tests/ui/same_functions_in_if_condition.stderr b/tests/ui/same_functions_in_if_condition.stderr index aade3b1fa457..6aacc73b90dc 100644 --- a/tests/ui/same_functions_in_if_condition.stderr +++ b/tests/ui/same_functions_in_if_condition.stderr @@ -1,11 +1,11 @@ error: this `if` has the same function call as a previous `if` - --> $DIR/same_functions_in_if_condition.rs:37:15 + --> $DIR/same_functions_in_if_condition.rs:39:15 | LL | } else if function() { | ^^^^^^^^^^ | note: same as this - --> $DIR/same_functions_in_if_condition.rs:36:8 + --> $DIR/same_functions_in_if_condition.rs:38:8 | LL | if function() { | ^^^^^^^^^^ @@ -16,61 +16,61 @@ LL | #![deny(clippy::same_functions_in_if_condition)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `if` has the same function call as a previous `if` - --> $DIR/same_functions_in_if_condition.rs:42:15 + --> $DIR/same_functions_in_if_condition.rs:44:15 | LL | } else if fn_arg(a) { | ^^^^^^^^^ | note: same as this - --> $DIR/same_functions_in_if_condition.rs:41:8 + --> $DIR/same_functions_in_if_condition.rs:43:8 | LL | if fn_arg(a) { | ^^^^^^^^^ error: this `if` has the same function call as a previous `if` - --> $DIR/same_functions_in_if_condition.rs:47:15 + --> $DIR/same_functions_in_if_condition.rs:49:15 | LL | } else if obj.method() { | ^^^^^^^^^^^^ | note: same as this - --> $DIR/same_functions_in_if_condition.rs:46:8 + --> $DIR/same_functions_in_if_condition.rs:48:8 | LL | if obj.method() { | ^^^^^^^^^^^^ error: this `if` has the same function call as a previous `if` - --> $DIR/same_functions_in_if_condition.rs:52:15 + --> $DIR/same_functions_in_if_condition.rs:54:15 | LL | } else if obj.method_arg(a) { | ^^^^^^^^^^^^^^^^^ | note: same as this - --> $DIR/same_functions_in_if_condition.rs:51:8 + --> $DIR/same_functions_in_if_condition.rs:53:8 | LL | if obj.method_arg(a) { | ^^^^^^^^^^^^^^^^^ error: this `if` has the same function call as a previous `if` - --> $DIR/same_functions_in_if_condition.rs:59:15 + --> $DIR/same_functions_in_if_condition.rs:61:15 | LL | } else if v.pop().is_none() { | ^^^^^^^^^^^^^^^^^ | note: same as this - --> $DIR/same_functions_in_if_condition.rs:57:8 + --> $DIR/same_functions_in_if_condition.rs:59:8 | LL | if v.pop().is_none() { | ^^^^^^^^^^^^^^^^^ error: this `if` has the same function call as a previous `if` - --> $DIR/same_functions_in_if_condition.rs:64:15 + --> $DIR/same_functions_in_if_condition.rs:66:15 | LL | } else if v.len() == 42 { | ^^^^^^^^^^^^^ | note: same as this - --> $DIR/same_functions_in_if_condition.rs:62:8 + --> $DIR/same_functions_in_if_condition.rs:64:8 | LL | if v.len() == 42 { | ^^^^^^^^^^^^^ From 4c4e5544990cc2318e02cc3029efabe6e551e7a1 Mon Sep 17 00:00:00 2001 From: Andrew Xie Date: Thu, 8 Jun 2023 00:38:50 -0400 Subject: [PATCH 0849/1222] Removed stable/unstable sort arg from into_sorted_stable_ord, fixed a few misc issues, added collect to UnordItems --- clippy_lints/src/wildcard_imports.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index b6e4cd22789f..2a3d86988bb0 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -160,7 +160,7 @@ impl LateLintPass<'_> for WildcardImports { ) }; - let mut imports = used_imports.items().map(ToString::to_string).into_sorted_stable_ord(false); + let mut imports = used_imports.items().map(ToString::to_string).into_sorted_stable_ord(); let imports_string = if imports.len() == 1 { imports.pop().unwrap() } else if braced_glob { From 99733f8392eff747591c326276b734b5d6b5898b Mon Sep 17 00:00:00 2001 From: Andrew Xie Date: Thu, 8 Jun 2023 00:40:29 -0400 Subject: [PATCH 0850/1222] fixup! Removed stable/unstable sort arg from into_sorted_stable_ord, fixed a few misc issues, added collect to UnordItems --- clippy_lints/src/wildcard_imports.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 2a3d86988bb0..b6e4cd22789f 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -160,7 +160,7 @@ impl LateLintPass<'_> for WildcardImports { ) }; - let mut imports = used_imports.items().map(ToString::to_string).into_sorted_stable_ord(); + let mut imports = used_imports.items().map(ToString::to_string).into_sorted_stable_ord(false); let imports_string = if imports.len() == 1 { imports.pop().unwrap() } else if braced_glob { From b8a39bd0354f4aa89794e75a8b0bbc16ffd6d12d Mon Sep 17 00:00:00 2001 From: Andrew Xie Date: Thu, 8 Jun 2023 01:05:38 -0400 Subject: [PATCH 0851/1222] Whoops, submodule change was actually valid - undoing fixup --- clippy_lints/src/wildcard_imports.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index b6e4cd22789f..2a3d86988bb0 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -160,7 +160,7 @@ impl LateLintPass<'_> for WildcardImports { ) }; - let mut imports = used_imports.items().map(ToString::to_string).into_sorted_stable_ord(false); + let mut imports = used_imports.items().map(ToString::to_string).into_sorted_stable_ord(); let imports_string = if imports.len() == 1 { imports.pop().unwrap() } else if braced_glob { From a6776499221c44c4e0b080f8a5b7c073ebb4bd44 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 12 May 2023 20:02:01 +0200 Subject: [PATCH 0852/1222] Drop uplifted clippy::undropped_manually_drops --- clippy_lints/src/declared_lints.rs | 1 - clippy_lints/src/drop_forget_ref.rs | 44 +-------- clippy_lints/src/renamed_lints.rs | 1 + tests/ui/rename.fixed | 2 + tests/ui/rename.rs | 2 + tests/ui/rename.stderr | 108 ++++++++++++----------- tests/ui/undropped_manually_drops.rs | 26 ------ tests/ui/undropped_manually_drops.stderr | 19 ---- 8 files changed, 64 insertions(+), 139 deletions(-) delete mode 100644 tests/ui/undropped_manually_drops.rs delete mode 100644 tests/ui/undropped_manually_drops.stderr diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 15ff8be0fd94..6270d2613132 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -136,7 +136,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::double_parens::DOUBLE_PARENS_INFO, crate::drop_forget_ref::DROP_NON_DROP_INFO, crate::drop_forget_ref::FORGET_NON_DROP_INFO, - crate::drop_forget_ref::UNDROPPED_MANUALLY_DROPS_INFO, crate::duplicate_mod::DUPLICATE_MOD_INFO, crate::else_if_without_else::ELSE_IF_WITHOUT_ELSE_INFO, crate::empty_drop::EMPTY_DROP_INFO, diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 9c60edb17941..7a4b9a87aeb4 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -1,4 +1,4 @@ -use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note}; +use clippy_utils::diagnostics::span_lint_and_note; use clippy_utils::get_parent_node; use clippy_utils::is_must_use_func_call; use clippy_utils::ty::{is_copy, is_must_use_ty, is_type_lang_item}; @@ -47,35 +47,6 @@ declare_clippy_lint! { "call to `std::mem::forget` with a value which does not implement `Drop`" } -declare_clippy_lint! { - /// ### What it does - /// Prevents the safe `std::mem::drop` function from being called on `std::mem::ManuallyDrop`. - /// - /// ### Why is this bad? - /// The safe `drop` function does not drop the inner value of a `ManuallyDrop`. - /// - /// ### Known problems - /// Does not catch cases if the user binds `std::mem::drop` - /// to a different name and calls it that way. - /// - /// ### Example - /// ```rust - /// struct S; - /// drop(std::mem::ManuallyDrop::new(S)); - /// ``` - /// Use instead: - /// ```rust - /// struct S; - /// unsafe { - /// std::mem::ManuallyDrop::drop(&mut std::mem::ManuallyDrop::new(S)); - /// } - /// ``` - #[clippy::version = "1.49.0"] - pub UNDROPPED_MANUALLY_DROPS, - correctness, - "use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value" -} - const DROP_NON_DROP_SUMMARY: &str = "call to `std::mem::drop` with a value that does not implement `Drop`. \ Dropping such a type only extends its contained lifetimes"; const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value that does not implement `Drop`. \ @@ -84,7 +55,6 @@ const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value t declare_lint_pass!(DropForgetRef => [ DROP_NON_DROP, FORGET_NON_DROP, - UNDROPPED_MANUALLY_DROPS ]); impl<'tcx> LateLintPass<'tcx> for DropForgetRef { @@ -103,17 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { sym::mem_forget if arg_ty.is_ref() => return, sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return, sym::mem_forget if is_copy => return, - sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => { - span_lint_and_help( - cx, - UNDROPPED_MANUALLY_DROPS, - expr.span, - "the inner value of this ManuallyDrop will not be dropped", - None, - "to drop a `ManuallyDrop`, use std::mem::ManuallyDrop::drop", - ); - return; - } + sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => return, sym::mem_drop if !(arg_ty.needs_drop(cx.tcx, cx.param_env) || is_must_use_func_call(cx, arg) diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index 4cb418300233..f76fa76f0764 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -50,6 +50,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::panic_params", "non_fmt_panics"), ("clippy::positional_named_format_parameters", "named_arguments_used_positionally"), ("clippy::temporary_cstring_as_ptr", "temporary_cstring_as_ptr"), + ("clippy::undropped_manually_drops", "undropped_manually_drops"), ("clippy::unknown_clippy_lints", "unknown_lints"), ("clippy::unused_label", "unused_labels"), ]; diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index 30f2bfc8c1a9..954145fc4e64 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -47,6 +47,7 @@ #![allow(named_arguments_used_positionally)] #![allow(suspicious_double_ref_op)] #![allow(temporary_cstring_as_ptr)] +#![allow(undropped_manually_drops)] #![allow(unknown_lints)] #![allow(unused_labels)] #![warn(clippy::almost_complete_range)] @@ -97,6 +98,7 @@ #![warn(non_fmt_panics)] #![warn(named_arguments_used_positionally)] #![warn(temporary_cstring_as_ptr)] +#![warn(undropped_manually_drops)] #![warn(unknown_lints)] #![warn(unused_labels)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index 3939914d4224..067a3109afb9 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -47,6 +47,7 @@ #![allow(named_arguments_used_positionally)] #![allow(suspicious_double_ref_op)] #![allow(temporary_cstring_as_ptr)] +#![allow(undropped_manually_drops)] #![allow(unknown_lints)] #![allow(unused_labels)] #![warn(clippy::almost_complete_letter_range)] @@ -97,6 +98,7 @@ #![warn(clippy::panic_params)] #![warn(clippy::positional_named_format_parameters)] #![warn(clippy::temporary_cstring_as_ptr)] +#![warn(clippy::undropped_manually_drops)] #![warn(clippy::unknown_clippy_lints)] #![warn(clippy::unused_label)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 7290cf32e5b6..1819d108c574 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> $DIR/rename.rs:52:9 + --> $DIR/rename.rs:53:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -7,298 +7,304 @@ LL | #![warn(clippy::almost_complete_letter_range)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> $DIR/rename.rs:53:9 + --> $DIR/rename.rs:54:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:54:9 + --> $DIR/rename.rs:55:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:55:9 + --> $DIR/rename.rs:56:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> $DIR/rename.rs:56:9 + --> $DIR/rename.rs:57:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:57:9 + --> $DIR/rename.rs:58:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:58:9 + --> $DIR/rename.rs:59:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> $DIR/rename.rs:59:9 + --> $DIR/rename.rs:60:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> $DIR/rename.rs:60:9 + --> $DIR/rename.rs:61:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> $DIR/rename.rs:61:9 + --> $DIR/rename.rs:62:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> $DIR/rename.rs:62:9 + --> $DIR/rename.rs:63:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> $DIR/rename.rs:63:9 + --> $DIR/rename.rs:64:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> $DIR/rename.rs:64:9 + --> $DIR/rename.rs:65:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::integer_arithmetic` has been renamed to `clippy::arithmetic_side_effects` - --> $DIR/rename.rs:65:9 + --> $DIR/rename.rs:66:9 | LL | #![warn(clippy::integer_arithmetic)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::arithmetic_side_effects` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:66:9 + --> $DIR/rename.rs:67:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:67:9 + --> $DIR/rename.rs:68:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:69:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:79:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:80:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::cast_ref_to_mut` has been renamed to `cast_ref_to_mut` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::cast_ref_to_mut)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `cast_ref_to_mut` error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:83:9 | LL | #![warn(clippy::clone_double_ref)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` error: lint `clippy::drop_copy` has been renamed to `dropping_copy_types` - --> $DIR/rename.rs:84:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::drop_copy)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `dropping_copy_types` error: lint `clippy::drop_ref` has been renamed to `dropping_references` - --> $DIR/rename.rs:85:9 + --> $DIR/rename.rs:86:9 | LL | #![warn(clippy::drop_ref)] | ^^^^^^^^^^^^^^^^ help: use the new name: `dropping_references` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:86:9 + --> $DIR/rename.rs:87:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:87:9 + --> $DIR/rename.rs:88:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:88:9 + --> $DIR/rename.rs:89:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::forget_copy` has been renamed to `forgetting_copy_types` - --> $DIR/rename.rs:89:9 + --> $DIR/rename.rs:90:9 | LL | #![warn(clippy::forget_copy)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_copy_types` error: lint `clippy::forget_ref` has been renamed to `forgetting_references` - --> $DIR/rename.rs:90:9 + --> $DIR/rename.rs:91:9 | LL | #![warn(clippy::forget_ref)] | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:91:9 + --> $DIR/rename.rs:92:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:92:9 + --> $DIR/rename.rs:93:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:93:9 + --> $DIR/rename.rs:94:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::invalid_utf8_in_unchecked` has been renamed to `invalid_from_utf8_unchecked` - --> $DIR/rename.rs:94:9 + --> $DIR/rename.rs:95:9 | LL | #![warn(clippy::invalid_utf8_in_unchecked)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_from_utf8_unchecked` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:95:9 + --> $DIR/rename.rs:96:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:96:9 + --> $DIR/rename.rs:97:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:97:9 + --> $DIR/rename.rs:98:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:98:9 + --> $DIR/rename.rs:99:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:99:9 + --> $DIR/rename.rs:100:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` +error: lint `clippy::undropped_manually_drops` has been renamed to `undropped_manually_drops` + --> $DIR/rename.rs:101:9 + | +LL | #![warn(clippy::undropped_manually_drops)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `undropped_manually_drops` + error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:100:9 + --> $DIR/rename.rs:102:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:101:9 + --> $DIR/rename.rs:103:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 50 previous errors +error: aborting due to 51 previous errors diff --git a/tests/ui/undropped_manually_drops.rs b/tests/ui/undropped_manually_drops.rs deleted file mode 100644 index f4cfc92e1cd0..000000000000 --- a/tests/ui/undropped_manually_drops.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![warn(clippy::undropped_manually_drops)] - -struct S; - -fn main() { - let f = std::mem::drop; - let g = std::mem::ManuallyDrop::drop; - let mut manual1 = std::mem::ManuallyDrop::new(S); - let mut manual2 = std::mem::ManuallyDrop::new(S); - let mut manual3 = std::mem::ManuallyDrop::new(S); - let mut manual4 = std::mem::ManuallyDrop::new(S); - - // These lines will not drop `S` and should be linted - drop(std::mem::ManuallyDrop::new(S)); - drop(manual1); - - // FIXME: this line is not linted, though it should be - f(manual2); - - // These lines will drop `S` and should be okay. - unsafe { - std::mem::ManuallyDrop::drop(&mut std::mem::ManuallyDrop::new(S)); - std::mem::ManuallyDrop::drop(&mut manual3); - g(&mut manual4); - } -} diff --git a/tests/ui/undropped_manually_drops.stderr b/tests/ui/undropped_manually_drops.stderr deleted file mode 100644 index 92611a9b7df4..000000000000 --- a/tests/ui/undropped_manually_drops.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: the inner value of this ManuallyDrop will not be dropped - --> $DIR/undropped_manually_drops.rs:14:5 - | -LL | drop(std::mem::ManuallyDrop::new(S)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: to drop a `ManuallyDrop`, use std::mem::ManuallyDrop::drop - = note: `-D clippy::undropped-manually-drops` implied by `-D warnings` - -error: the inner value of this ManuallyDrop will not be dropped - --> $DIR/undropped_manually_drops.rs:15:5 - | -LL | drop(manual1); - | ^^^^^^^^^^^^^ - | - = help: to drop a `ManuallyDrop`, use std::mem::ManuallyDrop::drop - -error: aborting due to 2 previous errors - From 226fc69b8e1ab8dbfd7d5b61da47cd5dc8be7f83 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sun, 21 May 2023 12:12:12 +0200 Subject: [PATCH 0853/1222] Drop uplifted `clippy:cmp_nan` --- clippy_lints/src/declared_lints.rs | 1 - clippy_lints/src/operators/cmp_nan.rs | 30 ------ clippy_lints/src/operators/mod.rs | 28 ----- clippy_lints/src/renamed_lints.rs | 1 + tests/ui/cmp_nan.rs | 34 ------ tests/ui/cmp_nan.stderr | 148 -------------------------- tests/ui/crashes/mut_mut_macro.rs | 5 +- tests/ui/rename.fixed | 2 + tests/ui/rename.rs | 2 + tests/ui/rename.stderr | 110 ++++++++++--------- tests/ui/unknown_clippy_lints.fixed | 2 +- tests/ui/unknown_clippy_lints.rs | 2 +- tests/ui/unknown_clippy_lints.stderr | 6 +- 13 files changed, 70 insertions(+), 301 deletions(-) delete mode 100644 clippy_lints/src/operators/cmp_nan.rs delete mode 100644 tests/ui/cmp_nan.rs delete mode 100644 tests/ui/cmp_nan.stderr diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 6270d2613132..f1d1355123ab 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -476,7 +476,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::operators::ARITHMETIC_SIDE_EFFECTS_INFO, crate::operators::ASSIGN_OP_PATTERN_INFO, crate::operators::BAD_BIT_MASK_INFO, - crate::operators::CMP_NAN_INFO, crate::operators::CMP_OWNED_INFO, crate::operators::DOUBLE_COMPARISONS_INFO, crate::operators::DURATION_SUBSEC_INFO, diff --git a/clippy_lints/src/operators/cmp_nan.rs b/clippy_lints/src/operators/cmp_nan.rs deleted file mode 100644 index e18064b7061b..000000000000 --- a/clippy_lints/src/operators/cmp_nan.rs +++ /dev/null @@ -1,30 +0,0 @@ -use clippy_utils::consts::{constant, Constant}; -use clippy_utils::diagnostics::span_lint; -use clippy_utils::in_constant; -use rustc_hir::{BinOpKind, Expr}; -use rustc_lint::LateContext; - -use super::CMP_NAN; - -pub(super) fn check(cx: &LateContext<'_>, e: &Expr<'_>, op: BinOpKind, lhs: &Expr<'_>, rhs: &Expr<'_>) { - if op.is_comparison() && !in_constant(cx, e.hir_id) && (is_nan(cx, lhs) || is_nan(cx, rhs)) { - span_lint( - cx, - CMP_NAN, - e.span, - "doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead", - ); - } -} - -fn is_nan(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { - if let Some(value) = constant(cx, cx.typeck_results(), e) { - match value { - Constant::F32(num) => num.is_nan(), - Constant::F64(num) => num.is_nan(), - _ => false, - } - } else { - false - } -} diff --git a/clippy_lints/src/operators/mod.rs b/clippy_lints/src/operators/mod.rs index d63a836e73d6..2cf15adda01a 100644 --- a/clippy_lints/src/operators/mod.rs +++ b/clippy_lints/src/operators/mod.rs @@ -1,7 +1,6 @@ mod absurd_extreme_comparisons; mod assign_op_pattern; mod bit_mask; -mod cmp_nan; mod cmp_owned; mod double_comparison; mod duration_subsec; @@ -485,31 +484,6 @@ declare_clippy_lint! { "integer division may cause loss of precision" } -declare_clippy_lint! { - /// ### What it does - /// Checks for comparisons to NaN. - /// - /// ### Why is this bad? - /// NaN does not compare meaningfully to anything – not - /// even itself – so those comparisons are simply wrong. - /// - /// ### Example - /// ```rust - /// # let x = 1.0; - /// if x == f32::NAN { } - /// ``` - /// - /// Use instead: - /// ```rust - /// # let x = 1.0f32; - /// if x.is_nan() { } - /// ``` - #[clippy::version = "pre 1.29.0"] - pub CMP_NAN, - correctness, - "comparisons to `NAN`, which will always return false, probably not intended" -} - declare_clippy_lint! { /// ### What it does /// Checks for conversions to owned values just for the sake @@ -775,7 +749,6 @@ impl_lint_pass!(Operators => [ FLOAT_EQUALITY_WITHOUT_ABS, IDENTITY_OP, INTEGER_DIVISION, - CMP_NAN, CMP_OWNED, FLOAT_CMP, FLOAT_CMP_CONST, @@ -816,7 +789,6 @@ impl<'tcx> LateLintPass<'tcx> for Operators { duration_subsec::check(cx, e, op.node, lhs, rhs); float_equality_without_abs::check(cx, e, op.node, lhs, rhs); integer_division::check(cx, e, op.node, lhs, rhs); - cmp_nan::check(cx, e, op.node, lhs, rhs); cmp_owned::check(cx, op.node, lhs, rhs); float_cmp::check(cx, e, op.node, lhs, rhs); modulo_one::check(cx, e, op.node, rhs); diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index f76fa76f0764..cbcd11debfd7 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -33,6 +33,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::zero_width_space", "clippy::invisible_characters"), ("clippy::cast_ref_to_mut", "cast_ref_to_mut"), ("clippy::clone_double_ref", "suspicious_double_ref_op"), + ("clippy::cmp_nan", "invalid_nan_comparisons"), ("clippy::drop_bounds", "drop_bounds"), ("clippy::drop_copy", "dropping_copy_types"), ("clippy::drop_ref", "dropping_references"), diff --git a/tests/ui/cmp_nan.rs b/tests/ui/cmp_nan.rs deleted file mode 100644 index 64ca52b010a7..000000000000 --- a/tests/ui/cmp_nan.rs +++ /dev/null @@ -1,34 +0,0 @@ -const NAN_F32: f32 = f32::NAN; -const NAN_F64: f64 = f64::NAN; - -#[warn(clippy::cmp_nan)] -#[allow(clippy::float_cmp, clippy::no_effect, clippy::unnecessary_operation)] -fn main() { - let x = 5f32; - x == f32::NAN; - x != f32::NAN; - x < f32::NAN; - x > f32::NAN; - x <= f32::NAN; - x >= f32::NAN; - x == NAN_F32; - x != NAN_F32; - x < NAN_F32; - x > NAN_F32; - x <= NAN_F32; - x >= NAN_F32; - - let y = 0f64; - y == f64::NAN; - y != f64::NAN; - y < f64::NAN; - y > f64::NAN; - y <= f64::NAN; - y >= f64::NAN; - y == NAN_F64; - y != NAN_F64; - y < NAN_F64; - y > NAN_F64; - y <= NAN_F64; - y >= NAN_F64; -} diff --git a/tests/ui/cmp_nan.stderr b/tests/ui/cmp_nan.stderr deleted file mode 100644 index 867516661a53..000000000000 --- a/tests/ui/cmp_nan.stderr +++ /dev/null @@ -1,148 +0,0 @@ -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:8:5 - | -LL | x == f32::NAN; - | ^^^^^^^^^^^^^ - | - = note: `-D clippy::cmp-nan` implied by `-D warnings` - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:9:5 - | -LL | x != f32::NAN; - | ^^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:10:5 - | -LL | x < f32::NAN; - | ^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:11:5 - | -LL | x > f32::NAN; - | ^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:12:5 - | -LL | x <= f32::NAN; - | ^^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:13:5 - | -LL | x >= f32::NAN; - | ^^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:14:5 - | -LL | x == NAN_F32; - | ^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:15:5 - | -LL | x != NAN_F32; - | ^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:16:5 - | -LL | x < NAN_F32; - | ^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:17:5 - | -LL | x > NAN_F32; - | ^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:18:5 - | -LL | x <= NAN_F32; - | ^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:19:5 - | -LL | x >= NAN_F32; - | ^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:22:5 - | -LL | y == f64::NAN; - | ^^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:23:5 - | -LL | y != f64::NAN; - | ^^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:24:5 - | -LL | y < f64::NAN; - | ^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:25:5 - | -LL | y > f64::NAN; - | ^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:26:5 - | -LL | y <= f64::NAN; - | ^^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:27:5 - | -LL | y >= f64::NAN; - | ^^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:28:5 - | -LL | y == NAN_F64; - | ^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:29:5 - | -LL | y != NAN_F64; - | ^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:30:5 - | -LL | y < NAN_F64; - | ^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:31:5 - | -LL | y > NAN_F64; - | ^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:32:5 - | -LL | y <= NAN_F64; - | ^^^^^^^^^^^^ - -error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead - --> $DIR/cmp_nan.rs:33:5 - | -LL | y >= NAN_F64; - | ^^^^^^^^^^^^ - -error: aborting due to 24 previous errors - diff --git a/tests/ui/crashes/mut_mut_macro.rs b/tests/ui/crashes/mut_mut_macro.rs index a238e7896fc6..92821b6ecbba 100644 --- a/tests/ui/crashes/mut_mut_macro.rs +++ b/tests/ui/crashes/mut_mut_macro.rs @@ -1,4 +1,4 @@ -#![deny(clippy::mut_mut, clippy::zero_ptr, clippy::cmp_nan)] +#![deny(clippy::mut_mut, clippy::zero_ptr)] #![allow(dead_code)] // FIXME: compiletest + extern crates doesn't work together. To make this test work, it would need @@ -8,13 +8,12 @@ // extern crate lazy_static; // use std::collections::HashMap; -/// ensure that we don't suggest `is_nan` and `is_null` inside constants +/// ensure that we don't suggest `is_null` inside constants /// FIXME: once const fn is stable, suggest these functions again in constants const BAA: *const i32 = 0 as *const i32; static mut BAR: *const i32 = BAA; static mut FOO: *const i32 = 0 as *const i32; -static mut BUH: bool = 42.0 < f32::NAN; #[allow(unused_variables, unused_mut)] fn main() { diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index 954145fc4e64..f1b25dc094ef 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -41,6 +41,7 @@ #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] #![allow(invalid_from_utf8_unchecked)] +#![allow(invalid_nan_comparisons)] #![allow(let_underscore_drop)] #![allow(enum_intrinsics_non_enums)] #![allow(non_fmt_panics)] @@ -55,6 +56,7 @@ #![warn(clippy::blocks_in_if_conditions)] #![warn(clippy::blocks_in_if_conditions)] #![warn(clippy::box_collection)] +#![warn(invalid_nan_comparisons)] #![warn(clippy::redundant_static_lifetimes)] #![warn(clippy::cognitive_complexity)] #![warn(clippy::derived_hash_with_manual_eq)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index 067a3109afb9..4af511c344c4 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -41,6 +41,7 @@ #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] #![allow(invalid_from_utf8_unchecked)] +#![allow(invalid_nan_comparisons)] #![allow(let_underscore_drop)] #![allow(enum_intrinsics_non_enums)] #![allow(non_fmt_panics)] @@ -55,6 +56,7 @@ #![warn(clippy::block_in_if_condition_expr)] #![warn(clippy::block_in_if_condition_stmt)] #![warn(clippy::box_vec)] +#![warn(clippy::cmp_nan)] #![warn(clippy::const_static_lifetime)] #![warn(clippy::cyclomatic_complexity)] #![warn(clippy::derive_hash_xor_eq)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 1819d108c574..156a8f96b502 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> $DIR/rename.rs:53:9 + --> $DIR/rename.rs:54:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -7,304 +7,310 @@ LL | #![warn(clippy::almost_complete_letter_range)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> $DIR/rename.rs:54:9 + --> $DIR/rename.rs:55:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:55:9 + --> $DIR/rename.rs:56:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:56:9 + --> $DIR/rename.rs:57:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> $DIR/rename.rs:57:9 + --> $DIR/rename.rs:58:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` +error: lint `clippy::cmp_nan` has been renamed to `invalid_nan_comparisons` + --> $DIR/rename.rs:59:9 + | +LL | #![warn(clippy::cmp_nan)] + | ^^^^^^^^^^^^^^^ help: use the new name: `invalid_nan_comparisons` + error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:58:9 + --> $DIR/rename.rs:60:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:59:9 + --> $DIR/rename.rs:61:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> $DIR/rename.rs:60:9 + --> $DIR/rename.rs:62:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> $DIR/rename.rs:61:9 + --> $DIR/rename.rs:63:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> $DIR/rename.rs:62:9 + --> $DIR/rename.rs:64:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> $DIR/rename.rs:63:9 + --> $DIR/rename.rs:65:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> $DIR/rename.rs:64:9 + --> $DIR/rename.rs:66:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> $DIR/rename.rs:65:9 + --> $DIR/rename.rs:67:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::integer_arithmetic` has been renamed to `clippy::arithmetic_side_effects` - --> $DIR/rename.rs:66:9 + --> $DIR/rename.rs:68:9 | LL | #![warn(clippy::integer_arithmetic)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::arithmetic_side_effects` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:67:9 + --> $DIR/rename.rs:69:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:79:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:80:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:83:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::cast_ref_to_mut` has been renamed to `cast_ref_to_mut` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::cast_ref_to_mut)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `cast_ref_to_mut` error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::clone_double_ref)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:84:9 + --> $DIR/rename.rs:86:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` error: lint `clippy::drop_copy` has been renamed to `dropping_copy_types` - --> $DIR/rename.rs:85:9 + --> $DIR/rename.rs:87:9 | LL | #![warn(clippy::drop_copy)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `dropping_copy_types` error: lint `clippy::drop_ref` has been renamed to `dropping_references` - --> $DIR/rename.rs:86:9 + --> $DIR/rename.rs:88:9 | LL | #![warn(clippy::drop_ref)] | ^^^^^^^^^^^^^^^^ help: use the new name: `dropping_references` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:87:9 + --> $DIR/rename.rs:89:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:88:9 + --> $DIR/rename.rs:90:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:89:9 + --> $DIR/rename.rs:91:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::forget_copy` has been renamed to `forgetting_copy_types` - --> $DIR/rename.rs:90:9 + --> $DIR/rename.rs:92:9 | LL | #![warn(clippy::forget_copy)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_copy_types` error: lint `clippy::forget_ref` has been renamed to `forgetting_references` - --> $DIR/rename.rs:91:9 + --> $DIR/rename.rs:93:9 | LL | #![warn(clippy::forget_ref)] | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:92:9 + --> $DIR/rename.rs:94:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:93:9 + --> $DIR/rename.rs:95:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:94:9 + --> $DIR/rename.rs:96:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::invalid_utf8_in_unchecked` has been renamed to `invalid_from_utf8_unchecked` - --> $DIR/rename.rs:95:9 + --> $DIR/rename.rs:97:9 | LL | #![warn(clippy::invalid_utf8_in_unchecked)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_from_utf8_unchecked` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:96:9 + --> $DIR/rename.rs:98:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:97:9 + --> $DIR/rename.rs:99:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:98:9 + --> $DIR/rename.rs:100:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:99:9 + --> $DIR/rename.rs:101:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:100:9 + --> $DIR/rename.rs:102:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::undropped_manually_drops` has been renamed to `undropped_manually_drops` - --> $DIR/rename.rs:101:9 + --> $DIR/rename.rs:103:9 | LL | #![warn(clippy::undropped_manually_drops)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `undropped_manually_drops` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:102:9 + --> $DIR/rename.rs:104:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:103:9 + --> $DIR/rename.rs:105:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 51 previous errors +error: aborting due to 52 previous errors diff --git a/tests/ui/unknown_clippy_lints.fixed b/tests/ui/unknown_clippy_lints.fixed index 49c0e4dc7eb1..debc7e152e73 100644 --- a/tests/ui/unknown_clippy_lints.fixed +++ b/tests/ui/unknown_clippy_lints.fixed @@ -3,7 +3,7 @@ #![warn(clippy::pedantic)] // Should suggest lowercase #![allow(clippy::all)] -#![warn(clippy::cmp_nan)] +#![warn(clippy::cmp_owned)] // Should suggest similar clippy lint name #[warn(clippy::if_not_else)] diff --git a/tests/ui/unknown_clippy_lints.rs b/tests/ui/unknown_clippy_lints.rs index b60042923ea1..16140fd10791 100644 --- a/tests/ui/unknown_clippy_lints.rs +++ b/tests/ui/unknown_clippy_lints.rs @@ -3,7 +3,7 @@ #![warn(clippy::pedantic)] // Should suggest lowercase #![allow(clippy::All)] -#![warn(clippy::CMP_NAN)] +#![warn(clippy::CMP_OWNED)] // Should suggest similar clippy lint name #[warn(clippy::if_not_els)] diff --git a/tests/ui/unknown_clippy_lints.stderr b/tests/ui/unknown_clippy_lints.stderr index 584c428932fe..880673eef3e4 100644 --- a/tests/ui/unknown_clippy_lints.stderr +++ b/tests/ui/unknown_clippy_lints.stderr @@ -6,11 +6,11 @@ LL | #![allow(clippy::All)] | = note: `-D unknown-lints` implied by `-D warnings` -error: unknown lint: `clippy::CMP_NAN` +error: unknown lint: `clippy::CMP_OWNED` --> $DIR/unknown_clippy_lints.rs:6:9 | -LL | #![warn(clippy::CMP_NAN)] - | ^^^^^^^^^^^^^^^ help: did you mean: `clippy::cmp_nan` +LL | #![warn(clippy::CMP_OWNED)] + | ^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::cmp_owned` error: unknown lint: `clippy::if_not_els` --> $DIR/unknown_clippy_lints.rs:9:8 From 3b164661b9fb435d26c0bf30a9a7bff949a9f8eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Sun, 11 Jun 2023 23:44:28 +0800 Subject: [PATCH 0854/1222] Extend `unused_must_use` to cover block exprs --- tests/ui/transmute_ptr_to_ref.fixed | 3 +- tests/ui/transmute_ptr_to_ref.rs | 3 +- tests/ui/transmute_ptr_to_ref.stderr | 48 ++++++++++++++-------------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/tests/ui/transmute_ptr_to_ref.fixed b/tests/ui/transmute_ptr_to_ref.fixed index 575dadde9063..ac55ab5a8e2d 100644 --- a/tests/ui/transmute_ptr_to_ref.fixed +++ b/tests/ui/transmute_ptr_to_ref.fixed @@ -2,6 +2,7 @@ #![warn(clippy::transmute_ptr_to_ref)] #![allow(clippy::match_single_binding)] +#![allow(unused_must_use)] unsafe fn _ptr_to_ref(p: *const T, m: *mut T, o: *const U, om: *mut U) { let _: &T = &*p; @@ -38,7 +39,7 @@ fn _issue1231() { type Bar<'a> = &'a u8; let raw = 42 as *const i32; - unsafe { &*(raw as *const u8) }; + let _ = unsafe { &*(raw as *const u8) }; } unsafe fn _issue8924<'a, 'b, 'c>(x: *const &'a u32, y: *const &'b u32) -> &'c &'b u32 { diff --git a/tests/ui/transmute_ptr_to_ref.rs b/tests/ui/transmute_ptr_to_ref.rs index 4238ff804780..901a3e90dbec 100644 --- a/tests/ui/transmute_ptr_to_ref.rs +++ b/tests/ui/transmute_ptr_to_ref.rs @@ -2,6 +2,7 @@ #![warn(clippy::transmute_ptr_to_ref)] #![allow(clippy::match_single_binding)] +#![allow(unused_must_use)] unsafe fn _ptr_to_ref(p: *const T, m: *mut T, o: *const U, om: *mut U) { let _: &T = std::mem::transmute(p); @@ -38,7 +39,7 @@ fn _issue1231() { type Bar<'a> = &'a u8; let raw = 42 as *const i32; - unsafe { std::mem::transmute::<_, Bar>(raw) }; + let _ = unsafe { std::mem::transmute::<_, Bar>(raw) }; } unsafe fn _issue8924<'a, 'b, 'c>(x: *const &'a u32, y: *const &'b u32) -> &'c &'b u32 { diff --git a/tests/ui/transmute_ptr_to_ref.stderr b/tests/ui/transmute_ptr_to_ref.stderr index b3e6c09d2d7a..68007edc4102 100644 --- a/tests/ui/transmute_ptr_to_ref.stderr +++ b/tests/ui/transmute_ptr_to_ref.stderr @@ -1,5 +1,5 @@ error: transmute from a pointer type (`*const T`) to a reference type (`&T`) - --> $DIR/transmute_ptr_to_ref.rs:7:17 + --> $DIR/transmute_ptr_to_ref.rs:8:17 | LL | let _: &T = std::mem::transmute(p); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*p` @@ -7,127 +7,127 @@ LL | let _: &T = std::mem::transmute(p); = note: `-D clippy::transmute-ptr-to-ref` implied by `-D warnings` error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`) - --> $DIR/transmute_ptr_to_ref.rs:10:21 + --> $DIR/transmute_ptr_to_ref.rs:11:21 | LL | let _: &mut T = std::mem::transmute(m); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *m` error: transmute from a pointer type (`*mut T`) to a reference type (`&T`) - --> $DIR/transmute_ptr_to_ref.rs:13:17 + --> $DIR/transmute_ptr_to_ref.rs:14:17 | LL | let _: &T = std::mem::transmute(m); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*m` error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`) - --> $DIR/transmute_ptr_to_ref.rs:16:21 + --> $DIR/transmute_ptr_to_ref.rs:17:21 | LL | let _: &mut T = std::mem::transmute(p as *mut T); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(p as *mut T)` error: transmute from a pointer type (`*const U`) to a reference type (`&T`) - --> $DIR/transmute_ptr_to_ref.rs:19:17 + --> $DIR/transmute_ptr_to_ref.rs:20:17 | LL | let _: &T = std::mem::transmute(o); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(o as *const T)` error: transmute from a pointer type (`*mut U`) to a reference type (`&mut T`) - --> $DIR/transmute_ptr_to_ref.rs:22:21 + --> $DIR/transmute_ptr_to_ref.rs:23:21 | LL | let _: &mut T = std::mem::transmute(om); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(om as *mut T)` error: transmute from a pointer type (`*mut U`) to a reference type (`&T`) - --> $DIR/transmute_ptr_to_ref.rs:25:17 + --> $DIR/transmute_ptr_to_ref.rs:26:17 | LL | let _: &T = std::mem::transmute(om); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(om as *const T)` error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo<'_, u8>`) - --> $DIR/transmute_ptr_to_ref.rs:35:32 + --> $DIR/transmute_ptr_to_ref.rs:36:32 | LL | let _: &Foo = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*raw.cast::>()` error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo<'_, &u8>`) - --> $DIR/transmute_ptr_to_ref.rs:37:33 + --> $DIR/transmute_ptr_to_ref.rs:38:33 | LL | let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*raw.cast::>()` error: transmute from a pointer type (`*const i32`) to a reference type (`&u8`) - --> $DIR/transmute_ptr_to_ref.rs:41:14 + --> $DIR/transmute_ptr_to_ref.rs:42:22 | -LL | unsafe { std::mem::transmute::<_, Bar>(raw) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const u8)` +LL | let _ = unsafe { std::mem::transmute::<_, Bar>(raw) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const u8)` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:46:14 + --> $DIR/transmute_ptr_to_ref.rs:47:14 | LL | 0 => std::mem::transmute(x), | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&u32>()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:47:14 + --> $DIR/transmute_ptr_to_ref.rs:48:14 | LL | 1 => std::mem::transmute(y), | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*y.cast::<&u32>()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:48:14 + --> $DIR/transmute_ptr_to_ref.rs:49:14 | LL | 2 => std::mem::transmute::<_, &&'b u32>(x), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&'b u32>()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:49:14 + --> $DIR/transmute_ptr_to_ref.rs:50:14 | LL | _ => std::mem::transmute::<_, &&'b u32>(y), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*y.cast::<&'b u32>()` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> $DIR/transmute_ptr_to_ref.rs:57:19 + --> $DIR/transmute_ptr_to_ref.rs:58:19 | LL | let _: &u32 = std::mem::transmute(a); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> $DIR/transmute_ptr_to_ref.rs:58:19 + --> $DIR/transmute_ptr_to_ref.rs:59:19 | LL | let _: &u32 = std::mem::transmute::<_, &u32>(a); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a.cast::()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:60:14 + --> $DIR/transmute_ptr_to_ref.rs:61:14 | LL | 0 => std::mem::transmute(x), | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&u32>()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:61:14 + --> $DIR/transmute_ptr_to_ref.rs:62:14 | LL | _ => std::mem::transmute::<_, &&'b u32>(x), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&'b u32>()` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> $DIR/transmute_ptr_to_ref.rs:69:19 + --> $DIR/transmute_ptr_to_ref.rs:70:19 | LL | let _: &u32 = std::mem::transmute(a); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> $DIR/transmute_ptr_to_ref.rs:70:19 + --> $DIR/transmute_ptr_to_ref.rs:71:19 | LL | let _: &u32 = std::mem::transmute::<_, &u32>(a); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(a as *const u32)` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:72:14 + --> $DIR/transmute_ptr_to_ref.rs:73:14 | LL | 0 => std::mem::transmute(x), | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(x as *const () as *const &u32)` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:73:14 + --> $DIR/transmute_ptr_to_ref.rs:74:14 | LL | _ => std::mem::transmute::<_, &&'b u32>(x), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(x as *const () as *const &'b u32)` From 0e42ec188c47493b74f3032849232a3c8948f7ba Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 7 Mar 2023 12:03:11 +0000 Subject: [PATCH 0855/1222] Add `AliasKind::Weak` for type aliases. Only use it when the type alias contains an opaque type. Also does wf-checking on such type aliases. --- clippy_lints/src/dereference.rs | 1 + tests/ui/from_over_into.fixed | 6 ----- tests/ui/from_over_into.rs | 6 ----- tests/ui/from_over_into_unfixable.rs | 6 +++++ tests/ui/from_over_into_unfixable.stderr | 33 ++++++------------------ tests/ui/new_ret_no_self.rs | 22 ---------------- tests/ui/new_ret_no_self.stderr | 18 +------------ tests/ui/new_ret_no_self_overflow.rs | 26 +++++++++++++++++++ tests/ui/new_ret_no_self_overflow.stderr | 9 +++++++ 9 files changed, 51 insertions(+), 76 deletions(-) create mode 100644 tests/ui/new_ret_no_self_overflow.rs create mode 100644 tests/ui/new_ret_no_self_overflow.stderr diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index a1d2147cb496..dbaf6aaa853c 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1424,6 +1424,7 @@ fn ty_auto_deref_stability<'tcx>( continue; }, ty::Param(_) => TyPosition::new_deref_stable_for_result(precedence, ty), + ty::Alias(ty::Weak, _) => unreachable!("should have been normalized away above"), ty::Alias(ty::Inherent, _) => unreachable!("inherent projection should have been normalized away above"), ty::Alias(ty::Projection, _) if ty.has_non_region_param() => { TyPosition::new_deref_stable_for_result(precedence, ty) diff --git a/tests/ui/from_over_into.fixed b/tests/ui/from_over_into.fixed index d18f93875658..204019130ede 100644 --- a/tests/ui/from_over_into.fixed +++ b/tests/ui/from_over_into.fixed @@ -82,10 +82,4 @@ fn msrv_1_41() { } } -type Opaque = impl Sized; -struct IntoOpaque; -impl Into for IntoOpaque { - fn into(self) -> Opaque {} -} - fn main() {} diff --git a/tests/ui/from_over_into.rs b/tests/ui/from_over_into.rs index de8ff0b06bdc..46e02847e308 100644 --- a/tests/ui/from_over_into.rs +++ b/tests/ui/from_over_into.rs @@ -82,10 +82,4 @@ fn msrv_1_41() { } } -type Opaque = impl Sized; -struct IntoOpaque; -impl Into for IntoOpaque { - fn into(self) -> Opaque {} -} - fn main() {} diff --git a/tests/ui/from_over_into_unfixable.rs b/tests/ui/from_over_into_unfixable.rs index 3b280b7488ae..bd62c655216e 100644 --- a/tests/ui/from_over_into_unfixable.rs +++ b/tests/ui/from_over_into_unfixable.rs @@ -32,4 +32,10 @@ impl Into for ContainsVal { } } +type Opaque = impl Sized; +struct IntoOpaque; +impl Into for IntoOpaque { + fn into(self) -> Opaque {} +} + fn main() {} diff --git a/tests/ui/from_over_into_unfixable.stderr b/tests/ui/from_over_into_unfixable.stderr index 251f1d84e74e..bb966af4b0ff 100644 --- a/tests/ui/from_over_into_unfixable.stderr +++ b/tests/ui/from_over_into_unfixable.stderr @@ -1,29 +1,12 @@ -error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into_unfixable.rs:11:1 +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/from_over_into_unfixable.rs:35:15 | -LL | impl Into for String { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | type Opaque = impl Sized; + | ^^^^^^^^^^ | - = help: replace the `Into` implementation with `From` - = note: `-D clippy::from-over-into` implied by `-D warnings` + = note: see issue #63063 for more information + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable -error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into_unfixable.rs:19:1 - | -LL | impl Into for &'static [u8] { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: replace the `Into` implementation with `From<&'static [u8]>` - -error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into_unfixable.rs:28:1 - | -LL | impl Into for ContainsVal { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: `impl From for Foreign` is allowed by the orphan rules, for more information see - https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence - = help: replace the `Into` implementation with `From` - -error: aborting due to 3 previous errors +error: aborting due to previous error +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/new_ret_no_self.rs b/tests/ui/new_ret_no_self.rs index a2a30c8b931c..4eff62b85ff6 100644 --- a/tests/ui/new_ret_no_self.rs +++ b/tests/ui/new_ret_no_self.rs @@ -401,25 +401,3 @@ mod issue7344 { } } } - -mod issue10041 { - struct Bomb; - - impl Bomb { - // Hidden default generic parameter. - pub fn new() -> impl PartialOrd { - 0i32 - } - } - - // TAIT with self-referencing bounds - type X = impl std::ops::Add; - - struct Bomb2; - - impl Bomb2 { - pub fn new() -> X { - 0i32 - } - } -} diff --git a/tests/ui/new_ret_no_self.stderr b/tests/ui/new_ret_no_self.stderr index 2eaebfb5cac5..2b053b462b16 100644 --- a/tests/ui/new_ret_no_self.stderr +++ b/tests/ui/new_ret_no_self.stderr @@ -92,21 +92,5 @@ LL | | unimplemented!() LL | | } | |_________^ -error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:410:9 - | -LL | / pub fn new() -> impl PartialOrd { -LL | | 0i32 -LL | | } - | |_________^ - -error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:421:9 - | -LL | / pub fn new() -> X { -LL | | 0i32 -LL | | } - | |_________^ - -error: aborting due to 14 previous errors +error: aborting due to 12 previous errors diff --git a/tests/ui/new_ret_no_self_overflow.rs b/tests/ui/new_ret_no_self_overflow.rs new file mode 100644 index 000000000000..7bc6fec10ba6 --- /dev/null +++ b/tests/ui/new_ret_no_self_overflow.rs @@ -0,0 +1,26 @@ +#![feature(type_alias_impl_trait)] +#![warn(clippy::new_ret_no_self)] + +mod issue10041 { + struct Bomb; + + impl Bomb { + // Hidden default generic parameter. + pub fn new() -> impl PartialOrd { + 0i32 + } + } + + // TAIT with self-referencing bounds + type X = impl std::ops::Add; + + struct Bomb2; + + impl Bomb2 { + pub fn new() -> X { + 0i32 + } + } +} + +fn main() {} diff --git a/tests/ui/new_ret_no_self_overflow.stderr b/tests/ui/new_ret_no_self_overflow.stderr new file mode 100644 index 000000000000..babb634fdcd1 --- /dev/null +++ b/tests/ui/new_ret_no_self_overflow.stderr @@ -0,0 +1,9 @@ +error[E0275]: overflow evaluating the requirement `::Output == issue10041::X` + --> $DIR/new_ret_no_self_overflow.rs:20:25 + | +LL | pub fn new() -> X { + | ^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0275`. From 51695e64c541fd9b70ddd7f99757f7fe6e222e6b Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 15 Jun 2023 16:59:01 +0000 Subject: [PATCH 0856/1222] Move WF goal to clause --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index c0d2c835d63d..b132e69269d8 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -33,7 +33,7 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv) | ty::Clause::Trait(..) | ty::Clause::ConstArgHasType(..), ) - | ty::PredicateKind::WellFormed(_) + | ty::PredicateKind::Clause(ty::Clause::WellFormed(_)) | ty::PredicateKind::ConstEvaluatable(..) | ty::PredicateKind::ConstEquate(..) | ty::PredicateKind::TypeWellFormedFromEnv(..) => continue, From ca875cdc65eac8d064bda3aa2683234d28eba67c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 15 Jun 2023 18:35:52 +0000 Subject: [PATCH 0857/1222] Move ConstEvaluatable to Clause --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index b132e69269d8..860a489494c8 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -34,7 +34,7 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv) | ty::Clause::ConstArgHasType(..), ) | ty::PredicateKind::Clause(ty::Clause::WellFormed(_)) - | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::Clause(ty::Clause::ConstEvaluatable(..)) | ty::PredicateKind::ConstEquate(..) | ty::PredicateKind::TypeWellFormedFromEnv(..) => continue, ty::PredicateKind::AliasRelate(..) => panic!("alias relate predicate on function: {predicate:#?}"), From 90eaf8e1930af3f6a8f0b761946f6a6934d2ab3b Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 18 Jun 2023 05:24:38 +0000 Subject: [PATCH 0858/1222] Better error for non const `PartialEq` call generated by `match` --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index c0d2c835d63d..566eecf36a77 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -317,7 +317,7 @@ fn check_terminator<'tcx>( TerminatorKind::Call { func, args, - from_hir_call: _, + call_source: _, destination: _, target: _, unwind: _, From 72f8bc68311faa78ecaf30a64b2237c98a92ea0f Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 18 Jun 2023 22:10:07 +0000 Subject: [PATCH 0859/1222] Treat TAIT equation as always ambiguous in coherence --- tests/ui/from_over_into_unfixable.rs | 6 ----- tests/ui/from_over_into_unfixable.stderr | 33 ++++++++++++++++++------ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/tests/ui/from_over_into_unfixable.rs b/tests/ui/from_over_into_unfixable.rs index bd62c655216e..3b280b7488ae 100644 --- a/tests/ui/from_over_into_unfixable.rs +++ b/tests/ui/from_over_into_unfixable.rs @@ -32,10 +32,4 @@ impl Into for ContainsVal { } } -type Opaque = impl Sized; -struct IntoOpaque; -impl Into for IntoOpaque { - fn into(self) -> Opaque {} -} - fn main() {} diff --git a/tests/ui/from_over_into_unfixable.stderr b/tests/ui/from_over_into_unfixable.stderr index bb966af4b0ff..251f1d84e74e 100644 --- a/tests/ui/from_over_into_unfixable.stderr +++ b/tests/ui/from_over_into_unfixable.stderr @@ -1,12 +1,29 @@ -error[E0658]: `impl Trait` in type aliases is unstable - --> $DIR/from_over_into_unfixable.rs:35:15 +error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true + --> $DIR/from_over_into_unfixable.rs:11:1 | -LL | type Opaque = impl Sized; - | ^^^^^^^^^^ +LL | impl Into for String { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: see issue #63063 for more information - = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + = help: replace the `Into` implementation with `From` + = note: `-D clippy::from-over-into` implied by `-D warnings` -error: aborting due to previous error +error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true + --> $DIR/from_over_into_unfixable.rs:19:1 + | +LL | impl Into for &'static [u8] { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: replace the `Into` implementation with `From<&'static [u8]>` + +error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true + --> $DIR/from_over_into_unfixable.rs:28:1 + | +LL | impl Into for ContainsVal { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: `impl From for Foreign` is allowed by the orphan rules, for more information see + https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence + = help: replace the `Into` implementation with `From` + +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0658`. From f80fc436ed728fbdce62a19d7c91b391f8dcb526 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 19 Jun 2023 12:22:02 +0000 Subject: [PATCH 0860/1222] Support `ast::ExprKind::Become` in clippy --- clippy_utils/src/sugg.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index f477524eec5c..a87d58110b0c 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -211,6 +211,7 @@ impl<'a> Sugg<'a> { | ast::ExprKind::Path(..) | ast::ExprKind::Repeat(..) | ast::ExprKind::Ret(..) + | ast::ExprKind::Become(..) | ast::ExprKind::Yeet(..) | ast::ExprKind::FormatArgs(..) | ast::ExprKind::Struct(..) From 1c0f98c2a0dcdfcbb90aef72a94b49ef13d9f280 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 16 Jun 2023 05:59:42 +0000 Subject: [PATCH 0861/1222] s/Clause/ClauseKind --- clippy_lints/src/dereference.rs | 8 ++++---- clippy_lints/src/derive.rs | 6 +++--- clippy_lints/src/future_not_send.rs | 4 ++-- clippy_lints/src/methods/needless_collect.rs | 4 ++-- clippy_lints/src/methods/unnecessary_to_owned.rs | 8 ++++---- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/ptr.rs | 4 ++-- clippy_lints/src/unit_return_expecting_ord.rs | 6 +++--- clippy_utils/src/eager_or_lazy.rs | 2 +- clippy_utils/src/qualify_min_const_fn.rs | 14 +++++++------- clippy_utils/src/ty.rs | 16 ++++++++-------- 11 files changed, 37 insertions(+), 37 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index dbaf6aaa853c..ee6aef71980e 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -26,7 +26,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::{Rvalue, StatementKind}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability}; use rustc_middle::ty::{ - self, Binder, BoundVariableKind, Clause, EarlyBinder, FnSig, GenericArgKind, List, ParamEnv, ParamTy, + self, Binder, BoundVariableKind, ClauseKind, EarlyBinder, FnSig, GenericArgKind, List, ParamEnv, ParamTy, PredicateKind, ProjectionPredicate, Ty, TyCtxt, TypeVisitableExt, TypeckResults, }; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -1133,7 +1133,7 @@ fn needless_borrow_impl_arg_position<'tcx>( let projection_predicates = predicates .iter() .filter_map(|predicate| { - if let PredicateKind::Clause(Clause::Projection(projection_predicate)) = predicate.kind().skip_binder() { + if let PredicateKind::Clause(ClauseKind::Projection(projection_predicate)) = predicate.kind().skip_binder() { Some(projection_predicate) } else { None @@ -1147,7 +1147,7 @@ fn needless_borrow_impl_arg_position<'tcx>( if predicates .iter() .filter_map(|predicate| { - if let PredicateKind::Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() + if let PredicateKind::Clause(ClauseKind::Trait(trait_predicate)) = predicate.kind().skip_binder() && trait_predicate.trait_ref.self_ty() == param_ty.to_ty(cx.tcx) { Some(trait_predicate.trait_ref.def_id) @@ -1209,7 +1209,7 @@ fn needless_borrow_impl_arg_position<'tcx>( } predicates.iter().all(|predicate| { - if let PredicateKind::Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() + if let PredicateKind::Clause(ClauseKind::Trait(trait_predicate)) = predicate.kind().skip_binder() && cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_predicate.trait_ref.def_id) && let ty::Param(param_ty) = trait_predicate.self_ty().kind() && let GenericArgKind::Type(ty) = substs_with_referent_ty[param_ty.index as usize].unpack() diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 8f5d319cd4fc..8d84e756ff87 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -14,7 +14,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::traits::Reveal; use rustc_middle::ty::{ - self, Binder, BoundConstness, Clause, GenericArgKind, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, + self, Binder, BoundConstness, ClauseKind, GenericArgKind, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate, Ty, TyCtxt, }; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -503,7 +503,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> let ty_predicates = tcx.predicates_of(did).predicates; for (p, _) in ty_predicates { - if let PredicateKind::Clause(Clause::Trait(p)) = p.kind().skip_binder() + if let PredicateKind::Clause(ClauseKind::Trait(p)) = p.kind().skip_binder() && p.trait_ref.def_id == eq_trait_id && let ty::Param(self_ty) = p.trait_ref.self_ty().kind() && p.constness == BoundConstness::NotConst @@ -516,7 +516,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> ParamEnv::new( tcx.mk_predicates_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain( params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| { - tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate { + tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(ClauseKind::Trait(TraitPredicate { trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]), constness: BoundConstness::NotConst, polarity: ImplPolarity::Positive, diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index d1314795f580..a391b76910ad 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, AliasTy, Clause, PredicateKind}; +use rustc_middle::ty::{self, AliasTy, ClauseKind, PredicateKind}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; use rustc_span::{sym, Span}; @@ -93,7 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { infcx .err_ctxt() .maybe_note_obligation_cause_for_async_await(db, &obligation); - if let PredicateKind::Clause(Clause::Trait(trait_pred)) = + if let PredicateKind::Clause(ClauseKind::Trait(trait_pred)) = obligation.predicate.kind().skip_binder() { db.note(format!( diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index 99f810c27cf8..cf85d3174dba 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -16,7 +16,7 @@ use rustc_hir::{ }; use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; -use rustc_middle::ty::{self, AssocKind, Clause, EarlyBinder, GenericArg, GenericArgKind, PredicateKind, Ty}; +use rustc_middle::ty::{self, AssocKind, ClauseKind, EarlyBinder, GenericArg, GenericArgKind, PredicateKind, Ty}; use rustc_span::symbol::Ident; use rustc_span::{sym, Span, Symbol}; @@ -175,7 +175,7 @@ fn check_collect_into_intoiterator<'tcx>( .caller_bounds() .into_iter() .filter_map(|p| { - if let PredicateKind::Clause(Clause::Trait(t)) = p.kind().skip_binder() + if let PredicateKind::Clause(ClauseKind::Trait(t)) = p.kind().skip_binder() && cx.tcx.is_diagnostic_item(sym::IntoIterator,t.trait_ref.def_id) { Some(t.self_ty()) } else { diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 309d2157b76e..06fa95cd657d 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -14,7 +14,7 @@ use rustc_lint::LateContext; use rustc_middle::mir::Mutability; use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef}; -use rustc_middle::ty::{self, Clause, EarlyBinder, ParamTy, PredicateKind, ProjectionPredicate, TraitPredicate, Ty}; +use rustc_middle::ty::{self, ClauseKind, EarlyBinder, ParamTy, PredicateKind, ProjectionPredicate, TraitPredicate, Ty}; use rustc_span::{sym, Symbol}; use rustc_trait_selection::traits::{query::evaluate_obligation::InferCtxtExt as _, Obligation, ObligationCause}; @@ -345,12 +345,12 @@ fn get_input_traits_and_projections<'tcx>( let mut projection_predicates = Vec::new(); for predicate in cx.tcx.param_env(callee_def_id).caller_bounds() { match predicate.kind().skip_binder() { - PredicateKind::Clause(Clause::Trait(trait_predicate)) => { + PredicateKind::Clause(ClauseKind::Trait(trait_predicate)) => { if trait_predicate.trait_ref.self_ty() == input { trait_predicates.push(trait_predicate); } }, - PredicateKind::Clause(Clause::Projection(projection_predicate)) => { + PredicateKind::Clause(ClauseKind::Projection(projection_predicate)) => { if projection_predicate.projection_ty.self_ty() == input { projection_predicates.push(projection_predicate); } @@ -407,7 +407,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< let mut trait_predicates = cx.tcx.param_env(callee_def_id) .caller_bounds().iter().filter(|predicate| { - if let PredicateKind::Clause(Clause::Trait(trait_predicate)) + if let PredicateKind::Clause(ClauseKind::Trait(trait_predicate)) = predicate.kind().skip_binder() && trait_predicate.trait_ref.self_ty() == *param_ty { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 7d53fe65658a..3773975e9554 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -126,7 +126,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { .filter_map(|pred| { // Note that we do not want to deal with qualified predicates here. match pred.kind().no_bound_vars() { - Some(ty::PredicateKind::Clause(ty::Clause::Trait(pred))) if pred.def_id() != sized_trait => { + Some(ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred))) if pred.def_id() != sized_trait => { Some(pred) }, _ => None, diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index fc550936165e..b8911f109076 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -19,7 +19,7 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::traits::{Obligation, ObligationCause}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; -use rustc_middle::ty::{self, Binder, Clause, ExistentialPredicate, List, PredicateKind, Ty}; +use rustc_middle::ty::{self, Binder, ClauseKind, ExistentialPredicate, List, PredicateKind, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::sym; @@ -697,7 +697,7 @@ fn matches_preds<'tcx>( ObligationCause::dummy(), cx.param_env, cx.tcx - .mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Projection( + .mk_predicate(Binder::dummy(PredicateKind::Clause(ClauseKind::Projection( p.with_self_ty(cx.tcx, ty), )))), )), diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 289ca4e9bed3..a375e5d5b4ca 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -4,7 +4,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::{Closure, Expr, ExprKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; -use rustc_middle::ty::{Clause, GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate}; +use rustc_middle::ty::{ClauseKind, GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, BytePos, Span}; @@ -45,7 +45,7 @@ fn get_trait_predicates_for_trait_id<'tcx>( let mut preds = Vec::new(); for (pred, _) in generics.predicates { if_chain! { - if let PredicateKind::Clause(Clause::Trait(poly_trait_pred)) = pred.kind().skip_binder(); + if let PredicateKind::Clause(ClauseKind::Trait(poly_trait_pred)) = pred.kind().skip_binder(); let trait_pred = cx.tcx.erase_late_bound_regions(pred.kind().rebind(poly_trait_pred)); if let Some(trait_def_id) = trait_id; if trait_def_id == trait_pred.trait_ref.def_id; @@ -63,7 +63,7 @@ fn get_projection_pred<'tcx>( trait_pred: TraitPredicate<'tcx>, ) -> Option> { generics.predicates.iter().find_map(|(proj_pred, _)| { - if let ty::PredicateKind::Clause(Clause::Projection(pred)) = proj_pred.kind().skip_binder() { + if let ty::PredicateKind::Clause(ClauseKind::Projection(pred)) = proj_pred.kind().skip_binder() { let projection_pred = cx.tcx.erase_late_bound_regions(proj_pred.kind().rebind(pred)); if projection_pred.projection_ty.substs == trait_pred.trait_ref.substs { return Some(projection_pred); diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 3df40942e7b5..941df3318ae8 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -73,7 +73,7 @@ fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg: .flat_map(|v| v.fields.iter()) .any(|x| matches!(cx.tcx.type_of(x.did).subst_identity().peel_refs().kind(), ty::Param(_))) && all_predicates_of(cx.tcx, fn_id).all(|(pred, _)| match pred.kind().skip_binder() { - PredicateKind::Clause(ty::Clause::Trait(pred)) => cx.tcx.trait_def(pred.trait_ref.def_id).is_marker, + PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => cx.tcx.trait_def(pred.trait_ref.def_id).is_marker, _ => true, }) && subs.types().all(|x| matches!(x.peel_refs().kind(), ty::Param(_))) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 860a489494c8..aea79984c7ad 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -27,14 +27,14 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv) for (predicate, _) in predicates.predicates { match predicate.kind().skip_binder() { ty::PredicateKind::Clause( - ty::Clause::RegionOutlives(_) - | ty::Clause::TypeOutlives(_) - | ty::Clause::Projection(_) - | ty::Clause::Trait(..) - | ty::Clause::ConstArgHasType(..), + ty::ClauseKind::RegionOutlives(_) + | ty::ClauseKind::TypeOutlives(_) + | ty::ClauseKind::Projection(_) + | ty::ClauseKind::Trait(..) + | ty::ClauseKind::ConstArgHasType(..), ) - | ty::PredicateKind::Clause(ty::Clause::WellFormed(_)) - | ty::PredicateKind::Clause(ty::Clause::ConstEvaluatable(..)) + | ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) + | ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..)) | ty::PredicateKind::ConstEquate(..) | ty::PredicateKind::TypeWellFormedFromEnv(..) => continue, ty::PredicateKind::AliasRelate(..) => panic!("alias relate predicate on function: {predicate:#?}"), diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 7b4ed77e8edb..12f18614d713 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -94,7 +94,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' match predicate.kind().skip_binder() { // For `impl Trait`, it will register a predicate of `T: Trait`, so we go through // and check substitutions to find `U`. - ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) => { + ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_predicate)) => { if trait_predicate .trait_ref .substs @@ -107,7 +107,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' }, // For `impl Trait`, it will register a predicate of `::Assoc = U`, // so we check the term for `U`. - ty::PredicateKind::Clause(ty::Clause::Projection(projection_predicate)) => { + ty::PredicateKind::Clause(ty::ClauseKind::Projection(projection_predicate)) => { if let ty::TermKind::Ty(ty) = projection_predicate.term.unpack() { if contains_ty_adt_constructor_opaque_inner(cx, ty, needle, seen) { return true; @@ -268,7 +268,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { for (predicate, _) in cx.tcx.explicit_item_bounds(def_id).skip_binder() { - if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() { + if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_predicate)) = predicate.kind().skip_binder() { if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) { return true; } @@ -707,7 +707,7 @@ fn sig_from_bounds<'tcx>( for pred in predicates { match pred.kind().skip_binder() { - PredicateKind::Clause(ty::Clause::Trait(p)) + PredicateKind::Clause(ty::ClauseKind::Trait(p)) if (lang_items.fn_trait() == Some(p.def_id()) || lang_items.fn_mut_trait() == Some(p.def_id()) || lang_items.fn_once_trait() == Some(p.def_id())) @@ -720,7 +720,7 @@ fn sig_from_bounds<'tcx>( } inputs = Some(i); }, - PredicateKind::Clause(ty::Clause::Projection(p)) + PredicateKind::Clause(ty::ClauseKind::Projection(p)) if Some(p.projection_ty.def_id) == lang_items.fn_once_output() && p.projection_ty.self_ty() == ty => { if output.is_some() { @@ -747,7 +747,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option .subst_iter_copied(cx.tcx, ty.substs) { match pred.kind().skip_binder() { - PredicateKind::Clause(ty::Clause::Trait(p)) + PredicateKind::Clause(ty::ClauseKind::Trait(p)) if (lang_items.fn_trait() == Some(p.def_id()) || lang_items.fn_mut_trait() == Some(p.def_id()) || lang_items.fn_once_trait() == Some(p.def_id())) => @@ -760,7 +760,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option } inputs = Some(i); }, - PredicateKind::Clause(ty::Clause::Projection(p)) + PredicateKind::Clause(ty::ClauseKind::Projection(p)) if Some(p.projection_ty.def_id) == lang_items.fn_once_output() => { if output.is_some() { @@ -950,7 +950,7 @@ pub fn ty_is_fn_once_param<'tcx>(tcx: TyCtxt<'_>, ty: Ty<'tcx>, predicates: &'tc predicates .iter() .try_fold(false, |found, p| { - if let PredicateKind::Clause(ty::Clause::Trait(p)) = p.kind().skip_binder() + if let PredicateKind::Clause(ty::ClauseKind::Trait(p)) = p.kind().skip_binder() && let ty::Param(self_ty) = p.trait_ref.self_ty().kind() && ty.index == self_ty.index { From e7d3e4ac776deb14fe06a12c3328e8e49013a6ef Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 19 Jun 2023 20:46:46 +0000 Subject: [PATCH 0862/1222] Migrate item_bounds to ty::Clause --- clippy_lints/src/future_not_send.rs | 2 +- clippy_utils/src/ty.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index a391b76910ad..818ebd1134de 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { let preds = cx.tcx.explicit_item_bounds(def_id); let mut is_future = false; for (p, _span) in preds.subst_iter_copied(cx.tcx, substs) { - if let Some(trait_pred) = p.to_opt_poly_trait_pred() { + if let Some(trait_pred) = p.as_trait_clause() { if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() { is_future = true; break; diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 12f18614d713..2b185943c59c 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -94,7 +94,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' match predicate.kind().skip_binder() { // For `impl Trait`, it will register a predicate of `T: Trait`, so we go through // and check substitutions to find `U`. - ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_predicate)) => { + ty::ClauseKind::Trait(trait_predicate) => { if trait_predicate .trait_ref .substs @@ -107,7 +107,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' }, // For `impl Trait`, it will register a predicate of `::Assoc = U`, // so we check the term for `U`. - ty::PredicateKind::Clause(ty::ClauseKind::Projection(projection_predicate)) => { + ty::ClauseKind::Projection(projection_predicate) => { if let ty::TermKind::Ty(ty) = projection_predicate.term.unpack() { if contains_ty_adt_constructor_opaque_inner(cx, ty, needle, seen) { return true; @@ -268,7 +268,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { for (predicate, _) in cx.tcx.explicit_item_bounds(def_id).skip_binder() { - if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_predicate)) = predicate.kind().skip_binder() { + if let ty::ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() { if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) { return true; } @@ -665,7 +665,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option sig_from_bounds( cx, ty, - cx.tcx.item_bounds(def_id).subst(cx.tcx, substs), + cx.tcx.item_bounds(def_id).subst_iter(cx.tcx, substs).map(|c| c.as_predicate()), cx.tcx.opt_parent(def_id), ), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), @@ -698,7 +698,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option( cx: &LateContext<'tcx>, ty: Ty<'tcx>, - predicates: &'tcx [Predicate<'tcx>], + predicates: impl IntoIterator>, predicates_id: Option, ) -> Option> { let mut inputs = None; @@ -747,7 +747,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option .subst_iter_copied(cx.tcx, ty.substs) { match pred.kind().skip_binder() { - PredicateKind::Clause(ty::ClauseKind::Trait(p)) + ty::ClauseKind::Trait(p) if (lang_items.fn_trait() == Some(p.def_id()) || lang_items.fn_mut_trait() == Some(p.def_id()) || lang_items.fn_once_trait() == Some(p.def_id())) => @@ -760,7 +760,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option } inputs = Some(i); }, - PredicateKind::Clause(ty::ClauseKind::Projection(p)) + ty::ClauseKind::Projection(p) if Some(p.projection_ty.def_id) == lang_items.fn_once_output() => { if output.is_some() { From 50469f4c4d1ad605fd1141e398c9082adc69e26e Mon Sep 17 00:00:00 2001 From: yukang Date: Tue, 6 Jun 2023 02:48:57 +0800 Subject: [PATCH 0863/1222] Do not offer any of the suggestions in emit_coerce_suggestions for expr from destructuring assignment desugaring --- tests/ui/crashes/ice-6250.stderr | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/ui/crashes/ice-6250.stderr b/tests/ui/crashes/ice-6250.stderr index 4506d1550bd4..db34e6bfa7b2 100644 --- a/tests/ui/crashes/ice-6250.stderr +++ b/tests/ui/crashes/ice-6250.stderr @@ -12,11 +12,6 @@ LL | for reference in vec![1, 2, 3] { ... LL | Some(reference) = cache.data.get(key) { | ^^^^^^^^^ expected integer, found `&i32` - | -help: consider dereferencing the borrow - | -LL | Some(*reference) = cache.data.get(key) { - | + error[E0308]: mismatched types --> $DIR/ice-6250.rs:12:9 From 205db413a33b2115c5dd8a56ac04ffeee4c08111 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 21 Jun 2023 14:00:51 +0000 Subject: [PATCH 0864/1222] Support `hir::ExprKind::Become` in clippy --- clippy_lints/src/loops/never_loop.rs | 6 ++++++ clippy_lints/src/matches/significant_drop_in_scrutinee.rs | 1 + clippy_lints/src/utils/author.rs | 5 +++++ clippy_utils/src/eager_or_lazy.rs | 1 + clippy_utils/src/hir_utils.rs | 3 +++ clippy_utils/src/sugg.rs | 1 + clippy_utils/src/visitors.rs | 1 + 7 files changed, 18 insertions(+) diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index 5f1fdf00be8c..10b5e1edf925 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -206,6 +206,12 @@ fn never_loop_expr(expr: &Expr<'_>, ignore_ids: &mut Vec, main_loop_id: H NeverLoopResult::AlwaysBreak, ) }), + ExprKind::Become(e) => { + combine_seq( + never_loop_expr(e, ignore_ids, main_loop_id), + NeverLoopResult::AlwaysBreak, + ) + } ExprKind::InlineAsm(asm) => asm .operands .iter() diff --git a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index 7945275393c0..93ef07d36aea 100644 --- a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -329,6 +329,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> { ExprKind::Field(..) | ExprKind::Index(..) | ExprKind::Ret(..) | + ExprKind::Become(..) | ExprKind::Repeat(..) | ExprKind::Yield(..) => walk_expr(self, ex), ExprKind::AddrOf(_, _, _) | diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 3c2bf5abab2b..6b51974d739a 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -559,6 +559,11 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { kind!("Ret({value})"); value.if_some(|e| self.expr(e)); }, + ExprKind::Become(value) => { + bind!(self, value); + kind!("Become({value})"); + self.expr(value); + }, ExprKind::InlineAsm(_) => { kind!("InlineAsm(_)"); out!("// unimplemented: `ExprKind::InlineAsm` is not further destructured at the moment"); diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 941df3318ae8..a42b2ccee889 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -191,6 +191,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS ExprKind::Break(..) | ExprKind::Continue(_) | ExprKind::Ret(_) + | ExprKind::Become(_) | ExprKind::InlineAsm(_) | ExprKind::Yield(..) | ExprKind::Err(_) => { diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index a49246a78327..3e1d73564146 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -845,6 +845,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_expr(e); } }, + ExprKind::Become(f) => { + self.hash_expr(f); + }, ExprKind::Path(ref qpath) => { self.hash_qpath(qpath); }, diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index a87d58110b0c..b38b9553558c 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -147,6 +147,7 @@ impl<'a> Sugg<'a> { | hir::ExprKind::Path(..) | hir::ExprKind::Repeat(..) | hir::ExprKind::Ret(..) + | hir::ExprKind::Become(..) | hir::ExprKind::Struct(..) | hir::ExprKind::Tup(..) | hir::ExprKind::Err(_) => Sugg::NonParen(get_snippet(expr.span)), diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index 5dcd71cef127..8dafa723afa0 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -651,6 +651,7 @@ pub fn for_each_unconsumed_temporary<'tcx, B>( // Either drops temporaries, jumps out of the current expression, or has no sub expression. ExprKind::DropTemps(_) | ExprKind::Ret(_) + | ExprKind::Become(_) | ExprKind::Break(..) | ExprKind::Yield(..) | ExprKind::Block(..) From 77fd1b3e216432aa169bd2172d800d2c487e088e Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 16 Jun 2023 16:02:11 +0000 Subject: [PATCH 0865/1222] Make simd_shuffle_indices use valtrees --- clippy_lints/src/non_copy_const.rs | 64 +++++++++++++++++++++++------- tests/ui/crashes/ice-9445.stderr | 12 ++++++ 2 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 tests/ui/crashes/ice-9445.stderr diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 58590df1fedf..ac49ccdb5011 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -15,12 +15,14 @@ use rustc_hir::{ }; use rustc_hir_analysis::hir_ty_to_ty; use rustc_lint::{LateContext, LateLintPass, Lint}; -use rustc_middle::mir; -use rustc_middle::mir::interpret::{ConstValue, ErrorHandled}; +use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::ty::adjustment::Adjust; -use rustc_middle::ty::{self, Ty}; +use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, InnerSpan, Span}; +use rustc_target::abi::VariantIdx; +use rustc_middle::mir::interpret::EvalToValTreeResult; +use rustc_middle::mir::interpret::GlobalId; // FIXME: this is a correctness problem but there's no suitable // warn-by-default category. @@ -141,21 +143,35 @@ fn is_unfrozen<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { fn is_value_unfrozen_raw<'tcx>( cx: &LateContext<'tcx>, - result: Result, ErrorHandled>, + result: Result>, ErrorHandled>, ty: Ty<'tcx>, ) -> bool { - fn inner<'tcx>(cx: &LateContext<'tcx>, val: mir::ConstantKind<'tcx>) -> bool { - match val.ty().kind() { + fn inner<'tcx>(cx: &LateContext<'tcx>, val: ty::ValTree<'tcx>, ty: Ty<'tcx>) -> bool { + match *ty.kind() { // the fact that we have to dig into every structs to search enums // leads us to the point checking `UnsafeCell` directly is the only option. ty::Adt(ty_def, ..) if ty_def.is_unsafe_cell() => true, // As of 2022-09-08 miri doesn't track which union field is active so there's no safe way to check the // contained value. ty::Adt(def, ..) if def.is_union() => false, - ty::Array(..) | ty::Adt(..) | ty::Tuple(..) => { - let val = cx.tcx.destructure_mir_constant(cx.param_env, val); - val.fields.iter().any(|field| inner(cx, *field)) + ty::Array(ty, _) => { + val.unwrap_branch().iter().any(|field| inner(cx, *field, ty)) }, + ty::Adt(def, _) if def.is_union() => false, + ty::Adt(def, substs) if def.is_enum() => { + let (&variant_index, fields) = val.unwrap_branch().split_first().unwrap(); + let variant_index = + VariantIdx::from_u32(variant_index.unwrap_leaf().try_to_u32().ok().unwrap()); + fields.iter().copied().zip( + def.variants()[variant_index] + .fields + .iter() + .map(|field| field.ty(cx.tcx, substs))).any(|(field, ty)| inner(cx, field, ty)) + } + ty::Adt(def, substs) => { + val.unwrap_branch().iter().zip(def.non_enum_variant().fields.iter().map(|field| field.ty(cx.tcx, substs))).any(|(field, ty)| inner(cx, *field, ty)) + } + ty::Tuple(tys) => val.unwrap_branch().iter().zip(tys).any(|(field, ty)| inner(cx, *field, ty)), _ => false, } } @@ -184,24 +200,44 @@ fn is_value_unfrozen_raw<'tcx>( // I chose this way because unfrozen enums as assoc consts are rare (or, hopefully, none). err == ErrorHandled::TooGeneric }, - |val| inner(cx, mir::ConstantKind::from_value(val, ty)), + |val| val.map_or(true, |val| inner(cx, val, ty)), ) } fn is_value_unfrozen_poly<'tcx>(cx: &LateContext<'tcx>, body_id: BodyId, ty: Ty<'tcx>) -> bool { - let result = cx.tcx.const_eval_poly(body_id.hir_id.owner.to_def_id()); + let def_id = body_id.hir_id.owner.to_def_id(); + let substs = ty::InternalSubsts::identity_for_item(cx.tcx, def_id); + let instance = ty::Instance::new(def_id, substs); + let cid = rustc_middle::mir::interpret::GlobalId { instance, promoted: None }; + let param_env = cx.tcx.param_env(def_id).with_reveal_all_normalized(cx.tcx); + let result = cx.tcx.const_eval_global_id_for_typeck(param_env, cid, None); is_value_unfrozen_raw(cx, result, ty) } fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: DefId, ty: Ty<'tcx>) -> bool { let substs = cx.typeck_results().node_substs(hir_id); - let result = cx - .tcx - .const_eval_resolve(cx.param_env, mir::UnevaluatedConst::new(def_id, substs), None); + let result = const_eval_resolve(cx.tcx, cx.param_env, ty::UnevaluatedConst::new(def_id, substs), None); is_value_unfrozen_raw(cx, result, ty) } + +pub fn const_eval_resolve<'tcx>( + tcx: TyCtxt<'tcx>, + param_env: ty::ParamEnv<'tcx>, + ct: ty::UnevaluatedConst<'tcx>, + span: Option, +) -> EvalToValTreeResult<'tcx> { + match ty::Instance::resolve(tcx, param_env, ct.def, ct.substs) { + Ok(Some(instance)) => { + let cid = GlobalId { instance, promoted: None }; + tcx.const_eval_global_id_for_typeck(param_env, cid, span) + } + Ok(None) => Err(ErrorHandled::TooGeneric), + Err(err) => Err(ErrorHandled::Reported(err.into())), + } +} + #[derive(Copy, Clone)] enum Source { Item { item: Span }, diff --git a/tests/ui/crashes/ice-9445.stderr b/tests/ui/crashes/ice-9445.stderr new file mode 100644 index 000000000000..a59d098e5ac0 --- /dev/null +++ b/tests/ui/crashes/ice-9445.stderr @@ -0,0 +1,12 @@ +error: a `const` item should never be interior mutable + --> $DIR/ice-9445.rs:1:1 + | +LL | const UNINIT: core::mem::MaybeUninit> = core::mem::MaybeUninit::uninit(); + | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | make this a static item (maybe with lazy_static) + | + = note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` + +error: aborting due to previous error + From 07fbf75ce5b6ababbd7e901b6293802bd3394dc6 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 22 Jun 2023 18:17:13 +0000 Subject: [PATCH 0866/1222] Migrate predicates_of and caller_bounds to Clause --- clippy_lints/src/dereference.rs | 8 ++--- clippy_lints/src/derive.rs | 12 ++++---- clippy_lints/src/methods/needless_collect.rs | 4 +-- .../src/methods/unnecessary_to_owned.rs | 8 ++--- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/unit_return_expecting_ord.rs | 6 ++-- clippy_utils/src/eager_or_lazy.rs | 4 +-- clippy_utils/src/qualify_min_const_fn.rs | 29 ------------------- clippy_utils/src/ty.rs | 16 +++++----- 9 files changed, 30 insertions(+), 59 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index ee6aef71980e..1ecaa1a123ce 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -27,7 +27,7 @@ use rustc_middle::mir::{Rvalue, StatementKind}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability}; use rustc_middle::ty::{ self, Binder, BoundVariableKind, ClauseKind, EarlyBinder, FnSig, GenericArgKind, List, ParamEnv, ParamTy, - PredicateKind, ProjectionPredicate, Ty, TyCtxt, TypeVisitableExt, TypeckResults, + ProjectionPredicate, Ty, TyCtxt, TypeVisitableExt, TypeckResults, }; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{symbol::sym, Span, Symbol}; @@ -1133,7 +1133,7 @@ fn needless_borrow_impl_arg_position<'tcx>( let projection_predicates = predicates .iter() .filter_map(|predicate| { - if let PredicateKind::Clause(ClauseKind::Projection(projection_predicate)) = predicate.kind().skip_binder() { + if let ClauseKind::Projection(projection_predicate) = predicate.kind().skip_binder() { Some(projection_predicate) } else { None @@ -1147,7 +1147,7 @@ fn needless_borrow_impl_arg_position<'tcx>( if predicates .iter() .filter_map(|predicate| { - if let PredicateKind::Clause(ClauseKind::Trait(trait_predicate)) = predicate.kind().skip_binder() + if let ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() && trait_predicate.trait_ref.self_ty() == param_ty.to_ty(cx.tcx) { Some(trait_predicate.trait_ref.def_id) @@ -1209,7 +1209,7 @@ fn needless_borrow_impl_arg_position<'tcx>( } predicates.iter().all(|predicate| { - if let PredicateKind::Clause(ClauseKind::Trait(trait_predicate)) = predicate.kind().skip_binder() + if let ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() && cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_predicate.trait_ref.def_id) && let ty::Param(param_ty) = trait_predicate.self_ty().kind() && let GenericArgKind::Type(ty) = substs_with_referent_ty[param_ty.index as usize].unpack() diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 8d84e756ff87..10a2f0cb1e7e 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -14,8 +14,8 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::traits::Reveal; use rustc_middle::ty::{ - self, Binder, BoundConstness, ClauseKind, GenericArgKind, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, - TraitPredicate, Ty, TyCtxt, + self, BoundConstness, ClauseKind, GenericArgKind, GenericParamDefKind, ImplPolarity, ParamEnv, + ToPredicate, TraitPredicate, Ty, TyCtxt, }; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; @@ -503,7 +503,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> let ty_predicates = tcx.predicates_of(did).predicates; for (p, _) in ty_predicates { - if let PredicateKind::Clause(ClauseKind::Trait(p)) = p.kind().skip_binder() + if let ClauseKind::Trait(p) = p.kind().skip_binder() && p.trait_ref.def_id == eq_trait_id && let ty::Param(self_ty) = p.trait_ref.self_ty().kind() && p.constness == BoundConstness::NotConst @@ -514,13 +514,13 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> } ParamEnv::new( - tcx.mk_predicates_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain( + tcx.mk_clauses_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain( params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| { - tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(ClauseKind::Trait(TraitPredicate { + ClauseKind::Trait(TraitPredicate { trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]), constness: BoundConstness::NotConst, polarity: ImplPolarity::Positive, - })))) + }).to_predicate(tcx) }), )), Reveal::UserFacing, diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index cf85d3174dba..0699997d0d2b 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -16,7 +16,7 @@ use rustc_hir::{ }; use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; -use rustc_middle::ty::{self, AssocKind, ClauseKind, EarlyBinder, GenericArg, GenericArgKind, PredicateKind, Ty}; +use rustc_middle::ty::{self, AssocKind, ClauseKind, EarlyBinder, GenericArg, GenericArgKind, Ty}; use rustc_span::symbol::Ident; use rustc_span::{sym, Span, Symbol}; @@ -175,7 +175,7 @@ fn check_collect_into_intoiterator<'tcx>( .caller_bounds() .into_iter() .filter_map(|p| { - if let PredicateKind::Clause(ClauseKind::Trait(t)) = p.kind().skip_binder() + if let ClauseKind::Trait(t) = p.kind().skip_binder() && cx.tcx.is_diagnostic_item(sym::IntoIterator,t.trait_ref.def_id) { Some(t.self_ty()) } else { diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 06fa95cd657d..80eb00a1b42d 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -14,7 +14,7 @@ use rustc_lint::LateContext; use rustc_middle::mir::Mutability; use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef}; -use rustc_middle::ty::{self, ClauseKind, EarlyBinder, ParamTy, PredicateKind, ProjectionPredicate, TraitPredicate, Ty}; +use rustc_middle::ty::{self, ClauseKind, EarlyBinder, ParamTy, ProjectionPredicate, TraitPredicate, Ty}; use rustc_span::{sym, Symbol}; use rustc_trait_selection::traits::{query::evaluate_obligation::InferCtxtExt as _, Obligation, ObligationCause}; @@ -345,12 +345,12 @@ fn get_input_traits_and_projections<'tcx>( let mut projection_predicates = Vec::new(); for predicate in cx.tcx.param_env(callee_def_id).caller_bounds() { match predicate.kind().skip_binder() { - PredicateKind::Clause(ClauseKind::Trait(trait_predicate)) => { + ClauseKind::Trait(trait_predicate) => { if trait_predicate.trait_ref.self_ty() == input { trait_predicates.push(trait_predicate); } }, - PredicateKind::Clause(ClauseKind::Projection(projection_predicate)) => { + ClauseKind::Projection(projection_predicate) => { if projection_predicate.projection_ty.self_ty() == input { projection_predicates.push(projection_predicate); } @@ -407,7 +407,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< let mut trait_predicates = cx.tcx.param_env(callee_def_id) .caller_bounds().iter().filter(|predicate| { - if let PredicateKind::Clause(ClauseKind::Trait(trait_predicate)) + if let ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() && trait_predicate.trait_ref.self_ty() == *param_ty { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 3773975e9554..c0970048cdfe 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -126,7 +126,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { .filter_map(|pred| { // Note that we do not want to deal with qualified predicates here. match pred.kind().no_bound_vars() { - Some(ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred))) if pred.def_id() != sized_trait => { + Some(ty::ClauseKind::Trait(pred)) if pred.def_id() != sized_trait => { Some(pred) }, _ => None, diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index a375e5d5b4ca..99a1d197678b 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -4,7 +4,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::{Closure, Expr, ExprKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; -use rustc_middle::ty::{ClauseKind, GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate}; +use rustc_middle::ty::{ClauseKind, GenericPredicates, ProjectionPredicate, TraitPredicate}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, BytePos, Span}; @@ -45,7 +45,7 @@ fn get_trait_predicates_for_trait_id<'tcx>( let mut preds = Vec::new(); for (pred, _) in generics.predicates { if_chain! { - if let PredicateKind::Clause(ClauseKind::Trait(poly_trait_pred)) = pred.kind().skip_binder(); + if let ClauseKind::Trait(poly_trait_pred) = pred.kind().skip_binder(); let trait_pred = cx.tcx.erase_late_bound_regions(pred.kind().rebind(poly_trait_pred)); if let Some(trait_def_id) = trait_id; if trait_def_id == trait_pred.trait_ref.def_id; @@ -63,7 +63,7 @@ fn get_projection_pred<'tcx>( trait_pred: TraitPredicate<'tcx>, ) -> Option> { generics.predicates.iter().find_map(|(proj_pred, _)| { - if let ty::PredicateKind::Clause(ClauseKind::Projection(pred)) = proj_pred.kind().skip_binder() { + if let ClauseKind::Projection(pred) = proj_pred.kind().skip_binder() { let projection_pred = cx.tcx.erase_late_bound_regions(proj_pred.kind().rebind(pred)); if projection_pred.projection_ty.substs == trait_pred.trait_ref.substs { return Some(projection_pred); diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index a42b2ccee889..659c693f87ae 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -15,7 +15,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{def_id::DefId, Block, Expr, ExprKind, QPath, UnOp}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, PredicateKind}; +use rustc_middle::ty; use rustc_span::{sym, Symbol}; use std::cmp; use std::ops; @@ -73,7 +73,7 @@ fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg: .flat_map(|v| v.fields.iter()) .any(|x| matches!(cx.tcx.type_of(x.did).subst_identity().peel_refs().kind(), ty::Param(_))) && all_predicates_of(cx.tcx, fn_id).all(|(pred, _)| match pred.kind().skip_binder() { - PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => cx.tcx.trait_def(pred.trait_ref.def_id).is_marker, + ty::ClauseKind::Trait(pred) => cx.tcx.trait_def(pred.trait_ref.def_id).is_marker, _ => true, }) && subs.types().all(|x| matches!(x.peel_refs().kind(), ty::Param(_))) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index a10eb8646af5..b7e83ce6caac 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -21,35 +21,6 @@ type McfResult = Result<(), (Span, Cow<'static, str>)>; pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv) -> McfResult { let def_id = body.source.def_id(); - let mut current = def_id; - loop { - let predicates = tcx.predicates_of(current); - for (predicate, _) in predicates.predicates { - match predicate.kind().skip_binder() { - ty::PredicateKind::Clause( - ty::ClauseKind::RegionOutlives(_) - | ty::ClauseKind::TypeOutlives(_) - | ty::ClauseKind::Projection(_) - | ty::ClauseKind::Trait(..) - | ty::ClauseKind::ConstArgHasType(..), - ) - | ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) - | ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..)) - | ty::PredicateKind::ConstEquate(..) - | ty::PredicateKind::TypeWellFormedFromEnv(..) => continue, - ty::PredicateKind::AliasRelate(..) => panic!("alias relate predicate on function: {predicate:#?}"), - ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {predicate:#?}"), - ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {predicate:#?}"), - ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {predicate:#?}"), - ty::PredicateKind::Coerce(_) => panic!("coerce predicate on function: {predicate:#?}"), - ty::PredicateKind::Ambiguous => panic!("ambiguous predicate on function: {predicate:#?}"), - } - } - match predicates.parent { - Some(parent) => current = parent, - None => break, - } - } for local in &body.local_decls { check_ty(tcx, local.ty, local.source_info.span)?; diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 2b185943c59c..8d3aecd4785b 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -17,7 +17,7 @@ use rustc_lint::LateContext; use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::ty::{ self, layout::ValidityRequirement, AdtDef, AliasTy, AssocKind, Binder, BoundRegion, FnSig, IntTy, List, ParamEnv, - Predicate, PredicateKind, Region, RegionKind, SubstsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, + Region, RegionKind, SubstsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, UintTy, VariantDef, VariantDiscr, }; use rustc_middle::ty::{GenericArg, GenericArgKind}; @@ -563,7 +563,7 @@ fn is_uninit_value_valid_for_ty_fallback<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t } /// Gets an iterator over all predicates which apply to the given item. -pub fn all_predicates_of(tcx: TyCtxt<'_>, id: DefId) -> impl Iterator, Span)> { +pub fn all_predicates_of(tcx: TyCtxt<'_>, id: DefId) -> impl Iterator, Span)> { let mut next_id = Some(id); iter::from_fn(move || { next_id.take().map(|id| { @@ -665,7 +665,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option sig_from_bounds( cx, ty, - cx.tcx.item_bounds(def_id).subst_iter(cx.tcx, substs).map(|c| c.as_predicate()), + cx.tcx.item_bounds(def_id).subst_iter(cx.tcx, substs), cx.tcx.opt_parent(def_id), ), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), @@ -698,7 +698,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option( cx: &LateContext<'tcx>, ty: Ty<'tcx>, - predicates: impl IntoIterator>, + predicates: impl IntoIterator>, predicates_id: Option, ) -> Option> { let mut inputs = None; @@ -707,7 +707,7 @@ fn sig_from_bounds<'tcx>( for pred in predicates { match pred.kind().skip_binder() { - PredicateKind::Clause(ty::ClauseKind::Trait(p)) + ty::ClauseKind::Trait(p) if (lang_items.fn_trait() == Some(p.def_id()) || lang_items.fn_mut_trait() == Some(p.def_id()) || lang_items.fn_once_trait() == Some(p.def_id())) @@ -720,7 +720,7 @@ fn sig_from_bounds<'tcx>( } inputs = Some(i); }, - PredicateKind::Clause(ty::ClauseKind::Projection(p)) + ty::ClauseKind::Projection(p) if Some(p.projection_ty.def_id) == lang_items.fn_once_output() && p.projection_ty.self_ty() == ty => { if output.is_some() { @@ -937,7 +937,7 @@ pub fn adt_and_variant_of_res<'tcx>(cx: &LateContext<'tcx>, res: Res) -> Option< } /// Checks if the type is a type parameter implementing `FnOnce`, but not `FnMut`. -pub fn ty_is_fn_once_param<'tcx>(tcx: TyCtxt<'_>, ty: Ty<'tcx>, predicates: &'tcx [Predicate<'_>]) -> bool { +pub fn ty_is_fn_once_param<'tcx>(tcx: TyCtxt<'_>, ty: Ty<'tcx>, predicates: &'tcx [ty::Clause<'_>]) -> bool { let ty::Param(ty) = *ty.kind() else { return false; }; @@ -950,7 +950,7 @@ pub fn ty_is_fn_once_param<'tcx>(tcx: TyCtxt<'_>, ty: Ty<'tcx>, predicates: &'tc predicates .iter() .try_fold(false, |found, p| { - if let PredicateKind::Clause(ty::ClauseKind::Trait(p)) = p.kind().skip_binder() + if let ty::ClauseKind::Trait(p) = p.kind().skip_binder() && let ty::Param(self_ty) = p.trait_ref.self_ty().kind() && ty.index == self_ty.index { From f901bec3f51e7b73e1e83c41442a4c5df374fa88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Fri, 23 Jun 2023 05:56:09 +0800 Subject: [PATCH 0867/1222] Provide more context for `rustc +nightly -Zunstable-options` on stable --- src/driver.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/driver.rs b/src/driver.rs index 3c5b6e12b968..f3cc94aeff01 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -16,6 +16,8 @@ extern crate rustc_session; extern crate rustc_span; use rustc_interface::interface; +use rustc_session::EarlyErrorHandler; +use rustc_session::config::ErrorOutputType; use rustc_session::parse::ParseSess; use rustc_span::symbol::Symbol; @@ -187,7 +189,9 @@ const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust-clippy/issues/ne #[allow(clippy::too_many_lines)] pub fn main() { - rustc_driver::init_rustc_env_logger(); + let handler = EarlyErrorHandler::new(ErrorOutputType::default()); + + rustc_driver::init_rustc_env_logger(&handler); rustc_driver::install_ice_hook(BUG_REPORT_URL, |handler| { // FIXME: this macro calls unwrap internally but is called in a panicking context! It's not From 28cb9c02a6c167b853c606bb7d44da4e51f00e60 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Sun, 2 Jul 2023 14:59:44 +0200 Subject: [PATCH 0868/1222] Fix valtree changes --- clippy_utils/src/consts.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 068820801dfe..dd3cda8ec527 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -725,8 +725,8 @@ fn field_of_struct<'tcx>( result: mir::ConstantKind<'tcx>, field: &Ident, ) -> Option> { - let dc = lcx.tcx.destructure_mir_constant(lcx.param_env, result); - if let Some(dc_variant) = dc.variant + if let Some(dc) = lcx.tcx.try_destructure_mir_constant(lcx.param_env.and(result)) + && let Some(dc_variant) = dc.variant && let Some(variant) = adt_def.variants().get(dc_variant) && let Some(field_idx) = variant.fields.iter().position(|el| el.name == field.name) && let Some(dc_field) = dc.fields.get(field_idx) From ce2744eccd4801cf7c9cf82b4b3d3d22f96f04fa Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Sun, 2 Jul 2023 15:07:39 +0200 Subject: [PATCH 0869/1222] Fix compile-test tests to work with the new ui_test crate --- tests/compile-test.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/compile-test.rs b/tests/compile-test.rs index dce6f2fc2726..0fd37c640aef 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -31,7 +31,7 @@ fn base_config(test_dir: &str) -> compiletest::Config { }, dependencies_crate_manifest_path: Some("clippy_test_deps/Cargo.toml".into()), target: None, - out_dir: "target/ui_test".into(), + out_dir: PathBuf::from(std::env::var_os("CARGO_TARGET_DIR").unwrap_or("target".into())).join("ui_test"), ..compiletest::Config::rustc(Path::new("tests").join(test_dir)) }; @@ -116,10 +116,7 @@ fn run_ui_toml() { config.stderr_filter( ®ex::escape( - &std::path::Path::new(file!()) - .parent() - .unwrap() - .canonicalize() + &fs::canonicalize("tests") .unwrap() .parent() .unwrap() @@ -175,10 +172,7 @@ fn run_ui_cargo() { config.stderr_filter( ®ex::escape( - &std::path::Path::new(file!()) - .parent() - .unwrap() - .canonicalize() + &fs::canonicalize("tests") .unwrap() .parent() .unwrap() From 91f389623a82057968f1cf95dc129e1592ac5a95 Mon Sep 17 00:00:00 2001 From: Boxy Date: Tue, 4 Jul 2023 15:41:45 +0100 Subject: [PATCH 0870/1222] Deal with fallout --- clippy_utils/src/consts.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index dd3cda8ec527..1e1bb2a1d962 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -689,7 +689,7 @@ pub fn miri_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::ConstantKind<'t mir::ConstantKind::Val(ConstValue::ByRef { alloc, offset: _ }, _) => match result.ty().kind() { ty::Adt(adt_def, _) if adt_def.is_struct() => Some(Constant::Adt(result)), ty::Array(sub_type, len) => match sub_type.kind() { - ty::Float(FloatTy::F32) => match len.kind().try_to_target_usize(lcx.tcx) { + ty::Float(FloatTy::F32) => match len.try_to_target_usize(lcx.tcx) { Some(len) => alloc .inner() .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * usize::try_from(len).unwrap())) @@ -700,7 +700,7 @@ pub fn miri_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::ConstantKind<'t .map(Constant::Vec), _ => None, }, - ty::Float(FloatTy::F64) => match len.kind().try_to_target_usize(lcx.tcx) { + ty::Float(FloatTy::F64) => match len.try_to_target_usize(lcx.tcx) { Some(len) => alloc .inner() .inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * usize::try_from(len).unwrap())) From 043b94f1861a9a7477979d2b9927de94a868735b Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 5 Jul 2023 16:16:03 +0000 Subject: [PATCH 0871/1222] Patch clippy --- clippy_utils/src/consts.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index dd3cda8ec527..b7f62af75b81 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -725,13 +725,14 @@ fn field_of_struct<'tcx>( result: mir::ConstantKind<'tcx>, field: &Ident, ) -> Option> { - if let Some(dc) = lcx.tcx.try_destructure_mir_constant(lcx.param_env.and(result)) + if let mir::ConstantKind::Val(result, ty) = result + && let Some(dc) = lcx.tcx.try_destructure_mir_constant_for_diagnostics((result, ty)) && let Some(dc_variant) = dc.variant && let Some(variant) = adt_def.variants().get(dc_variant) && let Some(field_idx) = variant.fields.iter().position(|el| el.name == field.name) - && let Some(dc_field) = dc.fields.get(field_idx) + && let Some(&(val, ty)) = dc.fields.get(field_idx) { - Some(*dc_field) + Some(mir::ConstantKind::Val(val, ty)) } else { None From c694f9ee2bc894c8e2431f97e190bf7347488274 Mon Sep 17 00:00:00 2001 From: Boxy Date: Wed, 5 Jul 2023 20:13:26 +0100 Subject: [PATCH 0872/1222] Move `TyCtxt::mk_x` to `Ty::new_x` where applicable --- clippy_lints/src/bool_assert_comparison.rs | 2 +- clippy_lints/src/loops/explicit_iter_loop.rs | 4 ++-- clippy_lints/src/methods/needless_collect.rs | 4 ++-- clippy_lints/src/methods/unnecessary_to_owned.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- clippy_lints/src/ptr.rs | 4 ++-- clippy_lints/src/redundant_slicing.rs | 3 ++- clippy_lints/src/transmute/transmute_ptr_to_ptr.rs | 2 +- clippy_lints/src/transmute/transmute_ref_to_ref.rs | 4 ++-- clippy_lints/src/transmute/useless_transmute.rs | 2 +- clippy_utils/src/ty.rs | 4 ++-- 11 files changed, 18 insertions(+), 17 deletions(-) diff --git a/clippy_lints/src/bool_assert_comparison.rs b/clippy_lints/src/bool_assert_comparison.rs index 8c3ad24eeed4..e8775b081444 100644 --- a/clippy_lints/src/bool_assert_comparison.rs +++ b/clippy_lints/src/bool_assert_comparison.rs @@ -61,7 +61,7 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) - ) }) .map_or(false, |assoc_item| { - let proj = cx.tcx.mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(ty, [])); + let proj = Ty::new_projection(cx.tcx,assoc_item.def_id, cx.tcx.mk_substs_trait(ty, [])); let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj); nty.is_bool() diff --git a/clippy_lints/src/loops/explicit_iter_loop.rs b/clippy_lints/src/loops/explicit_iter_loop.rs index f3347e33077b..5c5a4cfce884 100644 --- a/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_iter_loop.rs @@ -149,7 +149,7 @@ fn is_ref_iterable<'tcx>( let self_ty = if mutbl.is_mut() { self_ty } else { - cx.tcx.mk_ref(region, TypeAndMut { ty, mutbl }) + Ty::new_ref(cx.tcx,region, TypeAndMut { ty, mutbl }) }; if implements_trait(cx, self_ty, trait_id, &[]) && let Some(ty) = @@ -164,7 +164,7 @@ fn is_ref_iterable<'tcx>( && !self_ty.is_ref() { // Attempt to borrow - let self_ty = cx.tcx.mk_ref(cx.tcx.lifetimes.re_erased, TypeAndMut { + let self_ty = Ty::new_ref(cx.tcx,cx.tcx.lifetimes.re_erased, TypeAndMut { ty: self_ty, mutbl, }); diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index ac209d014062..8ca7af8107f6 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -215,7 +215,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty: && let Some(into_iter_item_proj) = make_projection(cx.tcx, into_iter_trait, item, [collect_ty]) && let Ok(into_iter_item_ty) = cx.tcx.try_normalize_erasing_regions( cx.param_env, - cx.tcx.mk_projection(into_iter_item_proj.def_id, into_iter_item_proj.substs) + Ty::new_projection(cx.tcx,into_iter_item_proj.def_id, into_iter_item_proj.substs) ) { iter_item_ty == into_iter_item_ty @@ -238,7 +238,7 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) - .associated_items(iter_trait) .find_by_name_and_kind(cx.tcx, Ident::with_dummy_span(Symbol::intern("Item")), AssocKind::Type, iter_trait) && let substs = cx.tcx.mk_substs(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))]) - && let proj_ty = cx.tcx.mk_projection(iter_item.def_id, substs) + && let proj_ty = Ty::new_projection(cx.tcx,iter_item.def_id, substs) && let Ok(item_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, proj_ty) { item_ty == EarlyBinder::bind(search_ty).subst(cx.tcx, cx.typeck_results().node_substs(call_id)) diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 16ef24bd4e34..6bd5e9e88c84 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -270,7 +270,7 @@ fn check_other_call_arg<'tcx>( if let Some((n_refs, receiver_ty)) = if n_refs > 0 || is_copy(cx, receiver_ty) { Some((n_refs, receiver_ty)) } else if trait_predicate.def_id() != deref_trait_id { - Some((1, cx.tcx.mk_ref( + Some((1, Ty::new_ref(cx.tcx, cx.tcx.lifetimes.re_erased, ty::TypeAndMut { ty: receiver_ty, diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index ece10474715f..f11d5773d041 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -17,7 +17,7 @@ use rustc_hir_typeck::expr_use_visitor as euv; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::FakeReadCause; -use rustc_middle::ty::{self, TypeVisitableExt}; +use rustc_middle::ty::{self, TypeVisitableExt, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::kw; @@ -168,7 +168,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { ( preds.iter().any(|t| cx.tcx.is_diagnostic_item(sym::Borrow, t.def_id())), !preds.is_empty() && { - let ty_empty_region = cx.tcx.mk_imm_ref(cx.tcx.lifetimes.re_erased, ty); + let ty_empty_region = Ty::new_imm_ref(cx.tcx,cx.tcx.lifetimes.re_erased, ty); preds.iter().all(|t| { let ty_params = t.trait_ref.substs.iter().skip(1).collect::>(); implements_trait(cx, ty_empty_region, t.def_id(), &ty_params) diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 866a04466c90..32213718b270 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -389,11 +389,11 @@ impl<'tcx> DerefTy<'tcx> { fn ty(&self, cx: &LateContext<'tcx>) -> Ty<'tcx> { match *self { Self::Str => cx.tcx.types.str_, - Self::Path => cx.tcx.mk_adt( + Self::Path => Ty::new_adt(cx.tcx, cx.tcx.adt_def(cx.tcx.get_diagnostic_item(sym::Path).unwrap()), List::empty(), ), - Self::Slice(_, ty) => cx.tcx.mk_slice(ty), + Self::Slice(_, ty) => Ty::new_slice(cx.tcx,ty), } } diff --git a/clippy_lints/src/redundant_slicing.rs b/clippy_lints/src/redundant_slicing.rs index 2fdd775ad489..c70ce83a9c45 100644 --- a/clippy_lints/src/redundant_slicing.rs +++ b/clippy_lints/src/redundant_slicing.rs @@ -7,6 +7,7 @@ use rustc_ast::util::parser::PREC_PREFIX; use rustc_errors::Applicability; use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability}; use rustc_lint::{LateContext, LateLintPass, Lint}; +use rustc_middle::ty::Ty; use rustc_middle::ty::adjustment::{Adjust, AutoBorrow, AutoBorrowMutability}; use rustc_middle::ty::subst::GenericArg; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -134,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing { } else if let Some(target_id) = cx.tcx.lang_items().deref_target() { if let Ok(deref_ty) = cx.tcx.try_normalize_erasing_regions( cx.param_env, - cx.tcx.mk_projection(target_id, cx.tcx.mk_substs(&[GenericArg::from(indexed_ty)])), + Ty::new_projection(cx.tcx,target_id, cx.tcx.mk_substs(&[GenericArg::from(indexed_ty)])), ) { if deref_ty == expr_ty { let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0; diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs index 31a9b69ca158..857d2ad82588 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs @@ -24,7 +24,7 @@ pub(super) fn check<'tcx>( "transmute from a pointer to a pointer", |diag| { if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) { - let sugg = arg.as_ty(cx.tcx.mk_ptr(*to_ty)); + let sugg = arg.as_ty(Ty::new_ptr(cx.tcx,*to_ty)); diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified); } }, diff --git a/clippy_lints/src/transmute/transmute_ref_to_ref.rs b/clippy_lints/src/transmute/transmute_ref_to_ref.rs index 426c7253806e..ea9ad99618ab 100644 --- a/clippy_lints/src/transmute/transmute_ref_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ref_to_ref.rs @@ -64,8 +64,8 @@ pub(super) fn check<'tcx>( }; let ty_to_and_mut = ty::TypeAndMut { ty: *ty_to, mutbl: *to_mutbl }; let sugg_paren = arg - .as_ty(cx.tcx.mk_ptr(ty_from_and_mut)) - .as_ty(cx.tcx.mk_ptr(ty_to_and_mut)); + .as_ty(Ty::new_ptr(cx.tcx,ty_from_and_mut)) + .as_ty(Ty::new_ptr(cx.tcx,ty_to_and_mut)); let sugg = if *to_mutbl == Mutability::Mut { sugg_paren.mut_addr_deref() } else { diff --git a/clippy_lints/src/transmute/useless_transmute.rs b/clippy_lints/src/transmute/useless_transmute.rs index 56207fe767c5..b6615410e257 100644 --- a/clippy_lints/src/transmute/useless_transmute.rs +++ b/clippy_lints/src/transmute/useless_transmute.rs @@ -43,7 +43,7 @@ pub(super) fn check<'tcx>( let sugg = if *ptr_ty == rty_and_mut { arg.as_ty(to_ty) } else { - arg.as_ty(cx.tcx.mk_ptr(rty_and_mut)).as_ty(to_ty) + arg.as_ty(Ty::new_ptr(cx.tcx,rty_and_mut)).as_ty(to_ty) }; diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified); diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 9c39d22c61b2..d650cbe0b132 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -1124,7 +1124,7 @@ pub fn make_normalized_projection<'tcx>( ); return None; } - match tcx.try_normalize_erasing_regions(param_env, tcx.mk_projection(ty.def_id, ty.substs)) { + match tcx.try_normalize_erasing_regions(param_env, Ty::new_projection(tcx,ty.def_id, ty.substs)) { Ok(ty) => Some(ty), Err(e) => { debug_assert!(false, "failed to normalize type `{ty}`: {e:#?}"); @@ -1207,7 +1207,7 @@ pub fn make_normalized_projection_with_regions<'tcx>( .infer_ctxt() .build() .at(&cause, param_env) - .query_normalize(tcx.mk_projection(ty.def_id, ty.substs)) + .query_normalize(Ty::new_projection(tcx,ty.def_id, ty.substs)) { Ok(ty) => Some(ty.value), Err(e) => { From c6034e79b0eb6cb83b96daf2056cb88fbb89d37e Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Wed, 5 Jul 2023 20:07:03 +0200 Subject: [PATCH 0873/1222] Rename `adjustment::PointerCast` and variants using it to `PointerCoercion` It makes it sound like the `ExprKind` and `Rvalue` are supposed to represent all pointer related casts, when in reality their just used to share a some enum variants. Make it clear there these are only coercion to make it clear why only some pointer related "casts" are in the enum. --- clippy_lints/src/derivable_impls.rs | 4 ++-- clippy_lints/src/pass_by_ref_or_value.rs | 4 ++-- clippy_utils/src/qualify_min_const_fn.rs | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index ec0ca50cfec7..020ffe7f8fa2 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -9,7 +9,7 @@ use rustc_hir::{ Body, Expr, ExprKind, GenericArg, Impl, ImplItemKind, Item, ItemKind, Node, PathSegment, QPath, TyKind, }; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::adjustment::{Adjust, PointerCast}; +use rustc_middle::ty::adjustment::{Adjust, PointerCoercion}; use rustc_middle::ty::{self, Adt, AdtDef, SubstsRef, Ty, TypeckResults}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::sym; @@ -116,7 +116,7 @@ fn check_struct<'tcx>( let is_default_without_adjusts = |expr| { is_default_equivalent(cx, expr) && typeck_results.expr_adjustments(expr).iter().all(|adj| { - !matches!(adj.kind, Adjust::Pointer(PointerCast::Unsize) + !matches!(adj.kind, Adjust::Pointer(PointerCoercion::Unsize) if contains_trait_object(adj.target)) }) }; diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 0d78c3048ba1..eab725de17f6 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -14,7 +14,7 @@ use rustc_hir as hir; use rustc_hir::intravisit::FnKind; use rustc_hir::{BindingAnnotation, Body, FnDecl, Impl, ItemKind, MutTy, Mutability, Node, PatKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::adjustment::{Adjust, PointerCast}; +use rustc_middle::ty::adjustment::{Adjust, PointerCoercion}; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, RegionKind}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -195,7 +195,7 @@ impl<'tcx> PassByRefOrValue { .adjustments() .items() .flat_map(|(_, a)| a) - .any(|a| matches!(a.kind, Adjust::Pointer(PointerCast::UnsafeFnPointer))) + .any(|a| matches!(a.kind, Adjust::Pointer(PointerCoercion::UnsafeFnPointer))) { continue; } diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index c9938caefb06..fbf4ab2722e6 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -16,7 +16,7 @@ use rustc_middle::mir::{ }; use rustc_middle::traits::{ImplSource, ObligationCause}; use rustc_middle::ty::subst::GenericArgKind; -use rustc_middle::ty::{self, adjustment::PointerCast, Ty, TyCtxt}; +use rustc_middle::ty::{self, adjustment::PointerCoercion, Ty, TyCtxt}; use rustc_middle::ty::{BoundConstness, TraitRef}; use rustc_semver::RustcVersion; use rustc_span::symbol::sym; @@ -119,18 +119,18 @@ fn check_rvalue<'tcx>( | CastKind::FloatToFloat | CastKind::FnPtrToPtr | CastKind::PtrToPtr - | CastKind::Pointer(PointerCast::MutToConstPointer | PointerCast::ArrayToPointer), + | CastKind::PointerCoercion(PointerCoercion::MutToConstPointer | PointerCoercion::ArrayToPointer), operand, _, ) => check_operand(tcx, operand, span, body), Rvalue::Cast( - CastKind::Pointer( - PointerCast::UnsafeFnPointer | PointerCast::ClosureFnPointer(_) | PointerCast::ReifyFnPointer, + CastKind::PointerCoercion( + PointerCoercion::UnsafeFnPointer | PointerCoercion::ClosureFnPointer(_) | PointerCoercion::ReifyFnPointer, ), _, _, ) => Err((span, "function pointer casts are not allowed in const fn".into())), - Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), op, cast_ty) => { + Rvalue::Cast(CastKind::PointerCoercion(PointerCoercion::Unsize), op, cast_ty) => { let pointee_ty = if let Some(deref_ty) = cast_ty.builtin_deref(true) { deref_ty.ty } else { From 3a10ba7c34e91f1491866938a1b287df9636e6d3 Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Fri, 7 Jul 2023 18:18:25 +0000 Subject: [PATCH 0874/1222] Fix failing clippy tests Comments out the C string literals due to https://github.com/rust-lang/rust/pull/113334 Fixes https://github.com/rust-lang/rust-clippy/issues/11121 --- clippy_lints/src/incorrect_impls.rs | 2 +- tests/ui/needless_raw_string.fixed | 7 ++++--- tests/ui/needless_raw_string.rs | 7 ++++--- tests/ui/needless_raw_string.stderr | 8 +------- tests/ui/needless_raw_string_hashes.fixed | 9 +++++---- tests/ui/needless_raw_string_hashes.rs | 9 +++++---- tests/ui/needless_raw_string_hashes.stderr | 20 +------------------- 7 files changed, 21 insertions(+), 41 deletions(-) diff --git a/clippy_lints/src/incorrect_impls.rs b/clippy_lints/src/incorrect_impls.rs index 13cc0b23ba33..7b95116ee4e3 100644 --- a/clippy_lints/src/incorrect_impls.rs +++ b/clippy_lints/src/incorrect_impls.rs @@ -82,7 +82,7 @@ impl LateLintPass<'_> for IncorrectImpls { cx, hir_ty_to_ty(cx.tcx, imp.self_ty), copy_def_id, - trait_impl.substs, + &[], ) { if impl_item.ident.name == sym::clone { diff --git a/tests/ui/needless_raw_string.fixed b/tests/ui/needless_raw_string.fixed index 6438e46977bb..b36912efbb2d 100644 --- a/tests/ui/needless_raw_string.fixed +++ b/tests/ui/needless_raw_string.fixed @@ -10,7 +10,8 @@ fn main() { b"aaa"; br#""aaa""#; br#"\s"#; - c"aaa"; - cr#""aaa""#; - cr#"\s"#; + // currently disabled: https://github.com/rust-lang/rust/issues/113333 + // cr#"aaa"#; + // cr#""aaa""#; + // cr#"\s"#; } diff --git a/tests/ui/needless_raw_string.rs b/tests/ui/needless_raw_string.rs index f7ddc68265ed..8f48e7dab2a6 100644 --- a/tests/ui/needless_raw_string.rs +++ b/tests/ui/needless_raw_string.rs @@ -10,7 +10,8 @@ fn main() { br#"aaa"#; br#""aaa""#; br#"\s"#; - cr#"aaa"#; - cr#""aaa""#; - cr#"\s"#; + // currently disabled: https://github.com/rust-lang/rust/issues/113333 + // cr#"aaa"#; + // cr#""aaa""#; + // cr#"\s"#; } diff --git a/tests/ui/needless_raw_string.stderr b/tests/ui/needless_raw_string.stderr index 0179978b7b08..cfb07b647d7c 100644 --- a/tests/ui/needless_raw_string.stderr +++ b/tests/ui/needless_raw_string.stderr @@ -12,11 +12,5 @@ error: unnecessary raw string literal LL | br#"aaa"#; | ^^^^^^^^^ help: try: `b"aaa"` -error: unnecessary raw string literal - --> $DIR/needless_raw_string.rs:13:5 - | -LL | cr#"aaa"#; - | ^^^^^^^^^ help: try: `c"aaa"` - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors diff --git a/tests/ui/needless_raw_string_hashes.fixed b/tests/ui/needless_raw_string_hashes.fixed index e4d7d8fb017a..c8507c727151 100644 --- a/tests/ui/needless_raw_string_hashes.fixed +++ b/tests/ui/needless_raw_string_hashes.fixed @@ -12,8 +12,9 @@ fn main() { br#"Hello "world"!"#; br####" "### "## "# "####; br###" "aa" "# "## "###; - cr#"aaa"#; - cr#"Hello "world"!"#; - cr####" "### "## "# "####; - cr###" "aa" "# "## "###; + // currently disabled: https://github.com/rust-lang/rust/issues/113333 + // cr#"aaa"#; + // cr##"Hello "world"!"##; + // cr######" "### "## "# "######; + // cr######" "aa" "# "## "######; } diff --git a/tests/ui/needless_raw_string_hashes.rs b/tests/ui/needless_raw_string_hashes.rs index e2d85c52e78c..912fbde1679d 100644 --- a/tests/ui/needless_raw_string_hashes.rs +++ b/tests/ui/needless_raw_string_hashes.rs @@ -12,8 +12,9 @@ fn main() { br##"Hello "world"!"##; br######" "### "## "# "######; br######" "aa" "# "## "######; - cr#"aaa"#; - cr##"Hello "world"!"##; - cr######" "### "## "# "######; - cr######" "aa" "# "## "######; + // currently disabled: https://github.com/rust-lang/rust/issues/113333 + // cr#"aaa"#; + // cr##"Hello "world"!"##; + // cr######" "### "## "# "######; + // cr######" "aa" "# "## "######; } diff --git a/tests/ui/needless_raw_string_hashes.stderr b/tests/ui/needless_raw_string_hashes.stderr index dff47a2d0421..30e6783a38e8 100644 --- a/tests/ui/needless_raw_string_hashes.stderr +++ b/tests/ui/needless_raw_string_hashes.stderr @@ -36,23 +36,5 @@ error: unnecessary hashes around raw string literal LL | br######" "aa" "# "## "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `br###" "aa" "# "## "###` -error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:16:5 - | -LL | cr##"Hello "world"!"##; - | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `cr#"Hello "world"!"#` - -error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:17:5 - | -LL | cr######" "### "## "# "######; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cr####" "### "## "# "####` - -error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:18:5 - | -LL | cr######" "aa" "# "## "######; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cr###" "aa" "# "## "###` - -error: aborting due to 9 previous errors +error: aborting due to 6 previous errors From 1fe014158af68a7da23083b5e503406f44f451a9 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sat, 8 Jul 2023 17:17:40 +0200 Subject: [PATCH 0875/1222] Delete `to_string_in_format_args_incremental.rs` It fails CI and passes locally. It passes random directores in `-Cincremental` so maybe something's up. It shouldn't block us here. --- tests/ui/to_string_in_format_args_incremental.rs | 9 --------- tests/ui/to_string_in_format_args_incremental.stderr | 10 ---------- 2 files changed, 19 deletions(-) delete mode 100644 tests/ui/to_string_in_format_args_incremental.rs delete mode 100644 tests/ui/to_string_in_format_args_incremental.stderr diff --git a/tests/ui/to_string_in_format_args_incremental.rs b/tests/ui/to_string_in_format_args_incremental.rs deleted file mode 100644 index 67115f7c5a7b..000000000000 --- a/tests/ui/to_string_in_format_args_incremental.rs +++ /dev/null @@ -1,9 +0,0 @@ -//@run-rustfix -//@compile-flags: -C incremental=target/debug/test/incr - -// see https://github.com/rust-lang/rust-clippy/issues/10969 - -fn main() { - let s = "Hello, world!"; - println!("{}", s.to_string()); -} diff --git a/tests/ui/to_string_in_format_args_incremental.stderr b/tests/ui/to_string_in_format_args_incremental.stderr deleted file mode 100644 index a992c5429149..000000000000 --- a/tests/ui/to_string_in_format_args_incremental.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/to_string_in_format_args_incremental.rs:8:21 - | -LL | println!("{}", s.to_string()); - | ^^^^^^^^^^^^ help: remove this - | - = note: `-D clippy::to-string-in-format-args` implied by `-D warnings` - -error: aborting due to previous error - From 829ffd898465072cf5defd794db9091ae6ce925e Mon Sep 17 00:00:00 2001 From: Urgau Date: Wed, 17 May 2023 20:01:36 +0200 Subject: [PATCH 0876/1222] Drop uplifted `clippy::fn_null_check` --- clippy_lints/src/declared_lints.rs | 1 - clippy_lints/src/fn_null_check.rs | 102 -------------------------- clippy_lints/src/lib.rs | 2 - clippy_lints/src/renamed_lints.rs | 1 + tests/ui/fn_null_check.rs | 22 ------ tests/ui/fn_null_check.stderr | 43 ----------- tests/ui/rename.fixed | 2 + tests/ui/rename.rs | 2 + tests/ui/rename.stderr | 112 +++++++++++++++-------------- 9 files changed, 64 insertions(+), 223 deletions(-) delete mode 100644 clippy_lints/src/fn_null_check.rs delete mode 100644 tests/ui/fn_null_check.rs delete mode 100644 tests/ui/fn_null_check.stderr diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 9d9ee6ba3079..b60f0738f649 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -171,7 +171,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::float_literal::LOSSY_FLOAT_LITERAL_INFO, crate::floating_point_arithmetic::IMPRECISE_FLOPS_INFO, crate::floating_point_arithmetic::SUBOPTIMAL_FLOPS_INFO, - crate::fn_null_check::FN_NULL_CHECK_INFO, crate::format::USELESS_FORMAT_INFO, crate::format_args::FORMAT_IN_FORMAT_ARGS_INFO, crate::format_args::TO_STRING_IN_FORMAT_ARGS_INFO, diff --git a/clippy_lints/src/fn_null_check.rs b/clippy_lints/src/fn_null_check.rs deleted file mode 100644 index 521045a9fed8..000000000000 --- a/clippy_lints/src/fn_null_check.rs +++ /dev/null @@ -1,102 +0,0 @@ -use clippy_utils::consts::{constant, Constant}; -use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::{is_integer_literal, is_path_diagnostic_item}; -use rustc_hir::{BinOpKind, Expr, ExprKind, TyKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::sym; - -declare_clippy_lint! { - /// ### What it does - /// Checks for comparing a function pointer to null. - /// - /// ### Why is this bad? - /// Function pointers are assumed to not be null. - /// - /// ### Example - /// ```rust,ignore - /// let fn_ptr: fn() = /* somehow obtained nullable function pointer */ - /// - /// if (fn_ptr as *const ()).is_null() { ... } - /// ``` - /// Use instead: - /// ```rust,ignore - /// let fn_ptr: Option = /* somehow obtained nullable function pointer */ - /// - /// if fn_ptr.is_none() { ... } - /// ``` - #[clippy::version = "1.68.0"] - pub FN_NULL_CHECK, - correctness, - "`fn()` type assumed to be nullable" -} -declare_lint_pass!(FnNullCheck => [FN_NULL_CHECK]); - -fn lint_expr(cx: &LateContext<'_>, expr: &Expr<'_>) { - span_lint_and_help( - cx, - FN_NULL_CHECK, - expr.span, - "function pointer assumed to be nullable, even though it isn't", - None, - "try wrapping your function pointer type in `Option` instead, and using `is_none` to check for null pointer value", - ); -} - -fn is_fn_ptr_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - if let ExprKind::Cast(cast_expr, cast_ty) = expr.kind - && let TyKind::Ptr(_) = cast_ty.kind - { - cx.typeck_results().expr_ty_adjusted(cast_expr).is_fn() - } else { - false - } -} - -impl<'tcx> LateLintPass<'tcx> for FnNullCheck { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - match expr.kind { - // Catching: - // (fn_ptr as * ).is_null() - ExprKind::MethodCall(method_name, receiver, _, _) - if method_name.ident.as_str() == "is_null" && is_fn_ptr_cast(cx, receiver) => - { - lint_expr(cx, expr); - }, - - ExprKind::Binary(op, left, right) if matches!(op.node, BinOpKind::Eq) => { - let to_check: &Expr<'_>; - if is_fn_ptr_cast(cx, left) { - to_check = right; - } else if is_fn_ptr_cast(cx, right) { - to_check = left; - } else { - return; - } - - match to_check.kind { - // Catching: - // (fn_ptr as * ) == (0 as ) - ExprKind::Cast(cast_expr, _) if is_integer_literal(cast_expr, 0) => { - lint_expr(cx, expr); - }, - - // Catching: - // (fn_ptr as * ) == std::ptr::null() - ExprKind::Call(func, []) if is_path_diagnostic_item(cx, func, sym::ptr_null) => { - lint_expr(cx, expr); - }, - - // Catching: - // (fn_ptr as * ) == - _ if matches!(constant(cx, cx.typeck_results(), to_check), Some(Constant::RawPtr(0))) => { - lint_expr(cx, expr); - }, - - _ => {}, - } - }, - _ => {}, - } - } -} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 87329ee5e14a..365cc4c59ad4 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -131,7 +131,6 @@ mod extra_unused_type_parameters; mod fallible_impl_from; mod float_literal; mod floating_point_arithmetic; -mod fn_null_check; mod format; mod format_args; mod format_impl; @@ -1003,7 +1002,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: semicolon_outside_block_ignore_multiline, )) }); - store.register_late_pass(|_| Box::new(fn_null_check::FnNullCheck)); store.register_late_pass(|_| Box::new(permissions_set_readonly_false::PermissionsSetReadonlyFalse)); store.register_late_pass(|_| Box::new(size_of_ref::SizeOfRef)); store.register_late_pass(|_| Box::new(multiple_unsafe_ops_per_block::MultipleUnsafeOpsPerBlock)); diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index cbcd11debfd7..d24215c22924 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -42,6 +42,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"), ("clippy::forget_copy", "forgetting_copy_types"), ("clippy::forget_ref", "forgetting_references"), + ("clippy::fn_null_check", "incorrect_fn_null_checks"), ("clippy::into_iter_on_array", "array_into_iter"), ("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"), ("clippy::invalid_ref", "invalid_value"), diff --git a/tests/ui/fn_null_check.rs b/tests/ui/fn_null_check.rs deleted file mode 100644 index dfdea100c8fd..000000000000 --- a/tests/ui/fn_null_check.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![allow(unused)] -#![warn(clippy::fn_null_check)] -#![allow(clippy::cmp_null)] -#![allow(clippy::needless_if)] -#![allow(clippy::ptr_eq)] -#![allow(clippy::zero_ptr)] - -pub const ZPTR: *const () = 0 as *const _; -pub const NOT_ZPTR: *const () = 1 as *const _; - -fn main() { - let fn_ptr = main; - - if (fn_ptr as *mut ()).is_null() {} - if (fn_ptr as *const u8).is_null() {} - if (fn_ptr as *const ()) == std::ptr::null() {} - if (fn_ptr as *const ()) == (0 as *const ()) {} - if (fn_ptr as *const ()) == ZPTR {} - - // no lint - if (fn_ptr as *const ()) == NOT_ZPTR {} -} diff --git a/tests/ui/fn_null_check.stderr b/tests/ui/fn_null_check.stderr deleted file mode 100644 index 5b9f48a961ca..000000000000 --- a/tests/ui/fn_null_check.stderr +++ /dev/null @@ -1,43 +0,0 @@ -error: function pointer assumed to be nullable, even though it isn't - --> $DIR/fn_null_check.rs:14:8 - | -LL | if (fn_ptr as *mut ()).is_null() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: try wrapping your function pointer type in `Option` instead, and using `is_none` to check for null pointer value - = note: `-D clippy::fn-null-check` implied by `-D warnings` - -error: function pointer assumed to be nullable, even though it isn't - --> $DIR/fn_null_check.rs:15:8 - | -LL | if (fn_ptr as *const u8).is_null() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: try wrapping your function pointer type in `Option` instead, and using `is_none` to check for null pointer value - -error: function pointer assumed to be nullable, even though it isn't - --> $DIR/fn_null_check.rs:16:8 - | -LL | if (fn_ptr as *const ()) == std::ptr::null() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: try wrapping your function pointer type in `Option` instead, and using `is_none` to check for null pointer value - -error: function pointer assumed to be nullable, even though it isn't - --> $DIR/fn_null_check.rs:17:8 - | -LL | if (fn_ptr as *const ()) == (0 as *const ()) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: try wrapping your function pointer type in `Option` instead, and using `is_none` to check for null pointer value - -error: function pointer assumed to be nullable, even though it isn't - --> $DIR/fn_null_check.rs:18:8 - | -LL | if (fn_ptr as *const ()) == ZPTR {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: try wrapping your function pointer type in `Option` instead, and using `is_none` to check for null pointer value - -error: aborting due to 5 previous errors - diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index b24c83d9a0da..cab02bb93c9c 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -37,6 +37,7 @@ #![allow(for_loops_over_fallibles)] #![allow(forgetting_copy_types)] #![allow(forgetting_references)] +#![allow(incorrect_fn_null_checks)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] @@ -89,6 +90,7 @@ #![warn(for_loops_over_fallibles)] #![warn(forgetting_copy_types)] #![warn(forgetting_references)] +#![warn(incorrect_fn_null_checks)] #![warn(array_into_iter)] #![warn(invalid_atomic_ordering)] #![warn(invalid_value)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index baa6345a64f8..e5e31452149d 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -37,6 +37,7 @@ #![allow(for_loops_over_fallibles)] #![allow(forgetting_copy_types)] #![allow(forgetting_references)] +#![allow(incorrect_fn_null_checks)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] @@ -89,6 +90,7 @@ #![warn(clippy::for_loops_over_fallibles)] #![warn(clippy::forget_copy)] #![warn(clippy::forget_ref)] +#![warn(clippy::fn_null_check)] #![warn(clippy::into_iter_on_array)] #![warn(clippy::invalid_atomic_ordering)] #![warn(clippy::invalid_ref)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index ae25c3b46bd2..783608a08410 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> $DIR/rename.rs:52:9 + --> $DIR/rename.rs:53:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -7,310 +7,316 @@ LL | #![warn(clippy::almost_complete_letter_range)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> $DIR/rename.rs:53:9 + --> $DIR/rename.rs:54:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:54:9 + --> $DIR/rename.rs:55:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:55:9 + --> $DIR/rename.rs:56:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> $DIR/rename.rs:56:9 + --> $DIR/rename.rs:57:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:57:9 + --> $DIR/rename.rs:58:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:58:9 + --> $DIR/rename.rs:59:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> $DIR/rename.rs:59:9 + --> $DIR/rename.rs:60:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> $DIR/rename.rs:60:9 + --> $DIR/rename.rs:61:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> $DIR/rename.rs:61:9 + --> $DIR/rename.rs:62:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> $DIR/rename.rs:62:9 + --> $DIR/rename.rs:63:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> $DIR/rename.rs:63:9 + --> $DIR/rename.rs:64:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> $DIR/rename.rs:64:9 + --> $DIR/rename.rs:65:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::integer_arithmetic` has been renamed to `clippy::arithmetic_side_effects` - --> $DIR/rename.rs:65:9 + --> $DIR/rename.rs:66:9 | LL | #![warn(clippy::integer_arithmetic)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::arithmetic_side_effects` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:66:9 + --> $DIR/rename.rs:67:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:67:9 + --> $DIR/rename.rs:68:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:69:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:79:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:80:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::cast_ref_to_mut` has been renamed to `cast_ref_to_mut` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::cast_ref_to_mut)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `cast_ref_to_mut` error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:83:9 | LL | #![warn(clippy::clone_double_ref)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op` error: lint `clippy::cmp_nan` has been renamed to `invalid_nan_comparisons` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::cmp_nan)] | ^^^^^^^^^^^^^^^ help: use the new name: `invalid_nan_comparisons` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:84:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` error: lint `clippy::drop_copy` has been renamed to `dropping_copy_types` - --> $DIR/rename.rs:85:9 + --> $DIR/rename.rs:86:9 | LL | #![warn(clippy::drop_copy)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `dropping_copy_types` error: lint `clippy::drop_ref` has been renamed to `dropping_references` - --> $DIR/rename.rs:86:9 + --> $DIR/rename.rs:87:9 | LL | #![warn(clippy::drop_ref)] | ^^^^^^^^^^^^^^^^ help: use the new name: `dropping_references` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:87:9 + --> $DIR/rename.rs:88:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:88:9 + --> $DIR/rename.rs:89:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:89:9 + --> $DIR/rename.rs:90:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::forget_copy` has been renamed to `forgetting_copy_types` - --> $DIR/rename.rs:90:9 + --> $DIR/rename.rs:91:9 | LL | #![warn(clippy::forget_copy)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_copy_types` error: lint `clippy::forget_ref` has been renamed to `forgetting_references` - --> $DIR/rename.rs:91:9 + --> $DIR/rename.rs:92:9 | LL | #![warn(clippy::forget_ref)] | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references` +error: lint `clippy::fn_null_check` has been renamed to `incorrect_fn_null_checks` + --> $DIR/rename.rs:93:9 + | +LL | #![warn(clippy::fn_null_check)] + | ^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `incorrect_fn_null_checks` + error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:92:9 + --> $DIR/rename.rs:94:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:93:9 + --> $DIR/rename.rs:95:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:94:9 + --> $DIR/rename.rs:96:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::invalid_utf8_in_unchecked` has been renamed to `invalid_from_utf8_unchecked` - --> $DIR/rename.rs:95:9 + --> $DIR/rename.rs:97:9 | LL | #![warn(clippy::invalid_utf8_in_unchecked)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_from_utf8_unchecked` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:96:9 + --> $DIR/rename.rs:98:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:97:9 + --> $DIR/rename.rs:99:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:98:9 + --> $DIR/rename.rs:100:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:99:9 + --> $DIR/rename.rs:101:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:100:9 + --> $DIR/rename.rs:102:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::undropped_manually_drops` has been renamed to `undropped_manually_drops` - --> $DIR/rename.rs:101:9 + --> $DIR/rename.rs:103:9 | LL | #![warn(clippy::undropped_manually_drops)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `undropped_manually_drops` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:102:9 + --> $DIR/rename.rs:104:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:103:9 + --> $DIR/rename.rs:105:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 52 previous errors +error: aborting due to 53 previous errors From b4c4eb218557015530678b279c63c9481af4f8be Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 12 Jul 2023 06:59:57 -0700 Subject: [PATCH 0877/1222] Ignore flaky clippy tests. --- tests/ui/empty_line_after_doc_comments.rs | 3 +++ tests/ui/empty_line_after_outer_attribute.rs | 3 +++ tests/ui/needless_arbitrary_self_type_unfixable.rs | 3 +++ 3 files changed, 9 insertions(+) diff --git a/tests/ui/empty_line_after_doc_comments.rs b/tests/ui/empty_line_after_doc_comments.rs index 83db2a07d334..cc36ce5f4879 100644 --- a/tests/ui/empty_line_after_doc_comments.rs +++ b/tests/ui/empty_line_after_doc_comments.rs @@ -1,4 +1,7 @@ //@aux-build:proc_macro_attr.rs:proc-macro +// Flaky test, see https://github.com/rust-lang/rust/issues/113585. +//@ignore-32bit +//@ignore-64bit #![warn(clippy::empty_line_after_doc_comments)] #![allow(clippy::assertions_on_constants)] #![feature(custom_inner_attributes)] diff --git a/tests/ui/empty_line_after_outer_attribute.rs b/tests/ui/empty_line_after_outer_attribute.rs index b2d7ddae4274..bc54e0fd2de1 100644 --- a/tests/ui/empty_line_after_outer_attribute.rs +++ b/tests/ui/empty_line_after_outer_attribute.rs @@ -1,4 +1,7 @@ //@aux-build:proc_macro_attr.rs:proc-macro +// Flaky test, see https://github.com/rust-lang/rust/issues/113585. +//@ignore-32bit +//@ignore-64bit #![warn(clippy::empty_line_after_outer_attr)] #![allow(clippy::assertions_on_constants)] #![feature(custom_inner_attributes)] diff --git a/tests/ui/needless_arbitrary_self_type_unfixable.rs b/tests/ui/needless_arbitrary_self_type_unfixable.rs index 876f16a3854d..321aa69a1a52 100644 --- a/tests/ui/needless_arbitrary_self_type_unfixable.rs +++ b/tests/ui/needless_arbitrary_self_type_unfixable.rs @@ -1,4 +1,7 @@ //@aux-build:proc_macro_attr.rs:proc-macro +// Flaky test, see https://github.com/rust-lang/rust/issues/113585. +//@ignore-32bit +//@ignore-64bit #![warn(clippy::needless_arbitrary_self_type)] From 6bafa681827117d9b901f8bc7beffb4769015dfc Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 8 Jun 2023 18:47:44 +0200 Subject: [PATCH 0878/1222] Rename cast_ref_to_mut to invalid_reference_casting (clippy side) --- clippy_lints/src/renamed_lints.rs | 2 +- tests/ui/rename.fixed | 4 ++-- tests/ui/rename.rs | 2 +- tests/ui/rename.stderr | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index d24215c22924..e532dd61a829 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -31,7 +31,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::stutter", "clippy::module_name_repetitions"), ("clippy::to_string_in_display", "clippy::recursive_format_impl"), ("clippy::zero_width_space", "clippy::invisible_characters"), - ("clippy::cast_ref_to_mut", "cast_ref_to_mut"), + ("clippy::cast_ref_to_mut", "invalid_reference_casting"), ("clippy::clone_double_ref", "suspicious_double_ref_op"), ("clippy::cmp_nan", "invalid_nan_comparisons"), ("clippy::drop_bounds", "drop_bounds"), diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index cab02bb93c9c..03d9ea41a0b1 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -28,9 +28,9 @@ #![allow(clippy::module_name_repetitions)] #![allow(clippy::recursive_format_impl)] #![allow(clippy::invisible_characters)] -#![allow(cast_ref_to_mut)] #![allow(suspicious_double_ref_op)] #![allow(invalid_nan_comparisons)] +#![allow(invalid_reference_casting)] #![allow(drop_bounds)] #![allow(dropping_copy_types)] #![allow(dropping_references)] @@ -79,7 +79,7 @@ #![warn(clippy::module_name_repetitions)] #![warn(clippy::recursive_format_impl)] #![warn(clippy::invisible_characters)] -#![warn(cast_ref_to_mut)] +#![warn(invalid_reference_casting)] #![warn(suspicious_double_ref_op)] #![warn(invalid_nan_comparisons)] #![warn(drop_bounds)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index e5e31452149d..c028fcb5a376 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -28,9 +28,9 @@ #![allow(clippy::module_name_repetitions)] #![allow(clippy::recursive_format_impl)] #![allow(clippy::invisible_characters)] -#![allow(cast_ref_to_mut)] #![allow(suspicious_double_ref_op)] #![allow(invalid_nan_comparisons)] +#![allow(invalid_reference_casting)] #![allow(drop_bounds)] #![allow(dropping_copy_types)] #![allow(dropping_references)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 783608a08410..4d8a7fd70f45 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -174,11 +174,11 @@ error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_ch LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` -error: lint `clippy::cast_ref_to_mut` has been renamed to `cast_ref_to_mut` +error: lint `clippy::cast_ref_to_mut` has been renamed to `invalid_reference_casting` --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::cast_ref_to_mut)] - | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `cast_ref_to_mut` + | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_reference_casting` error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op` --> $DIR/rename.rs:83:9 From 02f68a08127d74901a2a560dbae496211336097c Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Tue, 11 Jul 2023 22:35:29 +0100 Subject: [PATCH 0879/1222] refactor(rustc_middle): Substs -> GenericArg --- .../src/assertions_on_result_states.rs | 6 +- clippy_lints/src/bool_assert_comparison.rs | 2 +- clippy_lints/src/casts/as_ptr_cast_mut.rs | 2 +- clippy_lints/src/casts/cast_ptr_alignment.rs | 2 +- clippy_lints/src/copy_iterator.rs | 2 +- clippy_lints/src/default.rs | 8 +- clippy_lints/src/default_numeric_fallback.rs | 8 +- clippy_lints/src/dereference.rs | 46 +++++----- clippy_lints/src/derivable_impls.rs | 14 ++-- clippy_lints/src/derive.rs | 12 +-- clippy_lints/src/empty_enum.rs | 2 +- clippy_lints/src/enum_clike.rs | 2 +- clippy_lints/src/eta_reduction.rs | 28 +++---- clippy_lints/src/from_over_into.rs | 4 +- clippy_lints/src/functions/must_use.rs | 6 +- clippy_lints/src/functions/result.rs | 6 +- clippy_lints/src/future_not_send.rs | 4 +- clippy_lints/src/implicit_saturating_sub.rs | 4 +- clippy_lints/src/inherent_impl.rs | 2 +- .../src/iter_not_returning_iterator.rs | 2 +- clippy_lints/src/large_enum_variant.rs | 6 +- clippy_lints/src/len_zero.rs | 4 +- clippy_lints/src/let_underscore.rs | 2 +- clippy_lints/src/loops/explicit_iter_loop.rs | 2 +- clippy_lints/src/loops/missing_spin_loop.rs | 2 +- clippy_lints/src/loops/needless_range_loop.rs | 2 +- clippy_lints/src/manual_bits.rs | 2 +- .../src/manual_slice_size_calculation.rs | 2 +- clippy_lints/src/map_unit_fn.rs | 2 +- clippy_lints/src/matches/match_as_ref.rs | 8 +- .../src/matches/redundant_pattern_match.rs | 2 +- .../matches/rest_pat_in_fully_bound_struct.rs | 2 +- .../matches/significant_drop_in_scrutinee.rs | 2 +- .../src/methods/bytes_count_to_len.rs | 2 +- ...se_sensitive_file_extension_comparisons.rs | 2 +- clippy_lints/src/methods/err_expect.rs | 2 +- clippy_lints/src/methods/expect_fun_call.rs | 4 +- clippy_lints/src/methods/flat_map_option.rs | 2 +- clippy_lints/src/methods/get_first.rs | 2 +- clippy_lints/src/methods/implicit_clone.rs | 2 +- .../src/methods/inefficient_to_string.rs | 8 +- clippy_lints/src/methods/manual_ok_or.rs | 2 +- clippy_lints/src/methods/map_clone.rs | 2 +- .../src/methods/map_collect_result_unit.rs | 4 +- clippy_lints/src/methods/map_err_ignore.rs | 2 +- clippy_lints/src/methods/map_flatten.rs | 2 +- clippy_lints/src/methods/mod.rs | 8 +- clippy_lints/src/methods/mut_mutex_lock.rs | 2 +- clippy_lints/src/methods/needless_collect.rs | 14 ++-- clippy_lints/src/methods/ok_expect.rs | 2 +- clippy_lints/src/methods/open_options.rs | 2 +- .../src/methods/path_buf_push_overwrite.rs | 2 +- .../src/methods/stable_sort_primitive.rs | 2 +- clippy_lints/src/methods/suspicious_splitn.rs | 2 +- .../src/methods/unnecessary_sort_by.rs | 4 +- .../src/methods/unnecessary_to_owned.rs | 38 ++++----- clippy_lints/src/methods/utils.rs | 2 +- .../src/methods/vec_resize_to_zero.rs | 2 +- clippy_lints/src/mut_key.rs | 6 +- clippy_lints/src/mut_reference.rs | 4 +- clippy_lints/src/needless_pass_by_value.rs | 4 +- clippy_lints/src/new_without_default.rs | 6 +- clippy_lints/src/non_copy_const.rs | 20 ++--- .../src/non_send_fields_in_send_ty.rs | 14 ++-- clippy_lints/src/only_used_in_recursion.rs | 18 ++-- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/ptr.rs | 14 ++-- clippy_lints/src/redundant_slicing.rs | 4 +- clippy_lints/src/returns.rs | 4 +- clippy_lints/src/self_named_constructors.rs | 2 +- .../src/significant_drop_tightening.rs | 2 +- clippy_lints/src/size_of_in_element_count.rs | 4 +- .../src/transmute/transmute_undefined_repr.rs | 8 +- .../transmute/unsound_collection_transmute.rs | 6 +- clippy_lints/src/uninit_vec.rs | 4 +- clippy_lints/src/unit_return_expecting_ord.rs | 8 +- clippy_lints/src/unit_types/let_unit_value.rs | 2 +- clippy_lints/src/unnamed_address.rs | 2 +- clippy_lints/src/use_self.rs | 10 +-- clippy_lints/src/useless_conversion.rs | 8 +- .../interning_defined_symbol.rs | 2 +- .../utils/internal_lints/msrv_attr_impl.rs | 4 +- .../internal_lints/unnecessary_def_path.rs | 4 +- clippy_lints/src/vec.rs | 4 +- clippy_lints/src/zero_sized_map_values.rs | 4 +- clippy_utils/src/consts.rs | 16 ++-- clippy_utils/src/eager_or_lazy.rs | 6 +- clippy_utils/src/lib.rs | 10 +-- clippy_utils/src/qualify_min_const_fn.rs | 4 +- clippy_utils/src/sugg.rs | 2 +- clippy_utils/src/ty.rs | 84 +++++++++---------- tests/ui/crashes/ice-6256.rs | 2 +- tests/ui/eta.fixed | 2 +- tests/ui/eta.rs | 2 +- 94 files changed, 307 insertions(+), 307 deletions(-) diff --git a/clippy_lints/src/assertions_on_result_states.rs b/clippy_lints/src/assertions_on_result_states.rs index f6d6c23bb6ed..2980c9d6db3d 100644 --- a/clippy_lints/src/assertions_on_result_states.rs +++ b/clippy_lints/src/assertions_on_result_states.rs @@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates { && let result_type_with_refs = cx.typeck_results().expr_ty(recv) && let result_type = result_type_with_refs.peel_refs() && is_type_diagnostic_item(cx, result_type, sym::Result) - && let ty::Adt(_, substs) = result_type.kind() + && let ty::Adt(_, args) = result_type.kind() { if !is_copy(cx, result_type) { if result_type_with_refs != result_type { @@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates { let semicolon = if is_expr_final_block_expr(cx.tcx, e) {";"} else {""}; let mut app = Applicability::MachineApplicable; match method_segment.ident.as_str() { - "is_ok" if type_suitable_to_unwrap(cx, substs.type_at(1)) => { + "is_ok" if type_suitable_to_unwrap(cx, args.type_at(1)) => { span_lint_and_sugg( cx, ASSERTIONS_ON_RESULT_STATES, @@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates { app, ); } - "is_err" if type_suitable_to_unwrap(cx, substs.type_at(0)) => { + "is_err" if type_suitable_to_unwrap(cx, args.type_at(0)) => { span_lint_and_sugg( cx, ASSERTIONS_ON_RESULT_STATES, diff --git a/clippy_lints/src/bool_assert_comparison.rs b/clippy_lints/src/bool_assert_comparison.rs index e8775b081444..d984fddc57ae 100644 --- a/clippy_lints/src/bool_assert_comparison.rs +++ b/clippy_lints/src/bool_assert_comparison.rs @@ -61,7 +61,7 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) - ) }) .map_or(false, |assoc_item| { - let proj = Ty::new_projection(cx.tcx,assoc_item.def_id, cx.tcx.mk_substs_trait(ty, [])); + let proj = Ty::new_projection(cx.tcx,assoc_item.def_id, cx.tcx.mk_args_trait(ty, [])); let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj); nty.is_bool() diff --git a/clippy_lints/src/casts/as_ptr_cast_mut.rs b/clippy_lints/src/casts/as_ptr_cast_mut.rs index 1633ffd589c3..fa1550a0ef9b 100644 --- a/clippy_lints/src/casts/as_ptr_cast_mut.rs +++ b/clippy_lints/src/casts/as_ptr_cast_mut.rs @@ -17,7 +17,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, && let ExprKind::MethodCall(method_name, receiver, [], _) = cast_expr.peel_blocks().kind && method_name.ident.name == rustc_span::sym::as_ptr && let Some(as_ptr_did) = cx.typeck_results().type_dependent_def_id(cast_expr.peel_blocks().hir_id) - && let as_ptr_sig = cx.tcx.fn_sig(as_ptr_did).subst_identity() + && let as_ptr_sig = cx.tcx.fn_sig(as_ptr_did).instantiate_identity() && let Some(first_param_ty) = as_ptr_sig.skip_binder().inputs().iter().next() && let ty::Ref(_, _, Mutability::Not) = first_param_ty.kind() && let Some(recv) = snippet_opt(cx, receiver.span) diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index 6c8ee296c751..5bf467efa0f1 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -66,7 +66,7 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned") && let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id) && let Some(def_id) = cx.tcx.impl_of_method(def_id) - && cx.tcx.type_of(def_id).subst_identity().is_unsafe_ptr() + && cx.tcx.type_of(def_id).instantiate_identity().is_unsafe_ptr() { true } else { diff --git a/clippy_lints/src/copy_iterator.rs b/clippy_lints/src/copy_iterator.rs index 0fc11523298f..5d04ad0112d5 100644 --- a/clippy_lints/src/copy_iterator.rs +++ b/clippy_lints/src/copy_iterator.rs @@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyIterator { of_trait: Some(ref trait_ref), .. }) = item.kind; - let ty = cx.tcx.type_of(item.owner_id).subst_identity(); + let ty = cx.tcx.type_of(item.owner_id).instantiate_identity(); if is_copy(cx, ty); if let Some(trait_id) = trait_ref.trait_def_id(); if cx.tcx.is_diagnostic_item(sym::Iterator, trait_id); diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index 80c22742ba44..763ad0264ad9 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -150,7 +150,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { .fields .iter() .all(|field| { - is_copy(cx, cx.tcx.type_of(field.did).subst_identity()) + is_copy(cx, cx.tcx.type_of(field.did).instantiate_identity()) }); if !has_drop(cx, binding_type) || all_fields_are_copy; then { @@ -219,11 +219,11 @@ impl<'tcx> LateLintPass<'tcx> for Default { // give correct suggestion if generics are involved (see #6944) let binding_type = if_chain! { - if let ty::Adt(adt_def, substs) = binding_type.kind(); - if !substs.is_empty(); + if let ty::Adt(adt_def, args) = binding_type.kind(); + if !args.is_empty(); then { let adt_def_ty_name = cx.tcx.item_name(adt_def.did()); - let generic_args = substs.iter().collect::>(); + let generic_args = args.iter().collect::>(); let tys_str = generic_args .iter() .map(ToString::to_string) diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index e53a9877b20c..9217edcef071 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -141,7 +141,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { ExprKind::MethodCall(_, receiver, args, _) => { if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) { - let fn_sig = self.cx.tcx.fn_sig(def_id).subst_identity().skip_binder(); + let fn_sig = self.cx.tcx.fn_sig(def_id).instantiate_identity().skip_binder(); for (expr, bound) in iter::zip(std::iter::once(*receiver).chain(args.iter()), fn_sig.inputs()) { self.ty_bounds.push((*bound).into()); self.visit_expr(expr); @@ -167,7 +167,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { .iter() .find_map(|f_def| { if f_def.ident(self.cx.tcx) == field.ident - { Some(self.cx.tcx.type_of(f_def.did).subst_identity()) } + { Some(self.cx.tcx.type_of(f_def.did).instantiate_identity()) } else { None } }); self.ty_bounds.push(bound.into()); @@ -213,9 +213,9 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option> { let node_ty = cx.typeck_results().node_type_opt(hir_id)?; - // We can't use `Ty::fn_sig` because it automatically performs substs, this may result in FNs. + // We can't use `Ty::fn_sig` because it automatically performs args, this may result in FNs. match node_ty.kind() { - ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(*def_id).subst_identity()), + ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(*def_id).instantiate_identity()), ty::FnPtr(fn_sig) => Some(*fn_sig), _ => None, } diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 73556c1053ec..0e7efd53390c 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -739,7 +739,7 @@ fn walk_parents<'tcx>( span, .. }) if span.ctxt() == ctxt => { - let ty = cx.tcx.type_of(owner_id.def_id).subst_identity(); + let ty = cx.tcx.type_of(owner_id.def_id).instantiate_identity(); Some(ty_auto_deref_stability(cx.tcx, cx.param_env, ty, precedence).position_for_result(cx)) }, @@ -763,7 +763,7 @@ fn walk_parents<'tcx>( }) if span.ctxt() == ctxt => { let output = cx .tcx - .erase_late_bound_regions(cx.tcx.fn_sig(owner_id).subst_identity().output()); + .erase_late_bound_regions(cx.tcx.fn_sig(owner_id).instantiate_identity().output()); Some(ty_auto_deref_stability(cx.tcx, cx.param_env, output, precedence).position_for_result(cx)) }, @@ -785,7 +785,7 @@ fn walk_parents<'tcx>( cx.tcx, // Use the param_env of the target type. cx.tcx.param_env(adt.did()), - cx.tcx.type_of(field_def.did).subst_identity(), + cx.tcx.type_of(field_def.did).instantiate_identity(), precedence, ) .position_for_arg() @@ -808,7 +808,7 @@ fn walk_parents<'tcx>( } else { let output = cx .tcx - .erase_late_bound_regions(cx.tcx.fn_sig(owner_id).subst_identity().output()); + .erase_late_bound_regions(cx.tcx.fn_sig(owner_id).instantiate_identity().output()); ty_auto_deref_stability(cx.tcx, cx.param_env, output, precedence).position_for_result(cx) }, ) @@ -879,9 +879,9 @@ fn walk_parents<'tcx>( && let ty::Ref(_, sub_ty, _) = *arg_ty.kind() && let subs = cx .typeck_results() - .node_substs_opt(parent.hir_id).map(|subs| &subs[1..]).unwrap_or_default() + .node_args_opt(parent.hir_id).map(|subs| &subs[1..]).unwrap_or_default() && let impl_ty = if cx.tcx.fn_sig(fn_id) - .subst_identity() + .instantiate_identity() .skip_binder() .inputs()[0].is_ref() { @@ -905,7 +905,7 @@ fn walk_parents<'tcx>( return Some(Position::MethodReceiver); } args.iter().position(|arg| arg.hir_id == child_id).map(|i| { - let ty = cx.tcx.fn_sig(fn_id).subst_identity().input(i + 1); + let ty = cx.tcx.fn_sig(fn_id).instantiate_identity().input(i + 1); // `e.hir_id == child_id` for https://github.com/rust-lang/rust-clippy/issues/9739 // `method.args.is_none()` for https://github.com/rust-lang/rust-clippy/issues/9782 if e.hir_id == child_id @@ -1124,10 +1124,10 @@ fn needless_borrow_impl_arg_position<'tcx>( let sized_trait_def_id = cx.tcx.lang_items().sized_trait(); let Some(callee_def_id) = fn_def_id(cx, parent) else { return Position::Other(precedence) }; - let fn_sig = cx.tcx.fn_sig(callee_def_id).subst_identity().skip_binder(); - let substs_with_expr_ty = cx + let fn_sig = cx.tcx.fn_sig(callee_def_id).instantiate_identity().skip_binder(); + let args_with_expr_ty = cx .typeck_results() - .node_substs(if let ExprKind::Call(callee, _) = parent.kind { + .node_args(if let ExprKind::Call(callee, _) = parent.kind { callee.hir_id } else { parent.hir_id @@ -1181,9 +1181,9 @@ fn needless_borrow_impl_arg_position<'tcx>( return Position::Other(precedence); } - // `substs_with_referent_ty` can be constructed outside of `check_referent` because the same + // `args_with_referent_ty` can be constructed outside of `check_referent` because the same // elements are modified each time `check_referent` is called. - let mut substs_with_referent_ty = substs_with_expr_ty.to_vec(); + let mut args_with_referent_ty = args_with_expr_ty.to_vec(); let mut check_reference_and_referent = |reference, referent| { let referent_ty = cx.typeck_results().expr_ty(referent); @@ -1207,7 +1207,7 @@ fn needless_borrow_impl_arg_position<'tcx>( fn_sig, arg_index, &projection_predicates, - &mut substs_with_referent_ty, + &mut args_with_referent_ty, ) { return false; } @@ -1216,14 +1216,14 @@ fn needless_borrow_impl_arg_position<'tcx>( if let ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() && cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_predicate.trait_ref.def_id) && let ty::Param(param_ty) = trait_predicate.self_ty().kind() - && let GenericArgKind::Type(ty) = substs_with_referent_ty[param_ty.index as usize].unpack() + && let GenericArgKind::Type(ty) = args_with_referent_ty[param_ty.index as usize].unpack() && ty.is_array() && !msrv.meets(msrvs::ARRAY_INTO_ITERATOR) { return false; } - let predicate = EarlyBinder::bind(predicate).subst(cx.tcx, &substs_with_referent_ty); + let predicate = EarlyBinder::bind(predicate).instantiate(cx.tcx, &args_with_referent_ty); let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate); let infcx = cx.tcx.infer_ctxt().build(); infcx.predicate_must_hold_modulo_regions(&obligation) @@ -1252,7 +1252,7 @@ fn has_ref_mut_self_method(cx: &LateContext<'_>, trait_def_id: DefId) -> bool { .in_definition_order() .any(|assoc_item| { if assoc_item.fn_has_self_parameter { - let self_ty = cx.tcx.fn_sig(assoc_item.def_id).subst_identity().skip_binder().inputs()[0]; + let self_ty = cx.tcx.fn_sig(assoc_item.def_id).instantiate_identity().skip_binder().inputs()[0]; matches!(self_ty.kind(), ty::Ref(_, _, Mutability::Mut)) } else { false @@ -1323,7 +1323,7 @@ fn referent_used_exactly_once<'tcx>( } } -// Iteratively replaces `param_ty` with `new_ty` in `substs`, and similarly for each resulting +// Iteratively replaces `param_ty` with `new_ty` in `args`, and similarly for each resulting // projected type that is a type parameter. Returns `false` if replacing the types would have an // effect on the function signature beyond substituting `new_ty` for `param_ty`. // See: https://github.com/rust-lang/rust-clippy/pull/9136#discussion_r927212757 @@ -1334,11 +1334,11 @@ fn replace_types<'tcx>( fn_sig: FnSig<'tcx>, arg_index: usize, projection_predicates: &[ProjectionPredicate<'tcx>], - substs: &mut [ty::GenericArg<'tcx>], + args: &mut [ty::GenericArg<'tcx>], ) -> bool { - let mut replaced = BitSet::new_empty(substs.len()); + let mut replaced = BitSet::new_empty(args.len()); - let mut deque = VecDeque::with_capacity(substs.len()); + let mut deque = VecDeque::with_capacity(args.len()); deque.push_back((param_ty, new_ty)); while let Some((param_ty, new_ty)) = deque.pop_front() { @@ -1352,7 +1352,7 @@ fn replace_types<'tcx>( return false; } - substs[param_ty.index as usize] = ty::GenericArg::from(new_ty); + args[param_ty.index as usize] = ty::GenericArg::from(new_ty); // The `replaced.insert(...)` check provides some protection against infinite loops. if replaced.insert(param_ty.index) { @@ -1367,7 +1367,7 @@ fn replace_types<'tcx>( )); if let Ok(projected_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, projection) - && substs[term_param_ty.index as usize] != ty::GenericArg::from(projected_ty) + && args[term_param_ty.index as usize] != ty::GenericArg::from(projected_ty) { deque.push_back((*term_param_ty, projected_ty)); } @@ -1442,7 +1442,7 @@ fn ty_auto_deref_stability<'tcx>( ty::Adt(..) if ty.has_placeholders() || ty.has_opaque_types() => { Position::ReborrowStable(precedence).into() }, - ty::Adt(_, substs) if substs.has_non_region_param() => { + ty::Adt(_, args) if args.has_non_region_param() => { TyPosition::new_deref_stable_for_result(precedence, ty) }, ty::Bool diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index 020ffe7f8fa2..71b5104bed8e 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -10,7 +10,7 @@ use rustc_hir::{ }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, PointerCoercion}; -use rustc_middle::ty::{self, Adt, AdtDef, SubstsRef, Ty, TypeckResults}; +use rustc_middle::ty::{self, Adt, AdtDef, GenericArgsRef, Ty, TypeckResults}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::sym; @@ -80,7 +80,7 @@ fn is_path_self(e: &Expr<'_>) -> bool { fn contains_trait_object(ty: Ty<'_>) -> bool { match ty.kind() { ty::Ref(_, ty, _) => contains_trait_object(*ty), - ty::Adt(def, substs) => def.is_box() && substs[0].as_type().map_or(false, contains_trait_object), + ty::Adt(def, args) => def.is_box() && args[0].as_type().map_or(false, contains_trait_object), ty::Dynamic(..) => true, _ => false, } @@ -92,18 +92,18 @@ fn check_struct<'tcx>( self_ty: &hir::Ty<'_>, func_expr: &Expr<'_>, adt_def: AdtDef<'_>, - substs: SubstsRef<'_>, + ty_args: GenericArgsRef<'_>, typeck_results: &'tcx TypeckResults<'tcx>, ) { if let TyKind::Path(QPath::Resolved(_, p)) = self_ty.kind { if let Some(PathSegment { args, .. }) = p.segments.last() { let args = args.map(|a| a.args).unwrap_or(&[]); - // substs contains the generic parameters of the type declaration, while args contains the arguments + // ty_args contains the generic parameters of the type declaration, while args contains the arguments // used at instantiation time. If both len are not equal, it means that some parameters were not // provided (which means that the default values were used); in this case we will not risk // suggesting too broad a rewrite. We won't either if any argument is a type or a const. - if substs.len() != args.len() || args.iter().any(|arg| !matches!(arg, GenericArg::Lifetime(_))) { + if ty_args.len() != args.len() || args.iter().any(|arg| !matches!(arg, GenericArg::Lifetime(_))) { return; } } @@ -214,7 +214,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { if let Some(Node::ImplItem(impl_item)) = cx.tcx.hir().find(impl_item_hir); if let ImplItemKind::Fn(_, b) = &impl_item.kind; if let Body { value: func_expr, .. } = cx.tcx.hir().body(*b); - if let &Adt(adt_def, substs) = cx.tcx.type_of(item.owner_id).subst_identity().kind(); + if let &Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind(); if let attrs = cx.tcx.hir().attrs(item.hir_id()); if !attrs.iter().any(|attr| attr.doc_str().is_some()); if let child_attrs = cx.tcx.hir().attrs(impl_item_hir); @@ -222,7 +222,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { then { if adt_def.is_struct() { - check_struct(cx, item, self_ty, func_expr, adt_def, substs, cx.tcx.typeck_body(*b)); + check_struct(cx, item, self_ty, func_expr, adt_def, args, cx.tcx.typeck_body(*b)); } else if adt_def.is_enum() && self.msrv.meets(msrvs::DEFAULT_ENUM_ATTRIBUTE) { check_enum(cx, item, func_expr, adt_def); } diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index a005a360e9ce..78e7f93e2bfd 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -211,7 +211,7 @@ impl<'tcx> LateLintPass<'tcx> for Derive { .. }) = item.kind { - let ty = cx.tcx.type_of(item.owner_id).subst_identity(); + let ty = cx.tcx.type_of(item.owner_id).instantiate_identity(); let is_automatically_derived = cx.tcx.has_attr(item.owner_id, sym::automatically_derived); check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived); @@ -252,7 +252,7 @@ fn check_hash_peq<'tcx>( // Only care about `impl PartialEq for Foo` // For `impl PartialEq for A, input_types is [A, B] - if trait_ref.subst_identity().substs.type_at(1) == ty { + if trait_ref.instantiate_identity().args.type_at(1) == ty { span_lint_and_then( cx, DERIVED_HASH_WITH_MANUAL_EQ, @@ -300,7 +300,7 @@ fn check_ord_partial_ord<'tcx>( // Only care about `impl PartialOrd for Foo` // For `impl PartialOrd for A, input_types is [A, B] - if trait_ref.subst_identity().substs.type_at(1) == ty { + if trait_ref.instantiate_identity().args.type_at(1) == ty { let mess = if partial_ord_is_automatically_derived { "you are implementing `Ord` explicitly but have derived `PartialOrd`" } else { @@ -347,7 +347,7 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &h let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(©_id).map_or(false, |impls| { impls .iter() - .any(|&id| matches!(cx.tcx.type_of(id).subst_identity().kind(), ty::Adt(adt, _) if ty_adt.did() == adt.did())) + .any(|&id| matches!(cx.tcx.type_of(id).instantiate_identity().kind(), ty::Adt(adt, _) if ty_adt.did() == adt.did())) }); if !has_copy_impl { return; @@ -464,7 +464,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> { /// Implementation of the `DERIVE_PARTIAL_EQ_WITHOUT_EQ` lint. fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_ref: &hir::TraitRef<'_>, ty: Ty<'tcx>) { if_chain! { - if let ty::Adt(adt, substs) = ty.kind(); + if let ty::Adt(adt, args) = ty.kind(); if cx.tcx.visibility(adt.did()).is_public(); if let Some(eq_trait_def_id) = cx.tcx.get_diagnostic_item(sym::Eq); if let Some(def_id) = trait_ref.trait_def_id(); @@ -474,7 +474,7 @@ fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_r // If all of our fields implement `Eq`, we can implement `Eq` too if adt .all_fields() - .map(|f| f.ty(cx.tcx, substs)) + .map(|f| f.ty(cx.tcx, args)) .all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, [])); then { span_lint_and_sugg( diff --git a/clippy_lints/src/empty_enum.rs b/clippy_lints/src/empty_enum.rs index d94664daa561..1701d061128b 100644 --- a/clippy_lints/src/empty_enum.rs +++ b/clippy_lints/src/empty_enum.rs @@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for EmptyEnum { } if let ItemKind::Enum(..) = item.kind { - let ty = cx.tcx.type_of(item.owner_id).subst_identity(); + let ty = cx.tcx.type_of(item.owner_id).instantiate_identity(); let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); if adt.variants().is_empty() { span_lint_and_help( diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index d85650712db8..96c5c7fc5093 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant { for var in def.variants { if let Some(anon_const) = &var.disr_expr { let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body); - let mut ty = cx.tcx.type_of(def_id.to_def_id()).subst_identity(); + let mut ty = cx.tcx.type_of(def_id.to_def_id()).instantiate_identity(); let constant = cx .tcx .const_eval_poly(def_id.to_def_id()) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 58e62d1f3d37..22e10accd357 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -11,7 +11,7 @@ use rustc_hir::{Closure, Expr, ExprKind, Param, PatKind, Unsafety}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; use rustc_middle::ty::binding::BindingMode; -use rustc_middle::ty::{self, EarlyBinder, SubstsRef, Ty, TypeVisitableExt}; +use rustc_middle::ty::{self, EarlyBinder, GenericArgsRef, Ty, TypeVisitableExt}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; @@ -108,18 +108,18 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { if check_inputs(cx, body.params, None, args); let callee_ty = cx.typeck_results().expr_ty_adjusted(callee); let call_ty = cx.typeck_results().type_dependent_def_id(body.value.hir_id) - .map_or(callee_ty, |id| cx.tcx.type_of(id).subst_identity()); + .map_or(callee_ty, |id| cx.tcx.type_of(id).instantiate_identity()); if check_sig(cx, closure_ty, call_ty); - let substs = cx.typeck_results().node_substs(callee.hir_id); + let args = cx.typeck_results().node_args(callee.hir_id); // This fixes some false positives that I don't entirely understand - if substs.is_empty() || !cx.typeck_results().expr_ty(expr).has_late_bound_regions(); + if args.is_empty() || !cx.typeck_results().expr_ty(expr).has_late_bound_regions(); // A type param function ref like `T::f` is not 'static, however // it is if cast like `T::f as fn()`. This seems like a rustc bug. - if !substs.types().any(|t| matches!(t.kind(), ty::Param(_))); + if !args.types().any(|t| matches!(t.kind(), ty::Param(_))); let callee_ty_unadjusted = cx.typeck_results().expr_ty(callee).peel_refs(); if !is_type_diagnostic_item(cx, callee_ty_unadjusted, sym::Arc); if !is_type_diagnostic_item(cx, callee_ty_unadjusted, sym::Rc); - if let ty::Closure(_, substs) = *closure_ty.kind(); + if let ty::Closure(_, args) = *closure_ty.kind(); // Don't lint if this is an inclusive range expression. // They desugar to a call to `RangeInclusiveNew` which would have odd suggestions. (#10684) if !matches!(higher::Range::hir(body.value), Some(higher::Range { @@ -131,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure", |diag| { if let Some(mut snippet) = snippet_opt(cx, callee.span) { if let Some(fn_mut_id) = cx.tcx.lang_items().fn_mut_trait() - && let args = cx.tcx.erase_late_bound_regions(substs.as_closure().sig()).inputs() + && let args = cx.tcx.erase_late_bound_regions(args.as_closure().sig()).inputs() && implements_trait( cx, callee_ty.peel_refs(), @@ -160,12 +160,12 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { if let ExprKind::MethodCall(path, receiver, args, _) = body.value.kind; if check_inputs(cx, body.params, Some(receiver), args); let method_def_id = cx.typeck_results().type_dependent_def_id(body.value.hir_id).unwrap(); - let substs = cx.typeck_results().node_substs(body.value.hir_id); - let call_ty = cx.tcx.type_of(method_def_id).subst(cx.tcx, substs); + let args = cx.typeck_results().node_args(body.value.hir_id); + let call_ty = cx.tcx.type_of(method_def_id).instantiate(cx.tcx, args); if check_sig(cx, closure_ty, call_ty); then { span_lint_and_then(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure", |diag| { - let name = get_ufcs_type_name(cx, method_def_id, substs); + let name = get_ufcs_type_name(cx, method_def_id, args); diag.span_suggestion( expr.span, "replace the closure with the method itself", @@ -228,14 +228,14 @@ fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure_ty: Ty<'tcx>, call_ty: Ty<'tc if !closure_ty.has_late_bound_regions() { return true; } - let ty::Closure(_, substs) = closure_ty.kind() else { + let ty::Closure(_, args) = closure_ty.kind() else { return false; }; - let closure_sig = cx.tcx.signature_unclosure(substs.as_closure().sig(), Unsafety::Normal); + let closure_sig = cx.tcx.signature_unclosure(args.as_closure().sig(), Unsafety::Normal); cx.tcx.erase_late_bound_regions(closure_sig) == cx.tcx.erase_late_bound_regions(call_sig) } -fn get_ufcs_type_name<'tcx>(cx: &LateContext<'tcx>, method_def_id: DefId, substs: SubstsRef<'tcx>) -> String { +fn get_ufcs_type_name<'tcx>(cx: &LateContext<'tcx>, method_def_id: DefId, args: GenericArgsRef<'tcx>) -> String { let assoc_item = cx.tcx.associated_item(method_def_id); let def_id = assoc_item.container_id(cx.tcx); match assoc_item.container { @@ -251,7 +251,7 @@ fn get_ufcs_type_name<'tcx>(cx: &LateContext<'tcx>, method_def_id: DefId, substs | ty::Ref(..) | ty::Slice(_) | ty::Tuple(_) => { - format!("<{}>", EarlyBinder::bind(ty).subst(cx.tcx, substs)) + format!("<{}>", EarlyBinder::bind(ty).instantiate(cx.tcx, args)) }, _ => ty.to_string(), } diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index 92d67ef359dc..35061fc64c95 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -76,9 +76,9 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto { && let Some(into_trait_seg) = hir_trait_ref.path.segments.last() // `impl Into for self_ty` && let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args - && let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id).map(ty::EarlyBinder::subst_identity) + && let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id).map(ty::EarlyBinder::instantiate_identity) && cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id) - && !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Alias(ty::Opaque, _)) + && !matches!(middle_trait_ref.args.type_at(1).kind(), ty::Alias(ty::Opaque, _)) { span_lint_and_then( cx, diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index d0ad26282642..1b173de856b9 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -198,14 +198,14 @@ fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, tys: &mut DefIdSet) match *ty.kind() { // primitive types are never mutable ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false, - ty::Adt(adt, substs) => { + ty::Adt(adt, args) => { tys.insert(adt.did()) && !ty.is_freeze(cx.tcx, cx.param_env) || KNOWN_WRAPPER_TYS .iter() .any(|&sym| cx.tcx.is_diagnostic_item(sym, adt.did())) - && substs.types().any(|ty| is_mutable_ty(cx, ty, tys)) + && args.types().any(|ty| is_mutable_ty(cx, ty, tys)) }, - ty::Tuple(substs) => substs.iter().any(|ty| is_mutable_ty(cx, ty, tys)), + ty::Tuple(args) => args.iter().any(|ty| is_mutable_ty(cx, ty, tys)), ty::Array(ty, _) | ty::Slice(ty) => is_mutable_ty(cx, ty, tys), ty::RawPtr(ty::TypeAndMut { ty, mutbl }) | ty::Ref(_, ty, mutbl) => { mutbl == hir::Mutability::Mut || is_mutable_ty(cx, ty, tys) diff --git a/clippy_lints/src/functions/result.rs b/clippy_lints/src/functions/result.rs index fa2a9b30c058..90fc0d4f662e 100644 --- a/clippy_lints/src/functions/result.rs +++ b/clippy_lints/src/functions/result.rs @@ -21,11 +21,11 @@ fn result_err_ty<'tcx>( ) -> Option<(&'tcx hir::Ty<'tcx>, Ty<'tcx>)> { if !in_external_macro(cx.sess(), item_span) && let hir::FnRetTy::Return(hir_ty) = decl.output - && let ty = cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).subst_identity().output()) + && let ty = cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).instantiate_identity().output()) && is_type_diagnostic_item(cx, ty, sym::Result) - && let ty::Adt(_, substs) = ty.kind() + && let ty::Adt(_, args) = ty.kind() { - let err_ty = substs.type_at(1); + let err_ty = args.type_at(1); Some((hir_ty, err_ty)) } else { None diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 818ebd1134de..e54429aee8e8 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -63,10 +63,10 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { return; } let ret_ty = return_ty(cx, cx.tcx.hir().local_def_id_to_hir_id(fn_def_id).expect_owner()); - if let ty::Alias(ty::Opaque, AliasTy { def_id, substs, .. }) = *ret_ty.kind() { + if let ty::Alias(ty::Opaque, AliasTy { def_id, args, .. }) = *ret_ty.kind() { let preds = cx.tcx.explicit_item_bounds(def_id); let mut is_future = false; - for (p, _span) in preds.subst_iter_copied(cx.tcx, substs) { + for (p, _span) in preds.arg_iter_copied(cx.tcx, args) { if let Some(trait_pred) = p.as_trait_clause() { if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() { is_future = true; diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index 1e99b6faa6ca..b99d45446817 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -102,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { if let Some(const_id) = cx.typeck_results().type_dependent_def_id(cond_num_val.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(const_id); if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl - if cx.tcx.type_of(impl_id).subst_identity().is_integral(); + if cx.tcx.type_of(impl_id).instantiate_identity().is_integral(); then { print_lint_and_sugg(cx, var_name, expr) } @@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { if let Some(func_id) = cx.typeck_results().type_dependent_def_id(func.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(func_id); if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl - if cx.tcx.type_of(impl_id).subst_identity().is_integral(); + if cx.tcx.type_of(impl_id).instantiate_identity().is_integral(); then { print_lint_and_sugg(cx, var_name, expr) } diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index 7c41699f307a..3ac40401e898 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { ) }) { for impl_id in impl_ids.iter().map(|id| id.expect_local()) { - let impl_ty = cx.tcx.type_of(impl_id).subst_identity(); + let impl_ty = cx.tcx.type_of(impl_id).instantiate_identity(); match type_map.entry(impl_ty) { Entry::Vacant(e) => { // Store the id for the first impl block of this type. The span is retrieved lazily. diff --git a/clippy_lints/src/iter_not_returning_iterator.rs b/clippy_lints/src/iter_not_returning_iterator.rs index c924d7361ce3..bb100ec632e6 100644 --- a/clippy_lints/src/iter_not_returning_iterator.rs +++ b/clippy_lints/src/iter_not_returning_iterator.rs @@ -68,7 +68,7 @@ fn check_sig(cx: &LateContext<'_>, name: &str, sig: &FnSig<'_>, fn_id: LocalDefI if sig.decl.implicit_self.has_implicit_self() { let ret_ty = cx .tcx - .erase_late_bound_regions(cx.tcx.fn_sig(fn_id).subst_identity().output()); + .erase_late_bound_regions(cx.tcx.fn_sig(fn_id).instantiate_identity().output()); let ret_ty = cx .tcx .try_normalize_erasing_regions(cx.param_env, ret_ty) diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index 1c99bd2f3d02..693218f8a9c5 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -83,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant { return; } if let ItemKind::Enum(ref def, _) = item.kind { - let ty = cx.tcx.type_of(item.owner_id).subst_identity(); + let ty = cx.tcx.type_of(item.owner_id).instantiate_identity(); let Adt(adt, subst) = ty.kind() else { panic!("already checked whether this is an enum") }; @@ -169,8 +169,8 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant { } fn maybe_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { - if let Adt(_def, substs) = ty.kind() - && substs.types().next().is_some() + if let Adt(_def, args) = ty.kind() + && args.types().next().is_some() && let Some(copy_trait) = cx.tcx.lang_items().copy_trait() { return cx.tcx.non_blanket_impls_for_ty(copy_trait, ty).next().is_some(); diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 17bd89efaee0..83fa25c795a0 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -145,7 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero { if let Some(local_id) = ty_id.as_local(); let ty_hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_id); if !is_lint_allowed(cx, LEN_WITHOUT_IS_EMPTY, ty_hir_id); - if let Some(output) = parse_len_output(cx, cx.tcx.fn_sig(item.owner_id).subst_identity().skip_binder()); + if let Some(output) = parse_len_output(cx, cx.tcx.fn_sig(item.owner_id).instantiate_identity().skip_binder()); then { let (name, kind) = match cx.tcx.hir().find(ty_hir_id) { Some(Node::ForeignItem(x)) => (x.ident.name, "extern type"), @@ -425,7 +425,7 @@ fn check_for_is_empty( if !(is_empty.fn_has_self_parameter && check_is_empty_sig( cx, - cx.tcx.fn_sig(is_empty.def_id).subst_identity().skip_binder(), + cx.tcx.fn_sig(is_empty.def_id).instantiate_identity().skip_binder(), self_kind, output, )) => diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index e66141809208..b7a470020805 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -5,7 +5,7 @@ use clippy_utils::{is_must_use_func_call, paths}; use rustc_hir::{Local, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::subst::GenericArgKind; +use rustc_middle::ty::GenericArgKind; use rustc_middle::ty::IsSuggestable; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{BytePos, Span}; diff --git a/clippy_lints/src/loops/explicit_iter_loop.rs b/clippy_lints/src/loops/explicit_iter_loop.rs index 5c5a4cfce884..a84a0a6eeb82 100644 --- a/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_iter_loop.rs @@ -125,7 +125,7 @@ fn is_ref_iterable<'tcx>( } let res_ty = cx.tcx.erase_regions(EarlyBinder::bind(req_res_ty) - .subst(cx.tcx, typeck.node_substs(call_expr.hir_id))); + .instantiate(cx.tcx, typeck.node_args(call_expr.hir_id))); let mutbl = if let ty::Ref(_, _, mutbl) = *req_self_ty.kind() { Some(mutbl) } else { diff --git a/clippy_lints/src/loops/missing_spin_loop.rs b/clippy_lints/src/loops/missing_spin_loop.rs index 8412875b11b7..0e49f08d8989 100644 --- a/clippy_lints/src/loops/missing_spin_loop.rs +++ b/clippy_lints/src/loops/missing_spin_loop.rs @@ -35,7 +35,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, body: &' if let ExprKind::Block(Block { stmts: [], expr: None, ..}, _) = body.kind; if let ExprKind::MethodCall(method, callee, ..) = unpack_cond(cond).kind; if [sym::load, sym::compare_exchange, sym::compare_exchange_weak].contains(&method.ident.name); - if let ty::Adt(def, _substs) = cx.typeck_results().expr_ty(callee).kind(); + if let ty::Adt(def, _args) = cx.typeck_results().expr_ty(callee).kind(); if cx.tcx.is_diagnostic_item(sym::AtomicBool, def.did()); then { span_lint_and_sugg( diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index cb446567506a..2c20e9e86933 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -370,7 +370,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { ExprKind::MethodCall(_, receiver, args, _) => { let def_id = self.cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap(); for (ty, expr) in iter::zip( - self.cx.tcx.fn_sig(def_id).subst_identity().inputs().skip_binder(), + self.cx.tcx.fn_sig(def_id).instantiate_identity().inputs().skip_binder(), std::iter::once(receiver).chain(args.iter()), ) { self.prefer_mutable = false; diff --git a/clippy_lints/src/manual_bits.rs b/clippy_lints/src/manual_bits.rs index 4629b22d1717..6c7c57ba1d6b 100644 --- a/clippy_lints/src/manual_bits.rs +++ b/clippy_lints/src/manual_bits.rs @@ -110,7 +110,7 @@ fn get_size_of_ty<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option< if let Some(def_id) = cx.qpath_res(count_func_qpath, count_func.hir_id).opt_def_id(); if cx.tcx.is_diagnostic_item(sym::mem_size_of, def_id); then { - cx.typeck_results().node_substs(count_func.hir_id).types().next().map(|resolved_ty| (*real_ty, resolved_ty)) + cx.typeck_results().node_args(count_func.hir_id).types().next().map(|resolved_ty| (*real_ty, resolved_ty)) } else { None } diff --git a/clippy_lints/src/manual_slice_size_calculation.rs b/clippy_lints/src/manual_slice_size_calculation.rs index 703a6b25840b..f97600b53e4d 100644 --- a/clippy_lints/src/manual_slice_size_calculation.rs +++ b/clippy_lints/src/manual_slice_size_calculation.rs @@ -92,7 +92,7 @@ fn simplify_half<'tcx>( && let ExprKind::Path(ref func_qpath) = func.kind && let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id() && cx.tcx.is_diagnostic_item(sym::mem_size_of, def_id) - && let Some(ty2) = cx.typeck_results().node_substs(func.hir_id).types().next() + && let Some(ty2) = cx.typeck_results().node_args(func.hir_id).types().next() // T1 == T2? && *ty1 == ty2 { diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index edcab6968cbe..75605fb30918 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -104,7 +104,7 @@ fn is_unit_function(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { let ty = cx.typeck_results().expr_ty(expr); if let ty::FnDef(id, _) = *ty.kind() { - if let Some(fn_type) = cx.tcx.fn_sig(id).subst_identity().no_bound_vars() { + if let Some(fn_type) = cx.tcx.fn_sig(id).instantiate_identity().no_bound_vars() { return is_unit_type(fn_type.output()); } } diff --git a/clippy_lints/src/matches/match_as_ref.rs b/clippy_lints/src/matches/match_as_ref.rs index 2818f030b7a6..29c6e11134f8 100644 --- a/clippy_lints/src/matches/match_as_ref.rs +++ b/clippy_lints/src/matches/match_as_ref.rs @@ -27,10 +27,10 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: let input_ty = cx.typeck_results().expr_ty(ex); let cast = if_chain! { - if let ty::Adt(_, substs) = input_ty.kind(); - let input_ty = substs.type_at(0); - if let ty::Adt(_, substs) = output_ty.kind(); - let output_ty = substs.type_at(0); + if let ty::Adt(_, args) = input_ty.kind(); + let input_ty = args.type_at(0); + if let ty::Adt(_, args) = output_ty.kind(); + let output_ty = args.type_at(0); if let ty::Ref(_, output_ty, _) = *output_ty.kind(); if input_ty != output_ty; then { diff --git a/clippy_lints/src/matches/redundant_pattern_match.rs b/clippy_lints/src/matches/redundant_pattern_match.rs index 479cfd835126..039c2134cf81 100644 --- a/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/clippy_lints/src/matches/redundant_pattern_match.rs @@ -12,7 +12,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::LangItem::{self, OptionNone, OptionSome, PollPending, PollReady, ResultErr, ResultOk}; use rustc_hir::{Arm, Expr, ExprKind, Node, Pat, PatKind, QPath, UnOp}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, subst::GenericArgKind, Ty}; +use rustc_middle::ty::{self, GenericArgKind, Ty}; use rustc_span::{sym, Symbol}; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { diff --git a/clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs b/clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs index d06bcdaa27f0..4efe93d4b542 100644 --- a/clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs +++ b/clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs @@ -10,7 +10,7 @@ pub(crate) fn check(cx: &LateContext<'_>, pat: &Pat<'_>) { if !pat.span.from_expansion(); if let PatKind::Struct(QPath::Resolved(_, path), fields, true) = pat.kind; if let Some(def_id) = path.res.opt_def_id(); - let ty = cx.tcx.type_of(def_id).subst_identity(); + let ty = cx.tcx.type_of(def_id).instantiate_identity(); if let ty::Adt(def, _) = ty.kind(); if def.is_struct() || def.is_union(); if fields.len() == def.non_enum_variant().fields.len(); diff --git a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index 37528d9f7f20..02500fac293e 100644 --- a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -6,7 +6,7 @@ use rustc_errors::{Applicability, Diagnostic}; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{Arm, Expr, ExprKind, MatchSource}; use rustc_lint::{LateContext, LintContext}; -use rustc_middle::ty::subst::GenericArgKind; +use rustc_middle::ty::GenericArgKind; use rustc_middle::ty::{Ty, TypeAndMut}; use rustc_span::Span; diff --git a/clippy_lints/src/methods/bytes_count_to_len.rs b/clippy_lints/src/methods/bytes_count_to_len.rs index 46a20ad412ba..649fc46e4adf 100644 --- a/clippy_lints/src/methods/bytes_count_to_len.rs +++ b/clippy_lints/src/methods/bytes_count_to_len.rs @@ -17,7 +17,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(bytes_id) = cx.typeck_results().type_dependent_def_id(count_recv.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(bytes_id); - if cx.tcx.type_of(impl_id).subst_identity().is_str(); + if cx.tcx.type_of(impl_id).instantiate_identity().is_str(); let ty = cx.typeck_results().expr_ty(bytes_recv).peel_refs(); if ty.is_str() || is_type_lang_item(cx, ty, hir::LangItem::String); then { diff --git a/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs b/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs index 7711aa78b239..fb10f782f7aa 100644 --- a/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs +++ b/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs @@ -30,7 +30,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if cx.tcx.type_of(impl_id).subst_identity().is_str(); + if cx.tcx.type_of(impl_id).instantiate_identity().is_str(); if let ExprKind::Lit(Spanned { node: LitKind::Str(ext_literal, ..), ..}) = arg.kind; if (2..=6).contains(&ext_literal.as_str().len()); let ext_str = ext_literal.as_str(); diff --git a/clippy_lints/src/methods/err_expect.rs b/clippy_lints/src/methods/err_expect.rs index ae03da0d3f9c..4ab06bf2ae87 100644 --- a/clippy_lints/src/methods/err_expect.rs +++ b/clippy_lints/src/methods/err_expect.rs @@ -47,7 +47,7 @@ pub(super) fn check( /// Given a `Result` type, return its data (`T`). fn get_data_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option> { match ty.kind() { - ty::Adt(_, substs) if is_type_diagnostic_item(cx, ty, sym::Result) => substs.types().next(), + ty::Adt(_, args) if is_type_diagnostic_item(cx, ty, sym::Result) => args.types().next(), _ => None, } } diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index 92d21bb89326..9af11f08c261 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -70,7 +70,7 @@ pub(super) fn check<'tcx>( if let hir::ExprKind::Path(ref p) = fun.kind { match cx.qpath_res(p, fun.hir_id) { hir::def::Res::Def(hir::def::DefKind::Fn | hir::def::DefKind::AssocFn, def_id) => matches!( - cx.tcx.fn_sig(def_id).subst_identity().output().skip_binder().kind(), + cx.tcx.fn_sig(def_id).instantiate_identity().output().skip_binder().kind(), ty::Ref(re, ..) if re.is_static(), ), _ => false, @@ -84,7 +84,7 @@ pub(super) fn check<'tcx>( .type_dependent_def_id(arg.hir_id) .map_or(false, |method_id| { matches!( - cx.tcx.fn_sig(method_id).subst_identity().output().skip_binder().kind(), + cx.tcx.fn_sig(method_id).instantiate_identity().output().skip_binder().kind(), ty::Ref(re, ..) if re.is_static() ) }) diff --git a/clippy_lints/src/methods/flat_map_option.rs b/clippy_lints/src/methods/flat_map_option.rs index 615bde941334..4737a101345a 100644 --- a/clippy_lints/src/methods/flat_map_option.rs +++ b/clippy_lints/src/methods/flat_map_option.rs @@ -15,7 +15,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, arg } let arg_ty = cx.typeck_results().expr_ty_adjusted(arg); let sig = match arg_ty.kind() { - ty::Closure(_, substs) => substs.as_closure().sig(), + ty::Closure(_, args) => args.as_closure().sig(), _ if arg_ty.is_fn() => arg_ty.fn_sig(cx.tcx), _ => return, }; diff --git a/clippy_lints/src/methods/get_first.rs b/clippy_lints/src/methods/get_first.rs index 945bbf53bcf3..ee063adac64a 100644 --- a/clippy_lints/src/methods/get_first.rs +++ b/clippy_lints/src/methods/get_first.rs @@ -19,7 +19,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if cx.tcx.type_of(impl_id).subst_identity().is_slice(); + if cx.tcx.type_of(impl_id).instantiate_identity().is_slice(); if let Some(_) = is_slice_of_primitives(cx, recv); if let hir::ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = arg.kind; then { diff --git a/clippy_lints/src/methods/implicit_clone.rs b/clippy_lints/src/methods/implicit_clone.rs index 5a78a4168772..043425300d8b 100644 --- a/clippy_lints/src/methods/implicit_clone.rs +++ b/clippy_lints/src/methods/implicit_clone.rs @@ -54,7 +54,7 @@ pub fn is_clone_like(cx: &LateContext<'_>, method_name: &str, method_def_id: hir .tcx .impl_of_method(method_def_id) .filter(|&impl_did| { - cx.tcx.type_of(impl_did).subst_identity().is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none() + cx.tcx.type_of(impl_did).instantiate_identity().is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none() }) .is_some(), _ => false, diff --git a/clippy_lints/src/methods/inefficient_to_string.rs b/clippy_lints/src/methods/inefficient_to_string.rs index 424482859ee8..37da52dc7336 100644 --- a/clippy_lints/src/methods/inefficient_to_string.rs +++ b/clippy_lints/src/methods/inefficient_to_string.rs @@ -23,9 +23,9 @@ pub fn check( if args.is_empty() && method_name == sym::to_string; if let Some(to_string_meth_did) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if match_def_path(cx, to_string_meth_did, &paths::TO_STRING_METHOD); - if let Some(substs) = cx.typeck_results().node_substs_opt(expr.hir_id); + if let Some(args) = cx.typeck_results().node_args_opt(expr.hir_id); let arg_ty = cx.typeck_results().expr_ty_adjusted(receiver); - let self_ty = substs.type_at(0); + let self_ty = args.type_at(0); let (deref_self_ty, deref_count) = walk_ptrs_ty_depth(self_ty); if deref_count >= 1; if specializes_tostring(cx, deref_self_ty); @@ -64,8 +64,8 @@ fn specializes_tostring(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { return true; } - if let ty::Adt(adt, substs) = ty.kind() { - cx.tcx.is_diagnostic_item(sym::Cow, adt.did()) && substs.type_at(1).is_str() + if let ty::Adt(adt, args) = ty.kind() { + cx.tcx.is_diagnostic_item(sym::Cow, adt.did()) && args.type_at(1).is_str() } else { false } diff --git a/clippy_lints/src/methods/manual_ok_or.rs b/clippy_lints/src/methods/manual_ok_or.rs index b9a0ec779961..3031193e5312 100644 --- a/clippy_lints/src/methods/manual_ok_or.rs +++ b/clippy_lints/src/methods/manual_ok_or.rs @@ -21,7 +21,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).subst_identity(), sym::Option); + if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::Option); if let ExprKind::Call(err_path, [err_arg]) = or_expr.kind; if is_res_lang_ctor(cx, path_res(cx, err_path), ResultErr); if is_ok_wrapping(cx, map_expr); diff --git a/clippy_lints/src/methods/map_clone.rs b/clippy_lints/src/methods/map_clone.rs index 2b26ef014109..880efe60c1a3 100644 --- a/clippy_lints/src/methods/map_clone.rs +++ b/clippy_lints/src/methods/map_clone.rs @@ -19,7 +19,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_ if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id); if cx.tcx.impl_of_method(method_id) - .map_or(false, |id| is_type_diagnostic_item(cx, cx.tcx.type_of(id).subst_identity(), sym::Option)) + .map_or(false, |id| is_type_diagnostic_item(cx, cx.tcx.type_of(id).instantiate_identity(), sym::Option)) || is_diag_trait_item(cx, method_id, sym::Iterator); if let hir::ExprKind::Closure(&hir::Closure{ body, .. }) = arg.kind; then { diff --git a/clippy_lints/src/methods/map_collect_result_unit.rs b/clippy_lints/src/methods/map_collect_result_unit.rs index a0300d278709..042bab805b88 100644 --- a/clippy_lints/src/methods/map_collect_result_unit.rs +++ b/clippy_lints/src/methods/map_collect_result_unit.rs @@ -15,8 +15,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, iter: &hir::Expr let collect_ret_ty = cx.typeck_results().expr_ty(expr); if_chain! { if is_type_diagnostic_item(cx, collect_ret_ty, sym::Result); - if let ty::Adt(_, substs) = collect_ret_ty.kind(); - if let Some(result_t) = substs.types().next(); + if let ty::Adt(_, args) = collect_ret_ty.kind(); + if let Some(result_t) = args.types().next(); if result_t.is_unit(); // get parts for snippet then { diff --git a/clippy_lints/src/methods/map_err_ignore.rs b/clippy_lints/src/methods/map_err_ignore.rs index a5beb291f326..fbb83c8ce563 100644 --- a/clippy_lints/src/methods/map_err_ignore.rs +++ b/clippy_lints/src/methods/map_err_ignore.rs @@ -9,7 +9,7 @@ use super::MAP_ERR_IGNORE; pub(super) fn check(cx: &LateContext<'_>, e: &Expr<'_>, arg: &Expr<'_>) { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) && let Some(impl_id) = cx.tcx.impl_of_method(method_id) - && is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).subst_identity(), sym::Result) + && is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::Result) && let ExprKind::Closure(&Closure { capture_clause: CaptureBy::Ref, body, diff --git a/clippy_lints/src/methods/map_flatten.rs b/clippy_lints/src/methods/map_flatten.rs index 361ffcb5ef3f..950902d455b6 100644 --- a/clippy_lints/src/methods/map_flatten.rs +++ b/clippy_lints/src/methods/map_flatten.rs @@ -59,7 +59,7 @@ fn is_map_to_option(cx: &LateContext<'_>, map_arg: &Expr<'_>) -> bool { match map_closure_ty.kind() { ty::Closure(_, _) | ty::FnDef(_, _) | ty::FnPtr(_) => { let map_closure_sig = match map_closure_ty.kind() { - ty::Closure(_, substs) => substs.as_closure().sig(), + ty::Closure(_, args) => args.as_closure().sig(), _ => map_closure_ty.fn_sig(cx.tcx), }; let map_closure_return_ty = cx.tcx.erase_late_bound_regions(map_closure_sig.output()); diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 24dbe8c1d751..9ab78c6f8e05 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3508,11 +3508,11 @@ impl<'tcx> LateLintPass<'tcx> for Methods { let name = impl_item.ident.name.as_str(); let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(parent); - let self_ty = cx.tcx.type_of(item.owner_id).subst_identity(); + let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity(); let implements_trait = matches!(item.kind, hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })); if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind { - let method_sig = cx.tcx.fn_sig(impl_item.owner_id).subst_identity(); + let method_sig = cx.tcx.fn_sig(impl_item.owner_id).instantiate_identity(); let method_sig = cx.tcx.erase_late_bound_regions(method_sig); let first_arg_ty_opt = method_sig.inputs().iter().next().copied(); // if this impl block implements a trait, lint in trait definition instead @@ -4113,8 +4113,8 @@ impl SelfKind { } else if ty.is_box() { ty.boxed_ty() == parent_ty } else if is_type_diagnostic_item(cx, ty, sym::Rc) || is_type_diagnostic_item(cx, ty, sym::Arc) { - if let ty::Adt(_, substs) = ty.kind() { - substs.types().next().map_or(false, |t| t == parent_ty) + if let ty::Adt(_, args) = ty.kind() { + args.types().next().map_or(false, |t| t == parent_ty) } else { false } diff --git a/clippy_lints/src/methods/mut_mutex_lock.rs b/clippy_lints/src/methods/mut_mutex_lock.rs index d0aa39d06275..fe024ee8dff9 100644 --- a/clippy_lints/src/methods/mut_mutex_lock.rs +++ b/clippy_lints/src/methods/mut_mutex_lock.rs @@ -15,7 +15,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'tcx>, recv: &' if let ty::Ref(_, _, Mutability::Mut) = cx.typeck_results().expr_ty(recv).kind(); if let Some(method_id) = cx.typeck_results().type_dependent_def_id(ex.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).subst_identity(), sym::Mutex); + if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::Mutex); then { span_lint_and_sugg( cx, diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index 8ca7af8107f6..f34f1cf27045 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -163,7 +163,7 @@ fn check_collect_into_intoiterator<'tcx>( // that contains `collect_expr` let inputs = cx .tcx - .liberate_late_bound_regions(id, cx.tcx.fn_sig(id).subst_identity()) + .liberate_late_bound_regions(id, cx.tcx.fn_sig(id).instantiate_identity()) .inputs(); // map IntoIterator generic bounds to their signature @@ -201,7 +201,7 @@ fn check_collect_into_intoiterator<'tcx>( /// Checks if the given method call matches the expected signature of `([&[mut]] self) -> bool` fn is_is_empty_sig(cx: &LateContext<'_>, call_id: HirId) -> bool { cx.typeck_results().type_dependent_def_id(call_id).map_or(false, |id| { - let sig = cx.tcx.fn_sig(id).subst_identity().skip_binder(); + let sig = cx.tcx.fn_sig(id).instantiate_identity().skip_binder(); sig.inputs().len() == 1 && sig.output().is_bool() }) } @@ -215,7 +215,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty: && let Some(into_iter_item_proj) = make_projection(cx.tcx, into_iter_trait, item, [collect_ty]) && let Ok(into_iter_item_ty) = cx.tcx.try_normalize_erasing_regions( cx.param_env, - Ty::new_projection(cx.tcx,into_iter_item_proj.def_id, into_iter_item_proj.substs) + Ty::new_projection(cx.tcx,into_iter_item_proj.def_id, into_iter_item_proj.args) ) { iter_item_ty == into_iter_item_ty @@ -229,7 +229,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty: fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) -> bool { let typeck = cx.typeck_results(); if let Some(id) = typeck.type_dependent_def_id(call_id) - && let sig = cx.tcx.fn_sig(id).subst_identity() + && let sig = cx.tcx.fn_sig(id).instantiate_identity() && sig.skip_binder().output().is_bool() && let [_, search_ty] = *sig.skip_binder().inputs() && let ty::Ref(_, search_ty, Mutability::Not) = *cx.tcx.erase_late_bound_regions(sig.rebind(search_ty)).kind() @@ -237,11 +237,11 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) - && let Some(iter_item) = cx.tcx .associated_items(iter_trait) .find_by_name_and_kind(cx.tcx, Ident::with_dummy_span(Symbol::intern("Item")), AssocKind::Type, iter_trait) - && let substs = cx.tcx.mk_substs(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))]) - && let proj_ty = Ty::new_projection(cx.tcx,iter_item.def_id, substs) + && let args = cx.tcx.mk_args(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))]) + && let proj_ty = Ty::new_projection(cx.tcx,iter_item.def_id, args) && let Ok(item_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, proj_ty) { - item_ty == EarlyBinder::bind(search_ty).subst(cx.tcx, cx.typeck_results().node_substs(call_id)) + item_ty == EarlyBinder::bind(search_ty).instantiate(cx.tcx, cx.typeck_results().node_args(call_id)) } else { false } diff --git a/clippy_lints/src/methods/ok_expect.rs b/clippy_lints/src/methods/ok_expect.rs index 646fc4a7bcf3..f2ef42933df6 100644 --- a/clippy_lints/src/methods/ok_expect.rs +++ b/clippy_lints/src/methods/ok_expect.rs @@ -33,7 +33,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr /// Given a `Result` type, return its error type (`E`). fn get_error_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option> { match ty.kind() { - ty::Adt(_, substs) if is_type_diagnostic_item(cx, ty, sym::Result) => substs.types().nth(1), + ty::Adt(_, args) if is_type_diagnostic_item(cx, ty, sym::Result) => args.types().nth(1), _ => None, } } diff --git a/clippy_lints/src/methods/open_options.rs b/clippy_lints/src/methods/open_options.rs index bd625a6914c3..1c664e76d74f 100644 --- a/clippy_lints/src/methods/open_options.rs +++ b/clippy_lints/src/methods/open_options.rs @@ -11,7 +11,7 @@ use super::NONSENSICAL_OPEN_OPTIONS; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) && let Some(impl_id) = cx.tcx.impl_of_method(method_id) - && match_type(cx, cx.tcx.type_of(impl_id).subst_identity(), &paths::OPEN_OPTIONS) + && match_type(cx, cx.tcx.type_of(impl_id).instantiate_identity(), &paths::OPEN_OPTIONS) { let mut options = Vec::new(); get_open_options(cx, recv, &mut options); diff --git a/clippy_lints/src/methods/path_buf_push_overwrite.rs b/clippy_lints/src/methods/path_buf_push_overwrite.rs index 0284d9dea303..1c07d2a3a59c 100644 --- a/clippy_lints/src/methods/path_buf_push_overwrite.rs +++ b/clippy_lints/src/methods/path_buf_push_overwrite.rs @@ -14,7 +14,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arg: &'t if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).subst_identity(), sym::PathBuf); + if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::PathBuf); if let ExprKind::Lit(lit) = arg.kind; if let LitKind::Str(ref path_lit, _) = lit.node; if let pushed_path = Path::new(path_lit.as_str()); diff --git a/clippy_lints/src/methods/stable_sort_primitive.rs b/clippy_lints/src/methods/stable_sort_primitive.rs index b5fd0ad8ce52..0f4c97022dbe 100644 --- a/clippy_lints/src/methods/stable_sort_primitive.rs +++ b/clippy_lints/src/methods/stable_sort_primitive.rs @@ -10,7 +10,7 @@ use super::STABLE_SORT_PRIMITIVE; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) && let Some(impl_id) = cx.tcx.impl_of_method(method_id) - && cx.tcx.type_of(impl_id).subst_identity().is_slice() + && cx.tcx.type_of(impl_id).instantiate_identity().is_slice() && let Some(slice_type) = is_slice_of_primitives(cx, recv) { span_lint_and_then( diff --git a/clippy_lints/src/methods/suspicious_splitn.rs b/clippy_lints/src/methods/suspicious_splitn.rs index 90ca66bd70c5..3cb2719e4a03 100644 --- a/clippy_lints/src/methods/suspicious_splitn.rs +++ b/clippy_lints/src/methods/suspicious_splitn.rs @@ -13,7 +13,7 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se if let Some(call_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(call_id); if cx.tcx.impl_trait_ref(impl_id).is_none(); - let self_ty = cx.tcx.type_of(impl_id).subst_identity(); + let self_ty = cx.tcx.type_of(impl_id).instantiate_identity(); if self_ty.is_slice() || self_ty.is_str(); then { // Ignore empty slice and string literals when used with a literal count. diff --git a/clippy_lints/src/methods/unnecessary_sort_by.rs b/clippy_lints/src/methods/unnecessary_sort_by.rs index 67618f7038ad..e62a65a27125 100644 --- a/clippy_lints/src/methods/unnecessary_sort_by.rs +++ b/clippy_lints/src/methods/unnecessary_sort_by.rs @@ -6,7 +6,7 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Closure, Expr, ExprKind, Mutability, Param, Pat, PatKind, Path, PathSegment, QPath}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, subst::GenericArgKind}; +use rustc_middle::ty::{self, GenericArgKind}; use rustc_span::sym; use rustc_span::symbol::Ident; use std::iter; @@ -118,7 +118,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: &Exp if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if cx.tcx.type_of(impl_id).subst_identity().is_slice(); + if cx.tcx.type_of(impl_id).instantiate_identity().is_slice(); if let ExprKind::Closure(&Closure { body, .. }) = arg.kind; if let closure_body = cx.tcx.hir().body(body); if let &[ diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 6bd5e9e88c84..21e2638e5b92 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -13,7 +13,7 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::mir::Mutability; use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref}; -use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef}; +use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgsRef}; use rustc_middle::ty::{self, ClauseKind, EarlyBinder, ParamTy, ProjectionPredicate, TraitPredicate, Ty}; use rustc_span::{sym, Symbol}; use rustc_trait_selection::traits::{query::evaluate_obligation::InferCtxtExt as _, Obligation, ObligationCause}; @@ -250,8 +250,8 @@ fn check_other_call_arg<'tcx>( ) -> bool { if_chain! { if let Some((maybe_call, maybe_arg)) = skip_addr_of_ancestors(cx, expr); - if let Some((callee_def_id, _, recv, call_args)) = get_callee_substs_and_args(cx, maybe_call); - let fn_sig = cx.tcx.fn_sig(callee_def_id).subst_identity().skip_binder(); + if let Some((callee_def_id, _, recv, call_args)) = get_callee_generic_args_and_args(cx, maybe_call); + let fn_sig = cx.tcx.fn_sig(callee_def_id).instantiate_identity().skip_binder(); if let Some(i) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == maybe_arg.hir_id); if let Some(input) = fn_sig.inputs().get(i); let (input, n_refs) = peel_mid_ty_refs(*input); @@ -315,26 +315,26 @@ fn skip_addr_of_ancestors<'tcx>( } /// Checks whether an expression is a function or method call and, if so, returns its `DefId`, -/// `Substs`, and arguments. -fn get_callee_substs_and_args<'tcx>( +/// `GenericArgs`, and arguments. +fn get_callee_generic_args_and_args<'tcx>( cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, -) -> Option<(DefId, SubstsRef<'tcx>, Option<&'tcx Expr<'tcx>>, &'tcx [Expr<'tcx>])> { +) -> Option<(DefId, GenericArgsRef<'tcx>, Option<&'tcx Expr<'tcx>>, &'tcx [Expr<'tcx>])> { if_chain! { if let ExprKind::Call(callee, args) = expr.kind; let callee_ty = cx.typeck_results().expr_ty(callee); if let ty::FnDef(callee_def_id, _) = callee_ty.kind(); then { - let substs = cx.typeck_results().node_substs(callee.hir_id); - return Some((*callee_def_id, substs, None, args)); + let generic_args = cx.typeck_results().node_args(callee.hir_id); + return Some((*callee_def_id, generic_args, None, args)); } } if_chain! { if let ExprKind::MethodCall(_, recv, args, _) = expr.kind; if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); then { - let substs = cx.typeck_results().node_substs(expr.hir_id); - return Some((method_def_id, substs, Some(recv), args)); + let generic_args = cx.typeck_results().node_args(expr.hir_id); + return Some((method_def_id, generic_args, Some(recv), args)); } } None @@ -388,17 +388,17 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< } } Node::Expr(parent_expr) => { - if let Some((callee_def_id, call_substs, recv, call_args)) = get_callee_substs_and_args(cx, parent_expr) + if let Some((callee_def_id, call_generic_args, recv, call_args)) = get_callee_generic_args_and_args(cx, parent_expr) { - // FIXME: the `subst_identity()` below seems incorrect, since we eventually + // FIXME: the `instantiate_identity()` below seems incorrect, since we eventually // call `tcx.try_subst_and_normalize_erasing_regions` further down // (i.e., we are explicitly not in the identity context). - let fn_sig = cx.tcx.fn_sig(callee_def_id).subst_identity().skip_binder(); + let fn_sig = cx.tcx.fn_sig(callee_def_id).instantiate_identity().skip_binder(); if let Some(arg_index) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == expr.hir_id) && let Some(param_ty) = fn_sig.inputs().get(arg_index) && let ty::Param(ParamTy { index: param_index , ..}) = param_ty.kind() // https://github.com/rust-lang/rust-clippy/issues/9504 and https://github.com/rust-lang/rust-clippy/issues/10021 - && (*param_index as usize) < call_substs.len() + && (*param_index as usize) < call_generic_args.len() { if fn_sig .inputs() @@ -422,8 +422,8 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< } }); - let new_subst = cx.tcx.mk_substs_from_iter( - call_substs.iter() + let new_subst = cx.tcx.mk_args_from_iter( + call_generic_args.iter() .enumerate() .map(|(i, t)| if i == (*param_index as usize) { @@ -433,7 +433,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< })); if trait_predicates.any(|predicate| { - let predicate = EarlyBinder::bind(predicate).subst(cx.tcx, new_subst); + let predicate = EarlyBinder::bind(predicate).instantiate(cx.tcx, new_subst); let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate); !cx.tcx.infer_ctxt().build().predicate_must_hold_modulo_regions(&obligation) }) { @@ -500,8 +500,8 @@ fn is_to_string_on_string_like<'a>( return false; } - if let Some(substs) = cx.typeck_results().node_substs_opt(call_expr.hir_id) - && let [generic_arg] = substs.as_slice() + if let Some(args) = cx.typeck_results().node_args_opt(call_expr.hir_id) + && let [generic_arg] = args.as_slice() && let GenericArgKind::Type(ty) = generic_arg.unpack() && let Some(deref_trait_id) = cx.tcx.get_diagnostic_item(sym::Deref) && let Some(as_ref_trait_id) = cx.tcx.get_diagnostic_item(sym::AsRef) diff --git a/clippy_lints/src/methods/utils.rs b/clippy_lints/src/methods/utils.rs index c96d69226972..9f1f73e60218 100644 --- a/clippy_lints/src/methods/utils.rs +++ b/clippy_lints/src/methods/utils.rs @@ -143,7 +143,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for CloneOrCopyVisitor<'cx, 'tcx> { if_chain! { if args.iter().all(|arg| !self.is_binding(arg)); if let Some(method_def_id) = self.cx.typeck_results().type_dependent_def_id(parent.hir_id); - let method_ty = self.cx.tcx.type_of(method_def_id).subst_identity(); + let method_ty = self.cx.tcx.type_of(method_def_id).instantiate_identity(); let self_ty = method_ty.fn_sig(self.cx.tcx).input(0).skip_binder(); if matches!(self_ty.kind(), ty::Ref(_, _, Mutability::Not)); then { diff --git a/clippy_lints/src/methods/vec_resize_to_zero.rs b/clippy_lints/src/methods/vec_resize_to_zero.rs index b0cfc163fd08..73072718678e 100644 --- a/clippy_lints/src/methods/vec_resize_to_zero.rs +++ b/clippy_lints/src/methods/vec_resize_to_zero.rs @@ -20,7 +20,7 @@ pub(super) fn check<'tcx>( if_chain! { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(method_id); - if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).subst_identity(), sym::Vec); + if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::Vec); if let ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = count_arg.kind; if let ExprKind::Lit(Spanned { node: LitKind::Int(..), .. }) = default_arg.kind; then { diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 309f67521a3b..5878f899541a 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -139,7 +139,7 @@ impl MutableKeyType { } fn check_sig(&self, cx: &LateContext<'_>, fn_def_id: LocalDefId, decl: &hir::FnDecl<'_>) { - let fn_sig = cx.tcx.fn_sig(fn_def_id).subst_identity(); + let fn_sig = cx.tcx.fn_sig(fn_def_id).instantiate_identity(); for (hir_ty, ty) in iter::zip(decl.inputs, fn_sig.inputs().skip_binder()) { self.check_ty_(cx, hir_ty.span, *ty); } @@ -150,7 +150,7 @@ impl MutableKeyType { // generics (because the compiler cannot ensure immutability for unknown types). fn check_ty_<'tcx>(&self, cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) { let ty = ty.peel_refs(); - if let Adt(def, substs) = ty.kind() { + if let Adt(def, args) = ty.kind() { let is_keyed_type = [sym::HashMap, sym::BTreeMap, sym::HashSet, sym::BTreeSet] .iter() .any(|diag_item| cx.tcx.is_diagnostic_item(*diag_item, def.did())); @@ -158,7 +158,7 @@ impl MutableKeyType { return; } - let subst_ty = substs.type_at(0); + let subst_ty = args.type_at(0); // Determines if a type contains interior mutability which would affect its implementation of // [`Hash`] or [`Ord`]. if is_interior_mut_ty(cx, subst_ty) diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index e91aac41bc48..4b20aecad4a1 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -51,8 +51,8 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed { }, ExprKind::MethodCall(path, receiver, arguments, _) => { let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap(); - let substs = cx.typeck_results().node_substs(e.hir_id); - let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs); + let args = cx.typeck_results().node_args(e.hir_id); + let method_type = cx.tcx.type_of(def_id).instantiate(cx.tcx, args); check_arguments( cx, std::iter::once(receiver).chain(arguments.iter()).collect(), diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index f11d5773d041..55b6e1606ee4 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -140,7 +140,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { ctx }; - let fn_sig = cx.tcx.fn_sig(fn_def_id).subst_identity(); + let fn_sig = cx.tcx.fn_sig(fn_def_id).instantiate_identity(); let fn_sig = cx.tcx.liberate_late_bound_regions(fn_def_id.to_def_id(), fn_sig); for (idx, ((input, &ty), arg)) in decl.inputs.iter().zip(fn_sig.inputs()).zip(body.params).enumerate() { @@ -170,7 +170,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { !preds.is_empty() && { let ty_empty_region = Ty::new_imm_ref(cx.tcx,cx.tcx.lifetimes.re_erased, ty); preds.iter().all(|t| { - let ty_params = t.trait_ref.substs.iter().skip(1).collect::>(); + let ty_params = t.trait_ref.args.iter().skip(1).collect::>(); implements_trait(cx, ty_empty_region, t.def_id(), &ty_params) }) }, diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 653b1a8a05f6..cf7cd671dcab 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -98,14 +98,14 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { if name == sym::new; if cx.effective_visibilities.is_reachable(impl_item.owner_id.def_id); let self_def_id = cx.tcx.hir().get_parent_item(id.into()); - let self_ty = cx.tcx.type_of(self_def_id).subst_identity(); + let self_ty = cx.tcx.type_of(self_def_id).instantiate_identity(); if self_ty == return_ty(cx, id); if let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default); then { if self.impling_types.is_none() { let mut impls = HirIdSet::default(); cx.tcx.for_each_impl(default_trait_id, |d| { - let ty = cx.tcx.type_of(d).subst_identity(); + let ty = cx.tcx.type_of(d).instantiate_identity(); if let Some(ty_def) = ty.ty_adt_def() { if let Some(local_def_id) = ty_def.did().as_local() { impls.insert(cx.tcx.hir().local_def_id_to_hir_id(local_def_id)); @@ -119,7 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { // generics if_chain! { if let Some(ref impling_types) = self.impling_types; - let self_def = cx.tcx.type_of(self_def_id).subst_identity(); + let self_def = cx.tcx.type_of(self_def_id).instantiate_identity(); if let Some(self_def) = self_def.ty_adt_def(); if let Some(self_local_did) = self_def.did().as_local(); let self_id = cx.tcx.hir().local_def_id_to_hir_id(self_local_did); diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 75f1e95276a6..12d4f33d428a 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -158,7 +158,7 @@ fn is_value_unfrozen_raw<'tcx>( val.unwrap_branch().iter().any(|field| inner(cx, *field, ty)) }, ty::Adt(def, _) if def.is_union() => false, - ty::Adt(def, substs) if def.is_enum() => { + ty::Adt(def, args) if def.is_enum() => { let (&variant_index, fields) = val.unwrap_branch().split_first().unwrap(); let variant_index = VariantIdx::from_u32(variant_index.unwrap_leaf().try_to_u32().ok().unwrap()); @@ -166,10 +166,10 @@ fn is_value_unfrozen_raw<'tcx>( def.variants()[variant_index] .fields .iter() - .map(|field| field.ty(cx.tcx, substs))).any(|(field, ty)| inner(cx, field, ty)) + .map(|field| field.ty(cx.tcx, args))).any(|(field, ty)| inner(cx, field, ty)) } - ty::Adt(def, substs) => { - val.unwrap_branch().iter().zip(def.non_enum_variant().fields.iter().map(|field| field.ty(cx.tcx, substs))).any(|(field, ty)| inner(cx, *field, ty)) + ty::Adt(def, args) => { + val.unwrap_branch().iter().zip(def.non_enum_variant().fields.iter().map(|field| field.ty(cx.tcx, args))).any(|(field, ty)| inner(cx, *field, ty)) } ty::Tuple(tys) => val.unwrap_branch().iter().zip(tys).any(|(field, ty)| inner(cx, *field, ty)), _ => false, @@ -206,8 +206,8 @@ fn is_value_unfrozen_raw<'tcx>( fn is_value_unfrozen_poly<'tcx>(cx: &LateContext<'tcx>, body_id: BodyId, ty: Ty<'tcx>) -> bool { let def_id = body_id.hir_id.owner.to_def_id(); - let substs = ty::InternalSubsts::identity_for_item(cx.tcx, def_id); - let instance = ty::Instance::new(def_id, substs); + let args = ty::GenericArgs::identity_for_item(cx.tcx, def_id); + let instance = ty::Instance::new(def_id, args); let cid = rustc_middle::mir::interpret::GlobalId { instance, promoted: None }; let param_env = cx.tcx.param_env(def_id).with_reveal_all_normalized(cx.tcx); let result = cx.tcx.const_eval_global_id_for_typeck(param_env, cid, None); @@ -215,9 +215,9 @@ fn is_value_unfrozen_poly<'tcx>(cx: &LateContext<'tcx>, body_id: BodyId, ty: Ty< } fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: DefId, ty: Ty<'tcx>) -> bool { - let substs = cx.typeck_results().node_substs(hir_id); + let args = cx.typeck_results().node_args(hir_id); - let result = const_eval_resolve(cx.tcx, cx.param_env, ty::UnevaluatedConst::new(def_id, substs), None); + let result = const_eval_resolve(cx.tcx, cx.param_env, ty::UnevaluatedConst::new(def_id, args), None); is_value_unfrozen_raw(cx, result, ty) } @@ -228,7 +228,7 @@ pub fn const_eval_resolve<'tcx>( ct: ty::UnevaluatedConst<'tcx>, span: Option, ) -> EvalToValTreeResult<'tcx> { - match ty::Instance::resolve(tcx, param_env, ct.def, ct.substs) { + match ty::Instance::resolve(tcx, param_env, ct.def, ct.args) { Ok(Some(instance)) => { let cid = GlobalId { instance, promoted: None }; tcx.const_eval_global_id_for_typeck(param_env, cid, span) @@ -347,7 +347,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { // and, in that case, the definition is *not* generic. cx.tcx.normalize_erasing_regions( cx.tcx.param_env(of_trait_def_id), - cx.tcx.type_of(of_assoc_item).subst_identity(), + cx.tcx.type_of(of_assoc_item).instantiate_identity(), ), )) .is_err(); diff --git a/clippy_lints/src/non_send_fields_in_send_ty.rs b/clippy_lints/src/non_send_fields_in_send_ty.rs index 7eaa7db78a47..c5e777c20702 100644 --- a/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -7,7 +7,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::{FieldDef, Item, ItemKind, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, subst::GenericArgKind, Ty}; +use rustc_middle::ty::{self, GenericArgKind, Ty}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::sym; @@ -90,8 +90,8 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy { if send_trait == trait_id; if hir_impl.polarity == ImplPolarity::Positive; if let Some(ty_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id); - if let self_ty = ty_trait_ref.subst_identity().self_ty(); - if let ty::Adt(adt_def, impl_trait_substs) = self_ty.kind(); + if let self_ty = ty_trait_ref.instantiate_identity().self_ty(); + if let ty::Adt(adt_def, impl_trait_args) = self_ty.kind(); then { let mut non_send_fields = Vec::new(); @@ -104,7 +104,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy { .as_local() .map(|local_def_id| hir_map.local_def_id_to_hir_id(local_def_id)); if !is_lint_allowed(cx, NON_SEND_FIELDS_IN_SEND_TY, field_hir_id); - if let field_ty = field.ty(cx.tcx, impl_trait_substs); + if let field_ty = field.ty(cx.tcx, impl_trait_args); if !ty_allowed_in_send(cx, field_ty, send_trait); if let Node::Field(field_def) = hir_map.get(field_hir_id); then { @@ -206,10 +206,10 @@ fn ty_allowed_with_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t .iter() .all(|ty| ty_allowed_with_raw_pointer_heuristic(cx, ty, send_trait)), ty::Array(ty, _) | ty::Slice(ty) => ty_allowed_with_raw_pointer_heuristic(cx, *ty, send_trait), - ty::Adt(_, substs) => { + ty::Adt(_, args) => { if contains_pointer_like(cx, ty) { // descends only if ADT contains any raw pointers - substs.iter().all(|generic_arg| match generic_arg.unpack() { + args.iter().all(|generic_arg| match generic_arg.unpack() { GenericArgKind::Type(ty) => ty_allowed_with_raw_pointer_heuristic(cx, ty, send_trait), // Lifetimes and const generics are not solid part of ADT and ignored GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => true, @@ -224,7 +224,7 @@ fn ty_allowed_with_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t } } -/// Checks if the type contains any pointer-like types in substs (including nested ones) +/// Checks if the type contains any pointer-like types in args (including nested ones) fn contains_pointer_like<'tcx>(cx: &LateContext<'tcx>, target_ty: Ty<'tcx>) -> bool { for ty_node in target_ty.walk() { if let GenericArgKind::Type(inner_ty) = ty_node.unpack() { diff --git a/clippy_lints/src/only_used_in_recursion.rs b/clippy_lints/src/only_used_in_recursion.rs index 8b77a5c99f76..3615c7ec9bff 100644 --- a/clippy_lints/src/only_used_in_recursion.rs +++ b/clippy_lints/src/only_used_in_recursion.rs @@ -7,7 +7,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::hir_id::HirIdMap; use rustc_hir::{Body, Expr, ExprKind, HirId, ImplItem, ImplItemKind, Node, PatKind, TraitItem, TraitItemKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::subst::{EarlyBinder, GenericArgKind, SubstsRef}; +use rustc_middle::ty::{EarlyBinder, GenericArgKind, GenericArgsRef}; use rustc_middle::ty::{self, ConstKind}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::symbol::{kw, Ident}; @@ -90,7 +90,7 @@ impl_lint_pass!(OnlyUsedInRecursion => [ONLY_USED_IN_RECURSION]); enum FnKind { Fn, TraitFn, - // This is a hack. Ideally we would store a `SubstsRef<'tcx>` type here, but a lint pass must be `'static`. + // This is a hack. Ideally we would store a `GenericArgsRef<'tcx>` type here, but a lint pass must be `'static`. // Substitutions are, however, interned. This allows us to store the pointer as a `usize` when comparing for // equality. ImplTraitFn(usize), @@ -244,12 +244,12 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion { })) => { #[allow(trivial_casts)] if let Some(Node::Item(item)) = get_parent_node(cx.tcx, owner_id.into()) - && let Some(trait_ref) = cx.tcx.impl_trait_ref(item.owner_id).map(EarlyBinder::subst_identity) + && let Some(trait_ref) = cx.tcx.impl_trait_ref(item.owner_id).map(EarlyBinder::instantiate_identity) && let Some(trait_item_id) = cx.tcx.associated_item(owner_id).trait_item_def_id { ( trait_item_id, - FnKind::ImplTraitFn(cx.tcx.erase_regions(trait_ref.substs) as *const _ as usize), + FnKind::ImplTraitFn(cx.tcx.erase_regions(trait_ref.args) as *const _ as usize), usize::from(sig.decl.implicit_self.has_implicit_self()), ) } else { @@ -289,7 +289,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion { ExprKind::Call(callee, args) if path_def_id(cx, callee).map_or(false, |id| { id == param.fn_id - && has_matching_substs(param.fn_kind, typeck.node_substs(callee.hir_id)) + && has_matching_args(param.fn_kind, typeck.node_args(callee.hir_id)) }) => { if let Some(idx) = args.iter().position(|arg| arg.hir_id == child_id) { @@ -300,7 +300,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion { ExprKind::MethodCall(_, receiver, args, _) if typeck.type_dependent_def_id(parent.hir_id).map_or(false, |id| { id == param.fn_id - && has_matching_substs(param.fn_kind, typeck.node_substs(parent.hir_id)) + && has_matching_args(param.fn_kind, typeck.node_args(parent.hir_id)) }) => { if let Some(idx) = iter::once(receiver).chain(args).position(|arg| arg.hir_id == child_id) { @@ -381,15 +381,15 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion { } } -fn has_matching_substs(kind: FnKind, substs: SubstsRef<'_>) -> bool { +fn has_matching_args(kind: FnKind, args: GenericArgsRef<'_>) -> bool { match kind { FnKind::Fn => true, - FnKind::TraitFn => substs.iter().enumerate().all(|(idx, subst)| match subst.unpack() { + FnKind::TraitFn => args.iter().enumerate().all(|(idx, subst)| match subst.unpack() { GenericArgKind::Lifetime(_) => true, GenericArgKind::Type(ty) => matches!(*ty.kind(), ty::Param(ty) if ty.index as usize == idx), GenericArgKind::Const(c) => matches!(c.kind(), ConstKind::Param(c) if c.index as usize == idx), }), #[allow(trivial_casts)] - FnKind::ImplTraitFn(expected_substs) => substs as *const _ as usize == expected_substs, + FnKind::ImplTraitFn(expected_args) => args as *const _ as usize == expected_args, } } diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index eab725de17f6..7b4812e98d8a 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -143,7 +143,7 @@ impl<'tcx> PassByRefOrValue { return; } - let fn_sig = cx.tcx.fn_sig(def_id).subst_identity(); + let fn_sig = cx.tcx.fn_sig(def_id).instantiate_identity(); let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir().body(id)); // Gather all the lifetimes found in the output type which may affect whether diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 32213718b270..eb7c008c7a4d 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -166,7 +166,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { check_mut_from_ref(cx, sig, None); for arg in check_fn_args( cx, - cx.tcx.fn_sig(item.owner_id).subst_identity().skip_binder().inputs(), + cx.tcx.fn_sig(item.owner_id).instantiate_identity().skip_binder().inputs(), sig.decl.inputs, &sig.decl.output, &[], @@ -220,7 +220,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { check_mut_from_ref(cx, sig, Some(body)); let decl = sig.decl; - let sig = cx.tcx.fn_sig(item_id).subst_identity().skip_binder(); + let sig = cx.tcx.fn_sig(item_id).instantiate_identity().skip_binder(); let lint_args: Vec<_> = check_fn_args(cx, sig.inputs(), decl.inputs, &decl.output, body.params) .filter(|arg| !is_trait_item || arg.mutability() == Mutability::Not) .collect(); @@ -423,7 +423,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>( .enumerate() .filter_map(move |(i, (ty, hir_ty))| { if let ty::Ref(_, ty, mutability) = *ty.kind() - && let ty::Adt(adt, substs) = *ty.kind() + && let ty::Adt(adt, args) = *ty.kind() && let TyKind::Ref(lt, ref ty) = hir_ty.kind && let TyKind::Path(QPath::Resolved(None, path)) = ty.ty.kind // Check that the name as typed matches the actual name of the type. @@ -443,7 +443,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>( } else { None }), - substs.type_at(0), + args.type_at(0), ), ), _ if Some(adt.did()) == cx.tcx.lang_items().string() => ( @@ -496,7 +496,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>( } let ty_name = - snippet_opt(cx, ty.span()).unwrap_or_else(|| substs.type_at(1).to_string()); + snippet_opt(cx, ty.span()).unwrap_or_else(|| args.type_at(1).to_string()); span_lint_hir_and_then( cx, @@ -659,7 +659,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: return; }; - match *self.cx.tcx.fn_sig(id).subst_identity().skip_binder().inputs()[i] + match *self.cx.tcx.fn_sig(id).instantiate_identity().skip_binder().inputs()[i] .peel_refs() .kind() { @@ -725,7 +725,7 @@ fn matches_preds<'tcx>( let infcx = cx.tcx.infer_ctxt().build(); preds.iter().all(|&p| match cx.tcx.erase_late_bound_regions(p) { ExistentialPredicate::Trait(p) => infcx - .type_implements_trait(p.def_id, [ty.into()].into_iter().chain(p.substs.iter()), cx.param_env) + .type_implements_trait(p.def_id, [ty.into()].into_iter().chain(p.args.iter()), cx.param_env) .must_apply_modulo_regions(), ExistentialPredicate::Projection(p) => infcx.predicate_must_hold_modulo_regions(&Obligation::new( cx.tcx, diff --git a/clippy_lints/src/redundant_slicing.rs b/clippy_lints/src/redundant_slicing.rs index c70ce83a9c45..2b65c08d25d1 100644 --- a/clippy_lints/src/redundant_slicing.rs +++ b/clippy_lints/src/redundant_slicing.rs @@ -9,7 +9,7 @@ use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability}; use rustc_lint::{LateContext, LateLintPass, Lint}; use rustc_middle::ty::Ty; use rustc_middle::ty::adjustment::{Adjust, AutoBorrow, AutoBorrowMutability}; -use rustc_middle::ty::subst::GenericArg; +use rustc_middle::ty::GenericArg; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { @@ -135,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing { } else if let Some(target_id) = cx.tcx.lang_items().deref_target() { if let Ok(deref_ty) = cx.tcx.try_normalize_erasing_regions( cx.param_env, - Ty::new_projection(cx.tcx,target_id, cx.tcx.mk_substs(&[GenericArg::from(indexed_ty)])), + Ty::new_projection(cx.tcx,target_id, cx.tcx.mk_args(&[GenericArg::from(indexed_ty)])), ) { if deref_ty == expr_ty { let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0; diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 958351ad81bb..4977df6c83f3 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -9,7 +9,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, LangItem, MatchSource, PatKind, QPath, StmtKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, subst::GenericArgKind, Ty}; +use rustc_middle::ty::{self, GenericArgKind, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; use rustc_span::source_map::Span; @@ -333,7 +333,7 @@ fn last_statement_borrows<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) && cx .tcx .fn_sig(def_id) - .subst_identity() + .instantiate_identity() .skip_binder() .output() .walk() diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index beca203c868d..b92014f68b39 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(parent); - let self_ty = cx.tcx.type_of(item.owner_id).subst_identity(); + let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity(); let ret_ty = return_ty(cx, impl_item.owner_id); // Do not check trait impls diff --git a/clippy_lints/src/significant_drop_tightening.rs b/clippy_lints/src/significant_drop_tightening.rs index fffa8a380c2f..1493ad44ee55 100644 --- a/clippy_lints/src/significant_drop_tightening.rs +++ b/clippy_lints/src/significant_drop_tightening.rs @@ -10,7 +10,7 @@ use rustc_hir::{ intravisit::{walk_expr, Visitor}, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::ty::{subst::GenericArgKind, Ty, TypeAndMut}; +use rustc_middle::ty::{GenericArgKind, Ty, TypeAndMut}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{symbol::Ident, Span, DUMMY_SP}; use std::borrow::Cow; diff --git a/clippy_lints/src/size_of_in_element_count.rs b/clippy_lints/src/size_of_in_element_count.rs index ac4e29e9dfdf..80c834066bbc 100644 --- a/clippy_lints/src/size_of_in_element_count.rs +++ b/clippy_lints/src/size_of_in_element_count.rs @@ -47,7 +47,7 @@ fn get_size_of_ty<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, inverted: if let Some(def_id) = cx.qpath_res(count_func_qpath, count_func.hir_id).opt_def_id(); if matches!(cx.tcx.get_diagnostic_name(def_id), Some(sym::mem_size_of | sym::mem_size_of_val)); then { - cx.typeck_results().node_substs(count_func.hir_id).types().next() + cx.typeck_results().node_args(count_func.hir_id).types().next() } else { None } @@ -101,7 +101,7 @@ fn get_pointee_ty_and_count_expr<'tcx>( if FUNCTIONS.iter().any(|func_path| match_def_path(cx, def_id, func_path)); // Get the pointee type - if let Some(pointee_ty) = cx.typeck_results().node_substs(func.hir_id).types().next(); + if let Some(pointee_ty) = cx.typeck_results().node_args(func.hir_id).types().next(); then { return Some((pointee_ty, count)); } diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index 5e24213d07fd..9e5d76624264 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_c_void; use rustc_hir::Expr; use rustc_lint::LateContext; -use rustc_middle::ty::SubstsRef; +use rustc_middle::ty::GenericArgsRef; use rustc_middle::ty::{self, IntTy, Ty, TypeAndMut, UintTy}; #[expect(clippy::too_many_lines)] @@ -268,12 +268,12 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> } ReducedTy::UnorderedFields(ty) }, - ty::Adt(def, substs) if def.is_struct() => { + ty::Adt(def, args) if def.is_struct() => { let mut iter = def .non_enum_variant() .fields .iter() - .map(|f| cx.tcx.type_of(f.did).subst(cx.tcx, substs)); + .map(|f| cx.tcx.type_of(f.did).instantiate(cx.tcx, args)); let Some(sized_ty) = iter.find(|&ty| !is_zero_sized_ty(cx, ty)) else { return ReducedTy::TypeErasure { raw_ptr_only: false }; }; @@ -322,7 +322,7 @@ fn is_size_pair(ty: Ty<'_>) -> bool { } } -fn same_except_params<'tcx>(subs1: SubstsRef<'tcx>, subs2: SubstsRef<'tcx>) -> bool { +fn same_except_params<'tcx>(subs1: GenericArgsRef<'tcx>, subs2: GenericArgsRef<'tcx>) -> bool { // TODO: check const parameters as well. Currently this will consider `Array<5>` the same as // `Array<6>` for (ty1, ty2) in subs1.types().zip(subs2.types()).filter(|(ty1, ty2)| ty1 != ty2) { diff --git a/clippy_lints/src/transmute/unsound_collection_transmute.rs b/clippy_lints/src/transmute/unsound_collection_transmute.rs index b1445311b711..891fefc17a64 100644 --- a/clippy_lints/src/transmute/unsound_collection_transmute.rs +++ b/clippy_lints/src/transmute/unsound_collection_transmute.rs @@ -10,7 +10,7 @@ use rustc_span::symbol::sym; /// Returns `true` if it's triggered, otherwise returns `false`. pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> bool { match (&from_ty.kind(), &to_ty.kind()) { - (ty::Adt(from_adt, from_substs), ty::Adt(to_adt, to_substs)) => { + (ty::Adt(from_adt, from_args), ty::Adt(to_adt, to_args)) => { if from_adt.did() != to_adt.did() { return false; } @@ -28,9 +28,9 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty ) { return false; } - if from_substs + if from_args .types() - .zip(to_substs.types()) + .zip(to_args.types()) .any(|(from_ty, to_ty)| is_layout_incompatible(cx, from_ty, to_ty)) { span_lint( diff --git a/clippy_lints/src/uninit_vec.rs b/clippy_lints/src/uninit_vec.rs index 1ab0162a8813..6756df8e716c 100644 --- a/clippy_lints/src/uninit_vec.rs +++ b/clippy_lints/src/uninit_vec.rs @@ -88,7 +88,7 @@ fn handle_uninit_vec_pair<'tcx>( if let Some((set_len_self, call_span)) = extract_set_len_self(cx, maybe_set_len); if vec.location.eq_expr(cx, set_len_self); if let ty::Ref(_, vec_ty, _) = cx.typeck_results().expr_ty_adjusted(set_len_self).kind(); - if let ty::Adt(_, substs) = vec_ty.kind(); + if let ty::Adt(_, args) = vec_ty.kind(); // `#[allow(...)]` attribute can be set on enclosing unsafe block of `set_len()` if !is_lint_allowed(cx, UNINIT_VEC, maybe_set_len.hir_id); then { @@ -96,7 +96,7 @@ fn handle_uninit_vec_pair<'tcx>( // with_capacity / reserve -> set_len // Check T of Vec - if !is_uninit_value_valid_for_ty(cx, substs.type_at(0)) { + if !is_uninit_value_valid_for_ty(cx, args.type_at(0)) { // FIXME: #7698, false positive of the internal lints #[expect(clippy::collapsible_span_lint_calls)] span_lint_and_then( diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 99a1d197678b..dd829ded0d0d 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -65,7 +65,7 @@ fn get_projection_pred<'tcx>( generics.predicates.iter().find_map(|(proj_pred, _)| { if let ClauseKind::Projection(pred) = proj_pred.kind().skip_binder() { let projection_pred = cx.tcx.erase_late_bound_regions(proj_pred.kind().rebind(pred)); - if projection_pred.projection_ty.substs == trait_pred.trait_ref.substs { + if projection_pred.projection_ty.args == trait_pred.trait_ref.args { return Some(projection_pred); } } @@ -76,7 +76,7 @@ fn get_projection_pred<'tcx>( fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Vec<(usize, String)> { let mut args_to_check = Vec::new(); if let Some(def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) { - let fn_sig = cx.tcx.fn_sig(def_id).subst_identity(); + let fn_sig = cx.tcx.fn_sig(def_id).instantiate_identity(); let generics = cx.tcx.predicates_of(def_id); let fn_mut_preds = get_trait_predicates_for_trait_id(cx, generics, cx.tcx.lang_items().fn_mut_trait()); let ord_preds = get_trait_predicates_for_trait_id(cx, generics, cx.tcx.get_diagnostic_item(sym::Ord)); @@ -120,8 +120,8 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Span, Option)> { if_chain! { if let ExprKind::Closure(&Closure { body, fn_decl_span, .. }) = arg.kind; - if let ty::Closure(_def_id, substs) = &cx.typeck_results().node_type(arg.hir_id).kind(); - let ret_ty = substs.as_closure().sig().output(); + if let ty::Closure(_def_id, args) = &cx.typeck_results().node_type(arg.hir_id).kind(); + let ret_ty = args.as_closure().sig().output(); let ty = cx.tcx.erase_late_bound_regions(ret_ty); if ty.is_unit(); then { diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index cc7c2b039f2d..704d7abd7e55 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -161,7 +161,7 @@ fn needs_inferred_result_ty( }, _ => return false, }; - let sig = cx.tcx.fn_sig(id).subst_identity().skip_binder(); + let sig = cx.tcx.fn_sig(id).instantiate_identity().skip_binder(); if let ty::Param(output_ty) = *sig.output().kind() { let args: Vec<&Expr<'_>> = if let Some(receiver) = receiver { std::iter::once(receiver).chain(args.iter()).collect() diff --git a/clippy_lints/src/unnamed_address.rs b/clippy_lints/src/unnamed_address.rs index 0f5cdb6aaea1..dea8a1e35bbb 100644 --- a/clippy_lints/src/unnamed_address.rs +++ b/clippy_lints/src/unnamed_address.rs @@ -97,7 +97,7 @@ impl LateLintPass<'_> for UnnamedAddress { if let ExprKind::Path(ref func_qpath) = func.kind; if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::PTR_EQ); - let ty_param = cx.typeck_results().node_substs(func.hir_id).type_at(0); + let ty_param = cx.typeck_results().node_args(func.hir_id).type_at(0); if ty_param.is_trait(); then { span_lint_and_help( diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 5a02987453c4..81dc426b3899 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -145,7 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { then { // `self_ty` is the semantic self type of `impl for `. This cannot be // `Self`. - let self_ty = impl_trait_ref.subst_identity().self_ty(); + let self_ty = impl_trait_ref.instantiate_identity().self_ty(); // `trait_method_sig` is the signature of the function, how it is declared in the // trait, not in the impl of the trait. @@ -154,7 +154,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { .associated_item(impl_item.owner_id) .trait_item_def_id .expect("impl method matches a trait method"); - let trait_method_sig = cx.tcx.fn_sig(trait_method).subst_identity(); + let trait_method_sig = cx.tcx.fn_sig(trait_method).instantiate_identity(); let trait_method_sig = cx.tcx.erase_late_bound_regions(trait_method_sig); // `impl_inputs_outputs` is an iterator over the types (`hir::Ty`) declared in the @@ -226,7 +226,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { } else { hir_ty_to_ty(cx.tcx, hir_ty) }; - if same_type_and_consts(ty, cx.tcx.type_of(impl_id).subst_identity()); + if same_type_and_consts(ty, cx.tcx.type_of(impl_id).instantiate_identity()); then { span_lint(cx, hir_ty.span); } @@ -238,7 +238,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { if !expr.span.from_expansion(); if self.msrv.meets(msrvs::TYPE_ALIAS_ENUM_VARIANTS); if let Some(&StackItem::Check { impl_id, .. }) = self.stack.last(); - if cx.typeck_results().expr_ty(expr) == cx.tcx.type_of(impl_id).subst_identity(); + if cx.typeck_results().expr_ty(expr) == cx.tcx.type_of(impl_id).instantiate_identity(); then {} else { return; } } match expr.kind { @@ -262,7 +262,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { if let PatKind::Path(QPath::Resolved(_, path)) | PatKind::TupleStruct(QPath::Resolved(_, path), _, _) | PatKind::Struct(QPath::Resolved(_, path), _, _) = pat.kind; - if cx.typeck_results().pat_ty(pat) == cx.tcx.type_of(impl_id).subst_identity(); + if cx.typeck_results().pat_ty(pat) == cx.tcx.type_of(impl_id).instantiate_identity(); then { check_path(cx, path); } diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index b6c11cfb3556..98f7bfb4ba15 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -227,8 +227,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { let a = cx.typeck_results().expr_ty(e); let b = cx.typeck_results().expr_ty(recv); if is_type_diagnostic_item(cx, a, sym::Result); - if let ty::Adt(_, substs) = a.kind(); - if let Some(a_type) = substs.types().next(); + if let ty::Adt(_, args) = a.kind(); + if let Some(a_type) = args.types().next(); if same_type_and_consts(a_type, b); then { @@ -255,8 +255,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { if_chain! { if match_def_path(cx, def_id, &paths::TRY_FROM); if is_type_diagnostic_item(cx, a, sym::Result); - if let ty::Adt(_, substs) = a.kind(); - if let Some(a_type) = substs.types().next(); + if let ty::Adt(_, args) = a.kind(); + if let Some(a_type) = args.types().next(); if same_type_and_consts(a_type, b); then { diff --git a/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs b/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs index dced9fcf9abd..da8654d9388d 100644 --- a/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs +++ b/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs @@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol { for item in cx.tcx.module_children(def_id) { if_chain! { if let Res::Def(DefKind::Const, item_def_id) = item.res; - let ty = cx.tcx.type_of(item_def_id).subst_identity(); + let ty = cx.tcx.type_of(item_def_id).instantiate_identity(); if match_type(cx, ty, &paths::SYMBOL); if let Ok(ConstValue::Scalar(value)) = cx.tcx.const_eval_poly(item_def_id); if let Ok(value) = value.to_u32(); diff --git a/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs b/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs index 09f0f0d0adb6..bf835f89cfc7 100644 --- a/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs +++ b/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs @@ -7,7 +7,7 @@ use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir_analysis::hir_ty_to_ty; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::ty::{self, subst::GenericArgKind}; +use rustc_middle::ty::{self, GenericArgKind}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { @@ -39,7 +39,7 @@ impl LateLintPass<'_> for MsrvAttrImpl { if self_ty_def.all_fields().any(|f| { cx.tcx .type_of(f.did) - .subst_identity() + .instantiate_identity() .walk() .filter(|t| matches!(t.unpack(), GenericArgKind::Type(_))) .any(|t| match_type(cx, t.expect_ty(), &paths::MSRV)) diff --git a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs index 00842376628c..f66f33fee166 100644 --- a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs +++ b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs @@ -229,11 +229,11 @@ fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option read_mir_alloc_def_path( cx, cx.tcx.eval_static_initializer(def_id).ok()?.inner(), - cx.tcx.type_of(def_id).subst_identity(), + cx.tcx.type_of(def_id).instantiate_identity(), ), Res::Def(DefKind::Const, def_id) => match cx.tcx.const_eval_poly(def_id).ok()? { ConstValue::ByRef { alloc, offset } if offset.bytes() == 0 => { - read_mir_alloc_def_path(cx, alloc.inner(), cx.tcx.type_of(def_id).subst_identity()) + read_mir_alloc_def_path(cx, alloc.inner(), cx.tcx.type_of(def_id).instantiate_identity()) }, _ => None, }, diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index 2a594e750b9b..d1bf292d7112 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -230,8 +230,8 @@ fn size_of(cx: &LateContext<'_>, expr: &Expr<'_>) -> u64 { /// Returns the item type of the vector (i.e., the `T` in `Vec`). fn vec_type(ty: Ty<'_>) -> Ty<'_> { - if let ty::Adt(_, substs) = ty.kind() { - substs.type_at(0) + if let ty::Adt(_, args) = ty.kind() { + args.type_at(0) } else { panic!("The type of `vec!` is a not a struct?"); } diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 93e4b023c5c7..002304f8840b 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -51,8 +51,8 @@ impl LateLintPass<'_> for ZeroSizedMapValues { if !in_trait_impl(cx, hir_ty.hir_id); let ty = ty_from_hir_ty(cx, hir_ty); if is_type_diagnostic_item(cx, ty, sym::HashMap) || is_type_diagnostic_item(cx, ty, sym::BTreeMap); - if let Adt(_, substs) = ty.kind(); - let ty = substs.type_at(1); + if let Adt(_, args) = ty.kind(); + let ty = args.type_at(1); // Fixes https://github.com/rust-lang/rust-clippy/issues/7447 because of // https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/ty/sty.rs#L968 if !ty.has_escaping_bound_vars(); diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index d1cfdc49658d..4832a38ecebf 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -12,7 +12,7 @@ use rustc_lint::LateContext; use rustc_middle::mir; use rustc_middle::mir::interpret::Scalar; use rustc_middle::ty::{self, EarlyBinder, FloatTy, ScalarInt, Ty, TyCtxt}; -use rustc_middle::ty::{List, SubstsRef}; +use rustc_middle::ty::{List, GenericArgsRef}; use rustc_middle::{bug, span_bug}; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::SyntaxContext; @@ -327,7 +327,7 @@ pub struct ConstEvalLateContext<'a, 'tcx> { typeck_results: &'a ty::TypeckResults<'tcx>, param_env: ty::ParamEnv<'tcx>, source: ConstantSource, - substs: SubstsRef<'tcx>, + args: GenericArgsRef<'tcx>, } impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { @@ -337,7 +337,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { typeck_results, param_env: lcx.param_env, source: ConstantSource::Local, - substs: List::empty(), + args: List::empty(), } } @@ -473,16 +473,16 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { return None; } - let substs = self.typeck_results.node_substs(id); - let substs = if self.substs.is_empty() { - substs + let args = self.typeck_results.node_args(id); + let args = if self.args.is_empty() { + args } else { - EarlyBinder::bind(substs).subst(self.lcx.tcx, self.substs) + EarlyBinder::bind(args).instantiate(self.lcx.tcx, self.args) }; let result = self .lcx .tcx - .const_eval_resolve(self.param_env, mir::UnevaluatedConst::new(def_id, substs), None) + .const_eval_resolve(self.param_env, mir::UnevaluatedConst::new(def_id, args), None) .ok() .map(|val| rustc_middle::mir::ConstantKind::from_value(val, ty))?; let result = miri_to_const(self.lcx, result)?; diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 4a845ca63b49..94b9006ed506 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -51,7 +51,7 @@ fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg: let name = name.as_str(); let ty = match cx.tcx.impl_of_method(fn_id) { - Some(id) => cx.tcx.type_of(id).subst_identity(), + Some(id) => cx.tcx.type_of(id).instantiate_identity(), None => return Lazy, }; @@ -72,7 +72,7 @@ fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg: .variants() .iter() .flat_map(|v| v.fields.iter()) - .any(|x| matches!(cx.tcx.type_of(x.did).subst_identity().peel_refs().kind(), ty::Param(_))) + .any(|x| matches!(cx.tcx.type_of(x.did).instantiate_identity().peel_refs().kind(), ty::Param(_))) && all_predicates_of(cx.tcx, fn_id).all(|(pred, _)| match pred.kind().skip_binder() { ty::ClauseKind::Trait(pred) => cx.tcx.trait_def(pred.trait_ref.def_id).is_marker, _ => true, @@ -80,7 +80,7 @@ fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg: && subs.types().all(|x| matches!(x.peel_refs().kind(), ty::Param(_))) { // Limit the function to either `(self) -> bool` or `(&self) -> bool` - match &**cx.tcx.fn_sig(fn_id).subst_identity().skip_binder().inputs_and_output { + match &**cx.tcx.fn_sig(fn_id).instantiate_identity().skip_binder().inputs_and_output { [arg, res] if !arg.is_mutable_ptr() && arg.peel_refs() == ty && res.is_bool() => NoChange, _ => Lazy, } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 727b59f1f432..5eed5ddf9e31 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -305,7 +305,7 @@ pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str]) /// Checks if a method is defined in an impl of a diagnostic item pub fn is_diag_item_method(cx: &LateContext<'_>, def_id: DefId, diag_item: Symbol) -> bool { if let Some(impl_did) = cx.tcx.impl_of_method(def_id) { - if let Some(adt) = cx.tcx.type_of(impl_did).subst_identity().ty_adt_def() { + if let Some(adt) = cx.tcx.type_of(impl_did).instantiate_identity().ty_adt_def() { return cx.tcx.is_diagnostic_item(diag_item, adt.did()); } } @@ -812,7 +812,7 @@ fn is_default_equivalent_ctor(cx: &LateContext<'_>, def_id: DefId, path: &QPath< if let QPath::TypeRelative(_, method) = path { if method.ident.name == sym::new { if let Some(impl_did) = cx.tcx.impl_of_method(def_id) { - if let Some(adt) = cx.tcx.type_of(impl_did).subst_identity().ty_adt_def() { + if let Some(adt) = cx.tcx.type_of(impl_did).instantiate_identity().ty_adt_def() { return std_types_symbols.iter().any(|&symbol| { cx.tcx.is_diagnostic_item(symbol, adt.did()) || Some(adt.did()) == cx.tcx.lang_items().string() }); @@ -1377,7 +1377,7 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>( .chain(args.iter()) .position(|arg| arg.hir_id == id)?; let id = cx.typeck_results().type_dependent_def_id(e.hir_id)?; - let ty = cx.tcx.fn_sig(id).subst_identity().skip_binder().inputs()[i]; + let ty = cx.tcx.fn_sig(id).instantiate_identity().skip_binder().inputs()[i]; ty_is_fn_once_param(cx.tcx, ty, cx.tcx.param_env(id).caller_bounds()).then_some(()) }, _ => None, @@ -1639,13 +1639,13 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option { /// Convenience function to get the return type of a function. pub fn return_ty<'tcx>(cx: &LateContext<'tcx>, fn_def_id: hir::OwnerId) -> Ty<'tcx> { - let ret_ty = cx.tcx.fn_sig(fn_def_id).subst_identity().output(); + let ret_ty = cx.tcx.fn_sig(fn_def_id).instantiate_identity().output(); cx.tcx.erase_late_bound_regions(ret_ty) } /// Convenience function to get the nth argument type of a function. pub fn nth_arg<'tcx>(cx: &LateContext<'tcx>, fn_def_id: hir::OwnerId, nth: usize) -> Ty<'tcx> { - let arg = cx.tcx.fn_sig(fn_def_id).subst_identity().input(nth); + let arg = cx.tcx.fn_sig(fn_def_id).instantiate_identity().input(nth); cx.tcx.erase_late_bound_regions(arg) } diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index fbf4ab2722e6..515f80e0edfb 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -15,7 +15,7 @@ use rustc_middle::mir::{ Terminator, TerminatorKind, }; use rustc_middle::traits::{ImplSource, ObligationCause}; -use rustc_middle::ty::subst::GenericArgKind; +use rustc_middle::ty::GenericArgKind; use rustc_middle::ty::{self, adjustment::PointerCoercion, Ty, TyCtxt}; use rustc_middle::ty::{BoundConstness, TraitRef}; use rustc_semver::RustcVersion; @@ -35,7 +35,7 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv) // impl trait is gone in MIR, so check the return type manually check_ty( tcx, - tcx.fn_sig(def_id).subst_identity().output().skip_binder(), + tcx.fn_sig(def_id).instantiate_identity().output().skip_binder(), body.local_decls.iter().next().unwrap().source_info.span, )?; diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index cf781e18cd66..3953a7d8fa7e 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -877,7 +877,7 @@ impl<'tcx> DerefDelegate<'_, 'tcx> { .cx .typeck_results() .type_dependent_def_id(parent_expr.hir_id) - .map(|did| self.cx.tcx.fn_sig(did).subst_identity().skip_binder()) + .map(|did| self.cx.tcx.fn_sig(did).instantiate_identity().skip_binder()) { std::iter::once(receiver) .chain(call_args.iter()) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index d650cbe0b132..7687d361923c 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -17,7 +17,7 @@ use rustc_lint::LateContext; use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::ty::{ self, layout::ValidityRequirement, AdtDef, AliasTy, AssocKind, Binder, BoundRegion, FnSig, IntTy, List, ParamEnv, - Region, RegionKind, SubstsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, + Region, RegionKind, GenericArgsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, UintTy, VariantDef, VariantDiscr, }; use rustc_middle::ty::{GenericArg, GenericArgKind}; @@ -90,14 +90,14 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' return false; } - for (predicate, _span) in cx.tcx.explicit_item_bounds(def_id).subst_identity_iter_copied() { + for (predicate, _span) in cx.tcx.explicit_item_bounds(def_id).instantiate_identity_iter_copied() { match predicate.kind().skip_binder() { // For `impl Trait`, it will register a predicate of `T: Trait`, so we go through // and check substitutions to find `U`. ty::ClauseKind::Trait(trait_predicate) => { if trait_predicate .trait_ref - .substs + .args .types() .skip(1) // Skip the implicit `Self` generic parameter .any(|ty| contains_ty_adt_constructor_opaque_inner(cx, ty, needle, seen)) @@ -237,7 +237,7 @@ pub fn implements_trait_with_env<'tcx>( kind: TypeVariableOriginKind::MiscVariable, span: DUMMY_SP, }; - let ty_params = tcx.mk_substs_from_iter( + let ty_params = tcx.mk_args_from_iter( ty_params .into_iter() .map(|arg| arg.unwrap_or_else(|| infcx.next_ty_var(orig).into())), @@ -265,7 +265,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { // because we don't want to lint functions returning empty arrays is_must_use_ty(cx, *ty) }, - ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), + ty::Tuple(args) => args.iter().any(|ty| is_must_use_ty(cx, ty)), ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { for (predicate, _) in cx.tcx.explicit_item_bounds(def_id).skip_binder() { if let ty::ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() { @@ -314,11 +314,11 @@ fn is_normalizable_helper<'tcx>( let cause = rustc_middle::traits::ObligationCause::dummy(); let result = if infcx.at(&cause, param_env).query_normalize(ty).is_ok() { match ty.kind() { - ty::Adt(def, substs) => def.variants().iter().all(|variant| { + ty::Adt(def, args) => def.variants().iter().all(|variant| { variant .fields .iter() - .all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache)) + .all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, args), cache)) }), _ => ty.walk().all(|generic_arg| match generic_arg.unpack() { GenericArgKind::Type(inner_ty) if inner_ty != ty => { @@ -517,14 +517,14 @@ pub fn walk_ptrs_ty_depth(ty: Ty<'_>) -> (Ty<'_>, usize) { /// otherwise returns `false` pub fn same_type_and_consts<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool { match (&a.kind(), &b.kind()) { - (&ty::Adt(did_a, substs_a), &ty::Adt(did_b, substs_b)) => { + (&ty::Adt(did_a, args_a), &ty::Adt(did_b, args_b)) => { if did_a != did_b { return false; } - substs_a + args_a .iter() - .zip(substs_b.iter()) + .zip(args_b.iter()) .all(|(arg_a, arg_b)| match (arg_a.unpack(), arg_b.unpack()) { (GenericArgKind::Const(inner_a), GenericArgKind::Const(inner_b)) => inner_a == inner_b, (GenericArgKind::Type(type_a), GenericArgKind::Type(type_b)) => { @@ -643,7 +643,7 @@ impl<'tcx> ExprFnSig<'tcx> { /// If the expression is function like, get the signature for it. pub fn expr_sig<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option> { if let Res::Def(DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn) | DefKind::AssocFn, id) = path_res(cx, expr) { - Some(ExprFnSig::Sig(cx.tcx.fn_sig(id).subst_identity(), Some(id))) + Some(ExprFnSig::Sig(cx.tcx.fn_sig(id).instantiate_identity(), Some(id))) } else { ty_sig(cx, cx.typeck_results().expr_ty_adjusted(expr).peel_refs()) } @@ -661,11 +661,11 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option Some(ExprFnSig::Sig(cx.tcx.fn_sig(id).subst(cx.tcx, subs), Some(id))), - ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => sig_from_bounds( + ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.fn_sig(id).instantiate(cx.tcx, subs), Some(id))), + ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => sig_from_bounds( cx, ty, - cx.tcx.item_bounds(def_id).subst_iter(cx.tcx, substs), + cx.tcx.item_bounds(def_id).arg_iter(cx.tcx, args), cx.tcx.opt_parent(def_id), ), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), @@ -681,7 +681,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option None, } @@ -713,7 +713,7 @@ fn sig_from_bounds<'tcx>( || lang_items.fn_once_trait() == Some(p.def_id())) && p.self_ty() == ty => { - let i = pred.kind().rebind(p.trait_ref.substs.type_at(1)); + let i = pred.kind().rebind(p.trait_ref.args.type_at(1)); if inputs.map_or(false, |inputs| i != inputs) { // Multiple different fn trait impls. Is this even allowed? return None; @@ -744,7 +744,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option for (pred, _) in cx .tcx .explicit_item_bounds(ty.def_id) - .subst_iter_copied(cx.tcx, ty.substs) + .arg_iter_copied(cx.tcx, ty.args) { match pred.kind().skip_binder() { ty::ClauseKind::Trait(p) @@ -752,7 +752,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option || lang_items.fn_mut_trait() == Some(p.def_id()) || lang_items.fn_once_trait() == Some(p.def_id())) => { - let i = pred.kind().rebind(p.trait_ref.substs.type_at(1)); + let i = pred.kind().rebind(p.trait_ref.args.type_at(1)); if inputs.map_or(false, |inputs| inputs != i) { // Multiple different fn trait impls. Is this even allowed? @@ -793,7 +793,7 @@ impl core::ops::Add for EnumValue { #[expect(clippy::cast_possible_truncation, clippy::cast_possible_wrap)] pub fn read_explicit_enum_value(tcx: TyCtxt<'_>, id: DefId) -> Option { if let Ok(ConstValue::Scalar(Scalar::Int(value))) = tcx.const_eval_poly(id) { - match tcx.type_of(id).subst_identity().kind() { + match tcx.type_of(id).instantiate_identity().kind() { ty::Int(_) => Some(EnumValue::Signed(match value.size().bytes() { 1 => i128::from(value.assert_bits(Size::from_bytes(1)) as u8 as i8), 2 => i128::from(value.assert_bits(Size::from_bytes(2)) as u16 as i16), @@ -927,7 +927,7 @@ pub fn adt_and_variant_of_res<'tcx>(cx: &LateContext<'tcx>, res: Res) -> Option< Some((adt, adt.variant_with_id(var_id))) }, Res::SelfCtor(id) => { - let adt = cx.tcx.type_of(id).subst_identity().ty_adt_def().unwrap(); + let adt = cx.tcx.type_of(id).instantiate_identity().ty_adt_def().unwrap(); Some((adt, adt.non_enum_variant())) }, _ => None, @@ -1025,13 +1025,13 @@ pub fn make_projection<'tcx>( tcx: TyCtxt<'tcx>, container_id: DefId, assoc_ty: Symbol, - substs: impl IntoIterator>>, + args: impl IntoIterator>>, ) -> Option> { fn helper<'tcx>( tcx: TyCtxt<'tcx>, container_id: DefId, assoc_ty: Symbol, - substs: SubstsRef<'tcx>, + args: GenericArgsRef<'tcx>, ) -> Option> { let Some(assoc_item) = tcx .associated_items(container_id) @@ -1052,18 +1052,18 @@ pub fn make_projection<'tcx>( .map(|x| &x.kind); debug_assert!( - generic_count == substs.len(), - "wrong number of substs for `{:?}`: found `{}` expected `{generic_count}`.\n\ + generic_count == args.len(), + "wrong number of args for `{:?}`: found `{}` expected `{generic_count}`.\n\ note: the expected parameters are: {:#?}\n\ - the given arguments are: `{substs:#?}`", + the given arguments are: `{args:#?}`", assoc_item.def_id, - substs.len(), + args.len(), params.map(ty::GenericParamDefKind::descr).collect::>(), ); if let Some((idx, (param, arg))) = params .clone() - .zip(substs.iter().map(GenericArg::unpack)) + .zip(args.iter().map(GenericArg::unpack)) .enumerate() .find(|(_, (param, arg))| { !matches!( @@ -1078,20 +1078,20 @@ pub fn make_projection<'tcx>( false, "mismatched subst type at index {idx}: expected a {}, found `{arg:?}`\n\ note: the expected parameters are {:#?}\n\ - the given arguments are {substs:#?}", + the given arguments are {args:#?}", param.descr(), params.map(ty::GenericParamDefKind::descr).collect::>() ); } } - Some(tcx.mk_alias_ty(assoc_item.def_id, substs)) + Some(tcx.mk_alias_ty(assoc_item.def_id, args)) } helper( tcx, container_id, assoc_ty, - tcx.mk_substs_from_iter(substs.into_iter().map(Into::into)), + tcx.mk_args_from_iter(args.into_iter().map(Into::into)), ) } @@ -1106,25 +1106,25 @@ pub fn make_normalized_projection<'tcx>( param_env: ParamEnv<'tcx>, container_id: DefId, assoc_ty: Symbol, - substs: impl IntoIterator>>, + args: impl IntoIterator>>, ) -> Option> { fn helper<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: AliasTy<'tcx>) -> Option> { #[cfg(debug_assertions)] if let Some((i, subst)) = ty - .substs + .args .iter() .enumerate() .find(|(_, subst)| subst.has_late_bound_regions()) { debug_assert!( false, - "substs contain late-bound region at index `{i}` which can't be normalized.\n\ + "args contain late-bound region at index `{i}` which can't be normalized.\n\ use `TyCtxt::erase_late_bound_regions`\n\ note: subst is `{subst:#?}`", ); return None; } - match tcx.try_normalize_erasing_regions(param_env, Ty::new_projection(tcx,ty.def_id, ty.substs)) { + match tcx.try_normalize_erasing_regions(param_env, Ty::new_projection(tcx,ty.def_id, ty.args)) { Ok(ty) => Some(ty), Err(e) => { debug_assert!(false, "failed to normalize type `{ty}`: {e:#?}"); @@ -1132,7 +1132,7 @@ pub fn make_normalized_projection<'tcx>( }, } } - helper(tcx, param_env, make_projection(tcx, container_id, assoc_ty, substs)?) + helper(tcx, param_env, make_projection(tcx, container_id, assoc_ty, args)?) } /// Check if given type has inner mutability such as [`std::cell::Cell`] or [`std::cell::RefCell`] @@ -1147,7 +1147,7 @@ pub fn is_interior_mut_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { && is_interior_mut_ty(cx, inner_ty) }, ty::Tuple(fields) => fields.iter().any(|ty| is_interior_mut_ty(cx, ty)), - ty::Adt(def, substs) => { + ty::Adt(def, args) => { // Special case for collections in `std` who's impl of `Hash` or `Ord` delegates to // that of their type parameters. Note: we don't include `HashSet` and `HashMap` // because they have no impl for `Hash` or `Ord`. @@ -1168,7 +1168,7 @@ pub fn is_interior_mut_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { let is_box = Some(def_id) == cx.tcx.lang_items().owned_box(); if is_std_collection || is_box { // The type is mutable if any of its type parameters are - substs.types().any(|ty| is_interior_mut_ty(cx, ty)) + args.types().any(|ty| is_interior_mut_ty(cx, ty)) } else { !ty.has_escaping_bound_vars() && cx.tcx.layout_of(cx.param_env.and(ty)).is_ok() @@ -1184,19 +1184,19 @@ pub fn make_normalized_projection_with_regions<'tcx>( param_env: ParamEnv<'tcx>, container_id: DefId, assoc_ty: Symbol, - substs: impl IntoIterator>>, + args: impl IntoIterator>>, ) -> Option> { fn helper<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: AliasTy<'tcx>) -> Option> { #[cfg(debug_assertions)] if let Some((i, subst)) = ty - .substs + .args .iter() .enumerate() .find(|(_, subst)| subst.has_late_bound_regions()) { debug_assert!( false, - "substs contain late-bound region at index `{i}` which can't be normalized.\n\ + "args contain late-bound region at index `{i}` which can't be normalized.\n\ use `TyCtxt::erase_late_bound_regions`\n\ note: subst is `{subst:#?}`", ); @@ -1207,7 +1207,7 @@ pub fn make_normalized_projection_with_regions<'tcx>( .infer_ctxt() .build() .at(&cause, param_env) - .query_normalize(Ty::new_projection(tcx,ty.def_id, ty.substs)) + .query_normalize(Ty::new_projection(tcx,ty.def_id, ty.args)) { Ok(ty) => Some(ty.value), Err(e) => { @@ -1216,7 +1216,7 @@ pub fn make_normalized_projection_with_regions<'tcx>( }, } } - helper(tcx, param_env, make_projection(tcx, container_id, assoc_ty, substs)?) + helper(tcx, param_env, make_projection(tcx, container_id, assoc_ty, args)?) } pub fn normalize_with_regions<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { diff --git a/tests/ui/crashes/ice-6256.rs b/tests/ui/crashes/ice-6256.rs index 1d336b3cdc0c..bb488c2dcb35 100644 --- a/tests/ui/crashes/ice-6256.rs +++ b/tests/ui/crashes/ice-6256.rs @@ -1,5 +1,5 @@ // originally from rustc ./tests/ui/regions/issue-78262.rs -// ICE: to get the signature of a closure, use substs.as_closure().sig() not fn_sig() +// ICE: to get the signature of a closure, use args.as_closure().sig() not fn_sig() #![allow(clippy::upper_case_acronyms)] trait TT {} diff --git a/tests/ui/eta.fixed b/tests/ui/eta.fixed index bf44bcb564ec..db7bd99e0ae6 100644 --- a/tests/ui/eta.fixed +++ b/tests/ui/eta.fixed @@ -331,7 +331,7 @@ impl dyn TestTrait + '_ { } // https://github.com/rust-lang/rust-clippy/issues/7746 -fn angle_brackets_and_substs() { +fn angle_brackets_and_args() { let array_opt: Option<&[u8; 3]> = Some(&[4, 8, 7]); array_opt.map(<[u8; 3]>::as_slice); diff --git a/tests/ui/eta.rs b/tests/ui/eta.rs index b2af4bf09537..52fc17686fdf 100644 --- a/tests/ui/eta.rs +++ b/tests/ui/eta.rs @@ -331,7 +331,7 @@ impl dyn TestTrait + '_ { } // https://github.com/rust-lang/rust-clippy/issues/7746 -fn angle_brackets_and_substs() { +fn angle_brackets_and_args() { let array_opt: Option<&[u8; 3]> = Some(&[4, 8, 7]); array_opt.map(|a| a.as_slice()); From 7c241d5d8379c1c6d1080f4031e3d3525d377480 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Mon, 17 Jul 2023 10:22:49 +0200 Subject: [PATCH 0880/1222] Another fix for incorrect_impls --- clippy_lints/src/incorrect_impls.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/incorrect_impls.rs b/clippy_lints/src/incorrect_impls.rs index c5da6039ac39..e6c42ebb8329 100644 --- a/clippy_lints/src/incorrect_impls.rs +++ b/clippy_lints/src/incorrect_impls.rs @@ -4,7 +4,6 @@ use clippy_utils::{get_parent_node, is_res_lang_ctor, last_path_segment, path_re use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::{Expr, ExprKind, ImplItem, ImplItemKind, ItemKind, LangItem, Node, UnOp}; -use rustc_hir_analysis::hir_ty_to_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::EarlyBinder; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -121,7 +120,7 @@ impl LateLintPass<'_> for IncorrectImpls { if cx.tcx.is_automatically_derived(item.owner_id.to_def_id()) { return; } - let ItemKind::Impl(imp) = item.kind else { + let ItemKind::Impl(_) = item.kind else { return; }; let ImplItemKind::Fn(_, impl_item_id) = cx.tcx.hir().impl_item(impl_item.impl_item_id()).kind else { @@ -186,9 +185,9 @@ impl LateLintPass<'_> for IncorrectImpls { .get(&sym::Ord) && implements_trait( cx, - hir_ty_to_ty(cx.tcx, imp.self_ty), + trait_impl.self_ty(), *ord_def_id, - trait_impl.args, + &[], ) { if block.stmts.is_empty() From d72b8b9324de05d6db5a56c0f7539b118709ef4e Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 17 Jul 2023 17:49:47 +0000 Subject: [PATCH 0881/1222] Rename arg_iter to iter_instantiated --- clippy_lints/src/future_not_send.rs | 2 +- clippy_utils/src/ty.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index e54429aee8e8..621415c881cf 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { if let ty::Alias(ty::Opaque, AliasTy { def_id, args, .. }) = *ret_ty.kind() { let preds = cx.tcx.explicit_item_bounds(def_id); let mut is_future = false; - for (p, _span) in preds.arg_iter_copied(cx.tcx, args) { + for (p, _span) in preds.iter_instantiated_copied(cx.tcx, args) { if let Some(trait_pred) = p.as_trait_clause() { if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() { is_future = true; diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index ad79143f4da9..fd39a246f48d 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -663,7 +663,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option sig_from_bounds( cx, ty, - cx.tcx.item_bounds(def_id).arg_iter(cx.tcx, args), + cx.tcx.item_bounds(def_id).iter_instantiated(cx.tcx, args), cx.tcx.opt_parent(def_id), ), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), @@ -739,7 +739,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option let mut output = None; let lang_items = cx.tcx.lang_items(); - for (pred, _) in cx.tcx.explicit_item_bounds(ty.def_id).arg_iter_copied(cx.tcx, ty.args) { + for (pred, _) in cx.tcx.explicit_item_bounds(ty.def_id).iter_instantiated_copied(cx.tcx, ty.args) { match pred.kind().skip_binder() { ty::ClauseKind::Trait(p) if (lang_items.fn_trait() == Some(p.def_id()) From 0af24b31e323be73ec31a61f67bfc810c5c9eb6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 3 Mar 2023 22:25:18 +0000 Subject: [PATCH 0882/1222] On nightly, dump ICE backtraces to disk Implement rust-lang/compiler-team#578. When an ICE is encountered on nightly releases, the new rustc panic handler will also write the contents of the backtrace to disk. If any `delay_span_bug`s are encountered, their backtrace is also added to the file. The platform and rustc version will also be collected. --- clippy_lints/src/doc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index e5f39d102cd3..8879c529262b 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -729,7 +729,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { false, TerminalUrl::No, ); - let handler = Handler::with_emitter(false, None, Box::new(emitter)); + let handler = Handler::with_emitter(false, None, Box::new(emitter), None); let sess = ParseSess::with_span_handler(handler, sm); let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) { From cc8c8fc3041bb177aa6528fb09e429bc35f3a2e6 Mon Sep 17 00:00:00 2001 From: lcnr Date: Tue, 18 Jul 2023 17:03:22 +0200 Subject: [PATCH 0883/1222] XSimplifiedType to SimplifiedType::X --- .../src/utils/internal_lints/invalid_paths.rs | 8 ++-- clippy_utils/src/lib.rs | 47 +++++++++---------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/clippy_lints/src/utils/internal_lints/invalid_paths.rs b/clippy_lints/src/utils/internal_lints/invalid_paths.rs index 94b56304bcab..e4906944c8d0 100644 --- a/clippy_lints/src/utils/internal_lints/invalid_paths.rs +++ b/clippy_lints/src/utils/internal_lints/invalid_paths.rs @@ -74,10 +74,10 @@ pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool { let lang_items = cx.tcx.lang_items(); // This list isn't complete, but good enough for our current list of paths. let incoherent_impls = [ - SimplifiedType::FloatSimplifiedType(FloatTy::F32), - SimplifiedType::FloatSimplifiedType(FloatTy::F64), - SimplifiedType::SliceSimplifiedType, - SimplifiedType::StrSimplifiedType, + SimplifiedType::Float(FloatTy::F32), + SimplifiedType::Float(FloatTy::F64), + SimplifiedType::Slice, + SimplifiedType::Str, ] .iter() .flat_map(|&ty| cx.tcx.incoherent_impls(ty).iter().copied()); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 00e893fbdda8..035511e89125 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -100,10 +100,7 @@ use rustc_middle::mir::ConstantKind; use rustc_middle::ty as rustc_ty; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; use rustc_middle::ty::binding::BindingMode; -use rustc_middle::ty::fast_reject::SimplifiedType::{ - ArraySimplifiedType, BoolSimplifiedType, CharSimplifiedType, FloatSimplifiedType, IntSimplifiedType, - PtrSimplifiedType, SliceSimplifiedType, StrSimplifiedType, UintSimplifiedType, -}; +use rustc_middle::ty::fast_reject::SimplifiedType; use rustc_middle::ty::layout::IntegerExt; use rustc_middle::ty::{ BorrowKind, ClosureKind, FloatTy, IntTy, Ty, TyCtxt, TypeAndMut, TypeVisitableExt, UintTy, UpvarCapture, @@ -512,30 +509,30 @@ pub fn path_def_id<'tcx>(cx: &LateContext<'_>, maybe_path: &impl MaybePath<'tcx> fn find_primitive_impls<'tcx>(tcx: TyCtxt<'tcx>, name: &str) -> impl Iterator + 'tcx { let ty = match name { - "bool" => BoolSimplifiedType, - "char" => CharSimplifiedType, - "str" => StrSimplifiedType, - "array" => ArraySimplifiedType, - "slice" => SliceSimplifiedType, + "bool" => SimplifiedType::Bool, + "char" => SimplifiedType::Char, + "str" => SimplifiedType::Str, + "array" => SimplifiedType::Array, + "slice" => SimplifiedType::Slice, // FIXME: rustdoc documents these two using just `pointer`. // // Maybe this is something we should do here too. - "const_ptr" => PtrSimplifiedType(Mutability::Not), - "mut_ptr" => PtrSimplifiedType(Mutability::Mut), - "isize" => IntSimplifiedType(IntTy::Isize), - "i8" => IntSimplifiedType(IntTy::I8), - "i16" => IntSimplifiedType(IntTy::I16), - "i32" => IntSimplifiedType(IntTy::I32), - "i64" => IntSimplifiedType(IntTy::I64), - "i128" => IntSimplifiedType(IntTy::I128), - "usize" => UintSimplifiedType(UintTy::Usize), - "u8" => UintSimplifiedType(UintTy::U8), - "u16" => UintSimplifiedType(UintTy::U16), - "u32" => UintSimplifiedType(UintTy::U32), - "u64" => UintSimplifiedType(UintTy::U64), - "u128" => UintSimplifiedType(UintTy::U128), - "f32" => FloatSimplifiedType(FloatTy::F32), - "f64" => FloatSimplifiedType(FloatTy::F64), + "const_ptr" => SimplifiedType::Ptr(Mutability::Not), + "mut_ptr" => SimplifiedType::Ptr(Mutability::Mut), + "isize" => SimplifiedType::Int(IntTy::Isize), + "i8" => SimplifiedType::Int(IntTy::I8), + "i16" => SimplifiedType::Int(IntTy::I16), + "i32" => SimplifiedType::Int(IntTy::I32), + "i64" => SimplifiedType::Int(IntTy::I64), + "i128" => SimplifiedType::Int(IntTy::I128), + "usize" => SimplifiedType::Uint(UintTy::Usize), + "u8" => SimplifiedType::Uint(UintTy::U8), + "u16" => SimplifiedType::Uint(UintTy::U16), + "u32" => SimplifiedType::Uint(UintTy::U32), + "u64" => SimplifiedType::Uint(UintTy::U64), + "u128" => SimplifiedType::Uint(UintTy::U128), + "f32" => SimplifiedType::Float(FloatTy::F32), + "f64" => SimplifiedType::Float(FloatTy::F64), _ => return [].iter().copied(), }; From edfec8e72a3fdd5e307d314c0befc10b778b372d Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Thu, 25 May 2023 05:21:44 +0000 Subject: [PATCH 0884/1222] fix --- tests/ui/explicit_deref_methods.fixed | 1 + tests/ui/explicit_deref_methods.rs | 1 + tests/ui/explicit_deref_methods.stderr | 24 ++++++++++++------------ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/ui/explicit_deref_methods.fixed b/tests/ui/explicit_deref_methods.fixed index 4d72b58cdf86..4c0b0d8f275e 100644 --- a/tests/ui/explicit_deref_methods.fixed +++ b/tests/ui/explicit_deref_methods.fixed @@ -4,6 +4,7 @@ #![allow( clippy::borrow_deref_ref, suspicious_double_ref_op, + noop_method_call, clippy::explicit_auto_deref, clippy::needless_borrow, clippy::no_effect, diff --git a/tests/ui/explicit_deref_methods.rs b/tests/ui/explicit_deref_methods.rs index fcd945de3386..bc5da35e52e3 100644 --- a/tests/ui/explicit_deref_methods.rs +++ b/tests/ui/explicit_deref_methods.rs @@ -4,6 +4,7 @@ #![allow( clippy::borrow_deref_ref, suspicious_double_ref_op, + noop_method_call, clippy::explicit_auto_deref, clippy::needless_borrow, clippy::no_effect, diff --git a/tests/ui/explicit_deref_methods.stderr b/tests/ui/explicit_deref_methods.stderr index 362e559b21a5..e4d2fe3a1c3d 100644 --- a/tests/ui/explicit_deref_methods.stderr +++ b/tests/ui/explicit_deref_methods.stderr @@ -1,5 +1,5 @@ error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:54:19 + --> $DIR/explicit_deref_methods.rs:55:19 | LL | let b: &str = a.deref(); | ^^^^^^^^^ help: try: `&*a` @@ -7,67 +7,67 @@ LL | let b: &str = a.deref(); = note: `-D clippy::explicit-deref-methods` implied by `-D warnings` error: explicit `deref_mut` method call - --> $DIR/explicit_deref_methods.rs:56:23 + --> $DIR/explicit_deref_methods.rs:57:23 | LL | let b: &mut str = a.deref_mut(); | ^^^^^^^^^^^^^ help: try: `&mut **a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:59:39 + --> $DIR/explicit_deref_methods.rs:60:39 | LL | let b: String = format!("{}, {}", a.deref(), a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:59:50 + --> $DIR/explicit_deref_methods.rs:60:50 | LL | let b: String = format!("{}, {}", a.deref(), a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:61:20 + --> $DIR/explicit_deref_methods.rs:62:20 | LL | println!("{}", a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:64:11 + --> $DIR/explicit_deref_methods.rs:65:11 | LL | match a.deref() { | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:68:28 + --> $DIR/explicit_deref_methods.rs:69:28 | LL | let b: String = concat(a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:70:13 + --> $DIR/explicit_deref_methods.rs:71:13 | LL | let b = just_return(a).deref(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `just_return(a)` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:72:28 + --> $DIR/explicit_deref_methods.rs:73:28 | LL | let b: String = concat(just_return(a).deref()); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `just_return(a)` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:74:19 + --> $DIR/explicit_deref_methods.rs:75:19 | LL | let b: &str = a.deref().deref(); | ^^^^^^^^^^^^^^^^^ help: try: `&**a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:77:13 + --> $DIR/explicit_deref_methods.rs:78:13 | LL | let b = opt_a.unwrap().deref(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*opt_a.unwrap()` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:114:31 + --> $DIR/explicit_deref_methods.rs:115:31 | LL | let b: &str = expr_deref!(a.deref()); | ^^^^^^^^^ help: try: `&*a` From 392481f1cf9cd66b4c6794dbbd6286e0aba304ad Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 24 Jul 2023 14:47:32 +0000 Subject: [PATCH 0885/1222] Perform OpaqueCast field projection on HIR, too. This is necessary for closure captures in 2021 edition, as they capture individual fields, not the full mentioned variables. So it may try to capture a field of an opaque (because the hidden type is known to be something with a field). --- clippy_utils/src/sugg.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 5d7e1494fcfd..a43a81bc63a1 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -1011,6 +1011,8 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> { }, // note: unable to trigger `Subslice` kind in tests ProjectionKind::Subslice => (), + // Doesn't have surface syntax. Only occurs in patterns. + ProjectionKind::OpaqueCast => (), ProjectionKind::Deref => { // Explicit derefs are typically handled later on, but // some items do not need explicit deref, such as array accesses, From 10c667703feda82826170c74aedb438a9c8bad05 Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 25 Jul 2023 11:56:54 +0100 Subject: [PATCH 0886/1222] clippy: `env!` invocations can't be b"" literals Signed-off-by: David Wood --- clippy_lints/src/strings.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 58724852b3c4..4d45091f4b5b 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -328,7 +328,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { { // Don't lint. Byte strings produce `&[u8; N]` whereas `as_bytes()` produces // `&[u8]`. This change would prevent matching with different sized slices. - } else { + } else if !callsite.starts_with("env!") { span_lint_and_sugg( cx, STRING_LIT_AS_BYTES, From 1231655328c87580ef19a689ebc6a25dc8e0051f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 24 Jul 2023 19:42:21 +0200 Subject: [PATCH 0887/1222] bless more --- tests/ui/self_assignment.rs | 2 +- tests/ui/self_assignment.stderr | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ui/self_assignment.rs b/tests/ui/self_assignment.rs index d6682cc63dcf..a7f9fbaae7cf 100644 --- a/tests/ui/self_assignment.rs +++ b/tests/ui/self_assignment.rs @@ -14,7 +14,7 @@ pub fn positives(mut a: usize, b: &mut u32, mut s: S) { *b = *b; s = s; s.a = s.a; - s.b[10] = s.b[5 + 5]; + s.b[9] = s.b[5 + 4]; s.c[0][1] = s.c[0][1]; s.b[a] = s.b[a]; *s.e = *s.e; diff --git a/tests/ui/self_assignment.stderr b/tests/ui/self_assignment.stderr index bed88244eea7..25b8569fa3d0 100644 --- a/tests/ui/self_assignment.stderr +++ b/tests/ui/self_assignment.stderr @@ -24,11 +24,11 @@ error: self-assignment of `s.a` to `s.a` LL | s.a = s.a; | ^^^^^^^^^ -error: self-assignment of `s.b[5 + 5]` to `s.b[10]` +error: self-assignment of `s.b[5 + 4]` to `s.b[9]` --> $DIR/self_assignment.rs:17:5 | -LL | s.b[10] = s.b[5 + 5]; - | ^^^^^^^^^^^^^^^^^^^^ +LL | s.b[9] = s.b[5 + 4]; + | ^^^^^^^^^^^^^^^^^^^ error: self-assignment of `s.c[0][1]` to `s.c[0][1]` --> $DIR/self_assignment.rs:18:5 From 1a0020c3737774c00cb2c949c5c2102b8b8f7276 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 25 Jul 2023 10:27:34 +0000 Subject: [PATCH 0888/1222] Use a builder instead of boolean/option arguments --- clippy_lints/src/doc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 8879c529262b..00f70e586f42 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -729,7 +729,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { false, TerminalUrl::No, ); - let handler = Handler::with_emitter(false, None, Box::new(emitter), None); + let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings(); let sess = ParseSess::with_span_handler(handler, sm); let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) { From 2ee886e0f50c2b8991bea87af02553a0cb6c50e5 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 24 Jul 2023 22:02:52 +0000 Subject: [PATCH 0889/1222] Make everything builtin! --- clippy_utils/src/qualify_min_const_fn.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 1c29d614fa34..e563e41ab2aa 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -14,7 +14,7 @@ use rustc_middle::mir::{ Body, CastKind, NonDivergingIntrinsic, NullOp, Operand, Place, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, }; -use rustc_middle::traits::{ImplSource, ObligationCause}; +use rustc_middle::traits::{ImplSource, ObligationCause, BuiltinImplSource}; use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::{self, BoundConstness, GenericArgKind, TraitRef, Ty, TyCtxt}; use rustc_semver::RustcVersion; @@ -411,7 +411,7 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx> if !matches!( impl_src, - ImplSource::Builtin(_) | ImplSource::Param(_, ty::BoundConstness::ConstIfConst) + ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(ty::BoundConstness::ConstIfConst, _) ) { return false; } From 1150c75bef4b73485f7831872c4e95c05ce9fa8c Mon Sep 17 00:00:00 2001 From: blyxyas Date: Tue, 25 Jul 2023 20:22:41 +0000 Subject: [PATCH 0890/1222] Add `sym::iter_mut` + `sym::as_mut_ptr` --- clippy_lints/src/methods/bytecount.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/methods/bytecount.rs b/clippy_lints/src/methods/bytecount.rs index fef90f6eba49..f490a7175540 100644 --- a/clippy_lints/src/methods/bytecount.rs +++ b/clippy_lints/src/methods/bytecount.rs @@ -45,7 +45,7 @@ pub(super) fn check<'tcx>( let haystack = if let ExprKind::MethodCall(path, receiver, [], _) = filter_recv.kind { let p = path.ident.name; - if p == sym::iter || p == sym!(iter_mut) { + if p == sym::iter || p == sym::iter_mut { receiver } else { filter_recv From e01a203c8607eb4d4119a468804f2d6ddaf9ec4c Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 3 Jul 2023 13:40:14 -0400 Subject: [PATCH 0891/1222] Unite bless environment variables under `RUSTC_BLESS` Currently, Clippy, Miri, Rustfmt, and rustc all use an environment variable to indicate that output should be blessed, but they use different variable names. In order to improve consistency, this patch applies the following changes: - Emit `RUSTC_BLESS` within `prepare_cargo_test` so it is always available - Change usage of `MIRI_BLESS` in the Miri subtree to use `RUSTC_BLESS` - Change usage of `BLESS` in the Clippy subtree to `RUSTC_BLESS` - Change usage of `BLESS` in the Rustfmt subtree to `RUSTC_BLESS` - Adjust the blessable test in `rustc_errors` to use this same convention - Update documentation where applicable Any tools that uses `RUSTC_BLESS` should check that it is set to any value other than `"0"`. --- tests/compile-test.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/compile-test.rs b/tests/compile-test.rs index d70c4ea34cbc..f714b2962331 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -115,7 +115,9 @@ fn base_config(test_dir: &str) -> compiletest::Config { mode: TestMode::Yolo, stderr_filters: vec![], stdout_filters: vec![], - output_conflict_handling: if var_os("BLESS").is_some() || env::args().any(|arg| arg == "--bless") { + // FIXME(tgross35): deduplicate bless env once clippy can update + output_conflict_handling: if var_os("RUSTC_BLESS").is_some_and(|v| v != "0") + || env::args().any(|arg| arg == "--bless") { compiletest::OutputConflictHandling::Bless } else { compiletest::OutputConflictHandling::Error("cargo test -- -- --bless".into()) From 5ed58763aafc5367fc34fd07429fbf3aa06e1413 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Thu, 27 Jul 2023 15:50:42 +0000 Subject: [PATCH 0892/1222] Remove `constness` from `ParamEnv` --- clippy_lints/src/derive.rs | 3 +-- clippy_lints/src/manual_float_methods.rs | 2 +- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index c343f248d06d..91bc30ab5774 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -6,7 +6,7 @@ use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, Visitor}; use rustc_hir::{ - self as hir, BlockCheckMode, BodyId, Constness, Expr, ExprKind, FnDecl, Impl, Item, ItemKind, UnsafeSource, + self as hir, BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, Impl, Item, ItemKind, UnsafeSource, Unsafety, }; use rustc_lint::{LateContext, LateLintPass}; @@ -526,6 +526,5 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> }), )), Reveal::UserFacing, - Constness::NotConst, ) } diff --git a/clippy_lints/src/manual_float_methods.rs b/clippy_lints/src/manual_float_methods.rs index 085c73a5f9fb..ccd2f06aad27 100644 --- a/clippy_lints/src/manual_float_methods.rs +++ b/clippy_lints/src/manual_float_methods.rs @@ -83,7 +83,7 @@ impl Variant { impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if !in_external_macro(cx.sess(), expr.span) - && (!cx.param_env.is_const() || cx.tcx.features().active(sym!(const_float_classify))) + && cx.tcx.features().active(sym!(const_float_classify)) && let ExprKind::Binary(kind, lhs, rhs) = expr.kind && let ExprKind::Binary(lhs_kind, lhs_lhs, lhs_rhs) = lhs.kind && let ExprKind::Binary(rhs_kind, rhs_lhs, rhs_rhs) = rhs.kind diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index e563e41ab2aa..aed3d601bcac 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -399,7 +399,7 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx> let obligation = Obligation::new( tcx, ObligationCause::dummy_with_span(body.span), - ConstCx::new(tcx, body).param_env.with_const(), + ConstCx::new(tcx, body).param_env, TraitRef::from_lang_item(tcx, LangItem::Destruct, body.span, [ty]).with_constness(BoundConstness::ConstIfConst), ); From ef52a5fba376c4adcb699055f4d7bd547563d175 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Thu, 27 Jul 2023 17:56:25 +0000 Subject: [PATCH 0893/1222] bless clippy --- clippy_lints/src/manual_float_methods.rs | 8 +-- clippy_utils/src/qualify_min_const_fn.rs | 52 +++++++++++-------- .../ui/missing_const_for_fn/could_be_const.rs | 1 + .../could_be_const.stderr | 8 +-- 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/clippy_lints/src/manual_float_methods.rs b/clippy_lints/src/manual_float_methods.rs index ccd2f06aad27..f48a5d9d2456 100644 --- a/clippy_lints/src/manual_float_methods.rs +++ b/clippy_lints/src/manual_float_methods.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_opt; use clippy_utils::{is_from_proc_macro, path_to_local}; use rustc_errors::Applicability; -use rustc_hir::{BinOpKind, Expr, ExprKind}; +use rustc_hir::{BinOpKind, Constness, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass, Lint, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -83,8 +83,10 @@ impl Variant { impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if !in_external_macro(cx.sess(), expr.span) - && cx.tcx.features().active(sym!(const_float_classify)) - && let ExprKind::Binary(kind, lhs, rhs) = expr.kind + && ( + matches!(cx.tcx.constness(cx.tcx.hir().enclosing_body_owner(expr.hir_id)), Constness::NotConst) + || cx.tcx.features().active(sym!(const_float_classify)) + ) && let ExprKind::Binary(kind, lhs, rhs) = expr.kind && let ExprKind::Binary(lhs_kind, lhs_lhs, lhs_rhs) = lhs.kind && let ExprKind::Binary(rhs_kind, rhs_lhs, rhs_rhs) = rhs.kind // Checking all possible scenarios using a function would be a hopeless task, as we have diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index aed3d601bcac..a98e2038d5f0 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -391,32 +391,38 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool { #[expect(clippy::similar_names)] // bit too pedantic fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx>) -> bool { - // Avoid selecting for simple cases, such as builtin types. - if ty::util::is_trivially_const_drop(ty) { - return true; - } + // FIXME(effects, fee1-dead) revert to const destruct once it works again + #[expect(unused)] + fn is_ty_const_destruct_unused<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx>) -> bool { + // Avoid selecting for simple cases, such as builtin types. + if ty::util::is_trivially_const_drop(ty) { + return true; + } - let obligation = Obligation::new( - tcx, - ObligationCause::dummy_with_span(body.span), - ConstCx::new(tcx, body).param_env, - TraitRef::from_lang_item(tcx, LangItem::Destruct, body.span, [ty]).with_constness(BoundConstness::ConstIfConst), - ); + let obligation = Obligation::new( + tcx, + ObligationCause::dummy_with_span(body.span), + ConstCx::new(tcx, body).param_env, + TraitRef::from_lang_item(tcx, LangItem::Destruct, body.span, [ty]).with_constness(BoundConstness::ConstIfConst), + ); - let infcx = tcx.infer_ctxt().build(); - let mut selcx = SelectionContext::new(&infcx); - let Some(impl_src) = selcx.select(&obligation).ok().flatten() else { - return false; - }; + let infcx = tcx.infer_ctxt().build(); + let mut selcx = SelectionContext::new(&infcx); + let Some(impl_src) = selcx.select(&obligation).ok().flatten() else { + return false; + }; + + if !matches!( + impl_src, + ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(ty::BoundConstness::ConstIfConst, _) + ) { + return false; + } - if !matches!( - impl_src, - ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(ty::BoundConstness::ConstIfConst, _) - ) { - return false; + let ocx = ObligationCtxt::new(&infcx); + ocx.register_obligations(impl_src.nested_obligations()); + ocx.select_all_or_error().is_empty() } - let ocx = ObligationCtxt::new(&infcx); - ocx.register_obligations(impl_src.nested_obligations()); - ocx.select_all_or_error().is_empty() + !ty.needs_drop(tcx, ConstCx::new(tcx, body).param_env) } diff --git a/tests/ui/missing_const_for_fn/could_be_const.rs b/tests/ui/missing_const_for_fn/could_be_const.rs index b1980b1b523f..3aaee67e1d97 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.rs +++ b/tests/ui/missing_const_for_fn/could_be_const.rs @@ -99,4 +99,5 @@ impl const Drop for D { } // Lint this, since it can be dropped in const contexts +// FIXME(effects) fn d(this: D) {} diff --git a/tests/ui/missing_const_for_fn/could_be_const.stderr b/tests/ui/missing_const_for_fn/could_be_const.stderr index 7be2cc0ca930..66cf4e315293 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.stderr +++ b/tests/ui/missing_const_for_fn/could_be_const.stderr @@ -89,11 +89,5 @@ LL | | 46 LL | | } | |_^ -error: this could be a `const fn` - --> $DIR/could_be_const.rs:102:1 - | -LL | fn d(this: D) {} - | ^^^^^^^^^^^^^^^^ - -error: aborting due to 12 previous errors +error: aborting due to 11 previous errors From fbad9a035e82355cc21decb0b1cd63538f00e5d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sun, 2 Jul 2023 23:21:36 +0200 Subject: [PATCH 0894/1222] Make Clippy understand generic const items --- clippy_lints/src/large_const_arrays.rs | 6 +++++- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/types/mod.rs | 2 +- clippy_utils/src/ast_utils.rs | 8 ++++++-- clippy_utils/src/consts.rs | 2 +- clippy_utils/src/lib.rs | 2 +- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index 4dc750c03b48..9b26c3573e18 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -50,7 +50,11 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if_chain! { if !item.span.from_expansion(); - if let ItemKind::Const(hir_ty, _) = &item.kind; + if let ItemKind::Const(hir_ty, generics, _) = &item.kind; + // Since static items may not have generics, skip generic const items. + // FIXME(generic_const_items): I don't think checking `generics.hwcp` suffices as it + // doesn't account for empty where-clauses that only consist of keyword `where` IINM. + if generics.params.is_empty() && !generics.has_where_clause_predicates; let ty = hir_ty_to_ty(cx.tcx, hir_ty); if let ty::Array(element_type, cst) = ty.kind(); if let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind(); diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 87699fd0ca6e..8bb2fa925856 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -302,7 +302,7 @@ declare_lint_pass!(NonCopyConst => [DECLARE_INTERIOR_MUTABLE_CONST, BORROW_INTER impl<'tcx> LateLintPass<'tcx> for NonCopyConst { fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx Item<'_>) { - if let ItemKind::Const(hir_ty, body_id) = it.kind { + if let ItemKind::Const(hir_ty, _generics, body_id) = it.kind { let ty = hir_ty_to_ty(cx.tcx, hir_ty); if !ignored_macro(cx, it) && is_unfrozen(cx, ty) && is_value_unfrozen_poly(cx, body_id, ty) { lint(cx, Source::Item { item: it.span }); diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 3c873a5901d4..79f9d45d597e 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -349,7 +349,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { let is_exported = cx.effective_visibilities.is_exported(item.owner_id.def_id); match item.kind { - ItemKind::Static(ty, _, _) | ItemKind::Const(ty, _) => self.check_ty( + ItemKind::Static(ty, _, _) | ItemKind::Const(ty, _, _) => self.check_ty( cx, ty, CheckTyContext { diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 8cc01f1ef974..7e42924603a4 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -301,15 +301,17 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { ( Const(box ast::ConstItem { defaultness: ld, + generics: lg, ty: lt, expr: le, }), Const(box ast::ConstItem { defaultness: rd, + generics: rg, ty: rt, expr: re, }), - ) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), + ) => eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && eq_ty(lt, rt) && eq_expr_opt(le, re), ( Fn(box ast::Fn { defaultness: ld, @@ -476,15 +478,17 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { ( Const(box ast::ConstItem { defaultness: ld, + generics: lg, ty: lt, expr: le, }), Const(box ast::ConstItem { defaultness: rd, + generics: rg, ty: rt, expr: re, }), - ) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), + ) => eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && eq_ty(lt, rt) && eq_expr_opt(le, re), ( Fn(box ast::Fn { defaultness: ld, diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 061086c4fc20..f19e09a18ec5 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -461,7 +461,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { // Check if this constant is based on `cfg!(..)`, // which is NOT constant for our purposes. if let Some(node) = self.lcx.tcx.hir().get_if_local(def_id) - && let Node::Item(Item { kind: ItemKind::Const(_, body_id), .. }) = node + && let Node::Item(Item { kind: ItemKind::Const(.., body_id), .. }) = node && let Node::Expr(Expr { kind: ExprKind::Lit(_), span, .. }) = self.lcx .tcx .hir() diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 035511e89125..45b99df46b01 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -2380,7 +2380,7 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalDefId, f: impl Fn(&[Symbol for id in tcx.hir().module_items(module) { if matches!(tcx.def_kind(id.owner_id), DefKind::Const) && let item = tcx.hir().item(id) - && let ItemKind::Const(ty, _body) = item.kind { + && let ItemKind::Const(ty, _generics, _body) = item.kind { if let TyKind::Path(QPath::Resolved(_, path)) = ty.kind { // We could also check for the type name `test::TestDescAndFn` if let Res::Def(DefKind::Struct, _) = path.res { From 46a8f0f0c008e7bc6b89d72e935294ee3d154608 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 15 Jun 2023 13:15:52 +0000 Subject: [PATCH 0895/1222] Mark `map_or` as `#[must_use]` --- clippy_lints/src/operators/bit_mask.rs | 6 +++--- tests/ui/result_map_or_into_option.fixed | 2 +- tests/ui/result_map_or_into_option.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/operators/bit_mask.rs b/clippy_lints/src/operators/bit_mask.rs index 1fddf0f50e32..c146f3ae95b3 100644 --- a/clippy_lints/src/operators/bit_mask.rs +++ b/clippy_lints/src/operators/bit_mask.rs @@ -40,9 +40,9 @@ fn check_compare(cx: &LateContext<'_>, bit_op: &Expr<'_>, cmp_op: BinOpKind, cmp if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr { return; } - fetch_int_literal(cx, right) - .or_else(|| fetch_int_literal(cx, left)) - .map_or((), |mask| check_bit_mask(cx, op.node, cmp_op, mask, cmp_value, span)); + if let Some(mask) = fetch_int_literal(cx, right).or_else(|| fetch_int_literal(cx, left)) { + check_bit_mask(cx, op.node, cmp_op, mask, cmp_value, span); + } } } diff --git a/tests/ui/result_map_or_into_option.fixed b/tests/ui/result_map_or_into_option.fixed index 119ff25918a7..6850eeb7a4cd 100644 --- a/tests/ui/result_map_or_into_option.fixed +++ b/tests/ui/result_map_or_into_option.fixed @@ -15,5 +15,5 @@ fn main() { // A non-Some `f` closure where the argument is not used as the // return should not emit the lint let opt: Result = Ok(1); - opt.map_or(None, |_x| Some(1)); + _ = opt.map_or(None, |_x| Some(1)); } diff --git a/tests/ui/result_map_or_into_option.rs b/tests/ui/result_map_or_into_option.rs index eeeef830af0a..8e1518144078 100644 --- a/tests/ui/result_map_or_into_option.rs +++ b/tests/ui/result_map_or_into_option.rs @@ -15,5 +15,5 @@ fn main() { // A non-Some `f` closure where the argument is not used as the // return should not emit the lint let opt: Result = Ok(1); - opt.map_or(None, |_x| Some(1)); + _ = opt.map_or(None, |_x| Some(1)); } From d8e2f3261bb155ff717c153aabbae724cb0ec3e6 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 25 Jul 2023 13:25:38 +0000 Subject: [PATCH 0896/1222] Use builder pattern instead of lots of arguments for `EmitterWriter::new` --- clippy_lints/src/doc.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 00f70e586f42..573838ce63ef 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -16,7 +16,7 @@ use rustc_ast::token::CommentKind; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; use rustc_errors::emitter::EmitterWriter; -use rustc_errors::{Applicability, Handler, SuggestionStyle, TerminalUrl}; +use rustc_errors::{Applicability, Handler, SuggestionStyle}; use rustc_hir as hir; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{AnonConst, Expr}; @@ -718,16 +718,8 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false); let emitter = EmitterWriter::new( Box::new(io::sink()), - None, - None, fallback_bundle, false, - false, - false, - None, - false, - false, - TerminalUrl::No, ); let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings(); let sess = ParseSess::with_span_handler(handler, sm); From e9294663b75dc72a7e400df4cd2c804069d268d3 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 26 Jul 2023 13:58:50 +0000 Subject: [PATCH 0897/1222] Remove a `bool` for color in favor of the `WriteColor` trait wrapping colored and uncolored printing --- clippy_lints/src/doc.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 573838ce63ef..2c4d93e33ba7 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -719,7 +719,6 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { let emitter = EmitterWriter::new( Box::new(io::sink()), fallback_bundle, - false, ); let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings(); let sess = ParseSess::with_span_handler(handler, sm); From 4071a4f5165ff11f833b61d27cfcb9eaf68181dc Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 13 Jul 2023 12:23:06 +0200 Subject: [PATCH 0898/1222] Rename incorrect_fn_null_checks to useless_ptr_null_checks (clippy side) --- clippy_lints/src/renamed_lints.rs | 2 +- tests/ui/rename.fixed | 4 ++-- tests/ui/rename.rs | 2 +- tests/ui/rename.stderr | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index 49bdc6796049..fc1fabcc0ae5 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -43,7 +43,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"), ("clippy::forget_copy", "forgetting_copy_types"), ("clippy::forget_ref", "forgetting_references"), - ("clippy::fn_null_check", "incorrect_fn_null_checks"), + ("clippy::fn_null_check", "useless_ptr_null_checks"), ("clippy::into_iter_on_array", "array_into_iter"), ("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"), ("clippy::invalid_ref", "invalid_value"), diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index 8ec19b120d12..8257bf2947ab 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -38,7 +38,7 @@ #![allow(for_loops_over_fallibles)] #![allow(forgetting_copy_types)] #![allow(forgetting_references)] -#![allow(incorrect_fn_null_checks)] +#![allow(useless_ptr_null_checks)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] @@ -92,7 +92,7 @@ #![warn(for_loops_over_fallibles)] #![warn(forgetting_copy_types)] #![warn(forgetting_references)] -#![warn(incorrect_fn_null_checks)] +#![warn(useless_ptr_null_checks)] #![warn(array_into_iter)] #![warn(invalid_atomic_ordering)] #![warn(invalid_value)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index 51a5976eb614..6569dad18d40 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -38,7 +38,7 @@ #![allow(for_loops_over_fallibles)] #![allow(forgetting_copy_types)] #![allow(forgetting_references)] -#![allow(incorrect_fn_null_checks)] +#![allow(useless_ptr_null_checks)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index e420ea1d2adb..57e991e5695a 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -246,11 +246,11 @@ error: lint `clippy::forget_ref` has been renamed to `forgetting_references` LL | #![warn(clippy::forget_ref)] | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references` -error: lint `clippy::fn_null_check` has been renamed to `incorrect_fn_null_checks` +error: lint `clippy::fn_null_check` has been renamed to `useless_ptr_null_checks` --> $DIR/rename.rs:95:9 | LL | #![warn(clippy::fn_null_check)] - | ^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `incorrect_fn_null_checks` + | ^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `useless_ptr_null_checks` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` --> $DIR/rename.rs:96:9 From 965d9ddcadd41af11dcc1221690d6722543d394d Mon Sep 17 00:00:00 2001 From: yukang Date: Wed, 2 Aug 2023 16:17:31 +0800 Subject: [PATCH 0899/1222] fix RedundantLocals clippy caused by async and await --- clippy_lints/src/redundant_locals.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/redundant_locals.rs b/clippy_lints/src/redundant_locals.rs index 140ae837a172..896bd79b20bf 100644 --- a/clippy_lints/src/redundant_locals.rs +++ b/clippy_lints/src/redundant_locals.rs @@ -2,9 +2,11 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::is_from_proc_macro; use clippy_utils::ty::needs_ordered_drop; use rustc_hir::def::Res; -use rustc_hir::{BindingAnnotation, ByRef, Expr, ExprKind, HirId, Local, Node, Pat, PatKind, QPath}; +use rustc_hir::{ + BindingAnnotation, ByRef, Expr, ExprKind, HirId, Local, Node, Pat, PatKind, QPath, +}; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; +use rustc_middle::lint::{in_external_macro, is_from_async_await}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::Ident; @@ -65,6 +67,9 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals { // the local is user-controlled if !in_external_macro(cx.sess(), local.span); if !is_from_proc_macro(cx, expr); + // Async function parameters are lowered into the closure body, so we can't lint them. + // see `lower_maybe_async_body` in `rust_ast_lowering` + if !is_from_async_await(local.span); then { span_lint_and_help( cx, @@ -93,7 +98,12 @@ fn find_binding(pat: &Pat<'_>, name: Ident) -> Option { } /// Check if a rebinding of a local affects the code's drop behavior. -fn affects_drop_behavior<'tcx>(cx: &LateContext<'tcx>, bind: HirId, rebind: HirId, rebind_expr: &Expr<'tcx>) -> bool { +fn affects_drop_behavior<'tcx>( + cx: &LateContext<'tcx>, + bind: HirId, + rebind: HirId, + rebind_expr: &Expr<'tcx>, +) -> bool { let hir = cx.tcx.hir(); // the rebinding is in a different scope than the original binding From d4ec898b85fddfa4adf04a44cba27a751724d9e3 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sat, 29 Jul 2023 08:20:25 +0000 Subject: [PATCH 0900/1222] Remove constness from `TraitPredicate` --- clippy_lints/src/derive.rs | 4 +--- clippy_lints/src/eta_reduction.rs | 3 +-- clippy_utils/src/qualify_min_const_fn.rs | 5 +++-- clippy_utils/src/ty.rs | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index e3f2026cfe9e..9900dbdee6be 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -15,7 +15,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::traits::Reveal; use rustc_middle::ty::{ - self, BoundConstness, ClauseKind, GenericArgKind, GenericParamDefKind, ImplPolarity, ParamEnv, + self, ClauseKind, GenericArgKind, GenericParamDefKind, ImplPolarity, ParamEnv, ToPredicate, TraitPredicate, Ty, TyCtxt, }; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -523,7 +523,6 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> if let ClauseKind::Trait(p) = p.kind().skip_binder() && p.trait_ref.def_id == eq_trait_id && let ty::Param(self_ty) = p.trait_ref.self_ty().kind() - && p.constness == BoundConstness::NotConst { // Flag types which already have an `Eq` bound. params[self_ty.index as usize].1 = false; @@ -535,7 +534,6 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| { ClauseKind::Trait(TraitPredicate { trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]), - constness: BoundConstness::NotConst, polarity: ImplPolarity::Positive, }) .to_predicate(tcx) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 8d6fb8438b65..ba7957b0decc 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -10,7 +10,7 @@ use rustc_hir::{BindingAnnotation, Expr, ExprKind, FnRetTy, Param, PatKind, QPat use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{ - self, Binder, BoundConstness, ClosureArgs, ClosureKind, EarlyBinder, FnSig, GenericArg, GenericArgKind, + self, Binder, ClosureArgs, ClosureKind, EarlyBinder, FnSig, GenericArg, GenericArgKind, GenericArgsRef, ImplPolarity, List, Region, RegionKind, Ty, TypeVisitableExt, TypeckResults, }; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -171,7 +171,6 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { = cx.tcx.infer_ctxt().build().type_implements_fn_trait( cx.param_env, Binder::bind_with_vars(callee_ty_adjusted, List::empty()), - BoundConstness::NotConst, ImplPolarity::Positive, ) && path_to_local(callee) .map_or( diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index a98e2038d5f0..f0a777c5b895 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -16,7 +16,7 @@ use rustc_middle::mir::{ }; use rustc_middle::traits::{ImplSource, ObligationCause, BuiltinImplSource}; use rustc_middle::ty::adjustment::PointerCoercion; -use rustc_middle::ty::{self, BoundConstness, GenericArgKind, TraitRef, Ty, TyCtxt}; +use rustc_middle::ty::{self, GenericArgKind, TraitRef, Ty, TyCtxt}; use rustc_semver::RustcVersion; use rustc_span::symbol::sym; use rustc_span::Span; @@ -399,11 +399,12 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx> return true; } + // FIXME(effects) constness let obligation = Obligation::new( tcx, ObligationCause::dummy_with_span(body.span), ConstCx::new(tcx, body).param_env, - TraitRef::from_lang_item(tcx, LangItem::Destruct, body.span, [ty]).with_constness(BoundConstness::ConstIfConst), + TraitRef::from_lang_item(tcx, LangItem::Destruct, body.span, [ty]), ); let infcx = tcx.infer_ctxt().build(); diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index d0e15aa8bb32..717664805356 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -267,7 +267,7 @@ pub fn implements_trait_with_env_from_iter<'tcx>( cause: ObligationCause::dummy(), param_env, recursion_depth: 0, - predicate: ty::Binder::dummy(trait_ref).without_const().to_predicate(tcx), + predicate: ty::Binder::dummy(trait_ref).to_predicate(tcx), }; infcx .evaluate_obligation(&obligation) From 388a2a5490b9cd91c7655e08280c81aa1d51de84 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 9 Mar 2023 20:54:53 +0000 Subject: [PATCH 0901/1222] Add `internal_features` lint It lints against features that are inteded to be internal to the compiler and standard library. Implements MCP #596. We allow `internal_features` in the standard library and compiler as those use many features and this _is_ the standard library from the "internal to the compiler and standard library" after all. Marking some features as internal wasn't exactly the most scientific approach, I just marked some mostly obvious features. While there is a categorization in the macro, it's not very well upheld (should probably be fixed in another PR). We always pass `-Ainternal_features` in the testsuite About 400 UI tests and several other tests use internal features. Instead of throwing the attribute on each one, just always allow them. There's nothing wrong with testing internal features^^ --- tests/compile-test.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 385e25ce6b8f..e46f8bf6fabd 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -140,6 +140,7 @@ fn base_config(test_dir: &str) -> compiletest::Config { [ "--emit=metadata", "-Aunused", + "-Ainternal_features", "-Zui-testing", "-Dwarnings", &format!("-Ldependency={}", deps_path.display()), From b6292076d013ddf870d843f285bca749c13e7b4f Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 3 Aug 2023 21:43:17 +0200 Subject: [PATCH 0902/1222] Improve spans for indexing expressions Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location. This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR. --- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/functions/must_use.rs | 2 +- clippy_lints/src/index_refutable_slice.rs | 2 +- clippy_lints/src/indexing_slicing.rs | 2 +- clippy_lints/src/loops/manual_memcpy.rs | 4 ++-- clippy_lints/src/loops/needless_range_loop.rs | 2 +- clippy_lints/src/loops/never_loop.rs | 2 +- clippy_lints/src/loops/while_let_on_iterator.rs | 2 +- clippy_lints/src/manual_strip.rs | 2 +- clippy_lints/src/matches/match_on_vec_items.rs | 4 ++-- clippy_lints/src/methods/filter_next.rs | 2 +- clippy_lints/src/methods/iter_next_slice.rs | 2 +- clippy_lints/src/mixed_read_write_in_expression.rs | 2 +- clippy_lints/src/needless_bool.rs | 2 +- clippy_lints/src/no_effect.rs | 4 ++-- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/ptr.rs | 2 +- clippy_lints/src/redundant_slicing.rs | 2 +- clippy_lints/src/strings.rs | 4 ++-- clippy_lints/src/suspicious_operation_groupings.rs | 2 +- clippy_lints/src/swap.rs | 4 ++-- clippy_lints/src/temporary_assignment.rs | 2 +- clippy_lints/src/tuple_array_conversions.rs | 4 ++-- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/vec_init_then_push.rs | 2 +- clippy_utils/src/ast_utils.rs | 2 +- clippy_utils/src/check_proc_macro.rs | 2 +- clippy_utils/src/consts.rs | 2 +- clippy_utils/src/eager_or_lazy.rs | 2 +- clippy_utils/src/hir_utils.rs | 4 ++-- clippy_utils/src/lib.rs | 4 ++-- clippy_utils/src/ty/type_certainty/mod.rs | 2 +- clippy_utils/src/visitors.rs | 4 ++-- 33 files changed, 42 insertions(+), 42 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index a5ec979ccd97..137bd9c94510 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -800,7 +800,7 @@ fn in_postfix_position<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> boo && parent.span.ctxt() == e.span.ctxt() { match parent.kind { - ExprKind::Call(child, _) | ExprKind::MethodCall(_, child, _, _) | ExprKind::Index(child, _) + ExprKind::Call(child, _) | ExprKind::MethodCall(_, child, _, _) | ExprKind::Index(child, _, _) if child.hir_id == e.hir_id => true, ExprKind::Field(_, _) | ExprKind::Match(_, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar) => true, _ => false, diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 83445c7a0ca5..57df5683c9d3 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -221,7 +221,7 @@ fn is_mutated_static(e: &hir::Expr<'_>) -> bool { match e.kind { Path(QPath::Resolved(_, path)) => !matches!(path.res, Res::Local(_)), Path(_) => true, - Field(inner, _) | Index(inner, _) => is_mutated_static(inner), + Field(inner, _) | Index(inner, _, _) => is_mutated_static(inner), _ => false, } } diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index 01a7c497cbe7..f507f45d5bb9 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -254,7 +254,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> { // Checking for slice indexing let parent_id = map.parent_id(expr.hir_id); if let Some(hir::Node::Expr(parent_expr)) = map.find(parent_id); - if let hir::ExprKind::Index(_, index_expr) = parent_expr.kind; + if let hir::ExprKind::Index(_, index_expr, _) = parent_expr.kind; if let Some(Constant::Int(index_value)) = constant(cx, cx.typeck_results(), index_expr); if let Ok(index_value) = index_value.try_into(); if index_value < max_suggested_slice; diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index 22c14d9b04dd..4f4f571773fb 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -103,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { return; } - if let ExprKind::Index(array, index) = &expr.kind { + if let ExprKind::Index(array, index, _) = &expr.kind { let note = "the suggestion might not be applicable in constant blocks"; let ty = cx.typeck_results().expr_ty(array).peel_refs(); if let Some(range) = higher::Range::hir(index) { diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index 7d1f8ef29c81..d3fd0e8639e9 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -60,8 +60,8 @@ pub(super) fn check<'tcx>( o.and_then(|(lhs, rhs)| { let rhs = fetch_cloned_expr(rhs); if_chain! { - if let ExprKind::Index(base_left, idx_left) = lhs.kind; - if let ExprKind::Index(base_right, idx_right) = rhs.kind; + if let ExprKind::Index(base_left, idx_left, _) = lhs.kind; + if let ExprKind::Index(base_right, idx_right, _) = rhs.kind; if let Some(ty) = get_slice_like_element_ty(cx, cx.typeck_results().expr_ty(base_left)); if get_slice_like_element_ty(cx, cx.typeck_results().expr_ty(base_right)).is_some(); if let Some((start_left, offset_left)) = get_details_from_idx(cx, idx_left, &starts); diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 2c20e9e86933..c4af46b8fd3a 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -319,7 +319,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { if_chain! { // an index op - if let ExprKind::Index(seqexpr, idx) = expr.kind; + if let ExprKind::Index(seqexpr, idx, _) = expr.kind; if !self.check(idx, seqexpr, expr); then { return; diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index 7da9121fbb38..dd77c69ef88a 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -162,7 +162,7 @@ fn never_loop_expr<'tcx>( ExprKind::Binary(_, e1, e2) | ExprKind::Assign(e1, e2, _) | ExprKind::AssignOp(_, e1, e2) - | ExprKind::Index(e1, e2) => never_loop_expr_all(cx, &mut [e1, e2].iter().copied(), ignore_ids, main_loop_id), + | ExprKind::Index(e1, e2, _) => never_loop_expr_all(cx, &mut [e1, e2].iter().copied(), ignore_ids, main_loop_id), ExprKind::Loop(b, _, _, _) => { // Break can come from the inner loop so remove them. absorb_break(never_loop_block(cx, b, ignore_ids, main_loop_id)) diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index 8019f906aca4..5153070cfe66 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -113,7 +113,7 @@ fn try_parse_iter_expr(cx: &LateContext<'_>, mut e: &Expr<'_>) -> Option { + ExprKind::Index(base, idx, _) if !idx.can_have_side_effects() => { can_move = false; fields.clear(); e = base; diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index 2b9def1a6884..201bb56efcdd 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -204,7 +204,7 @@ fn find_stripping<'tcx>( if_chain! { if is_ref_str(self.cx, ex); let unref = peel_ref(ex); - if let ExprKind::Index(indexed, index) = &unref.kind; + if let ExprKind::Index(indexed, index, _) = &unref.kind; if let Some(higher::Range { start, end, .. }) = higher::Range::hir(index); if let ExprKind::Path(path) = &indexed.kind; if self.cx.qpath_res(path, ex.hir_id) == self.target; diff --git a/clippy_lints/src/matches/match_on_vec_items.rs b/clippy_lints/src/matches/match_on_vec_items.rs index 89dcac4d8494..bd53ebd48c88 100644 --- a/clippy_lints/src/matches/match_on_vec_items.rs +++ b/clippy_lints/src/matches/match_on_vec_items.rs @@ -12,7 +12,7 @@ use super::MATCH_ON_VEC_ITEMS; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, scrutinee: &'tcx Expr<'_>) { if_chain! { if let Some(idx_expr) = is_vec_indexing(cx, scrutinee); - if let ExprKind::Index(vec, idx) = idx_expr.kind; + if let ExprKind::Index(vec, idx, _) = idx_expr.kind; then { // FIXME: could be improved to suggest surrounding every pattern with Some(_), @@ -36,7 +36,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, scrutinee: &'tcx Expr<'_>) { fn is_vec_indexing<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { if_chain! { - if let ExprKind::Index(array, index) = expr.kind; + if let ExprKind::Index(array, index, _) = expr.kind; if is_vector(cx, array); if !is_full_range(cx, index); diff --git a/clippy_lints/src/methods/filter_next.rs b/clippy_lints/src/methods/filter_next.rs index ce7f9997b5a6..ac7bc9bcca47 100644 --- a/clippy_lints/src/methods/filter_next.rs +++ b/clippy_lints/src/methods/filter_next.rs @@ -12,7 +12,7 @@ use super::FILTER_NEXT; fn path_to_local(expr: &hir::Expr<'_>) -> Option { match expr.kind { hir::ExprKind::Field(f, _) => path_to_local(f), - hir::ExprKind::Index(recv, _) => path_to_local(recv), + hir::ExprKind::Index(recv, _, _) => path_to_local(recv), hir::ExprKind::Path(hir::QPath::Resolved( _, hir::Path { diff --git a/clippy_lints/src/methods/iter_next_slice.rs b/clippy_lints/src/methods/iter_next_slice.rs index e2029da8081f..8f885e9f729b 100644 --- a/clippy_lints/src/methods/iter_next_slice.rs +++ b/clippy_lints/src/methods/iter_next_slice.rs @@ -27,7 +27,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, cal if derefs_to_slice(cx, caller_expr, cx.typeck_results().expr_ty(caller_expr)).is_some() { // caller is a Slice if_chain! { - if let hir::ExprKind::Index(caller_var, index_expr) = &caller_expr.kind; + if let hir::ExprKind::Index(caller_var, index_expr, _) = &caller_expr.kind; if let Some(higher::Range { start: Some(start_expr), end: None, limits: ast::RangeLimits::HalfOpen }) = higher::Range::hir(index_expr); if let hir::ExprKind::Lit(start_lit) = &start_expr.kind; diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs index 57ec3a1f1e63..367cd6bd4133 100644 --- a/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/clippy_lints/src/mixed_read_write_in_expression.rs @@ -239,7 +239,7 @@ fn check_expr<'tcx>(vis: &mut ReadVisitor<'_, 'tcx>, expr: &'tcx Expr<'_>) -> St | ExprKind::MethodCall(..) | ExprKind::Call(_, _) | ExprKind::Assign(..) - | ExprKind::Index(_, _) + | ExprKind::Index(..) | ExprKind::Repeat(_, _) | ExprKind::Struct(_, _, _) => { walk_expr(vis, expr); diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index 46457400abcb..f6b87b071b94 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -119,7 +119,7 @@ fn condition_needs_parentheses(e: &Expr<'_>) -> bool { | ExprKind::Call(i, _) | ExprKind::Cast(i, _) | ExprKind::Type(i, _) - | ExprKind::Index(i, _) = inner.kind + | ExprKind::Index(i, _, _) = inner.kind { if matches!( i.kind, diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index e6d3e72d1e62..5f2a324b05fb 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -160,7 +160,7 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { match peel_blocks(expr).kind { ExprKind::Lit(..) | ExprKind::Closure { .. } => true, ExprKind::Path(..) => !has_drop(cx, cx.typeck_results().expr_ty(expr)), - ExprKind::Index(a, b) | ExprKind::Binary(_, a, b) => has_no_effect(cx, a) && has_no_effect(cx, b), + ExprKind::Index(a, b, _) | ExprKind::Binary(_, a, b) => has_no_effect(cx, a) && has_no_effect(cx, b), ExprKind::Array(v) | ExprKind::Tup(v) => v.iter().all(|val| has_no_effect(cx, val)), ExprKind::Repeat(inner, _) | ExprKind::Cast(inner, _) @@ -263,7 +263,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option Some(vec![a, b]), + ExprKind::Index(a, b, _) => Some(vec![a, b]), ExprKind::Binary(ref binop, a, b) if binop.node != BinOpKind::And && binop.node != BinOpKind::Or => { Some(vec![a, b]) }, diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index a70692d8ff86..243192385c25 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -438,7 +438,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { dereferenced_expr = parent_expr; }, - ExprKind::Index(e, _) if ptr::eq(&**e, cur_expr) => { + ExprKind::Index(e, _, _) if ptr::eq(&**e, cur_expr) => { // `e[i]` => desugared to `*Index::index(&e, i)`, // meaning `e` must be referenced. // no need to go further up since a method call is involved now. diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 42299d8d42f5..8009b00b4b9c 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -695,7 +695,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: } }, // Indexing is fine for currently supported types. - ExprKind::Index(e, _) if e.hir_id == child_id => (), + ExprKind::Index(e, _, _) if e.hir_id == child_id => (), _ => set_skip_flag(), }, _ => set_skip_flag(), diff --git a/clippy_lints/src/redundant_slicing.rs b/clippy_lints/src/redundant_slicing.rs index 8277ce724d42..4abfa0fc35c6 100644 --- a/clippy_lints/src/redundant_slicing.rs +++ b/clippy_lints/src/redundant_slicing.rs @@ -81,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing { if_chain! { if let ExprKind::AddrOf(BorrowKind::Ref, mutability, addressee) = expr.kind; if addressee.span.ctxt() == ctxt; - if let ExprKind::Index(indexed, range) = addressee.kind; + if let ExprKind::Index(indexed, range, _) = addressee.kind; if is_type_lang_item(cx, cx.typeck_results().expr_ty_adjusted(range), LangItem::RangeFull); then { let (expr_ty, expr_ref_count) = peel_mid_ty_refs(cx.typeck_results().expr_ty(expr)); diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 4d45091f4b5b..76f463fff7dc 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -190,7 +190,7 @@ impl<'tcx> LateLintPass<'tcx> for StringAdd { ); } }, - ExprKind::Index(target, _idx) => { + ExprKind::Index(target, _idx, _) => { let e_ty = cx.typeck_results().expr_ty(target).peel_refs(); if e_ty.is_str() || is_type_lang_item(cx, e_ty, LangItem::String) { span_lint( @@ -262,7 +262,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { // Find string::as_bytes if let ExprKind::AddrOf(BorrowKind::Ref, _, args) = args[0].kind; - if let ExprKind::Index(left, right) = args.kind; + if let ExprKind::Index(left, right, _) = args.kind; let (method_names, expressions, _) = method_calls(left, 1); if method_names.len() == 1; if expressions.len() == 1; diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index e2cdc48b583c..23d6e2a845fd 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -572,7 +572,7 @@ fn ident_difference_expr_with_base_location( | (AddrOf(_, _, _), AddrOf(_, _, _)) | (Path(_, _), Path(_, _)) | (Range(_, _, _), Range(_, _, _)) - | (Index(_, _), Index(_, _)) + | (Index(_, _, _), Index(_, _, _)) | (Field(_, _), Field(_, _)) | (AssignOp(_, _, _), AssignOp(_, _, _)) | (Assign(_, _, _), Assign(_, _, _)) diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index 98158ed0aee8..548fabb8b736 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -86,8 +86,8 @@ fn generate_swap_warning(cx: &LateContext<'_>, e1: &Expr<'_>, e2: &Expr<'_>, spa let mut applicability = Applicability::MachineApplicable; if !can_mut_borrow_both(cx, e1, e2) { - if let ExprKind::Index(lhs1, idx1) = e1.kind - && let ExprKind::Index(lhs2, idx2) = e2.kind + if let ExprKind::Index(lhs1, idx1, _) = e1.kind + && let ExprKind::Index(lhs2, idx2, _) = e2.kind && eq_expr_value(cx, lhs1, lhs2) && e1.span.ctxt() == ctxt && e2.span.ctxt() == ctxt diff --git a/clippy_lints/src/temporary_assignment.rs b/clippy_lints/src/temporary_assignment.rs index 3766b8f8ed10..b6b653f6610d 100644 --- a/clippy_lints/src/temporary_assignment.rs +++ b/clippy_lints/src/temporary_assignment.rs @@ -33,7 +33,7 @@ impl<'tcx> LateLintPass<'tcx> for TemporaryAssignment { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Assign(target, ..) = &expr.kind { let mut base = target; - while let ExprKind::Field(f, _) | ExprKind::Index(f, _) = &base.kind { + while let ExprKind::Field(f, _) | ExprKind::Index(f, _, _) = &base.kind { base = f; } if is_temporary(base) && !is_adjusted(cx, base) { diff --git a/clippy_lints/src/tuple_array_conversions.rs b/clippy_lints/src/tuple_array_conversions.rs index 7eec69820924..78ad52d8a879 100644 --- a/clippy_lints/src/tuple_array_conversions.rs +++ b/clippy_lints/src/tuple_array_conversions.rs @@ -103,11 +103,11 @@ fn check_tuple<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, elements: & // Fix #11100 && tys.iter().all_equal() && let Some(locals) = (match first.kind { - ExprKind::Index(_, _) => elements + ExprKind::Index(..) => elements .iter() .enumerate() .map(|(i, i_expr)| -> Option<&'tcx Expr<'tcx>> { - if let ExprKind::Index(lhs, index) = i_expr.kind + if let ExprKind::Index(lhs, index, _) = i_expr.kind && let ExprKind::Lit(lit) = index.kind && let LitKind::Int(val, _) = lit.node { diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 6b51974d739a..f02c33cc6743 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -526,7 +526,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { self.ident(field_name); self.expr(object); }, - ExprKind::Index(object, index) => { + ExprKind::Index(object, index, _) => { bind!(self, object, index); kind!("Index({object}, {index})"); self.expr(object); diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs index 1d4fc24eb6c2..3fa51216c773 100644 --- a/clippy_lints/src/vec_init_then_push.rs +++ b/clippy_lints/src/vec_init_then_push.rs @@ -88,7 +88,7 @@ impl VecPushSearcher { let mut last_place = parent; while let Some(parent) = get_parent_expr(cx, last_place) { if matches!(parent.kind, ExprKind::Unary(UnOp::Deref, _) | ExprKind::Field(..)) - || matches!(parent.kind, ExprKind::Index(e, _) if e.hir_id == last_place.hir_id) + || matches!(parent.kind, ExprKind::Index(e, _, _) if e.hir_id == last_place.hir_id) { last_place = parent; } else { diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 7e42924603a4..2d0d6f559ad6 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -178,7 +178,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (Yield(l), Yield(r)) | (Ret(l), Ret(r)) => eq_expr_opt(l, r), (Break(ll, le), Break(rl, re)) => eq_label(ll, rl) && eq_expr_opt(le, re), (Continue(ll), Continue(rl)) => eq_label(ll, rl), - (Assign(l1, l2, _), Assign(r1, r2, _)) | (Index(l1, l2), Index(r1, r2)) => eq_expr(l1, r1) && eq_expr(l2, r2), + (Assign(l1, l2, _), Assign(r1, r2, _)) | (Index(l1, l2, _), Index(r1, r2, _)) => eq_expr(l1, r1) && eq_expr(l2, r2), (AssignOp(lo, lp, lv), AssignOp(ro, rp, rv)) => lo.node == ro.node && eq_expr(lp, rp) && eq_expr(lv, rv), (Field(lp, lf), Field(rp, rf)) => eq_id(*lf, *rf) && eq_expr(lp, rp), (Match(ls, la), Match(rs, ra)) => eq_expr(ls, rs) && over(la, ra, eq_arm), diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index 89f8a65c5ae0..60fab1ec41ae 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -163,7 +163,7 @@ fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) { ) => (Pat::Str("unsafe"), Pat::Str("}")), ExprKind::Block(_, None) => (Pat::Str("{"), Pat::Str("}")), ExprKind::Field(e, name) => (expr_search_pat(tcx, e).0, Pat::Sym(name.name)), - ExprKind::Index(e, _) => (expr_search_pat(tcx, e).0, Pat::Str("]")), + ExprKind::Index(e, _, _) => (expr_search_pat(tcx, e).0, Pat::Str("]")), ExprKind::Path(ref path) => qpath_search_pat(path), ExprKind::AddrOf(_, _, e) => (Pat::Str("&"), expr_search_pat(tcx, e).1), ExprKind::Break(Destination { label: None, .. }, None) => (Pat::Str("break"), Pat::Str("break")), diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index f19e09a18ec5..d38e3f1ae76b 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -394,7 +394,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { } } }, - ExprKind::Index(arr, index) => self.index(arr, index), + ExprKind::Index(arr, index, _) => self.index(arr, index), ExprKind::AddrOf(_, _, inner) => self.expr(inner).map(|r| Constant::Ref(Box::new(r))), ExprKind::Field(local_expr, ref field) => { let result = self.expr(local_expr); diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index 3c969572b8e4..0bcefba75a7b 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -185,7 +185,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS .type_dependent_def_id(e.hir_id) .map_or(Lazy, |id| fn_eagerness(self.cx, id, name.ident.name, true)); }, - ExprKind::Index(_, e) => { + ExprKind::Index(_, e, _) => { let ty = self.cx.typeck_results().expr_ty_adjusted(e); if is_copy(self.cx, ty) && !ty.is_ref() { self.eagerness |= NoChange; diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 85b3b005f93d..fdc35cd4ddf8 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -299,7 +299,7 @@ impl HirEqInterExpr<'_, '_, '_> { (&ExprKind::Field(l_f_exp, ref l_f_ident), &ExprKind::Field(r_f_exp, ref r_f_ident)) => { l_f_ident.name == r_f_ident.name && self.eq_expr(l_f_exp, r_f_exp) }, - (&ExprKind::Index(la, li), &ExprKind::Index(ra, ri)) => self.eq_expr(la, ra) && self.eq_expr(li, ri), + (&ExprKind::Index(la, li, _), &ExprKind::Index(ra, ri, _)) => self.eq_expr(la, ra) && self.eq_expr(li, ri), (&ExprKind::If(lc, lt, ref le), &ExprKind::If(rc, rt, ref re)) => { self.eq_expr(lc, rc) && self.eq_expr(lt, rt) && both(le, re, |l, r| self.eq_expr(l, r)) }, @@ -730,7 +730,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_expr(e); self.hash_name(f.name); }, - ExprKind::Index(a, i) => { + ExprKind::Index(a, i, _) => { self.hash_expr(a); self.hash_expr(i); }, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index cf30930b76ea..4cd8a8c3325c 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -735,7 +735,7 @@ fn projection_stack<'a, 'hir>(mut e: &'a Expr<'hir>) -> (Vec<&'a Expr<'hir>>, &' let mut result = vec![]; let root = loop { match e.kind { - ExprKind::Index(ep, _) | ExprKind::Field(ep, _) => { + ExprKind::Index(ep, _, _) | ExprKind::Field(ep, _) => { result.push(e); e = ep; }, @@ -782,7 +782,7 @@ pub fn can_mut_borrow_both(cx: &LateContext<'_>, e1: &Expr<'_>, e2: &Expr<'_>) - return true; } }, - (ExprKind::Index(_, i1), ExprKind::Index(_, i2)) => { + (ExprKind::Index(_, i1, _), ExprKind::Index(_, i2, _)) => { if !eq_expr_value(cx, i1, i2) { return false; } diff --git a/clippy_utils/src/ty/type_certainty/mod.rs b/clippy_utils/src/ty/type_certainty/mod.rs index 45b5483e323d..0669ea72eb3e 100644 --- a/clippy_utils/src/ty/type_certainty/mod.rs +++ b/clippy_utils/src/ty/type_certainty/mod.rs @@ -31,7 +31,7 @@ fn expr_type_certainty(cx: &LateContext<'_>, expr: &Expr<'_>) -> Certainty { let certainty = match &expr.kind { ExprKind::Unary(_, expr) | ExprKind::Field(expr, _) - | ExprKind::Index(expr, _) + | ExprKind::Index(expr, _, _) | ExprKind::AddrOf(_, _, expr) => expr_type_certainty(cx, expr), ExprKind::Array(exprs) => join(exprs.iter().map(|expr| expr_type_certainty(cx, expr))), diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index 09f447b27eb4..f83988a6e325 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -329,7 +329,7 @@ pub fn is_const_evaluatable<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> && self.cx.typeck_results().expr_ty(rhs).peel_refs().is_primitive_ty() => {}, ExprKind::Unary(UnOp::Deref, e) if self.cx.typeck_results().expr_ty(e).is_ref() => (), ExprKind::Unary(_, e) if self.cx.typeck_results().expr_ty(e).peel_refs().is_primitive_ty() => (), - ExprKind::Index(base, _) + ExprKind::Index(base, _, _) if matches!( self.cx.typeck_results().expr_ty(base).peel_refs().kind(), ty::Slice(_) | ty::Array(..) @@ -629,7 +629,7 @@ pub fn for_each_unconsumed_temporary<'tcx, B>( helper(typeck, true, arg, f)?; } }, - ExprKind::Index(borrowed, consumed) + ExprKind::Index(borrowed, consumed, _) | ExprKind::Assign(borrowed, consumed, _) | ExprKind::AssignOp(_, borrowed, consumed) => { helper(typeck, false, borrowed, f)?; From 55b450369eb1c444b65b38ce3b4f7f835f4a17a9 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Sat, 5 Aug 2023 12:02:39 +0300 Subject: [PATCH 0903/1222] cleanup misinformation regarding has_deref --- clippy_lints/src/dereference.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index a5ec979ccd97..aeaf9fae8914 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1170,7 +1170,7 @@ fn referent_used_exactly_once<'tcx>( && let [location] = *local_assignments(mir, local).as_slice() && let Some(statement) = mir.basic_blocks[location.block].statements.get(location.statement_index) && let StatementKind::Assign(box (_, Rvalue::Ref(_, _, place))) = statement.kind - && !place.has_deref() + && !place.is_indirect_first_projection() // Ensure not in a loop (https://github.com/rust-lang/rust-clippy/issues/9710) && TriColorDepthFirstSearch::new(&mir.basic_blocks).run_from(location.block, &mut CycleDetector).is_none() { From b2794c78aca236617c2958808faff9552180687e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sun, 6 Aug 2023 23:02:27 +0200 Subject: [PATCH 0904/1222] Store the laziness of type aliases in the DefKind --- clippy_lints/src/init_numbered_fields.rs | 2 +- clippy_utils/src/lib.rs | 2 +- clippy_utils/src/ty/type_certainty/mod.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/init_numbered_fields.rs b/clippy_lints/src/init_numbered_fields.rs index f95d2c2edb1e..b00fa104f982 100644 --- a/clippy_lints/src/init_numbered_fields.rs +++ b/clippy_lints/src/init_numbered_fields.rs @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for NumberedFields { && fields .iter() .all(|f| f.ident.as_str().as_bytes().iter().all(u8::is_ascii_digit)) - && !matches!(cx.qpath_res(path, e.hir_id), Res::Def(DefKind::TyAlias, ..)) + && !matches!(cx.qpath_res(path, e.hir_id), Res::Def(DefKind::TyAlias { .. }, ..)) { let expr_spans = fields .iter() diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index cf30930b76ea..aeef7499ee0b 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -286,7 +286,7 @@ pub fn is_wild(pat: &Pat<'_>) -> bool { /// Checks if the given `QPath` belongs to a type alias. pub fn is_ty_alias(qpath: &QPath<'_>) -> bool { match *qpath { - QPath::Resolved(_, path) => matches!(path.res, Res::Def(DefKind::TyAlias | DefKind::AssocTy, ..)), + QPath::Resolved(_, path) => matches!(path.res, Res::Def(DefKind::TyAlias { .. } | DefKind::AssocTy, ..)), QPath::TypeRelative(ty, _) if let TyKind::Path(qpath) = ty.kind => { is_ty_alias(&qpath) }, _ => false, } diff --git a/clippy_utils/src/ty/type_certainty/mod.rs b/clippy_utils/src/ty/type_certainty/mod.rs index 45b5483e323d..3e8e694a2ac4 100644 --- a/clippy_utils/src/ty/type_certainty/mod.rs +++ b/clippy_utils/src/ty/type_certainty/mod.rs @@ -219,7 +219,7 @@ fn path_segment_certainty( // See the comment preceding `qpath_certainty`. `def_id` could refer to a type or a value. let certainty = lhs.join_clearing_def_ids(rhs); if resolves_to_type { - if cx.tcx.def_kind(def_id) == DefKind::TyAlias { + if let DefKind::TyAlias { .. } = cx.tcx.def_kind(def_id) { adt_def_id(cx.tcx.type_of(def_id).instantiate_identity()) .map_or(certainty, |def_id| certainty.with_def_id(def_id)) } else { From ead63cbf68f3353ad0d8521173bead25a9dc6ae0 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 8 Aug 2023 18:28:20 +0800 Subject: [PATCH 0905/1222] rustc: Move `crate_types` from `Session` to `GlobalCtxt` Removes a piece of mutable state. Follow up to #114578. --- clippy_lints/src/missing_inline.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index a41d5a9ce8d2..93f6025c71d6 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -74,7 +74,6 @@ fn is_executable_or_proc_macro(cx: &LateContext<'_>) -> bool { use rustc_session::config::CrateType; cx.tcx - .sess .crate_types() .iter() .any(|t: &CrateType| matches!(t, CrateType::Executable | CrateType::ProcMacro)) From e7f6e2e6394100e4e4b36f689bf1f879d9782a1c Mon Sep 17 00:00:00 2001 From: Catherine Flores Date: Thu, 10 Aug 2023 22:03:20 +0000 Subject: [PATCH 0906/1222] Revert "New lint [`filter_map_bool_then`]" This reverts commits 978b1daf99d8326718684381704902fdaaf71b18 and 3235d9d612909bc64550eea3a0d387e1187e93dd. --- CHANGELOG.md | 1 - clippy_lints/src/declared_lints.rs | 1 - .../src/methods/filter_map_bool_then.rs | 45 ------------------- clippy_lints/src/methods/mod.rs | 34 -------------- clippy_utils/src/paths.rs | 2 - tests/ui/filter_map_bool_then.fixed | 44 ------------------ tests/ui/filter_map_bool_then.rs | 44 ------------------ tests/ui/filter_map_bool_then.stderr | 34 -------------- 8 files changed, 205 deletions(-) delete mode 100644 clippy_lints/src/methods/filter_map_bool_then.rs delete mode 100644 tests/ui/filter_map_bool_then.fixed delete mode 100644 tests/ui/filter_map_bool_then.rs delete mode 100644 tests/ui/filter_map_bool_then.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 2655d93599e7..6357511cc4cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4844,7 +4844,6 @@ Released 2018-09-13 [`field_reassign_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default [`filetype_is_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#filetype_is_file [`filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map -[`filter_map_bool_then`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_bool_then [`filter_map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_identity [`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next [`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index d4e0d2863348..9a9998cca4ac 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -337,7 +337,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::methods::EXPECT_USED_INFO, crate::methods::EXTEND_WITH_DRAIN_INFO, crate::methods::FILETYPE_IS_FILE_INFO, - crate::methods::FILTER_MAP_BOOL_THEN_INFO, crate::methods::FILTER_MAP_IDENTITY_INFO, crate::methods::FILTER_MAP_NEXT_INFO, crate::methods::FILTER_NEXT_INFO, diff --git a/clippy_lints/src/methods/filter_map_bool_then.rs b/clippy_lints/src/methods/filter_map_bool_then.rs deleted file mode 100644 index 4aee22a4afc3..000000000000 --- a/clippy_lints/src/methods/filter_map_bool_then.rs +++ /dev/null @@ -1,45 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::paths::BOOL_THEN; -use clippy_utils::source::snippet_opt; -use clippy_utils::ty::is_copy; -use clippy_utils::{is_from_proc_macro, is_trait_method, match_def_path, peel_blocks}; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_span::{sym, Span}; - -use super::FILTER_MAP_BOOL_THEN; - -pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: &Expr<'_>, call_span: Span) { - if !in_external_macro(cx.sess(), expr.span) - && is_trait_method(cx, expr, sym::Iterator) - && let ExprKind::Closure(closure) = arg.kind - && let body = cx.tcx.hir().body(closure.body) - && let value = peel_blocks(body.value) - // Indexing should be fine as `filter_map` always has 1 input, we unfortunately need both - // `inputs` and `params` here as we need both the type and the span - && let param_ty = closure.fn_decl.inputs[0] - && let param = body.params[0] - && is_copy(cx, cx.typeck_results().node_type(param_ty.hir_id).peel_refs()) - && let ExprKind::MethodCall(_, recv, [then_arg], _) = value.kind - && let ExprKind::Closure(then_closure) = then_arg.kind - && let then_body = peel_blocks(cx.tcx.hir().body(then_closure.body).value) - && let Some(def_id) = cx.typeck_results().type_dependent_def_id(value.hir_id) - && match_def_path(cx, def_id, &BOOL_THEN) - && !is_from_proc_macro(cx, expr) - && let Some(param_snippet) = snippet_opt(cx, param.span) - && let Some(filter) = snippet_opt(cx, recv.span) - && let Some(map) = snippet_opt(cx, then_body.span) - { - span_lint_and_sugg( - cx, - FILTER_MAP_BOOL_THEN, - call_span, - "usage of `bool::then` in `filter_map`", - "use `filter` then `map` instead", - format!("filter(|&{param_snippet}| {filter}).map(|{param_snippet}| {map})"), - Applicability::MachineApplicable, - ); - } -} diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index dd694ce7393e..28a8978973fe 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -21,7 +21,6 @@ mod expect_used; mod extend_with_drain; mod filetype_is_file; mod filter_map; -mod filter_map_bool_then; mod filter_map_identity; mod filter_map_next; mod filter_next; @@ -3477,37 +3476,6 @@ declare_clippy_lint! { "disallows `.skip(0)`" } -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of `bool::then` in `Iterator::filter_map`. - /// - /// ### Why is this bad? - /// This can be written with `filter` then `map` instead, which would reduce nesting and - /// separates the filtering from the transformation phase. This comes with no cost to - /// performance and is just cleaner. - /// - /// ### Limitations - /// Does not lint `bool::then_some`, as it eagerly evaluates its arguments rather than lazily. - /// This can create differing behavior, so better safe than sorry. - /// - /// ### Example - /// ```rust - /// # fn really_expensive_fn(i: i32) -> i32 { i } - /// # let v = vec![]; - /// _ = v.into_iter().filter_map(|i| (i % 2 == 0).then(|| really_expensive_fn(i))); - /// ``` - /// Use instead: - /// ```rust - /// # fn really_expensive_fn(i: i32) -> i32 { i } - /// # let v = vec![]; - /// _ = v.into_iter().filter(|i| i % 2 == 0).map(|i| really_expensive_fn(i)); - /// ``` - #[clippy::version = "1.72.0"] - pub FILTER_MAP_BOOL_THEN, - style, - "checks for usage of `bool::then` in `Iterator::filter_map`" -} - declare_clippy_lint! { /// ### What it does /// Looks for calls to `RwLock::write` where the lock is only used for reading. @@ -3676,7 +3644,6 @@ impl_lint_pass!(Methods => [ FORMAT_COLLECT, STRING_LIT_CHARS_ANY, ITER_SKIP_ZERO, - FILTER_MAP_BOOL_THEN, READONLY_WRITE_LOCK ]); @@ -3955,7 +3922,6 @@ impl Methods { }, ("filter_map", [arg]) => { unnecessary_filter_map::check(cx, expr, arg, name); - filter_map_bool_then::check(cx, expr, arg, call_span); filter_map_identity::check(cx, expr, arg, span); }, ("find_map", [arg]) => { diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index 914ea85ac280..8d96d3cfe50b 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -163,5 +163,3 @@ pub const OPTION_EXPECT: [&str; 4] = ["core", "option", "Option", "expect"]; pub const FORMATTER: [&str; 3] = ["core", "fmt", "Formatter"]; pub const DEBUG_STRUCT: [&str; 4] = ["core", "fmt", "builders", "DebugStruct"]; pub const ORD_CMP: [&str; 4] = ["core", "cmp", "Ord", "cmp"]; -#[expect(clippy::invalid_paths)] // not sure why it thinks this, it works so -pub const BOOL_THEN: [&str; 4] = ["core", "bool", "", "then"]; diff --git a/tests/ui/filter_map_bool_then.fixed b/tests/ui/filter_map_bool_then.fixed deleted file mode 100644 index 3e72fee4b072..000000000000 --- a/tests/ui/filter_map_bool_then.fixed +++ /dev/null @@ -1,44 +0,0 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro -#![allow( - clippy::clone_on_copy, - clippy::map_identity, - clippy::unnecessary_lazy_evaluations, - unused -)] -#![warn(clippy::filter_map_bool_then)] - -#[macro_use] -extern crate proc_macros; - -#[derive(Clone, PartialEq)] -struct NonCopy; - -fn main() { - let v = vec![1, 2, 3, 4, 5, 6]; - v.clone().iter().filter(|&i| (i % 2 == 0)).map(|i| i + 1); - v.clone().into_iter().filter(|&i| (i % 2 == 0)).map(|i| i + 1); - v.clone() - .into_iter() - .filter(|&i| (i % 2 == 0)).map(|i| i + 1); - v.clone() - .into_iter() - .filter(|&i| i != 1000) - .filter(|&i| (i % 2 == 0)).map(|i| i + 1); - v.iter() - .copied() - .filter(|&i| i != 1000) - .filter(|&i| (i.clone() % 2 == 0)).map(|i| i + 1); - // Do not lint - let v = vec![NonCopy, NonCopy]; - v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i)); - external! { - let v = vec![1, 2, 3, 4, 5, 6]; - v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); - } - with_span! { - span - let v = vec![1, 2, 3, 4, 5, 6]; - v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); - } -} diff --git a/tests/ui/filter_map_bool_then.rs b/tests/ui/filter_map_bool_then.rs deleted file mode 100644 index 38a04e57de45..000000000000 --- a/tests/ui/filter_map_bool_then.rs +++ /dev/null @@ -1,44 +0,0 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro -#![allow( - clippy::clone_on_copy, - clippy::map_identity, - clippy::unnecessary_lazy_evaluations, - unused -)] -#![warn(clippy::filter_map_bool_then)] - -#[macro_use] -extern crate proc_macros; - -#[derive(Clone, PartialEq)] -struct NonCopy; - -fn main() { - let v = vec![1, 2, 3, 4, 5, 6]; - v.clone().iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); - v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); - v.clone() - .into_iter() - .filter_map(|i| -> Option<_> { (i % 2 == 0).then(|| i + 1) }); - v.clone() - .into_iter() - .filter(|&i| i != 1000) - .filter_map(|i| (i % 2 == 0).then(|| i + 1)); - v.iter() - .copied() - .filter(|&i| i != 1000) - .filter_map(|i| (i.clone() % 2 == 0).then(|| i + 1)); - // Do not lint - let v = vec![NonCopy, NonCopy]; - v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i)); - external! { - let v = vec![1, 2, 3, 4, 5, 6]; - v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); - } - with_span! { - span - let v = vec![1, 2, 3, 4, 5, 6]; - v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); - } -} diff --git a/tests/ui/filter_map_bool_then.stderr b/tests/ui/filter_map_bool_then.stderr deleted file mode 100644 index b411cd83dfd2..000000000000 --- a/tests/ui/filter_map_bool_then.stderr +++ /dev/null @@ -1,34 +0,0 @@ -error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:19:22 - | -LL | v.clone().iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` - | - = note: `-D clippy::filter-map-bool-then` implied by `-D warnings` - -error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:20:27 - | -LL | v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` - -error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:23:10 - | -LL | .filter_map(|i| -> Option<_> { (i % 2 == 0).then(|| i + 1) }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` - -error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:27:10 - | -LL | .filter_map(|i| (i % 2 == 0).then(|| i + 1)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` - -error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:31:10 - | -LL | .filter_map(|i| (i.clone() % 2 == 0).then(|| i + 1)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i.clone() % 2 == 0)).map(|i| i + 1)` - -error: aborting due to 5 previous errors - From 716bdbc0fe7acd9e31abc42b242f0a46b8ecccee Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 13 Aug 2023 13:59:19 +0000 Subject: [PATCH 0907/1222] Remove constness from `ImplSource::Param` --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 4c695cb9b6e1..139e31bc5286 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -415,7 +415,7 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx> if !matches!( impl_src, - ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(ty::BoundConstness::ConstIfConst, _) + ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(_) ) { return false; } From 085214fc67b05dc3b846912584ef34798c16cb32 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Wed, 26 Apr 2023 20:53:51 +0200 Subject: [PATCH 0908/1222] Use `{Local}ModDefId` in many queries --- clippy_utils/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 171b7faf2196..b77a2f1d0cd0 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -83,7 +83,7 @@ use rustc_ast::Attribute; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::unhash::UnhashMap; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; +use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalModDefId, LOCAL_CRATE}; use rustc_hir::hir_id::{HirIdMap, HirIdSet}; use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk}; @@ -2370,11 +2370,11 @@ pub fn is_hir_ty_cfg_dependant(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool { false } -static TEST_ITEM_NAMES_CACHE: OnceLock>>> = OnceLock::new(); +static TEST_ITEM_NAMES_CACHE: OnceLock>>> = OnceLock::new(); -fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalDefId, f: impl Fn(&[Symbol]) -> bool) -> bool { +fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId, f: impl Fn(&[Symbol]) -> bool) -> bool { let cache = TEST_ITEM_NAMES_CACHE.get_or_init(|| Mutex::new(FxHashMap::default())); - let mut map: MutexGuard<'_, FxHashMap>> = cache.lock().unwrap(); + let mut map: MutexGuard<'_, FxHashMap>> = cache.lock().unwrap(); let value = map.entry(module); match value { Entry::Occupied(entry) => f(entry.get()), From ab38bc78915b920671b7c6e9c9d844e009dc4fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 14 Aug 2023 19:25:01 +0000 Subject: [PATCH 0909/1222] Move scrutinee `HirId` into `MatchSource::TryDesugar` --- clippy_lints/src/dereference.rs | 3 ++- clippy_lints/src/matches/mod.rs | 2 +- clippy_lints/src/matches/try_err.rs | 2 +- clippy_lints/src/methods/clone_on_copy.rs | 2 +- clippy_lints/src/methods/str_splitn.rs | 2 +- clippy_lints/src/needless_question_mark.rs | 2 +- clippy_lints/src/question_mark_used.rs | 2 +- clippy_lints/src/redundant_closure_call.rs | 2 +- clippy_lints/src/returns.rs | 2 +- clippy_lints/src/unit_types/unit_arg.rs | 2 +- clippy_lints/src/useless_conversion.rs | 2 +- clippy_utils/src/check_proc_macro.rs | 2 +- clippy_utils/src/lib.rs | 2 +- clippy_utils/src/visitors.rs | 2 +- 14 files changed, 15 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index bc011a6c354c..58c278550001 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -802,7 +802,8 @@ fn in_postfix_position<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> boo match parent.kind { ExprKind::Call(child, _) | ExprKind::MethodCall(_, child, _, _) | ExprKind::Index(child, _, _) if child.hir_id == e.hir_id => true, - ExprKind::Field(_, _) | ExprKind::Match(_, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar) => true, + ExprKind::Match(.., MatchSource::TryDesugar(_) | MatchSource::AwaitDesugar) + | ExprKind::Field(_, _) => true, _ => false, } } else { diff --git a/clippy_lints/src/matches/mod.rs b/clippy_lints/src/matches/mod.rs index 6d16d1887540..930386a60aa0 100644 --- a/clippy_lints/src/matches/mod.rs +++ b/clippy_lints/src/matches/mod.rs @@ -1038,7 +1038,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches { wild_in_or_pats::check(cx, arms); } - if source == MatchSource::TryDesugar { + if let MatchSource::TryDesugar(_) = source { try_err::check(cx, expr, ex); } diff --git a/clippy_lints/src/matches/try_err.rs b/clippy_lints/src/matches/try_err.rs index 99a748489b47..0fd6f533db0d 100644 --- a/clippy_lints/src/matches/try_err.rs +++ b/clippy_lints/src/matches/try_err.rs @@ -80,7 +80,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, scrutine /// Finds function return type by examining return expressions in match arms. fn find_return_type<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx ExprKind<'_>) -> Option> { - if let ExprKind::Match(_, arms, MatchSource::TryDesugar) = expr { + if let ExprKind::Match(_, arms, MatchSource::TryDesugar(_)) = expr { for arm in *arms { if let ExprKind::Ret(Some(ret)) = arm.body.kind { return Some(cx.typeck_results().expr_ty(ret)); diff --git a/clippy_lints/src/methods/clone_on_copy.rs b/clippy_lints/src/methods/clone_on_copy.rs index 7eb325ee7b5e..eb4f003d38ae 100644 --- a/clippy_lints/src/methods/clone_on_copy.rs +++ b/clippy_lints/src/methods/clone_on_copy.rs @@ -64,7 +64,7 @@ pub(super) fn check( ExprKind::Path(QPath::LangItem(rustc_hir::LangItem::TryTraitBranch, _, _)) ), ExprKind::MethodCall(_, self_arg, ..) if expr.hir_id == self_arg.hir_id => true, - ExprKind::Match(_, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar) + ExprKind::Match(_, _, MatchSource::TryDesugar(_) | MatchSource::AwaitDesugar) | ExprKind::Field(..) | ExprKind::Index(..) => true, _ => false, diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 41986551da47..7016ad0a80f1 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -236,7 +236,7 @@ fn indirect_usage<'tcx>( !matches!( node, Node::Expr(Expr { - kind: ExprKind::Match(.., MatchSource::TryDesugar), + kind: ExprKind::Match(.., MatchSource::TryDesugar(_)), .. }) ) diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index e2a7ba02a043..7b0f7eaf1f06 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -122,7 +122,7 @@ fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { } else { return; }; - if let ExprKind::Match(inner_expr_with_q, _, MatchSource::TryDesugar) = &arg.kind; + if let ExprKind::Match(inner_expr_with_q, _, MatchSource::TryDesugar(_)) = &arg.kind; if let ExprKind::Call(called, [inner_expr]) = &inner_expr_with_q.kind; if let ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, ..)) = &called.kind; if expr.span.ctxt() == inner_expr.span.ctxt(); diff --git a/clippy_lints/src/question_mark_used.rs b/clippy_lints/src/question_mark_used.rs index ff66b8a00953..d0de33e3c4f1 100644 --- a/clippy_lints/src/question_mark_used.rs +++ b/clippy_lints/src/question_mark_used.rs @@ -34,7 +34,7 @@ declare_lint_pass!(QuestionMarkUsed => [QUESTION_MARK_USED]); impl<'tcx> LateLintPass<'tcx> for QuestionMarkUsed { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Match(_, _, MatchSource::TryDesugar) = expr.kind { + if let ExprKind::Match(_, _, MatchSource::TryDesugar(_)) = expr.kind { if !span_is_local(expr.span) { return; } diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 4e3efe97b8c6..fc49b58e0a77 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -52,7 +52,7 @@ impl ReturnVisitor { impl<'tcx> Visitor<'tcx> for ReturnVisitor { fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) { - if let hir::ExprKind::Ret(_) | hir::ExprKind::Match(.., hir::MatchSource::TryDesugar) = ex.kind { + if let hir::ExprKind::Ret(_) | hir::ExprKind::Match(.., hir::MatchSource::TryDesugar(_)) = ex.kind { self.found_return = true; } else { hir_visit::walk_expr(self, ex); diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 351bacf5691f..d6b9a49d2fe0 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -164,7 +164,7 @@ impl<'tcx> LateLintPass<'tcx> for Return { if !in_external_macro(cx.sess(), stmt.span) && let StmtKind::Semi(expr) = stmt.kind && let ExprKind::Ret(Some(ret)) = expr.kind - && let ExprKind::Match(.., MatchSource::TryDesugar) = ret.kind + && let ExprKind::Match(.., MatchSource::TryDesugar(_)) = ret.kind // Ensure this is not the final stmt, otherwise removing it would cause a compile error && let OwnerNode::Item(item) = cx.tcx.hir().owner(cx.tcx.hir().get_parent_item(expr.hir_id)) && let ItemKind::Fn(_, _, body) = item.kind diff --git a/clippy_lints/src/unit_types/unit_arg.rs b/clippy_lints/src/unit_types/unit_arg.rs index dd120599c04e..462b1aa8153e 100644 --- a/clippy_lints/src/unit_types/unit_arg.rs +++ b/clippy_lints/src/unit_types/unit_arg.rs @@ -42,7 +42,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if cx.typeck_results().expr_ty(arg).is_unit() && !utils::is_unit_literal(arg) { !matches!( &arg.kind, - ExprKind::Match(.., MatchSource::TryDesugar) | ExprKind::Path(..) + ExprKind::Match(.., MatchSource::TryDesugar(_)) | ExprKind::Path(..) ) } else { false diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 92b694d30760..bd4dc07a42bf 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -113,7 +113,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { } match e.kind { - ExprKind::Match(_, arms, MatchSource::TryDesugar) => { + ExprKind::Match(_, arms, MatchSource::TryDesugar(_)) => { let (ExprKind::Ret(Some(e)) | ExprKind::Break(_, Some(e))) = arms[0].body.kind else { return; }; diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index 60fab1ec41ae..6be8b8bb9169 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -149,7 +149,7 @@ fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) { (Pat::Str("for"), Pat::Str("}")) }, ExprKind::Match(_, _, MatchSource::Normal) => (Pat::Str("match"), Pat::Str("}")), - ExprKind::Match(e, _, MatchSource::TryDesugar) => (expr_search_pat(tcx, e).0, Pat::Str("?")), + ExprKind::Match(e, _, MatchSource::TryDesugar(_)) => (expr_search_pat(tcx, e).0, Pat::Str("?")), ExprKind::Match(e, _, MatchSource::AwaitDesugar) | ExprKind::Yield(e, YieldSource::Await { .. }) => { (expr_search_pat(tcx, e).0, Pat::Str("await")) }, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 171b7faf2196..09576d67b23b 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1765,7 +1765,7 @@ pub fn is_try<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'tcx>) -> Option<&'tc if let ExprKind::Match(_, arms, ref source) = expr.kind { // desugared from a `?` operator - if *source == MatchSource::TryDesugar { + if let MatchSource::TryDesugar(_) = *source { return Some(expr); } diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index f83988a6e325..3b47a451345e 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -161,7 +161,7 @@ pub fn for_each_expr_with_closures<'tcx, B, C: Continue>( /// returns `true` if expr contains match expr desugared from try fn contains_try(expr: &hir::Expr<'_>) -> bool { for_each_expr(expr, |e| { - if matches!(e.kind, hir::ExprKind::Match(_, _, hir::MatchSource::TryDesugar)) { + if matches!(e.kind, hir::ExprKind::Match(_, _, hir::MatchSource::TryDesugar(_))) { ControlFlow::Break(()) } else { ControlFlow::Continue(()) From 8625d5ec9acd66d0861990fbc69d32475515374b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 14 Aug 2023 22:00:46 +0000 Subject: [PATCH 0910/1222] bless clippy test --- tests/ui/if_same_then_else2.rs | 2 +- tests/ui/if_same_then_else2.stderr | 21 +-------------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/tests/ui/if_same_then_else2.rs b/tests/ui/if_same_then_else2.rs index 0b171f21d0cc..c545434efe5b 100644 --- a/tests/ui/if_same_then_else2.rs +++ b/tests/ui/if_same_then_else2.rs @@ -98,7 +98,7 @@ fn if_same_then_else2() -> Result<&'static str, ()> { }; if true { - //~^ ERROR: this `if` has identical blocks + // FIXME: should emit "this `if` has identical blocks" Ok("foo")?; } else { Ok("foo")?; diff --git a/tests/ui/if_same_then_else2.stderr b/tests/ui/if_same_then_else2.stderr index 56e5f3e45b22..37fe787d1de3 100644 --- a/tests/ui/if_same_then_else2.stderr +++ b/tests/ui/if_same_then_else2.stderr @@ -82,25 +82,6 @@ LL | | f32::NAN LL | | }; | |_____^ -error: this `if` has identical blocks - --> $DIR/if_same_then_else2.rs:100:13 - | -LL | if true { - | _____________^ -LL | | -LL | | Ok("foo")?; -LL | | } else { - | |_____^ - | -note: same as this - --> $DIR/if_same_then_else2.rs:103:12 - | -LL | } else { - | ____________^ -LL | | Ok("foo")?; -LL | | } - | |_____^ - error: this `if` has identical blocks --> $DIR/if_same_then_else2.rs:124:20 | @@ -122,5 +103,5 @@ LL | | return Ok(&foo[0..]); LL | | } | |_____^ -error: aborting due to 6 previous errors +error: aborting due to 5 previous errors From 6ae104f0824f5c17f18ab7d58503b16d07ac8465 Mon Sep 17 00:00:00 2001 From: bors Date: Thu, 17 Aug 2023 14:41:46 +0000 Subject: [PATCH 0911/1222] Auto merge of #11070 - y21:issue11065, r=flip1995 [`useless_conversion`]: only lint on paths to fn items and fix FP in macro Fixes #11065 (which is actually two issues: an ICE and a false positive) It now makes sure that the function call path points to a function-like item (and not e.g. a `const` like in the linked issue), so that calling `TyCtxt::fn_sig` later in the lint does not ICE (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616836099). It *also* makes sure that the expression is not part of a macro call (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616919639). ~~I'm not sure if there's a better way to check this other than to walk the parent expr chain and see if any of them are expansions.~~ (edit: it doesn't do this anymore) changelog: [`useless_conversion`]: fix ICE when call receiver is a non-fn item changelog: [`useless_conversion`]: don't lint if argument is a macro argument (fixes a FP) r? `@llogiq` (reviewed #10814, which introduced these issues) --- clippy_lints/src/useless_conversion.rs | 18 +++++++++++++++--- tests/ui/crashes/ice-11065.rs | 19 +++++++++++++++++++ tests/ui/useless_conversion.fixed | 14 ++++++++++++++ tests/ui/useless_conversion.rs | 14 ++++++++++++++ tests/ui/useless_conversion.stderr | 20 ++++++++++---------- 5 files changed, 72 insertions(+), 13 deletions(-) create mode 100644 tests/ui/crashes/ice-11065.rs diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index bd4dc07a42bf..5ac4f0aa46c1 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -5,6 +5,7 @@ use clippy_utils::ty::{is_copy, is_type_diagnostic_item, same_type_and_consts}; use clippy_utils::{get_parent_expr, is_trait_method, is_ty_alias, match_def_path, path_to_local, paths}; use if_chain::if_chain; use rustc_errors::Applicability; +use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_hir::{BindingAnnotation, Expr, ExprKind, HirId, MatchSource, Node, PatKind}; use rustc_lint::{LateContext, LateLintPass}; @@ -39,6 +40,7 @@ declare_clippy_lint! { #[derive(Default)] pub struct UselessConversion { try_desugar_arm: Vec, + expn_depth: u32, } impl_lint_pass!(UselessConversion => [USELESS_CONVERSION]); @@ -105,6 +107,7 @@ fn into_iter_deep_call<'hir>(cx: &LateContext<'_>, mut expr: &'hir Expr<'hir>) - impl<'tcx> LateLintPass<'tcx> for UselessConversion { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if e.span.from_expansion() { + self.expn_depth += 1; return; } @@ -150,9 +153,14 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { { if let Some(parent) = get_parent_expr(cx, e) { let parent_fn = match parent.kind { - ExprKind::Call(recv, args) if let ExprKind::Path(ref qpath) = recv.kind => { - cx.qpath_res(qpath, recv.hir_id).opt_def_id() - .map(|did| (did, args, MethodOrFunction::Function)) + ExprKind::Call(recv, args) + if let ExprKind::Path(ref qpath) = recv.kind + && let Some(did) = cx.qpath_res(qpath, recv.hir_id).opt_def_id() + // make sure that the path indeed points to a fn-like item, so that + // `fn_sig` does not ICE. (see #11065) + && cx.tcx.opt_def_kind(did).is_some_and(DefKind::is_fn_like) => + { + Some((did, args, MethodOrFunction::Function)) } ExprKind::MethodCall(.., args, _) => { cx.typeck_results().type_dependent_def_id(parent.hir_id) @@ -168,6 +176,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { && let Some(&into_iter_param) = sig.inputs().get(kind.param_pos(arg_pos)) && let ty::Param(param) = into_iter_param.kind() && let Some(span) = into_iter_bound(cx, parent_fn_did, into_iter_did, param.index) + && self.expn_depth == 0 { // Get the "innermost" `.into_iter()` call, e.g. given this expression: // `foo.into_iter().into_iter()` @@ -303,5 +312,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { if Some(&e.hir_id) == self.try_desugar_arm.last() { self.try_desugar_arm.pop(); } + if e.span.from_expansion() { + self.expn_depth -= 1; + } } } diff --git a/tests/ui/crashes/ice-11065.rs b/tests/ui/crashes/ice-11065.rs new file mode 100644 index 000000000000..f5cf6b1cd77a --- /dev/null +++ b/tests/ui/crashes/ice-11065.rs @@ -0,0 +1,19 @@ +#![warn(clippy::useless_conversion)] + +use std::iter::FromIterator; +use std::option::IntoIter as OptionIter; + +fn eq(a: T, b: T) -> bool { + a == b +} + +macro_rules! tests { + ($($expr:expr, $ty:ty, ($($test:expr),*);)+) => (pub fn main() {$({ + const C: $ty = $expr; + assert!(eq(C($($test),*), $expr($($test),*))); + })+}) +} + +tests! { + FromIterator::from_iter, fn(OptionIter) -> Vec, (Some(5).into_iter()); +} diff --git a/tests/ui/useless_conversion.fixed b/tests/ui/useless_conversion.fixed index 5d2c5b11658e..53d8a5a9ff18 100644 --- a/tests/ui/useless_conversion.fixed +++ b/tests/ui/useless_conversion.fixed @@ -155,6 +155,20 @@ fn main() { let _ = vec![s4, s4, s4].into_iter(); } +#[allow(dead_code)] +fn issue11065_fp() { + use std::option::IntoIter; + fn takes_into_iter(_: impl IntoIterator) {} + + macro_rules! x { + ($e:expr) => { + takes_into_iter($e); + let _: IntoIter = $e; // removing `.into_iter()` leads to a type error here + }; + } + x!(Some(5).into_iter()); +} + #[allow(dead_code)] fn explicit_into_iter_fn_arg() { fn a(_: T) {} diff --git a/tests/ui/useless_conversion.rs b/tests/ui/useless_conversion.rs index 03a3e3f95ba4..51ba49873396 100644 --- a/tests/ui/useless_conversion.rs +++ b/tests/ui/useless_conversion.rs @@ -155,6 +155,20 @@ fn main() { let _ = vec![s4, s4, s4].into_iter().into_iter(); } +#[allow(dead_code)] +fn issue11065_fp() { + use std::option::IntoIter; + fn takes_into_iter(_: impl IntoIterator) {} + + macro_rules! x { + ($e:expr) => { + takes_into_iter($e); + let _: IntoIter = $e; // removing `.into_iter()` leads to a type error here + }; + } + x!(Some(5).into_iter()); +} + #[allow(dead_code)] fn explicit_into_iter_fn_arg() { fn a(_: T) {} diff --git a/tests/ui/useless_conversion.stderr b/tests/ui/useless_conversion.stderr index 4957f73a469a..6f7dc01d2cd2 100644 --- a/tests/ui/useless_conversion.stderr +++ b/tests/ui/useless_conversion.stderr @@ -119,61 +119,61 @@ LL | let _ = vec![s4, s4, s4].into_iter().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![s4, s4, s4].into_iter()` error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:171:7 + --> $DIR/useless_conversion.rs:185:7 | LL | b(vec![1, 2].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:161:13 + --> $DIR/useless_conversion.rs:175:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:172:7 + --> $DIR/useless_conversion.rs:186:7 | LL | c(vec![1, 2].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:162:18 + --> $DIR/useless_conversion.rs:176:18 | LL | fn c(_: impl IntoIterator) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:173:7 + --> $DIR/useless_conversion.rs:187:7 | LL | d(vec![1, 2].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:165:12 + --> $DIR/useless_conversion.rs:179:12 | LL | T: IntoIterator, | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:176:7 + --> $DIR/useless_conversion.rs:190:7 | LL | b(vec![1, 2].into_iter().into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:161:13 + --> $DIR/useless_conversion.rs:175:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:177:7 + --> $DIR/useless_conversion.rs:191:7 | LL | b(vec![1, 2].into_iter().into_iter().into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:161:13 + --> $DIR/useless_conversion.rs:175:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ From b42a9d93e17abf41eb247761bbb0cb66ed01d4bb Mon Sep 17 00:00:00 2001 From: bors Date: Thu, 17 Aug 2023 15:55:23 +0000 Subject: [PATCH 0912/1222] Auto merge of #11314 - GuillaumeGomez:needless_ref_mut_async_block, r=Centri3 Correctly handle async blocks for NEEDLESS_PASS_BY_REF_MUT Fixes https://github.com/rust-lang/rust-clippy/issues/11299. The problem was that the `async block`s are popping a closure which we didn't go into, making it miss the mutable access to the variables. cc `@Centri3` changelog: none --- clippy_lints/src/needless_pass_by_ref_mut.rs | 103 +++++++++++++++---- tests/ui/needless_pass_by_ref_mut.rs | 35 +++++++ tests/ui/needless_pass_by_ref_mut.stderr | 14 ++- 3 files changed, 129 insertions(+), 23 deletions(-) diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index c634de960d13..7b00eabf97b4 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -5,14 +5,16 @@ use clippy_utils::{get_parent_node, inherits_cfg, is_from_proc_macro, is_self}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_qpath, FnKind, Visitor}; -use rustc_hir::{Body, ExprKind, FnDecl, HirId, HirIdMap, HirIdSet, Impl, ItemKind, Mutability, Node, PatKind, QPath}; +use rustc_hir::{ + Body, Closure, Expr, ExprKind, FnDecl, HirId, HirIdMap, HirIdSet, Impl, ItemKind, Mutability, Node, PatKind, QPath, +}; use rustc_hir_typeck::expr_use_visitor as euv; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::map::associated_body; use rustc_middle::hir::nested_filter::OnlyBodies; use rustc_middle::mir::FakeReadCause; -use rustc_middle::ty::{self, Ty, UpvarId, UpvarPath}; +use rustc_middle::ty::{self, Ty, TyCtxt, UpvarId, UpvarPath}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::kw; @@ -147,22 +149,36 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { // Collect variables mutably used and spans which will need dereferencings from the // function body. let MutablyUsedVariablesCtxt { mutably_used_vars, .. } = { - let mut ctx = MutablyUsedVariablesCtxt::default(); + let mut ctx = MutablyUsedVariablesCtxt { + mutably_used_vars: HirIdSet::default(), + prev_bind: None, + prev_move_to_closure: HirIdSet::default(), + aliases: HirIdMap::default(), + async_closures: FxHashSet::default(), + tcx: cx.tcx, + }; let infcx = cx.tcx.infer_ctxt().build(); euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body); if is_async { - let closures = ctx.async_closures.clone(); - let hir = cx.tcx.hir(); - for closure in closures { - ctx.prev_bind = None; - ctx.prev_move_to_closure.clear(); - if let Some(body) = hir - .find_by_def_id(closure) - .and_then(associated_body) - .map(|(_, body_id)| hir.body(body_id)) - { - euv::ExprUseVisitor::new(&mut ctx, &infcx, closure, cx.param_env, cx.typeck_results()) - .consume_body(body); + let mut checked_closures = FxHashSet::default(); + while !ctx.async_closures.is_empty() { + let closures = ctx.async_closures.clone(); + ctx.async_closures.clear(); + let hir = cx.tcx.hir(); + for closure in closures { + if !checked_closures.insert(closure) { + continue; + } + ctx.prev_bind = None; + ctx.prev_move_to_closure.clear(); + if let Some(body) = hir + .find_by_def_id(closure) + .and_then(associated_body) + .map(|(_, body_id)| hir.body(body_id)) + { + euv::ExprUseVisitor::new(&mut ctx, &infcx, closure, cx.param_env, cx.typeck_results()) + .consume_body(body); + } } } } @@ -225,16 +241,16 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { } } -#[derive(Default)] -struct MutablyUsedVariablesCtxt { +struct MutablyUsedVariablesCtxt<'tcx> { mutably_used_vars: HirIdSet, prev_bind: Option, prev_move_to_closure: HirIdSet, aliases: HirIdMap, async_closures: FxHashSet, + tcx: TyCtxt<'tcx>, } -impl MutablyUsedVariablesCtxt { +impl<'tcx> MutablyUsedVariablesCtxt<'tcx> { fn add_mutably_used_var(&mut self, mut used_id: HirId) { while let Some(id) = self.aliases.get(&used_id) { self.mutably_used_vars.insert(used_id); @@ -242,9 +258,27 @@ impl MutablyUsedVariablesCtxt { } self.mutably_used_vars.insert(used_id); } + + fn would_be_alias_cycle(&self, alias: HirId, mut target: HirId) -> bool { + while let Some(id) = self.aliases.get(&target) { + if *id == alias { + return true; + } + target = *id; + } + false + } + + fn add_alias(&mut self, alias: HirId, target: HirId) { + // This is to prevent alias loop. + if alias == target || self.would_be_alias_cycle(alias, target) { + return; + } + self.aliases.insert(alias, target); + } } -impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt { +impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt<'tcx> { fn consume(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, _id: HirId) { if let euv::Place { base: @@ -259,7 +293,7 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt { { if let Some(bind_id) = self.prev_bind.take() { if bind_id != *vid { - self.aliases.insert(bind_id, *vid); + self.add_alias(bind_id, *vid); } } else if !self.prev_move_to_closure.contains(vid) && matches!(base_ty.ref_mutability(), Some(Mutability::Mut)) @@ -289,6 +323,25 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt { { self.add_mutably_used_var(*vid); } + } else if borrow == ty::ImmBorrow { + // If there is an `async block`, it'll contain a call to a closure which we need to + // go into to ensure all "mutate" checks are found. + if let Node::Expr(Expr { + kind: + ExprKind::Call( + _, + [ + Expr { + kind: ExprKind::Closure(Closure { def_id, .. }), + .. + }, + ], + ), + .. + }) = self.tcx.hir().get(cmt.hir_id) + { + self.async_closures.insert(*def_id); + } } } @@ -296,7 +349,12 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt { self.prev_bind = None; if let euv::Place { projections, - base: euv::PlaceBase::Local(vid), + base: + euv::PlaceBase::Local(vid) + | euv::PlaceBase::Upvar(UpvarId { + var_path: UpvarPath { hir_id: vid }, + .. + }), .. } = &cmt.place { @@ -329,8 +387,9 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt { // Seems like we are inside an async function. We need to store the closure `DefId` // to go through it afterwards. self.async_closures.insert(inner); - self.aliases.insert(cmt.hir_id, *vid); + self.add_alias(cmt.hir_id, *vid); self.prev_move_to_closure.insert(*vid); + self.prev_bind = None; } } } diff --git a/tests/ui/needless_pass_by_ref_mut.rs b/tests/ui/needless_pass_by_ref_mut.rs index ae7b018d0e25..ec87d4475975 100644 --- a/tests/ui/needless_pass_by_ref_mut.rs +++ b/tests/ui/needless_pass_by_ref_mut.rs @@ -196,6 +196,41 @@ mod foo { //~| NOTE: this is cfg-gated and may require further changes } +// Should not warn. +async fn inner_async(x: &mut i32, y: &mut u32) { + async { + *y += 1; + *x += 1; + } + .await; +} + +async fn inner_async2(x: &mut i32, y: &mut u32) { + //~^ ERROR: this argument is a mutable reference, but not used mutably + async { + *x += 1; + } + .await; +} + +async fn inner_async3(x: &mut i32, y: &mut u32) { + //~^ ERROR: this argument is a mutable reference, but not used mutably + async { + *y += 1; + } + .await; +} + +// Should not warn. +async fn async_vec(b: &mut Vec) { + b.append(&mut vec![]); +} + +// Should not warn. +async fn async_vec2(b: &mut Vec) { + b.push(true); +} + fn main() { let mut u = 0; let mut v = vec![0]; diff --git a/tests/ui/needless_pass_by_ref_mut.stderr b/tests/ui/needless_pass_by_ref_mut.stderr index 0d426ce32f9d..2e06e7252d9b 100644 --- a/tests/ui/needless_pass_by_ref_mut.stderr +++ b/tests/ui/needless_pass_by_ref_mut.stderr @@ -94,5 +94,17 @@ LL | fn cfg_warn(s: &mut u32) {} | = note: this is cfg-gated and may require further changes -error: aborting due to 15 previous errors +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:208:39 + | +LL | async fn inner_async2(x: &mut i32, y: &mut u32) { + | ^^^^^^^^ help: consider changing to: `&u32` + +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:216:26 + | +LL | async fn inner_async3(x: &mut i32, y: &mut u32) { + | ^^^^^^^^ help: consider changing to: `&i32` + +error: aborting due to 17 previous errors From 5b8996051f595055ea157c75162fe36ce7f4d2a7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 19 Aug 2023 13:10:25 +0200 Subject: [PATCH 0913/1222] give some unwind-related terminators a more clear name --- clippy_utils/src/qualify_min_const_fn.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 139e31bc5286..43523faa2361 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -291,8 +291,8 @@ fn check_terminator<'tcx>( | TerminatorKind::FalseUnwind { .. } | TerminatorKind::Goto { .. } | TerminatorKind::Return - | TerminatorKind::Resume - | TerminatorKind::Terminate + | TerminatorKind::UnwindResume + | TerminatorKind::UnwindTerminate | TerminatorKind::Unreachable => Ok(()), TerminatorKind::Drop { place, .. } => { if !is_ty_const_destruct(tcx, place.ty(&body.local_decls, tcx).ty, body) { From 77e14c7d313c159ad29386ed09a39b23ebf6e5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 23 Aug 2023 00:58:09 +0000 Subject: [PATCH 0914/1222] Fix clippy lint for identical `if`/`else` contraining `?` expressions Follow up to #114819. --- clippy_utils/src/hir_utils.rs | 3 ++- tests/ui/if_same_then_else2.rs | 2 +- tests/ui/if_same_then_else2.stderr | 21 ++++++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index fdc35cd4ddf8..98441e83eb4a 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -10,6 +10,7 @@ use rustc_hir::{ GenericArgs, Guard, HirId, HirIdMap, InlineAsmOperand, Let, Lifetime, LifetimeName, Pat, PatField, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding, }; +use rustc_hir::MatchSource::TryDesugar; use rustc_lexer::{tokenize, TokenKind}; use rustc_lint::LateContext; use rustc_middle::ty::TypeckResults; @@ -311,7 +312,7 @@ impl HirEqInterExpr<'_, '_, '_> { lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.name == r.ident.name) }, (&ExprKind::Match(le, la, ref ls), &ExprKind::Match(re, ra, ref rs)) => { - ls == rs + (ls == rs || (matches!((ls, rs), (TryDesugar(_), TryDesugar(_))))) && self.eq_expr(le, re) && over(la, ra, |l, r| { self.eq_pat(l.pat, r.pat) diff --git a/tests/ui/if_same_then_else2.rs b/tests/ui/if_same_then_else2.rs index c545434efe5b..0b171f21d0cc 100644 --- a/tests/ui/if_same_then_else2.rs +++ b/tests/ui/if_same_then_else2.rs @@ -98,7 +98,7 @@ fn if_same_then_else2() -> Result<&'static str, ()> { }; if true { - // FIXME: should emit "this `if` has identical blocks" + //~^ ERROR: this `if` has identical blocks Ok("foo")?; } else { Ok("foo")?; diff --git a/tests/ui/if_same_then_else2.stderr b/tests/ui/if_same_then_else2.stderr index 37fe787d1de3..56e5f3e45b22 100644 --- a/tests/ui/if_same_then_else2.stderr +++ b/tests/ui/if_same_then_else2.stderr @@ -82,6 +82,25 @@ LL | | f32::NAN LL | | }; | |_____^ +error: this `if` has identical blocks + --> $DIR/if_same_then_else2.rs:100:13 + | +LL | if true { + | _____________^ +LL | | +LL | | Ok("foo")?; +LL | | } else { + | |_____^ + | +note: same as this + --> $DIR/if_same_then_else2.rs:103:12 + | +LL | } else { + | ____________^ +LL | | Ok("foo")?; +LL | | } + | |_____^ + error: this `if` has identical blocks --> $DIR/if_same_then_else2.rs:124:20 | @@ -103,5 +122,5 @@ LL | | return Ok(&foo[0..]); LL | | } | |_____^ -error: aborting due to 5 previous errors +error: aborting due to 6 previous errors From ff1a90b86176fdb35678bf3b7a5fca31cb8b5ff0 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 21 Aug 2023 09:57:10 +0200 Subject: [PATCH 0915/1222] when terminating during unwinding, show the reason why --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 43523faa2361..17233058c9c9 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -292,7 +292,7 @@ fn check_terminator<'tcx>( | TerminatorKind::Goto { .. } | TerminatorKind::Return | TerminatorKind::UnwindResume - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Unreachable => Ok(()), TerminatorKind::Drop { place, .. } => { if !is_ty_const_destruct(tcx, place.ty(&body.local_decls, tcx).ty, body) { From 410872691ace23361ab488cbc7f4e2cc3d78d9b4 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 29 Aug 2023 13:28:53 +0000 Subject: [PATCH 0916/1222] Bump ui_test --- Cargo.toml | 2 +- tests/compile-test.rs | 4 ++-- tests/ui/derive.stderr | 20 ++++++++++---------- tests/ui/temporary_assignment.stderr | 8 ++++---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cd04c78ef9ee..7c78beb5ddef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ tempfile = { version = "3.2", optional = true } termize = "0.1" [dev-dependencies] -ui_test = "0.17.0" +ui_test = "0.18.1" tester = "0.9" regex = "1.5" toml = "0.7.3" diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 844e66728f25..e329a94ff6a1 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -4,7 +4,7 @@ #![warn(rust_2018_idioms, unused_lifetimes)] #![allow(unused_extern_crates)] -use ui_test::{status_emitter, Args, CommandBuilder, Config, Match, Mode, OutputConflictHandling}; +use ui_test::{status_emitter, Args, CommandBuilder, Config, Match, Mode, OutputConflictHandling, RustfixMode}; use std::collections::BTreeMap; use std::env::{self, set_var, var_os}; @@ -130,7 +130,7 @@ fn base_config(test_dir: &str) -> (Config, Args) { }; let mut config = Config { - mode: Mode::Yolo { rustfix: true }, + mode: Mode::Yolo { rustfix: RustfixMode::Everything }, stderr_filters: vec![(Match::PathBackslash, b"/")], stdout_filters: vec![], output_conflict_handling: if bless { diff --git a/tests/ui/derive.stderr b/tests/ui/derive.stderr index cf8e90cd844e..2986296bcaf7 100644 --- a/tests/ui/derive.stderr +++ b/tests/ui/derive.stderr @@ -1,5 +1,5 @@ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:11:1 + --> $DIR/derive.rs:12:1 | LL | / impl Clone for Qux { LL | | @@ -10,7 +10,7 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:11:1 + --> $DIR/derive.rs:12:1 | LL | / impl Clone for Qux { LL | | @@ -22,7 +22,7 @@ LL | | } = note: `-D clippy::expl-impl-clone-on-copy` implied by `-D warnings` error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:36:1 + --> $DIR/derive.rs:37:1 | LL | / impl<'a> Clone for Lt<'a> { LL | | @@ -33,7 +33,7 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:36:1 + --> $DIR/derive.rs:37:1 | LL | / impl<'a> Clone for Lt<'a> { LL | | @@ -44,7 +44,7 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:48:1 + --> $DIR/derive.rs:49:1 | LL | / impl Clone for BigArray { LL | | @@ -55,7 +55,7 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:48:1 + --> $DIR/derive.rs:49:1 | LL | / impl Clone for BigArray { LL | | @@ -66,7 +66,7 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:60:1 + --> $DIR/derive.rs:61:1 | LL | / impl Clone for FnPtr { LL | | @@ -77,7 +77,7 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:60:1 + --> $DIR/derive.rs:61:1 | LL | / impl Clone for FnPtr { LL | | @@ -88,7 +88,7 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:81:1 + --> $DIR/derive.rs:82:1 | LL | / impl Clone for Generic2 { LL | | @@ -99,7 +99,7 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:81:1 + --> $DIR/derive.rs:82:1 | LL | / impl Clone for Generic2 { LL | | diff --git a/tests/ui/temporary_assignment.stderr b/tests/ui/temporary_assignment.stderr index 12e2c5a2fc31..241abc2c5c7c 100644 --- a/tests/ui/temporary_assignment.stderr +++ b/tests/ui/temporary_assignment.stderr @@ -1,5 +1,5 @@ error: assignment to temporary - --> $DIR/temporary_assignment.rs:47:5 + --> $DIR/temporary_assignment.rs:48:5 | LL | Struct { field: 0 }.field = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | Struct { field: 0 }.field = 1; = note: `-D clippy::temporary-assignment` implied by `-D warnings` error: assignment to temporary - --> $DIR/temporary_assignment.rs:50:5 + --> $DIR/temporary_assignment.rs:51:5 | LL | / MultiStruct { LL | | @@ -18,13 +18,13 @@ LL | | .field = 1; | |______________^ error: assignment to temporary - --> $DIR/temporary_assignment.rs:56:5 + --> $DIR/temporary_assignment.rs:57:5 | LL | ArrayStruct { array: [0] }.array[0] = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: assignment to temporary - --> $DIR/temporary_assignment.rs:58:5 + --> $DIR/temporary_assignment.rs:59:5 | LL | (0, 0).0 = 1; | ^^^^^^^^^^^^ From a632f8963fd11468375d899685bc2e7f86e55e14 Mon Sep 17 00:00:00 2001 From: Caio Date: Thu, 31 Aug 2023 15:10:51 -0300 Subject: [PATCH 0917/1222] [`clippy`] Use symbols intended for `arithmetic_side_effects` --- .../src/operators/arithmetic_side_effects.rs | 49 +++++++++++++++---- tests/ui/arithmetic_side_effects.rs | 30 +++++++++++- tests/ui/arithmetic_side_effects.stderr | 14 +++++- 3 files changed, 82 insertions(+), 11 deletions(-) diff --git a/clippy_lints/src/operators/arithmetic_side_effects.rs b/clippy_lints/src/operators/arithmetic_side_effects.rs index f9108145cdb6..a687c7d29b56 100644 --- a/clippy_lints/src/operators/arithmetic_side_effects.rs +++ b/clippy_lints/src/operators/arithmetic_side_effects.rs @@ -1,24 +1,20 @@ use super::ARITHMETIC_SIDE_EFFECTS; use clippy_utils::consts::{constant, constant_simple, Constant}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::ty::type_diagnostic_name; use clippy_utils::{expr_or_init, is_from_proc_macro, is_lint_allowed, peel_hir_expr_refs, peel_hir_expr_unary}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::Ty; use rustc_session::impl_lint_pass; use rustc_span::source_map::{Span, Spanned}; +use rustc_span::symbol::sym; use rustc_span::Symbol; use {rustc_ast as ast, rustc_hir as hir}; -const HARD_CODED_ALLOWED_BINARY: &[[&str; 2]] = &[ - ["f32", "f32"], - ["f64", "f64"], - ["std::num::Saturating", "*"], - ["std::num::Wrapping", "*"], - ["std::string::String", "str"], -]; +const HARD_CODED_ALLOWED_BINARY: &[[&str; 2]] = &[["f32", "f32"], ["f64", "f64"], ["std::string::String", "str"]]; const HARD_CODED_ALLOWED_UNARY: &[&str] = &["f32", "f64", "std::num::Saturating", "std::num::Wrapping"]; -const INTEGER_METHODS: &[&str] = &["saturating_div", "wrapping_div", "wrapping_rem", "wrapping_rem_euclid"]; +const INTEGER_METHODS: &[Symbol] = &[sym::saturating_div, sym::wrapping_div, sym::wrapping_rem, sym::wrapping_rem_euclid]; #[derive(Debug)] pub struct ArithmeticSideEffects { @@ -53,7 +49,7 @@ impl ArithmeticSideEffects { allowed_unary, const_span: None, expr_span: None, - integer_methods: INTEGER_METHODS.iter().map(|el| Symbol::intern(el)).collect(), + integer_methods: INTEGER_METHODS.iter().copied().collect(), } } @@ -86,6 +82,38 @@ impl ArithmeticSideEffects { self.allowed_unary.contains(ty_string_elem) } + /// Verifies built-in types that have specific allowed operations + fn has_specific_allowed_type_and_operation( + cx: &LateContext<'_>, + lhs_ty: Ty<'_>, + op: &Spanned, + rhs_ty: Ty<'_>, + ) -> bool { + let is_div_or_rem = matches!(op.node, hir::BinOpKind::Div | hir::BinOpKind::Rem); + let is_non_zero_u = |symbol: Option| { + matches!( + symbol, + Some(sym::NonZeroU128 | sym::NonZeroU16 | sym::NonZeroU32 | sym::NonZeroU64 | sym::NonZeroU8 | sym::NonZeroUsize) + ) + }; + let is_sat_or_wrap = |ty: Ty<'_>| { + let is_sat = type_diagnostic_name(cx, ty) == Some(sym::Saturating); + let is_wrap = type_diagnostic_name(cx, ty) == Some(sym::Wrapping); + is_sat || is_wrap + }; + + // If the RHS is NonZeroU*, then division or module by zero will never occur + if is_non_zero_u(type_diagnostic_name(cx, rhs_ty)) && is_div_or_rem { + return true; + } + // `Saturation` and `Wrapping` can overflow if the RHS is zero in a division or module + if is_sat_or_wrap(lhs_ty) { + return !is_div_or_rem; + } + + false + } + // For example, 8i32 or &i64::MAX. fn is_integral(ty: Ty<'_>) -> bool { ty.peel_refs().is_integral() @@ -147,6 +175,9 @@ impl ArithmeticSideEffects { if self.has_allowed_binary(lhs_ty, rhs_ty) { return; } + if Self::has_specific_allowed_type_and_operation(cx, lhs_ty, op, rhs_ty) { + return; + } let has_valid_op = if Self::is_integral(lhs_ty) && Self::is_integral(rhs_ty) { if let hir::BinOpKind::Shl | hir::BinOpKind::Shr = op.node { // At least for integers, shifts are already handled by the CTFE diff --git a/tests/ui/arithmetic_side_effects.rs b/tests/ui/arithmetic_side_effects.rs index 8485b3eab71b..def30f5903d7 100644 --- a/tests/ui/arithmetic_side_effects.rs +++ b/tests/ui/arithmetic_side_effects.rs @@ -15,7 +15,7 @@ extern crate proc_macro_derive; -use core::num::{Saturating, Wrapping}; +use core::num::{NonZeroUsize, Saturating, Wrapping}; const ONE: i32 = 1; const ZERO: i32 = 0; @@ -493,4 +493,32 @@ pub fn issue_11262() { let _ = 2 / zero; } +pub fn issue_11392() { + fn example_div(unsigned: usize, nonzero_unsigned: NonZeroUsize) -> usize { + unsigned / nonzero_unsigned + } + + fn example_rem(unsigned: usize, nonzero_unsigned: NonZeroUsize) -> usize { + unsigned % nonzero_unsigned + } + + let (unsigned, nonzero_unsigned) = (0, NonZeroUsize::new(1).unwrap()); + example_div(unsigned, nonzero_unsigned); + example_rem(unsigned, nonzero_unsigned); +} + +pub fn issue_11393() { + fn example_div(x: Wrapping, maybe_zero: Wrapping) -> Wrapping { + x / maybe_zero + } + + fn example_rem(x: Wrapping, maybe_zero: Wrapping) -> Wrapping { + x % maybe_zero + } + + let [x, maybe_zero] = [1, 0].map(Wrapping); + example_div(x, maybe_zero); + example_rem(x, maybe_zero); +} + fn main() {} diff --git a/tests/ui/arithmetic_side_effects.stderr b/tests/ui/arithmetic_side_effects.stderr index e9a626643ff7..7f490748160b 100644 --- a/tests/ui/arithmetic_side_effects.stderr +++ b/tests/ui/arithmetic_side_effects.stderr @@ -702,5 +702,17 @@ error: arithmetic operation that can potentially result in unexpected side-effec LL | 10 / a | ^^^^^^ -error: aborting due to 117 previous errors +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:512:9 + | +LL | x / maybe_zero + | ^^^^^^^^^^^^^^ + +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:516:9 + | +LL | x % maybe_zero + | ^^^^^^^^^^^^^^ + +error: aborting due to 119 previous errors From 6bb900f9b19b350d2bcbe035e6678673ce7e07e5 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Wed, 26 Jul 2023 22:30:29 +0200 Subject: [PATCH 0918/1222] Stabilize the Saturating type (saturating_int_impl, gh-87920) Also stabilizes saturating_int_assign_impl, gh-92354. And also make pub fns const where the underlying saturating_* fns became const in the meantime since the Saturating type was created. --- tests/ui/arithmetic_side_effects.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/arithmetic_side_effects.rs b/tests/ui/arithmetic_side_effects.rs index def30f5903d7..b454c29aef4d 100644 --- a/tests/ui/arithmetic_side_effects.rs +++ b/tests/ui/arithmetic_side_effects.rs @@ -10,7 +10,7 @@ arithmetic_overflow, unconditional_panic )] -#![feature(const_mut_refs, inline_const, saturating_int_impl)] +#![feature(const_mut_refs, inline_const)] #![warn(clippy::arithmetic_side_effects)] extern crate proc_macro_derive; From 8faf1cd430614995160fa8eb93f1bfd3f36b2c6f Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 3 Sep 2023 10:15:35 +0000 Subject: [PATCH 0919/1222] Use relative positions inside a SourceFile. --- clippy_lints/src/undocumented_unsafe_blocks.rs | 4 ++-- clippy_utils/src/source.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index f2ef602012f7..7956bf126223 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -12,7 +12,7 @@ use rustc_lexer::{tokenize, TokenKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::{BytePos, Pos, Span, SyntaxContext}; +use rustc_span::{BytePos, RelativeBytePos,Pos, Span, SyntaxContext}; declare_clippy_lint! { /// ### What it does @@ -688,7 +688,7 @@ fn span_in_body_has_safety_comment(cx: &LateContext<'_>, span: Span) -> bool { } /// Checks if the given text has a safety comment for the immediately proceeding line. -fn text_has_safety_comment(src: &str, line_starts: &[BytePos], offset: usize) -> Option { +fn text_has_safety_comment(src: &str, line_starts: &[RelativeBytePos], offset: usize) -> Option { let mut lines = line_starts .array_windows::<2>() .rev() diff --git a/clippy_utils/src/source.rs b/clippy_utils/src/source.rs index dc4ee7256817..03416d35ba45 100644 --- a/clippy_utils/src/source.rs +++ b/clippy_utils/src/source.rs @@ -8,7 +8,7 @@ use rustc_hir::{BlockCheckMode, Expr, ExprKind, UnsafeSource}; use rustc_lint::{LateContext, LintContext}; use rustc_session::Session; use rustc_span::source_map::{original_sp, SourceMap}; -use rustc_span::{hygiene, BytePos, Pos, SourceFile, Span, SpanData, SyntaxContext, DUMMY_SP}; +use rustc_span::{hygiene, BytePos, SourceFileAndLine, Pos, SourceFile, Span, SpanData, SyntaxContext, DUMMY_SP}; use std::borrow::Cow; use std::ops::Range; @@ -117,9 +117,9 @@ fn first_char_in_first_line(cx: &T, span: Span) -> Option(cx: &T, span: Span) -> Span { let span = original_sp(span, DUMMY_SP); - let source_map_and_line = cx.sess().source_map().lookup_line(span.lo()).unwrap(); - let line_no = source_map_and_line.line; - let line_start = source_map_and_line.sf.lines(|lines| lines[line_no]); + let SourceFileAndLine { sf, line } = cx.sess().source_map().lookup_line(span.lo()).unwrap(); + let line_start = sf.lines(|lines| lines[line]); + let line_start = sf.absolute_position(line_start); span.with_lo(line_start) } From aa7ae5d9203695320dc916c4048fd1722d77d5c8 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 3 Sep 2023 14:34:40 +0000 Subject: [PATCH 0920/1222] Fix clippy. --- .../src/undocumented_unsafe_blocks.rs | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index 7956bf126223..a1ea3a495eb6 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -12,7 +12,7 @@ use rustc_lexer::{tokenize, TokenKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::{BytePos, RelativeBytePos,Pos, Span, SyntaxContext}; +use rustc_span::{BytePos, Pos, RelativeBytePos, Span, SyntaxContext}; declare_clippy_lint! { /// ### What it does @@ -514,7 +514,7 @@ fn item_has_safety_comment(cx: &LateContext<'_>, item: &hir::Item<'_>) -> HasSaf match text_has_safety_comment( src, &lines[comment_start_line.line + 1..=unsafe_line.line], - unsafe_line.sf.start_pos.to_usize(), + unsafe_line.sf.start_pos, ) { Some(b) => HasSafetyComment::Yes(b), None => HasSafetyComment::No, @@ -558,7 +558,7 @@ fn stmt_has_safety_comment(cx: &LateContext<'_>, span: Span, hir_id: HirId) -> H match text_has_safety_comment( src, &lines[comment_start_line.line + 1..=unsafe_line.line], - unsafe_line.sf.start_pos.to_usize(), + unsafe_line.sf.start_pos, ) { Some(b) => HasSafetyComment::Yes(b), None => HasSafetyComment::No, @@ -619,7 +619,7 @@ fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span match text_has_safety_comment( src, &lines[macro_line.line + 1..=unsafe_line.line], - unsafe_line.sf.start_pos.to_usize(), + unsafe_line.sf.start_pos, ) { Some(b) => HasSafetyComment::Yes(b), None => HasSafetyComment::No, @@ -675,7 +675,7 @@ fn span_in_body_has_safety_comment(cx: &LateContext<'_>, span: Span) -> bool { body_line.line < unsafe_line.line && text_has_safety_comment( src, &lines[body_line.line + 1..=unsafe_line.line], - unsafe_line.sf.start_pos.to_usize(), + unsafe_line.sf.start_pos, ).is_some() }) } else { @@ -688,13 +688,13 @@ fn span_in_body_has_safety_comment(cx: &LateContext<'_>, span: Span) -> bool { } /// Checks if the given text has a safety comment for the immediately proceeding line. -fn text_has_safety_comment(src: &str, line_starts: &[RelativeBytePos], offset: usize) -> Option { +fn text_has_safety_comment(src: &str, line_starts: &[RelativeBytePos], start_pos: BytePos) -> Option { let mut lines = line_starts .array_windows::<2>() .rev() .map_while(|[start, end]| { - let start = start.to_usize() - offset; - let end = end.to_usize() - offset; + let start = start.to_usize(); + let end = end.to_usize(); let text = src.get(start..end)?; let trimmed = text.trim_start(); Some((start + (text.len() - trimmed.len()), trimmed)) @@ -709,9 +709,7 @@ fn text_has_safety_comment(src: &str, line_starts: &[RelativeBytePos], offset: u let (mut line, mut line_start) = (line, line_start); loop { if line.to_ascii_uppercase().contains("SAFETY:") { - return Some(BytePos( - u32::try_from(line_start).unwrap() + u32::try_from(offset).unwrap(), - )); + return Some(start_pos + BytePos(u32::try_from(line_start).unwrap())); } match lines.next() { Some((s, x)) if x.starts_with("//") => (line, line_start) = (x, s), @@ -724,15 +722,13 @@ fn text_has_safety_comment(src: &str, line_starts: &[RelativeBytePos], offset: u let (mut line_start, mut line) = (line_start, line); loop { if line.starts_with("/*") { - let src = &src[line_start..line_starts.last().unwrap().to_usize() - offset]; + let src = &src[line_start..line_starts.last().unwrap().to_usize()]; let mut tokens = tokenize(src); return (src[..tokens.next().unwrap().len as usize] .to_ascii_uppercase() .contains("SAFETY:") && tokens.all(|t| t.kind == TokenKind::Whitespace)) - .then_some(BytePos( - u32::try_from(line_start).unwrap() + u32::try_from(offset).unwrap(), - )); + .then_some(start_pos + BytePos(u32::try_from(line_start).unwrap())); } match lines.next() { Some(x) => (line_start, line) = x, From c3f1a45a8a0e9214f39c28f1c0d4bf7e8ca4ffd9 Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 1 Aug 2023 14:02:21 +0200 Subject: [PATCH 0921/1222] Adjust clippy tests with new rustc help suggestion for lints --- .../absolute_paths/absolute_paths.allow_crates.stderr | 1 + .../absolute_paths/absolute_paths.disallow_crates.stderr | 1 + .../uninlined_format_args.stderr | 2 ++ .../arithmetic_side_effects_allowed.stderr | 1 + .../array_size_threshold/array_size_threshold.stderr | 2 ++ .../await_holding_invalid_type.stderr | 1 + .../ui-toml/conf_deprecated_key/conf_deprecated_key.stderr | 1 + tests/ui-toml/dbg_macro/dbg_macro.stderr | 1 + tests/ui-toml/disallowed_macros/disallowed_macros.stderr | 1 + .../disallowed_names_append/disallowed_names.stderr | 1 + .../disallowed_names_replace/disallowed_names.stderr | 1 + tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr | 1 + tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr | 1 + tests/ui-toml/excessive_nesting/excessive_nesting.stderr | 1 + tests/ui-toml/expect_used/expect_used.stderr | 1 + tests/ui-toml/fn_params_excessive_bools/test.stderr | 1 + tests/ui-toml/functions_maxlines/test.stderr | 1 + tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr | 1 + tests/ui-toml/large_futures/large_futures.stderr | 1 + tests/ui-toml/large_include_file/large_include_file.stderr | 1 + tests/ui-toml/lint_decimal_readability/test.stderr | 2 ++ tests/ui-toml/min_ident_chars/min_ident_chars.stderr | 1 + tests/ui-toml/min_rust_version/min_rust_version.stderr | 1 + .../conf_missing_enforced_import_rename.stderr | 1 + tests/ui-toml/module_inception/module_inception.stderr | 1 + .../conf_nonstandard_macro_braces.stderr | 1 + tests/ui-toml/print_macro/print_macro.stderr | 2 ++ .../pub_crate_missing_docs/pub_crate_missing_doc.stderr | 1 + tests/ui-toml/semicolon_block/both.stderr | 2 ++ .../ui-toml/semicolon_block/semicolon_inside_block.stderr | 1 + .../ui-toml/semicolon_block/semicolon_outside_block.stderr | 1 + .../ui-toml/strict_non_send_fields_in_send_ty/test.stderr | 1 + tests/ui-toml/struct_excessive_bools/test.stderr | 1 + tests/ui-toml/suppress_lint_in_const/test.stderr | 1 + .../toml_disallow/conf_french_disallowed_name.stderr | 1 + .../toml_disallowed_methods/conf_disallowed_methods.stderr | 1 + .../toml_disallowed_types/conf_disallowed_types.stderr | 1 + tests/ui-toml/toml_trivially_copy/test.stderr | 1 + .../undocumented_unsafe_blocks.stderr | 2 ++ tests/ui-toml/unwrap_used/unwrap_used.stderr | 2 ++ .../upper_case_acronyms.stderr | 1 + tests/ui-toml/vec_box_sized/test.stderr | 1 + tests/ui/absurd-extreme-comparisons.stderr | 1 + tests/ui/allow_attributes.stderr | 1 + tests/ui/almost_complete_range.stderr | 1 + tests/ui/approx_const.stderr | 1 + tests/ui/arc_with_non_send_sync.stderr | 1 + tests/ui/arithmetic_side_effects.stderr | 1 + tests/ui/as_conversions.stderr | 1 + tests/ui/as_ptr_cast_mut.stderr | 1 + tests/ui/as_underscore.stderr | 1 + tests/ui/asm_syntax.stderr | 2 ++ tests/ui/assertions_on_constants.stderr | 1 + tests/ui/assertions_on_result_states.stderr | 1 + tests/ui/assign_ops.stderr | 1 + tests/ui/assign_ops2.stderr | 2 ++ tests/ui/async_yields_async.stderr | 1 + tests/ui/attrs.stderr | 2 ++ tests/ui/await_holding_lock.stderr | 1 + tests/ui/await_holding_refcell_ref.stderr | 1 + tests/ui/bit_masks.stderr | 2 ++ tests/ui/blanket_clippy_restriction_lints.stderr | 1 + tests/ui/blocks_in_if_conditions.stderr | 2 ++ tests/ui/blocks_in_if_conditions_closure.stderr | 1 + tests/ui/bool_assert_comparison.stderr | 1 + tests/ui/bool_comparison.stderr | 1 + tests/ui/bool_to_int_with_if.stderr | 1 + tests/ui/borrow_as_ptr.stderr | 1 + tests/ui/borrow_as_ptr_no_std.stderr | 1 + tests/ui/borrow_deref_ref.stderr | 1 + tests/ui/borrow_deref_ref_unfixable.stderr | 1 + tests/ui/box_collection.stderr | 1 + tests/ui/box_default.stderr | 1 + tests/ui/boxed_local.stderr | 1 + tests/ui/builtin_type_shadow.stderr | 1 + tests/ui/bytes_count_to_len.stderr | 1 + tests/ui/bytes_nth.stderr | 1 + tests/ui/case_sensitive_file_extension_comparisons.stderr | 1 + tests/ui/cast.stderr | 5 +++++ tests/ui/cast_abs_to_unsigned.stderr | 1 + tests/ui/cast_alignment.stderr | 1 + tests/ui/cast_enum_constructor.stderr | 1 + tests/ui/cast_lossless_bool.stderr | 1 + tests/ui/cast_lossless_float.stderr | 1 + tests/ui/cast_lossless_integer.stderr | 1 + tests/ui/cast_nan_to_int.stderr | 1 + tests/ui/cast_raw_slice_pointer_cast.stderr | 1 + tests/ui/cast_size.stderr | 3 +++ tests/ui/cfg_attr_rustfmt.stderr | 1 + tests/ui/cfg_features.stderr | 1 + tests/ui/char_lit_as_u8.stderr | 1 + tests/ui/char_lit_as_u8_suggestions.stderr | 1 + tests/ui/checked_conversions.stderr | 1 + tests/ui/clear_with_drain.stderr | 1 + tests/ui/clone_on_copy.stderr | 1 + tests/ui/cloned_instead_of_copied.stderr | 1 + tests/ui/cmp_null.stderr | 1 + tests/ui/cmp_owned/asymmetric_partial_eq.stderr | 1 + tests/ui/cmp_owned/comparison_flip.stderr | 1 + tests/ui/cmp_owned/with_suggestion.stderr | 1 + tests/ui/cmp_owned/without_suggestion.stderr | 1 + tests/ui/cognitive_complexity.stderr | 1 + tests/ui/cognitive_complexity_attr_used.stderr | 1 + tests/ui/collapsible_else_if.stderr | 1 + tests/ui/collapsible_if.stderr | 1 + tests/ui/collapsible_match.stderr | 1 + tests/ui/collapsible_match2.stderr | 1 + tests/ui/collapsible_str_replace.stderr | 1 + tests/ui/collection_is_never_read.stderr | 1 + tests/ui/comparison_chain.stderr | 1 + tests/ui/comparison_to_empty.stderr | 1 + tests/ui/const_comparisons.stderr | 2 ++ tests/ui/copy_iterator.stderr | 1 + tests/ui/crashes/ice-10148.stderr | 1 + tests/ui/crashes/ice-10645.stderr | 1 + tests/ui/crashes/ice-10912.stderr | 1 + tests/ui/crashes/ice-2774.stderr | 1 + tests/ui/crashes/ice-360.stderr | 2 ++ tests/ui/crashes/ice-3969.stderr | 1 + tests/ui/crashes/ice-5835.stderr | 1 + tests/ui/crashes/ice-5872.stderr | 1 + tests/ui/crashes/ice-6254.stderr | 1 + tests/ui/crashes/ice-7169.stderr | 1 + tests/ui/crashes/ice-7868.stderr | 1 + tests/ui/crashes/ice-7869.stderr | 1 + tests/ui/crashes/ice-8250.stderr | 1 + tests/ui/crashes/ice-8821.stderr | 1 + tests/ui/crashes/ice-8850.stderr | 1 + tests/ui/crashes/ice-9041.stderr | 1 + tests/ui/crashes/ice-9445.stderr | 1 + .../ui/crashes/needless_pass_by_value-w-late-bound.stderr | 1 + tests/ui/crate_in_macro_def.stderr | 1 + tests/ui/crate_level_checks/no_std_swap.stderr | 1 + tests/ui/crate_level_checks/std_main_recursion.stderr | 1 + tests/ui/create_dir.stderr | 1 + tests/ui/dbg_macro.stderr | 1 + tests/ui/debug_assert_with_mut_call.stderr | 1 + tests/ui/decimal_literal_representation.stderr | 1 + tests/ui/declare_interior_mutable_const/enums.stderr | 1 + tests/ui/declare_interior_mutable_const/others.stderr | 1 + tests/ui/declare_interior_mutable_const/traits.stderr | 1 + tests/ui/def_id_nocore.stderr | 1 + tests/ui/default_constructed_unit_structs.stderr | 1 + tests/ui/default_instead_of_iter_empty.stderr | 1 + tests/ui/default_numeric_fallback_f64.stderr | 1 + tests/ui/default_numeric_fallback_i32.stderr | 1 + tests/ui/default_union_representation.stderr | 1 + tests/ui/deprecated.stderr | 1 + tests/ui/deprecated_old.stderr | 1 + tests/ui/deref_addrof.stderr | 1 + tests/ui/deref_addrof_double_trigger.stderr | 1 + tests/ui/deref_by_slicing.stderr | 1 + tests/ui/derivable_impls.stderr | 1 + tests/ui/derive.stderr | 1 + tests/ui/derive_ord_xor_partial_ord.stderr | 1 + tests/ui/derive_partial_eq_without_eq.stderr | 1 + tests/ui/disallowed_names.stderr | 1 + tests/ui/diverging_sub_expression.stderr | 1 + tests/ui/doc/doc-fixable.stderr | 1 + tests/ui/doc/unbalanced_ticks.stderr | 1 + tests/ui/doc_errors.stderr | 1 + tests/ui/doc_link_with_quotes.stderr | 1 + tests/ui/doc_unsafe.stderr | 1 + tests/ui/double_comparison.stderr | 1 + tests/ui/double_must_use.stderr | 1 + tests/ui/double_neg.stderr | 1 + tests/ui/double_parens.stderr | 1 + tests/ui/drop_non_drop.stderr | 1 + tests/ui/duplicate_underscore_argument.stderr | 1 + tests/ui/duration_subsec.stderr | 1 + tests/ui/else_if_without_else.stderr | 1 + tests/ui/empty_drop.stderr | 1 + tests/ui/empty_enum.stderr | 1 + tests/ui/empty_line_after_doc_comments.stderr | 1 + tests/ui/empty_line_after_outer_attribute.stderr | 1 + tests/ui/empty_loop.stderr | 1 + tests/ui/empty_loop_no_std.stderr | 1 + tests/ui/empty_structs_with_brackets.stderr | 1 + tests/ui/endian_bytes.stderr | 3 +++ tests/ui/entry.stderr | 1 + tests/ui/entry_btree.stderr | 1 + tests/ui/entry_with_else.stderr | 1 + tests/ui/enum_glob_use.stderr | 1 + tests/ui/enum_variants.stderr | 1 + tests/ui/eprint_with_newline.stderr | 1 + tests/ui/eq_op.stderr | 1 + tests/ui/eq_op_macros.stderr | 1 + tests/ui/equatable_if_let.stderr | 1 + tests/ui/erasing_op.stderr | 1 + tests/ui/err_expect.stderr | 1 + tests/ui/error_impl_error.stderr | 1 + tests/ui/eta.stderr | 2 ++ tests/ui/excessive_precision.stderr | 1 + tests/ui/exit1.stderr | 1 + tests/ui/exit2.stderr | 1 + tests/ui/expect.stderr | 1 + tests/ui/expect_fun_call.stderr | 1 + tests/ui/expect_tool_lint_rfc_2383.stderr | 1 + tests/ui/explicit_auto_deref.stderr | 1 + tests/ui/explicit_counter_loop.stderr | 1 + tests/ui/explicit_deref_methods.stderr | 1 + tests/ui/explicit_into_iter_loop.stderr | 1 + tests/ui/explicit_iter_loop.stderr | 1 + tests/ui/explicit_write.stderr | 1 + tests/ui/extend_with_drain.stderr | 1 + tests/ui/extra_unused_lifetimes.stderr | 1 + tests/ui/extra_unused_type_parameters.stderr | 1 + tests/ui/extra_unused_type_parameters_unfixable.stderr | 1 + tests/ui/field_reassign_with_default.stderr | 1 + tests/ui/filetype_is_file.stderr | 1 + tests/ui/filter_map_bool_then.stderr | 1 + tests/ui/filter_map_identity.stderr | 1 + tests/ui/filter_map_next.stderr | 1 + tests/ui/filter_map_next_fixable.stderr | 1 + tests/ui/flat_map_identity.stderr | 1 + tests/ui/flat_map_option.stderr | 1 + tests/ui/float_arithmetic.stderr | 1 + tests/ui/float_cmp.stderr | 1 + tests/ui/float_cmp_const.stderr | 1 + tests/ui/float_equality_without_abs.stderr | 1 + tests/ui/floating_point_abs.stderr | 1 + tests/ui/floating_point_exp.stderr | 1 + tests/ui/floating_point_hypot.stderr | 1 + tests/ui/floating_point_log.stderr | 2 ++ tests/ui/floating_point_logbase.stderr | 1 + tests/ui/floating_point_mul_add.stderr | 1 + tests/ui/floating_point_powf.stderr | 2 ++ tests/ui/floating_point_powi.stderr | 1 + tests/ui/floating_point_rad.stderr | 1 + tests/ui/fn_address_comparisons.stderr | 1 + tests/ui/fn_params_excessive_bools.stderr | 1 + tests/ui/fn_to_numeric_cast.stderr | 2 ++ tests/ui/fn_to_numeric_cast_any.stderr | 1 + tests/ui/for_kv_map.stderr | 1 + tests/ui/forget_non_drop.stderr | 1 + tests/ui/format.stderr | 1 + tests/ui/format_args.stderr | 1 + tests/ui/format_args_unfixable.stderr | 1 + tests/ui/format_collect.stderr | 1 + tests/ui/format_push_string.stderr | 1 + tests/ui/formatting.stderr | 2 ++ tests/ui/four_forward_slashes.stderr | 1 + tests/ui/four_forward_slashes_first_line.stderr | 1 + tests/ui/from_iter_instead_of_collect.stderr | 1 + tests/ui/from_over_into.stderr | 1 + tests/ui/from_over_into_unfixable.stderr | 1 + tests/ui/from_raw_with_void_ptr.stderr | 1 + tests/ui/from_str_radix_10.stderr | 1 + tests/ui/functions.stderr | 2 ++ tests/ui/functions_maxlines.stderr | 1 + tests/ui/future_not_send.stderr | 1 + tests/ui/get_first.stderr | 1 + tests/ui/get_last_with_len.stderr | 1 + tests/ui/get_unwrap.stderr | 1 + tests/ui/identity_op.stderr | 1 + tests/ui/if_let_mutex.stderr | 1 + tests/ui/if_not_else.stderr | 1 + tests/ui/if_same_then_else.stderr | 1 + tests/ui/if_same_then_else2.stderr | 1 + tests/ui/if_then_some_else_none.stderr | 1 + tests/ui/ifs_same_cond.stderr | 1 + tests/ui/ignored_unit_patterns.stderr | 1 + tests/ui/impl.stderr | 1 + tests/ui/impl_trait_in_params.stderr | 1 + tests/ui/implicit_clone.stderr | 1 + tests/ui/implicit_return.stderr | 1 + tests/ui/implicit_saturating_add.stderr | 1 + tests/ui/implicit_saturating_sub.stderr | 1 + tests/ui/implied_bounds_in_impls.stderr | 1 + tests/ui/inconsistent_digit_grouping.stderr | 1 + tests/ui/inconsistent_struct_constructor.stderr | 1 + tests/ui/indexing_slicing_index.stderr | 1 + tests/ui/indexing_slicing_slice.stderr | 2 ++ tests/ui/infallible_destructuring_match.stderr | 1 + tests/ui/infinite_loop.stderr | 1 + tests/ui/inherent_to_string.stderr | 1 + tests/ui/inline_fn_without_body.stderr | 1 + tests/ui/inspect_for_each.stderr | 1 + tests/ui/int_plus_one.stderr | 1 + tests/ui/integer_division.stderr | 1 + tests/ui/into_iter_on_ref.stderr | 1 + tests/ui/invalid_upcast_comparisons.stderr | 1 + tests/ui/is_digit_ascii_radix.stderr | 1 + tests/ui/issue-7447.stderr | 1 + tests/ui/issue_4266.stderr | 2 ++ tests/ui/items_after_statement.stderr | 1 + tests/ui/iter_cloned_collect.stderr | 1 + tests/ui/iter_count.stderr | 1 + tests/ui/iter_kv_map.stderr | 1 + tests/ui/iter_next_slice.stderr | 1 + tests/ui/iter_not_returning_iterator.stderr | 1 + tests/ui/iter_nth.stderr | 1 + tests/ui/iter_nth_zero.stderr | 1 + tests/ui/iter_on_empty_collections.stderr | 1 + tests/ui/iter_on_single_items.stderr | 1 + tests/ui/iter_overeager_cloned.stderr | 2 ++ tests/ui/iter_skip_next.stderr | 1 + tests/ui/iter_skip_next_unfixable.stderr | 1 + tests/ui/iter_skip_zero.stderr | 1 + tests/ui/iter_with_drain.stderr | 1 + tests/ui/iterator_step_by_zero.stderr | 1 + tests/ui/large_const_arrays.stderr | 1 + tests/ui/large_digit_groups.stderr | 2 ++ tests/ui/large_enum_variant.stderr | 1 + tests/ui/large_futures.stderr | 1 + tests/ui/large_stack_arrays.stderr | 1 + tests/ui/large_stack_frames.stderr | 1 + tests/ui/large_types_passed_by_value.stderr | 1 + tests/ui/len_without_is_empty.stderr | 2 ++ tests/ui/len_zero.stderr | 2 ++ tests/ui/len_zero_ranges.stderr | 1 + tests/ui/let_and_return.stderr | 1 + tests/ui/let_if_seq.stderr | 1 + tests/ui/let_underscore_future.stderr | 2 ++ tests/ui/let_underscore_lock.stderr | 1 + tests/ui/let_underscore_must_use.stderr | 1 + tests/ui/let_underscore_untyped.stderr | 1 + tests/ui/let_unit.stderr | 1 + tests/ui/let_with_type_underscore.stderr | 1 + tests/ui/lines_filter_map_ok.stderr | 1 + tests/ui/linkedlist.stderr | 1 + tests/ui/literals.stderr | 6 ++++++ tests/ui/lossy_float_literal.stderr | 1 + tests/ui/macro_use_imports.stderr | 1 + tests/ui/manual_assert.edition2018.stderr | 1 + tests/ui/manual_assert.edition2021.stderr | 1 + tests/ui/manual_async_fn.stderr | 1 + tests/ui/manual_bits.stderr | 1 + tests/ui/manual_clamp.stderr | 1 + tests/ui/manual_filter.stderr | 1 + tests/ui/manual_filter_map.stderr | 2 ++ tests/ui/manual_find.stderr | 1 + tests/ui/manual_find_fixable.stderr | 1 + tests/ui/manual_find_map.stderr | 1 + tests/ui/manual_flatten.stderr | 1 + tests/ui/manual_float_methods.stderr | 2 ++ tests/ui/manual_instant_elapsed.stderr | 1 + tests/ui/manual_is_ascii_check.stderr | 1 + tests/ui/manual_let_else.stderr | 1 + tests/ui/manual_let_else_match.stderr | 1 + tests/ui/manual_let_else_question_mark.stderr | 2 ++ tests/ui/manual_main_separator_str.stderr | 1 + tests/ui/manual_map_option.stderr | 1 + tests/ui/manual_map_option_2.stderr | 1 + tests/ui/manual_memcpy/with_loop_counters.stderr | 1 + tests/ui/manual_memcpy/without_loop_counters.stderr | 1 + tests/ui/manual_next_back.stderr | 1 + tests/ui/manual_non_exhaustive_enum.stderr | 1 + tests/ui/manual_non_exhaustive_struct.stderr | 1 + tests/ui/manual_ok_or.stderr | 1 + tests/ui/manual_range_patterns.stderr | 1 + tests/ui/manual_rem_euclid.stderr | 1 + tests/ui/manual_retain.stderr | 1 + tests/ui/manual_saturating_arithmetic.stderr | 1 + tests/ui/manual_slice_size_calculation.stderr | 1 + tests/ui/manual_split_once.stderr | 1 + tests/ui/manual_str_repeat.stderr | 1 + tests/ui/manual_string_new.stderr | 1 + tests/ui/manual_strip.stderr | 1 + tests/ui/manual_try_fold.stderr | 1 + tests/ui/manual_unwrap_or.stderr | 1 + tests/ui/manual_while_let_some.stderr | 1 + tests/ui/many_single_char_names.stderr | 1 + tests/ui/map_clone.stderr | 1 + tests/ui/map_collect_result_unit.stderr | 1 + tests/ui/map_err.stderr | 1 + tests/ui/map_flatten.stderr | 1 + tests/ui/map_flatten_fixable.stderr | 1 + tests/ui/map_identity.stderr | 1 + tests/ui/map_unwrap_or.stderr | 1 + tests/ui/map_unwrap_or_fixable.stderr | 1 + tests/ui/match_as_ref.stderr | 1 + tests/ui/match_bool.stderr | 1 + tests/ui/match_expr_like_matches_macro.stderr | 2 ++ tests/ui/match_on_vec_items.stderr | 1 + tests/ui/match_overlapping_arm.stderr | 1 + tests/ui/match_ref_pats.stderr | 2 ++ tests/ui/match_result_ok.stderr | 1 + tests/ui/match_same_arms.stderr | 1 + tests/ui/match_same_arms2.stderr | 2 ++ tests/ui/match_same_arms_non_exhaustive.stderr | 1 + tests/ui/match_single_binding.stderr | 1 + tests/ui/match_single_binding2.stderr | 1 + tests/ui/match_str_case_mismatch.stderr | 1 + tests/ui/match_wild_err_arm.stderr | 1 + tests/ui/match_wildcard_for_single_variants.stderr | 1 + tests/ui/mem_forget.stderr | 1 + tests/ui/mem_replace.stderr | 2 ++ tests/ui/mem_replace_macro.stderr | 1 + tests/ui/methods.stderr | 2 ++ tests/ui/methods_fixable.stderr | 1 + tests/ui/methods_unfixable.stderr | 1 + tests/ui/min_ident_chars.stderr | 1 + tests/ui/min_max.stderr | 1 + tests/ui/mismatched_target_os_non_unix.stderr | 1 + tests/ui/mismatched_target_os_unix.stderr | 1 + tests/ui/mismatching_type_param_order.stderr | 1 + tests/ui/misnamed_getters.stderr | 1 + tests/ui/missing_assert_message.stderr | 1 + tests/ui/missing_const_for_fn/could_be_const.stderr | 1 + tests/ui/missing_doc.stderr | 1 + tests/ui/missing_doc_crate_missing.stderr | 1 + tests/ui/missing_doc_impl.stderr | 1 + tests/ui/missing_fields_in_debug.stderr | 1 + tests/ui/missing_inline.stderr | 1 + tests/ui/missing_panics_doc.stderr | 1 + tests/ui/missing_spin_loop.stderr | 1 + tests/ui/missing_spin_loop_no_std.stderr | 1 + tests/ui/missing_trait_methods.stderr | 1 + tests/ui/mixed_read_write_in_expression.stderr | 1 + tests/ui/module_inception.stderr | 1 + tests/ui/module_name_repetitions.stderr | 1 + tests/ui/modulo_arithmetic_float.stderr | 1 + tests/ui/modulo_arithmetic_integral.stderr | 1 + tests/ui/modulo_arithmetic_integral_const.stderr | 1 + tests/ui/modulo_one.stderr | 1 + tests/ui/multi_assignments.stderr | 1 + tests/ui/multiple_unsafe_ops_per_block.stderr | 1 + tests/ui/must_use_candidates.stderr | 1 + tests/ui/must_use_unit.stderr | 1 + tests/ui/mut_from_ref.stderr | 1 + tests/ui/mut_key.stderr | 2 ++ tests/ui/mut_mut.stderr | 1 + tests/ui/mut_mutex_lock.stderr | 1 + tests/ui/mut_range_bound.stderr | 1 + tests/ui/mut_reference.stderr | 2 ++ tests/ui/mutex_atomic.stderr | 2 ++ tests/ui/needless_arbitrary_self_type.stderr | 1 + tests/ui/needless_arbitrary_self_type_unfixable.stderr | 1 + tests/ui/needless_bitwise_bool.stderr | 1 + tests/ui/needless_bool/fixable.stderr | 2 ++ tests/ui/needless_bool/simple.stderr | 1 + tests/ui/needless_bool_assign.stderr | 1 + tests/ui/needless_borrow.stderr | 1 + tests/ui/needless_borrow_pat.stderr | 1 + tests/ui/needless_borrowed_ref.stderr | 1 + tests/ui/needless_collect.stderr | 1 + tests/ui/needless_collect_indirect.stderr | 1 + tests/ui/needless_continue.stderr | 1 + tests/ui/needless_doc_main.stderr | 1 + tests/ui/needless_else.stderr | 1 + tests/ui/needless_for_each_fixable.stderr | 1 + tests/ui/needless_for_each_unfixable.stderr | 1 + tests/ui/needless_if.stderr | 1 + tests/ui/needless_late_init.stderr | 1 + tests/ui/needless_lifetimes.stderr | 1 + tests/ui/needless_match.stderr | 1 + tests/ui/needless_option_as_deref.stderr | 1 + tests/ui/needless_option_take.stderr | 1 + tests/ui/needless_parens_on_range_literals.stderr | 1 + tests/ui/needless_pass_by_ref_mut.stderr | 1 + tests/ui/needless_pass_by_value.stderr | 1 + tests/ui/needless_pub_self.stderr | 1 + tests/ui/needless_question_mark.stderr | 1 + tests/ui/needless_range_loop.stderr | 1 + tests/ui/needless_range_loop2.stderr | 1 + tests/ui/needless_raw_string.stderr | 1 + tests/ui/needless_raw_string_hashes.stderr | 1 + tests/ui/needless_return.stderr | 1 + tests/ui/needless_return_with_question_mark.stderr | 1 + tests/ui/needless_splitn.stderr | 1 + tests/ui/needless_update.stderr | 1 + tests/ui/neg_cmp_op_on_partial_ord.stderr | 1 + tests/ui/neg_multiply.stderr | 1 + tests/ui/never_loop.stderr | 1 + tests/ui/new_ret_no_self.stderr | 1 + tests/ui/new_without_default.stderr | 1 + tests/ui/no_effect.stderr | 2 ++ tests/ui/no_effect_replace.stderr | 1 + tests/ui/no_effect_return.stderr | 1 + tests/ui/no_mangle_with_rust_abi.stderr | 1 + tests/ui/non_expressive_names.stderr | 1 + tests/ui/non_minimal_cfg.stderr | 1 + tests/ui/non_minimal_cfg2.stderr | 1 + tests/ui/non_octal_unix_permissions.stderr | 1 + tests/ui/non_send_fields_in_send_ty.stderr | 1 + tests/ui/nonminimal_bool.stderr | 1 + tests/ui/nonminimal_bool_methods.stderr | 1 + tests/ui/numbered_fields.stderr | 1 + tests/ui/obfuscated_if_else.stderr | 1 + tests/ui/octal_escapes.stderr | 1 + tests/ui/ok_expect.stderr | 1 + tests/ui/only_used_in_recursion.stderr | 1 + tests/ui/only_used_in_recursion2.stderr | 1 + tests/ui/op_ref.stderr | 1 + tests/ui/open_options.stderr | 1 + tests/ui/option_as_ref_deref.stderr | 1 + tests/ui/option_env_unwrap.stderr | 1 + tests/ui/option_filter_map.stderr | 1 + tests/ui/option_if_let_else.stderr | 1 + tests/ui/option_map_or_none.stderr | 2 ++ tests/ui/option_map_unit_fn_fixable.stderr | 1 + tests/ui/or_fun_call.stderr | 2 ++ tests/ui/or_then_unwrap.stderr | 1 + tests/ui/out_of_bounds_indexing/issue-3102.stderr | 1 + tests/ui/out_of_bounds_indexing/simple.stderr | 1 + tests/ui/overflow_check_conditional.stderr | 1 + tests/ui/overly_complex_bool_expr.stderr | 1 + tests/ui/panic_in_result_fn.stderr | 1 + tests/ui/panic_in_result_fn_assertions.stderr | 1 + tests/ui/panicking_macros.stderr | 4 ++++ tests/ui/partial_pub_fields.stderr | 1 + tests/ui/partialeq_ne_impl.stderr | 1 + tests/ui/partialeq_to_none.stderr | 1 + tests/ui/path_buf_push_overwrite.stderr | 1 + tests/ui/pattern_type_mismatch/mutability.stderr | 1 + tests/ui/pattern_type_mismatch/pattern_alternatives.stderr | 1 + tests/ui/pattern_type_mismatch/pattern_structs.stderr | 1 + tests/ui/pattern_type_mismatch/pattern_tuples.stderr | 1 + tests/ui/pattern_type_mismatch/syntax.stderr | 1 + tests/ui/patterns.stderr | 1 + tests/ui/permissions_set_readonly_false.stderr | 1 + tests/ui/precedence.stderr | 1 + tests/ui/print.stderr | 2 ++ tests/ui/print_in_format_impl.stderr | 1 + tests/ui/print_literal.stderr | 1 + tests/ui/print_stderr.stderr | 1 + tests/ui/print_with_newline.stderr | 1 + tests/ui/println_empty_string.stderr | 1 + tests/ui/ptr_arg.stderr | 1 + tests/ui/ptr_as_ptr.stderr | 1 + tests/ui/ptr_cast_constness.stderr | 1 + tests/ui/ptr_eq.stderr | 1 + tests/ui/ptr_offset_with_cast.stderr | 1 + tests/ui/pub_use.stderr | 1 + tests/ui/pub_with_shorthand.stderr | 1 + tests/ui/pub_without_shorthand.stderr | 1 + tests/ui/question_mark.stderr | 1 + tests/ui/question_mark_used.stderr | 1 + tests/ui/range.stderr | 1 + tests/ui/range_contains.stderr | 1 + tests/ui/range_plus_minus_one.stderr | 2 ++ tests/ui/rc_buffer.stderr | 1 + tests/ui/rc_buffer_arc.stderr | 1 + tests/ui/rc_clone_in_vec_init/arc.stderr | 1 + tests/ui/rc_clone_in_vec_init/rc.stderr | 1 + tests/ui/rc_clone_in_vec_init/weak.stderr | 1 + tests/ui/rc_mutex.stderr | 1 + tests/ui/read_line_without_trim.stderr | 1 + tests/ui/read_zero_byte_vec.stderr | 1 + tests/ui/readonly_write_lock.stderr | 1 + tests/ui/recursive_format_impl.stderr | 1 + tests/ui/redundant_allocation.stderr | 1 + tests/ui/redundant_allocation_fixable.stderr | 1 + tests/ui/redundant_async_block.stderr | 1 + tests/ui/redundant_at_rest_pattern.stderr | 1 + tests/ui/redundant_clone.stderr | 1 + tests/ui/redundant_closure_call_early.stderr | 1 + tests/ui/redundant_closure_call_fixable.stderr | 1 + tests/ui/redundant_closure_call_late.stderr | 1 + tests/ui/redundant_else.stderr | 1 + tests/ui/redundant_field_names.stderr | 1 + tests/ui/redundant_guards.stderr | 1 + tests/ui/redundant_locals.stderr | 1 + tests/ui/redundant_pattern_matching_drop_order.stderr | 1 + tests/ui/redundant_pattern_matching_ipaddr.stderr | 1 + tests/ui/redundant_pattern_matching_option.stderr | 1 + tests/ui/redundant_pattern_matching_poll.stderr | 1 + tests/ui/redundant_pattern_matching_result.stderr | 1 + tests/ui/redundant_pub_crate.stderr | 1 + tests/ui/redundant_slicing.stderr | 1 + tests/ui/redundant_static_lifetimes.stderr | 1 + tests/ui/redundant_static_lifetimes_multiple.stderr | 1 + tests/ui/redundant_type_annotations.stderr | 1 + tests/ui/ref_binding_to_reference.stderr | 1 + tests/ui/ref_option_ref.stderr | 1 + tests/ui/ref_patterns.stderr | 1 + tests/ui/regex.stderr | 2 ++ tests/ui/rename.stderr | 1 + tests/ui/repeat_once.stderr | 1 + tests/ui/repl_uninit.stderr | 1 + tests/ui/reserve_after_initialization.stderr | 1 + tests/ui/rest_pat_in_fully_bound_structs.stderr | 1 + tests/ui/result_large_err.stderr | 1 + tests/ui/result_map_or_into_option.stderr | 1 + tests/ui/result_map_unit_fn_fixable.stderr | 1 + tests/ui/result_map_unit_fn_unfixable.stderr | 1 + tests/ui/result_unit_error.stderr | 1 + tests/ui/return_self_not_must_use.stderr | 1 + tests/ui/reversed_empty_ranges_fixable.stderr | 1 + tests/ui/reversed_empty_ranges_loops_fixable.stderr | 1 + tests/ui/reversed_empty_ranges_loops_unfixable.stderr | 1 + tests/ui/reversed_empty_ranges_unfixable.stderr | 1 + tests/ui/same_item_push.stderr | 1 + tests/ui/same_name_method.stderr | 1 + tests/ui/search_is_some.stderr | 1 + tests/ui/search_is_some_fixable_none.stderr | 1 + tests/ui/search_is_some_fixable_some.stderr | 1 + tests/ui/seek_from_current.stderr | 1 + tests/ui/seek_to_start_instead_of_rewind.stderr | 1 + tests/ui/self_assignment.stderr | 1 + tests/ui/self_named_constructors.stderr | 1 + tests/ui/semicolon_if_nothing_returned.stderr | 1 + tests/ui/semicolon_inside_block.stderr | 1 + tests/ui/semicolon_outside_block.stderr | 1 + tests/ui/serde.stderr | 1 + tests/ui/shadow.stderr | 3 +++ tests/ui/short_circuit_statement.stderr | 1 + tests/ui/should_impl_trait/method_list_1.stderr | 1 + tests/ui/should_impl_trait/method_list_2.stderr | 2 ++ tests/ui/significant_drop_in_scrutinee.stderr | 1 + tests/ui/significant_drop_tightening.stderr | 1 + tests/ui/similar_names.stderr | 1 + tests/ui/single_call_fn.stderr | 1 + tests/ui/single_char_add_str.stderr | 1 + tests/ui/single_char_lifetime_names.stderr | 1 + tests/ui/single_char_pattern.stderr | 1 + tests/ui/single_component_path_imports.stderr | 1 + tests/ui/single_component_path_imports_nested_first.stderr | 1 + tests/ui/single_element_loop.stderr | 1 + tests/ui/single_match.stderr | 1 + tests/ui/single_match_else.stderr | 1 + tests/ui/single_range_in_vec_init.stderr | 1 + tests/ui/size_of_in_element_count/expressions.stderr | 1 + tests/ui/size_of_in_element_count/functions.stderr | 1 + tests/ui/size_of_ref.stderr | 1 + tests/ui/skip_while_next.stderr | 1 + tests/ui/slow_vector_initialization.stderr | 2 ++ tests/ui/stable_sort_primitive.stderr | 1 + tests/ui/starts_ends_with.stderr | 2 ++ tests/ui/std_instead_of_core.stderr | 3 +++ tests/ui/str_to_string.stderr | 1 + tests/ui/string_add.stderr | 2 ++ tests/ui/string_add_assign.stderr | 2 ++ tests/ui/string_extend.stderr | 1 + tests/ui/string_from_utf8_as_bytes.stderr | 1 + tests/ui/string_lit_as_bytes.stderr | 1 + tests/ui/string_lit_chars_any.stderr | 1 + tests/ui/string_slice.stderr | 1 + tests/ui/string_to_string.stderr | 1 + tests/ui/strlen_on_c_strings.stderr | 1 + tests/ui/struct_excessive_bools.stderr | 1 + tests/ui/suspicious_arithmetic_impl.stderr | 2 ++ tests/ui/suspicious_command_arg_space.stderr | 1 + tests/ui/suspicious_doc_comments.stderr | 1 + tests/ui/suspicious_doc_comments_unfixable.stderr | 1 + tests/ui/suspicious_else_formatting.stderr | 1 + tests/ui/suspicious_map.stderr | 1 + tests/ui/suspicious_operation_groupings.stderr | 1 + tests/ui/suspicious_splitn.stderr | 1 + tests/ui/suspicious_to_owned.stderr | 2 ++ tests/ui/suspicious_unary_op_formatting.stderr | 1 + tests/ui/suspicious_xor_used_as_pow.stderr | 1 + tests/ui/swap.stderr | 2 ++ tests/ui/swap_ptr_to_ref.stderr | 1 + tests/ui/swap_ptr_to_ref_unfixable.stderr | 1 + tests/ui/tabs_in_doc_comments.stderr | 1 + tests/ui/temporary_assignment.stderr | 1 + tests/ui/tests_outside_test_module.stderr | 1 + tests/ui/to_digit_is_some.stderr | 1 + tests/ui/toplevel_ref_arg.stderr | 1 + tests/ui/toplevel_ref_arg_non_rustfix.stderr | 1 + tests/ui/trailing_empty_array.stderr | 1 + tests/ui/trailing_zeros.stderr | 1 + tests/ui/transmute.stderr | 7 +++++++ tests/ui/transmute_64bit.stderr | 1 + tests/ui/transmute_collection.stderr | 1 + tests/ui/transmute_float_to_int.stderr | 1 + tests/ui/transmute_int_to_non_zero.stderr | 1 + tests/ui/transmute_null_to_fn.stderr | 1 + tests/ui/transmute_ptr_to_ptr.stderr | 1 + tests/ui/transmute_ptr_to_ref.stderr | 1 + tests/ui/transmute_undefined_repr.stderr | 1 + tests/ui/transmutes_expressible_as_ptr_casts.stderr | 3 +++ tests/ui/transmuting_null.stderr | 1 + tests/ui/trim_split_whitespace.stderr | 1 + tests/ui/tuple_array_conversions.stderr | 1 + tests/ui/type_complexity.stderr | 1 + tests/ui/type_id_on_box.stderr | 1 + tests/ui/types.stderr | 1 + tests/ui/unchecked_duration_subtraction.stderr | 1 + tests/ui/undocumented_unsafe_blocks.stderr | 2 ++ tests/ui/unicode.stderr | 2 ++ tests/ui/uninit_vec.stderr | 1 + tests/ui/uninlined_format_args.stderr | 1 + tests/ui/uninlined_format_args_panic.edition2018.stderr | 1 + tests/ui/uninlined_format_args_panic.edition2021.stderr | 1 + tests/ui/unit_arg.stderr | 1 + tests/ui/unit_arg_empty_blocks.stderr | 1 + tests/ui/unit_cmp.stderr | 1 + tests/ui/unit_hash.stderr | 1 + tests/ui/unit_return_expecting_ord.stderr | 1 + tests/ui/unknown_clippy_lints.stderr | 1 + tests/ui/unnecessary_box_returns.stderr | 1 + tests/ui/unnecessary_cast.stderr | 1 + tests/ui/unnecessary_cast_unfixable.stderr | 1 + tests/ui/unnecessary_clone.stderr | 2 ++ tests/ui/unnecessary_filter_map.stderr | 1 + tests/ui/unnecessary_find_map.stderr | 1 + tests/ui/unnecessary_fold.stderr | 1 + tests/ui/unnecessary_iter_cloned.stderr | 1 + tests/ui/unnecessary_join.stderr | 1 + tests/ui/unnecessary_lazy_eval.stderr | 1 + tests/ui/unnecessary_lazy_eval_unfixable.stderr | 1 + tests/ui/unnecessary_literal_unwrap.stderr | 1 + tests/ui/unnecessary_literal_unwrap_unfixable.stderr | 1 + tests/ui/unnecessary_operation.stderr | 1 + tests/ui/unnecessary_owned_empty_strings.stderr | 1 + tests/ui/unnecessary_safety_comment.stderr | 1 + tests/ui/unnecessary_self_imports.stderr | 1 + tests/ui/unnecessary_sort_by.stderr | 1 + tests/ui/unnecessary_struct_initialization.stderr | 1 + tests/ui/unnecessary_to_owned.stderr | 2 ++ tests/ui/unnecessary_unsafety_doc.stderr | 1 + tests/ui/unnecessary_wraps.stderr | 1 + tests/ui/unneeded_field_pattern.stderr | 1 + tests/ui/unnested_or_patterns.stderr | 1 + tests/ui/unnested_or_patterns2.stderr | 1 + tests/ui/unreadable_literal.stderr | 1 + tests/ui/unsafe_derive_deserialize.stderr | 1 + tests/ui/unsafe_removed_from_name.stderr | 1 + tests/ui/unseparated_prefix_literals.stderr | 1 + tests/ui/unused_async.stderr | 1 + tests/ui/unused_format_specs_unfixable.stderr | 1 + tests/ui/unused_io_amount.stderr | 1 + tests/ui/unused_peekable.stderr | 1 + tests/ui/unused_rounding.stderr | 1 + tests/ui/unused_self.stderr | 1 + tests/ui/unwrap.stderr | 1 + tests/ui/unwrap_expect_used.stderr | 2 ++ tests/ui/unwrap_in_result.stderr | 1 + tests/ui/unwrap_or.stderr | 1 + tests/ui/unwrap_or_else_default.stderr | 1 + tests/ui/upper_case_acronyms.stderr | 1 + tests/ui/use_self.stderr | 1 + tests/ui/use_self_trait.stderr | 1 + tests/ui/used_underscore_binding.stderr | 1 + tests/ui/useless_attribute.stderr | 1 + tests/ui/vec.stderr | 1 + tests/ui/vec_box_sized.stderr | 1 + tests/ui/vec_init_then_push.stderr | 1 + tests/ui/vec_resize_to_zero.stderr | 1 + tests/ui/verbose_file_reads.stderr | 1 + tests/ui/vtable_address_comparisons.stderr | 1 + tests/ui/while_let_loop.stderr | 1 + tests/ui/while_let_on_iterator.stderr | 1 + tests/ui/wild_in_or_pats.stderr | 1 + tests/ui/wildcard_imports.stderr | 1 + tests/ui/wildcard_imports_2021.edition2018.stderr | 1 + tests/ui/wildcard_imports_2021.edition2021.stderr | 1 + tests/ui/write_literal.stderr | 1 + tests/ui/write_literal_2.stderr | 2 ++ tests/ui/write_with_newline.stderr | 1 + tests/ui/writeln_empty_string.stderr | 1 + tests/ui/wrong_self_convention.stderr | 1 + tests/ui/wrong_self_convention2.stderr | 1 + tests/ui/wrong_self_conventions_mut.stderr | 1 + tests/ui/zero_div_zero.stderr | 1 + tests/ui/zero_ptr.stderr | 1 + tests/ui/zero_sized_btreemap_values.stderr | 1 + tests/ui/zero_sized_hashmap_values.stderr | 1 + 751 files changed, 838 insertions(+) diff --git a/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr b/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr index a8900da4e6eb..99f08d947278 100644 --- a/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr +++ b/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr @@ -5,6 +5,7 @@ LL | std::f32::MAX; | ^^^^^^^^^^^^^ | = note: `-D clippy::absolute-paths` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::absolute_paths)]` error: consider bringing this path into scope with the `use` keyword --> $DIR/absolute_paths.rs:41:5 diff --git a/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr b/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr index 41b70644be8c..017ba4cc24f1 100644 --- a/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr +++ b/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr @@ -5,6 +5,7 @@ LL | std::f32::MAX; | ^^^^^^^^^^^^^ | = note: `-D clippy::absolute-paths` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::absolute_paths)]` error: consider bringing this path into scope with the `use` keyword --> $DIR/absolute_paths.rs:41:5 diff --git a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr index c5912b7af9e5..b754f67edfb6 100644 --- a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr +++ b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr @@ -5,6 +5,7 @@ LL | println!("val='{}'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::uninlined-format-args` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::uninlined_format_args)]` help: change this to | LL - println!("val='{}'", local_i32); @@ -30,6 +31,7 @@ LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64); | ^^^ | = note: `-D clippy::print-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_literal)]` help: try | LL - println!("Hello {} is {:.*}", "x", local_i32, local_f64); diff --git a/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr b/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr index 4f98ca192311..5e8d26e07413 100644 --- a/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr +++ b/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr @@ -5,6 +5,7 @@ LL | let _ = Baz + Baz; | ^^^^^^^^^ | = note: `-D clippy::arithmetic-side-effects` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]` error: arithmetic operation that can potentially result in unexpected side-effects --> $DIR/arithmetic_side_effects_allowed.rs:80:13 diff --git a/tests/ui-toml/array_size_threshold/array_size_threshold.stderr b/tests/ui-toml/array_size_threshold/array_size_threshold.stderr index ac017b20916d..cf70b3c5cfcd 100644 --- a/tests/ui-toml/array_size_threshold/array_size_threshold.stderr +++ b/tests/ui-toml/array_size_threshold/array_size_threshold.stderr @@ -7,6 +7,7 @@ LL | const ABOVE: [u8; 11] = [0; 11]; | help: make this a static item: `static` | = note: `-D clippy::large-const-arrays` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_const_arrays)]` error: allocating a local array larger than 10 bytes --> $DIR/array_size_threshold.rs:4:25 @@ -16,6 +17,7 @@ LL | const ABOVE: [u8; 11] = [0; 11]; | = help: consider allocating on the heap with `vec![0; 11].into_boxed_slice()` = note: `-D clippy::large-stack-arrays` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_stack_arrays)]` error: allocating a local array larger than 10 bytes --> $DIR/array_size_threshold.rs:8:17 diff --git a/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr b/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr index 825aa1487e7a..6f8b04fd12b9 100644 --- a/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr +++ b/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr @@ -6,6 +6,7 @@ LL | let _x = String::from("hello"); | = note: strings are bad (from clippy.toml) = note: `-D clippy::await-holding-invalid-type` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::await_holding_invalid_type)]` error: `std::net::Ipv4Addr` may not be held across an `await` point per `clippy.toml` --> $DIR/await_holding_invalid_type.rs:10:9 diff --git a/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr index 89d84eb24556..a21952c0e7ad 100644 --- a/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr +++ b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr @@ -18,6 +18,7 @@ LL | fn cognitive_complexity() { | = help: you could split it up into multiple smaller functions = note: `-D clippy::cognitive-complexity` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cognitive_complexity)]` error: aborting due to previous error; 2 warnings emitted diff --git a/tests/ui-toml/dbg_macro/dbg_macro.stderr b/tests/ui-toml/dbg_macro/dbg_macro.stderr index 859383a71194..3a66f701e4df 100644 --- a/tests/ui-toml/dbg_macro/dbg_macro.stderr +++ b/tests/ui-toml/dbg_macro/dbg_macro.stderr @@ -5,6 +5,7 @@ LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } | ^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::dbg-macro` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::dbg_macro)]` help: remove the invocation before committing it to a version control system | LL | if let Some(n) = n.checked_sub(4) { n } else { n } diff --git a/tests/ui-toml/disallowed_macros/disallowed_macros.stderr b/tests/ui-toml/disallowed_macros/disallowed_macros.stderr index aed9feb6f796..0eebd587a5f1 100644 --- a/tests/ui-toml/disallowed_macros/disallowed_macros.stderr +++ b/tests/ui-toml/disallowed_macros/disallowed_macros.stderr @@ -5,6 +5,7 @@ LL | println!("one"); | ^^^^^^^^^^^^^^^ | = note: `-D clippy::disallowed-macros` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_macros)]` error: use of a disallowed macro `std::println` --> $DIR/disallowed_macros.rs:11:5 diff --git a/tests/ui-toml/disallowed_names_append/disallowed_names.stderr b/tests/ui-toml/disallowed_names_append/disallowed_names.stderr index 23c3e96a8d08..51cbe1abf599 100644 --- a/tests/ui-toml/disallowed_names_append/disallowed_names.stderr +++ b/tests/ui-toml/disallowed_names_append/disallowed_names.stderr @@ -5,6 +5,7 @@ LL | let foo = "bar"; | ^^^ | = note: `-D clippy::disallowed-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_names)]` error: use of a disallowed/placeholder name `ducks` --> $DIR/disallowed_names.rs:7:9 diff --git a/tests/ui-toml/disallowed_names_replace/disallowed_names.stderr b/tests/ui-toml/disallowed_names_replace/disallowed_names.stderr index d961fa34074b..d9f25a3eee50 100644 --- a/tests/ui-toml/disallowed_names_replace/disallowed_names.stderr +++ b/tests/ui-toml/disallowed_names_replace/disallowed_names.stderr @@ -5,6 +5,7 @@ LL | let ducks = ["quack", "quack"]; | ^^^^^ | = note: `-D clippy::disallowed-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_names)]` error: aborting due to previous error diff --git a/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr b/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr index 0f767c9b8559..92b0350581d3 100644 --- a/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr +++ b/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr @@ -5,6 +5,7 @@ LL | /// TestItemThingyOfCoolness might sound cool but is not on the list and sh | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::doc-markdown` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | LL | /// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. diff --git a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr index e0613eb863b3..6567b5f1275d 100644 --- a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr +++ b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr @@ -5,6 +5,7 @@ LL | /// OAuth and LaTeX are inside Clippy's default list. | ^^^^^ | = note: `-D clippy::doc-markdown` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | LL | /// `OAuth` and LaTeX are inside Clippy's default list. diff --git a/tests/ui-toml/excessive_nesting/excessive_nesting.stderr b/tests/ui-toml/excessive_nesting/excessive_nesting.stderr index 1a7311b33e86..74be5b2e2b92 100644 --- a/tests/ui-toml/excessive_nesting/excessive_nesting.stderr +++ b/tests/ui-toml/excessive_nesting/excessive_nesting.stderr @@ -6,6 +6,7 @@ LL | let w = { 3 }; | = help: try refactoring your code to minimize nesting = note: `-D clippy::excessive-nesting` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::excessive_nesting)]` error: this block is too nested --> $DIR/excessive_nesting.rs:67:17 diff --git a/tests/ui-toml/expect_used/expect_used.stderr b/tests/ui-toml/expect_used/expect_used.stderr index 815d009350f3..13b6d7ff9cd4 100644 --- a/tests/ui-toml/expect_used/expect_used.stderr +++ b/tests/ui-toml/expect_used/expect_used.stderr @@ -6,6 +6,7 @@ LL | let _ = opt.expect(""); | = note: if this value is `None`, it will panic = note: `-D clippy::expect-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::expect_used)]` error: used `expect()` on a `Result` value --> $DIR/expect_used.rs:12:13 diff --git a/tests/ui-toml/fn_params_excessive_bools/test.stderr b/tests/ui-toml/fn_params_excessive_bools/test.stderr index 87bdb61c6a5e..717a4bbfbfe1 100644 --- a/tests/ui-toml/fn_params_excessive_bools/test.stderr +++ b/tests/ui-toml/fn_params_excessive_bools/test.stderr @@ -6,6 +6,7 @@ LL | fn g(_: bool, _: bool) {} | = help: consider refactoring bools into two-variant enums = note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::fn_params_excessive_bools)]` error: aborting due to previous error diff --git a/tests/ui-toml/functions_maxlines/test.stderr b/tests/ui-toml/functions_maxlines/test.stderr index dc255bdcabaf..a2ca623e9662 100644 --- a/tests/ui-toml/functions_maxlines/test.stderr +++ b/tests/ui-toml/functions_maxlines/test.stderr @@ -8,6 +8,7 @@ LL | | } | |_^ | = note: `-D clippy::too-many-lines` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::too_many_lines)]` error: this function has too many lines (4/1) --> $DIR/test.rs:25:1 diff --git a/tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr b/tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr index 2841f62bc94a..305e00af27e5 100644 --- a/tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr +++ b/tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr @@ -10,6 +10,7 @@ note: same as this LL | if x.get() { | ^^^^^^^ = note: `-D clippy::ifs-same-cond` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ifs_same_cond)]` error: aborting due to previous error diff --git a/tests/ui-toml/large_futures/large_futures.stderr b/tests/ui-toml/large_futures/large_futures.stderr index b92734de2f08..7a02fcdbdd2f 100644 --- a/tests/ui-toml/large_futures/large_futures.stderr +++ b/tests/ui-toml/large_futures/large_futures.stderr @@ -5,6 +5,7 @@ LL | should_warn().await; | ^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(should_warn())` | = note: `-D clippy::large-futures` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_futures)]` error: aborting due to previous error diff --git a/tests/ui-toml/large_include_file/large_include_file.stderr b/tests/ui-toml/large_include_file/large_include_file.stderr index 7b5fb9e87659..7508cd6c46e2 100644 --- a/tests/ui-toml/large_include_file/large_include_file.stderr +++ b/tests/ui-toml/large_include_file/large_include_file.stderr @@ -6,6 +6,7 @@ LL | const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt"); | = note: the configuration allows a maximum size of 600 bytes = note: `-D clippy::large-include-file` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_include_file)]` = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info) error: attempted to include a large file diff --git a/tests/ui-toml/lint_decimal_readability/test.stderr b/tests/ui-toml/lint_decimal_readability/test.stderr index ac9d89d0cbee..ef97e5d3f312 100644 --- a/tests/ui-toml/lint_decimal_readability/test.stderr +++ b/tests/ui-toml/lint_decimal_readability/test.stderr @@ -5,6 +5,7 @@ LL | let _fail1 = 100_200_300.123456789; | ^^^^^^^^^^^^^^^^^^^^^ help: consider: `100_200_300.123_456_789` | = note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inconsistent_digit_grouping)]` error: long literal lacking separators --> $DIR/test.rs:22:18 @@ -13,6 +14,7 @@ LL | let _fail2 = 100200300.300200100; | ^^^^^^^^^^^^^^^^^^^ help: consider: `100_200_300.300_200_100` | = note: `-D clippy::unreadable-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unreadable_literal)]` error: aborting due to 2 previous errors diff --git a/tests/ui-toml/min_ident_chars/min_ident_chars.stderr b/tests/ui-toml/min_ident_chars/min_ident_chars.stderr index d9a27628ddb2..7f00fac49243 100644 --- a/tests/ui-toml/min_ident_chars/min_ident_chars.stderr +++ b/tests/ui-toml/min_ident_chars/min_ident_chars.stderr @@ -5,6 +5,7 @@ LL | use extern_types::Aaa; | ^^^ | = note: `-D clippy::min-ident-chars` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::min_ident_chars)]` error: this ident is too short (3 <= 3) --> $DIR/min_ident_chars.rs:10:5 diff --git a/tests/ui-toml/min_rust_version/min_rust_version.stderr b/tests/ui-toml/min_rust_version/min_rust_version.stderr index 5dae5af7eb5a..5b1f8dbd3eab 100644 --- a/tests/ui-toml/min_rust_version/min_rust_version.stderr +++ b/tests/ui-toml/min_rust_version/min_rust_version.stderr @@ -5,6 +5,7 @@ LL | let _: Option = Some(&16).map(|b| *b); | ^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `Some(&16).cloned()` | = note: `-D clippy::map-clone` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_clone)]` error: aborting due to previous error diff --git a/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr b/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr index 45de8fdffef7..0aea330d40bb 100644 --- a/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr +++ b/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr @@ -5,6 +5,7 @@ LL | use std::process::{exit as wrong_exit, Child as Kid}; | ^^^^^^^^^^^^^^^^^^ help: try: `exit as goodbye` | = note: `-D clippy::missing-enforced-import-renames` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_enforced_import_renames)]` error: this import should be renamed --> $DIR/conf_missing_enforced_import_rename.rs:6:1 diff --git a/tests/ui-toml/module_inception/module_inception.stderr b/tests/ui-toml/module_inception/module_inception.stderr index a5a09c322e13..0eb25453b256 100644 --- a/tests/ui-toml/module_inception/module_inception.stderr +++ b/tests/ui-toml/module_inception/module_inception.stderr @@ -7,6 +7,7 @@ LL | | } | |_________^ | = note: `-D clippy::module-inception` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::module_inception)]` error: module has the same name as its containing module --> $DIR/module_inception.rs:11:5 diff --git a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr index cfff1fffe80a..483941d3c312 100644 --- a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr +++ b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr @@ -5,6 +5,7 @@ LL | let _ = vec! {1, 2, 3}; | ^^^^^^^^^^^^^^ help: consider writing: `vec![1, 2, 3]` | = note: `-D clippy::nonstandard-macro-braces` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::nonstandard_macro_braces)]` error: use of irregular braces for `format!` macro --> $DIR/conf_nonstandard_macro_braces.rs:44:13 diff --git a/tests/ui-toml/print_macro/print_macro.stderr b/tests/ui-toml/print_macro/print_macro.stderr index d4b1ae84fd7d..fe2d5afc6caa 100644 --- a/tests/ui-toml/print_macro/print_macro.stderr +++ b/tests/ui-toml/print_macro/print_macro.stderr @@ -5,6 +5,7 @@ LL | print!("{n}"); | ^^^^^^^^^^^^^ | = note: `-D clippy::print-stdout` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_stdout)]` error: use of `eprint!` --> $DIR/print_macro.rs:7:5 @@ -13,6 +14,7 @@ LL | eprint!("{n}"); | ^^^^^^^^^^^^^^ | = note: `-D clippy::print-stderr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_stderr)]` error: aborting due to 2 previous errors diff --git a/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr b/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr index a474187050c1..1ecdabbc03e6 100644 --- a/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr +++ b/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr @@ -5,6 +5,7 @@ LL | pub(crate) fn crate_no_docs() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]` error: missing documentation for a function --> $DIR/pub_crate_missing_doc.rs:15:5 diff --git a/tests/ui-toml/semicolon_block/both.stderr b/tests/ui-toml/semicolon_block/both.stderr index 49b580674672..ca6a7475cf37 100644 --- a/tests/ui-toml/semicolon_block/both.stderr +++ b/tests/ui-toml/semicolon_block/both.stderr @@ -5,6 +5,7 @@ LL | { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::semicolon-outside-block` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::semicolon_outside_block)]` help: put the `;` here | LL - { unit_fn_block(); } @@ -33,6 +34,7 @@ LL | | }; | |______^ | = note: `-D clippy::semicolon-inside-block` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::semicolon_inside_block)]` help: put the `;` here | LL ~ unit_fn_block(); diff --git a/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr b/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr index 13ba9750f4b8..ce03d7d75a26 100644 --- a/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr +++ b/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr @@ -8,6 +8,7 @@ LL | | }; | |______^ | = note: `-D clippy::semicolon-inside-block` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::semicolon_inside_block)]` help: put the `;` here | LL ~ unit_fn_block(); diff --git a/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr b/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr index 3c619ebe73d1..fcc409796e2d 100644 --- a/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr +++ b/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr @@ -5,6 +5,7 @@ LL | { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::semicolon-outside-block` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::semicolon_outside_block)]` help: put the `;` here | LL - { unit_fn_block(); } diff --git a/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr b/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr index c72f8c6488db..6df11cc1fb7d 100644 --- a/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr +++ b/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr @@ -11,6 +11,7 @@ LL | rc_is_not_send: Rc, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::non_send_fields_in_send_ty)]` error: some fields in `MultiField` are not safe to be sent to another thread --> $DIR/test.rs:19:1 diff --git a/tests/ui-toml/struct_excessive_bools/test.stderr b/tests/ui-toml/struct_excessive_bools/test.stderr index 4e7c70d18385..9237c9c9d29d 100644 --- a/tests/ui-toml/struct_excessive_bools/test.stderr +++ b/tests/ui-toml/struct_excessive_bools/test.stderr @@ -8,6 +8,7 @@ LL | | } | = help: consider using a state machine or refactoring bools into two-variant enums = note: `-D clippy::struct-excessive-bools` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::struct_excessive_bools)]` error: aborting due to previous error diff --git a/tests/ui-toml/suppress_lint_in_const/test.stderr b/tests/ui-toml/suppress_lint_in_const/test.stderr index 14e13194427c..d14974faffa6 100644 --- a/tests/ui-toml/suppress_lint_in_const/test.stderr +++ b/tests/ui-toml/suppress_lint_in_const/test.stderr @@ -18,6 +18,7 @@ LL | x[index]; | = help: consider using `.get(n)` or `.get_mut(n)` instead = note: `-D clippy::indexing-slicing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]` error: indexing may panic --> $DIR/test.rs:46:5 diff --git a/tests/ui-toml/toml_disallow/conf_french_disallowed_name.stderr b/tests/ui-toml/toml_disallow/conf_french_disallowed_name.stderr index 9082c1c54c36..621328292236 100644 --- a/tests/ui-toml/toml_disallow/conf_french_disallowed_name.stderr +++ b/tests/ui-toml/toml_disallow/conf_french_disallowed_name.stderr @@ -5,6 +5,7 @@ LL | fn test(toto: ()) {} | ^^^^ | = note: `-D clippy::disallowed-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_names)]` error: use of a disallowed/placeholder name `toto` --> $DIR/conf_french_disallowed_name.rs:9:9 diff --git a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr index fc137c225d83..d9b70e3b77ce 100644 --- a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr +++ b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr @@ -5,6 +5,7 @@ LL | let re = Regex::new(r"ab.*c").unwrap(); | ^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::disallowed-methods` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_methods)]` error: use of a disallowed method `regex::Regex::is_match` --> $DIR/conf_disallowed_methods.rs:36:5 diff --git a/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr b/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr index e3ece799c7ce..4ac96deb44f3 100644 --- a/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr +++ b/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr @@ -5,6 +5,7 @@ LL | use std::sync::atomic::AtomicU32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::disallowed-types` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_types)]` error: `std::time::Instant` is not allowed according to config --> $DIR/conf_disallowed_types.rs:8:1 diff --git a/tests/ui-toml/toml_trivially_copy/test.stderr b/tests/ui-toml/toml_trivially_copy/test.stderr index db5d6805362d..262d302e72de 100644 --- a/tests/ui-toml/toml_trivially_copy/test.stderr +++ b/tests/ui-toml/toml_trivially_copy/test.stderr @@ -5,6 +5,7 @@ LL | fn bad(x: &u16, y: &Foo) {} | ^^^^ help: consider passing by value instead: `u16` | = note: `-D clippy::trivially-copy-pass-by-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::trivially_copy_pass_by_ref)]` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) --> $DIR/test.rs:15:20 diff --git a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.stderr b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.stderr index 9a0fd0593896..183c07fe786c 100644 --- a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.stderr +++ b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.stderr @@ -6,6 +6,7 @@ LL | /* Safety: */ unsafe {} | = help: consider adding a safety comment on the preceding line = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]` error: unsafe block missing a safety comment --> $DIR/undocumented_unsafe_blocks.rs:267:5 @@ -251,6 +252,7 @@ help: consider removing the safety comment LL | // SAFETY: | ^^^^^^^^^^ = note: `-D clippy::unnecessary-safety-comment` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]` error: unsafe impl missing a safety comment --> $DIR/undocumented_unsafe_blocks.rs:473:5 diff --git a/tests/ui-toml/unwrap_used/unwrap_used.stderr b/tests/ui-toml/unwrap_used/unwrap_used.stderr index 10219beaf971..cc22ea273d4f 100644 --- a/tests/ui-toml/unwrap_used/unwrap_used.stderr +++ b/tests/ui-toml/unwrap_used/unwrap_used.stderr @@ -5,6 +5,7 @@ LL | let _ = boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&boxed_slice[1]` | = note: `-D clippy::get-unwrap` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::get_unwrap)]` error: used `unwrap()` on an `Option` value --> $DIR/unwrap_used.rs:38:17 @@ -15,6 +16,7 @@ LL | let _ = boxed_slice.get(1).unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message = note: `-D clippy::unwrap-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise --> $DIR/unwrap_used.rs:39:17 diff --git a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr index 02f29bbefe14..3fad561b17c9 100644 --- a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr +++ b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr @@ -5,6 +5,7 @@ LL | struct HTTPResponse; // not linted by default, but with cfg option | ^^^^^^^^^^^^ help: consider making the acronym lowercase, except the initial letter: `HttpResponse` | = note: `-D clippy::upper-case-acronyms` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::upper_case_acronyms)]` error: name `NS` contains a capitalized acronym --> $DIR/upper_case_acronyms.rs:8:5 diff --git a/tests/ui-toml/vec_box_sized/test.stderr b/tests/ui-toml/vec_box_sized/test.stderr index 55de68f8ecf4..c88860ea8f6f 100644 --- a/tests/ui-toml/vec_box_sized/test.stderr +++ b/tests/ui-toml/vec_box_sized/test.stderr @@ -5,6 +5,7 @@ LL | struct Foo(Vec>); | ^^^^^^^^^^^^ help: try: `Vec` | = note: `-D clippy::vec-box` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::vec_box)]` error: `Vec` is already on the heap, the boxing is unnecessary --> $DIR/test.rs:10:12 diff --git a/tests/ui/absurd-extreme-comparisons.stderr b/tests/ui/absurd-extreme-comparisons.stderr index a7843e2b349e..64d38e60dc63 100644 --- a/tests/ui/absurd-extreme-comparisons.stderr +++ b/tests/ui/absurd-extreme-comparisons.stderr @@ -6,6 +6,7 @@ LL | u <= 0; | = help: because `0` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == 0` instead = note: `-D clippy::absurd-extreme-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::absurd_extreme_comparisons)]` error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false --> $DIR/absurd-extreme-comparisons.rs:16:5 diff --git a/tests/ui/allow_attributes.stderr b/tests/ui/allow_attributes.stderr index 30a947b0648b..7ac0bd456847 100644 --- a/tests/ui/allow_attributes.stderr +++ b/tests/ui/allow_attributes.stderr @@ -5,6 +5,7 @@ LL | #[allow(dead_code)] | ^^^^^ help: replace it with: `expect` | = note: `-D clippy::allow-attributes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::allow_attributes)]` error: #[allow] attribute found --> $DIR/allow_attributes.rs:22:30 diff --git a/tests/ui/almost_complete_range.stderr b/tests/ui/almost_complete_range.stderr index 9a6d91b7d8b3..054a02c9c902 100644 --- a/tests/ui/almost_complete_range.stderr +++ b/tests/ui/almost_complete_range.stderr @@ -7,6 +7,7 @@ LL | let _ = ('a') ..'z'; | help: use an inclusive range: `..=` | = note: `-D clippy::almost-complete-range` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::almost_complete_range)]` error: almost complete ascii range --> $DIR/almost_complete_range.rs:19:17 diff --git a/tests/ui/approx_const.stderr b/tests/ui/approx_const.stderr index 28d2d317155b..4b5cd2a7a62f 100644 --- a/tests/ui/approx_const.stderr +++ b/tests/ui/approx_const.stderr @@ -6,6 +6,7 @@ LL | let my_e = 2.7182; | = help: consider using the constant directly = note: `-D clippy::approx-constant` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::approx_constant)]` error: approximate value of `f{32, 64}::consts::E` found --> $DIR/approx_const.rs:6:20 diff --git a/tests/ui/arc_with_non_send_sync.stderr b/tests/ui/arc_with_non_send_sync.stderr index de3f2fb9e16e..fd239580d284 100644 --- a/tests/ui/arc_with_non_send_sync.stderr +++ b/tests/ui/arc_with_non_send_sync.stderr @@ -8,6 +8,7 @@ LL | let _ = Arc::new(RefCell::new(42)); = note: required for `Arc>` to implement `Send` and `Sync` = help: consider using an `Rc` instead or wrapping the inner type with a `Mutex` = note: `-D clippy::arc-with-non-send-sync` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::arc_with_non_send_sync)]` error: usage of an `Arc` that is not `Send` or `Sync` --> $DIR/arc_with_non_send_sync.rs:40:13 diff --git a/tests/ui/arithmetic_side_effects.stderr b/tests/ui/arithmetic_side_effects.stderr index 7f490748160b..13729a6c5a33 100644 --- a/tests/ui/arithmetic_side_effects.stderr +++ b/tests/ui/arithmetic_side_effects.stderr @@ -5,6 +5,7 @@ LL | _n += 1; | ^^^^^^^ | = note: `-D clippy::arithmetic-side-effects` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]` error: arithmetic operation that can potentially result in unexpected side-effects --> $DIR/arithmetic_side_effects.rs:305:5 diff --git a/tests/ui/as_conversions.stderr b/tests/ui/as_conversions.stderr index 54037a649978..4bb964399e2d 100644 --- a/tests/ui/as_conversions.stderr +++ b/tests/ui/as_conversions.stderr @@ -6,6 +6,7 @@ LL | let i = 0u32 as u64; | = help: consider using a safe wrapper for this conversion = note: `-D clippy::as-conversions` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::as_conversions)]` error: using a potentially dangerous silent `as` conversion --> $DIR/as_conversions.rs:12:13 diff --git a/tests/ui/as_ptr_cast_mut.stderr b/tests/ui/as_ptr_cast_mut.stderr index 1cd57dd6d165..92cdf911538d 100644 --- a/tests/ui/as_ptr_cast_mut.stderr +++ b/tests/ui/as_ptr_cast_mut.stderr @@ -5,6 +5,7 @@ LL | let _ = string.as_ptr() as *mut u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `string.as_mut_ptr()` | = note: `-D clippy::as-ptr-cast-mut` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::as_ptr_cast_mut)]` error: casting the result of `as_ptr` to *mut i8 --> $DIR/as_ptr_cast_mut.rs:25:22 diff --git a/tests/ui/as_underscore.stderr b/tests/ui/as_underscore.stderr index 21d7884445d9..1842eeeacecb 100644 --- a/tests/ui/as_underscore.stderr +++ b/tests/ui/as_underscore.stderr @@ -7,6 +7,7 @@ LL | foo(n as _); | help: consider giving the type explicitly: `usize` | = note: `-D clippy::as-underscore` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::as_underscore)]` error: using `as _` conversion --> $DIR/as_underscore.rs:10:18 diff --git a/tests/ui/asm_syntax.stderr b/tests/ui/asm_syntax.stderr index 8ee3c97ae2c6..537ea8c57e9b 100644 --- a/tests/ui/asm_syntax.stderr +++ b/tests/ui/asm_syntax.stderr @@ -6,6 +6,7 @@ LL | asm!(""); | = help: use AT&T x86 assembly syntax = note: `-D clippy::inline-asm-x86-intel-syntax` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inline_asm_x86_intel_syntax)]` error: Intel x86 assembly syntax used --> $DIR/asm_syntax.rs:10:9 @@ -31,6 +32,7 @@ LL | asm!("", options(att_syntax)); | = help: use Intel x86 assembly syntax = note: `-D clippy::inline-asm-x86-att-syntax` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inline_asm_x86_att_syntax)]` error: AT&T x86 assembly syntax used --> $DIR/asm_syntax.rs:28:9 diff --git a/tests/ui/assertions_on_constants.stderr b/tests/ui/assertions_on_constants.stderr index fc1c7671ffc7..780d1fe1c8a7 100644 --- a/tests/ui/assertions_on_constants.stderr +++ b/tests/ui/assertions_on_constants.stderr @@ -6,6 +6,7 @@ LL | assert!(true); | = help: remove it = note: `-D clippy::assertions-on-constants` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::assertions_on_constants)]` error: `assert!(false)` should probably be replaced --> $DIR/assertions_on_constants.rs:12:5 diff --git a/tests/ui/assertions_on_result_states.stderr b/tests/ui/assertions_on_result_states.stderr index 298d63c9c34f..23af51cfe6fd 100644 --- a/tests/ui/assertions_on_result_states.stderr +++ b/tests/ui/assertions_on_result_states.stderr @@ -5,6 +5,7 @@ LL | assert!(r.is_ok()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()` | = note: `-D clippy::assertions-on-result-states` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::assertions_on_result_states)]` error: called `assert!` with `Result::is_ok` --> $DIR/assertions_on_result_states.rs:42:5 diff --git a/tests/ui/assign_ops.stderr b/tests/ui/assign_ops.stderr index 525ce592b492..e021e1bab4c4 100644 --- a/tests/ui/assign_ops.stderr +++ b/tests/ui/assign_ops.stderr @@ -5,6 +5,7 @@ LL | a = a + 1; | ^^^^^^^^^ help: replace it with: `a += 1` | = note: `-D clippy::assign-op-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::assign_op_pattern)]` error: manual implementation of an assign operation --> $DIR/assign_ops.rs:8:5 diff --git a/tests/ui/assign_ops2.stderr b/tests/ui/assign_ops2.stderr index b392d1c690bb..6e9b96c0a644 100644 --- a/tests/ui/assign_ops2.stderr +++ b/tests/ui/assign_ops2.stderr @@ -5,6 +5,7 @@ LL | a += a + 1; | ^^^^^^^^^^ | = note: `-D clippy::misrefactored-assign-op` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::misrefactored_assign_op)]` help: did you mean `a = a + 1` or `a = a + a + 1`? Consider replacing it with | LL | a += 1; @@ -141,6 +142,7 @@ LL | buf = buf + cows.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `buf += cows.clone()` | = note: `-D clippy::assign-op-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::assign_op_pattern)]` error: aborting due to 10 previous errors diff --git a/tests/ui/async_yields_async.stderr b/tests/ui/async_yields_async.stderr index 22ce1c6f6471..c29e3c734b75 100644 --- a/tests/ui/async_yields_async.stderr +++ b/tests/ui/async_yields_async.stderr @@ -11,6 +11,7 @@ LL | | }; | |______- outer async construct | = note: `-D clippy::async-yields-async` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::async_yields_async)]` help: consider awaiting this value | LL ~ async { diff --git a/tests/ui/attrs.stderr b/tests/ui/attrs.stderr index 0139717f5486..16402a4ddfef 100644 --- a/tests/ui/attrs.stderr +++ b/tests/ui/attrs.stderr @@ -5,6 +5,7 @@ LL | #[inline(always)] | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::inline-always` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inline_always)]` error: the since field must contain a semver-compliant version --> $DIR/attrs.rs:27:14 @@ -13,6 +14,7 @@ LL | #[deprecated(since = "forever")] | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::deprecated-semver` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::deprecated_semver)]` error: the since field must contain a semver-compliant version --> $DIR/attrs.rs:32:14 diff --git a/tests/ui/await_holding_lock.stderr b/tests/ui/await_holding_lock.stderr index d360c757158b..56b111c4d9e4 100644 --- a/tests/ui/await_holding_lock.stderr +++ b/tests/ui/await_holding_lock.stderr @@ -14,6 +14,7 @@ LL | | baz().await LL | | } | |_____^ = note: `-D clippy::await-holding-lock` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::await_holding_lock)]` error: this `MutexGuard` is held across an `await` point --> $DIR/await_holding_lock.rs:25:13 diff --git a/tests/ui/await_holding_refcell_ref.stderr b/tests/ui/await_holding_refcell_ref.stderr index 266f8f39028a..6b7e1d1afddf 100644 --- a/tests/ui/await_holding_refcell_ref.stderr +++ b/tests/ui/await_holding_refcell_ref.stderr @@ -14,6 +14,7 @@ LL | | baz().await LL | | } | |_^ = note: `-D clippy::await-holding-refcell-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::await_holding_refcell_ref)]` error: this `RefCell` reference is held across an `await` point --> $DIR/await_holding_refcell_ref.rs:12:9 diff --git a/tests/ui/bit_masks.stderr b/tests/ui/bit_masks.stderr index d0cb3a263fca..4423d15d79d4 100644 --- a/tests/ui/bit_masks.stderr +++ b/tests/ui/bit_masks.stderr @@ -5,6 +5,7 @@ LL | x & 0 == 0; | ^^^^^^^^^^ | = note: `-D clippy::bad-bit-mask` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::bad_bit_mask)]` error: this operation will always return zero. This is likely not the intended outcome --> $DIR/bit_masks.rs:14:5 @@ -87,6 +88,7 @@ LL | x | 1 > 3; | ^^^^^^^^^ | = note: `-D clippy::ineffective-bit-mask` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ineffective_bit_mask)]` error: ineffective bit mask: `x | 1` compared to `4`, is the same as x compared directly --> $DIR/bit_masks.rs:72:5 diff --git a/tests/ui/blanket_clippy_restriction_lints.stderr b/tests/ui/blanket_clippy_restriction_lints.stderr index 0f92fbebae99..d04ea7151c2a 100644 --- a/tests/ui/blanket_clippy_restriction_lints.stderr +++ b/tests/ui/blanket_clippy_restriction_lints.stderr @@ -3,6 +3,7 @@ error: `clippy::restriction` is not meant to be enabled as a group = note: because of the command line `--warn clippy::restriction` = help: enable the restriction lints you need individually = note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::blanket_clippy_restriction_lints)]` error: `clippy::restriction` is not meant to be enabled as a group --> $DIR/blanket_clippy_restriction_lints.rs:6:9 diff --git a/tests/ui/blocks_in_if_conditions.stderr b/tests/ui/blocks_in_if_conditions.stderr index 2af7f3128c15..d80ef9c0fd8d 100644 --- a/tests/ui/blocks_in_if_conditions.stderr +++ b/tests/ui/blocks_in_if_conditions.stderr @@ -8,6 +8,7 @@ LL | | } { | |_____^ | = note: `-D clippy::blocks-in-if-conditions` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::blocks_in_if_conditions)]` help: try | LL ~ let res = { @@ -29,6 +30,7 @@ LL | if true && x == 3 { 6 } else { 10 } | ^^^^^^^^^^^^^^ help: try: `x == 3` | = note: `-D clippy::nonminimal-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` error: aborting due to 3 previous errors diff --git a/tests/ui/blocks_in_if_conditions_closure.stderr b/tests/ui/blocks_in_if_conditions_closure.stderr index 34ebe5b6d144..ab68997d477c 100644 --- a/tests/ui/blocks_in_if_conditions_closure.stderr +++ b/tests/ui/blocks_in_if_conditions_closure.stderr @@ -11,6 +11,7 @@ LL | | }, | |_____________^ | = note: `-D clippy::blocks-in-if-conditions` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::blocks_in_if_conditions)]` error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let` --> $DIR/blocks_in_if_conditions_closure.rs:34:13 diff --git a/tests/ui/bool_assert_comparison.stderr b/tests/ui/bool_assert_comparison.stderr index e0d718c4ed84..5969e4faa1aa 100644 --- a/tests/ui/bool_assert_comparison.stderr +++ b/tests/ui/bool_assert_comparison.stderr @@ -5,6 +5,7 @@ LL | assert_eq!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::bool-assert-comparison` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::bool_assert_comparison)]` help: replace it with `assert!(..)` | LL - assert_eq!("a".is_empty(), false); diff --git a/tests/ui/bool_comparison.stderr b/tests/ui/bool_comparison.stderr index 31522d4a5251..4560df6d4cdb 100644 --- a/tests/ui/bool_comparison.stderr +++ b/tests/ui/bool_comparison.stderr @@ -5,6 +5,7 @@ LL | if x == true { | ^^^^^^^^^ help: try simplifying it as shown: `x` | = note: `-D clippy::bool-comparison` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::bool_comparison)]` error: equality checks against false can be replaced by a negation --> $DIR/bool_comparison.rs:12:8 diff --git a/tests/ui/bool_to_int_with_if.stderr b/tests/ui/bool_to_int_with_if.stderr index b0581e96834c..837ed05d3a65 100644 --- a/tests/ui/bool_to_int_with_if.stderr +++ b/tests/ui/bool_to_int_with_if.stderr @@ -10,6 +10,7 @@ LL | | }; | = note: `a as i32` or `a.into()` can also be valid options = note: `-D clippy::bool-to-int-with-if` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::bool_to_int_with_if)]` error: boolean to int conversion using if --> $DIR/bool_to_int_with_if.rs:19:5 diff --git a/tests/ui/borrow_as_ptr.stderr b/tests/ui/borrow_as_ptr.stderr index b0e4e9363f1f..43a7a6bf5b57 100644 --- a/tests/ui/borrow_as_ptr.stderr +++ b/tests/ui/borrow_as_ptr.stderr @@ -5,6 +5,7 @@ LL | let _p = &val as *const i32; | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::addr_of!(val)` | = note: `-D clippy::borrow-as-ptr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::borrow_as_ptr)]` error: borrow as raw pointer --> $DIR/borrow_as_ptr.rs:17:18 diff --git a/tests/ui/borrow_as_ptr_no_std.stderr b/tests/ui/borrow_as_ptr_no_std.stderr index 4a0467cdbfe1..2f258bcf966a 100644 --- a/tests/ui/borrow_as_ptr_no_std.stderr +++ b/tests/ui/borrow_as_ptr_no_std.stderr @@ -5,6 +5,7 @@ LL | let _p = &val as *const i32; | ^^^^^^^^^^^^^^^^^^ help: try: `core::ptr::addr_of!(val)` | = note: `-D clippy::borrow-as-ptr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::borrow_as_ptr)]` error: borrow as raw pointer --> $DIR/borrow_as_ptr_no_std.rs:11:18 diff --git a/tests/ui/borrow_deref_ref.stderr b/tests/ui/borrow_deref_ref.stderr index 524cf597c7f2..c389d6797388 100644 --- a/tests/ui/borrow_deref_ref.stderr +++ b/tests/ui/borrow_deref_ref.stderr @@ -5,6 +5,7 @@ LL | let b = &*a; | ^^^ help: if you would like to reborrow, try removing `&*`: `a` | = note: `-D clippy::borrow-deref-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::borrow_deref_ref)]` error: deref on an immutable reference --> $DIR/borrow_deref_ref.rs:15:22 diff --git a/tests/ui/borrow_deref_ref_unfixable.stderr b/tests/ui/borrow_deref_ref_unfixable.stderr index 5650f722b54b..2a21f5ca236f 100644 --- a/tests/ui/borrow_deref_ref_unfixable.stderr +++ b/tests/ui/borrow_deref_ref_unfixable.stderr @@ -5,6 +5,7 @@ LL | let x: &str = &*s; | ^^^ | = note: `-D clippy::borrow-deref-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::borrow_deref_ref)]` help: if you would like to reborrow, try removing `&*` | LL | let x: &str = s; diff --git a/tests/ui/box_collection.stderr b/tests/ui/box_collection.stderr index 773427126753..1ae7c2a05e3d 100644 --- a/tests/ui/box_collection.stderr +++ b/tests/ui/box_collection.stderr @@ -6,6 +6,7 @@ LL | fn test1(foo: Box>) {} | = help: `Vec<..>` is already on the heap, `Box>` makes an extra allocation = note: `-D clippy::box-collection` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::box_collection)]` error: you seem to be trying to use `Box`. Consider using just `String` --> $DIR/box_collection.rs:29:15 diff --git a/tests/ui/box_default.stderr b/tests/ui/box_default.stderr index 8c4778983d39..004550c6c64a 100644 --- a/tests/ui/box_default.stderr +++ b/tests/ui/box_default.stderr @@ -5,6 +5,7 @@ LL | let _string: Box = Box::new(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` | = note: `-D clippy::box-default` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::box_default)]` error: `Box::new(_)` of default value --> $DIR/box_default.rs:23:17 diff --git a/tests/ui/boxed_local.stderr b/tests/ui/boxed_local.stderr index 11868605d969..187cc8fa18ba 100644 --- a/tests/ui/boxed_local.stderr +++ b/tests/ui/boxed_local.stderr @@ -5,6 +5,7 @@ LL | fn warn_arg(x: Box) { | ^ | = note: `-D clippy::boxed-local` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::boxed_local)]` error: local variable doesn't need to be boxed here --> $DIR/boxed_local.rs:123:12 diff --git a/tests/ui/builtin_type_shadow.stderr b/tests/ui/builtin_type_shadow.stderr index 47a8a1e623e8..cb8462182b89 100644 --- a/tests/ui/builtin_type_shadow.stderr +++ b/tests/ui/builtin_type_shadow.stderr @@ -5,6 +5,7 @@ LL | fn foo(a: u32) -> u32 { | ^^^ | = note: `-D clippy::builtin-type-shadow` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::builtin_type_shadow)]` error[E0308]: mismatched types --> $DIR/builtin_type_shadow.rs:5:5 diff --git a/tests/ui/bytes_count_to_len.stderr b/tests/ui/bytes_count_to_len.stderr index fe2c8b0627dc..db0bb4099de9 100644 --- a/tests/ui/bytes_count_to_len.stderr +++ b/tests/ui/bytes_count_to_len.stderr @@ -5,6 +5,7 @@ LL | let _ = String::from("foo").bytes().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.len()` instead: `String::from("foo").len()` | = note: `-D clippy::bytes-count-to-len` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::bytes_count_to_len)]` error: using long and hard to read `.bytes().count()` --> $DIR/bytes_count_to_len.rs:10:13 diff --git a/tests/ui/bytes_nth.stderr b/tests/ui/bytes_nth.stderr index d9ede64a3815..574bfaac193d 100644 --- a/tests/ui/bytes_nth.stderr +++ b/tests/ui/bytes_nth.stderr @@ -5,6 +5,7 @@ LL | let _ = s.bytes().nth(3); | ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3).copied()` | = note: `-D clippy::bytes-nth` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::bytes_nth)]` error: called `.bytes().nth().unwrap()` on a `String` --> $DIR/bytes_nth.rs:7:14 diff --git a/tests/ui/case_sensitive_file_extension_comparisons.stderr b/tests/ui/case_sensitive_file_extension_comparisons.stderr index 9abf8aaca93b..49c840bd7692 100644 --- a/tests/ui/case_sensitive_file_extension_comparisons.stderr +++ b/tests/ui/case_sensitive_file_extension_comparisons.stderr @@ -6,6 +6,7 @@ LL | filename.ends_with(".rs") | = help: consider using a case-insensitive comparison instead = note: `-D clippy::case-sensitive-file-extension-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::case_sensitive_file_extension_comparisons)]` help: use std::path::Path | LL ~ std::path::Path::new(filename) diff --git a/tests/ui/cast.stderr b/tests/ui/cast.stderr index 5442ef5db16d..bc74f7b728e8 100644 --- a/tests/ui/cast.stderr +++ b/tests/ui/cast.stderr @@ -5,6 +5,7 @@ LL | x0 as f32; | ^^^^^^^^^ | = note: `-D clippy::cast-precision-loss` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_precision_loss)]` error: casting `i64` to `f32` causes a loss of precision (`i64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide) --> $DIR/cast.rs:20:5 @@ -44,6 +45,7 @@ LL | 1f32 as i32; | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... = note: `-D clippy::cast-possible-truncation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_possible_truncation)]` error: casting `f32` to `u32` may truncate the value --> $DIR/cast.rs:35:5 @@ -60,6 +62,7 @@ LL | 1f32 as u32; | ^^^^^^^^^^^ | = note: `-D clippy::cast-sign-loss` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_sign_loss)]` error: casting `f64` to `f32` may truncate the value --> $DIR/cast.rs:39:5 @@ -190,6 +193,7 @@ LL | 1u8 as i8; | ^^^^^^^^^ | = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_possible_wrap)]` error: casting `u16` to `i16` may wrap around the value --> $DIR/cast.rs:69:5 @@ -360,6 +364,7 @@ LL | let _ = Self::B as u8; | ^^^^^^^^^^^^^ | = note: `-D clippy::cast-enum-truncation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_enum_truncation)]` error: casting `main::E5` to `i8` may truncate the value --> $DIR/cast.rs:260:21 diff --git a/tests/ui/cast_abs_to_unsigned.stderr b/tests/ui/cast_abs_to_unsigned.stderr index 94b87df0b6ec..fbdb559fc421 100644 --- a/tests/ui/cast_abs_to_unsigned.stderr +++ b/tests/ui/cast_abs_to_unsigned.stderr @@ -5,6 +5,7 @@ LL | let y: u32 = x.abs() as u32; | ^^^^^^^^^^^^^^ help: replace with: `x.unsigned_abs()` | = note: `-D clippy::cast-abs-to-unsigned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_abs_to_unsigned)]` error: casting the result of `i32::abs()` to usize --> $DIR/cast_abs_to_unsigned.rs:10:20 diff --git a/tests/ui/cast_alignment.stderr b/tests/ui/cast_alignment.stderr index 70510eaf6345..49bd8dad9c24 100644 --- a/tests/ui/cast_alignment.stderr +++ b/tests/ui/cast_alignment.stderr @@ -5,6 +5,7 @@ LL | (&1u8 as *const u8) as *const u16; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::cast-ptr-alignment` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_ptr_alignment)]` error: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 < 2 bytes) --> $DIR/cast_alignment.rs:22:5 diff --git a/tests/ui/cast_enum_constructor.stderr b/tests/ui/cast_enum_constructor.stderr index f0489f08f910..b1bf61edeedb 100644 --- a/tests/ui/cast_enum_constructor.stderr +++ b/tests/ui/cast_enum_constructor.stderr @@ -5,6 +5,7 @@ LL | let _ = Foo::Y as usize; | ^^^^^^^^^^^^^^^ | = note: `-D clippy::cast-enum-constructor` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_enum_constructor)]` error: cast of an enum tuple constructor to an integer --> $DIR/cast_enum_constructor.rs:16:13 diff --git a/tests/ui/cast_lossless_bool.stderr b/tests/ui/cast_lossless_bool.stderr index 891476f304df..e4a5b2e805c3 100644 --- a/tests/ui/cast_lossless_bool.stderr +++ b/tests/ui/cast_lossless_bool.stderr @@ -5,6 +5,7 @@ LL | let _ = true as u8; | ^^^^^^^^^^ help: try: `u8::from(true)` | = note: `-D clippy::cast-lossless` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` error: casting `bool` to `u16` is more cleanly stated with `u16::from(_)` --> $DIR/cast_lossless_bool.rs:7:13 diff --git a/tests/ui/cast_lossless_float.stderr b/tests/ui/cast_lossless_float.stderr index 70dc4a102648..95e80b4e4a6e 100644 --- a/tests/ui/cast_lossless_float.stderr +++ b/tests/ui/cast_lossless_float.stderr @@ -5,6 +5,7 @@ LL | let _ = x0 as f32; | ^^^^^^^^^ help: try: `f32::from(x0)` | = note: `-D clippy::cast-lossless` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` error: casting `i8` to `f64` may become silently lossy if you later change the type --> $DIR/cast_lossless_float.rs:8:13 diff --git a/tests/ui/cast_lossless_integer.stderr b/tests/ui/cast_lossless_integer.stderr index 4891d934c5e1..da75cb195eba 100644 --- a/tests/ui/cast_lossless_integer.stderr +++ b/tests/ui/cast_lossless_integer.stderr @@ -5,6 +5,7 @@ LL | let _ = 1i8 as i16; | ^^^^^^^^^^ help: try: `i16::from(1i8)` | = note: `-D clippy::cast-lossless` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` error: casting `i8` to `i32` may become silently lossy if you later change the type --> $DIR/cast_lossless_integer.rs:7:13 diff --git a/tests/ui/cast_nan_to_int.stderr b/tests/ui/cast_nan_to_int.stderr index 678db89954e5..c0bb29448f2f 100644 --- a/tests/ui/cast_nan_to_int.stderr +++ b/tests/ui/cast_nan_to_int.stderr @@ -6,6 +6,7 @@ LL | let _ = (0.0_f32 / -0.0) as usize; | = note: this always evaluates to 0 = note: `-D clippy::cast-nan-to-int` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_nan_to_int)]` error: casting a known NaN to usize --> $DIR/cast_nan_to_int.rs:8:13 diff --git a/tests/ui/cast_raw_slice_pointer_cast.stderr b/tests/ui/cast_raw_slice_pointer_cast.stderr index 831641120267..47dc39a30ef7 100644 --- a/tests/ui/cast_raw_slice_pointer_cast.stderr +++ b/tests/ui/cast_raw_slice_pointer_cast.stderr @@ -5,6 +5,7 @@ LL | let _: *const [u8] = unsafe { std::slice::from_raw_parts(ptr, 1) as *co | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)` | = note: `-D clippy::cast-slice-from-raw-parts` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_slice_from_raw_parts)]` error: casting the result of `from_raw_parts_mut` to *mut [u8] --> $DIR/cast_raw_slice_pointer_cast.rs:9:35 diff --git a/tests/ui/cast_size.stderr b/tests/ui/cast_size.stderr index 6c7459b3abae..bc9224be6440 100644 --- a/tests/ui/cast_size.stderr +++ b/tests/ui/cast_size.stderr @@ -6,6 +6,7 @@ LL | 1isize as i8; | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... = note: `-D clippy::cast-possible-truncation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_possible_truncation)]` help: ... or use `try_from` and handle the error accordingly | LL | i8::try_from(1isize); @@ -18,6 +19,7 @@ LL | x0 as f64; | ^^^^^^^^^ | = note: `-D clippy::cast-precision-loss` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_precision_loss)]` error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) --> $DIR/cast_size.rs:19:5 @@ -92,6 +94,7 @@ LL | 1usize as i32; | ^^^^^^^^^^^^^ | = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_possible_wrap)]` error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers --> $DIR/cast_size.rs:36:5 diff --git a/tests/ui/cfg_attr_rustfmt.stderr b/tests/ui/cfg_attr_rustfmt.stderr index 524a2bf72484..8816ce2d8374 100644 --- a/tests/ui/cfg_attr_rustfmt.stderr +++ b/tests/ui/cfg_attr_rustfmt.stderr @@ -5,6 +5,7 @@ LL | #[cfg_attr(rustfmt, rustfmt::skip)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[rustfmt::skip]` | = note: `-D clippy::deprecated-cfg-attr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::deprecated_cfg_attr)]` error: `cfg_attr` is deprecated for rustfmt and got replaced by tool attributes --> $DIR/cfg_attr_rustfmt.rs:22:1 diff --git a/tests/ui/cfg_features.stderr b/tests/ui/cfg_features.stderr index 5f92dfe169c7..401c3e92ed95 100644 --- a/tests/ui/cfg_features.stderr +++ b/tests/ui/cfg_features.stderr @@ -5,6 +5,7 @@ LL | #[cfg(features = "not-really-a-feature")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `feature = "not-really-a-feature"` | = note: `-D clippy::maybe-misused-cfg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::maybe_misused_cfg)]` error: feature may misspelled as features --> $DIR/cfg_features.rs:9:34 diff --git a/tests/ui/char_lit_as_u8.stderr b/tests/ui/char_lit_as_u8.stderr index da3e5c5e52b1..ce1f2f8296e5 100644 --- a/tests/ui/char_lit_as_u8.stderr +++ b/tests/ui/char_lit_as_u8.stderr @@ -6,6 +6,7 @@ LL | let _ = '❤' as u8; | = note: `char` is four bytes wide, but `u8` is a single byte = note: `-D clippy::char-lit-as-u8` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::char_lit_as_u8)]` error: aborting due to previous error diff --git a/tests/ui/char_lit_as_u8_suggestions.stderr b/tests/ui/char_lit_as_u8_suggestions.stderr index 0542db5501a0..359857119d09 100644 --- a/tests/ui/char_lit_as_u8_suggestions.stderr +++ b/tests/ui/char_lit_as_u8_suggestions.stderr @@ -6,6 +6,7 @@ LL | let _ = 'a' as u8; | = note: `char` is four bytes wide, but `u8` is a single byte = note: `-D clippy::char-lit-as-u8` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::char_lit_as_u8)]` error: casting a character literal to `u8` truncates --> $DIR/char_lit_as_u8_suggestions.rs:5:13 diff --git a/tests/ui/checked_conversions.stderr b/tests/ui/checked_conversions.stderr index 08457973a218..3e0169b74dab 100644 --- a/tests/ui/checked_conversions.stderr +++ b/tests/ui/checked_conversions.stderr @@ -5,6 +5,7 @@ LL | let _ = value <= (u32::max_value() as i64) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()` | = note: `-D clippy::checked-conversions` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::checked_conversions)]` error: checked cast can be simplified --> $DIR/checked_conversions.rs:15:13 diff --git a/tests/ui/clear_with_drain.stderr b/tests/ui/clear_with_drain.stderr index db545c5fba4e..b1a3812563af 100644 --- a/tests/ui/clear_with_drain.stderr +++ b/tests/ui/clear_with_drain.stderr @@ -5,6 +5,7 @@ LL | v.drain(0..v.len()); | ^^^^^^^^^^^^^^^^^ help: try: `clear()` | = note: `-D clippy::clear-with-drain` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::clear_with_drain)]` error: `drain` used to clear a `Vec` --> $DIR/clear_with_drain.rs:26:7 diff --git a/tests/ui/clone_on_copy.stderr b/tests/ui/clone_on_copy.stderr index 053dee954481..0526c2f5a28a 100644 --- a/tests/ui/clone_on_copy.stderr +++ b/tests/ui/clone_on_copy.stderr @@ -5,6 +5,7 @@ LL | 42.clone(); | ^^^^^^^^^^ help: try removing the `clone` call: `42` | = note: `-D clippy::clone-on-copy` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::clone_on_copy)]` error: using `clone` on type `i32` which implements the `Copy` trait --> $DIR/clone_on_copy.rs:27:5 diff --git a/tests/ui/cloned_instead_of_copied.stderr b/tests/ui/cloned_instead_of_copied.stderr index 247d15a015ab..69a3738dd05b 100644 --- a/tests/ui/cloned_instead_of_copied.stderr +++ b/tests/ui/cloned_instead_of_copied.stderr @@ -5,6 +5,7 @@ LL | let _ = [1].iter().cloned(); | ^^^^^^ help: try: `copied` | = note: `-D clippy::cloned-instead-of-copied` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cloned_instead_of_copied)]` error: used `cloned` where `copied` could be used instead --> $DIR/cloned_instead_of_copied.rs:8:31 diff --git a/tests/ui/cmp_null.stderr b/tests/ui/cmp_null.stderr index cc2ffb21b476..d3b7c85b2293 100644 --- a/tests/ui/cmp_null.stderr +++ b/tests/ui/cmp_null.stderr @@ -5,6 +5,7 @@ LL | if p == ptr::null() { | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::cmp-null` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cmp_null)]` error: comparing with null is better expressed by the `.is_null()` method --> $DIR/cmp_null.rs:16:8 diff --git a/tests/ui/cmp_owned/asymmetric_partial_eq.stderr b/tests/ui/cmp_owned/asymmetric_partial_eq.stderr index 95c829e795e6..6431b3619be9 100644 --- a/tests/ui/cmp_owned/asymmetric_partial_eq.stderr +++ b/tests/ui/cmp_owned/asymmetric_partial_eq.stderr @@ -5,6 +5,7 @@ LL | if borrowed.to_owned() == owned {} | ^^^^^^^^^^^^^^^^^^^ help: try: `borrowed` | = note: `-D clippy::cmp-owned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cmp_owned)]` error: this creates an owned instance just for comparison --> $DIR/asymmetric_partial_eq.rs:47:21 diff --git a/tests/ui/cmp_owned/comparison_flip.stderr b/tests/ui/cmp_owned/comparison_flip.stderr index 76983578f416..09a495996f2c 100644 --- a/tests/ui/cmp_owned/comparison_flip.stderr +++ b/tests/ui/cmp_owned/comparison_flip.stderr @@ -5,6 +5,7 @@ LL | if a.to_string() != "bar" { | ^^^^^^^^^^^^^ help: try: `a` | = note: `-D clippy::cmp-owned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cmp_owned)]` error: this creates an owned instance just for comparison --> $DIR/comparison_flip.rs:10:17 diff --git a/tests/ui/cmp_owned/with_suggestion.stderr b/tests/ui/cmp_owned/with_suggestion.stderr index 88e6da2f0671..0b1127c1a61b 100644 --- a/tests/ui/cmp_owned/with_suggestion.stderr +++ b/tests/ui/cmp_owned/with_suggestion.stderr @@ -5,6 +5,7 @@ LL | x != "foo".to_string(); | ^^^^^^^^^^^^^^^^^ help: try: `"foo"` | = note: `-D clippy::cmp-owned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cmp_owned)]` error: this creates an owned instance just for comparison --> $DIR/with_suggestion.rs:7:9 diff --git a/tests/ui/cmp_owned/without_suggestion.stderr b/tests/ui/cmp_owned/without_suggestion.stderr index fa7cb380eba1..c4f63bd09cb8 100644 --- a/tests/ui/cmp_owned/without_suggestion.stderr +++ b/tests/ui/cmp_owned/without_suggestion.stderr @@ -5,6 +5,7 @@ LL | y.to_owned() == *x; | ^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating | = note: `-D clippy::cmp-owned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cmp_owned)]` error: this creates an owned instance just for comparison --> $DIR/without_suggestion.rs:13:5 diff --git a/tests/ui/cognitive_complexity.stderr b/tests/ui/cognitive_complexity.stderr index a712b163b171..58c7455d11a6 100644 --- a/tests/ui/cognitive_complexity.stderr +++ b/tests/ui/cognitive_complexity.stderr @@ -6,6 +6,7 @@ LL | fn main() { | = help: you could split it up into multiple smaller functions = note: `-D clippy::cognitive-complexity` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cognitive_complexity)]` error: the function has a cognitive complexity of (7/1) --> $DIR/cognitive_complexity.rs:92:4 diff --git a/tests/ui/cognitive_complexity_attr_used.stderr b/tests/ui/cognitive_complexity_attr_used.stderr index bb48f3297486..9cd25f6fda98 100644 --- a/tests/ui/cognitive_complexity_attr_used.stderr +++ b/tests/ui/cognitive_complexity_attr_used.stderr @@ -6,6 +6,7 @@ LL | fn kaboom() { | = help: you could split it up into multiple smaller functions = note: `-D clippy::cognitive-complexity` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cognitive_complexity)]` error: aborting due to previous error diff --git a/tests/ui/collapsible_else_if.stderr b/tests/ui/collapsible_else_if.stderr index b644205d9830..f0f840653f8a 100644 --- a/tests/ui/collapsible_else_if.stderr +++ b/tests/ui/collapsible_else_if.stderr @@ -10,6 +10,7 @@ LL | | } | |_____^ | = note: `-D clippy::collapsible-else-if` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::collapsible_else_if)]` help: collapse nested if block | LL ~ } else if y == "world" { diff --git a/tests/ui/collapsible_if.stderr b/tests/ui/collapsible_if.stderr index c687bae1acc5..e8a36bf48f11 100644 --- a/tests/ui/collapsible_if.stderr +++ b/tests/ui/collapsible_if.stderr @@ -9,6 +9,7 @@ LL | | } | |_____^ | = note: `-D clippy::collapsible-if` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::collapsible_if)]` help: collapse nested if block | LL ~ if x == "hello" && y == "world" { diff --git a/tests/ui/collapsible_match.stderr b/tests/ui/collapsible_match.stderr index 51a5eedd761c..ce7da1c16d30 100644 --- a/tests/ui/collapsible_match.stderr +++ b/tests/ui/collapsible_match.stderr @@ -18,6 +18,7 @@ LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern = note: `-D clippy::collapsible-match` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::collapsible_match)]` error: this `match` can be collapsed into the outer `match` --> $DIR/collapsible_match.rs:23:20 diff --git a/tests/ui/collapsible_match2.stderr b/tests/ui/collapsible_match2.stderr index f1b7c1417ef7..e008355bec8a 100644 --- a/tests/ui/collapsible_match2.stderr +++ b/tests/ui/collapsible_match2.stderr @@ -18,6 +18,7 @@ LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern = note: `-D clippy::collapsible-match` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::collapsible_match)]` error: this `match` can be collapsed into the outer `match` --> $DIR/collapsible_match2.rs:21:24 diff --git a/tests/ui/collapsible_str_replace.stderr b/tests/ui/collapsible_str_replace.stderr index 0751a1043002..4b0bd818d2f0 100644 --- a/tests/ui/collapsible_str_replace.stderr +++ b/tests/ui/collapsible_str_replace.stderr @@ -5,6 +5,7 @@ LL | let _ = "hesuo worpd".replace('s', "l").replace('u', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['s', 'u'], "l")` | = note: `-D clippy::collapsible-str-replace` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::collapsible_str_replace)]` error: used consecutive `str::replace` call --> $DIR/collapsible_str_replace.rs:20:27 diff --git a/tests/ui/collection_is_never_read.stderr b/tests/ui/collection_is_never_read.stderr index 0d3f2fc602f8..acb9abff68e9 100644 --- a/tests/ui/collection_is_never_read.stderr +++ b/tests/ui/collection_is_never_read.stderr @@ -5,6 +5,7 @@ LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::collection-is-never-read` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::collection_is_never_read)]` error: collection is never read --> $DIR/collection_is_never_read.rs:62:5 diff --git a/tests/ui/comparison_chain.stderr b/tests/ui/comparison_chain.stderr index db20b1fbb3b4..3b41dcf55c62 100644 --- a/tests/ui/comparison_chain.stderr +++ b/tests/ui/comparison_chain.stderr @@ -11,6 +11,7 @@ LL | | } | = help: consider rewriting the `if` chain to use `cmp` and `match` = note: `-D clippy::comparison-chain` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::comparison_chain)]` error: `if` chain can be rewritten with `match` --> $DIR/comparison_chain.rs:28:5 diff --git a/tests/ui/comparison_to_empty.stderr b/tests/ui/comparison_to_empty.stderr index 0a59caea8a2d..b97ab4c3c937 100644 --- a/tests/ui/comparison_to_empty.stderr +++ b/tests/ui/comparison_to_empty.stderr @@ -5,6 +5,7 @@ LL | let _ = s == ""; | ^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()` | = note: `-D clippy::comparison-to-empty` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::comparison_to_empty)]` error: comparison to empty slice --> $DIR/comparison_to_empty.rs:9:13 diff --git a/tests/ui/const_comparisons.stderr b/tests/ui/const_comparisons.stderr index 8c920d36896d..f773ccbc711e 100644 --- a/tests/ui/const_comparisons.stderr +++ b/tests/ui/const_comparisons.stderr @@ -6,6 +6,7 @@ LL | status_code <= 400 && status_code > 500; | = note: since `400` < `500`, the expression evaluates to false for any value of `status_code` = note: `-D clippy::impossible-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::impossible_comparisons)]` error: boolean expression will never evaluate to 'true' --> $DIR/const_comparisons.rs:48:5 @@ -131,6 +132,7 @@ note: `if `status_code < 200` evaluates to true, status_code <= 299` will always LL | status_code < 200 && status_code <= 299; | ^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::redundant-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_comparisons)]` error: left-hand side of `&&` operator has no effect --> $DIR/const_comparisons.rs:114:5 diff --git a/tests/ui/copy_iterator.stderr b/tests/ui/copy_iterator.stderr index 12a329bdc12b..48c3385b6c8a 100644 --- a/tests/ui/copy_iterator.stderr +++ b/tests/ui/copy_iterator.stderr @@ -12,6 +12,7 @@ LL | | } | = note: consider implementing `IntoIterator` instead = note: `-D clippy::copy-iterator` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::copy_iterator)]` error: aborting due to previous error diff --git a/tests/ui/crashes/ice-10148.stderr b/tests/ui/crashes/ice-10148.stderr index f23e4433f95e..4d436e3aa04f 100644 --- a/tests/ui/crashes/ice-10148.stderr +++ b/tests/ui/crashes/ice-10148.stderr @@ -7,6 +7,7 @@ LL | println!(with_span!(""something "")); | help: remove the empty string | = note: `-D clippy::println-empty-string` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::println_empty_string)]` error: aborting due to previous error diff --git a/tests/ui/crashes/ice-10645.stderr b/tests/ui/crashes/ice-10645.stderr index 0055fe061e2a..fc5347c86cde 100644 --- a/tests/ui/crashes/ice-10645.stderr +++ b/tests/ui/crashes/ice-10645.stderr @@ -11,6 +11,7 @@ LL | pub async fn bar<'a, T: 'a>(_: T) {} | ^ has type `T` which is not `Send` = note: `T` doesn't implement `std::marker::Send` = note: `-D clippy::future-not-send` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::future_not_send)]` warning: 1 warning emitted diff --git a/tests/ui/crashes/ice-10912.stderr b/tests/ui/crashes/ice-10912.stderr index 0833769feecf..2be297b56250 100644 --- a/tests/ui/crashes/ice-10912.stderr +++ b/tests/ui/crashes/ice-10912.stderr @@ -11,6 +11,7 @@ LL | fn f2() -> impl Sized { && 3.14159265358979323846E } | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider: `3.141_592_653_589_793_238_46` | = note: `-D clippy::unreadable-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unreadable_literal)]` error: aborting due to 2 previous errors diff --git a/tests/ui/crashes/ice-2774.stderr b/tests/ui/crashes/ice-2774.stderr index a166ccb3ee8f..ae9610c9acd4 100644 --- a/tests/ui/crashes/ice-2774.stderr +++ b/tests/ui/crashes/ice-2774.stderr @@ -5,6 +5,7 @@ LL | pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) { | ^^ ^^ | = note: `-D clippy::needless-lifetimes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_lifetimes)]` help: elide the lifetimes | LL - pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) { diff --git a/tests/ui/crashes/ice-360.stderr b/tests/ui/crashes/ice-360.stderr index 292b27dd934e..dd016355b532 100644 --- a/tests/ui/crashes/ice-360.stderr +++ b/tests/ui/crashes/ice-360.stderr @@ -11,6 +11,7 @@ LL | | } | |_____^ help: try: `while let Some(ele) = iter.next() { .. }` | = note: `-D clippy::while-let-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::while_let_loop)]` error: empty `loop {}` wastes CPU cycles --> $DIR/ice-360.rs:12:9 @@ -20,6 +21,7 @@ LL | loop {} | = help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body = note: `-D clippy::empty-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_loop)]` error: aborting due to 2 previous errors diff --git a/tests/ui/crashes/ice-3969.stderr b/tests/ui/crashes/ice-3969.stderr index bc10555693ca..c6bef3004d37 100644 --- a/tests/ui/crashes/ice-3969.stderr +++ b/tests/ui/crashes/ice-3969.stderr @@ -5,6 +5,7 @@ LL | str: Sized; | ^^^^^ | = note: `-D trivial-bounds` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(trivial_bounds)]` error: trait bound for<'a> Dst<(dyn A + 'a)>: std::marker::Sized does not depend on any type or lifetime parameters --> $DIR/ice-3969.rs:26:30 diff --git a/tests/ui/crashes/ice-5835.stderr b/tests/ui/crashes/ice-5835.stderr index c972bcb60a0c..74d99a348472 100644 --- a/tests/ui/crashes/ice-5835.stderr +++ b/tests/ui/crashes/ice-5835.stderr @@ -5,6 +5,7 @@ LL | /// 位 | ^^^^ help: consider using four spaces per tab | = note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::tabs_in_doc_comments)]` error: aborting due to previous error diff --git a/tests/ui/crashes/ice-5872.stderr b/tests/ui/crashes/ice-5872.stderr index a60ca345cf78..75a26ee318c3 100644 --- a/tests/ui/crashes/ice-5872.stderr +++ b/tests/ui/crashes/ice-5872.stderr @@ -5,6 +5,7 @@ LL | let _ = vec![1, 2, 3].into_iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` | = note: `-D clippy::needless-collect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_collect)]` error: aborting due to previous error diff --git a/tests/ui/crashes/ice-6254.stderr b/tests/ui/crashes/ice-6254.stderr index 263c27d3d646..6ace7dae8bdc 100644 --- a/tests/ui/crashes/ice-6254.stderr +++ b/tests/ui/crashes/ice-6254.stderr @@ -9,6 +9,7 @@ LL | FOO_REF_REF => {}, = note: the traits must be derived, manual `impl`s are not sufficient = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details = note: `-D indirect-structural-match` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(indirect_structural_match)]` error: aborting due to previous error diff --git a/tests/ui/crashes/ice-7169.stderr b/tests/ui/crashes/ice-7169.stderr index 0cd02851640e..47947f89baf5 100644 --- a/tests/ui/crashes/ice-7169.stderr +++ b/tests/ui/crashes/ice-7169.stderr @@ -5,6 +5,7 @@ LL | if let Ok(_) = Ok::<_, ()>(A::::default()) {} | -------^^^^^-------------------------------------- help: try: `if Ok::<_, ()>(A::::default()).is_ok()` | = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: aborting due to previous error diff --git a/tests/ui/crashes/ice-7868.stderr b/tests/ui/crashes/ice-7868.stderr index 1d8314e889fa..e5f14f2215d7 100644 --- a/tests/ui/crashes/ice-7868.stderr +++ b/tests/ui/crashes/ice-7868.stderr @@ -6,6 +6,7 @@ LL | unsafe { 0 }; | = help: consider adding a safety comment on the preceding line = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]` error: aborting due to previous error diff --git a/tests/ui/crashes/ice-7869.stderr b/tests/ui/crashes/ice-7869.stderr index 61fc8a4817a7..7acace78a7b2 100644 --- a/tests/ui/crashes/ice-7869.stderr +++ b/tests/ui/crashes/ice-7869.stderr @@ -11,6 +11,7 @@ LL | | } | = help: remove the prefixes and use full paths to the variants instead of glob imports = note: `-D clippy::enum-variant-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::enum_variant_names)]` error: aborting due to previous error diff --git a/tests/ui/crashes/ice-8250.stderr b/tests/ui/crashes/ice-8250.stderr index e6f3644ef34f..9c57f334581c 100644 --- a/tests/ui/crashes/ice-8250.stderr +++ b/tests/ui/crashes/ice-8250.stderr @@ -5,6 +5,7 @@ LL | let _ = s[1..].splitn(2, '.').next()?; | ^^^^^^^^^^^^^^^^^^^^^ help: try: `s[1..].split('.')` | = note: `-D clippy::needless-splitn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_splitn)]` error: aborting due to previous error diff --git a/tests/ui/crashes/ice-8821.stderr b/tests/ui/crashes/ice-8821.stderr index 486096e0a06d..c8bd01fb1c64 100644 --- a/tests/ui/crashes/ice-8821.stderr +++ b/tests/ui/crashes/ice-8821.stderr @@ -5,6 +5,7 @@ LL | let _: () = FN(); | ^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `FN();` | = note: `-D clippy::let-unit-value` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_unit_value)]` error: aborting due to previous error diff --git a/tests/ui/crashes/ice-8850.stderr b/tests/ui/crashes/ice-8850.stderr index 41da3f715ae3..aa140f305e39 100644 --- a/tests/ui/crashes/ice-8850.stderr +++ b/tests/ui/crashes/ice-8850.stderr @@ -7,6 +7,7 @@ LL | res | ^^^ | = note: `-D clippy::let-and-return` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_and_return)]` help: return the expression directly | LL ~ diff --git a/tests/ui/crashes/ice-9041.stderr b/tests/ui/crashes/ice-9041.stderr index f5038f0a8484..49c9bdc300ee 100644 --- a/tests/ui/crashes/ice-9041.stderr +++ b/tests/ui/crashes/ice-9041.stderr @@ -5,6 +5,7 @@ LL | things.iter().find(|p| is_thing_ready(p)).is_some() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|p| is_thing_ready(&p))` | = note: `-D clippy::search-is-some` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::search_is_some)]` error: aborting due to previous error diff --git a/tests/ui/crashes/ice-9445.stderr b/tests/ui/crashes/ice-9445.stderr index a59d098e5ac0..9307409ba585 100644 --- a/tests/ui/crashes/ice-9445.stderr +++ b/tests/ui/crashes/ice-9445.stderr @@ -7,6 +7,7 @@ LL | const UNINIT: core::mem::MaybeUninit> = core: | make this a static item (maybe with lazy_static) | = note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::declare_interior_mutable_const)]` error: aborting due to previous error diff --git a/tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr b/tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr index 7a0a648974fc..6d45393996d0 100644 --- a/tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr +++ b/tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr @@ -10,6 +10,7 @@ help: consider marking this type as `Copy` LL | struct Foo<'a>(&'a [(); 100]); | ^^^^^^^^^^^^^^ = note: `-D clippy::needless-pass-by-value` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_value)]` error: aborting due to previous error diff --git a/tests/ui/crate_in_macro_def.stderr b/tests/ui/crate_in_macro_def.stderr index faf2bca1d629..3e624618237c 100644 --- a/tests/ui/crate_in_macro_def.stderr +++ b/tests/ui/crate_in_macro_def.stderr @@ -5,6 +5,7 @@ LL | println!("{}", crate::unhygienic::MESSAGE); | ^^^^^ help: to reference the macro definition's crate, use: `$crate` | = note: `-D clippy::crate-in-macro-def` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::crate_in_macro_def)]` error: aborting due to previous error diff --git a/tests/ui/crate_level_checks/no_std_swap.stderr b/tests/ui/crate_level_checks/no_std_swap.stderr index 9258c828aafc..01033246dd90 100644 --- a/tests/ui/crate_level_checks/no_std_swap.stderr +++ b/tests/ui/crate_level_checks/no_std_swap.stderr @@ -9,6 +9,7 @@ LL | | b = a; | = note: or maybe you should use `core::mem::replace`? = note: `-D clippy::almost-swapped` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::almost_swapped)]` error: aborting due to previous error diff --git a/tests/ui/crate_level_checks/std_main_recursion.stderr b/tests/ui/crate_level_checks/std_main_recursion.stderr index 82c68bd1cfef..f3ffd6a10c71 100644 --- a/tests/ui/crate_level_checks/std_main_recursion.stderr +++ b/tests/ui/crate_level_checks/std_main_recursion.stderr @@ -6,6 +6,7 @@ LL | main(); | = help: consider using another function for this recursion = note: `-D clippy::main-recursion` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::main_recursion)]` error: aborting due to previous error diff --git a/tests/ui/create_dir.stderr b/tests/ui/create_dir.stderr index 5c005bee761e..037e6ff173ac 100644 --- a/tests/ui/create_dir.stderr +++ b/tests/ui/create_dir.stderr @@ -5,6 +5,7 @@ LL | std::fs::create_dir("foo"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `create_dir_all("foo")` | = note: `-D clippy::create-dir` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::create_dir)]` error: calling `std::fs::create_dir` where there may be a better way --> $DIR/create_dir.rs:11:5 diff --git a/tests/ui/dbg_macro.stderr b/tests/ui/dbg_macro.stderr index e63d07a5f247..f45a7ba1faeb 100644 --- a/tests/ui/dbg_macro.stderr +++ b/tests/ui/dbg_macro.stderr @@ -5,6 +5,7 @@ LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } | ^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::dbg-macro` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::dbg_macro)]` help: remove the invocation before committing it to a version control system | LL | if let Some(n) = n.checked_sub(4) { n } else { n } diff --git a/tests/ui/debug_assert_with_mut_call.stderr b/tests/ui/debug_assert_with_mut_call.stderr index 97c47064a335..b993bbf5526d 100644 --- a/tests/ui/debug_assert_with_mut_call.stderr +++ b/tests/ui/debug_assert_with_mut_call.stderr @@ -5,6 +5,7 @@ LL | debug_assert!(bool_mut(&mut 3)); | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::debug-assert-with-mut-call` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::debug_assert_with_mut_call)]` error: do not call a function with mutable arguments inside of `debug_assert!` --> $DIR/debug_assert_with_mut_call.rs:45:20 diff --git a/tests/ui/decimal_literal_representation.stderr b/tests/ui/decimal_literal_representation.stderr index 2f126073c337..f1d4d744e731 100644 --- a/tests/ui/decimal_literal_representation.stderr +++ b/tests/ui/decimal_literal_representation.stderr @@ -5,6 +5,7 @@ LL | 32_773, // 0x8005 | ^^^^^^ help: consider: `0x8005` | = note: `-D clippy::decimal-literal-representation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::decimal_literal_representation)]` error: integer literal has a better hexadecimal representation --> $DIR/decimal_literal_representation.rs:17:9 diff --git a/tests/ui/declare_interior_mutable_const/enums.stderr b/tests/ui/declare_interior_mutable_const/enums.stderr index 6070df749ca9..6d34373886d5 100644 --- a/tests/ui/declare_interior_mutable_const/enums.stderr +++ b/tests/ui/declare_interior_mutable_const/enums.stderr @@ -7,6 +7,7 @@ LL | const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(tru | make this a static item (maybe with lazy_static) | = note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::declare_interior_mutable_const)]` error: a `const` item should never be interior mutable --> $DIR/enums.rs:23:1 diff --git a/tests/ui/declare_interior_mutable_const/others.stderr b/tests/ui/declare_interior_mutable_const/others.stderr index 0259f6a4a286..cc286b9f7f68 100644 --- a/tests/ui/declare_interior_mutable_const/others.stderr +++ b/tests/ui/declare_interior_mutable_const/others.stderr @@ -7,6 +7,7 @@ LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5); | make this a static item (maybe with lazy_static) | = note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::declare_interior_mutable_const)]` error: a `const` item should never be interior mutable --> $DIR/others.rs:10:1 diff --git a/tests/ui/declare_interior_mutable_const/traits.stderr b/tests/ui/declare_interior_mutable_const/traits.stderr index ef62919dfead..7647cd96fec7 100644 --- a/tests/ui/declare_interior_mutable_const/traits.stderr +++ b/tests/ui/declare_interior_mutable_const/traits.stderr @@ -5,6 +5,7 @@ LL | const ATOMIC: AtomicUsize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::declare_interior_mutable_const)]` error: a `const` item should never be interior mutable --> $DIR/traits.rs:9:9 diff --git a/tests/ui/def_id_nocore.stderr b/tests/ui/def_id_nocore.stderr index f8fc17e872bd..bfd0de4e13ac 100644 --- a/tests/ui/def_id_nocore.stderr +++ b/tests/ui/def_id_nocore.stderr @@ -6,6 +6,7 @@ LL | pub fn as_ref(self) -> &'static str { | = help: consider choosing a less ambiguous name = note: `-D clippy::wrong-self-convention` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wrong_self_convention)]` error: aborting due to previous error diff --git a/tests/ui/default_constructed_unit_structs.stderr b/tests/ui/default_constructed_unit_structs.stderr index 25128b89f2e9..434c72aa9b17 100644 --- a/tests/ui/default_constructed_unit_structs.stderr +++ b/tests/ui/default_constructed_unit_structs.stderr @@ -5,6 +5,7 @@ LL | Self::default() | ^^^^^^^^^^^ help: remove this call to `default` | = note: `-D clippy::default-constructed-unit-structs` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::default_constructed_unit_structs)]` error: use of `default` to create a unit struct --> $DIR/default_constructed_unit_structs.rs:53:31 diff --git a/tests/ui/default_instead_of_iter_empty.stderr b/tests/ui/default_instead_of_iter_empty.stderr index 2763ad6120e7..48d6c02d150d 100644 --- a/tests/ui/default_instead_of_iter_empty.stderr +++ b/tests/ui/default_instead_of_iter_empty.stderr @@ -5,6 +5,7 @@ LL | let _ = std::iter::Empty::::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::empty::()` | = note: `-D clippy::default-instead-of-iter-empty` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::default_instead_of_iter_empty)]` error: `std::iter::empty()` is the more idiomatic way --> $DIR/default_instead_of_iter_empty.rs:13:13 diff --git a/tests/ui/default_numeric_fallback_f64.stderr b/tests/ui/default_numeric_fallback_f64.stderr index 7aa2ad252285..7ea2e3e68194 100644 --- a/tests/ui/default_numeric_fallback_f64.stderr +++ b/tests/ui/default_numeric_fallback_f64.stderr @@ -5,6 +5,7 @@ LL | let x = 0.12; | ^^^^ help: consider adding suffix: `0.12_f64` | = note: `-D clippy::default-numeric-fallback` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::default_numeric_fallback)]` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:22:18 diff --git a/tests/ui/default_numeric_fallback_i32.stderr b/tests/ui/default_numeric_fallback_i32.stderr index 586f4fc0c03d..b03b8b84c332 100644 --- a/tests/ui/default_numeric_fallback_i32.stderr +++ b/tests/ui/default_numeric_fallback_i32.stderr @@ -5,6 +5,7 @@ LL | let x = 22; | ^^ help: consider adding suffix: `22_i32` | = note: `-D clippy::default-numeric-fallback` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::default_numeric_fallback)]` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_i32.rs:22:18 diff --git a/tests/ui/default_union_representation.stderr b/tests/ui/default_union_representation.stderr index 256eebc44200..82f69ffeec37 100644 --- a/tests/ui/default_union_representation.stderr +++ b/tests/ui/default_union_representation.stderr @@ -10,6 +10,7 @@ LL | | } | = help: consider annotating `NoAttribute` with `#[repr(C)]` to explicitly specify memory layout = note: `-D clippy::default-union-representation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::default_union_representation)]` error: this union has the default representation --> $DIR/default_union_representation.rs:17:1 diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr index 0e142ac8f20e..388fcc238466 100644 --- a/tests/ui/deprecated.stderr +++ b/tests/ui/deprecated.stderr @@ -5,6 +5,7 @@ LL | #![warn(clippy::should_assert_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D renamed-and-removed-lints` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(renamed_and_removed_lints)]` error: lint `clippy::extend_from_slice` has been removed: `.extend_from_slice(_)` is a faster way to extend a Vec by a slice --> $DIR/deprecated.rs:6:9 diff --git a/tests/ui/deprecated_old.stderr b/tests/ui/deprecated_old.stderr index 5a6c4be80b24..d27ad852f97f 100644 --- a/tests/ui/deprecated_old.stderr +++ b/tests/ui/deprecated_old.stderr @@ -5,6 +5,7 @@ LL | #[warn(unstable_as_slice)] | ^^^^^^^^^^^^^^^^^ | = note: `-D renamed-and-removed-lints` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(renamed_and_removed_lints)]` error: lint `unstable_as_mut_slice` has been removed: `Vec::as_mut_slice` has been stabilized in 1.7 --> $DIR/deprecated_old.rs:4:8 diff --git a/tests/ui/deref_addrof.stderr b/tests/ui/deref_addrof.stderr index 5918a33f38bf..b01fa4df6b1f 100644 --- a/tests/ui/deref_addrof.stderr +++ b/tests/ui/deref_addrof.stderr @@ -5,6 +5,7 @@ LL | let b = *&a; | ^^^ help: try: `a` | = note: `-D clippy::deref-addrof` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::deref_addrof)]` error: immediately dereferencing a reference --> $DIR/deref_addrof.rs:25:13 diff --git a/tests/ui/deref_addrof_double_trigger.stderr b/tests/ui/deref_addrof_double_trigger.stderr index 3463f0a1ab73..78ec73400162 100644 --- a/tests/ui/deref_addrof_double_trigger.stderr +++ b/tests/ui/deref_addrof_double_trigger.stderr @@ -5,6 +5,7 @@ LL | let b = **&&a; | ^^^^ help: try: `&a` | = note: `-D clippy::deref-addrof` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::deref_addrof)]` error: immediately dereferencing a reference --> $DIR/deref_addrof_double_trigger.rs:16:17 diff --git a/tests/ui/deref_by_slicing.stderr b/tests/ui/deref_by_slicing.stderr index b22c18c492db..7b8144a9a6e1 100644 --- a/tests/ui/deref_by_slicing.stderr +++ b/tests/ui/deref_by_slicing.stderr @@ -5,6 +5,7 @@ LL | let _ = &vec[..]; | ^^^^^^^^ help: dereference the original value instead: `&*vec` | = note: `-D clippy::deref-by-slicing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::deref_by_slicing)]` error: slicing when dereferencing would work --> $DIR/deref_by_slicing.rs:9:13 diff --git a/tests/ui/derivable_impls.stderr b/tests/ui/derivable_impls.stderr index b05af79e3fd6..98e2f3612904 100644 --- a/tests/ui/derivable_impls.stderr +++ b/tests/ui/derivable_impls.stderr @@ -11,6 +11,7 @@ LL | | } | |_^ | = note: `-D clippy::derivable-impls` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::derivable_impls)]` = help: remove the manual implementation... help: ...and instead derive it | diff --git a/tests/ui/derive.stderr b/tests/ui/derive.stderr index 2986296bcaf7..e9b2ee34760f 100644 --- a/tests/ui/derive.stderr +++ b/tests/ui/derive.stderr @@ -20,6 +20,7 @@ LL | | } LL | | } | |_^ = note: `-D clippy::expl-impl-clone-on-copy` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::expl_impl_clone_on_copy)]` error: you are implementing `Clone` explicitly on a `Copy` type --> $DIR/derive.rs:37:1 diff --git a/tests/ui/derive_ord_xor_partial_ord.stderr b/tests/ui/derive_ord_xor_partial_ord.stderr index ee900c5ea276..7555c12b196d 100644 --- a/tests/ui/derive_ord_xor_partial_ord.stderr +++ b/tests/ui/derive_ord_xor_partial_ord.stderr @@ -10,6 +10,7 @@ note: `PartialOrd` implemented here LL | impl PartialOrd for DeriveOrd { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::derive-ord-xor-partial-ord` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::derive_ord_xor_partial_ord)]` = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `Ord` but have implemented `PartialOrd` explicitly diff --git a/tests/ui/derive_partial_eq_without_eq.stderr b/tests/ui/derive_partial_eq_without_eq.stderr index 91729abc2bbb..abfd70e8c3d5 100644 --- a/tests/ui/derive_partial_eq_without_eq.stderr +++ b/tests/ui/derive_partial_eq_without_eq.stderr @@ -5,6 +5,7 @@ LL | #[derive(Debug, PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` | = note: `-D clippy::derive-partial-eq-without-eq` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::derive_partial_eq_without_eq)]` error: you are deriving `PartialEq` and can implement `Eq` --> $DIR/derive_partial_eq_without_eq.rs:53:10 diff --git a/tests/ui/disallowed_names.stderr b/tests/ui/disallowed_names.stderr index 259501a94e78..3387906a0e5c 100644 --- a/tests/ui/disallowed_names.stderr +++ b/tests/ui/disallowed_names.stderr @@ -5,6 +5,7 @@ LL | fn test(foo: ()) {} | ^^^ | = note: `-D clippy::disallowed-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_names)]` error: use of a disallowed/placeholder name `foo` --> $DIR/disallowed_names.rs:17:9 diff --git a/tests/ui/diverging_sub_expression.stderr b/tests/ui/diverging_sub_expression.stderr index 042e2690ec41..d8021c5d7ba8 100644 --- a/tests/ui/diverging_sub_expression.stderr +++ b/tests/ui/diverging_sub_expression.stderr @@ -5,6 +5,7 @@ LL | b || diverge(); | ^^^^^^^^^ | = note: `-D clippy::diverging-sub-expression` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::diverging_sub_expression)]` error: sub-expression diverges --> $DIR/diverging_sub_expression.rs:23:10 diff --git a/tests/ui/doc/doc-fixable.stderr b/tests/ui/doc/doc-fixable.stderr index dda764f8493b..a30ded81385f 100644 --- a/tests/ui/doc/doc-fixable.stderr +++ b/tests/ui/doc/doc-fixable.stderr @@ -5,6 +5,7 @@ LL | /// The foo_bar function does _nothing_. See also foo::bar. (note the dot t | ^^^^^^^ | = note: `-D clippy::doc-markdown` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | LL | /// The `foo_bar` function does _nothing_. See also foo::bar. (note the dot there) diff --git a/tests/ui/doc/unbalanced_ticks.stderr b/tests/ui/doc/unbalanced_ticks.stderr index 7a3544288be8..92b6f8536c88 100644 --- a/tests/ui/doc/unbalanced_ticks.stderr +++ b/tests/ui/doc/unbalanced_ticks.stderr @@ -10,6 +10,7 @@ LL | | /// very `confusing_and_misleading`. | = help: a backtick may be missing a pair = note: `-D clippy::doc-markdown` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` error: backticks are unbalanced --> $DIR/unbalanced_ticks.rs:14:1 diff --git a/tests/ui/doc_errors.stderr b/tests/ui/doc_errors.stderr index a0356623003e..9cea864f1d86 100644 --- a/tests/ui/doc_errors.stderr +++ b/tests/ui/doc_errors.stderr @@ -5,6 +5,7 @@ LL | pub fn pub_fn_missing_errors_header() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::missing-errors-doc` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_errors_doc)]` error: docs for function returning `Result` missing `# Errors` section --> $DIR/doc_errors.rs:13:1 diff --git a/tests/ui/doc_link_with_quotes.stderr b/tests/ui/doc_link_with_quotes.stderr index ea730e667d65..2db1bc092895 100644 --- a/tests/ui/doc_link_with_quotes.stderr +++ b/tests/ui/doc_link_with_quotes.stderr @@ -5,6 +5,7 @@ LL | /// Calls ['bar'] uselessly | ^^^^^ | = note: `-D clippy::doc-link-with-quotes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::doc_link_with_quotes)]` error: aborting due to previous error diff --git a/tests/ui/doc_unsafe.stderr b/tests/ui/doc_unsafe.stderr index a86e191370e3..ab3fb3c029dd 100644 --- a/tests/ui/doc_unsafe.stderr +++ b/tests/ui/doc_unsafe.stderr @@ -5,6 +5,7 @@ LL | pub unsafe fn destroy_the_planet() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::missing-safety-doc` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_safety_doc)]` error: unsafe function's docs miss `# Safety` section --> $DIR/doc_unsafe.rs:32:5 diff --git a/tests/ui/double_comparison.stderr b/tests/ui/double_comparison.stderr index 05ef4e25f7f8..02f0a960974b 100644 --- a/tests/ui/double_comparison.stderr +++ b/tests/ui/double_comparison.stderr @@ -5,6 +5,7 @@ LL | if x == y || x < y { | ^^^^^^^^^^^^^^^ help: try: `x <= y` | = note: `-D clippy::double-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::double_comparisons)]` error: this binary expression can be simplified --> $DIR/double_comparison.rs:9:8 diff --git a/tests/ui/double_must_use.stderr b/tests/ui/double_must_use.stderr index 46d56006ebfc..a2d87c59ecf8 100644 --- a/tests/ui/double_must_use.stderr +++ b/tests/ui/double_must_use.stderr @@ -6,6 +6,7 @@ LL | pub fn must_use_result() -> Result<(), ()> { | = help: either add some descriptive text or remove the attribute = note: `-D clippy::double-must-use` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::double_must_use)]` error: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]` --> $DIR/double_must_use.rs:11:1 diff --git a/tests/ui/double_neg.stderr b/tests/ui/double_neg.stderr index 7cdb040b6873..a6241c78610a 100644 --- a/tests/ui/double_neg.stderr +++ b/tests/ui/double_neg.stderr @@ -5,6 +5,7 @@ LL | --x; | ^^^ | = note: `-D clippy::double-neg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::double_neg)]` error: aborting due to previous error diff --git a/tests/ui/double_parens.stderr b/tests/ui/double_parens.stderr index 303ddce02483..8a010d8ccc04 100644 --- a/tests/ui/double_parens.stderr +++ b/tests/ui/double_parens.stderr @@ -5,6 +5,7 @@ LL | ((0)) | ^^^^^ | = note: `-D clippy::double-parens` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::double_parens)]` error: consider removing unnecessary double parentheses --> $DIR/double_parens.rs:21:14 diff --git a/tests/ui/drop_non_drop.stderr b/tests/ui/drop_non_drop.stderr index 15e7c6eeca27..a571076f68cd 100644 --- a/tests/ui/drop_non_drop.stderr +++ b/tests/ui/drop_non_drop.stderr @@ -10,6 +10,7 @@ note: argument has type `main::Foo` LL | drop(Foo); | ^^^ = note: `-D clippy::drop-non-drop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::drop_non_drop)]` error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes --> $DIR/drop_non_drop.rs:38:5 diff --git a/tests/ui/duplicate_underscore_argument.stderr b/tests/ui/duplicate_underscore_argument.stderr index f71614a5fd16..f47f6c89622d 100644 --- a/tests/ui/duplicate_underscore_argument.stderr +++ b/tests/ui/duplicate_underscore_argument.stderr @@ -5,6 +5,7 @@ LL | fn join_the_dark_side(darth: i32, _darth: i32) {} | ^^^^^ | = note: `-D clippy::duplicate-underscore-argument` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::duplicate_underscore_argument)]` error: aborting due to previous error diff --git a/tests/ui/duration_subsec.stderr b/tests/ui/duration_subsec.stderr index 6c1fd433e7cc..705683837123 100644 --- a/tests/ui/duration_subsec.stderr +++ b/tests/ui/duration_subsec.stderr @@ -5,6 +5,7 @@ LL | let bad_millis_1 = dur.subsec_micros() / 1_000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_millis()` | = note: `-D clippy::duration-subsec` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::duration_subsec)]` error: calling `subsec_millis()` is more concise than this calculation --> $DIR/duration_subsec.rs:10:24 diff --git a/tests/ui/else_if_without_else.stderr b/tests/ui/else_if_without_else.stderr index 11baf75441ae..b2bf4ac4d1b1 100644 --- a/tests/ui/else_if_without_else.stderr +++ b/tests/ui/else_if_without_else.stderr @@ -10,6 +10,7 @@ LL | | } | = help: add an `else` block here = note: `-D clippy::else-if-without-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::else_if_without_else)]` error: `if` expression with an `else if`, but without a final `else` --> $DIR/else_if_without_else.rs:54:12 diff --git a/tests/ui/empty_drop.stderr b/tests/ui/empty_drop.stderr index e95216937263..5848eab74474 100644 --- a/tests/ui/empty_drop.stderr +++ b/tests/ui/empty_drop.stderr @@ -7,6 +7,7 @@ LL | | } | |_^ help: try removing this impl | = note: `-D clippy::empty-drop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_drop)]` error: empty drop implementation --> $DIR/empty_drop.rs:23:1 diff --git a/tests/ui/empty_enum.stderr b/tests/ui/empty_enum.stderr index 0d9aa5818e28..92d81c7269a5 100644 --- a/tests/ui/empty_enum.stderr +++ b/tests/ui/empty_enum.stderr @@ -6,6 +6,7 @@ LL | enum Empty {} | = help: consider using the uninhabited type `!` (never type) or a wrapper around it to introduce a type which can't be instantiated = note: `-D clippy::empty-enum` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_enum)]` error: aborting due to previous error diff --git a/tests/ui/empty_line_after_doc_comments.stderr b/tests/ui/empty_line_after_doc_comments.stderr index 2ca1b51679ed..2cf5b5b0f549 100644 --- a/tests/ui/empty_line_after_doc_comments.stderr +++ b/tests/ui/empty_line_after_doc_comments.stderr @@ -7,6 +7,7 @@ LL | | fn with_doc_and_newline() { assert!(true)} | |_ | = note: `-D clippy::empty-line-after-doc-comments` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_doc_comments)]` error: found an empty line after a doc comment. Perhaps you need to use `//!` to make a comment on a module, remove the empty line, or make a regular comment with `//`? --> $DIR/empty_line_after_doc_comments.rs:68:1 diff --git a/tests/ui/empty_line_after_outer_attribute.stderr b/tests/ui/empty_line_after_outer_attribute.stderr index 594fca44a321..0cb848c20dde 100644 --- a/tests/ui/empty_line_after_outer_attribute.stderr +++ b/tests/ui/empty_line_after_outer_attribute.stderr @@ -8,6 +8,7 @@ LL | | fn with_one_newline_and_comment() { assert!(true) } | |_ | = note: `-D clippy::empty-line-after-outer-attr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_outer_attr)]` error: found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute? --> $DIR/empty_line_after_outer_attribute.rs:23:1 diff --git a/tests/ui/empty_loop.stderr b/tests/ui/empty_loop.stderr index 7602412334bb..84d7d61c7daa 100644 --- a/tests/ui/empty_loop.stderr +++ b/tests/ui/empty_loop.stderr @@ -6,6 +6,7 @@ LL | loop {} | = help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body = note: `-D clippy::empty-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_loop)]` error: empty `loop {}` wastes CPU cycles --> $DIR/empty_loop.rs:11:9 diff --git a/tests/ui/empty_loop_no_std.stderr b/tests/ui/empty_loop_no_std.stderr index 417b7f01c78a..90200826472b 100644 --- a/tests/ui/empty_loop_no_std.stderr +++ b/tests/ui/empty_loop_no_std.stderr @@ -6,6 +6,7 @@ LL | loop {} | = help: you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body = note: `-D clippy::empty-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_loop)]` error: empty `loop {}` wastes CPU cycles --> $DIR/empty_loop_no_std.rs:26:5 diff --git a/tests/ui/empty_structs_with_brackets.stderr b/tests/ui/empty_structs_with_brackets.stderr index ba3013750d56..4b8572d5c9ef 100644 --- a/tests/ui/empty_structs_with_brackets.stderr +++ b/tests/ui/empty_structs_with_brackets.stderr @@ -5,6 +5,7 @@ LL | pub struct MyEmptyStruct {} // should trigger lint | ^^^ | = note: `-D clippy::empty-structs-with-brackets` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_structs_with_brackets)]` = help: remove the brackets error: found empty brackets on struct declaration diff --git a/tests/ui/endian_bytes.stderr b/tests/ui/endian_bytes.stderr index 5e64ea5b5ab8..a458c46fa69a 100644 --- a/tests/ui/endian_bytes.stderr +++ b/tests/ui/endian_bytes.stderr @@ -9,6 +9,7 @@ LL | fn host() { fn_body!(); } | = help: specify the desired endianness explicitly = note: `-D clippy::host-endian-bytes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::host_endian_bytes)]` = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i8::to_ne_bytes` method @@ -346,6 +347,7 @@ LL | fn little() { fn_body!(); } | = help: use the native endianness instead = note: `-D clippy::little-endian-bytes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::little_endian_bytes)]` = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i8::to_le_bytes` method @@ -707,6 +709,7 @@ LL | fn host_encourage_little() { fn_body_smol!(); } | = help: use `u8::to_le_bytes` instead = note: `-D clippy::big-endian-bytes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::big_endian_bytes)]` = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_be_bytes` diff --git a/tests/ui/entry.stderr b/tests/ui/entry.stderr index e89d15cc1af7..b01f0a9a0e56 100644 --- a/tests/ui/entry.stderr +++ b/tests/ui/entry.stderr @@ -7,6 +7,7 @@ LL | | } | |_____^ help: try: `m.entry(k).or_insert(v);` | = note: `-D clippy::map-entry` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_entry)]` error: usage of `contains_key` followed by `insert` on a `HashMap` --> $DIR/entry.rs:29:5 diff --git a/tests/ui/entry_btree.stderr b/tests/ui/entry_btree.stderr index e5a1365eae93..cc0e951d9b42 100644 --- a/tests/ui/entry_btree.stderr +++ b/tests/ui/entry_btree.stderr @@ -8,6 +8,7 @@ LL | | } | |_____^ | = note: `-D clippy::map-entry` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_entry)]` help: try | LL ~ if let std::collections::btree_map::Entry::Vacant(e) = m.entry(k) { diff --git a/tests/ui/entry_with_else.stderr b/tests/ui/entry_with_else.stderr index a0f39568708c..425e87122d57 100644 --- a/tests/ui/entry_with_else.stderr +++ b/tests/ui/entry_with_else.stderr @@ -9,6 +9,7 @@ LL | | } | |_____^ | = note: `-D clippy::map-entry` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_entry)]` help: try | LL ~ match m.entry(k) { diff --git a/tests/ui/enum_glob_use.stderr b/tests/ui/enum_glob_use.stderr index c1851f92765b..8b94e67f87ea 100644 --- a/tests/ui/enum_glob_use.stderr +++ b/tests/ui/enum_glob_use.stderr @@ -5,6 +5,7 @@ LL | use std::cmp::Ordering::*; | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::cmp::Ordering::Less` | = note: `-D clippy::enum-glob-use` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::enum_glob_use)]` error: usage of wildcard import for enum variants --> $DIR/enum_glob_use.rs:11:5 diff --git a/tests/ui/enum_variants.stderr b/tests/ui/enum_variants.stderr index 1cfe48cd797f..9ea80b635f46 100644 --- a/tests/ui/enum_variants.stderr +++ b/tests/ui/enum_variants.stderr @@ -5,6 +5,7 @@ LL | cFoo, | ^^^^ | = note: `-D clippy::enum-variant-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::enum_variant_names)]` error: all variants have the same prefix: `c` --> $DIR/enum_variants.rs:14:1 diff --git a/tests/ui/eprint_with_newline.stderr b/tests/ui/eprint_with_newline.stderr index 934c4c831731..674b4fdaed50 100644 --- a/tests/ui/eprint_with_newline.stderr +++ b/tests/ui/eprint_with_newline.stderr @@ -5,6 +5,7 @@ LL | eprint!("Hello\n"); | ^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::print-with-newline` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_with_newline)]` help: use `eprintln!` instead | LL - eprint!("Hello\n"); diff --git a/tests/ui/eq_op.stderr b/tests/ui/eq_op.stderr index 315d94cc90e6..2427ac0dda55 100644 --- a/tests/ui/eq_op.stderr +++ b/tests/ui/eq_op.stderr @@ -5,6 +5,7 @@ LL | let _ = 1 == 1; | ^^^^^^ | = note: `-D clippy::eq-op` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::eq_op)]` error: equal expressions as operands to `==` --> $DIR/eq_op.rs:10:13 diff --git a/tests/ui/eq_op_macros.stderr b/tests/ui/eq_op_macros.stderr index 3c60cdbc5ca9..0df26607aa6e 100644 --- a/tests/ui/eq_op_macros.stderr +++ b/tests/ui/eq_op_macros.stderr @@ -8,6 +8,7 @@ LL | assert_in_macro_def!(); | ---------------------- in this macro invocation | = note: `-D clippy::eq-op` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::eq_op)]` = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) error: identical args used in this `assert_ne!` macro call diff --git a/tests/ui/equatable_if_let.stderr b/tests/ui/equatable_if_let.stderr index 3b6cbbabbe2b..6cc19d829edc 100644 --- a/tests/ui/equatable_if_let.stderr +++ b/tests/ui/equatable_if_let.stderr @@ -5,6 +5,7 @@ LL | if let 2 = a {} | ^^^^^^^^^ help: try: `a == 2` | = note: `-D clippy::equatable-if-let` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::equatable_if_let)]` error: this pattern matching can be expressed using equality --> $DIR/equatable_if_let.rs:65:8 diff --git a/tests/ui/erasing_op.stderr b/tests/ui/erasing_op.stderr index 7b9608fe4522..1b50a05cd228 100644 --- a/tests/ui/erasing_op.stderr +++ b/tests/ui/erasing_op.stderr @@ -5,6 +5,7 @@ LL | x * 0; | ^^^^^ | = note: `-D clippy::erasing-op` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::erasing_op)]` error: this operation will always return zero. This is likely not the intended outcome --> $DIR/erasing_op.rs:38:5 diff --git a/tests/ui/err_expect.stderr b/tests/ui/err_expect.stderr index e3046a5a13a7..da7cd47f0bb4 100644 --- a/tests/ui/err_expect.stderr +++ b/tests/ui/err_expect.stderr @@ -5,6 +5,7 @@ LL | test_debug.err().expect("Testing debug type"); | ^^^^^^^^^^^^ help: try: `expect_err` | = note: `-D clippy::err-expect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::err_expect)]` error: called `.err().expect()` on a `Result` value --> $DIR/err_expect.rs:25:7 diff --git a/tests/ui/error_impl_error.stderr b/tests/ui/error_impl_error.stderr index 54a55d5dcf4b..d7a1aa829890 100644 --- a/tests/ui/error_impl_error.stderr +++ b/tests/ui/error_impl_error.stderr @@ -10,6 +10,7 @@ note: `Error` was implemented here LL | impl std::error::Error for Error {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::error-impl-error` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::error_impl_error)]` error: exported type named `Error` that implements `Error` --> $DIR/error_impl_error.rs:21:21 diff --git a/tests/ui/eta.stderr b/tests/ui/eta.stderr index db6184e36a43..7c7f17974620 100644 --- a/tests/ui/eta.stderr +++ b/tests/ui/eta.stderr @@ -5,6 +5,7 @@ LL | let a = Some(1u8).map(|a| foo(a)); | ^^^^^^^^^^ help: replace the closure with the function itself: `foo` | = note: `-D clippy::redundant-closure` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_closure)]` error: redundant closure --> $DIR/eta.rs:32:40 @@ -37,6 +38,7 @@ LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); | ^^^^^^^^^^^ help: replace the closure with the method itself: `TestStruct::foo` | = note: `-D clippy::redundant-closure-for-method-calls` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_for_method_calls)]` error: redundant closure --> $DIR/eta.rs:94:51 diff --git a/tests/ui/excessive_precision.stderr b/tests/ui/excessive_precision.stderr index a1f874e93d44..5e7672e185af 100644 --- a/tests/ui/excessive_precision.stderr +++ b/tests/ui/excessive_precision.stderr @@ -5,6 +5,7 @@ LL | const BAD32_1: f32 = 0.123_456_789_f32; | ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79_f32` | = note: `-D clippy::excessive-precision` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::excessive_precision)]` error: float has excessive precision --> $DIR/excessive_precision.rs:21:26 diff --git a/tests/ui/exit1.stderr b/tests/ui/exit1.stderr index a8d3956aa27a..94d8f1e32ee1 100644 --- a/tests/ui/exit1.stderr +++ b/tests/ui/exit1.stderr @@ -5,6 +5,7 @@ LL | std::process::exit(4); | ^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::exit` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::exit)]` error: aborting due to previous error diff --git a/tests/ui/exit2.stderr b/tests/ui/exit2.stderr index 7263e156a9d2..cd324f182205 100644 --- a/tests/ui/exit2.stderr +++ b/tests/ui/exit2.stderr @@ -5,6 +5,7 @@ LL | std::process::exit(3); | ^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::exit` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::exit)]` error: aborting due to previous error diff --git a/tests/ui/expect.stderr b/tests/ui/expect.stderr index c9a29624d530..35a258a85e4e 100644 --- a/tests/ui/expect.stderr +++ b/tests/ui/expect.stderr @@ -6,6 +6,7 @@ LL | let _ = opt.expect(""); | = note: if this value is `None`, it will panic = note: `-D clippy::expect-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::expect_used)]` error: used `expect()` on a `Result` value --> $DIR/expect.rs:12:13 diff --git a/tests/ui/expect_fun_call.stderr b/tests/ui/expect_fun_call.stderr index b5ab580ad000..dd3976f3624c 100644 --- a/tests/ui/expect_fun_call.stderr +++ b/tests/ui/expect_fun_call.stderr @@ -5,6 +5,7 @@ LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))` | = note: `-D clippy::expect-fun-call` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::expect_fun_call)]` error: use of `expect` followed by a function call --> $DIR/expect_fun_call.rs:40:26 diff --git a/tests/ui/expect_tool_lint_rfc_2383.stderr b/tests/ui/expect_tool_lint_rfc_2383.stderr index 1a08d77113a4..3f8d0b724362 100644 --- a/tests/ui/expect_tool_lint_rfc_2383.stderr +++ b/tests/ui/expect_tool_lint_rfc_2383.stderr @@ -5,6 +5,7 @@ LL | #[expect(dead_code)] | ^^^^^^^^^ | = note: `-D unfulfilled-lint-expectations` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(unfulfilled_lint_expectations)]` error: this lint expectation is unfulfilled --> $DIR/expect_tool_lint_rfc_2383.rs:41:18 diff --git a/tests/ui/explicit_auto_deref.stderr b/tests/ui/explicit_auto_deref.stderr index 34ce188530c3..bea014d8ad55 100644 --- a/tests/ui/explicit_auto_deref.stderr +++ b/tests/ui/explicit_auto_deref.stderr @@ -5,6 +5,7 @@ LL | let _: &str = &*s; | ^^^ help: try: `&s` | = note: `-D clippy::explicit-auto-deref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::explicit_auto_deref)]` error: deref which would be done by auto-deref --> $DIR/explicit_auto_deref.rs:69:19 diff --git a/tests/ui/explicit_counter_loop.stderr b/tests/ui/explicit_counter_loop.stderr index 3b36f28617bb..aef979072525 100644 --- a/tests/ui/explicit_counter_loop.stderr +++ b/tests/ui/explicit_counter_loop.stderr @@ -5,6 +5,7 @@ LL | for _v in &vec { | ^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter().enumerate()` | = note: `-D clippy::explicit-counter-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::explicit_counter_loop)]` error: the variable `_index` is used as a loop counter --> $DIR/explicit_counter_loop.rs:15:5 diff --git a/tests/ui/explicit_deref_methods.stderr b/tests/ui/explicit_deref_methods.stderr index 362e559b21a5..eb7059367a20 100644 --- a/tests/ui/explicit_deref_methods.stderr +++ b/tests/ui/explicit_deref_methods.stderr @@ -5,6 +5,7 @@ LL | let b: &str = a.deref(); | ^^^^^^^^^ help: try: `&*a` | = note: `-D clippy::explicit-deref-methods` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::explicit_deref_methods)]` error: explicit `deref_mut` method call --> $DIR/explicit_deref_methods.rs:56:23 diff --git a/tests/ui/explicit_into_iter_loop.stderr b/tests/ui/explicit_into_iter_loop.stderr index 744be093b7b8..c03647ab4336 100644 --- a/tests/ui/explicit_into_iter_loop.stderr +++ b/tests/ui/explicit_into_iter_loop.stderr @@ -5,6 +5,7 @@ LL | for _ in iterator.into_iter() {} | ^^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `iterator` | = note: `-D clippy::explicit-into-iter-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::explicit_into_iter_loop)]` error: it is more concise to loop over containers instead of using explicit iteration methods --> $DIR/explicit_into_iter_loop.rs:22:14 diff --git a/tests/ui/explicit_iter_loop.stderr b/tests/ui/explicit_iter_loop.stderr index c311096117f6..af46d74e989a 100644 --- a/tests/ui/explicit_iter_loop.stderr +++ b/tests/ui/explicit_iter_loop.stderr @@ -53,6 +53,7 @@ LL | for _ in (&mut [1, 2, 3]).iter() {} | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::unnecessary-mut-passed` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_mut_passed)]` error: it is more concise to loop over references to containers instead of using explicit iteration methods --> $DIR/explicit_iter_loop.rs:33:14 diff --git a/tests/ui/explicit_write.stderr b/tests/ui/explicit_write.stderr index 230762c2db17..26aad266bbfc 100644 --- a/tests/ui/explicit_write.stderr +++ b/tests/ui/explicit_write.stderr @@ -5,6 +5,7 @@ LL | write!(std::io::stdout(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `print!("test")` | = note: `-D clippy::explicit-write` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::explicit_write)]` error: use of `write!(stderr(), ...).unwrap()` --> $DIR/explicit_write.rs:24:9 diff --git a/tests/ui/extend_with_drain.stderr b/tests/ui/extend_with_drain.stderr index 2c06d71e1020..e0bd5a620e78 100644 --- a/tests/ui/extend_with_drain.stderr +++ b/tests/ui/extend_with_drain.stderr @@ -5,6 +5,7 @@ LL | vec2.extend(vec1.drain(..)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec2.append(&mut vec1)` | = note: `-D clippy::extend-with-drain` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::extend_with_drain)]` error: use of `extend` instead of `append` for adding the full range of a second vector --> $DIR/extend_with_drain.rs:13:5 diff --git a/tests/ui/extra_unused_lifetimes.stderr b/tests/ui/extra_unused_lifetimes.stderr index 26ebc3976dfc..8790fe5a5b1a 100644 --- a/tests/ui/extra_unused_lifetimes.stderr +++ b/tests/ui/extra_unused_lifetimes.stderr @@ -5,6 +5,7 @@ LL | fn unused_lt<'a>(x: u8) {} | ^^ | = note: `-D clippy::extra-unused-lifetimes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::extra_unused_lifetimes)]` error: this lifetime isn't used in the function definition --> $DIR/extra_unused_lifetimes.rs:46:10 diff --git a/tests/ui/extra_unused_type_parameters.stderr b/tests/ui/extra_unused_type_parameters.stderr index 82cdc95a1d15..9a179076c482 100644 --- a/tests/ui/extra_unused_type_parameters.stderr +++ b/tests/ui/extra_unused_type_parameters.stderr @@ -5,6 +5,7 @@ LL | fn unused_ty(x: u8) { | ^^^ help: consider removing the parameter | = note: `-D clippy::extra-unused-type-parameters` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::extra_unused_type_parameters)]` error: type parameters go unused in function definition: T, U --> $DIR/extra_unused_type_parameters.rs:13:16 diff --git a/tests/ui/extra_unused_type_parameters_unfixable.stderr b/tests/ui/extra_unused_type_parameters_unfixable.stderr index bbd0cf478ab3..a216c4363075 100644 --- a/tests/ui/extra_unused_type_parameters_unfixable.stderr +++ b/tests/ui/extra_unused_type_parameters_unfixable.stderr @@ -6,6 +6,7 @@ LL | fn unused_where_clause(x: U) | = help: consider removing the parameter = note: `-D clippy::extra-unused-type-parameters` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::extra_unused_type_parameters)]` error: type parameters go unused in function definition: T, V --> $DIR/extra_unused_type_parameters_unfixable.rs:11:30 diff --git a/tests/ui/field_reassign_with_default.stderr b/tests/ui/field_reassign_with_default.stderr index da74f9ef9f7e..a8cf84bd4114 100644 --- a/tests/ui/field_reassign_with_default.stderr +++ b/tests/ui/field_reassign_with_default.stderr @@ -10,6 +10,7 @@ note: consider initializing the variable with `main::A { i: 42, ..Default::defau LL | let mut a: A = Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::field-reassign-with-default` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::field_reassign_with_default)]` error: field assignment outside of initializer for an instance created with Default::default() --> $DIR/field_reassign_with_default.rs:96:5 diff --git a/tests/ui/filetype_is_file.stderr b/tests/ui/filetype_is_file.stderr index 718d287e6799..8876ad5c9bbc 100644 --- a/tests/ui/filetype_is_file.stderr +++ b/tests/ui/filetype_is_file.stderr @@ -6,6 +6,7 @@ LL | if fs::metadata("foo.txt")?.file_type().is_file() { | = help: use `!FileType::is_dir()` instead = note: `-D clippy::filetype-is-file` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::filetype_is_file)]` error: `!FileType::is_file()` only denies regular files --> $DIR/filetype_is_file.rs:15:8 diff --git a/tests/ui/filter_map_bool_then.stderr b/tests/ui/filter_map_bool_then.stderr index c4215791c46f..86ef6edf8eed 100644 --- a/tests/ui/filter_map_bool_then.stderr +++ b/tests/ui/filter_map_bool_then.stderr @@ -5,6 +5,7 @@ LL | v.clone().iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` | = note: `-D clippy::filter-map-bool-then` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::filter_map_bool_then)]` error: usage of `bool::then` in `filter_map` --> $DIR/filter_map_bool_then.rs:20:27 diff --git a/tests/ui/filter_map_identity.stderr b/tests/ui/filter_map_identity.stderr index 248f6318f76a..a08477695c93 100644 --- a/tests/ui/filter_map_identity.stderr +++ b/tests/ui/filter_map_identity.stderr @@ -5,6 +5,7 @@ LL | let _ = iterator.filter_map(|x| x); | ^^^^^^^^^^^^^^^^^ help: try: `flatten()` | = note: `-D clippy::filter-map-identity` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::filter_map_identity)]` error: use of `filter_map` with an identity function --> $DIR/filter_map_identity.rs:9:22 diff --git a/tests/ui/filter_map_next.stderr b/tests/ui/filter_map_next.stderr index 3220ee51c2ac..1841553917ff 100644 --- a/tests/ui/filter_map_next.stderr +++ b/tests/ui/filter_map_next.stderr @@ -12,6 +12,7 @@ LL | | .next(); | |_______________^ | = note: `-D clippy::filter-map-next` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::filter_map_next)]` error: aborting due to previous error diff --git a/tests/ui/filter_map_next_fixable.stderr b/tests/ui/filter_map_next_fixable.stderr index fcbdbc31f353..0edf4e6e07d4 100644 --- a/tests/ui/filter_map_next_fixable.stderr +++ b/tests/ui/filter_map_next_fixable.stderr @@ -5,6 +5,7 @@ LL | let element: Option = a.iter().filter_map(|s| s.parse().ok()).next | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.iter().find_map(|s| s.parse().ok())` | = note: `-D clippy::filter-map-next` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::filter_map_next)]` error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead --> $DIR/filter_map_next_fixable.rs:20:26 diff --git a/tests/ui/flat_map_identity.stderr b/tests/ui/flat_map_identity.stderr index 6e4637874ace..d6fcc14fc563 100644 --- a/tests/ui/flat_map_identity.stderr +++ b/tests/ui/flat_map_identity.stderr @@ -5,6 +5,7 @@ LL | let _ = iterator.flat_map(|x| x); | ^^^^^^^^^^^^^^^ help: try: `flatten()` | = note: `-D clippy::flat-map-identity` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::flat_map_identity)]` error: use of `flat_map` with an identity function --> $DIR/flat_map_identity.rs:11:22 diff --git a/tests/ui/flat_map_option.stderr b/tests/ui/flat_map_option.stderr index c750902eb2fd..e0a59daf6a8f 100644 --- a/tests/ui/flat_map_option.stderr +++ b/tests/ui/flat_map_option.stderr @@ -5,6 +5,7 @@ LL | let _ = [1].iter().flat_map(c); | ^^^^^^^^ help: try: `filter_map` | = note: `-D clippy::flat-map-option` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::flat_map_option)]` error: used `flat_map` where `filter_map` could be used instead --> $DIR/flat_map_option.rs:8:24 diff --git a/tests/ui/float_arithmetic.stderr b/tests/ui/float_arithmetic.stderr index fe8446c98167..da4ca976792f 100644 --- a/tests/ui/float_arithmetic.stderr +++ b/tests/ui/float_arithmetic.stderr @@ -5,6 +5,7 @@ LL | f * 2.0; | ^^^^^^^ | = note: `-D clippy::float-arithmetic` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::float_arithmetic)]` error: floating-point arithmetic detected --> $DIR/float_arithmetic.rs:19:5 diff --git a/tests/ui/float_cmp.stderr b/tests/ui/float_cmp.stderr index 5836b5603d6e..cbe529954d0c 100644 --- a/tests/ui/float_cmp.stderr +++ b/tests/ui/float_cmp.stderr @@ -6,6 +6,7 @@ LL | ONE as f64 != 2.0; | = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` = note: `-D clippy::float-cmp` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::float_cmp)]` error: strict comparison of `f32` or `f64` --> $DIR/float_cmp.rs:64:5 diff --git a/tests/ui/float_cmp_const.stderr b/tests/ui/float_cmp_const.stderr index 4de1d58adc0f..856aaa2ea716 100644 --- a/tests/ui/float_cmp_const.stderr +++ b/tests/ui/float_cmp_const.stderr @@ -6,6 +6,7 @@ LL | 1f32 == ONE; | = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` = note: `-D clippy::float-cmp-const` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::float_cmp_const)]` error: strict comparison of `f32` or `f64` constant --> $DIR/float_cmp_const.rs:19:5 diff --git a/tests/ui/float_equality_without_abs.stderr b/tests/ui/float_equality_without_abs.stderr index c9806019f1fa..155699f6fcf0 100644 --- a/tests/ui/float_equality_without_abs.stderr +++ b/tests/ui/float_equality_without_abs.stderr @@ -7,6 +7,7 @@ LL | (a - b) < f32::EPSILON | help: add `.abs()`: `(a - b).abs()` | = note: `-D clippy::float-equality-without-abs` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::float_equality_without_abs)]` error: float equality check without `.abs()` --> $DIR/float_equality_without_abs.rs:15:13 diff --git a/tests/ui/floating_point_abs.stderr b/tests/ui/floating_point_abs.stderr index 464a0af5f9f5..fbc5783824d6 100644 --- a/tests/ui/floating_point_abs.stderr +++ b/tests/ui/floating_point_abs.stderr @@ -5,6 +5,7 @@ LL | if num >= 0.0 { num } else { -num } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()` | = note: `-D clippy::suboptimal-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: manual implementation of `abs` method --> $DIR/floating_point_abs.rs:19:5 diff --git a/tests/ui/floating_point_exp.stderr b/tests/ui/floating_point_exp.stderr index f84eede19872..6b64b9b60082 100644 --- a/tests/ui/floating_point_exp.stderr +++ b/tests/ui/floating_point_exp.stderr @@ -5,6 +5,7 @@ LL | let _ = x.exp() - 1.0; | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` | = note: `-D clippy::imprecise-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::imprecise_flops)]` error: (e.pow(x) - 1) can be computed more accurately --> $DIR/floating_point_exp.rs:7:13 diff --git a/tests/ui/floating_point_hypot.stderr b/tests/ui/floating_point_hypot.stderr index 82b0ed31204c..21e0bd8b5810 100644 --- a/tests/ui/floating_point_hypot.stderr +++ b/tests/ui/floating_point_hypot.stderr @@ -5,6 +5,7 @@ LL | let _ = (x * x + y * y).sqrt(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.hypot(y)` | = note: `-D clippy::imprecise-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::imprecise_flops)]` error: hypotenuse can be computed more accurately --> $DIR/floating_point_hypot.rs:7:13 diff --git a/tests/ui/floating_point_log.stderr b/tests/ui/floating_point_log.stderr index cbadd239aa2f..a426f4c3dde8 100644 --- a/tests/ui/floating_point_log.stderr +++ b/tests/ui/floating_point_log.stderr @@ -5,6 +5,7 @@ LL | let _ = x.log(2f32); | ^^^^^^^^^^^ help: consider using: `x.log2()` | = note: `-D clippy::suboptimal-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: logarithm for bases 2, 10 and e can be computed more accurately --> $DIR/floating_point_log.rs:10:13 @@ -61,6 +62,7 @@ LL | let _ = (1f32 + 2.).ln(); | ^^^^^^^^^^^^^^^^ help: consider using: `2.0f32.ln_1p()` | = note: `-D clippy::imprecise-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::imprecise_flops)]` error: ln(1 + x) can be computed more accurately --> $DIR/floating_point_log.rs:25:13 diff --git a/tests/ui/floating_point_logbase.stderr b/tests/ui/floating_point_logbase.stderr index 384e3554cbbe..463bdb84c159 100644 --- a/tests/ui/floating_point_logbase.stderr +++ b/tests/ui/floating_point_logbase.stderr @@ -5,6 +5,7 @@ LL | let _ = x.ln() / y.ln(); | ^^^^^^^^^^^^^^^ help: consider using: `x.log(y)` | = note: `-D clippy::suboptimal-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: log base can be expressed more clearly --> $DIR/floating_point_logbase.rs:8:13 diff --git a/tests/ui/floating_point_mul_add.stderr b/tests/ui/floating_point_mul_add.stderr index 613954724a5b..81b7126db54d 100644 --- a/tests/ui/floating_point_mul_add.stderr +++ b/tests/ui/floating_point_mul_add.stderr @@ -5,6 +5,7 @@ LL | let _ = a * b + c; | ^^^^^^^^^ help: consider using: `a.mul_add(b, c)` | = note: `-D clippy::suboptimal-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: multiply and add expressions can be calculated more efficiently and accurately --> $DIR/floating_point_mul_add.rs:21:13 diff --git a/tests/ui/floating_point_powf.stderr b/tests/ui/floating_point_powf.stderr index e9693de8fc90..0ff8f82d9a7d 100644 --- a/tests/ui/floating_point_powf.stderr +++ b/tests/ui/floating_point_powf.stderr @@ -5,6 +5,7 @@ LL | let _ = 2f32.powf(x); | ^^^^^^^^^^^^ help: consider using: `x.exp2()` | = note: `-D clippy::suboptimal-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: exponent for bases 2 and e can be computed more accurately --> $DIR/floating_point_powf.rs:7:13 @@ -49,6 +50,7 @@ LL | let _ = x.powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()` | = note: `-D clippy::imprecise-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::imprecise_flops)]` error: cube-root of a number can be computed more accurately --> $DIR/floating_point_powf.rs:14:13 diff --git a/tests/ui/floating_point_powi.stderr b/tests/ui/floating_point_powi.stderr index d60885e1b9a1..ddf20ff40ba2 100644 --- a/tests/ui/floating_point_powi.stderr +++ b/tests/ui/floating_point_powi.stderr @@ -5,6 +5,7 @@ LL | let _ = x.powi(2) + y; | ^^^^^^^^^^^^^ help: consider using: `x.mul_add(x, y)` | = note: `-D clippy::suboptimal-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: multiply and add expressions can be calculated more efficiently and accurately --> $DIR/floating_point_powi.rs:10:13 diff --git a/tests/ui/floating_point_rad.stderr b/tests/ui/floating_point_rad.stderr index 914358c98676..e7b42de04bdf 100644 --- a/tests/ui/floating_point_rad.stderr +++ b/tests/ui/floating_point_rad.stderr @@ -5,6 +5,7 @@ LL | let _ = degrees as f64 * std::f64::consts::PI / 180.0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(degrees as f64).to_radians()` | = note: `-D clippy::suboptimal-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: conversion to degrees can be done more accurately --> $DIR/floating_point_rad.rs:12:13 diff --git a/tests/ui/fn_address_comparisons.stderr b/tests/ui/fn_address_comparisons.stderr index 87415a0d9048..be7fa62f1b79 100644 --- a/tests/ui/fn_address_comparisons.stderr +++ b/tests/ui/fn_address_comparisons.stderr @@ -5,6 +5,7 @@ LL | let _ = f == a; | ^^^^^^ | = note: `-D clippy::fn-address-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::fn_address_comparisons)]` error: comparing with a non-unique address of a function item --> $DIR/fn_address_comparisons.rs:18:13 diff --git a/tests/ui/fn_params_excessive_bools.stderr b/tests/ui/fn_params_excessive_bools.stderr index db09418cd808..f529d8cc4110 100644 --- a/tests/ui/fn_params_excessive_bools.stderr +++ b/tests/ui/fn_params_excessive_bools.stderr @@ -6,6 +6,7 @@ LL | fn g(_: bool, _: bool, _: bool, _: bool) {} | = help: consider refactoring bools into two-variant enums = note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::fn_params_excessive_bools)]` error: more than 3 bools in function parameters --> $DIR/fn_params_excessive_bools.rs:23:1 diff --git a/tests/ui/fn_to_numeric_cast.stderr b/tests/ui/fn_to_numeric_cast.stderr index 5b2e8bdf30b0..53e8ac3c4b42 100644 --- a/tests/ui/fn_to_numeric_cast.stderr +++ b/tests/ui/fn_to_numeric_cast.stderr @@ -5,6 +5,7 @@ LL | let _ = foo as i8; | ^^^^^^^^^ help: try: `foo as usize` | = note: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_with_truncation)]` error: casting function pointer `foo` to `i16`, which truncates the value --> $DIR/fn_to_numeric_cast.rs:13:13 @@ -25,6 +26,7 @@ LL | let _ = foo as i64; | ^^^^^^^^^^ help: try: `foo as usize` | = note: `-D clippy::fn-to-numeric-cast` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast)]` error: casting function pointer `foo` to `i128` --> $DIR/fn_to_numeric_cast.rs:20:13 diff --git a/tests/ui/fn_to_numeric_cast_any.stderr b/tests/ui/fn_to_numeric_cast_any.stderr index 36058965479c..a1514c87b5ec 100644 --- a/tests/ui/fn_to_numeric_cast_any.stderr +++ b/tests/ui/fn_to_numeric_cast_any.stderr @@ -5,6 +5,7 @@ LL | let _ = foo as i8; | ^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i8` | = note: `-D clippy::fn-to-numeric-cast-any` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_any)]` error: casting function pointer `foo` to `i16` --> $DIR/fn_to_numeric_cast_any.rs:26:13 diff --git a/tests/ui/for_kv_map.stderr b/tests/ui/for_kv_map.stderr index d5e4ef0b4ba3..d29617e24f24 100644 --- a/tests/ui/for_kv_map.stderr +++ b/tests/ui/for_kv_map.stderr @@ -5,6 +5,7 @@ LL | for (_, v) in &m { | ^^ | = note: `-D clippy::for-kv-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::for_kv_map)]` help: use the corresponding method | LL | for v in m.values() { diff --git a/tests/ui/forget_non_drop.stderr b/tests/ui/forget_non_drop.stderr index 4634dc67f02d..c0fa433c479d 100644 --- a/tests/ui/forget_non_drop.stderr +++ b/tests/ui/forget_non_drop.stderr @@ -10,6 +10,7 @@ note: argument has type `main::Foo` LL | forget(Foo); | ^^^ = note: `-D clippy::forget-non-drop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::forget_non_drop)]` error: call to `std::mem::forget` with a value that does not implement `Drop`. Forgetting such a type is the same as dropping it --> $DIR/forget_non_drop.rs:25:5 diff --git a/tests/ui/format.stderr b/tests/ui/format.stderr index 7019e2c86754..d4630a8f1dab 100644 --- a/tests/ui/format.stderr +++ b/tests/ui/format.stderr @@ -5,6 +5,7 @@ LL | format!("foo"); | ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` | = note: `-D clippy::useless-format` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::useless_format)]` error: useless use of `format!` --> $DIR/format.rs:21:5 diff --git a/tests/ui/format_args.stderr b/tests/ui/format_args.stderr index a922f293b48e..dcdfa668aff3 100644 --- a/tests/ui/format_args.stderr +++ b/tests/ui/format_args.stderr @@ -5,6 +5,7 @@ LL | let _ = format!("error: something failed at {}", Location::caller().to_ | ^^^^^^^^^^^^ help: remove this | = note: `-D clippy::to-string-in-format-args` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::to_string_in_format_args)]` error: `to_string` applied to a type that implements `Display` in `write!` args --> $DIR/format_args.rs:80:27 diff --git a/tests/ui/format_args_unfixable.stderr b/tests/ui/format_args_unfixable.stderr index 430c43595793..3ffe2f6c8944 100644 --- a/tests/ui/format_args_unfixable.stderr +++ b/tests/ui/format_args_unfixable.stderr @@ -7,6 +7,7 @@ LL | println!("error: {}", format!("something failed at {}", Location::calle = help: combine the `format!(..)` arguments with the outer `println!(..)` call = help: or consider changing `format!` to `format_args!` = note: `-D clippy::format-in-format-args` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::format_in_format_args)]` error: `format!` in `println!` args --> $DIR/format_args_unfixable.rs:28:5 diff --git a/tests/ui/format_collect.stderr b/tests/ui/format_collect.stderr index 79e353111f38..340218ccf2c9 100644 --- a/tests/ui/format_collect.stderr +++ b/tests/ui/format_collect.stderr @@ -16,6 +16,7 @@ LL | bytes.iter().map(|b| format!("{b:02X}")).collect() | ^^^^^^^^^^^^^^^^^^ = note: this can be written more efficiently by appending to a `String` directly = note: `-D clippy::format-collect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::format_collect)]` error: use of `format!` to build up a string from an iterator --> $DIR/format_collect.rs:11:5 diff --git a/tests/ui/format_push_string.stderr b/tests/ui/format_push_string.stderr index d862dd6dc5f3..545915b56b56 100644 --- a/tests/ui/format_push_string.stderr +++ b/tests/ui/format_push_string.stderr @@ -6,6 +6,7 @@ LL | string += &format!("{:?}", 1234); | = help: consider using `write!` to avoid the extra allocation = note: `-D clippy::format-push-string` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::format_push_string)]` error: `format!(..)` appended to existing `String` --> $DIR/format_push_string.rs:7:5 diff --git a/tests/ui/formatting.stderr b/tests/ui/formatting.stderr index 1266d143cb16..d4eb8e511c8f 100644 --- a/tests/ui/formatting.stderr +++ b/tests/ui/formatting.stderr @@ -6,6 +6,7 @@ LL | a =- 35; | = note: to remove this lint, use either `-=` or `= -` = note: `-D clippy::suspicious-assignment-formatting` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_assignment_formatting)]` error: this looks like you are trying to use `.. *= ..`, but you really are doing `.. = (* ..)` --> $DIR/formatting.rs:19:6 @@ -31,6 +32,7 @@ LL | -1, -2, -3 // <= no comma here | = note: to remove this lint, add a comma or write the expr in a single line = note: `-D clippy::possible-missing-comma` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::possible_missing_comma)]` error: possibly missing a comma here --> $DIR/formatting.rs:41:19 diff --git a/tests/ui/four_forward_slashes.stderr b/tests/ui/four_forward_slashes.stderr index 89162e6b010e..6450c5f94601 100644 --- a/tests/ui/four_forward_slashes.stderr +++ b/tests/ui/four_forward_slashes.stderr @@ -6,6 +6,7 @@ LL | | fn a() {} | |_ | = note: `-D clippy::four-forward-slashes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::four_forward_slashes)]` help: make this a doc comment by removing one `/` | LL + /// whoops diff --git a/tests/ui/four_forward_slashes_first_line.stderr b/tests/ui/four_forward_slashes_first_line.stderr index 7944da14feb0..afb7c6b4dbda 100644 --- a/tests/ui/four_forward_slashes_first_line.stderr +++ b/tests/ui/four_forward_slashes_first_line.stderr @@ -6,6 +6,7 @@ LL | | fn a() {} | |_ | = note: `-D clippy::four-forward-slashes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::four_forward_slashes)]` help: make this a doc comment by removing one `/` | LL + /// borked doc comment on the first line. doesn't combust! diff --git a/tests/ui/from_iter_instead_of_collect.stderr b/tests/ui/from_iter_instead_of_collect.stderr index e42851bf8460..6e86341d1574 100644 --- a/tests/ui/from_iter_instead_of_collect.stderr +++ b/tests/ui/from_iter_instead_of_collect.stderr @@ -5,6 +5,7 @@ LL | >::from_iter(iter.into_iter().copied()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `iter.into_iter().copied().collect::()` | = note: `-D clippy::from-iter-instead-of-collect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::from_iter_instead_of_collect)]` error: usage of `FromIterator::from_iter` --> $DIR/from_iter_instead_of_collect.rs:23:13 diff --git a/tests/ui/from_over_into.stderr b/tests/ui/from_over_into.stderr index 96afec3de30e..784843ce5fd5 100644 --- a/tests/ui/from_over_into.stderr +++ b/tests/ui/from_over_into.stderr @@ -5,6 +5,7 @@ LL | impl Into for String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::from-over-into` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::from_over_into)]` help: replace the `Into` implementation with `From` | LL ~ impl From for StringWrapper { diff --git a/tests/ui/from_over_into_unfixable.stderr b/tests/ui/from_over_into_unfixable.stderr index 3470eff9e958..8ef36f082e0e 100644 --- a/tests/ui/from_over_into_unfixable.stderr +++ b/tests/ui/from_over_into_unfixable.stderr @@ -6,6 +6,7 @@ LL | impl Into for String { | = help: replace the `Into` implementation with `From` = note: `-D clippy::from-over-into` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::from_over_into)]` error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true --> $DIR/from_over_into_unfixable.rs:20:1 diff --git a/tests/ui/from_raw_with_void_ptr.stderr b/tests/ui/from_raw_with_void_ptr.stderr index b6460862419d..6e1ad0d99c49 100644 --- a/tests/ui/from_raw_with_void_ptr.stderr +++ b/tests/ui/from_raw_with_void_ptr.stderr @@ -10,6 +10,7 @@ help: cast this to a pointer of the appropriate type LL | let _ = unsafe { Box::from_raw(ptr) }; | ^^^ = note: `-D clippy::from-raw-with-void-ptr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::from_raw_with_void_ptr)]` error: creating a `Rc` from a void raw pointer --> $DIR/from_raw_with_void_ptr.rs:23:22 diff --git a/tests/ui/from_str_radix_10.stderr b/tests/ui/from_str_radix_10.stderr index 1fbd1e3a5f20..439dcff74d9c 100644 --- a/tests/ui/from_str_radix_10.stderr +++ b/tests/ui/from_str_radix_10.stderr @@ -5,6 +5,7 @@ LL | u32::from_str_radix("30", 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"30".parse::()` | = note: `-D clippy::from-str-radix-10` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::from_str_radix_10)]` error: this call to `from_str_radix` can be replaced with a call to `str::parse` --> $DIR/from_str_radix_10.rs:31:5 diff --git a/tests/ui/functions.stderr b/tests/ui/functions.stderr index fb8f4511e995..371ea1612601 100644 --- a/tests/ui/functions.stderr +++ b/tests/ui/functions.stderr @@ -5,6 +5,7 @@ LL | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::too-many-arguments` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::too_many_arguments)]` error: this function has too many arguments (8/7) --> $DIR/functions.rs:13:1 @@ -37,6 +38,7 @@ LL | println!("{}", unsafe { *p }); | ^ | = note: `-D clippy::not-unsafe-ptr-arg-deref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::not_unsafe_ptr_arg_deref)]` error: this public function might dereference a raw pointer but is not marked `unsafe` --> $DIR/functions.rs:71:35 diff --git a/tests/ui/functions_maxlines.stderr b/tests/ui/functions_maxlines.stderr index 6551892363c4..1d6ddad79ff2 100644 --- a/tests/ui/functions_maxlines.stderr +++ b/tests/ui/functions_maxlines.stderr @@ -11,6 +11,7 @@ LL | | } | |_^ | = note: `-D clippy::too-many-lines` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::too_many_lines)]` error: aborting due to previous error diff --git a/tests/ui/future_not_send.stderr b/tests/ui/future_not_send.stderr index 9628cf3a1b95..e417de723ff3 100644 --- a/tests/ui/future_not_send.stderr +++ b/tests/ui/future_not_send.stderr @@ -27,6 +27,7 @@ LL | } | - `cell` is later dropped here = note: `std::cell::Cell` doesn't implement `std::marker::Sync` = note: `-D clippy::future-not-send` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::future_not_send)]` error: future cannot be sent between threads safely --> $DIR/future_not_send.rs:12:42 diff --git a/tests/ui/get_first.stderr b/tests/ui/get_first.stderr index 51ebb1f3f06f..56b4c29a3135 100644 --- a/tests/ui/get_first.stderr +++ b/tests/ui/get_first.stderr @@ -5,6 +5,7 @@ LL | let _ = x.get(0); // Use x.first() | ^^^^^^^^ help: try: `x.first()` | = note: `-D clippy::get-first` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::get_first)]` error: accessing first element with `y.get(0)` --> $DIR/get_first.rs:22:13 diff --git a/tests/ui/get_last_with_len.stderr b/tests/ui/get_last_with_len.stderr index 8e852bbb2655..0056adc57f22 100644 --- a/tests/ui/get_last_with_len.stderr +++ b/tests/ui/get_last_with_len.stderr @@ -5,6 +5,7 @@ LL | let _ = x.get(x.len() - 1); | ^^^^^^^^^^^^^^^^^^ help: try: `x.last()` | = note: `-D clippy::get-last-with-len` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::get_last_with_len)]` error: accessing last element with `s.field.get(s.field.len() - 1)` --> $DIR/get_last_with_len.rs:32:13 diff --git a/tests/ui/get_unwrap.stderr b/tests/ui/get_unwrap.stderr index 242c339bbf1d..384860ea116e 100644 --- a/tests/ui/get_unwrap.stderr +++ b/tests/ui/get_unwrap.stderr @@ -19,6 +19,7 @@ LL | let _ = boxed_slice.get(1).unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message = note: `-D clippy::unwrap-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise --> $DIR/get_unwrap.rs:37:17 diff --git a/tests/ui/identity_op.stderr b/tests/ui/identity_op.stderr index cb251935b600..2a61327f15f2 100644 --- a/tests/ui/identity_op.stderr +++ b/tests/ui/identity_op.stderr @@ -5,6 +5,7 @@ LL | x + 0; | ^^^^^ help: consider reducing it to: `x` | = note: `-D clippy::identity-op` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::identity_op)]` error: this operation has no effect --> $DIR/identity_op.rs:43:5 diff --git a/tests/ui/if_let_mutex.stderr b/tests/ui/if_let_mutex.stderr index 6bbaadbe8553..8934294430b2 100644 --- a/tests/ui/if_let_mutex.stderr +++ b/tests/ui/if_let_mutex.stderr @@ -16,6 +16,7 @@ LL | | }; | = help: move the lock call outside of the `if let ...` expression = note: `-D clippy::if-let-mutex` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::if_let_mutex)]` error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock --> $DIR/if_let_mutex.rs:23:5 diff --git a/tests/ui/if_not_else.stderr b/tests/ui/if_not_else.stderr index 2a7500fdc61a..8b86f82fa8ee 100644 --- a/tests/ui/if_not_else.stderr +++ b/tests/ui/if_not_else.stderr @@ -11,6 +11,7 @@ LL | | } | = help: remove the `!` and swap the blocks of the `if`/`else` = note: `-D clippy::if-not-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::if_not_else)]` error: unnecessary `!=` operation --> $DIR/if_not_else.rs:18:5 diff --git a/tests/ui/if_same_then_else.stderr b/tests/ui/if_same_then_else.stderr index 774cc08685a7..fb33e94e6c3d 100644 --- a/tests/ui/if_same_then_else.stderr +++ b/tests/ui/if_same_then_else.stderr @@ -24,6 +24,7 @@ LL | | foo(); LL | | } | |_____^ = note: `-D clippy::if-same-then-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::if_same_then_else)]` error: this `if` has identical blocks --> $DIR/if_same_then_else.rs:67:21 diff --git a/tests/ui/if_same_then_else2.stderr b/tests/ui/if_same_then_else2.stderr index 56e5f3e45b22..fe68ef2711b5 100644 --- a/tests/ui/if_same_then_else2.stderr +++ b/tests/ui/if_same_then_else2.stderr @@ -24,6 +24,7 @@ LL | | } LL | | } | |_____^ = note: `-D clippy::if-same-then-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::if_same_then_else)]` error: this `if` has identical blocks --> $DIR/if_same_then_else2.rs:36:13 diff --git a/tests/ui/if_then_some_else_none.stderr b/tests/ui/if_then_some_else_none.stderr index f63298a7fce8..5c97b06da15a 100644 --- a/tests/ui/if_then_some_else_none.stderr +++ b/tests/ui/if_then_some_else_none.stderr @@ -13,6 +13,7 @@ LL | | }; | = help: consider using `bool::then` like: `foo().then(|| { /* snippet */ "foo" })` = note: `-D clippy::if-then-some-else-none` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::if_then_some_else_none)]` error: this could be simplified with `bool::then` --> $DIR/if_then_some_else_none.rs:14:13 diff --git a/tests/ui/ifs_same_cond.stderr b/tests/ui/ifs_same_cond.stderr index 3f52c10b7620..c5cd6b2c42e5 100644 --- a/tests/ui/ifs_same_cond.stderr +++ b/tests/ui/ifs_same_cond.stderr @@ -10,6 +10,7 @@ note: same as this LL | if b { | ^ = note: `-D clippy::ifs-same-cond` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ifs_same_cond)]` error: this `if` has the same condition as a previous `if` --> $DIR/ifs_same_cond.rs:19:15 diff --git a/tests/ui/ignored_unit_patterns.stderr b/tests/ui/ignored_unit_patterns.stderr index 6cb8b60ac0ce..a8ced22397db 100644 --- a/tests/ui/ignored_unit_patterns.stderr +++ b/tests/ui/ignored_unit_patterns.stderr @@ -5,6 +5,7 @@ LL | Ok(_) => {}, | ^ help: use `()` instead of `_`: `()` | = note: `-D clippy::ignored-unit-patterns` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ignored_unit_patterns)]` error: matching over `()` is more explicit --> $DIR/ignored_unit_patterns.rs:11:13 diff --git a/tests/ui/impl.stderr b/tests/ui/impl.stderr index 2eac1ce3dd7b..833a106062a3 100644 --- a/tests/ui/impl.stderr +++ b/tests/ui/impl.stderr @@ -15,6 +15,7 @@ LL | | fn first() {} LL | | } | |_^ = note: `-D clippy::multiple-inherent-impl` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::multiple_inherent_impl)]` error: multiple implementations of this structure --> $DIR/impl.rs:25:5 diff --git a/tests/ui/impl_trait_in_params.stderr b/tests/ui/impl_trait_in_params.stderr index ad035abc635b..36b4f27e9a45 100644 --- a/tests/ui/impl_trait_in_params.stderr +++ b/tests/ui/impl_trait_in_params.stderr @@ -5,6 +5,7 @@ LL | pub fn a(_: impl Trait) {} | ^^^^^^^^^^ | = note: `-D clippy::impl-trait-in-params` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::impl_trait_in_params)]` help: add a type parameter | LL | pub fn a<{ /* Generic name */ }: Trait>(_: impl Trait) {} diff --git a/tests/ui/implicit_clone.stderr b/tests/ui/implicit_clone.stderr index 59f000c06e20..64c31e65175a 100644 --- a/tests/ui/implicit_clone.stderr +++ b/tests/ui/implicit_clone.stderr @@ -5,6 +5,7 @@ LL | let _ = vec.to_owned(); | ^^^^^^^^^^^^^^ help: consider using: `vec.clone()` | = note: `-D clippy::implicit-clone` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::implicit_clone)]` error: implicitly cloning a `Vec` by calling `to_vec` on its dereferenced type --> $DIR/implicit_clone.rs:66:13 diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr index a761b4273953..1edc6cc6f778 100644 --- a/tests/ui/implicit_return.stderr +++ b/tests/ui/implicit_return.stderr @@ -5,6 +5,7 @@ LL | true | ^^^^ help: add `return` as shown: `return true` | = note: `-D clippy::implicit-return` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::implicit_return)]` error: missing `return` statement --> $DIR/implicit_return.rs:15:15 diff --git a/tests/ui/implicit_saturating_add.stderr b/tests/ui/implicit_saturating_add.stderr index cfd600c53c36..7119c8bf6fad 100644 --- a/tests/ui/implicit_saturating_add.stderr +++ b/tests/ui/implicit_saturating_add.stderr @@ -7,6 +7,7 @@ LL | | } | |_____^ help: use instead: `u_8 = u_8.saturating_add(1);` | = note: `-D clippy::implicit-saturating-add` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::implicit_saturating_add)]` error: manual saturating add detected --> $DIR/implicit_saturating_add.rs:25:5 diff --git a/tests/ui/implicit_saturating_sub.stderr b/tests/ui/implicit_saturating_sub.stderr index 75d8a88e8d43..6e026d1a6987 100644 --- a/tests/ui/implicit_saturating_sub.stderr +++ b/tests/ui/implicit_saturating_sub.stderr @@ -7,6 +7,7 @@ LL | | } | |_____^ help: try: `u_8 = u_8.saturating_sub(1);` | = note: `-D clippy::implicit-saturating-sub` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::implicit_saturating_sub)]` error: implicitly performing saturating subtraction --> $DIR/implicit_saturating_sub.rs:34:13 diff --git a/tests/ui/implied_bounds_in_impls.stderr b/tests/ui/implied_bounds_in_impls.stderr index 8dffc674444d..e2b1ecb9f1ec 100644 --- a/tests/ui/implied_bounds_in_impls.stderr +++ b/tests/ui/implied_bounds_in_impls.stderr @@ -5,6 +5,7 @@ LL | fn deref_derefmut(x: T) -> impl Deref + DerefMut | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::implied-bounds-in-impls` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::implied_bounds_in_impls)]` help: try removing this bound | LL - fn deref_derefmut(x: T) -> impl Deref + DerefMut { diff --git a/tests/ui/inconsistent_digit_grouping.stderr b/tests/ui/inconsistent_digit_grouping.stderr index 485c1fdb9120..6aeb33edafd3 100644 --- a/tests/ui/inconsistent_digit_grouping.stderr +++ b/tests/ui/inconsistent_digit_grouping.stderr @@ -5,6 +5,7 @@ LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f | ^^^^^^^^ help: consider: `123_456` | = note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inconsistent_digit_grouping)]` error: digits grouped inconsistently by underscores --> $DIR/inconsistent_digit_grouping.rs:25:26 diff --git a/tests/ui/inconsistent_struct_constructor.stderr b/tests/ui/inconsistent_struct_constructor.stderr index a2bee121ebf2..fc080d7ec057 100644 --- a/tests/ui/inconsistent_struct_constructor.stderr +++ b/tests/ui/inconsistent_struct_constructor.stderr @@ -5,6 +5,7 @@ LL | Foo { y, x, z }; | ^^^^^^^^^^^^^^^ help: try: `Foo { x, y, z }` | = note: `-D clippy::inconsistent-struct-constructor` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inconsistent_struct_constructor)]` error: struct constructor field order is inconsistent with struct definition field order --> $DIR/inconsistent_struct_constructor.rs:55:9 diff --git a/tests/ui/indexing_slicing_index.stderr b/tests/ui/indexing_slicing_index.stderr index edb47d39412b..64facf208034 100644 --- a/tests/ui/indexing_slicing_index.stderr +++ b/tests/ui/indexing_slicing_index.stderr @@ -7,6 +7,7 @@ LL | const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-re = help: consider using `.get(n)` or `.get_mut(n)` instead = note: the suggestion might not be applicable in constant blocks = note: `-D clippy::indexing-slicing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]` error: indexing may panic --> $DIR/indexing_slicing_index.rs:16:24 diff --git a/tests/ui/indexing_slicing_slice.stderr b/tests/ui/indexing_slicing_slice.stderr index 0f83ea52d01b..eebe67810a02 100644 --- a/tests/ui/indexing_slicing_slice.stderr +++ b/tests/ui/indexing_slicing_slice.stderr @@ -6,6 +6,7 @@ LL | &x[index..]; | = help: consider using `.get(n..)` or .get_mut(n..)` instead = note: `-D clippy::indexing-slicing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]` error: slicing may panic --> $DIR/indexing_slicing_slice.rs:14:6 @@ -54,6 +55,7 @@ LL | &x[5..][..10]; | ^ | = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]` error: slicing may panic --> $DIR/indexing_slicing_slice.rs:25:6 diff --git a/tests/ui/infallible_destructuring_match.stderr b/tests/ui/infallible_destructuring_match.stderr index ada02741692f..93851aae82bd 100644 --- a/tests/ui/infallible_destructuring_match.stderr +++ b/tests/ui/infallible_destructuring_match.stderr @@ -7,6 +7,7 @@ LL | | }; | |______^ help: try: `let SingleVariantEnum::Variant(data) = wrapper;` | = note: `-D clippy::infallible-destructuring-match` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::infallible_destructuring_match)]` error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let` --> $DIR/infallible_destructuring_match.rs:60:5 diff --git a/tests/ui/infinite_loop.stderr b/tests/ui/infinite_loop.stderr index 5ba806be867f..c32b5e323c09 100644 --- a/tests/ui/infinite_loop.stderr +++ b/tests/ui/infinite_loop.stderr @@ -98,6 +98,7 @@ LL | fn fn_mutref(i: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` | = note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]` error: aborting due to 12 previous errors diff --git a/tests/ui/inherent_to_string.stderr b/tests/ui/inherent_to_string.stderr index cfe8600e9260..cf8d09180191 100644 --- a/tests/ui/inherent_to_string.stderr +++ b/tests/ui/inherent_to_string.stderr @@ -9,6 +9,7 @@ LL | | } | = help: implement trait `Display` for type `A` instead = note: `-D clippy::inherent-to-string` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inherent_to_string)]` error: type `C` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display` --> $DIR/inherent_to_string.rs:47:5 diff --git a/tests/ui/inline_fn_without_body.stderr b/tests/ui/inline_fn_without_body.stderr index 87d2da71280d..60f6eb8dff08 100644 --- a/tests/ui/inline_fn_without_body.stderr +++ b/tests/ui/inline_fn_without_body.stderr @@ -7,6 +7,7 @@ LL | | fn default_inline(); | |____- help: remove | = note: `-D clippy::inline-fn-without-body` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inline_fn_without_body)]` error: use of `#[inline]` on trait method `always_inline` which has no body --> $DIR/inline_fn_without_body.rs:8:5 diff --git a/tests/ui/inspect_for_each.stderr b/tests/ui/inspect_for_each.stderr index bdeb1d844609..80df86ad64ec 100644 --- a/tests/ui/inspect_for_each.stderr +++ b/tests/ui/inspect_for_each.stderr @@ -12,6 +12,7 @@ LL | | }); | = help: move the code from `inspect(..)` to `for_each(..)` and remove the `inspect(..)` = note: `-D clippy::inspect-for-each` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inspect_for_each)]` error: aborting due to previous error diff --git a/tests/ui/int_plus_one.stderr b/tests/ui/int_plus_one.stderr index a0c5b32a205f..6a62eac7cc47 100644 --- a/tests/ui/int_plus_one.stderr +++ b/tests/ui/int_plus_one.stderr @@ -5,6 +5,7 @@ LL | let _ = x >= y + 1; | ^^^^^^^^^^ help: change it to: `x > y` | = note: `-D clippy::int-plus-one` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::int_plus_one)]` error: unnecessary `>= y + 1` or `x - 1 >=` --> $DIR/int_plus_one.rs:8:13 diff --git a/tests/ui/integer_division.stderr b/tests/ui/integer_division.stderr index 9bc41ef8385e..420f0f30e77c 100644 --- a/tests/ui/integer_division.stderr +++ b/tests/ui/integer_division.stderr @@ -6,6 +6,7 @@ LL | let n = 1 / 2; | = help: division of integers may cause loss of precision. consider using floats = note: `-D clippy::integer-division` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::integer_division)]` error: integer division --> $DIR/integer_division.rs:7:13 diff --git a/tests/ui/into_iter_on_ref.stderr b/tests/ui/into_iter_on_ref.stderr index 2c81518d8db4..481957d50e20 100644 --- a/tests/ui/into_iter_on_ref.stderr +++ b/tests/ui/into_iter_on_ref.stderr @@ -5,6 +5,7 @@ LL | let _ = (&vec![1, 2, 3]).into_iter(); | ^^^^^^^^^ help: call directly: `iter` | = note: `-D clippy::into-iter-on-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::into_iter_on_ref)]` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` --> $DIR/into_iter_on_ref.rs:14:46 diff --git a/tests/ui/invalid_upcast_comparisons.stderr b/tests/ui/invalid_upcast_comparisons.stderr index b201db3ddb14..a57b4b02dce3 100644 --- a/tests/ui/invalid_upcast_comparisons.stderr +++ b/tests/ui/invalid_upcast_comparisons.stderr @@ -5,6 +5,7 @@ LL | (u8 as u32) > 300; | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::invalid-upcast-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::invalid_upcast_comparisons)]` error: because of the numeric bounds on `u8` prior to casting, this expression is always false --> $DIR/invalid_upcast_comparisons.rs:24:5 diff --git a/tests/ui/is_digit_ascii_radix.stderr b/tests/ui/is_digit_ascii_radix.stderr index 7bc21b216d53..28040c3a9c26 100644 --- a/tests/ui/is_digit_ascii_radix.stderr +++ b/tests/ui/is_digit_ascii_radix.stderr @@ -5,6 +5,7 @@ LL | let _ = c.is_digit(10); | ^^^^^^^^^^^^^^ help: try: `c.is_ascii_digit()` | = note: `-D clippy::is-digit-ascii-radix` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::is_digit_ascii_radix)]` error: use of `char::is_digit` with literal radix of 16 --> $DIR/is_digit_ascii_radix.rs:10:13 diff --git a/tests/ui/issue-7447.stderr b/tests/ui/issue-7447.stderr index 27e102af62fb..51ecac4559c9 100644 --- a/tests/ui/issue-7447.stderr +++ b/tests/ui/issue-7447.stderr @@ -5,6 +5,7 @@ LL | byte_view(panic!()); | ^^^^^^^^ | = note: `-D clippy::diverging-sub-expression` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::diverging_sub_expression)]` = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: sub-expression diverges diff --git a/tests/ui/issue_4266.stderr b/tests/ui/issue_4266.stderr index acfa01e9f2b3..692de2ae58c0 100644 --- a/tests/ui/issue_4266.stderr +++ b/tests/ui/issue_4266.stderr @@ -5,6 +5,7 @@ LL | async fn sink1<'a>(_: &'a str) {} // lint | ^^ ^^ | = note: `-D clippy::needless-lifetimes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_lifetimes)]` error: the following explicit lifetimes could be elided: 'a --> $DIR/issue_4266.rs:10:21 @@ -20,6 +21,7 @@ LL | pub async fn new(&mut self) -> Self { | = help: consider choosing a less ambiguous name = note: `-D clippy::wrong-self-convention` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wrong_self_convention)]` error: aborting due to 3 previous errors diff --git a/tests/ui/items_after_statement.stderr b/tests/ui/items_after_statement.stderr index 0e043b1742ff..fa494f217489 100644 --- a/tests/ui/items_after_statement.stderr +++ b/tests/ui/items_after_statement.stderr @@ -9,6 +9,7 @@ LL | | } | |_____^ | = note: `-D clippy::items-after-statements` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::items_after_statements)]` error: adding items after statements is confusing, since items exist from the start of the scope --> $DIR/items_after_statement.rs:22:5 diff --git a/tests/ui/iter_cloned_collect.stderr b/tests/ui/iter_cloned_collect.stderr index 36f70d5aec29..aa7fb98a7c8a 100644 --- a/tests/ui/iter_cloned_collect.stderr +++ b/tests/ui/iter_cloned_collect.stderr @@ -5,6 +5,7 @@ LL | let v2: Vec = v.iter().cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()` | = note: `-D clippy::iter-cloned-collect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_cloned_collect)]` error: called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable --> $DIR/iter_cloned_collect.rs:13:38 diff --git a/tests/ui/iter_count.stderr b/tests/ui/iter_count.stderr index 2e3d7fc35de9..2882b7d28505 100644 --- a/tests/ui/iter_count.stderr +++ b/tests/ui/iter_count.stderr @@ -5,6 +5,7 @@ LL | &vec[..].iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` | = note: `-D clippy::iter-count` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_count)]` error: called `.iter().count()` on a `Vec` --> $DIR/iter_count.rs:55:5 diff --git a/tests/ui/iter_kv_map.stderr b/tests/ui/iter_kv_map.stderr index 75804af01ce2..62155b7f838e 100644 --- a/tests/ui/iter_kv_map.stderr +++ b/tests/ui/iter_kv_map.stderr @@ -5,6 +5,7 @@ LL | let _ = map.iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` | = note: `-D clippy::iter-kv-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_kv_map)]` error: iterating on a map's values --> $DIR/iter_kv_map.rs:15:13 diff --git a/tests/ui/iter_next_slice.stderr b/tests/ui/iter_next_slice.stderr index d8b89061ff89..e6b4bd6c0b48 100644 --- a/tests/ui/iter_next_slice.stderr +++ b/tests/ui/iter_next_slice.stderr @@ -5,6 +5,7 @@ LL | let _ = s.iter().next(); | ^^^^^^^^^^^^^^^ help: try calling: `s.first()` | = note: `-D clippy::iter-next-slice` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_next_slice)]` error: using `.iter().next()` on a Slice without end index --> $DIR/iter_next_slice.rs:12:13 diff --git a/tests/ui/iter_not_returning_iterator.stderr b/tests/ui/iter_not_returning_iterator.stderr index 3145ade4448b..c695b1932d35 100644 --- a/tests/ui/iter_not_returning_iterator.stderr +++ b/tests/ui/iter_not_returning_iterator.stderr @@ -5,6 +5,7 @@ LL | fn iter(&self) -> Counter2 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::iter-not-returning-iterator` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_not_returning_iterator)]` error: this method is named `iter_mut` but its return type does not implement `Iterator` --> $DIR/iter_not_returning_iterator.rs:36:5 diff --git a/tests/ui/iter_nth.stderr b/tests/ui/iter_nth.stderr index 24be814548a2..162e6c338494 100644 --- a/tests/ui/iter_nth.stderr +++ b/tests/ui/iter_nth.stderr @@ -6,6 +6,7 @@ LL | let bad_vec = some_vec.iter().nth(3); | = help: calling `.get()` is both faster and more readable = note: `-D clippy::iter-nth` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_nth)]` error: called `.iter().nth()` on a slice --> $DIR/iter_nth.rs:35:26 diff --git a/tests/ui/iter_nth_zero.stderr b/tests/ui/iter_nth_zero.stderr index 8338d7f7b93a..939fd0063c0b 100644 --- a/tests/ui/iter_nth_zero.stderr +++ b/tests/ui/iter_nth_zero.stderr @@ -5,6 +5,7 @@ LL | let _x = s.iter().nth(0); | ^^^^^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `s.iter().next()` | = note: `-D clippy::iter-nth-zero` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_nth_zero)]` error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent --> $DIR/iter_nth_zero.rs:23:14 diff --git a/tests/ui/iter_on_empty_collections.stderr b/tests/ui/iter_on_empty_collections.stderr index c115c1278389..57a532019966 100644 --- a/tests/ui/iter_on_empty_collections.stderr +++ b/tests/ui/iter_on_empty_collections.stderr @@ -5,6 +5,7 @@ LL | assert_eq!([].into_iter().next(), Option::::None); | ^^^^^^^^^^^^^^ help: try: `std::iter::empty()` | = note: `-D clippy::iter-on-empty-collections` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_on_empty_collections)]` error: `iter_mut` call on an empty collection --> $DIR/iter_on_empty_collections.rs:6:16 diff --git a/tests/ui/iter_on_single_items.stderr b/tests/ui/iter_on_single_items.stderr index c6714143ba5a..00398f541e9a 100644 --- a/tests/ui/iter_on_single_items.stderr +++ b/tests/ui/iter_on_single_items.stderr @@ -5,6 +5,7 @@ LL | assert_eq!([123].into_iter().next(), Some(123)); | ^^^^^^^^^^^^^^^^^ help: try: `std::iter::once(123)` | = note: `-D clippy::iter-on-single-items` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_on_single_items)]` error: `iter_mut` call on a collection with only one item --> $DIR/iter_on_single_items.rs:6:16 diff --git a/tests/ui/iter_overeager_cloned.stderr b/tests/ui/iter_overeager_cloned.stderr index 4417a40a63b8..fbcd33066d87 100644 --- a/tests/ui/iter_overeager_cloned.stderr +++ b/tests/ui/iter_overeager_cloned.stderr @@ -7,6 +7,7 @@ LL | let _: Option = vec.iter().cloned().last(); | help: try: `.last().cloned()` | = note: `-D clippy::iter-overeager-cloned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_overeager_cloned)]` error: unnecessarily eager cloning of iterator items --> $DIR/iter_overeager_cloned.rs:9:29 @@ -25,6 +26,7 @@ LL | let _: usize = vec.iter().filter(|x| x == &"2").cloned().count(); | help: try: `.count()` | = note: `-D clippy::redundant-clone` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]` error: unnecessarily eager cloning of iterator items --> $DIR/iter_overeager_cloned.rs:13:21 diff --git a/tests/ui/iter_skip_next.stderr b/tests/ui/iter_skip_next.stderr index ca6970b27f16..0b6bf652b1f1 100644 --- a/tests/ui/iter_skip_next.stderr +++ b/tests/ui/iter_skip_next.stderr @@ -5,6 +5,7 @@ LL | let _ = some_vec.iter().skip(42).next(); | ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)` | = note: `-D clippy::iter-skip-next` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_skip_next)]` error: called `skip(..).next()` on an iterator --> $DIR/iter_skip_next.rs:17:36 diff --git a/tests/ui/iter_skip_next_unfixable.stderr b/tests/ui/iter_skip_next_unfixable.stderr index 3160dc03a4fd..09a467793bd1 100644 --- a/tests/ui/iter_skip_next_unfixable.stderr +++ b/tests/ui/iter_skip_next_unfixable.stderr @@ -10,6 +10,7 @@ help: for this change `sp` has to be mutable LL | let sp = test_string.split('|').map(|s| s.trim()); | ^^ = note: `-D clippy::iter-skip-next` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_skip_next)]` error: called `skip(..).next()` on an iterator --> $DIR/iter_skip_next_unfixable.rs:12:29 diff --git a/tests/ui/iter_skip_zero.stderr b/tests/ui/iter_skip_zero.stderr index 6616020d0bdc..6b8b3b1056ac 100644 --- a/tests/ui/iter_skip_zero.stderr +++ b/tests/ui/iter_skip_zero.stderr @@ -6,6 +6,7 @@ LL | let _ = [1, 2, 3].iter().skip(0); | = note: this call to `skip` does nothing and is useless; remove it = note: `-D clippy::iter-skip-zero` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_skip_zero)]` error: usage of `.skip(0)` --> $DIR/iter_skip_zero.rs:12:39 diff --git a/tests/ui/iter_with_drain.stderr b/tests/ui/iter_with_drain.stderr index 0a3026570882..ac04f9396f5d 100644 --- a/tests/ui/iter_with_drain.stderr +++ b/tests/ui/iter_with_drain.stderr @@ -5,6 +5,7 @@ LL | let mut a: BinaryHeap<_> = a.drain(..).collect(); | ^^^^^^^^^ help: try: `into_iter()` | = note: `-D clippy::iter-with-drain` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_with_drain)]` error: `drain(..)` used on a `VecDeque` --> $DIR/iter_with_drain.rs:13:27 diff --git a/tests/ui/iterator_step_by_zero.stderr b/tests/ui/iterator_step_by_zero.stderr index fcf2930c26b2..20ea29322e85 100644 --- a/tests/ui/iterator_step_by_zero.stderr +++ b/tests/ui/iterator_step_by_zero.stderr @@ -5,6 +5,7 @@ LL | let _ = vec!["A", "B", "B"].iter().step_by(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::iterator-step-by-zero` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iterator_step_by_zero)]` error: `Iterator::step_by(0)` will panic at runtime --> $DIR/iterator_step_by_zero.rs:7:13 diff --git a/tests/ui/large_const_arrays.stderr b/tests/ui/large_const_arrays.stderr index e2348629088d..e522550ffcbd 100644 --- a/tests/ui/large_const_arrays.stderr +++ b/tests/ui/large_const_arrays.stderr @@ -7,6 +7,7 @@ LL | pub(crate) const FOO_PUB_CRATE: [u32; 1_000_000] = [0u32; 1_000_000]; | help: make this a static item: `static` | = note: `-D clippy::large-const-arrays` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_const_arrays)]` error: large array defined as const --> $DIR/large_const_arrays.rs:11:1 diff --git a/tests/ui/large_digit_groups.stderr b/tests/ui/large_digit_groups.stderr index 7e5ce7ad8d53..e5f37a6cce96 100644 --- a/tests/ui/large_digit_groups.stderr +++ b/tests/ui/large_digit_groups.stderr @@ -5,6 +5,7 @@ LL | 0xd_e_adbee_f_usize, | ^^^^^^^^^^^^^^^^^^^ help: consider: `0xdead_beef_usize` | = note: `-D clippy::unusual-byte-groupings` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unusual_byte_groupings)]` error: digit groups should be smaller --> $DIR/large_digit_groups.rs:23:9 @@ -13,6 +14,7 @@ LL | 1_23456_f32, | ^^^^^^^^^^^ help: consider: `123_456_f32` | = note: `-D clippy::large-digit-groups` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_digit_groups)]` error: digit groups should be smaller --> $DIR/large_digit_groups.rs:24:9 diff --git a/tests/ui/large_enum_variant.stderr b/tests/ui/large_enum_variant.stderr index 709972b4a6e4..7026ca785f34 100644 --- a/tests/ui/large_enum_variant.stderr +++ b/tests/ui/large_enum_variant.stderr @@ -10,6 +10,7 @@ LL | | } | |_^ the entire enum is at least 32004 bytes | = note: `-D clippy::large-enum-variant` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]` help: consider boxing the large fields to reduce the total size of the enum | LL | B(Box<[i32; 8000]>), diff --git a/tests/ui/large_futures.stderr b/tests/ui/large_futures.stderr index 5a0f00b67ec4..861366dafac6 100644 --- a/tests/ui/large_futures.stderr +++ b/tests/ui/large_futures.stderr @@ -5,6 +5,7 @@ LL | big_fut([0u8; 1024 * 16]).await; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(big_fut([0u8; 1024 * 16]))` | = note: `-D clippy::large-futures` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_futures)]` error: large future with a size of 16386 bytes --> $DIR/large_futures.rs:15:5 diff --git a/tests/ui/large_stack_arrays.stderr b/tests/ui/large_stack_arrays.stderr index 5126f4527855..0dfb6732b02a 100644 --- a/tests/ui/large_stack_arrays.stderr +++ b/tests/ui/large_stack_arrays.stderr @@ -6,6 +6,7 @@ LL | let _x = [build(); 3]; | = help: consider allocating on the heap with `vec![build(); 3].into_boxed_slice()` = note: `-D clippy::large-stack-arrays` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_stack_arrays)]` error: allocating a local array larger than 512000 bytes --> $DIR/large_stack_arrays.rs:32:14 diff --git a/tests/ui/large_stack_frames.stderr b/tests/ui/large_stack_frames.stderr index 6b14badca69f..12a458db807e 100644 --- a/tests/ui/large_stack_frames.stderr +++ b/tests/ui/large_stack_frames.stderr @@ -12,6 +12,7 @@ LL | | } | = note: allocating large amounts of stack space can overflow the stack = note: `-D clippy::large-stack-frames` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_stack_frames)]` error: this function allocates a large amount of stack space --> $DIR/large_stack_frames.rs:36:1 diff --git a/tests/ui/large_types_passed_by_value.stderr b/tests/ui/large_types_passed_by_value.stderr index 5f42dcfb9b52..b3f102cc498d 100644 --- a/tests/ui/large_types_passed_by_value.stderr +++ b/tests/ui/large_types_passed_by_value.stderr @@ -5,6 +5,7 @@ LL | fn bad(a: LargeAndCopy) {} | ^^^^^^^^^^^^ help: consider passing by reference instead: `&LargeAndCopy` | = note: `-D clippy::large-types-passed-by-value` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_types_passed_by_value)]` error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) --> $DIR/large_types_passed_by_value.rs:25:37 diff --git a/tests/ui/len_without_is_empty.stderr b/tests/ui/len_without_is_empty.stderr index 1042ea2e1b38..4815ce6a04b2 100644 --- a/tests/ui/len_without_is_empty.stderr +++ b/tests/ui/len_without_is_empty.stderr @@ -5,6 +5,7 @@ LL | pub fn len(&self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::len-without-is-empty` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::len_without_is_empty)]` error: trait `PubTraitsToo` has a `len` method but no (possibly inherited) `is_empty` method --> $DIR/len_without_is_empty.rs:57:1 @@ -96,6 +97,7 @@ LL | pub fn len(&self) -> Result { | = help: use a custom `Error` type instead = note: `-D clippy::result-unit-err` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::result_unit_err)]` error: this returns a `Result<_, ()>` --> $DIR/len_without_is_empty.rs:250:5 diff --git a/tests/ui/len_zero.stderr b/tests/ui/len_zero.stderr index 45130a3008d3..e1f2434415d0 100644 --- a/tests/ui/len_zero.stderr +++ b/tests/ui/len_zero.stderr @@ -5,6 +5,7 @@ LL | if x.len() == 0 { | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `x.is_empty()` | = note: `-D clippy::len-zero` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::len_zero)]` error: length comparison to zero --> $DIR/len_zero.rs:86:8 @@ -19,6 +20,7 @@ LL | println!("{}", *s1 == ""); | ^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s1.is_empty()` | = note: `-D clippy::comparison-to-empty` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::comparison_to_empty)]` error: comparison to empty slice --> $DIR/len_zero.rs:96:20 diff --git a/tests/ui/len_zero_ranges.stderr b/tests/ui/len_zero_ranges.stderr index 25a940181d49..1922e9b30444 100644 --- a/tests/ui/len_zero_ranges.stderr +++ b/tests/ui/len_zero_ranges.stderr @@ -5,6 +5,7 @@ LL | let _ = (0..42).len() == 0; | ^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(0..42).is_empty()` | = note: `-D clippy::len-zero` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::len_zero)]` error: length comparison to zero --> $DIR/len_zero_ranges.rs:11:17 diff --git a/tests/ui/let_and_return.stderr b/tests/ui/let_and_return.stderr index 3f60b69df456..c09c2b32aad0 100644 --- a/tests/ui/let_and_return.stderr +++ b/tests/ui/let_and_return.stderr @@ -7,6 +7,7 @@ LL | x | ^ | = note: `-D clippy::let-and-return` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_and_return)]` help: return the expression directly | LL ~ diff --git a/tests/ui/let_if_seq.stderr b/tests/ui/let_if_seq.stderr index b739268dacd5..bfb4bb9d0d2f 100644 --- a/tests/ui/let_if_seq.stderr +++ b/tests/ui/let_if_seq.stderr @@ -11,6 +11,7 @@ LL | | } | = note: you might not need `mut` at all = note: `-D clippy::useless-let-if-seq` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::useless_let_if_seq)]` error: `if _ { .. } else { .. }` is an expression --> $DIR/let_if_seq.rs:73:5 diff --git a/tests/ui/let_underscore_future.stderr b/tests/ui/let_underscore_future.stderr index e3a628236e70..3ba99c6377b7 100644 --- a/tests/ui/let_underscore_future.stderr +++ b/tests/ui/let_underscore_future.stderr @@ -6,6 +6,7 @@ LL | let _ = some_async_fn(); | = help: consider awaiting the future or dropping explicitly with `std::mem::drop` = note: `-D clippy::let-underscore-future` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_underscore_future)]` error: non-binding `let` on a future --> $DIR/let_underscore_future.rs:18:5 @@ -30,6 +31,7 @@ LL | fn do_something_to_future(future: &mut impl Future) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&impl Future` | = note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]` error: aborting due to 4 previous errors diff --git a/tests/ui/let_underscore_lock.stderr b/tests/ui/let_underscore_lock.stderr index 9c9ff9c917c8..ac6e0978e637 100644 --- a/tests/ui/let_underscore_lock.stderr +++ b/tests/ui/let_underscore_lock.stderr @@ -6,6 +6,7 @@ LL | let _ = p_m.lock(); | = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` = note: `-D clippy::let-underscore-lock` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_underscore_lock)]` error: non-binding `let` on a synchronization lock --> $DIR/let_underscore_lock.rs:14:5 diff --git a/tests/ui/let_underscore_must_use.stderr b/tests/ui/let_underscore_must_use.stderr index 5cd02a6e8122..83d0372e668c 100644 --- a/tests/ui/let_underscore_must_use.stderr +++ b/tests/ui/let_underscore_must_use.stderr @@ -6,6 +6,7 @@ LL | let _ = f(); | = help: consider explicitly using function result = note: `-D clippy::let-underscore-must-use` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_underscore_must_use)]` error: non-binding `let` on an expression with `#[must_use]` type --> $DIR/let_underscore_must_use.rs:69:5 diff --git a/tests/ui/let_underscore_untyped.stderr b/tests/ui/let_underscore_untyped.stderr index e0c39b6eeafe..0e5647fa1e92 100644 --- a/tests/ui/let_underscore_untyped.stderr +++ b/tests/ui/let_underscore_untyped.stderr @@ -10,6 +10,7 @@ help: consider adding a type annotation LL | let _ = a(); | ^ = note: `-D clippy::let-underscore-untyped` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_underscore_untyped)]` error: non-binding `let` without a type annotation --> $DIR/let_underscore_untyped.rs:52:5 diff --git a/tests/ui/let_unit.stderr b/tests/ui/let_unit.stderr index c54d4392a346..de106f50e0e7 100644 --- a/tests/ui/let_unit.stderr +++ b/tests/ui/let_unit.stderr @@ -5,6 +5,7 @@ LL | let _x = println!("x"); | ^^^^^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `println!("x");` | = note: `-D clippy::let-unit-value` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_unit_value)]` error: this let-binding has unit value --> $DIR/let_unit.rs:16:9 diff --git a/tests/ui/let_with_type_underscore.stderr b/tests/ui/let_with_type_underscore.stderr index a749552c7fac..d4c9ba19c39f 100644 --- a/tests/ui/let_with_type_underscore.stderr +++ b/tests/ui/let_with_type_underscore.stderr @@ -10,6 +10,7 @@ help: remove the explicit type `_` declaration LL | let x: _ = 1; | ^^^ = note: `-D clippy::let-with-type-underscore` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_with_type_underscore)]` error: variable declared with type underscore --> $DIR/let_with_type_underscore.rs:16:5 diff --git a/tests/ui/lines_filter_map_ok.stderr b/tests/ui/lines_filter_map_ok.stderr index 4244d85b448a..fa2ba0a9a462 100644 --- a/tests/ui/lines_filter_map_ok.stderr +++ b/tests/ui/lines_filter_map_ok.stderr @@ -10,6 +10,7 @@ note: this expression returning a `std::io::Lines` may produce an infinite numbe LL | BufReader::new(f).lines().filter_map(Result::ok).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::lines-filter-map-ok` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::lines_filter_map_ok)]` error: `flat_map()` will run forever if the iterator repeatedly produces an `Err` --> $DIR/lines_filter_map_ok.rs:12:31 diff --git a/tests/ui/linkedlist.stderr b/tests/ui/linkedlist.stderr index b31b0cd9314e..792af4dd06e8 100644 --- a/tests/ui/linkedlist.stderr +++ b/tests/ui/linkedlist.stderr @@ -6,6 +6,7 @@ LL | const C: LinkedList = LinkedList::new(); | = help: a `VecDeque` might work = note: `-D clippy::linkedlist` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::linkedlist)]` error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? --> $DIR/linkedlist.rs:10:11 diff --git a/tests/ui/literals.stderr b/tests/ui/literals.stderr index 7c79436752fc..bc755b1123db 100644 --- a/tests/ui/literals.stderr +++ b/tests/ui/literals.stderr @@ -5,6 +5,7 @@ LL | let ok4 = 0xab_cd_i32; | ^^^^^^^^^^^ help: remove the underscore: `0xab_cdi32` | = note: `-D clippy::separated-literal-suffix` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::separated_literal_suffix)]` error: integer type suffix should not be separated by an underscore --> $DIR/literals.rs:16:15 @@ -25,6 +26,7 @@ LL | let fail1 = 0xabCD; | ^^^^^^ | = note: `-D clippy::mixed-case-hex-literals` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mixed_case_hex_literals)]` error: integer type suffix should not be separated by an underscore --> $DIR/literals.rs:23:17 @@ -57,6 +59,7 @@ LL | let fail_multi_zero = 000_123usize; | ^^^^^^^^^^^^ help: add an underscore: `000_123_usize` | = note: `-D clippy::unseparated-literal-suffix` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unseparated_literal_suffix)]` error: this is a decimal constant --> $DIR/literals.rs:29:27 @@ -65,6 +68,7 @@ LL | let fail_multi_zero = 000_123usize; | ^^^^^^^^^^^^ | = note: `-D clippy::zero-prefixed-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::zero_prefixed_literal)]` help: if you mean to use a decimal constant, remove the `0` to avoid confusion | LL | let fail_multi_zero = 123usize; @@ -108,6 +112,7 @@ LL | let fail19 = 12_3456_21; | ^^^^^^^^^^ help: consider: `12_345_621` | = note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inconsistent_digit_grouping)]` error: digits grouped inconsistently by underscores --> $DIR/literals.rs:55:18 @@ -128,6 +133,7 @@ LL | let fail24 = 0xAB_ABC_AB; | ^^^^^^^^^^^ help: consider: `0x0ABA_BCAB` | = note: `-D clippy::unusual-byte-groupings` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unusual_byte_groupings)]` error: this is a decimal constant --> $DIR/literals.rs:70:13 diff --git a/tests/ui/lossy_float_literal.stderr b/tests/ui/lossy_float_literal.stderr index d2193c0c8195..ea787f5726aa 100644 --- a/tests/ui/lossy_float_literal.stderr +++ b/tests/ui/lossy_float_literal.stderr @@ -5,6 +5,7 @@ LL | let _: f32 = 16_777_217.0; | ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_216.0` | = note: `-D clippy::lossy-float-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::lossy_float_literal)]` error: literal cannot be represented as the underlying type without loss of precision --> $DIR/lossy_float_literal.rs:7:18 diff --git a/tests/ui/macro_use_imports.stderr b/tests/ui/macro_use_imports.stderr index 2259e5abf2f3..6de869699ec6 100644 --- a/tests/ui/macro_use_imports.stderr +++ b/tests/ui/macro_use_imports.stderr @@ -5,6 +5,7 @@ LL | #[macro_use] | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;` | = note: `-D clippy::macro-use-imports` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::macro_use_imports)]` error: `macro_use` attributes are no longer needed in the Rust 2018 edition --> $DIR/macro_use_imports.rs:23:5 diff --git a/tests/ui/manual_assert.edition2018.stderr b/tests/ui/manual_assert.edition2018.stderr index 1bf61fa33bf0..b19cca4d5f91 100644 --- a/tests/ui/manual_assert.edition2018.stderr +++ b/tests/ui/manual_assert.edition2018.stderr @@ -7,6 +7,7 @@ LL | | } | |_____^ help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);` | = note: `-D clippy::manual-assert` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_assert)]` error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:33:5 diff --git a/tests/ui/manual_assert.edition2021.stderr b/tests/ui/manual_assert.edition2021.stderr index 1bf61fa33bf0..b19cca4d5f91 100644 --- a/tests/ui/manual_assert.edition2021.stderr +++ b/tests/ui/manual_assert.edition2021.stderr @@ -7,6 +7,7 @@ LL | | } | |_____^ help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);` | = note: `-D clippy::manual-assert` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_assert)]` error: only a `panic!` in `if`-then statement --> $DIR/manual_assert.rs:33:5 diff --git a/tests/ui/manual_async_fn.stderr b/tests/ui/manual_async_fn.stderr index b196614dff96..c0c471912e49 100644 --- a/tests/ui/manual_async_fn.stderr +++ b/tests/ui/manual_async_fn.stderr @@ -5,6 +5,7 @@ LL | fn fut() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::manual-async-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_async_fn)]` help: make the function `async` and return the output of the future directly | LL | async fn fut() -> i32 { diff --git a/tests/ui/manual_bits.stderr b/tests/ui/manual_bits.stderr index 95910650da93..2f2ed5909c1a 100644 --- a/tests/ui/manual_bits.stderr +++ b/tests/ui/manual_bits.stderr @@ -5,6 +5,7 @@ LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `i8::BITS as usize` | = note: `-D clippy::manual-bits` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_bits)]` error: usage of `mem::size_of::()` to obtain the size of `T` in bits --> $DIR/manual_bits.rs:15:5 diff --git a/tests/ui/manual_clamp.stderr b/tests/ui/manual_clamp.stderr index 95e0cf5d4ec5..2fa68ede1261 100644 --- a/tests/ui/manual_clamp.stderr +++ b/tests/ui/manual_clamp.stderr @@ -12,6 +12,7 @@ LL | | } | = note: clamp will panic if max < min = note: `-D clippy::manual-clamp` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_clamp)]` error: clamp-like pattern without using clamp function --> $DIR/manual_clamp.rs:113:5 diff --git a/tests/ui/manual_filter.stderr b/tests/ui/manual_filter.stderr index a2d56f87b64a..1490f209735a 100644 --- a/tests/ui/manual_filter.stderr +++ b/tests/ui/manual_filter.stderr @@ -11,6 +11,7 @@ LL | | }; | |_____^ help: try: `Some(0).filter(|&x| x <= 0)` | = note: `-D clippy::manual-filter` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_filter)]` error: manual implementation of `Option::filter` --> $DIR/manual_filter.rs:16:5 diff --git a/tests/ui/manual_filter_map.stderr b/tests/ui/manual_filter_map.stderr index 5b8a553f84f9..0bfc1f5c7450 100644 --- a/tests/ui/manual_filter_map.stderr +++ b/tests/ui/manual_filter_map.stderr @@ -10,6 +10,7 @@ note: the suggestion might change the behavior of the program when merging `filt LL | let _ = (0..).filter(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap()); | ^^^^^^^^^^ = note: `-D clippy::manual-filter-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_filter_map)]` error: `filter(..).map(..)` can be simplified as `filter_map(..)` --> $DIR/manual_filter_map.rs:11:19 @@ -98,6 +99,7 @@ LL | iter::>().find(|x| x.is_some()).map(|x| x.cloned().unwrap() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned())` | = note: `-D clippy::manual-find-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_find_map)]` error: `find(..).map(..)` can be simplified as `find_map(..)` --> $DIR/manual_filter_map.rs:34:28 diff --git a/tests/ui/manual_find.stderr b/tests/ui/manual_find.stderr index 41aa00a8bc14..286ad54625d7 100644 --- a/tests/ui/manual_find.stderr +++ b/tests/ui/manual_find.stderr @@ -12,6 +12,7 @@ LL | | None | = note: you may need to dereference some variables = note: `-D clippy::manual-find` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_find)]` error: manual implementation of `Iterator::find` --> $DIR/manual_find.rs:16:5 diff --git a/tests/ui/manual_find_fixable.stderr b/tests/ui/manual_find_fixable.stderr index 2c6f79e928a6..387d1509c136 100644 --- a/tests/ui/manual_find_fixable.stderr +++ b/tests/ui/manual_find_fixable.stderr @@ -10,6 +10,7 @@ LL | | None | |________^ help: replace with an iterator: `ARRAY.iter().find(|&&v| v == n).copied()` | = note: `-D clippy::manual-find` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_find)]` error: manual implementation of `Iterator::find` --> $DIR/manual_find_fixable.rs:19:5 diff --git a/tests/ui/manual_find_map.stderr b/tests/ui/manual_find_map.stderr index 67523711cc8e..0dc9ae1df035 100644 --- a/tests/ui/manual_find_map.stderr +++ b/tests/ui/manual_find_map.stderr @@ -10,6 +10,7 @@ note: the suggestion might change the behavior of the program when merging `filt LL | let _ = (0..).find(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap()); | ^^^^^^^^^^ = note: `-D clippy::manual-find-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_find_map)]` error: `find(..).map(..)` can be simplified as `find_map(..)` --> $DIR/manual_find_map.rs:11:19 diff --git a/tests/ui/manual_flatten.stderr b/tests/ui/manual_flatten.stderr index 227bf3c5eaed..aa5c2104f654 100644 --- a/tests/ui/manual_flatten.stderr +++ b/tests/ui/manual_flatten.stderr @@ -20,6 +20,7 @@ LL | | println!("{}", y); LL | | } | |_________^ = note: `-D clippy::manual-flatten` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_flatten)]` error: unnecessary `if let` since only the `Ok` variant of the iterator element is used --> $DIR/manual_flatten.rs:16:5 diff --git a/tests/ui/manual_float_methods.stderr b/tests/ui/manual_float_methods.stderr index 35beb6fec733..680ab2efa094 100644 --- a/tests/ui/manual_float_methods.stderr +++ b/tests/ui/manual_float_methods.stderr @@ -5,6 +5,7 @@ LL | if x == f32::INFINITY || x == f32::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()` | = note: `-D clippy::manual-is-infinite` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_is_infinite)]` error: manually checking if a float is finite --> $DIR/manual_float_methods.rs:24:8 @@ -13,6 +14,7 @@ LL | if x != f32::INFINITY && x != f32::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::manual-is-finite` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_is_finite)]` help: use the dedicated method instead | LL | if x.is_finite() {} diff --git a/tests/ui/manual_instant_elapsed.stderr b/tests/ui/manual_instant_elapsed.stderr index 5537f5642a23..56d0b9cd77b2 100644 --- a/tests/ui/manual_instant_elapsed.stderr +++ b/tests/ui/manual_instant_elapsed.stderr @@ -5,6 +5,7 @@ LL | let duration = Instant::now() - prev_instant; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `prev_instant.elapsed()` | = note: `-D clippy::manual-instant-elapsed` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_instant_elapsed)]` error: manual implementation of `Instant::elapsed` --> $DIR/manual_instant_elapsed.rs:26:5 diff --git a/tests/ui/manual_is_ascii_check.stderr b/tests/ui/manual_is_ascii_check.stderr index 0497259b69b4..e0fb46e59fa1 100644 --- a/tests/ui/manual_is_ascii_check.stderr +++ b/tests/ui/manual_is_ascii_check.stderr @@ -5,6 +5,7 @@ LL | assert!(matches!('x', 'a'..='z')); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_lowercase()` | = note: `-D clippy::manual-is-ascii-check` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_is_ascii_check)]` error: manual check for common ascii range --> $DIR/manual_is_ascii_check.rs:6:13 diff --git a/tests/ui/manual_let_else.stderr b/tests/ui/manual_let_else.stderr index 309ce3986f37..49dbd7615e02 100644 --- a/tests/ui/manual_let_else.stderr +++ b/tests/ui/manual_let_else.stderr @@ -5,6 +5,7 @@ LL | let v = if let Some(v_some) = g() { v_some } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { return };` | = note: `-D clippy::manual-let-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_let_else)]` error: this could be rewritten as `let...else` --> $DIR/manual_let_else.rs:28:5 diff --git a/tests/ui/manual_let_else_match.stderr b/tests/ui/manual_let_else_match.stderr index fb7d83f32440..8ca2c84072d0 100644 --- a/tests/ui/manual_let_else_match.stderr +++ b/tests/ui/manual_let_else_match.stderr @@ -10,6 +10,7 @@ LL | | }; | |______^ help: consider writing: `let Some(v) = g() else { return };` | = note: `-D clippy::manual-let-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_let_else)]` error: this could be rewritten as `let...else` --> $DIR/manual_let_else_match.rs:43:5 diff --git a/tests/ui/manual_let_else_question_mark.stderr b/tests/ui/manual_let_else_question_mark.stderr index ea35618e3c10..bf0b1bbf0dd3 100644 --- a/tests/ui/manual_let_else_question_mark.stderr +++ b/tests/ui/manual_let_else_question_mark.stderr @@ -5,6 +5,7 @@ LL | let Some(v) = g() else { return None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `let v = g()?;` | = note: `-D clippy::question-mark` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::question_mark)]` error: this `let...else` may be rewritten with the `?` operator --> $DIR/manual_let_else_question_mark.rs:35:5 @@ -29,6 +30,7 @@ LL | | }; | |______^ | = note: `-D clippy::manual-let-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_let_else)]` help: consider writing | LL ~ let Some(v) = g() else { diff --git a/tests/ui/manual_main_separator_str.stderr b/tests/ui/manual_main_separator_str.stderr index f7612efa5006..3e92bd0238c3 100644 --- a/tests/ui/manual_main_separator_str.stderr +++ b/tests/ui/manual_main_separator_str.stderr @@ -5,6 +5,7 @@ LL | let _: &str = &MAIN_SEPARATOR.to_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `std::path::MAIN_SEPARATOR_STR` | = note: `-D clippy::manual-main-separator-str` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_main_separator_str)]` error: taking a reference on `std::path::MAIN_SEPARATOR` conversion to `String` --> $DIR/manual_main_separator_str.rs:22:17 diff --git a/tests/ui/manual_map_option.stderr b/tests/ui/manual_map_option.stderr index 3e5fd923df82..ff6ed974d4a1 100644 --- a/tests/ui/manual_map_option.stderr +++ b/tests/ui/manual_map_option.stderr @@ -8,6 +8,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|_| 2)` | = note: `-D clippy::manual-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_map)]` error: manual implementation of `Option::map` --> $DIR/manual_map_option.rs:18:5 diff --git a/tests/ui/manual_map_option_2.stderr b/tests/ui/manual_map_option_2.stderr index e71000dd5d54..bf242c0416c2 100644 --- a/tests/ui/manual_map_option_2.stderr +++ b/tests/ui/manual_map_option_2.stderr @@ -12,6 +12,7 @@ LL | | }; | |_____^ | = note: `-D clippy::manual-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_map)]` help: try | LL ~ let _ = Some(0).map(|x| { diff --git a/tests/ui/manual_memcpy/with_loop_counters.stderr b/tests/ui/manual_memcpy/with_loop_counters.stderr index e23c95dc8a4a..3f000fbab699 100644 --- a/tests/ui/manual_memcpy/with_loop_counters.stderr +++ b/tests/ui/manual_memcpy/with_loop_counters.stderr @@ -10,6 +10,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst[3..src.len()].copy_from_slice(&src[..(src.len() - 3)]);` | = note: `-D clippy::manual-memcpy` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_memcpy)]` error: it looks like you're manually copying between slices --> $DIR/with_loop_counters.rs:13:5 diff --git a/tests/ui/manual_memcpy/without_loop_counters.stderr b/tests/ui/manual_memcpy/without_loop_counters.stderr index 4f02c698a0d6..b9dbda6ede71 100644 --- a/tests/ui/manual_memcpy/without_loop_counters.stderr +++ b/tests/ui/manual_memcpy/without_loop_counters.stderr @@ -9,6 +9,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst[..src.len()].copy_from_slice(&src[..]);` | = note: `-D clippy::manual-memcpy` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_memcpy)]` error: it looks like you're manually copying between slices --> $DIR/without_loop_counters.rs:15:5 diff --git a/tests/ui/manual_next_back.stderr b/tests/ui/manual_next_back.stderr index d2e52b40b4f4..a63d266dd623 100644 --- a/tests/ui/manual_next_back.stderr +++ b/tests/ui/manual_next_back.stderr @@ -5,6 +5,7 @@ LL | let _ = (0..10).rev().next().unwrap(); | ^^^^^^^^^^^^^ help: use: `.next_back()` | = note: `-D clippy::manual-next-back` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_next_back)]` error: manual backwards iteration --> $DIR/manual_next_back.rs:33:32 diff --git a/tests/ui/manual_non_exhaustive_enum.stderr b/tests/ui/manual_non_exhaustive_enum.stderr index ab068d4827e7..ce7e21c94bbd 100644 --- a/tests/ui/manual_non_exhaustive_enum.stderr +++ b/tests/ui/manual_non_exhaustive_enum.stderr @@ -20,6 +20,7 @@ help: remove this variant LL | _C, | ^^ = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_non_exhaustive)]` error: this seems like a manual implementation of the non-exhaustive pattern --> $DIR/manual_non_exhaustive_enum.rs:15:1 diff --git a/tests/ui/manual_non_exhaustive_struct.stderr b/tests/ui/manual_non_exhaustive_struct.stderr index c062af6356c4..028b8ff76391 100644 --- a/tests/ui/manual_non_exhaustive_struct.stderr +++ b/tests/ui/manual_non_exhaustive_struct.stderr @@ -19,6 +19,7 @@ help: remove this field LL | _c: (), | ^^^^^^ = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_non_exhaustive)]` error: this seems like a manual implementation of the non-exhaustive pattern --> $DIR/manual_non_exhaustive_struct.rs:14:5 diff --git a/tests/ui/manual_ok_or.stderr b/tests/ui/manual_ok_or.stderr index 65459a097384..ddb2cf261e40 100644 --- a/tests/ui/manual_ok_or.stderr +++ b/tests/ui/manual_ok_or.stderr @@ -5,6 +5,7 @@ LL | foo.map_or(Err("error"), |v| Ok(v)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `foo.ok_or("error")` | = note: `-D clippy::manual-ok-or` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_ok_or)]` error: this pattern reimplements `Option::ok_or` --> $DIR/manual_ok_or.rs:14:5 diff --git a/tests/ui/manual_range_patterns.stderr b/tests/ui/manual_range_patterns.stderr index 1cf58d7df6a3..3eee39af86e7 100644 --- a/tests/ui/manual_range_patterns.stderr +++ b/tests/ui/manual_range_patterns.stderr @@ -5,6 +5,7 @@ LL | let _ = matches!(f, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` | = note: `-D clippy::manual-range-patterns` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_range_patterns)]` error: this OR pattern can be rewritten using a range --> $DIR/manual_range_patterns.rs:9:25 diff --git a/tests/ui/manual_rem_euclid.stderr b/tests/ui/manual_rem_euclid.stderr index c93d37a8bd4d..f296f264665c 100644 --- a/tests/ui/manual_rem_euclid.stderr +++ b/tests/ui/manual_rem_euclid.stderr @@ -5,6 +5,7 @@ LL | let _: i32 = ((value % 4) + 4) % 4; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` | = note: `-D clippy::manual-rem-euclid` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_rem_euclid)]` error: manual `rem_euclid` implementation --> $DIR/manual_rem_euclid.rs:14:18 diff --git a/tests/ui/manual_retain.stderr b/tests/ui/manual_retain.stderr index cc1b449d25ab..0c5b1383b6ae 100644 --- a/tests/ui/manual_retain.stderr +++ b/tests/ui/manual_retain.stderr @@ -5,6 +5,7 @@ LL | binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `binary_heap.retain(|x| x % 2 == 0)` | = note: `-D clippy::manual-retain` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_retain)]` error: this expression can be written more simply using `.retain()` --> $DIR/manual_retain.rs:23:5 diff --git a/tests/ui/manual_saturating_arithmetic.stderr b/tests/ui/manual_saturating_arithmetic.stderr index 06f578b3c1d8..dc36a5ee7c69 100644 --- a/tests/ui/manual_saturating_arithmetic.stderr +++ b/tests/ui/manual_saturating_arithmetic.stderr @@ -5,6 +5,7 @@ LL | let _ = 1u32.checked_add(1).unwrap_or(u32::max_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1u32.saturating_add(1)` | = note: `-D clippy::manual-saturating-arithmetic` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_saturating_arithmetic)]` error: manual saturating arithmetic --> $DIR/manual_saturating_arithmetic.rs:7:13 diff --git a/tests/ui/manual_slice_size_calculation.stderr b/tests/ui/manual_slice_size_calculation.stderr index 812d02c96fce..ebdb748137a9 100644 --- a/tests/ui/manual_slice_size_calculation.stderr +++ b/tests/ui/manual_slice_size_calculation.stderr @@ -5,6 +5,7 @@ LL | let _ = s_i32.len() * size_of::(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` | = note: `-D clippy::manual-slice-size-calculation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_slice_size_calculation)]` error: manual slice size calculation --> $DIR/manual_slice_size_calculation.rs:16:13 diff --git a/tests/ui/manual_split_once.stderr b/tests/ui/manual_split_once.stderr index d425f0881c0b..494a035edc3a 100644 --- a/tests/ui/manual_split_once.stderr +++ b/tests/ui/manual_split_once.stderr @@ -5,6 +5,7 @@ LL | let _ = "key=value".splitn(2, '=').nth(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split_once('=').unwrap().1` | = note: `-D clippy::manual-split-once` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_split_once)]` error: manual implementation of `split_once` --> $DIR/manual_split_once.rs:12:13 diff --git a/tests/ui/manual_str_repeat.stderr b/tests/ui/manual_str_repeat.stderr index b92835884d9c..9a13aa972273 100644 --- a/tests/ui/manual_str_repeat.stderr +++ b/tests/ui/manual_str_repeat.stderr @@ -5,6 +5,7 @@ LL | let _: String = std::iter::repeat("test").take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"test".repeat(10)` | = note: `-D clippy::manual-str-repeat` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_str_repeat)]` error: manual implementation of `str::repeat` using iterators --> $DIR/manual_str_repeat.rs:8:21 diff --git a/tests/ui/manual_string_new.stderr b/tests/ui/manual_string_new.stderr index 02aac6fdfeb0..399652d3fecb 100644 --- a/tests/ui/manual_string_new.stderr +++ b/tests/ui/manual_string_new.stderr @@ -5,6 +5,7 @@ LL | let _ = "".to_string(); | ^^^^^^^^^^^^^^ help: consider using: `String::new()` | = note: `-D clippy::manual-string-new` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_string_new)]` error: empty String is being created manually --> $DIR/manual_string_new.rs:16:13 diff --git a/tests/ui/manual_strip.stderr b/tests/ui/manual_strip.stderr index e7be2b4b9cec..0bf6975b1e36 100644 --- a/tests/ui/manual_strip.stderr +++ b/tests/ui/manual_strip.stderr @@ -10,6 +10,7 @@ note: the prefix was tested here LL | if s.starts_with("ab") { | ^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::manual-strip` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_strip)]` help: try using the `strip_prefix` method | LL ~ if let Some() = s.strip_prefix("ab") { diff --git a/tests/ui/manual_try_fold.stderr b/tests/ui/manual_try_fold.stderr index f1bb97c6d0f3..4eb3e302b214 100644 --- a/tests/ui/manual_try_fold.stderr +++ b/tests/ui/manual_try_fold.stderr @@ -5,6 +5,7 @@ LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(0i32, |sum, i| ...)` | = note: `-D clippy::manual-try-fold` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_try_fold)]` error: usage of `Iterator::fold` on a type that implements `Try` --> $DIR/manual_try_fold.rs:63:10 diff --git a/tests/ui/manual_unwrap_or.stderr b/tests/ui/manual_unwrap_or.stderr index 8b6de5d18bf8..3a0759dccaf2 100644 --- a/tests/ui/manual_unwrap_or.stderr +++ b/tests/ui/manual_unwrap_or.stderr @@ -8,6 +8,7 @@ LL | | }; | |_____^ help: replace with: `Some(1).unwrap_or(42)` | = note: `-D clippy::manual-unwrap-or` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_unwrap_or)]` error: this pattern reimplements `Option::unwrap_or` --> $DIR/manual_unwrap_or.rs:12:5 diff --git a/tests/ui/manual_while_let_some.stderr b/tests/ui/manual_while_let_some.stderr index 33dd313b21a5..37387c8c320f 100644 --- a/tests/ui/manual_while_let_some.stderr +++ b/tests/ui/manual_while_let_some.stderr @@ -5,6 +5,7 @@ LL | let number = numbers.pop().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::manual-while-let-some` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_while_let_some)]` help: consider using a `while..let` loop | LL ~ while let Some(number) = numbers.pop() { diff --git a/tests/ui/many_single_char_names.stderr b/tests/ui/many_single_char_names.stderr index 4f5a69a9b609..688158cff6b0 100644 --- a/tests/ui/many_single_char_names.stderr +++ b/tests/ui/many_single_char_names.stderr @@ -11,6 +11,7 @@ LL | let e: i32; | ^ | = note: `-D clippy::many-single-char-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::many_single_char_names)]` error: 6 bindings with single-character names in scope --> $DIR/many_single_char_names.rs:5:9 diff --git a/tests/ui/map_clone.stderr b/tests/ui/map_clone.stderr index d84a5bf8d4de..eb11f084887d 100644 --- a/tests/ui/map_clone.stderr +++ b/tests/ui/map_clone.stderr @@ -5,6 +5,7 @@ LL | let _: Vec = vec![5_i8; 6].iter().map(|x| *x).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `vec![5_i8; 6].iter().copied()` | = note: `-D clippy::map-clone` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_clone)]` error: you are using an explicit closure for cloning elements --> $DIR/map_clone.rs:12:26 diff --git a/tests/ui/map_collect_result_unit.stderr b/tests/ui/map_collect_result_unit.stderr index 3108582aa43b..1a505d4cecc3 100644 --- a/tests/ui/map_collect_result_unit.stderr +++ b/tests/ui/map_collect_result_unit.stderr @@ -5,6 +5,7 @@ LL | let _ = (0..3).map(|t| Err(t + 1)).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(0..3).try_for_each(|t| Err(t + 1))` | = note: `-D clippy::map-collect-result-unit` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_collect_result_unit)]` error: `.map().collect()` can be replaced with `.try_for_each()` --> $DIR/map_collect_result_unit.rs:6:32 diff --git a/tests/ui/map_err.stderr b/tests/ui/map_err.stderr index d44403a84a56..6a845c84a2a9 100644 --- a/tests/ui/map_err.stderr +++ b/tests/ui/map_err.stderr @@ -6,6 +6,7 @@ LL | println!("{:?}", x.map_err(|_| Errors::Ignored)); | = help: consider storing the original error as a source in the new error, or silence this warning using an ignored identifier (`.map_err(|_foo| ...`) = note: `-D clippy::map-err-ignore` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_err_ignore)]` error: aborting due to previous error diff --git a/tests/ui/map_flatten.stderr b/tests/ui/map_flatten.stderr index 88fdd04c0236..a65d8f75ddd2 100644 --- a/tests/ui/map_flatten.stderr +++ b/tests/ui/map_flatten.stderr @@ -12,6 +12,7 @@ LL | | .flatten(); | |__________________^ | = note: `-D clippy::map-flatten` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_flatten)]` help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|x| { diff --git a/tests/ui/map_flatten_fixable.stderr b/tests/ui/map_flatten_fixable.stderr index 865929421532..e5387eead2e0 100644 --- a/tests/ui/map_flatten_fixable.stderr +++ b/tests/ui/map_flatten_fixable.stderr @@ -5,6 +5,7 @@ LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().coll | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(option_id)` | = note: `-D clippy::map-flatten` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_flatten)]` error: called `map(..).flatten()` on `Iterator` --> $DIR/map_flatten_fixable.rs:17:47 diff --git a/tests/ui/map_identity.stderr b/tests/ui/map_identity.stderr index 97ff7ea70d78..8942fd7c0d26 100644 --- a/tests/ui/map_identity.stderr +++ b/tests/ui/map_identity.stderr @@ -5,6 +5,7 @@ LL | let _: Vec<_> = x.iter().map(not_identity).map(|x| return x).collect(); | ^^^^^^^^^^^^^^^^^^ help: remove the call to `map` | = note: `-D clippy::map-identity` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_identity)]` error: unnecessary map of the identity function --> $DIR/map_identity.rs:8:57 diff --git a/tests/ui/map_unwrap_or.stderr b/tests/ui/map_unwrap_or.stderr index 5b3c61acf747..7b7eeb322a55 100644 --- a/tests/ui/map_unwrap_or.stderr +++ b/tests/ui/map_unwrap_or.stderr @@ -8,6 +8,7 @@ LL | | .unwrap_or(0); | |_____________________^ | = note: `-D clippy::map-unwrap-or` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_unwrap_or)]` help: use `map_or(, )` instead | LL - let _ = opt.map(|x| x + 1) diff --git a/tests/ui/map_unwrap_or_fixable.stderr b/tests/ui/map_unwrap_or_fixable.stderr index 0635a8c79bdc..ca611ac9d7ff 100644 --- a/tests/ui/map_unwrap_or_fixable.stderr +++ b/tests/ui/map_unwrap_or_fixable.stderr @@ -8,6 +8,7 @@ LL | | .unwrap_or_else(|| 0); | |_____________________________^ help: try: `opt.map_or_else(|| 0, |x| x + 1)` | = note: `-D clippy::map-unwrap-or` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_unwrap_or)]` error: called `map().unwrap_or_else()` on a `Result` value. This can be done more directly by calling `.map_or_else(, )` instead --> $DIR/map_unwrap_or_fixable.rs:46:13 diff --git a/tests/ui/match_as_ref.stderr b/tests/ui/match_as_ref.stderr index 79ca203ee13a..cb0191370eaa 100644 --- a/tests/ui/match_as_ref.stderr +++ b/tests/ui/match_as_ref.stderr @@ -9,6 +9,7 @@ LL | | }; | |_____^ help: try: `owned.as_ref()` | = note: `-D clippy::match-as-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_as_ref)]` error: use `as_mut()` instead --> $DIR/match_as_ref.rs:12:39 diff --git a/tests/ui/match_bool.stderr b/tests/ui/match_bool.stderr index 351ebfc08cdb..369f4e1c6fab 100644 --- a/tests/ui/match_bool.stderr +++ b/tests/ui/match_bool.stderr @@ -5,6 +5,7 @@ LL | match test && test { | ^^^^^^^^^^^^ help: try: `test` | = note: `-D clippy::nonminimal-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` error: you seem to be trying to match on a boolean expression --> $DIR/match_bool.rs:7:5 diff --git a/tests/ui/match_expr_like_matches_macro.stderr b/tests/ui/match_expr_like_matches_macro.stderr index 06006e26aff2..c702523783e7 100644 --- a/tests/ui/match_expr_like_matches_macro.stderr +++ b/tests/ui/match_expr_like_matches_macro.stderr @@ -9,6 +9,7 @@ LL | | }; | |_____^ help: try: `matches!(x, Some(0))` | = note: `-D clippy::match-like-matches-macro` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_like_matches_macro)]` error: redundant pattern matching, consider using `is_some()` --> $DIR/match_expr_like_matches_macro.rs:20:14 @@ -21,6 +22,7 @@ LL | | }; | |_____^ help: try: `x.is_some()` | = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_none()` --> $DIR/match_expr_like_matches_macro.rs:26:14 diff --git a/tests/ui/match_on_vec_items.stderr b/tests/ui/match_on_vec_items.stderr index 71038aaad49f..140a458cb9a4 100644 --- a/tests/ui/match_on_vec_items.stderr +++ b/tests/ui/match_on_vec_items.stderr @@ -5,6 +5,7 @@ LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` | = note: `-D clippy::match-on-vec-items` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_on_vec_items)]` error: indexing into a vector may panic --> $DIR/match_on_vec_items.rs:19:11 diff --git a/tests/ui/match_overlapping_arm.stderr b/tests/ui/match_overlapping_arm.stderr index ceec40e8def0..322c704f2aa2 100644 --- a/tests/ui/match_overlapping_arm.stderr +++ b/tests/ui/match_overlapping_arm.stderr @@ -10,6 +10,7 @@ note: overlaps with this LL | 0..=11 => println!("0..=11"), | ^^^^^^ = note: `-D clippy::match-overlapping-arm` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_overlapping_arm)]` error: some ranges overlap --> $DIR/match_overlapping_arm.rs:19:9 diff --git a/tests/ui/match_ref_pats.stderr b/tests/ui/match_ref_pats.stderr index c65a2d100bee..e3bb2824aa07 100644 --- a/tests/ui/match_ref_pats.stderr +++ b/tests/ui/match_ref_pats.stderr @@ -8,6 +8,7 @@ LL | | } | |_________^ | = note: `-D clippy::match-ref-pats` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_ref_pats)]` help: instead of prefixing all patterns with `&`, you can dereference the expression | LL ~ match *v { @@ -38,6 +39,7 @@ LL | if let &None = a { | -------^^^^^---- help: try: `if a.is_none()` | = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_none()` --> $DIR/match_ref_pats.rs:42:12 diff --git a/tests/ui/match_result_ok.stderr b/tests/ui/match_result_ok.stderr index 2cf38624e576..de0361bd6b41 100644 --- a/tests/ui/match_result_ok.stderr +++ b/tests/ui/match_result_ok.stderr @@ -5,6 +5,7 @@ LL | if let Some(y) = x.parse().ok() { y } else { 0 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::match-result-ok` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_result_ok)]` help: consider matching on `Ok(y)` and removing the call to `ok` instead | LL | if let Ok(y) = x.parse() { y } else { 0 } diff --git a/tests/ui/match_same_arms.stderr b/tests/ui/match_same_arms.stderr index 5f7e2b475567..824dcfdce837 100644 --- a/tests/ui/match_same_arms.stderr +++ b/tests/ui/match_same_arms.stderr @@ -11,6 +11,7 @@ note: `_` wildcard arm here LL | _ => 0, | ^^^^^^ = note: `-D clippy::match-same-arms` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]` error: this match arm has an identical body to another arm --> $DIR/match_same_arms.rs:18:9 diff --git a/tests/ui/match_same_arms2.stderr b/tests/ui/match_same_arms2.stderr index a73481875738..40b20c7e16d2 100644 --- a/tests/ui/match_same_arms2.stderr +++ b/tests/ui/match_same_arms2.stderr @@ -23,6 +23,7 @@ LL | | a LL | | }, | |_________^ = note: `-D clippy::match-same-arms` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]` error: this match arm has an identical body to another arm --> $DIR/match_same_arms2.rs:38:9 @@ -147,6 +148,7 @@ LL | | }; | |_____^ help: try: `!matches!(x, E::A | E::B)` | = note: `-D clippy::match-like-matches-macro` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_like_matches_macro)]` error: this match arm has an identical body to another arm --> $DIR/match_same_arms2.rs:199:9 diff --git a/tests/ui/match_same_arms_non_exhaustive.stderr b/tests/ui/match_same_arms_non_exhaustive.stderr index 9ee8f14ad90e..a039536338bc 100644 --- a/tests/ui/match_same_arms_non_exhaustive.stderr +++ b/tests/ui/match_same_arms_non_exhaustive.stderr @@ -11,6 +11,7 @@ note: `_` wildcard arm here LL | _ => panic!(), | ^^^^^^^^^^^^^ = note: `-D clippy::match-same-arms` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]` error: this match arm has an identical body to the `_` wildcard arm --> $DIR/match_same_arms_non_exhaustive.rs:55:13 diff --git a/tests/ui/match_single_binding.stderr b/tests/ui/match_single_binding.stderr index 9d16af76c6af..81ec200dfc7a 100644 --- a/tests/ui/match_single_binding.stderr +++ b/tests/ui/match_single_binding.stderr @@ -9,6 +9,7 @@ LL | | } | |_____^ | = note: `-D clippy::match-single-binding` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_single_binding)]` help: consider using a `let` statement | LL ~ let (x, y, z) = (a, b, c); diff --git a/tests/ui/match_single_binding2.stderr b/tests/ui/match_single_binding2.stderr index 17ef9c36767b..e7b9ef8a1cda 100644 --- a/tests/ui/match_single_binding2.stderr +++ b/tests/ui/match_single_binding2.stderr @@ -8,6 +8,7 @@ LL | | }, | |_____________^ | = note: `-D clippy::match-single-binding` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_single_binding)]` help: consider using a `let` statement | LL ~ Some((iter, _item)) => { diff --git a/tests/ui/match_str_case_mismatch.stderr b/tests/ui/match_str_case_mismatch.stderr index 3c946b30a90e..f799a4698b94 100644 --- a/tests/ui/match_str_case_mismatch.stderr +++ b/tests/ui/match_str_case_mismatch.stderr @@ -5,6 +5,7 @@ LL | "Bar" => {}, | ^^^^^ | = note: `-D clippy::match-str-case-mismatch` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_str_case_mismatch)]` help: consider changing the case of this arm to respect `to_ascii_lowercase` | LL | "bar" => {}, diff --git a/tests/ui/match_wild_err_arm.stderr b/tests/ui/match_wild_err_arm.stderr index 696ba7303a96..c120aec5b23b 100644 --- a/tests/ui/match_wild_err_arm.stderr +++ b/tests/ui/match_wild_err_arm.stderr @@ -6,6 +6,7 @@ LL | Err(_) => panic!("err"), | = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable = note: `-D clippy::match-wild-err-arm` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_wild_err_arm)]` error: `Err(_)` matches all errors --> $DIR/match_wild_err_arm.rs:32:9 diff --git a/tests/ui/match_wildcard_for_single_variants.stderr b/tests/ui/match_wildcard_for_single_variants.stderr index dfb6e695aa99..e07d3bdd32e6 100644 --- a/tests/ui/match_wildcard_for_single_variants.stderr +++ b/tests/ui/match_wildcard_for_single_variants.stderr @@ -5,6 +5,7 @@ LL | _ => (), | ^ help: try: `Self::Rgb(..)` | = note: `-D clippy::match-wildcard-for-single-variants` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_wildcard_for_single_variants)]` error: wildcard matches only a single variant and will also match any future added variants --> $DIR/match_wildcard_for_single_variants.rs:32:9 diff --git a/tests/ui/mem_forget.stderr b/tests/ui/mem_forget.stderr index dd2ea7518559..a5ab150317a1 100644 --- a/tests/ui/mem_forget.stderr +++ b/tests/ui/mem_forget.stderr @@ -6,6 +6,7 @@ LL | memstuff::forget(six); | = note: argument has type `std::sync::Arc` = note: `-D clippy::mem-forget` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mem_forget)]` error: usage of `mem::forget` on `Drop` type --> $DIR/mem_forget.rs:19:5 diff --git a/tests/ui/mem_replace.stderr b/tests/ui/mem_replace.stderr index 00f3ccbdbea6..ae5f4e5340a2 100644 --- a/tests/ui/mem_replace.stderr +++ b/tests/ui/mem_replace.stderr @@ -5,6 +5,7 @@ LL | let _ = mem::replace(&mut an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` | = note: `-D clippy::mem-replace-option-with-none` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mem_replace_option_with_none)]` error: replacing an `Option` with `None` --> $DIR/mem_replace.rs:16:13 @@ -19,6 +20,7 @@ LL | let _ = std::mem::replace(&mut s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` | = note: `-D clippy::mem-replace-with-default` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> $DIR/mem_replace.rs:24:13 diff --git a/tests/ui/mem_replace_macro.stderr b/tests/ui/mem_replace_macro.stderr index 35dda93da3d0..842ad3a8565c 100644 --- a/tests/ui/mem_replace_macro.stderr +++ b/tests/ui/mem_replace_macro.stderr @@ -5,6 +5,7 @@ LL | inline!(std::mem::replace($s, Default::default())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::mem-replace-with-default` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]` = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/tests/ui/methods.stderr b/tests/ui/methods.stderr index 6be38b24fbda..e32b3b336af6 100644 --- a/tests/ui/methods.stderr +++ b/tests/ui/methods.stderr @@ -7,6 +7,7 @@ LL | | } | |_____^ | = note: `-D clippy::new-ret-no-self` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::new_ret_no_self)]` error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead --> $DIR/methods.rs:124:13 @@ -19,6 +20,7 @@ LL | | ).next(); | |___________________________^ | = note: `-D clippy::filter-next` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::filter_next)]` error: aborting due to 2 previous errors diff --git a/tests/ui/methods_fixable.stderr b/tests/ui/methods_fixable.stderr index e4e626192ca2..1bfe56d912b7 100644 --- a/tests/ui/methods_fixable.stderr +++ b/tests/ui/methods_fixable.stderr @@ -5,6 +5,7 @@ LL | let _ = v.iter().filter(|&x| *x < 0).next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `v.iter().find(|&x| *x < 0)` | = note: `-D clippy::filter-next` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::filter_next)]` error: aborting due to previous error diff --git a/tests/ui/methods_unfixable.stderr b/tests/ui/methods_unfixable.stderr index 6e101fe16b09..581a985e0b57 100644 --- a/tests/ui/methods_unfixable.stderr +++ b/tests/ui/methods_unfixable.stderr @@ -10,6 +10,7 @@ help: you will also need to make `iter` mutable, because `find` takes `&mut self LL | let iter = (0..10); | ^^^^ = note: `-D clippy::filter-next` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::filter_next)]` error: aborting due to previous error diff --git a/tests/ui/min_ident_chars.stderr b/tests/ui/min_ident_chars.stderr index 4dff6588bb18..253636cf91da 100644 --- a/tests/ui/min_ident_chars.stderr +++ b/tests/ui/min_ident_chars.stderr @@ -5,6 +5,7 @@ LL | struct A { | ^ | = note: `-D clippy::min-ident-chars` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::min_ident_chars)]` error: this ident consists of a single char --> $DIR/min_ident_chars.rs:9:5 diff --git a/tests/ui/min_max.stderr b/tests/ui/min_max.stderr index 128394e627ca..e9c64e56b619 100644 --- a/tests/ui/min_max.stderr +++ b/tests/ui/min_max.stderr @@ -5,6 +5,7 @@ LL | min(1, max(3, x)); | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::min-max` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::min_max)]` error: this `min`/`max` combination leads to constant result --> $DIR/min_max.rs:25:5 diff --git a/tests/ui/mismatched_target_os_non_unix.stderr b/tests/ui/mismatched_target_os_non_unix.stderr index 3d41510a8563..795d043e2ac7 100644 --- a/tests/ui/mismatched_target_os_non_unix.stderr +++ b/tests/ui/mismatched_target_os_non_unix.stderr @@ -7,6 +7,7 @@ LL | #[cfg(hermit)] | help: try: `target_os = "hermit"` | = note: `-D clippy::mismatched-target-os` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mismatched_target_os)]` error: operating system used in target family position --> $DIR/mismatched_target_os_non_unix.rs:7:1 diff --git a/tests/ui/mismatched_target_os_unix.stderr b/tests/ui/mismatched_target_os_unix.stderr index 8f4c60fc9ca6..261c33754e70 100644 --- a/tests/ui/mismatched_target_os_unix.stderr +++ b/tests/ui/mismatched_target_os_unix.stderr @@ -8,6 +8,7 @@ LL | #[cfg(linux)] | = help: did you mean `unix`? = note: `-D clippy::mismatched-target-os` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mismatched_target_os)]` error: operating system used in target family position --> $DIR/mismatched_target_os_unix.rs:7:1 diff --git a/tests/ui/mismatching_type_param_order.stderr b/tests/ui/mismatching_type_param_order.stderr index b3200a51d785..8edbe329503a 100644 --- a/tests/ui/mismatching_type_param_order.stderr +++ b/tests/ui/mismatching_type_param_order.stderr @@ -6,6 +6,7 @@ LL | impl Foo {} | = help: try `A`, or a name that does not conflict with `Foo`'s generic params = note: `-D clippy::mismatching-type-param-order` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mismatching_type_param_order)]` error: `Foo` has a similarly named generic type parameter `A` in its declaration, but in a different order --> $DIR/mismatching_type_param_order.rs:11:23 diff --git a/tests/ui/misnamed_getters.stderr b/tests/ui/misnamed_getters.stderr index 58f6f3eb7387..aadec6549083 100644 --- a/tests/ui/misnamed_getters.stderr +++ b/tests/ui/misnamed_getters.stderr @@ -10,6 +10,7 @@ LL | | } | |_____^ | = note: `-D clippy::misnamed-getters` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::misnamed_getters)]` error: getter function appears to return the wrong field --> $DIR/misnamed_getters.rs:16:5 diff --git a/tests/ui/missing_assert_message.stderr b/tests/ui/missing_assert_message.stderr index 00b9a36e9091..e07f52e3f66c 100644 --- a/tests/ui/missing_assert_message.stderr +++ b/tests/ui/missing_assert_message.stderr @@ -6,6 +6,7 @@ LL | assert!(foo()); | = help: consider describing why the failing assert is problematic = note: `-D clippy::missing-assert-message` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_assert_message)]` error: assert without any message --> $DIR/missing_assert_message.rs:14:5 diff --git a/tests/ui/missing_const_for_fn/could_be_const.stderr b/tests/ui/missing_const_for_fn/could_be_const.stderr index 5c6f9e8a7f0d..b3a8ad8fa717 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.stderr +++ b/tests/ui/missing_const_for_fn/could_be_const.stderr @@ -9,6 +9,7 @@ LL | | } | |_____^ | = note: `-D clippy::missing-const-for-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_const_for_fn)]` error: this could be a `const fn` --> $DIR/could_be_const.rs:20:5 diff --git a/tests/ui/missing_doc.stderr b/tests/ui/missing_doc.stderr index 4e8a49bf1cd7..1d8007fa5b0f 100644 --- a/tests/ui/missing_doc.stderr +++ b/tests/ui/missing_doc.stderr @@ -5,6 +5,7 @@ LL | type Typedef = String; | ^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]` error: missing documentation for a module --> $DIR/missing_doc.rs:19:1 diff --git a/tests/ui/missing_doc_crate_missing.stderr b/tests/ui/missing_doc_crate_missing.stderr index 75e033cc94b4..c684bc8e7072 100644 --- a/tests/ui/missing_doc_crate_missing.stderr +++ b/tests/ui/missing_doc_crate_missing.stderr @@ -9,6 +9,7 @@ LL | | fn main() {} | |____________^ | = note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]` error: aborting due to previous error diff --git a/tests/ui/missing_doc_impl.stderr b/tests/ui/missing_doc_impl.stderr index 111d65469660..e303b7b7d9fd 100644 --- a/tests/ui/missing_doc_impl.stderr +++ b/tests/ui/missing_doc_impl.stderr @@ -8,6 +8,7 @@ LL | | } | |_^ | = note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]` error: missing documentation for a struct field --> $DIR/missing_doc_impl.rs:14:5 diff --git a/tests/ui/missing_fields_in_debug.stderr b/tests/ui/missing_fields_in_debug.stderr index 51b5e7b314ac..481b2c632177 100644 --- a/tests/ui/missing_fields_in_debug.stderr +++ b/tests/ui/missing_fields_in_debug.stderr @@ -18,6 +18,7 @@ LL | hidden: u32, = help: consider including all fields in this `Debug` impl = help: consider calling `.finish_non_exhaustive()` if you intend to ignore fields = note: `-D clippy::missing-fields-in-debug` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_fields_in_debug)]` error: manual `Debug` impl does not include all fields --> $DIR/missing_fields_in_debug.rs:32:1 diff --git a/tests/ui/missing_inline.stderr b/tests/ui/missing_inline.stderr index be24af49273f..da2a2a7fedd4 100644 --- a/tests/ui/missing_inline.stderr +++ b/tests/ui/missing_inline.stderr @@ -5,6 +5,7 @@ LL | pub fn pub_foo() {} | ^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::missing-inline-in-public-items` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_inline_in_public_items)]` error: missing `#[inline]` for a default trait method --> $DIR/missing_inline.rs:39:5 diff --git a/tests/ui/missing_panics_doc.stderr b/tests/ui/missing_panics_doc.stderr index 3dbe2dfbd88f..efee485508ec 100644 --- a/tests/ui/missing_panics_doc.stderr +++ b/tests/ui/missing_panics_doc.stderr @@ -10,6 +10,7 @@ note: first possible panic found here LL | result.unwrap() | ^^^^^^^^^^^^^^^ = note: `-D clippy::missing-panics-doc` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_panics_doc)]` error: docs for function which may panic missing `# Panics` section --> $DIR/missing_panics_doc.rs:19:1 diff --git a/tests/ui/missing_spin_loop.stderr b/tests/ui/missing_spin_loop.stderr index b525406bbf0b..a84c19d59261 100644 --- a/tests/ui/missing_spin_loop.stderr +++ b/tests/ui/missing_spin_loop.stderr @@ -5,6 +5,7 @@ LL | while b.load(Ordering::Acquire) {} | ^^ help: try: `{ std::hint::spin_loop() }` | = note: `-D clippy::missing-spin-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_spin_loop)]` error: busy-waiting loop should at least have a spin loop hint --> $DIR/missing_spin_loop.rs:12:37 diff --git a/tests/ui/missing_spin_loop_no_std.stderr b/tests/ui/missing_spin_loop_no_std.stderr index 33e5d32fe88d..0b7be4616511 100644 --- a/tests/ui/missing_spin_loop_no_std.stderr +++ b/tests/ui/missing_spin_loop_no_std.stderr @@ -5,6 +5,7 @@ LL | while b.load(Ordering::Acquire) {} | ^^ help: try: `{ core::hint::spin_loop() }` | = note: `-D clippy::missing-spin-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_spin_loop)]` error: aborting due to previous error diff --git a/tests/ui/missing_trait_methods.stderr b/tests/ui/missing_trait_methods.stderr index 8f50e76135c4..3e20a51e0842 100644 --- a/tests/ui/missing_trait_methods.stderr +++ b/tests/ui/missing_trait_methods.stderr @@ -10,6 +10,7 @@ help: implement the method LL | fn provided() {} | ^^^^^^^^^^^^^ = note: `-D clippy::missing-trait-methods` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_trait_methods)]` error: missing trait method provided by default: `b` --> $DIR/missing_trait_methods.rs:25:1 diff --git a/tests/ui/mixed_read_write_in_expression.stderr b/tests/ui/mixed_read_write_in_expression.stderr index e0b405ddece9..3dad98815c61 100644 --- a/tests/ui/mixed_read_write_in_expression.stderr +++ b/tests/ui/mixed_read_write_in_expression.stderr @@ -10,6 +10,7 @@ note: whether read occurs before this write depends on evaluation order LL | x = 1; | ^^^^^ = note: `-D clippy::mixed-read-write-in-expression` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mixed_read_write_in_expression)]` error: unsequenced read of `x` --> $DIR/mixed_read_write_in_expression.rs:18:5 diff --git a/tests/ui/module_inception.stderr b/tests/ui/module_inception.stderr index b4f80a5bc7c2..d5856614f91f 100644 --- a/tests/ui/module_inception.stderr +++ b/tests/ui/module_inception.stderr @@ -9,6 +9,7 @@ LL | | } | |_________^ | = note: `-D clippy::module-inception` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::module_inception)]` error: module has the same name as its containing module --> $DIR/module_inception.rs:12:5 diff --git a/tests/ui/module_name_repetitions.stderr b/tests/ui/module_name_repetitions.stderr index 3c7fa1def2ba..1854d3a859a7 100644 --- a/tests/ui/module_name_repetitions.stderr +++ b/tests/ui/module_name_repetitions.stderr @@ -5,6 +5,7 @@ LL | pub fn foo_bar() {} | ^^^^^^^ | = note: `-D clippy::module-name-repetitions` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::module_name_repetitions)]` error: item name ends with its containing module's name --> $DIR/module_name_repetitions.rs:11:12 diff --git a/tests/ui/modulo_arithmetic_float.stderr b/tests/ui/modulo_arithmetic_float.stderr index 3faf8c5aee1c..46c8d0288a35 100644 --- a/tests/ui/modulo_arithmetic_float.stderr +++ b/tests/ui/modulo_arithmetic_float.stderr @@ -6,6 +6,7 @@ LL | -1.6 % 2.1; | = note: double check for expected result especially when interoperating with different languages = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::modulo_arithmetic)]` error: you are using modulo operator on constants with different signs: `1.600 % -2.100` --> $DIR/modulo_arithmetic_float.rs:9:5 diff --git a/tests/ui/modulo_arithmetic_integral.stderr b/tests/ui/modulo_arithmetic_integral.stderr index 6d61afa0c311..033a016c0e6f 100644 --- a/tests/ui/modulo_arithmetic_integral.stderr +++ b/tests/ui/modulo_arithmetic_integral.stderr @@ -7,6 +7,7 @@ LL | a % b; = note: double check for expected result especially when interoperating with different languages = note: or consider using `rem_euclid` or similar function = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::modulo_arithmetic)]` error: you are using modulo operator on types that might have different signs --> $DIR/modulo_arithmetic_integral.rs:11:5 diff --git a/tests/ui/modulo_arithmetic_integral_const.stderr b/tests/ui/modulo_arithmetic_integral_const.stderr index 59267b0e7969..47ed2261a7b6 100644 --- a/tests/ui/modulo_arithmetic_integral_const.stderr +++ b/tests/ui/modulo_arithmetic_integral_const.stderr @@ -7,6 +7,7 @@ LL | -1 % 2; = note: double check for expected result especially when interoperating with different languages = note: or consider using `rem_euclid` or similar function = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::modulo_arithmetic)]` error: you are using modulo operator on constants with different signs: `1 % -2` --> $DIR/modulo_arithmetic_integral_const.rs:14:5 diff --git a/tests/ui/modulo_one.stderr b/tests/ui/modulo_one.stderr index 62e23ee9a595..cc211ab6cd34 100644 --- a/tests/ui/modulo_one.stderr +++ b/tests/ui/modulo_one.stderr @@ -25,6 +25,7 @@ LL | 10 % 1; | ^^^^^^ | = note: `-D clippy::modulo-one` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::modulo_one)]` error: any number modulo -1 will panic/overflow or result in 0 --> $DIR/modulo_one.rs:11:5 diff --git a/tests/ui/multi_assignments.stderr b/tests/ui/multi_assignments.stderr index 813e920f74d7..9719b5e66847 100644 --- a/tests/ui/multi_assignments.stderr +++ b/tests/ui/multi_assignments.stderr @@ -5,6 +5,7 @@ LL | a = b = c; | ^^^^^^^^^ | = note: `-D clippy::multi-assignments` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::multi_assignments)]` error: assignments don't nest intuitively --> $DIR/multi_assignments.rs:7:5 diff --git a/tests/ui/multiple_unsafe_ops_per_block.stderr b/tests/ui/multiple_unsafe_ops_per_block.stderr index badc284ec423..4803a5089ab2 100644 --- a/tests/ui/multiple_unsafe_ops_per_block.stderr +++ b/tests/ui/multiple_unsafe_ops_per_block.stderr @@ -18,6 +18,7 @@ note: unsafe function call occurs here LL | not_very_safe(); | ^^^^^^^^^^^^^^^ = note: `-D clippy::multiple-unsafe-ops-per-block` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::multiple_unsafe_ops_per_block)]` error: this `unsafe` block contains 2 unsafe operations, expected only one --> $DIR/multiple_unsafe_ops_per_block.rs:45:5 diff --git a/tests/ui/must_use_candidates.stderr b/tests/ui/must_use_candidates.stderr index 35da27d83a40..581399f3e486 100644 --- a/tests/ui/must_use_candidates.stderr +++ b/tests/ui/must_use_candidates.stderr @@ -5,6 +5,7 @@ LL | pub fn pure(i: u8) -> u8 { | ^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn pure(i: u8) -> u8` | = note: `-D clippy::must-use-candidate` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::must_use_candidate)]` error: this method could have a `#[must_use]` attribute --> $DIR/must_use_candidates.rs:21:5 diff --git a/tests/ui/must_use_unit.stderr b/tests/ui/must_use_unit.stderr index bb421abc663c..e67d9b5b9d8d 100644 --- a/tests/ui/must_use_unit.stderr +++ b/tests/ui/must_use_unit.stderr @@ -7,6 +7,7 @@ LL | pub fn must_use_default() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::must-use-unit` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::must_use_unit)]` error: this unit-returning function has a `#[must_use]` attribute --> $DIR/must_use_unit.rs:13:1 diff --git a/tests/ui/mut_from_ref.stderr b/tests/ui/mut_from_ref.stderr index 1c3df2b54fca..38f47b9ad7b5 100644 --- a/tests/ui/mut_from_ref.stderr +++ b/tests/ui/mut_from_ref.stderr @@ -10,6 +10,7 @@ note: immutable borrow here LL | fn this_wont_hurt_a_bit(&self) -> &mut Foo { | ^^^^^ = note: `-D clippy::mut-from-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mut_from_ref)]` error: mutable borrow from immutable input(s) --> $DIR/mut_from_ref.rs:14:25 diff --git a/tests/ui/mut_key.stderr b/tests/ui/mut_key.stderr index bce9d4b58927..3701769a9ca7 100644 --- a/tests/ui/mut_key.stderr +++ b/tests/ui/mut_key.stderr @@ -5,6 +5,7 @@ LL | fn should_not_take_this_arg(m: &mut HashMap, _n: usize) -> Hash | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::mutable-key-type` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mutable_key_type)]` error: mutable key type --> $DIR/mut_key.rs:31:72 @@ -109,6 +110,7 @@ LL | fn should_not_take_this_arg(m: &mut HashMap, _n: usize) -> Hash | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&HashMap` | = note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]` error: aborting due to 18 previous errors diff --git a/tests/ui/mut_mut.stderr b/tests/ui/mut_mut.stderr index 58a1c4e683c9..5ed9cd1aff99 100644 --- a/tests/ui/mut_mut.stderr +++ b/tests/ui/mut_mut.stderr @@ -5,6 +5,7 @@ LL | fn fun(x: &mut &mut u32) -> bool { | ^^^^^^^^^^^^^ | = note: `-D clippy::mut-mut` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mut_mut)]` error: generally you want to avoid `&mut &mut _` if possible --> $DIR/mut_mut.rs:31:17 diff --git a/tests/ui/mut_mutex_lock.stderr b/tests/ui/mut_mutex_lock.stderr index f7b371822de8..9b20016be799 100644 --- a/tests/ui/mut_mutex_lock.stderr +++ b/tests/ui/mut_mutex_lock.stderr @@ -5,6 +5,7 @@ LL | let mut value = value_mutex.lock().unwrap(); | ^^^^ help: change this to: `get_mut` | = note: `-D clippy::mut-mutex-lock` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mut_mutex_lock)]` error: aborting due to previous error diff --git a/tests/ui/mut_range_bound.stderr b/tests/ui/mut_range_bound.stderr index c9de5393a2b1..42f8a161f74f 100644 --- a/tests/ui/mut_range_bound.stderr +++ b/tests/ui/mut_range_bound.stderr @@ -6,6 +6,7 @@ LL | m = 5; | = note: the range of the loop is unchanged = note: `-D clippy::mut-range-bound` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mut_range_bound)]` error: attempt to mutate range bound within loop --> $DIR/mut_range_bound.rs:17:9 diff --git a/tests/ui/mut_reference.stderr b/tests/ui/mut_reference.stderr index 4346560cea51..d7a0d0c22525 100644 --- a/tests/ui/mut_reference.stderr +++ b/tests/ui/mut_reference.stderr @@ -5,6 +5,7 @@ LL | takes_an_immutable_reference(&mut 42); | ^^^^^^^ | = note: `-D clippy::unnecessary-mut-passed` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_mut_passed)]` error: the function `as_ptr` doesn't need a mutable reference --> $DIR/mut_reference.rs:36:12 @@ -25,6 +26,7 @@ LL | fn takes_a_mutable_reference(&self, a: &mut i32) {} | ^^^^^^^^ help: consider changing to: `&i32` | = note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]` error: aborting due to 4 previous errors diff --git a/tests/ui/mutex_atomic.stderr b/tests/ui/mutex_atomic.stderr index 2f669067da6f..483e1ce15f6f 100644 --- a/tests/ui/mutex_atomic.stderr +++ b/tests/ui/mutex_atomic.stderr @@ -5,6 +5,7 @@ LL | Mutex::new(true); | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::mutex-atomic` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mutex_atomic)]` error: consider using an `AtomicUsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` --> $DIR/mutex_atomic.rs:11:5 @@ -37,6 +38,7 @@ LL | Mutex::new(0u32); | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::mutex-integer` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mutex_integer)]` error: consider using an `AtomicIsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` --> $DIR/mutex_atomic.rs:23:5 diff --git a/tests/ui/needless_arbitrary_self_type.stderr b/tests/ui/needless_arbitrary_self_type.stderr index c5b0b25c10b6..fe2ac34f79f6 100644 --- a/tests/ui/needless_arbitrary_self_type.stderr +++ b/tests/ui/needless_arbitrary_self_type.stderr @@ -5,6 +5,7 @@ LL | pub fn bad(self: Self) { | ^^^^^^^^^^ help: consider to change this parameter to: `self` | = note: `-D clippy::needless-arbitrary-self-type` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_arbitrary_self_type)]` error: the type of the `self` parameter does not need to be arbitrary --> $DIR/needless_arbitrary_self_type.rs:18:20 diff --git a/tests/ui/needless_arbitrary_self_type_unfixable.stderr b/tests/ui/needless_arbitrary_self_type_unfixable.stderr index c7df5936d706..183e2dbc8c16 100644 --- a/tests/ui/needless_arbitrary_self_type_unfixable.stderr +++ b/tests/ui/needless_arbitrary_self_type_unfixable.stderr @@ -5,6 +5,7 @@ LL | fn call_with_mut_self(self: &mut Self) {} | ^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&mut self` | = note: `-D clippy::needless-arbitrary-self-type` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_arbitrary_self_type)]` error: aborting due to previous error diff --git a/tests/ui/needless_bitwise_bool.stderr b/tests/ui/needless_bitwise_bool.stderr index 9752624902cc..2ed9208e6230 100644 --- a/tests/ui/needless_bitwise_bool.stderr +++ b/tests/ui/needless_bitwise_bool.stderr @@ -5,6 +5,7 @@ LL | if y & !x { | ^^^^^^ help: try: `y && !x` | = note: `-D clippy::needless-bitwise-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_bitwise_bool)]` error: aborting due to previous error diff --git a/tests/ui/needless_bool/fixable.stderr b/tests/ui/needless_bool/fixable.stderr index a2dfa2fd4827..2b189c898512 100644 --- a/tests/ui/needless_bool/fixable.stderr +++ b/tests/ui/needless_bool/fixable.stderr @@ -9,6 +9,7 @@ LL | | }; | |_____^ help: you can reduce it to: `x` | = note: `-D clippy::needless-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_bool)]` error: this if-then-else expression returns a bool literal --> $DIR/fixable.rs:45:5 @@ -137,6 +138,7 @@ LL | if x == true {}; | ^^^^^^^^^ help: try simplifying it as shown: `x` | = note: `-D clippy::bool-comparison` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::bool_comparison)]` error: equality checks against false can be replaced by a negation --> $DIR/fixable.rs:147:8 diff --git a/tests/ui/needless_bool/simple.stderr b/tests/ui/needless_bool/simple.stderr index 0ccc9416bcd5..a44205c59b75 100644 --- a/tests/ui/needless_bool/simple.stderr +++ b/tests/ui/needless_bool/simple.stderr @@ -9,6 +9,7 @@ LL | | }; | |_____^ | = note: `-D clippy::needless-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_bool)]` error: this if-then-else expression will always return false --> $DIR/simple.rs:19:5 diff --git a/tests/ui/needless_bool_assign.stderr b/tests/ui/needless_bool_assign.stderr index 8e7ea615c7d7..7866c89bd618 100644 --- a/tests/ui/needless_bool_assign.stderr +++ b/tests/ui/needless_bool_assign.stderr @@ -9,6 +9,7 @@ LL | | } | |_____^ help: you can reduce it to: `a.field = random() && random();` | = note: `-D clippy::needless-bool-assign` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_bool_assign)]` error: this if-then-else expression assigns a bool literal --> $DIR/needless_bool_assign.rs:18:5 diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr index d26c317124b8..8e27014d53c3 100644 --- a/tests/ui/needless_borrow.stderr +++ b/tests/ui/needless_borrow.stderr @@ -5,6 +5,7 @@ LL | let _ = x(&&a); // warn | ^^^ help: change this to: `&a` | = note: `-D clippy::needless-borrow` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` error: this expression creates a reference which is immediately dereferenced by the compiler --> $DIR/needless_borrow.rs:19:13 diff --git a/tests/ui/needless_borrow_pat.stderr b/tests/ui/needless_borrow_pat.stderr index 4eac32fcd9cf..ce3a36e35b85 100644 --- a/tests/ui/needless_borrow_pat.stderr +++ b/tests/ui/needless_borrow_pat.stderr @@ -5,6 +5,7 @@ LL | Some(ref x) => x, | ^^^^^ help: try: `x` | = note: `-D clippy::needless-borrow` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` error: this pattern creates a reference to a reference --> $DIR/needless_borrow_pat.rs:67:14 diff --git a/tests/ui/needless_borrowed_ref.stderr b/tests/ui/needless_borrowed_ref.stderr index 553b068c6b43..15261cfce0c3 100644 --- a/tests/ui/needless_borrowed_ref.stderr +++ b/tests/ui/needless_borrowed_ref.stderr @@ -5,6 +5,7 @@ LL | let _ = v.iter_mut().filter(|&ref a| a.is_empty()); | ^^^^^^ | = note: `-D clippy::needless-borrowed-reference` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_borrowed_reference)]` help: try removing the `&ref` part | LL - let _ = v.iter_mut().filter(|&ref a| a.is_empty()); diff --git a/tests/ui/needless_collect.stderr b/tests/ui/needless_collect.stderr index c24568bba9c8..2c21fc5965d5 100644 --- a/tests/ui/needless_collect.stderr +++ b/tests/ui/needless_collect.stderr @@ -5,6 +5,7 @@ LL | let len = sample.iter().collect::>().len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` | = note: `-D clippy::needless-collect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_collect)]` error: avoid using `collect()` when not needed --> $DIR/needless_collect.rs:10:22 diff --git a/tests/ui/needless_collect_indirect.stderr b/tests/ui/needless_collect_indirect.stderr index 9337a7412425..3d1ad2a1cfa5 100644 --- a/tests/ui/needless_collect_indirect.stderr +++ b/tests/ui/needless_collect_indirect.stderr @@ -8,6 +8,7 @@ LL | indirect_iter.into_iter().map(|x| (x, x + 1)).collect::>( | ------------------------- the iterator could be used here instead | = note: `-D clippy::needless-collect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_collect)]` help: use the original Iterator instead of collecting it and then producing a new one | LL ~ diff --git a/tests/ui/needless_continue.stderr b/tests/ui/needless_continue.stderr index 9a65248c9913..31b5dc2808da 100644 --- a/tests/ui/needless_continue.stderr +++ b/tests/ui/needless_continue.stderr @@ -35,6 +35,7 @@ LL | | } println!("bleh"); } = note: `-D clippy::needless-continue` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_continue)]` error: there is no need for an explicit `else` block for this `if` expression --> $DIR/needless_continue.rs:46:9 diff --git a/tests/ui/needless_doc_main.stderr b/tests/ui/needless_doc_main.stderr index be6675e6482e..8dd93bb05dd5 100644 --- a/tests/ui/needless_doc_main.stderr +++ b/tests/ui/needless_doc_main.stderr @@ -5,6 +5,7 @@ LL | /// fn main() { | ^^^^^^^^^^^^ | = note: `-D clippy::needless-doctest-main` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_doctest_main)]` error: needless `fn main` in doctest --> $DIR/needless_doc_main.rs:16:4 diff --git a/tests/ui/needless_else.stderr b/tests/ui/needless_else.stderr index 006e4d7d30fe..e6f7138e948d 100644 --- a/tests/ui/needless_else.stderr +++ b/tests/ui/needless_else.stderr @@ -7,6 +7,7 @@ LL | | } | |_____^ help: you can remove it | = note: `-D clippy::needless-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_else)]` error: aborting due to previous error diff --git a/tests/ui/needless_for_each_fixable.stderr b/tests/ui/needless_for_each_fixable.stderr index 08e995851d7a..3b5163b0171a 100644 --- a/tests/ui/needless_for_each_fixable.stderr +++ b/tests/ui/needless_for_each_fixable.stderr @@ -7,6 +7,7 @@ LL | | }); | |_______^ | = note: `-D clippy::needless-for-each` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_for_each)]` help: try | LL ~ for elem in v.iter() { diff --git a/tests/ui/needless_for_each_unfixable.stderr b/tests/ui/needless_for_each_unfixable.stderr index dad0053f5591..73f249ae6c2f 100644 --- a/tests/ui/needless_for_each_unfixable.stderr +++ b/tests/ui/needless_for_each_unfixable.stderr @@ -11,6 +11,7 @@ LL | | }); | |_______^ | = note: `-D clippy::needless-for-each` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_for_each)]` help: try | LL ~ for v in v.iter() { diff --git a/tests/ui/needless_if.stderr b/tests/ui/needless_if.stderr index bf131f2d7e4b..ed5b9452b86b 100644 --- a/tests/ui/needless_if.stderr +++ b/tests/ui/needless_if.stderr @@ -5,6 +5,7 @@ LL | if (true) {} | ^^^^^^^^^^^^ help: you can remove it | = note: `-D clippy::needless-if` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_if)]` error: this `if` branch is empty --> $DIR/needless_if.rs:28:5 diff --git a/tests/ui/needless_late_init.stderr b/tests/ui/needless_late_init.stderr index eff782f8bf10..602b1a683e51 100644 --- a/tests/ui/needless_late_init.stderr +++ b/tests/ui/needless_late_init.stderr @@ -7,6 +7,7 @@ LL | a = "zero"; | ^^^^^^^^^^ initialised here | = note: `-D clippy::needless-late-init` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_late_init)]` help: declare `a` here | LL | let a = "zero"; diff --git a/tests/ui/needless_lifetimes.stderr b/tests/ui/needless_lifetimes.stderr index 23b9cbe3f858..7051a2604b91 100644 --- a/tests/ui/needless_lifetimes.stderr +++ b/tests/ui/needless_lifetimes.stderr @@ -5,6 +5,7 @@ LL | fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {} | ^^ ^^ ^^ ^^ | = note: `-D clippy::needless-lifetimes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_lifetimes)]` help: elide the lifetimes | LL - fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {} diff --git a/tests/ui/needless_match.stderr b/tests/ui/needless_match.stderr index 6ae2f38bf500..736926b4415b 100644 --- a/tests/ui/needless_match.stderr +++ b/tests/ui/needless_match.stderr @@ -11,6 +11,7 @@ LL | | }; | |_____^ help: replace it with: `i` | = note: `-D clippy::needless-match` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_match)]` error: this match expression is unnecessary --> $DIR/needless_match.rs:22:19 diff --git a/tests/ui/needless_option_as_deref.stderr b/tests/ui/needless_option_as_deref.stderr index 94be76a9a45e..024d30c1717c 100644 --- a/tests/ui/needless_option_as_deref.stderr +++ b/tests/ui/needless_option_as_deref.stderr @@ -5,6 +5,7 @@ LL | let _: Option<&usize> = Some(&1).as_deref(); | ^^^^^^^^^^^^^^^^^^^ help: try: `Some(&1)` | = note: `-D clippy::needless-option-as-deref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_option_as_deref)]` error: derefed type is same as origin --> $DIR/needless_option_as_deref.rs:8:33 diff --git a/tests/ui/needless_option_take.stderr b/tests/ui/needless_option_take.stderr index b6b50d6f2ff6..d3c22441d003 100644 --- a/tests/ui/needless_option_take.stderr +++ b/tests/ui/needless_option_take.stderr @@ -5,6 +5,7 @@ LL | x.as_ref().take(); | ^^^^^^^^^^^^^^^^^ help: try: `x.as_ref()` | = note: `-D clippy::needless-option-take` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_option_take)]` error: aborting due to previous error diff --git a/tests/ui/needless_parens_on_range_literals.stderr b/tests/ui/needless_parens_on_range_literals.stderr index 0fe331ecc754..c73564e210c0 100644 --- a/tests/ui/needless_parens_on_range_literals.stderr +++ b/tests/ui/needless_parens_on_range_literals.stderr @@ -5,6 +5,7 @@ LL | let _ = ('a')..=('z'); | ^^^^^ help: try: `'a'` | = note: `-D clippy::needless-parens-on-range-literals` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_parens_on_range_literals)]` error: needless parenthesis on range literals can be removed --> $DIR/needless_parens_on_range_literals.rs:7:21 diff --git a/tests/ui/needless_pass_by_ref_mut.stderr b/tests/ui/needless_pass_by_ref_mut.stderr index 2e06e7252d9b..df3df045776b 100644 --- a/tests/ui/needless_pass_by_ref_mut.stderr +++ b/tests/ui/needless_pass_by_ref_mut.stderr @@ -5,6 +5,7 @@ LL | fn foo(s: &mut Vec, b: &u32, x: &mut u32) { | ^^^^^^^^^^^^^ help: consider changing to: `&Vec` | = note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]` error: this argument is a mutable reference, but not used mutably --> $DIR/needless_pass_by_ref_mut.rs:31:12 diff --git a/tests/ui/needless_pass_by_value.stderr b/tests/ui/needless_pass_by_value.stderr index a6bf30b1cdfb..1c3a63d661f6 100644 --- a/tests/ui/needless_pass_by_value.stderr +++ b/tests/ui/needless_pass_by_value.stderr @@ -5,6 +5,7 @@ LL | fn foo(v: Vec, w: Vec, mut x: Vec, y: Vec) -> Vec $DIR/needless_pass_by_value.rs:34:11 diff --git a/tests/ui/needless_pub_self.stderr b/tests/ui/needless_pub_self.stderr index 3aa2feb5ecd8..c1f6b908b53d 100644 --- a/tests/ui/needless_pub_self.stderr +++ b/tests/ui/needless_pub_self.stderr @@ -5,6 +5,7 @@ LL | pub(self) fn a() {} | ^^^^^^^^^ help: remove it | = note: `-D clippy::needless-pub-self` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_pub_self)]` error: unnecessary `pub(in self)` --> $DIR/needless_pub_self.rs:14:1 diff --git a/tests/ui/needless_question_mark.stderr b/tests/ui/needless_question_mark.stderr index 3e1d2c17c301..cd961a49f421 100644 --- a/tests/ui/needless_question_mark.stderr +++ b/tests/ui/needless_question_mark.stderr @@ -5,6 +5,7 @@ LL | return Some(to.magic?); | ^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `to.magic` | = note: `-D clippy::needless-question-mark` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_question_mark)]` error: question mark operator is useless here --> $DIR/needless_question_mark.rs:28:12 diff --git a/tests/ui/needless_range_loop.stderr b/tests/ui/needless_range_loop.stderr index 0358b2fb0251..0d8893c26196 100644 --- a/tests/ui/needless_range_loop.stderr +++ b/tests/ui/needless_range_loop.stderr @@ -5,6 +5,7 @@ LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ | = note: `-D clippy::needless-range-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_range_loop)]` help: consider using an iterator | LL | for in &vec { diff --git a/tests/ui/needless_range_loop2.stderr b/tests/ui/needless_range_loop2.stderr index 6e6ef73c1f6e..3d1d9e1bff43 100644 --- a/tests/ui/needless_range_loop2.stderr +++ b/tests/ui/needless_range_loop2.stderr @@ -5,6 +5,7 @@ LL | for i in 3..10 { | ^^^^^ | = note: `-D clippy::needless-range-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_range_loop)]` help: consider using an iterator | LL | for in ns.iter().take(10).skip(3) { diff --git a/tests/ui/needless_raw_string.stderr b/tests/ui/needless_raw_string.stderr index ddc36af2e724..83cc6d332ee5 100644 --- a/tests/ui/needless_raw_string.stderr +++ b/tests/ui/needless_raw_string.stderr @@ -5,6 +5,7 @@ LL | r#"aaa"#; | ^^^^^^^^ help: try: `"aaa"` | = note: `-D clippy::needless-raw-strings` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_raw_strings)]` error: unnecessary raw string literal --> $DIR/needless_raw_string.rs:9:5 diff --git a/tests/ui/needless_raw_string_hashes.stderr b/tests/ui/needless_raw_string_hashes.stderr index 9649d59a71fc..94c51c423b86 100644 --- a/tests/ui/needless_raw_string_hashes.stderr +++ b/tests/ui/needless_raw_string_hashes.stderr @@ -5,6 +5,7 @@ LL | r##"Hello "world"!"##; | ^^^^^^^^^^^^^^^^^^^^^ help: try: `r#"Hello "world"!"#` | = note: `-D clippy::needless-raw-string-hashes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_raw_string_hashes)]` error: unnecessary hashes around raw string literal --> $DIR/needless_raw_string_hashes.rs:8:5 diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr index eea9a5ff9cf2..cc48831115d9 100644 --- a/tests/ui/needless_return.stderr +++ b/tests/ui/needless_return.stderr @@ -5,6 +5,7 @@ LL | return true; | ^^^^^^^^^^^ | = note: `-D clippy::needless-return` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_return)]` help: remove `return` | LL - return true; diff --git a/tests/ui/needless_return_with_question_mark.stderr b/tests/ui/needless_return_with_question_mark.stderr index 5cc20e9682ba..0de0633803bc 100644 --- a/tests/ui/needless_return_with_question_mark.stderr +++ b/tests/ui/needless_return_with_question_mark.stderr @@ -5,6 +5,7 @@ LL | return Err(())?; | ^^^^^^^ help: remove it | = note: `-D clippy::needless-return-with-question-mark` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_return_with_question_mark)]` error: aborting due to previous error diff --git a/tests/ui/needless_splitn.stderr b/tests/ui/needless_splitn.stderr index 14c576e6457c..f347ca760dbe 100644 --- a/tests/ui/needless_splitn.stderr +++ b/tests/ui/needless_splitn.stderr @@ -5,6 +5,7 @@ LL | let _ = str.splitn(2, '=').next(); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` | = note: `-D clippy::needless-splitn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_splitn)]` error: unnecessary use of `splitn` --> $DIR/needless_splitn.rs:14:13 diff --git a/tests/ui/needless_update.stderr b/tests/ui/needless_update.stderr index b154b3b306dd..3e9e2941a7a7 100644 --- a/tests/ui/needless_update.stderr +++ b/tests/ui/needless_update.stderr @@ -5,6 +5,7 @@ LL | S { a: 1, b: 1, ..base }; | ^^^^ | = note: `-D clippy::needless-update` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_update)]` error: aborting due to previous error diff --git a/tests/ui/neg_cmp_op_on_partial_ord.stderr b/tests/ui/neg_cmp_op_on_partial_ord.stderr index c2e1f8702dde..c64d96b4b203 100644 --- a/tests/ui/neg_cmp_op_on_partial_ord.stderr +++ b/tests/ui/neg_cmp_op_on_partial_ord.stderr @@ -5,6 +5,7 @@ LL | let _not_less = !(a_value < another_value); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::neg-cmp-op-on-partial-ord` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::neg_cmp_op_on_partial_ord)]` error: the use of negated comparison operators on partially ordered types produces code that is hard to read and refactor, please consider using the `partial_cmp` method instead, to make it clear that the two values could be incomparable --> $DIR/neg_cmp_op_on_partial_ord.rs:21:30 diff --git a/tests/ui/neg_multiply.stderr b/tests/ui/neg_multiply.stderr index 8b31bca0b7d4..abfc94f97701 100644 --- a/tests/ui/neg_multiply.stderr +++ b/tests/ui/neg_multiply.stderr @@ -5,6 +5,7 @@ LL | x * -1; | ^^^^^^ help: consider using: `-x` | = note: `-D clippy::neg-multiply` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::neg_multiply)]` error: this multiplication by -1 can be written more succinctly --> $DIR/neg_multiply.rs:30:5 diff --git a/tests/ui/never_loop.stderr b/tests/ui/never_loop.stderr index 6d6d2c8ac52e..234780007b1a 100644 --- a/tests/ui/never_loop.stderr +++ b/tests/ui/never_loop.stderr @@ -137,6 +137,7 @@ LL | break 'a; | ^^^^^^^^ | = note: `-D clippy::diverging-sub-expression` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::diverging_sub_expression)]` error: this loop never actually loops --> $DIR/never_loop.rs:294:13 diff --git a/tests/ui/new_ret_no_self.stderr b/tests/ui/new_ret_no_self.stderr index 4c76603f596d..8436e101ff97 100644 --- a/tests/ui/new_ret_no_self.stderr +++ b/tests/ui/new_ret_no_self.stderr @@ -9,6 +9,7 @@ LL | | } | |_____^ | = note: `-D clippy::new-ret-no-self` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::new_ret_no_self)]` error: methods called `new` usually return `Self` --> $DIR/new_ret_no_self.rs:84:5 diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 4293cd5972df..acba5b0d7bd5 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -9,6 +9,7 @@ LL | | } | |_____^ | = note: `-D clippy::new-without-default` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::new_without_default)]` help: try adding this | LL + impl Default for Foo { diff --git a/tests/ui/no_effect.stderr b/tests/ui/no_effect.stderr index 4b8499a23a5d..feba35697f5e 100644 --- a/tests/ui/no_effect.stderr +++ b/tests/ui/no_effect.stderr @@ -5,6 +5,7 @@ LL | 0; | ^^ | = note: `-D clippy::no-effect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::no_effect)]` error: statement with no effect --> $DIR/no_effect.rs:101:5 @@ -157,6 +158,7 @@ LL | let _unused = 1; | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::no-effect-underscore-binding` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::no_effect_underscore_binding)]` error: binding to `_` prefixed variable with no side-effect --> $DIR/no_effect.rs:154:5 diff --git a/tests/ui/no_effect_replace.stderr b/tests/ui/no_effect_replace.stderr index 685b20b75d41..e1162f04f857 100644 --- a/tests/ui/no_effect_replace.stderr +++ b/tests/ui/no_effect_replace.stderr @@ -5,6 +5,7 @@ LL | let _ = "12345".replace('1', "1"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::no-effect-replace` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::no_effect_replace)]` error: replacing text with itself --> $DIR/no_effect_replace.rs:7:13 diff --git a/tests/ui/no_effect_return.stderr b/tests/ui/no_effect_return.stderr index 6b146a03abc1..b036e6342047 100644 --- a/tests/ui/no_effect_return.stderr +++ b/tests/ui/no_effect_return.stderr @@ -7,6 +7,7 @@ LL | 0u32; | help: did you mean to return it?: `return` | = note: `-D clippy::no-effect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::no_effect)]` error: statement with no effect --> $DIR/no_effect_return.rs:18:9 diff --git a/tests/ui/no_mangle_with_rust_abi.stderr b/tests/ui/no_mangle_with_rust_abi.stderr index 721dcf603b1f..62d53c8395fd 100644 --- a/tests/ui/no_mangle_with_rust_abi.stderr +++ b/tests/ui/no_mangle_with_rust_abi.stderr @@ -5,6 +5,7 @@ LL | fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::no-mangle-with-rust-abi` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::no_mangle_with_rust_abi)]` help: set an ABI | LL | extern "C" fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} diff --git a/tests/ui/non_expressive_names.stderr b/tests/ui/non_expressive_names.stderr index b62748d4989d..1b78124a9031 100644 --- a/tests/ui/non_expressive_names.stderr +++ b/tests/ui/non_expressive_names.stderr @@ -5,6 +5,7 @@ LL | let _1 = 1; | ^^ | = note: `-D clippy::just-underscores-and-digits` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::just_underscores_and_digits)]` error: consider choosing a more descriptive name --> $DIR/non_expressive_names.rs:29:9 diff --git a/tests/ui/non_minimal_cfg.stderr b/tests/ui/non_minimal_cfg.stderr index d0212e230213..c33c35ed8df9 100644 --- a/tests/ui/non_minimal_cfg.stderr +++ b/tests/ui/non_minimal_cfg.stderr @@ -5,6 +5,7 @@ LL | #[cfg(all(windows))] | ^^^^^^^^^^^^ help: try: `windows` | = note: `-D clippy::non-minimal-cfg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::non_minimal_cfg)]` error: unneeded sub `cfg` when there is only one condition --> $DIR/non_minimal_cfg.rs:6:7 diff --git a/tests/ui/non_minimal_cfg2.stderr b/tests/ui/non_minimal_cfg2.stderr index 2a9a36fbcef3..001fcddd9068 100644 --- a/tests/ui/non_minimal_cfg2.stderr +++ b/tests/ui/non_minimal_cfg2.stderr @@ -5,6 +5,7 @@ LL | #[cfg(all())] | ^^^^^ | = note: `-D clippy::non-minimal-cfg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::non_minimal_cfg)]` error: aborting due to previous error diff --git a/tests/ui/non_octal_unix_permissions.stderr b/tests/ui/non_octal_unix_permissions.stderr index 32845d065941..78c8f1a2fcf7 100644 --- a/tests/ui/non_octal_unix_permissions.stderr +++ b/tests/ui/non_octal_unix_permissions.stderr @@ -5,6 +5,7 @@ LL | options.mode(440); | ^^^ help: consider using an octal literal instead: `0o440` | = note: `-D clippy::non-octal-unix-permissions` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::non_octal_unix_permissions)]` error: using a non-octal value to set unix file permissions --> $DIR/non_octal_unix_permissions.rs:17:47 diff --git a/tests/ui/non_send_fields_in_send_ty.stderr b/tests/ui/non_send_fields_in_send_ty.stderr index 08a53b3a891c..1ea76196af93 100644 --- a/tests/ui/non_send_fields_in_send_ty.stderr +++ b/tests/ui/non_send_fields_in_send_ty.stderr @@ -11,6 +11,7 @@ LL | data: Vec>, | ^^^^^^^^^^^^^^^^^^^^^^^^ = help: add bounds on type parameter `T` that satisfy `Vec>: Send` = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::non_send_fields_in_send_ty)]` error: some fields in `MvccRwLock` are not safe to be sent to another thread --> $DIR/non_send_fields_in_send_ty.rs:26:1 diff --git a/tests/ui/nonminimal_bool.stderr b/tests/ui/nonminimal_bool.stderr index 2eba55555f43..deae389dbefa 100644 --- a/tests/ui/nonminimal_bool.stderr +++ b/tests/ui/nonminimal_bool.stderr @@ -5,6 +5,7 @@ LL | let _ = !true; | ^^^^^ help: try: `false` | = note: `-D clippy::nonminimal-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` error: this boolean expression can be simplified --> $DIR/nonminimal_bool.rs:16:13 diff --git a/tests/ui/nonminimal_bool_methods.stderr b/tests/ui/nonminimal_bool_methods.stderr index a2df889d6230..d47bbf7e0799 100644 --- a/tests/ui/nonminimal_bool_methods.stderr +++ b/tests/ui/nonminimal_bool_methods.stderr @@ -5,6 +5,7 @@ LL | let _ = !a.is_some(); | ^^^^^^^^^^^^ help: try: `a.is_none()` | = note: `-D clippy::nonminimal-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` error: this boolean expression can be simplified --> $DIR/nonminimal_bool_methods.rs:10:13 diff --git a/tests/ui/numbered_fields.stderr b/tests/ui/numbered_fields.stderr index 076c7aa0c6ac..d52a0cf15a83 100644 --- a/tests/ui/numbered_fields.stderr +++ b/tests/ui/numbered_fields.stderr @@ -10,6 +10,7 @@ LL | | }; | |_____^ help: try: `TupleStruct(1u32, 42, 23u8)` | = note: `-D clippy::init-numbered-fields` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::init_numbered_fields)]` error: used a field initializer for a tuple struct --> $DIR/numbered_fields.rs:25:13 diff --git a/tests/ui/obfuscated_if_else.stderr b/tests/ui/obfuscated_if_else.stderr index 1848151b1da2..ca9f5e1e374c 100644 --- a/tests/ui/obfuscated_if_else.stderr +++ b/tests/ui/obfuscated_if_else.stderr @@ -5,6 +5,7 @@ LL | true.then_some("a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { "a" } else { "b" }` | = note: `-D clippy::obfuscated-if-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::obfuscated_if_else)]` error: aborting due to previous error diff --git a/tests/ui/octal_escapes.stderr b/tests/ui/octal_escapes.stderr index 98f7d21261f5..d2161582b827 100644 --- a/tests/ui/octal_escapes.stderr +++ b/tests/ui/octal_escapes.stderr @@ -6,6 +6,7 @@ LL | let _bad1 = "\033[0m"; | = help: octal escapes are not supported, `\0` is always a null character = note: `-D clippy::octal-escapes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::octal_escapes)]` help: if an octal escape was intended, use the hexadecimal representation instead | LL | let _bad1 = "\x1b[0m"; diff --git a/tests/ui/ok_expect.stderr b/tests/ui/ok_expect.stderr index 4c295d7a4c25..ac2b6dcc83b5 100644 --- a/tests/ui/ok_expect.stderr +++ b/tests/ui/ok_expect.stderr @@ -6,6 +6,7 @@ LL | res.ok().expect("disaster!"); | = help: you can call `expect()` directly on the `Result` = note: `-D clippy::ok-expect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ok_expect)]` error: called `ok().expect()` on a `Result` value --> $DIR/ok_expect.rs:23:5 diff --git a/tests/ui/only_used_in_recursion.stderr b/tests/ui/only_used_in_recursion.stderr index b731d37c62c4..85eee99c01c5 100644 --- a/tests/ui/only_used_in_recursion.stderr +++ b/tests/ui/only_used_in_recursion.stderr @@ -10,6 +10,7 @@ note: parameter used here LL | if flag == 0 { 0 } else { _one_unused(flag - 1, a) } | ^ = note: `-D clippy::only-used-in-recursion` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::only_used_in_recursion)]` error: parameter is only used in recursion --> $DIR/only_used_in_recursion.rs:16:27 diff --git a/tests/ui/only_used_in_recursion2.stderr b/tests/ui/only_used_in_recursion2.stderr index ae349fd29e95..3ddd9758c26f 100644 --- a/tests/ui/only_used_in_recursion2.stderr +++ b/tests/ui/only_used_in_recursion2.stderr @@ -10,6 +10,7 @@ note: parameter used here LL | if flag == 0 { 0 } else { _with_inner(flag, a, b + x) } | ^ = note: `-D clippy::only-used-in-recursion` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::only_used_in_recursion)]` error: parameter is only used in recursion --> $DIR/only_used_in_recursion2.rs:5:25 diff --git a/tests/ui/op_ref.stderr b/tests/ui/op_ref.stderr index 5f3769ddfab4..f03e24b84005 100644 --- a/tests/ui/op_ref.stderr +++ b/tests/ui/op_ref.stderr @@ -5,6 +5,7 @@ LL | let foo = &5 - &6; | ^^^^^^^ | = note: `-D clippy::op-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::op_ref)]` help: use the values directly | LL | let foo = 5 - 6; diff --git a/tests/ui/open_options.stderr b/tests/ui/open_options.stderr index c136cf2dbf40..7ac826f52fa9 100644 --- a/tests/ui/open_options.stderr +++ b/tests/ui/open_options.stderr @@ -5,6 +5,7 @@ LL | OpenOptions::new().read(true).truncate(true).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::nonsensical-open-options` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::nonsensical_open_options)]` error: file opened with `append` and `truncate` --> $DIR/open_options.rs:9:5 diff --git a/tests/ui/option_as_ref_deref.stderr b/tests/ui/option_as_ref_deref.stderr index b5dc6a7f3318..eb0661c523a9 100644 --- a/tests/ui/option_as_ref_deref.stderr +++ b/tests/ui/option_as_ref_deref.stderr @@ -5,6 +5,7 @@ LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.clone().as_deref()` | = note: `-D clippy::option-as-ref-deref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::option_as_ref_deref)]` error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead --> $DIR/option_as_ref_deref.rs:14:13 diff --git a/tests/ui/option_env_unwrap.stderr b/tests/ui/option_env_unwrap.stderr index cfa9dd58a300..de31d0c7f095 100644 --- a/tests/ui/option_env_unwrap.stderr +++ b/tests/ui/option_env_unwrap.stderr @@ -6,6 +6,7 @@ LL | let _ = option_env!("PATH").unwrap(); | = help: consider using the `env!` macro instead = note: `-D clippy::option-env-unwrap` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::option_env_unwrap)]` error: this will panic at run-time if the environment variable doesn't exist at compile-time --> $DIR/option_env_unwrap.rs:11:13 diff --git a/tests/ui/option_filter_map.stderr b/tests/ui/option_filter_map.stderr index e7da7c292871..148f9d02f5e1 100644 --- a/tests/ui/option_filter_map.stderr +++ b/tests/ui/option_filter_map.stderr @@ -5,6 +5,7 @@ LL | let _ = Some(Some(1)).filter(Option::is_some).map(Option::unwrap); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` | = note: `-D clippy::option-filter-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::option_filter_map)]` error: `filter` for `Some` followed by `unwrap` --> $DIR/option_filter_map.rs:6:27 diff --git a/tests/ui/option_if_let_else.stderr b/tests/ui/option_if_let_else.stderr index aa2da2174003..6d7d02f8c255 100644 --- a/tests/ui/option_if_let_else.stderr +++ b/tests/ui/option_if_let_else.stderr @@ -9,6 +9,7 @@ LL | | } | |_____^ help: try: `string.map_or((false, "hello"), |x| (true, x))` | = note: `-D clippy::option-if-let-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::option_if_let_else)]` error: use Option::map_or instead of an if let/else --> $DIR/option_if_let_else.rs:30:13 diff --git a/tests/ui/option_map_or_none.stderr b/tests/ui/option_map_or_none.stderr index 76c464553436..fa150718f891 100644 --- a/tests/ui/option_map_or_none.stderr +++ b/tests/ui/option_map_or_none.stderr @@ -5,6 +5,7 @@ LL | let _: Option = opt.map_or(None, |x| Some(x + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `map` instead: `opt.map(|x| x + 1)` | = note: `-D clippy::option-map-or-none` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::option_map_or_none)]` error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead --> $DIR/option_map_or_none.rs:13:26 @@ -48,6 +49,7 @@ LL | let _: Option = r.map_or(None, Some); | ^^^^^^^^^^^^^^^^^^^^ help: try using `ok` instead: `r.ok()` | = note: `-D clippy::result-map-or-into-option` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::result_map_or_into_option)]` error: aborting due to 5 previous errors diff --git a/tests/ui/option_map_unit_fn_fixable.stderr b/tests/ui/option_map_unit_fn_fixable.stderr index 38bcb5967f69..34aca31e95c9 100644 --- a/tests/ui/option_map_unit_fn_fixable.stderr +++ b/tests/ui/option_map_unit_fn_fixable.stderr @@ -7,6 +7,7 @@ LL | x.field.map(do_nothing); | help: try: `if let Some(x_field) = x.field { do_nothing(x_field) }` | = note: `-D clippy::option-map-unit-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::option_map_unit_fn)]` error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()` --> $DIR/option_map_unit_fn_fixable.rs:39:5 diff --git a/tests/ui/or_fun_call.stderr b/tests/ui/or_fun_call.stderr index 5a904c2f490e..afa4b7628112 100644 --- a/tests/ui/or_fun_call.stderr +++ b/tests/ui/or_fun_call.stderr @@ -5,6 +5,7 @@ LL | with_constructor.unwrap_or(make()); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(make)` | = note: `-D clippy::or-fun-call` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::or_fun_call)]` error: use of `unwrap_or` to construct default value --> $DIR/or_fun_call.rs:55:14 @@ -13,6 +14,7 @@ LL | with_new.unwrap_or(Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` | = note: `-D clippy::unwrap-or-default` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unwrap_or_default)]` error: use of `unwrap_or` followed by a function call --> $DIR/or_fun_call.rs:58:21 diff --git a/tests/ui/or_then_unwrap.stderr b/tests/ui/or_then_unwrap.stderr index 4b47f538a6c4..99e4488c040d 100644 --- a/tests/ui/or_then_unwrap.stderr +++ b/tests/ui/or_then_unwrap.stderr @@ -5,6 +5,7 @@ LL | let _ = option.or(Some("fallback")).unwrap(); // should trigger lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or("fallback")` | = note: `-D clippy::or-then-unwrap` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::or_then_unwrap)]` error: found `.or(Ok(…)).unwrap()` --> $DIR/or_then_unwrap.rs:25:20 diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.stderr b/tests/ui/out_of_bounds_indexing/issue-3102.stderr index b50b76bd9b2e..37db11caab8a 100644 --- a/tests/ui/out_of_bounds_indexing/issue-3102.stderr +++ b/tests/ui/out_of_bounds_indexing/issue-3102.stderr @@ -5,6 +5,7 @@ LL | &x[num..10]; | ^^ | = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]` error: range is out of bounds --> $DIR/issue-3102.rs:12:8 diff --git a/tests/ui/out_of_bounds_indexing/simple.stderr b/tests/ui/out_of_bounds_indexing/simple.stderr index ea5e83e87e08..ddef38beb315 100644 --- a/tests/ui/out_of_bounds_indexing/simple.stderr +++ b/tests/ui/out_of_bounds_indexing/simple.stderr @@ -5,6 +5,7 @@ LL | &x[..=4]; | ^ | = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]` error: range is out of bounds --> $DIR/simple.rs:10:11 diff --git a/tests/ui/overflow_check_conditional.stderr b/tests/ui/overflow_check_conditional.stderr index b1e9f1eee54f..b3cab8a21098 100644 --- a/tests/ui/overflow_check_conditional.stderr +++ b/tests/ui/overflow_check_conditional.stderr @@ -5,6 +5,7 @@ LL | if a + b < a {} | ^^^^^^^^^ | = note: `-D clippy::overflow-check-conditional` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::overflow_check_conditional)]` error: you are trying to use classic C overflow conditions that will fail in Rust --> $DIR/overflow_check_conditional.rs:8:8 diff --git a/tests/ui/overly_complex_bool_expr.stderr b/tests/ui/overly_complex_bool_expr.stderr index d296b88224d8..dc62d0e1dbd2 100644 --- a/tests/ui/overly_complex_bool_expr.stderr +++ b/tests/ui/overly_complex_bool_expr.stderr @@ -10,6 +10,7 @@ help: this expression can be optimized out by applying boolean operations to the LL | let _ = a && b || a; | ^ = note: `-D clippy::overly-complex-bool-expr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::overly_complex_bool_expr)]` error: this boolean expression contains a logic bug --> $DIR/overly_complex_bool_expr.rs:14:13 diff --git a/tests/ui/panic_in_result_fn.stderr b/tests/ui/panic_in_result_fn.stderr index 9040018f1d4c..d55c5cf36f62 100644 --- a/tests/ui/panic_in_result_fn.stderr +++ b/tests/ui/panic_in_result_fn.stderr @@ -15,6 +15,7 @@ note: return Err() instead of panicking LL | panic!("error"); | ^^^^^^^^^^^^^^^ = note: `-D clippy::panic-in-result-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::panic_in_result_fn)]` error: used `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn.rs:53:1 diff --git a/tests/ui/panic_in_result_fn_assertions.stderr b/tests/ui/panic_in_result_fn_assertions.stderr index 368a9970af85..a80e6f27abcb 100644 --- a/tests/ui/panic_in_result_fn_assertions.stderr +++ b/tests/ui/panic_in_result_fn_assertions.stderr @@ -16,6 +16,7 @@ note: return Err() instead of panicking LL | assert!(x == 5, "wrong argument"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::panic-in-result-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::panic_in_result_fn)]` error: used `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn_assertions.rs:14:5 diff --git a/tests/ui/panicking_macros.stderr b/tests/ui/panicking_macros.stderr index b47220d2cdc3..59ce57d0b3da 100644 --- a/tests/ui/panicking_macros.stderr +++ b/tests/ui/panicking_macros.stderr @@ -5,6 +5,7 @@ LL | panic!(); | ^^^^^^^^ | = note: `-D clippy::panic` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::panic)]` error: `panic` should not be present in production code --> $DIR/panicking_macros.rs:26:5 @@ -25,6 +26,7 @@ LL | todo!(); | ^^^^^^^ | = note: `-D clippy::todo` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::todo)]` error: `todo` should not be present in production code --> $DIR/panicking_macros.rs:38:5 @@ -45,6 +47,7 @@ LL | unimplemented!(); | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::unimplemented` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unimplemented)]` error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:50:5 @@ -65,6 +68,7 @@ LL | unreachable!(); | ^^^^^^^^^^^^^^ | = note: `-D clippy::unreachable` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unreachable)]` error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:62:5 diff --git a/tests/ui/partial_pub_fields.stderr b/tests/ui/partial_pub_fields.stderr index 95960201769e..a152287403b7 100644 --- a/tests/ui/partial_pub_fields.stderr +++ b/tests/ui/partial_pub_fields.stderr @@ -6,6 +6,7 @@ LL | pub paths: HashMap, | = help: consider using private field here = note: `-D clippy::partial-pub-fields` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::partial_pub_fields)]` error: mixed usage of pub and non-pub fields --> $DIR/partial_pub_fields.rs:17:9 diff --git a/tests/ui/partialeq_ne_impl.stderr b/tests/ui/partialeq_ne_impl.stderr index 04b29dd8764a..163d6b1dd7b6 100644 --- a/tests/ui/partialeq_ne_impl.stderr +++ b/tests/ui/partialeq_ne_impl.stderr @@ -9,6 +9,7 @@ LL | | } | |_____^ | = note: `-D clippy::partialeq-ne-impl` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::partialeq_ne_impl)]` error: aborting due to previous error diff --git a/tests/ui/partialeq_to_none.stderr b/tests/ui/partialeq_to_none.stderr index d06ab7aee558..50ce15001f40 100644 --- a/tests/ui/partialeq_to_none.stderr +++ b/tests/ui/partialeq_to_none.stderr @@ -5,6 +5,7 @@ LL | if f != None { "yay" } else { "nay" } | ^^^^^^^^^ help: use `Option::is_some()` instead: `f.is_some()` | = note: `-D clippy::partialeq-to-none` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::partialeq_to_none)]` error: binary comparison to literal `Option::None` --> $DIR/partialeq_to_none.rs:44:13 diff --git a/tests/ui/path_buf_push_overwrite.stderr b/tests/ui/path_buf_push_overwrite.stderr index c94b32178049..1453d020c412 100644 --- a/tests/ui/path_buf_push_overwrite.stderr +++ b/tests/ui/path_buf_push_overwrite.stderr @@ -5,6 +5,7 @@ LL | x.push("/bar"); | ^^^^^^ help: try: `"bar"` | = note: `-D clippy::path-buf-push-overwrite` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::path_buf_push_overwrite)]` error: aborting due to previous error diff --git a/tests/ui/pattern_type_mismatch/mutability.stderr b/tests/ui/pattern_type_mismatch/mutability.stderr index b512f5e1ee25..f21e1894af2a 100644 --- a/tests/ui/pattern_type_mismatch/mutability.stderr +++ b/tests/ui/pattern_type_mismatch/mutability.stderr @@ -6,6 +6,7 @@ LL | Some(_) => (), | = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type --> $DIR/mutability.rs:16:9 diff --git a/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr b/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr index 8e0d13bc8bdb..b72c24840d7d 100644 --- a/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr @@ -6,6 +6,7 @@ LL | if let Value::B | Value::A(_) = ref_value {} | = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type --> $DIR/pattern_alternatives.rs:17:34 diff --git a/tests/ui/pattern_type_mismatch/pattern_structs.stderr b/tests/ui/pattern_type_mismatch/pattern_structs.stderr index a0c7a67b521e..c46c7de6dd65 100644 --- a/tests/ui/pattern_type_mismatch/pattern_structs.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_structs.stderr @@ -6,6 +6,7 @@ LL | let Struct { .. } = ref_value; | = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type --> $DIR/pattern_structs.rs:15:33 diff --git a/tests/ui/pattern_type_mismatch/pattern_tuples.stderr b/tests/ui/pattern_type_mismatch/pattern_tuples.stderr index 1001f4f63c68..b365731d5619 100644 --- a/tests/ui/pattern_type_mismatch/pattern_tuples.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_tuples.stderr @@ -6,6 +6,7 @@ LL | let TupleStruct(_) = ref_value; | = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type --> $DIR/pattern_tuples.rs:13:25 diff --git a/tests/ui/pattern_type_mismatch/syntax.stderr b/tests/ui/pattern_type_mismatch/syntax.stderr index 36869598815d..dfe4639c7746 100644 --- a/tests/ui/pattern_type_mismatch/syntax.stderr +++ b/tests/ui/pattern_type_mismatch/syntax.stderr @@ -6,6 +6,7 @@ LL | Some(_) => (), | = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type --> $DIR/syntax.rs:31:12 diff --git a/tests/ui/patterns.stderr b/tests/ui/patterns.stderr index e2431cb30097..2f608bbc18fa 100644 --- a/tests/ui/patterns.stderr +++ b/tests/ui/patterns.stderr @@ -5,6 +5,7 @@ LL | y @ _ => (), | ^^^^^ help: try: `y` | = note: `-D clippy::redundant-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern)]` error: the `x @ _` pattern can be written as just `x` --> $DIR/patterns.rs:29:9 diff --git a/tests/ui/permissions_set_readonly_false.stderr b/tests/ui/permissions_set_readonly_false.stderr index e7a8ee6cb19b..58a7de84d8f0 100644 --- a/tests/ui/permissions_set_readonly_false.stderr +++ b/tests/ui/permissions_set_readonly_false.stderr @@ -8,6 +8,7 @@ LL | permissions.set_readonly(false); = help: you can set the desired permissions using `PermissionsExt`. For more information, see https://doc.rust-lang.org/std/os/unix/fs/trait.PermissionsExt.html = note: `-D clippy::permissions-set-readonly-false` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::permissions_set_readonly_false)]` error: aborting due to previous error diff --git a/tests/ui/precedence.stderr b/tests/ui/precedence.stderr index 30f4607ad17a..bd0cbccc787c 100644 --- a/tests/ui/precedence.stderr +++ b/tests/ui/precedence.stderr @@ -5,6 +5,7 @@ LL | 1 << 2 + 3; | ^^^^^^^^^^ help: consider parenthesizing your expression: `1 << (2 + 3)` | = note: `-D clippy::precedence` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::precedence)]` error: operator precedence can trip the unwary --> $DIR/precedence.rs:17:5 diff --git a/tests/ui/print.stderr b/tests/ui/print.stderr index e9d88df33f59..bb8d945081e1 100644 --- a/tests/ui/print.stderr +++ b/tests/ui/print.stderr @@ -5,6 +5,7 @@ LL | write!(f, "{:?}", 43.1415) | ^^^^ | = note: `-D clippy::use-debug` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::use_debug)]` error: use of `println!` --> $DIR/print.rs:25:5 @@ -13,6 +14,7 @@ LL | println!("Hello"); | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::print-stdout` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_stdout)]` error: use of `print!` --> $DIR/print.rs:28:5 diff --git a/tests/ui/print_in_format_impl.stderr b/tests/ui/print_in_format_impl.stderr index 7a7a2dc1c2a7..57f06dc1143f 100644 --- a/tests/ui/print_in_format_impl.stderr +++ b/tests/ui/print_in_format_impl.stderr @@ -5,6 +5,7 @@ LL | print!("{}", 1); | ^^^^^^^^^^^^^^^ help: replace with: `write!(f, ..)` | = note: `-D clippy::print-in-format-impl` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_in_format_impl)]` error: use of `println!` in `Debug` impl --> $DIR/print_in_format_impl.rs:23:9 diff --git a/tests/ui/print_literal.stderr b/tests/ui/print_literal.stderr index d7a2fa7f4bb4..1d9751b92e9c 100644 --- a/tests/ui/print_literal.stderr +++ b/tests/ui/print_literal.stderr @@ -5,6 +5,7 @@ LL | print!("Hello {}", "world"); | ^^^^^^^ | = note: `-D clippy::print-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_literal)]` help: try | LL - print!("Hello {}", "world"); diff --git a/tests/ui/print_stderr.stderr b/tests/ui/print_stderr.stderr index 0a56fbcec999..7de16331067e 100644 --- a/tests/ui/print_stderr.stderr +++ b/tests/ui/print_stderr.stderr @@ -5,6 +5,7 @@ LL | eprintln!("Hello"); | ^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::print-stderr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_stderr)]` error: use of `eprint!` --> $DIR/print_stderr.rs:8:5 diff --git a/tests/ui/print_with_newline.stderr b/tests/ui/print_with_newline.stderr index 1c5f2548c89b..7ff6a5f060d0 100644 --- a/tests/ui/print_with_newline.stderr +++ b/tests/ui/print_with_newline.stderr @@ -5,6 +5,7 @@ LL | print!("Hello\n"); | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::print-with-newline` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_with_newline)]` help: use `println!` instead | LL - print!("Hello\n"); diff --git a/tests/ui/println_empty_string.stderr b/tests/ui/println_empty_string.stderr index eb740abc6b01..c89e64f665a7 100644 --- a/tests/ui/println_empty_string.stderr +++ b/tests/ui/println_empty_string.stderr @@ -7,6 +7,7 @@ LL | println!(""); | help: remove the empty string | = note: `-D clippy::println-empty-string` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::println_empty_string)]` error: empty string literal in `println!` --> $DIR/println_empty_string.rs:8:14 diff --git a/tests/ui/ptr_arg.stderr b/tests/ui/ptr_arg.stderr index e5708ce3a7e2..cccf2d62d631 100644 --- a/tests/ui/ptr_arg.stderr +++ b/tests/ui/ptr_arg.stderr @@ -5,6 +5,7 @@ LL | fn do_vec(x: &Vec) { | ^^^^^^^^^ help: change this to: `&[i64]` | = note: `-D clippy::ptr-arg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ptr_arg)]` error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do --> $DIR/ptr_arg.rs:20:18 diff --git a/tests/ui/ptr_as_ptr.stderr b/tests/ui/ptr_as_ptr.stderr index 9bd8f9b17d4d..c0ce69b4357d 100644 --- a/tests/ui/ptr_as_ptr.stderr +++ b/tests/ui/ptr_as_ptr.stderr @@ -5,6 +5,7 @@ LL | *unsafe { Box::from_raw(Box::into_raw(Box::new(o)) as *mut super::i | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `Box::into_raw(Box::new(o)).cast::>()` | = note: `-D clippy::ptr-as-ptr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ptr_as_ptr)]` error: `as` casting between raw pointers without changing its mutability --> $DIR/ptr_as_ptr.rs:27:13 diff --git a/tests/ui/ptr_cast_constness.stderr b/tests/ui/ptr_cast_constness.stderr index 76a5c7e01658..a4bf778ad19d 100644 --- a/tests/ui/ptr_cast_constness.stderr +++ b/tests/ui/ptr_cast_constness.stderr @@ -5,6 +5,7 @@ LL | let _: &mut T = std::mem::transmute(p as *mut T); | ^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `p.cast_mut()` | = note: `-D clippy::ptr-cast-constness` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ptr_cast_constness)]` error: `as` casting between raw pointers while changing only its constness --> $DIR/ptr_cast_constness.rs:11:19 diff --git a/tests/ui/ptr_eq.stderr b/tests/ui/ptr_eq.stderr index 3cdc30f970a2..2a384accac57 100644 --- a/tests/ui/ptr_eq.stderr +++ b/tests/ui/ptr_eq.stderr @@ -5,6 +5,7 @@ LL | let _ = a as *const _ as usize == b as *const _ as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(a, b)` | = note: `-D clippy::ptr-eq` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ptr_eq)]` error: use `std::ptr::eq` when comparing raw pointers --> $DIR/ptr_eq.rs:20:13 diff --git a/tests/ui/ptr_offset_with_cast.stderr b/tests/ui/ptr_offset_with_cast.stderr index fd45224ca067..e99053846795 100644 --- a/tests/ui/ptr_offset_with_cast.stderr +++ b/tests/ui/ptr_offset_with_cast.stderr @@ -5,6 +5,7 @@ LL | let _ = ptr.offset(offset_usize as isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.add(offset_usize)` | = note: `-D clippy::ptr-offset-with-cast` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ptr_offset_with_cast)]` error: use of `wrapping_offset` with a `usize` casted to an `isize` --> $DIR/ptr_offset_with_cast.rs:16:17 diff --git a/tests/ui/pub_use.stderr b/tests/ui/pub_use.stderr index ba4ee732c05c..781572736645 100644 --- a/tests/ui/pub_use.stderr +++ b/tests/ui/pub_use.stderr @@ -6,6 +6,7 @@ LL | pub use inner::Test; | = help: move the exported item to a public module instead = note: `-D clippy::pub-use` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::pub_use)]` error: aborting due to previous error diff --git a/tests/ui/pub_with_shorthand.stderr b/tests/ui/pub_with_shorthand.stderr index 323b5a23b247..423b0508092f 100644 --- a/tests/ui/pub_with_shorthand.stderr +++ b/tests/ui/pub_with_shorthand.stderr @@ -5,6 +5,7 @@ LL | pub(self) fn a() {} | ^^^^^^^^^ help: add it: `pub(in self)` | = note: `-D clippy::pub-with-shorthand` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::pub_with_shorthand)]` error: usage of `pub` without `in` --> $DIR/pub_with_shorthand.rs:19:5 diff --git a/tests/ui/pub_without_shorthand.stderr b/tests/ui/pub_without_shorthand.stderr index a18c9bf89344..4fb11cb3d4ad 100644 --- a/tests/ui/pub_without_shorthand.stderr +++ b/tests/ui/pub_without_shorthand.stderr @@ -5,6 +5,7 @@ LL | pub(in self) fn b() {} | ^^^^^^^^^^^^ help: remove it: `pub(self)` | = note: `-D clippy::pub-without-shorthand` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::pub_without_shorthand)]` error: usage of `pub` with `in` --> $DIR/pub_without_shorthand.rs:18:5 diff --git a/tests/ui/question_mark.stderr b/tests/ui/question_mark.stderr index 5dc62fadd8d6..7b7b85d08e63 100644 --- a/tests/ui/question_mark.stderr +++ b/tests/ui/question_mark.stderr @@ -7,6 +7,7 @@ LL | | } | |_____^ help: replace it with: `a?;` | = note: `-D clippy::question-mark` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::question_mark)]` error: this block may be rewritten with the `?` operator --> $DIR/question_mark.rs:52:9 diff --git a/tests/ui/question_mark_used.stderr b/tests/ui/question_mark_used.stderr index 8b5fcbcdbfd6..a3f440de80a5 100644 --- a/tests/ui/question_mark_used.stderr +++ b/tests/ui/question_mark_used.stderr @@ -6,6 +6,7 @@ LL | other_function()?; | = help: consider using a custom macro or match expression = note: `-D clippy::question-mark-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::question_mark_used)]` error: aborting due to previous error diff --git a/tests/ui/range.stderr b/tests/ui/range.stderr index ac83b67fde3a..9f174307b829 100644 --- a/tests/ui/range.stderr +++ b/tests/ui/range.stderr @@ -5,6 +5,7 @@ LL | let _x = v1.iter().zip(0..v1.len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::range-zip-with-len` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::range_zip_with_len)]` error: aborting due to previous error diff --git a/tests/ui/range_contains.stderr b/tests/ui/range_contains.stderr index ea34023a4664..349adea2193c 100644 --- a/tests/ui/range_contains.stderr +++ b/tests/ui/range_contains.stderr @@ -5,6 +5,7 @@ LL | x >= 8 && x < 12; | ^^^^^^^^^^^^^^^^ help: use: `(8..12).contains(&x)` | = note: `-D clippy::manual-range-contains` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_range_contains)]` error: manual `Range::contains` implementation --> $DIR/range_contains.rs:14:5 diff --git a/tests/ui/range_plus_minus_one.stderr b/tests/ui/range_plus_minus_one.stderr index f92826fb7536..c5c9b145db85 100644 --- a/tests/ui/range_plus_minus_one.stderr +++ b/tests/ui/range_plus_minus_one.stderr @@ -5,6 +5,7 @@ LL | for _ in 0..3 + 1 {} | ^^^^^^^^ help: use: `0..=3` | = note: `-D clippy::range-plus-one` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::range_plus_one)]` error: an inclusive range would be more readable --> $DIR/range_plus_minus_one.rs:32:14 @@ -31,6 +32,7 @@ LL | let _ = ..=11 - 1; | ^^^^^^^^^ help: use: `..11` | = note: `-D clippy::range-minus-one` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::range_minus_one)]` error: an exclusive range would be more readable --> $DIR/range_plus_minus_one.rs:46:13 diff --git a/tests/ui/rc_buffer.stderr b/tests/ui/rc_buffer.stderr index d78e39a010d8..04080326ae0f 100644 --- a/tests/ui/rc_buffer.stderr +++ b/tests/ui/rc_buffer.stderr @@ -5,6 +5,7 @@ LL | bad1: Rc, | ^^^^^^^^^^ help: try: `Rc` | = note: `-D clippy::rc-buffer` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::rc_buffer)]` error: usage of `Rc` when T is a buffer type --> $DIR/rc_buffer.rs:12:11 diff --git a/tests/ui/rc_buffer_arc.stderr b/tests/ui/rc_buffer_arc.stderr index 70d4381151af..52522dd725f4 100644 --- a/tests/ui/rc_buffer_arc.stderr +++ b/tests/ui/rc_buffer_arc.stderr @@ -5,6 +5,7 @@ LL | bad1: Arc, | ^^^^^^^^^^^ help: try: `Arc` | = note: `-D clippy::rc-buffer` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::rc_buffer)]` error: usage of `Arc` when T is a buffer type --> $DIR/rc_buffer_arc.rs:11:11 diff --git a/tests/ui/rc_clone_in_vec_init/arc.stderr b/tests/ui/rc_clone_in_vec_init/arc.stderr index 87f7ed56cd3c..5dc4b5a10e52 100644 --- a/tests/ui/rc_clone_in_vec_init/arc.stderr +++ b/tests/ui/rc_clone_in_vec_init/arc.stderr @@ -6,6 +6,7 @@ LL | let v = vec![Arc::new("x".to_string()); 2]; | = note: each element will point to the same `Arc` instance = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::rc_clone_in_vec_init)]` help: consider initializing each `Arc` element individually | LL ~ let v = { diff --git a/tests/ui/rc_clone_in_vec_init/rc.stderr b/tests/ui/rc_clone_in_vec_init/rc.stderr index 3fa187f0b813..e6bc6f68b3e4 100644 --- a/tests/ui/rc_clone_in_vec_init/rc.stderr +++ b/tests/ui/rc_clone_in_vec_init/rc.stderr @@ -6,6 +6,7 @@ LL | let v = vec![Rc::new("x".to_string()); 2]; | = note: each element will point to the same `Rc` instance = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::rc_clone_in_vec_init)]` help: consider initializing each `Rc` element individually | LL ~ let v = { diff --git a/tests/ui/rc_clone_in_vec_init/weak.stderr b/tests/ui/rc_clone_in_vec_init/weak.stderr index 9b60c22c2810..25d7dae72da3 100644 --- a/tests/ui/rc_clone_in_vec_init/weak.stderr +++ b/tests/ui/rc_clone_in_vec_init/weak.stderr @@ -6,6 +6,7 @@ LL | let v = vec![SyncWeak::::new(); 2]; | = note: each element will point to the same `Weak` instance = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::rc_clone_in_vec_init)]` help: consider initializing each `Weak` element individually | LL ~ let v = { diff --git a/tests/ui/rc_mutex.stderr b/tests/ui/rc_mutex.stderr index e21337b0f2ed..50922fb67e49 100644 --- a/tests/ui/rc_mutex.stderr +++ b/tests/ui/rc_mutex.stderr @@ -6,6 +6,7 @@ LL | foo: Rc>, | = help: consider using `Rc>` or `Arc>` instead = note: `-D clippy::rc-mutex` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::rc_mutex)]` error: usage of `Rc>` --> $DIR/rc_mutex.rs:27:18 diff --git a/tests/ui/read_line_without_trim.stderr b/tests/ui/read_line_without_trim.stderr index a7751eb68d83..8d46e0f79078 100644 --- a/tests/ui/read_line_without_trim.stderr +++ b/tests/ui/read_line_without_trim.stderr @@ -12,6 +12,7 @@ note: call to `.read_line()` here, which leaves a trailing newline character in LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::read-line-without-trim` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::read_line_without_trim)]` error: calling `.parse()` without trimming the trailing newline character --> $DIR/read_line_without_trim.rs:16:20 diff --git a/tests/ui/read_zero_byte_vec.stderr b/tests/ui/read_zero_byte_vec.stderr index b80a614eceba..523ecb2948df 100644 --- a/tests/ui/read_zero_byte_vec.stderr +++ b/tests/ui/read_zero_byte_vec.stderr @@ -5,6 +5,7 @@ LL | f.read_exact(&mut data).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `data.resize(20, 0); f.read_exact(&mut data).unwrap();` | = note: `-D clippy::read-zero-byte-vec` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::read_zero_byte_vec)]` error: reading zero byte data to `Vec` --> $DIR/read_zero_byte_vec.rs:27:5 diff --git a/tests/ui/readonly_write_lock.stderr b/tests/ui/readonly_write_lock.stderr index ca754e5c8f29..b4a093ce9c93 100644 --- a/tests/ui/readonly_write_lock.stderr +++ b/tests/ui/readonly_write_lock.stderr @@ -5,6 +5,7 @@ LL | let writer = lock.write().unwrap(); | ^^^^^^^^^^^^ help: consider using a read lock instead: `lock.read()` | = note: `-D clippy::readonly-write-lock` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::readonly_write_lock)]` error: this write lock is used only for reading --> $DIR/readonly_write_lock.rs:23:22 diff --git a/tests/ui/recursive_format_impl.stderr b/tests/ui/recursive_format_impl.stderr index c80e90ba61bc..adb16f44a999 100644 --- a/tests/ui/recursive_format_impl.stderr +++ b/tests/ui/recursive_format_impl.stderr @@ -5,6 +5,7 @@ LL | write!(f, "{}", self.to_string()) | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::recursive-format-impl` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::recursive_format_impl)]` error: using `self` as `Display` in `impl Display` will cause infinite recursion --> $DIR/recursive_format_impl.rs:77:9 diff --git a/tests/ui/redundant_allocation.stderr b/tests/ui/redundant_allocation.stderr index 233e3eb42896..d72f6b202ec2 100644 --- a/tests/ui/redundant_allocation.stderr +++ b/tests/ui/redundant_allocation.stderr @@ -7,6 +7,7 @@ LL | pub fn box_test6(foo: Box>) {} = note: `Rc` is already on the heap, `Box>` makes an extra allocation = help: consider using just `Box` or `Rc` = note: `-D clippy::redundant-allocation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_allocation)]` error: usage of `Box>` --> $DIR/redundant_allocation.rs:20:30 diff --git a/tests/ui/redundant_allocation_fixable.stderr b/tests/ui/redundant_allocation_fixable.stderr index 2e6e078b24b0..603600f30227 100644 --- a/tests/ui/redundant_allocation_fixable.stderr +++ b/tests/ui/redundant_allocation_fixable.stderr @@ -6,6 +6,7 @@ LL | pub fn box_test1(foo: Box<&T>) {} | = note: `&T` is already a pointer, `Box<&T>` allocates a pointer on the heap = note: `-D clippy::redundant-allocation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_allocation)]` error: usage of `Box<&MyStruct>` --> $DIR/redundant_allocation_fixable.rs:25:27 diff --git a/tests/ui/redundant_async_block.stderr b/tests/ui/redundant_async_block.stderr index 0ebd4d2cece7..adb44d7a62ef 100644 --- a/tests/ui/redundant_async_block.stderr +++ b/tests/ui/redundant_async_block.stderr @@ -5,6 +5,7 @@ LL | let x = async { f.await }; | ^^^^^^^^^^^^^^^^^ help: you can reduce it to: `f` | = note: `-D clippy::redundant-async-block` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_async_block)]` error: this async expression only awaits a single future --> $DIR/redundant_async_block.rs:20:16 diff --git a/tests/ui/redundant_at_rest_pattern.stderr b/tests/ui/redundant_at_rest_pattern.stderr index 008db304daf9..3a44636fc78e 100644 --- a/tests/ui/redundant_at_rest_pattern.stderr +++ b/tests/ui/redundant_at_rest_pattern.stderr @@ -5,6 +5,7 @@ LL | if let [a @ ..] = [()] {} | ^^^^^^^^ help: this is better represented with just the binding: `a` | = note: `-D clippy::redundant-at-rest-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_at_rest_pattern)]` error: using a rest pattern to bind an entire slice to a local --> $DIR/redundant_at_rest_pattern.rs:10:12 diff --git a/tests/ui/redundant_clone.stderr b/tests/ui/redundant_clone.stderr index a1c09d2b3c79..4115fcf21228 100644 --- a/tests/ui/redundant_clone.stderr +++ b/tests/ui/redundant_clone.stderr @@ -10,6 +10,7 @@ note: this value is dropped without further use LL | let _s = ["lorem", "ipsum"].join(" ").to_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::redundant-clone` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]` error: redundant clone --> $DIR/redundant_clone.rs:18:15 diff --git a/tests/ui/redundant_closure_call_early.stderr b/tests/ui/redundant_closure_call_early.stderr index 4a2ce175b5ce..be7a981dc27b 100644 --- a/tests/ui/redundant_closure_call_early.stderr +++ b/tests/ui/redundant_closure_call_early.stderr @@ -5,6 +5,7 @@ LL | let mut k = (|m| m + 1)(i); | ^^^^^^^^^^^^^^ | = note: `-D clippy::redundant-closure-call` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_call)]` error: try not to call a closure in the expression where it is declared --> $DIR/redundant_closure_call_early.rs:14:9 diff --git a/tests/ui/redundant_closure_call_fixable.stderr b/tests/ui/redundant_closure_call_fixable.stderr index a285420ea8f7..a7cdb43693fc 100644 --- a/tests/ui/redundant_closure_call_fixable.stderr +++ b/tests/ui/redundant_closure_call_fixable.stderr @@ -5,6 +5,7 @@ LL | let a = (|| 42)(); | ^^^^^^^^^ help: try doing something like: `42` | = note: `-D clippy::redundant-closure-call` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_call)]` error: try not to call a closure in the expression where it is declared --> $DIR/redundant_closure_call_fixable.rs:17:13 diff --git a/tests/ui/redundant_closure_call_late.stderr b/tests/ui/redundant_closure_call_late.stderr index 4a0fe95d5734..a89bfc7703de 100644 --- a/tests/ui/redundant_closure_call_late.stderr +++ b/tests/ui/redundant_closure_call_late.stderr @@ -5,6 +5,7 @@ LL | i = redun_closure(); | ^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::redundant-closure-call` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_call)]` error: closure called just once immediately after it was declared --> $DIR/redundant_closure_call_late.rs:22:5 diff --git a/tests/ui/redundant_else.stderr b/tests/ui/redundant_else.stderr index d6759422e953..af33e05a608f 100644 --- a/tests/ui/redundant_else.stderr +++ b/tests/ui/redundant_else.stderr @@ -10,6 +10,7 @@ LL | | } | = help: remove the `else` block and move the contents out = note: `-D clippy::redundant-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_else)]` error: redundant else block --> $DIR/redundant_else.rs:18:16 diff --git a/tests/ui/redundant_field_names.stderr b/tests/ui/redundant_field_names.stderr index 8bcf33007db6..5fee60b8ea41 100644 --- a/tests/ui/redundant_field_names.stderr +++ b/tests/ui/redundant_field_names.stderr @@ -5,6 +5,7 @@ LL | gender: gender, | ^^^^^^^^^^^^^^ help: replace it with: `gender` | = note: `-D clippy::redundant-field-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_field_names)]` error: redundant field names in struct initialization --> $DIR/redundant_field_names.rs:34:9 diff --git a/tests/ui/redundant_guards.stderr b/tests/ui/redundant_guards.stderr index 500772343826..0a45a6d7619f 100644 --- a/tests/ui/redundant_guards.stderr +++ b/tests/ui/redundant_guards.stderr @@ -5,6 +5,7 @@ LL | C(x, y) if let 1 = y => .., | ^^^^^^^^^ | = note: `-D clippy::redundant-guards` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_guards)]` help: try | LL - C(x, y) if let 1 = y => .., diff --git a/tests/ui/redundant_locals.stderr b/tests/ui/redundant_locals.stderr index 587de0575247..13b872e9576d 100644 --- a/tests/ui/redundant_locals.stderr +++ b/tests/ui/redundant_locals.stderr @@ -8,6 +8,7 @@ LL | let x = x; | = help: remove the redefinition of `x` = note: `-D clippy::redundant-locals` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_locals)]` error: redundant redefinition of a binding --> $DIR/redundant_locals.rs:16:9 diff --git a/tests/ui/redundant_pattern_matching_drop_order.stderr b/tests/ui/redundant_pattern_matching_drop_order.stderr index 636d1a292aca..28f0244b9e87 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.stderr +++ b/tests/ui/redundant_pattern_matching_drop_order.stderr @@ -7,6 +7,7 @@ LL | if let Ok(_) = m.lock() {} = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_err()` --> $DIR/redundant_pattern_matching_drop_order.rs:16:12 diff --git a/tests/ui/redundant_pattern_matching_ipaddr.stderr b/tests/ui/redundant_pattern_matching_ipaddr.stderr index f5f5d268a621..d36129a2bee9 100644 --- a/tests/ui/redundant_pattern_matching_ipaddr.stderr +++ b/tests/ui/redundant_pattern_matching_ipaddr.stderr @@ -5,6 +5,7 @@ LL | if let V4(_) = &ipaddr {} | -------^^^^^---------- help: try: `if ipaddr.is_ipv4()` | = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_ipv4()` --> $DIR/redundant_pattern_matching_ipaddr.rs:17:12 diff --git a/tests/ui/redundant_pattern_matching_option.stderr b/tests/ui/redundant_pattern_matching_option.stderr index 73b0353ce34f..fdf395d82862 100644 --- a/tests/ui/redundant_pattern_matching_option.stderr +++ b/tests/ui/redundant_pattern_matching_option.stderr @@ -5,6 +5,7 @@ LL | matches!(maybe_some, None if !boolean) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `maybe_some.is_none() && (!boolean)` | = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_none()` --> $DIR/redundant_pattern_matching_option.rs:18:13 diff --git a/tests/ui/redundant_pattern_matching_poll.stderr b/tests/ui/redundant_pattern_matching_poll.stderr index 6c4603bcf3d8..c010c3c44375 100644 --- a/tests/ui/redundant_pattern_matching_poll.stderr +++ b/tests/ui/redundant_pattern_matching_poll.stderr @@ -5,6 +5,7 @@ LL | if let Pending = Pending::<()> {} | -------^^^^^^^---------------- help: try: `if Pending::<()>.is_pending()` | = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_ready()` --> $DIR/redundant_pattern_matching_poll.rs:17:12 diff --git a/tests/ui/redundant_pattern_matching_result.stderr b/tests/ui/redundant_pattern_matching_result.stderr index 4467e8e81073..19e7f82298ea 100644 --- a/tests/ui/redundant_pattern_matching_result.stderr +++ b/tests/ui/redundant_pattern_matching_result.stderr @@ -5,6 +5,7 @@ LL | if let Ok(_) = &result {} | -------^^^^^---------- help: try: `if result.is_ok()` | = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_ok()` --> $DIR/redundant_pattern_matching_result.rs:17:12 diff --git a/tests/ui/redundant_pub_crate.stderr b/tests/ui/redundant_pub_crate.stderr index f8c7d7a9e69e..5d7744aa8649 100644 --- a/tests/ui/redundant_pub_crate.stderr +++ b/tests/ui/redundant_pub_crate.stderr @@ -7,6 +7,7 @@ LL | pub(crate) fn g() {} // private due to m1 | help: consider using: `pub` | = note: `-D clippy::redundant-pub-crate` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pub_crate)]` error: pub(crate) function inside private module --> $DIR/redundant_pub_crate.rs:11:9 diff --git a/tests/ui/redundant_slicing.stderr b/tests/ui/redundant_slicing.stderr index e0db72765a8d..05287c882f7e 100644 --- a/tests/ui/redundant_slicing.stderr +++ b/tests/ui/redundant_slicing.stderr @@ -5,6 +5,7 @@ LL | let _ = &slice[..]; // Redundant slice | ^^^^^^^^^^ help: use the original value instead: `slice` | = note: `-D clippy::redundant-slicing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_slicing)]` error: redundant slicing of the whole range --> $DIR/redundant_slicing.rs:12:13 diff --git a/tests/ui/redundant_static_lifetimes.stderr b/tests/ui/redundant_static_lifetimes.stderr index 3e344fc67f92..26f50345351f 100644 --- a/tests/ui/redundant_static_lifetimes.stderr +++ b/tests/ui/redundant_static_lifetimes.stderr @@ -5,6 +5,7 @@ LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR: Consider removi | -^^^^^^^---- help: consider removing `'static`: `&str` | = note: `-D clippy::redundant-static-lifetimes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_static_lifetimes)]` error: constants have by default a `'static` lifetime --> $DIR/redundant_static_lifetimes.rs:10:21 diff --git a/tests/ui/redundant_static_lifetimes_multiple.stderr b/tests/ui/redundant_static_lifetimes_multiple.stderr index 297f505d9684..bf4d211200f3 100644 --- a/tests/ui/redundant_static_lifetimes_multiple.stderr +++ b/tests/ui/redundant_static_lifetimes_multiple.stderr @@ -5,6 +5,7 @@ LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; | -^^^^^^^------------------ help: consider removing `'static`: `&[&[&'static str]]` | = note: `-D clippy::redundant-static-lifetimes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_static_lifetimes)]` error: constants have by default a `'static` lifetime --> $DIR/redundant_static_lifetimes_multiple.rs:4:30 diff --git a/tests/ui/redundant_type_annotations.stderr b/tests/ui/redundant_type_annotations.stderr index 927761c74372..d1f26f1832e3 100644 --- a/tests/ui/redundant_type_annotations.stderr +++ b/tests/ui/redundant_type_annotations.stderr @@ -5,6 +5,7 @@ LL | let v: u32 = self.return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::redundant-type-annotations` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_type_annotations)]` error: redundant type annotation --> $DIR/redundant_type_annotations.rs:84:9 diff --git a/tests/ui/ref_binding_to_reference.stderr b/tests/ui/ref_binding_to_reference.stderr index 2505d7d500bf..6e8b43a3e52a 100644 --- a/tests/ui/ref_binding_to_reference.stderr +++ b/tests/ui/ref_binding_to_reference.stderr @@ -5,6 +5,7 @@ LL | Some(ref x) => x, | ^^^^^ | = note: `-D clippy::ref-binding-to-reference` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ref_binding_to_reference)]` help: try | LL | Some(x) => &x, diff --git a/tests/ui/ref_option_ref.stderr b/tests/ui/ref_option_ref.stderr index 430dd9c0e8dc..6a28a68dc2bb 100644 --- a/tests/ui/ref_option_ref.stderr +++ b/tests/ui/ref_option_ref.stderr @@ -5,6 +5,7 @@ LL | static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD); | ^^^^^^^^^^^^^ help: try: `Option<&i32>` | = note: `-D clippy::ref-option-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ref_option_ref)]` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` --> $DIR/ref_option_ref.rs:14:18 diff --git a/tests/ui/ref_patterns.stderr b/tests/ui/ref_patterns.stderr index 5883a7883e64..74892bac6e4f 100644 --- a/tests/ui/ref_patterns.stderr +++ b/tests/ui/ref_patterns.stderr @@ -6,6 +6,7 @@ LL | Some(ref opt) => {}, | = help: consider using `&` for clarity instead = note: `-D clippy::ref-patterns` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ref_patterns)]` error: usage of ref pattern --> $DIR/ref_patterns.rs:15:9 diff --git a/tests/ui/regex.stderr b/tests/ui/regex.stderr index ed5aa29e079e..91f90157e684 100644 --- a/tests/ui/regex.stderr +++ b/tests/ui/regex.stderr @@ -6,6 +6,7 @@ LL | let pipe_in_wrong_position = Regex::new("|"); | = help: the regex is unlikely to be useful as it is = note: `-D clippy::trivial-regex` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::trivial_regex)]` error: trivial regex --> $DIR/regex.rs:20:60 @@ -22,6 +23,7 @@ LL | let wrong_char_ranice = Regex::new("[z-a]"); | ^^^ | = note: `-D clippy::invalid-regex` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::invalid_regex)]` error: regex syntax error: invalid character class range, the start must be <= the end --> $DIR/regex.rs:25:37 diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 2b26af16bad5..d98fc7b30db5 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -5,6 +5,7 @@ LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` | = note: `-D renamed-and-removed-lints` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(renamed_and_removed_lints)]` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` --> $DIR/rename.rs:53:9 diff --git a/tests/ui/repeat_once.stderr b/tests/ui/repeat_once.stderr index ae5258d4c2fb..895729390785 100644 --- a/tests/ui/repeat_once.stderr +++ b/tests/ui/repeat_once.stderr @@ -5,6 +5,7 @@ LL | let a = [1; 5].repeat(1); | ^^^^^^^^^^^^^^^^ help: consider using `.to_vec()` instead: `[1; 5].to_vec()` | = note: `-D clippy::repeat-once` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::repeat_once)]` error: calling `repeat(1)` on slice --> $DIR/repeat_once.rs:10:13 diff --git a/tests/ui/repl_uninit.stderr b/tests/ui/repl_uninit.stderr index 6bbefcadb863..c82f29adb5ac 100644 --- a/tests/ui/repl_uninit.stderr +++ b/tests/ui/repl_uninit.stderr @@ -5,6 +5,7 @@ LL | let taken_v = mem::replace(&mut v, mem::uninitialized()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(&mut v)` | = note: `-D clippy::mem-replace-with-uninit` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_uninit)]` error: replacing with `mem::MaybeUninit::uninit().assume_init()` --> $DIR/repl_uninit.rs:23:23 diff --git a/tests/ui/reserve_after_initialization.stderr b/tests/ui/reserve_after_initialization.stderr index 4a6164d8ebc9..a91033890766 100644 --- a/tests/ui/reserve_after_initialization.stderr +++ b/tests/ui/reserve_after_initialization.stderr @@ -6,6 +6,7 @@ LL | | v1.reserve(10); | |___________________^ help: consider using `Vec::with_capacity(/* Space hint */)`: `let mut v1: Vec = Vec::with_capacity(10);` | = note: `-D clippy::reserve-after-initialization` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::reserve_after_initialization)]` error: call to `reserve` immediately after creation --> $DIR/reserve_after_initialization.rs:17:5 diff --git a/tests/ui/rest_pat_in_fully_bound_structs.stderr b/tests/ui/rest_pat_in_fully_bound_structs.stderr index f8e4087823d6..2c221b4dbb2c 100644 --- a/tests/ui/rest_pat_in_fully_bound_structs.stderr +++ b/tests/ui/rest_pat_in_fully_bound_structs.stderr @@ -6,6 +6,7 @@ LL | A { a: 5, b: 42, c: "", .. } => {}, // Lint | = help: consider removing `..` from this binding = note: `-D clippy::rest-pat-in-fully-bound-structs` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::rest_pat_in_fully_bound_structs)]` error: unnecessary use of `..` pattern in struct binding. All fields were already bound --> $DIR/rest_pat_in_fully_bound_structs.rs:24:9 diff --git a/tests/ui/result_large_err.stderr b/tests/ui/result_large_err.stderr index c51531f55db6..d42dd6600a32 100644 --- a/tests/ui/result_large_err.stderr +++ b/tests/ui/result_large_err.stderr @@ -6,6 +6,7 @@ LL | pub fn large_err() -> Result<(), [u8; 512]> { | = help: try reducing the size of `[u8; 512]`, for example by boxing large elements or replacing it with `Box<[u8; 512]>` = note: `-D clippy::result-large-err` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::result_large_err)]` error: the `Err`-variant returned from this function is very large --> $DIR/result_large_err.rs:20:21 diff --git a/tests/ui/result_map_or_into_option.stderr b/tests/ui/result_map_or_into_option.stderr index 2b057042aee2..9396ea4c064e 100644 --- a/tests/ui/result_map_or_into_option.stderr +++ b/tests/ui/result_map_or_into_option.stderr @@ -5,6 +5,7 @@ LL | let _ = opt.map_or(None, Some); | ^^^^^^^^^^^^^^^^^^^^^^ help: try using `ok` instead: `opt.ok()` | = note: `-D clippy::result-map-or-into-option` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::result_map_or_into_option)]` error: aborting due to previous error diff --git a/tests/ui/result_map_unit_fn_fixable.stderr b/tests/ui/result_map_unit_fn_fixable.stderr index 5def0fe41733..42ee273c2bd2 100644 --- a/tests/ui/result_map_unit_fn_fixable.stderr +++ b/tests/ui/result_map_unit_fn_fixable.stderr @@ -7,6 +7,7 @@ LL | x.field.map(do_nothing); | help: try: `if let Ok(x_field) = x.field { do_nothing(x_field) }` | = note: `-D clippy::result-map-unit-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::result_map_unit_fn)]` error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` --> $DIR/result_map_unit_fn_fixable.rs:36:5 diff --git a/tests/ui/result_map_unit_fn_unfixable.stderr b/tests/ui/result_map_unit_fn_unfixable.stderr index ba17e22d0b35..ccf9bfb947c7 100644 --- a/tests/ui/result_map_unit_fn_unfixable.stderr +++ b/tests/ui/result_map_unit_fn_unfixable.stderr @@ -7,6 +7,7 @@ LL | x.field.map(|value| { do_nothing(value); do_nothing(value) }); | help: try: `if let Ok(value) = x.field { ... }` | = note: `-D clippy::result-map-unit-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::result_map_unit_fn)]` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` --> $DIR/result_map_unit_fn_unfixable.rs:27:5 diff --git a/tests/ui/result_unit_error.stderr b/tests/ui/result_unit_error.stderr index 252c72481f51..72208f539164 100644 --- a/tests/ui/result_unit_error.stderr +++ b/tests/ui/result_unit_error.stderr @@ -6,6 +6,7 @@ LL | pub fn returns_unit_error() -> Result { | = help: use a custom `Error` type instead = note: `-D clippy::result-unit-err` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::result_unit_err)]` error: this returns a `Result<_, ()>` --> $DIR/result_unit_error.rs:13:5 diff --git a/tests/ui/return_self_not_must_use.stderr b/tests/ui/return_self_not_must_use.stderr index adfd6564d99c..b3e41470d7b1 100644 --- a/tests/ui/return_self_not_must_use.stderr +++ b/tests/ui/return_self_not_must_use.stderr @@ -6,6 +6,7 @@ LL | fn what(&self) -> Self; | = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type = note: `-D clippy::return-self-not-must-use` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::return_self_not_must_use)]` error: missing `#[must_use]` attribute on a method returning `Self` --> $DIR/return_self_not_must_use.rs:19:5 diff --git a/tests/ui/reversed_empty_ranges_fixable.stderr b/tests/ui/reversed_empty_ranges_fixable.stderr index 2d1bfe62c923..92fbac8e30c9 100644 --- a/tests/ui/reversed_empty_ranges_fixable.stderr +++ b/tests/ui/reversed_empty_ranges_fixable.stderr @@ -5,6 +5,7 @@ LL | (42..=21).for_each(|x| println!("{}", x)); | ^^^^^^^^^ | = note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::reversed_empty_ranges)]` help: consider using the following if you are attempting to iterate over this range in reverse | LL | (21..=42).rev().for_each(|x| println!("{}", x)); diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.stderr b/tests/ui/reversed_empty_ranges_loops_fixable.stderr index a135da488ffd..843d6a36d9be 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.stderr +++ b/tests/ui/reversed_empty_ranges_loops_fixable.stderr @@ -5,6 +5,7 @@ LL | for i in 10..0 { | ^^^^^ | = note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::reversed_empty_ranges)]` help: consider using the following if you are attempting to iterate over this range in reverse | LL | for i in (0..10).rev() { diff --git a/tests/ui/reversed_empty_ranges_loops_unfixable.stderr b/tests/ui/reversed_empty_ranges_loops_unfixable.stderr index f64463174952..73165e091cb1 100644 --- a/tests/ui/reversed_empty_ranges_loops_unfixable.stderr +++ b/tests/ui/reversed_empty_ranges_loops_unfixable.stderr @@ -5,6 +5,7 @@ LL | for i in 5..5 { | ^^^^ | = note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::reversed_empty_ranges)]` error: this range is empty so it will yield no values --> $DIR/reversed_empty_ranges_loops_unfixable.rs:11:14 diff --git a/tests/ui/reversed_empty_ranges_unfixable.stderr b/tests/ui/reversed_empty_ranges_unfixable.stderr index d32301742d34..e3dc96dfb9c4 100644 --- a/tests/ui/reversed_empty_ranges_unfixable.stderr +++ b/tests/ui/reversed_empty_ranges_unfixable.stderr @@ -5,6 +5,7 @@ LL | let _ = &arr[3usize..=1usize]; | ^^^^^^^^^^^^^^^ | = note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::reversed_empty_ranges)]` error: this range is reversed and using it to index a slice will panic at run-time --> $DIR/reversed_empty_ranges_unfixable.rs:11:18 diff --git a/tests/ui/same_item_push.stderr b/tests/ui/same_item_push.stderr index 8e876e914cea..f519be463695 100644 --- a/tests/ui/same_item_push.stderr +++ b/tests/ui/same_item_push.stderr @@ -6,6 +6,7 @@ LL | vec.push(item); | = help: try using vec![item;SIZE] or vec.resize(NEW_SIZE, item) = note: `-D clippy::same-item-push` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::same_item_push)]` error: it looks like the same item is being pushed into this Vec --> $DIR/same_item_push.rs:30:9 diff --git a/tests/ui/same_name_method.stderr b/tests/ui/same_name_method.stderr index b31d2537eadf..3c5c4a53ad1f 100644 --- a/tests/ui/same_name_method.stderr +++ b/tests/ui/same_name_method.stderr @@ -10,6 +10,7 @@ note: existing `foo` defined here LL | fn foo() {} | ^^^^^^^^^^^ = note: `-D clippy::same-name-method` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::same_name_method)]` error: method's name is the same as an existing method in a trait --> $DIR/same_name_method.rs:36:13 diff --git a/tests/ui/search_is_some.stderr b/tests/ui/search_is_some.stderr index 7eff614d17c6..a7a47447f61d 100644 --- a/tests/ui/search_is_some.stderr +++ b/tests/ui/search_is_some.stderr @@ -10,6 +10,7 @@ LL | | ).is_some(); | = help: this is more succinctly expressed by calling `any()` = note: `-D clippy::search-is-some` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::search_is_some)]` error: called `is_some()` after searching an `Iterator` with `position` --> $DIR/search_is_some.rs:21:13 diff --git a/tests/ui/search_is_some_fixable_none.stderr b/tests/ui/search_is_some_fixable_none.stderr index 82b81f290604..f33b0430912a 100644 --- a/tests/ui/search_is_some_fixable_none.stderr +++ b/tests/ui/search_is_some_fixable_none.stderr @@ -5,6 +5,7 @@ LL | let _ = v.iter().find(|&x| *x < 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|x| *x < 0)` | = note: `-D clippy::search-is-some` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::search_is_some)]` error: called `is_none()` after searching an `Iterator` with `find` --> $DIR/search_is_some_fixable_none.rs:10:13 diff --git a/tests/ui/search_is_some_fixable_some.stderr b/tests/ui/search_is_some_fixable_some.stderr index 5466d0cb9f00..e878e62de07f 100644 --- a/tests/ui/search_is_some_fixable_some.stderr +++ b/tests/ui/search_is_some_fixable_some.stderr @@ -5,6 +5,7 @@ LL | let _ = v.iter().find(|&x| *x < 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| *x < 0)` | = note: `-D clippy::search-is-some` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::search_is_some)]` error: called `is_some()` after searching an `Iterator` with `find` --> $DIR/search_is_some_fixable_some.rs:10:20 diff --git a/tests/ui/seek_from_current.stderr b/tests/ui/seek_from_current.stderr index 2549a26b23c3..42eb342c10aa 100644 --- a/tests/ui/seek_from_current.stderr +++ b/tests/ui/seek_from_current.stderr @@ -5,6 +5,7 @@ LL | f.seek(SeekFrom::Current(0))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `f.stream_position()` | = note: `-D clippy::seek-from-current` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::seek_from_current)]` error: aborting due to previous error diff --git a/tests/ui/seek_to_start_instead_of_rewind.stderr b/tests/ui/seek_to_start_instead_of_rewind.stderr index 47cddfe7ea69..05c11cf7f8c6 100644 --- a/tests/ui/seek_to_start_instead_of_rewind.stderr +++ b/tests/ui/seek_to_start_instead_of_rewind.stderr @@ -5,6 +5,7 @@ LL | t.seek(SeekFrom::Start(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()` | = note: `-D clippy::seek-to-start-instead-of-rewind` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::seek_to_start_instead_of_rewind)]` error: used `seek` to go to the start of the stream --> $DIR/seek_to_start_instead_of_rewind.rs:57:7 diff --git a/tests/ui/self_assignment.stderr b/tests/ui/self_assignment.stderr index ecb62f96a93a..4612f8f82448 100644 --- a/tests/ui/self_assignment.stderr +++ b/tests/ui/self_assignment.stderr @@ -5,6 +5,7 @@ LL | a = a; | ^^^^^ | = note: `-D clippy::self-assignment` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::self_assignment)]` error: self-assignment of `*b` to `*b` --> $DIR/self_assignment.rs:16:5 diff --git a/tests/ui/self_named_constructors.stderr b/tests/ui/self_named_constructors.stderr index 2024d86f91fc..f299b860d478 100644 --- a/tests/ui/self_named_constructors.stderr +++ b/tests/ui/self_named_constructors.stderr @@ -9,6 +9,7 @@ LL | | } | |_____^ | = note: `-D clippy::self-named-constructors` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::self_named_constructors)]` error: aborting due to previous error diff --git a/tests/ui/semicolon_if_nothing_returned.stderr b/tests/ui/semicolon_if_nothing_returned.stderr index 8d9a67585cf1..66373a13c569 100644 --- a/tests/ui/semicolon_if_nothing_returned.stderr +++ b/tests/ui/semicolon_if_nothing_returned.stderr @@ -5,6 +5,7 @@ LL | println!("Hello") | ^^^^^^^^^^^^^^^^^ help: add a `;` here: `println!("Hello");` | = note: `-D clippy::semicolon-if-nothing-returned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::semicolon_if_nothing_returned)]` error: consider adding a `;` to the last statement for consistent formatting --> $DIR/semicolon_if_nothing_returned.rs:12:5 diff --git a/tests/ui/semicolon_inside_block.stderr b/tests/ui/semicolon_inside_block.stderr index 825c7142fdfa..1bfc1f24c436 100644 --- a/tests/ui/semicolon_inside_block.stderr +++ b/tests/ui/semicolon_inside_block.stderr @@ -5,6 +5,7 @@ LL | { unit_fn_block() }; | ^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::semicolon-inside-block` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::semicolon_inside_block)]` help: put the `;` here | LL - { unit_fn_block() }; diff --git a/tests/ui/semicolon_outside_block.stderr b/tests/ui/semicolon_outside_block.stderr index 53c6bbd825c1..427271fca64d 100644 --- a/tests/ui/semicolon_outside_block.stderr +++ b/tests/ui/semicolon_outside_block.stderr @@ -5,6 +5,7 @@ LL | { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::semicolon-outside-block` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::semicolon_outside_block)]` help: put the `;` here | LL - { unit_fn_block(); } diff --git a/tests/ui/serde.stderr b/tests/ui/serde.stderr index a0d8217010e9..e5d64e271644 100644 --- a/tests/ui/serde.stderr +++ b/tests/ui/serde.stderr @@ -11,6 +11,7 @@ LL | | } | |_____^ | = note: `-D clippy::serde-api-misuse` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::serde_api_misuse)]` error: aborting due to previous error diff --git a/tests/ui/shadow.stderr b/tests/ui/shadow.stderr index 88b02f53be12..26ace287b1f4 100644 --- a/tests/ui/shadow.stderr +++ b/tests/ui/shadow.stderr @@ -10,6 +10,7 @@ note: previous binding is here LL | let x = 1; | ^ = note: `-D clippy::shadow-same` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::shadow_same)]` error: `mut x` is shadowed by itself in `&x` --> $DIR/shadow.rs:25:13 @@ -59,6 +60,7 @@ note: previous binding is here LL | let x = ([[0]], ()); | ^ = note: `-D clippy::shadow-reuse` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::shadow_reuse)]` error: `x` is shadowed --> $DIR/shadow.rs:33:9 @@ -156,6 +158,7 @@ note: previous binding is here LL | let x = 1; | ^ = note: `-D clippy::shadow-unrelated` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::shadow_unrelated)]` error: `x` shadows a previous, unrelated binding --> $DIR/shadow.rs:60:13 diff --git a/tests/ui/short_circuit_statement.stderr b/tests/ui/short_circuit_statement.stderr index 1f7adea4a8b1..dbdf44dfcbd9 100644 --- a/tests/ui/short_circuit_statement.stderr +++ b/tests/ui/short_circuit_statement.stderr @@ -5,6 +5,7 @@ LL | f() && g(); | ^^^^^^^^^^^ help: replace it with: `if f() { g(); }` | = note: `-D clippy::short-circuit-statement` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::short_circuit_statement)]` error: boolean short circuit operator in statement may be clearer using an explicit test --> $DIR/short_circuit_statement.rs:6:5 diff --git a/tests/ui/should_impl_trait/method_list_1.stderr b/tests/ui/should_impl_trait/method_list_1.stderr index 7ad00d14d0cd..c9894eec53a2 100644 --- a/tests/ui/should_impl_trait/method_list_1.stderr +++ b/tests/ui/should_impl_trait/method_list_1.stderr @@ -9,6 +9,7 @@ LL | | } | = help: consider implementing the trait `std::ops::Add` or choosing a less ambiguous method name = note: `-D clippy::should-implement-trait` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::should_implement_trait)]` error: method `as_mut` can be confused for the standard trait method `std::convert::AsMut::as_mut` --> $DIR/method_list_1.rs:30:5 diff --git a/tests/ui/should_impl_trait/method_list_2.stderr b/tests/ui/should_impl_trait/method_list_2.stderr index 0073c899813f..79afddea2479 100644 --- a/tests/ui/should_impl_trait/method_list_2.stderr +++ b/tests/ui/should_impl_trait/method_list_2.stderr @@ -9,6 +9,7 @@ LL | | } | = help: consider implementing the trait `std::cmp::PartialEq` or choosing a less ambiguous method name = note: `-D clippy::should-implement-trait` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::should_implement_trait)]` error: method `from_iter` can be confused for the standard trait method `std::iter::FromIterator::from_iter` --> $DIR/method_list_2.rs:31:5 @@ -174,6 +175,7 @@ LL | pub fn hash(&self, state: &mut T) { | = warning: changing this function will impact semver compatibility = note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]` error: aborting due to 16 previous errors diff --git a/tests/ui/significant_drop_in_scrutinee.stderr b/tests/ui/significant_drop_in_scrutinee.stderr index 6ead59b07258..05bfda5475d8 100644 --- a/tests/ui/significant_drop_in_scrutinee.stderr +++ b/tests/ui/significant_drop_in_scrutinee.stderr @@ -12,6 +12,7 @@ LL | }; | = note: this might lead to deadlocks or other unexpected behavior = note: `-D clippy::significant-drop-in-scrutinee` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::significant_drop_in_scrutinee)]` help: try moving the temporary above the match | LL ~ let value = mutex.lock().unwrap().foo(); diff --git a/tests/ui/significant_drop_tightening.stderr b/tests/ui/significant_drop_tightening.stderr index ff6f5907ebd5..6572d9969317 100644 --- a/tests/ui/significant_drop_tightening.stderr +++ b/tests/ui/significant_drop_tightening.stderr @@ -16,6 +16,7 @@ LL | | } | = note: this might lead to unnecessary resource contention = note: `-D clippy::significant-drop-tightening` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::significant_drop_tightening)]` help: drop the temporary after the end of its last usage | LL ~ let _ = *lock; diff --git a/tests/ui/similar_names.stderr b/tests/ui/similar_names.stderr index 059e26d58911..011dbe679c08 100644 --- a/tests/ui/similar_names.stderr +++ b/tests/ui/similar_names.stderr @@ -10,6 +10,7 @@ note: existing binding defined here LL | let apple: i32; | ^^^^^ = note: `-D clippy::similar-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::similar_names)]` error: binding's name is too similar to existing binding --> $DIR/similar_names.rs:24:9 diff --git a/tests/ui/single_call_fn.stderr b/tests/ui/single_call_fn.stderr index 9ef8c487844f..4acb383c4084 100644 --- a/tests/ui/single_call_fn.stderr +++ b/tests/ui/single_call_fn.stderr @@ -14,6 +14,7 @@ help: used here LL | c(); | ^ = note: `-D clippy::single-call-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_call_fn)]` error: this function is only used once --> $DIR/single_call_fn.rs:12:1 diff --git a/tests/ui/single_char_add_str.stderr b/tests/ui/single_char_add_str.stderr index cea9ba7235de..a6f2b3e037b4 100644 --- a/tests/ui/single_char_add_str.stderr +++ b/tests/ui/single_char_add_str.stderr @@ -5,6 +5,7 @@ LL | string.push_str("R"); | ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('R')` | = note: `-D clippy::single-char-add-str` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_char_add_str)]` error: calling `push_str()` using a single-character string literal --> $DIR/single_char_add_str.rs:15:5 diff --git a/tests/ui/single_char_lifetime_names.stderr b/tests/ui/single_char_lifetime_names.stderr index 19bea0ae0c23..2cdfd61358e7 100644 --- a/tests/ui/single_char_lifetime_names.stderr +++ b/tests/ui/single_char_lifetime_names.stderr @@ -6,6 +6,7 @@ LL | struct DiagnosticCtx<'a, 'b> | = help: use a more informative name = note: `-D clippy::single-char-lifetime-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_char_lifetime_names)]` error: single-character lifetime names are likely uninformative --> $DIR/single_char_lifetime_names.rs:5:26 diff --git a/tests/ui/single_char_pattern.stderr b/tests/ui/single_char_pattern.stderr index f11ab12edee9..6e57ab3489f1 100644 --- a/tests/ui/single_char_pattern.stderr +++ b/tests/ui/single_char_pattern.stderr @@ -5,6 +5,7 @@ LL | x.split("x"); | ^^^ help: try using a `char` instead: `'x'` | = note: `-D clippy::single-char-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_char_pattern)]` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:13:13 diff --git a/tests/ui/single_component_path_imports.stderr b/tests/ui/single_component_path_imports.stderr index 0bff108f86ac..440d34002d7f 100644 --- a/tests/ui/single_component_path_imports.stderr +++ b/tests/ui/single_component_path_imports.stderr @@ -5,6 +5,7 @@ LL | use regex; | ^^^^^^^^^^ help: remove it entirely | = note: `-D clippy::single-component-path-imports` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_component_path_imports)]` error: this import is redundant --> $DIR/single_component_path_imports.rs:32:5 diff --git a/tests/ui/single_component_path_imports_nested_first.stderr b/tests/ui/single_component_path_imports_nested_first.stderr index b2a0521f7d14..d65ab5620db7 100644 --- a/tests/ui/single_component_path_imports_nested_first.stderr +++ b/tests/ui/single_component_path_imports_nested_first.stderr @@ -5,6 +5,7 @@ LL | use regex; | ^^^^^^^^^^ help: remove it entirely | = note: `-D clippy::single-component-path-imports` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_component_path_imports)]` error: this import is redundant --> $DIR/single_component_path_imports_nested_first.rs:17:10 diff --git a/tests/ui/single_element_loop.stderr b/tests/ui/single_element_loop.stderr index 1d89bf553879..603dd7406e4e 100644 --- a/tests/ui/single_element_loop.stderr +++ b/tests/ui/single_element_loop.stderr @@ -7,6 +7,7 @@ LL | | } | |_____^ | = note: `-D clippy::single-element-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_element_loop)]` help: try | LL ~ { diff --git a/tests/ui/single_match.stderr b/tests/ui/single_match.stderr index 76f7e7895898..d4b865995213 100644 --- a/tests/ui/single_match.stderr +++ b/tests/ui/single_match.stderr @@ -10,6 +10,7 @@ LL | | }; | |_____^ | = note: `-D clippy::single-match` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_match)]` help: try | LL ~ if let Some(y) = x { diff --git a/tests/ui/single_match_else.stderr b/tests/ui/single_match_else.stderr index e85d51de6a10..3b4b1332c403 100644 --- a/tests/ui/single_match_else.stderr +++ b/tests/ui/single_match_else.stderr @@ -12,6 +12,7 @@ LL | | }; | |_____^ | = note: `-D clippy::single-match-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_match_else)]` help: try | LL ~ let _ = if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { diff --git a/tests/ui/single_range_in_vec_init.stderr b/tests/ui/single_range_in_vec_init.stderr index 1b347f4ae97f..e83e49af676c 100644 --- a/tests/ui/single_range_in_vec_init.stderr +++ b/tests/ui/single_range_in_vec_init.stderr @@ -5,6 +5,7 @@ LL | [0..200]; | ^^^^^^^^ | = note: `-D clippy::single-range-in-vec-init` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_range_in_vec_init)]` help: if you wanted a `Vec` that contains the entire range, try | LL | (0..200).collect::>(); diff --git a/tests/ui/size_of_in_element_count/expressions.stderr b/tests/ui/size_of_in_element_count/expressions.stderr index 0c31c3a1f4b3..47f9632b8d12 100644 --- a/tests/ui/size_of_in_element_count/expressions.stderr +++ b/tests/ui/size_of_in_element_count/expressions.stderr @@ -6,6 +6,7 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::( | = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type = note: `-D clippy::size-of-in-element-count` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::size_of_in_element_count)]` error: found a count of bytes instead of a count of elements of `T` --> $DIR/expressions.rs:19:62 diff --git a/tests/ui/size_of_in_element_count/functions.stderr b/tests/ui/size_of_in_element_count/functions.stderr index 4901d11736d5..aba4c800e44d 100644 --- a/tests/ui/size_of_in_element_count/functions.stderr +++ b/tests/ui/size_of_in_element_count/functions.stderr @@ -6,6 +6,7 @@ LL | unsafe { copy_nonoverlapping::(x.as_ptr(), y.as_mut_ptr(), size_of: | = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type = note: `-D clippy::size-of-in-element-count` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::size_of_in_element_count)]` error: found a count of bytes instead of a count of elements of `T` --> $DIR/functions.rs:20:62 diff --git a/tests/ui/size_of_ref.stderr b/tests/ui/size_of_ref.stderr index c7a1758825cb..e239c5810c92 100644 --- a/tests/ui/size_of_ref.stderr +++ b/tests/ui/size_of_ref.stderr @@ -6,6 +6,7 @@ LL | size_of_val(&&x); | = help: dereference the argument to `std::mem::size_of_val()` to get the size of the value instead of the size of the reference-type = note: `-D clippy::size-of-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::size_of_ref)]` error: argument to `std::mem::size_of_val()` is a reference to a reference --> $DIR/size_of_ref.rs:15:5 diff --git a/tests/ui/skip_while_next.stderr b/tests/ui/skip_while_next.stderr index 7308ab4e55c9..3c33af3a1608 100644 --- a/tests/ui/skip_while_next.stderr +++ b/tests/ui/skip_while_next.stderr @@ -6,6 +6,7 @@ LL | let _ = v.iter().skip_while(|&x| *x < 0).next(); | = help: this is more succinctly expressed by calling `.find(!

)` instead = note: `-D clippy::skip-while-next` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::skip_while_next)]` error: called `skip_while(

).next()` on an `Iterator` --> $DIR/skip_while_next.rs:17:13 diff --git a/tests/ui/slow_vector_initialization.stderr b/tests/ui/slow_vector_initialization.stderr index 4800e6e44186..f4501551656a 100644 --- a/tests/ui/slow_vector_initialization.stderr +++ b/tests/ui/slow_vector_initialization.stderr @@ -7,6 +7,7 @@ LL | vec1.extend(repeat(0).take(len)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::slow-vector-initialization` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::slow_vector_initialization)]` error: slow zero-filling initialization --> $DIR/slow_vector_initialization.rs:20:5 @@ -103,6 +104,7 @@ LL | fn do_stuff(vec: &mut [u8]) {} | ^^^^^^^^^ help: consider changing to: `&[u8]` | = note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]` error: aborting due to 13 previous errors diff --git a/tests/ui/stable_sort_primitive.stderr b/tests/ui/stable_sort_primitive.stderr index 1432fdcff77a..b66503328334 100644 --- a/tests/ui/stable_sort_primitive.stderr +++ b/tests/ui/stable_sort_primitive.stderr @@ -6,6 +6,7 @@ LL | vec.sort(); | = note: an unstable sort typically performs faster without any observable difference for this data type = note: `-D clippy::stable-sort-primitive` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::stable_sort_primitive)]` error: used `sort` on primitive type `bool` --> $DIR/stable_sort_primitive.rs:9:5 diff --git a/tests/ui/starts_ends_with.stderr b/tests/ui/starts_ends_with.stderr index 48d561bc4b8e..c4c547949a36 100644 --- a/tests/ui/starts_ends_with.stderr +++ b/tests/ui/starts_ends_with.stderr @@ -5,6 +5,7 @@ LL | "".chars().next() == Some(' '); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".starts_with(' ')` | = note: `-D clippy::chars-next-cmp` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::chars_next_cmp)]` error: you should use the `starts_with` method --> $DIR/starts_ends_with.rs:8:5 @@ -37,6 +38,7 @@ LL | if s.chars().next_back().unwrap() == 'o' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')` | = note: `-D clippy::chars-last-cmp` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::chars_last_cmp)]` error: you should use the `ends_with` method --> $DIR/starts_ends_with.rs:25:8 diff --git a/tests/ui/std_instead_of_core.stderr b/tests/ui/std_instead_of_core.stderr index f2db81e51633..7435d716157a 100644 --- a/tests/ui/std_instead_of_core.stderr +++ b/tests/ui/std_instead_of_core.stderr @@ -6,6 +6,7 @@ LL | use std::hash::Hasher; | = help: consider importing the item from `core` = note: `-D clippy::std-instead-of-core` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::std_instead_of_core)]` error: used import from `std` instead of `core` --> $DIR/std_instead_of_core.rs:12:9 @@ -79,6 +80,7 @@ LL | use std::vec; | = help: consider importing the item from `alloc` = note: `-D clippy::std-instead-of-alloc` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::std_instead_of_alloc)]` error: used import from `std` instead of `alloc` --> $DIR/std_instead_of_core.rs:49:9 @@ -96,6 +98,7 @@ LL | use alloc::slice::from_ref; | = help: consider importing the item from `core` = note: `-D clippy::alloc-instead-of-core` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::alloc_instead_of_core)]` error: aborting due to 12 previous errors diff --git a/tests/ui/str_to_string.stderr b/tests/ui/str_to_string.stderr index 25af1d376638..203805eca5a6 100644 --- a/tests/ui/str_to_string.stderr +++ b/tests/ui/str_to_string.stderr @@ -6,6 +6,7 @@ LL | let hello = "hello world".to_string(); | = help: consider using `.to_owned()` = note: `-D clippy::str-to-string` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::str_to_string)]` error: `to_string()` called on a `&str` --> $DIR/str_to_string.rs:7:5 diff --git a/tests/ui/string_add.stderr b/tests/ui/string_add.stderr index 3987641c75a3..892753b9034e 100644 --- a/tests/ui/string_add.stderr +++ b/tests/ui/string_add.stderr @@ -5,6 +5,7 @@ LL | x = x + "."; | ^^^^^^^^^^^ help: replace it with: `x += "."` | = note: `-D clippy::assign-op-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::assign_op_pattern)]` error: you added something to a string. Consider using `String::push_str()` instead --> $DIR/string_add.rs:13:13 @@ -13,6 +14,7 @@ LL | x = x + "."; | ^^^^^^^ | = note: `-D clippy::string-add` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::string_add)]` error: you added something to a string. Consider using `String::push_str()` instead --> $DIR/string_add.rs:17:13 diff --git a/tests/ui/string_add_assign.stderr b/tests/ui/string_add_assign.stderr index d4b995519e37..7d37c98a8f93 100644 --- a/tests/ui/string_add_assign.stderr +++ b/tests/ui/string_add_assign.stderr @@ -5,6 +5,7 @@ LL | x = x + "."; | ^^^^^^^^^^^ | = note: `-D clippy::string-add-assign` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::string_add_assign)]` error: manual implementation of an assign operation --> $DIR/string_add_assign.rs:8:9 @@ -13,6 +14,7 @@ LL | x = x + "."; | ^^^^^^^^^^^ help: replace it with: `x += "."` | = note: `-D clippy::assign-op-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::assign_op_pattern)]` error: manual implementation of an assign operation --> $DIR/string_add_assign.rs:17:5 diff --git a/tests/ui/string_extend.stderr b/tests/ui/string_extend.stderr index 49ff4516db1b..e063d87e37d3 100644 --- a/tests/ui/string_extend.stderr +++ b/tests/ui/string_extend.stderr @@ -5,6 +5,7 @@ LL | s.extend(abc.chars()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `s.push_str(abc)` | = note: `-D clippy::string-extend-chars` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::string_extend_chars)]` error: calling `.extend(_.chars())` --> $DIR/string_extend.rs:19:5 diff --git a/tests/ui/string_from_utf8_as_bytes.stderr b/tests/ui/string_from_utf8_as_bytes.stderr index 0fa4d59068f8..cf5688a97824 100644 --- a/tests/ui/string_from_utf8_as_bytes.stderr +++ b/tests/ui/string_from_utf8_as_bytes.stderr @@ -5,6 +5,7 @@ LL | let _ = std::str::from_utf8(&"Hello World!".as_bytes()[6..11]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(&"Hello World!"[6..11])` | = note: `-D clippy::string-from-utf8-as-bytes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::string_from_utf8_as_bytes)]` error: aborting due to previous error diff --git a/tests/ui/string_lit_as_bytes.stderr b/tests/ui/string_lit_as_bytes.stderr index 73576f9f3000..1c12cb8e56d2 100644 --- a/tests/ui/string_lit_as_bytes.stderr +++ b/tests/ui/string_lit_as_bytes.stderr @@ -5,6 +5,7 @@ LL | let bs = "hello there".as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"hello there"` | = note: `-D clippy::string-lit-as-bytes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::string_lit_as_bytes)]` error: calling `as_bytes()` on a string literal --> $DIR/string_lit_as_bytes.rs:18:14 diff --git a/tests/ui/string_lit_chars_any.stderr b/tests/ui/string_lit_chars_any.stderr index dac9a90b3418..09c4f02eb062 100644 --- a/tests/ui/string_lit_chars_any.stderr +++ b/tests/ui/string_lit_chars_any.stderr @@ -5,6 +5,7 @@ LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == c); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::string-lit-chars-any` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::string_lit_chars_any)]` help: use `matches!(...)` instead | LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); diff --git a/tests/ui/string_slice.stderr b/tests/ui/string_slice.stderr index 94dad58cd972..e9e773aaf3ae 100644 --- a/tests/ui/string_slice.stderr +++ b/tests/ui/string_slice.stderr @@ -5,6 +5,7 @@ LL | &"Ölkanne"[1..]; | ^^^^^^^^^^^^^^ | = note: `-D clippy::string-slice` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::string_slice)]` error: indexing into a string may panic if the index is within a UTF-8 character --> $DIR/string_slice.rs:9:6 diff --git a/tests/ui/string_to_string.stderr b/tests/ui/string_to_string.stderr index e304c3e346db..27a84431507b 100644 --- a/tests/ui/string_to_string.stderr +++ b/tests/ui/string_to_string.stderr @@ -6,6 +6,7 @@ LL | let mut v = message.to_string(); | = help: consider using `.clone()` = note: `-D clippy::string-to-string` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::string_to_string)]` error: aborting due to previous error diff --git a/tests/ui/strlen_on_c_strings.stderr b/tests/ui/strlen_on_c_strings.stderr index 81881fbe3bd3..6d8ad3981c04 100644 --- a/tests/ui/strlen_on_c_strings.stderr +++ b/tests/ui/strlen_on_c_strings.stderr @@ -5,6 +5,7 @@ LL | let _ = unsafe { libc::strlen(cstring.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cstring.as_bytes().len()` | = note: `-D clippy::strlen-on-c-strings` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::strlen_on_c_strings)]` error: using `libc::strlen` on a `CString` or `CStr` value --> $DIR/strlen_on_c_strings.rs:17:13 diff --git a/tests/ui/struct_excessive_bools.stderr b/tests/ui/struct_excessive_bools.stderr index 05b2363eb568..5284949c2d2a 100644 --- a/tests/ui/struct_excessive_bools.stderr +++ b/tests/ui/struct_excessive_bools.stderr @@ -12,6 +12,7 @@ LL | | } | = help: consider using a state machine or refactoring bools into two-variant enums = note: `-D clippy::struct-excessive-bools` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::struct_excessive_bools)]` error: more than 3 bools in a struct --> $DIR/struct_excessive_bools.rs:39:5 diff --git a/tests/ui/suspicious_arithmetic_impl.stderr b/tests/ui/suspicious_arithmetic_impl.stderr index 4a4be0712b28..3995c6eb5c4e 100644 --- a/tests/ui/suspicious_arithmetic_impl.stderr +++ b/tests/ui/suspicious_arithmetic_impl.stderr @@ -5,6 +5,7 @@ LL | Foo(self.0 - other.0) | ^ | = note: `-D clippy::suspicious-arithmetic-impl` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_arithmetic_impl)]` error: suspicious use of `-` in `AddAssign` impl --> $DIR/suspicious_arithmetic_impl.rs:21:23 @@ -13,6 +14,7 @@ LL | *self = *self - other; | ^ | = note: `-D clippy::suspicious-op-assign-impl` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_op_assign_impl)]` error: suspicious use of `/` in `MulAssign` impl --> $DIR/suspicious_arithmetic_impl.rs:36:16 diff --git a/tests/ui/suspicious_command_arg_space.stderr b/tests/ui/suspicious_command_arg_space.stderr index 0ed4eb20ecb5..9bf3128cb8e2 100644 --- a/tests/ui/suspicious_command_arg_space.stderr +++ b/tests/ui/suspicious_command_arg_space.stderr @@ -5,6 +5,7 @@ LL | std::process::Command::new("echo").arg("-n hello").spawn().unwrap(); | ^^^^^^^^^^ | = note: `-D clippy::suspicious-command-arg-space` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_command_arg_space)]` help: consider splitting the argument | LL | std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap(); diff --git a/tests/ui/suspicious_doc_comments.stderr b/tests/ui/suspicious_doc_comments.stderr index 8d2a2bdf6e99..1b238f501e13 100644 --- a/tests/ui/suspicious_doc_comments.stderr +++ b/tests/ui/suspicious_doc_comments.stderr @@ -5,6 +5,7 @@ LL | ///! Fake module documentation. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::suspicious-doc-comments` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_doc_comments)]` help: use an inner doc comment to document the parent module or crate | LL | //! Fake module documentation. diff --git a/tests/ui/suspicious_doc_comments_unfixable.stderr b/tests/ui/suspicious_doc_comments_unfixable.stderr index 3a93c289fc70..ae92c334f609 100644 --- a/tests/ui/suspicious_doc_comments_unfixable.stderr +++ b/tests/ui/suspicious_doc_comments_unfixable.stderr @@ -10,6 +10,7 @@ LL | | ///! d | |______^ | = note: `-D clippy::suspicious-doc-comments` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_doc_comments)]` help: use an inner doc comment to document the parent module or crate | LL + //! a diff --git a/tests/ui/suspicious_else_formatting.stderr b/tests/ui/suspicious_else_formatting.stderr index 723fdd7e93e3..95047cb95ee1 100644 --- a/tests/ui/suspicious_else_formatting.stderr +++ b/tests/ui/suspicious_else_formatting.stderr @@ -6,6 +6,7 @@ LL | } { | = note: to remove this lint, add the missing `else` or add a new line before the next block = note: `-D clippy::suspicious-else-formatting` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_else_formatting)]` error: this looks like an `else if` but the `else` is missing --> $DIR/suspicious_else_formatting.rs:26:6 diff --git a/tests/ui/suspicious_map.stderr b/tests/ui/suspicious_map.stderr index 154083f99fa2..9c065e05ca6f 100644 --- a/tests/ui/suspicious_map.stderr +++ b/tests/ui/suspicious_map.stderr @@ -6,6 +6,7 @@ LL | let _ = (0..3).map(|x| x + 2).count(); | = help: make sure you did not confuse `map` with `filter`, `for_each` or `inspect` = note: `-D clippy::suspicious-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_map)]` error: this call to `map()` won't have an effect on the call to `count()` --> $DIR/suspicious_map.rs:8:13 diff --git a/tests/ui/suspicious_operation_groupings.stderr b/tests/ui/suspicious_operation_groupings.stderr index baf9bc74b000..0784da06e5f5 100644 --- a/tests/ui/suspicious_operation_groupings.stderr +++ b/tests/ui/suspicious_operation_groupings.stderr @@ -5,6 +5,7 @@ LL | self.x == other.y && self.y == other.y && self.z == other.z | ^^^^^^^^^^^^^^^^^ help: did you mean: `self.x == other.x` | = note: `-D clippy::suspicious-operation-groupings` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_operation_groupings)]` error: this sequence of operators looks suspiciously like a bug --> $DIR/suspicious_operation_groupings.rs:28:20 diff --git a/tests/ui/suspicious_splitn.stderr b/tests/ui/suspicious_splitn.stderr index 2bdf1043abb7..4513beac8b2d 100644 --- a/tests/ui/suspicious_splitn.stderr +++ b/tests/ui/suspicious_splitn.stderr @@ -6,6 +6,7 @@ LL | let _ = "a,b".splitn(0, ','); | = note: the resulting iterator will always return `None` = note: `-D clippy::suspicious-splitn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_splitn)]` error: `rsplitn` called with `0` splits --> $DIR/suspicious_splitn.rs:13:13 diff --git a/tests/ui/suspicious_to_owned.stderr b/tests/ui/suspicious_to_owned.stderr index cbda1649c629..eb967a714d94 100644 --- a/tests/ui/suspicious_to_owned.stderr +++ b/tests/ui/suspicious_to_owned.stderr @@ -5,6 +5,7 @@ LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ | = note: `-D clippy::suspicious-to-owned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_to_owned)]` help: depending on intent, either make the Cow an Owned variant | LL | let _ = cow.into_owned(); @@ -66,6 +67,7 @@ LL | let _ = String::from(moo).to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::from(moo).clone()` | = note: `-D clippy::implicit-clone` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::implicit_clone)]` error: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type --> $DIR/suspicious_to_owned.rs:69:13 diff --git a/tests/ui/suspicious_unary_op_formatting.stderr b/tests/ui/suspicious_unary_op_formatting.stderr index c44a43ea1ec2..3cddde4eca7b 100644 --- a/tests/ui/suspicious_unary_op_formatting.stderr +++ b/tests/ui/suspicious_unary_op_formatting.stderr @@ -6,6 +6,7 @@ LL | if a >- 30 {} | = help: put a space between `>` and `-` and remove the space after `-` = note: `-D clippy::suspicious-unary-op-formatting` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_unary_op_formatting)]` error: by not having a space between `>=` and `-` it looks like `>=-` is a single operator --> $DIR/suspicious_unary_op_formatting.rs:11:9 diff --git a/tests/ui/suspicious_xor_used_as_pow.stderr b/tests/ui/suspicious_xor_used_as_pow.stderr index 1a260e64e77a..29e9fa771019 100644 --- a/tests/ui/suspicious_xor_used_as_pow.stderr +++ b/tests/ui/suspicious_xor_used_as_pow.stderr @@ -5,6 +5,7 @@ LL | let _ = 2 ^ 5; | ^^^^^ help: did you mean to write: `2.pow(5)` | = note: `-D clippy::suspicious-xor-used-as-pow` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_xor_used_as_pow)]` error: `^` is not the exponentiation operator --> $DIR/suspicious_xor_used_as_pow.rs:22:13 diff --git a/tests/ui/swap.stderr b/tests/ui/swap.stderr index a3b9c2b744c9..e69ad02b08fe 100644 --- a/tests/ui/swap.stderr +++ b/tests/ui/swap.stderr @@ -8,6 +8,7 @@ LL | | bar.b = temp; | = note: or maybe you should use `std::mem::replace`? = note: `-D clippy::manual-swap` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_swap)]` error: this looks like you are swapping elements of `foo` manually --> $DIR/swap.rs:40:5 @@ -108,6 +109,7 @@ LL | | b = a; | = note: or maybe you should use `std::mem::replace`? = note: `-D clippy::almost-swapped` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::almost_swapped)]` error: this looks like you are trying to swap `c.0` and `a` --> $DIR/swap.rs:144:5 diff --git a/tests/ui/swap_ptr_to_ref.stderr b/tests/ui/swap_ptr_to_ref.stderr index a0f5160ee207..42455f4926e8 100644 --- a/tests/ui/swap_ptr_to_ref.stderr +++ b/tests/ui/swap_ptr_to_ref.stderr @@ -5,6 +5,7 @@ LL | core::mem::swap(&mut *y, &mut *z); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use ptr::swap: `core::ptr::swap(y, z)` | = note: `-D clippy::swap-ptr-to-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::swap_ptr_to_ref)]` error: call to `core::mem::swap` with a parameter derived from a raw pointer --> $DIR/swap_ptr_to_ref.rs:12:9 diff --git a/tests/ui/swap_ptr_to_ref_unfixable.stderr b/tests/ui/swap_ptr_to_ref_unfixable.stderr index f0c1e7e7428b..ce1d7814250a 100644 --- a/tests/ui/swap_ptr_to_ref_unfixable.stderr +++ b/tests/ui/swap_ptr_to_ref_unfixable.stderr @@ -5,6 +5,7 @@ LL | core::mem::swap(addr_of_mut_to_ref!(x), &mut *y); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::swap-ptr-to-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::swap_ptr_to_ref)]` error: call to `core::mem::swap` with a parameter derived from a raw pointer --> $DIR/swap_ptr_to_ref_unfixable.rs:17:9 diff --git a/tests/ui/tabs_in_doc_comments.stderr b/tests/ui/tabs_in_doc_comments.stderr index 9da05fbec682..69ce214ae565 100644 --- a/tests/ui/tabs_in_doc_comments.stderr +++ b/tests/ui/tabs_in_doc_comments.stderr @@ -5,6 +5,7 @@ LL | /// - First String: | ^^^^ help: consider using four spaces per tab | = note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::tabs_in_doc_comments)]` error: using tabs in doc comments is not recommended --> $DIR/tabs_in_doc_comments.rs:11:9 diff --git a/tests/ui/temporary_assignment.stderr b/tests/ui/temporary_assignment.stderr index 241abc2c5c7c..cbb8924187c4 100644 --- a/tests/ui/temporary_assignment.stderr +++ b/tests/ui/temporary_assignment.stderr @@ -5,6 +5,7 @@ LL | Struct { field: 0 }.field = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::temporary-assignment` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::temporary_assignment)]` error: assignment to temporary --> $DIR/temporary_assignment.rs:51:5 diff --git a/tests/ui/tests_outside_test_module.stderr b/tests/ui/tests_outside_test_module.stderr index 71c649c5d270..112d6ce1f2c4 100644 --- a/tests/ui/tests_outside_test_module.stderr +++ b/tests/ui/tests_outside_test_module.stderr @@ -6,6 +6,7 @@ LL | fn my_test() {} | = note: move it to a testing module marked with #[cfg(test)] = note: `-D clippy::tests-outside-test-module` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::tests_outside_test_module)]` error: aborting due to previous error diff --git a/tests/ui/to_digit_is_some.stderr b/tests/ui/to_digit_is_some.stderr index 9ece2fce664e..5067ad7fb6df 100644 --- a/tests/ui/to_digit_is_some.stderr +++ b/tests/ui/to_digit_is_some.stderr @@ -5,6 +5,7 @@ LL | let _ = d.to_digit(8).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `d.is_digit(8)` | = note: `-D clippy::to-digit-is-some` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::to_digit_is_some)]` error: use of `.to_digit(..).is_some()` --> $DIR/to_digit_is_some.rs:8:13 diff --git a/tests/ui/toplevel_ref_arg.stderr b/tests/ui/toplevel_ref_arg.stderr index 84017669f475..2c27a3c8e918 100644 --- a/tests/ui/toplevel_ref_arg.stderr +++ b/tests/ui/toplevel_ref_arg.stderr @@ -5,6 +5,7 @@ LL | let ref _x = 1; | ----^^^^^^----- help: try: `let _x = &1;` | = note: `-D clippy::toplevel-ref-arg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::toplevel_ref_arg)]` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead --> $DIR/toplevel_ref_arg.rs:16:9 diff --git a/tests/ui/toplevel_ref_arg_non_rustfix.stderr b/tests/ui/toplevel_ref_arg_non_rustfix.stderr index 7307bd599d9b..45123dd5ec0b 100644 --- a/tests/ui/toplevel_ref_arg_non_rustfix.stderr +++ b/tests/ui/toplevel_ref_arg_non_rustfix.stderr @@ -5,6 +5,7 @@ LL | fn the_answer(ref mut x: u8) { | ^^^^^^^^^ | = note: `-D clippy::toplevel-ref-arg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::toplevel_ref_arg)]` error: `ref` directly on a function argument is ignored. Consider using a reference type instead --> $DIR/toplevel_ref_arg_non_rustfix.rs:20:24 diff --git a/tests/ui/trailing_empty_array.stderr b/tests/ui/trailing_empty_array.stderr index d89e77f61ce4..ef7fc24c374f 100644 --- a/tests/ui/trailing_empty_array.stderr +++ b/tests/ui/trailing_empty_array.stderr @@ -10,6 +10,7 @@ LL | | } | = help: consider annotating `RarelyUseful` with `#[repr(C)]` or another `repr` attribute = note: `-D clippy::trailing-empty-array` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::trailing_empty_array)]` error: trailing zero-sized array in a struct which is not marked with a `repr` attribute --> $DIR/trailing_empty_array.rs:11:1 diff --git a/tests/ui/trailing_zeros.stderr b/tests/ui/trailing_zeros.stderr index fb4025a75481..10924ad12471 100644 --- a/tests/ui/trailing_zeros.stderr +++ b/tests/ui/trailing_zeros.stderr @@ -5,6 +5,7 @@ LL | let _ = (x & 0b1111 == 0); | ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 4` | = note: `-D clippy::verbose-bit-mask` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::verbose_bit_mask)]` error: bit mask could be simplified with a call to `trailing_zeros` --> $DIR/trailing_zeros.rs:9:13 diff --git a/tests/ui/transmute.stderr b/tests/ui/transmute.stderr index 2765f763d6df..cdc733b54a9b 100644 --- a/tests/ui/transmute.stderr +++ b/tests/ui/transmute.stderr @@ -5,6 +5,7 @@ LL | let _: *const T = core::intrinsics::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T` | = note: `-D clippy::useless-transmute` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::useless_transmute)]` error: transmute from a reference to a pointer --> $DIR/transmute.rs:28:21 @@ -67,6 +68,7 @@ LL | let _: Usize = core::intrinsics::transmute(int_const_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::crosspointer-transmute` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::crosspointer_transmute)]` error: transmute from a type (`*mut Usize`) to the type that it points to (`Usize`) --> $DIR/transmute.rs:94:24 @@ -93,6 +95,7 @@ LL | let _: char = unsafe { std::mem::transmute(0_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_u32).unwrap()` | = note: `-D clippy::transmute-int-to-char` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_char)]` error: transmute from a `i32` to a `char` --> $DIR/transmute.rs:110:28 @@ -107,6 +110,7 @@ LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `0_u8 != 0` | = note: `-D clippy::transmute-int-to-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_bool)]` error: transmute from a `u32` to a `f32` --> $DIR/transmute.rs:128:31 @@ -115,6 +119,7 @@ LL | let _: f32 = unsafe { std::mem::transmute(0_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_u32)` | = note: `-D clippy::transmute-int-to-float` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_float)]` error: transmute from a `i32` to a `f32` --> $DIR/transmute.rs:131:31 @@ -141,6 +146,7 @@ LL | let _: [u8; 1] = std::mem::transmute(0u8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u8.to_ne_bytes()` | = note: `-D clippy::transmute-num-to-bytes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_num_to_bytes)]` error: transmute from a `u32` to a `[u8; 4]` --> $DIR/transmute.rs:159:30 @@ -227,6 +233,7 @@ LL | let _: &str = unsafe { std::mem::transmute(B) }; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8(B).unwrap()` | = note: `-D clippy::transmute-bytes-to-str` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_bytes_to_str)]` error: transmute from a `&mut [u8]` to a `&mut str` --> $DIR/transmute.rs:201:32 diff --git a/tests/ui/transmute_64bit.stderr b/tests/ui/transmute_64bit.stderr index 32d7e6bdf421..a30480eb7df0 100644 --- a/tests/ui/transmute_64bit.stderr +++ b/tests/ui/transmute_64bit.stderr @@ -5,6 +5,7 @@ LL | let _: *const usize = std::mem::transmute(6.0f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::wrong-transmute` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wrong_transmute)]` error: transmute from a `f64` to a pointer --> $DIR/transmute_64bit.rs:10:29 diff --git a/tests/ui/transmute_collection.stderr b/tests/ui/transmute_collection.stderr index e4b9963be89b..2163142eef2e 100644 --- a/tests/ui/transmute_collection.stderr +++ b/tests/ui/transmute_collection.stderr @@ -5,6 +5,7 @@ LL | let _ = transmute::<_, Vec>(vec![0u8]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unsound-collection-transmute` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unsound_collection_transmute)]` error: transmute from `std::vec::Vec` to `std::vec::Vec<[u8; 4]>` with mismatched layout is unsound --> $DIR/transmute_collection.rs:13:17 diff --git a/tests/ui/transmute_float_to_int.stderr b/tests/ui/transmute_float_to_int.stderr index dd21c0cde2c4..1895120c0c99 100644 --- a/tests/ui/transmute_float_to_int.stderr +++ b/tests/ui/transmute_float_to_int.stderr @@ -5,6 +5,7 @@ LL | let _: u32 = unsafe { std::mem::transmute(1f32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits()` | = note: `-D clippy::transmute-float-to-int` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_float_to_int)]` error: transmute from a `f32` to a `i32` --> $DIR/transmute_float_to_int.rs:7:27 diff --git a/tests/ui/transmute_int_to_non_zero.stderr b/tests/ui/transmute_int_to_non_zero.stderr index 9efba88f38f6..b79a80c326d8 100644 --- a/tests/ui/transmute_int_to_non_zero.stderr +++ b/tests/ui/transmute_int_to_non_zero.stderr @@ -5,6 +5,7 @@ LL | let _: NonZeroU8 = unsafe { std::mem::transmute(int_u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU8::new_unchecked(int_u8)` | = note: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_non_zero)]` error: transmute from a `u16` to a `NonZeroU16` --> $DIR/transmute_int_to_non_zero.rs:21:34 diff --git a/tests/ui/transmute_null_to_fn.stderr b/tests/ui/transmute_null_to_fn.stderr index 6278f51dde25..ab0ac0dd480b 100644 --- a/tests/ui/transmute_null_to_fn.stderr +++ b/tests/ui/transmute_null_to_fn.stderr @@ -6,6 +6,7 @@ LL | let _: fn() = std::mem::transmute(0 as *const ()); | = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value = note: `-D clippy::transmute-null-to-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_null_to_fn)]` error: transmuting a known null pointer into a function pointer --> $DIR/transmute_null_to_fn.rs:10:23 diff --git a/tests/ui/transmute_ptr_to_ptr.stderr b/tests/ui/transmute_ptr_to_ptr.stderr index ee414e46bb74..564339c067ee 100644 --- a/tests/ui/transmute_ptr_to_ptr.stderr +++ b/tests/ui/transmute_ptr_to_ptr.stderr @@ -5,6 +5,7 @@ LL | let _: *const f32 = std::mem::transmute(ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr as *const f32` | = note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_ptr_to_ptr)]` error: transmute from a pointer to a pointer --> $DIR/transmute_ptr_to_ptr.rs:33:27 diff --git a/tests/ui/transmute_ptr_to_ref.stderr b/tests/ui/transmute_ptr_to_ref.stderr index c63b5524edb4..9d1b22a795b3 100644 --- a/tests/ui/transmute_ptr_to_ref.stderr +++ b/tests/ui/transmute_ptr_to_ref.stderr @@ -5,6 +5,7 @@ LL | let _: &T = std::mem::transmute(p); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*p` | = note: `-D clippy::transmute-ptr-to-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_ptr_to_ref)]` error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`) --> $DIR/transmute_ptr_to_ref.rs:8:21 diff --git a/tests/ui/transmute_undefined_repr.stderr b/tests/ui/transmute_undefined_repr.stderr index 3618213ecd50..f87b1ece9647 100644 --- a/tests/ui/transmute_undefined_repr.stderr +++ b/tests/ui/transmute_undefined_repr.stderr @@ -5,6 +5,7 @@ LL | let _: Ty2C = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::transmute-undefined-repr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_undefined_repr)]` error: transmute into `Ty2` which has an undefined layout --> $DIR/transmute_undefined_repr.rs:33:32 diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.stderr b/tests/ui/transmutes_expressible_as_ptr_casts.stderr index 846b982cdeac..a7988dc4b39b 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.stderr +++ b/tests/ui/transmutes_expressible_as_ptr_casts.stderr @@ -5,6 +5,7 @@ LL | let _ptr_i32_transmute = unsafe { transmute::(usize: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `usize::MAX as *const i32` | = note: `-D clippy::useless-transmute` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::useless_transmute)]` error: transmute from a pointer to a pointer --> $DIR/transmutes_expressible_as_ptr_casts.rs:21:38 @@ -13,6 +14,7 @@ LL | let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as *const i8` | = note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_ptr_to_ptr)]` error: transmute from a pointer to a pointer --> $DIR/transmutes_expressible_as_ptr_casts.rs:27:46 @@ -27,6 +29,7 @@ LL | let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, us | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as usize` | = note: `-D clippy::transmutes-expressible-as-ptr-casts` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmutes_expressible_as_ptr_casts)]` error: transmute from a reference to a pointer --> $DIR/transmutes_expressible_as_ptr_casts.rs:39:41 diff --git a/tests/ui/transmuting_null.stderr b/tests/ui/transmuting_null.stderr index a8de01ec15dc..402de38fe9e2 100644 --- a/tests/ui/transmuting_null.stderr +++ b/tests/ui/transmuting_null.stderr @@ -5,6 +5,7 @@ LL | let _: &u64 = std::mem::transmute(0 as *const u64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::transmuting-null` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmuting_null)]` error: transmuting a known null pointer into a reference --> $DIR/transmuting_null.rs:13:23 diff --git a/tests/ui/trim_split_whitespace.stderr b/tests/ui/trim_split_whitespace.stderr index 0379d79ae986..a1c66eea0d14 100644 --- a/tests/ui/trim_split_whitespace.stderr +++ b/tests/ui/trim_split_whitespace.stderr @@ -5,6 +5,7 @@ LL | let _ = " A B C ".trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` | = note: `-D clippy::trim-split-whitespace` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::trim_split_whitespace)]` error: found call to `str::trim_start` before `str::split_whitespace` --> $DIR/trim_split_whitespace.rs:62:23 diff --git a/tests/ui/tuple_array_conversions.stderr b/tests/ui/tuple_array_conversions.stderr index 70c13d10fd87..f8f5b3e75871 100644 --- a/tests/ui/tuple_array_conversions.stderr +++ b/tests/ui/tuple_array_conversions.stderr @@ -6,6 +6,7 @@ LL | let x = (x[0], x[1]); | = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed = note: `-D clippy::tuple-array-conversions` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::tuple_array_conversions)]` error: it looks like you're trying to convert a tuple to an array --> $DIR/tuple_array_conversions.rs:11:13 diff --git a/tests/ui/type_complexity.stderr b/tests/ui/type_complexity.stderr index 496dacfbfde6..a3cf6ffe9751 100644 --- a/tests/ui/type_complexity.stderr +++ b/tests/ui/type_complexity.stderr @@ -5,6 +5,7 @@ LL | const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::type-complexity` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::type_complexity)]` error: very complex type used. Consider factoring parts into `type` definitions --> $DIR/type_complexity.rs:10:12 diff --git a/tests/ui/type_id_on_box.stderr b/tests/ui/type_id_on_box.stderr index 442f2c6b8477..844dae158b8d 100644 --- a/tests/ui/type_id_on_box.stderr +++ b/tests/ui/type_id_on_box.stderr @@ -9,6 +9,7 @@ LL | let _ = any_box.type_id(); = note: this returns the type id of the literal type `Box` instead of the type id of the boxed value, which is most likely not what you want = note: if this is intentional, use `TypeId::of::>()` instead, which makes it more clear = note: `-D clippy::type-id-on-box` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::type_id_on_box)]` error: calling `.type_id()` on a `Box` --> $DIR/type_id_on_box.rs:28:13 diff --git a/tests/ui/types.stderr b/tests/ui/types.stderr index 0d489f625204..b253cf33867f 100644 --- a/tests/ui/types.stderr +++ b/tests/ui/types.stderr @@ -5,6 +5,7 @@ LL | let c_i64: i64 = c as i64; | ^^^^^^^^ help: try: `i64::from(c)` | = note: `-D clippy::cast-lossless` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` error: aborting due to previous error diff --git a/tests/ui/unchecked_duration_subtraction.stderr b/tests/ui/unchecked_duration_subtraction.stderr index fa47f6ee8062..2b62bc964039 100644 --- a/tests/ui/unchecked_duration_subtraction.stderr +++ b/tests/ui/unchecked_duration_subtraction.stderr @@ -5,6 +5,7 @@ LL | let _ = _first - second; | ^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(second).unwrap()` | = note: `-D clippy::unchecked-duration-subtraction` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unchecked_duration_subtraction)]` error: unchecked subtraction of a 'Duration' from an 'Instant' --> $DIR/unchecked_duration_subtraction.rs:11:13 diff --git a/tests/ui/undocumented_unsafe_blocks.stderr b/tests/ui/undocumented_unsafe_blocks.stderr index ee1d3aa285a2..77f6aea2e0d0 100644 --- a/tests/ui/undocumented_unsafe_blocks.stderr +++ b/tests/ui/undocumented_unsafe_blocks.stderr @@ -6,6 +6,7 @@ LL | /* Safety: */ unsafe {} | = help: consider adding a safety comment on the preceding line = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]` error: unsafe block missing a safety comment --> $DIR/undocumented_unsafe_blocks.rs:266:5 @@ -251,6 +252,7 @@ help: consider removing the safety comment LL | // SAFETY: | ^^^^^^^^^^ = note: `-D clippy::unnecessary-safety-comment` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]` error: unsafe impl missing a safety comment --> $DIR/undocumented_unsafe_blocks.rs:472:5 diff --git a/tests/ui/unicode.stderr b/tests/ui/unicode.stderr index 4f3bad6c0329..0b6e20664e34 100644 --- a/tests/ui/unicode.stderr +++ b/tests/ui/unicode.stderr @@ -5,6 +5,7 @@ LL | print!("Here >​< is a ZWS, and ​another"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >\u{200B}< is a ZWS, and \u{200B}another"` | = note: `-D clippy::invisible-characters` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::invisible_characters)]` error: invisible character detected --> $DIR/unicode.rs:7:12 @@ -25,6 +26,7 @@ LL | print!("̀àh?"); | ^^^^^ help: consider replacing the string with: `"̀àh?"` | = note: `-D clippy::unicode-not-nfc` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unicode_not_nfc)]` error: literal non-ASCII character detected --> $DIR/unicode.rs:23:16 diff --git a/tests/ui/uninit_vec.stderr b/tests/ui/uninit_vec.stderr index 1ffea9f8730d..d39f05839ed9 100644 --- a/tests/ui/uninit_vec.stderr +++ b/tests/ui/uninit_vec.stderr @@ -9,6 +9,7 @@ LL | vec.set_len(200); | = help: initialize the buffer or wrap the content in `MaybeUninit` = note: `-D clippy::uninit-vec` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::uninit_vec)]` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values --> $DIR/uninit_vec.rs:24:5 diff --git a/tests/ui/uninlined_format_args.stderr b/tests/ui/uninlined_format_args.stderr index c73c64873865..829d646b8669 100644 --- a/tests/ui/uninlined_format_args.stderr +++ b/tests/ui/uninlined_format_args.stderr @@ -5,6 +5,7 @@ LL | println!("val='{}'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::uninlined-format-args` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::uninlined_format_args)]` help: change this to | LL - println!("val='{}'", local_i32); diff --git a/tests/ui/uninlined_format_args_panic.edition2018.stderr b/tests/ui/uninlined_format_args_panic.edition2018.stderr index 55a3bd08b319..221efeb50cd9 100644 --- a/tests/ui/uninlined_format_args_panic.edition2018.stderr +++ b/tests/ui/uninlined_format_args_panic.edition2018.stderr @@ -5,6 +5,7 @@ LL | println!("val='{}'", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::uninlined-format-args` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::uninlined_format_args)]` help: change this to | LL - println!("val='{}'", var); diff --git a/tests/ui/uninlined_format_args_panic.edition2021.stderr b/tests/ui/uninlined_format_args_panic.edition2021.stderr index 00e7e8f0ff79..ec1e3a1cf117 100644 --- a/tests/ui/uninlined_format_args_panic.edition2021.stderr +++ b/tests/ui/uninlined_format_args_panic.edition2021.stderr @@ -5,6 +5,7 @@ LL | println!("val='{}'", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::uninlined-format-args` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::uninlined_format_args)]` help: change this to | LL - println!("val='{}'", var); diff --git a/tests/ui/unit_arg.stderr b/tests/ui/unit_arg.stderr index 1de9d44bb0d6..8656c8fddabc 100644 --- a/tests/ui/unit_arg.stderr +++ b/tests/ui/unit_arg.stderr @@ -7,6 +7,7 @@ LL | | }); | |______^ | = note: `-D clippy::unit-arg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unit_arg)]` help: remove the semicolon from the last statement in the block | LL | 1 diff --git a/tests/ui/unit_arg_empty_blocks.stderr b/tests/ui/unit_arg_empty_blocks.stderr index d35e931697d2..b207acb5927d 100644 --- a/tests/ui/unit_arg_empty_blocks.stderr +++ b/tests/ui/unit_arg_empty_blocks.stderr @@ -7,6 +7,7 @@ LL | foo({}); | help: use a unit literal instead: `()` | = note: `-D clippy::unit-arg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unit_arg)]` error: passing a unit value to a function --> $DIR/unit_arg_empty_blocks.rs:17:5 diff --git a/tests/ui/unit_cmp.stderr b/tests/ui/unit_cmp.stderr index 38618c59180c..17355e237978 100644 --- a/tests/ui/unit_cmp.stderr +++ b/tests/ui/unit_cmp.stderr @@ -12,6 +12,7 @@ LL | | } {} | |_____^ | = note: `-D clippy::unit-cmp` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unit_cmp)]` error: >-comparison of unit values detected. This will always be false --> $DIR/unit_cmp.rs:25:8 diff --git a/tests/ui/unit_hash.stderr b/tests/ui/unit_hash.stderr index eeb48cf7f37f..a26fd734413c 100644 --- a/tests/ui/unit_hash.stderr +++ b/tests/ui/unit_hash.stderr @@ -6,6 +6,7 @@ LL | Foo::Empty => ().hash(&mut state), | = note: the implementation of `Hash` for `()` is a no-op = note: `-D clippy::unit-hash` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unit_hash)]` error: this call to `hash` on the unit type will do nothing --> $DIR/unit_hash.rs:26:5 diff --git a/tests/ui/unit_return_expecting_ord.stderr b/tests/ui/unit_return_expecting_ord.stderr index 74e6d6b12629..9220fb89e901 100644 --- a/tests/ui/unit_return_expecting_ord.stderr +++ b/tests/ui/unit_return_expecting_ord.stderr @@ -10,6 +10,7 @@ help: probably caused by this trailing semicolon LL | double(s.field); | ^ = note: `-D clippy::unit-return-expecting-ord` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unit_return_expecting_ord)]` error: this closure returns the unit type which also implements PartialOrd --> $DIR/unit_return_expecting_ord.rs:24:30 diff --git a/tests/ui/unknown_clippy_lints.stderr b/tests/ui/unknown_clippy_lints.stderr index d478df8056b5..ee82db31c2c2 100644 --- a/tests/ui/unknown_clippy_lints.stderr +++ b/tests/ui/unknown_clippy_lints.stderr @@ -5,6 +5,7 @@ LL | #![allow(clippy::All)] | ^^^^^^^^^^^ help: did you mean: `clippy::all` | = note: `-D unknown-lints` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(unknown_lints)]` error: unknown lint: `clippy::CMP_OWNED` --> $DIR/unknown_clippy_lints.rs:4:9 diff --git a/tests/ui/unnecessary_box_returns.stderr b/tests/ui/unnecessary_box_returns.stderr index 8909dbcdd985..944e911fa944 100644 --- a/tests/ui/unnecessary_box_returns.stderr +++ b/tests/ui/unnecessary_box_returns.stderr @@ -6,6 +6,7 @@ LL | fn baz(&self) -> Box; | = help: changing this also requires a change to the return expressions in this function = note: `-D clippy::unnecessary-box-returns` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_box_returns)]` error: boxed return of the sized type `usize` --> $DIR/unnecessary_box_returns.rs:19:22 diff --git a/tests/ui/unnecessary_cast.stderr b/tests/ui/unnecessary_cast.stderr index 69bbcdf74071..d4786f66e447 100644 --- a/tests/ui/unnecessary_cast.stderr +++ b/tests/ui/unnecessary_cast.stderr @@ -5,6 +5,7 @@ LL | ptr as *const T | ^^^^^^^^^^^^^^^ help: try: `ptr` | = note: `-D clippy::unnecessary-cast` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_cast)]` error: casting integer literal to `i32` is unnecessary --> $DIR/unnecessary_cast.rs:53:5 diff --git a/tests/ui/unnecessary_cast_unfixable.stderr b/tests/ui/unnecessary_cast_unfixable.stderr index ef3632db9f1d..2d38a2a7709c 100644 --- a/tests/ui/unnecessary_cast_unfixable.stderr +++ b/tests/ui/unnecessary_cast_unfixable.stderr @@ -5,6 +5,7 @@ LL | let _ = std::ptr::null() as *const u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::null()` | = note: `-D clippy::unnecessary-cast` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_cast)]` error: casting raw pointers to the same type and constness is unnecessary (`*mut issue11113::Vtbl` -> `*mut issue11113::Vtbl`) --> $DIR/unnecessary_cast_unfixable.rs:21:16 diff --git a/tests/ui/unnecessary_clone.stderr b/tests/ui/unnecessary_clone.stderr index da387e8bb7c3..eab5f0423165 100644 --- a/tests/ui/unnecessary_clone.stderr +++ b/tests/ui/unnecessary_clone.stderr @@ -5,6 +5,7 @@ LL | rc.clone(); | ^^^^^^^^^^ help: try: `Rc::::clone(&rc)` | = note: `-D clippy::clone-on-ref-ptr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::clone_on_ref_ptr)]` error: using `.clone()` on a ref-counted pointer --> $DIR/unnecessary_clone.rs:28:5 @@ -37,6 +38,7 @@ LL | t.clone(); | ^^^^^^^^^ help: try removing the `clone` call: `t` | = note: `-D clippy::clone-on-copy` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::clone_on_copy)]` error: using `clone` on type `Option` which implements the `Copy` trait --> $DIR/unnecessary_clone.rs:50:5 diff --git a/tests/ui/unnecessary_filter_map.stderr b/tests/ui/unnecessary_filter_map.stderr index f34acdc8d7e6..0dd65f652724 100644 --- a/tests/ui/unnecessary_filter_map.stderr +++ b/tests/ui/unnecessary_filter_map.stderr @@ -5,6 +5,7 @@ LL | let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unnecessary-filter-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_filter_map)]` error: this `.filter_map` can be written more simply using `.filter` --> $DIR/unnecessary_filter_map.rs:7:13 diff --git a/tests/ui/unnecessary_find_map.stderr b/tests/ui/unnecessary_find_map.stderr index 9acbd6650024..662623fb6179 100644 --- a/tests/ui/unnecessary_find_map.stderr +++ b/tests/ui/unnecessary_find_map.stderr @@ -5,6 +5,7 @@ LL | let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unnecessary-find-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_find_map)]` error: this `.find_map` can be written more simply using `.find` --> $DIR/unnecessary_find_map.rs:7:13 diff --git a/tests/ui/unnecessary_fold.stderr b/tests/ui/unnecessary_fold.stderr index 10920470c1ad..f0d039638421 100644 --- a/tests/ui/unnecessary_fold.stderr +++ b/tests/ui/unnecessary_fold.stderr @@ -5,6 +5,7 @@ LL | let _ = (0..3).fold(false, |acc, x| acc || x > 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `any(|x| x > 2)` | = note: `-D clippy::unnecessary-fold` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_fold)]` error: this `.fold` can be written more succinctly using another method --> $DIR/unnecessary_fold.rs:8:20 diff --git a/tests/ui/unnecessary_iter_cloned.stderr b/tests/ui/unnecessary_iter_cloned.stderr index e9df5afa6b9f..ba40c6c14db2 100644 --- a/tests/ui/unnecessary_iter_cloned.stderr +++ b/tests/ui/unnecessary_iter_cloned.stderr @@ -5,6 +5,7 @@ LL | for (t, path) in files.iter().copied() { | ^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unnecessary-to-owned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_to_owned)]` help: use | LL | for (t, path) in files { diff --git a/tests/ui/unnecessary_join.stderr b/tests/ui/unnecessary_join.stderr index 80e5bc63a65e..8bf2ac5fdb1d 100644 --- a/tests/ui/unnecessary_join.stderr +++ b/tests/ui/unnecessary_join.stderr @@ -7,6 +7,7 @@ LL | | .join(""); | |_________________^ help: try using: `collect::()` | = note: `-D clippy::unnecessary-join` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_join)]` error: called `.collect::>().join("")` on an iterator --> $DIR/unnecessary_join.rs:19:10 diff --git a/tests/ui/unnecessary_lazy_eval.stderr b/tests/ui/unnecessary_lazy_eval.stderr index 2850a632fc77..4f1ca3748728 100644 --- a/tests/ui/unnecessary_lazy_eval.stderr +++ b/tests/ui/unnecessary_lazy_eval.stderr @@ -7,6 +7,7 @@ LL | let _ = opt.unwrap_or_else(|| 2); | help: use `unwrap_or(..)` instead: `unwrap_or(2)` | = note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_lazy_evaluations)]` error: unnecessary closure used to substitute value for `Option::None` --> $DIR/unnecessary_lazy_eval.rs:69:13 diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.stderr b/tests/ui/unnecessary_lazy_eval_unfixable.stderr index 8bff2a637793..27fa560d4d77 100644 --- a/tests/ui/unnecessary_lazy_eval_unfixable.stderr +++ b/tests/ui/unnecessary_lazy_eval_unfixable.stderr @@ -7,6 +7,7 @@ LL | let _ = Ok(1).unwrap_or_else(|()| 2); | help: use `unwrap_or(..)` instead: `unwrap_or(2)` | = note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_lazy_evaluations)]` error: unnecessary closure used to substitute value for `Result::Err` --> $DIR/unnecessary_lazy_eval_unfixable.rs:19:13 diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr index eae74f569508..013907f59c46 100644 --- a/tests/ui/unnecessary_literal_unwrap.stderr +++ b/tests/ui/unnecessary_literal_unwrap.stderr @@ -5,6 +5,7 @@ LL | let _val = Some(1).unwrap(); | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::unnecessary-literal-unwrap` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_literal_unwrap)]` help: remove the `Some` and `unwrap()` | LL - let _val = Some(1).unwrap(); diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr index 2a60896c0a3c..c6ecd6de61ea 100644 --- a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr +++ b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr @@ -10,6 +10,7 @@ help: remove the `Some` and `unwrap()` LL | let val = Some(1); | ^^^^^^^ = note: `-D clippy::unnecessary-literal-unwrap` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_literal_unwrap)]` error: used `expect()` on `Some` value --> $DIR/unnecessary_literal_unwrap_unfixable.rs:9:17 diff --git a/tests/ui/unnecessary_operation.stderr b/tests/ui/unnecessary_operation.stderr index d71aa60d4cc1..fbe495f518fa 100644 --- a/tests/ui/unnecessary_operation.stderr +++ b/tests/ui/unnecessary_operation.stderr @@ -5,6 +5,7 @@ LL | Tuple(get_number()); | ^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` | = note: `-D clippy::unnecessary-operation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_operation)]` error: unnecessary operation --> $DIR/unnecessary_operation.rs:55:5 diff --git a/tests/ui/unnecessary_owned_empty_strings.stderr b/tests/ui/unnecessary_owned_empty_strings.stderr index 2cfed265adf8..58d925b1096d 100644 --- a/tests/ui/unnecessary_owned_empty_strings.stderr +++ b/tests/ui/unnecessary_owned_empty_strings.stderr @@ -5,6 +5,7 @@ LL | ref_str_argument(&String::new()); | ^^^^^^^^^^^^^^ help: try: `""` | = note: `-D clippy::unnecessary-owned-empty-strings` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_owned_empty_strings)]` error: usage of `&String::from("")` for a function expecting a `&str` argument --> $DIR/unnecessary_owned_empty_strings.rs:14:22 diff --git a/tests/ui/unnecessary_safety_comment.stderr b/tests/ui/unnecessary_safety_comment.stderr index d97048e27036..6d4ef6c308db 100644 --- a/tests/ui/unnecessary_safety_comment.stderr +++ b/tests/ui/unnecessary_safety_comment.stderr @@ -10,6 +10,7 @@ help: consider removing the safety comment LL | // SAFETY: | ^^^^^^^^^^ = note: `-D clippy::unnecessary-safety-comment` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]` error: static item has unnecessary safety comment --> $DIR/unnecessary_safety_comment.rs:9:5 diff --git a/tests/ui/unnecessary_self_imports.stderr b/tests/ui/unnecessary_self_imports.stderr index 412674a85ec7..4e50aaececf9 100644 --- a/tests/ui/unnecessary_self_imports.stderr +++ b/tests/ui/unnecessary_self_imports.stderr @@ -8,6 +8,7 @@ LL | use std::fs::{self as alias}; | = note: this will slightly change semantics; any non-module items at the same path will also be imported = note: `-D clippy::unnecessary-self-imports` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_self_imports)]` error: import ending with `::{self}` --> $DIR/unnecessary_self_imports.rs:7:1 diff --git a/tests/ui/unnecessary_sort_by.stderr b/tests/ui/unnecessary_sort_by.stderr index 55d681487b66..9d54c8d50e31 100644 --- a/tests/ui/unnecessary_sort_by.stderr +++ b/tests/ui/unnecessary_sort_by.stderr @@ -5,6 +5,7 @@ LL | vec.sort_by(|a, b| a.cmp(b)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort()` | = note: `-D clippy::unnecessary-sort-by` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_sort_by)]` error: use Vec::sort here instead --> $DIR/unnecessary_sort_by.rs:13:5 diff --git a/tests/ui/unnecessary_struct_initialization.stderr b/tests/ui/unnecessary_struct_initialization.stderr index 5311415d166d..d8e0ce6ccaf2 100644 --- a/tests/ui/unnecessary_struct_initialization.stderr +++ b/tests/ui/unnecessary_struct_initialization.stderr @@ -5,6 +5,7 @@ LL | Self { ..*self } | ^^^^^^^^^^^^^^^^ help: replace with: `*self` | = note: `-D clippy::unnecessary-struct-initialization` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_struct_initialization)]` error: unnecessary struct building --> $DIR/unnecessary_struct_initialization.rs:39:17 diff --git a/tests/ui/unnecessary_to_owned.stderr b/tests/ui/unnecessary_to_owned.stderr index b5d009ae1dd5..d8971b51dcad 100644 --- a/tests/ui/unnecessary_to_owned.stderr +++ b/tests/ui/unnecessary_to_owned.stderr @@ -10,6 +10,7 @@ note: this value is dropped without further use LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::redundant-clone` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]` error: redundant clone --> $DIR/unnecessary_to_owned.rs:149:40 @@ -66,6 +67,7 @@ LL | require_c_str(&Cow::from(c_str).into_owned()); | ^^^^^^^^^^^^^ help: remove this | = note: `-D clippy::unnecessary-to-owned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_to_owned)]` error: unnecessary use of `to_owned` --> $DIR/unnecessary_to_owned.rs:58:19 diff --git a/tests/ui/unnecessary_unsafety_doc.stderr b/tests/ui/unnecessary_unsafety_doc.stderr index b0f20fdac5fa..817eb3e26eed 100644 --- a/tests/ui/unnecessary_unsafety_doc.stderr +++ b/tests/ui/unnecessary_unsafety_doc.stderr @@ -5,6 +5,7 @@ LL | pub fn apocalypse(universe: &mut ()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unnecessary-safety-doc` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_doc)]` error: safe function's docs have unnecessary `# Safety` section --> $DIR/unnecessary_unsafety_doc.rs:45:5 diff --git a/tests/ui/unnecessary_wraps.stderr b/tests/ui/unnecessary_wraps.stderr index 01340a0abddf..20d3e070e71c 100644 --- a/tests/ui/unnecessary_wraps.stderr +++ b/tests/ui/unnecessary_wraps.stderr @@ -11,6 +11,7 @@ LL | | } | |_^ | = note: `-D clippy::unnecessary-wraps` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_wraps)]` help: remove `Option` from the return type... | LL | fn func1(a: bool, b: bool) -> i32 { diff --git a/tests/ui/unneeded_field_pattern.stderr b/tests/ui/unneeded_field_pattern.stderr index 3f15684986fe..68b433df8aaa 100644 --- a/tests/ui/unneeded_field_pattern.stderr +++ b/tests/ui/unneeded_field_pattern.stderr @@ -6,6 +6,7 @@ LL | Foo { a: _, b: 0, .. } => {}, | = help: try with `Foo { b: 0, .. }` = note: `-D clippy::unneeded-field-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unneeded_field_pattern)]` error: all the struct fields are matched to a wildcard pattern, consider using `..` --> $DIR/unneeded_field_pattern.rs:20:9 diff --git a/tests/ui/unnested_or_patterns.stderr b/tests/ui/unnested_or_patterns.stderr index 9e4f0d45d80a..98ca7e373567 100644 --- a/tests/ui/unnested_or_patterns.stderr +++ b/tests/ui/unnested_or_patterns.stderr @@ -5,6 +5,7 @@ LL | if let box 0 | box 2 = Box::new(0) {} | ^^^^^^^^^^^^^ | = note: `-D clippy::unnested-or-patterns` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnested_or_patterns)]` help: nest the patterns | LL | if let box (0 | 2) = Box::new(0) {} diff --git a/tests/ui/unnested_or_patterns2.stderr b/tests/ui/unnested_or_patterns2.stderr index afb3100a552b..182ae00de220 100644 --- a/tests/ui/unnested_or_patterns2.stderr +++ b/tests/ui/unnested_or_patterns2.stderr @@ -5,6 +5,7 @@ LL | if let Some(Some(0)) | Some(Some(1)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unnested-or-patterns` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnested_or_patterns)]` help: nest the patterns | LL | if let Some(Some(0 | 1)) = None {} diff --git a/tests/ui/unreadable_literal.stderr b/tests/ui/unreadable_literal.stderr index b75aa75a336d..d7a3377ec37d 100644 --- a/tests/ui/unreadable_literal.stderr +++ b/tests/ui/unreadable_literal.stderr @@ -5,6 +5,7 @@ LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^^^ help: consider: `0b11_0110_i64` | = note: `-D clippy::unreadable-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unreadable_literal)]` error: long literal lacking separators --> $DIR/unreadable_literal.rs:32:31 diff --git a/tests/ui/unsafe_derive_deserialize.stderr b/tests/ui/unsafe_derive_deserialize.stderr index 7b96500fd115..d6fb82398d87 100644 --- a/tests/ui/unsafe_derive_deserialize.stderr +++ b/tests/ui/unsafe_derive_deserialize.stderr @@ -6,6 +6,7 @@ LL | #[derive(Deserialize)] | = help: consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html = note: `-D clippy::unsafe-derive-deserialize` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unsafe_derive_deserialize)]` = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` diff --git a/tests/ui/unsafe_removed_from_name.stderr b/tests/ui/unsafe_removed_from_name.stderr index 5daa69e1fb4d..261c7837a4c1 100644 --- a/tests/ui/unsafe_removed_from_name.stderr +++ b/tests/ui/unsafe_removed_from_name.stderr @@ -5,6 +5,7 @@ LL | use std::cell::UnsafeCell as TotallySafeCell; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unsafe-removed-from-name` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unsafe_removed_from_name)]` error: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCellAgain` --> $DIR/unsafe_removed_from_name.rs:9:1 diff --git a/tests/ui/unseparated_prefix_literals.stderr b/tests/ui/unseparated_prefix_literals.stderr index a0c0be7a9d15..d74e72875057 100644 --- a/tests/ui/unseparated_prefix_literals.stderr +++ b/tests/ui/unseparated_prefix_literals.stderr @@ -5,6 +5,7 @@ LL | let _fail1 = 1234i32; | ^^^^^^^ help: add an underscore: `1234_i32` | = note: `-D clippy::unseparated-literal-suffix` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unseparated_literal_suffix)]` error: integer type suffix should be separated by an underscore --> $DIR/unseparated_prefix_literals.rs:24:18 diff --git a/tests/ui/unused_async.stderr b/tests/ui/unused_async.stderr index 06944f8f8d8d..077e8cacce14 100644 --- a/tests/ui/unused_async.stderr +++ b/tests/ui/unused_async.stderr @@ -16,6 +16,7 @@ note: `await` used in an async block, which does not require the enclosing funct LL | ready(()).await; | ^^^^^ = note: `-D clippy::unused-async` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unused_async)]` error: unused `async` for function with no await statements --> $DIR/unused_async.rs:46:5 diff --git a/tests/ui/unused_format_specs_unfixable.stderr b/tests/ui/unused_format_specs_unfixable.stderr index e9145ff382a7..183e80c853c6 100644 --- a/tests/ui/unused_format_specs_unfixable.stderr +++ b/tests/ui/unused_format_specs_unfixable.stderr @@ -5,6 +5,7 @@ LL | println!("{:5}.", format_args!("")); | ^^^^ | = note: `-D clippy::unused-format-specs` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unused_format_specs)]` help: for the width to apply consider using `format!()` | LL | println!("{:5}.", format!("")); diff --git a/tests/ui/unused_io_amount.stderr b/tests/ui/unused_io_amount.stderr index c729a0b90166..f9aef596a1c9 100644 --- a/tests/ui/unused_io_amount.stderr +++ b/tests/ui/unused_io_amount.stderr @@ -6,6 +6,7 @@ LL | s.write(b"test")?; | = help: use `Write::write_all` instead, or handle partial writes = note: `-D clippy::unused-io-amount` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unused_io_amount)]` error: read amount is not handled --> $DIR/unused_io_amount.rs:12:5 diff --git a/tests/ui/unused_peekable.stderr b/tests/ui/unused_peekable.stderr index 896ca49d710c..157d6fc15f2f 100644 --- a/tests/ui/unused_peekable.stderr +++ b/tests/ui/unused_peekable.stderr @@ -6,6 +6,7 @@ LL | let peekable = std::iter::empty::().peekable(); | = help: consider removing the call to `peekable` = note: `-D clippy::unused-peekable` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unused_peekable)]` error: `peek` never called on `Peekable` iterator --> $DIR/unused_peekable.rs:18:9 diff --git a/tests/ui/unused_rounding.stderr b/tests/ui/unused_rounding.stderr index 163f78982eef..d6ce27351353 100644 --- a/tests/ui/unused_rounding.stderr +++ b/tests/ui/unused_rounding.stderr @@ -5,6 +5,7 @@ LL | let _ = 1f32.ceil(); | ^^^^^^^^^^^ help: remove the `ceil` method call: `1f32` | = note: `-D clippy::unused-rounding` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unused_rounding)]` error: used the `floor` method with a whole number float --> $DIR/unused_rounding.rs:5:13 diff --git a/tests/ui/unused_self.stderr b/tests/ui/unused_self.stderr index 5cf15c00b1b6..3865095bbfeb 100644 --- a/tests/ui/unused_self.stderr +++ b/tests/ui/unused_self.stderr @@ -6,6 +6,7 @@ LL | fn unused_self_move(self) {} | = help: consider refactoring to an associated function = note: `-D clippy::unused-self` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unused_self)]` error: unused `self` argument --> $DIR/unused_self.rs:13:28 diff --git a/tests/ui/unwrap.stderr b/tests/ui/unwrap.stderr index 38904858a323..25911ded2fb3 100644 --- a/tests/ui/unwrap.stderr +++ b/tests/ui/unwrap.stderr @@ -7,6 +7,7 @@ LL | let _ = opt.unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message = note: `-D clippy::unwrap-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` error: used `unwrap()` on a `Result` value --> $DIR/unwrap.rs:12:13 diff --git a/tests/ui/unwrap_expect_used.stderr b/tests/ui/unwrap_expect_used.stderr index 0b43f5727455..cbe6ea22e899 100644 --- a/tests/ui/unwrap_expect_used.stderr +++ b/tests/ui/unwrap_expect_used.stderr @@ -6,6 +6,7 @@ LL | Some(3).unwrap(); | = note: if this value is `None`, it will panic = note: `-D clippy::unwrap-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` error: used `expect()` on an `Option` value --> $DIR/unwrap_expect_used.rs:29:5 @@ -15,6 +16,7 @@ LL | Some(3).expect("Hello world!"); | = note: if this value is `None`, it will panic = note: `-D clippy::expect-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::expect_used)]` error: used `unwrap()` on a `Result` value --> $DIR/unwrap_expect_used.rs:45:5 diff --git a/tests/ui/unwrap_in_result.stderr b/tests/ui/unwrap_in_result.stderr index a394da272a86..9a0a32d471e3 100644 --- a/tests/ui/unwrap_in_result.stderr +++ b/tests/ui/unwrap_in_result.stderr @@ -17,6 +17,7 @@ note: potential non-recoverable error(s) LL | let i = i_str.parse::().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::unwrap-in-result` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unwrap_in_result)]` error: used unwrap or expect in a function that returns result or option --> $DIR/unwrap_in_result.rs:33:5 diff --git a/tests/ui/unwrap_or.stderr b/tests/ui/unwrap_or.stderr index 8992092bc58f..3a32092f7be1 100644 --- a/tests/ui/unwrap_or.stderr +++ b/tests/ui/unwrap_or.stderr @@ -5,6 +5,7 @@ LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| "Fail".to_string())` | = note: `-D clippy::or-fun-call` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::or_fun_call)]` error: use of `unwrap_or` followed by a function call --> $DIR/unwrap_or.rs:11:47 diff --git a/tests/ui/unwrap_or_else_default.stderr b/tests/ui/unwrap_or_else_default.stderr index 40023cf3b668..3119aba19e8f 100644 --- a/tests/ui/unwrap_or_else_default.stderr +++ b/tests/ui/unwrap_or_else_default.stderr @@ -5,6 +5,7 @@ LL | with_new.unwrap_or_else(Vec::new); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` | = note: `-D clippy::unwrap-or-default` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unwrap_or_default)]` error: use of `unwrap_or_else` to construct default value --> $DIR/unwrap_or_else_default.rs:60:23 diff --git a/tests/ui/upper_case_acronyms.stderr b/tests/ui/upper_case_acronyms.stderr index 9be1bb304ece..c57b325e91a6 100644 --- a/tests/ui/upper_case_acronyms.stderr +++ b/tests/ui/upper_case_acronyms.stderr @@ -5,6 +5,7 @@ LL | CWR, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Cwr` | = note: `-D clippy::upper-case-acronyms` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::upper_case_acronyms)]` error: name `ECE` contains a capitalized acronym --> $DIR/upper_case_acronyms.rs:12:5 diff --git a/tests/ui/use_self.stderr b/tests/ui/use_self.stderr index 0e6ae5d451ba..a1d4eac5dc09 100644 --- a/tests/ui/use_self.stderr +++ b/tests/ui/use_self.stderr @@ -5,6 +5,7 @@ LL | fn new() -> Foo { | ^^^ help: use the applicable keyword: `Self` | = note: `-D clippy::use-self` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::use_self)]` error: unnecessary structure name repetition --> $DIR/use_self.rs:22:13 diff --git a/tests/ui/use_self_trait.stderr b/tests/ui/use_self_trait.stderr index 301d78e6c1ec..71a227174eaf 100644 --- a/tests/ui/use_self_trait.stderr +++ b/tests/ui/use_self_trait.stderr @@ -5,6 +5,7 @@ LL | fn refs(p1: &Bad) -> &Bad { | ^^^ help: use the applicable keyword: `Self` | = note: `-D clippy::use-self` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::use_self)]` error: unnecessary structure name repetition --> $DIR/use_self_trait.rs:19:27 diff --git a/tests/ui/used_underscore_binding.stderr b/tests/ui/used_underscore_binding.stderr index 875fafe438a1..289519b172ee 100644 --- a/tests/ui/used_underscore_binding.stderr +++ b/tests/ui/used_underscore_binding.stderr @@ -5,6 +5,7 @@ LL | _foo + 1 | ^^^^ | = note: `-D clippy::used-underscore-binding` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::used_underscore_binding)]` error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used --> $DIR/used_underscore_binding.rs:29:20 diff --git a/tests/ui/useless_attribute.stderr b/tests/ui/useless_attribute.stderr index 8bb7b2d3d9ed..e65c59abaf88 100644 --- a/tests/ui/useless_attribute.stderr +++ b/tests/ui/useless_attribute.stderr @@ -5,6 +5,7 @@ LL | #[allow(dead_code)] | ^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(dead_code)]` | = note: `-D clippy::useless-attribute` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::useless_attribute)]` error: useless lint attribute --> $DIR/useless_attribute.rs:9:1 diff --git a/tests/ui/vec.stderr b/tests/ui/vec.stderr index 5cd6d9fa8c7e..a28024d236a1 100644 --- a/tests/ui/vec.stderr +++ b/tests/ui/vec.stderr @@ -5,6 +5,7 @@ LL | on_slice(&vec![]); | ^^^^^^^ help: you can use a slice directly: `&[]` | = note: `-D clippy::useless-vec` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::useless_vec)]` error: useless use of `vec!` --> $DIR/vec.rs:32:18 diff --git a/tests/ui/vec_box_sized.stderr b/tests/ui/vec_box_sized.stderr index 78e00f5661b4..9118f284bb97 100644 --- a/tests/ui/vec_box_sized.stderr +++ b/tests/ui/vec_box_sized.stderr @@ -5,6 +5,7 @@ LL | const C: Vec> = Vec::new(); | ^^^^^^^^^^^^^ help: try: `Vec` | = note: `-D clippy::vec-box` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::vec_box)]` error: `Vec` is already on the heap, the boxing is unnecessary --> $DIR/vec_box_sized.rs:11:15 diff --git a/tests/ui/vec_init_then_push.stderr b/tests/ui/vec_init_then_push.stderr index 9ad793d979b7..978201bd17aa 100644 --- a/tests/ui/vec_init_then_push.stderr +++ b/tests/ui/vec_init_then_push.stderr @@ -8,6 +8,7 @@ LL | | def_err.push(0); | |____________________^ help: consider using the `vec![]` macro: `let def_err: Vec = vec![..];` | = note: `-D clippy::vec-init-then-push` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::vec_init_then_push)]` error: calls to `push` immediately after creation --> $DIR/vec_init_then_push.rs:10:5 diff --git a/tests/ui/vec_resize_to_zero.stderr b/tests/ui/vec_resize_to_zero.stderr index 8851e9f38be4..715c9923b2e5 100644 --- a/tests/ui/vec_resize_to_zero.stderr +++ b/tests/ui/vec_resize_to_zero.stderr @@ -8,6 +8,7 @@ LL | v.resize(0, 5); | = help: the arguments may be inverted... = note: `-D clippy::vec-resize-to-zero` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::vec_resize_to_zero)]` error: aborting due to previous error diff --git a/tests/ui/verbose_file_reads.stderr b/tests/ui/verbose_file_reads.stderr index 592a7984305d..04e1aedf7c5a 100644 --- a/tests/ui/verbose_file_reads.stderr +++ b/tests/ui/verbose_file_reads.stderr @@ -6,6 +6,7 @@ LL | f.read_to_end(&mut buffer)?; | = help: consider using `fs::read` instead = note: `-D clippy::verbose-file-reads` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::verbose_file_reads)]` error: use of `File::read_to_string` --> $DIR/verbose_file_reads.rs:27:5 diff --git a/tests/ui/vtable_address_comparisons.stderr b/tests/ui/vtable_address_comparisons.stderr index 91490afce362..83c82f3796eb 100644 --- a/tests/ui/vtable_address_comparisons.stderr +++ b/tests/ui/vtable_address_comparisons.stderr @@ -6,6 +6,7 @@ LL | let _ = a == b; | = help: consider extracting and comparing data pointers only = note: `-D clippy::vtable-address-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::vtable_address_comparisons)]` error: comparing trait object pointers compares a non-unique vtable address --> $DIR/vtable_address_comparisons.rs:16:13 diff --git a/tests/ui/while_let_loop.stderr b/tests/ui/while_let_loop.stderr index 00411172141c..db887dc65c6a 100644 --- a/tests/ui/while_let_loop.stderr +++ b/tests/ui/while_let_loop.stderr @@ -11,6 +11,7 @@ LL | | } | |_____^ help: try: `while let Some(_x) = y { .. }` | = note: `-D clippy::while-let-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::while_let_loop)]` error: this loop could be written as a `while let` loop --> $DIR/while_let_loop.rs:25:5 diff --git a/tests/ui/while_let_on_iterator.stderr b/tests/ui/while_let_on_iterator.stderr index f8a66f2ad3e9..cdc83b816670 100644 --- a/tests/ui/while_let_on_iterator.stderr +++ b/tests/ui/while_let_on_iterator.stderr @@ -5,6 +5,7 @@ LL | while let Option::Some(x) = iter.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter` | = note: `-D clippy::while-let-on-iterator` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::while_let_on_iterator)]` error: this loop could be written as a `for` loop --> $DIR/while_let_on_iterator.rs:20:5 diff --git a/tests/ui/wild_in_or_pats.stderr b/tests/ui/wild_in_or_pats.stderr index 5d9ab78bbb4d..4cfa0d99350d 100644 --- a/tests/ui/wild_in_or_pats.stderr +++ b/tests/ui/wild_in_or_pats.stderr @@ -6,6 +6,7 @@ LL | "bar" | _ => { | = help: consider handling `_` separately = note: `-D clippy::wildcard-in-or-patterns` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wildcard_in_or_patterns)]` error: wildcard pattern covers any other pattern as it will match anyway --> $DIR/wild_in_or_pats.rs:17:9 diff --git a/tests/ui/wildcard_imports.stderr b/tests/ui/wildcard_imports.stderr index f7baf234c2f8..3c750815bafc 100644 --- a/tests/ui/wildcard_imports.stderr +++ b/tests/ui/wildcard_imports.stderr @@ -5,6 +5,7 @@ LL | use crate::fn_mod::*; | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` | = note: `-D clippy::wildcard-imports` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]` error: usage of wildcard import --> $DIR/wildcard_imports.rs:16:5 diff --git a/tests/ui/wildcard_imports_2021.edition2018.stderr b/tests/ui/wildcard_imports_2021.edition2018.stderr index af9ae6e786c9..709a665d65c2 100644 --- a/tests/ui/wildcard_imports_2021.edition2018.stderr +++ b/tests/ui/wildcard_imports_2021.edition2018.stderr @@ -5,6 +5,7 @@ LL | use crate::fn_mod::*; | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` | = note: `-D clippy::wildcard-imports` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]` error: usage of wildcard import --> $DIR/wildcard_imports_2021.rs:14:5 diff --git a/tests/ui/wildcard_imports_2021.edition2021.stderr b/tests/ui/wildcard_imports_2021.edition2021.stderr index af9ae6e786c9..709a665d65c2 100644 --- a/tests/ui/wildcard_imports_2021.edition2021.stderr +++ b/tests/ui/wildcard_imports_2021.edition2021.stderr @@ -5,6 +5,7 @@ LL | use crate::fn_mod::*; | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` | = note: `-D clippy::wildcard-imports` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]` error: usage of wildcard import --> $DIR/wildcard_imports_2021.rs:14:5 diff --git a/tests/ui/write_literal.stderr b/tests/ui/write_literal.stderr index f0a09074bc65..372a54cf769f 100644 --- a/tests/ui/write_literal.stderr +++ b/tests/ui/write_literal.stderr @@ -5,6 +5,7 @@ LL | write!(v, "Hello {}", "world"); | ^^^^^^^ | = note: `-D clippy::write-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::write_literal)]` help: try | LL - write!(v, "Hello {}", "world"); diff --git a/tests/ui/write_literal_2.stderr b/tests/ui/write_literal_2.stderr index 84b302d8d3b4..fc24dba45437 100644 --- a/tests/ui/write_literal_2.stderr +++ b/tests/ui/write_literal_2.stderr @@ -5,6 +5,7 @@ LL | writeln!(v, r"{}", r"{hello}"); | ^^^^^^^^^^ help: try: `"{hello}"` | = note: `-D clippy::needless-raw-strings` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_raw_strings)]` error: literal with an empty format string --> $DIR/write_literal_2.rs:10:23 @@ -13,6 +14,7 @@ LL | writeln!(v, "{}", "{hello}"); | ^^^^^^^^^ | = note: `-D clippy::write-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::write_literal)]` help: try | LL - writeln!(v, "{}", "{hello}"); diff --git a/tests/ui/write_with_newline.stderr b/tests/ui/write_with_newline.stderr index d84d57d84f5b..78874ffadc0b 100644 --- a/tests/ui/write_with_newline.stderr +++ b/tests/ui/write_with_newline.stderr @@ -5,6 +5,7 @@ LL | write!(v, "Hello\n"); | ^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::write-with-newline` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::write_with_newline)]` help: use `writeln!` instead | LL - write!(v, "Hello\n"); diff --git a/tests/ui/writeln_empty_string.stderr b/tests/ui/writeln_empty_string.stderr index 93e1af5a4ec4..037475543617 100644 --- a/tests/ui/writeln_empty_string.stderr +++ b/tests/ui/writeln_empty_string.stderr @@ -7,6 +7,7 @@ LL | writeln!(v, ""); | help: remove the empty string | = note: `-D clippy::writeln-empty-string` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::writeln_empty_string)]` error: empty string literal in `writeln!` --> $DIR/writeln_empty_string.rs:12:5 diff --git a/tests/ui/wrong_self_convention.stderr b/tests/ui/wrong_self_convention.stderr index 2d52b64c8127..9f457b50ce77 100644 --- a/tests/ui/wrong_self_convention.stderr +++ b/tests/ui/wrong_self_convention.stderr @@ -6,6 +6,7 @@ LL | fn from_i32(self) {} | = help: consider choosing a less ambiguous name = note: `-D clippy::wrong-self-convention` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wrong_self_convention)]` error: methods called `from_*` usually take no `self` --> $DIR/wrong_self_convention.rs:23:21 diff --git a/tests/ui/wrong_self_convention2.stderr b/tests/ui/wrong_self_convention2.stderr index 0069059203bf..dc12a844332e 100644 --- a/tests/ui/wrong_self_convention2.stderr +++ b/tests/ui/wrong_self_convention2.stderr @@ -6,6 +6,7 @@ LL | pub fn from_be_self(self) -> Self { | = help: consider choosing a less ambiguous name = note: `-D clippy::wrong-self-convention` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wrong_self_convention)]` error: methods called `from_*` usually take no `self` --> $DIR/wrong_self_convention2.rs:64:25 diff --git a/tests/ui/wrong_self_conventions_mut.stderr b/tests/ui/wrong_self_conventions_mut.stderr index cd7a9aae144e..21255287d722 100644 --- a/tests/ui/wrong_self_conventions_mut.stderr +++ b/tests/ui/wrong_self_conventions_mut.stderr @@ -6,6 +6,7 @@ LL | pub fn to_many(&mut self) -> Option<&mut [T]> { | = help: consider choosing a less ambiguous name = note: `-D clippy::wrong-self-convention` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wrong_self_convention)]` error: methods with the following characteristics: (`to_*` and `*_mut`) usually take `self` by mutable reference --> $DIR/wrong_self_conventions_mut.rs:23:28 diff --git a/tests/ui/zero_div_zero.stderr b/tests/ui/zero_div_zero.stderr index cde6bc907c68..797ae2537bb3 100644 --- a/tests/ui/zero_div_zero.stderr +++ b/tests/ui/zero_div_zero.stderr @@ -6,6 +6,7 @@ LL | let nan = 0.0 / 0.0; | = help: consider using `f64::NAN` if you would like a constant representing NaN = note: `-D clippy::zero-divided-by-zero` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::zero_divided_by_zero)]` error: constant division of `0.0` with `0.0` will always result in NaN --> $DIR/zero_div_zero.rs:6:19 diff --git a/tests/ui/zero_ptr.stderr b/tests/ui/zero_ptr.stderr index 21c2b8c1e352..57679a8ac564 100644 --- a/tests/ui/zero_ptr.stderr +++ b/tests/ui/zero_ptr.stderr @@ -5,6 +5,7 @@ LL | let _ = 0 as *const usize; | ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::null::()` | = note: `-D clippy::zero-ptr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::zero_ptr)]` error: `0 as *mut _` detected --> $DIR/zero_ptr.rs:5:13 diff --git a/tests/ui/zero_sized_btreemap_values.stderr b/tests/ui/zero_sized_btreemap_values.stderr index de122473fd26..c48e19a760af 100644 --- a/tests/ui/zero_sized_btreemap_values.stderr +++ b/tests/ui/zero_sized_btreemap_values.stderr @@ -6,6 +6,7 @@ LL | const CONST_NOT_OK: Option> = None; | = help: consider using a set instead = note: `-D clippy::zero-sized-map-values` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::zero_sized_map_values)]` error: map with zero-sized value type --> $DIR/zero_sized_btreemap_values.rs:9:30 diff --git a/tests/ui/zero_sized_hashmap_values.stderr b/tests/ui/zero_sized_hashmap_values.stderr index 0d489f45aca1..08b1b58f3df3 100644 --- a/tests/ui/zero_sized_hashmap_values.stderr +++ b/tests/ui/zero_sized_hashmap_values.stderr @@ -6,6 +6,7 @@ LL | const CONST_NOT_OK: Option> = None; | = help: consider using a set instead = note: `-D clippy::zero-sized-map-values` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::zero_sized_map_values)]` error: map with zero-sized value type --> $DIR/zero_sized_hashmap_values.rs:9:30 From 11e50d467ef90b618b39b30806d52d130abc3d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Thu, 31 Aug 2023 22:12:47 +0200 Subject: [PATCH 0922/1222] Use `Freeze` for `SourceFile.lines` --- .../src/undocumented_unsafe_blocks.rs | 84 +++++++++---------- clippy_utils/src/source.rs | 2 +- 2 files changed, 39 insertions(+), 47 deletions(-) diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index a1ea3a495eb6..da8d8ed4c0f2 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -507,20 +507,18 @@ fn item_has_safety_comment(cx: &LateContext<'_>, item: &hir::Item<'_>) -> HasSaf && Lrc::ptr_eq(&unsafe_line.sf, &comment_start_line.sf) && let Some(src) = unsafe_line.sf.src.as_deref() { - return unsafe_line.sf.lines(|lines| { - if comment_start_line.line >= unsafe_line.line { - HasSafetyComment::No - } else { - match text_has_safety_comment( - src, - &lines[comment_start_line.line + 1..=unsafe_line.line], - unsafe_line.sf.start_pos, - ) { - Some(b) => HasSafetyComment::Yes(b), - None => HasSafetyComment::No, - } + return if comment_start_line.line >= unsafe_line.line { + HasSafetyComment::No + } else { + match text_has_safety_comment( + src, + &unsafe_line.sf.lines()[comment_start_line.line + 1..=unsafe_line.line], + unsafe_line.sf.start_pos, + ) { + Some(b) => HasSafetyComment::Yes(b), + None => HasSafetyComment::No, } - }); + }; } } HasSafetyComment::Maybe @@ -551,20 +549,18 @@ fn stmt_has_safety_comment(cx: &LateContext<'_>, span: Span, hir_id: HirId) -> H && Lrc::ptr_eq(&unsafe_line.sf, &comment_start_line.sf) && let Some(src) = unsafe_line.sf.src.as_deref() { - return unsafe_line.sf.lines(|lines| { - if comment_start_line.line >= unsafe_line.line { - HasSafetyComment::No - } else { - match text_has_safety_comment( - src, - &lines[comment_start_line.line + 1..=unsafe_line.line], - unsafe_line.sf.start_pos, - ) { - Some(b) => HasSafetyComment::Yes(b), - None => HasSafetyComment::No, - } + return if comment_start_line.line >= unsafe_line.line { + HasSafetyComment::No + } else { + match text_has_safety_comment( + src, + &unsafe_line.sf.lines()[comment_start_line.line + 1..=unsafe_line.line], + unsafe_line.sf.start_pos, + ) { + Some(b) => HasSafetyComment::Yes(b), + None => HasSafetyComment::No, } - }); + }; } } HasSafetyComment::Maybe @@ -614,20 +610,18 @@ fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span && Lrc::ptr_eq(&unsafe_line.sf, ¯o_line.sf) && let Some(src) = unsafe_line.sf.src.as_deref() { - unsafe_line.sf.lines(|lines| { - if macro_line.line < unsafe_line.line { - match text_has_safety_comment( - src, - &lines[macro_line.line + 1..=unsafe_line.line], - unsafe_line.sf.start_pos, - ) { - Some(b) => HasSafetyComment::Yes(b), - None => HasSafetyComment::No, - } - } else { - HasSafetyComment::No + if macro_line.line < unsafe_line.line { + match text_has_safety_comment( + src, + &unsafe_line.sf.lines()[macro_line.line + 1..=unsafe_line.line], + unsafe_line.sf.start_pos, + ) { + Some(b) => HasSafetyComment::Yes(b), + None => HasSafetyComment::No, } - }) + } else { + HasSafetyComment::No + } } else { // Problem getting source text. Pretend a comment was found. HasSafetyComment::Maybe @@ -671,13 +665,11 @@ fn span_in_body_has_safety_comment(cx: &LateContext<'_>, span: Span) -> bool { // Get the text from the start of function body to the unsafe block. // fn foo() { some_stuff; unsafe { stuff }; other_stuff; } // ^-------------^ - unsafe_line.sf.lines(|lines| { - body_line.line < unsafe_line.line && text_has_safety_comment( - src, - &lines[body_line.line + 1..=unsafe_line.line], - unsafe_line.sf.start_pos, - ).is_some() - }) + body_line.line < unsafe_line.line && text_has_safety_comment( + src, + &unsafe_line.sf.lines()[body_line.line + 1..=unsafe_line.line], + unsafe_line.sf.start_pos, + ).is_some() } else { // Problem getting source text. Pretend a comment was found. true diff --git a/clippy_utils/src/source.rs b/clippy_utils/src/source.rs index 03416d35ba45..600cd084c19f 100644 --- a/clippy_utils/src/source.rs +++ b/clippy_utils/src/source.rs @@ -118,7 +118,7 @@ fn first_char_in_first_line(cx: &T, span: Span) -> Option(cx: &T, span: Span) -> Span { let span = original_sp(span, DUMMY_SP); let SourceFileAndLine { sf, line } = cx.sess().source_map().lookup_line(span.lo()).unwrap(); - let line_start = sf.lines(|lines| lines[line]); + let line_start = sf.lines()[line]; let line_start = sf.absolute_position(line_start); span.with_lo(line_start) } From 415cdbd1d84eb3fff7223334747ec9f5ccefe108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sun, 3 Sep 2023 06:31:56 +0200 Subject: [PATCH 0923/1222] Partially outline code inside the panic! macro --- .../src/mixed_read_write_in_expression.rs | 23 +++++++++++++++---- clippy_utils/src/macros.rs | 16 ++++++++++--- tests/ui/match_same_arms_non_exhaustive.rs | 20 +++++++++------- .../ui/match_same_arms_non_exhaustive.stderr | 16 ++++++------- 4 files changed, 52 insertions(+), 23 deletions(-) diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs index 367cd6bd4133..ea6a9bc5657d 100644 --- a/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/clippy_lints/src/mixed_read_write_in_expression.rs @@ -134,15 +134,30 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> { } } +fn stmt_might_diverge(stmt: &Stmt<'_>) -> bool { + match stmt.kind { + StmtKind::Item(..) => false, + _ => true, + } +} + impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { fn visit_expr(&mut self, e: &'tcx Expr<'_>) { match e.kind { // fix #10776 ExprKind::Block(block, ..) => match (block.stmts, block.expr) { - ([], Some(e)) => self.visit_expr(e), - ([stmt], None) => match stmt.kind { - StmtKind::Expr(e) | StmtKind::Semi(e) => self.visit_expr(e), - _ => {}, + (stmts, Some(e)) => { + if stmts.iter().all(|stmt| !stmt_might_diverge(stmt)) { + self.visit_expr(e) + } + }, + ([first @ .., stmt], None) => { + if first.iter().all(|stmt| !stmt_might_diverge(stmt)) { + match stmt.kind { + StmtKind::Expr(e) | StmtKind::Semi(e) => self.visit_expr(e), + _ => {}, + } + } }, _ => {}, }, diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs index 173f9841d446..94334f55109b 100644 --- a/clippy_utils/src/macros.rs +++ b/clippy_utils/src/macros.rs @@ -227,16 +227,26 @@ pub enum PanicExpn<'a> { impl<'a> PanicExpn<'a> { pub fn parse(expr: &'a Expr<'a>) -> Option { - let ExprKind::Call(callee, [arg, rest @ ..]) = &expr.kind else { + let ExprKind::Call(callee, args) = &expr.kind else { return None; }; let ExprKind::Path(QPath::Resolved(_, path)) = &callee.kind else { return None; }; - let result = match path.segments.last().unwrap().ident.as_str() { + let name = path.segments.last().unwrap().ident.as_str(); + + // This has no argument + if name == "panic_cold_explicit" { + return Some(Self::Empty); + }; + + let [arg, rest @ ..] = args else { + return None; + }; + let result = match name { "panic" if arg.span.ctxt() == expr.span.ctxt() => Self::Empty, "panic" | "panic_str" => Self::Str(arg), - "panic_display" => { + "panic_display" | "panic_cold_display" => { let ExprKind::AddrOf(_, _, e) = &arg.kind else { return None; }; diff --git a/tests/ui/match_same_arms_non_exhaustive.rs b/tests/ui/match_same_arms_non_exhaustive.rs index 1ee048bf7f6c..e1b95aa57760 100644 --- a/tests/ui/match_same_arms_non_exhaustive.rs +++ b/tests/ui/match_same_arms_non_exhaustive.rs @@ -4,14 +4,18 @@ //@no-rustfix use std::sync::atomic::Ordering; // #[non_exhaustive] enum +fn repeat() -> ! { + panic!() +} + pub fn f(x: Ordering) { match x { Ordering::Relaxed => println!("relaxed"), Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), - Ordering::AcqRel | Ordering::SeqCst => panic!(), + Ordering::AcqRel | Ordering::SeqCst => repeat(), #[deny(non_exhaustive_omitted_patterns)] - _ => panic!(), + _ => repeat(), } } @@ -25,8 +29,8 @@ mod f { Ordering::Relaxed => println!("relaxed"), Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), - Ordering::AcqRel | Ordering::SeqCst => panic!(), - _ => panic!(), + Ordering::AcqRel | Ordering::SeqCst => repeat(), + _ => repeat(), } } } @@ -38,9 +42,9 @@ pub fn g(x: Ordering) { Ordering::Relaxed => println!("relaxed"), Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), - Ordering::AcqRel | Ordering::SeqCst => panic!(), + Ordering::AcqRel | Ordering::SeqCst => repeat(), //~^ ERROR: this match arm has an identical body to the `_` wildcard arm - _ => panic!(), + _ => repeat(), } } @@ -52,9 +56,9 @@ mod g { Ordering::Relaxed => println!("relaxed"), Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), - Ordering::AcqRel | Ordering::SeqCst => panic!(), + Ordering::AcqRel | Ordering::SeqCst => repeat(), //~^ ERROR: this match arm has an identical body to the `_` wildcard arm - _ => panic!(), + _ => repeat(), } } } diff --git a/tests/ui/match_same_arms_non_exhaustive.stderr b/tests/ui/match_same_arms_non_exhaustive.stderr index a039536338bc..ae6b02ab1b50 100644 --- a/tests/ui/match_same_arms_non_exhaustive.stderr +++ b/tests/ui/match_same_arms_non_exhaustive.stderr @@ -1,29 +1,29 @@ error: this match arm has an identical body to the `_` wildcard arm - --> $DIR/match_same_arms_non_exhaustive.rs:41:9 + --> $DIR/match_same_arms_non_exhaustive.rs:45:9 | -LL | Ordering::AcqRel | Ordering::SeqCst => panic!(), +LL | Ordering::AcqRel | Ordering::SeqCst => repeat(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the arm | = help: or try changing either arm body note: `_` wildcard arm here - --> $DIR/match_same_arms_non_exhaustive.rs:43:9 + --> $DIR/match_same_arms_non_exhaustive.rs:47:9 | -LL | _ => panic!(), +LL | _ => repeat(), | ^^^^^^^^^^^^^ = note: `-D clippy::match-same-arms` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]` error: this match arm has an identical body to the `_` wildcard arm - --> $DIR/match_same_arms_non_exhaustive.rs:55:13 + --> $DIR/match_same_arms_non_exhaustive.rs:59:13 | -LL | Ordering::AcqRel | Ordering::SeqCst => panic!(), +LL | Ordering::AcqRel | Ordering::SeqCst => repeat(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the arm | = help: or try changing either arm body note: `_` wildcard arm here - --> $DIR/match_same_arms_non_exhaustive.rs:57:13 + --> $DIR/match_same_arms_non_exhaustive.rs:61:13 | -LL | _ => panic!(), +LL | _ => repeat(), | ^^^^^^^^^^^^^ error: aborting due to 2 previous errors From 101f7862a66e8fcece27633bdebc2fad3f8cd38d Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Fri, 8 Sep 2023 22:39:20 +0000 Subject: [PATCH 0924/1222] Reuse rustdoc's doc comment handling in Clippy --- clippy_lints/Cargo.toml | 1 - clippy_lints/src/doc.rs | 185 +++++++++------------------ clippy_lints/src/lib.rs | 2 + tests/compile-test.rs | 4 +- tests/ui/doc/doc-fixable.fixed | 10 ++ tests/ui/doc/doc-fixable.rs | 10 ++ tests/ui/doc/doc-fixable.stderr | 13 +- tests/ui/doc/unbalanced_ticks.rs | 2 +- tests/ui/doc/unbalanced_ticks.stderr | 21 +-- tests/ui/doc_errors.rs | 16 +++ tests/ui/doc_errors.stderr | 2 +- tests/ui/needless_doc_main.rs | 9 +- tests/ui/needless_doc_main.stderr | 42 ++++-- 13 files changed, 160 insertions(+), 157 deletions(-) diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index c0a9f466e7b0..dcd9a4adcbd4 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -15,7 +15,6 @@ clippy_utils = { path = "../clippy_utils" } declare_clippy_lint = { path = "../declare_clippy_lint" } if_chain = "1.0" itertools = "0.10.1" -pulldown-cmark = { version = "0.9", default-features = false } quine-mc_cluskey = "0.2" regex-syntax = "0.7" serde = { version = "1.0", features = ["derive"] } diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index e29ab634c979..d8f2fbcea002 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -1,18 +1,16 @@ use clippy_utils::attrs::is_doc_hidden; use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_note, span_lint_and_then}; use clippy_utils::macros::{is_panic, root_macro_call_first_node}; -use clippy_utils::source::{first_line_of_span, snippet_with_applicability}; +use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; use clippy_utils::{is_entrypoint_fn, method_chain_args, return_ty}; use if_chain::if_chain; -use itertools::Itertools; use pulldown_cmark::Event::{ Code, End, FootnoteReference, HardBreak, Html, Rule, SoftBreak, Start, TaskListMarker, Text, }; use pulldown_cmark::Tag::{CodeBlock, Heading, Item, Link, Paragraph}; use pulldown_cmark::{BrokenLink, CodeBlockKind, CowStr, Options}; -use rustc_ast::ast::{Async, AttrKind, Attribute, Fn, FnRetTy, ItemKind}; -use rustc_ast::token::CommentKind; +use rustc_ast::ast::{Async, Attribute, Fn, FnRetTy, ItemKind}; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; use rustc_errors::emitter::EmitterWriter; @@ -26,6 +24,9 @@ use rustc_middle::lint::in_external_macro; use rustc_middle::ty; use rustc_parse::maybe_new_parser_from_source_str; use rustc_parse::parser::ForceCollect; +use rustc_resolve::rustdoc::{ + add_doc_fragment, attrs_to_doc_fragments, main_body_opts, source_span_for_markdown_range, DocFragment, +}; use rustc_session::parse::ParseSess; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::edition::Edition; @@ -450,53 +451,16 @@ fn lint_for_missing_headers( } } -/// Cleanup documentation decoration. -/// -/// We can't use `rustc_ast::attr::AttributeMethods::with_desugared_doc` or -/// `rustc_ast::parse::lexer::comments::strip_doc_comment_decoration` because we -/// need to keep track of -/// the spans but this function is inspired from the later. -#[expect(clippy::cast_possible_truncation)] -#[must_use] -pub fn strip_doc_comment_decoration(doc: &str, comment_kind: CommentKind, span: Span) -> (String, Vec<(usize, Span)>) { - // one-line comments lose their prefix - if comment_kind == CommentKind::Line { - let mut doc = doc.to_owned(); - doc.push('\n'); - let len = doc.len(); - // +3 skips the opening delimiter - return (doc, vec![(len, span.with_lo(span.lo() + BytePos(3)))]); - } +#[derive(Copy, Clone)] +struct Fragments<'a> { + doc: &'a str, + fragments: &'a [DocFragment], +} - let mut sizes = vec![]; - let mut contains_initial_stars = false; - for line in doc.lines() { - let offset = line.as_ptr() as usize - doc.as_ptr() as usize; - debug_assert_eq!(offset as u32 as usize, offset); - contains_initial_stars |= line.trim_start().starts_with('*'); - // +1 adds the newline, +3 skips the opening delimiter - sizes.push((line.len() + 1, span.with_lo(span.lo() + BytePos(3 + offset as u32)))); - } - if !contains_initial_stars { - return (doc.to_string(), sizes); - } - // remove the initial '*'s if any - let mut no_stars = String::with_capacity(doc.len()); - for line in doc.lines() { - let mut chars = line.chars(); - for c in &mut chars { - if c.is_whitespace() { - no_stars.push(c); - } else { - no_stars.push(if c == '*' { ' ' } else { c }); - break; - } - } - no_stars.push_str(chars.as_str()); - no_stars.push('\n'); +impl Fragments<'_> { + fn span(self, cx: &LateContext<'_>, range: Range) -> Option { + source_span_for_markdown_range(cx.tcx, &self.doc, &range, &self.fragments) } - - (no_stars, sizes) } #[derive(Copy, Clone, Default)] @@ -515,27 +479,12 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ Some(("fake".into(), "fake".into())) } + let (fragments, _) = attrs_to_doc_fragments(attrs.iter().map(|attr| (attr, None)), true); let mut doc = String::new(); - let mut spans = vec![]; - - for attr in attrs { - if let AttrKind::DocComment(comment_kind, comment) = attr.kind { - let (comment, current_spans) = strip_doc_comment_decoration(comment.as_str(), comment_kind, attr.span); - spans.extend_from_slice(¤t_spans); - doc.push_str(&comment); - } else if attr.has_name(sym::doc) { - // ignore mix of sugared and non-sugared doc - // don't trigger the safety or errors check - return None; - } - } - - let mut current = 0; - for &mut (ref mut offset, _) in &mut spans { - let offset_copy = *offset; - *offset = current; - current += offset_copy; + for fragment in &fragments { + add_doc_fragment(&mut doc, fragment); } + doc.pop(); if doc.is_empty() { return Some(DocHeaders::default()); @@ -543,23 +492,19 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ let mut cb = fake_broken_link_callback; - let parser = - pulldown_cmark::Parser::new_with_broken_link_callback(&doc, Options::empty(), Some(&mut cb)).into_offset_iter(); - // Iterate over all `Events` and combine consecutive events into one - let events = parser.coalesce(|previous, current| { - let previous_range = previous.1; - let current_range = current.1; - - match (previous.0, current.0) { - (Text(previous), Text(current)) => { - let mut previous = previous.to_string(); - previous.push_str(¤t); - Ok((Text(previous.into()), previous_range)) - }, - (previous, current) => Err(((previous, previous_range), (current, current_range))), - } - }); - Some(check_doc(cx, valid_idents, events, &spans)) + // disable smart punctuation to pick up ['link'] more easily + let opts = main_body_opts() - Options::ENABLE_SMART_PUNCTUATION; + let parser = pulldown_cmark::Parser::new_with_broken_link_callback(&doc, opts, Some(&mut cb)); + + Some(check_doc( + cx, + valid_idents, + parser.into_offset_iter(), + Fragments { + fragments: &fragments, + doc: &doc, + }, + )) } const RUST_CODE: &[&str] = &["rust", "no_run", "should_panic", "compile_fail"]; @@ -568,7 +513,7 @@ fn check_doc<'a, Events: Iterator, Range, valid_idents: &FxHashSet, events: Events, - spans: &[(usize, Span)], + fragments: Fragments<'_>, ) -> DocHeaders { // true if a safety header was found let mut headers = DocHeaders::default(); @@ -579,8 +524,8 @@ fn check_doc<'a, Events: Iterator, Range, Span)> = Vec::new(); - let mut paragraph_span = spans.get(0).expect("function isn't called if doc comment is empty").1; + let mut text_to_check: Vec<(CowStr<'_>, Range)> = Vec::new(); + let mut paragraph_range = 0..0; for (event, range) in events { match event { Start(CodeBlock(ref kind)) => { @@ -613,25 +558,28 @@ fn check_doc<'a, Events: Iterator, Range { if let End(Heading(_, _, _)) = event { in_heading = false; } - if ticks_unbalanced { + if ticks_unbalanced + && let Some(span) = fragments.span(cx, paragraph_range.clone()) + { span_lint_and_help( cx, DOC_MARKDOWN, - paragraph_span, + span, "backticks are unbalanced", None, "a backtick may be missing a pair", ); } else { - for (text, span) in text_to_check { - check_text(cx, valid_idents, &text, span); + for (text, range) in text_to_check { + if let Some(span) = fragments.span(cx, range) { + check_text(cx, valid_idents, &text, span); + } } } text_to_check = Vec::new(); @@ -640,8 +588,7 @@ fn check_doc<'a, Events: Iterator, Range (), // HTML is weird, just ignore it SoftBreak | HardBreak | TaskListMarker(_) | Code(_) | Rule => (), FootnoteReference(text) | Text(text) => { - let (begin, span) = get_current_span(spans, range.start); - paragraph_span = paragraph_span.with_hi(span.hi()); + paragraph_range.end = range.end; ticks_unbalanced |= text.contains('`') && !in_code; if Some(&text) == in_link.as_ref() || ticks_unbalanced { // Probably a link of the form `` @@ -658,19 +605,19 @@ fn check_doc<'a, Events: Iterator, Range, Range, - in_link: bool, - trimmed_text: &str, - span: Span, - range: &Range, - begin: usize, - text_len: usize, -) { - if in_link && trimmed_text.starts_with('\'') && trimmed_text.ends_with('\'') { - // fix the span to only point at the text within the link - let lo = span.lo() + BytePos::from_usize(range.start - begin); +fn check_link_quotes(cx: &LateContext<'_>, trimmed_text: &str, range: Range, fragments: Fragments<'_>) { + if trimmed_text.starts_with('\'') + && trimmed_text.ends_with('\'') + && let Some(span) = fragments.span(cx, range) + { span_lint( cx, DOC_LINK_WITH_QUOTES, - span.with_lo(lo).with_hi(lo + BytePos::from_usize(text_len)), + span, "possible intra-doc link using quotes instead of backticks", ); } } -fn get_current_span(spans: &[(usize, Span)], idx: usize) -> (usize, Span) { - let index = match spans.binary_search_by(|c| c.0.cmp(&idx)) { - Ok(o) => o, - Err(e) => e - 1, - }; - spans[index] -} - -fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { +fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, range: Range, fragments: Fragments<'_>) { fn has_needless_main(code: String, edition: Edition) -> bool { rustc_driver::catch_fatal_errors(|| { rustc_span::create_session_globals_then(edition, || { @@ -774,12 +706,13 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { .unwrap_or_default() } + let trailing_whitespace = text.len() - text.trim_end().len(); + // 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") + && let Some(span) = fragments.span(cx, range.start..range.end - trailing_whitespace) { span_lint(cx, NEEDLESS_DOCTEST_MAIN, span, "needless `fn main` in doctest"); } diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index ab71bfbdc587..20fdf26dc521 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -21,6 +21,7 @@ // FIXME: switch to something more ergonomic here, once available. // (Currently there is no way to opt into sysroot crates without `extern crate`.) +extern crate pulldown_cmark; extern crate rustc_arena; extern crate rustc_ast; extern crate rustc_ast_pretty; @@ -37,6 +38,7 @@ extern crate rustc_lexer; extern crate rustc_lint; extern crate rustc_middle; extern crate rustc_parse; +extern crate rustc_resolve; extern crate rustc_session; extern crate rustc_span; extern crate rustc_target; diff --git a/tests/compile-test.rs b/tests/compile-test.rs index e329a94ff6a1..c1c3d4a868f9 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -130,7 +130,9 @@ fn base_config(test_dir: &str) -> (Config, Args) { }; let mut config = Config { - mode: Mode::Yolo { rustfix: RustfixMode::Everything }, + mode: Mode::Yolo { + rustfix: RustfixMode::Everything, + }, stderr_filters: vec![(Match::PathBackslash, b"/")], stdout_filters: vec![], output_conflict_handling: if bless { diff --git a/tests/ui/doc/doc-fixable.fixed b/tests/ui/doc/doc-fixable.fixed index f7c2f14a4824..47b56960a00f 100644 --- a/tests/ui/doc/doc-fixable.fixed +++ b/tests/ui/doc/doc-fixable.fixed @@ -198,6 +198,16 @@ fn pulldown_cmark_crash() {} /// [plain text][path::to::item] fn intra_doc_link() {} +/// Ignore escaped\_underscores +/// +/// \\[ +/// \\prod\_{x\\in X} p\_x +/// \\] +fn issue_2581() {} + +/// Foo \[bar\] \[baz\] \[qux\]. `DocMarkdownLint` +fn lint_after_escaped_chars() {} + // issue #7033 - generic_const_exprs ICE struct S where [(); N.checked_next_power_of_two().unwrap()]: { diff --git a/tests/ui/doc/doc-fixable.rs b/tests/ui/doc/doc-fixable.rs index 51961e75b84c..4d9a4eafa5fc 100644 --- a/tests/ui/doc/doc-fixable.rs +++ b/tests/ui/doc/doc-fixable.rs @@ -198,6 +198,16 @@ fn pulldown_cmark_crash() {} /// [plain text][path::to::item] fn intra_doc_link() {} +/// Ignore escaped\_underscores +/// +/// \\[ +/// \\prod\_{x\\in X} p\_x +/// \\] +fn issue_2581() {} + +/// Foo \[bar\] \[baz\] \[qux\]. DocMarkdownLint +fn lint_after_escaped_chars() {} + // issue #7033 - generic_const_exprs ICE struct S where [(); N.checked_next_power_of_two().unwrap()]: { diff --git a/tests/ui/doc/doc-fixable.stderr b/tests/ui/doc/doc-fixable.stderr index a30ded81385f..4c9ff41d9183 100644 --- a/tests/ui/doc/doc-fixable.stderr +++ b/tests/ui/doc/doc-fixable.stderr @@ -308,5 +308,16 @@ help: try LL | /// An iterator over `mycrate::Collection`'s values. | ~~~~~~~~~~~~~~~~~~~~~ -error: aborting due to 28 previous errors +error: item in documentation is missing backticks + --> $DIR/doc-fixable.rs:208:34 + | +LL | /// Foo \[bar\] \[baz\] \[qux\]. DocMarkdownLint + | ^^^^^^^^^^^^^^^ + | +help: try + | +LL | /// Foo \[bar\] \[baz\] \[qux\]. `DocMarkdownLint` + | ~~~~~~~~~~~~~~~~~ + +error: aborting due to 29 previous errors diff --git a/tests/ui/doc/unbalanced_ticks.rs b/tests/ui/doc/unbalanced_ticks.rs index 4a1711f79a02..6f7bab72040c 100644 --- a/tests/ui/doc/unbalanced_ticks.rs +++ b/tests/ui/doc/unbalanced_ticks.rs @@ -48,4 +48,4 @@ fn other_markdown() {} /// /// `lol` /// pub struct Struct; /// ``` -fn iss_7421() {} +fn issue_7421() {} diff --git a/tests/ui/doc/unbalanced_ticks.stderr b/tests/ui/doc/unbalanced_ticks.stderr index 92b6f8536c88..89ad8db3916c 100644 --- a/tests/ui/doc/unbalanced_ticks.stderr +++ b/tests/ui/doc/unbalanced_ticks.stderr @@ -1,7 +1,8 @@ error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:7:1 + --> $DIR/unbalanced_ticks.rs:7:5 | -LL | / /// This is a doc comment with `unbalanced_tick marks and several words that +LL | /// This is a doc comment with `unbalanced_tick marks and several words that + | _____^ LL | | LL | | /// should be `encompassed_by` tick marks because they `contain_underscores`. LL | | /// Because of the initial `unbalanced_tick` pair, the error message is @@ -13,10 +14,10 @@ LL | | /// very `confusing_and_misleading`. = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:14:1 + --> $DIR/unbalanced_ticks.rs:14:5 | LL | /// This paragraph has `unbalanced_tick marks and should stop_linting. - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: a backtick may be missing a pair @@ -32,10 +33,10 @@ LL | /// This paragraph is fine and `should_be` linted normally. | ~~~~~~~~~~~ error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:20:1 + --> $DIR/unbalanced_ticks.rs:20:5 | LL | /// Double unbalanced backtick from ``here to here` should lint. - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: a backtick may be missing a pair @@ -51,18 +52,18 @@ LL | /// ## `not_fine` | ~~~~~~~~~~ error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:37:1 + --> $DIR/unbalanced_ticks.rs:37:5 | LL | /// ### `unbalanced - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ | = help: a backtick may be missing a pair error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:40:1 + --> $DIR/unbalanced_ticks.rs:40:5 | LL | /// - This `item has unbalanced tick marks - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: a backtick may be missing a pair diff --git a/tests/ui/doc_errors.rs b/tests/ui/doc_errors.rs index 86721f61d199..d661231c59ea 100644 --- a/tests/ui/doc_errors.rs +++ b/tests/ui/doc_errors.rs @@ -85,6 +85,22 @@ impl Struct1 { async fn async_priv_method_missing_errors_header() -> Result<(), ()> { unimplemented!(); } + + /** + # Errors + A description of the errors goes here. + */ + fn block_comment() -> Result<(), ()> { + unimplemented!(); + } + + /** + * # Errors + * A description of the errors goes here. + */ + fn block_comment_leading_asterisks() -> Result<(), ()> { + unimplemented!(); + } } pub trait Trait1 { diff --git a/tests/ui/doc_errors.stderr b/tests/ui/doc_errors.stderr index 9cea864f1d86..28b2db2440b7 100644 --- a/tests/ui/doc_errors.stderr +++ b/tests/ui/doc_errors.stderr @@ -38,7 +38,7 @@ LL | pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:92:5 + --> $DIR/doc_errors.rs:108:5 | LL | fn trait_method_missing_errors_header() -> Result<(), ()>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/needless_doc_main.rs b/tests/ui/needless_doc_main.rs index d31b9047eaae..fee05926ce4f 100644 --- a/tests/ui/needless_doc_main.rs +++ b/tests/ui/needless_doc_main.rs @@ -10,7 +10,7 @@ /// unimplemented!(); /// } /// ``` -/// +/// /// With an explicit return type it should lint too /// ```edition2015 /// fn main() -> () { @@ -18,7 +18,7 @@ /// unimplemented!(); /// } /// ``` -/// +/// /// This should, too. /// ```rust /// fn main() { @@ -26,11 +26,12 @@ /// unimplemented!(); /// } /// ``` -/// +/// /// This one too. /// ```no_run -/// fn main() { +/// // the fn is not always the first line //~^ ERROR: needless `fn main` in doctest +/// fn main() { /// unimplemented!(); /// } /// ``` diff --git a/tests/ui/needless_doc_main.stderr b/tests/ui/needless_doc_main.stderr index 8dd93bb05dd5..84256548671d 100644 --- a/tests/ui/needless_doc_main.stderr +++ b/tests/ui/needless_doc_main.stderr @@ -1,29 +1,47 @@ error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:7:4 + --> $DIR/needless_doc_main.rs:7:5 | -LL | /// fn main() { - | ^^^^^^^^^^^^ +LL | /// fn main() { + | _____^ +LL | | +LL | | +LL | | /// unimplemented!(); +LL | | /// } + | |_____^ | = note: `-D clippy::needless-doctest-main` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_doctest_main)]` error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:16:4 + --> $DIR/needless_doc_main.rs:16:5 | -LL | /// fn main() -> () { - | ^^^^^^^^^^^^^^^^^^ +LL | /// fn main() -> () { + | _____^ +LL | | +LL | | /// unimplemented!(); +LL | | /// } + | |_____^ error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:24:4 + --> $DIR/needless_doc_main.rs:24:5 | -LL | /// fn main() { - | ^^^^^^^^^^^^ +LL | /// fn main() { + | _____^ +LL | | +LL | | /// unimplemented!(); +LL | | /// } + | |_____^ error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:32:4 + --> $DIR/needless_doc_main.rs:32:5 | -LL | /// fn main() { - | ^^^^^^^^^^^^ +LL | /// // the fn is not always the first line + | _____^ +LL | | +LL | | /// fn main() { +LL | | /// unimplemented!(); +LL | | /// } + | |_____^ error: aborting due to 4 previous errors From fb512a3ad1bc5b3c9ce05dc38e2a002fe42d0bef Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Sun, 10 Sep 2023 18:17:47 +0000 Subject: [PATCH 0925/1222] Call `LateLintPass::check_attribute` from `with_lint_attrs` --- tests/ui/allow_attributes.fixed | 7 +++++++ tests/ui/allow_attributes.rs | 7 +++++++ tests/ui/blanket_clippy_restriction_lints.stderr | 14 +++++++------- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/tests/ui/allow_attributes.fixed b/tests/ui/allow_attributes.fixed index 945ba83611c0..b506a9890f5b 100644 --- a/tests/ui/allow_attributes.fixed +++ b/tests/ui/allow_attributes.fixed @@ -22,6 +22,13 @@ struct T4; #[cfg_attr(panic = "unwind", expect(dead_code))] struct CfgT; +#[allow(clippy::allow_attributes, unused)] +struct Allowed; + +#[expect(clippy::allow_attributes)] +#[allow(unused)] +struct Expected; + fn ignore_external() { external! { #[allow(clippy::needless_borrow)] // Should not lint diff --git a/tests/ui/allow_attributes.rs b/tests/ui/allow_attributes.rs index 8afa61c7002c..c7daa7abd9d4 100644 --- a/tests/ui/allow_attributes.rs +++ b/tests/ui/allow_attributes.rs @@ -22,6 +22,13 @@ struct T4; #[cfg_attr(panic = "unwind", allow(dead_code))] struct CfgT; +#[allow(clippy::allow_attributes, unused)] +struct Allowed; + +#[expect(clippy::allow_attributes)] +#[allow(unused)] +struct Expected; + fn ignore_external() { external! { #[allow(clippy::needless_borrow)] // Should not lint diff --git a/tests/ui/blanket_clippy_restriction_lints.stderr b/tests/ui/blanket_clippy_restriction_lints.stderr index d04ea7151c2a..afb634f34b41 100644 --- a/tests/ui/blanket_clippy_restriction_lints.stderr +++ b/tests/ui/blanket_clippy_restriction_lints.stderr @@ -1,10 +1,3 @@ -error: `clippy::restriction` is not meant to be enabled as a group - | - = note: because of the command line `--warn clippy::restriction` - = help: enable the restriction lints you need individually - = note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::blanket_clippy_restriction_lints)]` - error: `clippy::restriction` is not meant to be enabled as a group --> $DIR/blanket_clippy_restriction_lints.rs:6:9 | @@ -12,6 +5,8 @@ LL | #![warn(clippy::restriction)] | ^^^^^^^^^^^^^^^^^^^ | = help: enable the restriction lints you need individually + = note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::blanket_clippy_restriction_lints)]` error: `clippy::restriction` is not meant to be enabled as a group --> $DIR/blanket_clippy_restriction_lints.rs:8:9 @@ -29,5 +24,10 @@ LL | #![forbid(clippy::restriction)] | = help: enable the restriction lints you need individually +error: `clippy::restriction` is not meant to be enabled as a group + | + = note: because of the command line `--warn clippy::restriction` + = help: enable the restriction lints you need individually + error: aborting due to 4 previous errors From f3c3d09ed07c6eaf3ea14bc43968f27af411e556 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Fri, 8 Sep 2023 16:14:47 +0000 Subject: [PATCH 0926/1222] Update tools and fulldeps tests --- clippy_lints/src/suspicious_operation_groupings.rs | 2 +- clippy_lints/src/unnested_or_patterns.rs | 2 +- clippy_utils/src/ast_utils.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index 23d6e2a845fd..d10f10ef87e8 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -586,7 +586,7 @@ fn ident_difference_expr_with_base_location( | (ForLoop(_, _, _, _), ForLoop(_, _, _, _)) | (While(_, _, _), While(_, _, _)) | (If(_, _, _), If(_, _, _)) - | (Let(_, _, _), Let(_, _, _)) + | (Let(_, _, _, _), Let(_, _, _, _)) | (Type(_, _), Type(_, _)) | (Cast(_, _), Cast(_, _)) | (Lit(_), Lit(_)) diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 9cf595772298..766a54814516 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -68,7 +68,7 @@ impl EarlyLintPass for UnnestedOrPatterns { fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) { if self.msrv.meets(msrvs::OR_PATTERNS) { - if let ast::ExprKind::Let(pat, _, _) = &e.kind { + if let ast::ExprKind::Let(pat, _, _, _) = &e.kind { lint_unnested_or_patterns(cx, pat); } } diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 140cfa2194fc..a78ff02021f2 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -166,7 +166,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (Unary(lo, l), Unary(ro, r)) => mem::discriminant(lo) == mem::discriminant(ro) && eq_expr(l, r), (Lit(l), Lit(r)) => l == r, (Cast(l, lt), Cast(r, rt)) | (Type(l, lt), Type(r, rt)) => eq_expr(l, r) && eq_ty(lt, rt), - (Let(lp, le, _), Let(rp, re, _)) => eq_pat(lp, rp) && eq_expr(le, re), + (Let(lp, le, _, _), Let(rp, re, _, _)) => eq_pat(lp, rp) && eq_expr(le, re), (If(lc, lt, le), If(rc, rt, re)) => eq_expr(lc, rc) && eq_block(lt, rt) && eq_expr_opt(le, re), (While(lc, lt, ll), While(rc, rt, rl)) => eq_label(ll, rl) && eq_expr(lc, rc) && eq_block(lt, rt), (ForLoop(lp, li, lt, ll), ForLoop(rp, ri, rt, rl)) => { From e82efb9adeb11754c588880b791ae368a939d4f7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 12 Sep 2023 23:47:47 +0200 Subject: [PATCH 0927/1222] make the set of methods between our two Const types more consistent --- clippy_lints/src/matches/overlapping_arms.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/matches/overlapping_arms.rs b/clippy_lints/src/matches/overlapping_arms.rs index 8be3c178a291..6e13148f2fc1 100644 --- a/clippy_lints/src/matches/overlapping_arms.rs +++ b/clippy_lints/src/matches/overlapping_arms.rs @@ -37,22 +37,14 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>) Some(lhs) => constant(cx, cx.typeck_results(), lhs)?, None => { let min_val_const = ty.numeric_min_val(cx.tcx)?; - let min_constant = mir::ConstantKind::from_value( - cx.tcx.valtree_to_const_val((ty, min_val_const.to_valtree())), - ty, - ); - miri_to_const(cx, min_constant)? + miri_to_const(cx, mir::ConstantKind::from_ty_const(min_val_const, cx.tcx))? }, }; let rhs_const = match rhs { Some(rhs) => constant(cx, cx.typeck_results(), rhs)?, None => { let max_val_const = ty.numeric_max_val(cx.tcx)?; - let max_constant = mir::ConstantKind::from_value( - cx.tcx.valtree_to_const_val((ty, max_val_const.to_valtree())), - ty, - ); - miri_to_const(cx, max_constant)? + miri_to_const(cx, mir::ConstantKind::from_ty_const(max_val_const, cx.tcx))? }, }; let lhs_val = lhs_const.int_value(cx, ty)?; From d58e71421a98b5c0c6d8ccf7a8c21b6f7b145c5f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 11 Sep 2023 20:01:48 +0200 Subject: [PATCH 0928/1222] use AllocId instead of Allocation in ConstValue::ByRef --- clippy_utils/src/consts.rs | 53 ++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index adeb673b6b9d..03341feffb8c 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -684,34 +684,37 @@ pub fn miri_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::ConstantKind<'t }, _ => None, }, - mir::ConstantKind::Val(ConstValue::ByRef { alloc, offset: _ }, _) => match result.ty().kind() { - ty::Adt(adt_def, _) if adt_def.is_struct() => Some(Constant::Adt(result)), - ty::Array(sub_type, len) => match sub_type.kind() { - ty::Float(FloatTy::F32) => match len.try_to_target_usize(lcx.tcx) { - Some(len) => alloc - .inner() - .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * usize::try_from(len).unwrap())) - .to_owned() - .array_chunks::<4>() - .map(|&chunk| Some(Constant::F32(f32::from_le_bytes(chunk)))) - .collect::>>>() - .map(Constant::Vec), - _ => None, - }, - ty::Float(FloatTy::F64) => match len.try_to_target_usize(lcx.tcx) { - Some(len) => alloc - .inner() - .inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * usize::try_from(len).unwrap())) - .to_owned() - .array_chunks::<8>() - .map(|&chunk| Some(Constant::F64(f64::from_le_bytes(chunk)))) - .collect::>>>() - .map(Constant::Vec), + mir::ConstantKind::Val(ConstValue::ByRef { alloc_id, offset: _ }, _) => { + let alloc = lcx.tcx.global_alloc(alloc_id).unwrap_memory(); + match result.ty().kind() { + ty::Adt(adt_def, _) if adt_def.is_struct() => Some(Constant::Adt(result)), + ty::Array(sub_type, len) => match sub_type.kind() { + ty::Float(FloatTy::F32) => match len.try_to_target_usize(lcx.tcx) { + Some(len) => alloc + .inner() + .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * usize::try_from(len).unwrap())) + .to_owned() + .array_chunks::<4>() + .map(|&chunk| Some(Constant::F32(f32::from_le_bytes(chunk)))) + .collect::>>>() + .map(Constant::Vec), + _ => None, + }, + ty::Float(FloatTy::F64) => match len.try_to_target_usize(lcx.tcx) { + Some(len) => alloc + .inner() + .inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * usize::try_from(len).unwrap())) + .to_owned() + .array_chunks::<8>() + .map(|&chunk| Some(Constant::F64(f64::from_le_bytes(chunk)))) + .collect::>>>() + .map(Constant::Vec), + _ => None, + }, _ => None, }, _ => None, - }, - _ => None, + } }, _ => None, } From 38df164a52abbf3f681a31057d7ea70857198477 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 12 Sep 2023 07:49:25 +0200 Subject: [PATCH 0929/1222] =?UTF-8?q?cleanup=20op=5Fto=5Fconst=20a=20bit;?= =?UTF-8?q?=20rename=20ConstValue::ByRef=20=E2=86=92=20Indirect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs | 2 +- clippy_utils/src/consts.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs index f66f33fee166..4a5b6fa5c18d 100644 --- a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs +++ b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs @@ -232,7 +232,7 @@ fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option match cx.tcx.const_eval_poly(def_id).ok()? { - ConstValue::ByRef { alloc, offset } if offset.bytes() == 0 => { + ConstValue::Indirect { alloc, offset } if offset.bytes() == 0 => { read_mir_alloc_def_path(cx, alloc.inner(), cx.tcx.type_of(def_id).instantiate_identity()) }, _ => None, diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 03341feffb8c..61b944667a4a 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -684,7 +684,7 @@ pub fn miri_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::ConstantKind<'t }, _ => None, }, - mir::ConstantKind::Val(ConstValue::ByRef { alloc_id, offset: _ }, _) => { + mir::ConstantKind::Val(ConstValue::Indirect { alloc_id, offset: _ }, _) => { let alloc = lcx.tcx.global_alloc(alloc_id).unwrap_memory(); match result.ty().kind() { ty::Adt(adt_def, _) if adt_def.is_struct() => Some(Constant::Adt(result)), From cd52d96f2ffc86dd17c69090c917162da2798097 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 13 Sep 2023 13:55:23 +0000 Subject: [PATCH 0930/1222] treat host effect params as erased generics in codegen This fixes the changes brought to codegen tests when effect params are added to libcore, by not attempting to monomorphize functions that get the host param by being `const fn`. --- clippy_lints/src/derive.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index d3311792cfa8..2bdac1352dce 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -343,7 +343,7 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &h // If the current self type doesn't implement Copy (due to generic constraints), search to see if // there's a Copy impl for any instance of the adt. if !is_copy(cx, ty) { - if ty_subs.non_erasable_generics().next().is_some() { + if ty_subs.non_erasable_generics(cx.tcx, ty_adt.did()).next().is_some() { let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(©_id).map_or(false, |impls| { impls.iter().any(|&id| { matches!(cx.tcx.type_of(id).instantiate_identity().kind(), ty::Adt(adt, _) From c44d7e5367645794340d8b485c138de4e616df6c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 12 Sep 2023 14:44:38 +0200 Subject: [PATCH 0931/1222] fix clippy (and MIR printing) handling of ConstValue::Indirect slices --- clippy_utils/src/consts.rs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 61b944667a4a..fcb90c63a6fc 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -671,19 +671,10 @@ pub fn miri_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::ConstantKind<'t ty::RawPtr(_) => Some(Constant::RawPtr(int.assert_bits(int.size()))), _ => None, }, - mir::ConstantKind::Val(ConstValue::Slice { data, start, end }, _) => match result.ty().kind() { - ty::Ref(_, tam, _) => match tam.kind() { - ty::Str => String::from_utf8( - data.inner() - .inspect_with_uninit_and_ptr_outside_interpreter(start..end) - .to_owned(), - ) - .ok() - .map(Constant::Str), - _ => None, - }, - _ => None, - }, + mir::ConstantKind::Val(cv, _) if matches!(result.ty().kind(), ty::Ref(_, inner_ty, _) if matches!(inner_ty.kind(), ty::Str)) => { + let data = cv.try_get_slice_bytes_for_diagnostics(lcx.tcx)?; + String::from_utf8(data.to_owned()).ok().map(Constant::Str) + } mir::ConstantKind::Val(ConstValue::Indirect { alloc_id, offset: _ }, _) => { let alloc = lcx.tcx.global_alloc(alloc_id).unwrap_memory(); match result.ty().kind() { From 7e2833ee3abe089c5b1bf41403ee7eecad87bed0 Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Thu, 14 Sep 2023 17:47:36 +0000 Subject: [PATCH 0932/1222] Ignore `#[doc(hidden)]` functions in clippy doc lints --- clippy_lints/src/doc.rs | 4 ++++ tests/ui/doc_errors.rs | 15 +++++++++++++++ tests/ui/doc_errors.stderr | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 4498e9ccdec2..bf2add6aa64f 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -479,6 +479,10 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ Some(("fake".into(), "fake".into())) } + if is_doc_hidden(attrs) { + return None; + } + let (fragments, _) = attrs_to_doc_fragments(attrs.iter().map(|attr| (attr, None)), true); let mut doc = String::new(); for fragment in &fragments { diff --git a/tests/ui/doc_errors.rs b/tests/ui/doc_errors.rs index d661231c59ea..9b3783aaf09d 100644 --- a/tests/ui/doc_errors.rs +++ b/tests/ui/doc_errors.rs @@ -101,6 +101,11 @@ impl Struct1 { fn block_comment_leading_asterisks() -> Result<(), ()> { unimplemented!(); } + + #[doc(hidden)] + fn doc_hidden() -> Result<(), ()> { + unimplemented!(); + } } pub trait Trait1 { @@ -111,6 +116,11 @@ pub trait Trait1 { /// # Errors /// A description of the errors goes here. fn trait_method_with_errors_header() -> Result<(), ()>; + + #[doc(hidden)] + fn doc_hidden() -> Result<(), ()> { + unimplemented!(); + } } impl Trait1 for Struct1 { @@ -123,6 +133,11 @@ impl Trait1 for Struct1 { } } +#[doc(hidden)] +pub trait DocHidden { + fn f() -> Result<(), ()>; +} + fn main() -> Result<(), ()> { Ok(()) } diff --git a/tests/ui/doc_errors.stderr b/tests/ui/doc_errors.stderr index 28b2db2440b7..dc59675b9e5f 100644 --- a/tests/ui/doc_errors.stderr +++ b/tests/ui/doc_errors.stderr @@ -38,7 +38,7 @@ LL | pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:108:5 + --> $DIR/doc_errors.rs:113:5 | LL | fn trait_method_missing_errors_header() -> Result<(), ()>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From e710260a05bd8d9250ba9120a2cbb421affc4057 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 11 Sep 2023 09:52:45 +0200 Subject: [PATCH 0933/1222] move required_consts check to general post-mono-check function --- clippy_lints/src/non_copy_const.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 243192385c25..884663337879 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -204,7 +204,7 @@ fn is_value_unfrozen_raw<'tcx>( // similar to 2., but with the a frozen variant) (e.g. borrowing // `borrow_interior_mutable_const::enums::AssocConsts::TO_BE_FROZEN_VARIANT`). // I chose this way because unfrozen enums as assoc consts are rare (or, hopefully, none). - err == ErrorHandled::TooGeneric + matches!(err, ErrorHandled::TooGeneric(..)) }, |val| val.map_or(true, |val| inner(cx, val, ty)), ) @@ -244,8 +244,8 @@ pub fn const_eval_resolve<'tcx>( }; tcx.const_eval_global_id_for_typeck(param_env, cid, span) }, - Ok(None) => Err(ErrorHandled::TooGeneric), - Err(err) => Err(ErrorHandled::Reported(err.into())), + Ok(None) => Err(ErrorHandled::TooGeneric(span.unwrap_or(rustc_span::DUMMY_SP))), + Err(err) => Err(ErrorHandled::Reported(err.into(), span.unwrap_or(rustc_span::DUMMY_SP))), } } From 836664236096939635d4626d8285b0c0b76c58e0 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 11 Sep 2023 23:09:11 +0200 Subject: [PATCH 0934/1222] don't point at const usage site for resolution-time errors also share the code that emits the actual error --- tests/ui-toml/suppress_lint_in_const/test.stderr | 2 +- tests/ui/indexing_slicing_index.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui-toml/suppress_lint_in_const/test.stderr b/tests/ui-toml/suppress_lint_in_const/test.stderr index d14974faffa6..f8ace7995939 100644 --- a/tests/ui-toml/suppress_lint_in_const/test.stderr +++ b/tests/ui-toml/suppress_lint_in_const/test.stderr @@ -4,7 +4,7 @@ error[E0080]: evaluation of `main::{constant#3}` failed LL | const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true. | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 -note: erroneous constant used +note: erroneous constant encountered --> $DIR/test.rs:37:5 | LL | const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true. diff --git a/tests/ui/indexing_slicing_index.stderr b/tests/ui/indexing_slicing_index.stderr index 64facf208034..1c34875d2b8a 100644 --- a/tests/ui/indexing_slicing_index.stderr +++ b/tests/ui/indexing_slicing_index.stderr @@ -24,7 +24,7 @@ error[E0080]: evaluation of `main::{constant#3}` failed LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 -note: erroneous constant used +note: erroneous constant encountered --> $DIR/indexing_slicing_index.rs:48:5 | LL | const { &ARR[idx4()] }; From 0a2d7f25f445526728e1ad3d16e14b27240d8d3a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 16 Sep 2023 09:36:22 +0200 Subject: [PATCH 0935/1222] move ConstValue into mir this way we have mir::ConstValue and ty::ValTree as reasonably parallel --- clippy_utils/src/consts.rs | 2 +- clippy_utils/src/ty.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index fcb90c63a6fc..c88fce22f7fb 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -656,7 +656,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { } pub fn miri_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::ConstantKind<'tcx>) -> Option> { - use rustc_middle::mir::interpret::ConstValue; + use rustc_middle::mir::ConstValue; match result { mir::ConstantKind::Val(ConstValue::Scalar(Scalar::Int(int)), _) => match result.ty().kind() { ty::Adt(adt_def, _) if adt_def.is_struct() => Some(Constant::Adt(result)), diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index f0b4ede35fbc..9e25d97f5a6b 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -13,7 +13,7 @@ use rustc_hir::{Expr, FnDecl, LangItem, TyKind, Unsafety}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; -use rustc_middle::mir::interpret::{ConstValue, Scalar}; +use rustc_middle::mir::{ConstValue, interpret::Scalar}; use rustc_middle::traits::EvaluationResult; use rustc_middle::ty::layout::ValidityRequirement; use rustc_middle::ty::{ From cb84020e1bb0afba3d7ca987bb2cdec237f5a151 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 20 Sep 2023 20:51:14 +0200 Subject: [PATCH 0936/1222] rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const --- clippy_lints/src/enum_clike.rs | 2 +- clippy_lints/src/matches/overlapping_arms.rs | 4 ++-- clippy_utils/src/consts.rs | 20 ++++++++++---------- clippy_utils/src/lib.rs | 6 +++--- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index 96c5c7fc5093..3f60e5a7c4d6 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant { .tcx .const_eval_poly(def_id.to_def_id()) .ok() - .map(|val| rustc_middle::mir::ConstantKind::from_value(val, ty)); + .map(|val| rustc_middle::mir::Const::from_value(val, ty)); if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx, c)) { if let ty::Adt(adt, _) = ty.kind() { if adt.is_enum() { diff --git a/clippy_lints/src/matches/overlapping_arms.rs b/clippy_lints/src/matches/overlapping_arms.rs index 6e13148f2fc1..7c0485914b83 100644 --- a/clippy_lints/src/matches/overlapping_arms.rs +++ b/clippy_lints/src/matches/overlapping_arms.rs @@ -37,14 +37,14 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>) Some(lhs) => constant(cx, cx.typeck_results(), lhs)?, None => { let min_val_const = ty.numeric_min_val(cx.tcx)?; - miri_to_const(cx, mir::ConstantKind::from_ty_const(min_val_const, cx.tcx))? + miri_to_const(cx, mir::Const::from_ty_const(min_val_const, cx.tcx))? }, }; let rhs_const = match rhs { Some(rhs) => constant(cx, cx.typeck_results(), rhs)?, None => { let max_val_const = ty.numeric_max_val(cx.tcx)?; - miri_to_const(cx, mir::ConstantKind::from_ty_const(max_val_const, cx.tcx))? + miri_to_const(cx, mir::Const::from_ty_const(max_val_const, cx.tcx))? }, }; let lhs_val = lhs_const.int_value(cx, ty)?; diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index c88fce22f7fb..a136de862408 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -21,7 +21,7 @@ use std::iter; /// A `LitKind`-like enum to fold constant `Expr`s into. #[derive(Debug, Clone)] pub enum Constant<'tcx> { - Adt(rustc_middle::mir::ConstantKind<'tcx>), + Adt(rustc_middle::mir::Const<'tcx>), /// A `String` (e.g., "abc"). Str(String), /// A binary string (e.g., `b"abc"`). @@ -482,7 +482,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { .tcx .const_eval_resolve(self.param_env, mir::UnevaluatedConst::new(def_id, args), None) .ok() - .map(|val| rustc_middle::mir::ConstantKind::from_value(val, ty))?; + .map(|val| rustc_middle::mir::Const::from_value(val, ty))?; let result = miri_to_const(self.lcx, result)?; self.source = ConstantSource::Constant; Some(result) @@ -655,10 +655,10 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { } } -pub fn miri_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::ConstantKind<'tcx>) -> Option> { +pub fn miri_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::Const<'tcx>) -> Option> { use rustc_middle::mir::ConstValue; match result { - mir::ConstantKind::Val(ConstValue::Scalar(Scalar::Int(int)), _) => match result.ty().kind() { + mir::Const::Val(ConstValue::Scalar(Scalar::Int(int)), _) => match result.ty().kind() { ty::Adt(adt_def, _) if adt_def.is_struct() => Some(Constant::Adt(result)), ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)), ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.assert_bits(int.size()))), @@ -671,11 +671,11 @@ pub fn miri_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::ConstantKind<'t ty::RawPtr(_) => Some(Constant::RawPtr(int.assert_bits(int.size()))), _ => None, }, - mir::ConstantKind::Val(cv, _) if matches!(result.ty().kind(), ty::Ref(_, inner_ty, _) if matches!(inner_ty.kind(), ty::Str)) => { + mir::Const::Val(cv, _) if matches!(result.ty().kind(), ty::Ref(_, inner_ty, _) if matches!(inner_ty.kind(), ty::Str)) => { let data = cv.try_get_slice_bytes_for_diagnostics(lcx.tcx)?; String::from_utf8(data.to_owned()).ok().map(Constant::Str) } - mir::ConstantKind::Val(ConstValue::Indirect { alloc_id, offset: _ }, _) => { + mir::Const::Val(ConstValue::Indirect { alloc_id, offset: _ }, _) => { let alloc = lcx.tcx.global_alloc(alloc_id).unwrap_memory(); match result.ty().kind() { ty::Adt(adt_def, _) if adt_def.is_struct() => Some(Constant::Adt(result)), @@ -714,17 +714,17 @@ pub fn miri_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::ConstantKind<'t fn field_of_struct<'tcx>( adt_def: ty::AdtDef<'tcx>, lcx: &LateContext<'tcx>, - result: mir::ConstantKind<'tcx>, + result: mir::Const<'tcx>, field: &Ident, -) -> Option> { - if let mir::ConstantKind::Val(result, ty) = result +) -> Option> { + if let mir::Const::Val(result, ty) = result && let Some(dc) = lcx.tcx.try_destructure_mir_constant_for_diagnostics((result, ty)) && let Some(dc_variant) = dc.variant && let Some(variant) = adt_def.variants().get(dc_variant) && let Some(field_idx) = variant.fields.iter().position(|el| el.name == field.name) && let Some(&(val, ty)) = dc.fields.get(field_idx) { - Some(mir::ConstantKind::Val(val, ty)) + Some(mir::Const::Val(val, ty)) } else { None diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 4ef3ec19647e..1e464db8087e 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -97,7 +97,7 @@ use rustc_hir::{ use rustc_lexer::{tokenize, TokenKind}; use rustc_lint::{LateContext, Level, Lint, LintContext}; use rustc_middle::hir::place::PlaceBase; -use rustc_middle::mir::ConstantKind; +use rustc_middle::mir::Const; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; use rustc_middle::ty::binding::BindingMode; use rustc_middle::ty::fast_reject::SimplifiedType; @@ -1510,7 +1510,7 @@ pub fn is_range_full(cx: &LateContext<'_>, expr: &Expr<'_>, container_path: Opti && let bnd_ty = subst.type_at(0) && let Some(min_val) = bnd_ty.numeric_min_val(cx.tcx) && let const_val = cx.tcx.valtree_to_const_val((bnd_ty, min_val.to_valtree())) - && let min_const_kind = ConstantKind::from_value(const_val, bnd_ty) + && let min_const_kind = Const::from_value(const_val, bnd_ty) && let Some(min_const) = miri_to_const(cx, min_const_kind) && let Some(start_const) = constant(cx, cx.typeck_results(), start) { @@ -1526,7 +1526,7 @@ pub fn is_range_full(cx: &LateContext<'_>, expr: &Expr<'_>, container_path: Opti && let bnd_ty = subst.type_at(0) && let Some(max_val) = bnd_ty.numeric_max_val(cx.tcx) && let const_val = cx.tcx.valtree_to_const_val((bnd_ty, max_val.to_valtree())) - && let max_const_kind = ConstantKind::from_value(const_val, bnd_ty) + && let max_const_kind = Const::from_value(const_val, bnd_ty) && let Some(max_const) = miri_to_const(cx, max_const_kind) && let Some(end_const) = constant(cx, cx.typeck_results(), end) { From a6360916e9fca6de5f0b4d13466498cfb6edbc7c Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 18 Sep 2023 15:30:07 +0000 Subject: [PATCH 0937/1222] Prevent promotion of const fn calls in inline consts --- clippy_lints/src/operators/arithmetic_side_effects.rs | 2 +- clippy_lints/src/operators/numeric_arithmetic.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/operators/arithmetic_side_effects.rs b/clippy_lints/src/operators/arithmetic_side_effects.rs index 8072aded8513..a10aa65e5948 100644 --- a/clippy_lints/src/operators/arithmetic_side_effects.rs +++ b/clippy_lints/src/operators/arithmetic_side_effects.rs @@ -315,7 +315,7 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects { let body_owner_def_id = cx.tcx.hir().body_owner_def_id(body.id()); let body_owner_kind = cx.tcx.hir().body_owner_kind(body_owner_def_id); - if let hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) = body_owner_kind { + if let hir::BodyOwnerKind::Const { .. } | hir::BodyOwnerKind::Static(_) = body_owner_kind { let body_span = cx.tcx.hir().span_with_body(body_owner); if let Some(span) = self.const_span && span.contains(body_span) { return; diff --git a/clippy_lints/src/operators/numeric_arithmetic.rs b/clippy_lints/src/operators/numeric_arithmetic.rs index 102845ceed09..80389cbf84be 100644 --- a/clippy_lints/src/operators/numeric_arithmetic.rs +++ b/clippy_lints/src/operators/numeric_arithmetic.rs @@ -72,7 +72,7 @@ impl Context { let body_owner_def_id = cx.tcx.hir().body_owner_def_id(body.id()); match cx.tcx.hir().body_owner_kind(body_owner_def_id) { - hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const => { + hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const { .. } => { let body_span = cx.tcx.hir().span_with_body(body_owner); if let Some(span) = self.const_span { From 93f9796133ab89bed060455d5cb03c821cb359ce Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 14 Sep 2023 22:38:07 +0000 Subject: [PATCH 0938/1222] Record asyncness span in HIR --- clippy_lints/src/redundant_closure_call.rs | 7 ++++--- clippy_utils/src/lib.rs | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index fc49b58e0a77..f42836611ca5 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -10,6 +10,7 @@ use rustc_hir::intravisit::{Visitor as HirVisitor, Visitor}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; +use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { @@ -84,7 +85,7 @@ fn find_innermost_closure<'tcx>( cx: &LateContext<'tcx>, mut expr: &'tcx hir::Expr<'tcx>, mut steps: usize, -) -> Option<(&'tcx hir::Expr<'tcx>, &'tcx hir::FnDecl<'tcx>, hir::IsAsync)> { +) -> Option<(&'tcx hir::Expr<'tcx>, &'tcx hir::FnDecl<'tcx>, ty::Asyncness)> { let mut data = None; while let hir::ExprKind::Closure(closure) = expr.kind @@ -98,9 +99,9 @@ fn find_innermost_closure<'tcx>( { expr = body.value; data = Some((body.value, closure.fn_decl, if is_async_closure(body) { - hir::IsAsync::Async + ty::Asyncness::Yes } else { - hir::IsAsync::NotAsync + ty::Asyncness::No })); steps -= 1; } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 1e464db8087e..be1c46319c2b 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -90,7 +90,7 @@ use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk}; use rustc_hir::{ self as hir, def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Closure, Destination, Expr, - ExprField, ExprKind, FnDecl, FnRetTy, GenericArgs, HirId, Impl, ImplItem, ImplItemKind, ImplItemRef, IsAsync, Item, + ExprField, ExprKind, FnDecl, FnRetTy, GenericArgs, HirId, Impl, ImplItem, ImplItemKind, ImplItemRef, Item, ItemKind, LangItem, Local, MatchSource, Mutability, Node, OwnerId, Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitItemRef, TraitRef, TyKind, UnOp, }; @@ -1958,8 +1958,8 @@ pub fn if_sequence<'tcx>(mut expr: &'tcx Expr<'tcx>) -> (Vec<&'tcx Expr<'tcx>>, /// Checks if the given function kind is an async function. pub fn is_async_fn(kind: FnKind<'_>) -> bool { match kind { - FnKind::ItemFn(_, _, header) => header.asyncness == IsAsync::Async, - FnKind::Method(_, sig) => sig.header.asyncness == IsAsync::Async, + FnKind::ItemFn(_, _, header) => header.asyncness .is_async(), + FnKind::Method(_, sig) => sig.header.asyncness.is_async(), FnKind::Closure => false, } } From 7c73d1589e7f6dcfa4ef56d8409af61f8d25a8c3 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 9 Sep 2023 08:36:50 +0200 Subject: [PATCH 0939/1222] adjust how closure/generator types and rvalues are printed --- tests/ui/box_default.fixed | 2 +- tests/ui/box_default.rs | 2 +- tests/ui/crashes/ice-6251.stderr | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ui/box_default.fixed b/tests/ui/box_default.fixed index 22c034c88ab1..69cabcb32d33 100644 --- a/tests/ui/box_default.fixed +++ b/tests/ui/box_default.fixed @@ -36,7 +36,7 @@ fn main() { issue_10381(); // `Box::>::default()` would be valid here, but not `Box::default()` or - // `Box::::default()` + // `Box::::default()` // // Would have a suggestion after https://github.com/rust-lang/rust/blob/fdd030127cc68afec44a8d3f6341525dd34e50ae/compiler/rustc_middle/src/ty/diagnostics.rs#L554-L563 let mut unnameable = Box::new(Option::default()); diff --git a/tests/ui/box_default.rs b/tests/ui/box_default.rs index 89e3888ba211..48fa8bc33bc2 100644 --- a/tests/ui/box_default.rs +++ b/tests/ui/box_default.rs @@ -36,7 +36,7 @@ fn main() { issue_10381(); // `Box::>::default()` would be valid here, but not `Box::default()` or - // `Box::::default()` + // `Box::::default()` // // Would have a suggestion after https://github.com/rust-lang/rust/blob/fdd030127cc68afec44a8d3f6341525dd34e50ae/compiler/rustc_middle/src/ty/diagnostics.rs#L554-L563 let mut unnameable = Box::new(Option::default()); diff --git a/tests/ui/crashes/ice-6251.stderr b/tests/ui/crashes/ice-6251.stderr index 68a5766c90c0..11081dc8087e 100644 --- a/tests/ui/crashes/ice-6251.stderr +++ b/tests/ui/crashes/ice-6251.stderr @@ -27,7 +27,7 @@ LL | fn bug() -> impl Iterator { | ^^^^^^^^^^^ expected `usize`, found closure | = note: expected type `usize` - found closure `[closure@$DIR/ice-6251.rs:4:44: 4:53]` + found closure `{closure@$DIR/ice-6251.rs:4:44: 4:53}` error: aborting due to 3 previous errors From 39aff885bd5122e69034c90ccd600cb06cf039f1 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Fri, 22 Sep 2023 00:05:45 +0000 Subject: [PATCH 0940/1222] fix clippy errors (ignore effects in certainty) --- clippy_utils/src/ty/type_certainty/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/ty/type_certainty/mod.rs b/clippy_utils/src/ty/type_certainty/mod.rs index dc7756533acb..4b06b12fb94d 100644 --- a/clippy_utils/src/ty/type_certainty/mod.rs +++ b/clippy_utils/src/ty/type_certainty/mod.rs @@ -207,7 +207,8 @@ fn path_segment_certainty( // Checking `res_generics_def_id(..)` before calling `generics_of` avoids an ICE. if cx.tcx.res_generics_def_id(path_segment.res).is_some() { let generics = cx.tcx.generics_of(def_id); - let lhs = if (parent_certainty.is_certain() || generics.parent_count == 0) && generics.params.is_empty() + let count = generics.params.len() - generics.host_effect_index.is_some() as usize; + let lhs = if (parent_certainty.is_certain() || generics.parent_count == 0) && count == 0 { Certainty::Certain(None) } else { @@ -299,7 +300,7 @@ fn type_is_inferrable_from_arguments(cx: &LateContext<'_>, expr: &Expr<'_>) -> b // Check that all type parameters appear in the functions input types. (0..(generics.parent_count + generics.params.len()) as u32).all(|index| { - fn_sig + Some(index as usize) == generics.host_effect_index || fn_sig .inputs() .iter() .any(|input_ty| contains_param(*input_ty.skip_binder(), index)) From f2e4e48830a199887ea930bc613e136dd60f0f0b Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 22 Sep 2023 09:14:39 +0000 Subject: [PATCH 0941/1222] Add a way to decouple the implementation and the declaration of a TyCtxt method. --- clippy_utils/src/consts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index a136de862408..6b1a738aaa94 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -718,7 +718,7 @@ fn field_of_struct<'tcx>( field: &Ident, ) -> Option> { if let mir::Const::Val(result, ty) = result - && let Some(dc) = lcx.tcx.try_destructure_mir_constant_for_diagnostics((result, ty)) + && let Some(dc) = lcx.tcx.try_destructure_mir_constant_for_diagnostics(result, ty) && let Some(dc_variant) = dc.variant && let Some(variant) = adt_def.variants().get(dc_variant) && let Some(field_idx) = variant.fields.iter().position(|el| el.name == field.name) From ec96ce3d7e3d3dbe08a7ebbe1e112888f42dbc37 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 28 Jan 2023 12:56:04 +0000 Subject: [PATCH 0942/1222] Enable drop_tracking_mir by default. --- clippy_lints/src/await_holding_invalid.rs | 43 +++++++++++++---------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index d40a385435af..7dd808a7b3b7 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -2,9 +2,9 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::{match_def_path, paths}; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::DefId; -use rustc_hir::{AsyncGeneratorKind, Body, BodyId, GeneratorKind}; +use rustc_hir::{AsyncGeneratorKind, Body, GeneratorKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::GeneratorInteriorTypeCause; +use rustc_middle::mir::GeneratorLayout; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{sym, Span}; @@ -197,28 +197,35 @@ impl LateLintPass<'_> for AwaitHolding { fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { use AsyncGeneratorKind::{Block, Closure, Fn}; if let Some(GeneratorKind::Async(Block | Closure | Fn)) = body.generator_kind { - let body_id = BodyId { - hir_id: body.value.hir_id, - }; - let typeck_results = cx.tcx.typeck_body(body_id); - self.check_interior_types( - cx, - typeck_results.generator_interior_types.as_ref().skip_binder(), - body.value.span, - ); + let def_id = cx.tcx.hir().body_owner_def_id(body.id()); + if let Some(generator_layout) = cx.tcx.mir_generator_witnesses(def_id) { + self.check_interior_types(cx, generator_layout); + } } } } impl AwaitHolding { - fn check_interior_types(&self, cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorTypeCause<'_>], span: Span) { - for ty_cause in ty_causes { + fn check_interior_types(&self, cx: &LateContext<'_>, generator: &GeneratorLayout<'_>) { + for (ty_index, ty_cause) in generator.field_tys.iter_enumerated() { if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind() { + let await_points = || { + generator + .variant_source_info + .iter_enumerated() + .filter_map(|(variant, source_info)| { + generator.variant_fields[variant] + .raw + .contains(&ty_index) + .then_some(source_info.span) + }) + .collect::>() + }; if is_mutex_guard(cx, adt.did()) { span_lint_and_then( cx, AWAIT_HOLDING_LOCK, - ty_cause.span, + ty_cause.source_info.span, "this `MutexGuard` is held across an `await` point", |diag| { diag.help( @@ -226,7 +233,7 @@ impl AwaitHolding { `MutexGuard` is dropped before calling await", ); diag.span_note( - ty_cause.scope_span.unwrap_or(span), + await_points(), "these are all the `await` points this lock is held through", ); }, @@ -235,18 +242,18 @@ impl AwaitHolding { span_lint_and_then( cx, AWAIT_HOLDING_REFCELL_REF, - ty_cause.span, + ty_cause.source_info.span, "this `RefCell` reference is held across an `await` point", |diag| { diag.help("ensure the reference is dropped before calling `await`"); diag.span_note( - ty_cause.scope_span.unwrap_or(span), + await_points(), "these are all the `await` points this reference is held through", ); }, ); } else if let Some(disallowed) = self.def_ids.get(&adt.did()) { - emit_invalid_type(cx, ty_cause.span, disallowed); + emit_invalid_type(cx, ty_cause.source_info.span, disallowed); } } } From f209a590d721052ba77ae4fac89d92ac51f6cec4 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 28 Jan 2023 23:20:02 +0000 Subject: [PATCH 0943/1222] Bless clippy. --- .../await_holding_invalid_type.rs | 6 +- .../await_holding_invalid_type.stderr | 6 +- tests/ui/await_holding_lock.stderr | 137 ++++++------------ tests/ui/await_holding_refcell_ref.stderr | 67 +++------ tests/ui/future_not_send.rs | 1 + tests/ui/future_not_send.stderr | 36 +---- 6 files changed, 87 insertions(+), 166 deletions(-) diff --git a/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs b/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs index fbef5c4564b1..868cf00a8d46 100644 --- a/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs +++ b/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs @@ -7,8 +7,10 @@ async fn bad() -> u32 { } async fn bad_reason() -> u32 { - let _x = Ipv4Addr::new(127, 0, 0, 1); - baz().await + let x = Ipv4Addr::new(127, 0, 0, 1); + let y = baz().await; + let _x = x; + y } async fn good() -> u32 { diff --git a/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr b/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr index 6f8b04fd12b9..ddcd1940d475 100644 --- a/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr +++ b/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr @@ -11,11 +11,11 @@ LL | let _x = String::from("hello"); error: `std::net::Ipv4Addr` may not be held across an `await` point per `clippy.toml` --> $DIR/await_holding_invalid_type.rs:10:9 | -LL | let _x = Ipv4Addr::new(127, 0, 0, 1); - | ^^ +LL | let x = Ipv4Addr::new(127, 0, 0, 1); + | ^ error: `std::string::String` may not be held across an `await` point per `clippy.toml` - --> $DIR/await_holding_invalid_type.rs:31:13 + --> $DIR/await_holding_invalid_type.rs:33:13 | LL | let _x = String::from("hi!"); | ^^ diff --git a/tests/ui/await_holding_lock.stderr b/tests/ui/await_holding_lock.stderr index 56b111c4d9e4..478210400022 100644 --- a/tests/ui/await_holding_lock.stderr +++ b/tests/ui/await_holding_lock.stderr @@ -6,13 +6,10 @@ LL | let guard = x.lock().unwrap(); | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:9:9 + --> $DIR/await_holding_lock.rs:11:15 | -LL | / let guard = x.lock().unwrap(); -LL | | -LL | | baz().await -LL | | } - | |_____^ +LL | baz().await + | ^^^^^ = note: `-D clippy::await-holding-lock` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::await_holding_lock)]` @@ -24,13 +21,10 @@ LL | let guard = x.read().unwrap(); | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:25:9 + --> $DIR/await_holding_lock.rs:27:15 | -LL | / let guard = x.read().unwrap(); -LL | | -LL | | baz().await -LL | | } - | |_____^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point --> $DIR/await_holding_lock.rs:31:13 @@ -40,13 +34,10 @@ LL | let mut guard = x.write().unwrap(); | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:31:9 + --> $DIR/await_holding_lock.rs:33:15 | -LL | / let mut guard = x.write().unwrap(); -LL | | -LL | | baz().await -LL | | } - | |_____^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point --> $DIR/await_holding_lock.rs:53:13 @@ -56,16 +47,13 @@ LL | let guard = x.lock().unwrap(); | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:53:9 - | -LL | / let guard = x.lock().unwrap(); -LL | | -LL | | -LL | | let second = baz().await; -... | -LL | | first + second + third -LL | | } - | |_____^ + --> $DIR/await_holding_lock.rs:56:28 + | +LL | let second = baz().await; + | ^^^^^ +LL | +LL | let third = baz().await; + | ^^^^^ error: this `MutexGuard` is held across an `await` point --> $DIR/await_holding_lock.rs:67:17 @@ -75,13 +63,10 @@ LL | let guard = x.lock().unwrap(); | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:67:13 + --> $DIR/await_holding_lock.rs:69:19 | -LL | / let guard = x.lock().unwrap(); -LL | | -LL | | baz().await -LL | | }; - | |_________^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point --> $DIR/await_holding_lock.rs:80:17 @@ -91,13 +76,10 @@ LL | let guard = x.lock().unwrap(); | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:80:13 + --> $DIR/await_holding_lock.rs:82:19 | -LL | / let guard = x.lock().unwrap(); -LL | | -LL | | baz().await -LL | | } - | |_________^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point --> $DIR/await_holding_lock.rs:93:13 @@ -107,13 +89,10 @@ LL | let guard = x.lock(); | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:93:9 + --> $DIR/await_holding_lock.rs:95:15 | -LL | / let guard = x.lock(); -LL | | -LL | | baz().await -LL | | } - | |_____^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point --> $DIR/await_holding_lock.rs:109:13 @@ -123,13 +102,10 @@ LL | let guard = x.read(); | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:109:9 + --> $DIR/await_holding_lock.rs:111:15 | -LL | / let guard = x.read(); -LL | | -LL | | baz().await -LL | | } - | |_____^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point --> $DIR/await_holding_lock.rs:115:13 @@ -139,13 +115,10 @@ LL | let mut guard = x.write(); | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:115:9 + --> $DIR/await_holding_lock.rs:117:15 | -LL | / let mut guard = x.write(); -LL | | -LL | | baz().await -LL | | } - | |_____^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point --> $DIR/await_holding_lock.rs:137:13 @@ -155,16 +128,13 @@ LL | let guard = x.lock(); | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:137:9 - | -LL | / let guard = x.lock(); -LL | | -LL | | -LL | | let second = baz().await; -... | -LL | | first + second + third -LL | | } - | |_____^ + --> $DIR/await_holding_lock.rs:140:28 + | +LL | let second = baz().await; + | ^^^^^ +LL | +LL | let third = baz().await; + | ^^^^^ error: this `MutexGuard` is held across an `await` point --> $DIR/await_holding_lock.rs:151:17 @@ -174,13 +144,10 @@ LL | let guard = x.lock(); | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:151:13 + --> $DIR/await_holding_lock.rs:153:19 | -LL | / let guard = x.lock(); -LL | | -LL | | baz().await -LL | | }; - | |_________^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point --> $DIR/await_holding_lock.rs:164:17 @@ -190,13 +157,10 @@ LL | let guard = x.lock(); | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:164:13 + --> $DIR/await_holding_lock.rs:166:19 | -LL | / let guard = x.lock(); -LL | | -LL | | baz().await -LL | | } - | |_________^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point --> $DIR/await_holding_lock.rs:185:9 @@ -206,15 +170,10 @@ LL | let mut guard = x.lock().unwrap(); | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:185:5 - | -LL | / let mut guard = x.lock().unwrap(); -LL | | -LL | | *guard += 1; -LL | | drop(guard); -LL | | baz().await; -LL | | } - | |_^ + --> $DIR/await_holding_lock.rs:189:11 + | +LL | baz().await; + | ^^^^^ error: aborting due to 13 previous errors diff --git a/tests/ui/await_holding_refcell_ref.stderr b/tests/ui/await_holding_refcell_ref.stderr index 6b7e1d1afddf..9264af93dc16 100644 --- a/tests/ui/await_holding_refcell_ref.stderr +++ b/tests/ui/await_holding_refcell_ref.stderr @@ -6,13 +6,10 @@ LL | let b = x.borrow(); | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:6:5 + --> $DIR/await_holding_refcell_ref.rs:8:11 | -LL | / let b = x.borrow(); -LL | | -LL | | baz().await -LL | | } - | |_^ +LL | baz().await + | ^^^^^ = note: `-D clippy::await-holding-refcell-ref` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::await_holding_refcell_ref)]` @@ -24,13 +21,10 @@ LL | let b = x.borrow_mut(); | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:12:5 + --> $DIR/await_holding_refcell_ref.rs:14:11 | -LL | / let b = x.borrow_mut(); -LL | | -LL | | baz().await -LL | | } - | |_^ +LL | baz().await + | ^^^^^ error: this `RefCell` reference is held across an `await` point --> $DIR/await_holding_refcell_ref.rs:34:9 @@ -40,16 +34,13 @@ LL | let b = x.borrow_mut(); | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:34:5 - | -LL | / let b = x.borrow_mut(); -LL | | -LL | | -LL | | let second = baz().await; -... | -LL | | first + second + third -LL | | } - | |_^ + --> $DIR/await_holding_refcell_ref.rs:37:24 + | +LL | let second = baz().await; + | ^^^^^ +LL | +LL | let third = baz().await; + | ^^^^^ error: this `RefCell` reference is held across an `await` point --> $DIR/await_holding_refcell_ref.rs:47:9 @@ -59,16 +50,10 @@ LL | let b = x.borrow_mut(); | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:47:5 - | -LL | / let b = x.borrow_mut(); -LL | | -LL | | -LL | | let second = baz().await; -... | -LL | | first + second + third -LL | | } - | |_^ + --> $DIR/await_holding_refcell_ref.rs:50:24 + | +LL | let second = baz().await; + | ^^^^^ error: this `RefCell` reference is held across an `await` point --> $DIR/await_holding_refcell_ref.rs:63:13 @@ -78,13 +63,10 @@ LL | let b = x.borrow_mut(); | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:63:9 + --> $DIR/await_holding_refcell_ref.rs:65:15 | -LL | / let b = x.borrow_mut(); -LL | | -LL | | baz().await -LL | | }; - | |_____^ +LL | baz().await + | ^^^^^ error: this `RefCell` reference is held across an `await` point --> $DIR/await_holding_refcell_ref.rs:76:13 @@ -94,13 +76,10 @@ LL | let b = x.borrow_mut(); | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:76:9 + --> $DIR/await_holding_refcell_ref.rs:78:15 | -LL | / let b = x.borrow_mut(); -LL | | -LL | | baz().await -LL | | } - | |_____^ +LL | baz().await + | ^^^^^ error: aborting due to 6 previous errors diff --git a/tests/ui/future_not_send.rs b/tests/ui/future_not_send.rs index 06090e2713de..9274340b5caa 100644 --- a/tests/ui/future_not_send.rs +++ b/tests/ui/future_not_send.rs @@ -59,6 +59,7 @@ where { let rt = &t; async { true }.await; + let _ = rt; t } diff --git a/tests/ui/future_not_send.stderr b/tests/ui/future_not_send.stderr index e417de723ff3..f43e3c8ff9f7 100644 --- a/tests/ui/future_not_send.stderr +++ b/tests/ui/future_not_send.stderr @@ -12,19 +12,12 @@ LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { LL | LL | async { true }.await | ^^^^^ await occurs here, with `rc` maybe used later -LL | } - | - `rc` is later dropped here = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` -note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:9:20 +note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` + --> $DIR/future_not_send.rs:7:39 | LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { - | ---- has type `&std::cell::Cell` which is not `Send` -LL | -LL | async { true }.await - | ^^^^^ await occurs here, with `cell` maybe used later -LL | } - | - `cell` is later dropped here + | ^^^^ has type `&std::cell::Cell` which is not `Send`, because `std::cell::Cell` is not `Sync` = note: `std::cell::Cell` doesn't implement `std::marker::Sync` = note: `-D clippy::future-not-send` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::future_not_send)]` @@ -43,8 +36,6 @@ LL | pub async fn public_future(rc: Rc<[u8]>) { LL | LL | async { true }.await; | ^^^^^ await occurs here, with `rc` maybe used later -LL | } - | - `rc` is later dropped here = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` error: future cannot be sent between threads safely @@ -93,9 +84,6 @@ LL | async fn private_future(&self) -> usize { LL | LL | async { true }.await; | ^^^^^ await occurs here, with `&self` maybe used later -LL | self.rc.len() -LL | } - | - `&self` is later dropped here = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely @@ -104,16 +92,11 @@ error: future cannot be sent between threads safely LL | pub async fn public_future(&self) { | ^ future returned by `public_future` is not `Send` | -note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:46:31 +note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` + --> $DIR/future_not_send.rs:44:32 | LL | pub async fn public_future(&self) { - | ----- has type `&Dummy` which is not `Send` -LL | -LL | self.private_future().await; - | ^^^^^ await occurs here, with `&self` maybe used later -LL | } - | - `&self` is later dropped here + | ^^^^^ has type `&Dummy` which is not `Send`, because `Dummy` is not `Sync` = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely @@ -129,19 +112,16 @@ LL | let rt = &t; | -- has type `&T` which is not `Send` LL | async { true }.await; | ^^^^^ await occurs here, with `rt` maybe used later -LL | t -LL | } - | - `rt` is later dropped here = note: `T` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:72:34 + --> $DIR/future_not_send.rs:73:34 | LL | async fn unclear_future(t: T) {} | ^ future returned by `unclear_future` is not `Send` | note: captured value is not `Send` - --> $DIR/future_not_send.rs:72:28 + --> $DIR/future_not_send.rs:73:28 | LL | async fn unclear_future(t: T) {} | ^ has type `T` which is not `Send` From 98620b26c2babde363dc4d92cda34c7e5e388727 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 3 Aug 2023 13:47:04 +0000 Subject: [PATCH 0944/1222] Remove GeneratorWitness and rename GeneratorWitnessMIR. --- clippy_lints/src/dereference.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 8090f821d1ff..fe37fd4a0c19 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -940,7 +940,6 @@ impl TyCoercionStability { | ty::FnDef(..) | ty::Generator(..) | ty::GeneratorWitness(..) - | ty::GeneratorWitnessMIR(..) | ty::Closure(..) | ty::Never | ty::Tuple(_) From 767fee33c2581bb46d8bd4b7b5c6caafa334ffb7 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 26 Sep 2023 02:15:32 +0000 Subject: [PATCH 0945/1222] Don't store lazyness in DefKind --- clippy_lints/src/init_numbered_fields.rs | 2 +- clippy_utils/src/lib.rs | 2 +- clippy_utils/src/ty/type_certainty/mod.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/init_numbered_fields.rs b/clippy_lints/src/init_numbered_fields.rs index b00fa104f982..f95d2c2edb1e 100644 --- a/clippy_lints/src/init_numbered_fields.rs +++ b/clippy_lints/src/init_numbered_fields.rs @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for NumberedFields { && fields .iter() .all(|f| f.ident.as_str().as_bytes().iter().all(u8::is_ascii_digit)) - && !matches!(cx.qpath_res(path, e.hir_id), Res::Def(DefKind::TyAlias { .. }, ..)) + && !matches!(cx.qpath_res(path, e.hir_id), Res::Def(DefKind::TyAlias, ..)) { let expr_spans = fields .iter() diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index be1c46319c2b..47cce4603a68 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -288,7 +288,7 @@ pub fn is_wild(pat: &Pat<'_>) -> bool { /// Checks if the given `QPath` belongs to a type alias. pub fn is_ty_alias(qpath: &QPath<'_>) -> bool { match *qpath { - QPath::Resolved(_, path) => matches!(path.res, Res::Def(DefKind::TyAlias { .. } | DefKind::AssocTy, ..)), + QPath::Resolved(_, path) => matches!(path.res, Res::Def(DefKind::TyAlias | DefKind::AssocTy, ..)), QPath::TypeRelative(ty, _) if let TyKind::Path(qpath) = ty.kind => { is_ty_alias(&qpath) }, _ => false, } diff --git a/clippy_utils/src/ty/type_certainty/mod.rs b/clippy_utils/src/ty/type_certainty/mod.rs index 4b06b12fb94d..686a3f41499b 100644 --- a/clippy_utils/src/ty/type_certainty/mod.rs +++ b/clippy_utils/src/ty/type_certainty/mod.rs @@ -220,7 +220,7 @@ fn path_segment_certainty( // See the comment preceding `qpath_certainty`. `def_id` could refer to a type or a value. let certainty = lhs.join_clearing_def_ids(rhs); if resolves_to_type { - if let DefKind::TyAlias { .. } = cx.tcx.def_kind(def_id) { + if let DefKind::TyAlias = cx.tcx.def_kind(def_id) { adt_def_id(cx.tcx.type_of(def_id).instantiate_identity()) .map_or(certainty, |def_id| certainty.with_def_id(def_id)) } else { From f7aa349f647b2c3e0929671507975c5e3f27f865 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 25 Sep 2023 15:46:38 +0200 Subject: [PATCH 0946/1222] subst -> instantiate --- clippy_lints/src/methods/unnecessary_to_owned.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 5c5ee2620528..50d6f3b7e55f 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -401,7 +401,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< = get_callee_generic_args_and_args(cx, parent_expr) { // FIXME: the `instantiate_identity()` below seems incorrect, since we eventually - // call `tcx.try_subst_and_normalize_erasing_regions` further down + // call `tcx.try_instantiate_and_normalize_erasing_regions` further down // (i.e., we are explicitly not in the identity context). let fn_sig = cx.tcx.fn_sig(callee_def_id).instantiate_identity().skip_binder(); if let Some(arg_index) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == expr.hir_id) @@ -452,7 +452,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< let output_ty = fn_sig.output(); if output_ty.contains(*param_ty) { - if let Ok(new_ty) = cx.tcx.try_subst_and_normalize_erasing_regions( + if let Ok(new_ty) = cx.tcx.try_instantiate_and_normalize_erasing_regions( new_subst, cx.param_env, EarlyBinder::bind(output_ty)) { expr = parent_expr; ty = new_ty; From 80f288436e6d3f3fbec9c892c459b8638f01aa77 Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Sun, 27 Aug 2023 11:43:45 +0000 Subject: [PATCH 0947/1222] Move needless_raw_string_hashes to pedantic --- clippy_lints/src/raw_strings.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/raw_strings.rs b/clippy_lints/src/raw_strings.rs index 2895595e0390..8a7e48746661 100644 --- a/clippy_lints/src/raw_strings.rs +++ b/clippy_lints/src/raw_strings.rs @@ -50,7 +50,7 @@ declare_clippy_lint! { /// ``` #[clippy::version = "1.72.0"] pub NEEDLESS_RAW_STRING_HASHES, - style, + pedantic, "suggests reducing the number of hashes around a raw string literal" } impl_lint_pass!(RawStrings => [NEEDLESS_RAW_STRINGS, NEEDLESS_RAW_STRING_HASHES]); From e77dc479b4374897f3154452afcfbfa4af4eae1f Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Thu, 28 Sep 2023 16:00:38 +0200 Subject: [PATCH 0948/1222] Remove `rustc_lint_defs::lint_array` --- .../src/utils/internal_lints/lint_without_lint_pass.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs b/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs index 87380f14f9a4..bbb5ade8b9f3 100644 --- a/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs +++ b/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs @@ -28,8 +28,8 @@ declare_clippy_lint! { /// know the name of the lint. /// /// ### Known problems - /// Only checks for lints associated using the - /// `declare_lint_pass!`, `impl_lint_pass!`, and `lint_array!` macros. + /// Only checks for lints associated using the `declare_lint_pass!` and + /// `impl_lint_pass!` macros. /// /// ### Example /// ```rust,ignore From 09a1bfbb62d2c7ee6a7990fb34bb767f420d1e38 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 28 Sep 2023 23:50:56 +0000 Subject: [PATCH 0949/1222] Reverse postorder instead of using reversed postorder --- clippy_utils/src/mir/mod.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/clippy_utils/src/mir/mod.rs b/clippy_utils/src/mir/mod.rs index f04467dc19d3..9dbb4c68d13f 100644 --- a/clippy_utils/src/mir/mod.rs +++ b/clippy_utils/src/mir/mod.rs @@ -30,20 +30,26 @@ pub fn visit_local_usage(locals: &[Local], mir: &Body<'_>, location: Location) - locals.len() ]; - traversal::ReversePostorder::new(mir, location.block).try_fold(init, |usage, (tbb, tdata)| { - // Give up on loops - if tdata.terminator().successors().any(|s| s == location.block) { - return None; - } + traversal::Postorder::new(&mir.basic_blocks, location.block) + .collect::>() + .into_iter() + .rev() + .try_fold(init, |usage, tbb| { + let tdata = &mir.basic_blocks[tbb]; + + // Give up on loops + if tdata.terminator().successors().any(|s| s == location.block) { + return None; + } - let mut v = V { - locals, - location, - results: usage, - }; - v.visit_basic_block_data(tbb, tdata); - Some(v.results) - }) + let mut v = V { + locals, + location, + results: usage, + }; + v.visit_basic_block_data(tbb, tdata); + Some(v.results) + }) } struct V<'a> { From e394a7f1f39957b9298e95b99e529c97f057f776 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Wed, 16 Aug 2023 08:43:30 +0300 Subject: [PATCH 0950/1222] subtyping_projections --- clippy_utils/src/qualify_min_const_fn.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 17233058c9c9..55f9cb27ad4d 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -272,6 +272,7 @@ fn check_place<'tcx>(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &B | ProjectionElem::Downcast(..) | ProjectionElem::Subslice { .. } | ProjectionElem::Deref + | ProjectionElem::Subtype(_) | ProjectionElem::Index(_) => {}, } } From d651f4ebf87ea05520a03b0f1c5fb2b885062f79 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 2 Oct 2023 21:31:46 +0000 Subject: [PATCH 0951/1222] Point to full async fn for future --- tests/ui/crashes/ice-10645.stderr | 4 ++-- tests/ui/future_not_send.stderr | 37 +++++++++++++++++-------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/tests/ui/crashes/ice-10645.stderr b/tests/ui/crashes/ice-10645.stderr index fc5347c86cde..7fc62d4fcf85 100644 --- a/tests/ui/crashes/ice-10645.stderr +++ b/tests/ui/crashes/ice-10645.stderr @@ -1,8 +1,8 @@ warning: future cannot be sent between threads safely - --> $DIR/ice-10645.rs:5:35 + --> $DIR/ice-10645.rs:5:1 | LL | pub async fn bar<'a, T: 'a>(_: T) {} - | ^ future returned by `bar` is not `Send` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `bar` is not `Send` | note: captured value is not `Send` --> $DIR/ice-10645.rs:5:29 diff --git a/tests/ui/future_not_send.stderr b/tests/ui/future_not_send.stderr index f43e3c8ff9f7..7ef4947f1d6c 100644 --- a/tests/ui/future_not_send.stderr +++ b/tests/ui/future_not_send.stderr @@ -1,8 +1,8 @@ error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:7:62 + --> $DIR/future_not_send.rs:7:1 | LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { - | ^^^^ future returned by `private_future` is not `Send` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `private_future` is not `Send` | note: future is not `Send` as this value is used across an await --> $DIR/future_not_send.rs:9:20 @@ -23,10 +23,10 @@ LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { = help: to override `-D warnings` add `#[allow(clippy::future_not_send)]` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:12:42 + --> $DIR/future_not_send.rs:12:1 | LL | pub async fn public_future(rc: Rc<[u8]>) { - | ^ future returned by `public_future` is not `Send` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `public_future` is not `Send` | note: future is not `Send` as this value is used across an await --> $DIR/future_not_send.rs:14:20 @@ -39,10 +39,10 @@ LL | async { true }.await; = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:21:63 + --> $DIR/future_not_send.rs:21:1 | LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { - | ^^^^ future returned by `private_future2` is not `Send` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `private_future2` is not `Send` | note: captured value is not `Send` --> $DIR/future_not_send.rs:21:26 @@ -58,10 +58,10 @@ LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { = note: `std::cell::Cell` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:26:43 + --> $DIR/future_not_send.rs:26:1 | LL | pub async fn public_future2(rc: Rc<[u8]>) {} - | ^ future returned by `public_future2` is not `Send` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `public_future2` is not `Send` | note: captured value is not `Send` --> $DIR/future_not_send.rs:26:29 @@ -71,10 +71,10 @@ LL | pub async fn public_future2(rc: Rc<[u8]>) {} = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:38:39 + --> $DIR/future_not_send.rs:38:5 | LL | async fn private_future(&self) -> usize { - | ^^^^^ future returned by `private_future` is not `Send` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `private_future` is not `Send` | note: future is not `Send` as this value is used across an await --> $DIR/future_not_send.rs:40:24 @@ -87,10 +87,10 @@ LL | async { true }.await; = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:44:39 + --> $DIR/future_not_send.rs:44:5 | LL | pub async fn public_future(&self) { - | ^ future returned by `public_future` is not `Send` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `public_future` is not `Send` | note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` --> $DIR/future_not_send.rs:44:32 @@ -100,10 +100,13 @@ LL | pub async fn public_future(&self) { = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:55:37 + --> $DIR/future_not_send.rs:55:1 | -LL | async fn generic_future(t: T) -> T - | ^ future returned by `generic_future` is not `Send` +LL | / async fn generic_future(t: T) -> T +LL | | +LL | | where +LL | | T: Send, + | |____________^ future returned by `generic_future` is not `Send` | note: future is not `Send` as this value is used across an await --> $DIR/future_not_send.rs:61:20 @@ -115,10 +118,10 @@ LL | async { true }.await; = note: `T` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:73:34 + --> $DIR/future_not_send.rs:73:1 | LL | async fn unclear_future(t: T) {} - | ^ future returned by `unclear_future` is not `Send` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `unclear_future` is not `Send` | note: captured value is not `Send` --> $DIR/future_not_send.rs:73:28 From 672778d9806830b955b278e56eeb102f926fcdb8 Mon Sep 17 00:00:00 2001 From: Ikko Eltociear Ashimine Date: Thu, 5 Oct 2023 00:03:04 +0900 Subject: [PATCH 0952/1222] Fix typo in attrs.rs documenation -> documentation --- clippy_lints/src/attrs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 0546807bac4f..db01ddbde04e 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -183,7 +183,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Checks for empty lines after documenation comments. + /// Checks for empty lines after documentation comments. /// /// ### Why is this bad? /// The documentation comment was most likely meant to be an inner attribute or regular comment. @@ -795,7 +795,7 @@ impl EarlyLintPass for EarlyAttributes { /// Check for empty lines after outer attributes. /// -/// Attributes and documenation comments are both considered outer attributes +/// Attributes and documentation comments are both considered outer attributes /// by the AST. However, the average user likely considers them to be different. /// Checking for empty lines after each of these attributes is split into two different /// lints but can share the same logic. From edd1fa2765461f7e2228dfff42c908fd89f738bf Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 2 Oct 2023 21:24:23 +0000 Subject: [PATCH 0953/1222] Fix clippy --- clippy_lints/src/methods/unnecessary_literal_unwrap.rs | 8 ++------ .../ui-toml/too_many_arguments/too_many_arguments.stderr | 2 +- tests/ui/crashes/ice-6251.stderr | 4 ++-- tests/ui/functions.stderr | 6 +++--- tests/ui/must_use_unit.stderr | 4 ++-- tests/ui/unnecessary_literal_unwrap.fixed | 4 ++-- tests/ui/unnecessary_literal_unwrap.stderr | 4 ++-- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs index 937aac8d25ef..24c0ea3f60a9 100644 --- a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs +++ b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs @@ -102,14 +102,10 @@ pub(super) fn check( ]), ("None", "unwrap_or_else", _) => match args[0].kind { hir::ExprKind::Closure(hir::Closure { - fn_decl: - hir::FnDecl { - output: hir::FnRetTy::DefaultReturn(span) | hir::FnRetTy::Return(hir::Ty { span, .. }), - .. - }, + body, .. }) => Some(vec![ - (expr.span.with_hi(span.hi()), String::new()), + (expr.span.with_hi(cx.tcx.hir().body(*body).value.span.lo()), String::new()), (expr.span.with_lo(args[0].span.hi()), String::new()), ]), _ => None, diff --git a/tests/ui-toml/too_many_arguments/too_many_arguments.stderr b/tests/ui-toml/too_many_arguments/too_many_arguments.stderr index a52e1fcb9e3a..8b9d159b59c3 100644 --- a/tests/ui-toml/too_many_arguments/too_many_arguments.stderr +++ b/tests/ui-toml/too_many_arguments/too_many_arguments.stderr @@ -2,7 +2,7 @@ error: this function has too many arguments (11/10) --> $DIR/too_many_arguments.rs:4:1 | LL | fn too_many(p1: u8, p2: u8, p3: u8, p4: u8, p5: u8, p6: u8, p7: u8, p8: u8, p9: u8, p10: u8, p11: u8) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::too-many-arguments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::too_many_arguments)]` diff --git a/tests/ui/crashes/ice-6251.stderr b/tests/ui/crashes/ice-6251.stderr index 11081dc8087e..aaebdabcbd5e 100644 --- a/tests/ui/crashes/ice-6251.stderr +++ b/tests/ui/crashes/ice-6251.stderr @@ -12,10 +12,10 @@ LL | fn bug() -> impl Iterator { | + error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/ice-6251.rs:4:54 + --> $DIR/ice-6251.rs:4:53 | LL | fn bug() -> impl Iterator { - | ^ doesn't have a size known at compile-time + | ^ doesn't have a size known at compile-time | = help: the trait `std::marker::Sized` is not implemented for `[u8]` = note: the return type of a function must have a statically known size diff --git a/tests/ui/functions.stderr b/tests/ui/functions.stderr index 371ea1612601..4b06cd038899 100644 --- a/tests/ui/functions.stderr +++ b/tests/ui/functions.stderr @@ -2,7 +2,7 @@ error: this function has too many arguments (8/7) --> $DIR/functions.rs:8:1 | LL | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::too-many-arguments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::too_many_arguments)]` @@ -17,7 +17,7 @@ LL | | two: u32, ... | LL | | eight: () LL | | ) { - | |__^ + | |_^ error: this function has too many arguments (8/7) --> $DIR/functions.rs:48:5 @@ -29,7 +29,7 @@ error: this function has too many arguments (8/7) --> $DIR/functions.rs:58:5 | LL | fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this public function might dereference a raw pointer but is not marked `unsafe` --> $DIR/functions.rs:68:34 diff --git a/tests/ui/must_use_unit.stderr b/tests/ui/must_use_unit.stderr index e67d9b5b9d8d..f2ee185857d3 100644 --- a/tests/ui/must_use_unit.stderr +++ b/tests/ui/must_use_unit.stderr @@ -4,7 +4,7 @@ error: this unit-returning function has a `#[must_use]` attribute LL | #[must_use] | ----------- help: remove the attribute LL | pub fn must_use_default() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::must-use-unit` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::must_use_unit)]` @@ -23,7 +23,7 @@ error: this unit-returning function has a `#[must_use]` attribute LL | #[must_use = "With note"] | ------------------------- help: remove the attribute LL | pub fn must_use_with_note() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/tests/ui/unnecessary_literal_unwrap.fixed b/tests/ui/unnecessary_literal_unwrap.fixed index 87df1f8cb08f..b17343aa9ba5 100644 --- a/tests/ui/unnecessary_literal_unwrap.fixed +++ b/tests/ui/unnecessary_literal_unwrap.fixed @@ -23,7 +23,7 @@ fn unwrap_option_none() { let _val: u16 = 234; let _val: u16 = 234; let _val: u16 = { 234 }; - let _val: u16 = { 234 }; + let _val: u16 = { 234 }; panic!(); panic!("this always happens"); @@ -31,7 +31,7 @@ fn unwrap_option_none() { 234; 234; { 234 }; - { 234 }; + { 234 }; } fn unwrap_result_ok() { diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr index 013907f59c46..4940091be60a 100644 --- a/tests/ui/unnecessary_literal_unwrap.stderr +++ b/tests/ui/unnecessary_literal_unwrap.stderr @@ -116,7 +116,7 @@ LL | let _val: u16 = None.unwrap_or_else(|| -> u16 { 234 }); help: remove the `None` and `unwrap_or_else()` | LL - let _val: u16 = None.unwrap_or_else(|| -> u16 { 234 }); -LL + let _val: u16 = { 234 }; +LL + let _val: u16 = { 234 }; | error: used `unwrap()` on `None` value @@ -187,7 +187,7 @@ LL | None::.unwrap_or_else(|| -> u16 { 234 }); help: remove the `None` and `unwrap_or_else()` | LL - None::.unwrap_or_else(|| -> u16 { 234 }); -LL + { 234 }; +LL + { 234 }; | error: used `unwrap()` on `Ok` value From bd6590a70ea532b87a430a8991f2ca1789e5dc4a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 2 Oct 2023 21:39:07 +0000 Subject: [PATCH 0954/1222] Point to closure return instead of output if defaulted --- tests/ui/crashes/ice-6251.stderr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/crashes/ice-6251.stderr b/tests/ui/crashes/ice-6251.stderr index aaebdabcbd5e..11081dc8087e 100644 --- a/tests/ui/crashes/ice-6251.stderr +++ b/tests/ui/crashes/ice-6251.stderr @@ -12,10 +12,10 @@ LL | fn bug() -> impl Iterator { | + error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/ice-6251.rs:4:53 + --> $DIR/ice-6251.rs:4:54 | LL | fn bug() -> impl Iterator { - | ^ doesn't have a size known at compile-time + | ^ doesn't have a size known at compile-time | = help: the trait `std::marker::Sized` is not implemented for `[u8]` = note: the return type of a function must have a statically known size From 7250871cc6980ba4fb6ca3323c496a495a3d3d35 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 5 Oct 2023 16:08:07 +1100 Subject: [PATCH 0955/1222] Rename `Features::active_features`. The word "active" is currently used in two different and confusing ways: - `ACTIVE_FEATURES` actually means "available unstable features" - `Features::active_features` actually means "features declared in the crate's code", which can include feature within `ACTIVE_FEATURES` but also others. (This is also distinct from "enabled" features which includes declared features but also some edition-specific features automatically enabled depending on the edition in use.) This commit changes the `Features::active_features` to `Features::declared_features` which actually matches its meaning. Likewise, `Features::active` becomes `Features::declared`. --- clippy_lints/src/manual_float_methods.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/manual_float_methods.rs b/clippy_lints/src/manual_float_methods.rs index 88db7ae6aece..15c8417e7028 100644 --- a/clippy_lints/src/manual_float_methods.rs +++ b/clippy_lints/src/manual_float_methods.rs @@ -85,7 +85,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods { if !in_external_macro(cx.sess(), expr.span) && ( matches!(cx.tcx.constness(cx.tcx.hir().enclosing_body_owner(expr.hir_id)), Constness::NotConst) - || cx.tcx.features().active(sym!(const_float_classify)) + || cx.tcx.features().declared(sym!(const_float_classify)) ) && let ExprKind::Binary(kind, lhs, rhs) = expr.kind && let ExprKind::Binary(lhs_kind, lhs_lhs, lhs_rhs) = lhs.kind && let ExprKind::Binary(rhs_kind, rhs_lhs, rhs_rhs) = rhs.kind From ab52199be0662c42cd8ef5d340352154ea8c3abc Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Tue, 26 Sep 2023 23:56:38 -0400 Subject: [PATCH 0956/1222] Add more diagnostic items for clippy --- clippy_lints/src/await_holding_invalid.rs | 2 +- clippy_lints/src/box_default.rs | 14 +-- clippy_lints/src/casts/cast_ptr_alignment.rs | 19 ++-- .../src/casts/cast_slice_from_raw_parts.rs | 12 +-- clippy_lints/src/create_dir.rs | 4 +- clippy_lints/src/default.rs | 10 +- .../src/default_constructed_unit_structs.rs | 5 +- .../src/default_instead_of_iter_empty.rs | 6 +- clippy_lints/src/exit.rs | 5 +- clippy_lints/src/explicit_write.rs | 28 +++--- clippy_lints/src/from_raw_with_void_ptr.rs | 4 +- clippy_lints/src/instant_subtraction.rs | 6 +- clippy_lints/src/lines_filter_map_ok.rs | 4 +- clippy_lints/src/manual_retain.rs | 2 +- clippy_lints/src/methods/bytecount.rs | 8 +- clippy_lints/src/methods/clone_on_ref_ptr.rs | 19 ++-- .../methods/from_iter_instead_of_collect.rs | 4 +- .../src/methods/inefficient_to_string.rs | 3 +- .../src/methods/iter_out_of_bounds.rs | 10 +- clippy_lints/src/methods/open_options.rs | 8 +- .../src/methods/option_as_ref_deref.rs | 5 +- clippy_lints/src/methods/seek_from_current.rs | 5 +- .../seek_to_start_instead_of_rewind.rs | 6 +- .../methods/suspicious_command_arg_space.rs | 7 +- clippy_lints/src/missing_fields_in_debug.rs | 12 ++- clippy_lints/src/needless_pass_by_value.rs | 4 +- clippy_lints/src/non_canonical_impls.rs | 7 +- .../src/non_octal_unix_permissions.rs | 10 +- .../src/non_send_fields_in_send_ty.rs | 4 +- clippy_lints/src/operators/cmp_owned.rs | 4 +- .../src/permissions_set_readonly_false.rs | 6 +- clippy_lints/src/ptr.rs | 94 ++++++++----------- clippy_lints/src/rc_clone_in_vec_init.rs | 9 +- clippy_lints/src/redundant_clone.rs | 4 +- clippy_lints/src/size_of_in_element_count.rs | 22 ++--- clippy_lints/src/swap_ptr_to_ref.rs | 6 +- clippy_lints/src/unnamed_address.rs | 4 +- clippy_lints/src/unused_peekable.rs | 10 +- clippy_lints/src/useless_conversion.rs | 4 +- clippy_utils/src/higher.rs | 2 +- clippy_utils/src/lib.rs | 2 +- clippy_utils/src/paths.rs | 48 ---------- clippy_utils/src/ty.rs | 6 +- .../unnecessary_def_path_hardcoded_path.rs | 4 +- ...unnecessary_def_path_hardcoded_path.stderr | 4 +- 45 files changed, 191 insertions(+), 271 deletions(-) diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index 7dd808a7b3b7..accff9b0a34c 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -287,5 +287,5 @@ fn is_mutex_guard(cx: &LateContext<'_>, def_id: DefId) -> bool { } fn is_refcell_ref(cx: &LateContext<'_>, def_id: DefId) -> bool { - match_def_path(cx, def_id, &paths::REFCELL_REF) || match_def_path(cx, def_id, &paths::REFCELL_REFMUT) + matches!(cx.tcx.get_diagnostic_name(def_id), Some(sym::RefCellRef | sym::RefCellRefMut)) } diff --git a/clippy_lints/src/box_default.rs b/clippy_lints/src/box_default.rs index fa9c525fc08d..3f1ff66b8cf6 100644 --- a/clippy_lints/src/box_default.rs +++ b/clippy_lints/src/box_default.rs @@ -1,10 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::macros::macro_backtrace; use clippy_utils::ty::expr_sig; -use clippy_utils::{get_parent_node, is_default_equivalent, match_path, path_def_id, paths}; +use clippy_utils::{get_parent_node, is_default_equivalent, path_def_id}; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_ty, Visitor}; -use rustc_hir::{Block, Expr, ExprKind, Local, Node, QPath, TyKind}; +use rustc_hir::{def::Res, Block, Expr, ExprKind, Local, Node, QPath, TyKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::print::with_forced_trimmed_paths; @@ -55,7 +55,7 @@ impl LateLintPass<'_> for BoxDefault { expr.span, "`Box::new(_)` of default value", "try", - if is_plain_default(arg_path) || given_type(cx, expr) { + if is_plain_default(cx, arg_path) || given_type(cx, expr) { "Box::default()".into() } else if let Some(arg_ty) = cx.typeck_results().expr_ty(arg).make_suggestable(cx.tcx, true) { with_forced_trimmed_paths!(format!("Box::<{arg_ty}>::default()")) @@ -68,11 +68,13 @@ impl LateLintPass<'_> for BoxDefault { } } -fn is_plain_default(arg_path: &Expr<'_>) -> bool { +fn is_plain_default(cx: &LateContext<'_>, arg_path: &Expr<'_>) -> bool { // we need to match the actual path so we don't match e.g. "u8::default" - if let ExprKind::Path(QPath::Resolved(None, path)) = &arg_path.kind { + if let ExprKind::Path(QPath::Resolved(None, path)) = &arg_path.kind + && let Res::Def(_, def_id) = path.res + { // avoid generic parameters - match_path(path, &paths::DEFAULT_TRAIT_METHOD) && path.segments.iter().all(|seg| seg.args.is_none()) + cx.tcx.is_diagnostic_item(sym::default_fn, def_id) && path.segments.iter().all(|seg| seg.args.is_none()) } else { false } diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index 1de69122101c..9e8ef2825374 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::is_c_void; -use clippy_utils::{get_parent_expr, is_hir_ty_cfg_dependant, match_any_def_paths, paths}; +use clippy_utils::{get_parent_expr, is_hir_ty_cfg_dependant}; use rustc_hir::{Expr, ExprKind, GenericArg}; use rustc_lint::LateContext; use rustc_middle::ty::layout::LayoutOf; @@ -75,16 +75,17 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { } }, ExprKind::Call(func, [arg, ..]) if arg.hir_id == e.hir_id => { - static PATHS: &[&[&str]] = &[ - paths::PTR_READ_UNALIGNED.as_slice(), - paths::PTR_UNALIGNED_VOLATILE_LOAD.as_slice(), - paths::PTR_UNALIGNED_VOLATILE_STORE.as_slice(), - ]; - if let ExprKind::Path(path) = &func.kind && let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id() - && (match_any_def_paths(cx, def_id, PATHS).is_some() - || cx.tcx.is_diagnostic_item(sym::ptr_write_unaligned, def_id)) + && matches!( + cx.tcx.get_diagnostic_name(def_id), + Some( + sym::ptr_write_unaligned + | sym::ptr_read_unaligned + | sym::intrinsics_unaligned_volatile_load + | sym::intrinsics_unaligned_volatile_store + ) + ) { true } else { diff --git a/clippy_lints/src/casts/cast_slice_from_raw_parts.rs b/clippy_lints/src/casts/cast_slice_from_raw_parts.rs index 5e0123842b04..eb0f75b2f605 100644 --- a/clippy_lints/src/casts/cast_slice_from_raw_parts.rs +++ b/clippy_lints/src/casts/cast_slice_from_raw_parts.rs @@ -1,13 +1,13 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::source::snippet_with_context; -use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty::{self, Ty}; +use rustc_span::sym; use super::CAST_SLICE_FROM_RAW_PARTS; @@ -17,12 +17,10 @@ enum RawPartsKind { } fn raw_parts_kind(cx: &LateContext<'_>, did: DefId) -> Option { - if match_def_path(cx, did, &paths::SLICE_FROM_RAW_PARTS) { - Some(RawPartsKind::Immutable) - } else if match_def_path(cx, did, &paths::SLICE_FROM_RAW_PARTS_MUT) { - Some(RawPartsKind::Mutable) - } else { - None + match cx.tcx.get_diagnostic_name(did)? { + sym::slice_from_raw_parts => Some(RawPartsKind::Immutable), + sym::slice_from_raw_parts_mut => Some(RawPartsKind::Mutable), + _ => None, } } diff --git a/clippy_lints/src/create_dir.rs b/clippy_lints/src/create_dir.rs index 878248a6bdc8..2bca695c43b1 100644 --- a/clippy_lints/src/create_dir.rs +++ b/clippy_lints/src/create_dir.rs @@ -1,11 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; -use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::sym; declare_clippy_lint! { /// ### What it does @@ -37,7 +37,7 @@ impl LateLintPass<'_> for CreateDir { if let ExprKind::Call(func, [arg, ..]) = expr.kind; if let ExprKind::Path(ref path) = func.kind; if let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id(); - if match_def_path(cx, def_id, &paths::STD_FS_CREATE_DIR); + if cx.tcx.is_diagnostic_item(sym::fs_create_dir, def_id); then { span_lint_and_sugg( cx, diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index 763ad0264ad9..5787f19cc6cb 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -1,9 +1,7 @@ use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_sugg}; use clippy_utils::source::snippet_with_context; use clippy_utils::ty::{has_drop, is_copy}; -use clippy_utils::{ - any_parent_is_automatically_derived, contains_name, get_parent_expr, is_from_proc_macro, match_def_path, paths, -}; +use clippy_utils::{any_parent_is_automatically_derived, contains_name, get_parent_expr, is_from_proc_macro}; use if_chain::if_chain; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; @@ -14,7 +12,7 @@ use rustc_middle::ty; use rustc_middle::ty::print::with_forced_trimmed_paths; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::symbol::{Ident, Symbol}; -use rustc_span::Span; +use rustc_span::{sym, Span}; declare_clippy_lint! { /// ### What it does @@ -91,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id); if let ExprKind::Path(ref qpath) = path.kind; if let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id(); - if match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD); + if cx.tcx.is_diagnostic_item(sym::default_fn, def_id); if !is_update_syntax_base(cx, expr); // Detect and ignore ::default() because these calls do explicitly name the type. if let QPath::Resolved(None, _path) = qpath; @@ -268,7 +266,7 @@ fn is_expr_default<'tcx>(expr: &'tcx Expr<'tcx>, cx: &LateContext<'tcx>) -> bool if let Res::Def(_, def_id) = cx.qpath_res(qpath, fn_expr.hir_id); then { // right hand side of assignment is `Default::default` - match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD) + cx.tcx.is_diagnostic_item(sym::default_fn, def_id) } else { false } diff --git a/clippy_lints/src/default_constructed_unit_structs.rs b/clippy_lints/src/default_constructed_unit_structs.rs index a294c6937877..0676777e7968 100644 --- a/clippy_lints/src/default_constructed_unit_structs.rs +++ b/clippy_lints/src/default_constructed_unit_structs.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::{is_ty_alias, match_def_path, paths}; +use clippy_utils::is_ty_alias; use hir::def::Res; use hir::ExprKind; use rustc_errors::Applicability; @@ -7,6 +7,7 @@ use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::sym; declare_clippy_lint! { /// ### What it does @@ -63,7 +64,7 @@ impl LateLintPass<'_> for DefaultConstructedUnitStructs { // `::Assoc` cannot be used as a constructor if !is_alias(*base); if let Res::Def(_, def_id) = cx.qpath_res(qpath, fn_expr.hir_id); - if match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD); + if cx.tcx.is_diagnostic_item(sym::default_fn, def_id); // make sure we have a struct with no fields (unit struct) if let ty::Adt(def, ..) = cx.typeck_results().expr_ty(expr).kind(); if def.is_struct(); diff --git a/clippy_lints/src/default_instead_of_iter_empty.rs b/clippy_lints/src/default_instead_of_iter_empty.rs index 572990aaba10..3d6d257e386b 100644 --- a/clippy_lints/src/default_instead_of_iter_empty.rs +++ b/clippy_lints/src/default_instead_of_iter_empty.rs @@ -1,11 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_context; -use clippy_utils::{last_path_segment, match_def_path, paths}; +use clippy_utils::last_path_segment; use rustc_errors::Applicability; use rustc_hir::{def, Expr, ExprKind, GenericArg, QPath, TyKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::SyntaxContext; +use rustc_span::{sym, SyntaxContext}; declare_clippy_lint! { /// ### What it does @@ -37,7 +37,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultIterEmpty { && let TyKind::Path(ty_path) = &ty.kind && let QPath::Resolved(None, path) = ty_path && let def::Res::Def(_, def_id) = &path.res - && match_def_path(cx, *def_id, &paths::ITER_EMPTY) + && cx.tcx.is_diagnostic_item(sym::IterEmpty, *def_id) && let ctxt = expr.span.ctxt() && ty.span.ctxt() == ctxt { diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index 8ba6a9e48763..5de79133c7dc 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -1,9 +1,10 @@ use clippy_utils::diagnostics::span_lint; -use clippy_utils::{is_entrypoint_fn, match_def_path, paths}; +use clippy_utils::{is_entrypoint_fn}; use if_chain::if_chain; use rustc_hir::{Expr, ExprKind, Item, ItemKind, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::sym; declare_clippy_lint! { /// ### What it does @@ -45,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit { if let ExprKind::Call(path_expr, _args) = e.kind; if let ExprKind::Path(ref path) = path_expr.kind; if let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id(); - if match_def_path(cx, def_id, &paths::EXIT); + if cx.tcx.is_diagnostic_item(sym::process_exit, def_id); let parent = cx.tcx.hir().get_parent_item(e.hir_id).def_id; if let Some(Node::Item(Item{kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find_by_def_id(parent); // If the next item up is a function we check if it is an entry point diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index b612cc00bf97..6f6177340f48 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::macros::{find_format_args, format_args_inputs_span}; use clippy_utils::source::snippet_with_applicability; -use clippy_utils::{is_expn_of, match_function_call, paths}; +use clippy_utils::{is_expn_of, path_def_id}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::def::Res; @@ -47,18 +47,19 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite { if let ExprKind::MethodCall(unwrap_fun, write_call, [], _) = expr.kind && unwrap_fun.ident.name == sym::unwrap // match call to write_fmt - && let ExprKind::MethodCall(write_fun, write_recv, [write_arg], _) = look_in_block(cx, &write_call.kind) + && let ExprKind::MethodCall(write_fun, write_recv, [write_arg], _) = *look_in_block(cx, &write_call.kind) + && let ExprKind::Call(write_recv_path, _) = write_recv.kind && write_fun.ident.name == sym!(write_fmt) - // match calls to std::io::stdout() / std::io::stderr () - && let Some(dest_name) = if match_function_call(cx, write_recv, &paths::STDOUT).is_some() { - Some("stdout") - } else if match_function_call(cx, write_recv, &paths::STDERR).is_some() { - Some("stderr") - } else { - None - } - && let Some(format_args) = find_format_args(cx, write_arg, ExpnId::root()) + && let Some(def_id) = path_def_id(cx, write_recv_path) { + // match calls to std::io::stdout() / std::io::stderr () + let (dest_name, prefix) = match cx.tcx.get_diagnostic_name(def_id) { + Some(sym::io_stdout) => ("stdout", ""), + Some(sym::io_stderr) => ("stderr", "e"), + _ => return, + }; + let Some(format_args) = find_format_args(cx, write_arg, ExpnId::root()) else { return; }; + // ordering is important here, since `writeln!` uses `write!` internally let calling_macro = if is_expn_of(write_call.span, "writeln").is_some() { Some("writeln") @@ -67,11 +68,6 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite { } else { None }; - let prefix = if dest_name == "stderr" { - "e" - } else { - "" - }; // We need to remove the last trailing newline from the string because the // underlying `fmt::write` function doesn't know whether `println!` or `print!` was diff --git a/clippy_lints/src/from_raw_with_void_ptr.rs b/clippy_lints/src/from_raw_with_void_ptr.rs index 5e859d97c624..d82ea6d2fc80 100644 --- a/clippy_lints/src/from_raw_with_void_ptr.rs +++ b/clippy_lints/src/from_raw_with_void_ptr.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::is_c_void; -use clippy_utils::{match_def_path, path_def_id, paths}; +use clippy_utils::path_def_id; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; @@ -68,7 +68,7 @@ fn def_id_matches_type(cx: &LateContext<'_>, def_id: DefId) -> Option<&'static s } } - if match_def_path(cx, def_id, &paths::WEAK_RC) || match_def_path(cx, def_id, &paths::WEAK_ARC) { + if matches!(cx.tcx.get_diagnostic_name(def_id), Some(sym::RcWeak | sym::ArcWeak)) { Some("Weak") } else { None diff --git a/clippy_lints/src/instant_subtraction.rs b/clippy_lints/src/instant_subtraction.rs index 8df7dfb8b9e5..a1a115f6d79f 100644 --- a/clippy_lints/src/instant_subtraction.rs +++ b/clippy_lints/src/instant_subtraction.rs @@ -130,11 +130,7 @@ fn is_instant_now_call(cx: &LateContext<'_>, expr_block: &'_ Expr<'_>) -> bool { fn is_an_instant(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let expr_ty = cx.typeck_results().expr_ty(expr); - - match expr_ty.kind() { - rustc_middle::ty::Adt(def, _) => clippy_utils::match_def_path(cx, def.did(), &clippy_utils::paths::INSTANT), - _ => false, - } + ty::is_type_diagnostic_item(cx, expr_ty, sym::Instant) } fn is_a_duration(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { diff --git a/clippy_lints/src/lines_filter_map_ok.rs b/clippy_lints/src/lines_filter_map_ok.rs index 49425ff0a8e0..ac949b672609 100644 --- a/clippy_lints/src/lines_filter_map_ok.rs +++ b/clippy_lints/src/lines_filter_map_ok.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::ty::match_type; +use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::{is_diag_item_method, is_trait_method, match_def_path, path_to_local_id, paths}; use rustc_errors::Applicability; use rustc_hir::{Body, Closure, Expr, ExprKind}; @@ -62,7 +62,7 @@ impl LateLintPass<'_> for LinesFilterMapOk { if let ExprKind::MethodCall(fm_method, fm_receiver, [fm_arg], fm_span) = expr.kind && is_trait_method(cx, expr, sym::Iterator) && (fm_method.ident.as_str() == "filter_map" || fm_method.ident.as_str() == "flat_map") && - match_type(cx, cx.typeck_results().expr_ty_adjusted(fm_receiver), &paths::STD_IO_LINES) + is_type_diagnostic_item(cx, cx.typeck_results().expr_ty_adjusted(fm_receiver), sym::IoLines) { let lint = match &fm_arg.kind { // Detect `Result::ok` diff --git a/clippy_lints/src/manual_retain.rs b/clippy_lints/src/manual_retain.rs index 1a69a48c582b..f923413f4348 100644 --- a/clippy_lints/src/manual_retain.rs +++ b/clippy_lints/src/manual_retain.rs @@ -135,7 +135,7 @@ fn check_to_owned( if msrv.meets(msrvs::STRING_RETAIN) && let hir::ExprKind::MethodCall(_, filter_expr, [], _) = &target_expr.kind && let Some(to_owned_def_id) = cx.typeck_results().type_dependent_def_id(target_expr.hir_id) - && match_def_path(cx, to_owned_def_id, &paths::TO_OWNED_METHOD) + && cx.tcx.is_diagnostic_item(sym::to_owned_method, to_owned_def_id) && let hir::ExprKind::MethodCall(_, chars_expr, [_], _) = &filter_expr.kind && let Some(filter_def_id) = cx.typeck_results().type_dependent_def_id(filter_expr.hir_id) && match_def_path(cx, filter_def_id, &paths::CORE_ITER_FILTER) diff --git a/clippy_lints/src/methods/bytecount.rs b/clippy_lints/src/methods/bytecount.rs index f490a7175540..35370355f834 100644 --- a/clippy_lints/src/methods/bytecount.rs +++ b/clippy_lints/src/methods/bytecount.rs @@ -1,8 +1,8 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; -use clippy_utils::ty::match_type; +use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::visitors::is_local_used; -use clippy_utils::{path_to_local_id, paths, peel_blocks, peel_ref_operators, strip_pat_refs}; +use clippy_utils::{path_to_local_id, peel_blocks, peel_ref_operators, strip_pat_refs}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Closure, Expr, ExprKind, PatKind}; @@ -25,9 +25,9 @@ pub(super) fn check<'tcx>( if let PatKind::Binding(_, arg_id, _, _) = strip_pat_refs(param.pat).kind; if let ExprKind::Binary(ref op, l, r) = body.value.kind; if op.node == BinOpKind::Eq; - if match_type(cx, + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(filter_recv).peel_refs(), - &paths::SLICE_ITER); + sym::SliceIter); let operand_is_arg = |expr| { let expr = peel_ref_operators(cx, peel_blocks(expr)); path_to_local_id(expr, arg_id) diff --git a/clippy_lints/src/methods/clone_on_ref_ptr.rs b/clippy_lints/src/methods/clone_on_ref_ptr.rs index ddf3c9f27df2..926bd06bacbd 100644 --- a/clippy_lints/src/methods/clone_on_ref_ptr.rs +++ b/clippy_lints/src/methods/clone_on_ref_ptr.rs @@ -1,7 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::paths; use clippy_utils::source::snippet_with_context; -use clippy_utils::ty::{is_type_diagnostic_item, match_type}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; @@ -22,15 +20,14 @@ pub(super) fn check( } let obj_ty = cx.typeck_results().expr_ty(receiver).peel_refs(); - if let ty::Adt(_, subst) = obj_ty.kind() { - let caller_type = if is_type_diagnostic_item(cx, obj_ty, sym::Rc) { - "Rc" - } else if is_type_diagnostic_item(cx, obj_ty, sym::Arc) { - "Arc" - } else if match_type(cx, obj_ty, &paths::WEAK_RC) || match_type(cx, obj_ty, &paths::WEAK_ARC) { - "Weak" - } else { - return; + if let ty::Adt(adt, subst) = obj_ty.kind() + && let Some(name) = cx.tcx.get_diagnostic_name(adt.did()) + { + let caller_type = match name { + sym::Rc => "Rc", + sym::Arc => "Arc", + sym::RcWeak | sym::ArcWeak => "Weak", + _ => return, }; // Sometimes unnecessary ::<_> after Rc/Arc/Weak diff --git a/clippy_lints/src/methods/from_iter_instead_of_collect.rs b/clippy_lints/src/methods/from_iter_instead_of_collect.rs index 66dfce3682b5..4040d3a5fe13 100644 --- a/clippy_lints/src/methods/from_iter_instead_of_collect.rs +++ b/clippy_lints/src/methods/from_iter_instead_of_collect.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_opt; use clippy_utils::ty::implements_trait; -use clippy_utils::{is_expr_path_def_path, paths, sugg}; +use clippy_utils::{is_path_diagnostic_item, sugg}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; @@ -13,7 +13,7 @@ use super::FROM_ITER_INSTEAD_OF_COLLECT; pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>], func: &hir::Expr<'_>) { if_chain! { - if is_expr_path_def_path(cx, func, &paths::FROM_ITERATOR_METHOD); + if is_path_diagnostic_item(cx, func, sym::from_iter_fn); let ty = cx.typeck_results().expr_ty(expr); let arg_ty = cx.typeck_results().expr_ty(&args[0]); if let Some(iter_id) = cx.tcx.get_diagnostic_item(sym::Iterator); diff --git a/clippy_lints/src/methods/inefficient_to_string.rs b/clippy_lints/src/methods/inefficient_to_string.rs index 631741d9290c..6686d42c95f8 100644 --- a/clippy_lints/src/methods/inefficient_to_string.rs +++ b/clippy_lints/src/methods/inefficient_to_string.rs @@ -1,7 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::{is_type_lang_item, walk_ptrs_ty_depth}; -use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; @@ -22,7 +21,7 @@ pub fn check( if_chain! { if args.is_empty() && method_name == sym::to_string; if let Some(to_string_meth_did) = cx.typeck_results().type_dependent_def_id(expr.hir_id); - if match_def_path(cx, to_string_meth_did, &paths::TO_STRING_METHOD); + if cx.tcx.is_diagnostic_item(sym::to_string_method, to_string_meth_did); if let Some(args) = cx.typeck_results().node_args_opt(expr.hir_id); let arg_ty = cx.typeck_results().expr_ty_adjusted(receiver); let self_ty = args.type_at(0); diff --git a/clippy_lints/src/methods/iter_out_of_bounds.rs b/clippy_lints/src/methods/iter_out_of_bounds.rs index 79c6d63254b2..99ea7f03df4e 100644 --- a/clippy_lints/src/methods/iter_out_of_bounds.rs +++ b/clippy_lints/src/methods/iter_out_of_bounds.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_note; use clippy_utils::higher::VecArgs; -use clippy_utils::{expr_or_init, is_trait_method, match_def_path, paths}; +use clippy_utils::{expr_or_init, is_trait_method}; use rustc_ast::LitKind; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; @@ -26,14 +26,14 @@ fn get_iterator_length<'tcx>(cx: &LateContext<'tcx>, iter: &'tcx Expr<'tcx>) -> }; let did = adt.did(); - if match_def_path(cx, did, &paths::ARRAY_INTO_ITER) { + if cx.tcx.is_diagnostic_item(sym::ArrayIntoIter, did) { // For array::IntoIter, the length is the second generic // parameter. substs .const_at(1) .try_eval_target_usize(cx.tcx, cx.param_env) .map(u128::from) - } else if match_def_path(cx, did, &paths::SLICE_ITER) + } else if cx.tcx.is_diagnostic_item(sym::SliceIter, did) && let ExprKind::MethodCall(_, recv, ..) = iter.kind { if let ty::Array(_, len) = cx.typeck_results().expr_ty(recv).peel_refs().kind() { @@ -47,9 +47,9 @@ fn get_iterator_length<'tcx>(cx: &LateContext<'tcx>, iter: &'tcx Expr<'tcx>) -> } else { None } - } else if match_def_path(cx, did, &paths::ITER_EMPTY) { + } else if cx.tcx.is_diagnostic_item(sym::IterEmpty, did) { Some(0) - } else if match_def_path(cx, did, &paths::ITER_ONCE) { + } else if cx.tcx.is_diagnostic_item(sym::IterOnce, did) { Some(1) } else { None diff --git a/clippy_lints/src/methods/open_options.rs b/clippy_lints/src/methods/open_options.rs index 1c664e76d74f..c0f5a2799451 100644 --- a/clippy_lints/src/methods/open_options.rs +++ b/clippy_lints/src/methods/open_options.rs @@ -1,17 +1,17 @@ use clippy_utils::diagnostics::span_lint; -use clippy_utils::paths; -use clippy_utils::ty::match_type; +use clippy_utils::ty::is_type_diagnostic_item; use rustc_ast::ast::LitKind; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; use rustc_span::source_map::{Span, Spanned}; +use rustc_span::sym; use super::NONSENSICAL_OPEN_OPTIONS; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) && let Some(impl_id) = cx.tcx.impl_of_method(method_id) - && match_type(cx, cx.tcx.type_of(impl_id).instantiate_identity(), &paths::OPEN_OPTIONS) + && is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::FsOpenOptions) { let mut options = Vec::new(); get_open_options(cx, recv, &mut options); @@ -40,7 +40,7 @@ fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec let obj_ty = cx.typeck_results().expr_ty(receiver).peel_refs(); // Only proceed if this is a call on some object of type std::fs::OpenOptions - if match_type(cx, obj_ty, &paths::OPEN_OPTIONS) && !arguments.is_empty() { + if is_type_diagnostic_item(cx, obj_ty, sym::FsOpenOptions) && !arguments.is_empty() { let argument_option = match arguments[0].kind { ExprKind::Lit(span) => { if let Spanned { diff --git a/clippy_lints/src/methods/option_as_ref_deref.rs b/clippy_lints/src/methods/option_as_ref_deref.rs index 3e33f9193374..d0c27f9631f7 100644 --- a/clippy_lints/src/methods/option_as_ref_deref.rs +++ b/clippy_lints/src/methods/option_as_ref_deref.rs @@ -32,8 +32,7 @@ pub(super) fn check( return; } - let deref_aliases: [&[&str]; 8] = [ - &paths::DEREF_MUT_TRAIT_METHOD, + let deref_aliases: [&[&str]; 7] = [ &paths::CSTRING_AS_C_STR, &paths::OS_STRING_AS_OS_STR, &paths::PATH_BUF_AS_PATH, @@ -49,6 +48,7 @@ pub(super) fn check( .opt_def_id() .map_or(false, |fun_def_id| { cx.tcx.is_diagnostic_item(sym::deref_method, fun_def_id) + || cx.tcx.is_diagnostic_item(sym::deref_mut_method, fun_def_id) || deref_aliases.iter().any(|path| match_def_path(cx, fun_def_id, path)) }) }, @@ -70,6 +70,7 @@ pub(super) fn check( then { let method_did = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id).unwrap(); cx.tcx.is_diagnostic_item(sym::deref_method, method_did) + || cx.tcx.is_diagnostic_item(sym::deref_mut_method, method_did) || deref_aliases.iter().any(|path| match_def_path(cx, method_did, path)) } else { false diff --git a/clippy_lints/src/methods/seek_from_current.rs b/clippy_lints/src/methods/seek_from_current.rs index f3d6a15ede01..4ea87027a9e6 100644 --- a/clippy_lints/src/methods/seek_from_current.rs +++ b/clippy_lints/src/methods/seek_from_current.rs @@ -2,18 +2,19 @@ use rustc_ast::ast::{LitIntType, LitKind}; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; +use rustc_span::sym; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::implements_trait; -use clippy_utils::{get_trait_def_id, match_def_path, paths}; +use clippy_utils::{match_def_path, paths}; use super::SEEK_FROM_CURRENT; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &'tcx Expr<'_>, arg: &'tcx Expr<'_>) { let ty = cx.typeck_results().expr_ty(recv); - if let Some(def_id) = get_trait_def_id(cx, &paths::STD_IO_SEEK) { + if let Some(def_id) = cx.tcx.get_diagnostic_item(sym::IoSeek) { if implements_trait(cx, ty, def_id, &[]) && arg_is_seek_from_current(cx, arg) { let mut applicability = Applicability::MachineApplicable; let snip = snippet_with_applicability(cx, recv.span, "..", &mut applicability); diff --git a/clippy_lints/src/methods/seek_to_start_instead_of_rewind.rs b/clippy_lints/src/methods/seek_to_start_instead_of_rewind.rs index 787e9e0ebd24..50d4de7a6800 100644 --- a/clippy_lints/src/methods/seek_to_start_instead_of_rewind.rs +++ b/clippy_lints/src/methods/seek_to_start_instead_of_rewind.rs @@ -1,11 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::implements_trait; -use clippy_utils::{get_trait_def_id, is_expr_used_or_unified, match_def_path, paths}; +use clippy_utils::{is_expr_used_or_unified, match_def_path, paths}; use rustc_ast::ast::{LitIntType, LitKind}; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; -use rustc_span::Span; +use rustc_span::{sym, Span}; use super::SEEK_TO_START_INSTEAD_OF_REWIND; @@ -23,7 +23,7 @@ pub(super) fn check<'tcx>( return; } - if let Some(seek_trait_id) = get_trait_def_id(cx, &paths::STD_IO_SEEK) && + if let Some(seek_trait_id) = cx.tcx.get_diagnostic_item(sym::IoSeek) && implements_trait(cx, ty, seek_trait_id, &[]) && let ExprKind::Call(func, args1) = arg.kind && let ExprKind::Path(ref path) = func.kind && diff --git a/clippy_lints/src/methods/suspicious_command_arg_space.rs b/clippy_lints/src/methods/suspicious_command_arg_space.rs index bc8f01767641..8959e2c1d75f 100644 --- a/clippy_lints/src/methods/suspicious_command_arg_space.rs +++ b/clippy_lints/src/methods/suspicious_command_arg_space.rs @@ -1,9 +1,8 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::paths; -use clippy_utils::ty::match_type; +use clippy_utils::ty::is_type_diagnostic_item; use rustc_errors::{Applicability, Diagnostic}; use rustc_lint::LateContext; -use rustc_span::Span; +use rustc_span::{sym, Span}; use {rustc_ast as ast, rustc_hir as hir}; use super::SUSPICIOUS_COMMAND_ARG_SPACE; @@ -11,7 +10,7 @@ use super::SUSPICIOUS_COMMAND_ARG_SPACE; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, recv: &'tcx hir::Expr<'_>, arg: &'tcx hir::Expr<'_>, span: Span) { let ty = cx.typeck_results().expr_ty(recv).peel_refs(); - if match_type(cx, ty, &paths::STD_PROCESS_COMMAND) + if is_type_diagnostic_item(cx, ty, sym::Command) && let hir::ExprKind::Lit(lit) = &arg.kind && let ast::LitKind::Str(s, _) = &lit.node && let Some((arg1, arg2)) = s.as_str().split_once(' ') diff --git a/clippy_lints/src/missing_fields_in_debug.rs b/clippy_lints/src/missing_fields_in_debug.rs index 2f63b9b9f0b8..f0b865be8042 100644 --- a/clippy_lints/src/missing_fields_in_debug.rs +++ b/clippy_lints/src/missing_fields_in_debug.rs @@ -1,9 +1,9 @@ use std::ops::ControlFlow; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::ty::match_type; +use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::visitors::{for_each_expr, Visitable}; -use clippy_utils::{is_path_lang_item, paths}; +use clippy_utils::is_path_lang_item; use rustc_ast::LitKind; use rustc_data_structures::fx::FxHashSet; use rustc_hir::def::{DefKind, Res}; @@ -114,9 +114,11 @@ fn should_lint<'tcx>( if let ExprKind::MethodCall(path, recv, ..) = &expr.kind { let recv_ty = typeck_results.expr_ty(recv).peel_refs(); - if path.ident.name == sym::debug_struct && match_type(cx, recv_ty, &paths::FORMATTER) { + if path.ident.name == sym::debug_struct && is_type_diagnostic_item(cx, recv_ty, sym::Formatter) { has_debug_struct = true; - } else if path.ident.name == sym!(finish_non_exhaustive) && match_type(cx, recv_ty, &paths::DEBUG_STRUCT) { + } else if path.ident.name == sym!(finish_non_exhaustive) + && is_type_diagnostic_item(cx, recv_ty, sym::DebugStruct) + { has_finish_non_exhaustive = true; } } @@ -137,7 +139,7 @@ fn as_field_call<'tcx>( ) -> Option { if let ExprKind::MethodCall(path, recv, [debug_field, _], _) = &expr.kind && let recv_ty = typeck_results.expr_ty(recv).peel_refs() - && match_type(cx, recv_ty, &paths::DEBUG_STRUCT) + && is_type_diagnostic_item(cx, recv_ty, sym::DebugStruct) && path.ident.name == sym::field && let ExprKind::Lit(lit) = &debug_field.kind && let LitKind::Str(sym, ..) = lit.node diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 5ee26966fa71..6d7df2eac629 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -4,7 +4,7 @@ use clippy_utils::source::{snippet, snippet_opt}; use clippy_utils::ty::{ implements_trait, implements_trait_with_env_from_iter, is_copy, is_type_diagnostic_item, is_type_lang_item, }; -use clippy_utils::{get_trait_def_id, is_self, paths}; +use clippy_utils::is_self; use if_chain::if_chain; use rustc_ast::ast::Attribute; use rustc_errors::{Applicability, Diagnostic}; @@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { need!(cx.tcx.lang_items().fn_trait()), need!(cx.tcx.lang_items().fn_once_trait()), need!(cx.tcx.lang_items().fn_mut_trait()), - need!(get_trait_def_id(cx, &paths::RANGE_ARGUMENT_TRAIT)), + need!(cx.tcx.get_diagnostic_item(sym::RangeBounds)), ]; let sized_trait = need!(cx.tcx.lang_items().sized_trait()); diff --git a/clippy_lints/src/non_canonical_impls.rs b/clippy_lints/src/non_canonical_impls.rs index 20b4b4f03ed4..4be140647fcc 100644 --- a/clippy_lints/src/non_canonical_impls.rs +++ b/clippy_lints/src/non_canonical_impls.rs @@ -1,7 +1,6 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; -use clippy_utils::paths::ORD_CMP; use clippy_utils::ty::implements_trait; -use clippy_utils::{get_parent_node, is_res_lang_ctor, last_path_segment, match_def_path, path_res, std_or_core}; +use clippy_utils::{get_parent_node, is_res_lang_ctor, last_path_segment, path_res, std_or_core}; use rustc_errors::Applicability; use rustc_hir::def_id::LocalDefId; use rustc_hir::{Expr, ExprKind, ImplItem, ImplItemKind, LangItem, Node, UnOp}; @@ -261,7 +260,7 @@ fn self_cmp_call<'tcx>( match cmp_expr.kind { ExprKind::Call(path, [_self, _other]) => path_res(cx, path) .opt_def_id() - .is_some_and(|def_id| match_def_path(cx, def_id, &ORD_CMP)), + .is_some_and(|def_id| cx.tcx.is_diagnostic_item(sym::ord_cmp_method, def_id)), ExprKind::MethodCall(_, _, [_other], ..) => { // We can set this to true here no matter what as if it's a `MethodCall` and goes to the // `else` branch, it must be a method named `cmp` that isn't `Ord::cmp` @@ -273,7 +272,7 @@ fn self_cmp_call<'tcx>( cx.tcx .typeck(def_id) .type_dependent_def_id(cmp_expr.hir_id) - .is_some_and(|def_id| match_def_path(cx, def_id, &ORD_CMP)) + .is_some_and(|def_id| cx.tcx.is_diagnostic_item(sym::ord_cmp_method, def_id)) }, _ => false, } diff --git a/clippy_lints/src/non_octal_unix_permissions.rs b/clippy_lints/src/non_octal_unix_permissions.rs index e1de494eb41c..d47728f190ab 100644 --- a/clippy_lints/src/non_octal_unix_permissions.rs +++ b/clippy_lints/src/non_octal_unix_permissions.rs @@ -1,6 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::{snippet_opt, snippet_with_applicability}; -use clippy_utils::ty::{is_type_diagnostic_item, match_type}; use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_errors::Applicability; @@ -45,13 +44,12 @@ impl<'tcx> LateLintPass<'tcx> for NonOctalUnixPermissions { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { match &expr.kind { ExprKind::MethodCall(path, func, [param], _) => { - let obj_ty = cx.typeck_results().expr_ty(func).peel_refs(); - if_chain! { + if let Some(adt) = cx.typeck_results().expr_ty(func).peel_refs().ty_adt_def(); if (path.ident.name == sym!(mode) - && (match_type(cx, obj_ty, &paths::OPEN_OPTIONS) - || is_type_diagnostic_item(cx, obj_ty, sym::DirBuilder))) - || (path.ident.name == sym!(set_mode) && match_type(cx, obj_ty, &paths::PERMISSIONS)); + && matches!(cx.tcx.get_diagnostic_name(adt.did()), Some(sym::FsOpenOptions | sym::DirBuilder))) + || (path.ident.name == sym!(set_mode) + && cx.tcx.is_diagnostic_item(sym::FsPermissions, adt.did())); if let ExprKind::Lit(_) = param.kind; if param.span.ctxt() == expr.span.ctxt(); diff --git a/clippy_lints/src/non_send_fields_in_send_ty.rs b/clippy_lints/src/non_send_fields_in_send_ty.rs index c5e777c20702..d388dfc08f3b 100644 --- a/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; use clippy_utils::ty::{implements_trait, is_copy}; -use clippy_utils::{is_lint_allowed, match_def_path, paths}; +use clippy_utils::is_lint_allowed; use rustc_ast::ImplPolarity; use rustc_hir::def_id::DefId; use rustc_hir::{FieldDef, Item, ItemKind, Node}; @@ -233,7 +233,7 @@ fn contains_pointer_like<'tcx>(cx: &LateContext<'tcx>, target_ty: Ty<'tcx>) -> b return true; }, ty::Adt(adt_def, _) => { - if match_def_path(cx, adt_def.did(), &paths::PTR_NON_NULL) { + if cx.tcx.is_diagnostic_item(sym::NonNull, adt_def.did()) { return true; } }, diff --git a/clippy_lints/src/operators/cmp_owned.rs b/clippy_lints/src/operators/cmp_owned.rs index d3de9699fe9d..136642d69dca 100644 --- a/clippy_lints/src/operators/cmp_owned.rs +++ b/clippy_lints/src/operators/cmp_owned.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; use clippy_utils::ty::{implements_trait, is_copy}; -use clippy_utils::{match_def_path, path_def_id, paths}; +use clippy_utils::path_def_id; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp}; use rustc_lint::LateContext; @@ -50,7 +50,7 @@ fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool) }, ExprKind::Call(path, [arg]) if path_def_id(cx, path).map_or(false, |did| { - if match_def_path(cx, did, &paths::FROM_STR_METHOD) { + if cx.tcx.is_diagnostic_item(sym::from_str_method, did) { true } else if cx.tcx.is_diagnostic_item(sym::from_fn, did) { !is_copy(cx, typeck.expr_ty(expr)) diff --git a/clippy_lints/src/permissions_set_readonly_false.rs b/clippy_lints/src/permissions_set_readonly_false.rs index 664d44d6504d..f3089d716ff1 100644 --- a/clippy_lints/src/permissions_set_readonly_false.rs +++ b/clippy_lints/src/permissions_set_readonly_false.rs @@ -1,10 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::paths; -use clippy_utils::ty::match_type; +use clippy_utils::ty::is_type_diagnostic_item; use rustc_ast::ast::LitKind; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::sym; declare_clippy_lint! { /// ### What it does @@ -31,7 +31,7 @@ declare_lint_pass!(PermissionsSetReadonlyFalse => [PERMISSIONS_SET_READONLY_FALS impl<'tcx> LateLintPass<'tcx> for PermissionsSetReadonlyFalse { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if let ExprKind::MethodCall(path, receiver, [arg], _) = &expr.kind - && match_type(cx, cx.typeck_results().expr_ty(receiver), &paths::PERMISSIONS) + && is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(receiver), sym::FsPermissions) && path.ident.name == sym!(set_readonly) && let ExprKind::Lit(lit) = &arg.kind && LitKind::Bool(false) == lit.node diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 7dabdcd58ec2..310051efc508 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -4,9 +4,8 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_the use clippy_utils::source::snippet_opt; use clippy_utils::ty::expr_sig; use clippy_utils::visitors::contains_unsafe_block; -use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_id, path_to_local, paths}; +use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_id, path_to_local}; use hir::LifetimeName; -use if_chain::if_chain; use rustc_errors::{Applicability, MultiSpan}; use rustc_hir::def_id::DefId; use rustc_hir::hir_id::HirIdMap; @@ -271,60 +270,43 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { } fn check_invalid_ptr_usage<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - // (fn_path, arg_indices) - `arg_indices` are the `arg` positions where null would cause U.B. - const INVALID_NULL_PTR_USAGE_TABLE: [(&[&str], &[usize]); 13] = [ - (&paths::SLICE_FROM_RAW_PARTS, &[0]), - (&paths::SLICE_FROM_RAW_PARTS_MUT, &[0]), - (&paths::PTR_COPY, &[0, 1]), - (&paths::PTR_COPY_NONOVERLAPPING, &[0, 1]), - (&paths::PTR_READ, &[0]), - (&paths::PTR_READ_UNALIGNED, &[0]), - (&paths::PTR_READ_VOLATILE, &[0]), - (&paths::PTR_REPLACE, &[0]), - (&paths::PTR_SLICE_FROM_RAW_PARTS, &[0]), - (&paths::PTR_SLICE_FROM_RAW_PARTS_MUT, &[0]), - (&paths::PTR_SWAP, &[0, 1]), - (&paths::PTR_SWAP_NONOVERLAPPING, &[0, 1]), - (&paths::PTR_WRITE_BYTES, &[0]), - ]; - let invalid_null_ptr_usage_table_diag_items: [(Option, &[usize]); 3] = [ - (cx.tcx.get_diagnostic_item(sym::ptr_write), &[0]), - (cx.tcx.get_diagnostic_item(sym::ptr_write_unaligned), &[0]), - (cx.tcx.get_diagnostic_item(sym::ptr_write_volatile), &[0]), - ]; - - if_chain! { - if let ExprKind::Call(fun, args) = expr.kind; - if let ExprKind::Path(ref qpath) = fun.kind; - if let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id(); - let fun_def_path = cx.get_def_path(fun_def_id).into_iter().map(Symbol::to_ident_string).collect::>(); - if let Some(arg_indices) = INVALID_NULL_PTR_USAGE_TABLE - .iter() - .find_map(|&(fn_path, indices)| if fn_path == fun_def_path { Some(indices) } else { None }) - .or_else(|| { - invalid_null_ptr_usage_table_diag_items - .iter() - .find_map(|&(def_id, indices)| { - if def_id == Some(fun_def_id) { - Some(indices) - } else { - None - } - }) - }); - then { - for &arg_idx in arg_indices { - if let Some(arg) = args.get(arg_idx).filter(|arg| is_null_path(cx, arg)) { - span_lint_and_sugg( - cx, - INVALID_NULL_PTR_USAGE, - arg.span, - "pointer must be non-null", - "change this to", - "core::ptr::NonNull::dangling().as_ptr()".to_string(), - Applicability::MachineApplicable, - ); - } + if let ExprKind::Call(fun, args) = expr.kind + && let ExprKind::Path(ref qpath) = fun.kind + && let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id() + && let Some(name) = cx.tcx.get_diagnostic_name(fun_def_id) + { + // `arg` positions where null would cause U.B. + let arg_indices: &[_] = match name { + sym::ptr_read + | sym::ptr_read_unaligned + | sym::ptr_read_volatile + | sym::ptr_replace + | sym::ptr_slice_from_raw_parts + | sym::ptr_slice_from_raw_parts_mut + | sym::ptr_write + | sym::ptr_write_bytes + | sym::ptr_write_unaligned + | sym::ptr_write_volatile + | sym::slice_from_raw_parts + | sym::slice_from_raw_parts_mut => &[0], + sym::ptr_copy + | sym::ptr_copy_nonoverlapping + | sym::ptr_swap + | sym::ptr_swap_nonoverlapping => &[0, 1], + _ => return, + }; + + for &arg_idx in arg_indices { + if let Some(arg) = args.get(arg_idx).filter(|arg| is_null_path(cx, arg)) { + span_lint_and_sugg( + cx, + INVALID_NULL_PTR_USAGE, + arg.span, + "pointer must be non-null", + "change this to", + "core::ptr::NonNull::dangling().as_ptr()".to_string(), + Applicability::MachineApplicable, + ); } } } diff --git a/clippy_lints/src/rc_clone_in_vec_init.rs b/clippy_lints/src/rc_clone_in_vec_init.rs index 8e85c55e7563..1a127c2bcf68 100644 --- a/clippy_lints/src/rc_clone_in_vec_init.rs +++ b/clippy_lints/src/rc_clone_in_vec_init.rs @@ -2,11 +2,11 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::higher::VecArgs; use clippy_utils::macros::root_macro_call_first_node; use clippy_utils::source::{indent_of, snippet}; -use clippy_utils::ty::match_type; -use clippy_utils::{last_path_segment, paths}; +use clippy_utils::last_path_segment; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, QPath, TyKind}; use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span, Symbol}; @@ -133,8 +133,9 @@ fn ref_init(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<(Symbol, Span)> { return Some((symbol, func.span)); } - let ty_path = cx.typeck_results().expr_ty(expr); - if match_type(cx, ty_path, &paths::WEAK_RC) || match_type(cx, ty_path, &paths::WEAK_ARC) { + if let ty::Adt(adt, _) = *cx.typeck_results().expr_ty(expr).kind() + && matches!(cx.tcx.get_diagnostic_name(adt.did()), Some(sym::RcWeak | sym::ArcWeak)) + { return Some((Symbol::intern("Weak"), func.span)); } } diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index e36adef555e6..2c0086b09813 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -99,8 +99,8 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone { unwrap_or_continue!(is_call_with_ref_arg(cx, mir, &terminator.kind)); let from_borrow = match_def_path(cx, fn_def_id, &paths::CLONE_TRAIT_METHOD) - || match_def_path(cx, fn_def_id, &paths::TO_OWNED_METHOD) - || (match_def_path(cx, fn_def_id, &paths::TO_STRING_METHOD) + || cx.tcx.is_diagnostic_item(sym::to_owned_method, fn_def_id) + || (cx.tcx.is_diagnostic_item(sym::to_string_method, fn_def_id) && is_type_lang_item(cx, arg_ty, LangItem::String)); let from_deref = !from_borrow diff --git a/clippy_lints/src/size_of_in_element_count.rs b/clippy_lints/src/size_of_in_element_count.rs index bd783b4e0054..b940cac6047b 100644 --- a/clippy_lints/src/size_of_in_element_count.rs +++ b/clippy_lints/src/size_of_in_element_count.rs @@ -2,7 +2,6 @@ //! expecting a count of T use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; @@ -67,16 +66,6 @@ fn get_pointee_ty_and_count_expr<'tcx>( cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, ) -> Option<(Ty<'tcx>, &'tcx Expr<'tcx>)> { - const FUNCTIONS: [&[&str]; 8] = [ - &paths::PTR_COPY_NONOVERLAPPING, - &paths::PTR_COPY, - &paths::PTR_WRITE_BYTES, - &paths::PTR_SWAP_NONOVERLAPPING, - &paths::PTR_SLICE_FROM_RAW_PARTS, - &paths::PTR_SLICE_FROM_RAW_PARTS_MUT, - &paths::SLICE_FROM_RAW_PARTS, - &paths::SLICE_FROM_RAW_PARTS_MUT, - ]; const METHODS: [&str; 11] = [ "write_bytes", "copy_to", @@ -97,7 +86,16 @@ fn get_pointee_ty_and_count_expr<'tcx>( if let ExprKind::Call(func, [.., count]) = expr.kind; if let ExprKind::Path(ref func_qpath) = func.kind; if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); - if FUNCTIONS.iter().any(|func_path| match_def_path(cx, def_id, func_path)); + if matches!(cx.tcx.get_diagnostic_name(def_id), Some( + sym::ptr_copy + | sym::ptr_copy_nonoverlapping + | sym::ptr_slice_from_raw_parts + | sym::ptr_slice_from_raw_parts_mut + | sym::ptr_swap_nonoverlapping + | sym::ptr_write_bytes + | sym::slice_from_raw_parts + | sym::slice_from_raw_parts_mut + )); // Get the pointee type if let Some(pointee_ty) = cx.typeck_results().node_args(func.hir_id).types().next(); diff --git a/clippy_lints/src/swap_ptr_to_ref.rs b/clippy_lints/src/swap_ptr_to_ref.rs index d085dda3582b..3685432a2539 100644 --- a/clippy_lints/src/swap_ptr_to_ref.rs +++ b/clippy_lints/src/swap_ptr_to_ref.rs @@ -1,11 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_with_context; -use clippy_utils::{match_def_path, path_def_id, paths}; +use clippy_utils::path_def_id; use rustc_errors::Applicability; use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::{Span, SyntaxContext}; +use rustc_span::{sym, Span, SyntaxContext}; declare_clippy_lint! { /// ### What it does @@ -42,7 +42,7 @@ impl LateLintPass<'_> for SwapPtrToRef { fn check_expr(&mut self, cx: &LateContext<'_>, e: &Expr<'_>) { if let ExprKind::Call(fn_expr, [arg1, arg2]) = e.kind && let Some(fn_id) = path_def_id(cx, fn_expr) - && match_def_path(cx, fn_id, &paths::MEM_SWAP) + && cx.tcx.is_diagnostic_item(sym::mem_swap, fn_id) && let ctxt = e.span.ctxt() && let (from_ptr1, arg1_span) = is_ptr_to_ref(cx, arg1, ctxt) && let (from_ptr2, arg2_span) = is_ptr_to_ref(cx, arg2, ctxt) diff --git a/clippy_lints/src/unnamed_address.rs b/clippy_lints/src/unnamed_address.rs index dea8a1e35bbb..996e7edf5573 100644 --- a/clippy_lints/src/unnamed_address.rs +++ b/clippy_lints/src/unnamed_address.rs @@ -1,10 +1,10 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; -use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::sym; declare_clippy_lint! { /// ### What it does @@ -96,7 +96,7 @@ impl LateLintPass<'_> for UnnamedAddress { if let ExprKind::Call(func, [ref _left, ref _right]) = expr.kind; if let ExprKind::Path(ref func_qpath) = func.kind; if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); - if match_def_path(cx, def_id, &paths::PTR_EQ); + if cx.tcx.is_diagnostic_item(sym::ptr_eq, def_id); let ty_param = cx.typeck_results().node_args(func.hir_id).type_at(0); if ty_param.is_trait(); then { diff --git a/clippy_lints/src/unused_peekable.rs b/clippy_lints/src/unused_peekable.rs index 4ee16d9a5e4a..db91beec0efa 100644 --- a/clippy_lints/src/unused_peekable.rs +++ b/clippy_lints/src/unused_peekable.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::ty::{match_type, peel_mid_ty_refs_is_mutable}; -use clippy_utils::{fn_def_id, is_trait_method, path_to_local_id, paths, peel_ref_operators}; +use clippy_utils::ty::{is_type_diagnostic_item, peel_mid_ty_refs_is_mutable}; +use clippy_utils::{fn_def_id, is_trait_method, path_to_local_id, peel_ref_operators}; use rustc_ast::Mutability; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{Block, Expr, ExprKind, HirId, Local, Node, PatKind, PathSegment, StmtKind}; @@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedPeekable { // Don't lint `Peekable`s returned from a block if let Some(expr) = block.expr && let Some(ty) = cx.typeck_results().expr_ty_opt(peel_ref_operators(cx, expr)) - && match_type(cx, ty, &paths::PEEKABLE) + && is_type_diagnostic_item(cx, ty, sym::IterPeekable) { return; } @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedPeekable { && !init.span.from_expansion() && let Some(ty) = cx.typeck_results().expr_ty_opt(init) && let (ty, _, Mutability::Mut) = peel_mid_ty_refs_is_mutable(ty) - && match_type(cx, ty, &paths::PEEKABLE) + && is_type_diagnostic_item(cx, ty, sym::IterPeekable) { let mut vis = PeekableVisitor::new(cx, binding); @@ -222,7 +222,7 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> { fn arg_is_mut_peekable(cx: &LateContext<'_>, arg: &Expr<'_>) -> bool { if let Some(ty) = cx.typeck_results().expr_ty_opt(arg) && let (ty, _, Mutability::Mut) = peel_mid_ty_refs_is_mutable(ty) - && match_type(cx, ty, &paths::PEEKABLE) + && is_type_diagnostic_item(cx, ty, sym::IterPeekable) { true } else { diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index f32e7edad6cb..3cc91838c000 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg, span_lin use clippy_utils::source::{snippet, snippet_with_applicability, snippet_with_context}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::{is_copy, is_type_diagnostic_item, same_type_and_consts}; -use clippy_utils::{get_parent_expr, is_trait_method, is_ty_alias, match_def_path, path_to_local, paths}; +use clippy_utils::{get_parent_expr, is_trait_method, is_ty_alias, path_to_local}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::def::DefKind; @@ -331,7 +331,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { let a = cx.typeck_results().expr_ty(e); let b = cx.typeck_results().expr_ty(arg); if_chain! { - if match_def_path(cx, def_id, &paths::TRY_FROM); + if cx.tcx.is_diagnostic_item(sym::try_from_fn, def_id); if is_type_diagnostic_item(cx, a, sym::Result); if let ty::Adt(_, args) = a.kind(); if let Some(a_type) = args.types().next(); diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index 802adbd4d2d5..741f9f54883d 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -457,7 +457,7 @@ pub fn get_vec_init_kind<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) - }; }, ExprKind::Path(QPath::Resolved(_, path)) - if match_def_path(cx, path.res.opt_def_id()?, &paths::DEFAULT_TRAIT_METHOD) + if cx.tcx.is_diagnostic_item(sym::default_fn, path.res.opt_def_id()?) && is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::Vec) => { return Some(VecInitKind::Default); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 13da79fba7e8..64ca2ff78736 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -2076,7 +2076,7 @@ pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool match expr.kind { ExprKind::Closure(&Closure { body, .. }) => is_body_identity_function(cx, cx.tcx.hir().body(body)), - _ => path_def_id(cx, expr).map_or(false, |id| match_def_path(cx, id, &paths::CONVERT_IDENTITY)), + _ => path_def_id(cx, expr).map_or(false, |id| cx.tcx.is_diagnostic_item(sym::convert_identity, id)), } } diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index 2fb24b5c7ed9..1f2bb16f459f 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -25,17 +25,12 @@ pub const CORE_ITER_COPIED: [&str; 6] = ["core", "iter", "traits", "iterator", " pub const CORE_ITER_FILTER: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "filter"]; pub const CORE_RESULT_OK_METHOD: [&str; 4] = ["core", "result", "Result", "ok"]; pub const CSTRING_AS_C_STR: [&str; 5] = ["alloc", "ffi", "c_str", "CString", "as_c_str"]; -pub const DEFAULT_TRAIT_METHOD: [&str; 4] = ["core", "default", "Default", "default"]; -pub const DEREF_MUT_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "DerefMut", "deref_mut"]; #[cfg(feature = "internal")] pub const EARLY_CONTEXT: [&str; 2] = ["rustc_lint", "EarlyContext"]; #[cfg(feature = "internal")] pub const EARLY_LINT_PASS: [&str; 3] = ["rustc_lint", "passes", "EarlyLintPass"]; -pub const EXIT: [&str; 3] = ["std", "process", "exit"]; pub const F32_EPSILON: [&str; 4] = ["core", "f32", "", "EPSILON"]; pub const F64_EPSILON: [&str; 4] = ["core", "f64", "", "EPSILON"]; -pub const FROM_ITERATOR_METHOD: [&str; 6] = ["core", "iter", "traits", "collect", "FromIterator", "from_iter"]; -pub const FROM_STR_METHOD: [&str; 5] = ["core", "str", "traits", "FromStr", "from_str"]; #[expect(clippy::invalid_paths)] // internal lints do not know about all external crates pub const FUTURES_IO_ASYNCREADEXT: [&str; 3] = ["futures_util", "io", "AsyncReadExt"]; #[expect(clippy::invalid_paths)] // internal lints do not know about all external crates @@ -48,8 +43,6 @@ pub const IDENT: [&str; 3] = ["rustc_span", "symbol", "Ident"]; #[cfg(feature = "internal")] pub const IDENT_AS_STR: [&str; 4] = ["rustc_span", "symbol", "Ident", "as_str"]; pub const INSERT_STR: [&str; 4] = ["alloc", "string", "String", "insert_str"]; -pub const ITER_EMPTY: [&str; 5] = ["core", "iter", "sources", "empty", "Empty"]; -pub const ITER_ONCE: [&str; 5] = ["core", "iter", "sources", "once", "Once"]; pub const ITERTOOLS_NEXT_TUPLE: [&str; 3] = ["itertools", "Itertools", "next_tuple"]; #[cfg(feature = "internal")] pub const KW_MODULE: [&str; 3] = ["rustc_span", "symbol", "kw"]; @@ -59,10 +52,8 @@ pub const LATE_CONTEXT: [&str; 2] = ["rustc_lint", "LateContext"]; pub const LATE_LINT_PASS: [&str; 3] = ["rustc_lint", "passes", "LateLintPass"]; #[cfg(feature = "internal")] pub const LINT: [&str; 2] = ["rustc_lint_defs", "Lint"]; -pub const MEM_SWAP: [&str; 3] = ["core", "mem", "swap"]; #[cfg(feature = "internal")] pub const MSRV: [&str; 3] = ["clippy_utils", "msrvs", "Msrv"]; -pub const OPEN_OPTIONS: [&str; 3] = ["std", "fs", "OpenOptions"]; pub const OS_STRING_AS_OS_STR: [&str; 5] = ["std", "ffi", "os_str", "OsString", "as_os_str"]; pub const OS_STR_TO_OS_STRING: [&str; 5] = ["std", "ffi", "os_str", "OsStr", "to_os_string"]; pub const PARKING_LOT_MUTEX_GUARD: [&str; 3] = ["lock_api", "mutex", "MutexGuard"]; @@ -71,28 +62,9 @@ pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 3] = ["lock_api", "rwlock", "Rw pub const PATH_BUF_AS_PATH: [&str; 4] = ["std", "path", "PathBuf", "as_path"]; pub const PATH_MAIN_SEPARATOR: [&str; 3] = ["std", "path", "MAIN_SEPARATOR"]; pub const PATH_TO_PATH_BUF: [&str; 4] = ["std", "path", "Path", "to_path_buf"]; -pub const PEEKABLE: [&str; 5] = ["core", "iter", "adapters", "peekable", "Peekable"]; -pub const PERMISSIONS: [&str; 3] = ["std", "fs", "Permissions"]; #[cfg_attr(not(unix), allow(clippy::invalid_paths))] pub const PERMISSIONS_FROM_MODE: [&str; 6] = ["std", "os", "unix", "fs", "PermissionsExt", "from_mode"]; -pub const PTR_COPY: [&str; 3] = ["core", "intrinsics", "copy"]; -pub const PTR_COPY_NONOVERLAPPING: [&str; 3] = ["core", "intrinsics", "copy_nonoverlapping"]; -pub const PTR_EQ: [&str; 3] = ["core", "ptr", "eq"]; -pub const PTR_SLICE_FROM_RAW_PARTS: [&str; 3] = ["core", "ptr", "slice_from_raw_parts"]; -pub const PTR_SLICE_FROM_RAW_PARTS_MUT: [&str; 3] = ["core", "ptr", "slice_from_raw_parts_mut"]; -pub const PTR_SWAP_NONOVERLAPPING: [&str; 3] = ["core", "ptr", "swap_nonoverlapping"]; -pub const PTR_READ: [&str; 3] = ["core", "ptr", "read"]; -pub const PTR_READ_UNALIGNED: [&str; 3] = ["core", "ptr", "read_unaligned"]; -pub const PTR_READ_VOLATILE: [&str; 3] = ["core", "ptr", "read_volatile"]; -pub const PTR_REPLACE: [&str; 3] = ["core", "ptr", "replace"]; -pub const PTR_SWAP: [&str; 3] = ["core", "ptr", "swap"]; -pub const PTR_UNALIGNED_VOLATILE_LOAD: [&str; 3] = ["core", "intrinsics", "unaligned_volatile_load"]; -pub const PTR_UNALIGNED_VOLATILE_STORE: [&str; 3] = ["core", "intrinsics", "unaligned_volatile_store"]; -pub const PTR_WRITE_BYTES: [&str; 3] = ["core", "intrinsics", "write_bytes"]; pub const PUSH_STR: [&str; 4] = ["alloc", "string", "String", "push_str"]; -pub const RANGE_ARGUMENT_TRAIT: [&str; 3] = ["core", "ops", "RangeBounds"]; -pub const REFCELL_REF: [&str; 3] = ["core", "cell", "Ref"]; -pub const REFCELL_REFMUT: [&str; 3] = ["core", "cell", "RefMut"]; pub const REGEX_BUILDER_NEW: [&str; 3] = ["regex", "RegexBuilder", "new"]; pub const REGEX_BYTES_BUILDER_NEW: [&str; 4] = ["regex", "bytes", "RegexBuilder", "new"]; pub const REGEX_BYTES_NEW: [&str; 4] = ["regex", "bytes", "Regex", "new"]; @@ -101,21 +73,11 @@ pub const REGEX_NEW: [&str; 3] = ["regex", "Regex", "new"]; pub const REGEX_SET_NEW: [&str; 3] = ["regex", "RegexSet", "new"]; pub const SERDE_DESERIALIZE: [&str; 3] = ["serde", "de", "Deserialize"]; pub const SERDE_DE_VISITOR: [&str; 3] = ["serde", "de", "Visitor"]; -pub const SLICE_FROM_RAW_PARTS: [&str; 4] = ["core", "slice", "raw", "from_raw_parts"]; -pub const SLICE_FROM_RAW_PARTS_MUT: [&str; 4] = ["core", "slice", "raw", "from_raw_parts_mut"]; pub const SLICE_GET: [&str; 4] = ["core", "slice", "", "get"]; pub const SLICE_INTO_VEC: [&str; 4] = ["alloc", "slice", "", "into_vec"]; pub const SLICE_INTO: [&str; 4] = ["core", "slice", "", "iter"]; -pub const SLICE_ITER: [&str; 4] = ["core", "slice", "iter", "Iter"]; -pub const STDERR: [&str; 4] = ["std", "io", "stdio", "stderr"]; -pub const STDOUT: [&str; 4] = ["std", "io", "stdio", "stdout"]; -pub const CONVERT_IDENTITY: [&str; 3] = ["core", "convert", "identity"]; -pub const STD_FS_CREATE_DIR: [&str; 3] = ["std", "fs", "create_dir"]; -pub const STD_IO_LINES: [&str; 3] = ["std", "io", "Lines"]; -pub const STD_IO_SEEK: [&str; 3] = ["std", "io", "Seek"]; pub const STD_IO_SEEK_FROM_CURRENT: [&str; 4] = ["std", "io", "SeekFrom", "Current"]; pub const STD_IO_SEEKFROM_START: [&str; 4] = ["std", "io", "SeekFrom", "Start"]; -pub const STD_PROCESS_COMMAND: [&str; 3] = ["std", "process", "Command"]; pub const STRING_AS_MUT_STR: [&str; 4] = ["alloc", "string", "String", "as_mut_str"]; pub const STRING_AS_STR: [&str; 4] = ["alloc", "string", "String", "as_str"]; pub const STRING_NEW: [&str; 4] = ["alloc", "string", "String", "new"]; @@ -136,13 +98,11 @@ pub const SYMBOL_TO_IDENT_STRING: [&str; 4] = ["rustc_span", "symbol", "Symbol", pub const SYM_MODULE: [&str; 3] = ["rustc_span", "symbol", "sym"]; #[cfg(feature = "internal")] pub const SYNTAX_CONTEXT: [&str; 3] = ["rustc_span", "hygiene", "SyntaxContext"]; -pub const TO_OWNED_METHOD: [&str; 4] = ["alloc", "borrow", "ToOwned", "to_owned"]; pub const TO_STRING_METHOD: [&str; 4] = ["alloc", "string", "ToString", "to_string"]; #[expect(clippy::invalid_paths)] // internal lints do not know about all external crates pub const TOKIO_IO_ASYNCREADEXT: [&str; 5] = ["tokio", "io", "util", "async_read_ext", "AsyncReadExt"]; #[expect(clippy::invalid_paths)] // internal lints do not know about all external crates pub const TOKIO_IO_ASYNCWRITEEXT: [&str; 5] = ["tokio", "io", "util", "async_write_ext", "AsyncWriteExt"]; -pub const TRY_FROM: [&str; 4] = ["core", "convert", "TryFrom", "try_from"]; pub const VEC_AS_MUT_SLICE: [&str; 4] = ["alloc", "vec", "Vec", "as_mut_slice"]; pub const VEC_AS_SLICE: [&str; 4] = ["alloc", "vec", "Vec", "as_slice"]; pub const VEC_DEQUE_ITER: [&str; 5] = ["alloc", "collections", "vec_deque", "VecDeque", "iter"]; @@ -150,18 +110,10 @@ pub const VEC_FROM_ELEM: [&str; 3] = ["alloc", "vec", "from_elem"]; pub const VEC_NEW: [&str; 4] = ["alloc", "vec", "Vec", "new"]; pub const VEC_WITH_CAPACITY: [&str; 4] = ["alloc", "vec", "Vec", "with_capacity"]; pub const VEC_RESIZE: [&str; 4] = ["alloc", "vec", "Vec", "resize"]; -pub const WEAK_ARC: [&str; 3] = ["alloc", "sync", "Weak"]; -pub const WEAK_RC: [&str; 3] = ["alloc", "rc", "Weak"]; -pub const PTR_NON_NULL: [&str; 4] = ["core", "ptr", "non_null", "NonNull"]; pub const INSTANT_NOW: [&str; 4] = ["std", "time", "Instant", "now"]; -pub const INSTANT: [&str; 3] = ["std", "time", "Instant"]; pub const VEC_IS_EMPTY: [&str; 4] = ["alloc", "vec", "Vec", "is_empty"]; pub const VEC_POP: [&str; 4] = ["alloc", "vec", "Vec", "pop"]; pub const OPTION_UNWRAP: [&str; 4] = ["core", "option", "Option", "unwrap"]; pub const OPTION_EXPECT: [&str; 4] = ["core", "option", "Option", "expect"]; -pub const FORMATTER: [&str; 3] = ["core", "fmt", "Formatter"]; -pub const DEBUG_STRUCT: [&str; 4] = ["core", "fmt", "builders", "DebugStruct"]; -pub const ORD_CMP: [&str; 4] = ["core", "cmp", "Ord", "cmp"]; #[expect(clippy::invalid_paths)] // not sure why it thinks this, it works so pub const BOOL_THEN: [&str; 4] = ["core", "bool", "", "then"]; -pub const ARRAY_INTO_ITER: [&str; 4] = ["core", "array", "iter", "IntoIter"]; diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 604dc76912e6..2d305a63eca1 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -31,7 +31,7 @@ use rustc_trait_selection::traits::{Obligation, ObligationCause}; use std::assert_matches::debug_assert_matches; use std::iter; -use crate::{match_def_path, path_res, paths}; +use crate::{match_def_path, path_res}; mod type_certainty; pub use type_certainty::expr_type_is_certain; @@ -461,10 +461,8 @@ pub fn needs_ordered_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { else if is_type_lang_item(cx, ty, LangItem::OwnedBox) || matches!( get_type_diagnostic_name(cx, ty), - Some(sym::HashSet | sym::Rc | sym::Arc | sym::cstring_type) + Some(sym::HashSet | sym::Rc | sym::Arc | sym::cstring_type | sym::RcWeak | sym::ArcWeak) ) - || match_type(cx, ty, &paths::WEAK_RC) - || match_type(cx, ty, &paths::WEAK_ARC) { // Check all of the generic arguments. if let ty::Adt(_, subs) = ty.kind() { diff --git a/tests/ui-internal/unnecessary_def_path_hardcoded_path.rs b/tests/ui-internal/unnecessary_def_path_hardcoded_path.rs index b5ff3a542056..60be29788134 100644 --- a/tests/ui-internal/unnecessary_def_path_hardcoded_path.rs +++ b/tests/ui-internal/unnecessary_def_path_hardcoded_path.rs @@ -11,6 +11,6 @@ fn main() { const DEREF_MUT_TRAIT: [&str; 4] = ["core", "ops", "deref", "DerefMut"]; const DEREF_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "Deref", "deref"]; - // Don't lint, not yet a diagnostic or language item - const DEREF_MUT_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "DerefMut", "deref_mut"]; + // Don't lint, not a diagnostic or language item + const OPS_MOD: [&str; 5] = ["core", "ops"]; } diff --git a/tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr b/tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr index 58b1fd92b5dc..076786329cd9 100644 --- a/tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr +++ b/tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr @@ -19,8 +19,8 @@ LL | const DEREF_MUT_TRAIT: [&str; 4] = ["core", "ops", "deref", "DerefMut"] error: hardcoded path to a diagnostic item --> $DIR/unnecessary_def_path_hardcoded_path.rs:12:43 | -LL | const DEREF_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "Deref", "deref"]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const OPS_MOD: [&str; 5] = ["core", "ops"]; + | ^^^^^^^^^^^^^^^ | = help: convert all references to use `sym::deref_method` From 90dd34ce1e10609853b94c6176756c5f9dfe22c9 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 6 Oct 2023 20:35:52 +0000 Subject: [PATCH 0957/1222] Extend impl's def_span to include where clauses --- tests/ui/crashes/ice-6252.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index cb65360d1291..f929bec9583c 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -31,7 +31,7 @@ LL | const VAL: T; | ------------ `VAL` from trait ... LL | impl TypeVal for Multiply where N: TypeVal {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation error: aborting due to 3 previous errors From 1e0b9e533e34e30fc396efeaeb5b836e606d7c41 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 10 Oct 2023 14:02:42 +1100 Subject: [PATCH 0958/1222] Rejig some top-level `rustc_hir_pretty` functions. There are several that are unused and can be removed. And there are some calls to `to_string`, which can be expressed more nicely as a `foo_to_string` call, and then `to_string` need not be `pub`. (This requires adding `pat_to_string`). --- clippy_lints/src/matches/match_wild_err_arm.rs | 2 +- clippy_lints/src/mut_reference.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/matches/match_wild_err_arm.rs b/clippy_lints/src/matches/match_wild_err_arm.rs index de911f7a0280..a2903e52ae08 100644 --- a/clippy_lints/src/matches/match_wild_err_arm.rs +++ b/clippy_lints/src/matches/match_wild_err_arm.rs @@ -19,7 +19,7 @@ pub(crate) fn check<'tcx>(cx: &LateContext<'tcx>, ex: &Expr<'tcx>, arms: &[Arm<' if is_type_diagnostic_item(cx, ex_ty, sym::Result) { for arm in arms { if let PatKind::TupleStruct(ref path, inner, _) = arm.pat.kind { - let path_str = rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false)); + let path_str = rustc_hir_pretty::qpath_to_string(path); if path_str == "Err" { let mut matching_wild = inner.iter().any(is_wild); let mut ident_bind_name = kw::Underscore; diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index e53e146ec5db..01b850cdb113 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed { cx, arguments.iter().collect(), cx.typeck_results().expr_ty(fn_expr), - &rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false)), + &rustc_hir_pretty::qpath_to_string(path), "function", ); } From 6c7dd3a85859f19e8285abc5d6c4b1646b66bc55 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 13 Sep 2023 16:04:42 +0000 Subject: [PATCH 0959/1222] Stabilize AFIT and RPITIT --- tests/ui/implied_bounds_in_impls.fixed | 1 - tests/ui/implied_bounds_in_impls.rs | 1 - tests/ui/implied_bounds_in_impls.stderr | 32 ++++++++++++------------- tests/ui/unused_async.rs | 1 - tests/ui/unused_async.stderr | 10 ++++---- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/tests/ui/implied_bounds_in_impls.fixed b/tests/ui/implied_bounds_in_impls.fixed index a50fa0ccf6e7..fa117aaddcd6 100644 --- a/tests/ui/implied_bounds_in_impls.fixed +++ b/tests/ui/implied_bounds_in_impls.fixed @@ -1,6 +1,5 @@ #![warn(clippy::implied_bounds_in_impls)] #![allow(dead_code)] -#![feature(return_position_impl_trait_in_trait)] use std::ops::{Deref, DerefMut}; diff --git a/tests/ui/implied_bounds_in_impls.rs b/tests/ui/implied_bounds_in_impls.rs index e74ed4425b81..c96aac151a7d 100644 --- a/tests/ui/implied_bounds_in_impls.rs +++ b/tests/ui/implied_bounds_in_impls.rs @@ -1,6 +1,5 @@ #![warn(clippy::implied_bounds_in_impls)] #![allow(dead_code)] -#![feature(return_position_impl_trait_in_trait)] use std::ops::{Deref, DerefMut}; diff --git a/tests/ui/implied_bounds_in_impls.stderr b/tests/ui/implied_bounds_in_impls.stderr index 72dc2a183a38..fb44f2aba174 100644 --- a/tests/ui/implied_bounds_in_impls.stderr +++ b/tests/ui/implied_bounds_in_impls.stderr @@ -1,5 +1,5 @@ error: this bound is already specified as the supertrait of `DerefMut` - --> $DIR/implied_bounds_in_impls.rs:13:36 + --> $DIR/implied_bounds_in_impls.rs:12:36 | LL | fn deref_derefmut(x: T) -> impl Deref + DerefMut { | ^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + fn deref_derefmut(x: T) -> impl DerefMut { | error: this bound is already specified as the supertrait of `GenericSubtrait` - --> $DIR/implied_bounds_in_impls.rs:30:37 + --> $DIR/implied_bounds_in_impls.rs:29:37 | LL | fn generics_implied() -> impl GenericTrait + GenericSubtrait | ^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + fn generics_implied() -> impl GenericSubtrait | error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, V>` - --> $DIR/implied_bounds_in_impls.rs:36:40 + --> $DIR/implied_bounds_in_impls.rs:35:40 | LL | fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} | ^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + fn generics_implied_multi() -> impl GenericTrait2 + GenericSubtrait<( | error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, V>` - --> $DIR/implied_bounds_in_impls.rs:36:60 + --> $DIR/implied_bounds_in_impls.rs:35:60 | LL | fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} | ^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + fn generics_implied_multi() -> impl GenericTrait + GenericSubtrait< | error: this bound is already specified as the supertrait of `GenericSubtrait<(), T, V>` - --> $DIR/implied_bounds_in_impls.rs:38:44 + --> $DIR/implied_bounds_in_impls.rs:37:44 | LL | fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> | ^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + fn generics_implied_multi2() -> impl GenericTrait2 + GenericSubtra | error: this bound is already specified as the supertrait of `GenericSubtrait<(), T, V>` - --> $DIR/implied_bounds_in_impls.rs:38:62 + --> $DIR/implied_bounds_in_impls.rs:37:62 | LL | fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> | ^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + fn generics_implied_multi2() -> impl GenericTrait + GenericSubtrai | error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, ()>` - --> $DIR/implied_bounds_in_impls.rs:48:28 + --> $DIR/implied_bounds_in_impls.rs:47:28 | LL | fn generics_same() -> impl GenericTrait + GenericSubtrait<(), i32, ()> {} | ^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + fn generics_same() -> impl GenericSubtrait<(), i32, ()> {} | error: this bound is already specified as the supertrait of `DerefMut` - --> $DIR/implied_bounds_in_impls.rs:52:20 + --> $DIR/implied_bounds_in_impls.rs:51:20 | LL | fn f() -> impl Deref + DerefMut; | ^^^^^ @@ -97,7 +97,7 @@ LL + fn f() -> impl DerefMut; | error: this bound is already specified as the supertrait of `DerefMut` - --> $DIR/implied_bounds_in_impls.rs:57:20 + --> $DIR/implied_bounds_in_impls.rs:56:20 | LL | fn f() -> impl Deref + DerefMut { | ^^^^^ @@ -109,7 +109,7 @@ LL + fn f() -> impl DerefMut { | error: this bound is already specified as the supertrait of `DerefMut` - --> $DIR/implied_bounds_in_impls.rs:63:20 + --> $DIR/implied_bounds_in_impls.rs:62:20 | LL | fn f() -> impl Deref + DerefMut { | ^^^^^ @@ -121,7 +121,7 @@ LL + fn f() -> impl DerefMut { | error: this bound is already specified as the supertrait of `PartialOrd` - --> $DIR/implied_bounds_in_impls.rs:74:41 + --> $DIR/implied_bounds_in_impls.rs:73:41 | LL | fn default_generic_param1() -> impl PartialEq + PartialOrd + Debug {} | ^^^^^^^^^ @@ -133,7 +133,7 @@ LL + fn default_generic_param1() -> impl PartialOrd + Debug {} | error: this bound is already specified as the supertrait of `PartialOrd` - --> $DIR/implied_bounds_in_impls.rs:75:54 + --> $DIR/implied_bounds_in_impls.rs:74:54 | LL | fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {} | ^^^^^^^^^ @@ -145,7 +145,7 @@ LL + fn default_generic_param2() -> impl PartialOrd + Debug {} | error: this bound is already specified as the supertrait of `DoubleEndedIterator` - --> $DIR/implied_bounds_in_impls.rs:88:26 + --> $DIR/implied_bounds_in_impls.rs:87:26 | LL | fn my_iter() -> impl Iterator + DoubleEndedIterator { | ^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + fn my_iter() -> impl DoubleEndedIterator { | error: this bound is already specified as the supertrait of `Copy` - --> $DIR/implied_bounds_in_impls.rs:93:27 + --> $DIR/implied_bounds_in_impls.rs:92:27 | LL | fn f() -> impl Copy + Clone { | ^^^^^ @@ -169,7 +169,7 @@ LL + fn f() -> impl Copy { | error: this bound is already specified as the supertrait of `Trait2` - --> $DIR/implied_bounds_in_impls.rs:107:21 + --> $DIR/implied_bounds_in_impls.rs:106:21 | LL | fn f2() -> impl Trait1 + Trait2 {} | ^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + fn f2() -> impl Trait2 {} | error: this bound is already specified as the supertrait of `Trait4` - --> $DIR/implied_bounds_in_impls.rs:122:21 + --> $DIR/implied_bounds_in_impls.rs:121:21 | LL | fn f3() -> impl Trait3 + Trait4 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unused_async.rs b/tests/ui/unused_async.rs index 71722e9afd0b..7ec8a3adb4cd 100644 --- a/tests/ui/unused_async.rs +++ b/tests/ui/unused_async.rs @@ -1,5 +1,4 @@ #![warn(clippy::unused_async)] -#![feature(async_fn_in_trait)] #![allow(incomplete_features)] use std::future::Future; diff --git a/tests/ui/unused_async.stderr b/tests/ui/unused_async.stderr index 077e8cacce14..c97a76a55cbe 100644 --- a/tests/ui/unused_async.stderr +++ b/tests/ui/unused_async.stderr @@ -1,5 +1,5 @@ error: unused `async` for function with no await statements - --> $DIR/unused_async.rs:13:5 + --> $DIR/unused_async.rs:12:5 | LL | / async fn async_block_await() { LL | | @@ -11,7 +11,7 @@ LL | | } | = help: consider removing the `async` from this function note: `await` used in an async block, which does not require the enclosing function to be `async` - --> $DIR/unused_async.rs:16:23 + --> $DIR/unused_async.rs:15:23 | LL | ready(()).await; | ^^^^^ @@ -19,7 +19,7 @@ LL | ready(()).await; = help: to override `-D warnings` add `#[allow(clippy::unused_async)]` error: unused `async` for function with no await statements - --> $DIR/unused_async.rs:46:5 + --> $DIR/unused_async.rs:45:5 | LL | async fn f3() {} | ^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL | async fn f3() {} = help: consider removing the `async` from this function error: unused `async` for function with no await statements - --> $DIR/unused_async.rs:59:1 + --> $DIR/unused_async.rs:58:1 | LL | / async fn foo() -> i32 { LL | | @@ -38,7 +38,7 @@ LL | | } = help: consider removing the `async` from this function error: unused `async` for function with no await statements - --> $DIR/unused_async.rs:71:5 + --> $DIR/unused_async.rs:70:5 | LL | / async fn unused(&self) -> i32 { LL | | From 75055cc6dc69926ba47b0111fb64d7205cebd410 Mon Sep 17 00:00:00 2001 From: Arthur Lafrance Date: Mon, 16 Oct 2023 13:52:50 -0700 Subject: [PATCH 0960/1222] fix lint failures in clippy --- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/entry.rs | 2 +- clippy_lints/src/formatting.rs | 2 +- clippy_lints/src/let_with_type_underscore.rs | 2 +- clippy_lints/src/manual_let_else.rs | 2 +- clippy_lints/src/matches/collapsible_match.rs | 2 +- clippy_lints/src/matches/manual_utils.rs | 4 ++-- clippy_lints/src/methods/map_unwrap_or.rs | 2 +- clippy_lints/src/needless_question_mark.rs | 2 +- clippy_lints/src/non_octal_unix_permissions.rs | 4 ++-- clippy_lints/src/redundant_async_block.rs | 2 +- clippy_lints/src/reference.rs | 2 +- clippy_lints/src/suspicious_xor_used_as_pow.rs | 2 +- clippy_utils/src/macros.rs | 2 +- 14 files changed, 16 insertions(+), 16 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 14877385646a..5134cf66050c 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -701,7 +701,7 @@ fn deref_method_same_type<'tcx>(result_ty: Ty<'tcx>, arg_ty: Ty<'tcx>) -> bool { fn in_postfix_position<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> bool { if let Some(parent) = get_parent_expr(cx, e) - && parent.span.ctxt() == e.span.ctxt() + && parent.span.eq_ctxt(e.span) { match parent.kind { ExprKind::Call(child, _) | ExprKind::MethodCall(_, child, _, _) | ExprKind::Index(child, _, _) diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 6197b5b19eb4..70a467dde613 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -241,7 +241,7 @@ fn try_parse_contains<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Optio }, ], _, - ) if key_span.ctxt() == expr.span.ctxt() => { + ) if key_span.eq_ctxt(expr.span) => { let id = cx.typeck_results().type_dependent_def_id(expr.hir_id)?; let expr = ContainsExpr { negated, diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index d03480c21084..4ebf0e9667df 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -274,7 +274,7 @@ fn check_array(cx: &EarlyContext<'_>, expr: &Expr) { for element in array { if_chain! { if let ExprKind::Binary(ref op, ref lhs, _) = element.kind; - if has_unary_equivalent(op.node) && lhs.span.ctxt() == op.span.ctxt(); + if has_unary_equivalent(op.node) && lhs.span.eq_ctxt(op.span); let space_span = lhs.span.between(op.span); if let Some(space_snippet) = snippet_opt(cx, space_span); let lint_span = lhs.span.with_lo(lhs.span.hi()); diff --git a/clippy_lints/src/let_with_type_underscore.rs b/clippy_lints/src/let_with_type_underscore.rs index 4e9d77ea156a..79d728a021c3 100644 --- a/clippy_lints/src/let_with_type_underscore.rs +++ b/clippy_lints/src/let_with_type_underscore.rs @@ -31,7 +31,7 @@ impl LateLintPass<'_> for UnderscoreTyped { if !in_external_macro(cx.tcx.sess, local.span); if let Some(ty) = local.ty; // Ensure that it has a type defined if let TyKind::Infer = &ty.kind; // that type is '_' - if local.span.ctxt() == ty.span.ctxt(); + if local.span.eq_ctxt(ty.span); then { // NOTE: Using `is_from_proc_macro` on `init` will require that it's initialized, // this doesn't. Alternatively, `WithSearchPat` can be implemented for `Ty` diff --git a/clippy_lints/src/manual_let_else.rs b/clippy_lints/src/manual_let_else.rs index 2117308cd400..86bbdb4ea199 100644 --- a/clippy_lints/src/manual_let_else.rs +++ b/clippy_lints/src/manual_let_else.rs @@ -59,7 +59,7 @@ impl<'tcx> QuestionMark { let Some(init) = local.init && local.els.is_none() && local.ty.is_none() && - init.span.ctxt() == stmt.span.ctxt() && + init.span.eq_ctxt(stmt.span) && let Some(if_let_or_match) = IfLetOrMatch::parse(cx, init) { match if_let_or_match { diff --git a/clippy_lints/src/matches/collapsible_match.rs b/clippy_lints/src/matches/collapsible_match.rs index 33a052c41a38..29b935fb61a8 100644 --- a/clippy_lints/src/matches/collapsible_match.rs +++ b/clippy_lints/src/matches/collapsible_match.rs @@ -57,7 +57,7 @@ fn check_arm<'tcx>( } }, }; - if outer_pat.span.ctxt() == inner_scrutinee.span.ctxt(); + if outer_pat.span.eq_ctxt(inner_scrutinee.span); // match expression must be a local binding // match { .. } if let Some(binding_id) = path_to_local(peel_ref_operators(cx, inner_scrutinee)); diff --git a/clippy_lints/src/matches/manual_utils.rs b/clippy_lints/src/matches/manual_utils.rs index 6b611f567ae2..781ee138c76f 100644 --- a/clippy_lints/src/matches/manual_utils.rs +++ b/clippy_lints/src/matches/manual_utils.rs @@ -119,7 +119,7 @@ where // it's being passed by value. let scrutinee = peel_hir_expr_refs(scrutinee).0; let (scrutinee_str, _) = snippet_with_context(cx, scrutinee.span, expr_ctxt, "..", &mut app); - let scrutinee_str = if scrutinee.span.ctxt() == expr.span.ctxt() && scrutinee.precedence().order() < PREC_POSTFIX { + let scrutinee_str = if scrutinee.span.eq_ctxt(expr.span) && scrutinee.precedence().order() < PREC_POSTFIX { format!("({scrutinee_str})") } else { scrutinee_str.into() @@ -130,7 +130,7 @@ where if_chain! { if !some_expr.needs_unsafe_block; if let Some(func) = can_pass_as_func(cx, id, some_expr.expr); - if func.span.ctxt() == some_expr.expr.span.ctxt(); + if func.span.eq_ctxt(some_expr.expr.span); then { snippet_with_applicability(cx, func.span, "..", &mut app).into_owned() } else { diff --git a/clippy_lints/src/methods/map_unwrap_or.rs b/clippy_lints/src/methods/map_unwrap_or.rs index 5464e455dea4..e70a1bc98799 100644 --- a/clippy_lints/src/methods/map_unwrap_or.rs +++ b/clippy_lints/src/methods/map_unwrap_or.rs @@ -56,7 +56,7 @@ pub(super) fn check<'tcx>( // lint, with note if neither arg is > 1 line and both map() and // unwrap_or_else() have the same span let multiline = map_snippet.lines().count() > 1 || unwrap_snippet.lines().count() > 1; - let same_span = map_arg.span.ctxt() == unwrap_arg.span.ctxt(); + let same_span = map_arg.span.eq_ctxt(unwrap_arg.span); if same_span && !multiline { let var_snippet = snippet(cx, recv.span, ".."); span_lint_and_sugg( diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index 7b0f7eaf1f06..0e834fb3ac76 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -125,7 +125,7 @@ fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { if let ExprKind::Match(inner_expr_with_q, _, MatchSource::TryDesugar(_)) = &arg.kind; if let ExprKind::Call(called, [inner_expr]) = &inner_expr_with_q.kind; if let ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, ..)) = &called.kind; - if expr.span.ctxt() == inner_expr.span.ctxt(); + if expr.span.eq_ctxt(inner_expr.span); let expr_ty = cx.typeck_results().expr_ty(expr); let inner_ty = cx.typeck_results().expr_ty(inner_expr); if expr_ty == inner_ty; diff --git a/clippy_lints/src/non_octal_unix_permissions.rs b/clippy_lints/src/non_octal_unix_permissions.rs index d47728f190ab..e94e45899660 100644 --- a/clippy_lints/src/non_octal_unix_permissions.rs +++ b/clippy_lints/src/non_octal_unix_permissions.rs @@ -51,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for NonOctalUnixPermissions { || (path.ident.name == sym!(set_mode) && cx.tcx.is_diagnostic_item(sym::FsPermissions, adt.did())); if let ExprKind::Lit(_) = param.kind; - if param.span.ctxt() == expr.span.ctxt(); + if param.span.eq_ctxt(expr.span); then { let Some(snip) = snippet_opt(cx, param.span) else { @@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for NonOctalUnixPermissions { if let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::PERMISSIONS_FROM_MODE); if let ExprKind::Lit(_) = param.kind; - if param.span.ctxt() == expr.span.ctxt(); + if param.span.eq_ctxt(expr.span); if let Some(snip) = snippet_opt(cx, param.span); if !snip.starts_with("0o"); then { diff --git a/clippy_lints/src/redundant_async_block.rs b/clippy_lints/src/redundant_async_block.rs index 534b2762ba76..8193057a6eb2 100644 --- a/clippy_lints/src/redundant_async_block.rs +++ b/clippy_lints/src/redundant_async_block.rs @@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantAsyncBlock { let Some(body_expr) = desugar_async_block(cx, expr) && let Some(expr) = desugar_await(peel_blocks(body_expr)) && // The await prefix must not come from a macro as its content could change in the future. - expr.span.ctxt() == body_expr.span.ctxt() && + expr.span.eq_ctxt(body_expr.span) && // An async block does not have immediate side-effects from a `.await` point-of-view. (!expr.can_have_side_effects() || desugar_async_block(cx, expr).is_some()) && let Some(shortened_span) = walk_span_to_context(expr.span, span.ctxt()) diff --git a/clippy_lints/src/reference.rs b/clippy_lints/src/reference.rs index db870ec4c5b6..12da29f11089 100644 --- a/clippy_lints/src/reference.rs +++ b/clippy_lints/src/reference.rs @@ -50,7 +50,7 @@ impl EarlyLintPass for DerefAddrOf { if_chain! { if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.kind; if let ExprKind::AddrOf(_, ref mutability, ref addrof_target) = without_parens(deref_target).kind; - if deref_target.span.ctxt() == e.span.ctxt(); + if deref_target.span.eq_ctxt(e.span); if !addrof_target.span.from_expansion(); then { let mut applicability = Applicability::MachineApplicable; diff --git a/clippy_lints/src/suspicious_xor_used_as_pow.rs b/clippy_lints/src/suspicious_xor_used_as_pow.rs index 8e156b8829b9..39cd289b67ad 100644 --- a/clippy_lints/src/suspicious_xor_used_as_pow.rs +++ b/clippy_lints/src/suspicious_xor_used_as_pow.rs @@ -33,7 +33,7 @@ impl LateLintPass<'_> for ConfusingXorAndPow { if !in_external_macro(cx.sess(), expr.span) && let ExprKind::Binary(op, left, right) = &expr.kind && op.node == BinOpKind::BitXor - && left.span.ctxt() == right.span.ctxt() + && left.span.eq_ctxt(right.span) && let ExprKind::Lit(lit_left) = &left.kind && let ExprKind::Lit(lit_right) = &right.kind && matches!(lit_right.node, LitKind::Int(..) | LitKind::Float(..)) diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs index eaf590f6ad77..46ce4ffdce5d 100644 --- a/clippy_utils/src/macros.rs +++ b/clippy_utils/src/macros.rs @@ -245,7 +245,7 @@ impl<'a> PanicExpn<'a> { return None; }; let result = match name { - "panic" if arg.span.ctxt() == expr.span.ctxt() => Self::Empty, + "panic" if arg.span.eq_ctxt(expr.span) => Self::Empty, "panic" | "panic_str" => Self::Str(arg), "panic_display" | "panic_cold_display" => { let ExprKind::AddrOf(_, _, e) = &arg.kind else { From 9cd0bf03e7d1f12c226eb89cd04514f24b0415ef Mon Sep 17 00:00:00 2001 From: Urgau Date: Wed, 23 Aug 2023 17:58:21 +0200 Subject: [PATCH 0961/1222] [RFC 3127 - Trim Paths]: Fix building tools (rustdoc, clippy, ...) --- clippy_lints/src/utils/internal_lints/metadata_collector.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index c38a3e81b0f7..c8600badf18e 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -494,7 +494,7 @@ impl SerializableSpan { let loc: Loc = cx.sess().source_map().lookup_char_pos(span.lo()); Self { - path: format!("{}", loc.file.name.prefer_remapped()), + path: format!("{}", loc.file.name.prefer_remapped_unconditionaly()), line: loc.line, } } From 53b4670abf4a1498d81fb0496029c5764a49dce8 Mon Sep 17 00:00:00 2001 From: lcnr Date: Wed, 18 Oct 2023 13:57:19 +0200 Subject: [PATCH 0962/1222] AliasTy::new instead of tcx method --- clippy_utils/src/ty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 2d305a63eca1..673b259523e1 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -1133,7 +1133,7 @@ pub fn make_projection<'tcx>( #[cfg(debug_assertions)] assert_generic_args_match(tcx, assoc_item.def_id, args); - Some(tcx.mk_alias_ty(assoc_item.def_id, args)) + Some(ty::AliasTy::new(tcx, assoc_item.def_id, args)) } helper( tcx, From 48dad1d1cbad4ba396cc4eb873679d13efdcb426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 18 Oct 2023 22:10:48 +0000 Subject: [PATCH 0963/1222] Tweak wording of type errors involving type params Fix #78206. --- tests/ui/builtin_type_shadow.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/builtin_type_shadow.stderr b/tests/ui/builtin_type_shadow.stderr index cb8462182b89..e051c00eb8d2 100644 --- a/tests/ui/builtin_type_shadow.stderr +++ b/tests/ui/builtin_type_shadow.stderr @@ -13,7 +13,7 @@ error[E0308]: mismatched types LL | fn foo(a: u32) -> u32 { | --- --- expected `u32` because of return type | | - | this type parameter + | expected this type parameter LL | 42 | ^^ expected type parameter `u32`, found integer | From daff42902dfbbc8945f5cd77cbe27225265ee8a9 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 18 Oct 2023 08:47:17 +0000 Subject: [PATCH 0964/1222] Avoid a `track_errors` by bubbling up most errors from `check_well_formed` --- tests/ui/crashes/ice-6252.stderr | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index f929bec9583c..30be9dde73c3 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -24,16 +24,6 @@ help: you might be missing a type parameter LL | impl TypeVal for Multiply where N: TypeVal {} | +++++ -error[E0046]: not all trait items implemented, missing: `VAL` - --> $DIR/ice-6252.rs:11:1 - | -LL | const VAL: T; - | ------------ `VAL` from trait -... -LL | impl TypeVal for Multiply where N: TypeVal {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors -Some errors have detailed explanations: E0046, E0412. -For more information about an error, try `rustc --explain E0046`. +For more information about this error, try `rustc --explain E0412`. From 224ba1c0eab7962993229cb6a99394327af1cd74 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 19 Oct 2023 16:06:43 +0000 Subject: [PATCH 0965/1222] s/Generator/Coroutine/ --- clippy_lints/src/async_yields_async.rs | 6 +++--- clippy_lints/src/await_holding_invalid.rs | 10 +++++----- clippy_lints/src/dereference.rs | 4 ++-- clippy_lints/src/doc.rs | 2 +- clippy_lints/src/large_futures.rs | 2 +- clippy_lints/src/manual_async_fn.rs | 4 ++-- clippy_lints/src/needless_question_mark.rs | 4 ++-- clippy_lints/src/redundant_async_block.rs | 4 ++-- clippy_lints/src/unused_async.rs | 2 +- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/clippy_lints/src/async_yields_async.rs b/clippy_lints/src/async_yields_async.rs index 9464694a3b55..99daec560e75 100644 --- a/clippy_lints/src/async_yields_async.rs +++ b/clippy_lints/src/async_yields_async.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::source::snippet; use clippy_utils::ty::implements_trait; use rustc_errors::Applicability; -use rustc_hir::{AsyncGeneratorKind, Body, BodyId, ExprKind, GeneratorKind, QPath}; +use rustc_hir::{AsyncCoroutineKind, Body, BodyId, ExprKind, CoroutineKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -45,10 +45,10 @@ declare_lint_pass!(AsyncYieldsAsync => [ASYNC_YIELDS_ASYNC]); impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync { fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) { - use AsyncGeneratorKind::{Block, Closure}; + use AsyncCoroutineKind::{Block, Closure}; // For functions, with explicitly defined types, don't warn. // XXXkhuey maybe we should? - if let Some(GeneratorKind::Async(Block | Closure)) = body.generator_kind { + if let Some(CoroutineKind::Async(Block | Closure)) = body.generator_kind { if let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait() { let body_id = BodyId { hir_id: body.value.hir_id, diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index accff9b0a34c..65d131c5751a 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -2,9 +2,9 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::{match_def_path, paths}; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::DefId; -use rustc_hir::{AsyncGeneratorKind, Body, GeneratorKind}; +use rustc_hir::{AsyncCoroutineKind, Body, CoroutineKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::mir::GeneratorLayout; +use rustc_middle::mir::CoroutineLayout; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{sym, Span}; @@ -195,8 +195,8 @@ impl LateLintPass<'_> for AwaitHolding { } fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { - use AsyncGeneratorKind::{Block, Closure, Fn}; - if let Some(GeneratorKind::Async(Block | Closure | Fn)) = body.generator_kind { + use AsyncCoroutineKind::{Block, Closure, Fn}; + if let Some(CoroutineKind::Async(Block | Closure | Fn)) = body.generator_kind { let def_id = cx.tcx.hir().body_owner_def_id(body.id()); if let Some(generator_layout) = cx.tcx.mir_generator_witnesses(def_id) { self.check_interior_types(cx, generator_layout); @@ -206,7 +206,7 @@ impl LateLintPass<'_> for AwaitHolding { } impl AwaitHolding { - fn check_interior_types(&self, cx: &LateContext<'_>, generator: &GeneratorLayout<'_>) { + fn check_interior_types(&self, cx: &LateContext<'_>, generator: &CoroutineLayout<'_>) { for (ty_index, ty_cause) in generator.field_tys.iter_enumerated() { if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind() { let await_points = || { diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 5134cf66050c..efe82036dc80 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -842,8 +842,8 @@ impl TyCoercionStability { | ty::Adt(..) | ty::Foreign(_) | ty::FnDef(..) - | ty::Generator(..) - | ty::GeneratorWitness(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) | ty::Closure(..) | ty::Never | ty::Tuple(_) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index e789e0da6797..ca9defc2bf35 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -436,7 +436,7 @@ fn lint_for_missing_headers( let body = cx.tcx.hir().body(body_id); let ret_ty = typeck.expr_ty(body.value); if implements_trait(cx, ret_ty, future, &[]); - if let ty::Generator(_, subs, _) = ret_ty.kind(); + if let ty::Coroutine(_, subs, _) = ret_ty.kind(); if is_type_diagnostic_item(cx, subs.as_generator().return_ty(), sym::Result); then { span_lint( diff --git a/clippy_lints/src/large_futures.rs b/clippy_lints/src/large_futures.rs index 19f1e08b57ad..90096f0f506d 100644 --- a/clippy_lints/src/large_futures.rs +++ b/clippy_lints/src/large_futures.rs @@ -12,7 +12,7 @@ declare_clippy_lint! { /// It checks for the size of a `Future` created by `async fn` or `async {}`. /// /// ### Why is this bad? - /// Due to the current [unideal implementation](https://github.com/rust-lang/rust/issues/69826) of `Generator`, + /// Due to the current [unideal implementation](https://github.com/rust-lang/rust/issues/69826) of `Coroutine`, /// large size of a `Future` may cause stack overflows. /// /// ### Example diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 577bc1d661db..499763347517 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -4,7 +4,7 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{ - AsyncGeneratorKind, Block, Body, Closure, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound, + AsyncCoroutineKind, Block, Body, Closure, Expr, ExprKind, FnDecl, FnRetTy, CoroutineKind, GenericArg, GenericBound, ImplItem, Item, ItemKind, LifetimeName, Node, Term, TraitRef, Ty, TyKind, TypeBindingKind, }; use rustc_lint::{LateContext, LateLintPass}; @@ -188,7 +188,7 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) .. } = block_expr; let closure_body = cx.tcx.hir().body(body); - if closure_body.generator_kind == Some(GeneratorKind::Async(AsyncGeneratorKind::Block)); + if closure_body.generator_kind == Some(CoroutineKind::Async(AsyncCoroutineKind::Block)); then { return Some(closure_body); } diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index 0e834fb3ac76..f2c823323bbb 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{AsyncGeneratorKind, Block, Body, Expr, ExprKind, GeneratorKind, LangItem, MatchSource, QPath}; +use rustc_hir::{AsyncCoroutineKind, Block, Body, Expr, ExprKind, CoroutineKind, LangItem, MatchSource, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -87,7 +87,7 @@ impl LateLintPass<'_> for NeedlessQuestionMark { } fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { - if let Some(GeneratorKind::Async(AsyncGeneratorKind::Fn)) = body.generator_kind { + if let Some(CoroutineKind::Async(AsyncCoroutineKind::Fn)) = body.generator_kind { if let ExprKind::Block( Block { expr: diff --git a/clippy_lints/src/redundant_async_block.rs b/clippy_lints/src/redundant_async_block.rs index 8193057a6eb2..59aecd232783 100644 --- a/clippy_lints/src/redundant_async_block.rs +++ b/clippy_lints/src/redundant_async_block.rs @@ -5,7 +5,7 @@ use clippy_utils::peel_blocks; use clippy_utils::source::{snippet, walk_span_to_context}; use clippy_utils::visitors::for_each_expr; use rustc_errors::Applicability; -use rustc_hir::{AsyncGeneratorKind, Closure, Expr, ExprKind, GeneratorKind, MatchSource}; +use rustc_hir::{AsyncCoroutineKind, Closure, Expr, ExprKind, CoroutineKind, MatchSource}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::UpvarCapture; @@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantAsyncBlock { fn desugar_async_block<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { if let ExprKind::Closure(Closure { body, def_id, .. }) = expr.kind && let body = cx.tcx.hir().body(*body) && - matches!(body.generator_kind, Some(GeneratorKind::Async(AsyncGeneratorKind::Block))) + matches!(body.generator_kind, Some(CoroutineKind::Async(AsyncCoroutineKind::Block))) { cx .typeck_results() diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index bc7c3897a6e8..5e1ba1b0dc06 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -86,7 +86,7 @@ impl<'a, 'tcx> Visitor<'tcx> for AsyncFnVisitor<'a, 'tcx> { } fn visit_body(&mut self, b: &'tcx Body<'tcx>) { - let is_async_block = matches!(b.generator_kind, Some(rustc_hir::GeneratorKind::Async(_))); + let is_async_block = matches!(b.generator_kind, Some(rustc_hir::CoroutineKind::Async(_))); if is_async_block { self.async_depth += 1; diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 55f9cb27ad4d..0d8fd9d2adf1 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -305,7 +305,7 @@ fn check_terminator<'tcx>( Ok(()) }, TerminatorKind::SwitchInt { discr, targets: _ } => check_operand(tcx, discr, span, body), - TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => { + TerminatorKind::CoroutineDrop | TerminatorKind::Yield { .. } => { Err((span, "const fn generators are unstable".into())) }, TerminatorKind::Call { From 8f4f6236933d622793ac685912c3fcea94070a40 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 19 Oct 2023 21:46:28 +0000 Subject: [PATCH 0966/1222] s/generator/coroutine/ --- clippy_lints/src/async_yields_async.rs | 2 +- clippy_lints/src/await_holding_invalid.rs | 14 +++++++------- clippy_lints/src/doc.rs | 2 +- clippy_lints/src/manual_async_fn.rs | 2 +- clippy_lints/src/methods/iter_kv_map.rs | 2 +- clippy_lints/src/needless_question_mark.rs | 2 +- clippy_lints/src/redundant_async_block.rs | 2 +- clippy_lints/src/redundant_closure_call.rs | 4 ++-- clippy_lints/src/unused_async.rs | 2 +- clippy_utils/src/qualify_min_const_fn.rs | 2 +- tests/ui/crashes/ice-5238.rs | 2 +- tests/ui/large_futures.fixed | 2 +- tests/ui/large_futures.rs | 2 +- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/clippy_lints/src/async_yields_async.rs b/clippy_lints/src/async_yields_async.rs index 99daec560e75..96a90d599aba 100644 --- a/clippy_lints/src/async_yields_async.rs +++ b/clippy_lints/src/async_yields_async.rs @@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync { use AsyncCoroutineKind::{Block, Closure}; // For functions, with explicitly defined types, don't warn. // XXXkhuey maybe we should? - if let Some(CoroutineKind::Async(Block | Closure)) = body.generator_kind { + if let Some(CoroutineKind::Async(Block | Closure)) = body.coroutine_kind { if let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait() { let body_id = BodyId { hir_id: body.value.hir_id, diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index 65d131c5751a..60f9bbd7458b 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -196,25 +196,25 @@ impl LateLintPass<'_> for AwaitHolding { fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { use AsyncCoroutineKind::{Block, Closure, Fn}; - if let Some(CoroutineKind::Async(Block | Closure | Fn)) = body.generator_kind { + if let Some(CoroutineKind::Async(Block | Closure | Fn)) = body.coroutine_kind { let def_id = cx.tcx.hir().body_owner_def_id(body.id()); - if let Some(generator_layout) = cx.tcx.mir_generator_witnesses(def_id) { - self.check_interior_types(cx, generator_layout); + if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(def_id) { + self.check_interior_types(cx, coroutine_layout); } } } } impl AwaitHolding { - fn check_interior_types(&self, cx: &LateContext<'_>, generator: &CoroutineLayout<'_>) { - for (ty_index, ty_cause) in generator.field_tys.iter_enumerated() { + fn check_interior_types(&self, cx: &LateContext<'_>, coroutine: &CoroutineLayout<'_>) { + for (ty_index, ty_cause) in coroutine.field_tys.iter_enumerated() { if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind() { let await_points = || { - generator + coroutine .variant_source_info .iter_enumerated() .filter_map(|(variant, source_info)| { - generator.variant_fields[variant] + coroutine.variant_fields[variant] .raw .contains(&ty_index) .then_some(source_info.span) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index ca9defc2bf35..fc9b381664a3 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -437,7 +437,7 @@ fn lint_for_missing_headers( let ret_ty = typeck.expr_ty(body.value); if implements_trait(cx, ret_ty, future, &[]); if let ty::Coroutine(_, subs, _) = ret_ty.kind(); - if is_type_diagnostic_item(cx, subs.as_generator().return_ty(), sym::Result); + if is_type_diagnostic_item(cx, subs.as_coroutine().return_ty(), sym::Result); then { span_lint( cx, diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 499763347517..914ceca2995d 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -188,7 +188,7 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) .. } = block_expr; let closure_body = cx.tcx.hir().body(body); - if closure_body.generator_kind == Some(CoroutineKind::Async(AsyncCoroutineKind::Block)); + if closure_body.coroutine_kind == Some(CoroutineKind::Async(AsyncCoroutineKind::Block)); then { return Some(closure_body); } diff --git a/clippy_lints/src/methods/iter_kv_map.rs b/clippy_lints/src/methods/iter_kv_map.rs index 674d34517481..b44a2716dde1 100644 --- a/clippy_lints/src/methods/iter_kv_map.rs +++ b/clippy_lints/src/methods/iter_kv_map.rs @@ -26,7 +26,7 @@ pub(super) fn check<'tcx>( if_chain! { if !expr.span.from_expansion(); if let ExprKind::Closure(c) = m_arg.kind; - if let Body {params: [p], value: body_expr, generator_kind: _ } = cx.tcx.hir().body(c.body); + if let Body {params: [p], value: body_expr, coroutine_kind: _ } = cx.tcx.hir().body(c.body); if let PatKind::Tuple([key_pat, val_pat], _) = p.pat.kind; let (replacement_kind, annotation, bound_ident) = match (&key_pat.kind, &val_pat.kind) { diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index f2c823323bbb..d267b3de7f25 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -87,7 +87,7 @@ impl LateLintPass<'_> for NeedlessQuestionMark { } fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { - if let Some(CoroutineKind::Async(AsyncCoroutineKind::Fn)) = body.generator_kind { + if let Some(CoroutineKind::Async(AsyncCoroutineKind::Fn)) = body.coroutine_kind { if let ExprKind::Block( Block { expr: diff --git a/clippy_lints/src/redundant_async_block.rs b/clippy_lints/src/redundant_async_block.rs index 59aecd232783..b8f787e1f1fb 100644 --- a/clippy_lints/src/redundant_async_block.rs +++ b/clippy_lints/src/redundant_async_block.rs @@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantAsyncBlock { fn desugar_async_block<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { if let ExprKind::Closure(Closure { body, def_id, .. }) = expr.kind && let body = cx.tcx.hir().body(*body) && - matches!(body.generator_kind, Some(CoroutineKind::Async(AsyncCoroutineKind::Block))) + matches!(body.coroutine_kind, Some(CoroutineKind::Async(AsyncCoroutineKind::Block))) { cx .typeck_results() diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index f42836611ca5..c18237e887db 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { // without this check, we'd end up linting twice. && !matches!(recv.kind, hir::ExprKind::Call(..)) && let (full_expr, call_depth) = get_parent_call_exprs(cx, expr) - && let Some((body, fn_decl, generator_kind)) = find_innermost_closure(cx, recv, call_depth) + && let Some((body, fn_decl, coroutine_kind)) = find_innermost_closure(cx, recv, call_depth) { span_lint_and_then( cx, @@ -156,7 +156,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { let mut applicability = Applicability::MachineApplicable; let mut hint = Sugg::hir_with_context(cx, body, full_expr.span.ctxt(), "..", &mut applicability); - if generator_kind.is_async() + if coroutine_kind.is_async() && let hir::ExprKind::Closure(closure) = body.kind { let async_closure_body = cx.tcx.hir().body(closure.body); diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index 5e1ba1b0dc06..3649f8792ae5 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -86,7 +86,7 @@ impl<'a, 'tcx> Visitor<'tcx> for AsyncFnVisitor<'a, 'tcx> { } fn visit_body(&mut self, b: &'tcx Body<'tcx>) { - let is_async_block = matches!(b.generator_kind, Some(rustc_hir::CoroutineKind::Async(_))); + let is_async_block = matches!(b.coroutine_kind, Some(rustc_hir::CoroutineKind::Async(_))); if is_async_block { self.async_depth += 1; diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 0d8fd9d2adf1..f6096ea546da 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -306,7 +306,7 @@ fn check_terminator<'tcx>( }, TerminatorKind::SwitchInt { discr, targets: _ } => check_operand(tcx, discr, span, body), TerminatorKind::CoroutineDrop | TerminatorKind::Yield { .. } => { - Err((span, "const fn generators are unstable".into())) + Err((span, "const fn coroutines are unstable".into())) }, TerminatorKind::Call { func, diff --git a/tests/ui/crashes/ice-5238.rs b/tests/ui/crashes/ice-5238.rs index 989eb6d44855..b1fc3fb9d251 100644 --- a/tests/ui/crashes/ice-5238.rs +++ b/tests/ui/crashes/ice-5238.rs @@ -1,6 +1,6 @@ // Regression test for #5238 / https://github.com/rust-lang/rust/pull/69562 -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] fn main() { let _ = || { diff --git a/tests/ui/large_futures.fixed b/tests/ui/large_futures.fixed index 4c192d1c8d1b..aa8c3021b970 100644 --- a/tests/ui/large_futures.fixed +++ b/tests/ui/large_futures.fixed @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] #![warn(clippy::large_futures)] #![allow(clippy::never_loop)] #![allow(clippy::future_not_send)] diff --git a/tests/ui/large_futures.rs b/tests/ui/large_futures.rs index 557d89a9cf99..fc6ea458d3db 100644 --- a/tests/ui/large_futures.rs +++ b/tests/ui/large_futures.rs @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] #![warn(clippy::large_futures)] #![allow(clippy::never_loop)] #![allow(clippy::future_not_send)] From b2abd54590874281b3b7e2ccc9c8d9b9bb10ff8c Mon Sep 17 00:00:00 2001 From: bohan Date: Sun, 15 Oct 2023 19:38:22 +0800 Subject: [PATCH 0967/1222] use visibility to check unused imports and delete some stmts --- tests/ui/enum_glob_use.fixed | 1 + tests/ui/enum_glob_use.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/ui/enum_glob_use.fixed b/tests/ui/enum_glob_use.fixed index 9044e80268db..3c0db9beb1a6 100644 --- a/tests/ui/enum_glob_use.fixed +++ b/tests/ui/enum_glob_use.fixed @@ -19,6 +19,7 @@ mod in_fn_test { } mod blurg { + #[allow(unused_imports)] pub use std::cmp::Ordering::*; // ok, re-export } diff --git a/tests/ui/enum_glob_use.rs b/tests/ui/enum_glob_use.rs index 4f157a97cbc9..2538477f7978 100644 --- a/tests/ui/enum_glob_use.rs +++ b/tests/ui/enum_glob_use.rs @@ -19,6 +19,7 @@ mod in_fn_test { } mod blurg { + #[allow(unused_imports)] pub use std::cmp::Ordering::*; // ok, re-export } From d2aea4ba54742f10a2e7bffa43f6f5f62530d92d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 15 Oct 2023 12:53:37 -0700 Subject: [PATCH 0968/1222] Fix stable feature names in tests --- tests/ui/missing_const_for_fn/auxiliary/helper.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/missing_const_for_fn/auxiliary/helper.rs b/tests/ui/missing_const_for_fn/auxiliary/helper.rs index 7b9dc76b8f1d..775e071147cf 100644 --- a/tests/ui/missing_const_for_fn/auxiliary/helper.rs +++ b/tests/ui/missing_const_for_fn/auxiliary/helper.rs @@ -1,8 +1,8 @@ // This file provides a const function that is unstably const forever. #![feature(staged_api)] -#![stable(feature = "1", since = "1.0.0")] +#![stable(feature = "clippytest", since = "1.0.0")] -#[stable(feature = "1", since = "1.0.0")] +#[stable(feature = "clippytest", since = "1.0.0")] #[rustc_const_unstable(feature = "foo", issue = "none")] pub const fn unstably_const_fn() {} From f5740af2e5db8e9e2367278c54cc8e5936716e4d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 24 Oct 2023 17:57:02 -0700 Subject: [PATCH 0969/1222] Handle structured stable attribute 'since' version in clippy --- clippy_utils/src/qualify_min_const_fn.rs | 31 +++++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index f6096ea546da..514988c6744d 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -5,6 +5,7 @@ use crate::msrvs::Msrv; use hir::LangItem; +use rustc_attr::{rust_version_symbol, Since}; use rustc_const_eval::transform::check_consts::ConstCx; use rustc_hir as hir; use rustc_hir::def_id::DefId; @@ -370,19 +371,25 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool { // function could be removed if `rustc` provided a MSRV-aware version of `is_const_fn`. // as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262. - // HACK(nilstrieb): CURRENT_RUSTC_VERSION can return versions like 1.66.0-dev. `rustc-semver` - // doesn't accept the `-dev` version number so we have to strip it off. - let short_version = since - .as_str() - .split('-') - .next() - .expect("rustc_attr::StabilityLevel::Stable::since` is empty"); + let const_stab_rust_version = match since { + Since::Version(version) => RustcVersion::new( + u32::from(version.major), + u32::from(version.minor), + u32::from(version.patch), + ), + Since::Current => { + // HACK(nilstrieb): CURRENT_RUSTC_VERSION can return versions like 1.66.0-dev. + // `rustc-semver` doesn't accept the `-dev` version number so we have to strip it off. + let current_rustc_version = rust_version_symbol(); + let short_version = current_rustc_version.as_str().split('-').next().unwrap(); + RustcVersion::parse(short_version).unwrap_or_else(|err| { + panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{current_rustc_version}`, {err:?}") + }) + }, + Since::Err => return false, + }; - let since = rustc_span::Symbol::intern(short_version); - - msrv.meets(RustcVersion::parse(since.as_str()).unwrap_or_else(|err| { - panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{since}`, {err:?}") - })) + msrv.meets(const_stab_rust_version) } else { // Unstable const fn with the feature enabled. msrv.current().is_none() From 2db441c2ed446a057e52aca01e8186eea2351345 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 24 Oct 2023 18:06:57 -0700 Subject: [PATCH 0970/1222] Expose a non-Symbol way to access current rustc version string --- clippy_utils/src/qualify_min_const_fn.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 514988c6744d..1e465ac91b76 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -5,7 +5,7 @@ use crate::msrvs::Msrv; use hir::LangItem; -use rustc_attr::{rust_version_symbol, Since}; +use rustc_attr::{Since, CURRENT_RUSTC_VERSION}; use rustc_const_eval::transform::check_consts::ConstCx; use rustc_hir as hir; use rustc_hir::def_id::DefId; @@ -380,10 +380,9 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool { Since::Current => { // HACK(nilstrieb): CURRENT_RUSTC_VERSION can return versions like 1.66.0-dev. // `rustc-semver` doesn't accept the `-dev` version number so we have to strip it off. - let current_rustc_version = rust_version_symbol(); - let short_version = current_rustc_version.as_str().split('-').next().unwrap(); + let short_version = CURRENT_RUSTC_VERSION.split('-').next().unwrap(); RustcVersion::parse(short_version).unwrap_or_else(|err| { - panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{current_rustc_version}`, {err:?}") + panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{CURRENT_RUSTC_VERSION}`, {err:?}") }) }, Since::Err => return false, From 49ab99a127fdc4c32b0de1ed829b7b414fa93ce4 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 25 Oct 2023 10:49:24 +0000 Subject: [PATCH 0971/1222] Work around the fact that `check_mod_type_wf` may spuriously return `ErrorGuaranteed`, even if that error is only emitted by `check_modwitem_types` --- tests/ui/crashes/ice-6252.stderr | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index 30be9dde73c3..f929bec9583c 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -24,6 +24,16 @@ help: you might be missing a type parameter LL | impl TypeVal for Multiply where N: TypeVal {} | +++++ -error: aborting due to 2 previous errors +error[E0046]: not all trait items implemented, missing: `VAL` + --> $DIR/ice-6252.rs:11:1 + | +LL | const VAL: T; + | ------------ `VAL` from trait +... +LL | impl TypeVal for Multiply where N: TypeVal {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation + +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0412`. +Some errors have detailed explanations: E0046, E0412. +For more information about an error, try `rustc --explain E0046`. From 6b0e56291d3b957be9f2369280c269ee8c602709 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 23 Oct 2023 17:02:40 +0000 Subject: [PATCH 0972/1222] Rename `AsyncCoroutineKind` to `CoroutineSource` similar to how we have `MatchSource`, it explains where the desugaring came from. --- clippy_lints/src/async_yields_async.rs | 4 ++-- clippy_lints/src/await_holding_invalid.rs | 4 ++-- clippy_lints/src/manual_async_fn.rs | 4 ++-- clippy_lints/src/needless_question_mark.rs | 4 ++-- clippy_lints/src/redundant_async_block.rs | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/async_yields_async.rs b/clippy_lints/src/async_yields_async.rs index 56f56fff1e78..050df68a0fa1 100644 --- a/clippy_lints/src/async_yields_async.rs +++ b/clippy_lints/src/async_yields_async.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::source::snippet; use clippy_utils::ty::implements_trait; use rustc_errors::Applicability; -use rustc_hir::{AsyncCoroutineKind, Body, BodyId, CoroutineKind, ExprKind, QPath}; +use rustc_hir::{CoroutineSource, Body, BodyId, CoroutineKind, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -45,7 +45,7 @@ declare_lint_pass!(AsyncYieldsAsync => [ASYNC_YIELDS_ASYNC]); impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync { fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) { - use AsyncCoroutineKind::{Block, Closure}; + use CoroutineSource::{Block, Closure}; // For functions, with explicitly defined types, don't warn. // XXXkhuey maybe we should? if let Some(CoroutineKind::Async(Block | Closure)) = body.coroutine_kind { diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index ae8618dcaa06..0c356934992f 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::{match_def_path, paths}; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::DefId; -use rustc_hir::{AsyncCoroutineKind, Body, CoroutineKind}; +use rustc_hir::{CoroutineSource, Body, CoroutineKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::CoroutineLayout; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -195,7 +195,7 @@ impl LateLintPass<'_> for AwaitHolding { } fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { - use AsyncCoroutineKind::{Block, Closure, Fn}; + use CoroutineSource::{Block, Closure, Fn}; if let Some(CoroutineKind::Async(Block | Closure | Fn)) = body.coroutine_kind { let def_id = cx.tcx.hir().body_owner_def_id(body.id()); if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(def_id) { diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 5a87e75722d0..a75c76d6fe0d 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -4,7 +4,7 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{ - AsyncCoroutineKind, Block, Body, Closure, CoroutineKind, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, GenericBound, + CoroutineSource, Block, Body, Closure, CoroutineKind, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, GenericBound, ImplItem, Item, ItemKind, LifetimeName, Node, Term, TraitRef, Ty, TyKind, TypeBindingKind, }; use rustc_lint::{LateContext, LateLintPass}; @@ -188,7 +188,7 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) .. } = block_expr; let closure_body = cx.tcx.hir().body(body); - if closure_body.coroutine_kind == Some(CoroutineKind::Async(AsyncCoroutineKind::Block)); + if closure_body.coroutine_kind == Some(CoroutineKind::Async(CoroutineSource::Block)); then { return Some(closure_body); } diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index ed279a3813d7..b3a2060d6ac9 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{AsyncCoroutineKind, Block, Body, CoroutineKind, Expr, ExprKind, LangItem, MatchSource, QPath}; +use rustc_hir::{CoroutineSource, Block, Body, CoroutineKind, Expr, ExprKind, LangItem, MatchSource, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -87,7 +87,7 @@ impl LateLintPass<'_> for NeedlessQuestionMark { } fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { - if let Some(CoroutineKind::Async(AsyncCoroutineKind::Fn)) = body.coroutine_kind { + if let Some(CoroutineKind::Async(CoroutineSource::Fn)) = body.coroutine_kind { if let ExprKind::Block( Block { expr: diff --git a/clippy_lints/src/redundant_async_block.rs b/clippy_lints/src/redundant_async_block.rs index 2e895d5f2369..bf9bdacba5b9 100644 --- a/clippy_lints/src/redundant_async_block.rs +++ b/clippy_lints/src/redundant_async_block.rs @@ -5,7 +5,7 @@ use clippy_utils::peel_blocks; use clippy_utils::source::{snippet, walk_span_to_context}; use clippy_utils::visitors::for_each_expr; use rustc_errors::Applicability; -use rustc_hir::{AsyncCoroutineKind, Closure, CoroutineKind, Expr, ExprKind, MatchSource}; +use rustc_hir::{CoroutineSource, Closure, CoroutineKind, Expr, ExprKind, MatchSource}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::UpvarCapture; @@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantAsyncBlock { fn desugar_async_block<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { if let ExprKind::Closure(Closure { body, def_id, .. }) = expr.kind && let body = cx.tcx.hir().body(*body) && - matches!(body.coroutine_kind, Some(CoroutineKind::Async(AsyncCoroutineKind::Block))) + matches!(body.coroutine_kind, Some(CoroutineKind::Async(CoroutineSource::Block))) { cx .typeck_results() From e6428ff760891187c6702bbf8f3558386966957a Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Mon, 16 Oct 2023 22:11:57 +0200 Subject: [PATCH 0973/1222] Stop telling people to submit bugs for internal feature ICEs This keeps track of usage of internal features, and changes the message to instead tell them that using internal features is not supported. See MCP 620. --- src/driver.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index d47767faed9e..3876da150c55 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -178,7 +178,7 @@ pub fn main() { rustc_driver::init_rustc_env_logger(&handler); - rustc_driver::install_ice_hook(BUG_REPORT_URL, |handler| { + let using_internal_features = rustc_driver::install_ice_hook(BUG_REPORT_URL, |handler| { // FIXME: this macro calls unwrap internally but is called in a panicking context! It's not // as simple as moving the call from the hook to main, because `install_ice_hook` doesn't // accept a generic closure. @@ -265,9 +265,11 @@ pub fn main() { let clippy_enabled = !cap_lints_allow && (!no_deps || in_primary_package); if clippy_enabled { args.extend(clippy_args); - rustc_driver::RunCompiler::new(&args, &mut ClippyCallbacks { clippy_args_var }).run() + rustc_driver::RunCompiler::new(&args, &mut ClippyCallbacks { clippy_args_var }) + .set_using_internal_features(using_internal_features).run() } else { - rustc_driver::RunCompiler::new(&args, &mut RustcCallbacks { clippy_args_var }).run() + rustc_driver::RunCompiler::new(&args, &mut RustcCallbacks { clippy_args_var }) + .set_using_internal_features(using_internal_features).run() } })) } From ccea2e366484f37fb59ef0e2cb681e798ea3fc2c Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 26 Oct 2023 17:18:21 -0700 Subject: [PATCH 0974/1222] Parse rustc version at compile time --- clippy_utils/src/qualify_min_const_fn.rs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 1e465ac91b76..31f7b87de635 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -5,7 +5,7 @@ use crate::msrvs::Msrv; use hir::LangItem; -use rustc_attr::{Since, CURRENT_RUSTC_VERSION}; +use rustc_attr::Since; use rustc_const_eval::transform::check_consts::ConstCx; use rustc_hir as hir; use rustc_hir::def_id::DefId; @@ -372,23 +372,16 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool { // as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262. let const_stab_rust_version = match since { - Since::Version(version) => RustcVersion::new( - u32::from(version.major), - u32::from(version.minor), - u32::from(version.patch), - ), - Since::Current => { - // HACK(nilstrieb): CURRENT_RUSTC_VERSION can return versions like 1.66.0-dev. - // `rustc-semver` doesn't accept the `-dev` version number so we have to strip it off. - let short_version = CURRENT_RUSTC_VERSION.split('-').next().unwrap(); - RustcVersion::parse(short_version).unwrap_or_else(|err| { - panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{CURRENT_RUSTC_VERSION}`, {err:?}") - }) - }, + Since::Version(version) => version, + Since::Current => rustc_session::RustcVersion::CURRENT, Since::Err => return false, }; - msrv.meets(const_stab_rust_version) + msrv.meets(RustcVersion::new( + u32::from(const_stab_rust_version.major), + u32::from(const_stab_rust_version.minor), + u32::from(const_stab_rust_version.patch), + )) } else { // Unstable const fn with the feature enabled. msrv.current().is_none() From 7291f78cb8da63fdd62c24951547204070721914 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 20 Oct 2023 21:26:57 +0000 Subject: [PATCH 0975/1222] Add gen blocks to ast and do some broken ast lowering --- clippy_lints/src/suspicious_operation_groupings.rs | 2 +- clippy_utils/src/ast_utils.rs | 2 +- clippy_utils/src/sugg.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index d10f10ef87e8..7dff37a2b8ff 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -578,7 +578,7 @@ fn ident_difference_expr_with_base_location( | (Assign(_, _, _), Assign(_, _, _)) | (TryBlock(_), TryBlock(_)) | (Await(_, _), Await(_, _)) - | (Async(_, _), Async(_, _)) + | (Gen(_, _, _), Gen(_, _, _)) | (Block(_, _), Block(_, _)) | (Closure(_), Closure(_)) | (Match(_, _), Match(_, _)) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index a78ff02021f2..a2c61e07b70a 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -211,7 +211,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { && eq_fn_decl(lf, rf) && eq_expr(le, re) }, - (Async(lc, lb), Async(rc, rb)) => lc == rc && eq_block(lb, rb), + (Gen(lc, lb, lk), Gen(rc, rb, rk)) => lc == rc && eq_block(lb, rb) && lk == rk, (Range(lf, lt, ll), Range(rf, rt, rl)) => ll == rl && eq_expr_opt(lf, rf) && eq_expr_opt(lt, rt), (AddrOf(lbk, lm, le), AddrOf(rbk, rm, re)) => lbk == rbk && lm == rm && eq_expr(le, re), (Path(lq, lp), Path(rq, rp)) => both(lq, rq, eq_qself) && eq_path(lp, rp), diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index ae8ee371ffae..836f8cc19168 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -190,7 +190,7 @@ impl<'a> Sugg<'a> { (snip, false) => Sugg::MaybeParen(snip), (snip, true) => Sugg::NonParen(snip), }, - ast::ExprKind::Async(..) + ast::ExprKind::Gen(..) | ast::ExprKind::Block(..) | ast::ExprKind::Break(..) | ast::ExprKind::Call(..) From d1073a8e3ad94e2e30d3a0bdc60fdbe71927ef46 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 26 Oct 2023 10:08:39 -0700 Subject: [PATCH 0976/1222] Rename Since -> StableSince in preparation for a DeprecatedSince --- clippy_utils/src/qualify_min_const_fn.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 31f7b87de635..ef0e2d3e1b3d 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -5,7 +5,7 @@ use crate::msrvs::Msrv; use hir::LangItem; -use rustc_attr::Since; +use rustc_attr::StableSince; use rustc_const_eval::transform::check_consts::ConstCx; use rustc_hir as hir; use rustc_hir::def_id::DefId; @@ -372,9 +372,9 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool { // as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262. let const_stab_rust_version = match since { - Since::Version(version) => version, - Since::Current => rustc_session::RustcVersion::CURRENT, - Since::Err => return false, + StableSince::Version(version) => version, + StableSince::Current => rustc_session::RustcVersion::CURRENT, + StableSince::Err => return false, }; msrv.meets(RustcVersion::new( From 4a7166cde311107d2c52278a2a8d55c0520481df Mon Sep 17 00:00:00 2001 From: John Millikin Date: Wed, 1 Nov 2023 09:16:34 +0900 Subject: [PATCH 0977/1222] Stabilize C string literals --- tests/ui/needless_raw_string.fixed | 1 - tests/ui/needless_raw_string.rs | 1 - tests/ui/needless_raw_string.stderr | 14 +++++----- tests/ui/needless_raw_string_hashes.fixed | 1 - tests/ui/needless_raw_string_hashes.rs | 1 - tests/ui/needless_raw_string_hashes.stderr | 30 +++++++++++----------- 6 files changed, 22 insertions(+), 26 deletions(-) diff --git a/tests/ui/needless_raw_string.fixed b/tests/ui/needless_raw_string.fixed index 4ea711fd67a1..1a9c601c462b 100644 --- a/tests/ui/needless_raw_string.fixed +++ b/tests/ui/needless_raw_string.fixed @@ -1,6 +1,5 @@ #![allow(clippy::needless_raw_string_hashes, clippy::no_effect, unused)] #![warn(clippy::needless_raw_strings)] -#![feature(c_str_literals)] fn main() { "aaa"; diff --git a/tests/ui/needless_raw_string.rs b/tests/ui/needless_raw_string.rs index b6239f9b1f03..1126ea5aa303 100644 --- a/tests/ui/needless_raw_string.rs +++ b/tests/ui/needless_raw_string.rs @@ -1,6 +1,5 @@ #![allow(clippy::needless_raw_string_hashes, clippy::no_effect, unused)] #![warn(clippy::needless_raw_strings)] -#![feature(c_str_literals)] fn main() { r#"aaa"#; diff --git a/tests/ui/needless_raw_string.stderr b/tests/ui/needless_raw_string.stderr index 276bc84c6c37..b2188698564f 100644 --- a/tests/ui/needless_raw_string.stderr +++ b/tests/ui/needless_raw_string.stderr @@ -1,5 +1,5 @@ error: unnecessary raw string literal - --> $DIR/needless_raw_string.rs:6:5 + --> $DIR/needless_raw_string.rs:5:5 | LL | r#"aaa"#; | ^^^^^^^^ @@ -13,7 +13,7 @@ LL + "aaa"; | error: unnecessary raw string literal - --> $DIR/needless_raw_string.rs:9:5 + --> $DIR/needless_raw_string.rs:8:5 | LL | br#"aaa"#; | ^^^^^^^^^ @@ -25,7 +25,7 @@ LL + b"aaa"; | error: unnecessary raw string literal - --> $DIR/needless_raw_string.rs:12:5 + --> $DIR/needless_raw_string.rs:11:5 | LL | cr#"aaa"#; | ^^^^^^^^^ @@ -37,7 +37,7 @@ LL + c"aaa"; | error: unnecessary raw string literal - --> $DIR/needless_raw_string.rs:16:5 + --> $DIR/needless_raw_string.rs:15:5 | LL | / r#" LL | | a @@ -56,7 +56,7 @@ LL ~ "; | error: unnecessary raw string literal - --> $DIR/needless_raw_string.rs:22:5 + --> $DIR/needless_raw_string.rs:21:5 | LL | r"no hashes"; | ^^^^^^^^^^^^ @@ -68,7 +68,7 @@ LL + "no hashes"; | error: unnecessary raw string literal - --> $DIR/needless_raw_string.rs:23:5 + --> $DIR/needless_raw_string.rs:22:5 | LL | br"no hashes"; | ^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL + b"no hashes"; | error: unnecessary raw string literal - --> $DIR/needless_raw_string.rs:24:5 + --> $DIR/needless_raw_string.rs:23:5 | LL | cr"no hashes"; | ^^^^^^^^^^^^^ diff --git a/tests/ui/needless_raw_string_hashes.fixed b/tests/ui/needless_raw_string_hashes.fixed index c99c2f46532a..b2ad657d6b29 100644 --- a/tests/ui/needless_raw_string_hashes.fixed +++ b/tests/ui/needless_raw_string_hashes.fixed @@ -1,6 +1,5 @@ #![allow(clippy::no_effect, unused)] #![warn(clippy::needless_raw_string_hashes)] -#![feature(c_str_literals)] fn main() { r"\aaa"; diff --git a/tests/ui/needless_raw_string_hashes.rs b/tests/ui/needless_raw_string_hashes.rs index dcc2af69f4e9..54d8ed76d475 100644 --- a/tests/ui/needless_raw_string_hashes.rs +++ b/tests/ui/needless_raw_string_hashes.rs @@ -1,6 +1,5 @@ #![allow(clippy::no_effect, unused)] #![warn(clippy::needless_raw_string_hashes)] -#![feature(c_str_literals)] fn main() { r#"\aaa"#; diff --git a/tests/ui/needless_raw_string_hashes.stderr b/tests/ui/needless_raw_string_hashes.stderr index 017160b1a421..c74eff8161e9 100644 --- a/tests/ui/needless_raw_string_hashes.stderr +++ b/tests/ui/needless_raw_string_hashes.stderr @@ -1,5 +1,5 @@ error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:6:5 + --> $DIR/needless_raw_string_hashes.rs:5:5 | LL | r#"\aaa"#; | ^^^^^^^^^ @@ -13,7 +13,7 @@ LL + r"\aaa"; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:7:5 + --> $DIR/needless_raw_string_hashes.rs:6:5 | LL | r##"Hello "world"!"##; | ^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + r#"Hello "world"!"#; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:8:5 + --> $DIR/needless_raw_string_hashes.rs:7:5 | LL | r######" "### "## "# "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + r####" "### "## "# "####; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:9:5 + --> $DIR/needless_raw_string_hashes.rs:8:5 | LL | r######" "aa" "# "## "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + r###" "aa" "# "## "###; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:10:5 + --> $DIR/needless_raw_string_hashes.rs:9:5 | LL | br#"\aaa"#; | ^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + br"\aaa"; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:11:5 + --> $DIR/needless_raw_string_hashes.rs:10:5 | LL | br##"Hello "world"!"##; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + br#"Hello "world"!"#; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:12:5 + --> $DIR/needless_raw_string_hashes.rs:11:5 | LL | br######" "### "## "# "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + br####" "### "## "# "####; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:13:5 + --> $DIR/needless_raw_string_hashes.rs:12:5 | LL | br######" "aa" "# "## "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + br###" "aa" "# "## "###; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:14:5 + --> $DIR/needless_raw_string_hashes.rs:13:5 | LL | cr#"\aaa"#; | ^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + cr"\aaa"; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:15:5 + --> $DIR/needless_raw_string_hashes.rs:14:5 | LL | cr##"Hello "world"!"##; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + cr#"Hello "world"!"#; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:16:5 + --> $DIR/needless_raw_string_hashes.rs:15:5 | LL | cr######" "### "## "# "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + cr####" "### "## "# "####; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:17:5 + --> $DIR/needless_raw_string_hashes.rs:16:5 | LL | cr######" "aa" "# "## "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + cr###" "aa" "# "## "###; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:19:5 + --> $DIR/needless_raw_string_hashes.rs:18:5 | LL | / r#" LL | | \a @@ -164,7 +164,7 @@ LL ~ "; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:25:5 + --> $DIR/needless_raw_string_hashes.rs:24:5 | LL | r###"rust"###; | ^^^^^^^^^^^^^ @@ -176,7 +176,7 @@ LL + r"rust"; | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:26:5 + --> $DIR/needless_raw_string_hashes.rs:25:5 | LL | r#"hello world"#; | ^^^^^^^^^^^^^^^^ From d7580f16cde4932bdfdd4bafa4b3e79aca06bf4c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 31 Oct 2023 17:38:41 +0000 Subject: [PATCH 0978/1222] Rename hook. --- clippy_utils/src/consts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 79c04c7c7f4a..50a73745acb8 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -710,7 +710,7 @@ fn field_of_struct<'tcx>( field: &Ident, ) -> Option> { if let mir::Const::Val(result, ty) = result - && let Some(dc) = lcx.tcx.try_destructure_mir_constant_for_diagnostics(result, ty) + && let Some(dc) = lcx.tcx.try_destructure_mir_constant_for_user_output(result, ty) && let Some(dc_variant) = dc.variant && let Some(variant) = adt_def.variants().get(dc_variant) && let Some(field_idx) = variant.fields.iter().position(|el| el.name == field.name) From e30639b6fab193561885a9dc8077a041d0c56b6a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 2 Nov 2023 14:10:12 +1100 Subject: [PATCH 0979/1222] Minimize `pub` usage in `source_map.rs`. Most notably, this commit changes the `pub use crate::*;` in that file to `use crate::*;`. This requires a lot of `use` items in other crates to be adjusted, because everything defined within `rustc_span::*` was also available via `rustc_span::source_map::*`, which is bizarre. The commit also removes `SourceMap::span_to_relative_line_string`, which is unused. --- clippy_lints/src/attrs.rs | 3 +-- clippy_lints/src/booleans.rs | 3 +-- clippy_lints/src/cargo/common_metadata.rs | 2 +- clippy_lints/src/cargo/feature_name.rs | 2 +- clippy_lints/src/cargo/multiple_crate_versions.rs | 2 +- clippy_lints/src/cargo/wildcard_dependencies.rs | 2 +- clippy_lints/src/cognitive_complexity.rs | 3 +-- clippy_lints/src/derive.rs | 3 +-- clippy_lints/src/doc.rs | 4 ++-- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/formatting.rs | 2 +- clippy_lints/src/implicit_hasher.rs | 2 +- clippy_lints/src/item_name_repetitions.rs | 2 +- clippy_lints/src/large_enum_variant.rs | 2 +- clippy_lints/src/len_zero.rs | 3 ++- clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/loops/manual_find.rs | 2 +- clippy_lints/src/loops/manual_flatten.rs | 2 +- clippy_lints/src/loops/mod.rs | 2 +- clippy_lints/src/loops/mut_range_bound.rs | 2 +- clippy_lints/src/map_unit_fn.rs | 3 +-- clippy_lints/src/mem_replace.rs | 2 +- clippy_lints/src/methods/expect_fun_call.rs | 2 +- clippy_lints/src/methods/filetype_is_file.rs | 3 +-- clippy_lints/src/methods/filter_map.rs | 2 +- clippy_lints/src/methods/filter_map_identity.rs | 3 +-- clippy_lints/src/methods/flat_map_identity.rs | 3 +-- clippy_lints/src/methods/flat_map_option.rs | 3 +-- clippy_lints/src/methods/inspect_for_each.rs | 3 +-- clippy_lints/src/methods/into_iter_on_ref.rs | 2 +- clippy_lints/src/methods/map_identity.rs | 3 +-- clippy_lints/src/methods/open_options.rs | 4 ++-- clippy_lints/src/methods/option_map_unwrap_or.rs | 3 +-- clippy_lints/src/methods/or_fun_call.rs | 2 +- clippy_lints/src/methods/search_is_some.rs | 2 +- clippy_lints/src/methods/unnecessary_fold.rs | 3 +-- clippy_lints/src/methods/wrong_self_convention.rs | 2 +- clippy_lints/src/misc.rs | 2 +- clippy_lints/src/misc_early/mod.rs | 2 +- clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs | 2 +- clippy_lints/src/missing_doc.rs | 3 +-- clippy_lints/src/missing_inline.rs | 3 +-- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/needless_for_each.rs | 3 +-- clippy_lints/src/neg_multiply.rs | 2 +- clippy_lints/src/non_expressive_names.rs | 3 +-- clippy_lints/src/operators/arithmetic_side_effects.rs | 4 ++-- clippy_lints/src/operators/bit_mask.rs | 2 +- clippy_lints/src/operators/const_comparisons.rs | 3 ++- clippy_lints/src/operators/double_comparison.rs | 2 +- clippy_lints/src/operators/identity_op.rs | 2 +- clippy_lints/src/operators/numeric_arithmetic.rs | 2 +- clippy_lints/src/pattern_type_mismatch.rs | 2 +- clippy_lints/src/ptr.rs | 3 +-- clippy_lints/src/ranges.rs | 3 ++- clippy_lints/src/redundant_clone.rs | 3 +-- clippy_lints/src/regex.rs | 2 +- clippy_lints/src/returns.rs | 3 +-- clippy_lints/src/tabs_in_doc_comments.rs | 2 +- clippy_lints/src/types/mod.rs | 2 +- clippy_lints/src/types/utils.rs | 2 +- clippy_lints/src/unicode.rs | 2 +- clippy_lints/src/unsafe_removed_from_name.rs | 2 +- clippy_lints/src/unused_unit.rs | 3 +-- clippy_lints/src/unwrap.rs | 3 +-- clippy_lints/src/vec.rs | 3 +-- clippy_utils/src/diagnostics.rs | 2 +- clippy_utils/src/sugg.rs | 2 +- 68 files changed, 74 insertions(+), 94 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index db01ddbde04e..d6b9d0eb5824 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -19,9 +19,8 @@ use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, use rustc_middle::lint::in_external_macro; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; use rustc_span::symbol::Symbol; -use rustc_span::{sym, DUMMY_SP}; +use rustc_span::{sym, DUMMY_SP, Span}; use semver::Version; static UNIX_SYSTEMS: &[&str] = &[ diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 04cca9e3177c..172e42fd692f 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -10,8 +10,7 @@ use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, UnOp}; use rustc_lint::{LateContext, LateLintPass, Level}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/cargo/common_metadata.rs b/clippy_lints/src/cargo/common_metadata.rs index 805121bcced3..99fe6c1e790e 100644 --- a/clippy_lints/src/cargo/common_metadata.rs +++ b/clippy_lints/src/cargo/common_metadata.rs @@ -3,7 +3,7 @@ use cargo_metadata::Metadata; use clippy_utils::diagnostics::span_lint; use rustc_lint::LateContext; -use rustc_span::source_map::DUMMY_SP; +use rustc_span::DUMMY_SP; use super::CARGO_COMMON_METADATA; diff --git a/clippy_lints/src/cargo/feature_name.rs b/clippy_lints/src/cargo/feature_name.rs index 37c169dbd95e..9e69919c7273 100644 --- a/clippy_lints/src/cargo/feature_name.rs +++ b/clippy_lints/src/cargo/feature_name.rs @@ -1,7 +1,7 @@ use cargo_metadata::Metadata; use clippy_utils::diagnostics::span_lint_and_help; use rustc_lint::LateContext; -use rustc_span::source_map::DUMMY_SP; +use rustc_span::DUMMY_SP; use super::{NEGATIVE_FEATURE_NAMES, REDUNDANT_FEATURE_NAMES}; diff --git a/clippy_lints/src/cargo/multiple_crate_versions.rs b/clippy_lints/src/cargo/multiple_crate_versions.rs index f9b17d45e9fb..f7a5b1857be2 100644 --- a/clippy_lints/src/cargo/multiple_crate_versions.rs +++ b/clippy_lints/src/cargo/multiple_crate_versions.rs @@ -6,7 +6,7 @@ use if_chain::if_chain; use itertools::Itertools; use rustc_hir::def_id::LOCAL_CRATE; use rustc_lint::LateContext; -use rustc_span::source_map::DUMMY_SP; +use rustc_span::DUMMY_SP; use super::MULTIPLE_CRATE_VERSIONS; diff --git a/clippy_lints/src/cargo/wildcard_dependencies.rs b/clippy_lints/src/cargo/wildcard_dependencies.rs index 7fa6acbf557b..4dcc9cbe3a75 100644 --- a/clippy_lints/src/cargo/wildcard_dependencies.rs +++ b/clippy_lints/src/cargo/wildcard_dependencies.rs @@ -2,7 +2,7 @@ use cargo_metadata::Metadata; use clippy_utils::diagnostics::span_lint; use if_chain::if_chain; use rustc_lint::LateContext; -use rustc_span::source_map::DUMMY_SP; +use rustc_span::DUMMY_SP; use super::WILDCARD_DEPENDENCIES; diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index a8926b29ac83..74ecaa60c7ca 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -12,8 +12,7 @@ use rustc_hir::{Body, Expr, ExprKind, FnDecl}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::def_id::LocalDefId; -use rustc_span::source_map::Span; -use rustc_span::{sym, BytePos}; +use rustc_span::{sym, BytePos, Span}; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 2bdac1352dce..fb9302eef28a 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -17,8 +17,7 @@ use rustc_middle::ty::{ }; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index fc9b381664a3..b3bcca4645ad 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -30,8 +30,8 @@ use rustc_resolve::rustdoc::{ use rustc_session::parse::ParseSess; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::edition::Edition; -use rustc_span::source_map::{BytePos, FilePathMapping, SourceMap, Span}; -use rustc_span::{sym, FileName, Pos}; +use rustc_span::{sym, BytePos, FileName, Pos, Span}; +use rustc_span::source_map::{FilePathMapping, SourceMap}; use std::ops::Range; use std::{io, thread}; use url::Url; diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index dbe3453e7bfa..87f516d8e0ec 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -8,7 +8,7 @@ use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, TraitRef, Ty}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::def_id::LocalDefId; -use rustc_span::source_map::Span; +use rustc_span::Span; use rustc_span::symbol::kw; use rustc_target::spec::abi::Abi; diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index 4ebf0e9667df..136a8a90f4a0 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -6,7 +6,7 @@ use rustc_ast::ast::{BinOpKind, Block, Expr, ExprKind, StmtKind, UnOp}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; +use rustc_span::Span; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 2b2ea156cd4d..230c68f5bf51 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -10,7 +10,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{Ty, TypeckResults}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; +use rustc_span::Span; use rustc_span::symbol::sym; use if_chain::if_chain; diff --git a/clippy_lints/src/item_name_repetitions.rs b/clippy_lints/src/item_name_repetitions.rs index 8b4984da3dd1..602774cdfbd1 100644 --- a/clippy_lints/src/item_name_repetitions.rs +++ b/clippy_lints/src/item_name_repetitions.rs @@ -7,7 +7,7 @@ use clippy_utils::str_utils::{camel_case_split, count_match_end, count_match_sta use rustc_hir::{EnumDef, FieldDef, Item, ItemKind, OwnerId, Variant, VariantData}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; +use rustc_span::Span; use rustc_span::symbol::Symbol; declare_clippy_lint! { diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index b22b57a3006f..080062646f70 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -9,7 +9,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::{Adt, Ty}; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; +use rustc_span::Span; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index c06b35ca0dab..65eb8846bdfd 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -15,7 +15,8 @@ use rustc_hir::{ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, AssocKind, FnSig, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::{Span, Spanned, Symbol}; +use rustc_span::{Span, Symbol}; +use rustc_span::source_map::Spanned; use rustc_span::symbol::sym; declare_clippy_lint! { diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 0004a150d51b..d5db769b7e3a 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -20,7 +20,7 @@ use rustc_middle::hir::nested_filter as middle_nested_filter; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; -use rustc_span::source_map::Span; +use rustc_span::Span; use rustc_span::symbol::{kw, Ident, Symbol}; declare_clippy_lint! { diff --git a/clippy_lints/src/loops/manual_find.rs b/clippy_lints/src/loops/manual_find.rs index 0aaa66e6bcee..a9a9058c93f3 100644 --- a/clippy_lints/src/loops/manual_find.rs +++ b/clippy_lints/src/loops/manual_find.rs @@ -10,7 +10,7 @@ use rustc_hir::def::Res; use rustc_hir::lang_items::LangItem; use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Node, Pat, PatKind, Stmt, StmtKind}; use rustc_lint::LateContext; -use rustc_span::source_map::Span; +use rustc_span::Span; pub(super) fn check<'tcx>( cx: &LateContext<'tcx>, diff --git a/clippy_lints/src/loops/manual_flatten.rs b/clippy_lints/src/loops/manual_flatten.rs index 559a2c03f146..124a35f8f540 100644 --- a/clippy_lints/src/loops/manual_flatten.rs +++ b/clippy_lints/src/loops/manual_flatten.rs @@ -9,7 +9,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::{Expr, Pat, PatKind}; use rustc_lint::LateContext; use rustc_middle::ty; -use rustc_span::source_map::Span; +use rustc_span::Span; /// Check for unnecessary `if let` usage in a for loop where only the `Some` or `Ok` variant of the /// iterator element is used. diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index 1fb16adad7a1..cd7f3e0c6bfb 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -24,7 +24,7 @@ use clippy_utils::msrvs::Msrv; use rustc_hir::{Expr, ExprKind, LoopSource, Pat}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; +use rustc_span::Span; use utils::{make_iterator_snippet, IncrementVisitor, InitializeVisitor}; declare_clippy_lint! { diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index b83d148b5f24..2c12d9582d63 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -9,7 +9,7 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty; -use rustc_span::source_map::Span; +use rustc_span::Span; pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>, body: &Expr<'_>) { if_chain! { diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index f0a0f482af29..18595d4a4695 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -8,8 +8,7 @@ use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 8a921d4af165..a3170fec647f 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -11,7 +11,7 @@ use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; +use rustc_span::Span; use rustc_span::symbol::sym; declare_clippy_lint! { diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index 40e487bf6505..a49970b5351d 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -6,7 +6,7 @@ use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_middle::ty; -use rustc_span::source_map::Span; +use rustc_span::Span; use rustc_span::symbol::sym; use std::borrow::Cow; diff --git a/clippy_lints/src/methods/filetype_is_file.rs b/clippy_lints/src/methods/filetype_is_file.rs index 3fef53739fbd..7818be81119b 100644 --- a/clippy_lints/src/methods/filetype_is_file.rs +++ b/clippy_lints/src/methods/filetype_is_file.rs @@ -4,8 +4,7 @@ use clippy_utils::ty::is_type_diagnostic_item; use if_chain::if_chain; use rustc_hir as hir; use rustc_lint::LateContext; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; use super::FILETYPE_IS_FILE; diff --git a/clippy_lints/src/methods/filter_map.rs b/clippy_lints/src/methods/filter_map.rs index c9eaa185acce..597e0da238ed 100644 --- a/clippy_lints/src/methods/filter_map.rs +++ b/clippy_lints/src/methods/filter_map.rs @@ -11,7 +11,7 @@ use rustc_hir::def::Res; use rustc_hir::{Closure, Expr, ExprKind, PatKind, PathSegment, QPath, UnOp}; use rustc_lint::LateContext; use rustc_middle::ty::adjustment::Adjust; -use rustc_span::source_map::Span; +use rustc_span::Span; use rustc_span::symbol::{sym, Ident, Symbol}; use std::borrow::Cow; diff --git a/clippy_lints/src/methods/filter_map_identity.rs b/clippy_lints/src/methods/filter_map_identity.rs index 20878f1e4dfe..8291c373f371 100644 --- a/clippy_lints/src/methods/filter_map_identity.rs +++ b/clippy_lints/src/methods/filter_map_identity.rs @@ -3,8 +3,7 @@ use clippy_utils::{is_expr_untyped_identity_function, is_trait_method}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; use super::FILTER_MAP_IDENTITY; diff --git a/clippy_lints/src/methods/flat_map_identity.rs b/clippy_lints/src/methods/flat_map_identity.rs index 8849a4f49420..651ea34f9d0e 100644 --- a/clippy_lints/src/methods/flat_map_identity.rs +++ b/clippy_lints/src/methods/flat_map_identity.rs @@ -3,8 +3,7 @@ use clippy_utils::{is_expr_untyped_identity_function, is_trait_method}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; use super::FLAT_MAP_IDENTITY; diff --git a/clippy_lints/src/methods/flat_map_option.rs b/clippy_lints/src/methods/flat_map_option.rs index 172c397fbc80..0a4a381b8618 100644 --- a/clippy_lints/src/methods/flat_map_option.rs +++ b/clippy_lints/src/methods/flat_map_option.rs @@ -4,8 +4,7 @@ use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_middle::ty; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; use super::FLAT_MAP_OPTION; use clippy_utils::ty::is_type_diagnostic_item; diff --git a/clippy_lints/src/methods/inspect_for_each.rs b/clippy_lints/src/methods/inspect_for_each.rs index 23cc192c38e3..ad4b6fa130e3 100644 --- a/clippy_lints/src/methods/inspect_for_each.rs +++ b/clippy_lints/src/methods/inspect_for_each.rs @@ -2,8 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::is_trait_method; use rustc_hir as hir; use rustc_lint::LateContext; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; use super::INSPECT_FOR_EACH; diff --git a/clippy_lints/src/methods/into_iter_on_ref.rs b/clippy_lints/src/methods/into_iter_on_ref.rs index 8adf9e370592..bbd964c10995 100644 --- a/clippy_lints/src/methods/into_iter_on_ref.rs +++ b/clippy_lints/src/methods/into_iter_on_ref.rs @@ -6,7 +6,7 @@ use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_middle::ty::{self, Ty}; -use rustc_span::source_map::Span; +use rustc_span::Span; use rustc_span::symbol::{sym, Symbol}; use super::INTO_ITER_ON_REF; diff --git a/clippy_lints/src/methods/map_identity.rs b/clippy_lints/src/methods/map_identity.rs index 57581363cfa0..bcfd0de8efe1 100644 --- a/clippy_lints/src/methods/map_identity.rs +++ b/clippy_lints/src/methods/map_identity.rs @@ -4,8 +4,7 @@ use clippy_utils::{is_expr_untyped_identity_function, is_trait_method}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; use super::MAP_IDENTITY; diff --git a/clippy_lints/src/methods/open_options.rs b/clippy_lints/src/methods/open_options.rs index c0f5a2799451..65c986dcacce 100644 --- a/clippy_lints/src/methods/open_options.rs +++ b/clippy_lints/src/methods/open_options.rs @@ -3,8 +3,8 @@ use clippy_utils::ty::is_type_diagnostic_item; use rustc_ast::ast::LitKind; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; -use rustc_span::source_map::{Span, Spanned}; -use rustc_span::sym; +use rustc_span::source_map::Spanned; +use rustc_span::{sym, Span}; use super::NONSENSICAL_OPEN_OPTIONS; diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index fcbe005fb286..605a89cd7085 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -9,8 +9,7 @@ use rustc_hir::intravisit::{walk_path, Visitor}; use rustc_hir::{self, ExprKind, HirId, Node, PatKind, Path, QPath}; use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; use super::MAP_UNWRAP_OR; diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index 942f3bd79a61..94527d67ac1c 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -7,7 +7,7 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_lint::LateContext; use rustc_middle::ty; -use rustc_span::source_map::Span; +use rustc_span::Span; use rustc_span::symbol::{self, sym, Symbol}; use {rustc_ast as ast, rustc_hir as hir}; diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs index 04ddaaa2f461..05a9a06c8c7d 100644 --- a/clippy_lints/src/methods/search_is_some.rs +++ b/clippy_lints/src/methods/search_is_some.rs @@ -8,7 +8,7 @@ use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::PatKind; use rustc_lint::LateContext; -use rustc_span::source_map::Span; +use rustc_span::Span; use rustc_span::symbol::sym; use super::SEARCH_IS_SOME; diff --git a/clippy_lints/src/methods/unnecessary_fold.rs b/clippy_lints/src/methods/unnecessary_fold.rs index 6e23754bf46e..6d51c4ab0544 100644 --- a/clippy_lints/src/methods/unnecessary_fold.rs +++ b/clippy_lints/src/methods/unnecessary_fold.rs @@ -8,8 +8,7 @@ use rustc_hir as hir; use rustc_hir::PatKind; use rustc_lint::LateContext; use rustc_middle::ty; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; use super::UNNECESSARY_FOLD; diff --git a/clippy_lints/src/methods/wrong_self_convention.rs b/clippy_lints/src/methods/wrong_self_convention.rs index 1fbf783b8860..0a810a13f3f9 100644 --- a/clippy_lints/src/methods/wrong_self_convention.rs +++ b/clippy_lints/src/methods/wrong_self_convention.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::is_copy; use rustc_lint::LateContext; use rustc_middle::ty::Ty; -use rustc_span::source_map::Span; +use rustc_span::Span; use std::fmt; use super::WRONG_SELF_CONVENTION; diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 9c8b47fb3032..b4e343741b43 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -16,7 +16,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; -use rustc_span::source_map::Span; +use rustc_span::Span; use crate::ref_patterns::REF_PATTERNS; diff --git a/clippy_lints/src/misc_early/mod.rs b/clippy_lints/src/misc_early/mod.rs index b226b8781237..89bf4484426e 100644 --- a/clippy_lints/src/misc_early/mod.rs +++ b/clippy_lints/src/misc_early/mod.rs @@ -17,7 +17,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; +use rustc_span::Span; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs b/clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs index 7c4ae746e90e..00f46629f102 100644 --- a/clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs +++ b/clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use rustc_ast::ast::{Pat, PatKind}; use rustc_errors::Applicability; use rustc_lint::EarlyContext; -use rustc_span::source_map::Span; +use rustc_span::Span; use super::UNNEEDED_WILDCARD_PATTERN; diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 0629dee4f722..973caa72b772 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -16,8 +16,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::ty::Visibility; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::def_id::CRATE_DEF_ID; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 93f6025c71d6..12114dc4cee0 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -3,8 +3,7 @@ use rustc_ast::ast; use rustc_hir as hir; use rustc_lint::{self, LateContext, LateLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 5878f899541a..4a19e2facfde 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -8,7 +8,7 @@ use rustc_middle::query::Key; use rustc_middle::ty::{Adt, Ty}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::def_id::LocalDefId; -use rustc_span::source_map::Span; +use rustc_span::Span; use rustc_span::symbol::sym; use std::iter; diff --git a/clippy_lints/src/needless_for_each.rs b/clippy_lints/src/needless_for_each.rs index 98bf122fab74..579b4a920b7d 100644 --- a/clippy_lints/src/needless_for_each.rs +++ b/clippy_lints/src/needless_for_each.rs @@ -3,8 +3,7 @@ use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{Closure, Expr, ExprKind, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::{sym, Symbol}; +use rustc_span::{sym, Span, Symbol}; use if_chain::if_chain; diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index db0e22842d14..8b69f94cbba2 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -8,7 +8,7 @@ use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; +use rustc_span::Span; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index d562047cbf15..1029de91bc8b 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -6,8 +6,7 @@ use rustc_ast::visit::{walk_block, walk_expr, walk_pat, Visitor}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; use rustc_span::symbol::{Ident, Symbol}; use std::cmp::Ordering; diff --git a/clippy_lints/src/operators/arithmetic_side_effects.rs b/clippy_lints/src/operators/arithmetic_side_effects.rs index a10aa65e5948..9a5c57402db9 100644 --- a/clippy_lints/src/operators/arithmetic_side_effects.rs +++ b/clippy_lints/src/operators/arithmetic_side_effects.rs @@ -7,9 +7,9 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::Ty; use rustc_session::impl_lint_pass; -use rustc_span::source_map::{Span, Spanned}; +use rustc_span::{Span, Symbol}; +use rustc_span::source_map::Spanned; use rustc_span::symbol::sym; -use rustc_span::Symbol; use {rustc_ast as ast, rustc_hir as hir}; const HARD_CODED_ALLOWED_BINARY: &[[&str; 2]] = &[["f32", "f32"], ["f64", "f64"], ["std::string::String", "str"]]; diff --git a/clippy_lints/src/operators/bit_mask.rs b/clippy_lints/src/operators/bit_mask.rs index c146f3ae95b3..2e026c369ee3 100644 --- a/clippy_lints/src/operators/bit_mask.rs +++ b/clippy_lints/src/operators/bit_mask.rs @@ -2,7 +2,7 @@ use clippy_utils::consts::{constant, Constant}; use clippy_utils::diagnostics::span_lint; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; -use rustc_span::source_map::Span; +use rustc_span::Span; use super::{BAD_BIT_MASK, INEFFECTIVE_BIT_MASK}; diff --git a/clippy_lints/src/operators/const_comparisons.rs b/clippy_lints/src/operators/const_comparisons.rs index abe8df195434..ec2bb869973f 100644 --- a/clippy_lints/src/operators/const_comparisons.rs +++ b/clippy_lints/src/operators/const_comparisons.rs @@ -8,7 +8,8 @@ use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty::layout::HasTyCtxt; use rustc_middle::ty::{Ty, TypeckResults}; -use rustc_span::source_map::{Span, Spanned}; +use rustc_span::Span; +use rustc_span::source_map::Spanned; use clippy_utils::diagnostics::span_lint_and_note; use clippy_utils::source::snippet; diff --git a/clippy_lints/src/operators/double_comparison.rs b/clippy_lints/src/operators/double_comparison.rs index 56a86d0ffa21..d48e8286f2ca 100644 --- a/clippy_lints/src/operators/double_comparison.rs +++ b/clippy_lints/src/operators/double_comparison.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; -use rustc_span::source_map::Span; +use rustc_span::Span; use super::DOUBLE_COMPARISONS; diff --git a/clippy_lints/src/operators/identity_op.rs b/clippy_lints/src/operators/identity_op.rs index 14a12da862ef..8ecb038627f5 100644 --- a/clippy_lints/src/operators/identity_op.rs +++ b/clippy_lints/src/operators/identity_op.rs @@ -6,7 +6,7 @@ use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, Node}; use rustc_lint::LateContext; use rustc_middle::ty; -use rustc_span::source_map::Span; +use rustc_span::Span; use super::IDENTITY_OP; diff --git a/clippy_lints/src/operators/numeric_arithmetic.rs b/clippy_lints/src/operators/numeric_arithmetic.rs index 80389cbf84be..ea933168cfd5 100644 --- a/clippy_lints/src/operators/numeric_arithmetic.rs +++ b/clippy_lints/src/operators/numeric_arithmetic.rs @@ -3,7 +3,7 @@ use clippy_utils::consts::constant_simple; use clippy_utils::diagnostics::span_lint; use rustc_hir as hir; use rustc_lint::LateContext; -use rustc_span::source_map::Span; +use rustc_span::Span; #[derive(Default)] pub struct Context { diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index 9f98195d311f..dcd1e7af0c2c 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -5,7 +5,7 @@ use rustc_middle::lint::in_external_macro; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; -use rustc_span::source_map::Span; +use rustc_span::Span; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 310051efc508..7d42cb677e92 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -21,8 +21,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, Binder, ClauseKind, ExistentialPredicate, List, PredicateKind, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; use rustc_span::symbol::Symbol; use rustc_target::spec::abi::Abi; use rustc_trait_selection::infer::InferCtxtExt as _; diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 3287675a82de..bd368465b075 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -11,7 +11,8 @@ use rustc_hir::{BinOpKind, Expr, ExprKind, HirId}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::{Span, Spanned}; +use rustc_span::Span; +use rustc_span::source_map::Spanned; use std::cmp::Ordering; declare_clippy_lint! { diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 2c0086b09813..7a686e35d40c 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -12,8 +12,7 @@ use rustc_middle::mir; use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; -use rustc_span::source_map::{BytePos, Span}; -use rustc_span::sym; +use rustc_span::{sym, BytePos, Span}; macro_rules! unwrap_or_continue { ($x:expr) => { diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index b795e4b15bac..cb78eec9e8d7 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -9,7 +9,7 @@ use rustc_hir::def_id::DefIdMap; use rustc_hir::{BorrowKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::{BytePos, Span}; +use rustc_span::{BytePos, Span}; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index d6b9a49d2fe0..c84f42343388 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -14,8 +14,7 @@ use rustc_middle::lint::in_external_macro; use rustc_middle::ty::{self, GenericArgKind, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; -use rustc_span::source_map::Span; -use rustc_span::{BytePos, Pos}; +use rustc_span::{BytePos, Pos, Span}; use std::borrow::Cow; declare_clippy_lint! { diff --git a/clippy_lints/src/tabs_in_doc_comments.rs b/clippy_lints/src/tabs_in_doc_comments.rs index e223aea297fc..97095e48ddf1 100644 --- a/clippy_lints/src/tabs_in_doc_comments.rs +++ b/clippy_lints/src/tabs_in_doc_comments.rs @@ -3,7 +3,7 @@ use rustc_ast::ast; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::{BytePos, Span}; +use rustc_span::{BytePos, Span}; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 788678a63b76..83f3f93a0443 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -18,7 +18,7 @@ use rustc_hir::{ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::def_id::LocalDefId; -use rustc_span::source_map::Span; +use rustc_span::Span; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/types/utils.rs b/clippy_lints/src/types/utils.rs index a30748db88fc..39469841bd40 100644 --- a/clippy_lints/src/types/utils.rs +++ b/clippy_lints/src/types/utils.rs @@ -2,7 +2,7 @@ use clippy_utils::last_path_segment; use if_chain::if_chain; use rustc_hir::{GenericArg, GenericArgsParentheses, QPath, TyKind}; use rustc_lint::LateContext; -use rustc_span::source_map::Span; +use rustc_span::Span; pub(super) fn match_borrows_parameter(_cx: &LateContext<'_>, qpath: &QPath<'_>) -> Option { let last = last_path_segment(qpath); diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index e275bfd37b00..a62665b8f37e 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -7,7 +7,7 @@ use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, HirId}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; +use rustc_span::Span; use unicode_normalization::UnicodeNormalization; declare_clippy_lint! { diff --git a/clippy_lints/src/unsafe_removed_from_name.rs b/clippy_lints/src/unsafe_removed_from_name.rs index 7ee785804f0a..c43d5dc94b3e 100644 --- a/clippy_lints/src/unsafe_removed_from_name.rs +++ b/clippy_lints/src/unsafe_removed_from_name.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_ast::ast::{Item, ItemKind, UseTree, UseTreeKind}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; +use rustc_span::Span; use rustc_span::symbol::Ident; declare_clippy_lint! { diff --git a/clippy_lints/src/unused_unit.rs b/clippy_lints/src/unused_unit.rs index 95e74718d806..70f52172e94c 100644 --- a/clippy_lints/src/unused_unit.rs +++ b/clippy_lints/src/unused_unit.rs @@ -6,8 +6,7 @@ use rustc_ast::{ast, ClosureBinder}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; -use rustc_span::BytePos; +use rustc_span::{BytePos, Span}; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 9a0d83d83f1f..55837bd5ab9c 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -15,8 +15,7 @@ use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index fc17e7c6d5aa..799e04180775 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -14,8 +14,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::source_map::Span; -use rustc_span::sym; +use rustc_span::{sym, Span}; #[expect(clippy::module_name_repetitions)] #[derive(Clone)] diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs index edd87546a5f8..61c15aff355d 100644 --- a/clippy_utils/src/diagnostics.rs +++ b/clippy_utils/src/diagnostics.rs @@ -11,7 +11,7 @@ use rustc_errors::{Applicability, Diagnostic, MultiSpan}; use rustc_hir::HirId; use rustc_lint::{LateContext, Lint, LintContext}; -use rustc_span::source_map::Span; +use rustc_span::Span; use std::env; fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) { diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 836f8cc19168..fe274b9c50b7 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -16,7 +16,7 @@ use rustc_lint::{EarlyContext, LateContext, LintContext}; use rustc_middle::hir::place::ProjectionKind; use rustc_middle::mir::{FakeReadCause, Mutability}; use rustc_middle::ty; -use rustc_span::source_map::{BytePos, CharPos, Pos, Span, SyntaxContext}; +use rustc_span::{BytePos, CharPos, Pos, Span, SyntaxContext}; use std::borrow::Cow; use std::fmt::{self, Display, Write as _}; use std::ops::{Add, Neg, Not, Sub}; From 34e54ffa3e28fc2f0c53516b0351ae9f08942fd1 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 23 Oct 2023 18:55:04 +0200 Subject: [PATCH 0980/1222] Warn when lint level is set on a match arm --- tests/ui/match_same_arms_non_exhaustive.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/match_same_arms_non_exhaustive.rs b/tests/ui/match_same_arms_non_exhaustive.rs index e1b95aa57760..5c277f925a8f 100644 --- a/tests/ui/match_same_arms_non_exhaustive.rs +++ b/tests/ui/match_same_arms_non_exhaustive.rs @@ -9,12 +9,12 @@ fn repeat() -> ! { } pub fn f(x: Ordering) { + #[deny(non_exhaustive_omitted_patterns)] match x { Ordering::Relaxed => println!("relaxed"), Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), Ordering::AcqRel | Ordering::SeqCst => repeat(), - #[deny(non_exhaustive_omitted_patterns)] _ => repeat(), } } From d6935ed68f52cc6b51ebf8a15ec79c4b067235bc Mon Sep 17 00:00:00 2001 From: Dinu Blanovschi Date: Sat, 4 Nov 2023 21:43:18 +0100 Subject: [PATCH 0981/1222] fix clippy author and failing test --- clippy_lints/src/utils/author.rs | 9 +++++++-- tests/ui/author/blocks.stdout | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index ce93aea21360..152248afc903 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -7,7 +7,7 @@ use rustc_ast::LitIntType; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; use rustc_hir::{ - ArrayLen, BindingAnnotation, Closure, ExprKind, FnRetTy, HirId, Lit, PatKind, QPath, StmtKind, TyKind, + ArrayLen, BindingAnnotation, Closure, ExprKind, FnRetTy, HirId, Lit, PatKind, QPath, StmtKind, TyKind, CaptureBy }; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::declare_lint_pass; @@ -479,6 +479,11 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { movability, .. }) => { + let capture_clause = match capture_clause { + CaptureBy::Value { .. } => "Value { .. }", + CaptureBy::Ref => "Ref", + }; + let movability = OptionPat::new(movability.map(|m| format!("Movability::{m:?}"))); let ret_ty = match fn_decl.output { @@ -487,7 +492,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { }; bind!(self, fn_decl, body_id); - kind!("Closure(CaptureBy::{capture_clause:?}, {fn_decl}, {body_id}, _, {movability})"); + kind!("Closure(CaptureBy::{capture_clause}, {fn_decl}, {body_id}, _, {movability})"); chain!(self, "let {ret_ty} = {fn_decl}.output"); self.body(body_id); }, diff --git a/tests/ui/author/blocks.stdout b/tests/ui/author/blocks.stdout index eb3e5189c823..140300a16730 100644 --- a/tests/ui/author/blocks.stdout +++ b/tests/ui/author/blocks.stdout @@ -40,10 +40,10 @@ if let ExprKind::Block(block, None) = expr.kind { // report your lint here } -if let ExprKind::Closure(CaptureBy::Value, fn_decl, body_id, _, None) = expr.kind +if let ExprKind::Closure(CaptureBy::Value { .. }, fn_decl, body_id, _, None) = expr.kind && let FnRetTy::DefaultReturn(_) = fn_decl.output && expr1 = &cx.tcx.hir().body(body_id).value - && let ExprKind::Closure(CaptureBy::Value, fn_decl1, body_id1, _, Some(Movability::Static)) = expr1.kind + && let ExprKind::Closure(CaptureBy::Value { .. }, fn_decl1, body_id1, _, Some(Movability::Static)) = expr1.kind && let FnRetTy::DefaultReturn(_) = fn_decl1.output && expr2 = &cx.tcx.hir().body(body_id1).value && let ExprKind::Block(block, None) = expr2.kind From 553c29cabfb57172df977c56e0106e0701cc086f Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 13 Nov 2023 14:00:05 +0000 Subject: [PATCH 0982/1222] rename `ReLateBound` to `ReBound` other changes: - `Region::new_late_bound` -> `Region::new_bound` - `Region::is_late_bound` -> `Region::is_bound` --- clippy_lints/src/eta_reduction.rs | 4 ++-- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/ptr.rs | 2 +- clippy_utils/src/ty.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index fad8fbf04497..150b1c777db1 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -247,8 +247,8 @@ fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure: ClosureArgs<'tcx>, call_sig: /// This is needed because rustc is unable to late bind early-bound regions in a function signature. fn has_late_bound_to_non_late_bound_regions(from_sig: FnSig<'_>, to_sig: FnSig<'_>) -> bool { fn check_region(from_region: Region<'_>, to_region: Region<'_>) -> bool { - matches!(from_region.kind(), RegionKind::ReLateBound(..)) - && !matches!(to_region.kind(), RegionKind::ReLateBound(..)) + matches!(from_region.kind(), RegionKind::ReBound(..)) + && !matches!(to_region.kind(), RegionKind::ReBound(..)) } fn check_subs(from_subs: &[GenericArg<'_>], to_subs: &[GenericArg<'_>]) -> bool { diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 4d7a055dae17..d6fa742b7968 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -168,7 +168,7 @@ impl<'tcx> PassByRefOrValue { match *ty.skip_binder().kind() { ty::Ref(lt, ty, Mutability::Not) => { match lt.kind() { - RegionKind::ReLateBound(index, region) + RegionKind::ReBound(index, region) if index.as_u32() == 0 && output_regions.contains(®ion) => { continue; diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 83863b92caff..c6ac96a4539c 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -466,7 +466,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>( .filter_map(|arg| { arg.as_region().and_then(|lifetime| match lifetime.kind() { ty::ReEarlyBound(r) => Some(r.def_id), - ty::ReLateBound(_, r) => r.kind.get_id(), + ty::ReBound(_, r) => r.kind.get_id(), ty::ReFree(r) => r.bound_region.get_id(), ty::ReStatic | ty::ReVar(_) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 7eff93881b26..758aa40a2dd1 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -890,7 +890,7 @@ pub fn for_each_top_level_late_bound_region( impl<'tcx, B, F: FnMut(BoundRegion) -> ControlFlow> TypeVisitor> for V { type BreakTy = B; fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow { - if let RegionKind::ReLateBound(idx, bound) = r.kind() + if let RegionKind::ReBound(idx, bound) = r.kind() && idx.as_u32() == self.index { (self.f)(bound) From b19807fe60ad146e130de3011efcb99658b7a3f8 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 13 Nov 2023 14:12:56 +0000 Subject: [PATCH 0983/1222] update type flags - `HAS_RE_LATE_BOUND` -> `HAS_RE_BOUND` - `HAS_TY_LATE_BOUND` -> `HAS_TY_BOUND` - `HAS_CT_LATE_BOUND` -> `HAS_CT_BOUND` - `HAS_LATE_BOUND` -> `HAS_BOUND_VARS` - `fn has_late_bound_regions` -> `fn has_bound_regions` - `fnhas_non_region_late_bound` -> `fn has_non_region_bound_vars` - `fn has_late_bound_vars` -> `fn has_bound_vars` --- clippy_lints/src/eta_reduction.rs | 2 +- clippy_utils/src/ty.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 150b1c777db1..02c53fafd696 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -290,7 +290,7 @@ fn has_late_bound_to_non_late_bound_regions(from_sig: FnSig<'_>, to_sig: FnSig<' .zip(to_tys) .any(|(from_ty, to_ty)| check_ty(from_ty, to_ty)) }, - _ => from_ty.has_late_bound_regions(), + _ => from_ty.has_bound_regions(), } } diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 758aa40a2dd1..2ff979f2dcb3 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -1160,7 +1160,7 @@ pub fn make_normalized_projection<'tcx>( ) -> Option> { fn helper<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: AliasTy<'tcx>) -> Option> { #[cfg(debug_assertions)] - if let Some((i, arg)) = ty.args.iter().enumerate().find(|(_, arg)| arg.has_late_bound_regions()) { + if let Some((i, arg)) = ty.args.iter().enumerate().find(|(_, arg)| arg.has_bound_regions()) { debug_assert!( false, "args contain late-bound region at index `{i}` which can't be normalized.\n\ @@ -1233,7 +1233,7 @@ pub fn make_normalized_projection_with_regions<'tcx>( ) -> Option> { fn helper<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: AliasTy<'tcx>) -> Option> { #[cfg(debug_assertions)] - if let Some((i, arg)) = ty.args.iter().enumerate().find(|(_, arg)| arg.has_late_bound_regions()) { + if let Some((i, arg)) = ty.args.iter().enumerate().find(|(_, arg)| arg.has_bound_regions()) { debug_assert!( false, "args contain late-bound region at index `{i}` which can't be normalized.\n\ From c5d8f55c5e1aa7b8871a804f8782a98feb9760de Mon Sep 17 00:00:00 2001 From: lcnr Date: Tue, 14 Nov 2023 13:13:27 +0000 Subject: [PATCH 0984/1222] finish `RegionKind` rename - `ReFree` -> `ReLateParam` - `ReEarlyBound` -> `ReEarlyParam` --- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/ptr.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index d6fa742b7968..4db65b0d04fe 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -175,7 +175,7 @@ impl<'tcx> PassByRefOrValue { }, // Early bound regions on functions are either from the containing item, are bounded by another // lifetime, or are used as a bound for a type or lifetime. - RegionKind::ReEarlyBound(..) => continue, + RegionKind::ReEarlyParam(..) => continue, _ => (), } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index c6ac96a4539c..1d4b4d10d501 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -465,9 +465,9 @@ fn check_fn_args<'cx, 'tcx: 'cx>( .walk() .filter_map(|arg| { arg.as_region().and_then(|lifetime| match lifetime.kind() { - ty::ReEarlyBound(r) => Some(r.def_id), + ty::ReEarlyParam(r) => Some(r.def_id), ty::ReBound(_, r) => r.kind.get_id(), - ty::ReFree(r) => r.bound_region.get_id(), + ty::ReLateParam(r) => r.bound_region.get_id(), ty::ReStatic | ty::ReVar(_) | ty::RePlaceholder(_) From f4e6df5e38eb37162558a87c6a0928816cd968ed Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 6 Nov 2023 16:52:38 +1100 Subject: [PATCH 0985/1222] Move `lint_store` from `GlobalCtxt` to `Session`. This was made possible by the removal of plugin support, which simplified lint store creation. This simplifies the places in rustc and rustdoc that call `describe_lints`, which are early on. The lint store is now built before those places, so they don't have to create their own lint store for temporary use, they can just use the main one. --- tests/ui/macro_use_imports.stderr | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/ui/macro_use_imports.stderr b/tests/ui/macro_use_imports.stderr index 6de869699ec6..bafe8cfddb47 100644 --- a/tests/ui/macro_use_imports.stderr +++ b/tests/ui/macro_use_imports.stderr @@ -1,23 +1,23 @@ error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:25:5 + --> $DIR/macro_use_imports.rs:23:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::mut_mut, inner::try_err};` | = note: `-D clippy::macro-use-imports` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::macro_use_imports)]` error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:23:5 + --> $DIR/macro_use_imports.rs:21:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::mut_mut, inner::try_err};` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;` error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:21:5 + --> $DIR/macro_use_imports.rs:25:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;` error: `macro_use` attributes are no longer needed in the Rust 2018 edition --> $DIR/macro_use_imports.rs:19:5 From eb51e22e68e9bc77e5d6861bf629cbad52ddd47d Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 17 Nov 2023 09:29:48 +0000 Subject: [PATCH 0986/1222] rename bound region instantiation - `erase_late_bound_regions` -> `instantiate_bound_regions_with_erased` - `replace_late_bound_regions_X` -> `instantiate_bound_regions_X` --- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/functions/result.rs | 2 +- clippy_lints/src/iter_not_returning_iterator.rs | 2 +- clippy_lints/src/methods/map_flatten.rs | 2 +- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/methods/needless_collect.rs | 2 +- clippy_lints/src/mixed_read_write_in_expression.rs | 2 +- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 4 ++-- clippy_lints/src/ptr.rs | 2 +- clippy_lints/src/unit_return_expecting_ord.rs | 10 +++++----- clippy_lints/src/unnecessary_box_returns.rs | 2 +- clippy_lints/src/use_self.rs | 2 +- clippy_utils/src/lib.rs | 4 ++-- clippy_utils/src/ty.rs | 4 ++-- 15 files changed, 22 insertions(+), 22 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index afca8850ac52..cbeb0050be0f 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -771,7 +771,7 @@ impl TyCoercionStability { DefinedTy::Mir(ty) => Self::for_mir_ty( cx.tcx, ty.param_env, - cx.tcx.erase_late_bound_regions(ty.value), + cx.tcx.instantiate_bound_regions_with_erased(ty.value), for_return, ), } diff --git a/clippy_lints/src/functions/result.rs b/clippy_lints/src/functions/result.rs index 47db107d669e..5e90fcd72ebe 100644 --- a/clippy_lints/src/functions/result.rs +++ b/clippy_lints/src/functions/result.rs @@ -23,7 +23,7 @@ fn result_err_ty<'tcx>( && let hir::FnRetTy::Return(hir_ty) = decl.output && let ty = cx .tcx - .erase_late_bound_regions(cx.tcx.fn_sig(id).instantiate_identity().output()) + .instantiate_bound_regions_with_erased(cx.tcx.fn_sig(id).instantiate_identity().output()) && is_type_diagnostic_item(cx, ty, sym::Result) && let ty::Adt(_, args) = ty.kind() { diff --git a/clippy_lints/src/iter_not_returning_iterator.rs b/clippy_lints/src/iter_not_returning_iterator.rs index 505aadd1a110..fce3b0e18b7d 100644 --- a/clippy_lints/src/iter_not_returning_iterator.rs +++ b/clippy_lints/src/iter_not_returning_iterator.rs @@ -71,7 +71,7 @@ fn check_sig(cx: &LateContext<'_>, name: &str, sig: &FnSig<'_>, fn_id: LocalDefI if sig.decl.implicit_self.has_implicit_self() { let ret_ty = cx .tcx - .erase_late_bound_regions(cx.tcx.fn_sig(fn_id).instantiate_identity().output()); + .instantiate_bound_regions_with_erased(cx.tcx.fn_sig(fn_id).instantiate_identity().output()); let ret_ty = cx .tcx .try_normalize_erasing_regions(cx.param_env, ret_ty) diff --git a/clippy_lints/src/methods/map_flatten.rs b/clippy_lints/src/methods/map_flatten.rs index e74a764551c1..26ef0d10fed4 100644 --- a/clippy_lints/src/methods/map_flatten.rs +++ b/clippy_lints/src/methods/map_flatten.rs @@ -63,7 +63,7 @@ fn is_map_to_option(cx: &LateContext<'_>, map_arg: &Expr<'_>) -> bool { ty::Closure(_, args) => args.as_closure().sig(), _ => map_closure_ty.fn_sig(cx.tcx), }; - let map_closure_return_ty = cx.tcx.erase_late_bound_regions(map_closure_sig.output()); + let map_closure_return_ty = cx.tcx.instantiate_bound_regions_with_erased(map_closure_sig.output()); is_type_diagnostic_item(cx, map_closure_return_ty, sym::Option) }, _ => false, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 57c3913944f3..31d44bc1b3fb 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3897,7 +3897,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { let implements_trait = matches!(item.kind, hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })); if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind { let method_sig = cx.tcx.fn_sig(impl_item.owner_id).instantiate_identity(); - let method_sig = cx.tcx.erase_late_bound_regions(method_sig); + let method_sig = cx.tcx.instantiate_bound_regions_with_erased(method_sig); let first_arg_ty_opt = method_sig.inputs().iter().next().copied(); // if this impl block implements a trait, lint in trait definition instead if !implements_trait && cx.effective_visibilities.is_exported(impl_item.owner_id.def_id) { diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index 2ef71be3217f..79ed5515ea29 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -225,7 +225,7 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) - && let sig = cx.tcx.fn_sig(id).instantiate_identity() && sig.skip_binder().output().is_bool() && let [_, search_ty] = *sig.skip_binder().inputs() - && let ty::Ref(_, search_ty, Mutability::Not) = *cx.tcx.erase_late_bound_regions(sig.rebind(search_ty)).kind() + && let ty::Ref(_, search_ty, Mutability::Not) = *cx.tcx.instantiate_bound_regions_with_erased(sig.rebind(search_ty)).kind() && let Some(iter_trait) = cx.tcx.get_diagnostic_item(sym::Iterator) && let Some(iter_item) = cx.tcx.associated_items(iter_trait).find_by_name_and_kind( cx.tcx, diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs index b46c006cd57a..e5ebdc145103 100644 --- a/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/clippy_lints/src/mixed_read_write_in_expression.rs @@ -165,7 +165,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { match typ.kind() { ty::FnDef(..) | ty::FnPtr(_) => { let sig = typ.fn_sig(self.cx.tcx); - if self.cx.tcx.erase_late_bound_regions(sig).output().kind() == &ty::Never { + if self.cx.tcx.instantiate_bound_regions_with_erased(sig).output().kind() == &ty::Never { self.report_diverging_sub_expr(e); } }, diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 823715f88406..454fc6f56429 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -143,7 +143,7 @@ impl MutableKeyType { for (hir_ty, ty) in iter::zip(decl.inputs, fn_sig.inputs().skip_binder()) { self.check_ty_(cx, hir_ty.span, *ty); } - self.check_ty_(cx, decl.output.span(), cx.tcx.erase_late_bound_regions(fn_sig.output())); + self.check_ty_(cx, decl.output.span(), cx.tcx.instantiate_bound_regions_with_erased(fn_sig.output())); } // We want to lint 1. sets or maps with 2. not immutable key types and 3. no unerased diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 0f6ddb35da30..bbca8a123e68 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -177,7 +177,7 @@ impl<'tcx> PassByRefOrValue { _ => (), } - let ty = cx.tcx.erase_late_bound_regions(fn_sig.rebind(ty)); + let ty = cx.tcx.instantiate_bound_regions_with_erased(fn_sig.rebind(ty)); if is_copy(cx, ty) && let Some(size) = cx.layout_of(ty).ok().map(|l| l.size.bytes()) && size <= self.ref_min_size @@ -225,7 +225,7 @@ impl<'tcx> PassByRefOrValue { _ => continue, } } - let ty = cx.tcx.erase_late_bound_regions(ty); + let ty = cx.tcx.instantiate_bound_regions_with_erased(ty); if is_copy(cx, ty) && !is_self_ty(input) diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 410f4ec651bf..621a32d79bf3 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -712,7 +712,7 @@ fn matches_preds<'tcx>( preds: &'tcx [ty::PolyExistentialPredicate<'tcx>], ) -> bool { let infcx = cx.tcx.infer_ctxt().build(); - preds.iter().all(|&p| match cx.tcx.erase_late_bound_regions(p) { + preds.iter().all(|&p| match cx.tcx.instantiate_bound_regions_with_erased(p) { ExistentialPredicate::Trait(p) => infcx .type_implements_trait(p.def_id, [ty.into()].into_iter().chain(p.args.iter()), cx.param_env) .must_apply_modulo_regions(), diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 385f8255a395..bfd30cec3ddd 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -44,7 +44,7 @@ fn get_trait_predicates_for_trait_id<'tcx>( let mut preds = Vec::new(); for (pred, _) in generics.predicates { if let ClauseKind::Trait(poly_trait_pred) = pred.kind().skip_binder() - && let trait_pred = cx.tcx.erase_late_bound_regions(pred.kind().rebind(poly_trait_pred)) + && let trait_pred = cx.tcx.instantiate_bound_regions_with_erased(pred.kind().rebind(poly_trait_pred)) && let Some(trait_def_id) = trait_id && trait_def_id == trait_pred.trait_ref.def_id { @@ -61,7 +61,7 @@ fn get_projection_pred<'tcx>( ) -> Option> { generics.predicates.iter().find_map(|(proj_pred, _)| { if let ClauseKind::Projection(pred) = proj_pred.kind().skip_binder() { - let projection_pred = cx.tcx.erase_late_bound_regions(proj_pred.kind().rebind(pred)); + let projection_pred = cx.tcx.instantiate_bound_regions_with_erased(proj_pred.kind().rebind(pred)); if projection_pred.projection_ty.args == trait_pred.trait_ref.args { return Some(projection_pred); } @@ -79,10 +79,10 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve let ord_preds = get_trait_predicates_for_trait_id(cx, generics, cx.tcx.get_diagnostic_item(sym::Ord)); let partial_ord_preds = get_trait_predicates_for_trait_id(cx, generics, cx.tcx.lang_items().partial_ord_trait()); - // Trying to call erase_late_bound_regions on fn_sig.inputs() gives the following error + // Trying to call instantiate_bound_regions_with_erased on fn_sig.inputs() gives the following error // The trait `rustc::ty::TypeFoldable<'_>` is not implemented for // `&[rustc_middle::ty::Ty<'_>]` - let inputs_output = cx.tcx.erase_late_bound_regions(fn_sig.inputs_and_output()); + let inputs_output = cx.tcx.instantiate_bound_regions_with_erased(fn_sig.inputs_and_output()); inputs_output .iter() .rev() @@ -116,7 +116,7 @@ fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Spa if let ExprKind::Closure(&Closure { body, fn_decl_span, .. }) = arg.kind && let ty::Closure(_def_id, args) = &cx.typeck_results().node_type(arg.hir_id).kind() && let ret_ty = args.as_closure().sig().output() - && let ty = cx.tcx.erase_late_bound_regions(ret_ty) + && let ty = cx.tcx.instantiate_bound_regions_with_erased(ret_ty) && ty.is_unit() { let body = cx.tcx.hir().body(body); diff --git a/clippy_lints/src/unnecessary_box_returns.rs b/clippy_lints/src/unnecessary_box_returns.rs index ca159eb4d5fd..9bd7167db257 100644 --- a/clippy_lints/src/unnecessary_box_returns.rs +++ b/clippy_lints/src/unnecessary_box_returns.rs @@ -71,7 +71,7 @@ impl UnnecessaryBoxReturns { let return_ty = cx .tcx - .erase_late_bound_regions(cx.tcx.fn_sig(def_id).skip_binder()) + .instantiate_bound_regions_with_erased(cx.tcx.fn_sig(def_id).skip_binder()) .output(); if !return_ty.is_box() { diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index f058fe5f8311..ac1d9acc70b1 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -159,7 +159,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { .trait_item_def_id .expect("impl method matches a trait method"); let trait_method_sig = cx.tcx.fn_sig(trait_method).instantiate_identity(); - let trait_method_sig = cx.tcx.erase_late_bound_regions(trait_method_sig); + let trait_method_sig = cx.tcx.instantiate_bound_regions_with_erased(trait_method_sig); // `impl_inputs_outputs` is an iterator over the types (`hir::Ty`) declared in the // implementation of the trait. diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 0998e00c7543..2466e8bb339d 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1667,13 +1667,13 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option { /// Convenience function to get the return type of a function. pub fn return_ty<'tcx>(cx: &LateContext<'tcx>, fn_def_id: hir::OwnerId) -> Ty<'tcx> { let ret_ty = cx.tcx.fn_sig(fn_def_id).instantiate_identity().output(); - cx.tcx.erase_late_bound_regions(ret_ty) + cx.tcx.instantiate_bound_regions_with_erased(ret_ty) } /// Convenience function to get the nth argument type of a function. pub fn nth_arg<'tcx>(cx: &LateContext<'tcx>, fn_def_id: hir::OwnerId, nth: usize) -> Ty<'tcx> { let arg = cx.tcx.fn_sig(fn_def_id).instantiate_identity().input(nth); - cx.tcx.erase_late_bound_regions(arg) + cx.tcx.instantiate_bound_regions_with_erased(arg) } /// Checks if an expression is constructing a tuple-like enum variant or struct diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index b8090b719394..20588b63a78d 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -1169,7 +1169,7 @@ pub fn make_normalized_projection<'tcx>( debug_assert!( false, "args contain late-bound region at index `{i}` which can't be normalized.\n\ - use `TyCtxt::erase_late_bound_regions`\n\ + use `TyCtxt::instantiate_bound_regions_with_erased`\n\ note: arg is `{arg:#?}`", ); return None; @@ -1247,7 +1247,7 @@ pub fn make_normalized_projection_with_regions<'tcx>( debug_assert!( false, "args contain late-bound region at index `{i}` which can't be normalized.\n\ - use `TyCtxt::erase_late_bound_regions`\n\ + use `TyCtxt::instantiate_bound_regions_with_erased`\n\ note: arg is `{arg:#?}`", ); return None; From a1854b10c255eda989d1927fad7ac2d7ba84ccac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 8 Nov 2023 18:24:49 +0000 Subject: [PATCH 0987/1222] Don't sort `span_suggestions`, leave that to caller --- clippy_lints/src/booleans.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index d4f2e316890e..2cb599964d2b 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -424,8 +424,9 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> { improvements.push(suggestion); } } - let nonminimal_bool_lint = |suggestions: Vec<_>| { + let nonminimal_bool_lint = |mut suggestions: Vec<_>| { if self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, e.hir_id).0 != Level::Allow { + suggestions.sort(); span_lint_hir_and_then( self.cx, NONMINIMAL_BOOL, From 6c906879c24fa7a1ad11dc6592e666dc356990fa Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 14 Nov 2023 10:02:52 +1100 Subject: [PATCH 0988/1222] Update itertools to 0.11. Because the API for `with_position` improved in 0.11 and I want to use it. --- Cargo.toml | 2 +- clippy_dev/Cargo.toml | 2 +- clippy_lints/Cargo.toml | 2 +- clippy_utils/Cargo.toml | 2 +- declare_clippy_lint/Cargo.toml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3b138b480b6f..f6084a462726 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ toml = "0.7.3" walkdir = "2.3" # This is used by the `collect-metadata` alias. filetime = "0.2" -itertools = "0.10.1" +itertools = "0.11" # UI test dependencies clippy_utils = { path = "clippy_utils" } diff --git a/clippy_dev/Cargo.toml b/clippy_dev/Cargo.toml index c3f8a782d273..ce738e3f4ec7 100644 --- a/clippy_dev/Cargo.toml +++ b/clippy_dev/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" aho-corasick = "0.7" clap = "4.1.4" indoc = "1.0" -itertools = "0.10.1" +itertools = "0.11" opener = "0.5" shell-escape = "0.1" walkdir = "2.3" diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 84246d285c09..a9375214be44 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -14,7 +14,7 @@ cargo_metadata = "0.15.3" clippy_config = { path = "../clippy_config" } clippy_utils = { path = "../clippy_utils" } declare_clippy_lint = { path = "../declare_clippy_lint" } -itertools = "0.10.1" +itertools = "0.11" quine-mc_cluskey = "0.2" regex-syntax = "0.7" serde = { version = "1.0", features = ["derive"] } diff --git a/clippy_utils/Cargo.toml b/clippy_utils/Cargo.toml index d7053d3ff848..5d23326cec89 100644 --- a/clippy_utils/Cargo.toml +++ b/clippy_utils/Cargo.toml @@ -7,7 +7,7 @@ publish = false [dependencies] clippy_config = { path = "../clippy_config" } arrayvec = { version = "0.7", default-features = false } -itertools = "0.10.1" +itertools = "0.11" rustc-semver = "1.1" [features] diff --git a/declare_clippy_lint/Cargo.toml b/declare_clippy_lint/Cargo.toml index 8c1150ed0104..af123e107d5c 100644 --- a/declare_clippy_lint/Cargo.toml +++ b/declare_clippy_lint/Cargo.toml @@ -8,7 +8,7 @@ publish = false proc-macro = true [dependencies] -itertools = "0.10.1" +itertools = "0.11" quote = "1.0.21" syn = "2.0" From 16f16928e2209a86d0af49de93de7442d7cc816c Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Tue, 21 Nov 2023 17:08:42 +0000 Subject: [PATCH 0989/1222] Bless clippy tests Co-authored-by: Adrian --- tests/ui-toml/bad_toml/conf_bad_toml.stderr | 2 +- tests/ui-toml/bad_toml_type/conf_bad_type.stderr | 2 +- tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr | 2 +- .../decimal_literal_representation.stderr | 2 +- tests/ui-toml/disallowed_names_replace/disallowed_names.stderr | 2 +- .../disallowed_script_idents/disallowed_script_idents.stderr | 2 +- tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr | 2 +- tests/ui-toml/duplicated_keys/duplicated_keys.stderr | 2 +- tests/ui-toml/duplicated_keys_deprecated/duplicated_keys.stderr | 2 +- .../ui-toml/duplicated_keys_deprecated_2/duplicated_keys.stderr | 2 +- tests/ui-toml/enum_variant_size/enum_variant_size.stderr | 2 +- tests/ui-toml/fn_params_excessive_bools/test.stderr | 2 +- tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr | 2 +- tests/ui-toml/impl_trait_in_params/impl_trait_in_params.stderr | 2 +- .../invalid_min_rust_version/invalid_min_rust_version.stderr | 2 +- tests/ui-toml/large_futures/large_futures.stderr | 2 +- tests/ui-toml/large_stack_frames/large_stack_frames.stderr | 2 +- .../large_types_passed_by_value.stderr | 2 +- tests/ui-toml/manual_let_else/manual_let_else.stderr | 2 +- .../index_refutable_slice.stderr | 2 +- tests/ui-toml/min_rust_version/min_rust_version.stderr | 2 +- tests/ui-toml/result_large_err/result_large_err.stderr | 2 +- tests/ui-toml/semicolon_block/semicolon_inside_block.stderr | 2 +- tests/ui-toml/struct_excessive_bools/test.stderr | 2 +- tests/ui-toml/too_large_for_stack/boxed_local.stderr | 2 +- tests/ui-toml/too_large_for_stack/useless_vec.stderr | 2 +- tests/ui-toml/too_many_arguments/too_many_arguments.stderr | 2 +- tests/ui-toml/type_complexity/type_complexity.stderr | 2 +- tests/ui-toml/type_repetition_in_bounds/main.stderr | 2 +- .../unnecessary_box_returns/unnecessary_box_returns.stderr | 2 +- tests/ui-toml/verbose_bit_mask/verbose_bit_mask.stderr | 2 +- tests/ui-toml/wildcard_imports/wildcard_imports.stderr | 2 +- tests/ui/borrow_deref_ref_unfixable.stderr | 2 +- tests/ui/char_lit_as_u8.stderr | 2 +- tests/ui/cognitive_complexity_attr_used.stderr | 2 +- tests/ui/copy_iterator.stderr | 2 +- tests/ui/crashes/ice-10148.stderr | 2 +- tests/ui/crashes/ice-11422.stderr | 2 +- tests/ui/crashes/ice-2774.stderr | 2 +- tests/ui/crashes/ice-3717.stderr | 2 +- tests/ui/crashes/ice-3891.stderr | 2 +- tests/ui/crashes/ice-5497.stderr | 2 +- tests/ui/crashes/ice-5835.stderr | 2 +- tests/ui/crashes/ice-5872.stderr | 2 +- tests/ui/crashes/ice-6254.stderr | 2 +- tests/ui/crashes/ice-6255.stderr | 2 +- tests/ui/crashes/ice-6256.stderr | 2 +- tests/ui/crashes/ice-7169.stderr | 2 +- tests/ui/crashes/ice-7868.stderr | 2 +- tests/ui/crashes/ice-7869.stderr | 2 +- tests/ui/crashes/ice-8250.stderr | 2 +- tests/ui/crashes/ice-8821.stderr | 2 +- tests/ui/crashes/ice-9041.stderr | 2 +- tests/ui/crashes/ice-9445.stderr | 2 +- tests/ui/crashes/ice-96721.stderr | 2 +- tests/ui/crashes/needless_lifetimes_impl_trait.stderr | 2 +- tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr | 2 +- tests/ui/crate_in_macro_def.stderr | 2 +- tests/ui/crate_level_checks/no_std_swap.stderr | 2 +- tests/ui/crate_level_checks/std_main_recursion.stderr | 2 +- tests/ui/def_id_nocore.stderr | 2 +- tests/ui/doc_link_with_quotes.stderr | 2 +- tests/ui/double_neg.stderr | 2 +- tests/ui/duplicate_underscore_argument.stderr | 2 +- tests/ui/empty_enum.stderr | 2 +- tests/ui/entry_btree.stderr | 2 +- tests/ui/exit1.stderr | 2 +- tests/ui/exit2.stderr | 2 +- tests/ui/filter_map_next.stderr | 2 +- tests/ui/four_forward_slashes_first_line.stderr | 2 +- tests/ui/functions_maxlines.stderr | 2 +- tests/ui/index_refutable_slice/slice_indexing_in_macro.stderr | 2 +- tests/ui/inspect_for_each.stderr | 2 +- tests/ui/issue-3145.stderr | 2 +- tests/ui/issue_2356.stderr | 2 +- tests/ui/items_after_test_module/in_submodule.stderr | 2 +- tests/ui/items_after_test_module/root_module.stderr | 2 +- tests/ui/iter_next_loop.stderr | 2 +- tests/ui/manual_non_exhaustive_enum.stderr | 2 +- tests/ui/map_err.stderr | 2 +- tests/ui/mem_replace_macro.stderr | 2 +- tests/ui/methods_fixable.stderr | 2 +- tests/ui/methods_unfixable.stderr | 2 +- tests/ui/missing_doc_crate_missing.stderr | 2 +- tests/ui/missing_spin_loop_no_std.stderr | 2 +- tests/ui/mut_mutex_lock.stderr | 2 +- tests/ui/needless_arbitrary_self_type_unfixable.stderr | 2 +- tests/ui/needless_bitwise_bool.stderr | 2 +- tests/ui/needless_else.stderr | 2 +- tests/ui/needless_for_each_unfixable.stderr | 2 +- tests/ui/needless_option_take.stderr | 2 +- tests/ui/needless_return_with_question_mark.stderr | 2 +- tests/ui/needless_update.stderr | 2 +- tests/ui/new_ret_no_self_overflow.stderr | 2 +- tests/ui/non_minimal_cfg2.stderr | 2 +- tests/ui/obfuscated_if_else.stderr | 2 +- tests/ui/partialeq_ne_impl.stderr | 2 +- tests/ui/path_buf_push_overwrite.stderr | 2 +- tests/ui/permissions_set_readonly_false.stderr | 2 +- tests/ui/proc_macro.stderr | 2 +- tests/ui/pub_use.stderr | 2 +- tests/ui/question_mark_used.stderr | 2 +- tests/ui/range.stderr | 2 +- tests/ui/renamed_builtin_attr.stderr | 2 +- tests/ui/result_map_or_into_option.stderr | 2 +- tests/ui/seek_from_current.stderr | 2 +- tests/ui/self_named_constructors.stderr | 2 +- tests/ui/serde.stderr | 2 +- tests/ui/should_panic_without_expect.stderr | 2 +- tests/ui/string_from_utf8_as_bytes.stderr | 2 +- tests/ui/string_to_string.stderr | 2 +- tests/ui/tests_outside_test_module.stderr | 2 +- tests/ui/track-diagnostics.stderr | 2 +- tests/ui/types.stderr | 2 +- tests/ui/uninlined_format_args_panic.edition2018.stderr | 2 +- tests/ui/unknown_attribute.stderr | 2 +- tests/ui/vec_resize_to_zero.stderr | 2 +- 117 files changed, 117 insertions(+), 117 deletions(-) diff --git a/tests/ui-toml/bad_toml/conf_bad_toml.stderr b/tests/ui-toml/bad_toml/conf_bad_toml.stderr index f7d53763a438..c308b7aa0239 100644 --- a/tests/ui-toml/bad_toml/conf_bad_toml.stderr +++ b/tests/ui-toml/bad_toml/conf_bad_toml.stderr @@ -4,5 +4,5 @@ error: error reading Clippy's configuration file: expected `.`, `=` LL | fn this_is_obviously(not: a, toml: file) { | ^ -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/bad_toml_type/conf_bad_type.stderr b/tests/ui-toml/bad_toml_type/conf_bad_type.stderr index fb0a14081524..1bcde2f30ed6 100644 --- a/tests/ui-toml/bad_toml_type/conf_bad_type.stderr +++ b/tests/ui-toml/bad_toml_type/conf_bad_type.stderr @@ -4,5 +4,5 @@ error: error reading Clippy's configuration file: invalid type: integer `42`, ex LL | disallowed-names = 42 | ^^ -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr index a21952c0e7ad..08fdb2d2dc32 100644 --- a/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr +++ b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr @@ -20,5 +20,5 @@ LL | fn cognitive_complexity() { = note: `-D clippy::cognitive-complexity` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::cognitive_complexity)]` -error: aborting due to previous error; 2 warnings emitted +error: aborting due to 1 previous error; 2 warnings emitted diff --git a/tests/ui-toml/decimal_literal_representation/decimal_literal_representation.stderr b/tests/ui-toml/decimal_literal_representation/decimal_literal_representation.stderr index 6f817a3fdde4..4510275c9a9a 100644 --- a/tests/ui-toml/decimal_literal_representation/decimal_literal_representation.stderr +++ b/tests/ui-toml/decimal_literal_representation/decimal_literal_representation.stderr @@ -7,5 +7,5 @@ LL | let _ = 16777215; = note: `-D clippy::decimal-literal-representation` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::decimal_literal_representation)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/disallowed_names_replace/disallowed_names.stderr b/tests/ui-toml/disallowed_names_replace/disallowed_names.stderr index d9f25a3eee50..a5fece575f84 100644 --- a/tests/ui-toml/disallowed_names_replace/disallowed_names.stderr +++ b/tests/ui-toml/disallowed_names_replace/disallowed_names.stderr @@ -7,5 +7,5 @@ LL | let ducks = ["quack", "quack"]; = note: `-D clippy::disallowed-names` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::disallowed_names)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/disallowed_script_idents/disallowed_script_idents.stderr b/tests/ui-toml/disallowed_script_idents/disallowed_script_idents.stderr index 31bb5ee3514a..e83027e4e28c 100644 --- a/tests/ui-toml/disallowed_script_idents/disallowed_script_idents.stderr +++ b/tests/ui-toml/disallowed_script_idents/disallowed_script_idents.stderr @@ -7,5 +7,5 @@ LL | let カウンタ = 10; = note: `-D clippy::disallowed-script-idents` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::disallowed_script_idents)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr b/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr index 92b0350581d3..877ca726fee0 100644 --- a/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr +++ b/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr @@ -11,5 +11,5 @@ help: try LL | /// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. | ~~~~~~~~~~~~~~~~~~~~~~~~~~ -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/duplicated_keys/duplicated_keys.stderr b/tests/ui-toml/duplicated_keys/duplicated_keys.stderr index 7c56dfdb948e..3f2086b5ecb6 100644 --- a/tests/ui-toml/duplicated_keys/duplicated_keys.stderr +++ b/tests/ui-toml/duplicated_keys/duplicated_keys.stderr @@ -4,5 +4,5 @@ error: error reading Clippy's configuration file: duplicate key `cognitive-compl LL | cognitive-complexity-threshold = 4 | ^ -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/duplicated_keys_deprecated/duplicated_keys.stderr b/tests/ui-toml/duplicated_keys_deprecated/duplicated_keys.stderr index 0af8c0add6c6..3c3839633880 100644 --- a/tests/ui-toml/duplicated_keys_deprecated/duplicated_keys.stderr +++ b/tests/ui-toml/duplicated_keys_deprecated/duplicated_keys.stderr @@ -10,5 +10,5 @@ warning: error reading Clippy's configuration file: deprecated field `cyclomatic LL | cyclomatic-complexity-threshold = 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to previous error; 1 warning emitted +error: aborting due to 1 previous error; 1 warning emitted diff --git a/tests/ui-toml/duplicated_keys_deprecated_2/duplicated_keys.stderr b/tests/ui-toml/duplicated_keys_deprecated_2/duplicated_keys.stderr index a4b1e9c335ca..3d37e4daa960 100644 --- a/tests/ui-toml/duplicated_keys_deprecated_2/duplicated_keys.stderr +++ b/tests/ui-toml/duplicated_keys_deprecated_2/duplicated_keys.stderr @@ -10,5 +10,5 @@ warning: error reading Clippy's configuration file: deprecated field `cyclomatic LL | cyclomatic-complexity-threshold = 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to previous error; 1 warning emitted +error: aborting due to 1 previous error; 1 warning emitted diff --git a/tests/ui-toml/enum_variant_size/enum_variant_size.stderr b/tests/ui-toml/enum_variant_size/enum_variant_size.stderr index 4d9bc9d48e45..ca96c47b92bb 100644 --- a/tests/ui-toml/enum_variant_size/enum_variant_size.stderr +++ b/tests/ui-toml/enum_variant_size/enum_variant_size.stderr @@ -17,5 +17,5 @@ help: consider boxing the large fields to reduce the total size of the enum LL | B(Box<[u8; 501]>), | ~~~~~~~~~~~~~~ -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/fn_params_excessive_bools/test.stderr b/tests/ui-toml/fn_params_excessive_bools/test.stderr index 717a4bbfbfe1..ceec4ea67553 100644 --- a/tests/ui-toml/fn_params_excessive_bools/test.stderr +++ b/tests/ui-toml/fn_params_excessive_bools/test.stderr @@ -8,5 +8,5 @@ LL | fn g(_: bool, _: bool) {} = note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::fn_params_excessive_bools)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr b/tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr index 305e00af27e5..e0e77bf23f66 100644 --- a/tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr +++ b/tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr @@ -12,5 +12,5 @@ LL | if x.get() { = note: `-D clippy::ifs-same-cond` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::ifs_same_cond)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/impl_trait_in_params/impl_trait_in_params.stderr b/tests/ui-toml/impl_trait_in_params/impl_trait_in_params.stderr index 80c4f5ed4b0c..bb1244ada9f4 100644 --- a/tests/ui-toml/impl_trait_in_params/impl_trait_in_params.stderr +++ b/tests/ui-toml/impl_trait_in_params/impl_trait_in_params.stderr @@ -11,5 +11,5 @@ help: add a type parameter LL | fn t<{ /* Generic name */ }: Trait>(_: impl Trait); | +++++++++++++++++++++++++++++++ -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/invalid_min_rust_version/invalid_min_rust_version.stderr b/tests/ui-toml/invalid_min_rust_version/invalid_min_rust_version.stderr index f127c2408f90..a764840665a3 100644 --- a/tests/ui-toml/invalid_min_rust_version/invalid_min_rust_version.stderr +++ b/tests/ui-toml/invalid_min_rust_version/invalid_min_rust_version.stderr @@ -4,5 +4,5 @@ error: error reading Clippy's configuration file: not a valid Rust version LL | msrv = "invalid.version" | ^^^^^^^^^^^^^^^^^ -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/large_futures/large_futures.stderr b/tests/ui-toml/large_futures/large_futures.stderr index 7a02fcdbdd2f..23c6215f9498 100644 --- a/tests/ui-toml/large_futures/large_futures.stderr +++ b/tests/ui-toml/large_futures/large_futures.stderr @@ -7,5 +7,5 @@ LL | should_warn().await; = note: `-D clippy::large-futures` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::large_futures)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/large_stack_frames/large_stack_frames.stderr b/tests/ui-toml/large_stack_frames/large_stack_frames.stderr index 67ee57ab672d..5adf666278fc 100644 --- a/tests/ui-toml/large_stack_frames/large_stack_frames.stderr +++ b/tests/ui-toml/large_stack_frames/large_stack_frames.stderr @@ -11,5 +11,5 @@ LL | | } = note: `-D clippy::large-stack-frames` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::large_stack_frames)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.stderr b/tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.stderr index 6678a2b47214..20026d358aef 100644 --- a/tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.stderr +++ b/tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.stderr @@ -7,5 +7,5 @@ LL | fn f2(_v: [u8; 513]) {} = note: `-D clippy::large-types-passed-by-value` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::large_types_passed_by_value)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/manual_let_else/manual_let_else.stderr b/tests/ui-toml/manual_let_else/manual_let_else.stderr index 5c2c86c37318..67647cc5e95f 100644 --- a/tests/ui-toml/manual_let_else/manual_let_else.stderr +++ b/tests/ui-toml/manual_let_else/manual_let_else.stderr @@ -11,5 +11,5 @@ LL | | }; = note: `-D clippy::manual-let-else` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::manual_let_else)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.stderr b/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.stderr index d319e65d06ce..20ffacd092ad 100644 --- a/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.stderr +++ b/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.stderr @@ -18,5 +18,5 @@ help: and replace the index expressions here LL | println!("{}", slice_7); | ~~~~~~~ -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/min_rust_version/min_rust_version.stderr b/tests/ui-toml/min_rust_version/min_rust_version.stderr index 5b1f8dbd3eab..5bf2bcd3bc61 100644 --- a/tests/ui-toml/min_rust_version/min_rust_version.stderr +++ b/tests/ui-toml/min_rust_version/min_rust_version.stderr @@ -7,5 +7,5 @@ LL | let _: Option = Some(&16).map(|b| *b); = note: `-D clippy::map-clone` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::map_clone)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/result_large_err/result_large_err.stderr b/tests/ui-toml/result_large_err/result_large_err.stderr index b0936319d1b9..cc603fc0cc04 100644 --- a/tests/ui-toml/result_large_err/result_large_err.stderr +++ b/tests/ui-toml/result_large_err/result_large_err.stderr @@ -8,5 +8,5 @@ LL | fn f2() -> Result<(), [u8; 512]> { = note: `-D clippy::result-large-err` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::result_large_err)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr b/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr index ce03d7d75a26..0542e139b340 100644 --- a/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr +++ b/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr @@ -15,5 +15,5 @@ LL ~ unit_fn_block(); LL ~ } | -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/struct_excessive_bools/test.stderr b/tests/ui-toml/struct_excessive_bools/test.stderr index 9237c9c9d29d..31e0e33a39b2 100644 --- a/tests/ui-toml/struct_excessive_bools/test.stderr +++ b/tests/ui-toml/struct_excessive_bools/test.stderr @@ -10,5 +10,5 @@ LL | | } = note: `-D clippy::struct-excessive-bools` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::struct_excessive_bools)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/too_large_for_stack/boxed_local.stderr b/tests/ui-toml/too_large_for_stack/boxed_local.stderr index 2859a29f1b2a..54990c35228f 100644 --- a/tests/ui-toml/too_large_for_stack/boxed_local.stderr +++ b/tests/ui-toml/too_large_for_stack/boxed_local.stderr @@ -7,5 +7,5 @@ LL | fn f(x: Box<[u8; 500]>) {} = note: `-D clippy::boxed-local` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::boxed_local)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/too_large_for_stack/useless_vec.stderr b/tests/ui-toml/too_large_for_stack/useless_vec.stderr index 923cded5eef1..5d289db8534b 100644 --- a/tests/ui-toml/too_large_for_stack/useless_vec.stderr +++ b/tests/ui-toml/too_large_for_stack/useless_vec.stderr @@ -7,5 +7,5 @@ LL | let x = vec![0u8; 500]; = note: `-D clippy::useless-vec` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::useless_vec)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/too_many_arguments/too_many_arguments.stderr b/tests/ui-toml/too_many_arguments/too_many_arguments.stderr index 8b9d159b59c3..81d9bee737e2 100644 --- a/tests/ui-toml/too_many_arguments/too_many_arguments.stderr +++ b/tests/ui-toml/too_many_arguments/too_many_arguments.stderr @@ -7,5 +7,5 @@ LL | fn too_many(p1: u8, p2: u8, p3: u8, p4: u8, p5: u8, p6: u8, p7: u8, p8: u8, = note: `-D clippy::too-many-arguments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::too_many_arguments)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/type_complexity/type_complexity.stderr b/tests/ui-toml/type_complexity/type_complexity.stderr index 8ca637f72225..df824400da82 100644 --- a/tests/ui-toml/type_complexity/type_complexity.stderr +++ b/tests/ui-toml/type_complexity/type_complexity.stderr @@ -7,5 +7,5 @@ LL | fn f2(_: (u8, (u8, (u8, (u8, (u8, (u8, u8))))))) {} = note: `-D clippy::type-complexity` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::type_complexity)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/type_repetition_in_bounds/main.stderr b/tests/ui-toml/type_repetition_in_bounds/main.stderr index 2ae2984975f4..444fbd12814d 100644 --- a/tests/ui-toml/type_repetition_in_bounds/main.stderr +++ b/tests/ui-toml/type_repetition_in_bounds/main.stderr @@ -8,5 +8,5 @@ LL | T: Unpin + PartialEq, = note: `-D clippy::type-repetition-in-bounds` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::type_repetition_in_bounds)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.stderr b/tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.stderr index df9aa37ac10f..9a747a19f795 100644 --- a/tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.stderr +++ b/tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.stderr @@ -8,5 +8,5 @@ LL | fn f() -> Box<[u8; 64]> { = note: `-D clippy::unnecessary-box-returns` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::unnecessary_box_returns)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/verbose_bit_mask/verbose_bit_mask.stderr b/tests/ui-toml/verbose_bit_mask/verbose_bit_mask.stderr index 7377921b42ab..5fcc63131bf4 100644 --- a/tests/ui-toml/verbose_bit_mask/verbose_bit_mask.stderr +++ b/tests/ui-toml/verbose_bit_mask/verbose_bit_mask.stderr @@ -7,5 +7,5 @@ LL | let _ = v & 0b111111 == 0; = note: `-D clippy::verbose-bit-mask` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::verbose_bit_mask)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-toml/wildcard_imports/wildcard_imports.stderr b/tests/ui-toml/wildcard_imports/wildcard_imports.stderr index 13ec3a229ce9..f11fda6a0c6e 100644 --- a/tests/ui-toml/wildcard_imports/wildcard_imports.stderr +++ b/tests/ui-toml/wildcard_imports/wildcard_imports.stderr @@ -7,5 +7,5 @@ LL | use prelude::*; = note: `-D clippy::wildcard-imports` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/borrow_deref_ref_unfixable.stderr b/tests/ui/borrow_deref_ref_unfixable.stderr index 2a21f5ca236f..296af6436934 100644 --- a/tests/ui/borrow_deref_ref_unfixable.stderr +++ b/tests/ui/borrow_deref_ref_unfixable.stderr @@ -15,5 +15,5 @@ help: if you would like to deref, try using `&**` LL | let x: &str = &**s; | ~~~~ -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/char_lit_as_u8.stderr b/tests/ui/char_lit_as_u8.stderr index ce1f2f8296e5..22774d2f9f6d 100644 --- a/tests/ui/char_lit_as_u8.stderr +++ b/tests/ui/char_lit_as_u8.stderr @@ -8,5 +8,5 @@ LL | let _ = '❤' as u8; = note: `-D clippy::char-lit-as-u8` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::char_lit_as_u8)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/cognitive_complexity_attr_used.stderr b/tests/ui/cognitive_complexity_attr_used.stderr index 9cd25f6fda98..b9af72371e6a 100644 --- a/tests/ui/cognitive_complexity_attr_used.stderr +++ b/tests/ui/cognitive_complexity_attr_used.stderr @@ -8,5 +8,5 @@ LL | fn kaboom() { = note: `-D clippy::cognitive-complexity` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::cognitive_complexity)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/copy_iterator.stderr b/tests/ui/copy_iterator.stderr index 48c3385b6c8a..30535db50cc9 100644 --- a/tests/ui/copy_iterator.stderr +++ b/tests/ui/copy_iterator.stderr @@ -14,5 +14,5 @@ LL | | } = note: `-D clippy::copy-iterator` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::copy_iterator)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-10148.stderr b/tests/ui/crashes/ice-10148.stderr index 4d436e3aa04f..ece3e1c39403 100644 --- a/tests/ui/crashes/ice-10148.stderr +++ b/tests/ui/crashes/ice-10148.stderr @@ -9,5 +9,5 @@ LL | println!(with_span!(""something "")); = note: `-D clippy::println-empty-string` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::println_empty_string)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-11422.stderr b/tests/ui/crashes/ice-11422.stderr index fb80b5b147f5..b3dcc00f3d9e 100644 --- a/tests/ui/crashes/ice-11422.stderr +++ b/tests/ui/crashes/ice-11422.stderr @@ -12,5 +12,5 @@ LL - fn gen() -> impl PartialOrd + PartialEq + Debug {} LL + fn gen() -> impl PartialOrd + Debug {} | -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-2774.stderr b/tests/ui/crashes/ice-2774.stderr index ae9610c9acd4..188a5985024e 100644 --- a/tests/ui/crashes/ice-2774.stderr +++ b/tests/ui/crashes/ice-2774.stderr @@ -12,5 +12,5 @@ LL - pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) { LL + pub fn add_barfoos_to_foos(bars: &HashSet<&Bar>) { | -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-3717.stderr b/tests/ui/crashes/ice-3717.stderr index 4d3d617b6937..863608fca8bd 100644 --- a/tests/ui/crashes/ice-3717.stderr +++ b/tests/ui/crashes/ice-3717.stderr @@ -18,5 +18,5 @@ help: ...and use generic constructor LL | let _: HashSet = HashSet::default(); | ~~~~~~~~~~~~~~~~~~ -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-3891.stderr b/tests/ui/crashes/ice-3891.stderr index 59469ec5891c..5358734fed04 100644 --- a/tests/ui/crashes/ice-3891.stderr +++ b/tests/ui/crashes/ice-3891.stderr @@ -6,5 +6,5 @@ LL | 1x; | = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-5497.stderr b/tests/ui/crashes/ice-5497.stderr index e75e7dc91367..ee69f3379b6a 100644 --- a/tests/ui/crashes/ice-5497.stderr +++ b/tests/ui/crashes/ice-5497.stderr @@ -6,5 +6,5 @@ LL | const OOB: i32 = [1][1] + T::OOB; | = note: `#[deny(unconditional_panic)]` on by default -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-5835.stderr b/tests/ui/crashes/ice-5835.stderr index 74d99a348472..1f930e1f6d2c 100644 --- a/tests/ui/crashes/ice-5835.stderr +++ b/tests/ui/crashes/ice-5835.stderr @@ -7,5 +7,5 @@ LL | /// 位 = note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::tabs_in_doc_comments)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-5872.stderr b/tests/ui/crashes/ice-5872.stderr index 75a26ee318c3..d0067a2239e9 100644 --- a/tests/ui/crashes/ice-5872.stderr +++ b/tests/ui/crashes/ice-5872.stderr @@ -7,5 +7,5 @@ LL | let _ = vec![1, 2, 3].into_iter().collect::>().is_empty(); = note: `-D clippy::needless-collect` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_collect)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-6254.stderr b/tests/ui/crashes/ice-6254.stderr index 6ace7dae8bdc..7a34e6cceeea 100644 --- a/tests/ui/crashes/ice-6254.stderr +++ b/tests/ui/crashes/ice-6254.stderr @@ -11,5 +11,5 @@ LL | FOO_REF_REF => {}, = note: `-D indirect-structural-match` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(indirect_structural_match)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-6255.stderr b/tests/ui/crashes/ice-6255.stderr index db0cb25e34a0..bc13319bef02 100644 --- a/tests/ui/crashes/ice-6255.stderr +++ b/tests/ui/crashes/ice-6255.stderr @@ -9,5 +9,5 @@ LL | define_other_core!(); | = note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-6256.stderr b/tests/ui/crashes/ice-6256.stderr index 671933157c80..cba6df194ecc 100644 --- a/tests/ui/crashes/ice-6256.stderr +++ b/tests/ui/crashes/ice-6256.stderr @@ -9,6 +9,6 @@ LL | let f = |x: &dyn TT| x.func(); | | let's call the lifetime of this reference `'1` | `x` is a reference that is only valid in the closure body -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0521`. diff --git a/tests/ui/crashes/ice-7169.stderr b/tests/ui/crashes/ice-7169.stderr index 47947f89baf5..3126de93d224 100644 --- a/tests/ui/crashes/ice-7169.stderr +++ b/tests/ui/crashes/ice-7169.stderr @@ -7,5 +7,5 @@ LL | if let Ok(_) = Ok::<_, ()>(A::::default()) {} = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-7868.stderr b/tests/ui/crashes/ice-7868.stderr index e5f14f2215d7..3315a8d907ae 100644 --- a/tests/ui/crashes/ice-7868.stderr +++ b/tests/ui/crashes/ice-7868.stderr @@ -8,5 +8,5 @@ LL | unsafe { 0 }; = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-7869.stderr b/tests/ui/crashes/ice-7869.stderr index 7acace78a7b2..22f2c7e46fdc 100644 --- a/tests/ui/crashes/ice-7869.stderr +++ b/tests/ui/crashes/ice-7869.stderr @@ -13,5 +13,5 @@ LL | | } = note: `-D clippy::enum-variant-names` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::enum_variant_names)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-8250.stderr b/tests/ui/crashes/ice-8250.stderr index 9c57f334581c..397e978af0bd 100644 --- a/tests/ui/crashes/ice-8250.stderr +++ b/tests/ui/crashes/ice-8250.stderr @@ -7,5 +7,5 @@ LL | let _ = s[1..].splitn(2, '.').next()?; = note: `-D clippy::needless-splitn` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_splitn)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-8821.stderr b/tests/ui/crashes/ice-8821.stderr index c8bd01fb1c64..94ebb20918ed 100644 --- a/tests/ui/crashes/ice-8821.stderr +++ b/tests/ui/crashes/ice-8821.stderr @@ -7,5 +7,5 @@ LL | let _: () = FN(); = note: `-D clippy::let-unit-value` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::let_unit_value)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-9041.stderr b/tests/ui/crashes/ice-9041.stderr index 49c9bdc300ee..00b65f00d787 100644 --- a/tests/ui/crashes/ice-9041.stderr +++ b/tests/ui/crashes/ice-9041.stderr @@ -7,5 +7,5 @@ LL | things.iter().find(|p| is_thing_ready(p)).is_some() = note: `-D clippy::search-is-some` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::search_is_some)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-9445.stderr b/tests/ui/crashes/ice-9445.stderr index 9307409ba585..f97b4536e129 100644 --- a/tests/ui/crashes/ice-9445.stderr +++ b/tests/ui/crashes/ice-9445.stderr @@ -9,5 +9,5 @@ LL | const UNINIT: core::mem::MaybeUninit> = core: = note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::declare_interior_mutable_const)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/ice-96721.stderr b/tests/ui/crashes/ice-96721.stderr index 712bd14c685f..1741c7c6a0a2 100644 --- a/tests/ui/crashes/ice-96721.stderr +++ b/tests/ui/crashes/ice-96721.stderr @@ -4,5 +4,5 @@ error: malformed `path` attribute input LL | #[path = foo!()] | ^^^^^^^^^^^^^^^^ help: must be of the form: `#[path = "file"]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.stderr b/tests/ui/crashes/needless_lifetimes_impl_trait.stderr index 37484f5ebd70..2ebb9d5cd1a1 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.stderr +++ b/tests/ui/crashes/needless_lifetimes_impl_trait.stderr @@ -15,5 +15,5 @@ LL - fn baz<'a>(&'a self) -> impl Foo + 'a { LL + fn baz(&self) -> impl Foo + '_ { | -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr b/tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr index 6d45393996d0..b318f8d3f7af 100644 --- a/tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr +++ b/tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr @@ -12,5 +12,5 @@ LL | struct Foo<'a>(&'a [(); 100]); = note: `-D clippy::needless-pass-by-value` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_value)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crate_in_macro_def.stderr b/tests/ui/crate_in_macro_def.stderr index 3e624618237c..1a21d4e92f24 100644 --- a/tests/ui/crate_in_macro_def.stderr +++ b/tests/ui/crate_in_macro_def.stderr @@ -7,5 +7,5 @@ LL | println!("{}", crate::unhygienic::MESSAGE); = note: `-D clippy::crate-in-macro-def` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::crate_in_macro_def)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crate_level_checks/no_std_swap.stderr b/tests/ui/crate_level_checks/no_std_swap.stderr index 01033246dd90..7ef8d08d5d69 100644 --- a/tests/ui/crate_level_checks/no_std_swap.stderr +++ b/tests/ui/crate_level_checks/no_std_swap.stderr @@ -11,5 +11,5 @@ LL | | b = a; = note: `-D clippy::almost-swapped` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::almost_swapped)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/crate_level_checks/std_main_recursion.stderr b/tests/ui/crate_level_checks/std_main_recursion.stderr index f3ffd6a10c71..3bc406206e4b 100644 --- a/tests/ui/crate_level_checks/std_main_recursion.stderr +++ b/tests/ui/crate_level_checks/std_main_recursion.stderr @@ -8,5 +8,5 @@ LL | main(); = note: `-D clippy::main-recursion` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::main_recursion)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/def_id_nocore.stderr b/tests/ui/def_id_nocore.stderr index bfd0de4e13ac..6a00331ec69f 100644 --- a/tests/ui/def_id_nocore.stderr +++ b/tests/ui/def_id_nocore.stderr @@ -8,5 +8,5 @@ LL | pub fn as_ref(self) -> &'static str { = note: `-D clippy::wrong-self-convention` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::wrong_self_convention)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/doc_link_with_quotes.stderr b/tests/ui/doc_link_with_quotes.stderr index 2db1bc092895..e1883f349b02 100644 --- a/tests/ui/doc_link_with_quotes.stderr +++ b/tests/ui/doc_link_with_quotes.stderr @@ -7,5 +7,5 @@ LL | /// Calls ['bar'] uselessly = note: `-D clippy::doc-link-with-quotes` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::doc_link_with_quotes)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/double_neg.stderr b/tests/ui/double_neg.stderr index a6241c78610a..a4fa1688d577 100644 --- a/tests/ui/double_neg.stderr +++ b/tests/ui/double_neg.stderr @@ -7,5 +7,5 @@ LL | --x; = note: `-D clippy::double-neg` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::double_neg)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/duplicate_underscore_argument.stderr b/tests/ui/duplicate_underscore_argument.stderr index f47f6c89622d..53ee0c4e8c89 100644 --- a/tests/ui/duplicate_underscore_argument.stderr +++ b/tests/ui/duplicate_underscore_argument.stderr @@ -7,5 +7,5 @@ LL | fn join_the_dark_side(darth: i32, _darth: i32) {} = note: `-D clippy::duplicate-underscore-argument` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::duplicate_underscore_argument)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/empty_enum.stderr b/tests/ui/empty_enum.stderr index 92d81c7269a5..c9bd887643e9 100644 --- a/tests/ui/empty_enum.stderr +++ b/tests/ui/empty_enum.stderr @@ -8,5 +8,5 @@ LL | enum Empty {} = note: `-D clippy::empty-enum` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::empty_enum)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/entry_btree.stderr b/tests/ui/entry_btree.stderr index cc0e951d9b42..63e9a0af8b6b 100644 --- a/tests/ui/entry_btree.stderr +++ b/tests/ui/entry_btree.stderr @@ -17,5 +17,5 @@ LL + foo(); LL + } | -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/exit1.stderr b/tests/ui/exit1.stderr index 94d8f1e32ee1..bbe0762c8d12 100644 --- a/tests/ui/exit1.stderr +++ b/tests/ui/exit1.stderr @@ -7,5 +7,5 @@ LL | std::process::exit(4); = note: `-D clippy::exit` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::exit)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/exit2.stderr b/tests/ui/exit2.stderr index cd324f182205..19abbc6062a6 100644 --- a/tests/ui/exit2.stderr +++ b/tests/ui/exit2.stderr @@ -7,5 +7,5 @@ LL | std::process::exit(3); = note: `-D clippy::exit` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::exit)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/filter_map_next.stderr b/tests/ui/filter_map_next.stderr index 1841553917ff..07760d8837a3 100644 --- a/tests/ui/filter_map_next.stderr +++ b/tests/ui/filter_map_next.stderr @@ -14,5 +14,5 @@ LL | | .next(); = note: `-D clippy::filter-map-next` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::filter_map_next)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/four_forward_slashes_first_line.stderr b/tests/ui/four_forward_slashes_first_line.stderr index afb7c6b4dbda..f49b7a0977fe 100644 --- a/tests/ui/four_forward_slashes_first_line.stderr +++ b/tests/ui/four_forward_slashes_first_line.stderr @@ -12,5 +12,5 @@ help: make this a doc comment by removing one `/` LL + /// borked doc comment on the first line. doesn't combust! | -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/functions_maxlines.stderr b/tests/ui/functions_maxlines.stderr index 1d6ddad79ff2..497acc0a65ea 100644 --- a/tests/ui/functions_maxlines.stderr +++ b/tests/ui/functions_maxlines.stderr @@ -13,5 +13,5 @@ LL | | } = note: `-D clippy::too-many-lines` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::too_many_lines)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/index_refutable_slice/slice_indexing_in_macro.stderr b/tests/ui/index_refutable_slice/slice_indexing_in_macro.stderr index 11b19428b4fd..429861e993e8 100644 --- a/tests/ui/index_refutable_slice/slice_indexing_in_macro.stderr +++ b/tests/ui/index_refutable_slice/slice_indexing_in_macro.stderr @@ -18,5 +18,5 @@ help: and replace the index expressions here LL | println!("{}", slice_0); | ~~~~~~~ -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/inspect_for_each.stderr b/tests/ui/inspect_for_each.stderr index 80df86ad64ec..8bd4fe3987c5 100644 --- a/tests/ui/inspect_for_each.stderr +++ b/tests/ui/inspect_for_each.stderr @@ -14,5 +14,5 @@ LL | | }); = note: `-D clippy::inspect-for-each` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::inspect_for_each)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/issue-3145.stderr b/tests/ui/issue-3145.stderr index d7c2c88a2047..51debc9b72f8 100644 --- a/tests/ui/issue-3145.stderr +++ b/tests/ui/issue-3145.stderr @@ -4,5 +4,5 @@ error: expected `,`, found `a` LL | println!("{}" a); | ^ expected `,` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/issue_2356.stderr b/tests/ui/issue_2356.stderr index d04b49e52a55..860c545c7b82 100644 --- a/tests/ui/issue_2356.stderr +++ b/tests/ui/issue_2356.stderr @@ -10,5 +10,5 @@ note: the lint level is defined here LL | #![deny(clippy::while_let_on_iterator)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/items_after_test_module/in_submodule.stderr b/tests/ui/items_after_test_module/in_submodule.stderr index 4e99876365cf..30aa90d29bf8 100644 --- a/tests/ui/items_after_test_module/in_submodule.stderr +++ b/tests/ui/items_after_test_module/in_submodule.stderr @@ -10,5 +10,5 @@ LL | fn in_submodule() {} = note: `-D clippy::items-after-test-module` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::items_after_test_module)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/items_after_test_module/root_module.stderr b/tests/ui/items_after_test_module/root_module.stderr index 67bc82ebff91..17b07cc32f4e 100644 --- a/tests/ui/items_after_test_module/root_module.stderr +++ b/tests/ui/items_after_test_module/root_module.stderr @@ -16,5 +16,5 @@ LL | macro_rules! should_lint { = help: to override `-D warnings` add `#[allow(clippy::items_after_test_module)]` = help: move the items to before the test module was defined -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/iter_next_loop.stderr b/tests/ui/iter_next_loop.stderr index 5bba0e635bba..5871d21e4915 100644 --- a/tests/ui/iter_next_loop.stderr +++ b/tests/ui/iter_next_loop.stderr @@ -4,6 +4,6 @@ error[E0423]: expected value, found macro `vec` LL | for _ in vec.iter().next() {} | ^^^ not a value -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0423`. diff --git a/tests/ui/manual_non_exhaustive_enum.stderr b/tests/ui/manual_non_exhaustive_enum.stderr index 7361a4a2cbbe..d2922af99bf7 100644 --- a/tests/ui/manual_non_exhaustive_enum.stderr +++ b/tests/ui/manual_non_exhaustive_enum.stderr @@ -22,5 +22,5 @@ LL | _C, = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::manual_non_exhaustive)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/map_err.stderr b/tests/ui/map_err.stderr index 6a845c84a2a9..eb6742ff2338 100644 --- a/tests/ui/map_err.stderr +++ b/tests/ui/map_err.stderr @@ -8,5 +8,5 @@ LL | println!("{:?}", x.map_err(|_| Errors::Ignored)); = note: `-D clippy::map-err-ignore` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::map_err_ignore)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/mem_replace_macro.stderr b/tests/ui/mem_replace_macro.stderr index 842ad3a8565c..c6435e94e967 100644 --- a/tests/ui/mem_replace_macro.stderr +++ b/tests/ui/mem_replace_macro.stderr @@ -8,5 +8,5 @@ LL | inline!(std::mem::replace($s, Default::default())); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]` = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/methods_fixable.stderr b/tests/ui/methods_fixable.stderr index 1bfe56d912b7..f290c20e5e98 100644 --- a/tests/ui/methods_fixable.stderr +++ b/tests/ui/methods_fixable.stderr @@ -7,5 +7,5 @@ LL | let _ = v.iter().filter(|&x| *x < 0).next(); = note: `-D clippy::filter-next` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::filter_next)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/methods_unfixable.stderr b/tests/ui/methods_unfixable.stderr index 581a985e0b57..771e10cbe105 100644 --- a/tests/ui/methods_unfixable.stderr +++ b/tests/ui/methods_unfixable.stderr @@ -12,5 +12,5 @@ LL | let iter = (0..10); = note: `-D clippy::filter-next` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::filter_next)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/missing_doc_crate_missing.stderr b/tests/ui/missing_doc_crate_missing.stderr index c684bc8e7072..3aa9781c2f1d 100644 --- a/tests/ui/missing_doc_crate_missing.stderr +++ b/tests/ui/missing_doc_crate_missing.stderr @@ -11,5 +11,5 @@ LL | | fn main() {} = note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/missing_spin_loop_no_std.stderr b/tests/ui/missing_spin_loop_no_std.stderr index 0b7be4616511..d84d06088ba3 100644 --- a/tests/ui/missing_spin_loop_no_std.stderr +++ b/tests/ui/missing_spin_loop_no_std.stderr @@ -7,5 +7,5 @@ LL | while b.load(Ordering::Acquire) {} = note: `-D clippy::missing-spin-loop` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::missing_spin_loop)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/mut_mutex_lock.stderr b/tests/ui/mut_mutex_lock.stderr index 9b20016be799..819602882766 100644 --- a/tests/ui/mut_mutex_lock.stderr +++ b/tests/ui/mut_mutex_lock.stderr @@ -7,5 +7,5 @@ LL | let mut value = value_mutex.lock().unwrap(); = note: `-D clippy::mut-mutex-lock` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::mut_mutex_lock)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/needless_arbitrary_self_type_unfixable.stderr b/tests/ui/needless_arbitrary_self_type_unfixable.stderr index 183e2dbc8c16..e91359a3cc18 100644 --- a/tests/ui/needless_arbitrary_self_type_unfixable.stderr +++ b/tests/ui/needless_arbitrary_self_type_unfixable.stderr @@ -7,5 +7,5 @@ LL | fn call_with_mut_self(self: &mut Self) {} = note: `-D clippy::needless-arbitrary-self-type` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_arbitrary_self_type)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/needless_bitwise_bool.stderr b/tests/ui/needless_bitwise_bool.stderr index 2ed9208e6230..b1fc1a7a9585 100644 --- a/tests/ui/needless_bitwise_bool.stderr +++ b/tests/ui/needless_bitwise_bool.stderr @@ -7,5 +7,5 @@ LL | if y & !x { = note: `-D clippy::needless-bitwise-bool` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_bitwise_bool)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/needless_else.stderr b/tests/ui/needless_else.stderr index e6f7138e948d..66552109c48e 100644 --- a/tests/ui/needless_else.stderr +++ b/tests/ui/needless_else.stderr @@ -9,5 +9,5 @@ LL | | } = note: `-D clippy::needless-else` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_else)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/needless_for_each_unfixable.stderr b/tests/ui/needless_for_each_unfixable.stderr index 73f249ae6c2f..24a22e232485 100644 --- a/tests/ui/needless_for_each_unfixable.stderr +++ b/tests/ui/needless_for_each_unfixable.stderr @@ -29,5 +29,5 @@ help: ...and replace `return` with `continue` LL | continue; | ~~~~~~~~ -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/needless_option_take.stderr b/tests/ui/needless_option_take.stderr index d3c22441d003..bf43a18e7115 100644 --- a/tests/ui/needless_option_take.stderr +++ b/tests/ui/needless_option_take.stderr @@ -7,5 +7,5 @@ LL | x.as_ref().take(); = note: `-D clippy::needless-option-take` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_option_take)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/needless_return_with_question_mark.stderr b/tests/ui/needless_return_with_question_mark.stderr index 580970a41aa9..707f1c25327a 100644 --- a/tests/ui/needless_return_with_question_mark.stderr +++ b/tests/ui/needless_return_with_question_mark.stderr @@ -7,5 +7,5 @@ LL | return Err(())?; = note: `-D clippy::needless-return-with-question-mark` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_return_with_question_mark)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/needless_update.stderr b/tests/ui/needless_update.stderr index 3e9e2941a7a7..60aeb0493870 100644 --- a/tests/ui/needless_update.stderr +++ b/tests/ui/needless_update.stderr @@ -7,5 +7,5 @@ LL | S { a: 1, b: 1, ..base }; = note: `-D clippy::needless-update` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_update)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/new_ret_no_self_overflow.stderr b/tests/ui/new_ret_no_self_overflow.stderr index babb634fdcd1..c0d6a74a51de 100644 --- a/tests/ui/new_ret_no_self_overflow.stderr +++ b/tests/ui/new_ret_no_self_overflow.stderr @@ -4,6 +4,6 @@ error[E0275]: overflow evaluating the requirement `::Outpu LL | pub fn new() -> X { | ^ -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/non_minimal_cfg2.stderr b/tests/ui/non_minimal_cfg2.stderr index 001fcddd9068..036d38c22f48 100644 --- a/tests/ui/non_minimal_cfg2.stderr +++ b/tests/ui/non_minimal_cfg2.stderr @@ -7,5 +7,5 @@ LL | #[cfg(all())] = note: `-D clippy::non-minimal-cfg` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::non_minimal_cfg)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/obfuscated_if_else.stderr b/tests/ui/obfuscated_if_else.stderr index ca9f5e1e374c..abf5adce4446 100644 --- a/tests/ui/obfuscated_if_else.stderr +++ b/tests/ui/obfuscated_if_else.stderr @@ -7,5 +7,5 @@ LL | true.then_some("a").unwrap_or("b"); = note: `-D clippy::obfuscated-if-else` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::obfuscated_if_else)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/partialeq_ne_impl.stderr b/tests/ui/partialeq_ne_impl.stderr index 163d6b1dd7b6..2210e706d930 100644 --- a/tests/ui/partialeq_ne_impl.stderr +++ b/tests/ui/partialeq_ne_impl.stderr @@ -11,5 +11,5 @@ LL | | } = note: `-D clippy::partialeq-ne-impl` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::partialeq_ne_impl)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/path_buf_push_overwrite.stderr b/tests/ui/path_buf_push_overwrite.stderr index 1453d020c412..f96ce0de7793 100644 --- a/tests/ui/path_buf_push_overwrite.stderr +++ b/tests/ui/path_buf_push_overwrite.stderr @@ -7,5 +7,5 @@ LL | x.push("/bar"); = note: `-D clippy::path-buf-push-overwrite` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::path_buf_push_overwrite)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/permissions_set_readonly_false.stderr b/tests/ui/permissions_set_readonly_false.stderr index 58a7de84d8f0..bd34463084a4 100644 --- a/tests/ui/permissions_set_readonly_false.stderr +++ b/tests/ui/permissions_set_readonly_false.stderr @@ -10,5 +10,5 @@ LL | permissions.set_readonly(false); = note: `-D clippy::permissions-set-readonly-false` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::permissions_set_readonly_false)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/proc_macro.stderr b/tests/ui/proc_macro.stderr index d912b5027551..122374ea804d 100644 --- a/tests/ui/proc_macro.stderr +++ b/tests/ui/proc_macro.stderr @@ -7,5 +7,5 @@ LL | let _x = 3.14; = help: consider using the constant directly = note: `#[deny(clippy::approx_constant)]` on by default -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/pub_use.stderr b/tests/ui/pub_use.stderr index 781572736645..f6f5db9a1800 100644 --- a/tests/ui/pub_use.stderr +++ b/tests/ui/pub_use.stderr @@ -8,5 +8,5 @@ LL | pub use inner::Test; = note: `-D clippy::pub-use` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::pub_use)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/question_mark_used.stderr b/tests/ui/question_mark_used.stderr index a3f440de80a5..b4e256ddb9eb 100644 --- a/tests/ui/question_mark_used.stderr +++ b/tests/ui/question_mark_used.stderr @@ -8,5 +8,5 @@ LL | other_function()?; = note: `-D clippy::question-mark-used` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::question_mark_used)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/range.stderr b/tests/ui/range.stderr index 9f174307b829..78ef17b5ba79 100644 --- a/tests/ui/range.stderr +++ b/tests/ui/range.stderr @@ -7,5 +7,5 @@ LL | let _x = v1.iter().zip(0..v1.len()); = note: `-D clippy::range-zip-with-len` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::range_zip_with_len)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/renamed_builtin_attr.stderr b/tests/ui/renamed_builtin_attr.stderr index 636d88fcd69c..662188bbabc5 100644 --- a/tests/ui/renamed_builtin_attr.stderr +++ b/tests/ui/renamed_builtin_attr.stderr @@ -4,5 +4,5 @@ error: usage of deprecated attribute LL | #[clippy::cyclomatic_complexity = "1"] | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `cognitive_complexity` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/result_map_or_into_option.stderr b/tests/ui/result_map_or_into_option.stderr index 9396ea4c064e..12de3b460882 100644 --- a/tests/ui/result_map_or_into_option.stderr +++ b/tests/ui/result_map_or_into_option.stderr @@ -7,5 +7,5 @@ LL | let _ = opt.map_or(None, Some); = note: `-D clippy::result-map-or-into-option` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::result_map_or_into_option)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/seek_from_current.stderr b/tests/ui/seek_from_current.stderr index 42eb342c10aa..4858cb82e7eb 100644 --- a/tests/ui/seek_from_current.stderr +++ b/tests/ui/seek_from_current.stderr @@ -7,5 +7,5 @@ LL | f.seek(SeekFrom::Current(0))?; = note: `-D clippy::seek-from-current` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::seek_from_current)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/self_named_constructors.stderr b/tests/ui/self_named_constructors.stderr index f299b860d478..8083ff965157 100644 --- a/tests/ui/self_named_constructors.stderr +++ b/tests/ui/self_named_constructors.stderr @@ -11,5 +11,5 @@ LL | | } = note: `-D clippy::self-named-constructors` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::self_named_constructors)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/serde.stderr b/tests/ui/serde.stderr index e5d64e271644..079ba42bd2bc 100644 --- a/tests/ui/serde.stderr +++ b/tests/ui/serde.stderr @@ -13,5 +13,5 @@ LL | | } = note: `-D clippy::serde-api-misuse` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::serde_api_misuse)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/should_panic_without_expect.stderr b/tests/ui/should_panic_without_expect.stderr index dfcef52a9f5f..b13db83bd5c7 100644 --- a/tests/ui/should_panic_without_expect.stderr +++ b/tests/ui/should_panic_without_expect.stderr @@ -10,5 +10,5 @@ note: the lint level is defined here LL | #![deny(clippy::should_panic_without_expect)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/string_from_utf8_as_bytes.stderr b/tests/ui/string_from_utf8_as_bytes.stderr index cf5688a97824..4738bef3ae9e 100644 --- a/tests/ui/string_from_utf8_as_bytes.stderr +++ b/tests/ui/string_from_utf8_as_bytes.stderr @@ -7,5 +7,5 @@ LL | let _ = std::str::from_utf8(&"Hello World!".as_bytes()[6..11]); = note: `-D clippy::string-from-utf8-as-bytes` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::string_from_utf8_as_bytes)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/string_to_string.stderr b/tests/ui/string_to_string.stderr index 27a84431507b..f1f8e176bc57 100644 --- a/tests/ui/string_to_string.stderr +++ b/tests/ui/string_to_string.stderr @@ -8,5 +8,5 @@ LL | let mut v = message.to_string(); = note: `-D clippy::string-to-string` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::string_to_string)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/tests_outside_test_module.stderr b/tests/ui/tests_outside_test_module.stderr index 112d6ce1f2c4..ec0cdea83d65 100644 --- a/tests/ui/tests_outside_test_module.stderr +++ b/tests/ui/tests_outside_test_module.stderr @@ -8,5 +8,5 @@ LL | fn my_test() {} = note: `-D clippy::tests-outside-test-module` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::tests_outside_test_module)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/track-diagnostics.stderr b/tests/ui/track-diagnostics.stderr index 39418d359288..131adfd588c2 100644 --- a/tests/ui/track-diagnostics.stderr +++ b/tests/ui/track-diagnostics.stderr @@ -5,6 +5,6 @@ LL | const S: A = B; | ^ expected `A`, found `B` -Ztrack-diagnostics: created at compiler/rustc_infer/src/infer/error_reporting/mod.rs:LL:CC -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/types.stderr b/tests/ui/types.stderr index b253cf33867f..f7473e1c5c52 100644 --- a/tests/ui/types.stderr +++ b/tests/ui/types.stderr @@ -7,5 +7,5 @@ LL | let c_i64: i64 = c as i64; = note: `-D clippy::cast-lossless` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/uninlined_format_args_panic.edition2018.stderr b/tests/ui/uninlined_format_args_panic.edition2018.stderr index 221efeb50cd9..736a68ab1c7e 100644 --- a/tests/ui/uninlined_format_args_panic.edition2018.stderr +++ b/tests/ui/uninlined_format_args_panic.edition2018.stderr @@ -12,5 +12,5 @@ LL - println!("val='{}'", var); LL + println!("val='{var}'"); | -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/unknown_attribute.stderr b/tests/ui/unknown_attribute.stderr index 618c5980d64e..edad35d1591b 100644 --- a/tests/ui/unknown_attribute.stderr +++ b/tests/ui/unknown_attribute.stderr @@ -4,5 +4,5 @@ error: usage of unknown attribute LL | #[clippy::unknown] | ^^^^^^^ -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/vec_resize_to_zero.stderr b/tests/ui/vec_resize_to_zero.stderr index 715c9923b2e5..c16ba4e52627 100644 --- a/tests/ui/vec_resize_to_zero.stderr +++ b/tests/ui/vec_resize_to_zero.stderr @@ -10,5 +10,5 @@ LL | v.resize(0, 5); = note: `-D clippy::vec-resize-to-zero` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::vec_resize_to_zero)]` -error: aborting due to previous error +error: aborting due to 1 previous error From 5d394e708c7786b9bda339be011db73e333eaab1 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Tue, 21 Nov 2023 20:26:31 +0100 Subject: [PATCH 0990/1222] Manual find replace updates --- tests/ui-internal/default_deprecation_reason.stderr | 2 +- tests/ui-internal/default_lint.stderr | 2 +- tests/ui-internal/lint_without_lint_pass.stderr | 2 +- tests/ui-internal/outer_expn_data.stderr | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ui-internal/default_deprecation_reason.stderr b/tests/ui-internal/default_deprecation_reason.stderr index ca26b649f986..595e4c138b47 100644 --- a/tests/ui-internal/default_deprecation_reason.stderr +++ b/tests/ui-internal/default_deprecation_reason.stderr @@ -18,5 +18,5 @@ LL | #![deny(clippy::internal)] = note: `#[deny(clippy::default_deprecation_reason)]` implied by `#[deny(clippy::internal)]` = note: this error originates in the macro `declare_deprecated_lint` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-internal/default_lint.stderr b/tests/ui-internal/default_lint.stderr index 8961bd4624f4..ab2470210254 100644 --- a/tests/ui-internal/default_lint.stderr +++ b/tests/ui-internal/default_lint.stderr @@ -17,5 +17,5 @@ LL | #![deny(clippy::internal)] = note: `#[deny(clippy::default_lint)]` implied by `#[deny(clippy::internal)]` = note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-internal/lint_without_lint_pass.stderr b/tests/ui-internal/lint_without_lint_pass.stderr index de04920b8e6f..de55876b1d70 100644 --- a/tests/ui-internal/lint_without_lint_pass.stderr +++ b/tests/ui-internal/lint_without_lint_pass.stderr @@ -17,5 +17,5 @@ LL | #![deny(clippy::internal)] = note: `#[deny(clippy::lint_without_lint_pass)]` implied by `#[deny(clippy::internal)]` = note: this error originates in the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui-internal/outer_expn_data.stderr b/tests/ui-internal/outer_expn_data.stderr index e41ace4729d8..0d5b01325994 100644 --- a/tests/ui-internal/outer_expn_data.stderr +++ b/tests/ui-internal/outer_expn_data.stderr @@ -11,5 +11,5 @@ LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ = note: `#[deny(clippy::outer_expn_expn_data)]` implied by `#[deny(clippy::internal)]` -error: aborting due to previous error +error: aborting due to 1 previous error From 4a1c98256ff22f25abb9f2966c0c7f3b9079bd8a Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 24 Nov 2023 00:49:02 +0300 Subject: [PATCH 0991/1222] rustc: Make `def_kind` mandatory for all `DefId`s --- clippy_lints/src/unused_async.rs | 2 +- clippy_lints/src/useless_conversion.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index aea72c798be7..780ece3677df 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -148,7 +148,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync { // statements, so don't lint at all if there are any such paths. if let Some(def_id) = path.res.opt_def_id() && let Some(local_def_id) = def_id.as_local() - && let Some(DefKind::Fn) = cx.tcx.opt_def_kind(def_id) + && cx.tcx.def_kind(def_id) == DefKind::Fn && cx.tcx.asyncness(def_id).is_async() && !is_node_func_call(cx.tcx.hir().get_parent(hir_id), path.span) { diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 52327b82e849..7aed1d6e30b4 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -4,7 +4,6 @@ use clippy_utils::sugg::Sugg; use clippy_utils::ty::{is_copy, is_type_diagnostic_item, same_type_and_consts}; use clippy_utils::{get_parent_expr, is_trait_method, is_ty_alias, path_to_local}; use rustc_errors::Applicability; -use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_hir::{BindingAnnotation, Expr, ExprKind, HirId, MatchSource, Node, PatKind}; use rustc_infer::infer::TyCtxtInferExt; @@ -208,7 +207,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { && let Some(did) = cx.qpath_res(qpath, recv.hir_id).opt_def_id() // make sure that the path indeed points to a fn-like item, so that // `fn_sig` does not ICE. (see #11065) - && cx.tcx.opt_def_kind(did).is_some_and(DefKind::is_fn_like) => + && cx.tcx.def_kind(did).is_fn_like() => { Some(( did, From cba9c63aae240b0c886bdbadcbe4a9d616153c7d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 23 Nov 2023 06:17:43 +0000 Subject: [PATCH 0992/1222] Appease the clippy --- clippy_lints/src/methods/clone_on_copy.rs | 2 +- clippy_lints/src/returns.rs | 2 +- clippy_lints/src/unnecessary_map_on_constructor.rs | 2 +- clippy_utils/src/ty/type_certainty/mod.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/methods/clone_on_copy.rs b/clippy_lints/src/methods/clone_on_copy.rs index eb4f003d38ae..532bbbeaf032 100644 --- a/clippy_lints/src/methods/clone_on_copy.rs +++ b/clippy_lints/src/methods/clone_on_copy.rs @@ -61,7 +61,7 @@ pub(super) fn check( // ? is a Call, makes sure not to rec *x?, but rather (*x)? ExprKind::Call(hir_callee, _) => matches!( hir_callee.kind, - ExprKind::Path(QPath::LangItem(rustc_hir::LangItem::TryTraitBranch, _, _)) + ExprKind::Path(QPath::LangItem(rustc_hir::LangItem::TryTraitBranch, ..)) ), ExprKind::MethodCall(_, self_arg, ..) if expr.hir_id == self_arg.hir_id => true, ExprKind::Match(_, _, MatchSource::TryDesugar(_) | MatchSource::AwaitDesugar) diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 8595205691b9..14c103e70472 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -309,7 +309,7 @@ fn check_final_expr<'tcx>( let replacement = if let Some(inner_expr) = inner { // if desugar of `do yeet`, don't lint if let ExprKind::Call(path_expr, _) = inner_expr.kind - && let ExprKind::Path(QPath::LangItem(LangItem::TryTraitFromYeet, _, _)) = path_expr.kind + && let ExprKind::Path(QPath::LangItem(LangItem::TryTraitFromYeet, ..)) = path_expr.kind { return; } diff --git a/clippy_lints/src/unnecessary_map_on_constructor.rs b/clippy_lints/src/unnecessary_map_on_constructor.rs index 06c017ea15ab..25a9db36d5c7 100644 --- a/clippy_lints/src/unnecessary_map_on_constructor.rs +++ b/clippy_lints/src/unnecessary_map_on_constructor.rs @@ -59,7 +59,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMapOnConstructor { } }, hir::QPath::TypeRelative(_, path) => path.ident.name, - hir::QPath::LangItem(_, _, _) => return, + hir::QPath::LangItem(..) => return, }; match constructor_symbol { sym::Some | sym::Ok if path.ident.name == rustc_span::sym::map => (), diff --git a/clippy_utils/src/ty/type_certainty/mod.rs b/clippy_utils/src/ty/type_certainty/mod.rs index 76fa15e15880..c325e4eae21f 100644 --- a/clippy_utils/src/ty/type_certainty/mod.rs +++ b/clippy_utils/src/ty/type_certainty/mod.rs @@ -170,7 +170,7 @@ fn qpath_certainty(cx: &LateContext<'_>, qpath: &QPath<'_>, resolves_to_type: bo path_segment_certainty(cx, type_certainty(cx, ty), path_segment, resolves_to_type) }, - QPath::LangItem(lang_item, _, _) => { + QPath::LangItem(lang_item, ..) => { cx.tcx .lang_items() .get(*lang_item) From 375f7fa0fc9c163f41674a56750999beb70ca0fd Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 24 Nov 2023 19:28:19 +0300 Subject: [PATCH 0993/1222] rustc: `hir().local_def_id_to_hir_id()` -> `tcx.local_def_id_to_hir_id()` cleanup --- clippy_lints/src/derive.rs | 6 +++--- clippy_lints/src/error_impl_error.rs | 2 +- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/excessive_bools.rs | 2 +- clippy_lints/src/functions/mod.rs | 2 +- clippy_lints/src/future_not_send.rs | 2 +- clippy_lints/src/inherent_impl.rs | 4 ++-- clippy_lints/src/len_zero.rs | 2 +- clippy_lints/src/manual_non_exhaustive.rs | 2 +- clippy_lints/src/methods/filter_map_bool_then.rs | 2 +- clippy_lints/src/missing_const_for_fn.rs | 2 +- clippy_lints/src/needless_pass_by_ref_mut.rs | 4 ++-- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/new_without_default.rs | 4 ++-- clippy_lints/src/non_send_fields_in_send_ty.rs | 2 +- clippy_lints/src/panic_in_result_fn.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/return_self_not_must_use.rs | 2 +- clippy_lints/src/self_named_constructors.rs | 2 +- clippy_lints/src/types/mod.rs | 2 +- clippy_lints/src/undocumented_unsafe_blocks.rs | 4 ++-- clippy_lints/src/unnecessary_wraps.rs | 2 +- clippy_utils/src/lib.rs | 6 +++--- clippy_utils/src/ty.rs | 2 +- 24 files changed, 32 insertions(+), 32 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 169c2a15db71..64573ac4d53d 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -255,7 +255,7 @@ fn check_hash_peq<'tcx>( "you are deriving `Hash` but have implemented `PartialEq` explicitly", |diag| { if let Some(local_def_id) = impl_id.as_local() { - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id); + let hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id); diag.span_note(cx.tcx.hir().span(hir_id), "`PartialEq` implemented here"); } }, @@ -299,7 +299,7 @@ fn check_ord_partial_ord<'tcx>( span_lint_and_then(cx, DERIVE_ORD_XOR_PARTIAL_ORD, span, mess, |diag| { if let Some(local_def_id) = impl_id.as_local() { - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id); + let hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id); diag.span_note(cx.tcx.hir().span(hir_id), "`PartialOrd` implemented here"); } }); @@ -381,7 +381,7 @@ fn check_unsafe_derive_deserialize<'tcx>( && match_def_path(cx, trait_def_id, &paths::SERDE_DESERIALIZE) && let ty::Adt(def, _) = ty.kind() && 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) + && let adt_hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id) && !is_lint_allowed(cx, UNSAFE_DERIVE_DESERIALIZE, adt_hir_id) && cx .tcx diff --git a/clippy_lints/src/error_impl_error.rs b/clippy_lints/src/error_impl_error.rs index bc878555c66d..35b1d3f9bab0 100644 --- a/clippy_lints/src/error_impl_error.rs +++ b/clippy_lints/src/error_impl_error.rs @@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for ErrorImplError { if let Some(trait_def_id) = imp.of_trait.and_then(|t| t.trait_def_id()) && error_def_id == trait_def_id && let Some(def_id) = path_res(cx, imp.self_ty).opt_def_id().and_then(DefId::as_local) - && let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id) + && let hir_id = cx.tcx.local_def_id_to_hir_id(def_id) && let Some(ident) = cx.tcx.opt_item_ident(def_id.to_def_id()) && ident.name == sym::Error && is_visible_outside_module(cx, def_id) => diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 2f22f344a21b..af2d1c27d433 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { let parent_id = cx .tcx .hir() - .get_parent_item(cx.tcx.hir().local_def_id_to_hir_id(fn_def_id)) + .get_parent_item(cx.tcx.local_def_id_to_hir_id(fn_def_id)) .def_id; let parent_node = cx.tcx.hir().find_by_def_id(parent_id); diff --git a/clippy_lints/src/excessive_bools.rs b/clippy_lints/src/excessive_bools.rs index 1d18e194d15c..713957bff51a 100644 --- a/clippy_lints/src/excessive_bools.rs +++ b/clippy_lints/src/excessive_bools.rs @@ -171,7 +171,7 @@ impl<'tcx> LateLintPass<'tcx> for ExcessiveBools { span: Span, def_id: LocalDefId, ) { - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); + let hir_id = cx.tcx.local_def_id_to_hir_id(def_id); if let Some(fn_header) = fn_kind.header() && fn_header.abi == Abi::Rust && get_parent_as_impl(cx.tcx, hir_id).map_or(true, |impl_item| impl_item.of_trait.is_none()) diff --git a/clippy_lints/src/functions/mod.rs b/clippy_lints/src/functions/mod.rs index 3f5cceec70ed..bfd73debd76f 100644 --- a/clippy_lints/src/functions/mod.rs +++ b/clippy_lints/src/functions/mod.rs @@ -407,7 +407,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions { span: Span, def_id: LocalDefId, ) { - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); + let hir_id = cx.tcx.local_def_id_to_hir_id(def_id); too_many_arguments::check_fn(cx, kind, decl, span, hir_id, self.too_many_arguments_threshold); too_many_lines::check_fn(cx, kind, span, body, self.too_many_lines_threshold); not_unsafe_ptr_arg_deref::check_fn(cx, kind, decl, body, def_id); diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index eee5b7540ba7..ded90f5f9110 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { if let FnKind::Closure = kind { return; } - let ret_ty = return_ty(cx, cx.tcx.hir().local_def_id_to_hir_id(fn_def_id).expect_owner()); + let ret_ty = return_ty(cx, cx.tcx.local_def_id_to_hir_id(fn_def_id).expect_owner()); if let ty::Alias(ty::Opaque, AliasTy { def_id, args, .. }) = *ret_ty.kind() { let preds = cx.tcx.explicit_item_bounds(def_id); let mut is_future = false; diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index a61a64161930..aa732980b1ff 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -63,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { && !is_lint_allowed( cx, MULTIPLE_INHERENT_IMPL, - cx.tcx.hir().local_def_id_to_hir_id(id), + cx.tcx.local_def_id_to_hir_id(id), ) }) { for impl_id in impl_ids.iter().map(|id| id.expect_local()) { @@ -117,7 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { /// Gets the span for the given impl block unless it's not being considered by the lint. fn get_impl_span(cx: &LateContext<'_>, id: LocalDefId) -> Option { - let id = cx.tcx.hir().local_def_id_to_hir_id(id); + let id = cx.tcx.local_def_id_to_hir_id(id); if let Node::Item(&Item { kind: ItemKind::Impl(impl_item), span, diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 6fc14dd89417..8c6ef81ccedf 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -142,7 +142,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero { && let TyKind::Path(ty_path) = &imp.self_ty.kind && let Some(ty_id) = cx.qpath_res(ty_path, imp.self_ty.hir_id).opt_def_id() && let Some(local_id) = ty_id.as_local() - && let ty_hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_id) + && let ty_hir_id = cx.tcx.local_def_id_to_hir_id(local_id) && !is_lint_allowed(cx, LEN_WITHOUT_IS_EMPTY, ty_hir_id) && let Some(output) = parse_len_output(cx, cx.tcx.fn_sig(item.owner_id).instantiate_identity().skip_binder()) diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index fc8f23630013..79cc98bfb7fa 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -192,7 +192,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum { .contains(&(enum_id.to_def_id(), variant_id.to_def_id())) }) { - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(enum_id); + let hir_id = cx.tcx.local_def_id_to_hir_id(enum_id); span_lint_hir_and_then( cx, MANUAL_NON_EXHAUSTIVE, diff --git a/clippy_lints/src/methods/filter_map_bool_then.rs b/clippy_lints/src/methods/filter_map_bool_then.rs index 9950c4428551..2e43d19a6991 100644 --- a/clippy_lints/src/methods/filter_map_bool_then.rs +++ b/clippy_lints/src/methods/filter_map_bool_then.rs @@ -27,7 +27,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: & closure.def_id.to_def_id(), Binder::bind_with_vars( cx.typeck_results().node_type(param_ty.hir_id), - cx.tcx.late_bound_vars(cx.tcx.hir().local_def_id_to_hir_id(closure.def_id)), + cx.tcx.late_bound_vars(cx.tcx.local_def_id_to_hir_id(closure.def_id)), ), ) && is_copy(cx, param_ty) diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 97522cbe6cea..496bae583f10 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -131,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { FnKind::Closure => return, } - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); + let hir_id = cx.tcx.local_def_id_to_hir_id(def_id); // Const fns are not allowed as methods in a trait. { diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index d610ba520a48..f4ccd26631f1 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { return; } - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(fn_def_id); + let hir_id = cx.tcx.local_def_id_to_hir_id(fn_def_id); let is_async = match kind { FnKind::ItemFn(.., header) => { if header.is_unsafe() { @@ -256,7 +256,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { span_lint_hir_and_then( cx, NEEDLESS_PASS_BY_REF_MUT, - cx.tcx.hir().local_def_id_to_hir_id(*fn_def_id), + cx.tcx.local_def_id_to_hir_id(*fn_def_id), sp, "this argument is a mutable reference, but not used mutably", |diag| { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 7c48b84e4306..5442463bbf58 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -86,7 +86,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { return; } - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(fn_def_id); + let hir_id = cx.tcx.local_def_id_to_hir_id(fn_def_id); match kind { FnKind::ItemFn(.., header) => { diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index abba622a285a..2f6aebae4f50 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -106,7 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { let ty = cx.tcx.type_of(d).instantiate_identity(); if let Some(ty_def) = ty.ty_adt_def() { if let Some(local_def_id) = ty_def.did().as_local() { - impls.insert(cx.tcx.hir().local_def_id_to_hir_id(local_def_id)); + impls.insert(cx.tcx.local_def_id_to_hir_id(local_def_id)); } } }); @@ -119,7 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { && let self_def = cx.tcx.type_of(self_def_id).instantiate_identity() && let Some(self_def) = self_def.ty_adt_def() && let Some(self_local_did) = self_def.did().as_local() - && let self_id = cx.tcx.hir().local_def_id_to_hir_id(self_local_did) + && let self_id = cx.tcx.local_def_id_to_hir_id(self_local_did) && impling_types.contains(&self_id) { return; diff --git a/clippy_lints/src/non_send_fields_in_send_ty.rs b/clippy_lints/src/non_send_fields_in_send_ty.rs index df1476e68098..d07a9da55a22 100644 --- a/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -100,7 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy { if let Some(field_hir_id) = field .did .as_local() - .map(|local_def_id| hir_map.local_def_id_to_hir_id(local_def_id)) + .map(|local_def_id| cx.tcx.local_def_id_to_hir_id(local_def_id)) && !is_lint_allowed(cx, NON_SEND_FIELDS_IN_SEND_TY, field_hir_id) && let field_ty = field.ty(cx.tcx, impl_trait_args) && !ty_allowed_in_send(cx, field_ty, send_trait) diff --git a/clippy_lints/src/panic_in_result_fn.rs b/clippy_lints/src/panic_in_result_fn.rs index 6a760f9fe64a..f4dc80d744a0 100644 --- a/clippy_lints/src/panic_in_result_fn.rs +++ b/clippy_lints/src/panic_in_result_fn.rs @@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for PanicInResultFn { if matches!(fn_kind, FnKind::Closure) { return; } - let owner = cx.tcx.hir().local_def_id_to_hir_id(def_id).expect_owner(); + let owner = cx.tcx.local_def_id_to_hir_id(def_id).expect_owner(); if is_type_diagnostic_item(cx, return_ty(cx, owner), sym::Result) { lint_impl_body(cx, span, body); } diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index bbca8a123e68..98d284d03403 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -279,7 +279,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { return; } - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); + let hir_id = cx.tcx.local_def_id_to_hir_id(def_id); match kind { FnKind::ItemFn(.., header) => { if header.abi != Abi::Rust { diff --git a/clippy_lints/src/return_self_not_must_use.rs b/clippy_lints/src/return_self_not_must_use.rs index ad22b751befa..1a23757f7d6e 100644 --- a/clippy_lints/src/return_self_not_must_use.rs +++ b/clippy_lints/src/return_self_not_must_use.rs @@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for ReturnSelfNotMustUse { // `#[must_use]` should be put on the trait definition directly. && cx.tcx.trait_id_of_impl(impl_def).is_none() { - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(fn_def); + let hir_id = cx.tcx.local_def_id_to_hir_id(fn_def); check_method(cx, decl, fn_def, span, hir_id.expect_owner()); } } diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index c1edcf509efa..36cb2edf7237 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { if let Some(self_def) = self_ty.ty_adt_def() && let Some(self_local_did) = self_def.did().as_local() - && let self_id = cx.tcx.hir().local_def_id_to_hir_id(self_local_did) + && let self_id = cx.tcx.local_def_id_to_hir_id(self_local_did) && let Some(Node::Item(x)) = cx.tcx.hir().find(self_id) && let type_name = x.ident.name.as_str().to_lowercase() && (impl_item.ident.name.as_str() == type_name diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index f333b2cdcb49..4037808d34f1 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -324,7 +324,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { let is_in_trait_impl = if let Some(hir::Node::Item(item)) = cx.tcx.hir().find_by_def_id( cx.tcx .hir() - .get_parent_item(cx.tcx.hir().local_def_id_to_hir_id(def_id)) + .get_parent_item(cx.tcx.local_def_id_to_hir_id(def_id)) .def_id, ) { matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index 32aebdd8c0f7..41c4d3359f4b 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -349,7 +349,7 @@ fn block_parents_have_safety_comment( span, owner_id, .. - })) => (*span, cx.tcx.hir().local_def_id_to_hir_id(owner_id.def_id)), + })) => (*span, cx.tcx.local_def_id_to_hir_id(owner_id.def_id)), _ => { if is_branchy(expr) { return false; @@ -370,7 +370,7 @@ fn block_parents_have_safety_comment( span, owner_id, .. - }) => (*span, cx.tcx.hir().local_def_id_to_hir_id(owner_id.def_id)), + }) => (*span, cx.tcx.local_def_id_to_hir_id(owner_id.def_id)), _ => return false, }; // if unsafe block is part of a let/const/static statement, diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index 5599a9dc4e81..0d551639ea9f 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { } // Abort if the method is implementing a trait or of it a trait method. - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); + let hir_id = cx.tcx.local_def_id_to_hir_id(def_id); if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) { if matches!( item.kind, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 2466e8bb339d..172b063df315 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -709,7 +709,7 @@ pub fn get_trait_def_id(cx: &LateContext<'_>, path: &[&str]) -> Option { /// ``` pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, def_id: LocalDefId) -> Option<&'tcx TraitRef<'tcx>> { // Get the implemented trait for the current function - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id); + let hir_id = cx.tcx.local_def_id_to_hir_id(def_id); let parent_impl = cx.tcx.hir().get_parent_item(hir_id); if parent_impl != hir::CRATE_OWNER_ID && let hir::Node::Item(item) = cx.tcx.hir().get_by_def_id(parent_impl.def_id) @@ -2567,7 +2567,7 @@ pub fn inherits_cfg(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { tcx.has_attr(def_id, sym::cfg) || hir - .parent_iter(hir.local_def_id_to_hir_id(def_id)) + .parent_iter(tcx.local_def_id_to_hir_id(def_id)) .flat_map(|(parent_id, _)| hir.attrs(parent_id)) .any(|attr| attr.has_name(sym::cfg)) } @@ -2687,7 +2687,7 @@ impl<'tcx> ExprUseNode<'tcx> { .and(Binder::dummy(cx.tcx.type_of(id).instantiate_identity())), )), Self::Return(id) => { - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(id.def_id); + let hir_id = cx.tcx.local_def_id_to_hir_id(id.def_id); if let Some(Node::Expr(Expr { kind: ExprKind::Closure(c), .. diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 20588b63a78d..1e748a46922c 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -694,7 +694,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option { let decl = id .as_local() - .and_then(|id| cx.tcx.hir().fn_decl_by_hir_id(cx.tcx.hir().local_def_id_to_hir_id(id))); + .and_then(|id| cx.tcx.hir().fn_decl_by_hir_id(cx.tcx.local_def_id_to_hir_id(id))); Some(ExprFnSig::Closure(decl, subs.as_closure().sig())) }, ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.fn_sig(id).instantiate(cx.tcx, subs), Some(id))), From 9243efcf5f8d98853dc52a25cec61fbd45cd94b3 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 28 Nov 2023 09:11:03 +1100 Subject: [PATCH 0994/1222] Rework `ast::BinOpKind::to_string` and `ast::UnOp::to_string`. - Rename them both `as_str`, which is the typical name for a function that returns a `&str`. (`to_string` is appropriate for functions returning `String` or maybe `Cow<'a, str>`.) - Change `UnOp::as_str` from an associated function (weird!) to a method. - Avoid needless `self` dereferences. --- clippy_lints/src/formatting.rs | 8 ++++---- clippy_lints/src/precedence.rs | 6 +++--- clippy_lints/src/suspicious_operation_groupings.rs | 4 ++-- clippy_utils/src/sugg.rs | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index 70892ce608f6..2ab04682f1d5 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note}; use clippy_utils::is_span_if; use clippy_utils::source::snippet_opt; -use rustc_ast::ast::{BinOpKind, Block, Expr, ExprKind, StmtKind, UnOp}; +use rustc_ast::ast::{BinOpKind, Block, Expr, ExprKind, StmtKind}; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -144,7 +144,7 @@ fn check_assign(cx: &EarlyContext<'_>, expr: &Expr) { let eq_span = lhs.span.between(rhs.span); if let ExprKind::Unary(op, ref sub_rhs) = rhs.kind { if let Some(eq_snippet) = snippet_opt(cx, eq_span) { - let op = UnOp::to_string(op); + let op = op.as_str(); let eqop_span = lhs.span.between(sub_rhs.span); if eq_snippet.ends_with('=') { span_lint_and_note( @@ -177,11 +177,11 @@ fn check_unop(cx: &EarlyContext<'_>, expr: &Expr) { && let unop_operand_span = rhs.span.until(un_rhs.span) && let Some(binop_snippet) = snippet_opt(cx, binop_span) && let Some(unop_operand_snippet) = snippet_opt(cx, unop_operand_span) - && let binop_str = BinOpKind::to_string(&binop.node) + && let binop_str = binop.node.as_str() // no space after BinOp operator and space after UnOp operator && binop_snippet.ends_with(binop_str) && unop_operand_snippet.ends_with(' ') { - let unop_str = UnOp::to_string(op); + let unop_str = op.as_str(); let eqop_span = lhs.span.between(un_rhs.span); span_lint_and_help( cx, diff --git a/clippy_lints/src/precedence.rs b/clippy_lints/src/precedence.rs index b638e83997a5..52cec4373786 100644 --- a/clippy_lints/src/precedence.rs +++ b/clippy_lints/src/precedence.rs @@ -78,7 +78,7 @@ impl EarlyLintPass for Precedence { let sugg = format!( "({}) {} ({})", snippet_with_applicability(cx, left.span, "..", &mut applicability), - op.to_string(), + op.as_str(), snippet_with_applicability(cx, right.span, "..", &mut applicability) ); span_sugg(expr, sugg, applicability); @@ -87,7 +87,7 @@ impl EarlyLintPass for Precedence { let sugg = format!( "({}) {} {}", snippet_with_applicability(cx, left.span, "..", &mut applicability), - op.to_string(), + op.as_str(), snippet_with_applicability(cx, right.span, "..", &mut applicability) ); span_sugg(expr, sugg, applicability); @@ -96,7 +96,7 @@ impl EarlyLintPass for Precedence { let sugg = format!( "{} {} ({})", snippet_with_applicability(cx, left.span, "..", &mut applicability), - op.to_string(), + op.as_str(), snippet_with_applicability(cx, right.span, "..", &mut applicability) ); span_sugg(expr, sugg, applicability); diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index 92de7917871f..b332309a5527 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -298,7 +298,7 @@ fn replace_left_sugg( ) -> String { format!( "{left_suggestion} {} {}", - binop.op.to_string(), + binop.op.as_str(), snippet_with_applicability(cx, binop.right.span, "..", applicability), ) } @@ -312,7 +312,7 @@ fn replace_right_sugg( format!( "{} {} {right_suggestion}", snippet_with_applicability(cx, binop.left.span, "..", applicability), - binop.op.to_string(), + binop.op.as_str(), ) } diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index db79dd788018..f143163152e0 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -382,7 +382,7 @@ fn binop_to_string(op: AssocOp, lhs: &str, rhs: &str) -> String { | AssocOp::GreaterEqual => { format!( "{lhs} {} {rhs}", - op.to_ast_binop().expect("Those are AST ops").to_string() + op.to_ast_binop().expect("Those are AST ops").as_str() ) }, AssocOp::Assign => format!("{lhs} = {rhs}"), From 17cb12d6d975417f9adf0d786b38215ec33de6c8 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 22 Nov 2023 02:30:43 +0100 Subject: [PATCH 0995/1222] Add `never_patterns` feature gate --- clippy_lints/src/equatable_if_let.rs | 2 +- clippy_lints/src/matches/match_same_arms.rs | 3 +++ clippy_lints/src/unnested_or_patterns.rs | 2 +- clippy_lints/src/utils/author.rs | 1 + clippy_utils/src/hir_utils.rs | 1 + clippy_utils/src/lib.rs | 1 + 6 files changed, 8 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/equatable_if_let.rs b/clippy_lints/src/equatable_if_let.rs index 575fead5bf3e..630df9a84f58 100644 --- a/clippy_lints/src/equatable_if_let.rs +++ b/clippy_lints/src/equatable_if_let.rs @@ -46,7 +46,7 @@ fn unary_pattern(pat: &Pat<'_>) -> bool { pats.iter().all(unary_pattern) } match &pat.kind { - PatKind::Slice(_, _, _) | PatKind::Range(_, _, _) | PatKind::Binding(..) | PatKind::Wild | PatKind::Or(_) => { + PatKind::Slice(_, _, _) | PatKind::Range(_, _, _) | PatKind::Binding(..) | PatKind::Wild | PatKind::Never | PatKind::Or(_) => { false }, PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)), diff --git a/clippy_lints/src/matches/match_same_arms.rs b/clippy_lints/src/matches/match_same_arms.rs index 745be671b86d..cbf478620ec3 100644 --- a/clippy_lints/src/matches/match_same_arms.rs +++ b/clippy_lints/src/matches/match_same_arms.rs @@ -150,6 +150,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) { #[derive(Clone, Copy)] enum NormalizedPat<'a> { Wild, + Never, Struct(Option, &'a [(Symbol, Self)]), Tuple(Option, &'a [Self]), Or(&'a [Self]), @@ -229,6 +230,7 @@ impl<'a> NormalizedPat<'a> { PatKind::Binding(.., Some(pat)) | PatKind::Box(pat) | PatKind::Ref(pat, _) => { Self::from_pat(cx, arena, pat) }, + PatKind::Never => Self::Never, PatKind::Struct(ref path, fields, _) => { let fields = arena.alloc_from_iter(fields.iter().map(|f| (f.ident.name, Self::from_pat(cx, arena, f.pat)))); @@ -333,6 +335,7 @@ impl<'a> NormalizedPat<'a> { fn has_overlapping_values(&self, other: &Self) -> bool { match (*self, *other) { (Self::Wild, _) | (_, Self::Wild) => true, + (Self::Never, Self::Never) => true, (Self::Or(pats), ref other) | (ref other, Self::Or(pats)) => { pats.iter().any(|pat| pat.has_overlapping_values(other)) }, diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 8ff088a208f2..952c0dc72b19 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -226,7 +226,7 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec>, focus_idx: us // Therefore they are not some form of constructor `C`, // with which a pattern `C(p_0)` may be formed, // which we would want to join with other `C(p_j)`s. - Ident(.., None) | Lit(_) | Wild | Path(..) | Range(..) | Rest | MacCall(_) + Ident(.., None) | Lit(_) | Wild | Never | Path(..) | Range(..) | Rest | MacCall(_) // Skip immutable refs, as grouping them saves few characters, // and almost always requires adding parens (increasing noisiness). // In the case of only two patterns, replacement adds net characters. diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index e8842ce10f8a..e83c04eda207 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -629,6 +629,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { match pat.value.kind { PatKind::Wild => kind!("Wild"), + PatKind::Never => kind!("Never"), PatKind::Binding(ann, _, name, sub) => { bind!(self, name); opt_bind!(self, sub); diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 8031e6faa745..34ec83709ffd 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -1017,6 +1017,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } e.hash(&mut self.s); }, + PatKind::Never => {}, PatKind::Wild => {}, } } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 172b063df315..fd37713fc605 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1707,6 +1707,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { match pat.kind { PatKind::Wild => false, + PatKind::Never => false, // If `!` typechecked then the type is empty, so not refutable. PatKind::Binding(_, _, _, pat) => pat.map_or(false, |pat| is_refutable(cx, pat)), PatKind::Box(pat) | PatKind::Ref(pat, _) => is_refutable(cx, pat), PatKind::Lit(..) | PatKind::Range(..) => true, From fbc291fa1f10a2de161781b1f5cdd443e2b3a6bf Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 30 Nov 2023 14:01:35 +1100 Subject: [PATCH 0996/1222] Rename `*note_without_error` as `*note`. Because the variant name in `Level` is `Note`, and the `without_error` suffix is omitted in similar cases like `struct_allow` and `struct_help`. --- src/driver.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver.rs b/src/driver.rs index 1ae8ac81695f..49f0cad08e01 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -183,7 +183,7 @@ pub fn main() { // as simple as moving the call from the hook to main, because `install_ice_hook` doesn't // accept a generic closure. let version_info = rustc_tools_util::get_version_info!(); - handler.note_without_error(format!("Clippy version: {version_info}")); + handler.note(format!("Clippy version: {version_info}")); }); exit(rustc_driver::catch_with_exit_code(move || { From 8efd3e8ad9a68a0a18af1e013995d6d0bfd3bd07 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 30 Nov 2023 15:01:11 +1100 Subject: [PATCH 0997/1222] Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`. Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug` follows the pattern used everywhere else: `span_err`, `span_warning`, etc. --- tests/integration.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration.rs b/tests/integration.rs index 031982edbe9e..267f095f9c20 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -69,15 +69,15 @@ fn integration_test() { // debug: eprintln!("{stderr}"); - // this is an internal test to make sure we would correctly panic on a delay_span_bug + // this is an internal test to make sure we would correctly panic on a span_delayed_bug if repo_name == "matthiaskrgr/clippy_ci_panic_test" { // we need to kind of switch around our logic here: // if we find a panic, everything is fine, if we don't panic, SOMETHING is broken about our testing - // the repo basically just contains a delay_span_bug that forces rustc/clippy to panic: + // the repo basically just contains a span_delayed_bug that forces rustc/clippy to panic: /* #![feature(rustc_attrs)] - #[rustc_error(delay_span_bug_from_inside_query)] + #[rustc_error(span_delayed_bug_from_inside_query)] fn main() {} */ @@ -86,7 +86,7 @@ fn integration_test() { return; } - panic!("panic caused by delay_span_bug was NOT detected! Something is broken!"); + panic!("panic caused by span_delayed_bug was NOT detected! Something is broken!"); } if let Some(backtrace_start) = stderr.find("error: internal compiler error") { From 2e13f9007b5792a7a0164cf9d0511b9220ced9d9 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 27 Nov 2023 03:15:56 +0100 Subject: [PATCH 0998/1222] Parse a pattern with no arm --- clippy_lints/src/non_expressive_names.rs | 4 +++- clippy_lints/src/redundant_else.rs | 4 +++- clippy_utils/src/ast_utils.rs | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 649a23565a96..107f488484db 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -341,7 +341,9 @@ impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> { self.apply(|this| { SimilarNamesNameVisitor(this).visit_pat(&arm.pat); - this.apply(|this| walk_expr(this, &arm.body)); + if let Some(body) = &arm.body { + this.apply(|this| walk_expr(this, body)); + } }); self.check_single_char_names(); diff --git a/clippy_lints/src/redundant_else.rs b/clippy_lints/src/redundant_else.rs index 221aa317e5d4..530fc6646579 100644 --- a/clippy_lints/src/redundant_else.rs +++ b/clippy_lints/src/redundant_else.rs @@ -105,7 +105,9 @@ impl<'ast> Visitor<'ast> for BreakVisitor { fn visit_expr(&mut self, expr: &'ast Expr) { self.is_break = match expr.kind { ExprKind::Break(..) | ExprKind::Continue(..) | ExprKind::Ret(..) => true, - ExprKind::Match(_, ref arms) => arms.iter().all(|arm| self.check_expr(&arm.body)), + ExprKind::Match(_, ref arms) => arms.iter().all(|arm| + arm.body.is_none() || arm.body.as_deref().is_some_and(|body| self.check_expr(body)) + ), ExprKind::If(_, ref then, Some(ref els)) => self.check_block(then) && self.check_expr(els), ExprKind::If(_, _, None) // ignore loops for simplicity diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index a2c61e07b70a..b2cff1646613 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -236,7 +236,7 @@ pub fn eq_field(l: &ExprField, r: &ExprField) -> bool { pub fn eq_arm(l: &Arm, r: &Arm) -> bool { l.is_placeholder == r.is_placeholder && eq_pat(&l.pat, &r.pat) - && eq_expr(&l.body, &r.body) + && eq_expr_opt(&l.body, &r.body) && eq_expr_opt(&l.guard, &r.guard) && over(&l.attrs, &r.attrs, eq_attr) } From 2f0a18973c35452dd47a1d07b4a32c223c8a4674 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Thu, 30 Nov 2023 14:54:39 -0800 Subject: [PATCH 0999/1222] Merge Async and Gen into CoroutineKind --- clippy_lints/src/doc/mod.rs | 199 ++++++++++++++++++++++++++++++++++ clippy_utils/src/ast_utils.rs | 6 +- 2 files changed, 202 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index ba452775015d..ec4abc21f485 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -655,6 +655,205 @@ fn check_doc<'a, Events: Iterator, Range, trimmed_text: &str, range: Range, fragments: Fragments<'_>) { + if trimmed_text.starts_with('\'') + && trimmed_text.ends_with('\'') + && let Some(span) = fragments.span(cx, range) + { + span_lint( + cx, + DOC_LINK_WITH_QUOTES, + span, + "possible intra-doc link using quotes instead of backticks", + ); + } +} + +fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, range: Range, fragments: Fragments<'_>) { + fn has_needless_main(code: String, edition: Edition) -> bool { + rustc_driver::catch_fatal_errors(|| { + rustc_span::create_session_globals_then(edition, || { + let filename = FileName::anon_source_code(&code); + + let fallback_bundle = + rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false); + let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle); + let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings(); + #[expect(clippy::arc_with_non_send_sync)] // `Lrc` is expected by with_span_handler + let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); + let sess = ParseSess::with_span_handler(handler, sm); + + let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) { + Ok(p) => p, + Err(errs) => { + drop(errs); + return false; + }, + }; + + let mut relevant_main_found = false; + loop { + match parser.parse_item(ForceCollect::No) { + Ok(Some(item)) => match &item.kind { + ItemKind::Fn(box Fn { + sig, body: Some(block), .. + }) if item.ident.name == sym::main => { + let is_async = sig.header.coro_kind.is_async(); + let returns_nothing = match &sig.decl.output { + FnRetTy::Default(..) => true, + FnRetTy::Ty(ty) if ty.kind.is_unit() => true, + FnRetTy::Ty(_) => false, + }; + + if returns_nothing && !is_async && !block.stmts.is_empty() { + // This main function should be linted, but only if there are no other functions + relevant_main_found = true; + } else { + // This main function should not be linted, we're done + return false; + } + }, + // Tests with one of these items are ignored + ItemKind::Static(..) + | ItemKind::Const(..) + | ItemKind::ExternCrate(..) + | ItemKind::ForeignMod(..) + // Another function was found; this case is ignored + | ItemKind::Fn(..) => return false, + _ => {}, + }, + Ok(None) => break, + Err(e) => { + e.cancel(); + return false; + }, + } + } + + relevant_main_found + }) + }) + .ok() + .unwrap_or_default() + } + + let trailing_whitespace = text.len() - text.trim_end().len(); + + // 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") + && let Some(span) = fragments.span(cx, range.start..range.end - trailing_whitespace) + { + span_lint(cx, NEEDLESS_DOCTEST_MAIN, span, "needless `fn main` in doctest"); + } +} + +fn check_text(cx: &LateContext<'_>, valid_idents: &FxHashSet, text: &str, span: Span) { + for word in text.split(|c: char| c.is_whitespace() || c == '\'') { + // Trim punctuation as in `some comment (see foo::bar).` + // ^^ + // Or even as in `_foo bar_` which is emphasized. Also preserve `::` as a prefix/suffix. + let mut word = word.trim_matches(|c: char| !c.is_alphanumeric() && c != ':'); + + // Remove leading or trailing single `:` which may be part of a sentence. + if word.starts_with(':') && !word.starts_with("::") { + word = word.trim_start_matches(':'); + } + if word.ends_with(':') && !word.ends_with("::") { + word = word.trim_end_matches(':'); + } + + if valid_idents.contains(word) || word.chars().all(|c| c == ':') { + continue; + } + + // Adjust for the current word + let offset = word.as_ptr() as usize - text.as_ptr() as usize; + let span = Span::new( + span.lo() + BytePos::from_usize(offset), + span.lo() + BytePos::from_usize(offset + word.len()), + span.ctxt(), + span.parent(), + ); + + check_word(cx, word, span); + } +} + +fn check_word(cx: &LateContext<'_>, word: &str, span: Span) { + /// Checks if a string is upper-camel-case, i.e., starts with an uppercase and + /// contains at least two uppercase letters (`Clippy` is ok) and one lower-case + /// letter (`NASA` is ok). + /// Plurals are also excluded (`IDs` is ok). + fn is_camel_case(s: &str) -> bool { + if s.starts_with(|c: char| c.is_ascii_digit() | c.is_ascii_lowercase()) { + return false; + } + + let s = s.strip_suffix('s').unwrap_or(s); + + s.chars().all(char::is_alphanumeric) + && s.chars().filter(|&c| c.is_uppercase()).take(2).count() > 1 + && s.chars().filter(|&c| c.is_lowercase()).take(1).count() > 0 + } + + fn has_underscore(s: &str) -> bool { + s != "_" && !s.contains("\\_") && s.contains('_') + } + + fn has_hyphen(s: &str) -> bool { + s != "-" && s.contains('-') + } + + if let Ok(url) = Url::parse(word) { + // try to get around the fact that `foo::bar` parses as a valid URL + if !url.cannot_be_a_base() { + span_lint( + cx, + DOC_MARKDOWN, + span, + "you should put bare URLs between `<`/`>` or make a proper Markdown link", + ); + + return; + } + } + + // We assume that mixed-case words are not meant to be put inside backticks. (Issue #2343) + if has_underscore(word) && has_hyphen(word) { + return; + } + + if has_underscore(word) || word.contains("::") || is_camel_case(word) { + let mut applicability = Applicability::MachineApplicable; + + span_lint_and_then( + cx, + DOC_MARKDOWN, + span, + "item in documentation is missing backticks", + |diag| { + let snippet = snippet_with_applicability(cx, span, "..", &mut applicability); + diag.span_suggestion_with_style( + span, + "try", + format!("`{snippet}`"), + applicability, + // always show the suggestion in a separate line, since the + // inline presentation adds another pair of backticks + SuggestionStyle::ShowAlways, + ); + }, + ); + } +} + +>>>>>>> d116f1718f1 (Merge Async and Gen into CoroutineKind):src/tools/clippy/clippy_lints/src/doc.rs struct FindPanicUnwrap<'a, 'tcx> { cx: &'a LateContext<'tcx>, panic_span: Option, diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index a2c61e07b70a..ac9da383b935 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -188,7 +188,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { Closure(box ast::Closure { binder: lb, capture_clause: lc, - asyncness: la, + coro_kind: la, movability: lm, fn_decl: lf, body: le, @@ -197,7 +197,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { Closure(box ast::Closure { binder: rb, capture_clause: rc, - asyncness: ra, + coro_kind: ra, movability: rm, fn_decl: rf, body: re, @@ -565,7 +565,7 @@ pub fn eq_fn_sig(l: &FnSig, r: &FnSig) -> bool { pub fn eq_fn_header(l: &FnHeader, r: &FnHeader) -> bool { matches!(l.unsafety, Unsafe::No) == matches!(r.unsafety, Unsafe::No) - && l.asyncness.is_async() == r.asyncness.is_async() + && (l.coro_kind.is_async() == r.coro_kind.is_async() || l.coro_kind.is_gen() == r.coro_kind.is_gen()) && matches!(l.constness, Const::No) == matches!(r.constness, Const::No) && eq_ext(&l.ext, &r.ext) } From 0414e841bbfe4373f0cfd8de88044e5273817311 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Thu, 30 Nov 2023 16:39:56 -0800 Subject: [PATCH 1000/1222] Option --- clippy_lints/src/doc/mod.rs | 2 +- clippy_utils/src/ast_utils.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index ec4abc21f485..0c623dba3696 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -700,7 +700,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, range: Range { - let is_async = sig.header.coro_kind.is_async(); + let is_async = sig.header.coro_kind.map_or(false, |coro| coro.is_async()); let returns_nothing = match &sig.decl.output { FnRetTy::Default(..) => true, FnRetTy::Ty(ty) if ty.kind.is_unit() => true, diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index ac9da383b935..12403bbff3c9 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -206,7 +206,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { ) => { eq_closure_binder(lb, rb) && lc == rc - && la.is_async() == ra.is_async() + && la.map_or(false, |la| la.is_async()) == ra.map_or(false, |ra| ra.is_async()) && lm == rm && eq_fn_decl(lf, rf) && eq_expr(le, re) @@ -563,9 +563,18 @@ pub fn eq_fn_sig(l: &FnSig, r: &FnSig) -> bool { eq_fn_decl(&l.decl, &r.decl) && eq_fn_header(&l.header, &r.header) } +fn eq_opt_coro_kind(l: Option, r: Option) -> bool { + match (l, r) { + (Some(CoroutineKind::Async { .. }), Some(CoroutineKind::Async { .. })) + | (Some(CoroutineKind::Gen { .. }), Some(CoroutineKind::Gen { .. })) => true, + (None, None) => true, + _ => false, + } +} + pub fn eq_fn_header(l: &FnHeader, r: &FnHeader) -> bool { matches!(l.unsafety, Unsafe::No) == matches!(r.unsafety, Unsafe::No) - && (l.coro_kind.is_async() == r.coro_kind.is_async() || l.coro_kind.is_gen() == r.coro_kind.is_gen()) + && eq_opt_coro_kind(l.coro_kind, r.coro_kind) && matches!(l.constness, Const::No) == matches!(r.constness, Const::No) && eq_ext(&l.ext, &r.ext) } From c3927d957ce73df4dd39d9bd569d9e2d03c9c6b1 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Mon, 4 Dec 2023 14:38:10 -0800 Subject: [PATCH 1001/1222] Remove bad merge --- clippy_lints/src/doc/mod.rs | 199 ------------------------------------ 1 file changed, 199 deletions(-) diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 0c623dba3696..ba452775015d 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -655,205 +655,6 @@ fn check_doc<'a, Events: Iterator, Range, trimmed_text: &str, range: Range, fragments: Fragments<'_>) { - if trimmed_text.starts_with('\'') - && trimmed_text.ends_with('\'') - && let Some(span) = fragments.span(cx, range) - { - span_lint( - cx, - DOC_LINK_WITH_QUOTES, - span, - "possible intra-doc link using quotes instead of backticks", - ); - } -} - -fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, range: Range, fragments: Fragments<'_>) { - fn has_needless_main(code: String, edition: Edition) -> bool { - rustc_driver::catch_fatal_errors(|| { - rustc_span::create_session_globals_then(edition, || { - let filename = FileName::anon_source_code(&code); - - let fallback_bundle = - rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false); - let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle); - let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings(); - #[expect(clippy::arc_with_non_send_sync)] // `Lrc` is expected by with_span_handler - let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let sess = ParseSess::with_span_handler(handler, sm); - - let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) { - Ok(p) => p, - Err(errs) => { - drop(errs); - return false; - }, - }; - - let mut relevant_main_found = false; - loop { - match parser.parse_item(ForceCollect::No) { - Ok(Some(item)) => match &item.kind { - ItemKind::Fn(box Fn { - sig, body: Some(block), .. - }) if item.ident.name == sym::main => { - let is_async = sig.header.coro_kind.map_or(false, |coro| coro.is_async()); - let returns_nothing = match &sig.decl.output { - FnRetTy::Default(..) => true, - FnRetTy::Ty(ty) if ty.kind.is_unit() => true, - FnRetTy::Ty(_) => false, - }; - - if returns_nothing && !is_async && !block.stmts.is_empty() { - // This main function should be linted, but only if there are no other functions - relevant_main_found = true; - } else { - // This main function should not be linted, we're done - return false; - } - }, - // Tests with one of these items are ignored - ItemKind::Static(..) - | ItemKind::Const(..) - | ItemKind::ExternCrate(..) - | ItemKind::ForeignMod(..) - // Another function was found; this case is ignored - | ItemKind::Fn(..) => return false, - _ => {}, - }, - Ok(None) => break, - Err(e) => { - e.cancel(); - return false; - }, - } - } - - relevant_main_found - }) - }) - .ok() - .unwrap_or_default() - } - - let trailing_whitespace = text.len() - text.trim_end().len(); - - // 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") - && let Some(span) = fragments.span(cx, range.start..range.end - trailing_whitespace) - { - span_lint(cx, NEEDLESS_DOCTEST_MAIN, span, "needless `fn main` in doctest"); - } -} - -fn check_text(cx: &LateContext<'_>, valid_idents: &FxHashSet, text: &str, span: Span) { - for word in text.split(|c: char| c.is_whitespace() || c == '\'') { - // Trim punctuation as in `some comment (see foo::bar).` - // ^^ - // Or even as in `_foo bar_` which is emphasized. Also preserve `::` as a prefix/suffix. - let mut word = word.trim_matches(|c: char| !c.is_alphanumeric() && c != ':'); - - // Remove leading or trailing single `:` which may be part of a sentence. - if word.starts_with(':') && !word.starts_with("::") { - word = word.trim_start_matches(':'); - } - if word.ends_with(':') && !word.ends_with("::") { - word = word.trim_end_matches(':'); - } - - if valid_idents.contains(word) || word.chars().all(|c| c == ':') { - continue; - } - - // Adjust for the current word - let offset = word.as_ptr() as usize - text.as_ptr() as usize; - let span = Span::new( - span.lo() + BytePos::from_usize(offset), - span.lo() + BytePos::from_usize(offset + word.len()), - span.ctxt(), - span.parent(), - ); - - check_word(cx, word, span); - } -} - -fn check_word(cx: &LateContext<'_>, word: &str, span: Span) { - /// Checks if a string is upper-camel-case, i.e., starts with an uppercase and - /// contains at least two uppercase letters (`Clippy` is ok) and one lower-case - /// letter (`NASA` is ok). - /// Plurals are also excluded (`IDs` is ok). - fn is_camel_case(s: &str) -> bool { - if s.starts_with(|c: char| c.is_ascii_digit() | c.is_ascii_lowercase()) { - return false; - } - - let s = s.strip_suffix('s').unwrap_or(s); - - s.chars().all(char::is_alphanumeric) - && s.chars().filter(|&c| c.is_uppercase()).take(2).count() > 1 - && s.chars().filter(|&c| c.is_lowercase()).take(1).count() > 0 - } - - fn has_underscore(s: &str) -> bool { - s != "_" && !s.contains("\\_") && s.contains('_') - } - - fn has_hyphen(s: &str) -> bool { - s != "-" && s.contains('-') - } - - if let Ok(url) = Url::parse(word) { - // try to get around the fact that `foo::bar` parses as a valid URL - if !url.cannot_be_a_base() { - span_lint( - cx, - DOC_MARKDOWN, - span, - "you should put bare URLs between `<`/`>` or make a proper Markdown link", - ); - - return; - } - } - - // We assume that mixed-case words are not meant to be put inside backticks. (Issue #2343) - if has_underscore(word) && has_hyphen(word) { - return; - } - - if has_underscore(word) || word.contains("::") || is_camel_case(word) { - let mut applicability = Applicability::MachineApplicable; - - span_lint_and_then( - cx, - DOC_MARKDOWN, - span, - "item in documentation is missing backticks", - |diag| { - let snippet = snippet_with_applicability(cx, span, "..", &mut applicability); - diag.span_suggestion_with_style( - span, - "try", - format!("`{snippet}`"), - applicability, - // always show the suggestion in a separate line, since the - // inline presentation adds another pair of backticks - SuggestionStyle::ShowAlways, - ); - }, - ); - } -} - ->>>>>>> d116f1718f1 (Merge Async and Gen into CoroutineKind):src/tools/clippy/clippy_lints/src/doc.rs struct FindPanicUnwrap<'a, 'tcx> { cx: &'a LateContext<'tcx>, panic_span: Option, From de88f405e6e518f64c870d6a67c1f2ef51d8473e Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Mon, 4 Dec 2023 16:37:45 -0800 Subject: [PATCH 1002/1222] Update doctest --- clippy_lints/src/doc/needless_doctest_main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/doc/needless_doctest_main.rs b/clippy_lints/src/doc/needless_doctest_main.rs index e50e83834c1a..8079129f7823 100644 --- a/clippy_lints/src/doc/needless_doctest_main.rs +++ b/clippy_lints/src/doc/needless_doctest_main.rs @@ -3,7 +3,7 @@ use std::{io, thread}; use crate::doc::{NEEDLESS_DOCTEST_MAIN, TEST_ATTR_IN_DOCTEST}; use clippy_utils::diagnostics::span_lint; -use rustc_ast::{Async, Fn, FnRetTy, Item, ItemKind}; +use rustc_ast::{CoroutineKind, Fn, FnRetTy, Item, ItemKind}; use rustc_data_structures::sync::Lrc; use rustc_errors::emitter::EmitterWriter; use rustc_errors::Handler; @@ -69,7 +69,7 @@ pub fn check( if !ignore { get_test_spans(&item, &mut test_attr_spans); } - let is_async = matches!(sig.header.asyncness, Async::Yes { .. }); + let is_async = matches!(sig.header.coro_kind, CoroutineKind::Async { .. }); let returns_nothing = match &sig.decl.output { FnRetTy::Default(..) => true, FnRetTy::Ty(ty) if ty.kind.is_unit() => true, From 7b8e84ef0831c33a583a9f59d78a38703fea7ce4 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Mon, 4 Dec 2023 16:46:45 -0800 Subject: [PATCH 1003/1222] Fix build --- clippy_lints/src/doc/needless_doctest_main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/doc/needless_doctest_main.rs b/clippy_lints/src/doc/needless_doctest_main.rs index 8079129f7823..640d4a069ec7 100644 --- a/clippy_lints/src/doc/needless_doctest_main.rs +++ b/clippy_lints/src/doc/needless_doctest_main.rs @@ -69,7 +69,7 @@ pub fn check( if !ignore { get_test_spans(&item, &mut test_attr_spans); } - let is_async = matches!(sig.header.coro_kind, CoroutineKind::Async { .. }); + let is_async = matches!(sig.header.coro_kind, Some(CoroutineKind::Async { .. })); let returns_nothing = match &sig.decl.output { FnRetTy::Default(..) => true, FnRetTy::Ty(ty) if ty.kind.is_unit() => true, From 5de880b6f3e78cc44c0fd99047f05d98674ad7aa Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 9 Nov 2023 19:13:35 +0100 Subject: [PATCH 1004/1222] Drop clippy::vtable_address_comparisons --- clippy_lints/src/declared_lints.rs | 1 - clippy_lints/src/renamed_lints.rs | 1 + clippy_lints/src/unnamed_address.rs | 68 +----------- tests/ui/rename.fixed | 2 + tests/ui/rename.rs | 2 + tests/ui/rename.stderr | 120 +++++++++++---------- tests/ui/vtable_address_comparisons.rs | 52 --------- tests/ui/vtable_address_comparisons.stderr | 68 ------------ 8 files changed, 70 insertions(+), 244 deletions(-) delete mode 100644 tests/ui/vtable_address_comparisons.rs delete mode 100644 tests/ui/vtable_address_comparisons.stderr diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index b440e267efe3..3627096ed91b 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -684,7 +684,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::unit_types::UNIT_ARG_INFO, crate::unit_types::UNIT_CMP_INFO, crate::unnamed_address::FN_ADDRESS_COMPARISONS_INFO, - crate::unnamed_address::VTABLE_ADDRESS_COMPARISONS_INFO, crate::unnecessary_box_returns::UNNECESSARY_BOX_RETURNS_INFO, crate::unnecessary_map_on_constructor::UNNECESSARY_MAP_ON_CONSTRUCTOR_INFO, crate::unnecessary_owned_empty_strings::UNNECESSARY_OWNED_EMPTY_STRINGS_INFO, diff --git a/clippy_lints/src/renamed_lints.rs b/clippy_lints/src/renamed_lints.rs index 613f1ecc6fbe..9f5897d2ca74 100644 --- a/clippy_lints/src/renamed_lints.rs +++ b/clippy_lints/src/renamed_lints.rs @@ -58,4 +58,5 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::undropped_manually_drops", "undropped_manually_drops"), ("clippy::unknown_clippy_lints", "unknown_lints"), ("clippy::unused_label", "unused_labels"), + ("clippy::vtable_address_comparisons", "ambiguous_wide_pointer_comparisons"), ]; diff --git a/clippy_lints/src/unnamed_address.rs b/clippy_lints/src/unnamed_address.rs index 41e13e13e56c..cd2dacc9f099 100644 --- a/clippy_lints/src/unnamed_address.rs +++ b/clippy_lints/src/unnamed_address.rs @@ -1,9 +1,8 @@ -use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; +use clippy_utils::diagnostics::span_lint; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::declare_lint_pass; -use rustc_span::sym; declare_clippy_lint! { /// ### What it does @@ -29,31 +28,7 @@ declare_clippy_lint! { "comparison with an address of a function item" } -declare_clippy_lint! { - /// ### What it does - /// Checks for comparisons with an address of a trait vtable. - /// - /// ### Why is this bad? - /// Comparing trait objects pointers compares an vtable addresses which - /// are not guaranteed to be unique and could vary between different code generation units. - /// Furthermore vtables for different types could have the same address after being merged - /// together. - /// - /// ### Example - /// ```rust,ignore - /// let a: Rc = ... - /// let b: Rc = ... - /// if Rc::ptr_eq(&a, &b) { - /// ... - /// } - /// ``` - #[clippy::version = "1.44.0"] - pub VTABLE_ADDRESS_COMPARISONS, - correctness, - "comparison with an address of a trait vtable" -} - -declare_lint_pass!(UnnamedAddress => [FN_ADDRESS_COMPARISONS, VTABLE_ADDRESS_COMPARISONS]); +declare_lint_pass!(UnnamedAddress => [FN_ADDRESS_COMPARISONS]); impl LateLintPass<'_> for UnnamedAddress { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { @@ -64,49 +39,10 @@ impl LateLintPass<'_> for UnnamedAddress { ) } - fn is_trait_ptr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - match cx.typeck_results().expr_ty_adjusted(expr).kind() { - ty::RawPtr(ty::TypeAndMut { ty, .. }) => ty.is_trait(), - _ => false, - } - } - fn is_fn_def(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { matches!(cx.typeck_results().expr_ty(expr).kind(), ty::FnDef(..)) } - if let ExprKind::Binary(binop, left, right) = expr.kind - && is_comparison(binop.node) - && is_trait_ptr(cx, left) - && is_trait_ptr(cx, right) - { - span_lint_and_help( - cx, - VTABLE_ADDRESS_COMPARISONS, - expr.span, - "comparing trait object pointers compares a non-unique vtable address", - None, - "consider extracting and comparing data pointers only", - ); - } - - if let ExprKind::Call(func, [ref _left, ref _right]) = expr.kind - && let ExprKind::Path(ref func_qpath) = func.kind - && let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id() - && cx.tcx.is_diagnostic_item(sym::ptr_eq, def_id) - && let ty_param = cx.typeck_results().node_args(func.hir_id).type_at(0) - && ty_param.is_trait() - { - span_lint_and_help( - cx, - VTABLE_ADDRESS_COMPARISONS, - expr.span, - "comparing trait object pointers compares a non-unique vtable address", - None, - "consider extracting and comparing data pointers only", - ); - } - if let ExprKind::Binary(binop, left, right) = expr.kind && is_comparison(binop.node) && cx.typeck_results().expr_ty_adjusted(left).is_fn_ptr() diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index 4df9be2c21d9..31f1ee6a86d1 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -51,6 +51,7 @@ #![allow(undropped_manually_drops)] #![allow(unknown_lints)] #![allow(unused_labels)] +#![allow(ambiguous_wide_pointer_comparisons)] #![warn(clippy::almost_complete_range)] #![warn(clippy::disallowed_names)] #![warn(clippy::blocks_in_if_conditions)] @@ -107,5 +108,6 @@ #![warn(undropped_manually_drops)] #![warn(unknown_lints)] #![warn(unused_labels)] +#![warn(ambiguous_wide_pointer_comparisons)] fn main() {} diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index 940e60068e7b..325bc356c15f 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -51,6 +51,7 @@ #![allow(undropped_manually_drops)] #![allow(unknown_lints)] #![allow(unused_labels)] +#![allow(ambiguous_wide_pointer_comparisons)] #![warn(clippy::almost_complete_letter_range)] #![warn(clippy::blacklisted_name)] #![warn(clippy::block_in_if_condition_expr)] @@ -107,5 +108,6 @@ #![warn(clippy::undropped_manually_drops)] #![warn(clippy::unknown_clippy_lints)] #![warn(clippy::unused_label)] +#![warn(clippy::vtable_address_comparisons)] fn main() {} diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 30824e154b8b..a6164338c20c 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> $DIR/rename.rs:54:9 + --> $DIR/rename.rs:55:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -8,334 +8,340 @@ LL | #![warn(clippy::almost_complete_letter_range)] = help: to override `-D warnings` add `#[allow(renamed_and_removed_lints)]` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> $DIR/rename.rs:55:9 + --> $DIR/rename.rs:56:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:56:9 + --> $DIR/rename.rs:57:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:57:9 + --> $DIR/rename.rs:58:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> $DIR/rename.rs:58:9 + --> $DIR/rename.rs:59:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:59:9 + --> $DIR/rename.rs:60:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:60:9 + --> $DIR/rename.rs:61:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> $DIR/rename.rs:61:9 + --> $DIR/rename.rs:62:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> $DIR/rename.rs:62:9 + --> $DIR/rename.rs:63:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> $DIR/rename.rs:63:9 + --> $DIR/rename.rs:64:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> $DIR/rename.rs:64:9 + --> $DIR/rename.rs:65:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> $DIR/rename.rs:65:9 + --> $DIR/rename.rs:66:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> $DIR/rename.rs:66:9 + --> $DIR/rename.rs:67:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::incorrect_clone_impl_on_copy_type` has been renamed to `clippy::non_canonical_clone_impl` - --> $DIR/rename.rs:67:9 + --> $DIR/rename.rs:68:9 | LL | #![warn(clippy::incorrect_clone_impl_on_copy_type)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::non_canonical_clone_impl` error: lint `clippy::incorrect_partial_ord_impl_on_ord_type` has been renamed to `clippy::non_canonical_partial_ord_impl` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:69:9 | LL | #![warn(clippy::incorrect_partial_ord_impl_on_ord_type)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::non_canonical_partial_ord_impl` error: lint `clippy::integer_arithmetic` has been renamed to `clippy::arithmetic_side_effects` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::integer_arithmetic)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::arithmetic_side_effects` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:79:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:80:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:83:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::unwrap_or_else_default` has been renamed to `clippy::unwrap_or_default` - --> $DIR/rename.rs:84:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::unwrap_or_else_default)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_or_default` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:85:9 + --> $DIR/rename.rs:86:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::cast_ref_to_mut` has been renamed to `invalid_reference_casting` - --> $DIR/rename.rs:86:9 + --> $DIR/rename.rs:87:9 | LL | #![warn(clippy::cast_ref_to_mut)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_reference_casting` error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op` - --> $DIR/rename.rs:87:9 + --> $DIR/rename.rs:88:9 | LL | #![warn(clippy::clone_double_ref)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op` error: lint `clippy::cmp_nan` has been renamed to `invalid_nan_comparisons` - --> $DIR/rename.rs:88:9 + --> $DIR/rename.rs:89:9 | LL | #![warn(clippy::cmp_nan)] | ^^^^^^^^^^^^^^^ help: use the new name: `invalid_nan_comparisons` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:89:9 + --> $DIR/rename.rs:90:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` error: lint `clippy::drop_copy` has been renamed to `dropping_copy_types` - --> $DIR/rename.rs:90:9 + --> $DIR/rename.rs:91:9 | LL | #![warn(clippy::drop_copy)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `dropping_copy_types` error: lint `clippy::drop_ref` has been renamed to `dropping_references` - --> $DIR/rename.rs:91:9 + --> $DIR/rename.rs:92:9 | LL | #![warn(clippy::drop_ref)] | ^^^^^^^^^^^^^^^^ help: use the new name: `dropping_references` error: lint `clippy::fn_null_check` has been renamed to `useless_ptr_null_checks` - --> $DIR/rename.rs:92:9 + --> $DIR/rename.rs:93:9 | LL | #![warn(clippy::fn_null_check)] | ^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `useless_ptr_null_checks` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:93:9 + --> $DIR/rename.rs:94:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:94:9 + --> $DIR/rename.rs:95:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:95:9 + --> $DIR/rename.rs:96:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::forget_copy` has been renamed to `forgetting_copy_types` - --> $DIR/rename.rs:96:9 + --> $DIR/rename.rs:97:9 | LL | #![warn(clippy::forget_copy)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_copy_types` error: lint `clippy::forget_ref` has been renamed to `forgetting_references` - --> $DIR/rename.rs:97:9 + --> $DIR/rename.rs:98:9 | LL | #![warn(clippy::forget_ref)] | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:98:9 + --> $DIR/rename.rs:99:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:99:9 + --> $DIR/rename.rs:100:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:100:9 + --> $DIR/rename.rs:101:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::invalid_utf8_in_unchecked` has been renamed to `invalid_from_utf8_unchecked` - --> $DIR/rename.rs:101:9 + --> $DIR/rename.rs:102:9 | LL | #![warn(clippy::invalid_utf8_in_unchecked)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_from_utf8_unchecked` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:102:9 + --> $DIR/rename.rs:103:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:103:9 + --> $DIR/rename.rs:104:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:104:9 + --> $DIR/rename.rs:105:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:105:9 + --> $DIR/rename.rs:106:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:106:9 + --> $DIR/rename.rs:107:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::undropped_manually_drops` has been renamed to `undropped_manually_drops` - --> $DIR/rename.rs:107:9 + --> $DIR/rename.rs:108:9 | LL | #![warn(clippy::undropped_manually_drops)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `undropped_manually_drops` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:108:9 + --> $DIR/rename.rs:109:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:109:9 + --> $DIR/rename.rs:110:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 56 previous errors +error: lint `clippy::vtable_address_comparisons` has been renamed to `ambiguous_wide_pointer_comparisons` + --> $DIR/rename.rs:111:9 + | +LL | #![warn(clippy::vtable_address_comparisons)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `ambiguous_wide_pointer_comparisons` + +error: aborting due to 57 previous errors diff --git a/tests/ui/vtable_address_comparisons.rs b/tests/ui/vtable_address_comparisons.rs deleted file mode 100644 index 75647c027e14..000000000000 --- a/tests/ui/vtable_address_comparisons.rs +++ /dev/null @@ -1,52 +0,0 @@ -use std::fmt::Debug; -use std::ptr; -use std::rc::Rc; -use std::sync::Arc; - -#[warn(clippy::vtable_address_comparisons)] -#[allow(clippy::borrow_as_ptr)] - -fn main() { - let a: *const dyn Debug = &1 as &dyn Debug; - let b: *const dyn Debug = &1 as &dyn Debug; - - // These should fail: - let _ = a == b; - //~^ ERROR: comparing trait object pointers compares a non-unique vtable address - let _ = a != b; - //~^ ERROR: comparing trait object pointers compares a non-unique vtable address - let _ = a < b; - //~^ ERROR: comparing trait object pointers compares a non-unique vtable address - let _ = a <= b; - //~^ ERROR: comparing trait object pointers compares a non-unique vtable address - let _ = a > b; - //~^ ERROR: comparing trait object pointers compares a non-unique vtable address - let _ = a >= b; - //~^ ERROR: comparing trait object pointers compares a non-unique vtable address - ptr::eq(a, b); - //~^ ERROR: comparing trait object pointers compares a non-unique vtable address - - let a = &1 as &dyn Debug; - let b = &1 as &dyn Debug; - ptr::eq(a, b); - //~^ ERROR: comparing trait object pointers compares a non-unique vtable address - - // These should be fine: - let a = &1; - ptr::eq(a, a); - - let a = Rc::new(1); - Rc::ptr_eq(&a, &a); - - let a = Arc::new(1); - Arc::ptr_eq(&a, &a); - - let a: Rc = Rc::new(1); - Rc::ptr_eq(&a, &a); - - let a: Arc = Arc::new(1); - Arc::ptr_eq(&a, &a); - - let a: &[u8] = b""; - ptr::eq(a, a); -} diff --git a/tests/ui/vtable_address_comparisons.stderr b/tests/ui/vtable_address_comparisons.stderr deleted file mode 100644 index 83c82f3796eb..000000000000 --- a/tests/ui/vtable_address_comparisons.stderr +++ /dev/null @@ -1,68 +0,0 @@ -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:14:13 - | -LL | let _ = a == b; - | ^^^^^^ - | - = help: consider extracting and comparing data pointers only - = note: `-D clippy::vtable-address-comparisons` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::vtable_address_comparisons)]` - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:16:13 - | -LL | let _ = a != b; - | ^^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:18:13 - | -LL | let _ = a < b; - | ^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:20:13 - | -LL | let _ = a <= b; - | ^^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:22:13 - | -LL | let _ = a > b; - | ^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:24:13 - | -LL | let _ = a >= b; - | ^^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:26:5 - | -LL | ptr::eq(a, b); - | ^^^^^^^^^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:31:5 - | -LL | ptr::eq(a, b); - | ^^^^^^^^^^^^^ - | - = help: consider extracting and comparing data pointers only - -error: aborting due to 8 previous errors - From 0f5d94e7fea67fd7abbffca4f5777cd5939fdf68 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 5 Dec 2023 21:39:36 +0000 Subject: [PATCH 1005/1222] coro_kind -> coroutine_kind --- clippy_lints/src/doc/needless_doctest_main.rs | 2 +- clippy_utils/src/ast_utils.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/doc/needless_doctest_main.rs b/clippy_lints/src/doc/needless_doctest_main.rs index 640d4a069ec7..e019523e6098 100644 --- a/clippy_lints/src/doc/needless_doctest_main.rs +++ b/clippy_lints/src/doc/needless_doctest_main.rs @@ -69,7 +69,7 @@ pub fn check( if !ignore { get_test_spans(&item, &mut test_attr_spans); } - let is_async = matches!(sig.header.coro_kind, Some(CoroutineKind::Async { .. })); + let is_async = matches!(sig.header.coroutine_kind, Some(CoroutineKind::Async { .. })); let returns_nothing = match &sig.decl.output { FnRetTy::Default(..) => true, FnRetTy::Ty(ty) if ty.kind.is_unit() => true, diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 12403bbff3c9..8373627d6a0e 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -188,7 +188,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { Closure(box ast::Closure { binder: lb, capture_clause: lc, - coro_kind: la, + coroutine_kind: la, movability: lm, fn_decl: lf, body: le, @@ -197,7 +197,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { Closure(box ast::Closure { binder: rb, capture_clause: rc, - coro_kind: ra, + coroutine_kind: ra, movability: rm, fn_decl: rf, body: re, @@ -563,7 +563,7 @@ pub fn eq_fn_sig(l: &FnSig, r: &FnSig) -> bool { eq_fn_decl(&l.decl, &r.decl) && eq_fn_header(&l.header, &r.header) } -fn eq_opt_coro_kind(l: Option, r: Option) -> bool { +fn eq_opt_coroutine_kind(l: Option, r: Option) -> bool { match (l, r) { (Some(CoroutineKind::Async { .. }), Some(CoroutineKind::Async { .. })) | (Some(CoroutineKind::Gen { .. }), Some(CoroutineKind::Gen { .. })) => true, @@ -574,7 +574,7 @@ fn eq_opt_coro_kind(l: Option, r: Option) -> bool pub fn eq_fn_header(l: &FnHeader, r: &FnHeader) -> bool { matches!(l.unsafety, Unsafe::No) == matches!(r.unsafety, Unsafe::No) - && eq_opt_coro_kind(l.coro_kind, r.coro_kind) + && eq_opt_coroutine_kind(l.coroutine_kind, r.coroutine_kind) && matches!(l.constness, Const::No) == matches!(r.constness, Const::No) && eq_ext(&l.ext, &r.ext) } From 33f7c94b98f572792015d2e6275429ccf937ce3f Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 5 Dec 2023 21:53:18 +0000 Subject: [PATCH 1006/1222] Make some matches exhaustive to avoid bugs, fix tools --- clippy_utils/src/ast_utils.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 8373627d6a0e..b4fe67023d86 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -566,7 +566,8 @@ pub fn eq_fn_sig(l: &FnSig, r: &FnSig) -> bool { fn eq_opt_coroutine_kind(l: Option, r: Option) -> bool { match (l, r) { (Some(CoroutineKind::Async { .. }), Some(CoroutineKind::Async { .. })) - | (Some(CoroutineKind::Gen { .. }), Some(CoroutineKind::Gen { .. })) => true, + | (Some(CoroutineKind::Gen { .. }), Some(CoroutineKind::Gen { .. })) + | (Some(CoroutineKind::AsyncGen { .. }), Some(CoroutineKind::AsyncGen { .. })) => true, (None, None) => true, _ => false, } From 5c9167a192afef9171ad65f51d3d939d611e4496 Mon Sep 17 00:00:00 2001 From: surechen Date: Fri, 10 Nov 2023 10:11:24 +0800 Subject: [PATCH 1007/1222] remove redundant imports detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR. --- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/loops/manual_memcpy.rs | 1 - clippy_lints/src/loops/needless_range_loop.rs | 2 +- clippy_lints/src/loops/never_loop.rs | 2 +- clippy_lints/src/loops/same_item_push.rs | 1 - clippy_lints/src/loops/utils.rs | 1 - clippy_lints/src/methods/option_map_unwrap_or.rs | 2 +- clippy_lints/src/missing_inline.rs | 2 +- 8 files changed, 5 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index ae1e69a4f232..3452f98c5aad 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_hir; -use rustc_hir::{self, intravisit, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node, Pat, PatKind}; +use rustc_hir::{intravisit, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node, Pat, PatKind}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index 40d56240b9de..fda6c9749d43 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -12,7 +12,6 @@ use rustc_lint::LateContext; use rustc_middle::ty::{self, Ty}; use rustc_span::symbol::sym; use std::fmt::Display; -use std::iter::Iterator; /// Checks for `for` loops that sequentially copy items from one slice-like /// object to another. diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index e2be861a7089..28abecd04297 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -13,7 +13,7 @@ use rustc_lint::LateContext; use rustc_middle::middle::region; use rustc_middle::ty::{self, Ty}; use rustc_span::symbol::{sym, Symbol}; -use std::iter::{self, Iterator}; +use std::iter::{self}; use std::mem; /// Checks for looping over a range and then indexing a sequence with it. diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index cc054cb46692..62bc663191f6 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -8,7 +8,7 @@ use rustc_errors::Applicability; use rustc_hir::{Block, Destination, Expr, ExprKind, HirId, InlineAsmOperand, Pat, Stmt, StmtKind}; use rustc_lint::LateContext; use rustc_span::{sym, Span}; -use std::iter::{once, Iterator}; +use std::iter::once; pub(super) fn check<'tcx>( cx: &LateContext<'tcx>, diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index 15e11fd386cd..f4eaf649f77b 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -11,7 +11,6 @@ use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Mutability, Nod use rustc_lint::LateContext; use rustc_span::symbol::sym; use rustc_span::SyntaxContext; -use std::iter::Iterator; /// Detects for loop pushing the same item into a Vec pub(super) fn check<'tcx>( diff --git a/clippy_lints/src/loops/utils.rs b/clippy_lints/src/loops/utils.rs index 38fdca573c6b..e685274adb8d 100644 --- a/clippy_lints/src/loops/utils.rs +++ b/clippy_lints/src/loops/utils.rs @@ -9,7 +9,6 @@ use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, Ty}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{sym, Symbol}; -use std::iter::Iterator; #[derive(Debug, PartialEq, Eq)] enum IncrementVisitorVarState { diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 575c2d8f1575..826c3de1db5d 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::intravisit::{walk_path, Visitor}; -use rustc_hir::{self, ExprKind, HirId, Node, PatKind, Path, QPath}; +use rustc_hir::{ExprKind, HirId, Node, PatKind, Path, QPath}; use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; use rustc_span::{sym, Span}; diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 07bcbfc4ff4d..7393b39c8f60 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_ast::ast; use rustc_hir as hir; -use rustc_lint::{self, LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::declare_lint_pass; use rustc_span::{sym, Span}; From 6e2c50c14d4e4c59c469dbd5106fb8d5c2e7c8eb Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 10 Dec 2023 13:06:18 +0000 Subject: [PATCH 1008/1222] fix clippy --- clippy_lints/src/derive.rs | 4 +-- clippy_lints/src/implied_bounds_in_impls.rs | 4 +++ clippy_lints/src/loops/explicit_iter_loop.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 1 + clippy_utils/src/ty.rs | 34 +++++++++++++------- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 61faaa10b8a4..d8abe411030b 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -450,12 +450,12 @@ fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_r && let Some(def_id) = trait_ref.trait_def_id() && cx.tcx.is_diagnostic_item(sym::PartialEq, def_id) && let param_env = param_env_for_derived_eq(cx.tcx, adt.did(), eq_trait_def_id) - && !implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, &[]) + && !implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, adt.did(),&[]) // If all of our fields implement `Eq`, we can implement `Eq` too && adt .all_fields() .map(|f| f.ty(cx.tcx, args)) - .all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, &[])) + .all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, adt.did(), &[])) { span_lint_and_sugg( cx, diff --git a/clippy_lints/src/implied_bounds_in_impls.rs b/clippy_lints/src/implied_bounds_in_impls.rs index 9a66cbde53c0..4811691c80d1 100644 --- a/clippy_lints/src/implied_bounds_in_impls.rs +++ b/clippy_lints/src/implied_bounds_in_impls.rs @@ -194,6 +194,10 @@ fn is_same_generics<'tcx>( .enumerate() .skip(1) // skip `Self` implicit arg .all(|(arg_index, arg)| { + if [implied_by_generics.host_effect_index, implied_generics.host_effect_index].contains(&Some(arg_index)) { + // skip host effect params in determining whether generics are same + return true; + } if let Some(ty) = arg.as_type() { if let &ty::Param(ty::ParamTy { index, .. }) = ty.kind() // `index == 0` means that it's referring to `Self`, diff --git a/clippy_lints/src/loops/explicit_iter_loop.rs b/clippy_lints/src/loops/explicit_iter_loop.rs index 1c2b7a169fc3..c7980060807c 100644 --- a/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_iter_loop.rs @@ -118,7 +118,7 @@ fn is_ref_iterable<'tcx>( .liberate_late_bound_regions(fn_id, cx.tcx.fn_sig(fn_id).skip_binder()) && let &[req_self_ty, req_res_ty] = &**sig.inputs_and_output && let param_env = cx.tcx.param_env(fn_id) - && implements_trait_with_env(cx.tcx, param_env, req_self_ty, trait_id, &[]) + && implements_trait_with_env(cx.tcx, param_env, req_self_ty, trait_id, fn_id, &[]) && let Some(into_iter_ty) = make_normalized_projection_with_regions(cx.tcx, param_env, trait_id, sym!(IntoIter), [req_self_ty]) && let req_res_ty = normalize_with_regions(cx.tcx, param_env, req_res_ty) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 27da44812eb1..2c5c3dcaa752 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -186,6 +186,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { cx.param_env, ty, t, + None, [Option::>::None], ) }) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 1e748a46922c..868c92f2f54d 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -214,7 +214,8 @@ pub fn implements_trait<'tcx>( trait_id: DefId, args: &[GenericArg<'tcx>], ) -> bool { - implements_trait_with_env_from_iter(cx.tcx, cx.param_env, ty, trait_id, args.iter().map(|&x| Some(x))) + let callee_id = cx.enclosing_body.map(|body| cx.tcx.hir().body_owner(body).owner.to_def_id()); + implements_trait_with_env_from_iter(cx.tcx, cx.param_env, ty, trait_id, callee_id, args.iter().map(|&x| Some(x))) } /// Same as `implements_trait` but allows using a `ParamEnv` different from the lint context. @@ -223,9 +224,10 @@ pub fn implements_trait_with_env<'tcx>( param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, trait_id: DefId, + callee_id: DefId, args: &[GenericArg<'tcx>], ) -> bool { - implements_trait_with_env_from_iter(tcx, param_env, ty, trait_id, args.iter().map(|&x| Some(x))) + implements_trait_with_env_from_iter(tcx, param_env, ty, trait_id, Some(callee_id), args.iter().map(|&x| Some(x))) } /// Same as `implements_trait_from_env` but takes the arguments as an iterator. @@ -234,6 +236,7 @@ pub fn implements_trait_with_env_from_iter<'tcx>( param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, trait_id: DefId, + callee_id: Option, args: impl IntoIterator>>>, ) -> bool { // Clippy shouldn't have infer types @@ -245,20 +248,29 @@ pub fn implements_trait_with_env_from_iter<'tcx>( } let infcx = tcx.infer_ctxt().build(); + let args = args.into_iter().map(|arg| { + arg.into().unwrap_or_else(|| { + let orig = TypeVariableOrigin { + kind: TypeVariableOriginKind::MiscVariable, + span: DUMMY_SP, + }; + infcx.next_ty_var(orig).into() + }) + }).collect::>(); + + // If an effect arg was not specified, we need to specify it. + let effect_arg = if tcx.generics_of(trait_id).host_effect_index.is_some_and(|x| args.get(x - 1).is_none()) { + Some(GenericArg::from(callee_id.map(|def_id| tcx.expected_host_effect_param_for_body(def_id)).unwrap_or(tcx.consts.true_))) + } else { + None + }; + let trait_ref = TraitRef::new( tcx, trait_id, Some(GenericArg::from(ty)) .into_iter() - .chain(args.into_iter().map(|arg| { - arg.into().unwrap_or_else(|| { - let orig = TypeVariableOrigin { - kind: TypeVariableOriginKind::MiscVariable, - span: DUMMY_SP, - }; - infcx.next_ty_var(orig).into() - }) - })), + .chain(args).chain(effect_arg), ); debug_assert_matches!( From aab7ce66be7643ca11aed21fabe72adfce12755d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 12 Oct 2023 15:36:14 +1100 Subject: [PATCH 1009/1222] Add spacing information to delimiters. This is an extension of the previous commit. It means the output of something like this: ``` stringify!(let a: Vec = vec![];) ``` goes from this: ``` let a: Vec = vec![] ; ``` With this PR, it now produces this string: ``` let a: Vec = vec![]; ``` --- clippy_lints/src/crate_in_macro_def.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/crate_in_macro_def.rs b/clippy_lints/src/crate_in_macro_def.rs index d4828778be28..b1aa472aa03f 100644 --- a/clippy_lints/src/crate_in_macro_def.rs +++ b/clippy_lints/src/crate_in_macro_def.rs @@ -92,7 +92,7 @@ fn contains_unhygienic_crate_reference(tts: &TokenStream) -> Option { { return Some(span); } - if let TokenTree::Delimited(_, _, tts) = &curr { + if let TokenTree::Delimited(.., tts) = &curr { let span = contains_unhygienic_crate_reference(tts); if span.is_some() { return span; From 000db24ec79a4e5a8bce6ee5a602291328a2b6be Mon Sep 17 00:00:00 2001 From: zetanumbers Date: Fri, 1 Dec 2023 05:28:34 -0800 Subject: [PATCH 1010/1222] Move some methods from `tcx.hir()` to `tcx` Renamings: - find -> opt_hir_node - get -> hir_node - find_by_def_id -> opt_hir_node_by_def_id - get_by_def_id -> hir_node_by_def_id Fix rebase changes using removed methods Use `tcx.hir_node_by_def_id()` whenever possible in compiler Fix clippy errors Fix compiler Apply suggestions from code review Co-authored-by: Vadim Petrochenkov Add FIXME for `tcx.hir()` returned type about its removal Simplify with with `tcx.hir_node_by_def_id` --- clippy_lints/src/absolute_paths.rs | 2 +- .../src/casts/cast_slice_different_sizes.rs | 2 +- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/derivable_impls.rs | 2 +- clippy_lints/src/empty_drop.rs | 2 +- clippy_lints/src/escape.rs | 12 ++++++------ clippy_lints/src/exit.rs | 2 +- clippy_lints/src/explicit_write.rs | 2 +- clippy_lints/src/functions/result.rs | 2 +- clippy_lints/src/index_refutable_slice.rs | 4 ++-- clippy_lints/src/inherent_impl.rs | 2 +- clippy_lints/src/len_zero.rs | 2 +- clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/loops/mut_range_bound.rs | 2 +- clippy_lints/src/loops/same_item_push.rs | 4 ++-- clippy_lints/src/manual_async_fn.rs | 2 +- clippy_lints/src/manual_rem_euclid.rs | 2 +- clippy_lints/src/methods/filter_next.rs | 2 +- clippy_lints/src/methods/iter_skip_next.rs | 2 +- clippy_lints/src/methods/option_map_unwrap_or.rs | 4 ++-- clippy_lints/src/min_ident_chars.rs | 2 +- clippy_lints/src/missing_const_for_fn.rs | 2 +- clippy_lints/src/missing_fields_in_debug.rs | 2 +- .../src/mixed_read_write_in_expression.rs | 2 +- clippy_lints/src/needless_pass_by_ref_mut.rs | 9 +++++---- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/non_send_fields_in_send_ty.rs | 3 +-- clippy_lints/src/redundant_locals.rs | 2 +- clippy_lints/src/same_name_method.rs | 2 +- clippy_lints/src/self_named_constructors.rs | 2 +- clippy_lints/src/suspicious_trait_impl.rs | 2 +- clippy_lints/src/types/mod.rs | 5 ++--- .../src/unnecessary_struct_initialization.rs | 2 +- clippy_lints/src/useless_conversion.rs | 2 +- .../utils/internal_lints/unnecessary_def_path.rs | 2 +- clippy_lints/src/zero_sized_map_values.rs | 2 +- clippy_utils/src/check_proc_macro.rs | 2 +- clippy_utils/src/consts.rs | 2 +- clippy_utils/src/lib.rs | 16 ++++++++-------- 39 files changed, 59 insertions(+), 60 deletions(-) diff --git a/clippy_lints/src/absolute_paths.rs b/clippy_lints/src/absolute_paths.rs index 83d15c0c4252..3822b83b4bc6 100644 --- a/clippy_lints/src/absolute_paths.rs +++ b/clippy_lints/src/absolute_paths.rs @@ -62,7 +62,7 @@ impl LateLintPass<'_> for AbsolutePaths { } = self; if !path.span.from_expansion() - && let Some(node) = cx.tcx.hir().find(hir_id) + && let Some(node) = cx.tcx.opt_hir_node(hir_id) && !matches!(node, Node::Item(item) if matches!(item.kind, ItemKind::Use(_, _))) && let [first, rest @ ..] = path.segments // Handle `::std` diff --git a/clippy_lints/src/casts/cast_slice_different_sizes.rs b/clippy_lints/src/casts/cast_slice_different_sizes.rs index 2a9f7fec1722..91bad8256ecb 100644 --- a/clippy_lints/src/casts/cast_slice_different_sizes.rs +++ b/clippy_lints/src/casts/cast_slice_different_sizes.rs @@ -69,7 +69,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv fn is_child_of_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let map = cx.tcx.hir(); if let Some(parent_id) = map.opt_parent_id(expr.hir_id) - && let Some(parent) = map.find(parent_id) + && let Some(parent) = cx.tcx.opt_hir_node(parent_id) { let expr = match parent { Node::Block(block) => { diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 854324f845b4..aaef163ad554 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1090,7 +1090,7 @@ fn report<'tcx>( if parent_id == data.first_expr.hir_id { return; } - (cx.tcx.hir().get(parent_id).expect_expr().span, true) + (cx.tcx.hir_node(parent_id).expect_expr().span, true) } else { (expr.span, false) }; diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index 53ef6d7e387e..6b0423200d76 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -195,7 +195,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { && let Some(def_id) = trait_ref.trait_def_id() && cx.tcx.is_diagnostic_item(sym::Default, def_id) && let impl_item_hir = child.id.hir_id() - && let Some(Node::ImplItem(impl_item)) = cx.tcx.hir().find(impl_item_hir) + && let Some(Node::ImplItem(impl_item)) = cx.tcx.opt_hir_node(impl_item_hir) && let ImplItemKind::Fn(_, b) = &impl_item.kind && let Body { value: func_expr, .. } = cx.tcx.hir().body(*b) && let &Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind() diff --git a/clippy_lints/src/empty_drop.rs b/clippy_lints/src/empty_drop.rs index e97030cc8b63..1d2b907b9482 100644 --- a/clippy_lints/src/empty_drop.rs +++ b/clippy_lints/src/empty_drop.rs @@ -42,7 +42,7 @@ impl LateLintPass<'_> for EmptyDrop { }) = item.kind && trait_ref.trait_def_id() == cx.tcx.lang_items().drop_trait() && let impl_item_hir = child.id.hir_id() - && let Some(Node::ImplItem(impl_item)) = cx.tcx.hir().find(impl_item_hir) + && let Some(Node::ImplItem(impl_item)) = cx.tcx.opt_hir_node(impl_item_hir) && let ImplItemKind::Fn(_, b) = &impl_item.kind && let Body { value: func_expr, .. } = cx.tcx.hir().body(*b) && let func_expr = peel_blocks(func_expr) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 3452f98c5aad..b7776263060b 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -5,7 +5,7 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::layout::LayoutOf; -use rustc_middle::ty::{self, TraitRef, Ty}; +use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt}; use rustc_session::impl_lint_pass; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::kw; @@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { .hir() .get_parent_item(cx.tcx.local_def_id_to_hir_id(fn_def_id)) .def_id; - let parent_node = cx.tcx.hir().find_by_def_id(parent_id); + let parent_node = cx.tcx.opt_hir_node_by_def_id(parent_id); let mut trait_self_ty = None; if let Some(Node::Item(item)) = parent_node { @@ -122,8 +122,8 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { } // TODO: Replace with Map::is_argument(..) when it's fixed -fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool { - match map.find(id) { +fn is_argument(tcx: TyCtxt<'_>, id: HirId) -> bool { + match tcx.opt_hir_node(id) { Some(Node::Pat(Pat { kind: PatKind::Binding(..), .. @@ -131,7 +131,7 @@ fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool { _ => return false, } - matches!(map.find_parent(id), Some(Node::Param(_))) + matches!(tcx.hir().find_parent(id), Some(Node::Param(_))) } impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { @@ -154,7 +154,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) { if cmt.place.projections.is_empty() { let map = &self.cx.tcx.hir(); - if is_argument(*map, cmt.hir_id) { + if is_argument(self.cx.tcx, cmt.hir_id) { // Skip closure arguments let parent_id = map.parent_id(cmt.hir_id); if let Some(Node::Expr(..)) = map.find_parent(parent_id) { diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index a974c10bc7dc..6603512c73cd 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit { && let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id() && cx.tcx.is_diagnostic_item(sym::process_exit, def_id) && let parent = cx.tcx.hir().get_parent_item(e.hir_id).def_id - && let Some(Node::Item(Item{kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find_by_def_id(parent) + && let Some(Node::Item(Item{kind: ItemKind::Fn(..), ..})) = cx.tcx.opt_hir_node_by_def_id(parent) // If the next item up is a function we check if it is an entry point // and only then emit a linter warning && !is_entrypoint_fn(cx, parent.to_def_id()) diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 4e2e1d1724a5..f1366c434f4f 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -111,7 +111,7 @@ fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>) // Find id of the local that expr_end_of_block resolves to && let ExprKind::Path(QPath::Resolved(None, expr_path)) = expr_end_of_block.kind && let Res::Local(expr_res) = expr_path.res - && let Some(Node::Pat(res_pat)) = cx.tcx.hir().find(expr_res) + && let Some(Node::Pat(res_pat)) = cx.tcx.opt_hir_node(expr_res) // Find id of the local we found in the block && let PatKind::Binding(BindingAnnotation::NONE, local_hir_id, _ident, None) = local.pat.kind diff --git a/clippy_lints/src/functions/result.rs b/clippy_lints/src/functions/result.rs index 5e90fcd72ebe..f1200c2edc13 100644 --- a/clippy_lints/src/functions/result.rs +++ b/clippy_lints/src/functions/result.rs @@ -92,7 +92,7 @@ fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty .expect("already checked this is adt") .did() .as_local() - && let Some(hir::Node::Item(item)) = cx.tcx.hir().find_by_def_id(local_def_id) + && let Some(hir::Node::Item(item)) = cx.tcx.opt_hir_node_by_def_id(local_def_id) && let hir::ItemKind::Enum(ref def, _) = item.kind { let variants_size = AdtVariantInfo::new(cx, *adt, subst); diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index b6f9d8b81f82..5417c13d0796 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -248,7 +248,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> { // Checking for slice indexing && let parent_id = map.parent_id(expr.hir_id) - && let Some(hir::Node::Expr(parent_expr)) = map.find(parent_id) + && let Some(hir::Node::Expr(parent_expr)) = cx.tcx.opt_hir_node(parent_id) && let hir::ExprKind::Index(_, index_expr, _) = parent_expr.kind && let Some(Constant::Int(index_value)) = constant(cx, cx.typeck_results(), index_expr) && let Ok(index_value) = index_value.try_into() @@ -256,7 +256,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> { // Make sure that this slice index is read only && let maybe_addrof_id = map.parent_id(parent_id) - && let Some(hir::Node::Expr(maybe_addrof_expr)) = map.find(maybe_addrof_id) + && let Some(hir::Node::Expr(maybe_addrof_expr)) = cx.tcx.opt_hir_node(maybe_addrof_id) && let hir::ExprKind::AddrOf(_kind, hir::Mutability::Not, _inner_expr) = maybe_addrof_expr.kind { use_info.index_use.push((index_value, map.span(parent_expr.hir_id))); diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index 5c926133c427..e4781752e757 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -122,7 +122,7 @@ fn get_impl_span(cx: &LateContext<'_>, id: LocalDefId) -> Option { kind: ItemKind::Impl(impl_item), span, .. - }) = cx.tcx.hir().get(id) + }) = cx.tcx.hir_node(id) { (!span.from_expansion() && impl_item.generics.params.is_empty() diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index e121da776b21..83af551fcd3c 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero { && let Some(output) = parse_len_output(cx, cx.tcx.fn_sig(item.owner_id).instantiate_identity().skip_binder()) { - let (name, kind) = match cx.tcx.hir().find(ty_hir_id) { + let (name, kind) = match cx.tcx.opt_hir_node(ty_hir_id) { Some(Node::ForeignItem(x)) => (x.ident.name, "extern type"), Some(Node::Item(x)) => match x.kind { ItemKind::Struct(..) => (x.ident.name, "struct"), diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 17ca48683b3c..ffef84d1fade 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -195,7 +195,7 @@ fn check_fn_inner<'tcx>( .iter() // In principle, the result of the call to `Node::ident` could be `unwrap`ped, as `DefId` should refer to a // `Node::GenericParam`. - .filter_map(|&def_id| cx.tcx.hir().get_by_def_id(def_id).ident()) + .filter_map(|&def_id| cx.tcx.hir_node_by_def_id(def_id).ident()) .map(|ident| ident.to_string()) .collect::>() .join(", "); diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index 227096251a55..c4e60e98ad46 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -40,7 +40,7 @@ fn mut_warn_with_span(cx: &LateContext<'_>, span: Option) { fn check_for_mutability(cx: &LateContext<'_>, bound: &Expr<'_>) -> Option { if let Some(hir_id) = path_to_local(bound) - && let Node::Pat(pat) = cx.tcx.hir().get(hir_id) + && let Node::Pat(pat) = cx.tcx.hir_node(hir_id) && let PatKind::Binding(BindingAnnotation::MUT, ..) = pat.kind { return Some(hir_id); diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index f4eaf649f77b..c245eaf1ab44 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -58,12 +58,12 @@ pub(super) fn check<'tcx>( match cx.qpath_res(qpath, pushed_item.hir_id) { // immutable bindings that are initialized with literal or constant Res::Local(hir_id) => { - let node = cx.tcx.hir().get(hir_id); + let node = cx.tcx.hir_node(hir_id); if let Node::Pat(pat) = node && let PatKind::Binding(bind_ann, ..) = pat.kind && !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut)) && let parent_node = cx.tcx.hir().parent_id(hir_id) - && let Some(Node::Local(parent_let_expr)) = cx.tcx.hir().find(parent_node) + && let Some(Node::Local(parent_let_expr)) = cx.tcx.opt_hir_node(parent_node) && let Some(init) = parent_let_expr.init { match init.kind { diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index ee053ffe4eca..eaaaea0be9f8 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn { && block.stmts.is_empty() && let Some(closure_body) = desugared_async_block(cx, block) && let Node::Item(Item {vis_span, ..}) | Node::ImplItem(ImplItem {vis_span, ..}) = - cx.tcx.hir().get_by_def_id(def_id) + cx.tcx.hir_node_by_def_id(def_id) { let header_span = span.with_hi(ret_ty.span.hi()); diff --git a/clippy_lints/src/manual_rem_euclid.rs b/clippy_lints/src/manual_rem_euclid.rs index e006df7d6666..71a83a68db93 100644 --- a/clippy_lints/src/manual_rem_euclid.rs +++ b/clippy_lints/src/manual_rem_euclid.rs @@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid { // Also ensures the const is nonzero since zero can't be a divisor && const1 == const2 && const2 == const3 && let Some(hir_id) = path_to_local(expr3) - && let Some(Node::Pat(_)) = cx.tcx.hir().find(hir_id) + && let Some(Node::Pat(_)) = cx.tcx.opt_hir_node(hir_id) { // Apply only to params or locals with annotated types match cx.tcx.hir().find_parent(hir_id) { diff --git a/clippy_lints/src/methods/filter_next.rs b/clippy_lints/src/methods/filter_next.rs index ac7bc9bcca47..9251130a3054 100644 --- a/clippy_lints/src/methods/filter_next.rs +++ b/clippy_lints/src/methods/filter_next.rs @@ -44,7 +44,7 @@ pub(super) fn check<'tcx>( // add note if not multi-line span_lint_and_then(cx, FILTER_NEXT, expr.span, msg, |diag| { let (applicability, pat) = if let Some(id) = path_to_local(recv) - && let Some(hir::Node::Pat(pat)) = cx.tcx.hir().find(id) + && let Some(hir::Node::Pat(pat)) = cx.tcx.opt_hir_node(id) && let hir::PatKind::Binding(BindingAnnotation(_, Mutability::Not), _, ident, _) = pat.kind { (Applicability::Unspecified, Some((pat.span, ident))) diff --git a/clippy_lints/src/methods/iter_skip_next.rs b/clippy_lints/src/methods/iter_skip_next.rs index fbe20dfe54ec..d1215290dada 100644 --- a/clippy_lints/src/methods/iter_skip_next.rs +++ b/clippy_lints/src/methods/iter_skip_next.rs @@ -20,7 +20,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr "called `skip(..).next()` on an iterator", |diag| { if let Some(id) = path_to_local(recv) - && let Node::Pat(pat) = cx.tcx.hir().get(id) + && let Node::Pat(pat) = cx.tcx.hir_node(id) && let PatKind::Binding(ann, _, _, _) = pat.kind && ann != BindingAnnotation::MUT { diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 826c3de1db5d..63e64a5b35d0 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -135,7 +135,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrapVisitor<'a, 'tcx> { fn visit_path(&mut self, path: &Path<'tcx>, _: HirId) { if let Res::Local(local_id) = path.res - && let Some(Node::Pat(pat)) = self.cx.tcx.hir().find(local_id) + && let Some(Node::Pat(pat)) = self.cx.tcx.opt_hir_node(local_id) && let PatKind::Binding(_, local_id, ..) = pat.kind { self.identifiers.insert(local_id); @@ -166,7 +166,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReferenceVisitor<'a, 'tcx> { && let ExprKind::Path(ref path) = expr.kind && let QPath::Resolved(_, path) = path && let Res::Local(local_id) = path.res - && let Some(Node::Pat(pat)) = self.cx.tcx.hir().find(local_id) + && let Some(Node::Pat(pat)) = self.cx.tcx.opt_hir_node(local_id) && let PatKind::Binding(_, local_id, ..) = pat.kind && self.identifiers.contains(&local_id) { diff --git a/clippy_lints/src/min_ident_chars.rs b/clippy_lints/src/min_ident_chars.rs index f5b749c7f800..34b8e0dbe6a7 100644 --- a/clippy_lints/src/min_ident_chars.rs +++ b/clippy_lints/src/min_ident_chars.rs @@ -91,7 +91,7 @@ impl Visitor<'_> for IdentVisitor<'_, '_> { let node = if hir_id.local_id == ItemLocalId::from_u32(0) { // In this case, we can just use `find`, `Owner`'s `node` field is private anyway so we can't // reimplement it even if we wanted to - cx.tcx.hir().find(hir_id) + cx.tcx.opt_hir_node(hir_id) } else { let Some(owner) = cx.tcx.hir_owner_nodes(hir_id.owner).as_owner() else { return; diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 5f736898159d..acaa6be30092 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { { let parent = cx.tcx.hir().get_parent_item(hir_id).def_id; if parent != CRATE_DEF_ID { - if let hir::Node::Item(item) = cx.tcx.hir().get_by_def_id(parent) { + if let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(parent) { if let hir::ItemKind::Trait(..) = &item.kind { return; } diff --git a/clippy_lints/src/missing_fields_in_debug.rs b/clippy_lints/src/missing_fields_in_debug.rs index 8be45b8c2f35..88b331ddefdb 100644 --- a/clippy_lints/src/missing_fields_in_debug.rs +++ b/clippy_lints/src/missing_fields_in_debug.rs @@ -220,7 +220,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingFieldsInDebug { && let self_ty = cx.tcx.type_of(self_path_did).skip_binder().peel_refs() && let Some(self_adt) = self_ty.ty_adt_def() && let Some(self_def_id) = self_adt.did().as_local() - && let Some(Node::Item(self_item)) = cx.tcx.hir().find_by_def_id(self_def_id) + && let Some(Node::Item(self_item)) = cx.tcx.opt_hir_node_by_def_id(self_def_id) // NB: can't call cx.typeck_results() as we are not in a body && let typeck_results = cx.tcx.typeck_body(*body_id) && should_lint(cx, typeck_results, block) diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs index cd180754113f..34119c6911c5 100644 --- a/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/clippy_lints/src/mixed_read_write_in_expression.rs @@ -213,7 +213,7 @@ fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) { if parent_id == cur_id { break; } - let Some(parent_node) = map.find(parent_id) else { break }; + let Some(parent_node) = vis.cx.tcx.opt_hir_node(parent_id) else { break }; let stop_early = match parent_node { Node::Expr(expr) => check_expr(vis, expr), diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index 13b736cd9ad8..64ef709e2fa2 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -113,8 +113,9 @@ fn check_closures<'tcx>( } ctx.prev_bind = None; ctx.prev_move_to_closure.clear(); - if let Some(body) = hir - .find_by_def_id(closure) + if let Some(body) = cx + .tcx + .opt_hir_node_by_def_id(closure) .and_then(associated_body) .map(|(_, body_id)| hir.body(body_id)) { @@ -412,7 +413,7 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt<'tcx> { ], ), .. - }) = self.tcx.hir().get(cmt.hir_id) + }) = self.tcx.hir_node(cmt.hir_id) { self.async_closures.insert(*def_id); } @@ -521,7 +522,7 @@ impl<'tcx> Visitor<'tcx> for FnNeedsMutVisitor<'_, 'tcx> { let Self { cx, used_fn_def_ids } = self; // #11182; do not lint if mutability is required elsewhere - if let Node::Expr(expr) = cx.tcx.hir().get(hir_id) + if let Node::Expr(expr) = cx.tcx.hir_node(hir_id) && let Some(parent) = get_parent_node(cx.tcx, expr.hir_id) && let ty::FnDef(def_id, _) = cx .tcx diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 4f8922aea178..4013cb34561a 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -454,7 +454,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { if parent_id == cur_expr.hir_id { break; } - if let Some(Node::Expr(parent_expr)) = cx.tcx.hir().find(parent_id) { + if let Some(Node::Expr(parent_expr)) = cx.tcx.opt_hir_node(parent_id) { match &parent_expr.kind { ExprKind::AddrOf(..) => { // `&e` => `e` must be referenced. diff --git a/clippy_lints/src/non_send_fields_in_send_ty.rs b/clippy_lints/src/non_send_fields_in_send_ty.rs index 352540d70b52..793a3a9545cd 100644 --- a/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -94,7 +94,6 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy { { let mut non_send_fields = Vec::new(); - let hir_map = cx.tcx.hir(); for variant in adt_def.variants() { for field in &variant.fields { if let Some(field_hir_id) = field @@ -104,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy { && !is_lint_allowed(cx, NON_SEND_FIELDS_IN_SEND_TY, field_hir_id) && let field_ty = field.ty(cx.tcx, impl_trait_args) && !ty_allowed_in_send(cx, field_ty, send_trait) - && let Node::Field(field_def) = hir_map.get(field_hir_id) + && let Node::Field(field_def) = cx.tcx.hir_node(field_hir_id) { non_send_fields.push(NonSendField { def: field_def, diff --git a/clippy_lints/src/redundant_locals.rs b/clippy_lints/src/redundant_locals.rs index 8c374d7d6db7..2c511ee0bc02 100644 --- a/clippy_lints/src/redundant_locals.rs +++ b/clippy_lints/src/redundant_locals.rs @@ -59,7 +59,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals { && last_segment.ident == ident // resolve the path to its defining binding pattern && let Res::Local(binding_id) = cx.qpath_res(&qpath, expr.hir_id) - && let Node::Pat(binding_pat) = cx.tcx.hir().get(binding_id) + && let Node::Pat(binding_pat) = cx.tcx.hir_node(binding_id) // the previous binding has the same mutability && find_binding(binding_pat, ident).is_some_and(|bind| bind.1 == mutability) // the local does not change the effect of assignments to the binding. see #11290 diff --git a/clippy_lints/src/same_name_method.rs b/clippy_lints/src/same_name_method.rs index 74193e0199f3..1316343e0c2f 100644 --- a/clippy_lints/src/same_name_method.rs +++ b/clippy_lints/src/same_name_method.rs @@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod { Some(trait_ref) => { let mut methods_in_trait: BTreeSet = if let Some(Node::TraitRef(TraitRef { path, .. - })) = cx.tcx.hir().find(trait_ref.hir_ref_id) + })) = cx.tcx.opt_hir_node(trait_ref.hir_ref_id) && let Res::Def(DefKind::Trait, did) = path.res { // FIXME: if diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index 935dd4a3630f..98f3235af10a 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -73,7 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { if let Some(self_def) = self_ty.ty_adt_def() && let Some(self_local_did) = self_def.did().as_local() && let self_id = cx.tcx.local_def_id_to_hir_id(self_local_did) - && let Some(Node::Item(x)) = cx.tcx.hir().find(self_id) + && let Some(Node::Item(x)) = cx.tcx.opt_hir_node(self_id) && let type_name = x.ident.name.as_str().to_lowercase() && (impl_item.ident.name.as_str() == type_name || impl_item.ident.name.as_str().replace('_', "") == type_name) diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index 268c0c1b2dfc..8eab3f5874e1 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl { // Check for more than one binary operation in the implemented function // Linting when multiple operations are involved can result in false positives && let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id - && let hir::Node::ImplItem(impl_item) = cx.tcx.hir().get_by_def_id(parent_fn) + && let hir::Node::ImplItem(impl_item) = cx.tcx.hir_node_by_def_id(parent_fn) && let hir::ImplItemKind::Fn(_, body_id) = impl_item.kind && let body = cx.tcx.hir().body(body_id) && let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 8e890b4df889..81efec65343d 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -321,7 +321,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { _: Span, def_id: LocalDefId, ) { - let is_in_trait_impl = if let Some(hir::Node::Item(item)) = cx.tcx.hir().find_by_def_id( + let is_in_trait_impl = if let Some(hir::Node::Item(item)) = cx.tcx.opt_hir_node_by_def_id( cx.tcx .hir() .get_parent_item(cx.tcx.local_def_id_to_hir_id(def_id)) @@ -368,8 +368,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { ImplItemKind::Const(ty, _) => { let is_in_trait_impl = if let Some(hir::Node::Item(item)) = cx .tcx - .hir() - .find_by_def_id(cx.tcx.hir().get_parent_item(item.hir_id()).def_id) + .opt_hir_node_by_def_id(cx.tcx.hir().get_parent_item(item.hir_id()).def_id) { matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) } else { diff --git a/clippy_lints/src/unnecessary_struct_initialization.rs b/clippy_lints/src/unnecessary_struct_initialization.rs index ed4d87ef8f8a..333ea0c82df6 100644 --- a/clippy_lints/src/unnecessary_struct_initialization.rs +++ b/clippy_lints/src/unnecessary_struct_initialization.rs @@ -82,7 +82,7 @@ impl LateLintPass<'_> for UnnecessaryStruct { fn is_mutable(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { if let Some(hir_id) = path_to_local(expr) - && let Node::Pat(pat) = cx.tcx.hir().get(hir_id) + && let Node::Pat(pat) = cx.tcx.hir_node(hir_id) { matches!(pat.kind, PatKind::Binding(BindingAnnotation::MUT, ..)) } else { diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 2ab24f70ae0b..2e0a0f6cb3e4 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -281,7 +281,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { } if let Some(id) = path_to_local(recv) - && let Node::Pat(pat) = cx.tcx.hir().get(id) + && let Node::Pat(pat) = cx.tcx.hir_node(id) && let PatKind::Binding(ann, ..) = pat.kind && ann != BindingAnnotation::MUT { diff --git a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs index 70ca1b206b43..31a81a524970 100644 --- a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs +++ b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs @@ -218,7 +218,7 @@ fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option match cx.qpath_res(qpath, expr.hir_id) { Res::Local(hir_id) => { let parent_id = cx.tcx.hir().parent_id(hir_id); - if let Some(Node::Local(Local { init: Some(init), .. })) = cx.tcx.hir().find(parent_id) { + if let Some(Node::Local(Local { init: Some(init), .. })) = cx.tcx.hir_node(parent_id) { path_to_matched_type(cx, init) } else { None diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index fba3808261ac..b36c4ef91dc6 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -74,7 +74,7 @@ impl LateLintPass<'_> for ZeroSizedMapValues { fn in_trait_impl(cx: &LateContext<'_>, hir_id: HirId) -> bool { let parent_id = cx.tcx.hir().get_parent_item(hir_id); let second_parent_id = cx.tcx.hir().get_parent_item(parent_id.into()).def_id; - if let Some(Node::Item(item)) = cx.tcx.hir().find_by_def_id(second_parent_id) { + if let Some(Node::Item(item)) = cx.tcx.opt_hir_node_by_def_id(second_parent_id) { if let ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind { return true; } diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index 3bac0626f885..3f68b6d75b59 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -269,7 +269,7 @@ fn fn_kind_pat(tcx: TyCtxt<'_>, kind: &FnKind<'_>, body: &Body<'_>, hir_id: HirI FnKind::Method(.., sig) => (fn_header_search_pat(sig.header), Pat::Str("")), FnKind::Closure => return (Pat::Str(""), expr_search_pat(tcx, body.value).1), }; - let start_pat = match tcx.hir().get(hir_id) { + let start_pat = match tcx.hir_node(hir_id) { Node::Item(Item { vis_span, .. }) | Node::ImplItem(ImplItem { vis_span, .. }) => { if vis_span.is_empty() { start_pat diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 35a8a7920a9d..727f93c83274 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -531,7 +531,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { kind: ExprKind::Lit(_), span, .. - }) = self.lcx.tcx.hir().get(body_id.hir_id) + }) = self.lcx.tcx.hir_node(body_id.hir_id) && is_direct_expn_of(*span, "cfg").is_some() { return None; diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index f3b63f1cdcf0..70a3c6f82c1c 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -176,10 +176,10 @@ pub fn expr_or_init<'a, 'b, 'tcx: 'b>(cx: &LateContext<'tcx>, mut expr: &'a Expr /// canonical binding `HirId`. pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<'tcx>> { let hir = cx.tcx.hir(); - if let Some(Node::Pat(pat)) = hir.find(hir_id) + if let Some(Node::Pat(pat)) = cx.tcx.opt_hir_node(hir_id) && matches!(pat.kind, PatKind::Binding(BindingAnnotation::NONE, ..)) && let parent = hir.parent_id(hir_id) - && let Some(Node::Local(local)) = hir.find(parent) + && let Some(Node::Local(local)) = cx.tcx.opt_hir_node(parent) { return local.init; } @@ -563,7 +563,7 @@ fn local_item_children_by_name(tcx: TyCtxt<'_>, local_id: LocalDefId, name: Symb let hir = tcx.hir(); let root_mod; - let item_kind = match hir.find_by_def_id(local_id) { + let item_kind = match tcx.opt_hir_node_by_def_id(local_id) { Some(Node::Crate(r#mod)) => { root_mod = ItemKind::Mod(r#mod); &root_mod @@ -712,7 +712,7 @@ pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, def_id: LocalDefId) -> let hir_id = cx.tcx.local_def_id_to_hir_id(def_id); let parent_impl = cx.tcx.hir().get_parent_item(hir_id); if parent_impl != hir::CRATE_OWNER_ID - && let hir::Node::Item(item) = cx.tcx.hir().get_by_def_id(parent_impl.def_id) + && let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(parent_impl.def_id) && let hir::ItemKind::Impl(impl_) = &item.kind { return impl_.of_trait.as_ref(); @@ -1242,7 +1242,7 @@ pub fn is_in_panic_handler(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { /// Gets the name of the item the expression is in, if available. pub fn get_item_name(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id).def_id; - match cx.tcx.hir().find_by_def_id(parent_id) { + match cx.tcx.opt_hir_node_by_def_id(parent_id) { Some( Node::Item(Item { ident, .. }) | Node::TraitItem(TraitItem { ident, .. }) @@ -1319,7 +1319,7 @@ pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio let map = &cx.tcx.hir(); let enclosing_node = map .get_enclosing_scope(hir_id) - .and_then(|enclosing_id| map.find(enclosing_id)); + .and_then(|enclosing_id| cx.tcx.opt_hir_node(enclosing_id)); enclosing_node.and_then(|node| match node { Node::Block(block) => Some(block), Node::Item(&Item { @@ -2691,7 +2691,7 @@ impl<'tcx> ExprUseNode<'tcx> { if let Some(Node::Expr(Expr { kind: ExprKind::Closure(c), .. - })) = cx.tcx.hir().find(hir_id) + })) = cx.tcx.opt_hir_node(hir_id) { match c.fn_decl.output { FnRetTy::DefaultReturn(_) => None, @@ -2757,7 +2757,7 @@ pub fn expr_use_ctxt<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> Optio walk_to_expr_usage(cx, e, &mut |parent, child_id| { // LocalTableInContext returns the wrong lifetime, so go use `expr_adjustments` instead. if adjustments.is_empty() - && let Node::Expr(e) = cx.tcx.hir().get(child_id) + && let Node::Expr(e) = cx.tcx.hir_node(child_id) { adjustments = cx.typeck_results().expr_adjustments(e); } From a66c4515fb3c87416af22f0af6567a00ecb0173d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 12 Dec 2023 19:07:19 +0000 Subject: [PATCH 1011/1222] Uplift TypeAndMut --- clippy_lints/src/casts/as_ptr_cast_mut.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/casts/as_ptr_cast_mut.rs b/clippy_lints/src/casts/as_ptr_cast_mut.rs index 55294f5f3864..b55cd8833b73 100644 --- a/clippy_lints/src/casts/as_ptr_cast_mut.rs +++ b/clippy_lints/src/casts/as_ptr_cast_mut.rs @@ -10,8 +10,8 @@ use super::AS_PTR_CAST_MUT; pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>) { if let ty::RawPtr( - ptrty @ TypeAndMut { - mutbl: Mutability::Mut, .. + TypeAndMut { + mutbl: Mutability::Mut, ty: ptrty, }, ) = cast_to.kind() && let ty::RawPtr(TypeAndMut { @@ -34,7 +34,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cx, AS_PTR_CAST_MUT, expr.span, - &format!("casting the result of `as_ptr` to *{ptrty}"), + &format!("casting the result of `as_ptr` to *mut {ptrty}"), "replace with", format!("{recv}.as_mut_ptr()"), applicability, From f3fed692d8c73940c5b5dc4258c6821a2cc8aecc Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 8 Dec 2023 01:52:56 +0000 Subject: [PATCH 1012/1222] Don't pass lint back out of lint decorator --- clippy_utils/src/diagnostics.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs index fa56e5b0ba2b..7562961538e3 100644 --- a/clippy_utils/src/diagnostics.rs +++ b/clippy_utils/src/diagnostics.rs @@ -49,7 +49,6 @@ pub fn span_lint(cx: &T, lint: &'static Lint, sp: impl Into( diag.help(help.to_string()); } docs_link(diag, lint); - diag }); } @@ -134,7 +132,6 @@ pub fn span_lint_and_note( diag.note(note); } docs_link(diag, lint); - diag }); } @@ -152,7 +149,6 @@ where cx.struct_span_lint(lint, sp, msg.to_string(), |diag| { f(diag); docs_link(diag, lint); - diag }); } @@ -160,7 +156,6 @@ pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, s #[expect(clippy::disallowed_methods)] cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg.to_string(), |diag| { docs_link(diag, lint); - diag }); } @@ -176,7 +171,6 @@ pub fn span_lint_hir_and_then( cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg.to_string(), |diag| { f(diag); docs_link(diag, lint); - diag }); } From 1b56ed0549c530f580a3a06aa3803235488f3762 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 28 Nov 2023 00:59:51 +0000 Subject: [PATCH 1013/1222] Appease the tools: clippy, rustdoc --- clippy_lints/src/len_zero.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 83af551fcd3c..8c032b170236 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -8,8 +8,8 @@ use rustc_hir::def::Res; use rustc_hir::def_id::{DefId, DefIdSet}; use rustc_hir::{ AssocItemKind, BinOpKind, Expr, ExprKind, FnRetTy, GenericArg, GenericBound, ImplItem, ImplItemKind, - ImplicitSelfKind, Item, ItemKind, LangItem, Mutability, Node, PatKind, PathSegment, PrimTy, QPath, TraitItemRef, - TyKind, TypeBindingKind, + ImplicitSelfKind, Item, ItemKind, Mutability, Node, PatKind, PathSegment, PrimTy, QPath, TraitItemRef, + TyKind, TypeBindingKind, OpaqueTyOrigin, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, AssocKind, FnSig, Ty}; @@ -289,8 +289,10 @@ fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<& kind: ItemKind::OpaqueTy(opaque), .. } = item - && opaque.bounds.len() == 1 - && let GenericBound::LangItemTrait(LangItem::Future, _, _, generic_args) = &opaque.bounds[0] + && let OpaqueTyOrigin::AsyncFn(_) = opaque.origin + && let [GenericBound::Trait(trait_ref, _)] = &opaque.bounds + && let Some(segment) = trait_ref.trait_ref.path.segments.last() + && let Some(generic_args) = segment.args && generic_args.bindings.len() == 1 && let TypeBindingKind::Equality { term: From 07b84486cfcdaeb5b3da5246655cd10f3ccd16e6 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sun, 17 Dec 2023 21:48:57 +1100 Subject: [PATCH 1014/1222] Rename `Handler` as `DiagCtxt`. --- clippy_lints/src/doc/needless_doctest_main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/doc/needless_doctest_main.rs b/clippy_lints/src/doc/needless_doctest_main.rs index e019523e6098..ccd6f22146b9 100644 --- a/clippy_lints/src/doc/needless_doctest_main.rs +++ b/clippy_lints/src/doc/needless_doctest_main.rs @@ -6,7 +6,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_ast::{CoroutineKind, Fn, FnRetTy, Item, ItemKind}; use rustc_data_structures::sync::Lrc; use rustc_errors::emitter::EmitterWriter; -use rustc_errors::Handler; +use rustc_errors::DiagCtxt; use rustc_lint::LateContext; use rustc_parse::maybe_new_parser_from_source_str; use rustc_parse::parser::ForceCollect; @@ -45,7 +45,7 @@ pub fn check( let fallback_bundle = rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false); let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle); - let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings(); + let handler = DiagCtxt::with_emitter(Box::new(emitter)).disable_warnings(); #[expect(clippy::arc_with_non_send_sync)] // `Lrc` is expected by with_span_handler let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sess = ParseSess::with_span_handler(handler, sm); From bc374f79c786e8c709013bd78336ab89541ad4c7 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sun, 17 Dec 2023 22:01:06 +1100 Subject: [PATCH 1015/1222] Rename `EarlyErrorHandler` as `EarlyDiagCtxt`. --- src/driver.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index 49f0cad08e01..af38dde254ed 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -18,7 +18,7 @@ extern crate rustc_span; use rustc_interface::interface; use rustc_session::config::ErrorOutputType; use rustc_session::parse::ParseSess; -use rustc_session::EarlyErrorHandler; +use rustc_session::EarlyDiagCtxt; use rustc_span::symbol::Symbol; use std::env; @@ -174,7 +174,7 @@ const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust-clippy/issues/ne #[allow(clippy::too_many_lines)] #[allow(clippy::ignored_unit_patterns)] pub fn main() { - let handler = EarlyErrorHandler::new(ErrorOutputType::default()); + let handler = EarlyDiagCtxt::new(ErrorOutputType::default()); rustc_driver::init_rustc_env_logger(&handler); From 7ca7362a090304fcece6b48460f2b39a3a242ec2 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 18 Dec 2023 07:52:43 +1100 Subject: [PATCH 1016/1222] Rename `ParseSess::with_span_handler` as `ParseSess::with_dcx`. --- clippy_lints/src/doc/needless_doctest_main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/doc/needless_doctest_main.rs b/clippy_lints/src/doc/needless_doctest_main.rs index ccd6f22146b9..b2ac39a8e9fa 100644 --- a/clippy_lints/src/doc/needless_doctest_main.rs +++ b/clippy_lints/src/doc/needless_doctest_main.rs @@ -46,9 +46,9 @@ pub fn check( rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false); let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle); let handler = DiagCtxt::with_emitter(Box::new(emitter)).disable_warnings(); - #[expect(clippy::arc_with_non_send_sync)] // `Lrc` is expected by with_span_handler + #[expect(clippy::arc_with_non_send_sync)] // `Lrc` is expected by with_dcx let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let sess = ParseSess::with_span_handler(handler, sm); + let sess = ParseSess::with_dcx(handler, sm); let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) { Ok(p) => p, From 3db34ffd550e04e46d0c517b44a7407a68dd7336 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 18 Dec 2023 11:15:13 +1100 Subject: [PATCH 1017/1222] Rename many `DiagCtxt` and `EarlyDiagCtxt` locals. --- clippy_lints/src/doc/needless_doctest_main.rs | 4 ++-- src/driver.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/doc/needless_doctest_main.rs b/clippy_lints/src/doc/needless_doctest_main.rs index b2ac39a8e9fa..c639813a3f9a 100644 --- a/clippy_lints/src/doc/needless_doctest_main.rs +++ b/clippy_lints/src/doc/needless_doctest_main.rs @@ -45,10 +45,10 @@ pub fn check( let fallback_bundle = rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false); let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle); - let handler = DiagCtxt::with_emitter(Box::new(emitter)).disable_warnings(); + let dcx = DiagCtxt::with_emitter(Box::new(emitter)).disable_warnings(); #[expect(clippy::arc_with_non_send_sync)] // `Lrc` is expected by with_dcx let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let sess = ParseSess::with_dcx(handler, sm); + let sess = ParseSess::with_dcx(dcx, sm); let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) { Ok(p) => p, diff --git a/src/driver.rs b/src/driver.rs index af38dde254ed..b944a299256c 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -174,9 +174,9 @@ const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust-clippy/issues/ne #[allow(clippy::too_many_lines)] #[allow(clippy::ignored_unit_patterns)] pub fn main() { - let handler = EarlyDiagCtxt::new(ErrorOutputType::default()); + let early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default()); - rustc_driver::init_rustc_env_logger(&handler); + rustc_driver::init_rustc_env_logger(&early_dcx); let using_internal_features = rustc_driver::install_ice_hook(BUG_REPORT_URL, |handler| { // FIXME: this macro calls unwrap internally but is called in a panicking context! It's not From 2c0d56aaeae590b98677d58f0700a459179aec49 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Fri, 8 Dec 2023 14:51:50 -0800 Subject: [PATCH 1018/1222] Plumb awaitness of for loops --- clippy_lints/src/needless_continue.rs | 6 +++++- clippy_lints/src/redundant_else.rs | 2 +- .../src/suspicious_operation_groupings.rs | 2 +- clippy_utils/src/ast_utils.rs | 19 ++++++++++++++++--- clippy_utils/src/sugg.rs | 2 +- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs index 4b9ab50e4fd7..ff72b5e69ef1 100644 --- a/clippy_lints/src/needless_continue.rs +++ b/clippy_lints/src/needless_continue.rs @@ -220,7 +220,11 @@ where F: FnMut(&ast::Block, Option<&ast::Label>), { if let ast::ExprKind::While(_, loop_block, label) - | ast::ExprKind::ForLoop(_, _, loop_block, label) + | ast::ExprKind::ForLoop { + body: loop_block, + label, + .. + } | ast::ExprKind::Loop(loop_block, label, ..) = &expr.kind { func(loop_block, label.as_ref()); diff --git a/clippy_lints/src/redundant_else.rs b/clippy_lints/src/redundant_else.rs index 001686c84f81..fb434fb7450a 100644 --- a/clippy_lints/src/redundant_else.rs +++ b/clippy_lints/src/redundant_else.rs @@ -111,7 +111,7 @@ impl<'ast> Visitor<'ast> for BreakVisitor { ExprKind::If(_, ref then, Some(ref els)) => self.check_block(then) && self.check_expr(els), ExprKind::If(_, _, None) // ignore loops for simplicity - | ExprKind::While(..) | ExprKind::ForLoop(..) | ExprKind::Loop(..) => false, + | ExprKind::While(..) | ExprKind::ForLoop { .. } | ExprKind::Loop(..) => false, _ => { walk_expr(self, expr); return; diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index 8b9d9bade915..60e9d262e7e0 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -554,7 +554,7 @@ fn ident_difference_expr_with_base_location( | (Closure(_), Closure(_)) | (Match(_, _), Match(_, _)) | (Loop(_, _, _), Loop(_, _, _)) - | (ForLoop(_, _, _, _), ForLoop(_, _, _, _)) + | (ForLoop { .. }, ForLoop { .. }) | (While(_, _, _), While(_, _, _)) | (If(_, _, _), If(_, _, _)) | (Let(_, _, _, _), Let(_, _, _, _)) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index e36f2fa87a72..be3c418ef707 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -169,9 +169,22 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (Let(lp, le, _, _), Let(rp, re, _, _)) => eq_pat(lp, rp) && eq_expr(le, re), (If(lc, lt, le), If(rc, rt, re)) => eq_expr(lc, rc) && eq_block(lt, rt) && eq_expr_opt(le, re), (While(lc, lt, ll), While(rc, rt, rl)) => eq_label(ll, rl) && eq_expr(lc, rc) && eq_block(lt, rt), - (ForLoop(lp, li, lt, ll), ForLoop(rp, ri, rt, rl)) => { - eq_label(ll, rl) && eq_pat(lp, rp) && eq_expr(li, ri) && eq_block(lt, rt) - }, + ( + ForLoop { + pat: lp, + iter: li, + body: lt, + label: ll, + kind: lk, + }, + ForLoop { + pat: rp, + iter: ri, + body: rt, + label: rl, + kind: rk, + }, + ) => eq_label(ll, rl) && eq_pat(lp, rp) && eq_expr(li, ri) && eq_block(lt, rt) && lk == rk, (Loop(lt, ll, _), Loop(rt, rl, _)) => eq_label(ll, rl) && eq_block(lt, rt), (Block(lb, ll), Block(rb, rl)) => eq_label(ll, rl) && eq_block(lb, rb), (TryBlock(l), TryBlock(r)) => eq_block(l, r), diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 9b2bc8df1f30..c86362c427ce 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -197,7 +197,7 @@ impl<'a> Sugg<'a> { | ast::ExprKind::Continue(..) | ast::ExprKind::Yield(..) | ast::ExprKind::Field(..) - | ast::ExprKind::ForLoop(..) + | ast::ExprKind::ForLoop { .. } | ast::ExprKind::Index(..) | ast::ExprKind::InlineAsm(..) | ast::ExprKind::OffsetOf(..) From abcd167273701dcd9b58c12c9ec9b85d47e07289 Mon Sep 17 00:00:00 2001 From: Alona Enraght-Moony Date: Tue, 19 Dec 2023 22:47:30 +0000 Subject: [PATCH 1019/1222] Give `VariantData::Struct` named fields, to clairfy `recovered`. --- clippy_lints/src/item_name_repetitions.rs | 2 +- clippy_lints/src/manual_non_exhaustive.rs | 2 +- clippy_utils/src/ast_utils.rs | 4 +++- clippy_utils/src/check_proc_macro.rs | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/item_name_repetitions.rs b/clippy_lints/src/item_name_repetitions.rs index b6aacba2517a..a9f1612ff05e 100644 --- a/clippy_lints/src/item_name_repetitions.rs +++ b/clippy_lints/src/item_name_repetitions.rs @@ -436,7 +436,7 @@ impl LateLintPass<'_> for ItemNameRepetitions { { match item.kind { ItemKind::Enum(def, _) => check_variant(cx, self.enum_threshold, &def, item_name, item.span), - ItemKind::Struct(VariantData::Struct(fields, _), _) => { + ItemKind::Struct(VariantData::Struct { fields, .. }, _) => { check_fields(cx, self.struct_threshold, item, fields); }, _ => (), diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 545b122930e5..d2ac0ad8363e 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -103,7 +103,7 @@ impl EarlyLintPass for ManualNonExhaustiveStruct { if let ast::ItemKind::Struct(variant_data, _) = &item.kind { let (fields, delimiter) = match variant_data { - ast::VariantData::Struct(fields, _) => (&**fields, '{'), + ast::VariantData::Struct { fields, .. } => (&**fields, '{'), ast::VariantData::Tuple(fields, _) => (&**fields, '('), ast::VariantData::Unit(_) => return, }; diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index e36f2fa87a72..c271e498665e 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -546,7 +546,9 @@ pub fn eq_variant_data(l: &VariantData, r: &VariantData) -> bool { use VariantData::*; match (l, r) { (Unit(_), Unit(_)) => true, - (Struct(l, _), Struct(r, _)) | (Tuple(l, _), Tuple(r, _)) => over(l, r, eq_struct_field), + (Struct { fields: l, .. }, Struct { fields: r, .. }) | (Tuple(l, _), Tuple(r, _)) => { + over(l, r, eq_struct_field) + }, _ => false, } } diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index 470d31fa3e1a..d751aeaf9022 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -200,7 +200,7 @@ fn item_search_pat(item: &Item<'_>) -> (Pat, Pat) { ItemKind::ForeignMod { .. } => (Pat::Str("extern"), Pat::Str("}")), ItemKind::TyAlias(..) | ItemKind::OpaqueTy(_) => (Pat::Str("type"), Pat::Str(";")), ItemKind::Enum(..) => (Pat::Str("enum"), Pat::Str("}")), - ItemKind::Struct(VariantData::Struct(..), _) => (Pat::Str("struct"), Pat::Str("}")), + ItemKind::Struct(VariantData::Struct { .. }, _) => (Pat::Str("struct"), Pat::Str("}")), ItemKind::Struct(..) => (Pat::Str("struct"), Pat::Str(";")), ItemKind::Union(..) => (Pat::Str("union"), Pat::Str("}")), ItemKind::Trait(_, Unsafety::Unsafe, ..) @@ -255,7 +255,7 @@ fn field_def_search_pat(def: &FieldDef<'_>) -> (Pat, Pat) { fn variant_search_pat(v: &Variant<'_>) -> (Pat, Pat) { match v.data { - VariantData::Struct(..) => (Pat::Sym(v.ident.name), Pat::Str("}")), + VariantData::Struct { .. } => (Pat::Sym(v.ident.name), Pat::Str("}")), VariantData::Tuple(..) => (Pat::Sym(v.ident.name), Pat::Str("")), VariantData::Unit(..) => (Pat::Sym(v.ident.name), Pat::Sym(v.ident.name)), } From 148b782bb1af725fd8fb51487ab9f1bb368d793f Mon Sep 17 00:00:00 2001 From: Jules Bertholet Date: Tue, 19 Dec 2023 22:52:04 -0500 Subject: [PATCH 1020/1222] Hide foreign `#[doc(hidden)]` paths in import suggestions --- tests/ui/crashes/ice-6252.stderr | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index f929bec9583c..f6d0976091c5 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -8,8 +8,6 @@ help: consider importing one of these items | LL + use core::marker::PhantomData; | -LL + use serde::__private::PhantomData; - | LL + use std::marker::PhantomData; | From 4d1b008c0399556437327068241e7db8575b3905 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 21 Dec 2023 18:49:20 +0000 Subject: [PATCH 1021/1222] Split coroutine desugaring kind from source --- clippy_lints/src/async_yields_async.rs | 5 ++--- clippy_lints/src/await_holding_invalid.rs | 5 ++--- clippy_lints/src/manual_async_fn.rs | 4 ++-- clippy_lints/src/needless_question_mark.rs | 4 ++-- clippy_lints/src/redundant_async_block.rs | 4 ++-- clippy_lints/src/redundant_closure_call.rs | 4 ++-- clippy_lints/src/unused_async.rs | 8 +++++++- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/clippy_lints/src/async_yields_async.rs b/clippy_lints/src/async_yields_async.rs index 3e5a01c45df1..28e6614f03fb 100644 --- a/clippy_lints/src/async_yields_async.rs +++ b/clippy_lints/src/async_yields_async.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::source::snippet; use clippy_utils::ty::implements_trait; use rustc_errors::Applicability; -use rustc_hir::{Body, BodyId, CoroutineKind, CoroutineSource, ExprKind, QPath}; +use rustc_hir::{Body, BodyId, CoroutineKind, CoroutineSource, CoroutineDesugaring, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; @@ -45,10 +45,9 @@ declare_lint_pass!(AsyncYieldsAsync => [ASYNC_YIELDS_ASYNC]); impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync { fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) { - use CoroutineSource::{Block, Closure}; // For functions, with explicitly defined types, don't warn. // XXXkhuey maybe we should? - if let Some(CoroutineKind::Async(Block | Closure)) = body.coroutine_kind { + if let Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Block | CoroutineSource::Closure)) = body.coroutine_kind { if let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait() { let body_id = BodyId { hir_id: body.value.hir_id, diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index 9894a1639618..dff6e884fa11 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::{match_def_path, paths}; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::DefId; -use rustc_hir::{Body, CoroutineKind, CoroutineSource}; +use rustc_hir::{Body, CoroutineKind, CoroutineDesugaring}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::CoroutineLayout; use rustc_session::impl_lint_pass; @@ -194,8 +194,7 @@ impl LateLintPass<'_> for AwaitHolding { } fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { - use CoroutineSource::{Block, Closure, Fn}; - if let Some(CoroutineKind::Async(Block | Closure | Fn)) = body.coroutine_kind { + if let Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, _)) = body.coroutine_kind { let def_id = cx.tcx.hir().body_owner_def_id(body.id()); if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(def_id) { self.check_interior_types(cx, coroutine_layout); diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index eaaaea0be9f8..8982ce5e196e 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -3,7 +3,7 @@ use clippy_utils::source::{position_before_rarrow, snippet_block, snippet_opt}; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{ - Block, Body, Closure, CoroutineKind, CoroutineSource, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, GenericBound, + Block, Body, Closure, CoroutineKind, CoroutineSource, CoroutineDesugaring, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, GenericBound, ImplItem, Item, ItemKind, LifetimeName, Node, Term, TraitRef, Ty, TyKind, TypeBindingKind, }; use rustc_lint::{LateContext, LateLintPass}; @@ -178,7 +178,7 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) .. } = block_expr && let closure_body = cx.tcx.hir().body(body) - && closure_body.coroutine_kind == Some(CoroutineKind::Async(CoroutineSource::Block)) + && closure_body.coroutine_kind == Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Block)) { return Some(closure_body); } diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index a4d3aaf0de98..350707d3a136 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -3,7 +3,7 @@ use clippy_utils::path_res; use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{Block, Body, CoroutineKind, CoroutineSource, Expr, ExprKind, LangItem, MatchSource, QPath}; +use rustc_hir::{Block, Body, CoroutineKind, CoroutineSource, CoroutineDesugaring, Expr, ExprKind, LangItem, MatchSource, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; @@ -86,7 +86,7 @@ impl LateLintPass<'_> for NeedlessQuestionMark { } fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { - if let Some(CoroutineKind::Async(CoroutineSource::Fn)) = body.coroutine_kind { + if let Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Fn)) = body.coroutine_kind { if let ExprKind::Block( Block { expr: diff --git a/clippy_lints/src/redundant_async_block.rs b/clippy_lints/src/redundant_async_block.rs index 19d9d64b31e3..4b3fe9c0bb55 100644 --- a/clippy_lints/src/redundant_async_block.rs +++ b/clippy_lints/src/redundant_async_block.rs @@ -5,7 +5,7 @@ use clippy_utils::peel_blocks; use clippy_utils::source::{snippet, walk_span_to_context}; use clippy_utils::visitors::for_each_expr; use rustc_errors::Applicability; -use rustc_hir::{Closure, CoroutineKind, CoroutineSource, Expr, ExprKind, MatchSource}; +use rustc_hir::{Closure, CoroutineKind, CoroutineSource, CoroutineDesugaring, Expr, ExprKind, MatchSource}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::UpvarCapture; @@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantAsyncBlock { fn desugar_async_block<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { if let ExprKind::Closure(Closure { body, def_id, .. }) = expr.kind && let body = cx.tcx.hir().body(*body) - && matches!(body.coroutine_kind, Some(CoroutineKind::Async(CoroutineSource::Block))) + && matches!(body.coroutine_kind, Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Block))) { cx.typeck_results() .closure_min_captures diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 8bac2e40e012..9312a9c89b78 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -5,7 +5,7 @@ use clippy_utils::sugg::Sugg; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::intravisit::{Visitor as HirVisitor, Visitor}; -use rustc_hir::{intravisit as hir_visit, CoroutineKind, CoroutineSource, Node}; +use rustc_hir::{intravisit as hir_visit, CoroutineKind, CoroutineSource, CoroutineDesugaring, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; @@ -67,7 +67,7 @@ fn is_async_closure(cx: &LateContext<'_>, body: &hir::Body<'_>) -> bool { if let hir::ExprKind::Closure(innermost_closure_generated_by_desugar) = body.value.kind && let desugared_inner_closure_body = cx.tcx.hir().body(innermost_closure_generated_by_desugar.body) // checks whether it is `async || whatever_expression` - && let Some(CoroutineKind::Async(CoroutineSource::Closure)) = desugared_inner_closure_body.coroutine_kind + && let Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Closure)) = desugared_inner_closure_body.coroutine_kind { true } else { diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index 9c8c44c0a16d..f71fe4e1e92e 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -86,7 +86,13 @@ impl<'a, 'tcx> Visitor<'tcx> for AsyncFnVisitor<'a, 'tcx> { } fn visit_body(&mut self, b: &'tcx Body<'tcx>) { - let is_async_block = matches!(b.coroutine_kind, Some(rustc_hir::CoroutineKind::Async(_))); + let is_async_block = matches!( + b.coroutine_kind, + Some(rustc_hir::CoroutineKind::Desugared( + rustc_hir::CoroutineDesugaring::Async, + _ + )) + ); if is_async_block { self.async_depth += 1; From 540a0418d6a11ed6d65bfdcb68e8cfa9539514c4 Mon Sep 17 00:00:00 2001 From: Alona Enraght-Moony Date: Fri, 22 Dec 2023 23:29:20 +0000 Subject: [PATCH 1022/1222] bool->enum for ast::PatKind::Struct presence of `..` See https://github.com/rust-lang/rust/blob/cee794ee98d49b45a55ba225680d98e0c4672736/compiler/rustc_parse/src/parser/pat.rs#L890-L897 for the only place this is constructed. --- clippy_lints/src/unnested_or_patterns.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 65600009c1d7..77adcdd0e6bf 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -293,7 +293,7 @@ fn extend_with_struct_pat( qself1: &Option>, path1: &ast::Path, fps1: &mut [ast::PatField], - rest1: bool, + rest1: ast::PatFieldsRest, start: usize, alternatives: &mut ThinVec>, ) -> bool { From b949a32a827106bd584f21c9fd34329441096fe6 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 18 Dec 2023 22:21:37 +1100 Subject: [PATCH 1023/1222] Remove `Session` methods that duplicate `DiagCtxt` methods. Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access. --- clippy_config/src/conf.rs | 10 +++++----- clippy_config/src/msrvs.rs | 8 ++++---- clippy_lints/src/missing_const_for_fn.rs | 2 +- clippy_utils/src/attrs.rs | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 88611eb70878..3cf4377002a8 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -636,11 +636,11 @@ impl Conf { match path { Ok((_, warnings)) => { for warning in warnings { - sess.warn(warning.clone()); + sess.dcx().warn(warning.clone()); } }, Err(error) => { - sess.err(format!("error finding Clippy's configuration file: {error}")); + sess.dcx().err(format!("error finding Clippy's configuration file: {error}")); }, } @@ -652,7 +652,7 @@ impl Conf { Ok((Some(path), _)) => match sess.source_map().load_file(path) { Ok(file) => deserialize(&file), Err(error) => { - sess.err(format!("failed to read `{}`: {error}", path.display())); + sess.dcx().err(format!("failed to read `{}`: {error}", path.display())); TryConf::default() }, }, @@ -663,14 +663,14 @@ impl Conf { // all conf errors are non-fatal, we just use the default conf in case of error for error in errors { - sess.span_err( + sess.dcx().span_err( error.span, format!("error reading Clippy's configuration file: {}", error.message), ); } for warning in warnings { - sess.span_warn( + sess.dcx().span_warn( warning.span, format!("error reading Clippy's configuration file: {}", warning.message), ); diff --git a/clippy_config/src/msrvs.rs b/clippy_config/src/msrvs.rs index b3ef666e3063..13e61e5a0326 100644 --- a/clippy_config/src/msrvs.rs +++ b/clippy_config/src/msrvs.rs @@ -83,7 +83,7 @@ impl Msrv { (None, Some(cargo_msrv)) => self.stack = vec![cargo_msrv], (Some(clippy_msrv), Some(cargo_msrv)) => { if clippy_msrv != cargo_msrv { - sess.warn(format!( + sess.dcx().warn(format!( "the MSRV in `clippy.toml` and `Cargo.toml` differ; using `{clippy_msrv}` from `clippy.toml`" )); } @@ -106,7 +106,7 @@ impl Msrv { if let Some(msrv_attr) = msrv_attrs.next() { if let Some(duplicate) = msrv_attrs.last() { - sess.struct_span_err(duplicate.span, "`clippy::msrv` is defined multiple times") + sess.dcx().struct_span_err(duplicate.span, "`clippy::msrv` is defined multiple times") .span_note(msrv_attr.span, "first definition found here") .emit(); } @@ -116,9 +116,9 @@ impl Msrv { return Some(version); } - sess.span_err(msrv_attr.span, format!("`{msrv}` is not a valid Rust version")); + sess.dcx().span_err(msrv_attr.span, format!("`{msrv}` is not a valid Rust version")); } else { - sess.span_err(msrv_attr.span, "bad clippy attribute"); + sess.dcx().span_err(msrv_attr.span, "bad clippy attribute"); } } diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index acaa6be30092..9ba19e0a8658 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -153,7 +153,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { if let Err((span, err)) = is_min_const_fn(cx.tcx, mir, &self.msrv) { if cx.tcx.is_const_fn_raw(def_id.to_def_id()) { - cx.tcx.sess.span_err(span, err); + cx.tcx.dcx().span_err(span, err); } } else { span_lint(cx, MISSING_CONST_FOR_FN, span, "this could be a `const fn`"); diff --git a/clippy_utils/src/attrs.rs b/clippy_utils/src/attrs.rs index 51771f78d4ff..46c96fad884f 100644 --- a/clippy_utils/src/attrs.rs +++ b/clippy_utils/src/attrs.rs @@ -76,12 +76,12 @@ pub fn get_attr<'a>( }) .map_or_else( || { - sess.span_err(attr_segments[1].ident.span, "usage of unknown attribute"); + sess.dcx().span_err(attr_segments[1].ident.span, "usage of unknown attribute"); false }, |deprecation_status| { let mut diag = - sess.struct_span_err(attr_segments[1].ident.span, "usage of deprecated attribute"); + sess.dcx().struct_span_err(attr_segments[1].ident.span, "usage of deprecated attribute"); match *deprecation_status { DeprecationStatus::Deprecated => { diag.emit(); @@ -116,10 +116,10 @@ fn parse_attrs(sess: &Session, attrs: &[ast::Attribute], name: &' if let Ok(value) = FromStr::from_str(value.as_str()) { f(value); } else { - sess.span_err(attr.span, "not a number"); + sess.dcx().span_err(attr.span, "not a number"); } } else { - sess.span_err(attr.span, "bad clippy attribute"); + sess.dcx().span_err(attr.span, "bad clippy attribute"); } } } @@ -132,7 +132,7 @@ pub fn get_unique_attr<'a>( let mut unique_attr: Option<&ast::Attribute> = None; for attr in get_attr(sess, attrs, name) { if let Some(duplicate) = unique_attr { - sess.struct_span_err(attr.span, format!("`{name}` is defined multiple times")) + sess.dcx().struct_span_err(attr.span, format!("`{name}` is defined multiple times")) .span_note(duplicate.span, "first definition found here") .emit(); } else { From cfe290cab4d3091795fe206d16c405e62141512c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 25 Dec 2023 18:01:56 +0000 Subject: [PATCH 1024/1222] Fix clippy's usage of Body's coroutine_kind Also fixes a bug where we weren't peeling blocks from async bodies --- clippy_lints/src/async_yields_async.rs | 23 +++++++++++----- clippy_lints/src/await_holding_invalid.rs | 18 +++++++----- clippy_lints/src/manual_async_fn.rs | 32 ++++++++++++++-------- clippy_lints/src/methods/iter_kv_map.rs | 1 - clippy_lints/src/needless_question_mark.rs | 32 ++++++++++------------ clippy_lints/src/redundant_async_block.rs | 6 ++-- clippy_lints/src/redundant_closure_call.rs | 9 +++--- clippy_lints/src/unused_async.rs | 28 +++++++++---------- clippy_lints/src/utils/author.rs | 21 +++++++++++--- tests/ui/author/blocks.stdout | 4 +-- tests/ui/author/macro_in_closure.stdout | 2 +- tests/ui/needless_question_mark.fixed | 4 +++ tests/ui/needless_question_mark.rs | 4 +++ tests/ui/needless_question_mark.stderr | 8 +++++- 14 files changed, 119 insertions(+), 73 deletions(-) diff --git a/clippy_lints/src/async_yields_async.rs b/clippy_lints/src/async_yields_async.rs index 28e6614f03fb..c965341d3fdf 100644 --- a/clippy_lints/src/async_yields_async.rs +++ b/clippy_lints/src/async_yields_async.rs @@ -2,7 +2,9 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::source::snippet; use clippy_utils::ty::implements_trait; use rustc_errors::Applicability; -use rustc_hir::{Body, BodyId, CoroutineKind, CoroutineSource, CoroutineDesugaring, ExprKind, QPath}; +use rustc_hir::{ + Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, QPath, +}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; @@ -44,15 +46,22 @@ declare_clippy_lint! { declare_lint_pass!(AsyncYieldsAsync => [ASYNC_YIELDS_ASYNC]); impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync { - fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { // For functions, with explicitly defined types, don't warn. // XXXkhuey maybe we should? - if let Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Block | CoroutineSource::Closure)) = body.coroutine_kind { + if let ExprKind::Closure(Closure { + kind: + ClosureKind::Coroutine(CoroutineKind::Desugared( + CoroutineDesugaring::Async, + CoroutineSource::Block | CoroutineSource::Closure, + )), + body: body_id, + .. + }) = expr.kind + { if let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait() { - let body_id = BodyId { - hir_id: body.value.hir_id, - }; - let typeck_results = cx.tcx.typeck_body(body_id); + let typeck_results = cx.tcx.typeck_body(*body_id); + let body = cx.tcx.hir().body(*body_id); let expr_ty = typeck_results.expr_ty(body.value); if implements_trait(cx, expr_ty, future_trait_def_id, &[]) { diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index dff6e884fa11..765cc7c0a54f 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -2,8 +2,8 @@ use clippy_config::types::DisallowedPath; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::{match_def_path, paths}; use rustc_data_structures::fx::FxHashMap; +use rustc_hir as hir; use rustc_hir::def_id::DefId; -use rustc_hir::{Body, CoroutineKind, CoroutineDesugaring}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::CoroutineLayout; use rustc_session::impl_lint_pass; @@ -183,8 +183,8 @@ impl AwaitHolding { } } -impl LateLintPass<'_> for AwaitHolding { - fn check_crate(&mut self, cx: &LateContext<'_>) { +impl<'tcx> LateLintPass<'tcx> for AwaitHolding { + fn check_crate(&mut self, cx: &LateContext<'tcx>) { for conf in &self.conf_invalid_types { let segs: Vec<_> = conf.path().split("::").collect(); for id in clippy_utils::def_path_def_ids(cx, &segs) { @@ -193,10 +193,14 @@ impl LateLintPass<'_> for AwaitHolding { } } - fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { - if let Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, _)) = body.coroutine_kind { - let def_id = cx.tcx.hir().body_owner_def_id(body.id()); - if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(def_id) { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) { + if let hir::ExprKind::Closure(hir::Closure { + kind: hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)), + def_id, + .. + }) = expr.kind + { + if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(*def_id) { self.check_interior_types(cx, coroutine_layout); } } diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 8982ce5e196e..9ba1d3afcbe9 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -3,8 +3,9 @@ use clippy_utils::source::{position_before_rarrow, snippet_block, snippet_opt}; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{ - Block, Body, Closure, CoroutineKind, CoroutineSource, CoroutineDesugaring, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, GenericBound, - ImplItem, Item, ItemKind, LifetimeName, Node, Term, TraitRef, Ty, TyKind, TypeBindingKind, + Block, Body, Closure, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, FnDecl, FnRetTy, + GenericArg, GenericBound, ImplItem, Item, ItemKind, LifetimeName, Node, Term, TraitRef, Ty, TyKind, + TypeBindingKind, ClosureKind, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; @@ -171,16 +172,25 @@ fn captures_all_lifetimes(inputs: &[Ty<'_>], output_lifetimes: &[LifetimeName]) .all(|in_lt| output_lifetimes.iter().any(|out_lt| in_lt == out_lt)) } -fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) -> Option<&'tcx Body<'tcx>> { - if let Some(block_expr) = block.expr - && let Expr { - kind: ExprKind::Closure(&Closure { body, .. }), - .. - } = block_expr - && let closure_body = cx.tcx.hir().body(body) - && closure_body.coroutine_kind == Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Block)) +fn desugared_async_block<'tcx>( + cx: &LateContext<'tcx>, + block: &'tcx Block<'tcx>, +) -> Option<&'tcx Body<'tcx>> { + if let Some(Expr { + kind: + ExprKind::Closure(&Closure { + kind: + ClosureKind::Coroutine(CoroutineKind::Desugared( + CoroutineDesugaring::Async, + CoroutineSource::Block, + )), + body, + .. + }), + .. + }) = block.expr { - return Some(closure_body); + return Some(cx.tcx.hir().body(body)); } None diff --git a/clippy_lints/src/methods/iter_kv_map.rs b/clippy_lints/src/methods/iter_kv_map.rs index e1b934d36ea8..6394f35f8604 100644 --- a/clippy_lints/src/methods/iter_kv_map.rs +++ b/clippy_lints/src/methods/iter_kv_map.rs @@ -32,7 +32,6 @@ pub(super) fn check<'tcx>( && let Body { params: [p], value: body_expr, - coroutine_kind: _, } = cx.tcx.hir().body(c.body) && let PatKind::Tuple([key_pat, val_pat], _) = p.pat.kind && let (replacement_kind, annotation, bound_ident) = match (&key_pat.kind, &val_pat.kind) { diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index 350707d3a136..d7adf22ff32a 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -3,7 +3,7 @@ use clippy_utils::path_res; use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{Block, Body, CoroutineKind, CoroutineSource, CoroutineDesugaring, Expr, ExprKind, LangItem, MatchSource, QPath}; +use rustc_hir::{Block, Body, Expr, ExprKind, LangItem, MatchSource, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; @@ -86,22 +86,20 @@ impl LateLintPass<'_> for NeedlessQuestionMark { } fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { - if let Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Fn)) = body.coroutine_kind { - if let ExprKind::Block( - Block { - expr: - Some(Expr { - kind: ExprKind::DropTemps(async_body), - .. - }), - .. - }, - _, - ) = body.value.kind - { - if let ExprKind::Block(Block { expr: Some(expr), .. }, ..) = async_body.kind { - check(cx, expr); - } + if let ExprKind::Block( + Block { + expr: + Some(Expr { + kind: ExprKind::DropTemps(async_body), + .. + }), + .. + }, + _, + ) = body.value.kind + { + if let ExprKind::Block(Block { expr: Some(expr), .. }, ..) = async_body.kind { + check(cx, expr.peel_blocks()); } } else { check(cx, body.value.peel_blocks()); diff --git a/clippy_lints/src/redundant_async_block.rs b/clippy_lints/src/redundant_async_block.rs index 4b3fe9c0bb55..b50141f048c5 100644 --- a/clippy_lints/src/redundant_async_block.rs +++ b/clippy_lints/src/redundant_async_block.rs @@ -5,7 +5,7 @@ use clippy_utils::peel_blocks; use clippy_utils::source::{snippet, walk_span_to_context}; use clippy_utils::visitors::for_each_expr; use rustc_errors::Applicability; -use rustc_hir::{Closure, CoroutineKind, CoroutineSource, CoroutineDesugaring, Expr, ExprKind, MatchSource}; +use rustc_hir::{Closure, ClosureKind, CoroutineKind, CoroutineSource, CoroutineDesugaring, Expr, ExprKind, MatchSource}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::UpvarCapture; @@ -69,9 +69,9 @@ impl<'tcx> LateLintPass<'tcx> for RedundantAsyncBlock { /// If `expr` is a desugared `async` block, return the original expression if it does not capture /// any variable by ref. fn desugar_async_block<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { - if let ExprKind::Closure(Closure { body, def_id, .. }) = expr.kind + if let ExprKind::Closure(Closure { body, def_id, kind, .. }) = expr.kind && let body = cx.tcx.hir().body(*body) - && matches!(body.coroutine_kind, Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Block))) + && matches!(kind, ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Block))) { cx.typeck_results() .closure_min_captures diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 9312a9c89b78..16c929edb928 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -5,7 +5,7 @@ use clippy_utils::sugg::Sugg; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::intravisit::{Visitor as HirVisitor, Visitor}; -use rustc_hir::{intravisit as hir_visit, CoroutineKind, CoroutineSource, CoroutineDesugaring, Node}; +use rustc_hir::{intravisit as hir_visit, CoroutineKind, CoroutineSource, CoroutineDesugaring, Node, ClosureKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; @@ -63,11 +63,10 @@ impl<'tcx> Visitor<'tcx> for ReturnVisitor { /// Checks if the body is owned by an async closure. /// Returns true for `async || whatever_expression`, but false for `|| async { whatever_expression /// }`. -fn is_async_closure(cx: &LateContext<'_>, body: &hir::Body<'_>) -> bool { +fn is_async_closure(body: &hir::Body<'_>) -> bool { if let hir::ExprKind::Closure(innermost_closure_generated_by_desugar) = body.value.kind - && let desugared_inner_closure_body = cx.tcx.hir().body(innermost_closure_generated_by_desugar.body) // checks whether it is `async || whatever_expression` - && let Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Closure)) = desugared_inner_closure_body.coroutine_kind + && let ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Closure)) = innermost_closure_generated_by_desugar.kind { true } else { @@ -103,7 +102,7 @@ fn find_innermost_closure<'tcx>( data = Some(( body.value, closure.fn_decl, - if is_async_closure(cx, body) { + if is_async_closure(body) { ty::Asyncness::Yes } else { ty::Asyncness::No diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index f71fe4e1e92e..1d42375ba8e5 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::is_def_id_trait_method; use rustc_hir::def::DefKind; -use rustc_hir::intravisit::{walk_body, walk_expr, walk_fn, FnKind, Visitor}; +use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, Visitor}; use rustc_hir::{Body, Expr, ExprKind, FnDecl, Node, YieldSource}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; @@ -78,32 +78,32 @@ impl<'a, 'tcx> Visitor<'tcx> for AsyncFnVisitor<'a, 'tcx> { self.await_in_async_block = Some(ex.span); } } - walk_expr(self, ex); - } - - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() - } - fn visit_body(&mut self, b: &'tcx Body<'tcx>) { let is_async_block = matches!( - b.coroutine_kind, - Some(rustc_hir::CoroutineKind::Desugared( - rustc_hir::CoroutineDesugaring::Async, - _ - )) + ex.kind, + ExprKind::Closure(rustc_hir::Closure { + kind: rustc_hir::ClosureKind::Coroutine(rustc_hir::CoroutineKind::Desugared( + rustc_hir::CoroutineDesugaring::Async, + _ + )), + .. + }) ); if is_async_block { self.async_depth += 1; } - walk_body(self, b); + walk_expr(self, ex); if is_async_block { self.async_depth -= 1; } } + + fn nested_visit_map(&mut self) -> Self::Map { + self.cx.tcx.hir() + } } impl<'tcx> LateLintPass<'tcx> for UnusedAsync { diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index e83c04eda207..df715b12dea7 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -7,7 +7,8 @@ use rustc_ast::LitIntType; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; use rustc_hir::{ - ArrayLen, BindingAnnotation, CaptureBy, Closure, ExprKind, FnRetTy, HirId, Lit, PatKind, QPath, StmtKind, TyKind, + ArrayLen, BindingAnnotation, CaptureBy, Closure, ClosureKind, CoroutineKind, ExprKind, FnRetTy, HirId, Lit, + PatKind, QPath, StmtKind, TyKind, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::declare_lint_pass; @@ -476,7 +477,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { capture_clause, fn_decl, body: body_id, - movability, + kind, .. }) => { let capture_clause = match capture_clause { @@ -484,7 +485,17 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { CaptureBy::Ref => "Ref", }; - let movability = OptionPat::new(movability.map(|m| format!("Movability::{m:?}"))); + let closure_kind = match kind { + ClosureKind::Closure => "ClosureKind::Closure".to_string(), + ClosureKind::Coroutine(coroutine_kind) => match coroutine_kind { + CoroutineKind::Desugared(desugaring, source) => format!( + "ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::{desugaring:?}, CoroutineSource::{source:?}))" + ), + CoroutineKind::Coroutine(movability) => { + format!("ClosureKind::Coroutine(CoroutineKind::Coroutine(Movability::{movability:?})") + }, + }, + }; let ret_ty = match fn_decl.output { FnRetTy::DefaultReturn(_) => "FnRetTy::DefaultReturn(_)", @@ -492,7 +503,9 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { }; bind!(self, fn_decl, body_id); - kind!("Closure(CaptureBy::{capture_clause}, {fn_decl}, {body_id}, _, {movability})"); + kind!( + "Closure {{ capture_clause: CaptureBy::{capture_clause}, fn_decl: {fn_decl}, body: {body_id}, closure_kind: {closure_kind}, .. }}" + ); chain!(self, "let {ret_ty} = {fn_decl}.output"); self.body(body_id); }, diff --git a/tests/ui/author/blocks.stdout b/tests/ui/author/blocks.stdout index 140300a16730..62de661f8ff8 100644 --- a/tests/ui/author/blocks.stdout +++ b/tests/ui/author/blocks.stdout @@ -40,10 +40,10 @@ if let ExprKind::Block(block, None) = expr.kind { // report your lint here } -if let ExprKind::Closure(CaptureBy::Value { .. }, fn_decl, body_id, _, None) = expr.kind +if let ExprKind::Closure { capture_clause: CaptureBy::Value { .. }, fn_decl: fn_decl, body: body_id, closure_kind: ClosureKind::Closure, .. } = expr.kind && let FnRetTy::DefaultReturn(_) = fn_decl.output && expr1 = &cx.tcx.hir().body(body_id).value - && let ExprKind::Closure(CaptureBy::Value { .. }, fn_decl1, body_id1, _, Some(Movability::Static)) = expr1.kind + && let ExprKind::Closure { capture_clause: CaptureBy::Value { .. }, fn_decl: fn_decl1, body: body_id1, closure_kind: ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Closure)), .. } = expr1.kind && let FnRetTy::DefaultReturn(_) = fn_decl1.output && expr2 = &cx.tcx.hir().body(body_id1).value && let ExprKind::Block(block, None) = expr2.kind diff --git a/tests/ui/author/macro_in_closure.stdout b/tests/ui/author/macro_in_closure.stdout index 9ab71986f40f..06386d1d7ec4 100644 --- a/tests/ui/author/macro_in_closure.stdout +++ b/tests/ui/author/macro_in_closure.stdout @@ -1,6 +1,6 @@ if let StmtKind::Local(local) = stmt.kind && let Some(init) = local.init - && let ExprKind::Closure(CaptureBy::Ref, fn_decl, body_id, _, None) = init.kind + && let ExprKind::Closure { capture_clause: CaptureBy::Ref, fn_decl: fn_decl, body: body_id, closure_kind: ClosureKind::Closure, .. } = init.kind && let FnRetTy::DefaultReturn(_) = fn_decl.output && expr = &cx.tcx.hir().body(body_id).value && let ExprKind::Block(block, None) = expr.kind diff --git a/tests/ui/needless_question_mark.fixed b/tests/ui/needless_question_mark.fixed index 07bd6b6f3c1e..92f01c217c1c 100644 --- a/tests/ui/needless_question_mark.fixed +++ b/tests/ui/needless_question_mark.fixed @@ -135,3 +135,7 @@ async fn async_deref_ref(s: Option<&String>) -> Option<&str> { async fn async_result_bad(s: TR) -> Result { s.magic } + +async fn async_wrapped(a: Option) -> Option { + { a } +} diff --git a/tests/ui/needless_question_mark.rs b/tests/ui/needless_question_mark.rs index fbf8a12fd504..21c858c291ff 100644 --- a/tests/ui/needless_question_mark.rs +++ b/tests/ui/needless_question_mark.rs @@ -135,3 +135,7 @@ async fn async_deref_ref(s: Option<&String>) -> Option<&str> { async fn async_result_bad(s: TR) -> Result { Ok(s.magic?) } + +async fn async_wrapped(a: Option) -> Option { + { Some(a?) } +} diff --git a/tests/ui/needless_question_mark.stderr b/tests/ui/needless_question_mark.stderr index cd961a49f421..bf090302ef7e 100644 --- a/tests/ui/needless_question_mark.stderr +++ b/tests/ui/needless_question_mark.stderr @@ -90,5 +90,11 @@ error: question mark operator is useless here LL | Ok(s.magic?) | ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `s.magic` -error: aborting due to 14 previous errors +error: question mark operator is useless here + --> $DIR/needless_question_mark.rs:140:7 + | +LL | { Some(a?) } + | ^^^^^^^^ help: try removing question mark and `Some()`: `a` + +error: aborting due to 15 previous errors From 88be6d7bf12bc7ca074edc63c3e0e734dd335057 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 23 Dec 2023 04:02:17 +0000 Subject: [PATCH 1025/1222] Make some non-diagnostic-affecting QPath::LangItem into regular qpaths --- tests/ui/author/macro_in_closure.stdout | 2 ++ tests/ui/author/macro_in_loop.stdout | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/ui/author/macro_in_closure.stdout b/tests/ui/author/macro_in_closure.stdout index 9ab71986f40f..5a2542c8628a 100644 --- a/tests/ui/author/macro_in_closure.stdout +++ b/tests/ui/author/macro_in_closure.stdout @@ -12,6 +12,7 @@ if let StmtKind::Local(local) = stmt.kind && args.len() == 1 && let ExprKind::Call(func1, args1) = args[0].kind && let ExprKind::Path(ref qpath1) = func1.kind + && match_qpath(qpath1, &["format_arguments", "new_v1"]) && args1.len() == 2 && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = args1[0].kind && let ExprKind::Array(elements) = inner.kind @@ -27,6 +28,7 @@ if let StmtKind::Local(local) = stmt.kind && elements1.len() == 1 && let ExprKind::Call(func2, args2) = elements1[0].kind && let ExprKind::Path(ref qpath2) = func2.kind + && match_qpath(qpath2, &["format_argument", "new_display"]) && args2.len() == 1 && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[0].kind && let ExprKind::Path(ref qpath3) = inner2.kind diff --git a/tests/ui/author/macro_in_loop.stdout b/tests/ui/author/macro_in_loop.stdout index bd054b6abc43..a719e3af7e76 100644 --- a/tests/ui/author/macro_in_loop.stdout +++ b/tests/ui/author/macro_in_loop.stdout @@ -22,6 +22,7 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo && args.len() == 1 && let ExprKind::Call(func1, args1) = args[0].kind && let ExprKind::Path(ref qpath2) = func1.kind + && match_qpath(qpath2, &["format_arguments", "new_v1"]) && args1.len() == 2 && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = args1[0].kind && let ExprKind::Array(elements) = inner.kind @@ -37,6 +38,7 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo && elements1.len() == 1 && let ExprKind::Call(func2, args2) = elements1[0].kind && let ExprKind::Path(ref qpath3) = func2.kind + && match_qpath(qpath3, &["format_argument", "new_display"]) && args2.len() == 1 && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[0].kind && let ExprKind::Path(ref qpath4) = inner2.kind From d7f367bb3b0d1bc580031fcecd8b9153f8891d81 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 21 Dec 2023 01:52:10 +0000 Subject: [PATCH 1026/1222] Remove movability from TyKind::Coroutine --- clippy_lints/src/doc/missing_headers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/doc/missing_headers.rs b/clippy_lints/src/doc/missing_headers.rs index 4cbfa97a8a35..26f120cb33f0 100644 --- a/clippy_lints/src/doc/missing_headers.rs +++ b/clippy_lints/src/doc/missing_headers.rs @@ -72,7 +72,7 @@ pub fn check( && let body = cx.tcx.hir().body(body_id) && let ret_ty = typeck.expr_ty(body.value) && implements_trait(cx, ret_ty, future, &[]) - && let ty::Coroutine(_, subs, _) = ret_ty.kind() + && let ty::Coroutine(_, subs) = ret_ty.kind() && is_type_diagnostic_item(cx, subs.as_coroutine().return_ty(), sym::Result) { span_lint( From ab70c170a08b67febc0fd9084d1916407c826ee5 Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Wed, 29 Nov 2023 15:28:46 -0500 Subject: [PATCH 1027/1222] Address unused tuple struct fields in clippy --- .../src/methods/iter_overeager_cloned.rs | 8 ++++---- clippy_lints/src/methods/mod.rs | 8 ++++---- clippy_lints/src/question_mark.rs | 5 ++--- .../src/transmute/transmute_undefined_repr.rs | 16 ++++++++-------- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/clippy_lints/src/methods/iter_overeager_cloned.rs b/clippy_lints/src/methods/iter_overeager_cloned.rs index eac6df0545ff..b2fe129cd951 100644 --- a/clippy_lints/src/methods/iter_overeager_cloned.rs +++ b/clippy_lints/src/methods/iter_overeager_cloned.rs @@ -22,7 +22,7 @@ pub(super) enum Op<'a> { // rm `.cloned()` // e.g. `map` `for_each` `all` `any` - NeedlessMove(&'a str, &'a Expr<'a>), + NeedlessMove(&'a Expr<'a>), // later `.cloned()` // and add `&` to the parameter of closure parameter @@ -59,7 +59,7 @@ pub(super) fn check<'tcx>( return; } - if let Op::NeedlessMove(_, expr) = op { + if let Op::NeedlessMove(expr) = op { let rustc_hir::ExprKind::Closure(closure) = expr.kind else { return; }; @@ -104,7 +104,7 @@ pub(super) fn check<'tcx>( } let (lint, msg, trailing_clone) = match op { - Op::RmCloned | Op::NeedlessMove(_, _) => (REDUNDANT_CLONE, "unneeded cloning of iterator items", ""), + Op::RmCloned | Op::NeedlessMove(_) => (REDUNDANT_CLONE, "unneeded cloning of iterator items", ""), Op::LaterCloned | Op::FixClosure(_, _) => ( ITER_OVEREAGER_CLONED, "unnecessarily eager cloning of iterator items", @@ -133,7 +133,7 @@ pub(super) fn check<'tcx>( diag.span_suggestion(replace_span, "try", snip, Applicability::MachineApplicable); } }, - Op::NeedlessMove(_, _) => { + Op::NeedlessMove(_) => { let method_span = expr.span.with_lo(cloned_call.span.hi()); if let Some(snip) = snippet_opt(cx, method_span) { let replace_span = expr.span.with_lo(cloned_recv.span.hi()); diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 25b1ea526e2e..c1e126137dfe 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -4186,7 +4186,7 @@ impl Methods { expr, recv, recv2, - iter_overeager_cloned::Op::NeedlessMove(name, arg), + iter_overeager_cloned::Op::NeedlessMove(arg), false, ); } @@ -4204,7 +4204,7 @@ impl Methods { expr, recv, recv2, - iter_overeager_cloned::Op::NeedlessMove(name, arg), + iter_overeager_cloned::Op::NeedlessMove(arg), false, ), Some(("chars", recv, _, _, _)) @@ -4379,7 +4379,7 @@ impl Methods { expr, recv, recv2, - iter_overeager_cloned::Op::NeedlessMove(name, arg), + iter_overeager_cloned::Op::NeedlessMove(arg), false, ), _ => {}, @@ -4433,7 +4433,7 @@ impl Methods { expr, recv, recv2, - iter_overeager_cloned::Op::NeedlessMove(name, m_arg), + iter_overeager_cloned::Op::NeedlessMove(m_arg), false, ), _ => {}, diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 509d9483e1d7..9469888a4d4b 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -80,7 +80,6 @@ enum IfBlockType<'hir> { Ty<'hir>, Symbol, &'hir Expr<'hir>, - Option<&'hir Expr<'hir>>, ), /// An `if let Xxx(a) = b { c } else { d }` expression. /// @@ -143,7 +142,7 @@ fn check_let_some_else_return_none(cx: &LateContext<'_>, stmt: &Stmt<'_>) { fn is_early_return(smbl: Symbol, cx: &LateContext<'_>, if_block: &IfBlockType<'_>) -> bool { match *if_block { - IfBlockType::IfIs(caller, caller_ty, call_sym, if_then, _) => { + IfBlockType::IfIs(caller, caller_ty, call_sym, if_then) => { // If the block could be identified as `if x.is_none()/is_err()`, // we then only need to check the if_then return to see if it is none/err. is_type_diagnostic_item(cx, caller_ty, smbl) @@ -235,7 +234,7 @@ impl QuestionMark { && !is_else_clause(cx.tcx, expr) && let ExprKind::MethodCall(segment, caller, ..) = &cond.kind && let caller_ty = cx.typeck_results().expr_ty(caller) - && let if_block = IfBlockType::IfIs(caller, caller_ty, segment.ident.name, then, r#else) + && let if_block = IfBlockType::IfIs(caller, caller_ty, segment.ident.name, then) && (is_early_return(sym::Option, cx, &if_block) || is_early_return(sym::Result, cx, &if_block)) { let mut applicability = Applicability::MachineApplicable; diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index a65bc0ce458b..db378cfd7555 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -26,18 +26,18 @@ pub(super) fn check<'tcx>( // `Repr(C)` <-> unordered type. // If the first field of the `Repr(C)` type matches then the transmute is ok - (ReducedTy::OrderedFields(_, Some(from_sub_ty)), ReducedTy::UnorderedFields(to_sub_ty)) - | (ReducedTy::UnorderedFields(from_sub_ty), ReducedTy::OrderedFields(_, Some(to_sub_ty))) => { + (ReducedTy::OrderedFields(Some(from_sub_ty)), ReducedTy::UnorderedFields(to_sub_ty)) + | (ReducedTy::UnorderedFields(from_sub_ty), ReducedTy::OrderedFields(Some(to_sub_ty))) => { from_ty = from_sub_ty; to_ty = to_sub_ty; continue; }, - (ReducedTy::OrderedFields(_, Some(from_sub_ty)), ReducedTy::Other(to_sub_ty)) if reduced_tys.to_fat_ptr => { + (ReducedTy::OrderedFields(Some(from_sub_ty)), ReducedTy::Other(to_sub_ty)) if reduced_tys.to_fat_ptr => { from_ty = from_sub_ty; to_ty = to_sub_ty; continue; }, - (ReducedTy::Other(from_sub_ty), ReducedTy::OrderedFields(_, Some(to_sub_ty))) + (ReducedTy::Other(from_sub_ty), ReducedTy::OrderedFields(Some(to_sub_ty))) if reduced_tys.from_fat_ptr => { from_ty = from_sub_ty; @@ -235,8 +235,8 @@ enum ReducedTy<'tcx> { TypeErasure { raw_ptr_only: bool }, /// The type is a struct containing either zero non-zero sized fields, or multiple non-zero /// sized fields with a defined order. - /// The second value is the first non-zero sized type. - OrderedFields(Ty<'tcx>, Option>), + /// The value is the first non-zero sized type. + OrderedFields(Option>), /// The type is a struct containing multiple non-zero sized fields with no defined order. UnorderedFields(Ty<'tcx>), /// Any other type. @@ -259,7 +259,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> ty::Tuple(args) => { let mut iter = args.iter(); let Some(sized_ty) = iter.find(|&ty| !is_zero_sized_ty(cx, ty)) else { - return ReducedTy::OrderedFields(ty, None); + return ReducedTy::OrderedFields(None); }; if iter.all(|ty| is_zero_sized_ty(cx, ty)) { ty = sized_ty; @@ -281,7 +281,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> continue; } if def.repr().inhibit_struct_field_reordering_opt() { - ReducedTy::OrderedFields(ty, Some(sized_ty)) + ReducedTy::OrderedFields(Some(sized_ty)) } else { ReducedTy::UnorderedFields(ty) } From e6580daaf45ba6e09712e96adf4523c64bd91bfe Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Wed, 29 Nov 2023 15:29:11 -0500 Subject: [PATCH 1028/1222] Remove #[allow(unused_tuple_struct_fields)] from Clippy tests --- .../auxiliary/helper.rs | 1 - tests/ui/format.fixed | 1 - tests/ui/format.rs | 1 - tests/ui/format.stderr | 30 +++++------ tests/ui/from_iter_instead_of_collect.fixed | 2 +- tests/ui/from_iter_instead_of_collect.rs | 2 +- tests/ui/must_use_candidates.fixed | 1 - tests/ui/must_use_candidates.rs | 1 - tests/ui/must_use_candidates.stderr | 10 ++-- tests/ui/numbered_fields.fixed | 1 - tests/ui/numbered_fields.rs | 1 - tests/ui/numbered_fields.stderr | 4 +- tests/ui/option_if_let_else.fixed | 1 - tests/ui/option_if_let_else.rs | 1 - tests/ui/option_if_let_else.stderr | 50 +++++++++---------- tests/ui/unreadable_literal.fixed | 1 - tests/ui/unreadable_literal.rs | 1 - tests/ui/unreadable_literal.stderr | 20 ++++---- 18 files changed, 59 insertions(+), 70 deletions(-) diff --git a/tests/ui/borrow_interior_mutable_const/auxiliary/helper.rs b/tests/ui/borrow_interior_mutable_const/auxiliary/helper.rs index b03c21262c3b..96e037d4fcd7 100644 --- a/tests/ui/borrow_interior_mutable_const/auxiliary/helper.rs +++ b/tests/ui/borrow_interior_mutable_const/auxiliary/helper.rs @@ -2,7 +2,6 @@ // As the most common case is the `http` crate, it replicates `http::HeaderName`'s structure. #![allow(clippy::declare_interior_mutable_const)] -#![allow(unused_tuple_struct_fields)] use std::sync::atomic::AtomicUsize; diff --git a/tests/ui/format.fixed b/tests/ui/format.fixed index 36679a9c883d..2b32fdeae2b5 100644 --- a/tests/ui/format.fixed +++ b/tests/ui/format.fixed @@ -1,6 +1,5 @@ #![warn(clippy::useless_format)] #![allow( - unused_tuple_struct_fields, clippy::print_literal, clippy::redundant_clone, clippy::to_string_in_format_args, diff --git a/tests/ui/format.rs b/tests/ui/format.rs index b0920daf0886..bad192067e93 100644 --- a/tests/ui/format.rs +++ b/tests/ui/format.rs @@ -1,6 +1,5 @@ #![warn(clippy::useless_format)] #![allow( - unused_tuple_struct_fields, clippy::print_literal, clippy::redundant_clone, clippy::to_string_in_format_args, diff --git a/tests/ui/format.stderr b/tests/ui/format.stderr index d4630a8f1dab..e02fdb1e4151 100644 --- a/tests/ui/format.stderr +++ b/tests/ui/format.stderr @@ -1,5 +1,5 @@ error: useless use of `format!` - --> $DIR/format.rs:20:5 + --> $DIR/format.rs:19:5 | LL | format!("foo"); | ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` @@ -8,19 +8,19 @@ LL | format!("foo"); = help: to override `-D warnings` add `#[allow(clippy::useless_format)]` error: useless use of `format!` - --> $DIR/format.rs:21:5 + --> $DIR/format.rs:20:5 | LL | format!("{{}}"); | ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{}".to_string()` error: useless use of `format!` - --> $DIR/format.rs:22:5 + --> $DIR/format.rs:21:5 | LL | format!("{{}} abc {{}}"); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string()` error: useless use of `format!` - --> $DIR/format.rs:23:5 + --> $DIR/format.rs:22:5 | LL | / format!( LL | | r##"foo {{}} @@ -35,67 +35,67 @@ LL ~ " bar"##.to_string(); | error: useless use of `format!` - --> $DIR/format.rs:28:13 + --> $DIR/format.rs:27:13 | LL | let _ = format!(""); | ^^^^^^^^^^^ help: consider using `String::new()`: `String::new()` error: useless use of `format!` - --> $DIR/format.rs:30:5 + --> $DIR/format.rs:29:5 | LL | format!("{}", "foo"); | ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` error: useless use of `format!` - --> $DIR/format.rs:38:5 + --> $DIR/format.rs:37:5 | LL | format!("{}", arg); | ^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()` error: useless use of `format!` - --> $DIR/format.rs:68:5 + --> $DIR/format.rs:67:5 | LL | format!("{}", 42.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string()` error: useless use of `format!` - --> $DIR/format.rs:70:5 + --> $DIR/format.rs:69:5 | LL | format!("{}", x.display().to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string()` error: useless use of `format!` - --> $DIR/format.rs:74:18 + --> $DIR/format.rs:73:18 | LL | let _ = Some(format!("{}", a + "bar")); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `a + "bar"` error: useless use of `format!` - --> $DIR/format.rs:78:22 + --> $DIR/format.rs:77:22 | LL | let _s: String = format!("{}", &*v.join("\n")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `(&*v.join("\n")).to_string()` error: useless use of `format!` - --> $DIR/format.rs:84:13 + --> $DIR/format.rs:83:13 | LL | let _ = format!("{x}"); | ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()` error: useless use of `format!` - --> $DIR/format.rs:86:13 + --> $DIR/format.rs:85:13 | LL | let _ = format!("{y}", y = x); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()` error: useless use of `format!` - --> $DIR/format.rs:90:13 + --> $DIR/format.rs:89:13 | LL | let _ = format!("{abc}"); | ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `abc.to_string()` error: useless use of `format!` - --> $DIR/format.rs:92:13 + --> $DIR/format.rs:91:13 | LL | let _ = format!("{xx}"); | ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `xx.to_string()` diff --git a/tests/ui/from_iter_instead_of_collect.fixed b/tests/ui/from_iter_instead_of_collect.fixed index 82c8e1d8abdb..c250162dfb8c 100644 --- a/tests/ui/from_iter_instead_of_collect.fixed +++ b/tests/ui/from_iter_instead_of_collect.fixed @@ -1,5 +1,5 @@ #![warn(clippy::from_iter_instead_of_collect)] -#![allow(unused_imports, unused_tuple_struct_fields)] +#![allow(unused_imports)] #![allow(clippy::useless_vec)] use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque}; diff --git a/tests/ui/from_iter_instead_of_collect.rs b/tests/ui/from_iter_instead_of_collect.rs index 2aed6b14be14..8adbb841c8ba 100644 --- a/tests/ui/from_iter_instead_of_collect.rs +++ b/tests/ui/from_iter_instead_of_collect.rs @@ -1,5 +1,5 @@ #![warn(clippy::from_iter_instead_of_collect)] -#![allow(unused_imports, unused_tuple_struct_fields)] +#![allow(unused_imports)] #![allow(clippy::useless_vec)] use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque}; diff --git a/tests/ui/must_use_candidates.fixed b/tests/ui/must_use_candidates.fixed index 3ed705b29061..db20ba29f3d9 100644 --- a/tests/ui/must_use_candidates.fixed +++ b/tests/ui/must_use_candidates.fixed @@ -1,7 +1,6 @@ #![feature(never_type)] #![allow( unused_mut, - unused_tuple_struct_fields, clippy::redundant_allocation, clippy::needless_pass_by_ref_mut )] diff --git a/tests/ui/must_use_candidates.rs b/tests/ui/must_use_candidates.rs index ab8efea0ac7e..d7e561302450 100644 --- a/tests/ui/must_use_candidates.rs +++ b/tests/ui/must_use_candidates.rs @@ -1,7 +1,6 @@ #![feature(never_type)] #![allow( unused_mut, - unused_tuple_struct_fields, clippy::redundant_allocation, clippy::needless_pass_by_ref_mut )] diff --git a/tests/ui/must_use_candidates.stderr b/tests/ui/must_use_candidates.stderr index 581399f3e486..39446bf6cd92 100644 --- a/tests/ui/must_use_candidates.stderr +++ b/tests/ui/must_use_candidates.stderr @@ -1,5 +1,5 @@ error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:16:1 + --> $DIR/must_use_candidates.rs:15:1 | LL | pub fn pure(i: u8) -> u8 { | ^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn pure(i: u8) -> u8` @@ -8,25 +8,25 @@ LL | pub fn pure(i: u8) -> u8 { = help: to override `-D warnings` add `#[allow(clippy::must_use_candidate)]` error: this method could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:21:5 + --> $DIR/must_use_candidates.rs:20:5 | LL | pub fn inherent_pure(&self) -> u8 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn inherent_pure(&self) -> u8` error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:52:1 + --> $DIR/must_use_candidates.rs:51:1 | LL | pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool` error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:64:1 + --> $DIR/must_use_candidates.rs:63:1 | LL | pub fn rcd(_x: Rc) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn rcd(_x: Rc) -> bool` error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:72:1 + --> $DIR/must_use_candidates.rs:71:1 | LL | pub fn arcd(_x: Arc) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn arcd(_x: Arc) -> bool` diff --git a/tests/ui/numbered_fields.fixed b/tests/ui/numbered_fields.fixed index 7f0a6f8e5447..dc88081ba0a7 100644 --- a/tests/ui/numbered_fields.fixed +++ b/tests/ui/numbered_fields.fixed @@ -1,5 +1,4 @@ #![warn(clippy::init_numbered_fields)] -#![allow(unused_tuple_struct_fields)] #[derive(Default)] struct TupleStruct(u32, u32, u8); diff --git a/tests/ui/numbered_fields.rs b/tests/ui/numbered_fields.rs index 38f3b36ec4d0..e8fa652e3c1d 100644 --- a/tests/ui/numbered_fields.rs +++ b/tests/ui/numbered_fields.rs @@ -1,5 +1,4 @@ #![warn(clippy::init_numbered_fields)] -#![allow(unused_tuple_struct_fields)] #[derive(Default)] struct TupleStruct(u32, u32, u8); diff --git a/tests/ui/numbered_fields.stderr b/tests/ui/numbered_fields.stderr index d52a0cf15a83..76f5e082f326 100644 --- a/tests/ui/numbered_fields.stderr +++ b/tests/ui/numbered_fields.stderr @@ -1,5 +1,5 @@ error: used a field initializer for a tuple struct - --> $DIR/numbered_fields.rs:18:13 + --> $DIR/numbered_fields.rs:17:13 | LL | let _ = TupleStruct { | _____________^ @@ -13,7 +13,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::init_numbered_fields)]` error: used a field initializer for a tuple struct - --> $DIR/numbered_fields.rs:25:13 + --> $DIR/numbered_fields.rs:24:13 | LL | let _ = TupleStruct { | _____________^ diff --git a/tests/ui/option_if_let_else.fixed b/tests/ui/option_if_let_else.fixed index 363520112ef2..d443334bb059 100644 --- a/tests/ui/option_if_let_else.fixed +++ b/tests/ui/option_if_let_else.fixed @@ -1,6 +1,5 @@ #![warn(clippy::option_if_let_else)] #![allow( - unused_tuple_struct_fields, clippy::ref_option_ref, clippy::equatable_if_let, clippy::let_unit_value, diff --git a/tests/ui/option_if_let_else.rs b/tests/ui/option_if_let_else.rs index aaa87a0db549..317c35bf8427 100644 --- a/tests/ui/option_if_let_else.rs +++ b/tests/ui/option_if_let_else.rs @@ -1,6 +1,5 @@ #![warn(clippy::option_if_let_else)] #![allow( - unused_tuple_struct_fields, clippy::ref_option_ref, clippy::equatable_if_let, clippy::let_unit_value, diff --git a/tests/ui/option_if_let_else.stderr b/tests/ui/option_if_let_else.stderr index 55a8360ffd0c..e053d356ff24 100644 --- a/tests/ui/option_if_let_else.stderr +++ b/tests/ui/option_if_let_else.stderr @@ -1,5 +1,5 @@ error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:11:5 + --> $DIR/option_if_let_else.rs:10:5 | LL | / if let Some(x) = string { LL | | (true, x) @@ -12,19 +12,19 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::option_if_let_else)]` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:29:13 + --> $DIR/option_if_let_else.rs:28:13 | LL | let _ = if let Some(s) = *string { s.len() } else { 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.map_or(0, |s| s.len())` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:30:13 + --> $DIR/option_if_let_else.rs:29:13 | LL | let _ = if let Some(s) = &num { s } else { &0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:31:13 + --> $DIR/option_if_let_else.rs:30:13 | LL | let _ = if let Some(s) = &mut num { | _____________^ @@ -44,13 +44,13 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:37:13 + --> $DIR/option_if_let_else.rs:36:13 | LL | let _ = if let Some(ref s) = num { s } else { &0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:38:13 + --> $DIR/option_if_let_else.rs:37:13 | LL | let _ = if let Some(mut s) = num { | _____________^ @@ -70,7 +70,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:44:13 + --> $DIR/option_if_let_else.rs:43:13 | LL | let _ = if let Some(ref mut s) = num { | _____________^ @@ -90,7 +90,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:53:5 + --> $DIR/option_if_let_else.rs:52:5 | LL | / if let Some(x) = arg { LL | | let y = x * x; @@ -109,7 +109,7 @@ LL + }) | error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:66:13 + --> $DIR/option_if_let_else.rs:65:13 | LL | let _ = if let Some(x) = arg { | _____________^ @@ -121,7 +121,7 @@ LL | | }; | |_____^ help: try: `arg.map_or_else(side_effect, |x| x)` error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:75:13 + --> $DIR/option_if_let_else.rs:74:13 | LL | let _ = if let Some(x) = arg { | _____________^ @@ -144,7 +144,7 @@ LL ~ }, |x| x * x * x * x); | error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:108:13 + --> $DIR/option_if_let_else.rs:107:13 | LL | / if let Some(idx) = s.find('.') { LL | | vec![s[..idx].to_string(), s[idx..].to_string()] @@ -154,7 +154,7 @@ LL | | } | |_____________^ help: try: `s.find('.').map_or_else(|| vec![s.to_string()], |idx| vec![s[..idx].to_string(), s[idx..].to_string()])` error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:119:5 + --> $DIR/option_if_let_else.rs:118:5 | LL | / if let Ok(binding) = variable { LL | | println!("Ok {binding}"); @@ -177,13 +177,13 @@ LL + }) | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:143:13 + --> $DIR/option_if_let_else.rs:142:13 | LL | let _ = if let Some(x) = optional { x + 2 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:153:13 + --> $DIR/option_if_let_else.rs:152:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ @@ -205,13 +205,13 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:181:13 + --> $DIR/option_if_let_else.rs:180:13 | LL | let _ = if let Some(x) = Some(0) { s.len() + x } else { s.len() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(0).map_or(s.len(), |x| s.len() + x)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:185:13 + --> $DIR/option_if_let_else.rs:184:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ @@ -231,7 +231,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:224:13 + --> $DIR/option_if_let_else.rs:223:13 | LL | let _ = match s { | _____________^ @@ -241,7 +241,7 @@ LL | | }; | |_____^ help: try: `s.map_or(1, |string| string.len())` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:228:13 + --> $DIR/option_if_let_else.rs:227:13 | LL | let _ = match Some(10) { | _____________^ @@ -251,7 +251,7 @@ LL | | }; | |_____^ help: try: `Some(10).map_or(5, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:234:13 + --> $DIR/option_if_let_else.rs:233:13 | LL | let _ = match res { | _____________^ @@ -261,7 +261,7 @@ LL | | }; | |_____^ help: try: `res.map_or(1, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:238:13 + --> $DIR/option_if_let_else.rs:237:13 | LL | let _ = match res { | _____________^ @@ -271,13 +271,13 @@ LL | | }; | |_____^ help: try: `res.map_or(1, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:242:13 + --> $DIR/option_if_let_else.rs:241:13 | LL | let _ = if let Ok(a) = res { a + 1 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `res.map_or(5, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:259:17 + --> $DIR/option_if_let_else.rs:258:17 | LL | let _ = match initial { | _________________^ @@ -287,7 +287,7 @@ LL | | }; | |_________^ help: try: `initial.as_ref().map_or(42, |value| do_something(value))` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:266:17 + --> $DIR/option_if_let_else.rs:265:17 | LL | let _ = match initial { | _________________^ @@ -297,7 +297,7 @@ LL | | }; | |_________^ help: try: `initial.as_mut().map_or(42, |value| do_something2(value))` error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:289:24 + --> $DIR/option_if_let_else.rs:288:24 | LL | let mut _hashmap = if let Some(hm) = &opt { | ________________________^ @@ -308,7 +308,7 @@ LL | | }; | |_____^ help: try: `opt.as_ref().map_or_else(HashMap::new, |hm| hm.clone())` error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:295:19 + --> $DIR/option_if_let_else.rs:294:19 | LL | let mut _hm = if let Some(hm) = &opt { hm.clone() } else { new_map!() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.as_ref().map_or_else(|| new_map!(), |hm| hm.clone())` diff --git a/tests/ui/unreadable_literal.fixed b/tests/ui/unreadable_literal.fixed index 6d8c719ee072..fb9c2672db82 100644 --- a/tests/ui/unreadable_literal.fixed +++ b/tests/ui/unreadable_literal.fixed @@ -1,5 +1,4 @@ #![warn(clippy::unreadable_literal)] -#![allow(unused_tuple_struct_fields)] struct Foo(u64); diff --git a/tests/ui/unreadable_literal.rs b/tests/ui/unreadable_literal.rs index 42ca773c3516..0a24fa852546 100644 --- a/tests/ui/unreadable_literal.rs +++ b/tests/ui/unreadable_literal.rs @@ -1,5 +1,4 @@ #![warn(clippy::unreadable_literal)] -#![allow(unused_tuple_struct_fields)] struct Foo(u64); diff --git a/tests/ui/unreadable_literal.stderr b/tests/ui/unreadable_literal.stderr index d7a3377ec37d..37f91acf82b9 100644 --- a/tests/ui/unreadable_literal.stderr +++ b/tests/ui/unreadable_literal.stderr @@ -1,5 +1,5 @@ error: long literal lacking separators - --> $DIR/unreadable_literal.rs:32:17 + --> $DIR/unreadable_literal.rs:31:17 | LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^^^ help: consider: `0b11_0110_i64` @@ -8,55 +8,55 @@ LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); = help: to override `-D warnings` add `#[allow(clippy::unreadable_literal)]` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:32:31 + --> $DIR/unreadable_literal.rs:31:31 | LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^^^^^^^ help: consider: `0x1234_5678_usize` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:32:49 + --> $DIR/unreadable_literal.rs:31:49 | LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^ help: consider: `123_456_f32` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:32:61 + --> $DIR/unreadable_literal.rs:31:61 | LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^^^ help: consider: `1.234_567_f32` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:34:20 + --> $DIR/unreadable_literal.rs:33:20 | LL | let _bad_sci = 1.123456e1; | ^^^^^^^^^^ help: consider: `1.123_456e1` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:36:18 + --> $DIR/unreadable_literal.rs:35:18 | LL | let _fail1 = 0xabcdef; | ^^^^^^^^ help: consider: `0x00ab_cdef` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:37:23 + --> $DIR/unreadable_literal.rs:36:23 | LL | let _fail2: u32 = 0xBAFEBAFE; | ^^^^^^^^^^ help: consider: `0xBAFE_BAFE` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:38:18 + --> $DIR/unreadable_literal.rs:37:18 | LL | let _fail3 = 0xabcdeff; | ^^^^^^^^^ help: consider: `0x0abc_deff` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:39:24 + --> $DIR/unreadable_literal.rs:38:24 | LL | let _fail4: i128 = 0xabcabcabcabcabcabc; | ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:40:18 + --> $DIR/unreadable_literal.rs:39:18 | LL | let _fail5 = 1.100300400; | ^^^^^^^^^^^ help: consider: `1.100_300_400` From 3cdf21866b06aa033e298f2810e72612eff3b990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 20 Dec 2023 19:13:24 +0000 Subject: [PATCH 1029/1222] Track `HirId` instead of `Span` in `ObligationCauseCode::SizedArgumentType` This gets us more accurate suggestions. --- tests/ui/crashes/ice-6251.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/crashes/ice-6251.stderr b/tests/ui/crashes/ice-6251.stderr index 11081dc8087e..0196c9923dbe 100644 --- a/tests/ui/crashes/ice-6251.stderr +++ b/tests/ui/crashes/ice-6251.stderr @@ -6,7 +6,7 @@ LL | fn bug() -> impl Iterator { | = help: the trait `std::marker::Sized` is not implemented for `[u8]` = help: unsized fn params are gated as an unstable feature -help: function arguments must have a statically known size, borrowed types always have a known size +help: function arguments must have a statically known size, borrowed slices always have a known size | LL | fn bug() -> impl Iterator { | + From a4afa9621a3e9750197792e2bfad02fb71e573cf Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 5 Jan 2024 10:02:40 +1100 Subject: [PATCH 1030/1222] Rename `EmitterWriter` as `HumanEmitter`. For consistency with other `Emitter` impls, such as `JsonEmitter`, `SilentEmitter`, `SharedEmitter`, etc. --- clippy_lints/src/doc/needless_doctest_main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/doc/needless_doctest_main.rs b/clippy_lints/src/doc/needless_doctest_main.rs index c639813a3f9a..a744b69ecb47 100644 --- a/clippy_lints/src/doc/needless_doctest_main.rs +++ b/clippy_lints/src/doc/needless_doctest_main.rs @@ -5,7 +5,7 @@ use crate::doc::{NEEDLESS_DOCTEST_MAIN, TEST_ATTR_IN_DOCTEST}; use clippy_utils::diagnostics::span_lint; use rustc_ast::{CoroutineKind, Fn, FnRetTy, Item, ItemKind}; use rustc_data_structures::sync::Lrc; -use rustc_errors::emitter::EmitterWriter; +use rustc_errors::emitter::HumanEmitter; use rustc_errors::DiagCtxt; use rustc_lint::LateContext; use rustc_parse::maybe_new_parser_from_source_str; @@ -44,7 +44,7 @@ pub fn check( let fallback_bundle = rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false); - let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle); + let emitter = HumanEmitter::new(Box::new(io::sink()), fallback_bundle); let dcx = DiagCtxt::with_emitter(Box::new(emitter)).disable_warnings(); #[expect(clippy::arc_with_non_send_sync)] // `Lrc` is expected by with_dcx let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); From 81fce27a4259ce3376378e5972302c5fead4f8bb Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Thu, 4 Jan 2024 10:29:47 +0000 Subject: [PATCH 1031/1222] Update clippy for hir::Guard removal --- clippy_lints/src/entry.rs | 4 +- clippy_lints/src/manual_clamp.rs | 4 +- clippy_lints/src/matches/collapsible_match.rs | 8 +-- .../src/matches/match_like_matches.rs | 23 ++------- clippy_lints/src/matches/needless_match.rs | 17 ++----- clippy_lints/src/matches/redundant_guards.rs | 50 ++++++++----------- .../src/matches/redundant_pattern_match.rs | 20 ++++---- .../src/mixed_read_write_in_expression.rs | 4 +- clippy_lints/src/utils/author.rs | 10 +--- clippy_utils/src/hir_utils.rs | 24 ++------- clippy_utils/src/lib.rs | 4 +- 11 files changed, 56 insertions(+), 112 deletions(-) diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index ce0a1dfdc61f..0b4bc375df0d 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -8,7 +8,7 @@ use core::fmt::{self, Write}; use rustc_errors::Applicability; use rustc_hir::hir_id::HirIdSet; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::{Block, Expr, ExprKind, Guard, HirId, Let, Pat, Stmt, StmtKind, UnOp}; +use rustc_hir::{Block, Expr, ExprKind, HirId, Pat, Stmt, StmtKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; use rustc_span::{Span, SyntaxContext, DUMMY_SP}; @@ -465,7 +465,7 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> { let mut is_map_used = self.is_map_used; for arm in arms { self.visit_pat(arm.pat); - if let Some(Guard::If(guard) | Guard::IfLet(&Let { init: guard, .. })) = arm.guard { + if let Some(guard) = arm.guard { self.visit_non_tail_expr(guard); } is_map_used |= self.visit_cond_arm(arm.body); diff --git a/clippy_lints/src/manual_clamp.rs b/clippy_lints/src/manual_clamp.rs index 385fe387a314..0da309f9531e 100644 --- a/clippy_lints/src/manual_clamp.rs +++ b/clippy_lints/src/manual_clamp.rs @@ -11,7 +11,7 @@ use clippy_utils::{ use itertools::Itertools; use rustc_errors::{Applicability, Diagnostic}; use rustc_hir::def::Res; -use rustc_hir::{Arm, BinOpKind, Block, Expr, ExprKind, Guard, HirId, PatKind, PathSegment, PrimTy, QPath, StmtKind}; +use rustc_hir::{Arm, BinOpKind, Block, Expr, ExprKind, HirId, PatKind, PathSegment, PrimTy, QPath, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::Ty; use rustc_session::impl_lint_pass; @@ -394,7 +394,7 @@ fn is_match_pattern<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Opt // Find possible min/max branches let minmax_values = |a: &'tcx Arm<'tcx>| { if let PatKind::Binding(_, var_hir_id, _, None) = &a.pat.kind - && let Some(Guard::If(e)) = a.guard + && let Some(e) = a.guard { Some((e, var_hir_id, a.body)) } else { diff --git a/clippy_lints/src/matches/collapsible_match.rs b/clippy_lints/src/matches/collapsible_match.rs index 91e6ca7fa8bc..5fef5930fab2 100644 --- a/clippy_lints/src/matches/collapsible_match.rs +++ b/clippy_lints/src/matches/collapsible_match.rs @@ -7,7 +7,7 @@ use clippy_utils::{ }; use rustc_errors::MultiSpan; use rustc_hir::LangItem::OptionNone; -use rustc_hir::{Arm, Expr, Guard, HirId, Let, Pat, PatKind}; +use rustc_hir::{Arm, Expr, HirId, Pat, PatKind}; use rustc_lint::LateContext; use rustc_span::Span; @@ -16,7 +16,7 @@ use super::COLLAPSIBLE_MATCH; pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) { if let Some(els_arm) = arms.iter().rfind(|arm| arm_is_wild_like(cx, arm)) { for arm in arms { - check_arm(cx, true, arm.pat, arm.body, arm.guard.as_ref(), Some(els_arm.body)); + check_arm(cx, true, arm.pat, arm.body, arm.guard, Some(els_arm.body)); } } } @@ -35,7 +35,7 @@ fn check_arm<'tcx>( outer_is_match: bool, outer_pat: &'tcx Pat<'tcx>, outer_then_body: &'tcx Expr<'tcx>, - outer_guard: Option<&'tcx Guard<'tcx>>, + outer_guard: Option<&'tcx Expr<'tcx>>, outer_else_body: Option<&'tcx Expr<'tcx>>, ) { let inner_expr = peel_blocks_with_stmt(outer_then_body); @@ -71,7 +71,7 @@ fn check_arm<'tcx>( // the binding must not be used in the if guard && outer_guard.map_or( true, - |(Guard::If(e) | Guard::IfLet(Let { init: e, .. }))| !is_local_used(cx, *e, binding_id) + |e| !is_local_used(cx, e, binding_id) ) // ...or anywhere in the inner expression && match inner { diff --git a/clippy_lints/src/matches/match_like_matches.rs b/clippy_lints/src/matches/match_like_matches.rs index 56123326fe4a..b062e81cefdd 100644 --- a/clippy_lints/src/matches/match_like_matches.rs +++ b/clippy_lints/src/matches/match_like_matches.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet_with_applicability; use clippy_utils::{is_lint_allowed, is_wild, span_contains_comment}; use rustc_ast::{Attribute, LitKind}; use rustc_errors::Applicability; -use rustc_hir::{Arm, BorrowKind, Expr, ExprKind, Guard, Pat, PatKind, QPath}; +use rustc_hir::{Arm, BorrowKind, Expr, ExprKind, Pat, PatKind, QPath}; use rustc_lint::{LateContext, LintContext}; use rustc_middle::ty; use rustc_span::source_map::Spanned; @@ -41,14 +41,8 @@ pub(super) fn check_match<'tcx>( find_matches_sugg( cx, scrutinee, - arms.iter().map(|arm| { - ( - cx.tcx.hir().attrs(arm.hir_id), - Some(arm.pat), - arm.body, - arm.guard.as_ref(), - ) - }), + arms.iter() + .map(|arm| (cx.tcx.hir().attrs(arm.hir_id), Some(arm.pat), arm.body, arm.guard)), e, false, ) @@ -67,14 +61,7 @@ where I: Clone + DoubleEndedIterator + ExactSizeIterator - + Iterator< - Item = ( - &'a [Attribute], - Option<&'a Pat<'b>>, - &'a Expr<'b>, - Option<&'a Guard<'b>>, - ), - >, + + Iterator>, &'a Expr<'b>, Option<&'a Expr<'b>>)>, { if !span_contains_comment(cx.sess().source_map(), expr.span) && iter.len() >= 2 @@ -115,7 +102,7 @@ where }) .join(" | ") }; - let pat_and_guard = if let Some(Guard::If(g)) = first_guard { + let pat_and_guard = if let Some(g) = first_guard { format!( "{pat} if {}", snippet_with_applicability(cx, g.span, "..", &mut applicability) diff --git a/clippy_lints/src/matches/needless_match.rs b/clippy_lints/src/matches/needless_match.rs index 44dc29c36a6b..cc482f15a91d 100644 --- a/clippy_lints/src/matches/needless_match.rs +++ b/clippy_lints/src/matches/needless_match.rs @@ -8,7 +8,7 @@ use clippy_utils::{ }; use rustc_errors::Applicability; use rustc_hir::LangItem::OptionNone; -use rustc_hir::{Arm, BindingAnnotation, ByRef, Expr, ExprKind, Guard, ItemKind, Node, Pat, PatKind, Path, QPath}; +use rustc_hir::{Arm, BindingAnnotation, ByRef, Expr, ExprKind, ItemKind, Node, Pat, PatKind, Path, QPath}; use rustc_lint::LateContext; use rustc_span::sym; @@ -66,18 +66,9 @@ fn check_all_arms(cx: &LateContext<'_>, match_expr: &Expr<'_>, arms: &[Arm<'_>]) let arm_expr = peel_blocks_with_stmt(arm.body); if let Some(guard_expr) = &arm.guard { - match guard_expr { - // gives up if `pat if expr` can have side effects - Guard::If(if_cond) => { - if if_cond.can_have_side_effects() { - return false; - } - }, - // gives up `pat if let ...` arm - Guard::IfLet(_) => { - return false; - }, - }; + if guard_expr.can_have_side_effects() { + return false; + } } if let PatKind::Wild = arm.pat.kind { diff --git a/clippy_lints/src/matches/redundant_guards.rs b/clippy_lints/src/matches/redundant_guards.rs index f57b22374c8e..dfaaeb14ca3c 100644 --- a/clippy_lints/src/matches/redundant_guards.rs +++ b/clippy_lints/src/matches/redundant_guards.rs @@ -5,7 +5,7 @@ use clippy_utils::visitors::{for_each_expr, is_local_used}; use rustc_ast::{BorrowKind, LitKind}; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{Arm, BinOpKind, Expr, ExprKind, Guard, MatchSource, Node, Pat, PatKind}; +use rustc_hir::{Arm, BinOpKind, Expr, ExprKind, MatchSource, Node, Pat, PatKind}; use rustc_lint::LateContext; use rustc_span::symbol::Ident; use rustc_span::{Span, Symbol}; @@ -21,20 +21,19 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>]) { }; // `Some(x) if matches!(x, y)` - if let Guard::If(if_expr) = guard - && let ExprKind::Match( - scrutinee, - [ - arm, - Arm { - pat: Pat { - kind: PatKind::Wild, .. - }, - .. + if let ExprKind::Match( + scrutinee, + [ + arm, + Arm { + pat: Pat { + kind: PatKind::Wild, .. }, - ], - MatchSource::Normal, - ) = if_expr.kind + .. + }, + ], + MatchSource::Normal, + ) = guard.kind && let Some(binding) = get_pat_binding(cx, scrutinee, outer_arm) { let pat_span = match (arm.pat.kind, binding.byref_ident) { @@ -45,14 +44,14 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>]) { emit_redundant_guards( cx, outer_arm, - if_expr.span, + guard.span, snippet(cx, pat_span, ""), &binding, arm.guard, ); } // `Some(x) if let Some(2) = x` - else if let Guard::IfLet(let_expr) = guard + else if let ExprKind::Let(let_expr) = guard.kind && let Some(binding) = get_pat_binding(cx, let_expr.init, outer_arm) { let pat_span = match (let_expr.pat.kind, binding.byref_ident) { @@ -71,8 +70,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>]) { } // `Some(x) if x == Some(2)` // `Some(x) if Some(2) == x` - else if let Guard::If(if_expr) = guard - && let ExprKind::Binary(bin_op, local, pat) = if_expr.kind + else if let ExprKind::Binary(bin_op, local, pat) = guard.kind && matches!(bin_op.node, BinOpKind::Eq) // Ensure they have the same type. If they don't, we'd need deref coercion which isn't // possible (currently) in a pattern. In some cases, you can use something like @@ -96,16 +94,15 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>]) { emit_redundant_guards( cx, outer_arm, - if_expr.span, + guard.span, snippet(cx, pat_span, ""), &binding, None, ); - } else if let Guard::If(if_expr) = guard - && let ExprKind::MethodCall(path, recv, args, ..) = if_expr.kind + } else if let ExprKind::MethodCall(path, recv, args, ..) = guard.kind && let Some(binding) = get_pat_binding(cx, recv, outer_arm) { - check_method_calls(cx, outer_arm, path.ident.name, recv, args, if_expr, &binding); + check_method_calls(cx, outer_arm, path.ident.name, recv, args, guard, &binding); } } } @@ -216,7 +213,7 @@ fn emit_redundant_guards<'tcx>( guard_span: Span, binding_replacement: Cow<'static, str>, pat_binding: &PatBindingInfo, - inner_guard: Option>, + inner_guard: Option<&Expr<'_>>, ) { span_lint_and_then( cx, @@ -242,12 +239,7 @@ fn emit_redundant_guards<'tcx>( ( guard_span.source_callsite().with_lo(outer_arm.pat.span.hi()), inner_guard.map_or_else(String::new, |guard| { - let (prefix, span) = match guard { - Guard::If(e) => ("if", e.span), - Guard::IfLet(l) => ("if let", l.span), - }; - - format!(" {prefix} {}", snippet(cx, span, "")) + format!(" if {}", snippet(cx, guard.span, "")) }), ), ], diff --git a/clippy_lints/src/matches/redundant_pattern_match.rs b/clippy_lints/src/matches/redundant_pattern_match.rs index a4acdfb1db4e..b5870d94d996 100644 --- a/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/clippy_lints/src/matches/redundant_pattern_match.rs @@ -9,7 +9,7 @@ use rustc_ast::ast::LitKind; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::LangItem::{self, OptionNone, OptionSome, PollPending, PollReady, ResultErr, ResultOk}; -use rustc_hir::{Arm, Expr, ExprKind, Guard, Node, Pat, PatKind, QPath, UnOp}; +use rustc_hir::{Arm, Expr, ExprKind, Node, Pat, PatKind, QPath, UnOp}; use rustc_lint::LateContext; use rustc_middle::ty::{self, GenericArgKind, Ty}; use rustc_span::{sym, Span, Symbol}; @@ -277,8 +277,6 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op let mut sugg = format!("{}.{good_method}", snippet(cx, result_expr.span, "_")); if let Some(guard) = maybe_guard { - let Guard::If(guard) = *guard else { return }; // `...is_none() && let ...` is a syntax error - // wow, the HIR for match guards in `PAT if let PAT = expr && expr => ...` is annoying! // `guard` here is `Guard::If` with the let expression somewhere deep in the tree of exprs, // counter to the intuition that it should be `Guard::IfLet`, so we need another check @@ -319,7 +317,7 @@ fn found_good_method<'tcx>( cx: &LateContext<'_>, arms: &'tcx [Arm<'tcx>], node: (&PatKind<'_>, &PatKind<'_>), -) -> Option<(&'static str, Option<&'tcx Guard<'tcx>>)> { +) -> Option<(&'static str, Option<&'tcx Expr<'tcx>>)> { match node { ( PatKind::TupleStruct(ref path_left, patterns_left, _), @@ -409,7 +407,7 @@ fn get_good_method<'tcx>( cx: &LateContext<'_>, arms: &'tcx [Arm<'tcx>], path_left: &QPath<'_>, -) -> Option<(&'static str, Option<&'tcx Guard<'tcx>>)> { +) -> Option<(&'static str, Option<&'tcx Expr<'tcx>>)> { if let Some(name) = get_ident(path_left) { let (expected_item_left, should_be_left, should_be_right) = match name.as_str() { "Ok" => (Item::Lang(ResultOk), "is_ok()", "is_err()"), @@ -478,7 +476,7 @@ fn find_good_method_for_match<'a, 'tcx>( expected_item_right: Item, should_be_left: &'a str, should_be_right: &'a str, -) -> Option<(&'a str, Option<&'tcx Guard<'tcx>>)> { +) -> Option<(&'a str, Option<&'tcx Expr<'tcx>>)> { let first_pat = arms[0].pat; let second_pat = arms[1].pat; @@ -496,8 +494,8 @@ fn find_good_method_for_match<'a, 'tcx>( match body_node_pair { (ExprKind::Lit(lit_left), ExprKind::Lit(lit_right)) => match (&lit_left.node, &lit_right.node) { - (LitKind::Bool(true), LitKind::Bool(false)) => Some((should_be_left, arms[0].guard.as_ref())), - (LitKind::Bool(false), LitKind::Bool(true)) => Some((should_be_right, arms[1].guard.as_ref())), + (LitKind::Bool(true), LitKind::Bool(false)) => Some((should_be_left, arms[0].guard)), + (LitKind::Bool(false), LitKind::Bool(true)) => Some((should_be_right, arms[1].guard)), _ => None, }, _ => None, @@ -511,7 +509,7 @@ fn find_good_method_for_matches_macro<'a, 'tcx>( expected_item_left: Item, should_be_left: &'a str, should_be_right: &'a str, -) -> Option<(&'a str, Option<&'tcx Guard<'tcx>>)> { +) -> Option<(&'a str, Option<&'tcx Expr<'tcx>>)> { let first_pat = arms[0].pat; let body_node_pair = if is_pat_variant(cx, first_pat, path_left, expected_item_left) { @@ -522,8 +520,8 @@ fn find_good_method_for_matches_macro<'a, 'tcx>( match body_node_pair { (ExprKind::Lit(lit_left), ExprKind::Lit(lit_right)) => match (&lit_left.node, &lit_right.node) { - (LitKind::Bool(true), LitKind::Bool(false)) => Some((should_be_left, arms[0].guard.as_ref())), - (LitKind::Bool(false), LitKind::Bool(true)) => Some((should_be_right, arms[1].guard.as_ref())), + (LitKind::Bool(true), LitKind::Bool(false)) => Some((should_be_left, arms[0].guard)), + (LitKind::Bool(false), LitKind::Bool(true)) => Some((should_be_right, arms[1].guard)), _ => None, }, _ => None, diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs index 3ff40081c472..195ce17629a7 100644 --- a/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/clippy_lints/src/mixed_read_write_in_expression.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_note}; use clippy_utils::{get_parent_expr, path_to_local, path_to_local_id}; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Guard, HirId, Local, Node, Stmt, StmtKind}; +use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, Local, Node, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::declare_lint_pass; @@ -119,7 +119,7 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> { ExprKind::Match(e, arms, _) => { self.visit_expr(e); for arm in arms { - if let Some(Guard::If(if_expr)) = arm.guard { + if let Some(if_expr) = arm.guard { self.visit_expr(if_expr); } // make sure top level arm expressions aren't linted diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 8817e46b3c8c..8d38b87e1d79 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -318,17 +318,11 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { self.pat(field!(arm.pat)); match arm.value.guard { None => chain!(self, "{arm}.guard.is_none()"), - Some(hir::Guard::If(expr)) => { + Some(expr) => { bind!(self, expr); - chain!(self, "let Some(Guard::If({expr})) = {arm}.guard"); + chain!(self, "let Some({expr}) = {arm}.guard"); self.expr(expr); }, - Some(hir::Guard::IfLet(let_expr)) => { - bind!(self, let_expr); - chain!(self, "let Some(Guard::IfLet({let_expr}) = {arm}.guard"); - self.pat(field!(let_expr.pat)); - self.expr(field!(let_expr.init)); - }, } self.expr(field!(arm.body)); } diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index e610ed930505..a23105691bf3 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -8,7 +8,7 @@ use rustc_hir::def::Res; use rustc_hir::MatchSource::TryDesugar; use rustc_hir::{ ArrayLen, BinOpKind, BindingAnnotation, Block, BodyId, Closure, Expr, ExprField, ExprKind, FnRetTy, GenericArg, - GenericArgs, Guard, HirId, HirIdMap, InlineAsmOperand, Let, Lifetime, LifetimeName, Pat, PatField, PatKind, Path, + GenericArgs, HirId, HirIdMap, InlineAsmOperand, Let, Lifetime, LifetimeName, Pat, PatField, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding, }; use rustc_lexer::{tokenize, TokenKind}; @@ -320,7 +320,7 @@ impl HirEqInterExpr<'_, '_, '_> { && self.eq_expr(le, re) && over(la, ra, |l, r| { self.eq_pat(l.pat, r.pat) - && both(&l.guard, &r.guard, |l, r| self.eq_guard(l, r)) + && both(&l.guard, &r.guard, |l, r| self.eq_expr(l, r)) && self.eq_expr(l.body, r.body) }) }, @@ -410,16 +410,6 @@ impl HirEqInterExpr<'_, '_, '_> { left.ident.name == right.ident.name && self.eq_expr(left.expr, right.expr) } - fn eq_guard(&mut self, left: &Guard<'_>, right: &Guard<'_>) -> bool { - match (left, right) { - (Guard::If(l), Guard::If(r)) => self.eq_expr(l, r), - (Guard::IfLet(l), Guard::IfLet(r)) => { - self.eq_pat(l.pat, r.pat) && both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r)) && self.eq_expr(l.init, r.init) - }, - _ => false, - } - } - fn eq_generic_arg(&mut self, left: &GenericArg<'_>, right: &GenericArg<'_>) -> bool { match (left, right) { (GenericArg::Const(l), GenericArg::Const(r)) => self.eq_body(l.value.body, r.value.body), @@ -876,7 +866,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { for arm in arms { self.hash_pat(arm.pat); if let Some(ref e) = arm.guard { - self.hash_guard(e); + self.hash_expr(e); } self.hash_expr(arm.body); } @@ -1056,14 +1046,6 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } - pub fn hash_guard(&mut self, g: &Guard<'_>) { - match g { - Guard::If(expr) | Guard::IfLet(Let { init: expr, .. }) => { - self.hash_expr(expr); - }, - } - } - pub fn hash_lifetime(&mut self, lifetime: &Lifetime) { lifetime.ident.name.hash(&mut self.s); std::mem::discriminant(&lifetime.res).hash(&mut self.s); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 70a3c6f82c1c..cdf8528f48a2 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -3164,7 +3164,7 @@ pub fn is_never_expr<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> Option< self.is_never = false; if let Some(guard) = arm.guard { let in_final_expr = mem::replace(&mut self.in_final_expr, false); - self.visit_expr(guard.body()); + self.visit_expr(guard); self.in_final_expr = in_final_expr; // The compiler doesn't consider diverging guards as causing the arm to diverge. self.is_never = false; @@ -3223,7 +3223,7 @@ pub fn is_never_expr<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> Option< fn visit_arm(&mut self, arm: &Arm<'tcx>) { if let Some(guard) = arm.guard { let in_final_expr = mem::replace(&mut self.in_final_expr, false); - self.visit_expr(guard.body()); + self.visit_expr(guard); self.in_final_expr = in_final_expr; } self.visit_expr(arm.body); From d534bcb0a5e77be4d96d38dfc42d9d45bc796cf8 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 2 Jan 2024 23:32:40 +0300 Subject: [PATCH 1032/1222] rustc_span: Optimize syntax context comparisons Including comparisons with root context --- clippy_lints/src/casts/unnecessary_cast.rs | 2 +- clippy_lints/src/implicit_hasher.rs | 2 +- clippy_lints/src/implicit_return.rs | 2 +- clippy_lints/src/methods/option_map_unwrap_or.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/casts/unnecessary_cast.rs b/clippy_lints/src/casts/unnecessary_cast.rs index 849920bb76d5..3761ba81f521 100644 --- a/clippy_lints/src/casts/unnecessary_cast.rs +++ b/clippy_lints/src/casts/unnecessary_cast.rs @@ -145,7 +145,7 @@ pub(super) fn check<'tcx>( if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) { if let Some(id) = path_to_local(cast_expr) && let Some(span) = cx.tcx.hir().opt_span(id) - && span.ctxt() != cast_expr.span.ctxt() + && !span.eq_ctxt(cast_expr.span) { // Binding context is different than the identifiers context. // Weird macro wizardry could be involved here. diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 43eb6a9b8386..788fe8287278 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -118,7 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { vis.visit_ty(impl_.self_ty); for target in &vis.found { - if item.span.ctxt() != target.span().ctxt() { + if !item.span.eq_ctxt(target.span()) { return; } diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index d68c5c4bac68..5288efd8df8c 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -225,7 +225,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitReturn { _: LocalDefId, ) { if (!matches!(kind, FnKind::Closure) && matches!(decl.output, FnRetTy::DefaultReturn(_))) - || span.ctxt() != body.value.span.ctxt() + || !span.eq_ctxt(body.value.span) || in_external_macro(cx.sess(), span) { return; diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 63e64a5b35d0..47c9438c588f 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -67,7 +67,7 @@ pub(super) fn check<'tcx>( } } - if unwrap_arg.span.ctxt() != map_span.ctxt() { + if !unwrap_arg.span.eq_ctxt(map_span) { return; } From 47f8ac9c9d7c736aafc8688df05964d3385432a5 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 3 Jan 2024 12:17:35 +1100 Subject: [PATCH 1033/1222] Make `DiagnosticBuilder::emit` consuming. This works for most of its call sites. This is nice, because `emit` very much makes sense as a consuming operation -- indeed, `DiagnosticBuilderState` exists to ensure no diagnostic is emitted twice, but it uses runtime checks. For the small number of call sites where a consuming emit doesn't work, the commit adds `DiagnosticBuilder::emit_without_consuming`. (This will be removed in subsequent commits.) Likewise, `emit_unless` becomes consuming. And `delay_as_bug` becomes consuming, while `delay_as_bug_without_consuming` is added (which will also be removed in subsequent commits.) All this requires significant changes to `DiagnosticBuilder`'s chaining methods. Currently `DiagnosticBuilder` method chaining uses a non-consuming `&mut self -> &mut Self` style, which allows chaining to be used when the chain ends in `emit()`, like so: ``` struct_err(msg).span(span).emit(); ``` But it doesn't work when producing a `DiagnosticBuilder` value, requiring this: ``` let mut err = self.struct_err(msg); err.span(span); err ``` This style of chaining won't work with consuming `emit` though. For that, we need to use to a `self -> Self` style. That also would allow `DiagnosticBuilder` production to be chained, e.g.: ``` self.struct_err(msg).span(span) ``` However, removing the `&mut self -> &mut Self` style would require that individual modifications of a `DiagnosticBuilder` go from this: ``` err.span(span); ``` to this: ``` err = err.span(span); ``` There are *many* such places. I have a high tolerance for tedious refactorings, but even I gave up after a long time trying to convert them all. Instead, this commit has it both ways: the existing `&mut self -> Self` chaining methods are kept, and new `self -> Self` chaining methods are added, all of which have a `_mv` suffix (short for "move"). Changes to the existing `forward!` macro lets this happen with very little additional boilerplate code. I chose to add the suffix to the new chaining methods rather than the existing ones, because the number of changes required is much smaller that way. This doubled chainging is a bit clumsy, but I think it is worthwhile because it allows a *lot* of good things to subsequently happen. In this commit, there are many `mut` qualifiers removed in places where diagnostics are emitted without being modified. In subsequent commits: - chaining can be used more, making the code more concise; - more use of chaining also permits the removal of redundant diagnostic APIs like `struct_err_with_code`, which can be replaced easily with `struct_err` + `code_mv`; - `emit_without_diagnostic` can be removed, which simplifies a lot of machinery, removing the need for `DiagnosticBuilderState`. --- clippy_config/src/msrvs.rs | 2 +- clippy_utils/src/attrs.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_config/src/msrvs.rs b/clippy_config/src/msrvs.rs index 471ad73e2074..76f3663f04f2 100644 --- a/clippy_config/src/msrvs.rs +++ b/clippy_config/src/msrvs.rs @@ -109,7 +109,7 @@ impl Msrv { if let Some(duplicate) = msrv_attrs.last() { sess.dcx() .struct_span_err(duplicate.span, "`clippy::msrv` is defined multiple times") - .span_note(msrv_attr.span, "first definition found here") + .span_note_mv(msrv_attr.span, "first definition found here") .emit(); } diff --git a/clippy_utils/src/attrs.rs b/clippy_utils/src/attrs.rs index db80e07ca1c4..19d38903ade2 100644 --- a/clippy_utils/src/attrs.rs +++ b/clippy_utils/src/attrs.rs @@ -136,7 +136,7 @@ pub fn get_unique_attr<'a>( if let Some(duplicate) = unique_attr { sess.dcx() .struct_span_err(attr.span, format!("`{name}` is defined multiple times")) - .span_note(duplicate.span, "first definition found here") + .span_note_mv(duplicate.span, "first definition found here") .emit(); } else { unique_attr = Some(attr); From da255101ef0b2c0c19fe0f8a747012df16cb2595 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 12 Nov 2023 18:57:24 +0000 Subject: [PATCH 1034/1222] Rustdoc and Clippy stop misusing Key for Ty -> (adt) DefId --- clippy_lints/src/copies.rs | 3 +-- clippy_lints/src/methods/drain_collect.rs | 7 +++---- clippy_lints/src/methods/redundant_as_str.rs | 7 +------ clippy_lints/src/mut_key.rs | 3 +-- clippy_lints/src/non_copy_const.rs | 3 +-- clippy_lints/src/transmute/transmute_int_to_non_zero.rs | 5 ++--- 6 files changed, 9 insertions(+), 19 deletions(-) diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index d91af76f5e0d..bd07c19a2d81 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -12,7 +12,6 @@ use rustc_errors::Applicability; use rustc_hir::def_id::DefIdSet; use rustc_hir::{intravisit, BinOpKind, Block, Expr, ExprKind, HirId, HirIdSet, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::query::Key; use rustc_session::impl_lint_pass; use rustc_span::hygiene::walk_chain; use rustc_span::source_map::SourceMap; @@ -574,7 +573,7 @@ fn method_caller_is_mutable(cx: &LateContext<'_>, caller_expr: &Expr<'_>, ignore let caller_ty = cx.typeck_results().expr_ty(caller_expr); // Check if given type has inner mutability and was not set to ignored by the configuration let is_inner_mut_ty = is_interior_mut_ty(cx, caller_ty) - && !matches!(caller_ty.ty_adt_id(), Some(adt_id) if ignored_ty_ids.contains(&adt_id)); + && !matches!(caller_ty.ty_adt_def(), Some(adt) if ignored_ty_ids.contains(&adt.did())); is_inner_mut_ty || caller_ty.is_mutable_ptr() diff --git a/clippy_lints/src/methods/drain_collect.rs b/clippy_lints/src/methods/drain_collect.rs index 6a82d8f756ad..3a8ca37610a9 100644 --- a/clippy_lints/src/methods/drain_collect.rs +++ b/clippy_lints/src/methods/drain_collect.rs @@ -6,7 +6,6 @@ use clippy_utils::ty::is_type_lang_item; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, LangItem, Path, QPath}; use rustc_lint::LateContext; -use rustc_middle::query::Key; use rustc_middle::ty; use rustc_middle::ty::Ty; use rustc_span::{sym, Symbol}; @@ -18,10 +17,10 @@ use rustc_span::{sym, Symbol}; /// `vec![1,2].drain(..).collect::>()` /// ^^^^^^^^^ ^^^^^^^^^^ false fn types_match_diagnostic_item(cx: &LateContext<'_>, expr: Ty<'_>, recv: Ty<'_>, sym: Symbol) -> bool { - if let Some(expr_adt_did) = expr.ty_adt_id() - && let Some(recv_adt_did) = recv.ty_adt_id() + if let Some(expr_adt) = expr.ty_adt_def() + && let Some(recv_adt) = recv.ty_adt_def() { - cx.tcx.is_diagnostic_item(sym, expr_adt_did) && cx.tcx.is_diagnostic_item(sym, recv_adt_did) + cx.tcx.is_diagnostic_item(sym, expr_adt.did()) && cx.tcx.is_diagnostic_item(sym, recv_adt.did()) } else { false } diff --git a/clippy_lints/src/methods/redundant_as_str.rs b/clippy_lints/src/methods/redundant_as_str.rs index 98cd6afc2b79..2a2feedd2b49 100644 --- a/clippy_lints/src/methods/redundant_as_str.rs +++ b/clippy_lints/src/methods/redundant_as_str.rs @@ -4,7 +4,6 @@ use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; -use rustc_middle::query::Key; use rustc_span::Span; pub(super) fn check( @@ -14,11 +13,7 @@ pub(super) fn check( as_str_span: Span, other_method_span: Span, ) { - if cx - .tcx - .lang_items() - .string() - .is_some_and(|id| Some(id) == cx.typeck_results().expr_ty(recv).ty_adt_id()) + if cx.typeck_results().expr_ty(recv).ty_adt_def().is_some_and(|adt| Some(adt.did()) == cx.tcx.lang_items().string()) { let mut applicability = Applicability::MachineApplicable; span_lint_and_sugg( diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 04d2ced6abf8..c32025fcbb6a 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -4,7 +4,6 @@ use clippy_utils::{def_path_def_ids, trait_ref_of_method}; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::query::Key; use rustc_middle::ty::{Adt, Ty}; use rustc_session::impl_lint_pass; use rustc_span::def_id::LocalDefId; @@ -166,7 +165,7 @@ impl MutableKeyType { // Determines if a type contains interior mutability which would affect its implementation of // [`Hash`] or [`Ord`]. if is_interior_mut_ty(cx, subst_ty) - && !matches!(subst_ty.ty_adt_id(), Some(adt_id) if self.ignore_mut_def_ids.contains(&adt_id)) + && !matches!(subst_ty.ty_adt_def(), Some(adt) if self.ignore_mut_def_ids.contains(&adt.did())) { span_lint(cx, MUTABLE_KEY_TYPE, span, "mutable key type"); } diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 4013cb34561a..f8365deebd46 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -15,7 +15,6 @@ use rustc_hir::{ }; use rustc_lint::{LateContext, LateLintPass, Lint}; use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult, GlobalId}; -use rustc_middle::query::Key; use rustc_middle::ty::adjustment::Adjust; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_session::impl_lint_pass; @@ -188,7 +187,7 @@ impl NonCopyConst { } fn is_ty_ignored(&self, ty: Ty<'_>) -> bool { - matches!(ty.ty_adt_id(), Some(adt_id) if self.ignore_mut_def_ids.contains(&adt_id)) + matches!(ty.ty_adt_def(), Some(adt) if self.ignore_mut_def_ids.contains(&adt.did())) } fn is_unfrozen<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { diff --git a/clippy_lints/src/transmute/transmute_int_to_non_zero.rs b/clippy_lints/src/transmute/transmute_int_to_non_zero.rs index c0d0d2b93dc0..5df645491ff8 100644 --- a/clippy_lints/src/transmute/transmute_int_to_non_zero.rs +++ b/clippy_lints/src/transmute/transmute_int_to_non_zero.rs @@ -4,7 +4,6 @@ use clippy_utils::sugg; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; -use rustc_middle::query::Key; use rustc_middle::ty::{self, Ty}; use rustc_span::symbol::sym; @@ -17,10 +16,10 @@ pub(super) fn check<'tcx>( to_ty: Ty<'tcx>, arg: &'tcx Expr<'_>, ) -> bool { - let (ty::Int(_) | ty::Uint(_), Some(to_ty_id)) = (&from_ty.kind(), to_ty.ty_adt_id()) else { + let (ty::Int(_) | ty::Uint(_), Some(to_ty_adt)) = (&from_ty.kind(), to_ty.ty_adt_def()) else { return false; }; - let Some(to_type_sym) = cx.tcx.get_diagnostic_name(to_ty_id) else { + let Some(to_type_sym) = cx.tcx.get_diagnostic_name(to_ty_adt.did()) else { return false; }; From 4f489073ce2acfccc142f5141cdc96ee269b4d26 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 9 Jan 2024 09:08:49 +1100 Subject: [PATCH 1035/1222] Rename consuming chaining methods on `DiagnosticBuilder`. In #119606 I added them and used a `_mv` suffix, but that wasn't great. A `with_` prefix has three different existing uses. - Constructors, e.g. `Vec::with_capacity`. - Wrappers that provide an environment to execute some code, e.g. `with_session_globals`. - Consuming chaining methods, e.g. `Span::with_{lo,hi,ctxt}`. The third case is exactly what we want, so this commit changes `DiagnosticBuilder::foo_mv` to `DiagnosticBuilder::with_foo`. Thanks to @compiler-errors for the suggestion. --- clippy_config/src/msrvs.rs | 2 +- clippy_utils/src/attrs.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_config/src/msrvs.rs b/clippy_config/src/msrvs.rs index 76f3663f04f2..dae9f09ec00a 100644 --- a/clippy_config/src/msrvs.rs +++ b/clippy_config/src/msrvs.rs @@ -109,7 +109,7 @@ impl Msrv { if let Some(duplicate) = msrv_attrs.last() { sess.dcx() .struct_span_err(duplicate.span, "`clippy::msrv` is defined multiple times") - .span_note_mv(msrv_attr.span, "first definition found here") + .with_span_note(msrv_attr.span, "first definition found here") .emit(); } diff --git a/clippy_utils/src/attrs.rs b/clippy_utils/src/attrs.rs index 19d38903ade2..ad8619f0d3d9 100644 --- a/clippy_utils/src/attrs.rs +++ b/clippy_utils/src/attrs.rs @@ -136,7 +136,7 @@ pub fn get_unique_attr<'a>( if let Some(duplicate) = unique_attr { sess.dcx() .struct_span_err(attr.span, format!("`{name}` is defined multiple times")) - .span_note_mv(duplicate.span, "first definition found here") + .with_span_note(duplicate.span, "first definition found here") .emit(); } else { unique_attr = Some(attr); From e922607d1874b41a29ea96abb82944bd9a6da1f1 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 11 Jan 2024 14:22:44 +1100 Subject: [PATCH 1036/1222] Stop using `DiagnosticBuilder::buffer` in the parser. One consequence is that errors returned by `maybe_new_parser_from_source_str` now must be consumed, so a bunch of places that previously ignored those errors now cancel them. (Most of them explicitly dropped the errors before. I guess that was to indicate "we are explicitly ignoring these", though I'm not 100% sure.) --- clippy_lints/src/doc/needless_doctest_main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/doc/needless_doctest_main.rs b/clippy_lints/src/doc/needless_doctest_main.rs index a744b69ecb47..8b018220c171 100644 --- a/clippy_lints/src/doc/needless_doctest_main.rs +++ b/clippy_lints/src/doc/needless_doctest_main.rs @@ -53,7 +53,7 @@ pub fn check( let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) { Ok(p) => p, Err(errs) => { - drop(errs); + errs.into_iter().for_each(|err| err.cancel()); return (false, test_attr_spans); }, }; From 606dc829457c760fbebf58b7f4fa3f442947962d Mon Sep 17 00:00:00 2001 From: yukang Date: Thu, 11 Jan 2024 00:24:46 +0800 Subject: [PATCH 1037/1222] check rust lints when an unknown lint is detected --- tests/ui/unknown_clippy_lints.fixed | 6 ++++-- tests/ui/unknown_clippy_lints.rs | 4 +++- tests/ui/unknown_clippy_lints.stderr | 20 ++++++++++++++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/ui/unknown_clippy_lints.fixed b/tests/ui/unknown_clippy_lints.fixed index cba32ce6b772..c0ccd41c19ab 100644 --- a/tests/ui/unknown_clippy_lints.fixed +++ b/tests/ui/unknown_clippy_lints.fixed @@ -7,10 +7,12 @@ #[warn(clippy::if_not_else)] #[warn(clippy::unnecessary_cast)] #[warn(clippy::useless_transmute)] -// Shouldn't suggest rustc lint name(`dead_code`) -#[warn(clippy::eq_op)] +// Should suggest rustc lint name(`dead_code`) +#[warn(dead_code)] // Shouldn't suggest removed/deprecated clippy lint name(`unused_collect`) #[warn(clippy::unused_self)] // Shouldn't suggest renamed clippy lint name(`const_static_lifetime`) #[warn(clippy::redundant_static_lifetimes)] +// issue #118183, should report `missing_docs` from rustc lint +#[warn(missing_docs)] fn main() {} diff --git a/tests/ui/unknown_clippy_lints.rs b/tests/ui/unknown_clippy_lints.rs index c15d541974f0..7a59ad364aa7 100644 --- a/tests/ui/unknown_clippy_lints.rs +++ b/tests/ui/unknown_clippy_lints.rs @@ -7,10 +7,12 @@ #[warn(clippy::if_not_els)] #[warn(clippy::UNNecsaRy_cAst)] #[warn(clippy::useles_transute)] -// Shouldn't suggest rustc lint name(`dead_code`) +// Should suggest rustc lint name(`dead_code`) #[warn(clippy::dead_cod)] // Shouldn't suggest removed/deprecated clippy lint name(`unused_collect`) #[warn(clippy::unused_colle)] // Shouldn't suggest renamed clippy lint name(`const_static_lifetime`) #[warn(clippy::const_static_lifetim)] +// issue #118183, should report `missing_docs` from rustc lint +#[warn(clippy::missing_docs)] fn main() {} diff --git a/tests/ui/unknown_clippy_lints.stderr b/tests/ui/unknown_clippy_lints.stderr index ee82db31c2c2..432c7f72e32e 100644 --- a/tests/ui/unknown_clippy_lints.stderr +++ b/tests/ui/unknown_clippy_lints.stderr @@ -35,7 +35,12 @@ error: unknown lint: `clippy::dead_cod` --> $DIR/unknown_clippy_lints.rs:11:8 | LL | #[warn(clippy::dead_cod)] - | ^^^^^^^^^^^^^^^^ help: did you mean: `clippy::eq_op` + | ^^^^^^^^^^^^^^^^ + | +help: a lint with a similar name exists in `rustc` lints + | +LL | #[warn(dead_code)] + | ~~~~~~~~~ error: unknown lint: `clippy::unused_colle` --> $DIR/unknown_clippy_lints.rs:13:8 @@ -49,5 +54,16 @@ error: unknown lint: `clippy::const_static_lifetim` LL | #[warn(clippy::const_static_lifetim)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::redundant_static_lifetimes` -error: aborting due to 8 previous errors +error: unknown lint: `clippy::missing_docs` + --> $DIR/unknown_clippy_lints.rs:17:8 + | +LL | #[warn(clippy::missing_docs)] + | ^^^^^^^^^^^^^^^^^^^^ + | +help: a lint with a similar name exists in `rustc` lints + | +LL | #[warn(missing_docs)] + | ~~~~~~~~~~~~ + +error: aborting due to 9 previous errors From 408b2ec0ab1f46768e05e84ecc58cad7766af277 Mon Sep 17 00:00:00 2001 From: Bryanskiy Date: Sun, 26 Nov 2023 15:57:31 +0300 Subject: [PATCH 1038/1222] Delegation implementation: step 1 --- clippy_lints/src/dereference.rs | 1 + clippy_utils/src/hir_utils.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index aaef163ad554..8ff54dfcfa0d 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -830,6 +830,7 @@ impl TyCoercionStability { | TyKind::Infer | TyKind::Typeof(..) | TyKind::TraitObject(..) + | TyKind::InferDelegation(..) | TyKind::Err(_) => Self::Reborrow, }; } diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 07b72e3f570b..482eaed77d1d 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -1108,7 +1108,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { TyKind::Typeof(anon_const) => { self.hash_body(anon_const.body); }, - TyKind::Err(_) | TyKind::Infer | TyKind::Never => {}, + TyKind::Err(_) | TyKind::Infer | TyKind::Never | TyKind::InferDelegation(..) => {}, } } From 099cab6cf02d4ff2d692a038579ed165d89c221e Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 7 Jan 2024 20:37:51 +0100 Subject: [PATCH 1039/1222] Improve `let_underscore_lock` - lint if the lock was in a nested pattern - lint if the lock is inside a `Result` --- tests/ui/let_underscore_lock.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ui/let_underscore_lock.rs b/tests/ui/let_underscore_lock.rs index ccac73be79e4..28d8dd498319 100644 --- a/tests/ui/let_underscore_lock.rs +++ b/tests/ui/let_underscore_lock.rs @@ -26,6 +26,7 @@ fn main() { let _ = p_rw; } +#[allow(let_underscore_lock)] fn uplifted() { // shouldn't lint std locks as they were uplifted as rustc's `let_underscore_lock` From cca88fe749f860c489c62ed0708872a9bf2e4c62 Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Mon, 15 Jan 2024 12:26:45 -0500 Subject: [PATCH 1040/1222] Ensure `callee_id`s are body owners --- clippy_lints/src/derive.rs | 4 +-- clippy_lints/src/loops/explicit_iter_loop.rs | 2 +- clippy_utils/src/ty.rs | 30 +++++++------------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index d8abe411030b..a8217d0602a5 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -450,12 +450,12 @@ fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_r && let Some(def_id) = trait_ref.trait_def_id() && cx.tcx.is_diagnostic_item(sym::PartialEq, def_id) && let param_env = param_env_for_derived_eq(cx.tcx, adt.did(), eq_trait_def_id) - && !implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, adt.did(),&[]) + && !implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, None, &[]) // If all of our fields implement `Eq`, we can implement `Eq` too && adt .all_fields() .map(|f| f.ty(cx.tcx, args)) - .all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, adt.did(), &[])) + .all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, None, &[])) { span_lint_and_sugg( cx, diff --git a/clippy_lints/src/loops/explicit_iter_loop.rs b/clippy_lints/src/loops/explicit_iter_loop.rs index c7980060807c..814ccaa36f5a 100644 --- a/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_iter_loop.rs @@ -118,7 +118,7 @@ fn is_ref_iterable<'tcx>( .liberate_late_bound_regions(fn_id, cx.tcx.fn_sig(fn_id).skip_binder()) && let &[req_self_ty, req_res_ty] = &**sig.inputs_and_output && let param_env = cx.tcx.param_env(fn_id) - && implements_trait_with_env(cx.tcx, param_env, req_self_ty, trait_id, fn_id, &[]) + && implements_trait_with_env(cx.tcx, param_env, req_self_ty, trait_id, Some(fn_id), &[]) && let Some(into_iter_ty) = make_normalized_projection_with_regions(cx.tcx, param_env, trait_id, sym!(IntoIter), [req_self_ty]) && let req_res_ty = normalize_with_regions(cx.tcx, param_env, req_res_ty) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 61d0663aa839..a07d6587bf97 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -214,36 +214,21 @@ pub fn implements_trait<'tcx>( trait_id: DefId, args: &[GenericArg<'tcx>], ) -> bool { - let callee_id = cx - .enclosing_body - .map(|body| cx.tcx.hir().body_owner(body).owner.to_def_id()); - implements_trait_with_env_from_iter( - cx.tcx, - cx.param_env, - ty, - trait_id, - callee_id, - args.iter().map(|&x| Some(x)), - ) + implements_trait_with_env_from_iter(cx.tcx, cx.param_env, ty, trait_id, None, args.iter().map(|&x| Some(x))) } /// Same as `implements_trait` but allows using a `ParamEnv` different from the lint context. +/// +/// The `callee_id` argument is used to determine the "effect arg", if one is needed. pub fn implements_trait_with_env<'tcx>( tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, trait_id: DefId, - callee_id: DefId, + callee_id: Option, args: &[GenericArg<'tcx>], ) -> bool { - implements_trait_with_env_from_iter( - tcx, - param_env, - ty, - trait_id, - Some(callee_id), - args.iter().map(|&x| Some(x)), - ) + implements_trait_with_env_from_iter(tcx, param_env, ty, trait_id, callee_id, args.iter().map(|&x| Some(x))) } /// Same as `implements_trait_from_env` but takes the arguments as an iterator. @@ -258,6 +243,11 @@ pub fn implements_trait_with_env_from_iter<'tcx>( // Clippy shouldn't have infer types assert!(!ty.has_infer()); + // If a `callee_id` is passed, then "assert" it is a body owner. + if let Some(callee_id) = callee_id { + let _ = tcx.hir().body_owner_kind(callee_id); + } + let ty = tcx.erase_regions(ty); if ty.has_escaping_bound_vars() { return false; From a18c948be58c0db229bacbd079606f5fa9aa62a7 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Fri, 12 Jan 2024 08:21:42 +0100 Subject: [PATCH 1041/1222] compiler: Lower fn call arg spans down to MIR To enable improved accuracy of diagnostics in upcoming commits. --- clippy_lints/src/redundant_clone.rs | 4 ++-- clippy_utils/src/mir/possible_borrower.rs | 2 +- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index c62c351e7167..3416a93e3c4a 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -257,9 +257,9 @@ fn is_call_with_ref_arg<'tcx>( .. } = kind && args.len() == 1 - && let mir::Operand::Move(mir::Place { local, .. }) = &args[0] + && let mir::Operand::Move(mir::Place { local, .. }) = &args[0].node && let ty::FnDef(def_id, _) = *func.ty(mir, cx.tcx).kind() - && let (inner_ty, 1) = walk_ptrs_ty_depth(args[0].ty(mir, cx.tcx)) + && let (inner_ty, 1) = walk_ptrs_ty_depth(args[0].node.ty(mir, cx.tcx)) && !is_copy(cx, inner_ty) { Some((def_id, *local, inner_ty, destination.as_local()?)) diff --git a/clippy_utils/src/mir/possible_borrower.rs b/clippy_utils/src/mir/possible_borrower.rs index 703985b9d4b3..f9cc5f191253 100644 --- a/clippy_utils/src/mir/possible_borrower.rs +++ b/clippy_utils/src/mir/possible_borrower.rs @@ -104,7 +104,7 @@ impl<'a, 'b, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'b, let mut mutable_borrowers = vec![]; for op in args { - match op { + match &op.node { mir::Operand::Copy(p) | mir::Operand::Move(p) => { if let ty::Ref(_, _, Mutability::Mut) = self.body.local_decls[p.local].ty.kind() { mutable_borrowers.push(p.local); diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 668ea9fcf3b4..81f4fcc2133d 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -345,7 +345,7 @@ fn check_terminator<'tcx>( check_operand(tcx, func, span, body)?; for arg in args { - check_operand(tcx, arg, span, body)?; + check_operand(tcx, &arg.node, span, body)?; } Ok(()) } else { From 8d6ccdf865e17845ab49680db0e43163c6183388 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 15 Jan 2024 19:38:53 +0000 Subject: [PATCH 1042/1222] Deal with additional wrapping of async closure body in clippy --- clippy_lints/src/async_yields_async.rs | 98 +++++++++++++--------- clippy_lints/src/redundant_closure_call.rs | 20 ++++- tests/ui/author/blocks.stdout | 6 +- 3 files changed, 82 insertions(+), 42 deletions(-) diff --git a/clippy_lints/src/async_yields_async.rs b/clippy_lints/src/async_yields_async.rs index bb08ac7508bc..eeaa3de3725f 100644 --- a/clippy_lints/src/async_yields_async.rs +++ b/clippy_lints/src/async_yields_async.rs @@ -45,50 +45,72 @@ declare_lint_pass!(AsyncYieldsAsync => [ASYNC_YIELDS_ASYNC]); impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - // For functions, with explicitly defined types, don't warn. - // XXXkhuey maybe we should? - if let ExprKind::Closure(Closure { - kind: - ClosureKind::Coroutine(CoroutineKind::Desugared( - CoroutineDesugaring::Async, - CoroutineSource::Block | CoroutineSource::Closure, - )), + let ExprKind::Closure(Closure { + kind: ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, kind)), body: body_id, .. }) = expr.kind - { - if let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait() { - let typeck_results = cx.tcx.typeck_body(*body_id); - let body = cx.tcx.hir().body(*body_id); - let expr_ty = typeck_results.expr_ty(body.value); + else { + return; + }; - if implements_trait(cx, expr_ty, future_trait_def_id, &[]) { - let return_expr_span = match &body.value.kind { - // XXXkhuey there has to be a better way. - ExprKind::Block(block, _) => block.expr.map(|e| e.span), - ExprKind::Path(QPath::Resolved(_, path)) => Some(path.span), - _ => None, - }; - if let Some(return_expr_span) = return_expr_span { - span_lint_hir_and_then( - cx, - ASYNC_YIELDS_ASYNC, - body.value.hir_id, + let body_expr = match kind { + CoroutineSource::Fn => { + // For functions, with explicitly defined types, don't warn. + // XXXkhuey maybe we should? + return; + }, + CoroutineSource::Block => cx.tcx.hir().body(*body_id).value, + CoroutineSource::Closure => { + // Like `async fn`, async closures are wrapped in an additional block + // to move all of the closure's arguments into the future. + + let async_closure_body = cx.tcx.hir().body(*body_id).value; + let ExprKind::Block(block, _) = async_closure_body.kind else { + return; + }; + let Some(block_expr) = block.expr else { + return; + }; + let ExprKind::DropTemps(body_expr) = block_expr.kind else { + return; + }; + body_expr + }, + }; + + let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait() else { + return; + }; + + let typeck_results = cx.tcx.typeck_body(*body_id); + let expr_ty = typeck_results.expr_ty(body_expr); + + if implements_trait(cx, expr_ty, future_trait_def_id, &[]) { + let return_expr_span = match &body_expr.kind { + // XXXkhuey there has to be a better way. + ExprKind::Block(block, _) => block.expr.map(|e| e.span), + ExprKind::Path(QPath::Resolved(_, path)) => Some(path.span), + _ => None, + }; + if let Some(return_expr_span) = return_expr_span { + span_lint_hir_and_then( + cx, + ASYNC_YIELDS_ASYNC, + body_expr.hir_id, + return_expr_span, + "an async construct yields a type which is itself awaitable", + |db| { + db.span_label(body_expr.span, "outer async construct"); + db.span_label(return_expr_span, "awaitable value not awaited"); + db.span_suggestion( return_expr_span, - "an async construct yields a type which is itself awaitable", - |db| { - db.span_label(body.value.span, "outer async construct"); - db.span_label(return_expr_span, "awaitable value not awaited"); - db.span_suggestion( - return_expr_span, - "consider awaiting this value", - format!("{}.await", snippet(cx, return_expr_span, "..")), - Applicability::MaybeIncorrect, - ); - }, + "consider awaiting this value", + format!("{}.await", snippet(cx, return_expr_span, "..")), + Applicability::MaybeIncorrect, ); - } - } + }, + ); } } } diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index cde08dfcc748..334e6770ae40 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -5,7 +5,9 @@ use clippy_utils::sugg::Sugg; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::intravisit::{Visitor as HirVisitor, Visitor}; -use rustc_hir::{intravisit as hir_visit, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Node}; +use rustc_hir::{ + intravisit as hir_visit, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, ExprKind, Node, +}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; @@ -166,10 +168,22 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { if coroutine_kind.is_async() && let hir::ExprKind::Closure(closure) = body.kind { - let async_closure_body = cx.tcx.hir().body(closure.body); + // Like `async fn`, async closures are wrapped in an additional block + // to move all of the closure's arguments into the future. + + let async_closure_body = cx.tcx.hir().body(closure.body).value; + let ExprKind::Block(block, _) = async_closure_body.kind else { + return; + }; + let Some(block_expr) = block.expr else { + return; + }; + let ExprKind::DropTemps(body_expr) = block_expr.kind else { + return; + }; // `async x` is a syntax error, so it becomes `async { x }` - if !matches!(async_closure_body.value.kind, hir::ExprKind::Block(_, _)) { + if !matches!(body_expr.kind, hir::ExprKind::Block(_, _)) { hint = hint.blockify(); } diff --git a/tests/ui/author/blocks.stdout b/tests/ui/author/blocks.stdout index 62de661f8ff8..8c4d71e68f80 100644 --- a/tests/ui/author/blocks.stdout +++ b/tests/ui/author/blocks.stdout @@ -48,7 +48,11 @@ if let ExprKind::Closure { capture_clause: CaptureBy::Value { .. }, fn_decl: fn_ && expr2 = &cx.tcx.hir().body(body_id1).value && let ExprKind::Block(block, None) = expr2.kind && block.stmts.is_empty() - && block.expr.is_none() + && let Some(trailing_expr) = block.expr + && let ExprKind::DropTemps(expr3) = trailing_expr.kind + && let ExprKind::Block(block1, None) = expr3.kind + && block1.stmts.is_empty() + && block1.expr.is_none() { // report your lint here } From 74a18c6391f1992afdc9677d31efa16120126a4b Mon Sep 17 00:00:00 2001 From: Lieselotte <52315535+she3py@users.noreply.github.com> Date: Wed, 17 Jan 2024 03:14:16 +0100 Subject: [PATCH 1043/1222] Add `PatKind::Err` --- clippy_lints/src/equatable_if_let.rs | 3 ++- clippy_lints/src/matches/match_same_arms.rs | 5 ++++- clippy_lints/src/unnested_or_patterns.rs | 2 +- clippy_lints/src/utils/author.rs | 1 + clippy_utils/src/hir_utils.rs | 2 +- clippy_utils/src/lib.rs | 1 + 6 files changed, 10 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/equatable_if_let.rs b/clippy_lints/src/equatable_if_let.rs index 3c4352942526..4e728d61b853 100644 --- a/clippy_lints/src/equatable_if_let.rs +++ b/clippy_lints/src/equatable_if_let.rs @@ -51,7 +51,8 @@ fn unary_pattern(pat: &Pat<'_>) -> bool { | PatKind::Binding(..) | PatKind::Wild | PatKind::Never - | PatKind::Or(_) => false, + | PatKind::Or(_) + | PatKind::Err(_) => false, PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)), PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => etc.as_opt_usize().is_none() && array_rec(a), PatKind::Ref(x, _) | PatKind::Box(x) => unary_pattern(x), diff --git a/clippy_lints/src/matches/match_same_arms.rs b/clippy_lints/src/matches/match_same_arms.rs index c823d07e2bd3..5ca161e93096 100644 --- a/clippy_lints/src/matches/match_same_arms.rs +++ b/clippy_lints/src/matches/match_same_arms.rs @@ -11,7 +11,7 @@ use rustc_hir::{Arm, Expr, ExprKind, HirId, HirIdMap, HirIdMapEntry, HirIdSet, P use rustc_lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS; use rustc_lint::LateContext; use rustc_middle::ty; -use rustc_span::Symbol; +use rustc_span::{ErrorGuaranteed, Symbol}; use super::MATCH_SAME_ARMS; @@ -167,6 +167,8 @@ enum NormalizedPat<'a> { /// contains everything afterwards. Note that either side, or both sides, may contain zero /// patterns. Slice(&'a [Self], Option<&'a [Self]>), + /// A placeholder for a pattern that wasn't well formed in some way. + Err(ErrorGuaranteed), } #[derive(Clone, Copy)] @@ -329,6 +331,7 @@ impl<'a> NormalizedPat<'a> { arena.alloc_from_iter(front.iter().map(|pat| Self::from_pat(cx, arena, pat))), wild_pat.map(|_| &*arena.alloc_from_iter(back.iter().map(|pat| Self::from_pat(cx, arena, pat)))), ), + PatKind::Err(guar) => Self::Err(guar), } } diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 77adcdd0e6bf..7246214f9bf8 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -226,7 +226,7 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec>, focus_idx: us // Therefore they are not some form of constructor `C`, // with which a pattern `C(p_0)` may be formed, // which we would want to join with other `C(p_j)`s. - Ident(.., None) | Lit(_) | Wild | Never | Path(..) | Range(..) | Rest | MacCall(_) + Ident(.., None) | Lit(_) | Wild | Err(_) | Never | Path(..) | Range(..) | Rest | MacCall(_) // Skip immutable refs, as grouping them saves few characters, // and almost always requires adding parens (increasing noisiness). // In the case of only two patterns, replacement adds net characters. diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 8d38b87e1d79..b26ebe5cee32 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -710,6 +710,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { self.slice(start, |pat| self.pat(pat)); self.slice(end, |pat| self.pat(pat)); }, + PatKind::Err(_) => kind!("Err"), } } diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 482eaed77d1d..979b117db256 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -1007,7 +1007,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } e.hash(&mut self.s); }, - PatKind::Never | PatKind::Wild => {}, + PatKind::Never | PatKind::Wild | PatKind::Err(_) => {}, } } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index cdf8528f48a2..2e54690d123c 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1733,6 +1733,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { }, } }, + PatKind::Err(_) => true, } } From a124c18ca85b02e61b30301086b7420e405a006a Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 12 Jan 2024 16:58:29 +0000 Subject: [PATCH 1044/1222] Fix clippy --- clippy_lints/src/derive.rs | 3 ++- clippy_lints/src/inherent_impl.rs | 3 ++- clippy_lints/src/iter_without_into_iter.rs | 2 +- clippy_lints/src/len_zero.rs | 5 +++-- clippy_lints/src/methods/or_fun_call.rs | 3 ++- clippy_utils/src/lib.rs | 8 +++++--- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index d8abe411030b..d1fe9f5cbece 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -386,7 +386,8 @@ fn check_unsafe_derive_deserialize<'tcx>( && cx .tcx .inherent_impls(def.did()) - .iter() + .into_iter() + .flatten() .map(|imp_did| cx.tcx.hir().expect_item(imp_did.expect_local())) .any(|imp| has_unsafe(cx, imp)) { diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index e4781752e757..fb7b82ec304e 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -53,9 +53,10 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { // List of spans to lint. (lint_span, first_span) let mut lint_spans = Vec::new(); + let Ok(impls) = cx.tcx.crate_inherent_impls(()) else { return }; let inherent_impls = cx .tcx - .with_stable_hashing_context(|hcx| cx.tcx.crate_inherent_impls(()).inherent_impls.to_sorted(&hcx, true)); + .with_stable_hashing_context(|hcx| impls.inherent_impls.to_sorted(&hcx, true)); for (_, impl_ids) in inherent_impls.into_iter().filter(|(&id, impls)| { impls.len() > 1 diff --git a/clippy_lints/src/iter_without_into_iter.rs b/clippy_lints/src/iter_without_into_iter.rs index 903d3a2ab896..82a37bb4f278 100644 --- a/clippy_lints/src/iter_without_into_iter.rs +++ b/clippy_lints/src/iter_without_into_iter.rs @@ -139,7 +139,7 @@ fn deref_chain<'cx, 'tcx>(cx: &'cx LateContext<'tcx>, ty: Ty<'tcx>) -> impl Iter fn adt_has_inherent_method(cx: &LateContext<'_>, ty: Ty<'_>, method_name: Symbol) -> bool { if let Some(ty_did) = ty.ty_adt_def().map(ty::AdtDef::did) { - cx.tcx.inherent_impls(ty_did).iter().any(|&did| { + cx.tcx.inherent_impls(ty_did).into_iter().flatten().any(|&did| { cx.tcx .associated_items(did) .filter_by_name_unhygienic(method_name) diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index c09d3d1862b0..c1ab020117ca 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -441,7 +441,8 @@ fn check_for_is_empty( let is_empty = cx .tcx .inherent_impls(impl_ty) - .iter() + .into_iter() + .flatten() .flat_map(|&id| cx.tcx.associated_items(id).filter_by_name_unhygienic(is_empty)) .find(|item| item.kind == AssocKind::Fn); @@ -605,7 +606,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { /// Checks the inherent impl's items for an `is_empty(self)` method. fn has_is_empty_impl(cx: &LateContext<'_>, id: DefId) -> bool { let is_empty = sym!(is_empty); - cx.tcx.inherent_impls(id).iter().any(|imp| { + cx.tcx.inherent_impls(id).into_iter().flatten().any(|imp| { cx.tcx .associated_items(*imp) .filter_by_name_unhygienic(is_empty) diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index e38c66f6741d..0602eeaa7041 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -73,7 +73,8 @@ pub(super) fn check<'tcx>( let has_suggested_method = receiver_ty.ty_adt_def().is_some_and(|adt_def| { cx.tcx .inherent_impls(adt_def.did()) - .iter() + .into_iter() + .flatten() .flat_map(|impl_id| cx.tcx.associated_items(impl_id).filter_by_name_unhygienic(sugg)) .any(|assoc| { assoc.fn_has_self_parameter diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index cdf8528f48a2..1a4b22799f2a 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -534,10 +534,11 @@ fn find_primitive_impls<'tcx>(tcx: TyCtxt<'tcx>, name: &str) -> impl Iterator SimplifiedType::Uint(UintTy::U128), "f32" => SimplifiedType::Float(FloatTy::F32), "f64" => SimplifiedType::Float(FloatTy::F64), - _ => return [].iter().copied(), + #[allow(trivial_casts)] + _ => return Result::<_, rustc_errors::ErrorGuaranteed>::Ok(&[] as &[_]).into_iter().flatten().copied(), }; - tcx.incoherent_impls(ty).iter().copied() + tcx.incoherent_impls(ty).into_iter().flatten().copied() } fn non_local_item_children_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) -> Vec { @@ -663,7 +664,8 @@ pub fn def_path_res(cx: &LateContext<'_>, path: &[&str]) -> Vec { // `impl S { ... }` let inherent_impl_children = tcx .inherent_impls(def_id) - .iter() + .into_iter() + .flatten() .flat_map(|&impl_def_id| item_children_by_name(tcx, impl_def_id, segment)); let direct_children = item_children_by_name(tcx, def_id, segment); From bed723dbc2ef7b7e2523a2c74a52130dabe3b595 Mon Sep 17 00:00:00 2001 From: Samuel Moelius <35515885+smoelius@users.noreply.github.com> Date: Thu, 18 Jan 2024 10:32:57 -0500 Subject: [PATCH 1045/1222] Apply suggestions from code review Co-authored-by: fee1-dead --- clippy_utils/src/ty.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index a07d6587bf97..59ebe685c11e 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -219,7 +219,7 @@ pub fn implements_trait<'tcx>( /// Same as `implements_trait` but allows using a `ParamEnv` different from the lint context. /// -/// The `callee_id` argument is used to determine the "effect arg", if one is needed. +/// The `callee_id` argument is used to determine whether this is a function call in a `const fn` environment, used for checking const traits. pub fn implements_trait_with_env<'tcx>( tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, @@ -243,7 +243,9 @@ pub fn implements_trait_with_env_from_iter<'tcx>( // Clippy shouldn't have infer types assert!(!ty.has_infer()); - // If a `callee_id` is passed, then "assert" it is a body owner. + // If a `callee_id` is passed, then we assert that it is a body owner + // through calling `body_owner_kind`, which would panic if the callee + // does not have a body. if let Some(callee_id) = callee_id { let _ = tcx.hir().body_owner_kind(callee_id); } From 0d75eb4b89aef19f88a4297a23c859d7de2a489a Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 1 Feb 2023 14:23:51 +0000 Subject: [PATCH 1046/1222] Don't forget that the lifetime on hir types is `'tcx` --- .../src/default_union_representation.rs | 2 +- clippy_lints/src/implicit_hasher.rs | 2 +- clippy_lints/src/types/mod.rs | 18 +++++++++--------- clippy_lints/src/types/redundant_allocation.rs | 2 +- clippy_lints/src/types/vec_box.rs | 6 +++--- clippy_lints/src/unconditional_recursion.rs | 4 ++-- clippy_lints/src/uninhabited_references.rs | 6 +++--- clippy_lints/src/use_self.rs | 2 +- clippy_lints/src/zero_sized_map_values.rs | 4 ++-- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/clippy_lints/src/default_union_representation.rs b/clippy_lints/src/default_union_representation.rs index db01ff2cd220..bfd89bfd2c72 100644 --- a/clippy_lints/src/default_union_representation.rs +++ b/clippy_lints/src/default_union_representation.rs @@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultUnionRepresentation { /// (ZST fields having an arbitrary offset is completely inconsequential, and /// if there is only one field left after ignoring ZST fields then the offset /// of that field does not matter either.) -fn is_union_with_two_non_zst_fields(cx: &LateContext<'_>, item: &Item<'_>) -> bool { +fn is_union_with_two_non_zst_fields<'tcx>(cx: &LateContext<'tcx>, item: &Item<'tcx>) -> bool { if let ItemKind::Union(..) = &item.kind && let ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind() { diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 788fe8287278..87f6f5e7959e 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -210,7 +210,7 @@ enum ImplicitHasherType<'tcx> { impl<'tcx> ImplicitHasherType<'tcx> { /// Checks that `ty` is a target type without a `BuildHasher`. - fn new(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'_>) -> Option { + fn new(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Option { if let TyKind::Path(QPath::Resolved(None, path)) = hir_ty.kind { let params: Vec<_> = path .segments diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 81efec65343d..7882bfdd09fa 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -314,9 +314,9 @@ impl_lint_pass!(Types => [BOX_COLLECTION, VEC_BOX, OPTION_OPTION, LINKEDLIST, BO impl<'tcx> LateLintPass<'tcx> for Types { fn check_fn( &mut self, - cx: &LateContext<'_>, + cx: &LateContext<'tcx>, fn_kind: FnKind<'_>, - decl: &FnDecl<'_>, + decl: &FnDecl<'tcx>, _: &Body<'_>, _: Span, def_id: LocalDefId, @@ -346,7 +346,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { ); } - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { + fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { let is_exported = cx.effective_visibilities.is_exported(item.owner_id.def_id); match item.kind { @@ -363,7 +363,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { } } - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'tcx>) { match item.kind { ImplItemKind::Const(ty, _) => { let is_in_trait_impl = if let Some(hir::Node::Item(item)) = cx @@ -391,7 +391,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { } } - fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) { + fn check_field_def(&mut self, cx: &LateContext<'tcx>, field: &hir::FieldDef<'tcx>) { let is_exported = cx.effective_visibilities.is_exported(field.def_id); self.check_ty( @@ -404,7 +404,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { ); } - fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &TraitItem<'_>) { + fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &TraitItem<'tcx>) { let is_exported = cx.effective_visibilities.is_exported(item.owner_id.def_id); let context = CheckTyContext { @@ -421,7 +421,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { } } - fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &Local<'tcx>) { if let Some(ty) = local.ty { self.check_ty( cx, @@ -444,7 +444,7 @@ impl Types { } } - fn check_fn_decl(&mut self, cx: &LateContext<'_>, decl: &FnDecl<'_>, context: CheckTyContext) { + fn check_fn_decl<'tcx>(&mut self, cx: &LateContext<'tcx>, decl: &FnDecl<'tcx>, context: CheckTyContext) { // Ignore functions in trait implementations as they are usually forced by the trait definition. // // FIXME: ideally we would like to warn *if the complicated type can be simplified*, but it's hard @@ -466,7 +466,7 @@ impl Types { /// lint found. /// /// The parameter `is_local` distinguishes the context of the type. - fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, mut context: CheckTyContext) { + fn check_ty<'tcx>(&mut self, cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>, mut context: CheckTyContext) { if hir_ty.span.from_expansion() { return; } diff --git a/clippy_lints/src/types/redundant_allocation.rs b/clippy_lints/src/types/redundant_allocation.rs index 5a986254fad5..a0d609501a0c 100644 --- a/clippy_lints/src/types/redundant_allocation.rs +++ b/clippy_lints/src/types/redundant_allocation.rs @@ -11,7 +11,7 @@ use rustc_span::symbol::sym; use super::{utils, REDUNDANT_ALLOCATION}; -pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool { +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>, qpath: &QPath<'tcx>, def_id: DefId) -> bool { let mut applicability = Applicability::MaybeIncorrect; let outer_sym = if Some(def_id) == cx.tcx.lang_items().owned_box() { "Box" diff --git a/clippy_lints/src/types/vec_box.rs b/clippy_lints/src/types/vec_box.rs index 9d5066199bde..a285f771f1b1 100644 --- a/clippy_lints/src/types/vec_box.rs +++ b/clippy_lints/src/types/vec_box.rs @@ -13,10 +13,10 @@ use rustc_span::symbol::sym; use super::VEC_BOX; -pub(super) fn check( - cx: &LateContext<'_>, +pub(super) fn check<'tcx>( + cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'_>, - qpath: &QPath<'_>, + qpath: &QPath<'tcx>, def_id: DefId, box_size_threshold: u64, ) -> bool { diff --git a/clippy_lints/src/unconditional_recursion.rs b/clippy_lints/src/unconditional_recursion.rs index e90306ded61c..b418db53ea47 100644 --- a/clippy_lints/src/unconditional_recursion.rs +++ b/clippy_lints/src/unconditional_recursion.rs @@ -77,7 +77,7 @@ fn get_ty_def_id(ty: Ty<'_>) -> Option { } } -fn get_hir_ty_def_id(tcx: TyCtxt<'_>, hir_ty: rustc_hir::Ty<'_>) -> Option { +fn get_hir_ty_def_id<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: rustc_hir::Ty<'tcx>) -> Option { let TyKind::Path(qpath) = hir_ty.kind else { return None }; match qpath { QPath::Resolved(_, path) => path.res.opt_def_id(), @@ -229,7 +229,7 @@ fn check_to_string(cx: &LateContext<'_>, method_span: Span, method_def_id: Local } } -fn is_default_method_on_current_ty(tcx: TyCtxt<'_>, qpath: QPath<'_>, implemented_ty_id: DefId) -> bool { +fn is_default_method_on_current_ty<'tcx>(tcx: TyCtxt<'tcx>, qpath: QPath<'tcx>, implemented_ty_id: DefId) -> bool { match qpath { QPath::Resolved(_, path) => match path.segments { [first, .., last] => last.ident.name == kw::Default && first.res.opt_def_id() == Some(implemented_ty_id), diff --git a/clippy_lints/src/uninhabited_references.rs b/clippy_lints/src/uninhabited_references.rs index 903593ecfd7d..6732a43a19ec 100644 --- a/clippy_lints/src/uninhabited_references.rs +++ b/clippy_lints/src/uninhabited_references.rs @@ -57,11 +57,11 @@ impl LateLintPass<'_> for UninhabitedReferences { } } - fn check_fn( + fn check_fn<'tcx>( &mut self, - cx: &LateContext<'_>, + cx: &LateContext<'tcx>, kind: FnKind<'_>, - fndecl: &'_ FnDecl<'_>, + fndecl: &'_ FnDecl<'tcx>, _: &'_ Body<'_>, span: Span, _: LocalDefId, diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index fa033838ef35..a1b08d105b9d 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -207,7 +207,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { } } - fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>) { + fn check_ty(&mut self, cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>) { if !hir_ty.span.from_expansion() && self.msrv.meets(msrvs::TYPE_ALIAS_ENUM_VARIANTS) && let Some(&StackItem::Check { diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index b36c4ef91dc6..81d4a26e9da4 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -44,7 +44,7 @@ declare_clippy_lint! { declare_lint_pass!(ZeroSizedMapValues => [ZERO_SIZED_MAP_VALUES]); impl LateLintPass<'_> for ZeroSizedMapValues { - fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>) { + fn check_ty<'tcx>(&mut self, cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>) { if !hir_ty.span.from_expansion() && !in_trait_impl(cx, hir_ty.hir_id) && let ty = ty_from_hir_ty(cx, hir_ty) @@ -82,7 +82,7 @@ fn in_trait_impl(cx: &LateContext<'_>, hir_id: HirId) -> bool { false } -fn ty_from_hir_ty<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'_>) -> Ty<'tcx> { +fn ty_from_hir_ty<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { cx.maybe_typeck_results() .and_then(|results| { if results.hir_owner == hir_ty.hir_id.owner { From b2dec0fe635cc16501edd7ebacf28f71c8427bf6 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 17 Jan 2024 15:40:30 -0800 Subject: [PATCH 1047/1222] Pack the u128 in LitKind::Int --- clippy_lints/src/casts/unnecessary_cast.rs | 2 +- clippy_lints/src/implicit_saturating_add.rs | 3 ++- clippy_lints/src/implicit_saturating_sub.rs | 3 ++- clippy_lints/src/loops/manual_memcpy.rs | 2 +- clippy_lints/src/loops/needless_range_loop.rs | 4 ++-- clippy_lints/src/manual_bits.rs | 3 ++- clippy_lints/src/manual_range_patterns.rs | 2 +- clippy_lints/src/manual_strip.rs | 2 +- clippy_lints/src/matches/match_same_arms.rs | 6 ++--- clippy_lints/src/methods/get_first.rs | 3 ++- .../src/methods/iter_out_of_bounds.rs | 2 +- clippy_lints/src/methods/seek_from_current.rs | 3 ++- .../seek_to_start_instead_of_rewind.rs | 3 ++- clippy_lints/src/methods/unnecessary_fold.rs | 5 ++-- .../src/methods/vec_resize_to_zero.rs | 3 ++- .../src/missing_asserts_for_indexing.rs | 23 ++++++++++--------- .../src/operators/arithmetic_side_effects.rs | 2 +- .../src/operators/verbose_bit_mask.rs | 5 ++-- clippy_utils/src/consts.rs | 2 +- clippy_utils/src/lib.rs | 3 ++- 20 files changed, 46 insertions(+), 35 deletions(-) diff --git a/clippy_lints/src/casts/unnecessary_cast.rs b/clippy_lints/src/casts/unnecessary_cast.rs index 3761ba81f521..bb86b6f30759 100644 --- a/clippy_lints/src/casts/unnecessary_cast.rs +++ b/clippy_lints/src/casts/unnecessary_cast.rs @@ -107,7 +107,7 @@ pub(super) fn check<'tcx>( && let Some(src) = snippet_opt(cx, cast_expr.span) && cast_to.is_floating_point() && let Some(num_lit) = NumericLiteral::from_lit_kind(&src, &lit.node) - && let from_nbits = 128 - n.leading_zeros() + && let from_nbits = 128 - n.get().leading_zeros() && let to_nbits = fp_ty_mantissa_nbits(cast_to) && from_nbits != 0 && to_nbits != 0 diff --git a/clippy_lints/src/implicit_saturating_add.rs b/clippy_lints/src/implicit_saturating_add.rs index cc74844f2942..b8d7e8f3b07c 100644 --- a/clippy_lints/src/implicit_saturating_add.rs +++ b/clippy_lints/src/implicit_saturating_add.rs @@ -3,6 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::get_parent_expr; use clippy_utils::source::snippet_with_context; use rustc_ast::ast::{LitIntType, LitKind}; +use rustc_data_structures::packed::Pu128; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; @@ -69,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingAdd { && clippy_utils::SpanlessEq::new(cx).eq_expr(l, target) && BinOpKind::Add == op1.node && let ExprKind::Lit(lit) = value.kind - && let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node + && let LitKind::Int(Pu128(1), LitIntType::Unsuffixed) = lit.node && block.expr.is_none() { let mut app = Applicability::MachineApplicable; diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index 81df1a889c78..127c73ed637b 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -1,6 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::{higher, is_integer_literal, peel_blocks_with_stmt, SpanlessEq}; use rustc_ast::ast::LitKind; +use rustc_data_structures::packed::Pu128; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; @@ -86,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { match cond_num_val.kind { ExprKind::Lit(cond_lit) => { // Check if the constant is zero - if let LitKind::Int(0, _) = cond_lit.node { + if let LitKind::Int(Pu128(0), _) = cond_lit.node { if cx.typeck_results().expr_ty(cond_left).is_signed() { } else { print_lint_and_sugg(cx, var_name, expr); diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index fda6c9749d43..58f713d81871 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -461,7 +461,7 @@ fn is_array_length_equal_to_range(cx: &LateContext<'_>, start: &Expr<'_>, end: & if let ExprKind::Lit(lit) = expr.kind && let ast::LitKind::Int(value, _) = lit.node { - Some(value) + Some(value.get()) } else { None } diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 4acf46f73c90..08b8a9e2ff07 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -209,8 +209,8 @@ fn is_end_eq_array_len<'tcx>( && let Some(arr_len) = arr_len_const.try_eval_target_usize(cx.tcx, cx.param_env) { return match limits { - ast::RangeLimits::Closed => end_int + 1 >= arr_len.into(), - ast::RangeLimits::HalfOpen => end_int >= arr_len.into(), + ast::RangeLimits::Closed => end_int.get() + 1 >= arr_len.into(), + ast::RangeLimits::HalfOpen => end_int.get() >= arr_len.into(), }; } diff --git a/clippy_lints/src/manual_bits.rs b/clippy_lints/src/manual_bits.rs index 96c652283daa..aa02e4e7a434 100644 --- a/clippy_lints/src/manual_bits.rs +++ b/clippy_lints/src/manual_bits.rs @@ -3,6 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::get_parent_expr; use clippy_utils::source::snippet_with_context; use rustc_ast::ast::LitKind; +use rustc_data_structures::packed::Pu128; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, GenericArg, QPath}; use rustc_lint::{LateContext, LateLintPass, LintContext}; @@ -62,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualBits { && let Some((real_ty, resolved_ty, other_expr)) = get_one_size_of_ty(cx, left_expr, right_expr) && matches!(resolved_ty.kind(), ty::Int(_) | ty::Uint(_)) && let ExprKind::Lit(lit) = &other_expr.kind - && let LitKind::Int(8, _) = lit.node + && let LitKind::Int(Pu128(8), _) = lit.node { let mut app = Applicability::MachineApplicable; let ty_snip = snippet_with_context(cx, real_ty.span, ctxt, "..", &mut app).0; diff --git a/clippy_lints/src/manual_range_patterns.rs b/clippy_lints/src/manual_range_patterns.rs index d585290f7773..ec60de92c4ba 100644 --- a/clippy_lints/src/manual_range_patterns.rs +++ b/clippy_lints/src/manual_range_patterns.rs @@ -45,7 +45,7 @@ fn expr_as_i128(expr: &Expr<'_>) -> Option { && let LitKind::Int(num, _) = lit.node { // Intentionally not handling numbers greater than i128::MAX (for u128 literals) for now. - num.try_into().ok() + num.get().try_into().ok() } else { None } diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index 7b04fd28b896..bcd024360024 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -161,7 +161,7 @@ fn eq_pattern_length<'tcx>(cx: &LateContext<'tcx>, pattern: &Expr<'_>, expr: &'t .. }) = expr.kind { - constant_length(cx, pattern).map_or(false, |length| length == *n) + constant_length(cx, pattern).map_or(false, |length| *n == length) } else { len_arg(cx, expr).map_or(false, |arg| eq_expr_value(cx, pattern, arg)) } diff --git a/clippy_lints/src/matches/match_same_arms.rs b/clippy_lints/src/matches/match_same_arms.rs index 5ca161e93096..d645e6c6c05c 100644 --- a/clippy_lints/src/matches/match_same_arms.rs +++ b/clippy_lints/src/matches/match_same_arms.rs @@ -293,7 +293,7 @@ impl<'a> NormalizedPat<'a> { LitKind::ByteStr(ref bytes, _) | LitKind::CStr(ref bytes, _) => Self::LitBytes(bytes), LitKind::Byte(val) => Self::LitInt(val.into()), LitKind::Char(val) => Self::LitInt(val.into()), - LitKind::Int(val, _) => Self::LitInt(val), + LitKind::Int(val, _) => Self::LitInt(val.get()), LitKind::Bool(val) => Self::LitBool(val), LitKind::Float(..) | LitKind::Err => Self::Wild, }, @@ -305,7 +305,7 @@ impl<'a> NormalizedPat<'a> { None => 0, Some(e) => match &e.kind { ExprKind::Lit(lit) => match lit.node { - LitKind::Int(val, _) => val, + LitKind::Int(val, _) => val.get(), LitKind::Char(val) => val.into(), LitKind::Byte(val) => val.into(), _ => return Self::Wild, @@ -317,7 +317,7 @@ impl<'a> NormalizedPat<'a> { None => (u128::MAX, RangeEnd::Included), Some(e) => match &e.kind { ExprKind::Lit(lit) => match lit.node { - LitKind::Int(val, _) => (val, bounds), + LitKind::Int(val, _) => (val.get(), bounds), LitKind::Char(val) => (val.into(), bounds), LitKind::Byte(val) => (val.into(), bounds), _ => return Self::Wild, diff --git a/clippy_lints/src/methods/get_first.rs b/clippy_lints/src/methods/get_first.rs index e1f1e4893558..55fcf3728940 100644 --- a/clippy_lints/src/methods/get_first.rs +++ b/clippy_lints/src/methods/get_first.rs @@ -2,6 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; use rustc_ast::LitKind; +use rustc_data_structures::packed::Pu128; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; @@ -20,7 +21,7 @@ pub(super) fn check<'tcx>( && let Some(impl_id) = cx.tcx.impl_of_method(method_id) && let identity = cx.tcx.type_of(impl_id).instantiate_identity() && let hir::ExprKind::Lit(Spanned { - node: LitKind::Int(0, _), + node: LitKind::Int(Pu128(0), _), .. }) = arg.kind { diff --git a/clippy_lints/src/methods/iter_out_of_bounds.rs b/clippy_lints/src/methods/iter_out_of_bounds.rs index 29e69b111de6..f198849c5c0c 100644 --- a/clippy_lints/src/methods/iter_out_of_bounds.rs +++ b/clippy_lints/src/methods/iter_out_of_bounds.rs @@ -13,7 +13,7 @@ fn expr_as_u128(cx: &LateContext<'_>, e: &Expr<'_>) -> Option { if let ExprKind::Lit(lit) = expr_or_init(cx, e).kind && let LitKind::Int(n, _) = lit.node { - Some(n) + Some(n.get()) } else { None } diff --git a/clippy_lints/src/methods/seek_from_current.rs b/clippy_lints/src/methods/seek_from_current.rs index 63d41677feed..e45c7962f13f 100644 --- a/clippy_lints/src/methods/seek_from_current.rs +++ b/clippy_lints/src/methods/seek_from_current.rs @@ -1,4 +1,5 @@ use rustc_ast::ast::{LitIntType, LitKind}; +use rustc_data_structures::packed::Pu128; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; @@ -41,7 +42,7 @@ fn arg_is_seek_from_current<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) // check if argument of `SeekFrom::Current` is `0` if args.len() == 1 && let ExprKind::Lit(lit) = args[0].kind - && let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node + && let LitKind::Int(Pu128(0), LitIntType::Unsuffixed) = lit.node { return true; } diff --git a/clippy_lints/src/methods/seek_to_start_instead_of_rewind.rs b/clippy_lints/src/methods/seek_to_start_instead_of_rewind.rs index 9f38460357ba..cc4cb47e35c6 100644 --- a/clippy_lints/src/methods/seek_to_start_instead_of_rewind.rs +++ b/clippy_lints/src/methods/seek_to_start_instead_of_rewind.rs @@ -2,6 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::implements_trait; use clippy_utils::{is_expr_used_or_unified, match_def_path, paths}; use rustc_ast::ast::{LitIntType, LitKind}; +use rustc_data_structures::packed::Pu128; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; @@ -31,7 +32,7 @@ pub(super) fn check<'tcx>( && match_def_path(cx, def_id, &paths::STD_IO_SEEKFROM_START) && args1.len() == 1 && let ExprKind::Lit(lit) = args1[0].kind - && let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node + && let LitKind::Int(Pu128(0), LitIntType::Unsuffixed) = lit.node { let method_call_span = expr.span.with_lo(name_span.lo()); span_lint_and_then( diff --git a/clippy_lints/src/methods/unnecessary_fold.rs b/clippy_lints/src/methods/unnecessary_fold.rs index ebbdde48b450..f3577ef6082b 100644 --- a/clippy_lints/src/methods/unnecessary_fold.rs +++ b/clippy_lints/src/methods/unnecessary_fold.rs @@ -2,6 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::{is_trait_method, path_to_local_id, peel_blocks, strip_pat_refs}; use rustc_ast::ast; +use rustc_data_structures::packed::Pu128; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::PatKind; @@ -150,7 +151,7 @@ pub(super) fn check( }, ); }, - ast::LitKind::Int(0, _) => check_fold_with_op( + ast::LitKind::Int(Pu128(0), _) => check_fold_with_op( cx, expr, acc, @@ -162,7 +163,7 @@ pub(super) fn check( method_name: "sum", }, ), - ast::LitKind::Int(1, _) => { + ast::LitKind::Int(Pu128(1), _) => { check_fold_with_op( cx, expr, diff --git a/clippy_lints/src/methods/vec_resize_to_zero.rs b/clippy_lints/src/methods/vec_resize_to_zero.rs index 9e87fb45aa65..3e271a606115 100644 --- a/clippy_lints/src/methods/vec_resize_to_zero.rs +++ b/clippy_lints/src/methods/vec_resize_to_zero.rs @@ -1,6 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_type_diagnostic_item; use rustc_ast::LitKind; +use rustc_data_structures::packed::Pu128; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; @@ -20,7 +21,7 @@ pub(super) fn check<'tcx>( && let Some(impl_id) = cx.tcx.impl_of_method(method_id) && is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::Vec) && let ExprKind::Lit(Spanned { - node: LitKind::Int(0, _), + node: LitKind::Int(Pu128(0), _), .. }) = count_arg.kind && let ExprKind::Lit(Spanned { diff --git a/clippy_lints/src/missing_asserts_for_indexing.rs b/clippy_lints/src/missing_asserts_for_indexing.rs index bbc4d0a0f9a5..0e4d39c99902 100644 --- a/clippy_lints/src/missing_asserts_for_indexing.rs +++ b/clippy_lints/src/missing_asserts_for_indexing.rs @@ -7,6 +7,7 @@ use clippy_utils::source::snippet; use clippy_utils::visitors::for_each_expr; use clippy_utils::{eq_expr_value, hash_expr, higher}; use rustc_ast::{LitKind, RangeLimits}; +use rustc_data_structures::packed::Pu128; use rustc_data_structures::unhash::UnhashMap; use rustc_errors::{Applicability, Diagnostic}; use rustc_hir::{BinOp, Block, Body, Expr, ExprKind, UnOp}; @@ -102,8 +103,8 @@ fn len_comparison<'hir>( ) -> Option<(LengthComparison, usize, &'hir Expr<'hir>)> { macro_rules! int_lit_pat { ($id:ident) => { - ExprKind::Lit(Spanned { - node: LitKind::Int($id, _), + ExprKind::Lit(&Spanned { + node: LitKind::Int(Pu128($id), _), .. }) }; @@ -112,13 +113,13 @@ fn len_comparison<'hir>( // normalize comparison, `v.len() > 4` becomes `4 < v.len()` // this simplifies the logic a bit let (op, left, right) = normalize_comparison(bin_op.node, left, right)?; - match (op, &left.kind, &right.kind) { - (Rel::Lt, int_lit_pat!(left), _) => Some((LengthComparison::IntLessThanLength, *left as usize, right)), - (Rel::Lt, _, int_lit_pat!(right)) => Some((LengthComparison::LengthLessThanInt, *right as usize, left)), - (Rel::Le, int_lit_pat!(left), _) => Some((LengthComparison::IntLessThanOrEqualLength, *left as usize, right)), - (Rel::Le, _, int_lit_pat!(right)) => Some((LengthComparison::LengthLessThanOrEqualInt, *right as usize, left)), - (Rel::Eq, int_lit_pat!(left), _) => Some((LengthComparison::LengthEqualInt, *left as usize, right)), - (Rel::Eq, _, int_lit_pat!(right)) => Some((LengthComparison::LengthEqualInt, *right as usize, left)), + match (op, left.kind, right.kind) { + (Rel::Lt, int_lit_pat!(left), _) => Some((LengthComparison::IntLessThanLength, left as usize, right)), + (Rel::Lt, _, int_lit_pat!(right)) => Some((LengthComparison::LengthLessThanInt, right as usize, left)), + (Rel::Le, int_lit_pat!(left), _) => Some((LengthComparison::IntLessThanOrEqualLength, left as usize, right)), + (Rel::Le, _, int_lit_pat!(right)) => Some((LengthComparison::LengthLessThanOrEqualInt, right as usize, left)), + (Rel::Eq, int_lit_pat!(left), _) => Some((LengthComparison::LengthEqualInt, left as usize, right)), + (Rel::Eq, _, int_lit_pat!(right)) => Some((LengthComparison::LengthEqualInt, right as usize, left)), _ => None, } } @@ -206,14 +207,14 @@ impl<'hir> IndexEntry<'hir> { /// for `..=5` this returns `Some(5)` fn upper_index_expr(expr: &Expr<'_>) -> Option { if let ExprKind::Lit(lit) = &expr.kind - && let LitKind::Int(index, _) = lit.node + && let LitKind::Int(Pu128(index), _) = lit.node { Some(index as usize) } else if let Some(higher::Range { end: Some(end), limits, .. }) = higher::Range::hir(expr) && let ExprKind::Lit(lit) = &end.kind - && let LitKind::Int(index @ 1.., _) = lit.node + && let LitKind::Int(Pu128(index @ 1..), _) = lit.node { match limits { RangeLimits::HalfOpen => Some(index as usize - 1), diff --git a/clippy_lints/src/operators/arithmetic_side_effects.rs b/clippy_lints/src/operators/arithmetic_side_effects.rs index c081dec9b6b7..929efb6c574d 100644 --- a/clippy_lints/src/operators/arithmetic_side_effects.rs +++ b/clippy_lints/src/operators/arithmetic_side_effects.rs @@ -151,7 +151,7 @@ impl ArithmeticSideEffects { if let hir::ExprKind::Lit(lit) = actual.kind && let ast::LitKind::Int(n, _) = lit.node { - return Some(n); + return Some(n.get()); } if let Some(Constant::Int(n)) = constant(cx, cx.typeck_results(), expr) { return Some(n); diff --git a/clippy_lints/src/operators/verbose_bit_mask.rs b/clippy_lints/src/operators/verbose_bit_mask.rs index fbf65e92b322..a6aba33e431a 100644 --- a/clippy_lints/src/operators/verbose_bit_mask.rs +++ b/clippy_lints/src/operators/verbose_bit_mask.rs @@ -1,6 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::sugg::Sugg; use rustc_ast::ast::LitKind; +use rustc_data_structures::packed::Pu128; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; @@ -19,9 +20,9 @@ pub(super) fn check<'tcx>( && 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 LitKind::Int(Pu128(n), _) = lit.node && let ExprKind::Lit(lit1) = &right.kind - && let LitKind::Int(0, _) = lit1.node + && let LitKind::Int(Pu128(0), _) = lit1.node && n.leading_zeros() == n.count_zeros() && n > u128::from(threshold) { diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 727f93c83274..61b38391d9e0 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -275,7 +275,7 @@ pub fn lit_to_mir_constant<'tcx>(lit: &LitKind, ty: Option>) -> Constan LitKind::Byte(b) => Constant::Int(u128::from(b)), LitKind::ByteStr(ref s, _) | LitKind::CStr(ref s, _) => Constant::Binary(Lrc::clone(s)), LitKind::Char(c) => Constant::Char(c), - LitKind::Int(n, _) => Constant::Int(n), + LitKind::Int(n, _) => Constant::Int(n.get()), LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty { ast::FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()), ast::FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()), diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index d264e46f1332..ebe520b27eb5 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -80,6 +80,7 @@ use std::sync::{Mutex, MutexGuard, OnceLock}; use itertools::Itertools; use rustc_ast::ast::{self, LitKind, RangeLimits}; use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::packed::Pu128; use rustc_data_structures::unhash::UnhashMap; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalModDefId, LOCAL_CRATE}; @@ -838,7 +839,7 @@ pub fn is_default_equivalent_call(cx: &LateContext<'_>, repl_func: &Expr<'_>) -> pub fn is_default_equivalent(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { match &e.kind { ExprKind::Lit(lit) => match lit.node { - LitKind::Bool(false) | LitKind::Int(0, _) => true, + LitKind::Bool(false) | LitKind::Int(Pu128(0), _) => true, LitKind::Str(s, _) => s.is_empty(), _ => false, }, From 4f82668de386769ee9bf68c67c6a9a42978e8c6d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 16 Jan 2024 14:29:28 +1100 Subject: [PATCH 1048/1222] Rename `LintContext::struct_span_lint` as `LintContext::span_lint`. --- clippy.toml | 2 +- .../src/utils/internal_lints/compiler_lint_functions.rs | 1 - clippy_utils/src/diagnostics.rs | 8 ++++---- ...disallow_struct_span_lint.rs => disallow_span_lint.rs} | 2 +- ..._struct_span_lint.stderr => disallow_span_lint.stderr} | 6 +++--- 5 files changed, 9 insertions(+), 10 deletions(-) rename tests/ui-internal/{disallow_struct_span_lint.rs => disallow_span_lint.rs} (92%) rename tests/ui-internal/{disallow_struct_span_lint.stderr => disallow_span_lint.stderr} (81%) diff --git a/clippy.toml b/clippy.toml index 4a1805f75235..afadbb032b76 100644 --- a/clippy.toml +++ b/clippy.toml @@ -2,6 +2,6 @@ avoid-breaking-exported-api = false # use the various `span_lint_*` methods instead, which also add a link to the docs disallowed-methods = [ - "rustc_lint::context::LintContext::struct_span_lint", + "rustc_lint::context::LintContext::span_lint", "rustc_middle::ty::context::TyCtxt::struct_span_lint_hir" ] diff --git a/clippy_lints/src/utils/internal_lints/compiler_lint_functions.rs b/clippy_lints/src/utils/internal_lints/compiler_lint_functions.rs index 5059712d69c1..df37619227c8 100644 --- a/clippy_lints/src/utils/internal_lints/compiler_lint_functions.rs +++ b/clippy_lints/src/utils/internal_lints/compiler_lint_functions.rs @@ -41,7 +41,6 @@ impl CompilerLintFunctions { pub fn new() -> Self { let mut map = FxHashMap::default(); map.insert("span_lint", "utils::span_lint"); - map.insert("struct_span_lint", "utils::span_lint"); map.insert("lint", "utils::span_lint"); map.insert("span_lint_note", "utils::span_lint_and_note"); map.insert("span_lint_help", "utils::span_lint_and_help"); diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs index 7562961538e3..86a43cb367f8 100644 --- a/clippy_utils/src/diagnostics.rs +++ b/clippy_utils/src/diagnostics.rs @@ -47,7 +47,7 @@ fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) { /// ``` pub fn span_lint(cx: &T, lint: &'static Lint, sp: impl Into, msg: &str) { #[expect(clippy::disallowed_methods)] - cx.struct_span_lint(lint, sp, msg.to_string(), |diag| { + cx.span_lint(lint, sp, msg.to_string(), |diag| { docs_link(diag, lint); }); } @@ -81,7 +81,7 @@ pub fn span_lint_and_help( help: &str, ) { #[expect(clippy::disallowed_methods)] - cx.struct_span_lint(lint, span, msg.to_string(), |diag| { + cx.span_lint(lint, span, msg.to_string(), |diag| { let help = help.to_string(); if let Some(help_span) = help_span { diag.span_help(help_span, help.to_string()); @@ -124,7 +124,7 @@ pub fn span_lint_and_note( note: &str, ) { #[expect(clippy::disallowed_methods)] - cx.struct_span_lint(lint, span, msg.to_string(), |diag| { + cx.span_lint(lint, span, msg.to_string(), |diag| { let note = note.to_string(); if let Some(note_span) = note_span { diag.span_note(note_span, note); @@ -146,7 +146,7 @@ where F: FnOnce(&mut Diagnostic), { #[expect(clippy::disallowed_methods)] - cx.struct_span_lint(lint, sp, msg.to_string(), |diag| { + cx.span_lint(lint, sp, msg.to_string(), |diag| { f(diag); docs_link(diag, lint); }); diff --git a/tests/ui-internal/disallow_struct_span_lint.rs b/tests/ui-internal/disallow_span_lint.rs similarity index 92% rename from tests/ui-internal/disallow_struct_span_lint.rs rename to tests/ui-internal/disallow_span_lint.rs index c81d54918cbb..8b605b5a7e1d 100644 --- a/tests/ui-internal/disallow_struct_span_lint.rs +++ b/tests/ui-internal/disallow_span_lint.rs @@ -11,7 +11,7 @@ use rustc_lint::{Lint, LintContext}; use rustc_middle::ty::TyCtxt; pub fn a(cx: impl LintContext, lint: &'static Lint, span: impl Into, msg: impl Into) { - cx.struct_span_lint(lint, span, msg, |_| {}); + cx.span_lint(lint, span, msg, |_| {}); } pub fn b( diff --git a/tests/ui-internal/disallow_struct_span_lint.stderr b/tests/ui-internal/disallow_span_lint.stderr similarity index 81% rename from tests/ui-internal/disallow_struct_span_lint.stderr rename to tests/ui-internal/disallow_span_lint.stderr index 7d424124f2b1..9b1010a1b6d2 100644 --- a/tests/ui-internal/disallow_struct_span_lint.stderr +++ b/tests/ui-internal/disallow_span_lint.stderr @@ -1,8 +1,8 @@ -error: use of a disallowed method `rustc_lint::context::LintContext::struct_span_lint` +error: use of a disallowed method `rustc_lint::context::LintContext::span_lint` --> $DIR/disallow_struct_span_lint.rs:14:5 | -LL | cx.struct_span_lint(lint, span, msg, |_| {}); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | cx.span_lint(lint, span, msg, |_| {}); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::disallowed-methods` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::disallowed_methods)]` From 78430fb7cc71c869bb9caec8b6a0e084a3693344 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 16 Jan 2024 16:14:33 +1100 Subject: [PATCH 1049/1222] Rename `TyCtxt::struct_span_lint_hir` as `TyCtxt::node_span_lint`. --- clippy.toml | 2 +- clippy_utils/src/diagnostics.rs | 4 ++-- tests/ui-internal/disallow_span_lint.rs | 2 +- tests/ui-internal/disallow_span_lint.stderr | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy.toml b/clippy.toml index afadbb032b76..8c405ac6a4e8 100644 --- a/clippy.toml +++ b/clippy.toml @@ -3,5 +3,5 @@ avoid-breaking-exported-api = false # use the various `span_lint_*` methods instead, which also add a link to the docs disallowed-methods = [ "rustc_lint::context::LintContext::span_lint", - "rustc_middle::ty::context::TyCtxt::struct_span_lint_hir" + "rustc_middle::ty::context::TyCtxt::node_span_lint" ] diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs index 86a43cb367f8..56978eb2ee80 100644 --- a/clippy_utils/src/diagnostics.rs +++ b/clippy_utils/src/diagnostics.rs @@ -154,7 +154,7 @@ where pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) { #[expect(clippy::disallowed_methods)] - cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg.to_string(), |diag| { + cx.tcx.node_span_lint(lint, hir_id, sp, msg.to_string(), |diag| { docs_link(diag, lint); }); } @@ -168,7 +168,7 @@ pub fn span_lint_hir_and_then( f: impl FnOnce(&mut Diagnostic), ) { #[expect(clippy::disallowed_methods)] - cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg.to_string(), |diag| { + cx.tcx.node_span_lint(lint, hir_id, sp, msg.to_string(), |diag| { f(diag); docs_link(diag, lint); }); diff --git a/tests/ui-internal/disallow_span_lint.rs b/tests/ui-internal/disallow_span_lint.rs index 8b605b5a7e1d..b9b4a07d29d0 100644 --- a/tests/ui-internal/disallow_span_lint.rs +++ b/tests/ui-internal/disallow_span_lint.rs @@ -21,7 +21,7 @@ pub fn b( span: impl Into, msg: impl Into, ) { - tcx.struct_span_lint_hir(lint, hir_id, span, msg, |_| {}); + tcx.node_span_lint(lint, hir_id, span, msg, |_| {}); } fn main() {} diff --git a/tests/ui-internal/disallow_span_lint.stderr b/tests/ui-internal/disallow_span_lint.stderr index 9b1010a1b6d2..03556823a8f5 100644 --- a/tests/ui-internal/disallow_span_lint.stderr +++ b/tests/ui-internal/disallow_span_lint.stderr @@ -7,10 +7,10 @@ LL | cx.span_lint(lint, span, msg, |_| {}); = note: `-D clippy::disallowed-methods` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::disallowed_methods)]` -error: use of a disallowed method `rustc_middle::ty::context::TyCtxt::struct_span_lint_hir` +error: use of a disallowed method `rustc_middle::ty::context::TyCtxt::node_span_lint` --> $DIR/disallow_struct_span_lint.rs:24:5 | -LL | tcx.struct_span_lint_hir(lint, hir_id, span, msg, |_| {}); +LL | tcx.node_span_lint(lint, hir_id, span, msg, |_| {}); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors From a0fbb3bc472426236d2c8b1946082c63ec792919 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 8 Jan 2024 09:41:48 +0000 Subject: [PATCH 1050/1222] We don't look into static items anymore during const prop --- tests/ui/modulo_one.rs | 3 +-- tests/ui/modulo_one.stderr | 8 +------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/ui/modulo_one.rs b/tests/ui/modulo_one.rs index c1dbe9d9a878..c332a15f1577 100644 --- a/tests/ui/modulo_one.rs +++ b/tests/ui/modulo_one.rs @@ -33,7 +33,6 @@ fn main() { INT_MIN % NEG_ONE; //~^ ERROR: this operation will panic at runtime //~| ERROR: any number modulo -1 will panic/overflow or result in 0 - // ONLY caught by rustc + // Not caught by lint, we don't look into static items, even if entirely immutable. INT_MIN % STATIC_NEG_ONE; - //~^ ERROR: this operation will panic at runtime } diff --git a/tests/ui/modulo_one.stderr b/tests/ui/modulo_one.stderr index cc211ab6cd34..06bbb0f5d9a8 100644 --- a/tests/ui/modulo_one.stderr +++ b/tests/ui/modulo_one.stderr @@ -12,12 +12,6 @@ error: this operation will panic at runtime LL | INT_MIN % NEG_ONE; | ^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow -error: this operation will panic at runtime - --> $DIR/modulo_one.rs:37:5 - | -LL | INT_MIN % STATIC_NEG_ONE; - | ^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow - error: any number modulo 1 will be 0 --> $DIR/modulo_one.rs:8:5 | @@ -57,5 +51,5 @@ error: any number modulo -1 will panic/overflow or result in 0 LL | INT_MIN % NEG_ONE; | ^^^^^^^^^^^^^^^^^ -error: aborting due to 9 previous errors +error: aborting due to 8 previous errors From c0a40a4804ec67c1b1e29209b484800b2e472c45 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 26 Sep 2023 09:39:41 +0200 Subject: [PATCH 1051/1222] remove StructuralEq trait --- tests/ui/crashes/ice-6254.rs | 2 -- tests/ui/crashes/ice-6254.stderr | 15 --------------- 2 files changed, 17 deletions(-) delete mode 100644 tests/ui/crashes/ice-6254.stderr diff --git a/tests/ui/crashes/ice-6254.rs b/tests/ui/crashes/ice-6254.rs index 2ae426cf789d..8af60890390e 100644 --- a/tests/ui/crashes/ice-6254.rs +++ b/tests/ui/crashes/ice-6254.rs @@ -11,8 +11,6 @@ fn main() { // This used to cause an ICE (https://github.com/rust-lang/rust/issues/78071) match FOO_REF_REF { FOO_REF_REF => {}, - //~^ ERROR: to use a constant of type `Foo` in a pattern, `Foo` must be annotated - //~| NOTE: for more information, see issue #62411 {}, } } diff --git a/tests/ui/crashes/ice-6254.stderr b/tests/ui/crashes/ice-6254.stderr deleted file mode 100644 index 7a34e6cceeea..000000000000 --- a/tests/ui/crashes/ice-6254.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error: to use a constant of type `Foo` in a pattern, `Foo` must be annotated with `#[derive(PartialEq, Eq)]` - --> $DIR/ice-6254.rs:13:9 - | -LL | FOO_REF_REF => {}, - | ^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #62411 - = note: the traits must be derived, manual `impl`s are not sufficient - = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details - = note: `-D indirect-structural-match` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(indirect_structural_match)]` - -error: aborting due to 1 previous error - From 6c8d59d4100dd6766a3dc480e43f554b41308124 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 24 Jan 2024 15:24:58 +1100 Subject: [PATCH 1052/1222] Rename the unescaping functions. `unescape_literal` becomes `unescape_unicode`, and `unescape_c_string` becomes `unescape_mixed`. Because rfc3349 will mean that C string literals will no longer be the only mixed utf8 literals. --- clippy_dev/src/update_lints.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_dev/src/update_lints.rs b/clippy_dev/src/update_lints.rs index 6b76a44debff..f598f5d3d50f 100644 --- a/clippy_dev/src/update_lints.rs +++ b/clippy_dev/src/update_lints.rs @@ -928,7 +928,7 @@ fn remove_line_splices(s: &str) -> String { .and_then(|s| s.strip_suffix('"')) .unwrap_or_else(|| panic!("expected quoted string, found `{s}`")); let mut res = String::with_capacity(s.len()); - unescape::unescape_literal(s, unescape::Mode::Str, &mut |range, ch| { + unescape::unescape_unicode(s, unescape::Mode::Str, &mut |range, ch| { if ch.is_ok() { res.push_str(&s[range]); } From e52672fc44c5854868e97455c1302c3c4056e033 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 25 Jan 2024 12:06:01 +0000 Subject: [PATCH 1053/1222] Remove an unused error count check --- clippy_lints/src/transmute/utils.rs | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/clippy_lints/src/transmute/utils.rs b/clippy_lints/src/transmute/utils.rs index 1cf6cf8548a6..7a7bb9f9c94c 100644 --- a/clippy_lints/src/transmute/utils.rs +++ b/clippy_lints/src/transmute/utils.rs @@ -37,12 +37,6 @@ pub(super) fn check_cast<'tcx>( let inherited = Inherited::new(cx.tcx, local_def_id); let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, local_def_id); - // If we already have errors, we can't be sure we can pointer cast. - assert!( - !fn_ctxt.errors_reported_since_creation(), - "Newly created FnCtxt contained errors" - ); - if let Ok(check) = cast::CastCheck::new( &fn_ctxt, e, @@ -53,17 +47,7 @@ pub(super) fn check_cast<'tcx>( DUMMY_SP, hir::Constness::NotConst, ) { - let res = check.do_check(&fn_ctxt); - - // do_check's documentation says that it might return Ok and create - // errors in the fcx instead of returning Err in some cases. Those cases - // should be filtered out before getting here. - assert!( - !fn_ctxt.errors_reported_since_creation(), - "`fn_ctxt` contained errors after cast check!" - ); - - res.ok() + check.do_check(&fn_ctxt).ok() } else { None } From 274cb5ca1676cccb4f3030a3bd0214aef9eca948 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Fri, 26 Jan 2024 09:42:12 +0100 Subject: [PATCH 1054/1222] Clippy: Fix empty suggestion in from_over_into Co-authored-by: y21 <30553356+y21@users.noreply.github.com> --- clippy_lints/src/from_over_into.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index 93527bcdf5ce..1933a00891b0 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -181,9 +181,6 @@ fn convert_to_from( let from = snippet_opt(cx, self_ty.span)?; let into = snippet_opt(cx, target_ty.span)?; - let return_type = matches!(sig.decl.output, FnRetTy::Return(_)) - .then_some(String::from("Self")) - .unwrap_or_default(); let mut suggestions = vec![ // impl Into for U -> impl From for U // ~~~~ ~~~~ @@ -200,10 +197,13 @@ fn convert_to_from( // fn into([mut] self) -> T -> fn into([mut] v: T) -> T // ~~~~ ~~~~ (self_ident.span, format!("val: {from}")), + ]; + + if let FnRetTy::Return(_) = sig.decl.output { // fn into(self) -> T -> fn into(self) -> Self // ~ ~~~~ - (sig.decl.output.span(), return_type), - ]; + suggestions.push((sig.decl.output.span(), String::from("Self"))); + } let mut finder = SelfFinder { cx, From 893ffcdaaaf0ccdf7fcde0e3690fdf683057b24e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 6 Jan 2024 14:39:51 +0100 Subject: [PATCH 1055/1222] remove illegal_floating_point_literal_pattern lint --- tests/ui/expect_tool_lint_rfc_2383.rs | 16 ++++------------ tests/ui/expect_tool_lint_rfc_2383.stderr | 16 ++++++++-------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/tests/ui/expect_tool_lint_rfc_2383.rs b/tests/ui/expect_tool_lint_rfc_2383.rs index 3811421dc715..72097bfabd72 100644 --- a/tests/ui/expect_tool_lint_rfc_2383.rs +++ b/tests/ui/expect_tool_lint_rfc_2383.rs @@ -20,12 +20,8 @@ mod rustc_ok { pub fn rustc_lints() { let x = 42.0; - #[expect(illegal_floating_point_literal_pattern)] - match x { - 5.0 => {} - 6.0 => {} - _ => {} - } + #[expect(invalid_nan_comparisons)] + let _b = x == f32::NAN; } } @@ -38,13 +34,9 @@ mod rustc_warn { pub fn rustc_lints() { let x = 42; - #[expect(illegal_floating_point_literal_pattern)] + #[expect(invalid_nan_comparisons)] //~^ ERROR: this lint expectation is unfulfilled - match x { - 5 => {} - 6 => {} - _ => {} - } + let _b = x == 5; } } diff --git a/tests/ui/expect_tool_lint_rfc_2383.stderr b/tests/ui/expect_tool_lint_rfc_2383.stderr index 3f8d0b724362..2a418d845663 100644 --- a/tests/ui/expect_tool_lint_rfc_2383.stderr +++ b/tests/ui/expect_tool_lint_rfc_2383.stderr @@ -1,5 +1,5 @@ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:35:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:31:14 | LL | #[expect(dead_code)] | ^^^^^^^^^ @@ -8,31 +8,31 @@ LL | #[expect(dead_code)] = help: to override `-D warnings` add `#[allow(unfulfilled_lint_expectations)]` error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:41:18 + --> $DIR/expect_tool_lint_rfc_2383.rs:37:18 | -LL | #[expect(illegal_floating_point_literal_pattern)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[expect(invalid_nan_comparisons)] + | ^^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:116:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:108:14 | LL | #[expect(clippy::almost_swapped)] | ^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:124:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:116:14 | LL | #[expect(clippy::bytes_nth)] | ^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:130:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:122:14 | LL | #[expect(clippy::if_same_then_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:136:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:128:14 | LL | #[expect(clippy::overly_complex_bool_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 746b560efae0c7ff94c95f058074b125ab9d4c5d Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 12 May 2023 03:02:46 +0200 Subject: [PATCH 1056/1222] Fix `NonZero` clippy lints. --- .../src/operators/arithmetic_side_effects.rs | 55 +++++++++++-------- .../transmute/transmute_int_to_non_zero.rs | 51 +++++++++++------ 2 files changed, 64 insertions(+), 42 deletions(-) diff --git a/clippy_lints/src/operators/arithmetic_side_effects.rs b/clippy_lints/src/operators/arithmetic_side_effects.rs index 929efb6c574d..96ea063aa74d 100644 --- a/clippy_lints/src/operators/arithmetic_side_effects.rs +++ b/clippy_lints/src/operators/arithmetic_side_effects.rs @@ -1,11 +1,11 @@ use super::ARITHMETIC_SIDE_EFFECTS; use clippy_utils::consts::{constant, constant_simple, Constant}; use clippy_utils::diagnostics::span_lint; -use clippy_utils::ty::type_diagnostic_name; +use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::{expr_or_init, is_from_proc_macro, is_lint_allowed, peel_hir_expr_refs, peel_hir_expr_unary}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::Ty; +use rustc_middle::ty::{self, Ty}; use rustc_session::impl_lint_pass; use rustc_span::source_map::Spanned; use rustc_span::symbol::sym; @@ -88,37 +88,44 @@ impl ArithmeticSideEffects { } /// Verifies built-in types that have specific allowed operations - fn has_specific_allowed_type_and_operation( - cx: &LateContext<'_>, - lhs_ty: Ty<'_>, + fn has_specific_allowed_type_and_operation<'tcx>( + cx: &LateContext<'tcx>, + lhs_ty: Ty<'tcx>, op: &Spanned, - rhs_ty: Ty<'_>, + rhs_ty: Ty<'tcx>, ) -> bool { let is_div_or_rem = matches!(op.node, hir::BinOpKind::Div | hir::BinOpKind::Rem); - let is_non_zero_u = |symbol: Option| { - matches!( - symbol, - Some( - sym::NonZeroU128 - | sym::NonZeroU16 - | sym::NonZeroU32 - | sym::NonZeroU64 - | sym::NonZeroU8 - | sym::NonZeroUsize - ) - ) + let is_non_zero_u = |cx: &LateContext<'tcx>, ty: Ty<'tcx>| { + let tcx = cx.tcx; + + let ty::Adt(adt, substs) = ty.kind() else { return false }; + + if !tcx.is_diagnostic_item(sym::NonZero, adt.did()) { + return false; + }; + + let int_type = substs.type_at(0); + let unsigned_int_types = [ + tcx.types.u8, + tcx.types.u16, + tcx.types.u32, + tcx.types.u64, + tcx.types.u128, + tcx.types.usize, + ]; + + unsigned_int_types.contains(&int_type) }; let is_sat_or_wrap = |ty: Ty<'_>| { - let is_sat = type_diagnostic_name(cx, ty) == Some(sym::Saturating); - let is_wrap = type_diagnostic_name(cx, ty) == Some(sym::Wrapping); - is_sat || is_wrap + is_type_diagnostic_item(cx, ty, sym::Saturating) || is_type_diagnostic_item(cx, ty, sym::Wrapping) }; - // If the RHS is NonZeroU*, then division or module by zero will never occur - if is_non_zero_u(type_diagnostic_name(cx, rhs_ty)) && is_div_or_rem { + // If the RHS is `NonZero`, then division or module by zero will never occur. + if is_non_zero_u(cx, rhs_ty) && is_div_or_rem { return true; } - // `Saturation` and `Wrapping` can overflow if the RHS is zero in a division or module + + // `Saturation` and `Wrapping` can overflow if the RHS is zero in a division or module. if is_sat_or_wrap(lhs_ty) { return !is_div_or_rem; } diff --git a/clippy_lints/src/transmute/transmute_int_to_non_zero.rs b/clippy_lints/src/transmute/transmute_int_to_non_zero.rs index 5df645491ff8..97068efd43cd 100644 --- a/clippy_lints/src/transmute/transmute_int_to_non_zero.rs +++ b/clippy_lints/src/transmute/transmute_int_to_non_zero.rs @@ -16,40 +16,55 @@ pub(super) fn check<'tcx>( to_ty: Ty<'tcx>, arg: &'tcx Expr<'_>, ) -> bool { - let (ty::Int(_) | ty::Uint(_), Some(to_ty_adt)) = (&from_ty.kind(), to_ty.ty_adt_def()) else { + let tcx = cx.tcx; + + let (ty::Int(_) | ty::Uint(_), ty::Adt(adt, substs)) = (&from_ty.kind(), to_ty.kind()) else { return false; }; - let Some(to_type_sym) = cx.tcx.get_diagnostic_name(to_ty_adt.did()) else { + + if !tcx.is_diagnostic_item(sym::NonZero, adt.did()) { return false; }; - if !matches!( - to_type_sym, - sym::NonZeroU8 - | sym::NonZeroU16 - | sym::NonZeroU32 - | sym::NonZeroU64 - | sym::NonZeroU128 - | sym::NonZeroI8 - | sym::NonZeroI16 - | sym::NonZeroI32 - | sym::NonZeroI64 - | sym::NonZeroI128 - ) { + // FIXME: This can be simplified once `NonZero` is stable. + let coercable_types = [ + ("NonZeroU8", tcx.types.u8), + ("NonZeroU16", tcx.types.u16), + ("NonZeroU32", tcx.types.u32), + ("NonZeroU64", tcx.types.u64), + ("NonZeroU128", tcx.types.u128), + ("NonZeroUsize", tcx.types.usize), + ("NonZeroI8", tcx.types.i8), + ("NonZeroI16", tcx.types.i16), + ("NonZeroI32", tcx.types.i32), + ("NonZeroI64", tcx.types.i64), + ("NonZeroI128", tcx.types.i128), + ("NonZeroIsize", tcx.types.isize), + ]; + + let int_type = substs.type_at(0); + + let Some(nonzero_alias) = coercable_types.iter().find_map(|(nonzero_alias, t)| { + if *t == int_type && *t == from_ty { + Some(nonzero_alias) + } else { + None + } + }) else { return false; - } + }; span_lint_and_then( cx, TRANSMUTE_INT_TO_NON_ZERO, e.span, - &format!("transmute from a `{from_ty}` to a `{to_type_sym}`"), + &format!("transmute from a `{from_ty}` to a `{nonzero_alias}`"), |diag| { let arg = sugg::Sugg::hir(cx, arg, ".."); diag.span_suggestion( e.span, "consider using", - format!("{to_type_sym}::{}({arg})", sym::new_unchecked), + format!("{nonzero_alias}::{}({arg})", sym::new_unchecked), Applicability::Unspecified, ); }, From 5bb9a44b95cc40bf6f3429d206b2a76a19fe60e8 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 25 Jan 2024 19:16:38 +0300 Subject: [PATCH 1057/1222] hir: Simplify `hir_owner_nodes` query The query accept arbitrary DefIds, not just owner DefIds. The return can be an `Option` because if there are no nodes, then it doesn't matter whether it's due to NonOwner or Phantom. Also rename the query to `opt_hir_owner_nodes`. --- clippy_lints/src/min_ident_chars.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/min_ident_chars.rs b/clippy_lints/src/min_ident_chars.rs index 34b8e0dbe6a7..2b0063f62d94 100644 --- a/clippy_lints/src/min_ident_chars.rs +++ b/clippy_lints/src/min_ident_chars.rs @@ -93,7 +93,7 @@ impl Visitor<'_> for IdentVisitor<'_, '_> { // reimplement it even if we wanted to cx.tcx.opt_hir_node(hir_id) } else { - let Some(owner) = cx.tcx.hir_owner_nodes(hir_id.owner).as_owner() else { + let Some(owner) = cx.tcx.opt_hir_owner_nodes(hir_id.owner) else { return; }; owner.nodes.get(hir_id.local_id).copied().flatten().map(|p| p.node) From 9715435ef2e54419f5406abd1a80ac517276732a Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 25 Jan 2024 19:34:49 +0300 Subject: [PATCH 1058/1222] hir: Add non-optional `hir_owner_nodes` for real `OwnerId`s --- clippy_lints/src/min_ident_chars.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/clippy_lints/src/min_ident_chars.rs b/clippy_lints/src/min_ident_chars.rs index 2b0063f62d94..41168230752a 100644 --- a/clippy_lints/src/min_ident_chars.rs +++ b/clippy_lints/src/min_ident_chars.rs @@ -93,9 +93,7 @@ impl Visitor<'_> for IdentVisitor<'_, '_> { // reimplement it even if we wanted to cx.tcx.opt_hir_node(hir_id) } else { - let Some(owner) = cx.tcx.opt_hir_owner_nodes(hir_id.owner) else { - return; - }; + let owner = cx.tcx.hir_owner_nodes(hir_id.owner); owner.nodes.get(hir_id.local_id).copied().flatten().map(|p| p.node) }; let Some(node) = node else { From 05404e9b69d4187e879946cb3e9df02dd2b605aa Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 25 Jan 2024 20:47:03 +0300 Subject: [PATCH 1059/1222] hir: Remove `hir::Map::{owner,expect_owner}` --- clippy_lints/src/methods/iter_nth_zero.rs | 2 +- clippy_lints/src/returns.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/methods/iter_nth_zero.rs b/clippy_lints/src/methods/iter_nth_zero.rs index e1f950d5a4a5..262a57ab591a 100644 --- a/clippy_lints/src/methods/iter_nth_zero.rs +++ b/clippy_lints/src/methods/iter_nth_zero.rs @@ -11,7 +11,7 @@ use rustc_span::sym; use super::ITER_NTH_ZERO; pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>) { - if let OwnerNode::Item(item) = cx.tcx.hir().owner(cx.tcx.hir().get_parent_item(expr.hir_id)) + if let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir().get_parent_item(expr.hir_id)) && let def_id = item.owner_id.to_def_id() && is_trait_method(cx, expr, sym::Iterator) && let Some(Constant::Int(0)) = constant(cx, cx.typeck_results(), arg) diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 2293b53b42b9..e01750465873 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -183,7 +183,7 @@ impl<'tcx> LateLintPass<'tcx> for Return { && let ExprKind::Ret(Some(ret)) = expr.kind && let ExprKind::Match(.., MatchSource::TryDesugar(_)) = ret.kind // Ensure this is not the final stmt, otherwise removing it would cause a compile error - && let OwnerNode::Item(item) = cx.tcx.hir().owner(cx.tcx.hir().get_parent_item(expr.hir_id)) + && let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir().get_parent_item(expr.hir_id)) && let ItemKind::Fn(_, _, body) = item.kind && let block = cx.tcx.hir().body(body).value && let ExprKind::Block(block, _) = block.kind From 1c1a462d921b4dcd0d81315dc8e3679152af6842 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 30 Jan 2024 16:57:29 +1100 Subject: [PATCH 1060/1222] Don't hash lints differently to non-lints. `Diagnostic::keys`, which is used for hashing and equating diagnostics, has a surprising behaviour: it ignores children, but only for lints. This was added in #88493 to fix some duplicated diagnostics, but it doesn't seem necessary any more. This commit removes the special case and only four tests have changed output, with additional errors. And those additional errors aren't exact duplicates, they're just similar. For example, in src/tools/clippy/tests/ui/same_name_method.rs we currently have this error: ``` error: method's name is the same as an existing method in a trait --> $DIR/same_name_method.rs:75:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here --> $DIR/same_name_method.rs:79:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ ``` and with this change we also get this error: ``` error: method's name is the same as an existing method in a trait --> $DIR/same_name_method.rs:75:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here --> $DIR/same_name_method.rs:81:9 | LL | impl T2 for S {} | ^^^^^^^^^^^^^^^^ ``` I think printing this second argument is reasonable, possibly even preferable to hiding it. And the other cases are similar. --- tests/ui/same_name_method.rs | 1 + tests/ui/same_name_method.stderr | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/ui/same_name_method.rs b/tests/ui/same_name_method.rs index 1c166a19b0ad..26b1a299ba1c 100644 --- a/tests/ui/same_name_method.rs +++ b/tests/ui/same_name_method.rs @@ -74,6 +74,7 @@ mod should_lint { impl S { fn foo() {} //~^ ERROR: method's name is the same as an existing method in a trait + //~| ERROR: method's name is the same as an existing method in a trait } impl T1 for S {} diff --git a/tests/ui/same_name_method.stderr b/tests/ui/same_name_method.stderr index 3c5c4a53ad1f..82f5ef6a9e82 100644 --- a/tests/ui/same_name_method.stderr +++ b/tests/ui/same_name_method.stderr @@ -56,10 +56,22 @@ LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> $DIR/same_name_method.rs:79:9 + --> $DIR/same_name_method.rs:80:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ -error: aborting due to 5 previous errors +error: method's name is the same as an existing method in a trait + --> $DIR/same_name_method.rs:75:13 + | +LL | fn foo() {} + | ^^^^^^^^^^^ + | +note: existing `foo` defined here + --> $DIR/same_name_method.rs:82:9 + | +LL | impl T2 for S {} + | ^^^^^^^^^^^^^^^^ + +error: aborting due to 6 previous errors From 4fd114ee1bbc189edea745fa1e758f286592ec22 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 6 Feb 2024 09:51:39 +1100 Subject: [PATCH 1061/1222] Invert diagnostic lints. That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has be converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted. --- clippy_config/src/lib.rs | 4 +++- clippy_lints/src/lib.rs | 7 ++++++- clippy_utils/src/lib.rs | 8 +++++++- src/driver.rs | 2 ++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/clippy_config/src/lib.rs b/clippy_config/src/lib.rs index 533e375a3104..5449feed090a 100644 --- a/clippy_config/src/lib.rs +++ b/clippy_config/src/lib.rs @@ -4,7 +4,9 @@ #![allow( clippy::must_use_candidate, clippy::missing_panics_doc, - rustc::untranslatable_diagnostic_trivial + rustc::diagnostic_outside_of_impl, + rustc::untranslatable_diagnostic, + rustc::untranslatable_diagnostic_trivial, )] extern crate rustc_ast; diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index feb4d188f397..f6608b229539 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -10,7 +10,12 @@ #![feature(stmt_expr_attributes)] #![recursion_limit = "512"] #![cfg_attr(feature = "deny-warnings", deny(warnings))] -#![allow(clippy::missing_docs_in_private_items, clippy::must_use_candidate)] +#![allow( + clippy::missing_docs_in_private_items, + clippy::must_use_candidate, + rustc::diagnostic_outside_of_impl, + rustc::untranslatable_diagnostic, +)] #![warn(trivial_casts, trivial_numeric_casts)] // warn on lints, that are included in `rust-lang/rust`s bootstrap #![warn(rust_2018_idioms, unused_lifetimes)] diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 4e499ff4cc61..36034861df5b 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -8,7 +8,13 @@ #![feature(assert_matches)] #![recursion_limit = "512"] #![cfg_attr(feature = "deny-warnings", deny(warnings))] -#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc, clippy::must_use_candidate)] +#![allow( + clippy::missing_errors_doc, + clippy::missing_panics_doc, + clippy::must_use_candidate, + rustc::diagnostic_outside_of_impl, + rustc::untranslatable_diagnostic, +)] // warn on the same lints as `clippy_lints` #![warn(trivial_casts, trivial_numeric_casts)] // warn on lints, that are included in `rust-lang/rust`s bootstrap diff --git a/src/driver.rs b/src/driver.rs index b944a299256c..1b159f5937a2 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -1,3 +1,5 @@ +#![allow(rustc::diagnostic_outside_of_impl)] +#![allow(rustc::untranslatable_diagnostic)] #![feature(rustc_private)] #![feature(let_chains)] #![feature(lazy_cell)] From f244ae07ec9240ec7ba1df3f340168e9e8717d02 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 24 Jan 2024 18:01:56 +0000 Subject: [PATCH 1062/1222] Add CoroutineClosure to TyKind, AggregateKind, UpvarArgs --- clippy_lints/src/dereference.rs | 1 + clippy_lints/src/utils/author.rs | 3 +++ tests/ui/author/blocks.stdout | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 8ff54dfcfa0d..194cf69ea7ed 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -881,6 +881,7 @@ impl TyCoercionStability { | ty::Coroutine(..) | ty::CoroutineWitness(..) | ty::Closure(..) + | ty::CoroutineClosure(..) | ty::Never | ty::Tuple(_) | ty::Alias(ty::Projection, _) => Self::Deref, diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index b26ebe5cee32..288df0fd663f 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -490,6 +490,9 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { format!("ClosureKind::Coroutine(CoroutineKind::Coroutine(Movability::{movability:?})") }, }, + ClosureKind::CoroutineClosure(desugaring) => format!( + "ClosureKind::CoroutineClosure(CoroutineDesugaring::{desugaring:?})" + ), }; let ret_ty = match fn_decl.output { diff --git a/tests/ui/author/blocks.stdout b/tests/ui/author/blocks.stdout index 8c4d71e68f80..579f137f861e 100644 --- a/tests/ui/author/blocks.stdout +++ b/tests/ui/author/blocks.stdout @@ -40,10 +40,10 @@ if let ExprKind::Block(block, None) = expr.kind { // report your lint here } -if let ExprKind::Closure { capture_clause: CaptureBy::Value { .. }, fn_decl: fn_decl, body: body_id, closure_kind: ClosureKind::Closure, .. } = expr.kind +if let ExprKind::Closure { capture_clause: CaptureBy::Value { .. }, fn_decl: fn_decl, body: body_id, closure_kind: ClosureKind::CoroutineClosure(CoroutineDesugaring::Async), .. } = expr.kind && let FnRetTy::DefaultReturn(_) = fn_decl.output && expr1 = &cx.tcx.hir().body(body_id).value - && let ExprKind::Closure { capture_clause: CaptureBy::Value { .. }, fn_decl: fn_decl1, body: body_id1, closure_kind: ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Closure)), .. } = expr1.kind + && let ExprKind::Closure { capture_clause: CaptureBy::Ref, fn_decl: fn_decl1, body: body_id1, closure_kind: ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Closure)), .. } = expr1.kind && let FnRetTy::DefaultReturn(_) = fn_decl1.output && expr2 = &cx.tcx.hir().body(body_id1).value && let ExprKind::Block(block, None) = expr2.kind From 1e590f9c40872e8e106918c9af459260b9a4f017 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 20 Jan 2024 15:21:27 +0300 Subject: [PATCH 1063/1222] hir: Make sure all `HirId`s have corresponding HIR `Node`s --- clippy_lints/src/min_ident_chars.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/min_ident_chars.rs b/clippy_lints/src/min_ident_chars.rs index 41168230752a..2f9f04832a75 100644 --- a/clippy_lints/src/min_ident_chars.rs +++ b/clippy_lints/src/min_ident_chars.rs @@ -94,7 +94,7 @@ impl Visitor<'_> for IdentVisitor<'_, '_> { cx.tcx.opt_hir_node(hir_id) } else { let owner = cx.tcx.hir_owner_nodes(hir_id.owner); - owner.nodes.get(hir_id.local_id).copied().flatten().map(|p| p.node) + owner.nodes.get(hir_id.local_id).copied().map(|p| p.node) }; let Some(node) = node else { return; From 243a93571b51b1e9814cddafc758a5ff414abe4f Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 21 Jan 2024 21:13:15 +0300 Subject: [PATCH 1064/1222] hir: Remove `fn opt_hir_id` and `fn opt_span` --- clippy_lints/src/absolute_paths.rs | 2 +- clippy_lints/src/casts/cast_slice_different_sizes.rs | 5 ++--- clippy_lints/src/casts/unnecessary_cast.rs | 3 +-- clippy_lints/src/derivable_impls.rs | 2 +- clippy_lints/src/empty_drop.rs | 2 +- clippy_lints/src/escape.rs | 6 +++--- clippy_lints/src/explicit_write.rs | 2 +- clippy_lints/src/index_refutable_slice.rs | 4 ++-- clippy_lints/src/len_zero.rs | 6 +++--- clippy_lints/src/loops/same_item_push.rs | 2 +- clippy_lints/src/manual_rem_euclid.rs | 2 +- clippy_lints/src/methods/filter_next.rs | 2 +- clippy_lints/src/methods/option_map_unwrap_or.rs | 4 ++-- clippy_lints/src/min_ident_chars.rs | 2 +- clippy_lints/src/mixed_read_write_in_expression.rs | 5 +---- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/same_name_method.rs | 4 ++-- clippy_lints/src/self_named_constructors.rs | 2 +- clippy_utils/src/lib.rs | 10 +++++----- 19 files changed, 31 insertions(+), 36 deletions(-) diff --git a/clippy_lints/src/absolute_paths.rs b/clippy_lints/src/absolute_paths.rs index 3822b83b4bc6..8ba661afeeb6 100644 --- a/clippy_lints/src/absolute_paths.rs +++ b/clippy_lints/src/absolute_paths.rs @@ -62,7 +62,7 @@ impl LateLintPass<'_> for AbsolutePaths { } = self; if !path.span.from_expansion() - && let Some(node) = cx.tcx.opt_hir_node(hir_id) + && let node = cx.tcx.hir_node(hir_id) && !matches!(node, Node::Item(item) if matches!(item.kind, ItemKind::Use(_, _))) && let [first, rest @ ..] = path.segments // Handle `::std` diff --git a/clippy_lints/src/casts/cast_slice_different_sizes.rs b/clippy_lints/src/casts/cast_slice_different_sizes.rs index 91bad8256ecb..0f29743856ac 100644 --- a/clippy_lints/src/casts/cast_slice_different_sizes.rs +++ b/clippy_lints/src/casts/cast_slice_different_sizes.rs @@ -68,9 +68,8 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv fn is_child_of_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let map = cx.tcx.hir(); - if let Some(parent_id) = map.opt_parent_id(expr.hir_id) - && let Some(parent) = cx.tcx.opt_hir_node(parent_id) - { + if let Some(parent_id) = map.opt_parent_id(expr.hir_id) { + let parent = cx.tcx.hir_node(parent_id); let expr = match parent { Node::Block(block) => { if let Some(parent_expr) = block.expr { diff --git a/clippy_lints/src/casts/unnecessary_cast.rs b/clippy_lints/src/casts/unnecessary_cast.rs index bb86b6f30759..81d0def4322d 100644 --- a/clippy_lints/src/casts/unnecessary_cast.rs +++ b/clippy_lints/src/casts/unnecessary_cast.rs @@ -144,8 +144,7 @@ pub(super) fn check<'tcx>( if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) { if let Some(id) = path_to_local(cast_expr) - && let Some(span) = cx.tcx.hir().opt_span(id) - && !span.eq_ctxt(cast_expr.span) + && !cx.tcx.hir().span(id).eq_ctxt(cast_expr.span) { // Binding context is different than the identifiers context. // Weird macro wizardry could be involved here. diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index 6b0423200d76..b0f46f5c646c 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -195,7 +195,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { && let Some(def_id) = trait_ref.trait_def_id() && cx.tcx.is_diagnostic_item(sym::Default, def_id) && let impl_item_hir = child.id.hir_id() - && let Some(Node::ImplItem(impl_item)) = cx.tcx.opt_hir_node(impl_item_hir) + && let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir) && let ImplItemKind::Fn(_, b) = &impl_item.kind && let Body { value: func_expr, .. } = cx.tcx.hir().body(*b) && let &Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind() diff --git a/clippy_lints/src/empty_drop.rs b/clippy_lints/src/empty_drop.rs index 1d2b907b9482..74db250b3ae9 100644 --- a/clippy_lints/src/empty_drop.rs +++ b/clippy_lints/src/empty_drop.rs @@ -42,7 +42,7 @@ impl LateLintPass<'_> for EmptyDrop { }) = item.kind && trait_ref.trait_def_id() == cx.tcx.lang_items().drop_trait() && let impl_item_hir = child.id.hir_id() - && let Some(Node::ImplItem(impl_item)) = cx.tcx.opt_hir_node(impl_item_hir) + && let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir) && let ImplItemKind::Fn(_, b) = &impl_item.kind && let Body { value: func_expr, .. } = cx.tcx.hir().body(*b) && let func_expr = peel_blocks(func_expr) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index b7776263060b..218d7c6c01ae 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -123,11 +123,11 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { // TODO: Replace with Map::is_argument(..) when it's fixed fn is_argument(tcx: TyCtxt<'_>, id: HirId) -> bool { - match tcx.opt_hir_node(id) { - Some(Node::Pat(Pat { + match tcx.hir_node(id) { + Node::Pat(Pat { kind: PatKind::Binding(..), .. - })) => (), + }) => (), _ => return false, } diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index e8c1e5db35e0..de048fef5f22 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -111,7 +111,7 @@ fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>) // Find id of the local that expr_end_of_block resolves to && let ExprKind::Path(QPath::Resolved(None, expr_path)) = expr_end_of_block.kind && let Res::Local(expr_res) = expr_path.res - && let Some(Node::Pat(res_pat)) = cx.tcx.opt_hir_node(expr_res) + && let Node::Pat(res_pat) = cx.tcx.hir_node(expr_res) // Find id of the local we found in the block && let PatKind::Binding(BindingAnnotation::NONE, local_hir_id, _ident, None) = local.pat.kind diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index 5417c13d0796..252be30c4e27 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -248,7 +248,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> { // Checking for slice indexing && let parent_id = map.parent_id(expr.hir_id) - && let Some(hir::Node::Expr(parent_expr)) = cx.tcx.opt_hir_node(parent_id) + && let hir::Node::Expr(parent_expr) = cx.tcx.hir_node(parent_id) && let hir::ExprKind::Index(_, index_expr, _) = parent_expr.kind && let Some(Constant::Int(index_value)) = constant(cx, cx.typeck_results(), index_expr) && let Ok(index_value) = index_value.try_into() @@ -256,7 +256,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> { // Make sure that this slice index is read only && let maybe_addrof_id = map.parent_id(parent_id) - && let Some(hir::Node::Expr(maybe_addrof_expr)) = cx.tcx.opt_hir_node(maybe_addrof_id) + && let hir::Node::Expr(maybe_addrof_expr) = cx.tcx.hir_node(maybe_addrof_id) && let hir::ExprKind::AddrOf(_kind, hir::Mutability::Not, _inner_expr) = maybe_addrof_expr.kind { use_info.index_use.push((index_value, map.span(parent_expr.hir_id))); diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index c1ab020117ca..27d85cde5320 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -147,9 +147,9 @@ impl<'tcx> LateLintPass<'tcx> for LenZero { && let Some(output) = parse_len_output(cx, cx.tcx.fn_sig(item.owner_id).instantiate_identity().skip_binder()) { - let (name, kind) = match cx.tcx.opt_hir_node(ty_hir_id) { - Some(Node::ForeignItem(x)) => (x.ident.name, "extern type"), - Some(Node::Item(x)) => match x.kind { + let (name, kind) = match cx.tcx.hir_node(ty_hir_id) { + Node::ForeignItem(x) => (x.ident.name, "extern type"), + Node::Item(x) => match x.kind { ItemKind::Struct(..) => (x.ident.name, "struct"), ItemKind::Enum(..) => (x.ident.name, "enum"), ItemKind::Union(..) => (x.ident.name, "union"), diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index 920a887a6fd1..5f015db2b33b 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -63,7 +63,7 @@ pub(super) fn check<'tcx>( && let PatKind::Binding(bind_ann, ..) = pat.kind && !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut)) && let parent_node = cx.tcx.hir().parent_id(hir_id) - && let Some(Node::Local(parent_let_expr)) = cx.tcx.opt_hir_node(parent_node) + && let Node::Local(parent_let_expr) = cx.tcx.hir_node(parent_node) && let Some(init) = parent_let_expr.init { match init.kind { diff --git a/clippy_lints/src/manual_rem_euclid.rs b/clippy_lints/src/manual_rem_euclid.rs index 71a83a68db93..e1768c6d9764 100644 --- a/clippy_lints/src/manual_rem_euclid.rs +++ b/clippy_lints/src/manual_rem_euclid.rs @@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid { // Also ensures the const is nonzero since zero can't be a divisor && const1 == const2 && const2 == const3 && let Some(hir_id) = path_to_local(expr3) - && let Some(Node::Pat(_)) = cx.tcx.opt_hir_node(hir_id) + && let Node::Pat(_) = cx.tcx.hir_node(hir_id) { // Apply only to params or locals with annotated types match cx.tcx.hir().find_parent(hir_id) { diff --git a/clippy_lints/src/methods/filter_next.rs b/clippy_lints/src/methods/filter_next.rs index 9251130a3054..7339362193e5 100644 --- a/clippy_lints/src/methods/filter_next.rs +++ b/clippy_lints/src/methods/filter_next.rs @@ -44,7 +44,7 @@ pub(super) fn check<'tcx>( // add note if not multi-line span_lint_and_then(cx, FILTER_NEXT, expr.span, msg, |diag| { let (applicability, pat) = if let Some(id) = path_to_local(recv) - && let Some(hir::Node::Pat(pat)) = cx.tcx.opt_hir_node(id) + && let hir::Node::Pat(pat) = cx.tcx.hir_node(id) && let hir::PatKind::Binding(BindingAnnotation(_, Mutability::Not), _, ident, _) = pat.kind { (Applicability::Unspecified, Some((pat.span, ident))) diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 624597ffca94..ab36f854fcb1 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -135,7 +135,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrapVisitor<'a, 'tcx> { fn visit_path(&mut self, path: &Path<'tcx>, _: HirId) { if let Res::Local(local_id) = path.res - && let Some(Node::Pat(pat)) = self.cx.tcx.opt_hir_node(local_id) + && let Node::Pat(pat) = self.cx.tcx.hir_node(local_id) && let PatKind::Binding(_, local_id, ..) = pat.kind { self.identifiers.insert(local_id); @@ -166,7 +166,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReferenceVisitor<'a, 'tcx> { && let ExprKind::Path(ref path) = expr.kind && let QPath::Resolved(_, path) = path && let Res::Local(local_id) = path.res - && let Some(Node::Pat(pat)) = self.cx.tcx.opt_hir_node(local_id) + && let Node::Pat(pat) = self.cx.tcx.hir_node(local_id) && let PatKind::Binding(_, local_id, ..) = pat.kind && self.identifiers.contains(&local_id) { diff --git a/clippy_lints/src/min_ident_chars.rs b/clippy_lints/src/min_ident_chars.rs index 2f9f04832a75..70cc43e266c6 100644 --- a/clippy_lints/src/min_ident_chars.rs +++ b/clippy_lints/src/min_ident_chars.rs @@ -91,7 +91,7 @@ impl Visitor<'_> for IdentVisitor<'_, '_> { let node = if hir_id.local_id == ItemLocalId::from_u32(0) { // In this case, we can just use `find`, `Owner`'s `node` field is private anyway so we can't // reimplement it even if we wanted to - cx.tcx.opt_hir_node(hir_id) + Some(cx.tcx.hir_node(hir_id)) } else { let owner = cx.tcx.hir_owner_nodes(hir_id.owner); owner.nodes.get(hir_id.local_id).copied().map(|p| p.node) diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs index 195ce17629a7..b593e48ae2e1 100644 --- a/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/clippy_lints/src/mixed_read_write_in_expression.rs @@ -213,11 +213,8 @@ fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) { if parent_id == cur_id { break; } - let Some(parent_node) = vis.cx.tcx.opt_hir_node(parent_id) else { - break; - }; - let stop_early = match parent_node { + let stop_early = match vis.cx.tcx.hir_node(parent_id) { Node::Expr(expr) => check_expr(vis, expr), Node::Stmt(stmt) => check_stmt(vis, stmt), Node::Item(_) => { diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index f8365deebd46..10ab380ba1bc 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -453,7 +453,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { if parent_id == cur_expr.hir_id { break; } - if let Some(Node::Expr(parent_expr)) = cx.tcx.opt_hir_node(parent_id) { + if let Node::Expr(parent_expr) = cx.tcx.hir_node(parent_id) { match &parent_expr.kind { ExprKind::AddrOf(..) => { // `&e` => `e` must be referenced. diff --git a/clippy_lints/src/same_name_method.rs b/clippy_lints/src/same_name_method.rs index 7a351dab2d45..07806b182f22 100644 --- a/clippy_lints/src/same_name_method.rs +++ b/clippy_lints/src/same_name_method.rs @@ -76,8 +76,8 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod { match of_trait { Some(trait_ref) => { let mut methods_in_trait: BTreeSet = - if let Some(Node::TraitRef(TraitRef { path, .. })) = - cx.tcx.opt_hir_node(trait_ref.hir_ref_id) + if let Node::TraitRef(TraitRef { path, .. }) = + cx.tcx.hir_node(trait_ref.hir_ref_id) && let Res::Def(DefKind::Trait, did) = path.res { // FIXME: if diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index 98f3235af10a..fc5a45dd56d6 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -73,7 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { if let Some(self_def) = self_ty.ty_adt_def() && let Some(self_local_did) = self_def.did().as_local() && let self_id = cx.tcx.local_def_id_to_hir_id(self_local_did) - && let Some(Node::Item(x)) = cx.tcx.opt_hir_node(self_id) + && let Node::Item(x) = cx.tcx.hir_node(self_id) && let type_name = x.ident.name.as_str().to_lowercase() && (impl_item.ident.name.as_str() == type_name || impl_item.ident.name.as_str().replace('_', "") == type_name) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 4e499ff4cc61..3f936009e44e 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -177,10 +177,10 @@ pub fn expr_or_init<'a, 'b, 'tcx: 'b>(cx: &LateContext<'tcx>, mut expr: &'a Expr /// canonical binding `HirId`. pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<'tcx>> { let hir = cx.tcx.hir(); - if let Some(Node::Pat(pat)) = cx.tcx.opt_hir_node(hir_id) + if let Node::Pat(pat) = cx.tcx.hir_node(hir_id) && matches!(pat.kind, PatKind::Binding(BindingAnnotation::NONE, ..)) && let parent = hir.parent_id(hir_id) - && let Some(Node::Local(local)) = cx.tcx.opt_hir_node(parent) + && let Node::Local(local) = cx.tcx.hir_node(parent) { return local.init; } @@ -1327,7 +1327,7 @@ pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio let map = &cx.tcx.hir(); let enclosing_node = map .get_enclosing_scope(hir_id) - .and_then(|enclosing_id| cx.tcx.opt_hir_node(enclosing_id)); + .map(|enclosing_id| cx.tcx.hir_node(enclosing_id)); enclosing_node.and_then(|node| match node { Node::Block(block) => Some(block), Node::Item(&Item { @@ -2696,10 +2696,10 @@ impl<'tcx> ExprUseNode<'tcx> { )), Self::Return(id) => { let hir_id = cx.tcx.local_def_id_to_hir_id(id.def_id); - if let Some(Node::Expr(Expr { + if let Node::Expr(Expr { kind: ExprKind::Closure(c), .. - })) = cx.tcx.opt_hir_node(hir_id) + }) = cx.tcx.hir_node(hir_id) { match c.fn_decl.output { FnRetTy::DefaultReturn(_) => None, From 76ff37bc3acabc666244522d62387b9dd2fc2102 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 7 Feb 2024 17:17:52 +0000 Subject: [PATCH 1065/1222] Use correct param env in clippy --- clippy_lints/src/default.rs | 4 ++-- clippy_lints/src/useless_conversion.rs | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index d8a070b785d5..8789efcc9944 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -131,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { // only when assigning `... = Default::default()` && is_expr_default(expr, cx) && let binding_type = cx.typeck_results().node_type(binding_id) - && let Some(adt) = binding_type.ty_adt_def() + && let ty::Adt(adt, args) = *binding_type.kind() && adt.is_struct() && let variant = adt.non_enum_variant() && (adt.did().is_local() || !variant.is_field_list_non_exhaustive()) @@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { .fields .iter() .all(|field| { - is_copy(cx, cx.tcx.type_of(field.did).instantiate_identity()) + is_copy(cx, cx.tcx.type_of(field.did).instantiate(cx.tcx, args)) }) && (!has_drop(cx, binding_type) || all_fields_are_copy) { diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 2e0a0f6cb3e4..f7a455977fac 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -86,7 +86,6 @@ fn into_iter_bound<'tcx>( param_index: u32, node_args: GenericArgsRef<'tcx>, ) -> Option { - let param_env = cx.tcx.param_env(fn_did); let mut into_iter_span = None; for (pred, span) in cx.tcx.explicit_predicates_of(fn_did).predicates { @@ -111,7 +110,7 @@ fn into_iter_bound<'tcx>( })); let predicate = EarlyBinder::bind(tr).instantiate(cx.tcx, args); - let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), param_env, predicate); + let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate); if !cx .tcx .infer_ctxt() From 2b620ec5d1ba1bf990e5fada4781820f3e42f73e Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 1 Feb 2024 08:35:37 +0000 Subject: [PATCH 1066/1222] inline a function that is only used in clippy --- clippy_lints/src/lifetimes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index ffef84d1fade..f5636945f203 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -176,7 +176,7 @@ fn check_fn_inner<'tcx>( _ => None, }); for bound in lifetimes { - if !bound.is_static() && !bound.is_elided() { + if bound.res != LifetimeName::Static && !bound.is_elided() { return; } } From c7d0ea7e98ca1204a99553e15e7934ff6008c036 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Wed, 7 Feb 2024 10:26:00 -0500 Subject: [PATCH 1067/1222] Add a new debug_assertions instrinsic (compiler) And in clippy --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 81f4fcc2133d..8d5bcd665ad2 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -174,7 +174,7 @@ fn check_rvalue<'tcx>( )) } }, - Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_), _) | Rvalue::ShallowInitBox(_, _) => { + Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_) | NullOp::DebugAssertions, _) | Rvalue::ShallowInitBox(_, _) => { Ok(()) }, Rvalue::UnaryOp(_, operand) => { From 750b8ec4b2712a014cb3d81be30e1252e6122d5b Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 9 Feb 2024 23:58:36 +0300 Subject: [PATCH 1068/1222] hir: Remove `hir::Map::{opt_parent_id,parent_id,get_parent,find_parent}` --- clippy_lints/src/assertions_on_constants.rs | 3 +- .../src/casts/cast_slice_different_sizes.rs | 31 ++++++++----------- clippy_lints/src/casts/unnecessary_cast.rs | 2 +- clippy_lints/src/dbg_macro.rs | 2 +- clippy_lints/src/default_numeric_fallback.rs | 3 +- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/escape.rs | 6 ++-- .../src/functions/impl_trait_in_params.rs | 4 +-- clippy_lints/src/ignored_unit_patterns.rs | 4 +-- clippy_lints/src/index_refutable_slice.rs | 11 ++----- clippy_lints/src/iter_without_into_iter.rs | 2 +- clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/loops/same_item_push.rs | 3 +- clippy_lints/src/manual_hash_one.rs | 6 ++-- clippy_lints/src/manual_rem_euclid.rs | 6 ++-- .../src/matches/match_single_binding.rs | 16 +++++----- clippy_lints/src/matches/redundant_guards.rs | 2 +- clippy_lints/src/methods/mod.rs | 2 +- .../src/methods/readonly_write_lock.rs | 4 +-- clippy_lints/src/methods/unnecessary_fold.rs | 2 +- .../src/methods/unnecessary_literal_unwrap.rs | 2 +- .../src/mixed_read_write_in_expression.rs | 3 +- clippy_lints/src/needless_pass_by_ref_mut.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/non_copy_const.rs | 2 +- .../src/operators/modulo_arithmetic.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- .../transmutes_expressible_as_ptr_casts.rs | 2 +- clippy_lints/src/tuple_array_conversions.rs | 9 ++---- clippy_lints/src/unit_types/unit_arg.rs | 8 ++--- clippy_lints/src/unnecessary_box_returns.rs | 2 +- clippy_lints/src/unnecessary_wraps.rs | 2 +- clippy_lints/src/unused_async.rs | 2 +- clippy_lints/src/unwrap.rs | 2 +- .../internal_lints/metadata_collector.rs | 6 ++-- .../internal_lints/unnecessary_def_path.rs | 3 +- clippy_lints/src/vec.rs | 4 +-- clippy_utils/src/lib.rs | 10 +++--- clippy_utils/src/ty/type_certainty/mod.rs | 2 +- 39 files changed, 78 insertions(+), 102 deletions(-) diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index 1e327f7a6dfb..9365fbfaed08 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -46,11 +46,10 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants { return; }; if let ConstantSource::Constant = source - && let Some(node) = cx.tcx.hir().find_parent(e.hir_id) && let Node::Item(Item { kind: ItemKind::Const(..), .. - }) = node + }) = cx.tcx.parent_hir_node(e.hir_id) { return; } diff --git a/clippy_lints/src/casts/cast_slice_different_sizes.rs b/clippy_lints/src/casts/cast_slice_different_sizes.rs index 0f29743856ac..a31943f00218 100644 --- a/clippy_lints/src/casts/cast_slice_different_sizes.rs +++ b/clippy_lints/src/casts/cast_slice_different_sizes.rs @@ -67,25 +67,20 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv } fn is_child_of_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - let map = cx.tcx.hir(); - if let Some(parent_id) = map.opt_parent_id(expr.hir_id) { - let parent = cx.tcx.hir_node(parent_id); - let expr = match parent { - Node::Block(block) => { - if let Some(parent_expr) = block.expr { - parent_expr - } else { - return false; - } - }, - Node::Expr(expr) => expr, - _ => return false, - }; + let parent = cx.tcx.parent_hir_node(expr.hir_id); + let expr = match parent { + Node::Block(block) => { + if let Some(parent_expr) = block.expr { + parent_expr + } else { + return false; + } + }, + Node::Expr(expr) => expr, + _ => return false, + }; - matches!(expr.kind, ExprKind::Cast(..)) - } else { - false - } + matches!(expr.kind, ExprKind::Cast(..)) } /// Returns the type T of the pointed to *const [T] or *mut [T] and the mutability of the slice if diff --git a/clippy_lints/src/casts/unnecessary_cast.rs b/clippy_lints/src/casts/unnecessary_cast.rs index 81d0def4322d..b4a23d0d4db4 100644 --- a/clippy_lints/src/casts/unnecessary_cast.rs +++ b/clippy_lints/src/casts/unnecessary_cast.rs @@ -65,7 +65,7 @@ pub(super) fn check<'tcx>( && let ExprKind::Path(qpath) = inner.kind && let QPath::Resolved(None, Path { res, .. }) = qpath && let Res::Local(hir_id) = res - && let parent = cx.tcx.hir().get_parent(*hir_id) + && let parent = cx.tcx.parent_hir_node(*hir_id) && let Node::Local(local) = parent { if let Some(ty) = local.ty diff --git a/clippy_lints/src/dbg_macro.rs b/clippy_lints/src/dbg_macro.rs index 9424a9103db8..ec66556cebff 100644 --- a/clippy_lints/src/dbg_macro.rs +++ b/clippy_lints/src/dbg_macro.rs @@ -63,7 +63,7 @@ impl LateLintPass<'_> for DbgMacro { ExprKind::Block(..) => { // If the `dbg!` macro is a "free" statement and not contained within other expressions, // remove the whole statement. - if let Some(Node::Stmt(_)) = cx.tcx.hir().find_parent(expr.hir_id) + if let Node::Stmt(_) = cx.tcx.parent_hir_node(expr.hir_id) && let Some(semi_span) = cx.sess().source_map().mac_call_stmt_semi_span(macro_call.span) { (macro_call.span.to(semi_span), String::new()) diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index c4437a3c4b33..59d2df0295fb 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -128,8 +128,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { }, _, ) => { - if let Some(parent) = self.cx.tcx.hir().find_parent(expr.hir_id) - && let Some(fn_sig) = parent.fn_sig() + if let Some(fn_sig) = self.cx.tcx.parent_hir_node(expr.hir_id).fn_sig() && let FnRetTy::Return(_ty) = fn_sig.decl.output { // We cannot check the exact type since it's a `hir::Ty`` which does not implement `is_numeric` diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 194cf69ea7ed..cdbb52f497b3 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1088,7 +1088,7 @@ fn report<'tcx>( // // e.g. `&mut x.y.z` where `x` is a union, and accessing `z` requires a // deref through `ManuallyDrop<_>` will not compile. - let parent_id = cx.tcx.hir().parent_id(expr.hir_id); + let parent_id = cx.tcx.parent_hir_id(expr.hir_id); if parent_id == data.first_expr.hir_id { return; } diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 218d7c6c01ae..064bac2e7dc7 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -131,7 +131,7 @@ fn is_argument(tcx: TyCtxt<'_>, id: HirId) -> bool { _ => return false, } - matches!(tcx.hir().find_parent(id), Some(Node::Param(_))) + matches!(tcx.parent_hir_node(id), Node::Param(_)) } impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { @@ -156,8 +156,8 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { let map = &self.cx.tcx.hir(); if is_argument(self.cx.tcx, cmt.hir_id) { // Skip closure arguments - let parent_id = map.parent_id(cmt.hir_id); - if let Some(Node::Expr(..)) = map.find_parent(parent_id) { + let parent_id = self.cx.tcx.parent_hir_id(cmt.hir_id); + if let Node::Expr(..) = self.cx.tcx.parent_hir_node(parent_id) { return; } diff --git a/clippy_lints/src/functions/impl_trait_in_params.rs b/clippy_lints/src/functions/impl_trait_in_params.rs index 8fba41c0e24d..6fb38a0d6dd8 100644 --- a/clippy_lints/src/functions/impl_trait_in_params.rs +++ b/clippy_lints/src/functions/impl_trait_in_params.rs @@ -53,7 +53,7 @@ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body: pub(super) fn check_impl_item(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) { if let ImplItemKind::Fn(_, body_id) = impl_item.kind - && let hir::Node::Item(item) = cx.tcx.hir().get_parent(impl_item.hir_id()) + && let hir::Node::Item(item) = cx.tcx.parent_hir_node(impl_item.hir_id()) && let hir::ItemKind::Impl(impl_) = item.kind && let hir::Impl { of_trait, .. } = *impl_ && of_trait.is_none() @@ -72,7 +72,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) { pub(super) fn check_trait_item(cx: &LateContext<'_>, trait_item: &TraitItem<'_>, avoid_breaking_exported_api: bool) { if !avoid_breaking_exported_api && let TraitItemKind::Fn(_, _) = trait_item.kind - && let hir::Node::Item(item) = cx.tcx.hir().get_parent(trait_item.hir_id()) + && let hir::Node::Item(item) = cx.tcx.parent_hir_node(trait_item.hir_id()) // ^^ (Will always be a trait) && !item.vis_span.is_empty() // Is public && !is_in_test_function(cx.tcx, trait_item.hir_id()) diff --git a/clippy_lints/src/ignored_unit_patterns.rs b/clippy_lints/src/ignored_unit_patterns.rs index 0a2fd0c663e5..80a537b9f941 100644 --- a/clippy_lints/src/ignored_unit_patterns.rs +++ b/clippy_lints/src/ignored_unit_patterns.rs @@ -41,8 +41,8 @@ impl<'tcx> LateLintPass<'tcx> for IgnoredUnitPatterns { return; } - match cx.tcx.hir().get_parent(pat.hir_id) { - Node::Param(param) if matches!(cx.tcx.hir().get_parent(param.hir_id), Node::Item(_)) => { + match cx.tcx.parent_hir_node(pat.hir_id) { + Node::Param(param) if matches!(cx.tcx.parent_hir_node(param.hir_id), Node::Item(_)) => { // Ignore function parameters return; }, diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index 252be30c4e27..51b4f26b6d13 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -242,12 +242,8 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> { } = *self; if let Some(use_info) = slice_lint_info.get_mut(&local_id) - // Check if this is even a local we're interested in - - && let map = cx.tcx.hir() - // Checking for slice indexing - && let parent_id = map.parent_id(expr.hir_id) + && let parent_id = cx.tcx.parent_hir_id(expr.hir_id) && let hir::Node::Expr(parent_expr) = cx.tcx.hir_node(parent_id) && let hir::ExprKind::Index(_, index_expr, _) = parent_expr.kind && let Some(Constant::Int(index_value)) = constant(cx, cx.typeck_results(), index_expr) @@ -255,11 +251,10 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> { && index_value < max_suggested_slice // Make sure that this slice index is read only - && let maybe_addrof_id = map.parent_id(parent_id) - && let hir::Node::Expr(maybe_addrof_expr) = cx.tcx.hir_node(maybe_addrof_id) + && let hir::Node::Expr(maybe_addrof_expr) = cx.tcx.parent_hir_node(parent_id) && let hir::ExprKind::AddrOf(_kind, hir::Mutability::Not, _inner_expr) = maybe_addrof_expr.kind { - use_info.index_use.push((index_value, map.span(parent_expr.hir_id))); + use_info.index_use.push((index_value, cx.tcx.hir().span(parent_expr.hir_id))); return; } diff --git a/clippy_lints/src/iter_without_into_iter.rs b/clippy_lints/src/iter_without_into_iter.rs index 82a37bb4f278..b5821d909f84 100644 --- a/clippy_lints/src/iter_without_into_iter.rs +++ b/clippy_lints/src/iter_without_into_iter.rs @@ -269,7 +269,7 @@ impl {self_ty_without_ref} {{ // } let span_behind_impl = cx .tcx - .def_span(cx.tcx.hir().parent_id(item.hir_id()).owner.def_id) + .def_span(cx.tcx.parent_hir_id(item.hir_id()).owner.def_id) .shrink_to_lo(); let sugg = format!( diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index f5636945f203..2b73663d229e 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -285,7 +285,7 @@ fn elision_suggestions( .iter() .filter(|usage| named_lifetime(usage).map_or(false, |id| elidable_lts.contains(&id))) .map(|usage| { - match cx.tcx.hir().get_parent(usage.hir_id) { + match cx.tcx.parent_hir_node(usage.hir_id) { Node::Ty(Ty { kind: TyKind::Ref(..), .. }) => { diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index 5f015db2b33b..0f35514b8ad6 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -62,8 +62,7 @@ pub(super) fn check<'tcx>( if let Node::Pat(pat) = node && let PatKind::Binding(bind_ann, ..) = pat.kind && !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut)) - && let parent_node = cx.tcx.hir().parent_id(hir_id) - && let Node::Local(parent_let_expr) = cx.tcx.hir_node(parent_node) + && let Node::Local(parent_let_expr) = cx.tcx.parent_hir_node(hir_id) && let Some(init) = parent_let_expr.init { match init.kind { diff --git a/clippy_lints/src/manual_hash_one.rs b/clippy_lints/src/manual_hash_one.rs index 73687fbbe54e..5cbab0ec977c 100644 --- a/clippy_lints/src/manual_hash_one.rs +++ b/clippy_lints/src/manual_hash_one.rs @@ -68,8 +68,8 @@ impl LateLintPass<'_> for ManualHashOne { && let ExprKind::MethodCall(seg, build_hasher, [], _) = init.kind && seg.ident.name == sym!(build_hasher) - && let Node::Stmt(local_stmt) = cx.tcx.hir().get_parent(local.hir_id) - && let Node::Block(block) = cx.tcx.hir().get_parent(local_stmt.hir_id) + && let Node::Stmt(local_stmt) = cx.tcx.parent_hir_node(local.hir_id) + && let Node::Block(block) = cx.tcx.parent_hir_node(local_stmt.hir_id) && let mut stmts = block.stmts.iter() .skip_while(|stmt| stmt.hir_id != local_stmt.hir_id) @@ -91,7 +91,7 @@ impl LateLintPass<'_> for ManualHashOne { // `hasher.finish()`, may be anywhere in a statement or the trailing expr of the block && let Some(path_expr) = local_used_once(cx, (maybe_finish_stmt, block.expr), hasher) - && let Node::Expr(finish_expr) = cx.tcx.hir().get_parent(path_expr.hir_id) + && let Node::Expr(finish_expr) = cx.tcx.parent_hir_node(path_expr.hir_id) && !finish_expr.span.from_expansion() && let ExprKind::MethodCall(seg, _, [], _) = finish_expr.kind && seg.ident.name == sym!(finish) diff --git a/clippy_lints/src/manual_rem_euclid.rs b/clippy_lints/src/manual_rem_euclid.rs index e1768c6d9764..0bde62bd5549 100644 --- a/clippy_lints/src/manual_rem_euclid.rs +++ b/clippy_lints/src/manual_rem_euclid.rs @@ -79,9 +79,9 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid { && let Node::Pat(_) = cx.tcx.hir_node(hir_id) { // Apply only to params or locals with annotated types - match cx.tcx.hir().find_parent(hir_id) { - Some(Node::Param(..)) => (), - Some(Node::Local(local)) => { + match cx.tcx.parent_hir_node(hir_id) { + Node::Param(..) => (), + Node::Local(local) => { let Some(ty) = local.ty else { return }; if matches!(ty.kind, TyKind::Infer) { return; diff --git a/clippy_lints/src/matches/match_single_binding.rs b/clippy_lints/src/matches/match_single_binding.rs index 89da7a55cbd5..61977045fd46 100644 --- a/clippy_lints/src/matches/match_single_binding.rs +++ b/clippy_lints/src/matches/match_single_binding.rs @@ -36,7 +36,7 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e .to_string(); // Do we need to add ';' to suggestion ? - if let Node::Stmt(stmt) = cx.tcx.hir().get_parent(expr.hir_id) + if let Node::Stmt(stmt) = cx.tcx.parent_hir_node(expr.hir_id) && let StmtKind::Expr(_) = stmt.kind && match match_body.kind { // We don't need to add a ; to blocks, unless that block is from a macro expansion @@ -146,18 +146,16 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e /// Returns true if the `ex` match expression is in a local (`let`) or assign expression fn opt_parent_assign_span<'a>(cx: &LateContext<'a>, ex: &Expr<'a>) -> Option { - let map = &cx.tcx.hir(); - - if let Some(Node::Expr(parent_arm_expr)) = map.find_parent(ex.hir_id) { - return match map.find_parent(parent_arm_expr.hir_id) { - Some(Node::Local(parent_let_expr)) => Some(AssignmentExpr::Local { + if let Node::Expr(parent_arm_expr) = cx.tcx.parent_hir_node(ex.hir_id) { + return match cx.tcx.parent_hir_node(parent_arm_expr.hir_id) { + Node::Local(parent_let_expr) => Some(AssignmentExpr::Local { span: parent_let_expr.span, pat_span: parent_let_expr.pat.span(), }), - Some(Node::Expr(Expr { + Node::Expr(Expr { kind: ExprKind::Assign(parent_assign_expr, match_expr, _), .. - })) => Some(AssignmentExpr::Assign { + }) => Some(AssignmentExpr::Assign { span: parent_assign_expr.span, match_span: match_expr.span, }), @@ -191,7 +189,7 @@ fn sugg_with_curlies<'a>( // If the parent is already an arm, and the body is another match statement, // we need curly braces around suggestion - if let Node::Arm(arm) = &cx.tcx.hir().get_parent(match_expr.hir_id) { + if let Node::Arm(arm) = &cx.tcx.parent_hir_node(match_expr.hir_id) { if let ExprKind::Match(..) = arm.body.kind { cbrace_end = format!("\n{indent}}}"); // Fix body indent due to the match diff --git a/clippy_lints/src/matches/redundant_guards.rs b/clippy_lints/src/matches/redundant_guards.rs index dfaaeb14ca3c..a1b82679f2e2 100644 --- a/clippy_lints/src/matches/redundant_guards.rs +++ b/clippy_lints/src/matches/redundant_guards.rs @@ -199,7 +199,7 @@ fn get_pat_binding<'tcx>( return span.map(|span| PatBindingInfo { span, byref_ident, - is_field: matches!(cx.tcx.hir().get_parent(local), Node::PatField(_)), + is_field: matches!(cx.tcx.parent_hir_node(local), Node::PatField(_)), }); } } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index e8a7a321bf4b..1452547807ba 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -4458,7 +4458,7 @@ impl Methods { _ => {}, }, ("drain", ..) => { - if let Node::Stmt(Stmt { hir_id: _, kind, .. }) = cx.tcx.hir().get_parent(expr.hir_id) + if let Node::Stmt(Stmt { hir_id: _, kind, .. }) = cx.tcx.parent_hir_node(expr.hir_id) && matches!(kind, StmtKind::Semi(_)) && args.len() <= 1 { diff --git a/clippy_lints/src/methods/readonly_write_lock.rs b/clippy_lints/src/methods/readonly_write_lock.rs index 1184dd4525a7..6c6846c4b476 100644 --- a/clippy_lints/src/methods/readonly_write_lock.rs +++ b/clippy_lints/src/methods/readonly_write_lock.rs @@ -21,9 +21,9 @@ fn is_unwrap_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, receiver: &Expr<'_>) { if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(receiver).peel_refs(), sym::RwLock) - && let Node::Expr(unwrap_call_expr) = cx.tcx.hir().get_parent(expr.hir_id) + && let Node::Expr(unwrap_call_expr) = cx.tcx.parent_hir_node(expr.hir_id) && is_unwrap_call(cx, unwrap_call_expr) - && let parent = cx.tcx.hir().get_parent(unwrap_call_expr.hir_id) + && let parent = cx.tcx.parent_hir_node(unwrap_call_expr.hir_id) && let Node::Local(local) = parent && let Some(mir) = enclosing_mir(cx.tcx, expr.hir_id) && let Some((local, _)) = mir diff --git a/clippy_lints/src/methods/unnecessary_fold.rs b/clippy_lints/src/methods/unnecessary_fold.rs index 2046692bbd0b..988f3e86fcf0 100644 --- a/clippy_lints/src/methods/unnecessary_fold.rs +++ b/clippy_lints/src/methods/unnecessary_fold.rs @@ -16,7 +16,7 @@ use super::UNNECESSARY_FOLD; /// Changing `fold` to `sum` needs it sometimes when the return type can't be /// inferred. This checks for some common cases where it can be safely omitted fn needs_turbofish(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { - let parent = cx.tcx.hir().get_parent(expr.hir_id); + let parent = cx.tcx.parent_hir_node(expr.hir_id); // some common cases where turbofish isn't needed: // - assigned to a local variable with a type annotation diff --git a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs index a1125d70db39..1b2bfbf4090e 100644 --- a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs +++ b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs @@ -76,7 +76,7 @@ pub(super) fn check( (expr.span.with_lo(call_args[0].span.hi()), String::new()), ]; // try to also remove the unsafe block if present - if let hir::Node::Block(block) = cx.tcx.hir().get_parent(expr.hir_id) + if let hir::Node::Block(block) = cx.tcx.parent_hir_node(expr.hir_id) && let hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::UserProvided) = block.rules { suggs.extend([ diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs index b593e48ae2e1..a1f7dc7b38c4 100644 --- a/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/clippy_lints/src/mixed_read_write_in_expression.rs @@ -206,10 +206,9 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { /// /// When such a read is found, the lint is triggered. fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) { - let map = &vis.cx.tcx.hir(); let mut cur_id = vis.write_expr.hir_id; loop { - let parent_id = map.parent_id(cur_id); + let parent_id = vis.cx.tcx.parent_hir_id(cur_id); if parent_id == cur_id { break; } diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index d2eef6ae4338..149d440ecac4 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -161,7 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { }; // Exclude non-inherent impls - if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) { + if let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) { if matches!( item.kind, ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 2c5c3dcaa752..384a402ce5b0 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -100,7 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { } // Exclude non-inherent impls - if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) { + if let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) { if matches!( item.kind, ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 10ab380ba1bc..ea73d9afa2ea 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -449,7 +449,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { let mut dereferenced_expr = expr; let mut needs_check_adjustment = true; loop { - let parent_id = cx.tcx.hir().parent_id(cur_expr.hir_id); + let parent_id = cx.tcx.parent_hir_id(cur_expr.hir_id); if parent_id == cur_expr.hir_id { break; } diff --git a/clippy_lints/src/operators/modulo_arithmetic.rs b/clippy_lints/src/operators/modulo_arithmetic.rs index 40d4a842befb..2a933a11e12c 100644 --- a/clippy_lints/src/operators/modulo_arithmetic.rs +++ b/clippy_lints/src/operators/modulo_arithmetic.rs @@ -34,7 +34,7 @@ pub(super) fn check<'tcx>( } fn used_in_comparison_with_zero(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - let Some(Node::Expr(parent_expr)) = cx.tcx.hir().find_parent(expr.hir_id) else { + let Node::Expr(parent_expr) = cx.tcx.parent_hir_node(expr.hir_id) else { return false; }; let ExprKind::Binary(op, lhs, rhs) = parent_expr.kind else { diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 57d37067e8f9..ec03ab0e41ab 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -301,7 +301,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { } // Exclude non-inherent impls - if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) { + if let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) { if matches!( item.kind, ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) diff --git a/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs b/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs index 513a913f56ad..bbecc39a8130 100644 --- a/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs +++ b/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs @@ -41,7 +41,7 @@ pub(super) fn check<'tcx>( _ => return false, }; - if let Node::Expr(parent) = cx.tcx.hir().get_parent(e.hir_id) + if let Node::Expr(parent) = cx.tcx.parent_hir_node(e.hir_id) && parent.precedence().order() > ExprPrecedence::Cast.order() { sugg = format!("({sugg})"); diff --git a/clippy_lints/src/tuple_array_conversions.rs b/clippy_lints/src/tuple_array_conversions.rs index e1cd82e18d56..c11504cd2d4f 100644 --- a/clippy_lints/src/tuple_array_conversions.rs +++ b/clippy_lints/src/tuple_array_conversions.rs @@ -153,13 +153,10 @@ fn all_bindings_are_for_conv<'tcx>( let Some(locals) = locals.iter().map(|e| path_to_local(e)).collect::>>() else { return false; }; - let Some(local_parents) = locals + let local_parents = locals .iter() - .map(|&l| cx.tcx.hir().find_parent(l)) - .collect::>>() - else { - return false; - }; + .map(|l| cx.tcx.parent_hir_node(*l)) + .collect::>(); local_parents .iter() diff --git a/clippy_lints/src/unit_types/unit_arg.rs b/clippy_lints/src/unit_types/unit_arg.rs index 44cff78a7936..eba7fa7b993c 100644 --- a/clippy_lints/src/unit_types/unit_arg.rs +++ b/clippy_lints/src/unit_types/unit_arg.rs @@ -19,9 +19,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if is_questionmark_desugar_marked_call(expr) { return; } - let map = &cx.tcx.hir(); - let opt_parent_node = map.find_parent(expr.hir_id); - if let Some(hir::Node::Expr(parent_expr)) = opt_parent_node + if let hir::Node::Expr(parent_expr) = cx.tcx.parent_hir_node(expr.hir_id) && is_questionmark_desugar_marked_call(parent_expr) { return; @@ -183,8 +181,8 @@ fn fmt_stmts_and_call( let mut stmts_and_call_snippet = stmts_and_call.join(&format!("{}{}", ";\n", " ".repeat(call_expr_indent))); // expr is not in a block statement or result expression position, wrap in a block - let parent_node = cx.tcx.hir().find_parent(call_expr.hir_id); - if !matches!(parent_node, Some(Node::Block(_))) && !matches!(parent_node, Some(Node::Stmt(_))) { + let parent_node = cx.tcx.parent_hir_node(call_expr.hir_id); + if !matches!(parent_node, Node::Block(_)) && !matches!(parent_node, Node::Stmt(_)) { let block_indent = call_expr_indent + 4; stmts_and_call_snippet = reindent_multiline(stmts_and_call_snippet.into(), true, Some(block_indent)).into_owned(); diff --git a/clippy_lints/src/unnecessary_box_returns.rs b/clippy_lints/src/unnecessary_box_returns.rs index f5af540fa148..c332cf076ae7 100644 --- a/clippy_lints/src/unnecessary_box_returns.rs +++ b/clippy_lints/src/unnecessary_box_returns.rs @@ -116,7 +116,7 @@ impl LateLintPass<'_> for UnnecessaryBoxReturns { fn check_impl_item(&mut self, cx: &LateContext<'_>, item: &rustc_hir::ImplItem<'_>) { // Ignore implementations of traits, because the lint should be on the // trait, not on the implementation of it. - let Node::Item(parent) = cx.tcx.hir().get_parent(item.hir_id()) else { + let Node::Item(parent) = cx.tcx.parent_hir_node(item.hir_id()) else { return; }; let ItemKind::Impl(parent) = parent.kind else { return }; diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index 446160f8e0fd..9c8b0ae17276 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { // Abort if the method is implementing a trait or of it a trait method. let hir_id = cx.tcx.local_def_id_to_hir_id(def_id); - if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) { + if let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) { if matches!( item.kind, ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index 1d42375ba8e5..738fba54fa83 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -156,7 +156,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync { && let Some(local_def_id) = def_id.as_local() && cx.tcx.def_kind(def_id) == DefKind::Fn && cx.tcx.asyncness(def_id).is_async() - && !is_node_func_call(cx.tcx.hir().get_parent(hir_id), path.span) + && !is_node_func_call(cx.tcx.parent_hir_node(hir_id), path.span) { self.async_fns_as_value.insert(local_def_id); } diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index ae2ac38cffe1..f2eb774b5cbf 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -208,7 +208,7 @@ struct MutationVisitor<'tcx> { /// (i.e. the `x` in `x.as_mut()`), and that is the reason for why we care about its parent /// expression: that will be where the actual method call is. fn is_option_as_mut_use(tcx: TyCtxt<'_>, expr_id: HirId) -> bool { - if let Node::Expr(mutating_expr) = tcx.hir().get_parent(expr_id) + if let Node::Expr(mutating_expr) = tcx.parent_hir_node(expr_id) && let ExprKind::MethodCall(path, ..) = mutating_expr.kind { path.ident.name.as_str() == "as_mut" diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index fae1b90ace21..349e0e3e077a 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -1007,9 +1007,9 @@ fn get_parent_local<'hir>(cx: &LateContext<'hir>, expr: &'hir hir::Expr<'hir>) - fn get_parent_local_hir_id<'hir>(cx: &LateContext<'hir>, hir_id: hir::HirId) -> Option<&'hir hir::Local<'hir>> { let map = cx.tcx.hir(); - match map.find_parent(hir_id) { - Some(hir::Node::Local(local)) => Some(local), - Some(hir::Node::Pat(pattern)) => get_parent_local_hir_id(cx, pattern.hir_id), + match cx.tcx.parent_hir_node(hir_id) { + hir::Node::Local(local) => Some(local), + hir::Node::Pat(pattern) => get_parent_local_hir_id(cx, pattern.hir_id), _ => None, } } diff --git a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs index 6e449dc98063..38c832931fc6 100644 --- a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs +++ b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs @@ -217,8 +217,7 @@ fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option match cx.qpath_res(qpath, expr.hir_id) { Res::Local(hir_id) => { - let parent_id = cx.tcx.hir().parent_id(hir_id); - if let Node::Local(Local { init: Some(init), .. }) = cx.tcx.hir_node(parent_id) { + if let Node::Local(Local { init: Some(init), .. }) = cx.tcx.parent_hir_node(hir_id) { path_to_matched_type(cx, init) } else { None diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index 2c33c93412a3..b3489142558e 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec { if let Some(vec_args) = higher::VecArgs::hir(cx, expr.peel_borrows()) { // search for `let foo = vec![_]` expressions where all uses of `foo` // adjust to slices or call a method that exist on slices (e.g. len) - if let Node::Local(local) = cx.tcx.hir().get_parent(expr.hir_id) + if let Node::Local(local) = cx.tcx.parent_hir_node(expr.hir_id) // for now ignore locals with type annotations. // this is to avoid compile errors when doing the suggestion here: let _: Vec<_> = vec![..]; && local.ty.is_none() @@ -103,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec { } // if the local pattern has a specified type, do not lint. else if let Some(_) = higher::VecArgs::hir(cx, expr) - && let Node::Local(local) = cx.tcx.hir().get_parent(expr.hir_id) + && let Node::Local(local) = cx.tcx.parent_hir_node(expr.hir_id) && local.ty.is_some() { let span = expr.span.ctxt().outer_expn_data().call_site; diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 6a33e11be465..67a18caca0e2 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -182,11 +182,9 @@ pub fn expr_or_init<'a, 'b, 'tcx: 'b>(cx: &LateContext<'tcx>, mut expr: &'a Expr /// Note: If you have an expression that references a binding `x`, use `path_to_local` to get the /// canonical binding `HirId`. pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<'tcx>> { - let hir = cx.tcx.hir(); if let Node::Pat(pat) = cx.tcx.hir_node(hir_id) && matches!(pat.kind, PatKind::Binding(BindingAnnotation::NONE, ..)) - && let parent = hir.parent_id(hir_id) - && let Node::Local(local) = cx.tcx.hir_node(parent) + && let Node::Local(local) = cx.tcx.parent_hir_node(hir_id) { return local.init; } @@ -333,7 +331,7 @@ pub fn is_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, diag_item: Symbol) /// Checks if the `def_id` belongs to a function that is part of a trait impl. pub fn is_def_id_trait_method(cx: &LateContext<'_>, def_id: LocalDefId) -> bool { if let Some(hir_id) = cx.tcx.opt_local_def_id_to_hir_id(def_id) - && let Node::Item(item) = cx.tcx.hir().get_parent(hir_id) + && let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) && let ItemKind::Impl(imp) = item.kind { imp.of_trait.is_some() @@ -1311,7 +1309,7 @@ pub fn contains_return<'tcx>(expr: impl Visitable<'tcx>) -> bool { /// Gets the parent node, if any. pub fn get_parent_node(tcx: TyCtxt<'_>, id: HirId) -> Option> { - tcx.hir().find_parent(id) + Some(tcx.parent_hir_node(id)) } /// Gets the parent expression, if any –- this is useful to constrain a lint. @@ -2227,7 +2225,7 @@ pub fn is_no_core_crate(cx: &LateContext<'_>) -> bool { /// } /// ``` pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool { - if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) { + if let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) { matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) } else { false diff --git a/clippy_utils/src/ty/type_certainty/mod.rs b/clippy_utils/src/ty/type_certainty/mod.rs index adca2ca1c3ef..7913926928f2 100644 --- a/clippy_utils/src/ty/type_certainty/mod.rs +++ b/clippy_utils/src/ty/type_certainty/mod.rs @@ -237,7 +237,7 @@ fn path_segment_certainty( }, // `get_parent` because `hir_id` refers to a `Pat`, and we're interested in the node containing the `Pat`. - Res::Local(hir_id) => match cx.tcx.hir().get_parent(hir_id) { + Res::Local(hir_id) => match cx.tcx.parent_hir_node(hir_id) { // An argument's type is always certain. Node::Param(..) => Certainty::Certain(None), // A local's type is certain if its type annotation is certain or it has an initializer whose From 67f4e06af25639f0348749a5b1dfc66d9e6cc825 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 11 Feb 2024 21:36:12 +0000 Subject: [PATCH 1069/1222] is_closure_like --- clippy_lints/src/redundant_locals.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/redundant_locals.rs b/clippy_lints/src/redundant_locals.rs index 700a5dd4a851..6528a7b369f7 100644 --- a/clippy_lints/src/redundant_locals.rs +++ b/clippy_lints/src/redundant_locals.rs @@ -101,7 +101,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals { fn is_by_value_closure_capture(cx: &LateContext<'_>, redefinition: HirId, root_variable: HirId) -> bool { let closure_def_id = cx.tcx.hir().enclosing_body_owner(redefinition); - cx.tcx.is_closure_or_coroutine(closure_def_id.to_def_id()) + cx.tcx.is_closure_like(closure_def_id.to_def_id()) && cx.tcx.closure_captures(closure_def_id).iter().any(|c| { matches!(c.info.capture_kind, UpvarCapture::ByValue) && matches!(c.place.base, PlaceBase::Upvar(upvar) if upvar.var_path.hir_id == root_variable) From 2514dce109c222f73f8f3f6e587c81331c48055e Mon Sep 17 00:00:00 2001 From: Frank King Date: Thu, 4 Jan 2024 21:53:06 +0800 Subject: [PATCH 1070/1222] Lower anonymous structs or unions to HIR --- clippy_lints/src/dereference.rs | 1 + clippy_utils/src/hir_utils.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index cdbb52f497b3..0ddfeaa0ae05 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -831,6 +831,7 @@ impl TyCoercionStability { | TyKind::Typeof(..) | TyKind::TraitObject(..) | TyKind::InferDelegation(..) + | TyKind::AnonAdt(..) | TyKind::Err(_) => Self::Reborrow, }; } diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 4fa93ad23c36..d50332e82da5 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -515,6 +515,7 @@ impl HirEqInterExpr<'_, '_, '_> { (TyKind::Path(l), TyKind::Path(r)) => self.eq_qpath(l, r), (&TyKind::Tup(l), &TyKind::Tup(r)) => over(l, r, |l, r| self.eq_ty(l, r)), (&TyKind::Infer, &TyKind::Infer) => true, + (TyKind::AnonAdt(l_item_id), TyKind::AnonAdt(r_item_id)) => l_item_id == r_item_id, _ => false, } } @@ -1108,7 +1109,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { TyKind::Typeof(anon_const) => { self.hash_body(anon_const.body); }, - TyKind::Err(_) | TyKind::Infer | TyKind::Never | TyKind::InferDelegation(..) => {}, + TyKind::Err(_) | TyKind::Infer | TyKind::Never | TyKind::InferDelegation(..) | TyKind::AnonAdt(_) => {}, } } From c6ac6be76ec805037ff871d386216f4fe8ec81a8 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 12 Feb 2024 15:26:59 +1100 Subject: [PATCH 1071/1222] Tweak delayed bug mentions. Now that we have both `delayed_bug` and `span_delayed_bug`, it makes sense to use the generic term "delayed bug" more. --- tests/integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration.rs b/tests/integration.rs index 267f095f9c20..7f4500826ff6 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -77,7 +77,7 @@ fn integration_test() { // the repo basically just contains a span_delayed_bug that forces rustc/clippy to panic: /* #![feature(rustc_attrs)] - #[rustc_error(span_delayed_bug_from_inside_query)] + #[rustc_error(delayed_bug_from_inside_query)] fn main() {} */ From 1daf3eb8c99c8034a10181e0f37f4e5c70820e36 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 30 Jan 2024 14:20:22 +0000 Subject: [PATCH 1072/1222] Make `is_intrinsic` query return the intrinsic name --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 8d5bcd665ad2..47195fcc17b4 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -335,7 +335,7 @@ fn check_terminator<'tcx>( // within const fns. `transmute` is allowed in all other const contexts. // This won't really scale to more intrinsics or functions. Let's allow const // transmutes in const fn before we add more hacks to this. - if tcx.is_intrinsic(fn_def_id) && tcx.item_name(fn_def_id) == sym::transmute { + if matches!(tcx.intrinsic(fn_def_id), Some(sym::transmute)) { return Err(( span, "can only call `transmute` from const items, not `const fn`".into(), From 92a1814e81314161db4251bed80a7f1d593a463a Mon Sep 17 00:00:00 2001 From: Urgau Date: Sun, 17 Dec 2023 17:28:24 +0100 Subject: [PATCH 1073/1222] Avoid UB in clippy transmute_ptr_to_ptr UI test --- tests/ui/transmute_ptr_to_ptr.fixed | 6 +++--- tests/ui/transmute_ptr_to_ptr.rs | 6 +++--- tests/ui/transmute_ptr_to_ptr.stderr | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/ui/transmute_ptr_to_ptr.fixed b/tests/ui/transmute_ptr_to_ptr.fixed index 4e145693c553..696def08f142 100644 --- a/tests/ui/transmute_ptr_to_ptr.fixed +++ b/tests/ui/transmute_ptr_to_ptr.fixed @@ -35,7 +35,7 @@ fn transmute_ptr_to_ptr() { // ref-ref transmutes; bad let _: &f32 = &*(&1u32 as *const u32 as *const f32); //~^ ERROR: transmute from a reference to a reference - let _: &f64 = &*(&1f32 as *const f32 as *const f64); + let _: &f32 = &*(&1f64 as *const f64 as *const f32); //~^ ERROR: transmute from a reference to a reference //:^ this test is here because both f32 and f64 are the same TypeVariant, but they are not // the same type @@ -43,8 +43,8 @@ fn transmute_ptr_to_ptr() { //~^ ERROR: transmute from a reference to a reference let _: &GenericParam = &*(&GenericParam { t: 1u32 } as *const GenericParam as *const GenericParam); //~^ ERROR: transmute from a reference to a reference - let u8_ref: &u8 = &0u8; - let u64_ref: &u64 = unsafe { &*(u8_ref as *const u8 as *const u64) }; + let u64_ref: &u64 = &0u64; + let u8_ref: &u8 = unsafe { &*(u64_ref as *const u64 as *const u8) }; //~^ ERROR: transmute from a reference to a reference } diff --git a/tests/ui/transmute_ptr_to_ptr.rs b/tests/ui/transmute_ptr_to_ptr.rs index 086aadc36474..0700d8c19576 100644 --- a/tests/ui/transmute_ptr_to_ptr.rs +++ b/tests/ui/transmute_ptr_to_ptr.rs @@ -35,7 +35,7 @@ fn transmute_ptr_to_ptr() { // ref-ref transmutes; bad let _: &f32 = std::mem::transmute(&1u32); //~^ ERROR: transmute from a reference to a reference - let _: &f64 = std::mem::transmute(&1f32); + let _: &f32 = std::mem::transmute(&1f64); //~^ ERROR: transmute from a reference to a reference //:^ this test is here because both f32 and f64 are the same TypeVariant, but they are not // the same type @@ -43,8 +43,8 @@ fn transmute_ptr_to_ptr() { //~^ ERROR: transmute from a reference to a reference let _: &GenericParam = std::mem::transmute(&GenericParam { t: 1u32 }); //~^ ERROR: transmute from a reference to a reference - let u8_ref: &u8 = &0u8; - let u64_ref: &u64 = unsafe { std::mem::transmute(u8_ref) }; + let u64_ref: &u64 = &0u64; + let u8_ref: &u8 = unsafe { std::mem::transmute(u64_ref) }; //~^ ERROR: transmute from a reference to a reference } diff --git a/tests/ui/transmute_ptr_to_ptr.stderr b/tests/ui/transmute_ptr_to_ptr.stderr index 9f8599921ec7..6e3af1f73371 100644 --- a/tests/ui/transmute_ptr_to_ptr.stderr +++ b/tests/ui/transmute_ptr_to_ptr.stderr @@ -22,8 +22,8 @@ LL | let _: &f32 = std::mem::transmute(&1u32); error: transmute from a reference to a reference --> $DIR/transmute_ptr_to_ptr.rs:38:23 | -LL | let _: &f64 = std::mem::transmute(&1f32); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&1f32 as *const f32 as *const f64)` +LL | let _: &f32 = std::mem::transmute(&1f64); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&1f64 as *const f64 as *const f32)` error: transmute from a reference to a reference --> $DIR/transmute_ptr_to_ptr.rs:42:27 @@ -38,10 +38,10 @@ LL | let _: &GenericParam = std::mem::transmute(&GenericParam { t: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&GenericParam { t: 1u32 } as *const GenericParam as *const GenericParam)` error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:47:38 + --> $DIR/transmute_ptr_to_ptr.rs:47:36 | -LL | let u64_ref: &u64 = unsafe { std::mem::transmute(u8_ref) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(u8_ref as *const u8 as *const u64)` +LL | let u8_ref: &u8 = unsafe { std::mem::transmute(u64_ref) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(u64_ref as *const u64 as *const u8)` error: aborting due to 7 previous errors From 452b32d32d1483215ccb87c5de620b36c44b6426 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Sun, 28 Jan 2024 20:53:28 +0000 Subject: [PATCH 1074/1222] Bump `indexmap` `swap` has been deprecated in favour of `swap_remove` - the behaviour is the same though. --- clippy_lints/src/copies.rs | 3 ++- clippy_lints/src/escape.rs | 6 ++++-- clippy_lints/src/index_refutable_slice.rs | 6 ++++-- clippy_lints/src/matches/match_same_arms.rs | 3 ++- clippy_lints/src/needless_pass_by_ref_mut.rs | 3 ++- clippy_lints/src/no_effect.rs | 6 ++++-- clippy_lints/src/only_used_in_recursion.rs | 3 ++- 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index bd07c19a2d81..247048bbc49d 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -511,7 +511,8 @@ fn scan_block_for_eq<'tcx>( for stmt in &stmts[stmts.len() - init..=stmts.len() - offset] { if let StmtKind::Local(l) = stmt.kind { l.pat.each_binding_or_first(&mut |_, id, _, _| { - eq.locals.remove(&id); + // FIXME(rust/#120456) - is `swap_remove` correct? + eq.locals.swap_remove(&id); }); } } diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 064bac2e7dc7..8857cb8e3827 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -138,7 +138,8 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { fn consume(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) { if cmt.place.projections.is_empty() { if let PlaceBase::Local(lid) = cmt.place.base { - self.set.remove(&lid); + // FIXME(rust/#120456) - is `swap_remove` correct? + self.set.swap_remove(&lid); } } } @@ -146,7 +147,8 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) { if cmt.place.projections.is_empty() { if let PlaceBase::Local(lid) = cmt.place.base { - self.set.remove(&lid); + // FIXME(rust/#120456) - is `swap_remove` correct? + self.set.swap_remove(&lid); } } } diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index 51b4f26b6d13..41e9d5b1c2e9 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -106,7 +106,8 @@ fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> { } // The slice was used for something other than indexing - self.slice_lint_info.remove(&local_id); + // FIXME(rust/#120456) - is `swap_remove` correct? + self.slice_lint_info.swap_remove(&local_id); } intravisit::walk_expr(self, expr); } diff --git a/clippy_lints/src/matches/match_same_arms.rs b/clippy_lints/src/matches/match_same_arms.rs index d645e6c6c05c..6595658b7692 100644 --- a/clippy_lints/src/matches/match_same_arms.rs +++ b/clippy_lints/src/matches/match_same_arms.rs @@ -415,6 +415,7 @@ fn pat_contains_local(pat: &Pat<'_>, id: HirId) -> bool { /// Returns true if all the bindings in the `Pat` are in `ids` and vice versa fn bindings_eq(pat: &Pat<'_>, mut ids: HirIdSet) -> bool { let mut result = true; - pat.each_binding_or_first(&mut |_, id, _, _| result &= ids.remove(&id)); + // FIXME(rust/#120456) - is `swap_remove` correct? + pat.each_binding_or_first(&mut |_, id, _, _| result &= ids.swap_remove(&id)); result && ids.is_empty() } diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index 149d440ecac4..710ecd745f8d 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -382,7 +382,8 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt<'tcx> { self.add_mutably_used_var(*vid); } self.prev_bind = None; - self.prev_move_to_closure.remove(vid); + // FIXME(rust/#120456) - is `swap_remove` correct? + self.prev_move_to_closure.swap_remove(vid); } } diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 580160efeb70..6a5555ca3836 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -98,7 +98,8 @@ impl<'tcx> LateLintPass<'tcx> for NoEffect { fn check_block_post(&mut self, cx: &LateContext<'tcx>, _: &'tcx rustc_hir::Block<'tcx>) { for hir_id in self.local_bindings.pop().unwrap() { - if let Some(span) = self.underscore_bindings.remove(&hir_id) { + // FIXME(rust/#120456) - is `swap_remove` correct? + if let Some(span) = self.underscore_bindings.swap_remove(&hir_id) { span_lint_hir( cx, NO_EFFECT_UNDERSCORE_BINDING, @@ -112,7 +113,8 @@ impl<'tcx> LateLintPass<'tcx> for NoEffect { fn check_expr(&mut self, _: &LateContext<'tcx>, expr: &'tcx rustc_hir::Expr<'tcx>) { if let Some(def_id) = path_to_local(expr) { - self.underscore_bindings.remove(&def_id); + // FIXME(rust/#120456) - is `swap_remove` correct? + self.underscore_bindings.swap_remove(&def_id); } } } diff --git a/clippy_lints/src/only_used_in_recursion.rs b/clippy_lints/src/only_used_in_recursion.rs index ae14016f4823..a568392ecc45 100644 --- a/clippy_lints/src/only_used_in_recursion.rs +++ b/clippy_lints/src/only_used_in_recursion.rs @@ -153,7 +153,8 @@ impl Params { param.uses = Vec::new(); let key = (param.fn_id, param.idx); self.by_fn.remove(&key); - self.by_id.remove(&id); + // FIXME(rust/#120456) - is `swap_remove` correct? + self.by_id.swap_remove(&id); } } From 7e924b49733766b4ca8edcad0d0817dad0b65235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 14 Feb 2024 19:18:28 +0000 Subject: [PATCH 1075/1222] Fix msg for verbose suggestions with confusable capitalization When encountering a verbose/multipart suggestion that has changes that are only caused by different capitalization of ASCII letters that have little differenciation, expand the message to highlight that fact (like we already do for inline suggestions). The logic to do this was already present, but implemented incorrectly. --- tests/ui/match_str_case_mismatch.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/match_str_case_mismatch.stderr b/tests/ui/match_str_case_mismatch.stderr index f799a4698b94..b178fb7512cd 100644 --- a/tests/ui/match_str_case_mismatch.stderr +++ b/tests/ui/match_str_case_mismatch.stderr @@ -17,7 +17,7 @@ error: this `match` arm has a differing case than its expression LL | "~!@#$%^&*()-_=+Foo" => {}, | ^^^^^^^^^^^^^^^^^^^^ | -help: consider changing the case of this arm to respect `to_ascii_lowercase` +help: consider changing the case of this arm to respect `to_ascii_lowercase` (notice the capitalization difference) | LL | "~!@#$%^&*()-_=+foo" => {}, | ~~~~~~~~~~~~~~~~~~~~ From 697b10e5b7eb45169d31c3b427e2e01469a2a32a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 14 Feb 2024 14:50:49 +1100 Subject: [PATCH 1076/1222] Add an `ErrorGuaranteed` to `ast::TyKind::Err`. This makes it more like `hir::TyKind::Err`, and avoids a `span_delayed_bug` call in `LoweringContext::lower_ty_direct`. It also requires adding `ast::TyKind::Dummy`, now that `ast::TyKind::Err` can't be used for that purpose in the absence of an error emission. There are a couple of cases that aren't as neat as I would have liked, marked with `FIXME` comments. --- clippy_utils/src/ast_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index adc35bd82ae3..0467a8a65709 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -690,7 +690,7 @@ pub fn eq_ty(l: &Ty, r: &Ty) -> bool { match (&l.kind, &r.kind) { (Paren(l), _) => eq_ty(l, r), (_, Paren(r)) => eq_ty(l, r), - (Never, Never) | (Infer, Infer) | (ImplicitSelf, ImplicitSelf) | (Err, Err) | (CVarArgs, CVarArgs) => true, + (Never, Never) | (Infer, Infer) | (ImplicitSelf, ImplicitSelf) | (Err(_), Err(_)) | (CVarArgs, CVarArgs) => true, (Slice(l), Slice(r)) => eq_ty(l, r), (Array(le, ls), Array(re, rs)) => eq_ty(le, re) && eq_expr(&ls.value, &rs.value), (Ptr(l), Ptr(r)) => l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty), From 7fa141d18dfa880d997437b18e5e72d83949ec2a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 14 Feb 2024 20:12:05 +1100 Subject: [PATCH 1077/1222] Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`. This mostly works well, and eliminates a couple of delayed bugs. One annoying thing is that we should really also add an `ErrorGuaranteed` to `proc_macro::bridge::LitKind::Err`. But that's difficult because `proc_macro` doesn't have access to `ErrorGuaranteed`, so we have to fake it. --- clippy_lints/src/matches/match_same_arms.rs | 3 ++- clippy_lints/src/redundant_type_annotations.rs | 2 +- clippy_lints/src/utils/author.rs | 2 +- clippy_utils/src/consts.rs | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/matches/match_same_arms.rs b/clippy_lints/src/matches/match_same_arms.rs index 6595658b7692..b8f7d9668201 100644 --- a/clippy_lints/src/matches/match_same_arms.rs +++ b/clippy_lints/src/matches/match_same_arms.rs @@ -295,7 +295,8 @@ impl<'a> NormalizedPat<'a> { LitKind::Char(val) => Self::LitInt(val.into()), LitKind::Int(val, _) => Self::LitInt(val.get()), LitKind::Bool(val) => Self::LitBool(val), - LitKind::Float(..) | LitKind::Err => Self::Wild, + LitKind::Float(..) => Self::Wild, + LitKind::Err(guar) => Self::Err(guar), }, _ => Self::Wild, }, diff --git a/clippy_lints/src/redundant_type_annotations.rs b/clippy_lints/src/redundant_type_annotations.rs index c8352c052659..079e6500e3cf 100644 --- a/clippy_lints/src/redundant_type_annotations.rs +++ b/clippy_lints/src/redundant_type_annotations.rs @@ -200,7 +200,7 @@ impl LateLintPass<'_> for RedundantTypeAnnotations { span_lint(cx, REDUNDANT_TYPE_ANNOTATIONS, local.span, "redundant type annotation"); } }, - LitKind::Err => (), + LitKind::Err(_) => (), LitKind::ByteStr(..) => { // We only lint if the type annotation is an array type (e.g. &[u8; 4]). // If instead it is a slice (e.g. &[u8]) it may not be redundant, so we diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 29c67341a467..a0a6382046d0 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -279,7 +279,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { match lit.value.node { LitKind::Bool(val) => kind!("Bool({val:?})"), LitKind::Char(c) => kind!("Char({c:?})"), - LitKind::Err => kind!("Err"), + LitKind::Err(_) => kind!("Err"), LitKind::Byte(b) => kind!("Byte({b})"), LitKind::Int(i, suffix) => { let int_ty = match suffix { diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 61b38391d9e0..79c691992a85 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -286,7 +286,7 @@ pub fn lit_to_mir_constant<'tcx>(lit: &LitKind, ty: Option>) -> Constan _ => bug!(), }, LitKind::Bool(b) => Constant::Bool(b), - LitKind::Err => Constant::Err, + LitKind::Err(_) => Constant::Err, } } From 3d87ab8eabcdf84bd9a421586a85346906db1cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 17 Feb 2024 12:46:18 +0100 Subject: [PATCH 1078/1222] remove a couple of redundant clones --- clippy_utils/src/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs index 56978eb2ee80..5199959c0f2b 100644 --- a/clippy_utils/src/diagnostics.rs +++ b/clippy_utils/src/diagnostics.rs @@ -84,9 +84,9 @@ pub fn span_lint_and_help( cx.span_lint(lint, span, msg.to_string(), |diag| { let help = help.to_string(); if let Some(help_span) = help_span { - diag.span_help(help_span, help.to_string()); + diag.span_help(help_span, help); } else { - diag.help(help.to_string()); + diag.help(help); } docs_link(diag, lint); }); From 00c948e01c612d46389162447f4dbffef99fe199 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 26 Jan 2024 18:48:18 +0100 Subject: [PATCH 1079/1222] Allow newly added non_local_definitions lint in clippy --- .../undocumented_unsafe_blocks.rs | 2 +- tests/ui/bool_comparison.fixed | 2 +- tests/ui/bool_comparison.rs | 2 +- tests/ui/crashes/ice-4760.rs | 2 + tests/ui/crashes/ice-6179.rs | 1 + tests/ui/explicit_into_iter_loop.fixed | 1 + tests/ui/explicit_into_iter_loop.rs | 1 + tests/ui/explicit_into_iter_loop.stderr | 12 ++--- tests/ui/explicit_iter_loop.fixed | 3 +- tests/ui/explicit_iter_loop.rs | 3 +- tests/ui/explicit_iter_loop.stderr | 36 ++++++------- tests/ui/from_over_into.fixed | 1 + tests/ui/from_over_into.rs | 1 + tests/ui/from_over_into.stderr | 14 ++--- tests/ui/manual_str_repeat.fixed | 1 + tests/ui/manual_str_repeat.rs | 1 + tests/ui/manual_str_repeat.stderr | 20 +++---- tests/ui/needless_borrow.fixed | 1 + tests/ui/needless_borrow.rs | 1 + tests/ui/needless_borrow.stderr | 54 +++++++++---------- 20 files changed, 86 insertions(+), 73 deletions(-) diff --git a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs index a27813987606..8997073c8a55 100644 --- a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs +++ b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs @@ -4,7 +4,7 @@ //@[disabled] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/undocumented_unsafe_blocks/disabled #![warn(clippy::undocumented_unsafe_blocks, clippy::unnecessary_safety_comment)] -#![allow(deref_nullptr, clippy::let_unit_value, clippy::missing_safety_doc)] +#![allow(deref_nullptr, non_local_definitions, clippy::let_unit_value, clippy::missing_safety_doc)] #![feature(lint_reasons)] extern crate proc_macro_unsafe; diff --git a/tests/ui/bool_comparison.fixed b/tests/ui/bool_comparison.fixed index 02f1d09b8339..600380fd1420 100644 --- a/tests/ui/bool_comparison.fixed +++ b/tests/ui/bool_comparison.fixed @@ -1,4 +1,4 @@ -#![allow(clippy::needless_if)] +#![allow(non_local_definitions, clippy::needless_if)] #![warn(clippy::bool_comparison)] #![allow(clippy::non_canonical_partial_ord_impl)] diff --git a/tests/ui/bool_comparison.rs b/tests/ui/bool_comparison.rs index 5ef696d855ec..910df6151f8c 100644 --- a/tests/ui/bool_comparison.rs +++ b/tests/ui/bool_comparison.rs @@ -1,4 +1,4 @@ -#![allow(clippy::needless_if)] +#![allow(non_local_definitions, clippy::needless_if)] #![warn(clippy::bool_comparison)] #![allow(clippy::non_canonical_partial_ord_impl)] diff --git a/tests/ui/crashes/ice-4760.rs b/tests/ui/crashes/ice-4760.rs index 08b06961760f..e1265169762f 100644 --- a/tests/ui/crashes/ice-4760.rs +++ b/tests/ui/crashes/ice-4760.rs @@ -1,3 +1,5 @@ +#![allow(non_local_definitions)] + const COUNT: usize = 2; struct Thing; trait Dummy {} diff --git a/tests/ui/crashes/ice-6179.rs b/tests/ui/crashes/ice-6179.rs index ce1895851e2d..fffc0f7d0d4f 100644 --- a/tests/ui/crashes/ice-6179.rs +++ b/tests/ui/crashes/ice-6179.rs @@ -3,6 +3,7 @@ #![warn(clippy::use_self)] #![allow(dead_code, clippy::let_with_type_underscore)] +#![allow(non_local_definitions)] struct Foo; diff --git a/tests/ui/explicit_into_iter_loop.fixed b/tests/ui/explicit_into_iter_loop.fixed index 2521bce6a58e..6d67488a7130 100644 --- a/tests/ui/explicit_into_iter_loop.fixed +++ b/tests/ui/explicit_into_iter_loop.fixed @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] #![warn(clippy::explicit_into_iter_loop)] fn main() { diff --git a/tests/ui/explicit_into_iter_loop.rs b/tests/ui/explicit_into_iter_loop.rs index 9eac96d182b9..14630c07c5cc 100644 --- a/tests/ui/explicit_into_iter_loop.rs +++ b/tests/ui/explicit_into_iter_loop.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] #![warn(clippy::explicit_into_iter_loop)] fn main() { diff --git a/tests/ui/explicit_into_iter_loop.stderr b/tests/ui/explicit_into_iter_loop.stderr index c03647ab4336..a1e632271ed3 100644 --- a/tests/ui/explicit_into_iter_loop.stderr +++ b/tests/ui/explicit_into_iter_loop.stderr @@ -1,5 +1,5 @@ error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:9:18 + --> $DIR/explicit_into_iter_loop.rs:10:18 | LL | for _ in iterator.into_iter() {} | ^^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `iterator` @@ -8,31 +8,31 @@ LL | for _ in iterator.into_iter() {} = help: to override `-D warnings` add `#[allow(clippy::explicit_into_iter_loop)]` error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:22:14 + --> $DIR/explicit_into_iter_loop.rs:23:14 | LL | for _ in t.into_iter() {} | ^^^^^^^^^^^^^ help: to write this more concisely, try: `&t` error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:25:14 + --> $DIR/explicit_into_iter_loop.rs:26:14 | LL | for _ in r.into_iter() {} | ^^^^^^^^^^^^^ help: to write this more concisely, try: `r` error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:33:14 + --> $DIR/explicit_into_iter_loop.rs:34:14 | LL | for _ in mr.into_iter() {} | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&*mr` error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:45:14 + --> $DIR/explicit_into_iter_loop.rs:46:14 | LL | for _ in u.into_iter() {} | ^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut u` error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:48:14 + --> $DIR/explicit_into_iter_loop.rs:49:14 | LL | for _ in mr.into_iter() {} | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut *mr` diff --git a/tests/ui/explicit_iter_loop.fixed b/tests/ui/explicit_iter_loop.fixed index f08397defa53..06229a52a18c 100644 --- a/tests/ui/explicit_iter_loop.fixed +++ b/tests/ui/explicit_iter_loop.fixed @@ -5,7 +5,8 @@ clippy::needless_borrow, clippy::deref_addrof, clippy::unnecessary_mut_passed, - dead_code + dead_code, + non_local_definitions, )] use core::slice; diff --git a/tests/ui/explicit_iter_loop.rs b/tests/ui/explicit_iter_loop.rs index 2ee6825d445c..c2bf45ab2e99 100644 --- a/tests/ui/explicit_iter_loop.rs +++ b/tests/ui/explicit_iter_loop.rs @@ -5,7 +5,8 @@ clippy::needless_borrow, clippy::deref_addrof, clippy::unnecessary_mut_passed, - dead_code + dead_code, + non_local_definitions, )] use core::slice; diff --git a/tests/ui/explicit_iter_loop.stderr b/tests/ui/explicit_iter_loop.stderr index 725d9b63cf8d..007606b52c29 100644 --- a/tests/ui/explicit_iter_loop.stderr +++ b/tests/ui/explicit_iter_loop.stderr @@ -1,5 +1,5 @@ error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:17:14 + --> $DIR/explicit_iter_loop.rs:18:14 | LL | for _ in vec.iter() {} | ^^^^^^^^^^ help: to write this more concisely, try: `&vec` @@ -11,103 +11,103 @@ LL | #![deny(clippy::explicit_iter_loop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:18:14 + --> $DIR/explicit_iter_loop.rs:19:14 | LL | for _ in vec.iter_mut() {} | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut vec` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:21:14 + --> $DIR/explicit_iter_loop.rs:22:14 | LL | for _ in rvec.iter() {} | ^^^^^^^^^^^ help: to write this more concisely, try: `rvec` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:30:14 + --> $DIR/explicit_iter_loop.rs:31:14 | LL | for _ in [1, 2, 3].iter() {} | ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[1, 2, 3]` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:34:14 + --> $DIR/explicit_iter_loop.rs:35:14 | LL | for _ in [0; 32].iter() {} | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:35:14 + --> $DIR/explicit_iter_loop.rs:36:14 | LL | for _ in [0; 33].iter() {} | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 33]` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:38:14 + --> $DIR/explicit_iter_loop.rs:39:14 | LL | for _ in ll.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&ll` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:40:14 + --> $DIR/explicit_iter_loop.rs:41:14 | LL | for _ in rll.iter() {} | ^^^^^^^^^^ help: to write this more concisely, try: `rll` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:43:14 + --> $DIR/explicit_iter_loop.rs:44:14 | LL | for _ in vd.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&vd` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:45:14 + --> $DIR/explicit_iter_loop.rs:46:14 | LL | for _ in rvd.iter() {} | ^^^^^^^^^^ help: to write this more concisely, try: `rvd` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:48:14 + --> $DIR/explicit_iter_loop.rs:49:14 | LL | for _ in bh.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&bh` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:51:14 + --> $DIR/explicit_iter_loop.rs:52:14 | LL | for _ in hm.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&hm` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:54:14 + --> $DIR/explicit_iter_loop.rs:55:14 | LL | for _ in bt.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&bt` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:57:14 + --> $DIR/explicit_iter_loop.rs:58:14 | LL | for _ in hs.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&hs` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:60:14 + --> $DIR/explicit_iter_loop.rs:61:14 | LL | for _ in bs.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&bs` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:149:14 + --> $DIR/explicit_iter_loop.rs:150:14 | LL | for _ in x.iter() {} | ^^^^^^^^ help: to write this more concisely, try: `&x` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:150:14 + --> $DIR/explicit_iter_loop.rs:151:14 | LL | for _ in x.iter_mut() {} | ^^^^^^^^^^^^ help: to write this more concisely, try: `&mut x` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:153:14 + --> $DIR/explicit_iter_loop.rs:154:14 | LL | for _ in r.iter() {} | ^^^^^^^^ help: to write this more concisely, try: `r` diff --git a/tests/ui/from_over_into.fixed b/tests/ui/from_over_into.fixed index 4a68505ee0b1..a33c1ea5738b 100644 --- a/tests/ui/from_over_into.fixed +++ b/tests/ui/from_over_into.fixed @@ -1,5 +1,6 @@ #![feature(type_alias_impl_trait)] #![warn(clippy::from_over_into)] +#![allow(non_local_definitions)] #![allow(unused)] // this should throw an error diff --git a/tests/ui/from_over_into.rs b/tests/ui/from_over_into.rs index bf3ed0c2b642..6cd811ae401e 100644 --- a/tests/ui/from_over_into.rs +++ b/tests/ui/from_over_into.rs @@ -1,5 +1,6 @@ #![feature(type_alias_impl_trait)] #![warn(clippy::from_over_into)] +#![allow(non_local_definitions)] #![allow(unused)] // this should throw an error diff --git a/tests/ui/from_over_into.stderr b/tests/ui/from_over_into.stderr index f1370ed844fa..15b4e02a264f 100644 --- a/tests/ui/from_over_into.stderr +++ b/tests/ui/from_over_into.stderr @@ -1,5 +1,5 @@ error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:8:1 + --> $DIR/from_over_into.rs:9:1 | LL | impl Into for String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -14,7 +14,7 @@ LL ~ StringWrapper(val) | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:16:1 + --> $DIR/from_over_into.rs:17:1 | LL | impl Into for String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL ~ SelfType(String::new()) | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:31:1 + --> $DIR/from_over_into.rs:32:1 | LL | impl Into for X { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -42,7 +42,7 @@ LL ~ let _: X = val; | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:43:1 + --> $DIR/from_over_into.rs:44:1 | LL | impl core::convert::Into for crate::ExplicitPaths { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL ~ val.0 | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:63:1 + --> $DIR/from_over_into.rs:64:1 | LL | impl Into for PathInExpansion { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -74,7 +74,7 @@ LL ~ fn from(val: PathInExpansion) -> Self { | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:85:5 + --> $DIR/from_over_into.rs:86:5 | LL | impl Into> for Vec { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -87,7 +87,7 @@ LL ~ FromOverInto(val) | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:95:5 + --> $DIR/from_over_into.rs:96:5 | LL | impl Into<()> for Hello { | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/manual_str_repeat.fixed b/tests/ui/manual_str_repeat.fixed index 888a466278cc..5f2f1bd9916d 100644 --- a/tests/ui/manual_str_repeat.fixed +++ b/tests/ui/manual_str_repeat.fixed @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] #![warn(clippy::manual_str_repeat)] use std::borrow::Cow; diff --git a/tests/ui/manual_str_repeat.rs b/tests/ui/manual_str_repeat.rs index a366351ffa45..3e3c7f4db4a2 100644 --- a/tests/ui/manual_str_repeat.rs +++ b/tests/ui/manual_str_repeat.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] #![warn(clippy::manual_str_repeat)] use std::borrow::Cow; diff --git a/tests/ui/manual_str_repeat.stderr b/tests/ui/manual_str_repeat.stderr index 9a13aa972273..6eb6f2b85a8f 100644 --- a/tests/ui/manual_str_repeat.stderr +++ b/tests/ui/manual_str_repeat.stderr @@ -1,5 +1,5 @@ error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:7:21 + --> $DIR/manual_str_repeat.rs:8:21 | LL | let _: String = std::iter::repeat("test").take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"test".repeat(10)` @@ -8,55 +8,55 @@ LL | let _: String = std::iter::repeat("test").take(10).collect(); = help: to override `-D warnings` add `#[allow(clippy::manual_str_repeat)]` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:8:21 + --> $DIR/manual_str_repeat.rs:9:21 | LL | let _: String = std::iter::repeat('x').take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"x".repeat(10)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:9:21 + --> $DIR/manual_str_repeat.rs:10:21 | LL | let _: String = std::iter::repeat('\'').take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"'".repeat(10)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:10:21 + --> $DIR/manual_str_repeat.rs:11:21 | LL | let _: String = std::iter::repeat('"').take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"\"".repeat(10)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:14:13 + --> $DIR/manual_str_repeat.rs:15:13 | LL | let _ = repeat(x).take(count + 2).collect::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count + 2)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:23:21 + --> $DIR/manual_str_repeat.rs:24:21 | LL | let _: String = repeat(*x).take(count).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(*x).repeat(count)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:32:21 + --> $DIR/manual_str_repeat.rs:33:21 | LL | let _: String = repeat(x).take(count).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:44:21 + --> $DIR/manual_str_repeat.rs:45:21 | LL | let _: String = repeat(Cow::Borrowed("test")).take(count).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Cow::Borrowed("test").repeat(count)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:47:21 + --> $DIR/manual_str_repeat.rs:48:21 | LL | let _: String = repeat(x).take(count).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:62:21 + --> $DIR/manual_str_repeat.rs:63:21 | LL | let _: String = std::iter::repeat("test").take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"test".repeat(10)` diff --git a/tests/ui/needless_borrow.fixed b/tests/ui/needless_borrow.fixed index 23e8bf8a468f..998f5430fdf0 100644 --- a/tests/ui/needless_borrow.fixed +++ b/tests/ui/needless_borrow.fixed @@ -1,6 +1,7 @@ #![feature(lint_reasons)] #![allow( unused, + non_local_definitions, clippy::uninlined_format_args, clippy::unnecessary_mut_passed, clippy::unnecessary_to_owned, diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs index 27771a8f15b3..acb2c74d849a 100644 --- a/tests/ui/needless_borrow.rs +++ b/tests/ui/needless_borrow.rs @@ -1,6 +1,7 @@ #![feature(lint_reasons)] #![allow( unused, + non_local_definitions, clippy::uninlined_format_args, clippy::unnecessary_mut_passed, clippy::unnecessary_to_owned, diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr index a21ed8382c14..9034bd83a0b0 100644 --- a/tests/ui/needless_borrow.stderr +++ b/tests/ui/needless_borrow.stderr @@ -1,5 +1,5 @@ error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:15:15 + --> $DIR/needless_borrow.rs:16:15 | LL | let _ = x(&&a); // warn | ^^^ help: change this to: `&a` @@ -8,157 +8,157 @@ LL | let _ = x(&&a); // warn = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:19:13 + --> $DIR/needless_borrow.rs:20:13 | LL | mut_ref(&mut &mut b); // warn | ^^^^^^^^^^^ help: change this to: `&mut b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:31:13 + --> $DIR/needless_borrow.rs:32:13 | LL | &&a | ^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:33:15 + --> $DIR/needless_borrow.rs:34:15 | LL | 46 => &&a, | ^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:39:27 + --> $DIR/needless_borrow.rs:40:27 | LL | break &ref_a; | ^^^^^^ help: change this to: `ref_a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:46:15 + --> $DIR/needless_borrow.rs:47:15 | LL | let _ = x(&&&a); | ^^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:47:15 + --> $DIR/needless_borrow.rs:48:15 | LL | let _ = x(&mut &&a); | ^^^^^^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:48:15 + --> $DIR/needless_borrow.rs:49:15 | LL | let _ = x(&&&mut b); | ^^^^^^^^ help: change this to: `&mut b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:49:15 + --> $DIR/needless_borrow.rs:50:15 | LL | let _ = x(&&ref_a); | ^^^^^^^ help: change this to: `ref_a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:52:11 + --> $DIR/needless_borrow.rs:53:11 | LL | x(&b); | ^^ help: change this to: `b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:59:13 + --> $DIR/needless_borrow.rs:60:13 | LL | mut_ref(&mut x); | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:60:13 + --> $DIR/needless_borrow.rs:61:13 | LL | mut_ref(&mut &mut x); | ^^^^^^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:61:23 + --> $DIR/needless_borrow.rs:62:23 | LL | let y: &mut i32 = &mut x; | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:62:23 + --> $DIR/needless_borrow.rs:63:23 | LL | let y: &mut i32 = &mut &mut x; | ^^^^^^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:71:14 + --> $DIR/needless_borrow.rs:72:14 | LL | 0 => &mut x, | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:77:14 + --> $DIR/needless_borrow.rs:78:14 | LL | 0 => &mut x, | ^^^^^^ help: change this to: `x` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:89:13 + --> $DIR/needless_borrow.rs:90:13 | LL | let _ = (&x).0; | ^^^^ help: change this to: `x` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:91:22 + --> $DIR/needless_borrow.rs:92:22 | LL | let _ = unsafe { (&*x).0 }; | ^^^^^ help: change this to: `(*x)` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:101:5 + --> $DIR/needless_borrow.rs:102:5 | LL | (&&()).foo(); | ^^^^^^ help: change this to: `(&())` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:110:5 + --> $DIR/needless_borrow.rs:111:5 | LL | (&&5).foo(); | ^^^^^ help: change this to: `(&5)` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:136:23 + --> $DIR/needless_borrow.rs:137:23 | LL | let x: (&str,) = (&"",); | ^^^ help: change this to: `""` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:178:13 + --> $DIR/needless_borrow.rs:179:13 | LL | (&self.f)() | ^^^^^^^^^ help: change this to: `(self.f)` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:187:13 + --> $DIR/needless_borrow.rs:188:13 | LL | (&mut self.f)() | ^^^^^^^^^^^^^ help: change this to: `(self.f)` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:224:22 + --> $DIR/needless_borrow.rs:225:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:231:22 + --> $DIR/needless_borrow.rs:232:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:235:22 + --> $DIR/needless_borrow.rs:236:22 | LL | let _ = &mut (&mut x.u).x; | ^^^^^^^^^^ help: change this to: `x.u` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:236:22 + --> $DIR/needless_borrow.rs:237:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` From dc91bd7676e6fc7d50aad5d1e5f4628cc3cf0326 Mon Sep 17 00:00:00 2001 From: surechen Date: Fri, 10 Nov 2023 10:11:24 +0800 Subject: [PATCH 1080/1222] By tracking import use types to check whether it is scope uses or the other situations like module-relative uses, we can do more accurate redundant import checking. fixes #117448 For example unnecessary imports in std::prelude that can be eliminated: ```rust use std::option::Option::Some;//~ WARNING the item `Some` is imported redundantly use std::option::Option::None; //~ WARNING the item `None` is imported redundantly ``` --- src/driver.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/driver.rs b/src/driver.rs index bdf1cf0a2240..85867d1511d9 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -28,7 +28,6 @@ use std::fs::read_to_string; use std::ops::Deref; use std::path::Path; use std::process::exit; -use std::string::ToString; use anstream::println; From f78187e964bb0c40406423877daae639e1d16e3e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 1 Feb 2024 10:13:24 +1100 Subject: [PATCH 1081/1222] Prefer `DiagnosticBuilder` over `Diagnostic` in diagnostic modifiers. There are lots of functions that modify a diagnostic. This can be via a `&mut Diagnostic` or a `&mut DiagnosticBuilder`, because the latter type wraps the former and impls `DerefMut`. This commit converts all the `&mut Diagnostic` occurrences to `&mut DiagnosticBuilder`. This is a step towards greatly simplifying `Diagnostic`. Some of the relevant function are made generic, because they deal with both errors and warnings. No function bodies are changed, because all the modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`. --- clippy_lints/src/casts/cast_possible_truncation.rs | 4 ++-- clippy_lints/src/functions/result.rs | 4 ++-- clippy_lints/src/if_let_mutex.rs | 4 ++-- clippy_lints/src/implicit_hasher.rs | 4 ++-- clippy_lints/src/manual_clamp.rs | 4 ++-- .../src/matches/significant_drop_in_scrutinee.rs | 4 ++-- .../src/methods/suspicious_command_arg_space.rs | 4 ++-- clippy_lints/src/missing_asserts_for_indexing.rs | 4 ++-- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- clippy_utils/src/diagnostics.rs | 12 ++++++------ 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/clippy_lints/src/casts/cast_possible_truncation.rs b/clippy_lints/src/casts/cast_possible_truncation.rs index f99a51e2b88c..1543ae803996 100644 --- a/clippy_lints/src/casts/cast_possible_truncation.rs +++ b/clippy_lints/src/casts/cast_possible_truncation.rs @@ -4,7 +4,7 @@ use clippy_utils::expr_or_init; use clippy_utils::source::snippet; use clippy_utils::sugg::Sugg; use clippy_utils::ty::{get_discriminant_value, is_isize_or_usize}; -use rustc_errors::{Applicability, Diagnostic, SuggestionStyle}; +use rustc_errors::{Applicability, DiagnosticBuilder, SuggestionStyle}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; @@ -177,7 +177,7 @@ fn offer_suggestion( expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to_span: Span, - diag: &mut Diagnostic, + diag: &mut DiagnosticBuilder<'_, ()>, ) { let cast_to_snip = snippet(cx, cast_to_span, ".."); let suggestion = if cast_to_snip == "_" { diff --git a/clippy_lints/src/functions/result.rs b/clippy_lints/src/functions/result.rs index f1200c2edc13..9505741e68ff 100644 --- a/clippy_lints/src/functions/result.rs +++ b/clippy_lints/src/functions/result.rs @@ -1,4 +1,4 @@ -use rustc_errors::Diagnostic; +use rustc_errors::DiagnosticBuilder; use rustc_hir as hir; use rustc_lint::{LateContext, LintContext}; use rustc_middle::lint::in_external_macro; @@ -135,7 +135,7 @@ fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty RESULT_LARGE_ERR, hir_ty_span, "the `Err`-variant returned from this function is very large", - |diag: &mut Diagnostic| { + |diag: &mut DiagnosticBuilder<'_, ()>| { diag.span_label(hir_ty_span, format!("the `Err`-variant is at least {ty_size} bytes")); diag.help(format!("try reducing the size of `{err_ty}`, for example by boxing large elements or replacing it with `Box<{err_ty}>`")); }, diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index 5e354209cbfc..61a322ea8812 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::{higher, SpanlessEq}; -use rustc_errors::Diagnostic; +use rustc_errors::DiagnosticBuilder; use rustc_hir::intravisit::{self as visit, Visitor}; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; @@ -59,7 +59,7 @@ impl<'tcx> LateLintPass<'tcx> for IfLetMutex { arm_visit.visit_expr(if_else); if let Some(arm_mutex) = arm_visit.found_mutex_if_same_as(op_mutex) { - let diag = |diag: &mut Diagnostic| { + let diag = |diag: &mut DiagnosticBuilder<'_, ()>| { diag.span_label( op_mutex.span, "this Mutex will remain locked for the entire `if let`-block...", diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 87f6f5e7959e..746de50c0fa7 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use std::collections::BTreeMap; -use rustc_errors::Diagnostic; +use rustc_errors::DiagnosticBuilder; use rustc_hir as hir; use rustc_hir::intravisit::{walk_body, walk_expr, walk_inf, walk_ty, Visitor}; use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind}; @@ -65,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { fn suggestion( cx: &LateContext<'_>, - diag: &mut Diagnostic, + diag: &mut DiagnosticBuilder<'_, ()>, generics_span: Span, generics_suggestion_span: Span, target: &ImplicitHasherType<'_>, diff --git a/clippy_lints/src/manual_clamp.rs b/clippy_lints/src/manual_clamp.rs index 0da309f9531e..12bb80dfde2c 100644 --- a/clippy_lints/src/manual_clamp.rs +++ b/clippy_lints/src/manual_clamp.rs @@ -9,7 +9,7 @@ use clippy_utils::{ peel_blocks_with_stmt, MaybePath, }; use itertools::Itertools; -use rustc_errors::{Applicability, Diagnostic}; +use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir::def::Res; use rustc_hir::{Arm, BinOpKind, Block, Expr, ExprKind, HirId, PatKind, PathSegment, PrimTy, QPath, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; @@ -163,7 +163,7 @@ fn emit_suggestion<'tcx>(cx: &LateContext<'tcx>, suggestion: &ClampSuggestion<'t }; let suggestion = format!("{assignment}{input}.clamp({min}, {max}){semicolon}"); let msg = "clamp-like pattern without using clamp function"; - let lint_builder = |d: &mut Diagnostic| { + let lint_builder = |d: &mut DiagnosticBuilder<'_, ()>| { d.span_suggestion(*span, "replace with clamp", suggestion, Applicability::MaybeIncorrect); if *is_float { d.note("clamp will panic if max < min, min.is_nan(), or max.is_nan()") diff --git a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index ee0fdb35313d..a7e42fd24059 100644 --- a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -2,7 +2,7 @@ use crate::FxHashSet; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::{indent_of, snippet}; use clippy_utils::{get_attr, is_lint_allowed}; -use rustc_errors::{Applicability, Diagnostic}; +use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{Arm, Expr, ExprKind, MatchSource}; use rustc_lint::{LateContext, LintContext}; @@ -37,7 +37,7 @@ pub(super) fn check<'tcx>( } } -fn set_diagnostic<'tcx>(diag: &mut Diagnostic, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, found: FoundSigDrop) { +fn set_diagnostic<'tcx>(diag: &mut DiagnosticBuilder<'_, ()>, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, found: FoundSigDrop) { if found.lint_suggestion == LintSuggestion::MoveAndClone { // If our suggestion is to move and clone, then we want to leave it to the user to // decide how to address this lint, since it may be that cloning is inappropriate. diff --git a/clippy_lints/src/methods/suspicious_command_arg_space.rs b/clippy_lints/src/methods/suspicious_command_arg_space.rs index b2c5987e43d2..617d6d998fcc 100644 --- a/clippy_lints/src/methods/suspicious_command_arg_space.rs +++ b/clippy_lints/src/methods/suspicious_command_arg_space.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_type_diagnostic_item; -use rustc_errors::{Applicability, Diagnostic}; +use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_lint::LateContext; use rustc_span::{sym, Span}; use {rustc_ast as ast, rustc_hir as hir}; @@ -22,7 +22,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, recv: &'tcx hir::Expr<'_>, arg SUSPICIOUS_COMMAND_ARG_SPACE, arg.span, "single argument that looks like it should be multiple arguments", - |diag: &mut Diagnostic| { + |diag: &mut DiagnosticBuilder<'_, ()>| { diag.multipart_suggestion_verbose( "consider splitting the argument", vec![(span, "args".to_string()), (arg.span, format!("[{arg1:?}, {arg2:?}]"))], diff --git a/clippy_lints/src/missing_asserts_for_indexing.rs b/clippy_lints/src/missing_asserts_for_indexing.rs index 0e4d39c99902..ab25dde7efee 100644 --- a/clippy_lints/src/missing_asserts_for_indexing.rs +++ b/clippy_lints/src/missing_asserts_for_indexing.rs @@ -9,7 +9,7 @@ use clippy_utils::{eq_expr_value, hash_expr, higher}; use rustc_ast::{LitKind, RangeLimits}; use rustc_data_structures::packed::Pu128; use rustc_data_structures::unhash::UnhashMap; -use rustc_errors::{Applicability, Diagnostic}; +use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir::{BinOp, Block, Body, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; @@ -67,7 +67,7 @@ declare_lint_pass!(MissingAssertsForIndexing => [MISSING_ASSERTS_FOR_INDEXING]); fn report_lint(cx: &LateContext<'_>, full_span: Span, msg: &str, indexes: &[Span], f: F) where - F: FnOnce(&mut Diagnostic), + F: FnOnce(&mut DiagnosticBuilder<'_, ()>), { span_lint_and_then(cx, MISSING_ASSERTS_FOR_INDEXING, full_span, msg, |diag| { f(diag); diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 384a402ce5b0..6252f91b25f8 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -6,7 +6,7 @@ use clippy_utils::ty::{ implements_trait, implements_trait_with_env_from_iter, is_copy, is_type_diagnostic_item, is_type_lang_item, }; use rustc_ast::ast::Attribute; -use rustc_errors::{Applicability, Diagnostic}; +use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir::intravisit::FnKind; use rustc_hir::{ BindingAnnotation, Body, FnDecl, GenericArg, HirId, HirIdSet, Impl, ItemKind, LangItem, Mutability, Node, PatKind, @@ -196,7 +196,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { && !moved_vars.contains(&canonical_id) { // Dereference suggestion - let sugg = |diag: &mut Diagnostic| { + let sugg = |diag: &mut DiagnosticBuilder<'_, ()>| { if let ty::Adt(def, ..) = ty.kind() { if let Some(span) = cx.tcx.hir().span_if_local(def.did()) { if type_allowed_to_implement_copy( diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs index 5199959c0f2b..db94b60dc951 100644 --- a/clippy_utils/src/diagnostics.rs +++ b/clippy_utils/src/diagnostics.rs @@ -8,13 +8,13 @@ //! Thank you! //! ~The `INTERNAL_METADATA_COLLECTOR` lint -use rustc_errors::{Applicability, Diagnostic, MultiSpan}; +use rustc_errors::{Applicability, DiagnosticBuilder, MultiSpan}; use rustc_hir::HirId; use rustc_lint::{LateContext, Lint, LintContext}; use rustc_span::Span; use std::env; -fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) { +fn docs_link(diag: &mut DiagnosticBuilder<'_, ()>, lint: &'static Lint) { if env::var("CLIPPY_DISABLE_DOCS_LINKS").is_err() { if let Some(lint) = lint.name_lower().strip_prefix("clippy::") { diag.help(format!( @@ -143,7 +143,7 @@ pub fn span_lint_and_then(cx: &C, lint: &'static Lint, sp: S, msg: &str where C: LintContext, S: Into, - F: FnOnce(&mut Diagnostic), + F: FnOnce(&mut DiagnosticBuilder<'_, ()>), { #[expect(clippy::disallowed_methods)] cx.span_lint(lint, sp, msg.to_string(), |diag| { @@ -165,7 +165,7 @@ pub fn span_lint_hir_and_then( hir_id: HirId, sp: impl Into, msg: &str, - f: impl FnOnce(&mut Diagnostic), + f: impl FnOnce(&mut DiagnosticBuilder<'_, ()>), ) { #[expect(clippy::disallowed_methods)] cx.tcx.node_span_lint(lint, hir_id, sp, msg.to_string(), |diag| { @@ -214,7 +214,7 @@ pub fn span_lint_and_sugg( /// appear once per /// replacement. In human-readable format though, it only appears once before /// the whole suggestion. -pub fn multispan_sugg(diag: &mut Diagnostic, help_msg: &str, sugg: I) +pub fn multispan_sugg(diag: &mut DiagnosticBuilder<'_, ()>, help_msg: &str, sugg: I) where I: IntoIterator, { @@ -227,7 +227,7 @@ where /// multiple spans. This is tracked in issue [rustfix#141](https://github.com/rust-lang/rustfix/issues/141). /// Suggestions with multiple spans will be silently ignored. pub fn multispan_sugg_with_applicability( - diag: &mut Diagnostic, + diag: &mut DiagnosticBuilder<'_, ()>, help_msg: &str, applicability: Applicability, sugg: I, From 40a9ff87377884c2f46ffca763efa360710266c9 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 19 Feb 2024 17:39:25 -0300 Subject: [PATCH 1082/1222] Remove suspicious auto trait lint --- tests/ui/non_send_fields_in_send_ty.rs | 1 - tests/ui/non_send_fields_in_send_ty.stderr | 52 +++++++++++----------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/tests/ui/non_send_fields_in_send_ty.rs b/tests/ui/non_send_fields_in_send_ty.rs index c6855a096968..046ea70b08f1 100644 --- a/tests/ui/non_send_fields_in_send_ty.rs +++ b/tests/ui/non_send_fields_in_send_ty.rs @@ -1,5 +1,4 @@ #![warn(clippy::non_send_fields_in_send_ty)] -#![allow(suspicious_auto_trait_impls)] #![feature(extern_types)] use std::cell::UnsafeCell; diff --git a/tests/ui/non_send_fields_in_send_ty.stderr b/tests/ui/non_send_fields_in_send_ty.stderr index 1ea76196af93..99fd4ea60b60 100644 --- a/tests/ui/non_send_fields_in_send_ty.stderr +++ b/tests/ui/non_send_fields_in_send_ty.stderr @@ -1,11 +1,11 @@ error: some fields in `RingBuffer` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:17:1 + --> $DIR/non_send_fields_in_send_ty.rs:16:1 | LL | unsafe impl Send for RingBuffer {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `data` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:12:5 + --> $DIR/non_send_fields_in_send_ty.rs:11:5 | LL | data: Vec>, | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -14,155 +14,155 @@ LL | data: Vec>, = help: to override `-D warnings` add `#[allow(clippy::non_send_fields_in_send_ty)]` error: some fields in `MvccRwLock` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:26:1 + --> $DIR/non_send_fields_in_send_ty.rs:25:1 | LL | unsafe impl Send for MvccRwLock {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `lock` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:23:5 + --> $DIR/non_send_fields_in_send_ty.rs:22:5 | LL | lock: Mutex>, | ^^^^^^^^^^^^^^^^^^^ = help: add bounds on type parameter `T` that satisfy `Mutex>: Send` error: some fields in `ArcGuard` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:35:1 + --> $DIR/non_send_fields_in_send_ty.rs:34:1 | LL | unsafe impl Send for ArcGuard {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `head` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:32:5 + --> $DIR/non_send_fields_in_send_ty.rs:31:5 | LL | head: Arc, | ^^^^^^^^^^^^^ = help: add bounds on type parameter `RC` that satisfy `Arc: Send` error: some fields in `DeviceHandle` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:52:1 + --> $DIR/non_send_fields_in_send_ty.rs:51:1 | LL | unsafe impl Send for DeviceHandle {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `context` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:48:5 + --> $DIR/non_send_fields_in_send_ty.rs:47:5 | LL | context: T, | ^^^^^^^^^^ = help: add `T: Send` bound in `Send` impl error: some fields in `NoGeneric` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:60:1 + --> $DIR/non_send_fields_in_send_ty.rs:59:1 | LL | unsafe impl Send for NoGeneric {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `rc_is_not_send` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:57:5 + --> $DIR/non_send_fields_in_send_ty.rs:56:5 | LL | rc_is_not_send: Rc, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` error: some fields in `MultiField` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:69:1 + --> $DIR/non_send_fields_in_send_ty.rs:68:1 | LL | unsafe impl Send for MultiField {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:64:5 + --> $DIR/non_send_fields_in_send_ty.rs:63:5 | LL | field1: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl note: it is not safe to send field `field2` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:65:5 + --> $DIR/non_send_fields_in_send_ty.rs:64:5 | LL | field2: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl note: it is not safe to send field `field3` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:66:5 + --> $DIR/non_send_fields_in_send_ty.rs:65:5 | LL | field3: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl error: some fields in `MyOption` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:77:1 + --> $DIR/non_send_fields_in_send_ty.rs:76:1 | LL | unsafe impl Send for MyOption {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `0` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:73:12 + --> $DIR/non_send_fields_in_send_ty.rs:72:12 | LL | MySome(T), | ^ = help: add `T: Send` bound in `Send` impl error: some fields in `MultiParam` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:90:1 + --> $DIR/non_send_fields_in_send_ty.rs:89:1 | LL | unsafe impl Send for MultiParam {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `vec` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:87:5 + --> $DIR/non_send_fields_in_send_ty.rs:86:5 | LL | vec: Vec<(A, B)>, | ^^^^^^^^^^^^^^^^ = help: add bounds on type parameters `A, B` that satisfy `Vec<(A, B)>: Send` error: some fields in `HeuristicTest` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:109:1 + --> $DIR/non_send_fields_in_send_ty.rs:108:1 | LL | unsafe impl Send for HeuristicTest {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field4` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:104:5 + --> $DIR/non_send_fields_in_send_ty.rs:103:5 | LL | field4: (*const NonSend, Rc), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` error: some fields in `AttrTest3` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:129:1 + --> $DIR/non_send_fields_in_send_ty.rs:128:1 | LL | unsafe impl Send for AttrTest3 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `0` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:124:11 + --> $DIR/non_send_fields_in_send_ty.rs:123:11 | LL | Enum2(T), | ^ = help: add `T: Send` bound in `Send` impl error: some fields in `Complex` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:138:1 + --> $DIR/non_send_fields_in_send_ty.rs:137:1 | LL | unsafe impl

Send for Complex {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:134:5 + --> $DIR/non_send_fields_in_send_ty.rs:133:5 | LL | field1: A, | ^^^^^^^^^ = help: add `P: Send` bound in `Send` impl error: some fields in `Complex>` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:142:1 + --> $DIR/non_send_fields_in_send_ty.rs:141:1 | LL | unsafe impl Send for Complex> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field2` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:135:5 + --> $DIR/non_send_fields_in_send_ty.rs:134:5 | LL | field2: B, | ^^^^^^^^^ From a921353a8e09ba7ebf44a98c10cb9bb3d10e4702 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 14 Feb 2024 12:28:07 +0000 Subject: [PATCH 1083/1222] Always evaluate free constants and statics, even if previous errors occurred --- tests/ui-toml/suppress_lint_in_const/test.rs | 5 -- .../suppress_lint_in_const/test.stderr | 33 +++---------- tests/ui/indexing_slicing_index.rs | 2 - tests/ui/indexing_slicing_index.stderr | 47 +++++++------------ 4 files changed, 23 insertions(+), 64 deletions(-) diff --git a/tests/ui-toml/suppress_lint_in_const/test.rs b/tests/ui-toml/suppress_lint_in_const/test.rs index 3edb3a10b769..4ae75544c60c 100644 --- a/tests/ui-toml/suppress_lint_in_const/test.rs +++ b/tests/ui-toml/suppress_lint_in_const/test.rs @@ -13,8 +13,6 @@ const ARR: [i32; 2] = [1, 2]; const REF: &i32 = &ARR[idx()]; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true. -const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. -//~^ ERROR: failed const fn idx() -> usize { 1 @@ -35,9 +33,6 @@ fn main() { x[const { idx() }]; // Ok, should not produce stderr. x[const { idx4() }]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. const { &ARR[idx()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true. - const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true. - // - //~^^ ERROR: failed let y = &x; y[0]; // Ok, referencing shouldn't affect this lint. See the issue 6021 diff --git a/tests/ui-toml/suppress_lint_in_const/test.stderr b/tests/ui-toml/suppress_lint_in_const/test.stderr index 84e7eff45573..d5ce891b6805 100644 --- a/tests/ui-toml/suppress_lint_in_const/test.stderr +++ b/tests/ui-toml/suppress_lint_in_const/test.stderr @@ -1,17 +1,5 @@ -error[E0080]: evaluation of `main::{constant#3}` failed - --> $DIR/test.rs:38:14 - | -LL | const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true. - | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 - -note: erroneous constant encountered - --> $DIR/test.rs:38:5 - | -LL | const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true. - | ^^^^^^^^^^^^^^^^^^^^^^ - error: indexing may panic - --> $DIR/test.rs:29:5 + --> $DIR/test.rs:27:5 | LL | x[index]; | ^^^^^^^^ @@ -21,7 +9,7 @@ LL | x[index]; = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]` error: indexing may panic - --> $DIR/test.rs:47:5 + --> $DIR/test.rs:42:5 | LL | v[0]; | ^^^^ @@ -29,7 +17,7 @@ LL | v[0]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/test.rs:48:5 + --> $DIR/test.rs:43:5 | LL | v[10]; | ^^^^^ @@ -37,7 +25,7 @@ LL | v[10]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/test.rs:49:5 + --> $DIR/test.rs:44:5 | LL | v[1 << 3]; | ^^^^^^^^^ @@ -45,7 +33,7 @@ LL | v[1 << 3]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/test.rs:55:5 + --> $DIR/test.rs:50:5 | LL | v[N]; | ^^^^ @@ -53,19 +41,12 @@ LL | v[N]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/test.rs:56:5 + --> $DIR/test.rs:51:5 | LL | v[M]; | ^^^^ | = help: consider using `.get(n)` or `.get_mut(n)` instead -error[E0080]: evaluation of constant value failed - --> $DIR/test.rs:16:24 - | -LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. - | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 - -error: aborting due to 8 previous errors +error: aborting due to 6 previous errors -For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/indexing_slicing_index.rs b/tests/ui/indexing_slicing_index.rs index 1ac0bb11014a..2ababad7fc75 100644 --- a/tests/ui/indexing_slicing_index.rs +++ b/tests/ui/indexing_slicing_index.rs @@ -13,8 +13,6 @@ const ARR: [i32; 2] = [1, 2]; const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-restriction-lint-in-const` default is false. //~^ ERROR: indexing may panic -const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. -//~^ ERROR: indexing may panic const fn idx() -> usize { 1 diff --git a/tests/ui/indexing_slicing_index.stderr b/tests/ui/indexing_slicing_index.stderr index 6d64fa1e6cf8..2996e31a1aa2 100644 --- a/tests/ui/indexing_slicing_index.stderr +++ b/tests/ui/indexing_slicing_index.stderr @@ -9,29 +9,20 @@ LL | const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-re = note: `-D clippy::indexing-slicing` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]` -error: indexing may panic - --> $DIR/indexing_slicing_index.rs:16:24 - | -LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. - | ^^^^^^^^^^^ - | - = help: consider using `.get(n)` or `.get_mut(n)` instead - = note: the suggestion might not be applicable in constant blocks - error[E0080]: evaluation of `main::{constant#3}` failed - --> $DIR/indexing_slicing_index.rs:48:14 + --> $DIR/indexing_slicing_index.rs:46:14 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 note: erroneous constant encountered - --> $DIR/indexing_slicing_index.rs:48:5 + --> $DIR/indexing_slicing_index.rs:46:5 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^^^^^^^^^^^^ error: indexing may panic - --> $DIR/indexing_slicing_index.rs:29:5 + --> $DIR/indexing_slicing_index.rs:27:5 | LL | x[index]; | ^^^^^^^^ @@ -39,7 +30,7 @@ LL | x[index]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: index is out of bounds - --> $DIR/indexing_slicing_index.rs:32:5 + --> $DIR/indexing_slicing_index.rs:30:5 | LL | x[4]; | ^^^^ @@ -48,13 +39,13 @@ LL | x[4]; = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]` error: index is out of bounds - --> $DIR/indexing_slicing_index.rs:34:5 + --> $DIR/indexing_slicing_index.rs:32:5 | LL | x[1 << 3]; | ^^^^^^^^^ error: indexing may panic - --> $DIR/indexing_slicing_index.rs:45:14 + --> $DIR/indexing_slicing_index.rs:43:14 | LL | const { &ARR[idx()] }; | ^^^^^^^^^^ @@ -63,7 +54,7 @@ LL | const { &ARR[idx()] }; = note: the suggestion might not be applicable in constant blocks error: indexing may panic - --> $DIR/indexing_slicing_index.rs:48:14 + --> $DIR/indexing_slicing_index.rs:46:14 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ @@ -72,13 +63,13 @@ LL | const { &ARR[idx4()] }; = note: the suggestion might not be applicable in constant blocks error: index is out of bounds - --> $DIR/indexing_slicing_index.rs:55:5 + --> $DIR/indexing_slicing_index.rs:53:5 | LL | y[4]; | ^^^^ error: indexing may panic - --> $DIR/indexing_slicing_index.rs:58:5 + --> $DIR/indexing_slicing_index.rs:56:5 | LL | v[0]; | ^^^^ @@ -86,7 +77,7 @@ LL | v[0]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:60:5 + --> $DIR/indexing_slicing_index.rs:58:5 | LL | v[10]; | ^^^^^ @@ -94,7 +85,7 @@ LL | v[10]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:62:5 + --> $DIR/indexing_slicing_index.rs:60:5 | LL | v[1 << 3]; | ^^^^^^^^^ @@ -102,13 +93,13 @@ LL | v[1 << 3]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: index is out of bounds - --> $DIR/indexing_slicing_index.rs:70:5 + --> $DIR/indexing_slicing_index.rs:68:5 | LL | x[N]; | ^^^^ error: indexing may panic - --> $DIR/indexing_slicing_index.rs:73:5 + --> $DIR/indexing_slicing_index.rs:71:5 | LL | v[N]; | ^^^^ @@ -116,7 +107,7 @@ LL | v[N]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:75:5 + --> $DIR/indexing_slicing_index.rs:73:5 | LL | v[M]; | ^^^^ @@ -124,17 +115,11 @@ LL | v[M]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: index is out of bounds - --> $DIR/indexing_slicing_index.rs:79:13 + --> $DIR/indexing_slicing_index.rs:77:13 | LL | let _ = x[4]; | ^^^^ -error[E0080]: evaluation of constant value failed - --> $DIR/indexing_slicing_index.rs:16:24 - | -LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. - | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 - -error: aborting due to 17 previous errors +error: aborting due to 15 previous errors For more information about this error, try `rustc --explain E0080`. From 95e11b51625d279b4aaf086b56b8cff7c79db7cd Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 6 Feb 2024 16:44:30 +1100 Subject: [PATCH 1084/1222] Reduce capabilities of `Diagnostic`. Currently many diagnostic modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`. This commit removes most of them from `Diagnostic`. To minimize the diff size, it keeps them within `diagnostic.rs` but changes the surrounding `impl Diagnostic` block to `impl DiagnosticBuilder`. (I intend to move things around later, to give a more sensible code layout.) `Diagnostic` keeps a few methods that it still needs, like `sub`, `arg`, and `replace_args`. The `forward!` macro, which defined two additional methods per call (e.g. `note` and `with_note`), is replaced by the `with_fn!` macro, which defines one additional method per call (e.g. `with_note`). It's now also only used when necessary -- not all modifier methods currently need a `with_*` form. (New ones can be easily added as necessary.) All this also requires changing `trait AddToDiagnostic` so its methods take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`. There are three subdiagnostics -- `DelayedAtWithoutNewline`, `DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` -- that are created within the diagnostics machinery and appended to external diagnostics. These are handled at the `Diagnostic` level, which means it's now hard to construct them via `derive(Diagnostic)`, so instead we construct them by hand. This has no effect on what they look like when printed. There are lots of new `allow` markers for `untranslatable_diagnostics` and `diagnostics_outside_of_impl`. This is because `#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic` modifier methods, but missing from the `DiagnosticBuilder` modifier methods. They're now present. --- clippy_utils/src/sugg.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index c86362c427ce..b355e66b7b12 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -683,7 +683,7 @@ fn indentation(cx: &T, span: Span) -> Option { }) } -/// Convenience extension trait for `Diagnostic`. +/// Convenience extension trait for `DiagnosticBuilder`. pub trait DiagnosticExt { /// Suggests to add an attribute to an item. /// @@ -731,7 +731,7 @@ pub trait DiagnosticExt { fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str, applicability: Applicability); } -impl DiagnosticExt for rustc_errors::Diagnostic { +impl DiagnosticExt for rustc_errors::DiagnosticBuilder<'_, ()> { fn suggest_item_with_attr( &mut self, cx: &T, From 200ac94b4e0c685d2ed2f843aff999ed3963524d Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Tue, 20 Feb 2024 20:55:13 -0700 Subject: [PATCH 1085/1222] Stabilize `LazyCell` and `LazyLock` (`lazy_cell`) --- clippy_dev/src/lib.rs | 1 - src/driver.rs | 1 - tests/compile-test.rs | 1 - tests/dogfood.rs | 1 - tests/lint_message_convention.rs | 1 - tests/workspace.rs | 2 -- 6 files changed, 7 deletions(-) diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index 385191e0361b..3aa43dbe23ed 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(lazy_cell)] #![feature(let_chains)] #![feature(rustc_private)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] diff --git a/src/driver.rs b/src/driver.rs index 9e42abbc9aa9..f79da26964f3 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -2,7 +2,6 @@ #![allow(rustc::untranslatable_diagnostic)] #![feature(rustc_private)] #![feature(let_chains)] -#![feature(lazy_cell)] #![feature(lint_reasons)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] // warn on lints, that are included in `rust-lang/rust`s bootstrap diff --git a/tests/compile-test.rs b/tests/compile-test.rs index b06a11702ec8..333a2ab58575 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -1,4 +1,3 @@ -#![feature(lazy_cell)] #![feature(is_sorted)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] #![warn(rust_2018_idioms, unused_lifetimes)] diff --git a/tests/dogfood.rs b/tests/dogfood.rs index 3f16c180ea78..36a7a651c4d2 100644 --- a/tests/dogfood.rs +++ b/tests/dogfood.rs @@ -3,7 +3,6 @@ //! //! See [Eating your own dog food](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) for context -#![feature(lazy_cell)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] #![warn(rust_2018_idioms, unused_lifetimes)] diff --git a/tests/lint_message_convention.rs b/tests/lint_message_convention.rs index 98019c755276..6ce7e44474d8 100644 --- a/tests/lint_message_convention.rs +++ b/tests/lint_message_convention.rs @@ -1,4 +1,3 @@ -#![feature(lazy_cell)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] #![warn(rust_2018_idioms, unused_lifetimes)] diff --git a/tests/workspace.rs b/tests/workspace.rs index 699ab2be199a..19ccc7ae9607 100644 --- a/tests/workspace.rs +++ b/tests/workspace.rs @@ -1,5 +1,3 @@ -#![feature(lazy_cell)] - use std::path::PathBuf; use std::process::Command; use test_utils::{CARGO_CLIPPY_PATH, IS_RUSTC_TEST_SUITE}; From 15bb4319b0fc27163eeeeb84da4852edaa808ca6 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 25 Dec 2023 20:53:01 +0000 Subject: [PATCH 1086/1222] Add asm label support to AST and HIR --- clippy_lints/src/loops/never_loop.rs | 3 +++ clippy_utils/src/hir_utils.rs | 1 + 2 files changed, 4 insertions(+) diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index 245a903f9982..65d922f03df3 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -255,6 +255,9 @@ fn never_loop_expr<'tcx>( InlineAsmOperand::Const { .. } | InlineAsmOperand::SymFn { .. } | InlineAsmOperand::SymStatic { .. } => { NeverLoopResult::Normal }, + InlineAsmOperand::Label { block } => { + never_loop_block(cx, block, local_labels, main_loop_id) + } })), ExprKind::OffsetOf(_, _) | ExprKind::Yield(_, _) diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index d50332e82da5..643852c1c54f 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -835,6 +835,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_body(anon_const.body); }, InlineAsmOperand::SymStatic { path, def_id: _ } => self.hash_qpath(path), + InlineAsmOperand::Label { block } => self.hash_block(block), } } }, From b170b35b96481693f34b83782aa39cbcd2f64878 Mon Sep 17 00:00:00 2001 From: Lieselotte <52315535+she3py@users.noreply.github.com> Date: Sun, 25 Feb 2024 22:22:09 +0100 Subject: [PATCH 1087/1222] Add `ast::ExprKind::Dummy` --- clippy_utils/src/ast_utils.rs | 1 + clippy_utils/src/sugg.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 0467a8a65709..81a26a12009d 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -144,6 +144,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (Paren(l), _) => eq_expr(l, r), (_, Paren(r)) => eq_expr(l, r), (Err, Err) => true, + (Dummy, _) | (_, Dummy) => unreachable!("comparing `ExprKind::Dummy`"), (Try(l), Try(r)) | (Await(l, _), Await(r, _)) => eq_expr(l, r), (Array(l), Array(r)) => over(l, r, |l, r| eq_expr(l, r)), (Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)), diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index b355e66b7b12..7b1b0388b29f 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -222,7 +222,8 @@ impl<'a> Sugg<'a> { | ast::ExprKind::Array(..) | ast::ExprKind::While(..) | ast::ExprKind::Await(..) - | ast::ExprKind::Err => Sugg::NonParen(snippet_with_context(cx, expr.span, ctxt, default, app).0), + | ast::ExprKind::Err + | ast::ExprKind::Dummy => Sugg::NonParen(snippet_with_context(cx, expr.span, ctxt, default, app).0), ast::ExprKind::Range(ref lhs, ref rhs, RangeLimits::HalfOpen) => Sugg::BinOp( AssocOp::DotDot, lhs.as_ref().map_or("".into(), |lhs| { From 9bebd2e6eae0a4f6b085afde46541b6a784a7ca2 Mon Sep 17 00:00:00 2001 From: Lieselotte <52315535+she3py@users.noreply.github.com> Date: Sun, 25 Feb 2024 22:22:11 +0100 Subject: [PATCH 1088/1222] Add `ErrorGuaranteed` to `ast::ExprKind::Err` --- clippy_utils/src/ast_utils.rs | 2 +- clippy_utils/src/sugg.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 81a26a12009d..c52a4e0d8b7c 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -143,7 +143,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { match (&l.kind, &r.kind) { (Paren(l), _) => eq_expr(l, r), (_, Paren(r)) => eq_expr(l, r), - (Err, Err) => true, + (Err(_), Err(_)) => true, (Dummy, _) | (_, Dummy) => unreachable!("comparing `ExprKind::Dummy`"), (Try(l), Try(r)) | (Await(l, _), Await(r, _)) => eq_expr(l, r), (Array(l), Array(r)) => over(l, r, |l, r| eq_expr(l, r)), diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 7b1b0388b29f..1f6446b8746e 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -222,7 +222,7 @@ impl<'a> Sugg<'a> { | ast::ExprKind::Array(..) | ast::ExprKind::While(..) | ast::ExprKind::Await(..) - | ast::ExprKind::Err + | ast::ExprKind::Err(_) | ast::ExprKind::Dummy => Sugg::NonParen(snippet_with_context(cx, expr.span, ctxt, default, app).0), ast::ExprKind::Range(ref lhs, ref rhs, RangeLimits::HalfOpen) => Sugg::BinOp( AssocOp::DotDot, From 455ceff7c48fab31fc1113f4b07fe62014f13c51 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 23 Feb 2024 10:20:45 +1100 Subject: [PATCH 1089/1222] Rename `DiagnosticBuilder` as `Diag`. Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy. --- clippy_lints/src/casts/cast_possible_truncation.rs | 4 ++-- clippy_lints/src/disallowed_macros.rs | 4 ++-- clippy_lints/src/doc/needless_doctest_main.rs | 4 ++-- clippy_lints/src/functions/result.rs | 4 ++-- clippy_lints/src/if_let_mutex.rs | 4 ++-- clippy_lints/src/implicit_hasher.rs | 4 ++-- clippy_lints/src/manual_clamp.rs | 4 ++-- .../src/matches/significant_drop_in_scrutinee.rs | 4 ++-- .../src/methods/suspicious_command_arg_space.rs | 4 ++-- clippy_lints/src/missing_asserts_for_indexing.rs | 4 ++-- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- .../src/utils/internal_lints/metadata_collector.rs | 6 +++--- clippy_utils/src/diagnostics.rs | 12 ++++++------ clippy_utils/src/paths.rs | 2 +- clippy_utils/src/sugg.rs | 4 ++-- 15 files changed, 34 insertions(+), 34 deletions(-) diff --git a/clippy_lints/src/casts/cast_possible_truncation.rs b/clippy_lints/src/casts/cast_possible_truncation.rs index ab89bb2f5f15..2c0a3d482960 100644 --- a/clippy_lints/src/casts/cast_possible_truncation.rs +++ b/clippy_lints/src/casts/cast_possible_truncation.rs @@ -4,7 +4,7 @@ use clippy_utils::expr_or_init; use clippy_utils::source::snippet; use clippy_utils::sugg::Sugg; use clippy_utils::ty::{get_discriminant_value, is_isize_or_usize}; -use rustc_errors::{Applicability, DiagnosticBuilder, SuggestionStyle}; +use rustc_errors::{Applicability, Diag, SuggestionStyle}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; @@ -176,7 +176,7 @@ fn offer_suggestion( expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to_span: Span, - diag: &mut DiagnosticBuilder<'_, ()>, + diag: &mut Diag<'_, ()>, ) { let cast_to_snip = snippet(cx, cast_to_span, ".."); let suggestion = if cast_to_snip == "_" { diff --git a/clippy_lints/src/disallowed_macros.rs b/clippy_lints/src/disallowed_macros.rs index 75379cb4e545..4a617ba34d57 100644 --- a/clippy_lints/src/disallowed_macros.rs +++ b/clippy_lints/src/disallowed_macros.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then}; use clippy_utils::macros::macro_backtrace; use rustc_ast::Attribute; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_hir::def_id::DefIdMap; use rustc_hir::{ Expr, ExprKind, ForeignItem, HirId, ImplItem, Item, ItemKind, OwnerId, Pat, Path, Stmt, TraitItem, Ty, @@ -89,7 +89,7 @@ impl DisallowedMacros { if let Some(&index) = self.disallowed.get(&mac.def_id) { let conf = &self.conf_disallowed[index]; let msg = format!("use of a disallowed macro `{}`", conf.path()); - let add_note = |diag: &mut DiagnosticBuilder<'_, _>| { + let add_note = |diag: &mut Diag<'_, _>| { if let Some(reason) = conf.reason() { diag.note(reason); } diff --git a/clippy_lints/src/doc/needless_doctest_main.rs b/clippy_lints/src/doc/needless_doctest_main.rs index 8dde4f227ed1..58656140352f 100644 --- a/clippy_lints/src/doc/needless_doctest_main.rs +++ b/clippy_lints/src/doc/needless_doctest_main.rs @@ -6,7 +6,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_ast::{CoroutineKind, Fn, FnRetTy, Item, ItemKind}; use rustc_data_structures::sync::Lrc; use rustc_errors::emitter::HumanEmitter; -use rustc_errors::{DiagCtxt, DiagnosticBuilder}; +use rustc_errors::{Diag, DiagCtxt}; use rustc_lint::LateContext; use rustc_parse::maybe_new_parser_from_source_str; use rustc_parse::parser::ForceCollect; @@ -53,7 +53,7 @@ pub fn check( let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) { Ok(p) => p, Err(errs) => { - errs.into_iter().for_each(DiagnosticBuilder::cancel); + errs.into_iter().for_each(Diag::cancel); return (false, test_attr_spans); }, }; diff --git a/clippy_lints/src/functions/result.rs b/clippy_lints/src/functions/result.rs index 9505741e68ff..7f36f33fe708 100644 --- a/clippy_lints/src/functions/result.rs +++ b/clippy_lints/src/functions/result.rs @@ -1,4 +1,4 @@ -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_hir as hir; use rustc_lint::{LateContext, LintContext}; use rustc_middle::lint::in_external_macro; @@ -135,7 +135,7 @@ fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty RESULT_LARGE_ERR, hir_ty_span, "the `Err`-variant returned from this function is very large", - |diag: &mut DiagnosticBuilder<'_, ()>| { + |diag: &mut Diag<'_, ()>| { diag.span_label(hir_ty_span, format!("the `Err`-variant is at least {ty_size} bytes")); diag.help(format!("try reducing the size of `{err_ty}`, for example by boxing large elements or replacing it with `Box<{err_ty}>`")); }, diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index 61a322ea8812..a55836a972fb 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::{higher, SpanlessEq}; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_hir::intravisit::{self as visit, Visitor}; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; @@ -59,7 +59,7 @@ impl<'tcx> LateLintPass<'tcx> for IfLetMutex { arm_visit.visit_expr(if_else); if let Some(arm_mutex) = arm_visit.found_mutex_if_same_as(op_mutex) { - let diag = |diag: &mut DiagnosticBuilder<'_, ()>| { + let diag = |diag: &mut Diag<'_, ()>| { diag.span_label( op_mutex.span, "this Mutex will remain locked for the entire `if let`-block...", diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 746de50c0fa7..a79bf66ae013 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use std::collections::BTreeMap; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_hir as hir; use rustc_hir::intravisit::{walk_body, walk_expr, walk_inf, walk_ty, Visitor}; use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind}; @@ -65,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { fn suggestion( cx: &LateContext<'_>, - diag: &mut DiagnosticBuilder<'_, ()>, + diag: &mut Diag<'_, ()>, generics_span: Span, generics_suggestion_span: Span, target: &ImplicitHasherType<'_>, diff --git a/clippy_lints/src/manual_clamp.rs b/clippy_lints/src/manual_clamp.rs index 12bb80dfde2c..830af77968c0 100644 --- a/clippy_lints/src/manual_clamp.rs +++ b/clippy_lints/src/manual_clamp.rs @@ -9,7 +9,7 @@ use clippy_utils::{ peel_blocks_with_stmt, MaybePath, }; use itertools::Itertools; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_hir::def::Res; use rustc_hir::{Arm, BinOpKind, Block, Expr, ExprKind, HirId, PatKind, PathSegment, PrimTy, QPath, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; @@ -163,7 +163,7 @@ fn emit_suggestion<'tcx>(cx: &LateContext<'tcx>, suggestion: &ClampSuggestion<'t }; let suggestion = format!("{assignment}{input}.clamp({min}, {max}){semicolon}"); let msg = "clamp-like pattern without using clamp function"; - let lint_builder = |d: &mut DiagnosticBuilder<'_, ()>| { + let lint_builder = |d: &mut Diag<'_, ()>| { d.span_suggestion(*span, "replace with clamp", suggestion, Applicability::MaybeIncorrect); if *is_float { d.note("clamp will panic if max < min, min.is_nan(), or max.is_nan()") diff --git a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index 78107c0cd237..69f86836775d 100644 --- a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -2,7 +2,7 @@ use crate::FxHashSet; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::{indent_of, snippet}; use clippy_utils::{get_attr, is_lint_allowed}; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{Arm, Expr, ExprKind, MatchSource}; use rustc_lint::{LateContext, LintContext}; @@ -38,7 +38,7 @@ pub(super) fn check<'tcx>( } fn set_diagnostic<'tcx>( - diag: &mut DiagnosticBuilder<'_, ()>, + diag: &mut Diag<'_, ()>, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, found: FoundSigDrop, diff --git a/clippy_lints/src/methods/suspicious_command_arg_space.rs b/clippy_lints/src/methods/suspicious_command_arg_space.rs index 617d6d998fcc..38f2c9169124 100644 --- a/clippy_lints/src/methods/suspicious_command_arg_space.rs +++ b/clippy_lints/src/methods/suspicious_command_arg_space.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_type_diagnostic_item; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_lint::LateContext; use rustc_span::{sym, Span}; use {rustc_ast as ast, rustc_hir as hir}; @@ -22,7 +22,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, recv: &'tcx hir::Expr<'_>, arg SUSPICIOUS_COMMAND_ARG_SPACE, arg.span, "single argument that looks like it should be multiple arguments", - |diag: &mut DiagnosticBuilder<'_, ()>| { + |diag: &mut Diag<'_, ()>| { diag.multipart_suggestion_verbose( "consider splitting the argument", vec![(span, "args".to_string()), (arg.span, format!("[{arg1:?}, {arg2:?}]"))], diff --git a/clippy_lints/src/missing_asserts_for_indexing.rs b/clippy_lints/src/missing_asserts_for_indexing.rs index ab25dde7efee..39d4ea74b312 100644 --- a/clippy_lints/src/missing_asserts_for_indexing.rs +++ b/clippy_lints/src/missing_asserts_for_indexing.rs @@ -9,7 +9,7 @@ use clippy_utils::{eq_expr_value, hash_expr, higher}; use rustc_ast::{LitKind, RangeLimits}; use rustc_data_structures::packed::Pu128; use rustc_data_structures::unhash::UnhashMap; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_hir::{BinOp, Block, Body, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; @@ -67,7 +67,7 @@ declare_lint_pass!(MissingAssertsForIndexing => [MISSING_ASSERTS_FOR_INDEXING]); fn report_lint(cx: &LateContext<'_>, full_span: Span, msg: &str, indexes: &[Span], f: F) where - F: FnOnce(&mut DiagnosticBuilder<'_, ()>), + F: FnOnce(&mut Diag<'_, ()>), { span_lint_and_then(cx, MISSING_ASSERTS_FOR_INDEXING, full_span, msg, |diag| { f(diag); diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 6252f91b25f8..f33e2e0ed71a 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -6,7 +6,7 @@ use clippy_utils::ty::{ implements_trait, implements_trait_with_env_from_iter, is_copy, is_type_diagnostic_item, is_type_lang_item, }; use rustc_ast::ast::Attribute; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diag}; use rustc_hir::intravisit::FnKind; use rustc_hir::{ BindingAnnotation, Body, FnDecl, GenericArg, HirId, HirIdSet, Impl, ItemKind, LangItem, Mutability, Node, PatKind, @@ -196,7 +196,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { && !moved_vars.contains(&canonical_id) { // Dereference suggestion - let sugg = |diag: &mut DiagnosticBuilder<'_, ()>| { + let sugg = |diag: &mut Diag<'_, ()>| { if let ty::Adt(def, ..) = ty.kind() { if let Some(span) = cx.tcx.hir().span_if_local(def.did()) { if type_allowed_to_implement_copy( diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index 6fceb5656a68..97b509a84f93 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -74,7 +74,7 @@ const LINT_EMISSION_FUNCTIONS: [&[&str]; 7] = [ &["clippy_utils", "diagnostics", "span_lint_and_then"], &["clippy_utils", "diagnostics", "span_lint_hir_and_then"], ]; -const SUGGESTION_DIAGNOSTIC_BUILDER_METHODS: [(&str, bool); 9] = [ +const SUGGESTION_DIAG_METHODS: [(&str, bool); 9] = [ ("span_suggestion", false), ("span_suggestion_short", false), ("span_suggestion_verbose", false), @@ -1067,9 +1067,9 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for IsMultiSpanScanner<'a, 'hir> { }, ExprKind::MethodCall(path, recv, _, _arg_span) => { let (self_ty, _) = walk_ptrs_ty_depth(self.cx.typeck_results().expr_ty(recv)); - if match_type(self.cx, self_ty, &paths::DIAGNOSTIC_BUILDER) { + if match_type(self.cx, self_ty, &paths::DIAG) { let called_method = path.ident.name.as_str().to_string(); - for (method_name, is_multi_part) in &SUGGESTION_DIAGNOSTIC_BUILDER_METHODS { + for (method_name, is_multi_part) in &SUGGESTION_DIAG_METHODS { if *method_name == called_method { if *is_multi_part { self.add_multi_part_suggestion(); diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs index e725390d8cc2..6ed46e5dde04 100644 --- a/clippy_utils/src/diagnostics.rs +++ b/clippy_utils/src/diagnostics.rs @@ -8,13 +8,13 @@ //! Thank you! //! ~The `INTERNAL_METADATA_COLLECTOR` lint -use rustc_errors::{Applicability, DiagnosticBuilder, MultiSpan}; +use rustc_errors::{Applicability, Diag, MultiSpan}; use rustc_hir::HirId; use rustc_lint::{LateContext, Lint, LintContext}; use rustc_span::Span; use std::env; -fn docs_link(diag: &mut DiagnosticBuilder<'_, ()>, lint: &'static Lint) { +fn docs_link(diag: &mut Diag<'_, ()>, lint: &'static Lint) { if env::var("CLIPPY_DISABLE_DOCS_LINKS").is_err() { if let Some(lint) = lint.name_lower().strip_prefix("clippy::") { diag.help(format!( @@ -143,7 +143,7 @@ pub fn span_lint_and_then(cx: &C, lint: &'static Lint, sp: S, msg: &str where C: LintContext, S: Into, - F: FnOnce(&mut DiagnosticBuilder<'_, ()>), + F: FnOnce(&mut Diag<'_, ()>), { #[expect(clippy::disallowed_methods)] cx.span_lint(lint, sp, msg.to_string(), |diag| { @@ -165,7 +165,7 @@ pub fn span_lint_hir_and_then( hir_id: HirId, sp: impl Into, msg: &str, - f: impl FnOnce(&mut DiagnosticBuilder<'_, ()>), + f: impl FnOnce(&mut Diag<'_, ()>), ) { #[expect(clippy::disallowed_methods)] cx.tcx.node_span_lint(lint, hir_id, sp, msg.to_string(), |diag| { @@ -214,7 +214,7 @@ pub fn span_lint_and_sugg( /// appear once per /// replacement. In human-readable format though, it only appears once before /// the whole suggestion. -pub fn multispan_sugg(diag: &mut DiagnosticBuilder<'_, ()>, help_msg: &str, sugg: I) +pub fn multispan_sugg(diag: &mut Diag<'_, ()>, help_msg: &str, sugg: I) where I: IntoIterator, { @@ -227,7 +227,7 @@ where /// multiple spans. This is tracked in issue [rustfix#141](https://github.com/rust-lang/rustfix/issues/141). /// Suggestions with multiple spans will be silently ignored. pub fn multispan_sugg_with_applicability( - diag: &mut DiagnosticBuilder<'_, ()>, + diag: &mut Diag<'_, ()>, help_msg: &str, applicability: Applicability, sugg: I, diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index a51ada8aa126..2f728b62754e 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -11,7 +11,7 @@ pub const APPLICABILITY_VALUES: [[&str; 3]; 4] = [ ["rustc_lint_defs", "Applicability", "MaybeIncorrect"], ["rustc_lint_defs", "Applicability", "MachineApplicable"], ]; -pub const DIAGNOSTIC_BUILDER: [&str; 2] = ["rustc_errors", "DiagnosticBuilder"]; +pub const DIAG: [&str; 2] = ["rustc_errors", "Diag"]; pub const BINARYHEAP_ITER: [&str; 5] = ["alloc", "collections", "binary_heap", "BinaryHeap", "iter"]; pub const BTREEMAP_CONTAINS_KEY: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "contains_key"]; pub const BTREEMAP_INSERT: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "insert"]; diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 1f6446b8746e..d2ec327534a8 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -684,7 +684,7 @@ fn indentation(cx: &T, span: Span) -> Option { }) } -/// Convenience extension trait for `DiagnosticBuilder`. +/// Convenience extension trait for `Diag`. pub trait DiagnosticExt { /// Suggests to add an attribute to an item. /// @@ -732,7 +732,7 @@ pub trait DiagnosticExt { fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str, applicability: Applicability); } -impl DiagnosticExt for rustc_errors::DiagnosticBuilder<'_, ()> { +impl DiagnosticExt for rustc_errors::Diag<'_, ()> { fn suggest_item_with_attr( &mut self, cx: &T, From 56f134b86e5008266f5d225eb475994fc64cc656 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 5 Feb 2024 16:27:53 +1100 Subject: [PATCH 1090/1222] Remove the `UntranslatableDiagnosticTrivial` lint. It's a specialized form of the `UntranslatableDiagnostic` lint that is deny-by-default. Now that `UntranslatableDiagnostic` has been changed from allow-by-default to deny-by-default, the trivial variant is no longer needed. --- clippy_config/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_config/src/lib.rs b/clippy_config/src/lib.rs index dab3119894a4..3d5002f1780a 100644 --- a/clippy_config/src/lib.rs +++ b/clippy_config/src/lib.rs @@ -6,7 +6,6 @@ clippy::missing_panics_doc, rustc::diagnostic_outside_of_impl, rustc::untranslatable_diagnostic, - rustc::untranslatable_diagnostic_trivial )] extern crate rustc_ast; From e441d162bb9f6cf0009de9e8ee7e966f46c90c17 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 28 Feb 2024 15:49:48 +1100 Subject: [PATCH 1091/1222] Use `LitKind::Err` for floats with empty exponents. This prevents a follow-up type error in a test, which seems fine. --- tests/ui/crashes/ice-10912.rs | 2 -- tests/ui/crashes/ice-10912.stderr | 11 +---------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/tests/ui/crashes/ice-10912.rs b/tests/ui/crashes/ice-10912.rs index 8dfce1942217..1d689e1d0082 100644 --- a/tests/ui/crashes/ice-10912.rs +++ b/tests/ui/crashes/ice-10912.rs @@ -2,7 +2,5 @@ //@no-rustfix fn f2() -> impl Sized { && 3.14159265358979323846E } //~^ ERROR: expected at least one digit in exponent -//~| ERROR: long literal lacking separators -//~| NOTE: `-D clippy::unreadable-literal` implied by `-D warnings` fn main() {} diff --git a/tests/ui/crashes/ice-10912.stderr b/tests/ui/crashes/ice-10912.stderr index cc80354c7c62..c697e54679f9 100644 --- a/tests/ui/crashes/ice-10912.stderr +++ b/tests/ui/crashes/ice-10912.stderr @@ -4,14 +4,5 @@ error: expected at least one digit in exponent LL | fn f2() -> impl Sized { && 3.14159265358979323846E } | ^^^^^^^^^^^^^^^^^^^^^^^ -error: long literal lacking separators - --> tests/ui/crashes/ice-10912.rs:3:28 - | -LL | fn f2() -> impl Sized { && 3.14159265358979323846E } - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider: `3.141_592_653_589_793_238_46` - | - = note: `-D clippy::unreadable-literal` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::unreadable_literal)]` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error From be5b3ce5c204bf5cd113199b2c0d7e02dab1eb1c Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 28 Feb 2024 03:53:58 -0500 Subject: [PATCH 1092/1222] Add stubs for `f16` and `f128` to clippy --- clippy_lints/src/float_literal.rs | 4 ++++ clippy_utils/src/consts.rs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index 38a16c5c8b0b..cffca952e47a 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -81,6 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral { LitFloatType::Unsuffixed => None, }; let (is_whole, is_inf, mut float_str) = match fty { + FloatTy::F16 => unimplemented!("f16_f128"), FloatTy::F32 => { let value = sym_str.parse::().unwrap(); @@ -91,6 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral { (value.fract() == 0.0, value.is_infinite(), formatter.format(value)) }, + FloatTy::F128 => unimplemented!("f16_f128"), }; if is_inf { @@ -135,8 +137,10 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral { #[must_use] fn max_digits(fty: FloatTy) -> u32 { match fty { + FloatTy::F16 => unimplemented!("f16_f128"), FloatTy::F32 => f32::DIGITS, FloatTy::F64 => f64::DIGITS, + FloatTy::F128 => unimplemented!("f16_f128"), } } diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 79c691992a85..1f2b2d54efd6 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -778,8 +778,10 @@ pub fn mir_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::Const<'tcx>) -> let range = alloc_range(offset + size * idx, size); let val = alloc.read_scalar(&lcx.tcx, range, /* read_provenance */ false).ok()?; res.push(match flt { + FloatTy::F16 => unimplemented!("f16_f128"), FloatTy::F32 => Constant::F32(f32::from_bits(val.to_u32().ok()?)), FloatTy::F64 => Constant::F64(f64::from_bits(val.to_u64().ok()?)), + FloatTy::F128 => unimplemented!("f16_f128"), }); } Some(Constant::Vec(res)) From fdb6e76592d7d733c4485216c47ab50445db7ffc Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 26 Feb 2024 15:21:01 +1100 Subject: [PATCH 1093/1222] Overhaul how stashed diagnostics work, again. Stashed errors used to be counted as errors, but could then be cancelled, leading to `ErrorGuaranteed` soundness holes. #120828 changed that, closing the soundness hole. But it introduced other difficulties because you sometimes have to account for pending stashed errors when making decisions about whether errors have occured/will occur and it's easy to overlook these. This commit aims for a middle ground. - Stashed errors (not warnings) are counted immediately as emitted errors, avoiding the possibility of forgetting to consider them. - The ability to cancel (or downgrade) stashed errors is eliminated, by disallowing the use of `steal_diagnostic` with errors, and introducing the more restrictive methods `try_steal_{modify,replace}_and_emit_err` that can be used instead. Other things: - `DiagnosticBuilder::stash` and `DiagCtxt::stash_diagnostic` now both return `Option`, which enables the removal of two `delayed_bug` calls and one `Ty::new_error_with_message` call. This is possible because we store error guarantees in `DiagCtxt::stashed_diagnostics`. - Storing the guarantees also saves us having to maintain a counter. - Calls to the `stashed_err_count` method are no longer necessary alongside calls to `has_errors`, which is a nice simplification, and eliminates two more `span_delayed_bug` calls and one FIXME comment. - Tests are added for three of the four fixed PRs mentioned below. - `issue-121108.rs`'s output improved slightly, omitting a non-useful error message. Fixes #121451. Fixes #121477. Fixes #121504. Fixes #121508. --- tests/ui/crashes/unreachable-array-or-slice.rs | 8 ++++++++ tests/ui/crashes/unreachable-array-or-slice.stderr | 9 +++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/ui/crashes/unreachable-array-or-slice.rs create mode 100644 tests/ui/crashes/unreachable-array-or-slice.stderr diff --git a/tests/ui/crashes/unreachable-array-or-slice.rs b/tests/ui/crashes/unreachable-array-or-slice.rs new file mode 100644 index 000000000000..b56abccbd411 --- /dev/null +++ b/tests/ui/crashes/unreachable-array-or-slice.rs @@ -0,0 +1,8 @@ +struct Foo(isize, isize, isize, isize); + +pub fn main() { + let Self::anything_here_kills_it(a, b, ..) = Foo(5, 5, 5, 5); + match [5, 5, 5, 5] { + [..] => { } + } +} diff --git a/tests/ui/crashes/unreachable-array-or-slice.stderr b/tests/ui/crashes/unreachable-array-or-slice.stderr new file mode 100644 index 000000000000..9e0d3b934b80 --- /dev/null +++ b/tests/ui/crashes/unreachable-array-or-slice.stderr @@ -0,0 +1,9 @@ +error[E0433]: failed to resolve: `Self` is only available in impls, traits, and type definitions + --> tests/ui/crashes/unreachable-array-or-slice.rs:4:9 + | +LL | let Self::anything_here_kills_it(a, b, ..) = Foo(5, 5, 5, 5); + | ^^^^ `Self` is only available in impls, traits, and type definitions + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0433`. From 2089bc9bc5289a26ce5f8c50e91a9fc4f659767d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Feb 2024 11:50:32 +1100 Subject: [PATCH 1094/1222] Rename `DiagCtxt::with_emitter` as `DiagCtxt::new`. Because it's now the only constructor. --- clippy_lints/src/doc/needless_doctest_main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/doc/needless_doctest_main.rs b/clippy_lints/src/doc/needless_doctest_main.rs index 58656140352f..fdb9ceb7179a 100644 --- a/clippy_lints/src/doc/needless_doctest_main.rs +++ b/clippy_lints/src/doc/needless_doctest_main.rs @@ -45,7 +45,7 @@ pub fn check( let fallback_bundle = rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false); let emitter = HumanEmitter::new(Box::new(io::sink()), fallback_bundle); - let dcx = DiagCtxt::with_emitter(Box::new(emitter)).disable_warnings(); + let dcx = DiagCtxt::new(Box::new(emitter)).disable_warnings(); #[expect(clippy::arc_with_non_send_sync)] // `Lrc` is expected by with_dcx let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sess = ParseSess::with_dcx(dcx, sm); From a2cfec7beb665b25dc398f727dce017f5df0ba75 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Fri, 26 Jan 2024 15:32:59 +0000 Subject: [PATCH 1095/1222] If suggestion would leave an empty line, delete it --- tests/ui/derivable_impls.fixed | 8 -------- tests/ui/empty_drop.fixed | 2 -- tests/ui/must_use_unit.fixed | 3 --- tests/ui/single_component_path_imports.fixed | 1 - 4 files changed, 14 deletions(-) diff --git a/tests/ui/derivable_impls.fixed b/tests/ui/derivable_impls.fixed index 68c5a5c5ca45..c85f384fd6eb 100644 --- a/tests/ui/derivable_impls.fixed +++ b/tests/ui/derivable_impls.fixed @@ -19,12 +19,10 @@ struct FooDefault<'a> { } - #[derive(Default)] struct TupleDefault(bool, i32, u64); - struct FooND1 { a: bool, } @@ -73,7 +71,6 @@ impl Default for FooNDVec { struct StrDefault<'a>(&'a str); - #[derive(Default)] struct AlreadyDerived(i32, bool); @@ -96,7 +93,6 @@ mac!(0); #[derive(Default)] struct Y(u32); - struct RustIssue26925 { a: Option, } @@ -132,12 +128,10 @@ struct WithoutSelfCurly { } - #[derive(Default)] struct WithoutSelfParan(bool); - // https://github.com/rust-lang/rust-clippy/issues/7655 pub struct SpecializedImpl2 { @@ -184,7 +178,6 @@ pub struct RepeatDefault1 { } - pub struct RepeatDefault2 { a: [i8; 33], } @@ -216,7 +209,6 @@ pub enum SimpleEnum { } - pub enum NonExhaustiveEnum { Foo, #[non_exhaustive] diff --git a/tests/ui/empty_drop.fixed b/tests/ui/empty_drop.fixed index 949d0d8b3997..17cfdcdc9c68 100644 --- a/tests/ui/empty_drop.fixed +++ b/tests/ui/empty_drop.fixed @@ -5,7 +5,6 @@ struct Foo; - // shouldn't cause an error struct Bar; @@ -19,5 +18,4 @@ impl Drop for Bar { struct Baz; - fn main() {} diff --git a/tests/ui/must_use_unit.fixed b/tests/ui/must_use_unit.fixed index 75f91e668242..f255cb666528 100644 --- a/tests/ui/must_use_unit.fixed +++ b/tests/ui/must_use_unit.fixed @@ -6,13 +6,10 @@ extern crate proc_macros; use proc_macros::external; - pub fn must_use_default() {} - pub fn must_use_unit() -> () {} - pub fn must_use_with_note() {} fn main() { diff --git a/tests/ui/single_component_path_imports.fixed b/tests/ui/single_component_path_imports.fixed index fdff336c281b..3e81bcd5e487 100644 --- a/tests/ui/single_component_path_imports.fixed +++ b/tests/ui/single_component_path_imports.fixed @@ -4,7 +4,6 @@ use core; - use serde as edres; pub use serde; From 97cae4c3af3ec7efa7060c4f207da4ba599223f8 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 1 Mar 2024 04:03:46 -0500 Subject: [PATCH 1096/1222] Propegate HIR and AST `f16` and `f128` types to clippy --- clippy_lints/src/approx_const.rs | 3 +++ clippy_lints/src/float_literal.rs | 2 ++ clippy_utils/src/consts.rs | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index 409ae0c85acf..25606f4253e4 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -75,9 +75,12 @@ impl ApproxConstant { fn check_lit(&self, cx: &LateContext<'_>, lit: &LitKind, e: &Expr<'_>) { match *lit { LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty { + FloatTy::F16 => self.check_known_consts(cx, e, s, "f16"), FloatTy::F32 => self.check_known_consts(cx, e, s, "f32"), FloatTy::F64 => self.check_known_consts(cx, e, s, "f64"), + FloatTy::F128 => self.check_known_consts(cx, e, s, "f128"), }, + // FIXME(f16_f128): add `f16` and `f128` when these types become stable. LitKind::Float(s, LitFloatType::Unsuffixed) => self.check_known_consts(cx, e, s, "f{32, 64}"), _ => (), } diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index cffca952e47a..07fbb1cb5c9f 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -76,8 +76,10 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral { let digits = count_digits(sym_str); let max = max_digits(fty); let type_suffix = match lit_float_ty { + LitFloatType::Suffixed(ast::FloatTy::F16) => Some("f16"), LitFloatType::Suffixed(ast::FloatTy::F32) => Some("f32"), LitFloatType::Suffixed(ast::FloatTy::F64) => Some("f64"), + LitFloatType::Suffixed(ast::FloatTy::F128) => Some("f128"), LitFloatType::Unsuffixed => None, }; let (is_whole, is_inf, mut float_str) = match fty { diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 1f2b2d54efd6..07ed4fbbf8e9 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -277,12 +277,16 @@ pub fn lit_to_mir_constant<'tcx>(lit: &LitKind, ty: Option>) -> Constan LitKind::Char(c) => Constant::Char(c), LitKind::Int(n, _) => Constant::Int(n.get()), LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty { + ast::FloatTy::F16 => unimplemented!("f16_f128"), ast::FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()), ast::FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()), + ast::FloatTy::F128 => unimplemented!("f16_f128"), }, LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind() { + ty::Float(FloatTy::F16) => unimplemented!("f16_f128"), ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()), ty::Float(FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()), + ty::Float(FloatTy::F128) => unimplemented!("f16_f128"), _ => bug!(), }, LitKind::Bool(b) => Constant::Bool(b), From 3433e0fa8a9b7ec3aad441bfcdd729550598da78 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 19 Feb 2024 22:51:45 +0000 Subject: [PATCH 1097/1222] Add `is_intrinsic` helper --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 183dbe3aecc1..e369cb9d0a40 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -334,7 +334,7 @@ fn check_terminator<'tcx>( // within const fns. `transmute` is allowed in all other const contexts. // This won't really scale to more intrinsics or functions. Let's allow const // transmutes in const fn before we add more hacks to this. - if matches!(tcx.intrinsic(fn_def_id), Some(sym::transmute)) { + if tcx.is_intrinsic(fn_def_id, sym::transmute) { return Err(( span, "can only call `transmute` from const items, not `const fn`".into(), From bbd9a5ceceb175a022a958a53d1a5358b99da236 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 4 Mar 2024 16:31:49 +1100 Subject: [PATCH 1098/1222] Rename all `ParseSess` variables/fields/lifetimes as `psess`. Existing names for values of this type are `sess`, `parse_sess`, `parse_session`, and `ps`. `sess` is particularly annoying because that's also used for `Session` values, which are often co-located, and it can be difficult to know which type a value named `sess` refers to. (That annoyance is the main motivation for this change.) `psess` is nice and short, which is good for a name used this much. The commit also renames some `parse_sess_created` values as `psess_created`. --- clippy_lints/src/disallowed_script_idents.rs | 2 +- clippy_lints/src/doc/needless_doctest_main.rs | 4 ++-- src/driver.rs | 20 +++++++++---------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/disallowed_script_idents.rs b/clippy_lints/src/disallowed_script_idents.rs index d5205e65cef3..0c1bb2da7e89 100644 --- a/clippy_lints/src/disallowed_script_idents.rs +++ b/clippy_lints/src/disallowed_script_idents.rs @@ -72,7 +72,7 @@ impl EarlyLintPass for DisallowedScriptIdents { return; } - let symbols = cx.sess().parse_sess.symbol_gallery.symbols.lock(); + let symbols = cx.sess().psess.symbol_gallery.symbols.lock(); // Sort by `Span` so that error messages make sense with respect to the // order of identifier locations in the code. let mut symbols: Vec<_> = symbols.iter().collect(); diff --git a/clippy_lints/src/doc/needless_doctest_main.rs b/clippy_lints/src/doc/needless_doctest_main.rs index fdb9ceb7179a..e55a988321b3 100644 --- a/clippy_lints/src/doc/needless_doctest_main.rs +++ b/clippy_lints/src/doc/needless_doctest_main.rs @@ -48,9 +48,9 @@ pub fn check( let dcx = DiagCtxt::new(Box::new(emitter)).disable_warnings(); #[expect(clippy::arc_with_non_send_sync)] // `Lrc` is expected by with_dcx let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let sess = ParseSess::with_dcx(dcx, sm); + let psess = ParseSess::with_dcx(dcx, sm); - let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) { + let mut parser = match maybe_new_parser_from_source_str(&psess, filename, code) { Ok(p) => p, Err(errs) => { errs.into_iter().for_each(Diag::cancel); diff --git a/src/driver.rs b/src/driver.rs index b966fcf9b80f..8fc66644632c 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -68,8 +68,8 @@ fn test_arg_value() { assert_eq!(arg_value(args, "--foo", |_| true), None); } -fn track_clippy_args(parse_sess: &mut ParseSess, args_env_var: &Option) { - parse_sess.env_depinfo.get_mut().insert(( +fn track_clippy_args(psess: &mut ParseSess, args_env_var: &Option) { + psess.env_depinfo.get_mut().insert(( Symbol::intern("CLIPPY_ARGS"), args_env_var.as_deref().map(Symbol::intern), )); @@ -77,8 +77,8 @@ fn track_clippy_args(parse_sess: &mut ParseSess, args_env_var: &Option) /// Track files that may be accessed at runtime in `file_depinfo` so that cargo will re-run clippy /// when any of them are modified -fn track_files(parse_sess: &mut ParseSess) { - let file_depinfo = parse_sess.file_depinfo.get_mut(); +fn track_files(psess: &mut ParseSess) { + let file_depinfo = psess.file_depinfo.get_mut(); // Used by `clippy::cargo` lints and to determine the MSRV. `cargo clippy` executes `clippy-driver` // with the current directory set to `CARGO_MANIFEST_DIR` so a relative path is fine @@ -115,8 +115,8 @@ struct RustcCallbacks { impl rustc_driver::Callbacks for RustcCallbacks { fn config(&mut self, config: &mut interface::Config) { let clippy_args_var = self.clippy_args_var.take(); - config.parse_sess_created = Some(Box::new(move |parse_sess| { - track_clippy_args(parse_sess, &clippy_args_var); + config.psess_created = Some(Box::new(move |psess| { + track_clippy_args(psess, &clippy_args_var); })); } } @@ -132,13 +132,13 @@ impl rustc_driver::Callbacks for ClippyCallbacks { let conf_path = clippy_config::lookup_conf_file(); let previous = config.register_lints.take(); let clippy_args_var = self.clippy_args_var.take(); - config.parse_sess_created = Some(Box::new(move |parse_sess| { - track_clippy_args(parse_sess, &clippy_args_var); - track_files(parse_sess); + config.psess_created = Some(Box::new(move |psess| { + track_clippy_args(psess, &clippy_args_var); + track_files(psess); // Trigger a rebuild if CLIPPY_CONF_DIR changes. The value must be a valid string so // changes between dirs that are invalid UTF-8 will not trigger rebuilds - parse_sess.env_depinfo.get_mut().insert(( + psess.env_depinfo.get_mut().insert(( Symbol::intern("CLIPPY_CONF_DIR"), env::var("CLIPPY_CONF_DIR").ok().map(|dir| Symbol::intern(&dir)), )); From ee4ab2f8a8a51cd7cf77c6f728b2c8308f788b2e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Feb 2024 11:58:51 +1100 Subject: [PATCH 1099/1222] Rename `DiagnosticMessage` as `DiagMessage`. --- tests/ui-internal/disallow_span_lint.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/ui-internal/disallow_span_lint.rs b/tests/ui-internal/disallow_span_lint.rs index b9b4a07d29d0..c5029bbd9a42 100644 --- a/tests/ui-internal/disallow_span_lint.rs +++ b/tests/ui-internal/disallow_span_lint.rs @@ -5,12 +5,17 @@ extern crate rustc_hir; extern crate rustc_lint; extern crate rustc_middle; -use rustc_errors::{DiagnosticMessage, MultiSpan}; +use rustc_errors::{DiagMessage, MultiSpan}; use rustc_hir::hir_id::HirId; use rustc_lint::{Lint, LintContext}; use rustc_middle::ty::TyCtxt; -pub fn a(cx: impl LintContext, lint: &'static Lint, span: impl Into, msg: impl Into) { +pub fn a( + cx: impl LintContext, + lint: &'static Lint, + span: impl Into, + msg: impl Into) +{ cx.span_lint(lint, span, msg, |_| {}); } @@ -19,7 +24,7 @@ pub fn b( lint: &'static Lint, hir_id: HirId, span: impl Into, - msg: impl Into, + msg: impl Into, ) { tcx.node_span_lint(lint, hir_id, span, msg, |_| {}); } From 091d030915e8ad23ff6fd90f94bfaf201e506742 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Feb 2024 16:34:08 +1100 Subject: [PATCH 1100/1222] Rename `DiagnosticExt` as `DiagExt`. --- clippy_lints/src/inline_fn_without_body.rs | 2 +- clippy_lints/src/new_without_default.rs | 2 +- clippy_utils/src/sugg.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index bc236c5c71fd..83ecaeef9825 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -1,7 +1,7 @@ //! checks for `#[inline]` on trait methods without bodies use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::sugg::DiagnosticExt; +use clippy_utils::sugg::DiagExt; use rustc_ast::ast::Attribute; use rustc_errors::Applicability; use rustc_hir::{TraitFn, TraitItem, TraitItemKind}; diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index b3b8a5e99638..627b4968d9f6 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::return_ty; use clippy_utils::source::snippet; -use clippy_utils::sugg::DiagnosticExt; +use clippy_utils::sugg::DiagExt; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::HirIdSet; diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index d2ec327534a8..e74621a0fbba 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -685,7 +685,7 @@ fn indentation(cx: &T, span: Span) -> Option { } /// Convenience extension trait for `Diag`. -pub trait DiagnosticExt { +pub trait DiagExt { /// Suggests to add an attribute to an item. /// /// Correctly handles indentation of the attribute and item. @@ -732,7 +732,7 @@ pub trait DiagnosticExt { fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str, applicability: Applicability); } -impl DiagnosticExt for rustc_errors::Diag<'_, ()> { +impl DiagExt for rustc_errors::Diag<'_, ()> { fn suggest_item_with_attr( &mut self, cx: &T, From 0e3f8e690fa78e0db0e28592970644b74a9c793b Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Sat, 24 Feb 2024 17:22:28 -0500 Subject: [PATCH 1101/1222] Convert `TypeVisitor` and `DefIdVisitor` to use `VisitorResult` --- clippy_lints/src/methods/useless_asref.rs | 4 ++-- clippy_utils/src/mir/possible_borrower.rs | 4 ++-- clippy_utils/src/ty.rs | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/methods/useless_asref.rs b/clippy_lints/src/methods/useless_asref.rs index 514015af0455..b8baad18cc8d 100644 --- a/clippy_lints/src/methods/useless_asref.rs +++ b/clippy_lints/src/methods/useless_asref.rs @@ -22,9 +22,9 @@ fn get_enum_ty(enum_ty: Ty<'_>) -> Option> { } impl<'tcx> TypeVisitor> for ContainsTyVisitor { - type BreakTy = Ty<'tcx>; + type Result = ControlFlow>; - fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { + fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result { self.level += 1; if self.level == 1 { t.super_visit_with(self) diff --git a/clippy_utils/src/mir/possible_borrower.rs b/clippy_utils/src/mir/possible_borrower.rs index f9cc5f191253..06229ac938f9 100644 --- a/clippy_utils/src/mir/possible_borrower.rs +++ b/clippy_utils/src/mir/possible_borrower.rs @@ -141,9 +141,9 @@ impl<'a, 'b, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'b, struct ContainsRegion; impl TypeVisitor> for ContainsRegion { - type BreakTy = (); + type Result = ControlFlow<()>; - fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow { + fn visit_region(&mut self, _: ty::Region<'_>) -> Self::Result { ControlFlow::Break(()) } } diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 6762c8830050..6e011a28bb7b 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -916,8 +916,8 @@ pub fn for_each_top_level_late_bound_region( f: F, } impl<'tcx, B, F: FnMut(BoundRegion) -> ControlFlow> TypeVisitor> for V { - type BreakTy = B; - fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow { + type Result = ControlFlow; + fn visit_region(&mut self, r: Region<'tcx>) -> Self::Result { if let RegionKind::ReBound(idx, bound) = r.kind() && idx.as_u32() == self.index { @@ -926,7 +926,7 @@ pub fn for_each_top_level_late_bound_region( ControlFlow::Continue(()) } } - fn visit_binder>>(&mut self, t: &Binder<'tcx, T>) -> ControlFlow { + fn visit_binder>>(&mut self, t: &Binder<'tcx, T>) -> Self::Result { self.index += 1; let res = t.super_visit_with(self); self.index -= 1; From 4f77985bfa15ea5d717c514f13e3deb469ec2c18 Mon Sep 17 00:00:00 2001 From: Ross Smyth Date: Sat, 17 Feb 2024 12:43:54 -0500 Subject: [PATCH 1102/1222] Add MatchKind member to the Match expr for pretty printing & fmt --- clippy_lints/src/redundant_else.rs | 2 +- clippy_lints/src/suspicious_operation_groupings.rs | 2 +- clippy_utils/src/ast_utils.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/redundant_else.rs b/clippy_lints/src/redundant_else.rs index fb434fb7450a..3bdf13dbbea6 100644 --- a/clippy_lints/src/redundant_else.rs +++ b/clippy_lints/src/redundant_else.rs @@ -105,7 +105,7 @@ impl<'ast> Visitor<'ast> for BreakVisitor { fn visit_expr(&mut self, expr: &'ast Expr) { self.is_break = match expr.kind { ExprKind::Break(..) | ExprKind::Continue(..) | ExprKind::Ret(..) => true, - ExprKind::Match(_, ref arms) => arms.iter().all(|arm| + ExprKind::Match(_, ref arms, _) => arms.iter().all(|arm| arm.body.is_none() || arm.body.as_deref().is_some_and(|body| self.check_expr(body)) ), ExprKind::If(_, ref then, Some(ref els)) => self.check_block(then) && self.check_expr(els), diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index 60e9d262e7e0..ab1b3043f0c3 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -552,7 +552,7 @@ fn ident_difference_expr_with_base_location( | (Gen(_, _, _), Gen(_, _, _)) | (Block(_, _), Block(_, _)) | (Closure(_), Closure(_)) - | (Match(_, _), Match(_, _)) + | (Match(_, _, _), Match(_, _, _)) | (Loop(_, _, _), Loop(_, _, _)) | (ForLoop { .. }, ForLoop { .. }) | (While(_, _, _), While(_, _, _)) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 3b3939da7b6b..eb916a37f6ea 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -198,7 +198,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { }, (AssignOp(lo, lp, lv), AssignOp(ro, rp, rv)) => lo.node == ro.node && eq_expr(lp, rp) && eq_expr(lv, rv), (Field(lp, lf), Field(rp, rf)) => eq_id(*lf, *rf) && eq_expr(lp, rp), - (Match(ls, la), Match(rs, ra)) => eq_expr(ls, rs) && over(la, ra, eq_arm), + (Match(ls, la, lkind), Match(rs, ra, rkind)) => (lkind == rkind) && eq_expr(ls, rs) && over(la, ra, eq_arm), ( Closure(box ast::Closure { binder: lb, From 4cbfcd5f167240e584fc60a8c2544798caa0d1e0 Mon Sep 17 00:00:00 2001 From: beetrees Date: Mon, 15 May 2023 18:37:47 +0000 Subject: [PATCH 1103/1222] Use `rustc_driver::args::raw_args()` in Clippy --- src/driver.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver.rs b/src/driver.rs index 8fc66644632c..9e42abbc9aa9 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -190,7 +190,7 @@ pub fn main() { }); exit(rustc_driver::catch_with_exit_code(move || { - let mut orig_args: Vec = env::args().collect(); + let mut orig_args = rustc_driver::args::raw_args(&early_dcx)?; let has_sysroot_arg = |args: &mut [String]| -> bool { if arg_value(args, "--sysroot", |_| true).is_some() { From 7648d81943be339c070ea2d8b7b9269b233028e9 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Mon, 26 Feb 2024 21:25:27 -0500 Subject: [PATCH 1104/1222] Distinguish between library and lang UB in assert_unsafe_precondition --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index e369cb9d0a40..dadb0d662ce8 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -174,7 +174,7 @@ fn check_rvalue<'tcx>( )) } }, - Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_) | NullOp::DebugAssertions, _) + Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_) | NullOp::UbCheck(_), _) | Rvalue::ShallowInitBox(_, _) => Ok(()), Rvalue::UnaryOp(_, operand) => { let ty = operand.ty(body, tcx); From a85871667f85420061a917d6b911164de6585421 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 17 Jan 2024 14:50:49 +0100 Subject: [PATCH 1105/1222] Allow lint where we don't care --- tests/ui/manual_range_patterns.fixed | 1 + tests/ui/manual_range_patterns.rs | 1 + tests/ui/manual_range_patterns.stderr | 38 +++++++++++++-------------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/tests/ui/manual_range_patterns.fixed b/tests/ui/manual_range_patterns.fixed index b348d7071f6e..e9f6fbcc3fc8 100644 --- a/tests/ui/manual_range_patterns.fixed +++ b/tests/ui/manual_range_patterns.fixed @@ -1,4 +1,5 @@ #![allow(unused)] +#![allow(non_contiguous_range_endpoints)] #![warn(clippy::manual_range_patterns)] #![feature(exclusive_range_pattern)] diff --git a/tests/ui/manual_range_patterns.rs b/tests/ui/manual_range_patterns.rs index a0750f54b73f..d525aaa24ad1 100644 --- a/tests/ui/manual_range_patterns.rs +++ b/tests/ui/manual_range_patterns.rs @@ -1,4 +1,5 @@ #![allow(unused)] +#![allow(non_contiguous_range_endpoints)] #![warn(clippy::manual_range_patterns)] #![feature(exclusive_range_pattern)] diff --git a/tests/ui/manual_range_patterns.stderr b/tests/ui/manual_range_patterns.stderr index 7c19fdd475f1..af9256aeea39 100644 --- a/tests/ui/manual_range_patterns.stderr +++ b/tests/ui/manual_range_patterns.stderr @@ -1,5 +1,5 @@ error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:8:25 + --> tests/ui/manual_range_patterns.rs:9:25 | LL | let _ = matches!(f, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` @@ -8,109 +8,109 @@ LL | let _ = matches!(f, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10); = help: to override `-D warnings` add `#[allow(clippy::manual_range_patterns)]` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:9:25 + --> tests/ui/manual_range_patterns.rs:10:25 | LL | let _ = matches!(f, 4 | 2 | 3 | 1 | 5 | 6 | 9 | 7 | 8 | 10); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:16:25 + --> tests/ui/manual_range_patterns.rs:17:25 | LL | let _ = matches!(f, 1 | (2..=4)); | ^^^^^^^^^^^ help: try: `1..=4` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:17:25 + --> tests/ui/manual_range_patterns.rs:18:25 | LL | let _ = matches!(f, 1 | (2..4)); | ^^^^^^^^^^ help: try: `1..4` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:18:25 + --> tests/ui/manual_range_patterns.rs:19:25 | LL | let _ = matches!(f, (1..=10) | (2..=13) | (14..=48324728) | 48324729); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=48324729` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:19:25 + --> tests/ui/manual_range_patterns.rs:20:25 | LL | let _ = matches!(f, 0 | (1..=10) | 48324730 | (2..=13) | (14..=48324728) | 48324729); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0..=48324730` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:20:25 + --> tests/ui/manual_range_patterns.rs:21:25 | LL | let _ = matches!(f, 0..=1 | 0..=2 | 0..=3); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `0..=3` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:23:9 + --> tests/ui/manual_range_patterns.rs:24:9 | LL | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 => true, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:26:25 + --> tests/ui/manual_range_patterns.rs:27:25 | LL | let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1 | 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-5..=3` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:28:25 + --> tests/ui/manual_range_patterns.rs:29:25 | LL | let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_001); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-1_000_001..=1_000_001` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:31:17 + --> tests/ui/manual_range_patterns.rs:32:17 | LL | matches!(f, 0x00 | 0x01 | 0x02 | 0x03); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0x00..=0x03` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:32:17 + --> tests/ui/manual_range_patterns.rs:33:17 | LL | matches!(f, 0x00..=0x05 | 0x06 | 0x07); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0x00..=0x07` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:33:17 + --> tests/ui/manual_range_patterns.rs:34:17 | LL | matches!(f, -0x09 | -0x08 | -0x07..=0x00); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-0x09..=0x00` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:35:17 + --> tests/ui/manual_range_patterns.rs:36:17 | LL | matches!(f, 0..5 | 5); | ^^^^^^^^ help: try: `0..=5` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:36:17 + --> tests/ui/manual_range_patterns.rs:37:17 | LL | matches!(f, 0 | 1..5); | ^^^^^^^^ help: try: `0..5` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:38:17 + --> tests/ui/manual_range_patterns.rs:39:17 | LL | matches!(f, 0..=5 | 6..10); | ^^^^^^^^^^^^^ help: try: `0..10` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:39:17 + --> tests/ui/manual_range_patterns.rs:40:17 | LL | matches!(f, 0..5 | 5..=10); | ^^^^^^^^^^^^^ help: try: `0..=10` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:40:17 + --> tests/ui/manual_range_patterns.rs:41:17 | LL | matches!(f, 5..=10 | 0..5); | ^^^^^^^^^^^^^ help: try: `0..=10` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:44:26 + --> tests/ui/manual_range_patterns.rs:45:26 | LL | matches!($e, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` From a32ec3a1fa5c86ad46b73bb78dfe9a9cb1dc12fa Mon Sep 17 00:00:00 2001 From: r0cky Date: Thu, 29 Feb 2024 20:53:08 +0800 Subject: [PATCH 1106/1222] Remove unused structs in clippy --- clippy_lints/src/loops/utils.rs | 60 ++------------------------------- clippy_lints/src/macro_use.rs | 6 ---- 2 files changed, 2 insertions(+), 64 deletions(-) diff --git a/clippy_lints/src/loops/utils.rs b/clippy_lints/src/loops/utils.rs index e685274adb8d..8bca33754e81 100644 --- a/clippy_lints/src/loops/utils.rs +++ b/clippy_lints/src/loops/utils.rs @@ -2,8 +2,8 @@ use clippy_utils::ty::{has_iter_method, implements_trait}; use clippy_utils::{get_parent_expr, is_integer_const, path_to_local, path_to_local_id, sugg}; use rustc_ast::ast::{LitIntType, LitKind}; use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_expr, walk_local, walk_pat, walk_stmt, Visitor}; -use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, Local, Mutability, Pat, PatKind, Stmt}; +use rustc_hir::intravisit::{walk_expr, walk_local, Visitor}; +use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, Local, Mutability, PatKind}; use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, Ty}; @@ -253,62 +253,6 @@ fn is_conditional(expr: &Expr<'_>) -> bool { matches!(expr.kind, ExprKind::If(..) | ExprKind::Match(..)) } -#[derive(PartialEq, Eq)] -pub(super) enum Nesting { - Unknown, // no nesting detected yet - RuledOut, // the iterator is initialized or assigned within scope - LookFurther, // no nesting detected, no further walk required -} - -use self::Nesting::{LookFurther, RuledOut, Unknown}; - -pub(super) struct LoopNestVisitor { - pub(super) hir_id: HirId, - pub(super) iterator: HirId, - pub(super) nesting: Nesting, -} - -impl<'tcx> Visitor<'tcx> for LoopNestVisitor { - fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { - if stmt.hir_id == self.hir_id { - self.nesting = LookFurther; - } else if self.nesting == Unknown { - walk_stmt(self, stmt); - } - } - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if self.nesting != Unknown { - return; - } - if expr.hir_id == self.hir_id { - self.nesting = LookFurther; - return; - } - match expr.kind { - ExprKind::Assign(path, _, _) | ExprKind::AssignOp(_, path, _) => { - if path_to_local_id(path, self.iterator) { - self.nesting = RuledOut; - } - }, - _ => walk_expr(self, expr), - } - } - - fn visit_pat(&mut self, pat: &'tcx Pat<'_>) { - if self.nesting != Unknown { - return; - } - if let PatKind::Binding(_, id, ..) = pat.kind { - if id == self.iterator { - self.nesting = RuledOut; - return; - } - } - walk_pat(self, pat); - } -} - /// If `arg` was the argument to a `for` loop, return the "cleanest" way of writing the /// actual `Iterator` that the loop uses. pub(super) fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic_ref: &mut Applicability) -> String { diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index 8d3e7520a549..067384b09015 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -30,12 +30,6 @@ declare_clippy_lint! { "#[macro_use] is no longer needed" } -#[derive(Clone, Debug, PartialEq, Eq)] -struct PathAndSpan { - path: String, - span: Span, -} - /// `MacroRefData` includes the name of the macro. #[derive(Debug, Clone)] pub struct MacroRefData { From 2160f6ffde414ee59de237998cb508d84b31640c Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 23 Feb 2024 23:12:20 +0000 Subject: [PATCH 1107/1222] Change `DefKind::Static` to a struct variant --- clippy_lints/src/loops/needless_range_loop.rs | 2 +- clippy_lints/src/loops/while_immutable_condition.rs | 2 +- clippy_lints/src/methods/expect_fun_call.rs | 2 +- clippy_lints/src/multiple_unsafe_ops_per_block.rs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 08b8a9e2ff07..47dc3807e624 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -273,7 +273,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { } return false; // no need to walk further *on the variable* }, - Res::Def(DefKind::Static(_) | DefKind::Const, ..) => { + Res::Def(DefKind::Static{..} | DefKind::Const, ..) => { if index_used_directly { self.indexed_directly.insert( seqvar.segments[0].ident.name, diff --git a/clippy_lints/src/loops/while_immutable_condition.rs b/clippy_lints/src/loops/while_immutable_condition.rs index 9fd9b7a16312..3511d24e8134 100644 --- a/clippy_lints/src/loops/while_immutable_condition.rs +++ b/clippy_lints/src/loops/while_immutable_condition.rs @@ -101,7 +101,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> { Res::Local(hir_id) => { self.ids.insert(hir_id); }, - Res::Def(DefKind::Static(_), def_id) => { + Res::Def(DefKind::Static{..}, def_id) => { let mutable = self.cx.tcx.is_mutable_static(def_id); self.def_ids.insert(def_id, mutable); }, diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index f0fc925799a3..e2c2997594ad 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -91,7 +91,7 @@ pub(super) fn check<'tcx>( }, hir::ExprKind::Path(ref p) => matches!( cx.qpath_res(p, arg.hir_id), - hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static(_), _) + hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static{..}, _) ), _ => false, } diff --git a/clippy_lints/src/multiple_unsafe_ops_per_block.rs b/clippy_lints/src/multiple_unsafe_ops_per_block.rs index 049f44f3246f..d8caa632b938 100644 --- a/clippy_lints/src/multiple_unsafe_ops_per_block.rs +++ b/clippy_lints/src/multiple_unsafe_ops_per_block.rs @@ -109,7 +109,7 @@ fn collect_unsafe_exprs<'tcx>( ExprKind::Path(QPath::Resolved( _, hir::Path { - res: Res::Def(DefKind::Static(Mutability::Mut), _), + res: Res::Def(DefKind::Static{mt:Mutability::Mut}, _), .. }, )) => { @@ -149,7 +149,7 @@ fn collect_unsafe_exprs<'tcx>( ExprKind::Path(QPath::Resolved( _, hir::Path { - res: Res::Def(DefKind::Static(Mutability::Mut), _), + res: Res::Def(DefKind::Static{mt:Mutability::Mut}, _), .. } )) From 81b4f41fc21376a490a514d4f53aa51b760e5482 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 23 Feb 2024 23:29:09 +0000 Subject: [PATCH 1108/1222] Add `nested` bool to `DefKind::Static`. Will be used in the next commit --- clippy_lints/src/multiple_unsafe_ops_per_block.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/multiple_unsafe_ops_per_block.rs b/clippy_lints/src/multiple_unsafe_ops_per_block.rs index d8caa632b938..4155e608026e 100644 --- a/clippy_lints/src/multiple_unsafe_ops_per_block.rs +++ b/clippy_lints/src/multiple_unsafe_ops_per_block.rs @@ -109,7 +109,7 @@ fn collect_unsafe_exprs<'tcx>( ExprKind::Path(QPath::Resolved( _, hir::Path { - res: Res::Def(DefKind::Static{mt:Mutability::Mut}, _), + res: Res::Def(DefKind::Static{mt:Mutability::Mut, ..}, _), .. }, )) => { @@ -149,7 +149,7 @@ fn collect_unsafe_exprs<'tcx>( ExprKind::Path(QPath::Resolved( _, hir::Path { - res: Res::Def(DefKind::Static{mt:Mutability::Mut}, _), + res: Res::Def(DefKind::Static{mt:Mutability::Mut, ..}, _), .. } )) From b15989669a3dc802b7f7801bb756751802bea165 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 11 Mar 2024 17:33:57 +0000 Subject: [PATCH 1109/1222] s/mt/mutability/ --- clippy_lints/src/multiple_unsafe_ops_per_block.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/multiple_unsafe_ops_per_block.rs b/clippy_lints/src/multiple_unsafe_ops_per_block.rs index 4155e608026e..70fd07cd93ce 100644 --- a/clippy_lints/src/multiple_unsafe_ops_per_block.rs +++ b/clippy_lints/src/multiple_unsafe_ops_per_block.rs @@ -109,7 +109,7 @@ fn collect_unsafe_exprs<'tcx>( ExprKind::Path(QPath::Resolved( _, hir::Path { - res: Res::Def(DefKind::Static{mt:Mutability::Mut, ..}, _), + res: Res::Def(DefKind::Static{mutability:Mutability::Mut, ..}, _), .. }, )) => { @@ -149,7 +149,7 @@ fn collect_unsafe_exprs<'tcx>( ExprKind::Path(QPath::Resolved( _, hir::Path { - res: Res::Def(DefKind::Static{mt:Mutability::Mut, ..}, _), + res: Res::Def(DefKind::Static{mutability:Mutability::Mut, ..}, _), .. } )) From e49d2626fddf7228ab9d7dfbe5329d900b76c0e9 Mon Sep 17 00:00:00 2001 From: Arthur Carcano Date: Fri, 5 Jan 2024 16:13:24 +0100 Subject: [PATCH 1110/1222] fix: allow-one-hash-in-raw-strings option of needless_raw_string_hashes was ignored Fixes: https://github.com/rust-lang/rust-clippy/issues/11481 changelog: Fix `allow-one-hash-in-raw-strings` option of [`needless_raw_string_hashes`] was ignored --- clippy_lints/src/raw_strings.rs | 6 ++- .../clippy.toml | 1 + .../needless_raw_string_hashes.fixed | 9 +++++ .../needless_raw_string_hashes.rs | 9 +++++ .../needless_raw_string_hashes.stderr | 40 +++++++++++++++++++ 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 tests/ui-toml/needless_raw_string_hashes_one_allowed/clippy.toml create mode 100644 tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.fixed create mode 100644 tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs create mode 100644 tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.stderr diff --git a/clippy_lints/src/raw_strings.rs b/clippy_lints/src/raw_strings.rs index ac29d27303c8..7e71f48c6d9a 100644 --- a/clippy_lints/src/raw_strings.rs +++ b/clippy_lints/src/raw_strings.rs @@ -108,7 +108,7 @@ impl EarlyLintPass for RawStrings { } } - let req = { + let mut req = { let mut following_quote = false; let mut req = 0; // `once` so a raw string ending in hashes is still checked @@ -136,7 +136,9 @@ impl EarlyLintPass for RawStrings { ControlFlow::Continue(num) | ControlFlow::Break(num) => num, } }; - + if self.allow_one_hash_in_raw_strings { + req = req.max(1); + } if req < max { span_lint_and_then( cx, diff --git a/tests/ui-toml/needless_raw_string_hashes_one_allowed/clippy.toml b/tests/ui-toml/needless_raw_string_hashes_one_allowed/clippy.toml new file mode 100644 index 000000000000..2f3d60be3a73 --- /dev/null +++ b/tests/ui-toml/needless_raw_string_hashes_one_allowed/clippy.toml @@ -0,0 +1 @@ +allow-one-hash-in-raw-strings = true diff --git a/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.fixed b/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.fixed new file mode 100644 index 000000000000..fd20bdff6e25 --- /dev/null +++ b/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.fixed @@ -0,0 +1,9 @@ +#![allow(clippy::no_effect, unused)] +#![warn(clippy::needless_raw_string_hashes)] + +fn main() { + r#"\aaa"#; + r#"\aaa"#; + r#"Hello "world"!"#; + r####" "### "## "# "####; +} diff --git a/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs b/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs new file mode 100644 index 000000000000..3c6c24637006 --- /dev/null +++ b/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs @@ -0,0 +1,9 @@ +#![allow(clippy::no_effect, unused)] +#![warn(clippy::needless_raw_string_hashes)] + +fn main() { + r#"\aaa"#; + r##"\aaa"##; + r##"Hello "world"!"##; + r######" "### "## "# "######; +} diff --git a/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.stderr b/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.stderr new file mode 100644 index 000000000000..421ad66e4c96 --- /dev/null +++ b/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.stderr @@ -0,0 +1,40 @@ +error: unnecessary hashes around raw string literal + --> tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs:6:5 + | +LL | r##"\aaa"##; + | ^^^^^^^^^^^ + | + = note: `-D clippy::needless-raw-string-hashes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_raw_string_hashes)]` +help: remove one hash from both sides of the string literal + | +LL - r##"\aaa"##; +LL + r#"\aaa"#; + | + +error: unnecessary hashes around raw string literal + --> tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs:7:5 + | +LL | r##"Hello "world"!"##; + | ^^^^^^^^^^^^^^^^^^^^^ + | +help: remove one hash from both sides of the string literal + | +LL - r##"Hello "world"!"##; +LL + r#"Hello "world"!"#; + | + +error: unnecessary hashes around raw string literal + --> tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs:8:5 + | +LL | r######" "### "## "# "######; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: remove 2 hashes from both sides of the string literal + | +LL - r######" "### "## "# "######; +LL + r####" "### "## "# "####; + | + +error: aborting due to 3 previous errors + From 59780656d3552d7f1efa7411bec36f946b3736a0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 14 Mar 2024 11:25:05 +0100 Subject: [PATCH 1111/1222] Rename `ast::StmtKind::Local` into `ast::StmtKind::Let` --- clippy_utils/src/ast_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 3b3939da7b6b..3874c1169e48 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -267,7 +267,7 @@ pub fn eq_block(l: &Block, r: &Block) -> bool { pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool { use StmtKind::*; match (&l.kind, &r.kind) { - (Local(l), Local(r)) => { + (Let(l), Let(r)) => { eq_pat(&l.pat, &r.pat) && both(&l.ty, &r.ty, |l, r| eq_ty(l, r)) && eq_local_kind(&l.kind, &r.kind) From febe1fd6975e71ee9cdf50dc918416c291aaeaeb Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 14 Mar 2024 11:53:38 +0100 Subject: [PATCH 1112/1222] Rename `hir::StmtKind::Local` into `hir::StmtKind::Let` --- clippy_lints/src/attrs/utils.rs | 2 +- clippy_lints/src/copies.rs | 8 ++++---- clippy_lints/src/default.rs | 2 +- clippy_lints/src/default_numeric_fallback.rs | 2 +- clippy_lints/src/entry.rs | 2 +- clippy_lints/src/explicit_write.rs | 2 +- clippy_lints/src/let_if_seq.rs | 2 +- clippy_lints/src/loops/manual_memcpy.rs | 2 +- clippy_lints/src/loops/manual_while_let_some.rs | 2 +- clippy_lints/src/loops/never_loop.rs | 2 +- clippy_lints/src/loops/while_let_loop.rs | 2 +- clippy_lints/src/manual_let_else.rs | 2 +- clippy_lints/src/map_unit_fn.rs | 2 +- clippy_lints/src/methods/needless_collect.rs | 2 +- clippy_lints/src/methods/str_splitn.rs | 2 +- .../src/methods/unnecessary_result_map_or_else.rs | 2 +- clippy_lints/src/misc.rs | 2 +- clippy_lints/src/mixed_read_write_in_expression.rs | 4 ++-- clippy_lints/src/needless_late_init.rs | 2 +- clippy_lints/src/no_effect.rs | 2 +- clippy_lints/src/pattern_type_mismatch.rs | 2 +- clippy_lints/src/question_mark.rs | 2 +- clippy_lints/src/read_zero_byte_vec.rs | 2 +- clippy_lints/src/redundant_closure_call.rs | 2 +- clippy_lints/src/returns.rs | 2 +- clippy_lints/src/significant_drop_tightening.rs | 6 +++--- clippy_lints/src/slow_vector_initialization.rs | 2 +- clippy_lints/src/swap.rs | 4 ++-- clippy_lints/src/undocumented_unsafe_blocks.rs | 4 ++-- clippy_lints/src/uninit_vec.rs | 2 +- clippy_lints/src/unused_io_amount.rs | 4 ++-- clippy_lints/src/unused_peekable.rs | 4 ++-- clippy_lints/src/utils/author.rs | 2 +- clippy_utils/src/hir_utils.rs | 4 ++-- clippy_utils/src/lib.rs | 2 +- 35 files changed, 46 insertions(+), 46 deletions(-) diff --git a/clippy_lints/src/attrs/utils.rs b/clippy_lints/src/attrs/utils.rs index 9b36cc00444f..91ae19acbf7f 100644 --- a/clippy_lints/src/attrs/utils.rs +++ b/clippy_lints/src/attrs/utils.rs @@ -52,7 +52,7 @@ fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_ .as_ref() .map_or(false, |e| is_relevant_expr(cx, typeck_results, e)), |stmt| match &stmt.kind { - StmtKind::Local(_) => true, + StmtKind::Let(_) => true, StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, typeck_results, expr), StmtKind::Item(_) => false, }, diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 247048bbc49d..acdcb54be271 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -349,7 +349,7 @@ impl BlockEq { /// If the statement is a local, checks if the bound names match the expected list of names. fn eq_binding_names(s: &Stmt<'_>, names: &[(HirId, Symbol)]) -> bool { - if let StmtKind::Local(l) = s.kind { + if let StmtKind::Let(l) = s.kind { let mut i = 0usize; let mut res = true; l.pat.each_binding_or_first(&mut |_, _, _, name| { @@ -389,7 +389,7 @@ fn eq_stmts( eq: &mut HirEqInterExpr<'_, '_, '_>, moved_bindings: &mut Vec<(HirId, Symbol)>, ) -> bool { - (if let StmtKind::Local(l) = stmt.kind { + (if let StmtKind::Let(l) = stmt.kind { let old_count = moved_bindings.len(); l.pat.each_binding_or_first(&mut |_, id, _, name| { moved_bindings.push((id, name.name)); @@ -432,7 +432,7 @@ fn scan_block_for_eq<'tcx>( .iter() .enumerate() .find(|&(i, stmt)| { - if let StmtKind::Local(l) = stmt.kind + if let StmtKind::Let(l) = stmt.kind && needs_ordered_drop(cx, cx.typeck_results().node_type(l.hir_id)) { local_needs_ordered_drop = true; @@ -509,7 +509,7 @@ fn scan_block_for_eq<'tcx>( // Clear out all locals seen at the end so far. None of them can be moved. let stmts = &blocks[0].stmts; for stmt in &stmts[stmts.len() - init..=stmts.len() - offset] { - if let StmtKind::Local(l) = stmt.kind { + if let StmtKind::Let(l) = stmt.kind { l.pat.each_binding_or_first(&mut |_, id, _, _| { // FIXME(rust/#120456) - is `swap_remove` correct? eq.locals.swap_remove(&id); diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index 8789efcc9944..98a6d9370c34 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -121,7 +121,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { // find all binding statements like `let mut _ = T::default()` where `T::default()` is the // `default` method of the `Default` trait, and store statement index in current block being // checked and the name of the bound variable - let (local, variant, binding_name, binding_type, span) = if let StmtKind::Local(local) = stmt.kind + let (local, variant, binding_name, binding_type, span) = if let StmtKind::Let(local) = stmt.kind // only take `let ...` statements && let Some(expr) = local.init && !any_parent_is_automatically_derived(cx.tcx, expr.hir_id) diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index 59d2df0295fb..1d6c4ce72e18 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -221,7 +221,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { match stmt.kind { // we cannot check the exact type since it's a hir::Ty which does not implement `is_numeric` - StmtKind::Local(local) => self.ty_bounds.push(ExplicitTyBound(local.ty.is_some())), + StmtKind::Let(local) => self.ty_bounds.push(ExplicitTyBound(local.ty.is_some())), _ => self.ty_bounds.push(ExplicitTyBound(false)), } diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index de6073c27236..ebda2ad83870 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -423,7 +423,7 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> { } }, StmtKind::Expr(e) => self.visit_expr(e), - StmtKind::Local(l) => { + StmtKind::Let(l) => { self.visit_pat(l.pat); if let Some(e) = l.init { self.allow_insert_closure &= !self.in_tail_pos; diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index de048fef5f22..2e9bec6a7b08 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -102,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite { fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>) -> &'tcx ExprKind<'hir> { if let ExprKind::Block(block, _label @ None) = kind && let Block { - stmts: [Stmt { kind: StmtKind::Local(local), .. }], + stmts: [Stmt { kind: StmtKind::Let(local), .. }], expr: Some(expr_end_of_block), rules: BlockCheckMode::DefaultBlock, .. diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index 270162ae7717..f084d89ccc28 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq { let mut it = block.stmts.iter().peekable(); while let Some(stmt) = it.next() { if let Some(expr) = it.peek() - && let hir::StmtKind::Local(local) = stmt.kind + && let hir::StmtKind::Let(local) = stmt.kind && let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.kind && let hir::StmtKind::Expr(if_) = expr.kind && let hir::ExprKind::If( diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index 18f799e875a0..a7c1d1bd6cd3 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -410,7 +410,7 @@ fn get_assignments<'a, 'tcx>( stmts .iter() .filter_map(move |stmt| match stmt.kind { - StmtKind::Local(..) | StmtKind::Item(..) => None, + StmtKind::Let(..) | StmtKind::Item(..) => None, StmtKind::Expr(e) | StmtKind::Semi(e) => Some(e), }) .chain(*expr) diff --git a/clippy_lints/src/loops/manual_while_let_some.rs b/clippy_lints/src/loops/manual_while_let_some.rs index ca584a454d03..b00a082bb8cf 100644 --- a/clippy_lints/src/loops/manual_while_let_some.rs +++ b/clippy_lints/src/loops/manual_while_let_some.rs @@ -72,7 +72,7 @@ fn is_vec_pop_unwrap(cx: &LateContext<'_>, expr: &Expr<'_>, is_empty_recv: &Expr } fn check_local(cx: &LateContext<'_>, stmt: &Stmt<'_>, is_empty_recv: &Expr<'_>, loop_span: Span) { - if let StmtKind::Local(local) = stmt.kind + if let StmtKind::Let(local) = stmt.kind && let Some(init) = local.init && is_vec_pop_unwrap(cx, init, is_empty_recv) { diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index 65d922f03df3..6cc79440f39a 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -137,7 +137,7 @@ fn stmt_to_expr<'tcx>(stmt: &Stmt<'tcx>) -> Option<(&'tcx Expr<'tcx>, Option<&'t match stmt.kind { StmtKind::Semi(e) | StmtKind::Expr(e) => Some((e, None)), // add the let...else expression (if present) - StmtKind::Local(local) => local.init.map(|init| (init, local.els)), + StmtKind::Let(local) => local.init.map(|init| (init, local.els)), StmtKind::Item(..) => None, } } diff --git a/clippy_lints/src/loops/while_let_loop.rs b/clippy_lints/src/loops/while_let_loop.rs index 735d704a43ce..93774b897682 100644 --- a/clippy_lints/src/loops/while_let_loop.rs +++ b/clippy_lints/src/loops/while_let_loop.rs @@ -11,7 +11,7 @@ use rustc_lint::LateContext; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) { let (init, has_trailing_exprs) = match (loop_block.stmts, loop_block.expr) { ([stmt, stmts @ ..], expr) => { - if let StmtKind::Local(&Local { + if let StmtKind::Let(&Local { init: Some(e), els: None, .. diff --git a/clippy_lints/src/manual_let_else.rs b/clippy_lints/src/manual_let_else.rs index fdf8fa4e2771..03e4d668dd8f 100644 --- a/clippy_lints/src/manual_let_else.rs +++ b/clippy_lints/src/manual_let_else.rs @@ -53,7 +53,7 @@ impl<'tcx> QuestionMark { return; } - if let StmtKind::Local(local) = stmt.kind + if let StmtKind::Let(local) = stmt.kind && let Some(init) = local.init && local.els.is_none() && local.ty.is_none() diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 3b82c50a84e6..c9eab7109ebc 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -138,7 +138,7 @@ fn reduce_unit_expression(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option< // If block only contains statements, // reduce `{ X; }` to `X` or `X;` match inner_stmt.kind { - hir::StmtKind::Local(local) => Some(local.span), + hir::StmtKind::Let(local) => Some(local.span), hir::StmtKind::Expr(e) => Some(e.span), hir::StmtKind::Semi(..) => Some(inner_stmt.span), hir::StmtKind::Item(..) => None, diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index 55050ae693e7..78540353005d 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -424,7 +424,7 @@ fn get_expr_and_hir_id_from_stmt<'v>(stmt: &'v Stmt<'v>) -> Option<(&'v Expr<'v> match stmt.kind { StmtKind::Expr(expr) | StmtKind::Semi(expr) => Some((expr, None)), StmtKind::Item(..) => None, - StmtKind::Local(Local { init, pat, .. }) => { + StmtKind::Let(Local { init, pat, .. }) => { if let PatKind::Binding(_, hir_id, ..) = pat.kind { init.map(|init_expr| (init_expr, Some(hir_id))) } else { diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 0e7ad8fc996e..55cd1a38ec96 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -198,7 +198,7 @@ fn indirect_usage<'tcx>( binding: HirId, ctxt: SyntaxContext, ) -> Option> { - if let StmtKind::Local(&Local { + if let StmtKind::Let(&Local { pat: Pat { kind: PatKind::Binding(BindingAnnotation::NONE, _, ident, None), .. diff --git a/clippy_lints/src/methods/unnecessary_result_map_or_else.rs b/clippy_lints/src/methods/unnecessary_result_map_or_else.rs index 7b0cf48ac43b..cdfaa690d5f4 100644 --- a/clippy_lints/src/methods/unnecessary_result_map_or_else.rs +++ b/clippy_lints/src/methods/unnecessary_result_map_or_else.rs @@ -27,7 +27,7 @@ fn emit_lint(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, def_arg: &E fn get_last_chain_binding_hir_id(mut hir_id: HirId, statements: &[Stmt<'_>]) -> Option { for stmt in statements { - if let StmtKind::Local(local) = stmt.kind + if let StmtKind::Let(local) = stmt.kind && let Some(init) = local.init && let ExprKind::Path(QPath::Resolved(_, path)) = init.kind && let hir::def::Res::Local(local_hir_id) = path.res diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index b9784a58596c..4094d7ded7d8 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for LintPass { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { if !in_external_macro(cx.tcx.sess, stmt.span) - && let StmtKind::Local(local) = stmt.kind + && let StmtKind::Let(local) = stmt.kind && let PatKind::Binding(BindingAnnotation(ByRef::Yes, mutabl), .., name, None) = local.pat.kind && let Some(init) = local.init // Do not emit if clippy::ref_patterns is not allowed to avoid having two lints for the same issue. diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs index a1f7dc7b38c4..12c7c18afde6 100644 --- a/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/clippy_lints/src/mixed_read_write_in_expression.rs @@ -97,7 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for EvalOrderDependence { } fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { match stmt.kind { - StmtKind::Local(local) => { + StmtKind::Let(local) => { if let Local { init: Some(e), .. } = local { DivergenceVisitor { cx }.visit_expr(e); } @@ -291,7 +291,7 @@ fn check_stmt<'tcx>(vis: &mut ReadVisitor<'_, 'tcx>, stmt: &'tcx Stmt<'_>) -> St StmtKind::Expr(expr) | StmtKind::Semi(expr) => check_expr(vis, expr), // If the declaration is of a local variable, check its initializer // expression if it has one. Otherwise, keep going. - StmtKind::Local(local) => local + StmtKind::Let(local) => local .init .as_ref() .map_or(StopEarly::KeepGoing, |expr| check_expr(vis, expr)), diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs index 3e63c0a1d36e..4cda4b171e31 100644 --- a/clippy_lints/src/needless_late_init.rs +++ b/clippy_lints/src/needless_late_init.rs @@ -86,7 +86,7 @@ fn contains_let(cond: &Expr<'_>) -> bool { } fn stmt_needs_ordered_drop(cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool { - let StmtKind::Local(local) = stmt.kind else { + let StmtKind::Let(local) = stmt.kind else { return false; }; !local.pat.walk_short(|pat| { diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index cac34c8ce06e..43810ec0ec74 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -174,7 +174,7 @@ impl NoEffect { ); return true; } - } else if let StmtKind::Local(local) = stmt.kind { + } else if let StmtKind::Let(local) = stmt.kind { if !is_lint_allowed(cx, NO_EFFECT_UNDERSCORE_BINDING, local.hir_id) && !matches!(local.source, LocalSource::AsyncFn) && let Some(init) = local.init diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index 60ced9c12082..fbca4329342a 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -82,7 +82,7 @@ declare_lint_pass!(PatternTypeMismatch => [PATTERN_TYPE_MISMATCH]); impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { - if let StmtKind::Local(local) = stmt.kind { + if let StmtKind::Let(local) = stmt.kind { if in_external_macro(cx.sess(), local.pat.span) { return; } diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index cf7f730140ce..831c291ed7cc 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -109,7 +109,7 @@ fn find_let_else_ret_expression<'hir>(block: &'hir Block<'hir>) -> Option<&'hir } fn check_let_some_else_return_none(cx: &LateContext<'_>, stmt: &Stmt<'_>) { - if let StmtKind::Local(Local { + if let StmtKind::Let(Local { pat, init: Some(init_expr), els: Some(els), diff --git a/clippy_lints/src/read_zero_byte_vec.rs b/clippy_lints/src/read_zero_byte_vec.rs index 650324d4249e..d0b37cd92e00 100644 --- a/clippy_lints/src/read_zero_byte_vec.rs +++ b/clippy_lints/src/read_zero_byte_vec.rs @@ -56,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for ReadZeroByteVec { return; } - if let StmtKind::Local(local) = stmt.kind + if let StmtKind::Let(local) = stmt.kind && let Local { pat, init: Some(init), .. } = local diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index f61527cc0a9f..c2673bc409fa 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -262,7 +262,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { } for w in block.stmts.windows(2) { - if let hir::StmtKind::Local(local) = w[0].kind + if let hir::StmtKind::Let(local) = w[0].kind && let Option::Some(t) = local.init && let hir::ExprKind::Closure { .. } = t.kind && let hir::PatKind::Binding(_, _, ident, _) = local.pat.kind diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 2af466d3f51e..196975274674 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -222,7 +222,7 @@ impl<'tcx> LateLintPass<'tcx> for Return { // we need both a let-binding stmt and an expr if let Some(retexpr) = block.expr && let Some(stmt) = block.stmts.iter().last() - && let StmtKind::Local(local) = &stmt.kind + && let StmtKind::Let(local) = &stmt.kind && local.ty.is_none() && cx.tcx.hir().attrs(local.hir_id).is_empty() && let Some(initexpr) = &local.init diff --git a/clippy_lints/src/significant_drop_tightening.rs b/clippy_lints/src/significant_drop_tightening.rs index 6c99ccda7ea7..f8726aa173a9 100644 --- a/clippy_lints/src/significant_drop_tightening.rs +++ b/clippy_lints/src/significant_drop_tightening.rs @@ -236,7 +236,7 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> StmtsChecker<'ap, 'lc, 'others, 'stmt, 'tcx fn manage_has_expensive_expr_after_last_attr(&mut self) { let has_expensive_stmt = match self.ap.curr_stmt.kind { hir::StmtKind::Expr(expr) if is_inexpensive_expr(expr) => false, - hir::StmtKind::Local(local) + hir::StmtKind::Let(local) if let Some(expr) = local.init && let hir::ExprKind::Path(_) = expr.kind => { @@ -290,7 +290,7 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> Visitor<'tcx> for StmtsChecker<'ap, 'lc, 'o }; let mut ac = AttrChecker::new(self.cx, self.seen_types, self.type_cache); if ac.has_sig_drop_attr(self.cx.typeck_results().expr_ty(expr)) { - if let hir::StmtKind::Local(local) = self.ap.curr_stmt.kind + if let hir::StmtKind::Let(local) = self.ap.curr_stmt.kind && let hir::PatKind::Binding(_, hir_id, ident, _) = local.pat.kind && !self.ap.apas.contains_key(&hir_id) && { @@ -326,7 +326,7 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> Visitor<'tcx> for StmtsChecker<'ap, 'lc, 'o return; }; match self.ap.curr_stmt.kind { - hir::StmtKind::Local(local) => { + hir::StmtKind::Let(local) => { if let hir::PatKind::Binding(_, _, ident, _) = local.pat.kind { apa.last_bind_ident = ident; } diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 4837f2858a66..ff8e8fe70217 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -119,7 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for SlowVectorInit { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { // Matches statements which initializes vectors. For example: `let mut vec = Vec::with_capacity(10)` // or `Vec::new()` - if let StmtKind::Local(local) = stmt.kind + if let StmtKind::Let(local) = stmt.kind && let PatKind::Binding(BindingAnnotation::MUT, local_id, _, None) = local.pat.kind && let Some(init) = local.init && let Some(size_expr) = Self::as_vec_initializer(cx, init) diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index daa6fe8715ca..be590aede158 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -148,7 +148,7 @@ fn check_manual_swap(cx: &LateContext<'_>, block: &Block<'_>) { } for [s1, s2, s3] in block.stmts.array_windows::<3>() { - if let StmtKind::Local(tmp) = s1.kind + if let StmtKind::Let(tmp) = s1.kind // let t = foo(); && let Some(tmp_init) = tmp.init && let PatKind::Binding(.., ident, None) = tmp.pat.kind @@ -243,7 +243,7 @@ fn parse<'a, 'hir>(stmt: &'a Stmt<'hir>) -> Option<(ExprOrIdent<'hir>, &'a Expr< if let ExprKind::Assign(lhs, rhs, _) = expr.kind { return Some((ExprOrIdent::Expr(lhs), rhs)); } - } else if let StmtKind::Local(expr) = stmt.kind { + } else if let StmtKind::Let(expr) = stmt.kind { if let Some(rhs) = expr.init { if let PatKind::Binding(_, _, ident_l, _) = expr.pat.kind { return Some((ExprOrIdent::Ident(ident_l), rhs)); diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index 559d7ace40ed..0efa65b28e23 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -158,7 +158,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks { } fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &hir::Stmt<'tcx>) { - let (hir::StmtKind::Local(&hir::Local { init: Some(expr), .. }) + let (hir::StmtKind::Let(&hir::Local { init: Some(expr), .. }) | hir::StmtKind::Expr(expr) | hir::StmtKind::Semi(expr)) = stmt.kind else { @@ -358,7 +358,7 @@ fn block_parents_have_safety_comment( }, Node::Stmt(hir::Stmt { kind: - hir::StmtKind::Local(hir::Local { span, hir_id, .. }) + hir::StmtKind::Let(hir::Local { span, hir_id, .. }) | hir::StmtKind::Expr(hir::Expr { span, hir_id, .. }) | hir::StmtKind::Semi(hir::Expr { span, hir_id, .. }), .. diff --git a/clippy_lints/src/uninit_vec.rs b/clippy_lints/src/uninit_vec.rs index fc8519d56283..9ffcfcc0f50c 100644 --- a/clippy_lints/src/uninit_vec.rs +++ b/clippy_lints/src/uninit_vec.rs @@ -153,7 +153,7 @@ impl<'tcx> VecLocation<'tcx> { /// or `self` expression for `Vec::reserve()`. fn extract_init_or_reserve_target<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'tcx>) -> Option> { match stmt.kind { - StmtKind::Local(local) => { + StmtKind::Let(local) => { if let Some(init_expr) = local.init && let PatKind::Binding(_, hir_id, _, None) = local.pat.kind && let Some(init_kind) = get_vec_init_kind(cx, init_expr) diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index 6b3ea7700b73..eb64dd633f60 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -61,10 +61,10 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount { /// we need to check them at `check_expr` or `check_block` as they are not stmts /// but we can't check them at `check_expr` because we need the broader context /// because we should do this only for the final expression of the block, and not for - /// `StmtKind::Local` which binds values => the io amount is used. + /// `StmtKind::Let` which binds values => the io amount is used. /// /// To check for unused io amount in stmts, we only consider `StmtKind::Semi`. - /// `StmtKind::Local` is not considered because it binds values => the io amount is used. + /// `StmtKind::Let` is not considered because it binds values => the io amount is used. /// `StmtKind::Expr` is not considered because requires unit type => the io amount is used. /// `StmtKind::Item` is not considered because it's not an expression. /// diff --git a/clippy_lints/src/unused_peekable.rs b/clippy_lints/src/unused_peekable.rs index ba72b3450b93..f1d0c22b1aec 100644 --- a/clippy_lints/src/unused_peekable.rs +++ b/clippy_lints/src/unused_peekable.rs @@ -56,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedPeekable { for (idx, stmt) in block.stmts.iter().enumerate() { if !stmt.span.from_expansion() - && let StmtKind::Local(local) = stmt.kind + && let StmtKind::Let(local) = stmt.kind && let PatKind::Binding(_, binding, ident, _) = local.pat.kind && let Some(init) = local.init && !init.span.from_expansion() @@ -197,7 +197,7 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> { }, Node::Stmt(stmt) => { match stmt.kind { - StmtKind::Local(_) | StmtKind::Item(_) => self.found_peek_call = true, + StmtKind::Let(_) | StmtKind::Item(_) => self.found_peek_call = true, StmtKind::Expr(_) | StmtKind::Semi(_) => {}, } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index a0a6382046d0..187bfda129cd 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -724,7 +724,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { } match stmt.value.kind { - StmtKind::Local(local) => { + StmtKind::Let(local) => { bind!(self, local); kind!("Local({local})"); self.option(field!(local.init), "init", |init| { diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index f7f5f7ca35ff..106d1d0d77f0 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -108,7 +108,7 @@ pub struct HirEqInterExpr<'a, 'b, 'tcx> { impl HirEqInterExpr<'_, '_, '_> { pub fn eq_stmt(&mut self, left: &Stmt<'_>, right: &Stmt<'_>) -> bool { match (&left.kind, &right.kind) { - (&StmtKind::Local(l), &StmtKind::Local(r)) => { + (&StmtKind::Let(l), &StmtKind::Let(r)) => { // This additional check ensures that the type of the locals are equivalent even if the init // expression or type have some inferred parts. if let Some((typeck_lhs, typeck_rhs)) = self.inner.maybe_typeck_results { @@ -1030,7 +1030,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { std::mem::discriminant(&b.kind).hash(&mut self.s); match &b.kind { - StmtKind::Local(local) => { + StmtKind::Let(local) => { self.hash_pat(local.pat); if let Some(init) = local.init { self.hash_expr(init); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 708037a46555..dc0725730322 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -2161,7 +2161,7 @@ pub fn is_expr_used_or_unified(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { Node::Stmt(Stmt { kind: StmtKind::Expr(_) | StmtKind::Semi(_) - | StmtKind::Local(Local { + | StmtKind::Let(Local { pat: Pat { kind: PatKind::Wild, .. From 92fe24f24789cc68fc3ddef709e5b29a9e69b137 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 14 Mar 2024 21:05:06 +0300 Subject: [PATCH 1113/1222] hir: Remove `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id` Also replace a few `hir_node()` calls with `hir_node_by_def_id()` --- clippy_lints/src/escape.rs | 3 +-- clippy_lints/src/exit.rs | 2 +- clippy_lints/src/functions/result.rs | 2 +- clippy_lints/src/misc.rs | 3 +-- clippy_lints/src/missing_fields_in_debug.rs | 2 +- clippy_lints/src/needless_pass_by_ref_mut.rs | 5 +---- clippy_lints/src/self_named_constructors.rs | 3 +-- clippy_lints/src/single_call_fn.rs | 2 +- clippy_lints/src/types/mod.rs | 6 +++--- clippy_lints/src/zero_sized_map_values.rs | 2 +- clippy_utils/src/lib.rs | 22 ++++++++------------ 11 files changed, 21 insertions(+), 31 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 8857cb8e3827..ad589dad350b 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -76,10 +76,9 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { .hir() .get_parent_item(cx.tcx.local_def_id_to_hir_id(fn_def_id)) .def_id; - let parent_node = cx.tcx.opt_hir_node_by_def_id(parent_id); let mut trait_self_ty = None; - if let Some(Node::Item(item)) = parent_node { + if let Node::Item(item) = cx.tcx.hir_node_by_def_id(parent_id) { // If the method is an impl for a trait, don't warn. if let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = item.kind { return; diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index 6603512c73cd..106844dd4348 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit { && let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id() && cx.tcx.is_diagnostic_item(sym::process_exit, def_id) && let parent = cx.tcx.hir().get_parent_item(e.hir_id).def_id - && let Some(Node::Item(Item{kind: ItemKind::Fn(..), ..})) = cx.tcx.opt_hir_node_by_def_id(parent) + && let Node::Item(Item{kind: ItemKind::Fn(..), ..}) = cx.tcx.hir_node_by_def_id(parent) // If the next item up is a function we check if it is an entry point // and only then emit a linter warning && !is_entrypoint_fn(cx, parent.to_def_id()) diff --git a/clippy_lints/src/functions/result.rs b/clippy_lints/src/functions/result.rs index 7f36f33fe708..37fbf2c7d596 100644 --- a/clippy_lints/src/functions/result.rs +++ b/clippy_lints/src/functions/result.rs @@ -92,7 +92,7 @@ fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty .expect("already checked this is adt") .did() .as_local() - && let Some(hir::Node::Item(item)) = cx.tcx.opt_hir_node_by_def_id(local_def_id) + && let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(local_def_id) && let hir::ItemKind::Enum(ref def, _) = item.kind { let variants_size = AdtVariantInfo::new(cx, *adt, subst); diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index b9784a58596c..ac9df8bfca3e 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -225,10 +225,9 @@ impl<'tcx> LateLintPass<'tcx> for LintPass { if let Some(adt_def) = cx.typeck_results().expr_ty_adjusted(recv).ty_adt_def() && let Some(field) = adt_def.all_fields().find(|field| field.name == ident.name) && let Some(local_did) = field.did.as_local() - && let Some(hir_id) = cx.tcx.opt_local_def_id_to_hir_id(local_did) && !cx.tcx.type_of(field.did).skip_binder().is_phantom_data() { - (hir_id, ident) + (cx.tcx.local_def_id_to_hir_id(local_did), ident) } else { return; } diff --git a/clippy_lints/src/missing_fields_in_debug.rs b/clippy_lints/src/missing_fields_in_debug.rs index 88b331ddefdb..3bf9f75e2261 100644 --- a/clippy_lints/src/missing_fields_in_debug.rs +++ b/clippy_lints/src/missing_fields_in_debug.rs @@ -220,7 +220,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingFieldsInDebug { && let self_ty = cx.tcx.type_of(self_path_did).skip_binder().peel_refs() && let Some(self_adt) = self_ty.ty_adt_def() && let Some(self_def_id) = self_adt.did().as_local() - && let Some(Node::Item(self_item)) = cx.tcx.opt_hir_node_by_def_id(self_def_id) + && let Node::Item(self_item) = cx.tcx.hir_node_by_def_id(self_def_id) // NB: can't call cx.typeck_results() as we are not in a body && let typeck_results = cx.tcx.typeck_body(*body_id) && should_lint(cx, typeck_results, block) diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index a5b58f9910ad..a450dee30500 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -112,10 +112,7 @@ fn check_closures<'tcx>( } ctx.prev_bind = None; ctx.prev_move_to_closure.clear(); - if let Some(body) = cx - .tcx - .opt_hir_node_by_def_id(closure) - .and_then(associated_body) + if let Some(body) = associated_body(cx.tcx.hir_node_by_def_id(closure)) .map(|(_, body_id)| hir.body(body_id)) { euv::ExprUseVisitor::new(ctx, infcx, closure, cx.param_env, cx.typeck_results()).consume_body(body); diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index fc5a45dd56d6..85a2b1a67352 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -72,8 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { if let Some(self_def) = self_ty.ty_adt_def() && let Some(self_local_did) = self_def.did().as_local() - && let self_id = cx.tcx.local_def_id_to_hir_id(self_local_did) - && let Node::Item(x) = cx.tcx.hir_node(self_id) + && let Node::Item(x) = cx.tcx.hir_node_by_def_id(self_local_did) && let type_name = x.ident.name.as_str().to_lowercase() && (impl_item.ident.name.as_str() == type_name || impl_item.ident.name.as_str().replace('_', "") == type_name) diff --git a/clippy_lints/src/single_call_fn.rs b/clippy_lints/src/single_call_fn.rs index 223cbb3fae10..2ce7e714c642 100644 --- a/clippy_lints/src/single_call_fn.rs +++ b/clippy_lints/src/single_call_fn.rs @@ -95,7 +95,7 @@ impl SingleCallFn { /// to be considered. fn is_valid_item_kind(cx: &LateContext<'_>, def_id: LocalDefId) -> bool { matches!( - cx.tcx.hir_node(cx.tcx.local_def_id_to_hir_id(def_id)), + cx.tcx.hir_node_by_def_id(def_id), Node::Item(_) | Node::ImplItem(_) | Node::TraitItem(_) ) } diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 7882bfdd09fa..bdef82e9c5ee 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -321,7 +321,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { _: Span, def_id: LocalDefId, ) { - let is_in_trait_impl = if let Some(hir::Node::Item(item)) = cx.tcx.opt_hir_node_by_def_id( + let is_in_trait_impl = if let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id( cx.tcx .hir() .get_parent_item(cx.tcx.local_def_id_to_hir_id(def_id)) @@ -366,9 +366,9 @@ impl<'tcx> LateLintPass<'tcx> for Types { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'tcx>) { match item.kind { ImplItemKind::Const(ty, _) => { - let is_in_trait_impl = if let Some(hir::Node::Item(item)) = cx + let is_in_trait_impl = if let hir::Node::Item(item) = cx .tcx - .opt_hir_node_by_def_id(cx.tcx.hir().get_parent_item(item.hir_id()).def_id) + .hir_node_by_def_id(cx.tcx.hir().get_parent_item(item.hir_id()).def_id) { matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) } else { diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 81d4a26e9da4..4aaf3b0a0b67 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -74,7 +74,7 @@ impl LateLintPass<'_> for ZeroSizedMapValues { fn in_trait_impl(cx: &LateContext<'_>, hir_id: HirId) -> bool { let parent_id = cx.tcx.hir().get_parent_item(hir_id); let second_parent_id = cx.tcx.hir().get_parent_item(parent_id.into()).def_id; - if let Some(Node::Item(item)) = cx.tcx.opt_hir_node_by_def_id(second_parent_id) { + if let Node::Item(item) = cx.tcx.hir_node_by_def_id(second_parent_id) { if let ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind { return true; } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 708037a46555..1cf896d74345 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -330,8 +330,7 @@ pub fn is_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, diag_item: Symbol) /// Checks if the `def_id` belongs to a function that is part of a trait impl. pub fn is_def_id_trait_method(cx: &LateContext<'_>, def_id: LocalDefId) -> bool { - if let Some(hir_id) = cx.tcx.opt_local_def_id_to_hir_id(def_id) - && let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) + if let Node::Item(item) = cx.tcx.parent_hir_node(cx.tcx.local_def_id_to_hir_id(def_id)) && let ItemKind::Impl(imp) = item.kind { imp.of_trait.is_some() @@ -574,12 +573,12 @@ fn local_item_children_by_name(tcx: TyCtxt<'_>, local_id: LocalDefId, name: Symb let hir = tcx.hir(); let root_mod; - let item_kind = match tcx.opt_hir_node_by_def_id(local_id) { - Some(Node::Crate(r#mod)) => { + let item_kind = match tcx.hir_node_by_def_id(local_id) { + Node::Crate(r#mod) => { root_mod = ItemKind::Mod(r#mod); &root_mod }, - Some(Node::Item(item)) => &item.kind, + Node::Item(item) => &item.kind, _ => return Vec::new(), }; @@ -1254,12 +1253,10 @@ pub fn is_in_panic_handler(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { /// Gets the name of the item the expression is in, if available. pub fn get_item_name(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id).def_id; - match cx.tcx.opt_hir_node_by_def_id(parent_id) { - Some( - Node::Item(Item { ident, .. }) - | Node::TraitItem(TraitItem { ident, .. }) - | Node::ImplItem(ImplItem { ident, .. }), - ) => Some(ident.name), + match cx.tcx.hir_node_by_def_id(parent_id) { + Node::Item(Item { ident, .. }) + | Node::TraitItem(TraitItem { ident, .. }) + | Node::ImplItem(ImplItem { ident, .. }) => Some(ident.name), _ => None, } } @@ -2667,11 +2664,10 @@ impl<'tcx> ExprUseNode<'tcx> { .and(Binder::dummy(cx.tcx.type_of(id).instantiate_identity())), )), Self::Return(id) => { - let hir_id = cx.tcx.local_def_id_to_hir_id(id.def_id); if let Node::Expr(Expr { kind: ExprKind::Closure(c), .. - }) = cx.tcx.hir_node(hir_id) + }) = cx.tcx.hir_node_by_def_id(id.def_id) { match c.fn_decl.output { FnRetTy::DefaultReturn(_) => None, From de32d72ddbedadee6100cfcb9c93c33b483eb30d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Sat, 9 Mar 2024 20:32:36 +0000 Subject: [PATCH 1114/1222] Note that type param is chosen by caller when suggesting return impl Trait --- tests/ui/builtin_type_shadow.stderr | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ui/builtin_type_shadow.stderr b/tests/ui/builtin_type_shadow.stderr index 1e15cdee772a..033204af9255 100644 --- a/tests/ui/builtin_type_shadow.stderr +++ b/tests/ui/builtin_type_shadow.stderr @@ -19,6 +19,7 @@ LL | 42 | = note: expected type parameter `u32` found type `{integer}` + = note: the caller chooses a type for `u32` which can be different from `i32` error: aborting due to 2 previous errors From 16d1214047fc694125ee4bccc3138f876a9ea9e9 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 14 Mar 2024 09:10:28 +0000 Subject: [PATCH 1115/1222] Avoid various uses of `Option` in favor of using `DUMMY_SP` in the few cases that used `None` --- clippy_lints/src/non_copy_const.rs | 10 +++++----- clippy_utils/src/consts.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index ea73d9afa2ea..cebd23856565 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -290,14 +290,14 @@ impl NonCopyConst { promoted: None, }; let param_env = cx.tcx.param_env(def_id).with_reveal_all_normalized(cx.tcx); - let result = cx.tcx.const_eval_global_id_for_typeck(param_env, cid, None); + let result = cx.tcx.const_eval_global_id_for_typeck(param_env, cid, rustc_span::DUMMY_SP); self.is_value_unfrozen_raw(cx, result, ty) } fn is_value_unfrozen_expr<'tcx>(&self, cx: &LateContext<'tcx>, hir_id: HirId, def_id: DefId, ty: Ty<'tcx>) -> bool { let args = cx.typeck_results().node_args(hir_id); - let result = Self::const_eval_resolve(cx.tcx, cx.param_env, ty::UnevaluatedConst::new(def_id, args), None); + let result = Self::const_eval_resolve(cx.tcx, cx.param_env, ty::UnevaluatedConst::new(def_id, args), rustc_span::DUMMY_SP); self.is_value_unfrozen_raw(cx, result, ty) } @@ -305,7 +305,7 @@ impl NonCopyConst { tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, ct: ty::UnevaluatedConst<'tcx>, - span: Option, + span: Span, ) -> EvalToValTreeResult<'tcx> { match ty::Instance::resolve(tcx, param_env, ct.def, ct.args) { Ok(Some(instance)) => { @@ -315,8 +315,8 @@ impl NonCopyConst { }; tcx.const_eval_global_id_for_typeck(param_env, cid, span) }, - Ok(None) => Err(ErrorHandled::TooGeneric(span.unwrap_or(rustc_span::DUMMY_SP))), - Err(err) => Err(ErrorHandled::Reported(err.into(), span.unwrap_or(rustc_span::DUMMY_SP))), + Ok(None) => Err(ErrorHandled::TooGeneric(span)), + Err(err) => Err(ErrorHandled::Reported(err.into(), span)), } } } diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 07ed4fbbf8e9..e75d5953faef 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -550,7 +550,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let result = self .lcx .tcx - .const_eval_resolve(self.param_env, mir::UnevaluatedConst::new(def_id, args), None) + .const_eval_resolve(self.param_env, mir::UnevaluatedConst::new(def_id, args), qpath.span()) .ok() .map(|val| rustc_middle::mir::Const::from_value(val, ty))?; let result = mir_to_const(self.lcx, result)?; From 4c332d591770dc7b252adc9c6eadbed4f7e48c86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 5 Mar 2024 16:24:30 +0000 Subject: [PATCH 1116/1222] When displaying multispans, ignore empty lines adjacent to `...` ``` error[E0308]: `match` arms have incompatible types --> tests/ui/codemap_tests/huge_multispan_highlight.rs:98:18 | 6 | let _ = match true { | ---------- `match` arms have incompatible types 7 | true => ( | _________________- 8 | | // last line shown in multispan header ... | 96 | | 97 | | ), | |_________- this is found to be of type `()` 98 | false => " | __________________^ ... | 119 | | 120 | | ", | |_________^ expected `()`, found `&str` error[E0308]: `match` arms have incompatible types --> tests/ui/codemap_tests/huge_multispan_highlight.rs:215:18 | 122 | let _ = match true { | ---------- `match` arms have incompatible types 123 | true => ( | _________________- 124 | | 125 | | 1 // last line shown in multispan header ... | 213 | | 214 | | ), | |_________- this is found to be of type `{integer}` 215 | false => " | __________________^ 216 | | 217 | | 218 | | 1 last line shown in multispan ... | 237 | | 238 | | ", | |_________^ expected integer, found `&str` ``` --- tests/ui/async_yields_async.stderr | 3 +-- tests/ui/empty_line_after_outer_attribute.stderr | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/ui/async_yields_async.stderr b/tests/ui/async_yields_async.stderr index f1fae6549de4..991ad7ae0ae2 100644 --- a/tests/ui/async_yields_async.stderr +++ b/tests/ui/async_yields_async.stderr @@ -81,8 +81,7 @@ LL | let _m = async || { | _______________________- LL | | println!("I'm bored"); LL | | // Some more stuff -LL | | -LL | | // Finally something to await +... | LL | | CustomFutureType | | ^^^^^^^^^^^^^^^^ | | | diff --git a/tests/ui/empty_line_after_outer_attribute.stderr b/tests/ui/empty_line_after_outer_attribute.stderr index 1b5b00a4a83b..b43e6e30da22 100644 --- a/tests/ui/empty_line_after_outer_attribute.stderr +++ b/tests/ui/empty_line_after_outer_attribute.stderr @@ -22,8 +22,7 @@ error: found an empty line after an outer attribute. Perhaps you forgot to add a --> tests/ui/empty_line_after_outer_attribute.rs:28:1 | LL | / #[crate_type = "lib"] -LL | | -LL | | +... | LL | | fn with_two_newlines() { assert!(true) } | |_ From ed4fad50498887aaacfba716070693c1c3bccac9 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 5 Mar 2024 09:42:25 +0000 Subject: [PATCH 1117/1222] Deduplicate `associated_body` and `body_id` They match on almost the same patterns, which is fishy. Also turn `associated_body` into a method and do some cleanups nearby the call sites --- clippy_lints/src/needless_pass_by_ref_mut.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index a450dee30500..30d3e86dc4ed 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -13,7 +13,6 @@ use rustc_hir::{ use rustc_hir_typeck::expr_use_visitor as euv; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::associated_body; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::{self, Ty, TyCtxt, UpvarId, UpvarPath}; use rustc_session::impl_lint_pass; @@ -112,7 +111,10 @@ fn check_closures<'tcx>( } ctx.prev_bind = None; ctx.prev_move_to_closure.clear(); - if let Some(body) = associated_body(cx.tcx.hir_node_by_def_id(closure)) + if let Some(body) = cx + .tcx + .hir_node_by_def_id(closure) + .associated_body() .map(|(_, body_id)| hir.body(body_id)) { euv::ExprUseVisitor::new(ctx, infcx, closure, cx.param_env, cx.typeck_results()).consume_body(body); From 98f0050c63ce8c35238e184cf195217de5ce9118 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 20 Mar 2024 16:47:11 +0100 Subject: [PATCH 1118/1222] Rename `hir::Let` into `hir::LetExpr` --- clippy_lints/src/pattern_type_mismatch.rs | 4 ++-- clippy_lints/src/shadow.rs | 4 ++-- clippy_lints/src/unused_io_amount.rs | 2 +- clippy_utils/src/higher.rs | 4 ++-- clippy_utils/src/hir_utils.rs | 4 ++-- clippy_utils/src/visitors.rs | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index fbca4329342a..127801de7def 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_help; -use rustc_hir::{intravisit, Body, Expr, ExprKind, FnDecl, Let, LocalSource, Mutability, Pat, PatKind, Stmt, StmtKind}; +use rustc_hir::{intravisit, Body, Expr, ExprKind, FnDecl, LetExpr, LocalSource, Mutability, Pat, PatKind, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty; @@ -103,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch { } } } - if let ExprKind::Let(Let { pat, .. }) = expr.kind { + if let ExprKind::Let(LetExpr { pat, .. }) = expr.kind { apply_lint(cx, pat, DerefPossible::Possible); } } diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index c74364d89d61..df7bd4c8d1d3 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -5,7 +5,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_hir::def::Res; use rustc_hir::def_id::LocalDefId; use rustc_hir::hir_id::ItemLocalId; -use rustc_hir::{Block, Body, BodyOwnerKind, Expr, ExprKind, HirId, Let, Node, Pat, PatKind, QPath, UnOp}; +use rustc_hir::{Block, Body, BodyOwnerKind, Expr, ExprKind, HirId, LetExpr, Node, Pat, PatKind, QPath, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; use rustc_span::{Span, Symbol}; @@ -238,7 +238,7 @@ fn find_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<' let init = match node { Node::Arm(_) | Node::Pat(_) => continue, Node::Expr(expr) => match expr.kind { - ExprKind::Match(e, _, _) | ExprKind::Let(&Let { init: e, .. }) => Some(e), + ExprKind::Match(e, _, _) | ExprKind::Let(&LetExpr { init: e, .. }) => Some(e), _ => None, }, Node::Local(local) => local.init, diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index eb64dd633f60..1497d883dfc4 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -131,7 +131,7 @@ fn non_consuming_ok_arm<'a>(cx: &LateContext<'a>, arm: &hir::Arm<'a>) -> bool { fn check_expr<'a>(cx: &LateContext<'a>, expr: &'a hir::Expr<'a>) { match expr.kind { hir::ExprKind::If(cond, _, _) - if let ExprKind::Let(hir::Let { pat, init, .. }) = cond.kind + if let ExprKind::Let(hir::LetExpr { pat, init, .. }) = cond.kind && is_ok_wild_or_dotdot_pattern(cx, pat) && let Some(op) = should_lint(cx, init) => { diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index ba682813dadf..8ce19998a082 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -102,7 +102,7 @@ impl<'hir> IfLet<'hir> { if let ExprKind::If( Expr { kind: - ExprKind::Let(&hir::Let { + ExprKind::Let(&hir::LetExpr { pat: let_pat, init: let_expr, span: let_span, @@ -379,7 +379,7 @@ impl<'hir> WhileLet<'hir> { ExprKind::If( Expr { kind: - ExprKind::Let(&hir::Let { + ExprKind::Let(&hir::LetExpr { pat: let_pat, init: let_expr, span: let_span, diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 106d1d0d77f0..162bf24d85d2 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -8,7 +8,7 @@ use rustc_hir::def::Res; use rustc_hir::MatchSource::TryDesugar; use rustc_hir::{ ArrayLen, BinOpKind, BindingAnnotation, Block, BodyId, Closure, Expr, ExprField, ExprKind, FnRetTy, GenericArg, - GenericArgs, HirId, HirIdMap, InlineAsmOperand, Let, Lifetime, LifetimeName, Pat, PatField, PatKind, Path, + GenericArgs, HirId, HirIdMap, InlineAsmOperand, LetExpr, Lifetime, LifetimeName, Pat, PatField, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding, }; use rustc_lexer::{tokenize, TokenKind}; @@ -837,7 +837,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } }, - ExprKind::Let(Let { pat, init, ty, .. }) => { + ExprKind::Let(LetExpr { pat, init, ty, .. }) => { self.hash_expr(init); if let Some(ty) = ty { self.hash_ty(ty); diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index ebc38e531fe6..0a05ac029eae 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -5,7 +5,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::intravisit::{self, walk_block, walk_expr, Visitor}; use rustc_hir::{ - AnonConst, Arm, Block, BlockCheckMode, Body, BodyId, Expr, ExprKind, HirId, ItemId, ItemKind, Let, Pat, QPath, + AnonConst, Arm, Block, BlockCheckMode, Body, BodyId, Expr, ExprKind, HirId, ItemId, ItemKind, LetExpr, Pat, QPath, Stmt, UnOp, UnsafeSource, Unsafety, }; use rustc_lint::LateContext; @@ -624,7 +624,7 @@ pub fn for_each_unconsumed_temporary<'tcx, B>( | ExprKind::Field(e, _) | ExprKind::Unary(UnOp::Deref, e) | ExprKind::Match(e, ..) - | ExprKind::Let(&Let { init: e, .. }) => { + | ExprKind::Let(&LetExpr { init: e, .. }) => { helper(typeck, false, e, f)?; }, ExprKind::Block(&Block { expr: Some(e), .. }, _) | ExprKind::Cast(e, _) | ExprKind::Unary(_, e) => { From 8ca1bb5c46e37961a842b75ff128bba7fe622b4d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 20 Mar 2024 12:52:54 -0400 Subject: [PATCH 1119/1222] Bless test fallout (duplicate diagnostics) --- clippy_lints/src/future_not_send.rs | 2 +- clippy_utils/src/ty.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 9fb59a320d48..18f4e51ebd66 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { } let ret_ty = return_ty(cx, cx.tcx.local_def_id_to_hir_id(fn_def_id).expect_owner()); if let ty::Alias(ty::Opaque, AliasTy { def_id, args, .. }) = *ret_ty.kind() { - let preds = cx.tcx.explicit_item_bounds(def_id); + let preds = cx.tcx.explicit_item_super_predicates(def_id); let mut is_future = false; for (p, _span) in preds.iter_instantiated_copied(cx.tcx, args) { if let Some(trait_pred) = p.as_trait_clause() { diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 6e011a28bb7b..801452e444c6 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -96,7 +96,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' return false; } - for (predicate, _span) in cx.tcx.explicit_item_bounds(def_id).instantiate_identity_iter_copied() { + for (predicate, _span) in cx.tcx.explicit_item_super_predicates(def_id).instantiate_identity_iter_copied() { match predicate.kind().skip_binder() { // For `impl Trait`, it will register a predicate of `T: Trait`, so we go through // and check substitutions to find `U`. @@ -328,7 +328,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { }, ty::Tuple(args) => args.iter().any(|ty| is_must_use_ty(cx, ty)), ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { - for (predicate, _) in cx.tcx.explicit_item_bounds(def_id).skip_binder() { + for (predicate, _) in cx.tcx.explicit_item_super_predicates(def_id).skip_binder() { if let ty::ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() { if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) { return true; @@ -729,7 +729,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option sig_from_bounds( cx, ty, - cx.tcx.item_bounds(def_id).iter_instantiated(cx.tcx, args), + cx.tcx.item_super_predicates(def_id).iter_instantiated(cx.tcx, args), cx.tcx.opt_parent(def_id), ), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), @@ -807,7 +807,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option for (pred, _) in cx .tcx - .explicit_item_bounds(ty.def_id) + .explicit_item_super_predicates(ty.def_id) .iter_instantiated_copied(cx.tcx, ty.args) { match pred.kind().skip_binder() { From c60e243f2f6755f8ad9579c732264e25267aa955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 20 Mar 2024 22:50:32 +0000 Subject: [PATCH 1120/1222] Replace closures with `_` when suggesting fully qualified path for method call ``` error[E0283]: type annotations needed --> $DIR/into-inference-needs-type.rs:12:10 | LL | .into()?; | ^^^^ | = note: cannot satisfy `_: From<...>` = note: required for `FilterMap<...>` to implement `Into<_>` help: try using a fully qualified path to specify the expected types | LL ~ let list = , _>, _> as Into>::into(vec LL | .iter() LL | .map(|s| s.strip_prefix("t")) LL ~ .filter_map(Option::Some))?; | ``` Fix #122569. --- clippy_lints/src/box_default.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/box_default.rs b/clippy_lints/src/box_default.rs index 779ae03c4640..66206d1a059b 100644 --- a/clippy_lints/src/box_default.rs +++ b/clippy_lints/src/box_default.rs @@ -70,7 +70,9 @@ impl LateLintPass<'_> for BoxDefault { "try", if is_plain_default(cx, arg_path) || given_type(cx, expr) { "Box::default()".into() - } else if let Some(arg_ty) = cx.typeck_results().expr_ty(arg).make_suggestable(cx.tcx, true) { + } else if let Some(arg_ty) = + cx.typeck_results().expr_ty(arg).make_suggestable(cx.tcx, true, None) + { // Check if we can copy from the source expression in the replacement. // We need the call to have no argument (see `explicit_default_type`). if inner_call_args.is_empty() From 3ac6510518ba7bee20d3a6f31cca1e14815f3171 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 20 Mar 2024 16:53:50 -0400 Subject: [PATCH 1121/1222] Implement macro-based deref!() syntax for deref patterns Stop using `box PAT` syntax for deref patterns, as it's misleading and also causes their semantics being tangled up. --- clippy_lints/src/equatable_if_let.rs | 2 +- clippy_lints/src/matches/match_same_arms.rs | 2 +- clippy_lints/src/unnested_or_patterns.rs | 2 ++ clippy_lints/src/utils/author.rs | 5 +++++ clippy_utils/src/hir_utils.rs | 1 + clippy_utils/src/lib.rs | 2 +- 6 files changed, 11 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/equatable_if_let.rs b/clippy_lints/src/equatable_if_let.rs index 4e728d61b853..37442bf3e286 100644 --- a/clippy_lints/src/equatable_if_let.rs +++ b/clippy_lints/src/equatable_if_let.rs @@ -55,7 +55,7 @@ fn unary_pattern(pat: &Pat<'_>) -> bool { | PatKind::Err(_) => false, PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)), PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => etc.as_opt_usize().is_none() && array_rec(a), - PatKind::Ref(x, _) | PatKind::Box(x) => unary_pattern(x), + PatKind::Ref(x, _) | PatKind::Box(x) | PatKind::Deref(x) => unary_pattern(x), PatKind::Path(_) | PatKind::Lit(_) => true, } } diff --git a/clippy_lints/src/matches/match_same_arms.rs b/clippy_lints/src/matches/match_same_arms.rs index c7c453b7f6ec..cd61e733694b 100644 --- a/clippy_lints/src/matches/match_same_arms.rs +++ b/clippy_lints/src/matches/match_same_arms.rs @@ -243,7 +243,7 @@ impl<'a> NormalizedPat<'a> { fn from_pat(cx: &LateContext<'_>, arena: &'a DroplessArena, pat: &'a Pat<'_>) -> Self { match pat.kind { PatKind::Wild | PatKind::Binding(.., None) => Self::Wild, - PatKind::Binding(.., Some(pat)) | PatKind::Box(pat) | PatKind::Ref(pat, _) => { + PatKind::Binding(.., Some(pat)) | PatKind::Box(pat) | PatKind::Deref(pat) | PatKind::Ref(pat, _) => { Self::from_pat(cx, arena, pat) }, PatKind::Never => Self::Never, diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 7246214f9bf8..d4dd31e11781 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -242,6 +242,8 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec>, focus_idx: us |k| matches!(k, Box(_)), |k| always_pat!(k, Box(p) => p), ), + // FIXME(deref_patterns): Should we merge patterns here? + Deref(_) => false, // Transform `&mut x | ... | &mut y` into `&mut (x | y)`. Ref(target, Mutability::Mut) => extend_with_matching( target, start, alternatives, diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 187bfda129cd..5319915b2eac 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -689,6 +689,11 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { kind!("Box({pat})"); self.pat(pat); }, + PatKind::Deref(pat) => { + bind!(self, pat); + kind!("Deref({pat})"); + self.pat(pat); + }, PatKind::Ref(pat, muta) => { bind!(self, pat); kind!("Ref({pat}, Mutability::{muta:?})"); diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 162bf24d85d2..7a4eba9790ed 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -955,6 +955,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } }, PatKind::Box(pat) => self.hash_pat(pat), + PatKind::Deref(pat) => self.hash_pat(pat), PatKind::Lit(expr) => self.hash_expr(expr), PatKind::Or(pats) => { for pat in pats { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index a38db0ebec0f..b4cc747e0e62 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1678,7 +1678,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { match pat.kind { PatKind::Wild | PatKind::Never => false, // If `!` typechecked then the type is empty, so not refutable. PatKind::Binding(_, _, _, pat) => pat.map_or(false, |pat| is_refutable(cx, pat)), - PatKind::Box(pat) | PatKind::Ref(pat, _) => is_refutable(cx, pat), + PatKind::Box(pat) | PatKind::Deref(pat) | PatKind::Ref(pat, _) => is_refutable(cx, pat), PatKind::Path(ref qpath) => is_enum_variant(cx, qpath, pat.hir_id), PatKind::Or(pats) => { // TODO: should be the honest check, that pats is exhaustive set From 3d77b4efa5a55ebd35133264243ef36ad62bcb17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Fri, 15 Mar 2024 03:21:55 +0100 Subject: [PATCH 1122/1222] Rename AstConv to HIR ty lowering This includes updating astconv-related items and a few local variables. --- clippy_lints/src/implicit_hasher.rs | 4 ++-- clippy_lints/src/implied_bounds_in_impls.rs | 4 ++-- clippy_lints/src/types/redundant_allocation.rs | 4 ++-- clippy_lints/src/types/vec_box.rs | 6 +++--- clippy_lints/src/unconditional_recursion.rs | 4 ++-- clippy_lints/src/uninhabited_references.rs | 4 ++-- clippy_lints/src/use_self.rs | 4 ++-- clippy_lints/src/zero_sized_map_values.rs | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index a79bf66ae013..8acb138332cf 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -5,7 +5,7 @@ use rustc_errors::Diag; use rustc_hir as hir; use rustc_hir::intravisit::{walk_body, walk_expr, walk_inf, walk_ty, Visitor}; use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{Ty, TypeckResults}; @@ -227,7 +227,7 @@ impl<'tcx> ImplicitHasherType<'tcx> { .collect(); let params_len = params.len(); - let ty = hir_ty_to_ty(cx.tcx, hir_ty); + let ty = lower_ty(cx.tcx, hir_ty); if is_type_diagnostic_item(cx, ty, sym::HashMap) && params_len == 2 { Some(ImplicitHasherType::HashMap( diff --git a/clippy_lints/src/implied_bounds_in_impls.rs b/clippy_lints/src/implied_bounds_in_impls.rs index 74582f7f1de2..9f4d7b51271b 100644 --- a/clippy_lints/src/implied_bounds_in_impls.rs +++ b/clippy_lints/src/implied_bounds_in_impls.rs @@ -6,7 +6,7 @@ use rustc_hir::{ GenericArg, GenericBound, GenericBounds, ItemKind, PredicateOrigin, TraitBoundModifier, TyKind, TypeBinding, WherePredicate, }; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, ClauseKind, Generics, Ty, TyCtxt}; use rustc_session::declare_lint_pass; @@ -146,7 +146,7 @@ fn try_resolve_type<'tcx>( index: usize, ) -> Option> { match args.get(index - 1) { - Some(GenericArg::Type(ty)) => Some(hir_ty_to_ty(tcx, ty)), + Some(GenericArg::Type(ty)) => Some(lower_ty(tcx, ty)), Some(_) => None, None => Some(tcx.type_of(generics.params[index].def_id).skip_binder()), } diff --git a/clippy_lints/src/types/redundant_allocation.rs b/clippy_lints/src/types/redundant_allocation.rs index a0d609501a0c..9729c971672c 100644 --- a/clippy_lints/src/types/redundant_allocation.rs +++ b/clippy_lints/src/types/redundant_allocation.rs @@ -4,7 +4,7 @@ use clippy_utils::{path_def_id, qpath_generic_tys}; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, QPath, TyKind}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::LateContext; use rustc_middle::ty::TypeVisitableExt; use rustc_span::symbol::sym; @@ -59,7 +59,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>, qpath: // Reallocation of a fat pointer causes it to become thin. `hir_ty_to_ty` is safe to use // here because `mod.rs` guarantees this lint is only run on types outside of bodies and // is not run on locals. - let ty = hir_ty_to_ty(cx.tcx, hir_ty); + let ty = lower_ty(cx.tcx, hir_ty); if ty.has_escaping_bound_vars() || !ty.is_sized(cx.tcx, cx.param_env) { return false; } diff --git a/clippy_lints/src/types/vec_box.rs b/clippy_lints/src/types/vec_box.rs index 7926738d68f1..29996a6f783e 100644 --- a/clippy_lints/src/types/vec_box.rs +++ b/clippy_lints/src/types/vec_box.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, GenericArg, LangItem, QPath, TyKind}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::LateContext; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::TypeVisitableExt; @@ -35,7 +35,7 @@ pub(super) fn check<'tcx>( && let Some(GenericArg::Type(boxed_ty)) = last.args.first() // extract allocator from the Box for later && let boxed_alloc_ty = last.args.get(1) - && let ty_ty = hir_ty_to_ty(cx.tcx, boxed_ty) + && let ty_ty = lower_ty(cx.tcx, boxed_ty) && !ty_ty.has_escaping_bound_vars() && ty_ty.is_sized(cx.tcx, cx.param_env) && let Ok(ty_ty_size) = cx.layout_of(ty_ty).map(|l| l.size.bytes()) @@ -55,7 +55,7 @@ pub(super) fn check<'tcx>( } }, (Some(GenericArg::Type(l)), Some(GenericArg::Type(r))) => - hir_ty_to_ty(cx.tcx, l) == hir_ty_to_ty(cx.tcx, r), + lower_ty(cx.tcx, l) == lower_ty(cx.tcx, r), _ => false } { diff --git a/clippy_lints/src/unconditional_recursion.rs b/clippy_lints/src/unconditional_recursion.rs index d638af2b78b3..8764e3006c6b 100644 --- a/clippy_lints/src/unconditional_recursion.rs +++ b/clippy_lints/src/unconditional_recursion.rs @@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::{walk_body, walk_expr, FnKind, Visitor}; use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, Node, QPath, TyKind}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::map::Map; use rustc_middle::hir::nested_filter; @@ -74,7 +74,7 @@ fn get_hir_ty_def_id<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: rustc_hir::Ty<'tcx>) -> Op match qpath { QPath::Resolved(_, path) => path.res.opt_def_id(), QPath::TypeRelative(_, _) => { - let ty = hir_ty_to_ty(tcx, &hir_ty); + let ty = lower_ty(tcx, &hir_ty); match ty.kind() { ty::Alias(ty::Projection, proj) => { diff --git a/clippy_lints/src/uninhabited_references.rs b/clippy_lints/src/uninhabited_references.rs index 6732a43a19ec..88039372ebd2 100644 --- a/clippy_lints/src/uninhabited_references.rs +++ b/clippy_lints/src/uninhabited_references.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, Expr, ExprKind, FnDecl, FnRetTy, TyKind, UnOp}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_session::declare_lint_pass; @@ -71,7 +71,7 @@ impl LateLintPass<'_> for UninhabitedReferences { } if let FnRetTy::Return(hir_ty) = fndecl.output && let TyKind::Ref(_, mut_ty) = hir_ty.kind - && hir_ty_to_ty(cx.tcx, mut_ty.ty).is_privately_uninhabited(cx.tcx, cx.param_env) + && lower_ty(cx.tcx, mut_ty.ty).is_privately_uninhabited(cx.tcx, cx.param_env) { span_lint( cx, diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index b28037db1121..dfa816963bc0 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -11,7 +11,7 @@ use rustc_hir::{ self as hir, Expr, ExprKind, FnRetTy, FnSig, GenericArgsParentheses, GenericParam, GenericParamKind, HirId, Impl, ImplItemKind, Item, ItemKind, Pat, PatKind, Path, QPath, Ty, TyKind, }; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::Ty as MiddleTy; use rustc_session::impl_lint_pass; @@ -224,7 +224,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { && let ty = if in_body > 0 { cx.typeck_results().node_type(hir_ty.hir_id) } else { - hir_ty_to_ty(cx.tcx, hir_ty) + lower_ty(cx.tcx, hir_ty) } && let impl_ty = cx.tcx.type_of(impl_id).instantiate_identity() && same_type_and_consts(ty, impl_ty) diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 4aaf3b0a0b67..d1f7c6417c7e 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::{is_normalizable, is_type_diagnostic_item}; use rustc_hir::{self as hir, HirId, ItemKind, Node}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::{Adt, Ty, TypeVisitableExt}; @@ -91,5 +91,5 @@ fn ty_from_hir_ty<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'t None } }) - .unwrap_or_else(|| hir_ty_to_ty(cx.tcx, hir_ty)) + .unwrap_or_else(|| lower_ty(cx.tcx, hir_ty)) } From 6308c00e2e1963c989529ccc8a655cf5a0e29acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sun, 11 Feb 2024 09:22:52 +0100 Subject: [PATCH 1123/1222] Update (doc) comments Several (doc) comments were super outdated or didn't provide enough context. Some doc comments shoved everything in a single paragraph without respecting the fact that the first paragraph should be a single sentence because rustdoc treats these as item descriptions / synopses on module pages. --- book/src/development/type_checking.md | 10 +++++----- clippy_lints/src/types/redundant_allocation.rs | 2 +- clippy_lints/src/use_self.rs | 2 +- tests/ui/crashes/ice-6179.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/book/src/development/type_checking.md b/book/src/development/type_checking.md index 136b3fd02705..e6da4322a179 100644 --- a/book/src/development/type_checking.md +++ b/book/src/development/type_checking.md @@ -118,10 +118,10 @@ Here the HIR sees the types without "thinking" about them, it knows that the fun an `u32`. As far as `hir::Ty` is concerned those might be different types. But at the `ty::Ty` level the compiler understands that they're the same type, in-depth lifetimes, etc... -To get from a `hir::Ty` to a `ty::Ty`, you can use the [`hir_ty_to_ty`][hir_ty_to_ty] function outside of bodies or +To get from a `hir::Ty` to a `ty::Ty`, you can use the [`lower_ty`][lower_ty] function outside of bodies or the [`TypeckResults::node_type()`][node_type] method inside of bodies. -> **Warning**: Don't use `hir_ty_to_ty` inside of bodies, because this can cause ICEs. +> **Warning**: Don't use `lower_ty` inside of bodies, because this can cause ICEs. ## Creating Types programmatically @@ -162,6 +162,6 @@ in this chapter: [Ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html [TyKind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/ty_kind/enum.TyKind.html [TypeckResults]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html -[middle_ty]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_middle/ty/struct.Ty.html -[hir_ty]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/struct.Ty.html -[hir_ty_to_ty]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir_analysis/fn.hir_ty_to_ty.html +[middle_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html +[hir_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/struct.Ty.html +[lower_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/fn.lower_ty.html diff --git a/clippy_lints/src/types/redundant_allocation.rs b/clippy_lints/src/types/redundant_allocation.rs index 9729c971672c..37437cbfbec4 100644 --- a/clippy_lints/src/types/redundant_allocation.rs +++ b/clippy_lints/src/types/redundant_allocation.rs @@ -56,7 +56,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>, qpath: }; let inner_span = match qpath_generic_tys(inner_qpath).next() { Some(hir_ty) => { - // Reallocation of a fat pointer causes it to become thin. `hir_ty_to_ty` is safe to use + // Reallocation of a fat pointer causes it to become thin. `lower_ty` is safe to use // here because `mod.rs` guarantees this lint is only run on types outside of bodies and // is not run on locals. let ty = lower_ty(cx.tcx, hir_ty); diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index dfa816963bc0..a6b411d6c0f9 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -193,7 +193,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { } fn check_body(&mut self, _: &LateContext<'_>, _: &hir::Body<'_>) { - // `hir_ty_to_ty` cannot be called in `Body`s or it will panic (sometimes). But in bodies + // `lower_ty` cannot be called in `Body`s or it will panic (sometimes). But in bodies // we can use `cx.typeck_results.node_type(..)` to get the `ty::Ty` from a `hir::Ty`. // However the `node_type()` method can *only* be called in bodies. if let Some(&mut StackItem::Check { ref mut in_body, .. }) = self.stack.last_mut() { diff --git a/tests/ui/crashes/ice-6179.rs b/tests/ui/crashes/ice-6179.rs index fffc0f7d0d4f..91160eef03df 100644 --- a/tests/ui/crashes/ice-6179.rs +++ b/tests/ui/crashes/ice-6179.rs @@ -1,5 +1,5 @@ //! This is a minimal reproducer for the ICE in https://github.com/rust-lang/rust-clippy/pull/6179. -//! The ICE is mainly caused by using `hir_ty_to_ty`. See the discussion in the PR for details. +//! The ICE is mainly caused by using `lower_ty`. See the discussion in the PR for details. #![warn(clippy::use_self)] #![allow(dead_code, clippy::let_with_type_underscore)] From 5ae6fcfcd1f75ad14edaeeef9f22816eb95751f0 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 21 Mar 2024 16:50:21 -0400 Subject: [PATCH 1124/1222] Eagerly convert some ctors to use their specialized ctors --- clippy_lints/src/methods/unnecessary_to_owned.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index c234e4f9b110..6e525b5ff930 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -336,12 +336,9 @@ fn check_other_call_arg<'tcx>( && let Some((n_refs, receiver_ty)) = if n_refs > 0 || is_copy(cx, receiver_ty) { Some((n_refs, receiver_ty)) } else if trait_predicate.def_id() != deref_trait_id { - Some((1, Ty::new_ref(cx.tcx, + Some((1, Ty::new_imm_ref(cx.tcx, cx.tcx.lifetimes.re_erased, - ty::TypeAndMut { - ty: receiver_ty, - mutbl: Mutability::Not, - }, + receiver_ty, ))) } else { None From 9e26d4adbf47da6d99bba5eae11153308f83a56a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 21 Mar 2024 17:11:06 -0400 Subject: [PATCH 1125/1222] Programmatically convert some of the pat ctors --- .../src/casts/cast_slice_different_sizes.rs | 2 +- clippy_lints/src/casts/ptr_as_ptr.rs | 4 ++-- clippy_lints/src/casts/ref_as_ptr.rs | 2 +- clippy_lints/src/from_raw_with_void_ptr.rs | 2 +- clippy_lints/src/functions/must_use.rs | 2 +- .../src/functions/not_unsafe_ptr_arg_deref.rs | 2 +- .../src/matches/significant_drop_in_scrutinee.rs | 2 +- clippy_lints/src/methods/zst_offset.rs | 2 +- clippy_lints/src/mutex_atomic.rs | 2 +- clippy_lints/src/non_send_fields_in_send_ty.rs | 4 ++-- clippy_lints/src/significant_drop_tightening.rs | 2 +- clippy_lints/src/size_of_in_element_count.rs | 2 +- .../src/transmute/transmute_ptr_to_ptr.rs | 2 +- .../src/transmute/transmute_undefined_repr.rs | 16 ++++++++-------- clippy_lints/src/transmute/useless_transmute.rs | 2 +- clippy_lints/src/transmute/wrong_transmute.rs | 2 +- clippy_utils/src/consts.rs | 2 +- clippy_utils/src/lib.rs | 4 ++-- clippy_utils/src/ty.rs | 2 +- 19 files changed, 29 insertions(+), 29 deletions(-) diff --git a/clippy_lints/src/casts/cast_slice_different_sizes.rs b/clippy_lints/src/casts/cast_slice_different_sizes.rs index a31943f00218..76d5c3291790 100644 --- a/clippy_lints/src/casts/cast_slice_different_sizes.rs +++ b/clippy_lints/src/casts/cast_slice_different_sizes.rs @@ -87,7 +87,7 @@ fn is_child_of_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { /// the type is one of those slices fn get_raw_slice_ty_mut(ty: Ty<'_>) -> Option> { match ty.kind() { - ty::RawPtr(TypeAndMut { ty: slice_ty, mutbl }) => match slice_ty.kind() { + ty::RawPtr(slice_ty, mutbl) => match slice_ty.kind() { ty::Slice(ty) => Some(TypeAndMut { ty: *ty, mutbl: *mutbl }), _ => None, }, diff --git a/clippy_lints/src/casts/ptr_as_ptr.rs b/clippy_lints/src/casts/ptr_as_ptr.rs index 35e36e9ef3f5..5182c6179e68 100644 --- a/clippy_lints/src/casts/ptr_as_ptr.rs +++ b/clippy_lints/src/casts/ptr_as_ptr.rs @@ -33,8 +33,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Msrv) { if let ExprKind::Cast(cast_expr, cast_to_hir_ty) = expr.kind && let (cast_from, cast_to) = (cx.typeck_results().expr_ty(cast_expr), cx.typeck_results().expr_ty(expr)) - && let ty::RawPtr(TypeAndMut { mutbl: from_mutbl, .. }) = cast_from.kind() - && let ty::RawPtr(TypeAndMut { ty: to_pointee_ty, mutbl: to_mutbl }) = cast_to.kind() + && let ty::RawPtr(_, from_mutbl) = cast_from.kind() + && let ty::RawPtr(to_pointee_ty, to_mutbl) = cast_to.kind() && matches!((from_mutbl, to_mutbl), (Mutability::Not, Mutability::Not) | (Mutability::Mut, Mutability::Mut)) // The `U` in `pointer::cast` have to be `Sized` diff --git a/clippy_lints/src/casts/ref_as_ptr.rs b/clippy_lints/src/casts/ref_as_ptr.rs index 9d5a486336d5..a999b4e43884 100644 --- a/clippy_lints/src/casts/ref_as_ptr.rs +++ b/clippy_lints/src/casts/ref_as_ptr.rs @@ -21,7 +21,7 @@ pub(super) fn check<'tcx>( ); if matches!(cast_from.kind(), ty::Ref(..)) - && let ty::RawPtr(TypeAndMut { mutbl: to_mutbl, .. }) = cast_to.kind() + && let ty::RawPtr(_, to_mutbl) = cast_to.kind() && let Some(use_cx) = expr_use_ctxt(cx, expr) // TODO: only block the lint if `cast_expr` is a temporary && !matches!(use_cx.node, ExprUseNode::Local(_) | ExprUseNode::ConstStatic(_)) diff --git a/clippy_lints/src/from_raw_with_void_ptr.rs b/clippy_lints/src/from_raw_with_void_ptr.rs index c8d10dc4b929..1c91a377b1aa 100644 --- a/clippy_lints/src/from_raw_with_void_ptr.rs +++ b/clippy_lints/src/from_raw_with_void_ptr.rs @@ -44,7 +44,7 @@ impl LateLintPass<'_> for FromRawWithVoidPtr { && seg.ident.name == sym!(from_raw) && let Some(type_str) = path_def_id(cx, ty).and_then(|id| def_id_matches_type(cx, id)) && let arg_kind = cx.typeck_results().expr_ty(arg).kind() - && let RawPtr(TypeAndMut { ty, .. }) = arg_kind + && let ty::RawPtr(ty, _) = arg_kind && is_c_void(cx, *ty) { let msg = format!("creating a `{type_str}` from a void raw pointer"); diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 3aaf63ce340a..d752d010f9fe 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -207,7 +207,7 @@ fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, tys: &mut DefIdSet) }, ty::Tuple(args) => args.iter().any(|ty| is_mutable_ty(cx, ty, tys)), ty::Array(ty, _) | ty::Slice(ty) => is_mutable_ty(cx, ty, tys), - ty::RawPtr(ty::TypeAndMut { ty, mutbl }) | ty::Ref(_, ty, mutbl) => { + ty::RawPtr(ty, mutbl) | ty::Ref(_, ty, mutbl) => { mutbl == hir::Mutability::Mut || is_mutable_ty(cx, ty, tys) }, // calling something constitutes a side effect, so return true on all callables diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index f2aa7b597a79..2d757883f266 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -75,7 +75,7 @@ fn check_raw_ptr<'tcx>( } fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option { - if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_))) = ( + if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_, _))) = ( &arg.pat.kind, cx.maybe_typeck_results() .map(|typeck_results| typeck_results.pat_ty(arg.pat).kind()), diff --git a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index b770ad0ddb5c..10c3203725a8 100644 --- a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -149,7 +149,7 @@ impl<'a, 'tcx> SigDropChecker<'a, 'tcx> { false }, rustc_middle::ty::Array(ty, _) - | rustc_middle::ty::RawPtr(TypeAndMut { ty, .. }) + | rustc_middle::ty::RawPtr(ty, _) | rustc_middle::ty::Ref(_, ty, _) | rustc_middle::ty::Slice(ty) => self.has_sig_drop_attr(cx, *ty), _ => false, diff --git a/clippy_lints/src/methods/zst_offset.rs b/clippy_lints/src/methods/zst_offset.rs index 0b829d99aef8..d33021c2a7bf 100644 --- a/clippy_lints/src/methods/zst_offset.rs +++ b/clippy_lints/src/methods/zst_offset.rs @@ -6,7 +6,7 @@ use rustc_middle::ty; use super::ZST_OFFSET; pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) { - if let ty::RawPtr(ty::TypeAndMut { ty, .. }) = cx.typeck_results().expr_ty(recv).kind() + if let ty::RawPtr(ty, _) = cx.typeck_results().expr_ty(recv).kind() && let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(*ty)) && layout.is_zst() { diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index 4ae4fc9b0961..61243c837316 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -127,7 +127,7 @@ fn get_atomic_name(ty: Ty<'_>) -> Option<&'static str> { IntTy::I128 => None, } }, - ty::RawPtr(_) => Some("AtomicPtr"), + ty::RawPtr(_, _) => Some("AtomicPtr"), _ => None, } } diff --git a/clippy_lints/src/non_send_fields_in_send_ty.rs b/clippy_lints/src/non_send_fields_in_send_ty.rs index 793a3a9545cd..408216229a41 100644 --- a/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -219,7 +219,7 @@ fn ty_allowed_with_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t } }, // Raw pointers are `!Send` but allowed by the heuristic - ty::RawPtr(_) => true, + ty::RawPtr(_, _) => true, _ => false, } } @@ -229,7 +229,7 @@ fn contains_pointer_like<'tcx>(cx: &LateContext<'tcx>, target_ty: Ty<'tcx>) -> b for ty_node in target_ty.walk() { if let GenericArgKind::Type(inner_ty) = ty_node.unpack() { match inner_ty.kind() { - ty::RawPtr(_) => { + ty::RawPtr(_, _) => { return true; }, ty::Adt(adt_def, _) => { diff --git a/clippy_lints/src/significant_drop_tightening.rs b/clippy_lints/src/significant_drop_tightening.rs index f8726aa173a9..57470f950da0 100644 --- a/clippy_lints/src/significant_drop_tightening.rs +++ b/clippy_lints/src/significant_drop_tightening.rs @@ -199,7 +199,7 @@ impl<'cx, 'others, 'tcx> AttrChecker<'cx, 'others, 'tcx> { false }, rustc_middle::ty::Array(ty, _) - | rustc_middle::ty::RawPtr(TypeAndMut { ty, .. }) + | rustc_middle::ty::RawPtr(ty, _) | rustc_middle::ty::Ref(_, ty, _) | rustc_middle::ty::Slice(ty) => self.has_sig_drop_attr(*ty), _ => false, diff --git a/clippy_lints/src/size_of_in_element_count.rs b/clippy_lints/src/size_of_in_element_count.rs index 756e47cbdf0a..c26ce1272ff8 100644 --- a/clippy_lints/src/size_of_in_element_count.rs +++ b/clippy_lints/src/size_of_in_element_count.rs @@ -107,7 +107,7 @@ fn get_pointee_ty_and_count_expr<'tcx>( && METHODS.iter().any(|m| *m == method_ident) // Get the pointee type - && let ty::RawPtr(TypeAndMut { ty: pointee_ty, .. }) = + && let ty::RawPtr(pointee_ty, _) = cx.typeck_results().expr_ty(ptr_self).kind() { return Some((*pointee_ty, count)); diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs index 4ae4359eea0b..84fa201639ac 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs @@ -16,7 +16,7 @@ pub(super) fn check<'tcx>( arg: &'tcx Expr<'_>, ) -> bool { match (&from_ty.kind(), &to_ty.kind()) { - (ty::RawPtr(_), ty::RawPtr(to_ty)) => { + (ty::RawPtr(_, _), ty::RawPtr(to_ty)) => { span_lint_and_then( cx, TRANSMUTE_PTR_TO_PTR, diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index a6f03c85b4f6..44b5f460737d 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -45,8 +45,8 @@ pub(super) fn check<'tcx>( // ptr <-> ptr (ReducedTy::Other(from_sub_ty), ReducedTy::Other(to_sub_ty)) - if matches!(from_sub_ty.kind(), ty::Ref(..) | ty::RawPtr(_)) - && matches!(to_sub_ty.kind(), ty::Ref(..) | ty::RawPtr(_)) => + if matches!(from_sub_ty.kind(), ty::Ref(..) | ty::RawPtr(_, _)) + && matches!(to_sub_ty.kind(), ty::Ref(..) | ty::RawPtr(_, _)) => { from_ty = from_sub_ty; to_ty = to_sub_ty; @@ -196,21 +196,21 @@ fn reduce_refs<'tcx>(cx: &LateContext<'tcx>, mut from_ty: Ty<'tcx>, mut to_ty: T let (from_fat_ptr, to_fat_ptr) = loop { break match (from_ty.kind(), to_ty.kind()) { ( - &(ty::Ref(_, from_sub_ty, _) | ty::RawPtr(TypeAndMut { ty: from_sub_ty, .. })), - &(ty::Ref(_, to_sub_ty, _) | ty::RawPtr(TypeAndMut { ty: to_sub_ty, .. })), + &(ty::Ref(_, from_sub_ty, _) | ty::RawPtr(from_sub_ty, _)), + &(ty::Ref(_, to_sub_ty, _) | ty::RawPtr(to_sub_ty, _)), ) => { - from_raw_ptr = matches!(*from_ty.kind(), ty::RawPtr(_)); + from_raw_ptr = matches!(*from_ty.kind(), ty::RawPtr(_, _)); from_ty = from_sub_ty; - to_raw_ptr = matches!(*to_ty.kind(), ty::RawPtr(_)); + to_raw_ptr = matches!(*to_ty.kind(), ty::RawPtr(_, _)); to_ty = to_sub_ty; continue; }, - (&(ty::Ref(_, unsized_ty, _) | ty::RawPtr(TypeAndMut { ty: unsized_ty, .. })), _) + (&(ty::Ref(_, unsized_ty, _) | ty::RawPtr(unsized_ty, _)), _) if !unsized_ty.is_sized(cx.tcx, cx.param_env) => { (true, false) }, - (_, &(ty::Ref(_, unsized_ty, _) | ty::RawPtr(TypeAndMut { ty: unsized_ty, .. }))) + (_, &(ty::Ref(_, unsized_ty, _) | ty::RawPtr(unsized_ty, _))) if !unsized_ty.is_sized(cx.tcx, cx.param_env) => { (false, true) diff --git a/clippy_lints/src/transmute/useless_transmute.rs b/clippy_lints/src/transmute/useless_transmute.rs index 088c8fda87a3..f3d3516755c0 100644 --- a/clippy_lints/src/transmute/useless_transmute.rs +++ b/clippy_lints/src/transmute/useless_transmute.rs @@ -53,7 +53,7 @@ pub(super) fn check<'tcx>( } true }, - (ty::Int(_) | ty::Uint(_), ty::RawPtr(_)) => { + (ty::Int(_) | ty::Uint(_), ty::RawPtr(_, _)) => { span_lint_and_then( cx, USELESS_TRANSMUTE, diff --git a/clippy_lints/src/transmute/wrong_transmute.rs b/clippy_lints/src/transmute/wrong_transmute.rs index d1965565b926..ed815884a764 100644 --- a/clippy_lints/src/transmute/wrong_transmute.rs +++ b/clippy_lints/src/transmute/wrong_transmute.rs @@ -8,7 +8,7 @@ use rustc_middle::ty::{self, Ty}; /// Returns `true` if it's triggered, otherwise returns `false`. pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> bool { match (&from_ty.kind(), &to_ty.kind()) { - (ty::Float(_) | ty::Char, ty::Ref(..) | ty::RawPtr(_)) => { + (ty::Float(_) | ty::Char, ty::Ref(..) | ty::RawPtr(_, _)) => { span_lint( cx, WRONG_TRANSMUTE, diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 046087d32989..6b86630339fb 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -819,7 +819,7 @@ pub fn mir_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::Const<'tcx>) -> ty::Float(FloatTy::F64) => Some(Constant::F64(f64::from_bits( int.try_into().expect("invalid f64 bit representation"), ))), - ty::RawPtr(_) => Some(Constant::RawPtr(int.assert_bits(int.size()))), + ty::RawPtr(_, _) => Some(Constant::RawPtr(int.assert_bits(int.size()))), _ => None, }, (_, ty::Ref(_, inner_ty, _)) if matches!(inner_ty.kind(), ty::Str) => { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 11b56ed47de8..e90317f5524a 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1040,7 +1040,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind { .get(child_id) .map_or(&[][..], |x| &**x) { - if let rustc_ty::RawPtr(TypeAndMut { mutbl: mutability, .. }) | rustc_ty::Ref(_, _, mutability) = + if let rustc_ty::RawPtr(_, mutability) | rustc_ty::Ref(_, _, mutability) = *adjust.last().map_or(target, |a| a.target).kind() { return CaptureKind::Ref(mutability); @@ -3235,7 +3235,7 @@ fn get_path_to_ty<'tcx>(tcx: TyCtxt<'tcx>, from: LocalDefId, ty: Ty<'tcx>, args: rustc_ty::Array(..) | rustc_ty::Dynamic(..) | rustc_ty::Never - | rustc_ty::RawPtr(_) + | rustc_ty::RawPtr(_, _) | rustc_ty::Ref(..) | rustc_ty::Slice(_) | rustc_ty::Tuple(_) => format!("<{}>", EarlyBinder::bind(ty).instantiate(tcx, args)), diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 801452e444c6..97ce755adbbe 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -321,7 +321,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { match ty.kind() { ty::Adt(adt, _) => cx.tcx.has_attr(adt.did(), sym::must_use), ty::Foreign(did) => cx.tcx.has_attr(*did, sym::must_use), - ty::Slice(ty) | ty::Array(ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) | ty::Ref(_, ty, _) => { + ty::Slice(ty) | ty::Array(ty, _) | ty::RawPtr(ty, _) | ty::Ref(_, ty, _) => { // for the Array case we don't need to care for the len == 0 case // because we don't want to lint functions returning empty arrays is_must_use_ty(cx, *ty) From c051eee8ae69c483fddee2bdc5191182cb257465 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 21 Mar 2024 17:42:46 -0400 Subject: [PATCH 1126/1222] And the tools too --- clippy_lints/src/casts/as_ptr_cast_mut.rs | 11 +++-------- clippy_lints/src/casts/cast_ptr_alignment.rs | 10 +++++----- .../src/casts/cast_slice_from_raw_parts.rs | 4 ++-- clippy_lints/src/casts/ptr_as_ptr.rs | 2 +- clippy_lints/src/casts/ptr_cast_constness.rs | 12 +++--------- clippy_lints/src/casts/ref_as_ptr.rs | 2 +- clippy_lints/src/from_raw_with_void_ptr.rs | 4 ++-- clippy_lints/src/loops/explicit_iter_loop.rs | 6 +++--- clippy_lints/src/mut_reference.rs | 4 +--- .../src/significant_drop_tightening.rs | 2 +- clippy_lints/src/size_of_in_element_count.rs | 2 +- .../src/transmute/crosspointer_transmute.rs | 6 +++--- .../src/transmute/transmute_ptr_to_ptr.rs | 4 ++-- .../src/transmute/transmute_ptr_to_ref.rs | 4 ++-- .../src/transmute/transmute_ref_to_ref.rs | 18 +++++------------- .../src/transmute/transmute_undefined_repr.rs | 2 +- .../src/transmute/useless_transmute.rs | 13 ++++--------- clippy_utils/src/lib.rs | 2 +- 18 files changed, 41 insertions(+), 67 deletions(-) diff --git a/clippy_lints/src/casts/as_ptr_cast_mut.rs b/clippy_lints/src/casts/as_ptr_cast_mut.rs index 8bfb7383f148..a667ea04af0a 100644 --- a/clippy_lints/src/casts/as_ptr_cast_mut.rs +++ b/clippy_lints/src/casts/as_ptr_cast_mut.rs @@ -4,18 +4,13 @@ use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::mir::Mutability; -use rustc_middle::ty::{self, Ty, TypeAndMut}; +use rustc_middle::ty::{self, Ty}; use super::AS_PTR_CAST_MUT; pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>) { - if let ty::RawPtr(TypeAndMut { - mutbl: Mutability::Mut, - ty: ptrty, - }) = cast_to.kind() - && let ty::RawPtr(TypeAndMut { - mutbl: Mutability::Not, .. - }) = cx.typeck_results().node_type(cast_expr.hir_id).kind() + if let ty::RawPtr(ptrty, Mutability::Mut) = cast_to.kind() + && let ty::RawPtr(_, Mutability::Not) = cx.typeck_results().node_type(cast_expr.hir_id).kind() && let ExprKind::MethodCall(method_name, receiver, [], _) = cast_expr.peel_blocks().kind && method_name.ident.name == rustc_span::sym::as_ptr && let Some(as_ptr_did) = cx diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index f12f03fbe794..4d1a0f678f4b 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -33,13 +33,13 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { } fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>) { - if let ty::RawPtr(from_ptr_ty) = &cast_from.kind() - && let ty::RawPtr(to_ptr_ty) = &cast_to.kind() - && let Ok(from_layout) = cx.layout_of(from_ptr_ty.ty) - && let Ok(to_layout) = cx.layout_of(to_ptr_ty.ty) + if let ty::RawPtr(from_ptr_ty, _) = *cast_from.kind() + && let ty::RawPtr(to_ptr_ty, _) = *cast_to.kind() + && let Ok(from_layout) = cx.layout_of(from_ptr_ty) + && let Ok(to_layout) = cx.layout_of(to_ptr_ty) && from_layout.align.abi < to_layout.align.abi // with c_void, we inherently need to trust the user - && !is_c_void(cx, from_ptr_ty.ty) + && !is_c_void(cx, from_ptr_ty) // when casting from a ZST, we don't know enough to properly lint && !from_layout.is_zst() && !is_used_as_unaligned(cx, expr) diff --git a/clippy_lints/src/casts/cast_slice_from_raw_parts.rs b/clippy_lints/src/casts/cast_slice_from_raw_parts.rs index 3db1e3e6d97e..48629b6c5ccd 100644 --- a/clippy_lints/src/casts/cast_slice_from_raw_parts.rs +++ b/clippy_lints/src/casts/cast_slice_from_raw_parts.rs @@ -25,8 +25,8 @@ fn raw_parts_kind(cx: &LateContext<'_>, did: DefId) -> Option { pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>, msrv: &Msrv) { if msrv.meets(msrvs::PTR_SLICE_RAW_PARTS) - && let ty::RawPtr(ptrty) = cast_to.kind() - && let ty::Slice(_) = ptrty.ty.kind() + && let ty::RawPtr(ptrty, _) = cast_to.kind() + && let ty::Slice(_) = ptrty.kind() && let ExprKind::Call(fun, [ptr_arg, len_arg]) = cast_expr.peel_blocks().kind && let ExprKind::Path(ref qpath) = fun.kind && let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id() diff --git a/clippy_lints/src/casts/ptr_as_ptr.rs b/clippy_lints/src/casts/ptr_as_ptr.rs index 5182c6179e68..5a121e6a7eb3 100644 --- a/clippy_lints/src/casts/ptr_as_ptr.rs +++ b/clippy_lints/src/casts/ptr_as_ptr.rs @@ -6,7 +6,7 @@ use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, Mutability, QPath, TyKind}; use rustc_hir_pretty::qpath_to_string; use rustc_lint::LateContext; -use rustc_middle::ty::{self, TypeAndMut}; +use rustc_middle::ty; use rustc_span::sym; use super::PTR_AS_PTR; diff --git a/clippy_lints/src/casts/ptr_cast_constness.rs b/clippy_lints/src/casts/ptr_cast_constness.rs index ff069860a116..e88146331cae 100644 --- a/clippy_lints/src/casts/ptr_cast_constness.rs +++ b/clippy_lints/src/casts/ptr_cast_constness.rs @@ -4,7 +4,7 @@ use clippy_utils::sugg::Sugg; use rustc_errors::Applicability; use rustc_hir::{Expr, Mutability}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty, TypeAndMut}; +use rustc_middle::ty::{self, Ty}; use super::PTR_CAST_CONSTNESS; @@ -17,14 +17,8 @@ pub(super) fn check<'tcx>( msrv: &Msrv, ) { if msrv.meets(msrvs::POINTER_CAST_CONSTNESS) - && let ty::RawPtr(TypeAndMut { - mutbl: from_mutbl, - ty: from_ty, - }) = cast_from.kind() - && let ty::RawPtr(TypeAndMut { - mutbl: to_mutbl, - ty: to_ty, - }) = cast_to.kind() + && let ty::RawPtr(from_ty, from_mutbl) = cast_from.kind() + && let ty::RawPtr(to_ty, to_mutbl) = cast_to.kind() && matches!( (from_mutbl, to_mutbl), (Mutability::Not, Mutability::Mut) | (Mutability::Mut, Mutability::Not) diff --git a/clippy_lints/src/casts/ref_as_ptr.rs b/clippy_lints/src/casts/ref_as_ptr.rs index a999b4e43884..662737a14a4d 100644 --- a/clippy_lints/src/casts/ref_as_ptr.rs +++ b/clippy_lints/src/casts/ref_as_ptr.rs @@ -5,7 +5,7 @@ use clippy_utils::{expr_use_ctxt, is_no_std_crate, ExprUseNode}; use rustc_errors::Applicability; use rustc_hir::{Expr, Mutability, Ty, TyKind}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, TypeAndMut}; +use rustc_middle::ty; use super::REF_AS_PTR; diff --git a/clippy_lints/src/from_raw_with_void_ptr.rs b/clippy_lints/src/from_raw_with_void_ptr.rs index 1c91a377b1aa..286ba2306c92 100644 --- a/clippy_lints/src/from_raw_with_void_ptr.rs +++ b/clippy_lints/src/from_raw_with_void_ptr.rs @@ -4,7 +4,7 @@ use clippy_utils::ty::is_c_void; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{RawPtr, TypeAndMut}; +use rustc_middle::ty::{RawPtr}; use rustc_session::declare_lint_pass; use rustc_span::sym; @@ -44,7 +44,7 @@ impl LateLintPass<'_> for FromRawWithVoidPtr { && seg.ident.name == sym!(from_raw) && let Some(type_str) = path_def_id(cx, ty).and_then(|id| def_id_matches_type(cx, id)) && let arg_kind = cx.typeck_results().expr_ty(arg).kind() - && let ty::RawPtr(ty, _) = arg_kind + && let RawPtr(ty, _) = arg_kind && is_c_void(cx, *ty) { let msg = format!("creating a `{type_str}` from a void raw pointer"); diff --git a/clippy_lints/src/loops/explicit_iter_loop.rs b/clippy_lints/src/loops/explicit_iter_loop.rs index 814ccaa36f5a..eea5f2a94ea6 100644 --- a/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_iter_loop.rs @@ -10,7 +10,7 @@ use rustc_errors::Applicability; use rustc_hir::{Expr, Mutability}; use rustc_lint::LateContext; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability}; -use rustc_middle::ty::{self, EarlyBinder, Ty, TypeAndMut}; +use rustc_middle::ty::{self, EarlyBinder, Ty}; use rustc_span::sym; pub(super) fn check( @@ -160,7 +160,7 @@ fn is_ref_iterable<'tcx>( let self_ty = if mutbl.is_mut() { self_ty } else { - Ty::new_ref(cx.tcx, region, TypeAndMut { ty, mutbl }) + Ty::new_ref(cx.tcx, region, ty, mutbl) }; if implements_trait(cx, self_ty, trait_id, &[]) && let Some(ty) = @@ -175,7 +175,7 @@ fn is_ref_iterable<'tcx>( && !self_ty.is_ref() { // Attempt to borrow - let self_ty = Ty::new_ref(cx.tcx, cx.tcx.lifetimes.re_erased, TypeAndMut { ty: self_ty, mutbl }); + let self_ty = Ty::new_ref(cx.tcx, cx.tcx.lifetimes.re_erased, self_ty, mutbl); if implements_trait(cx, self_ty, trait_id, &[]) && let Some(ty) = make_normalized_projection(cx.tcx, cx.param_env, trait_id, sym!(IntoIter), [self_ty]) && ty == res_ty diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index f905a4e5b64c..14a1e6be7388 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -84,9 +84,7 @@ fn check_arguments<'tcx>( for (argument, parameter) in iter::zip(arguments, parameters) { match parameter.kind() { ty::Ref(_, _, Mutability::Not) - | ty::RawPtr(ty::TypeAndMut { - mutbl: Mutability::Not, .. - }) => { + | ty::RawPtr(_, Mutability::Not) => { if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, _) = argument.kind { span_lint( cx, diff --git a/clippy_lints/src/significant_drop_tightening.rs b/clippy_lints/src/significant_drop_tightening.rs index 57470f950da0..d3540bc8e1c3 100644 --- a/clippy_lints/src/significant_drop_tightening.rs +++ b/clippy_lints/src/significant_drop_tightening.rs @@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{self as hir}; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::ty::{GenericArgKind, Ty, TypeAndMut}; +use rustc_middle::ty::{GenericArgKind, Ty}; use rustc_session::impl_lint_pass; use rustc_span::symbol::Ident; use rustc_span::{sym, Span, DUMMY_SP}; diff --git a/clippy_lints/src/size_of_in_element_count.rs b/clippy_lints/src/size_of_in_element_count.rs index c26ce1272ff8..01f0e3cfadbd 100644 --- a/clippy_lints/src/size_of_in_element_count.rs +++ b/clippy_lints/src/size_of_in_element_count.rs @@ -4,7 +4,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, Ty, TypeAndMut}; +use rustc_middle::ty::{self, Ty}; use rustc_session::declare_lint_pass; use rustc_span::sym; diff --git a/clippy_lints/src/transmute/crosspointer_transmute.rs b/clippy_lints/src/transmute/crosspointer_transmute.rs index c4b9d82fc735..102aee1cb959 100644 --- a/clippy_lints/src/transmute/crosspointer_transmute.rs +++ b/clippy_lints/src/transmute/crosspointer_transmute.rs @@ -7,8 +7,8 @@ use rustc_middle::ty::{self, Ty}; /// Checks for `crosspointer_transmute` lint. /// Returns `true` if it's triggered, otherwise returns `false`. pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> bool { - match (&from_ty.kind(), &to_ty.kind()) { - (ty::RawPtr(from_ptr), _) if from_ptr.ty == to_ty => { + match (*from_ty.kind(), *to_ty.kind()) { + (ty::RawPtr(from_ptr_ty, _), _) if from_ptr_ty == to_ty => { span_lint( cx, CROSSPOINTER_TRANSMUTE, @@ -17,7 +17,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty ); true }, - (_, ty::RawPtr(to_ptr)) if to_ptr.ty == from_ty => { + (_, ty::RawPtr(to_ptr_ty, _)) if to_ptr_ty == from_ty => { span_lint( cx, CROSSPOINTER_TRANSMUTE, diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs index 84fa201639ac..1476ea8e7a4e 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs @@ -16,7 +16,7 @@ pub(super) fn check<'tcx>( arg: &'tcx Expr<'_>, ) -> bool { match (&from_ty.kind(), &to_ty.kind()) { - (ty::RawPtr(_, _), ty::RawPtr(to_ty)) => { + (ty::RawPtr(_, _), ty::RawPtr(to_ty, to_mutbl)) => { span_lint_and_then( cx, TRANSMUTE_PTR_TO_PTR, @@ -24,7 +24,7 @@ pub(super) fn check<'tcx>( "transmute from a pointer to a pointer", |diag| { if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) { - let sugg = arg.as_ty(Ty::new_ptr(cx.tcx, *to_ty)); + let sugg = arg.as_ty(Ty::new_ptr(cx.tcx, *to_ty, *to_mutbl)); diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified); } }, diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs index 4ab3afbe7143..cf78709583cf 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs @@ -20,7 +20,7 @@ pub(super) fn check<'tcx>( msrv: &Msrv, ) -> bool { match (&from_ty.kind(), &to_ty.kind()) { - (ty::RawPtr(from_ptr_ty), ty::Ref(_, to_ref_ty, mutbl)) => { + (ty::RawPtr(from_ptr_ty, _), ty::Ref(_, to_ref_ty, mutbl)) => { span_lint_and_then( cx, TRANSMUTE_PTR_TO_REF, @@ -44,7 +44,7 @@ pub(super) fn check<'tcx>( } else { sugg::make_unop(deref, arg.as_ty(format!("{cast} {ty_snip}"))).to_string() } - } else if from_ptr_ty.ty == *to_ref_ty { + } else if *from_ptr_ty == *to_ref_ty { if from_ptr_ty.has_erased_regions() { if msrv.meets(msrvs::POINTER_CAST) { format!("{deref}{}.cast::<{to_ref_ty}>()", arg.maybe_par()) diff --git a/clippy_lints/src/transmute/transmute_ref_to_ref.rs b/clippy_lints/src/transmute/transmute_ref_to_ref.rs index 6c885ebdea11..73321c56f3fe 100644 --- a/clippy_lints/src/transmute/transmute_ref_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ref_to_ref.rs @@ -19,7 +19,7 @@ pub(super) fn check<'tcx>( ) -> bool { let mut triggered = false; - if let (ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) = (&from_ty.kind(), &to_ty.kind()) { + if let (ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) = (*from_ty.kind(), *to_ty.kind()) { if let ty::Slice(slice_ty) = *ty_from.kind() && ty_to.is_str() && let ty::Uint(ty::UintTy::U8) = slice_ty.kind() @@ -27,7 +27,7 @@ pub(super) fn check<'tcx>( { let Some(top_crate) = std_or_core(cx) else { return true }; - let postfix = if *from_mutbl == Mutability::Mut { "_mut" } else { "" }; + let postfix = if from_mutbl == Mutability::Mut { "_mut" } else { "" }; let snippet = snippet(cx, arg.span, ".."); @@ -53,18 +53,10 @@ pub(super) fn check<'tcx>( "transmute from a reference to a reference", |diag| { if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) { - let ty_from_and_mut = ty::TypeAndMut { - ty: *ty_from, - mutbl: *from_mutbl, - }; - let ty_to_and_mut = ty::TypeAndMut { - ty: *ty_to, - mutbl: *to_mutbl, - }; let sugg_paren = arg - .as_ty(Ty::new_ptr(cx.tcx, ty_from_and_mut)) - .as_ty(Ty::new_ptr(cx.tcx, ty_to_and_mut)); - let sugg = if *to_mutbl == Mutability::Mut { + .as_ty(Ty::new_ptr(cx.tcx, ty_from, from_mutbl)) + .as_ty(Ty::new_ptr(cx.tcx, ty_to, to_mutbl)); + let sugg = if to_mutbl == Mutability::Mut { sugg_paren.mut_addr_deref() } else { sugg_paren.addr_deref() diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index 44b5f460737d..33c4031fa875 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_c_void; use rustc_hir::Expr; use rustc_lint::LateContext; -use rustc_middle::ty::{self, GenericArgsRef, IntTy, Ty, TypeAndMut, UintTy}; +use rustc_middle::ty::{self, GenericArgsRef, IntTy, Ty, UintTy}; #[expect(clippy::too_many_lines)] pub(super) fn check<'tcx>( diff --git a/clippy_lints/src/transmute/useless_transmute.rs b/clippy_lints/src/transmute/useless_transmute.rs index f3d3516755c0..70628f3d4f41 100644 --- a/clippy_lints/src/transmute/useless_transmute.rs +++ b/clippy_lints/src/transmute/useless_transmute.rs @@ -15,7 +15,7 @@ pub(super) fn check<'tcx>( to_ty: Ty<'tcx>, arg: &'tcx Expr<'_>, ) -> bool { - match (&from_ty.kind(), &to_ty.kind()) { + match (*from_ty.kind(), *to_ty.kind()) { _ if from_ty == to_ty && !from_ty.has_erased_regions() => { span_lint( cx, @@ -25,7 +25,7 @@ pub(super) fn check<'tcx>( ); true }, - (ty::Ref(_, rty, rty_mutbl), ty::RawPtr(ptr_ty)) => { + (ty::Ref(_, rty, rty_mutbl), ty::RawPtr(ptr_ty, ptr_mutbl)) => { // No way to give the correct suggestion here. Avoid linting for now. if !rty.has_erased_regions() { span_lint_and_then( @@ -35,15 +35,10 @@ pub(super) fn check<'tcx>( "transmute from a reference to a pointer", |diag| { if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) { - let rty_and_mut = ty::TypeAndMut { - ty: *rty, - mutbl: *rty_mutbl, - }; - - let sugg = if *ptr_ty == rty_and_mut { + let sugg = if ptr_ty == rty && rty_mutbl == ptr_mutbl { arg.as_ty(to_ty) } else { - arg.as_ty(Ty::new_ptr(cx.tcx, rty_and_mut)).as_ty(to_ty) + arg.as_ty(Ty::new_ptr(cx.tcx, rty, rty_mutbl)).as_ty(to_ty) }; diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index e90317f5524a..a526ba97af67 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -112,7 +112,7 @@ use rustc_middle::ty::fast_reject::SimplifiedType; use rustc_middle::ty::layout::IntegerExt; use rustc_middle::ty::{ self as rustc_ty, Binder, BorrowKind, ClosureKind, EarlyBinder, FloatTy, GenericArgsRef, IntTy, ParamEnv, - ParamEnvAnd, Ty, TyCtxt, TypeAndMut, TypeVisitableExt, UintTy, UpvarCapture, + ParamEnvAnd, Ty, TyCtxt, TypeVisitableExt, UintTy, UpvarCapture, }; use rustc_span::hygiene::{ExpnKind, MacroKind}; use rustc_span::source_map::SourceMap; From fe9a1bd95d06dad629606d9abae61232910d69ee Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 21 Mar 2024 15:49:17 -0400 Subject: [PATCH 1127/1222] Fix clippy --- clippy_lints/src/derive.rs | 4 ++-- clippy_lints/src/eta_reduction.rs | 4 ++-- clippy_lints/src/methods/unnecessary_to_owned.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index f0f2c7d6658f..c554edc8fceb 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -11,7 +11,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::traits::Reveal; use rustc_middle::ty::{ - self, ClauseKind, GenericArgKind, GenericParamDefKind, ImplPolarity, ParamEnv, ToPredicate, TraitPredicate, Ty, + self, ClauseKind, GenericArgKind, GenericParamDefKind, ParamEnv, ToPredicate, TraitPredicate, Ty, TyCtxt, }; use rustc_session::declare_lint_pass; @@ -502,7 +502,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| { ClauseKind::Trait(TraitPredicate { trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]), - polarity: ImplPolarity::Positive, + polarity: ty::PredicatePolarity::Positive, }) .to_predicate(tcx) }), diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 40be71a0e5d6..eccfc31fdd3e 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -9,7 +9,7 @@ use rustc_hir::{BindingAnnotation, Expr, ExprKind, FnRetTy, Param, PatKind, QPat use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{ - self, Binder, ClosureArgs, ClosureKind, FnSig, GenericArg, GenericArgKind, ImplPolarity, List, Region, RegionKind, + self, Binder, ClosureArgs, ClosureKind, FnSig, GenericArg, GenericArgKind, List, Region, RegionKind, Ty, TypeVisitableExt, TypeckResults, }; use rustc_session::declare_lint_pass; @@ -173,7 +173,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { if let Ok((ClosureKind::FnMut, _)) = cx.tcx.infer_ctxt().build().type_implements_fn_trait( cx.param_env, Binder::bind_with_vars(callee_ty_adjusted, List::empty()), - ImplPolarity::Positive, + ty::PredicatePolarity::Positive, ) && path_to_local(callee).map_or(false, |l| { local_used_in(cx, l, args) || local_used_after_expr(cx, l, expr) }) { diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index c234e4f9b110..abf717126fbf 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -18,7 +18,7 @@ use rustc_lint::LateContext; use rustc_middle::mir::Mutability; use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref}; use rustc_middle::ty::{ - self, ClauseKind, GenericArg, GenericArgKind, GenericArgsRef, ImplPolarity, ParamTy, ProjectionPredicate, + self, ClauseKind, GenericArg, GenericArgKind, GenericArgsRef, ParamTy, ProjectionPredicate, TraitPredicate, Ty, }; use rustc_span::{sym, Symbol}; @@ -669,7 +669,7 @@ fn check_borrow_predicate<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) { && let Some(borrow_id) = cx.tcx.get_diagnostic_item(sym::Borrow) && cx.tcx.predicates_of(method_def_id).predicates.iter().any(|(pred, _)| { if let ClauseKind::Trait(trait_pred) = pred.kind().skip_binder() - && trait_pred.polarity == ImplPolarity::Positive + && trait_pred.polarity == ty::PredicatePolarity::Positive && trait_pred.trait_ref.def_id == borrow_id { true From c70a7d257805a4b8a75e3f2d92d8510507cdc827 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 20 Mar 2024 17:50:31 +0100 Subject: [PATCH 1128/1222] Rename `hir::Local` into `hir::LetStmt` --- clippy_lints/src/box_default.rs | 4 ++-- clippy_lints/src/collection_is_never_read.rs | 6 +++--- clippy_lints/src/let_underscore.rs | 4 ++-- clippy_lints/src/let_with_type_underscore.rs | 4 ++-- clippy_lints/src/loops/utils.rs | 4 ++-- clippy_lints/src/loops/while_let_loop.rs | 4 ++-- clippy_lints/src/loops/while_let_on_iterator.rs | 4 ++-- clippy_lints/src/manual_hash_one.rs | 4 ++-- .../src/matches/infallible_destructuring_match.rs | 4 ++-- clippy_lints/src/matches/mod.rs | 4 ++-- clippy_lints/src/methods/needless_collect.rs | 4 ++-- clippy_lints/src/methods/str_splitn.rs | 4 ++-- clippy_lints/src/mixed_read_write_in_expression.rs | 4 ++-- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/needless_late_init.rs | 10 +++++----- clippy_lints/src/question_mark.rs | 4 ++-- clippy_lints/src/read_zero_byte_vec.rs | 4 ++-- clippy_lints/src/redundant_locals.rs | 4 ++-- clippy_lints/src/redundant_type_annotations.rs | 2 +- clippy_lints/src/reserve_after_initialization.rs | 4 ++-- clippy_lints/src/types/mod.rs | 4 ++-- clippy_lints/src/undocumented_unsafe_blocks.rs | 8 ++++---- clippy_lints/src/unit_types/let_unit_value.rs | 4 ++-- clippy_lints/src/unit_types/mod.rs | 4 ++-- clippy_lints/src/unused_peekable.rs | 4 ++-- clippy_lints/src/vec.rs | 6 +++--- clippy_lints/src/vec_init_then_push.rs | 4 ++-- clippy_utils/src/lib.rs | 14 +++++++------- 28 files changed, 66 insertions(+), 66 deletions(-) diff --git a/clippy_lints/src/box_default.rs b/clippy_lints/src/box_default.rs index 66206d1a059b..a950de4bd223 100644 --- a/clippy_lints/src/box_default.rs +++ b/clippy_lints/src/box_default.rs @@ -6,7 +6,7 @@ use clippy_utils::{is_default_equivalent, path_def_id}; use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::intravisit::{walk_ty, Visitor}; -use rustc_hir::{Block, Expr, ExprKind, Local, Node, QPath, Ty, TyKind}; +use rustc_hir::{Block, Expr, ExprKind, LetStmt, Node, QPath, Ty, TyKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::print::with_forced_trimmed_paths; @@ -139,7 +139,7 @@ impl<'tcx> Visitor<'tcx> for InferVisitor { fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { match cx.tcx.parent_hir_node(expr.hir_id) { - Node::Local(Local { ty: Some(ty), .. }) => { + Node::Local(LetStmt { ty: Some(ty), .. }) => { let mut v = InferVisitor::default(); v.visit_ty(ty); !v.0 diff --git a/clippy_lints/src/collection_is_never_read.rs b/clippy_lints/src/collection_is_never_read.rs index d820413e1112..e921b9b46a67 100644 --- a/clippy_lints/src/collection_is_never_read.rs +++ b/clippy_lints/src/collection_is_never_read.rs @@ -3,7 +3,7 @@ use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item}; use clippy_utils::visitors::for_each_expr_with_closures; use clippy_utils::{get_enclosing_block, path_to_local_id}; use core::ops::ControlFlow; -use rustc_hir::{Block, ExprKind, HirId, LangItem, Local, Node, PatKind}; +use rustc_hir::{Block, ExprKind, HirId, LangItem, LetStmt, Node, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; use rustc_span::symbol::sym; @@ -58,7 +58,7 @@ static COLLECTIONS: [Symbol; 9] = [ ]; impl<'tcx> LateLintPass<'tcx> for CollectionIsNeverRead { - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { // Look for local variables whose type is a container. Search surrounding bock for read access. if match_acceptable_type(cx, local, &COLLECTIONS) && let PatKind::Binding(_, local_id, _, _) = local.pat.kind @@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for CollectionIsNeverRead { } } -fn match_acceptable_type(cx: &LateContext<'_>, local: &Local<'_>, collections: &[rustc_span::Symbol]) -> bool { +fn match_acceptable_type(cx: &LateContext<'_>, local: &LetStmt<'_>, collections: &[rustc_span::Symbol]) -> bool { let ty = cx.typeck_results().pat_ty(local.pat); collections.iter().any(|&sym| is_type_diagnostic_item(cx, ty, sym)) // String type is a lang item but not a diagnostic item for now so we need a separate check diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index 0ea53c392802..619e933b4fff 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::{implements_trait, is_must_use_ty, match_type}; use clippy_utils::{is_from_proc_macro, is_must_use_func_call, paths}; -use rustc_hir::{Local, LocalSource, PatKind}; +use rustc_hir::{LetStmt, LocalSource, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::{GenericArgKind, IsSuggestable}; @@ -138,7 +138,7 @@ const SYNC_GUARD_PATHS: [&[&str]; 3] = [ ]; impl<'tcx> LateLintPass<'tcx> for LetUnderscore { - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &Local<'tcx>) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &LetStmt<'tcx>) { if matches!(local.source, LocalSource::Normal) && !in_external_macro(cx.tcx.sess, local.span) && let PatKind::Wild = local.pat.kind diff --git a/clippy_lints/src/let_with_type_underscore.rs b/clippy_lints/src/let_with_type_underscore.rs index 5f3f9b43f458..593b29154b42 100644 --- a/clippy_lints/src/let_with_type_underscore.rs +++ b/clippy_lints/src/let_with_type_underscore.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::snippet; -use rustc_hir::{Local, TyKind}; +use rustc_hir::{LetStmt, TyKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_session::declare_lint_pass; @@ -26,7 +26,7 @@ declare_clippy_lint! { declare_lint_pass!(UnderscoreTyped => [LET_WITH_TYPE_UNDERSCORE]); impl LateLintPass<'_> for UnderscoreTyped { - fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) { + fn check_local(&mut self, cx: &LateContext<'_>, local: &LetStmt<'_>) { if !in_external_macro(cx.tcx.sess, local.span) && let Some(ty) = local.ty // Ensure that it has a type defined && let TyKind::Infer = &ty.kind // that type is '_' diff --git a/clippy_lints/src/loops/utils.rs b/clippy_lints/src/loops/utils.rs index 8bca33754e81..7b45cc95431c 100644 --- a/clippy_lints/src/loops/utils.rs +++ b/clippy_lints/src/loops/utils.rs @@ -3,7 +3,7 @@ use clippy_utils::{get_parent_expr, is_integer_const, path_to_local, path_to_loc use rustc_ast::ast::{LitIntType, LitKind}; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_expr, walk_local, Visitor}; -use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, Local, Mutability, PatKind}; +use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, LetStmt, Mutability, PatKind}; use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, Ty}; @@ -141,7 +141,7 @@ impl<'a, 'tcx> InitializeVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { type NestedFilter = nested_filter::OnlyBodies; - fn visit_local(&mut self, l: &'tcx Local<'_>) { + fn visit_local(&mut self, l: &'tcx LetStmt<'_>) { // Look for declarations of the variable if l.pat.hir_id == self.var_id && let PatKind::Binding(.., ident, _) = l.pat.kind diff --git a/clippy_lints/src/loops/while_let_loop.rs b/clippy_lints/src/loops/while_let_loop.rs index 93774b897682..bd04827a1f0e 100644 --- a/clippy_lints/src/loops/while_let_loop.rs +++ b/clippy_lints/src/loops/while_let_loop.rs @@ -5,13 +5,13 @@ use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::needs_ordered_drop; use clippy_utils::visitors::any_temporaries_need_ordered_drop; use rustc_errors::Applicability; -use rustc_hir::{Block, Expr, ExprKind, Local, MatchSource, Pat, StmtKind}; +use rustc_hir::{Block, Expr, ExprKind, LetStmt, MatchSource, Pat, StmtKind}; use rustc_lint::LateContext; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) { let (init, has_trailing_exprs) = match (loop_block.stmts, loop_block.expr) { ([stmt, stmts @ ..], expr) => { - if let StmtKind::Let(&Local { + if let StmtKind::Let(&LetStmt { init: Some(e), els: None, .. diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index d070ee749856..194dd4752f91 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -6,7 +6,7 @@ use clippy_utils::{get_enclosing_loop_or_multi_call_closure, higher, is_refutabl use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::{Closure, Expr, ExprKind, HirId, LangItem, Local, Mutability, PatKind, UnOp}; +use rustc_hir::{Closure, Expr, ExprKind, HirId, LangItem, LetStmt, Mutability, PatKind, UnOp}; use rustc_lint::LateContext; use rustc_middle::hir::nested_filter::OnlyBodies; use rustc_middle::ty::adjustment::Adjust; @@ -286,7 +286,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: & self.cx.tcx.hir() } - fn visit_local(&mut self, l: &'tcx Local<'_>) { + fn visit_local(&mut self, l: &'tcx LetStmt<'_>) { if !self.after_loop { l.pat.each_binding_or_first(&mut |_, id, _, _| { if id == self.local_id { diff --git a/clippy_lints/src/manual_hash_one.rs b/clippy_lints/src/manual_hash_one.rs index 5cbab0ec977c..f8f33cfc82e9 100644 --- a/clippy_lints/src/manual_hash_one.rs +++ b/clippy_lints/src/manual_hash_one.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet_opt; use clippy_utils::visitors::{is_local_used, local_used_once}; use clippy_utils::{is_trait_method, path_to_local_id}; use rustc_errors::Applicability; -use rustc_hir::{BindingAnnotation, ExprKind, Local, Node, PatKind, StmtKind}; +use rustc_hir::{BindingAnnotation, ExprKind, LetStmt, Node, PatKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; use rustc_span::sym; @@ -60,7 +60,7 @@ impl ManualHashOne { impl_lint_pass!(ManualHashOne => [MANUAL_HASH_ONE]); impl LateLintPass<'_> for ManualHashOne { - fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) { + fn check_local(&mut self, cx: &LateContext<'_>, local: &LetStmt<'_>) { // `let mut hasher = seg.build_hasher();` if let PatKind::Binding(BindingAnnotation::MUT, hasher, _, None) = local.pat.kind && let Some(init) = local.init diff --git a/clippy_lints/src/matches/infallible_destructuring_match.rs b/clippy_lints/src/matches/infallible_destructuring_match.rs index c8a48246e676..0f242e0b9e12 100644 --- a/clippy_lints/src/matches/infallible_destructuring_match.rs +++ b/clippy_lints/src/matches/infallible_destructuring_match.rs @@ -2,12 +2,12 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::{path_to_local_id, peel_blocks, strip_pat_refs}; use rustc_errors::Applicability; -use rustc_hir::{ByRef, ExprKind, Local, MatchSource, PatKind, QPath}; +use rustc_hir::{ByRef, ExprKind, LetStmt, MatchSource, PatKind, QPath}; use rustc_lint::LateContext; use super::INFALLIBLE_DESTRUCTURING_MATCH; -pub(crate) fn check(cx: &LateContext<'_>, local: &Local<'_>) -> bool { +pub(crate) fn check(cx: &LateContext<'_>, local: &LetStmt<'_>) -> bool { if !local.span.from_expansion() && let Some(expr) = local.init && let ExprKind::Match(target, arms, MatchSource::Normal) = expr.kind diff --git a/clippy_lints/src/matches/mod.rs b/clippy_lints/src/matches/mod.rs index 50494f4819f4..580d4a642963 100644 --- a/clippy_lints/src/matches/mod.rs +++ b/clippy_lints/src/matches/mod.rs @@ -27,7 +27,7 @@ mod wild_in_or_pats; use clippy_config::msrvs::{self, Msrv}; use clippy_utils::source::{snippet_opt, walk_span_to_context}; use clippy_utils::{higher, in_constant, is_direct_expn_of, is_span_match, tokenize_with_text}; -use rustc_hir::{Arm, Expr, ExprKind, Local, MatchSource, Pat}; +use rustc_hir::{Arm, Expr, ExprKind, LetStmt, MatchSource, Pat}; use rustc_lexer::TokenKind; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; @@ -1124,7 +1124,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches { } } - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'_>) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'_>) { self.infallible_destructuring_match_linted |= local.els.is_none() && infallible_destructuring_match::check(cx, local); } diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index 78540353005d..378644c53c06 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -11,7 +11,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_errors::{Applicability, MultiSpan}; use rustc_hir::intravisit::{walk_block, walk_expr, Visitor}; use rustc_hir::{ - BindingAnnotation, Block, Expr, ExprKind, HirId, HirIdSet, Local, Mutability, Node, PatKind, Stmt, StmtKind, + BindingAnnotation, Block, Expr, ExprKind, HirId, HirIdSet, LetStmt, Mutability, Node, PatKind, Stmt, StmtKind, }; use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; @@ -424,7 +424,7 @@ fn get_expr_and_hir_id_from_stmt<'v>(stmt: &'v Stmt<'v>) -> Option<(&'v Expr<'v> match stmt.kind { StmtKind::Expr(expr) | StmtKind::Semi(expr) => Some((expr, None)), StmtKind::Item(..) => None, - StmtKind::Let(Local { init, pat, .. }) => { + StmtKind::Let(LetStmt { init, pat, .. }) => { if let PatKind::Binding(_, hir_id, ..) = pat.kind { init.map(|init_expr| (init_expr, Some(hir_id))) } else { diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 55cd1a38ec96..94e263cf3d1d 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -8,7 +8,7 @@ use clippy_utils::{is_diag_item_method, match_def_path, path_to_local_id, paths} use core::ops::ControlFlow; use rustc_errors::Applicability; use rustc_hir::{ - BindingAnnotation, Expr, ExprKind, HirId, LangItem, Local, MatchSource, Node, Pat, PatKind, QPath, Stmt, StmtKind, + BindingAnnotation, Expr, ExprKind, HirId, LangItem, LetStmt, MatchSource, Node, Pat, PatKind, QPath, Stmt, StmtKind, }; use rustc_lint::LateContext; use rustc_middle::ty; @@ -198,7 +198,7 @@ fn indirect_usage<'tcx>( binding: HirId, ctxt: SyntaxContext, ) -> Option> { - if let StmtKind::Let(&Local { + if let StmtKind::Let(&LetStmt { pat: Pat { kind: PatKind::Binding(BindingAnnotation::NONE, _, ident, None), .. diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs index 12c7c18afde6..656fb907fcda 100644 --- a/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/clippy_lints/src/mixed_read_write_in_expression.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_note}; use clippy_utils::{get_parent_expr, path_to_local, path_to_local_id}; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, Local, Node, Stmt, StmtKind}; +use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, LetStmt, Node, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::declare_lint_pass; @@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for EvalOrderDependence { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { match stmt.kind { StmtKind::Let(local) => { - if let Local { init: Some(e), .. } = local { + if let LetStmt { init: Some(e), .. } = local { DivergenceVisitor { cx }.visit_expr(e); } }, diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index c32025fcbb6a..79f0a398d55d 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -121,7 +121,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType { } } - fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::Local<'_>) { + fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::LetStmt<'_>) { if let hir::PatKind::Wild = local.pat.kind { return; } diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs index 4cda4b171e31..810799acb2e2 100644 --- a/clippy_lints/src/needless_late_init.rs +++ b/clippy_lints/src/needless_late_init.rs @@ -6,7 +6,7 @@ use clippy_utils::visitors::{for_each_expr, for_each_expr_with_closures, is_loca use core::ops::ControlFlow; use rustc_errors::{Applicability, MultiSpan}; use rustc_hir::{ - BindingAnnotation, Block, Expr, ExprKind, HirId, Local, LocalSource, MatchSource, Node, Pat, PatKind, Stmt, + BindingAnnotation, Block, Expr, ExprKind, HirId, LetStmt, LocalSource, MatchSource, Node, Pat, PatKind, Stmt, StmtKind, }; use rustc_lint::{LateContext, LateLintPass}; @@ -237,7 +237,7 @@ fn first_usage<'tcx>( }) } -fn local_snippet_without_semicolon(cx: &LateContext<'_>, local: &Local<'_>) -> Option { +fn local_snippet_without_semicolon(cx: &LateContext<'_>, local: &LetStmt<'_>) -> Option { let span = local.span.with_hi(match local.ty { // let : ; // ~~~~~~~~~~~~~~~ @@ -252,7 +252,7 @@ fn local_snippet_without_semicolon(cx: &LateContext<'_>, local: &Local<'_>) -> O fn check<'tcx>( cx: &LateContext<'tcx>, - local: &'tcx Local<'tcx>, + local: &'tcx LetStmt<'tcx>, local_stmt: &'tcx Stmt<'tcx>, block: &'tcx Block<'tcx>, binding_id: HirId, @@ -363,9 +363,9 @@ fn check<'tcx>( } impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit { - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { let mut parents = cx.tcx.hir().parent_iter(local.hir_id); - if let Local { + if let LetStmt { init: None, pat: &Pat { diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 831c291ed7cc..f1db571e1137 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -14,7 +14,7 @@ use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::LangItem::{self, OptionNone, OptionSome, ResultErr, ResultOk}; use rustc_hir::{ - BindingAnnotation, Block, ByRef, Expr, ExprKind, Local, Node, PatKind, PathSegment, QPath, Stmt, StmtKind, + BindingAnnotation, Block, ByRef, Expr, ExprKind, LetStmt, Node, PatKind, PathSegment, QPath, Stmt, StmtKind, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::Ty; @@ -109,7 +109,7 @@ fn find_let_else_ret_expression<'hir>(block: &'hir Block<'hir>) -> Option<&'hir } fn check_let_some_else_return_none(cx: &LateContext<'_>, stmt: &Stmt<'_>) { - if let StmtKind::Let(Local { + if let StmtKind::Let(LetStmt { pat, init: Some(init_expr), els: Some(els), diff --git a/clippy_lints/src/read_zero_byte_vec.rs b/clippy_lints/src/read_zero_byte_vec.rs index 0ebdb031d5a1..7f4735c6a889 100644 --- a/clippy_lints/src/read_zero_byte_vec.rs +++ b/clippy_lints/src/read_zero_byte_vec.rs @@ -3,7 +3,7 @@ use clippy_utils::get_enclosing_block; use clippy_utils::higher::{get_vec_init_kind, VecInitKind}; use clippy_utils::source::snippet; -use hir::{Expr, ExprKind, HirId, Local, PatKind, PathSegment, QPath, StmtKind}; +use hir::{Expr, ExprKind, HirId, LetStmt, PatKind, PathSegment, QPath, StmtKind}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::Res; @@ -57,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for ReadZeroByteVec { } if let StmtKind::Let(local) = stmt.kind - && let Local { + && let LetStmt { pat, init: Some(init), .. } = local && let PatKind::Binding(_, id, ident, _) = pat.kind diff --git a/clippy_lints/src/redundant_locals.rs b/clippy_lints/src/redundant_locals.rs index 6528a7b369f7..0f579f779dfd 100644 --- a/clippy_lints/src/redundant_locals.rs +++ b/clippy_lints/src/redundant_locals.rs @@ -3,7 +3,7 @@ use clippy_utils::is_from_proc_macro; use clippy_utils::ty::needs_ordered_drop; use rustc_ast::Mutability; use rustc_hir::def::Res; -use rustc_hir::{BindingAnnotation, ByRef, ExprKind, HirId, Local, Node, Pat, PatKind, QPath}; +use rustc_hir::{BindingAnnotation, ByRef, ExprKind, HirId, LetStmt, Node, Pat, PatKind, QPath}; use rustc_hir_typeck::expr_use_visitor::PlaceBase; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; @@ -47,7 +47,7 @@ declare_clippy_lint! { declare_lint_pass!(RedundantLocals => [REDUNDANT_LOCALS]); impl<'tcx> LateLintPass<'tcx> for RedundantLocals { - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { if !local.span.is_desugaring(DesugaringKind::Async) // the pattern is a single by-value binding && let PatKind::Binding(BindingAnnotation(ByRef::No, mutability), _, ident, None) = local.pat.kind diff --git a/clippy_lints/src/redundant_type_annotations.rs b/clippy_lints/src/redundant_type_annotations.rs index 079e6500e3cf..96f6f0ec36fc 100644 --- a/clippy_lints/src/redundant_type_annotations.rs +++ b/clippy_lints/src/redundant_type_annotations.rs @@ -131,7 +131,7 @@ fn extract_primty(ty_kind: &hir::TyKind<'_>) -> Option { } impl LateLintPass<'_> for RedundantTypeAnnotations { - fn check_local<'tcx>(&mut self, cx: &LateContext<'tcx>, local: &'tcx rustc_hir::Local<'tcx>) { + fn check_local<'tcx>(&mut self, cx: &LateContext<'tcx>, local: &'tcx rustc_hir::LetStmt<'tcx>) { if !is_lint_allowed(cx, REDUNDANT_TYPE_ANNOTATIONS, local.hir_id) // type annotation part && !local.span.from_expansion() diff --git a/clippy_lints/src/reserve_after_initialization.rs b/clippy_lints/src/reserve_after_initialization.rs index ca7a0c7c87bb..c227b5b22f4d 100644 --- a/clippy_lints/src/reserve_after_initialization.rs +++ b/clippy_lints/src/reserve_after_initialization.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet; use clippy_utils::{is_from_proc_macro, path_to_local_id}; use rustc_errors::Applicability; use rustc_hir::def::Res; -use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Local, PatKind, QPath, Stmt, StmtKind}; +use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, LetStmt, PatKind, QPath, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::impl_lint_pass; @@ -69,7 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { self.searcher = None; } - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { if let Some(init_expr) = local.init && let PatKind::Binding(BindingAnnotation::MUT, id, _, None) = local.pat.kind && !in_external_macro(cx.sess(), local.span) diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 2ad15ac8312d..0802cb2b7c75 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -12,7 +12,7 @@ mod vec_box; use rustc_hir as hir; use rustc_hir::intravisit::FnKind; use rustc_hir::{ - Body, FnDecl, FnRetTy, GenericArg, ImplItem, ImplItemKind, Item, ItemKind, Local, MutTy, QPath, TraitItem, + Body, FnDecl, FnRetTy, GenericArg, ImplItem, ImplItemKind, Item, ItemKind, LetStmt, MutTy, QPath, TraitItem, TraitItemKind, TyKind, }; use rustc_lint::{LateContext, LateLintPass}; @@ -425,7 +425,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { } } - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &Local<'tcx>) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &LetStmt<'tcx>) { if let Some(ty) = local.ty { self.check_ty( cx, diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index 0efa65b28e23..fe3888d09c98 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -158,7 +158,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks { } fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &hir::Stmt<'tcx>) { - let (hir::StmtKind::Let(&hir::Local { init: Some(expr), .. }) + let (hir::StmtKind::Let(&hir::LetStmt { init: Some(expr), .. }) | hir::StmtKind::Expr(expr) | hir::StmtKind::Semi(expr)) = stmt.kind else { @@ -342,7 +342,7 @@ fn block_parents_have_safety_comment( ) -> bool { let (span, hir_id) = match cx.tcx.parent_hir_node(id) { Node::Expr(expr) => match cx.tcx.parent_hir_node(expr.hir_id) { - Node::Local(hir::Local { span, hir_id, .. }) => (*span, *hir_id), + Node::Local(hir::LetStmt { span, hir_id, .. }) => (*span, *hir_id), Node::Item(hir::Item { kind: hir::ItemKind::Const(..) | ItemKind::Static(..), span, @@ -358,12 +358,12 @@ fn block_parents_have_safety_comment( }, Node::Stmt(hir::Stmt { kind: - hir::StmtKind::Let(hir::Local { span, hir_id, .. }) + hir::StmtKind::Let(hir::LetStmt { span, hir_id, .. }) | hir::StmtKind::Expr(hir::Expr { span, hir_id, .. }) | hir::StmtKind::Semi(hir::Expr { span, hir_id, .. }), .. }) - | Node::Local(hir::Local { span, hir_id, .. }) => (*span, *hir_id), + | Node::Local(hir::LetStmt { span, hir_id, .. }) => (*span, *hir_id), Node::Item(hir::Item { kind: hir::ItemKind::Const(..) | ItemKind::Static(..), span, diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index 9406d1607695..c11acab98c01 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -4,14 +4,14 @@ use clippy_utils::visitors::{for_each_local_assignment, for_each_value_source}; use core::ops::ControlFlow; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{Expr, ExprKind, HirId, HirIdSet, Local, MatchSource, Node, PatKind, QPath, TyKind}; +use rustc_hir::{Expr, ExprKind, HirId, HirIdSet, LetStmt, MatchSource, Node, PatKind, QPath, TyKind}; use rustc_lint::{LateContext, LintContext}; use rustc_middle::lint::{in_external_macro, is_from_async_await}; use rustc_middle::ty; use super::LET_UNIT_VALUE; -pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>) { +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx LetStmt<'_>) { // skip `let () = { ... }` if let PatKind::Tuple(fields, ..) = local.pat.kind && fields.is_empty() diff --git a/clippy_lints/src/unit_types/mod.rs b/clippy_lints/src/unit_types/mod.rs index 0abd48e6423b..e016bd3434b1 100644 --- a/clippy_lints/src/unit_types/mod.rs +++ b/clippy_lints/src/unit_types/mod.rs @@ -3,7 +3,7 @@ mod unit_arg; mod unit_cmp; mod utils; -use rustc_hir::{Expr, Local}; +use rustc_hir::{Expr, LetStmt}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; @@ -99,7 +99,7 @@ declare_clippy_lint! { declare_lint_pass!(UnitTypes => [LET_UNIT_VALUE, UNIT_CMP, UNIT_ARG]); impl<'tcx> LateLintPass<'tcx> for UnitTypes { - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { let_unit_value::check(cx, local); } diff --git a/clippy_lints/src/unused_peekable.rs b/clippy_lints/src/unused_peekable.rs index 3f4ab3e31cfe..e152a0e83438 100644 --- a/clippy_lints/src/unused_peekable.rs +++ b/clippy_lints/src/unused_peekable.rs @@ -3,7 +3,7 @@ use clippy_utils::ty::{is_type_diagnostic_item, peel_mid_ty_refs_is_mutable}; use clippy_utils::{fn_def_id, is_trait_method, path_to_local_id, peel_ref_operators}; use rustc_ast::Mutability; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::{Block, Expr, ExprKind, HirId, Local, Node, PatKind, PathSegment, StmtKind}; +use rustc_hir::{Block, Expr, ExprKind, HirId, LetStmt, Node, PatKind, PathSegment, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter::OnlyBodies; use rustc_session::declare_lint_pass; @@ -190,7 +190,7 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> { }, } }, - Node::Local(Local { init: Some(init), .. }) => { + Node::Local(LetStmt { init: Some(init), .. }) => { if arg_is_mut_peekable(self.cx, init) { self.found_peek_call = true; } diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index 7cfcf3fe946e..fba96b630a01 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -9,7 +9,7 @@ use clippy_utils::ty::is_copy; use clippy_utils::visitors::for_each_local_use_after_expr; use clippy_utils::{get_parent_expr, higher, is_trait_method}; use rustc_errors::Applicability; -use rustc_hir::{BorrowKind, Expr, ExprKind, HirId, Local, Mutability, Node, Pat, PatKind}; +use rustc_hir::{BorrowKind, Expr, ExprKind, HirId, LetStmt, Mutability, Node, Pat, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_middle::ty::layout::LayoutOf; @@ -63,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec { match cx.tcx.parent_hir_node(expr.hir_id) { // search for `let foo = vec![_]` expressions where all uses of `foo` // adjust to slices or call a method that exist on slices (e.g. len) - Node::Local(Local { + Node::Local(LetStmt { ty: None, pat: Pat { @@ -93,7 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec { } }, // if the local pattern has a specified type, do not lint. - Node::Local(Local { ty: Some(_), .. }) if higher::VecArgs::hir(cx, expr).is_some() => { + Node::Local(LetStmt { ty: Some(_), .. }) if higher::VecArgs::hir(cx, expr).is_some() => { self.span_to_lint_map.insert(callsite, None); }, // search for `for _ in vec![...]` diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs index ac3b2bdaf650..b58a4fb84746 100644 --- a/clippy_lints/src/vec_init_then_push.rs +++ b/clippy_lints/src/vec_init_then_push.rs @@ -7,7 +7,7 @@ use core::ops::ControlFlow; use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::{ - BindingAnnotation, Block, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, Stmt, StmtKind, UnOp, + BindingAnnotation, Block, Expr, ExprKind, HirId, LetStmt, Mutability, PatKind, QPath, Stmt, StmtKind, UnOp, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; @@ -157,7 +157,7 @@ impl<'tcx> LateLintPass<'tcx> for VecInitThenPush { self.searcher = None; } - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { if let Some(init_expr) = local.init && let PatKind::Binding(BindingAnnotation::MUT, id, name, None) = local.pat.kind && !in_external_macro(cx.sess(), local.span) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 11b56ed47de8..0709d56c2318 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -99,7 +99,7 @@ use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk}; use rustc_hir::{ self as hir, def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Closure, Destination, Expr, ExprField, ExprKind, FnDecl, FnRetTy, GenericArgs, HirId, Impl, ImplItem, ImplItemKind, ImplItemRef, Item, - ItemKind, LangItem, Local, MatchSource, Mutability, Node, OwnerId, Param, Pat, PatKind, Path, PathSegment, PrimTy, + ItemKind, LangItem, LetStmt, MatchSource, Mutability, Node, OwnerId, Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitItemRef, TraitRef, TyKind, UnOp, }; use rustc_lexer::{tokenize, TokenKind}; @@ -1462,7 +1462,7 @@ pub fn is_else_clause(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { pub fn is_inside_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { let mut child_id = expr.hir_id; for (parent_id, node) in tcx.hir().parent_iter(child_id) { - if let Node::Local(Local { + if let Node::Local(LetStmt { init: Some(init), els: Some(els), .. @@ -1482,7 +1482,7 @@ pub fn is_inside_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { pub fn is_else_clause_in_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { let mut child_id = expr.hir_id; for (parent_id, node) in tcx.hir().parent_iter(child_id) { - if let Node::Local(Local { els: Some(els), .. }) = node + if let Node::Local(LetStmt { els: Some(els), .. }) = node && els.hir_id == child_id { return true; @@ -2158,7 +2158,7 @@ pub fn is_expr_used_or_unified(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { Node::Stmt(Stmt { kind: StmtKind::Expr(_) | StmtKind::Semi(_) - | StmtKind::Let(Local { + | StmtKind::Let(LetStmt { pat: Pat { kind: PatKind::Wild, .. @@ -2639,7 +2639,7 @@ pub struct ExprUseCtxt<'tcx> { /// The node which consumes a value. pub enum ExprUseNode<'tcx> { /// Assignment to, or initializer for, a local - Local(&'tcx Local<'tcx>), + Local(&'tcx LetStmt<'tcx>), /// Initializer for a const or static item. ConstStatic(OwnerId), /// Implicit or explicit return from a function. @@ -2671,7 +2671,7 @@ impl<'tcx> ExprUseNode<'tcx> { /// Gets the needed type as it's defined without any type inference. pub fn defined_ty(&self, cx: &LateContext<'tcx>) -> Option> { match *self { - Self::Local(Local { ty: Some(ty), .. }) => Some(DefinedTy::Hir(ty)), + Self::Local(LetStmt { ty: Some(ty), .. }) => Some(DefinedTy::Hir(ty)), Self::ConstStatic(id) => Some(DefinedTy::Mir( cx.param_env .and(Binder::dummy(cx.tcx.type_of(id).instantiate_identity())), @@ -3158,7 +3158,7 @@ pub fn is_never_expr<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> Option< } } - fn visit_local(&mut self, l: &'tcx Local<'_>) { + fn visit_local(&mut self, l: &'tcx LetStmt<'_>) { if let Some(e) = l.init { self.visit_expr(e); } From a5a622edb582abf823b3ec49cd6f7104b0c18420 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 22 Mar 2024 18:06:20 +0100 Subject: [PATCH 1129/1222] Rename `hir::Node::Local` into `hir::Node::LetStmt` --- clippy_lints/src/assigning_clones.rs | 2 +- clippy_lints/src/box_default.rs | 2 +- clippy_lints/src/casts/ref_as_ptr.rs | 2 +- clippy_lints/src/casts/unnecessary_cast.rs | 4 ++-- clippy_lints/src/ignored_unit_patterns.rs | 2 +- clippy_lints/src/loops/same_item_push.rs | 2 +- clippy_lints/src/manual_rem_euclid.rs | 2 +- .../src/matches/match_single_binding.rs | 2 +- clippy_lints/src/matches/needless_match.rs | 2 +- clippy_lints/src/methods/clone_on_copy.rs | 2 +- .../iter_on_single_or_empty_collections.rs | 2 +- clippy_lints/src/methods/needless_collect.rs | 2 +- .../src/methods/readonly_write_lock.rs | 2 +- clippy_lints/src/methods/str_splitn.rs | 2 +- clippy_lints/src/methods/unnecessary_fold.rs | 2 +- clippy_lints/src/ptr.rs | 2 +- clippy_lints/src/shadow.rs | 2 +- clippy_lints/src/tuple_array_conversions.rs | 4 ++-- clippy_lints/src/undocumented_unsafe_blocks.rs | 6 +++--- clippy_lints/src/unit_types/let_unit_value.rs | 2 +- clippy_lints/src/unused_peekable.rs | 2 +- .../utils/internal_lints/metadata_collector.rs | 2 +- .../internal_lints/unnecessary_def_path.rs | 2 +- clippy_lints/src/vec.rs | 4 ++-- clippy_lints/src/zero_repeat_side_effects.rs | 2 +- clippy_utils/src/lib.rs | 18 +++++++++--------- clippy_utils/src/ty/type_certainty/mod.rs | 2 +- 27 files changed, 40 insertions(+), 40 deletions(-) diff --git a/clippy_lints/src/assigning_clones.rs b/clippy_lints/src/assigning_clones.rs index 88d9f762a87b..8e27b3ccefdc 100644 --- a/clippy_lints/src/assigning_clones.rs +++ b/clippy_lints/src/assigning_clones.rs @@ -163,7 +163,7 @@ fn is_ok_to_suggest<'tcx>(cx: &LateContext<'tcx>, lhs: &Expr<'tcx>, call: &CallC // TODO: This check currently bails if the local variable has no initializer. // That is overly conservative - the lint should fire even if there was no initializer, // but the variable has been initialized before `lhs` was evaluated. - if let Some(Node::Local(local)) = cx.tcx.hir().parent_id_iter(local).next().map(|p| cx.tcx.hir_node(p)) + if let Some(Node::LetStmt(local)) = cx.tcx.hir().parent_id_iter(local).next().map(|p| cx.tcx.hir_node(p)) && local.init.is_none() { return false; diff --git a/clippy_lints/src/box_default.rs b/clippy_lints/src/box_default.rs index a950de4bd223..8683cb86e8ac 100644 --- a/clippy_lints/src/box_default.rs +++ b/clippy_lints/src/box_default.rs @@ -139,7 +139,7 @@ impl<'tcx> Visitor<'tcx> for InferVisitor { fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { match cx.tcx.parent_hir_node(expr.hir_id) { - Node::Local(LetStmt { ty: Some(ty), .. }) => { + Node::LetStmt(LetStmt { ty: Some(ty), .. }) => { let mut v = InferVisitor::default(); v.visit_ty(ty); !v.0 diff --git a/clippy_lints/src/casts/ref_as_ptr.rs b/clippy_lints/src/casts/ref_as_ptr.rs index 9d5a486336d5..0d7eae182c49 100644 --- a/clippy_lints/src/casts/ref_as_ptr.rs +++ b/clippy_lints/src/casts/ref_as_ptr.rs @@ -24,7 +24,7 @@ pub(super) fn check<'tcx>( && let ty::RawPtr(TypeAndMut { mutbl: to_mutbl, .. }) = cast_to.kind() && let Some(use_cx) = expr_use_ctxt(cx, expr) // TODO: only block the lint if `cast_expr` is a temporary - && !matches!(use_cx.node, ExprUseNode::Local(_) | ExprUseNode::ConstStatic(_)) + && !matches!(use_cx.node, ExprUseNode::LetStmt(_) | ExprUseNode::ConstStatic(_)) { let core_or_std = if is_no_std_crate(cx) { "core" } else { "std" }; let fn_name = match to_mutbl { diff --git a/clippy_lints/src/casts/unnecessary_cast.rs b/clippy_lints/src/casts/unnecessary_cast.rs index 08341ff32f35..148d52cb5ddc 100644 --- a/clippy_lints/src/casts/unnecessary_cast.rs +++ b/clippy_lints/src/casts/unnecessary_cast.rs @@ -66,7 +66,7 @@ pub(super) fn check<'tcx>( && let QPath::Resolved(None, Path { res, .. }) = qpath && let Res::Local(hir_id) = res && let parent = cx.tcx.parent_hir_node(*hir_id) - && let Node::Local(local) = parent + && let Node::LetStmt(local) = parent { if let Some(ty) = local.ty && let TyKind::Path(qpath) = ty.kind @@ -275,7 +275,7 @@ fn is_cast_from_ty_alias<'tcx>(cx: &LateContext<'tcx>, expr: impl Visitable<'tcx } // Local usage } else if let Res::Local(hir_id) = res - && let Node::Local(l) = cx.tcx.parent_hir_node(hir_id) + && let Node::LetStmt(l) = cx.tcx.parent_hir_node(hir_id) { if let Some(e) = l.init && is_cast_from_ty_alias(cx, e, cast_from) diff --git a/clippy_lints/src/ignored_unit_patterns.rs b/clippy_lints/src/ignored_unit_patterns.rs index 80a537b9f941..a32201d80793 100644 --- a/clippy_lints/src/ignored_unit_patterns.rs +++ b/clippy_lints/src/ignored_unit_patterns.rs @@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for IgnoredUnitPatterns { // Ignore function parameters return; }, - Node::Local(local) if local.ty.is_some() => { + Node::LetStmt(local) if local.ty.is_some() => { // Ignore let bindings with explicit type return; }, diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index 0f35514b8ad6..670a78d58c3c 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -62,7 +62,7 @@ pub(super) fn check<'tcx>( if let Node::Pat(pat) = node && let PatKind::Binding(bind_ann, ..) = pat.kind && !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut)) - && let Node::Local(parent_let_expr) = cx.tcx.parent_hir_node(hir_id) + && let Node::LetStmt(parent_let_expr) = cx.tcx.parent_hir_node(hir_id) && let Some(init) = parent_let_expr.init { match init.kind { diff --git a/clippy_lints/src/manual_rem_euclid.rs b/clippy_lints/src/manual_rem_euclid.rs index 0bde62bd5549..ab9bca170cf7 100644 --- a/clippy_lints/src/manual_rem_euclid.rs +++ b/clippy_lints/src/manual_rem_euclid.rs @@ -81,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid { // Apply only to params or locals with annotated types match cx.tcx.parent_hir_node(hir_id) { Node::Param(..) => (), - Node::Local(local) => { + Node::LetStmt(local) => { let Some(ty) = local.ty else { return }; if matches!(ty.kind, TyKind::Infer) { return; diff --git a/clippy_lints/src/matches/match_single_binding.rs b/clippy_lints/src/matches/match_single_binding.rs index 61977045fd46..864923b27739 100644 --- a/clippy_lints/src/matches/match_single_binding.rs +++ b/clippy_lints/src/matches/match_single_binding.rs @@ -148,7 +148,7 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e fn opt_parent_assign_span<'a>(cx: &LateContext<'a>, ex: &Expr<'a>) -> Option { if let Node::Expr(parent_arm_expr) = cx.tcx.parent_hir_node(ex.hir_id) { return match cx.tcx.parent_hir_node(parent_arm_expr.hir_id) { - Node::Local(parent_let_expr) => Some(AssignmentExpr::Local { + Node::LetStmt(parent_let_expr) => Some(AssignmentExpr::Local { span: parent_let_expr.span, pat_span: parent_let_expr.pat.span(), }), diff --git a/clippy_lints/src/matches/needless_match.rs b/clippy_lints/src/matches/needless_match.rs index 3d3f29e5fc6c..cee77f62b61e 100644 --- a/clippy_lints/src/matches/needless_match.rs +++ b/clippy_lints/src/matches/needless_match.rs @@ -125,7 +125,7 @@ fn strip_return<'hir>(expr: &'hir Expr<'hir>) -> &'hir Expr<'hir> { fn expr_ty_matches_p_ty(cx: &LateContext<'_>, expr: &Expr<'_>, p_expr: &Expr<'_>) -> bool { match cx.tcx.parent_hir_node(p_expr.hir_id) { // Compare match_expr ty with local in `let local = match match_expr {..}` - Node::Local(local) => { + Node::LetStmt(local) => { let results = cx.typeck_results(); return same_type_and_consts(results.node_type(local.hir_id), results.expr_ty(expr)); }, diff --git a/clippy_lints/src/methods/clone_on_copy.rs b/clippy_lints/src/methods/clone_on_copy.rs index fb5c0c544a95..d4a5de3d1dea 100644 --- a/clippy_lints/src/methods/clone_on_copy.rs +++ b/clippy_lints/src/methods/clone_on_copy.rs @@ -69,7 +69,7 @@ pub(super) fn check( _ => false, }, // local binding capturing a reference - Node::Local(l) if matches!(l.pat.kind, PatKind::Binding(BindingAnnotation(ByRef::Yes, _), ..)) => { + Node::LetStmt(l) if matches!(l.pat.kind, PatKind::Binding(BindingAnnotation(ByRef::Yes, _), ..)) => { return; }, _ => false, diff --git a/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs b/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs index 4c7c56e7174a..19b7e97339de 100644 --- a/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs +++ b/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs @@ -50,7 +50,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: &str, re | ExprKind::Break(_, _) => true, _ => false, }, - Some((Node::Stmt(_) | Node::Local(_), _)) => false, + Some((Node::Stmt(_) | Node::LetStmt(_), _)) => false, _ => true, }; diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index 378644c53c06..9e2fd92255e1 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -85,7 +85,7 @@ pub(super) fn check<'tcx>( ); } }, - Node::Local(l) => { + Node::LetStmt(l) => { if let PatKind::Binding(BindingAnnotation::NONE | BindingAnnotation::MUT, id, _, None) = l.pat.kind && let ty = cx.typeck_results().expr_ty(collect_expr) && [sym::Vec, sym::VecDeque, sym::BinaryHeap, sym::LinkedList] diff --git a/clippy_lints/src/methods/readonly_write_lock.rs b/clippy_lints/src/methods/readonly_write_lock.rs index 6c6846c4b476..9b0180d93699 100644 --- a/clippy_lints/src/methods/readonly_write_lock.rs +++ b/clippy_lints/src/methods/readonly_write_lock.rs @@ -24,7 +24,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, receiver && let Node::Expr(unwrap_call_expr) = cx.tcx.parent_hir_node(expr.hir_id) && is_unwrap_call(cx, unwrap_call_expr) && let parent = cx.tcx.parent_hir_node(unwrap_call_expr.hir_id) - && let Node::Local(local) = parent + && let Node::LetStmt(local) = parent && let Some(mir) = enclosing_mir(cx.tcx, expr.hir_id) && let Some((local, _)) = mir .local_decls diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 94e263cf3d1d..946cdb49d274 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -128,7 +128,7 @@ fn check_manual_split_once_indirect( ) -> Option<()> { let ctxt = expr.span.ctxt(); let mut parents = cx.tcx.hir().parent_iter(expr.hir_id); - if let (_, Node::Local(local)) = parents.next()? + if let (_, Node::LetStmt(local)) = parents.next()? && let PatKind::Binding(BindingAnnotation::MUT, iter_binding_id, iter_ident, None) = local.pat.kind && let (iter_stmt_id, Node::Stmt(_)) = parents.next()? && let (_, Node::Block(enclosing_block)) = parents.next()? diff --git a/clippy_lints/src/methods/unnecessary_fold.rs b/clippy_lints/src/methods/unnecessary_fold.rs index 988f3e86fcf0..ccc8d17970ec 100644 --- a/clippy_lints/src/methods/unnecessary_fold.rs +++ b/clippy_lints/src/methods/unnecessary_fold.rs @@ -20,7 +20,7 @@ fn needs_turbofish(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { // some common cases where turbofish isn't needed: // - assigned to a local variable with a type annotation - if let hir::Node::Local(local) = parent + if let hir::Node::LetStmt(local) = parent && local.ty.is_some() { return false; diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 2587b3881bbf..896c99a71046 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -604,7 +604,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: match get_expr_use_or_unification_node(self.cx.tcx, e) { Some((Node::Stmt(_), _)) => (), - Some((Node::Local(l), _)) => { + Some((Node::LetStmt(l), _)) => { // Only trace simple bindings. e.g `let x = y;` if let PatKind::Binding(BindingAnnotation::NONE, id, _, None) = l.pat.kind { self.bindings.insert(id, args_idx); diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index df7bd4c8d1d3..d98b37bda355 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -241,7 +241,7 @@ fn find_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<' ExprKind::Match(e, _, _) | ExprKind::Let(&LetExpr { init: e, .. }) => Some(e), _ => None, }, - Node::Local(local) => local.init, + Node::LetStmt(local) => local.init, _ => None, }; return init; diff --git a/clippy_lints/src/tuple_array_conversions.rs b/clippy_lints/src/tuple_array_conversions.rs index 0d84a9ab395e..564b065d0ba2 100644 --- a/clippy_lints/src/tuple_array_conversions.rs +++ b/clippy_lints/src/tuple_array_conversions.rs @@ -159,7 +159,7 @@ fn all_bindings_are_for_conv<'tcx>( .iter() .map(|node| match node { Node::Pat(pat) => kind.eq(&pat.kind).then_some(pat.hir_id), - Node::Local(l) => Some(l.hir_id), + Node::LetStmt(l) => Some(l.hir_id), _ => None, }) .all_equal() @@ -170,7 +170,7 @@ fn all_bindings_are_for_conv<'tcx>( && local_parents.first().is_some_and(|node| { let Some(ty) = match node { Node::Pat(pat) => Some(pat.hir_id), - Node::Local(l) => Some(l.hir_id), + Node::LetStmt(l) => Some(l.hir_id), _ => None, } .map(|hir_id| cx.typeck_results().node_type(hir_id)) else { diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index fe3888d09c98..5fe4b74b3a7a 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -342,7 +342,7 @@ fn block_parents_have_safety_comment( ) -> bool { let (span, hir_id) = match cx.tcx.parent_hir_node(id) { Node::Expr(expr) => match cx.tcx.parent_hir_node(expr.hir_id) { - Node::Local(hir::LetStmt { span, hir_id, .. }) => (*span, *hir_id), + Node::LetStmt(hir::LetStmt { span, hir_id, .. }) => (*span, *hir_id), Node::Item(hir::Item { kind: hir::ItemKind::Const(..) | ItemKind::Static(..), span, @@ -363,7 +363,7 @@ fn block_parents_have_safety_comment( | hir::StmtKind::Semi(hir::Expr { span, hir_id, .. }), .. }) - | Node::Local(hir::LetStmt { span, hir_id, .. }) => (*span, *hir_id), + | Node::LetStmt(hir::LetStmt { span, hir_id, .. }) => (*span, *hir_id), Node::Item(hir::Item { kind: hir::ItemKind::Const(..) | ItemKind::Static(..), span, @@ -603,7 +603,7 @@ fn get_body_search_span(cx: &LateContext<'_>) -> Option { for (_, node) in map.parent_iter(body.hir_id) { match node { Node::Expr(e) => span = e.span, - Node::Block(_) | Node::Arm(_) | Node::Stmt(_) | Node::Local(_) => (), + Node::Block(_) | Node::Arm(_) | Node::Stmt(_) | Node::LetStmt(_) => (), Node::Item(hir::Item { kind: hir::ItemKind::Const(..) | ItemKind::Static(..), .. diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index c11acab98c01..ffb909d79073 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -102,7 +102,7 @@ fn expr_needs_inferred_result<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) - return false; } while let Some(id) = locals_to_check.pop() { - if let Node::Local(l) = cx.tcx.parent_hir_node(id) { + if let Node::LetStmt(l) = cx.tcx.parent_hir_node(id) { if !l.ty.map_or(true, |ty| matches!(ty.kind, TyKind::Infer)) { return false; } diff --git a/clippy_lints/src/unused_peekable.rs b/clippy_lints/src/unused_peekable.rs index e152a0e83438..e6f799335d7d 100644 --- a/clippy_lints/src/unused_peekable.rs +++ b/clippy_lints/src/unused_peekable.rs @@ -190,7 +190,7 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> { }, } }, - Node::Local(LetStmt { init: Some(init), .. }) => { + Node::LetStmt(LetStmt { init: Some(init), .. }) => { if arg_is_mut_peekable(self.cx, init) { self.found_peek_call = true; } diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index 1ebe1d6a2c4b..c56c8ddc7a92 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -1006,7 +1006,7 @@ fn get_parent_local<'hir>(cx: &LateContext<'hir>, expr: &'hir hir::Expr<'hir>) - fn get_parent_local_hir_id<'hir>(cx: &LateContext<'hir>, hir_id: hir::HirId) -> Option<&'hir hir::Local<'hir>> { match cx.tcx.parent_hir_node(hir_id) { - hir::Node::Local(local) => Some(local), + hir::Node::LetStmt(local) => Some(local), hir::Node::Pat(pattern) => get_parent_local_hir_id(cx, pattern.hir_id), _ => None, } diff --git a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs index f4e277fd0c4c..304a13793740 100644 --- a/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs +++ b/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs @@ -217,7 +217,7 @@ fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option match cx.qpath_res(qpath, expr.hir_id) { Res::Local(hir_id) => { - if let Node::Local(Local { init: Some(init), .. }) = cx.tcx.parent_hir_node(hir_id) { + if let Node::LetStmt(Local { init: Some(init), .. }) = cx.tcx.parent_hir_node(hir_id) { path_to_matched_type(cx, init) } else { None diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index fba96b630a01..27ead55bf39c 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -63,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec { match cx.tcx.parent_hir_node(expr.hir_id) { // search for `let foo = vec![_]` expressions where all uses of `foo` // adjust to slices or call a method that exist on slices (e.g. len) - Node::Local(LetStmt { + Node::LetStmt(LetStmt { ty: None, pat: Pat { @@ -93,7 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec { } }, // if the local pattern has a specified type, do not lint. - Node::Local(LetStmt { ty: Some(_), .. }) if higher::VecArgs::hir(cx, expr).is_some() => { + Node::LetStmt(LetStmt { ty: Some(_), .. }) if higher::VecArgs::hir(cx, expr).is_some() => { self.span_to_lint_map.insert(callsite, None); }, // search for `for _ in vec![...]` diff --git a/clippy_lints/src/zero_repeat_side_effects.rs b/clippy_lints/src/zero_repeat_side_effects.rs index 852d04cd21b2..143fecdd237d 100644 --- a/clippy_lints/src/zero_repeat_side_effects.rs +++ b/clippy_lints/src/zero_repeat_side_effects.rs @@ -78,7 +78,7 @@ fn inner_check(cx: &LateContext<'_>, expr: &'_ rustc_hir::Expr<'_>, inner_expr: let parent_hir_node = cx.tcx.parent_hir_node(expr.hir_id); let return_type = cx.typeck_results().expr_ty(expr); - if let Node::Local(l) = parent_hir_node { + if let Node::LetStmt(l) = parent_hir_node { array_span_lint( cx, l.span, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 0709d56c2318..d7886e723e86 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -184,7 +184,7 @@ pub fn expr_or_init<'a, 'b, 'tcx: 'b>(cx: &LateContext<'tcx>, mut expr: &'a Expr pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<'tcx>> { if let Node::Pat(pat) = cx.tcx.hir_node(hir_id) && matches!(pat.kind, PatKind::Binding(BindingAnnotation::NONE, ..)) - && let Node::Local(local) = cx.tcx.parent_hir_node(hir_id) + && let Node::LetStmt(local) = cx.tcx.parent_hir_node(hir_id) { return local.init; } @@ -1079,7 +1079,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind { }, _ => break, }, - Node::Local(l) => match pat_capture_kind(cx, l.pat) { + Node::LetStmt(l) => match pat_capture_kind(cx, l.pat) { CaptureKind::Value => break, capture @ CaptureKind::Ref(_) => return capture, }, @@ -1357,7 +1357,7 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>( ExprKind::Closure { .. } | ExprKind::Loop(..) => return Some(e), _ => (), }, - Node::Stmt(_) | Node::Block(_) | Node::Local(_) | Node::Arm(_) => (), + Node::Stmt(_) | Node::Block(_) | Node::LetStmt(_) | Node::Arm(_) => (), _ => break, } } @@ -1462,7 +1462,7 @@ pub fn is_else_clause(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { pub fn is_inside_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { let mut child_id = expr.hir_id; for (parent_id, node) in tcx.hir().parent_iter(child_id) { - if let Node::Local(LetStmt { + if let Node::LetStmt(LetStmt { init: Some(init), els: Some(els), .. @@ -1482,7 +1482,7 @@ pub fn is_inside_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { pub fn is_else_clause_in_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { let mut child_id = expr.hir_id; for (parent_id, node) in tcx.hir().parent_iter(child_id) { - if let Node::Local(LetStmt { els: Some(els), .. }) = node + if let Node::LetStmt(LetStmt { els: Some(els), .. }) = node && els.hir_id == child_id { return true; @@ -2639,7 +2639,7 @@ pub struct ExprUseCtxt<'tcx> { /// The node which consumes a value. pub enum ExprUseNode<'tcx> { /// Assignment to, or initializer for, a local - Local(&'tcx LetStmt<'tcx>), + LetStmt(&'tcx LetStmt<'tcx>), /// Initializer for a const or static item. ConstStatic(OwnerId), /// Implicit or explicit return from a function. @@ -2671,7 +2671,7 @@ impl<'tcx> ExprUseNode<'tcx> { /// Gets the needed type as it's defined without any type inference. pub fn defined_ty(&self, cx: &LateContext<'tcx>) -> Option> { match *self { - Self::Local(LetStmt { ty: Some(ty), .. }) => Some(DefinedTy::Hir(ty)), + Self::LetStmt(LetStmt { ty: Some(ty), .. }) => Some(DefinedTy::Hir(ty)), Self::ConstStatic(id) => Some(DefinedTy::Mir( cx.param_env .and(Binder::dummy(cx.tcx.type_of(id).instantiate_identity())), @@ -2731,7 +2731,7 @@ impl<'tcx> ExprUseNode<'tcx> { let sig = cx.tcx.fn_sig(id).skip_binder(); Some(DefinedTy::Mir(cx.tcx.param_env(id).and(sig.input(i)))) }, - Self::Local(_) | Self::FieldAccess(..) | Self::Callee | Self::Expr | Self::Other => None, + Self::LetStmt(_) | Self::FieldAccess(..) | Self::Callee | Self::Expr | Self::Other => None, } } } @@ -2770,7 +2770,7 @@ pub fn expr_use_ctxt<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> Optio .continue_value() .map(|(use_node, child_id)| { let node = match use_node { - Node::Local(l) => ExprUseNode::Local(l), + Node::LetStmt(l) => ExprUseNode::LetStmt(l), Node::ExprField(field) => ExprUseNode::Field(field), Node::Item(&Item { diff --git a/clippy_utils/src/ty/type_certainty/mod.rs b/clippy_utils/src/ty/type_certainty/mod.rs index 7913926928f2..762830ffd78d 100644 --- a/clippy_utils/src/ty/type_certainty/mod.rs +++ b/clippy_utils/src/ty/type_certainty/mod.rs @@ -242,7 +242,7 @@ fn path_segment_certainty( Node::Param(..) => Certainty::Certain(None), // A local's type is certain if its type annotation is certain or it has an initializer whose // type is certain. - Node::Local(local) => { + Node::LetStmt(local) => { let lhs = local.ty.map_or(Certainty::Uncertain, |ty| type_certainty(cx, ty)); let rhs = local .init From 74ca34bbc6b5789437c5e8ed310b0b97f005347a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 23 Mar 2024 12:21:20 +0100 Subject: [PATCH 1130/1222] rename MIR int2ptr casts to match library name --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index dadb0d662ce8..0c4260037f23 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -112,7 +112,7 @@ fn check_rvalue<'tcx>( Rvalue::Repeat(operand, _) | Rvalue::Use(operand) | Rvalue::Cast( - CastKind::PointerFromExposedAddress + CastKind::PointerWithExposedProvenance | CastKind::IntToInt | CastKind::FloatToInt | CastKind::IntToFloat From 0fd455451c5de31b3928fd703a12e092ea296e4d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 17 Mar 2024 10:12:25 +0100 Subject: [PATCH 1131/1222] move assert_unsafe_preconditions to its own file These macros and functions are not intrinsics, after all. --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index dadb0d662ce8..cabebf89becc 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -174,7 +174,7 @@ fn check_rvalue<'tcx>( )) } }, - Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_) | NullOp::UbCheck(_), _) + Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_) | NullOp::UbChecks, _) | Rvalue::ShallowInitBox(_, _) => Ok(()), Rvalue::UnaryOp(_, operand) => { let ty = operand.ty(body, tcx); From c69744603a54c5de80e0422ed757fa44e73dc08c Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Sun, 24 Mar 2024 14:57:57 +0000 Subject: [PATCH 1132/1222] Rename `{enter,exit}_lint_attrs` to `check_attributes{,_post}` --- clippy_config/src/msrvs.rs | 4 ++-- clippy_lints/src/cognitive_complexity.rs | 4 ++-- clippy_lints/src/missing_doc.rs | 4 ++-- clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs | 2 +- clippy_utils/src/lib.rs | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clippy_config/src/msrvs.rs b/clippy_config/src/msrvs.rs index bf4da5f14fe0..149c4776dc9c 100644 --- a/clippy_config/src/msrvs.rs +++ b/clippy_config/src/msrvs.rs @@ -143,13 +143,13 @@ impl Msrv { None } - pub fn enter_lint_attrs(&mut self, sess: &Session, attrs: &[Attribute]) { + pub fn check_attributes(&mut self, sess: &Session, attrs: &[Attribute]) { if let Some(version) = Self::parse_attr(sess, attrs) { self.stack.push(version); } } - pub fn exit_lint_attrs(&mut self, sess: &Session, attrs: &[Attribute]) { + pub fn check_attributes_post(&mut self, sess: &Session, attrs: &[Attribute]) { if Self::parse_attr(sess, attrs).is_some() { self.stack.pop(); } diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index 60f436dc5d2b..7dac3c5d9dab 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -158,10 +158,10 @@ impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity { } } - fn enter_lint_attrs(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) { + fn check_attributes(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) { self.limit.push_attrs(cx.sess(), attrs, "cognitive_complexity"); } - fn exit_lint_attrs(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) { + fn check_attributes_post(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) { self.limit.pop_attrs(cx.sess(), attrs, "cognitive_complexity"); } } diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 6878fb3349d4..2773427e72d5 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -162,12 +162,12 @@ impl MissingDoc { impl_lint_pass!(MissingDoc => [MISSING_DOCS_IN_PRIVATE_ITEMS]); impl<'tcx> LateLintPass<'tcx> for MissingDoc { - fn enter_lint_attrs(&mut self, _: &LateContext<'tcx>, attrs: &'tcx [ast::Attribute]) { + fn check_attributes(&mut self, _: &LateContext<'tcx>, attrs: &'tcx [ast::Attribute]) { let doc_hidden = self.doc_hidden() || is_doc_hidden(attrs); self.doc_hidden_stack.push(doc_hidden); } - fn exit_lint_attrs(&mut self, _: &LateContext<'tcx>, _: &'tcx [ast::Attribute]) { + fn check_attributes_post(&mut self, _: &LateContext<'tcx>, _: &'tcx [ast::Attribute]) { self.doc_hidden_stack.pop().expect("empty doc_hidden_stack"); } diff --git a/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs b/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs index 6d5240db8324..8d208fbb7e95 100644 --- a/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs +++ b/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs @@ -42,7 +42,7 @@ impl LateLintPass<'_> for MsrvAttrImpl { .filter(|t| matches!(t.unpack(), GenericArgKind::Type(_))) .any(|t| match_type(cx, t.expect_ty(), &paths::MSRV)) }) - && !items.iter().any(|item| item.ident.name == sym!(enter_lint_attrs)) + && !items.iter().any(|item| item.ident.name == sym!(check_attributes)) { let context = if is_late_pass { "LateContext" } else { "EarlyContext" }; let lint_pass = if is_late_pass { "LateLintPass" } else { "EarlyLintPass" }; diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 3b1b99caebe2..8251bdf78fc7 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -131,14 +131,14 @@ use rustc_middle::hir::nested_filter; #[macro_export] macro_rules! extract_msrv_attr { ($context:ident) => { - fn enter_lint_attrs(&mut self, cx: &rustc_lint::$context<'_>, attrs: &[rustc_ast::ast::Attribute]) { + fn check_attributes(&mut self, cx: &rustc_lint::$context<'_>, attrs: &[rustc_ast::ast::Attribute]) { let sess = rustc_lint::LintContext::sess(cx); - self.msrv.enter_lint_attrs(sess, attrs); + self.msrv.check_attributes(sess, attrs); } - fn exit_lint_attrs(&mut self, cx: &rustc_lint::$context<'_>, attrs: &[rustc_ast::ast::Attribute]) { + fn check_attributes_post(&mut self, cx: &rustc_lint::$context<'_>, attrs: &[rustc_ast::ast::Attribute]) { let sess = rustc_lint::LintContext::sess(cx); - self.msrv.exit_lint_attrs(sess, attrs); + self.msrv.check_attributes_post(sess, attrs); } }; } From 701817577cf3bcfff73f1e4623a6724051a75652 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 26 Mar 2024 05:48:13 -0400 Subject: [PATCH 1133/1222] Change `f16` and `f128` clippy stubs to be nonpanicking It turns out there is a bit of a circular dependency - I cannot add anything to `core` because Clippy fails, and I can't actually add correct Clippy implementations without new implementations from `core`. Change some of the Clippy stubs from `unimplemented!` to success values and leave a FIXME in their place to mitigate this. Fixes --- clippy_lints/src/float_literal.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index 07fbb1cb5c9f..981a76d683d2 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -83,7 +83,10 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral { LitFloatType::Unsuffixed => None, }; let (is_whole, is_inf, mut float_str) = match fty { - FloatTy::F16 => unimplemented!("f16_f128"), + FloatTy::F16 => { + // FIXME(f16_f128): do a check like the others when parsing is available + return; + }, FloatTy::F32 => { let value = sym_str.parse::().unwrap(); @@ -94,7 +97,10 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral { (value.fract() == 0.0, value.is_infinite(), formatter.format(value)) }, - FloatTy::F128 => unimplemented!("f16_f128"), + FloatTy::F128 => { + // FIXME(f16_f128): do a check like the others when parsing is available + return; + }, }; if is_inf { @@ -139,10 +145,11 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral { #[must_use] fn max_digits(fty: FloatTy) -> u32 { match fty { - FloatTy::F16 => unimplemented!("f16_f128"), + // FIXME(f16_f128): replace the magic numbers once `{f16,f128}::DIGITS` are available + FloatTy::F16 => 3, FloatTy::F32 => f32::DIGITS, FloatTy::F64 => f64::DIGITS, - FloatTy::F128 => unimplemented!("f16_f128"), + FloatTy::F128 => 33, } } From 065dfebef481b3545da400b0628f1fe9ed68b8c5 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 26 Mar 2024 14:11:51 -0400 Subject: [PATCH 1134/1222] Inherited -> TypeckRootCtxt --- clippy_lints/src/methods/unnecessary_to_owned.rs | 6 +++--- clippy_lints/src/transmute/utils.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index bc5dd10cad0a..e58d47764279 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -12,7 +12,7 @@ use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{BorrowKind, Expr, ExprKind, ItemKind, LangItem, Node}; -use rustc_hir_typeck::{FnCtxt, Inherited}; +use rustc_hir_typeck::{FnCtxt, TypeckRootCtxt}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::mir::Mutability; @@ -438,8 +438,8 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< Node::Item(item) => { if let ItemKind::Fn(_, _, body_id) = &item.kind && let output_ty = return_ty(cx, item.owner_id) - && let inherited = Inherited::new(cx.tcx, item.owner_id.def_id) - && let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, item.owner_id.def_id) + && let root_ctxt = TypeckRootCtxt::new(cx.tcx, item.owner_id.def_id) + && let fn_ctxt = FnCtxt::new(&root_ctxt, cx.param_env, item.owner_id.def_id) && fn_ctxt.can_coerce(ty, output_ty) { if has_lifetime(output_ty) && has_lifetime(ty) { diff --git a/clippy_lints/src/transmute/utils.rs b/clippy_lints/src/transmute/utils.rs index 7a7bb9f9c94c..15f1890aa39e 100644 --- a/clippy_lints/src/transmute/utils.rs +++ b/clippy_lints/src/transmute/utils.rs @@ -1,6 +1,6 @@ use rustc_hir as hir; use rustc_hir::Expr; -use rustc_hir_typeck::{cast, FnCtxt, Inherited}; +use rustc_hir_typeck::{cast, FnCtxt, TypeckRootCtxt}; use rustc_lint::LateContext; use rustc_middle::ty::cast::CastKind; use rustc_middle::ty::Ty; @@ -34,8 +34,8 @@ pub(super) fn check_cast<'tcx>( let hir_id = e.hir_id; let local_def_id = hir_id.owner.def_id; - let inherited = Inherited::new(cx.tcx, local_def_id); - let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, local_def_id); + let root_ctxt = TypeckRootCtxt::new(cx.tcx, local_def_id); + let fn_ctxt = FnCtxt::new(&root_ctxt, cx.param_env, local_def_id); if let Ok(check) = cast::CastCheck::new( &fn_ctxt, From 21f5368a33580802cd725ee09f42e8c132724058 Mon Sep 17 00:00:00 2001 From: Jules Bertholet Date: Sat, 23 Mar 2024 21:04:45 -0400 Subject: [PATCH 1135/1222] Implement `mut ref`/`mut ref mut` --- clippy_lints/src/functions/misnamed_getters.rs | 4 ++-- clippy_lints/src/index_refutable_slice.rs | 4 ++-- clippy_lints/src/iter_without_into_iter.rs | 4 ++-- clippy_lints/src/len_zero.rs | 8 ++++---- .../src/matches/infallible_destructuring_match.rs | 4 ++-- clippy_lints/src/matches/match_as_ref.rs | 2 +- clippy_lints/src/matches/needless_match.rs | 2 +- clippy_lints/src/matches/redundant_guards.rs | 2 +- clippy_lints/src/methods/clone_on_copy.rs | 2 +- clippy_lints/src/methods/iter_kv_map.rs | 5 ++--- clippy_lints/src/misc.rs | 4 ++-- clippy_lints/src/question_mark.rs | 10 +++++++--- clippy_lints/src/utils/author.rs | 2 ++ clippy_utils/src/lib.rs | 10 +++++----- 14 files changed, 34 insertions(+), 29 deletions(-) diff --git a/clippy_lints/src/functions/misnamed_getters.rs b/clippy_lints/src/functions/misnamed_getters.rs index bf96c0d62b05..8ac17e17688d 100644 --- a/clippy_lints/src/functions/misnamed_getters.rs +++ b/clippy_lints/src/functions/misnamed_getters.rs @@ -24,13 +24,13 @@ pub fn check_fn(cx: &LateContext<'_>, kind: FnKind<'_>, decl: &FnDecl<'_>, body: let name = ident.name.as_str(); let name = match decl.implicit_self { - ImplicitSelfKind::MutRef => { + ImplicitSelfKind::RefMut => { let Some(name) = name.strip_suffix("_mut") else { return; }; name }, - ImplicitSelfKind::Imm | ImplicitSelfKind::Mut | ImplicitSelfKind::ImmRef => name, + ImplicitSelfKind::Imm | ImplicitSelfKind::Mut | ImplicitSelfKind::RefImm => name, ImplicitSelfKind::None => return, }; diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index 5b5eb355f86c..4d1f89b1d9d9 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -97,7 +97,7 @@ fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap, pat: &hir::Pat<'_>) -> FxIndexMap, item: &rustc_hir::ImplItem<'_>) { let item_did = item.owner_id.to_def_id(); let (borrow_prefix, expected_implicit_self) = match item.ident.name { - sym::iter => ("&", ImplicitSelfKind::ImmRef), - sym::iter_mut => ("&mut ", ImplicitSelfKind::MutRef), + sym::iter => ("&", ImplicitSelfKind::RefImm), + sym::iter_mut => ("&mut ", ImplicitSelfKind::RefMut), _ => return, }; diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 27d85cde5320..cae9ada5a33c 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -384,8 +384,8 @@ impl LenOutput { fn expected_sig(self, self_kind: ImplicitSelfKind) -> String { let self_ref = match self_kind { - ImplicitSelfKind::ImmRef => "&", - ImplicitSelfKind::MutRef => "&mut ", + ImplicitSelfKind::RefImm => "&", + ImplicitSelfKind::RefMut => "&mut ", _ => "", }; match self { @@ -411,8 +411,8 @@ fn check_is_empty_sig<'tcx>( [arg, res] if len_output.matches_is_empty_output(cx, *res) => { matches!( (arg.kind(), self_kind), - (ty::Ref(_, _, Mutability::Not), ImplicitSelfKind::ImmRef) - | (ty::Ref(_, _, Mutability::Mut), ImplicitSelfKind::MutRef) + (ty::Ref(_, _, Mutability::Not), ImplicitSelfKind::RefImm) + | (ty::Ref(_, _, Mutability::Mut), ImplicitSelfKind::RefMut) ) || (!arg.is_ref() && matches!(self_kind, ImplicitSelfKind::Imm | ImplicitSelfKind::Mut)) }, _ => false, diff --git a/clippy_lints/src/matches/infallible_destructuring_match.rs b/clippy_lints/src/matches/infallible_destructuring_match.rs index 0f242e0b9e12..93d7683d2af8 100644 --- a/clippy_lints/src/matches/infallible_destructuring_match.rs +++ b/clippy_lints/src/matches/infallible_destructuring_match.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::{path_to_local_id, peel_blocks, strip_pat_refs}; use rustc_errors::Applicability; -use rustc_hir::{ByRef, ExprKind, LetStmt, MatchSource, PatKind, QPath}; +use rustc_hir::{ExprKind, LetStmt, MatchSource, PatKind, QPath}; use rustc_lint::LateContext; use super::INFALLIBLE_DESTRUCTURING_MATCH; @@ -30,7 +30,7 @@ pub(crate) fn check(cx: &LateContext<'_>, local: &LetStmt<'_>) -> bool { format!( "let {}({}{}) = {};", snippet_with_applicability(cx, variant_name.span, "..", &mut applicability), - if binding.0 == ByRef::Yes { "ref " } else { "" }, + binding.prefix_str(), snippet_with_applicability(cx, local.pat.span, "..", &mut applicability), snippet_with_applicability(cx, target.span, "..", &mut applicability), ), diff --git a/clippy_lints/src/matches/match_as_ref.rs b/clippy_lints/src/matches/match_as_ref.rs index 3f737da92c05..6b484ff2749b 100644 --- a/clippy_lints/src/matches/match_as_ref.rs +++ b/clippy_lints/src/matches/match_as_ref.rs @@ -67,7 +67,7 @@ fn is_none_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool { fn is_ref_some_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> Option { if let PatKind::TupleStruct(ref qpath, [first_pat, ..], _) = arm.pat.kind && is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), LangItem::OptionSome) - && let PatKind::Binding(BindingAnnotation(ByRef::Yes, mutabl), .., ident, _) = first_pat.kind + && let PatKind::Binding(BindingAnnotation(ByRef::Yes(mutabl), _), .., ident, _) = first_pat.kind && let ExprKind::Call(e, [arg]) = peel_blocks(arm.body).kind && is_res_lang_ctor(cx, path_res(cx, e), LangItem::OptionSome) && let ExprKind::Path(QPath::Resolved(_, path2)) = arg.kind diff --git a/clippy_lints/src/matches/needless_match.rs b/clippy_lints/src/matches/needless_match.rs index cee77f62b61e..fe83e784c3c9 100644 --- a/clippy_lints/src/matches/needless_match.rs +++ b/clippy_lints/src/matches/needless_match.rs @@ -178,7 +178,7 @@ fn pat_same_as_expr(pat: &Pat<'_>, expr: &Expr<'_>) -> bool { }, )), ) => { - return !matches!(annot, BindingAnnotation(ByRef::Yes, _)) && pat_ident.name == first_seg.ident.name; + return !matches!(annot, BindingAnnotation(ByRef::Yes(_), _)) && pat_ident.name == first_seg.ident.name; }, // Example: `Custom::TypeA => Custom::TypeB`, or `None => None` (PatKind::Path(QPath::Resolved(_, p_path)), ExprKind::Path(QPath::Resolved(_, e_path))) => { diff --git a/clippy_lints/src/matches/redundant_guards.rs b/clippy_lints/src/matches/redundant_guards.rs index 6bae51b45b8f..50cbccc39683 100644 --- a/clippy_lints/src/matches/redundant_guards.rs +++ b/clippy_lints/src/matches/redundant_guards.rs @@ -182,7 +182,7 @@ fn get_pat_binding<'tcx>( if let PatKind::Binding(bind_annot, hir_id, ident, _) = pat.kind && hir_id == local { - if matches!(bind_annot.0, rustc_ast::ByRef::Yes) { + if matches!(bind_annot.0, rustc_ast::ByRef::Yes(_)) { let _ = byref_ident.insert(ident); } // the second call of `replace()` returns a `Some(span)`, meaning a multi-binding pattern diff --git a/clippy_lints/src/methods/clone_on_copy.rs b/clippy_lints/src/methods/clone_on_copy.rs index d4a5de3d1dea..3e099004c479 100644 --- a/clippy_lints/src/methods/clone_on_copy.rs +++ b/clippy_lints/src/methods/clone_on_copy.rs @@ -69,7 +69,7 @@ pub(super) fn check( _ => false, }, // local binding capturing a reference - Node::LetStmt(l) if matches!(l.pat.kind, PatKind::Binding(BindingAnnotation(ByRef::Yes, _), ..)) => { + Node::LetStmt(l) if matches!(l.pat.kind, PatKind::Binding(BindingAnnotation(ByRef::Yes(_), _), ..)) => { return; }, _ => false, diff --git a/clippy_lints/src/methods/iter_kv_map.rs b/clippy_lints/src/methods/iter_kv_map.rs index 6394f35f8604..1431a5db2d96 100644 --- a/clippy_lints/src/methods/iter_kv_map.rs +++ b/clippy_lints/src/methods/iter_kv_map.rs @@ -60,8 +60,6 @@ pub(super) fn check<'tcx>( applicability, ); } else { - let ref_annotation = if annotation.0 == ByRef::Yes { "ref " } else { "" }; - let mut_annotation = if annotation.1 == Mutability::Mut { "mut " } else { "" }; span_lint_and_sugg( cx, ITER_KV_MAP, @@ -69,7 +67,8 @@ pub(super) fn check<'tcx>( &format!("iterating on a map's {replacement_kind}s"), "try", format!( - "{recv_snippet}.{into_prefix}{replacement_kind}s().map(|{ref_annotation}{mut_annotation}{bound_ident}| {})", + "{recv_snippet}.{into_prefix}{replacement_kind}s().map(|{}{bound_ident}| {})", + annotation.prefix_str(), snippet_with_applicability(cx, body_expr.span, "/* body */", &mut applicability) ), applicability, diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index ea6e662b4be3..11fecb7d72e2 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -129,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for LintPass { if !is_lint_allowed(cx, REF_PATTERNS, arg.pat.hir_id) { return; } - if let PatKind::Binding(BindingAnnotation(ByRef::Yes, _), ..) = arg.pat.kind { + if let PatKind::Binding(BindingAnnotation(ByRef::Yes(_), _), ..) = arg.pat.kind { span_lint( cx, TOPLEVEL_REF_ARG, @@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for LintPass { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { if !in_external_macro(cx.tcx.sess, stmt.span) && let StmtKind::Let(local) = stmt.kind - && let PatKind::Binding(BindingAnnotation(ByRef::Yes, mutabl), .., name, None) = local.pat.kind + && let PatKind::Binding(BindingAnnotation(ByRef::Yes(mutabl), _), .., name, None) = local.pat.kind && let Some(init) = local.init // Do not emit if clippy::ref_patterns is not allowed to avoid having two lints for the same issue. && is_lint_allowed(cx, REF_PATTERNS, local.pat.hir_id) diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index f1db571e1137..b57220e6cf0a 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -14,7 +14,7 @@ use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::LangItem::{self, OptionNone, OptionSome, ResultErr, ResultOk}; use rustc_hir::{ - BindingAnnotation, Block, ByRef, Expr, ExprKind, LetStmt, Node, PatKind, PathSegment, QPath, Stmt, StmtKind, + BindingAnnotation, Block, ByRef, Expr, ExprKind, LetStmt, Mutability, Node, PatKind, PathSegment, QPath, Stmt, StmtKind, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::Ty; @@ -283,9 +283,13 @@ fn check_if_let_some_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr: let mut applicability = Applicability::MachineApplicable; let receiver_str = snippet_with_applicability(cx, let_expr.span, "..", &mut applicability); let requires_semi = matches!(cx.tcx.parent_hir_node(expr.hir_id), Node::Stmt(_)); + let method_call_str = match by_ref { + ByRef::Yes(Mutability::Mut) => ".as_mut()", + ByRef::Yes(Mutability::Not) => ".as_ref()", + ByRef::No => "", + }; let sugg = format!( - "{receiver_str}{}?{}", - if by_ref == ByRef::Yes { ".as_ref()" } else { "" }, + "{receiver_str}{method_call_str}?{}", if requires_semi { ";" } else { "" } ); span_lint_and_sugg( diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 5319915b2eac..e45beb4910be 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -649,6 +649,8 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { BindingAnnotation::REF => "REF", BindingAnnotation::MUT => "MUT", BindingAnnotation::REF_MUT => "REF_MUT", + BindingAnnotation::MUT_REF => "MUT_REF", + BindingAnnotation::MUT_REF_MUT => "MUT_REF_MUT", }; kind!("Binding(BindingAnnotation::{ann}, _, {name}, {sub})"); self.ident(name); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 8251bdf78fc7..95bab5801d1c 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -97,7 +97,7 @@ use rustc_hir::hir_id::{HirIdMap, HirIdSet}; use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk}; use rustc_hir::{ - self as hir, def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Closure, Destination, Expr, + self as hir, def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, ByRef, Closure, Destination, Expr, ExprField, ExprKind, FnDecl, FnRetTy, GenericArgs, HirId, Impl, ImplItem, ImplItemKind, ImplItemRef, Item, ItemKind, LangItem, LetStmt, MatchSource, Mutability, Node, OwnerId, Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitItemRef, TraitRef, TyKind, UnOp, @@ -107,7 +107,6 @@ use rustc_lint::{LateContext, Level, Lint, LintContext}; use rustc_middle::hir::place::PlaceBase; use rustc_middle::mir::Const; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; -use rustc_middle::ty::binding::BindingMode; use rustc_middle::ty::fast_reject::SimplifiedType; use rustc_middle::ty::layout::IntegerExt; use rustc_middle::ty::{ @@ -1006,11 +1005,12 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind { .typeck_results() .extract_binding_mode(cx.sess(), id, span) .unwrap() + .0 { - BindingMode::BindByValue(_) if !is_copy(cx, cx.typeck_results().node_type(id)) => { + ByRef::No if !is_copy(cx, cx.typeck_results().node_type(id)) => { capture = CaptureKind::Value; }, - BindingMode::BindByReference(Mutability::Mut) if capture != CaptureKind::Value => { + ByRef::Yes(Mutability::Mut) if capture != CaptureKind::Value => { capture = CaptureKind::Ref(Mutability::Mut); }, _ => (), @@ -2035,7 +2035,7 @@ fn is_body_identity_function(cx: &LateContext<'_>, func: &Body<'_>) -> bool { .typeck_results() .pat_binding_modes() .get(pat.hir_id) - .is_some_and(|mode| matches!(mode, BindingMode::BindByReference(_))) + .is_some_and(|mode| matches!(mode.0, ByRef::Yes(_))) { // If a tuple `(x, y)` is of type `&(i32, i32)`, then due to match ergonomics, // the inner patterns become references. Don't consider this the identity function From 31e9cae754a89bf1826a71202808717c7eba378d Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 29 Mar 2024 13:34:01 -0700 Subject: [PATCH 1136/1222] clippy: fix up `include_str!` spans in diagnostics --- clippy_lints/src/large_include_file.rs | 2 +- clippy_lints/src/strings.rs | 2 +- .../large_include_file/large_include_file.stderr | 2 -- tests/ui/empty_docs.stderr | 11 ++++++----- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/large_include_file.rs b/clippy_lints/src/large_include_file.rs index 1b5981ecc281..553d447d440a 100644 --- a/clippy_lints/src/large_include_file.rs +++ b/clippy_lints/src/large_include_file.rs @@ -71,7 +71,7 @@ impl LateLintPass<'_> for LargeIncludeFile { span_lint_and_note( cx, LARGE_INCLUDE_FILE, - expr.span, + expr.span.source_callsite(), "attempted to include a large file", None, &format!( diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 13ae1ff52ddf..217901348545 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -300,7 +300,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { e.span, "calling `as_bytes()` on `include_str!(..)`", "consider using `include_bytes!(..)` instead", - snippet_with_applicability(cx, receiver.span, r#""foo""#, &mut applicability).replacen( + snippet_with_applicability(cx, receiver.span.source_callsite(), r#""foo""#, &mut applicability).replacen( "include_str", "include_bytes", 1, diff --git a/tests/ui-toml/large_include_file/large_include_file.stderr b/tests/ui-toml/large_include_file/large_include_file.stderr index b45cb11939f0..34224065f078 100644 --- a/tests/ui-toml/large_include_file/large_include_file.stderr +++ b/tests/ui-toml/large_include_file/large_include_file.stderr @@ -7,7 +7,6 @@ LL | const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt"); = note: the configuration allows a maximum size of 600 bytes = note: `-D clippy::large-include-file` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::large_include_file)]` - = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info) error: attempted to include a large file --> tests/ui-toml/large_include_file/large_include_file.rs:14:35 @@ -16,7 +15,6 @@ LL | const TOO_BIG_INCLUDE_STR: &str = include_str!("too_big.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the configuration allows a maximum size of 600 bytes - = note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/tests/ui/empty_docs.stderr b/tests/ui/empty_docs.stderr index 28ebea22c5db..5fd7272d7c16 100644 --- a/tests/ui/empty_docs.stderr +++ b/tests/ui/empty_docs.stderr @@ -25,19 +25,20 @@ LL | /// = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:30:5 + --> tests/ui/empty_docs.rs:30:13 | LL | #[doc = ""] - | ^^^^^^^^^^^ + | ^^ | = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:33:5 + --> tests/ui/empty_docs.rs:33:13 | -LL | / #[doc = ""] +LL | #[doc = ""] + | _____________^ LL | | #[doc = ""] - | |_______________^ + | |______________^ | = help: consider removing or filling it From 451148f2b4258a60b0815f55aa42512105479193 Mon Sep 17 00:00:00 2001 From: joboet Date: Wed, 3 Apr 2024 15:17:00 +0200 Subject: [PATCH 1137/1222] rename `expose_addr` to `expose_provenance` --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 12b080059970..325c9bee0578 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -149,7 +149,7 @@ fn check_rvalue<'tcx>( Err((span, "unsizing casts are not allowed in const fn".into())) } }, - Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => { + Rvalue::Cast(CastKind::PointerExposeProvenance, _, _) => { Err((span, "casting pointers to ints is unstable in const fn".into())) }, Rvalue::Cast(CastKind::DynStar, _, _) => { From b7ba5d1fc2f17f335d6ab506a5331d04c5823ab7 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 3 Apr 2024 19:03:12 -0400 Subject: [PATCH 1138/1222] update messages --- clippy_lints/src/misc.rs | 2 +- tests/ui-internal/custom_ice_message.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index ea6e662b4be3..be1a35f8fb21 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -66,7 +66,7 @@ declare_clippy_lint! { /// /// ### Known problems /// The lint does not work properly with desugaring and - /// macro, it has been allowed in the mean time. + /// macro, it has been allowed in the meantime. /// /// ### Example /// ```no_run diff --git a/tests/ui-internal/custom_ice_message.stderr b/tests/ui-internal/custom_ice_message.stderr index b84f4e87e073..763ce59ba1d9 100644 --- a/tests/ui-internal/custom_ice_message.stderr +++ b/tests/ui-internal/custom_ice_message.stderr @@ -4,7 +4,7 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace error: the compiler unexpectedly panicked. this is a bug. -note: it seems that this compiler is outdated, a newer nightly should have been released in the mean time +note: it seems that this compiler is outdated, a newer nightly should have been released in the meantime | = note: please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists = note: if the problem still persists, we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml From 5e15a68b5c85d5888e087c006ce1fb87401f8f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Thu, 4 Apr 2024 19:03:32 +0200 Subject: [PATCH 1139/1222] Rename ModSep to PathSep --- clippy_lints/src/crate_in_macro_def.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/crate_in_macro_def.rs b/clippy_lints/src/crate_in_macro_def.rs index b1aa472aa03f..adf6f7c47375 100644 --- a/clippy_lints/src/crate_in_macro_def.rs +++ b/clippy_lints/src/crate_in_macro_def.rs @@ -88,7 +88,7 @@ fn contains_unhygienic_crate_reference(tts: &TokenStream) -> Option { if !prev_is_dollar && let Some(span) = is_crate_keyword(curr) && let Some(next) = cursor.look_ahead(0) - && is_token(next, &TokenKind::ModSep) + && is_token(next, &TokenKind::PathSep) { return Some(span); } From 3f90cc2efe3e3ca36011059871c44550b25caf08 Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Fri, 5 Apr 2024 00:17:27 +0200 Subject: [PATCH 1140/1222] use `Lrc` instead of the aliased type `Arc` directly --- clippy_lints/src/attrs/mixed_attributes_style.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/attrs/mixed_attributes_style.rs b/clippy_lints/src/attrs/mixed_attributes_style.rs index 75a3d7a9ac3c..5d2ea36b366c 100644 --- a/clippy_lints/src/attrs/mixed_attributes_style.rs +++ b/clippy_lints/src/attrs/mixed_attributes_style.rs @@ -2,10 +2,10 @@ use super::MIXED_ATTRIBUTES_STYLE; use clippy_utils::diagnostics::span_lint; use rustc_ast::{AttrKind, AttrStyle, Attribute}; use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::sync::Lrc; use rustc_lint::{LateContext, LintContext}; use rustc_span::source_map::SourceMap; use rustc_span::{SourceFile, Span, Symbol}; -use std::sync::Arc; #[derive(Hash, PartialEq, Eq)] enum SimpleAttrKind { @@ -79,7 +79,7 @@ fn lint_mixed_attrs(cx: &LateContext<'_>, attrs: &[Attribute]) { ); } -fn attr_in_same_src_as_item(source_map: &SourceMap, item_src: &Arc, attr_span: Span) -> bool { +fn attr_in_same_src_as_item(source_map: &SourceMap, item_src: &Lrc, attr_span: Span) -> bool { let attr_src = source_map.lookup_source_file(attr_span.lo()); - Arc::ptr_eq(item_src, &attr_src) + Lrc::ptr_eq(item_src, &attr_src) } From a85e6c1cc6731ee5ea0715b991b926fd32735f88 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 8 Apr 2024 10:36:15 +0000 Subject: [PATCH 1141/1222] Stop exporting `TypeckRootCtxt` and `FnCtxt`. While they have many convenient APIs, it is better to expose dedicated functions for them --- .../src/methods/unnecessary_to_owned.rs | 5 +-- .../transmutes_expressible_as_ptr_casts.rs | 4 +- clippy_lints/src/transmute/utils.rs | 37 ------------------- 3 files changed, 3 insertions(+), 43 deletions(-) diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 23fc323446e0..d3347466be98 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -12,7 +12,6 @@ use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{BorrowKind, Expr, ExprKind, ItemKind, LangItem, Node}; -use rustc_hir_typeck::{FnCtxt, TypeckRootCtxt}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::mir::Mutability; @@ -437,9 +436,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< Node::Item(item) => { if let ItemKind::Fn(_, _, body_id) = &item.kind && let output_ty = return_ty(cx, item.owner_id) - && let root_ctxt = TypeckRootCtxt::new(cx.tcx, item.owner_id.def_id) - && let fn_ctxt = FnCtxt::new(&root_ctxt, cx.param_env, item.owner_id.def_id) - && fn_ctxt.can_coerce(ty, output_ty) + && rustc_hir_typeck::can_coerce(cx.tcx, cx.param_env, item.owner_id.def_id, ty, output_ty) { if has_lifetime(output_ty) && has_lifetime(ty) { return false; diff --git a/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs b/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs index 6f5ac625e357..a6a6e9a3bac3 100644 --- a/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs +++ b/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs @@ -1,4 +1,4 @@ -use super::utils::check_cast; +use rustc_hir_typeck::cast::check_cast; use super::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::sugg::Sugg; @@ -22,7 +22,7 @@ pub(super) fn check<'tcx>( ) -> bool { use CastKind::{AddrPtrCast, ArrayPtrCast, FnPtrAddrCast, FnPtrPtrCast, PtrAddrCast, PtrPtrCast}; let mut app = Applicability::MachineApplicable; - let mut sugg = match check_cast(cx, e, from_ty, to_ty) { + let mut sugg = match check_cast(cx.tcx, cx.param_env, e, from_ty, to_ty) { Some(FnPtrAddrCast | PtrAddrCast) if const_context => return false, Some(PtrPtrCast | AddrPtrCast | ArrayPtrCast | FnPtrPtrCast | FnPtrAddrCast) => { Sugg::hir_with_context(cx, arg, e.span.ctxt(), "..", &mut app) diff --git a/clippy_lints/src/transmute/utils.rs b/clippy_lints/src/transmute/utils.rs index 15f1890aa39e..e8ccd35b4daf 100644 --- a/clippy_lints/src/transmute/utils.rs +++ b/clippy_lints/src/transmute/utils.rs @@ -1,10 +1,5 @@ -use rustc_hir as hir; -use rustc_hir::Expr; -use rustc_hir_typeck::{cast, FnCtxt, TypeckRootCtxt}; use rustc_lint::LateContext; -use rustc_middle::ty::cast::CastKind; use rustc_middle::ty::Ty; -use rustc_span::DUMMY_SP; // check if the component types of the transmuted collection and the result have different ABI, // size or alignment @@ -20,35 +15,3 @@ pub(super) fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx false } } - -/// If a cast from `from_ty` to `to_ty` is valid, returns an Ok containing the kind of -/// the cast. In certain cases, including some invalid casts from array references -/// to pointers, this may cause additional errors to be emitted and/or ICE error -/// messages. This function will panic if that occurs. -pub(super) fn check_cast<'tcx>( - cx: &LateContext<'tcx>, - e: &'tcx Expr<'_>, - from_ty: Ty<'tcx>, - to_ty: Ty<'tcx>, -) -> Option { - let hir_id = e.hir_id; - let local_def_id = hir_id.owner.def_id; - - let root_ctxt = TypeckRootCtxt::new(cx.tcx, local_def_id); - let fn_ctxt = FnCtxt::new(&root_ctxt, cx.param_env, local_def_id); - - if let Ok(check) = cast::CastCheck::new( - &fn_ctxt, - e, - from_ty, - to_ty, - // We won't show any error to the user, so we don't care what the span is here. - DUMMY_SP, - DUMMY_SP, - hir::Constness::NotConst, - ) { - check.do_check(&fn_ctxt).ok() - } else { - None - } -} From 7d2f98c580bee135e46ae698bfc5f7d3942ce4b0 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 31 Jan 2023 11:54:06 +0000 Subject: [PATCH 1142/1222] Thread pattern types through the HIR --- clippy_lints/src/dereference.rs | 1 + clippy_utils/src/hir_utils.rs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 560b2acc1c70..eb317c70926a 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -821,6 +821,7 @@ impl TyCoercionStability { | TyKind::Array(..) | TyKind::Ptr(_) | TyKind::BareFn(_) + | TyKind::Pat(..) | TyKind::Never | TyKind::Tup(_) | TyKind::Path(_) => Self::Deref, diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index f8bbe9977748..6c3d93299322 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -1068,6 +1068,10 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_ty(ty); self.hash_array_length(len); }, + TyKind::Pat(ty, pat) => { + self.hash_ty(ty); + self.hash_pat(pat); + }, TyKind::Ptr(ref mut_ty) => { self.hash_ty(mut_ty.ty); mut_ty.mutbl.hash(&mut self.s); From 716c6eb4e696fc65d338b59a3f9c072be7e4f0ca Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 2 Feb 2023 13:57:36 +0000 Subject: [PATCH 1143/1222] Actually create ranged int types in the type system. --- clippy_lints/src/dereference.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index eb317c70926a..f83fb1b90198 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -870,6 +870,7 @@ impl TyCoercionStability { | ty::Int(_) | ty::Uint(_) | ty::Array(..) + | ty::Pat(..) | ty::Float(_) | ty::RawPtr(..) | ty::FnPtr(_) From 493abb52cd55b20f4f28af839351ec26b401bd4e Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 7 Apr 2024 19:38:05 -0400 Subject: [PATCH 1144/1222] Add a helper for extending a span to include any trailing whitespace --- clippy_lints/src/lifetimes.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index a60a40a2a471..2bb63ec2b046 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -294,8 +294,7 @@ fn elision_suggestions( let span = cx .sess() .source_map() - .span_extend_while(usage.ident.span, |ch| ch.is_ascii_whitespace()) - .unwrap_or(usage.ident.span); + .span_extend_while_whitespace(usage.ident.span); (span, String::new()) }, From 83c2d1f5dcca481bc55b1d6fb27f1eecf364e7ca Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Tue, 2 Apr 2024 00:26:10 +0200 Subject: [PATCH 1145/1222] store the span of the nested part of the use tree in the ast --- clippy_lints/src/single_component_path_imports.rs | 8 ++++---- clippy_lints/src/unnecessary_self_imports.rs | 4 ++-- clippy_lints/src/unsafe_removed_from_name.rs | 4 ++-- clippy_utils/src/ast_utils.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/single_component_path_imports.rs b/clippy_lints/src/single_component_path_imports.rs index 18fbbdb40791..acf44a9bb5ab 100644 --- a/clippy_lints/src/single_component_path_imports.rs +++ b/clippy_lints/src/single_component_path_imports.rs @@ -201,8 +201,8 @@ impl SingleComponentPathImports { if segments.is_empty() { // keep track of `use {some_module, some_other_module};` usages - if let UseTreeKind::Nested(trees) = &use_tree.kind { - for tree in trees { + if let UseTreeKind::Nested { items, .. } = &use_tree.kind { + for tree in items { let segments = &tree.0.prefix.segments; if segments.len() == 1 { if let UseTreeKind::Simple(None) = tree.0.kind { @@ -229,8 +229,8 @@ impl SingleComponentPathImports { } // nested case such as `use self::{module1::Struct1, module2::Struct2}` - if let UseTreeKind::Nested(trees) = &use_tree.kind { - for tree in trees { + if let UseTreeKind::Nested { items, .. } = &use_tree.kind { + for tree in items { let segments = &tree.0.prefix.segments; if !segments.is_empty() { imports_reused_with_self.push(segments[0].ident.name); diff --git a/clippy_lints/src/unnecessary_self_imports.rs b/clippy_lints/src/unnecessary_self_imports.rs index ddee06b59cae..528a1dfcfc10 100644 --- a/clippy_lints/src/unnecessary_self_imports.rs +++ b/clippy_lints/src/unnecessary_self_imports.rs @@ -36,8 +36,8 @@ declare_lint_pass!(UnnecessarySelfImports => [UNNECESSARY_SELF_IMPORTS]); impl EarlyLintPass for UnnecessarySelfImports { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { if let ItemKind::Use(use_tree) = &item.kind - && let UseTreeKind::Nested(nodes) = &use_tree.kind - && let [(self_tree, _)] = &**nodes + && let UseTreeKind::Nested { items, .. } = &use_tree.kind + && let [(self_tree, _)] = &**items && let [self_seg] = &*self_tree.prefix.segments && self_seg.ident.name == kw::SelfLower && let Some(last_segment) = use_tree.prefix.segments.last() diff --git a/clippy_lints/src/unsafe_removed_from_name.rs b/clippy_lints/src/unsafe_removed_from_name.rs index 51b3ea93b6dc..309eaedac8d2 100644 --- a/clippy_lints/src/unsafe_removed_from_name.rs +++ b/clippy_lints/src/unsafe_removed_from_name.rs @@ -49,8 +49,8 @@ fn check_use_tree(use_tree: &UseTree, cx: &EarlyContext<'_>, span: Span) { unsafe_to_safe_check(old_name, new_name, cx, span); }, UseTreeKind::Simple(None) | UseTreeKind::Glob => {}, - UseTreeKind::Nested(ref nested_use_tree) => { - for (use_tree, _) in nested_use_tree { + UseTreeKind::Nested { ref items, .. } => { + for (use_tree, _) in items { check_use_tree(use_tree, cx, span); } }, diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index f594a40ff59a..36d54bb41fa4 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -637,7 +637,7 @@ pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool { match (l, r) { (Glob, Glob) => true, (Simple(l), Simple(r)) => both(l, r, |l, r| eq_id(*l, *r)), - (Nested(l), Nested(r)) => over(l, r, |(l, _), (r, _)| eq_use_tree(l, r)), + (Nested { items: l, .. }, Nested { items: r, .. }) => over(l, r, |(l, _), (r, _)| eq_use_tree(l, r)), _ => false, } } From 769fcd4f0e0e5d4a259cf823fd81694730e5add1 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 4 Apr 2024 20:52:56 -0400 Subject: [PATCH 1146/1222] Rustfmt, clippy --- clippy_utils/src/ast_utils.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index f594a40ff59a..9f0bd4ea7e2e 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -709,7 +709,8 @@ pub fn eq_ty(l: &Ty, r: &Ty) -> bool { (Tup(l), Tup(r)) => over(l, r, |l, r| eq_ty(l, r)), (Path(lq, lp), Path(rq, rp)) => both(lq, rq, eq_qself) && eq_path(lp, rp), (TraitObject(lg, ls), TraitObject(rg, rs)) => ls == rs && over(lg, rg, eq_generic_bound), - (ImplTrait(_, lg), ImplTrait(_, rg)) => over(lg, rg, eq_generic_bound), + (ImplTrait(_, lg, lc), ImplTrait(_, rg, rc)) => + over(lg, rg, eq_generic_bound) && both(lc, rc, |lc, rc| over(lc.0.as_slice(), rc.0.as_slice(), eq_precise_capture)), (Typeof(l), Typeof(r)) => eq_expr(&l.value, &r.value), (MacCall(l), MacCall(r)) => eq_mac_call(l, r), _ => false, @@ -770,6 +771,14 @@ pub fn eq_generic_bound(l: &GenericBound, r: &GenericBound) -> bool { } } +pub fn eq_precise_capture(l: &PreciseCapturingArg, r: &PreciseCapturingArg) -> bool { + match (l, r) { + (PreciseCapturingArg::Lifetime(l), PreciseCapturingArg::Lifetime(r)) => l.ident == r.ident, + (PreciseCapturingArg::Arg(l, _), PreciseCapturingArg::Arg(r, _)) => l.segments[0].ident == r.segments[0].ident, + _ => false, + } +} + fn eq_term(l: &Term, r: &Term) -> bool { match (l, r) { (Term::Ty(l), Term::Ty(r)) => eq_ty(l, r), From 0513b0677907d475bc490d04bff212f10786bed3 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 24 Mar 2024 12:47:01 -0400 Subject: [PATCH 1147/1222] Remove TypeVariableOriginKind --- clippy_utils/src/ty.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index ab1be66dc787..1afc5ed0157a 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -10,7 +10,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, FnDecl, LangItem, TyKind, Unsafety}; -use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; +use rustc_infer::infer::type_variable::{TypeVariableOrigin}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::mir::interpret::Scalar; @@ -276,8 +276,8 @@ pub fn implements_trait_with_env_from_iter<'tcx>( .map(|arg| { arg.into().unwrap_or_else(|| { let orig = TypeVariableOrigin { - kind: TypeVariableOriginKind::MiscVariable, span: DUMMY_SP, + param_def_id: None, }; infcx.next_ty_var(orig).into() }) From af698d487c14a6402ecfc354787ceb77f4505ad2 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 14 Apr 2024 11:04:18 -0400 Subject: [PATCH 1148/1222] Fix clippy --- clippy_lints/src/casts/ptr_as_ptr.rs | 2 +- clippy_lints/src/matches/match_wild_err_arm.rs | 2 +- clippy_lints/src/mut_reference.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/casts/ptr_as_ptr.rs b/clippy_lints/src/casts/ptr_as_ptr.rs index 68841076f770..2c168405ee26 100644 --- a/clippy_lints/src/casts/ptr_as_ptr.rs +++ b/clippy_lints/src/casts/ptr_as_ptr.rs @@ -77,7 +77,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Msrv) { let (help, final_suggestion) = if let Some(method) = omit_cast.corresponding_item() { // don't force absolute path - let method = qpath_to_string(method); + let method = qpath_to_string(&cx.tcx, method); ("try call directly", format!("{method}{turbofish}()")) } else { let cast_expr_sugg = Sugg::hir_with_applicability(cx, cast_expr, "_", &mut app); diff --git a/clippy_lints/src/matches/match_wild_err_arm.rs b/clippy_lints/src/matches/match_wild_err_arm.rs index d1f637ec78c6..310675d01a20 100644 --- a/clippy_lints/src/matches/match_wild_err_arm.rs +++ b/clippy_lints/src/matches/match_wild_err_arm.rs @@ -19,7 +19,7 @@ pub(crate) fn check<'tcx>(cx: &LateContext<'tcx>, ex: &Expr<'tcx>, arms: &[Arm<' if is_type_diagnostic_item(cx, ex_ty, sym::Result) { for arm in arms { if let PatKind::TupleStruct(ref path, inner, _) = arm.pat.kind { - let path_str = rustc_hir_pretty::qpath_to_string(path); + let path_str = rustc_hir_pretty::qpath_to_string(&cx.tcx, path); if path_str == "Err" { let mut matching_wild = inner.iter().any(is_wild); let mut ident_bind_name = kw::Underscore; diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 6867f76a7235..0a3b769c3e60 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed { cx, arguments.iter().collect(), cx.typeck_results().expr_ty(fn_expr), - &rustc_hir_pretty::qpath_to_string(path), + &rustc_hir_pretty::qpath_to_string(&cx.tcx, path), "function", ); } From c4bfb37fc8b538f8b3249b7346cf7214b2fa2bb2 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 21 Mar 2024 14:17:00 +1100 Subject: [PATCH 1149/1222] Construct `SourceMap` at the same time as `SessionGlobals`. Currently `SourceMap` is constructed slightly later than `SessionGlobals`, and inserted. This commit changes things so they are done at the same time. Benefits: - `SessionGlobals::source_map` changes from `Lock>>` to `Option>`. It's still optional, but mutability isn't required because it's initialized at construction. - `set_source_map` is removed, simplifying `run_compiler`, which is good because that's a critical function and it's nice to make it simpler. This requires moving things around a bit, so the necessary inputs are available when `SessionGlobals` is created, in particular the `loader` and `hash_kind`, which are no longer computed by `build_session`. These inputs are captured by the new `SourceMapInputs` type, which is threaded through various places. --- clippy_lints/src/doc/needless_doctest_main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/doc/needless_doctest_main.rs b/clippy_lints/src/doc/needless_doctest_main.rs index e55a988321b3..651f2ebaee6f 100644 --- a/clippy_lints/src/doc/needless_doctest_main.rs +++ b/clippy_lints/src/doc/needless_doctest_main.rs @@ -38,7 +38,7 @@ pub fn check( // of all `#[test]` attributes in not ignored code examples fn check_code_sample(code: String, edition: Edition, ignore: bool) -> (bool, Vec>) { rustc_driver::catch_fatal_errors(|| { - rustc_span::create_session_globals_then(edition, || { + rustc_span::create_session_globals_then(edition, None, || { let mut test_attr_spans = vec![]; let filename = FileName::anon_source_code(&code); From f4453925660ec6da86648780cfe34603ae2e4ebe Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 6 Mar 2024 16:39:02 +1100 Subject: [PATCH 1150/1222] Avoid unnecessary `rustc_span::DUMMY_SP` usage. In some cases `DUMMY_SP` is already imported. In other cases this commit adds the necessary import, in files where `DUMMY_SP` is used more than once. --- clippy_lints/src/non_copy_const.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 73fc34c2450f..5ca388d67a17 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -18,7 +18,7 @@ use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult, GlobalId}; use rustc_middle::ty::adjustment::Adjust; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_session::impl_lint_pass; -use rustc_span::{sym, InnerSpan, Span}; +use rustc_span::{sym, DUMMY_SP, InnerSpan, Span}; use rustc_target::abi::VariantIdx; // FIXME: this is a correctness problem but there's no suitable @@ -290,9 +290,7 @@ impl NonCopyConst { promoted: None, }; let param_env = cx.tcx.param_env(def_id).with_reveal_all_normalized(cx.tcx); - let result = cx - .tcx - .const_eval_global_id_for_typeck(param_env, cid, rustc_span::DUMMY_SP); + let result = cx.tcx.const_eval_global_id_for_typeck(param_env, cid, DUMMY_SP); self.is_value_unfrozen_raw(cx, result, ty) } @@ -303,7 +301,7 @@ impl NonCopyConst { cx.tcx, cx.param_env, ty::UnevaluatedConst::new(def_id, args), - rustc_span::DUMMY_SP, + DUMMY_SP, ); self.is_value_unfrozen_raw(cx, result, ty) } From 39895dfc3dbc4a9f320d8d148cc2d990ddf236d6 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 6 Mar 2024 16:54:36 +1100 Subject: [PATCH 1151/1222] Always use `ty::` qualifier for `TyKind` enum variants. Because that's the way it should be done. --- clippy_lints/src/derivable_impls.rs | 6 +++--- clippy_lints/src/from_raw_with_void_ptr.rs | 4 ++-- clippy_lints/src/functions/result.rs | 6 +++--- clippy_lints/src/implicit_saturating_add.rs | 3 ++- clippy_lints/src/large_enum_variant.rs | 6 +++--- clippy_lints/src/methods/unnecessary_join.rs | 6 +++--- clippy_lints/src/mut_key.rs | 4 ++-- clippy_lints/src/zero_sized_map_values.rs | 4 ++-- 8 files changed, 20 insertions(+), 19 deletions(-) diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index 80327586fedc..0c9ad5e8d001 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -9,7 +9,7 @@ use rustc_hir::{ }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, PointerCoercion}; -use rustc_middle::ty::{self, Adt, AdtDef, GenericArgsRef, Ty, TypeckResults}; +use rustc_middle::ty::{self, AdtDef, GenericArgsRef, Ty, TypeckResults}; use rustc_session::impl_lint_pass; use rustc_span::sym; @@ -79,7 +79,7 @@ fn is_path_self(e: &Expr<'_>) -> bool { fn contains_trait_object(ty: Ty<'_>) -> bool { match ty.kind() { ty::Ref(_, ty, _) => contains_trait_object(*ty), - Adt(def, args) => def.is_box() && args[0].as_type().map_or(false, contains_trait_object), + ty::Adt(def, args) => def.is_box() && args[0].as_type().map_or(false, contains_trait_object), ty::Dynamic(..) => true, _ => false, } @@ -198,7 +198,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { && let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir) && let ImplItemKind::Fn(_, b) = &impl_item.kind && let Body { value: func_expr, .. } = cx.tcx.hir().body(*b) - && let &Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind() + && let &ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind() && let attrs = cx.tcx.hir().attrs(item.hir_id()) && !attrs.iter().any(|attr| attr.doc_str().is_some()) && cx.tcx.hir().attrs(impl_item_hir).is_empty() diff --git a/clippy_lints/src/from_raw_with_void_ptr.rs b/clippy_lints/src/from_raw_with_void_ptr.rs index ba2495c17a21..d62d008d480f 100644 --- a/clippy_lints/src/from_raw_with_void_ptr.rs +++ b/clippy_lints/src/from_raw_with_void_ptr.rs @@ -4,7 +4,7 @@ use clippy_utils::ty::is_c_void; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::RawPtr; +use rustc_middle::ty; use rustc_session::declare_lint_pass; use rustc_span::sym; @@ -44,7 +44,7 @@ impl LateLintPass<'_> for FromRawWithVoidPtr { && seg.ident.name == sym!(from_raw) && let Some(type_str) = path_def_id(cx, ty).and_then(|id| def_id_matches_type(cx, id)) && let arg_kind = cx.typeck_results().expr_ty(arg).kind() - && let RawPtr(ty, _) = arg_kind + && let ty::RawPtr(ty, _) = arg_kind && is_c_void(cx, *ty) { let msg = format!("creating a `{type_str}` from a void raw pointer"); diff --git a/clippy_lints/src/functions/result.rs b/clippy_lints/src/functions/result.rs index 93f088d3e339..c3a0b40a677a 100644 --- a/clippy_lints/src/functions/result.rs +++ b/clippy_lints/src/functions/result.rs @@ -2,7 +2,7 @@ use rustc_errors::Diag; use rustc_hir as hir; use rustc_lint::{LateContext, LintContext}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{Adt, Ty}; +use rustc_middle::ty::{self, Ty}; use rustc_span::{sym, Span}; use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then}; @@ -25,7 +25,7 @@ fn result_err_ty<'tcx>( .tcx .instantiate_bound_regions_with_erased(cx.tcx.fn_sig(id).instantiate_identity().output()) && is_type_diagnostic_item(cx, ty, sym::Result) - && let Adt(_, args) = ty.kind() + && let ty::Adt(_, args) = ty.kind() { let err_ty = args.type_at(1); Some((hir_ty, err_ty)) @@ -86,7 +86,7 @@ fn check_result_unit_err(cx: &LateContext<'_>, err_ty: Ty<'_>, fn_header_span: S } fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty_span: Span, large_err_threshold: u64) { - if let Adt(adt, subst) = err_ty.kind() + if let ty::Adt(adt, subst) = err_ty.kind() && let Some(local_def_id) = err_ty .ty_adt_def() .expect("already checked this is adt") diff --git a/clippy_lints/src/implicit_saturating_add.rs b/clippy_lints/src/implicit_saturating_add.rs index b8d7e8f3b07c..f225c6e7f049 100644 --- a/clippy_lints/src/implicit_saturating_add.rs +++ b/clippy_lints/src/implicit_saturating_add.rs @@ -7,7 +7,7 @@ use rustc_data_structures::packed::Pu128; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{Int, IntTy, Ty, Uint, UintTy}; +use rustc_middle::ty::{IntTy, Ty, UintTy}; use rustc_session::declare_lint_pass; declare_clippy_lint! { @@ -97,6 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingAdd { } fn get_int_max(ty: Ty<'_>) -> Option { + use rustc_middle::ty::{Int, Uint}; match ty.peel_refs().kind() { Int(IntTy::I8) => i8::MAX.try_into().ok(), Int(IntTy::I16) => i16::MAX.try_into().ok(), diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index 6feb18855764..0bf7389ef9cc 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -7,7 +7,7 @@ use rustc_errors::Applicability; use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{Adt, Ty}; +use rustc_middle::ty::{self, Ty}; use rustc_session::impl_lint_pass; use rustc_span::Span; @@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant { } if let ItemKind::Enum(ref def, _) = item.kind { let ty = cx.tcx.type_of(item.owner_id).instantiate_identity(); - let Adt(adt, subst) = ty.kind() else { + let ty::Adt(adt, subst) = ty.kind() else { panic!("already checked whether this is an enum") }; if adt.variants().len() <= 1 { @@ -167,7 +167,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant { } fn maybe_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { - if let Adt(_def, args) = ty.kind() + if let ty::Adt(_def, args) = ty.kind() && args.types().next().is_some() && let Some(copy_trait) = cx.tcx.lang_items().copy_trait() { diff --git a/clippy_lints/src/methods/unnecessary_join.rs b/clippy_lints/src/methods/unnecessary_join.rs index c3ad4db38759..efd1a718504c 100644 --- a/clippy_lints/src/methods/unnecessary_join.rs +++ b/clippy_lints/src/methods/unnecessary_join.rs @@ -4,7 +4,7 @@ use rustc_ast::ast::LitKind; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, LangItem}; use rustc_lint::LateContext; -use rustc_middle::ty::{Ref, Slice}; +use rustc_middle::ty; use rustc_span::Span; use super::UNNECESSARY_JOIN; @@ -18,9 +18,9 @@ pub(super) fn check<'tcx>( ) { let applicability = Applicability::MachineApplicable; let collect_output_adjusted_type = cx.typeck_results().expr_ty_adjusted(join_self_arg); - if let Ref(_, ref_type, _) = collect_output_adjusted_type.kind() + if let ty::Ref(_, ref_type, _) = collect_output_adjusted_type.kind() // the turbofish for collect is ::> - && let Slice(slice) = ref_type.kind() + && let ty::Slice(slice) = ref_type.kind() && is_type_lang_item(cx, *slice, LangItem::String) // the argument for join is "" && let ExprKind::Lit(spanned) = &join_arg.kind diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 79f0a398d55d..8c2f43c97f4d 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -4,7 +4,7 @@ use clippy_utils::{def_path_def_ids, trait_ref_of_method}; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{Adt, Ty}; +use rustc_middle::ty::{self, Ty}; use rustc_session::impl_lint_pass; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::sym; @@ -153,7 +153,7 @@ impl MutableKeyType { // generics (because the compiler cannot ensure immutability for unknown types). fn check_ty_<'tcx>(&self, cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) { let ty = ty.peel_refs(); - if let Adt(def, args) = ty.kind() { + if let ty::Adt(def, args) = ty.kind() { let is_keyed_type = [sym::HashMap, sym::BTreeMap, sym::HashSet, sym::BTreeSet] .iter() .any(|diag_item| cx.tcx.is_diagnostic_item(*diag_item, def.did())); diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index d1f7c6417c7e..e14480b86556 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -4,7 +4,7 @@ use rustc_hir::{self as hir, HirId, ItemKind, Node}; use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::layout::LayoutOf as _; -use rustc_middle::ty::{Adt, Ty, TypeVisitableExt}; +use rustc_middle::ty::{self, Ty, TypeVisitableExt}; use rustc_session::declare_lint_pass; use rustc_span::sym; @@ -49,7 +49,7 @@ impl LateLintPass<'_> for ZeroSizedMapValues { && !in_trait_impl(cx, hir_ty.hir_id) && let ty = ty_from_hir_ty(cx, hir_ty) && (is_type_diagnostic_item(cx, ty, sym::HashMap) || is_type_diagnostic_item(cx, ty, sym::BTreeMap)) - && let Adt(_, args) = ty.kind() + && let ty::Adt(_, args) = ty.kind() && let ty = args.type_at(1) // Fixes https://github.com/rust-lang/rust-clippy/issues/7447 because of // https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/ty/sty.rs#L968 From b6b3a2f0329196000b837e0f61d9cbef3d833f74 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 6 Mar 2024 17:24:13 +1100 Subject: [PATCH 1152/1222] Avoid lots of `hir::HirId{,Map,Set}` qualifiers. Because they're a bit redundant. --- .../src/functions/not_unsafe_ptr_arg_deref.rs | 4 +-- clippy_lints/src/index_refutable_slice.rs | 13 ++++---- .../src/operators/assign_op_pattern.rs | 33 ++++++++++--------- clippy_lints/src/ptr.rs | 4 +-- .../src/significant_drop_tightening.rs | 18 +++++----- 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index 2d757883f266..995dd782cbbd 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -1,4 +1,4 @@ -use rustc_hir::{self as hir, intravisit, HirIdSet}; +use rustc_hir::{self as hir, intravisit, HirId, HirIdSet}; use rustc_lint::LateContext; use rustc_middle::ty; use rustc_span::def_id::LocalDefId; @@ -74,7 +74,7 @@ fn check_raw_ptr<'tcx>( } } -fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option { +fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option { if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_, _))) = ( &arg.pat.kind, cx.maybe_typeck_results() diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index 4d1f89b1d9d9..6ddc8346511d 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -7,6 +7,7 @@ use clippy_utils::{is_expn_of, is_lint_allowed, path_to_local}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_errors::Applicability; use rustc_hir as hir; +use rustc_hir::HirId; use rustc_hir::intravisit::{self, Visitor}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; @@ -87,9 +88,9 @@ impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice { extract_msrv_attr!(LateContext); } -fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap { - let mut removed_pat: FxHashSet = FxHashSet::default(); - let mut slices: FxIndexMap = FxIndexMap::default(); +fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap { + let mut removed_pat: FxHashSet = FxHashSet::default(); + let mut slices: FxIndexMap = FxIndexMap::default(); pat.walk_always(|pat| { // We'll just ignore mut and ref mut for simplicity sake right now if let hir::PatKind::Binding( @@ -206,10 +207,10 @@ impl SliceLintInformation { fn filter_lintable_slices<'tcx>( cx: &LateContext<'tcx>, - slice_lint_info: FxIndexMap, + slice_lint_info: FxIndexMap, max_suggested_slice: u64, scope: &'tcx hir::Expr<'tcx>, -) -> FxIndexMap { +) -> FxIndexMap { let mut visitor = SliceIndexLintingVisitor { cx, slice_lint_info, @@ -223,7 +224,7 @@ fn filter_lintable_slices<'tcx>( struct SliceIndexLintingVisitor<'a, 'tcx> { cx: &'a LateContext<'tcx>, - slice_lint_info: FxIndexMap, + slice_lint_info: FxIndexMap, max_suggested_slice: u64, } diff --git a/clippy_lints/src/operators/assign_op_pattern.rs b/clippy_lints/src/operators/assign_op_pattern.rs index 2f85130fba11..435eb9048f58 100644 --- a/clippy_lints/src/operators/assign_op_pattern.rs +++ b/clippy_lints/src/operators/assign_op_pattern.rs @@ -6,6 +6,7 @@ use clippy_utils::{binop_traits, eq_expr_value, trait_ref_of_method}; use core::ops::ControlFlow; use rustc_errors::Applicability; use rustc_hir as hir; +use rustc_hir::{HirId, HirIdSet}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use rustc_lint::LateContext; use rustc_middle::mir::FakeReadCause; @@ -98,10 +99,10 @@ pub(super) fn check<'tcx>( } } -fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet { - struct S(hir::HirIdSet); +fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet { + struct S(HirIdSet); impl Delegate<'_> for S { - fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: hir::HirId, kind: BorrowKind) { + fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: HirId, kind: BorrowKind) { if matches!(kind, BorrowKind::ImmBorrow | BorrowKind::UniqueImmBorrow) { self.0.insert(match place.place.base { PlaceBase::Local(id) => id, @@ -111,13 +112,13 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet } } - fn consume(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} - fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} - fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: hir::HirId) {} - fn copy(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} + fn consume(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {} + fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {} + fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: HirId) {} + fn copy(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {} } - let mut s = S(hir::HirIdSet::default()); + let mut s = S(HirIdSet::default()); let infcx = cx.tcx.infer_ctxt().build(); let mut v = ExprUseVisitor::new( &mut s, @@ -130,10 +131,10 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet s.0 } -fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet { - struct S(hir::HirIdSet); +fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet { + struct S(HirIdSet); impl Delegate<'_> for S { - fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: hir::HirId, kind: BorrowKind) { + fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: HirId, kind: BorrowKind) { if matches!(kind, BorrowKind::MutBorrow) { self.0.insert(match place.place.base { PlaceBase::Local(id) => id, @@ -143,13 +144,13 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet } } - fn consume(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} - fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} - fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: hir::HirId) {} - fn copy(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} + fn consume(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {} + fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {} + fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: HirId) {} + fn copy(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {} } - let mut s = S(hir::HirIdSet::default()); + let mut s = S(HirIdSet::default()); let infcx = cx.tcx.infer_ctxt().build(); let mut v = ExprUseVisitor::new( &mut s, diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 83b32000a9f9..d6592622f0bb 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -8,7 +8,7 @@ use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_i use hir::LifetimeName; use rustc_errors::{Applicability, MultiSpan}; use rustc_hir::def_id::DefId; -use rustc_hir::hir_id::HirIdMap; +use rustc_hir::hir_id::{HirId, HirIdMap}; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{ self as hir, AnonConst, BinOpKind, BindingAnnotation, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg, @@ -324,7 +324,7 @@ struct PtrArgReplacement { struct PtrArg<'tcx> { idx: usize, - emission_id: hir::HirId, + emission_id: HirId, span: Span, ty_did: DefId, ty_name: Symbol, diff --git a/clippy_lints/src/significant_drop_tightening.rs b/clippy_lints/src/significant_drop_tightening.rs index d3540bc8e1c3..038eb92d652b 100644 --- a/clippy_lints/src/significant_drop_tightening.rs +++ b/clippy_lints/src/significant_drop_tightening.rs @@ -5,7 +5,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::{self as hir}; +use rustc_hir::{self as hir, HirId}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::ty::{GenericArgKind, Ty}; use rustc_session::impl_lint_pass; @@ -55,7 +55,7 @@ impl_lint_pass!(SignificantDropTightening<'_> => [SIGNIFICANT_DROP_TIGHTENING]); #[derive(Default)] pub struct SignificantDropTightening<'tcx> { - apas: FxIndexMap, + apas: FxIndexMap, /// Auxiliary structure used to avoid having to verify the same type multiple times. seen_types: FxHashSet>, type_cache: FxHashMap, bool>, @@ -359,9 +359,9 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> Visitor<'tcx> for StmtsChecker<'ap, 'lc, 'o /// Auxiliary parameters used on each block check of an item struct AuxParams<'others, 'stmt, 'tcx> { //// See [AuxParamsAttr]. - apas: &'others mut FxIndexMap, + apas: &'others mut FxIndexMap, /// The current block identifier that is being visited. - curr_block_hir_id: hir::HirId, + curr_block_hir_id: HirId, /// The current block span that is being visited. curr_block_span: Span, /// The current statement that is being visited. @@ -369,10 +369,10 @@ struct AuxParams<'others, 'stmt, 'tcx> { } impl<'others, 'stmt, 'tcx> AuxParams<'others, 'stmt, 'tcx> { - fn new(apas: &'others mut FxIndexMap, curr_stmt: &'stmt hir::Stmt<'tcx>) -> Self { + fn new(apas: &'others mut FxIndexMap, curr_stmt: &'stmt hir::Stmt<'tcx>) -> Self { Self { apas, - curr_block_hir_id: hir::HirId::INVALID, + curr_block_hir_id: HirId::INVALID, curr_block_span: DUMMY_SP, curr_stmt: Cow::Borrowed(curr_stmt), } @@ -389,7 +389,7 @@ struct AuxParamsAttr { has_expensive_expr_after_last_attr: bool, /// The identifier of the block that involves the first `#[has_significant_drop]`. - first_block_hir_id: hir::HirId, + first_block_hir_id: HirId, /// The span of the block that involves the first `#[has_significant_drop]`. first_block_span: Span, /// The binding or variable that references the initial construction of the type marked with @@ -414,7 +414,7 @@ impl Default for AuxParamsAttr { Self { counter: 0, has_expensive_expr_after_last_attr: false, - first_block_hir_id: hir::HirId::INVALID, + first_block_hir_id: HirId::INVALID, first_bind_ident: Ident::empty(), first_block_span: DUMMY_SP, first_method_span: DUMMY_SP, @@ -428,7 +428,7 @@ impl Default for AuxParamsAttr { fn dummy_stmt_expr<'any>(expr: &'any hir::Expr<'any>) -> hir::Stmt<'any> { hir::Stmt { - hir_id: hir::HirId::INVALID, + hir_id: HirId::INVALID, kind: hir::StmtKind::Expr(expr), span: DUMMY_SP, } From 01907390db529e11ca8d8274c11b10215b4124ce Mon Sep 17 00:00:00 2001 From: Jules Bertholet Date: Tue, 16 Apr 2024 19:23:30 -0400 Subject: [PATCH 1153/1222] Rename `BindingAnnotation` to `BindingMode` --- clippy_lints/src/dereference.rs | 4 ++-- clippy_lints/src/eta_reduction.rs | 4 ++-- clippy_lints/src/explicit_write.rs | 4 ++-- clippy_lints/src/index_refutable_slice.rs | 2 +- clippy_lints/src/let_if_seq.rs | 4 ++-- clippy_lints/src/loops/manual_find.rs | 4 ++-- clippy_lints/src/loops/mut_range_bound.rs | 4 ++-- clippy_lints/src/loops/same_item_push.rs | 4 ++-- clippy_lints/src/manual_hash_one.rs | 4 ++-- clippy_lints/src/matches/manual_utils.rs | 4 ++-- clippy_lints/src/matches/match_as_ref.rs | 4 ++-- clippy_lints/src/matches/needless_match.rs | 4 ++-- clippy_lints/src/matches/single_match.rs | 4 ++-- clippy_lints/src/methods/clone_on_copy.rs | 4 ++-- clippy_lints/src/methods/filter_next.rs | 4 ++-- clippy_lints/src/methods/iter_kv_map.rs | 2 +- .../src/methods/iter_overeager_cloned.rs | 4 ++-- clippy_lints/src/methods/iter_skip_next.rs | 4 ++-- clippy_lints/src/methods/map_clone.rs | 4 ++-- clippy_lints/src/methods/needless_collect.rs | 4 ++-- clippy_lints/src/methods/str_splitn.rs | 6 +++--- clippy_lints/src/misc.rs | 6 +++--- clippy_lints/src/needless_arbitrary_self_type.rs | 6 +++--- clippy_lints/src/needless_borrowed_ref.rs | 6 +++--- clippy_lints/src/needless_late_init.rs | 4 ++-- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- clippy_lints/src/option_if_let_else.rs | 8 ++++---- clippy_lints/src/pass_by_ref_or_value.rs | 4 ++-- clippy_lints/src/ptr.rs | 6 +++--- clippy_lints/src/question_mark.rs | 4 ++-- clippy_lints/src/redundant_locals.rs | 6 +++--- clippy_lints/src/ref_patterns.rs | 4 ++-- clippy_lints/src/reserve_after_initialization.rs | 4 ++-- clippy_lints/src/slow_vector_initialization.rs | 4 ++-- .../src/unnecessary_struct_initialization.rs | 4 ++-- clippy_lints/src/unnested_or_patterns.rs | 4 ++-- clippy_lints/src/useless_conversion.rs | 4 ++-- clippy_lints/src/utils/author.rs | 16 ++++++++-------- clippy_lints/src/vec_init_then_push.rs | 4 ++-- clippy_utils/src/hir_utils.rs | 4 ++-- clippy_utils/src/lib.rs | 4 ++-- tests/ui/author.stdout | 2 +- tests/ui/author/blocks.stdout | 6 +++--- tests/ui/author/loop.stdout | 4 ++-- tests/ui/author/macro_in_closure.stdout | 2 +- tests/ui/author/macro_in_loop.stdout | 2 +- tests/ui/author/matches.stdout | 4 ++-- 47 files changed, 104 insertions(+), 104 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index f83fb1b90198..bff40c2ae75d 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -9,7 +9,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_ty, Visitor}; use rustc_hir::{ - self as hir, BindingAnnotation, Body, BodyId, BorrowKind, Expr, ExprKind, HirId, MatchSource, Mutability, Node, + self as hir, BindingMode, Body, BodyId, BorrowKind, Expr, ExprKind, HirId, MatchSource, Mutability, Node, Pat, PatKind, Path, QPath, TyKind, UnOp, }; use rustc_lint::{LateContext, LateLintPass}; @@ -599,7 +599,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> { } fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { - if let PatKind::Binding(BindingAnnotation::REF, id, name, _) = pat.kind { + if let PatKind::Binding(BindingMode::REF, id, name, _) = pat.kind { if let Some(opt_prev_pat) = self.ref_locals.get_mut(&id) { // This binding id has been seen before. Add this pattern to the list of changes. if let Some(prev_pat) = opt_prev_pat { diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 850a4f0eec8e..306a4a9e55c9 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -5,7 +5,7 @@ use clippy_utils::ty::type_diagnostic_name; use clippy_utils::usage::{local_used_after_expr, local_used_in}; use clippy_utils::{get_path_from_caller_to_method_type, is_adjusted, path_to_local, path_to_local_id}; use rustc_errors::Applicability; -use rustc_hir::{BindingAnnotation, Expr, ExprKind, FnRetTy, Param, PatKind, QPath, TyKind, Unsafety}; +use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, Param, PatKind, QPath, TyKind, Unsafety}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{ @@ -229,7 +229,7 @@ fn check_inputs( && params.iter().zip(self_arg.into_iter().chain(args)).all(|(p, arg)| { matches!( p.pat.kind, - PatKind::Binding(BindingAnnotation::NONE, id, _, None) + PatKind::Binding(BindingMode::NONE, id, _, None) if path_to_local_id(arg, id) ) // Only allow adjustments which change regions (i.e. re-borrowing). diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 33bd5a5a9d3a..724e1843359b 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet_with_applicability; use clippy_utils::{is_expn_of, path_def_id}; use rustc_errors::Applicability; use rustc_hir::def::Res; -use rustc_hir::{BindingAnnotation, Block, BlockCheckMode, Expr, ExprKind, Node, PatKind, QPath, Stmt, StmtKind}; +use rustc_hir::{BindingMode, Block, BlockCheckMode, Expr, ExprKind, Node, PatKind, QPath, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; use rustc_span::{sym, ExpnId}; @@ -114,7 +114,7 @@ fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>) && let Node::Pat(res_pat) = cx.tcx.hir_node(expr_res) // Find id of the local we found in the block - && let PatKind::Binding(BindingAnnotation::NONE, local_hir_id, _ident, None) = local.pat.kind + && let PatKind::Binding(BindingMode::NONE, local_hir_id, _ident, None) = local.pat.kind // If those two are the same hir id && res_pat.hir_id == local_hir_id diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index 6ddc8346511d..799ec9d553d4 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -94,7 +94,7 @@ fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap LateLintPass<'tcx> for LetIfSeq { }; let mutability = match mode { - BindingAnnotation(_, Mutability::Mut) => " ", + BindingMode(_, Mutability::Mut) => " ", _ => "", }; diff --git a/clippy_lints/src/loops/manual_find.rs b/clippy_lints/src/loops/manual_find.rs index d484ce40d785..b27528c11d48 100644 --- a/clippy_lints/src/loops/manual_find.rs +++ b/clippy_lints/src/loops/manual_find.rs @@ -7,7 +7,7 @@ use clippy_utils::{higher, is_res_lang_ctor, path_res, peel_blocks_with_stmt}; use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::lang_items::LangItem; -use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Node, Pat, PatKind, Stmt, StmtKind}; +use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, Node, Pat, PatKind, Stmt, StmtKind}; use rustc_lint::LateContext; use rustc_span::Span; @@ -107,7 +107,7 @@ fn get_binding(pat: &Pat<'_>) -> Option { hir_id = None; return; } - if let BindingAnnotation::NONE = annotation { + if let BindingMode::NONE = annotation { hir_id = Some(id); } }); diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index 94330001e4f1..5047092192f4 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -2,7 +2,7 @@ use super::MUT_RANGE_BOUND; use clippy_utils::diagnostics::span_lint_and_note; use clippy_utils::{get_enclosing_block, higher, path_to_local}; use rustc_hir::intravisit::{self, Visitor}; -use rustc_hir::{BindingAnnotation, Expr, ExprKind, HirId, Node, PatKind}; +use rustc_hir::{BindingMode, Expr, ExprKind, HirId, Node, PatKind}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; @@ -41,7 +41,7 @@ fn mut_warn_with_span(cx: &LateContext<'_>, span: Option) { fn check_for_mutability(cx: &LateContext<'_>, bound: &Expr<'_>) -> Option { if let Some(hir_id) = path_to_local(bound) && let Node::Pat(pat) = cx.tcx.hir_node(hir_id) - && let PatKind::Binding(BindingAnnotation::MUT, ..) = pat.kind + && let PatKind::Binding(BindingMode::MUT, ..) = pat.kind { return Some(hir_id); } diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index 1d90d4a58f5e..9185cf1f8b2e 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Mutability, Node, Pat, PatKind, Stmt, StmtKind}; +use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, Mutability, Node, Pat, PatKind, Stmt, StmtKind}; use rustc_lint::LateContext; use rustc_span::symbol::sym; use rustc_span::SyntaxContext; @@ -61,7 +61,7 @@ pub(super) fn check<'tcx>( let node = cx.tcx.hir_node(hir_id); if let Node::Pat(pat) = node && let PatKind::Binding(bind_ann, ..) = pat.kind - && !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut)) + && !matches!(bind_ann, BindingMode(_, Mutability::Mut)) && let Node::LetStmt(parent_let_expr) = cx.tcx.parent_hir_node(hir_id) && let Some(init) = parent_let_expr.init { diff --git a/clippy_lints/src/manual_hash_one.rs b/clippy_lints/src/manual_hash_one.rs index f8f33cfc82e9..daa8101aa5ff 100644 --- a/clippy_lints/src/manual_hash_one.rs +++ b/clippy_lints/src/manual_hash_one.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet_opt; use clippy_utils::visitors::{is_local_used, local_used_once}; use clippy_utils::{is_trait_method, path_to_local_id}; use rustc_errors::Applicability; -use rustc_hir::{BindingAnnotation, ExprKind, LetStmt, Node, PatKind, StmtKind}; +use rustc_hir::{BindingMode, ExprKind, LetStmt, Node, PatKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; use rustc_span::sym; @@ -62,7 +62,7 @@ impl_lint_pass!(ManualHashOne => [MANUAL_HASH_ONE]); impl LateLintPass<'_> for ManualHashOne { fn check_local(&mut self, cx: &LateContext<'_>, local: &LetStmt<'_>) { // `let mut hasher = seg.build_hasher();` - if let PatKind::Binding(BindingAnnotation::MUT, hasher, _, None) = local.pat.kind + if let PatKind::Binding(BindingMode::MUT, hasher, _, None) = local.pat.kind && let Some(init) = local.init && !init.span.from_expansion() && let ExprKind::MethodCall(seg, build_hasher, [], _) = init.kind diff --git a/clippy_lints/src/matches/manual_utils.rs b/clippy_lints/src/matches/manual_utils.rs index 152aba99ce9b..183caab56c59 100644 --- a/clippy_lints/src/matches/manual_utils.rs +++ b/clippy_lints/src/matches/manual_utils.rs @@ -11,7 +11,7 @@ use rustc_ast::util::parser::PREC_POSTFIX; use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::LangItem::{OptionNone, OptionSome}; -use rustc_hir::{BindingAnnotation, Expr, ExprKind, HirId, Mutability, Pat, PatKind, Path, QPath}; +use rustc_hir::{BindingMode, Expr, ExprKind, HirId, Mutability, Pat, PatKind, Path, QPath}; use rustc_lint::LateContext; use rustc_span::{sym, SyntaxContext}; @@ -139,7 +139,7 @@ where } // `ref` and `ref mut` annotations were handled earlier. - let annotation = if matches!(annotation, BindingAnnotation::MUT) { + let annotation = if matches!(annotation, BindingMode::MUT) { "mut " } else { "" diff --git a/clippy_lints/src/matches/match_as_ref.rs b/clippy_lints/src/matches/match_as_ref.rs index f5da8ec61874..6c123649afc2 100644 --- a/clippy_lints/src/matches/match_as_ref.rs +++ b/clippy_lints/src/matches/match_as_ref.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::{is_res_lang_ctor, path_res, peel_blocks}; use rustc_errors::Applicability; -use rustc_hir::{Arm, BindingAnnotation, ByRef, Expr, ExprKind, LangItem, Mutability, PatKind, QPath}; +use rustc_hir::{Arm, BindingMode, ByRef, Expr, ExprKind, LangItem, Mutability, PatKind, QPath}; use rustc_lint::LateContext; use rustc_middle::ty; @@ -67,7 +67,7 @@ fn is_none_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool { fn is_ref_some_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> Option { if let PatKind::TupleStruct(ref qpath, [first_pat, ..], _) = arm.pat.kind && is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), LangItem::OptionSome) - && let PatKind::Binding(BindingAnnotation(ByRef::Yes(mutabl), _), .., ident, _) = first_pat.kind + && let PatKind::Binding(BindingMode(ByRef::Yes(mutabl), _), .., ident, _) = first_pat.kind && let ExprKind::Call(e, [arg]) = peel_blocks(arm.body).kind && is_res_lang_ctor(cx, path_res(cx, e), LangItem::OptionSome) && let ExprKind::Path(QPath::Resolved(_, path2)) = arg.kind diff --git a/clippy_lints/src/matches/needless_match.rs b/clippy_lints/src/matches/needless_match.rs index fe83e784c3c9..6f7d69026404 100644 --- a/clippy_lints/src/matches/needless_match.rs +++ b/clippy_lints/src/matches/needless_match.rs @@ -8,7 +8,7 @@ use clippy_utils::{ }; use rustc_errors::Applicability; use rustc_hir::LangItem::OptionNone; -use rustc_hir::{Arm, BindingAnnotation, ByRef, Expr, ExprKind, ItemKind, Node, Pat, PatKind, Path, QPath}; +use rustc_hir::{Arm, BindingMode, ByRef, Expr, ExprKind, ItemKind, Node, Pat, PatKind, Path, QPath}; use rustc_lint::LateContext; use rustc_span::sym; @@ -178,7 +178,7 @@ fn pat_same_as_expr(pat: &Pat<'_>, expr: &Expr<'_>) -> bool { }, )), ) => { - return !matches!(annot, BindingAnnotation(ByRef::Yes(_), _)) && pat_ident.name == first_seg.ident.name; + return !matches!(annot, BindingMode(ByRef::Yes(_), _)) && pat_ident.name == first_seg.ident.name; }, // Example: `Custom::TypeA => Custom::TypeB`, or `None => None` (PatKind::Path(QPath::Resolved(_, p_path)), ExprKind::Path(QPath::Resolved(_, e_path))) => { diff --git a/clippy_lints/src/matches/single_match.rs b/clippy_lints/src/matches/single_match.rs index a0db8e2db1f8..37f72528140f 100644 --- a/clippy_lints/src/matches/single_match.rs +++ b/clippy_lints/src/matches/single_match.rs @@ -4,7 +4,7 @@ use clippy_utils::ty::{implements_trait, is_type_diagnostic_item, peel_mid_ty_re use clippy_utils::{is_lint_allowed, is_unit_expr, is_wild, peel_blocks, peel_hir_pat_refs, peel_n_hir_expr_refs}; use core::cmp::max; use rustc_errors::Applicability; -use rustc_hir::{Arm, BindingAnnotation, Block, Expr, ExprKind, Pat, PatKind}; +use rustc_hir::{Arm, BindingMode, Block, Expr, ExprKind, Pat, PatKind}; use rustc_lint::LateContext; use rustc_middle::ty::{self, Ty}; use rustc_span::{sym, Span}; @@ -166,7 +166,7 @@ fn collect_pat_paths<'a>(acc: &mut Vec>, cx: &LateContext<'a>, pat: &Pat< let p_ty = cx.typeck_results().pat_ty(p); collect_pat_paths(acc, cx, p, p_ty); }), - PatKind::TupleStruct(..) | PatKind::Binding(BindingAnnotation::NONE, .., None) | PatKind::Path(_) => { + PatKind::TupleStruct(..) | PatKind::Binding(BindingMode::NONE, .., None) | PatKind::Path(_) => { acc.push(ty); }, _ => {}, diff --git a/clippy_lints/src/methods/clone_on_copy.rs b/clippy_lints/src/methods/clone_on_copy.rs index 4e6823e8220b..e7a2060be046 100644 --- a/clippy_lints/src/methods/clone_on_copy.rs +++ b/clippy_lints/src/methods/clone_on_copy.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_context; use clippy_utils::ty::is_copy; use rustc_errors::Applicability; -use rustc_hir::{BindingAnnotation, ByRef, Expr, ExprKind, MatchSource, Node, PatKind, QPath}; +use rustc_hir::{BindingMode, ByRef, Expr, ExprKind, MatchSource, Node, PatKind, QPath}; use rustc_lint::LateContext; use rustc_middle::ty::adjustment::Adjust; use rustc_middle::ty::print::with_forced_trimmed_paths; @@ -69,7 +69,7 @@ pub(super) fn check( _ => false, }, // local binding capturing a reference - Node::LetStmt(l) if matches!(l.pat.kind, PatKind::Binding(BindingAnnotation(ByRef::Yes(_), _), ..)) => { + Node::LetStmt(l) if matches!(l.pat.kind, PatKind::Binding(BindingMode(ByRef::Yes(_), _), ..)) => { return; }, _ => false, diff --git a/clippy_lints/src/methods/filter_next.rs b/clippy_lints/src/methods/filter_next.rs index 7339362193e5..e697ba656f5f 100644 --- a/clippy_lints/src/methods/filter_next.rs +++ b/clippy_lints/src/methods/filter_next.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; use clippy_utils::source::snippet; use clippy_utils::ty::implements_trait; -use rustc_ast::{BindingAnnotation, Mutability}; +use rustc_ast::{BindingMode, Mutability}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; @@ -45,7 +45,7 @@ pub(super) fn check<'tcx>( span_lint_and_then(cx, FILTER_NEXT, expr.span, msg, |diag| { let (applicability, pat) = if let Some(id) = path_to_local(recv) && let hir::Node::Pat(pat) = cx.tcx.hir_node(id) - && let hir::PatKind::Binding(BindingAnnotation(_, Mutability::Not), _, ident, _) = pat.kind + && let hir::PatKind::Binding(BindingMode(_, Mutability::Not), _, ident, _) = pat.kind { (Applicability::Unspecified, Some((pat.span, ident))) } else { diff --git a/clippy_lints/src/methods/iter_kv_map.rs b/clippy_lints/src/methods/iter_kv_map.rs index b9fec0c4f80a..7c852a3768d1 100644 --- a/clippy_lints/src/methods/iter_kv_map.rs +++ b/clippy_lints/src/methods/iter_kv_map.rs @@ -6,7 +6,7 @@ use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_sugg, span_lint_an use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::{pat_is_wild, sugg}; -use rustc_hir::{BindingAnnotation, Body, BorrowKind, ByRef, Expr, ExprKind, Mutability, Pat, PatKind}; +use rustc_hir::{BindingMode, Body, BorrowKind, ByRef, Expr, ExprKind, Mutability, Pat, PatKind}; use rustc_lint::{LateContext, LintContext}; use rustc_middle::ty; use rustc_span::{sym, Span}; diff --git a/clippy_lints/src/methods/iter_overeager_cloned.rs b/clippy_lints/src/methods/iter_overeager_cloned.rs index 4729481320eb..6d70989546a2 100644 --- a/clippy_lints/src/methods/iter_overeager_cloned.rs +++ b/clippy_lints/src/methods/iter_overeager_cloned.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_opt; use clippy_utils::ty::{implements_trait, is_copy}; -use rustc_ast::BindingAnnotation; +use rustc_ast::BindingMode; use rustc_errors::Applicability; use rustc_hir::{Body, Expr, ExprKind, HirId, HirIdSet, PatKind}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; @@ -89,7 +89,7 @@ pub(super) fn check<'tcx>( } match it.kind { - PatKind::Binding(BindingAnnotation(_, Mutability::Mut), _, _, _) + PatKind::Binding(BindingMode(_, Mutability::Mut), _, _, _) | PatKind::Ref(_, Mutability::Mut) => { to_be_discarded = true; false diff --git a/clippy_lints/src/methods/iter_skip_next.rs b/clippy_lints/src/methods/iter_skip_next.rs index d1215290dada..fedb7c22eded 100644 --- a/clippy_lints/src/methods/iter_skip_next.rs +++ b/clippy_lints/src/methods/iter_skip_next.rs @@ -3,7 +3,7 @@ use clippy_utils::source::snippet; use clippy_utils::{is_trait_method, path_to_local}; use rustc_errors::Applicability; use rustc_hir as hir; -use rustc_hir::{BindingAnnotation, Node, PatKind}; +use rustc_hir::{BindingMode, Node, PatKind}; use rustc_lint::LateContext; use rustc_span::sym; @@ -22,7 +22,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr if let Some(id) = path_to_local(recv) && let Node::Pat(pat) = cx.tcx.hir_node(id) && let PatKind::Binding(ann, _, _, _) = pat.kind - && ann != BindingAnnotation::MUT + && ann != BindingMode::MUT { application = Applicability::Unspecified; diag.span_help( diff --git a/clippy_lints/src/methods/map_clone.rs b/clippy_lints/src/methods/map_clone.rs index 0901268e9bdc..a5ba5e5d8918 100644 --- a/clippy_lints/src/methods/map_clone.rs +++ b/clippy_lints/src/methods/map_clone.rs @@ -51,13 +51,13 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_ let closure_expr = peel_blocks(closure_body.value); match closure_body.params[0].pat.kind { hir::PatKind::Ref(inner, Mutability::Not) => { - if let hir::PatKind::Binding(hir::BindingAnnotation::NONE, .., name, None) = inner.kind { + if let hir::PatKind::Binding(hir::BindingMode::NONE, .., name, None) = inner.kind { if ident_eq(name, closure_expr) { lint_explicit_closure(cx, e.span, recv.span, true, msrv); } } }, - hir::PatKind::Binding(hir::BindingAnnotation::NONE, .., name, None) => { + hir::PatKind::Binding(hir::BindingMode::NONE, .., name, None) => { match closure_expr.kind { hir::ExprKind::Unary(hir::UnOp::Deref, inner) => { if ident_eq(name, inner) { diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index 662e7746496a..1c695655536c 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -11,7 +11,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_errors::{Applicability, MultiSpan}; use rustc_hir::intravisit::{walk_block, walk_expr, Visitor}; use rustc_hir::{ - BindingAnnotation, Block, Expr, ExprKind, HirId, HirIdSet, LetStmt, Mutability, Node, PatKind, Stmt, StmtKind, + BindingMode, Block, Expr, ExprKind, HirId, HirIdSet, LetStmt, Mutability, Node, PatKind, Stmt, StmtKind, }; use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; @@ -86,7 +86,7 @@ pub(super) fn check<'tcx>( } }, Node::LetStmt(l) => { - if let PatKind::Binding(BindingAnnotation::NONE | BindingAnnotation::MUT, id, _, None) = l.pat.kind + if let PatKind::Binding(BindingMode::NONE | BindingMode::MUT, id, _, None) = l.pat.kind && let ty = cx.typeck_results().expr_ty(collect_expr) && [sym::Vec, sym::VecDeque, sym::BinaryHeap, sym::LinkedList] .into_iter() diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 55ae9746298f..e8c12bbeea0e 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -8,7 +8,7 @@ use clippy_utils::{is_diag_item_method, match_def_path, path_to_local_id, paths} use core::ops::ControlFlow; use rustc_errors::Applicability; use rustc_hir::{ - BindingAnnotation, Expr, ExprKind, HirId, LangItem, LetStmt, MatchSource, Node, Pat, PatKind, QPath, Stmt, StmtKind, + BindingMode, Expr, ExprKind, HirId, LangItem, LetStmt, MatchSource, Node, Pat, PatKind, QPath, Stmt, StmtKind, }; use rustc_lint::LateContext; use rustc_middle::ty; @@ -129,7 +129,7 @@ fn check_manual_split_once_indirect( let ctxt = expr.span.ctxt(); let mut parents = cx.tcx.hir().parent_iter(expr.hir_id); if let (_, Node::LetStmt(local)) = parents.next()? - && let PatKind::Binding(BindingAnnotation::MUT, iter_binding_id, iter_ident, None) = local.pat.kind + && let PatKind::Binding(BindingMode::MUT, iter_binding_id, iter_ident, None) = local.pat.kind && let (iter_stmt_id, Node::Stmt(_)) = parents.next()? && let (_, Node::Block(enclosing_block)) = parents.next()? && let mut stmts = enclosing_block @@ -200,7 +200,7 @@ fn indirect_usage<'tcx>( ) -> Option> { if let StmtKind::Let(&LetStmt { pat: Pat { - kind: PatKind::Binding(BindingAnnotation::NONE, _, ident, None), + kind: PatKind::Binding(BindingMode::NONE, _, ident, None), .. }, init: Some(init_expr), diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 3cf054e72071..f3f9bf11a61c 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -9,7 +9,7 @@ use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::intravisit::FnKind; use rustc_hir::{ - BinOpKind, BindingAnnotation, Body, ByRef, Expr, ExprKind, FnDecl, Mutability, PatKind, QPath, Stmt, StmtKind, + BinOpKind, BindingMode, Body, ByRef, Expr, ExprKind, FnDecl, Mutability, PatKind, QPath, Stmt, StmtKind, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; @@ -129,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for LintPass { if !is_lint_allowed(cx, REF_PATTERNS, arg.pat.hir_id) { return; } - if let PatKind::Binding(BindingAnnotation(ByRef::Yes(_), _), ..) = arg.pat.kind { + if let PatKind::Binding(BindingMode(ByRef::Yes(_), _), ..) = arg.pat.kind { span_lint( cx, TOPLEVEL_REF_ARG, @@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for LintPass { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { if !in_external_macro(cx.tcx.sess, stmt.span) && let StmtKind::Let(local) = stmt.kind - && let PatKind::Binding(BindingAnnotation(ByRef::Yes(mutabl), _), .., name, None) = local.pat.kind + && let PatKind::Binding(BindingMode(ByRef::Yes(mutabl), _), .., name, None) = local.pat.kind && let Some(init) = local.init // Do not emit if clippy::ref_patterns is not allowed to avoid having two lints for the same issue. && is_lint_allowed(cx, REF_PATTERNS, local.pat.hir_id) diff --git a/clippy_lints/src/needless_arbitrary_self_type.rs b/clippy_lints/src/needless_arbitrary_self_type.rs index 2ab83f733cb1..60c44382059a 100644 --- a/clippy_lints/src/needless_arbitrary_self_type.rs +++ b/clippy_lints/src/needless_arbitrary_self_type.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use rustc_ast::ast::{BindingAnnotation, ByRef, Lifetime, Mutability, Param, PatKind, Path, TyKind}; +use rustc_ast::ast::{BindingMode, ByRef, Lifetime, Mutability, Param, PatKind, Path, TyKind}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::declare_lint_pass; @@ -117,13 +117,13 @@ impl EarlyLintPass for NeedlessArbitrarySelfType { match &p.ty.kind { TyKind::Path(None, path) => { - if let PatKind::Ident(BindingAnnotation(ByRef::No, mutbl), _, _) = p.pat.kind { + if let PatKind::Ident(BindingMode(ByRef::No, mutbl), _, _) = p.pat.kind { check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Value, mutbl); } }, TyKind::Ref(lifetime, mut_ty) => { if let TyKind::Path(None, path) = &mut_ty.ty.kind - && let PatKind::Ident(BindingAnnotation::NONE, _, _) = p.pat.kind + && let PatKind::Ident(BindingMode::NONE, _, _) = p.pat.kind { check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Ref(*lifetime), mut_ty.mutbl); } diff --git a/clippy_lints/src/needless_borrowed_ref.rs b/clippy_lints/src/needless_borrowed_ref.rs index d91329eadcb4..fb02f24c9dc6 100644 --- a/clippy_lints/src/needless_borrowed_ref.rs +++ b/clippy_lints/src/needless_borrowed_ref.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use rustc_errors::Applicability; -use rustc_hir::{BindingAnnotation, Mutability, Node, Pat, PatKind}; +use rustc_hir::{BindingMode, Mutability, Node, Pat, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; @@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowedRef { match pat.kind { // Check sub_pat got a `ref` keyword (excluding `ref mut`). - PatKind::Binding(BindingAnnotation::REF, _, ident, None) => { + PatKind::Binding(BindingMode::REF, _, ident, None) => { span_lint_and_then( cx, NEEDLESS_BORROWED_REFERENCE, @@ -128,7 +128,7 @@ fn check_subpatterns<'tcx>( for subpattern in subpatterns { match subpattern.kind { - PatKind::Binding(BindingAnnotation::REF, _, ident, None) => { + PatKind::Binding(BindingMode::REF, _, ident, None) => { // `ref ident` // ^^^^ let span = subpattern.span.until(ident.span); diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs index 810799acb2e2..0c0b1a73351f 100644 --- a/clippy_lints/src/needless_late_init.rs +++ b/clippy_lints/src/needless_late_init.rs @@ -6,7 +6,7 @@ use clippy_utils::visitors::{for_each_expr, for_each_expr_with_closures, is_loca use core::ops::ControlFlow; use rustc_errors::{Applicability, MultiSpan}; use rustc_hir::{ - BindingAnnotation, Block, Expr, ExprKind, HirId, LetStmt, LocalSource, MatchSource, Node, Pat, PatKind, Stmt, + BindingMode, Block, Expr, ExprKind, HirId, LetStmt, LocalSource, MatchSource, Node, Pat, PatKind, Stmt, StmtKind, }; use rustc_lint::{LateContext, LateLintPass}; @@ -369,7 +369,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit { init: None, pat: &Pat { - kind: PatKind::Binding(BindingAnnotation::NONE, binding_id, _, None), + kind: PatKind::Binding(BindingMode::NONE, binding_id, _, None), .. }, source: LocalSource::Normal, diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index f33e2e0ed71a..53bcde680876 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -9,7 +9,7 @@ use rustc_ast::ast::Attribute; use rustc_errors::{Applicability, Diag}; use rustc_hir::intravisit::FnKind; use rustc_hir::{ - BindingAnnotation, Body, FnDecl, GenericArg, HirId, HirIdSet, Impl, ItemKind, LangItem, Mutability, Node, PatKind, + BindingMode, Body, FnDecl, GenericArg, HirId, HirIdSet, Impl, ItemKind, LangItem, Mutability, Node, PatKind, QPath, TyKind, }; use rustc_hir_typeck::expr_use_visitor as euv; @@ -192,7 +192,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { }) && !implements_borrow_trait && !all_borrowable_trait - && let PatKind::Binding(BindingAnnotation(_, Mutability::Not), canonical_id, ..) = arg.pat.kind + && let PatKind::Binding(BindingMode(_, Mutability::Not), canonical_id, ..) = arg.pat.kind && !moved_vars.contains(&canonical_id) { // Dereference suggestion diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index 3cbd03a58c55..d4906328ccb9 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -7,7 +7,7 @@ use clippy_utils::{ use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk}; -use rustc_hir::{Arm, BindingAnnotation, Expr, ExprKind, MatchSource, Mutability, Pat, PatKind, Path, QPath, UnOp}; +use rustc_hir::{Arm, BindingMode, Expr, ExprKind, MatchSource, Mutability, Pat, PatKind, Path, QPath, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; use rustc_span::SyntaxContext; @@ -129,7 +129,7 @@ fn try_get_option_occurrence<'tcx>( .filter_map(|(id, &c)| none_captures.get(id).map(|&c2| (c, c2))) .all(|(x, y)| x.is_imm_ref() && y.is_imm_ref()) { - let capture_mut = if bind_annotation == BindingAnnotation::MUT { + let capture_mut = if bind_annotation == BindingMode::MUT { "mut " } else { "" @@ -149,8 +149,8 @@ fn try_get_option_occurrence<'tcx>( (mutb == Mutability::Not, mutb == Mutability::Mut) }, _ => ( - bind_annotation == BindingAnnotation::REF, - bind_annotation == BindingAnnotation::REF_MUT, + bind_annotation == BindingMode::REF, + bind_annotation == BindingMode::REF_MUT, ), }; diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index bb4a1de9f77d..128bfd49d9e5 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -10,7 +10,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::intravisit::FnKind; -use rustc_hir::{BindingAnnotation, Body, FnDecl, Impl, ItemKind, MutTy, Mutability, Node, PatKind}; +use rustc_hir::{BindingMode, Body, FnDecl, Impl, ItemKind, MutTy, Mutability, Node, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, PointerCoercion}; use rustc_middle::ty::layout::LayoutOf; @@ -221,7 +221,7 @@ impl<'tcx> PassByRefOrValue { // if function has a body and parameter is annotated with mut, ignore if let Some(param) = fn_body.and_then(|body| body.params.get(index)) { match param.pat.kind { - PatKind::Binding(BindingAnnotation::NONE, _, _, _) => {}, + PatKind::Binding(BindingMode::NONE, _, _, _) => {}, _ => continue, } } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index d6592622f0bb..cc61ef9184cd 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -11,7 +11,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::hir_id::{HirId, HirIdMap}; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{ - self as hir, AnonConst, BinOpKind, BindingAnnotation, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg, + self as hir, AnonConst, BinOpKind, BindingMode, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg, ImplItemKind, ItemKind, Lifetime, Mutability, Node, Param, PatKind, QPath, TraitFn, TraitItem, TraitItemKind, TyKind, Unsafety, }; @@ -606,7 +606,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: Some((Node::Stmt(_), _)) => (), Some((Node::LetStmt(l), _)) => { // Only trace simple bindings. e.g `let x = y;` - if let PatKind::Binding(BindingAnnotation::NONE, id, _, None) = l.pat.kind { + if let PatKind::Binding(BindingMode::NONE, id, _, None) = l.pat.kind { self.bindings.insert(id, args_idx); } else { set_skip_flag(); @@ -687,7 +687,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: .filter_map(|(i, arg)| { let param = &body.params[arg.idx]; match param.pat.kind { - PatKind::Binding(BindingAnnotation::NONE, id, _, None) + PatKind::Binding(BindingMode::NONE, id, _, None) if !is_lint_allowed(cx, PTR_ARG, param.hir_id) => { Some((id, i)) diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 927c6f1d519e..4ad967589a54 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -14,7 +14,7 @@ use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::LangItem::{self, OptionNone, OptionSome, ResultErr, ResultOk}; use rustc_hir::{ - BindingAnnotation, Block, Body, ByRef, Expr, ExprKind, LetStmt, Mutability, Node, PatKind, PathSegment, QPath, + BindingMode, Block, Body, ByRef, Expr, ExprKind, LetStmt, Mutability, Node, PatKind, PathSegment, QPath, Stmt, StmtKind, }; use rustc_lint::{LateContext, LateLintPass}; @@ -283,7 +283,7 @@ fn check_if_let_some_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr: && !is_else_clause(cx.tcx, expr) && let PatKind::TupleStruct(ref path1, [field], ddpos) = let_pat.kind && ddpos.as_opt_usize().is_none() - && let PatKind::Binding(BindingAnnotation(by_ref, _), bind_id, ident, None) = field.kind + && let PatKind::Binding(BindingMode(by_ref, _), bind_id, ident, None) = field.kind && let caller_ty = cx.typeck_results().expr_ty(let_expr) && let if_block = IfBlockType::IfLet( cx.qpath_res(path1, let_pat.hir_id), diff --git a/clippy_lints/src/redundant_locals.rs b/clippy_lints/src/redundant_locals.rs index 7202266deeb2..d94ca5bc7ec2 100644 --- a/clippy_lints/src/redundant_locals.rs +++ b/clippy_lints/src/redundant_locals.rs @@ -3,7 +3,7 @@ use clippy_utils::is_from_proc_macro; use clippy_utils::ty::needs_ordered_drop; use rustc_ast::Mutability; use rustc_hir::def::Res; -use rustc_hir::{BindingAnnotation, ByRef, ExprKind, HirId, LetStmt, Node, Pat, PatKind, QPath}; +use rustc_hir::{BindingMode, ByRef, ExprKind, HirId, LetStmt, Node, Pat, PatKind, QPath}; use rustc_hir_typeck::expr_use_visitor::PlaceBase; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { if !local.span.is_desugaring(DesugaringKind::Async) // the pattern is a single by-value binding - && let PatKind::Binding(BindingAnnotation(ByRef::No, mutability), _, ident, None) = local.pat.kind + && let PatKind::Binding(BindingMode(ByRef::No, mutability), _, ident, None) = local.pat.kind // the binding is not type-ascribed && local.ty.is_none() // the expression is a resolved path @@ -109,7 +109,7 @@ fn is_by_value_closure_capture(cx: &LateContext<'_>, redefinition: HirId, root_v } /// Find the annotation of a binding introduced by a pattern, or `None` if it's not introduced. -fn find_binding(pat: &Pat<'_>, name: Ident) -> Option { +fn find_binding(pat: &Pat<'_>, name: Ident) -> Option { let mut ret = None; pat.each_binding_or_first(&mut |annotation, _, _, ident| { diff --git a/clippy_lints/src/ref_patterns.rs b/clippy_lints/src/ref_patterns.rs index a4be78b310b4..607a0740b843 100644 --- a/clippy_lints/src/ref_patterns.rs +++ b/clippy_lints/src/ref_patterns.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_help; -use rustc_ast::ast::{BindingAnnotation, Pat, PatKind}; +use rustc_ast::ast::{BindingMode, Pat, PatKind}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::declare_lint_pass; @@ -28,7 +28,7 @@ declare_lint_pass!(RefPatterns => [REF_PATTERNS]); impl EarlyLintPass for RefPatterns { fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &Pat) { - if let PatKind::Ident(BindingAnnotation::REF, _, _) = pat.kind + if let PatKind::Ident(BindingMode::REF, _, _) = pat.kind && !pat.span.from_expansion() { span_lint_and_help( diff --git a/clippy_lints/src/reserve_after_initialization.rs b/clippy_lints/src/reserve_after_initialization.rs index c227b5b22f4d..caf3fb8707da 100644 --- a/clippy_lints/src/reserve_after_initialization.rs +++ b/clippy_lints/src/reserve_after_initialization.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet; use clippy_utils::{is_from_proc_macro, path_to_local_id}; use rustc_errors::Applicability; use rustc_hir::def::Res; -use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, LetStmt, PatKind, QPath, Stmt, StmtKind}; +use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, LetStmt, PatKind, QPath, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::impl_lint_pass; @@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { if let Some(init_expr) = local.init - && let PatKind::Binding(BindingAnnotation::MUT, id, _, None) = local.pat.kind + && let PatKind::Binding(BindingMode::MUT, id, _, None) = local.pat.kind && !in_external_macro(cx.sess(), local.span) && let Some(init) = get_vec_init_kind(cx, init_expr) && !matches!( diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 8a9f02b6dcb1..28c254537abd 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -7,7 +7,7 @@ use clippy_utils::{ }; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_block, walk_expr, walk_stmt, Visitor}; -use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, PatKind, Stmt, StmtKind}; +use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, PatKind, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; use rustc_span::symbol::sym; @@ -120,7 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for SlowVectorInit { // Matches statements which initializes vectors. For example: `let mut vec = Vec::with_capacity(10)` // or `Vec::new()` if let StmtKind::Let(local) = stmt.kind - && let PatKind::Binding(BindingAnnotation::MUT, local_id, _, None) = local.pat.kind + && let PatKind::Binding(BindingMode::MUT, local_id, _, None) = local.pat.kind && let Some(init) = local.init && let Some(size_expr) = Self::as_vec_initializer(cx, init) { diff --git a/clippy_lints/src/unnecessary_struct_initialization.rs b/clippy_lints/src/unnecessary_struct_initialization.rs index 333ea0c82df6..2da753343448 100644 --- a/clippy_lints/src/unnecessary_struct_initialization.rs +++ b/clippy_lints/src/unnecessary_struct_initialization.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_copy; use clippy_utils::{get_parent_expr, path_to_local}; -use rustc_hir::{BindingAnnotation, Expr, ExprKind, Node, PatKind, UnOp}; +use rustc_hir::{BindingMode, Expr, ExprKind, Node, PatKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; @@ -84,7 +84,7 @@ fn is_mutable(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { if let Some(hir_id) = path_to_local(expr) && let Node::Pat(pat) = cx.tcx.hir_node(hir_id) { - matches!(pat.kind, PatKind::Binding(BindingAnnotation::MUT, ..)) + matches!(pat.kind, PatKind::Binding(BindingMode::MUT, ..)) } else { true } diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 0049de931f4f..fcc41b51542f 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -137,12 +137,12 @@ fn insert_necessary_parens(pat: &mut P) { struct Visitor; impl MutVisitor for Visitor { fn visit_pat(&mut self, pat: &mut P) { - use ast::BindingAnnotation; + use ast::BindingMode; noop_visit_pat(pat, self); let target = match &mut pat.kind { // `i @ a | b`, `box a | b`, and `& mut? a | b`. Ident(.., Some(p)) | Box(p) | Ref(p, _) if matches!(&p.kind, Or(ps) if ps.len() > 1) => p, - Ref(p, Mutability::Not) if matches!(p.kind, Ident(BindingAnnotation::MUT, ..)) => p, // `&(mut x)` + Ref(p, Mutability::Not) if matches!(p.kind, Ident(BindingMode::MUT, ..)) => p, // `&(mut x)` _ => return, }; target.kind = Paren(P(take_pat(target))); diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 755417661565..2f7d54e73ed7 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -5,7 +5,7 @@ use clippy_utils::ty::{is_copy, is_type_diagnostic_item, same_type_and_consts}; use clippy_utils::{get_parent_expr, is_trait_method, is_ty_alias, path_to_local}; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; -use rustc_hir::{BindingAnnotation, Expr, ExprKind, HirId, MatchSource, Node, PatKind}; +use rustc_hir::{BindingMode, Expr, ExprKind, HirId, MatchSource, Node, PatKind}; use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::traits::Obligation; use rustc_lint::{LateContext, LateLintPass}; @@ -282,7 +282,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { if let Some(id) = path_to_local(recv) && let Node::Pat(pat) = cx.tcx.hir_node(id) && let PatKind::Binding(ann, ..) = pat.kind - && ann != BindingAnnotation::MUT + && ann != BindingMode::MUT { // Do not remove .into_iter() applied to a non-mutable local variable used in // a larger expression context as it would differ in mutability. diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 7b43abeef671..7f0769452c73 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -7,7 +7,7 @@ use rustc_ast::LitIntType; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; use rustc_hir::{ - ArrayLen, BindingAnnotation, CaptureBy, Closure, ClosureKind, CoroutineKind, ExprKind, FnRetTy, HirId, Lit, + ArrayLen, BindingMode, CaptureBy, Closure, ClosureKind, CoroutineKind, ExprKind, FnRetTy, HirId, Lit, PatKind, QPath, StmtKind, TyKind, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; @@ -645,14 +645,14 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { bind!(self, name); opt_bind!(self, sub); let ann = match ann { - BindingAnnotation::NONE => "NONE", - BindingAnnotation::REF => "REF", - BindingAnnotation::MUT => "MUT", - BindingAnnotation::REF_MUT => "REF_MUT", - BindingAnnotation::MUT_REF => "MUT_REF", - BindingAnnotation::MUT_REF_MUT => "MUT_REF_MUT", + BindingMode::NONE => "NONE", + BindingMode::REF => "REF", + BindingMode::MUT => "MUT", + BindingMode::REF_MUT => "REF_MUT", + BindingMode::MUT_REF => "MUT_REF", + BindingMode::MUT_REF_MUT => "MUT_REF_MUT", }; - kind!("Binding(BindingAnnotation::{ann}, _, {name}, {sub})"); + kind!("Binding(BindingMode::{ann}, _, {name}, {sub})"); self.ident(name); sub.if_some(|p| self.pat(p)); }, diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs index b58a4fb84746..c46f0298cc8b 100644 --- a/clippy_lints/src/vec_init_then_push.rs +++ b/clippy_lints/src/vec_init_then_push.rs @@ -7,7 +7,7 @@ use core::ops::ControlFlow; use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::{ - BindingAnnotation, Block, Expr, ExprKind, HirId, LetStmt, Mutability, PatKind, QPath, Stmt, StmtKind, UnOp, + BindingMode, Block, Expr, ExprKind, HirId, LetStmt, Mutability, PatKind, QPath, Stmt, StmtKind, UnOp, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; @@ -159,7 +159,7 @@ impl<'tcx> LateLintPass<'tcx> for VecInitThenPush { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { if let Some(init_expr) = local.init - && let PatKind::Binding(BindingAnnotation::MUT, id, name, None) = local.pat.kind + && let PatKind::Binding(BindingMode::MUT, id, name, None) = local.pat.kind && !in_external_macro(cx.sess(), local.span) && let Some(init) = get_vec_init_kind(cx, init_expr) && !matches!(init, VecInitKind::WithExprCapacity(_)) diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 6c3d93299322..07c443acb05f 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxHasher; use rustc_hir::def::Res; use rustc_hir::MatchSource::TryDesugar; use rustc_hir::{ - ArrayLen, BinOpKind, BindingAnnotation, Block, BodyId, Closure, Expr, ExprField, ExprKind, FnRetTy, GenericArg, + ArrayLen, BinOpKind, BindingMode, Block, BodyId, Closure, Expr, ExprField, ExprKind, FnRetTy, GenericArg, GenericArgs, HirId, HirIdMap, InlineAsmOperand, LetExpr, Lifetime, LifetimeName, Pat, PatField, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding, }; @@ -947,7 +947,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { pub fn hash_pat(&mut self, pat: &Pat<'_>) { std::mem::discriminant(&pat.kind).hash(&mut self.s); match pat.kind { - PatKind::Binding(BindingAnnotation(by_ref, mutability), _, _, pat) => { + PatKind::Binding(BindingMode(by_ref, mutability), _, _, pat) => { std::mem::discriminant(&by_ref).hash(&mut self.s); std::mem::discriminant(&mutability).hash(&mut self.s); if let Some(pat) = pat { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 37c12dd850c2..aac699eed239 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -99,7 +99,7 @@ use rustc_hir::hir_id::{HirIdMap, HirIdSet}; use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk}; use rustc_hir::{ - self as hir, def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, ByRef, Closure, Destination, Expr, + self as hir, def, Arm, ArrayLen, BindingMode, Block, BlockCheckMode, Body, ByRef, Closure, Destination, Expr, ExprField, ExprKind, FnDecl, FnRetTy, GenericArgs, HirId, Impl, ImplItem, ImplItemKind, ImplItemRef, Item, ItemKind, LangItem, LetStmt, MatchSource, Mutability, Node, OwnerId, Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitItemRef, TraitRef, TyKind, UnOp, @@ -184,7 +184,7 @@ pub fn expr_or_init<'a, 'b, 'tcx: 'b>(cx: &LateContext<'tcx>, mut expr: &'a Expr /// canonical binding `HirId`. pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<'tcx>> { if let Node::Pat(pat) = cx.tcx.hir_node(hir_id) - && matches!(pat.kind, PatKind::Binding(BindingAnnotation::NONE, ..)) + && matches!(pat.kind, PatKind::Binding(BindingMode::NONE, ..)) && let Node::LetStmt(local) = cx.tcx.parent_hir_node(hir_id) { return local.init; diff --git a/tests/ui/author.stdout b/tests/ui/author.stdout index 27ad538f24d8..d448db097a7e 100644 --- a/tests/ui/author.stdout +++ b/tests/ui/author.stdout @@ -5,7 +5,7 @@ if let StmtKind::Local(local) = stmt.kind && match_qpath(qpath, &["char"]) && let ExprKind::Lit(ref lit) = expr.kind && let LitKind::Int(69, LitIntType::Unsuffixed) = lit.node - && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind + && let PatKind::Binding(BindingMode::NONE, _, name, None) = local.pat.kind && name.as_str() == "x" { // report your lint here diff --git a/tests/ui/author/blocks.stdout b/tests/ui/author/blocks.stdout index 579f137f861e..80b928dd6cb5 100644 --- a/tests/ui/author/blocks.stdout +++ b/tests/ui/author/blocks.stdout @@ -4,13 +4,13 @@ if let ExprKind::Block(block, None) = expr.kind && let Some(init) = local.init && let ExprKind::Lit(ref lit) = init.kind && let LitKind::Int(42, LitIntType::Signed(IntTy::I32)) = lit.node - && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind + && let PatKind::Binding(BindingMode::NONE, _, name, None) = local.pat.kind && name.as_str() == "x" && let StmtKind::Local(local1) = block.stmts[1].kind && let Some(init1) = local1.init && let ExprKind::Lit(ref lit1) = init1.kind && let LitKind::Float(_, LitFloatType::Suffixed(FloatTy::F32)) = lit1.node - && let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local1.pat.kind + && let PatKind::Binding(BindingMode::NONE, _, name1, None) = local1.pat.kind && name1.as_str() == "_t" && let StmtKind::Semi(e) = block.stmts[2].kind && let ExprKind::Unary(UnOp::Neg, inner) = e.kind @@ -28,7 +28,7 @@ if let ExprKind::Block(block, None) = expr.kind && let ExprKind::Path(ref qpath) = func.kind && match_qpath(qpath, &["String", "new"]) && args.is_empty() - && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind + && let PatKind::Binding(BindingMode::NONE, _, name, None) = local.pat.kind && name.as_str() == "expr" && let Some(trailing_expr) = block.expr && let ExprKind::Call(func1, args1) = trailing_expr.kind diff --git a/tests/ui/author/loop.stdout b/tests/ui/author/loop.stdout index 94a6436ed547..631105a2238d 100644 --- a/tests/ui/author/loop.stdout +++ b/tests/ui/author/loop.stdout @@ -1,5 +1,5 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr) - && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = pat.kind + && let PatKind::Binding(BindingMode::NONE, _, name, None) = pat.kind && name.as_str() == "y" && let ExprKind::Struct(qpath, fields, None) = arg.kind && matches!(qpath, QPath::LangItem(LangItem::Range, _)) @@ -16,7 +16,7 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo && let Some(init) = local.init && let ExprKind::Path(ref qpath1) = init.kind && match_qpath(qpath1, &["y"]) - && let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local.pat.kind + && let PatKind::Binding(BindingMode::NONE, _, name1, None) = local.pat.kind && name1.as_str() == "z" && block.expr.is_none() { diff --git a/tests/ui/author/macro_in_closure.stdout b/tests/ui/author/macro_in_closure.stdout index f2e54c2c1c86..b90c830e0307 100644 --- a/tests/ui/author/macro_in_closure.stdout +++ b/tests/ui/author/macro_in_closure.stdout @@ -34,7 +34,7 @@ if let StmtKind::Local(local) = stmt.kind && let ExprKind::Path(ref qpath3) = inner2.kind && match_qpath(qpath3, &["x"]) && block.expr.is_none() - && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind + && let PatKind::Binding(BindingMode::NONE, _, name, None) = local.pat.kind && name.as_str() == "print_text" { // report your lint here diff --git a/tests/ui/author/macro_in_loop.stdout b/tests/ui/author/macro_in_loop.stdout index a719e3af7e76..3f9be297c33c 100644 --- a/tests/ui/author/macro_in_loop.stdout +++ b/tests/ui/author/macro_in_loop.stdout @@ -1,5 +1,5 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr) - && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = pat.kind + && let PatKind::Binding(BindingMode::NONE, _, name, None) = pat.kind && name.as_str() == "i" && let ExprKind::Struct(qpath, fields, None) = arg.kind && matches!(qpath, QPath::LangItem(LangItem::Range, _)) diff --git a/tests/ui/author/matches.stdout b/tests/ui/author/matches.stdout index 88e2ca656a4f..30e4a9b2560a 100644 --- a/tests/ui/author/matches.stdout +++ b/tests/ui/author/matches.stdout @@ -20,7 +20,7 @@ if let StmtKind::Local(local) = stmt.kind && let Some(init1) = local1.init && let ExprKind::Lit(ref lit4) = init1.kind && let LitKind::Int(3, LitIntType::Unsuffixed) = lit4.node - && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local1.pat.kind + && let PatKind::Binding(BindingMode::NONE, _, name, None) = local1.pat.kind && name.as_str() == "x" && let Some(trailing_expr) = block.expr && let ExprKind::Path(ref qpath) = trailing_expr.kind @@ -29,7 +29,7 @@ if let StmtKind::Local(local) = stmt.kind && arms[2].guard.is_none() && let ExprKind::Lit(ref lit5) = arms[2].body.kind && let LitKind::Int(1, LitIntType::Unsuffixed) = lit5.node - && let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local.pat.kind + && let PatKind::Binding(BindingMode::NONE, _, name1, None) = local.pat.kind && name1.as_str() == "a" { // report your lint here From 10bb47a57f9a5de2070edbad7a57afe5e1679f03 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 15 Apr 2024 18:56:44 -0400 Subject: [PATCH 1154/1222] has_typeck_results doesnt need to be a query --- clippy_lints/src/functions/must_use.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index d0c66900c006..e7ec2b3151e6 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -185,7 +185,7 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut DefIdSet) if let hir::PatKind::Wild = pat.kind { return false; // ignore `_` patterns } - if cx.tcx.has_typeck_results(pat.hir_id.owner.to_def_id()) { + if cx.tcx.has_typeck_results(pat.hir_id.owner.def_id) { is_mutable_ty(cx, cx.tcx.typeck(pat.hir_id.owner.def_id).pat_ty(pat), tys) } else { false @@ -233,7 +233,7 @@ fn mutates_static<'tcx>(cx: &LateContext<'tcx>, body: &'tcx hir::Body<'_>) -> bo Call(_, args) => { let mut tys = DefIdSet::default(); for arg in args { - if cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id()) + if cx.tcx.has_typeck_results(arg.hir_id.owner.def_id) && is_mutable_ty(cx, cx.tcx.typeck(arg.hir_id.owner.def_id).expr_ty(arg), &mut tys) && is_mutated_static(arg) { @@ -246,7 +246,7 @@ fn mutates_static<'tcx>(cx: &LateContext<'tcx>, body: &'tcx hir::Body<'_>) -> bo MethodCall(_, receiver, args, _) => { let mut tys = DefIdSet::default(); for arg in std::iter::once(receiver).chain(args.iter()) { - if cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id()) + if cx.tcx.has_typeck_results(arg.hir_id.owner.def_id) && is_mutable_ty(cx, cx.tcx.typeck(arg.hir_id.owner.def_id).expr_ty(arg), &mut tys) && is_mutated_static(arg) { From e2a77ba877cfa10a939a3d6daed19ee8988fa140 Mon Sep 17 00:00:00 2001 From: Dominik Stolz Date: Wed, 17 Apr 2024 23:40:03 +0200 Subject: [PATCH 1155/1222] Disallow ambiguous attributes on expressions --- tests/ui/cfg_attr_rustfmt.fixed | 6 +++--- tests/ui/cfg_attr_rustfmt.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/ui/cfg_attr_rustfmt.fixed b/tests/ui/cfg_attr_rustfmt.fixed index 05d5b3d10eaf..84dac431169a 100644 --- a/tests/ui/cfg_attr_rustfmt.fixed +++ b/tests/ui/cfg_attr_rustfmt.fixed @@ -16,7 +16,7 @@ fn foo( fn skip_on_statements() { #[rustfmt::skip] - 5+3; + { 5+3; } } #[rustfmt::skip] @@ -33,11 +33,11 @@ mod foo { #[clippy::msrv = "1.29"] fn msrv_1_29() { #[cfg_attr(rustfmt, rustfmt::skip)] - 1+29; + { 1+29; } } #[clippy::msrv = "1.30"] fn msrv_1_30() { #[rustfmt::skip] - 1+30; + { 1+30; } } diff --git a/tests/ui/cfg_attr_rustfmt.rs b/tests/ui/cfg_attr_rustfmt.rs index bc29e20210e8..4ab5c70e13b5 100644 --- a/tests/ui/cfg_attr_rustfmt.rs +++ b/tests/ui/cfg_attr_rustfmt.rs @@ -16,7 +16,7 @@ fn foo( fn skip_on_statements() { #[cfg_attr(rustfmt, rustfmt::skip)] - 5+3; + { 5+3; } } #[cfg_attr(rustfmt, rustfmt_skip)] @@ -33,11 +33,11 @@ mod foo { #[clippy::msrv = "1.29"] fn msrv_1_29() { #[cfg_attr(rustfmt, rustfmt::skip)] - 1+29; + { 1+29; } } #[clippy::msrv = "1.30"] fn msrv_1_30() { #[cfg_attr(rustfmt, rustfmt::skip)] - 1+30; + { 1+30; } } From 24108e07014dbdf032e1d53fd745c07a2c1b9d80 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 11 Apr 2024 13:15:34 +0000 Subject: [PATCH 1156/1222] Error on using `yield` without also using `#[coroutine]` on the closure And suggest adding the `#[coroutine]` to the closure --- tests/ui/crashes/ice-5238.rs | 4 ++-- tests/ui/large_futures.fixed | 1 - tests/ui/large_futures.rs | 1 - tests/ui/large_futures.stderr | 16 ++++++++-------- tests/ui/redundant_locals.rs | 6 +++--- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/tests/ui/crashes/ice-5238.rs b/tests/ui/crashes/ice-5238.rs index b1fc3fb9d251..fe03a39ad1ba 100644 --- a/tests/ui/crashes/ice-5238.rs +++ b/tests/ui/crashes/ice-5238.rs @@ -1,9 +1,9 @@ // Regression test for #5238 / https://github.com/rust-lang/rust/pull/69562 -#![feature(coroutines, coroutine_trait)] +#![feature(coroutines, coroutine_trait, stmt_expr_attributes)] fn main() { - let _ = || { + let _ = #[coroutine] || { yield; }; } diff --git a/tests/ui/large_futures.fixed b/tests/ui/large_futures.fixed index aa8c3021b970..1e87859f4526 100644 --- a/tests/ui/large_futures.fixed +++ b/tests/ui/large_futures.fixed @@ -1,4 +1,3 @@ -#![feature(coroutines)] #![warn(clippy::large_futures)] #![allow(clippy::never_loop)] #![allow(clippy::future_not_send)] diff --git a/tests/ui/large_futures.rs b/tests/ui/large_futures.rs index fc6ea458d3db..3f4ea2ebf8bb 100644 --- a/tests/ui/large_futures.rs +++ b/tests/ui/large_futures.rs @@ -1,4 +1,3 @@ -#![feature(coroutines)] #![warn(clippy::large_futures)] #![allow(clippy::never_loop)] #![allow(clippy::future_not_send)] diff --git a/tests/ui/large_futures.stderr b/tests/ui/large_futures.stderr index 5709c7b77a0a..00082e579c59 100644 --- a/tests/ui/large_futures.stderr +++ b/tests/ui/large_futures.stderr @@ -1,5 +1,5 @@ error: large future with a size of 16385 bytes - --> tests/ui/large_futures.rs:11:9 + --> tests/ui/large_futures.rs:10:9 | LL | big_fut([0u8; 1024 * 16]).await; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(big_fut([0u8; 1024 * 16]))` @@ -8,37 +8,37 @@ LL | big_fut([0u8; 1024 * 16]).await; = help: to override `-D warnings` add `#[allow(clippy::large_futures)]` error: large future with a size of 16386 bytes - --> tests/ui/large_futures.rs:15:5 + --> tests/ui/large_futures.rs:14:5 | LL | f.await | ^ help: consider `Box::pin` on it: `Box::pin(f)` error: large future with a size of 16387 bytes - --> tests/ui/large_futures.rs:20:9 + --> tests/ui/large_futures.rs:19:9 | LL | wait().await; | ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())` error: large future with a size of 16387 bytes - --> tests/ui/large_futures.rs:25:13 + --> tests/ui/large_futures.rs:24:13 | LL | wait().await; | ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())` error: large future with a size of 65540 bytes - --> tests/ui/large_futures.rs:33:5 + --> tests/ui/large_futures.rs:32:5 | LL | foo().await; | ^^^^^ help: consider `Box::pin` on it: `Box::pin(foo())` error: large future with a size of 49159 bytes - --> tests/ui/large_futures.rs:35:5 + --> tests/ui/large_futures.rs:34:5 | LL | calls_fut(fut).await; | ^^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(calls_fut(fut))` error: large future with a size of 65540 bytes - --> tests/ui/large_futures.rs:48:5 + --> tests/ui/large_futures.rs:47:5 | LL | / async { LL | | @@ -59,7 +59,7 @@ LL + }) | error: large future with a size of 65540 bytes - --> tests/ui/large_futures.rs:60:13 + --> tests/ui/large_futures.rs:59:13 | LL | / async { LL | | let x = [0i32; 1024 * 16]; diff --git a/tests/ui/redundant_locals.rs b/tests/ui/redundant_locals.rs index f6909828aa9a..e9d77182a919 100644 --- a/tests/ui/redundant_locals.rs +++ b/tests/ui/redundant_locals.rs @@ -1,7 +1,7 @@ //@aux-build:proc_macros.rs #![allow(unused, clippy::no_effect, clippy::needless_pass_by_ref_mut)] #![warn(clippy::redundant_locals)] -#![feature(async_closure, coroutines)] +#![feature(async_closure, coroutines, stmt_expr_attributes)] extern crate proc_macros; use proc_macros::{external, with_span}; @@ -191,11 +191,11 @@ fn issue12225() { let v4 = v4; dbg!(&v4); }); - assert_static(static || { + assert_static(#[coroutine] static || { let v5 = v5; yield; }); - assert_static(|| { + assert_static(#[coroutine] || { let v6 = v6; yield; }); From 360117c060f547262caabe6d7a0debf4989d10d5 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Fri, 19 Apr 2024 17:01:35 +0100 Subject: [PATCH 1157/1222] Fix and bless clippy tests --- tests/ui-toml/suppress_lint_in_const/test.rs | 1 - .../suppress_lint_in_const/test.stderr | 12 ++--- tests/ui/arithmetic_side_effects.rs | 2 +- tests/ui/bool_to_int_with_if.fixed | 2 +- tests/ui/bool_to_int_with_if.rs | 2 +- tests/ui/const_is_empty.rs | 1 - tests/ui/const_is_empty.stderr | 52 +++++++++---------- tests/ui/indexing_slicing_index.rs | 1 - tests/ui/indexing_slicing_index.stderr | 32 ++++++------ tests/ui/manual_float_methods.rs | 1 - tests/ui/manual_float_methods.stderr | 12 ++--- tests/ui/never_loop.rs | 2 +- tests/ui/panicking_macros.rs | 1 - tests/ui/panicking_macros.stderr | 32 ++++++------ 14 files changed, 74 insertions(+), 79 deletions(-) diff --git a/tests/ui-toml/suppress_lint_in_const/test.rs b/tests/ui-toml/suppress_lint_in_const/test.rs index 4ae75544c60c..232bccf6a154 100644 --- a/tests/ui-toml/suppress_lint_in_const/test.rs +++ b/tests/ui-toml/suppress_lint_in_const/test.rs @@ -1,4 +1,3 @@ -#![feature(inline_const)] #![warn(clippy::indexing_slicing)] // We also check the out_of_bounds_indexing lint here, because it lints similar things and // we want to avoid false positives. diff --git a/tests/ui-toml/suppress_lint_in_const/test.stderr b/tests/ui-toml/suppress_lint_in_const/test.stderr index 120f5c35cb03..5ce2ed2ffaee 100644 --- a/tests/ui-toml/suppress_lint_in_const/test.stderr +++ b/tests/ui-toml/suppress_lint_in_const/test.stderr @@ -1,5 +1,5 @@ error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:27:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:26:5 | LL | x[index]; | ^^^^^^^^ @@ -9,7 +9,7 @@ LL | x[index]; = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]` error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:42:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:41:5 | LL | v[0]; | ^^^^ @@ -17,7 +17,7 @@ LL | v[0]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:43:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:42:5 | LL | v[10]; | ^^^^^ @@ -25,7 +25,7 @@ LL | v[10]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:44:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:43:5 | LL | v[1 << 3]; | ^^^^^^^^^ @@ -33,7 +33,7 @@ LL | v[1 << 3]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:50:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:49:5 | LL | v[N]; | ^^^^ @@ -41,7 +41,7 @@ LL | v[N]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:51:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:50:5 | LL | v[M]; | ^^^^ diff --git a/tests/ui/arithmetic_side_effects.rs b/tests/ui/arithmetic_side_effects.rs index b454c29aef4d..fdec14a1528f 100644 --- a/tests/ui/arithmetic_side_effects.rs +++ b/tests/ui/arithmetic_side_effects.rs @@ -10,7 +10,7 @@ arithmetic_overflow, unconditional_panic )] -#![feature(const_mut_refs, inline_const)] +#![feature(const_mut_refs)] #![warn(clippy::arithmetic_side_effects)] extern crate proc_macro_derive; diff --git a/tests/ui/bool_to_int_with_if.fixed b/tests/ui/bool_to_int_with_if.fixed index 167263d31df8..f7dad28b0369 100644 --- a/tests/ui/bool_to_int_with_if.fixed +++ b/tests/ui/bool_to_int_with_if.fixed @@ -1,4 +1,4 @@ -#![feature(let_chains, inline_const)] +#![feature(let_chains)] #![warn(clippy::bool_to_int_with_if)] #![allow(unused, dead_code, clippy::unnecessary_operation, clippy::no_effect)] diff --git a/tests/ui/bool_to_int_with_if.rs b/tests/ui/bool_to_int_with_if.rs index f3f055eb7f06..d22871d2c8f2 100644 --- a/tests/ui/bool_to_int_with_if.rs +++ b/tests/ui/bool_to_int_with_if.rs @@ -1,4 +1,4 @@ -#![feature(let_chains, inline_const)] +#![feature(let_chains)] #![warn(clippy::bool_to_int_with_if)] #![allow(unused, dead_code, clippy::unnecessary_operation, clippy::no_effect)] diff --git a/tests/ui/const_is_empty.rs b/tests/ui/const_is_empty.rs index ae37a82e4f93..04e0de91ecfb 100644 --- a/tests/ui/const_is_empty.rs +++ b/tests/ui/const_is_empty.rs @@ -1,4 +1,3 @@ -#![feature(inline_const)] #![warn(clippy::const_is_empty)] #![allow(clippy::needless_late_init, unused_must_use)] diff --git a/tests/ui/const_is_empty.stderr b/tests/ui/const_is_empty.stderr index 0e09da77bb46..7f80b520b1a4 100644 --- a/tests/ui/const_is_empty.stderr +++ b/tests/ui/const_is_empty.stderr @@ -1,5 +1,5 @@ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:6:8 + --> tests/ui/const_is_empty.rs:5:8 | LL | if "".is_empty() { | ^^^^^^^^^^^^^ @@ -8,151 +8,151 @@ LL | if "".is_empty() { = help: to override `-D warnings` add `#[allow(clippy::const_is_empty)]` error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:9:8 + --> tests/ui/const_is_empty.rs:8:8 | LL | if "foobar".is_empty() { | ^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:15:8 + --> tests/ui/const_is_empty.rs:14:8 | LL | if b"".is_empty() { | ^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:18:8 + --> tests/ui/const_is_empty.rs:17:8 | LL | if b"foobar".is_empty() { | ^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:35:8 + --> tests/ui/const_is_empty.rs:34:8 | LL | if empty2.is_empty() { | ^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:38:8 + --> tests/ui/const_is_empty.rs:37:8 | LL | if non_empty2.is_empty() { | ^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:60:13 + --> tests/ui/const_is_empty.rs:59:13 | LL | let _ = EMPTY_STR.is_empty(); | ^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:62:13 + --> tests/ui/const_is_empty.rs:61:13 | LL | let _ = NON_EMPTY_STR.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:64:13 + --> tests/ui/const_is_empty.rs:63:13 | LL | let _ = EMPTY_BSTR.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:66:13 + --> tests/ui/const_is_empty.rs:65:13 | LL | let _ = NON_EMPTY_BSTR.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:68:13 + --> tests/ui/const_is_empty.rs:67:13 | LL | let _ = EMPTY_ARRAY.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:70:13 + --> tests/ui/const_is_empty.rs:69:13 | LL | let _ = EMPTY_ARRAY_REPEAT.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:72:13 + --> tests/ui/const_is_empty.rs:71:13 | LL | let _ = EMPTY_U8_SLICE.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:74:13 + --> tests/ui/const_is_empty.rs:73:13 | LL | let _ = NON_EMPTY_U8_SLICE.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:76:13 + --> tests/ui/const_is_empty.rs:75:13 | LL | let _ = NON_EMPTY_ARRAY.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:78:13 + --> tests/ui/const_is_empty.rs:77:13 | LL | let _ = NON_EMPTY_ARRAY_REPEAT.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:80:13 + --> tests/ui/const_is_empty.rs:79:13 | LL | let _ = EMPTY_REF_ARRAY.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:82:13 + --> tests/ui/const_is_empty.rs:81:13 | LL | let _ = NON_EMPTY_REF_ARRAY.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:84:13 + --> tests/ui/const_is_empty.rs:83:13 | LL | let _ = EMPTY_SLICE.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:86:13 + --> tests/ui/const_is_empty.rs:85:13 | LL | let _ = NON_EMPTY_SLICE.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:88:13 + --> tests/ui/const_is_empty.rs:87:13 | LL | let _ = NON_EMPTY_SLICE_REPEAT.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:94:13 + --> tests/ui/const_is_empty.rs:93:13 | LL | let _ = value.is_empty(); | ^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:97:13 + --> tests/ui/const_is_empty.rs:96:13 | LL | let _ = x.is_empty(); | ^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:99:13 + --> tests/ui/const_is_empty.rs:98:13 | LL | let _ = "".is_empty(); | ^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:101:13 + --> tests/ui/const_is_empty.rs:100:13 | LL | let _ = b"".is_empty(); | ^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:155:13 + --> tests/ui/const_is_empty.rs:154:13 | LL | let _ = val.is_empty(); | ^^^^^^^^^^^^^^ diff --git a/tests/ui/indexing_slicing_index.rs b/tests/ui/indexing_slicing_index.rs index 27ee2f91594b..2e726141649e 100644 --- a/tests/ui/indexing_slicing_index.rs +++ b/tests/ui/indexing_slicing_index.rs @@ -1,6 +1,5 @@ //@compile-flags: -Zdeduplicate-diagnostics=yes -#![feature(inline_const)] #![warn(clippy::indexing_slicing)] // We also check the out_of_bounds_indexing lint here, because it lints similar things and // we want to avoid false positives. diff --git a/tests/ui/indexing_slicing_index.stderr b/tests/ui/indexing_slicing_index.stderr index 5f62ec9b5565..386f91becf14 100644 --- a/tests/ui/indexing_slicing_index.stderr +++ b/tests/ui/indexing_slicing_index.stderr @@ -1,5 +1,5 @@ error: indexing may panic - --> tests/ui/indexing_slicing_index.rs:16:20 + --> tests/ui/indexing_slicing_index.rs:15:20 | LL | const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-restriction-lint-in-const` default is false. | ^^^^^^^^^^ @@ -10,19 +10,19 @@ LL | const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-re = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]` error[E0080]: evaluation of `main::{constant#3}` failed - --> tests/ui/indexing_slicing_index.rs:48:14 + --> tests/ui/indexing_slicing_index.rs:47:14 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 note: erroneous constant encountered - --> tests/ui/indexing_slicing_index.rs:48:5 + --> tests/ui/indexing_slicing_index.rs:47:5 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^^^^^^^^^^^^ error: indexing may panic - --> tests/ui/indexing_slicing_index.rs:29:5 + --> tests/ui/indexing_slicing_index.rs:28:5 | LL | x[index]; | ^^^^^^^^ @@ -30,7 +30,7 @@ LL | x[index]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: index is out of bounds - --> tests/ui/indexing_slicing_index.rs:32:5 + --> tests/ui/indexing_slicing_index.rs:31:5 | LL | x[4]; | ^^^^ @@ -39,13 +39,13 @@ LL | x[4]; = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]` error: index is out of bounds - --> tests/ui/indexing_slicing_index.rs:34:5 + --> tests/ui/indexing_slicing_index.rs:33:5 | LL | x[1 << 3]; | ^^^^^^^^^ error: indexing may panic - --> tests/ui/indexing_slicing_index.rs:45:14 + --> tests/ui/indexing_slicing_index.rs:44:14 | LL | const { &ARR[idx()] }; | ^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | const { &ARR[idx()] }; = note: the suggestion might not be applicable in constant blocks error: indexing may panic - --> tests/ui/indexing_slicing_index.rs:48:14 + --> tests/ui/indexing_slicing_index.rs:47:14 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ @@ -63,13 +63,13 @@ LL | const { &ARR[idx4()] }; = note: the suggestion might not be applicable in constant blocks error: index is out of bounds - --> tests/ui/indexing_slicing_index.rs:55:5 + --> tests/ui/indexing_slicing_index.rs:54:5 | LL | y[4]; | ^^^^ error: indexing may panic - --> tests/ui/indexing_slicing_index.rs:58:5 + --> tests/ui/indexing_slicing_index.rs:57:5 | LL | v[0]; | ^^^^ @@ -77,7 +77,7 @@ LL | v[0]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui/indexing_slicing_index.rs:60:5 + --> tests/ui/indexing_slicing_index.rs:59:5 | LL | v[10]; | ^^^^^ @@ -85,7 +85,7 @@ LL | v[10]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui/indexing_slicing_index.rs:62:5 + --> tests/ui/indexing_slicing_index.rs:61:5 | LL | v[1 << 3]; | ^^^^^^^^^ @@ -93,13 +93,13 @@ LL | v[1 << 3]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: index is out of bounds - --> tests/ui/indexing_slicing_index.rs:70:5 + --> tests/ui/indexing_slicing_index.rs:69:5 | LL | x[N]; | ^^^^ error: indexing may panic - --> tests/ui/indexing_slicing_index.rs:73:5 + --> tests/ui/indexing_slicing_index.rs:72:5 | LL | v[N]; | ^^^^ @@ -107,7 +107,7 @@ LL | v[N]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui/indexing_slicing_index.rs:75:5 + --> tests/ui/indexing_slicing_index.rs:74:5 | LL | v[M]; | ^^^^ @@ -115,7 +115,7 @@ LL | v[M]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: index is out of bounds - --> tests/ui/indexing_slicing_index.rs:79:13 + --> tests/ui/indexing_slicing_index.rs:78:13 | LL | let _ = x[4]; | ^^^^ diff --git a/tests/ui/manual_float_methods.rs b/tests/ui/manual_float_methods.rs index f3e95d6807d3..80781ecda721 100644 --- a/tests/ui/manual_float_methods.rs +++ b/tests/ui/manual_float_methods.rs @@ -2,7 +2,6 @@ //@aux-build:proc_macros.rs #![allow(clippy::needless_if, unused)] #![warn(clippy::manual_is_infinite, clippy::manual_is_finite)] -#![feature(inline_const)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/manual_float_methods.stderr b/tests/ui/manual_float_methods.stderr index dae96839262d..930df0b97cb3 100644 --- a/tests/ui/manual_float_methods.stderr +++ b/tests/ui/manual_float_methods.stderr @@ -1,5 +1,5 @@ error: manually checking if a float is infinite - --> tests/ui/manual_float_methods.rs:23:8 + --> tests/ui/manual_float_methods.rs:22:8 | LL | if x == f32::INFINITY || x == f32::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()` @@ -8,7 +8,7 @@ LL | if x == f32::INFINITY || x == f32::NEG_INFINITY {} = help: to override `-D warnings` add `#[allow(clippy::manual_is_infinite)]` error: manually checking if a float is finite - --> tests/ui/manual_float_methods.rs:24:8 + --> tests/ui/manual_float_methods.rs:23:8 | LL | if x != f32::INFINITY && x != f32::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -29,13 +29,13 @@ LL | if !x.is_infinite() {} | ~~~~~~~~~~~~~~~~ error: manually checking if a float is infinite - --> tests/ui/manual_float_methods.rs:25:8 + --> tests/ui/manual_float_methods.rs:24:8 | LL | if x == INFINITE || x == NEG_INFINITE {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()` error: manually checking if a float is finite - --> tests/ui/manual_float_methods.rs:26:8 + --> tests/ui/manual_float_methods.rs:25:8 | LL | if x != INFINITE && x != NEG_INFINITE {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,13 +54,13 @@ LL | if !x.is_infinite() {} | ~~~~~~~~~~~~~~~~ error: manually checking if a float is infinite - --> tests/ui/manual_float_methods.rs:28:8 + --> tests/ui/manual_float_methods.rs:27:8 | LL | if x == f64::INFINITY || x == f64::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()` error: manually checking if a float is finite - --> tests/ui/manual_float_methods.rs:29:8 + --> tests/ui/manual_float_methods.rs:28:8 | LL | if x != f64::INFINITY && x != f64::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/never_loop.rs b/tests/ui/never_loop.rs index 92f173d9db4a..93c69209c698 100644 --- a/tests/ui/never_loop.rs +++ b/tests/ui/never_loop.rs @@ -1,4 +1,4 @@ -#![feature(inline_const, try_blocks)] +#![feature(try_blocks)] #![allow( clippy::eq_op, clippy::single_match, diff --git a/tests/ui/panicking_macros.rs b/tests/ui/panicking_macros.rs index dccfbd409e50..2bbf5792ec4c 100644 --- a/tests/ui/panicking_macros.rs +++ b/tests/ui/panicking_macros.rs @@ -1,5 +1,4 @@ #![allow(clippy::assertions_on_constants, clippy::eq_op, clippy::let_unit_value)] -#![feature(inline_const)] #![warn(clippy::unimplemented, clippy::unreachable, clippy::todo, clippy::panic)] extern crate core; diff --git a/tests/ui/panicking_macros.stderr b/tests/ui/panicking_macros.stderr index 06025859c0c6..7c0f0a7d3764 100644 --- a/tests/ui/panicking_macros.stderr +++ b/tests/ui/panicking_macros.stderr @@ -1,5 +1,5 @@ error: `panic` should not be present in production code - --> tests/ui/panicking_macros.rs:23:5 + --> tests/ui/panicking_macros.rs:22:5 | LL | panic!(); | ^^^^^^^^ @@ -8,19 +8,19 @@ LL | panic!(); = help: to override `-D warnings` add `#[allow(clippy::panic)]` error: `panic` should not be present in production code - --> tests/ui/panicking_macros.rs:26:5 + --> tests/ui/panicking_macros.rs:25:5 | LL | panic!("message"); | ^^^^^^^^^^^^^^^^^ error: `panic` should not be present in production code - --> tests/ui/panicking_macros.rs:28:5 + --> tests/ui/panicking_macros.rs:27:5 | LL | panic!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `todo` should not be present in production code - --> tests/ui/panicking_macros.rs:35:5 + --> tests/ui/panicking_macros.rs:34:5 | LL | todo!(); | ^^^^^^^ @@ -29,19 +29,19 @@ LL | todo!(); = help: to override `-D warnings` add `#[allow(clippy::todo)]` error: `todo` should not be present in production code - --> tests/ui/panicking_macros.rs:38:5 + --> tests/ui/panicking_macros.rs:37:5 | LL | todo!("message"); | ^^^^^^^^^^^^^^^^ error: `todo` should not be present in production code - --> tests/ui/panicking_macros.rs:40:5 + --> tests/ui/panicking_macros.rs:39:5 | LL | todo!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `unimplemented` should not be present in production code - --> tests/ui/panicking_macros.rs:47:5 + --> tests/ui/panicking_macros.rs:46:5 | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^ @@ -50,19 +50,19 @@ LL | unimplemented!(); = help: to override `-D warnings` add `#[allow(clippy::unimplemented)]` error: `unimplemented` should not be present in production code - --> tests/ui/panicking_macros.rs:50:5 + --> tests/ui/panicking_macros.rs:49:5 | LL | unimplemented!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `unimplemented` should not be present in production code - --> tests/ui/panicking_macros.rs:52:5 + --> tests/ui/panicking_macros.rs:51:5 | LL | unimplemented!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> tests/ui/panicking_macros.rs:59:5 + --> tests/ui/panicking_macros.rs:58:5 | LL | unreachable!(); | ^^^^^^^^^^^^^^ @@ -71,37 +71,37 @@ LL | unreachable!(); = help: to override `-D warnings` add `#[allow(clippy::unreachable)]` error: usage of the `unreachable!` macro - --> tests/ui/panicking_macros.rs:62:5 + --> tests/ui/panicking_macros.rs:61:5 | LL | unreachable!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> tests/ui/panicking_macros.rs:64:5 + --> tests/ui/panicking_macros.rs:63:5 | LL | unreachable!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `panic` should not be present in production code - --> tests/ui/panicking_macros.rs:71:5 + --> tests/ui/panicking_macros.rs:70:5 | LL | panic!(); | ^^^^^^^^ error: `todo` should not be present in production code - --> tests/ui/panicking_macros.rs:73:5 + --> tests/ui/panicking_macros.rs:72:5 | LL | todo!(); | ^^^^^^^ error: `unimplemented` should not be present in production code - --> tests/ui/panicking_macros.rs:75:5 + --> tests/ui/panicking_macros.rs:74:5 | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> tests/ui/panicking_macros.rs:77:5 + --> tests/ui/panicking_macros.rs:76:5 | LL | unreachable!(); | ^^^^^^^^^^^^^^ From f601814db50d2aa3021e908a63f8032c507bd497 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 24 Apr 2024 20:31:51 +0300 Subject: [PATCH 1158/1222] ast: Generalize item kind visiting And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign). --- tests/ui/tabs_in_doc_comments.stderr | 48 ++++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/ui/tabs_in_doc_comments.stderr b/tests/ui/tabs_in_doc_comments.stderr index 23d5dcd3a8da..aef6c3914526 100644 --- a/tests/ui/tabs_in_doc_comments.stderr +++ b/tests/ui/tabs_in_doc_comments.stderr @@ -1,53 +1,53 @@ error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:10:9 + --> tests/ui/tabs_in_doc_comments.rs:6:5 | -LL | /// - First String: - | ^^^^ help: consider using four spaces per tab +LL | /// - first one + | ^^^^ help: consider using four spaces per tab | = note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::tabs_in_doc_comments)]` error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:11:9 + --> tests/ui/tabs_in_doc_comments.rs:6:13 | -LL | /// - needs to be inside here - | ^^^^^^^^ help: consider using four spaces per tab +LL | /// - first one + | ^^^^^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:14:9 + --> tests/ui/tabs_in_doc_comments.rs:7:5 | -LL | /// - Second String: - | ^^^^ help: consider using four spaces per tab +LL | /// - second one + | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:15:9 + --> tests/ui/tabs_in_doc_comments.rs:7:14 | -LL | /// - needs to be inside here - | ^^^^^^^^ help: consider using four spaces per tab +LL | /// - second one + | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:6:5 + --> tests/ui/tabs_in_doc_comments.rs:10:9 | -LL | /// - first one - | ^^^^ help: consider using four spaces per tab +LL | /// - First String: + | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:6:13 + --> tests/ui/tabs_in_doc_comments.rs:11:9 | -LL | /// - first one - | ^^^^^^^^ help: consider using four spaces per tab +LL | /// - needs to be inside here + | ^^^^^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:7:5 + --> tests/ui/tabs_in_doc_comments.rs:14:9 | -LL | /// - second one - | ^^^^ help: consider using four spaces per tab +LL | /// - Second String: + | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:7:14 + --> tests/ui/tabs_in_doc_comments.rs:15:9 | -LL | /// - second one - | ^^^^ help: consider using four spaces per tab +LL | /// - needs to be inside here + | ^^^^^^^^ help: consider using four spaces per tab error: aborting due to 8 previous errors From 324c3aea97b0ebc443201d3ec726a9d1f78ccc0e Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 26 Apr 2024 12:57:02 +0000 Subject: [PATCH 1159/1222] put `hir::AnonConst` on the hir arena --- clippy_utils/src/hir_utils.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 07c443acb05f..c921168df290 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -224,7 +224,7 @@ impl HirEqInterExpr<'_, '_, '_> { }) } - pub fn eq_array_length(&mut self, left: ArrayLen, right: ArrayLen) -> bool { + pub fn eq_array_length(&mut self, left: ArrayLen<'_>, right: ArrayLen<'_>) -> bool { match (left, right) { (ArrayLen::Infer(..), ArrayLen::Infer(..)) => true, (ArrayLen::Body(l_ct), ArrayLen::Body(r_ct)) => self.eq_body(l_ct.body, r_ct.body), @@ -1116,7 +1116,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } - pub fn hash_array_length(&mut self, length: ArrayLen) { + pub fn hash_array_length(&mut self, length: ArrayLen<'_>) { match length { ArrayLen::Infer(..) => {}, ArrayLen::Body(anon_const) => self.hash_body(anon_const.body), From 2a60ff64dd90daec9a85420f97bb3316a2999404 Mon Sep 17 00:00:00 2001 From: klensy Date: Fri, 26 Apr 2024 13:47:14 +0300 Subject: [PATCH 1160/1222] clippy: bless tests --- tests/ui/from_over_into.stderr | 2 +- tests/ui/let_and_return.stderr | 2 +- tests/ui/manual_strip.stderr | 4 ++-- tests/ui/result_map_unit_fn_unfixable.stderr | 2 +- tests/ui/suspicious_doc_comments.stderr | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/ui/from_over_into.stderr b/tests/ui/from_over_into.stderr index 0649a6cb0f3e..f913ae0bb506 100644 --- a/tests/ui/from_over_into.stderr +++ b/tests/ui/from_over_into.stderr @@ -54,7 +54,7 @@ help: replace the `Into` implementation with `From` LL ~ impl core::convert::From for bool { LL ~ fn from(mut val: crate::ExplicitPaths) -> Self { LL ~ let in_closure = || val.0; -LL | +LL | LL ~ val.0 = false; LL ~ val.0 | diff --git a/tests/ui/let_and_return.stderr b/tests/ui/let_and_return.stderr index f614a5739a86..ff5962ec196e 100644 --- a/tests/ui/let_and_return.stderr +++ b/tests/ui/let_and_return.stderr @@ -71,7 +71,7 @@ LL | result help: return the expression directly | LL ~ -LL | +LL | LL ~ (match self { LL + E::A(x) => x, LL + E::B(x) => x, diff --git a/tests/ui/manual_strip.stderr b/tests/ui/manual_strip.stderr index d2d4f765310b..a70c988a0549 100644 --- a/tests/ui/manual_strip.stderr +++ b/tests/ui/manual_strip.stderr @@ -17,7 +17,7 @@ LL ~ if let Some() = s.strip_prefix("ab") { LL ~ str::to_string(); LL | LL ~ .to_string(); -LL | +LL | LL ~ str::to_string(); LL ~ .to_string(); | @@ -39,7 +39,7 @@ LL ~ if let Some() = s.strip_suffix("bc") { LL ~ str::to_string(); LL | LL ~ .to_string(); -LL | +LL | LL ~ str::to_string(); LL ~ .to_string(); | diff --git a/tests/ui/result_map_unit_fn_unfixable.stderr b/tests/ui/result_map_unit_fn_unfixable.stderr index fa2ac7a1b37e..d69c86c70e29 100644 --- a/tests/ui/result_map_unit_fn_unfixable.stderr +++ b/tests/ui/result_map_unit_fn_unfixable.stderr @@ -27,7 +27,7 @@ LL | || do_nothing(value) LL | || }); | ||______^- help: try: `if let Ok(value) = x.field { ... }` | |______| - | + | error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` --> tests/ui/result_map_unit_fn_unfixable.rs:37:5 diff --git a/tests/ui/suspicious_doc_comments.stderr b/tests/ui/suspicious_doc_comments.stderr index b54309b44d5d..f12053b1595a 100644 --- a/tests/ui/suspicious_doc_comments.stderr +++ b/tests/ui/suspicious_doc_comments.stderr @@ -85,7 +85,7 @@ LL | | ///! b help: use an inner doc comment to document the parent module or crate | LL ~ //! a -LL | +LL | LL ~ //! b | From 48de3898fcd04f6275a64f55c6bf2f7e15efa0a9 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 29 Apr 2024 11:27:14 -0300 Subject: [PATCH 1161/1222] Add StaticForeignItem and use it on ForeignItemKind --- clippy_utils/src/ast_utils.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 0395eb1449b4..529d20126b22 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -446,7 +446,18 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { use ForeignItemKind::*; match (l, r) { - (Static(lt, lm, le), Static(rt, rm, re)) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), + ( + Static(box StaticForeignItem { + ty: lt, + mutability: lm, + expr: le, + }), + Static(box StaticForeignItem { + ty: rt, + mutability: rm, + expr: re, + }), + ) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), ( Fn(box ast::Fn { defaultness: ld, From 48bcb16ac7b85375c9bf29e653ee98b754bc0de3 Mon Sep 17 00:00:00 2001 From: Ross Smyth <18294397+RossSmyth@users.noreply.github.com> Date: Sun, 28 Apr 2024 00:39:32 -0400 Subject: [PATCH 1162/1222] Update clippy tests for stable exclusive_range --- tests/ui/almost_complete_range.fixed | 1 - tests/ui/almost_complete_range.rs | 1 - tests/ui/almost_complete_range.stderr | 54 +++++++++++++-------------- tests/ui/manual_range_patterns.fixed | 1 - tests/ui/manual_range_patterns.rs | 1 - tests/ui/manual_range_patterns.stderr | 38 +++++++++---------- tests/ui/match_overlapping_arm.rs | 1 - tests/ui/match_overlapping_arm.stderr | 32 ++++++++-------- tests/ui/match_wild_err_arm.rs | 1 - tests/ui/match_wild_err_arm.stderr | 8 ++-- 10 files changed, 66 insertions(+), 72 deletions(-) diff --git a/tests/ui/almost_complete_range.fixed b/tests/ui/almost_complete_range.fixed index 21caeb153e77..6c2b2f117437 100644 --- a/tests/ui/almost_complete_range.fixed +++ b/tests/ui/almost_complete_range.fixed @@ -1,7 +1,6 @@ //@edition:2018 //@aux-build:proc_macros.rs -#![feature(exclusive_range_pattern)] #![feature(stmt_expr_attributes)] #![warn(clippy::almost_complete_range)] #![allow(ellipsis_inclusive_range_patterns)] diff --git a/tests/ui/almost_complete_range.rs b/tests/ui/almost_complete_range.rs index 556110a5c8aa..813668a53096 100644 --- a/tests/ui/almost_complete_range.rs +++ b/tests/ui/almost_complete_range.rs @@ -1,7 +1,6 @@ //@edition:2018 //@aux-build:proc_macros.rs -#![feature(exclusive_range_pattern)] #![feature(stmt_expr_attributes)] #![warn(clippy::almost_complete_range)] #![allow(ellipsis_inclusive_range_patterns)] diff --git a/tests/ui/almost_complete_range.stderr b/tests/ui/almost_complete_range.stderr index 0195e59226d5..bfc2beb07d85 100644 --- a/tests/ui/almost_complete_range.stderr +++ b/tests/ui/almost_complete_range.stderr @@ -1,5 +1,5 @@ error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:18:17 + --> tests/ui/almost_complete_range.rs:17:17 | LL | let _ = ('a') ..'z'; | ^^^^^^--^^^ @@ -10,7 +10,7 @@ LL | let _ = ('a') ..'z'; = help: to override `-D warnings` add `#[allow(clippy::almost_complete_range)]` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:19:17 + --> tests/ui/almost_complete_range.rs:18:17 | LL | let _ = 'A' .. ('Z'); | ^^^^--^^^^^^ @@ -18,7 +18,7 @@ LL | let _ = 'A' .. ('Z'); | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:20:17 + --> tests/ui/almost_complete_range.rs:19:17 | LL | let _ = ((('0'))) .. ('9'); | ^^^^^^^^^^--^^^^^^ @@ -26,7 +26,7 @@ LL | let _ = ((('0'))) .. ('9'); | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:27:13 + --> tests/ui/almost_complete_range.rs:26:13 | LL | let _ = (b'a')..(b'z'); | ^^^^^^--^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = (b'a')..(b'z'); | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:28:13 + --> tests/ui/almost_complete_range.rs:27:13 | LL | let _ = b'A'..b'Z'; | ^^^^--^^^^ @@ -42,7 +42,7 @@ LL | let _ = b'A'..b'Z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:29:13 + --> tests/ui/almost_complete_range.rs:28:13 | LL | let _ = b'0'..b'9'; | ^^^^--^^^^ @@ -50,7 +50,7 @@ LL | let _ = b'0'..b'9'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:35:13 + --> tests/ui/almost_complete_range.rs:34:13 | LL | let _ = inline!('a')..'z'; | ^^^^^^^^^^^^--^^^ @@ -58,7 +58,7 @@ LL | let _ = inline!('a')..'z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:36:13 + --> tests/ui/almost_complete_range.rs:35:13 | LL | let _ = inline!('A')..'Z'; | ^^^^^^^^^^^^--^^^ @@ -66,7 +66,7 @@ LL | let _ = inline!('A')..'Z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:37:13 + --> tests/ui/almost_complete_range.rs:36:13 | LL | let _ = inline!('0')..'9'; | ^^^^^^^^^^^^--^^^ @@ -74,7 +74,7 @@ LL | let _ = inline!('0')..'9'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:40:9 + --> tests/ui/almost_complete_range.rs:39:9 | LL | b'a'..b'z' if true => 1, | ^^^^--^^^^ @@ -82,7 +82,7 @@ LL | b'a'..b'z' if true => 1, | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:41:9 + --> tests/ui/almost_complete_range.rs:40:9 | LL | b'A'..b'Z' if true => 2, | ^^^^--^^^^ @@ -90,7 +90,7 @@ LL | b'A'..b'Z' if true => 2, | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:42:9 + --> tests/ui/almost_complete_range.rs:41:9 | LL | b'0'..b'9' if true => 3, | ^^^^--^^^^ @@ -98,7 +98,7 @@ LL | b'0'..b'9' if true => 3, | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:50:9 + --> tests/ui/almost_complete_range.rs:49:9 | LL | 'a'..'z' if true => 1, | ^^^--^^^ @@ -106,7 +106,7 @@ LL | 'a'..'z' if true => 1, | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:51:9 + --> tests/ui/almost_complete_range.rs:50:9 | LL | 'A'..'Z' if true => 2, | ^^^--^^^ @@ -114,7 +114,7 @@ LL | 'A'..'Z' if true => 2, | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:52:9 + --> tests/ui/almost_complete_range.rs:51:9 | LL | '0'..'9' if true => 3, | ^^^--^^^ @@ -122,7 +122,7 @@ LL | '0'..'9' if true => 3, | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:65:17 + --> tests/ui/almost_complete_range.rs:64:17 | LL | let _ = 'a'..'z'; | ^^^--^^^ @@ -132,7 +132,7 @@ LL | let _ = 'a'..'z'; = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:66:17 + --> tests/ui/almost_complete_range.rs:65:17 | LL | let _ = 'A'..'Z'; | ^^^--^^^ @@ -142,7 +142,7 @@ LL | let _ = 'A'..'Z'; = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:67:17 + --> tests/ui/almost_complete_range.rs:66:17 | LL | let _ = '0'..'9'; | ^^^--^^^ @@ -152,7 +152,7 @@ LL | let _ = '0'..'9'; = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:74:9 + --> tests/ui/almost_complete_range.rs:73:9 | LL | 'a'..'z' => 1, | ^^^--^^^ @@ -160,7 +160,7 @@ LL | 'a'..'z' => 1, | help: use an inclusive range: `...` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:75:9 + --> tests/ui/almost_complete_range.rs:74:9 | LL | 'A'..'Z' => 2, | ^^^--^^^ @@ -168,7 +168,7 @@ LL | 'A'..'Z' => 2, | help: use an inclusive range: `...` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:76:9 + --> tests/ui/almost_complete_range.rs:75:9 | LL | '0'..'9' => 3, | ^^^--^^^ @@ -176,7 +176,7 @@ LL | '0'..'9' => 3, | help: use an inclusive range: `...` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:83:13 + --> tests/ui/almost_complete_range.rs:82:13 | LL | let _ = 'a'..'z'; | ^^^--^^^ @@ -184,7 +184,7 @@ LL | let _ = 'a'..'z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:84:13 + --> tests/ui/almost_complete_range.rs:83:13 | LL | let _ = 'A'..'Z'; | ^^^--^^^ @@ -192,7 +192,7 @@ LL | let _ = 'A'..'Z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:85:13 + --> tests/ui/almost_complete_range.rs:84:13 | LL | let _ = '0'..'9'; | ^^^--^^^ @@ -200,7 +200,7 @@ LL | let _ = '0'..'9'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:87:9 + --> tests/ui/almost_complete_range.rs:86:9 | LL | 'a'..'z' => 1, | ^^^--^^^ @@ -208,7 +208,7 @@ LL | 'a'..'z' => 1, | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:88:9 + --> tests/ui/almost_complete_range.rs:87:9 | LL | 'A'..'Z' => 1, | ^^^--^^^ @@ -216,7 +216,7 @@ LL | 'A'..'Z' => 1, | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:89:9 + --> tests/ui/almost_complete_range.rs:88:9 | LL | '0'..'9' => 3, | ^^^--^^^ diff --git a/tests/ui/manual_range_patterns.fixed b/tests/ui/manual_range_patterns.fixed index e9f6fbcc3fc8..f1b99637afdb 100644 --- a/tests/ui/manual_range_patterns.fixed +++ b/tests/ui/manual_range_patterns.fixed @@ -1,7 +1,6 @@ #![allow(unused)] #![allow(non_contiguous_range_endpoints)] #![warn(clippy::manual_range_patterns)] -#![feature(exclusive_range_pattern)] fn main() { let f = 6; diff --git a/tests/ui/manual_range_patterns.rs b/tests/ui/manual_range_patterns.rs index d525aaa24ad1..869ffbe80b97 100644 --- a/tests/ui/manual_range_patterns.rs +++ b/tests/ui/manual_range_patterns.rs @@ -1,7 +1,6 @@ #![allow(unused)] #![allow(non_contiguous_range_endpoints)] #![warn(clippy::manual_range_patterns)] -#![feature(exclusive_range_pattern)] fn main() { let f = 6; diff --git a/tests/ui/manual_range_patterns.stderr b/tests/ui/manual_range_patterns.stderr index af9256aeea39..7c19fdd475f1 100644 --- a/tests/ui/manual_range_patterns.stderr +++ b/tests/ui/manual_range_patterns.stderr @@ -1,5 +1,5 @@ error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:9:25 + --> tests/ui/manual_range_patterns.rs:8:25 | LL | let _ = matches!(f, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` @@ -8,109 +8,109 @@ LL | let _ = matches!(f, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10); = help: to override `-D warnings` add `#[allow(clippy::manual_range_patterns)]` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:10:25 + --> tests/ui/manual_range_patterns.rs:9:25 | LL | let _ = matches!(f, 4 | 2 | 3 | 1 | 5 | 6 | 9 | 7 | 8 | 10); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:17:25 + --> tests/ui/manual_range_patterns.rs:16:25 | LL | let _ = matches!(f, 1 | (2..=4)); | ^^^^^^^^^^^ help: try: `1..=4` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:18:25 + --> tests/ui/manual_range_patterns.rs:17:25 | LL | let _ = matches!(f, 1 | (2..4)); | ^^^^^^^^^^ help: try: `1..4` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:19:25 + --> tests/ui/manual_range_patterns.rs:18:25 | LL | let _ = matches!(f, (1..=10) | (2..=13) | (14..=48324728) | 48324729); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=48324729` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:20:25 + --> tests/ui/manual_range_patterns.rs:19:25 | LL | let _ = matches!(f, 0 | (1..=10) | 48324730 | (2..=13) | (14..=48324728) | 48324729); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0..=48324730` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:21:25 + --> tests/ui/manual_range_patterns.rs:20:25 | LL | let _ = matches!(f, 0..=1 | 0..=2 | 0..=3); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `0..=3` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:24:9 + --> tests/ui/manual_range_patterns.rs:23:9 | LL | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 => true, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:27:25 + --> tests/ui/manual_range_patterns.rs:26:25 | LL | let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1 | 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-5..=3` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:29:25 + --> tests/ui/manual_range_patterns.rs:28:25 | LL | let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_001); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-1_000_001..=1_000_001` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:32:17 + --> tests/ui/manual_range_patterns.rs:31:17 | LL | matches!(f, 0x00 | 0x01 | 0x02 | 0x03); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0x00..=0x03` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:33:17 + --> tests/ui/manual_range_patterns.rs:32:17 | LL | matches!(f, 0x00..=0x05 | 0x06 | 0x07); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0x00..=0x07` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:34:17 + --> tests/ui/manual_range_patterns.rs:33:17 | LL | matches!(f, -0x09 | -0x08 | -0x07..=0x00); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-0x09..=0x00` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:36:17 + --> tests/ui/manual_range_patterns.rs:35:17 | LL | matches!(f, 0..5 | 5); | ^^^^^^^^ help: try: `0..=5` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:37:17 + --> tests/ui/manual_range_patterns.rs:36:17 | LL | matches!(f, 0 | 1..5); | ^^^^^^^^ help: try: `0..5` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:39:17 + --> tests/ui/manual_range_patterns.rs:38:17 | LL | matches!(f, 0..=5 | 6..10); | ^^^^^^^^^^^^^ help: try: `0..10` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:40:17 + --> tests/ui/manual_range_patterns.rs:39:17 | LL | matches!(f, 0..5 | 5..=10); | ^^^^^^^^^^^^^ help: try: `0..=10` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:41:17 + --> tests/ui/manual_range_patterns.rs:40:17 | LL | matches!(f, 5..=10 | 0..5); | ^^^^^^^^^^^^^ help: try: `0..=10` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:45:26 + --> tests/ui/manual_range_patterns.rs:44:26 | LL | matches!($e, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` diff --git a/tests/ui/match_overlapping_arm.rs b/tests/ui/match_overlapping_arm.rs index c2c2f28392d7..4457ae73da2f 100644 --- a/tests/ui/match_overlapping_arm.rs +++ b/tests/ui/match_overlapping_arm.rs @@ -1,4 +1,3 @@ -#![feature(exclusive_range_pattern)] #![warn(clippy::match_overlapping_arm)] #![allow(clippy::redundant_pattern_matching)] #![allow(clippy::if_same_then_else, clippy::equatable_if_let, clippy::needless_if)] diff --git a/tests/ui/match_overlapping_arm.stderr b/tests/ui/match_overlapping_arm.stderr index 1a6c5746c3dd..65092ffbb555 100644 --- a/tests/ui/match_overlapping_arm.stderr +++ b/tests/ui/match_overlapping_arm.stderr @@ -1,11 +1,11 @@ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:12:9 + --> tests/ui/match_overlapping_arm.rs:11:9 | LL | 0..=10 => println!("0..=10"), | ^^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:14:9 + --> tests/ui/match_overlapping_arm.rs:13:9 | LL | 0..=11 => println!("0..=11"), | ^^^^^^ @@ -13,85 +13,85 @@ LL | 0..=11 => println!("0..=11"), = help: to override `-D warnings` add `#[allow(clippy::match_overlapping_arm)]` error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:19:9 + --> tests/ui/match_overlapping_arm.rs:18:9 | LL | 0..=5 => println!("0..=5"), | ^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:22:9 + --> tests/ui/match_overlapping_arm.rs:21:9 | LL | FOO..=11 => println!("FOO..=11"), | ^^^^^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:57:9 + --> tests/ui/match_overlapping_arm.rs:56:9 | LL | 0..11 => println!("0..11"), | ^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:59:9 + --> tests/ui/match_overlapping_arm.rs:58:9 | LL | 0..=11 => println!("0..=11"), | ^^^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:83:9 + --> tests/ui/match_overlapping_arm.rs:82:9 | LL | 0..=10 => println!("0..=10"), | ^^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:82:9 + --> tests/ui/match_overlapping_arm.rs:81:9 | LL | 5..14 => println!("5..14"), | ^^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:89:9 + --> tests/ui/match_overlapping_arm.rs:88:9 | LL | 0..7 => println!("0..7"), | ^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:91:9 + --> tests/ui/match_overlapping_arm.rs:90:9 | LL | 0..=10 => println!("0..=10"), | ^^^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:102:9 + --> tests/ui/match_overlapping_arm.rs:101:9 | LL | ..=23 => println!("..=23"), | ^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:104:9 + --> tests/ui/match_overlapping_arm.rs:103:9 | LL | ..26 => println!("..26"), | ^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:112:9 + --> tests/ui/match_overlapping_arm.rs:111:9 | LL | 21..=30 => (), | ^^^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:114:9 + --> tests/ui/match_overlapping_arm.rs:113:9 | LL | 21..=40 => (), | ^^^^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:127:9 + --> tests/ui/match_overlapping_arm.rs:126:9 | LL | 0..=0x0000_0000_0000_00ff => (), | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:129:9 + --> tests/ui/match_overlapping_arm.rs:128:9 | LL | 0..=0x0000_0000_0000_ffff => (), | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/match_wild_err_arm.rs b/tests/ui/match_wild_err_arm.rs index 7bdd75d7f463..8e670ce5bda2 100644 --- a/tests/ui/match_wild_err_arm.rs +++ b/tests/ui/match_wild_err_arm.rs @@ -1,4 +1,3 @@ -#![feature(exclusive_range_pattern)] #![allow(clippy::match_same_arms, dead_code)] #![warn(clippy::match_wild_err_arm)] diff --git a/tests/ui/match_wild_err_arm.stderr b/tests/ui/match_wild_err_arm.stderr index 3145665a341e..f98065d9a591 100644 --- a/tests/ui/match_wild_err_arm.stderr +++ b/tests/ui/match_wild_err_arm.stderr @@ -1,5 +1,5 @@ error: `Err(_)` matches all errors - --> tests/ui/match_wild_err_arm.rs:24:9 + --> tests/ui/match_wild_err_arm.rs:23:9 | LL | Err(_) => panic!("err"), | ^^^^^^ @@ -9,7 +9,7 @@ LL | Err(_) => panic!("err"), = help: to override `-D warnings` add `#[allow(clippy::match_wild_err_arm)]` error: `Err(_)` matches all errors - --> tests/ui/match_wild_err_arm.rs:32:9 + --> tests/ui/match_wild_err_arm.rs:31:9 | LL | Err(_) => panic!(), | ^^^^^^ @@ -17,7 +17,7 @@ LL | Err(_) => panic!(), = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable error: `Err(_)` matches all errors - --> tests/ui/match_wild_err_arm.rs:40:9 + --> tests/ui/match_wild_err_arm.rs:39:9 | LL | Err(_) => { | ^^^^^^ @@ -25,7 +25,7 @@ LL | Err(_) => { = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable error: `Err(_e)` matches all errors - --> tests/ui/match_wild_err_arm.rs:50:9 + --> tests/ui/match_wild_err_arm.rs:49:9 | LL | Err(_e) => panic!(), | ^^^^^^^ From 0eff5a05438b6db5621595365d4d2acfca6ad58a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 8 May 2024 16:56:02 +1000 Subject: [PATCH 1163/1222] Simplify `use crate::rustc_foo::bar` occurrences. They can just be written as `use rustc_foo::bar`, which is far more standard. (I didn't even know that a `crate::` prefix was valid.) --- clippy_lints/src/manual_assert.rs | 3 +-- clippy_lints/src/methods/iter_overeager_cloned.rs | 2 +- clippy_lints/src/redundant_closure_call.rs | 3 +-- clippy_lints/src/semicolon_if_nothing_returned.rs | 3 +-- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/manual_assert.rs b/clippy_lints/src/manual_assert.rs index d76b94eba23e..83c16d4466d0 100644 --- a/clippy_lints/src/manual_assert.rs +++ b/clippy_lints/src/manual_assert.rs @@ -1,10 +1,9 @@ -use crate::rustc_lint::LintContext; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::macros::{is_panic, root_macro_call}; use clippy_utils::{is_else_clause, is_parent_stmt, peel_blocks_with_stmt, span_extract_comment, sugg}; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, UnOp}; -use rustc_lint::{LateContext, LateLintPass}; +use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::declare_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/methods/iter_overeager_cloned.rs b/clippy_lints/src/methods/iter_overeager_cloned.rs index 03b4680c5224..deac159457a6 100644 --- a/clippy_lints/src/methods/iter_overeager_cloned.rs +++ b/clippy_lints/src/methods/iter_overeager_cloned.rs @@ -9,10 +9,10 @@ use rustc_lint::LateContext; use rustc_middle::mir::{FakeReadCause, Mutability}; use rustc_middle::ty::{self, BorrowKind}; use rustc_span::sym; +use rustc_trait_selection::infer::TyCtxtInferExt; use super::ITER_OVEREAGER_CLONED; use crate::redundant_clone::REDUNDANT_CLONE; -use crate::rustc_trait_selection::infer::TyCtxtInferExt; #[derive(Clone, Copy)] pub(super) enum Op<'a> { diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 2863eb190d34..47d3ed08b8ec 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -1,4 +1,3 @@ -use crate::rustc_lint::LintContext; use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir}; use clippy_utils::get_parent_expr; use clippy_utils::sugg::Sugg; @@ -9,7 +8,7 @@ use rustc_hir::intravisit::{Visitor as HirVisitor, Visitor}; use rustc_hir::{ intravisit as hir_visit, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, ExprKind, Node, }; -use rustc_lint::{LateContext, LateLintPass}; +use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; use rustc_middle::ty; diff --git a/clippy_lints/src/semicolon_if_nothing_returned.rs b/clippy_lints/src/semicolon_if_nothing_returned.rs index 6540626f7d5a..63237c655ef1 100644 --- a/clippy_lints/src/semicolon_if_nothing_returned.rs +++ b/clippy_lints/src/semicolon_if_nothing_returned.rs @@ -1,9 +1,8 @@ -use crate::rustc_lint::LintContext; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_context; use rustc_errors::Applicability; use rustc_hir::{Block, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; +use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::declare_lint_pass; use rustc_span::{ExpnKind, MacroKind, Span}; From 7ed117e0488aaef21c66e841d2447e3f767b1126 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 23 Apr 2024 21:15:33 +0200 Subject: [PATCH 1164/1222] Simplify `clippy` lint. --- clippy_lints/src/transmute/mod.rs | 10 +-- .../transmute/transmute_int_to_non_zero.rs | 35 ++------ tests/ui/transmute_int_to_non_zero.fixed | 62 +++++++------- tests/ui/transmute_int_to_non_zero.rs | 62 +++++++------- tests/ui/transmute_int_to_non_zero.stderr | 80 +++++++++---------- 5 files changed, 113 insertions(+), 136 deletions(-) diff --git a/clippy_lints/src/transmute/mod.rs b/clippy_lints/src/transmute/mod.rs index 7fa536a1a29d..598032ccdebe 100644 --- a/clippy_lints/src/transmute/mod.rs +++ b/clippy_lints/src/transmute/mod.rs @@ -257,7 +257,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Checks for transmutes from integers to `NonZero*` types, and suggests their `new_unchecked` + /// Checks for transmutes from `T` to `NonZero`, and suggests the `new_unchecked` /// method instead. /// /// ### Why is this bad? @@ -266,13 +266,13 @@ declare_clippy_lint! { /// /// ### Example /// ```no_run - /// # use core::num::NonZeroU32; - /// let _non_zero: NonZeroU32 = unsafe { std::mem::transmute(123) }; + /// # use core::num::NonZero; + /// let _: NonZero = unsafe { std::mem::transmute(123) }; /// ``` /// Use instead: /// ```no_run - /// # use core::num::NonZeroU32; - /// let _non_zero = unsafe { NonZeroU32::new_unchecked(123) }; + /// # use core::num::NonZero; + /// let _: NonZero = unsafe { NonZero::new_unchecked(123) }; /// ``` #[clippy::version = "1.69.0"] pub TRANSMUTE_INT_TO_NON_ZERO, diff --git a/clippy_lints/src/transmute/transmute_int_to_non_zero.rs b/clippy_lints/src/transmute/transmute_int_to_non_zero.rs index 2bea3be3d603..7d824ef21390 100644 --- a/clippy_lints/src/transmute/transmute_int_to_non_zero.rs +++ b/clippy_lints/src/transmute/transmute_int_to_non_zero.rs @@ -26,45 +26,22 @@ pub(super) fn check<'tcx>( return false; }; - // FIXME: This can be simplified once `NonZero` is stable. - let coercible_types = [ - ("NonZeroU8", tcx.types.u8), - ("NonZeroU16", tcx.types.u16), - ("NonZeroU32", tcx.types.u32), - ("NonZeroU64", tcx.types.u64), - ("NonZeroU128", tcx.types.u128), - ("NonZeroUsize", tcx.types.usize), - ("NonZeroI8", tcx.types.i8), - ("NonZeroI16", tcx.types.i16), - ("NonZeroI32", tcx.types.i32), - ("NonZeroI64", tcx.types.i64), - ("NonZeroI128", tcx.types.i128), - ("NonZeroIsize", tcx.types.isize), - ]; - - let int_type = substs.type_at(0); - - let Some(nonzero_alias) = coercible_types.iter().find_map(|(nonzero_alias, t)| { - if *t == int_type && *t == from_ty { - Some(nonzero_alias) - } else { - None - } - }) else { - return false; - }; + let int_ty = substs.type_at(0); + if from_ty != int_ty { + return false; + } span_lint_and_then( cx, TRANSMUTE_INT_TO_NON_ZERO, e.span, - format!("transmute from a `{from_ty}` to a `{nonzero_alias}`"), + format!("transmute from a `{from_ty}` to a `{}<{int_ty}>`", sym::NonZero), |diag| { let arg = sugg::Sugg::hir(cx, arg, ".."); diag.span_suggestion( e.span, "consider using", - format!("{nonzero_alias}::{}({arg})", sym::new_unchecked), + format!("{}::{}({arg})", sym::NonZero, sym::new_unchecked), Applicability::Unspecified, ); }, diff --git a/tests/ui/transmute_int_to_non_zero.fixed b/tests/ui/transmute_int_to_non_zero.fixed index fe8db3dcb0cf..1a48051ec8c4 100644 --- a/tests/ui/transmute_int_to_non_zero.fixed +++ b/tests/ui/transmute_int_to_non_zero.fixed @@ -1,7 +1,7 @@ #![warn(clippy::transmute_int_to_non_zero)] #![allow(clippy::missing_transmute_annotations)] -use core::num::*; +use core::num::NonZero; fn main() { let int_u8: u8 = 1; @@ -16,38 +16,38 @@ fn main() { let int_i64: i64 = 1; let int_i128: i128 = 1; - let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) }; - //~^ ERROR: transmute from a `u8` to a `NonZeroU8` + let _: NonZero = unsafe { NonZero::new_unchecked(int_u8) }; + //~^ ERROR: transmute from a `u8` to a `NonZero` //~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings` - let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) }; - //~^ ERROR: transmute from a `u16` to a `NonZeroU16` - let _: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(int_u32) }; - //~^ ERROR: transmute from a `u32` to a `NonZeroU32` - let _: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(int_u64) }; - //~^ ERROR: transmute from a `u64` to a `NonZeroU64` - let _: NonZeroU128 = unsafe { NonZeroU128::new_unchecked(int_u128) }; - //~^ ERROR: transmute from a `u128` to a `NonZeroU128` + let _: NonZero = unsafe { NonZero::new_unchecked(int_u16) }; + //~^ ERROR: transmute from a `u16` to a `NonZero` + let _: NonZero = unsafe { NonZero::new_unchecked(int_u32) }; + //~^ ERROR: transmute from a `u32` to a `NonZero` + let _: NonZero = unsafe { NonZero::new_unchecked(int_u64) }; + //~^ ERROR: transmute from a `u64` to a `NonZero` + let _: NonZero = unsafe { NonZero::new_unchecked(int_u128) }; + //~^ ERROR: transmute from a `u128` to a `NonZero` - let _: NonZeroI8 = unsafe { NonZeroI8::new_unchecked(int_i8) }; - //~^ ERROR: transmute from a `i8` to a `NonZeroI8` - let _: NonZeroI16 = unsafe { NonZeroI16::new_unchecked(int_i16) }; - //~^ ERROR: transmute from a `i16` to a `NonZeroI16` - let _: NonZeroI32 = unsafe { NonZeroI32::new_unchecked(int_i32) }; - //~^ ERROR: transmute from a `i32` to a `NonZeroI32` - let _: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(int_i64) }; - //~^ ERROR: transmute from a `i64` to a `NonZeroI64` - let _: NonZeroI128 = unsafe { NonZeroI128::new_unchecked(int_i128) }; - //~^ ERROR: transmute from a `i128` to a `NonZeroI128` + let _: NonZero = unsafe { NonZero::new_unchecked(int_i8) }; + //~^ ERROR: transmute from a `i8` to a `NonZero` + let _: NonZero = unsafe { NonZero::new_unchecked(int_i16) }; + //~^ ERROR: transmute from a `i16` to a `NonZero` + let _: NonZero = unsafe { NonZero::new_unchecked(int_i32) }; + //~^ ERROR: transmute from a `i32` to a `NonZero` + let _: NonZero = unsafe { NonZero::new_unchecked(int_i64) }; + //~^ ERROR: transmute from a `i64` to a `NonZero` + let _: NonZero = unsafe { NonZero::new_unchecked(int_i128) }; + //~^ ERROR: transmute from a `i128` to a `NonZero` - let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) }; - let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) }; - let _: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(int_u32) }; - let _: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(int_u64) }; - let _: NonZeroU128 = unsafe { NonZeroU128::new_unchecked(int_u128) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_u8) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_u16) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_u32) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_u64) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_u128) }; - let _: NonZeroI8 = unsafe { NonZeroI8::new_unchecked(int_i8) }; - let _: NonZeroI16 = unsafe { NonZeroI16::new_unchecked(int_i16) }; - let _: NonZeroI32 = unsafe { NonZeroI32::new_unchecked(int_i32) }; - let _: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(int_i64) }; - let _: NonZeroI128 = unsafe { NonZeroI128::new_unchecked(int_i128) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_i8) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_i16) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_i32) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_i64) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_i128) }; } diff --git a/tests/ui/transmute_int_to_non_zero.rs b/tests/ui/transmute_int_to_non_zero.rs index a79ed5279b1f..d8e842fb99ce 100644 --- a/tests/ui/transmute_int_to_non_zero.rs +++ b/tests/ui/transmute_int_to_non_zero.rs @@ -1,7 +1,7 @@ #![warn(clippy::transmute_int_to_non_zero)] #![allow(clippy::missing_transmute_annotations)] -use core::num::*; +use core::num::NonZero; fn main() { let int_u8: u8 = 1; @@ -16,38 +16,38 @@ fn main() { let int_i64: i64 = 1; let int_i128: i128 = 1; - let _: NonZeroU8 = unsafe { std::mem::transmute(int_u8) }; - //~^ ERROR: transmute from a `u8` to a `NonZeroU8` + let _: NonZero = unsafe { std::mem::transmute(int_u8) }; + //~^ ERROR: transmute from a `u8` to a `NonZero` //~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings` - let _: NonZeroU16 = unsafe { std::mem::transmute(int_u16) }; - //~^ ERROR: transmute from a `u16` to a `NonZeroU16` - let _: NonZeroU32 = unsafe { std::mem::transmute(int_u32) }; - //~^ ERROR: transmute from a `u32` to a `NonZeroU32` - let _: NonZeroU64 = unsafe { std::mem::transmute(int_u64) }; - //~^ ERROR: transmute from a `u64` to a `NonZeroU64` - let _: NonZeroU128 = unsafe { std::mem::transmute(int_u128) }; - //~^ ERROR: transmute from a `u128` to a `NonZeroU128` + let _: NonZero = unsafe { std::mem::transmute(int_u16) }; + //~^ ERROR: transmute from a `u16` to a `NonZero` + let _: NonZero = unsafe { std::mem::transmute(int_u32) }; + //~^ ERROR: transmute from a `u32` to a `NonZero` + let _: NonZero = unsafe { std::mem::transmute(int_u64) }; + //~^ ERROR: transmute from a `u64` to a `NonZero` + let _: NonZero = unsafe { std::mem::transmute(int_u128) }; + //~^ ERROR: transmute from a `u128` to a `NonZero` - let _: NonZeroI8 = unsafe { std::mem::transmute(int_i8) }; - //~^ ERROR: transmute from a `i8` to a `NonZeroI8` - let _: NonZeroI16 = unsafe { std::mem::transmute(int_i16) }; - //~^ ERROR: transmute from a `i16` to a `NonZeroI16` - let _: NonZeroI32 = unsafe { std::mem::transmute(int_i32) }; - //~^ ERROR: transmute from a `i32` to a `NonZeroI32` - let _: NonZeroI64 = unsafe { std::mem::transmute(int_i64) }; - //~^ ERROR: transmute from a `i64` to a `NonZeroI64` - let _: NonZeroI128 = unsafe { std::mem::transmute(int_i128) }; - //~^ ERROR: transmute from a `i128` to a `NonZeroI128` + let _: NonZero = unsafe { std::mem::transmute(int_i8) }; + //~^ ERROR: transmute from a `i8` to a `NonZero` + let _: NonZero = unsafe { std::mem::transmute(int_i16) }; + //~^ ERROR: transmute from a `i16` to a `NonZero` + let _: NonZero = unsafe { std::mem::transmute(int_i32) }; + //~^ ERROR: transmute from a `i32` to a `NonZero` + let _: NonZero = unsafe { std::mem::transmute(int_i64) }; + //~^ ERROR: transmute from a `i64` to a `NonZero` + let _: NonZero = unsafe { std::mem::transmute(int_i128) }; + //~^ ERROR: transmute from a `i128` to a `NonZero` - let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) }; - let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) }; - let _: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(int_u32) }; - let _: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(int_u64) }; - let _: NonZeroU128 = unsafe { NonZeroU128::new_unchecked(int_u128) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_u8) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_u16) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_u32) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_u64) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_u128) }; - let _: NonZeroI8 = unsafe { NonZeroI8::new_unchecked(int_i8) }; - let _: NonZeroI16 = unsafe { NonZeroI16::new_unchecked(int_i16) }; - let _: NonZeroI32 = unsafe { NonZeroI32::new_unchecked(int_i32) }; - let _: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(int_i64) }; - let _: NonZeroI128 = unsafe { NonZeroI128::new_unchecked(int_i128) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_i8) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_i16) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_i32) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_i64) }; + let _: NonZero = unsafe { NonZero::new_unchecked(int_i128) }; } diff --git a/tests/ui/transmute_int_to_non_zero.stderr b/tests/ui/transmute_int_to_non_zero.stderr index bb0b0d0ff4f0..199b8ec59d09 100644 --- a/tests/ui/transmute_int_to_non_zero.stderr +++ b/tests/ui/transmute_int_to_non_zero.stderr @@ -1,65 +1,65 @@ -error: transmute from a `u8` to a `NonZeroU8` - --> tests/ui/transmute_int_to_non_zero.rs:19:33 +error: transmute from a `u8` to a `NonZero` + --> tests/ui/transmute_int_to_non_zero.rs:19:35 | -LL | let _: NonZeroU8 = unsafe { std::mem::transmute(int_u8) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU8::new_unchecked(int_u8)` +LL | let _: NonZero = unsafe { std::mem::transmute(int_u8) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u8)` | = note: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_non_zero)]` -error: transmute from a `u16` to a `NonZeroU16` - --> tests/ui/transmute_int_to_non_zero.rs:22:34 +error: transmute from a `u16` to a `NonZero` + --> tests/ui/transmute_int_to_non_zero.rs:22:36 | -LL | let _: NonZeroU16 = unsafe { std::mem::transmute(int_u16) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU16::new_unchecked(int_u16)` +LL | let _: NonZero = unsafe { std::mem::transmute(int_u16) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u16)` -error: transmute from a `u32` to a `NonZeroU32` - --> tests/ui/transmute_int_to_non_zero.rs:24:34 +error: transmute from a `u32` to a `NonZero` + --> tests/ui/transmute_int_to_non_zero.rs:24:36 | -LL | let _: NonZeroU32 = unsafe { std::mem::transmute(int_u32) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU32::new_unchecked(int_u32)` +LL | let _: NonZero = unsafe { std::mem::transmute(int_u32) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u32)` -error: transmute from a `u64` to a `NonZeroU64` - --> tests/ui/transmute_int_to_non_zero.rs:26:34 +error: transmute from a `u64` to a `NonZero` + --> tests/ui/transmute_int_to_non_zero.rs:26:36 | -LL | let _: NonZeroU64 = unsafe { std::mem::transmute(int_u64) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU64::new_unchecked(int_u64)` +LL | let _: NonZero = unsafe { std::mem::transmute(int_u64) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u64)` -error: transmute from a `u128` to a `NonZeroU128` - --> tests/ui/transmute_int_to_non_zero.rs:28:35 +error: transmute from a `u128` to a `NonZero` + --> tests/ui/transmute_int_to_non_zero.rs:28:37 | -LL | let _: NonZeroU128 = unsafe { std::mem::transmute(int_u128) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU128::new_unchecked(int_u128)` +LL | let _: NonZero = unsafe { std::mem::transmute(int_u128) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u128)` -error: transmute from a `i8` to a `NonZeroI8` - --> tests/ui/transmute_int_to_non_zero.rs:31:33 +error: transmute from a `i8` to a `NonZero` + --> tests/ui/transmute_int_to_non_zero.rs:31:35 | -LL | let _: NonZeroI8 = unsafe { std::mem::transmute(int_i8) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI8::new_unchecked(int_i8)` +LL | let _: NonZero = unsafe { std::mem::transmute(int_i8) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i8)` -error: transmute from a `i16` to a `NonZeroI16` - --> tests/ui/transmute_int_to_non_zero.rs:33:34 +error: transmute from a `i16` to a `NonZero` + --> tests/ui/transmute_int_to_non_zero.rs:33:36 | -LL | let _: NonZeroI16 = unsafe { std::mem::transmute(int_i16) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI16::new_unchecked(int_i16)` +LL | let _: NonZero = unsafe { std::mem::transmute(int_i16) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i16)` -error: transmute from a `i32` to a `NonZeroI32` - --> tests/ui/transmute_int_to_non_zero.rs:35:34 +error: transmute from a `i32` to a `NonZero` + --> tests/ui/transmute_int_to_non_zero.rs:35:36 | -LL | let _: NonZeroI32 = unsafe { std::mem::transmute(int_i32) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI32::new_unchecked(int_i32)` +LL | let _: NonZero = unsafe { std::mem::transmute(int_i32) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i32)` -error: transmute from a `i64` to a `NonZeroI64` - --> tests/ui/transmute_int_to_non_zero.rs:37:34 +error: transmute from a `i64` to a `NonZero` + --> tests/ui/transmute_int_to_non_zero.rs:37:36 | -LL | let _: NonZeroI64 = unsafe { std::mem::transmute(int_i64) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI64::new_unchecked(int_i64)` +LL | let _: NonZero = unsafe { std::mem::transmute(int_i64) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i64)` -error: transmute from a `i128` to a `NonZeroI128` - --> tests/ui/transmute_int_to_non_zero.rs:39:35 +error: transmute from a `i128` to a `NonZero` + --> tests/ui/transmute_int_to_non_zero.rs:39:37 | -LL | let _: NonZeroI128 = unsafe { std::mem::transmute(int_i128) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI128::new_unchecked(int_i128)` +LL | let _: NonZero = unsafe { std::mem::transmute(int_i128) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i128)` error: aborting due to 10 previous errors From aae0df2e8449dc615d327344e3d41a100b98c8bf Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 21 Apr 2024 21:45:18 +0200 Subject: [PATCH 1165/1222] Use generic `NonZero`. --- clippy_lints/src/transmute/eager_transmute.rs | 2 +- lintcheck/src/config.rs | 4 ++-- tests/ui/arithmetic_side_effects.rs | 8 ++++---- tests/ui/eager_transmute.fixed | 20 +++++++++---------- tests/ui/eager_transmute.rs | 20 +++++++++---------- tests/ui/eager_transmute.stderr | 18 ++++++++--------- 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/clippy_lints/src/transmute/eager_transmute.rs b/clippy_lints/src/transmute/eager_transmute.rs index c44f5150dd1a..1dfc9f7091e8 100644 --- a/clippy_lints/src/transmute/eager_transmute.rs +++ b/clippy_lints/src/transmute/eager_transmute.rs @@ -87,7 +87,7 @@ pub(super) fn check<'tcx>( && is_normalizable(cx, cx.param_env, from_ty) && is_normalizable(cx, cx.param_env, to_ty) // we only want to lint if the target type has a niche that is larger than the one of the source type - // e.g. `u8` to `NonZeroU8` should lint, but `NonZeroU8` to `u8` should not + // e.g. `u8` to `NonZero` should lint, but `NonZero` to `u8` should not && let Ok(from_layout) = cx.tcx.layout_of(cx.param_env.and(from_ty)) && let Ok(to_layout) = cx.tcx.layout_of(cx.param_env.and(to_ty)) && match (from_layout.largest_niche, to_layout.largest_niche) { diff --git a/lintcheck/src/config.rs b/lintcheck/src/config.rs index e678d40795ee..3f712f453fa0 100644 --- a/lintcheck/src/config.rs +++ b/lintcheck/src/config.rs @@ -1,5 +1,5 @@ use clap::Parser; -use std::num::NonZeroUsize; +use std::num::NonZero; use std::path::PathBuf; #[derive(Clone, Debug, Parser)] @@ -61,7 +61,7 @@ impl LintcheckConfig { config.max_jobs = if config.fix || config.recursive { 1 } else { - std::thread::available_parallelism().map_or(1, NonZeroUsize::get) + std::thread::available_parallelism().map_or(1, NonZero::get) }; }; diff --git a/tests/ui/arithmetic_side_effects.rs b/tests/ui/arithmetic_side_effects.rs index 66d71f337f2f..33a91e8bbbe5 100644 --- a/tests/ui/arithmetic_side_effects.rs +++ b/tests/ui/arithmetic_side_effects.rs @@ -15,7 +15,7 @@ extern crate proc_macro_derive; -use core::num::{NonZeroUsize, Saturating, Wrapping}; +use core::num::{NonZero, Saturating, Wrapping}; const ONE: i32 = 1; const ZERO: i32 = 0; @@ -494,15 +494,15 @@ pub fn issue_11262() { } pub fn issue_11392() { - fn example_div(unsigned: usize, nonzero_unsigned: NonZeroUsize) -> usize { + fn example_div(unsigned: usize, nonzero_unsigned: NonZero) -> usize { unsigned / nonzero_unsigned } - fn example_rem(unsigned: usize, nonzero_unsigned: NonZeroUsize) -> usize { + fn example_rem(unsigned: usize, nonzero_unsigned: NonZero) -> usize { unsigned % nonzero_unsigned } - let (unsigned, nonzero_unsigned) = (0, NonZeroUsize::new(1).unwrap()); + let (unsigned, nonzero_unsigned) = (0, NonZero::new(1).unwrap()); example_div(unsigned, nonzero_unsigned); example_rem(unsigned, nonzero_unsigned); } diff --git a/tests/ui/eager_transmute.fixed b/tests/ui/eager_transmute.fixed index c29e7dd9ab3e..ba4342462dca 100644 --- a/tests/ui/eager_transmute.fixed +++ b/tests/ui/eager_transmute.fixed @@ -2,7 +2,7 @@ #![warn(clippy::eager_transmute)] #![allow(clippy::transmute_int_to_non_zero, clippy::missing_transmute_annotations)] -use std::num::NonZeroU8; +use std::num::NonZero; #[repr(u8)] enum Opcode { @@ -85,21 +85,21 @@ macro_rules! impls { } impls!(NonMaxU8, NonZeroNonMaxU8); -fn niche_tests(v1: u8, v2: NonZeroU8, v3: NonZeroNonMaxU8) { - // u8 -> NonZeroU8, do lint - let _: Option = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) }); +fn niche_tests(v1: u8, v2: NonZero, v3: NonZeroNonMaxU8) { + // u8 -> NonZero, do lint + let _: Option> = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) }); - // NonZeroU8 -> u8, don't lint, target type has no niche and therefore a higher validity range - let _: Option = (v2 > NonZeroU8::new(1).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); + // NonZero -> u8, don't lint, target type has no niche and therefore a higher validity range + let _: Option = (v2 > NonZero::new(1u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); - // NonZeroU8 -> NonMaxU8, do lint, different niche - let _: Option = (v2 < NonZeroU8::new(255).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); + // NonZero -> NonMaxU8, do lint, different niche + let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); // NonZeroNonMaxU8 -> NonMaxU8, don't lint, target type has more validity let _: Option = (v3 < 255).then_some(unsafe { std::mem::transmute(v2) }); - // NonZeroU8 -> NonZeroNonMaxU8, do lint, target type has less validity - let _: Option = (v2 < NonZeroU8::new(255).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); + // NonZero -> NonZeroNonMaxU8, do lint, target type has less validity + let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); } fn main() {} diff --git a/tests/ui/eager_transmute.rs b/tests/ui/eager_transmute.rs index 491a9485c932..9750e87ce574 100644 --- a/tests/ui/eager_transmute.rs +++ b/tests/ui/eager_transmute.rs @@ -2,7 +2,7 @@ #![warn(clippy::eager_transmute)] #![allow(clippy::transmute_int_to_non_zero, clippy::missing_transmute_annotations)] -use std::num::NonZeroU8; +use std::num::NonZero; #[repr(u8)] enum Opcode { @@ -85,21 +85,21 @@ macro_rules! impls { } impls!(NonMaxU8, NonZeroNonMaxU8); -fn niche_tests(v1: u8, v2: NonZeroU8, v3: NonZeroNonMaxU8) { - // u8 -> NonZeroU8, do lint - let _: Option = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) }); +fn niche_tests(v1: u8, v2: NonZero, v3: NonZeroNonMaxU8) { + // u8 -> NonZero, do lint + let _: Option> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) }); - // NonZeroU8 -> u8, don't lint, target type has no niche and therefore a higher validity range - let _: Option = (v2 > NonZeroU8::new(1).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); + // NonZero -> u8, don't lint, target type has no niche and therefore a higher validity range + let _: Option = (v2 > NonZero::new(1u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); - // NonZeroU8 -> NonMaxU8, do lint, different niche - let _: Option = (v2 < NonZeroU8::new(255).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); + // NonZero -> NonMaxU8, do lint, different niche + let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); // NonZeroNonMaxU8 -> NonMaxU8, don't lint, target type has more validity let _: Option = (v3 < 255).then_some(unsafe { std::mem::transmute(v2) }); - // NonZeroU8 -> NonZeroNonMaxU8, do lint, target type has less validity - let _: Option = (v2 < NonZeroU8::new(255).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); + // NonZero -> NonZeroNonMaxU8, do lint, target type has less validity + let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); } fn main() {} diff --git a/tests/ui/eager_transmute.stderr b/tests/ui/eager_transmute.stderr index b9a4321d99ef..5cf7bd49a929 100644 --- a/tests/ui/eager_transmute.stderr +++ b/tests/ui/eager_transmute.stderr @@ -155,36 +155,36 @@ LL | (op < 4).then(|| std::mem::transmute::<_, Opcode>(op)); | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:90:60 + --> tests/ui/eager_transmute.rs:90:62 | -LL | let _: Option = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) }); - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | let _: Option> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) }); + | ^^^^^^^^^^^^^^^^^^^^^^^ | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) }); - | ~~~~ ++ +LL | let _: Option> = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) }); + | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:96:86 | -LL | let _: Option = (v2 < NonZeroU8::new(255).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); +LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (v2 < NonZeroU8::new(255).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); +LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:102:93 | -LL | let _: Option = (v2 < NonZeroU8::new(255).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); +LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (v2 < NonZeroU8::new(255).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); +LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); | ~~~~ ++ error: aborting due to 17 previous errors From 0badcfc962dedf8276a34ee2e2dca34feee2aeb3 Mon Sep 17 00:00:00 2001 From: lcnr Date: Thu, 9 May 2024 19:47:08 +0000 Subject: [PATCH 1166/1222] always use `GenericArgsRef` --- clippy_lints/src/default_union_representation.rs | 4 ++-- clippy_lints/src/needless_borrows_for_generic_args.rs | 4 ++-- clippy_utils/src/ty.rs | 8 ++++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/default_union_representation.rs b/clippy_lints/src/default_union_representation.rs index 3f87ed8df2bf..b4290b6437f2 100644 --- a/clippy_lints/src/default_union_representation.rs +++ b/clippy_lints/src/default_union_representation.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use rustc_hir::{HirId, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::layout::LayoutOf; -use rustc_middle::ty::{self, FieldDef, GenericArg, List}; +use rustc_middle::ty::{self, FieldDef}; use rustc_session::declare_lint_pass; use rustc_span::sym; @@ -85,7 +85,7 @@ fn is_union_with_two_non_zst_fields<'tcx>(cx: &LateContext<'tcx>, item: &Item<'t } } -fn is_zst<'tcx>(cx: &LateContext<'tcx>, field: &FieldDef, args: &'tcx List>) -> bool { +fn is_zst<'tcx>(cx: &LateContext<'tcx>, field: &FieldDef, args: ty::GenericArgsRef<'tcx>) -> bool { let ty = field.ty(cx.tcx, args); if let Ok(layout) = cx.layout_of(ty) { layout.is_zst() diff --git a/clippy_lints/src/needless_borrows_for_generic_args.rs b/clippy_lints/src/needless_borrows_for_generic_args.rs index a24cd4f9c8a3..e6c6a15b8d48 100644 --- a/clippy_lints/src/needless_borrows_for_generic_args.rs +++ b/clippy_lints/src/needless_borrows_for_generic_args.rs @@ -13,7 +13,7 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::{Rvalue, StatementKind}; use rustc_middle::ty::{ - self, ClauseKind, EarlyBinder, FnSig, GenericArg, GenericArgKind, List, ParamTy, ProjectionPredicate, Ty, + self, ClauseKind, EarlyBinder, FnSig, GenericArg, GenericArgKind, ParamTy, ProjectionPredicate, Ty, }; use rustc_session::impl_lint_pass; use rustc_span::symbol::sym; @@ -161,7 +161,7 @@ fn needless_borrow_count<'tcx>( cx: &LateContext<'tcx>, possible_borrowers: &mut Vec<(LocalDefId, PossibleBorrowerMap<'tcx, 'tcx>)>, fn_id: DefId, - callee_args: &'tcx List>, + callee_args: ty::GenericArgsRef<'tcx>, arg_index: usize, param_ty: ParamTy, mut expr: &Expr<'tcx>, diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 23750ed4d1ba..626d6a35307c 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -19,7 +19,7 @@ use rustc_middle::traits::EvaluationResult; use rustc_middle::ty::layout::ValidityRequirement; use rustc_middle::ty::{ self, AdtDef, AliasTy, AssocKind, Binder, BoundRegion, FnSig, GenericArg, GenericArgKind, GenericArgsRef, - GenericParamDefKind, IntTy, List, ParamEnv, Region, RegionKind, ToPredicate, TraitRef, Ty, TyCtxt, + GenericParamDefKind, IntTy, ParamEnv, Region, RegionKind, ToPredicate, TraitRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, UintTy, VariantDef, VariantDiscr, }; use rustc_span::symbol::Ident; @@ -961,7 +961,11 @@ pub struct AdtVariantInfo { impl AdtVariantInfo { /// Returns ADT variants ordered by size - pub fn new<'tcx>(cx: &LateContext<'tcx>, adt: AdtDef<'tcx>, subst: &'tcx List>) -> Vec { + pub fn new<'tcx>( + cx: &LateContext<'tcx>, + adt: AdtDef<'tcx>, + subst: GenericArgsRef<'tcx> + ) -> Vec { let mut variants_size = adt .variants() .iter() From 211911769ace61097bb3bf993cdbf2ffc700d631 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 10 May 2024 09:06:47 +1000 Subject: [PATCH 1167/1222] Use fewer origins when creating type variables. `InferCtxt::next_{ty,const}_var*` all take an origin, but the `param_def_id` is almost always `None`. This commit changes them to just take a `Span` and build the origin within the method, and adds new methods for the rare cases where `param_def_id` might not be `None`. This avoids a lot of tedious origin building. Specifically: - next_ty_var{,_id_in_universe,_in_universe}: now take `Span` instead of `TypeVariableOrigin` - next_ty_var_with_origin: added - next_const_var{,_in_universe}: takes Span instead of ConstVariableOrigin - next_const_var_with_origin: added - next_region_var, next_region_var_in_universe: these are unchanged, still take RegionVariableOrigin The API inconsistency (ty/const vs region) seems worth it for the large conciseness improvements. --- clippy_utils/src/ty.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 23750ed4d1ba..69dd3ba2970e 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -10,7 +10,6 @@ use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, FnDecl, LangItem, TyKind, Unsafety}; -use rustc_infer::infer::type_variable::TypeVariableOrigin; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::mir::interpret::Scalar; @@ -276,11 +275,7 @@ pub fn implements_trait_with_env_from_iter<'tcx>( .into_iter() .map(|arg| { arg.into().unwrap_or_else(|| { - let orig = TypeVariableOrigin { - span: DUMMY_SP, - param_def_id: None, - }; - infcx.next_ty_var(orig).into() + infcx.next_ty_var(DUMMY_SP).into() }) }) .collect::>(); From 097c69a9b006c93907b4b86da95e0c3964649750 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 9 May 2024 20:56:44 -0400 Subject: [PATCH 1168/1222] Rename Generics::params to Generics::own_params --- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/derive.rs | 2 +- clippy_lints/src/implied_bounds_in_impls.rs | 2 +- clippy_lints/src/iter_without_into_iter.rs | 2 +- clippy_lints/src/mismatching_type_param_order.rs | 2 +- clippy_utils/src/ty.rs | 6 +++--- clippy_utils/src/ty/type_certainty/mod.rs | 6 +++--- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index b936b28470b5..c6aef9ac2d60 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -382,7 +382,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> { cx, impl_ty, trait_id, - &args[..cx.tcx.generics_of(trait_id).params.len() - 1], + &args[..cx.tcx.generics_of(trait_id).own_params.len() - 1], ) { false diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 42cd19fb8eca..9662c8f4fe2f 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -480,7 +480,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> // Vec<(param_def, needs_eq)> let mut params = tcx .generics_of(did) - .params + .own_params .iter() .map(|p| (p, matches!(p.kind, GenericParamDefKind::Type { .. }))) .collect::>(); diff --git a/clippy_lints/src/implied_bounds_in_impls.rs b/clippy_lints/src/implied_bounds_in_impls.rs index 3bf8d6189558..dc935ed3d7fe 100644 --- a/clippy_lints/src/implied_bounds_in_impls.rs +++ b/clippy_lints/src/implied_bounds_in_impls.rs @@ -148,7 +148,7 @@ fn try_resolve_type<'tcx>( match args.get(index - 1) { Some(GenericArg::Type(ty)) => Some(lower_ty(tcx, ty)), Some(_) => None, - None => Some(tcx.type_of(generics.params[index].def_id).skip_binder()), + None => Some(tcx.type_of(generics.own_params[index].def_id).skip_binder()), } } diff --git a/clippy_lints/src/iter_without_into_iter.rs b/clippy_lints/src/iter_without_into_iter.rs index c749a7123303..a75dfaf286fd 100644 --- a/clippy_lints/src/iter_without_into_iter.rs +++ b/clippy_lints/src/iter_without_into_iter.rs @@ -225,7 +225,7 @@ impl {self_ty_without_ref} {{ && let ImplItemKind::Fn(sig, _) = item.kind && let FnRetTy::Return(ret) = sig.decl.output && is_nameable_in_impl_trait(ret) - && cx.tcx.generics_of(item_did).params.is_empty() + && cx.tcx.generics_of(item_did).own_params.is_empty() && sig.decl.implicit_self == expected_implicit_self && sig.decl.inputs.len() == 1 && let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id()) diff --git a/clippy_lints/src/mismatching_type_param_order.rs b/clippy_lints/src/mismatching_type_param_order.rs index 0842a8728247..934b9f490add 100644 --- a/clippy_lints/src/mismatching_type_param_order.rs +++ b/clippy_lints/src/mismatching_type_param_order.rs @@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeParamMismatch { }; // get the names of the generic parameters in the type - let type_params = &cx.tcx.generics_of(defid).params; + let type_params = &cx.tcx.generics_of(defid).own_params; let type_param_names: Vec<_> = type_params .iter() .filter_map(|p| match p.kind { diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 23750ed4d1ba..ad17c7cefff0 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -1070,11 +1070,11 @@ pub fn approx_ty_size<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> u64 { fn assert_generic_args_match<'tcx>(tcx: TyCtxt<'tcx>, did: DefId, args: &[GenericArg<'tcx>]) { let g = tcx.generics_of(did); let parent = g.parent.map(|did| tcx.generics_of(did)); - let count = g.parent_count + g.params.len(); + let count = g.parent_count + g.own_params.len(); let params = parent - .map_or([].as_slice(), |p| p.params.as_slice()) + .map_or([].as_slice(), |p| p.own_params.as_slice()) .iter() - .chain(&g.params) + .chain(&g.own_params) .map(|x| &x.kind); assert!( diff --git a/clippy_utils/src/ty/type_certainty/mod.rs b/clippy_utils/src/ty/type_certainty/mod.rs index 2241494b484a..c2ff19931d5c 100644 --- a/clippy_utils/src/ty/type_certainty/mod.rs +++ b/clippy_utils/src/ty/type_certainty/mod.rs @@ -176,7 +176,7 @@ fn qpath_certainty(cx: &LateContext<'_>, qpath: &QPath<'_>, resolves_to_type: bo .get(*lang_item) .map_or(Certainty::Uncertain, |def_id| { let generics = cx.tcx.generics_of(def_id); - if generics.parent_count == 0 && generics.params.is_empty() { + if generics.parent_count == 0 && generics.own_params.is_empty() { Certainty::Certain(if resolves_to_type { Some(def_id) } else { None }) } else { Certainty::Uncertain @@ -206,7 +206,7 @@ fn path_segment_certainty( // Checking `res_generics_def_id(..)` before calling `generics_of` avoids an ICE. if cx.tcx.res_generics_def_id(path_segment.res).is_some() { let generics = cx.tcx.generics_of(def_id); - let count = generics.params.len() - usize::from(generics.host_effect_index.is_some()); + let count = generics.own_params.len() - usize::from(generics.host_effect_index.is_some()); let lhs = if (parent_certainty.is_certain() || generics.parent_count == 0) && count == 0 { Certainty::Certain(None) } else { @@ -299,7 +299,7 @@ fn type_is_inferable_from_arguments(cx: &LateContext<'_>, expr: &Expr<'_>) -> bo let fn_sig = cx.tcx.fn_sig(callee_def_id).skip_binder(); // Check that all type parameters appear in the functions input types. - (0..(generics.parent_count + generics.params.len()) as u32).all(|index| { + (0..(generics.parent_count + generics.own_params.len()) as u32).all(|index| { Some(index as usize) == generics.host_effect_index || fn_sig .inputs() From bdbf708b07f29a812d8c645701a90ca00d5bd9ed Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 9 May 2024 22:45:14 -0400 Subject: [PATCH 1169/1222] Make builtin_deref just return a Ty --- clippy_lints/src/matches/significant_drop_in_scrutinee.rs | 8 ++++---- clippy_lints/src/operators/cmp_owned.rs | 2 +- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index 10c3203725a8..f775ea072e1f 100644 --- a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -6,7 +6,7 @@ use rustc_errors::{Applicability, Diag}; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{Arm, Expr, ExprKind, MatchSource}; use rustc_lint::{LateContext, LintContext}; -use rustc_middle::ty::{GenericArgKind, Ty, TypeAndMut}; +use rustc_middle::ty::{GenericArgKind, Ty}; use rustc_span::Span; use super::SIGNIFICANT_DROP_IN_SCRUTINEE; @@ -234,9 +234,9 @@ impl<'a, 'tcx> SigDropHelper<'a, 'tcx> { } let ty = self.sig_drop_checker.get_type(expr); if ty.is_ref() { - // We checked that the type was ref, so builtin_deref will return Some TypeAndMut, - // but let's avoid any chance of an ICE - if let Some(TypeAndMut { ty, .. }) = ty.builtin_deref(true) { + // We checked that the type was ref, so builtin_deref will return Some, + // but let's avoid any chance of an ICE. + if let Some(ty) = ty.builtin_deref(true) { if ty.is_trivially_pure_clone_copy() { self.replace_current_sig_drop(expr.span, false, LintSuggestion::MoveAndDerefToCopy); } else if allow_move_and_clone { diff --git a/clippy_lints/src/operators/cmp_owned.rs b/clippy_lints/src/operators/cmp_owned.rs index ea8ed28ba62b..208b20a7a069 100644 --- a/clippy_lints/src/operators/cmp_owned.rs +++ b/clippy_lints/src/operators/cmp_owned.rs @@ -70,7 +70,7 @@ fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool) let without_deref = symmetric_partial_eq(cx, arg_ty, other_ty).unwrap_or_default(); let with_deref = arg_ty .builtin_deref(true) - .and_then(|tam| symmetric_partial_eq(cx, tam.ty, other_ty)) + .and_then(|ty| symmetric_partial_eq(cx, ty, other_ty)) .unwrap_or_default(); if !with_deref.is_implemented() && !without_deref.is_implemented() { diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 325c9bee0578..d8d26e21369a 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -134,7 +134,7 @@ fn check_rvalue<'tcx>( ) => Err((span, "function pointer casts are not allowed in const fn".into())), Rvalue::Cast(CastKind::PointerCoercion(PointerCoercion::Unsize), op, cast_ty) => { let pointee_ty = if let Some(deref_ty) = cast_ty.builtin_deref(true) { - deref_ty.ty + deref_ty } else { // We cannot allow this for now. return Err((span, "unsizing casts are only allowed for references right now".into())); From 8087786f8e2cb0dd5188067303aa250e78954c6b Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 10 May 2024 14:59:56 -0400 Subject: [PATCH 1170/1222] Lift `TraitRef` into `rustc_type_ir` --- clippy_lints/src/future_not_send.rs | 1 + clippy_utils/src/qualify_min_const_fn.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 18f4e51ebd66..2c2daac02349 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -5,6 +5,7 @@ use rustc_hir::{Body, FnDecl}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, AliasTy, ClauseKind, PredicateKind}; +use rustc_middle::ty::print::PrintTraitRefExt; use rustc_session::declare_lint_pass; use rustc_span::def_id::LocalDefId; use rustc_span::{sym, Span}; diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index d8d26e21369a..95851a2eed81 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -402,7 +402,7 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx> tcx, ObligationCause::dummy_with_span(body.span), ConstCx::new(tcx, body).param_env, - TraitRef::from_lang_item(tcx, LangItem::Destruct, body.span, [ty]), + TraitRef::new(tcx, tcx.require_lang_item(LangItem::Destruct, Some(body.span)), [ty]), ); let infcx = tcx.infer_ctxt().build(); From 2e2a1bfe66c40e3af718189d8345fd2a2c3961fa Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 8 May 2024 13:10:50 -0400 Subject: [PATCH 1171/1222] Inline MemCategorization into ExprUseVisitor --- clippy_lints/src/operators/assign_op_pattern.rs | 4 ++-- clippy_lints/src/unwrap.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/operators/assign_op_pattern.rs b/clippy_lints/src/operators/assign_op_pattern.rs index 435eb9048f58..8effe6ab54db 100644 --- a/clippy_lints/src/operators/assign_op_pattern.rs +++ b/clippy_lints/src/operators/assign_op_pattern.rs @@ -120,7 +120,7 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet { let mut s = S(HirIdSet::default()); let infcx = cx.tcx.infer_ctxt().build(); - let mut v = ExprUseVisitor::new( + let v = ExprUseVisitor::new( &mut s, &infcx, cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()), @@ -152,7 +152,7 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet { let mut s = S(HirIdSet::default()); let infcx = cx.tcx.infer_ctxt().build(); - let mut v = ExprUseVisitor::new( + let v = ExprUseVisitor::new( &mut s, &infcx, cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()), diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 2622abd59cbd..6aec3dfa45cb 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -253,7 +253,7 @@ impl<'a, 'tcx> UnwrappableVariablesVisitor<'a, 'tcx> { }; let infcx = self.cx.tcx.infer_ctxt().build(); - let mut vis = ExprUseVisitor::new( + let vis = ExprUseVisitor::new( &mut delegate, &infcx, cond.hir_id.owner.def_id, From 8ba89c1766ddf2b7d3240770b483cd7fcb76530a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 8 May 2024 14:08:18 -0400 Subject: [PATCH 1172/1222] Make LateCtxt be a type info delegate for EUV for clippy --- clippy_lints/src/escape.rs | 4 +--- clippy_lints/src/loops/mut_range_bound.rs | 10 +++------- .../src/methods/iter_overeager_cloned.rs | 9 +++------ clippy_lints/src/needless_pass_by_ref_mut.rs | 11 ++++------- clippy_lints/src/needless_pass_by_value.rs | 4 +--- .../src/operators/assign_op_pattern.rs | 19 ++----------------- clippy_lints/src/unwrap.rs | 10 +++------- clippy_utils/src/sugg.rs | 4 +--- clippy_utils/src/usage.rs | 10 +++------- 9 files changed, 21 insertions(+), 60 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 386d4c3c317f..6392ca13df18 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -1,7 +1,6 @@ use clippy_utils::diagnostics::span_lint_hir; use rustc_hir::{intravisit, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node, Pat, PatKind}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; -use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::layout::LayoutOf; @@ -105,8 +104,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { too_large_for_stack: self.too_large_for_stack, }; - let infcx = cx.tcx.infer_ctxt().build(); - ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body); + ExprUseVisitor::for_clippy(cx, fn_def_id, &mut v).consume_body(body); for node in v.set { span_lint_hir( diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index 5047092192f4..082c5977cbde 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -4,7 +4,6 @@ use clippy_utils::{get_enclosing_block, higher, path_to_local}; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{BindingMode, Expr, ExprKind, HirId, Node, PatKind}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; -use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty; @@ -61,13 +60,10 @@ fn check_for_mutation( span_low: None, span_high: None, }; - let infcx = cx.tcx.infer_ctxt().build(); - ExprUseVisitor::new( - &mut delegate, - &infcx, + ExprUseVisitor::for_clippy( + cx, body.hir_id.owner.def_id, - cx.param_env, - cx.typeck_results(), + &mut delegate, ) .walk_expr(body); diff --git a/clippy_lints/src/methods/iter_overeager_cloned.rs b/clippy_lints/src/methods/iter_overeager_cloned.rs index deac159457a6..d4c709de97f5 100644 --- a/clippy_lints/src/methods/iter_overeager_cloned.rs +++ b/clippy_lints/src/methods/iter_overeager_cloned.rs @@ -69,14 +69,11 @@ pub(super) fn check<'tcx>( let mut delegate = MoveDelegate { used_move: HirIdSet::default(), }; - let infcx = cx.tcx.infer_ctxt().build(); - ExprUseVisitor::new( + ExprUseVisitor::for_clippy( + cx, + closure.def_id, &mut delegate, - &infcx, - closure.body.hir_id.owner.def_id, - cx.param_env, - cx.typeck_results(), ) .consume_body(body); diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index 9e47c3ad0b7f..5e786c1277ac 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -11,7 +11,6 @@ use rustc_hir::{ PatKind, }; use rustc_hir_typeck::expr_use_visitor as euv; -use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::{self, Ty, TyCtxt, UpvarId, UpvarPath}; @@ -102,7 +101,6 @@ fn should_skip<'tcx>( fn check_closures<'tcx>( ctx: &mut MutablyUsedVariablesCtxt<'tcx>, cx: &LateContext<'tcx>, - infcx: &InferCtxt<'tcx>, checked_closures: &mut FxHashSet, closures: FxHashSet, ) { @@ -119,7 +117,7 @@ fn check_closures<'tcx>( .associated_body() .map(|(_, body_id)| hir.body(body_id)) { - euv::ExprUseVisitor::new(ctx, infcx, closure, cx.param_env, cx.typeck_results()).consume_body(body); + euv::ExprUseVisitor::for_clippy(cx, closure, &mut *ctx).consume_body(body); } } } @@ -196,8 +194,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { async_closures: FxHashSet::default(), tcx: cx.tcx, }; - let infcx = cx.tcx.infer_ctxt().build(); - euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body); + euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx).consume_body(body); let mut checked_closures = FxHashSet::default(); @@ -210,13 +207,13 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { } ControlFlow::<()>::Continue(()) }); - check_closures(&mut ctx, cx, &infcx, &mut checked_closures, closures); + check_closures(&mut ctx, cx, &mut checked_closures, closures); if is_async { while !ctx.async_closures.is_empty() { let async_closures = ctx.async_closures.clone(); ctx.async_closures.clear(); - check_closures(&mut ctx, cx, &infcx, &mut checked_closures, async_closures); + check_closures(&mut ctx, cx, &mut checked_closures, async_closures); } } ctx.generate_mutably_used_ids_from_aliases() diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 39d374d0d27f..60523ae0d0e2 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -13,7 +13,6 @@ use rustc_hir::{ TyKind, }; use rustc_hir_typeck::expr_use_visitor as euv; -use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::{self, Ty, TypeVisitableExt}; @@ -134,8 +133,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { // function body. let MovedVariablesCtxt { moved_vars } = { let mut ctx = MovedVariablesCtxt::default(); - let infcx = cx.tcx.infer_ctxt().build(); - euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body); + euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx).consume_body(body); ctx }; diff --git a/clippy_lints/src/operators/assign_op_pattern.rs b/clippy_lints/src/operators/assign_op_pattern.rs index 8effe6ab54db..6d617447bb5f 100644 --- a/clippy_lints/src/operators/assign_op_pattern.rs +++ b/clippy_lints/src/operators/assign_op_pattern.rs @@ -11,7 +11,6 @@ use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, Pl use rustc_lint::LateContext; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::BorrowKind; -use rustc_trait_selection::infer::TyCtxtInferExt; use super::ASSIGN_OP_PATTERN; @@ -119,14 +118,7 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet { } let mut s = S(HirIdSet::default()); - let infcx = cx.tcx.infer_ctxt().build(); - let v = ExprUseVisitor::new( - &mut s, - &infcx, - cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()), - cx.param_env, - cx.typeck_results(), - ); + let v = ExprUseVisitor::for_clippy(cx, e.hir_id.owner.def_id, &mut s); v.consume_expr(e); s.0 } @@ -151,14 +143,7 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet { } let mut s = S(HirIdSet::default()); - let infcx = cx.tcx.infer_ctxt().build(); - let v = ExprUseVisitor::new( - &mut s, - &infcx, - cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()), - cx.param_env, - cx.typeck_results(), - ); + let v = ExprUseVisitor::for_clippy(cx, e.hir_id.owner.def_id, &mut s); v.consume_expr(e); s.0 } diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 6aec3dfa45cb..aa5555d65f63 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -6,7 +6,6 @@ use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, Visitor}; use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, Node, PathSegment, UnOp}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceWithHirId}; -use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; @@ -252,13 +251,10 @@ impl<'a, 'tcx> UnwrappableVariablesVisitor<'a, 'tcx> { local_id: unwrap_info.local_id, }; - let infcx = self.cx.tcx.infer_ctxt().build(); - let vis = ExprUseVisitor::new( - &mut delegate, - &infcx, + let vis = ExprUseVisitor::for_clippy( + self.cx, cond.hir_id.owner.def_id, - self.cx.param_env, - self.cx.typeck_results(), + &mut delegate, ); vis.walk_expr(cond); vis.walk_expr(branch); diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 8d6057272c4e..49b0eb05d2ac 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -11,7 +11,6 @@ use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::{Closure, ExprKind, HirId, MutTy, TyKind}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; -use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{EarlyContext, LateContext, LintContext}; use rustc_middle::hir::place::ProjectionKind; use rustc_middle::mir::{FakeReadCause, Mutability}; @@ -831,8 +830,7 @@ pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Opti applicability: Applicability::MachineApplicable, }; - let infcx = cx.tcx.infer_ctxt().build(); - ExprUseVisitor::new(&mut visitor, &infcx, def_id, cx.param_env, cx.typeck_results()).consume_body(closure_body); + ExprUseVisitor::for_clippy(cx, def_id, &mut visitor).consume_body(closure_body); if !visitor.suggestion_start.is_empty() { return Some(DerefClosure { diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index a145920aa85e..d0ab6d434aab 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -5,7 +5,6 @@ use hir::def::Res; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{self as hir, Expr, ExprKind, HirId, HirIdSet}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, Place, PlaceBase, PlaceWithHirId}; -use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; use rustc_middle::mir::FakeReadCause; @@ -17,13 +16,10 @@ pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) -> used_mutably: HirIdSet::default(), skip: false, }; - let infcx = cx.tcx.infer_ctxt().build(); - ExprUseVisitor::new( - &mut delegate, - &infcx, + ExprUseVisitor::for_clippy( + cx, expr.hir_id.owner.def_id, - cx.param_env, - cx.typeck_results(), + &mut delegate, ) .walk_expr(expr); From 8fa179a06b71a66c536cb4e05818b2d2bba3613c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 9 May 2024 11:33:53 -0400 Subject: [PATCH 1173/1222] Propagate errors rather than using return_if_err --- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/lib.rs | 1 + clippy_lints/src/loops/mut_range_bound.rs | 2 +- clippy_lints/src/methods/iter_overeager_cloned.rs | 3 +-- clippy_lints/src/needless_pass_by_ref_mut.rs | 4 ++-- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/operators/assign_op_pattern.rs | 4 ++-- clippy_lints/src/unwrap.rs | 4 ++-- clippy_utils/src/lib.rs | 1 + clippy_utils/src/sugg.rs | 4 +++- clippy_utils/src/usage.rs | 3 ++- 11 files changed, 17 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 6392ca13df18..6715de52649d 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -104,7 +104,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { too_large_for_stack: self.too_large_for_stack, }; - ExprUseVisitor::for_clippy(cx, fn_def_id, &mut v).consume_body(body); + ExprUseVisitor::for_clippy(cx, fn_def_id, &mut v).consume_body(body).into_ok(); for node in v.set { span_lint_hir( diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 2c44c3881aa7..a8bfbbdd9eca 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -8,6 +8,7 @@ #![feature(never_type)] #![feature(rustc_private)] #![feature(stmt_expr_attributes)] +#![feature(unwrap_infallible)] #![recursion_limit = "512"] #![cfg_attr(feature = "deny-warnings", deny(warnings))] #![allow( diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index 082c5977cbde..6b9ecf5f1413 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -65,7 +65,7 @@ fn check_for_mutation( body.hir_id.owner.def_id, &mut delegate, ) - .walk_expr(body); + .walk_expr(body).into_ok(); delegate.mutation_span() } diff --git a/clippy_lints/src/methods/iter_overeager_cloned.rs b/clippy_lints/src/methods/iter_overeager_cloned.rs index d4c709de97f5..a52d38790a2b 100644 --- a/clippy_lints/src/methods/iter_overeager_cloned.rs +++ b/clippy_lints/src/methods/iter_overeager_cloned.rs @@ -9,7 +9,6 @@ use rustc_lint::LateContext; use rustc_middle::mir::{FakeReadCause, Mutability}; use rustc_middle::ty::{self, BorrowKind}; use rustc_span::sym; -use rustc_trait_selection::infer::TyCtxtInferExt; use super::ITER_OVEREAGER_CLONED; use crate::redundant_clone::REDUNDANT_CLONE; @@ -75,7 +74,7 @@ pub(super) fn check<'tcx>( closure.def_id, &mut delegate, ) - .consume_body(body); + .consume_body(body).into_ok(); let mut to_be_discarded = false; diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index 5e786c1277ac..9b852f52ea1e 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -117,7 +117,7 @@ fn check_closures<'tcx>( .associated_body() .map(|(_, body_id)| hir.body(body_id)) { - euv::ExprUseVisitor::for_clippy(cx, closure, &mut *ctx).consume_body(body); + euv::ExprUseVisitor::for_clippy(cx, closure, &mut *ctx).consume_body(body).into_ok(); } } } @@ -194,7 +194,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { async_closures: FxHashSet::default(), tcx: cx.tcx, }; - euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx).consume_body(body); + euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx).consume_body(body).into_ok(); let mut checked_closures = FxHashSet::default(); diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 60523ae0d0e2..0986571d0f28 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -133,7 +133,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { // function body. let MovedVariablesCtxt { moved_vars } = { let mut ctx = MovedVariablesCtxt::default(); - euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx).consume_body(body); + euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx).consume_body(body).into_ok(); ctx }; diff --git a/clippy_lints/src/operators/assign_op_pattern.rs b/clippy_lints/src/operators/assign_op_pattern.rs index 6d617447bb5f..910e584a7a0f 100644 --- a/clippy_lints/src/operators/assign_op_pattern.rs +++ b/clippy_lints/src/operators/assign_op_pattern.rs @@ -119,7 +119,7 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet { let mut s = S(HirIdSet::default()); let v = ExprUseVisitor::for_clippy(cx, e.hir_id.owner.def_id, &mut s); - v.consume_expr(e); + v.consume_expr(e).into_ok(); s.0 } @@ -144,6 +144,6 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet { let mut s = S(HirIdSet::default()); let v = ExprUseVisitor::for_clippy(cx, e.hir_id.owner.def_id, &mut s); - v.consume_expr(e); + v.consume_expr(e).into_ok(); s.0 } diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index aa5555d65f63..5b2841dcd833 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -256,8 +256,8 @@ impl<'a, 'tcx> UnwrappableVariablesVisitor<'a, 'tcx> { cond.hir_id.owner.def_id, &mut delegate, ); - vis.walk_expr(cond); - vis.walk_expr(branch); + vis.walk_expr(cond).into_ok(); + vis.walk_expr(branch).into_ok(); if delegate.is_mutated { // if the variable is mutated, we don't know whether it can be unwrapped. diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index a49414a058b1..99d7aba2f7a1 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -7,6 +7,7 @@ #![feature(never_type)] #![feature(rustc_private)] #![feature(assert_matches)] +#![feature(unwrap_infallible)] #![recursion_limit = "512"] #![cfg_attr(feature = "deny-warnings", deny(warnings))] #![allow( diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 49b0eb05d2ac..bf03c6c16015 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -830,7 +830,9 @@ pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Opti applicability: Applicability::MachineApplicable, }; - ExprUseVisitor::for_clippy(cx, def_id, &mut visitor).consume_body(closure_body); + ExprUseVisitor::for_clippy(cx, def_id, &mut visitor) + .consume_body(closure_body) + .into_ok(); if !visitor.suggestion_start.is_empty() { return Some(DerefClosure { diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index d0ab6d434aab..9abb4ef9b8d3 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -21,7 +21,8 @@ pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) -> expr.hir_id.owner.def_id, &mut delegate, ) - .walk_expr(expr); + .walk_expr(expr) + .into_ok(); if delegate.skip { return None; From bba3ed6fd75c93d8bf2afe3d330001029b1b9039 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 13 May 2024 10:00:38 -0400 Subject: [PATCH 1174/1222] split out AliasTy -> AliasTerm --- clippy_lints/src/methods/unnecessary_to_owned.rs | 2 +- .../src/needless_borrows_for_generic_args.rs | 13 +++++-------- clippy_lints/src/unit_return_expecting_ord.rs | 2 +- clippy_utils/src/ty.rs | 4 ++-- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index d3347466be98..ae9aa83efd68 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -417,7 +417,7 @@ fn get_input_traits_and_projections<'tcx>( } }, ClauseKind::Projection(projection_predicate) => { - if projection_predicate.projection_ty.self_ty() == input { + if projection_predicate.projection_term.self_ty() == input { projection_predicates.push(projection_predicate); } }, diff --git a/clippy_lints/src/needless_borrows_for_generic_args.rs b/clippy_lints/src/needless_borrows_for_generic_args.rs index e6c6a15b8d48..8de5caf32b74 100644 --- a/clippy_lints/src/needless_borrows_for_generic_args.rs +++ b/clippy_lints/src/needless_borrows_for_generic_args.rs @@ -320,11 +320,11 @@ fn is_mixed_projection_predicate<'tcx>( && (term_param_ty.index as usize) < generics.parent_count { // The inner-most self type is a type parameter from the current function. - let mut projection_ty = projection_predicate.projection_ty; + let mut projection_ty = projection_predicate.projection_term; loop { - match projection_ty.self_ty().kind() { + match *projection_ty.self_ty().kind() { ty::Alias(ty::Projection, inner_projection_ty) => { - projection_ty = *inner_projection_ty; + projection_ty = inner_projection_ty.into(); }, ty::Param(param_ty) => { return (param_ty.index as usize) >= generics.parent_count; @@ -404,14 +404,11 @@ fn replace_types<'tcx>( // The `replaced.insert(...)` check provides some protection against infinite loops. if replaced.insert(param_ty.index) { for projection_predicate in projection_predicates { - if projection_predicate.projection_ty.self_ty() == param_ty.to_ty(cx.tcx) + if projection_predicate.projection_term.self_ty() == param_ty.to_ty(cx.tcx) && let Some(term_ty) = projection_predicate.term.ty() && let ty::Param(term_param_ty) = term_ty.kind() { - let projection = cx.tcx.mk_ty_from_kind(ty::Alias( - ty::Projection, - projection_predicate.projection_ty.with_self_ty(cx.tcx, new_ty), - )); + let projection = projection_predicate.projection_term.with_self_ty(cx.tcx, new_ty).expect_ty(cx.tcx).to_ty(cx.tcx); if let Ok(projected_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, projection) && args[term_param_ty.index as usize] != GenericArg::from(projected_ty) diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 214b69dc9250..f0d1458a59b2 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -66,7 +66,7 @@ fn get_projection_pred<'tcx>( let projection_pred = cx .tcx .instantiate_bound_regions_with_erased(proj_pred.kind().rebind(pred)); - if projection_pred.projection_ty.args == trait_pred.trait_ref.args { + if projection_pred.projection_term.args == trait_pred.trait_ref.args { return Some(projection_pred); } } diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 97bba8648c5f..e3ab42c3107c 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -795,7 +795,7 @@ fn sig_from_bounds<'tcx>( inputs = Some(i); }, ty::ClauseKind::Projection(p) - if Some(p.projection_ty.def_id) == lang_items.fn_once_output() && p.projection_ty.self_ty() == ty => + if Some(p.projection_term.def_id) == lang_items.fn_once_output() && p.projection_term.self_ty() == ty => { if output.is_some() { // Multiple different fn trait impls. Is this even allowed? @@ -834,7 +834,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option } inputs = Some(i); }, - ty::ClauseKind::Projection(p) if Some(p.projection_ty.def_id) == lang_items.fn_once_output() => { + ty::ClauseKind::Projection(p) if Some(p.projection_term.def_id) == lang_items.fn_once_output() => { if output.is_some() { // Multiple different fn trait impls. Is this even allowed? return None; From ca22afb05311f6cb4a17ed366adf24b1e008f206 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 13 May 2024 14:34:47 -0400 Subject: [PATCH 1175/1222] Apply nits --- clippy_lints/src/needless_borrows_for_generic_args.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/needless_borrows_for_generic_args.rs b/clippy_lints/src/needless_borrows_for_generic_args.rs index 8de5caf32b74..ae6cf992ef7b 100644 --- a/clippy_lints/src/needless_borrows_for_generic_args.rs +++ b/clippy_lints/src/needless_borrows_for_generic_args.rs @@ -320,11 +320,11 @@ fn is_mixed_projection_predicate<'tcx>( && (term_param_ty.index as usize) < generics.parent_count { // The inner-most self type is a type parameter from the current function. - let mut projection_ty = projection_predicate.projection_term; + let mut projection_term = projection_predicate.projection_term; loop { - match *projection_ty.self_ty().kind() { + match *projection_term.self_ty().kind() { ty::Alias(ty::Projection, inner_projection_ty) => { - projection_ty = inner_projection_ty.into(); + projection_term = inner_projection_ty.into(); }, ty::Param(param_ty) => { return (param_ty.index as usize) >= generics.parent_count; From 4047db92e3ee93c2adc8cff3bed91ea40f8673e9 Mon Sep 17 00:00:00 2001 From: Jakob Schwarz Date: Wed, 15 May 2024 15:07:34 +0200 Subject: [PATCH 1176/1222] fulfill expectations in `check_unsafe_derive_deserialize` The utility function `clippy_utils::fulfill_or_allowed` is not used because using it would require to move the check for allowed after the check iterating over all inherent impls of the type, doing possibly unnecessary work. Instead, `is_lint_allowed` is called as before, but additionally, once certain that the lint should be emitted, `span_lint_hir_and_then` is called instead of `span_lint_and_help` to also fulfill expectations. fixes: #12802 changelog: fulfill expectations in `check_unsafe_derive_deserialize` --- .cargo/config.toml | 18 - .editorconfig | 22 - .gitattributes | 3 - .github/ISSUE_TEMPLATE/blank_issue.yml | 44 - .github/ISSUE_TEMPLATE/bug_report.yml | 57 - .github/ISSUE_TEMPLATE/config.yml | 5 - .github/ISSUE_TEMPLATE/false_negative.yml | 50 - .github/ISSUE_TEMPLATE/false_positive.yml | 68 - .github/ISSUE_TEMPLATE/ice.yml | 48 - .github/ISSUE_TEMPLATE/new_lint.yml | 48 - .github/PULL_REQUEST_TEMPLATE.md | 39 - .github/deploy.sh | 67 - .github/driver.sh | 61 - .github/workflows/clippy.yml | 74 - .github/workflows/clippy_bors.yml | 251 - .github/workflows/clippy_dev.yml | 71 - .github/workflows/deploy.yml | 66 - .github/workflows/remark.yml | 72 - .gitignore | 47 - .remarkrc | 13 - CHANGELOG.md | 6010 ----------------- CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 280 - COPYRIGHT | 11 - Cargo.toml | 65 - LICENSE-APACHE | 201 - LICENSE-MIT | 27 - README.md | 289 - book/README.md | 4 - book/book.toml | 28 - book/src/README.md | 44 - book/src/SUMMARY.md | 35 - book/src/configuration.md | 143 - book/src/continuous_integration/README.md | 18 - .../continuous_integration/github_actions.md | 21 - book/src/continuous_integration/gitlab.md | 16 - book/src/continuous_integration/travis.md | 20 - book/src/development/README.md | 65 - book/src/development/adding_lints.md | 796 --- book/src/development/basics.md | 193 - .../development/common_tools_writing_lints.md | 274 - book/src/development/defining_lints.md | 204 - book/src/development/emitting_lints.md | 217 - book/src/development/infrastructure/README.md | 19 - .../development/infrastructure/backport.md | 72 - book/src/development/infrastructure/book.md | 42 - .../infrastructure/changelog_update.md | 117 - .../src/development/infrastructure/release.md | 142 - book/src/development/infrastructure/sync.md | 121 - book/src/development/lint_passes.md | 114 - book/src/development/macro_expansions.md | 158 - book/src/development/method_checking.md | 93 - book/src/development/proposals/README.md | 11 - .../src/development/proposals/roadmap-2021.md | 235 - .../proposals/syntax-tree-patterns.md | 986 --- book/src/development/speedtest.md | 20 - book/src/development/the_team.md | 130 - book/src/development/trait_checking.md | 155 - book/src/development/type_checking.md | 167 - book/src/development/writing_tests.md | 218 - book/src/installation.md | 24 - book/src/lint_configuration.md | 934 --- book/src/lints.md | 105 - book/src/usage.md | 152 - build.rs | 7 - clippy.toml | 10 - clippy_config/Cargo.toml | 21 - clippy_config/src/conf.rs | 916 --- clippy_config/src/lib.rs | 31 - clippy_config/src/metadata.rs | 121 - clippy_config/src/msrvs.rs | 157 - clippy_config/src/types.rs | 134 - clippy_dev/Cargo.toml | 21 - clippy_dev/src/dogfood.rs | 31 - clippy_dev/src/fmt.rs | 226 - clippy_dev/src/lib.rs | 84 - clippy_dev/src/lint.rs | 44 - clippy_dev/src/main.rs | 293 - clippy_dev/src/new_lint.rs | 591 -- clippy_dev/src/serve.rs | 65 - clippy_dev/src/setup/git_hook.rs | 82 - clippy_dev/src/setup/intellij.rs | 209 - clippy_dev/src/setup/mod.rs | 24 - clippy_dev/src/setup/toolchain.rs | 75 - clippy_dev/src/setup/vscode.rs | 95 - clippy_dev/src/update_lints.rs | 1210 ---- clippy_dummy/Cargo.toml | 16 - clippy_dummy/PUBLISH.md | 6 - clippy_dummy/build.rs | 42 - clippy_dummy/crates-readme.md | 9 - clippy_dummy/src/main.rs | 3 - clippy_lints/Cargo.toml | 41 - clippy_lints/README.md | 1 - clippy_lints/src/absolute_paths.rs | 100 - clippy_lints/src/allow_attributes.rs | 73 - clippy_lints/src/almost_complete_range.rs | 101 - clippy_lints/src/approx_const.rs | 135 - clippy_lints/src/arc_with_non_send_sync.rs | 86 - clippy_lints/src/as_conversions.rs | 65 - clippy_lints/src/asm_syntax.rs | 160 - clippy_lints/src/assertions_on_constants.rs | 83 - .../src/assertions_on_result_states.rs | 100 - clippy_lints/src/assigning_clones.rs | 362 - clippy_lints/src/async_yields_async.rs | 117 - .../attrs/allow_attributes_without_reason.rs | 37 - .../attrs/blanket_clippy_restriction_lints.rs | 44 - clippy_lints/src/attrs/deprecated_cfg_attr.rs | 87 - clippy_lints/src/attrs/deprecated_semver.rs | 20 - .../src/attrs/duplicated_attributes.rs | 76 - clippy_lints/src/attrs/empty_line_after.rs | 52 - clippy_lints/src/attrs/inline_always.rs | 29 - clippy_lints/src/attrs/maybe_misused_cfg.rs | 51 - .../src/attrs/mismatched_target_os.rs | 90 - .../src/attrs/mixed_attributes_style.rs | 85 - clippy_lints/src/attrs/mod.rs | 638 -- clippy_lints/src/attrs/non_minimal_cfg.rs | 49 - .../src/attrs/should_panic_without_expect.rs | 54 - .../src/attrs/unnecessary_clippy_cfg.rs | 70 - clippy_lints/src/attrs/useless_attribute.rs | 88 - clippy_lints/src/attrs/utils.rs | 87 - clippy_lints/src/await_holding_invalid.rs | 296 - clippy_lints/src/blocks_in_conditions.rs | 153 - clippy_lints/src/bool_assert_comparison.rs | 147 - clippy_lints/src/bool_to_int_with_if.rs | 127 - clippy_lints/src/booleans.rs | 615 -- clippy_lints/src/borrow_deref_ref.rs | 112 - clippy_lints/src/box_default.rs | 133 - clippy_lints/src/cargo/common_metadata.rs | 54 - clippy_lints/src/cargo/feature_name.rs | 90 - .../src/cargo/lint_groups_priority.rs | 179 - clippy_lints/src/cargo/mod.rs | 266 - .../src/cargo/multiple_crate_versions.rs | 77 - .../src/cargo/wildcard_dependencies.rs | 24 - clippy_lints/src/casts/as_ptr_cast_mut.rs | 37 - clippy_lints/src/casts/as_underscore.rs | 25 - clippy_lints/src/casts/borrow_as_ptr.rs | 47 - .../src/casts/cast_abs_to_unsigned.rs | 43 - .../src/casts/cast_enum_constructor.rs | 21 - clippy_lints/src/casts/cast_lossless.rs | 121 - clippy_lints/src/casts/cast_nan_to_int.rs | 28 - .../src/casts/cast_possible_truncation.rs | 201 - clippy_lints/src/casts/cast_possible_wrap.rs | 89 - clippy_lints/src/casts/cast_precision_loss.rs | 51 - clippy_lints/src/casts/cast_ptr_alignment.rs | 96 - clippy_lints/src/casts/cast_sign_loss.rs | 339 - .../src/casts/cast_slice_different_sizes.rs | 136 - .../src/casts/cast_slice_from_raw_parts.rs | 55 - clippy_lints/src/casts/char_lit_as_u8.rs | 39 - clippy_lints/src/casts/fn_to_numeric_cast.rs | 37 - .../src/casts/fn_to_numeric_cast_any.rs | 34 - .../fn_to_numeric_cast_with_truncation.rs | 36 - clippy_lints/src/casts/mod.rs | 810 --- clippy_lints/src/casts/ptr_as_ptr.rs | 101 - clippy_lints/src/casts/ptr_cast_constness.rs | 44 - clippy_lints/src/casts/ref_as_ptr.rs | 63 - clippy_lints/src/casts/unnecessary_cast.rs | 302 - clippy_lints/src/casts/utils.rs | 75 - clippy_lints/src/casts/zero_ptr.rs | 39 - clippy_lints/src/checked_conversions.rs | 324 - clippy_lints/src/cognitive_complexity.rs | 167 - clippy_lints/src/collapsible_if.rs | 202 - clippy_lints/src/collection_is_never_read.rs | 160 - clippy_lints/src/comparison_chain.rs | 136 - clippy_lints/src/copies.rs | 637 -- clippy_lints/src/copy_iterator.rs | 58 - clippy_lints/src/crate_in_macro_def.rs | 128 - clippy_lints/src/create_dir.rs | 51 - clippy_lints/src/dbg_macro.rs | 134 - clippy_lints/src/declared_lints.rs | 764 --- clippy_lints/src/default.rs | 294 - .../src/default_constructed_unit_structs.rs | 85 - .../src/default_instead_of_iter_empty.rs | 81 - clippy_lints/src/default_numeric_fallback.rs | 258 - .../src/default_union_representation.rs | 110 - clippy_lints/src/deprecated_lints.rs | 217 - clippy_lints/src/dereference.rs | 1191 ---- clippy_lints/src/derivable_impls.rs | 215 - clippy_lints/src/derive.rs | 511 -- clippy_lints/src/disallowed_macros.rs | 182 - clippy_lints/src/disallowed_methods.rs | 108 - clippy_lints/src/disallowed_names.rs | 78 - clippy_lints/src/disallowed_script_idents.rs | 112 - clippy_lints/src/disallowed_types.rs | 137 - clippy_lints/src/doc/lazy_continuation.rs | 95 - clippy_lints/src/doc/link_with_quotes.rs | 20 - clippy_lints/src/doc/markdown.rs | 135 - clippy_lints/src/doc/missing_headers.rs | 85 - clippy_lints/src/doc/mod.rs | 871 --- clippy_lints/src/doc/needless_doctest_main.rs | 135 - .../src/doc/suspicious_doc_comments.rs | 48 - clippy_lints/src/double_parens.rs | 74 - clippy_lints/src/drop_forget_ref.rs | 152 - clippy_lints/src/duplicate_mod.rs | 128 - clippy_lints/src/else_if_without_else.rs | 70 - clippy_lints/src/empty_drop.rs | 64 - clippy_lints/src/empty_enum.rs | 67 - clippy_lints/src/empty_with_brackets.rs | 152 - clippy_lints/src/endian_bytes.rs | 214 - clippy_lints/src/entry.rs | 699 -- clippy_lints/src/enum_clike.rs | 81 - clippy_lints/src/equatable_if_let.rs | 120 - clippy_lints/src/error_impl_error.rs | 89 - clippy_lints/src/escape.rs | 192 - clippy_lints/src/eta_reduction.rs | 311 - clippy_lints/src/excessive_bools.rs | 182 - clippy_lints/src/excessive_nesting.rs | 180 - clippy_lints/src/exhaustive_items.rs | 100 - clippy_lints/src/exit.rs | 57 - clippy_lints/src/explicit_write.rs | 137 - .../src/extra_unused_type_parameters.rs | 292 - clippy_lints/src/fallible_impl_from.rs | 130 - clippy_lints/src/float_literal.rs | 191 - clippy_lints/src/floating_point_arithmetic.rs | 782 --- clippy_lints/src/format.rs | 130 - clippy_lints/src/format_args.rs | 507 -- clippy_lints/src/format_impl.rs | 277 - clippy_lints/src/format_push_string.rs | 94 - clippy_lints/src/formatting.rs | 326 - clippy_lints/src/four_forward_slashes.rs | 99 - clippy_lints/src/from_over_into.rs | 233 - clippy_lints/src/from_raw_with_void_ptr.rs | 84 - clippy_lints/src/from_str_radix_10.rs | 93 - .../src/functions/impl_trait_in_params.rs | 86 - .../src/functions/misnamed_getters.rs | 117 - clippy_lints/src/functions/mod.rs | 489 -- clippy_lints/src/functions/must_use.rs | 268 - .../src/functions/not_unsafe_ptr_arg_deref.rs | 98 - .../src/functions/renamed_function_params.rs | 110 - clippy_lints/src/functions/result.rs | 145 - .../src/functions/too_many_arguments.rs | 65 - clippy_lints/src/functions/too_many_lines.rs | 83 - clippy_lints/src/future_not_send.rs | 112 - clippy_lints/src/if_let_mutex.rs | 138 - clippy_lints/src/if_not_else.rs | 100 - clippy_lints/src/if_then_some_else_none.rs | 128 - clippy_lints/src/ignored_unit_patterns.rs | 67 - .../impl_hash_with_borrow_str_and_bytes.rs | 106 - clippy_lints/src/implicit_hasher.rs | 380 -- clippy_lints/src/implicit_return.rs | 249 - clippy_lints/src/implicit_saturating_add.rs | 141 - clippy_lints/src/implicit_saturating_sub.rs | 155 - clippy_lints/src/implied_bounds_in_impls.rs | 353 - clippy_lints/src/incompatible_msrv.rs | 139 - .../src/inconsistent_struct_constructor.rs | 132 - clippy_lints/src/index_refutable_slice.rs | 268 - clippy_lints/src/indexing_slicing.rs | 232 - clippy_lints/src/ineffective_open_options.rs | 95 - clippy_lints/src/infinite_iter.rs | 267 - clippy_lints/src/inherent_impl.rs | 142 - clippy_lints/src/inherent_to_string.rs | 151 - clippy_lints/src/init_numbered_fields.rs | 81 - clippy_lints/src/inline_fn_without_body.rs | 60 - clippy_lints/src/instant_subtraction.rs | 161 - clippy_lints/src/int_plus_one.rs | 168 - .../src/integer_division_remainder_used.rs | 50 - .../src/invalid_upcast_comparisons.rs | 159 - clippy_lints/src/item_name_repetitions.rs | 461 -- clippy_lints/src/items_after_statements.rs | 89 - clippy_lints/src/items_after_test_module.rs | 109 - .../src/iter_not_returning_iterator.rs | 91 - clippy_lints/src/iter_over_hash_type.rs | 78 - clippy_lints/src/iter_without_into_iter.rs | 298 - clippy_lints/src/large_const_arrays.rs | 85 - clippy_lints/src/large_enum_variant.rs | 177 - clippy_lints/src/large_futures.rs | 82 - clippy_lints/src/large_include_file.rs | 84 - clippy_lints/src/large_stack_arrays.rs | 118 - clippy_lints/src/large_stack_frames.rs | 220 - clippy_lints/src/legacy_numeric_constants.rs | 293 - clippy_lints/src/len_zero.rs | 649 -- clippy_lints/src/let_if_seq.rs | 172 - clippy_lints/src/let_underscore.rs | 224 - clippy_lints/src/let_with_type_underscore.rs | 51 - clippy_lints/src/lib.deprecated.rs | 70 - clippy_lints/src/lib.rs | 1227 ---- clippy_lints/src/lifetimes.rs | 708 -- clippy_lints/src/lines_filter_map_ok.rs | 119 - clippy_lints/src/literal_representation.rs | 527 -- clippy_lints/src/loops/empty_loop.rs | 18 - .../src/loops/explicit_counter_loop.rs | 86 - .../src/loops/explicit_into_iter_loop.rs | 90 - clippy_lints/src/loops/explicit_iter_loop.rs | 252 - clippy_lints/src/loops/for_kv_map.rs | 56 - clippy_lints/src/loops/infinite_loop.rs | 130 - clippy_lints/src/loops/iter_next_loop.rs | 18 - clippy_lints/src/loops/manual_find.rs | 154 - clippy_lints/src/loops/manual_flatten.rs | 70 - clippy_lints/src/loops/manual_memcpy.rs | 490 -- .../src/loops/manual_while_let_some.rs | 107 - clippy_lints/src/loops/missing_spin_loop.rs | 60 - clippy_lints/src/loops/mod.rs | 814 --- clippy_lints/src/loops/mut_range_bound.rs | 162 - clippy_lints/src/loops/needless_range_loop.rs | 379 -- clippy_lints/src/loops/never_loop.rs | 299 - clippy_lints/src/loops/same_item_push.rs | 186 - clippy_lints/src/loops/single_element_loop.rs | 115 - .../src/loops/unused_enumerate_index.rs | 42 - clippy_lints/src/loops/utils.rs | 292 - .../src/loops/while_immutable_condition.rs | 124 - clippy_lints/src/loops/while_let_loop.rs | 103 - .../src/loops/while_let_on_iterator.rs | 352 - clippy_lints/src/macro_metavars_in_unsafe.rs | 256 - clippy_lints/src/macro_use.rs | 211 - clippy_lints/src/main_recursion.rs | 60 - clippy_lints/src/manual_assert.rs | 89 - clippy_lints/src/manual_async_fn.rs | 197 - clippy_lints/src/manual_bits.rs | 150 - clippy_lints/src/manual_clamp.rs | 759 --- clippy_lints/src/manual_float_methods.rs | 171 - clippy_lints/src/manual_hash_one.rs | 132 - clippy_lints/src/manual_is_ascii_check.rs | 212 - clippy_lints/src/manual_let_else.rs | 379 -- clippy_lints/src/manual_main_separator_str.rs | 74 - clippy_lints/src/manual_non_exhaustive.rs | 215 - clippy_lints/src/manual_range_patterns.rs | 163 - clippy_lints/src/manual_rem_euclid.rs | 128 - clippy_lints/src/manual_retain.rs | 289 - .../src/manual_slice_size_calculation.rs | 103 - clippy_lints/src/manual_string_new.rs | 132 - clippy_lints/src/manual_strip.rs | 255 - clippy_lints/src/manual_unwrap_or_default.rs | 179 - clippy_lints/src/map_unit_fn.rs | 266 - clippy_lints/src/match_result_ok.rs | 85 - clippy_lints/src/matches/collapsible_match.rs | 147 - .../matches/infallible_destructuring_match.rs | 42 - clippy_lints/src/matches/manual_filter.rs | 166 - clippy_lints/src/matches/manual_map.rs | 116 - clippy_lints/src/matches/manual_unwrap_or.rs | 71 - clippy_lints/src/matches/manual_utils.rs | 276 - clippy_lints/src/matches/match_as_ref.rs | 80 - clippy_lints/src/matches/match_bool.rs | 77 - .../src/matches/match_like_matches.rs | 178 - .../src/matches/match_on_vec_items.rs | 50 - clippy_lints/src/matches/match_ref_pats.rs | 82 - clippy_lints/src/matches/match_same_arms.rs | 449 -- .../src/matches/match_single_binding.rs | 218 - .../src/matches/match_str_case_mismatch.rs | 118 - clippy_lints/src/matches/match_wild_enum.rs | 201 - .../src/matches/match_wild_err_arm.rs | 55 - clippy_lints/src/matches/mod.rs | 1212 ---- clippy_lints/src/matches/needless_match.rs | 213 - clippy_lints/src/matches/overlapping_arms.rs | 186 - clippy_lints/src/matches/redundant_guards.rs | 279 - .../src/matches/redundant_pattern_match.rs | 529 -- .../matches/rest_pat_in_fully_bound_struct.rs | 27 - .../matches/significant_drop_in_scrutinee.rs | 407 -- clippy_lints/src/matches/single_match.rs | 237 - clippy_lints/src/matches/try_err.rs | 130 - clippy_lints/src/matches/wild_in_or_pats.rs | 24 - clippy_lints/src/mem_replace.rs | 244 - .../src/methods/bind_instead_of_map.rs | 180 - clippy_lints/src/methods/bytecount.rs | 66 - .../src/methods/bytes_count_to_len.rs | 36 - clippy_lints/src/methods/bytes_nth.rs | 50 - ...se_sensitive_file_extension_comparisons.rs | 80 - clippy_lints/src/methods/chars_cmp.rs | 48 - .../src/methods/chars_cmp_with_unwrap.rs | 41 - clippy_lints/src/methods/chars_last_cmp.rs | 13 - .../src/methods/chars_last_cmp_with_unwrap.rs | 13 - clippy_lints/src/methods/chars_next_cmp.rs | 8 - .../src/methods/chars_next_cmp_with_unwrap.rs | 8 - clippy_lints/src/methods/clear_with_drain.rs | 52 - clippy_lints/src/methods/clone_on_copy.rs | 105 - clippy_lints/src/methods/clone_on_ref_ptr.rs | 47 - .../src/methods/cloned_instead_of_copied.rs | 45 - .../src/methods/collapsible_str_replace.rs | 95 - clippy_lints/src/methods/drain_collect.rs | 79 - clippy_lints/src/methods/err_expect.rs | 49 - clippy_lints/src/methods/expect_fun_call.rs | 169 - clippy_lints/src/methods/extend_with_drain.rs | 42 - clippy_lints/src/methods/filetype_is_file.rs | 38 - clippy_lints/src/methods/filter_map.rs | 445 -- .../src/methods/filter_map_bool_then.rs | 62 - .../src/methods/filter_map_identity.rs | 34 - clippy_lints/src/methods/filter_map_next.rs | 42 - clippy_lints/src/methods/filter_next.rs | 73 - clippy_lints/src/methods/flat_map_identity.rs | 28 - clippy_lints/src/methods/flat_map_option.rs | 34 - clippy_lints/src/methods/format_collect.rs | 39 - .../methods/from_iter_instead_of_collect.rs | 81 - clippy_lints/src/methods/get_first.rs | 54 - clippy_lints/src/methods/get_last_with_len.rs | 53 - clippy_lints/src/methods/get_unwrap.rs | 81 - clippy_lints/src/methods/implicit_clone.rs | 60 - .../src/methods/inefficient_to_string.rs | 69 - clippy_lints/src/methods/inspect_for_each.rs | 23 - clippy_lints/src/methods/into_iter_on_ref.rs | 49 - .../src/methods/is_digit_ascii_radix.rs | 48 - clippy_lints/src/methods/is_empty.rs | 49 - .../src/methods/iter_cloned_collect.rs | 29 - clippy_lints/src/methods/iter_count.rs | 48 - clippy_lints/src/methods/iter_filter.rs | 197 - clippy_lints/src/methods/iter_kv_map.rs | 80 - clippy_lints/src/methods/iter_next_slice.rs | 80 - clippy_lints/src/methods/iter_nth.rs | 44 - clippy_lints/src/methods/iter_nth_zero.rs | 31 - .../iter_on_single_or_empty_collections.rs | 88 - .../src/methods/iter_out_of_bounds.rs | 106 - .../src/methods/iter_overeager_cloned.rs | 162 - clippy_lints/src/methods/iter_skip_next.rs | 43 - clippy_lints/src/methods/iter_skip_zero.rs | 34 - clippy_lints/src/methods/iter_with_drain.rs | 29 - .../src/methods/iterator_step_by_zero.rs | 21 - .../src/methods/join_absolute_paths.rs | 52 - .../src/methods/manual_c_str_literals.rs | 197 - .../src/methods/manual_is_variant_and.rs | 59 - clippy_lints/src/methods/manual_next_back.rs | 38 - clippy_lints/src/methods/manual_ok_or.rs | 59 - .../methods/manual_saturating_arithmetic.rs | 154 - clippy_lints/src/methods/manual_str_repeat.rs | 95 - clippy_lints/src/methods/manual_try_fold.rs | 52 - clippy_lints/src/methods/map_clone.rs | 194 - .../src/methods/map_collect_result_unit.rs | 35 - clippy_lints/src/methods/map_err_ignore.rs | 34 - clippy_lints/src/methods/map_flatten.rs | 71 - clippy_lints/src/methods/map_identity.rs | 37 - clippy_lints/src/methods/map_unwrap_or.rs | 77 - clippy_lints/src/methods/mod.rs | 5233 -------------- clippy_lints/src/methods/mut_mutex_lock.rs | 29 - clippy_lints/src/methods/needless_collect.rs | 517 -- .../src/methods/needless_option_as_deref.rs | 39 - .../src/methods/needless_option_take.rs | 41 - clippy_lints/src/methods/no_effect_replace.rs | 42 - .../src/methods/obfuscated_if_else.rs | 41 - clippy_lints/src/methods/ok_expect.rs | 35 - clippy_lints/src/methods/open_options.rs | 206 - .../src/methods/option_as_ref_cloned.rs | 24 - .../src/methods/option_as_ref_deref.rs | 113 - .../src/methods/option_map_or_err_ok.rs | 41 - .../src/methods/option_map_or_none.rs | 105 - .../src/methods/option_map_unwrap_or.rs | 182 - clippy_lints/src/methods/or_fun_call.rs | 243 - clippy_lints/src/methods/or_then_unwrap.rs | 69 - .../src/methods/path_buf_push_overwrite.rs | 34 - .../src/methods/path_ends_with_ext.rs | 52 - .../src/methods/range_zip_with_len.rs | 33 - .../src/methods/read_line_without_trim.rs | 124 - .../src/methods/readonly_write_lock.rs | 62 - clippy_lints/src/methods/redundant_as_str.rs | 33 - clippy_lints/src/methods/repeat_once.rs | 51 - .../src/methods/result_map_or_else_none.rs | 42 - clippy_lints/src/methods/search_is_some.rs | 168 - clippy_lints/src/methods/seek_from_current.rs | 52 - .../seek_to_start_instead_of_rewind.rs | 50 - .../src/methods/single_char_add_str.rs | 14 - .../src/methods/single_char_insert_string.rs | 28 - .../src/methods/single_char_pattern.rs | 64 - .../src/methods/single_char_push_string.rs | 27 - clippy_lints/src/methods/skip_while_next.rs | 22 - .../src/methods/stable_sort_primitive.rs | 31 - clippy_lints/src/methods/str_split.rs | 38 - clippy_lints/src/methods/str_splitn.rs | 366 - .../src/methods/string_extend_chars.rs | 46 - .../src/methods/string_lit_chars_any.rs | 58 - .../methods/suspicious_command_arg_space.rs | 34 - clippy_lints/src/methods/suspicious_map.rs | 31 - clippy_lints/src/methods/suspicious_splitn.rs | 42 - .../src/methods/suspicious_to_owned.rs | 47 - clippy_lints/src/methods/type_id_on_box.rs | 88 - .../src/methods/uninit_assumed_init.rs | 24 - clippy_lints/src/methods/unit_hash.rs | 29 - .../unnecessary_fallible_conversions.rs | 199 - .../src/methods/unnecessary_filter_map.rs | 115 - clippy_lints/src/methods/unnecessary_fold.rs | 182 - .../src/methods/unnecessary_get_then_check.rs | 85 - .../src/methods/unnecessary_iter_cloned.rs | 145 - clippy_lints/src/methods/unnecessary_join.rs | 40 - .../src/methods/unnecessary_lazy_eval.rs | 78 - .../src/methods/unnecessary_literal_unwrap.rs | 143 - .../methods/unnecessary_result_map_or_else.rs | 95 - .../src/methods/unnecessary_sort_by.rs | 241 - .../src/methods/unnecessary_to_owned.rs | 679 -- .../src/methods/unused_enumerate_index.rs | 134 - .../src/methods/unwrap_expect_used.rs | 83 - clippy_lints/src/methods/useless_asref.rs | 170 - clippy_lints/src/methods/utils.rs | 173 - .../src/methods/vec_resize_to_zero.rs | 48 - .../src/methods/verbose_file_reads.rs | 28 - clippy_lints/src/methods/waker_clone_wake.rs | 32 - .../src/methods/wrong_self_convention.rs | 153 - clippy_lints/src/methods/zst_offset.rs | 15 - clippy_lints/src/min_ident_chars.rs | 198 - clippy_lints/src/minmax.rs | 125 - clippy_lints/src/misc.rs | 269 - .../src/misc_early/builtin_type_shadow.rs | 19 - clippy_lints/src/misc_early/double_neg.rs | 18 - clippy_lints/src/misc_early/literal_suffix.rs | 36 - .../src/misc_early/mixed_case_hex_literals.rs | 32 - clippy_lints/src/misc_early/mod.rs | 454 -- .../misc_early/redundant_at_rest_pattern.rs | 26 - .../src/misc_early/redundant_pattern.rs | 25 - .../src/misc_early/unneeded_field_pattern.rs | 73 - .../misc_early/unneeded_wildcard_pattern.rs | 52 - .../src/misc_early/zero_prefixed_literal.rs | 33 - .../src/mismatching_type_param_order.rs | 120 - clippy_lints/src/missing_assert_message.rs | 92 - .../src/missing_asserts_for_indexing.rs | 416 -- clippy_lints/src/missing_const_for_fn.rs | 178 - clippy_lints/src/missing_doc.rs | 273 - .../src/missing_enforced_import_rename.rs | 106 - clippy_lints/src/missing_fields_in_debug.rs | 234 - clippy_lints/src/missing_inline.rs | 170 - clippy_lints/src/missing_trait_methods.rs | 100 - .../src/mixed_read_write_in_expression.rs | 368 - clippy_lints/src/module_style.rs | 177 - clippy_lints/src/multi_assignments.rs | 65 - clippy_lints/src/multiple_bound_locations.rs | 84 - .../src/multiple_unsafe_ops_per_block.rs | 181 - clippy_lints/src/mut_key.rs | 147 - clippy_lints/src/mut_mut.rs | 110 - clippy_lints/src/mut_reference.rs | 102 - clippy_lints/src/mutable_debug_assertion.rs | 121 - clippy_lints/src/mutex_atomic.rs | 133 - .../src/needless_arbitrary_self_type.rs | 134 - clippy_lints/src/needless_bool.rs | 451 -- clippy_lints/src/needless_borrowed_ref.rs | 156 - .../src/needless_borrows_for_generic_args.rs | 392 -- clippy_lints/src/needless_continue.rs | 474 -- clippy_lints/src/needless_else.rs | 61 - clippy_lints/src/needless_for_each.rs | 165 - clippy_lints/src/needless_if.rs | 78 - clippy_lints/src/needless_late_init.rs | 360 - .../src/needless_parens_on_range_literals.rs | 87 - clippy_lints/src/needless_pass_by_ref_mut.rs | 530 -- clippy_lints/src/needless_pass_by_value.rs | 330 - clippy_lints/src/needless_question_mark.rs | 139 - clippy_lints/src/needless_update.rs | 70 - clippy_lints/src/neg_cmp_op_on_partial_ord.rs | 84 - clippy_lints/src/neg_multiply.rs | 76 - clippy_lints/src/new_without_default.rs | 172 - clippy_lints/src/no_effect.rs | 376 -- clippy_lints/src/no_mangle_with_rust_abi.rs | 70 - clippy_lints/src/non_canonical_impls.rs | 298 - clippy_lints/src/non_copy_const.rs | 504 -- clippy_lints/src/non_expressive_names.rs | 443 -- .../src/non_octal_unix_permissions.rs | 93 - .../src/non_send_fields_in_send_ty.rs | 251 - clippy_lints/src/nonstandard_macro_braces.rs | 153 - clippy_lints/src/octal_escapes.rs | 155 - clippy_lints/src/only_used_in_recursion.rs | 396 -- .../operators/absurd_extreme_comparisons.rs | 141 - .../src/operators/arithmetic_side_effects.rs | 380 -- .../src/operators/assign_op_pattern.rs | 164 - clippy_lints/src/operators/bit_mask.rs | 173 - clippy_lints/src/operators/cmp_owned.rs | 147 - .../src/operators/const_comparisons.rs | 207 - .../src/operators/double_comparison.rs | 53 - clippy_lints/src/operators/duration_subsec.rs | 43 - clippy_lints/src/operators/eq_op.rs | 54 - clippy_lints/src/operators/erasing_op.rs | 53 - clippy_lints/src/operators/float_cmp.rs | 129 - .../operators/float_equality_without_abs.rs | 65 - clippy_lints/src/operators/identity_op.rs | 251 - .../src/operators/integer_division.rs | 27 - .../src/operators/misrefactored_assign_op.rs | 78 - clippy_lints/src/operators/mod.rs | 886 --- .../src/operators/modulo_arithmetic.rs | 147 - clippy_lints/src/operators/modulo_one.rs | 26 - .../src/operators/needless_bitwise_bool.rs | 36 - .../src/operators/numeric_arithmetic.rs | 100 - clippy_lints/src/operators/op_ref.rs | 211 - clippy_lints/src/operators/ptr_eq.rs | 62 - clippy_lints/src/operators/self_assignment.rs | 20 - .../src/operators/verbose_bit_mask.rs | 45 - clippy_lints/src/option_env_unwrap.rs | 64 - clippy_lints/src/option_if_let_else.rs | 317 - .../src/overflow_check_conditional.rs | 70 - clippy_lints/src/panic_in_result_fn.rs | 95 - clippy_lints/src/panic_unimplemented.rs | 123 - clippy_lints/src/partial_pub_fields.rs | 81 - clippy_lints/src/partialeq_ne_impl.rs | 58 - clippy_lints/src/partialeq_to_none.rs | 103 - clippy_lints/src/pass_by_ref_or_value.rs | 315 - clippy_lints/src/pattern_type_mismatch.rs | 195 - .../src/permissions_set_readonly_false.rs | 54 - clippy_lints/src/precedence.rs | 159 - clippy_lints/src/ptr.rs | 751 -- clippy_lints/src/ptr_offset_with_cast.rs | 151 - clippy_lints/src/pub_underscore_fields.rs | 85 - clippy_lints/src/pub_use.rs | 57 - clippy_lints/src/question_mark.rs | 390 -- clippy_lints/src/question_mark_used.rs | 52 - clippy_lints/src/ranges.rs | 526 -- clippy_lints/src/raw_strings.rs | 197 - clippy_lints/src/rc_clone_in_vec_init.rs | 143 - clippy_lints/src/read_zero_byte_vec.rs | 176 - clippy_lints/src/redundant_async_block.rs | 119 - clippy_lints/src/redundant_clone.rs | 377 -- clippy_lints/src/redundant_closure_call.rs | 286 - clippy_lints/src/redundant_else.rs | 140 - clippy_lints/src/redundant_field_names.rs | 83 - clippy_lints/src/redundant_locals.rs | 130 - clippy_lints/src/redundant_pub_crate.rs | 98 - clippy_lints/src/redundant_slicing.rs | 159 - .../src/redundant_static_lifetimes.rs | 117 - .../src/redundant_type_annotations.rs | 220 - clippy_lints/src/ref_option_ref.rs | 66 - clippy_lints/src/ref_patterns.rs | 44 - clippy_lints/src/reference.rs | 108 - clippy_lints/src/regex.rs | 229 - clippy_lints/src/renamed_lints.rs | 63 - clippy_lints/src/repeat_vec_with_capacity.rs | 113 - .../src/reserve_after_initialization.rs | 149 - clippy_lints/src/return_self_not_must_use.rs | 128 - clippy_lints/src/returns.rs | 477 -- clippy_lints/src/same_name_method.rs | 163 - clippy_lints/src/self_named_constructors.rs | 88 - clippy_lints/src/semicolon_block.rs | 182 - .../src/semicolon_if_nothing_returned.rs | 71 - clippy_lints/src/serde_api.rs | 60 - clippy_lints/src/shadow.rs | 250 - .../src/significant_drop_tightening.rs | 471 -- clippy_lints/src/single_call_fn.rs | 145 - .../src/single_char_lifetime_names.rs | 63 - .../src/single_component_path_imports.rs | 246 - clippy_lints/src/single_range_in_vec_init.rs | 149 - clippy_lints/src/size_of_in_element_count.rs | 138 - clippy_lints/src/size_of_ref.rs | 75 - .../src/slow_vector_initialization.rs | 340 - clippy_lints/src/std_instead_of_core.rs | 172 - clippy_lints/src/strings.rs | 516 -- clippy_lints/src/strlen_on_c_strings.rs | 84 - .../src/suspicious_operation_groupings.rs | 660 -- clippy_lints/src/suspicious_trait_impl.rs | 110 - .../src/suspicious_xor_used_as_pow.rs | 55 - clippy_lints/src/swap.rs | 450 -- clippy_lints/src/swap_ptr_to_ref.rs | 88 - clippy_lints/src/tabs_in_doc_comments.rs | 230 - clippy_lints/src/temporary_assignment.rs | 44 - clippy_lints/src/tests_outside_test_module.rs | 72 - ...ead_local_initializer_can_be_made_const.rs | 153 - clippy_lints/src/to_digit_is_some.rs | 94 - clippy_lints/src/to_string_trait_impl.rs | 70 - clippy_lints/src/trailing_empty_array.rs | 71 - clippy_lints/src/trait_bounds.rs | 479 -- .../src/transmute/crosspointer_transmute.rs | 31 - clippy_lints/src/transmute/eager_transmute.rs | 119 - .../missing_transmute_annotations.rs | 87 - clippy_lints/src/transmute/mod.rs | 635 -- .../src/transmute/transmute_float_to_int.rs | 62 - .../src/transmute/transmute_int_to_bool.rs | 42 - .../src/transmute/transmute_int_to_char.rs | 47 - .../src/transmute/transmute_int_to_float.rs | 48 - .../transmute/transmute_int_to_non_zero.rs | 73 - .../src/transmute/transmute_null_to_fn.rs | 70 - .../src/transmute/transmute_num_to_bytes.rs | 49 - .../src/transmute/transmute_ptr_to_ptr.rs | 36 - .../src/transmute/transmute_ptr_to_ref.rs | 80 - .../src/transmute/transmute_ref_to_ref.rs | 74 - .../src/transmute/transmute_undefined_repr.rs | 331 - .../transmutes_expressible_as_ptr_casts.rs | 62 - .../src/transmute/transmuting_null.rs | 50 - .../transmute/unsound_collection_transmute.rs | 49 - .../src/transmute/useless_transmute.rs | 67 - clippy_lints/src/transmute/utils.rs | 17 - clippy_lints/src/transmute/wrong_transmute.rs | 22 - clippy_lints/src/tuple_array_conversions.rs | 207 - clippy_lints/src/types/borrowed_box.rs | 109 - clippy_lints/src/types/box_collection.rs | 59 - clippy_lints/src/types/linked_list.rs | 23 - clippy_lints/src/types/mod.rs | 599 -- clippy_lints/src/types/option_option.rs | 26 - clippy_lints/src/types/rc_buffer.rs | 104 - clippy_lints/src/types/rc_mutex.rs | 28 - .../src/types/redundant_allocation.rs | 107 - clippy_lints/src/types/type_complexity.rs | 78 - clippy_lints/src/types/utils.rs | 19 - clippy_lints/src/types/vec_box.rs | 78 - clippy_lints/src/unconditional_recursion.rs | 447 -- .../src/undocumented_unsafe_blocks.rs | 713 -- clippy_lints/src/unicode.rs | 149 - clippy_lints/src/uninhabited_references.rs | 84 - clippy_lints/src/uninit_vec.rs | 223 - clippy_lints/src/unit_return_expecting_ord.rs | 181 - clippy_lints/src/unit_types/let_unit_value.rs | 233 - clippy_lints/src/unit_types/mod.rs | 110 - clippy_lints/src/unit_types/unit_arg.rs | 197 - clippy_lints/src/unit_types/unit_cmp.rs | 51 - clippy_lints/src/unit_types/utils.rs | 5 - clippy_lints/src/unnamed_address.rs | 60 - clippy_lints/src/unnecessary_box_returns.rs | 139 - .../src/unnecessary_map_on_constructor.rs | 100 - .../src/unnecessary_owned_empty_strings.rs | 75 - clippy_lints/src/unnecessary_self_imports.rs | 70 - .../src/unnecessary_struct_initialization.rs | 91 - clippy_lints/src/unnecessary_wraps.rs | 170 - clippy_lints/src/unnested_or_patterns.rs | 441 -- clippy_lints/src/unsafe_removed_from_name.rs | 76 - clippy_lints/src/unused_async.rs | 194 - clippy_lints/src/unused_io_amount.rs | 315 - clippy_lints/src/unused_peekable.rs | 229 - clippy_lints/src/unused_rounding.rs | 65 - clippy_lints/src/unused_self.rs | 94 - clippy_lints/src/unused_unit.rs | 149 - clippy_lints/src/unwrap.rs | 415 -- clippy_lints/src/unwrap_in_result.rs | 116 - clippy_lints/src/upper_case_acronyms.rs | 133 - clippy_lints/src/use_self.rs | 359 - clippy_lints/src/useless_conversion.rs | 384 -- clippy_lints/src/utils/author.rs | 789 --- clippy_lints/src/utils/dump_hir.rs | 64 - .../src/utils/format_args_collector.rs | 112 - clippy_lints/src/utils/internal_lints.rs | 12 - .../almost_standard_lint_formulation.rs | 87 - .../utils/internal_lints/collapsible_calls.rs | 241 - .../internal_lints/compiler_lint_functions.rs | 73 - .../interning_defined_symbol.rs | 241 - .../src/utils/internal_lints/invalid_paths.rs | 102 - .../internal_lints/lint_without_lint_pass.rs | 342 - .../internal_lints/metadata_collector.rs | 1089 --- .../utils/internal_lints/msrv_attr_impl.rs | 61 - .../internal_lints/outer_expn_data_pass.rs | 59 - .../src/utils/internal_lints/produce_ice.rs | 37 - .../internal_lints/unnecessary_def_path.rs | 301 - .../unsorted_clippy_utils_paths.rs | 49 - clippy_lints/src/utils/mod.rs | 5 - clippy_lints/src/vec.rs | 250 - clippy_lints/src/vec_init_then_push.rs | 225 - clippy_lints/src/visibility.rs | 135 - clippy_lints/src/wildcard_imports.rs | 219 - clippy_lints/src/write.rs | 686 -- clippy_lints/src/zero_div_zero.rs | 60 - clippy_lints/src/zero_repeat_side_effects.rs | 154 - clippy_lints/src/zero_sized_map_values.rs | 95 - clippy_utils/Cargo.toml | 18 - clippy_utils/src/ast_utils.rs | 842 --- clippy_utils/src/ast_utils/ident_iter.rs | 45 - clippy_utils/src/attrs.rs | 203 - clippy_utils/src/check_proc_macro.rs | 442 -- clippy_utils/src/comparisons.rs | 36 - clippy_utils/src/consts.rs | 907 --- clippy_utils/src/diagnostics.rs | 355 - clippy_utils/src/eager_or_lazy.rs | 333 - clippy_utils/src/higher.rs | 480 -- clippy_utils/src/hir_utils.rs | 1189 ---- clippy_utils/src/lib.rs | 3371 --------- clippy_utils/src/macros.rs | 550 -- clippy_utils/src/mir/mod.rs | 201 - clippy_utils/src/mir/possible_borrower.rs | 243 - clippy_utils/src/mir/possible_origin.rs | 59 - clippy_utils/src/mir/transitive_relation.rs | 29 - clippy_utils/src/numeric_literal.rs | 247 - clippy_utils/src/paths.rs | 114 - clippy_utils/src/ptr.rs | 52 - clippy_utils/src/qualify_min_const_fn.rs | 427 -- clippy_utils/src/source.rs | 598 -- clippy_utils/src/str_utils.rs | 378 -- clippy_utils/src/sugg.rs | 1118 --- clippy_utils/src/sym_helper.rs | 7 - clippy_utils/src/ty.rs | 1338 ---- .../src/ty/type_certainty/certainty.rs | 122 - clippy_utils/src/ty/type_certainty/mod.rs | 322 - clippy_utils/src/usage.rs | 210 - clippy_utils/src/visitors.rs | 791 --- declare_clippy_lint/Cargo.toml | 16 - declare_clippy_lint/src/lib.rs | 167 - etc/relicense/RELICENSE_DOCUMENTATION.md | 69 - etc/relicense/contributors.txt | 232 - etc/relicense/relicense_comments.txt | 227 - lintcheck/Cargo.toml | 38 - lintcheck/README.md | 106 - lintcheck/lintcheck_crates.toml | 43 - lintcheck/src/config.rs | 80 - lintcheck/src/driver.rs | 67 - lintcheck/src/main.rs | 875 --- lintcheck/src/popular-crates.rs | 65 - lintcheck/src/recursive.rs | 122 - lintcheck/test_sources.toml | 4 - rust-toolchain | 3 - rustc_tools_util/CHANGELOG.md | 6 - rustc_tools_util/Cargo.toml | 15 - rustc_tools_util/LICENSE-APACHE | 1 - rustc_tools_util/LICENSE-MIT | 1 - rustc_tools_util/README.md | 62 - rustc_tools_util/src/lib.rs | 180 - rustfmt.toml | 9 - src/driver.rs | 323 - src/main.rs | 219 - tests/check-fmt.rs | 28 - tests/clippy.toml | 1 - tests/compile-test.rs | 358 - tests/dogfood.rs | 130 - tests/headers.rs | 34 - tests/integration.rs | 125 - tests/lint_message_convention.rs | 118 - tests/missing-test-files.rs | 69 - tests/test_utils/mod.rs | 13 - .../cargo_common_metadata/fail/Cargo.stderr | 16 - .../cargo_common_metadata/fail/Cargo.toml | 6 - .../cargo_common_metadata/fail/clippy.toml | 1 - .../cargo_common_metadata/fail/src/main.rs | 3 - .../fail_publish/Cargo.stderr | 16 - .../fail_publish/Cargo.toml | 6 - .../fail_publish/src/main.rs | 3 - .../fail_publish_true/Cargo.stderr | 16 - .../fail_publish_true/Cargo.toml | 6 - .../fail_publish_true/src/main.rs | 3 - .../cargo_common_metadata/pass/Cargo.toml | 12 - .../cargo_common_metadata/pass/clippy.toml | 1 - .../cargo_common_metadata/pass/src/main.rs | 3 - .../pass_publish_empty/Cargo.toml | 6 - .../pass_publish_empty/src/main.rs | 3 - .../pass_publish_false/Cargo.toml | 6 - .../pass_publish_false/src/main.rs | 3 - .../fail_both_diff/Cargo.stderr | 21 - .../fail_both_diff/Cargo.toml | 9 - .../fail_both_diff/clippy.toml | 1 - .../fail_both_diff/src/main.rs | 11 - .../fail_both_same/Cargo.stderr | 19 - .../fail_both_same/Cargo.toml | 9 - .../fail_both_same/clippy.toml | 1 - .../fail_both_same/src/main.rs | 11 - .../fail_cargo/Cargo.stderr | 19 - .../cargo_rust_version/fail_cargo/Cargo.toml | 9 - .../cargo_rust_version/fail_cargo/src/main.rs | 11 - .../fail_clippy/Cargo.stderr | 19 - .../cargo_rust_version/fail_clippy/Cargo.toml | 8 - .../fail_clippy/clippy.toml | 1 - .../fail_clippy/src/main.rs | 11 - .../fail_file_attr/Cargo.stderr | 19 - .../fail_file_attr/Cargo.toml | 9 - .../fail_file_attr/clippy.toml | 1 - .../fail_file_attr/src/main.rs | 16 - .../pass_both_same/Cargo.toml | 9 - .../pass_both_same/clippy.toml | 1 - .../pass_both_same/src/main.rs | 11 - .../cargo_rust_version/pass_cargo/Cargo.toml | 9 - .../cargo_rust_version/pass_cargo/src/main.rs | 11 - .../cargo_rust_version/pass_clippy/Cargo.toml | 8 - .../pass_clippy/clippy.toml | 1 - .../pass_clippy/src/main.rs | 11 - .../pass_file_attr/Cargo.toml | 9 - .../pass_file_attr/src/main.rs | 13 - .../warn_both_diff/Cargo.stderr | 2 - .../warn_both_diff/Cargo.toml | 9 - .../warn_both_diff/clippy.toml | 1 - .../warn_both_diff/src/main.rs | 11 - .../ui-cargo/duplicate_mod/fail/Cargo.stderr | 53 - tests/ui-cargo/duplicate_mod/fail/Cargo.toml | 5 - tests/ui-cargo/duplicate_mod/fail/src/a.rs | 1 - tests/ui-cargo/duplicate_mod/fail/src/b.rs | 1 - tests/ui-cargo/duplicate_mod/fail/src/c.rs | 1 - tests/ui-cargo/duplicate_mod/fail/src/d.rs | 1 - .../fail/src/from_other_module.rs | 1 - tests/ui-cargo/duplicate_mod/fail/src/main.rs | 28 - .../fail/src/other_module/mod.rs | 2 - tests/ui-cargo/feature_name/fail/Cargo.stderr | 45 - tests/ui-cargo/feature_name/fail/Cargo.toml | 21 - tests/ui-cargo/feature_name/fail/src/main.rs | 6 - tests/ui-cargo/feature_name/pass/Cargo.toml | 9 - tests/ui-cargo/feature_name/pass/src/main.rs | 6 - .../lint_groups_priority/fail/Cargo.stderr | 73 - .../lint_groups_priority/fail/Cargo.toml | 28 - .../lint_groups_priority/fail/src/lib.rs | 1 - .../lint_groups_priority/pass/Cargo.toml | 10 - .../lint_groups_priority/pass/src/lib.rs | 1 - .../module_style/fail_mod/Cargo.stderr | 19 - .../ui-cargo/module_style/fail_mod/Cargo.toml | 9 - .../module_style/fail_mod/src/bad/inner.rs | 1 - .../fail_mod/src/bad/inner/stuff.rs | 3 - .../fail_mod/src/bad/inner/stuff/most.rs | 1 - .../module_style/fail_mod/src/bad/mod.rs | 3 - .../module_style/fail_mod/src/main.rs | 9 - .../module_style/fail_mod_remap/Cargo.stderr | 11 - .../module_style/fail_mod_remap/Cargo.toml | 9 - .../module_style/fail_mod_remap/src/bad.rs | 1 - .../fail_mod_remap/src/bad/inner.rs | 1 - .../module_style/fail_mod_remap/src/main.rs | 8 - .../module_style/fail_no_mod/Cargo.stderr | 11 - .../module_style/fail_no_mod/Cargo.toml | 9 - .../module_style/fail_no_mod/src/bad/mod.rs | 1 - .../module_style/fail_no_mod/src/main.rs | 7 - .../ui-cargo/module_style/pass_mod/Cargo.toml | 9 - .../module_style/pass_mod/src/bad/mod.rs | 1 - .../module_style/pass_mod/src/main.rs | 10 - .../module_style/pass_mod/src/more/foo.rs | 1 - .../pass_mod/src/more/inner/mod.rs | 1 - .../module_style/pass_mod/src/more/mod.rs | 2 - .../module_style/pass_no_mod/Cargo.toml | 9 - .../module_style/pass_no_mod/src/good.rs | 1 - .../module_style/pass_no_mod/src/main.rs | 7 - .../multiple_config_files/no_warn/Cargo.toml | 9 - .../multiple_config_files/no_warn/clippy.toml | 1 - .../multiple_config_files/no_warn/src/main.rs | 3 - .../multiple_config_files/warn/.clippy.toml | 1 - .../multiple_config_files/warn/Cargo.stderr | 2 - .../multiple_config_files/warn/Cargo.toml | 9 - .../multiple_config_files/warn/clippy.toml | 1 - .../multiple_config_files/warn/src/main.rs | 3 - .../12145_with_dashes/Cargo.stderr | 6 - .../12145_with_dashes/Cargo.toml | 14 - .../12145_with_dashes/src/main.rs | 3 - .../12176_allow_duplicate_crates/Cargo.toml | 10 - .../12176_allow_duplicate_crates/clippy.toml | 1 - .../12176_allow_duplicate_crates/src/main.rs | 3 - .../5041_allow_dev_build/Cargo.toml | 19 - .../5041_allow_dev_build/src/main.rs | 3 - .../multiple_crate_versions/fail/Cargo.lock | 48 - .../multiple_crate_versions/fail/Cargo.stderr | 6 - .../multiple_crate_versions/fail/Cargo.toml | 10 - .../multiple_crate_versions/fail/src/main.rs | 3 - .../multiple_crate_versions/pass/Cargo.toml | 10 - .../multiple_crate_versions/pass/src/main.rs | 3 - tests/ui-cargo/update-all-references.sh | 3 - .../wildcard_dependencies/fail/Cargo.stderr | 6 - .../wildcard_dependencies/fail/Cargo.toml | 9 - .../wildcard_dependencies/fail/src/main.rs | 3 - .../wildcard_dependencies/pass/Cargo.toml | 9 - .../wildcard_dependencies/pass/src/main.rs | 3 - tests/ui-internal/auxiliary/paths.rs | 2 - .../check_clippy_version_attribute.rs | 87 - .../check_clippy_version_attribute.stderr | 68 - tests/ui-internal/check_formulation.rs | 54 - tests/ui-internal/check_formulation.stderr | 20 - .../collapsible_span_lint_calls.fixed | 56 - .../collapsible_span_lint_calls.rs | 66 - .../collapsible_span_lint_calls.stderr | 49 - tests/ui-internal/custom_ice_message.rs | 14 - tests/ui-internal/custom_ice_message.stderr | 16 - .../ui-internal/default_deprecation_reason.rs | 30 - .../default_deprecation_reason.stderr | 22 - tests/ui-internal/default_lint.rs | 28 - tests/ui-internal/default_lint.stderr | 21 - tests/ui-internal/disallow_span_lint.rs | 21 - tests/ui-internal/disallow_span_lint.stderr | 20 - .../interning_defined_symbol.fixed | 36 - tests/ui-internal/interning_defined_symbol.rs | 36 - .../interning_defined_symbol.stderr | 33 - .../ui-internal/invalid_msrv_attr_impl.fixed | 38 - tests/ui-internal/invalid_msrv_attr_impl.rs | 36 - .../ui-internal/invalid_msrv_attr_impl.stderr | 32 - tests/ui-internal/invalid_paths.rs | 27 - tests/ui-internal/invalid_paths.stderr | 23 - tests/ui-internal/lint_without_lint_pass.rs | 45 - .../ui-internal/lint_without_lint_pass.stderr | 21 - tests/ui-internal/outer_expn_data.fixed | 27 - tests/ui-internal/outer_expn_data.rs | 27 - tests/ui-internal/outer_expn_data.stderr | 15 - tests/ui-internal/unnecessary_def_path.fixed | 61 - tests/ui-internal/unnecessary_def_path.rs | 61 - tests/ui-internal/unnecessary_def_path.stderr | 101 - .../unnecessary_def_path_hardcoded_path.rs | 16 - ...unnecessary_def_path_hardcoded_path.stderr | 28 - .../ui-internal/unnecessary_symbol_str.fixed | 20 - tests/ui-internal/unnecessary_symbol_str.rs | 20 - .../ui-internal/unnecessary_symbol_str.stderr | 39 - .../absolute_paths.allow_crates.stderr | 29 - .../absolute_paths.disallow_crates.stderr | 71 - .../ui-toml/absolute_paths/absolute_paths.rs | 97 - .../absolute_paths/allow_crates/clippy.toml | 2 - .../absolute_paths/auxiliary/helper.rs | 11 - .../disallow_crates/clippy.toml | 1 - .../clippy.toml | 1 - .../uninlined_format_args.fixed | 14 - .../uninlined_format_args.rs | 14 - .../uninlined_format_args.stderr | 78 - .../arithmetic_side_effects_allowed.rs | 119 - .../arithmetic_side_effects_allowed.stderr | 59 - .../clippy.toml | 11 - .../array_size_threshold.rs | 10 - .../array_size_threshold.stderr | 31 - .../ui-toml/array_size_threshold/clippy.toml | 1 - .../await_holding_invalid_type.rs | 43 - .../await_holding_invalid_type.stderr | 26 - .../await_holding_invalid_type/clippy.toml | 4 - tests/ui-toml/bad_toml/clippy.toml | 2 - tests/ui-toml/bad_toml/conf_bad_toml.rs | 3 - tests/ui-toml/bad_toml/conf_bad_toml.stderr | 8 - tests/ui-toml/bad_toml_type/clippy.toml | 1 - tests/ui-toml/bad_toml_type/conf_bad_type.rs | 3 - .../bad_toml_type/conf_bad_type.stderr | 8 - .../borrow_interior_mutable_const/clippy.toml | 1 - .../borrow_interior_mutable_const/ignore.rs | 37 - tests/ui-toml/conf_deprecated_key/clippy.toml | 7 - .../conf_deprecated_key.rs | 13 - .../conf_deprecated_key.stderr | 24 - tests/ui-toml/dbg_macro/clippy.toml | 1 - tests/ui-toml/dbg_macro/dbg_macro.fixed | 38 - tests/ui-toml/dbg_macro/dbg_macro.rs | 38 - tests/ui-toml/dbg_macro/dbg_macro.stderr | 81 - .../clippy.toml | 1 - .../decimal_literal_representation.fixed | 6 - .../decimal_literal_representation.rs | 6 - .../decimal_literal_representation.stderr | 11 - .../clippy.toml | 1 - .../declare_interior_mutable_const/ignore.rs | 46 - .../disallowed_macros/auxiliary/macros.rs | 47 - .../auxiliary/proc_macros.rs | 29 - tests/ui-toml/disallowed_macros/clippy.toml | 14 - .../disallowed_macros/disallowed_macros.rs | 48 - .../disallowed_macros.stderr | 105 - .../disallowed_names_append/clippy.toml | 1 - .../disallowed_names.rs | 10 - .../disallowed_names.stderr | 17 - .../disallowed_names_replace/clippy.toml | 1 - .../disallowed_names.rs | 10 - .../disallowed_names.stderr | 11 - .../disallowed_script_idents/clippy.toml | 1 - .../disallowed_script_idents.rs | 6 - .../disallowed_script_idents.stderr | 11 - .../doc_valid_idents_append/clippy.toml | 1 - .../doc_markdown.fixed | 12 - .../doc_valid_idents_append/doc_markdown.rs | 12 - .../doc_markdown.stderr | 15 - .../doc_valid_idents_replace/clippy.toml | 1 - .../doc_markdown.fixed | 12 - .../doc_valid_idents_replace/doc_markdown.rs | 12 - .../doc_markdown.stderr | 37 - tests/ui-toml/duplicated_keys/clippy.toml | 2 - .../duplicated_keys/duplicated_keys.rs | 3 - .../duplicated_keys/duplicated_keys.stderr | 8 - .../duplicated_keys_deprecated/clippy.toml | 3 - .../duplicated_keys.rs | 1 - .../duplicated_keys.stderr | 14 - .../duplicated_keys_deprecated_2/clippy.toml | 4 - .../duplicated_keys.rs | 1 - .../duplicated_keys.stderr | 14 - tests/ui-toml/enum_variant_size/clippy.toml | 1 - .../enum_variant_size/enum_variant_size.fixed | 11 - .../enum_variant_size/enum_variant_size.rs | 11 - .../enum_variant_size.stderr | 21 - tests/ui-toml/excessive_nesting/clippy.toml | 1 - .../excessive_nesting/excessive_nesting.rs | 197 - .../excessive_nesting.stderr | 315 - tests/ui-toml/expect_used/clippy.toml | 1 - tests/ui-toml/expect_used/expect_used.rs | 47 - tests/ui-toml/expect_used/expect_used.stderr | 20 - tests/ui-toml/explicit_iter_loop/clippy.toml | 1 - .../explicit_iter_loop.fixed | 10 - .../explicit_iter_loop/explicit_iter_loop.rs | 10 - .../explicit_iter_loop.stderr | 17 - .../extra_unused_type_parameters/clippy.toml | 1 - .../extra_unused_type_parameters.rs | 9 - .../fn_params_excessive_bools/clippy.toml | 1 - .../ui-toml/fn_params_excessive_bools/test.rs | 6 - .../fn_params_excessive_bools/test.stderr | 12 - tests/ui-toml/functions_maxlines/clippy.toml | 1 - tests/ui-toml/functions_maxlines/test.rs | 60 - tests/ui-toml/functions_maxlines/test.stderr | 44 - .../good_toml_no_false_negatives/clippy.toml | 3 - .../conf_no_false_negatives.rs | 1 - tests/ui-toml/ifs_same_cond/clippy.toml | 1 - tests/ui-toml/ifs_same_cond/ifs_same_cond.rs | 18 - .../ifs_same_cond/ifs_same_cond.stderr | 16 - .../ui-toml/impl_trait_in_params/clippy.toml | 1 - .../impl_trait_in_params.rs | 16 - .../impl_trait_in_params.stderr | 15 - .../invalid_min_rust_version/clippy.toml | 1 - .../invalid_min_rust_version.rs | 5 - .../invalid_min_rust_version.stderr | 8 - .../allowed_prefixes/clippy.toml | 1 - .../allowed_prefixes/item_name_repetitions.rs | 15 - .../item_name_repetitions.stderr | 11 - .../allowed_prefixes_extend/clippy.toml | 1 - .../item_name_repetitions.rs | 21 - .../item_name_repetitions.stderr | 11 - .../threshold0/clippy.toml | 2 - .../threshold0/item_name_repetitions.rs | 5 - .../threshold5/clippy.toml | 2 - .../threshold5/item_name_repetitions.rs | 32 - .../threshold5/item_name_repetitions.stderr | 34 - tests/ui-toml/large_futures/clippy.toml | 1 - .../ui-toml/large_futures/large_futures.fixed | 27 - tests/ui-toml/large_futures/large_futures.rs | 27 - .../large_futures/large_futures.stderr | 11 - tests/ui-toml/large_include_file/clippy.toml | 1 - .../large_include_file/large_include_file.rs | 16 - .../large_include_file.stderr | 20 - tests/ui-toml/large_include_file/too_big.txt | 1 - tests/ui-toml/large_stack_frames/clippy.toml | 1 - .../large_stack_frames/large_stack_frames.rs | 17 - .../large_stack_frames.stderr | 16 - .../large_types_passed_by_value/clippy.toml | 1 - .../large_types_passed_by_value.fixed | 7 - .../large_types_passed_by_value.rs | 7 - .../large_types_passed_by_value.stderr | 11 - .../lint_decimal_readability/clippy.toml | 1 - .../lint_decimal_readability/test.fixed | 23 - .../ui-toml/lint_decimal_readability/test.rs | 23 - .../lint_decimal_readability/test.stderr | 20 - .../macro_metavars_in_unsafe/default/test.rs | 260 - .../default/test.stderr | 187 - .../private/clippy.toml | 1 - .../macro_metavars_in_unsafe/private/test.rs | 15 - .../private/test.stderr | 17 - tests/ui-toml/manual_let_else/clippy.toml | 1 - .../manual_let_else/manual_let_else.fixed | 10 - .../manual_let_else/manual_let_else.rs | 14 - .../manual_let_else/manual_let_else.stderr | 15 - .../clippy.toml | 1 - .../index_refutable_slice.fixed | 24 - .../index_refutable_slice.rs | 24 - .../index_refutable_slice.stderr | 22 - .../min_ident_chars/auxiliary/extern_types.rs | 9 - tests/ui-toml/min_ident_chars/clippy.toml | 2 - .../min_ident_chars/min_ident_chars.rs | 22 - .../min_ident_chars/min_ident_chars.stderr | 53 - tests/ui-toml/min_rust_version/clippy.toml | 1 - .../min_rust_version/min_rust_version.fixed | 98 - .../min_rust_version/min_rust_version.rs | 98 - .../min_rust_version/min_rust_version.stderr | 11 - .../clippy.toml | 10 - .../conf_missing_enforced_import_rename.fixed | 16 - .../conf_missing_enforced_import_rename.rs | 16 - ...conf_missing_enforced_import_rename.stderr | 41 - tests/ui-toml/module_inception/clippy.toml | 1 - .../module_inception/module_inception.rs | 34 - .../module_inception/module_inception.stderr | 21 - tests/ui-toml/modulo_arithmetic/clippy.toml | 1 - .../modulo_arithmetic/modulo_arithmetic.rs | 10 - .../modulo_arithmetic.stderr | 40 - tests/ui-toml/mut_key/clippy.toml | 1 - tests/ui-toml/mut_key/mut_key.rs | 61 - .../clippy.toml | 1 - .../needless_raw_string_hashes.fixed | 9 - .../needless_raw_string_hashes.rs | 9 - .../needless_raw_string_hashes.stderr | 40 - .../auxiliary/proc_macro_derive.rs | 13 - .../nonstandard_macro_braces/clippy.toml | 6 - .../conf_nonstandard_macro_braces.fixed | 61 - .../conf_nonstandard_macro_braces.rs | 61 - .../conf_nonstandard_macro_braces.stderr | 58 - tests/ui-toml/path_ends_with_ext/clippy.toml | 1 - .../path_ends_with_ext/path_ends_with_ext.rs | 9 - tests/ui-toml/print_macro/clippy.toml | 1 - tests/ui-toml/print_macro/print_macro.rs | 20 - tests/ui-toml/print_macro/print_macro.stderr | 20 - tests/ui-toml/private-doc-errors/clippy.toml | 1 - tests/ui-toml/private-doc-errors/doc_lints.rs | 54 - .../private-doc-errors/doc_lints.stderr | 64 - .../pub_crate_missing_docs/clippy.toml | 1 - .../pub_crate_missing_doc.rs | 60 - .../pub_crate_missing_doc.stderr | 53 - .../all_pub_fields/clippy.toml | 1 - .../exported/clippy.toml | 1 - ...ub_underscore_fields.all_pub_fields.stderr | 60 - .../pub_underscore_fields.exported.stderr | 12 - .../pub_underscore_fields.rs | 72 - .../default/clippy.toml | 2 - .../extend/clippy.toml | 2 - .../renamed_function_params.default.stderr | 46 - .../renamed_function_params.extend.stderr | 34 - .../renamed_function_params.rs | 110 - tests/ui-toml/result_large_err/clippy.toml | 1 - .../result_large_err/result_large_err.rs | 10 - .../result_large_err/result_large_err.stderr | 12 - tests/ui-toml/semicolon_block/both.fixed | 85 - tests/ui-toml/semicolon_block/both.rs | 85 - tests/ui-toml/semicolon_block/both.stderr | 57 - tests/ui-toml/semicolon_block/clippy.toml | 2 - .../semicolon_inside_block.fixed | 84 - .../semicolon_block/semicolon_inside_block.rs | 84 - .../semicolon_inside_block.stderr | 19 - .../semicolon_outside_block.fixed | 84 - .../semicolon_outside_block.rs | 84 - .../semicolon_outside_block.stderr | 40 - .../clippy.toml | 1 - .../strict_non_send_fields_in_send_ty/test.rs | 43 - .../test.stderr | 92 - .../struct_excessive_bools/clippy.toml | 1 - tests/ui-toml/struct_excessive_bools/test.rs | 9 - .../struct_excessive_bools/test.stderr | 14 - .../suppress_lint_in_const/clippy.toml | 1 - tests/ui-toml/suppress_lint_in_const/test.rs | 63 - .../suppress_lint_in_const/test.stderr | 52 - tests/ui-toml/toml_disallow/clippy.toml | 1 - .../conf_french_disallowed_name.rs | 20 - .../conf_french_disallowed_name.stderr | 47 - .../toml_disallowed_methods/clippy.toml | 17 - .../conf_disallowed_methods.rs | 61 - .../conf_disallowed_methods.stderr | 91 - .../ui-toml/toml_disallowed_types/clippy.toml | 15 - .../conf_disallowed_types.rs | 48 - .../conf_disallowed_types.stderr | 133 - tests/ui-toml/toml_trivially_copy/clippy.toml | 1 - tests/ui-toml/toml_trivially_copy/test.rs | 21 - tests/ui-toml/toml_trivially_copy/test.stderr | 17 - tests/ui-toml/toml_unknown_key/clippy.toml | 11 - .../toml_unknown_key/conf_unknown_key.rs | 4 - .../toml_unknown_key/conf_unknown_key.stderr | 251 - .../too_large_for_stack/boxed_local.rs | 5 - .../too_large_for_stack/boxed_local.stderr | 11 - tests/ui-toml/too_large_for_stack/clippy.toml | 1 - .../too_large_for_stack/useless_vec.fixed | 9 - .../too_large_for_stack/useless_vec.rs | 9 - .../too_large_for_stack/useless_vec.stderr | 11 - tests/ui-toml/too_many_arguments/clippy.toml | 1 - .../too_many_arguments/too_many_arguments.rs | 7 - .../too_many_arguments.stderr | 11 - tests/ui-toml/type_complexity/clippy.toml | 1 - .../type_complexity/type_complexity.rs | 7 - .../type_complexity/type_complexity.stderr | 11 - .../type_repetition_in_bounds/clippy.toml | 1 - .../ui-toml/type_repetition_in_bounds/main.rs | 18 - .../type_repetition_in_bounds/main.stderr | 12 - .../default/clippy.toml | 2 - .../disabled/clippy.toml | 3 - .../undocumented_unsafe_blocks.default.stderr | 316 - ...undocumented_unsafe_blocks.disabled.stderr | 396 -- .../undocumented_unsafe_blocks.rs | 590 -- .../unnecessary_box_returns/clippy.toml | 1 - .../unnecessary_box_returns.fixed | 11 - .../unnecessary_box_returns.rs | 11 - .../unnecessary_box_returns.stderr | 12 - tests/ui-toml/unwrap_used/clippy.toml | 1 - tests/ui-toml/unwrap_used/unwrap_used.fixed | 95 - tests/ui-toml/unwrap_used/unwrap_used.rs | 95 - tests/ui-toml/unwrap_used/unwrap_used.stderr | 214 - tests/ui-toml/update-all-references.sh | 3 - .../clippy.toml | 1 - .../upper_case_acronyms.fixed | 44 - .../upper_case_acronyms.rs | 44 - .../upper_case_acronyms.stderr | 83 - tests/ui-toml/useless_vec/clippy.toml | 1 - tests/ui-toml/useless_vec/useless_vec.fixed | 26 - tests/ui-toml/useless_vec/useless_vec.rs | 26 - tests/ui-toml/useless_vec/useless_vec.stderr | 11 - tests/ui-toml/vec_box_sized/clippy.toml | 1 - tests/ui-toml/vec_box_sized/test.fixed | 16 - tests/ui-toml/vec_box_sized/test.rs | 16 - tests/ui-toml/vec_box_sized/test.stderr | 23 - tests/ui-toml/verbose_bit_mask/clippy.toml | 1 - .../verbose_bit_mask/verbose_bit_mask.fixed | 7 - .../verbose_bit_mask/verbose_bit_mask.rs | 7 - .../verbose_bit_mask/verbose_bit_mask.stderr | 11 - tests/ui-toml/wildcard_imports/clippy.toml | 4 - .../wildcard_imports/wildcard_imports.fixed | 30 - .../wildcard_imports/wildcard_imports.rs | 30 - .../wildcard_imports/wildcard_imports.stderr | 23 - .../wildcard_imports_whitelist/clippy.toml | 1 - .../wildcard_imports.fixed | 26 - .../wildcard_imports.rs | 26 - .../wildcard_imports.stderr | 11 - .../zero_single_char_names/clippy.toml | 1 - .../zero_single_char_names.rs | 3 - tests/ui/absurd-extreme-comparisons.rs | 80 - tests/ui/absurd-extreme-comparisons.stderr | 148 - tests/ui/allow_attributes.fixed | 49 - tests/ui/allow_attributes.rs | 49 - tests/ui/allow_attributes.stderr | 17 - tests/ui/allow_attributes_without_reason.rs | 44 - .../ui/allow_attributes_without_reason.stderr | 39 - tests/ui/almost_complete_range.fixed | 92 - tests/ui/almost_complete_range.rs | 92 - tests/ui/almost_complete_range.stderr | 227 - tests/ui/approx_const.rs | 86 - tests/ui/approx_const.stderr | 188 - tests/ui/arc_with_non_send_sync.rs | 41 - tests/ui/arc_with_non_send_sync.stderr | 34 - tests/ui/arithmetic_side_effects.rs | 534 -- tests/ui/arithmetic_side_effects.stderr | 731 -- tests/ui/as_conversions.rs | 23 - tests/ui/as_conversions.stderr | 28 - tests/ui/as_ptr_cast_mut.rs | 41 - tests/ui/as_ptr_cast_mut.stderr | 17 - tests/ui/as_underscore.fixed | 11 - tests/ui/as_underscore.rs | 11 - tests/ui/as_underscore.stderr | 21 - tests/ui/asm_syntax_not_x86.rs | 24 - tests/ui/asm_syntax_x86.i686.stderr | 70 - tests/ui/asm_syntax_x86.rs | 52 - tests/ui/asm_syntax_x86.x86_64.stderr | 70 - tests/ui/assertions_on_constants.rs | 55 - tests/ui/assertions_on_constants.stderr | 84 - tests/ui/assertions_on_result_states.fixed | 83 - tests/ui/assertions_on_result_states.rs | 83 - tests/ui/assertions_on_result_states.stderr | 47 - tests/ui/assign_ops.fixed | 30 - tests/ui/assign_ops.rs | 30 - tests/ui/assign_ops.stderr | 71 - tests/ui/assign_ops2.rs | 70 - tests/ui/assign_ops2.stderr | 148 - tests/ui/assigning_clones.fixed | 274 - tests/ui/assigning_clones.rs | 274 - tests/ui/assigning_clones.stderr | 149 - tests/ui/async_yields_async.fixed | 78 - tests/ui/async_yields_async.rs | 78 - tests/ui/async_yields_async.stderr | 94 - tests/ui/attrs.rs | 53 - tests/ui/attrs.stderr | 26 - tests/ui/author.rs | 4 - tests/ui/author.stdout | 12 - tests/ui/author/blocks.rs | 24 - tests/ui/author/blocks.stdout | 58 - tests/ui/author/call.rs | 4 - tests/ui/author/call.stdout | 14 - tests/ui/author/if.rs | 17 - tests/ui/author/if.stdout | 46 - tests/ui/author/issue_3849.rs | 14 - tests/ui/author/issue_3849.stdout | 12 - tests/ui/author/loop.rs | 40 - tests/ui/author/loop.stdout | 101 - tests/ui/author/macro_in_closure.rs | 5 - tests/ui/author/macro_in_closure.stdout | 41 - tests/ui/author/macro_in_loop.rs | 8 - tests/ui/author/macro_in_loop.stdout | 50 - tests/ui/author/matches.rs | 13 - tests/ui/author/matches.stdout | 36 - tests/ui/author/repeat.rs | 5 - tests/ui/author/repeat.stdout | 10 - tests/ui/author/struct.rs | 45 - tests/ui/author/struct.stdout | 56 - tests/ui/auxiliary/extern_fake_libc.rs | 10 - tests/ui/auxiliary/macro_rules.rs | 59 - tests/ui/auxiliary/macro_use_helper.rs | 61 - tests/ui/auxiliary/non-exhaustive-enum.rs | 8 - tests/ui/auxiliary/option_helpers.rs | 64 - tests/ui/auxiliary/proc_macro_attr.rs | 192 - tests/ui/auxiliary/proc_macro_derive.rs | 171 - .../proc_macro_suspicious_else_formatting.rs | 69 - tests/ui/auxiliary/proc_macro_unsafe.rs | 13 - tests/ui/auxiliary/proc_macros.rs | 490 -- tests/ui/auxiliary/test_macro.rs | 11 - tests/ui/auxiliary/use_self_macro.rs | 15 - tests/ui/auxiliary/wildcard_imports_helper.rs | 33 - tests/ui/await_holding_lock.rs | 206 - tests/ui/await_holding_lock.stderr | 179 - tests/ui/await_holding_refcell_ref.rs | 91 - tests/ui/await_holding_refcell_ref.stderr | 85 - tests/ui/bind_instead_of_map.fixed | 25 - tests/ui/bind_instead_of_map.rs | 25 - tests/ui/bind_instead_of_map.stderr | 26 - tests/ui/bind_instead_of_map_multipart.fixed | 61 - tests/ui/bind_instead_of_map_multipart.rs | 61 - tests/ui/bind_instead_of_map_multipart.stderr | 91 - tests/ui/bit_masks.rs | 83 - tests/ui/bit_masks.stderr | 112 - tests/ui/blanket_clippy_restriction_lints.rs | 13 - .../blanket_clippy_restriction_lints.stderr | 33 - tests/ui/blocks_in_conditions.fixed | 120 - tests/ui/blocks_in_conditions.rs | 120 - tests/ui/blocks_in_conditions.stderr | 57 - tests/ui/blocks_in_conditions_closure.rs | 89 - tests/ui/blocks_in_conditions_closure.stderr | 39 - tests/ui/bool_assert_comparison.fixed | 169 - tests/ui/bool_assert_comparison.rs | 169 - tests/ui/bool_assert_comparison.stderr | 400 -- tests/ui/bool_comparison.fixed | 176 - tests/ui/bool_comparison.rs | 176 - tests/ui/bool_comparison.stderr | 155 - tests/ui/bool_to_int_with_if.fixed | 118 - tests/ui/bool_to_int_with_if.rs | 150 - tests/ui/bool_to_int_with_if.stderr | 110 - tests/ui/borrow_as_ptr.fixed | 19 - tests/ui/borrow_as_ptr.rs | 19 - tests/ui/borrow_as_ptr.stderr | 17 - tests/ui/borrow_as_ptr_no_std.fixed | 22 - tests/ui/borrow_as_ptr_no_std.rs | 22 - tests/ui/borrow_as_ptr_no_std.stderr | 17 - tests/ui/borrow_box.rs | 129 - tests/ui/borrow_box.stderr | 68 - tests/ui/borrow_deref_ref.fixed | 73 - tests/ui/borrow_deref_ref.rs | 73 - tests/ui/borrow_deref_ref.stderr | 23 - tests/ui/borrow_deref_ref_unfixable.rs | 13 - tests/ui/borrow_deref_ref_unfixable.stderr | 19 - .../auxiliary/helper.rs | 16 - .../ui/borrow_interior_mutable_const/enums.rs | 101 - .../enums.stderr | 79 - .../borrow_interior_mutable_const/others.rs | 104 - .../others.stderr | 119 - .../borrow_interior_mutable_const/traits.rs | 202 - .../traits.stderr | 143 - tests/ui/box_collection.rs | 65 - tests/ui/box_collection.stderr | 76 - tests/ui/box_default.fixed | 143 - tests/ui/box_default.rs | 143 - tests/ui/box_default.stderr | 65 - tests/ui/box_default_no_std.rs | 33 - tests/ui/boxed_local.rs | 203 - tests/ui/boxed_local.stderr | 29 - .../branches_sharing_code/false_positives.rs | 95 - .../branches_sharing_code/shared_at_bottom.rs | 240 - .../shared_at_bottom.stderr | 159 - .../ui/branches_sharing_code/shared_at_top.rs | 122 - .../shared_at_top.stderr | 124 - .../shared_at_top_and_bottom.rs | 125 - .../shared_at_top_and_bottom.stderr | 160 - .../branches_sharing_code/valid_if_blocks.rs | 161 - .../valid_if_blocks.stderr | 97 - tests/ui/builtin_type_shadow.rs | 9 - tests/ui/builtin_type_shadow.stderr | 26 - tests/ui/bytecount.rs | 39 - tests/ui/bytecount.stderr | 26 - tests/ui/bytes_count_to_len.fixed | 33 - tests/ui/bytes_count_to_len.rs | 33 - tests/ui/bytes_count_to_len.stderr | 29 - tests/ui/bytes_nth.fixed | 9 - tests/ui/bytes_nth.rs | 9 - tests/ui/bytes_nth.stderr | 23 - ...sensitive_file_extension_comparisons.fixed | 71 - ...se_sensitive_file_extension_comparisons.rs | 59 - ...ensitive_file_extension_comparisons.stderr | 88 - tests/ui/cast.rs | 500 -- tests/ui/cast.stderr | 735 -- tests/ui/cast_abs_to_unsigned.fixed | 43 - tests/ui/cast_abs_to_unsigned.rs | 43 - tests/ui/cast_abs_to_unsigned.stderr | 113 - tests/ui/cast_alignment.rs | 56 - tests/ui/cast_alignment.stderr | 29 - tests/ui/cast_enum_constructor.rs | 20 - tests/ui/cast_enum_constructor.stderr | 17 - tests/ui/cast_lossless_bool.fixed | 54 - tests/ui/cast_lossless_bool.rs | 54 - tests/ui/cast_lossless_bool.stderr | 95 - tests/ui/cast_lossless_float.fixed | 48 - tests/ui/cast_lossless_float.rs | 48 - tests/ui/cast_lossless_float.stderr | 83 - tests/ui/cast_lossless_integer.fixed | 72 - tests/ui/cast_lossless_integer.rs | 72 - tests/ui/cast_lossless_integer.stderr | 137 - tests/ui/cast_nan_to_int.rs | 30 - tests/ui/cast_nan_to_int.stderr | 52 - tests/ui/cast_raw_slice_pointer_cast.fixed | 23 - tests/ui/cast_raw_slice_pointer_cast.rs | 23 - tests/ui/cast_raw_slice_pointer_cast.stderr | 47 - tests/ui/cast_size.32bit.stderr | 181 - tests/ui/cast_size.64bit.stderr | 172 - tests/ui/cast_size.rs | 37 - tests/ui/cast_slice_different_sizes.rs | 98 - tests/ui/cast_slice_different_sizes.stderr | 131 - tests/ui/cfg_attr_cargo_clippy.fixed | 13 - tests/ui/cfg_attr_cargo_clippy.rs | 13 - tests/ui/cfg_attr_cargo_clippy.stderr | 47 - tests/ui/cfg_attr_rustfmt.fixed | 43 - tests/ui/cfg_attr_rustfmt.rs | 43 - tests/ui/cfg_attr_rustfmt.stderr | 23 - tests/ui/cfg_features.fixed | 29 - tests/ui/cfg_features.rs | 29 - tests/ui/cfg_features.stderr | 53 - tests/ui/char_lit_as_u8.rs | 8 - tests/ui/char_lit_as_u8.stderr | 12 - tests/ui/char_lit_as_u8_suggestions.fixed | 8 - tests/ui/char_lit_as_u8_suggestions.rs | 8 - tests/ui/char_lit_as_u8_suggestions.stderr | 36 - tests/ui/checked_conversions.fixed | 91 - tests/ui/checked_conversions.rs | 91 - tests/ui/checked_conversions.stderr | 107 - .../ui/checked_unwrap/complex_conditionals.rs | 98 - .../complex_conditionals.stderr | 213 - .../complex_conditionals_nested.rs | 23 - .../complex_conditionals_nested.stderr | 32 - .../ui/checked_unwrap/simple_conditionals.rs | 199 - .../checked_unwrap/simple_conditionals.stderr | 240 - tests/ui/clear_with_drain.fixed | 357 - tests/ui/clear_with_drain.rs | 357 - tests/ui/clear_with_drain.stderr | 131 - tests/ui/clone_on_copy.fixed | 77 - tests/ui/clone_on_copy.rs | 77 - tests/ui/clone_on_copy.stderr | 59 - tests/ui/clone_on_copy_impl.rs | 24 - tests/ui/cloned_instead_of_copied.fixed | 34 - tests/ui/cloned_instead_of_copied.rs | 34 - tests/ui/cloned_instead_of_copied.stderr | 53 - tests/ui/cmp_null.rs | 20 - tests/ui/cmp_null.stderr | 17 - .../ui/cmp_owned/asymmetric_partial_eq.fixed | 97 - tests/ui/cmp_owned/asymmetric_partial_eq.rs | 97 - .../ui/cmp_owned/asymmetric_partial_eq.stderr | 47 - tests/ui/cmp_owned/comparison_flip.fixed | 27 - tests/ui/cmp_owned/comparison_flip.rs | 27 - tests/ui/cmp_owned/comparison_flip.stderr | 19 - tests/ui/cmp_owned/with_suggestion.fixed | 70 - tests/ui/cmp_owned/with_suggestion.rs | 70 - tests/ui/cmp_owned/with_suggestion.stderr | 41 - tests/ui/cmp_owned/without_suggestion.rs | 79 - tests/ui/cmp_owned/without_suggestion.stderr | 23 - tests/ui/cognitive_complexity.rs | 431 -- tests/ui/cognitive_complexity.stderr | 164 - tests/ui/cognitive_complexity_attr_used.rs | 16 - .../ui/cognitive_complexity_attr_used.stderr | 12 - tests/ui/collapsible_else_if.fixed | 83 - tests/ui/collapsible_else_if.rs | 99 - tests/ui/collapsible_else_if.stderr | 164 - tests/ui/collapsible_if.fixed | 157 - tests/ui/collapsible_if.rs | 175 - tests/ui/collapsible_if.stderr | 139 - tests/ui/collapsible_match.rs | 309 - tests/ui/collapsible_match.stderr | 246 - tests/ui/collapsible_match2.rs | 91 - tests/ui/collapsible_match2.stderr | 106 - tests/ui/collapsible_str_replace.fixed | 82 - tests/ui/collapsible_str_replace.rs | 85 - tests/ui/collapsible_str_replace.stderr | 93 - tests/ui/collection_is_never_read.rs | 238 - tests/ui/collection_is_never_read.stderr | 125 - tests/ui/comparison_chain.rs | 241 - tests/ui/comparison_chain.stderr | 100 - tests/ui/comparison_to_empty.fixed | 36 - tests/ui/comparison_to_empty.rs | 36 - tests/ui/comparison_to_empty.stderr | 59 - tests/ui/const_comparisons.rs | 150 - tests/ui/const_comparisons.stderr | 230 - tests/ui/const_is_empty.rs | 173 - tests/ui/const_is_empty.stderr | 161 - tests/ui/copy_iterator.rs | 23 - tests/ui/copy_iterator.stderr | 18 - tests/ui/crashes/associated-constant-ice.rs | 13 - tests/ui/crashes/auxiliary/ice-4727-aux.rs | 9 - tests/ui/crashes/auxiliary/ice-7272-aux.rs | 14 - tests/ui/crashes/auxiliary/ice-7868-aux.rs | 5 - tests/ui/crashes/auxiliary/ice-7934-aux.rs | 4 - tests/ui/crashes/auxiliary/ice-8681-aux.rs | 6 - .../ui/crashes/auxiliary/proc_macro_crash.rs | 30 - tests/ui/crashes/auxiliary/use_self_macro.rs | 15 - tests/ui/crashes/cc_seme.rs | 27 - tests/ui/crashes/enum-glob-import-crate.rs | 6 - tests/ui/crashes/ice-10148.rs | 9 - tests/ui/crashes/ice-10148.stderr | 13 - tests/ui/crashes/ice-10645.rs | 7 - tests/ui/crashes/ice-10645.stderr | 17 - tests/ui/crashes/ice-10912.rs | 6 - tests/ui/crashes/ice-10912.stderr | 8 - tests/ui/crashes/ice-11065.rs | 18 - tests/ui/crashes/ice-11230.rs | 6 - tests/ui/crashes/ice-11337.rs | 9 - tests/ui/crashes/ice-11422.fixed | 25 - tests/ui/crashes/ice-11422.rs | 25 - tests/ui/crashes/ice-11422.stderr | 16 - tests/ui/crashes/ice-11755.rs | 5 - tests/ui/crashes/ice-11803.rs | 9 - tests/ui/crashes/ice-11803.stderr | 26 - tests/ui/crashes/ice-11939.rs | 14 - tests/ui/crashes/ice-12253.rs | 5 - tests/ui/crashes/ice-12491.fixed | 7 - tests/ui/crashes/ice-12491.rs | 8 - tests/ui/crashes/ice-12491.stderr | 19 - tests/ui/crashes/ice-12585.rs | 26 - tests/ui/crashes/ice-12616.fixed | 7 - tests/ui/crashes/ice-12616.rs | 7 - tests/ui/crashes/ice-12616.stderr | 11 - tests/ui/crashes/ice-1588.rs | 13 - tests/ui/crashes/ice-1782.rs | 27 - tests/ui/crashes/ice-1969.rs | 13 - tests/ui/crashes/ice-2499.rs | 26 - tests/ui/crashes/ice-2594.rs | 20 - tests/ui/crashes/ice-2727.rs | 7 - tests/ui/crashes/ice-2760.rs | 23 - tests/ui/crashes/ice-2774.fixed | 29 - tests/ui/crashes/ice-2774.rs | 29 - tests/ui/crashes/ice-2774.stderr | 16 - tests/ui/crashes/ice-2862.rs | 16 - tests/ui/crashes/ice-2865.rs | 16 - tests/ui/crashes/ice-3151.rs | 15 - tests/ui/crashes/ice-3462.rs | 23 - tests/ui/crashes/ice-360.rs | 16 - tests/ui/crashes/ice-360.stderr | 41 - tests/ui/crashes/ice-3717.fixed | 11 - tests/ui/crashes/ice-3717.rs | 11 - tests/ui/crashes/ice-3717.stderr | 22 - tests/ui/crashes/ice-3741.rs | 10 - tests/ui/crashes/ice-3747.rs | 17 - tests/ui/crashes/ice-3891.rs | 4 - tests/ui/crashes/ice-3891.stderr | 10 - tests/ui/crashes/ice-3969.rs | 56 - tests/ui/crashes/ice-3969.stderr | 35 - tests/ui/crashes/ice-4121.rs | 13 - tests/ui/crashes/ice-4545.rs | 14 - tests/ui/crashes/ice-4579.rs | 13 - tests/ui/crashes/ice-4671.rs | 21 - tests/ui/crashes/ice-4727.rs | 6 - tests/ui/crashes/ice-4760.rs | 11 - tests/ui/crashes/ice-4775.rs | 13 - tests/ui/crashes/ice-4968.rs | 19 - tests/ui/crashes/ice-5207.rs | 4 - tests/ui/crashes/ice-5223.rs | 15 - tests/ui/crashes/ice-5238.rs | 10 - tests/ui/crashes/ice-5389.rs | 13 - tests/ui/crashes/ice-5497.rs | 13 - tests/ui/crashes/ice-5497.stderr | 10 - tests/ui/crashes/ice-5579.rs | 19 - tests/ui/crashes/ice-5835.fixed | 11 - tests/ui/crashes/ice-5835.rs | 11 - tests/ui/crashes/ice-5835.stderr | 11 - tests/ui/crashes/ice-5872.fixed | 7 - tests/ui/crashes/ice-5872.rs | 7 - tests/ui/crashes/ice-5872.stderr | 11 - tests/ui/crashes/ice-5944.rs | 14 - tests/ui/crashes/ice-6139.rs | 7 - tests/ui/crashes/ice-6153.rs | 9 - tests/ui/crashes/ice-6179.rs | 22 - tests/ui/crashes/ice-6250.rs | 16 - tests/ui/crashes/ice-6250.stderr | 23 - tests/ui/crashes/ice-6251.rs | 6 - tests/ui/crashes/ice-6251.stderr | 35 - tests/ui/crashes/ice-6252.rs | 15 - tests/ui/crashes/ice-6252.stderr | 37 - tests/ui/crashes/ice-6254.rs | 16 - tests/ui/crashes/ice-6255.rs | 15 - tests/ui/crashes/ice-6255.stderr | 13 - tests/ui/crashes/ice-6256.rs | 15 - tests/ui/crashes/ice-6256.stderr | 14 - tests/ui/crashes/ice-6332.rs | 11 - tests/ui/crashes/ice-6539.rs | 16 - tests/ui/crashes/ice-6792.rs | 20 - tests/ui/crashes/ice-6793.rs | 23 - tests/ui/crashes/ice-6840.rs | 31 - tests/ui/crashes/ice-700.rs | 9 - tests/ui/crashes/ice-7012.rs | 17 - tests/ui/crashes/ice-7126.rs | 14 - tests/ui/crashes/ice-7169.fixed | 13 - tests/ui/crashes/ice-7169.rs | 13 - tests/ui/crashes/ice-7169.stderr | 11 - tests/ui/crashes/ice-7231.rs | 9 - tests/ui/crashes/ice-7272.rs | 12 - tests/ui/crashes/ice-7340.rs | 6 - tests/ui/crashes/ice-7410.rs | 33 - tests/ui/crashes/ice-7423.rs | 13 - tests/ui/crashes/ice-7868.rs | 7 - tests/ui/crashes/ice-7868.stderr | 12 - tests/ui/crashes/ice-7869.rs | 8 - tests/ui/crashes/ice-7869.stderr | 17 - tests/ui/crashes/ice-7934.rs | 7 - tests/ui/crashes/ice-8250.fixed | 8 - tests/ui/crashes/ice-8250.rs | 8 - tests/ui/crashes/ice-8250.stderr | 11 - tests/ui/crashes/ice-8386.rs | 3 - tests/ui/crashes/ice-8681.rs | 10 - tests/ui/crashes/ice-8821.rs | 8 - tests/ui/crashes/ice-8850.fixed | 31 - tests/ui/crashes/ice-8850.rs | 31 - tests/ui/crashes/ice-8850.stderr | 46 - tests/ui/crashes/ice-9041.rs | 10 - tests/ui/crashes/ice-9041.stderr | 11 - tests/ui/crashes/ice-9238.rs | 12 - tests/ui/crashes/ice-9242.rs | 8 - tests/ui/crashes/ice-9405.rs | 11 - tests/ui/crashes/ice-9405.stderr | 11 - tests/ui/crashes/ice-9414.rs | 8 - tests/ui/crashes/ice-9445.rs | 5 - tests/ui/crashes/ice-9445.stderr | 13 - tests/ui/crashes/ice-9459.rs | 5 - tests/ui/crashes/ice-9463.rs | 9 - tests/ui/crashes/ice-9463.stderr | 29 - tests/ui/crashes/ice-9625.rs | 4 - tests/ui/crashes/ice-96721.fixed | 10 - tests/ui/crashes/ice-96721.rs | 10 - tests/ui/crashes/ice-96721.stderr | 8 - tests/ui/crashes/ice-9746.rs | 15 - tests/ui/crashes/ice-rust-107877.rs | 17 - tests/ui/crashes/ice_exact_size.rs | 19 - tests/ui/crashes/if_same_then_else.rs | 16 - tests/ui/crashes/implements-trait.rs | 5 - tests/ui/crashes/inherent_impl.rs | 26 - tests/ui/crashes/issue-825.rs | 25 - tests/ui/crashes/issues_loop_mut_cond.rs | 28 - tests/ui/crashes/match_same_arms_const.rs | 18 - tests/ui/crashes/mut_mut_macro.rs | 33 - tests/ui/crashes/needless_borrow_fp.rs | 7 - .../needless_lifetimes_impl_trait.fixed | 21 - .../crashes/needless_lifetimes_impl_trait.rs | 21 - .../needless_lifetimes_impl_trait.stderr | 19 - .../needless_pass_by_value-w-late-bound.fixed | 10 - .../needless_pass_by_value-w-late-bound.rs | 10 - ...needless_pass_by_value-w-late-bound.stderr | 16 - tests/ui/crashes/regressions.rs | 11 - tests/ui/crashes/returns.rs | 23 - tests/ui/crashes/shadow.rs | 6 - tests/ui/crashes/single-match-else.rs | 11 - tests/ui/crashes/third-party/clippy.toml | 3 - .../crashes/third-party/conf_allowlisted.rs | 1 - tests/ui/crashes/trivial_bounds.rs | 11 - .../ui/crashes/unreachable-array-or-slice.rs | 8 - .../crashes/unreachable-array-or-slice.stderr | 9 - .../crashes/used_underscore_binding_macro.rs | 16 - tests/ui/crate_in_macro_def.fixed | 55 - tests/ui/crate_in_macro_def.rs | 55 - tests/ui/crate_in_macro_def.stderr | 11 - .../entrypoint_recursion.rs | 11 - .../no_std_main_recursion.rs | 32 - tests/ui/crate_level_checks/no_std_swap.fixed | 13 - tests/ui/crate_level_checks/no_std_swap.rs | 16 - .../ui/crate_level_checks/no_std_swap.stderr | 15 - .../crate_level_checks/std_main_recursion.rs | 7 - .../std_main_recursion.stderr | 12 - tests/ui/create_dir.fixed | 16 - tests/ui/create_dir.rs | 16 - tests/ui/create_dir.stderr | 17 - tests/ui/dbg_macro/auxiliary/submodule.rs | 3 - tests/ui/dbg_macro/dbg_macro.fixed | 111 - tests/ui/dbg_macro/dbg_macro.rs | 111 - tests/ui/dbg_macro/dbg_macro.stderr | 219 - tests/ui/dbg_macro/dbg_macro_unfixable.rs | 12 - tests/ui/dbg_macro/dbg_macro_unfixable.stderr | 71 - tests/ui/debug_assert_with_mut_call.rs | 162 - tests/ui/debug_assert_with_mut_call.stderr | 173 - tests/ui/decimal_literal_representation.fixed | 25 - tests/ui/decimal_literal_representation.rs | 25 - .../ui/decimal_literal_representation.stderr | 47 - .../declare_interior_mutable_const/enums.rs | 124 - .../enums.stderr | 91 - .../declare_interior_mutable_const/others.rs | 56 - .../others.stderr | 51 - .../declare_interior_mutable_const/traits.rs | 150 - .../traits.stderr | 88 - tests/ui/def_id_nocore.rs | 31 - tests/ui/def_id_nocore.stderr | 12 - .../ui/default_constructed_unit_structs.fixed | 157 - tests/ui/default_constructed_unit_structs.rs | 157 - .../default_constructed_unit_structs.stderr | 41 - tests/ui/default_instead_of_iter_empty.fixed | 20 - tests/ui/default_instead_of_iter_empty.rs | 20 - tests/ui/default_instead_of_iter_empty.stderr | 23 - ...default_instead_of_iter_empty_no_std.fixed | 28 - .../default_instead_of_iter_empty_no_std.rs | 28 - ...efault_instead_of_iter_empty_no_std.stderr | 17 - tests/ui/default_numeric_fallback_f64.fixed | 181 - tests/ui/default_numeric_fallback_f64.rs | 181 - tests/ui/default_numeric_fallback_f64.stderr | 145 - tests/ui/default_numeric_fallback_i32.fixed | 259 - tests/ui/default_numeric_fallback_i32.rs | 259 - tests/ui/default_numeric_fallback_i32.stderr | 175 - tests/ui/default_trait_access.fixed | 103 - tests/ui/default_trait_access.rs | 103 - tests/ui/default_trait_access.stderr | 56 - tests/ui/default_union_representation.rs | 82 - tests/ui/default_union_representation.stderr | 53 - tests/ui/deprecated.rs | 22 - tests/ui/deprecated.stderr | 101 - tests/ui/deprecated_old.rs | 9 - tests/ui/deprecated_old.stderr | 23 - tests/ui/deref_addrof.fixed | 59 - tests/ui/deref_addrof.rs | 59 - tests/ui/deref_addrof.stderr | 69 - tests/ui/deref_addrof_double_trigger.rs | 27 - tests/ui/deref_addrof_double_trigger.stderr | 23 - tests/ui/deref_addrof_macro.rs | 13 - tests/ui/deref_by_slicing.fixed | 28 - tests/ui/deref_by_slicing.rs | 28 - tests/ui/deref_by_slicing.stderr | 59 - tests/ui/derivable_impls.fixed | 295 - tests/ui/derivable_impls.rs | 339 - tests/ui/derivable_impls.stderr | 147 - tests/ui/derive.rs | 104 - tests/ui/derive.stderr | 114 - tests/ui/derive_ord_xor_partial_ord.rs | 74 - tests/ui/derive_ord_xor_partial_ord.stderr | 66 - tests/ui/derive_partial_eq_without_eq.fixed | 182 - tests/ui/derive_partial_eq_without_eq.rs | 182 - tests/ui/derive_partial_eq_without_eq.stderr | 83 - tests/ui/derived_hash_with_manual_eq.rs | 41 - tests/ui/derived_hash_with_manual_eq.stderr | 29 - tests/ui/disallowed_names.rs | 78 - tests/ui/disallowed_names.stderr | 89 - tests/ui/disallowed_script_idents.rs | 16 - tests/ui/disallowed_script_idents.stderr | 20 - tests/ui/diverging_sub_expression.rs | 69 - tests/ui/diverging_sub_expression.stderr | 73 - tests/ui/doc/doc-fixable.fixed | 242 - tests/ui/doc/doc-fixable.rs | 242 - tests/ui/doc/doc-fixable.stderr | 367 - tests/ui/doc/doc_lazy_blockquote.fixed | 47 - tests/ui/doc/doc_lazy_blockquote.rs | 47 - tests/ui/doc/doc_lazy_blockquote.stderr | 76 - tests/ui/doc/doc_lazy_list.fixed | 42 - tests/ui/doc/doc_lazy_list.rs | 42 - tests/ui/doc/doc_lazy_list.stderr | 112 - tests/ui/doc/issue_10262.fixed | 12 - tests/ui/doc/issue_10262.rs | 12 - tests/ui/doc/issue_10262.stderr | 15 - tests/ui/doc/issue_1832.rs | 9 - tests/ui/doc/issue_902.rs | 7 - tests/ui/doc/issue_9473.fixed | 9 - tests/ui/doc/issue_9473.rs | 9 - tests/ui/doc/issue_9473.stderr | 15 - tests/ui/doc/needless_doctest_main.rs | 20 - tests/ui/doc/unbalanced_ticks.rs | 51 - tests/ui/doc/unbalanced_ticks.stderr | 82 - tests/ui/doc_errors.rs | 143 - tests/ui/doc_errors.stderr | 47 - tests/ui/doc_link_with_quotes.rs | 25 - tests/ui/doc_link_with_quotes.stderr | 17 - tests/ui/doc_unsafe.rs | 138 - tests/ui/doc_unsafe.stderr | 46 - tests/ui/double_comparison.fixed | 30 - tests/ui/double_comparison.rs | 30 - tests/ui/double_comparison.stderr | 53 - tests/ui/double_must_use.rs | 43 - tests/ui/double_must_use.stderr | 36 - tests/ui/double_neg.rs | 10 - tests/ui/double_neg.stderr | 11 - tests/ui/double_parens.rs | 63 - tests/ui/double_parens.stderr | 41 - tests/ui/drain_collect.fixed | 75 - tests/ui/drain_collect.rs | 75 - tests/ui/drain_collect.stderr | 68 - tests/ui/drop_non_drop.rs | 42 - tests/ui/drop_non_drop.stderr | 28 - tests/ui/duplicate_underscore_argument.rs | 12 - tests/ui/duplicate_underscore_argument.stderr | 11 - tests/ui/duplicated_attributes.rs | 30 - tests/ui/duplicated_attributes.stderr | 38 - tests/ui/duration_subsec.fixed | 28 - tests/ui/duration_subsec.rs | 28 - tests/ui/duration_subsec.stderr | 35 - tests/ui/eager_transmute.fixed | 105 - tests/ui/eager_transmute.rs | 105 - tests/ui/eager_transmute.stderr | 191 - tests/ui/else_if_without_else.rs | 122 - tests/ui/else_if_without_else.stderr | 52 - tests/ui/empty_docs.rs | 86 - tests/ui/empty_docs.stderr | 78 - tests/ui/empty_drop.fixed | 21 - tests/ui/empty_drop.rs | 29 - tests/ui/empty_drop.stderr | 23 - tests/ui/empty_enum.rs | 8 - tests/ui/empty_enum.stderr | 12 - .../empty_enum_variants_with_brackets.fixed | 27 - tests/ui/empty_enum_variants_with_brackets.rs | 27 - .../empty_enum_variants_with_brackets.stderr | 36 - tests/ui/empty_enum_without_never_type.rs | 7 - tests/ui/empty_line_after_doc_comments.rs | 132 - tests/ui/empty_line_after_doc_comments.stderr | 37 - tests/ui/empty_line_after_outer_attribute.rs | 120 - .../empty_line_after_outer_attribute.stderr | 54 - tests/ui/empty_loop.rs | 51 - tests/ui/empty_loop.stderr | 28 - tests/ui/empty_loop_no_std.rs | 28 - tests/ui/empty_loop_no_std.stderr | 20 - tests/ui/empty_structs_with_brackets.fixed | 24 - tests/ui/empty_structs_with_brackets.rs | 24 - tests/ui/empty_structs_with_brackets.stderr | 20 - tests/ui/endian_bytes.rs | 127 - tests/ui/endian_bytes.stderr | 1034 --- tests/ui/entry.fixed | 189 - tests/ui/entry.rs | 193 - tests/ui/entry.stderr | 239 - tests/ui/entry_btree.fixed | 16 - tests/ui/entry_btree.rs | 16 - tests/ui/entry_btree.stderr | 21 - tests/ui/entry_with_else.fixed | 71 - tests/ui/entry_with_else.rs | 58 - tests/ui/entry_with_else.stderr | 152 - tests/ui/enum_clike_unportable_variant.rs | 60 - tests/ui/enum_clike_unportable_variant.stderr | 59 - tests/ui/enum_glob_use.fixed | 29 - tests/ui/enum_glob_use.rs | 29 - tests/ui/enum_glob_use.stderr | 23 - tests/ui/enum_variants.rs | 224 - tests/ui/enum_variants.stderr | 174 - tests/ui/eprint_with_newline.fixed | 69 - tests/ui/eprint_with_newline.rs | 71 - tests/ui/eprint_with_newline.stderr | 122 - tests/ui/eq_op.rs | 140 - tests/ui/eq_op.stderr | 181 - tests/ui/eq_op_macros.rs | 65 - tests/ui/eq_op_macros.stderr | 96 - tests/ui/equatable_if_let.fixed | 91 - tests/ui/equatable_if_let.rs | 91 - tests/ui/equatable_if_let.stderr | 89 - tests/ui/erasing_op.rs | 51 - tests/ui/erasing_op.stderr | 35 - tests/ui/err_expect.fixed | 26 - tests/ui/err_expect.rs | 26 - tests/ui/err_expect.stderr | 17 - tests/ui/error_impl_error.rs | 94 - tests/ui/error_impl_error.stderr | 46 - tests/ui/eta.fixed | 473 -- tests/ui/eta.rs | 473 -- tests/ui/eta.stderr | 194 - tests/ui/excessive_precision.fixed | 81 - tests/ui/excessive_precision.rs | 81 - tests/ui/excessive_precision.stderr | 95 - tests/ui/exhaustive_items.fixed | 89 - tests/ui/exhaustive_items.rs | 86 - tests/ui/exhaustive_items.stderr | 61 - tests/ui/exit1.rs | 17 - tests/ui/exit1.stderr | 11 - tests/ui/exit2.rs | 15 - tests/ui/exit2.stderr | 11 - tests/ui/exit3.rs | 8 - tests/ui/expect.rs | 21 - tests/ui/expect.stderr | 28 - tests/ui/expect_fun_call.fixed | 112 - tests/ui/expect_fun_call.rs | 112 - tests/ui/expect_fun_call.stderr | 95 - tests/ui/expect_tool_lint_rfc_2383.rs | 141 - tests/ui/expect_tool_lint_rfc_2383.stderr | 41 - tests/ui/explicit_auto_deref.fixed | 347 - tests/ui/explicit_auto_deref.rs | 347 - tests/ui/explicit_auto_deref.stderr | 275 - tests/ui/explicit_counter_loop.rs | 280 - tests/ui/explicit_counter_loop.stderr | 61 - tests/ui/explicit_deref_methods.fixed | 130 - tests/ui/explicit_deref_methods.rs | 130 - tests/ui/explicit_deref_methods.stderr | 77 - tests/ui/explicit_into_iter_loop.fixed | 69 - tests/ui/explicit_into_iter_loop.rs | 69 - tests/ui/explicit_into_iter_loop.stderr | 41 - tests/ui/explicit_iter_loop.fixed | 155 - tests/ui/explicit_iter_loop.rs | 155 - tests/ui/explicit_iter_loop.stderr | 116 - tests/ui/explicit_write.fixed | 65 - tests/ui/explicit_write.rs | 65 - tests/ui/explicit_write.stderr | 83 - tests/ui/extend_with_drain.fixed | 59 - tests/ui/extend_with_drain.rs | 59 - tests/ui/extend_with_drain.stderr | 29 - tests/ui/extra_unused_lifetimes.rs | 129 - tests/ui/extra_unused_lifetimes.stderr | 41 - tests/ui/extra_unused_type_parameters.fixed | 131 - tests/ui/extra_unused_type_parameters.rs | 131 - tests/ui/extra_unused_type_parameters.stderr | 65 - .../extra_unused_type_parameters_unfixable.rs | 27 - ...ra_unused_type_parameters_unfixable.stderr | 28 - tests/ui/fallible_impl_from.rs | 81 - tests/ui/fallible_impl_from.stderr | 94 - tests/ui/field_reassign_with_default.rs | 277 - tests/ui/field_reassign_with_default.stderr | 136 - tests/ui/filetype_is_file.rs | 27 - tests/ui/filetype_is_file.stderr | 28 - tests/ui/filter_map_bool_then.fixed | 81 - tests/ui/filter_map_bool_then.rs | 81 - tests/ui/filter_map_bool_then.stderr | 65 - tests/ui/filter_map_identity.fixed | 83 - tests/ui/filter_map_identity.rs | 83 - tests/ui/filter_map_identity.stderr | 137 - tests/ui/filter_map_next.rs | 19 - tests/ui/filter_map_next.stderr | 18 - tests/ui/filter_map_next_fixable.fixed | 21 - tests/ui/filter_map_next_fixable.rs | 21 - tests/ui/filter_map_next_fixable.stderr | 17 - tests/ui/find_map.rs | 34 - tests/ui/flat_map_identity.fixed | 15 - tests/ui/flat_map_identity.rs | 15 - tests/ui/flat_map_identity.stderr | 23 - tests/ui/flat_map_option.fixed | 12 - tests/ui/flat_map_option.rs | 12 - tests/ui/flat_map_option.stderr | 17 - tests/ui/float_arithmetic.rs | 70 - tests/ui/float_arithmetic.stderr | 107 - tests/ui/float_cmp.rs | 140 - tests/ui/float_cmp.stderr | 52 - tests/ui/float_cmp_const.rs | 74 - tests/ui/float_cmp_const.stderr | 68 - tests/ui/float_equality_without_abs.rs | 43 - tests/ui/float_equality_without_abs.stderr | 93 - tests/ui/floating_point_abs.fixed | 83 - tests/ui/floating_point_abs.rs | 83 - tests/ui/floating_point_abs.stderr | 53 - tests/ui/floating_point_arithmetic_nostd.rs | 31 - tests/ui/floating_point_exp.fixed | 19 - tests/ui/floating_point_exp.rs | 19 - tests/ui/floating_point_exp.stderr | 35 - tests/ui/floating_point_hypot.fixed | 13 - tests/ui/floating_point_hypot.rs | 13 - tests/ui/floating_point_hypot.stderr | 23 - tests/ui/floating_point_log.fixed | 58 - tests/ui/floating_point_log.rs | 58 - tests/ui/floating_point_log.stderr | 182 - tests/ui/floating_point_logbase.fixed | 17 - tests/ui/floating_point_logbase.rs | 17 - tests/ui/floating_point_logbase.stderr | 35 - tests/ui/floating_point_mul_add.fixed | 59 - tests/ui/floating_point_mul_add.rs | 59 - tests/ui/floating_point_mul_add.stderr | 83 - tests/ui/floating_point_powf.fixed | 50 - tests/ui/floating_point_powf.rs | 50 - tests/ui/floating_point_powf.stderr | 194 - tests/ui/floating_point_powi.fixed | 32 - tests/ui/floating_point_powi.rs | 32 - tests/ui/floating_point_powi.stderr | 89 - tests/ui/floating_point_rad.fixed | 29 - tests/ui/floating_point_rad.rs | 29 - tests/ui/floating_point_rad.stderr | 53 - tests/ui/fn_address_comparisons.rs | 23 - tests/ui/fn_address_comparisons.stderr | 17 - tests/ui/fn_params_excessive_bools.rs | 60 - tests/ui/fn_params_excessive_bools.stderr | 64 - tests/ui/fn_to_numeric_cast.32bit.stderr | 146 - tests/ui/fn_to_numeric_cast.64bit.stderr | 146 - tests/ui/fn_to_numeric_cast.rs | 55 - tests/ui/fn_to_numeric_cast_any.rs | 94 - tests/ui/fn_to_numeric_cast_any.stderr | 107 - tests/ui/for_kv_map.fixed | 56 - tests/ui/for_kv_map.rs | 56 - tests/ui/for_kv_map.stderr | 59 - tests/ui/forget_non_drop.rs | 29 - tests/ui/forget_non_drop.stderr | 28 - tests/ui/format.fixed | 90 - tests/ui/format.rs | 92 - tests/ui/format.stderr | 104 - tests/ui/format_args.fixed | 167 - tests/ui/format_args.rs | 167 - tests/ui/format_args.stderr | 155 - tests/ui/format_args_unfixable.rs | 121 - tests/ui/format_args_unfixable.stderr | 178 - tests/ui/format_collect.rs | 34 - tests/ui/format_collect.stderr | 64 - tests/ui/format_push_string.rs | 41 - tests/ui/format_push_string.stderr | 58 - tests/ui/formatting.rs | 85 - tests/ui/formatting.stderr | 54 - tests/ui/four_forward_slashes.fixed | 48 - tests/ui/four_forward_slashes.rs | 48 - tests/ui/four_forward_slashes.stderr | 69 - .../ui/four_forward_slashes_first_line.fixed | 6 - tests/ui/four_forward_slashes_first_line.rs | 6 - .../ui/four_forward_slashes_first_line.stderr | 16 - tests/ui/from_iter_instead_of_collect.fixed | 60 - tests/ui/from_iter_instead_of_collect.rs | 60 - tests/ui/from_iter_instead_of_collect.stderr | 95 - tests/ui/from_over_into.fixed | 101 - tests/ui/from_over_into.rs | 101 - tests/ui/from_over_into.stderr | 104 - tests/ui/from_over_into_unfixable.rs | 49 - tests/ui/from_over_into_unfixable.stderr | 38 - tests/ui/from_raw_with_void_ptr.rs | 40 - tests/ui/from_raw_with_void_ptr.stderr | 64 - tests/ui/from_str_radix_10.fixed | 72 - tests/ui/from_str_radix_10.rs | 72 - tests/ui/from_str_radix_10.stderr | 53 - tests/ui/functions.rs | 130 - tests/ui/functions.stderr | 110 - tests/ui/functions_maxlines.rs | 165 - tests/ui/functions_maxlines.stderr | 17 - tests/ui/future_not_send.rs | 88 - tests/ui/future_not_send.stderr | 134 - tests/ui/get_first.fixed | 50 - tests/ui/get_first.rs | 50 - tests/ui/get_first.stderr | 35 - tests/ui/get_last_with_len.fixed | 47 - tests/ui/get_last_with_len.rs | 47 - tests/ui/get_last_with_len.stderr | 41 - tests/ui/get_unwrap.fixed | 108 - tests/ui/get_unwrap.rs | 108 - tests/ui/get_unwrap.stderr | 229 - tests/ui/identity_op.fixed | 214 - tests/ui/identity_op.rs | 214 - tests/ui/identity_op.stderr | 317 - tests/ui/if_let_mutex.rs | 53 - tests/ui/if_let_mutex.stderr | 57 - tests/ui/if_not_else.rs | 31 - tests/ui/if_not_else.stderr | 30 - tests/ui/if_not_else_bittest.rs | 11 - tests/ui/if_same_then_else.rs | 246 - tests/ui/if_same_then_else.stderr | 110 - tests/ui/if_same_then_else2.rs | 158 - tests/ui/if_same_then_else2.stderr | 116 - tests/ui/if_then_some_else_none.rs | 137 - tests/ui/if_then_some_else_none.stderr | 65 - tests/ui/ifs_same_cond.rs | 82 - tests/ui/ifs_same_cond.stderr | 52 - tests/ui/ignored_unit_patterns.fixed | 61 - tests/ui/ignored_unit_patterns.rs | 61 - tests/ui/ignored_unit_patterns.stderr | 59 - tests/ui/impl.rs | 71 - tests/ui/impl.stderr | 67 - .../ui/impl_hash_with_borrow_str_and_bytes.rs | 136 - ...impl_hash_with_borrow_str_and_bytes.stderr | 41 - tests/ui/impl_trait_in_params.rs | 47 - tests/ui/impl_trait_in_params.stderr | 48 - tests/ui/implicit_clone.fixed | 127 - tests/ui/implicit_clone.rs | 127 - tests/ui/implicit_clone.stderr | 71 - tests/ui/implicit_hasher.rs | 103 - tests/ui/implicit_hasher.stderr | 40 - tests/ui/implicit_return.fixed | 139 - tests/ui/implicit_return.rs | 139 - tests/ui/implicit_return.stderr | 110 - tests/ui/implicit_saturating_add.fixed | 104 - tests/ui/implicit_saturating_add.rs | 152 - tests/ui/implicit_saturating_add.stderr | 198 - tests/ui/implicit_saturating_sub.fixed | 217 - tests/ui/implicit_saturating_sub.rs | 263 - tests/ui/implicit_saturating_sub.stderr | 189 - tests/ui/implied_bounds_in_impls.fixed | 176 - tests/ui/implied_bounds_in_impls.rs | 176 - tests/ui/implied_bounds_in_impls.stderr | 280 - tests/ui/incompatible_msrv.rs | 36 - tests/ui/incompatible_msrv.stderr | 23 - tests/ui/inconsistent_digit_grouping.fixed | 46 - tests/ui/inconsistent_digit_grouping.rs | 46 - tests/ui/inconsistent_digit_grouping.stderr | 71 - .../ui/inconsistent_struct_constructor.fixed | 73 - tests/ui/inconsistent_struct_constructor.rs | 77 - .../ui/inconsistent_struct_constructor.stderr | 21 - .../if_let_slice_binding.fixed | 177 - .../if_let_slice_binding.rs | 177 - .../if_let_slice_binding.stderr | 158 - .../slice_indexing_in_macro.fixed | 29 - .../slice_indexing_in_macro.rs | 29 - .../slice_indexing_in_macro.stderr | 22 - tests/ui/indexing_slicing_index.rs | 79 - tests/ui/indexing_slicing_index.stderr | 125 - tests/ui/indexing_slicing_slice.rs | 54 - tests/ui/indexing_slicing_slice.stderr | 127 - tests/ui/ineffective_open_options.fixed | 48 - tests/ui/ineffective_open_options.rs | 48 - tests/ui/ineffective_open_options.stderr | 17 - tests/ui/inefficient_to_string.fixed | 30 - tests/ui/inefficient_to_string.rs | 30 - tests/ui/inefficient_to_string.stderr | 55 - tests/ui/infallible_destructuring_match.fixed | 123 - tests/ui/infallible_destructuring_match.rs | 131 - .../ui/infallible_destructuring_match.stderr | 37 - tests/ui/infinite_iter.rs | 104 - tests/ui/infinite_iter.stderr | 111 - tests/ui/infinite_loop.rs | 241 - tests/ui/infinite_loop.stderr | 95 - tests/ui/infinite_loops.rs | 393 -- tests/ui/infinite_loops.stderr | 259 - tests/ui/inherent_to_string.rs | 130 - tests/ui/inherent_to_string.stderr | 27 - tests/ui/inline_fn_without_body.fixed | 15 - tests/ui/inline_fn_without_body.rs | 18 - tests/ui/inline_fn_without_body.stderr | 29 - tests/ui/inspect_for_each.rs | 23 - tests/ui/inspect_for_each.stderr | 18 - tests/ui/int_plus_one.fixed | 15 - tests/ui/int_plus_one.rs | 15 - tests/ui/int_plus_one.stderr | 29 - tests/ui/integer_division.rs | 12 - tests/ui/integer_division.stderr | 28 - tests/ui/integer_division_remainder_used.rs | 41 - .../ui/integer_division_remainder_used.stderr | 59 - tests/ui/into_iter_on_ref.fixed | 44 - tests/ui/into_iter_on_ref.rs | 44 - tests/ui/into_iter_on_ref.stderr | 167 - tests/ui/into_iter_without_iter.rs | 187 - tests/ui/into_iter_without_iter.stderr | 140 - tests/ui/invalid_null_ptr_usage.fixed | 47 - tests/ui/invalid_null_ptr_usage.rs | 47 - tests/ui/invalid_null_ptr_usage.stderr | 154 - tests/ui/invalid_upcast_comparisons.rs | 113 - tests/ui/invalid_upcast_comparisons.stderr | 167 - tests/ui/is_digit_ascii_radix.fixed | 16 - tests/ui/is_digit_ascii_radix.rs | 16 - tests/ui/is_digit_ascii_radix.stderr | 23 - tests/ui/issue-111399.rs | 13 - tests/ui/issue-3145.rs | 3 - tests/ui/issue-3145.stderr | 8 - tests/ui/issue-7447.rs | 31 - tests/ui/issue-7447.stderr | 20 - tests/ui/issue_2356.fixed | 26 - tests/ui/issue_2356.rs | 26 - tests/ui/issue_2356.stderr | 14 - tests/ui/issue_4266.rs | 43 - tests/ui/issue_4266.stderr | 27 - tests/ui/items_after_statement.rs | 73 - tests/ui/items_after_statement.stderr | 37 - .../after_proc_macros.rs | 11 - .../auxiliary/submodule.rs | 4 - .../auxiliary/tests.rs | 1 - .../imported_module.rs | 20 - .../items_after_test_module/in_submodule.rs | 8 - .../in_submodule.stderr | 14 - .../multiple_modules.rs | 11 - .../items_after_test_module/root_module.fixed | 22 - .../ui/items_after_test_module/root_module.rs | 22 - .../root_module.stderr | 20 - tests/ui/iter_cloned_collect.fixed | 27 - tests/ui/iter_cloned_collect.rs | 30 - tests/ui/iter_cloned_collect.stderr | 39 - tests/ui/iter_count.fixed | 87 - tests/ui/iter_count.rs | 87 - tests/ui/iter_count.stderr | 155 - tests/ui/iter_filter_is_ok.fixed | 205 - tests/ui/iter_filter_is_ok.rs | 205 - tests/ui/iter_filter_is_ok.stderr | 77 - tests/ui/iter_filter_is_some.fixed | 241 - tests/ui/iter_filter_is_some.rs | 241 - tests/ui/iter_filter_is_some.stderr | 65 - tests/ui/iter_kv_map.fixed | 134 - tests/ui/iter_kv_map.rs | 138 - tests/ui/iter_kv_map.stderr | 265 - tests/ui/iter_next_loop.rs | 16 - tests/ui/iter_next_loop.stderr | 9 - tests/ui/iter_next_slice.fixed | 24 - tests/ui/iter_next_slice.rs | 24 - tests/ui/iter_next_slice.stderr | 29 - tests/ui/iter_not_returning_iterator.rs | 78 - tests/ui/iter_not_returning_iterator.stderr | 23 - tests/ui/iter_nth.fixed | 60 - tests/ui/iter_nth.rs | 60 - tests/ui/iter_nth.stderr | 92 - tests/ui/iter_nth_zero.fixed | 44 - tests/ui/iter_nth_zero.rs | 44 - tests/ui/iter_nth_zero.stderr | 23 - tests/ui/iter_on_empty_collections.fixed | 62 - tests/ui/iter_on_empty_collections.rs | 62 - tests/ui/iter_on_empty_collections.stderr | 41 - tests/ui/iter_on_single_items.fixed | 62 - tests/ui/iter_on_single_items.rs | 62 - tests/ui/iter_on_single_items.stderr | 41 - tests/ui/iter_out_of_bounds.rs | 71 - tests/ui/iter_out_of_bounds.stderr | 119 - tests/ui/iter_over_hash_type.rs | 74 - tests/ui/iter_over_hash_type.stderr | 109 - tests/ui/iter_overeager_cloned.fixed | 80 - tests/ui/iter_overeager_cloned.rs | 81 - tests/ui/iter_overeager_cloned.stderr | 168 - tests/ui/iter_skip_next.fixed | 38 - tests/ui/iter_skip_next.rs | 38 - tests/ui/iter_skip_next.stderr | 47 - tests/ui/iter_skip_next_unfixable.rs | 22 - tests/ui/iter_skip_next_unfixable.stderr | 40 - tests/ui/iter_skip_zero.fixed | 24 - tests/ui/iter_skip_zero.rs | 24 - tests/ui/iter_skip_zero.stderr | 44 - tests/ui/iter_with_drain.fixed | 64 - tests/ui/iter_with_drain.rs | 64 - tests/ui/iter_with_drain.stderr | 41 - tests/ui/iter_without_into_iter.rs | 155 - tests/ui/iter_without_into_iter.stderr | 174 - tests/ui/iterator_step_by_zero.rs | 37 - tests/ui/iterator_step_by_zero.stderr | 47 - tests/ui/join_absolute_paths.rs | 30 - tests/ui/join_absolute_paths.stderr | 68 - tests/ui/large_const_arrays.fixed | 35 - tests/ui/large_const_arrays.rs | 35 - tests/ui/large_const_arrays.stderr | 77 - tests/ui/large_digit_groups.fixed | 30 - tests/ui/large_digit_groups.rs | 30 - tests/ui/large_digit_groups.stderr | 38 - tests/ui/large_enum_variant.32bit.stderr | 280 - tests/ui/large_enum_variant.64bit.stderr | 280 - tests/ui/large_enum_variant.rs | 165 - tests/ui/large_futures.fixed | 69 - tests/ui/large_futures.rs | 69 - tests/ui/large_futures.stderr | 85 - tests/ui/large_stack_arrays.rs | 105 - tests/ui/large_stack_arrays.stderr | 104 - tests/ui/large_stack_frames.rs | 55 - tests/ui/large_stack_frames.stderr | 42 - tests/ui/large_types_passed_by_value.rs | 66 - tests/ui/large_types_passed_by_value.stderr | 53 - tests/ui/legacy_numeric_constants.fixed | 117 - tests/ui/legacy_numeric_constants.rs | 117 - tests/ui/legacy_numeric_constants.stderr | 184 - .../ui/legacy_numeric_constants_unfixable.rs | 78 - .../legacy_numeric_constants_unfixable.stderr | 83 - tests/ui/len_without_is_empty.rs | 462 -- tests/ui/len_without_is_empty.stderr | 151 - tests/ui/len_zero.fixed | 228 - tests/ui/len_zero.rs | 228 - tests/ui/len_zero.stderr | 164 - tests/ui/len_zero_ranges.fixed | 15 - tests/ui/len_zero_ranges.rs | 15 - tests/ui/len_zero_ranges.stderr | 17 - tests/ui/let_and_return.fixed | 213 - tests/ui/let_and_return.rs | 213 - tests/ui/let_and_return.stderr | 82 - tests/ui/let_if_seq.rs | 140 - tests/ui/let_if_seq.stderr | 56 - tests/ui/let_underscore_future.rs | 23 - tests/ui/let_underscore_future.stderr | 28 - tests/ui/let_underscore_lock.rs | 45 - tests/ui/let_underscore_lock.stderr | 36 - tests/ui/let_underscore_must_use.rs | 107 - tests/ui/let_underscore_must_use.stderr | 100 - tests/ui/let_underscore_untyped.rs | 77 - tests/ui/let_underscore_untyped.stderr | 64 - tests/ui/let_unit.fixed | 197 - tests/ui/let_unit.rs | 197 - tests/ui/let_unit.stderr | 74 - tests/ui/let_with_type_underscore.rs | 42 - tests/ui/let_with_type_underscore.stderr | 64 - tests/ui/lines_filter_map_ok.fixed | 33 - tests/ui/lines_filter_map_ok.rs | 33 - tests/ui/lines_filter_map_ok.stderr | 76 - tests/ui/linkedlist.rs | 57 - tests/ui/linkedlist.stderr | 76 - tests/ui/literals.rs | 76 - tests/ui/literals.stderr | 172 - tests/ui/lossy_float_literal.fixed | 38 - tests/ui/lossy_float_literal.rs | 38 - tests/ui/lossy_float_literal.stderr | 71 - tests/ui/macro_use_imports.fixed | 48 - tests/ui/macro_use_imports.rs | 48 - tests/ui/macro_use_imports.stderr | 29 - tests/ui/macro_use_imports_expect.rs | 51 - tests/ui/manual_assert.edition2018.fixed | 76 - tests/ui/manual_assert.edition2018.stderr | 95 - tests/ui/manual_assert.edition2021.fixed | 76 - tests/ui/manual_assert.edition2021.stderr | 95 - tests/ui/manual_assert.rs | 95 - tests/ui/manual_async_fn.fixed | 115 - tests/ui/manual_async_fn.rs | 141 - tests/ui/manual_async_fn.stderr | 211 - tests/ui/manual_bits.fixed | 58 - tests/ui/manual_bits.rs | 58 - tests/ui/manual_bits.stderr | 179 - tests/ui/manual_c_str_literals.fixed | 60 - tests/ui/manual_c_str_literals.rs | 60 - tests/ui/manual_c_str_literals.stderr | 83 - tests/ui/manual_clamp.fixed | 439 -- tests/ui/manual_clamp.rs | 560 -- tests/ui/manual_clamp.stderr | 406 -- tests/ui/manual_filter.fixed | 158 - tests/ui/manual_filter.rs | 280 - tests/ui/manual_filter.stderr | 190 - tests/ui/manual_filter_map.fixed | 146 - tests/ui/manual_filter_map.rs | 163 - tests/ui/manual_filter_map.stderr | 267 - tests/ui/manual_find.rs | 26 - tests/ui/manual_find.stderr | 32 - tests/ui/manual_find_fixable.fixed | 181 - tests/ui/manual_find_fixable.rs | 241 - tests/ui/manual_find_fixable.stderr | 143 - tests/ui/manual_find_map.fixed | 125 - tests/ui/manual_find_map.rs | 138 - tests/ui/manual_find_map.stderr | 264 - tests/ui/manual_flatten.rs | 134 - tests/ui/manual_flatten.stderr | 209 - tests/ui/manual_float_methods.rs | 55 - tests/ui/manual_float_methods.stderr | 82 - tests/ui/manual_hash_one.fixed | 89 - tests/ui/manual_hash_one.rs | 89 - tests/ui/manual_hash_one.stderr | 56 - tests/ui/manual_instant_elapsed.fixed | 27 - tests/ui/manual_instant_elapsed.rs | 27 - tests/ui/manual_instant_elapsed.stderr | 17 - tests/ui/manual_is_ascii_check.fixed | 84 - tests/ui/manual_is_ascii_check.rs | 84 - tests/ui/manual_is_ascii_check.stderr | 177 - tests/ui/manual_is_variant_and.fixed | 51 - tests/ui/manual_is_variant_and.rs | 57 - tests/ui/manual_is_variant_and.stderr | 82 - tests/ui/manual_let_else.rs | 459 -- tests/ui/manual_let_else.stderr | 490 -- tests/ui/manual_let_else_match.fixed | 139 - tests/ui/manual_let_else_match.rs | 180 - tests/ui/manual_let_else_match.stderr | 106 - tests/ui/manual_let_else_question_mark.fixed | 83 - tests/ui/manual_let_else_question_mark.rs | 90 - tests/ui/manual_let_else_question_mark.stderr | 65 - tests/ui/manual_main_separator_str.fixed | 37 - tests/ui/manual_main_separator_str.rs | 37 - tests/ui/manual_main_separator_str.stderr | 29 - tests/ui/manual_map_option.fixed | 156 - tests/ui/manual_map_option.rs | 222 - tests/ui/manual_map_option.stderr | 199 - tests/ui/manual_map_option_2.fixed | 56 - tests/ui/manual_map_option_2.rs | 71 - tests/ui/manual_map_option_2.stderr | 65 - tests/ui/manual_memcpy/with_loop_counters.rs | 100 - .../manual_memcpy/with_loop_counters.stderr | 124 - .../ui/manual_memcpy/without_loop_counters.rs | 225 - .../without_loop_counters.stderr | 175 - tests/ui/manual_next_back.fixed | 34 - tests/ui/manual_next_back.rs | 34 - tests/ui/manual_next_back.stderr | 17 - tests/ui/manual_non_exhaustive_enum.rs | 88 - tests/ui/manual_non_exhaustive_enum.stderr | 47 - tests/ui/manual_non_exhaustive_struct.rs | 78 - tests/ui/manual_non_exhaustive_struct.stderr | 88 - tests/ui/manual_ok_or.fixed | 40 - tests/ui/manual_ok_or.rs | 44 - tests/ui/manual_ok_or.stderr | 51 - tests/ui/manual_range_patterns.fixed | 49 - tests/ui/manual_range_patterns.rs | 49 - tests/ui/manual_range_patterns.stderr | 124 - tests/ui/manual_rem_euclid.fixed | 80 - tests/ui/manual_rem_euclid.rs | 80 - tests/ui/manual_rem_euclid.stderr | 67 - tests/ui/manual_retain.fixed | 311 - tests/ui/manual_retain.rs | 317 - tests/ui/manual_retain.stderr | 239 - tests/ui/manual_saturating_arithmetic.fixed | 43 - tests/ui/manual_saturating_arithmetic.rs | 53 - tests/ui/manual_saturating_arithmetic.stderr | 164 - tests/ui/manual_slice_size_calculation.fixed | 45 - tests/ui/manual_slice_size_calculation.rs | 45 - tests/ui/manual_slice_size_calculation.stderr | 47 - tests/ui/manual_split_once.fixed | 144 - tests/ui/manual_split_once.rs | 144 - tests/ui/manual_split_once.stderr | 214 - tests/ui/manual_str_repeat.fixed | 64 - tests/ui/manual_str_repeat.rs | 64 - tests/ui/manual_str_repeat.stderr | 65 - tests/ui/manual_string_new.fixed | 62 - tests/ui/manual_string_new.rs | 62 - tests/ui/manual_string_new.stderr | 59 - tests/ui/manual_strip.rs | 90 - tests/ui/manual_strip.stderr | 154 - tests/ui/manual_swap_auto_fix.fixed | 57 - tests/ui/manual_swap_auto_fix.rs | 72 - tests/ui/manual_swap_auto_fix.stderr | 88 - tests/ui/manual_try_fold.rs | 128 - tests/ui/manual_try_fold.stderr | 29 - tests/ui/manual_unwrap_or.fixed | 185 - tests/ui/manual_unwrap_or.rs | 227 - tests/ui/manual_unwrap_or.stderr | 156 - tests/ui/manual_unwrap_or_default.fixed | 74 - tests/ui/manual_unwrap_or_default.rs | 98 - tests/ui/manual_unwrap_or_default.stderr | 66 - tests/ui/manual_while_let_some.fixed | 91 - tests/ui/manual_while_let_some.rs | 91 - tests/ui/manual_while_let_some.stderr | 88 - tests/ui/many_single_char_names.rs | 82 - tests/ui/many_single_char_names.stderr | 55 - tests/ui/map_clone.fixed | 158 - tests/ui/map_clone.rs | 158 - tests/ui/map_clone.stderr | 95 - tests/ui/map_collect_result_unit.fixed | 15 - tests/ui/map_collect_result_unit.rs | 15 - tests/ui/map_collect_result_unit.stderr | 17 - tests/ui/map_err.rs | 30 - tests/ui/map_err.stderr | 12 - tests/ui/map_flatten.rs | 60 - tests/ui/map_flatten.stderr | 106 - tests/ui/map_flatten_fixable.fixed | 63 - tests/ui/map_flatten_fixable.rs | 65 - tests/ui/map_flatten_fixable.stderr | 100 - tests/ui/map_identity.fixed | 63 - tests/ui/map_identity.rs | 67 - tests/ui/map_identity.stderr | 77 - tests/ui/map_unit_fn.rs | 11 - tests/ui/map_unwrap_or.rs | 143 - tests/ui/map_unwrap_or.stderr | 193 - tests/ui/map_unwrap_or_fixable.fixed | 53 - tests/ui/map_unwrap_or_fixable.rs | 57 - tests/ui/map_unwrap_or_fixable.stderr | 23 - tests/ui/match_as_ref.fixed | 43 - tests/ui/match_as_ref.rs | 52 - tests/ui/match_as_ref.stderr | 34 - tests/ui/match_bool.rs | 74 - tests/ui/match_bool.stderr | 123 - tests/ui/match_expr_like_matches_macro.fixed | 212 - tests/ui/match_expr_like_matches_macro.rs | 256 - tests/ui/match_expr_like_matches_macro.stderr | 149 - tests/ui/match_on_vec_items.rs | 162 - tests/ui/match_on_vec_items.stderr | 53 - tests/ui/match_overlapping_arm.rs | 142 - tests/ui/match_overlapping_arm.stderr | 100 - tests/ui/match_ref_pats.fixed | 118 - tests/ui/match_ref_pats.rs | 118 - tests/ui/match_ref_pats.stderr | 70 - tests/ui/match_result_ok.fixed | 61 - tests/ui/match_result_ok.rs | 61 - tests/ui/match_result_ok.stderr | 37 - tests/ui/match_same_arms.rs | 139 - tests/ui/match_same_arms.stderr | 130 - tests/ui/match_same_arms2.fixed | 241 - tests/ui/match_same_arms2.rs | 264 - tests/ui/match_same_arms2.stderr | 225 - tests/ui/match_same_arms_non_exhaustive.fixed | 61 - tests/ui/match_same_arms_non_exhaustive.rs | 63 - .../ui/match_same_arms_non_exhaustive.stderr | 32 - tests/ui/match_single_binding.fixed | 173 - tests/ui/match_single_binding.rs | 207 - tests/ui/match_single_binding.stderr | 318 - tests/ui/match_single_binding2.fixed | 52 - tests/ui/match_single_binding2.rs | 54 - tests/ui/match_single_binding2.stderr | 69 - tests/ui/match_str_case_mismatch.fixed | 185 - tests/ui/match_str_case_mismatch.rs | 185 - tests/ui/match_str_case_mismatch.stderr | 81 - tests/ui/match_wild_err_arm.rs | 86 - tests/ui/match_wild_err_arm.stderr | 36 - .../match_wildcard_for_single_variants.fixed | 154 - .../ui/match_wildcard_for_single_variants.rs | 154 - .../match_wildcard_for_single_variants.stderr | 65 - tests/ui/mem_forget.rs | 34 - tests/ui/mem_forget.stderr | 36 - tests/ui/mem_replace.fixed | 132 - tests/ui/mem_replace.rs | 132 - tests/ui/mem_replace.stderr | 152 - tests/ui/mem_replace_macro.rs | 12 - tests/ui/mem_replace_macro.stderr | 12 - tests/ui/mem_replace_no_std.fixed | 82 - tests/ui/mem_replace_no_std.rs | 82 - tests/ui/mem_replace_no_std.stderr | 50 - tests/ui/methods.rs | 139 - tests/ui/methods.stderr | 26 - tests/ui/methods_fixable.fixed | 10 - tests/ui/methods_fixable.rs | 10 - tests/ui/methods_fixable.stderr | 11 - tests/ui/methods_unfixable.rs | 11 - tests/ui/methods_unfixable.stderr | 16 - tests/ui/min_ident_chars.rs | 94 - tests/ui/min_ident_chars.stderr | 197 - tests/ui/min_max.rs | 75 - tests/ui/min_max.stderr | 83 - tests/ui/min_rust_version_attr.rs | 68 - tests/ui/min_rust_version_attr.stderr | 51 - tests/ui/min_rust_version_invalid_attr.rs | 24 - tests/ui/min_rust_version_invalid_attr.stderr | 38 - tests/ui/mismatched_target_os_non_unix.fixed | 25 - tests/ui/mismatched_target_os_non_unix.rs | 25 - tests/ui/mismatched_target_os_non_unix.stderr | 37 - tests/ui/mismatched_target_os_unix.fixed | 60 - tests/ui/mismatched_target_os_unix.rs | 60 - tests/ui/mismatched_target_os_unix.stderr | 184 - tests/ui/mismatching_type_param_order.rs | 74 - tests/ui/mismatching_type_param_order.stderr | 84 - tests/ui/misnamed_getters.fixed | 144 - tests/ui/misnamed_getters.rs | 144 - tests/ui/misnamed_getters.stderr | 186 - tests/ui/missing_assert_message.rs | 99 - tests/ui/missing_assert_message.stderr | 132 - tests/ui/missing_asserts_for_indexing.fixed | 136 - tests/ui/missing_asserts_for_indexing.rs | 136 - tests/ui/missing_asserts_for_indexing.stderr | 305 - .../missing_asserts_for_indexing_unfixable.rs | 71 - ...sing_asserts_for_indexing_unfixable.stderr | 183 - .../missing_const_for_fn/auxiliary/helper.rs | 8 - .../ui/missing_const_for_fn/cant_be_const.rs | 167 - .../ui/missing_const_for_fn/could_be_const.rs | 115 - .../could_be_const.stderr | 106 - tests/ui/missing_doc.rs | 126 - tests/ui/missing_doc.stderr | 92 - tests/ui/missing_doc_crate.rs | 4 - tests/ui/missing_doc_crate_missing.rs | 5 - tests/ui/missing_doc_crate_missing.stderr | 15 - tests/ui/missing_doc_impl.rs | 107 - tests/ui/missing_doc_impl.stderr | 54 - tests/ui/missing_fields_in_debug.rs | 194 - tests/ui/missing_fields_in_debug.stderr | 74 - tests/ui/missing_inline.rs | 79 - tests/ui/missing_inline.stderr | 41 - tests/ui/missing_inline_executable.rs | 5 - tests/ui/missing_inline_proc_macro.rs | 22 - tests/ui/missing_panics_doc.rs | 201 - tests/ui/missing_panics_doc.stderr | 148 - tests/ui/missing_spin_loop.fixed | 27 - tests/ui/missing_spin_loop.rs | 27 - tests/ui/missing_spin_loop.stderr | 41 - tests/ui/missing_spin_loop_no_std.fixed | 22 - tests/ui/missing_spin_loop_no_std.rs | 22 - tests/ui/missing_spin_loop_no_std.stderr | 11 - tests/ui/missing_trait_methods.rs | 52 - tests/ui/missing_trait_methods.stderr | 28 - tests/ui/missing_transmute_annotations.fixed | 78 - tests/ui/missing_transmute_annotations.rs | 78 - tests/ui/missing_transmute_annotations.stderr | 76 - tests/ui/mistyped_literal_suffix.fixed | 48 - tests/ui/mistyped_literal_suffix.rs | 48 - tests/ui/mistyped_literal_suffix.stderr | 100 - tests/ui/mixed_attributes_style.rs | 100 - tests/ui/mixed_attributes_style.stderr | 63 - .../auxiliary/submodule.rs | 9 - .../ui/mixed_attributes_style/global_allow.rs | 7 - .../mixed_attributes_style/mod_declaration.rs | 3 - .../mod_declaration.stderr | 14 - tests/ui/mixed_read_write_in_expression.rs | 116 - .../ui/mixed_read_write_in_expression.stderr | 52 - tests/ui/module_inception.rs | 38 - tests/ui/module_inception.stderr | 42 - tests/ui/module_name_repetitions.rs | 38 - tests/ui/module_name_repetitions.stderr | 35 - tests/ui/modulo_arithmetic_float.rs | 49 - tests/ui/modulo_arithmetic_float.stderr | 84 - tests/ui/modulo_arithmetic_integral.rs | 125 - tests/ui/modulo_arithmetic_integral.stderr | 157 - tests/ui/modulo_arithmetic_integral_const.rs | 76 - .../modulo_arithmetic_integral_const.stderr | 157 - tests/ui/modulo_one.rs | 38 - tests/ui/modulo_one.stderr | 55 - tests/ui/multi_assignments.rs | 16 - tests/ui/multi_assignments.stderr | 41 - tests/ui/multiple_bound_locations.rs | 60 - tests/ui/multiple_bound_locations.stderr | 59 - tests/ui/multiple_unsafe_ops_per_block.rs | 158 - tests/ui/multiple_unsafe_ops_per_block.stderr | 190 - tests/ui/must_use_candidates.fixed | 92 - tests/ui/must_use_candidates.rs | 92 - tests/ui/must_use_candidates.stderr | 35 - tests/ui/must_use_unit.fixed | 25 - tests/ui/must_use_unit.rs | 28 - tests/ui/must_use_unit.stderr | 29 - tests/ui/mut_from_ref.rs | 60 - tests/ui/mut_from_ref.stderr | 76 - tests/ui/mut_key.rs | 104 - tests/ui/mut_key.stderr | 95 - tests/ui/mut_mut.rs | 88 - tests/ui/mut_mut.stderr | 61 - tests/ui/mut_mutex_lock.fixed | 27 - tests/ui/mut_mutex_lock.rs | 27 - tests/ui/mut_mutex_lock.stderr | 11 - tests/ui/mut_range_bound.rs | 100 - tests/ui/mut_range_bound.stderr | 60 - tests/ui/mut_reference.rs | 60 - tests/ui/mut_reference.stderr | 23 - tests/ui/mutex_atomic.rs | 41 - tests/ui/mutex_atomic.stderr | 74 - tests/ui/needless_arbitrary_self_type.fixed | 67 - tests/ui/needless_arbitrary_self_type.rs | 67 - tests/ui/needless_arbitrary_self_type.stderr | 41 - ...edless_arbitrary_self_type_unfixable.fixed | 46 - .../needless_arbitrary_self_type_unfixable.rs | 46 - ...dless_arbitrary_self_type_unfixable.stderr | 11 - tests/ui/needless_bitwise_bool.fixed | 39 - tests/ui/needless_bitwise_bool.rs | 39 - tests/ui/needless_bitwise_bool.stderr | 11 - tests/ui/needless_bool/fixable.fixed | 133 - tests/ui/needless_bool/fixable.rs | 193 - tests/ui/needless_bool/fixable.stderr | 195 - tests/ui/needless_bool/simple.rs | 47 - tests/ui/needless_bool/simple.stderr | 45 - tests/ui/needless_bool_assign.fixed | 31 - tests/ui/needless_bool_assign.rs | 43 - tests/ui/needless_bool_assign.stderr | 55 - tests/ui/needless_borrow.fixed | 261 - tests/ui/needless_borrow.rs | 261 - tests/ui/needless_borrow.stderr | 173 - tests/ui/needless_borrow_pat.fixed | 163 - tests/ui/needless_borrow_pat.rs | 163 - tests/ui/needless_borrow_pat.stderr | 117 - tests/ui/needless_borrowed_ref.fixed | 122 - tests/ui/needless_borrowed_ref.rs | 122 - tests/ui/needless_borrowed_ref.stderr | 215 - .../needless_borrows_for_generic_args.fixed | 336 - tests/ui/needless_borrows_for_generic_args.rs | 336 - .../needless_borrows_for_generic_args.stderr | 71 - tests/ui/needless_collect.fixed | 80 - tests/ui/needless_collect.rs | 80 - tests/ui/needless_collect.stderr | 119 - tests/ui/needless_collect_indirect.rs | 324 - tests/ui/needless_collect_indirect.stderr | 272 - tests/ui/needless_continue.rs | 153 - tests/ui/needless_continue.stderr | 140 - tests/ui/needless_doc_main.rs | 146 - tests/ui/needless_doc_main.stderr | 47 - tests/ui/needless_else.fixed | 56 - tests/ui/needless_else.rs | 57 - tests/ui/needless_else.stderr | 13 - tests/ui/needless_for_each_fixable.fixed | 122 - tests/ui/needless_for_each_fixable.rs | 122 - tests/ui/needless_for_each_fixable.stderr | 124 - tests/ui/needless_for_each_unfixable.rs | 17 - tests/ui/needless_for_each_unfixable.stderr | 33 - tests/ui/needless_if.fixed | 102 - tests/ui/needless_if.rs | 103 - tests/ui/needless_if.stderr | 75 - tests/ui/needless_late_init.fixed | 272 - tests/ui/needless_late_init.rs | 272 - tests/ui/needless_late_init.stderr | 260 - tests/ui/needless_lifetimes.fixed | 546 -- tests/ui/needless_lifetimes.rs | 546 -- tests/ui/needless_lifetimes.stderr | 557 -- tests/ui/needless_match.fixed | 248 - tests/ui/needless_match.rs | 292 - tests/ui/needless_match.stderr | 135 - tests/ui/needless_option_as_deref.fixed | 54 - tests/ui/needless_option_as_deref.rs | 54 - tests/ui/needless_option_as_deref.stderr | 23 - tests/ui/needless_option_take.fixed | 13 - tests/ui/needless_option_take.rs | 13 - tests/ui/needless_option_take.stderr | 11 - .../needless_parens_on_range_literals.fixed | 13 - tests/ui/needless_parens_on_range_literals.rs | 13 - .../needless_parens_on_range_literals.stderr | 41 - tests/ui/needless_pass_by_ref_mut.rs | 369 - tests/ui/needless_pass_by_ref_mut.stderr | 219 - tests/ui/needless_pass_by_ref_mut2.fixed | 24 - tests/ui/needless_pass_by_ref_mut2.rs | 24 - tests/ui/needless_pass_by_ref_mut2.stderr | 20 - tests/ui/needless_pass_by_value.rs | 184 - tests/ui/needless_pass_by_value.stderr | 179 - tests/ui/needless_pass_by_value_proc_macro.rs | 20 - tests/ui/needless_pub_self.fixed | 33 - tests/ui/needless_pub_self.rs | 33 - tests/ui/needless_pub_self.stderr | 23 - tests/ui/needless_question_mark.fixed | 141 - tests/ui/needless_question_mark.rs | 141 - tests/ui/needless_question_mark.stderr | 100 - tests/ui/needless_range_loop.rs | 173 - tests/ui/needless_range_loop.stderr | 158 - tests/ui/needless_range_loop2.rs | 119 - tests/ui/needless_range_loop2.stderr | 92 - tests/ui/needless_raw_string.fixed | 24 - tests/ui/needless_raw_string.rs | 24 - tests/ui/needless_raw_string.stderr | 95 - tests/ui/needless_raw_string_hashes.fixed | 26 - tests/ui/needless_raw_string_hashes.rs | 26 - tests/ui/needless_raw_string_hashes.stderr | 191 - tests/ui/needless_return.fixed | 326 - tests/ui/needless_return.rs | 336 - tests/ui/needless_return.stderr | 657 -- .../needless_return_with_question_mark.fixed | 129 - .../ui/needless_return_with_question_mark.rs | 129 - .../needless_return_with_question_mark.stderr | 17 - tests/ui/needless_splitn.fixed | 45 - tests/ui/needless_splitn.rs | 45 - tests/ui/needless_splitn.stderr | 83 - tests/ui/needless_update.rs | 27 - tests/ui/needless_update.stderr | 11 - tests/ui/neg_cmp_op_on_partial_ord.rs | 67 - tests/ui/neg_cmp_op_on_partial_ord.stderr | 29 - tests/ui/neg_multiply.fixed | 47 - tests/ui/neg_multiply.rs | 47 - tests/ui/neg_multiply.stderr | 53 - tests/ui/never_loop.rs | 427 -- tests/ui/never_loop.stderr | 184 - tests/ui/new_ret_no_self.rs | 416 -- tests/ui/new_ret_no_self.stderr | 108 - tests/ui/new_ret_no_self_overflow.rs | 26 - tests/ui/new_ret_no_self_overflow.stderr | 9 - tests/ui/new_without_default.fixed | 315 - tests/ui/new_without_default.rs | 258 - tests/ui/new_without_default.stderr | 170 - tests/ui/no_effect.rs | 197 - tests/ui/no_effect.stderr | 170 - tests/ui/no_effect_async_fn.rs | 50 - tests/ui/no_effect_async_fn.stderr | 29 - tests/ui/no_effect_replace.rs | 60 - tests/ui/no_effect_replace.stderr | 53 - tests/ui/no_effect_return.rs | 93 - tests/ui/no_effect_return.stderr | 69 - tests/ui/no_mangle_with_rust_abi.rs | 53 - tests/ui/no_mangle_with_rust_abi.stderr | 83 - tests/ui/non_canonical_clone_impl.fixed | 97 - tests/ui/non_canonical_clone_impl.rs | 107 - tests/ui/non_canonical_clone_impl.stderr | 41 - tests/ui/non_canonical_partial_ord_impl.fixed | 162 - tests/ui/non_canonical_partial_ord_impl.rs | 166 - .../ui/non_canonical_partial_ord_impl.stderr | 32 - ...n_canonical_partial_ord_impl_fully_qual.rs | 51 - ...nonical_partial_ord_impl_fully_qual.stderr | 32 - tests/ui/non_expressive_names.rs | 58 - tests/ui/non_expressive_names.stderr | 41 - tests/ui/non_minimal_cfg.fixed | 15 - tests/ui/non_minimal_cfg.rs | 15 - tests/ui/non_minimal_cfg.stderr | 29 - tests/ui/non_minimal_cfg2.rs | 8 - tests/ui/non_minimal_cfg2.stderr | 11 - tests/ui/non_octal_unix_permissions.fixed | 37 - tests/ui/non_octal_unix_permissions.rs | 37 - tests/ui/non_octal_unix_permissions.stderr | 29 - tests/ui/non_send_fields_in_send_ty.rs | 144 - tests/ui/non_send_fields_in_send_ty.stderr | 172 - tests/ui/nonminimal_bool.rs | 181 - tests/ui/nonminimal_bool.stderr | 217 - tests/ui/nonminimal_bool_methods.fixed | 120 - tests/ui/nonminimal_bool_methods.rs | 120 - tests/ui/nonminimal_bool_methods.stderr | 101 - tests/ui/numbered_fields.fixed | 37 - tests/ui/numbered_fields.rs | 45 - tests/ui/numbered_fields.stderr | 27 - tests/ui/obfuscated_if_else.fixed | 5 - tests/ui/obfuscated_if_else.rs | 5 - tests/ui/obfuscated_if_else.stderr | 11 - tests/ui/octal_escapes.rs | 31 - tests/ui/octal_escapes.stderr | 148 - tests/ui/ok_expect.rs | 34 - tests/ui/ok_expect.stderr | 44 - tests/ui/only_used_in_recursion.rs | 129 - tests/ui/only_used_in_recursion.stderr | 196 - tests/ui/only_used_in_recursion2.rs | 96 - tests/ui/only_used_in_recursion2.stderr | 64 - tests/ui/op_ref.fixed | 99 - tests/ui/op_ref.rs | 99 - tests/ui/op_ref.stderr | 39 - tests/ui/open_options.rs | 52 - tests/ui/open_options.stderr | 53 - tests/ui/open_options_fixable.fixed | 7 - tests/ui/open_options_fixable.rs | 7 - tests/ui/open_options_fixable.stderr | 14 - tests/ui/option_as_ref_cloned.fixed | 21 - tests/ui/option_as_ref_cloned.rs | 21 - tests/ui/option_as_ref_cloned.stderr | 37 - tests/ui/option_as_ref_deref.fixed | 54 - tests/ui/option_as_ref_deref.rs | 57 - tests/ui/option_as_ref_deref.stderr | 117 - tests/ui/option_env_unwrap.rs | 17 - tests/ui/option_env_unwrap.stderr | 64 - tests/ui/option_filter_map.fixed | 30 - tests/ui/option_filter_map.rs | 34 - tests/ui/option_filter_map.stderr | 59 - tests/ui/option_if_let_else.fixed | 255 - tests/ui/option_if_let_else.rs | 306 - tests/ui/option_if_let_else.stderr | 317 - tests/ui/option_map_or_err_ok.fixed | 7 - tests/ui/option_map_or_err_ok.rs | 7 - tests/ui/option_map_or_err_ok.stderr | 11 - tests/ui/option_map_or_none.fixed | 24 - tests/ui/option_map_or_none.rs | 26 - tests/ui/option_map_or_none.stderr | 55 - tests/ui/option_map_unit_fn_fixable.fixed | 86 - tests/ui/option_map_unit_fn_fixable.rs | 86 - tests/ui/option_map_unit_fn_fixable.stderr | 157 - tests/ui/option_map_unit_fn_unfixable.rs | 39 - tests/ui/option_map_unit_fn_unfixable.stderr | 27 - tests/ui/option_option.rs | 101 - tests/ui/option_option.stderr | 80 - tests/ui/or_fun_call.fixed | 314 - tests/ui/or_fun_call.rs | 314 - tests/ui/or_fun_call.stderr | 194 - tests/ui/or_then_unwrap.fixed | 50 - tests/ui/or_then_unwrap.rs | 50 - tests/ui/or_then_unwrap.stderr | 23 - tests/ui/out_of_bounds_indexing/issue-3102.rs | 14 - .../out_of_bounds_indexing/issue-3102.stderr | 17 - tests/ui/out_of_bounds_indexing/simple.rs | 29 - tests/ui/out_of_bounds_indexing/simple.stderr | 41 - tests/ui/overflow_check_conditional.rs | 36 - tests/ui/overflow_check_conditional.stderr | 53 - tests/ui/overly_complex_bool_expr.fixed | 39 - tests/ui/overly_complex_bool_expr.rs | 39 - tests/ui/overly_complex_bool_expr.stderr | 64 - tests/ui/panic_in_result_fn.rs | 72 - tests/ui/panic_in_result_fn.stderr | 38 - tests/ui/panic_in_result_fn_assertions.rs | 51 - tests/ui/panic_in_result_fn_assertions.stderr | 58 - .../ui/panic_in_result_fn_debug_assertions.rs | 43 - tests/ui/panicking_macros.rs | 114 - tests/ui/panicking_macros.stderr | 110 - tests/ui/partial_pub_fields.rs | 44 - tests/ui/partial_pub_fields.stderr | 36 - tests/ui/partialeq_ne_impl.rs | 28 - tests/ui/partialeq_ne_impl.stderr | 15 - tests/ui/partialeq_to_none.fixed | 74 - tests/ui/partialeq_to_none.rs | 74 - tests/ui/partialeq_to_none.stderr | 111 - tests/ui/path_buf_push_overwrite.fixed | 7 - tests/ui/path_buf_push_overwrite.rs | 7 - tests/ui/path_buf_push_overwrite.stderr | 11 - tests/ui/path_ends_with_ext.fixed | 36 - tests/ui/path_ends_with_ext.rs | 36 - tests/ui/path_ends_with_ext.stderr | 17 - tests/ui/pattern_type_mismatch/mutability.rs | 51 - .../pattern_type_mismatch/mutability.stderr | 20 - .../pattern_alternatives.rs | 27 - .../pattern_alternatives.stderr | 28 - .../pattern_type_mismatch/pattern_structs.rs | 53 - .../pattern_structs.stderr | 68 - .../pattern_type_mismatch/pattern_tuples.rs | 67 - .../pattern_tuples.stderr | 84 - tests/ui/pattern_type_mismatch/syntax.rs | 154 - tests/ui/pattern_type_mismatch/syntax.stderr | 80 - tests/ui/patterns.fixed | 47 - tests/ui/patterns.rs | 47 - tests/ui/patterns.stderr | 23 - tests/ui/permissions_set_readonly_false.rs | 31 - .../ui/permissions_set_readonly_false.stderr | 14 - tests/ui/precedence.fixed | 60 - tests/ui/precedence.rs | 60 - tests/ui/precedence.stderr | 77 - tests/ui/print.rs | 45 - tests/ui/print.stderr | 56 - tests/ui/print_in_format_impl.rs | 66 - tests/ui/print_in_format_impl.stderr | 47 - tests/ui/print_literal.fixed | 68 - tests/ui/print_literal.rs | 68 - tests/ui/print_literal.stderr | 196 - tests/ui/print_stderr.rs | 11 - tests/ui/print_stderr.stderr | 17 - tests/ui/print_stdout_build_script.rs | 12 - tests/ui/print_with_newline.fixed | 72 - tests/ui/print_with_newline.rs | 74 - tests/ui/print_with_newline.stderr | 122 - tests/ui/println_empty_string.fixed | 17 - tests/ui/println_empty_string.rs | 17 - tests/ui/println_empty_string.stderr | 37 - tests/ui/proc_macro.rs | 26 - tests/ui/proc_macro.stderr | 11 - tests/ui/ptr_arg.rs | 312 - tests/ui/ptr_arg.stderr | 216 - tests/ui/ptr_as_ptr.fixed | 188 - tests/ui/ptr_as_ptr.rs | 188 - tests/ui/ptr_as_ptr.stderr | 205 - tests/ui/ptr_cast_constness.fixed | 66 - tests/ui/ptr_cast_constness.rs | 66 - tests/ui/ptr_cast_constness.stderr | 47 - tests/ui/ptr_eq.fixed | 37 - tests/ui/ptr_eq.rs | 37 - tests/ui/ptr_eq.stderr | 17 - tests/ui/ptr_eq_no_std.fixed | 49 - tests/ui/ptr_eq_no_std.rs | 49 - tests/ui/ptr_eq_no_std.stderr | 17 - tests/ui/ptr_offset_with_cast.fixed | 20 - tests/ui/ptr_offset_with_cast.rs | 20 - tests/ui/ptr_offset_with_cast.stderr | 17 - tests/ui/pub_use.rs | 15 - tests/ui/pub_use.stderr | 12 - tests/ui/pub_with_shorthand.fixed | 38 - tests/ui/pub_with_shorthand.rs | 38 - tests/ui/pub_with_shorthand.stderr | 29 - tests/ui/pub_without_shorthand.fixed | 38 - tests/ui/pub_without_shorthand.rs | 38 - tests/ui/pub_without_shorthand.stderr | 23 - tests/ui/question_mark.fixed | 319 - tests/ui/question_mark.rs | 361 - tests/ui/question_mark.stderr | 153 - tests/ui/question_mark_used.rs | 16 - tests/ui/question_mark_used.stderr | 12 - tests/ui/range.rs | 19 - tests/ui/range.stderr | 11 - tests/ui/range_contains.fixed | 77 - tests/ui/range_contains.rs | 77 - tests/ui/range_contains.stderr | 131 - tests/ui/range_plus_minus_one.fixed | 59 - tests/ui/range_plus_minus_one.rs | 59 - tests/ui/range_plus_minus_one.stderr | 62 - tests/ui/rc_buffer.fixed | 27 - tests/ui/rc_buffer.rs | 27 - tests/ui/rc_buffer.stderr | 53 - tests/ui/rc_buffer_arc.fixed | 26 - tests/ui/rc_buffer_arc.rs | 26 - tests/ui/rc_buffer_arc.stderr | 53 - tests/ui/rc_buffer_redefined_string.rs | 12 - tests/ui/rc_clone_in_vec_init/arc.rs | 78 - tests/ui/rc_clone_in_vec_init/arc.stderr | 110 - tests/ui/rc_clone_in_vec_init/rc.rs | 79 - tests/ui/rc_clone_in_vec_init/rc.stderr | 110 - tests/ui/rc_clone_in_vec_init/weak.rs | 101 - tests/ui/rc_clone_in_vec_init/weak.stderr | 202 - tests/ui/rc_mutex.rs | 40 - tests/ui/rc_mutex.stderr | 36 - tests/ui/read_line_without_trim.fixed | 47 - tests/ui/read_line_without_trim.rs | 47 - tests/ui/read_line_without_trim.stderr | 102 - tests/ui/read_zero_byte_vec.rs | 121 - tests/ui/read_zero_byte_vec.stderr | 71 - tests/ui/readonly_write_lock.fixed | 49 - tests/ui/readonly_write_lock.rs | 49 - tests/ui/readonly_write_lock.stderr | 17 - tests/ui/recursive_format_impl.rs | 334 - tests/ui/recursive_format_impl.stderr | 83 - tests/ui/redundant_allocation.rs | 167 - tests/ui/redundant_allocation.stderr | 184 - tests/ui/redundant_allocation_fixable.fixed | 68 - tests/ui/redundant_allocation_fixable.rs | 68 - tests/ui/redundant_allocation_fixable.stderr | 100 - tests/ui/redundant_as_str.fixed | 25 - tests/ui/redundant_as_str.rs | 25 - tests/ui/redundant_as_str.stderr | 17 - tests/ui/redundant_async_block.fixed | 197 - tests/ui/redundant_async_block.rs | 197 - tests/ui/redundant_async_block.stderr | 75 - tests/ui/redundant_at_rest_pattern.fixed | 26 - tests/ui/redundant_at_rest_pattern.rs | 26 - tests/ui/redundant_at_rest_pattern.stderr | 41 - tests/ui/redundant_clone.fixed | 246 - tests/ui/redundant_clone.rs | 246 - tests/ui/redundant_clone.stderr | 184 - tests/ui/redundant_closure_call_early.rs | 23 - tests/ui/redundant_closure_call_early.stderr | 17 - tests/ui/redundant_closure_call_fixable.fixed | 130 - tests/ui/redundant_closure_call_fixable.rs | 130 - .../ui/redundant_closure_call_fixable.stderr | 145 - tests/ui/redundant_closure_call_late.rs | 44 - tests/ui/redundant_closure_call_late.stderr | 23 - tests/ui/redundant_else.rs | 161 - tests/ui/redundant_else.stderr | 88 - tests/ui/redundant_field_names.fixed | 100 - tests/ui/redundant_field_names.rs | 100 - tests/ui/redundant_field_names.stderr | 64 - tests/ui/redundant_guards.fixed | 319 - tests/ui/redundant_guards.rs | 319 - tests/ui/redundant_guards.stderr | 339 - tests/ui/redundant_locals.rs | 217 - tests/ui/redundant_locals.stderr | 172 - ...edundant_pattern_matching_drop_order.fixed | 61 - .../redundant_pattern_matching_drop_order.rs | 61 - ...dundant_pattern_matching_drop_order.stderr | 172 - ...dundant_pattern_matching_if_let_true.fixed | 38 - .../redundant_pattern_matching_if_let_true.rs | 38 - ...undant_pattern_matching_if_let_true.stderr | 47 - .../redundant_pattern_matching_ipaddr.fixed | 80 - tests/ui/redundant_pattern_matching_ipaddr.rs | 98 - .../redundant_pattern_matching_ipaddr.stderr | 143 - .../redundant_pattern_matching_option.fixed | 139 - tests/ui/redundant_pattern_matching_option.rs | 166 - .../redundant_pattern_matching_option.stderr | 213 - .../ui/redundant_pattern_matching_poll.fixed | 81 - tests/ui/redundant_pattern_matching_poll.rs | 96 - .../ui/redundant_pattern_matching_poll.stderr | 141 - .../redundant_pattern_matching_result.fixed | 150 - tests/ui/redundant_pattern_matching_result.rs | 180 - .../redundant_pattern_matching_result.stderr | 203 - tests/ui/redundant_pub_crate.fixed | 116 - tests/ui/redundant_pub_crate.rs | 116 - tests/ui/redundant_pub_crate.stderr | 133 - tests/ui/redundant_slicing.fixed | 44 - tests/ui/redundant_slicing.rs | 44 - tests/ui/redundant_slicing.stderr | 23 - tests/ui/redundant_static_lifetimes.fixed | 70 - tests/ui/redundant_static_lifetimes.rs | 70 - tests/ui/redundant_static_lifetimes.stderr | 113 - .../ui/redundant_static_lifetimes_multiple.rs | 25 - ...redundant_static_lifetimes_multiple.stderr | 65 - tests/ui/redundant_type_annotations.rs | 213 - tests/ui/redundant_type_annotations.stderr | 107 - tests/ui/ref_as_ptr.fixed | 116 - tests/ui/ref_as_ptr.rs | 116 - tests/ui/ref_as_ptr.stderr | 269 - tests/ui/ref_binding_to_reference.rs | 93 - tests/ui/ref_binding_to_reference.stderr | 94 - tests/ui/ref_option_ref.rs | 64 - tests/ui/ref_option_ref.stderr | 71 - tests/ui/ref_patterns.rs | 22 - tests/ui/ref_patterns.stderr | 28 - tests/ui/regex.rs | 124 - tests/ui/regex.stderr | 199 - tests/ui/rename.fixed | 115 - tests/ui/rename.rs | 115 - tests/ui/rename.stderr | 353 - tests/ui/renamed_builtin_attr.fixed | 4 - tests/ui/renamed_builtin_attr.rs | 4 - tests/ui/renamed_builtin_attr.stderr | 8 - tests/ui/repeat_once.fixed | 15 - tests/ui/repeat_once.rs | 15 - tests/ui/repeat_once.stderr | 41 - tests/ui/repeat_vec_with_capacity.fixed | 38 - tests/ui/repeat_vec_with_capacity.rs | 38 - tests/ui/repeat_vec_with_capacity.stderr | 40 - tests/ui/repl_uninit.rs | 46 - tests/ui/repl_uninit.stderr | 31 - tests/ui/reserve_after_initialization.fixed | 48 - tests/ui/reserve_after_initialization.rs | 51 - tests/ui/reserve_after_initialization.stderr | 26 - tests/ui/rest_pat_in_fully_bound_structs.rs | 61 - .../ui/rest_pat_in_fully_bound_structs.stderr | 28 - tests/ui/result_filter_map.fixed | 27 - tests/ui/result_filter_map.rs | 35 - tests/ui/result_filter_map.stderr | 41 - tests/ui/result_large_err.rs | 131 - tests/ui/result_large_err.stderr | 108 - tests/ui/result_map_or_into_option.fixed | 24 - tests/ui/result_map_or_into_option.rs | 24 - tests/ui/result_map_or_into_option.stderr | 23 - tests/ui/result_map_unit_fn_fixable.fixed | 81 - tests/ui/result_map_unit_fn_fixable.rs | 81 - tests/ui/result_map_unit_fn_fixable.stderr | 149 - tests/ui/result_map_unit_fn_unfixable.rs | 53 - tests/ui/result_map_unit_fn_unfixable.stderr | 57 - tests/ui/result_unit_error.rs | 61 - tests/ui/result_unit_error.stderr | 44 - tests/ui/return_self_not_must_use.rs | 61 - tests/ui/return_self_not_must_use.stderr | 34 - tests/ui/reversed_empty_ranges_fixable.fixed | 29 - tests/ui/reversed_empty_ranges_fixable.rs | 29 - tests/ui/reversed_empty_ranges_fixable.stderr | 48 - .../reversed_empty_ranges_loops_fixable.fixed | 57 - .../ui/reversed_empty_ranges_loops_fixable.rs | 57 - ...reversed_empty_ranges_loops_fixable.stderr | 70 - .../reversed_empty_ranges_loops_unfixable.rs | 15 - ...versed_empty_ranges_loops_unfixable.stderr | 17 - tests/ui/reversed_empty_ranges_unfixable.rs | 19 - .../ui/reversed_empty_ranges_unfixable.stderr | 23 - tests/ui/same_functions_in_if_condition.rs | 117 - .../ui/same_functions_in_if_condition.stderr | 79 - tests/ui/same_item_push.rs | 164 - tests/ui/same_item_push.stderr | 44 - tests/ui/same_name_method.rs | 133 - tests/ui/same_name_method.stderr | 77 - tests/ui/search_is_some.rs | 80 - tests/ui/search_is_some.stderr | 88 - tests/ui/search_is_some_fixable_none.fixed | 265 - tests/ui/search_is_some_fixable_none.rs | 271 - tests/ui/search_is_some_fixable_none.stderr | 358 - tests/ui/search_is_some_fixable_some.fixed | 247 - tests/ui/search_is_some_fixable_some.rs | 250 - tests/ui/search_is_some_fixable_some.stderr | 293 - tests/ui/seek_from_current.fixed | 24 - tests/ui/seek_from_current.rs | 24 - tests/ui/seek_from_current.stderr | 11 - .../ui/seek_to_start_instead_of_rewind.fixed | 142 - tests/ui/seek_to_start_instead_of_rewind.rs | 142 - .../ui/seek_to_start_instead_of_rewind.stderr | 23 - tests/ui/self_assignment.rs | 80 - tests/ui/self_assignment.stderr | 71 - tests/ui/self_named_constructors.rs | 61 - tests/ui/self_named_constructors.stderr | 15 - tests/ui/semicolon_if_nothing_returned.fixed | 161 - tests/ui/semicolon_if_nothing_returned.rs | 161 - tests/ui/semicolon_if_nothing_returned.stderr | 35 - tests/ui/semicolon_inside_block.fixed | 84 - tests/ui/semicolon_inside_block.rs | 84 - tests/ui/semicolon_inside_block.stderr | 55 - tests/ui/semicolon_outside_block.fixed | 84 - tests/ui/semicolon_outside_block.rs | 84 - tests/ui/semicolon_outside_block.stderr | 55 - tests/ui/serde.rs | 49 - tests/ui/serde.stderr | 17 - tests/ui/shadow.rs | 122 - tests/ui/shadow.stderr | 284 - tests/ui/short_circuit_statement.fixed | 16 - tests/ui/short_circuit_statement.rs | 16 - tests/ui/short_circuit_statement.stderr | 23 - tests/ui/should_impl_trait/corner_cases.rs | 84 - tests/ui/should_impl_trait/method_list_1.rs | 102 - .../ui/should_impl_trait/method_list_1.stderr | 169 - tests/ui/should_impl_trait/method_list_2.rs | 103 - .../ui/should_impl_trait/method_list_2.stderr | 169 - tests/ui/should_panic_without_expect.rs | 21 - tests/ui/should_panic_without_expect.stderr | 14 - tests/ui/significant_drop_in_scrutinee.rs | 734 -- tests/ui/significant_drop_in_scrutinee.stderr | 525 -- tests/ui/significant_drop_tightening.fixed | 144 - tests/ui/significant_drop_tightening.rs | 140 - tests/ui/significant_drop_tightening.stderr | 95 - tests/ui/similar_names.rs | 126 - tests/ui/similar_names.stderr | 64 - tests/ui/single_call_fn.rs | 108 - tests/ui/single_call_fn.stderr | 80 - tests/ui/single_char_add_str.fixed | 45 - tests/ui/single_char_add_str.rs | 45 - tests/ui/single_char_add_str.stderr | 95 - tests/ui/single_char_lifetime_names.rs | 49 - tests/ui/single_char_lifetime_names.stderr | 44 - tests/ui/single_char_pattern.fixed | 69 - tests/ui/single_char_pattern.rs | 69 - tests/ui/single_char_pattern.stderr | 215 - tests/ui/single_component_path_imports.fixed | 41 - tests/ui/single_component_path_imports.rs | 42 - tests/ui/single_component_path_imports.stderr | 17 - .../ui/single_component_path_imports_macro.rs | 20 - ...gle_component_path_imports_nested_first.rs | 22 - ...component_path_imports_nested_first.stderr | 27 - ...ingle_component_path_imports_self_after.rs | 16 - ...ngle_component_path_imports_self_before.rs | 17 - tests/ui/single_element_loop.fixed | 60 - tests/ui/single_element_loop.rs | 57 - tests/ui/single_element_loop.stderr | 87 - tests/ui/single_match.fixed | 255 - tests/ui/single_match.rs | 313 - tests/ui/single_match.stderr | 202 - tests/ui/single_match_else.fixed | 173 - tests/ui/single_match_else.rs | 201 - tests/ui/single_match_else.stderr | 201 - tests/ui/single_range_in_vec_init.rs | 59 - tests/ui/single_range_in_vec_init.stderr | 146 - .../size_of_in_element_count/expressions.rs | 41 - .../expressions.stderr | 36 - .../ui/size_of_in_element_count/functions.rs | 67 - .../size_of_in_element_count/functions.stderr | 172 - tests/ui/size_of_ref.rs | 30 - tests/ui/size_of_ref.stderr | 28 - tests/ui/skip_while_next.rs | 29 - tests/ui/skip_while_next.stderr | 24 - tests/ui/slow_vector_initialization.rs | 112 - tests/ui/slow_vector_initialization.stderr | 109 - tests/ui/stable_sort_primitive.fixed | 32 - tests/ui/stable_sort_primitive.rs | 32 - tests/ui/stable_sort_primitive.stderr | 60 - tests/ui/starts_ends_with.fixed | 53 - tests/ui/starts_ends_with.rs | 53 - tests/ui/starts_ends_with.stderr | 104 - tests/ui/std_instead_of_core.fixed | 82 - tests/ui/std_instead_of_core.rs | 82 - tests/ui/std_instead_of_core.stderr | 83 - tests/ui/str_split.fixed | 145 - tests/ui/str_split.rs | 145 - tests/ui/str_split.stderr | 65 - tests/ui/str_to_string.rs | 9 - tests/ui/str_to_string.stderr | 20 - tests/ui/string_add.rs | 29 - tests/ui/string_add.stderr | 32 - tests/ui/string_add_assign.fixed | 19 - tests/ui/string_add_assign.rs | 19 - tests/ui/string_add_assign.stderr | 26 - tests/ui/string_extend.fixed | 33 - tests/ui/string_extend.rs | 33 - tests/ui/string_extend.stderr | 29 - tests/ui/string_from_utf8_as_bytes.fixed | 5 - tests/ui/string_from_utf8_as_bytes.rs | 5 - tests/ui/string_from_utf8_as_bytes.stderr | 11 - tests/ui/string_lit_as_bytes.fixed | 49 - tests/ui/string_lit_as_bytes.rs | 49 - tests/ui/string_lit_as_bytes.stderr | 52 - tests/ui/string_lit_chars_any.fixed | 49 - tests/ui/string_lit_chars_any.rs | 49 - tests/ui/string_lit_chars_any.stderr | 59 - tests/ui/string_slice.rs | 14 - tests/ui/string_slice.stderr | 23 - tests/ui/string_to_string.rs | 8 - tests/ui/string_to_string.stderr | 12 - tests/ui/strlen_on_c_strings.fixed | 32 - tests/ui/strlen_on_c_strings.rs | 32 - tests/ui/strlen_on_c_strings.stderr | 47 - tests/ui/struct_excessive_bools.rs | 46 - tests/ui/struct_excessive_bools.stderr | 32 - tests/ui/struct_fields.rs | 345 - tests/ui/struct_fields.stderr | 285 - tests/ui/suspicious_arithmetic_impl.rs | 182 - tests/ui/suspicious_arithmetic_impl.stderr | 62 - tests/ui/suspicious_command_arg_space.fixed | 13 - tests/ui/suspicious_command_arg_space.rs | 13 - tests/ui/suspicious_command_arg_space.stderr | 26 - tests/ui/suspicious_doc_comments.fixed | 80 - tests/ui/suspicious_doc_comments.rs | 80 - tests/ui/suspicious_doc_comments.stderr | 115 - tests/ui/suspicious_doc_comments_unfixable.rs | 19 - .../suspicious_doc_comments_unfixable.stderr | 44 - tests/ui/suspicious_else_formatting.rs | 155 - tests/ui/suspicious_else_formatting.stderr | 91 - tests/ui/suspicious_map.rs | 34 - tests/ui/suspicious_map.stderr | 20 - tests/ui/suspicious_operation_groupings.fixed | 210 - tests/ui/suspicious_operation_groupings.rs | 210 - .../ui/suspicious_operation_groupings.stderr | 161 - tests/ui/suspicious_splitn.rs | 39 - tests/ui/suspicious_splitn.stderr | 76 - tests/ui/suspicious_to_owned.rs | 71 - tests/ui/suspicious_to_owned.stderr | 79 - tests/ui/suspicious_unary_op_formatting.rs | 28 - .../ui/suspicious_unary_op_formatting.stderr | 36 - tests/ui/suspicious_xor_used_as_pow.rs | 41 - tests/ui/suspicious_xor_used_as_pow.stderr | 52 - tests/ui/swap.fixed | 202 - tests/ui/swap.rs | 231 - tests/ui/swap.stderr | 161 - tests/ui/swap_ptr_to_ref.fixed | 22 - tests/ui/swap_ptr_to_ref.rs | 22 - tests/ui/swap_ptr_to_ref.stderr | 29 - tests/ui/swap_ptr_to_ref_unfixable.rs | 22 - tests/ui/swap_ptr_to_ref_unfixable.stderr | 23 - tests/ui/tabs_in_doc_comments.fixed | 20 - tests/ui/tabs_in_doc_comments.rs | 20 - tests/ui/tabs_in_doc_comments.stderr | 53 - tests/ui/temporary_assignment.rs | 75 - tests/ui/temporary_assignment.stderr | 34 - tests/ui/test_attr_in_doctest.rs | 51 - tests/ui/test_attr_in_doctest.stderr | 29 - tests/ui/tests_outside_test_module.rs | 19 - tests/ui/tests_outside_test_module.stderr | 12 - ..._local_initializer_can_be_made_const.fixed | 75 - ...ead_local_initializer_can_be_made_const.rs | 75 - ...local_initializer_can_be_made_const.stderr | 41 - tests/ui/to_digit_is_some.fixed | 9 - tests/ui/to_digit_is_some.rs | 9 - tests/ui/to_digit_is_some.stderr | 17 - ...to_string_in_format_args_incremental.fixed | 8 - .../to_string_in_format_args_incremental.rs | 8 - ...o_string_in_format_args_incremental.stderr | 11 - tests/ui/to_string_trait_impl.rs | 75 - tests/ui/to_string_trait_impl.stderr | 28 - tests/ui/toplevel_ref_arg.fixed | 39 - tests/ui/toplevel_ref_arg.rs | 39 - tests/ui/toplevel_ref_arg.stderr | 43 - tests/ui/toplevel_ref_arg_non_rustfix.rs | 27 - tests/ui/toplevel_ref_arg_non_rustfix.stderr | 19 - tests/ui/track-diagnostics.rs | 11 - tests/ui/track-diagnostics.stderr | 10 - tests/ui/trailing_empty_array.rs | 194 - tests/ui/trailing_empty_array.stderr | 129 - tests/ui/trailing_zeros.fixed | 13 - tests/ui/trailing_zeros.rs | 13 - tests/ui/trailing_zeros.stderr | 17 - tests/ui/trait_duplication_in_bounds.fixed | 150 - tests/ui/trait_duplication_in_bounds.rs | 150 - tests/ui/trait_duplication_in_bounds.stderr | 62 - .../trait_duplication_in_bounds_unfixable.rs | 175 - ...ait_duplication_in_bounds_unfixable.stderr | 71 - tests/ui/transmute.rs | 199 - tests/ui/transmute.stderr | 236 - tests/ui/transmute_32bit.rs | 14 - tests/ui/transmute_32bit.stderr | 29 - tests/ui/transmute_64bit.rs | 13 - tests/ui/transmute_64bit.stderr | 17 - tests/ui/transmute_collection.rs | 70 - tests/ui/transmute_collection.stderr | 113 - tests/ui/transmute_float_to_int.fixed | 33 - tests/ui/transmute_float_to_int.rs | 33 - tests/ui/transmute_float_to_int.stderr | 41 - tests/ui/transmute_int_to_char.fixed | 16 - tests/ui/transmute_int_to_char.rs | 16 - tests/ui/transmute_int_to_char.stderr | 17 - tests/ui/transmute_int_to_char_no_std.fixed | 28 - tests/ui/transmute_int_to_char_no_std.rs | 28 - tests/ui/transmute_int_to_char_no_std.stderr | 17 - tests/ui/transmute_int_to_non_zero.fixed | 53 - tests/ui/transmute_int_to_non_zero.rs | 53 - tests/ui/transmute_int_to_non_zero.stderr | 65 - tests/ui/transmute_null_to_fn.rs | 42 - tests/ui/transmute_null_to_fn.stderr | 52 - tests/ui/transmute_ptr_to_ptr.fixed | 73 - tests/ui/transmute_ptr_to_ptr.rs | 73 - tests/ui/transmute_ptr_to_ptr.stderr | 47 - tests/ui/transmute_ptr_to_ref.fixed | 79 - tests/ui/transmute_ptr_to_ref.rs | 79 - tests/ui/transmute_ptr_to_ref.stderr | 137 - tests/ui/transmute_ref_to_ref.rs | 18 - tests/ui/transmute_ref_to_ref.stderr | 26 - tests/ui/transmute_ref_to_ref_no_std.rs | 30 - tests/ui/transmute_ref_to_ref_no_std.stderr | 26 - tests/ui/transmute_undefined_repr.rs | 258 - tests/ui/transmute_undefined_repr.stderr | 97 - .../transmutes_expressible_as_ptr_casts.fixed | 91 - .../ui/transmutes_expressible_as_ptr_casts.rs | 91 - ...transmutes_expressible_as_ptr_casts.stderr | 71 - tests/ui/transmuting_null.rs | 34 - tests/ui/transmuting_null.stderr | 23 - tests/ui/trim_split_whitespace.fixed | 90 - tests/ui/trim_split_whitespace.rs | 90 - tests/ui/trim_split_whitespace.stderr | 53 - tests/ui/trivially_copy_pass_by_ref.rs | 190 - tests/ui/trivially_copy_pass_by_ref.stderr | 116 - tests/ui/try_err.fixed | 154 - tests/ui/try_err.rs | 154 - tests/ui/try_err.stderr | 78 - tests/ui/tuple_array_conversions.rs | 108 - tests/ui/tuple_array_conversions.stderr | 84 - tests/ui/ty_fn_sig.rs | 14 - tests/ui/type_complexity.rs | 85 - tests/ui/type_complexity.stderr | 95 - tests/ui/type_id_on_box.fixed | 56 - tests/ui/type_id_on_box.rs | 56 - tests/ui/type_id_on_box.stderr | 48 - tests/ui/type_id_on_box_unfixable.rs | 31 - tests/ui/type_id_on_box_unfixable.stderr | 22 - tests/ui/type_repetition_in_bounds.rs | 142 - tests/ui/type_repetition_in_bounds.stderr | 47 - tests/ui/types.fixed | 13 - tests/ui/types.rs | 13 - tests/ui/types.stderr | 11 - tests/ui/unchecked_duration_subtraction.fixed | 16 - tests/ui/unchecked_duration_subtraction.rs | 16 - .../ui/unchecked_duration_subtraction.stderr | 29 - tests/ui/unconditional_recursion.rs | 401 -- tests/ui/unconditional_recursion.stderr | 364 - tests/ui/unicode.fixed | 58 - tests/ui/unicode.rs | 58 - tests/ui/unicode.stderr | 68 - tests/ui/uninhabited_references.rs | 23 - tests/ui/uninhabited_references.stderr | 39 - tests/ui/uninit.rs | 57 - tests/ui/uninit.stderr | 22 - tests/ui/uninit_vec.rs | 146 - tests/ui/uninit_vec.stderr | 119 - tests/ui/uninlined_format_args.fixed | 269 - tests/ui/uninlined_format_args.rs | 274 - tests/ui/uninlined_format_args.stderr | 849 --- ...nlined_format_args_panic.edition2018.fixed | 31 - ...lined_format_args_panic.edition2018.stderr | 16 - ...nlined_format_args_panic.edition2021.fixed | 31 - ...lined_format_args_panic.edition2021.stderr | 76 - tests/ui/uninlined_format_args_panic.rs | 31 - tests/ui/unit_arg.rs | 143 - tests/ui/unit_arg.stderr | 188 - tests/ui/unit_arg_empty_blocks.fixed | 30 - tests/ui/unit_arg_empty_blocks.rs | 27 - tests/ui/unit_arg_empty_blocks.stderr | 46 - tests/ui/unit_cmp.rs | 69 - tests/ui/unit_cmp.stderr | 78 - tests/ui/unit_hash.fixed | 34 - tests/ui/unit_hash.rs | 34 - tests/ui/unit_hash.stderr | 28 - tests/ui/unit_return_expecting_ord.rs | 41 - tests/ui/unit_return_expecting_ord.stderr | 40 - tests/ui/unknown_attribute.rs | 6 - tests/ui/unknown_attribute.stderr | 8 - tests/ui/unknown_clippy_lints.fixed | 18 - tests/ui/unknown_clippy_lints.rs | 18 - tests/ui/unknown_clippy_lints.stderr | 69 - tests/ui/unnecessary_box_returns.rs | 74 - tests/ui/unnecessary_box_returns.stderr | 36 - tests/ui/unnecessary_cast.fixed | 230 - tests/ui/unnecessary_cast.rs | 230 - tests/ui/unnecessary_cast.stderr | 251 - tests/ui/unnecessary_cast_unfixable.rs | 25 - tests/ui/unnecessary_cast_unfixable.stderr | 17 - tests/ui/unnecessary_clippy_cfg.rs | 23 - tests/ui/unnecessary_clippy_cfg.stderr | 97 - tests/ui/unnecessary_clone.rs | 108 - tests/ui/unnecessary_clone.stderr | 62 - .../ui/unnecessary_fallible_conversions.fixed | 43 - tests/ui/unnecessary_fallible_conversions.rs | 43 - .../unnecessary_fallible_conversions.stderr | 134 - ...ecessary_fallible_conversions_unfixable.rs | 43 - ...sary_fallible_conversions_unfixable.stderr | 52 - tests/ui/unnecessary_filter_map.rs | 161 - tests/ui/unnecessary_filter_map.stderr | 47 - tests/ui/unnecessary_find_map.rs | 34 - tests/ui/unnecessary_find_map.stderr | 47 - tests/ui/unnecessary_fold.fixed | 80 - tests/ui/unnecessary_fold.rs | 80 - tests/ui/unnecessary_fold.stderr | 104 - tests/ui/unnecessary_get_then_check.fixed | 26 - tests/ui/unnecessary_get_then_check.rs | 26 - tests/ui/unnecessary_get_then_check.stderr | 75 - tests/ui/unnecessary_iter_cloned.fixed | 172 - tests/ui/unnecessary_iter_cloned.rs | 172 - tests/ui/unnecessary_iter_cloned.stderr | 36 - tests/ui/unnecessary_join.fixed | 34 - tests/ui/unnecessary_join.rs | 36 - tests/ui/unnecessary_join.stderr | 21 - tests/ui/unnecessary_lazy_eval.fixed | 283 - tests/ui/unnecessary_lazy_eval.rs | 283 - tests/ui/unnecessary_lazy_eval.stderr | 516 -- tests/ui/unnecessary_lazy_eval_unfixable.rs | 32 - .../ui/unnecessary_lazy_eval_unfixable.stderr | 37 - tests/ui/unnecessary_literal_unwrap.fixed | 109 - tests/ui/unnecessary_literal_unwrap.rs | 109 - tests/ui/unnecessary_literal_unwrap.stderr | 606 -- .../unnecessary_literal_unwrap_unfixable.rs | 170 - ...nnecessary_literal_unwrap_unfixable.stderr | 616 -- tests/ui/unnecessary_map_on_constructor.fixed | 56 - tests/ui/unnecessary_map_on_constructor.rs | 56 - .../ui/unnecessary_map_on_constructor.stderr | 53 - tests/ui/unnecessary_operation.fixed | 116 - tests/ui/unnecessary_operation.rs | 120 - tests/ui/unnecessary_operation.stderr | 123 - .../ui/unnecessary_owned_empty_strings.fixed | 21 - tests/ui/unnecessary_owned_empty_strings.rs | 21 - .../ui/unnecessary_owned_empty_strings.stderr | 17 - tests/ui/unnecessary_result_map_or_else.fixed | 61 - tests/ui/unnecessary_result_map_or_else.rs | 69 - .../ui/unnecessary_result_map_or_else.stderr | 35 - tests/ui/unnecessary_safety_comment.rs | 97 - tests/ui/unnecessary_safety_comment.stderr | 116 - tests/ui/unnecessary_self_imports.fixed | 9 - tests/ui/unnecessary_self_imports.rs | 9 - tests/ui/unnecessary_self_imports.stderr | 24 - tests/ui/unnecessary_sort_by.fixed | 101 - tests/ui/unnecessary_sort_by.rs | 101 - tests/ui/unnecessary_sort_by.stderr | 77 - .../unnecessary_struct_initialization.fixed | 71 - tests/ui/unnecessary_struct_initialization.rs | 75 - .../unnecessary_struct_initialization.stderr | 47 - tests/ui/unnecessary_to_owned.fixed | 568 -- tests/ui/unnecessary_to_owned.rs | 568 -- tests/ui/unnecessary_to_owned.stderr | 557 -- tests/ui/unnecessary_to_owned_on_split.fixed | 38 - tests/ui/unnecessary_to_owned_on_split.rs | 38 - tests/ui/unnecessary_to_owned_on_split.stderr | 59 - tests/ui/unnecessary_unsafety_doc.rs | 153 - tests/ui/unnecessary_unsafety_doc.stderr | 52 - tests/ui/unnecessary_wraps.rs | 153 - tests/ui/unnecessary_wraps.stderr | 161 - tests/ui/unneeded_field_pattern.rs | 34 - tests/ui/unneeded_field_pattern.stderr | 20 - tests/ui/unneeded_wildcard_pattern.fixed | 53 - tests/ui/unneeded_wildcard_pattern.rs | 53 - tests/ui/unneeded_wildcard_pattern.stderr | 92 - tests/ui/unnested_or_patterns.fixed | 49 - tests/ui/unnested_or_patterns.rs | 49 - tests/ui/unnested_or_patterns.stderr | 191 - tests/ui/unnested_or_patterns2.fixed | 20 - tests/ui/unnested_or_patterns2.rs | 20 - tests/ui/unnested_or_patterns2.stderr | 92 - tests/ui/unreadable_literal.fixed | 43 - tests/ui/unreadable_literal.rs | 43 - tests/ui/unreadable_literal.stderr | 65 - tests/ui/unsafe_derive_deserialize.rs | 74 - tests/ui/unsafe_derive_deserialize.stderr | 40 - tests/ui/unsafe_removed_from_name.rs | 44 - tests/ui/unsafe_removed_from_name.stderr | 35 - tests/ui/unseparated_prefix_literals.fixed | 41 - tests/ui/unseparated_prefix_literals.rs | 41 - tests/ui/unseparated_prefix_literals.stderr | 64 - tests/ui/unused_async.rs | 102 - tests/ui/unused_async.stderr | 52 - tests/ui/unused_enumerate_index.fixed | 106 - tests/ui/unused_enumerate_index.rs | 106 - tests/ui/unused_enumerate_index.stderr | 98 - tests/ui/unused_format_specs_unfixable.rs | 35 - tests/ui/unused_format_specs_unfixable.stderr | 62 - tests/ui/unused_io_amount.rs | 280 - tests/ui/unused_io_amount.stderr | 264 - tests/ui/unused_peekable.rs | 182 - tests/ui/unused_peekable.stderr | 68 - tests/ui/unused_rounding.fixed | 16 - tests/ui/unused_rounding.rs | 16 - tests/ui/unused_rounding.stderr | 35 - tests/ui/unused_self.rs | 168 - tests/ui/unused_self.stderr | 76 - tests/ui/unused_unit.fixed | 103 - tests/ui/unused_unit.rs | 103 - tests/ui/unused_unit.stderr | 122 - tests/ui/unwrap.rs | 21 - tests/ui/unwrap.stderr | 31 - tests/ui/unwrap_expect_used.rs | 53 - tests/ui/unwrap_expect_used.stderr | 54 - tests/ui/unwrap_in_result.rs | 46 - tests/ui/unwrap_in_result.stderr | 42 - tests/ui/unwrap_or.fixed | 13 - tests/ui/unwrap_or.rs | 13 - tests/ui/unwrap_or.stderr | 17 - tests/ui/unwrap_or_else_default.fixed | 163 - tests/ui/unwrap_or_else_default.rs | 163 - tests/ui/unwrap_or_else_default.stderr | 101 - tests/ui/update-all-references.sh | 3 - tests/ui/upper_case_acronyms.fixed | 70 - tests/ui/upper_case_acronyms.rs | 70 - tests/ui/upper_case_acronyms.stderr | 77 - tests/ui/use_self.fixed | 669 -- tests/ui/use_self.rs | 669 -- tests/ui/use_self.stderr | 263 - tests/ui/use_self_trait.fixed | 150 - tests/ui/use_self_trait.rs | 150 - tests/ui/use_self_trait.stderr | 101 - tests/ui/used_underscore_binding.rs | 147 - tests/ui/used_underscore_binding.stderr | 76 - tests/ui/useful_asref.rs | 13 - tests/ui/useless_asref.fixed | 204 - tests/ui/useless_asref.rs | 204 - tests/ui/useless_asref.stderr | 116 - tests/ui/useless_attribute.fixed | 136 - tests/ui/useless_attribute.rs | 136 - tests/ui/useless_attribute.stderr | 23 - tests/ui/useless_conversion.fixed | 297 - tests/ui/useless_conversion.rs | 297 - tests/ui/useless_conversion.stderr | 230 - tests/ui/useless_conversion_try.rs | 50 - tests/ui/useless_conversion_try.stderr | 79 - tests/ui/vec.fixed | 223 - tests/ui/vec.rs | 223 - tests/ui/vec.stderr | 131 - tests/ui/vec_box_sized.rs | 90 - tests/ui/vec_box_sized.stderr | 59 - tests/ui/vec_init_then_push.rs | 121 - tests/ui/vec_init_then_push.stderr | 81 - tests/ui/vec_resize_to_zero.fixed | 20 - tests/ui/vec_resize_to_zero.rs | 20 - tests/ui/vec_resize_to_zero.stderr | 14 - tests/ui/verbose_file_reads.rs | 30 - tests/ui/verbose_file_reads.stderr | 20 - tests/ui/waker_clone_wake.fixed | 29 - tests/ui/waker_clone_wake.rs | 29 - tests/ui/waker_clone_wake.stderr | 17 - tests/ui/while_let_loop.rs | 152 - tests/ui/while_let_loop.stderr | 65 - tests/ui/while_let_on_iterator.fixed | 464 -- tests/ui/while_let_on_iterator.rs | 464 -- tests/ui/while_let_on_iterator.stderr | 167 - tests/ui/wild_in_or_pats.rs | 40 - tests/ui/wild_in_or_pats.stderr | 36 - tests/ui/wildcard_enum_match_arm.fixed | 101 - tests/ui/wildcard_enum_match_arm.rs | 101 - tests/ui/wildcard_enum_match_arm.stderr | 44 - tests/ui/wildcard_imports.fixed | 275 - tests/ui/wildcard_imports.rs | 276 - tests/ui/wildcard_imports.stderr | 139 - .../wildcard_imports_2021.edition2018.fixed | 269 - .../wildcard_imports_2021.edition2018.stderr | 139 - .../wildcard_imports_2021.edition2021.fixed | 269 - .../wildcard_imports_2021.edition2021.stderr | 139 - tests/ui/wildcard_imports_2021.rs | 270 - tests/ui/wildcard_imports_cfgtest.rs | 19 - tests/ui/write_literal.fixed | 64 - tests/ui/write_literal.rs | 64 - tests/ui/write_literal.stderr | 148 - tests/ui/write_literal_2.rs | 51 - tests/ui/write_literal_2.stderr | 161 - tests/ui/write_with_newline.fixed | 76 - tests/ui/write_with_newline.rs | 80 - tests/ui/write_with_newline.stderr | 124 - tests/ui/writeln_empty_string.fixed | 18 - tests/ui/writeln_empty_string.rs | 18 - tests/ui/writeln_empty_string.stderr | 21 - tests/ui/wrong_self_convention.rs | 230 - tests/ui/wrong_self_convention.stderr | 196 - tests/ui/wrong_self_convention2.rs | 118 - tests/ui/wrong_self_convention2.stderr | 20 - tests/ui/wrong_self_conventions_mut.rs | 31 - tests/ui/wrong_self_conventions_mut.stderr | 20 - tests/ui/zero_div_zero.rs | 17 - tests/ui/zero_div_zero.stderr | 36 - tests/ui/zero_offset.rs | 28 - tests/ui/zero_offset.stderr | 52 - tests/ui/zero_ptr.fixed | 13 - tests/ui/zero_ptr.rs | 13 - tests/ui/zero_ptr.stderr | 35 - tests/ui/zero_ptr_no_std.fixed | 19 - tests/ui/zero_ptr_no_std.rs | 19 - tests/ui/zero_ptr_no_std.stderr | 26 - tests/ui/zero_repeat_side_effects.fixed | 60 - tests/ui/zero_repeat_side_effects.rs | 60 - tests/ui/zero_repeat_side_effects.stderr | 77 - tests/ui/zero_sized_btreemap_values.rs | 80 - tests/ui/zero_sized_btreemap_values.stderr | 108 - tests/ui/zero_sized_hashmap_values.rs | 80 - tests/ui/zero_sized_hashmap_values.stderr | 108 - tests/versioncheck.rs | 94 - tests/workspace.rs | 147 - tests/workspace_test/Cargo.toml | 7 - tests/workspace_test/build.rs | 7 - .../pass_mod_with_dep_in_subdir/Cargo.toml | 10 - .../dep_no_mod/Cargo.toml | 9 - .../dep_no_mod/src/foo.rs | 2 - .../dep_no_mod/src/foo/hello.rs | 1 - .../dep_no_mod/src/lib.rs | 5 - .../src/bad/mod.rs | 1 - .../pass_mod_with_dep_in_subdir/src/main.rs | 13 - .../src/more/foo.rs | 1 - .../src/more/inner/mod.rs | 1 - .../src/more/mod.rs | 2 - .../pass_no_mod_with_dep_in_subdir/Cargo.toml | 10 - .../dep_with_mod/Cargo.toml | 9 - .../dep_with_mod/src/lib.rs | 7 - .../dep_with_mod/src/with_mod/inner.rs | 1 - .../dep_with_mod/src/with_mod/inner/stuff.rs | 3 - .../src/with_mod/inner/stuff/most.rs | 1 - .../dep_with_mod/src/with_mod/mod.rs | 3 - .../src/good.rs | 1 - .../src/main.rs | 9 - tests/workspace_test/path_dep/Cargo.toml | 3 - tests/workspace_test/path_dep/src/lib.rs | 6 - tests/workspace_test/src/main.rs | 3 - tests/workspace_test/subcrate/Cargo.toml | 6 - tests/workspace_test/subcrate/src/lib.rs | 1 - triagebot.toml | 41 - util/etc/pre-commit.sh | 22 - util/etc/vscode-tasks.json | 57 - util/fetch_prs_between.sh | 43 - util/gh-pages/index.html | 635 -- util/gh-pages/script.js | 550 -- util/gh-pages/versions.html | 88 - util/versions.py | 51 - 3594 files changed, 354072 deletions(-) delete mode 100644 .cargo/config.toml delete mode 100644 .editorconfig delete mode 100644 .gitattributes delete mode 100644 .github/ISSUE_TEMPLATE/blank_issue.yml delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml delete mode 100644 .github/ISSUE_TEMPLATE/config.yml delete mode 100644 .github/ISSUE_TEMPLATE/false_negative.yml delete mode 100644 .github/ISSUE_TEMPLATE/false_positive.yml delete mode 100644 .github/ISSUE_TEMPLATE/ice.yml delete mode 100644 .github/ISSUE_TEMPLATE/new_lint.yml delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/deploy.sh delete mode 100755 .github/driver.sh delete mode 100644 .github/workflows/clippy.yml delete mode 100644 .github/workflows/clippy_bors.yml delete mode 100644 .github/workflows/clippy_dev.yml delete mode 100644 .github/workflows/deploy.yml delete mode 100644 .github/workflows/remark.yml delete mode 100644 .gitignore delete mode 100644 .remarkrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 COPYRIGHT delete mode 100644 Cargo.toml delete mode 100644 LICENSE-APACHE delete mode 100644 LICENSE-MIT delete mode 100644 README.md delete mode 100644 book/README.md delete mode 100644 book/book.toml delete mode 100644 book/src/README.md delete mode 100644 book/src/SUMMARY.md delete mode 100644 book/src/configuration.md delete mode 100644 book/src/continuous_integration/README.md delete mode 100644 book/src/continuous_integration/github_actions.md delete mode 100644 book/src/continuous_integration/gitlab.md delete mode 100644 book/src/continuous_integration/travis.md delete mode 100644 book/src/development/README.md delete mode 100644 book/src/development/adding_lints.md delete mode 100644 book/src/development/basics.md delete mode 100644 book/src/development/common_tools_writing_lints.md delete mode 100644 book/src/development/defining_lints.md delete mode 100644 book/src/development/emitting_lints.md delete mode 100644 book/src/development/infrastructure/README.md delete mode 100644 book/src/development/infrastructure/backport.md delete mode 100644 book/src/development/infrastructure/book.md delete mode 100644 book/src/development/infrastructure/changelog_update.md delete mode 100644 book/src/development/infrastructure/release.md delete mode 100644 book/src/development/infrastructure/sync.md delete mode 100644 book/src/development/lint_passes.md delete mode 100644 book/src/development/macro_expansions.md delete mode 100644 book/src/development/method_checking.md delete mode 100644 book/src/development/proposals/README.md delete mode 100644 book/src/development/proposals/roadmap-2021.md delete mode 100644 book/src/development/proposals/syntax-tree-patterns.md delete mode 100644 book/src/development/speedtest.md delete mode 100644 book/src/development/the_team.md delete mode 100644 book/src/development/trait_checking.md delete mode 100644 book/src/development/type_checking.md delete mode 100644 book/src/development/writing_tests.md delete mode 100644 book/src/installation.md delete mode 100644 book/src/lint_configuration.md delete mode 100644 book/src/lints.md delete mode 100644 book/src/usage.md delete mode 100644 build.rs delete mode 100644 clippy.toml delete mode 100644 clippy_config/Cargo.toml delete mode 100644 clippy_config/src/conf.rs delete mode 100644 clippy_config/src/lib.rs delete mode 100644 clippy_config/src/metadata.rs delete mode 100644 clippy_config/src/msrvs.rs delete mode 100644 clippy_config/src/types.rs delete mode 100644 clippy_dev/Cargo.toml delete mode 100644 clippy_dev/src/dogfood.rs delete mode 100644 clippy_dev/src/fmt.rs delete mode 100644 clippy_dev/src/lib.rs delete mode 100644 clippy_dev/src/lint.rs delete mode 100644 clippy_dev/src/main.rs delete mode 100644 clippy_dev/src/new_lint.rs delete mode 100644 clippy_dev/src/serve.rs delete mode 100644 clippy_dev/src/setup/git_hook.rs delete mode 100644 clippy_dev/src/setup/intellij.rs delete mode 100644 clippy_dev/src/setup/mod.rs delete mode 100644 clippy_dev/src/setup/toolchain.rs delete mode 100644 clippy_dev/src/setup/vscode.rs delete mode 100644 clippy_dev/src/update_lints.rs delete mode 100644 clippy_dummy/Cargo.toml delete mode 100644 clippy_dummy/PUBLISH.md delete mode 100644 clippy_dummy/build.rs delete mode 100644 clippy_dummy/crates-readme.md delete mode 100644 clippy_dummy/src/main.rs delete mode 100644 clippy_lints/Cargo.toml delete mode 100644 clippy_lints/README.md delete mode 100644 clippy_lints/src/absolute_paths.rs delete mode 100644 clippy_lints/src/allow_attributes.rs delete mode 100644 clippy_lints/src/almost_complete_range.rs delete mode 100644 clippy_lints/src/approx_const.rs delete mode 100644 clippy_lints/src/arc_with_non_send_sync.rs delete mode 100644 clippy_lints/src/as_conversions.rs delete mode 100644 clippy_lints/src/asm_syntax.rs delete mode 100644 clippy_lints/src/assertions_on_constants.rs delete mode 100644 clippy_lints/src/assertions_on_result_states.rs delete mode 100644 clippy_lints/src/assigning_clones.rs delete mode 100644 clippy_lints/src/async_yields_async.rs delete mode 100644 clippy_lints/src/attrs/allow_attributes_without_reason.rs delete mode 100644 clippy_lints/src/attrs/blanket_clippy_restriction_lints.rs delete mode 100644 clippy_lints/src/attrs/deprecated_cfg_attr.rs delete mode 100644 clippy_lints/src/attrs/deprecated_semver.rs delete mode 100644 clippy_lints/src/attrs/duplicated_attributes.rs delete mode 100644 clippy_lints/src/attrs/empty_line_after.rs delete mode 100644 clippy_lints/src/attrs/inline_always.rs delete mode 100644 clippy_lints/src/attrs/maybe_misused_cfg.rs delete mode 100644 clippy_lints/src/attrs/mismatched_target_os.rs delete mode 100644 clippy_lints/src/attrs/mixed_attributes_style.rs delete mode 100644 clippy_lints/src/attrs/mod.rs delete mode 100644 clippy_lints/src/attrs/non_minimal_cfg.rs delete mode 100644 clippy_lints/src/attrs/should_panic_without_expect.rs delete mode 100644 clippy_lints/src/attrs/unnecessary_clippy_cfg.rs delete mode 100644 clippy_lints/src/attrs/useless_attribute.rs delete mode 100644 clippy_lints/src/attrs/utils.rs delete mode 100644 clippy_lints/src/await_holding_invalid.rs delete mode 100644 clippy_lints/src/blocks_in_conditions.rs delete mode 100644 clippy_lints/src/bool_assert_comparison.rs delete mode 100644 clippy_lints/src/bool_to_int_with_if.rs delete mode 100644 clippy_lints/src/booleans.rs delete mode 100644 clippy_lints/src/borrow_deref_ref.rs delete mode 100644 clippy_lints/src/box_default.rs delete mode 100644 clippy_lints/src/cargo/common_metadata.rs delete mode 100644 clippy_lints/src/cargo/feature_name.rs delete mode 100644 clippy_lints/src/cargo/lint_groups_priority.rs delete mode 100644 clippy_lints/src/cargo/mod.rs delete mode 100644 clippy_lints/src/cargo/multiple_crate_versions.rs delete mode 100644 clippy_lints/src/cargo/wildcard_dependencies.rs delete mode 100644 clippy_lints/src/casts/as_ptr_cast_mut.rs delete mode 100644 clippy_lints/src/casts/as_underscore.rs delete mode 100644 clippy_lints/src/casts/borrow_as_ptr.rs delete mode 100644 clippy_lints/src/casts/cast_abs_to_unsigned.rs delete mode 100644 clippy_lints/src/casts/cast_enum_constructor.rs delete mode 100644 clippy_lints/src/casts/cast_lossless.rs delete mode 100644 clippy_lints/src/casts/cast_nan_to_int.rs delete mode 100644 clippy_lints/src/casts/cast_possible_truncation.rs delete mode 100644 clippy_lints/src/casts/cast_possible_wrap.rs delete mode 100644 clippy_lints/src/casts/cast_precision_loss.rs delete mode 100644 clippy_lints/src/casts/cast_ptr_alignment.rs delete mode 100644 clippy_lints/src/casts/cast_sign_loss.rs delete mode 100644 clippy_lints/src/casts/cast_slice_different_sizes.rs delete mode 100644 clippy_lints/src/casts/cast_slice_from_raw_parts.rs delete mode 100644 clippy_lints/src/casts/char_lit_as_u8.rs delete mode 100644 clippy_lints/src/casts/fn_to_numeric_cast.rs delete mode 100644 clippy_lints/src/casts/fn_to_numeric_cast_any.rs delete mode 100644 clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs delete mode 100644 clippy_lints/src/casts/mod.rs delete mode 100644 clippy_lints/src/casts/ptr_as_ptr.rs delete mode 100644 clippy_lints/src/casts/ptr_cast_constness.rs delete mode 100644 clippy_lints/src/casts/ref_as_ptr.rs delete mode 100644 clippy_lints/src/casts/unnecessary_cast.rs delete mode 100644 clippy_lints/src/casts/utils.rs delete mode 100644 clippy_lints/src/casts/zero_ptr.rs delete mode 100644 clippy_lints/src/checked_conversions.rs delete mode 100644 clippy_lints/src/cognitive_complexity.rs delete mode 100644 clippy_lints/src/collapsible_if.rs delete mode 100644 clippy_lints/src/collection_is_never_read.rs delete mode 100644 clippy_lints/src/comparison_chain.rs delete mode 100644 clippy_lints/src/copies.rs delete mode 100644 clippy_lints/src/copy_iterator.rs delete mode 100644 clippy_lints/src/crate_in_macro_def.rs delete mode 100644 clippy_lints/src/create_dir.rs delete mode 100644 clippy_lints/src/dbg_macro.rs delete mode 100644 clippy_lints/src/declared_lints.rs delete mode 100644 clippy_lints/src/default.rs delete mode 100644 clippy_lints/src/default_constructed_unit_structs.rs delete mode 100644 clippy_lints/src/default_instead_of_iter_empty.rs delete mode 100644 clippy_lints/src/default_numeric_fallback.rs delete mode 100644 clippy_lints/src/default_union_representation.rs delete mode 100644 clippy_lints/src/deprecated_lints.rs delete mode 100644 clippy_lints/src/dereference.rs delete mode 100644 clippy_lints/src/derivable_impls.rs delete mode 100644 clippy_lints/src/derive.rs delete mode 100644 clippy_lints/src/disallowed_macros.rs delete mode 100644 clippy_lints/src/disallowed_methods.rs delete mode 100644 clippy_lints/src/disallowed_names.rs delete mode 100644 clippy_lints/src/disallowed_script_idents.rs delete mode 100644 clippy_lints/src/disallowed_types.rs delete mode 100644 clippy_lints/src/doc/lazy_continuation.rs delete mode 100644 clippy_lints/src/doc/link_with_quotes.rs delete mode 100644 clippy_lints/src/doc/markdown.rs delete mode 100644 clippy_lints/src/doc/missing_headers.rs delete mode 100644 clippy_lints/src/doc/mod.rs delete mode 100644 clippy_lints/src/doc/needless_doctest_main.rs delete mode 100644 clippy_lints/src/doc/suspicious_doc_comments.rs delete mode 100644 clippy_lints/src/double_parens.rs delete mode 100644 clippy_lints/src/drop_forget_ref.rs delete mode 100644 clippy_lints/src/duplicate_mod.rs delete mode 100644 clippy_lints/src/else_if_without_else.rs delete mode 100644 clippy_lints/src/empty_drop.rs delete mode 100644 clippy_lints/src/empty_enum.rs delete mode 100644 clippy_lints/src/empty_with_brackets.rs delete mode 100644 clippy_lints/src/endian_bytes.rs delete mode 100644 clippy_lints/src/entry.rs delete mode 100644 clippy_lints/src/enum_clike.rs delete mode 100644 clippy_lints/src/equatable_if_let.rs delete mode 100644 clippy_lints/src/error_impl_error.rs delete mode 100644 clippy_lints/src/escape.rs delete mode 100644 clippy_lints/src/eta_reduction.rs delete mode 100644 clippy_lints/src/excessive_bools.rs delete mode 100644 clippy_lints/src/excessive_nesting.rs delete mode 100644 clippy_lints/src/exhaustive_items.rs delete mode 100644 clippy_lints/src/exit.rs delete mode 100644 clippy_lints/src/explicit_write.rs delete mode 100644 clippy_lints/src/extra_unused_type_parameters.rs delete mode 100644 clippy_lints/src/fallible_impl_from.rs delete mode 100644 clippy_lints/src/float_literal.rs delete mode 100644 clippy_lints/src/floating_point_arithmetic.rs delete mode 100644 clippy_lints/src/format.rs delete mode 100644 clippy_lints/src/format_args.rs delete mode 100644 clippy_lints/src/format_impl.rs delete mode 100644 clippy_lints/src/format_push_string.rs delete mode 100644 clippy_lints/src/formatting.rs delete mode 100644 clippy_lints/src/four_forward_slashes.rs delete mode 100644 clippy_lints/src/from_over_into.rs delete mode 100644 clippy_lints/src/from_raw_with_void_ptr.rs delete mode 100644 clippy_lints/src/from_str_radix_10.rs delete mode 100644 clippy_lints/src/functions/impl_trait_in_params.rs delete mode 100644 clippy_lints/src/functions/misnamed_getters.rs delete mode 100644 clippy_lints/src/functions/mod.rs delete mode 100644 clippy_lints/src/functions/must_use.rs delete mode 100644 clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs delete mode 100644 clippy_lints/src/functions/renamed_function_params.rs delete mode 100644 clippy_lints/src/functions/result.rs delete mode 100644 clippy_lints/src/functions/too_many_arguments.rs delete mode 100644 clippy_lints/src/functions/too_many_lines.rs delete mode 100644 clippy_lints/src/future_not_send.rs delete mode 100644 clippy_lints/src/if_let_mutex.rs delete mode 100644 clippy_lints/src/if_not_else.rs delete mode 100644 clippy_lints/src/if_then_some_else_none.rs delete mode 100644 clippy_lints/src/ignored_unit_patterns.rs delete mode 100644 clippy_lints/src/impl_hash_with_borrow_str_and_bytes.rs delete mode 100644 clippy_lints/src/implicit_hasher.rs delete mode 100644 clippy_lints/src/implicit_return.rs delete mode 100644 clippy_lints/src/implicit_saturating_add.rs delete mode 100644 clippy_lints/src/implicit_saturating_sub.rs delete mode 100644 clippy_lints/src/implied_bounds_in_impls.rs delete mode 100644 clippy_lints/src/incompatible_msrv.rs delete mode 100644 clippy_lints/src/inconsistent_struct_constructor.rs delete mode 100644 clippy_lints/src/index_refutable_slice.rs delete mode 100644 clippy_lints/src/indexing_slicing.rs delete mode 100644 clippy_lints/src/ineffective_open_options.rs delete mode 100644 clippy_lints/src/infinite_iter.rs delete mode 100644 clippy_lints/src/inherent_impl.rs delete mode 100644 clippy_lints/src/inherent_to_string.rs delete mode 100644 clippy_lints/src/init_numbered_fields.rs delete mode 100644 clippy_lints/src/inline_fn_without_body.rs delete mode 100644 clippy_lints/src/instant_subtraction.rs delete mode 100644 clippy_lints/src/int_plus_one.rs delete mode 100644 clippy_lints/src/integer_division_remainder_used.rs delete mode 100644 clippy_lints/src/invalid_upcast_comparisons.rs delete mode 100644 clippy_lints/src/item_name_repetitions.rs delete mode 100644 clippy_lints/src/items_after_statements.rs delete mode 100644 clippy_lints/src/items_after_test_module.rs delete mode 100644 clippy_lints/src/iter_not_returning_iterator.rs delete mode 100644 clippy_lints/src/iter_over_hash_type.rs delete mode 100644 clippy_lints/src/iter_without_into_iter.rs delete mode 100644 clippy_lints/src/large_const_arrays.rs delete mode 100644 clippy_lints/src/large_enum_variant.rs delete mode 100644 clippy_lints/src/large_futures.rs delete mode 100644 clippy_lints/src/large_include_file.rs delete mode 100644 clippy_lints/src/large_stack_arrays.rs delete mode 100644 clippy_lints/src/large_stack_frames.rs delete mode 100644 clippy_lints/src/legacy_numeric_constants.rs delete mode 100644 clippy_lints/src/len_zero.rs delete mode 100644 clippy_lints/src/let_if_seq.rs delete mode 100644 clippy_lints/src/let_underscore.rs delete mode 100644 clippy_lints/src/let_with_type_underscore.rs delete mode 100644 clippy_lints/src/lib.deprecated.rs delete mode 100644 clippy_lints/src/lib.rs delete mode 100644 clippy_lints/src/lifetimes.rs delete mode 100644 clippy_lints/src/lines_filter_map_ok.rs delete mode 100644 clippy_lints/src/literal_representation.rs delete mode 100644 clippy_lints/src/loops/empty_loop.rs delete mode 100644 clippy_lints/src/loops/explicit_counter_loop.rs delete mode 100644 clippy_lints/src/loops/explicit_into_iter_loop.rs delete mode 100644 clippy_lints/src/loops/explicit_iter_loop.rs delete mode 100644 clippy_lints/src/loops/for_kv_map.rs delete mode 100644 clippy_lints/src/loops/infinite_loop.rs delete mode 100644 clippy_lints/src/loops/iter_next_loop.rs delete mode 100644 clippy_lints/src/loops/manual_find.rs delete mode 100644 clippy_lints/src/loops/manual_flatten.rs delete mode 100644 clippy_lints/src/loops/manual_memcpy.rs delete mode 100644 clippy_lints/src/loops/manual_while_let_some.rs delete mode 100644 clippy_lints/src/loops/missing_spin_loop.rs delete mode 100644 clippy_lints/src/loops/mod.rs delete mode 100644 clippy_lints/src/loops/mut_range_bound.rs delete mode 100644 clippy_lints/src/loops/needless_range_loop.rs delete mode 100644 clippy_lints/src/loops/never_loop.rs delete mode 100644 clippy_lints/src/loops/same_item_push.rs delete mode 100644 clippy_lints/src/loops/single_element_loop.rs delete mode 100644 clippy_lints/src/loops/unused_enumerate_index.rs delete mode 100644 clippy_lints/src/loops/utils.rs delete mode 100644 clippy_lints/src/loops/while_immutable_condition.rs delete mode 100644 clippy_lints/src/loops/while_let_loop.rs delete mode 100644 clippy_lints/src/loops/while_let_on_iterator.rs delete mode 100644 clippy_lints/src/macro_metavars_in_unsafe.rs delete mode 100644 clippy_lints/src/macro_use.rs delete mode 100644 clippy_lints/src/main_recursion.rs delete mode 100644 clippy_lints/src/manual_assert.rs delete mode 100644 clippy_lints/src/manual_async_fn.rs delete mode 100644 clippy_lints/src/manual_bits.rs delete mode 100644 clippy_lints/src/manual_clamp.rs delete mode 100644 clippy_lints/src/manual_float_methods.rs delete mode 100644 clippy_lints/src/manual_hash_one.rs delete mode 100644 clippy_lints/src/manual_is_ascii_check.rs delete mode 100644 clippy_lints/src/manual_let_else.rs delete mode 100644 clippy_lints/src/manual_main_separator_str.rs delete mode 100644 clippy_lints/src/manual_non_exhaustive.rs delete mode 100644 clippy_lints/src/manual_range_patterns.rs delete mode 100644 clippy_lints/src/manual_rem_euclid.rs delete mode 100644 clippy_lints/src/manual_retain.rs delete mode 100644 clippy_lints/src/manual_slice_size_calculation.rs delete mode 100644 clippy_lints/src/manual_string_new.rs delete mode 100644 clippy_lints/src/manual_strip.rs delete mode 100644 clippy_lints/src/manual_unwrap_or_default.rs delete mode 100644 clippy_lints/src/map_unit_fn.rs delete mode 100644 clippy_lints/src/match_result_ok.rs delete mode 100644 clippy_lints/src/matches/collapsible_match.rs delete mode 100644 clippy_lints/src/matches/infallible_destructuring_match.rs delete mode 100644 clippy_lints/src/matches/manual_filter.rs delete mode 100644 clippy_lints/src/matches/manual_map.rs delete mode 100644 clippy_lints/src/matches/manual_unwrap_or.rs delete mode 100644 clippy_lints/src/matches/manual_utils.rs delete mode 100644 clippy_lints/src/matches/match_as_ref.rs delete mode 100644 clippy_lints/src/matches/match_bool.rs delete mode 100644 clippy_lints/src/matches/match_like_matches.rs delete mode 100644 clippy_lints/src/matches/match_on_vec_items.rs delete mode 100644 clippy_lints/src/matches/match_ref_pats.rs delete mode 100644 clippy_lints/src/matches/match_same_arms.rs delete mode 100644 clippy_lints/src/matches/match_single_binding.rs delete mode 100644 clippy_lints/src/matches/match_str_case_mismatch.rs delete mode 100644 clippy_lints/src/matches/match_wild_enum.rs delete mode 100644 clippy_lints/src/matches/match_wild_err_arm.rs delete mode 100644 clippy_lints/src/matches/mod.rs delete mode 100644 clippy_lints/src/matches/needless_match.rs delete mode 100644 clippy_lints/src/matches/overlapping_arms.rs delete mode 100644 clippy_lints/src/matches/redundant_guards.rs delete mode 100644 clippy_lints/src/matches/redundant_pattern_match.rs delete mode 100644 clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs delete mode 100644 clippy_lints/src/matches/significant_drop_in_scrutinee.rs delete mode 100644 clippy_lints/src/matches/single_match.rs delete mode 100644 clippy_lints/src/matches/try_err.rs delete mode 100644 clippy_lints/src/matches/wild_in_or_pats.rs delete mode 100644 clippy_lints/src/mem_replace.rs delete mode 100644 clippy_lints/src/methods/bind_instead_of_map.rs delete mode 100644 clippy_lints/src/methods/bytecount.rs delete mode 100644 clippy_lints/src/methods/bytes_count_to_len.rs delete mode 100644 clippy_lints/src/methods/bytes_nth.rs delete mode 100644 clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs delete mode 100644 clippy_lints/src/methods/chars_cmp.rs delete mode 100644 clippy_lints/src/methods/chars_cmp_with_unwrap.rs delete mode 100644 clippy_lints/src/methods/chars_last_cmp.rs delete mode 100644 clippy_lints/src/methods/chars_last_cmp_with_unwrap.rs delete mode 100644 clippy_lints/src/methods/chars_next_cmp.rs delete mode 100644 clippy_lints/src/methods/chars_next_cmp_with_unwrap.rs delete mode 100644 clippy_lints/src/methods/clear_with_drain.rs delete mode 100644 clippy_lints/src/methods/clone_on_copy.rs delete mode 100644 clippy_lints/src/methods/clone_on_ref_ptr.rs delete mode 100644 clippy_lints/src/methods/cloned_instead_of_copied.rs delete mode 100644 clippy_lints/src/methods/collapsible_str_replace.rs delete mode 100644 clippy_lints/src/methods/drain_collect.rs delete mode 100644 clippy_lints/src/methods/err_expect.rs delete mode 100644 clippy_lints/src/methods/expect_fun_call.rs delete mode 100644 clippy_lints/src/methods/extend_with_drain.rs delete mode 100644 clippy_lints/src/methods/filetype_is_file.rs delete mode 100644 clippy_lints/src/methods/filter_map.rs delete mode 100644 clippy_lints/src/methods/filter_map_bool_then.rs delete mode 100644 clippy_lints/src/methods/filter_map_identity.rs delete mode 100644 clippy_lints/src/methods/filter_map_next.rs delete mode 100644 clippy_lints/src/methods/filter_next.rs delete mode 100644 clippy_lints/src/methods/flat_map_identity.rs delete mode 100644 clippy_lints/src/methods/flat_map_option.rs delete mode 100644 clippy_lints/src/methods/format_collect.rs delete mode 100644 clippy_lints/src/methods/from_iter_instead_of_collect.rs delete mode 100644 clippy_lints/src/methods/get_first.rs delete mode 100644 clippy_lints/src/methods/get_last_with_len.rs delete mode 100644 clippy_lints/src/methods/get_unwrap.rs delete mode 100644 clippy_lints/src/methods/implicit_clone.rs delete mode 100644 clippy_lints/src/methods/inefficient_to_string.rs delete mode 100644 clippy_lints/src/methods/inspect_for_each.rs delete mode 100644 clippy_lints/src/methods/into_iter_on_ref.rs delete mode 100644 clippy_lints/src/methods/is_digit_ascii_radix.rs delete mode 100644 clippy_lints/src/methods/is_empty.rs delete mode 100644 clippy_lints/src/methods/iter_cloned_collect.rs delete mode 100644 clippy_lints/src/methods/iter_count.rs delete mode 100644 clippy_lints/src/methods/iter_filter.rs delete mode 100644 clippy_lints/src/methods/iter_kv_map.rs delete mode 100644 clippy_lints/src/methods/iter_next_slice.rs delete mode 100644 clippy_lints/src/methods/iter_nth.rs delete mode 100644 clippy_lints/src/methods/iter_nth_zero.rs delete mode 100644 clippy_lints/src/methods/iter_on_single_or_empty_collections.rs delete mode 100644 clippy_lints/src/methods/iter_out_of_bounds.rs delete mode 100644 clippy_lints/src/methods/iter_overeager_cloned.rs delete mode 100644 clippy_lints/src/methods/iter_skip_next.rs delete mode 100644 clippy_lints/src/methods/iter_skip_zero.rs delete mode 100644 clippy_lints/src/methods/iter_with_drain.rs delete mode 100644 clippy_lints/src/methods/iterator_step_by_zero.rs delete mode 100644 clippy_lints/src/methods/join_absolute_paths.rs delete mode 100644 clippy_lints/src/methods/manual_c_str_literals.rs delete mode 100644 clippy_lints/src/methods/manual_is_variant_and.rs delete mode 100644 clippy_lints/src/methods/manual_next_back.rs delete mode 100644 clippy_lints/src/methods/manual_ok_or.rs delete mode 100644 clippy_lints/src/methods/manual_saturating_arithmetic.rs delete mode 100644 clippy_lints/src/methods/manual_str_repeat.rs delete mode 100644 clippy_lints/src/methods/manual_try_fold.rs delete mode 100644 clippy_lints/src/methods/map_clone.rs delete mode 100644 clippy_lints/src/methods/map_collect_result_unit.rs delete mode 100644 clippy_lints/src/methods/map_err_ignore.rs delete mode 100644 clippy_lints/src/methods/map_flatten.rs delete mode 100644 clippy_lints/src/methods/map_identity.rs delete mode 100644 clippy_lints/src/methods/map_unwrap_or.rs delete mode 100644 clippy_lints/src/methods/mod.rs delete mode 100644 clippy_lints/src/methods/mut_mutex_lock.rs delete mode 100644 clippy_lints/src/methods/needless_collect.rs delete mode 100644 clippy_lints/src/methods/needless_option_as_deref.rs delete mode 100644 clippy_lints/src/methods/needless_option_take.rs delete mode 100644 clippy_lints/src/methods/no_effect_replace.rs delete mode 100644 clippy_lints/src/methods/obfuscated_if_else.rs delete mode 100644 clippy_lints/src/methods/ok_expect.rs delete mode 100644 clippy_lints/src/methods/open_options.rs delete mode 100644 clippy_lints/src/methods/option_as_ref_cloned.rs delete mode 100644 clippy_lints/src/methods/option_as_ref_deref.rs delete mode 100644 clippy_lints/src/methods/option_map_or_err_ok.rs delete mode 100644 clippy_lints/src/methods/option_map_or_none.rs delete mode 100644 clippy_lints/src/methods/option_map_unwrap_or.rs delete mode 100644 clippy_lints/src/methods/or_fun_call.rs delete mode 100644 clippy_lints/src/methods/or_then_unwrap.rs delete mode 100644 clippy_lints/src/methods/path_buf_push_overwrite.rs delete mode 100644 clippy_lints/src/methods/path_ends_with_ext.rs delete mode 100644 clippy_lints/src/methods/range_zip_with_len.rs delete mode 100644 clippy_lints/src/methods/read_line_without_trim.rs delete mode 100644 clippy_lints/src/methods/readonly_write_lock.rs delete mode 100644 clippy_lints/src/methods/redundant_as_str.rs delete mode 100644 clippy_lints/src/methods/repeat_once.rs delete mode 100644 clippy_lints/src/methods/result_map_or_else_none.rs delete mode 100644 clippy_lints/src/methods/search_is_some.rs delete mode 100644 clippy_lints/src/methods/seek_from_current.rs delete mode 100644 clippy_lints/src/methods/seek_to_start_instead_of_rewind.rs delete mode 100644 clippy_lints/src/methods/single_char_add_str.rs delete mode 100644 clippy_lints/src/methods/single_char_insert_string.rs delete mode 100644 clippy_lints/src/methods/single_char_pattern.rs delete mode 100644 clippy_lints/src/methods/single_char_push_string.rs delete mode 100644 clippy_lints/src/methods/skip_while_next.rs delete mode 100644 clippy_lints/src/methods/stable_sort_primitive.rs delete mode 100644 clippy_lints/src/methods/str_split.rs delete mode 100644 clippy_lints/src/methods/str_splitn.rs delete mode 100644 clippy_lints/src/methods/string_extend_chars.rs delete mode 100644 clippy_lints/src/methods/string_lit_chars_any.rs delete mode 100644 clippy_lints/src/methods/suspicious_command_arg_space.rs delete mode 100644 clippy_lints/src/methods/suspicious_map.rs delete mode 100644 clippy_lints/src/methods/suspicious_splitn.rs delete mode 100644 clippy_lints/src/methods/suspicious_to_owned.rs delete mode 100644 clippy_lints/src/methods/type_id_on_box.rs delete mode 100644 clippy_lints/src/methods/uninit_assumed_init.rs delete mode 100644 clippy_lints/src/methods/unit_hash.rs delete mode 100644 clippy_lints/src/methods/unnecessary_fallible_conversions.rs delete mode 100644 clippy_lints/src/methods/unnecessary_filter_map.rs delete mode 100644 clippy_lints/src/methods/unnecessary_fold.rs delete mode 100644 clippy_lints/src/methods/unnecessary_get_then_check.rs delete mode 100644 clippy_lints/src/methods/unnecessary_iter_cloned.rs delete mode 100644 clippy_lints/src/methods/unnecessary_join.rs delete mode 100644 clippy_lints/src/methods/unnecessary_lazy_eval.rs delete mode 100644 clippy_lints/src/methods/unnecessary_literal_unwrap.rs delete mode 100644 clippy_lints/src/methods/unnecessary_result_map_or_else.rs delete mode 100644 clippy_lints/src/methods/unnecessary_sort_by.rs delete mode 100644 clippy_lints/src/methods/unnecessary_to_owned.rs delete mode 100644 clippy_lints/src/methods/unused_enumerate_index.rs delete mode 100644 clippy_lints/src/methods/unwrap_expect_used.rs delete mode 100644 clippy_lints/src/methods/useless_asref.rs delete mode 100644 clippy_lints/src/methods/utils.rs delete mode 100644 clippy_lints/src/methods/vec_resize_to_zero.rs delete mode 100644 clippy_lints/src/methods/verbose_file_reads.rs delete mode 100644 clippy_lints/src/methods/waker_clone_wake.rs delete mode 100644 clippy_lints/src/methods/wrong_self_convention.rs delete mode 100644 clippy_lints/src/methods/zst_offset.rs delete mode 100644 clippy_lints/src/min_ident_chars.rs delete mode 100644 clippy_lints/src/minmax.rs delete mode 100644 clippy_lints/src/misc.rs delete mode 100644 clippy_lints/src/misc_early/builtin_type_shadow.rs delete mode 100644 clippy_lints/src/misc_early/double_neg.rs delete mode 100644 clippy_lints/src/misc_early/literal_suffix.rs delete mode 100644 clippy_lints/src/misc_early/mixed_case_hex_literals.rs delete mode 100644 clippy_lints/src/misc_early/mod.rs delete mode 100644 clippy_lints/src/misc_early/redundant_at_rest_pattern.rs delete mode 100644 clippy_lints/src/misc_early/redundant_pattern.rs delete mode 100644 clippy_lints/src/misc_early/unneeded_field_pattern.rs delete mode 100644 clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs delete mode 100644 clippy_lints/src/misc_early/zero_prefixed_literal.rs delete mode 100644 clippy_lints/src/mismatching_type_param_order.rs delete mode 100644 clippy_lints/src/missing_assert_message.rs delete mode 100644 clippy_lints/src/missing_asserts_for_indexing.rs delete mode 100644 clippy_lints/src/missing_const_for_fn.rs delete mode 100644 clippy_lints/src/missing_doc.rs delete mode 100644 clippy_lints/src/missing_enforced_import_rename.rs delete mode 100644 clippy_lints/src/missing_fields_in_debug.rs delete mode 100644 clippy_lints/src/missing_inline.rs delete mode 100644 clippy_lints/src/missing_trait_methods.rs delete mode 100644 clippy_lints/src/mixed_read_write_in_expression.rs delete mode 100644 clippy_lints/src/module_style.rs delete mode 100644 clippy_lints/src/multi_assignments.rs delete mode 100644 clippy_lints/src/multiple_bound_locations.rs delete mode 100644 clippy_lints/src/multiple_unsafe_ops_per_block.rs delete mode 100644 clippy_lints/src/mut_key.rs delete mode 100644 clippy_lints/src/mut_mut.rs delete mode 100644 clippy_lints/src/mut_reference.rs delete mode 100644 clippy_lints/src/mutable_debug_assertion.rs delete mode 100644 clippy_lints/src/mutex_atomic.rs delete mode 100644 clippy_lints/src/needless_arbitrary_self_type.rs delete mode 100644 clippy_lints/src/needless_bool.rs delete mode 100644 clippy_lints/src/needless_borrowed_ref.rs delete mode 100644 clippy_lints/src/needless_borrows_for_generic_args.rs delete mode 100644 clippy_lints/src/needless_continue.rs delete mode 100644 clippy_lints/src/needless_else.rs delete mode 100644 clippy_lints/src/needless_for_each.rs delete mode 100644 clippy_lints/src/needless_if.rs delete mode 100644 clippy_lints/src/needless_late_init.rs delete mode 100644 clippy_lints/src/needless_parens_on_range_literals.rs delete mode 100644 clippy_lints/src/needless_pass_by_ref_mut.rs delete mode 100644 clippy_lints/src/needless_pass_by_value.rs delete mode 100644 clippy_lints/src/needless_question_mark.rs delete mode 100644 clippy_lints/src/needless_update.rs delete mode 100644 clippy_lints/src/neg_cmp_op_on_partial_ord.rs delete mode 100644 clippy_lints/src/neg_multiply.rs delete mode 100644 clippy_lints/src/new_without_default.rs delete mode 100644 clippy_lints/src/no_effect.rs delete mode 100644 clippy_lints/src/no_mangle_with_rust_abi.rs delete mode 100644 clippy_lints/src/non_canonical_impls.rs delete mode 100644 clippy_lints/src/non_copy_const.rs delete mode 100644 clippy_lints/src/non_expressive_names.rs delete mode 100644 clippy_lints/src/non_octal_unix_permissions.rs delete mode 100644 clippy_lints/src/non_send_fields_in_send_ty.rs delete mode 100644 clippy_lints/src/nonstandard_macro_braces.rs delete mode 100644 clippy_lints/src/octal_escapes.rs delete mode 100644 clippy_lints/src/only_used_in_recursion.rs delete mode 100644 clippy_lints/src/operators/absurd_extreme_comparisons.rs delete mode 100644 clippy_lints/src/operators/arithmetic_side_effects.rs delete mode 100644 clippy_lints/src/operators/assign_op_pattern.rs delete mode 100644 clippy_lints/src/operators/bit_mask.rs delete mode 100644 clippy_lints/src/operators/cmp_owned.rs delete mode 100644 clippy_lints/src/operators/const_comparisons.rs delete mode 100644 clippy_lints/src/operators/double_comparison.rs delete mode 100644 clippy_lints/src/operators/duration_subsec.rs delete mode 100644 clippy_lints/src/operators/eq_op.rs delete mode 100644 clippy_lints/src/operators/erasing_op.rs delete mode 100644 clippy_lints/src/operators/float_cmp.rs delete mode 100644 clippy_lints/src/operators/float_equality_without_abs.rs delete mode 100644 clippy_lints/src/operators/identity_op.rs delete mode 100644 clippy_lints/src/operators/integer_division.rs delete mode 100644 clippy_lints/src/operators/misrefactored_assign_op.rs delete mode 100644 clippy_lints/src/operators/mod.rs delete mode 100644 clippy_lints/src/operators/modulo_arithmetic.rs delete mode 100644 clippy_lints/src/operators/modulo_one.rs delete mode 100644 clippy_lints/src/operators/needless_bitwise_bool.rs delete mode 100644 clippy_lints/src/operators/numeric_arithmetic.rs delete mode 100644 clippy_lints/src/operators/op_ref.rs delete mode 100644 clippy_lints/src/operators/ptr_eq.rs delete mode 100644 clippy_lints/src/operators/self_assignment.rs delete mode 100644 clippy_lints/src/operators/verbose_bit_mask.rs delete mode 100644 clippy_lints/src/option_env_unwrap.rs delete mode 100644 clippy_lints/src/option_if_let_else.rs delete mode 100644 clippy_lints/src/overflow_check_conditional.rs delete mode 100644 clippy_lints/src/panic_in_result_fn.rs delete mode 100644 clippy_lints/src/panic_unimplemented.rs delete mode 100644 clippy_lints/src/partial_pub_fields.rs delete mode 100644 clippy_lints/src/partialeq_ne_impl.rs delete mode 100644 clippy_lints/src/partialeq_to_none.rs delete mode 100644 clippy_lints/src/pass_by_ref_or_value.rs delete mode 100644 clippy_lints/src/pattern_type_mismatch.rs delete mode 100644 clippy_lints/src/permissions_set_readonly_false.rs delete mode 100644 clippy_lints/src/precedence.rs delete mode 100644 clippy_lints/src/ptr.rs delete mode 100644 clippy_lints/src/ptr_offset_with_cast.rs delete mode 100644 clippy_lints/src/pub_underscore_fields.rs delete mode 100644 clippy_lints/src/pub_use.rs delete mode 100644 clippy_lints/src/question_mark.rs delete mode 100644 clippy_lints/src/question_mark_used.rs delete mode 100644 clippy_lints/src/ranges.rs delete mode 100644 clippy_lints/src/raw_strings.rs delete mode 100644 clippy_lints/src/rc_clone_in_vec_init.rs delete mode 100644 clippy_lints/src/read_zero_byte_vec.rs delete mode 100644 clippy_lints/src/redundant_async_block.rs delete mode 100644 clippy_lints/src/redundant_clone.rs delete mode 100644 clippy_lints/src/redundant_closure_call.rs delete mode 100644 clippy_lints/src/redundant_else.rs delete mode 100644 clippy_lints/src/redundant_field_names.rs delete mode 100644 clippy_lints/src/redundant_locals.rs delete mode 100644 clippy_lints/src/redundant_pub_crate.rs delete mode 100644 clippy_lints/src/redundant_slicing.rs delete mode 100644 clippy_lints/src/redundant_static_lifetimes.rs delete mode 100644 clippy_lints/src/redundant_type_annotations.rs delete mode 100644 clippy_lints/src/ref_option_ref.rs delete mode 100644 clippy_lints/src/ref_patterns.rs delete mode 100644 clippy_lints/src/reference.rs delete mode 100644 clippy_lints/src/regex.rs delete mode 100644 clippy_lints/src/renamed_lints.rs delete mode 100644 clippy_lints/src/repeat_vec_with_capacity.rs delete mode 100644 clippy_lints/src/reserve_after_initialization.rs delete mode 100644 clippy_lints/src/return_self_not_must_use.rs delete mode 100644 clippy_lints/src/returns.rs delete mode 100644 clippy_lints/src/same_name_method.rs delete mode 100644 clippy_lints/src/self_named_constructors.rs delete mode 100644 clippy_lints/src/semicolon_block.rs delete mode 100644 clippy_lints/src/semicolon_if_nothing_returned.rs delete mode 100644 clippy_lints/src/serde_api.rs delete mode 100644 clippy_lints/src/shadow.rs delete mode 100644 clippy_lints/src/significant_drop_tightening.rs delete mode 100644 clippy_lints/src/single_call_fn.rs delete mode 100644 clippy_lints/src/single_char_lifetime_names.rs delete mode 100644 clippy_lints/src/single_component_path_imports.rs delete mode 100644 clippy_lints/src/single_range_in_vec_init.rs delete mode 100644 clippy_lints/src/size_of_in_element_count.rs delete mode 100644 clippy_lints/src/size_of_ref.rs delete mode 100644 clippy_lints/src/slow_vector_initialization.rs delete mode 100644 clippy_lints/src/std_instead_of_core.rs delete mode 100644 clippy_lints/src/strings.rs delete mode 100644 clippy_lints/src/strlen_on_c_strings.rs delete mode 100644 clippy_lints/src/suspicious_operation_groupings.rs delete mode 100644 clippy_lints/src/suspicious_trait_impl.rs delete mode 100644 clippy_lints/src/suspicious_xor_used_as_pow.rs delete mode 100644 clippy_lints/src/swap.rs delete mode 100644 clippy_lints/src/swap_ptr_to_ref.rs delete mode 100644 clippy_lints/src/tabs_in_doc_comments.rs delete mode 100644 clippy_lints/src/temporary_assignment.rs delete mode 100644 clippy_lints/src/tests_outside_test_module.rs delete mode 100644 clippy_lints/src/thread_local_initializer_can_be_made_const.rs delete mode 100644 clippy_lints/src/to_digit_is_some.rs delete mode 100644 clippy_lints/src/to_string_trait_impl.rs delete mode 100644 clippy_lints/src/trailing_empty_array.rs delete mode 100644 clippy_lints/src/trait_bounds.rs delete mode 100644 clippy_lints/src/transmute/crosspointer_transmute.rs delete mode 100644 clippy_lints/src/transmute/eager_transmute.rs delete mode 100644 clippy_lints/src/transmute/missing_transmute_annotations.rs delete mode 100644 clippy_lints/src/transmute/mod.rs delete mode 100644 clippy_lints/src/transmute/transmute_float_to_int.rs delete mode 100644 clippy_lints/src/transmute/transmute_int_to_bool.rs delete mode 100644 clippy_lints/src/transmute/transmute_int_to_char.rs delete mode 100644 clippy_lints/src/transmute/transmute_int_to_float.rs delete mode 100644 clippy_lints/src/transmute/transmute_int_to_non_zero.rs delete mode 100644 clippy_lints/src/transmute/transmute_null_to_fn.rs delete mode 100644 clippy_lints/src/transmute/transmute_num_to_bytes.rs delete mode 100644 clippy_lints/src/transmute/transmute_ptr_to_ptr.rs delete mode 100644 clippy_lints/src/transmute/transmute_ptr_to_ref.rs delete mode 100644 clippy_lints/src/transmute/transmute_ref_to_ref.rs delete mode 100644 clippy_lints/src/transmute/transmute_undefined_repr.rs delete mode 100644 clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs delete mode 100644 clippy_lints/src/transmute/transmuting_null.rs delete mode 100644 clippy_lints/src/transmute/unsound_collection_transmute.rs delete mode 100644 clippy_lints/src/transmute/useless_transmute.rs delete mode 100644 clippy_lints/src/transmute/utils.rs delete mode 100644 clippy_lints/src/transmute/wrong_transmute.rs delete mode 100644 clippy_lints/src/tuple_array_conversions.rs delete mode 100644 clippy_lints/src/types/borrowed_box.rs delete mode 100644 clippy_lints/src/types/box_collection.rs delete mode 100644 clippy_lints/src/types/linked_list.rs delete mode 100644 clippy_lints/src/types/mod.rs delete mode 100644 clippy_lints/src/types/option_option.rs delete mode 100644 clippy_lints/src/types/rc_buffer.rs delete mode 100644 clippy_lints/src/types/rc_mutex.rs delete mode 100644 clippy_lints/src/types/redundant_allocation.rs delete mode 100644 clippy_lints/src/types/type_complexity.rs delete mode 100644 clippy_lints/src/types/utils.rs delete mode 100644 clippy_lints/src/types/vec_box.rs delete mode 100644 clippy_lints/src/unconditional_recursion.rs delete mode 100644 clippy_lints/src/undocumented_unsafe_blocks.rs delete mode 100644 clippy_lints/src/unicode.rs delete mode 100644 clippy_lints/src/uninhabited_references.rs delete mode 100644 clippy_lints/src/uninit_vec.rs delete mode 100644 clippy_lints/src/unit_return_expecting_ord.rs delete mode 100644 clippy_lints/src/unit_types/let_unit_value.rs delete mode 100644 clippy_lints/src/unit_types/mod.rs delete mode 100644 clippy_lints/src/unit_types/unit_arg.rs delete mode 100644 clippy_lints/src/unit_types/unit_cmp.rs delete mode 100644 clippy_lints/src/unit_types/utils.rs delete mode 100644 clippy_lints/src/unnamed_address.rs delete mode 100644 clippy_lints/src/unnecessary_box_returns.rs delete mode 100644 clippy_lints/src/unnecessary_map_on_constructor.rs delete mode 100644 clippy_lints/src/unnecessary_owned_empty_strings.rs delete mode 100644 clippy_lints/src/unnecessary_self_imports.rs delete mode 100644 clippy_lints/src/unnecessary_struct_initialization.rs delete mode 100644 clippy_lints/src/unnecessary_wraps.rs delete mode 100644 clippy_lints/src/unnested_or_patterns.rs delete mode 100644 clippy_lints/src/unsafe_removed_from_name.rs delete mode 100644 clippy_lints/src/unused_async.rs delete mode 100644 clippy_lints/src/unused_io_amount.rs delete mode 100644 clippy_lints/src/unused_peekable.rs delete mode 100644 clippy_lints/src/unused_rounding.rs delete mode 100644 clippy_lints/src/unused_self.rs delete mode 100644 clippy_lints/src/unused_unit.rs delete mode 100644 clippy_lints/src/unwrap.rs delete mode 100644 clippy_lints/src/unwrap_in_result.rs delete mode 100644 clippy_lints/src/upper_case_acronyms.rs delete mode 100644 clippy_lints/src/use_self.rs delete mode 100644 clippy_lints/src/useless_conversion.rs delete mode 100644 clippy_lints/src/utils/author.rs delete mode 100644 clippy_lints/src/utils/dump_hir.rs delete mode 100644 clippy_lints/src/utils/format_args_collector.rs delete mode 100644 clippy_lints/src/utils/internal_lints.rs delete mode 100644 clippy_lints/src/utils/internal_lints/almost_standard_lint_formulation.rs delete mode 100644 clippy_lints/src/utils/internal_lints/collapsible_calls.rs delete mode 100644 clippy_lints/src/utils/internal_lints/compiler_lint_functions.rs delete mode 100644 clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs delete mode 100644 clippy_lints/src/utils/internal_lints/invalid_paths.rs delete mode 100644 clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs delete mode 100644 clippy_lints/src/utils/internal_lints/metadata_collector.rs delete mode 100644 clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs delete mode 100644 clippy_lints/src/utils/internal_lints/outer_expn_data_pass.rs delete mode 100644 clippy_lints/src/utils/internal_lints/produce_ice.rs delete mode 100644 clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs delete mode 100644 clippy_lints/src/utils/internal_lints/unsorted_clippy_utils_paths.rs delete mode 100644 clippy_lints/src/utils/mod.rs delete mode 100644 clippy_lints/src/vec.rs delete mode 100644 clippy_lints/src/vec_init_then_push.rs delete mode 100644 clippy_lints/src/visibility.rs delete mode 100644 clippy_lints/src/wildcard_imports.rs delete mode 100644 clippy_lints/src/write.rs delete mode 100644 clippy_lints/src/zero_div_zero.rs delete mode 100644 clippy_lints/src/zero_repeat_side_effects.rs delete mode 100644 clippy_lints/src/zero_sized_map_values.rs delete mode 100644 clippy_utils/Cargo.toml delete mode 100644 clippy_utils/src/ast_utils.rs delete mode 100644 clippy_utils/src/ast_utils/ident_iter.rs delete mode 100644 clippy_utils/src/attrs.rs delete mode 100644 clippy_utils/src/check_proc_macro.rs delete mode 100644 clippy_utils/src/comparisons.rs delete mode 100644 clippy_utils/src/consts.rs delete mode 100644 clippy_utils/src/diagnostics.rs delete mode 100644 clippy_utils/src/eager_or_lazy.rs delete mode 100644 clippy_utils/src/higher.rs delete mode 100644 clippy_utils/src/hir_utils.rs delete mode 100644 clippy_utils/src/lib.rs delete mode 100644 clippy_utils/src/macros.rs delete mode 100644 clippy_utils/src/mir/mod.rs delete mode 100644 clippy_utils/src/mir/possible_borrower.rs delete mode 100644 clippy_utils/src/mir/possible_origin.rs delete mode 100644 clippy_utils/src/mir/transitive_relation.rs delete mode 100644 clippy_utils/src/numeric_literal.rs delete mode 100644 clippy_utils/src/paths.rs delete mode 100644 clippy_utils/src/ptr.rs delete mode 100644 clippy_utils/src/qualify_min_const_fn.rs delete mode 100644 clippy_utils/src/source.rs delete mode 100644 clippy_utils/src/str_utils.rs delete mode 100644 clippy_utils/src/sugg.rs delete mode 100644 clippy_utils/src/sym_helper.rs delete mode 100644 clippy_utils/src/ty.rs delete mode 100644 clippy_utils/src/ty/type_certainty/certainty.rs delete mode 100644 clippy_utils/src/ty/type_certainty/mod.rs delete mode 100644 clippy_utils/src/usage.rs delete mode 100644 clippy_utils/src/visitors.rs delete mode 100644 declare_clippy_lint/Cargo.toml delete mode 100644 declare_clippy_lint/src/lib.rs delete mode 100644 etc/relicense/RELICENSE_DOCUMENTATION.md delete mode 100644 etc/relicense/contributors.txt delete mode 100644 etc/relicense/relicense_comments.txt delete mode 100644 lintcheck/Cargo.toml delete mode 100644 lintcheck/README.md delete mode 100644 lintcheck/lintcheck_crates.toml delete mode 100644 lintcheck/src/config.rs delete mode 100644 lintcheck/src/driver.rs delete mode 100644 lintcheck/src/main.rs delete mode 100644 lintcheck/src/popular-crates.rs delete mode 100644 lintcheck/src/recursive.rs delete mode 100644 lintcheck/test_sources.toml delete mode 100644 rust-toolchain delete mode 100644 rustc_tools_util/CHANGELOG.md delete mode 100644 rustc_tools_util/Cargo.toml delete mode 120000 rustc_tools_util/LICENSE-APACHE delete mode 120000 rustc_tools_util/LICENSE-MIT delete mode 100644 rustc_tools_util/README.md delete mode 100644 rustc_tools_util/src/lib.rs delete mode 100644 rustfmt.toml delete mode 100644 src/driver.rs delete mode 100644 src/main.rs delete mode 100644 tests/check-fmt.rs delete mode 100644 tests/clippy.toml delete mode 100644 tests/compile-test.rs delete mode 100644 tests/dogfood.rs delete mode 100644 tests/headers.rs delete mode 100644 tests/integration.rs delete mode 100644 tests/lint_message_convention.rs delete mode 100644 tests/missing-test-files.rs delete mode 100644 tests/test_utils/mod.rs delete mode 100644 tests/ui-cargo/cargo_common_metadata/fail/Cargo.stderr delete mode 100644 tests/ui-cargo/cargo_common_metadata/fail/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_common_metadata/fail/clippy.toml delete mode 100644 tests/ui-cargo/cargo_common_metadata/fail/src/main.rs delete mode 100644 tests/ui-cargo/cargo_common_metadata/fail_publish/Cargo.stderr delete mode 100644 tests/ui-cargo/cargo_common_metadata/fail_publish/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_common_metadata/fail_publish/src/main.rs delete mode 100644 tests/ui-cargo/cargo_common_metadata/fail_publish_true/Cargo.stderr delete mode 100644 tests/ui-cargo/cargo_common_metadata/fail_publish_true/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_common_metadata/fail_publish_true/src/main.rs delete mode 100644 tests/ui-cargo/cargo_common_metadata/pass/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_common_metadata/pass/clippy.toml delete mode 100644 tests/ui-cargo/cargo_common_metadata/pass/src/main.rs delete mode 100644 tests/ui-cargo/cargo_common_metadata/pass_publish_empty/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_common_metadata/pass_publish_empty/src/main.rs delete mode 100644 tests/ui-cargo/cargo_common_metadata/pass_publish_false/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_common_metadata/pass_publish_false/src/main.rs delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_both_diff/Cargo.stderr delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_both_diff/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_both_diff/clippy.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_both_diff/src/main.rs delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_both_same/Cargo.stderr delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_both_same/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_both_same/clippy.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_both_same/src/main.rs delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_cargo/Cargo.stderr delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_cargo/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_cargo/src/main.rs delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_clippy/Cargo.stderr delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_clippy/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_clippy/clippy.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_clippy/src/main.rs delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_file_attr/Cargo.stderr delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_file_attr/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_file_attr/clippy.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/fail_file_attr/src/main.rs delete mode 100644 tests/ui-cargo/cargo_rust_version/pass_both_same/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/pass_both_same/clippy.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/pass_both_same/src/main.rs delete mode 100644 tests/ui-cargo/cargo_rust_version/pass_cargo/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/pass_cargo/src/main.rs delete mode 100644 tests/ui-cargo/cargo_rust_version/pass_clippy/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/pass_clippy/clippy.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/pass_clippy/src/main.rs delete mode 100644 tests/ui-cargo/cargo_rust_version/pass_file_attr/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/pass_file_attr/src/main.rs delete mode 100644 tests/ui-cargo/cargo_rust_version/warn_both_diff/Cargo.stderr delete mode 100644 tests/ui-cargo/cargo_rust_version/warn_both_diff/Cargo.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/warn_both_diff/clippy.toml delete mode 100644 tests/ui-cargo/cargo_rust_version/warn_both_diff/src/main.rs delete mode 100644 tests/ui-cargo/duplicate_mod/fail/Cargo.stderr delete mode 100644 tests/ui-cargo/duplicate_mod/fail/Cargo.toml delete mode 100644 tests/ui-cargo/duplicate_mod/fail/src/a.rs delete mode 100644 tests/ui-cargo/duplicate_mod/fail/src/b.rs delete mode 100644 tests/ui-cargo/duplicate_mod/fail/src/c.rs delete mode 100644 tests/ui-cargo/duplicate_mod/fail/src/d.rs delete mode 100644 tests/ui-cargo/duplicate_mod/fail/src/from_other_module.rs delete mode 100644 tests/ui-cargo/duplicate_mod/fail/src/main.rs delete mode 100644 tests/ui-cargo/duplicate_mod/fail/src/other_module/mod.rs delete mode 100644 tests/ui-cargo/feature_name/fail/Cargo.stderr delete mode 100644 tests/ui-cargo/feature_name/fail/Cargo.toml delete mode 100644 tests/ui-cargo/feature_name/fail/src/main.rs delete mode 100644 tests/ui-cargo/feature_name/pass/Cargo.toml delete mode 100644 tests/ui-cargo/feature_name/pass/src/main.rs delete mode 100644 tests/ui-cargo/lint_groups_priority/fail/Cargo.stderr delete mode 100644 tests/ui-cargo/lint_groups_priority/fail/Cargo.toml delete mode 100644 tests/ui-cargo/lint_groups_priority/fail/src/lib.rs delete mode 100644 tests/ui-cargo/lint_groups_priority/pass/Cargo.toml delete mode 100644 tests/ui-cargo/lint_groups_priority/pass/src/lib.rs delete mode 100644 tests/ui-cargo/module_style/fail_mod/Cargo.stderr delete mode 100644 tests/ui-cargo/module_style/fail_mod/Cargo.toml delete mode 100644 tests/ui-cargo/module_style/fail_mod/src/bad/inner.rs delete mode 100644 tests/ui-cargo/module_style/fail_mod/src/bad/inner/stuff.rs delete mode 100644 tests/ui-cargo/module_style/fail_mod/src/bad/inner/stuff/most.rs delete mode 100644 tests/ui-cargo/module_style/fail_mod/src/bad/mod.rs delete mode 100644 tests/ui-cargo/module_style/fail_mod/src/main.rs delete mode 100644 tests/ui-cargo/module_style/fail_mod_remap/Cargo.stderr delete mode 100644 tests/ui-cargo/module_style/fail_mod_remap/Cargo.toml delete mode 100644 tests/ui-cargo/module_style/fail_mod_remap/src/bad.rs delete mode 100644 tests/ui-cargo/module_style/fail_mod_remap/src/bad/inner.rs delete mode 100644 tests/ui-cargo/module_style/fail_mod_remap/src/main.rs delete mode 100644 tests/ui-cargo/module_style/fail_no_mod/Cargo.stderr delete mode 100644 tests/ui-cargo/module_style/fail_no_mod/Cargo.toml delete mode 100644 tests/ui-cargo/module_style/fail_no_mod/src/bad/mod.rs delete mode 100644 tests/ui-cargo/module_style/fail_no_mod/src/main.rs delete mode 100644 tests/ui-cargo/module_style/pass_mod/Cargo.toml delete mode 100644 tests/ui-cargo/module_style/pass_mod/src/bad/mod.rs delete mode 100644 tests/ui-cargo/module_style/pass_mod/src/main.rs delete mode 100644 tests/ui-cargo/module_style/pass_mod/src/more/foo.rs delete mode 100644 tests/ui-cargo/module_style/pass_mod/src/more/inner/mod.rs delete mode 100644 tests/ui-cargo/module_style/pass_mod/src/more/mod.rs delete mode 100644 tests/ui-cargo/module_style/pass_no_mod/Cargo.toml delete mode 100644 tests/ui-cargo/module_style/pass_no_mod/src/good.rs delete mode 100644 tests/ui-cargo/module_style/pass_no_mod/src/main.rs delete mode 100644 tests/ui-cargo/multiple_config_files/no_warn/Cargo.toml delete mode 100644 tests/ui-cargo/multiple_config_files/no_warn/clippy.toml delete mode 100644 tests/ui-cargo/multiple_config_files/no_warn/src/main.rs delete mode 100644 tests/ui-cargo/multiple_config_files/warn/.clippy.toml delete mode 100644 tests/ui-cargo/multiple_config_files/warn/Cargo.stderr delete mode 100644 tests/ui-cargo/multiple_config_files/warn/Cargo.toml delete mode 100644 tests/ui-cargo/multiple_config_files/warn/clippy.toml delete mode 100644 tests/ui-cargo/multiple_config_files/warn/src/main.rs delete mode 100644 tests/ui-cargo/multiple_crate_versions/12145_with_dashes/Cargo.stderr delete mode 100644 tests/ui-cargo/multiple_crate_versions/12145_with_dashes/Cargo.toml delete mode 100644 tests/ui-cargo/multiple_crate_versions/12145_with_dashes/src/main.rs delete mode 100644 tests/ui-cargo/multiple_crate_versions/12176_allow_duplicate_crates/Cargo.toml delete mode 100644 tests/ui-cargo/multiple_crate_versions/12176_allow_duplicate_crates/clippy.toml delete mode 100644 tests/ui-cargo/multiple_crate_versions/12176_allow_duplicate_crates/src/main.rs delete mode 100644 tests/ui-cargo/multiple_crate_versions/5041_allow_dev_build/Cargo.toml delete mode 100644 tests/ui-cargo/multiple_crate_versions/5041_allow_dev_build/src/main.rs delete mode 100644 tests/ui-cargo/multiple_crate_versions/fail/Cargo.lock delete mode 100644 tests/ui-cargo/multiple_crate_versions/fail/Cargo.stderr delete mode 100644 tests/ui-cargo/multiple_crate_versions/fail/Cargo.toml delete mode 100644 tests/ui-cargo/multiple_crate_versions/fail/src/main.rs delete mode 100644 tests/ui-cargo/multiple_crate_versions/pass/Cargo.toml delete mode 100644 tests/ui-cargo/multiple_crate_versions/pass/src/main.rs delete mode 100755 tests/ui-cargo/update-all-references.sh delete mode 100644 tests/ui-cargo/wildcard_dependencies/fail/Cargo.stderr delete mode 100644 tests/ui-cargo/wildcard_dependencies/fail/Cargo.toml delete mode 100644 tests/ui-cargo/wildcard_dependencies/fail/src/main.rs delete mode 100644 tests/ui-cargo/wildcard_dependencies/pass/Cargo.toml delete mode 100644 tests/ui-cargo/wildcard_dependencies/pass/src/main.rs delete mode 100644 tests/ui-internal/auxiliary/paths.rs delete mode 100644 tests/ui-internal/check_clippy_version_attribute.rs delete mode 100644 tests/ui-internal/check_clippy_version_attribute.stderr delete mode 100644 tests/ui-internal/check_formulation.rs delete mode 100644 tests/ui-internal/check_formulation.stderr delete mode 100644 tests/ui-internal/collapsible_span_lint_calls.fixed delete mode 100644 tests/ui-internal/collapsible_span_lint_calls.rs delete mode 100644 tests/ui-internal/collapsible_span_lint_calls.stderr delete mode 100644 tests/ui-internal/custom_ice_message.rs delete mode 100644 tests/ui-internal/custom_ice_message.stderr delete mode 100644 tests/ui-internal/default_deprecation_reason.rs delete mode 100644 tests/ui-internal/default_deprecation_reason.stderr delete mode 100644 tests/ui-internal/default_lint.rs delete mode 100644 tests/ui-internal/default_lint.stderr delete mode 100644 tests/ui-internal/disallow_span_lint.rs delete mode 100644 tests/ui-internal/disallow_span_lint.stderr delete mode 100644 tests/ui-internal/interning_defined_symbol.fixed delete mode 100644 tests/ui-internal/interning_defined_symbol.rs delete mode 100644 tests/ui-internal/interning_defined_symbol.stderr delete mode 100644 tests/ui-internal/invalid_msrv_attr_impl.fixed delete mode 100644 tests/ui-internal/invalid_msrv_attr_impl.rs delete mode 100644 tests/ui-internal/invalid_msrv_attr_impl.stderr delete mode 100644 tests/ui-internal/invalid_paths.rs delete mode 100644 tests/ui-internal/invalid_paths.stderr delete mode 100644 tests/ui-internal/lint_without_lint_pass.rs delete mode 100644 tests/ui-internal/lint_without_lint_pass.stderr delete mode 100644 tests/ui-internal/outer_expn_data.fixed delete mode 100644 tests/ui-internal/outer_expn_data.rs delete mode 100644 tests/ui-internal/outer_expn_data.stderr delete mode 100644 tests/ui-internal/unnecessary_def_path.fixed delete mode 100644 tests/ui-internal/unnecessary_def_path.rs delete mode 100644 tests/ui-internal/unnecessary_def_path.stderr delete mode 100644 tests/ui-internal/unnecessary_def_path_hardcoded_path.rs delete mode 100644 tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr delete mode 100644 tests/ui-internal/unnecessary_symbol_str.fixed delete mode 100644 tests/ui-internal/unnecessary_symbol_str.rs delete mode 100644 tests/ui-internal/unnecessary_symbol_str.stderr delete mode 100644 tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr delete mode 100644 tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr delete mode 100644 tests/ui-toml/absolute_paths/absolute_paths.rs delete mode 100644 tests/ui-toml/absolute_paths/allow_crates/clippy.toml delete mode 100644 tests/ui-toml/absolute_paths/auxiliary/helper.rs delete mode 100644 tests/ui-toml/absolute_paths/disallow_crates/clippy.toml delete mode 100644 tests/ui-toml/allow_mixed_uninlined_format_args/clippy.toml delete mode 100644 tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed delete mode 100644 tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs delete mode 100644 tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr delete mode 100644 tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs delete mode 100644 tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr delete mode 100644 tests/ui-toml/arithmetic_side_effects_allowed/clippy.toml delete mode 100644 tests/ui-toml/array_size_threshold/array_size_threshold.rs delete mode 100644 tests/ui-toml/array_size_threshold/array_size_threshold.stderr delete mode 100644 tests/ui-toml/array_size_threshold/clippy.toml delete mode 100644 tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs delete mode 100644 tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr delete mode 100644 tests/ui-toml/await_holding_invalid_type/clippy.toml delete mode 100644 tests/ui-toml/bad_toml/clippy.toml delete mode 100644 tests/ui-toml/bad_toml/conf_bad_toml.rs delete mode 100644 tests/ui-toml/bad_toml/conf_bad_toml.stderr delete mode 100644 tests/ui-toml/bad_toml_type/clippy.toml delete mode 100644 tests/ui-toml/bad_toml_type/conf_bad_type.rs delete mode 100644 tests/ui-toml/bad_toml_type/conf_bad_type.stderr delete mode 100644 tests/ui-toml/borrow_interior_mutable_const/clippy.toml delete mode 100644 tests/ui-toml/borrow_interior_mutable_const/ignore.rs delete mode 100644 tests/ui-toml/conf_deprecated_key/clippy.toml delete mode 100644 tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs delete mode 100644 tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr delete mode 100644 tests/ui-toml/dbg_macro/clippy.toml delete mode 100644 tests/ui-toml/dbg_macro/dbg_macro.fixed delete mode 100644 tests/ui-toml/dbg_macro/dbg_macro.rs delete mode 100644 tests/ui-toml/dbg_macro/dbg_macro.stderr delete mode 100644 tests/ui-toml/decimal_literal_representation/clippy.toml delete mode 100644 tests/ui-toml/decimal_literal_representation/decimal_literal_representation.fixed delete mode 100644 tests/ui-toml/decimal_literal_representation/decimal_literal_representation.rs delete mode 100644 tests/ui-toml/decimal_literal_representation/decimal_literal_representation.stderr delete mode 100644 tests/ui-toml/declare_interior_mutable_const/clippy.toml delete mode 100644 tests/ui-toml/declare_interior_mutable_const/ignore.rs delete mode 100644 tests/ui-toml/disallowed_macros/auxiliary/macros.rs delete mode 100644 tests/ui-toml/disallowed_macros/auxiliary/proc_macros.rs delete mode 100644 tests/ui-toml/disallowed_macros/clippy.toml delete mode 100644 tests/ui-toml/disallowed_macros/disallowed_macros.rs delete mode 100644 tests/ui-toml/disallowed_macros/disallowed_macros.stderr delete mode 100644 tests/ui-toml/disallowed_names_append/clippy.toml delete mode 100644 tests/ui-toml/disallowed_names_append/disallowed_names.rs delete mode 100644 tests/ui-toml/disallowed_names_append/disallowed_names.stderr delete mode 100644 tests/ui-toml/disallowed_names_replace/clippy.toml delete mode 100644 tests/ui-toml/disallowed_names_replace/disallowed_names.rs delete mode 100644 tests/ui-toml/disallowed_names_replace/disallowed_names.stderr delete mode 100644 tests/ui-toml/disallowed_script_idents/clippy.toml delete mode 100644 tests/ui-toml/disallowed_script_idents/disallowed_script_idents.rs delete mode 100644 tests/ui-toml/disallowed_script_idents/disallowed_script_idents.stderr delete mode 100644 tests/ui-toml/doc_valid_idents_append/clippy.toml delete mode 100644 tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed delete mode 100644 tests/ui-toml/doc_valid_idents_append/doc_markdown.rs delete mode 100644 tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr delete mode 100644 tests/ui-toml/doc_valid_idents_replace/clippy.toml delete mode 100644 tests/ui-toml/doc_valid_idents_replace/doc_markdown.fixed delete mode 100644 tests/ui-toml/doc_valid_idents_replace/doc_markdown.rs delete mode 100644 tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr delete mode 100644 tests/ui-toml/duplicated_keys/clippy.toml delete mode 100644 tests/ui-toml/duplicated_keys/duplicated_keys.rs delete mode 100644 tests/ui-toml/duplicated_keys/duplicated_keys.stderr delete mode 100644 tests/ui-toml/duplicated_keys_deprecated/clippy.toml delete mode 100644 tests/ui-toml/duplicated_keys_deprecated/duplicated_keys.rs delete mode 100644 tests/ui-toml/duplicated_keys_deprecated/duplicated_keys.stderr delete mode 100644 tests/ui-toml/duplicated_keys_deprecated_2/clippy.toml delete mode 100644 tests/ui-toml/duplicated_keys_deprecated_2/duplicated_keys.rs delete mode 100644 tests/ui-toml/duplicated_keys_deprecated_2/duplicated_keys.stderr delete mode 100644 tests/ui-toml/enum_variant_size/clippy.toml delete mode 100644 tests/ui-toml/enum_variant_size/enum_variant_size.fixed delete mode 100644 tests/ui-toml/enum_variant_size/enum_variant_size.rs delete mode 100644 tests/ui-toml/enum_variant_size/enum_variant_size.stderr delete mode 100644 tests/ui-toml/excessive_nesting/clippy.toml delete mode 100644 tests/ui-toml/excessive_nesting/excessive_nesting.rs delete mode 100644 tests/ui-toml/excessive_nesting/excessive_nesting.stderr delete mode 100644 tests/ui-toml/expect_used/clippy.toml delete mode 100644 tests/ui-toml/expect_used/expect_used.rs delete mode 100644 tests/ui-toml/expect_used/expect_used.stderr delete mode 100644 tests/ui-toml/explicit_iter_loop/clippy.toml delete mode 100644 tests/ui-toml/explicit_iter_loop/explicit_iter_loop.fixed delete mode 100644 tests/ui-toml/explicit_iter_loop/explicit_iter_loop.rs delete mode 100644 tests/ui-toml/explicit_iter_loop/explicit_iter_loop.stderr delete mode 100644 tests/ui-toml/extra_unused_type_parameters/clippy.toml delete mode 100644 tests/ui-toml/extra_unused_type_parameters/extra_unused_type_parameters.rs delete mode 100644 tests/ui-toml/fn_params_excessive_bools/clippy.toml delete mode 100644 tests/ui-toml/fn_params_excessive_bools/test.rs delete mode 100644 tests/ui-toml/fn_params_excessive_bools/test.stderr delete mode 100644 tests/ui-toml/functions_maxlines/clippy.toml delete mode 100644 tests/ui-toml/functions_maxlines/test.rs delete mode 100644 tests/ui-toml/functions_maxlines/test.stderr delete mode 100644 tests/ui-toml/good_toml_no_false_negatives/clippy.toml delete mode 100644 tests/ui-toml/good_toml_no_false_negatives/conf_no_false_negatives.rs delete mode 100644 tests/ui-toml/ifs_same_cond/clippy.toml delete mode 100644 tests/ui-toml/ifs_same_cond/ifs_same_cond.rs delete mode 100644 tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr delete mode 100644 tests/ui-toml/impl_trait_in_params/clippy.toml delete mode 100644 tests/ui-toml/impl_trait_in_params/impl_trait_in_params.rs delete mode 100644 tests/ui-toml/impl_trait_in_params/impl_trait_in_params.stderr delete mode 100644 tests/ui-toml/invalid_min_rust_version/clippy.toml delete mode 100644 tests/ui-toml/invalid_min_rust_version/invalid_min_rust_version.rs delete mode 100644 tests/ui-toml/invalid_min_rust_version/invalid_min_rust_version.stderr delete mode 100644 tests/ui-toml/item_name_repetitions/allowed_prefixes/clippy.toml delete mode 100644 tests/ui-toml/item_name_repetitions/allowed_prefixes/item_name_repetitions.rs delete mode 100644 tests/ui-toml/item_name_repetitions/allowed_prefixes/item_name_repetitions.stderr delete mode 100644 tests/ui-toml/item_name_repetitions/allowed_prefixes_extend/clippy.toml delete mode 100644 tests/ui-toml/item_name_repetitions/allowed_prefixes_extend/item_name_repetitions.rs delete mode 100644 tests/ui-toml/item_name_repetitions/allowed_prefixes_extend/item_name_repetitions.stderr delete mode 100644 tests/ui-toml/item_name_repetitions/threshold0/clippy.toml delete mode 100644 tests/ui-toml/item_name_repetitions/threshold0/item_name_repetitions.rs delete mode 100644 tests/ui-toml/item_name_repetitions/threshold5/clippy.toml delete mode 100644 tests/ui-toml/item_name_repetitions/threshold5/item_name_repetitions.rs delete mode 100644 tests/ui-toml/item_name_repetitions/threshold5/item_name_repetitions.stderr delete mode 100644 tests/ui-toml/large_futures/clippy.toml delete mode 100644 tests/ui-toml/large_futures/large_futures.fixed delete mode 100644 tests/ui-toml/large_futures/large_futures.rs delete mode 100644 tests/ui-toml/large_futures/large_futures.stderr delete mode 100644 tests/ui-toml/large_include_file/clippy.toml delete mode 100644 tests/ui-toml/large_include_file/large_include_file.rs delete mode 100644 tests/ui-toml/large_include_file/large_include_file.stderr delete mode 100644 tests/ui-toml/large_include_file/too_big.txt delete mode 100644 tests/ui-toml/large_stack_frames/clippy.toml delete mode 100644 tests/ui-toml/large_stack_frames/large_stack_frames.rs delete mode 100644 tests/ui-toml/large_stack_frames/large_stack_frames.stderr delete mode 100644 tests/ui-toml/large_types_passed_by_value/clippy.toml delete mode 100644 tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.fixed delete mode 100644 tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.rs delete mode 100644 tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.stderr delete mode 100644 tests/ui-toml/lint_decimal_readability/clippy.toml delete mode 100644 tests/ui-toml/lint_decimal_readability/test.fixed delete mode 100644 tests/ui-toml/lint_decimal_readability/test.rs delete mode 100644 tests/ui-toml/lint_decimal_readability/test.stderr delete mode 100644 tests/ui-toml/macro_metavars_in_unsafe/default/test.rs delete mode 100644 tests/ui-toml/macro_metavars_in_unsafe/default/test.stderr delete mode 100644 tests/ui-toml/macro_metavars_in_unsafe/private/clippy.toml delete mode 100644 tests/ui-toml/macro_metavars_in_unsafe/private/test.rs delete mode 100644 tests/ui-toml/macro_metavars_in_unsafe/private/test.stderr delete mode 100644 tests/ui-toml/manual_let_else/clippy.toml delete mode 100644 tests/ui-toml/manual_let_else/manual_let_else.fixed delete mode 100644 tests/ui-toml/manual_let_else/manual_let_else.rs delete mode 100644 tests/ui-toml/manual_let_else/manual_let_else.stderr delete mode 100644 tests/ui-toml/max_suggested_slice_pattern_length/clippy.toml delete mode 100644 tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.fixed delete mode 100644 tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.rs delete mode 100644 tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.stderr delete mode 100644 tests/ui-toml/min_ident_chars/auxiliary/extern_types.rs delete mode 100644 tests/ui-toml/min_ident_chars/clippy.toml delete mode 100644 tests/ui-toml/min_ident_chars/min_ident_chars.rs delete mode 100644 tests/ui-toml/min_ident_chars/min_ident_chars.stderr delete mode 100644 tests/ui-toml/min_rust_version/clippy.toml delete mode 100644 tests/ui-toml/min_rust_version/min_rust_version.fixed delete mode 100644 tests/ui-toml/min_rust_version/min_rust_version.rs delete mode 100644 tests/ui-toml/min_rust_version/min_rust_version.stderr delete mode 100644 tests/ui-toml/missing_enforced_import_rename/clippy.toml delete mode 100644 tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.fixed delete mode 100644 tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs delete mode 100644 tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr delete mode 100644 tests/ui-toml/module_inception/clippy.toml delete mode 100644 tests/ui-toml/module_inception/module_inception.rs delete mode 100644 tests/ui-toml/module_inception/module_inception.stderr delete mode 100644 tests/ui-toml/modulo_arithmetic/clippy.toml delete mode 100644 tests/ui-toml/modulo_arithmetic/modulo_arithmetic.rs delete mode 100644 tests/ui-toml/modulo_arithmetic/modulo_arithmetic.stderr delete mode 100644 tests/ui-toml/mut_key/clippy.toml delete mode 100644 tests/ui-toml/mut_key/mut_key.rs delete mode 100644 tests/ui-toml/needless_raw_string_hashes_one_allowed/clippy.toml delete mode 100644 tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.fixed delete mode 100644 tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs delete mode 100644 tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.stderr delete mode 100644 tests/ui-toml/nonstandard_macro_braces/auxiliary/proc_macro_derive.rs delete mode 100644 tests/ui-toml/nonstandard_macro_braces/clippy.toml delete mode 100644 tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed delete mode 100644 tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs delete mode 100644 tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr delete mode 100644 tests/ui-toml/path_ends_with_ext/clippy.toml delete mode 100644 tests/ui-toml/path_ends_with_ext/path_ends_with_ext.rs delete mode 100644 tests/ui-toml/print_macro/clippy.toml delete mode 100644 tests/ui-toml/print_macro/print_macro.rs delete mode 100644 tests/ui-toml/print_macro/print_macro.stderr delete mode 100644 tests/ui-toml/private-doc-errors/clippy.toml delete mode 100644 tests/ui-toml/private-doc-errors/doc_lints.rs delete mode 100644 tests/ui-toml/private-doc-errors/doc_lints.stderr delete mode 100644 tests/ui-toml/pub_crate_missing_docs/clippy.toml delete mode 100644 tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs delete mode 100644 tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr delete mode 100644 tests/ui-toml/pub_underscore_fields/all_pub_fields/clippy.toml delete mode 100644 tests/ui-toml/pub_underscore_fields/exported/clippy.toml delete mode 100644 tests/ui-toml/pub_underscore_fields/pub_underscore_fields.all_pub_fields.stderr delete mode 100644 tests/ui-toml/pub_underscore_fields/pub_underscore_fields.exported.stderr delete mode 100644 tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs delete mode 100644 tests/ui-toml/renamed_function_params/default/clippy.toml delete mode 100644 tests/ui-toml/renamed_function_params/extend/clippy.toml delete mode 100644 tests/ui-toml/renamed_function_params/renamed_function_params.default.stderr delete mode 100644 tests/ui-toml/renamed_function_params/renamed_function_params.extend.stderr delete mode 100644 tests/ui-toml/renamed_function_params/renamed_function_params.rs delete mode 100644 tests/ui-toml/result_large_err/clippy.toml delete mode 100644 tests/ui-toml/result_large_err/result_large_err.rs delete mode 100644 tests/ui-toml/result_large_err/result_large_err.stderr delete mode 100644 tests/ui-toml/semicolon_block/both.fixed delete mode 100644 tests/ui-toml/semicolon_block/both.rs delete mode 100644 tests/ui-toml/semicolon_block/both.stderr delete mode 100644 tests/ui-toml/semicolon_block/clippy.toml delete mode 100644 tests/ui-toml/semicolon_block/semicolon_inside_block.fixed delete mode 100644 tests/ui-toml/semicolon_block/semicolon_inside_block.rs delete mode 100644 tests/ui-toml/semicolon_block/semicolon_inside_block.stderr delete mode 100644 tests/ui-toml/semicolon_block/semicolon_outside_block.fixed delete mode 100644 tests/ui-toml/semicolon_block/semicolon_outside_block.rs delete mode 100644 tests/ui-toml/semicolon_block/semicolon_outside_block.stderr delete mode 100644 tests/ui-toml/strict_non_send_fields_in_send_ty/clippy.toml delete mode 100644 tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs delete mode 100644 tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr delete mode 100644 tests/ui-toml/struct_excessive_bools/clippy.toml delete mode 100644 tests/ui-toml/struct_excessive_bools/test.rs delete mode 100644 tests/ui-toml/struct_excessive_bools/test.stderr delete mode 100644 tests/ui-toml/suppress_lint_in_const/clippy.toml delete mode 100644 tests/ui-toml/suppress_lint_in_const/test.rs delete mode 100644 tests/ui-toml/suppress_lint_in_const/test.stderr delete mode 100644 tests/ui-toml/toml_disallow/clippy.toml delete mode 100644 tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs delete mode 100644 tests/ui-toml/toml_disallow/conf_french_disallowed_name.stderr delete mode 100644 tests/ui-toml/toml_disallowed_methods/clippy.toml delete mode 100644 tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs delete mode 100644 tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr delete mode 100644 tests/ui-toml/toml_disallowed_types/clippy.toml delete mode 100644 tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs delete mode 100644 tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr delete mode 100644 tests/ui-toml/toml_trivially_copy/clippy.toml delete mode 100644 tests/ui-toml/toml_trivially_copy/test.rs delete mode 100644 tests/ui-toml/toml_trivially_copy/test.stderr delete mode 100644 tests/ui-toml/toml_unknown_key/clippy.toml delete mode 100644 tests/ui-toml/toml_unknown_key/conf_unknown_key.rs delete mode 100644 tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr delete mode 100644 tests/ui-toml/too_large_for_stack/boxed_local.rs delete mode 100644 tests/ui-toml/too_large_for_stack/boxed_local.stderr delete mode 100644 tests/ui-toml/too_large_for_stack/clippy.toml delete mode 100644 tests/ui-toml/too_large_for_stack/useless_vec.fixed delete mode 100644 tests/ui-toml/too_large_for_stack/useless_vec.rs delete mode 100644 tests/ui-toml/too_large_for_stack/useless_vec.stderr delete mode 100644 tests/ui-toml/too_many_arguments/clippy.toml delete mode 100644 tests/ui-toml/too_many_arguments/too_many_arguments.rs delete mode 100644 tests/ui-toml/too_many_arguments/too_many_arguments.stderr delete mode 100644 tests/ui-toml/type_complexity/clippy.toml delete mode 100644 tests/ui-toml/type_complexity/type_complexity.rs delete mode 100644 tests/ui-toml/type_complexity/type_complexity.stderr delete mode 100644 tests/ui-toml/type_repetition_in_bounds/clippy.toml delete mode 100644 tests/ui-toml/type_repetition_in_bounds/main.rs delete mode 100644 tests/ui-toml/type_repetition_in_bounds/main.stderr delete mode 100644 tests/ui-toml/undocumented_unsafe_blocks/default/clippy.toml delete mode 100644 tests/ui-toml/undocumented_unsafe_blocks/disabled/clippy.toml delete mode 100644 tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr delete mode 100644 tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr delete mode 100644 tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs delete mode 100644 tests/ui-toml/unnecessary_box_returns/clippy.toml delete mode 100644 tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.fixed delete mode 100644 tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.rs delete mode 100644 tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.stderr delete mode 100644 tests/ui-toml/unwrap_used/clippy.toml delete mode 100644 tests/ui-toml/unwrap_used/unwrap_used.fixed delete mode 100644 tests/ui-toml/unwrap_used/unwrap_used.rs delete mode 100644 tests/ui-toml/unwrap_used/unwrap_used.stderr delete mode 100755 tests/ui-toml/update-all-references.sh delete mode 100644 tests/ui-toml/upper_case_acronyms_aggressive/clippy.toml delete mode 100644 tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.fixed delete mode 100644 tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs delete mode 100644 tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr delete mode 100644 tests/ui-toml/useless_vec/clippy.toml delete mode 100644 tests/ui-toml/useless_vec/useless_vec.fixed delete mode 100644 tests/ui-toml/useless_vec/useless_vec.rs delete mode 100644 tests/ui-toml/useless_vec/useless_vec.stderr delete mode 100644 tests/ui-toml/vec_box_sized/clippy.toml delete mode 100644 tests/ui-toml/vec_box_sized/test.fixed delete mode 100644 tests/ui-toml/vec_box_sized/test.rs delete mode 100644 tests/ui-toml/vec_box_sized/test.stderr delete mode 100644 tests/ui-toml/verbose_bit_mask/clippy.toml delete mode 100644 tests/ui-toml/verbose_bit_mask/verbose_bit_mask.fixed delete mode 100644 tests/ui-toml/verbose_bit_mask/verbose_bit_mask.rs delete mode 100644 tests/ui-toml/verbose_bit_mask/verbose_bit_mask.stderr delete mode 100644 tests/ui-toml/wildcard_imports/clippy.toml delete mode 100644 tests/ui-toml/wildcard_imports/wildcard_imports.fixed delete mode 100644 tests/ui-toml/wildcard_imports/wildcard_imports.rs delete mode 100644 tests/ui-toml/wildcard_imports/wildcard_imports.stderr delete mode 100644 tests/ui-toml/wildcard_imports_whitelist/clippy.toml delete mode 100644 tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.fixed delete mode 100644 tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.rs delete mode 100644 tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.stderr delete mode 100644 tests/ui-toml/zero_single_char_names/clippy.toml delete mode 100644 tests/ui-toml/zero_single_char_names/zero_single_char_names.rs delete mode 100644 tests/ui/absurd-extreme-comparisons.rs delete mode 100644 tests/ui/absurd-extreme-comparisons.stderr delete mode 100644 tests/ui/allow_attributes.fixed delete mode 100644 tests/ui/allow_attributes.rs delete mode 100644 tests/ui/allow_attributes.stderr delete mode 100644 tests/ui/allow_attributes_without_reason.rs delete mode 100644 tests/ui/allow_attributes_without_reason.stderr delete mode 100644 tests/ui/almost_complete_range.fixed delete mode 100644 tests/ui/almost_complete_range.rs delete mode 100644 tests/ui/almost_complete_range.stderr delete mode 100644 tests/ui/approx_const.rs delete mode 100644 tests/ui/approx_const.stderr delete mode 100644 tests/ui/arc_with_non_send_sync.rs delete mode 100644 tests/ui/arc_with_non_send_sync.stderr delete mode 100644 tests/ui/arithmetic_side_effects.rs delete mode 100644 tests/ui/arithmetic_side_effects.stderr delete mode 100644 tests/ui/as_conversions.rs delete mode 100644 tests/ui/as_conversions.stderr delete mode 100644 tests/ui/as_ptr_cast_mut.rs delete mode 100644 tests/ui/as_ptr_cast_mut.stderr delete mode 100644 tests/ui/as_underscore.fixed delete mode 100644 tests/ui/as_underscore.rs delete mode 100644 tests/ui/as_underscore.stderr delete mode 100644 tests/ui/asm_syntax_not_x86.rs delete mode 100644 tests/ui/asm_syntax_x86.i686.stderr delete mode 100644 tests/ui/asm_syntax_x86.rs delete mode 100644 tests/ui/asm_syntax_x86.x86_64.stderr delete mode 100644 tests/ui/assertions_on_constants.rs delete mode 100644 tests/ui/assertions_on_constants.stderr delete mode 100644 tests/ui/assertions_on_result_states.fixed delete mode 100644 tests/ui/assertions_on_result_states.rs delete mode 100644 tests/ui/assertions_on_result_states.stderr delete mode 100644 tests/ui/assign_ops.fixed delete mode 100644 tests/ui/assign_ops.rs delete mode 100644 tests/ui/assign_ops.stderr delete mode 100644 tests/ui/assign_ops2.rs delete mode 100644 tests/ui/assign_ops2.stderr delete mode 100644 tests/ui/assigning_clones.fixed delete mode 100644 tests/ui/assigning_clones.rs delete mode 100644 tests/ui/assigning_clones.stderr delete mode 100644 tests/ui/async_yields_async.fixed delete mode 100644 tests/ui/async_yields_async.rs delete mode 100644 tests/ui/async_yields_async.stderr delete mode 100644 tests/ui/attrs.rs delete mode 100644 tests/ui/attrs.stderr delete mode 100644 tests/ui/author.rs delete mode 100644 tests/ui/author.stdout delete mode 100644 tests/ui/author/blocks.rs delete mode 100644 tests/ui/author/blocks.stdout delete mode 100644 tests/ui/author/call.rs delete mode 100644 tests/ui/author/call.stdout delete mode 100644 tests/ui/author/if.rs delete mode 100644 tests/ui/author/if.stdout delete mode 100644 tests/ui/author/issue_3849.rs delete mode 100644 tests/ui/author/issue_3849.stdout delete mode 100644 tests/ui/author/loop.rs delete mode 100644 tests/ui/author/loop.stdout delete mode 100644 tests/ui/author/macro_in_closure.rs delete mode 100644 tests/ui/author/macro_in_closure.stdout delete mode 100644 tests/ui/author/macro_in_loop.rs delete mode 100644 tests/ui/author/macro_in_loop.stdout delete mode 100644 tests/ui/author/matches.rs delete mode 100644 tests/ui/author/matches.stdout delete mode 100644 tests/ui/author/repeat.rs delete mode 100644 tests/ui/author/repeat.stdout delete mode 100644 tests/ui/author/struct.rs delete mode 100644 tests/ui/author/struct.stdout delete mode 100644 tests/ui/auxiliary/extern_fake_libc.rs delete mode 100644 tests/ui/auxiliary/macro_rules.rs delete mode 100644 tests/ui/auxiliary/macro_use_helper.rs delete mode 100644 tests/ui/auxiliary/non-exhaustive-enum.rs delete mode 100644 tests/ui/auxiliary/option_helpers.rs delete mode 100644 tests/ui/auxiliary/proc_macro_attr.rs delete mode 100644 tests/ui/auxiliary/proc_macro_derive.rs delete mode 100644 tests/ui/auxiliary/proc_macro_suspicious_else_formatting.rs delete mode 100644 tests/ui/auxiliary/proc_macro_unsafe.rs delete mode 100644 tests/ui/auxiliary/proc_macros.rs delete mode 100644 tests/ui/auxiliary/test_macro.rs delete mode 100644 tests/ui/auxiliary/use_self_macro.rs delete mode 100644 tests/ui/auxiliary/wildcard_imports_helper.rs delete mode 100644 tests/ui/await_holding_lock.rs delete mode 100644 tests/ui/await_holding_lock.stderr delete mode 100644 tests/ui/await_holding_refcell_ref.rs delete mode 100644 tests/ui/await_holding_refcell_ref.stderr delete mode 100644 tests/ui/bind_instead_of_map.fixed delete mode 100644 tests/ui/bind_instead_of_map.rs delete mode 100644 tests/ui/bind_instead_of_map.stderr delete mode 100644 tests/ui/bind_instead_of_map_multipart.fixed delete mode 100644 tests/ui/bind_instead_of_map_multipart.rs delete mode 100644 tests/ui/bind_instead_of_map_multipart.stderr delete mode 100644 tests/ui/bit_masks.rs delete mode 100644 tests/ui/bit_masks.stderr delete mode 100644 tests/ui/blanket_clippy_restriction_lints.rs delete mode 100644 tests/ui/blanket_clippy_restriction_lints.stderr delete mode 100644 tests/ui/blocks_in_conditions.fixed delete mode 100644 tests/ui/blocks_in_conditions.rs delete mode 100644 tests/ui/blocks_in_conditions.stderr delete mode 100644 tests/ui/blocks_in_conditions_closure.rs delete mode 100644 tests/ui/blocks_in_conditions_closure.stderr delete mode 100644 tests/ui/bool_assert_comparison.fixed delete mode 100644 tests/ui/bool_assert_comparison.rs delete mode 100644 tests/ui/bool_assert_comparison.stderr delete mode 100644 tests/ui/bool_comparison.fixed delete mode 100644 tests/ui/bool_comparison.rs delete mode 100644 tests/ui/bool_comparison.stderr delete mode 100644 tests/ui/bool_to_int_with_if.fixed delete mode 100644 tests/ui/bool_to_int_with_if.rs delete mode 100644 tests/ui/bool_to_int_with_if.stderr delete mode 100644 tests/ui/borrow_as_ptr.fixed delete mode 100644 tests/ui/borrow_as_ptr.rs delete mode 100644 tests/ui/borrow_as_ptr.stderr delete mode 100644 tests/ui/borrow_as_ptr_no_std.fixed delete mode 100644 tests/ui/borrow_as_ptr_no_std.rs delete mode 100644 tests/ui/borrow_as_ptr_no_std.stderr delete mode 100644 tests/ui/borrow_box.rs delete mode 100644 tests/ui/borrow_box.stderr delete mode 100644 tests/ui/borrow_deref_ref.fixed delete mode 100644 tests/ui/borrow_deref_ref.rs delete mode 100644 tests/ui/borrow_deref_ref.stderr delete mode 100644 tests/ui/borrow_deref_ref_unfixable.rs delete mode 100644 tests/ui/borrow_deref_ref_unfixable.stderr delete mode 100644 tests/ui/borrow_interior_mutable_const/auxiliary/helper.rs delete mode 100644 tests/ui/borrow_interior_mutable_const/enums.rs delete mode 100644 tests/ui/borrow_interior_mutable_const/enums.stderr delete mode 100644 tests/ui/borrow_interior_mutable_const/others.rs delete mode 100644 tests/ui/borrow_interior_mutable_const/others.stderr delete mode 100644 tests/ui/borrow_interior_mutable_const/traits.rs delete mode 100644 tests/ui/borrow_interior_mutable_const/traits.stderr delete mode 100644 tests/ui/box_collection.rs delete mode 100644 tests/ui/box_collection.stderr delete mode 100644 tests/ui/box_default.fixed delete mode 100644 tests/ui/box_default.rs delete mode 100644 tests/ui/box_default.stderr delete mode 100644 tests/ui/box_default_no_std.rs delete mode 100644 tests/ui/boxed_local.rs delete mode 100644 tests/ui/boxed_local.stderr delete mode 100644 tests/ui/branches_sharing_code/false_positives.rs delete mode 100644 tests/ui/branches_sharing_code/shared_at_bottom.rs delete mode 100644 tests/ui/branches_sharing_code/shared_at_bottom.stderr delete mode 100644 tests/ui/branches_sharing_code/shared_at_top.rs delete mode 100644 tests/ui/branches_sharing_code/shared_at_top.stderr delete mode 100644 tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs delete mode 100644 tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr delete mode 100644 tests/ui/branches_sharing_code/valid_if_blocks.rs delete mode 100644 tests/ui/branches_sharing_code/valid_if_blocks.stderr delete mode 100644 tests/ui/builtin_type_shadow.rs delete mode 100644 tests/ui/builtin_type_shadow.stderr delete mode 100644 tests/ui/bytecount.rs delete mode 100644 tests/ui/bytecount.stderr delete mode 100644 tests/ui/bytes_count_to_len.fixed delete mode 100644 tests/ui/bytes_count_to_len.rs delete mode 100644 tests/ui/bytes_count_to_len.stderr delete mode 100644 tests/ui/bytes_nth.fixed delete mode 100644 tests/ui/bytes_nth.rs delete mode 100644 tests/ui/bytes_nth.stderr delete mode 100644 tests/ui/case_sensitive_file_extension_comparisons.fixed delete mode 100644 tests/ui/case_sensitive_file_extension_comparisons.rs delete mode 100644 tests/ui/case_sensitive_file_extension_comparisons.stderr delete mode 100644 tests/ui/cast.rs delete mode 100644 tests/ui/cast.stderr delete mode 100644 tests/ui/cast_abs_to_unsigned.fixed delete mode 100644 tests/ui/cast_abs_to_unsigned.rs delete mode 100644 tests/ui/cast_abs_to_unsigned.stderr delete mode 100644 tests/ui/cast_alignment.rs delete mode 100644 tests/ui/cast_alignment.stderr delete mode 100644 tests/ui/cast_enum_constructor.rs delete mode 100644 tests/ui/cast_enum_constructor.stderr delete mode 100644 tests/ui/cast_lossless_bool.fixed delete mode 100644 tests/ui/cast_lossless_bool.rs delete mode 100644 tests/ui/cast_lossless_bool.stderr delete mode 100644 tests/ui/cast_lossless_float.fixed delete mode 100644 tests/ui/cast_lossless_float.rs delete mode 100644 tests/ui/cast_lossless_float.stderr delete mode 100644 tests/ui/cast_lossless_integer.fixed delete mode 100644 tests/ui/cast_lossless_integer.rs delete mode 100644 tests/ui/cast_lossless_integer.stderr delete mode 100644 tests/ui/cast_nan_to_int.rs delete mode 100644 tests/ui/cast_nan_to_int.stderr delete mode 100644 tests/ui/cast_raw_slice_pointer_cast.fixed delete mode 100644 tests/ui/cast_raw_slice_pointer_cast.rs delete mode 100644 tests/ui/cast_raw_slice_pointer_cast.stderr delete mode 100644 tests/ui/cast_size.32bit.stderr delete mode 100644 tests/ui/cast_size.64bit.stderr delete mode 100644 tests/ui/cast_size.rs delete mode 100644 tests/ui/cast_slice_different_sizes.rs delete mode 100644 tests/ui/cast_slice_different_sizes.stderr delete mode 100644 tests/ui/cfg_attr_cargo_clippy.fixed delete mode 100644 tests/ui/cfg_attr_cargo_clippy.rs delete mode 100644 tests/ui/cfg_attr_cargo_clippy.stderr delete mode 100644 tests/ui/cfg_attr_rustfmt.fixed delete mode 100644 tests/ui/cfg_attr_rustfmt.rs delete mode 100644 tests/ui/cfg_attr_rustfmt.stderr delete mode 100644 tests/ui/cfg_features.fixed delete mode 100644 tests/ui/cfg_features.rs delete mode 100644 tests/ui/cfg_features.stderr delete mode 100644 tests/ui/char_lit_as_u8.rs delete mode 100644 tests/ui/char_lit_as_u8.stderr delete mode 100644 tests/ui/char_lit_as_u8_suggestions.fixed delete mode 100644 tests/ui/char_lit_as_u8_suggestions.rs delete mode 100644 tests/ui/char_lit_as_u8_suggestions.stderr delete mode 100644 tests/ui/checked_conversions.fixed delete mode 100644 tests/ui/checked_conversions.rs delete mode 100644 tests/ui/checked_conversions.stderr delete mode 100644 tests/ui/checked_unwrap/complex_conditionals.rs delete mode 100644 tests/ui/checked_unwrap/complex_conditionals.stderr delete mode 100644 tests/ui/checked_unwrap/complex_conditionals_nested.rs delete mode 100644 tests/ui/checked_unwrap/complex_conditionals_nested.stderr delete mode 100644 tests/ui/checked_unwrap/simple_conditionals.rs delete mode 100644 tests/ui/checked_unwrap/simple_conditionals.stderr delete mode 100644 tests/ui/clear_with_drain.fixed delete mode 100644 tests/ui/clear_with_drain.rs delete mode 100644 tests/ui/clear_with_drain.stderr delete mode 100644 tests/ui/clone_on_copy.fixed delete mode 100644 tests/ui/clone_on_copy.rs delete mode 100644 tests/ui/clone_on_copy.stderr delete mode 100644 tests/ui/clone_on_copy_impl.rs delete mode 100644 tests/ui/cloned_instead_of_copied.fixed delete mode 100644 tests/ui/cloned_instead_of_copied.rs delete mode 100644 tests/ui/cloned_instead_of_copied.stderr delete mode 100644 tests/ui/cmp_null.rs delete mode 100644 tests/ui/cmp_null.stderr delete mode 100644 tests/ui/cmp_owned/asymmetric_partial_eq.fixed delete mode 100644 tests/ui/cmp_owned/asymmetric_partial_eq.rs delete mode 100644 tests/ui/cmp_owned/asymmetric_partial_eq.stderr delete mode 100644 tests/ui/cmp_owned/comparison_flip.fixed delete mode 100644 tests/ui/cmp_owned/comparison_flip.rs delete mode 100644 tests/ui/cmp_owned/comparison_flip.stderr delete mode 100644 tests/ui/cmp_owned/with_suggestion.fixed delete mode 100644 tests/ui/cmp_owned/with_suggestion.rs delete mode 100644 tests/ui/cmp_owned/with_suggestion.stderr delete mode 100644 tests/ui/cmp_owned/without_suggestion.rs delete mode 100644 tests/ui/cmp_owned/without_suggestion.stderr delete mode 100644 tests/ui/cognitive_complexity.rs delete mode 100644 tests/ui/cognitive_complexity.stderr delete mode 100644 tests/ui/cognitive_complexity_attr_used.rs delete mode 100644 tests/ui/cognitive_complexity_attr_used.stderr delete mode 100644 tests/ui/collapsible_else_if.fixed delete mode 100644 tests/ui/collapsible_else_if.rs delete mode 100644 tests/ui/collapsible_else_if.stderr delete mode 100644 tests/ui/collapsible_if.fixed delete mode 100644 tests/ui/collapsible_if.rs delete mode 100644 tests/ui/collapsible_if.stderr delete mode 100644 tests/ui/collapsible_match.rs delete mode 100644 tests/ui/collapsible_match.stderr delete mode 100644 tests/ui/collapsible_match2.rs delete mode 100644 tests/ui/collapsible_match2.stderr delete mode 100644 tests/ui/collapsible_str_replace.fixed delete mode 100644 tests/ui/collapsible_str_replace.rs delete mode 100644 tests/ui/collapsible_str_replace.stderr delete mode 100644 tests/ui/collection_is_never_read.rs delete mode 100644 tests/ui/collection_is_never_read.stderr delete mode 100644 tests/ui/comparison_chain.rs delete mode 100644 tests/ui/comparison_chain.stderr delete mode 100644 tests/ui/comparison_to_empty.fixed delete mode 100644 tests/ui/comparison_to_empty.rs delete mode 100644 tests/ui/comparison_to_empty.stderr delete mode 100644 tests/ui/const_comparisons.rs delete mode 100644 tests/ui/const_comparisons.stderr delete mode 100644 tests/ui/const_is_empty.rs delete mode 100644 tests/ui/const_is_empty.stderr delete mode 100644 tests/ui/copy_iterator.rs delete mode 100644 tests/ui/copy_iterator.stderr delete mode 100644 tests/ui/crashes/associated-constant-ice.rs delete mode 100644 tests/ui/crashes/auxiliary/ice-4727-aux.rs delete mode 100644 tests/ui/crashes/auxiliary/ice-7272-aux.rs delete mode 100644 tests/ui/crashes/auxiliary/ice-7868-aux.rs delete mode 100644 tests/ui/crashes/auxiliary/ice-7934-aux.rs delete mode 100644 tests/ui/crashes/auxiliary/ice-8681-aux.rs delete mode 100644 tests/ui/crashes/auxiliary/proc_macro_crash.rs delete mode 100644 tests/ui/crashes/auxiliary/use_self_macro.rs delete mode 100644 tests/ui/crashes/cc_seme.rs delete mode 100644 tests/ui/crashes/enum-glob-import-crate.rs delete mode 100644 tests/ui/crashes/ice-10148.rs delete mode 100644 tests/ui/crashes/ice-10148.stderr delete mode 100644 tests/ui/crashes/ice-10645.rs delete mode 100644 tests/ui/crashes/ice-10645.stderr delete mode 100644 tests/ui/crashes/ice-10912.rs delete mode 100644 tests/ui/crashes/ice-10912.stderr delete mode 100644 tests/ui/crashes/ice-11065.rs delete mode 100644 tests/ui/crashes/ice-11230.rs delete mode 100644 tests/ui/crashes/ice-11337.rs delete mode 100644 tests/ui/crashes/ice-11422.fixed delete mode 100644 tests/ui/crashes/ice-11422.rs delete mode 100644 tests/ui/crashes/ice-11422.stderr delete mode 100644 tests/ui/crashes/ice-11755.rs delete mode 100644 tests/ui/crashes/ice-11803.rs delete mode 100644 tests/ui/crashes/ice-11803.stderr delete mode 100644 tests/ui/crashes/ice-11939.rs delete mode 100644 tests/ui/crashes/ice-12253.rs delete mode 100644 tests/ui/crashes/ice-12491.fixed delete mode 100644 tests/ui/crashes/ice-12491.rs delete mode 100644 tests/ui/crashes/ice-12491.stderr delete mode 100644 tests/ui/crashes/ice-12585.rs delete mode 100644 tests/ui/crashes/ice-12616.fixed delete mode 100644 tests/ui/crashes/ice-12616.rs delete mode 100644 tests/ui/crashes/ice-12616.stderr delete mode 100644 tests/ui/crashes/ice-1588.rs delete mode 100644 tests/ui/crashes/ice-1782.rs delete mode 100644 tests/ui/crashes/ice-1969.rs delete mode 100644 tests/ui/crashes/ice-2499.rs delete mode 100644 tests/ui/crashes/ice-2594.rs delete mode 100644 tests/ui/crashes/ice-2727.rs delete mode 100644 tests/ui/crashes/ice-2760.rs delete mode 100644 tests/ui/crashes/ice-2774.fixed delete mode 100644 tests/ui/crashes/ice-2774.rs delete mode 100644 tests/ui/crashes/ice-2774.stderr delete mode 100644 tests/ui/crashes/ice-2862.rs delete mode 100644 tests/ui/crashes/ice-2865.rs delete mode 100644 tests/ui/crashes/ice-3151.rs delete mode 100644 tests/ui/crashes/ice-3462.rs delete mode 100644 tests/ui/crashes/ice-360.rs delete mode 100644 tests/ui/crashes/ice-360.stderr delete mode 100644 tests/ui/crashes/ice-3717.fixed delete mode 100644 tests/ui/crashes/ice-3717.rs delete mode 100644 tests/ui/crashes/ice-3717.stderr delete mode 100644 tests/ui/crashes/ice-3741.rs delete mode 100644 tests/ui/crashes/ice-3747.rs delete mode 100644 tests/ui/crashes/ice-3891.rs delete mode 100644 tests/ui/crashes/ice-3891.stderr delete mode 100644 tests/ui/crashes/ice-3969.rs delete mode 100644 tests/ui/crashes/ice-3969.stderr delete mode 100644 tests/ui/crashes/ice-4121.rs delete mode 100644 tests/ui/crashes/ice-4545.rs delete mode 100644 tests/ui/crashes/ice-4579.rs delete mode 100644 tests/ui/crashes/ice-4671.rs delete mode 100644 tests/ui/crashes/ice-4727.rs delete mode 100644 tests/ui/crashes/ice-4760.rs delete mode 100644 tests/ui/crashes/ice-4775.rs delete mode 100644 tests/ui/crashes/ice-4968.rs delete mode 100644 tests/ui/crashes/ice-5207.rs delete mode 100644 tests/ui/crashes/ice-5223.rs delete mode 100644 tests/ui/crashes/ice-5238.rs delete mode 100644 tests/ui/crashes/ice-5389.rs delete mode 100644 tests/ui/crashes/ice-5497.rs delete mode 100644 tests/ui/crashes/ice-5497.stderr delete mode 100644 tests/ui/crashes/ice-5579.rs delete mode 100644 tests/ui/crashes/ice-5835.fixed delete mode 100644 tests/ui/crashes/ice-5835.rs delete mode 100644 tests/ui/crashes/ice-5835.stderr delete mode 100644 tests/ui/crashes/ice-5872.fixed delete mode 100644 tests/ui/crashes/ice-5872.rs delete mode 100644 tests/ui/crashes/ice-5872.stderr delete mode 100644 tests/ui/crashes/ice-5944.rs delete mode 100644 tests/ui/crashes/ice-6139.rs delete mode 100644 tests/ui/crashes/ice-6153.rs delete mode 100644 tests/ui/crashes/ice-6179.rs delete mode 100644 tests/ui/crashes/ice-6250.rs delete mode 100644 tests/ui/crashes/ice-6250.stderr delete mode 100644 tests/ui/crashes/ice-6251.rs delete mode 100644 tests/ui/crashes/ice-6251.stderr delete mode 100644 tests/ui/crashes/ice-6252.rs delete mode 100644 tests/ui/crashes/ice-6252.stderr delete mode 100644 tests/ui/crashes/ice-6254.rs delete mode 100644 tests/ui/crashes/ice-6255.rs delete mode 100644 tests/ui/crashes/ice-6255.stderr delete mode 100644 tests/ui/crashes/ice-6256.rs delete mode 100644 tests/ui/crashes/ice-6256.stderr delete mode 100644 tests/ui/crashes/ice-6332.rs delete mode 100644 tests/ui/crashes/ice-6539.rs delete mode 100644 tests/ui/crashes/ice-6792.rs delete mode 100644 tests/ui/crashes/ice-6793.rs delete mode 100644 tests/ui/crashes/ice-6840.rs delete mode 100644 tests/ui/crashes/ice-700.rs delete mode 100644 tests/ui/crashes/ice-7012.rs delete mode 100644 tests/ui/crashes/ice-7126.rs delete mode 100644 tests/ui/crashes/ice-7169.fixed delete mode 100644 tests/ui/crashes/ice-7169.rs delete mode 100644 tests/ui/crashes/ice-7169.stderr delete mode 100644 tests/ui/crashes/ice-7231.rs delete mode 100644 tests/ui/crashes/ice-7272.rs delete mode 100644 tests/ui/crashes/ice-7340.rs delete mode 100644 tests/ui/crashes/ice-7410.rs delete mode 100644 tests/ui/crashes/ice-7423.rs delete mode 100644 tests/ui/crashes/ice-7868.rs delete mode 100644 tests/ui/crashes/ice-7868.stderr delete mode 100644 tests/ui/crashes/ice-7869.rs delete mode 100644 tests/ui/crashes/ice-7869.stderr delete mode 100644 tests/ui/crashes/ice-7934.rs delete mode 100644 tests/ui/crashes/ice-8250.fixed delete mode 100644 tests/ui/crashes/ice-8250.rs delete mode 100644 tests/ui/crashes/ice-8250.stderr delete mode 100644 tests/ui/crashes/ice-8386.rs delete mode 100644 tests/ui/crashes/ice-8681.rs delete mode 100644 tests/ui/crashes/ice-8821.rs delete mode 100644 tests/ui/crashes/ice-8850.fixed delete mode 100644 tests/ui/crashes/ice-8850.rs delete mode 100644 tests/ui/crashes/ice-8850.stderr delete mode 100644 tests/ui/crashes/ice-9041.rs delete mode 100644 tests/ui/crashes/ice-9041.stderr delete mode 100644 tests/ui/crashes/ice-9238.rs delete mode 100644 tests/ui/crashes/ice-9242.rs delete mode 100644 tests/ui/crashes/ice-9405.rs delete mode 100644 tests/ui/crashes/ice-9405.stderr delete mode 100644 tests/ui/crashes/ice-9414.rs delete mode 100644 tests/ui/crashes/ice-9445.rs delete mode 100644 tests/ui/crashes/ice-9445.stderr delete mode 100644 tests/ui/crashes/ice-9459.rs delete mode 100644 tests/ui/crashes/ice-9463.rs delete mode 100644 tests/ui/crashes/ice-9463.stderr delete mode 100644 tests/ui/crashes/ice-9625.rs delete mode 100644 tests/ui/crashes/ice-96721.fixed delete mode 100644 tests/ui/crashes/ice-96721.rs delete mode 100644 tests/ui/crashes/ice-96721.stderr delete mode 100644 tests/ui/crashes/ice-9746.rs delete mode 100644 tests/ui/crashes/ice-rust-107877.rs delete mode 100644 tests/ui/crashes/ice_exact_size.rs delete mode 100644 tests/ui/crashes/if_same_then_else.rs delete mode 100644 tests/ui/crashes/implements-trait.rs delete mode 100644 tests/ui/crashes/inherent_impl.rs delete mode 100644 tests/ui/crashes/issue-825.rs delete mode 100644 tests/ui/crashes/issues_loop_mut_cond.rs delete mode 100644 tests/ui/crashes/match_same_arms_const.rs delete mode 100644 tests/ui/crashes/mut_mut_macro.rs delete mode 100644 tests/ui/crashes/needless_borrow_fp.rs delete mode 100644 tests/ui/crashes/needless_lifetimes_impl_trait.fixed delete mode 100644 tests/ui/crashes/needless_lifetimes_impl_trait.rs delete mode 100644 tests/ui/crashes/needless_lifetimes_impl_trait.stderr delete mode 100644 tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed delete mode 100644 tests/ui/crashes/needless_pass_by_value-w-late-bound.rs delete mode 100644 tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr delete mode 100644 tests/ui/crashes/regressions.rs delete mode 100644 tests/ui/crashes/returns.rs delete mode 100644 tests/ui/crashes/shadow.rs delete mode 100644 tests/ui/crashes/single-match-else.rs delete mode 100644 tests/ui/crashes/third-party/clippy.toml delete mode 100644 tests/ui/crashes/third-party/conf_allowlisted.rs delete mode 100644 tests/ui/crashes/trivial_bounds.rs delete mode 100644 tests/ui/crashes/unreachable-array-or-slice.rs delete mode 100644 tests/ui/crashes/unreachable-array-or-slice.stderr delete mode 100644 tests/ui/crashes/used_underscore_binding_macro.rs delete mode 100644 tests/ui/crate_in_macro_def.fixed delete mode 100644 tests/ui/crate_in_macro_def.rs delete mode 100644 tests/ui/crate_in_macro_def.stderr delete mode 100644 tests/ui/crate_level_checks/entrypoint_recursion.rs delete mode 100644 tests/ui/crate_level_checks/no_std_main_recursion.rs delete mode 100644 tests/ui/crate_level_checks/no_std_swap.fixed delete mode 100644 tests/ui/crate_level_checks/no_std_swap.rs delete mode 100644 tests/ui/crate_level_checks/no_std_swap.stderr delete mode 100644 tests/ui/crate_level_checks/std_main_recursion.rs delete mode 100644 tests/ui/crate_level_checks/std_main_recursion.stderr delete mode 100644 tests/ui/create_dir.fixed delete mode 100644 tests/ui/create_dir.rs delete mode 100644 tests/ui/create_dir.stderr delete mode 100644 tests/ui/dbg_macro/auxiliary/submodule.rs delete mode 100644 tests/ui/dbg_macro/dbg_macro.fixed delete mode 100644 tests/ui/dbg_macro/dbg_macro.rs delete mode 100644 tests/ui/dbg_macro/dbg_macro.stderr delete mode 100644 tests/ui/dbg_macro/dbg_macro_unfixable.rs delete mode 100644 tests/ui/dbg_macro/dbg_macro_unfixable.stderr delete mode 100644 tests/ui/debug_assert_with_mut_call.rs delete mode 100644 tests/ui/debug_assert_with_mut_call.stderr delete mode 100644 tests/ui/decimal_literal_representation.fixed delete mode 100644 tests/ui/decimal_literal_representation.rs delete mode 100644 tests/ui/decimal_literal_representation.stderr delete mode 100644 tests/ui/declare_interior_mutable_const/enums.rs delete mode 100644 tests/ui/declare_interior_mutable_const/enums.stderr delete mode 100644 tests/ui/declare_interior_mutable_const/others.rs delete mode 100644 tests/ui/declare_interior_mutable_const/others.stderr delete mode 100644 tests/ui/declare_interior_mutable_const/traits.rs delete mode 100644 tests/ui/declare_interior_mutable_const/traits.stderr delete mode 100644 tests/ui/def_id_nocore.rs delete mode 100644 tests/ui/def_id_nocore.stderr delete mode 100644 tests/ui/default_constructed_unit_structs.fixed delete mode 100644 tests/ui/default_constructed_unit_structs.rs delete mode 100644 tests/ui/default_constructed_unit_structs.stderr delete mode 100644 tests/ui/default_instead_of_iter_empty.fixed delete mode 100644 tests/ui/default_instead_of_iter_empty.rs delete mode 100644 tests/ui/default_instead_of_iter_empty.stderr delete mode 100644 tests/ui/default_instead_of_iter_empty_no_std.fixed delete mode 100644 tests/ui/default_instead_of_iter_empty_no_std.rs delete mode 100644 tests/ui/default_instead_of_iter_empty_no_std.stderr delete mode 100644 tests/ui/default_numeric_fallback_f64.fixed delete mode 100644 tests/ui/default_numeric_fallback_f64.rs delete mode 100644 tests/ui/default_numeric_fallback_f64.stderr delete mode 100644 tests/ui/default_numeric_fallback_i32.fixed delete mode 100644 tests/ui/default_numeric_fallback_i32.rs delete mode 100644 tests/ui/default_numeric_fallback_i32.stderr delete mode 100644 tests/ui/default_trait_access.fixed delete mode 100644 tests/ui/default_trait_access.rs delete mode 100644 tests/ui/default_trait_access.stderr delete mode 100644 tests/ui/default_union_representation.rs delete mode 100644 tests/ui/default_union_representation.stderr delete mode 100644 tests/ui/deprecated.rs delete mode 100644 tests/ui/deprecated.stderr delete mode 100644 tests/ui/deprecated_old.rs delete mode 100644 tests/ui/deprecated_old.stderr delete mode 100644 tests/ui/deref_addrof.fixed delete mode 100644 tests/ui/deref_addrof.rs delete mode 100644 tests/ui/deref_addrof.stderr delete mode 100644 tests/ui/deref_addrof_double_trigger.rs delete mode 100644 tests/ui/deref_addrof_double_trigger.stderr delete mode 100644 tests/ui/deref_addrof_macro.rs delete mode 100644 tests/ui/deref_by_slicing.fixed delete mode 100644 tests/ui/deref_by_slicing.rs delete mode 100644 tests/ui/deref_by_slicing.stderr delete mode 100644 tests/ui/derivable_impls.fixed delete mode 100644 tests/ui/derivable_impls.rs delete mode 100644 tests/ui/derivable_impls.stderr delete mode 100644 tests/ui/derive.rs delete mode 100644 tests/ui/derive.stderr delete mode 100644 tests/ui/derive_ord_xor_partial_ord.rs delete mode 100644 tests/ui/derive_ord_xor_partial_ord.stderr delete mode 100644 tests/ui/derive_partial_eq_without_eq.fixed delete mode 100644 tests/ui/derive_partial_eq_without_eq.rs delete mode 100644 tests/ui/derive_partial_eq_without_eq.stderr delete mode 100644 tests/ui/derived_hash_with_manual_eq.rs delete mode 100644 tests/ui/derived_hash_with_manual_eq.stderr delete mode 100644 tests/ui/disallowed_names.rs delete mode 100644 tests/ui/disallowed_names.stderr delete mode 100644 tests/ui/disallowed_script_idents.rs delete mode 100644 tests/ui/disallowed_script_idents.stderr delete mode 100644 tests/ui/diverging_sub_expression.rs delete mode 100644 tests/ui/diverging_sub_expression.stderr delete mode 100644 tests/ui/doc/doc-fixable.fixed delete mode 100644 tests/ui/doc/doc-fixable.rs delete mode 100644 tests/ui/doc/doc-fixable.stderr delete mode 100644 tests/ui/doc/doc_lazy_blockquote.fixed delete mode 100644 tests/ui/doc/doc_lazy_blockquote.rs delete mode 100644 tests/ui/doc/doc_lazy_blockquote.stderr delete mode 100644 tests/ui/doc/doc_lazy_list.fixed delete mode 100644 tests/ui/doc/doc_lazy_list.rs delete mode 100644 tests/ui/doc/doc_lazy_list.stderr delete mode 100644 tests/ui/doc/issue_10262.fixed delete mode 100644 tests/ui/doc/issue_10262.rs delete mode 100644 tests/ui/doc/issue_10262.stderr delete mode 100644 tests/ui/doc/issue_1832.rs delete mode 100644 tests/ui/doc/issue_902.rs delete mode 100644 tests/ui/doc/issue_9473.fixed delete mode 100644 tests/ui/doc/issue_9473.rs delete mode 100644 tests/ui/doc/issue_9473.stderr delete mode 100644 tests/ui/doc/needless_doctest_main.rs delete mode 100644 tests/ui/doc/unbalanced_ticks.rs delete mode 100644 tests/ui/doc/unbalanced_ticks.stderr delete mode 100644 tests/ui/doc_errors.rs delete mode 100644 tests/ui/doc_errors.stderr delete mode 100644 tests/ui/doc_link_with_quotes.rs delete mode 100644 tests/ui/doc_link_with_quotes.stderr delete mode 100644 tests/ui/doc_unsafe.rs delete mode 100644 tests/ui/doc_unsafe.stderr delete mode 100644 tests/ui/double_comparison.fixed delete mode 100644 tests/ui/double_comparison.rs delete mode 100644 tests/ui/double_comparison.stderr delete mode 100644 tests/ui/double_must_use.rs delete mode 100644 tests/ui/double_must_use.stderr delete mode 100644 tests/ui/double_neg.rs delete mode 100644 tests/ui/double_neg.stderr delete mode 100644 tests/ui/double_parens.rs delete mode 100644 tests/ui/double_parens.stderr delete mode 100644 tests/ui/drain_collect.fixed delete mode 100644 tests/ui/drain_collect.rs delete mode 100644 tests/ui/drain_collect.stderr delete mode 100644 tests/ui/drop_non_drop.rs delete mode 100644 tests/ui/drop_non_drop.stderr delete mode 100644 tests/ui/duplicate_underscore_argument.rs delete mode 100644 tests/ui/duplicate_underscore_argument.stderr delete mode 100644 tests/ui/duplicated_attributes.rs delete mode 100644 tests/ui/duplicated_attributes.stderr delete mode 100644 tests/ui/duration_subsec.fixed delete mode 100644 tests/ui/duration_subsec.rs delete mode 100644 tests/ui/duration_subsec.stderr delete mode 100644 tests/ui/eager_transmute.fixed delete mode 100644 tests/ui/eager_transmute.rs delete mode 100644 tests/ui/eager_transmute.stderr delete mode 100644 tests/ui/else_if_without_else.rs delete mode 100644 tests/ui/else_if_without_else.stderr delete mode 100644 tests/ui/empty_docs.rs delete mode 100644 tests/ui/empty_docs.stderr delete mode 100644 tests/ui/empty_drop.fixed delete mode 100644 tests/ui/empty_drop.rs delete mode 100644 tests/ui/empty_drop.stderr delete mode 100644 tests/ui/empty_enum.rs delete mode 100644 tests/ui/empty_enum.stderr delete mode 100644 tests/ui/empty_enum_variants_with_brackets.fixed delete mode 100644 tests/ui/empty_enum_variants_with_brackets.rs delete mode 100644 tests/ui/empty_enum_variants_with_brackets.stderr delete mode 100644 tests/ui/empty_enum_without_never_type.rs delete mode 100644 tests/ui/empty_line_after_doc_comments.rs delete mode 100644 tests/ui/empty_line_after_doc_comments.stderr delete mode 100644 tests/ui/empty_line_after_outer_attribute.rs delete mode 100644 tests/ui/empty_line_after_outer_attribute.stderr delete mode 100644 tests/ui/empty_loop.rs delete mode 100644 tests/ui/empty_loop.stderr delete mode 100644 tests/ui/empty_loop_no_std.rs delete mode 100644 tests/ui/empty_loop_no_std.stderr delete mode 100644 tests/ui/empty_structs_with_brackets.fixed delete mode 100644 tests/ui/empty_structs_with_brackets.rs delete mode 100644 tests/ui/empty_structs_with_brackets.stderr delete mode 100644 tests/ui/endian_bytes.rs delete mode 100644 tests/ui/endian_bytes.stderr delete mode 100644 tests/ui/entry.fixed delete mode 100644 tests/ui/entry.rs delete mode 100644 tests/ui/entry.stderr delete mode 100644 tests/ui/entry_btree.fixed delete mode 100644 tests/ui/entry_btree.rs delete mode 100644 tests/ui/entry_btree.stderr delete mode 100644 tests/ui/entry_with_else.fixed delete mode 100644 tests/ui/entry_with_else.rs delete mode 100644 tests/ui/entry_with_else.stderr delete mode 100644 tests/ui/enum_clike_unportable_variant.rs delete mode 100644 tests/ui/enum_clike_unportable_variant.stderr delete mode 100644 tests/ui/enum_glob_use.fixed delete mode 100644 tests/ui/enum_glob_use.rs delete mode 100644 tests/ui/enum_glob_use.stderr delete mode 100644 tests/ui/enum_variants.rs delete mode 100644 tests/ui/enum_variants.stderr delete mode 100644 tests/ui/eprint_with_newline.fixed delete mode 100644 tests/ui/eprint_with_newline.rs delete mode 100644 tests/ui/eprint_with_newline.stderr delete mode 100644 tests/ui/eq_op.rs delete mode 100644 tests/ui/eq_op.stderr delete mode 100644 tests/ui/eq_op_macros.rs delete mode 100644 tests/ui/eq_op_macros.stderr delete mode 100644 tests/ui/equatable_if_let.fixed delete mode 100644 tests/ui/equatable_if_let.rs delete mode 100644 tests/ui/equatable_if_let.stderr delete mode 100644 tests/ui/erasing_op.rs delete mode 100644 tests/ui/erasing_op.stderr delete mode 100644 tests/ui/err_expect.fixed delete mode 100644 tests/ui/err_expect.rs delete mode 100644 tests/ui/err_expect.stderr delete mode 100644 tests/ui/error_impl_error.rs delete mode 100644 tests/ui/error_impl_error.stderr delete mode 100644 tests/ui/eta.fixed delete mode 100644 tests/ui/eta.rs delete mode 100644 tests/ui/eta.stderr delete mode 100644 tests/ui/excessive_precision.fixed delete mode 100644 tests/ui/excessive_precision.rs delete mode 100644 tests/ui/excessive_precision.stderr delete mode 100644 tests/ui/exhaustive_items.fixed delete mode 100644 tests/ui/exhaustive_items.rs delete mode 100644 tests/ui/exhaustive_items.stderr delete mode 100644 tests/ui/exit1.rs delete mode 100644 tests/ui/exit1.stderr delete mode 100644 tests/ui/exit2.rs delete mode 100644 tests/ui/exit2.stderr delete mode 100644 tests/ui/exit3.rs delete mode 100644 tests/ui/expect.rs delete mode 100644 tests/ui/expect.stderr delete mode 100644 tests/ui/expect_fun_call.fixed delete mode 100644 tests/ui/expect_fun_call.rs delete mode 100644 tests/ui/expect_fun_call.stderr delete mode 100644 tests/ui/expect_tool_lint_rfc_2383.rs delete mode 100644 tests/ui/expect_tool_lint_rfc_2383.stderr delete mode 100644 tests/ui/explicit_auto_deref.fixed delete mode 100644 tests/ui/explicit_auto_deref.rs delete mode 100644 tests/ui/explicit_auto_deref.stderr delete mode 100644 tests/ui/explicit_counter_loop.rs delete mode 100644 tests/ui/explicit_counter_loop.stderr delete mode 100644 tests/ui/explicit_deref_methods.fixed delete mode 100644 tests/ui/explicit_deref_methods.rs delete mode 100644 tests/ui/explicit_deref_methods.stderr delete mode 100644 tests/ui/explicit_into_iter_loop.fixed delete mode 100644 tests/ui/explicit_into_iter_loop.rs delete mode 100644 tests/ui/explicit_into_iter_loop.stderr delete mode 100644 tests/ui/explicit_iter_loop.fixed delete mode 100644 tests/ui/explicit_iter_loop.rs delete mode 100644 tests/ui/explicit_iter_loop.stderr delete mode 100644 tests/ui/explicit_write.fixed delete mode 100644 tests/ui/explicit_write.rs delete mode 100644 tests/ui/explicit_write.stderr delete mode 100644 tests/ui/extend_with_drain.fixed delete mode 100644 tests/ui/extend_with_drain.rs delete mode 100644 tests/ui/extend_with_drain.stderr delete mode 100644 tests/ui/extra_unused_lifetimes.rs delete mode 100644 tests/ui/extra_unused_lifetimes.stderr delete mode 100644 tests/ui/extra_unused_type_parameters.fixed delete mode 100644 tests/ui/extra_unused_type_parameters.rs delete mode 100644 tests/ui/extra_unused_type_parameters.stderr delete mode 100644 tests/ui/extra_unused_type_parameters_unfixable.rs delete mode 100644 tests/ui/extra_unused_type_parameters_unfixable.stderr delete mode 100644 tests/ui/fallible_impl_from.rs delete mode 100644 tests/ui/fallible_impl_from.stderr delete mode 100644 tests/ui/field_reassign_with_default.rs delete mode 100644 tests/ui/field_reassign_with_default.stderr delete mode 100644 tests/ui/filetype_is_file.rs delete mode 100644 tests/ui/filetype_is_file.stderr delete mode 100644 tests/ui/filter_map_bool_then.fixed delete mode 100644 tests/ui/filter_map_bool_then.rs delete mode 100644 tests/ui/filter_map_bool_then.stderr delete mode 100644 tests/ui/filter_map_identity.fixed delete mode 100644 tests/ui/filter_map_identity.rs delete mode 100644 tests/ui/filter_map_identity.stderr delete mode 100644 tests/ui/filter_map_next.rs delete mode 100644 tests/ui/filter_map_next.stderr delete mode 100644 tests/ui/filter_map_next_fixable.fixed delete mode 100644 tests/ui/filter_map_next_fixable.rs delete mode 100644 tests/ui/filter_map_next_fixable.stderr delete mode 100644 tests/ui/find_map.rs delete mode 100644 tests/ui/flat_map_identity.fixed delete mode 100644 tests/ui/flat_map_identity.rs delete mode 100644 tests/ui/flat_map_identity.stderr delete mode 100644 tests/ui/flat_map_option.fixed delete mode 100644 tests/ui/flat_map_option.rs delete mode 100644 tests/ui/flat_map_option.stderr delete mode 100644 tests/ui/float_arithmetic.rs delete mode 100644 tests/ui/float_arithmetic.stderr delete mode 100644 tests/ui/float_cmp.rs delete mode 100644 tests/ui/float_cmp.stderr delete mode 100644 tests/ui/float_cmp_const.rs delete mode 100644 tests/ui/float_cmp_const.stderr delete mode 100644 tests/ui/float_equality_without_abs.rs delete mode 100644 tests/ui/float_equality_without_abs.stderr delete mode 100644 tests/ui/floating_point_abs.fixed delete mode 100644 tests/ui/floating_point_abs.rs delete mode 100644 tests/ui/floating_point_abs.stderr delete mode 100644 tests/ui/floating_point_arithmetic_nostd.rs delete mode 100644 tests/ui/floating_point_exp.fixed delete mode 100644 tests/ui/floating_point_exp.rs delete mode 100644 tests/ui/floating_point_exp.stderr delete mode 100644 tests/ui/floating_point_hypot.fixed delete mode 100644 tests/ui/floating_point_hypot.rs delete mode 100644 tests/ui/floating_point_hypot.stderr delete mode 100644 tests/ui/floating_point_log.fixed delete mode 100644 tests/ui/floating_point_log.rs delete mode 100644 tests/ui/floating_point_log.stderr delete mode 100644 tests/ui/floating_point_logbase.fixed delete mode 100644 tests/ui/floating_point_logbase.rs delete mode 100644 tests/ui/floating_point_logbase.stderr delete mode 100644 tests/ui/floating_point_mul_add.fixed delete mode 100644 tests/ui/floating_point_mul_add.rs delete mode 100644 tests/ui/floating_point_mul_add.stderr delete mode 100644 tests/ui/floating_point_powf.fixed delete mode 100644 tests/ui/floating_point_powf.rs delete mode 100644 tests/ui/floating_point_powf.stderr delete mode 100644 tests/ui/floating_point_powi.fixed delete mode 100644 tests/ui/floating_point_powi.rs delete mode 100644 tests/ui/floating_point_powi.stderr delete mode 100644 tests/ui/floating_point_rad.fixed delete mode 100644 tests/ui/floating_point_rad.rs delete mode 100644 tests/ui/floating_point_rad.stderr delete mode 100644 tests/ui/fn_address_comparisons.rs delete mode 100644 tests/ui/fn_address_comparisons.stderr delete mode 100644 tests/ui/fn_params_excessive_bools.rs delete mode 100644 tests/ui/fn_params_excessive_bools.stderr delete mode 100644 tests/ui/fn_to_numeric_cast.32bit.stderr delete mode 100644 tests/ui/fn_to_numeric_cast.64bit.stderr delete mode 100644 tests/ui/fn_to_numeric_cast.rs delete mode 100644 tests/ui/fn_to_numeric_cast_any.rs delete mode 100644 tests/ui/fn_to_numeric_cast_any.stderr delete mode 100644 tests/ui/for_kv_map.fixed delete mode 100644 tests/ui/for_kv_map.rs delete mode 100644 tests/ui/for_kv_map.stderr delete mode 100644 tests/ui/forget_non_drop.rs delete mode 100644 tests/ui/forget_non_drop.stderr delete mode 100644 tests/ui/format.fixed delete mode 100644 tests/ui/format.rs delete mode 100644 tests/ui/format.stderr delete mode 100644 tests/ui/format_args.fixed delete mode 100644 tests/ui/format_args.rs delete mode 100644 tests/ui/format_args.stderr delete mode 100644 tests/ui/format_args_unfixable.rs delete mode 100644 tests/ui/format_args_unfixable.stderr delete mode 100644 tests/ui/format_collect.rs delete mode 100644 tests/ui/format_collect.stderr delete mode 100644 tests/ui/format_push_string.rs delete mode 100644 tests/ui/format_push_string.stderr delete mode 100644 tests/ui/formatting.rs delete mode 100644 tests/ui/formatting.stderr delete mode 100644 tests/ui/four_forward_slashes.fixed delete mode 100644 tests/ui/four_forward_slashes.rs delete mode 100644 tests/ui/four_forward_slashes.stderr delete mode 100644 tests/ui/four_forward_slashes_first_line.fixed delete mode 100644 tests/ui/four_forward_slashes_first_line.rs delete mode 100644 tests/ui/four_forward_slashes_first_line.stderr delete mode 100644 tests/ui/from_iter_instead_of_collect.fixed delete mode 100644 tests/ui/from_iter_instead_of_collect.rs delete mode 100644 tests/ui/from_iter_instead_of_collect.stderr delete mode 100644 tests/ui/from_over_into.fixed delete mode 100644 tests/ui/from_over_into.rs delete mode 100644 tests/ui/from_over_into.stderr delete mode 100644 tests/ui/from_over_into_unfixable.rs delete mode 100644 tests/ui/from_over_into_unfixable.stderr delete mode 100644 tests/ui/from_raw_with_void_ptr.rs delete mode 100644 tests/ui/from_raw_with_void_ptr.stderr delete mode 100644 tests/ui/from_str_radix_10.fixed delete mode 100644 tests/ui/from_str_radix_10.rs delete mode 100644 tests/ui/from_str_radix_10.stderr delete mode 100644 tests/ui/functions.rs delete mode 100644 tests/ui/functions.stderr delete mode 100644 tests/ui/functions_maxlines.rs delete mode 100644 tests/ui/functions_maxlines.stderr delete mode 100644 tests/ui/future_not_send.rs delete mode 100644 tests/ui/future_not_send.stderr delete mode 100644 tests/ui/get_first.fixed delete mode 100644 tests/ui/get_first.rs delete mode 100644 tests/ui/get_first.stderr delete mode 100644 tests/ui/get_last_with_len.fixed delete mode 100644 tests/ui/get_last_with_len.rs delete mode 100644 tests/ui/get_last_with_len.stderr delete mode 100644 tests/ui/get_unwrap.fixed delete mode 100644 tests/ui/get_unwrap.rs delete mode 100644 tests/ui/get_unwrap.stderr delete mode 100644 tests/ui/identity_op.fixed delete mode 100644 tests/ui/identity_op.rs delete mode 100644 tests/ui/identity_op.stderr delete mode 100644 tests/ui/if_let_mutex.rs delete mode 100644 tests/ui/if_let_mutex.stderr delete mode 100644 tests/ui/if_not_else.rs delete mode 100644 tests/ui/if_not_else.stderr delete mode 100644 tests/ui/if_not_else_bittest.rs delete mode 100644 tests/ui/if_same_then_else.rs delete mode 100644 tests/ui/if_same_then_else.stderr delete mode 100644 tests/ui/if_same_then_else2.rs delete mode 100644 tests/ui/if_same_then_else2.stderr delete mode 100644 tests/ui/if_then_some_else_none.rs delete mode 100644 tests/ui/if_then_some_else_none.stderr delete mode 100644 tests/ui/ifs_same_cond.rs delete mode 100644 tests/ui/ifs_same_cond.stderr delete mode 100644 tests/ui/ignored_unit_patterns.fixed delete mode 100644 tests/ui/ignored_unit_patterns.rs delete mode 100644 tests/ui/ignored_unit_patterns.stderr delete mode 100644 tests/ui/impl.rs delete mode 100644 tests/ui/impl.stderr delete mode 100644 tests/ui/impl_hash_with_borrow_str_and_bytes.rs delete mode 100644 tests/ui/impl_hash_with_borrow_str_and_bytes.stderr delete mode 100644 tests/ui/impl_trait_in_params.rs delete mode 100644 tests/ui/impl_trait_in_params.stderr delete mode 100644 tests/ui/implicit_clone.fixed delete mode 100644 tests/ui/implicit_clone.rs delete mode 100644 tests/ui/implicit_clone.stderr delete mode 100644 tests/ui/implicit_hasher.rs delete mode 100644 tests/ui/implicit_hasher.stderr delete mode 100644 tests/ui/implicit_return.fixed delete mode 100644 tests/ui/implicit_return.rs delete mode 100644 tests/ui/implicit_return.stderr delete mode 100644 tests/ui/implicit_saturating_add.fixed delete mode 100644 tests/ui/implicit_saturating_add.rs delete mode 100644 tests/ui/implicit_saturating_add.stderr delete mode 100644 tests/ui/implicit_saturating_sub.fixed delete mode 100644 tests/ui/implicit_saturating_sub.rs delete mode 100644 tests/ui/implicit_saturating_sub.stderr delete mode 100644 tests/ui/implied_bounds_in_impls.fixed delete mode 100644 tests/ui/implied_bounds_in_impls.rs delete mode 100644 tests/ui/implied_bounds_in_impls.stderr delete mode 100644 tests/ui/incompatible_msrv.rs delete mode 100644 tests/ui/incompatible_msrv.stderr delete mode 100644 tests/ui/inconsistent_digit_grouping.fixed delete mode 100644 tests/ui/inconsistent_digit_grouping.rs delete mode 100644 tests/ui/inconsistent_digit_grouping.stderr delete mode 100644 tests/ui/inconsistent_struct_constructor.fixed delete mode 100644 tests/ui/inconsistent_struct_constructor.rs delete mode 100644 tests/ui/inconsistent_struct_constructor.stderr delete mode 100644 tests/ui/index_refutable_slice/if_let_slice_binding.fixed delete mode 100644 tests/ui/index_refutable_slice/if_let_slice_binding.rs delete mode 100644 tests/ui/index_refutable_slice/if_let_slice_binding.stderr delete mode 100644 tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed delete mode 100644 tests/ui/index_refutable_slice/slice_indexing_in_macro.rs delete mode 100644 tests/ui/index_refutable_slice/slice_indexing_in_macro.stderr delete mode 100644 tests/ui/indexing_slicing_index.rs delete mode 100644 tests/ui/indexing_slicing_index.stderr delete mode 100644 tests/ui/indexing_slicing_slice.rs delete mode 100644 tests/ui/indexing_slicing_slice.stderr delete mode 100644 tests/ui/ineffective_open_options.fixed delete mode 100644 tests/ui/ineffective_open_options.rs delete mode 100644 tests/ui/ineffective_open_options.stderr delete mode 100644 tests/ui/inefficient_to_string.fixed delete mode 100644 tests/ui/inefficient_to_string.rs delete mode 100644 tests/ui/inefficient_to_string.stderr delete mode 100644 tests/ui/infallible_destructuring_match.fixed delete mode 100644 tests/ui/infallible_destructuring_match.rs delete mode 100644 tests/ui/infallible_destructuring_match.stderr delete mode 100644 tests/ui/infinite_iter.rs delete mode 100644 tests/ui/infinite_iter.stderr delete mode 100644 tests/ui/infinite_loop.rs delete mode 100644 tests/ui/infinite_loop.stderr delete mode 100644 tests/ui/infinite_loops.rs delete mode 100644 tests/ui/infinite_loops.stderr delete mode 100644 tests/ui/inherent_to_string.rs delete mode 100644 tests/ui/inherent_to_string.stderr delete mode 100644 tests/ui/inline_fn_without_body.fixed delete mode 100644 tests/ui/inline_fn_without_body.rs delete mode 100644 tests/ui/inline_fn_without_body.stderr delete mode 100644 tests/ui/inspect_for_each.rs delete mode 100644 tests/ui/inspect_for_each.stderr delete mode 100644 tests/ui/int_plus_one.fixed delete mode 100644 tests/ui/int_plus_one.rs delete mode 100644 tests/ui/int_plus_one.stderr delete mode 100644 tests/ui/integer_division.rs delete mode 100644 tests/ui/integer_division.stderr delete mode 100644 tests/ui/integer_division_remainder_used.rs delete mode 100644 tests/ui/integer_division_remainder_used.stderr delete mode 100644 tests/ui/into_iter_on_ref.fixed delete mode 100644 tests/ui/into_iter_on_ref.rs delete mode 100644 tests/ui/into_iter_on_ref.stderr delete mode 100644 tests/ui/into_iter_without_iter.rs delete mode 100644 tests/ui/into_iter_without_iter.stderr delete mode 100644 tests/ui/invalid_null_ptr_usage.fixed delete mode 100644 tests/ui/invalid_null_ptr_usage.rs delete mode 100644 tests/ui/invalid_null_ptr_usage.stderr delete mode 100644 tests/ui/invalid_upcast_comparisons.rs delete mode 100644 tests/ui/invalid_upcast_comparisons.stderr delete mode 100644 tests/ui/is_digit_ascii_radix.fixed delete mode 100644 tests/ui/is_digit_ascii_radix.rs delete mode 100644 tests/ui/is_digit_ascii_radix.stderr delete mode 100644 tests/ui/issue-111399.rs delete mode 100644 tests/ui/issue-3145.rs delete mode 100644 tests/ui/issue-3145.stderr delete mode 100644 tests/ui/issue-7447.rs delete mode 100644 tests/ui/issue-7447.stderr delete mode 100644 tests/ui/issue_2356.fixed delete mode 100644 tests/ui/issue_2356.rs delete mode 100644 tests/ui/issue_2356.stderr delete mode 100644 tests/ui/issue_4266.rs delete mode 100644 tests/ui/issue_4266.stderr delete mode 100644 tests/ui/items_after_statement.rs delete mode 100644 tests/ui/items_after_statement.stderr delete mode 100644 tests/ui/items_after_test_module/after_proc_macros.rs delete mode 100644 tests/ui/items_after_test_module/auxiliary/submodule.rs delete mode 100644 tests/ui/items_after_test_module/auxiliary/tests.rs delete mode 100644 tests/ui/items_after_test_module/imported_module.rs delete mode 100644 tests/ui/items_after_test_module/in_submodule.rs delete mode 100644 tests/ui/items_after_test_module/in_submodule.stderr delete mode 100644 tests/ui/items_after_test_module/multiple_modules.rs delete mode 100644 tests/ui/items_after_test_module/root_module.fixed delete mode 100644 tests/ui/items_after_test_module/root_module.rs delete mode 100644 tests/ui/items_after_test_module/root_module.stderr delete mode 100644 tests/ui/iter_cloned_collect.fixed delete mode 100644 tests/ui/iter_cloned_collect.rs delete mode 100644 tests/ui/iter_cloned_collect.stderr delete mode 100644 tests/ui/iter_count.fixed delete mode 100644 tests/ui/iter_count.rs delete mode 100644 tests/ui/iter_count.stderr delete mode 100644 tests/ui/iter_filter_is_ok.fixed delete mode 100644 tests/ui/iter_filter_is_ok.rs delete mode 100644 tests/ui/iter_filter_is_ok.stderr delete mode 100644 tests/ui/iter_filter_is_some.fixed delete mode 100644 tests/ui/iter_filter_is_some.rs delete mode 100644 tests/ui/iter_filter_is_some.stderr delete mode 100644 tests/ui/iter_kv_map.fixed delete mode 100644 tests/ui/iter_kv_map.rs delete mode 100644 tests/ui/iter_kv_map.stderr delete mode 100644 tests/ui/iter_next_loop.rs delete mode 100644 tests/ui/iter_next_loop.stderr delete mode 100644 tests/ui/iter_next_slice.fixed delete mode 100644 tests/ui/iter_next_slice.rs delete mode 100644 tests/ui/iter_next_slice.stderr delete mode 100644 tests/ui/iter_not_returning_iterator.rs delete mode 100644 tests/ui/iter_not_returning_iterator.stderr delete mode 100644 tests/ui/iter_nth.fixed delete mode 100644 tests/ui/iter_nth.rs delete mode 100644 tests/ui/iter_nth.stderr delete mode 100644 tests/ui/iter_nth_zero.fixed delete mode 100644 tests/ui/iter_nth_zero.rs delete mode 100644 tests/ui/iter_nth_zero.stderr delete mode 100644 tests/ui/iter_on_empty_collections.fixed delete mode 100644 tests/ui/iter_on_empty_collections.rs delete mode 100644 tests/ui/iter_on_empty_collections.stderr delete mode 100644 tests/ui/iter_on_single_items.fixed delete mode 100644 tests/ui/iter_on_single_items.rs delete mode 100644 tests/ui/iter_on_single_items.stderr delete mode 100644 tests/ui/iter_out_of_bounds.rs delete mode 100644 tests/ui/iter_out_of_bounds.stderr delete mode 100644 tests/ui/iter_over_hash_type.rs delete mode 100644 tests/ui/iter_over_hash_type.stderr delete mode 100644 tests/ui/iter_overeager_cloned.fixed delete mode 100644 tests/ui/iter_overeager_cloned.rs delete mode 100644 tests/ui/iter_overeager_cloned.stderr delete mode 100644 tests/ui/iter_skip_next.fixed delete mode 100644 tests/ui/iter_skip_next.rs delete mode 100644 tests/ui/iter_skip_next.stderr delete mode 100644 tests/ui/iter_skip_next_unfixable.rs delete mode 100644 tests/ui/iter_skip_next_unfixable.stderr delete mode 100644 tests/ui/iter_skip_zero.fixed delete mode 100644 tests/ui/iter_skip_zero.rs delete mode 100644 tests/ui/iter_skip_zero.stderr delete mode 100644 tests/ui/iter_with_drain.fixed delete mode 100644 tests/ui/iter_with_drain.rs delete mode 100644 tests/ui/iter_with_drain.stderr delete mode 100644 tests/ui/iter_without_into_iter.rs delete mode 100644 tests/ui/iter_without_into_iter.stderr delete mode 100644 tests/ui/iterator_step_by_zero.rs delete mode 100644 tests/ui/iterator_step_by_zero.stderr delete mode 100644 tests/ui/join_absolute_paths.rs delete mode 100644 tests/ui/join_absolute_paths.stderr delete mode 100644 tests/ui/large_const_arrays.fixed delete mode 100644 tests/ui/large_const_arrays.rs delete mode 100644 tests/ui/large_const_arrays.stderr delete mode 100644 tests/ui/large_digit_groups.fixed delete mode 100644 tests/ui/large_digit_groups.rs delete mode 100644 tests/ui/large_digit_groups.stderr delete mode 100644 tests/ui/large_enum_variant.32bit.stderr delete mode 100644 tests/ui/large_enum_variant.64bit.stderr delete mode 100644 tests/ui/large_enum_variant.rs delete mode 100644 tests/ui/large_futures.fixed delete mode 100644 tests/ui/large_futures.rs delete mode 100644 tests/ui/large_futures.stderr delete mode 100644 tests/ui/large_stack_arrays.rs delete mode 100644 tests/ui/large_stack_arrays.stderr delete mode 100644 tests/ui/large_stack_frames.rs delete mode 100644 tests/ui/large_stack_frames.stderr delete mode 100644 tests/ui/large_types_passed_by_value.rs delete mode 100644 tests/ui/large_types_passed_by_value.stderr delete mode 100644 tests/ui/legacy_numeric_constants.fixed delete mode 100644 tests/ui/legacy_numeric_constants.rs delete mode 100644 tests/ui/legacy_numeric_constants.stderr delete mode 100644 tests/ui/legacy_numeric_constants_unfixable.rs delete mode 100644 tests/ui/legacy_numeric_constants_unfixable.stderr delete mode 100644 tests/ui/len_without_is_empty.rs delete mode 100644 tests/ui/len_without_is_empty.stderr delete mode 100644 tests/ui/len_zero.fixed delete mode 100644 tests/ui/len_zero.rs delete mode 100644 tests/ui/len_zero.stderr delete mode 100644 tests/ui/len_zero_ranges.fixed delete mode 100644 tests/ui/len_zero_ranges.rs delete mode 100644 tests/ui/len_zero_ranges.stderr delete mode 100644 tests/ui/let_and_return.fixed delete mode 100644 tests/ui/let_and_return.rs delete mode 100644 tests/ui/let_and_return.stderr delete mode 100644 tests/ui/let_if_seq.rs delete mode 100644 tests/ui/let_if_seq.stderr delete mode 100644 tests/ui/let_underscore_future.rs delete mode 100644 tests/ui/let_underscore_future.stderr delete mode 100644 tests/ui/let_underscore_lock.rs delete mode 100644 tests/ui/let_underscore_lock.stderr delete mode 100644 tests/ui/let_underscore_must_use.rs delete mode 100644 tests/ui/let_underscore_must_use.stderr delete mode 100644 tests/ui/let_underscore_untyped.rs delete mode 100644 tests/ui/let_underscore_untyped.stderr delete mode 100644 tests/ui/let_unit.fixed delete mode 100644 tests/ui/let_unit.rs delete mode 100644 tests/ui/let_unit.stderr delete mode 100644 tests/ui/let_with_type_underscore.rs delete mode 100644 tests/ui/let_with_type_underscore.stderr delete mode 100644 tests/ui/lines_filter_map_ok.fixed delete mode 100644 tests/ui/lines_filter_map_ok.rs delete mode 100644 tests/ui/lines_filter_map_ok.stderr delete mode 100644 tests/ui/linkedlist.rs delete mode 100644 tests/ui/linkedlist.stderr delete mode 100644 tests/ui/literals.rs delete mode 100644 tests/ui/literals.stderr delete mode 100644 tests/ui/lossy_float_literal.fixed delete mode 100644 tests/ui/lossy_float_literal.rs delete mode 100644 tests/ui/lossy_float_literal.stderr delete mode 100644 tests/ui/macro_use_imports.fixed delete mode 100644 tests/ui/macro_use_imports.rs delete mode 100644 tests/ui/macro_use_imports.stderr delete mode 100644 tests/ui/macro_use_imports_expect.rs delete mode 100644 tests/ui/manual_assert.edition2018.fixed delete mode 100644 tests/ui/manual_assert.edition2018.stderr delete mode 100644 tests/ui/manual_assert.edition2021.fixed delete mode 100644 tests/ui/manual_assert.edition2021.stderr delete mode 100644 tests/ui/manual_assert.rs delete mode 100644 tests/ui/manual_async_fn.fixed delete mode 100644 tests/ui/manual_async_fn.rs delete mode 100644 tests/ui/manual_async_fn.stderr delete mode 100644 tests/ui/manual_bits.fixed delete mode 100644 tests/ui/manual_bits.rs delete mode 100644 tests/ui/manual_bits.stderr delete mode 100644 tests/ui/manual_c_str_literals.fixed delete mode 100644 tests/ui/manual_c_str_literals.rs delete mode 100644 tests/ui/manual_c_str_literals.stderr delete mode 100644 tests/ui/manual_clamp.fixed delete mode 100644 tests/ui/manual_clamp.rs delete mode 100644 tests/ui/manual_clamp.stderr delete mode 100644 tests/ui/manual_filter.fixed delete mode 100644 tests/ui/manual_filter.rs delete mode 100644 tests/ui/manual_filter.stderr delete mode 100644 tests/ui/manual_filter_map.fixed delete mode 100644 tests/ui/manual_filter_map.rs delete mode 100644 tests/ui/manual_filter_map.stderr delete mode 100644 tests/ui/manual_find.rs delete mode 100644 tests/ui/manual_find.stderr delete mode 100644 tests/ui/manual_find_fixable.fixed delete mode 100644 tests/ui/manual_find_fixable.rs delete mode 100644 tests/ui/manual_find_fixable.stderr delete mode 100644 tests/ui/manual_find_map.fixed delete mode 100644 tests/ui/manual_find_map.rs delete mode 100644 tests/ui/manual_find_map.stderr delete mode 100644 tests/ui/manual_flatten.rs delete mode 100644 tests/ui/manual_flatten.stderr delete mode 100644 tests/ui/manual_float_methods.rs delete mode 100644 tests/ui/manual_float_methods.stderr delete mode 100644 tests/ui/manual_hash_one.fixed delete mode 100644 tests/ui/manual_hash_one.rs delete mode 100644 tests/ui/manual_hash_one.stderr delete mode 100644 tests/ui/manual_instant_elapsed.fixed delete mode 100644 tests/ui/manual_instant_elapsed.rs delete mode 100644 tests/ui/manual_instant_elapsed.stderr delete mode 100644 tests/ui/manual_is_ascii_check.fixed delete mode 100644 tests/ui/manual_is_ascii_check.rs delete mode 100644 tests/ui/manual_is_ascii_check.stderr delete mode 100644 tests/ui/manual_is_variant_and.fixed delete mode 100644 tests/ui/manual_is_variant_and.rs delete mode 100644 tests/ui/manual_is_variant_and.stderr delete mode 100644 tests/ui/manual_let_else.rs delete mode 100644 tests/ui/manual_let_else.stderr delete mode 100644 tests/ui/manual_let_else_match.fixed delete mode 100644 tests/ui/manual_let_else_match.rs delete mode 100644 tests/ui/manual_let_else_match.stderr delete mode 100644 tests/ui/manual_let_else_question_mark.fixed delete mode 100644 tests/ui/manual_let_else_question_mark.rs delete mode 100644 tests/ui/manual_let_else_question_mark.stderr delete mode 100644 tests/ui/manual_main_separator_str.fixed delete mode 100644 tests/ui/manual_main_separator_str.rs delete mode 100644 tests/ui/manual_main_separator_str.stderr delete mode 100644 tests/ui/manual_map_option.fixed delete mode 100644 tests/ui/manual_map_option.rs delete mode 100644 tests/ui/manual_map_option.stderr delete mode 100644 tests/ui/manual_map_option_2.fixed delete mode 100644 tests/ui/manual_map_option_2.rs delete mode 100644 tests/ui/manual_map_option_2.stderr delete mode 100644 tests/ui/manual_memcpy/with_loop_counters.rs delete mode 100644 tests/ui/manual_memcpy/with_loop_counters.stderr delete mode 100644 tests/ui/manual_memcpy/without_loop_counters.rs delete mode 100644 tests/ui/manual_memcpy/without_loop_counters.stderr delete mode 100644 tests/ui/manual_next_back.fixed delete mode 100644 tests/ui/manual_next_back.rs delete mode 100644 tests/ui/manual_next_back.stderr delete mode 100644 tests/ui/manual_non_exhaustive_enum.rs delete mode 100644 tests/ui/manual_non_exhaustive_enum.stderr delete mode 100644 tests/ui/manual_non_exhaustive_struct.rs delete mode 100644 tests/ui/manual_non_exhaustive_struct.stderr delete mode 100644 tests/ui/manual_ok_or.fixed delete mode 100644 tests/ui/manual_ok_or.rs delete mode 100644 tests/ui/manual_ok_or.stderr delete mode 100644 tests/ui/manual_range_patterns.fixed delete mode 100644 tests/ui/manual_range_patterns.rs delete mode 100644 tests/ui/manual_range_patterns.stderr delete mode 100644 tests/ui/manual_rem_euclid.fixed delete mode 100644 tests/ui/manual_rem_euclid.rs delete mode 100644 tests/ui/manual_rem_euclid.stderr delete mode 100644 tests/ui/manual_retain.fixed delete mode 100644 tests/ui/manual_retain.rs delete mode 100644 tests/ui/manual_retain.stderr delete mode 100644 tests/ui/manual_saturating_arithmetic.fixed delete mode 100644 tests/ui/manual_saturating_arithmetic.rs delete mode 100644 tests/ui/manual_saturating_arithmetic.stderr delete mode 100644 tests/ui/manual_slice_size_calculation.fixed delete mode 100644 tests/ui/manual_slice_size_calculation.rs delete mode 100644 tests/ui/manual_slice_size_calculation.stderr delete mode 100644 tests/ui/manual_split_once.fixed delete mode 100644 tests/ui/manual_split_once.rs delete mode 100644 tests/ui/manual_split_once.stderr delete mode 100644 tests/ui/manual_str_repeat.fixed delete mode 100644 tests/ui/manual_str_repeat.rs delete mode 100644 tests/ui/manual_str_repeat.stderr delete mode 100644 tests/ui/manual_string_new.fixed delete mode 100644 tests/ui/manual_string_new.rs delete mode 100644 tests/ui/manual_string_new.stderr delete mode 100644 tests/ui/manual_strip.rs delete mode 100644 tests/ui/manual_strip.stderr delete mode 100644 tests/ui/manual_swap_auto_fix.fixed delete mode 100644 tests/ui/manual_swap_auto_fix.rs delete mode 100644 tests/ui/manual_swap_auto_fix.stderr delete mode 100644 tests/ui/manual_try_fold.rs delete mode 100644 tests/ui/manual_try_fold.stderr delete mode 100644 tests/ui/manual_unwrap_or.fixed delete mode 100644 tests/ui/manual_unwrap_or.rs delete mode 100644 tests/ui/manual_unwrap_or.stderr delete mode 100644 tests/ui/manual_unwrap_or_default.fixed delete mode 100644 tests/ui/manual_unwrap_or_default.rs delete mode 100644 tests/ui/manual_unwrap_or_default.stderr delete mode 100644 tests/ui/manual_while_let_some.fixed delete mode 100644 tests/ui/manual_while_let_some.rs delete mode 100644 tests/ui/manual_while_let_some.stderr delete mode 100644 tests/ui/many_single_char_names.rs delete mode 100644 tests/ui/many_single_char_names.stderr delete mode 100644 tests/ui/map_clone.fixed delete mode 100644 tests/ui/map_clone.rs delete mode 100644 tests/ui/map_clone.stderr delete mode 100644 tests/ui/map_collect_result_unit.fixed delete mode 100644 tests/ui/map_collect_result_unit.rs delete mode 100644 tests/ui/map_collect_result_unit.stderr delete mode 100644 tests/ui/map_err.rs delete mode 100644 tests/ui/map_err.stderr delete mode 100644 tests/ui/map_flatten.rs delete mode 100644 tests/ui/map_flatten.stderr delete mode 100644 tests/ui/map_flatten_fixable.fixed delete mode 100644 tests/ui/map_flatten_fixable.rs delete mode 100644 tests/ui/map_flatten_fixable.stderr delete mode 100644 tests/ui/map_identity.fixed delete mode 100644 tests/ui/map_identity.rs delete mode 100644 tests/ui/map_identity.stderr delete mode 100644 tests/ui/map_unit_fn.rs delete mode 100644 tests/ui/map_unwrap_or.rs delete mode 100644 tests/ui/map_unwrap_or.stderr delete mode 100644 tests/ui/map_unwrap_or_fixable.fixed delete mode 100644 tests/ui/map_unwrap_or_fixable.rs delete mode 100644 tests/ui/map_unwrap_or_fixable.stderr delete mode 100644 tests/ui/match_as_ref.fixed delete mode 100644 tests/ui/match_as_ref.rs delete mode 100644 tests/ui/match_as_ref.stderr delete mode 100644 tests/ui/match_bool.rs delete mode 100644 tests/ui/match_bool.stderr delete mode 100644 tests/ui/match_expr_like_matches_macro.fixed delete mode 100644 tests/ui/match_expr_like_matches_macro.rs delete mode 100644 tests/ui/match_expr_like_matches_macro.stderr delete mode 100644 tests/ui/match_on_vec_items.rs delete mode 100644 tests/ui/match_on_vec_items.stderr delete mode 100644 tests/ui/match_overlapping_arm.rs delete mode 100644 tests/ui/match_overlapping_arm.stderr delete mode 100644 tests/ui/match_ref_pats.fixed delete mode 100644 tests/ui/match_ref_pats.rs delete mode 100644 tests/ui/match_ref_pats.stderr delete mode 100644 tests/ui/match_result_ok.fixed delete mode 100644 tests/ui/match_result_ok.rs delete mode 100644 tests/ui/match_result_ok.stderr delete mode 100644 tests/ui/match_same_arms.rs delete mode 100644 tests/ui/match_same_arms.stderr delete mode 100644 tests/ui/match_same_arms2.fixed delete mode 100644 tests/ui/match_same_arms2.rs delete mode 100644 tests/ui/match_same_arms2.stderr delete mode 100644 tests/ui/match_same_arms_non_exhaustive.fixed delete mode 100644 tests/ui/match_same_arms_non_exhaustive.rs delete mode 100644 tests/ui/match_same_arms_non_exhaustive.stderr delete mode 100644 tests/ui/match_single_binding.fixed delete mode 100644 tests/ui/match_single_binding.rs delete mode 100644 tests/ui/match_single_binding.stderr delete mode 100644 tests/ui/match_single_binding2.fixed delete mode 100644 tests/ui/match_single_binding2.rs delete mode 100644 tests/ui/match_single_binding2.stderr delete mode 100644 tests/ui/match_str_case_mismatch.fixed delete mode 100644 tests/ui/match_str_case_mismatch.rs delete mode 100644 tests/ui/match_str_case_mismatch.stderr delete mode 100644 tests/ui/match_wild_err_arm.rs delete mode 100644 tests/ui/match_wild_err_arm.stderr delete mode 100644 tests/ui/match_wildcard_for_single_variants.fixed delete mode 100644 tests/ui/match_wildcard_for_single_variants.rs delete mode 100644 tests/ui/match_wildcard_for_single_variants.stderr delete mode 100644 tests/ui/mem_forget.rs delete mode 100644 tests/ui/mem_forget.stderr delete mode 100644 tests/ui/mem_replace.fixed delete mode 100644 tests/ui/mem_replace.rs delete mode 100644 tests/ui/mem_replace.stderr delete mode 100644 tests/ui/mem_replace_macro.rs delete mode 100644 tests/ui/mem_replace_macro.stderr delete mode 100644 tests/ui/mem_replace_no_std.fixed delete mode 100644 tests/ui/mem_replace_no_std.rs delete mode 100644 tests/ui/mem_replace_no_std.stderr delete mode 100644 tests/ui/methods.rs delete mode 100644 tests/ui/methods.stderr delete mode 100644 tests/ui/methods_fixable.fixed delete mode 100644 tests/ui/methods_fixable.rs delete mode 100644 tests/ui/methods_fixable.stderr delete mode 100644 tests/ui/methods_unfixable.rs delete mode 100644 tests/ui/methods_unfixable.stderr delete mode 100644 tests/ui/min_ident_chars.rs delete mode 100644 tests/ui/min_ident_chars.stderr delete mode 100644 tests/ui/min_max.rs delete mode 100644 tests/ui/min_max.stderr delete mode 100644 tests/ui/min_rust_version_attr.rs delete mode 100644 tests/ui/min_rust_version_attr.stderr delete mode 100644 tests/ui/min_rust_version_invalid_attr.rs delete mode 100644 tests/ui/min_rust_version_invalid_attr.stderr delete mode 100644 tests/ui/mismatched_target_os_non_unix.fixed delete mode 100644 tests/ui/mismatched_target_os_non_unix.rs delete mode 100644 tests/ui/mismatched_target_os_non_unix.stderr delete mode 100644 tests/ui/mismatched_target_os_unix.fixed delete mode 100644 tests/ui/mismatched_target_os_unix.rs delete mode 100644 tests/ui/mismatched_target_os_unix.stderr delete mode 100644 tests/ui/mismatching_type_param_order.rs delete mode 100644 tests/ui/mismatching_type_param_order.stderr delete mode 100644 tests/ui/misnamed_getters.fixed delete mode 100644 tests/ui/misnamed_getters.rs delete mode 100644 tests/ui/misnamed_getters.stderr delete mode 100644 tests/ui/missing_assert_message.rs delete mode 100644 tests/ui/missing_assert_message.stderr delete mode 100644 tests/ui/missing_asserts_for_indexing.fixed delete mode 100644 tests/ui/missing_asserts_for_indexing.rs delete mode 100644 tests/ui/missing_asserts_for_indexing.stderr delete mode 100644 tests/ui/missing_asserts_for_indexing_unfixable.rs delete mode 100644 tests/ui/missing_asserts_for_indexing_unfixable.stderr delete mode 100644 tests/ui/missing_const_for_fn/auxiliary/helper.rs delete mode 100644 tests/ui/missing_const_for_fn/cant_be_const.rs delete mode 100644 tests/ui/missing_const_for_fn/could_be_const.rs delete mode 100644 tests/ui/missing_const_for_fn/could_be_const.stderr delete mode 100644 tests/ui/missing_doc.rs delete mode 100644 tests/ui/missing_doc.stderr delete mode 100644 tests/ui/missing_doc_crate.rs delete mode 100644 tests/ui/missing_doc_crate_missing.rs delete mode 100644 tests/ui/missing_doc_crate_missing.stderr delete mode 100644 tests/ui/missing_doc_impl.rs delete mode 100644 tests/ui/missing_doc_impl.stderr delete mode 100644 tests/ui/missing_fields_in_debug.rs delete mode 100644 tests/ui/missing_fields_in_debug.stderr delete mode 100644 tests/ui/missing_inline.rs delete mode 100644 tests/ui/missing_inline.stderr delete mode 100644 tests/ui/missing_inline_executable.rs delete mode 100644 tests/ui/missing_inline_proc_macro.rs delete mode 100644 tests/ui/missing_panics_doc.rs delete mode 100644 tests/ui/missing_panics_doc.stderr delete mode 100644 tests/ui/missing_spin_loop.fixed delete mode 100644 tests/ui/missing_spin_loop.rs delete mode 100644 tests/ui/missing_spin_loop.stderr delete mode 100644 tests/ui/missing_spin_loop_no_std.fixed delete mode 100644 tests/ui/missing_spin_loop_no_std.rs delete mode 100644 tests/ui/missing_spin_loop_no_std.stderr delete mode 100644 tests/ui/missing_trait_methods.rs delete mode 100644 tests/ui/missing_trait_methods.stderr delete mode 100644 tests/ui/missing_transmute_annotations.fixed delete mode 100644 tests/ui/missing_transmute_annotations.rs delete mode 100644 tests/ui/missing_transmute_annotations.stderr delete mode 100644 tests/ui/mistyped_literal_suffix.fixed delete mode 100644 tests/ui/mistyped_literal_suffix.rs delete mode 100644 tests/ui/mistyped_literal_suffix.stderr delete mode 100644 tests/ui/mixed_attributes_style.rs delete mode 100644 tests/ui/mixed_attributes_style.stderr delete mode 100644 tests/ui/mixed_attributes_style/auxiliary/submodule.rs delete mode 100644 tests/ui/mixed_attributes_style/global_allow.rs delete mode 100644 tests/ui/mixed_attributes_style/mod_declaration.rs delete mode 100644 tests/ui/mixed_attributes_style/mod_declaration.stderr delete mode 100644 tests/ui/mixed_read_write_in_expression.rs delete mode 100644 tests/ui/mixed_read_write_in_expression.stderr delete mode 100644 tests/ui/module_inception.rs delete mode 100644 tests/ui/module_inception.stderr delete mode 100644 tests/ui/module_name_repetitions.rs delete mode 100644 tests/ui/module_name_repetitions.stderr delete mode 100644 tests/ui/modulo_arithmetic_float.rs delete mode 100644 tests/ui/modulo_arithmetic_float.stderr delete mode 100644 tests/ui/modulo_arithmetic_integral.rs delete mode 100644 tests/ui/modulo_arithmetic_integral.stderr delete mode 100644 tests/ui/modulo_arithmetic_integral_const.rs delete mode 100644 tests/ui/modulo_arithmetic_integral_const.stderr delete mode 100644 tests/ui/modulo_one.rs delete mode 100644 tests/ui/modulo_one.stderr delete mode 100644 tests/ui/multi_assignments.rs delete mode 100644 tests/ui/multi_assignments.stderr delete mode 100644 tests/ui/multiple_bound_locations.rs delete mode 100644 tests/ui/multiple_bound_locations.stderr delete mode 100644 tests/ui/multiple_unsafe_ops_per_block.rs delete mode 100644 tests/ui/multiple_unsafe_ops_per_block.stderr delete mode 100644 tests/ui/must_use_candidates.fixed delete mode 100644 tests/ui/must_use_candidates.rs delete mode 100644 tests/ui/must_use_candidates.stderr delete mode 100644 tests/ui/must_use_unit.fixed delete mode 100644 tests/ui/must_use_unit.rs delete mode 100644 tests/ui/must_use_unit.stderr delete mode 100644 tests/ui/mut_from_ref.rs delete mode 100644 tests/ui/mut_from_ref.stderr delete mode 100644 tests/ui/mut_key.rs delete mode 100644 tests/ui/mut_key.stderr delete mode 100644 tests/ui/mut_mut.rs delete mode 100644 tests/ui/mut_mut.stderr delete mode 100644 tests/ui/mut_mutex_lock.fixed delete mode 100644 tests/ui/mut_mutex_lock.rs delete mode 100644 tests/ui/mut_mutex_lock.stderr delete mode 100644 tests/ui/mut_range_bound.rs delete mode 100644 tests/ui/mut_range_bound.stderr delete mode 100644 tests/ui/mut_reference.rs delete mode 100644 tests/ui/mut_reference.stderr delete mode 100644 tests/ui/mutex_atomic.rs delete mode 100644 tests/ui/mutex_atomic.stderr delete mode 100644 tests/ui/needless_arbitrary_self_type.fixed delete mode 100644 tests/ui/needless_arbitrary_self_type.rs delete mode 100644 tests/ui/needless_arbitrary_self_type.stderr delete mode 100644 tests/ui/needless_arbitrary_self_type_unfixable.fixed delete mode 100644 tests/ui/needless_arbitrary_self_type_unfixable.rs delete mode 100644 tests/ui/needless_arbitrary_self_type_unfixable.stderr delete mode 100644 tests/ui/needless_bitwise_bool.fixed delete mode 100644 tests/ui/needless_bitwise_bool.rs delete mode 100644 tests/ui/needless_bitwise_bool.stderr delete mode 100644 tests/ui/needless_bool/fixable.fixed delete mode 100644 tests/ui/needless_bool/fixable.rs delete mode 100644 tests/ui/needless_bool/fixable.stderr delete mode 100644 tests/ui/needless_bool/simple.rs delete mode 100644 tests/ui/needless_bool/simple.stderr delete mode 100644 tests/ui/needless_bool_assign.fixed delete mode 100644 tests/ui/needless_bool_assign.rs delete mode 100644 tests/ui/needless_bool_assign.stderr delete mode 100644 tests/ui/needless_borrow.fixed delete mode 100644 tests/ui/needless_borrow.rs delete mode 100644 tests/ui/needless_borrow.stderr delete mode 100644 tests/ui/needless_borrow_pat.fixed delete mode 100644 tests/ui/needless_borrow_pat.rs delete mode 100644 tests/ui/needless_borrow_pat.stderr delete mode 100644 tests/ui/needless_borrowed_ref.fixed delete mode 100644 tests/ui/needless_borrowed_ref.rs delete mode 100644 tests/ui/needless_borrowed_ref.stderr delete mode 100644 tests/ui/needless_borrows_for_generic_args.fixed delete mode 100644 tests/ui/needless_borrows_for_generic_args.rs delete mode 100644 tests/ui/needless_borrows_for_generic_args.stderr delete mode 100644 tests/ui/needless_collect.fixed delete mode 100644 tests/ui/needless_collect.rs delete mode 100644 tests/ui/needless_collect.stderr delete mode 100644 tests/ui/needless_collect_indirect.rs delete mode 100644 tests/ui/needless_collect_indirect.stderr delete mode 100644 tests/ui/needless_continue.rs delete mode 100644 tests/ui/needless_continue.stderr delete mode 100644 tests/ui/needless_doc_main.rs delete mode 100644 tests/ui/needless_doc_main.stderr delete mode 100644 tests/ui/needless_else.fixed delete mode 100644 tests/ui/needless_else.rs delete mode 100644 tests/ui/needless_else.stderr delete mode 100644 tests/ui/needless_for_each_fixable.fixed delete mode 100644 tests/ui/needless_for_each_fixable.rs delete mode 100644 tests/ui/needless_for_each_fixable.stderr delete mode 100644 tests/ui/needless_for_each_unfixable.rs delete mode 100644 tests/ui/needless_for_each_unfixable.stderr delete mode 100644 tests/ui/needless_if.fixed delete mode 100644 tests/ui/needless_if.rs delete mode 100644 tests/ui/needless_if.stderr delete mode 100644 tests/ui/needless_late_init.fixed delete mode 100644 tests/ui/needless_late_init.rs delete mode 100644 tests/ui/needless_late_init.stderr delete mode 100644 tests/ui/needless_lifetimes.fixed delete mode 100644 tests/ui/needless_lifetimes.rs delete mode 100644 tests/ui/needless_lifetimes.stderr delete mode 100644 tests/ui/needless_match.fixed delete mode 100644 tests/ui/needless_match.rs delete mode 100644 tests/ui/needless_match.stderr delete mode 100644 tests/ui/needless_option_as_deref.fixed delete mode 100644 tests/ui/needless_option_as_deref.rs delete mode 100644 tests/ui/needless_option_as_deref.stderr delete mode 100644 tests/ui/needless_option_take.fixed delete mode 100644 tests/ui/needless_option_take.rs delete mode 100644 tests/ui/needless_option_take.stderr delete mode 100644 tests/ui/needless_parens_on_range_literals.fixed delete mode 100644 tests/ui/needless_parens_on_range_literals.rs delete mode 100644 tests/ui/needless_parens_on_range_literals.stderr delete mode 100644 tests/ui/needless_pass_by_ref_mut.rs delete mode 100644 tests/ui/needless_pass_by_ref_mut.stderr delete mode 100644 tests/ui/needless_pass_by_ref_mut2.fixed delete mode 100644 tests/ui/needless_pass_by_ref_mut2.rs delete mode 100644 tests/ui/needless_pass_by_ref_mut2.stderr delete mode 100644 tests/ui/needless_pass_by_value.rs delete mode 100644 tests/ui/needless_pass_by_value.stderr delete mode 100644 tests/ui/needless_pass_by_value_proc_macro.rs delete mode 100644 tests/ui/needless_pub_self.fixed delete mode 100644 tests/ui/needless_pub_self.rs delete mode 100644 tests/ui/needless_pub_self.stderr delete mode 100644 tests/ui/needless_question_mark.fixed delete mode 100644 tests/ui/needless_question_mark.rs delete mode 100644 tests/ui/needless_question_mark.stderr delete mode 100644 tests/ui/needless_range_loop.rs delete mode 100644 tests/ui/needless_range_loop.stderr delete mode 100644 tests/ui/needless_range_loop2.rs delete mode 100644 tests/ui/needless_range_loop2.stderr delete mode 100644 tests/ui/needless_raw_string.fixed delete mode 100644 tests/ui/needless_raw_string.rs delete mode 100644 tests/ui/needless_raw_string.stderr delete mode 100644 tests/ui/needless_raw_string_hashes.fixed delete mode 100644 tests/ui/needless_raw_string_hashes.rs delete mode 100644 tests/ui/needless_raw_string_hashes.stderr delete mode 100644 tests/ui/needless_return.fixed delete mode 100644 tests/ui/needless_return.rs delete mode 100644 tests/ui/needless_return.stderr delete mode 100644 tests/ui/needless_return_with_question_mark.fixed delete mode 100644 tests/ui/needless_return_with_question_mark.rs delete mode 100644 tests/ui/needless_return_with_question_mark.stderr delete mode 100644 tests/ui/needless_splitn.fixed delete mode 100644 tests/ui/needless_splitn.rs delete mode 100644 tests/ui/needless_splitn.stderr delete mode 100644 tests/ui/needless_update.rs delete mode 100644 tests/ui/needless_update.stderr delete mode 100644 tests/ui/neg_cmp_op_on_partial_ord.rs delete mode 100644 tests/ui/neg_cmp_op_on_partial_ord.stderr delete mode 100644 tests/ui/neg_multiply.fixed delete mode 100644 tests/ui/neg_multiply.rs delete mode 100644 tests/ui/neg_multiply.stderr delete mode 100644 tests/ui/never_loop.rs delete mode 100644 tests/ui/never_loop.stderr delete mode 100644 tests/ui/new_ret_no_self.rs delete mode 100644 tests/ui/new_ret_no_self.stderr delete mode 100644 tests/ui/new_ret_no_self_overflow.rs delete mode 100644 tests/ui/new_ret_no_self_overflow.stderr delete mode 100644 tests/ui/new_without_default.fixed delete mode 100644 tests/ui/new_without_default.rs delete mode 100644 tests/ui/new_without_default.stderr delete mode 100644 tests/ui/no_effect.rs delete mode 100644 tests/ui/no_effect.stderr delete mode 100644 tests/ui/no_effect_async_fn.rs delete mode 100644 tests/ui/no_effect_async_fn.stderr delete mode 100644 tests/ui/no_effect_replace.rs delete mode 100644 tests/ui/no_effect_replace.stderr delete mode 100644 tests/ui/no_effect_return.rs delete mode 100644 tests/ui/no_effect_return.stderr delete mode 100644 tests/ui/no_mangle_with_rust_abi.rs delete mode 100644 tests/ui/no_mangle_with_rust_abi.stderr delete mode 100644 tests/ui/non_canonical_clone_impl.fixed delete mode 100644 tests/ui/non_canonical_clone_impl.rs delete mode 100644 tests/ui/non_canonical_clone_impl.stderr delete mode 100644 tests/ui/non_canonical_partial_ord_impl.fixed delete mode 100644 tests/ui/non_canonical_partial_ord_impl.rs delete mode 100644 tests/ui/non_canonical_partial_ord_impl.stderr delete mode 100644 tests/ui/non_canonical_partial_ord_impl_fully_qual.rs delete mode 100644 tests/ui/non_canonical_partial_ord_impl_fully_qual.stderr delete mode 100644 tests/ui/non_expressive_names.rs delete mode 100644 tests/ui/non_expressive_names.stderr delete mode 100644 tests/ui/non_minimal_cfg.fixed delete mode 100644 tests/ui/non_minimal_cfg.rs delete mode 100644 tests/ui/non_minimal_cfg.stderr delete mode 100644 tests/ui/non_minimal_cfg2.rs delete mode 100644 tests/ui/non_minimal_cfg2.stderr delete mode 100644 tests/ui/non_octal_unix_permissions.fixed delete mode 100644 tests/ui/non_octal_unix_permissions.rs delete mode 100644 tests/ui/non_octal_unix_permissions.stderr delete mode 100644 tests/ui/non_send_fields_in_send_ty.rs delete mode 100644 tests/ui/non_send_fields_in_send_ty.stderr delete mode 100644 tests/ui/nonminimal_bool.rs delete mode 100644 tests/ui/nonminimal_bool.stderr delete mode 100644 tests/ui/nonminimal_bool_methods.fixed delete mode 100644 tests/ui/nonminimal_bool_methods.rs delete mode 100644 tests/ui/nonminimal_bool_methods.stderr delete mode 100644 tests/ui/numbered_fields.fixed delete mode 100644 tests/ui/numbered_fields.rs delete mode 100644 tests/ui/numbered_fields.stderr delete mode 100644 tests/ui/obfuscated_if_else.fixed delete mode 100644 tests/ui/obfuscated_if_else.rs delete mode 100644 tests/ui/obfuscated_if_else.stderr delete mode 100644 tests/ui/octal_escapes.rs delete mode 100644 tests/ui/octal_escapes.stderr delete mode 100644 tests/ui/ok_expect.rs delete mode 100644 tests/ui/ok_expect.stderr delete mode 100644 tests/ui/only_used_in_recursion.rs delete mode 100644 tests/ui/only_used_in_recursion.stderr delete mode 100644 tests/ui/only_used_in_recursion2.rs delete mode 100644 tests/ui/only_used_in_recursion2.stderr delete mode 100644 tests/ui/op_ref.fixed delete mode 100644 tests/ui/op_ref.rs delete mode 100644 tests/ui/op_ref.stderr delete mode 100644 tests/ui/open_options.rs delete mode 100644 tests/ui/open_options.stderr delete mode 100644 tests/ui/open_options_fixable.fixed delete mode 100644 tests/ui/open_options_fixable.rs delete mode 100644 tests/ui/open_options_fixable.stderr delete mode 100644 tests/ui/option_as_ref_cloned.fixed delete mode 100644 tests/ui/option_as_ref_cloned.rs delete mode 100644 tests/ui/option_as_ref_cloned.stderr delete mode 100644 tests/ui/option_as_ref_deref.fixed delete mode 100644 tests/ui/option_as_ref_deref.rs delete mode 100644 tests/ui/option_as_ref_deref.stderr delete mode 100644 tests/ui/option_env_unwrap.rs delete mode 100644 tests/ui/option_env_unwrap.stderr delete mode 100644 tests/ui/option_filter_map.fixed delete mode 100644 tests/ui/option_filter_map.rs delete mode 100644 tests/ui/option_filter_map.stderr delete mode 100644 tests/ui/option_if_let_else.fixed delete mode 100644 tests/ui/option_if_let_else.rs delete mode 100644 tests/ui/option_if_let_else.stderr delete mode 100644 tests/ui/option_map_or_err_ok.fixed delete mode 100644 tests/ui/option_map_or_err_ok.rs delete mode 100644 tests/ui/option_map_or_err_ok.stderr delete mode 100644 tests/ui/option_map_or_none.fixed delete mode 100644 tests/ui/option_map_or_none.rs delete mode 100644 tests/ui/option_map_or_none.stderr delete mode 100644 tests/ui/option_map_unit_fn_fixable.fixed delete mode 100644 tests/ui/option_map_unit_fn_fixable.rs delete mode 100644 tests/ui/option_map_unit_fn_fixable.stderr delete mode 100644 tests/ui/option_map_unit_fn_unfixable.rs delete mode 100644 tests/ui/option_map_unit_fn_unfixable.stderr delete mode 100644 tests/ui/option_option.rs delete mode 100644 tests/ui/option_option.stderr delete mode 100644 tests/ui/or_fun_call.fixed delete mode 100644 tests/ui/or_fun_call.rs delete mode 100644 tests/ui/or_fun_call.stderr delete mode 100644 tests/ui/or_then_unwrap.fixed delete mode 100644 tests/ui/or_then_unwrap.rs delete mode 100644 tests/ui/or_then_unwrap.stderr delete mode 100644 tests/ui/out_of_bounds_indexing/issue-3102.rs delete mode 100644 tests/ui/out_of_bounds_indexing/issue-3102.stderr delete mode 100644 tests/ui/out_of_bounds_indexing/simple.rs delete mode 100644 tests/ui/out_of_bounds_indexing/simple.stderr delete mode 100644 tests/ui/overflow_check_conditional.rs delete mode 100644 tests/ui/overflow_check_conditional.stderr delete mode 100644 tests/ui/overly_complex_bool_expr.fixed delete mode 100644 tests/ui/overly_complex_bool_expr.rs delete mode 100644 tests/ui/overly_complex_bool_expr.stderr delete mode 100644 tests/ui/panic_in_result_fn.rs delete mode 100644 tests/ui/panic_in_result_fn.stderr delete mode 100644 tests/ui/panic_in_result_fn_assertions.rs delete mode 100644 tests/ui/panic_in_result_fn_assertions.stderr delete mode 100644 tests/ui/panic_in_result_fn_debug_assertions.rs delete mode 100644 tests/ui/panicking_macros.rs delete mode 100644 tests/ui/panicking_macros.stderr delete mode 100644 tests/ui/partial_pub_fields.rs delete mode 100644 tests/ui/partial_pub_fields.stderr delete mode 100644 tests/ui/partialeq_ne_impl.rs delete mode 100644 tests/ui/partialeq_ne_impl.stderr delete mode 100644 tests/ui/partialeq_to_none.fixed delete mode 100644 tests/ui/partialeq_to_none.rs delete mode 100644 tests/ui/partialeq_to_none.stderr delete mode 100644 tests/ui/path_buf_push_overwrite.fixed delete mode 100644 tests/ui/path_buf_push_overwrite.rs delete mode 100644 tests/ui/path_buf_push_overwrite.stderr delete mode 100644 tests/ui/path_ends_with_ext.fixed delete mode 100644 tests/ui/path_ends_with_ext.rs delete mode 100644 tests/ui/path_ends_with_ext.stderr delete mode 100644 tests/ui/pattern_type_mismatch/mutability.rs delete mode 100644 tests/ui/pattern_type_mismatch/mutability.stderr delete mode 100644 tests/ui/pattern_type_mismatch/pattern_alternatives.rs delete mode 100644 tests/ui/pattern_type_mismatch/pattern_alternatives.stderr delete mode 100644 tests/ui/pattern_type_mismatch/pattern_structs.rs delete mode 100644 tests/ui/pattern_type_mismatch/pattern_structs.stderr delete mode 100644 tests/ui/pattern_type_mismatch/pattern_tuples.rs delete mode 100644 tests/ui/pattern_type_mismatch/pattern_tuples.stderr delete mode 100644 tests/ui/pattern_type_mismatch/syntax.rs delete mode 100644 tests/ui/pattern_type_mismatch/syntax.stderr delete mode 100644 tests/ui/patterns.fixed delete mode 100644 tests/ui/patterns.rs delete mode 100644 tests/ui/patterns.stderr delete mode 100644 tests/ui/permissions_set_readonly_false.rs delete mode 100644 tests/ui/permissions_set_readonly_false.stderr delete mode 100644 tests/ui/precedence.fixed delete mode 100644 tests/ui/precedence.rs delete mode 100644 tests/ui/precedence.stderr delete mode 100644 tests/ui/print.rs delete mode 100644 tests/ui/print.stderr delete mode 100644 tests/ui/print_in_format_impl.rs delete mode 100644 tests/ui/print_in_format_impl.stderr delete mode 100644 tests/ui/print_literal.fixed delete mode 100644 tests/ui/print_literal.rs delete mode 100644 tests/ui/print_literal.stderr delete mode 100644 tests/ui/print_stderr.rs delete mode 100644 tests/ui/print_stderr.stderr delete mode 100644 tests/ui/print_stdout_build_script.rs delete mode 100644 tests/ui/print_with_newline.fixed delete mode 100644 tests/ui/print_with_newline.rs delete mode 100644 tests/ui/print_with_newline.stderr delete mode 100644 tests/ui/println_empty_string.fixed delete mode 100644 tests/ui/println_empty_string.rs delete mode 100644 tests/ui/println_empty_string.stderr delete mode 100644 tests/ui/proc_macro.rs delete mode 100644 tests/ui/proc_macro.stderr delete mode 100644 tests/ui/ptr_arg.rs delete mode 100644 tests/ui/ptr_arg.stderr delete mode 100644 tests/ui/ptr_as_ptr.fixed delete mode 100644 tests/ui/ptr_as_ptr.rs delete mode 100644 tests/ui/ptr_as_ptr.stderr delete mode 100644 tests/ui/ptr_cast_constness.fixed delete mode 100644 tests/ui/ptr_cast_constness.rs delete mode 100644 tests/ui/ptr_cast_constness.stderr delete mode 100644 tests/ui/ptr_eq.fixed delete mode 100644 tests/ui/ptr_eq.rs delete mode 100644 tests/ui/ptr_eq.stderr delete mode 100644 tests/ui/ptr_eq_no_std.fixed delete mode 100644 tests/ui/ptr_eq_no_std.rs delete mode 100644 tests/ui/ptr_eq_no_std.stderr delete mode 100644 tests/ui/ptr_offset_with_cast.fixed delete mode 100644 tests/ui/ptr_offset_with_cast.rs delete mode 100644 tests/ui/ptr_offset_with_cast.stderr delete mode 100644 tests/ui/pub_use.rs delete mode 100644 tests/ui/pub_use.stderr delete mode 100644 tests/ui/pub_with_shorthand.fixed delete mode 100644 tests/ui/pub_with_shorthand.rs delete mode 100644 tests/ui/pub_with_shorthand.stderr delete mode 100644 tests/ui/pub_without_shorthand.fixed delete mode 100644 tests/ui/pub_without_shorthand.rs delete mode 100644 tests/ui/pub_without_shorthand.stderr delete mode 100644 tests/ui/question_mark.fixed delete mode 100644 tests/ui/question_mark.rs delete mode 100644 tests/ui/question_mark.stderr delete mode 100644 tests/ui/question_mark_used.rs delete mode 100644 tests/ui/question_mark_used.stderr delete mode 100644 tests/ui/range.rs delete mode 100644 tests/ui/range.stderr delete mode 100644 tests/ui/range_contains.fixed delete mode 100644 tests/ui/range_contains.rs delete mode 100644 tests/ui/range_contains.stderr delete mode 100644 tests/ui/range_plus_minus_one.fixed delete mode 100644 tests/ui/range_plus_minus_one.rs delete mode 100644 tests/ui/range_plus_minus_one.stderr delete mode 100644 tests/ui/rc_buffer.fixed delete mode 100644 tests/ui/rc_buffer.rs delete mode 100644 tests/ui/rc_buffer.stderr delete mode 100644 tests/ui/rc_buffer_arc.fixed delete mode 100644 tests/ui/rc_buffer_arc.rs delete mode 100644 tests/ui/rc_buffer_arc.stderr delete mode 100644 tests/ui/rc_buffer_redefined_string.rs delete mode 100644 tests/ui/rc_clone_in_vec_init/arc.rs delete mode 100644 tests/ui/rc_clone_in_vec_init/arc.stderr delete mode 100644 tests/ui/rc_clone_in_vec_init/rc.rs delete mode 100644 tests/ui/rc_clone_in_vec_init/rc.stderr delete mode 100644 tests/ui/rc_clone_in_vec_init/weak.rs delete mode 100644 tests/ui/rc_clone_in_vec_init/weak.stderr delete mode 100644 tests/ui/rc_mutex.rs delete mode 100644 tests/ui/rc_mutex.stderr delete mode 100644 tests/ui/read_line_without_trim.fixed delete mode 100644 tests/ui/read_line_without_trim.rs delete mode 100644 tests/ui/read_line_without_trim.stderr delete mode 100644 tests/ui/read_zero_byte_vec.rs delete mode 100644 tests/ui/read_zero_byte_vec.stderr delete mode 100644 tests/ui/readonly_write_lock.fixed delete mode 100644 tests/ui/readonly_write_lock.rs delete mode 100644 tests/ui/readonly_write_lock.stderr delete mode 100644 tests/ui/recursive_format_impl.rs delete mode 100644 tests/ui/recursive_format_impl.stderr delete mode 100644 tests/ui/redundant_allocation.rs delete mode 100644 tests/ui/redundant_allocation.stderr delete mode 100644 tests/ui/redundant_allocation_fixable.fixed delete mode 100644 tests/ui/redundant_allocation_fixable.rs delete mode 100644 tests/ui/redundant_allocation_fixable.stderr delete mode 100644 tests/ui/redundant_as_str.fixed delete mode 100644 tests/ui/redundant_as_str.rs delete mode 100644 tests/ui/redundant_as_str.stderr delete mode 100644 tests/ui/redundant_async_block.fixed delete mode 100644 tests/ui/redundant_async_block.rs delete mode 100644 tests/ui/redundant_async_block.stderr delete mode 100644 tests/ui/redundant_at_rest_pattern.fixed delete mode 100644 tests/ui/redundant_at_rest_pattern.rs delete mode 100644 tests/ui/redundant_at_rest_pattern.stderr delete mode 100644 tests/ui/redundant_clone.fixed delete mode 100644 tests/ui/redundant_clone.rs delete mode 100644 tests/ui/redundant_clone.stderr delete mode 100644 tests/ui/redundant_closure_call_early.rs delete mode 100644 tests/ui/redundant_closure_call_early.stderr delete mode 100644 tests/ui/redundant_closure_call_fixable.fixed delete mode 100644 tests/ui/redundant_closure_call_fixable.rs delete mode 100644 tests/ui/redundant_closure_call_fixable.stderr delete mode 100644 tests/ui/redundant_closure_call_late.rs delete mode 100644 tests/ui/redundant_closure_call_late.stderr delete mode 100644 tests/ui/redundant_else.rs delete mode 100644 tests/ui/redundant_else.stderr delete mode 100644 tests/ui/redundant_field_names.fixed delete mode 100644 tests/ui/redundant_field_names.rs delete mode 100644 tests/ui/redundant_field_names.stderr delete mode 100644 tests/ui/redundant_guards.fixed delete mode 100644 tests/ui/redundant_guards.rs delete mode 100644 tests/ui/redundant_guards.stderr delete mode 100644 tests/ui/redundant_locals.rs delete mode 100644 tests/ui/redundant_locals.stderr delete mode 100644 tests/ui/redundant_pattern_matching_drop_order.fixed delete mode 100644 tests/ui/redundant_pattern_matching_drop_order.rs delete mode 100644 tests/ui/redundant_pattern_matching_drop_order.stderr delete mode 100644 tests/ui/redundant_pattern_matching_if_let_true.fixed delete mode 100644 tests/ui/redundant_pattern_matching_if_let_true.rs delete mode 100644 tests/ui/redundant_pattern_matching_if_let_true.stderr delete mode 100644 tests/ui/redundant_pattern_matching_ipaddr.fixed delete mode 100644 tests/ui/redundant_pattern_matching_ipaddr.rs delete mode 100644 tests/ui/redundant_pattern_matching_ipaddr.stderr delete mode 100644 tests/ui/redundant_pattern_matching_option.fixed delete mode 100644 tests/ui/redundant_pattern_matching_option.rs delete mode 100644 tests/ui/redundant_pattern_matching_option.stderr delete mode 100644 tests/ui/redundant_pattern_matching_poll.fixed delete mode 100644 tests/ui/redundant_pattern_matching_poll.rs delete mode 100644 tests/ui/redundant_pattern_matching_poll.stderr delete mode 100644 tests/ui/redundant_pattern_matching_result.fixed delete mode 100644 tests/ui/redundant_pattern_matching_result.rs delete mode 100644 tests/ui/redundant_pattern_matching_result.stderr delete mode 100644 tests/ui/redundant_pub_crate.fixed delete mode 100644 tests/ui/redundant_pub_crate.rs delete mode 100644 tests/ui/redundant_pub_crate.stderr delete mode 100644 tests/ui/redundant_slicing.fixed delete mode 100644 tests/ui/redundant_slicing.rs delete mode 100644 tests/ui/redundant_slicing.stderr delete mode 100644 tests/ui/redundant_static_lifetimes.fixed delete mode 100644 tests/ui/redundant_static_lifetimes.rs delete mode 100644 tests/ui/redundant_static_lifetimes.stderr delete mode 100644 tests/ui/redundant_static_lifetimes_multiple.rs delete mode 100644 tests/ui/redundant_static_lifetimes_multiple.stderr delete mode 100644 tests/ui/redundant_type_annotations.rs delete mode 100644 tests/ui/redundant_type_annotations.stderr delete mode 100644 tests/ui/ref_as_ptr.fixed delete mode 100644 tests/ui/ref_as_ptr.rs delete mode 100644 tests/ui/ref_as_ptr.stderr delete mode 100644 tests/ui/ref_binding_to_reference.rs delete mode 100644 tests/ui/ref_binding_to_reference.stderr delete mode 100644 tests/ui/ref_option_ref.rs delete mode 100644 tests/ui/ref_option_ref.stderr delete mode 100644 tests/ui/ref_patterns.rs delete mode 100644 tests/ui/ref_patterns.stderr delete mode 100644 tests/ui/regex.rs delete mode 100644 tests/ui/regex.stderr delete mode 100644 tests/ui/rename.fixed delete mode 100644 tests/ui/rename.rs delete mode 100644 tests/ui/rename.stderr delete mode 100644 tests/ui/renamed_builtin_attr.fixed delete mode 100644 tests/ui/renamed_builtin_attr.rs delete mode 100644 tests/ui/renamed_builtin_attr.stderr delete mode 100644 tests/ui/repeat_once.fixed delete mode 100644 tests/ui/repeat_once.rs delete mode 100644 tests/ui/repeat_once.stderr delete mode 100644 tests/ui/repeat_vec_with_capacity.fixed delete mode 100644 tests/ui/repeat_vec_with_capacity.rs delete mode 100644 tests/ui/repeat_vec_with_capacity.stderr delete mode 100644 tests/ui/repl_uninit.rs delete mode 100644 tests/ui/repl_uninit.stderr delete mode 100644 tests/ui/reserve_after_initialization.fixed delete mode 100644 tests/ui/reserve_after_initialization.rs delete mode 100644 tests/ui/reserve_after_initialization.stderr delete mode 100644 tests/ui/rest_pat_in_fully_bound_structs.rs delete mode 100644 tests/ui/rest_pat_in_fully_bound_structs.stderr delete mode 100644 tests/ui/result_filter_map.fixed delete mode 100644 tests/ui/result_filter_map.rs delete mode 100644 tests/ui/result_filter_map.stderr delete mode 100644 tests/ui/result_large_err.rs delete mode 100644 tests/ui/result_large_err.stderr delete mode 100644 tests/ui/result_map_or_into_option.fixed delete mode 100644 tests/ui/result_map_or_into_option.rs delete mode 100644 tests/ui/result_map_or_into_option.stderr delete mode 100644 tests/ui/result_map_unit_fn_fixable.fixed delete mode 100644 tests/ui/result_map_unit_fn_fixable.rs delete mode 100644 tests/ui/result_map_unit_fn_fixable.stderr delete mode 100644 tests/ui/result_map_unit_fn_unfixable.rs delete mode 100644 tests/ui/result_map_unit_fn_unfixable.stderr delete mode 100644 tests/ui/result_unit_error.rs delete mode 100644 tests/ui/result_unit_error.stderr delete mode 100644 tests/ui/return_self_not_must_use.rs delete mode 100644 tests/ui/return_self_not_must_use.stderr delete mode 100644 tests/ui/reversed_empty_ranges_fixable.fixed delete mode 100644 tests/ui/reversed_empty_ranges_fixable.rs delete mode 100644 tests/ui/reversed_empty_ranges_fixable.stderr delete mode 100644 tests/ui/reversed_empty_ranges_loops_fixable.fixed delete mode 100644 tests/ui/reversed_empty_ranges_loops_fixable.rs delete mode 100644 tests/ui/reversed_empty_ranges_loops_fixable.stderr delete mode 100644 tests/ui/reversed_empty_ranges_loops_unfixable.rs delete mode 100644 tests/ui/reversed_empty_ranges_loops_unfixable.stderr delete mode 100644 tests/ui/reversed_empty_ranges_unfixable.rs delete mode 100644 tests/ui/reversed_empty_ranges_unfixable.stderr delete mode 100644 tests/ui/same_functions_in_if_condition.rs delete mode 100644 tests/ui/same_functions_in_if_condition.stderr delete mode 100644 tests/ui/same_item_push.rs delete mode 100644 tests/ui/same_item_push.stderr delete mode 100644 tests/ui/same_name_method.rs delete mode 100644 tests/ui/same_name_method.stderr delete mode 100644 tests/ui/search_is_some.rs delete mode 100644 tests/ui/search_is_some.stderr delete mode 100644 tests/ui/search_is_some_fixable_none.fixed delete mode 100644 tests/ui/search_is_some_fixable_none.rs delete mode 100644 tests/ui/search_is_some_fixable_none.stderr delete mode 100644 tests/ui/search_is_some_fixable_some.fixed delete mode 100644 tests/ui/search_is_some_fixable_some.rs delete mode 100644 tests/ui/search_is_some_fixable_some.stderr delete mode 100644 tests/ui/seek_from_current.fixed delete mode 100644 tests/ui/seek_from_current.rs delete mode 100644 tests/ui/seek_from_current.stderr delete mode 100644 tests/ui/seek_to_start_instead_of_rewind.fixed delete mode 100644 tests/ui/seek_to_start_instead_of_rewind.rs delete mode 100644 tests/ui/seek_to_start_instead_of_rewind.stderr delete mode 100644 tests/ui/self_assignment.rs delete mode 100644 tests/ui/self_assignment.stderr delete mode 100644 tests/ui/self_named_constructors.rs delete mode 100644 tests/ui/self_named_constructors.stderr delete mode 100644 tests/ui/semicolon_if_nothing_returned.fixed delete mode 100644 tests/ui/semicolon_if_nothing_returned.rs delete mode 100644 tests/ui/semicolon_if_nothing_returned.stderr delete mode 100644 tests/ui/semicolon_inside_block.fixed delete mode 100644 tests/ui/semicolon_inside_block.rs delete mode 100644 tests/ui/semicolon_inside_block.stderr delete mode 100644 tests/ui/semicolon_outside_block.fixed delete mode 100644 tests/ui/semicolon_outside_block.rs delete mode 100644 tests/ui/semicolon_outside_block.stderr delete mode 100644 tests/ui/serde.rs delete mode 100644 tests/ui/serde.stderr delete mode 100644 tests/ui/shadow.rs delete mode 100644 tests/ui/shadow.stderr delete mode 100644 tests/ui/short_circuit_statement.fixed delete mode 100644 tests/ui/short_circuit_statement.rs delete mode 100644 tests/ui/short_circuit_statement.stderr delete mode 100644 tests/ui/should_impl_trait/corner_cases.rs delete mode 100644 tests/ui/should_impl_trait/method_list_1.rs delete mode 100644 tests/ui/should_impl_trait/method_list_1.stderr delete mode 100644 tests/ui/should_impl_trait/method_list_2.rs delete mode 100644 tests/ui/should_impl_trait/method_list_2.stderr delete mode 100644 tests/ui/should_panic_without_expect.rs delete mode 100644 tests/ui/should_panic_without_expect.stderr delete mode 100644 tests/ui/significant_drop_in_scrutinee.rs delete mode 100644 tests/ui/significant_drop_in_scrutinee.stderr delete mode 100644 tests/ui/significant_drop_tightening.fixed delete mode 100644 tests/ui/significant_drop_tightening.rs delete mode 100644 tests/ui/significant_drop_tightening.stderr delete mode 100644 tests/ui/similar_names.rs delete mode 100644 tests/ui/similar_names.stderr delete mode 100644 tests/ui/single_call_fn.rs delete mode 100644 tests/ui/single_call_fn.stderr delete mode 100644 tests/ui/single_char_add_str.fixed delete mode 100644 tests/ui/single_char_add_str.rs delete mode 100644 tests/ui/single_char_add_str.stderr delete mode 100644 tests/ui/single_char_lifetime_names.rs delete mode 100644 tests/ui/single_char_lifetime_names.stderr delete mode 100644 tests/ui/single_char_pattern.fixed delete mode 100644 tests/ui/single_char_pattern.rs delete mode 100644 tests/ui/single_char_pattern.stderr delete mode 100644 tests/ui/single_component_path_imports.fixed delete mode 100644 tests/ui/single_component_path_imports.rs delete mode 100644 tests/ui/single_component_path_imports.stderr delete mode 100644 tests/ui/single_component_path_imports_macro.rs delete mode 100644 tests/ui/single_component_path_imports_nested_first.rs delete mode 100644 tests/ui/single_component_path_imports_nested_first.stderr delete mode 100644 tests/ui/single_component_path_imports_self_after.rs delete mode 100644 tests/ui/single_component_path_imports_self_before.rs delete mode 100644 tests/ui/single_element_loop.fixed delete mode 100644 tests/ui/single_element_loop.rs delete mode 100644 tests/ui/single_element_loop.stderr delete mode 100644 tests/ui/single_match.fixed delete mode 100644 tests/ui/single_match.rs delete mode 100644 tests/ui/single_match.stderr delete mode 100644 tests/ui/single_match_else.fixed delete mode 100644 tests/ui/single_match_else.rs delete mode 100644 tests/ui/single_match_else.stderr delete mode 100644 tests/ui/single_range_in_vec_init.rs delete mode 100644 tests/ui/single_range_in_vec_init.stderr delete mode 100644 tests/ui/size_of_in_element_count/expressions.rs delete mode 100644 tests/ui/size_of_in_element_count/expressions.stderr delete mode 100644 tests/ui/size_of_in_element_count/functions.rs delete mode 100644 tests/ui/size_of_in_element_count/functions.stderr delete mode 100644 tests/ui/size_of_ref.rs delete mode 100644 tests/ui/size_of_ref.stderr delete mode 100644 tests/ui/skip_while_next.rs delete mode 100644 tests/ui/skip_while_next.stderr delete mode 100644 tests/ui/slow_vector_initialization.rs delete mode 100644 tests/ui/slow_vector_initialization.stderr delete mode 100644 tests/ui/stable_sort_primitive.fixed delete mode 100644 tests/ui/stable_sort_primitive.rs delete mode 100644 tests/ui/stable_sort_primitive.stderr delete mode 100644 tests/ui/starts_ends_with.fixed delete mode 100644 tests/ui/starts_ends_with.rs delete mode 100644 tests/ui/starts_ends_with.stderr delete mode 100644 tests/ui/std_instead_of_core.fixed delete mode 100644 tests/ui/std_instead_of_core.rs delete mode 100644 tests/ui/std_instead_of_core.stderr delete mode 100644 tests/ui/str_split.fixed delete mode 100644 tests/ui/str_split.rs delete mode 100644 tests/ui/str_split.stderr delete mode 100644 tests/ui/str_to_string.rs delete mode 100644 tests/ui/str_to_string.stderr delete mode 100644 tests/ui/string_add.rs delete mode 100644 tests/ui/string_add.stderr delete mode 100644 tests/ui/string_add_assign.fixed delete mode 100644 tests/ui/string_add_assign.rs delete mode 100644 tests/ui/string_add_assign.stderr delete mode 100644 tests/ui/string_extend.fixed delete mode 100644 tests/ui/string_extend.rs delete mode 100644 tests/ui/string_extend.stderr delete mode 100644 tests/ui/string_from_utf8_as_bytes.fixed delete mode 100644 tests/ui/string_from_utf8_as_bytes.rs delete mode 100644 tests/ui/string_from_utf8_as_bytes.stderr delete mode 100644 tests/ui/string_lit_as_bytes.fixed delete mode 100644 tests/ui/string_lit_as_bytes.rs delete mode 100644 tests/ui/string_lit_as_bytes.stderr delete mode 100644 tests/ui/string_lit_chars_any.fixed delete mode 100644 tests/ui/string_lit_chars_any.rs delete mode 100644 tests/ui/string_lit_chars_any.stderr delete mode 100644 tests/ui/string_slice.rs delete mode 100644 tests/ui/string_slice.stderr delete mode 100644 tests/ui/string_to_string.rs delete mode 100644 tests/ui/string_to_string.stderr delete mode 100644 tests/ui/strlen_on_c_strings.fixed delete mode 100644 tests/ui/strlen_on_c_strings.rs delete mode 100644 tests/ui/strlen_on_c_strings.stderr delete mode 100644 tests/ui/struct_excessive_bools.rs delete mode 100644 tests/ui/struct_excessive_bools.stderr delete mode 100644 tests/ui/struct_fields.rs delete mode 100644 tests/ui/struct_fields.stderr delete mode 100644 tests/ui/suspicious_arithmetic_impl.rs delete mode 100644 tests/ui/suspicious_arithmetic_impl.stderr delete mode 100644 tests/ui/suspicious_command_arg_space.fixed delete mode 100644 tests/ui/suspicious_command_arg_space.rs delete mode 100644 tests/ui/suspicious_command_arg_space.stderr delete mode 100644 tests/ui/suspicious_doc_comments.fixed delete mode 100644 tests/ui/suspicious_doc_comments.rs delete mode 100644 tests/ui/suspicious_doc_comments.stderr delete mode 100644 tests/ui/suspicious_doc_comments_unfixable.rs delete mode 100644 tests/ui/suspicious_doc_comments_unfixable.stderr delete mode 100644 tests/ui/suspicious_else_formatting.rs delete mode 100644 tests/ui/suspicious_else_formatting.stderr delete mode 100644 tests/ui/suspicious_map.rs delete mode 100644 tests/ui/suspicious_map.stderr delete mode 100644 tests/ui/suspicious_operation_groupings.fixed delete mode 100644 tests/ui/suspicious_operation_groupings.rs delete mode 100644 tests/ui/suspicious_operation_groupings.stderr delete mode 100644 tests/ui/suspicious_splitn.rs delete mode 100644 tests/ui/suspicious_splitn.stderr delete mode 100644 tests/ui/suspicious_to_owned.rs delete mode 100644 tests/ui/suspicious_to_owned.stderr delete mode 100644 tests/ui/suspicious_unary_op_formatting.rs delete mode 100644 tests/ui/suspicious_unary_op_formatting.stderr delete mode 100644 tests/ui/suspicious_xor_used_as_pow.rs delete mode 100644 tests/ui/suspicious_xor_used_as_pow.stderr delete mode 100644 tests/ui/swap.fixed delete mode 100644 tests/ui/swap.rs delete mode 100644 tests/ui/swap.stderr delete mode 100644 tests/ui/swap_ptr_to_ref.fixed delete mode 100644 tests/ui/swap_ptr_to_ref.rs delete mode 100644 tests/ui/swap_ptr_to_ref.stderr delete mode 100644 tests/ui/swap_ptr_to_ref_unfixable.rs delete mode 100644 tests/ui/swap_ptr_to_ref_unfixable.stderr delete mode 100644 tests/ui/tabs_in_doc_comments.fixed delete mode 100644 tests/ui/tabs_in_doc_comments.rs delete mode 100644 tests/ui/tabs_in_doc_comments.stderr delete mode 100644 tests/ui/temporary_assignment.rs delete mode 100644 tests/ui/temporary_assignment.stderr delete mode 100644 tests/ui/test_attr_in_doctest.rs delete mode 100644 tests/ui/test_attr_in_doctest.stderr delete mode 100644 tests/ui/tests_outside_test_module.rs delete mode 100644 tests/ui/tests_outside_test_module.stderr delete mode 100644 tests/ui/thread_local_initializer_can_be_made_const.fixed delete mode 100644 tests/ui/thread_local_initializer_can_be_made_const.rs delete mode 100644 tests/ui/thread_local_initializer_can_be_made_const.stderr delete mode 100644 tests/ui/to_digit_is_some.fixed delete mode 100644 tests/ui/to_digit_is_some.rs delete mode 100644 tests/ui/to_digit_is_some.stderr delete mode 100644 tests/ui/to_string_in_format_args_incremental.fixed delete mode 100644 tests/ui/to_string_in_format_args_incremental.rs delete mode 100644 tests/ui/to_string_in_format_args_incremental.stderr delete mode 100644 tests/ui/to_string_trait_impl.rs delete mode 100644 tests/ui/to_string_trait_impl.stderr delete mode 100644 tests/ui/toplevel_ref_arg.fixed delete mode 100644 tests/ui/toplevel_ref_arg.rs delete mode 100644 tests/ui/toplevel_ref_arg.stderr delete mode 100644 tests/ui/toplevel_ref_arg_non_rustfix.rs delete mode 100644 tests/ui/toplevel_ref_arg_non_rustfix.stderr delete mode 100644 tests/ui/track-diagnostics.rs delete mode 100644 tests/ui/track-diagnostics.stderr delete mode 100644 tests/ui/trailing_empty_array.rs delete mode 100644 tests/ui/trailing_empty_array.stderr delete mode 100644 tests/ui/trailing_zeros.fixed delete mode 100644 tests/ui/trailing_zeros.rs delete mode 100644 tests/ui/trailing_zeros.stderr delete mode 100644 tests/ui/trait_duplication_in_bounds.fixed delete mode 100644 tests/ui/trait_duplication_in_bounds.rs delete mode 100644 tests/ui/trait_duplication_in_bounds.stderr delete mode 100644 tests/ui/trait_duplication_in_bounds_unfixable.rs delete mode 100644 tests/ui/trait_duplication_in_bounds_unfixable.stderr delete mode 100644 tests/ui/transmute.rs delete mode 100644 tests/ui/transmute.stderr delete mode 100644 tests/ui/transmute_32bit.rs delete mode 100644 tests/ui/transmute_32bit.stderr delete mode 100644 tests/ui/transmute_64bit.rs delete mode 100644 tests/ui/transmute_64bit.stderr delete mode 100644 tests/ui/transmute_collection.rs delete mode 100644 tests/ui/transmute_collection.stderr delete mode 100644 tests/ui/transmute_float_to_int.fixed delete mode 100644 tests/ui/transmute_float_to_int.rs delete mode 100644 tests/ui/transmute_float_to_int.stderr delete mode 100644 tests/ui/transmute_int_to_char.fixed delete mode 100644 tests/ui/transmute_int_to_char.rs delete mode 100644 tests/ui/transmute_int_to_char.stderr delete mode 100644 tests/ui/transmute_int_to_char_no_std.fixed delete mode 100644 tests/ui/transmute_int_to_char_no_std.rs delete mode 100644 tests/ui/transmute_int_to_char_no_std.stderr delete mode 100644 tests/ui/transmute_int_to_non_zero.fixed delete mode 100644 tests/ui/transmute_int_to_non_zero.rs delete mode 100644 tests/ui/transmute_int_to_non_zero.stderr delete mode 100644 tests/ui/transmute_null_to_fn.rs delete mode 100644 tests/ui/transmute_null_to_fn.stderr delete mode 100644 tests/ui/transmute_ptr_to_ptr.fixed delete mode 100644 tests/ui/transmute_ptr_to_ptr.rs delete mode 100644 tests/ui/transmute_ptr_to_ptr.stderr delete mode 100644 tests/ui/transmute_ptr_to_ref.fixed delete mode 100644 tests/ui/transmute_ptr_to_ref.rs delete mode 100644 tests/ui/transmute_ptr_to_ref.stderr delete mode 100644 tests/ui/transmute_ref_to_ref.rs delete mode 100644 tests/ui/transmute_ref_to_ref.stderr delete mode 100644 tests/ui/transmute_ref_to_ref_no_std.rs delete mode 100644 tests/ui/transmute_ref_to_ref_no_std.stderr delete mode 100644 tests/ui/transmute_undefined_repr.rs delete mode 100644 tests/ui/transmute_undefined_repr.stderr delete mode 100644 tests/ui/transmutes_expressible_as_ptr_casts.fixed delete mode 100644 tests/ui/transmutes_expressible_as_ptr_casts.rs delete mode 100644 tests/ui/transmutes_expressible_as_ptr_casts.stderr delete mode 100644 tests/ui/transmuting_null.rs delete mode 100644 tests/ui/transmuting_null.stderr delete mode 100644 tests/ui/trim_split_whitespace.fixed delete mode 100644 tests/ui/trim_split_whitespace.rs delete mode 100644 tests/ui/trim_split_whitespace.stderr delete mode 100644 tests/ui/trivially_copy_pass_by_ref.rs delete mode 100644 tests/ui/trivially_copy_pass_by_ref.stderr delete mode 100644 tests/ui/try_err.fixed delete mode 100644 tests/ui/try_err.rs delete mode 100644 tests/ui/try_err.stderr delete mode 100644 tests/ui/tuple_array_conversions.rs delete mode 100644 tests/ui/tuple_array_conversions.stderr delete mode 100644 tests/ui/ty_fn_sig.rs delete mode 100644 tests/ui/type_complexity.rs delete mode 100644 tests/ui/type_complexity.stderr delete mode 100644 tests/ui/type_id_on_box.fixed delete mode 100644 tests/ui/type_id_on_box.rs delete mode 100644 tests/ui/type_id_on_box.stderr delete mode 100644 tests/ui/type_id_on_box_unfixable.rs delete mode 100644 tests/ui/type_id_on_box_unfixable.stderr delete mode 100644 tests/ui/type_repetition_in_bounds.rs delete mode 100644 tests/ui/type_repetition_in_bounds.stderr delete mode 100644 tests/ui/types.fixed delete mode 100644 tests/ui/types.rs delete mode 100644 tests/ui/types.stderr delete mode 100644 tests/ui/unchecked_duration_subtraction.fixed delete mode 100644 tests/ui/unchecked_duration_subtraction.rs delete mode 100644 tests/ui/unchecked_duration_subtraction.stderr delete mode 100644 tests/ui/unconditional_recursion.rs delete mode 100644 tests/ui/unconditional_recursion.stderr delete mode 100644 tests/ui/unicode.fixed delete mode 100644 tests/ui/unicode.rs delete mode 100644 tests/ui/unicode.stderr delete mode 100644 tests/ui/uninhabited_references.rs delete mode 100644 tests/ui/uninhabited_references.stderr delete mode 100644 tests/ui/uninit.rs delete mode 100644 tests/ui/uninit.stderr delete mode 100644 tests/ui/uninit_vec.rs delete mode 100644 tests/ui/uninit_vec.stderr delete mode 100644 tests/ui/uninlined_format_args.fixed delete mode 100644 tests/ui/uninlined_format_args.rs delete mode 100644 tests/ui/uninlined_format_args.stderr delete mode 100644 tests/ui/uninlined_format_args_panic.edition2018.fixed delete mode 100644 tests/ui/uninlined_format_args_panic.edition2018.stderr delete mode 100644 tests/ui/uninlined_format_args_panic.edition2021.fixed delete mode 100644 tests/ui/uninlined_format_args_panic.edition2021.stderr delete mode 100644 tests/ui/uninlined_format_args_panic.rs delete mode 100644 tests/ui/unit_arg.rs delete mode 100644 tests/ui/unit_arg.stderr delete mode 100644 tests/ui/unit_arg_empty_blocks.fixed delete mode 100644 tests/ui/unit_arg_empty_blocks.rs delete mode 100644 tests/ui/unit_arg_empty_blocks.stderr delete mode 100644 tests/ui/unit_cmp.rs delete mode 100644 tests/ui/unit_cmp.stderr delete mode 100644 tests/ui/unit_hash.fixed delete mode 100644 tests/ui/unit_hash.rs delete mode 100644 tests/ui/unit_hash.stderr delete mode 100644 tests/ui/unit_return_expecting_ord.rs delete mode 100644 tests/ui/unit_return_expecting_ord.stderr delete mode 100644 tests/ui/unknown_attribute.rs delete mode 100644 tests/ui/unknown_attribute.stderr delete mode 100644 tests/ui/unknown_clippy_lints.fixed delete mode 100644 tests/ui/unknown_clippy_lints.rs delete mode 100644 tests/ui/unknown_clippy_lints.stderr delete mode 100644 tests/ui/unnecessary_box_returns.rs delete mode 100644 tests/ui/unnecessary_box_returns.stderr delete mode 100644 tests/ui/unnecessary_cast.fixed delete mode 100644 tests/ui/unnecessary_cast.rs delete mode 100644 tests/ui/unnecessary_cast.stderr delete mode 100644 tests/ui/unnecessary_cast_unfixable.rs delete mode 100644 tests/ui/unnecessary_cast_unfixable.stderr delete mode 100644 tests/ui/unnecessary_clippy_cfg.rs delete mode 100644 tests/ui/unnecessary_clippy_cfg.stderr delete mode 100644 tests/ui/unnecessary_clone.rs delete mode 100644 tests/ui/unnecessary_clone.stderr delete mode 100644 tests/ui/unnecessary_fallible_conversions.fixed delete mode 100644 tests/ui/unnecessary_fallible_conversions.rs delete mode 100644 tests/ui/unnecessary_fallible_conversions.stderr delete mode 100644 tests/ui/unnecessary_fallible_conversions_unfixable.rs delete mode 100644 tests/ui/unnecessary_fallible_conversions_unfixable.stderr delete mode 100644 tests/ui/unnecessary_filter_map.rs delete mode 100644 tests/ui/unnecessary_filter_map.stderr delete mode 100644 tests/ui/unnecessary_find_map.rs delete mode 100644 tests/ui/unnecessary_find_map.stderr delete mode 100644 tests/ui/unnecessary_fold.fixed delete mode 100644 tests/ui/unnecessary_fold.rs delete mode 100644 tests/ui/unnecessary_fold.stderr delete mode 100644 tests/ui/unnecessary_get_then_check.fixed delete mode 100644 tests/ui/unnecessary_get_then_check.rs delete mode 100644 tests/ui/unnecessary_get_then_check.stderr delete mode 100644 tests/ui/unnecessary_iter_cloned.fixed delete mode 100644 tests/ui/unnecessary_iter_cloned.rs delete mode 100644 tests/ui/unnecessary_iter_cloned.stderr delete mode 100644 tests/ui/unnecessary_join.fixed delete mode 100644 tests/ui/unnecessary_join.rs delete mode 100644 tests/ui/unnecessary_join.stderr delete mode 100644 tests/ui/unnecessary_lazy_eval.fixed delete mode 100644 tests/ui/unnecessary_lazy_eval.rs delete mode 100644 tests/ui/unnecessary_lazy_eval.stderr delete mode 100644 tests/ui/unnecessary_lazy_eval_unfixable.rs delete mode 100644 tests/ui/unnecessary_lazy_eval_unfixable.stderr delete mode 100644 tests/ui/unnecessary_literal_unwrap.fixed delete mode 100644 tests/ui/unnecessary_literal_unwrap.rs delete mode 100644 tests/ui/unnecessary_literal_unwrap.stderr delete mode 100644 tests/ui/unnecessary_literal_unwrap_unfixable.rs delete mode 100644 tests/ui/unnecessary_literal_unwrap_unfixable.stderr delete mode 100644 tests/ui/unnecessary_map_on_constructor.fixed delete mode 100644 tests/ui/unnecessary_map_on_constructor.rs delete mode 100644 tests/ui/unnecessary_map_on_constructor.stderr delete mode 100644 tests/ui/unnecessary_operation.fixed delete mode 100644 tests/ui/unnecessary_operation.rs delete mode 100644 tests/ui/unnecessary_operation.stderr delete mode 100644 tests/ui/unnecessary_owned_empty_strings.fixed delete mode 100644 tests/ui/unnecessary_owned_empty_strings.rs delete mode 100644 tests/ui/unnecessary_owned_empty_strings.stderr delete mode 100644 tests/ui/unnecessary_result_map_or_else.fixed delete mode 100644 tests/ui/unnecessary_result_map_or_else.rs delete mode 100644 tests/ui/unnecessary_result_map_or_else.stderr delete mode 100644 tests/ui/unnecessary_safety_comment.rs delete mode 100644 tests/ui/unnecessary_safety_comment.stderr delete mode 100644 tests/ui/unnecessary_self_imports.fixed delete mode 100644 tests/ui/unnecessary_self_imports.rs delete mode 100644 tests/ui/unnecessary_self_imports.stderr delete mode 100644 tests/ui/unnecessary_sort_by.fixed delete mode 100644 tests/ui/unnecessary_sort_by.rs delete mode 100644 tests/ui/unnecessary_sort_by.stderr delete mode 100644 tests/ui/unnecessary_struct_initialization.fixed delete mode 100644 tests/ui/unnecessary_struct_initialization.rs delete mode 100644 tests/ui/unnecessary_struct_initialization.stderr delete mode 100644 tests/ui/unnecessary_to_owned.fixed delete mode 100644 tests/ui/unnecessary_to_owned.rs delete mode 100644 tests/ui/unnecessary_to_owned.stderr delete mode 100644 tests/ui/unnecessary_to_owned_on_split.fixed delete mode 100644 tests/ui/unnecessary_to_owned_on_split.rs delete mode 100644 tests/ui/unnecessary_to_owned_on_split.stderr delete mode 100644 tests/ui/unnecessary_unsafety_doc.rs delete mode 100644 tests/ui/unnecessary_unsafety_doc.stderr delete mode 100644 tests/ui/unnecessary_wraps.rs delete mode 100644 tests/ui/unnecessary_wraps.stderr delete mode 100644 tests/ui/unneeded_field_pattern.rs delete mode 100644 tests/ui/unneeded_field_pattern.stderr delete mode 100644 tests/ui/unneeded_wildcard_pattern.fixed delete mode 100644 tests/ui/unneeded_wildcard_pattern.rs delete mode 100644 tests/ui/unneeded_wildcard_pattern.stderr delete mode 100644 tests/ui/unnested_or_patterns.fixed delete mode 100644 tests/ui/unnested_or_patterns.rs delete mode 100644 tests/ui/unnested_or_patterns.stderr delete mode 100644 tests/ui/unnested_or_patterns2.fixed delete mode 100644 tests/ui/unnested_or_patterns2.rs delete mode 100644 tests/ui/unnested_or_patterns2.stderr delete mode 100644 tests/ui/unreadable_literal.fixed delete mode 100644 tests/ui/unreadable_literal.rs delete mode 100644 tests/ui/unreadable_literal.stderr delete mode 100644 tests/ui/unsafe_derive_deserialize.rs delete mode 100644 tests/ui/unsafe_derive_deserialize.stderr delete mode 100644 tests/ui/unsafe_removed_from_name.rs delete mode 100644 tests/ui/unsafe_removed_from_name.stderr delete mode 100644 tests/ui/unseparated_prefix_literals.fixed delete mode 100644 tests/ui/unseparated_prefix_literals.rs delete mode 100644 tests/ui/unseparated_prefix_literals.stderr delete mode 100644 tests/ui/unused_async.rs delete mode 100644 tests/ui/unused_async.stderr delete mode 100644 tests/ui/unused_enumerate_index.fixed delete mode 100644 tests/ui/unused_enumerate_index.rs delete mode 100644 tests/ui/unused_enumerate_index.stderr delete mode 100644 tests/ui/unused_format_specs_unfixable.rs delete mode 100644 tests/ui/unused_format_specs_unfixable.stderr delete mode 100644 tests/ui/unused_io_amount.rs delete mode 100644 tests/ui/unused_io_amount.stderr delete mode 100644 tests/ui/unused_peekable.rs delete mode 100644 tests/ui/unused_peekable.stderr delete mode 100644 tests/ui/unused_rounding.fixed delete mode 100644 tests/ui/unused_rounding.rs delete mode 100644 tests/ui/unused_rounding.stderr delete mode 100644 tests/ui/unused_self.rs delete mode 100644 tests/ui/unused_self.stderr delete mode 100644 tests/ui/unused_unit.fixed delete mode 100644 tests/ui/unused_unit.rs delete mode 100644 tests/ui/unused_unit.stderr delete mode 100644 tests/ui/unwrap.rs delete mode 100644 tests/ui/unwrap.stderr delete mode 100644 tests/ui/unwrap_expect_used.rs delete mode 100644 tests/ui/unwrap_expect_used.stderr delete mode 100644 tests/ui/unwrap_in_result.rs delete mode 100644 tests/ui/unwrap_in_result.stderr delete mode 100644 tests/ui/unwrap_or.fixed delete mode 100644 tests/ui/unwrap_or.rs delete mode 100644 tests/ui/unwrap_or.stderr delete mode 100644 tests/ui/unwrap_or_else_default.fixed delete mode 100644 tests/ui/unwrap_or_else_default.rs delete mode 100644 tests/ui/unwrap_or_else_default.stderr delete mode 100755 tests/ui/update-all-references.sh delete mode 100644 tests/ui/upper_case_acronyms.fixed delete mode 100644 tests/ui/upper_case_acronyms.rs delete mode 100644 tests/ui/upper_case_acronyms.stderr delete mode 100644 tests/ui/use_self.fixed delete mode 100644 tests/ui/use_self.rs delete mode 100644 tests/ui/use_self.stderr delete mode 100644 tests/ui/use_self_trait.fixed delete mode 100644 tests/ui/use_self_trait.rs delete mode 100644 tests/ui/use_self_trait.stderr delete mode 100644 tests/ui/used_underscore_binding.rs delete mode 100644 tests/ui/used_underscore_binding.stderr delete mode 100644 tests/ui/useful_asref.rs delete mode 100644 tests/ui/useless_asref.fixed delete mode 100644 tests/ui/useless_asref.rs delete mode 100644 tests/ui/useless_asref.stderr delete mode 100644 tests/ui/useless_attribute.fixed delete mode 100644 tests/ui/useless_attribute.rs delete mode 100644 tests/ui/useless_attribute.stderr delete mode 100644 tests/ui/useless_conversion.fixed delete mode 100644 tests/ui/useless_conversion.rs delete mode 100644 tests/ui/useless_conversion.stderr delete mode 100644 tests/ui/useless_conversion_try.rs delete mode 100644 tests/ui/useless_conversion_try.stderr delete mode 100644 tests/ui/vec.fixed delete mode 100644 tests/ui/vec.rs delete mode 100644 tests/ui/vec.stderr delete mode 100644 tests/ui/vec_box_sized.rs delete mode 100644 tests/ui/vec_box_sized.stderr delete mode 100644 tests/ui/vec_init_then_push.rs delete mode 100644 tests/ui/vec_init_then_push.stderr delete mode 100644 tests/ui/vec_resize_to_zero.fixed delete mode 100644 tests/ui/vec_resize_to_zero.rs delete mode 100644 tests/ui/vec_resize_to_zero.stderr delete mode 100644 tests/ui/verbose_file_reads.rs delete mode 100644 tests/ui/verbose_file_reads.stderr delete mode 100644 tests/ui/waker_clone_wake.fixed delete mode 100644 tests/ui/waker_clone_wake.rs delete mode 100644 tests/ui/waker_clone_wake.stderr delete mode 100644 tests/ui/while_let_loop.rs delete mode 100644 tests/ui/while_let_loop.stderr delete mode 100644 tests/ui/while_let_on_iterator.fixed delete mode 100644 tests/ui/while_let_on_iterator.rs delete mode 100644 tests/ui/while_let_on_iterator.stderr delete mode 100644 tests/ui/wild_in_or_pats.rs delete mode 100644 tests/ui/wild_in_or_pats.stderr delete mode 100644 tests/ui/wildcard_enum_match_arm.fixed delete mode 100644 tests/ui/wildcard_enum_match_arm.rs delete mode 100644 tests/ui/wildcard_enum_match_arm.stderr delete mode 100644 tests/ui/wildcard_imports.fixed delete mode 100644 tests/ui/wildcard_imports.rs delete mode 100644 tests/ui/wildcard_imports.stderr delete mode 100644 tests/ui/wildcard_imports_2021.edition2018.fixed delete mode 100644 tests/ui/wildcard_imports_2021.edition2018.stderr delete mode 100644 tests/ui/wildcard_imports_2021.edition2021.fixed delete mode 100644 tests/ui/wildcard_imports_2021.edition2021.stderr delete mode 100644 tests/ui/wildcard_imports_2021.rs delete mode 100644 tests/ui/wildcard_imports_cfgtest.rs delete mode 100644 tests/ui/write_literal.fixed delete mode 100644 tests/ui/write_literal.rs delete mode 100644 tests/ui/write_literal.stderr delete mode 100644 tests/ui/write_literal_2.rs delete mode 100644 tests/ui/write_literal_2.stderr delete mode 100644 tests/ui/write_with_newline.fixed delete mode 100644 tests/ui/write_with_newline.rs delete mode 100644 tests/ui/write_with_newline.stderr delete mode 100644 tests/ui/writeln_empty_string.fixed delete mode 100644 tests/ui/writeln_empty_string.rs delete mode 100644 tests/ui/writeln_empty_string.stderr delete mode 100644 tests/ui/wrong_self_convention.rs delete mode 100644 tests/ui/wrong_self_convention.stderr delete mode 100644 tests/ui/wrong_self_convention2.rs delete mode 100644 tests/ui/wrong_self_convention2.stderr delete mode 100644 tests/ui/wrong_self_conventions_mut.rs delete mode 100644 tests/ui/wrong_self_conventions_mut.stderr delete mode 100644 tests/ui/zero_div_zero.rs delete mode 100644 tests/ui/zero_div_zero.stderr delete mode 100644 tests/ui/zero_offset.rs delete mode 100644 tests/ui/zero_offset.stderr delete mode 100644 tests/ui/zero_ptr.fixed delete mode 100644 tests/ui/zero_ptr.rs delete mode 100644 tests/ui/zero_ptr.stderr delete mode 100644 tests/ui/zero_ptr_no_std.fixed delete mode 100644 tests/ui/zero_ptr_no_std.rs delete mode 100644 tests/ui/zero_ptr_no_std.stderr delete mode 100644 tests/ui/zero_repeat_side_effects.fixed delete mode 100644 tests/ui/zero_repeat_side_effects.rs delete mode 100644 tests/ui/zero_repeat_side_effects.stderr delete mode 100644 tests/ui/zero_sized_btreemap_values.rs delete mode 100644 tests/ui/zero_sized_btreemap_values.stderr delete mode 100644 tests/ui/zero_sized_hashmap_values.rs delete mode 100644 tests/ui/zero_sized_hashmap_values.stderr delete mode 100644 tests/versioncheck.rs delete mode 100644 tests/workspace.rs delete mode 100644 tests/workspace_test/Cargo.toml delete mode 100644 tests/workspace_test/build.rs delete mode 100644 tests/workspace_test/module_style/pass_mod_with_dep_in_subdir/Cargo.toml delete mode 100644 tests/workspace_test/module_style/pass_mod_with_dep_in_subdir/dep_no_mod/Cargo.toml delete mode 100644 tests/workspace_test/module_style/pass_mod_with_dep_in_subdir/dep_no_mod/src/foo.rs delete mode 100644 tests/workspace_test/module_style/pass_mod_with_dep_in_subdir/dep_no_mod/src/foo/hello.rs delete mode 100644 tests/workspace_test/module_style/pass_mod_with_dep_in_subdir/dep_no_mod/src/lib.rs delete mode 100644 tests/workspace_test/module_style/pass_mod_with_dep_in_subdir/src/bad/mod.rs delete mode 100644 tests/workspace_test/module_style/pass_mod_with_dep_in_subdir/src/main.rs delete mode 100644 tests/workspace_test/module_style/pass_mod_with_dep_in_subdir/src/more/foo.rs delete mode 100644 tests/workspace_test/module_style/pass_mod_with_dep_in_subdir/src/more/inner/mod.rs delete mode 100644 tests/workspace_test/module_style/pass_mod_with_dep_in_subdir/src/more/mod.rs delete mode 100644 tests/workspace_test/module_style/pass_no_mod_with_dep_in_subdir/Cargo.toml delete mode 100644 tests/workspace_test/module_style/pass_no_mod_with_dep_in_subdir/dep_with_mod/Cargo.toml delete mode 100644 tests/workspace_test/module_style/pass_no_mod_with_dep_in_subdir/dep_with_mod/src/lib.rs delete mode 100644 tests/workspace_test/module_style/pass_no_mod_with_dep_in_subdir/dep_with_mod/src/with_mod/inner.rs delete mode 100644 tests/workspace_test/module_style/pass_no_mod_with_dep_in_subdir/dep_with_mod/src/with_mod/inner/stuff.rs delete mode 100644 tests/workspace_test/module_style/pass_no_mod_with_dep_in_subdir/dep_with_mod/src/with_mod/inner/stuff/most.rs delete mode 100644 tests/workspace_test/module_style/pass_no_mod_with_dep_in_subdir/dep_with_mod/src/with_mod/mod.rs delete mode 100644 tests/workspace_test/module_style/pass_no_mod_with_dep_in_subdir/src/good.rs delete mode 100644 tests/workspace_test/module_style/pass_no_mod_with_dep_in_subdir/src/main.rs delete mode 100644 tests/workspace_test/path_dep/Cargo.toml delete mode 100644 tests/workspace_test/path_dep/src/lib.rs delete mode 100644 tests/workspace_test/src/main.rs delete mode 100644 tests/workspace_test/subcrate/Cargo.toml delete mode 100644 tests/workspace_test/subcrate/src/lib.rs delete mode 100644 triagebot.toml delete mode 100755 util/etc/pre-commit.sh delete mode 100644 util/etc/vscode-tasks.json delete mode 100755 util/fetch_prs_between.sh delete mode 100644 util/gh-pages/index.html delete mode 100644 util/gh-pages/script.js delete mode 100644 util/gh-pages/versions.html delete mode 100755 util/versions.py diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index 48a63e485681..000000000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,18 +0,0 @@ -[alias] -uitest = "test --test compile-test" -uibless = "test --test compile-test -- -- --bless" -bless = "test -- -- --bless" -dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --" -lintcheck = "run --package lintcheck --bin lintcheck --manifest-path lintcheck/Cargo.toml -- " -collect-metadata = "test --test dogfood --features internal -- run_metadata_collection_lint --ignored" - -[build] -# -Zbinary-dep-depinfo allows us to track which rlib files to use for compiling UI tests -rustflags = ["-Zunstable-options", "-Zbinary-dep-depinfo"] -target-dir = "target" - -[unstable] -binary-dep-depinfo = true - -[profile.dev] -split-debuginfo = "unpacked" diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index bc7642bf8c7c..000000000000 --- a/.editorconfig +++ /dev/null @@ -1,22 +0,0 @@ -# EditorConfig helps developers define and maintain consistent -# coding styles between different editors and IDEs -# editorconfig.org - -root = true - -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true -indent_style = space -indent_size = 4 -max_line_length = 120 - -[*.md] -# double whitespace at end of line -# denotes a line break in Markdown -trim_trailing_whitespace = false - -[*.yml] -indent_size = 2 diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 90cf33053c77..000000000000 --- a/.gitattributes +++ /dev/null @@ -1,3 +0,0 @@ -* text=auto eol=lf -*.rs text eol=lf whitespace=tab-in-indent,trailing-space,tabwidth=4 -*.fixed linguist-language=Rust diff --git a/.github/ISSUE_TEMPLATE/blank_issue.yml b/.github/ISSUE_TEMPLATE/blank_issue.yml deleted file mode 100644 index 89884bfc8590..000000000000 --- a/.github/ISSUE_TEMPLATE/blank_issue.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Blank Issue -description: Create a blank issue. -body: - - type: markdown - attributes: - value: Thank you for filing an issue! - - type: textarea - id: problem - attributes: - label: Description - description: > - Please provide a description of the issue, along with any information - you feel relevant to replicate it. - validations: - required: true - - type: textarea - id: version - attributes: - label: Version - description: "Rust version (`rustc -Vv`)" - placeholder: | - rustc 1.46.0-nightly (f455e46ea 2020-06-20) - binary: rustc - commit-hash: f455e46eae1a227d735091091144601b467e1565 - commit-date: 2020-06-20 - host: x86_64-unknown-linux-gnu - release: 1.46.0-nightly - LLVM version: 10.0 - render: text - - type: textarea - id: labels - attributes: - label: Additional Labels - description: > - Additional labels can be added to this issue by including the following - command - placeholder: | - @rustbot label +

Backtrace -

- - ``` - - ``` - -

-
diff --git a/.github/ISSUE_TEMPLATE/new_lint.yml b/.github/ISSUE_TEMPLATE/new_lint.yml deleted file mode 100644 index b49493edce1b..000000000000 --- a/.github/ISSUE_TEMPLATE/new_lint.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: New lint suggestion -description: Suggest a new Clippy lint. -labels: ["A-lint"] -body: - - type: markdown - attributes: - value: Thank you for your lint idea! - - type: textarea - id: what - attributes: - label: What it does - description: What does this lint do? - validations: - required: true - - type: textarea - id: advantage - attributes: - label: Advantage - description: > - What is the advantage of the recommended code over the original code? - placeholder: | - - Remove bounds check inserted by ... - - Remove the need to duplicate/store ... - - Remove typo ... - - type: textarea - id: drawbacks - attributes: - label: Drawbacks - description: What might be possible drawbacks of such a lint? - - type: textarea - id: example - attributes: - label: Example - description: > - Include a short example showing when the lint should trigger together - with the improved code. - value: | - ```rust - - ``` - - Could be written as: - - ```rust - - ``` - validations: - required: true diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 9e49f60892d2..000000000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,39 +0,0 @@ -Thank you for making Clippy better! - -We're collecting our changelog from pull request descriptions. -If your PR only includes internal changes, you can just write -`changelog: none`. Otherwise, please write a short comment -explaining your change. - -It's also helpful for us that the lint name is put within backticks (`` ` ` ``), -and then encapsulated by square brackets (`[]`), for example: -``` -changelog: [`lint_name`]: your change -``` - -If your PR fixes an issue, you can add `fixes #issue_number` into this -PR description. This way the issue will be automatically closed when -your PR is merged. - -If you added a new lint, here's a checklist for things that will be -checked during review or continuous integration. - -- \[ ] Followed [lint naming conventions][lint_naming] -- \[ ] Added passing UI tests (including committed `.stderr` file) -- \[ ] `cargo test` passes locally -- \[ ] Executed `cargo dev update_lints` -- \[ ] Added lint documentation -- \[ ] Run `cargo dev fmt` - -[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints - -Note that you can skip the above if you are just opening a WIP PR in -order to get feedback. - -Delete this line and everything above before opening your PR. - ---- - -*Please write a short comment explaining your change (or "none" for internal only changes)* - -changelog: diff --git a/.github/deploy.sh b/.github/deploy.sh deleted file mode 100644 index 5a59f94ec918..000000000000 --- a/.github/deploy.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash - -set -ex - -echo "Removing the current docs for master" -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 - echo "Save the doc for the current tag ($TAG_NAME) and point stable/ to it" - cp -Tr out/master "out/$TAG_NAME" - rm -f out/stable - ln -s "$TAG_NAME" out/stable -fi - -if [[ $BETA = "true" ]]; then - echo "Update documentation for the beta release" - cp -r out/master/* out/beta -fi - -# Generate version index that is shown as root index page -cp util/gh-pages/versions.html out/index.html - -echo "Making the versions.json file" -python3 ./util/versions.py out - -# Now let's go have some fun with the cloned repo -cd out -git config user.name "GHA CI" -git config user.email "gha@ci.invalid" - -if [[ -n $TAG_NAME ]]; then - # track files, so that the following check works - git add --intent-to-add "$TAG_NAME" - if git diff --exit-code --quiet -- $TAG_NAME/; then - echo "No changes to the output on this push; exiting." - exit 0 - fi - # Add the new dir - git add "$TAG_NAME" - # Update the symlink - git add stable - # Update versions file - git add versions.json - git commit -m "Add documentation for ${TAG_NAME} release: ${SHA}" -elif [[ $BETA = "true" ]]; then - if git diff --exit-code --quiet -- beta/; then - echo "No changes to the output on this push; exiting." - exit 0 - fi - git add beta - git commit -m "Automatic deploy to GitHub Pages (beta): ${SHA}" -else - if git diff --exit-code --quiet; then - echo "No changes to the output on this push; exiting." - exit 0 - fi - git add . - git commit -m "Automatic deploy to GitHub Pages: ${SHA}" -fi - -git push "$SSH_REPO" "$TARGET_BRANCH" diff --git a/.github/driver.sh b/.github/driver.sh deleted file mode 100755 index 2eafdd0fbc87..000000000000 --- a/.github/driver.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -set -ex - -# Check sysroot handling -sysroot=$(./target/debug/clippy-driver --print sysroot) -test "$sysroot" = "$(rustc --print sysroot)" - -if [[ ${OS} == "Windows" ]]; then - desired_sysroot=C:/tmp -else - desired_sysroot=/tmp -fi -# Set --sysroot in command line -sysroot=$(./target/debug/clippy-driver --sysroot $desired_sysroot --print sysroot) -test "$sysroot" = $desired_sysroot - -# Set --sysroot in arg_file.txt and pass @arg_file.txt to command line -echo "--sysroot=$desired_sysroot" > arg_file.txt -sysroot=$(./target/debug/clippy-driver @arg_file.txt --print sysroot) -test "$sysroot" = $desired_sysroot - -# Setting SYSROOT in command line -sysroot=$(SYSROOT=$desired_sysroot ./target/debug/clippy-driver --print sysroot) -test "$sysroot" = $desired_sysroot - -# Check that the --sysroot argument is only passed once (SYSROOT is ignored) -( - cd rustc_tools_util - touch src/lib.rs - SYSROOT=/tmp RUSTFLAGS="--sysroot=$(rustc --print sysroot)" ../target/debug/cargo-clippy clippy --verbose -) - -# Check that the --sysroot argument is only passed once via arg_file.txt (SYSROOT is ignored) -( - echo "fn main() {}" > target/driver_test.rs - echo "--sysroot="$(./target/debug/clippy-driver --print sysroot)"" > arg_file.txt - echo "--verbose" >> arg_file.txt - SYSROOT=/tmp ./target/debug/clippy-driver @arg_file.txt ./target/driver_test.rs -) - -# Make sure this isn't set - clippy-driver should cope without it -unset CARGO_MANIFEST_DIR - -# Run a lint and make sure it produces the expected output. It's also expected to exit with code 1 -# FIXME: How to match the clippy invocation in compile-test.rs? -./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/double_neg.rs 2>double_neg.stderr && exit 1 -sed -e "/= help: for/d" double_neg.stderr > normalized.stderr -diff -u normalized.stderr tests/ui/double_neg.stderr - -# make sure "clippy-driver --rustc --arg" and "rustc --arg" behave the same -SYSROOT=$(rustc --print sysroot) -diff -u <(./target/debug/clippy-driver --rustc --version --verbose) <(rustc --version --verbose) - -echo "fn main() {}" >target/driver_test.rs -# we can't run 2 rustcs on the same file at the same time -CLIPPY=$(./target/debug/clippy-driver ./target/driver_test.rs --rustc) -RUSTC=$(rustc ./target/driver_test.rs) -diff -u <($CLIPPY) <($RUSTC) - -# TODO: CLIPPY_CONF_DIR / CARGO_MANIFEST_DIR diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml deleted file mode 100644 index 8179e3e65b54..000000000000 --- a/.github/workflows/clippy.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: Clippy Test - -on: - push: - # Ignore bors branches, since they are covered by `clippy_bors.yml` - branches-ignore: - - auto - - try - # Don't run Clippy tests, when only text files were modified - paths-ignore: - - 'COPYRIGHT' - - 'LICENSE-*' - - '**.md' - - '**.txt' - pull_request: - # Don't run Clippy tests, when only text files were modified - paths-ignore: - - 'COPYRIGHT' - - 'LICENSE-*' - - '**.md' - - '**.txt' - -env: - RUST_BACKTRACE: 1 - CARGO_TARGET_DIR: '${{ github.workspace }}/target' - NO_FMT_TEST: 1 - CARGO_INCREMENTAL: 0 - -concurrency: - # For a given workflow, if we push to the same PR, cancel all previous builds on that PR. - # If the push is not attached to a PR, we will cancel all builds on the same branch. - group: "${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}" - cancel-in-progress: true - -jobs: - base: - # NOTE: If you modify this job, make sure you copy the changes to clippy_bors.yml - runs-on: ubuntu-latest - - steps: - # Setup - - name: Checkout - uses: actions/checkout@v4 - - - name: Install toolchain - run: rustup show active-toolchain - - # Run - - name: Build - run: cargo build --tests --features deny-warnings,internal - - - name: Test - run: cargo test --features deny-warnings,internal - - - name: Test clippy_lints - run: cargo test --features deny-warnings,internal - working-directory: clippy_lints - - - name: Test clippy_utils - run: cargo test --features deny-warnings - working-directory: clippy_utils - - - name: Test rustc_tools_util - run: cargo test --features deny-warnings - working-directory: rustc_tools_util - - - name: Test clippy_dev - run: cargo test --features deny-warnings - working-directory: clippy_dev - - - name: Test clippy-driver - run: | - TOOLCHAIN=$(rustup show active-toolchain | cut -f1 -d' ') - rustup run $TOOLCHAIN bash .github/driver.sh diff --git a/.github/workflows/clippy_bors.yml b/.github/workflows/clippy_bors.yml deleted file mode 100644 index 94515987eba4..000000000000 --- a/.github/workflows/clippy_bors.yml +++ /dev/null @@ -1,251 +0,0 @@ -name: Clippy Test (bors) - -on: - push: - branches: - - auto - - try - -env: - RUST_BACKTRACE: 1 - CARGO_TARGET_DIR: '${{ github.workspace }}/target' - NO_FMT_TEST: 1 - CARGO_INCREMENTAL: 0 - -concurrency: - # For a given workflow, if we push to the same branch, cancel all previous builds on that branch. - group: "${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}" - cancel-in-progress: true - -defaults: - run: - shell: bash - -jobs: - changelog: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - ref: ${{ github.ref }} - - # Run - - name: Check Changelog - run: | - MESSAGE=$(git log --format=%B -n 1) - PR=$(echo "$MESSAGE" | grep -o "#[0-9]*" | head -1 | sed -e 's/^#//') - body=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -s "https://api.github.com/repos/rust-lang/rust-clippy/pulls/$PR" | \ - python -c "import sys, json; print(json.load(sys.stdin)['body'])") - output=$(grep "^changelog:\s*\S" <<< "$body" | sed "s/changelog:\s*//g") || { - echo "ERROR: PR body must contain 'changelog: ...'" - exit 1 - } - if [[ "$output" = "none" ]]; then - echo "WARNING: changelog is 'none'" - else - echo "changelog: $output" - fi - env: - PYTHONIOENCODING: 'utf-8' - base: - needs: changelog - strategy: - matrix: - include: - - os: ubuntu-latest - host: x86_64-unknown-linux-gnu - - os: ubuntu-latest - host: i686-unknown-linux-gnu - - os: windows-latest - host: x86_64-pc-windows-msvc - - os: macos-13 - host: x86_64-apple-darwin - - runs-on: ${{ matrix.os }} - - # NOTE: If you modify this job, make sure you copy the changes to clippy.yml - steps: - # Setup - - name: Checkout - uses: actions/checkout@v4 - - - name: Install i686 dependencies - if: matrix.host == 'i686-unknown-linux-gnu' - run: | - sudo dpkg --add-architecture i386 - sudo apt-get update - sudo apt-get install gcc-multilib zlib1g-dev:i386 - - - name: Install toolchain - run: | - rustup set default-host ${{ matrix.host }} - rustup show active-toolchain - - # Run - - name: Build - run: cargo build --tests --features deny-warnings,internal - - - name: Test - if: matrix.host == 'x86_64-unknown-linux-gnu' - run: cargo test --features deny-warnings,internal - - - name: Test - if: matrix.host != 'x86_64-unknown-linux-gnu' - run: cargo test --features deny-warnings,internal -- --skip dogfood - - - name: Test clippy_lints - run: cargo test --features deny-warnings,internal - working-directory: clippy_lints - - - name: Test clippy_utils - run: cargo test --features deny-warnings - working-directory: clippy_utils - - - name: Test clippy_config - run: cargo test --features deny-warnings - working-directory: clippy_config - - - name: Test rustc_tools_util - run: cargo test --features deny-warnings - working-directory: rustc_tools_util - - - name: Test clippy_dev - run: cargo test --features deny-warnings - working-directory: clippy_dev - - - name: Test clippy-driver - run: | - TOOLCHAIN=$(rustup show active-toolchain | cut -f1 -d' ') - rustup run $TOOLCHAIN bash .github/driver.sh - env: - OS: ${{ runner.os }} - - metadata_collection: - needs: changelog - runs-on: ubuntu-latest - - steps: - # Setup - - name: Checkout - uses: actions/checkout@v4 - - - name: Install toolchain - run: rustup show active-toolchain - - - name: Test metadata collection - run: cargo collect-metadata - - - name: Test lint_configuration.md is up-to-date - run: | - echo "run \`cargo collect-metadata\` if this fails" - git update-index --refresh - - integration_build: - needs: changelog - runs-on: ubuntu-latest - - steps: - # Setup - - name: Checkout - uses: actions/checkout@v4 - - - name: Install toolchain - run: rustup show active-toolchain - - # Run - - name: Build Integration Test - env: - CARGO_PROFILE_DEV_SPLIT_DEBUGINFO: off - run: cargo test --test integration --features integration --no-run - - # Upload - - name: Extract Binaries - run: | - DIR=$CARGO_TARGET_DIR/debug - find $DIR/deps/integration-* -executable ! -type d | xargs -I {} mv {} $DIR/integration - find $DIR ! -executable -o -type d ! -path $DIR | xargs rm -rf - - - name: Upload Binaries - uses: actions/upload-artifact@v3 - with: - name: binaries - path: target/debug - - integration: - needs: integration_build - strategy: - fail-fast: false - max-parallel: 6 - matrix: - integration: - - 'matthiaskrgr/clippy_ci_panic_test' - - 'rust-lang/cargo' - - 'rust-lang/chalk' - - 'rust-lang/rustfmt' - - 'Marwes/combine' - - 'Geal/nom' - - 'rust-lang/stdarch' - - 'serde-rs/serde' - - 'chronotope/chrono' - - 'hyperium/hyper' - - 'rust-random/rand' - - 'rust-lang/futures-rs' - - 'rust-itertools/itertools' - - 'rust-lang-nursery/failure' - - 'rust-lang/log' - - runs-on: ubuntu-latest - - steps: - # Setup - - name: Checkout - uses: actions/checkout@v4 - - - name: Install toolchain - run: rustup show active-toolchain - - # Download - - name: Download target dir - uses: actions/download-artifact@v3 - with: - name: binaries - path: target/debug - - - name: Make Binaries Executable - run: chmod +x $CARGO_TARGET_DIR/debug/* - - # Run - - name: Test ${{ matrix.integration }} - run: | - TOOLCHAIN=$(rustup show active-toolchain | cut -f1 -d' ') - rustup run $TOOLCHAIN $CARGO_TARGET_DIR/debug/integration --show-output - env: - INTEGRATION: ${{ matrix.integration }} - - # These jobs doesn't actually test anything, but they're only used to tell - # bors the build completed, as there is no practical way to detect when a - # workflow is successful listening to webhooks only. - # - # ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB! - - end-success: - name: bors test finished - if: github.event.pusher.name == 'bors' && success() - runs-on: ubuntu-latest - needs: [changelog, base, metadata_collection, integration_build, integration] - - steps: - - name: Mark the job as successful - run: exit 0 - - end-failure: - name: bors test finished - if: github.event.pusher.name == 'bors' && (failure() || cancelled()) - runs-on: ubuntu-latest - needs: [changelog, base, metadata_collection, integration_build, integration] - - steps: - - name: Mark the job as a failure - run: exit 1 diff --git a/.github/workflows/clippy_dev.yml b/.github/workflows/clippy_dev.yml deleted file mode 100644 index 37f18a4c0874..000000000000 --- a/.github/workflows/clippy_dev.yml +++ /dev/null @@ -1,71 +0,0 @@ -name: Clippy Dev Test - -on: - push: - branches: - - auto - - try - pull_request: - # Only run on paths, that get checked by the clippy_dev tool - paths: - - 'CHANGELOG.md' - - 'README.md' - - '**.stderr' - - '**.rs' - -env: - RUST_BACKTRACE: 1 - CARGO_INCREMENTAL: 0 - -jobs: - clippy_dev: - runs-on: ubuntu-latest - - steps: - # Setup - - name: Checkout - uses: actions/checkout@v4 - - # Run - - name: Build - run: cargo build --features deny-warnings - working-directory: clippy_dev - - - name: Test update_lints - run: cargo dev update_lints --check - - - name: Test fmt - run: cargo dev fmt --check - - - name: Test cargo dev new lint - run: | - cargo dev new_lint --name new_early_pass --pass early - cargo dev new_lint --name new_late_pass --pass late - cargo check - git reset --hard HEAD - - # These jobs doesn't actually test anything, but they're only used to tell - # bors the build completed, as there is no practical way to detect when a - # workflow is successful listening to webhooks only. - # - # ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB! - - end-success: - name: bors dev test finished - if: github.event.pusher.name == 'bors' && success() - runs-on: ubuntu-latest - needs: [clippy_dev] - - steps: - - name: Mark the job as successful - run: exit 0 - - end-failure: - name: bors dev test finished - if: github.event.pusher.name == 'bors' && (failure() || cancelled()) - runs-on: ubuntu-latest - needs: [clippy_dev] - - steps: - - name: Mark the job as a failure - run: exit 1 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 94f494b65c47..000000000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: Deploy - -on: - push: - branches: - - master - - beta - tags: - - rust-1.** - -env: - TARGET_BRANCH: 'gh-pages' - SHA: '${{ github.sha }}' - SSH_REPO: 'git@github.com:${{ github.repository }}.git' - -jobs: - deploy: - runs-on: ubuntu-latest - if: github.repository == 'rust-lang/rust-clippy' - - steps: - # Setup - - name: Checkout - uses: actions/checkout@v4 - - - name: Checkout - uses: actions/checkout@v4 - with: - ref: ${{ env.TARGET_BRANCH }} - path: 'out' - - # Run - - name: Set tag name - if: startswith(github.ref, 'refs/tags/') - run: | - TAG=$(basename ${{ github.ref }}) - echo "TAG_NAME=$TAG" >> $GITHUB_ENV - - name: Set beta to true - if: github.ref == 'refs/heads/beta' - run: echo "BETA=true" >> $GITHUB_ENV - - # We need to check out all files that (transitively) depend on the - # structure of the gh-pages branch, so that we're able to change that - # structure without breaking the deployment. - - name: Use deploy files from master branch - run: | - git fetch --no-tags --prune --depth=1 origin master - git checkout origin/master -- .github/deploy.sh util/versions.py util/gh-pages/versions.html - - # Generate lockfile for caching to avoid build problems with cached deps - - name: cargo generate-lockfile - run: cargo generate-lockfile - - - name: Cache - uses: Swatinem/rust-cache@v2.7.0 - with: - save-if: ${{ github.ref == 'refs/heads/master' }} - - - name: cargo collect-metadata - run: cargo collect-metadata - - - name: Deploy - run: | - eval "$(ssh-agent -s)" - ssh-add - <<< "${{ secrets.DEPLOY_KEY }}" - bash .github/deploy.sh diff --git a/.github/workflows/remark.yml b/.github/workflows/remark.yml deleted file mode 100644 index 348d52020fd2..000000000000 --- a/.github/workflows/remark.yml +++ /dev/null @@ -1,72 +0,0 @@ -name: Remark - -on: - push: - branches: - - auto - - try - pull_request: - paths: - - '**.md' - -jobs: - remark: - runs-on: ubuntu-latest - - steps: - # Setup - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: '18.x' - - - name: Install remark - run: npm install remark-cli remark-lint remark-lint-maximum-line-length@^3.1.3 remark-preset-lint-recommended remark-gfm - - - name: Install mdbook - run: | - mkdir mdbook - curl -Lf https://github.com/rust-lang/mdBook/releases/download/v0.4.34/mdbook-v0.4.34-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook - echo `pwd`/mdbook >> $GITHUB_PATH - - # Run - - name: Check *.md files - run: ./node_modules/.bin/remark -u lint -f . - - - 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 - - # These jobs doesn't actually test anything, but they're only used to tell - # bors the build completed, as there is no practical way to detect when a - # workflow is successful listening to webhooks only. - # - # ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB! - - end-success: - name: bors remark test finished - if: github.event.pusher.name == 'bors' && success() - runs-on: ubuntu-latest - needs: [remark] - - steps: - - name: Mark the job as successful - run: exit 0 - - end-failure: - name: bors remark test finished - if: github.event.pusher.name == 'bors' && (failure() || cancelled()) - runs-on: ubuntu-latest - needs: [remark] - - steps: - - name: Mark the job as a failure - run: exit 1 diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 181b71a658b9..000000000000 --- a/.gitignore +++ /dev/null @@ -1,47 +0,0 @@ -# Generated by ui-test -rustc-ice-* - -# Used by CI to be able to push: -/.github/deploy_key -out - -# Compiled files -*.o -*.d -*.so -*.rlib -*.dll -*.pyc -*.rmeta - -# Executables -*.exe - -# Generated by Cargo -*Cargo.lock -/target -/clippy_lints/target -/clippy_utils/target -/clippy_dev/target -/lintcheck/target -/rustc_tools_util/target - -# Generated by dogfood -/target_recur/ - -# Generated by lintcheck -/lintcheck-logs - -# gh pages docs -util/gh-pages/lints.json - -# rustfmt backups -*.rs.bk - -helper.txt -*.iml -.vscode -.idea - -# mdbook generated output -/book/book diff --git a/.remarkrc b/.remarkrc deleted file mode 100644 index 04b82b8cc581..000000000000 --- a/.remarkrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "plugins": [ - "remark-preset-lint-recommended", - "remark-gfm", - ["remark-lint-list-item-indent", false], - ["remark-lint-no-literal-urls", false], - ["remark-lint-no-shortcut-reference-link", false], - ["remark-lint-maximum-line-length", 120] - ], - "settings": { - "commonmark": true - } -} diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index cfff0bb50a6a..000000000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,6010 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. -See [Changelog Update](book/src/development/infrastructure/changelog_update.md) if you want to update this -document. - -## Unreleased / Beta / In Rust Nightly - -[93f0a9a9...master](https://github.com/rust-lang/rust-clippy/compare/93f0a9a9...master) - -## Rust 1.78 - -Current stable, released 2024-05-02 - -[View all 112 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2024-01-26T05%3A46%3A23Z..2024-03-07T16%3A25%3A52Z+base%3Amaster) - -### New Lints - -* [`assigning_clones`] - [#12077](https://github.com/rust-lang/rust-clippy/pull/12077) -* [`mixed_attributes_style`] - [#12354](https://github.com/rust-lang/rust-clippy/pull/12354) -* [`empty_docs`] - [#12342](https://github.com/rust-lang/rust-clippy/pull/12342) -* [`unnecessary_get_then_check`] - [#12339](https://github.com/rust-lang/rust-clippy/pull/12339) -* [`multiple_bound_locations`] - [#12259](https://github.com/rust-lang/rust-clippy/pull/12259) -* [`unnecessary_clippy_cfg`] - [#12303](https://github.com/rust-lang/rust-clippy/pull/12303) -* [`deprecated_clippy_cfg_attr`] - [#12292](https://github.com/rust-lang/rust-clippy/pull/12292) -* [`manual_c_str_literals`] - [#11919](https://github.com/rust-lang/rust-clippy/pull/11919) -* [`ref_as_ptr`] - [#12087](https://github.com/rust-lang/rust-clippy/pull/12087) -* [`lint_groups_priority`] - [#11832](https://github.com/rust-lang/rust-clippy/pull/11832) -* [`unnecessary_result_map_or_else`] - [#12169](https://github.com/rust-lang/rust-clippy/pull/12169) -* [`to_string_trait_impl`] - [#12122](https://github.com/rust-lang/rust-clippy/pull/12122) -* [`incompatible_msrv`] - [#12160](https://github.com/rust-lang/rust-clippy/pull/12160) - -### Enhancements - -* [`thread_local_initializer_can_be_made_const`]: Now checks the [`msrv`] configuration - [#12405](https://github.com/rust-lang/rust-clippy/pull/12405) -* [`disallowed_macros`]: Code generated by derive macros can no longer allow this lint - [#12267](https://github.com/rust-lang/rust-clippy/pull/12267) -* [`wildcard_imports`]: Add configuration [`allowed-wildcard-imports`] to allow preconfigured wildcards - [#11979](https://github.com/rust-lang/rust-clippy/pull/11979) - -### ICE Fixes - -* [`ptr_as_ptr`]: No longer ICEs when the cast source is a function call to a local variable - [#12617](https://github.com/rust-lang/rust-clippy/pull/12617) -* [`cast_sign_loss`]: Avoids an infinite loop when casting two chained `.unwrap()` calls - [#12508](https://github.com/rust-lang/rust-clippy/pull/12508) - -## Rust 1.77 - -Released 2024-03-18 - -[View all 93 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-12-16T18%3A20%3A00Z..2024-01-25T18%3A15%3A56Z+base%3Amaster) - -### New Lints - -* [`suspicious_open_options`] - [#11608](https://github.com/rust-lang/rust-clippy/pull/11608) -* [`option_as_ref_cloned`] - [#12051](https://github.com/rust-lang/rust-clippy/pull/12051) -* [`thread_local_initializer_can_be_made_const`] - [#12026](https://github.com/rust-lang/rust-clippy/pull/12026) -* [`str_split_at_newline`] - [#11987](https://github.com/rust-lang/rust-clippy/pull/11987) -* [`empty_enum_variants_with_brackets`] - [#12047](https://github.com/rust-lang/rust-clippy/pull/12047) -* [`manual_is_variant_and`] - [#11865](https://github.com/rust-lang/rust-clippy/pull/11865) -* [`pub_underscore_fields`] - [#10283](https://github.com/rust-lang/rust-clippy/pull/10283) -* [`eager_transmute`] - [#11981](https://github.com/rust-lang/rust-clippy/pull/11981) -* [`iter_filter_is_some`] - [#12004](https://github.com/rust-lang/rust/pull/12004) -* [`iter_filter_is_ok`] - [#12004](https://github.com/rust-lang/rust/pull/12004) -* [`result_filter_map`] - [#11869](https://github.com/rust-lang/rust-clippy/pull/11869) -* [`unconditional_recursion`] - [#11938](https://github.com/rust-lang/rust-clippy/pull/11938) - -### Enhancements - -* [`multiple_crate_versions`]: Added the [`allowed-duplicate-crates`] configuration to allow specific crates - [#12179](https://github.com/rust-lang/rust-clippy/pull/12179) -* [`single_call_fn`]: No longer ignores `#[allow]` attributes - [#12183](https://github.com/rust-lang/rust-clippy/pull/12183) -* [`read_zero_byte_vec`]: Updated the heuristics used for linting - [#11766](https://github.com/rust-lang/rust-clippy/pull/11766) - -### ICE Fixes - -* [`unit_arg`]: No longer crashes when checking for const in nested bodies - [#11977](https://github.com/rust-lang/rust-clippy/pull/11977) -* [`indexing_slicing`]: No longer crashes when the array index exceeds `usize` - [#12266](https://github.com/rust-lang/rust-clippy/pull/12266) - -### Others - -* Warnings about invalid fields inside `clippy.toml` files now include suggestions for existing fields - [#12180](https://github.com/rust-lang/rust-clippy/pull/12180) - -## Rust 1.76 - -Released 2024-02-08 - -[View all 85 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-11-02T20%3A23%3A40Z..2023-12-16T13%3A11%3A08Z+base%3Amaster) - -### New Lints - -- [`infinite_loop`] - [#11829](https://github.com/rust-lang/rust-clippy/pull/11829) -- [`ineffective_open_options`] - [#11902](https://github.com/rust-lang/rust-clippy/pull/11902) -- [`uninhabited_references`] - [#11878](https://github.com/rust-lang/rust-clippy/pull/11878) -- [`repeat_vec_with_capacity`] - [#11597](https://github.com/rust-lang/rust-clippy/pull/11597) -- [`test_attr_in_doctest`] - [#11872](https://github.com/rust-lang/rust-clippy/pull/11872) -- [`option_map_or_err_ok`] - [#11864](https://github.com/rust-lang/rust-clippy/pull/11864) -- [`join_absolute_paths`] - [#11453](https://github.com/rust-lang/rust-clippy/pull/11453) -- [`impl_hash_borrow_with_str_and_bytes`] - [#11781](https://github.com/rust-lang/rust-clippy/pull/11781) -- [`iter_over_hash_type`] - [#11791](https://github.com/rust-lang/rust-clippy/pull/11791) - -### Moves and Deprecations - -- Renamed `blocks_in_if_conditions` to [`blocks_in_conditions`] - [#11853](https://github.com/rust-lang/rust-clippy/pull/11853) -- Moved [`implied_bounds_in_impls`] to `complexity` (Now warn-by-default) - [#11867](https://github.com/rust-lang/rust-clippy/pull/11867) -- Moved [`if_same_then_else`] to `style` (Now warn-by-default) - [#11809](https://github.com/rust-lang/rust-clippy/pull/11809) - -### Enhancements - -- [`missing_safety_doc`], [`unnecessary_safety_doc`], [`missing_panics_doc`], [`missing_errors_doc`]: - Added the [`check-private-items`] configuration to enable lints on private items - [#11842](https://github.com/rust-lang/rust-clippy/pull/11842) - -### ICE Fixes - -- [`impl_trait_in_params`]: No longer crashes when a function has generics but no function parameters - [#11804](https://github.com/rust-lang/rust-clippy/pull/11804) -- [`unused_enumerate_index`]: No longer crashes on empty tuples - [#11756](https://github.com/rust-lang/rust-clippy/pull/11756) - -### Others - -- Clippy now respects the `CARGO` environment value - [#11944](https://github.com/rust-lang/rust-clippy/pull/11944) - -## Rust 1.75 - -Released 2023-12-28 - -[View all 69 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-09-25T11%3A47%3A47Z..2023-11-02T16%3A41%3A59Z+base%3Amaster) - -### New Lints - -* [`unused_enumerate_index`] - [#10404](https://github.com/rust-lang/rust-clippy/pull/10404) -* [`unnecessary_fallible_conversions`] - [#11669](https://github.com/rust-lang/rust-clippy/pull/11669) -* [`waker_clone_wake`] - [#11698](https://github.com/rust-lang/rust-clippy/pull/11698) -* [`struct_field_names`] - [#11496](https://github.com/rust-lang/rust-clippy/pull/11496) -* [`into_iter_without_iter`] - [#11587](https://github.com/rust-lang/rust-clippy/pull/11587) -* [`iter_without_into_iter`] - [#11527](https://github.com/rust-lang/rust-clippy/pull/11527) -* [`manual_hash_one`] - [#11556](https://github.com/rust-lang/rust-clippy/pull/11556) - - -### Moves and Deprecations - -* Moved [`read_zero_byte_vec`] to `nursery` (Now allow-by-default) - [#11727](https://github.com/rust-lang/rust-clippy/pull/11727) -* Moved [`missing_enforced_import_renames`] to `style` (Now warn-by-default) - [#11539](https://github.com/rust-lang/rust-clippy/pull/11539) -* Moved [`needless_raw_string_hashes`] to `pedantic` (Now allow-by-default) - [#11415](https://github.com/rust-lang/rust-clippy/pull/11415) -* Moved [`needless_pass_by_ref_mut`] to `nursery` (Now allow-by-default) - [#11596](https://github.com/rust-lang/rust-clippy/pull/11596) - -### Enhancements - -* [`declare_interior_mutable_const`] and [`borrow_interior_mutable_const`]: Now check the - [`ignore-interior-mutability`] config value - [#11678](https://github.com/rust-lang/rust-clippy/pull/11678) - -### Suggestion Fixes/Improvements - -* [`items_after_test_module`]: The suggestion is now machine-applicable - [#11611](https://github.com/rust-lang/rust-clippy/pull/11611) - -### ICE Fixes - -* [`redundant_locals`]: No longer crashes if variables are rebound above macros - [#11623](https://github.com/rust-lang/rust-clippy/pull/11623) -* [`implicit_hasher`]: No longer lints inside macros, which could cause ICEs - [#11593](https://github.com/rust-lang/rust-clippy/pull/11593) - -### Documentation Improvements - -* `cargo clippy --help` now uses colors for readability :tada: - -## Rust 1.74 - -Released 2023-11-16 - -[View all 94 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-08-11T15%3A29%3A18Z..2023-09-25T08%3A48%3A22Z+base%3Amaster) - -### New Lints - -* [`redundant_as_str`] - [#11526](https://github.com/rust-lang/rust-clippy/pull/11526) -* [`needless_borrows_for_generic_args`] - [#11511](https://github.com/rust-lang/rust-clippy/pull/11511) -* [`path_ends_with_ext`] - [#11483](https://github.com/rust-lang/rust-clippy/pull/11483) -* [`unnecessary_map_on_constructor`] - [#11413](https://github.com/rust-lang/rust-clippy/pull/11413) -* [`missing_asserts_for_indexing`] - [#10692](https://github.com/rust-lang/rust-clippy/pull/10692) -* [`iter_out_of_bounds`] - [#11396](https://github.com/rust-lang/rust-clippy/pull/11396) -* [`implied_bounds_in_impls`] - [#11362](https://github.com/rust-lang/rust-clippy/pull/11362) -* [`reserve_after_initialization`] - [#11373](https://github.com/rust-lang/rust-clippy/pull/11373) -* [`should_panic_without_expect`] - [#11204](https://github.com/rust-lang/rust-clippy/pull/11204) - -### Moves and Deprecations - -* Renamed `incorrect_clone_impl_on_copy_type` to [`non_canonical_clone_impl`] - [#11358](https://github.com/rust-lang/rust-clippy/pull/11358) -* Renamed `incorrect_partial_ord_impl_on_ord_type` to [`non_canonical_partial_ord_impl`] - [#11358](https://github.com/rust-lang/rust-clippy/pull/11358) -* Moved [`non_canonical_clone_impl`] to `suspicious` (Now warn-by-default) - [#11358](https://github.com/rust-lang/rust-clippy/pull/11358) -* Moved [`non_canonical_partial_ord_impl`] to `suspicious` (Now warn-by-default) - [#11358](https://github.com/rust-lang/rust-clippy/pull/11358) -* Moved [`needless_pass_by_ref_mut`] to `nursery` (Now allow-by-default) - [#11596](https://github.com/rust-lang/rust-clippy/pull/11596) - -### Enhancements - -* [`undocumented_unsafe_blocks`]: The config values [`accept-comment-above-statement`] and - [`accept-comment-above-attributes`] are now `true` by default - [#11170](https://github.com/rust-lang/rust-clippy/pull/11170) -* [`explicit_iter_loop`]: Added [`enforce-iter-loop-reborrow`] to disable reborrow linting by default - [#11418](https://github.com/rust-lang/rust-clippy/pull/11418) - -### ICE Fixes - -* [`enum_variant_names`]: No longer crashes if the threshold is 0 and the enum has no variants - [#11552](https://github.com/rust-lang/rust-clippy/pull/11552) -* [`cast_possible_truncation`]: No longer crashes on values larger than `u64::MAX` - [#11517](https://github.com/rust-lang/rust-clippy/pull/11517) -* [`tuple_array_conversions`]: No longer crashes if the array length is not usize - [#11379](https://github.com/rust-lang/rust-clippy/pull/11379) -* [`useless_conversion`]: No longer crashes, when the receiver is a non-fn item - [#11070](https://github.com/rust-lang/rust-clippy/pull/11070) - -## Rust 1.73 - -Released 2023-10-05 - -[View all 103 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-07-02T12%3A24%3A40Z..2023-08-11T11%3A09%3A56Z+base%3Amaster) - -### New Lints - -* [`impossible_comparisons`] - [#10843](https://github.com/rust-lang/rust-clippy/pull/10843) -* [`redundant_comparisons`] - [#10843](https://github.com/rust-lang/rust-clippy/pull/10843) -* [`ignored_unit_patterns`] - [#11242](https://github.com/rust-lang/rust-clippy/pull/11242) -* [`readonly_write_lock`] - [#11210](https://github.com/rust-lang/rust-clippy/pull/11210) -* [`filter_map_bool_then`] - [#11115](https://github.com/rust-lang/rust-clippy/pull/11115) -* [`needless_return_with_question_mark`] - [#11031](https://github.com/rust-lang/rust-clippy/pull/11031) -* [`redundant_guards`] - [#10955](https://github.com/rust-lang/rust-clippy/pull/10955) -* [`redundant_locals`] - [#10885](https://github.com/rust-lang/rust-clippy/pull/10885) -* [`absolute_paths`] - [#11003](https://github.com/rust-lang/rust-clippy/pull/11003) -* [`error_impl_error`] - [#11107](https://github.com/rust-lang/rust-clippy/pull/11107) -* [`iter_skip_zero`] - [#11046](https://github.com/rust-lang/rust-clippy/pull/11046) -* [`string_lit_chars_any`] - [#11052](https://github.com/rust-lang/rust-clippy/pull/11052) -* [`four_forward_slashes`] - [#11140](https://github.com/rust-lang/rust-clippy/pull/11140) -* [`format_collect`] - [#11116](https://github.com/rust-lang/rust-clippy/pull/11116) -* [`needless_pass_by_ref_mut`] - [#10900](https://github.com/rust-lang/rust-clippy/pull/10900) -* [`manual_is_infinite`] - [#11049](https://github.com/rust-lang/rust-clippy/pull/11049) -* [`manual_is_finite`] - [#11049](https://github.com/rust-lang/rust-clippy/pull/11049) -* [`incorrect_partial_ord_impl_on_ord_type`] - [#10788](https://github.com/rust-lang/rust-clippy/pull/10788) -* [`read_line_without_trim`] - [#10970](https://github.com/rust-lang/rust-clippy/pull/10970) -* [`type_id_on_box`] - [#10987](https://github.com/rust-lang/rust-clippy/pull/10987) - -### Moves and Deprecations - -* Renamed `unwrap_or_else_default` to [`unwrap_or_default`] - [#10120](https://github.com/rust-lang/rust-clippy/pull/10120) -* Moved [`tuple_array_conversions`] to `pedantic` (Now allow-by-default) - [#11146](https://github.com/rust-lang/rust-clippy/pull/11146) -* Moved [`arc_with_non_send_sync`] to `suspicious` (Now warn-by-default) - [#11104](https://github.com/rust-lang/rust-clippy/pull/11104) -* Moved [`needless_raw_string_hashes`] to `pedantic` (Now allow-by-default) - [#11415](https://github.com/rust-lang/rust-clippy/pull/11415) - -### Enhancements - -* [`unwrap_used`]: No longer lints on the never-type or never-like enums - [#11252](https://github.com/rust-lang/rust-clippy/pull/11252) -* [`expect_used`]: No longer lints on the never-type or never-like enums - [#11252](https://github.com/rust-lang/rust-clippy/pull/11252) - -### False Positive Fixes - -* [`panic_in_result_fn`]: No longer triggers on `todo!`, `unimplemented!`, `unreachable!` - [#11123](https://github.com/rust-lang/rust-clippy/pull/11123) - -### Suggestion Fixes/Improvements - -* [`semicolon_if_nothing_returned`]: The suggestion is now machine-applicable with rustfix - [#11083](https://github.com/rust-lang/rust-clippy/pull/11083) - -### ICE Fixes - -* [`filter_map_bool_then`]: No longer crashes on late-bound regions - [#11318](https://github.com/rust-lang/rust-clippy/pull/11318) -* [`unwrap_or_default`]: No longer crashes on alias types for local items - [#11258](https://github.com/rust-lang/rust-clippy/pull/11258) -* [`unnecessary_literal_unwrap`]: No longer crashes on `None.unwrap_or_default()` - [#11106](https://github.com/rust-lang/rust-clippy/pull/11106) -* Fixed MIR-related ICE - [#11130](https://github.com/rust-lang/rust-clippy/pull/11130) -* [`missing_fields_in_debug`]: No longer crashes on non-ADT self types - [#11069](https://github.com/rust-lang/rust-clippy/pull/11069) - -## Rust 1.72 - -Released 2023-08-24 - -[View all 131 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-05-22T14%3A53%3A59Z..2023-07-01T22%3A57%3A20Z+base%3Amaster) - -### New Lints - -* [`manual_try_fold`] - [#11012](https://github.com/rust-lang/rust-clippy/pull/11012) -* [`tuple_array_conversions`] - [#11020](https://github.com/rust-lang/rust-clippy/pull/11020) -* [`redundant_at_rest_pattern`] - [#11013](https://github.com/rust-lang/rust-clippy/pull/11013) -* [`needless_pub_self`] - [#10967](https://github.com/rust-lang/rust-clippy/pull/10967) -* [`pub_with_shorthand`] - [#10967](https://github.com/rust-lang/rust-clippy/pull/10967) -* [`pub_without_shorthand`] - [#10967](https://github.com/rust-lang/rust-clippy/pull/10967) -* [`manual_range_patterns`] - [#10968](https://github.com/rust-lang/rust-clippy/pull/10968) -* [`needless_raw_string_hashes`] - [#10884](https://github.com/rust-lang/rust-clippy/pull/10884) -* [`needless_raw_strings`] - [#10884](https://github.com/rust-lang/rust-clippy/pull/10884) -* [`incorrect_clone_impl_on_copy_type`] - [#10925](https://github.com/rust-lang/rust-clippy/pull/10925) -* [`drain_collect`] - [#10835](https://github.com/rust-lang/rust-clippy/pull/10835) -* [`single_range_in_vec_init`] - [#10934](https://github.com/rust-lang/rust-clippy/pull/10934) -* [`unnecessary_literal_unwrap`] - [#10358](https://github.com/rust-lang/rust-clippy/pull/10358) -* [`large_stack_frames`] - [#10827](https://github.com/rust-lang/rust-clippy/pull/10827) -* [`min_ident_chars`] - [#10916](https://github.com/rust-lang/rust-clippy/pull/10916) -* [`needless_if`] - [#10921](https://github.com/rust-lang/rust-clippy/pull/10921) -* [`excessive_nesting`] - [#10672](https://github.com/rust-lang/rust-clippy/pull/10672) -* [`arc_with_non_send_sync`] - [#10898](https://github.com/rust-lang/rust-clippy/pull/10898) -* [`redundant_type_annotations`] - [#10570](https://github.com/rust-lang/rust-clippy/pull/10570) -* [`host_endian_bytes`] - [#10826](https://github.com/rust-lang/rust-clippy/pull/10826) -* [`little_endian_bytes`] - [#10826](https://github.com/rust-lang/rust-clippy/pull/10826) -* [`big_endian_bytes`] - [#10826](https://github.com/rust-lang/rust-clippy/pull/10826) -* [`ptr_cast_constness`] - [#10779](https://github.com/rust-lang/rust-clippy/pull/10779) -* [`needless_else`] - [#10810](https://github.com/rust-lang/rust-clippy/pull/10810) - -### Moves and Deprecations - -* Moved [`redundant_clone`] to `nursery` (Now allow-by-default) - [#10873](https://github.com/rust-lang/rust-clippy/pull/10873) - -### Enhancements - -* [`undocumented_unsafe_blocks`]: Added [`accept-comment-above-attributes`] configuration - [#10986](https://github.com/rust-lang/rust-clippy/pull/10986) -* [`undocumented_unsafe_blocks`]: Added [`accept-comment-above-statement`] configuration. - [#10886](https://github.com/rust-lang/rust-clippy/pull/10886) -* [`missing_panics_doc`]: No longer lints on `todo!()` - [#10976](https://github.com/rust-lang/rust-clippy/pull/10976) -* [`module_inception`]: Added `allow-private-module-inception` configuration. - [#10917](https://github.com/rust-lang/rust-clippy/pull/10917) -* Errors and warnings generated while parsing `clippy.toml` now point to the location in the TOML - file the error/warning occurred in. - [#10607](https://github.com/rust-lang/rust-clippy/pull/10607) - -### False Positive Fixes - -* [`excessive_precision`]: No longer lints overflowing literals - [#10952](https://github.com/rust-lang/rust-clippy/pull/10952) - -### Suggestion Fixes/Improvements - -* [`option_map_unwrap_or`]: The suggestion now considers the set [`msrv`] config value - [#11030](https://github.com/rust-lang/rust-clippy/pull/11030) - -### Documentation Improvements - -* [Clippy's lint list] now stores filter parameters in the URL, to allow easy sharing - [#10834](https://github.com/rust-lang/rust-clippy/pull/10834) - -## Rust 1.71 - -Released 2023-07-13 - -Note: Clippy will use a shorter changelog format from now on, if you want a detailed list of -all changes, please check out the list of merged pull requests. - -[View all 78 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-04-11T20%3A05%3A26Z..2023-05-20T13%3A48%3A17Z+base%3Amaster) - -### New Lints - -* [`non_minimal_cfg`] - [#10763](https://github.com/rust-lang/rust-clippy/pull/10763) -* [`manual_next_back`] - [#10769](https://github.com/rust-lang/rust-clippy/pull/10769) -* [`ref_patterns`] - [#10736](https://github.com/rust-lang/rust-clippy/pull/10736) -* [`default_constructed_unit_structs`] - [#10716](https://github.com/rust-lang/rust-clippy/pull/10716) -* [`manual_while_let_some`] - [#10647](https://github.com/rust-lang/rust-clippy/pull/10647) -* [`needless_bool_assign`] - [#10432](https://github.com/rust-lang/rust-clippy/pull/10432) -* [`items_after_test_module`] - [#10578](https://github.com/rust-lang/rust-clippy/pull/10578) - -### Moves and Deprecations - -* Rename `integer_arithmetic` to `arithmetic_side_effects` - [#10674](https://github.com/rust-lang/rust-clippy/pull/10674) -* Moved [`redundant_clone`] to `nursery` (Now allow-by-default) - [#10873](https://github.com/rust-lang/rust-clippy/pull/10873) - -### Enhancements - -* [`invalid_regex`]: Now supports the new syntax introduced after regex v1.8.0 - [#10682](https://github.com/rust-lang/rust-clippy/pull/10682) -* [`semicolon_outside_block`]: Added [`semicolon-outside-block-ignore-multiline`] as a new config value. - [#10656](https://github.com/rust-lang/rust-clippy/pull/10656) -* [`semicolon_inside_block`]: Added [`semicolon-inside-block-ignore-singleline`] as a new config value. - [#10656](https://github.com/rust-lang/rust-clippy/pull/10656) -* [`unnecessary_box_returns`]: Added [`unnecessary-box-size`] as a new config value to set the maximum - size of `T` in `Box` to be linted. - [#10651](https://github.com/rust-lang/rust-clippy/pull/10651) - -### Documentation Improvements - -* `cargo clippy --explain LINT` now shows possible configuration options for the explained lint - [#10751](https://github.com/rust-lang/rust-clippy/pull/10751) -* New config values mentioned in this changelog will now be linked. - [#10889](https://github.com/rust-lang/rust-clippy/pull/10889) -* Several sections of [Clippy's book] have been reworked - [#10652](https://github.com/rust-lang/rust-clippy/pull/10652) - [#10622](https://github.com/rust-lang/rust-clippy/pull/10622) - -[Clippy's book]: https://doc.rust-lang.org/clippy/ - -## Rust 1.70 - -Released 2023-06-01 - -[View all 91 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-02-26T01%3A05%3A43Z..2023-04-11T13%3A27%3A30Z+base%3Amaster) - -### 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 items 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 - -Released 2023-04-20 - -[View all 72 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-01-13T06%3A12%3A46Z..2023-02-25T23%3A48%3A10Z+base%3Amaster) - -### New Lints - -* [`no_mangle_with_rust_abi`] - [#10369](https://github.com/rust-lang/rust-clippy/pull/10369) -* [`significant_drop_tightening`] - [#10163](https://github.com/rust-lang/rust-clippy/pull/10163) -* [`suspicious_command_arg_space`] - [#10317](https://github.com/rust-lang/rust-clippy/pull/10317) -* [`let_underscore_untyped`] - [#10356](https://github.com/rust-lang/rust-clippy/pull/10356) -* [`question_mark_used`] - [#10342](https://github.com/rust-lang/rust-clippy/pull/10342) -* [`extra_unused_type_parameters`] - [#10028](https://github.com/rust-lang/rust-clippy/pull/10028) -* [`impl_trait_in_params`] - [10197](https://github.com/rust-lang/rust-clippy/pull/10197) -* [`transmute_int_to_non_zero`] - [#10360](https://github.com/rust-lang/rust-clippy/pull/10360) -* [`multiple_unsafe_ops_per_block`] - [#10206](https://github.com/rust-lang/rust-clippy/pull/10206) - -### Moves and Deprecations - -* Moved [`uninlined_format_args`] to `pedantic` (Now allow-by-default) - [#10265](https://github.com/rust-lang/rust-clippy/pull/10265) -* Moved [`unchecked_duration_subtraction`] to `pedantic` (Now allow-by-default) - [#10194](https://github.com/rust-lang/rust-clippy/pull/10194) - -### Enhancements - -* [`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) -* [`unused_io_amount`]: Now detects usages of `is_ok` and `is_err` - [#10225](https://github.com/rust-lang/rust-clippy/pull/10225) -* [`missing_docs_in_private_items`]: Added new configuration `missing-docs-in-crate-items` to lint - on items visible within the current crate. For example, `pub(crate)` items. - [#10303](https://github.com/rust-lang/rust-clippy/pull/10303) -* [`almost_swapped`]: Now detects almost swaps using `let` statements - [#10177](https://github.com/rust-lang/rust-clippy/pull/10177) -* [`wildcard_enum_match_arm`]: Now lints missing private variants, for local enums - [#10250](https://github.com/rust-lang/rust-clippy/pull/10250) - -### False Positive Fixes - -* [`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 - [#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 - [#10380](https://github.com/rust-lang/rust-clippy/pull/10380) -* [`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 - 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 - [#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 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 - [#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 - [#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) -* [`suspicious_to_owned`]: The suggestion now shows all options clearly - [#10295](https://github.com/rust-lang/rust-clippy/pull/10295) -* [`bytes_nth`]: Now suggests the correct replacement based on the context - [#10361](https://github.com/rust-lang/rust-clippy/pull/10361) -* [`bool_assert_comparison`]: The suggestion is now machine applicable - [#10218](https://github.com/rust-lang/rust-clippy/pull/10218) -* [`cast_possible_truncation`]: Corrected the lint name in the help message - [#10330](https://github.com/rust-lang/rust-clippy/pull/10330) -* [`needless_return`]: The suggestion now works on if sequences - [#10345](https://github.com/rust-lang/rust-clippy/pull/10345) -* [`needless_lifetimes`]: The suggestion is now machine applicable - [#10222](https://github.com/rust-lang/rust-clippy/pull/10222) -* [`map_entry`]: The suggestion no longer expands macros - [#10346](https://github.com/rust-lang/rust-clippy/pull/10346) - -### ICE Fixes - -* [`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) - -### Documentation Improvements - -* All configurations are now documented in the Clippy Book - [#10199](https://github.com/rust-lang/rust-clippy/pull/10199) - -## Rust 1.68 - -Released 2023-03-09 - -[View all 76 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2022-12-01T20%3A40%3A04Z..2023-01-12T18%3A58%3A59Z+base%3Amaster) - -### New Lints - -* [`permissions_set_readonly_false`] - [#10063](https://github.com/rust-lang/rust-clippy/pull/10063) -* [`almost_complete_range`] - [#10043](https://github.com/rust-lang/rust-clippy/pull/10043) -* [`size_of_ref`] - [#10098](https://github.com/rust-lang/rust-clippy/pull/10098) -* [`semicolon_outside_block`] - [#9826](https://github.com/rust-lang/rust-clippy/pull/9826) -* [`semicolon_inside_block`] - [#9826](https://github.com/rust-lang/rust-clippy/pull/9826) -* [`transmute_null_to_fn`] - [#10099](https://github.com/rust-lang/rust-clippy/pull/10099) -* [`fn_null_check`] - [#10099](https://github.com/rust-lang/rust-clippy/pull/10099) - -### Moves and Deprecations - -* Moved [`manual_clamp`] to `nursery` (Now allow-by-default) - [#10101](https://github.com/rust-lang/rust-clippy/pull/10101) -* Moved [`mutex_atomic`] to `restriction` - [#10115](https://github.com/rust-lang/rust-clippy/pull/10115) -* Renamed `derive_hash_xor_eq` to [`derived_hash_with_manual_eq`] - [#10184](https://github.com/rust-lang/rust-clippy/pull/10184) - -### Enhancements - -* [`collapsible_str_replace`]: Now takes MSRV into consideration. The minimal version is 1.58 - [#10047](https://github.com/rust-lang/rust-clippy/pull/10047) -* [`unused_self`]: No longer lints, if the method body contains a `todo!()` call - [#10166](https://github.com/rust-lang/rust-clippy/pull/10166) -* [`derivable_impls`]: Now suggests deriving `Default` for enums with default unit variants - [#10161](https://github.com/rust-lang/rust-clippy/pull/10161) -* [`arithmetic_side_effects`]: Added two new config values - `arithmetic-side-effects-allowed-binary` and `arithmetic-side-effects-allowed-unary` - to allow operation on user types - [#9840](https://github.com/rust-lang/rust-clippy/pull/9840) -* [`large_const_arrays`], [`large_stack_arrays`]: avoid integer overflow when calculating - total array size - [#10103](https://github.com/rust-lang/rust-clippy/pull/10103) -* [`indexing_slicing`]: add new config `suppress-restriction-lint-in-const` to enable - restriction lints, even if the suggestion might not be applicable - [#9920](https://github.com/rust-lang/rust-clippy/pull/9920) -* [`needless_borrow`], [`redundant_clone`]: Now track references better and detect more cases - [#9701](https://github.com/rust-lang/rust-clippy/pull/9701) -* [`derived_hash_with_manual_eq`]: Now allows `#[derive(PartialEq)]` with custom `Hash` - implementations - [#10184](https://github.com/rust-lang/rust-clippy/pull/10184) -* [`manual_is_ascii_check`]: Now detects ranges with `.contains()` calls - [#10053](https://github.com/rust-lang/rust-clippy/pull/10053) -* [`transmuting_null`]: Now detects `const` pointers to all types - [#10099](https://github.com/rust-lang/rust-clippy/pull/10099) -* [`needless_return`]: Now detects more cases for returns of owned values - [#10110](https://github.com/rust-lang/rust-clippy/pull/10110) - -### False Positive Fixes - -* [`field_reassign_with_default`]: No longer lints cases, where values are initializes from - closures capturing struct values - [#10143](https://github.com/rust-lang/rust-clippy/pull/10143) -* [`seek_to_start_instead_of_rewind`]: No longer lints, if the return of `seek` is used. - [#10096](https://github.com/rust-lang/rust-clippy/pull/10096) -* [`manual_filter`]: Now ignores if expressions where the else branch has side effects or - doesn't return `None` - [#10091](https://github.com/rust-lang/rust-clippy/pull/10091) -* [`implicit_clone`]: No longer lints if the type doesn't implement clone - [#10022](https://github.com/rust-lang/rust-clippy/pull/10022) -* [`match_wildcard_for_single_variants`]: No longer lints on wildcards with a guard - [#10056](https://github.com/rust-lang/rust-clippy/pull/10056) -* [`drop_ref`]: No longer lints idiomatic expression in `match` arms - [#10142](https://github.com/rust-lang/rust-clippy/pull/10142) -* [`arithmetic_side_effects`]: No longer lints on corner cases with negative number literals - [#9867](https://github.com/rust-lang/rust-clippy/pull/9867) -* [`string_lit_as_bytes`]: No longer lints in scrutinies of `match` statements - [#10012](https://github.com/rust-lang/rust-clippy/pull/10012) -* [`manual_assert`]: No longer lints in `else if` statements - [#10013](https://github.com/rust-lang/rust-clippy/pull/10013) -* [`needless_return`]: don't lint when using `do yeet` - [#10109](https://github.com/rust-lang/rust-clippy/pull/10109) -* All lints: No longer lint in enum discriminant values when the suggestion won't work in a - const context - [#10008](https://github.com/rust-lang/rust-clippy/pull/10008) -* [`single_element_loop`]: No longer lints, if the loop contains a `break` or `continue` - [#10162](https://github.com/rust-lang/rust-clippy/pull/10162) -* [`uninlined_format_args`]: No longer suggests inlining arguments in `assert!` and - `debug_assert!` macros before 2021 edition - [#10055](https://github.com/rust-lang/rust-clippy/pull/10055) -* [`explicit_counter_loop`]: No longer ignores counter changes after `continue` expressions - [#10094](https://github.com/rust-lang/rust-clippy/pull/10094) -* [`from_over_into`]: No longer lints on opaque types - [#9982](https://github.com/rust-lang/rust-clippy/pull/9982) -* [`expl_impl_clone_on_copy`]: No longer lints on `#[repr(packed)]` structs with generic - parameters - [#10189](https://github.com/rust-lang/rust-clippy/pull/10189) - -### Suggestion Fixes/Improvements - -* [`zero_ptr`]: Now suggests `core::` paths for `no_std` crates - [#10023](https://github.com/rust-lang/rust-clippy/pull/10023) -* [`useless_conversion`]: Now suggests removing calls to `into_iter()` on an expression - implementing `Iterator` - [#10020](https://github.com/rust-lang/rust-clippy/pull/10020) -* [`box_default`]: The suggestion now uses short paths - [#10153](https://github.com/rust-lang/rust-clippy/pull/10153) -* [`default_trait_access`], [`clone_on_copy`]: The suggestion now uses short paths - [#10160](https://github.com/rust-lang/rust-clippy/pull/10160) -* [`comparison_to_empty`]: The suggestion now removes unused deref operations - [#9962](https://github.com/rust-lang/rust-clippy/pull/9962) -* [`manual_let_else`]: Suggestions for or-patterns now include required brackets. - [#9966](https://github.com/rust-lang/rust-clippy/pull/9966) -* [`match_single_binding`]: suggestion no longer introduces unneeded semicolons - [#10060](https://github.com/rust-lang/rust-clippy/pull/10060) -* [`case_sensitive_file_extension_comparisons`]: Now displays a suggestion with `Path` - [#10107](https://github.com/rust-lang/rust-clippy/pull/10107) -* [`empty_structs_with_brackets`]: The suggestion is no longer machine applicable, to avoid - errors when accessing struct fields - [#10141](https://github.com/rust-lang/rust-clippy/pull/10141) -* [`identity_op`]: Removes borrows in the suggestion when needed - [#10004](https://github.com/rust-lang/rust-clippy/pull/10004) -* [`suboptimal_flops`]: The suggestion now includes parentheses when required - [#10113](https://github.com/rust-lang/rust-clippy/pull/10113) -* [`iter_kv_map`]: Now handles `mut` and reference annotations in the suggestion - [#10159](https://github.com/rust-lang/rust-clippy/pull/10159) -* [`redundant_static_lifetimes`]: The suggestion no longer removes `mut` from references - [#10006](https://github.com/rust-lang/rust-clippy/pull/10006) - -### ICE Fixes - -* [`new_ret_no_self`]: Now avoids a stack overflow for `impl Trait` types - [#10086](https://github.com/rust-lang/rust-clippy/pull/10086) -* [`unnecessary_to_owned`]: Now handles compiler generated notes better - [#10027](https://github.com/rust-lang/rust-clippy/pull/10027) - -### Others - -* `SYSROOT` and `--sysroot` can now be set at the same time - [#10149](https://github.com/rust-lang/rust-clippy/pull/10149) -* Fix error when providing an `array-size-threshold` in `clippy.toml` - [#10423](https://github.com/rust-lang/rust-clippy/pull/10423) - -## Rust 1.67 - -Released 2023-01-26 - -[View all 104 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2022-10-23T13%3A35%3A19Z..2022-12-01T13%3A34%3A39Z+base%3Amaster) - -### New Lints - -* [`seek_from_current`] - [#9681](https://github.com/rust-lang/rust-clippy/pull/9681) -* [`from_raw_with_void_ptr`] - [#9690](https://github.com/rust-lang/rust-clippy/pull/9690) -* [`misnamed_getters`] - [#9770](https://github.com/rust-lang/rust-clippy/pull/9770) -* [`seek_to_start_instead_of_rewind`] - [#9667](https://github.com/rust-lang/rust-clippy/pull/9667) -* [`suspicious_xor_used_as_pow`] - [#9506](https://github.com/rust-lang/rust-clippy/pull/9506) -* [`unnecessary_safety_doc`] - [#9822](https://github.com/rust-lang/rust-clippy/pull/9822) -* [`unchecked_duration_subtraction`] - [#9570](https://github.com/rust-lang/rust-clippy/pull/9570) -* [`manual_is_ascii_check`] - [#9765](https://github.com/rust-lang/rust-clippy/pull/9765) -* [`unnecessary_safety_comment`] - [#9851](https://github.com/rust-lang/rust-clippy/pull/9851) -* [`let_underscore_future`] - [#9760](https://github.com/rust-lang/rust-clippy/pull/9760) -* [`manual_let_else`] - [#8437](https://github.com/rust-lang/rust-clippy/pull/8437) - -### Moves and Deprecations - -* Moved [`needless_collect`] to `nursery` (Now allow-by-default) - [#9705](https://github.com/rust-lang/rust-clippy/pull/9705) -* Moved [`or_fun_call`] to `nursery` (Now allow-by-default) - [#9829](https://github.com/rust-lang/rust-clippy/pull/9829) -* Uplifted [`let_underscore_lock`] into rustc - [#9697](https://github.com/rust-lang/rust-clippy/pull/9697) -* Uplifted [`let_underscore_drop`] into rustc - [#9697](https://github.com/rust-lang/rust-clippy/pull/9697) -* Moved [`bool_to_int_with_if`] to `pedantic` (Now allow-by-default) - [#9830](https://github.com/rust-lang/rust-clippy/pull/9830) -* Move `index_refutable_slice` to `pedantic` (Now warn-by-default) - [#9975](https://github.com/rust-lang/rust-clippy/pull/9975) -* Moved [`manual_clamp`] to `nursery` (Now allow-by-default) - [#10101](https://github.com/rust-lang/rust-clippy/pull/10101) - -### Enhancements - -* The scope of `#![clippy::msrv]` is now tracked correctly - [#9924](https://github.com/rust-lang/rust-clippy/pull/9924) -* `#[clippy::msrv]` can now be used as an outer attribute - [#9860](https://github.com/rust-lang/rust-clippy/pull/9860) -* Clippy will now avoid Cargo's cache, if `Cargo.toml` or `clippy.toml` have changed - [#9707](https://github.com/rust-lang/rust-clippy/pull/9707) -* [`uninlined_format_args`]: Added a new config `allow-mixed-uninlined-format-args` to allow the - lint, if only some arguments can be inlined - [#9865](https://github.com/rust-lang/rust-clippy/pull/9865) -* [`needless_lifetimes`]: Now provides suggests for individual lifetimes - [#9743](https://github.com/rust-lang/rust-clippy/pull/9743) -* [`needless_collect`]: Now detects needless `is_empty` and `contains` calls - [#8744](https://github.com/rust-lang/rust-clippy/pull/8744) -* [`blanket_clippy_restriction_lints`]: Now lints, if `clippy::restriction` is enabled via the - command line arguments - [#9755](https://github.com/rust-lang/rust-clippy/pull/9755) -* [`mutable_key_type`]: Now has the `ignore-interior-mutability` configuration, to add types which - should be ignored by the lint - [#9692](https://github.com/rust-lang/rust-clippy/pull/9692) -* [`uninlined_format_args`]: Now works for multiline `format!` expressions - [#9945](https://github.com/rust-lang/rust-clippy/pull/9945) -* [`cognitive_complexity`]: Now works for async functions - [#9828](https://github.com/rust-lang/rust-clippy/pull/9828) - [#9836](https://github.com/rust-lang/rust-clippy/pull/9836) -* [`vec_box`]: Now avoids an off-by-one error when using the `vec-box-size-threshold` configuration - [#9848](https://github.com/rust-lang/rust-clippy/pull/9848) -* [`never_loop`]: Now correctly handles breaks in nested labeled blocks - [#9858](https://github.com/rust-lang/rust-clippy/pull/9858) - [#9837](https://github.com/rust-lang/rust-clippy/pull/9837) -* [`disallowed_methods`], [`disallowed_types`], [`disallowed_macros`]: Now correctly resolve - paths, if a crate is used multiple times with different versions - [#9800](https://github.com/rust-lang/rust-clippy/pull/9800) -* [`disallowed_methods`]: Can now be used for local methods - [#9800](https://github.com/rust-lang/rust-clippy/pull/9800) -* [`print_stdout`], [`print_stderr`]: Can now be enabled in test with the `allow-print-in-tests` - config value - [#9797](https://github.com/rust-lang/rust-clippy/pull/9797) -* [`from_raw_with_void_ptr`]: Now works for `Rc`, `Arc`, `alloc::rc::Weak` and - `alloc::sync::Weak` types. - [#9700](https://github.com/rust-lang/rust-clippy/pull/9700) -* [`needless_borrowed_reference`]: Now works for struct and tuple patterns with wildcards - [#9855](https://github.com/rust-lang/rust-clippy/pull/9855) -* [`or_fun_call`]: Now supports `map_or` methods - [#9689](https://github.com/rust-lang/rust-clippy/pull/9689) -* [`unwrap_used`], [`expect_used`]: No longer lints in test code - [#9686](https://github.com/rust-lang/rust-clippy/pull/9686) -* [`fn_params_excessive_bools`]: Is now emitted with the lint level at the linted function - [#9698](https://github.com/rust-lang/rust-clippy/pull/9698) - -### False Positive Fixes - -* [`new_ret_no_self`]: No longer lints when `impl Trait` is returned - [#9733](https://github.com/rust-lang/rust-clippy/pull/9733) -* [`unnecessary_lazy_evaluations`]: No longer lints, if the type has a significant drop - [#9750](https://github.com/rust-lang/rust-clippy/pull/9750) -* [`option_if_let_else`]: No longer lints, if any arm has guard - [#9747](https://github.com/rust-lang/rust-clippy/pull/9747) -* [`explicit_auto_deref`]: No longer lints, if the target type is a projection with generic - arguments - [#9813](https://github.com/rust-lang/rust-clippy/pull/9813) -* [`unnecessary_to_owned`]: No longer lints, if the suggestion effects types - [#9796](https://github.com/rust-lang/rust-clippy/pull/9796) -* [`needless_borrow`]: No longer lints, if the suggestion is affected by `Deref` - [#9674](https://github.com/rust-lang/rust-clippy/pull/9674) -* [`unused_unit`]: No longer lints, if lifetimes are bound to the return type - [#9849](https://github.com/rust-lang/rust-clippy/pull/9849) -* [`mut_mut`]: No longer lints cases with unsized mutable references - [#9835](https://github.com/rust-lang/rust-clippy/pull/9835) -* [`bool_to_int_with_if`]: No longer lints in const context - [#9738](https://github.com/rust-lang/rust-clippy/pull/9738) -* [`use_self`]: No longer lints in macros - [#9704](https://github.com/rust-lang/rust-clippy/pull/9704) -* [`unnecessary_operation`]: No longer lints, if multiple macros are involved - [#9981](https://github.com/rust-lang/rust-clippy/pull/9981) -* [`allow_attributes_without_reason`]: No longer lints inside external macros - [#9630](https://github.com/rust-lang/rust-clippy/pull/9630) -* [`question_mark`]: No longer lints for `if let Err()` with an `else` branch - [#9722](https://github.com/rust-lang/rust-clippy/pull/9722) -* [`unnecessary_cast`]: No longer lints if the identifier and cast originate from different macros - [#9980](https://github.com/rust-lang/rust-clippy/pull/9980) -* [`arithmetic_side_effects`]: Now detects operations with associated constants - [#9592](https://github.com/rust-lang/rust-clippy/pull/9592) -* [`explicit_auto_deref`]: No longer lints, if the initial value is not a reference or reference - receiver - [#9997](https://github.com/rust-lang/rust-clippy/pull/9997) -* [`module_name_repetitions`], [`single_component_path_imports`]: Now handle `#[allow]` - attributes correctly - [#9879](https://github.com/rust-lang/rust-clippy/pull/9879) -* [`bool_to_int_with_if`]: No longer lints `if let` statements - [#9714](https://github.com/rust-lang/rust-clippy/pull/9714) -* [`needless_borrow`]: No longer lints, `if`-`else`-statements that require the borrow - [#9791](https://github.com/rust-lang/rust-clippy/pull/9791) -* [`needless_borrow`]: No longer lints borrows, if moves were illegal - [#9711](https://github.com/rust-lang/rust-clippy/pull/9711) -* [`manual_swap`]: No longer lints in const context - [#9871](https://github.com/rust-lang/rust-clippy/pull/9871) - -### Suggestion Fixes/Improvements - -* [`missing_safety_doc`], [`missing_errors_doc`], [`missing_panics_doc`]: No longer show the - entire item in the lint emission. - [#9772](https://github.com/rust-lang/rust-clippy/pull/9772) -* [`needless_lifetimes`]: Only suggests `'_` when it's applicable - [#9743](https://github.com/rust-lang/rust-clippy/pull/9743) -* [`use_self`]: Now suggests full paths correctly - [#9726](https://github.com/rust-lang/rust-clippy/pull/9726) -* [`redundant_closure_call`]: Now correctly deals with macros during suggestion creation - [#9987](https://github.com/rust-lang/rust-clippy/pull/9987) -* [`unnecessary_cast`]: Suggestions now correctly deal with references - [#9996](https://github.com/rust-lang/rust-clippy/pull/9996) -* [`unnecessary_join`]: Suggestions now correctly use [turbofish] operators - [#9779](https://github.com/rust-lang/rust-clippy/pull/9779) -* [`equatable_if_let`]: Can now suggest `matches!` replacements - [#9368](https://github.com/rust-lang/rust-clippy/pull/9368) -* [`string_extend_chars`]: Suggestions now correctly work for `str` slices - [#9741](https://github.com/rust-lang/rust-clippy/pull/9741) -* [`redundant_closure_for_method_calls`]: Suggestions now include angle brackets and generic - arguments if needed - [#9745](https://github.com/rust-lang/rust-clippy/pull/9745) -* [`manual_let_else`]: Suggestions no longer expand macro calls - [#9943](https://github.com/rust-lang/rust-clippy/pull/9943) -* [`infallible_destructuring_match`]: Suggestions now preserve references - [#9850](https://github.com/rust-lang/rust-clippy/pull/9850) -* [`result_large_err`]: The error now shows the largest enum variant - [#9662](https://github.com/rust-lang/rust-clippy/pull/9662) -* [`needless_return`]: Suggestions are now formatted better - [#9967](https://github.com/rust-lang/rust-clippy/pull/9967) -* [`unused_rounding`]: The suggestion now preserves the original float literal notation - [#9870](https://github.com/rust-lang/rust-clippy/pull/9870) - -[turbofish]: https://turbo.fish/::%3CClippy%3E - -### ICE Fixes - -* [`result_large_err`]: Fixed ICE for empty enums - [#10007](https://github.com/rust-lang/rust-clippy/pull/10007) -* [`redundant_allocation`]: Fixed ICE for types with bounded variables - [#9773](https://github.com/rust-lang/rust-clippy/pull/9773) -* [`unused_rounding`]: Fixed ICE, if `_` was used as a separator - [#10001](https://github.com/rust-lang/rust-clippy/pull/10001) - -## Rust 1.66 - -Released 2022-12-15 - -[View all 116 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2022-09-09T17%3A32%3A39Z..2022-10-23T11%3A27%3A24Z+base%3Amaster) - -### New Lints - -* [`manual_clamp`] - [#9484](https://github.com/rust-lang/rust-clippy/pull/9484) -* [`missing_trait_methods`] - [#9670](https://github.com/rust-lang/rust-clippy/pull/9670) -* [`unused_format_specs`] - [#9637](https://github.com/rust-lang/rust-clippy/pull/9637) -* [`iter_kv_map`] - [#9409](https://github.com/rust-lang/rust-clippy/pull/9409) -* [`manual_filter`] - [#9451](https://github.com/rust-lang/rust-clippy/pull/9451) -* [`box_default`] - [#9511](https://github.com/rust-lang/rust-clippy/pull/9511) -* [`implicit_saturating_add`] - [#9549](https://github.com/rust-lang/rust-clippy/pull/9549) -* [`as_ptr_cast_mut`] - [#9572](https://github.com/rust-lang/rust-clippy/pull/9572) -* [`disallowed_macros`] - [#9495](https://github.com/rust-lang/rust-clippy/pull/9495) -* [`partial_pub_fields`] - [#9658](https://github.com/rust-lang/rust-clippy/pull/9658) -* [`uninlined_format_args`] - [#9233](https://github.com/rust-lang/rust-clippy/pull/9233) -* [`cast_nan_to_int`] - [#9617](https://github.com/rust-lang/rust-clippy/pull/9617) - -### Moves and Deprecations - -* `positional_named_format_parameters` was uplifted to rustc under the new name - `named_arguments_used_positionally` - [#8518](https://github.com/rust-lang/rust-clippy/pull/8518) -* Moved [`implicit_saturating_sub`] to `style` (Now warn-by-default) - [#9584](https://github.com/rust-lang/rust-clippy/pull/9584) -* Moved `derive_partial_eq_without_eq` to `nursery` (now allow-by-default) - [#9536](https://github.com/rust-lang/rust-clippy/pull/9536) - -### Enhancements - -* [`nonstandard_macro_braces`]: Now includes `matches!()` in the default lint config - [#9471](https://github.com/rust-lang/rust-clippy/pull/9471) -* [`suboptimal_flops`]: Now supports multiplication and subtraction operations - [#9581](https://github.com/rust-lang/rust-clippy/pull/9581) -* [`arithmetic_side_effects`]: Now detects cases with literals behind references - [#9587](https://github.com/rust-lang/rust-clippy/pull/9587) -* [`upper_case_acronyms`]: Now also checks enum names - [#9580](https://github.com/rust-lang/rust-clippy/pull/9580) -* [`needless_borrowed_reference`]: Now lints nested patterns - [#9573](https://github.com/rust-lang/rust-clippy/pull/9573) -* [`unnecessary_cast`]: Now works for non-trivial non-literal expressions - [#9576](https://github.com/rust-lang/rust-clippy/pull/9576) -* [`arithmetic_side_effects`]: Now detects operations with custom types - [#9559](https://github.com/rust-lang/rust-clippy/pull/9559) -* [`disallowed_methods`], [`disallowed_types`]: Not correctly lints types, functions and macros - with the same path - [#9495](https://github.com/rust-lang/rust-clippy/pull/9495) -* [`self_named_module_files`], [`mod_module_files`]: Now take remapped path prefixes into account - [#9475](https://github.com/rust-lang/rust-clippy/pull/9475) -* [`bool_to_int_with_if`]: Now detects the inverse if case - [#9476](https://github.com/rust-lang/rust-clippy/pull/9476) - -### False Positive Fixes - -* [`arithmetic_side_effects`]: Now allows operations that can't overflow - [#9474](https://github.com/rust-lang/rust-clippy/pull/9474) -* [`unnecessary_lazy_evaluations`]: No longer lints in external macros - [#9486](https://github.com/rust-lang/rust-clippy/pull/9486) -* [`needless_borrow`], [`explicit_auto_deref`]: No longer lint on unions that require the reference - [#9490](https://github.com/rust-lang/rust-clippy/pull/9490) -* [`almost_complete_letter_range`]: No longer lints in external macros - [#9467](https://github.com/rust-lang/rust-clippy/pull/9467) -* [`drop_copy`]: No longer lints on idiomatic cases in match arms - [#9491](https://github.com/rust-lang/rust-clippy/pull/9491) -* [`question_mark`]: No longer lints in const context - [#9487](https://github.com/rust-lang/rust-clippy/pull/9487) -* [`collapsible_if`]: Suggestion now work in macros - [#9410](https://github.com/rust-lang/rust-clippy/pull/9410) -* [`std_instead_of_core`]: No longer triggers on unstable modules - [#9545](https://github.com/rust-lang/rust-clippy/pull/9545) -* [`unused_peekable`]: No longer lints, if the peak is done in a closure or function - [#9465](https://github.com/rust-lang/rust-clippy/pull/9465) -* [`useless_attribute`]: No longer lints on `#[allow]` attributes for [`unsafe_removed_from_name`] - [#9593](https://github.com/rust-lang/rust-clippy/pull/9593) -* [`unnecessary_lazy_evaluations`]: No longer suggest switching to early evaluation when type has - custom `Drop` implementation - [#9551](https://github.com/rust-lang/rust-clippy/pull/9551) -* [`unnecessary_cast`]: No longer lints on negative hexadecimal literals when cast as floats - [#9609](https://github.com/rust-lang/rust-clippy/pull/9609) -* [`use_self`]: No longer lints in proc macros - [#9454](https://github.com/rust-lang/rust-clippy/pull/9454) -* [`never_loop`]: Now takes `let ... else` statements into consideration. - [#9496](https://github.com/rust-lang/rust-clippy/pull/9496) -* [`default_numeric_fallback`]: Now ignores constants - [#9636](https://github.com/rust-lang/rust-clippy/pull/9636) -* [`uninit_vec`]: No longer lints `Vec::set_len(0)` - [#9519](https://github.com/rust-lang/rust-clippy/pull/9519) -* [`arithmetic_side_effects`]: Now ignores references to integer types - [#9507](https://github.com/rust-lang/rust-clippy/pull/9507) -* [`large_stack_arrays`]: No longer lints inside static items - [#9466](https://github.com/rust-lang/rust-clippy/pull/9466) -* [`ref_option_ref`]: No longer lints if the inner reference is mutable - [#9684](https://github.com/rust-lang/rust-clippy/pull/9684) -* [`ptr_arg`]: No longer lints if the argument is used as an incomplete trait object - [#9645](https://github.com/rust-lang/rust-clippy/pull/9645) -* [`should_implement_trait`]: Now also works for `default` methods - [#9546](https://github.com/rust-lang/rust-clippy/pull/9546) - -### Suggestion Fixes/Improvements - -* [`derivable_impls`]: The suggestion is now machine applicable - [#9429](https://github.com/rust-lang/rust-clippy/pull/9429) -* [`match_single_binding`]: The suggestion now handles scrutinies with side effects better - [#9601](https://github.com/rust-lang/rust-clippy/pull/9601) -* [`zero_prefixed_literal`]: Only suggests using octal numbers, if this is possible - [#9652](https://github.com/rust-lang/rust-clippy/pull/9652) -* [`rc_buffer`]: The suggestion is no longer machine applicable to avoid semantic changes - [#9633](https://github.com/rust-lang/rust-clippy/pull/9633) -* [`print_literal`], [`write_literal`], [`uninlined_format_args`]: The suggestion now ignores - comments after the macro call. - [#9586](https://github.com/rust-lang/rust-clippy/pull/9586) -* [`expect_fun_call`]:Improved the suggestion for `format!` calls with captured variables - [#9586](https://github.com/rust-lang/rust-clippy/pull/9586) -* [`nonstandard_macro_braces`]: The suggestion is now machine applicable and will no longer - replace brackets inside the macro argument. - [#9499](https://github.com/rust-lang/rust-clippy/pull/9499) -* [`from_over_into`]: The suggestion is now a machine applicable and contains explanations - [#9649](https://github.com/rust-lang/rust-clippy/pull/9649) -* [`needless_return`]: The automatic suggestion now removes all required semicolons - [#9497](https://github.com/rust-lang/rust-clippy/pull/9497) -* [`to_string_in_format_args`]: The suggestion now keeps parenthesis around values - [#9590](https://github.com/rust-lang/rust-clippy/pull/9590) -* [`manual_assert`]: The suggestion now preserves comments - [#9479](https://github.com/rust-lang/rust-clippy/pull/9479) -* [`redundant_allocation`]: The suggestion applicability is now marked `MaybeIncorrect` to - avoid semantic changes - [#9634](https://github.com/rust-lang/rust-clippy/pull/9634) -* [`assertions_on_result_states`]: The suggestion has been corrected, for cases where the - `assert!` is not in a statement. - [#9453](https://github.com/rust-lang/rust-clippy/pull/9453) -* [`nonminimal_bool`]: The suggestion no longer expands macros - [#9457](https://github.com/rust-lang/rust-clippy/pull/9457) -* [`collapsible_match`]: Now specifies field names, when a struct is destructed - [#9685](https://github.com/rust-lang/rust-clippy/pull/9685) -* [`unnecessary_cast`]: The suggestion now adds parenthesis for negative numbers - [#9577](https://github.com/rust-lang/rust-clippy/pull/9577) -* [`redundant_closure`]: The suggestion now works for `impl FnMut` arguments - [#9556](https://github.com/rust-lang/rust-clippy/pull/9556) - -### ICE Fixes - -* [`unnecessary_to_owned`]: Avoid ICEs in favor of false negatives if information is missing - [#9505](https://github.com/rust-lang/rust-clippy/pull/9505) - [#10027](https://github.com/rust-lang/rust-clippy/pull/10027) -* [`manual_range_contains`]: No longer ICEs on values behind references - [#9627](https://github.com/rust-lang/rust-clippy/pull/9627) -* [`needless_pass_by_value`]: No longer ICEs on unsized `dyn Fn` arguments - [#9531](https://github.com/rust-lang/rust-clippy/pull/9531) -* `*_interior_mutable_const` lints: no longer ICE on const unions containing `!Freeze` types - [#9539](https://github.com/rust-lang/rust-clippy/pull/9539) - -### Others - -* Released `rustc_tools_util` for version information on `Crates.io`. (Further adjustments will - not be published as part of this changelog) - -## Rust 1.65 - -Released 2022-11-03 - -[View all 86 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2022-07-29T01%3A09%3A31Z..2022-09-09T00%3A01%3A54Z+base%3Amaster) - -### Important Changes - -* Clippy now has an `--explain ` command to show the lint description in the console - [#8952](https://github.com/rust-lang/rust-clippy/pull/8952) - -### New Lints - -* [`unused_peekable`] - [#9258](https://github.com/rust-lang/rust-clippy/pull/9258) -* [`collapsible_str_replace`] - [#9269](https://github.com/rust-lang/rust-clippy/pull/9269) -* [`manual_string_new`] - [#9295](https://github.com/rust-lang/rust-clippy/pull/9295) -* [`iter_on_empty_collections`] - [#9187](https://github.com/rust-lang/rust-clippy/pull/9187) -* [`iter_on_single_items`] - [#9187](https://github.com/rust-lang/rust-clippy/pull/9187) -* [`bool_to_int_with_if`] - [#9412](https://github.com/rust-lang/rust-clippy/pull/9412) -* [`multi_assignments`] - [#9379](https://github.com/rust-lang/rust-clippy/pull/9379) -* [`result_large_err`] - [#9373](https://github.com/rust-lang/rust-clippy/pull/9373) -* [`partialeq_to_none`] - [#9288](https://github.com/rust-lang/rust-clippy/pull/9288) -* [`suspicious_to_owned`] - [#8984](https://github.com/rust-lang/rust-clippy/pull/8984) -* [`cast_slice_from_raw_parts`] - [#9247](https://github.com/rust-lang/rust-clippy/pull/9247) -* [`manual_instant_elapsed`] - [#9264](https://github.com/rust-lang/rust-clippy/pull/9264) - -### Moves and Deprecations - -* Moved [`significant_drop_in_scrutinee`] to `nursery` (now allow-by-default) - [#9302](https://github.com/rust-lang/rust-clippy/pull/9302) -* Rename `logic_bug` to [`overly_complex_bool_expr`] - [#9306](https://github.com/rust-lang/rust-clippy/pull/9306) -* Rename `arithmetic` to [`arithmetic_side_effects`] - [#9443](https://github.com/rust-lang/rust-clippy/pull/9443) -* Moved [`only_used_in_recursion`] to complexity (now warn-by-default) - [#8804](https://github.com/rust-lang/rust-clippy/pull/8804) -* Moved [`assertions_on_result_states`] to restriction (now allow-by-default) - [#9273](https://github.com/rust-lang/rust-clippy/pull/9273) -* Renamed `blacklisted_name` to [`disallowed_names`] - [#8974](https://github.com/rust-lang/rust-clippy/pull/8974) - -### Enhancements - -* [`option_if_let_else`]: Now also checks for match expressions - [#8696](https://github.com/rust-lang/rust-clippy/pull/8696) -* [`explicit_auto_deref`]: Now lints on implicit returns in closures - [#9126](https://github.com/rust-lang/rust-clippy/pull/9126) -* [`needless_borrow`]: Now considers trait implementations - [#9136](https://github.com/rust-lang/rust-clippy/pull/9136) -* [`suboptimal_flops`], [`imprecise_flops`]: Now lint on constant expressions - [#9404](https://github.com/rust-lang/rust-clippy/pull/9404) -* [`if_let_mutex`]: Now detects mutex behind references and warns about deadlocks - [#9318](https://github.com/rust-lang/rust-clippy/pull/9318) - -### False Positive Fixes - -* [`unit_arg`] [`default_trait_access`] [`missing_docs_in_private_items`]: No longer - trigger in code generated from proc-macros - [#8694](https://github.com/rust-lang/rust-clippy/pull/8694) -* [`unwrap_used`]: Now lints uses of `unwrap_err` - [#9338](https://github.com/rust-lang/rust-clippy/pull/9338) -* [`expect_used`]: Now lints uses of `expect_err` - [#9338](https://github.com/rust-lang/rust-clippy/pull/9338) -* [`transmute_undefined_repr`]: Now longer lints if the first field is compatible - with the other type - [#9287](https://github.com/rust-lang/rust-clippy/pull/9287) -* [`unnecessary_to_owned`]: No longer lints, if type change cased errors in - the caller function - [#9424](https://github.com/rust-lang/rust-clippy/pull/9424) -* [`match_like_matches_macro`]: No longer lints, if there are comments inside the - match expression - [#9276](https://github.com/rust-lang/rust-clippy/pull/9276) -* [`partialeq_to_none`]: No longer trigger in code generated from macros - [#9389](https://github.com/rust-lang/rust-clippy/pull/9389) -* [`arithmetic_side_effects`]: No longer lints expressions that only use literals - [#9365](https://github.com/rust-lang/rust-clippy/pull/9365) -* [`explicit_auto_deref`]: Now ignores references on block expressions when the type - is `Sized`, on `dyn Trait` returns and when the suggestion is non-trivial - [#9126](https://github.com/rust-lang/rust-clippy/pull/9126) -* [`trait_duplication_in_bounds`]: Now better tracks bounds to avoid false positives - [#9167](https://github.com/rust-lang/rust-clippy/pull/9167) -* [`format_in_format_args`]: Now suggests cases where the result is formatted again - [#9349](https://github.com/rust-lang/rust-clippy/pull/9349) -* [`only_used_in_recursion`]: No longer lints on function without recursions and - takes external functions into account - [#8804](https://github.com/rust-lang/rust-clippy/pull/8804) -* [`missing_const_for_fn`]: No longer lints in proc-macros - [#9308](https://github.com/rust-lang/rust-clippy/pull/9308) -* [`non_ascii_literal`]: Allow non-ascii comments in tests and make sure `#[allow]` - attributes work in tests - [#9327](https://github.com/rust-lang/rust-clippy/pull/9327) -* [`question_mark`]: No longer lint `if let`s with subpatterns - [#9348](https://github.com/rust-lang/rust-clippy/pull/9348) -* [`needless_collect`]: No longer lints in loops - [#8992](https://github.com/rust-lang/rust-clippy/pull/8992) -* [`mut_mutex_lock`]: No longer lints if the mutex is behind an immutable reference - [#9418](https://github.com/rust-lang/rust-clippy/pull/9418) -* [`needless_return`]: Now ignores returns with arguments - [#9381](https://github.com/rust-lang/rust-clippy/pull/9381) -* [`range_plus_one`], [`range_minus_one`]: Now ignores code with macros - [#9446](https://github.com/rust-lang/rust-clippy/pull/9446) -* [`assertions_on_result_states`]: No longer lints on the unit type - [#9273](https://github.com/rust-lang/rust-clippy/pull/9273) - -### Suggestion Fixes/Improvements - -* [`unwrap_or_else_default`]: Now suggests `unwrap_or_default()` for empty strings - [#9421](https://github.com/rust-lang/rust-clippy/pull/9421) -* [`if_then_some_else_none`]: Now also suggests `bool::then_some` - [#9289](https://github.com/rust-lang/rust-clippy/pull/9289) -* [`redundant_closure_call`]: The suggestion now works for async closures - [#9053](https://github.com/rust-lang/rust-clippy/pull/9053) -* [`suboptimal_flops`]: Now suggests parenthesis when they are required - [#9394](https://github.com/rust-lang/rust-clippy/pull/9394) -* [`case_sensitive_file_extension_comparisons`]: Now suggests `map_or(..)` instead of `map(..).unwrap_or` - [#9341](https://github.com/rust-lang/rust-clippy/pull/9341) -* Deprecated configuration values can now be updated automatically - [#9252](https://github.com/rust-lang/rust-clippy/pull/9252) -* [`or_fun_call`]: Now suggest `Entry::or_default` for `Entry::or_insert(Default::default())` - [#9342](https://github.com/rust-lang/rust-clippy/pull/9342) -* [`unwrap_used`]: Only suggests `expect` if [`expect_used`] is allowed - [#9223](https://github.com/rust-lang/rust-clippy/pull/9223) - -### ICE Fixes - -* Fix ICE in [`useless_format`] for literals - [#9406](https://github.com/rust-lang/rust-clippy/pull/9406) -* Fix infinite loop in [`vec_init_then_push`] - [#9441](https://github.com/rust-lang/rust-clippy/pull/9441) -* Fix ICE when reading literals with weird proc-macro spans - [#9303](https://github.com/rust-lang/rust-clippy/pull/9303) - -## Rust 1.64 - -Released 2022-09-22 - -[View all 110 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2022-06-17T21%3A25%3A31Z..2022-07-28T17%3A11%3A18Z+base%3Amaster) - -### New Lints - -* [`arithmetic_side_effects`] - [#9130](https://github.com/rust-lang/rust-clippy/pull/9130) -* [`invalid_utf8_in_unchecked`] - [#9105](https://github.com/rust-lang/rust-clippy/pull/9105) -* [`assertions_on_result_states`] - [#9225](https://github.com/rust-lang/rust-clippy/pull/9225) -* [`manual_find`] - [#8649](https://github.com/rust-lang/rust-clippy/pull/8649) -* [`manual_retain`] - [#8972](https://github.com/rust-lang/rust-clippy/pull/8972) -* [`default_instead_of_iter_empty`] - [#8989](https://github.com/rust-lang/rust-clippy/pull/8989) -* [`manual_rem_euclid`] - [#9031](https://github.com/rust-lang/rust-clippy/pull/9031) -* [`obfuscated_if_else`] - [#9148](https://github.com/rust-lang/rust-clippy/pull/9148) -* [`std_instead_of_core`] - [#9103](https://github.com/rust-lang/rust-clippy/pull/9103) -* [`std_instead_of_alloc`] - [#9103](https://github.com/rust-lang/rust-clippy/pull/9103) -* [`alloc_instead_of_core`] - [#9103](https://github.com/rust-lang/rust-clippy/pull/9103) -* [`explicit_auto_deref`] - [#8355](https://github.com/rust-lang/rust-clippy/pull/8355) - - -### Moves and Deprecations - -* Moved [`format_push_string`] to `restriction` (now allow-by-default) - [#9161](https://github.com/rust-lang/rust-clippy/pull/9161) - -### Enhancements - -* [`significant_drop_in_scrutinee`]: Now gives more context in the lint message - [#8981](https://github.com/rust-lang/rust-clippy/pull/8981) -* [`single_match`], [`single_match_else`]: Now catches more `Option` cases - [#8985](https://github.com/rust-lang/rust-clippy/pull/8985) -* [`unused_async`]: Now works for async methods - [#9025](https://github.com/rust-lang/rust-clippy/pull/9025) -* [`manual_filter_map`], [`manual_find_map`]: Now lint more expressions - [#8958](https://github.com/rust-lang/rust-clippy/pull/8958) -* [`question_mark`]: Now works for simple `if let` expressions - [#8356](https://github.com/rust-lang/rust-clippy/pull/8356) -* [`undocumented_unsafe_blocks`]: Now finds comments before the start of closures - [#9117](https://github.com/rust-lang/rust-clippy/pull/9117) -* [`trait_duplication_in_bounds`]: Now catches duplicate bounds in where clauses - [#8703](https://github.com/rust-lang/rust-clippy/pull/8703) -* [`shadow_reuse`], [`shadow_same`], [`shadow_unrelated`]: Now lint in const blocks - [#9124](https://github.com/rust-lang/rust-clippy/pull/9124) -* [`slow_vector_initialization`]: Now detects cases with `vec.capacity()` - [#8953](https://github.com/rust-lang/rust-clippy/pull/8953) -* [`unused_self`]: Now respects the `avoid-breaking-exported-api` config option - [#9199](https://github.com/rust-lang/rust-clippy/pull/9199) -* [`box_collection`]: Now supports all std collections - [#9170](https://github.com/rust-lang/rust-clippy/pull/9170) - -### False Positive Fixes - -* [`significant_drop_in_scrutinee`]: Now ignores calls to `IntoIterator::into_iter` - [#9140](https://github.com/rust-lang/rust-clippy/pull/9140) -* [`while_let_loop`]: Now ignores cases when the significant drop order would change - [#8981](https://github.com/rust-lang/rust-clippy/pull/8981) -* [`branches_sharing_code`]: Now ignores cases where moved variables have a significant - drop or variable modifications can affect the conditions - [#9138](https://github.com/rust-lang/rust-clippy/pull/9138) -* [`let_underscore_lock`]: Now ignores bindings that aren't locked - [#8990](https://github.com/rust-lang/rust-clippy/pull/8990) -* [`trivially_copy_pass_by_ref`]: Now tracks lifetimes and ignores cases where unsafe - pointers are used - [#8639](https://github.com/rust-lang/rust-clippy/pull/8639) -* [`let_unit_value`]: No longer ignores `#[allow]` attributes on the value - [#9082](https://github.com/rust-lang/rust-clippy/pull/9082) -* [`declare_interior_mutable_const`]: Now ignores the `thread_local!` macro - [#9015](https://github.com/rust-lang/rust-clippy/pull/9015) -* [`if_same_then_else`]: Now ignores branches with `todo!` and `unimplemented!` - [#9006](https://github.com/rust-lang/rust-clippy/pull/9006) -* [`enum_variant_names`]: Now ignores names with `_` prefixes - [#9032](https://github.com/rust-lang/rust-clippy/pull/9032) -* [`let_unit_value`]: Now ignores cases, where the unit type is manually specified - [#9056](https://github.com/rust-lang/rust-clippy/pull/9056) -* [`match_same_arms`]: Now ignores branches with `todo!` - [#9207](https://github.com/rust-lang/rust-clippy/pull/9207) -* [`assign_op_pattern`]: Ignores cases that break borrowing rules - [#9214](https://github.com/rust-lang/rust-clippy/pull/9214) -* [`extra_unused_lifetimes`]: No longer triggers in derive macros - [#9037](https://github.com/rust-lang/rust-clippy/pull/9037) -* [`mismatching_type_param_order`]: Now ignores complicated generic parameters - [#9146](https://github.com/rust-lang/rust-clippy/pull/9146) -* [`equatable_if_let`]: No longer lints in macros - [#9074](https://github.com/rust-lang/rust-clippy/pull/9074) -* [`new_without_default`]: Now ignores generics and lifetime parameters on `fn new` - [#9115](https://github.com/rust-lang/rust-clippy/pull/9115) -* [`needless_borrow`]: Now ignores cases that result in the execution of different traits - [#9096](https://github.com/rust-lang/rust-clippy/pull/9096) -* [`declare_interior_mutable_const`]: No longer triggers in thread-local initializers - [#9246](https://github.com/rust-lang/rust-clippy/pull/9246) - -### Suggestion Fixes/Improvements - -* [`type_repetition_in_bounds`]: The suggestion now works with maybe bounds - [#9132](https://github.com/rust-lang/rust-clippy/pull/9132) -* [`transmute_ptr_to_ref`]: Now suggests `pointer::cast` when possible - [#8939](https://github.com/rust-lang/rust-clippy/pull/8939) -* [`useless_format`]: Now suggests the correct variable name - [#9237](https://github.com/rust-lang/rust-clippy/pull/9237) -* [`or_fun_call`]: The lint emission will now only span over the `unwrap_or` call - [#9144](https://github.com/rust-lang/rust-clippy/pull/9144) -* [`neg_multiply`]: Now suggests adding parentheses around suggestion if needed - [#9026](https://github.com/rust-lang/rust-clippy/pull/9026) -* [`unnecessary_lazy_evaluations`]: Now suggest for `bool::then_some` for lazy evaluation - [#9099](https://github.com/rust-lang/rust-clippy/pull/9099) -* [`manual_flatten`]: Improved message for long code snippets - [#9156](https://github.com/rust-lang/rust-clippy/pull/9156) -* [`explicit_counter_loop`]: The suggestion is now machine applicable - [#9149](https://github.com/rust-lang/rust-clippy/pull/9149) -* [`needless_borrow`]: Now keeps parentheses around fields, when needed - [#9210](https://github.com/rust-lang/rust-clippy/pull/9210) -* [`while_let_on_iterator`]: The suggestion now works in `FnOnce` closures - [#9134](https://github.com/rust-lang/rust-clippy/pull/9134) - -### ICE Fixes - -* Fix ICEs related to `#![feature(generic_const_exprs)]` usage - [#9241](https://github.com/rust-lang/rust-clippy/pull/9241) -* Fix ICEs related to reference lints - [#9093](https://github.com/rust-lang/rust-clippy/pull/9093) -* [`question_mark`]: Fix ICE on zero field tuple structs - [#9244](https://github.com/rust-lang/rust-clippy/pull/9244) - -### Documentation Improvements - -* [`needless_option_take`]: Now includes a "What it does" and "Why is this bad?" section. - [#9022](https://github.com/rust-lang/rust-clippy/pull/9022) - -### Others - -* Using `--cap-lints=allow` and only `--force-warn`ing some will now work with Clippy's driver - [#9036](https://github.com/rust-lang/rust-clippy/pull/9036) -* Clippy now tries to read the `rust-version` from `Cargo.toml` to identify the - minimum supported rust version - [#8774](https://github.com/rust-lang/rust-clippy/pull/8774) - -## Rust 1.63 - -Released 2022-08-11 - -[View all 91 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2022-05-05T17%3A24%3A22Z..2022-06-16T14%3A24%3A48Z+base%3Amaster) - -### New Lints - -* [`borrow_deref_ref`] - [#7930](https://github.com/rust-lang/rust-clippy/pull/7930) -* [`doc_link_with_quotes`] - [#8385](https://github.com/rust-lang/rust-clippy/pull/8385) -* [`no_effect_replace`] - [#8754](https://github.com/rust-lang/rust-clippy/pull/8754) -* [`rc_clone_in_vec_init`] - [#8769](https://github.com/rust-lang/rust-clippy/pull/8769) -* [`derive_partial_eq_without_eq`] - [#8796](https://github.com/rust-lang/rust-clippy/pull/8796) -* [`mismatching_type_param_order`] - [#8831](https://github.com/rust-lang/rust-clippy/pull/8831) -* [`duplicate_mod`] [#8832](https://github.com/rust-lang/rust-clippy/pull/8832) -* [`unused_rounding`] - [#8866](https://github.com/rust-lang/rust-clippy/pull/8866) -* [`get_first`] [#8882](https://github.com/rust-lang/rust-clippy/pull/8882) -* [`swap_ptr_to_ref`] - [#8916](https://github.com/rust-lang/rust-clippy/pull/8916) -* [`almost_complete_letter_range`] - [#8918](https://github.com/rust-lang/rust-clippy/pull/8918) -* [`needless_parens_on_range_literals`] - [#8933](https://github.com/rust-lang/rust-clippy/pull/8933) -* [`as_underscore`] [#8934](https://github.com/rust-lang/rust-clippy/pull/8934) - -### Moves and Deprecations - -* Rename `eval_order_dependence` to [`mixed_read_write_in_expression`], move to - `nursery` [#8621](https://github.com/rust-lang/rust-clippy/pull/8621) - -### Enhancements - -* [`undocumented_unsafe_blocks`]: Now also lints on unsafe trait implementations - [#8761](https://github.com/rust-lang/rust-clippy/pull/8761) -* [`empty_line_after_outer_attr`]: Now also lints on argumentless macros - [#8790](https://github.com/rust-lang/rust-clippy/pull/8790) -* [`expect_used`]: Now can be disabled in tests with the `allow-expect-in-tests` - option [#8802](https://github.com/rust-lang/rust-clippy/pull/8802) -* [`unwrap_used`]: Now can be disabled in tests with the `allow-unwrap-in-tests` - option [#8802](https://github.com/rust-lang/rust-clippy/pull/8802) -* [`disallowed_methods`]: Now also lints indirect usages - [#8852](https://github.com/rust-lang/rust-clippy/pull/8852) -* [`get_last_with_len`]: Now also lints `VecDeque` and any deref to slice - [#8862](https://github.com/rust-lang/rust-clippy/pull/8862) -* [`manual_range_contains`]: Now also lints on chains of `&&` and `||` - [#8884](https://github.com/rust-lang/rust-clippy/pull/8884) -* [`rc_clone_in_vec_init`]: Now also lints on `Weak` - [#8885](https://github.com/rust-lang/rust-clippy/pull/8885) -* [`dbg_macro`]: Introduce `allow-dbg-in-tests` config option - [#8897](https://github.com/rust-lang/rust-clippy/pull/8897) -* [`use_self`]: Now also lints on `TupleStruct` and `Struct` patterns - [#8899](https://github.com/rust-lang/rust-clippy/pull/8899) -* [`manual_find_map`] and [`manual_filter_map`]: Now also lints on more complex - method chains inside `map` - [#8930](https://github.com/rust-lang/rust-clippy/pull/8930) -* [`needless_return`]: Now also lints on macro expressions in return statements - [#8932](https://github.com/rust-lang/rust-clippy/pull/8932) -* [`doc_markdown`]: Users can now indicate, that the `doc-valid-idents` config - should extend the default and not replace it - [#8944](https://github.com/rust-lang/rust-clippy/pull/8944) -* [`disallowed_names`]: Users can now indicate, that the `disallowed-names` - config should extend the default and not replace it - [#8944](https://github.com/rust-lang/rust-clippy/pull/8944) -* [`never_loop`]: Now checks for `continue` in struct expression - [#9002](https://github.com/rust-lang/rust-clippy/pull/9002) - -### False Positive Fixes - -* [`useless_transmute`]: No longer lints on types with erased regions - [#8564](https://github.com/rust-lang/rust-clippy/pull/8564) -* [`vec_init_then_push`]: No longer lints when further extended - [#8699](https://github.com/rust-lang/rust-clippy/pull/8699) -* [`cmp_owned`]: No longer lints on `From::from` for `Copy` types - [#8807](https://github.com/rust-lang/rust-clippy/pull/8807) -* [`redundant_allocation`]: No longer lints on fat pointers that would become - thin pointers [#8813](https://github.com/rust-lang/rust-clippy/pull/8813) -* [`derive_partial_eq_without_eq`]: - * Handle differing predicates applied by `#[derive(PartialEq)]` and - `#[derive(Eq)]` - [#8869](https://github.com/rust-lang/rust-clippy/pull/8869) - * No longer lints on non-public types and better handles generics - [#8950](https://github.com/rust-lang/rust-clippy/pull/8950) -* [`empty_line_after_outer_attr`]: No longer lints empty lines in inner - string values [#8892](https://github.com/rust-lang/rust-clippy/pull/8892) -* [`branches_sharing_code`]: No longer lints when using different binding names - [#8901](https://github.com/rust-lang/rust-clippy/pull/8901) -* [`significant_drop_in_scrutinee`]: No longer lints on Try `?` and `await` - desugared expressions [#8902](https://github.com/rust-lang/rust-clippy/pull/8902) -* [`checked_conversions`]: No longer lints in `const` contexts - [#8907](https://github.com/rust-lang/rust-clippy/pull/8907) -* [`iter_overeager_cloned`]: No longer lints on `.cloned().flatten()` when - `T::Item` doesn't implement `IntoIterator` - [#8960](https://github.com/rust-lang/rust-clippy/pull/8960) - -### Suggestion Fixes/Improvements - -* [`vec_init_then_push`]: Suggest to remove `mut` binding when possible - [#8699](https://github.com/rust-lang/rust-clippy/pull/8699) -* [`manual_range_contains`]: Fix suggestion for integers with different signs - [#8763](https://github.com/rust-lang/rust-clippy/pull/8763) -* [`identity_op`]: Add parenthesis to suggestions where required - [#8786](https://github.com/rust-lang/rust-clippy/pull/8786) -* [`cast_lossless`]: No longer gives wrong suggestion on `usize`/`isize`->`f64` - [#8778](https://github.com/rust-lang/rust-clippy/pull/8778) -* [`rc_clone_in_vec_init`]: Add suggestion - [#8814](https://github.com/rust-lang/rust-clippy/pull/8814) -* The "unknown field" error messages for config files now wraps the field names - [#8823](https://github.com/rust-lang/rust-clippy/pull/8823) -* [`cast_abs_to_unsigned`]: Do not remove cast if it's required - [#8876](https://github.com/rust-lang/rust-clippy/pull/8876) -* [`significant_drop_in_scrutinee`]: Improve lint message for types that are not - references and not trivially clone-able - [#8902](https://github.com/rust-lang/rust-clippy/pull/8902) -* [`for_loops_over_fallibles`]: Now suggests the correct variant of `iter()`, - `iter_mut()` or `into_iter()` - [#8941](https://github.com/rust-lang/rust-clippy/pull/8941) - -### ICE Fixes - -* Fix ICE in [`let_unit_value`] when calling a `static`/`const` callable type - [#8835](https://github.com/rust-lang/rust-clippy/pull/8835) -* Fix ICEs on callable `static`/`const`s - [#8896](https://github.com/rust-lang/rust-clippy/pull/8896) -* [`needless_late_init`] - [#8912](https://github.com/rust-lang/rust-clippy/pull/8912) -* Fix ICE in shadow lints - [#8913](https://github.com/rust-lang/rust-clippy/pull/8913) - -### Documentation Improvements - -* Clippy has a [Book](https://doc.rust-lang.org/nightly/clippy/) now! - [#7359](https://github.com/rust-lang/rust-clippy/pull/7359) -* Add a *copy lint name*-button to Clippy's lint list - [#8839](https://github.com/rust-lang/rust-clippy/pull/8839) -* Display past names of renamed lints on Clippy's lint list - [#8843](https://github.com/rust-lang/rust-clippy/pull/8843) -* Add the ability to show the lint output in the lint list - [#8947](https://github.com/rust-lang/rust-clippy/pull/8947) - -## Rust 1.62 - -Released 2022-06-30 - -[View all 90 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2022-03-25T17%3A22%3A30Z..2022-05-05T13%3A29%3A44Z+base%3Amaster) - -### New Lints - -* [`large_include_file`] - [#8727](https://github.com/rust-lang/rust-clippy/pull/8727) -* [`cast_abs_to_unsigned`] - [#8635](https://github.com/rust-lang/rust-clippy/pull/8635) -* [`err_expect`] - [#8606](https://github.com/rust-lang/rust-clippy/pull/8606) -* [`unnecessary_owned_empty_strings`] - [#8660](https://github.com/rust-lang/rust-clippy/pull/8660) -* [`empty_structs_with_brackets`] - [#8594](https://github.com/rust-lang/rust-clippy/pull/8594) -* [`crate_in_macro_def`] - [#8576](https://github.com/rust-lang/rust-clippy/pull/8576) -* [`needless_option_take`] - [#8665](https://github.com/rust-lang/rust-clippy/pull/8665) -* [`bytes_count_to_len`] - [#8711](https://github.com/rust-lang/rust-clippy/pull/8711) -* [`is_digit_ascii_radix`] - [#8624](https://github.com/rust-lang/rust-clippy/pull/8624) -* [`await_holding_invalid_type`] - [#8707](https://github.com/rust-lang/rust-clippy/pull/8707) -* [`trim_split_whitespace`] - [#8575](https://github.com/rust-lang/rust-clippy/pull/8575) -* [`pub_use`] - [#8670](https://github.com/rust-lang/rust-clippy/pull/8670) -* [`format_push_string`] - [#8626](https://github.com/rust-lang/rust-clippy/pull/8626) -* [`empty_drop`] - [#8571](https://github.com/rust-lang/rust-clippy/pull/8571) -* [`drop_non_drop`] - [#8630](https://github.com/rust-lang/rust-clippy/pull/8630) -* [`forget_non_drop`] - [#8630](https://github.com/rust-lang/rust-clippy/pull/8630) - -### Moves and Deprecations - -* Move [`only_used_in_recursion`] to `nursery` (now allow-by-default) - [#8783](https://github.com/rust-lang/rust-clippy/pull/8783) -* Move [`stable_sort_primitive`] to `pedantic` (now allow-by-default) - [#8716](https://github.com/rust-lang/rust-clippy/pull/8716) - -### Enhancements - -* Remove overlap between [`manual_split_once`] and [`needless_splitn`] - [#8631](https://github.com/rust-lang/rust-clippy/pull/8631) -* [`map_identity`]: Now checks for needless `map_err` - [#8487](https://github.com/rust-lang/rust-clippy/pull/8487) -* [`extra_unused_lifetimes`]: Now checks for impl lifetimes - [#8737](https://github.com/rust-lang/rust-clippy/pull/8737) -* [`cast_possible_truncation`]: Now catches more cases with larger shift or divide operations - [#8687](https://github.com/rust-lang/rust-clippy/pull/8687) -* [`identity_op`]: Now checks for modulo expressions - [#8519](https://github.com/rust-lang/rust-clippy/pull/8519) -* [`panic`]: No longer lint in constant context - [#8592](https://github.com/rust-lang/rust-clippy/pull/8592) -* [`manual_split_once`]: Now lints manual iteration of `splitn` - [#8717](https://github.com/rust-lang/rust-clippy/pull/8717) -* [`self_named_module_files`], [`mod_module_files`]: Now handle relative module paths - [#8611](https://github.com/rust-lang/rust-clippy/pull/8611) -* [`unsound_collection_transmute`]: Now has better size and alignment checks - [#8648](https://github.com/rust-lang/rust-clippy/pull/8648) -* [`unnested_or_patterns`]: Ignore cases, where the suggestion would be longer - [#8619](https://github.com/rust-lang/rust-clippy/pull/8619) - -### False Positive Fixes - -* [`rest_pat_in_fully_bound_structs`]: Now ignores structs marked with `#[non_exhaustive]` - [#8690](https://github.com/rust-lang/rust-clippy/pull/8690) -* [`needless_late_init`]: No longer lints `if let` statements, `let mut` bindings or instances that - changes the drop order significantly - [#8617](https://github.com/rust-lang/rust-clippy/pull/8617) -* [`unnecessary_cast`]: No longer lints to casts to aliased or non-primitive types - [#8596](https://github.com/rust-lang/rust-clippy/pull/8596) -* [`init_numbered_fields`]: No longer lints type aliases - [#8780](https://github.com/rust-lang/rust-clippy/pull/8780) -* [`needless_option_as_deref`]: No longer lints for `as_deref_mut` on `Option` values that can't be moved - [#8646](https://github.com/rust-lang/rust-clippy/pull/8646) -* [`mistyped_literal_suffixes`]: Now ignores float literals without an exponent - [#8742](https://github.com/rust-lang/rust-clippy/pull/8742) -* [`undocumented_unsafe_blocks`]: Now ignores unsafe blocks from proc-macros and works better for sub-expressions - [#8450](https://github.com/rust-lang/rust-clippy/pull/8450) -* [`same_functions_in_if_condition`]: Now allows different constants, even if they have the same value - [#8673](https://github.com/rust-lang/rust-clippy/pull/8673) -* [`needless_match`]: Now checks for more complex types and ignores type coercion - [#8549](https://github.com/rust-lang/rust-clippy/pull/8549) -* [`assertions_on_constants`]: Now ignores constants from `cfg!` macros - [#8614](https://github.com/rust-lang/rust-clippy/pull/8614) -* [`indexing_slicing`]: Fix false positives with constant indices in - [#8588](https://github.com/rust-lang/rust-clippy/pull/8588) -* [`iter_with_drain`]: Now ignores iterator references - [#8668](https://github.com/rust-lang/rust-clippy/pull/8668) -* [`useless_attribute`]: Now allows [`redundant_pub_crate`] on `use` items - [#8743](https://github.com/rust-lang/rust-clippy/pull/8743) -* [`cast_ptr_alignment`]: Now ignores expressions, when used for unaligned reads and writes - [#8632](https://github.com/rust-lang/rust-clippy/pull/8632) -* [`wrong_self_convention`]: Now allows `&mut self` and no self as arguments for `is_*` methods - [#8738](https://github.com/rust-lang/rust-clippy/pull/8738) -* [`mut_from_ref`]: Only lint in unsafe code - [#8647](https://github.com/rust-lang/rust-clippy/pull/8647) -* [`redundant_pub_crate`]: Now allows macro exports - [#8736](https://github.com/rust-lang/rust-clippy/pull/8736) -* [`needless_match`]: Ignores cases where the else block expression is different - [#8700](https://github.com/rust-lang/rust-clippy/pull/8700) -* [`transmute_int_to_char`]: Now allows transmutations in `const` code - [#8610](https://github.com/rust-lang/rust-clippy/pull/8610) -* [`manual_non_exhaustive`]: Ignores cases, where the enum value is used - [#8645](https://github.com/rust-lang/rust-clippy/pull/8645) -* [`redundant_closure`]: Now ignores coerced closure - [#8431](https://github.com/rust-lang/rust-clippy/pull/8431) -* [`identity_op`]: Is now ignored in cases where extra brackets would be needed - [#8730](https://github.com/rust-lang/rust-clippy/pull/8730) -* [`let_unit_value`]: Now ignores cases which are used for type inference - [#8563](https://github.com/rust-lang/rust-clippy/pull/8563) - -### Suggestion Fixes/Improvements - -* [`manual_split_once`]: Fixed incorrect suggestions for single result accesses - [#8631](https://github.com/rust-lang/rust-clippy/pull/8631) -* [`bytes_nth`]: Fix typos in the diagnostic message - [#8403](https://github.com/rust-lang/rust-clippy/pull/8403) -* [`mistyped_literal_suffixes`]: Now suggests the correct integer types - [#8742](https://github.com/rust-lang/rust-clippy/pull/8742) -* [`unnecessary_to_owned`]: Fixed suggestion based on the configured msrv - [#8692](https://github.com/rust-lang/rust-clippy/pull/8692) -* [`single_element_loop`]: Improve lint for Edition 2021 arrays - [#8616](https://github.com/rust-lang/rust-clippy/pull/8616) -* [`manual_bits`]: Now includes a cast for proper type conversion, when needed - [#8677](https://github.com/rust-lang/rust-clippy/pull/8677) -* [`option_map_unit_fn`], [`result_map_unit_fn`]: Fix some incorrect suggestions - [#8584](https://github.com/rust-lang/rust-clippy/pull/8584) -* [`collapsible_else_if`]: Add whitespace in suggestion - [#8729](https://github.com/rust-lang/rust-clippy/pull/8729) -* [`transmute_bytes_to_str`]: Now suggest `from_utf8_unchecked` in `const` context - [#8612](https://github.com/rust-lang/rust-clippy/pull/8612) -* [`map_clone`]: Improve message and suggestion based on the msrv - [#8688](https://github.com/rust-lang/rust-clippy/pull/8688) -* [`needless_late_init`]: Now shows the `let` statement where it was first initialized - [#8779](https://github.com/rust-lang/rust-clippy/pull/8779) - -### ICE Fixes - -* [`only_used_in_recursion`] - [#8691](https://github.com/rust-lang/rust-clippy/pull/8691) -* [`cast_slice_different_sizes`] - [#8720](https://github.com/rust-lang/rust-clippy/pull/8720) -* [`iter_overeager_cloned`] - [#8602](https://github.com/rust-lang/rust-clippy/pull/8602) -* [`undocumented_unsafe_blocks`] - [#8686](https://github.com/rust-lang/rust-clippy/pull/8686) - -## Rust 1.61 - -Released 2022-05-19 - -[View all 60 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2022-02-11T16%3A54%3A41Z..2022-03-24T13%3A42%3A25Z+base%3Amaster) - -### New Lints - -* [`only_used_in_recursion`] - [#8422](https://github.com/rust-lang/rust-clippy/pull/8422) -* [`cast_enum_truncation`] - [#8381](https://github.com/rust-lang/rust-clippy/pull/8381) -* [`missing_spin_loop`] - [#8174](https://github.com/rust-lang/rust-clippy/pull/8174) -* [`deref_by_slicing`] - [#8218](https://github.com/rust-lang/rust-clippy/pull/8218) -* [`needless_match`] - [#8471](https://github.com/rust-lang/rust-clippy/pull/8471) -* [`allow_attributes_without_reason`] (Requires `#![feature(lint_reasons)]`) - [#8504](https://github.com/rust-lang/rust-clippy/pull/8504) -* [`print_in_format_impl`] - [#8253](https://github.com/rust-lang/rust-clippy/pull/8253) -* [`unnecessary_find_map`] - [#8489](https://github.com/rust-lang/rust-clippy/pull/8489) -* [`or_then_unwrap`] - [#8561](https://github.com/rust-lang/rust-clippy/pull/8561) -* [`unnecessary_join`] - [#8579](https://github.com/rust-lang/rust-clippy/pull/8579) -* [`iter_with_drain`] - [#8483](https://github.com/rust-lang/rust-clippy/pull/8483) -* [`cast_enum_constructor`] - [#8562](https://github.com/rust-lang/rust-clippy/pull/8562) -* [`cast_slice_different_sizes`] - [#8445](https://github.com/rust-lang/rust-clippy/pull/8445) - -### Moves and Deprecations - -* Moved [`transmute_undefined_repr`] to `nursery` (now allow-by-default) - [#8432](https://github.com/rust-lang/rust-clippy/pull/8432) -* Moved [`try_err`] to `restriction` - [#8544](https://github.com/rust-lang/rust-clippy/pull/8544) -* Move [`iter_with_drain`] to `nursery` - [#8541](https://github.com/rust-lang/rust-clippy/pull/8541) -* Renamed `to_string_in_display` to [`recursive_format_impl`] - [#8188](https://github.com/rust-lang/rust-clippy/pull/8188) - -### Enhancements - -* [`dbg_macro`]: The lint level can now be set with crate attributes and works inside macros - [#8411](https://github.com/rust-lang/rust-clippy/pull/8411) -* [`ptr_as_ptr`]: Now works inside macros - [#8442](https://github.com/rust-lang/rust-clippy/pull/8442) -* [`use_self`]: Now works for variants in match expressions - [#8456](https://github.com/rust-lang/rust-clippy/pull/8456) -* [`await_holding_lock`]: Now lints for `parking_lot::{Mutex, RwLock}` - [#8419](https://github.com/rust-lang/rust-clippy/pull/8419) -* [`recursive_format_impl`]: Now checks for format calls on `self` - [#8188](https://github.com/rust-lang/rust-clippy/pull/8188) - -### False Positive Fixes - -* [`new_without_default`]: No longer lints for `new()` methods with `#[doc(hidden)]` - [#8472](https://github.com/rust-lang/rust-clippy/pull/8472) -* [`transmute_undefined_repr`]: No longer lints for single field structs with `#[repr(C)]`, - generic parameters, wide pointers, unions, tuples and allow several forms of type erasure - [#8425](https://github.com/rust-lang/rust-clippy/pull/8425) - [#8553](https://github.com/rust-lang/rust-clippy/pull/8553) - [#8440](https://github.com/rust-lang/rust-clippy/pull/8440) - [#8547](https://github.com/rust-lang/rust-clippy/pull/8547) -* [`match_single_binding`], [`match_same_arms`], [`match_as_ref`], [`match_bool`]: No longer - lint `match` expressions with `cfg`ed arms - [#8443](https://github.com/rust-lang/rust-clippy/pull/8443) -* [`single_component_path_imports`]: No longer lint on macros - [#8537](https://github.com/rust-lang/rust-clippy/pull/8537) -* [`ptr_arg`]: Allow `&mut` arguments for `Cow<_>` - [#8552](https://github.com/rust-lang/rust-clippy/pull/8552) -* [`needless_borrow`]: No longer lints for method calls - [#8441](https://github.com/rust-lang/rust-clippy/pull/8441) -* [`match_same_arms`]: Now ensures that interposing arm patterns don't overlap - [#8232](https://github.com/rust-lang/rust-clippy/pull/8232) -* [`default_trait_access`]: Now allows `Default::default` in update expressions - [#8433](https://github.com/rust-lang/rust-clippy/pull/8433) - -### Suggestion Fixes/Improvements - -* [`redundant_slicing`]: Fixed suggestion for a method calls - [#8218](https://github.com/rust-lang/rust-clippy/pull/8218) -* [`map_flatten`]: Long suggestions will now be split up into two help messages - [#8520](https://github.com/rust-lang/rust-clippy/pull/8520) -* [`unnecessary_lazy_evaluations`]: Now shows suggestions for longer code snippets - [#8543](https://github.com/rust-lang/rust-clippy/pull/8543) -* [`unnecessary_sort_by`]: Now suggests `Reverse` including the path - [#8462](https://github.com/rust-lang/rust-clippy/pull/8462) -* [`search_is_some`]: More suggestions are now `MachineApplicable` - [#8536](https://github.com/rust-lang/rust-clippy/pull/8536) - -### Documentation Improvements - -* [`new_without_default`]: Document `pub` requirement for the struct and fields - [#8429](https://github.com/rust-lang/rust-clippy/pull/8429) - -## Rust 1.60 - -Released 2022-04-07 - -[View all 73 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2021-12-31T17%3A53%3A37Z..2022-02-10T17%3A31%3A37Z+base%3Amaster) - -### New Lints - -* [`single_char_lifetime_names`] - [#8236](https://github.com/rust-lang/rust-clippy/pull/8236) -* [`iter_overeager_cloned`] - [#8203](https://github.com/rust-lang/rust-clippy/pull/8203) -* [`transmute_undefined_repr`] - [#8398](https://github.com/rust-lang/rust-clippy/pull/8398) -* [`default_union_representation`] - [#8289](https://github.com/rust-lang/rust-clippy/pull/8289) -* [`manual_bits`] - [#8213](https://github.com/rust-lang/rust-clippy/pull/8213) -* [`borrow_as_ptr`] - [#8210](https://github.com/rust-lang/rust-clippy/pull/8210) - -### Moves and Deprecations - -* Moved [`disallowed_methods`] and [`disallowed_types`] to `style` (now warn-by-default) - [#8261](https://github.com/rust-lang/rust-clippy/pull/8261) -* Rename `ref_in_deref` to [`needless_borrow`] - [#8217](https://github.com/rust-lang/rust-clippy/pull/8217) -* Moved [`mutex_atomic`] to `nursery` (now allow-by-default) - [#8260](https://github.com/rust-lang/rust-clippy/pull/8260) - -### Enhancements - -* [`ptr_arg`]: Now takes the argument usage into account and lints for mutable references - [#8271](https://github.com/rust-lang/rust-clippy/pull/8271) -* [`unused_io_amount`]: Now supports async read and write traits - [#8179](https://github.com/rust-lang/rust-clippy/pull/8179) -* [`while_let_on_iterator`]: Improved detection to catch more cases - [#8221](https://github.com/rust-lang/rust-clippy/pull/8221) -* [`trait_duplication_in_bounds`]: Now covers trait functions with `Self` bounds - [#8252](https://github.com/rust-lang/rust-clippy/pull/8252) -* [`unwrap_used`]: Now works for `.get(i).unwrap()` and `.get_mut(i).unwrap()` - [#8372](https://github.com/rust-lang/rust-clippy/pull/8372) -* [`map_clone`]: The suggestion takes `msrv` into account - [#8280](https://github.com/rust-lang/rust-clippy/pull/8280) -* [`manual_bits`] and [`borrow_as_ptr`]: Now track the `clippy::msrv` attribute - [#8280](https://github.com/rust-lang/rust-clippy/pull/8280) -* [`disallowed_methods`]: Now works for methods on primitive types - [#8112](https://github.com/rust-lang/rust-clippy/pull/8112) -* [`not_unsafe_ptr_arg_deref`]: Now works for type aliases - [#8273](https://github.com/rust-lang/rust-clippy/pull/8273) -* [`needless_question_mark`]: Now works for async functions - [#8311](https://github.com/rust-lang/rust-clippy/pull/8311) -* [`iter_not_returning_iterator`]: Now handles type projections - [#8228](https://github.com/rust-lang/rust-clippy/pull/8228) -* [`wrong_self_convention`]: Now detects wrong `self` references in more cases - [#8208](https://github.com/rust-lang/rust-clippy/pull/8208) -* [`single_match`]: Now works for `match` statements with tuples - [#8322](https://github.com/rust-lang/rust-clippy/pull/8322) - -### False Positive Fixes - -* [`erasing_op`]: No longer triggers if the output type changes - [#8204](https://github.com/rust-lang/rust-clippy/pull/8204) -* [`if_same_then_else`]: No longer triggers for `if let` statements - [#8297](https://github.com/rust-lang/rust-clippy/pull/8297) -* [`manual_memcpy`]: No longer lints on `VecDeque` - [#8226](https://github.com/rust-lang/rust-clippy/pull/8226) -* [`trait_duplication_in_bounds`]: Now takes path segments into account - [#8315](https://github.com/rust-lang/rust-clippy/pull/8315) -* [`deref_addrof`]: No longer lints when the dereference or borrow occurs in different a context - [#8268](https://github.com/rust-lang/rust-clippy/pull/8268) -* [`type_repetition_in_bounds`]: Now checks for full equality to prevent false positives - [#8224](https://github.com/rust-lang/rust-clippy/pull/8224) -* [`ptr_arg`]: No longer lint for mutable references in traits - [#8369](https://github.com/rust-lang/rust-clippy/pull/8369) -* [`implicit_clone`]: No longer lints for double references - [#8231](https://github.com/rust-lang/rust-clippy/pull/8231) -* [`needless_lifetimes`]: No longer lints lifetimes for explicit `self` types - [#8278](https://github.com/rust-lang/rust-clippy/pull/8278) -* [`op_ref`]: No longer lints in `BinOp` impl if that can cause recursion - [#8298](https://github.com/rust-lang/rust-clippy/pull/8298) -* [`enum_variant_names`]: No longer triggers for empty variant names - [#8329](https://github.com/rust-lang/rust-clippy/pull/8329) -* [`redundant_closure`]: No longer lints for `Arc` or `Rc` - [#8193](https://github.com/rust-lang/rust-clippy/pull/8193) -* [`iter_not_returning_iterator`]: No longer lints on trait implementations but therefore on trait definitions - [#8228](https://github.com/rust-lang/rust-clippy/pull/8228) -* [`single_match`]: No longer lints on exhaustive enum patterns without a wildcard - [#8322](https://github.com/rust-lang/rust-clippy/pull/8322) -* [`manual_swap`]: No longer lints on cases that involve automatic dereferences - [#8220](https://github.com/rust-lang/rust-clippy/pull/8220) -* [`useless_format`]: Now works for implicit named arguments - [#8295](https://github.com/rust-lang/rust-clippy/pull/8295) - -### Suggestion Fixes/Improvements - -* [`needless_borrow`]: Prevent mutable borrows being moved and suggest removing the borrow on method calls - [#8217](https://github.com/rust-lang/rust-clippy/pull/8217) -* [`chars_next_cmp`]: Correctly escapes the suggestion - [#8376](https://github.com/rust-lang/rust-clippy/pull/8376) -* [`explicit_write`]: Add suggestions for `write!`s with format arguments - [#8365](https://github.com/rust-lang/rust-clippy/pull/8365) -* [`manual_memcpy`]: Suggests `copy_from_slice` when applicable - [#8226](https://github.com/rust-lang/rust-clippy/pull/8226) -* [`or_fun_call`]: Improved suggestion display for long arguments - [#8292](https://github.com/rust-lang/rust-clippy/pull/8292) -* [`unnecessary_cast`]: Now correctly includes the sign - [#8350](https://github.com/rust-lang/rust-clippy/pull/8350) -* [`cmp_owned`]: No longer flips the comparison order - [#8299](https://github.com/rust-lang/rust-clippy/pull/8299) -* [`explicit_counter_loop`]: Now correctly suggests `iter()` on references - [#8382](https://github.com/rust-lang/rust-clippy/pull/8382) - -### ICE Fixes - -* [`manual_split_once`] - [#8250](https://github.com/rust-lang/rust-clippy/pull/8250) - -### Documentation Improvements - -* [`map_flatten`]: Add documentation for the `Option` type - [#8354](https://github.com/rust-lang/rust-clippy/pull/8354) -* Document that Clippy's driver might use a different code generation than rustc - [#8037](https://github.com/rust-lang/rust-clippy/pull/8037) -* Clippy's lint list will now automatically focus the search box - [#8343](https://github.com/rust-lang/rust-clippy/pull/8343) - -### Others - -* Clippy now warns if we find multiple Clippy config files exist - [#8326](https://github.com/rust-lang/rust-clippy/pull/8326) - -## Rust 1.59 - -Released 2022-02-24 - -[View all 94 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2021-11-04T12%3A40%3A18Z..2021-12-30T13%3A36%3A20Z+base%3Amaster) - -### New Lints - -* [`index_refutable_slice`] - [#7643](https://github.com/rust-lang/rust-clippy/pull/7643) -* [`needless_splitn`] - [#7896](https://github.com/rust-lang/rust-clippy/pull/7896) -* [`unnecessary_to_owned`] - [#7978](https://github.com/rust-lang/rust-clippy/pull/7978) -* [`needless_late_init`] - [#7995](https://github.com/rust-lang/rust-clippy/pull/7995) -* [`octal_escapes`] [#8007](https://github.com/rust-lang/rust-clippy/pull/8007) -* [`return_self_not_must_use`] - [#8071](https://github.com/rust-lang/rust-clippy/pull/8071) -* [`init_numbered_fields`] - [#8170](https://github.com/rust-lang/rust-clippy/pull/8170) - -### Moves and Deprecations - -* Move `if_then_panic` to `pedantic` and rename to [`manual_assert`] (now - allow-by-default) [#7810](https://github.com/rust-lang/rust-clippy/pull/7810) -* Rename `disallow_type` to [`disallowed_types`] and `disallowed_method` to - [`disallowed_methods`] - [#7984](https://github.com/rust-lang/rust-clippy/pull/7984) -* Move [`map_flatten`] to `complexity` (now warn-by-default) - [#8054](https://github.com/rust-lang/rust-clippy/pull/8054) - -### Enhancements - -* [`match_overlapping_arm`]: Fix false negative where after included ranges, - overlapping ranges weren't linted anymore - [#7909](https://github.com/rust-lang/rust-clippy/pull/7909) -* [`deprecated_cfg_attr`]: Now takes the specified MSRV into account - [#7944](https://github.com/rust-lang/rust-clippy/pull/7944) -* [`cast_lossless`]: Now also lints for `bool` to integer casts - [#7948](https://github.com/rust-lang/rust-clippy/pull/7948) -* [`let_underscore_lock`]: Also emit lints for the `parking_lot` crate - [#7957](https://github.com/rust-lang/rust-clippy/pull/7957) -* [`needless_borrow`] - [#7977](https://github.com/rust-lang/rust-clippy/pull/7977) - * Lint when a borrow is auto-dereffed more than once - * Lint in the trailing expression of a block for a match arm -* [`strlen_on_c_strings`] - [8001](https://github.com/rust-lang/rust-clippy/pull/8001) - * Lint when used without a fully-qualified path - * Suggest removing the surrounding unsafe block when possible -* [`non_ascii_literal`]: Now also lints on `char`s, not just `string`s - [#8034](https://github.com/rust-lang/rust-clippy/pull/8034) -* [`single_char_pattern`]: Now also lints on `split_inclusive`, `split_once`, - `rsplit_once`, `replace`, and `replacen` - [#8077](https://github.com/rust-lang/rust-clippy/pull/8077) -* [`unwrap_or_else_default`]: Now also lints on `std` constructors like - `Vec::new`, `HashSet::new`, and `HashMap::new` - [#8163](https://github.com/rust-lang/rust-clippy/pull/8163) -* [`shadow_reuse`]: Now also lints on shadowed `if let` bindings, instead of - [`shadow_unrelated`] - [#8165](https://github.com/rust-lang/rust-clippy/pull/8165) - -### False Positive Fixes - -* [`or_fun_call`], [`unnecessary_lazy_evaluations`]: Improve heuristics, so that - cheap functions (e.g. calling `.len()` on a `Vec`) won't get linted anymore - [#7639](https://github.com/rust-lang/rust-clippy/pull/7639) -* [`manual_split_once`]: No longer suggests code changing the original behavior - [#7896](https://github.com/rust-lang/rust-clippy/pull/7896) -* Don't show [`no_effect`] or [`unnecessary_operation`] warning for unit struct - implementing `FnOnce` - [#7898](https://github.com/rust-lang/rust-clippy/pull/7898) -* [`semicolon_if_nothing_returned`]: Fixed a bug, where the lint wrongly - triggered on `let-else` statements - [#7955](https://github.com/rust-lang/rust-clippy/pull/7955) -* [`if_then_some_else_none`]: No longer lints if there is an early return - [#7980](https://github.com/rust-lang/rust-clippy/pull/7980) -* [`needless_collect`]: No longer suggests removal of `collect` when removal - would create code requiring mutably borrowing a value multiple times - [#7982](https://github.com/rust-lang/rust-clippy/pull/7982) -* [`shadow_same`]: Fix false positive for `async` function's params - [#7997](https://github.com/rust-lang/rust-clippy/pull/7997) -* [`suboptimal_flops`]: No longer triggers in constant functions - [#8009](https://github.com/rust-lang/rust-clippy/pull/8009) -* [`type_complexity`]: No longer lints on associated types in traits - [#8030](https://github.com/rust-lang/rust-clippy/pull/8030) -* [`question_mark`]: No longer lints if returned object is not local - [#8080](https://github.com/rust-lang/rust-clippy/pull/8080) -* [`option_if_let_else`]: No longer lint on complex sub-patterns - [#8086](https://github.com/rust-lang/rust-clippy/pull/8086) -* [`blocks_in_if_conditions`]: No longer lints on empty closures - [#8100](https://github.com/rust-lang/rust-clippy/pull/8100) -* [`enum_variant_names`]: No longer lint when first prefix is only a substring - of a camel-case word - [#8127](https://github.com/rust-lang/rust-clippy/pull/8127) -* [`identity_op`]: Only lint on integral operands - [#8183](https://github.com/rust-lang/rust-clippy/pull/8183) - -### Suggestion Fixes/Improvements - -* [`search_is_some`]: Fix suggestion for `any()` not taking item by reference - [#7463](https://github.com/rust-lang/rust-clippy/pull/7463) -* [`almost_swapped`]: Now detects if there is a `no_std` or `no_core` attribute - and adapts the suggestion accordingly - [#7877](https://github.com/rust-lang/rust-clippy/pull/7877) -* [`redundant_pattern_matching`]: Fix suggestion for deref expressions - [#7949](https://github.com/rust-lang/rust-clippy/pull/7949) -* [`explicit_counter_loop`]: Now also produces a suggestion for non-`usize` - types [#7950](https://github.com/rust-lang/rust-clippy/pull/7950) -* [`manual_map`]: Fix suggestion when used with unsafe functions and blocks - [#7968](https://github.com/rust-lang/rust-clippy/pull/7968) -* [`option_map_or_none`]: Suggest `map` over `and_then` when possible - [#7971](https://github.com/rust-lang/rust-clippy/pull/7971) -* [`option_if_let_else`]: No longer expands macros in the suggestion - [#7974](https://github.com/rust-lang/rust-clippy/pull/7974) -* [`iter_cloned_collect`]: Suggest `copied` over `cloned` when possible - [#8006](https://github.com/rust-lang/rust-clippy/pull/8006) -* [`doc_markdown`]: No longer uses inline hints to improve readability of - suggestion [#8011](https://github.com/rust-lang/rust-clippy/pull/8011) -* [`needless_question_mark`]: Now better explains the suggestion - [#8028](https://github.com/rust-lang/rust-clippy/pull/8028) -* [`single_char_pattern`]: Escape backslash `\` in suggestion - [#8067](https://github.com/rust-lang/rust-clippy/pull/8067) -* [`needless_bool`]: Suggest `a != b` over `!(a == b)` - [#8117](https://github.com/rust-lang/rust-clippy/pull/8117) -* [`iter_skip_next`]: Suggest to add a `mut` if it is necessary in order to - apply this lints suggestion - [#8133](https://github.com/rust-lang/rust-clippy/pull/8133) -* [`neg_multiply`]: Now produces a suggestion - [#8144](https://github.com/rust-lang/rust-clippy/pull/8144) -* [`needless_return`]: Now suggests the unit type `()` over an empty block `{}` - in match arms [#8185](https://github.com/rust-lang/rust-clippy/pull/8185) -* [`suboptimal_flops`]: Now gives a syntactically correct suggestion for - `to_radians` and `to_degrees` - [#8187](https://github.com/rust-lang/rust-clippy/pull/8187) - -### ICE Fixes - -* [`undocumented_unsafe_blocks`] - [#7945](https://github.com/rust-lang/rust-clippy/pull/7945) - [#7988](https://github.com/rust-lang/rust-clippy/pull/7988) -* [`unnecessary_cast`] - [#8167](https://github.com/rust-lang/rust-clippy/pull/8167) - -### Documentation Improvements - -* [`print_stdout`], [`print_stderr`], [`dbg_macro`]: Document how the lint level - can be changed crate-wide - [#8040](https://github.com/rust-lang/rust-clippy/pull/8040) -* Added a note to the `README` that config changes don't apply to already - compiled code [#8175](https://github.com/rust-lang/rust-clippy/pull/8175) - -### Others - -* [Clippy's lint - list](https://rust-lang.github.io/rust-clippy/master/index.html) now displays - the version a lint was added. :tada: - [#7813](https://github.com/rust-lang/rust-clippy/pull/7813) -* New and improved issue templates - [#8032](https://github.com/rust-lang/rust-clippy/pull/8032) -* _Dev:_ Add `cargo dev lint` command, to run your modified Clippy version on a - file [#7917](https://github.com/rust-lang/rust-clippy/pull/7917) - -## Rust 1.58 - -Released 2022-01-13 - -[View all 68 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2021-10-07T09%3A49%3A18Z..2021-11-04T12%3A20%3A12Z+base%3Amaster) - -### Rust 1.58.1 - -* Move [`non_send_fields_in_send_ty`] to `nursery` (now allow-by-default) - [#8075](https://github.com/rust-lang/rust-clippy/pull/8075) -* [`useless_format`]: Handle implicit named arguments - [#8295](https://github.com/rust-lang/rust-clippy/pull/8295) - -### New lints - -* [`transmute_num_to_bytes`] - [#7805](https://github.com/rust-lang/rust-clippy/pull/7805) -* [`match_str_case_mismatch`] - [#7806](https://github.com/rust-lang/rust-clippy/pull/7806) -* [`format_in_format_args`], [`to_string_in_format_args`] - [#7743](https://github.com/rust-lang/rust-clippy/pull/7743) -* [`uninit_vec`] - [#7682](https://github.com/rust-lang/rust-clippy/pull/7682) -* [`fn_to_numeric_cast_any`] - [#7705](https://github.com/rust-lang/rust-clippy/pull/7705) -* [`undocumented_unsafe_blocks`] - [#7748](https://github.com/rust-lang/rust-clippy/pull/7748) -* [`trailing_empty_array`] - [#7838](https://github.com/rust-lang/rust-clippy/pull/7838) -* [`string_slice`] - [#7878](https://github.com/rust-lang/rust-clippy/pull/7878) - -### Moves or deprecations of lints - -* Move [`non_send_fields_in_send_ty`] to `suspicious` - [#7874](https://github.com/rust-lang/rust-clippy/pull/7874) -* Move [`non_ascii_literal`] to `restriction` - [#7907](https://github.com/rust-lang/rust-clippy/pull/7907) - -### Changes that expand what code existing lints cover - -* [`question_mark`] now covers `Result` - [#7840](https://github.com/rust-lang/rust-clippy/pull/7840) -* Make [`useless_format`] recognize bare `format!("")` - [#7801](https://github.com/rust-lang/rust-clippy/pull/7801) -* Lint on underscored variables with no side effects in [`no_effect`] - [#7775](https://github.com/rust-lang/rust-clippy/pull/7775) -* Expand [`match_ref_pats`] to check for multiple reference patterns - [#7800](https://github.com/rust-lang/rust-clippy/pull/7800) - -### False positive fixes - -* Fix false positive of [`implicit_saturating_sub`] with `else` clause - [#7832](https://github.com/rust-lang/rust-clippy/pull/7832) -* Fix [`question_mark`] when there is call in conditional predicate - [#7860](https://github.com/rust-lang/rust-clippy/pull/7860) -* [`mut_mut`] no longer lints when type is defined in external macros - [#7795](https://github.com/rust-lang/rust-clippy/pull/7795) -* Avoid [`eq_op`] in test functions - [#7811](https://github.com/rust-lang/rust-clippy/pull/7811) -* [`cast_possible_truncation`] no longer lints when cast is coming from `signum` - method call [#7850](https://github.com/rust-lang/rust-clippy/pull/7850) -* [`match_str_case_mismatch`] no longer lints on uncased characters - [#7865](https://github.com/rust-lang/rust-clippy/pull/7865) -* [`ptr_arg`] no longer lints references to type aliases - [#7890](https://github.com/rust-lang/rust-clippy/pull/7890) -* [`missing_safety_doc`] now also accepts "implementation safety" headers - [#7856](https://github.com/rust-lang/rust-clippy/pull/7856) -* [`missing_safety_doc`] no longer lints if any parent has `#[doc(hidden)]` - attribute [#7849](https://github.com/rust-lang/rust-clippy/pull/7849) -* [`if_not_else`] now ignores else-if statements - [#7895](https://github.com/rust-lang/rust-clippy/pull/7895) -* Avoid linting [`cast_possible_truncation`] on bit-reducing operations - [#7819](https://github.com/rust-lang/rust-clippy/pull/7819) -* Avoid linting [`field_reassign_with_default`] when `Drop` and `Copy` are - involved [#7794](https://github.com/rust-lang/rust-clippy/pull/7794) -* [`unnecessary_sort_by`] now checks if argument implements `Ord` trait - [#7824](https://github.com/rust-lang/rust-clippy/pull/7824) -* Fix false positive in [`match_overlapping_arm`] - [#7847](https://github.com/rust-lang/rust-clippy/pull/7847) -* Prevent [`needless_lifetimes`] false positive in `async` function definition - [#7901](https://github.com/rust-lang/rust-clippy/pull/7901) - -### Suggestion fixes/improvements - -* Keep an initial `::` when [`doc_markdown`] suggests to use ticks - [#7916](https://github.com/rust-lang/rust-clippy/pull/7916) -* Add a machine applicable suggestion for the [`doc_markdown`] missing backticks - lint [#7904](https://github.com/rust-lang/rust-clippy/pull/7904) -* [`equatable_if_let`] no longer expands macros in the suggestion - [#7788](https://github.com/rust-lang/rust-clippy/pull/7788) -* Make [`shadow_reuse`] suggestion less verbose - [#7782](https://github.com/rust-lang/rust-clippy/pull/7782) - -### ICE fixes - -* Fix ICE in [`enum_variant_names`] - [#7873](https://github.com/rust-lang/rust-clippy/pull/7873) -* Fix ICE in [`undocumented_unsafe_blocks`] - [#7891](https://github.com/rust-lang/rust-clippy/pull/7891) - -### Documentation improvements - -* Fixed naive doc formatting for `#[must_use]` lints ([`must_use_unit`], - [`double_must_use`], [`must_use_candidate`], [`let_underscore_must_use`]) - [#7827](https://github.com/rust-lang/rust-clippy/pull/7827) -* Fix typo in example for [`match_result_ok`] - [#7815](https://github.com/rust-lang/rust-clippy/pull/7815) - -### Others - -* Allow giving reasons for [`disallowed_types`] - [#7791](https://github.com/rust-lang/rust-clippy/pull/7791) -* Fix [`manual_assert`] and [`match_wild_err_arm`] for `#![no_std]` and Rust - 2021. [#7851](https://github.com/rust-lang/rust-clippy/pull/7851) -* Fix regression in [`semicolon_if_nothing_returned`] on macros containing while - loops [#7789](https://github.com/rust-lang/rust-clippy/pull/7789) -* Added a new configuration `literal-suffix-style` to enforce a certain style - writing [`unseparated_literal_suffix`] - [#7726](https://github.com/rust-lang/rust-clippy/pull/7726) - -## Rust 1.57 - -Released 2021-12-02 - -[View all 148 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2021-08-12T20%3A36%3A04Z..2021-11-03T17%3A57%3A59Z+base%3Amaster) - -### New Lints - -* [`negative_feature_names`] - [#7539](https://github.com/rust-lang/rust-clippy/pull/7539) -* [`redundant_feature_names`] - [#7539](https://github.com/rust-lang/rust-clippy/pull/7539) -* [`mod_module_files`] - [#7543](https://github.com/rust-lang/rust-clippy/pull/7543) -* [`self_named_module_files`] - [#7543](https://github.com/rust-lang/rust-clippy/pull/7543) -* [`manual_split_once`] - [#7565](https://github.com/rust-lang/rust-clippy/pull/7565) -* [`derivable_impls`] - [#7570](https://github.com/rust-lang/rust-clippy/pull/7570) -* [`needless_option_as_deref`] - [#7596](https://github.com/rust-lang/rust-clippy/pull/7596) -* [`iter_not_returning_iterator`] - [#7610](https://github.com/rust-lang/rust-clippy/pull/7610) -* [`same_name_method`] - [#7653](https://github.com/rust-lang/rust-clippy/pull/7653) -* [`manual_assert`] [#7669](https://github.com/rust-lang/rust-clippy/pull/7669) -* [`non_send_fields_in_send_ty`] - [#7709](https://github.com/rust-lang/rust-clippy/pull/7709) -* [`equatable_if_let`] - [#7762](https://github.com/rust-lang/rust-clippy/pull/7762) - -### Moves and Deprecations - -* Move [`shadow_unrelated`] to `restriction` - [#7338](https://github.com/rust-lang/rust-clippy/pull/7338) -* Move [`option_if_let_else`] to `nursery` - [#7568](https://github.com/rust-lang/rust-clippy/pull/7568) -* Move [`branches_sharing_code`] to `nursery` - [#7595](https://github.com/rust-lang/rust-clippy/pull/7595) -* Rename `if_let_some_result` to [`match_result_ok`] which now also handles - `while let` cases [#7608](https://github.com/rust-lang/rust-clippy/pull/7608) -* Move [`many_single_char_names`] to `pedantic` - [#7671](https://github.com/rust-lang/rust-clippy/pull/7671) -* Move [`float_cmp`] to `pedantic` - [#7692](https://github.com/rust-lang/rust-clippy/pull/7692) -* Rename `box_vec` to [`box_collection`] and lint on more general cases - [#7693](https://github.com/rust-lang/rust-clippy/pull/7693) -* Uplift `invalid_atomic_ordering` to rustc - [rust-lang/rust#84039](https://github.com/rust-lang/rust/pull/84039) - -### Enhancements - -* Rewrite the `shadow*` lints, so that they find a lot more shadows and are not - limited to certain patterns - [#7338](https://github.com/rust-lang/rust-clippy/pull/7338) -* The `avoid-breaking-exported-api` configuration now also works for - [`box_collection`], [`redundant_allocation`], [`rc_buffer`], [`vec_box`], - [`option_option`], [`linkedlist`], [`rc_mutex`] - [#7560](https://github.com/rust-lang/rust-clippy/pull/7560) -* [`unnecessary_unwrap`]: Now also checks for `expect`s - [#7584](https://github.com/rust-lang/rust-clippy/pull/7584) -* [`disallowed_methods`]: Allow adding a reason that will be displayed with the - lint message - [#7621](https://github.com/rust-lang/rust-clippy/pull/7621) -* [`approx_constant`]: Now checks the MSRV for `LOG10_2` and `LOG2_10` - [#7629](https://github.com/rust-lang/rust-clippy/pull/7629) -* [`approx_constant`]: Add `TAU` - [#7642](https://github.com/rust-lang/rust-clippy/pull/7642) -* [`needless_borrow`]: Now also lints on needless mutable borrows - [#7657](https://github.com/rust-lang/rust-clippy/pull/7657) -* [`missing_safety_doc`]: Now also lints on unsafe traits - [#7734](https://github.com/rust-lang/rust-clippy/pull/7734) - -### False Positive Fixes - -* [`manual_map`]: No longer lints when the option is borrowed in the match and - also consumed in the arm - [#7531](https://github.com/rust-lang/rust-clippy/pull/7531) -* [`filter_next`]: No longer lints if `filter` method is not the - `Iterator::filter` method - [#7562](https://github.com/rust-lang/rust-clippy/pull/7562) -* [`manual_flatten`]: No longer lints if expression is used after `if let` - [#7566](https://github.com/rust-lang/rust-clippy/pull/7566) -* [`option_if_let_else`]: Multiple fixes - [#7573](https://github.com/rust-lang/rust-clippy/pull/7573) - * `break` and `continue` statements local to the would-be closure are - allowed - * Don't lint in const contexts - * Don't lint when yield expressions are used - * Don't lint when the captures made by the would-be closure conflict with - the other branch - * Don't lint when a field of a local is used when the type could be - potentially moved from - * In some cases, don't lint when scrutinee expression conflicts with the - captures of the would-be closure -* [`redundant_allocation`]: No longer lints on `Box>` which replaces - wide pointers with thin pointers - [#7592](https://github.com/rust-lang/rust-clippy/pull/7592) -* [`bool_assert_comparison`]: No longer lints on types that do not implement the - `Not` trait with `Output = bool` - [#7605](https://github.com/rust-lang/rust-clippy/pull/7605) -* [`mut_range_bound`]: No longer lints on range bound mutations, that are - immediately followed by a `break;` - [#7607](https://github.com/rust-lang/rust-clippy/pull/7607) -* [`mutable_key_type`]: Improve accuracy and document remaining false positives - and false negatives - [#7640](https://github.com/rust-lang/rust-clippy/pull/7640) -* [`redundant_closure`]: Rewrite the lint to fix various false positives and - false negatives [#7661](https://github.com/rust-lang/rust-clippy/pull/7661) -* [`large_enum_variant`]: No longer wrongly identifies the second largest - variant [#7677](https://github.com/rust-lang/rust-clippy/pull/7677) -* [`needless_return`]: No longer lints on let-else expressions - [#7685](https://github.com/rust-lang/rust-clippy/pull/7685) -* [`suspicious_else_formatting`]: No longer lints in proc-macros - [#7707](https://github.com/rust-lang/rust-clippy/pull/7707) -* [`excessive_precision`]: No longer lints when in some cases the float was - already written in the shortest form - [#7722](https://github.com/rust-lang/rust-clippy/pull/7722) -* [`doc_markdown`]: No longer lints on intra-doc links - [#7772](https://github.com/rust-lang/rust-clippy/pull/7772) - -### Suggestion Fixes/Improvements - -* [`unnecessary_operation`]: Recommend using an `assert!` instead of using a - function call in an indexing operation - [#7453](https://github.com/rust-lang/rust-clippy/pull/7453) -* [`manual_split_once`]: Produce semantically equivalent suggestion when - `rsplitn` is used [#7663](https://github.com/rust-lang/rust-clippy/pull/7663) -* [`while_let_on_iterator`]: Produce correct suggestion when using `&mut` - [#7690](https://github.com/rust-lang/rust-clippy/pull/7690) -* [`manual_assert`]: No better handles complex conditions - [#7741](https://github.com/rust-lang/rust-clippy/pull/7741) -* Correctly handle signs in exponents in numeric literals lints - [#7747](https://github.com/rust-lang/rust-clippy/pull/7747) -* [`suspicious_map`]: Now also suggests to use `inspect` as an alternative - [#7770](https://github.com/rust-lang/rust-clippy/pull/7770) -* Drop exponent from suggestion if it is 0 in numeric literals lints - [#7774](https://github.com/rust-lang/rust-clippy/pull/7774) - -### ICE Fixes - -* [`implicit_hasher`] - [#7761](https://github.com/rust-lang/rust-clippy/pull/7761) - -### Others - -* Clippy now uses the 2021 - [Edition!](https://www.youtube.com/watch?v=q0aNduqb2Ro) - [#7664](https://github.com/rust-lang/rust-clippy/pull/7664) - -## Rust 1.56 - -Released 2021-10-21 - -[View all 38 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2021-07-19T14%3A33%3A33Z..2021-08-12T09%3A28%3A38Z+base%3Amaster) - -### New Lints - -* [`unwrap_or_else_default`] - [#7516](https://github.com/rust-lang/rust-clippy/pull/7516) - -### Enhancements - -* [`needless_continue`]: Now also lints in `loop { continue; }` case - [#7477](https://github.com/rust-lang/rust-clippy/pull/7477) -* [`disallowed_types`]: Now also primitive types can be disallowed - [#7488](https://github.com/rust-lang/rust-clippy/pull/7488) -* [`manual_swap`]: Now also lints on xor swaps - [#7506](https://github.com/rust-lang/rust-clippy/pull/7506) -* [`map_flatten`]: Now also lints on the `Result` type - [#7522](https://github.com/rust-lang/rust-clippy/pull/7522) -* [`no_effect`]: Now also lints on inclusive ranges - [#7556](https://github.com/rust-lang/rust-clippy/pull/7556) - -### False Positive Fixes - -* [`nonstandard_macro_braces`]: No longer lints on similar named nested macros - [#7478](https://github.com/rust-lang/rust-clippy/pull/7478) -* [`too_many_lines`]: No longer lints in closures to avoid duplicated diagnostics - [#7534](https://github.com/rust-lang/rust-clippy/pull/7534) -* [`similar_names`]: No longer complains about `iter` and `item` being too - similar [#7546](https://github.com/rust-lang/rust-clippy/pull/7546) - -### Suggestion Fixes/Improvements - -* [`similar_names`]: No longer suggests to insert or add an underscore as a fix - [#7221](https://github.com/rust-lang/rust-clippy/pull/7221) -* [`new_without_default`]: No longer shows the full qualified type path when - suggesting adding a `Default` implementation - [#7493](https://github.com/rust-lang/rust-clippy/pull/7493) -* [`while_let_on_iterator`]: Now suggests re-borrowing mutable references - [#7520](https://github.com/rust-lang/rust-clippy/pull/7520) -* [`extend_with_drain`]: Improve code suggestion for mutable and immutable - references [#7533](https://github.com/rust-lang/rust-clippy/pull/7533) -* [`trivially_copy_pass_by_ref`]: Now properly handles `Self` type - [#7535](https://github.com/rust-lang/rust-clippy/pull/7535) -* [`never_loop`]: Now suggests using `if let` instead of a `for` loop when - applicable [#7541](https://github.com/rust-lang/rust-clippy/pull/7541) - -### Documentation Improvements - -* Clippy now uses a lint to generate its lint documentation. [Lints all the way - down](https://en.wikipedia.org/wiki/Turtles_all_the_way_down). - [#7502](https://github.com/rust-lang/rust-clippy/pull/7502) -* Reworked Clippy's website: - [#7172](https://github.com/rust-lang/rust-clippy/issues/7172) - [#7279](https://github.com/rust-lang/rust-clippy/pull/7279) - * Added applicability information about lints - * Added a link to jump into the implementation - * Improved loading times - * Adapted some styling -* `cargo clippy --help` now also explains the `--fix` and `--no-deps` flag - [#7492](https://github.com/rust-lang/rust-clippy/pull/7492) -* [`unnested_or_patterns`]: Removed `or_patterns` feature gate in the code - example [#7507](https://github.com/rust-lang/rust-clippy/pull/7507) - -## Rust 1.55 - -Released 2021-09-09 - -[View all 83 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2021-06-03T07%3A23%3A59Z..2021-07-29T11%3A47%3A32Z+base%3Amaster) - -### Important Changes - -* Stabilized `cargo clippy --fix` :tada: - [#7405](https://github.com/rust-lang/rust-clippy/pull/7405) - -### New Lints - -* [`rc_mutex`] - [#7316](https://github.com/rust-lang/rust-clippy/pull/7316) -* [`nonstandard_macro_braces`] - [#7299](https://github.com/rust-lang/rust-clippy/pull/7299) -* [`strlen_on_c_strings`] - [#7243](https://github.com/rust-lang/rust-clippy/pull/7243) -* [`self_named_constructors`] - [#7403](https://github.com/rust-lang/rust-clippy/pull/7403) -* [`disallowed_script_idents`] - [#7400](https://github.com/rust-lang/rust-clippy/pull/7400) -* [`disallowed_types`] - [#7315](https://github.com/rust-lang/rust-clippy/pull/7315) -* [`missing_enforced_import_renames`] - [#7300](https://github.com/rust-lang/rust-clippy/pull/7300) -* [`extend_with_drain`] - [#7270](https://github.com/rust-lang/rust-clippy/pull/7270) - -### Moves and Deprecations - -* Moved [`from_iter_instead_of_collect`] to `pedantic` - [#7375](https://github.com/rust-lang/rust-clippy/pull/7375) -* Added `suspicious` as a new lint group for *code that is most likely wrong or useless* - [#7350](https://github.com/rust-lang/rust-clippy/pull/7350) - * Moved [`blanket_clippy_restriction_lints`] to `suspicious` - * Moved [`empty_loop`] to `suspicious` - * Moved [`eval_order_dependence`] to `suspicious` - * Moved [`float_equality_without_abs`] to `suspicious` - * Moved [`for_loops_over_fallibles`] to `suspicious` - * Moved [`misrefactored_assign_op`] to `suspicious` - * Moved [`mut_range_bound`] to `suspicious` - * Moved [`mutable_key_type`] to `suspicious` - * Moved [`suspicious_arithmetic_impl`] to `suspicious` - * Moved [`suspicious_assignment_formatting`] to `suspicious` - * Moved [`suspicious_else_formatting`] to `suspicious` - * Moved [`suspicious_map`] to `suspicious` - * Moved [`suspicious_op_assign_impl`] to `suspicious` - * Moved [`suspicious_unary_op_formatting`] to `suspicious` - -### Enhancements - -* [`while_let_on_iterator`]: Now suggests `&mut iter` inside closures - [#7262](https://github.com/rust-lang/rust-clippy/pull/7262) -* [`doc_markdown`]: - * Now detects unbalanced ticks - [#7357](https://github.com/rust-lang/rust-clippy/pull/7357) - * Add `FreeBSD` to the default configuration as an allowed identifier - [#7334](https://github.com/rust-lang/rust-clippy/pull/7334) -* [`wildcard_enum_match_arm`], [`match_wildcard_for_single_variants`]: Now allows wildcards for enums with unstable - or hidden variants - [#7407](https://github.com/rust-lang/rust-clippy/pull/7407) -* [`redundant_allocation`]: Now additionally supports the `Arc<>` type - [#7308](https://github.com/rust-lang/rust-clippy/pull/7308) -* [`disallowed_names`]: Now allows disallowed names in test code - [#7379](https://github.com/rust-lang/rust-clippy/pull/7379) -* [`redundant_closure`]: Suggests `&mut` for `FnMut` - [#7437](https://github.com/rust-lang/rust-clippy/pull/7437) -* [`disallowed_methods`], [`disallowed_types`]: The configuration values `disallowed-method` and `disallowed-type` - no longer require fully qualified paths - [#7345](https://github.com/rust-lang/rust-clippy/pull/7345) -* [`zst_offset`]: Fixed lint invocation after it was accidentally suppressed - [#7396](https://github.com/rust-lang/rust-clippy/pull/7396) - -### False Positive Fixes - -* [`default_numeric_fallback`]: No longer lints on float literals as function arguments - [#7446](https://github.com/rust-lang/rust-clippy/pull/7446) -* [`use_self`]: No longer lints on type parameters - [#7288](https://github.com/rust-lang/rust-clippy/pull/7288) -* [`unimplemented`]: Now ignores the `assert` and `debug_assert` macros - [#7439](https://github.com/rust-lang/rust-clippy/pull/7439) -* [`branches_sharing_code`]: Now always checks for block expressions - [#7462](https://github.com/rust-lang/rust-clippy/pull/7462) -* [`field_reassign_with_default`]: No longer triggers in macros - [#7160](https://github.com/rust-lang/rust-clippy/pull/7160) -* [`redundant_clone`]: No longer lints on required clones for borrowed data - [#7346](https://github.com/rust-lang/rust-clippy/pull/7346) -* [`default_numeric_fallback`]: No longer triggers in external macros - [#7325](https://github.com/rust-lang/rust-clippy/pull/7325) -* [`needless_bool`]: No longer lints in macros - [#7442](https://github.com/rust-lang/rust-clippy/pull/7442) -* [`useless_format`]: No longer triggers when additional text is being appended - [#7442](https://github.com/rust-lang/rust-clippy/pull/7442) -* [`assertions_on_constants`]: `cfg!(...)` is no longer considered to be a constant - [#7319](https://github.com/rust-lang/rust-clippy/pull/7319) - -### Suggestion Fixes/Improvements - -* [`needless_collect`]: Now show correct lint messages for shadowed values - [#7289](https://github.com/rust-lang/rust-clippy/pull/7289) -* [`wrong_pub_self_convention`]: The deprecated message now suggest the correct configuration value - [#7382](https://github.com/rust-lang/rust-clippy/pull/7382) -* [`semicolon_if_nothing_returned`]: Allow missing semicolon in blocks with only one expression - [#7326](https://github.com/rust-lang/rust-clippy/pull/7326) - -### ICE Fixes - -* [`zero_sized_map_values`] - [#7470](https://github.com/rust-lang/rust-clippy/pull/7470) -* [`redundant_pattern_matching`] - [#7471](https://github.com/rust-lang/rust-clippy/pull/7471) -* [`modulo_one`] - [#7473](https://github.com/rust-lang/rust-clippy/pull/7473) -* [`use_self`] - [#7428](https://github.com/rust-lang/rust-clippy/pull/7428) - -## Rust 1.54 - -Released 2021-07-29 - -[View all 74 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2021-04-27T23%3A51%3A18Z..2021-06-03T06%3A54%3A07Z+base%3Amaster) - -### New Lints - -- [`ref_binding_to_reference`] - [#7105](https://github.com/rust-lang/rust-clippy/pull/7105) -- [`needless_bitwise_bool`] - [#7133](https://github.com/rust-lang/rust-clippy/pull/7133) -- [`unused_async`] [#7225](https://github.com/rust-lang/rust-clippy/pull/7225) -- [`manual_str_repeat`] - [#7265](https://github.com/rust-lang/rust-clippy/pull/7265) -- [`suspicious_splitn`] - [#7292](https://github.com/rust-lang/rust-clippy/pull/7292) - -### Moves and Deprecations - -- Deprecate `pub_enum_variant_names` and `wrong_pub_self_convention` in favor of - the new `avoid-breaking-exported-api` config option (see - [Enhancements](#1-54-enhancements)) - [#7187](https://github.com/rust-lang/rust-clippy/pull/7187) -- Move [`inconsistent_struct_constructor`] to `pedantic` - [#7193](https://github.com/rust-lang/rust-clippy/pull/7193) -- Move [`needless_borrow`] to `style` (now warn-by-default) - [#7254](https://github.com/rust-lang/rust-clippy/pull/7254) -- Move [`suspicious_operation_groupings`] to `nursery` - [#7266](https://github.com/rust-lang/rust-clippy/pull/7266) -- Move [`semicolon_if_nothing_returned`] to `pedantic` - [#7268](https://github.com/rust-lang/rust-clippy/pull/7268) - -### Enhancements - -- [`while_let_on_iterator`]: Now also lints in nested loops - [#6966](https://github.com/rust-lang/rust-clippy/pull/6966) -- [`single_char_pattern`]: Now also lints on `strip_prefix` and `strip_suffix` - [#7156](https://github.com/rust-lang/rust-clippy/pull/7156) -- [`needless_collect`]: Now also lints on assignments with type annotations - [#7163](https://github.com/rust-lang/rust-clippy/pull/7163) -- [`if_then_some_else_none`]: Now works with the MSRV config - [#7177](https://github.com/rust-lang/rust-clippy/pull/7177) -- Add `avoid-breaking-exported-api` config option for the lints - [`enum_variant_names`], [`large_types_passed_by_value`], - [`trivially_copy_pass_by_ref`], [`unnecessary_wraps`], - [`upper_case_acronyms`], and [`wrong_self_convention`]. We recommend to set - this configuration option to `false` before a major release (1.0/2.0/...) to - clean up the API [#7187](https://github.com/rust-lang/rust-clippy/pull/7187) -- [`needless_collect`]: Now lints on even more data structures - [#7188](https://github.com/rust-lang/rust-clippy/pull/7188) -- [`missing_docs_in_private_items`]: No longer sees `#[ = ""]` like - attributes as sufficient documentation - [#7281](https://github.com/rust-lang/rust-clippy/pull/7281) -- [`needless_collect`], [`short_circuit_statement`], [`unnecessary_operation`]: - Now work as expected when used with `allow` - [#7282](https://github.com/rust-lang/rust-clippy/pull/7282) - -### False Positive Fixes - -- [`implicit_return`]: Now takes all diverging functions in account to avoid - false positives [#6951](https://github.com/rust-lang/rust-clippy/pull/6951) -- [`while_let_on_iterator`]: No longer lints when the iterator is a struct field - and the struct is used in the loop - [#6966](https://github.com/rust-lang/rust-clippy/pull/6966) -- [`multiple_inherent_impl`]: No longer lints with generic arguments - [#7089](https://github.com/rust-lang/rust-clippy/pull/7089) -- [`comparison_chain`]: No longer lints in a `const` context - [#7118](https://github.com/rust-lang/rust-clippy/pull/7118) -- [`while_immutable_condition`]: Fix false positive where mutation in the loop - variable wasn't picked up - [#7144](https://github.com/rust-lang/rust-clippy/pull/7144) -- [`default_trait_access`]: No longer lints in macros - [#7150](https://github.com/rust-lang/rust-clippy/pull/7150) -- [`needless_question_mark`]: No longer lints when the inner value is implicitly - dereferenced [#7165](https://github.com/rust-lang/rust-clippy/pull/7165) -- [`unused_unit`]: No longer lints when multiple macro contexts are involved - [#7167](https://github.com/rust-lang/rust-clippy/pull/7167) -- [`eval_order_dependence`]: Fix false positive in async context - [#7174](https://github.com/rust-lang/rust-clippy/pull/7174) -- [`unnecessary_filter_map`]: No longer lints if the `filter_map` changes the - type [#7175](https://github.com/rust-lang/rust-clippy/pull/7175) -- [`wrong_self_convention`]: No longer lints in trait implementations of - non-`Copy` types [#7182](https://github.com/rust-lang/rust-clippy/pull/7182) -- [`suboptimal_flops`]: No longer lints on `powi(2)` - [#7201](https://github.com/rust-lang/rust-clippy/pull/7201) -- [`wrong_self_convention`]: No longer lints if there is no implicit `self` - [#7215](https://github.com/rust-lang/rust-clippy/pull/7215) -- [`option_if_let_else`]: No longer lints on `else if let` pattern - [#7216](https://github.com/rust-lang/rust-clippy/pull/7216) -- [`use_self`], [`useless_conversion`]: Fix false positives when generic - arguments are involved - [#7223](https://github.com/rust-lang/rust-clippy/pull/7223) -- [`manual_unwrap_or`]: Fix false positive with deref coercion - [#7233](https://github.com/rust-lang/rust-clippy/pull/7233) -- [`similar_names`]: No longer lints on `wparam`/`lparam` - [#7255](https://github.com/rust-lang/rust-clippy/pull/7255) -- [`redundant_closure`]: No longer lints on using the `vec![]` macro in a - closure [#7263](https://github.com/rust-lang/rust-clippy/pull/7263) - -### Suggestion Fixes/Improvements - -- [`implicit_return`] - [#6951](https://github.com/rust-lang/rust-clippy/pull/6951) - - Fix suggestion for async functions - - Improve suggestion with macros - - Suggest to change `break` to `return` when appropriate -- [`while_let_on_iterator`]: Now suggests `&mut iter` when necessary - [#6966](https://github.com/rust-lang/rust-clippy/pull/6966) -- [`match_single_binding`]: Improve suggestion when match scrutinee has side - effects [#7095](https://github.com/rust-lang/rust-clippy/pull/7095) -- [`needless_borrow`]: Now suggests to also change usage sites as needed - [#7105](https://github.com/rust-lang/rust-clippy/pull/7105) -- [`write_with_newline`]: Improve suggestion when only `\n` is written to the - buffer [#7183](https://github.com/rust-lang/rust-clippy/pull/7183) -- [`from_iter_instead_of_collect`]: The suggestion is now auto applicable also - when a `<_ as Trait>::_` is involved - [#7264](https://github.com/rust-lang/rust-clippy/pull/7264) -- [`not_unsafe_ptr_arg_deref`]: Improved error message - [#7294](https://github.com/rust-lang/rust-clippy/pull/7294) - -### ICE Fixes - -- Fix ICE when running Clippy on `libstd` - [#7140](https://github.com/rust-lang/rust-clippy/pull/7140) -- [`implicit_return`] - [#7242](https://github.com/rust-lang/rust-clippy/pull/7242) - -## Rust 1.53 - -Released 2021-06-17 - -[View all 126 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2021-03-12T22%3A49%3A20Z..2021-04-27T14%3A38%3A20Z+base%3Amaster) - -### New Lints - -* [`option_filter_map`] - [#6342](https://github.com/rust-lang/rust-clippy/pull/6342) -* [`branches_sharing_code`] - [#6463](https://github.com/rust-lang/rust-clippy/pull/6463) -* [`needless_for_each`] - [#6706](https://github.com/rust-lang/rust-clippy/pull/6706) -* [`if_then_some_else_none`] - [#6859](https://github.com/rust-lang/rust-clippy/pull/6859) -* [`non_octal_unix_permissions`] - [#7001](https://github.com/rust-lang/rust-clippy/pull/7001) -* [`unnecessary_self_imports`] - [#7072](https://github.com/rust-lang/rust-clippy/pull/7072) -* [`bool_assert_comparison`] - [#7083](https://github.com/rust-lang/rust-clippy/pull/7083) -* [`cloned_instead_of_copied`] - [#7098](https://github.com/rust-lang/rust-clippy/pull/7098) -* [`flat_map_option`] - [#7101](https://github.com/rust-lang/rust-clippy/pull/7101) - -### Moves and Deprecations - -* Deprecate [`filter_map`] lint - [#7059](https://github.com/rust-lang/rust-clippy/pull/7059) -* Move [`transmute_ptr_to_ptr`] to `pedantic` - [#7102](https://github.com/rust-lang/rust-clippy/pull/7102) - -### Enhancements - -* [`mem_replace_with_default`]: Also lint on common std constructors - [#6820](https://github.com/rust-lang/rust-clippy/pull/6820) -* [`wrong_self_convention`]: Also lint on `to_*_mut` methods - [#6828](https://github.com/rust-lang/rust-clippy/pull/6828) -* [`wildcard_enum_match_arm`], [`match_wildcard_for_single_variants`]: - [#6863](https://github.com/rust-lang/rust-clippy/pull/6863) - * Attempt to find a common path prefix in suggestion - * Don't lint on `Option` and `Result` - * Consider `Self` prefix -* [`explicit_deref_methods`]: Also lint on chained `deref` calls - [#6865](https://github.com/rust-lang/rust-clippy/pull/6865) -* [`or_fun_call`]: Also lint on `unsafe` blocks - [#6928](https://github.com/rust-lang/rust-clippy/pull/6928) -* [`vec_box`], [`linkedlist`], [`option_option`]: Also lint in `const` and - `static` items [#6938](https://github.com/rust-lang/rust-clippy/pull/6938) -* [`search_is_some`]: Also check for `is_none` - [#6942](https://github.com/rust-lang/rust-clippy/pull/6942) -* [`string_lit_as_bytes`]: Also lint on `into_bytes` - [#6959](https://github.com/rust-lang/rust-clippy/pull/6959) -* [`len_without_is_empty`]: Also lint if function signatures of `len` and - `is_empty` don't match - [#6980](https://github.com/rust-lang/rust-clippy/pull/6980) -* [`redundant_pattern_matching`]: Also lint if the pattern is a `&` pattern - [#6991](https://github.com/rust-lang/rust-clippy/pull/6991) -* [`clone_on_copy`]: Also lint on chained method calls taking `self` by value - [#7000](https://github.com/rust-lang/rust-clippy/pull/7000) -* [`missing_panics_doc`]: Also lint on `assert_eq!` and `assert_ne!` - [#7029](https://github.com/rust-lang/rust-clippy/pull/7029) -* [`needless_return`]: Also lint in `async` functions - [#7067](https://github.com/rust-lang/rust-clippy/pull/7067) -* [`unused_io_amount`]: Also lint on expressions like `_.read().ok()?` - [#7100](https://github.com/rust-lang/rust-clippy/pull/7100) -* [`iter_cloned_collect`]: Also lint on large arrays, since const-generics are - now stable [#7138](https://github.com/rust-lang/rust-clippy/pull/7138) - -### False Positive Fixes - -* [`upper_case_acronyms`]: No longer lints on public items - [#6805](https://github.com/rust-lang/rust-clippy/pull/6805) -* [`suspicious_map`]: No longer lints when side effects may occur inside the - `map` call [#6831](https://github.com/rust-lang/rust-clippy/pull/6831) -* [`manual_map`], [`manual_unwrap_or`]: No longer lints in `const` functions - [#6917](https://github.com/rust-lang/rust-clippy/pull/6917) -* [`wrong_self_convention`]: Now respects `Copy` types - [#6924](https://github.com/rust-lang/rust-clippy/pull/6924) -* [`needless_question_mark`]: No longer lints if the `?` and the `Some(..)` come - from different macro contexts [#6935](https://github.com/rust-lang/rust-clippy/pull/6935) -* [`map_entry`]: Better detect if the entry API can be used - [#6937](https://github.com/rust-lang/rust-clippy/pull/6937) -* [`or_fun_call`]: No longer lints on some `len` function calls - [#6950](https://github.com/rust-lang/rust-clippy/pull/6950) -* [`new_ret_no_self`]: No longer lints when `Self` is returned with different - generic arguments [#6952](https://github.com/rust-lang/rust-clippy/pull/6952) -* [`upper_case_acronyms`]: No longer lints on public items - [#6981](https://github.com/rust-lang/rust-clippy/pull/6981) -* [`explicit_into_iter_loop`]: Only lint when `into_iter` is an implementation - of `IntoIterator` [#6982](https://github.com/rust-lang/rust-clippy/pull/6982) -* [`expl_impl_clone_on_copy`]: Take generic constraints into account before - suggesting to use `derive` instead - [#6993](https://github.com/rust-lang/rust-clippy/pull/6993) -* [`missing_panics_doc`]: No longer lints when only debug-assertions are used - [#6996](https://github.com/rust-lang/rust-clippy/pull/6996) -* [`clone_on_copy`]: Only lint when using the `Clone` trait - [#7000](https://github.com/rust-lang/rust-clippy/pull/7000) -* [`wrong_self_convention`]: No longer lints inside a trait implementation - [#7002](https://github.com/rust-lang/rust-clippy/pull/7002) -* [`redundant_clone`]: No longer lints when the cloned value is modified while - the clone is in use - [#7011](https://github.com/rust-lang/rust-clippy/pull/7011) -* [`same_item_push`]: No longer lints if the `Vec` is used in the loop body - [#7018](https://github.com/rust-lang/rust-clippy/pull/7018) -* [`cargo_common_metadata`]: Remove author requirement - [#7026](https://github.com/rust-lang/rust-clippy/pull/7026) -* [`panic_in_result_fn`]: No longer lints on `debug_assert` family - [#7060](https://github.com/rust-lang/rust-clippy/pull/7060) -* [`panic`]: No longer wrongfully lints on `debug_assert` with message - [#7063](https://github.com/rust-lang/rust-clippy/pull/7063) -* [`wrong_self_convention`]: No longer lints in trait implementations where no - `self` is involved [#7064](https://github.com/rust-lang/rust-clippy/pull/7064) -* [`missing_const_for_fn`]: No longer lints when unstable `const` function is - involved [#7076](https://github.com/rust-lang/rust-clippy/pull/7076) -* [`suspicious_else_formatting`]: Allow Allman style braces - [#7087](https://github.com/rust-lang/rust-clippy/pull/7087) -* [`inconsistent_struct_constructor`]: No longer lints in macros - [#7097](https://github.com/rust-lang/rust-clippy/pull/7097) -* [`single_component_path_imports`]: No longer lints on macro re-exports - [#7120](https://github.com/rust-lang/rust-clippy/pull/7120) - -### Suggestion Fixes/Improvements - -* [`redundant_pattern_matching`]: Add a note when applying this lint would - change the drop order - [#6568](https://github.com/rust-lang/rust-clippy/pull/6568) -* [`write_literal`], [`print_literal`]: Add auto-applicable suggestion - [#6821](https://github.com/rust-lang/rust-clippy/pull/6821) -* [`manual_map`]: Fix suggestion for complex `if let ... else` chains - [#6856](https://github.com/rust-lang/rust-clippy/pull/6856) -* [`inconsistent_struct_constructor`]: Make lint description and message clearer - [#6892](https://github.com/rust-lang/rust-clippy/pull/6892) -* [`map_entry`]: Now suggests `or_insert`, `insert_with` or `match _.entry(_)` - as appropriate [#6937](https://github.com/rust-lang/rust-clippy/pull/6937) -* [`manual_flatten`]: Suggest to insert `copied` if necessary - [#6962](https://github.com/rust-lang/rust-clippy/pull/6962) -* [`redundant_slicing`]: Fix suggestion when a re-borrow might be required or - when the value is from a macro call - [#6975](https://github.com/rust-lang/rust-clippy/pull/6975) -* [`match_wildcard_for_single_variants`]: Fix suggestion for hidden variant - [#6988](https://github.com/rust-lang/rust-clippy/pull/6988) -* [`clone_on_copy`]: Correct suggestion when the cloned value is a macro call - [#7000](https://github.com/rust-lang/rust-clippy/pull/7000) -* [`manual_map`]: Fix suggestion at the end of an if chain - [#7004](https://github.com/rust-lang/rust-clippy/pull/7004) -* Fix needless parenthesis output in multiple lint suggestions - [#7013](https://github.com/rust-lang/rust-clippy/pull/7013) -* [`needless_collect`]: Better explanation in the lint message - [#7020](https://github.com/rust-lang/rust-clippy/pull/7020) -* [`useless_vec`]: Now considers mutability - [#7036](https://github.com/rust-lang/rust-clippy/pull/7036) -* [`useless_format`]: Wrap the content in braces if necessary - [#7092](https://github.com/rust-lang/rust-clippy/pull/7092) -* [`single_match`]: Don't suggest an equality check for types which don't - implement `PartialEq` - [#7093](https://github.com/rust-lang/rust-clippy/pull/7093) -* [`from_over_into`]: Mention type in help message - [#7099](https://github.com/rust-lang/rust-clippy/pull/7099) -* [`manual_unwrap_or`]: Fix invalid code suggestion due to a macro call - [#7136](https://github.com/rust-lang/rust-clippy/pull/7136) - -### ICE Fixes - -* [`macro_use_imports`] - [#7022](https://github.com/rust-lang/rust-clippy/pull/7022) -* [`missing_panics_doc`] - [#7034](https://github.com/rust-lang/rust-clippy/pull/7034) -* [`tabs_in_doc_comments`] - [#7039](https://github.com/rust-lang/rust-clippy/pull/7039) -* [`missing_const_for_fn`] - [#7128](https://github.com/rust-lang/rust-clippy/pull/7128) - -### Others - -* [Clippy's lint - list](https://rust-lang.github.io/rust-clippy/master/index.html) now supports - themes [#7030](https://github.com/rust-lang/rust-clippy/pull/7030) -* Lints that were uplifted to `rustc` now mention the new `rustc` name in the - deprecation warning - [#7056](https://github.com/rust-lang/rust-clippy/pull/7056) - -## Rust 1.52 - -Released 2021-05-06 - -[View all 102 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2021-02-03T15%3A59%3A06Z..2021-03-11T20%3A06%3A43Z+base%3Amaster) - -### New Lints - -* [`from_str_radix_10`] - [#6717](https://github.com/rust-lang/rust-clippy/pull/6717) -* [`implicit_clone`] - [#6730](https://github.com/rust-lang/rust-clippy/pull/6730) -* [`semicolon_if_nothing_returned`] - [#6681](https://github.com/rust-lang/rust-clippy/pull/6681) -* [`manual_flatten`] - [#6646](https://github.com/rust-lang/rust-clippy/pull/6646) -* [`inconsistent_struct_constructor`] - [#6769](https://github.com/rust-lang/rust-clippy/pull/6769) -* [`iter_count`] - [#6791](https://github.com/rust-lang/rust-clippy/pull/6791) -* [`default_numeric_fallback`] - [#6662](https://github.com/rust-lang/rust-clippy/pull/6662) -* [`bytes_nth`] - [#6695](https://github.com/rust-lang/rust-clippy/pull/6695) -* [`filter_map_identity`] - [#6685](https://github.com/rust-lang/rust-clippy/pull/6685) -* [`manual_map`] - [#6573](https://github.com/rust-lang/rust-clippy/pull/6573) - -### Moves and Deprecations - -* Moved [`upper_case_acronyms`] to `pedantic` - [#6775](https://github.com/rust-lang/rust-clippy/pull/6775) -* Moved [`manual_map`] to `nursery` - [#6796](https://github.com/rust-lang/rust-clippy/pull/6796) -* Moved [`unnecessary_wraps`] to `pedantic` - [#6765](https://github.com/rust-lang/rust-clippy/pull/6765) -* Moved [`trivial_regex`] to `nursery` - [#6696](https://github.com/rust-lang/rust-clippy/pull/6696) -* Moved [`naive_bytecount`] to `pedantic` - [#6825](https://github.com/rust-lang/rust-clippy/pull/6825) -* Moved [`upper_case_acronyms`] to `style` - [#6788](https://github.com/rust-lang/rust-clippy/pull/6788) -* Moved [`manual_map`] to `style` - [#6801](https://github.com/rust-lang/rust-clippy/pull/6801) - -### Enhancements - -* [`disallowed_methods`]: Now supports functions in addition to methods - [#6674](https://github.com/rust-lang/rust-clippy/pull/6674) -* [`upper_case_acronyms`]: Added a new configuration `upper-case-acronyms-aggressive` to - trigger the lint if there is more than one uppercase character next to each other - [#6788](https://github.com/rust-lang/rust-clippy/pull/6788) -* [`collapsible_match`]: Now supports block comparison with different value names - [#6754](https://github.com/rust-lang/rust-clippy/pull/6754) -* [`unnecessary_wraps`]: Will now suggest removing unnecessary wrapped return unit type, like `Option<()>` - [#6665](https://github.com/rust-lang/rust-clippy/pull/6665) -* Improved value usage detection in closures - [#6698](https://github.com/rust-lang/rust-clippy/pull/6698) - -### False Positive Fixes - -* [`use_self`]: No longer lints in macros - [#6833](https://github.com/rust-lang/rust-clippy/pull/6833) -* [`use_self`]: Fixed multiple false positives for: generics, associated types and derive implementations - [#6179](https://github.com/rust-lang/rust-clippy/pull/6179) -* [`missing_inline_in_public_items`]: No longer lints for procedural macros - [#6814](https://github.com/rust-lang/rust-clippy/pull/6814) -* [`inherent_to_string`]: No longer lints on functions with function generics - [#6771](https://github.com/rust-lang/rust-clippy/pull/6771) -* [`doc_markdown`]: Add `OpenDNS` to the default configuration as an allowed identifier - [#6783](https://github.com/rust-lang/rust-clippy/pull/6783) -* [`missing_panics_doc`]: No longer lints on [`unreachable!`](https://doc.rust-lang.org/std/macro.unreachable.html) - [#6700](https://github.com/rust-lang/rust-clippy/pull/6700) -* [`collapsible_if`]: No longer lints on if statements with attributes - [#6701](https://github.com/rust-lang/rust-clippy/pull/6701) -* [`match_same_arms`]: Only considers empty blocks as equal if the tokens contained are the same - [#6843](https://github.com/rust-lang/rust-clippy/pull/6843) -* [`redundant_closure`]: Now ignores macros - [#6871](https://github.com/rust-lang/rust-clippy/pull/6871) -* [`manual_map`]: Fixed false positives when control flow statements like `return`, `break` etc. are used - [#6801](https://github.com/rust-lang/rust-clippy/pull/6801) -* [`vec_init_then_push`]: Fixed false positives for loops and if statements - [#6697](https://github.com/rust-lang/rust-clippy/pull/6697) -* [`len_without_is_empty`]: Will now consider multiple impl blocks and `#[allow]` on - the `len` method as well as the type definition. - [#6853](https://github.com/rust-lang/rust-clippy/pull/6853) -* [`let_underscore_drop`]: Only lints on types which implement `Drop` - [#6682](https://github.com/rust-lang/rust-clippy/pull/6682) -* [`unit_arg`]: No longer lints on unit arguments when they come from a path expression. - [#6601](https://github.com/rust-lang/rust-clippy/pull/6601) -* [`cargo_common_metadata`]: No longer lints if - [`publish = false`](https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field) - is defined in the manifest - [#6650](https://github.com/rust-lang/rust-clippy/pull/6650) - -### Suggestion Fixes/Improvements - -* [`collapsible_match`]: Fixed lint message capitalization - [#6766](https://github.com/rust-lang/rust-clippy/pull/6766) -* [`or_fun_call`]: Improved suggestions for `or_insert(vec![])` - [#6790](https://github.com/rust-lang/rust-clippy/pull/6790) -* [`manual_map`]: No longer expands macros in the suggestions - [#6801](https://github.com/rust-lang/rust-clippy/pull/6801) -* Aligned Clippy's lint messages with the rustc dev guide - [#6787](https://github.com/rust-lang/rust-clippy/pull/6787) - -### ICE Fixes - -* [`zero_sized_map_values`] - [#6866](https://github.com/rust-lang/rust-clippy/pull/6866) - -### Documentation Improvements - -* [`useless_format`]: Improved the documentation example - [#6854](https://github.com/rust-lang/rust-clippy/pull/6854) -* Clippy's [`README.md`]: Includes a new subsection on running Clippy as a rustc wrapper - [#6782](https://github.com/rust-lang/rust-clippy/pull/6782) - -### Others -* Running `cargo clippy` after `cargo check` now works as expected - (`cargo clippy` and `cargo check` no longer shares the same build cache) - [#6687](https://github.com/rust-lang/rust-clippy/pull/6687) -* Cargo now re-runs Clippy if arguments after `--` provided to `cargo clippy` are changed. - [#6834](https://github.com/rust-lang/rust-clippy/pull/6834) -* Extracted Clippy's `utils` module into the new `clippy_utils` crate - [#6756](https://github.com/rust-lang/rust-clippy/pull/6756) -* Clippy lintcheck tool improvements - [#6800](https://github.com/rust-lang/rust-clippy/pull/6800) - [#6735](https://github.com/rust-lang/rust-clippy/pull/6735) - [#6764](https://github.com/rust-lang/rust-clippy/pull/6764) - [#6708](https://github.com/rust-lang/rust-clippy/pull/6708) - [#6780](https://github.com/rust-lang/rust-clippy/pull/6780) - [#6686](https://github.com/rust-lang/rust-clippy/pull/6686) - -## Rust 1.51 - -Released 2021-03-25 - -[View all 78 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2020-12-21T15%3A43%3A04Z..2021-02-03T04%3A21%3A10Z+base%3Amaster) - -### New Lints - -* [`upper_case_acronyms`] - [#6475](https://github.com/rust-lang/rust-clippy/pull/6475) -* [`from_over_into`] [#6476](https://github.com/rust-lang/rust-clippy/pull/6476) -* [`case_sensitive_file_extension_comparisons`] - [#6500](https://github.com/rust-lang/rust-clippy/pull/6500) -* [`needless_question_mark`] - [#6507](https://github.com/rust-lang/rust-clippy/pull/6507) -* [`missing_panics_doc`] - [#6523](https://github.com/rust-lang/rust-clippy/pull/6523) -* [`redundant_slicing`] - [#6528](https://github.com/rust-lang/rust-clippy/pull/6528) -* [`vec_init_then_push`] - [#6538](https://github.com/rust-lang/rust-clippy/pull/6538) -* [`ptr_as_ptr`] [#6542](https://github.com/rust-lang/rust-clippy/pull/6542) -* [`collapsible_else_if`] (split out from `collapsible_if`) - [#6544](https://github.com/rust-lang/rust-clippy/pull/6544) -* [`inspect_for_each`] [#6577](https://github.com/rust-lang/rust-clippy/pull/6577) -* [`manual_filter_map`] - [#6591](https://github.com/rust-lang/rust-clippy/pull/6591) -* [`exhaustive_enums`] - [#6617](https://github.com/rust-lang/rust-clippy/pull/6617) -* [`exhaustive_structs`] - [#6617](https://github.com/rust-lang/rust-clippy/pull/6617) - -### Moves and Deprecations - -* Replace [`find_map`] with [`manual_find_map`] - [#6591](https://github.com/rust-lang/rust-clippy/pull/6591) -* `unknown_clippy_lints` Now integrated in the `unknown_lints` rustc lint - [#6653](https://github.com/rust-lang/rust-clippy/pull/6653) - -### Enhancements - -* [`ptr_arg`] Now also suggests to use `&Path` instead of `&PathBuf` - [#6506](https://github.com/rust-lang/rust-clippy/pull/6506) -* [`cast_ptr_alignment`] Also lint when the `pointer::cast` method is used - [#6557](https://github.com/rust-lang/rust-clippy/pull/6557) -* [`collapsible_match`] Now also deals with `&` and `*` operators in the `match` - scrutinee [#6619](https://github.com/rust-lang/rust-clippy/pull/6619) - -### False Positive Fixes - -* [`similar_names`] Ignore underscore prefixed names - [#6403](https://github.com/rust-lang/rust-clippy/pull/6403) -* [`print_literal`] and [`write_literal`] No longer lint numeric literals - [#6408](https://github.com/rust-lang/rust-clippy/pull/6408) -* [`large_enum_variant`] No longer lints in external macros - [#6485](https://github.com/rust-lang/rust-clippy/pull/6485) -* [`empty_enum`] Only lint if `never_type` feature is enabled - [#6513](https://github.com/rust-lang/rust-clippy/pull/6513) -* [`field_reassign_with_default`] No longer lints in macros - [#6553](https://github.com/rust-lang/rust-clippy/pull/6553) -* [`size_of_in_element_count`] No longer lints when dividing by element size - [#6578](https://github.com/rust-lang/rust-clippy/pull/6578) -* [`needless_return`] No longer lints in macros - [#6586](https://github.com/rust-lang/rust-clippy/pull/6586) -* [`match_overlapping_arm`] No longer lint when first arm is completely included - in second arm [#6603](https://github.com/rust-lang/rust-clippy/pull/6603) -* [`doc_markdown`] Add `WebGL` to the default configuration as an allowed - identifier [#6605](https://github.com/rust-lang/rust-clippy/pull/6605) - -### Suggestion Fixes/Improvements - -* [`field_reassign_with_default`] Don't expand macro in lint suggestion - [#6531](https://github.com/rust-lang/rust-clippy/pull/6531) -* [`match_like_matches_macro`] Strip references in suggestion - [#6532](https://github.com/rust-lang/rust-clippy/pull/6532) -* [`single_match`] Suggest `if` over `if let` when possible - [#6574](https://github.com/rust-lang/rust-clippy/pull/6574) -* `ref_in_deref` Use parentheses correctly in suggestion - [#6609](https://github.com/rust-lang/rust-clippy/pull/6609) -* [`stable_sort_primitive`] Clarify error message - [#6611](https://github.com/rust-lang/rust-clippy/pull/6611) - -### ICE Fixes - -* [`zero_sized_map_values`] - [#6582](https://github.com/rust-lang/rust-clippy/pull/6582) - -### Documentation Improvements - -* Improve search performance on the Clippy website and make it possible to - directly search for lints on the GitHub issue tracker - [#6483](https://github.com/rust-lang/rust-clippy/pull/6483) -* Clean up `README.md` by removing outdated paragraph - [#6488](https://github.com/rust-lang/rust-clippy/pull/6488) -* [`await_holding_refcell_ref`] and [`await_holding_lock`] - [#6585](https://github.com/rust-lang/rust-clippy/pull/6585) -* [`as_conversions`] [#6608](https://github.com/rust-lang/rust-clippy/pull/6608) - -### Others - -* Clippy now has a [Roadmap] for 2021. If you like to get involved in a bigger - project, take a look at the [Roadmap project page]. All issues listed there - are actively mentored - [#6462](https://github.com/rust-lang/rust-clippy/pull/6462) -* The Clippy version number now corresponds to the Rust version number - [#6526](https://github.com/rust-lang/rust-clippy/pull/6526) -* Fix oversight which caused Clippy to lint deps in some environments, where - `CLIPPY_TESTS=true` was set somewhere - [#6575](https://github.com/rust-lang/rust-clippy/pull/6575) -* Add `cargo dev-lintcheck` tool to the Clippy Dev Tool - [#6469](https://github.com/rust-lang/rust-clippy/pull/6469) - -[Roadmap]: https://github.com/rust-lang/rust-clippy/blob/master/book/src/development/proposals/roadmap-2021.md -[Roadmap project page]: https://github.com/rust-lang/rust-clippy/projects/3 - -## Rust 1.50 - -Released 2021-02-11 - -[View all 119 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2020-11-06T18%3A32%3A40Z..2021-01-03T14%3A51%3A18Z+base%3Amaster) - -### New Lints - -* [`suspicious_operation_groupings`] [#6086](https://github.com/rust-lang/rust-clippy/pull/6086) -* [`size_of_in_element_count`] [#6394](https://github.com/rust-lang/rust-clippy/pull/6394) -* [`unnecessary_wraps`] [#6070](https://github.com/rust-lang/rust-clippy/pull/6070) -* [`let_underscore_drop`] [#6305](https://github.com/rust-lang/rust-clippy/pull/6305) -* [`collapsible_match`] [#6402](https://github.com/rust-lang/rust-clippy/pull/6402) -* [`redundant_else`] [#6330](https://github.com/rust-lang/rust-clippy/pull/6330) -* [`zero_sized_map_values`] [#6218](https://github.com/rust-lang/rust-clippy/pull/6218) -* [`print_stderr`] [#6367](https://github.com/rust-lang/rust-clippy/pull/6367) -* [`string_from_utf8_as_bytes`] [#6134](https://github.com/rust-lang/rust-clippy/pull/6134) - -### Moves and Deprecations - -* Previously deprecated [`str_to_string`] and [`string_to_string`] have been un-deprecated - as `restriction` lints [#6333](https://github.com/rust-lang/rust-clippy/pull/6333) -* Deprecate `panic_params` lint. This is now available in rustc as `non_fmt_panics` - [#6351](https://github.com/rust-lang/rust-clippy/pull/6351) -* Move [`map_err_ignore`] to `restriction` - [#6416](https://github.com/rust-lang/rust-clippy/pull/6416) -* Move [`await_holding_refcell_ref`] to `pedantic` - [#6354](https://github.com/rust-lang/rust-clippy/pull/6354) -* Move [`await_holding_lock`] to `pedantic` - [#6354](https://github.com/rust-lang/rust-clippy/pull/6354) - -### Enhancements - -* Add the `unreadable-literal-lint-fractions` configuration to disable - the `unreadable_literal` lint for fractions - [#6421](https://github.com/rust-lang/rust-clippy/pull/6421) -* [`clone_on_copy`]: Now shows the type in the lint message - [#6443](https://github.com/rust-lang/rust-clippy/pull/6443) -* [`redundant_pattern_matching`]: Now also lints on `std::task::Poll` - [#6339](https://github.com/rust-lang/rust-clippy/pull/6339) -* [`redundant_pattern_matching`]: Additionally also lints on `std::net::IpAddr` - [#6377](https://github.com/rust-lang/rust-clippy/pull/6377) -* [`search_is_some`]: Now suggests `contains` instead of `find(foo).is_some()` - [#6119](https://github.com/rust-lang/rust-clippy/pull/6119) -* [`clone_double_ref`]: Now prints the reference type in the lint message - [#6442](https://github.com/rust-lang/rust-clippy/pull/6442) -* [`modulo_one`]: Now also lints on -1. - [#6360](https://github.com/rust-lang/rust-clippy/pull/6360) -* [`empty_loop`]: Now lints no_std crates, too - [#6205](https://github.com/rust-lang/rust-clippy/pull/6205) -* [`or_fun_call`]: Now also lints when indexing `HashMap` or `BTreeMap` - [#6267](https://github.com/rust-lang/rust-clippy/pull/6267) -* [`wrong_self_convention`]: Now also lints in trait definitions - [#6316](https://github.com/rust-lang/rust-clippy/pull/6316) -* [`needless_borrow`]: Print the type in the lint message - [#6449](https://github.com/rust-lang/rust-clippy/pull/6449) - -[msrv_readme]: https://github.com/rust-lang/rust-clippy#specifying-the-minimum-supported-rust-version - -### False Positive Fixes - -* [`manual_range_contains`]: No longer lints in `const fn` - [#6382](https://github.com/rust-lang/rust-clippy/pull/6382) -* [`unnecessary_lazy_evaluations`]: No longer lints if closure argument is used - [#6370](https://github.com/rust-lang/rust-clippy/pull/6370) -* [`match_single_binding`]: Now ignores cases with `#[cfg()]` macros - [#6435](https://github.com/rust-lang/rust-clippy/pull/6435) -* [`match_like_matches_macro`]: No longer lints on arms with attributes - [#6290](https://github.com/rust-lang/rust-clippy/pull/6290) -* [`map_clone`]: No longer lints with deref and clone - [#6269](https://github.com/rust-lang/rust-clippy/pull/6269) -* [`map_clone`]: No longer lints in the case of &mut - [#6301](https://github.com/rust-lang/rust-clippy/pull/6301) -* [`needless_update`]: Now ignores `non_exhaustive` structs - [#6464](https://github.com/rust-lang/rust-clippy/pull/6464) -* [`needless_collect`]: No longer lints when a collect is needed multiple times - [#6313](https://github.com/rust-lang/rust-clippy/pull/6313) -* [`unnecessary_cast`] No longer lints cfg-dependent types - [#6369](https://github.com/rust-lang/rust-clippy/pull/6369) -* [`declare_interior_mutable_const`] and [`borrow_interior_mutable_const`]: - Both now ignore enums with frozen variants - [#6110](https://github.com/rust-lang/rust-clippy/pull/6110) -* [`field_reassign_with_default`] No longer lint for private fields - [#6537](https://github.com/rust-lang/rust-clippy/pull/6537) - - -### Suggestion Fixes/Improvements - -* [`vec_box`]: Provide correct type scope suggestion - [#6271](https://github.com/rust-lang/rust-clippy/pull/6271) -* [`manual_range_contains`]: Give correct suggestion when using floats - [#6320](https://github.com/rust-lang/rust-clippy/pull/6320) -* [`unnecessary_lazy_evaluations`]: Don't always mark suggestion as MachineApplicable - [#6272](https://github.com/rust-lang/rust-clippy/pull/6272) -* [`manual_async_fn`]: Improve suggestion formatting - [#6294](https://github.com/rust-lang/rust-clippy/pull/6294) -* [`unnecessary_cast`]: Fix incorrectly formatted float literal suggestion - [#6362](https://github.com/rust-lang/rust-clippy/pull/6362) - -### ICE Fixes - -* Fix a crash in [`from_iter_instead_of_collect`] - [#6304](https://github.com/rust-lang/rust-clippy/pull/6304) -* Fix a silent crash when parsing doc comments in [`needless_doctest_main`] - [#6458](https://github.com/rust-lang/rust-clippy/pull/6458) - -### Documentation Improvements - -* The lint website search has been improved ([#6477](https://github.com/rust-lang/rust-clippy/pull/6477)): - * Searching for lints with dashes and spaces is possible now. For example - `missing-errors-doc` and `missing errors doc` are now valid aliases for lint names - * Improved fuzzy search in lint descriptions -* Various README improvements - [#6287](https://github.com/rust-lang/rust-clippy/pull/6287) -* Add known problems to [`comparison_chain`] documentation - [#6390](https://github.com/rust-lang/rust-clippy/pull/6390) -* Fix example used in [`cargo_common_metadata`] - [#6293](https://github.com/rust-lang/rust-clippy/pull/6293) -* Improve [`map_clone`] documentation - [#6340](https://github.com/rust-lang/rust-clippy/pull/6340) - -### Others - -* You can now tell Clippy about the MSRV your project supports. Please refer to - the specific README section to learn more about MSRV support [here][msrv_readme] - [#6201](https://github.com/rust-lang/rust-clippy/pull/6201) -* Add `--no-deps` option to avoid running on path dependencies in workspaces - [#6188](https://github.com/rust-lang/rust-clippy/pull/6188) - -## Rust 1.49 - -Released 2020-12-31 - -[View all 107 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2020-09-24T14%3A05%3A12Z..2020-11-05T13%3A35%3A44Z+base%3Amaster) - -### New Lints - -* [`field_reassign_with_default`] [#5911](https://github.com/rust-lang/rust-clippy/pull/5911) -* [`await_holding_refcell_ref`] [#6029](https://github.com/rust-lang/rust-clippy/pull/6029) -* [`disallowed_methods`] [#6081](https://github.com/rust-lang/rust-clippy/pull/6081) -* [`inline_asm_x86_att_syntax`] [#6092](https://github.com/rust-lang/rust-clippy/pull/6092) -* [`inline_asm_x86_intel_syntax`] [#6092](https://github.com/rust-lang/rust-clippy/pull/6092) -* [`from_iter_instead_of_collect`] [#6101](https://github.com/rust-lang/rust-clippy/pull/6101) -* [`mut_mutex_lock`] [#6103](https://github.com/rust-lang/rust-clippy/pull/6103) -* [`single_element_loop`] [#6109](https://github.com/rust-lang/rust-clippy/pull/6109) -* [`manual_unwrap_or`] [#6123](https://github.com/rust-lang/rust-clippy/pull/6123) -* [`large_types_passed_by_value`] [#6135](https://github.com/rust-lang/rust-clippy/pull/6135) -* [`result_unit_err`] [#6157](https://github.com/rust-lang/rust-clippy/pull/6157) -* [`ref_option_ref`] [#6165](https://github.com/rust-lang/rust-clippy/pull/6165) -* [`manual_range_contains`] [#6177](https://github.com/rust-lang/rust-clippy/pull/6177) -* [`unusual_byte_groupings`] [#6183](https://github.com/rust-lang/rust-clippy/pull/6183) -* [`comparison_to_empty`] [#6226](https://github.com/rust-lang/rust-clippy/pull/6226) -* [`map_collect_result_unit`] [#6227](https://github.com/rust-lang/rust-clippy/pull/6227) -* [`manual_ok_or`] [#6233](https://github.com/rust-lang/rust-clippy/pull/6233) - -### Moves and Deprecations - -* Rename `single_char_push_str` to [`single_char_add_str`] - [#6037](https://github.com/rust-lang/rust-clippy/pull/6037) -* Rename `zero_width_space` to [`invisible_characters`] - [#6105](https://github.com/rust-lang/rust-clippy/pull/6105) -* Deprecate `drop_bounds` (uplifted) - [#6111](https://github.com/rust-lang/rust-clippy/pull/6111) -* Move [`string_lit_as_bytes`] to `nursery` - [#6117](https://github.com/rust-lang/rust-clippy/pull/6117) -* Move [`rc_buffer`] to `restriction` - [#6128](https://github.com/rust-lang/rust-clippy/pull/6128) - -### Enhancements - -* [`manual_memcpy`]: Also lint when there are loop counters (and produce a - reliable suggestion) - [#5727](https://github.com/rust-lang/rust-clippy/pull/5727) -* [`single_char_add_str`]: Also lint on `String::insert_str` - [#6037](https://github.com/rust-lang/rust-clippy/pull/6037) -* [`invisible_characters`]: Also lint the characters `\u{AD}` and `\u{2060}` - [#6105](https://github.com/rust-lang/rust-clippy/pull/6105) -* [`eq_op`]: Also lint on the `assert_*!` macro family - [#6167](https://github.com/rust-lang/rust-clippy/pull/6167) -* [`items_after_statements`]: Also lint in local macro expansions - [#6176](https://github.com/rust-lang/rust-clippy/pull/6176) -* [`unnecessary_cast`]: Also lint casts on integer and float literals - [#6187](https://github.com/rust-lang/rust-clippy/pull/6187) -* [`manual_unwrap_or`]: Also lint `Result::unwrap_or` - [#6190](https://github.com/rust-lang/rust-clippy/pull/6190) -* [`match_like_matches_macro`]: Also lint when `match` has more than two arms - [#6216](https://github.com/rust-lang/rust-clippy/pull/6216) -* [`integer_arithmetic`]: Better handle `/` an `%` operators - [#6229](https://github.com/rust-lang/rust-clippy/pull/6229) - -### False Positive Fixes - -* [`needless_lifetimes`]: Bail out if the function has a `where` clause with the - lifetime [#5978](https://github.com/rust-lang/rust-clippy/pull/5978) -* [`explicit_counter_loop`]: No longer lints, when loop counter is used after it - is incremented [#6076](https://github.com/rust-lang/rust-clippy/pull/6076) -* [`or_fun_call`]: Revert changes addressing the handling of `const fn` - [#6077](https://github.com/rust-lang/rust-clippy/pull/6077) -* [`needless_range_loop`]: No longer lints, when the iterable is used in the - range [#6102](https://github.com/rust-lang/rust-clippy/pull/6102) -* [`inconsistent_digit_grouping`]: Fix bug when using floating point exponent - [#6104](https://github.com/rust-lang/rust-clippy/pull/6104) -* [`mistyped_literal_suffixes`]: No longer lints on the fractional part of a - float (e.g. `713.32_64`) - [#6114](https://github.com/rust-lang/rust-clippy/pull/6114) -* [`invalid_regex`]: No longer lint on unicode characters within `bytes::Regex` - [#6132](https://github.com/rust-lang/rust-clippy/pull/6132) -* [`boxed_local`]: No longer lints on `extern fn` arguments - [#6133](https://github.com/rust-lang/rust-clippy/pull/6133) -* [`needless_lifetimes`]: Fix regression, where lifetime is used in `where` - clause [#6198](https://github.com/rust-lang/rust-clippy/pull/6198) - -### Suggestion Fixes/Improvements - -* [`unnecessary_sort_by`]: Avoid dereferencing the suggested closure parameter - [#6078](https://github.com/rust-lang/rust-clippy/pull/6078) -* [`needless_arbitrary_self_type`]: Correctly handle expanded code - [#6093](https://github.com/rust-lang/rust-clippy/pull/6093) -* [`useless_format`]: Preserve raw strings in suggestion - [#6151](https://github.com/rust-lang/rust-clippy/pull/6151) -* [`empty_loop`]: Suggest alternatives - [#6162](https://github.com/rust-lang/rust-clippy/pull/6162) -* [`borrowed_box`]: Correctly add parentheses in suggestion - [#6200](https://github.com/rust-lang/rust-clippy/pull/6200) -* [`unused_unit`]: Improve suggestion formatting - [#6247](https://github.com/rust-lang/rust-clippy/pull/6247) - -### Documentation Improvements - -* Some doc improvements: - * [`rc_buffer`] [#6090](https://github.com/rust-lang/rust-clippy/pull/6090) - * [`empty_loop`] [#6162](https://github.com/rust-lang/rust-clippy/pull/6162) -* [`doc_markdown`]: Document problematic link text style - [#6107](https://github.com/rust-lang/rust-clippy/pull/6107) - -## Rust 1.48 - -Released 2020-11-19 - -[View all 99 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2020-08-11T13%3A14%3A38Z..2020-09-23T18%3A55%3A22Z+base%3Amaster) - -### New lints - -* [`self_assignment`] [#5894](https://github.com/rust-lang/rust-clippy/pull/5894) -* [`unnecessary_lazy_evaluations`] [#5720](https://github.com/rust-lang/rust-clippy/pull/5720) -* [`manual_strip`] [#6038](https://github.com/rust-lang/rust-clippy/pull/6038) -* [`map_err_ignore`] [#5998](https://github.com/rust-lang/rust-clippy/pull/5998) -* [`rc_buffer`] [#6044](https://github.com/rust-lang/rust-clippy/pull/6044) -* `to_string_in_display` [#5831](https://github.com/rust-lang/rust-clippy/pull/5831) -* `single_char_push_str` [#5881](https://github.com/rust-lang/rust-clippy/pull/5881) - -### Moves and Deprecations - -* Downgrade [`verbose_bit_mask`] to pedantic - [#6036](https://github.com/rust-lang/rust-clippy/pull/6036) - -### Enhancements - -* Extend [`precedence`] to handle chains of methods combined with unary negation - [#5928](https://github.com/rust-lang/rust-clippy/pull/5928) -* [`useless_vec`]: add a configuration value for the maximum allowed size on the stack - [#5907](https://github.com/rust-lang/rust-clippy/pull/5907) -* [`suspicious_arithmetic_impl`]: extend to implementations of `BitAnd`, `BitOr`, `BitXor`, `Rem`, `Shl`, and `Shr` - [#5884](https://github.com/rust-lang/rust-clippy/pull/5884) -* `invalid_atomic_ordering`: detect misuse of `compare_exchange`, `compare_exchange_weak`, and `fetch_update` - [#6025](https://github.com/rust-lang/rust-clippy/pull/6025) -* Avoid [`redundant_pattern_matching`] triggering in macros - [#6069](https://github.com/rust-lang/rust-clippy/pull/6069) -* [`option_if_let_else`]: distinguish pure from impure `else` expressions - [#5937](https://github.com/rust-lang/rust-clippy/pull/5937) -* [`needless_doctest_main`]: parse doctests instead of using textual search - [#5912](https://github.com/rust-lang/rust-clippy/pull/5912) -* [`wildcard_imports`]: allow `prelude` to appear in any segment of an import - [#5929](https://github.com/rust-lang/rust-clippy/pull/5929) -* Re-enable [`len_zero`] for ranges now that `range_is_empty` is stable - [#5961](https://github.com/rust-lang/rust-clippy/pull/5961) -* [`option_as_ref_deref`]: catch fully-qualified calls to `Deref::deref` and `DerefMut::deref_mut` - [#5933](https://github.com/rust-lang/rust-clippy/pull/5933) - -### False Positive Fixes - -* [`useless_attribute`]: permit allowing [`wildcard_imports`] and [`enum_glob_use`] - [#5994](https://github.com/rust-lang/rust-clippy/pull/5994) -* [`transmute_ptr_to_ptr`]: avoid suggesting dereferencing raw pointers in const contexts - [#5999](https://github.com/rust-lang/rust-clippy/pull/5999) -* [`redundant_closure_call`]: take into account usages of the closure in nested functions and closures - [#5920](https://github.com/rust-lang/rust-clippy/pull/5920) -* Fix false positive in [`borrow_interior_mutable_const`] when referencing a field behind a pointer - [#5949](https://github.com/rust-lang/rust-clippy/pull/5949) -* [`doc_markdown`]: allow using "GraphQL" without backticks - [#5996](https://github.com/rust-lang/rust-clippy/pull/5996) -* `to_string_in_display`: avoid linting when calling `to_string()` on anything that is not `self` - [#5971](https://github.com/rust-lang/rust-clippy/pull/5971) -* [`indexing_slicing`] and [`out_of_bounds_indexing`] treat references to arrays as arrays - [#6034](https://github.com/rust-lang/rust-clippy/pull/6034) -* [`should_implement_trait`]: ignore methods with lifetime parameters - [#5725](https://github.com/rust-lang/rust-clippy/pull/5725) -* [`needless_return`]: avoid linting if a temporary borrows a local variable - [#5903](https://github.com/rust-lang/rust-clippy/pull/5903) -* Restrict [`unnecessary_sort_by`] to non-reference, Copy types - [#6006](https://github.com/rust-lang/rust-clippy/pull/6006) -* Avoid suggesting `from_bits`/`to_bits` in const contexts in [`transmute_int_to_float`] - [#5919](https://github.com/rust-lang/rust-clippy/pull/5919) -* [`declare_interior_mutable_const`] and [`borrow_interior_mutable_const`]: improve detection of interior mutable types - [#6046](https://github.com/rust-lang/rust-clippy/pull/6046) - -### Suggestion Fixes/Improvements - -* [`let_and_return`]: add a cast to the suggestion when the return expression has adjustments - [#5946](https://github.com/rust-lang/rust-clippy/pull/5946) -* [`useless_conversion`]: show the type in the error message - [#6035](https://github.com/rust-lang/rust-clippy/pull/6035) -* [`unnecessary_mut_passed`]: discriminate between functions and methods in the error message - [#5892](https://github.com/rust-lang/rust-clippy/pull/5892) -* [`float_cmp`] and [`float_cmp_const`]: change wording to make margin of error less ambiguous - [#6043](https://github.com/rust-lang/rust-clippy/pull/6043) -* [`default_trait_access`]: do not use unnecessary type parameters in the suggestion - [#5993](https://github.com/rust-lang/rust-clippy/pull/5993) -* [`collapsible_if`]: don't use expanded code in the suggestion - [#5992](https://github.com/rust-lang/rust-clippy/pull/5992) -* Do not suggest empty format strings in [`print_with_newline`] and [`write_with_newline`] - [#6042](https://github.com/rust-lang/rust-clippy/pull/6042) -* [`unit_arg`]: improve the readability of the suggestion - [#5931](https://github.com/rust-lang/rust-clippy/pull/5931) -* [`stable_sort_primitive`]: print the type that is being sorted in the lint message - [#5935](https://github.com/rust-lang/rust-clippy/pull/5935) -* Show line count and max lines in [`too_many_lines`] lint message - [#6009](https://github.com/rust-lang/rust-clippy/pull/6009) -* Keep parentheses in the suggestion of [`useless_conversion`] where applicable - [#5900](https://github.com/rust-lang/rust-clippy/pull/5900) -* [`option_map_unit_fn`] and [`result_map_unit_fn`]: print the unit type `()` explicitly - [#6024](https://github.com/rust-lang/rust-clippy/pull/6024) -* [`redundant_allocation`]: suggest replacing `Rc>` with `Rc` - [#5899](https://github.com/rust-lang/rust-clippy/pull/5899) -* Make lint messages adhere to rustc dev guide conventions - [#5893](https://github.com/rust-lang/rust-clippy/pull/5893) - -### ICE Fixes - -* Fix ICE in [`repeat_once`] - [#5948](https://github.com/rust-lang/rust-clippy/pull/5948) - -### Documentation Improvements - -* [`mutable_key_type`]: explain potential for false positives when the interior mutable type is not accessed in the `Hash` implementation - [#6019](https://github.com/rust-lang/rust-clippy/pull/6019) -* [`unnecessary_mut_passed`]: fix typo - [#5913](https://github.com/rust-lang/rust-clippy/pull/5913) -* Add example of false positive to [`ptr_arg`] docs. - [#5885](https://github.com/rust-lang/rust-clippy/pull/5885) -* [`box_vec`](https://rust-lang.github.io/rust-clippy/master/index.html#box_collection), [`vec_box`] and [`borrowed_box`]: add link to the documentation of `Box` - [#6023](https://github.com/rust-lang/rust-clippy/pull/6023) - -## Rust 1.47 - -Released 2020-10-08 - -[View all 76 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2020-06-23T16%3A27%3A11Z..2020-08-11T12%3A52%3A41Z+base%3Amaster) - -### New lints - -* [`derive_ord_xor_partial_ord`] [#5848](https://github.com/rust-lang/rust-clippy/pull/5848) -* [`trait_duplication_in_bounds`] [#5852](https://github.com/rust-lang/rust-clippy/pull/5852) -* [`map_identity`] [#5694](https://github.com/rust-lang/rust-clippy/pull/5694) -* [`unit_return_expecting_ord`] [#5737](https://github.com/rust-lang/rust-clippy/pull/5737) -* [`pattern_type_mismatch`] [#4841](https://github.com/rust-lang/rust-clippy/pull/4841) -* [`repeat_once`] [#5773](https://github.com/rust-lang/rust-clippy/pull/5773) -* [`same_item_push`] [#5825](https://github.com/rust-lang/rust-clippy/pull/5825) -* [`needless_arbitrary_self_type`] [#5869](https://github.com/rust-lang/rust-clippy/pull/5869) -* [`match_like_matches_macro`] [#5769](https://github.com/rust-lang/rust-clippy/pull/5769) -* [`stable_sort_primitive`] [#5809](https://github.com/rust-lang/rust-clippy/pull/5809) -* [`blanket_clippy_restriction_lints`] [#5750](https://github.com/rust-lang/rust-clippy/pull/5750) -* [`option_if_let_else`] [#5301](https://github.com/rust-lang/rust-clippy/pull/5301) - -### Moves and Deprecations - -* Deprecate [`regex_macro`] lint - [#5760](https://github.com/rust-lang/rust-clippy/pull/5760) -* Move [`range_minus_one`] to `pedantic` - [#5752](https://github.com/rust-lang/rust-clippy/pull/5752) - -### Enhancements - -* Improve [`needless_collect`] by catching `collect` calls followed by `iter` or `into_iter` calls - [#5837](https://github.com/rust-lang/rust-clippy/pull/5837) -* [`panic`], [`todo`], [`unimplemented`] and [`unreachable`] now detect calls with formatting - [#5811](https://github.com/rust-lang/rust-clippy/pull/5811) -* Detect more cases of [`suboptimal_flops`] and [`imprecise_flops`] - [#5443](https://github.com/rust-lang/rust-clippy/pull/5443) -* Handle asymmetrical implementations of `PartialEq` in [`cmp_owned`] - [#5701](https://github.com/rust-lang/rust-clippy/pull/5701) -* Make it possible to allow [`unsafe_derive_deserialize`] - [#5870](https://github.com/rust-lang/rust-clippy/pull/5870) -* Catch `ord.min(a).max(b)` where a < b in [`min_max`] - [#5871](https://github.com/rust-lang/rust-clippy/pull/5871) -* Make [`clone_on_copy`] suggestion machine applicable - [#5745](https://github.com/rust-lang/rust-clippy/pull/5745) -* Enable [`len_zero`] on ranges now that `is_empty` is stable on them - [#5961](https://github.com/rust-lang/rust-clippy/pull/5961) - -### False Positive Fixes - -* Avoid triggering [`or_fun_call`] with const fns that take no arguments - [#5889](https://github.com/rust-lang/rust-clippy/pull/5889) -* Fix [`redundant_closure_call`] false positive for closures that have multiple calls - [#5800](https://github.com/rust-lang/rust-clippy/pull/5800) -* Don't lint cases involving `ManuallyDrop` in [`redundant_clone`] - [#5824](https://github.com/rust-lang/rust-clippy/pull/5824) -* Treat a single expression the same as a single statement in the 2nd arm of a match in [`single_match_else`] - [#5771](https://github.com/rust-lang/rust-clippy/pull/5771) -* Don't trigger [`unnested_or_patterns`] if the feature `or_patterns` is not enabled - [#5758](https://github.com/rust-lang/rust-clippy/pull/5758) -* Avoid linting if key borrows in [`unnecessary_sort_by`] - [#5756](https://github.com/rust-lang/rust-clippy/pull/5756) -* Consider `Try` impl for `Poll` when generating suggestions in [`try_err`] - [#5857](https://github.com/rust-lang/rust-clippy/pull/5857) -* Take input lifetimes into account in `manual_async_fn` - [#5859](https://github.com/rust-lang/rust-clippy/pull/5859) -* Fix multiple false positives in [`type_repetition_in_bounds`] and add a configuration option - [#5761](https://github.com/rust-lang/rust-clippy/pull/5761) -* Limit the [`suspicious_arithmetic_impl`] lint to one binary operation - [#5820](https://github.com/rust-lang/rust-clippy/pull/5820) - -### Suggestion Fixes/Improvements - -* Improve readability of [`shadow_unrelated`] suggestion by truncating the RHS snippet - [#5788](https://github.com/rust-lang/rust-clippy/pull/5788) -* Suggest `filter_map` instead of `flat_map` when mapping to `Option` in [`map_flatten`] - [#5846](https://github.com/rust-lang/rust-clippy/pull/5846) -* Ensure suggestion is shown correctly for long method call chains in [`iter_nth_zero`] - [#5793](https://github.com/rust-lang/rust-clippy/pull/5793) -* Drop borrow operator in suggestions of [`redundant_pattern_matching`] - [#5815](https://github.com/rust-lang/rust-clippy/pull/5815) -* Add suggestion for [`iter_skip_next`] - [#5843](https://github.com/rust-lang/rust-clippy/pull/5843) -* Improve [`collapsible_if`] fix suggestion - [#5732](https://github.com/rust-lang/rust-clippy/pull/5732) - -### ICE Fixes - -* Fix ICE caused by [`needless_collect`] - [#5877](https://github.com/rust-lang/rust-clippy/pull/5877) -* Fix ICE caused by [`unnested_or_patterns`] - [#5784](https://github.com/rust-lang/rust-clippy/pull/5784) - -### Documentation Improvements - -* Fix grammar of [`await_holding_lock`] documentation - [#5748](https://github.com/rust-lang/rust-clippy/pull/5748) - -### Others - -* Make lints adhere to the rustc dev guide - [#5888](https://github.com/rust-lang/rust-clippy/pull/5888) - -## Rust 1.46 - -Released 2020-08-27 - -[View all 48 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2020-05-31T12%3A50%3A53Z..2020-06-23T15%3A00%3A32Z+base%3Amaster) - -### New lints - -* [`unnested_or_patterns`] [#5378](https://github.com/rust-lang/rust-clippy/pull/5378) -* [`iter_next_slice`] [#5597](https://github.com/rust-lang/rust-clippy/pull/5597) -* [`unnecessary_sort_by`] [#5623](https://github.com/rust-lang/rust-clippy/pull/5623) -* [`vec_resize_to_zero`] [#5637](https://github.com/rust-lang/rust-clippy/pull/5637) - -### Moves and Deprecations - -* Move [`cast_ptr_alignment`] to pedantic [#5667](https://github.com/rust-lang/rust-clippy/pull/5667) - -### Enhancements - -* Improve [`mem_replace_with_uninit`] lint [#5695](https://github.com/rust-lang/rust-clippy/pull/5695) - -### False Positive Fixes - -* [`len_zero`]: Avoid linting ranges when the `range_is_empty` feature is not enabled - [#5656](https://github.com/rust-lang/rust-clippy/pull/5656) -* [`let_and_return`]: Don't lint if a temporary borrow is involved - [#5680](https://github.com/rust-lang/rust-clippy/pull/5680) -* [`reversed_empty_ranges`]: Avoid linting `N..N` in for loop arguments in - [#5692](https://github.com/rust-lang/rust-clippy/pull/5692) -* [`if_same_then_else`]: Don't assume multiplication is always commutative - [#5702](https://github.com/rust-lang/rust-clippy/pull/5702) -* [`disallowed_names`]: Remove `bar` from the default configuration - [#5712](https://github.com/rust-lang/rust-clippy/pull/5712) -* [`redundant_pattern_matching`]: Avoid suggesting non-`const fn` calls in const contexts - [#5724](https://github.com/rust-lang/rust-clippy/pull/5724) - -### Suggestion Fixes/Improvements - -* Fix suggestion of [`unit_arg`] lint, so that it suggest semantic equivalent code - [#4455](https://github.com/rust-lang/rust-clippy/pull/4455) -* Add auto applicable suggestion to [`macro_use_imports`] - [#5279](https://github.com/rust-lang/rust-clippy/pull/5279) - -### ICE Fixes - -* Fix ICE in the `consts` module of Clippy [#5709](https://github.com/rust-lang/rust-clippy/pull/5709) - -### Documentation Improvements - -* Improve code examples across multiple lints [#5664](https://github.com/rust-lang/rust-clippy/pull/5664) - -### Others - -* Introduce a `--rustc` flag to `clippy-driver`, which turns `clippy-driver` - into `rustc` and passes all the given arguments to `rustc`. This is especially - useful for tools that need the `rustc` version Clippy was compiled with, - instead of the Clippy version. E.g. `clippy-driver --rustc --version` will - print the output of `rustc --version`. - [#5178](https://github.com/rust-lang/rust-clippy/pull/5178) -* New issue templates now make it easier to complain if Clippy is too annoying - or not annoying enough! [#5735](https://github.com/rust-lang/rust-clippy/pull/5735) - -## Rust 1.45 - -Released 2020-07-16 - -[View all 81 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2020-04-18T20%3A18%3A04Z..2020-05-27T19%3A25%3A04Z+base%3Amaster) - -### New lints - -* [`match_wildcard_for_single_variants`] [#5582](https://github.com/rust-lang/rust-clippy/pull/5582) -* [`unsafe_derive_deserialize`] [#5493](https://github.com/rust-lang/rust-clippy/pull/5493) -* [`if_let_mutex`] [#5332](https://github.com/rust-lang/rust-clippy/pull/5332) -* [`mismatched_target_os`] [#5506](https://github.com/rust-lang/rust-clippy/pull/5506) -* [`await_holding_lock`] [#5439](https://github.com/rust-lang/rust-clippy/pull/5439) -* [`match_on_vec_items`] [#5522](https://github.com/rust-lang/rust-clippy/pull/5522) -* [`manual_async_fn`] [#5576](https://github.com/rust-lang/rust-clippy/pull/5576) -* [`reversed_empty_ranges`] [#5583](https://github.com/rust-lang/rust-clippy/pull/5583) -* [`manual_non_exhaustive`] [#5550](https://github.com/rust-lang/rust-clippy/pull/5550) - -### Moves and Deprecations - -* Downgrade [`match_bool`] to pedantic [#5408](https://github.com/rust-lang/rust-clippy/pull/5408) -* Downgrade [`match_wild_err_arm`] to pedantic and update help messages. [#5622](https://github.com/rust-lang/rust-clippy/pull/5622) -* Downgrade [`useless_let_if_seq`] to nursery. [#5599](https://github.com/rust-lang/rust-clippy/pull/5599) -* Generalize `option_and_then_some` and rename to [`bind_instead_of_map`]. [#5529](https://github.com/rust-lang/rust-clippy/pull/5529) -* Rename `identity_conversion` to [`useless_conversion`]. [#5568](https://github.com/rust-lang/rust-clippy/pull/5568) -* Merge `block_in_if_condition_expr` and `block_in_if_condition_stmt` into [`blocks_in_if_conditions`]. -[#5563](https://github.com/rust-lang/rust-clippy/pull/5563) -* Merge `option_map_unwrap_or`, `option_map_unwrap_or_else` and `result_map_unwrap_or_else` into [`map_unwrap_or`]. -[#5563](https://github.com/rust-lang/rust-clippy/pull/5563) -* Merge `option_unwrap_used` and `result_unwrap_used` into [`unwrap_used`]. -[#5563](https://github.com/rust-lang/rust-clippy/pull/5563) -* Merge `option_expect_used` and `result_expect_used` into [`expect_used`]. -[#5563](https://github.com/rust-lang/rust-clippy/pull/5563) -* Merge `for_loop_over_option` and `for_loop_over_result` into [`for_loops_over_fallibles`]. -[#5563](https://github.com/rust-lang/rust-clippy/pull/5563) - -### Enhancements - -* Avoid running cargo lints when not enabled to improve performance. [#5505](https://github.com/rust-lang/rust-clippy/pull/5505) -* Extend [`useless_conversion`] with `TryFrom` and `TryInto`. [#5631](https://github.com/rust-lang/rust-clippy/pull/5631) -* Lint also in type parameters and where clauses in [`unused_unit`]. [#5592](https://github.com/rust-lang/rust-clippy/pull/5592) -* Do not suggest deriving `Default` in [`new_without_default`]. [#5616](https://github.com/rust-lang/rust-clippy/pull/5616) - -### False Positive Fixes - -* [`while_let_on_iterator`] [#5525](https://github.com/rust-lang/rust-clippy/pull/5525) -* [`empty_line_after_outer_attr`] [#5609](https://github.com/rust-lang/rust-clippy/pull/5609) -* [`unnecessary_unwrap`] [#5558](https://github.com/rust-lang/rust-clippy/pull/5558) -* [`comparison_chain`] [#5596](https://github.com/rust-lang/rust-clippy/pull/5596) -* Don't trigger [`used_underscore_binding`] in await desugaring. [#5535](https://github.com/rust-lang/rust-clippy/pull/5535) -* Don't trigger [`borrowed_box`] on mutable references. [#5491](https://github.com/rust-lang/rust-clippy/pull/5491) -* Allow `1 << 0` in [`identity_op`]. [#5602](https://github.com/rust-lang/rust-clippy/pull/5602) -* Allow `use super::*;` glob imports in [`wildcard_imports`]. [#5564](https://github.com/rust-lang/rust-clippy/pull/5564) -* Whitelist more words in [`doc_markdown`]. [#5611](https://github.com/rust-lang/rust-clippy/pull/5611) -* Skip dev and build deps in [`multiple_crate_versions`]. [#5636](https://github.com/rust-lang/rust-clippy/pull/5636) -* Honor `allow` attribute on arguments in [`ptr_arg`]. [#5647](https://github.com/rust-lang/rust-clippy/pull/5647) -* Honor lint level attributes for [`redundant_field_names`], [`just_underscores_and_digits`], [`many_single_char_names`] -and [`similar_names`]. [#5651](https://github.com/rust-lang/rust-clippy/pull/5651) -* Ignore calls to `len` in [`or_fun_call`]. [#4429](https://github.com/rust-lang/rust-clippy/pull/4429) - -### Suggestion Improvements - -* Simplify suggestions in [`manual_memcpy`]. [#5536](https://github.com/rust-lang/rust-clippy/pull/5536) -* Fix suggestion in [`redundant_pattern_matching`] for macros. [#5511](https://github.com/rust-lang/rust-clippy/pull/5511) -* Avoid suggesting `copied()` for mutable references in [`map_clone`]. [#5530](https://github.com/rust-lang/rust-clippy/pull/5530) -* Improve help message for [`clone_double_ref`]. [#5547](https://github.com/rust-lang/rust-clippy/pull/5547) - -### ICE Fixes - -* Fix ICE caused in unwrap module. [#5590](https://github.com/rust-lang/rust-clippy/pull/5590) -* Fix ICE on rustc test issue-69020-assoc-const-arith-overflow.rs [#5499](https://github.com/rust-lang/rust-clippy/pull/5499) - -### Documentation - -* Clarify the documentation of [`unnecessary_mut_passed`]. [#5639](https://github.com/rust-lang/rust-clippy/pull/5639) -* Extend example for [`unneeded_field_pattern`]. [#5541](https://github.com/rust-lang/rust-clippy/pull/5541) - -## Rust 1.44 - -Released 2020-06-04 - -[View all 124 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2020-03-05T17%3A30%3A53Z..2020-04-18T09%3A20%3A51Z+base%3Amaster) - -### New lints - -* [`explicit_deref_methods`] [#5226](https://github.com/rust-lang/rust-clippy/pull/5226) -* [`implicit_saturating_sub`] [#5427](https://github.com/rust-lang/rust-clippy/pull/5427) -* [`macro_use_imports`] [#5230](https://github.com/rust-lang/rust-clippy/pull/5230) -* [`verbose_file_reads`] [#5272](https://github.com/rust-lang/rust-clippy/pull/5272) -* [`future_not_send`] [#5423](https://github.com/rust-lang/rust-clippy/pull/5423) -* [`redundant_pub_crate`] [#5319](https://github.com/rust-lang/rust-clippy/pull/5319) -* [`large_const_arrays`] [#5248](https://github.com/rust-lang/rust-clippy/pull/5248) -* [`result_map_or_into_option`] [#5415](https://github.com/rust-lang/rust-clippy/pull/5415) -* [`redundant_allocation`] [#5349](https://github.com/rust-lang/rust-clippy/pull/5349) -* [`fn_address_comparisons`] [#5294](https://github.com/rust-lang/rust-clippy/pull/5294) -* [`vtable_address_comparisons`] [#5294](https://github.com/rust-lang/rust-clippy/pull/5294) - - -### Moves and Deprecations - -* Deprecate [`replace_consts`] lint [#5380](https://github.com/rust-lang/rust-clippy/pull/5380) -* Move [`cognitive_complexity`] to nursery [#5428](https://github.com/rust-lang/rust-clippy/pull/5428) -* Move [`useless_transmute`] to nursery [#5364](https://github.com/rust-lang/rust-clippy/pull/5364) -* Downgrade [`inefficient_to_string`] to pedantic [#5412](https://github.com/rust-lang/rust-clippy/pull/5412) -* Downgrade [`option_option`] to pedantic [#5401](https://github.com/rust-lang/rust-clippy/pull/5401) -* Downgrade [`unreadable_literal`] to pedantic [#5419](https://github.com/rust-lang/rust-clippy/pull/5419) -* Downgrade [`let_unit_value`] to pedantic [#5409](https://github.com/rust-lang/rust-clippy/pull/5409) -* Downgrade [`trivially_copy_pass_by_ref`] to pedantic [#5410](https://github.com/rust-lang/rust-clippy/pull/5410) -* Downgrade [`implicit_hasher`] to pedantic [#5411](https://github.com/rust-lang/rust-clippy/pull/5411) - -### Enhancements - -* On _nightly_ you can now use `cargo clippy --fix -Z unstable-options` to - auto-fix lints that support this [#5363](https://github.com/rust-lang/rust-clippy/pull/5363) -* Make [`redundant_clone`] also trigger on cases where the cloned value is not - consumed. [#5304](https://github.com/rust-lang/rust-clippy/pull/5304) -* Expand [`integer_arithmetic`] to also disallow bit-shifting [#5430](https://github.com/rust-lang/rust-clippy/pull/5430) -* [`option_as_ref_deref`] now detects more deref cases [#5425](https://github.com/rust-lang/rust-clippy/pull/5425) -* [`large_enum_variant`] now report the sizes of the largest and second-largest variants [#5466](https://github.com/rust-lang/rust-clippy/pull/5466) -* [`bool_comparison`] now also checks for inequality comparisons that can be - written more concisely [#5365](https://github.com/rust-lang/rust-clippy/pull/5365) -* Expand [`clone_on_copy`] to work in method call arguments as well [#5441](https://github.com/rust-lang/rust-clippy/pull/5441) -* [`redundant_pattern_matching`] now also handles `while let` [#5483](https://github.com/rust-lang/rust-clippy/pull/5483) -* [`integer_arithmetic`] now also lints references of integers [#5329](https://github.com/rust-lang/rust-clippy/pull/5329) -* Expand [`float_cmp_const`] to also work on arrays [#5345](https://github.com/rust-lang/rust-clippy/pull/5345) -* Trigger [`map_flatten`] when map is called on an `Option` [#5473](https://github.com/rust-lang/rust-clippy/pull/5473) - -### False Positive Fixes - -* [`many_single_char_names`] [#5468](https://github.com/rust-lang/rust-clippy/pull/5468) -* [`should_implement_trait`] [#5437](https://github.com/rust-lang/rust-clippy/pull/5437) -* [`unused_self`] [#5387](https://github.com/rust-lang/rust-clippy/pull/5387) -* [`redundant_clone`] [#5453](https://github.com/rust-lang/rust-clippy/pull/5453) -* [`precedence`] [#5445](https://github.com/rust-lang/rust-clippy/pull/5445) -* [`suspicious_op_assign_impl`] [#5424](https://github.com/rust-lang/rust-clippy/pull/5424) -* [`needless_lifetimes`] [#5293](https://github.com/rust-lang/rust-clippy/pull/5293) -* [`redundant_pattern`] [#5287](https://github.com/rust-lang/rust-clippy/pull/5287) -* [`inconsistent_digit_grouping`] [#5451](https://github.com/rust-lang/rust-clippy/pull/5451) - - -### Suggestion Improvements - -* Improved [`question_mark`] lint suggestion so that it doesn't add redundant `as_ref()` [#5481](https://github.com/rust-lang/rust-clippy/pull/5481) -* Improve the suggested placeholder in [`option_map_unit_fn`] [#5292](https://github.com/rust-lang/rust-clippy/pull/5292) -* Improve suggestion for [`match_single_binding`] when triggered inside a closure [#5350](https://github.com/rust-lang/rust-clippy/pull/5350) - -### ICE Fixes - -* Handle the unstable `trivial_bounds` feature [#5296](https://github.com/rust-lang/rust-clippy/pull/5296) -* `shadow_*` lints [#5297](https://github.com/rust-lang/rust-clippy/pull/5297) - -### Documentation - -* Fix documentation generation for configurable lints [#5353](https://github.com/rust-lang/rust-clippy/pull/5353) -* Update documentation for [`new_ret_no_self`] [#5448](https://github.com/rust-lang/rust-clippy/pull/5448) -* The documentation for [`option_option`] now suggest using a tri-state enum [#5403](https://github.com/rust-lang/rust-clippy/pull/5403) -* Fix bit mask example in [`verbose_bit_mask`] documentation [#5454](https://github.com/rust-lang/rust-clippy/pull/5454) -* [`wildcard_imports`] documentation now mentions that `use ...::prelude::*` is - not linted [#5312](https://github.com/rust-lang/rust-clippy/pull/5312) - -## Rust 1.43 - -Released 2020-04-23 - -[View all 91 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2020-01-26T16%3A01%3A11Z..2020-03-04T16%3A45%3A37Z+base%3Amaster) - -### New lints - -* [`imprecise_flops`] [#4897](https://github.com/rust-lang/rust-clippy/pull/4897) -* [`suboptimal_flops`] [#4897](https://github.com/rust-lang/rust-clippy/pull/4897) -* [`wildcard_imports`] [#5029](https://github.com/rust-lang/rust-clippy/pull/5029) -* [`single_component_path_imports`] [#5058](https://github.com/rust-lang/rust-clippy/pull/5058) -* [`match_single_binding`] [#5061](https://github.com/rust-lang/rust-clippy/pull/5061) -* [`let_underscore_lock`] [#5101](https://github.com/rust-lang/rust-clippy/pull/5101) -* [`struct_excessive_bools`] [#5125](https://github.com/rust-lang/rust-clippy/pull/5125) -* [`fn_params_excessive_bools`] [#5125](https://github.com/rust-lang/rust-clippy/pull/5125) -* [`option_env_unwrap`] [#5148](https://github.com/rust-lang/rust-clippy/pull/5148) -* [`lossy_float_literal`] [#5202](https://github.com/rust-lang/rust-clippy/pull/5202) -* [`rest_pat_in_fully_bound_structs`] [#5258](https://github.com/rust-lang/rust-clippy/pull/5258) - -### Moves and Deprecations - -* Move [`unneeded_field_pattern`] to pedantic group [#5200](https://github.com/rust-lang/rust-clippy/pull/5200) - -### Enhancements - -* Make [`missing_errors_doc`] lint also trigger on `async` functions - [#5181](https://github.com/rust-lang/rust-clippy/pull/5181) -* Add more constants to [`approx_constant`] [#5193](https://github.com/rust-lang/rust-clippy/pull/5193) -* Extend [`question_mark`] lint [#5266](https://github.com/rust-lang/rust-clippy/pull/5266) - -### False Positive Fixes - -* [`use_debug`] [#5047](https://github.com/rust-lang/rust-clippy/pull/5047) -* [`unnecessary_unwrap`] [#5132](https://github.com/rust-lang/rust-clippy/pull/5132) -* [`zero_prefixed_literal`] [#5170](https://github.com/rust-lang/rust-clippy/pull/5170) -* [`missing_const_for_fn`] [#5216](https://github.com/rust-lang/rust-clippy/pull/5216) - -### Suggestion Improvements - -* Improve suggestion when blocks of code are suggested [#5134](https://github.com/rust-lang/rust-clippy/pull/5134) - -### ICE Fixes - -* `misc_early` lints [#5129](https://github.com/rust-lang/rust-clippy/pull/5129) -* [`missing_errors_doc`] [#5213](https://github.com/rust-lang/rust-clippy/pull/5213) -* Fix ICE when evaluating `usize`s [#5256](https://github.com/rust-lang/rust-clippy/pull/5256) - -### Documentation - -* Improve documentation of [`iter_nth_zero`] -* Add documentation pages for stable releases [#5171](https://github.com/rust-lang/rust-clippy/pull/5171) - -### Others - -* Clippy now completely runs on GitHub Actions [#5190](https://github.com/rust-lang/rust-clippy/pull/5190) - - -## Rust 1.42 - -Released 2020-03-12 - -[View all 101 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2019-12-15T01%3A40%3A34Z..2020-01-26T11%3A22%3A13Z+base%3Amaster) - -### New lints - -* [`filetype_is_file`] [#4543](https://github.com/rust-lang/rust-clippy/pull/4543) -* [`let_underscore_must_use`] [#4823](https://github.com/rust-lang/rust-clippy/pull/4823) -* [`modulo_arithmetic`] [#4867](https://github.com/rust-lang/rust-clippy/pull/4867) -* [`mem_replace_with_default`] [#4881](https://github.com/rust-lang/rust-clippy/pull/4881) -* [`mutable_key_type`] [#4885](https://github.com/rust-lang/rust-clippy/pull/4885) -* [`option_as_ref_deref`] [#4945](https://github.com/rust-lang/rust-clippy/pull/4945) -* [`wildcard_in_or_patterns`] [#4960](https://github.com/rust-lang/rust-clippy/pull/4960) -* [`iter_nth_zero`] [#4966](https://github.com/rust-lang/rust-clippy/pull/4966) -* `invalid_atomic_ordering` [#4999](https://github.com/rust-lang/rust-clippy/pull/4999) -* [`skip_while_next`] [#5067](https://github.com/rust-lang/rust-clippy/pull/5067) - -### Moves and Deprecations - -* Move [`transmute_float_to_int`] from nursery to complexity group - [#5015](https://github.com/rust-lang/rust-clippy/pull/5015) -* Move [`range_plus_one`] to pedantic group [#5057](https://github.com/rust-lang/rust-clippy/pull/5057) -* Move [`debug_assert_with_mut_call`] to nursery group [#5106](https://github.com/rust-lang/rust-clippy/pull/5106) -* Deprecate `unused_label` [#4930](https://github.com/rust-lang/rust-clippy/pull/4930) - -### Enhancements - -* Lint vectored IO in [`unused_io_amount`] [#5027](https://github.com/rust-lang/rust-clippy/pull/5027) -* Make [`vec_box`] configurable by adding a size threshold [#5081](https://github.com/rust-lang/rust-clippy/pull/5081) -* Also lint constants in [`cmp_nan`] [#4910](https://github.com/rust-lang/rust-clippy/pull/4910) -* Fix false negative in [`expect_fun_call`] [#4915](https://github.com/rust-lang/rust-clippy/pull/4915) -* Fix false negative in [`redundant_clone`] [#5017](https://github.com/rust-lang/rust-clippy/pull/5017) - -### False Positive Fixes - -* [`map_clone`] [#4937](https://github.com/rust-lang/rust-clippy/pull/4937) -* [`replace_consts`] [#4977](https://github.com/rust-lang/rust-clippy/pull/4977) -* [`let_and_return`] [#5008](https://github.com/rust-lang/rust-clippy/pull/5008) -* [`eq_op`] [#5079](https://github.com/rust-lang/rust-clippy/pull/5079) -* [`possible_missing_comma`] [#5083](https://github.com/rust-lang/rust-clippy/pull/5083) -* [`debug_assert_with_mut_call`] [#5106](https://github.com/rust-lang/rust-clippy/pull/5106) -* Don't trigger [`let_underscore_must_use`] in external macros - [#5082](https://github.com/rust-lang/rust-clippy/pull/5082) -* Don't trigger [`empty_loop`] in `no_std` crates [#5086](https://github.com/rust-lang/rust-clippy/pull/5086) - -### Suggestion Improvements - -* `option_map_unwrap_or` [#4634](https://github.com/rust-lang/rust-clippy/pull/4634) -* [`wildcard_enum_match_arm`] [#4934](https://github.com/rust-lang/rust-clippy/pull/4934) -* [`cognitive_complexity`] [#4935](https://github.com/rust-lang/rust-clippy/pull/4935) -* [`decimal_literal_representation`] [#4956](https://github.com/rust-lang/rust-clippy/pull/4956) -* `unknown_clippy_lints` [#4963](https://github.com/rust-lang/rust-clippy/pull/4963) -* [`explicit_into_iter_loop`] [#4978](https://github.com/rust-lang/rust-clippy/pull/4978) -* [`useless_attribute`] [#5022](https://github.com/rust-lang/rust-clippy/pull/5022) -* `if_let_some_result` [#5032](https://github.com/rust-lang/rust-clippy/pull/5032) - -### ICE fixes - -* [`unsound_collection_transmute`] [#4975](https://github.com/rust-lang/rust-clippy/pull/4975) - -### Documentation - -* Improve documentation of [`empty_enum`], [`replace_consts`], [`redundant_clone`], and [`iterator_step_by_zero`] - - -## Rust 1.41 - -Released 2020-01-30 - -[View all 74 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2019-10-28T20%3A50%3A24Z..2019-12-12T00%3A53%3A03Z+base%3Amaster) - -* New Lints: - * [`exit`] [#4697](https://github.com/rust-lang/rust-clippy/pull/4697) - * [`to_digit_is_some`] [#4801](https://github.com/rust-lang/rust-clippy/pull/4801) - * [`tabs_in_doc_comments`] [#4806](https://github.com/rust-lang/rust-clippy/pull/4806) - * [`large_stack_arrays`] [#4807](https://github.com/rust-lang/rust-clippy/pull/4807) - * [`same_functions_in_if_condition`] [#4814](https://github.com/rust-lang/rust-clippy/pull/4814) - * [`zst_offset`] [#4816](https://github.com/rust-lang/rust-clippy/pull/4816) - * [`as_conversions`] [#4821](https://github.com/rust-lang/rust-clippy/pull/4821) - * [`missing_errors_doc`] [#4884](https://github.com/rust-lang/rust-clippy/pull/4884) - * [`transmute_float_to_int`] [#4889](https://github.com/rust-lang/rust-clippy/pull/4889) -* Remove plugin interface, see - [Inside Rust Blog](https://blog.rust-lang.org/inside-rust/2019/11/04/Clippy-removes-plugin-interface.html) for - details [#4714](https://github.com/rust-lang/rust-clippy/pull/4714) -* Move [`use_self`] to nursery group [#4863](https://github.com/rust-lang/rust-clippy/pull/4863) -* Deprecate `into_iter_on_array` [#4788](https://github.com/rust-lang/rust-clippy/pull/4788) -* Expand [`string_lit_as_bytes`] to also trigger when literal has escapes - [#4808](https://github.com/rust-lang/rust-clippy/pull/4808) -* Fix false positive in `comparison_chain` [#4842](https://github.com/rust-lang/rust-clippy/pull/4842) -* Fix false positive in `while_immutable_condition` [#4730](https://github.com/rust-lang/rust-clippy/pull/4730) -* Fix false positive in `explicit_counter_loop` [#4803](https://github.com/rust-lang/rust-clippy/pull/4803) -* Fix false positive in `must_use_candidate` [#4794](https://github.com/rust-lang/rust-clippy/pull/4794) -* Fix false positive in `print_with_newline` and `write_with_newline` - [#4769](https://github.com/rust-lang/rust-clippy/pull/4769) -* Fix false positive in `derive_hash_xor_eq` [#4766](https://github.com/rust-lang/rust-clippy/pull/4766) -* Fix false positive in `missing_inline_in_public_items` [#4870](https://github.com/rust-lang/rust-clippy/pull/4870) -* Fix false positive in `string_add` [#4880](https://github.com/rust-lang/rust-clippy/pull/4880) -* Fix false positive in `float_arithmetic` [#4851](https://github.com/rust-lang/rust-clippy/pull/4851) -* Fix false positive in `cast_sign_loss` [#4883](https://github.com/rust-lang/rust-clippy/pull/4883) -* Fix false positive in `manual_swap` [#4877](https://github.com/rust-lang/rust-clippy/pull/4877) -* Fix ICEs occurring while checking some block expressions [#4772](https://github.com/rust-lang/rust-clippy/pull/4772) -* Fix ICE in `use_self` [#4776](https://github.com/rust-lang/rust-clippy/pull/4776) -* Fix ICEs related to `const_generics` [#4780](https://github.com/rust-lang/rust-clippy/pull/4780) -* Display help when running `clippy-driver` without arguments, instead of ICEing - [#4810](https://github.com/rust-lang/rust-clippy/pull/4810) -* Clippy has its own ICE message now [#4588](https://github.com/rust-lang/rust-clippy/pull/4588) -* Show deprecated lints in the documentation again [#4757](https://github.com/rust-lang/rust-clippy/pull/4757) -* Improve Documentation by adding positive examples to some lints - [#4832](https://github.com/rust-lang/rust-clippy/pull/4832) - -## Rust 1.40 - -Released 2019-12-19 - -[View all 76 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2019-09-23T06%3A18%3A04Z..2019-10-28T17%3A34%3A55Z+base%3Amaster) - -* New Lints: - * [`unneeded_wildcard_pattern`] [#4537](https://github.com/rust-lang/rust-clippy/pull/4537) - * [`needless_doctest_main`] [#4603](https://github.com/rust-lang/rust-clippy/pull/4603) - * [`suspicious_unary_op_formatting`] [#4615](https://github.com/rust-lang/rust-clippy/pull/4615) - * [`debug_assert_with_mut_call`] [#4680](https://github.com/rust-lang/rust-clippy/pull/4680) - * [`unused_self`] [#4619](https://github.com/rust-lang/rust-clippy/pull/4619) - * [`inefficient_to_string`] [#4683](https://github.com/rust-lang/rust-clippy/pull/4683) - * [`must_use_unit`] [#4560](https://github.com/rust-lang/rust-clippy/pull/4560) - * [`must_use_candidate`] [#4560](https://github.com/rust-lang/rust-clippy/pull/4560) - * [`double_must_use`] [#4560](https://github.com/rust-lang/rust-clippy/pull/4560) - * [`comparison_chain`] [#4569](https://github.com/rust-lang/rust-clippy/pull/4569) - * [`unsound_collection_transmute`] [#4592](https://github.com/rust-lang/rust-clippy/pull/4592) - * [`panic`] [#4657](https://github.com/rust-lang/rust-clippy/pull/4657) - * [`unreachable`] [#4657](https://github.com/rust-lang/rust-clippy/pull/4657) - * [`todo`] [#4657](https://github.com/rust-lang/rust-clippy/pull/4657) - * `option_expect_used` [#4657](https://github.com/rust-lang/rust-clippy/pull/4657) - * `result_expect_used` [#4657](https://github.com/rust-lang/rust-clippy/pull/4657) -* Move `redundant_clone` to perf group [#4509](https://github.com/rust-lang/rust-clippy/pull/4509) -* Move `manual_mul_add` to nursery group [#4736](https://github.com/rust-lang/rust-clippy/pull/4736) -* Expand `unit_cmp` to also work with `assert_eq!`, `debug_assert_eq!`, `assert_ne!` and `debug_assert_ne!` [#4613](https://github.com/rust-lang/rust-clippy/pull/4613) -* Expand `integer_arithmetic` to also detect mutating arithmetic like `+=` [#4585](https://github.com/rust-lang/rust-clippy/pull/4585) -* Fix false positive in `nonminimal_bool` [#4568](https://github.com/rust-lang/rust-clippy/pull/4568) -* Fix false positive in `missing_safety_doc` [#4611](https://github.com/rust-lang/rust-clippy/pull/4611) -* Fix false positive in `cast_sign_loss` [#4614](https://github.com/rust-lang/rust-clippy/pull/4614) -* Fix false positive in `redundant_clone` [#4509](https://github.com/rust-lang/rust-clippy/pull/4509) -* Fix false positive in `try_err` [#4721](https://github.com/rust-lang/rust-clippy/pull/4721) -* Fix false positive in `toplevel_ref_arg` [#4570](https://github.com/rust-lang/rust-clippy/pull/4570) -* Fix false positive in `multiple_inherent_impl` [#4593](https://github.com/rust-lang/rust-clippy/pull/4593) -* Improve more suggestions and tests in preparation for the unstable `cargo fix --clippy` [#4575](https://github.com/rust-lang/rust-clippy/pull/4575) -* Improve suggestion for `zero_ptr` [#4599](https://github.com/rust-lang/rust-clippy/pull/4599) -* Improve suggestion for `explicit_counter_loop` [#4691](https://github.com/rust-lang/rust-clippy/pull/4691) -* Improve suggestion for `mul_add` [#4602](https://github.com/rust-lang/rust-clippy/pull/4602) -* Improve suggestion for `assertions_on_constants` [#4635](https://github.com/rust-lang/rust-clippy/pull/4635) -* Fix ICE in `use_self` [#4671](https://github.com/rust-lang/rust-clippy/pull/4671) -* Fix ICE when encountering const casts [#4590](https://github.com/rust-lang/rust-clippy/pull/4590) - -## Rust 1.39 - -Released 2019-11-07 - -[View all 100 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2019-08-11T19%3A21%3A38Z..2019-09-22T12%3A07%3A39Z+base%3Amaster) - -* New Lints: - * [`uninit_assumed_init`] [#4479](https://github.com/rust-lang/rust-clippy/pull/4479) - * [`flat_map_identity`] [#4231](https://github.com/rust-lang/rust-clippy/pull/4231) - * [`missing_safety_doc`] [#4535](https://github.com/rust-lang/rust-clippy/pull/4535) - * [`mem_replace_with_uninit`] [#4511](https://github.com/rust-lang/rust-clippy/pull/4511) - * [`suspicious_map`] [#4394](https://github.com/rust-lang/rust-clippy/pull/4394) - * `option_and_then_some` [#4386](https://github.com/rust-lang/rust-clippy/pull/4386) - * [`manual_saturating_arithmetic`] [#4498](https://github.com/rust-lang/rust-clippy/pull/4498) -* Deprecate `unused_collect` lint. This is fully covered by rustc's `#[must_use]` on `collect` [#4348](https://github.com/rust-lang/rust-clippy/pull/4348) -* Move `type_repetition_in_bounds` to pedantic group [#4403](https://github.com/rust-lang/rust-clippy/pull/4403) -* Move `cast_lossless` to pedantic group [#4539](https://github.com/rust-lang/rust-clippy/pull/4539) -* `temporary_cstring_as_ptr` now catches more cases [#4425](https://github.com/rust-lang/rust-clippy/pull/4425) -* `use_self` now works in constructors, too [#4525](https://github.com/rust-lang/rust-clippy/pull/4525) -* `cargo_common_metadata` now checks for license files [#4518](https://github.com/rust-lang/rust-clippy/pull/4518) -* `cognitive_complexity` now includes the measured complexity in the warning message [#4469](https://github.com/rust-lang/rust-clippy/pull/4469) -* Fix false positives in `block_in_if_*` lints [#4458](https://github.com/rust-lang/rust-clippy/pull/4458) -* Fix false positive in `cast_lossless` [#4473](https://github.com/rust-lang/rust-clippy/pull/4473) -* Fix false positive in `clone_on_copy` [#4411](https://github.com/rust-lang/rust-clippy/pull/4411) -* Fix false positive in `deref_addrof` [#4487](https://github.com/rust-lang/rust-clippy/pull/4487) -* Fix false positive in `too_many_lines` [#4490](https://github.com/rust-lang/rust-clippy/pull/4490) -* Fix false positive in `new_ret_no_self` [#4365](https://github.com/rust-lang/rust-clippy/pull/4365) -* Fix false positive in `manual_swap` [#4478](https://github.com/rust-lang/rust-clippy/pull/4478) -* Fix false positive in `missing_const_for_fn` [#4450](https://github.com/rust-lang/rust-clippy/pull/4450) -* Fix false positive in `extra_unused_lifetimes` [#4477](https://github.com/rust-lang/rust-clippy/pull/4477) -* Fix false positive in `inherent_to_string` [#4460](https://github.com/rust-lang/rust-clippy/pull/4460) -* Fix false positive in `map_entry` [#4495](https://github.com/rust-lang/rust-clippy/pull/4495) -* Fix false positive in `unused_unit` [#4445](https://github.com/rust-lang/rust-clippy/pull/4445) -* Fix false positive in `redundant_pattern` [#4489](https://github.com/rust-lang/rust-clippy/pull/4489) -* Fix false positive in `wrong_self_convention` [#4369](https://github.com/rust-lang/rust-clippy/pull/4369) -* Improve various suggestions and tests in preparation for the unstable `cargo fix --clippy` [#4558](https://github.com/rust-lang/rust-clippy/pull/4558) -* Improve suggestions for `redundant_pattern_matching` [#4352](https://github.com/rust-lang/rust-clippy/pull/4352) -* Improve suggestions for `explicit_write` [#4544](https://github.com/rust-lang/rust-clippy/pull/4544) -* Improve suggestion for `or_fun_call` [#4522](https://github.com/rust-lang/rust-clippy/pull/4522) -* Improve suggestion for `match_as_ref` [#4446](https://github.com/rust-lang/rust-clippy/pull/4446) -* Improve suggestion for `unnecessary_fold_span` [#4382](https://github.com/rust-lang/rust-clippy/pull/4382) -* Add suggestions for `unseparated_literal_suffix` [#4401](https://github.com/rust-lang/rust-clippy/pull/4401) -* Add suggestions for `char_lit_as_u8` [#4418](https://github.com/rust-lang/rust-clippy/pull/4418) - -## Rust 1.38 - -Released 2019-09-26 - -[View all 76 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2019-06-30T13%3A40%3A26Z..2019-08-11T09%3A47%3A27Z+base%3Amaster) - -* New Lints: - * [`main_recursion`] [#4203](https://github.com/rust-lang/rust-clippy/pull/4203) - * [`inherent_to_string`] [#4259](https://github.com/rust-lang/rust-clippy/pull/4259) - * [`inherent_to_string_shadow_display`] [#4259](https://github.com/rust-lang/rust-clippy/pull/4259) - * [`type_repetition_in_bounds`] [#3766](https://github.com/rust-lang/rust-clippy/pull/3766) - * [`try_err`] [#4222](https://github.com/rust-lang/rust-clippy/pull/4222) -* Move `{unnecessary,panicking}_unwrap` out of nursery [#4307](https://github.com/rust-lang/rust-clippy/pull/4307) -* Extend the `use_self` lint to suggest uses of `Self::Variant` [#4308](https://github.com/rust-lang/rust-clippy/pull/4308) -* Improve suggestion for needless return [#4262](https://github.com/rust-lang/rust-clippy/pull/4262) -* Add auto-fixable suggestion for `let_unit` [#4337](https://github.com/rust-lang/rust-clippy/pull/4337) -* Fix false positive in `pub_enum_variant_names` and `enum_variant_names` [#4345](https://github.com/rust-lang/rust-clippy/pull/4345) -* Fix false positive in `cast_ptr_alignment` [#4257](https://github.com/rust-lang/rust-clippy/pull/4257) -* Fix false positive in `string_lit_as_bytes` [#4233](https://github.com/rust-lang/rust-clippy/pull/4233) -* Fix false positive in `needless_lifetimes` [#4266](https://github.com/rust-lang/rust-clippy/pull/4266) -* Fix false positive in `float_cmp` [#4275](https://github.com/rust-lang/rust-clippy/pull/4275) -* Fix false positives in `needless_return` [#4274](https://github.com/rust-lang/rust-clippy/pull/4274) -* Fix false negative in `match_same_arms` [#4246](https://github.com/rust-lang/rust-clippy/pull/4246) -* Fix incorrect suggestion for `needless_bool` [#4335](https://github.com/rust-lang/rust-clippy/pull/4335) -* Improve suggestion for `cast_ptr_alignment` [#4257](https://github.com/rust-lang/rust-clippy/pull/4257) -* Improve suggestion for `single_char_literal` [#4361](https://github.com/rust-lang/rust-clippy/pull/4361) -* Improve suggestion for `len_zero` [#4314](https://github.com/rust-lang/rust-clippy/pull/4314) -* Fix ICE in `implicit_hasher` [#4268](https://github.com/rust-lang/rust-clippy/pull/4268) -* Fix allow bug in `trivially_copy_pass_by_ref` [#4250](https://github.com/rust-lang/rust-clippy/pull/4250) - -## Rust 1.37 - -Released 2019-08-15 - -[View all 72 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2019-05-19T08%3A11%3A23Z..2019-06-25T23%3A22%3A22Z+base%3Amaster) - -* New Lints: - * [`checked_conversions`] [#4088](https://github.com/rust-lang/rust-clippy/pull/4088) - * [`get_last_with_len`] [#3832](https://github.com/rust-lang/rust-clippy/pull/3832) - * [`integer_division`] [#4195](https://github.com/rust-lang/rust-clippy/pull/4195) -* Renamed Lint: `const_static_lifetime` is now called [`redundant_static_lifetimes`]. - The lint now covers statics in addition to consts [#4162](https://github.com/rust-lang/rust-clippy/pull/4162) -* [`match_same_arms`] now warns for all identical arms, instead of only the first one [#4102](https://github.com/rust-lang/rust-clippy/pull/4102) -* [`needless_return`] now works with void functions [#4220](https://github.com/rust-lang/rust-clippy/pull/4220) -* Fix false positive in [`redundant_closure`] [#4190](https://github.com/rust-lang/rust-clippy/pull/4190) -* Fix false positive in [`useless_attribute`] [#4107](https://github.com/rust-lang/rust-clippy/pull/4107) -* Fix incorrect suggestion for [`float_cmp`] [#4214](https://github.com/rust-lang/rust-clippy/pull/4214) -* Add suggestions for [`print_with_newline`] and [`write_with_newline`] [#4136](https://github.com/rust-lang/rust-clippy/pull/4136) -* Improve suggestions for `option_map_unwrap_or_else` and `result_map_unwrap_or_else` [#4164](https://github.com/rust-lang/rust-clippy/pull/4164) -* Improve suggestions for [`non_ascii_literal`] [#4119](https://github.com/rust-lang/rust-clippy/pull/4119) -* Improve diagnostics for [`let_and_return`] [#4137](https://github.com/rust-lang/rust-clippy/pull/4137) -* Improve diagnostics for [`trivially_copy_pass_by_ref`] [#4071](https://github.com/rust-lang/rust-clippy/pull/4071) -* Add macro check for [`unreadable_literal`] [#4099](https://github.com/rust-lang/rust-clippy/pull/4099) - -## Rust 1.36 - -Released 2019-07-04 - -[View all 81 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2019-04-10T09%3A41%3A56Z..2019-05-18T00%3A29%3A40Z+base%3Amaster) - -* New lints: [`find_map`], [`filter_map_next`] [#4039](https://github.com/rust-lang/rust-clippy/pull/4039) -* New lint: [`path_buf_push_overwrite`] [#3954](https://github.com/rust-lang/rust-clippy/pull/3954) -* Move `path_buf_push_overwrite` to the nursery [#4013](https://github.com/rust-lang/rust-clippy/pull/4013) -* Split [`redundant_closure`] into [`redundant_closure`] and [`redundant_closure_for_method_calls`] [#4110](https://github.com/rust-lang/rust-clippy/pull/4101) -* Allow allowing of [`toplevel_ref_arg`] lint [#4007](https://github.com/rust-lang/rust-clippy/pull/4007) -* Fix false negative in [`or_fun_call`] pertaining to nested constructors [#4084](https://github.com/rust-lang/rust-clippy/pull/4084) -* Fix false positive in [`or_fun_call`] pertaining to enum variant constructors [#4018](https://github.com/rust-lang/rust-clippy/pull/4018) -* Fix false positive in [`useless_let_if_seq`] pertaining to interior mutability [#4035](https://github.com/rust-lang/rust-clippy/pull/4035) -* Fix false positive in [`redundant_closure`] pertaining to non-function types [#4008](https://github.com/rust-lang/rust-clippy/pull/4008) -* Fix false positive in [`let_and_return`] pertaining to attributes on `let`s [#4024](https://github.com/rust-lang/rust-clippy/pull/4024) -* Fix false positive in [`module_name_repetitions`] lint pertaining to attributes [#4006](https://github.com/rust-lang/rust-clippy/pull/4006) -* Fix false positive on [`assertions_on_constants`] pertaining to `debug_assert!` [#3989](https://github.com/rust-lang/rust-clippy/pull/3989) -* Improve suggestion in [`map_clone`] to suggest `.copied()` where applicable [#3970](https://github.com/rust-lang/rust-clippy/pull/3970) [#4043](https://github.com/rust-lang/rust-clippy/pull/4043) -* Improve suggestion for [`search_is_some`] [#4049](https://github.com/rust-lang/rust-clippy/pull/4049) -* Improve suggestion applicability for [`naive_bytecount`] [#3984](https://github.com/rust-lang/rust-clippy/pull/3984) -* Improve suggestion applicability for [`while_let_loop`] [#3975](https://github.com/rust-lang/rust-clippy/pull/3975) -* Improve diagnostics for [`too_many_arguments`] [#4053](https://github.com/rust-lang/rust-clippy/pull/4053) -* Improve diagnostics for [`cast_lossless`] [#4021](https://github.com/rust-lang/rust-clippy/pull/4021) -* Deal with macro checks in desugarings better [#4082](https://github.com/rust-lang/rust-clippy/pull/4082) -* Add macro check for [`unnecessary_cast`] [#4026](https://github.com/rust-lang/rust-clippy/pull/4026) -* Remove [`approx_constant`]'s documentation's "Known problems" section. [#4027](https://github.com/rust-lang/rust-clippy/pull/4027) -* Fix ICE in [`suspicious_else_formatting`] [#3960](https://github.com/rust-lang/rust-clippy/pull/3960) -* Fix ICE in [`decimal_literal_representation`] [#3931](https://github.com/rust-lang/rust-clippy/pull/3931) - - -## Rust 1.35 - -Released 2019-05-20 - -[1fac380..37f5c1e](https://github.com/rust-lang/rust-clippy/compare/1fac380...37f5c1e) - -* New lint: `drop_bounds` to detect `T: Drop` bounds -* Split [`redundant_closure`] into [`redundant_closure`] and [`redundant_closure_for_method_calls`] [#4110](https://github.com/rust-lang/rust-clippy/pull/4101) -* Rename `cyclomatic_complexity` to [`cognitive_complexity`], start work on making lint more practical for Rust code -* Move [`get_unwrap`] to the restriction category -* Improve suggestions for [`iter_cloned_collect`] -* Improve suggestions for [`cast_lossless`] to suggest suffixed literals -* Fix false positives in [`print_with_newline`] and [`write_with_newline`] pertaining to raw strings -* Fix false positive in [`needless_range_loop`] pertaining to structs without a `.iter()` -* Fix false positive in [`bool_comparison`] pertaining to non-bool types -* Fix false positive in [`redundant_closure`] pertaining to differences in borrows -* Fix false positive in `option_map_unwrap_or` on non-copy types -* Fix false positives in [`missing_const_for_fn`] pertaining to macros and trait method impls -* Fix false positive in [`needless_pass_by_value`] pertaining to procedural macros -* Fix false positive in [`needless_continue`] pertaining to loop labels -* Fix false positive for [`boxed_local`] pertaining to arguments moved into closures -* Fix false positive for [`use_self`] in nested functions -* Fix suggestion for [`expect_fun_call`] (https://github.com/rust-lang/rust-clippy/pull/3846) -* Fix suggestion for [`explicit_counter_loop`] to deal with parenthesizing range variables -* Fix suggestion for [`single_char_pattern`] to correctly escape single quotes -* Avoid triggering [`redundant_closure`] in macros -* ICE fixes: [#3805](https://github.com/rust-lang/rust-clippy/pull/3805), [#3772](https://github.com/rust-lang/rust-clippy/pull/3772), [#3741](https://github.com/rust-lang/rust-clippy/pull/3741) - -## Rust 1.34 - -Released 2019-04-10 - -[View all 61 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2019-01-17T17%3A45%3A39Z..2019-02-19T08%3A24%3A05Z+base%3Amaster) - -* New lint: [`assertions_on_constants`] to detect for example `assert!(true)` -* New lint: [`dbg_macro`] to detect uses of the `dbg!` macro -* New lint: [`missing_const_for_fn`] that can suggest functions to be made `const` -* New lint: [`too_many_lines`] to detect functions with excessive LOC. It can be - configured using the `too-many-lines-threshold` configuration. -* New lint: [`wildcard_enum_match_arm`] to check for wildcard enum matches using `_` -* Expand `redundant_closure` to also work for methods (not only functions) -* Fix ICEs in `vec_box`, `needless_pass_by_value` and `implicit_hasher` -* Fix false positive in `cast_sign_loss` -* Fix false positive in `integer_arithmetic` -* Fix false positive in `unit_arg` -* Fix false positives in `implicit_return` -* Add suggestion to `explicit_write` -* Improve suggestions for `question_mark` lint -* Fix incorrect suggestion for `cast_lossless` -* Fix incorrect suggestion for `expect_fun_call` -* Fix incorrect suggestion for `needless_bool` -* Fix incorrect suggestion for `needless_range_loop` -* Fix incorrect suggestion for `use_self` -* Fix incorrect suggestion for `while_let_on_iterator` -* Clippy is now slightly easier to invoke in non-cargo contexts. See - [#3665][pull3665] for more details. -* We now have [improved documentation][adding_lints] on how to add new lints - -## Rust 1.33 - -Released 2019-02-26 - -[View all 120 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2018-11-28T06%3A19%3A50Z..2019-01-15T09%3A27%3A02Z+base%3Amaster) - -* New lints: [`implicit_return`], [`vec_box`], [`cast_ref_to_mut`] -* The `rust-clippy` repository is now part of the `rust-lang` org. -* Rename `stutter` to `module_name_repetitions` -* Merge `new_without_default_derive` into `new_without_default` lint -* Move `large_digit_groups` from `style` group to `pedantic` -* Expand `bool_comparison` to check for `<`, `<=`, `>`, `>=`, and `!=` - comparisons against booleans -* Expand `no_effect` to detect writes to constants such as `A_CONST.field = 2` -* Expand `redundant_clone` to work on struct fields -* Expand `suspicious_else_formatting` to detect `if .. {..} {..}` -* Expand `use_self` to work on tuple structs and also in local macros -* Fix ICE in `result_map_unit_fn` and `option_map_unit_fn` -* Fix false positives in `implicit_return` -* Fix false positives in `use_self` -* Fix false negative in `clone_on_copy` -* Fix false positive in `doc_markdown` -* Fix false positive in `empty_loop` -* Fix false positive in `if_same_then_else` -* Fix false positive in `infinite_iter` -* Fix false positive in `question_mark` -* Fix false positive in `useless_asref` -* Fix false positive in `wildcard_dependencies` -* Fix false positive in `write_with_newline` -* Add suggestion to `explicit_write` -* Improve suggestions for `question_mark` lint -* Fix incorrect suggestion for `get_unwrap` - -## Rust 1.32 - -Released 2019-01-17 - -[View all 71 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2018-10-24T05%3A02%3A21Z..2018-11-27T17%3A29%3A34Z+base%3Amaster) - -* New lints: [`slow_vector_initialization`], `mem_discriminant_non_enum`, - [`redundant_clone`], [`wildcard_dependencies`], - [`into_iter_on_ref`], `into_iter_on_array`, [`deprecated_cfg_attr`], - [`cargo_common_metadata`] -* Add support for `u128` and `i128` to integer related lints -* Add float support to `mistyped_literal_suffixes` -* Fix false positives in `use_self` -* Fix false positives in `missing_comma` -* Fix false positives in `new_ret_no_self` -* Fix false positives in `possible_missing_comma` -* Fix false positive in `integer_arithmetic` in constant items -* Fix false positive in `needless_borrow` -* Fix false positive in `out_of_bounds_indexing` -* Fix false positive in `new_without_default_derive` -* Fix false positive in `string_lit_as_bytes` -* Fix false negative in `out_of_bounds_indexing` -* Fix false negative in `use_self`. It will now also check existential types -* Fix incorrect suggestion for `redundant_closure_call` -* Fix various suggestions that contained expanded macros -* Fix `bool_comparison` triggering 3 times on on on the same code -* Expand `trivially_copy_pass_by_ref` to work on trait methods -* Improve suggestion for `needless_range_loop` -* Move `needless_pass_by_value` from `pedantic` group to `style` - -## Rust 1.31 - -Released 2018-12-06 - -[125907ad..2e26fdc2](https://github.com/rust-lang/rust-clippy/compare/125907ad..2e26fdc2) - -* Clippy has been relicensed under a dual MIT / Apache license. - See [#3093](https://github.com/rust-lang/rust-clippy/issues/3093) for more - information. -* With Rust 1.31, Clippy is no longer available via crates.io. The recommended - installation method is via `rustup component add clippy`. -* New lints: [`redundant_pattern_matching`], [`unnecessary_filter_map`], - [`unused_unit`], [`map_flatten`], [`mem_replace_option_with_none`] -* Fix ICE in `if_let_redundant_pattern_matching` -* Fix ICE in `needless_pass_by_value` when encountering a generic function - argument with a lifetime parameter -* Fix ICE in `needless_range_loop` -* Fix ICE in `single_char_pattern` when encountering a constant value -* Fix false positive in `assign_op_pattern` -* Fix false positive in `boxed_local` on trait implementations -* Fix false positive in `cmp_owned` -* Fix false positive in `collapsible_if` when conditionals have comments -* Fix false positive in `double_parens` -* Fix false positive in `excessive_precision` -* Fix false positive in `explicit_counter_loop` -* Fix false positive in `fn_to_numeric_cast_with_truncation` -* Fix false positive in `map_clone` -* Fix false positive in `new_ret_no_self` -* Fix false positive in `new_without_default` when `new` is unsafe -* Fix false positive in `type_complexity` when using extern types -* Fix false positive in `useless_format` -* Fix false positive in `wrong_self_convention` -* Fix incorrect suggestion for `excessive_precision` -* Fix incorrect suggestion for `expect_fun_call` -* Fix incorrect suggestion for `get_unwrap` -* Fix incorrect suggestion for `useless_format` -* `fn_to_numeric_cast_with_truncation` lint can be disabled again -* Improve suggestions for `manual_memcpy` -* Improve help message for `needless_lifetimes` - -## Rust 1.30 - -Released 2018-10-25 - -[View all 88 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2018-08-02T16%3A54%3A12Z..2018-09-17T09%3A44%3A06Z+base%3Amaster) -* Deprecate `assign_ops` lint -* New lints: [`mistyped_literal_suffixes`], [`ptr_offset_with_cast`], - [`needless_collect`], [`copy_iterator`] -* `cargo clippy -V` now includes the Clippy commit hash of the Rust - Clippy component -* Fix ICE in `implicit_hasher` -* Fix ICE when encountering `println!("{}" a);` -* Fix ICE when encountering a macro call in match statements -* Fix false positive in `default_trait_access` -* Fix false positive in `trivially_copy_pass_by_ref` -* Fix false positive in `similar_names` -* Fix false positive in `redundant_field_name` -* Fix false positive in `expect_fun_call` -* Fix false negative in `identity_conversion` -* Fix false negative in `explicit_counter_loop` -* Fix `range_plus_one` suggestion and false negative -* `print_with_newline` / `write_with_newline`: don't warn about string with several `\n`s in them -* Fix `useless_attribute` to also whitelist `unused_extern_crates` -* Fix incorrect suggestion for `single_char_pattern` -* Improve suggestion for `identity_conversion` lint -* Move `explicit_iter_loop` and `explicit_into_iter_loop` from `style` group to `pedantic` -* Move `range_plus_one` and `range_minus_one` from `nursery` group to `complexity` -* Move `shadow_unrelated` from `restriction` group to `pedantic` -* Move `indexing_slicing` from `pedantic` group to `restriction` - -## Rust 1.29 - -Released 2018-09-13 - -[v0.0.212...14207503](https://github.com/rust-lang/rust-clippy/compare/v0.0.212...14207503) - -* :tada: :tada: **Rust 1.29 is the first stable Rust that includes a bundled Clippy** :tada: - :tada: - You can now run `rustup component add clippy-preview` and then `cargo - clippy` to run Clippy. This should put an end to the continuous nightly - upgrades for Clippy users. -* Clippy now follows the Rust versioning scheme instead of its own -* Fix ICE when encountering a `while let (..) = x.iter()` construct -* Fix false positives in `use_self` -* Fix false positive in `trivially_copy_pass_by_ref` -* Fix false positive in `useless_attribute` lint -* Fix false positive in `print_literal` -* Fix `use_self` regressions -* Improve lint message for `neg_cmp_op_on_partial_ord` -* Improve suggestion highlight for `single_char_pattern` -* Improve suggestions for various print/write macro lints -* Improve website header - -## 0.0.212 (2018-07-10) -* Rustup to *rustc 1.29.0-nightly (e06c87544 2018-07-06)* - -## 0.0.211 -* Rustup to *rustc 1.28.0-nightly (e3bf634e0 2018-06-28)* - -## 0.0.210 -* Rustup to *rustc 1.28.0-nightly (01cc982e9 2018-06-24)* - -## 0.0.209 -* Rustup to *rustc 1.28.0-nightly (523097979 2018-06-18)* - -## 0.0.208 -* Rustup to *rustc 1.28.0-nightly (86a8f1a63 2018-06-17)* - -## 0.0.207 -* Rustup to *rustc 1.28.0-nightly (2a0062974 2018-06-09)* - -## 0.0.206 -* Rustup to *rustc 1.28.0-nightly (5bf68db6e 2018-05-28)* - -## 0.0.205 -* Rustup to *rustc 1.28.0-nightly (990d8aa74 2018-05-25)* -* Rename `unused_lifetimes` to `extra_unused_lifetimes` because of naming conflict with new rustc lint - -## 0.0.204 -* Rustup to *rustc 1.28.0-nightly (71e87be38 2018-05-22)* - -## 0.0.203 -* Rustup to *rustc 1.28.0-nightly (a3085756e 2018-05-19)* -* Clippy attributes are now of the form `clippy::cyclomatic_complexity` instead of `clippy(cyclomatic_complexity)` - -## 0.0.202 -* Rustup to *rustc 1.28.0-nightly (952f344cd 2018-05-18)* - -## 0.0.201 -* Rustup to *rustc 1.27.0-nightly (2f2a11dfc 2018-05-16)* - -## 0.0.200 -* Rustup to *rustc 1.27.0-nightly (9fae15374 2018-05-13)* - -## 0.0.199 -* Rustup to *rustc 1.27.0-nightly (ff2ac35db 2018-05-12)* - -## 0.0.198 -* Rustup to *rustc 1.27.0-nightly (acd3871ba 2018-05-10)* - -## 0.0.197 -* Rustup to *rustc 1.27.0-nightly (428ea5f6b 2018-05-06)* - -## 0.0.196 -* Rustup to *rustc 1.27.0-nightly (e82261dfb 2018-05-03)* - -## 0.0.195 -* Rustup to *rustc 1.27.0-nightly (ac3c2288f 2018-04-18)* - -## 0.0.194 -* Rustup to *rustc 1.27.0-nightly (bd40cbbe1 2018-04-14)* -* New lints: [`cast_ptr_alignment`], [`transmute_ptr_to_ptr`], [`write_literal`], [`write_with_newline`], [`writeln_empty_string`] - -## 0.0.193 -* Rustup to *rustc 1.27.0-nightly (eeea94c11 2018-04-06)* - -## 0.0.192 -* Rustup to *rustc 1.27.0-nightly (fb44b4c0e 2018-04-04)* -* New lint: [`print_literal`] - -## 0.0.191 -* Rustup to *rustc 1.26.0-nightly (ae544ee1c 2018-03-29)* -* Lint audit; categorize lints as style, correctness, complexity, pedantic, nursery, restriction. - -## 0.0.190 -* Fix a bunch of intermittent cargo bugs - -## 0.0.189 -* Rustup to *rustc 1.26.0-nightly (5508b2714 2018-03-18)* - -## 0.0.188 -* Rustup to *rustc 1.26.0-nightly (392645394 2018-03-15)* -* New lint: [`while_immutable_condition`] - -## 0.0.187 -* Rustup to *rustc 1.26.0-nightly (322d7f7b9 2018-02-25)* -* New lints: [`redundant_field_names`], [`suspicious_arithmetic_impl`], [`suspicious_op_assign_impl`] - -## 0.0.186 -* Rustup to *rustc 1.25.0-nightly (0c6091fbd 2018-02-04)* -* Various false positive fixes - -## 0.0.185 -* Rustup to *rustc 1.25.0-nightly (56733bc9f 2018-02-01)* -* New lint: [`question_mark`] - -## 0.0.184 -* Rustup to *rustc 1.25.0-nightly (90eb44a58 2018-01-29)* -* New lints: [`double_comparisons`], [`empty_line_after_outer_attr`] - -## 0.0.183 -* Rustup to *rustc 1.25.0-nightly (21882aad7 2018-01-28)* -* New lint: [`misaligned_transmute`] - -## 0.0.182 -* Rustup to *rustc 1.25.0-nightly (a0dcecff9 2018-01-24)* -* New lint: [`decimal_literal_representation`] - -## 0.0.181 -* Rustup to *rustc 1.25.0-nightly (97520ccb1 2018-01-21)* -* New lints: [`else_if_without_else`], [`option_option`], [`unit_arg`], [`unnecessary_fold`] -* Removed `unit_expr` -* Various false positive fixes for [`needless_pass_by_value`] - -## 0.0.180 -* Rustup to *rustc 1.25.0-nightly (3f92e8d89 2018-01-14)* - -## 0.0.179 -* Rustup to *rustc 1.25.0-nightly (61452e506 2018-01-09)* - -## 0.0.178 -* Rustup to *rustc 1.25.0-nightly (ee220daca 2018-01-07)* - -## 0.0.177 -* Rustup to *rustc 1.24.0-nightly (250b49205 2017-12-21)* -* New lint: [`match_as_ref`] - -## 0.0.176 -* Rustup to *rustc 1.24.0-nightly (0077d128d 2017-12-14)* - -## 0.0.175 -* Rustup to *rustc 1.24.0-nightly (bb42071f6 2017-12-01)* - -## 0.0.174 -* Rustup to *rustc 1.23.0-nightly (63739ab7b 2017-11-21)* - -## 0.0.173 -* Rustup to *rustc 1.23.0-nightly (33374fa9d 2017-11-20)* - -## 0.0.172 -* Rustup to *rustc 1.23.0-nightly (d0f8e2913 2017-11-16)* - -## 0.0.171 -* Rustup to *rustc 1.23.0-nightly (ff0f5de3b 2017-11-14)* - -## 0.0.170 -* Rustup to *rustc 1.23.0-nightly (d6b06c63a 2017-11-09)* - -## 0.0.169 -* Rustup to *rustc 1.23.0-nightly (3b82e4c74 2017-11-05)* -* New lints: [`just_underscores_and_digits`], `result_map_unwrap_or_else`, [`transmute_bytes_to_str`] - -## 0.0.168 -* Rustup to *rustc 1.23.0-nightly (f0fe716db 2017-10-30)* - -## 0.0.167 -* Rustup to *rustc 1.23.0-nightly (90ef3372e 2017-10-29)* -* New lints: `const_static_lifetime`, [`erasing_op`], [`fallible_impl_from`], [`println_empty_string`], [`useless_asref`] - -## 0.0.166 -* Rustup to *rustc 1.22.0-nightly (b7960878b 2017-10-18)* -* New lints: [`explicit_write`], `identity_conversion`, [`implicit_hasher`], `invalid_ref`, [`option_map_or_none`], - [`range_minus_one`], [`range_plus_one`], [`transmute_int_to_bool`], [`transmute_int_to_char`], - [`transmute_int_to_float`] - -## 0.0.165 -* Rust upgrade to rustc 1.22.0-nightly (0e6f4cf51 2017-09-27) -* New lint: [`mut_range_bound`] - -## 0.0.164 -* Update to *rustc 1.22.0-nightly (6c476ce46 2017-09-25)* -* New lint: [`int_plus_one`] - -## 0.0.163 -* Update to *rustc 1.22.0-nightly (14039a42a 2017-09-22)* - -## 0.0.162 -* Update to *rustc 1.22.0-nightly (0701b37d9 2017-09-18)* -* New lint: [`chars_last_cmp`] -* Improved suggestions for [`needless_borrow`], [`ptr_arg`], - -## 0.0.161 -* Update to *rustc 1.22.0-nightly (539f2083d 2017-09-13)* - -## 0.0.160 -* Update to *rustc 1.22.0-nightly (dd08c3070 2017-09-12)* - -## 0.0.159 -* Update to *rustc 1.22.0-nightly (eba374fb2 2017-09-11)* -* New lint: [`clone_on_ref_ptr`] - -## 0.0.158 -* New lint: [`manual_memcpy`] -* [`cast_lossless`] no longer has redundant parentheses in its suggestions -* Update to *rustc 1.22.0-nightly (dead08cb3 2017-09-08)* - -## 0.0.157 - 2017-09-04 -* Update to *rustc 1.22.0-nightly (981ce7d8d 2017-09-03)* -* New lint: `unit_expr` - -## 0.0.156 - 2017-09-03 -* Update to *rustc 1.22.0-nightly (744dd6c1d 2017-09-02)* - -## 0.0.155 -* Update to *rustc 1.21.0-nightly (c11f689d2 2017-08-29)* -* New lint: [`infinite_iter`], [`maybe_infinite_iter`], [`cast_lossless`] - -## 0.0.154 -* Update to *rustc 1.21.0-nightly (2c0558f63 2017-08-24)* -* Fix [`use_self`] triggering inside derives -* Add support for linting an entire workspace with `cargo clippy --all` -* New lint: [`naive_bytecount`] - -## 0.0.153 -* Update to *rustc 1.21.0-nightly (8c303ed87 2017-08-20)* -* New lint: [`use_self`] - -## 0.0.152 -* Update to *rustc 1.21.0-nightly (df511d554 2017-08-14)* - -## 0.0.151 -* Update to *rustc 1.21.0-nightly (13d94d5fa 2017-08-10)* - -## 0.0.150 -* Update to *rustc 1.21.0-nightly (215e0b10e 2017-08-08)* - -## 0.0.148 -* Update to *rustc 1.21.0-nightly (37c7d0ebb 2017-07-31)* -* New lints: [`unreadable_literal`], [`inconsistent_digit_grouping`], [`large_digit_groups`] - -## 0.0.147 -* Update to *rustc 1.21.0-nightly (aac223f4f 2017-07-30)* - -## 0.0.146 -* Update to *rustc 1.21.0-nightly (52a330969 2017-07-27)* -* Fixes false positives in `inline_always` -* Fixes false negatives in `panic_params` - -## 0.0.145 -* Update to *rustc 1.20.0-nightly (afe145d22 2017-07-23)* - -## 0.0.144 -* Update to *rustc 1.20.0-nightly (086eaa78e 2017-07-15)* - -## 0.0.143 -* Update to *rustc 1.20.0-nightly (d84693b93 2017-07-09)* -* Fix `cargo clippy` crashing on `dylib` projects -* Fix false positives around `nested_while_let` and `never_loop` - -## 0.0.142 -* Update to *rustc 1.20.0-nightly (067971139 2017-07-02)* - -## 0.0.141 -* Rewrite of the `doc_markdown` lint. -* Deprecated [`range_step_by_zero`] -* New lint: [`iterator_step_by_zero`] -* New lint: [`needless_borrowed_reference`] -* Update to *rustc 1.20.0-nightly (69c65d296 2017-06-28)* - -## 0.0.140 - 2017-06-16 -* Update to *rustc 1.19.0-nightly (258ae6dd9 2017-06-15)* - -## 0.0.139 — 2017-06-10 -* Update to *rustc 1.19.0-nightly (4bf5c99af 2017-06-10)* -* Fix bugs with for loop desugaring -* Check for [`AsRef`]/[`AsMut`] arguments in [`wrong_self_convention`] - -## 0.0.138 — 2017-06-05 -* Update to *rustc 1.19.0-nightly (0418fa9d3 2017-06-04)* - -## 0.0.137 — 2017-06-05 -* Update to *rustc 1.19.0-nightly (6684d176c 2017-06-03)* - -## 0.0.136 — 2017—05—26 -* Update to *rustc 1.19.0-nightly (557967766 2017-05-26)* - -## 0.0.135 — 2017—05—24 -* Update to *rustc 1.19.0-nightly (5b13bff52 2017-05-23)* - -## 0.0.134 — 2017—05—19 -* Update to *rustc 1.19.0-nightly (0ed1ec9f9 2017-05-18)* - -## 0.0.133 — 2017—05—14 -* Update to *rustc 1.19.0-nightly (826d8f385 2017-05-13)* - -## 0.0.132 — 2017—05—05 -* Fix various bugs and some ices - -## 0.0.131 — 2017—05—04 -* Update to *rustc 1.19.0-nightly (2d4ed8e0c 2017-05-03)* - -## 0.0.130 — 2017—05—03 -* Update to *rustc 1.19.0-nightly (6a5fc9eec 2017-05-02)* - -## 0.0.129 — 2017-05-01 -* Update to *rustc 1.19.0-nightly (06fb4d256 2017-04-30)* - -## 0.0.128 — 2017-04-28 -* Update to *rustc 1.18.0-nightly (94e884b63 2017-04-27)* - -## 0.0.127 — 2017-04-27 -* Update to *rustc 1.18.0-nightly (036983201 2017-04-26)* -* New lint: [`needless_continue`] - -## 0.0.126 — 2017-04-24 -* Update to *rustc 1.18.0-nightly (2bd4b5c6d 2017-04-23)* - -## 0.0.125 — 2017-04-19 -* Update to *rustc 1.18.0-nightly (9f2abadca 2017-04-18)* - -## 0.0.124 — 2017-04-16 -* Update to *rustc 1.18.0-nightly (d5cf1cb64 2017-04-15)* - -## 0.0.123 — 2017-04-07 -* Fix various false positives - -## 0.0.122 — 2017-04-07 -* Rustup to *rustc 1.18.0-nightly (91ae22a01 2017-04-05)* -* New lint: [`op_ref`] - -## 0.0.121 — 2017-03-21 -* Rustup to *rustc 1.17.0-nightly (134c4a0f0 2017-03-20)* - -## 0.0.120 — 2017-03-17 -* Rustup to *rustc 1.17.0-nightly (0aeb9c129 2017-03-15)* - -## 0.0.119 — 2017-03-13 -* Rustup to *rustc 1.17.0-nightly (824c9ebbd 2017-03-12)* - -## 0.0.118 — 2017-03-05 -* Rustup to *rustc 1.17.0-nightly (b1e31766d 2017-03-03)* - -## 0.0.117 — 2017-03-01 -* Rustup to *rustc 1.17.0-nightly (be760566c 2017-02-28)* - -## 0.0.116 — 2017-02-28 -* Fix `cargo clippy` on 64 bit windows systems - -## 0.0.115 — 2017-02-27 -* Rustup to *rustc 1.17.0-nightly (60a0edc6c 2017-02-26)* -* New lints: [`zero_ptr`], [`never_loop`], [`mut_from_ref`] - -## 0.0.114 — 2017-02-08 -* Rustup to *rustc 1.17.0-nightly (c49d10207 2017-02-07)* -* Tests are now ui tests (testing the exact output of rustc) - -## 0.0.113 — 2017-02-04 -* Rustup to *rustc 1.16.0-nightly (eedaa94e3 2017-02-02)* -* New lint: [`large_enum_variant`] -* `explicit_into_iter_loop` provides suggestions - -## 0.0.112 — 2017-01-27 -* Rustup to *rustc 1.16.0-nightly (df8debf6d 2017-01-25)* - -## 0.0.111 — 2017-01-21 -* Rustup to *rustc 1.16.0-nightly (a52da95ce 2017-01-20)* - -## 0.0.110 — 2017-01-20 -* Add badges and categories to `Cargo.toml` - -## 0.0.109 — 2017-01-19 -* Update to *rustc 1.16.0-nightly (c07a6ae77 2017-01-17)* - -## 0.0.108 — 2017-01-12 -* Update to *rustc 1.16.0-nightly (2782e8f8f 2017-01-12)* - -## 0.0.107 — 2017-01-11 -* Update regex dependency -* Fix FP when matching `&&mut` by `&ref` -* Reintroduce `for (_, x) in &mut hash_map` -> `for x in hash_map.values_mut()` -* New lints: [`unused_io_amount`], [`forget_ref`], [`short_circuit_statement`] - -## 0.0.106 — 2017-01-04 -* Fix FP introduced by rustup in [`wrong_self_convention`] - -## 0.0.105 — 2017-01-04 -* Update to *rustc 1.16.0-nightly (468227129 2017-01-03)* -* New lints: [`deref_addrof`], [`double_parens`], [`pub_enum_variant_names`] -* Fix suggestion in [`new_without_default`] -* FP fix in [`absurd_extreme_comparisons`] - -## 0.0.104 — 2016-12-15 -* Update to *rustc 1.15.0-nightly (8f02c429a 2016-12-15)* - -## 0.0.103 — 2016-11-25 -* Update to *rustc 1.15.0-nightly (d5814b03e 2016-11-23)* - -## 0.0.102 — 2016-11-24 -* Update to *rustc 1.15.0-nightly (3bf2be9ce 2016-11-22)* - -## 0.0.101 — 2016-11-23 -* Update to *rustc 1.15.0-nightly (7b3eeea22 2016-11-21)* -* New lint: [`string_extend_chars`] - -## 0.0.100 — 2016-11-20 -* Update to *rustc 1.15.0-nightly (ac635aa95 2016-11-18)* - -## 0.0.99 — 2016-11-18 -* Update to rustc 1.15.0-nightly (0ed951993 2016-11-14) -* New lint: [`get_unwrap`] - -## 0.0.98 — 2016-11-08 -* Fixes an issue due to a change in how cargo handles `--sysroot`, which broke `cargo clippy` - -## 0.0.97 — 2016-11-03 -* For convenience, `cargo clippy` defines a `cargo-clippy` feature. This was - previously added for a short time under the name `clippy` but removed for - compatibility. -* `cargo clippy --help` is more helping (and less helpful :smile:) -* Rustup to *rustc 1.14.0-nightly (5665bdf3e 2016-11-02)* -* New lints: [`if_let_redundant_pattern_matching`], [`partialeq_ne_impl`] - -## 0.0.96 — 2016-10-22 -* Rustup to *rustc 1.14.0-nightly (f09420685 2016-10-20)* -* New lint: [`iter_skip_next`] - -## 0.0.95 — 2016-10-06 -* Rustup to *rustc 1.14.0-nightly (3210fd5c2 2016-10-05)* - -## 0.0.94 — 2016-10-04 -* Fixes bustage on Windows due to forbidden directory name - -## 0.0.93 — 2016-10-03 -* Rustup to *rustc 1.14.0-nightly (144af3e97 2016-10-02)* -* `option_map_unwrap_or` and `option_map_unwrap_or_else` are now - allowed by default. -* New lint: [`explicit_into_iter_loop`] - -## 0.0.92 — 2016-09-30 -* Rustup to *rustc 1.14.0-nightly (289f3a4ca 2016-09-29)* - -## 0.0.91 — 2016-09-28 -* Rustup to *rustc 1.13.0-nightly (d0623cf7b 2016-09-26)* - -## 0.0.90 — 2016-09-09 -* Rustup to *rustc 1.13.0-nightly (f1f40f850 2016-09-09)* - -## 0.0.89 — 2016-09-06 -* Rustup to *rustc 1.13.0-nightly (cbe4de78e 2016-09-05)* - -## 0.0.88 — 2016-09-04 -* Rustup to *rustc 1.13.0-nightly (70598e04f 2016-09-03)* -* The following lints are not new but were only usable through the `clippy` - lint groups: [`filter_next`], `for_loop_over_option`, - `for_loop_over_result` and [`match_overlapping_arm`]. You should now be - able to `#[allow/deny]` them individually and they are available directly - through `cargo clippy`. - -## 0.0.87 — 2016-08-31 -* Rustup to *rustc 1.13.0-nightly (eac41469d 2016-08-30)* -* New lints: [`builtin_type_shadow`] -* Fix FP in [`zero_prefixed_literal`] and `0b`/`0o` - -## 0.0.86 — 2016-08-28 -* Rustup to *rustc 1.13.0-nightly (a23064af5 2016-08-27)* -* New lints: [`missing_docs_in_private_items`], [`zero_prefixed_literal`] - -## 0.0.85 — 2016-08-19 -* Fix ICE with [`useless_attribute`] -* [`useless_attribute`] ignores `unused_imports` on `use` statements - -## 0.0.84 — 2016-08-18 -* Rustup to *rustc 1.13.0-nightly (aef6971ca 2016-08-17)* - -## 0.0.83 — 2016-08-17 -* Rustup to *rustc 1.12.0-nightly (1bf5fa326 2016-08-16)* -* New lints: [`print_with_newline`], [`useless_attribute`] - -## 0.0.82 — 2016-08-17 -* Rustup to *rustc 1.12.0-nightly (197be89f3 2016-08-15)* -* New lint: [`module_inception`] - -## 0.0.81 — 2016-08-14 -* Rustup to *rustc 1.12.0-nightly (1deb02ea6 2016-08-12)* -* New lints: [`eval_order_dependence`], [`mixed_case_hex_literals`], [`unseparated_literal_suffix`] -* False positive fix in [`too_many_arguments`] -* Addition of functionality to [`needless_borrow`] -* Suggestions for [`clone_on_copy`] -* Bug fix in [`wrong_self_convention`] -* Doc improvements - -## 0.0.80 — 2016-07-31 -* Rustup to *rustc 1.12.0-nightly (1225e122f 2016-07-30)* -* New lints: [`misrefactored_assign_op`], [`serde_api_misuse`] - -## 0.0.79 — 2016-07-10 -* Rustup to *rustc 1.12.0-nightly (f93aaf84c 2016-07-09)* -* Major suggestions refactoring - -## 0.0.78 — 2016-07-02 -* Rustup to *rustc 1.11.0-nightly (01411937f 2016-07-01)* -* New lints: [`wrong_transmute`], [`double_neg`], [`filter_map`] -* For compatibility, `cargo clippy` does not defines the `clippy` feature - introduced in 0.0.76 anymore -* [`collapsible_if`] now considers `if let` - -## 0.0.77 — 2016-06-21 -* Rustup to *rustc 1.11.0-nightly (5522e678b 2016-06-20)* -* New lints: `stutter` and [`iter_nth`] - -## 0.0.76 — 2016-06-10 -* Rustup to *rustc 1.11.0-nightly (7d2f75a95 2016-06-09)* -* `cargo clippy` now automatically defines the `clippy` feature -* New lint: [`not_unsafe_ptr_arg_deref`] - -## 0.0.75 — 2016-06-08 -* Rustup to *rustc 1.11.0-nightly (763f9234b 2016-06-06)* - -## 0.0.74 — 2016-06-07 -* Fix bug with `cargo-clippy` JSON parsing -* Add the `CLIPPY_DISABLE_DOCS_LINKS` environment variable to deactivate the - “for further information visit *lint-link*” message. - -## 0.0.73 — 2016-06-05 -* Fix false positives in [`useless_let_if_seq`] - -## 0.0.72 — 2016-06-04 -* Fix false positives in [`useless_let_if_seq`] - -## 0.0.71 — 2016-05-31 -* Rustup to *rustc 1.11.0-nightly (a967611d8 2016-05-30)* -* New lint: [`useless_let_if_seq`] - -## 0.0.70 — 2016-05-28 -* Rustup to *rustc 1.10.0-nightly (7bddce693 2016-05-27)* -* [`invalid_regex`] and [`trivial_regex`] can now warn on `RegexSet::new`, - `RegexBuilder::new` and byte regexes - -## 0.0.69 — 2016-05-20 -* Rustup to *rustc 1.10.0-nightly (476fe6eef 2016-05-21)* -* [`used_underscore_binding`] has been made `Allow` temporarily - -## 0.0.68 — 2016-05-17 -* Rustup to *rustc 1.10.0-nightly (cd6a40017 2016-05-16)* -* New lint: [`unnecessary_operation`] - -## 0.0.67 — 2016-05-12 -* Rustup to *rustc 1.10.0-nightly (22ac88f1a 2016-05-11)* - -## 0.0.66 — 2016-05-11 -* New `cargo clippy` subcommand -* New lints: [`assign_op_pattern`], [`assign_ops`], [`needless_borrow`] - -## 0.0.65 — 2016-05-08 -* Rustup to *rustc 1.10.0-nightly (62e2b2fb7 2016-05-06)* -* New lints: [`float_arithmetic`], [`integer_arithmetic`] - -## 0.0.64 — 2016-04-26 -* Rustup to *rustc 1.10.0-nightly (645dd013a 2016-04-24)* -* New lints: `temporary_cstring_as_ptr`, [`unsafe_removed_from_name`], and [`mem_forget`] - -## 0.0.63 — 2016-04-08 -* Rustup to *rustc 1.9.0-nightly (7979dd608 2016-04-07)* - -## 0.0.62 — 2016-04-07 -* Rustup to *rustc 1.9.0-nightly (bf5da36f1 2016-04-06)* - -## 0.0.61 — 2016-04-03 -* Rustup to *rustc 1.9.0-nightly (5ab11d72c 2016-04-02)* -* New lint: [`invalid_upcast_comparisons`] - -## 0.0.60 — 2016-04-01 -* Rustup to *rustc 1.9.0-nightly (e1195c24b 2016-03-31)* - -## 0.0.59 — 2016-03-31 -* Rustup to *rustc 1.9.0-nightly (30a3849f2 2016-03-30)* -* New lints: [`logic_bug`], [`nonminimal_bool`] -* Fixed: [`match_same_arms`] now ignores arms with guards -* Improved: [`useless_vec`] now warns on `for … in vec![…]` - -## 0.0.58 — 2016-03-27 -* Rustup to *rustc 1.9.0-nightly (d5a91e695 2016-03-26)* -* New lint: [`doc_markdown`] - -## 0.0.57 — 2016-03-27 -* Update to *rustc 1.9.0-nightly (a1e29daf1 2016-03-25)* -* Deprecated lints: [`str_to_string`], [`string_to_string`], [`unstable_as_slice`], [`unstable_as_mut_slice`] -* New lint: [`crosspointer_transmute`] - -## 0.0.56 — 2016-03-23 -* Update to *rustc 1.9.0-nightly (0dcc413e4 2016-03-22)* -* New lints: [`many_single_char_names`] and [`similar_names`] - -## 0.0.55 — 2016-03-21 -* Update to *rustc 1.9.0-nightly (02310fd31 2016-03-19)* - -## 0.0.54 — 2016-03-16 -* Update to *rustc 1.9.0-nightly (c66d2380a 2016-03-15)* - -## 0.0.53 — 2016-03-15 -* Add a [configuration file] - -## ~~0.0.52~~ - -## 0.0.51 — 2016-03-13 -* Add `str` to types considered by [`len_zero`] -* New lints: [`indexing_slicing`] - -## 0.0.50 — 2016-03-11 -* Update to *rustc 1.9.0-nightly (c9629d61c 2016-03-10)* - -## 0.0.49 — 2016-03-09 -* Update to *rustc 1.9.0-nightly (eabfc160f 2016-03-08)* -* New lints: [`overflow_check_conditional`], `unused_label`, [`new_without_default`] - -## 0.0.48 — 2016-03-07 -* Fixed: ICE in [`needless_range_loop`] with globals - -## 0.0.47 — 2016-03-07 -* Update to *rustc 1.9.0-nightly (998a6720b 2016-03-07)* -* New lint: [`redundant_closure_call`] - -[`AsMut`]: https://doc.rust-lang.org/std/convert/trait.AsMut.html -[`AsRef`]: https://doc.rust-lang.org/std/convert/trait.AsRef.html -[configuration file]: ./rust-clippy#configuration -[pull3665]: https://github.com/rust-lang/rust-clippy/pull/3665 -[adding_lints]: https://github.com/rust-lang/rust-clippy/blob/master/book/src/development/adding_lints.md -[`README.md`]: https://github.com/rust-lang/rust-clippy/blob/master/README.md -[Clippy's lint list]: https://rust-lang.github.io/rust-clippy/master/index.html - - - -[`absolute_paths`]: https://rust-lang.github.io/rust-clippy/master/index.html#absolute_paths -[`absurd_extreme_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#absurd_extreme_comparisons -[`alloc_instead_of_core`]: https://rust-lang.github.io/rust-clippy/master/index.html#alloc_instead_of_core -[`allow_attributes`]: https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes -[`allow_attributes_without_reason`]: https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes_without_reason -[`almost_complete_letter_range`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_complete_letter_range -[`almost_complete_range`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_complete_range -[`almost_swapped`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_swapped -[`approx_constant`]: https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant -[`arc_with_non_send_sync`]: https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync -[`arithmetic_side_effects`]: https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects -[`as_conversions`]: https://rust-lang.github.io/rust-clippy/master/index.html#as_conversions -[`as_ptr_cast_mut`]: https://rust-lang.github.io/rust-clippy/master/index.html#as_ptr_cast_mut -[`as_underscore`]: https://rust-lang.github.io/rust-clippy/master/index.html#as_underscore -[`assertions_on_constants`]: https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants -[`assertions_on_result_states`]: https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_result_states -[`assign_op_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern -[`assign_ops`]: https://rust-lang.github.io/rust-clippy/master/index.html#assign_ops -[`assigning_clones`]: https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones -[`async_yields_async`]: https://rust-lang.github.io/rust-clippy/master/index.html#async_yields_async -[`await_holding_invalid_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_invalid_type -[`await_holding_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_lock -[`await_holding_refcell_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_refcell_ref -[`bad_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#bad_bit_mask -[`big_endian_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#big_endian_bytes -[`bind_instead_of_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#bind_instead_of_map -[`blacklisted_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name -[`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 -[`bool_to_int_with_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_to_int_with_if -[`borrow_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrow_as_ptr -[`borrow_deref_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref -[`borrow_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrow_interior_mutable_const -[`borrowed_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrowed_box -[`box_collection`]: https://rust-lang.github.io/rust-clippy/master/index.html#box_collection -[`box_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#box_default -[`box_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#box_vec -[`boxed_local`]: https://rust-lang.github.io/rust-clippy/master/index.html#boxed_local -[`branches_sharing_code`]: https://rust-lang.github.io/rust-clippy/master/index.html#branches_sharing_code -[`builtin_type_shadow`]: https://rust-lang.github.io/rust-clippy/master/index.html#builtin_type_shadow -[`bytes_count_to_len`]: https://rust-lang.github.io/rust-clippy/master/index.html#bytes_count_to_len -[`bytes_nth`]: https://rust-lang.github.io/rust-clippy/master/index.html#bytes_nth -[`cargo_common_metadata`]: https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata -[`case_sensitive_file_extension_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#case_sensitive_file_extension_comparisons -[`cast_abs_to_unsigned`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_abs_to_unsigned -[`cast_enum_constructor`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_enum_constructor -[`cast_enum_truncation`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_enum_truncation -[`cast_lossless`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless -[`cast_nan_to_int`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_nan_to_int -[`cast_possible_truncation`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation -[`cast_possible_wrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap -[`cast_precision_loss`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_precision_loss -[`cast_ptr_alignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_ptr_alignment -[`cast_ref_to_mut`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_ref_to_mut -[`cast_sign_loss`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss -[`cast_slice_different_sizes`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_slice_different_sizes -[`cast_slice_from_raw_parts`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_slice_from_raw_parts -[`char_lit_as_u8`]: https://rust-lang.github.io/rust-clippy/master/index.html#char_lit_as_u8 -[`chars_last_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#chars_last_cmp -[`chars_next_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#chars_next_cmp -[`checked_conversions`]: https://rust-lang.github.io/rust-clippy/master/index.html#checked_conversions -[`clear_with_drain`]: https://rust-lang.github.io/rust-clippy/master/index.html#clear_with_drain -[`clone_double_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_double_ref -[`clone_on_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy -[`clone_on_ref_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_ref_ptr -[`cloned_instead_of_copied`]: https://rust-lang.github.io/rust-clippy/master/index.html#cloned_instead_of_copied -[`cmp_nan`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_nan -[`cmp_null`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_null -[`cmp_owned`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_owned -[`cognitive_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#cognitive_complexity -[`collapsible_else_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if -[`collapsible_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if -[`collapsible_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_match -[`collapsible_str_replace`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_str_replace -[`collection_is_never_read`]: https://rust-lang.github.io/rust-clippy/master/index.html#collection_is_never_read -[`comparison_chain`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_chain -[`comparison_to_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_to_empty -[`const_is_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_is_empty -[`const_static_lifetime`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_static_lifetime -[`copy_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#copy_iterator -[`crate_in_macro_def`]: https://rust-lang.github.io/rust-clippy/master/index.html#crate_in_macro_def -[`create_dir`]: https://rust-lang.github.io/rust-clippy/master/index.html#create_dir -[`crosspointer_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#crosspointer_transmute -[`cyclomatic_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#cyclomatic_complexity -[`dbg_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#dbg_macro -[`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 -[`default_union_representation`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_union_representation -[`deprecated_cfg_attr`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_cfg_attr -[`deprecated_clippy_cfg_attr`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_clippy_cfg_attr -[`deprecated_semver`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_semver -[`deref_addrof`]: https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof -[`deref_by_slicing`]: https://rust-lang.github.io/rust-clippy/master/index.html#deref_by_slicing -[`derivable_impls`]: https://rust-lang.github.io/rust-clippy/master/index.html#derivable_impls -[`derive_hash_xor_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq -[`derive_ord_xor_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord -[`derive_partial_eq_without_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_partial_eq_without_eq -[`derived_hash_with_manual_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derived_hash_with_manual_eq -[`disallowed_macros`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_macros -[`disallowed_method`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_method -[`disallowed_methods`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods -[`disallowed_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names -[`disallowed_script_idents`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_script_idents -[`disallowed_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_type -[`disallowed_types`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types -[`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression -[`doc_lazy_continuation`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation -[`doc_link_with_quotes`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_with_quotes -[`doc_markdown`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown -[`double_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_comparisons -[`double_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_must_use -[`double_neg`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_neg -[`double_parens`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_parens -[`drain_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#drain_collect -[`drop_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#drop_bounds -[`drop_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#drop_copy -[`drop_non_drop`]: https://rust-lang.github.io/rust-clippy/master/index.html#drop_non_drop -[`drop_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#drop_ref -[`duplicate_mod`]: https://rust-lang.github.io/rust-clippy/master/index.html#duplicate_mod -[`duplicate_underscore_argument`]: https://rust-lang.github.io/rust-clippy/master/index.html#duplicate_underscore_argument -[`duplicated_attributes`]: https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes -[`duration_subsec`]: https://rust-lang.github.io/rust-clippy/master/index.html#duration_subsec -[`eager_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#eager_transmute -[`else_if_without_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else -[`empty_docs`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_docs -[`empty_drop`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_drop -[`empty_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_enum -[`empty_enum_variants_with_brackets`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_enum_variants_with_brackets -[`empty_line_after_doc_comments`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments -[`empty_line_after_outer_attr`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_outer_attr -[`empty_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_loop -[`empty_structs_with_brackets`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_structs_with_brackets -[`enum_clike_unportable_variant`]: https://rust-lang.github.io/rust-clippy/master/index.html#enum_clike_unportable_variant -[`enum_glob_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#enum_glob_use -[`enum_variant_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names -[`eq_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#eq_op -[`equatable_if_let`]: https://rust-lang.github.io/rust-clippy/master/index.html#equatable_if_let -[`erasing_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#erasing_op -[`err_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#err_expect -[`error_impl_error`]: https://rust-lang.github.io/rust-clippy/master/index.html#error_impl_error -[`eval_order_dependence`]: https://rust-lang.github.io/rust-clippy/master/index.html#eval_order_dependence -[`excessive_nesting`]: https://rust-lang.github.io/rust-clippy/master/index.html#excessive_nesting -[`excessive_precision`]: https://rust-lang.github.io/rust-clippy/master/index.html#excessive_precision -[`exhaustive_enums`]: https://rust-lang.github.io/rust-clippy/master/index.html#exhaustive_enums -[`exhaustive_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#exhaustive_structs -[`exit`]: https://rust-lang.github.io/rust-clippy/master/index.html#exit -[`expect_fun_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#expect_fun_call -[`expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#expect_used -[`expl_impl_clone_on_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#expl_impl_clone_on_copy -[`explicit_auto_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref -[`explicit_counter_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_counter_loop -[`explicit_deref_methods`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_deref_methods -[`explicit_into_iter_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_into_iter_loop -[`explicit_iter_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_iter_loop -[`explicit_write`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_write -[`extend_from_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#extend_from_slice -[`extend_with_drain`]: https://rust-lang.github.io/rust-clippy/master/index.html#extend_with_drain -[`extra_unused_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes -[`extra_unused_type_parameters`]: https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_type_parameters -[`fallible_impl_from`]: https://rust-lang.github.io/rust-clippy/master/index.html#fallible_impl_from -[`field_reassign_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default -[`filetype_is_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#filetype_is_file -[`filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map -[`filter_map_bool_then`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_bool_then -[`filter_map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_identity -[`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next -[`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next -[`find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#find_map -[`flat_map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#flat_map_identity -[`flat_map_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#flat_map_option -[`float_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_arithmetic -[`float_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp -[`float_cmp_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp_const -[`float_equality_without_abs`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_equality_without_abs -[`fn_address_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_address_comparisons -[`fn_null_check`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_null_check -[`fn_params_excessive_bools`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_params_excessive_bools -[`fn_to_numeric_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_to_numeric_cast -[`fn_to_numeric_cast_any`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_to_numeric_cast_any -[`fn_to_numeric_cast_with_truncation`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_to_numeric_cast_with_truncation -[`for_kv_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_kv_map -[`for_loop_over_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loop_over_option -[`for_loop_over_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loop_over_result -[`for_loops_over_fallibles`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loops_over_fallibles -[`forget_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_copy -[`forget_non_drop`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_non_drop -[`forget_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_ref -[`format_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#format_collect -[`format_in_format_args`]: https://rust-lang.github.io/rust-clippy/master/index.html#format_in_format_args -[`format_push_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string -[`four_forward_slashes`]: https://rust-lang.github.io/rust-clippy/master/index.html#four_forward_slashes -[`from_iter_instead_of_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#from_iter_instead_of_collect -[`from_over_into`]: https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into -[`from_raw_with_void_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#from_raw_with_void_ptr -[`from_str_radix_10`]: https://rust-lang.github.io/rust-clippy/master/index.html#from_str_radix_10 -[`future_not_send`]: https://rust-lang.github.io/rust-clippy/master/index.html#future_not_send -[`get_first`]: https://rust-lang.github.io/rust-clippy/master/index.html#get_first -[`get_last_with_len`]: https://rust-lang.github.io/rust-clippy/master/index.html#get_last_with_len -[`get_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#get_unwrap -[`host_endian_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#host_endian_bytes -[`identity_conversion`]: https://rust-lang.github.io/rust-clippy/master/index.html#identity_conversion -[`identity_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#identity_op -[`if_let_mutex`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_let_mutex -[`if_let_redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_let_redundant_pattern_matching -[`if_let_some_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_let_some_result -[`if_not_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else -[`if_same_then_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else -[`if_then_some_else_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_then_some_else_none -[`ifs_same_cond`]: https://rust-lang.github.io/rust-clippy/master/index.html#ifs_same_cond -[`ignored_unit_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#ignored_unit_patterns -[`impl_hash_borrow_with_str_and_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#impl_hash_borrow_with_str_and_bytes -[`impl_trait_in_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#impl_trait_in_params -[`implicit_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_clone -[`implicit_hasher`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_hasher -[`implicit_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_return -[`implicit_saturating_add`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_add -[`implicit_saturating_sub`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_sub -[`implied_bounds_in_impls`]: https://rust-lang.github.io/rust-clippy/master/index.html#implied_bounds_in_impls -[`impossible_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#impossible_comparisons -[`imprecise_flops`]: https://rust-lang.github.io/rust-clippy/master/index.html#imprecise_flops -[`incompatible_msrv`]: https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv -[`inconsistent_digit_grouping`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_digit_grouping -[`inconsistent_struct_constructor`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_struct_constructor -[`incorrect_clone_impl_on_copy_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#incorrect_clone_impl_on_copy_type -[`incorrect_partial_ord_impl_on_ord_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#incorrect_partial_ord_impl_on_ord_type -[`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 -[`inline_always`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_always -[`inline_asm_x86_att_syntax`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_asm_x86_att_syntax -[`inline_asm_x86_intel_syntax`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_asm_x86_intel_syntax -[`inline_fn_without_body`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_fn_without_body -[`inspect_for_each`]: https://rust-lang.github.io/rust-clippy/master/index.html#inspect_for_each -[`int_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#int_plus_one -[`integer_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_arithmetic -[`integer_division`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_division -[`integer_division_remainder_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_division_remainder_used -[`into_iter_on_array`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_array -[`into_iter_on_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref -[`into_iter_without_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_without_iter -[`invalid_atomic_ordering`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_atomic_ordering -[`invalid_null_ptr_usage`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_null_ptr_usage -[`invalid_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_ref -[`invalid_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_regex -[`invalid_upcast_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_upcast_comparisons -[`invalid_utf8_in_unchecked`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_utf8_in_unchecked -[`invisible_characters`]: https://rust-lang.github.io/rust-clippy/master/index.html#invisible_characters -[`is_digit_ascii_radix`]: https://rust-lang.github.io/rust-clippy/master/index.html#is_digit_ascii_radix -[`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements -[`items_after_test_module`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_test_module -[`iter_cloned_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_cloned_collect -[`iter_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_count -[`iter_filter_is_ok`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_filter_is_ok -[`iter_filter_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_filter_is_some -[`iter_kv_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_kv_map -[`iter_next_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_loop -[`iter_next_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_slice -[`iter_not_returning_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator -[`iter_nth`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth -[`iter_nth_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth_zero -[`iter_on_empty_collections`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_on_empty_collections -[`iter_on_single_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_on_single_items -[`iter_out_of_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_out_of_bounds -[`iter_over_hash_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_over_hash_type -[`iter_overeager_cloned`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_overeager_cloned -[`iter_skip_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_next -[`iter_skip_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_zero -[`iter_with_drain`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_with_drain -[`iter_without_into_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_without_into_iter -[`iterator_step_by_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iterator_step_by_zero -[`join_absolute_paths`]: https://rust-lang.github.io/rust-clippy/master/index.html#join_absolute_paths -[`just_underscores_and_digits`]: https://rust-lang.github.io/rust-clippy/master/index.html#just_underscores_and_digits -[`large_const_arrays`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_const_arrays -[`large_digit_groups`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_digit_groups -[`large_enum_variant`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant -[`large_futures`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_futures -[`large_include_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_include_file -[`large_stack_arrays`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_stack_arrays -[`large_stack_frames`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_stack_frames -[`large_types_passed_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_types_passed_by_value -[`legacy_numeric_constants`]: https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants -[`len_without_is_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty -[`len_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_zero -[`let_and_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return -[`let_underscore_drop`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_drop -[`let_underscore_future`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_future -[`let_underscore_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_lock -[`let_underscore_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_must_use -[`let_underscore_untyped`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_untyped -[`let_unit_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value -[`let_with_type_underscore`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_with_type_underscore -[`lines_filter_map_ok`]: https://rust-lang.github.io/rust-clippy/master/index.html#lines_filter_map_ok -[`linkedlist`]: https://rust-lang.github.io/rust-clippy/master/index.html#linkedlist -[`lint_groups_priority`]: https://rust-lang.github.io/rust-clippy/master/index.html#lint_groups_priority -[`little_endian_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#little_endian_bytes -[`logic_bug`]: https://rust-lang.github.io/rust-clippy/master/index.html#logic_bug -[`lossy_float_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#lossy_float_literal -[`macro_metavars_in_unsafe`]: https://rust-lang.github.io/rust-clippy/master/index.html#macro_metavars_in_unsafe -[`macro_use_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#macro_use_imports -[`main_recursion`]: https://rust-lang.github.io/rust-clippy/master/index.html#main_recursion -[`manual_assert`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_assert -[`manual_async_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_async_fn -[`manual_bits`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_bits -[`manual_c_str_literals`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_c_str_literals -[`manual_clamp`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_clamp -[`manual_filter`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_filter -[`manual_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_filter_map -[`manual_find`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find -[`manual_find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find_map -[`manual_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_flatten -[`manual_hash_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_hash_one -[`manual_instant_elapsed`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_instant_elapsed -[`manual_is_ascii_check`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_ascii_check -[`manual_is_finite`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_finite -[`manual_is_infinite`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_infinite -[`manual_is_variant_and`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_variant_and -[`manual_let_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else -[`manual_main_separator_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_main_separator_str -[`manual_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_map -[`manual_memcpy`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_memcpy -[`manual_next_back`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_next_back -[`manual_non_exhaustive`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive -[`manual_ok_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_or -[`manual_range_contains`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains -[`manual_range_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_patterns -[`manual_rem_euclid`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_rem_euclid -[`manual_retain`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain -[`manual_saturating_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic -[`manual_slice_size_calculation`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_slice_size_calculation -[`manual_split_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_split_once -[`manual_str_repeat`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_str_repeat -[`manual_string_new`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_string_new -[`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_try_fold`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold -[`manual_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or -[`manual_unwrap_or_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or_default -[`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 -[`map_entry`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_entry -[`map_err_ignore`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_err_ignore -[`map_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten -[`map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_identity -[`map_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or -[`match_as_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_as_ref -[`match_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_bool -[`match_like_matches_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro -[`match_on_vec_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_on_vec_items -[`match_overlapping_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_overlapping_arm -[`match_ref_pats`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_ref_pats -[`match_result_ok`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_result_ok -[`match_same_arms`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms -[`match_single_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_single_binding -[`match_str_case_mismatch`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_str_case_mismatch -[`match_wild_err_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_wild_err_arm -[`match_wildcard_for_single_variants`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_wildcard_for_single_variants -[`maybe_infinite_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#maybe_infinite_iter -[`maybe_misused_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#maybe_misused_cfg -[`mem_discriminant_non_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_discriminant_non_enum -[`mem_forget`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_forget -[`mem_replace_option_with_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_option_with_none -[`mem_replace_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default -[`mem_replace_with_uninit`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_uninit -[`min_ident_chars`]: https://rust-lang.github.io/rust-clippy/master/index.html#min_ident_chars -[`min_max`]: https://rust-lang.github.io/rust-clippy/master/index.html#min_max -[`misaligned_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#misaligned_transmute -[`mismatched_target_os`]: https://rust-lang.github.io/rust-clippy/master/index.html#mismatched_target_os -[`mismatching_type_param_order`]: https://rust-lang.github.io/rust-clippy/master/index.html#mismatching_type_param_order -[`misnamed_getters`]: https://rust-lang.github.io/rust-clippy/master/index.html#misnamed_getters -[`misrefactored_assign_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#misrefactored_assign_op -[`missing_assert_message`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_assert_message -[`missing_asserts_for_indexing`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_asserts_for_indexing -[`missing_const_for_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn -[`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 -[`missing_spin_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_spin_loop -[`missing_trait_methods`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_trait_methods -[`missing_transmute_annotations`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_transmute_annotations -[`mistyped_literal_suffixes`]: https://rust-lang.github.io/rust-clippy/master/index.html#mistyped_literal_suffixes -[`mixed_attributes_style`]: https://rust-lang.github.io/rust-clippy/master/index.html#mixed_attributes_style -[`mixed_case_hex_literals`]: https://rust-lang.github.io/rust-clippy/master/index.html#mixed_case_hex_literals -[`mixed_read_write_in_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#mixed_read_write_in_expression -[`mod_module_files`]: https://rust-lang.github.io/rust-clippy/master/index.html#mod_module_files -[`module_inception`]: https://rust-lang.github.io/rust-clippy/master/index.html#module_inception -[`module_name_repetitions`]: https://rust-lang.github.io/rust-clippy/master/index.html#module_name_repetitions -[`modulo_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#modulo_arithmetic -[`modulo_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#modulo_one -[`multi_assignments`]: https://rust-lang.github.io/rust-clippy/master/index.html#multi_assignments -[`multiple_bound_locations`]: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations -[`multiple_crate_versions`]: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_crate_versions -[`multiple_inherent_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_inherent_impl -[`multiple_unsafe_ops_per_block`]: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_unsafe_ops_per_block -[`must_use_candidate`]: https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate -[`must_use_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#must_use_unit -[`mut_from_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_from_ref -[`mut_mut`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_mut -[`mut_mutex_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_mutex_lock -[`mut_range_bound`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_range_bound -[`mutable_key_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#mutable_key_type -[`mutex_atomic`]: https://rust-lang.github.io/rust-clippy/master/index.html#mutex_atomic -[`mutex_integer`]: https://rust-lang.github.io/rust-clippy/master/index.html#mutex_integer -[`naive_bytecount`]: https://rust-lang.github.io/rust-clippy/master/index.html#naive_bytecount -[`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_borrows_for_generic_args`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args -[`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_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_if -[`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 -[`needless_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_match -[`needless_option_as_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_option_as_deref -[`needless_option_take`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_option_take -[`needless_parens_on_range_literals`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_parens_on_range_literals -[`needless_pass_by_ref_mut`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut -[`needless_pass_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value -[`needless_pub_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_pub_self -[`needless_question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark -[`needless_range_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop -[`needless_raw_string_hashes`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes -[`needless_raw_strings`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_strings -[`needless_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_return -[`needless_return_with_question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_return_with_question_mark -[`needless_splitn`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_splitn -[`needless_update`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_update -[`neg_cmp_op_on_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#neg_cmp_op_on_partial_ord -[`neg_multiply`]: https://rust-lang.github.io/rust-clippy/master/index.html#neg_multiply -[`negative_feature_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#negative_feature_names -[`never_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#never_loop -[`new_ret_no_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_ret_no_self -[`new_without_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default -[`new_without_default_derive`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default_derive -[`no_effect`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_effect -[`no_effect_replace`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_effect_replace -[`no_effect_underscore_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_effect_underscore_binding -[`no_mangle_with_rust_abi`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_mangle_with_rust_abi -[`non_ascii_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_ascii_literal -[`non_canonical_clone_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_canonical_clone_impl -[`non_canonical_partial_ord_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_canonical_partial_ord_impl -[`non_minimal_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_minimal_cfg -[`non_octal_unix_permissions`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_octal_unix_permissions -[`non_send_fields_in_send_ty`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_send_fields_in_send_ty -[`nonminimal_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool -[`nonsensical_open_options`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonsensical_open_options -[`nonstandard_macro_braces`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces -[`not_unsafe_ptr_arg_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref -[`obfuscated_if_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#obfuscated_if_else -[`octal_escapes`]: https://rust-lang.github.io/rust-clippy/master/index.html#octal_escapes -[`ok_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#ok_expect -[`only_used_in_recursion`]: https://rust-lang.github.io/rust-clippy/master/index.html#only_used_in_recursion -[`op_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#op_ref -[`option_and_then_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_and_then_some -[`option_as_ref_cloned`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_cloned -[`option_as_ref_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref -[`option_env_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_env_unwrap -[`option_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_expect_used -[`option_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_filter_map -[`option_if_let_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_if_let_else -[`option_map_or_err_ok`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_or_err_ok -[`option_map_or_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_or_none -[`option_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unit_fn -[`option_map_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unwrap_or -[`option_map_unwrap_or_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unwrap_or_else -[`option_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_option -[`option_unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_unwrap_used -[`or_fun_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call -[`or_then_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#or_then_unwrap -[`out_of_bounds_indexing`]: https://rust-lang.github.io/rust-clippy/master/index.html#out_of_bounds_indexing -[`overflow_check_conditional`]: https://rust-lang.github.io/rust-clippy/master/index.html#overflow_check_conditional -[`overly_complex_bool_expr`]: https://rust-lang.github.io/rust-clippy/master/index.html#overly_complex_bool_expr -[`panic`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic -[`panic_in_result_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_in_result_fn -[`panic_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_params -[`panicking_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#panicking_unwrap -[`partial_pub_fields`]: https://rust-lang.github.io/rust-clippy/master/index.html#partial_pub_fields -[`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl -[`partialeq_to_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_to_none -[`path_buf_push_overwrite`]: https://rust-lang.github.io/rust-clippy/master/index.html#path_buf_push_overwrite -[`path_ends_with_ext`]: https://rust-lang.github.io/rust-clippy/master/index.html#path_ends_with_ext -[`pattern_type_mismatch`]: https://rust-lang.github.io/rust-clippy/master/index.html#pattern_type_mismatch -[`permissions_set_readonly_false`]: https://rust-lang.github.io/rust-clippy/master/index.html#permissions_set_readonly_false -[`positional_named_format_parameters`]: https://rust-lang.github.io/rust-clippy/master/index.html#positional_named_format_parameters -[`possible_missing_comma`]: https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma -[`precedence`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence -[`print_in_format_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_in_format_impl -[`print_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_literal -[`print_stderr`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_stderr -[`print_stdout`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_stdout -[`print_with_newline`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_with_newline -[`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 -[`pub_underscore_fields`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_underscore_fields -[`pub_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_use -[`pub_with_shorthand`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_with_shorthand -[`pub_without_shorthand`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_without_shorthand -[`question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#question_mark -[`question_mark_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#question_mark_used -[`range_minus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_minus_one -[`range_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_plus_one -[`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_clone_in_vec_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_clone_in_vec_init -[`rc_mutex`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_mutex -[`read_line_without_trim`]: https://rust-lang.github.io/rust-clippy/master/index.html#read_line_without_trim -[`read_zero_byte_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#read_zero_byte_vec -[`readonly_write_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#readonly_write_lock -[`recursive_format_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#recursive_format_impl -[`redundant_allocation`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_allocation -[`redundant_as_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_as_str -[`redundant_async_block`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_async_block -[`redundant_at_rest_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_at_rest_pattern -[`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 -[`redundant_closure_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_call -[`redundant_closure_for_method_calls`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls -[`redundant_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_comparisons -[`redundant_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else -[`redundant_feature_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_feature_names -[`redundant_field_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names -[`redundant_guards`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_guards -[`redundant_locals`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_locals -[`redundant_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern -[`redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching -[`redundant_pub_crate`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pub_crate -[`redundant_slicing`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_slicing -[`redundant_static_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes -[`redundant_type_annotations`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_type_annotations -[`ref_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_as_ptr -[`ref_binding_to_reference`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_binding_to_reference -[`ref_in_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_in_deref -[`ref_option_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_option_ref -[`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 -[`renamed_function_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#renamed_function_params -[`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 -[`result_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_expect_used -[`result_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_filter_map -[`result_large_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err -[`result_map_or_into_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_or_into_option -[`result_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unit_fn -[`result_map_unwrap_or_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unwrap_or_else -[`result_unit_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_unit_err -[`result_unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_unwrap_used -[`return_self_not_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use -[`reversed_empty_ranges`]: https://rust-lang.github.io/rust-clippy/master/index.html#reversed_empty_ranges -[`same_functions_in_if_condition`]: https://rust-lang.github.io/rust-clippy/master/index.html#same_functions_in_if_condition -[`same_item_push`]: https://rust-lang.github.io/rust-clippy/master/index.html#same_item_push -[`same_name_method`]: https://rust-lang.github.io/rust-clippy/master/index.html#same_name_method -[`search_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#search_is_some -[`seek_from_current`]: https://rust-lang.github.io/rust-clippy/master/index.html#seek_from_current -[`seek_to_start_instead_of_rewind`]: https://rust-lang.github.io/rust-clippy/master/index.html#seek_to_start_instead_of_rewind -[`self_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#self_assignment -[`self_named_constructors`]: https://rust-lang.github.io/rust-clippy/master/index.html#self_named_constructors -[`self_named_module_files`]: https://rust-lang.github.io/rust-clippy/master/index.html#self_named_module_files -[`semicolon_if_nothing_returned`]: https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned -[`semicolon_inside_block`]: https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_inside_block -[`semicolon_outside_block`]: https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_outside_block -[`separated_literal_suffix`]: https://rust-lang.github.io/rust-clippy/master/index.html#separated_literal_suffix -[`serde_api_misuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#serde_api_misuse -[`shadow_reuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_reuse -[`shadow_same`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_same -[`shadow_unrelated`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_unrelated -[`short_circuit_statement`]: https://rust-lang.github.io/rust-clippy/master/index.html#short_circuit_statement -[`should_assert_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_assert_eq -[`should_implement_trait`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait -[`should_panic_without_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_panic_without_expect -[`significant_drop_in_scrutinee`]: https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_in_scrutinee -[`significant_drop_tightening`]: https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_tightening -[`similar_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#similar_names -[`single_call_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_call_fn -[`single_char_add_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_add_str -[`single_char_lifetime_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_lifetime_names -[`single_char_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern -[`single_char_push_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_push_str -[`single_component_path_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports -[`single_element_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_element_loop -[`single_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match -[`single_match_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else -[`single_range_in_vec_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_range_in_vec_init -[`size_of_in_element_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#size_of_in_element_count -[`size_of_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#size_of_ref -[`skip_while_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#skip_while_next -[`slow_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#slow_vector_initialization -[`stable_sort_primitive`]: https://rust-lang.github.io/rust-clippy/master/index.html#stable_sort_primitive -[`std_instead_of_alloc`]: https://rust-lang.github.io/rust-clippy/master/index.html#std_instead_of_alloc -[`std_instead_of_core`]: https://rust-lang.github.io/rust-clippy/master/index.html#std_instead_of_core -[`str_split_at_newline`]: https://rust-lang.github.io/rust-clippy/master/index.html#str_split_at_newline -[`str_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#str_to_string -[`string_add`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_add -[`string_add_assign`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_add_assign -[`string_extend_chars`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_extend_chars -[`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_lit_chars_any`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_lit_chars_any -[`string_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_slice -[`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 -[`struct_field_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#struct_field_names -[`stutter`]: https://rust-lang.github.io/rust-clippy/master/index.html#stutter -[`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 -[`suspicious_assignment_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_assignment_formatting -[`suspicious_command_arg_space`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_command_arg_space -[`suspicious_doc_comments`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_doc_comments -[`suspicious_else_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_else_formatting -[`suspicious_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_map -[`suspicious_op_assign_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_op_assign_impl -[`suspicious_open_options`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_open_options -[`suspicious_operation_groupings`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_operation_groupings -[`suspicious_splitn`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_splitn -[`suspicious_to_owned`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_to_owned -[`suspicious_unary_op_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_unary_op_formatting -[`suspicious_xor_used_as_pow`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_xor_used_as_pow -[`swap_ptr_to_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#swap_ptr_to_ref -[`tabs_in_doc_comments`]: https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments -[`temporary_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_assignment -[`temporary_cstring_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_cstring_as_ptr -[`test_attr_in_doctest`]: https://rust-lang.github.io/rust-clippy/master/index.html#test_attr_in_doctest -[`tests_outside_test_module`]: https://rust-lang.github.io/rust-clippy/master/index.html#tests_outside_test_module -[`thread_local_initializer_can_be_made_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#thread_local_initializer_can_be_made_const -[`to_digit_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_digit_is_some -[`to_string_in_display`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_string_in_display -[`to_string_in_format_args`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_string_in_format_args -[`to_string_trait_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_string_trait_impl -[`todo`]: https://rust-lang.github.io/rust-clippy/master/index.html#todo -[`too_many_arguments`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments -[`too_many_lines`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_lines -[`toplevel_ref_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#toplevel_ref_arg -[`trailing_empty_array`]: https://rust-lang.github.io/rust-clippy/master/index.html#trailing_empty_array -[`trait_duplication_in_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#trait_duplication_in_bounds -[`transmute_bytes_to_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_bytes_to_str -[`transmute_float_to_int`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_float_to_int -[`transmute_int_to_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_bool -[`transmute_int_to_char`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_char -[`transmute_int_to_float`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_float -[`transmute_int_to_non_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_non_zero -[`transmute_null_to_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_null_to_fn -[`transmute_num_to_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_num_to_bytes -[`transmute_ptr_to_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ptr -[`transmute_ptr_to_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ref -[`transmute_undefined_repr`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_undefined_repr -[`transmutes_expressible_as_ptr_casts`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmutes_expressible_as_ptr_casts -[`transmuting_null`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmuting_null -[`trim_split_whitespace`]: https://rust-lang.github.io/rust-clippy/master/index.html#trim_split_whitespace -[`trivial_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#trivial_regex -[`trivially_copy_pass_by_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref -[`try_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#try_err -[`tuple_array_conversions`]: https://rust-lang.github.io/rust-clippy/master/index.html#tuple_array_conversions -[`type_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity -[`type_id_on_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_id_on_box -[`type_repetition_in_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds -[`unchecked_duration_subtraction`]: https://rust-lang.github.io/rust-clippy/master/index.html#unchecked_duration_subtraction -[`unconditional_recursion`]: https://rust-lang.github.io/rust-clippy/master/index.html#unconditional_recursion -[`undocumented_unsafe_blocks`]: https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks -[`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 -[`unit_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg -[`unit_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_cmp -[`unit_hash`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_hash -[`unit_return_expecting_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_return_expecting_ord -[`unknown_clippy_lints`]: https://rust-lang.github.io/rust-clippy/master/index.html#unknown_clippy_lints -[`unnecessary_box_returns`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_box_returns -[`unnecessary_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast -[`unnecessary_clippy_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_clippy_cfg -[`unnecessary_fallible_conversions`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_fallible_conversions -[`unnecessary_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_filter_map -[`unnecessary_find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_find_map -[`unnecessary_fold`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_fold -[`unnecessary_get_then_check`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_get_then_check -[`unnecessary_join`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_join -[`unnecessary_lazy_evaluations`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations -[`unnecessary_literal_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_literal_unwrap -[`unnecessary_map_on_constructor`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_on_constructor -[`unnecessary_mut_passed`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed -[`unnecessary_operation`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_operation -[`unnecessary_owned_empty_strings`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_owned_empty_strings -[`unnecessary_result_map_or_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_result_map_or_else -[`unnecessary_safety_comment`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_safety_comment -[`unnecessary_safety_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_safety_doc -[`unnecessary_self_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_self_imports -[`unnecessary_sort_by`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_sort_by -[`unnecessary_struct_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_struct_initialization -[`unnecessary_to_owned`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_to_owned -[`unnecessary_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_unwrap -[`unnecessary_wraps`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_wraps -[`unneeded_field_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_field_pattern -[`unneeded_wildcard_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_wildcard_pattern -[`unnested_or_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns -[`unreachable`]: https://rust-lang.github.io/rust-clippy/master/index.html#unreachable -[`unreadable_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#unreadable_literal -[`unsafe_derive_deserialize`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_derive_deserialize -[`unsafe_removed_from_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_removed_from_name -[`unsafe_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_vector_initialization -[`unseparated_literal_suffix`]: https://rust-lang.github.io/rust-clippy/master/index.html#unseparated_literal_suffix -[`unsound_collection_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsound_collection_transmute -[`unstable_as_mut_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#unstable_as_mut_slice -[`unstable_as_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#unstable_as_slice -[`unused_async`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_async -[`unused_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_collect -[`unused_enumerate_index`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_enumerate_index -[`unused_format_specs`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_format_specs -[`unused_io_amount`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_io_amount -[`unused_label`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_label -[`unused_peekable`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_peekable -[`unused_rounding`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_rounding -[`unused_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_self -[`unused_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit -[`unusual_byte_groupings`]: https://rust-lang.github.io/rust-clippy/master/index.html#unusual_byte_groupings -[`unwrap_in_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_in_result -[`unwrap_or_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_or_default -[`unwrap_or_else_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_or_else_default -[`unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used -[`upper_case_acronyms`]: https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms -[`use_debug`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_debug -[`use_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_self -[`used_underscore_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding -[`useless_asref`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_asref -[`useless_attribute`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_attribute -[`useless_conversion`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion -[`useless_format`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_format -[`useless_let_if_seq`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_let_if_seq -[`useless_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_transmute -[`useless_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_vec -[`vec_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#vec_box -[`vec_init_then_push`]: https://rust-lang.github.io/rust-clippy/master/index.html#vec_init_then_push -[`vec_resize_to_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#vec_resize_to_zero -[`verbose_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#verbose_bit_mask -[`verbose_file_reads`]: https://rust-lang.github.io/rust-clippy/master/index.html#verbose_file_reads -[`vtable_address_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#vtable_address_comparisons -[`waker_clone_wake`]: https://rust-lang.github.io/rust-clippy/master/index.html#waker_clone_wake -[`while_immutable_condition`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_immutable_condition -[`while_let_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_loop -[`while_let_on_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_on_iterator -[`wildcard_dependencies`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_dependencies -[`wildcard_enum_match_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_enum_match_arm -[`wildcard_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports -[`wildcard_in_or_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_in_or_patterns -[`write_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#write_literal -[`write_with_newline`]: https://rust-lang.github.io/rust-clippy/master/index.html#write_with_newline -[`writeln_empty_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#writeln_empty_string -[`wrong_pub_self_convention`]: https://rust-lang.github.io/rust-clippy/master/index.html#wrong_pub_self_convention -[`wrong_self_convention`]: https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention -[`wrong_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#wrong_transmute -[`zero_divided_by_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_divided_by_zero -[`zero_prefixed_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_prefixed_literal -[`zero_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_ptr -[`zero_repeat_side_effects`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_repeat_side_effects -[`zero_sized_map_values`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_sized_map_values -[`zero_width_space`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_width_space -[`zst_offset`]: https://rust-lang.github.io/rust-clippy/master/index.html#zst_offset - - -[`absolute-paths-allowed-crates`]: https://doc.rust-lang.org/clippy/lint_configuration.html#absolute-paths-allowed-crates -[`absolute-paths-max-segments`]: https://doc.rust-lang.org/clippy/lint_configuration.html#absolute-paths-max-segments -[`accept-comment-above-attributes`]: https://doc.rust-lang.org/clippy/lint_configuration.html#accept-comment-above-attributes -[`accept-comment-above-statement`]: https://doc.rust-lang.org/clippy/lint_configuration.html#accept-comment-above-statement -[`allow-comparison-to-zero`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-comparison-to-zero -[`allow-dbg-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-dbg-in-tests -[`allow-expect-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-expect-in-tests -[`allow-mixed-uninlined-format-args`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-mixed-uninlined-format-args -[`allow-one-hash-in-raw-strings`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-one-hash-in-raw-strings -[`allow-print-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-print-in-tests -[`allow-private-module-inception`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-private-module-inception -[`allow-renamed-params-for`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-renamed-params-for -[`allow-unwrap-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-unwrap-in-tests -[`allow-useless-vec-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-useless-vec-in-tests -[`allowed-dotfiles`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-dotfiles -[`allowed-duplicate-crates`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-duplicate-crates -[`allowed-idents-below-min-chars`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-idents-below-min-chars -[`allowed-prefixes`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-prefixes -[`allowed-scripts`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-scripts -[`allowed-wildcard-imports`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-wildcard-imports -[`arithmetic-side-effects-allowed`]: https://doc.rust-lang.org/clippy/lint_configuration.html#arithmetic-side-effects-allowed -[`arithmetic-side-effects-allowed-binary`]: https://doc.rust-lang.org/clippy/lint_configuration.html#arithmetic-side-effects-allowed-binary -[`arithmetic-side-effects-allowed-unary`]: https://doc.rust-lang.org/clippy/lint_configuration.html#arithmetic-side-effects-allowed-unary -[`array-size-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#array-size-threshold -[`avoid-breaking-exported-api`]: https://doc.rust-lang.org/clippy/lint_configuration.html#avoid-breaking-exported-api -[`await-holding-invalid-types`]: https://doc.rust-lang.org/clippy/lint_configuration.html#await-holding-invalid-types -[`cargo-ignore-publish`]: https://doc.rust-lang.org/clippy/lint_configuration.html#cargo-ignore-publish -[`check-private-items`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-private-items -[`cognitive-complexity-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#cognitive-complexity-threshold -[`disallowed-macros`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-macros -[`disallowed-methods`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-methods -[`disallowed-names`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-names -[`disallowed-types`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-types -[`doc-valid-idents`]: https://doc.rust-lang.org/clippy/lint_configuration.html#doc-valid-idents -[`enable-raw-pointer-heuristic-for-send`]: https://doc.rust-lang.org/clippy/lint_configuration.html#enable-raw-pointer-heuristic-for-send -[`enforce-iter-loop-reborrow`]: https://doc.rust-lang.org/clippy/lint_configuration.html#enforce-iter-loop-reborrow -[`enforced-import-renames`]: https://doc.rust-lang.org/clippy/lint_configuration.html#enforced-import-renames -[`enum-variant-name-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#enum-variant-name-threshold -[`enum-variant-size-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#enum-variant-size-threshold -[`excessive-nesting-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#excessive-nesting-threshold -[`future-size-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#future-size-threshold -[`ignore-interior-mutability`]: https://doc.rust-lang.org/clippy/lint_configuration.html#ignore-interior-mutability -[`large-error-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#large-error-threshold -[`literal-representation-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#literal-representation-threshold -[`matches-for-let-else`]: https://doc.rust-lang.org/clippy/lint_configuration.html#matches-for-let-else -[`max-fn-params-bools`]: https://doc.rust-lang.org/clippy/lint_configuration.html#max-fn-params-bools -[`max-include-file-size`]: https://doc.rust-lang.org/clippy/lint_configuration.html#max-include-file-size -[`max-struct-bools`]: https://doc.rust-lang.org/clippy/lint_configuration.html#max-struct-bools -[`max-suggested-slice-pattern-length`]: https://doc.rust-lang.org/clippy/lint_configuration.html#max-suggested-slice-pattern-length -[`max-trait-bounds`]: https://doc.rust-lang.org/clippy/lint_configuration.html#max-trait-bounds -[`min-ident-chars-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#min-ident-chars-threshold -[`missing-docs-in-crate-items`]: https://doc.rust-lang.org/clippy/lint_configuration.html#missing-docs-in-crate-items -[`msrv`]: https://doc.rust-lang.org/clippy/lint_configuration.html#msrv -[`pass-by-value-size-limit`]: https://doc.rust-lang.org/clippy/lint_configuration.html#pass-by-value-size-limit -[`pub-underscore-fields-behavior`]: https://doc.rust-lang.org/clippy/lint_configuration.html#pub-underscore-fields-behavior -[`semicolon-inside-block-ignore-singleline`]: https://doc.rust-lang.org/clippy/lint_configuration.html#semicolon-inside-block-ignore-singleline -[`semicolon-outside-block-ignore-multiline`]: https://doc.rust-lang.org/clippy/lint_configuration.html#semicolon-outside-block-ignore-multiline -[`single-char-binding-names-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#single-char-binding-names-threshold -[`stack-size-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#stack-size-threshold -[`standard-macro-braces`]: https://doc.rust-lang.org/clippy/lint_configuration.html#standard-macro-braces -[`struct-field-name-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#struct-field-name-threshold -[`suppress-restriction-lint-in-const`]: https://doc.rust-lang.org/clippy/lint_configuration.html#suppress-restriction-lint-in-const -[`too-large-for-stack`]: https://doc.rust-lang.org/clippy/lint_configuration.html#too-large-for-stack -[`too-many-arguments-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#too-many-arguments-threshold -[`too-many-lines-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#too-many-lines-threshold -[`trivial-copy-size-limit`]: https://doc.rust-lang.org/clippy/lint_configuration.html#trivial-copy-size-limit -[`type-complexity-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#type-complexity-threshold -[`unnecessary-box-size`]: https://doc.rust-lang.org/clippy/lint_configuration.html#unnecessary-box-size -[`unreadable-literal-lint-fractions`]: https://doc.rust-lang.org/clippy/lint_configuration.html#unreadable-literal-lint-fractions -[`upper-case-acronyms-aggressive`]: https://doc.rust-lang.org/clippy/lint_configuration.html#upper-case-acronyms-aggressive -[`vec-box-size-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#vec-box-size-threshold -[`verbose-bit-mask-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#verbose-bit-mask-threshold -[`warn-on-all-wildcard-imports`]: https://doc.rust-lang.org/clippy/lint_configuration.html#warn-on-all-wildcard-imports -[`warn-unsafe-macro-metavars-in-private-macros`]: https://doc.rust-lang.org/clippy/lint_configuration.html#warn-unsafe-macro-metavars-in-private-macros - diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index e3708bc48539..000000000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,3 +0,0 @@ -# The Rust Code of Conduct - -The Code of Conduct for this repository [can be found online](https://www.rust-lang.org/conduct.html). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index b1a59238c826..000000000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,280 +0,0 @@ -# Contributing to Clippy - -Hello fellow Rustacean! Great to see your interest in compiler internals and lints! - -**First**: if you're unsure or afraid of _anything_, just ask or submit the issue or pull request anyway. You won't be -yelled at for giving it your best effort. The worst that can happen is that you'll be politely asked to change -something. We appreciate any sort of contributions, and don't want a wall of rules to get in the way of that. - -Clippy welcomes contributions from everyone. There are many ways to contribute to Clippy and the following document -explains how you can contribute and how to get started. If you have any questions about contributing or need help with -anything, feel free to ask questions on issues or visit the `#clippy` on [Zulip]. - -All contributors are expected to follow the [Rust Code of Conduct]. - -- [Contributing to Clippy](#contributing-to-clippy) - - [The Clippy book](#the-clippy-book) - - [High level approach](#high-level-approach) - - [Finding something to fix/improve](#finding-something-to-fiximprove) - - [Getting code-completion for rustc internals to work](#getting-code-completion-for-rustc-internals-to-work) - - [IntelliJ Rust](#intellij-rust) - - [Rust Analyzer](#rust-analyzer) - - [How Clippy works](#how-clippy-works) - - [Issue and PR triage](#issue-and-pr-triage) - - [Bors and Homu](#bors-and-homu) - - [Contributions](#contributions) - - [License](#license) - -[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/clippy -[Rust Code of Conduct]: https://www.rust-lang.org/policies/code-of-conduct - -## The Clippy book - -If you're new to Clippy and don't know where to start, the [Clippy book] includes -a [developer guide] and is a good place to start your journey. - -[Clippy book]: https://doc.rust-lang.org/nightly/clippy/index.html -[developer guide]: https://doc.rust-lang.org/nightly/clippy/development/index.html - -## High level approach - -1. Find something to fix/improve -2. Change code (likely some file in `clippy_lints/src/`) -3. Follow the instructions in the [Basics docs](book/src/development/basics.md) - to get set up -4. Run `cargo test` in the root directory and wiggle code until it passes -5. Open a PR (also can be done after 2. if you run into problems) - -## Finding something to fix/improve - -All issues on Clippy are mentored, if you want help simply ask someone from the -Clippy team directly by mentioning them in the issue or over on [Zulip]. All -currently active team members can be found -[here](https://github.com/rust-lang/rust-clippy/blob/master/triagebot.toml#L18) - -Some issues are easier than others. The [`good-first-issue`] label can be used to find the easy -issues. You can use `@rustbot claim` to assign the issue to yourself. - -There are also some abandoned PRs, marked with [`S-inactive-closed`]. -Pretty often these PRs are nearly completed and just need some extra steps -(formatting, addressing review comments, ...) to be merged. If you want to -complete such a PR, please leave a comment in the PR and open a new one based -on it. - -Issues marked [`T-AST`] involve simple matching of the syntax tree structure, -and are generally easier than [`T-middle`] issues, which involve types -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 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 [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. -Note that [`E-medium`] issues may require some knowledge of Clippy internals or some -debugging to find the actual problem behind the issue. - -[`T-middle`] issues can be more involved and require verifying types. The [`ty`] module contains a -lot of methods that are useful, though one of the most useful would be `expr_ty` (gives the type of -an AST expression). `match_def_path()` in Clippy's `utils` module can also be useful. - -[`good-first-issue`]: https://github.com/rust-lang/rust-clippy/labels/good-first-issue -[`S-inactive-closed`]: https://github.com/rust-lang/rust-clippy/pulls?q=is%3Aclosed+label%3AS-inactive-closed -[`T-AST`]: https://github.com/rust-lang/rust-clippy/labels/T-AST -[`T-middle`]: https://github.com/rust-lang/rust-clippy/labels/T-middle -[`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/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 - -## Getting code-completion for rustc internals to work - -### IntelliJ Rust -Unfortunately, [`IntelliJ Rust`][IntelliJ_rust_homepage] does not (yet?) understand how Clippy uses compiler-internals -using `extern crate` and it also needs to be able to read the source files of the rustc-compiler which are not -available via a `rustup` component at the time of writing. -To work around this, you need to have a copy of the [rustc-repo][rustc_repo] available which can be obtained via -`git clone https://github.com/rust-lang/rust/`. -Then you can run a `cargo dev` command to automatically make Clippy use the rustc-repo via path-dependencies -which `IntelliJ Rust` will be able to understand. -Run `cargo dev setup intellij --repo-path ` where `` is a path to the rustc repo -you just cloned. -The command will add path-dependencies pointing towards rustc-crates inside the rustc repo to -Clippy's `Cargo.toml`s and should allow `IntelliJ Rust` to understand most of the types that Clippy uses. -Just make sure to remove the dependencies again before finally making a pull request! - -[rustc_repo]: https://github.com/rust-lang/rust/ -[IntelliJ_rust_homepage]: https://intellij-rust.github.io/ - -### Rust Analyzer -For [`rust-analyzer`][ra_homepage] to work correctly make sure that in the `rust-analyzer` configuration you set - -```json -{ "rust-analyzer.rustc.source": "discover" } -``` - -You should be able to see information on things like `Expr` or `EarlyContext` now if you hover them, also -a lot more type hints. - -To have `rust-analyzer` also work in the `clippy_dev` and `lintcheck` crates, add the following configuration - -```json -{ - "rust-analyzer.linkedProjects": [ - "./Cargo.toml", - "clippy_dev/Cargo.toml", - "lintcheck/Cargo.toml", - ] -} -``` - -[ra_homepage]: https://rust-analyzer.github.io/ - -## How Clippy works - -[`clippy_lints/src/lib.rs`][lint_crate_entry] imports all the different lint modules and registers in the [`LintStore`]. -For example, the [`else_if_without_else`][else_if_without_else] lint is registered like this: - -```rust -// ./clippy_lints/src/lib.rs - -// ... -pub mod else_if_without_else; -// ... - -pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { - // ... - store.register_early_pass(|| Box::new(else_if_without_else::ElseIfWithoutElse)); - // ... -} -``` - -The [`rustc_lint::LintStore`][`LintStore`] provides two methods to register lints: -[register_early_pass][reg_early_pass] and [register_late_pass][reg_late_pass]. Both take an object -that implements an [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass] respectively. This is done in -every single lint. It's worth noting that the majority of `clippy_lints/src/lib.rs` is autogenerated by `cargo dev -update_lints`. When you are writing your own lint, you can use that script to save you some time. - -```rust -// ./clippy_lints/src/else_if_without_else.rs - -use rustc_lint::{EarlyLintPass, EarlyContext}; - -// ... - -pub struct ElseIfWithoutElse; - -// ... - -impl EarlyLintPass for ElseIfWithoutElse { - // ... the functions needed, to make the lint work -} -``` - -The difference between `EarlyLintPass` and `LateLintPass` is that the methods of the `EarlyLintPass` trait only provide -AST information. The methods of the `LateLintPass` trait are executed after type checking and contain type information -via the `LateContext` parameter. - -That's why the `else_if_without_else` example uses the `register_early_pass` function. Because the -[actual lint logic][else_if_without_else] does not depend on any type information. - -[lint_crate_entry]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/lib.rs -[else_if_without_else]: https://github.com/rust-lang/rust-clippy/blob/4253aa7137cb7378acc96133c787e49a345c2b3c/clippy_lints/src/else_if_without_else.rs -[`LintStore`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LintStore.html -[reg_early_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LintStore.html#method.register_early_pass -[reg_late_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LintStore.html#method.register_late_pass -[early_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.EarlyLintPass.html -[late_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html - -## Issue and PR triage - -Clippy is following the [Rust triage procedure][triage] for issues and pull -requests. - -However, we are a smaller project with all contributors being volunteers -currently. Between writing new lints, fixing issues, reviewing pull requests and -responding to issues there may not always be enough time to stay on top of it -all. - -Our highest priority is fixing [crashes][l-crash] and [bugs][l-bug], for example -an ICE in a popular crate that many other crates depend on. We don't -want Clippy to crash on your code and we want it to be as reliable as the -suggestions from Rust compiler errors. - -We have prioritization labels and a sync-blocker label, which are described below. -- [P-low][p-low]: Requires attention (fix/response/evaluation) by a team member but isn't urgent. -- [P-medium][p-medium]: Should be addressed by a team member until the next sync. -- [P-high][p-high]: Should be immediately addressed and will require an out-of-cycle sync or a backport. -- [L-sync-blocker][l-sync-blocker]: An issue that "blocks" a sync. -Or rather: before the sync this should be addressed, -e.g. by removing a lint again, so it doesn't hit beta/stable. - -## Bors and Homu - -We use a bot powered by [Homu][homu] to help automate testing and landing of pull -requests in Clippy. The bot's username is @bors. - -You can find the Clippy bors queue [here][homu_queue]. - -If you have @bors permissions, you can find an overview of the available -commands [here][homu_instructions]. - -[triage]: https://forge.rust-lang.org/release/triage-procedure.html -[l-crash]: https://github.com/rust-lang/rust-clippy/labels/L-crash -[l-bug]: https://github.com/rust-lang/rust-clippy/labels/L-bug -[p-low]: https://github.com/rust-lang/rust-clippy/labels/P-low -[p-medium]: https://github.com/rust-lang/rust-clippy/labels/P-medium -[p-high]: https://github.com/rust-lang/rust-clippy/labels/P-high -[l-sync-blocker]: https://github.com/rust-lang/rust-clippy/labels/L-sync-blocker -[homu]: https://github.com/rust-lang/homu -[homu_instructions]: https://bors.rust-lang.org/ -[homu_queue]: https://bors.rust-lang.org/queue/clippy - -## Contributions - -Contributions to Clippy should be made in the form of GitHub pull requests. Each pull request will -be reviewed by a core contributor (someone with permission to land patches) and either landed in the -main tree or given feedback for changes that would be required. - -All PRs should include a `changelog` entry with a short comment explaining the change. The rule of thumb is basically, -"what do you believe is important from an outsider's perspective?" Often, PRs are only related to a single property of a -lint, and then it's good to mention that one. Otherwise, it's better to include too much detail than too little. - -Clippy's [changelog] is created from these comments. Every release, someone gets all commits from bors with a -`changelog: XYZ` entry and combines them into the changelog. This is a manual process. - -Examples: -- New lint - ``` - changelog: new lint: [`missing_trait_methods`] - ``` -- False positive fix - ``` - changelog: Fix [`unused_peekable`] false positive when peeked in a closure or called as `f(&mut peekable)` - ``` -- Purely internal change - ``` - changelog: none - ``` - -Note this it is fine for a PR to include multiple `changelog` entries, e.g.: -``` -changelog: Something 1 -changelog: Something 2 -changelog: Something 3 -``` - -[changelog]: CHANGELOG.md - -## License - -All code in this repository is under the [Apache-2.0] or the [MIT] license. - - - -[Apache-2.0]: https://www.apache.org/licenses/LICENSE-2.0 -[MIT]: https://opensource.org/licenses/MIT diff --git a/COPYRIGHT b/COPYRIGHT deleted file mode 100644 index 219693d63d97..000000000000 --- a/COPYRIGHT +++ /dev/null @@ -1,11 +0,0 @@ -// REUSE-IgnoreStart - -Copyright 2014-2024 The Rust Project Developers - -Licensed under the Apache License, Version 2.0 or the MIT license -, at your -option. All files in the project carrying such notice may not be -copied, modified, or distributed except according to those terms. - -// REUSE-IgnoreEnd diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index b48f3ab3919c..000000000000 --- a/Cargo.toml +++ /dev/null @@ -1,65 +0,0 @@ -[package] -name = "clippy" -version = "0.1.80" -description = "A bunch of helpful lints to avoid common pitfalls in Rust" -repository = "https://github.com/rust-lang/rust-clippy" -readme = "README.md" -license = "MIT OR Apache-2.0" -keywords = ["clippy", "lint", "plugin"] -categories = ["development-tools", "development-tools::cargo-plugins"] -build = "build.rs" -edition = "2021" -publish = false - -[[bin]] -name = "cargo-clippy" -test = false -path = "src/main.rs" - -[[bin]] -name = "clippy-driver" -path = "src/driver.rs" - -[dependencies] -clippy_config = { path = "clippy_config" } -clippy_lints = { path = "clippy_lints" } -rustc_tools_util = "0.3.0" -tempfile = { version = "3.3", optional = true } -termize = "0.1" -color-print = "0.3.4" -anstream = "0.6.0" - -[dev-dependencies] -ui_test = "0.23" -regex = "1.5.5" -toml = "0.7.3" -walkdir = "2.3" -# This is used by the `collect-metadata` alias. -filetime = "0.2.9" -itertools = "0.12" - -# UI test dependencies -clippy_utils = { path = "clippy_utils" } -if_chain = "1.0" -quote = "1.0.25" -serde = { version = "1.0.145", features = ["derive"] } -syn = { version = "2.0", features = ["full"] } -futures = "0.3" -parking_lot = "0.12" -tokio = { version = "1", features = ["io-util"] } - -[build-dependencies] -rustc_tools_util = "0.3.0" - -[features] -deny-warnings = ["clippy_lints/deny-warnings"] -integration = ["tempfile"] -internal = ["clippy_lints/internal", "tempfile"] - -[package.metadata.rust-analyzer] -# This package uses #[feature(rustc_private)] -rustc_private = true - -[[test]] -name = "compile-test" -harness = false diff --git a/LICENSE-APACHE b/LICENSE-APACHE deleted file mode 100644 index 506582c31d6d..000000000000 --- a/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright 2014-2024 The Rust Project Developers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/LICENSE-MIT b/LICENSE-MIT deleted file mode 100644 index 6d8ee9afb616..000000000000 --- a/LICENSE-MIT +++ /dev/null @@ -1,27 +0,0 @@ -MIT License - -Copyright (c) 2014-2024 The Rust Project Developers - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md deleted file mode 100644 index fa18447090c1..000000000000 --- a/README.md +++ /dev/null @@ -1,289 +0,0 @@ -# Clippy - -[![Clippy Test](https://github.com/rust-lang/rust-clippy/workflows/Clippy%20Test%20(bors)/badge.svg?branch=auto&event=push)](https://github.com/rust-lang/rust-clippy/actions?query=workflow%3A%22Clippy+Test+(bors)%22+event%3Apush+branch%3Aauto) -[![License: MIT OR Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](#license) - -A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. - -[There are over 700 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) - -Lints are divided into categories, each with a default [lint level](https://doc.rust-lang.org/rustc/lints/levels.html). -You can choose how much Clippy is supposed to ~~annoy~~ help you by changing the lint level by category. - -| Category | Description | Default level | -|-----------------------|-------------------------------------------------------------------------------------|---------------| -| `clippy::all` | all lints that are on by default (correctness, suspicious, style, complexity, perf) | **warn/deny** | -| `clippy::correctness` | code that is outright wrong or useless | **deny** | -| `clippy::suspicious` | code that is most likely wrong or useless | **warn** | -| `clippy::style` | code that should be written in a more idiomatic way | **warn** | -| `clippy::complexity` | code that does something simple but in a complex way | **warn** | -| `clippy::perf` | code that can be written to run faster | **warn** | -| `clippy::pedantic` | lints which are rather strict or have occasional false positives | allow | -| `clippy::restriction` | lints which prevent the use of language and library features[^restrict] | allow | -| `clippy::nursery` | new lints that are still under development | allow | -| `clippy::cargo` | lints for the cargo manifest | allow | - -More to come, please [file an issue](https://github.com/rust-lang/rust-clippy/issues) if you have ideas! - -The `restriction` category should, *emphatically*, not be enabled as a whole. The contained -lints may lint against perfectly reasonable code, may not have an alternative suggestion, -and may contradict any other lints (including other categories). Lints should be considered -on a case-by-case basis before enabling. - -[^restrict]: Some use cases for `restriction` lints include: - - Strict coding styles (e.g. [`clippy::else_if_without_else`]). - - Additional restrictions on CI (e.g. [`clippy::todo`]). - - Preventing panicking in certain functions (e.g. [`clippy::unwrap_used`]). - - Running a lint only on a subset of code (e.g. `#[forbid(clippy::float_arithmetic)]` on a module). - -[`clippy::else_if_without_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else -[`clippy::todo`]: https://rust-lang.github.io/rust-clippy/master/index.html#todo -[`clippy::unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used - ---- - -Table of contents: - -* [Usage instructions](#usage) -* [Configuration](#configuration) -* [Contributing](#contributing) -* [License](#license) - -## Usage - -Below are instructions on how to use Clippy as a cargo subcommand, -in projects that do not use cargo, or in Travis CI. - -### As a cargo subcommand (`cargo clippy`) - -One way to use Clippy is by installing Clippy through rustup as a cargo -subcommand. - -#### Step 1: Install Rustup - -You can install [Rustup](https://rustup.rs/) on supported platforms. This will help -us install Clippy and its dependencies. - -If you already have Rustup installed, update to ensure you have the latest -Rustup and compiler: - -```terminal -rustup update -``` - -#### Step 2: Install Clippy - -Once you have rustup and the latest stable release (at least Rust 1.29) installed, run the following command: - -```terminal -rustup component add clippy -``` - -If it says that it can't find the `clippy` component, please run `rustup self update`. - -#### Step 3: Run Clippy - -Now you can run Clippy by invoking the following command: - -```terminal -cargo clippy -``` - -#### Automatically applying Clippy suggestions - -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 -``` - -#### Workspaces - -All the usual workspace options should work with Clippy. For example the following command -will run Clippy on the `example` crate: - -```terminal -cargo clippy -p example -``` - -As with `cargo check`, this includes dependencies that are members of the workspace, like path dependencies. -If you want to run Clippy **only** on the given crate, use the `--no-deps` option like this: - -```terminal -cargo clippy -p example -- --no-deps -``` - -### Using `clippy-driver` - -Clippy can also be used in projects that do not use cargo. To do so, run `clippy-driver` -with the same arguments you use for `rustc`. For example: - -```terminal -clippy-driver --edition 2018 -Cpanic=abort foo.rs -``` - -Note that `clippy-driver` is designed for running Clippy only and should not be used as a general -replacement for `rustc`. `clippy-driver` may produce artifacts that are not optimized as expected, -for example. - -### Travis CI - -You can add Clippy to Travis CI in the same way you use it locally: - -```yaml -language: rust -rust: - - stable - - beta -before_script: - - rustup component add clippy -script: - - cargo clippy - # if you want the build job to fail when encountering warnings, use - - cargo clippy -- -D warnings - # in order to also check tests and non-default crate features, use - - cargo clippy --all-targets --all-features -- -D warnings - - cargo test - # etc. -``` - -Note that adding `-D warnings` will cause your build to fail if **any** warnings are found in your code. -That includes warnings found by rustc (e.g. `dead_code`, etc.). If you want to avoid this and only cause -an error for Clippy warnings, use `#![deny(clippy::all)]` in your code or `-D clippy::all` on the command -line. (You can swap `clippy::all` with the specific lint category you are targeting.) - -## Configuration - -### Allowing/denying lints - -You can add options to your code to `allow`/`warn`/`deny` Clippy lints: - -* the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy::all)]`). - Note that `rustc` has additional [lint groups](https://doc.rust-lang.org/rustc/lints/groups.html). - -* all lints using both the `clippy` and `clippy::pedantic` lint groups (`#![deny(clippy::all)]`, - `#![deny(clippy::pedantic)]`). Note that `clippy::pedantic` contains some very aggressive - lints prone to false positives. - -* only some lints (`#![deny(clippy::single_match, clippy::box_vec)]`, etc.) - -* `allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc. - -Note: `allow` means to suppress the lint for your code. With `warn` the lint -will only emit a warning, while with `deny` the lint will emit an error, when -triggering for your code. An error causes clippy to exit with an error code, so -is useful in scripts like CI/CD. - -If you do not want to include your lint levels in your code, you can globally -enable/disable lints by passing extra flags to Clippy during the run: - -To allow `lint_name`, run - -```terminal -cargo clippy -- -A clippy::lint_name -``` - -And to warn on `lint_name`, run - -```terminal -cargo clippy -- -W clippy::lint_name -``` - -This also works with lint groups. For example, you -can run Clippy with warnings for all lints enabled: - -```terminal -cargo clippy -- -W clippy::pedantic -``` - -If you care only about a single lint, you can allow all others and then explicitly warn on -the lint(s) you are interested in: - -```terminal -cargo clippy -- -A clippy::all -W clippy::useless_format -W clippy::... -``` - -### Configure the behavior of some lints - -Some lints can be configured in a TOML file named `clippy.toml` or `.clippy.toml`. It contains a basic `variable = -value` mapping e.g. - -```toml -avoid-breaking-exported-api = false -disallowed-names = ["toto", "tata", "titi"] -``` - -The [table of configurations](https://doc.rust-lang.org/nightly/clippy/lint_configuration.html) -contains all config values, their default, and a list of lints they affect. -Each [configurable lint](https://rust-lang.github.io/rust-clippy/master/index.html#Configuration) -, also contains information about these values. - -For configurations that are a list type with default values such as -[disallowed-names](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names), -you can use the unique value `".."` to extend the default values instead of replacing them. - -```toml -# default of disallowed-names is ["foo", "baz", "quux"] -disallowed-names = ["bar", ".."] # -> ["bar", "foo", "baz", "quux"] -``` - -> **Note** -> -> `clippy.toml` or `.clippy.toml` cannot be used to allow/deny lints. - -To deactivate the “for further information visit *lint-link*” message you can -define the `CLIPPY_DISABLE_DOCS_LINKS` environment variable. - -### Specifying the minimum supported Rust version - -Projects that intend to support old versions of Rust can disable lints pertaining to newer features by -specifying the minimum supported Rust version (MSRV) in the clippy configuration file. - -```toml -msrv = "1.30.0" -``` - -Alternatively, the [`rust-version` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-rust-version-field) -in the `Cargo.toml` can be used. - -```toml -# Cargo.toml -rust-version = "1.30" -``` - -The MSRV can also be specified as an attribute, like below. - -```rust,ignore -#![feature(custom_inner_attributes)] -#![clippy::msrv = "1.30.0"] - -fn main() { - ... -} -``` - -You can also omit the patch version when specifying the MSRV, so `msrv = 1.30` -is equivalent to `msrv = 1.30.0`. - -Note: `custom_inner_attributes` is an unstable feature, so it has to be enabled explicitly. - -Lints that recognize this configuration option can be found [here](https://rust-lang.github.io/rust-clippy/master/index.html#msrv) - -## Contributing - -If you want to contribute to Clippy, you can find more information in [CONTRIBUTING.md](https://github.com/rust-lang/rust-clippy/blob/master/CONTRIBUTING.md). - -## License - - - -Copyright 2014-2024 The Rust Project Developers - -Licensed under the Apache License, Version 2.0 or the MIT license -, at your -option. Files in the project may not be -copied, modified, or distributed except according to those terms. - - diff --git a/book/README.md b/book/README.md deleted file mode 100644 index 6d67f80ff256..000000000000 --- a/book/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# Clippy Book - -This is the source for the Clippy Book. See the -[book](src/development/infrastructure/book.md) for more information. diff --git a/book/book.toml b/book/book.toml deleted file mode 100644 index 93b6641f7e1e..000000000000 --- a/book/book.toml +++ /dev/null @@ -1,28 +0,0 @@ -[book] -authors = ["The Rust Clippy Developers"] -language = "en" -multilingual = false -src = "src" -title = "Clippy Documentation" - -[rust] -edition = "2018" - -[output.html] -edit-url-template = "https://github.com/rust-lang/rust-clippy/edit/master/book/{path}" -git-repository-url = "https://github.com/rust-lang/rust-clippy/tree/master/book" -mathjax-support = true -site-url = "/rust-clippy/" - -[output.html.playground] -editable = true -line-numbers = true - -[output.html.search] -boost-hierarchy = 2 -boost-paragraph = 1 -boost-title = 2 -expand = true -heading-split-level = 2 -limit-results = 20 -use-boolean-and = true diff --git a/book/src/README.md b/book/src/README.md deleted file mode 100644 index 7bdfb97c3acf..000000000000 --- a/book/src/README.md +++ /dev/null @@ -1,44 +0,0 @@ -# Clippy - -[![Clippy Test](https://github.com/rust-lang/rust-clippy/workflows/Clippy%20Test%20(bors)/badge.svg?branch=auto&event=push)](https://github.com/rust-lang/rust-clippy/actions?query=workflow%3A%22Clippy+Test+(bors)%22+event%3Apush+branch%3Aauto) -[![License: MIT OR Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](https://github.com/rust-lang/rust-clippy#license) - -A collection of lints to catch common mistakes and improve your -[Rust](https://github.com/rust-lang/rust) code. - -[There are over 700 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) - -Lints are divided into categories, each with a default [lint -level](https://doc.rust-lang.org/rustc/lints/levels.html). You can choose how -much Clippy is supposed to ~~annoy~~ help you by changing the lint level by -category. - -| Category | Description | Default level | -|-----------------------|-------------------------------------------------------------------------------------|---------------| -| `clippy::all` | all lints that are on by default (correctness, suspicious, style, complexity, perf) | **warn/deny** | -| `clippy::correctness` | code that is outright wrong or useless | **deny** | -| `clippy::suspicious` | code that is most likely wrong or useless | **warn** | -| `clippy::style` | code that should be written in a more idiomatic way | **warn** | -| `clippy::complexity` | code that does something simple but in a complex way | **warn** | -| `clippy::perf` | code that can be written to run faster | **warn** | -| `clippy::pedantic` | lints which are rather strict or have occasional false positives | allow | -| `clippy::restriction` | lints which prevent the use of language and library features[^restrict] | allow | -| `clippy::nursery` | new lints that are still under development | allow | -| `clippy::cargo` | lints for the cargo manifest | allow | - -More to come, please [file an issue](https://github.com/rust-lang/rust-clippy/issues) if you have ideas! - -The `restriction` category should, *emphatically*, not be enabled as a whole. The contained -lints may lint against perfectly reasonable code, may not have an alternative suggestion, -and may contradict any other lints (including other categories). Lints should be considered -on a case-by-case basis before enabling. - -[^restrict]: Some use cases for `restriction` lints include: - - Strict coding styles (e.g. [`clippy::else_if_without_else`]). - - Additional restrictions on CI (e.g. [`clippy::todo`]). - - Preventing panicking in certain functions (e.g. [`clippy::unwrap_used`]). - - Running a lint only on a subset of code (e.g. `#[forbid(clippy::float_arithmetic)]` on a module). - -[`clippy::else_if_without_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else -[`clippy::todo`]: https://rust-lang.github.io/rust-clippy/master/index.html#todo -[`clippy::unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md deleted file mode 100644 index be13fcbe260f..000000000000 --- a/book/src/SUMMARY.md +++ /dev/null @@ -1,35 +0,0 @@ -# Summary - -[Introduction](README.md) - -- [Installation](installation.md) -- [Usage](usage.md) -- [Configuration](configuration.md) - - [Lint Configuration](lint_configuration.md) -- [Clippy's Lints](lints.md) -- [Continuous Integration](continuous_integration/README.md) - - [GitHub Actions](continuous_integration/github_actions.md) - - [GitLab CI](continuous_integration/gitlab.md) - - [Travis CI](continuous_integration/travis.md) -- [Development](development/README.md) - - [Basics](development/basics.md) - - [Adding Lints](development/adding_lints.md) - - [Defining Lints](development/defining_lints.md) - - [Writing tests](development/writing_tests.md) - - [Lint Passes](development/lint_passes.md) - - [Emitting lints](development/emitting_lints.md) - - [Type Checking](development/type_checking.md) - - [Trait Checking](development/trait_checking.md) - - [Method Checking](development/method_checking.md) - - [Macro Expansions](development/macro_expansions.md) - - [Common Tools](development/common_tools_writing_lints.md) - - [Infrastructure](development/infrastructure/README.md) - - [Syncing changes between Clippy and rust-lang/rust](development/infrastructure/sync.md) - - [Backporting Changes](development/infrastructure/backport.md) - - [Updating the Changelog](development/infrastructure/changelog_update.md) - - [Release a New Version](development/infrastructure/release.md) - - [The Clippy Book](development/infrastructure/book.md) - - [Proposals](development/proposals/README.md) - - [Roadmap 2021](development/proposals/roadmap-2021.md) - - [Syntax Tree Patterns](development/proposals/syntax-tree-patterns.md) - - [The Team](development/the_team.md) diff --git a/book/src/configuration.md b/book/src/configuration.md deleted file mode 100644 index 9eb067abd91e..000000000000 --- a/book/src/configuration.md +++ /dev/null @@ -1,143 +0,0 @@ -# Configuring Clippy - -> **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`, 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 -disallowed-names = ["toto", "tata", "titi"] -``` - -The [table of configurations](./lint_configuration.md) -contains all config values, their default, and a list of lints they affect. -Each [configurable lint](https://rust-lang.github.io/rust-clippy/master/index.html#Configuration) -, also contains information about these values. - -For configurations that are a list type with default values such as -[disallowed-names](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names), -you can use the unique value `".."` to extend the default values instead of replacing them. - -```toml -# default of disallowed-names is ["foo", "baz", "quux"] -disallowed-names = ["bar", ".."] # -> ["bar", "foo", "baz", "quux"] -``` - -To deactivate the "for further information visit *lint-link*" message you can define the `CLIPPY_DISABLE_DOCS_LINKS` -environment variable. - -### Allowing/Denying Lints - -#### Attributes in Code - -You can add attributes to your code to `allow`/`warn`/`deny` Clippy lints: - -* the whole set of `warn`-by-default lints using the `clippy` lint group (`#![allow(clippy::all)]`) - -* all lints using both the `clippy` and `clippy::pedantic` lint groups (`#![warn(clippy::all, clippy::pedantic)]`. Note - that `clippy::pedantic` contains some very aggressive lints prone to false positives. - -* only some lints (`#![deny(clippy::single_match, clippy::box_vec)]`, etc.) - -* `allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc. - -Note: `allow` means to suppress the lint for your code. With `warn` the lint will only emit a warning, while with `deny` -the lint will emit an error, when triggering for your code. An error causes Clippy to exit with an error code, so is -most useful in scripts used in CI/CD. - -#### Command Line Flags - -If you do not want to include your lint levels in the code, you can globally enable/disable lints by passing extra flags -to Clippy during the run: - -To allow `lint_name`, run - -```terminal -cargo clippy -- -A clippy::lint_name -``` - -And to warn on `lint_name`, run - -```terminal -cargo clippy -- -W clippy::lint_name -``` - -This also works with lint groups. For example, you can run Clippy with warnings for all pedantic lints enabled: - -```terminal -cargo clippy -- -W clippy::pedantic -``` - -If you care only about a certain lints, you can allow all others and then explicitly warn on the lints you are -interested in: - -```terminal -cargo clippy -- -A clippy::all -W clippy::useless_format -W clippy::... -``` - -#### Lints Section in `Cargo.toml` - -Finally, lints can be allowed/denied using [the lints -section](https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-lints-section)) in the `Cargo.toml` file: - -To deny `clippy::enum_glob_use`, put the following in the `Cargo.toml`: - -```toml -[lints.clippy] -enum_glob_use = "deny" -``` - -For more details and options, refer to the Cargo documentation. - -### Specifying the minimum supported Rust version - -Projects that intend to support old versions of Rust can disable lints pertaining to newer features by specifying the -minimum supported Rust version (MSRV) in the clippy configuration file. - -```toml -msrv = "1.30.0" -``` - -The MSRV can also be specified as an attribute, like below. - -```rust,ignore -#![feature(custom_inner_attributes)] -#![clippy::msrv = "1.30.0"] - -fn main() { - ... -} -``` - -You can also omit the patch version when specifying the MSRV, so `msrv = 1.30` -is equivalent to `msrv = 1.30.0`. - -Note: `custom_inner_attributes` is an unstable feature, so it has to be enabled explicitly. - -Lints that recognize this configuration option can be -found [here](https://rust-lang.github.io/rust-clippy/master/index.html#msrv) - -### Disabling evaluation of certain code - -> **Note:** This should only be used in cases where other solutions, like `#[allow(clippy::all)]`, are not sufficient. - -Very rarely, you may wish to prevent Clippy from evaluating certain sections of code entirely. You can do this with -[conditional compilation](https://doc.rust-lang.org/reference/conditional-compilation.html) by checking that the -`clippy` cfg is not set. You may need to provide a stub so that the code compiles: - -```rust -#[cfg(not(clippy)] -include!(concat!(env!("OUT_DIR"), "/my_big_function-generated.rs")); - -#[cfg(clippy)] -fn my_big_function(_input: &str) -> Option { - None -} -``` diff --git a/book/src/continuous_integration/README.md b/book/src/continuous_integration/README.md deleted file mode 100644 index e5c3673bde45..000000000000 --- a/book/src/continuous_integration/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Continuous Integration - -It is recommended to run Clippy on CI with `-Dwarnings`, so that Clippy lints -prevent CI from passing. To enforce errors on warnings on all `cargo` commands -not just `cargo clippy`, you can set the env var `RUSTFLAGS="-Dwarnings"`. - -We recommend to use Clippy from the same toolchain, that you use for compiling -your crate for maximum compatibility. E.g. if your crate is compiled with the -`stable` toolchain, you should also use `stable` Clippy. - -> _Note:_ New Clippy lints are first added to the `nightly` toolchain. If you -> want to help with improving Clippy and have CI resources left, please consider -> adding a `nightly` Clippy check to your CI and report problems like false -> positives back to us. With that we can fix bugs early, before they can get to -> stable. - -This chapter will give an overview on how to use Clippy on different popular CI -providers. diff --git a/book/src/continuous_integration/github_actions.md b/book/src/continuous_integration/github_actions.md deleted file mode 100644 index b588c8f0f02c..000000000000 --- a/book/src/continuous_integration/github_actions.md +++ /dev/null @@ -1,21 +0,0 @@ -# GitHub Actions - -GitHub hosted runners using the latest stable version of Rust have Clippy pre-installed. -It is as simple as running `cargo clippy` to run lints against the codebase. - -```yml -on: push -name: Clippy check - -# Make sure CI fails on all warnings, including Clippy lints -env: - RUSTFLAGS: "-Dwarnings" - -jobs: - clippy_check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Run Clippy - run: cargo clippy --all-targets --all-features -``` diff --git a/book/src/continuous_integration/gitlab.md b/book/src/continuous_integration/gitlab.md deleted file mode 100644 index bb3ef246c2fa..000000000000 --- a/book/src/continuous_integration/gitlab.md +++ /dev/null @@ -1,16 +0,0 @@ -# GitLab CI - -You can add Clippy to GitLab CI by using the latest stable [rust docker image](https://hub.docker.com/_/rust), -as it is shown in the `.gitlab-ci.yml` CI configuration file below, - -```yml -# Make sure CI fails on all warnings, including Clippy lints -variables: - RUSTFLAGS: "-Dwarnings" - -clippy_check: - image: rust:latest - script: - - rustup component add clippy - - cargo clippy --all-targets --all-features -``` diff --git a/book/src/continuous_integration/travis.md b/book/src/continuous_integration/travis.md deleted file mode 100644 index 85b9ed53daea..000000000000 --- a/book/src/continuous_integration/travis.md +++ /dev/null @@ -1,20 +0,0 @@ -# Travis CI - -You can add Clippy to Travis CI in the same way you use it locally: - -```yml -language: rust -rust: - - stable - - beta -before_script: - - rustup component add clippy -script: - - cargo clippy - # if you want the build job to fail when encountering warnings, use - - cargo clippy -- -D warnings - # in order to also check tests and non-default crate features, use - - cargo clippy --all-targets --all-features -- -D warnings - - cargo test - # etc. -``` diff --git a/book/src/development/README.md b/book/src/development/README.md deleted file mode 100644 index 8f09f66f5958..000000000000 --- a/book/src/development/README.md +++ /dev/null @@ -1,65 +0,0 @@ -# Clippy Development - -Hello fellow Rustacean! If you made it here, you're probably interested in -making Clippy better by contributing to it. In that case, welcome to the -project! - -> _Note:_ If you're just interested in using Clippy, there's nothing to see from -> this point onward, and you should return to one of the earlier chapters. - -## Getting started - -If this is your first time contributing to Clippy, you should first read the -[Basics docs](basics.md). This will explain the basics on how to get the source -code and how to compile and test the code. - -## Additional Readings for Beginners - -If a dear reader of this documentation has never taken a class on compilers -and interpreters, it might be confusing as to why AST level deals with only -the language's syntax. And some readers might not even understand what lexing, -parsing, and AST mean. - -This documentation serves by no means as a crash course on compilers or language design. -And for details specifically related to Rust, the [Rustc Development Guide][rustc_dev_guide] -is a far better choice to peruse. - -The [Syntax and AST][ast] chapter and the [High-Level IR][hir] chapter are -great introduction to the concepts mentioned in this chapter. - -Some readers might also find the [introductory chapter][map_of_territory] of -Robert Nystrom's _Crafting Interpreters_ a helpful overview of compiled and -interpreted languages before jumping back to the Rustc guide. - -## Writing code - -If you have done the basic setup, it's time to start hacking. - -The [Adding lints](adding_lints.md) chapter is a walk through on how to add a -new lint to Clippy. This is also interesting if you just want to fix a lint, -because it also covers how to test lints and gives an overview of the bigger -picture. - -If you want to add a new lint or change existing ones apart from bugfixing, it's -also a good idea to give the [stability guarantees][rfc_stability] and -[lint categories][rfc_lint_cats] sections of the [Clippy 1.0 RFC][clippy_rfc] a -quick read. The lint categories are also described [earlier in this -book](../lints.md). - -> _Note:_ Some higher level things about contributing to Clippy are still -> covered in the [`CONTRIBUTING.md`] document. Some of those will be moved to -> the book over time, like: -> - Finding something to fix -> - IDE setup -> - High level overview on how Clippy works -> - Triage procedure -> - Bors and Homu - -[ast]: https://rustc-dev-guide.rust-lang.org/syntax-intro.html -[hir]: https://rustc-dev-guide.rust-lang.org/hir.html -[rustc_dev_guide]: https://rustc-dev-guide.rust-lang.org/ -[map_of_territory]: https://craftinginterpreters.com/a-map-of-the-territory.html -[clippy_rfc]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md -[rfc_stability]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#stability-guarantees -[rfc_lint_cats]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#lint-audit-and-categories -[`CONTRIBUTING.md`]: https://github.com/rust-lang/rust-clippy/blob/master/CONTRIBUTING.md diff --git a/book/src/development/adding_lints.md b/book/src/development/adding_lints.md deleted file mode 100644 index 415022612caa..000000000000 --- a/book/src/development/adding_lints.md +++ /dev/null @@ -1,796 +0,0 @@ -# Adding a new lint - -You are probably here because you want to add a new lint to Clippy. If this is -the first time you're contributing to Clippy, this document guides you through -creating an example lint from scratch. - -To get started, we will create a lint that detects functions called `foo`, -because that's clearly a non-descriptive name. - -- [Adding a new lint](#adding-a-new-lint) - - [Setup](#setup) - - [Getting Started](#getting-started) - - [Defining Our Lint](#defining-our-lint) - - [Standalone](#standalone) - - [Specific Type](#specific-type) - - [Tests Location](#tests-location) - - [Testing](#testing) - - [Cargo lints](#cargo-lints) - - [Rustfix tests](#rustfix-tests) - - [Testing manually](#testing-manually) - - [Lint declaration](#lint-declaration) - - [Lint registration](#lint-registration) - - [Lint passes](#lint-passes) - - [Emitting a lint](#emitting-a-lint) - - [Adding the lint logic](#adding-the-lint-logic) - - [Specifying the lint's minimum supported Rust version (MSRV)](#specifying-the-lints-minimum-supported-rust-version-msrv) - - [Author lint](#author-lint) - - [Print HIR lint](#print-hir-lint) - - [Documentation](#documentation) - - [Running rustfmt](#running-rustfmt) - - [Debugging](#debugging) - - [Conflicting lints](#conflicting-lints) - - [PR Checklist](#pr-checklist) - - [Adding configuration to a lint](#adding-configuration-to-a-lint) - - [Cheat Sheet](#cheat-sheet) - -## Setup - -See the [Basics](basics.md#get-the-code) documentation. - -## Getting Started - -There is a bit of boilerplate code that needs to be set up when creating a new -lint. Fortunately, you can use the Clippy dev tools to handle this for you. We -are naming our new lint `foo_functions` (lints are generally written in snake -case), and we don't need type information, so it will have an early pass type -(more on this later). If you're unsure if the name you chose fits the lint, -take a look at our [lint naming guidelines][lint_naming]. - -## Defining Our Lint -To get started, there are two ways to define our lint. - -### Standalone -Command: `cargo dev new_lint --name=foo_functions --pass=early --category=pedantic` -(category will default to nursery if not provided) - -This command will create a new file: `clippy_lints/src/foo_functions.rs`, as well -as [register the lint](#lint-registration). - -### Specific Type -Command: `cargo dev new_lint --name=foo_functions --type=functions --category=pedantic` - -This command will create a new file: `clippy_lints/src/{type}/foo_functions.rs`. - -Notice how this command has a `--type` flag instead of `--pass`. Unlike a standalone -definition, this lint won't be registered in the traditional sense. Instead, you will -call your lint from within the type's lint pass, found in `clippy_lints/src/{type}/mod.rs`. - -A "type" is just the name of a directory in `clippy_lints/src`, like `functions` in -the example command. These are groupings of lints with common behaviors, so if your -lint falls into one, it would be best to add it to that type. - -### Tests Location -Both commands will create a file: `tests/ui/foo_functions.rs`. For cargo lints, -two project hierarchies (fail/pass) will be created by default under `tests/ui-cargo`. - -Next, we'll open up these files and add our lint! - -## Testing - -Let's write some tests first that we can execute while we iterate on our lint. - -Clippy uses UI tests for testing. UI tests check that the output of Clippy is -exactly as expected. Each test is just a plain Rust file that contains the code -we want to check. The output of Clippy is compared against a `.stderr` file. -Note that you don't have to create this file yourself, we'll get to generating -the `.stderr` files further down. - -We start by opening the test file created at `tests/ui/foo_functions.rs`. - -Update the file with some examples to get started: - -```rust -#![allow(unused)] -#![warn(clippy::foo_functions)] - -// Impl methods -struct A; -impl A { - pub fn fo(&self) {} - pub fn foo(&self) {} - pub fn food(&self) {} -} - -// Default trait methods -trait B { - fn fo(&self) {} - fn foo(&self) {} - fn food(&self) {} -} - -// Plain functions -fn fo() {} -fn foo() {} -fn food() {} - -fn main() { - // We also don't want to lint method calls - foo(); - let a = A; - a.foo(); -} -``` - -Now we can run the test with `TESTNAME=foo_functions cargo uibless`, currently -this test is meaningless though. - -While we are working on implementing our lint, we can keep running the UI test. -That allows us to check if the output is turning into what we want by checking the -`.stderr` file that gets updated on every test run. - -Running `TESTNAME=foo_functions cargo uitest` should pass on its own. When we -commit our lint, we need to commit the generated `.stderr` files, too. In -general, you should only commit files changed by `cargo bless` for the -specific lint you are creating/editing. - -> _Note:_ you can run multiple test files by specifying a comma separated list: -> `TESTNAME=foo_functions,test2,test3`. - -### Cargo lints - -For cargo lints, the process of testing differs in that we are interested in the -`Cargo.toml` manifest file. We also need a minimal crate associated with that -manifest. - -If our new lint is named e.g. `foo_categories`, after running `cargo dev -new_lint --name=foo_categories --type=cargo --category=cargo` we will find by -default two new crates, each with its manifest file: - -* `tests/ui-cargo/foo_categories/fail/Cargo.toml`: this file should cause the - new lint to raise an error. -* `tests/ui-cargo/foo_categories/pass/Cargo.toml`: this file should not trigger - the lint. - -If you need more cases, you can copy one of those crates (under -`foo_categories`) and rename it. - -The process of generating the `.stderr` file is the same, and prepending the -`TESTNAME` variable to `cargo uitest` works too. - -## Rustfix tests - -If the lint you are working on is making use of structured suggestions, the test -will create a `.fixed` file by running [rustfix] for that test. -Rustfix will apply the suggestions -from the lint to the code of the test file and compare that to the contents of a -`.fixed` file. - -Use `cargo bless` to automatically generate the `.fixed` file while running -the tests. - -[rustfix]: https://github.com/rust-lang/rustfix - -## Testing manually - -Manually testing against an example file can be useful if you have added some -`println!`s and the test suite output becomes unreadable. To try Clippy with -your local modifications, run the following from the Clippy directory: - -```bash -cargo dev lint input.rs -``` - -To run Clippy on an existing project rather than a single file you can use - -```bash -cargo dev lint /path/to/project -``` - -Or set up a rustup toolchain that points to the local Clippy binaries - -```bash -cargo dev setup toolchain - -# Then in `/path/to/project` you can run -cargo +clippy clippy -``` - -## Lint declaration - -Let's start by opening the new file created in the `clippy_lints` crate at -`clippy_lints/src/foo_functions.rs`. That's the crate where all the lint code -is. This file has already imported some initial things we will need: - -```rust -use rustc_lint::{EarlyLintPass, EarlyContext}; -use rustc_session::declare_lint_pass; -use rustc_ast::ast::*; -``` - -The next step is to update the lint declaration. Lints are declared using the -[`declare_clippy_lint!`][declare_clippy_lint] macro, and we just need to update -the auto-generated lint declaration to have a real description, something like -this: - -```rust -declare_clippy_lint! { - /// ### What it does - /// - /// ### Why is this bad? - /// - /// ### Example - /// ```rust - /// // example code - /// ``` - #[clippy::version = "1.29.0"] - pub FOO_FUNCTIONS, - pedantic, - "function named `foo`, which is not a descriptive name" -} -``` - -* The section of lines prefixed with `///` constitutes the lint documentation - section. This is the default documentation style and will be displayed [like - this][example_lint_page]. To render and open this documentation locally in a - browser, run `cargo dev serve`. -* The `#[clippy::version]` attribute will be rendered as part of the lint - documentation. The value should be set to the current Rust version that the - lint is developed in, it can be retrieved by running `rustc -vV` in the - rust-clippy directory. The version is listed under *release*. (Use the version - without the `-nightly`) suffix. -* `FOO_FUNCTIONS` is the name of our lint. Be sure to follow the [lint naming - guidelines][lint_naming] here when naming your lint. In short, the name should - state the thing that is being checked for and read well when used with - `allow`/`warn`/`deny`. -* `pedantic` sets the lint level to `Allow`. The exact mapping can be found - [here][category_level_mapping] -* The last part should be a text that explains what exactly is wrong with the - code - -The rest of this file contains an empty implementation for our lint pass, which -in this case is `EarlyLintPass` and should look like this: - -```rust -// clippy_lints/src/foo_functions.rs - -// .. imports and lint declaration .. - -declare_lint_pass!(FooFunctions => [FOO_FUNCTIONS]); - -impl EarlyLintPass for FooFunctions {} -``` - -[declare_clippy_lint]: https://github.com/rust-lang/rust-clippy/blob/557f6848bd5b7183f55c1e1522a326e9e1df6030/clippy_lints/src/lib.rs#L60 -[example_lint_page]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure -[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints -[category_level_mapping]: ../index.html - -## Lint registration - -When using `cargo dev new_lint`, the lint is automatically registered and -nothing more has to be done. - -When declaring a new lint by hand and `cargo dev update_lints` is used, the lint -pass may have to be registered manually in the `register_lints` function in -`clippy_lints/src/lib.rs`: - -```rust,ignore -store.register_early_pass(|| Box::new(foo_functions::FooFunctions)); -``` - -As one may expect, there is a corresponding `register_late_pass` method -available as well. Without a call to one of `register_early_pass` or -`register_late_pass`, the lint pass in question will not be run. - -One reason that `cargo dev update_lints` does not automate this step is that -multiple lints can use the same lint pass, so registering the lint pass may -already be done when adding a new lint. Another reason that this step is not -automated is that the order that the passes are registered determines the order -the passes actually run, which in turn affects the order that any emitted lints -are output in. - -## Lint passes - -Writing a lint that only checks for the name of a function means that we only -have to deal with the AST and don't have to deal with the type system at all. -This is good, because it makes writing this particular lint less complicated. - -We have to make this decision with every new Clippy lint. It boils down to using -either [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass]. - -In short, the `EarlyLintPass` runs before type checking and -[HIR](https://rustc-dev-guide.rust-lang.org/hir.html) lowering and the `LateLintPass` -has access to type information. Consider using the `LateLintPass` unless you need -something specific from the `EarlyLintPass`. - -Since we don't need type information for checking the function name, we used -`--pass=early` when running the new lint automation and all the imports were -added accordingly. - -[early_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.EarlyLintPass.html -[late_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html - -## Emitting a lint - -With UI tests and the lint declaration in place, we can start working on the -implementation of the lint logic. - -Let's start by implementing the `EarlyLintPass` for our `FooFunctions`: - -```rust,ignore -impl EarlyLintPass for FooFunctions { - fn check_fn(&mut self, cx: &EarlyContext<'_>, fn_kind: FnKind<'_>, span: Span, _: NodeId) { - // TODO: Emit lint here - } -} -``` - -We implement the [`check_fn`][check_fn] method from the -[`EarlyLintPass`][early_lint_pass] trait. This gives us access to various -information about the function that is currently being checked. More on that in -the next section. Let's worry about the details later and emit our lint for -*every* function definition first. - -Depending on how complex we want our lint message to be, we can choose from a -variety of lint emission functions. They can all be found in -[`clippy_utils/src/diagnostics.rs`][diagnostics]. - -`span_lint_and_help` seems most appropriate in this case. It allows us to -provide an extra help message, and we can't really suggest a better name -automatically. This is how it looks: - -```rust,ignore -impl EarlyLintPass for FooFunctions { - fn check_fn(&mut self, cx: &EarlyContext<'_>, fn_kind: FnKind<'_>, span: Span, _: NodeId) { - span_lint_and_help( - cx, - FOO_FUNCTIONS, - span, - "function named `foo`", - None, - "consider using a more meaningful name" - ); - } -} -``` - -Running our UI test should now produce output that contains the lint message. - -According to [the rustc-dev-guide], the text should be matter of fact and avoid -capitalization and periods, unless multiple sentences are needed. When code or -an identifier must appear in a message or label, it should be surrounded with -single grave accents \`. - -[check_fn]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.EarlyLintPass.html#method.check_fn -[diagnostics]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_utils/src/diagnostics.rs -[the rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/diagnostics.html - -## Adding the lint logic - -Writing the logic for your lint will most likely be different from our example, -so this section is kept rather short. - -Using the [`check_fn`][check_fn] method gives us access to [`FnKind`][fn_kind] -that has the [`FnKind::Fn`] variant. It provides access to the name of the -function/method via an [`Ident`][ident]. - -With that we can expand our `check_fn` method to: - -```rust -impl EarlyLintPass for FooFunctions { - fn check_fn(&mut self, cx: &EarlyContext<'_>, fn_kind: FnKind<'_>, span: Span, _: NodeId) { - if is_foo_fn(fn_kind) { - span_lint_and_help( - cx, - FOO_FUNCTIONS, - span, - "function named `foo`", - None, - "consider using a more meaningful name" - ); - } - } -} -``` - -We separate the lint conditional from the lint emissions because it makes the -code a bit easier to read. In some cases this separation would also allow to -write some unit tests (as opposed to only UI tests) for the separate function. - -In our example, `is_foo_fn` looks like: - -```rust -// use statements, impl EarlyLintPass, check_fn, .. - -fn is_foo_fn(fn_kind: FnKind<'_>) -> bool { - match fn_kind { - FnKind::Fn(_, ident, ..) => { - // check if `fn` name is `foo` - ident.name.as_str() == "foo" - } - // ignore closures - FnKind::Closure(..) => false - } -} -``` - -Now we should also run the full test suite with `cargo test`. At this point -running `cargo test` should produce the expected output. Remember to run `cargo -bless` to update the `.stderr` file. - -`cargo test` (as opposed to `cargo uitest`) will also ensure that our lint -implementation is not violating any Clippy lints itself. - -That should be it for the lint implementation. Running `cargo test` should now -pass. - -[fn_kind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/visit/enum.FnKind.html -[`FnKind::Fn`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/visit/enum.FnKind.html#variant.Fn -[ident]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/symbol/struct.Ident.html - -## Specifying the lint's minimum supported Rust version (MSRV) - -Sometimes a lint makes suggestions that require a certain version of Rust. For -example, the `manual_strip` lint suggests using `str::strip_prefix` and -`str::strip_suffix` which is only available after Rust 1.45. In such cases, you -need to ensure that the MSRV configured for the project is >= the MSRV of the -required Rust feature. If multiple features are required, just use the one with -a lower MSRV. - -First, add an MSRV alias for the required feature in [`clippy_config::msrvs`]. -This can be accessed later as `msrvs::STR_STRIP_PREFIX`, for example. - -```rust -msrv_aliases! { - .. - 1,45,0 { STR_STRIP_PREFIX } -} -``` - -In order to access the project-configured MSRV, you need to have an `msrv` field -in the LintPass struct, and a constructor to initialize the field. The `msrv` -value is passed to the constructor in `clippy_lints/lib.rs`. - -```rust -pub struct ManualStrip { - msrv: Msrv, -} - -impl ManualStrip { - #[must_use] - pub fn new(msrv: Msrv) -> Self { - Self { msrv } - } -} -``` - -The project's MSRV can then be matched against the feature MSRV in the LintPass -using the `Msrv::meets` method. - -``` rust -if !self.msrv.meets(msrvs::STR_STRIP_PREFIX) { - return; -} -``` - -The project's MSRV can also be specified as an attribute, which overrides -the value from `clippy.toml`. This can be accounted for using the -`extract_msrv_attr!(LintContext)` macro and passing -`LateContext`/`EarlyContext`. - -```rust,ignore -impl<'tcx> LateLintPass<'tcx> for ManualStrip { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - ... - } - extract_msrv_attr!(LateContext); -} -``` - -Once the `msrv` is added to the lint, a relevant test case should be added to -the lint's test file, `tests/ui/manual_strip.rs` in this example. It should -have a case for the version below the MSRV and one with the same contents but -for the MSRV version itself. - -```rust,ignore -... - -#[clippy::msrv = "1.44"] -fn msrv_1_44() { - /* something that would trigger the lint */ -} - -#[clippy::msrv = "1.45"] -fn msrv_1_45() { - /* something that would trigger the lint */ -} -``` - -As a last step, the lint should be added to the lint documentation. This is done -in `clippy_config/src/conf.rs`: - -```rust -define_Conf! { - /// Lint: LIST, OF, LINTS, . The minimum rust version that the project supports - (msrv: Option = None), - ... -} -``` - -[`clippy_config::msrvs`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_config/msrvs/index.html - -Afterwards update the documentation for the book as described in [Adding configuration to a lint](#adding-configuration-to-a-lint). - -## Author lint - -If you have trouble implementing your lint, there is also the internal `author` -lint to generate Clippy code that detects the offending pattern. It does not -work for all the Rust syntax, but can give a good starting point. - -The quickest way to use it, is the [Rust playground: -play.rust-lang.org][author_example]. Put the code you want to lint into the -editor and add the `#[clippy::author]` attribute above the item. Then run Clippy -via `Tools -> Clippy` and you should see the generated code in the output below. - -[Here][author_example] is an example on the playground. - -If the command was executed successfully, you can copy the code over to where -you are implementing your lint. - -[author_example]: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=9a12cb60e5c6ad4e3003ac6d5e63cf55 - -## Print HIR lint - -To implement a lint, it's helpful to first understand the internal -representation that rustc uses. Clippy has the `#[clippy::dump]` attribute that -prints the [_High-Level Intermediate Representation (HIR)_] of the item, -statement, or expression that the attribute is attached to. To attach the -attribute to expressions you often need to enable -`#![feature(stmt_expr_attributes)]`. - -[Here][print_hir_example] you can find an example, just select _Tools_ and run -_Clippy_. - -[_High-Level Intermediate Representation (HIR)_]: https://rustc-dev-guide.rust-lang.org/hir.html -[print_hir_example]: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=daf14db3a7f39ca467cd1b86c34b9afb - -## Documentation - -The final thing before submitting our PR is to add some documentation to our -lint declaration. - -Please document your lint with a doc comment akin to the following: - -```rust -declare_clippy_lint! { - /// ### What it does - /// Checks for ... (describe what the lint matches). - /// - /// ### Why is this bad? - /// Supply the reason for linting the code. - /// - /// ### Example - /// - /// ```rust,ignore - /// // A short example of code that triggers the lint - /// ``` - /// - /// Use instead: - /// ```rust,ignore - /// // A short example of improved code that doesn't trigger the lint - /// ``` - #[clippy::version = "1.29.0"] - pub FOO_FUNCTIONS, - pedantic, - "function named `foo`, which is not a descriptive name" -} -``` - -Once your lint is merged, this documentation will show up in the [lint -list][lint_list]. - -[lint_list]: https://rust-lang.github.io/rust-clippy/master/index.html - -## Running rustfmt - -[Rustfmt] is a tool for formatting Rust code according to style guidelines. Your -code has to be formatted by `rustfmt` before a PR can be merged. Clippy uses -nightly `rustfmt` in the CI. - -It can be installed via `rustup`: - -```bash -rustup component add rustfmt --toolchain=nightly -``` - -Use `cargo dev fmt` to format the whole codebase. Make sure that `rustfmt` is -installed for the nightly toolchain. - -[Rustfmt]: https://github.com/rust-lang/rustfmt - -## Debugging - -If you want to debug parts of your lint implementation, you can use the [`dbg!`] -macro anywhere in your code. Running the tests should then include the debug -output in the `stdout` part. - -[`dbg!`]: https://doc.rust-lang.org/std/macro.dbg.html - -## Conflicting lints - -There are several lints that deal with the same pattern but suggest different approaches. In other words, some lints -may suggest modifications that go in the opposite direction to what some other lints already propose for the same -code, creating conflicting diagnostics. - -When you are creating a lint that ends up in this scenario, the following tips should be encouraged to guide -classification: - -* The only case where they should be in the same category is if that category is `restriction`. For example, -`semicolon_inside_block` and `semicolon_outside_block`. -* For all the other cases, they should be in different categories with different levels of allowance. For example, -`implicit_return` (restriction, allow) and `needless_return` (style, warn). - -For lints that are in different categories, it is also recommended that at least one of them should be in the -`restriction` category. The reason for this is that the `restriction` group is the only group where we don't -recommend to enable the entire set, but cherry pick lints out of. - -## PR Checklist - -Before submitting your PR make sure you followed all the basic requirements: - - - -- \[ ] Followed [lint naming conventions][lint_naming] -- \[ ] Added passing UI tests (including committed `.stderr` file) -- \[ ] `cargo test` passes locally -- \[ ] Executed `cargo dev update_lints` -- \[ ] Added lint documentation -- \[ ] Run `cargo dev fmt` - -## Adding configuration to a lint - -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: - -1. Adding a new configuration entry to [`clippy_config::conf`] like this: - - ```rust,ignore - /// Lint: LINT_NAME. - /// - /// - (configuration_ident: Type = DefaultValue), - ``` - - The doc comment is automatically added to the documentation of the listed - lints. The default value will be formatted using the `Debug` implementation - of the type. -2. Adding the configuration value to the lint impl struct: - 1. This first requires the definition of a lint impl struct. Lint impl - structs are usually generated with the `declare_lint_pass!` macro. This - struct needs to be defined manually to add some kind of metadata to it: - ```rust - // Generated struct definition - declare_lint_pass!(StructName => [ - LINT_NAME - ]); - - // New manual definition struct - #[derive(Copy, Clone)] - pub struct StructName {} - - impl_lint_pass!(StructName => [ - LINT_NAME - ]); - ``` - - 2. Next add the configuration value and a corresponding creation method like - this: - ```rust - #[derive(Copy, Clone)] - pub struct StructName { - configuration_ident: Type, - } - - // ... - - impl StructName { - pub fn new(configuration_ident: Type) -> Self { - Self { - configuration_ident, - } - } - } - ``` -3. Passing the configuration value to the lint impl struct: - - First find the struct construction in the [`clippy_lints` lib file]. The - configuration value is now cloned or copied into a local value that is then - passed to the impl struct like this: - - ```rust,ignore - // Default generated registration: - store.register_*_pass(|| box module::StructName); - - // New registration with configuration value - let configuration_ident = conf.configuration_ident.clone(); - store.register_*_pass(move || box module::StructName::new(configuration_ident)); - ``` - - Congratulations the work is almost done. The configuration value can now be - accessed in the linting code via `self.configuration_ident`. - -4. Adding tests: - 1. The default configured value can be tested like any normal lint in - [`tests/ui`]. - 2. The configuration itself will be tested separately in [`tests/ui-toml`]. - Simply add a new subfolder with a fitting name. This folder contains a - `clippy.toml` file with the configuration value and a rust file that - should be linted by Clippy. The test can otherwise be written as usual. - -5. Update [Lint Configuration](../lint_configuration.md) - - Run `cargo collect-metadata` to generate documentation changes for the book. - -[`clippy_config::conf`]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_config/src/conf.rs -[`clippy_lints` lib file]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/lib.rs -[`tests/ui`]: https://github.com/rust-lang/rust-clippy/blob/master/tests/ui -[`tests/ui-toml`]: https://github.com/rust-lang/rust-clippy/blob/master/tests/ui-toml - -## Cheat Sheet - -Here are some pointers to things you are likely going to need for every lint: - -* [Clippy utils][utils] - Various helper functions. Maybe the function you need - is already in here ([`is_type_diagnostic_item`], [`implements_trait`], - [`snippet`], etc) -* [Clippy diagnostics][diagnostics] -* [Let chains][let-chains] -* [`from_expansion`][from_expansion] and - [`in_external_macro`][in_external_macro] -* [`Span`][span] -* [`Applicability`][applicability] -* [Common tools for writing lints](common_tools_writing_lints.md) helps with - common operations -* [The rustc-dev-guide][rustc-dev-guide] explains a lot of internal compiler - concepts -* [The nightly rustc docs][nightly_docs] which has been linked to throughout - this guide - -For `EarlyLintPass` lints: - -* [`EarlyLintPass`][early_lint_pass] -* [`rustc_ast::ast`][ast] - -For `LateLintPass` lints: - -* [`LateLintPass`][late_lint_pass] -* [`Ty::TyKind`][ty] - -While most of Clippy's lint utils are documented, most of rustc's internals lack -documentation currently. This is unfortunate, but in most cases you can probably -get away with copying things from existing similar lints. If you are stuck, -don't hesitate to ask on [Zulip] or in the issue/PR. - -[utils]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/index.html -[`is_type_diagnostic_item`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/ty/fn.is_type_diagnostic_item.html -[`implements_trait`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/ty/fn.implements_trait.html -[`snippet`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/source/fn.snippet.html -[let-chains]: https://github.com/rust-lang/rust/pull/94927 -[from_expansion]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html#method.from_expansion -[in_external_macro]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/lint/fn.in_external_macro.html -[span]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html -[applicability]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/enum.Applicability.html -[rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/ -[nightly_docs]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ -[ast]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/index.html -[ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/sty/index.html -[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/clippy diff --git a/book/src/development/basics.md b/book/src/development/basics.md deleted file mode 100644 index f4c109ff1191..000000000000 --- a/book/src/development/basics.md +++ /dev/null @@ -1,193 +0,0 @@ -# Basics for hacking on Clippy - -This document explains the basics for hacking on Clippy. Besides others, this -includes how to build and test Clippy. For a more in depth description on the -codebase take a look at [Adding Lints] or [Common Tools]. - -[Adding Lints]: adding_lints.md -[Common Tools]: common_tools_writing_lints.md - -- [Basics for hacking on Clippy](#basics-for-hacking-on-clippy) - - [Get the Code](#get-the-code) - - [Building and Testing](#building-and-testing) - - [`cargo dev`](#cargo-dev) - - [lintcheck](#lintcheck) - - [PR](#pr) - - [Common Abbreviations](#common-abbreviations) - - [Install from source](#install-from-source) - -## Get the Code - -First, make sure you have checked out the latest version of Clippy. If this is -your first time working on Clippy, create a fork of the repository and clone it -afterwards with the following command: - -```bash -git clone git@github.com:/rust-clippy -``` - -If you've already cloned Clippy in the past, update it to the latest version: - -```bash -# If the upstream remote has not been added yet -git remote add upstream https://github.com/rust-lang/rust-clippy -# upstream has to be the remote of the rust-lang/rust-clippy repo -git fetch upstream -# make sure that you are on the master branch -git checkout master -# rebase your master branch on the upstream master -git rebase upstream/master -# push to the master branch of your fork -git push -``` - -## Building and Testing - -You can build and test Clippy like every other Rust project: - -```bash -cargo build # builds Clippy -cargo test # tests Clippy -``` - -Since Clippy's test suite is pretty big, there are some commands that only run a -subset of Clippy's tests: - -```bash -# only run UI tests -cargo uitest -# only run UI tests starting with `test_` -TESTNAME="test_" cargo uitest -# only run dogfood tests -cargo dev dogfood -``` - -If the output of a [UI test] differs from the expected output, you can update -the reference file with: - -```bash -cargo bless -``` - -For example, this is necessary if you fix a typo in an error message of a lint, -or if you modify a test file to add a test case. - -> _Note:_ This command may update more files than you intended. In that case -> only commit the files you wanted to update. - -[UI test]: https://rustc-dev-guide.rust-lang.org/tests/adding.html#guide-to-the-ui-tests - -## `cargo dev` - -Clippy has some dev tools to make working on Clippy more convenient. These tools -can be accessed through the `cargo dev` command. Available tools are listed -below. To get more information about these commands, just call them with -`--help`. - -```bash -# formats the whole Clippy codebase and all tests -cargo dev fmt -# register or update lint names/groups/... -cargo dev update_lints -# create a new lint and register it -cargo dev new_lint -# deprecate a lint and attempt to remove code relating to it -cargo dev deprecate -# automatically formatting all code before each commit -cargo dev setup git-hook -# (experimental) Setup Clippy to work with IntelliJ-Rust -cargo dev setup intellij -# runs the `dogfood` tests -cargo dev dogfood -``` - -More about [intellij] command usage and reasons. - -[intellij]: https://github.com/rust-lang/rust-clippy/blob/master/CONTRIBUTING.md#intellij-rust - -## lintcheck - -`cargo lintcheck` will build and run clippy on a fixed set of crates and -generate a log of the results. You can `git diff` the updated log against its -previous version and see what impact your lint made on a small set of crates. -If you add a new lint, please audit the resulting warnings and make sure there -are no false positives and that the suggestions are valid. - -Refer to the tools [README] for more details. - -[README]: https://github.com/rust-lang/rust-clippy/blob/master/lintcheck/README.md - -## PR - -We follow a rustc no merge-commit policy. See -. - -## Common Abbreviations - -| Abbreviation | Meaning | -|--------------|----------------------------------------| -| UB | Undefined Behavior | -| FP | False Positive | -| FN | False Negative | -| ICE | Internal Compiler Error | -| AST | Abstract Syntax Tree | -| MIR | Mid-Level Intermediate Representation | -| HIR | High-Level Intermediate Representation | -| TCX | Type context | - -This is a concise list of abbreviations that can come up during Clippy -development. An extensive general list can be found in the [rustc-dev-guide -glossary][glossary]. Always feel free to ask if an abbreviation or meaning is -unclear to you. - -## Install from source - -If you are hacking on Clippy and want to install it from source, do the -following: - -First, take note of the toolchain -[override](https://rust-lang.github.io/rustup/overrides.html) in -`/rust-toolchain`. We will use this override to install Clippy into the right -toolchain. - -> Tip: You can view the active toolchain for the current directory with `rustup -> show active-toolchain`. - -From the Clippy project root, run the following command to build the Clippy -binaries and copy them into the toolchain directory. This will override the -currently installed Clippy component. - -```terminal -cargo build --release --bin cargo-clippy --bin clippy-driver -Zunstable-options --out-dir "$(rustc --print=sysroot)/bin" -``` - -Now you may run `cargo clippy` in any project, using the toolchain where you -just installed Clippy. - -```terminal -cd my-project -cargo +nightly-2021-07-01 clippy -``` - -...or `clippy-driver` - -```terminal -clippy-driver +nightly-2021-07-01 -``` - -If you need to restore the default Clippy installation, run the following (from -the Clippy project root). - -```terminal -rustup component remove clippy -rustup component add clippy -``` - -> **DO NOT** install using `cargo install --path . --force` since this will -> overwrite rustup -> [proxies](https://rust-lang.github.io/rustup/concepts/proxies.html). That is, -> `~/.cargo/bin/cargo-clippy` and `~/.cargo/bin/clippy-driver` should be hard or -> soft links to `~/.cargo/bin/rustup`. You can repair these by running `rustup -> update`. - -[glossary]: https://rustc-dev-guide.rust-lang.org/appendix/glossary.html diff --git a/book/src/development/common_tools_writing_lints.md b/book/src/development/common_tools_writing_lints.md deleted file mode 100644 index 09171d86a209..000000000000 --- a/book/src/development/common_tools_writing_lints.md +++ /dev/null @@ -1,274 +0,0 @@ -# Common tools for writing lints - -You may need following tooltips to catch up with common operations. - -- [Common tools for writing lints](#common-tools-for-writing-lints) - - [Retrieving the type of expression](#retrieving-the-type-of-expression) - - [Checking if an expr is calling a specific method](#checking-if-an-expr-is-calling-a-specific-method) - - [Checking for a specific type](#checking-for-a-specific-type) - - [Checking if a type implements a specific trait](#checking-if-a-type-implements-a-specific-trait) - - [Checking if a type defines a specific method](#checking-if-a-type-defines-a-specific-method) - - [Dealing with macros](#dealing-with-macros-and-expansions) - -Useful Rustc dev guide links: -- [Stages of compilation](https://rustc-dev-guide.rust-lang.org/compiler-src.html#the-main-stages-of-compilation) -- [Diagnostic items](https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-items.html) -- [Type checking](https://rustc-dev-guide.rust-lang.org/type-checking.html) -- [Ty module](https://rustc-dev-guide.rust-lang.org/ty.html) - -## Retrieving the type of expression - -Sometimes you may want to retrieve the type `Ty` of an expression `Expr`, for -example to answer following questions: - -- which type does this expression correspond to (using its [`TyKind`][TyKind])? -- is it a sized type? -- is it a primitive type? -- does it implement a trait? - -This operation is performed using the [`expr_ty()`][expr_ty] method from the -[`TypeckResults`][TypeckResults] struct, that gives you access to the underlying -structure [`Ty`][Ty]. - -Example of use: -```rust -impl LateLintPass<'_> for MyStructLint { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - // Get type of `expr` - let ty = cx.typeck_results().expr_ty(expr); - // Match its kind to enter its type - match ty.kind { - ty::Adt(adt_def, _) if adt_def.is_struct() => println!("Our `expr` is a struct!"), - _ => () - } - } -} -``` - -Similarly, in [`TypeckResults`][TypeckResults] methods, you have the -[`pat_ty()`][pat_ty] method to retrieve a type from a pattern. - -Two noticeable items here: -- `cx` is the lint context [`LateContext`][LateContext]. The two most useful - data structures in this context are `tcx` and the `TypeckResults` returned by - `LateContext::typeck_results`, allowing us to jump to type definitions and - other compilation stages such as HIR. -- `typeck_results`'s return value is [`TypeckResults`][TypeckResults] and is - created by type checking step, it includes useful information such as types of - expressions, ways to resolve methods and so on. - -## Checking if an expr is calling a specific method - -Starting with an `expr`, you can check whether it is calling a specific method -`some_method`: - -```rust -impl<'tcx> LateLintPass<'tcx> for MyStructLint { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - // Check our expr is calling a method - if let hir::ExprKind::MethodCall(path, _, _self_arg, ..) = &expr.kind - // Check the name of this method is `some_method` - && path.ident.name == sym!(some_method) - // Optionally, check the type of the self argument. - // - See "Checking for a specific type" - { - // ... - } - } -} -``` - -## Checking for a specific type - -There are three ways to check if an expression type is a specific type we want -to check for. All of these methods only check for the base type, generic -arguments have to be checked separately. - -```rust -use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item}; -use clippy_utils::{paths, match_def_path}; -use rustc_span::symbol::sym; -use rustc_hir::LangItem; - -impl LateLintPass<'_> for MyStructLint { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - // Getting the expression type - let ty = cx.typeck_results().expr_ty(expr); - - // 1. Using diagnostic items - // The last argument is the diagnostic item to check for - if is_type_diagnostic_item(cx, ty, sym::Option) { - // The type is an `Option` - } - - // 2. Using lang items - if is_type_lang_item(cx, ty, LangItem::RangeFull) { - // The type is a full range like `.drain(..)` - } - - // 3. Using the type path - // This method should be avoided if possible - if match_def_path(cx, def_id, &paths::RESULT) { - // The type is a `core::result::Result` - } - } -} -``` - -Prefer using diagnostic items and lang items where possible. - -## Checking if a type implements a specific trait - -There are three ways to do this, depending on if the target trait has a -diagnostic item, lang item or neither. - -```rust -use clippy_utils::ty::implements_trait; -use clippy_utils::is_trait_method; -use rustc_span::symbol::sym; - -impl LateLintPass<'_> for MyStructLint { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - // 1. Using diagnostic items with the expression - // we use `is_trait_method` function from Clippy's utils - if is_trait_method(cx, expr, sym::Iterator) { - // method call in `expr` belongs to `Iterator` trait - } - - // 2. Using lang items with the expression type - let ty = cx.typeck_results().expr_ty(expr); - if cx.tcx.lang_items() - // we are looking for the `DefId` of `Drop` trait in lang items - .drop_trait() - // then we use it with our type `ty` by calling `implements_trait` from Clippy's utils - .map_or(false, |id| implements_trait(cx, ty, id, &[])) { - // `expr` implements `Drop` trait - } - } -} -``` - -> Prefer using diagnostic and lang items, if the target trait has one. - -We access lang items through the type context `tcx`. `tcx` is of type -[`TyCtxt`][TyCtxt] and is defined in the `rustc_middle` crate. A list of defined -paths for Clippy can be found in [paths.rs][paths] - -## Checking if a type defines a specific method - -To check if our type defines a method called `some_method`: - -```rust -use clippy_utils::ty::is_type_diagnostic_item; -use clippy_utils::return_ty; - -impl<'tcx> LateLintPass<'tcx> for MyTypeImpl { - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { - // Check if item is a method/function - if let ImplItemKind::Fn(ref signature, _) = impl_item.kind - // Check the method is named `some_method` - && impl_item.ident.name == sym!(some_method) - // We can also check it has a parameter `self` - && signature.decl.implicit_self.has_implicit_self() - // We can go further and even check if its return type is `String` - && is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym!(string_type)) - { - // ... - } - } -} -``` - -## Dealing with macros and expansions - -Keep in mind that macros are already expanded and desugaring is already applied -to the code representation that you are working with in Clippy. This -unfortunately causes a lot of false positives because macro expansions are -"invisible" unless you actively check for them. Generally speaking, code with -macro expansions should just be ignored by Clippy because that code can be -dynamic in ways that are difficult or impossible to see. Use the following -functions to deal with macros: - -- `span.from_expansion()`: detects if a span is from macro expansion or - desugaring. Checking this is a common first step in a lint. - - ```rust,ignore - if expr.span.from_expansion() { - // just forget it - return; - } - ``` - -- `span.ctxt()`: the span's context represents whether it is from expansion, and - if so, which macro call expanded it. It is sometimes useful to check if the - context of two spans are equal. - - ```rust,ignore - // expands to `1 + 0`, but don't lint - 1 + mac!() - ``` - ```rust,ignore - if left.span.ctxt() != right.span.ctxt() { - // the coder most likely cannot modify this expression - return; - } - ``` - > Note: Code that is not from expansion is in the "root" context. So any spans - > where `from_expansion` returns `true` can be assumed to have the same - > context. And so just using `span.from_expansion()` is often good enough. - - -- `in_external_macro(span)`: detect if the given span is from a macro defined in - a foreign crate. If you want the lint to work with macro-generated code, this - is the next line of defense to avoid macros not defined in the current crate. - It doesn't make sense to lint code that the coder can't change. - - You may want to use it for example to not start linting in macros from other - crates - - ```rust - use rustc_middle::lint::in_external_macro; - - use a_crate_with_macros::foo; - - // `foo` is defined in `a_crate_with_macros` - foo!("bar"); - - // if we lint the `match` of `foo` call and test its span - assert_eq!(in_external_macro(cx.sess(), match_span), true); - ``` - -- `span.ctxt()`: the span's context represents whether it is from expansion, and - if so, what expanded it - - One thing `SpanContext` is useful for is to check if two spans are in the same - context. For example, in `a == b`, `a` and `b` have the same context. In a - `macro_rules!` with `a == $b`, `$b` is expanded to some expression with a - different context from `a`. - - ```rust,ignore - macro_rules! m { - ($a:expr, $b:expr) => { - if $a.is_some() { - $b; - } - } - } - - let x: Option = Some(42); - m!(x, x.unwrap()); - - // These spans are not from the same context - // x.is_some() is from inside the macro - // x.unwrap() is from outside the macro - assert_eq!(x_is_some_span.ctxt(), x_unwrap_span.ctxt()); - ``` - -[Ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html -[TyKind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html -[TypeckResults]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html -[expr_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html#method.expr_ty -[LateContext]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LateContext.html -[TyCtxt]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html -[pat_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TypeckResults.html#method.pat_ty -[paths]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/paths/index.html diff --git a/book/src/development/defining_lints.md b/book/src/development/defining_lints.md deleted file mode 100644 index 806ed0845f03..000000000000 --- a/book/src/development/defining_lints.md +++ /dev/null @@ -1,204 +0,0 @@ -# Define New Lints - -The first step in the journey of a new lint is the definition -and registration of the lint in Clippy's codebase. -We can use the Clippy dev tools to handle this step since setting up the -lint involves some boilerplate code. - -#### Lint types - -A lint type is the category of items and expressions in which your lint focuses on. - -As of the writing of this documentation update, there are 12 _types_ of lints -besides the numerous standalone lints living under `clippy_lints/src/`: - -- `cargo` -- `casts` -- `functions` -- `loops` -- `matches` -- `methods` -- `misc_early` -- `operators` -- `transmute` -- `types` -- `unit_types` -- `utils / internal` (Clippy internal lints) - -These types group together lints that share some common behaviors. For instance, -`functions` groups together lints that deal with some aspects of functions in -Rust, like definitions, signatures and attributes. - -For more information, feel free to compare the lint files under any category -with [All Clippy lints][all_lints] or ask one of the maintainers. - -## Lint name - -A good lint name is important, make sure to check the [lint naming -guidelines][lint_naming]. Don't worry, if the lint name doesn't fit, a Clippy -team member will alert you in the PR process. - ---- - -We'll name our example lint that detects functions named "foo" `foo_functions`. -Check the [lint naming guidelines][lint_naming] to see why this name makes -sense. - -## Add and Register the Lint - -Now that a name is chosen, we shall register `foo_functions` as a lint to the -codebase. There are two ways to register a lint. - -### Standalone - -If you believe that this new lint is a standalone lint (that doesn't belong to -any specific [type](#lint-types) like `functions` or `loops`), you can run the -following command in your Clippy project: - -```sh -$ cargo dev new_lint --name=lint_name --pass=late --category=pedantic -``` - -There are two things to note here: - -1. `--pass`: We set `--pass=late` in this command to do a late lint pass. The - alternative is an `early` lint pass. We will discuss this difference in the - [Lint Passes] chapter. -2. `--category`: If not provided, the `category` of this new lint will default - to `nursery`. - -The `cargo dev new_lint` command will create a new file: -`clippy_lints/src/foo_functions.rs` as well as [register the -lint](#lint-registration). - -Overall, you should notice that the following files are modified or created: - -```sh -$ git status -On branch foo_functions -Changes not staged for commit: - (use "git add ..." to update what will be committed) - (use "git restore ..." to discard changes in working directory) - modified: CHANGELOG.md - modified: clippy_lints/src/lib.register_lints.rs - modified: clippy_lints/src/lib.register_pedantic.rs - modified: clippy_lints/src/lib.rs - -Untracked files: - (use "git add ..." to include in what will be committed) - clippy_lints/src/foo_functions.rs - tests/ui/foo_functions.rs -``` - - -### Specific Type - -> **Note**: Lint types are listed in the ["Lint types"](#lint-types) section - -If you believe that this new lint belongs to a specific type of lints, -you can run `cargo dev new_lint` with a `--type` option. - -Since our `foo_functions` lint is related to function calls, one could -argue that we should put it into a group of lints that detect some behaviors -of functions, we can put it in the `functions` group. - -Let's run the following command in your Clippy project: - -```sh -$ cargo dev new_lint --name=foo_functions --type=functions --category=pedantic -``` - -This command will create, among other things, a new file: -`clippy_lints/src/{type}/foo_functions.rs`. -In our case, the path will be `clippy_lints/src/functions/foo_functions.rs`. - -Notice how this command has a `--type` flag instead of `--pass`. Unlike a standalone -definition, this lint won't be registered in the traditional sense. Instead, you will -call your lint from within the type's lint pass, found in `clippy_lints/src/{type}/mod.rs`. - -A _type_ is just the name of a directory in `clippy_lints/src`, like `functions` in -the example command. Clippy groups together some lints that share common behaviors, -so if your lint falls into one, it would be best to add it to that type. - -Overall, you should notice that the following files are modified or created: - -```sh -$ git status -On branch foo_functions -Changes not staged for commit: - (use "git add ..." to update what will be committed) - (use "git restore ..." to discard changes in working directory) - modified: CHANGELOG.md - modified: clippy_lints/src/declared_lints.rs - modified: clippy_lints/src/functions/mod.rs - -Untracked files: - (use "git add ..." to include in what will be committed) - clippy_lints/src/functions/foo_functions.rs - tests/ui/foo_functions.rs -``` - - -## The `define_clippy_lints` macro - -After `cargo dev new_lint`, you should see a macro with the name -`define_clippy_lints`. It will be in the same file if you defined a standalone -lint, and it will be in `mod.rs` if you defined a type-specific lint. - -The macro looks something like this: - -```rust -declare_clippy_lint! { - /// ### What it does - /// - /// // Describe here what does the lint do. - /// - /// Triggers when detects... - /// - /// ### Why is this bad? - /// - /// // Describe why this pattern would be bad - /// - /// It can lead to... - /// - /// ### Example - /// ```rust - /// // example code where clippy issues a warning - /// ``` - /// Use instead: - /// ```rust - /// // example code which does not raise clippy warning - /// ``` - #[clippy::version = "1.70.0"] // <- In which version was this implemented, keep it up to date! - pub LINT_NAME, // <- The lint name IN_ALL_CAPS - pedantic, // <- The lint group - "default lint description" // <- A lint description, e.g. "A function has an unit return type." -} -``` - -## Lint registration - -If we run the `cargo dev new_lint` command for a new lint, the lint will be -automatically registered and there is nothing more to do. - -However, sometimes we might want to declare a new lint by hand. In this case, -we'd use `cargo dev update_lints` command afterwards. - -When a lint is manually declared, we might need to register the lint pass -manually in the `register_lints` function in `clippy_lints/src/lib.rs`: - -```rust -store.register_late_pass(|_| Box::new(foo_functions::FooFunctions)); -``` - -As you might have guessed, where there's something late, there is something -early: in Clippy there is a `register_early_pass` method as well. More on early -vs. late passes in the [Lint Passes] chapter. - -Without a call to one of `register_early_pass` or `register_late_pass`, the lint -pass in question will not be run. - - -[all_lints]: https://rust-lang.github.io/rust-clippy/master/ -[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints -[Lint Passes]: lint_passes.md diff --git a/book/src/development/emitting_lints.md b/book/src/development/emitting_lints.md deleted file mode 100644 index d70f4fc17ebf..000000000000 --- a/book/src/development/emitting_lints.md +++ /dev/null @@ -1,217 +0,0 @@ -# Emitting a lint - -Once we have [defined a lint](defining_lints.md), written [UI -tests](writing_tests.md) and chosen [the lint pass](lint_passes.md) for the lint, -we can begin the implementation of the lint logic so that we can emit it and -gradually work towards a lint that behaves as expected. - -Note that we will not go into concrete implementation of a lint logic in this -chapter. We will go into details in later chapters as well as in two examples of -real Clippy lints. - -To emit a lint, we must implement a pass (see [Lint Passes](lint_passes.md)) for -the lint that we have declared. In this example we'll implement a "late" lint, -so take a look at the [LateLintPass][late_lint_pass] documentation, which -provides an abundance of methods that we can implement for our lint. - -```rust -pub trait LateLintPass<'tcx>: LintPass { - // Trait methods -} -``` - -By far the most common method used for Clippy lints is [`check_expr` -method][late_check_expr], this is because Rust is an expression language and, -more often than not, the lint we want to work on must examine expressions. - -> _Note:_ If you don't fully understand what expressions are in Rust, take a -> look at the official documentation on [expressions][rust_expressions] - -Other common ones include the [`check_fn` method][late_check_fn] and the -[`check_item` method][late_check_item]. - -### Emitting a lint - -Inside the trait method that we implement, we can write down the lint logic and -emit the lint with suggestions. - -Clippy's [diagnostics] provides quite a few diagnostic functions that we can use -to emit lints. Take a look at the documentation to pick one that suits your -lint's needs the best. Some common ones you will encounter in the Clippy -repository includes: - -- [`span_lint`]: Emits a lint without providing any other information -- [`span_lint_and_note`]: Emits a lint and adds a note -- [`span_lint_and_help`]: Emits a lint and provides a helpful message -- [`span_lint_and_sugg`]: Emits a lint and provides a suggestion to fix the code -- [`span_lint_and_then`]: Like `span_lint`, but allows for a lot of output - customization. - -```rust -impl<'tcx> LateLintPass<'tcx> for LintName { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - // Imagine that `some_lint_expr_logic` checks for requirements for emitting the lint - if some_lint_expr_logic(expr) { - span_lint_and_help( - cx, // < The context - LINT_NAME, // < The name of the lint in ALL CAPS - expr.span, // < The span to lint - "message on why the lint is emitted", - None, // < An optional help span (to highlight something in the lint) - "message that provides a helpful suggestion", - ); - } - } -} -``` - -> Note: The message should be matter of fact and avoid capitalization and -> punctuation. If multiple sentences are needed, the messages should probably be -> split up into an error + a help / note / suggestion message. - -## Suggestions: Automatic fixes - -Some lints know what to change in order to fix the code. For example, the lint -[`range_plus_one`][range_plus_one] warns for ranges where the user wrote `x..y + -1` instead of using an [inclusive range][inclusive_range] (`x..=y`). The fix to -this code would be changing the `x..y + 1` expression to `x..=y`. **This is -where suggestions come in**. - -A suggestion is a change that the lint provides to fix the issue it is linting. -The output looks something like this (from the example earlier): - -```text -error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:37:14 - | -LL | for _ in 1..1 + 1 {} - | ^^^^^^^^ help: use: `1..=1` -``` - -**Not all suggestions are always right**, some of them require human -supervision, that's why we have [Applicability][applicability]. - -Applicability indicates confidence in the correctness of the suggestion, some -are always right (`Applicability::MachineApplicable`), but we use -`Applicability::MaybeIncorrect` and others when talking about a suggestion that -may be incorrect. - -### Example - -The same lint `LINT_NAME` but that emits a suggestion would look something like this: - -```rust -impl<'tcx> LateLintPass<'tcx> for LintName { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - // Imagine that `some_lint_expr_logic` checks for requirements for emitting the lint - if some_lint_expr_logic(expr) { - span_lint_and_sugg( // < Note this change - cx, - LINT_NAME, - span, - "message on why the lint is emitted", - "use", - format!("foo + {} * bar", snippet(cx, expr.span, "")), // < Suggestion - Applicability::MachineApplicable, - ); - } - } -} -``` - -Suggestions generally use the [`format!`][format_macro] macro to interpolate the -old values with the new ones. To get code snippets, use one of the `snippet*` -functions from `clippy_utils::source`. - -## How to choose between notes, help messages and suggestions - -Notes are presented separately from the main lint message, they provide useful -information that the user needs to understand why the lint was activated. They -are the most helpful when attached to a span. - -Examples: - -### Notes - -```text -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing. - --> tests/ui/drop_forget_ref.rs:10:5 - | -10 | forget(&SomeStruct); - | ^^^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::forget-ref` implied by `-D warnings` -note: argument has type &SomeStruct - --> tests/ui/drop_forget_ref.rs:10:12 - | -10 | forget(&SomeStruct); - | ^^^^^^^^^^^ -``` - -### Help Messages - -Help messages are specifically to help the user. These are used in situation -where you can't provide a specific machine applicable suggestion. They can also -be attached to a span. - -Example: - -```text -error: constant division of 0.0 with 0.0 will always result in NaN - --> tests/ui/zero_div_zero.rs:6:25 - | -6 | let other_f64_nan = 0.0f64 / 0.0; - | ^^^^^^^^^^^^ - | - = help: consider using `f64::NAN` if you would like a constant representing NaN -``` - -### Suggestions - -Suggestions are the most helpful, they are changes to the source code to fix the -error. The magic in suggestions is that tools like `rustfix` can detect them and -automatically fix your code. - -Example: - -```text -error: This `.fold` can be more succinctly expressed as `.any` ---> tests/ui/methods.rs:390:13 - | -390 | let _ = (0..3).fold(false, |acc, x| acc || x > 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.any(|x| x > 2)` - | -``` - -### Snippets - -Snippets are pieces of the source code (as a string), they are extracted -generally using the [`snippet`][snippet_fn] function. - -For example, if you want to know how an item looks (and you know the item's -span), you could use `snippet(cx, span, "..")`. - -## Final: Run UI Tests to Emit the Lint - -Now, if we run our [UI test](writing_tests.md), we should see that Clippy now -produces output that contains the lint message we designed. - -The next step is to implement the logic properly, which is a detail that we will -cover in the next chapters. - -[diagnostics]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/diagnostics/index.html -[late_check_expr]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html#method.check_expr -[late_check_fn]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html#method.check_fn -[late_check_item]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html#method.check_item -[late_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html -[rust_expressions]: https://doc.rust-lang.org/reference/expressions.html -[`span_lint`]: https://doc.rust-lang.org/beta/nightly-rustc/clippy_utils/diagnostics/fn.span_lint.html -[`span_lint_and_note`]: https://doc.rust-lang.org/beta/nightly-rustc/clippy_utils/diagnostics/fn.span_lint_and_note.html -[`span_lint_and_help`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/diagnostics/fn.span_lint_and_help.html -[`span_lint_and_sugg`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/diagnostics/fn.span_lint_and_sugg.html -[`span_lint_and_then`]: https://doc.rust-lang.org/beta/nightly-rustc/clippy_utils/diagnostics/fn.span_lint_and_then.html -[range_plus_one]: https://rust-lang.github.io/rust-clippy/master/index.html#range_plus_one -[inclusive_range]: https://doc.rust-lang.org/std/ops/struct.RangeInclusive.html -[applicability]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_errors/enum.Applicability.html -[snippet_fn]: https://doc.rust-lang.org/beta/nightly-rustc/clippy_utils/source/fn.snippet.html -[format_macro]: https://doc.rust-lang.org/std/macro.format.html diff --git a/book/src/development/infrastructure/README.md b/book/src/development/infrastructure/README.md deleted file mode 100644 index 3b2a25399962..000000000000 --- a/book/src/development/infrastructure/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# Infrastructure - -In order to deploy Clippy over `rustup`, some infrastructure is necessary. This -chapter describes the different parts of the Clippy infrastructure that need to -be maintained to make this possible. - -The most important part is the sync between the `rust-lang/rust` repository and -the Clippy repository that takes place every two weeks. This process is -described in the [Syncing changes between Clippy and `rust-lang/rust`](sync.md) -section. - -A new Clippy release is done together with every Rust release, so every six -weeks. The release process is described in the [Release a new Clippy -Version](release.md) section. During a release cycle a changelog entry for the -next release has to be written. The format of that and how to do that is -documented in the [Changelog Update](changelog_update.md) section. - -> _Note:_ The Clippy CI should also be described in this chapter, but for now is -> left as a TODO. diff --git a/book/src/development/infrastructure/backport.md b/book/src/development/infrastructure/backport.md deleted file mode 100644 index 6920c4e46561..000000000000 --- a/book/src/development/infrastructure/backport.md +++ /dev/null @@ -1,72 +0,0 @@ -# Backport Changes - -Sometimes it is necessary to backport changes to the beta release of Clippy. -Backports in Clippy are rare and should be approved by the Clippy team. For -example, a backport is done, if a crucial ICE was fixed or a lint is broken to a -point, that it has to be disabled, before landing on stable. - -Backports are done to the `beta` branch of Clippy. Backports to stable Clippy -releases basically don't exist, since this would require a Rust point release, -which is almost never justifiable for a Clippy fix. - - -## Backport the changes - -Backports are done on the beta branch of the Clippy repository. - -```bash -# Assuming the current directory corresponds to the Clippy repository -$ git checkout beta -$ git checkout -b backport -$ git cherry-pick # `` is the commit hash of the commit(s), that should be backported -$ git push origin backport -``` - -Now you should test that the backport passes all the tests in the Rust -repository. You can do this with: - -```bash -# Assuming the current directory corresponds to the Rust repository -$ git checkout beta -# Make sure to change `your-github-name` to your github name in the following command -$ git subtree pull -p src/tools/clippy https://github.com//rust-clippy backport -$ ./x.py test src/tools/clippy -``` - -Should the test fail, you can fix Clippy directly in the Rust repository. This -has to be first applied to the Clippy beta branch and then again synced to the -Rust repository, though. The easiest way to do this is: - -```bash -# In the Rust repository -$ git diff --patch --relative=src/tools/clippy > clippy.patch -# In the Clippy repository -$ git apply /path/to/clippy.patch -$ git add -u -$ git commit -m "Fix rustup fallout" -$ git push origin backport -``` - -After this, you can open a PR to the `beta` branch of the Clippy repository. - - -## Update Clippy in the Rust Repository - -This step must be done, **after** the PR of the previous step was merged. - -After the backport landed in the Clippy repository, the branch has to be synced -back to the beta branch of the Rust repository. - -```bash -# Assuming the current directory corresponds to the Rust repository -$ git checkout beta -$ git checkout -b clippy_backport -$ git subtree pull -p src/tools/clippy https://github.com/rust-lang/rust-clippy beta -$ git push origin clippy_backport -``` - -Make sure to test the backport in the Rust repository before opening a PR. This -is done with `./x.py test src/tools/clippy`. If that passes all tests, open a PR -to the `beta` branch of the Rust repository. In this PR you should tag the -Clippy team member, that agreed to the backport or the `@rust-lang/clippy` team. -Make sure to add `[beta]` to the title of the PR. diff --git a/book/src/development/infrastructure/book.md b/book/src/development/infrastructure/book.md deleted file mode 100644 index de5de4bebaa9..000000000000 --- a/book/src/development/infrastructure/book.md +++ /dev/null @@ -1,42 +0,0 @@ -# The Clippy Book - -This document explains how to make additions and changes to the Clippy book, the -guide to Clippy that you're reading right now. The Clippy book is formatted with -[Markdown](https://www.markdownguide.org) and generated by -[mdBook](https://github.com/rust-lang/mdBook). - -- [Get mdBook](#get-mdbook) -- [Make changes](#make-changes) - -## Get mdBook - -While not strictly necessary since the book source is simply Markdown text -files, having mdBook locally will allow you to build, test and serve the book -locally to view changes before you commit them to the repository. You likely -already have `cargo` installed, so the easiest option is to: - -```shell -cargo install mdbook -``` - -See the mdBook [installation](https://github.com/rust-lang/mdBook#installation) -instructions for other options. - -## Make changes - -The book's -[src](https://github.com/rust-lang/rust-clippy/tree/master/book/src) -directory contains all the markdown files used to generate the book. If you -want to see your changes in real time, you can use the mdBook `serve` command to -run a web server locally that will automatically update changes as they are -made. From the top level of your `rust-clippy` directory: - -```shell -mdbook serve book --open -``` - -Then navigate to `http://localhost:3000` to see the generated book. While the -server is running, changes you make will automatically be updated. - -For more information, see the mdBook -[guide](https://rust-lang.github.io/mdBook/). diff --git a/book/src/development/infrastructure/changelog_update.md b/book/src/development/infrastructure/changelog_update.md deleted file mode 100644 index df9b1bbe18f3..000000000000 --- a/book/src/development/infrastructure/changelog_update.md +++ /dev/null @@ -1,117 +0,0 @@ -# Changelog Update - -If you want to help with updating the [changelog], you're in the right place. - -## When to update - -Typos and other small fixes/additions are _always_ welcome. - -Special care needs to be taken when it comes to updating the changelog for a new -Rust release. For that purpose, the changelog is ideally updated during the week -before an upcoming stable release. You can find the release dates on the [Rust -Forge][forge]. - -Most of the time we only need to update the changelog for minor Rust releases. -It's been very rare that Clippy changes were included in a patch release. - -## Changelog update walkthrough - -### 1. Finding the relevant Clippy commits - -Each Rust release ships with its own version of Clippy. The Clippy subtree can -be found in the `tools` directory of the Rust repository. - -Depending on the current time and what exactly you want to update, the following -bullet points might be helpful: - -* When writing the release notes for the **upcoming stable release** you need to - check out the Clippy commit of the current Rust `beta` branch. - [Link][rust_beta_tools] -* When writing the release notes for the **upcoming beta release**, you need to - check out the Clippy commit of the current Rust `master`. - [Link][rust_master_tools] -* When writing the (forgotten) release notes for a **past stable release**, you - need to check out the Rust release tag of the stable release. - [Link][rust_stable_tools] - -Usually you want to write the changelog of the **upcoming stable release**. Make -sure though, that `beta` was already branched in the Rust repository. - -To find the commit hash, issue the following command when in a `rust-lang/rust` -checkout: -``` -git log --oneline -- src/tools/clippy/ | grep -o "Merge commit '[a-f0-9]*' into .*" | head -1 | sed -e "s/Merge commit '\([a-f0-9]*\)' into .*/\1/g" -``` - -### 2. Fetching the PRs between those commits - -Once you've got the correct commit range, run - -``` -util/fetch_prs_between.sh commit1 commit2 > changes.txt -``` - -and open that file in your editor of choice. - -When updating the changelog it's also a good idea to make sure that `commit1` is -already correct in the current changelog. - -### 3. Authoring the final changelog - -The above script should have dumped all the relevant PRs to the file you -specified. It should have filtered out most of the irrelevant PRs already, but -it's a good idea to do a manual cleanup pass where you look for more irrelevant -PRs. If you're not sure about some PRs, just leave them in for the review and -ask for feedback. - -With the PRs filtered, you can start to take each PR and move the `changelog: ` -content to `CHANGELOG.md`. Adapt the wording as you see fit but try to keep it -somewhat coherent. - -The order should roughly be: - -1. New lints -2. Moves or deprecations of lints -3. Changes that expand what code existing lints cover -4. False positive fixes -5. Suggestion fixes/improvements -6. ICE fixes -7. Documentation improvements -8. Others - -As section headers, we use: - -``` -### New Lints -### Moves and Deprecations -### Enhancements -### False Positive Fixes -### Suggestion Fixes/Improvements -### ICE Fixes -### Documentation Improvements -### Others -``` - -Please also be sure to update the Beta/Unreleased sections at the top with the -relevant commit ranges. - -#### 3.1 Include `beta-accepted` PRs - -Look for the [`beta-accepted`] label and make sure to also include the PRs with -that label in the changelog. If you can, remove the `beta-accepted` labels -**after** the changelog PR was merged. - -> _Note:_ Some of those PRs might even get backported to the previous `beta`. -> Those have to be included in the changelog of the _previous_ release. - -### 4. Update `clippy::version` attributes - -Next, make sure to check that the `#[clippy::version]` attributes for the added -lints contain the correct version. - -[changelog]: https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md -[forge]: https://forge.rust-lang.org/ -[rust_master_tools]: https://github.com/rust-lang/rust/tree/master/src/tools/clippy -[rust_beta_tools]: https://github.com/rust-lang/rust/tree/beta/src/tools/clippy -[rust_stable_tools]: https://github.com/rust-lang/rust/releases -[`beta-accepted`]: https://github.com/rust-lang/rust-clippy/issues?q=label%3Abeta-accepted+ diff --git a/book/src/development/infrastructure/release.md b/book/src/development/infrastructure/release.md deleted file mode 100644 index 98fabf8e89ae..000000000000 --- a/book/src/development/infrastructure/release.md +++ /dev/null @@ -1,142 +0,0 @@ -# Release a new Clippy Version - -> _NOTE:_ This document is probably only relevant to you, if you're a member of -> the Clippy team. - -Clippy is released together with stable Rust releases. The dates for these -releases can be found at the [Rust Forge]. This document explains the necessary -steps to create a Clippy release. - -1. [Remerge the `beta` branch](#remerge-the-beta-branch) -2. [Update the `beta` branch](#update-the-beta-branch) -3. [Find the Clippy commit](#find-the-clippy-commit) -4. [Tag the stable commit](#tag-the-stable-commit) -5. [Update `CHANGELOG.md`](#update-changelogmd) - -> _NOTE:_ This document is for stable Rust releases, not for point releases. For -> point releases, step 1. and 2. should be enough. - -[Rust Forge]: https://forge.rust-lang.org/ - -## Remerge the `beta` branch - -This step is only necessary, if since the last release something was backported -to the beta Rust release. The remerge is then necessary, to make sure that the -Clippy commit, that was used by the now stable Rust release, persists in the -tree of the Clippy repository. - -To find out if this step is necessary run - -```bash -# Assumes that the local master branch of rust-lang/rust-clippy is up-to-date -$ git fetch upstream -$ git branch master --contains upstream/beta -``` - -If this command outputs `master`, this step is **not** necessary. - -```bash -# Assuming `HEAD` is the current `master` branch of rust-lang/rust-clippy -$ git checkout -b backport_remerge -$ git merge upstream/beta -$ git diff # This diff has to be empty, otherwise something with the remerge failed -$ git push origin backport_remerge # This can be pushed to your fork -``` - -After this, open a PR to the master branch. In this PR, the commit hash of the -`HEAD` of the `beta` branch must exist. In addition to that, no files should be -changed by this PR. - -## Update the `beta` branch - -This step must be done **after** the PR of the previous step was merged. - -First, the Clippy commit of the `beta` branch of the Rust repository has to be -determined. - -```bash -# Assuming the current directory corresponds to the Rust repository -$ git fetch upstream -$ git checkout upstream/beta -$ BETA_SHA=$(git log --oneline -- src/tools/clippy/ | grep -o "Merge commit '[a-f0-9]*' into .*" | head -1 | sed -e "s/Merge commit '\([a-f0-9]*\)' into .*/\1/g") -``` - -After finding the Clippy commit, the `beta` branch in the Clippy repository can -be updated. - -```bash -# Assuming the current directory corresponds to the Clippy repository -$ git checkout beta -$ git reset --hard $BETA_SHA -$ git push upstream beta -``` - -## Find the Clippy commit - -The first step is to tag the Clippy commit, that is included in the stable Rust -release. This commit can be found in the Rust repository. - -```bash -# Assuming the current directory corresponds to the Rust repository -$ git fetch upstream # `upstream` is the `rust-lang/rust` remote -$ git checkout 1.XX.0 # XX should be exchanged with the corresponding version -$ SHA=$(git log --oneline -- src/tools/clippy/ | grep -o "Merge commit '[a-f0-9]*' into .*" | head -1 | sed -e "s/Merge commit '\([a-f0-9]*\)' into .*/\1/g") -``` - -## Tag the stable commit - -After finding the Clippy commit, it can be tagged with the release number. - -```bash -# Assuming the current directory corresponds to the Clippy repository -$ git checkout $SHA -$ git tag rust-1.XX.0 # XX should be exchanged with the corresponding version -$ git push upstream rust-1.XX.0 # `upstream` is the `rust-lang/rust-clippy` remote -``` - -After this, the release should be available on the Clippy [release page]. - -[release page]: https://github.com/rust-lang/rust-clippy/releases - -## Update the `stable` branch - -At this step you should have already checked out the commit of the `rust-1.XX.0` -tag. Updating the stable branch from here is as easy as: - -```bash -# Assuming the current directory corresponds to the Clippy repository and the -# commit of the just created rust-1.XX.0 tag is checked out. -$ git push upstream rust-1.XX.0:stable # `upstream` is the `rust-lang/rust-clippy` remote -``` - -> _NOTE:_ Usually there are no stable backports for Clippy, so this update -> should be possible without force pushing or anything like this. If there -> should have happened a stable backport, make sure to re-merge those changes -> just as with the `beta` branch. - -## Update `CHANGELOG.md` - -For this see the document on [how to update the changelog]. - -If you don't have time to do a complete changelog update right away, just update -the following parts: - -- Remove the `(beta)` from the new stable version: - - ```markdown - ## Rust 1.XX (beta) -> ## Rust 1.XX - ``` - -- Update the release date line of the new stable version: - - ```markdown - Current beta, release 20YY-MM-DD -> Current stable, released 20YY-MM-DD - ``` - -- Update the release date line of the previous stable version: - - ```markdown - Current stable, released 20YY-MM-DD -> Released 20YY-MM-DD - ``` - -[how to update the changelog]: changelog_update.md diff --git a/book/src/development/infrastructure/sync.md b/book/src/development/infrastructure/sync.md deleted file mode 100644 index e1fe92f95250..000000000000 --- a/book/src/development/infrastructure/sync.md +++ /dev/null @@ -1,121 +0,0 @@ -# Syncing changes between Clippy and [`rust-lang/rust`] - -Clippy currently gets built with a pinned nightly version. - -In the `rust-lang/rust` repository, where rustc resides, there's a copy of -Clippy that compiler hackers modify from time to time to adapt to changes in the -unstable API of the compiler. - -We need to sync these changes back to this repository periodically, and the -changes made to this repository in the meantime also need to be synced to the -`rust-lang/rust` repository. - -To avoid flooding the `rust-lang/rust` PR queue, this two-way sync process is -done in a bi-weekly basis if there's no urgent changes. This is done starting on -the day of the Rust stable release and then every other week. That way we -guarantee that we keep this repo up to date with the latest compiler API, and -every feature in Clippy is available for 2 weeks in nightly, before it can get -to beta. For reference, the first sync following this cadence was performed the -2020-08-27. - -This process is described in detail in the following sections. For general -information about `subtree`s in the Rust repository see [the rustc-dev-guide][subtree]. - -## Patching git-subtree to work with big repos - -Currently, there's a bug in `git-subtree` that prevents it from working properly -with the [`rust-lang/rust`] repo. There's an open PR to fix that, but it's -stale. Before continuing with the following steps, we need to manually apply -that fix to our local copy of `git-subtree`. - -You can get the patched version of `git-subtree` from [here][gitgitgadget-pr]. -Put this file under `/usr/lib/git-core` (making a backup of the previous file) -and make sure it has the proper permissions: - -```bash -sudo cp --backup /path/to/patched/git-subtree.sh /usr/lib/git-core/git-subtree -sudo chmod --reference=/usr/lib/git-core/git-subtree~ /usr/lib/git-core/git-subtree -sudo chown --reference=/usr/lib/git-core/git-subtree~ /usr/lib/git-core/git-subtree -``` - -> _Note:_ The first time running `git subtree push` a cache has to be built. -> This involves going through the complete Clippy history once. For this you -> have to increase the stack limit though, which you can do with `ulimit -s -> 60000`. Make sure to run the `ulimit` command from the same session you call -> git subtree. - -> _Note:_ If you are a Debian user, `dash` is the shell used by default for -> scripts instead of `sh`. This shell has a hardcoded recursion limit set to -> 1,000. In order to make this process work, you need to force the script to run -> `bash` instead. You can do this by editing the first line of the `git-subtree` -> script and changing `sh` to `bash`. - -## Defining remotes - -You may want to define remotes, so you don't have to type out the remote -addresses on every sync. You can do this with the following commands (these -commands still have to be run inside the `rust` directory): - -```bash -# Set clippy-upstream remote for pulls -$ git remote add clippy-upstream https://github.com/rust-lang/rust-clippy -# Make sure to not push to the upstream repo -$ git remote set-url --push clippy-upstream DISABLED -# Set a local remote -$ git remote add clippy-local /path/to/rust-clippy -``` - -> Note: The following sections assume that you have set those remotes with the -> above remote names. - -## Performing the sync from [`rust-lang/rust`] to Clippy - -Here is a TL;DR version of the sync process (all the following commands have -to be run inside the `rust` directory): - -1. Clone the [`rust-lang/rust`] repository or make sure it is up-to-date. -2. Checkout the commit from the latest available nightly. You can get it using - `rustup check`. -3. Sync the changes to the rust-copy of Clippy to your Clippy fork: - ```bash - # Be sure to either use a net-new branch, e.g. `sync-from-rust`, or delete the branch beforehand - # because changes cannot be fast forwarded and you have to run this command again. - git subtree push -P src/tools/clippy clippy-local sync-from-rust - ``` - - > _Note:_ Most of the time you have to create a merge commit in the - > `rust-clippy` repo (this has to be done in the Clippy repo, not in the - > rust-copy of Clippy): - ```bash - git fetch upstream # assuming upstream is the rust-lang/rust remote - git checkout sync-from-rust - git merge upstream/master --no-ff - ``` - > Note: This is one of the few instances where a merge commit is allowed in - > a PR. -4. Bump the nightly version in the Clippy repository by changing the date in the - rust-toolchain file to the current date and committing it with the message: - ```bash - git commit -m "Bump nightly version -> YYYY-MM-DD" - ``` -5. Open a PR to `rust-lang/rust-clippy` and wait for it to get merged (to - accelerate the process ping the `@rust-lang/clippy` team in your PR and/or - ask them in the [Zulip] stream.) - -[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/clippy - -## Performing the sync from Clippy to [`rust-lang/rust`] - -All the following commands have to be run inside the `rust` directory. - -1. Make sure you have checked out the latest `master` of `rust-lang/rust`. -2. Sync the `rust-lang/rust-clippy` master to the rust-copy of Clippy: - ```bash - git checkout -b sync-from-clippy - git subtree pull -P src/tools/clippy clippy-upstream master - ``` -3. Open a PR to [`rust-lang/rust`] - -[gitgitgadget-pr]: https://github.com/gitgitgadget/git/pull/493 -[subtree]: https://rustc-dev-guide.rust-lang.org/external-repos.html#external-dependencies-subtree -[`rust-lang/rust`]: https://github.com/rust-lang/rust diff --git a/book/src/development/lint_passes.md b/book/src/development/lint_passes.md deleted file mode 100644 index dde9e1a273bc..000000000000 --- a/book/src/development/lint_passes.md +++ /dev/null @@ -1,114 +0,0 @@ -# Lint passes - -Before working on the logic of a new lint, there is an important decision -that every Clippy developer must make: to use -[`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass]. - -In short, the `LateLintPass` has access to type and symbol information while the -`EarlyLintPass` doesn't. If you don't need access to type information, use the -`EarlyLintPass`. - -Let us expand on these two traits more below. - -## `EarlyLintPass` - -If you examine the documentation on [`EarlyLintPass`][early_lint_pass] closely, -you'll see that every method defined for this trait utilizes a -[`EarlyContext`][early_context]. In `EarlyContext`'s documentation, it states: - -> Context for lint checking of the AST, after expansion, before lowering to HIR. - -Voilà. `EarlyLintPass` works only on the Abstract Syntax Tree (AST) level. -And AST is generated during the [lexing and parsing][lexing_and_parsing] phase -of code compilation. Therefore, it doesn't know what a symbol means or information about types, and it should -be our trait choice for a new lint if the lint only deals with syntax-related issues. - -While linting speed has not been a concern for Clippy, -the `EarlyLintPass` is faster, and it should be your choice -if you know for sure a lint does not need type information. - -As a reminder, run the following command to generate boilerplate for lints -that use `EarlyLintPass`: - -```sh -$ cargo dev new_lint --name= --pass=early --category= -``` - -### Example for `EarlyLintPass` - -Take a look at the following code: - -```rust -let x = OurUndefinedType; -x.non_existing_method(); -``` - -From the AST perspective, both lines are "grammatically" correct. -The assignment uses a `let` and ends with a semicolon. The invocation -of a method looks fine, too. As programmers, we might raise a few -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 -the [Define New Lints](defining_lints.md) 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 -work with the AST and don't have to access the type system at all (the type system is where -`LateLintPass` comes into the picture). - -## `LateLintPass` - -In contrast to `EarlyLintPass`, `LateLintPass` contains type information. - -If you examine the documentation on [`LateLintPass`][late_lint_pass] closely, -you see that every method defined in this trait utilizes a -[`LateContext`][late_context]. - -In `LateContext`'s documentation we will find methods that -deal with type-checking, which do not exist in `EarlyContext`, such as: - -- [`maybe_typeck_results`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.LateContext.html#method.maybe_typeck_results) -- [`typeck_results`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.LateContext.html#method.typeck_results) - -### Example for `LateLintPass` - -Let us take a look with the following example: - -```rust -let x = OurUndefinedType; -x.non_existing_method(); -``` - -These two lines of code are syntactically correct code from the perspective -of the AST. We have an assignment and invoke a method on the variable that -is of a type. Grammatically, everything is in order for the parser. - -However, going down a level and looking at the type information, -the compiler will notice that both `OurUndefinedType` and `non_existing_method()` -**are undefined**. - -As Clippy developers, to access such type information, we must implement -`LateLintPass` on our lint. -When you browse through Clippy's lints, you will notice that almost every lint -is implemented in a `LateLintPass`, specifically because we often need to check -not only for syntactic issues but also type information. - -Another limitation of the `EarlyLintPass` is that the nodes are only identified -by their position in the AST. This means that you can't just get an `id` and -request a certain node. For most lints that is fine, but we have some lints -that require the inspection of other nodes, which is easier at the HIR level. -In these cases, `LateLintPass` is the better choice. - -As a reminder, run the following command to generate boilerplate for lints -that use `LateLintPass`: - -```sh -$ cargo dev new_lint --name= --pass=late --category= -``` - -[early_context]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.EarlyContext.html -[early_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.EarlyLintPass.html -[late_context]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.LateContext.html -[late_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html -[lexing_and_parsing]: https://rustc-dev-guide.rust-lang.org/overview.html#lexing-and-parsing diff --git a/book/src/development/macro_expansions.md b/book/src/development/macro_expansions.md deleted file mode 100644 index 125b6c4bc5be..000000000000 --- a/book/src/development/macro_expansions.md +++ /dev/null @@ -1,158 +0,0 @@ -# Dealing with macros and expansions - -Sometimes we might encounter Rust macro expansions while working with Clippy. -While macro expansions are not as dramatic and profound as the expansion -of our universe, they can certainly bring chaos to the orderly world -of code and logic. - -The general rule of thumb is that we should ignore code with macro -expansions when working with Clippy because the code can be dynamic -in ways that are difficult or impossible for us to foresee. - -## False Positives - -What exactly do we mean by _dynamic in ways that are difficult to foresee_? - -Macros are [expanded][expansion] in the `EarlyLintPass` level, -so the Abstract Syntax Tree (AST) is generated in place of macros. -This means the code which we work with in Clippy is already expanded. - -If we wrote a new lint, there is a possibility that the lint is -triggered in macro-generated code. Since this expanded macro code -is not written by the macro's user but really by the macro's author, -the user cannot and should not be responsible for fixing the issue -that triggers the lint. - -Besides, a [Span] in a macro can be changed by the macro author. -Therefore, any lint check related to lines or columns should be -avoided since they might be changed at any time and become unreliable -or incorrect information. - -Because of these unforeseeable or unstable behaviors, macro expansion -should often not be regarded as a part of the stable API. -This is also why most lints check if they are inside a macro or not -before emitting suggestions to the end user to avoid false positives. - -## How to Work with Macros - -Several functions are available for working with macros. - -### The `Span.from_expansion` method - -We could utilize a `span`'s [`from_expansion`] method, which -detects if the `span` is from a macro expansion / desugaring. -This is a very common first step in a lint: - -```rust -if expr.span.from_expansion() { - // We most likely want to ignore it. - return; -} -``` - -### `Span.ctxt` method - -The `span`'s context, given by the method [`ctxt`] and returning [SyntaxContext], -represents if the span is from a macro expansion and, if it is, which -macro call expanded this span. - -Sometimes, it is useful to check if the context of two spans are equal. -For instance, suppose we have the following line of code that would -expand into `1 + 0`: - -```rust -// The following code expands to `1 + 0` for both `EarlyLintPass` and `LateLintPass` -1 + mac!() -``` - -Assuming that we'd collect the `1` expression as a variable `left` and the -`0`/`mac!()` expression as a variable `right`, we can simply compare their -contexts. If the context is different, then we most likely are dealing with a -macro expansion and should just ignore it: - -```rust -if left.span.ctxt() != right.span.ctxt() { - // The code author most likely cannot modify this expression - return; -} -``` - -> **Note**: Code that is not from expansion is in the "root" context. -> So any spans whose `from_expansion` returns `false` can be assumed -> to have the same context. Because of this, using `span.from_expansion()` -> is often sufficient. - -Going a bit deeper, in a simple expression such as `a == b`, -`a` and `b` have the same context. -However, in a `macro_rules!` with `a == $b`, `$b` is expanded to -an expression that contains a different context from `a`. - -Take a look at the following macro `m`: - -```rust -macro_rules! m { - ($a:expr, $b:expr) => { - if $a.is_some() { - $b; - } - } -} - -let x: Option = Some(42); -m!(x, x.unwrap()); -``` - -If the `m!(x, x.unwrap());` line is expanded, we would get two expanded -expressions: - -- `x.is_some()` (from the `$a.is_some()` line in the `m` macro) -- `x.unwrap()` (corresponding to `$b` in the `m` macro) - -Suppose `x.is_some()` expression's span is associated with the `x_is_some_span` variable -and `x.unwrap()` expression's span is associated with `x_unwrap_span` variable, -we could assume that these two spans do not share the same context: - -```rust -// x.is_some() is from inside the macro -// x.unwrap() is from outside the macro -assert_ne!(x_is_some_span.ctxt(), x_unwrap_span.ctxt()); -``` - -### The `in_external_macro` function - -`rustc_middle::lint` provides a function ([`in_external_macro`]) that can -detect if the given span is from a macro defined in a foreign crate. - -Therefore, if we really want a new lint to work with macro-generated code, -this is the next line of defense to avoid macros not defined inside -the current crate since it is unfair to the user if Clippy lints code -which the user cannot change. - -For example, assume we have the following code that is being examined -by Clippy: - -```rust -#[macro_use] -extern crate a_foreign_crate_with_macros; - -// `foo` macro is defined in `a_foreign_crate_with_macros` -foo!("bar"); -``` - -Also assume that we get the corresponding variable `foo_span` for the -`foo` macro call, we could decide not to lint if `in_external_macro` -results in `true` (note that `cx` can be `EarlyContext` or `LateContext`): - -```rust -if in_external_macro(cx.sess(), foo_span) { - // We should ignore macro from a foreign crate. - return; -} -``` - -[`ctxt`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html#method.ctxt -[expansion]: https://rustc-dev-guide.rust-lang.org/macro-expansion.html#expansion-and-ast-integration -[`from_expansion`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html#method.from_expansion -[`in_external_macro`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/lint/fn.in_external_macro.html -[Span]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html -[SyntaxContext]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/hygiene/struct.SyntaxContext.html diff --git a/book/src/development/method_checking.md b/book/src/development/method_checking.md deleted file mode 100644 index 56d1be37519e..000000000000 --- a/book/src/development/method_checking.md +++ /dev/null @@ -1,93 +0,0 @@ -# Method Checking - -In some scenarios we might want to check for methods when developing -a lint. There are two kinds of questions that we might be curious about: - -- Invocation: Does an expression call a specific method? -- Definition: Does an `impl` define a method? - -## Checking if an `expr` is calling a specific method - -Suppose we have an `expr`, we can check whether it calls a specific -method, e.g. `our_fancy_method`, by performing a pattern match on -the [`ExprKind`] that we can access from `expr.kind`: - -```rust -use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_span::sym; -use clippy_utils::is_trait_method; - -impl<'tcx> LateLintPass<'tcx> for OurFancyMethodLint { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - // Check our expr is calling a method with pattern matching - if let hir::ExprKind::MethodCall(path, _, [self_arg, ..]) = &expr.kind - // Check if the name of this method is `our_fancy_method` - && path.ident.name == sym!(our_fancy_method) - // We can check the type of the self argument whenever necessary. - // (It's necessary if we want to check that method is specifically belonging to a specific trait, - // for example, a `map` method could belong to user-defined trait instead of to `Iterator`) - // See the next section for more information. - && is_trait_method(cx, self_arg, sym::OurFancyTrait) - { - println!("`expr` is a method call for `our_fancy_method`"); - } - } -} -``` - -Take a closer look at the `ExprKind` enum variant [`MethodCall`] for more -information on the pattern matching. As mentioned in [Define -Lints](defining_lints.md#lint-types), the `methods` lint type is full of pattern -matching with `MethodCall` in case the reader wishes to explore more. - -Additionally, we use the [`clippy_utils::sym!`][sym] macro to conveniently -convert an input `our_fancy_method` into a `Symbol` and compare that symbol to -the [`Ident`]'s name in the [`PathSegment`] in the [`MethodCall`]. - -## Checking if a `impl` block implements a method - -While sometimes we want to check whether a method is being called or not, other -times we want to know if our `Ty` defines a method. - -To check if our `impl` block defines a method `our_fancy_method`, we will -utilize the [`check_impl_item`] method that is available in our beloved -[`LateLintPass`] (for more information, refer to the ["Lint -Passes"](lint_passes.md) chapter in the Clippy book). This method provides us -with an [`ImplItem`] struct, which represents anything within an `impl` block. - -Let us take a look at how we might check for the implementation of -`our_fancy_method` on a type: - -```rust -use clippy_utils::ty::is_type_diagnostic_item; -use clippy_utils::return_ty; -use rustc_hir::{ImplItem, ImplItemKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_span::symbol::sym; - -impl<'tcx> LateLintPass<'tcx> for MyTypeImpl { - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { - // Check if item is a method/function - if let ImplItemKind::Fn(ref signature, _) = impl_item.kind - // Check the method is named `our_fancy_method` - && impl_item.ident.name == sym!(our_fancy_method) - // We can also check it has a parameter `self` - && signature.decl.implicit_self.has_implicit_self() - // We can go even further and even check if its return type is `String` - && is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::String) - { - println!("`our_fancy_method` is implemented!"); - } - } -} -``` - -[`check_impl_item`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html#method.check_impl_item -[`ExprKind`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/enum.ExprKind.html -[`Ident`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_span/symbol/struct.Ident.html -[`ImplItem`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_hir/hir/struct.ImplItem.html -[`LateLintPass`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html -[`MethodCall`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/enum.ExprKind.html#variant.MethodCall -[`PathSegment`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/struct.PathSegment.html -[sym]: https://doc.rust-lang.org/stable/nightly-rustc/clippy_utils/macro.sym.html diff --git a/book/src/development/proposals/README.md b/book/src/development/proposals/README.md deleted file mode 100644 index 059c22ce1ce8..000000000000 --- a/book/src/development/proposals/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Proposals - -This chapter is about accepted proposals for changes that should be worked on in -or around Clippy in the long run. - -Besides adding more and more lints and improve the lints that Clippy already -has, Clippy is also interested in making the experience of its users, developers -and maintainers better over time. Projects that address bigger picture things -like this usually take more time, and it is useful to have a proposal for those -first. This is the place where such proposals are collected, so that we can -refer to them when working on them. diff --git a/book/src/development/proposals/roadmap-2021.md b/book/src/development/proposals/roadmap-2021.md deleted file mode 100644 index 4406616bbb61..000000000000 --- a/book/src/development/proposals/roadmap-2021.md +++ /dev/null @@ -1,235 +0,0 @@ -# Roadmap 2021 - -# Summary - -This Roadmap lays out the plans for Clippy in 2021: - -- Improving usability and reliability -- Improving experience of contributors and maintainers -- Develop and specify processes - -Members of the Clippy team will be assigned tasks from one or more of these -topics. The team member is then responsible to complete the assigned tasks. This -can either be done by implementing them or by providing mentorship to interested -contributors. - -# Motivation - -With the ongoing growth of the Rust language and with that of the whole -ecosystem, also Clippy gets more and more users and contributors. This is good -for the project, but also brings challenges along. Some of these challenges are: - -- More issues about reliability or usability are popping up -- Traffic is hard to handle for a small team -- Bigger projects don't get completed due to the lack of processes and/or time - of the team members - -Additionally, according to the [Rust Roadmap 2021], clear processes should be -defined by every team and unified across teams. This Roadmap is the first step -towards this. - -[Rust Roadmap 2021]: https://github.com/rust-lang/rfcs/pull/3037 - -# Explanation - -This section will explain the things that should be done in 2021. It is -important to note, that this document focuses on the "What?", not the "How?". -The later will be addressed in follow-up tracking issue, with an assigned team -member. - -The following is split up in two major sections. The first section covers the -user facing plans, the second section the internal plans. - -## User Facing - -Clippy should be as pleasant to use and configure as possible. This section -covers plans that should be implemented to improve the situation of Clippy in -this regard. - -### Usability - -In the following, plans to improve the usability are covered. - -#### No Output After `cargo check` - -Currently, when `cargo clippy` is run after `cargo check`, it does not produce -any output. This is especially problematic since `rust-analyzer` is on the rise, -and it uses `cargo check` for checking code. A fix is already implemented, but -it still has to be pushed over the finish line. This also includes the -stabilization of the `cargo clippy --fix` command or the support of multi-span -suggestions in `rustfix`. - -- [#4612](https://github.com/rust-lang/rust-clippy/issues/4612) - -#### `lints.toml` Configuration - -This is something that comes up every now and then: a reusable configuration -file, where lint levels can be defined. Discussions about this often lead to -nothing specific or to "we need an RFC for this". And this is exactly what needs -to be done. Get together with the cargo team and write an RFC and implement such -a configuration file somehow and somewhere. - -- [#3164](https://github.com/rust-lang/rust-clippy/issues/3164) -- [cargo#5034](https://github.com/rust-lang/cargo/issues/5034) -- [IRLO](https://internals.rust-lang.org/t/proposal-cargo-lint-configuration/9135/8) - -#### Lint Groups - -There are more and more issues about managing lints in Clippy popping up. Lints -are hard to implement with a guarantee of no/few false positives (FPs). One way -to address this might be to introduce more lint groups to give users the ability -to better manage lints, or improve the process of classifying lints, so that -disabling lints due to FPs becomes rare. It is important to note, that Clippy -lints are less conservative than `rustc` lints, which won't change in the -future. - -- [#5537](https://github.com/rust-lang/rust-clippy/issues/5537) -- [#6366](https://github.com/rust-lang/rust-clippy/issues/6366) - -### Reliability - -In the following, plans to improve the reliability are covered. - -#### False Positive Rate - -In the worst case, new lints are only available in nightly for 2 weeks, before -hitting beta and ultimately stable. This and the fact that fewer people use -nightly Rust nowadays makes it more probable that a lint with many FPs hits -stable. This leads to annoyed users, that will disable these new lints in the -best case and to more annoyed users, that will stop using Clippy in the worst. -A process should be developed and implemented to prevent this from happening. - -- [#6429](https://github.com/rust-lang/rust-clippy/issues/6429) - -## Internal - -(The end of) 2020 has shown, that Clippy has to think about the available -resources, especially regarding management and maintenance of the project. This -section address issues affecting team members and contributors. - -### Management - -In 2020 Clippy achieved over 1000 open issues with regularly between 25-35 open -PRs. This is simultaneously a win and a loss. More issues and PRs means more -people are interested in Clippy and in contributing to it. On the other hand, it -means for team members more work and for contributors longer wait times for -reviews. The following will describe plans how to improve the situation for both -team members and contributors. - -#### Clear Expectations for Team Members - -According to the [Rust Roadmap 2021], a document specifying what it means to be -a member of the team should be produced. This should not put more pressure on -the team members, but rather help them and interested folks to know what the -expectations are. With this it should also be easier to recruit new team members -and may encourage people to get in touch, if they're interested to join. - -#### Scaling up the Team - -More people means less work for each individual. Together with the document -about expectations for team members, a document defining the process of how to -join the team should be produced. This can also increase the stability of the -team, in case of current members dropping out (temporarily). There can also be -different roles in the team, like people triaging vs. people reviewing. - -#### Regular Meetings - -Other teams have regular meetings. Clippy is big enough that it might be worth -to also do them. Especially if more people join the team, this can be important -for sync-ups. Besides the asynchronous communication, that works well for -working on separate lints, a meeting adds a synchronous alternative at a known -time. This is especially helpful if there are bigger things that need to be -discussed (like the projects in this roadmap). For starters bi-weekly meetings -before Rust syncs might make sense. - -#### Triaging - -To get a handle on the influx of open issues, a process for triaging issues and -PRs should be developed. Officially, Clippy follows the Rust triage process, but -currently no one enforces it. This can be improved by sharing triage teams -across projects or by implementing dashboards / tools which simplify triaging. - -### Development - -Improving the developer and contributor experience is something the Clippy team -works on regularly. Though, some things might need special attention and -planing. These topics are listed in the following. - -#### Process for New and Existing Lints - -As already mentioned above, classifying new lints gets quite hard, because the -probability of a buggy lint getting into stable is quite high. A process should -be implemented on how to classify lints. In addition, a test system should be -developed to find out which lints are currently problematic in real world code -to fix or disable them. - -- [#6429 (comment)](https://github.com/rust-lang/rust-clippy/issues/6429#issuecomment-741056379) -- [#6429 (comment)](https://github.com/rust-lang/rust-clippy/issues/6429#issuecomment-741153345) - -#### Processes - -Related to the point before, a process for suggesting and discussing major -changes should be implemented. It's also not clearly defined when a lint should -be enabled or disabled by default. This can also be improved by the test system -mentioned above. - -#### Dev-Tools - -There's already `cargo dev` which makes Clippy development easier and more -pleasant. This can still be expanded, so that it covers more areas of the -development process. - -- [#5394](https://github.com/rust-lang/rust-clippy/issues/5394) - -#### Contributor Guide - -Similar to a Clippy Book, which describes how to use Clippy, a book about how to -contribute to Clippy might be helpful for new and existing contributors. There's -already the `doc` directory in the Clippy repo, this can be turned into a -`mdbook`. - -#### `rustc` integration - -Recently Clippy was integrated with `git subtree` into the `rust-lang/rust` -repository. This made syncing between the two repositories easier. A -`#[non_exhaustive]` list of things that still can be improved is: - -1. Use the same `rustfmt` version and configuration as `rustc`. -2. Make `cargo dev` work in the Rust repo, just as it works in the Clippy repo. - E.g. `cargo dev bless` or `cargo dev update_lints`. And even add more things - to it that might be useful for the Rust repo, e.g. `cargo dev deprecate`. -3. Easier sync process. The `subtree` situation is not ideal. - -## Prioritization - -The most pressing issues for users of Clippy are of course the user facing -issues. So there should be a priority on those issues, but without losing track -of the internal issues listed in this document. - -Getting the FP rate of warn/deny-by-default lints under control should have the -highest priority. Other user facing issues should also get a high priority, but -shouldn't be in the way of addressing internal issues. - -To better manage the upcoming projects, the basic internal processes, like -meetings, tracking issues and documentation, should be established as soon as -possible. They might even be necessary to properly manage the projects, -regarding the user facing issues. - -# Prior Art - -## Rust Roadmap - -Rust's roadmap process was established by [RFC 1728] in 2016. Since then every -year a roadmap was published, that defined the bigger plans for the coming -years. This year roadmap can be found [here][Rust Roadmap 2021]. - -[RFC 1728]: https://rust-lang.github.io/rfcs/1728-north-star.html - -# Drawbacks - -## Big Roadmap - -This roadmap is pretty big and not all items listed in this document might be -addressed during 2021. Because this is the first roadmap for Clippy, having open -tasks at the end of 2021 is fine, but they should be revisited in the 2022 -roadmap. diff --git a/book/src/development/proposals/syntax-tree-patterns.md b/book/src/development/proposals/syntax-tree-patterns.md deleted file mode 100644 index 285488cec55c..000000000000 --- a/book/src/development/proposals/syntax-tree-patterns.md +++ /dev/null @@ -1,986 +0,0 @@ -- Feature Name: syntax-tree-patterns -- Start Date: 2019-03-12 -- RFC PR: [#3875](https://github.com/rust-lang/rust-clippy/pull/3875) - -# Summary - -Introduce a domain-specific language (similar to regular expressions) that -allows to describe lints using *syntax tree patterns*. - - -# Motivation - -Finding parts of a syntax tree (AST, HIR, ...) that have certain properties -(e.g. "*an if that has a block as its condition*") is a major task when writing -lints. For non-trivial lints, it often requires nested pattern matching of AST / -HIR nodes. For example, testing that an expression is a boolean literal requires -the following checks: - -```rust,ignore -if let ast::ExprKind::Lit(lit) = &expr.node { - if let ast::LitKind::Bool(_) = &lit.node { - ... - } -} -``` - -Writing this kind of matching code quickly becomes a complex task and the -resulting code is often hard to comprehend. The code below shows a simplified -version of the pattern matching required by the `collapsible_if` lint: - -```rust,ignore -// simplified version of the collapsible_if lint -if let ast::ExprKind::If(check, then, None) = &expr.node { - if then.stmts.len() == 1 { - if let ast::StmtKind::Expr(inner) | ast::StmtKind::Semi(inner) = &then.stmts[0].node { - if let ast::ExprKind::If(check_inner, content, None) = &inner.node { - ... - } - } - } -} -``` - -The `if_chain` macro can improve readability by flattening the nested if -statements, but the resulting code is still quite hard to read: - -```rust -// simplified version of the collapsible_if lint -if_chain! { - if let ast::ExprKind::If(check, then, None) = &expr.node; - if then.stmts.len() == 1; - if let ast::StmtKind::Expr(inner) | ast::StmtKind::Semi(inner) = &then.stmts[0].node; - if let ast::ExprKind::If(check_inner, content, None) = &inner.node; - then { - ... - } -} -``` - -The code above matches if expressions that contain only another if expression -(where both ifs don't have an else branch). While it's easy to explain what the -lint does, it's hard to see that from looking at the code samples above. - -Following the motivation above, the first goal this RFC is to **simplify writing -and reading lints**. - -The second part of the motivation is clippy's dependence on unstable -compiler-internal data structures. Clippy lints are currently written against -the compiler's AST / HIR which means that even small changes in these data -structures might break a lot of lints. The second goal of this RFC is to **make -lints independent of the compiler's AST / HIR data structures**. - -# Approach - -A lot of complexity in writing lints currently seems to come from having to -manually implement the matching logic (see code samples above). It's an -imperative style that describes *how* to match a syntax tree node instead of -specifying *what* should be matched against declaratively. In other areas, it's -common to use declarative patterns to describe desired information and let the -implementation do the actual matching. A well-known example of this approach are -[regular expressions](https://en.wikipedia.org/wiki/Regular_expression). Instead -of writing code that detects certain character sequences, one can describe a -search pattern using a domain-specific language and search for matches using -that pattern. The advantage of using a declarative domain-specific language is -that its limited domain (e.g. matching character sequences in the case of -regular expressions) allows to express entities in that domain in a very natural -and expressive way. - -While regular expressions are very useful when searching for patterns in flat -character sequences, they cannot easily be applied to hierarchical data -structures like syntax trees. This RFC therefore proposes a pattern matching -system that is inspired by regular expressions and designed for hierarchical -syntax trees. - -# Guide-level explanation - -This proposal adds a `pattern!` macro that can be used to specify a syntax tree -pattern to search for. A simple pattern is shown below: - -```rust -pattern!{ - my_pattern: Expr = - Lit(Bool(false)) -} -``` - -This macro call defines a pattern named `my_pattern` that can be matched against -an `Expr` syntax tree node. The actual pattern (`Lit(Bool(false))` in this case) -defines which syntax trees should match the pattern. This pattern matches -expressions that are boolean literals with value `false`. - -The pattern can then be used to implement lints in the following way: - -```rust,ignore -... - -impl EarlyLintPass for MyAwesomeLint { - fn check_expr(&mut self, cx: &EarlyContext, expr: &syntax::ast::Expr) { - - if my_pattern(expr).is_some() { - cx.span_lint( - MY_AWESOME_LINT, - expr.span, - "This is a match for a simple pattern. Well done!", - ); - } - - } -} -``` - -The `pattern!` macro call expands to a function `my_pattern` that expects a -syntax tree expression as its argument and returns an `Option` that indicates -whether the pattern matched. - -> Note: The result type is explained in more detail in [a later -> section](#the-result-type). For now, it's enough to know that the result is -> `Some` if the pattern matched and `None` otherwise. - -## Pattern syntax - -The following examples demonstrate the pattern syntax: - - -#### Any (`_`) - -The simplest pattern is the any pattern. It matches anything and is therefore -similar to regex's `*`. - -```rust -pattern!{ - // matches any expression - my_pattern: Expr = - _ -} -``` - -#### Node (`()`) - -Nodes are used to match a specific variant of an AST node. A node has a name and -a number of arguments that depends on the node type. For example, the `Lit` node -has a single argument that describes the type of the literal. As another -example, the `If` node has three arguments describing the if's condition, then -block and else block. - -```rust -pattern!{ - // matches any expression that is a literal - my_pattern: Expr = - Lit(_) -} - -pattern!{ - // matches any expression that is a boolean literal - my_pattern: Expr = - Lit(Bool(_)) -} - -pattern!{ - // matches if expressions that have a boolean literal in their condition - // Note: The `_?` syntax here means that the else branch is optional and can be anything. - // This is discussed in more detail in the section `Repetition`. - my_pattern: Expr = - If( Lit(Bool(_)) , _, _?) -} -``` - - -#### Literal (``) - -A pattern can also contain Rust literals. These literals match themselves. - -```rust -pattern!{ - // matches the boolean literal false - my_pattern: Expr = - Lit(Bool(false)) -} - -pattern!{ - // matches the character literal 'x' - my_pattern: Expr = - Lit(Char('x')) -} -``` - -#### Alternations (`a | b`) - -```rust -pattern!{ - // matches if the literal is a boolean or integer literal - my_pattern: Lit = - Bool(_) | Int(_) -} - -pattern!{ - // matches if the expression is a char literal with value 'x' or 'y' - my_pattern: Expr = - Lit( Char('x' | 'y') ) -} -``` - -#### Empty (`()`) - -The empty pattern represents an empty sequence or the `None` variant of an -optional. - -```rust -pattern!{ - // matches if the expression is an empty array - my_pattern: Expr = - Array( () ) -} - -pattern!{ - // matches if expressions that don't have an else clause - my_pattern: Expr = - If(_, _, ()) -} -``` - -#### Sequence (` `) - -```rust -pattern!{ - // matches the array [true, false] - my_pattern: Expr = - Array( Lit(Bool(true)) Lit(Bool(false)) ) -} -``` - -#### Repetition (`*`, `+`, `?`, `{n}`, `{n,m}`, `{n,}`) - -Elements may be repeated. The syntax for specifying repetitions is identical to -[regex's syntax](https://docs.rs/regex/1.1.2/regex/#repetitions). - -```rust -pattern!{ - // matches arrays that contain 2 'x's as their last or second-last elements - // Examples: - // ['x', 'x'] match - // ['x', 'x', 'y'] match - // ['a', 'b', 'c', 'x', 'x', 'y'] match - // ['x', 'x', 'y', 'z'] no match - my_pattern: Expr = - Array( _* Lit(Char('x')){2} _? ) -} - -pattern!{ - // matches if expressions that **may or may not** have an else block - // Attn: `If(_, _, _)` matches only ifs that **have** an else block - // - // | if with else block | if without else block - // If(_, _, _) | match | no match - // If(_, _, _?) | match | match - // If(_, _, ()) | no match | match - my_pattern: Expr = - If(_, _, _?) -} -``` - -#### Named submatch (`#`) - -```rust -pattern!{ - // matches character literals and gives the literal the name foo - my_pattern: Expr = - Lit(Char(_)#foo) -} - -pattern!{ - // matches character literals and gives the char the name bar - my_pattern: Expr = - Lit(Char(_#bar)) -} - -pattern!{ - // matches character literals and gives the expression the name baz - my_pattern: Expr = - Lit(Char(_))#baz -} -``` - -The reason for using named submatches is described in the section [The result -type](#the-result-type). - -### Summary - -The following table gives an summary of the pattern syntax: - -| Syntax | Concept | Examples | -|-------------------------|------------------|--------------------------------------------| -|`_` | Any | `_` | -|`()` | Node | `Lit(Bool(true))`, `If(_, _, _)` | -|`` | Literal | `'x'`, `false`, `101` | -|` \| ` | Alternation | `Char(_) \| Bool(_)` | -|`()` | Empty | `Array( () )` | -|` ` | Sequence | `Tuple( Lit(Bool(_)) Lit(Int(_)) Lit(_) )` | -|`*`
`
+`
`
?`
`
{n}`
`
{n,m}`
`
{n,}` | Repetition





| `Array( _* )`,
`Block( Semi(_)+ )`,
`If(_, _, Block(_)?)`,
`Array( Lit(_){10} )`,
`Lit(_){5,10}`,
`Lit(Bool(_)){10,}` | -|`
#` | Named submatch | `Lit(Int(_))#foo` `Lit(Int(_#bar))` | - - -## The result type - -A lot of lints require checks that go beyond what the pattern syntax described -above can express. For example, a lint might want to check whether a node was -created as part of a macro expansion or whether there's no comment above a node. -Another example would be a lint that wants to match two nodes that have the same -value (as needed by lints like `almost_swapped`). Instead of allowing users to -write these checks into the pattern directly (which might make patterns hard to -read), the proposed solution allows users to assign names to parts of a pattern -expression. When matching a pattern against a syntax tree node, the return value -will contain references to all nodes that were matched by these named -subpatterns. This is similar to capture groups in regular expressions. - -For example, given the following pattern - -```rust -pattern!{ - // matches character literals - my_pattern: Expr = - Lit(Char(_#val_inner)#val)#val_outer -} -``` - -one could get references to the nodes that matched the subpatterns in the -following way: - -```rust,ignore -... -fn check_expr(expr: &syntax::ast::Expr) { - if let Some(result) = my_pattern(expr) { - result.val_inner // type: &char - result.val // type: &syntax::ast::Lit - result.val_outer // type: &syntax::ast::Expr - } -} -``` - -The types in the `result` struct depend on the pattern. For example, the -following pattern - -```rust -pattern!{ - // matches arrays of character literals - my_pattern_seq: Expr = - Array( Lit(_)*#foo ) -} -``` - -matches arrays that consist of any number of literal expressions. Because those -expressions are named `foo`, the result struct contains a `foo` attribute which -is a vector of expressions: - -```rust,ignore -... -if let Some(result) = my_pattern_seq(expr) { - result.foo // type: Vec<&syntax::ast::Expr> -} -``` - -Another result type occurs when a name is only defined in one branch of an -alternation: - -```rust -pattern!{ - // matches if expression is a boolean or integer literal - my_pattern_alt: Expr = - Lit( Bool(_#bar) | Int(_) ) -} -``` - -In the pattern above, the `bar` name is only defined if the pattern matches a -boolean literal. If it matches an integer literal, the name isn't set. To -account for this, the result struct's `bar` attribute is an option type: - -```rust,ignore -... -if let Some(result) = my_pattern_alt(expr) { - result.bar // type: Option<&bool> -} -``` - -It's also possible to use a name in multiple alternation branches if they have -compatible types: - -```rust,ignore -pattern!{ - // matches if expression is a boolean or integer literal - my_pattern_mult: Expr = - Lit(_#baz) | Array( Lit(_#baz) ) -} -... -if let Some(result) = my_pattern_mult(expr) { - result.baz // type: &syntax::ast::Lit -} -``` - -Named submatches are a **flat** namespace and this is intended. In the example -above, two different sub-structures are assigned to a flat name. I expect that -for most lints, a flat namespace is sufficient and easier to work with than a -hierarchical one. - -#### Two stages - -Using named subpatterns, users can write lints in two stages. First, a coarse -selection of possible matches is produced by the pattern syntax. In the second -stage, the named subpattern references can be used to do additional tests like -asserting that a node hasn't been created as part of a macro expansion. - -## Implementing clippy lints using patterns - -As a "real-world" example, I re-implemented the `collapsible_if` lint using -patterns. The code can be found -[here](https://github.com/fkohlgrueber/rust-clippy-pattern/blob/039b07ecccaf96d6aa7504f5126720d2c9cceddd/clippy_lints/src/collapsible_if.rs#L88-L163). -The pattern-based version passes all test cases that were written for -`collapsible_if`. - - -# Reference-level explanation - -## Overview - -The following diagram shows the dependencies between the main parts of the -proposed solution: - -``` - Pattern syntax - | - | parsing / lowering - v - PatternTree - ^ - | - | - IsMatch trait - | - | - +---------------+-----------+---------+ - | | | | - v v v v - syntax::ast rustc::hir syn ... -``` - -The pattern syntax described in the previous section is parsed / lowered into -the so-called *PatternTree* data structure that represents a valid syntax tree -pattern. Matching a *PatternTree* against an actual syntax tree (e.g. rust ast / -hir or the syn ast, ...) is done using the *IsMatch* trait. - -The *PatternTree* and the *IsMatch* trait are introduced in more detail in the -following sections. - -## PatternTree - -The core data structure of this RFC is the **PatternTree**. - -It's a data structure similar to rust's AST / HIR, but with the following -differences: - -- The PatternTree doesn't contain parsing information like `Span`s -- The PatternTree can represent alternatives, sequences and optionals - -The code below shows a simplified version of the current PatternTree: - -> Note: The current implementation can be found -> [here](https://github.com/fkohlgrueber/pattern-matching/blob/dfb3bc9fbab69cec7c91e72564a63ebaa2ede638/pattern-match/src/pattern_tree.rs#L50-L96). - - -```rust -pub enum Expr { - Lit(Alt), - Array(Seq), - Block_(Alt), - If(Alt, Alt, Opt), - IfLet( - Alt, - Opt, - ), -} - -pub enum Lit { - Char(Alt), - Bool(Alt), - Int(Alt), -} - -pub enum Stmt { - Expr(Alt), - Semi(Alt), -} - -pub enum BlockType { - Block(Seq), -} -``` - -The `Alt`, `Seq` and `Opt` structs look like these: - -> Note: The current implementation can be found -> [here](https://github.com/fkohlgrueber/pattern-matching/blob/dfb3bc9fbab69cec7c91e72564a63ebaa2ede638/pattern-match/src/matchers.rs#L35-L60). - -```rust,ignore -pub enum Alt { - Any, - Elmt(Box), - Alt(Box, Box), - Named(Box, ...) -} - -pub enum Opt { - Any, // anything, but not None - Elmt(Box), - None, - Alt(Box, Box), - Named(Box, ...) -} - -pub enum Seq { - Any, - Empty, - Elmt(Box), - Repeat(Box, RepeatRange), - Seq(Box, Box), - Alt(Box, Box), - Named(Box, ...) -} - -pub struct RepeatRange { - pub start: usize, - pub end: Option // exclusive -} -``` - -## Parsing / Lowering - -The input of a `pattern!` macro call is parsed into a `ParseTree` first and then -lowered to a `PatternTree`. - -Valid patterns depend on the *PatternTree* definitions. For example, the pattern -`Lit(Bool(_)*)` isn't valid because the parameter type of the `Lit` variant of -the `Expr` enum is `Any` and therefore doesn't support repetition (`*`). As -another example, `Array( Lit(_)* )` is a valid pattern because the parameter of -`Array` is of type `Seq` which allows sequences and repetitions. - -> Note: names in the pattern syntax correspond to *PatternTree* enum -> **variants**. For example, the `Lit` in the pattern above refers to the `Lit` -> variant of the `Expr` enum (`Expr::Lit`), not the `Lit` enum. - -## The IsMatch Trait - -The pattern syntax and the *PatternTree* are independent of specific syntax tree -implementations (rust ast / hir, syn, ...). When looking at the different -pattern examples in the previous sections, it can be seen that the patterns -don't contain any information specific to a certain syntax tree implementation. -In contrast, clippy lints currently match against ast / hir syntax tree nodes -and therefore directly depend on their implementation. - -The connection between the *PatternTree* and specific syntax tree -implementations is the `IsMatch` trait. It defines how to match *PatternTree* -nodes against specific syntax tree nodes. A simplified implementation of the -`IsMatch` trait is shown below: - -```rust,ignore -pub trait IsMatch { - fn is_match(&self, other: &'o O) -> bool; -} -``` - -This trait needs to be implemented on each enum of the *PatternTree* (for the -corresponding syntax tree types). For example, the `IsMatch` implementation for -matching `ast::LitKind` against the *PatternTree's* `Lit` enum might look like -this: - -```rust -impl IsMatch for Lit { - fn is_match(&self, other: &ast::LitKind) -> bool { - match (self, other) { - (Lit::Char(i), ast::LitKind::Char(j)) => i.is_match(j), - (Lit::Bool(i), ast::LitKind::Bool(j)) => i.is_match(j), - (Lit::Int(i), ast::LitKind::Int(j, _)) => i.is_match(j), - _ => false, - } - } -} -``` - -All `IsMatch` implementations for matching the current *PatternTree* against -`syntax::ast` can be found -[here](https://github.com/fkohlgrueber/pattern-matching/blob/dfb3bc9fbab69cec7c91e72564a63ebaa2ede638/pattern-match/src/ast_match.rs). - - -# Drawbacks - -#### Performance - -The pattern matching code is currently not optimized for performance, so it -might be slower than hand-written matching code. Additionally, the two-stage -approach (matching against the coarse pattern first and checking for additional -properties later) might be slower than the current practice of checking for -structure and additional properties in one pass. For example, the following lint - -```rust,ignore -pattern!{ - pat_if_without_else: Expr = - If( - _, - Block( - Expr( If(_, _, ())#inner ) - | Semi( If(_, _, ())#inner ) - )#then, - () - ) -} -... -fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { - if let Some(result) = pat_if_without_else(expr) { - if !block_starts_with_comment(cx, result.then) { - ... - } -} -``` - -first matches against the pattern and then checks that the `then` block doesn't -start with a comment. Using clippy's current approach, it's possible to check -for these conditions earlier: - -```rust,ignore -fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { - if_chain! { - if let ast::ExprKind::If(ref check, ref then, None) = expr.node; - if !block_starts_with_comment(cx, then); - if let Some(inner) = expr_block(then); - if let ast::ExprKind::If(ref check_inner, ref content, None) = inner.node; - then { - ... - } - } -} -``` - -Whether or not this causes performance regressions depends on actual patterns. -If it turns out to be a problem, the pattern matching algorithms could be -extended to allow "early filtering" (see the [Early Filtering](#early-filtering) -section in Future Possibilities). - -That being said, I don't see any conceptual limitations regarding pattern -matching performance. - -#### Applicability - -Even though I'd expect that a lot of lints can be written using the proposed -pattern syntax, it's unlikely that all lints can be expressed using patterns. I -suspect that there will still be lints that need to be implemented by writing -custom pattern matching code. This would lead to mix within clippy's codebase -where some lints are implemented using patterns and others aren't. This -inconsistency might be considered a drawback. - - -# Rationale and alternatives - -Specifying lints using syntax tree patterns has a couple of advantages compared -to the current approach of manually writing matching code. First, syntax tree -patterns allow users to describe patterns in a simple and expressive way. This -makes it easier to write new lints for both novices and experts and also makes -reading / modifying existing lints simpler. - -Another advantage is that lints are independent of specific syntax tree -implementations (e.g. AST / HIR, ...). When these syntax tree implementations -change, only the `IsMatch` trait implementations need to be adapted and existing -lints can remain unchanged. This also means that if the `IsMatch` trait -implementations were integrated into the compiler, updating the `IsMatch` -implementations would be required for the compiler to compile successfully. This -could reduce the number of times clippy breaks because of changes in the -compiler. Another advantage of the pattern's independence is that converting an -`EarlyLintPass` lint into a `LatePassLint` wouldn't require rewriting the whole -pattern matching code. In fact, the pattern might work just fine without any -adaptions. - - -## Alternatives - -### Rust-like pattern syntax - -The proposed pattern syntax requires users to know the structure of the -`PatternTree` (which is very similar to the AST's / HIR's structure) and also -the pattern syntax. An alternative would be to introduce a pattern syntax that -is similar to actual Rust syntax (probably like the `quote!` macro). For -example, a pattern that matches `if` expressions that have `false` in their -condition could look like this: - -```rust,ignore -if false { - #[*] -} -``` - -#### Problems - -Extending Rust syntax (which is quite complex by itself) with additional syntax -needed for specifying patterns (alternations, sequences, repetitions, named -submatches, ...) might become difficult to read and really hard to parse -properly. - -For example, a pattern that matches a binary operation that has `0` on both -sides might look like this: - -``` -0 #[*:BinOpKind] 0 -``` - -Now consider this slightly more complex example: - -``` -1 + 0 #[*:BinOpKind] 0 -``` - -The parser would need to know the precedence of `#[*:BinOpKind]` because it -affects the structure of the resulting AST. `1 + 0 + 0` is parsed as `(1 + 0) + -0` while `1 + 0 * 0` is parsed as `1 + (0 * 0)`. Since the pattern could be any -`BinOpKind`, the precedence cannot be known in advance. - -Another example of a problem would be named submatches. Take a look at this -pattern: - -```rust,ignore -fn test() { - 1 #foo -} -``` - -Which node is `#foo` referring to? `int`, `ast::Lit`, `ast::Expr`, `ast::Stmt`? -Naming subpatterns in a rust-like syntax is difficult because a lot of AST nodes -don't have a syntactic element that can be used to put the name tag on. In these -situations, the only sensible option would be to assign the name tag to the -outermost node (`ast::Stmt` in the example above), because the information of -all child nodes can be retrieved through the outermost node. The problem with -this then would be that accessing inner nodes (like `ast::Lit`) would again -require manual pattern matching. - -In general, Rust syntax contains a lot of code structure implicitly. This -structure is reconstructed during parsing (e.g. binary operations are -reconstructed using operator precedence and left-to-right) and is one of the -reasons why parsing is a complex task. The advantage of this approach is that -writing code is simpler for users. - -When writing *syntax tree patterns*, each element of the hierarchy might have -alternatives, repetitions, etc.. Respecting that while still allowing -human-friendly syntax that contains structure implicitly seems to be really -complex, if not impossible. - -Developing such a syntax would also require to maintain a custom parser that is -at least as complex as the Rust parser itself. Additionally, future changes in -the Rust syntax might be incompatible with such a syntax. - -In summary, I think that developing such a syntax would introduce a lot of -complexity to solve a relatively minor problem. - -The issue of users not knowing about the *PatternTree* structure could be solved -by a tool that, given a rust program, generates a pattern that matches only this -program (similar to the clippy author lint). - -For some simple cases (like the first example above), it might be possible to -successfully mix Rust and pattern syntax. This space could be further explored -in a future extension. - -# Prior art - -The pattern syntax is heavily inspired by regular expressions (repetitions, -alternatives, sequences, ...). - -From what I've seen until now, other linters also implement lints that directly -work on syntax tree data structures, just like clippy does currently. I would -therefore consider the pattern syntax to be *new*, but please correct me if I'm -wrong. - -# Unresolved questions - -#### How to handle multiple matches? - -When matching a syntax tree node against a pattern, there are possibly multiple -ways in which the pattern can be matched. A simple example of this would be the -following pattern: - -```rust -pattern!{ - my_pattern: Expr = - Array( _* Lit(_)+#literals) -} -``` - -This pattern matches arrays that end with at least one literal. Now given the -array `[x, 1, 2]`, should `1` be matched as part of the `_*` or the `Lit(_)+` -part of the pattern? The difference is important because the named submatch -`#literals` would contain 1 or 2 elements depending how the pattern is matched. -In regular expressions, this problem is solved by matching "greedy" by default -and "non-greedy" optionally. - -I haven't looked much into this yet because I don't know how relevant it is for -most lints. The current implementation simply returns the first match it finds. - -# Future possibilities - -#### Implement rest of Rust Syntax - -The current project only implements a small part of the Rust syntax. In the -future, this should incrementally be extended to more syntax to allow -implementing more lints. Implementing more of the Rust syntax requires extending -the `PatternTree` and `IsMatch` implementations, but should be relatively -straight-forward. - -#### Early filtering - -As described in the *Drawbacks/Performance* section, allowing additional checks -during the pattern matching might be beneficial. - -The pattern below shows how this could look like: - -```rust -pattern!{ - pat_if_without_else: Expr = - If( - _, - Block( - Expr( If(_, _, ())#inner ) - | Semi( If(_, _, ())#inner ) - )#then, - () - ) - where - !in_macro(#then.span); -} -``` - -The difference compared to the currently proposed two-stage filtering is that -using early filtering, the condition (`!in_macro(#then.span)` in this case) -would be evaluated as soon as the `Block(_)#then` was matched. - -Another idea in this area would be to introduce a syntax for backreferences. -They could be used to require that multiple parts of a pattern should match the -same value. For example, the `assign_op_pattern` lint that searches for `a = a -op b` and recommends changing it to `a op= b` requires that both occurrences of -`a` are the same. Using `=#...` as syntax for backreferences, the lint could be -implemented like this: - -```rust,ignore -pattern!{ - assign_op_pattern: Expr = - Assign(_#target, Binary(_, =#target, _) -} -``` - -#### Match descendant - -A lot of lints currently implement custom visitors that check whether any -subtree (which might not be a direct descendant) of the current node matches -some properties. This cannot be expressed with the proposed pattern syntax. -Extending the pattern syntax to allow patterns like "a function that contains at -least two return statements" could be a practical addition. - -#### Negation operator for alternatives - -For patterns like "a literal that is not a boolean literal" one currently needs -to list all alternatives except the boolean case. Introducing a negation -operator that allows to write `Lit(!Bool(_))` might be a good idea. This pattern -would be equivalent to `Lit( Char(_) | Int(_) )` (given that currently only three -literal types are implemented). - -#### Functional composition - -Patterns currently don't have any concept of composition. This leads to -repetitions within patterns. For example, one of the collapsible-if patterns -currently has to be written like this: - -```rust -pattern!{ - pat_if_else: Expr = - If( - _, - _, - Block_( - Block( - Expr((If(_, _, _?) | IfLet(_, _?))#else_) | - Semi((If(_, _, _?) | IfLet(_, _?))#else_) - )#block_inner - )#block - ) | - IfLet( - _, - Block_( - Block( - Expr((If(_, _, _?) | IfLet(_, _?))#else_) | - Semi((If(_, _, _?) | IfLet(_, _?))#else_) - )#block_inner - )#block - ) -} -``` - -If patterns supported defining functions of subpatterns, the code could be -simplified as follows: - -```rust -pattern!{ - fn expr_or_semi(expr: Expr) -> Stmt { - Expr(expr) | Semi(expr) - } - fn if_or_if_let(then: Block, else: Opt) -> Expr { - If(_, then, else) | IfLet(then, else) - } - pat_if_else: Expr = - if_or_if_let( - _, - Block_( - Block( - expr_or_semi( if_or_if_let(_, _?)#else_ ) - )#block_inner - )#block - ) -} -``` - -Additionally, common patterns like `expr_or_semi` could be shared between -different lints. - -#### Clippy Pattern Author - -Another improvement could be to create a tool that, given some valid Rust -syntax, generates a pattern that matches this syntax exactly. This would make -starting to write a pattern easier. A user could take a look at the patterns -generated for a couple of Rust code examples and use that information to write a -pattern that matches all of them. - -This is similar to clippy's author lint. - -#### Supporting other syntaxes - -Most of the proposed system is language-agnostic. For example, the pattern -syntax could also be used to describe patterns for other programming languages. - -In order to support other languages' syntaxes, one would need to implement -another `PatternTree` that sufficiently describes the languages' AST and -implement `IsMatch` for this `PatternTree` and the languages' AST. - -One aspect of this is that it would even be possible to write lints that work on -the pattern syntax itself. For example, when writing the following pattern - - -```rust -pattern!{ - my_pattern: Expr = - Array( Lit(Bool(false)) Lit(Bool(false)) ) -} -``` - -a lint that works on the pattern syntax's AST could suggest using this pattern -instead: - -```rust -pattern!{ - my_pattern: Expr = - Array( Lit(Bool(false)){2} ) -} -``` - -In the future, clippy could use this system to also provide lints for custom -syntaxes like those found in macros. diff --git a/book/src/development/speedtest.md b/book/src/development/speedtest.md deleted file mode 100644 index 4ea1c8e5c9c0..000000000000 --- a/book/src/development/speedtest.md +++ /dev/null @@ -1,20 +0,0 @@ -# Speedtest -`SPEEDTEST` is the tool we use to measure lint's performance, it works by executing the same test several times. - -It's useful for measuring changes to current lints and deciding if the performance changes too much. `SPEEDTEST` is -accessed by the `SPEEDTEST` (and `SPEEDTEST_*`) environment variables. - -## Checking Speedtest - -To do a simple speed test of a lint (e.g. `allow_attributes`), use this command. - -```sh -$ SPEEDTEST=ui TESTNAME="allow_attributes" cargo uitest -``` - -This will test all `ui` tests (`SPEEDTEST=ui`) whose names start with `allow_attributes`. By default, `SPEEDTEST` will -iterate your test 1000 times. But you can change this with `SPEEDTEST_ITERATIONS`. - -```sh -$ SPEEDTEST=toml SPEEDTEST_ITERATIONS=100 TESTNAME="semicolon_block" cargo uitest -``` diff --git a/book/src/development/the_team.md b/book/src/development/the_team.md deleted file mode 100644 index 10341791cec4..000000000000 --- a/book/src/development/the_team.md +++ /dev/null @@ -1,130 +0,0 @@ -# The team - -Everyone who contributes to Clippy makes the project what it is. Collaboration -and discussions are the lifeblood of every open-source project. Clippy has a -very flat hierarchy. The teams mainly have additional access rights to the repo. - -This document outlines the onboarding process, as well as duties, and access -rights for members of a group. - -All regular events mentioned in this chapter are tracked in the [calendar repository]. -The calendar file is also available for download: [clippy.ics] - -## Everyone - -Everyone, including you, is welcome to join discussions and contribute in other -ways, like PRs. - -You also have some triage rights, using `@rustbot` to add labels and claim -issues. See [labeling with @rustbot]. - -A rule for everyone should be to keep a healthy work-life balance. Take a break -when you need one. - -## Clippy-Contributors - -This is a group of regular contributors to Clippy to help with triaging. - -### Duties - -This team exists to make contributing easier for regular members. It doesn't -carry any duties that need to be done. However, we want to encourage members of -this group to help with triaging, which can include: - -1. **Labeling issues** - - For the `good-first-issue` label, it can still be good to use `@rustbot` to - subscribe to the issue and help interested parties, if they post questions - in the comments. - -2. **Closing duplicate or resolved issues** - - When you manually close an issue, it's often a good idea, to add a short - comment explaining the reason. - -3. **Ping people after two weeks of inactivity** - - We try to keep issue assignments and PRs fairly up-to-date. After two weeks, - it can be good to send a friendly ping to the delaying party. - - You might close a PR with the `I-inactive-closed` label if the author is - busy or wants to abandon it. If the reviewer is busy, the PR can be - reassigned to someone else. - - Checkout: https://triage.rust-lang.org/triage/rust-lang/rust-clippy to - monitor PRs. - -While not part of their duties, contributors are encouraged to review PRs -and help on Zulip. The team always appreciates help! - -### Membership - -If you have been contributing to Clippy for some time, we'll probably ask you if -you want to join this team. Members of this team are also welcome to suggest -people who they think would make a great addition to this group. - -For this group, there is no direct onboarding process. You're welcome to just -continue what you've been doing. If you like, you can ask for someone to mentor -you, either in the Clippy stream on Zulip or privately via a PM. - -If you have been inactive in Clippy for over three months, we'll probably move -you to the alumni group. You're always welcome to come back. - -## The Clippy Team - -[The Clippy team](https://www.rust-lang.org/governance/teams/dev-tools#Clippy%20team) -is responsible for maintaining Clippy. - -### Duties - -1. **Respond to PRs in a timely manner** - - It's totally fine, if you don't have the time for reviews right now. - You can reassign the PR to a random member by commenting `r? clippy`. - -2. **Take a break when you need one** - - You are valuable! Clippy wouldn't be what it is without you. So take a break - early and recharge some energy when you need to. - -3. **Be responsive on Zulip** - - This means in a reasonable time frame, so responding within one or two days - is totally fine. - - It's also good, if you answer threads on Zulip and take part in our Clippy - meetings, every two weeks. The meeting dates are tracked in the [calendar repository]. - - -4. **Sync Clippy with the rust-lang/rust repo** - - This is done every two weeks, usually by @flip1995. - -5. **Update the changelog** - - This needs to be done for every release, every six weeks. This is usually - done by @xFrednet. - -### Membership - -If you have been active for some time, we'll probably reach out and ask -if you want to help with reviews and eventually join the Clippy team. - -During the onboarding process, you'll be assigned pull requests to review. -You'll also have an active team member as a mentor who'll stay in contact via -Zulip DMs to provide advice and feedback. If you have questions, you're always -welcome to ask, that is the best way to learn. Once you're done with the review, -you can ping your mentor for a full review and to r+ the PR in both of your names. - -When your mentor is confident that you can handle reviews on your own, they'll -start an informal vote among the active team members to officially add you to -the team. This vote is usually accepted unanimously. Then you'll be added to -the team once you've confirmed that you're still interested in joining. The -onboarding phase typically takes a couple of weeks to a few months. - -If you have been inactive in Clippy for over three months, we'll probably move -you to the alumni group. You're always welcome to come back. - -[calendar repository]: https://github.com/rust-lang/calendar/blob/main/clippy.toml -[clippy.ics]: https://rust-lang.github.io/calendar/clippy.ics -[labeling with @rustbot]: https://forge.rust-lang.org/triagebot/labeling.html diff --git a/book/src/development/trait_checking.md b/book/src/development/trait_checking.md deleted file mode 100644 index b7d229ccc193..000000000000 --- a/book/src/development/trait_checking.md +++ /dev/null @@ -1,155 +0,0 @@ -# Trait Checking - -Besides [type checking](type_checking.md), we might want to examine if -a specific type `Ty` implements certain trait when implementing a lint. -There are three approaches to achieve this, depending on if the target trait -that we want to examine has a [diagnostic item][diagnostic_items], -[lang item][lang_items], or neither. - -## Using Diagnostic Items - -As explained in the [Rust Compiler Development Guide][rustc_dev_guide], diagnostic items -are introduced for identifying types via [Symbols][symbol]. - -For instance, if we want to examine whether an expression implements -the `Iterator` trait, we could simply write the following code, -providing the `LateContext` (`cx`), our expression at hand, and -the symbol of the trait in question: - -```rust -use clippy_utils::is_trait_method; -use rustc_hir::Expr; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_span::symbol::sym; - -impl LateLintPass<'_> for CheckIteratorTraitLint { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - let implements_iterator = cx.tcx.get_diagnostic_item(sym::Iterator).map_or(false, |id| { - implements_trait(cx, cx.typeck_results().expr_ty(arg), id, &[]) - }); - if implements_iterator { - // [...] - } - - } -} -``` - -> **Note**: Refer to [this index][symbol_index] for all the defined `Symbol`s. - -## Using Lang Items - -Besides diagnostic items, we can also use [`lang_items`][lang_items]. -Take a look at the documentation to find that `LanguageItems` contains -all language items defined in the compiler. - -Using one of its `*_trait` method, we could obtain the [DefId] of any -specific item, such as `Clone`, `Copy`, `Drop`, `Eq`, which are familiar -to many Rustaceans. - -For instance, if we want to examine whether an expression `expr` implements -`Drop` trait, we could access `LanguageItems` via our `LateContext`'s -[TyCtxt], which provides a `lang_items` method that will return the id of -`Drop` trait to us. Then, by calling Clippy utils function `implements_trait` -we can check that the `Ty` of the `expr` implements the trait: - -```rust -use clippy_utils::implements_trait; -use rustc_hir::Expr; -use rustc_lint::{LateContext, LateLintPass}; - -impl LateLintPass<'_> for CheckDropTraitLint { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - let ty = cx.typeck_results().expr_ty(expr); - if cx.tcx.lang_items() - .drop_trait() - .map_or(false, |id| implements_trait(cx, ty, id, &[])) { - println!("`expr` implements `Drop` trait!"); - } - } -} -``` - -## Using Type Path - -If neither diagnostic item nor a language item is available, we can use -[`clippy_utils::paths`][paths] with the `match_trait_method` to determine trait -implementation. - -> **Note**: This approach should be avoided if possible, the best thing to do would be to make a PR to [`rust-lang/rust`][rust] adding a diagnostic item. - -Below, we check if the given `expr` implements the `Iterator`'s trait method `cloned` : - -```rust -use clippy_utils::{match_trait_method, paths}; -use rustc_hir::Expr; -use rustc_lint::{LateContext, LateLintPass}; - -impl LateLintPass<'_> for CheckTokioAsyncReadExtTrait { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - if match_trait_method(cx, expr, &paths::CORE_ITER_CLONED) { - println!("`expr` implements `CORE_ITER_CLONED` trait!"); - } - } -} -``` - -## Creating Types Programmatically - -Traits are often generic over a type parameter, e.g. `Borrow` is generic -over `T`. Rust allows us to implement a trait for a specific type. For example, -we can implement `Borrow<[u8]>` for a hypothetical type `Foo`. Let's suppose -that we would like to find whether our type actually implements `Borrow<[u8]>`. - -To do so, we can use the same `implements_trait` function as above, and supply -a type parameter that represents `[u8]`. Since `[u8]` is a specialization of -`[T]`, we can use the [`Ty::new_slice`][new_slice] method to create a type -that represents `[T]` and supply `u8` as a type parameter. -To create a `ty::Ty` programmatically, we rely on `Ty::new_*` methods. These -methods create a `TyKind` and then wrap it in a `Ty` struct. This means we -have access to all the primitive types, such as `Ty::new_char`, -`Ty::new_bool`, `Ty::new_int`, etc. We can also create more complex types, -such as slices, tuples, and references out of these basic building blocks. - -For trait checking, it is not enough to create the types, we need to convert -them into [GenericArg]. In rustc, a generic is an entity that the compiler -understands and has three kinds, type, const and lifetime. By calling -`.into()` on a constructed [Ty], we wrap the type into a generic which can -then be used by the query system to decide whether the specialized trait -is implemented. - -The following code demonstrates how to do this: - -```rust - -use rustc_middle::ty::Ty; -use clippy_utils::ty::implements_trait; -use rustc_span::symbol::sym; - -let ty = todo!("Get the `Foo` type to check for a trait implementation"); -let borrow_id = cx.tcx.get_diagnostic_item(sym::Borrow).unwrap(); // avoid unwrap in real code -let slice_of_bytes_t = Ty::new_slice(cx.tcx, cx.tcx.types.u8); -let generic_param = slice_of_bytes_t.into(); -if implements_trait(cx, ty, borrow_id, &[generic_param]) { - todo!("Rest of lint implementation") -} -``` - -In essence, the [Ty] struct allows us to create types programmatically in a -representation that can be used by the compiler and the query engine. We then -use the `rustc_middle::Ty` of the type we are interested in, and query the -compiler to see if it indeed implements the trait we are interested in. - - -[DefId]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.DefId.html -[diagnostic_items]: https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-items.html -[lang_items]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/lang_items/struct.LanguageItems.html -[paths]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_utils/src/paths.rs -[rustc_dev_guide]: https://rustc-dev-guide.rust-lang.org/ -[symbol]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/symbol/struct.Symbol.html -[symbol_index]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_span/symbol/sym/index.html -[TyCtxt]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html -[Ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html -[rust]: https://github.com/rust-lang/rust -[new_slice]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html#method.new_slice -[GenericArg]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.GenericArg.html diff --git a/book/src/development/type_checking.md b/book/src/development/type_checking.md deleted file mode 100644 index e6da4322a179..000000000000 --- a/book/src/development/type_checking.md +++ /dev/null @@ -1,167 +0,0 @@ -# Type Checking - -When we work on a new lint or improve an existing lint, we might want -to retrieve the type `Ty` of an expression `Expr` for a variety of -reasons. This can be achieved by utilizing the [`LateContext`][LateContext] -that is available for [`LateLintPass`][LateLintPass]. - -## `LateContext` and `TypeckResults` - -The lint context [`LateContext`][LateContext] and [`TypeckResults`][TypeckResults] -(returned by `LateContext::typeck_results`) are the two most useful data structures -in `LateLintPass`. They allow us to jump to type definitions and other compilation -stages such as HIR. - -> Note: `LateContext.typeck_results`'s return value is [`TypeckResults`][TypeckResults] -> and is created in the type checking step, it includes useful information such as types of -> expressions, ways to resolve methods and so on. - -`TypeckResults` contains useful methods such as [`expr_ty`][expr_ty], -which gives us access to the underlying structure [`Ty`][Ty] of a given expression. - -```rust -pub fn expr_ty(&self, expr: &Expr<'_>) -> Ty<'tcx> -``` - -As a side note, besides `expr_ty`, [`TypeckResults`][TypeckResults] contains a -[`pat_ty()`][pat_ty] method that is useful for retrieving a type from a pattern. - -## `Ty` - -`Ty` struct contains the type information of an expression. -Let's take a look at `rustc_middle`'s [`Ty`][Ty] struct to examine this struct: - -```rust -pub struct Ty<'tcx>(Interned<'tcx, WithStableHash>>); -``` - -At a first glance, this struct looks quite esoteric. But at a closer look, -we will see that this struct contains many useful methods for type checking. - -For instance, [`is_char`][is_char] checks if the given `Ty` struct corresponds -to the primitive character type. - -### `is_*` Usage - -In some scenarios, all we need to do is check if the `Ty` of an expression -is a specific type, such as `char` type, so we could write the following: - -```rust -impl LateLintPass<'_> for MyStructLint { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - // Get type of `expr` - let ty = cx.typeck_results().expr_ty(expr); - - // Check if the `Ty` of this expression is of character type - if ty.is_char() { - println!("Our expression is a char!"); - } - } -} -``` - -Furthermore, if we examine the [source code][is_char_source] for `is_char`, -we find something very interesting: - -```rust -#[inline] -pub fn is_char(self) -> bool { - matches!(self.kind(), Char) -} -``` - -Indeed, we just discovered `Ty`'s [`kind()` method][kind], which provides us -with [`TyKind`][TyKind] of a `Ty`. - -## `TyKind` - -`TyKind` defines the kinds of types in Rust's type system. -Peeking into [`TyKind` documentation][TyKind], we will see that it is an -enum of over 25 variants, including items such as `Bool`, `Int`, `Ref`, etc. - -### `kind` Usage - -The `TyKind` of `Ty` can be returned by calling [`Ty.kind()` method][kind]. -We often use this method to perform pattern matching in Clippy. - -For instance, if we want to check for a `struct`, we could examine if the -`ty.kind` corresponds to an [`Adt`][Adt] (algebraic data type) and if its -[`AdtDef`][AdtDef] is a struct: - -```rust -impl LateLintPass<'_> for MyStructLint { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - // Get type of `expr` - let ty = cx.typeck_results().expr_ty(expr); - // Match its kind to enter the type - match ty.kind { - ty::Adt(adt_def, _) if adt_def.is_struct() => println!("Our `expr` is a struct!"), - _ => () - } - } -} -``` - -## `hir::Ty` and `ty::Ty` - -We've been talking about [`ty::Ty`][middle_ty] this whole time without addressing [`hir::Ty`][hir_ty], but the latter -is also important to understand. - -`hir::Ty` would represent *what* the user wrote, while `ty::Ty` is how the compiler sees the type and has more -information. Example: - -```rust -fn foo(x: u32) -> u32 { x } -``` - -Here the HIR sees the types without "thinking" about them, it knows that the function takes an `u32` and returns -an `u32`. As far as `hir::Ty` is concerned those might be different types. But at the `ty::Ty` level the compiler -understands that they're the same type, in-depth lifetimes, etc... - -To get from a `hir::Ty` to a `ty::Ty`, you can use the [`lower_ty`][lower_ty] function outside of bodies or -the [`TypeckResults::node_type()`][node_type] method inside of bodies. - -> **Warning**: Don't use `lower_ty` inside of bodies, because this can cause ICEs. - -## Creating Types programmatically - -A common usecase for creating types programmatically is when we want to check if a type implements a trait (see -[Trait Checking](trait_checking.md)). - -Here's an example of how to create a `Ty` for a slice of `u8`, i.e. `[u8]` - -```rust -use rustc_middle::ty::Ty; -// assume we have access to a LateContext -let ty = Ty::new_slice(cx.tcx, Ty::new_u8()); -``` - -In general, we rely on `Ty::new_*` methods. These methods define the basic building-blocks that the -type-system and trait-system use to define and understand the written code. - -## Useful Links - -Below are some useful links to further explore the concepts covered -in this chapter: - -- [Stages of compilation](https://rustc-dev-guide.rust-lang.org/compiler-src.html#the-main-stages-of-compilation) -- [Diagnostic items](https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-items.html) -- [Type checking](https://rustc-dev-guide.rust-lang.org/type-checking.html) -- [Ty module](https://rustc-dev-guide.rust-lang.org/ty.html) - -[Adt]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/ty_kind/enum.TyKind.html#variant.Adt -[AdtDef]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/adt/struct.AdtDef.html -[expr_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html#method.expr_ty -[node_type]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html#method.node_type -[is_char]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html#method.is_char -[is_char_source]: https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_middle/ty/sty.rs.html#1831-1834 -[kind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html#method.kind -[LateContext]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LateContext.html -[LateLintPass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html -[pat_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/typeck_results/struct.TypeckResults.html#method.pat_ty -[Ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html -[TyKind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/ty_kind/enum.TyKind.html -[TypeckResults]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html -[middle_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html -[hir_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/struct.Ty.html -[lower_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/fn.lower_ty.html diff --git a/book/src/development/writing_tests.md b/book/src/development/writing_tests.md deleted file mode 100644 index 39a5ad966885..000000000000 --- a/book/src/development/writing_tests.md +++ /dev/null @@ -1,218 +0,0 @@ -# Testing - -Developing lints for Clippy is a Test-Driven Development (TDD) process because -our first task before implementing any logic for a new lint is to write some test cases. - -## Develop Lints with Tests - -When we develop Clippy, we enter a complex and chaotic realm full of -programmatic issues, stylistic errors, illogical code and non-adherence to convention. -Tests are the first layer of order we can leverage to define when and where -we want a new lint to trigger or not. - -Moreover, writing tests first help Clippy developers to find a balance for -the first iteration of and further enhancements for a lint. -With test cases on our side, we will not have to worry about over-engineering -a lint on its first version nor missing out some obvious edge cases of the lint. -This approach empowers us to iteratively enhance each lint. - -## Clippy UI Tests - -We use **UI tests** for testing in Clippy. These UI tests check that the output -of Clippy is exactly as we expect it to be. Each test is just a plain Rust file -that contains the code we want to check. - -The output of Clippy is compared against a `.stderr` file. Note that you don't -have to create this file yourself. We'll get to generating the `.stderr` files -with the command [`cargo bless`](#cargo-bless) (seen later on). - -### Write Test Cases - -Let us now think about some tests for our imaginary `foo_functions` lint. We -start by opening the test file `tests/ui/foo_functions.rs` that was created by -`cargo dev new_lint`. - -Update the file with some examples to get started: - -```rust -#![warn(clippy::foo_functions)] // < Add this, so the lint is guaranteed to be enabled in this file - -// Impl methods -struct A; -impl A { - pub fn fo(&self) {} - pub fn foo(&self) {} //~ ERROR: function called "foo" - pub fn food(&self) {} -} - -// Default trait methods -trait B { - fn fo(&self) {} - fn foo(&self) {} //~ ERROR: function called "foo" - fn food(&self) {} -} - -// Plain functions -fn fo() {} -fn foo() {} //~ ERROR: function called "foo" -fn food() {} - -fn main() { - // We also don't want to lint method calls - foo(); - let a = A; - a.foo(); -} -``` - -Without actual lint logic to emit the lint when we see a `foo` function name, -this test will just pass, because no lint will be emitted. However, we can now -run the test with the following command: - -```sh -$ TESTNAME=foo_functions cargo uitest -``` - -Clippy will compile and it will conclude with an `ok` for the tests: - -``` -...Clippy warnings and test outputs... -test compile_test ... ok -test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.48s -``` - -This is normal. After all, we wrote a bunch of Rust code but we haven't really -implemented any logic for Clippy to detect `foo` functions and emit a lint. - -As we gradually implement our lint logic, we will keep running this UI test command. -Clippy will begin outputting information that allows us to check if the output is -turning into what we want it to be. - -### Example output - -As our `foo_functions` lint is tested, the output would look something like this: - -``` -failures: ----- compile_test stdout ---- -normalized stderr: -error: function called "foo" - --> tests/ui/foo_functions.rs:6:12 - | -LL | pub fn foo(&self) {} - | ^^^ - | - = note: `-D clippy::foo-functions` implied by `-D warnings` -error: function called "foo" - --> tests/ui/foo_functions.rs:13:8 - | -LL | fn foo(&self) {} - | ^^^ -error: function called "foo" - --> tests/ui/foo_functions.rs:19:4 - | -LL | fn foo() {} - | ^^^ -error: aborting due to 3 previous errors -``` - -Note the *failures* label at the top of the fragment, we'll get rid of it -(saving this output) in the next section. - -> _Note:_ You can run multiple test files by specifying a comma separated list: -> `TESTNAME=foo_functions,bar_methods,baz_structs`. - -### `cargo bless` - -Once we are satisfied with the output, we need to run this command to -generate or update the `.stderr` file for our lint: - -```sh -$ TESTNAME=foo_functions cargo uibless -``` - -This writes the emitted lint suggestions and fixes to the `.stderr` file, with -the reason for the lint, suggested fixes, and line numbers, etc. - -Running `TESTNAME=foo_functions cargo uitest` should pass then. When we commit -our lint, we need to commit the generated `.stderr` files, too. - -In general, you should only commit files changed by `cargo bless` for the -specific lint you are creating/editing. - -> _Note:_ If the generated `.stderr`, and `.fixed` files are empty, -> they should be removed. - -## `toml` Tests - -Some lints can be configured through a `clippy.toml` file. Those configuration -values are tested in `tests/ui-toml`. - -To add a new test there, create a new directory and add the files: - -- `clippy.toml`: Put here the configuration value you want to test. -- `lint_name.rs`: A test file where you put the testing code, that should see a - different lint behavior according to the configuration set in the - `clippy.toml` file. - -The potential `.stderr` and `.fixed` files can again be generated with `cargo -bless`. - -## Cargo Lints - -The process of testing is different for Cargo lints in that now we are -interested in the `Cargo.toml` manifest file. In this case, we also need a -minimal crate associated with that manifest. Those tests are generated in -`tests/ui-cargo`. - -Imagine we have a new example lint that is named `foo_categories`, we can run: - -```sh -$ cargo dev new_lint --name=foo_categories --pass=late --category=cargo -``` - -After running `cargo dev new_lint` we will find by default two new crates, -each with its manifest file: - -* `tests/ui-cargo/foo_categories/fail/Cargo.toml`: this file should cause the - new lint to raise an error. -* `tests/ui-cargo/foo_categories/pass/Cargo.toml`: this file should not trigger - the lint. - -If you need more cases, you can copy one of those crates (under -`foo_categories`) and rename it. - -The process of generating the `.stderr` file is the same as for other lints -and prepending the `TESTNAME` variable to `cargo uitest` works for Cargo lints too. - -## Rustfix Tests - -If the lint you are working on is making use of structured suggestions, -[`rustfix`] will apply the suggestions from the lint to the test file code and -compare that to the contents of a `.fixed` file. - -Structured suggestions tell a user how to fix or re-write certain code that has -been linted with [`span_lint_and_sugg`]. - -Should `span_lint_and_sugg` be used to generate a suggestion, but not all -suggestions lead to valid code, you can use the `//@no-rustfix` comment on top -of the test file, to not run `rustfix` on that file. - -We'll talk about suggestions more in depth in a [later chapter](emitting_lints.md). - -Use `cargo bless` to automatically generate the `.fixed` file after running -the tests. - -[`rustfix`]: https://github.com/rust-lang/rustfix -[`span_lint_and_sugg`]: https://doc.rust-lang.org/beta/nightly-rustc/clippy_utils/diagnostics/fn.span_lint_and_sugg.html - -## Testing Manually - -Manually testing against an example file can be useful if you have added some -`println!`s and the test suite output becomes unreadable. - -To try Clippy with your local modifications, run from the working copy root. - -```sh -$ cargo dev lint input.rs -``` diff --git a/book/src/installation.md b/book/src/installation.md deleted file mode 100644 index d54fff9deba1..000000000000 --- a/book/src/installation.md +++ /dev/null @@ -1,24 +0,0 @@ -# Installation - -If you're using `rustup` to install and manage your Rust toolchains, Clippy is -usually **already installed**. In that case you can skip this chapter and go to -the [Usage] chapter. - -> Note: If you used the `minimal` profile when installing a Rust toolchain, -> Clippy is not automatically installed. - -## Using Rustup - -If Clippy was not installed for a toolchain, it can be installed with - -``` -$ rustup component add clippy [--toolchain=] -``` - -## From Source - -Take a look at the [Basics] chapter in the Clippy developer guide to find step-by-step -instructions on how to build and install Clippy from source. - -[Basics]: development/basics.md#install-from-source -[Usage]: usage.md diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md deleted file mode 100644 index b049a6106f56..000000000000 --- a/book/src/lint_configuration.md +++ /dev/null @@ -1,934 +0,0 @@ - - -# Lint Configuration Options - -The following list shows each configuration option, along with a description, its default value, an example -and lints affected. - ---- - -## `absolute-paths-allowed-crates` -Which crates to allow absolute paths from - -**Default Value:** `[]` - ---- -**Affected lints:** -* [`absolute_paths`](https://rust-lang.github.io/rust-clippy/master/index.html#absolute_paths) - - -## `absolute-paths-max-segments` -The maximum number of segments a path can have before being linted, anything above this will -be linted. - -**Default Value:** `2` - ---- -**Affected lints:** -* [`absolute_paths`](https://rust-lang.github.io/rust-clippy/master/index.html#absolute_paths) - - -## `accept-comment-above-attributes` -Whether to accept a safety comment to be placed above the attributes for the `unsafe` block - -**Default Value:** `true` - ---- -**Affected lints:** -* [`undocumented_unsafe_blocks`](https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks) - - -## `accept-comment-above-statement` -Whether to accept a safety comment to be placed above the statement containing the `unsafe` block - -**Default Value:** `true` - ---- -**Affected lints:** -* [`undocumented_unsafe_blocks`](https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks) - - -## `allow-comparison-to-zero` -Don't lint when comparing the result of a modulo operation to zero. - -**Default Value:** `true` - ---- -**Affected lints:** -* [`modulo_arithmetic`](https://rust-lang.github.io/rust-clippy/master/index.html#modulo_arithmetic) - - -## `allow-dbg-in-tests` -Whether `dbg!` should be allowed in test functions or `#[cfg(test)]` - -**Default Value:** `false` - ---- -**Affected lints:** -* [`dbg_macro`](https://rust-lang.github.io/rust-clippy/master/index.html#dbg_macro) - - -## `allow-expect-in-tests` -Whether `expect` should be allowed in test functions or `#[cfg(test)]` - -**Default Value:** `false` - ---- -**Affected lints:** -* [`expect_used`](https://rust-lang.github.io/rust-clippy/master/index.html#expect_used) - - -## `allow-mixed-uninlined-format-args` -Whether to allow mixed uninlined format args, e.g. `format!("{} {}", a, foo.bar)` - -**Default Value:** `true` - ---- -**Affected lints:** -* [`uninlined_format_args`](https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args) - - -## `allow-one-hash-in-raw-strings` -Whether to allow `r#""#` when `r""` can be used - -**Default Value:** `false` - ---- -**Affected lints:** -* [`unnecessary_raw_string_hashes`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_raw_string_hashes) - - -## `allow-print-in-tests` -Whether print macros (ex. `println!`) should be allowed in test functions or `#[cfg(test)]` - -**Default Value:** `false` - ---- -**Affected lints:** -* [`print_stderr`](https://rust-lang.github.io/rust-clippy/master/index.html#print_stderr) -* [`print_stdout`](https://rust-lang.github.io/rust-clippy/master/index.html#print_stdout) - - -## `allow-private-module-inception` -Whether to allow module inception if it's not public. - -**Default Value:** `false` - ---- -**Affected lints:** -* [`module_inception`](https://rust-lang.github.io/rust-clippy/master/index.html#module_inception) - - -## `allow-renamed-params-for` -List of trait paths to ignore when checking renamed function parameters. - -#### Example - -```toml -allow-renamed-params-for = [ "std::convert::From" ] -``` - -#### Noteworthy - -- By default, the following traits are ignored: `From`, `TryFrom`, `FromStr` -- `".."` can be used as part of the list to indicate that the configured values should be appended to the -default configuration of Clippy. By default, any configuration will replace the default value. - -**Default Value:** `["core::convert::From", "core::convert::TryFrom", "core::str::FromStr"]` - ---- -**Affected lints:** -* [`renamed_function_params`](https://rust-lang.github.io/rust-clippy/master/index.html#renamed_function_params) - - -## `allow-unwrap-in-tests` -Whether `unwrap` should be allowed in test functions or `#[cfg(test)]` - -**Default Value:** `false` - ---- -**Affected lints:** -* [`unwrap_used`](https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used) - - -## `allow-useless-vec-in-tests` -Whether `useless_vec` should ignore test functions or `#[cfg(test)]` - -**Default Value:** `false` - ---- -**Affected lints:** -* [`useless_vec`](https://rust-lang.github.io/rust-clippy/master/index.html#useless_vec) - - -## `allowed-dotfiles` -Additional dotfiles (files or directories starting with a dot) to allow - -**Default Value:** `[]` - ---- -**Affected lints:** -* [`path_ends_with_ext`](https://rust-lang.github.io/rust-clippy/master/index.html#path_ends_with_ext) - - -## `allowed-duplicate-crates` -A list of crate names to allow duplicates of - -**Default Value:** `[]` - ---- -**Affected lints:** -* [`multiple_crate_versions`](https://rust-lang.github.io/rust-clippy/master/index.html#multiple_crate_versions) - - -## `allowed-idents-below-min-chars` -Allowed names below the minimum allowed characters. The value `".."` can be used as part of -the list to indicate, that the configured values should be appended to the default -configuration of Clippy. By default, any configuration will replace the default value. - -**Default Value:** `["j", "z", "i", "y", "n", "x", "w"]` - ---- -**Affected lints:** -* [`min_ident_chars`](https://rust-lang.github.io/rust-clippy/master/index.html#min_ident_chars) - - -## `allowed-prefixes` -List of prefixes to allow when determining whether an item's name ends with the module's name. -If the rest of an item's name is an allowed prefix (e.g. item `ToFoo` or `to_foo` in module `foo`), -then don't emit a warning. - -#### Example - -```toml -allowed-prefixes = [ "to", "from" ] -``` - -#### Noteworthy - -- By default, the following prefixes are allowed: `to`, `as`, `into`, `from`, `try_into` and `try_from` -- PascalCase variant is included automatically for each snake_case variant (e.g. if `try_into` is included, - `TryInto` will also be included) -- Use `".."` as part of the list to indicate that the configured values should be appended to the -default configuration of Clippy. By default, any configuration will replace the default value - -**Default Value:** `["to", "as", "into", "from", "try_into", "try_from"]` - ---- -**Affected lints:** -* [`module_name_repetitions`](https://rust-lang.github.io/rust-clippy/master/index.html#module_name_repetitions) - - -## `allowed-scripts` -The list of unicode scripts allowed to be used in the scope. - -**Default Value:** `["Latin"]` - ---- -**Affected lints:** -* [`disallowed_script_idents`](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_script_idents) - - -## `allowed-wildcard-imports` -List of path segments allowed to have wildcard imports. - -#### Example - -```toml -allowed-wildcard-imports = [ "utils", "common" ] -``` - -#### Noteworthy - -1. This configuration has no effects if used with `warn_on_all_wildcard_imports = true`. -2. Paths with any segment that containing the word 'prelude' -are already allowed by default. - -**Default Value:** `[]` - ---- -**Affected lints:** -* [`wildcard_imports`](https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports) - - -## `arithmetic-side-effects-allowed` -Suppress checking of the passed type names in all types of operations. - -If a specific operation is desired, consider using `arithmetic_side_effects_allowed_binary` or `arithmetic_side_effects_allowed_unary` instead. - -#### Example - -```toml -arithmetic-side-effects-allowed = ["SomeType", "AnotherType"] -``` - -#### Noteworthy - -A type, say `SomeType`, listed in this configuration has the same behavior of -`["SomeType" , "*"], ["*", "SomeType"]` in `arithmetic_side_effects_allowed_binary`. - -**Default Value:** `[]` - ---- -**Affected lints:** -* [`arithmetic_side_effects`](https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects) - - -## `arithmetic-side-effects-allowed-binary` -Suppress checking of the passed type pair names in binary operations like addition or -multiplication. - -Supports the "*" wildcard to indicate that a certain type won't trigger the lint regardless -of the involved counterpart. For example, `["SomeType", "*"]` or `["*", "AnotherType"]`. - -Pairs are asymmetric, which means that `["SomeType", "AnotherType"]` is not the same as -`["AnotherType", "SomeType"]`. - -#### Example - -```toml -arithmetic-side-effects-allowed-binary = [["SomeType" , "f32"], ["AnotherType", "*"]] -``` - -**Default Value:** `[]` - ---- -**Affected lints:** -* [`arithmetic_side_effects`](https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects) - - -## `arithmetic-side-effects-allowed-unary` -Suppress checking of the passed type names in unary operations like "negation" (`-`). - -#### Example - -```toml -arithmetic-side-effects-allowed-unary = ["SomeType", "AnotherType"] -``` - -**Default Value:** `[]` - ---- -**Affected lints:** -* [`arithmetic_side_effects`](https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects) - - -## `array-size-threshold` -The maximum allowed size for arrays on the stack - -**Default Value:** `512000` - ---- -**Affected lints:** -* [`large_const_arrays`](https://rust-lang.github.io/rust-clippy/master/index.html#large_const_arrays) -* [`large_stack_arrays`](https://rust-lang.github.io/rust-clippy/master/index.html#large_stack_arrays) - - -## `avoid-breaking-exported-api` -Suppress lints whenever the suggested change would cause breakage for other crates. - -**Default Value:** `true` - ---- -**Affected lints:** -* [`box_collection`](https://rust-lang.github.io/rust-clippy/master/index.html#box_collection) -* [`enum_variant_names`](https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names) -* [`large_types_passed_by_value`](https://rust-lang.github.io/rust-clippy/master/index.html#large_types_passed_by_value) -* [`linkedlist`](https://rust-lang.github.io/rust-clippy/master/index.html#linkedlist) -* [`option_option`](https://rust-lang.github.io/rust-clippy/master/index.html#option_option) -* [`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) -* [`single_call_fn`](https://rust-lang.github.io/rust-clippy/master/index.html#single_call_fn) -* [`trivially_copy_pass_by_ref`](https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref) -* [`unnecessary_box_returns`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_box_returns) -* [`unnecessary_wraps`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_wraps) -* [`unused_self`](https://rust-lang.github.io/rust-clippy/master/index.html#unused_self) -* [`upper_case_acronyms`](https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms) -* [`vec_box`](https://rust-lang.github.io/rust-clippy/master/index.html#vec_box) -* [`wrong_self_convention`](https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention) - - -## `await-holding-invalid-types` - - -**Default Value:** `[]` - ---- -**Affected lints:** -* [`await_holding_invalid_type`](https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_invalid_type) - - -## `cargo-ignore-publish` -For internal testing only, ignores the current `publish` settings in the Cargo manifest. - -**Default Value:** `false` - ---- -**Affected lints:** -* [`cargo_common_metadata`](https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata) - - -## `check-private-items` -Whether to also run the listed lints on private items. - -**Default Value:** `false` - ---- -**Affected lints:** -* [`missing_errors_doc`](https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc) -* [`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) -* [`unnecessary_safety_doc`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_safety_doc) - - -## `cognitive-complexity-threshold` -The maximum cognitive complexity a function can have - -**Default Value:** `25` - ---- -**Affected lints:** -* [`cognitive_complexity`](https://rust-lang.github.io/rust-clippy/master/index.html#cognitive_complexity) - - -## `disallowed-macros` -The list of disallowed macros, written as fully qualified paths. - -**Default Value:** `[]` - ---- -**Affected lints:** -* [`disallowed_macros`](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_macros) - - -## `disallowed-methods` -The list of disallowed methods, written as fully qualified paths. - -**Default Value:** `[]` - ---- -**Affected lints:** -* [`disallowed_methods`](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods) - - -## `disallowed-names` -The list of disallowed names to lint about. NB: `bar` is not here since it has legitimate uses. The value -`".."` can be used as part of the list to indicate that the configured values should be appended to the -default configuration of Clippy. By default, any configuration will replace the default value. - -**Default Value:** `["foo", "baz", "quux"]` - ---- -**Affected lints:** -* [`disallowed_names`](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names) - - -## `disallowed-types` -The list of disallowed types, written as fully qualified paths. - -**Default Value:** `[]` - ---- -**Affected lints:** -* [`disallowed_types`](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types) - - -## `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 -default configuration of Clippy. By default, any configuration will replace the default value. For example: -* `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`. -* `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list. - -**Default Value:** `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PureScript", "TypeScript", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry", "WebGL", "WebGL2", "WebGPU", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]` - ---- -**Affected lints:** -* [`doc_markdown`](https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown) - - -## `enable-raw-pointer-heuristic-for-send` -Whether to apply the raw pointer heuristic to determine if a type is `Send`. - -**Default Value:** `true` - ---- -**Affected lints:** -* [`non_send_fields_in_send_ty`](https://rust-lang.github.io/rust-clippy/master/index.html#non_send_fields_in_send_ty) - - -## `enforce-iter-loop-reborrow` -Whether to recommend using implicit into iter for reborrowed values. - -#### Example -```no_run -let mut vec = vec![1, 2, 3]; -let rmvec = &mut vec; -for _ in rmvec.iter() {} -for _ in rmvec.iter_mut() {} -``` - -Use instead: -```no_run -let mut vec = vec![1, 2, 3]; -let rmvec = &mut vec; -for _ in &*rmvec {} -for _ in &mut *rmvec {} -``` - -**Default Value:** `false` - ---- -**Affected lints:** -* [`explicit_iter_loop`](https://rust-lang.github.io/rust-clippy/master/index.html#explicit_iter_loop) - - -## `enforced-import-renames` -The list of imports to always rename, a fully qualified path followed by the rename. - -**Default Value:** `[]` - ---- -**Affected lints:** -* [`missing_enforced_import_renames`](https://rust-lang.github.io/rust-clippy/master/index.html#missing_enforced_import_renames) - - -## `enum-variant-name-threshold` -The minimum number of enum variants for the lints about variant names to trigger - -**Default Value:** `3` - ---- -**Affected lints:** -* [`enum_variant_names`](https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names) - - -## `enum-variant-size-threshold` -The maximum size of an enum's variant to avoid box suggestion - -**Default Value:** `200` - ---- -**Affected lints:** -* [`large_enum_variant`](https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant) - - -## `excessive-nesting-threshold` -The maximum amount of nesting a block can reside in - -**Default Value:** `0` - ---- -**Affected lints:** -* [`excessive_nesting`](https://rust-lang.github.io/rust-clippy/master/index.html#excessive_nesting) - - -## `future-size-threshold` -The maximum byte size a `Future` can have, before it triggers the `clippy::large_futures` lint - -**Default Value:** `16384` - ---- -**Affected lints:** -* [`large_futures`](https://rust-lang.github.io/rust-clippy/master/index.html#large_futures) - - -## `ignore-interior-mutability` -A list of paths to types that should be treated as if they do not contain interior mutability - -**Default Value:** `["bytes::Bytes"]` - ---- -**Affected lints:** -* [`borrow_interior_mutable_const`](https://rust-lang.github.io/rust-clippy/master/index.html#borrow_interior_mutable_const) -* [`declare_interior_mutable_const`](https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const) -* [`ifs_same_cond`](https://rust-lang.github.io/rust-clippy/master/index.html#ifs_same_cond) -* [`mutable_key_type`](https://rust-lang.github.io/rust-clippy/master/index.html#mutable_key_type) - - -## `large-error-threshold` -The maximum size of the `Err`-variant in a `Result` returned from a function - -**Default Value:** `128` - ---- -**Affected lints:** -* [`result_large_err`](https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err) - - -## `literal-representation-threshold` -The lower bound for linting decimal literals - -**Default Value:** `16384` - ---- -**Affected lints:** -* [`decimal_literal_representation`](https://rust-lang.github.io/rust-clippy/master/index.html#decimal_literal_representation) - - -## `matches-for-let-else` -Whether the matches should be considered by the lint, and whether there should -be filtering for common types. - -**Default Value:** `"WellKnownTypes"` - ---- -**Affected lints:** -* [`manual_let_else`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else) - - -## `max-fn-params-bools` -The maximum number of bool parameters a function can have - -**Default Value:** `3` - ---- -**Affected lints:** -* [`fn_params_excessive_bools`](https://rust-lang.github.io/rust-clippy/master/index.html#fn_params_excessive_bools) - - -## `max-include-file-size` -The maximum size of a file included via `include_bytes!()` or `include_str!()`, in bytes - -**Default Value:** `1000000` - ---- -**Affected lints:** -* [`large_include_file`](https://rust-lang.github.io/rust-clippy/master/index.html#large_include_file) - - -## `max-struct-bools` -The maximum number of bool fields a struct can have - -**Default Value:** `3` - ---- -**Affected lints:** -* [`struct_excessive_bools`](https://rust-lang.github.io/rust-clippy/master/index.html#struct_excessive_bools) - - -## `max-suggested-slice-pattern-length` -When Clippy suggests using a slice pattern, this is the maximum number of elements allowed in -the slice pattern that is suggested. If more elements are necessary, the lint is suppressed. -For example, `[_, _, _, e, ..]` is a slice pattern with 4 elements. - -**Default Value:** `3` - ---- -**Affected lints:** -* [`index_refutable_slice`](https://rust-lang.github.io/rust-clippy/master/index.html#index_refutable_slice) - - -## `max-trait-bounds` -The maximum number of bounds a trait can have to be linted - -**Default Value:** `3` - ---- -**Affected lints:** -* [`type_repetition_in_bounds`](https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds) - - -## `min-ident-chars-threshold` -Minimum chars an ident can have, anything below or equal to this will be linted. - -**Default Value:** `1` - ---- -**Affected lints:** -* [`min_ident_chars`](https://rust-lang.github.io/rust-clippy/master/index.html#min_ident_chars) - - -## `missing-docs-in-crate-items` -Whether to **only** check for missing documentation in items visible within the current -crate. For example, `pub(crate)` items. - -**Default Value:** `false` - ---- -**Affected lints:** -* [`missing_docs_in_private_items`](https://rust-lang.github.io/rust-clippy/master/index.html#missing_docs_in_private_items) - - -## `msrv` -The minimum rust version that the project supports. Defaults to the `rust-version` field in `Cargo.toml` - ---- -**Affected lints:** -* [`almost_complete_range`](https://rust-lang.github.io/rust-clippy/master/index.html#almost_complete_range) -* [`approx_constant`](https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant) -* [`assigning_clones`](https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones) -* [`borrow_as_ptr`](https://rust-lang.github.io/rust-clippy/master/index.html#borrow_as_ptr) -* [`cast_abs_to_unsigned`](https://rust-lang.github.io/rust-clippy/master/index.html#cast_abs_to_unsigned) -* [`checked_conversions`](https://rust-lang.github.io/rust-clippy/master/index.html#checked_conversions) -* [`cloned_instead_of_copied`](https://rust-lang.github.io/rust-clippy/master/index.html#cloned_instead_of_copied) -* [`collapsible_str_replace`](https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_str_replace) -* [`deprecated_cfg_attr`](https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_cfg_attr) -* [`derivable_impls`](https://rust-lang.github.io/rust-clippy/master/index.html#derivable_impls) -* [`err_expect`](https://rust-lang.github.io/rust-clippy/master/index.html#err_expect) -* [`filter_map_next`](https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next) -* [`from_over_into`](https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into) -* [`if_then_some_else_none`](https://rust-lang.github.io/rust-clippy/master/index.html#if_then_some_else_none) -* [`index_refutable_slice`](https://rust-lang.github.io/rust-clippy/master/index.html#index_refutable_slice) -* [`iter_kv_map`](https://rust-lang.github.io/rust-clippy/master/index.html#iter_kv_map) -* [`legacy_numeric_constants`](https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants) -* [`manual_bits`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_bits) -* [`manual_c_str_literals`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_c_str_literals) -* [`manual_clamp`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_clamp) -* [`manual_hash_one`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_hash_one) -* [`manual_is_ascii_check`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_ascii_check) -* [`manual_let_else`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else) -* [`manual_non_exhaustive`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive) -* [`manual_range_contains`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains) -* [`manual_rem_euclid`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_rem_euclid) -* [`manual_retain`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain) -* [`manual_split_once`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_split_once) -* [`manual_str_repeat`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_str_repeat) -* [`manual_strip`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip) -* [`manual_try_fold`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold) -* [`map_clone`](https://rust-lang.github.io/rust-clippy/master/index.html#map_clone) -* [`map_unwrap_or`](https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or) -* [`match_like_matches_macro`](https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro) -* [`mem_replace_with_default`](https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default) -* [`missing_const_for_fn`](https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn) -* [`needless_borrow`](https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow) -* [`option_as_ref_deref`](https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref) -* [`option_map_unwrap_or`](https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unwrap_or) -* [`ptr_as_ptr`](https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr) -* [`redundant_field_names`](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names) -* [`redundant_static_lifetimes`](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes) -* [`seek_from_current`](https://rust-lang.github.io/rust-clippy/master/index.html#seek_from_current) -* [`seek_rewind`](https://rust-lang.github.io/rust-clippy/master/index.html#seek_rewind) -* [`transmute_ptr_to_ref`](https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ref) -* [`tuple_array_conversions`](https://rust-lang.github.io/rust-clippy/master/index.html#tuple_array_conversions) -* [`type_repetition_in_bounds`](https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds) -* [`unchecked_duration_subtraction`](https://rust-lang.github.io/rust-clippy/master/index.html#unchecked_duration_subtraction) -* [`uninlined_format_args`](https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args) -* [`unnecessary_lazy_evaluations`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations) -* [`unnested_or_patterns`](https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns) -* [`use_self`](https://rust-lang.github.io/rust-clippy/master/index.html#use_self) - - -## `pass-by-value-size-limit` -The minimum size (in bytes) to consider a type for passing by reference instead of by value. - -**Default Value:** `256` - ---- -**Affected lints:** -* [`large_types_passed_by_value`](https://rust-lang.github.io/rust-clippy/master/index.html#large_types_passed_by_value) - - -## `pub-underscore-fields-behavior` -Lint "public" fields in a struct that are prefixed with an underscore based on their -exported visibility, or whether they are marked as "pub". - -**Default Value:** `"PubliclyExported"` - ---- -**Affected lints:** -* [`pub_underscore_fields`](https://rust-lang.github.io/rust-clippy/master/index.html#pub_underscore_fields) - - -## `semicolon-inside-block-ignore-singleline` -Whether to lint only if it's multiline. - -**Default Value:** `false` - ---- -**Affected lints:** -* [`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` - ---- -**Affected lints:** -* [`semicolon_outside_block`](https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_outside_block) - - -## `single-char-binding-names-threshold` -The maximum number of single char bindings a scope may have - -**Default Value:** `4` - ---- -**Affected lints:** -* [`many_single_char_names`](https://rust-lang.github.io/rust-clippy/master/index.html#many_single_char_names) - - -## `stack-size-threshold` -The maximum allowed stack size for functions in bytes - -**Default Value:** `512000` - ---- -**Affected lints:** -* [`large_stack_frames`](https://rust-lang.github.io/rust-clippy/master/index.html#large_stack_frames) - - -## `standard-macro-braces` -Enforce the named macros always use the braces specified. - -A `MacroMatcher` can be added like so `{ name = "macro_name", brace = "(" }`. If the macro -could be used with a full path two `MacroMatcher`s have to be added one with the full path -`crate_name::macro_name` and one with just the macro name. - -**Default Value:** `[]` - ---- -**Affected lints:** -* [`nonstandard_macro_braces`](https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces) - - -## `struct-field-name-threshold` -The minimum number of struct fields for the lints about field names to trigger - -**Default Value:** `3` - ---- -**Affected lints:** -* [`struct_field_names`](https://rust-lang.github.io/rust-clippy/master/index.html#struct_field_names) - - -## `suppress-restriction-lint-in-const` -Whether to suppress a restriction lint in constant code. In same -cases the restructured operation might not be unavoidable, as the -suggested counterparts are unavailable in constant code. This -configuration will cause restriction lints to trigger even -if no suggestion can be made. - -**Default Value:** `false` - ---- -**Affected lints:** -* [`indexing_slicing`](https://rust-lang.github.io/rust-clippy/master/index.html#indexing_slicing) - - -## `too-large-for-stack` -The maximum size of objects (in bytes) that will be linted. Larger objects are ok on the heap - -**Default Value:** `200` - ---- -**Affected lints:** -* [`boxed_local`](https://rust-lang.github.io/rust-clippy/master/index.html#boxed_local) -* [`useless_vec`](https://rust-lang.github.io/rust-clippy/master/index.html#useless_vec) - - -## `too-many-arguments-threshold` -The maximum number of argument a function or method can have - -**Default Value:** `7` - ---- -**Affected lints:** -* [`too_many_arguments`](https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments) - - -## `too-many-lines-threshold` -The maximum number of lines a function or method can have - -**Default Value:** `100` - ---- -**Affected lints:** -* [`too_many_lines`](https://rust-lang.github.io/rust-clippy/master/index.html#too_many_lines) - - -## `trivial-copy-size-limit` -The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by -reference. By default there is no limit - ---- -**Affected lints:** -* [`trivially_copy_pass_by_ref`](https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref) - - -## `type-complexity-threshold` -The maximum complexity a type can have - -**Default Value:** `250` - ---- -**Affected lints:** -* [`type_complexity`](https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity) - - -## `unnecessary-box-size` -The byte size a `T` in `Box` can have, below which it triggers the `clippy::unnecessary_box` lint - -**Default Value:** `128` - ---- -**Affected lints:** -* [`unnecessary_box_returns`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_box_returns) - - -## `unreadable-literal-lint-fractions` -Should the fraction of a decimal be linted to include separators. - -**Default Value:** `true` - ---- -**Affected lints:** -* [`unreadable_literal`](https://rust-lang.github.io/rust-clippy/master/index.html#unreadable_literal) - - -## `upper-case-acronyms-aggressive` -Enables verbose mode. Triggers if there is more than one uppercase char next to each other - -**Default Value:** `false` - ---- -**Affected lints:** -* [`upper_case_acronyms`](https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms) - - -## `vec-box-size-threshold` -The size of the boxed type in bytes, where boxing in a `Vec` is allowed - -**Default Value:** `4096` - ---- -**Affected lints:** -* [`vec_box`](https://rust-lang.github.io/rust-clippy/master/index.html#vec_box) - - -## `verbose-bit-mask-threshold` -The maximum allowed size of a bit mask before suggesting to use 'trailing_zeros' - -**Default Value:** `1` - ---- -**Affected lints:** -* [`verbose_bit_mask`](https://rust-lang.github.io/rust-clippy/master/index.html#verbose_bit_mask) - - -## `warn-on-all-wildcard-imports` -Whether to allow certain wildcard imports (prelude, super in tests). - -**Default Value:** `false` - ---- -**Affected lints:** -* [`wildcard_imports`](https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports) - - -## `warn-unsafe-macro-metavars-in-private-macros` -Whether to also emit warnings for unsafe blocks with metavariable expansions in **private** macros. - -**Default Value:** `false` - ---- -**Affected lints:** -* [`macro_metavars_in_unsafe`](https://rust-lang.github.io/rust-clippy/master/index.html#macro_metavars_in_unsafe) - - diff --git a/book/src/lints.md b/book/src/lints.md deleted file mode 100644 index 442dc63914e9..000000000000 --- a/book/src/lints.md +++ /dev/null @@ -1,105 +0,0 @@ -# Clippy's Lints - -Clippy offers a bunch of additional lints, to help its users write more correct -and idiomatic Rust code. A full list of all lints, that can be filtered by -category, lint level or keywords, can be found in the [Clippy lint -documentation]. - -This chapter will give an overview of the different lint categories, which kind -of lints they offer and recommended actions when you should see a lint out of -that category. For examples, see the [Clippy lint documentation] and filter by -category. - -The different lint groups were defined in the [Clippy 1.0 RFC]. - -## Correctness - -The `clippy::correctness` group is the only lint group in Clippy which lints are -deny-by-default and abort the compilation when triggered. This is for good -reason: If you see a `correctness` lint, it means that your code is outright -wrong or useless, and you should try to fix it. - -Lints in this category are carefully picked and should be free of false -positives. So just `#[allow]`ing those lints is not recommended. - -## Suspicious - -The `clippy::suspicious` group is similar to the correctness lints in that it -contains lints that trigger on code that is really _sus_ and should be fixed. As -opposed to correctness lints, it might be possible that the linted code is -intentionally written like it is. - -It is still recommended to fix code that is linted by lints out of this group -instead of `#[allow]`ing the lint. In case you intentionally have written code -that offends the lint you should specifically and locally `#[allow]` the lint -and add give a reason why the code is correct as written. - -## Complexity - -The `clippy::complexity` group offers lints that give you suggestions on how to -simplify your code. It mostly focuses on code that can be written in a shorter -and more readable way, while preserving the semantics. - -If you should see a complexity lint, it usually means that you can remove or -replace some code, and it is recommended to do so. However, if you need the more -complex code for some expressiveness reason, it is recommended to allow -complexity lints on a case-by-case basis. - -## Perf - -The `clippy::perf` group gives you suggestions on how you can increase the -performance of your code. Those lints are mostly about code that the compiler -can't trivially optimize, but has to be written in a slightly different way to -make the optimizer job easier. - -Perf lints are usually easy to apply, and it is recommended to do so. - -## Style - -The `clippy::style` group is mostly about writing idiomatic code. Because style -is subjective, this lint group is the most opinionated warn-by-default group in -Clippy. - -If you see a style lint, applying the suggestion usually makes your code more -readable and idiomatic. But because we know that this is opinionated, feel free -to sprinkle `#[allow]`s for style lints in your code or `#![allow]` a style lint -on your whole crate if you disagree with the suggested style completely. - -## Pedantic - -The `clippy::pedantic` group makes Clippy even more _pedantic_. You can enable -the whole group with `#![warn(clippy::pedantic)]` in the `lib.rs`/`main.rs` of -your crate. This lint group is for Clippy power users that want an in depth -check of their code. - -> _Note:_ Instead of enabling the whole group (like Clippy itself does), you may -> want to cherry-pick lints out of the pedantic group. - -If you enable this group, expect to also use `#[allow]` attributes generously -throughout your code. Lints in this group are designed to be pedantic and false -positives sometimes are intentional in order to prevent false negatives. - -## Restriction - -The `clippy::restriction` group contains lints that will _restrict_ you from -using certain parts of the Rust language. It is **not** recommended to enable -the whole group, but rather cherry-pick lints that are useful for your code base -and your use case. - -> _Note:_ Clippy will produce a warning if it finds a -> `#![warn(clippy::restriction)]` attribute in your code! - -Lints from this group will restrict you in some way. If you enable a restriction -lint for your crate it is recommended to also fix code that this lint triggers -on. However, those lints are really strict by design, and you might want to -`#[allow]` them in some special cases, with a comment justifying that. - -## Cargo - -The `clippy::cargo` group gives you suggestions on how to improve your -`Cargo.toml` file. This might be especially interesting if you want to publish -your crate and are not sure if you have all useful information in your -`Cargo.toml`. - -[Clippy lint documentation]: https://rust-lang.github.io/rust-clippy/ -[Clippy 1.0 RFC]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#lint-audit-and-categories diff --git a/book/src/usage.md b/book/src/usage.md deleted file mode 100644 index 36448e4cccfa..000000000000 --- a/book/src/usage.md +++ /dev/null @@ -1,152 +0,0 @@ -# Usage - -This chapter describes how to use Clippy to get the most out of it. Clippy can -be used as a `cargo` subcommand or, like `rustc`, directly with the -`clippy-driver` binary. - -> _Note:_ This chapter assumes that you have Clippy installed already. If you're -> not sure, take a look at the [Installation] chapter. - -## Cargo subcommand - -The easiest and most common way to run Clippy is through `cargo`. To do that, -just run - -```bash -cargo clippy -``` - -### Lint configuration - -The above command will run the default set of lints, which are included in the -lint group `clippy::all`. You might want to use even more lints, or you may not -agree with every Clippy lint, and for that there are ways to configure lint -levels. - -> _Note:_ Clippy is meant to be used with a generous sprinkling of -> `#[allow(..)]`s through your code. So if you disagree with a lint, don't feel -> bad disabling them for parts of your code or the whole project. - -#### Command line - -You can configure lint levels on the command line by adding -`-A/W/D clippy::lint_name` like this: - -```bash -cargo clippy -- -Aclippy::style -Wclippy::double_neg -Dclippy::perf -``` - -For [CI] all warnings can be elevated to errors which will inturn fail -the build and cause Clippy to exit with a code other than `0`. - -``` -cargo clippy -- -Dwarnings -``` - -> _Note:_ Adding `-D warnings` will cause your build to fail if **any** warnings -> are found in your code. That includes warnings found by rustc (e.g. -> `dead_code`, etc.). - -For more information on configuring lint levels, see the [rustc documentation]. - -[rustc documentation]: https://doc.rust-lang.org/rustc/lints/levels.html#configuring-warning-levels - -#### Even more lints - -Clippy has lint groups which are allow-by-default. This means, that you will -have to enable the lints in those groups manually. - -For a full list of all lints with their description and examples, please refer -to [Clippy's lint list]. The two most important allow-by-default groups are -described below: - -[Clippy's lint list]: https://rust-lang.github.io/rust-clippy/master/index.html - -##### `clippy::pedantic` - -The first group is the `pedantic` group. This group contains really opinionated -lints, that may have some intentional false positives in order to prevent false -negatives. So while this group is ready to be used in production, you can expect -to sprinkle multiple `#[allow(..)]`s in your code. If you find any false -positives, you're still welcome to report them to us for future improvements. - -> FYI: Clippy uses the whole group to lint itself. - -##### `clippy::restriction` - -The second group is the `restriction` group. This group contains lints that -"restrict" the language in some way. For example the `clippy::unwrap` lint from -this group won't allow you to use `.unwrap()` in your code. You may want to look -through the lints in this group and enable the ones that fit your need. - -> _Note:_ You shouldn't enable the whole lint group, but cherry-pick lints from -> this group. Some lints in this group will even contradict other Clippy lints! - -#### Too many lints - -The most opinionated warn-by-default group of Clippy is the `clippy::style` -group. Some people prefer to disable this group completely and then cherry-pick -some lints they like from this group. The same is of course possible with every -other of Clippy's lint groups. - -> _Note:_ We try to keep the warn-by-default groups free from false positives -> (FP). If you find that a lint wrongly triggers, please report it in an issue -> (if there isn't an issue for that FP already) - -#### Source Code - -You can configure lint levels in source code the same way you can configure -`rustc` lints: - -```rust,ignore -#![allow(clippy::style)] - -#[warn(clippy::double_neg)] -fn main() { - let x = 1; - let y = --x; - // ^^ warning: double negation -} -``` - -### Automatically applying Clippy suggestions - -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 -``` - -### Workspaces - -All the usual workspace options should work with Clippy. For example the -following command will run Clippy on the `example` crate in your workspace: - -```terminal -cargo clippy -p example -``` - -As with `cargo check`, this includes dependencies that are members of the -workspace, like path dependencies. If you want to run Clippy **only** on the -given crate, use the `--no-deps` option like this: - -```terminal -cargo clippy -p example -- --no-deps -``` - -## Using Clippy without `cargo`: `clippy-driver` - -Clippy can also be used in projects that do not use cargo. To do so, run -`clippy-driver` with the same arguments you use for `rustc`. For example: - -```terminal -clippy-driver --edition 2018 -Cpanic=abort foo.rs -``` - -> _Note:_ `clippy-driver` is designed for running Clippy and should not be used -> as a general replacement for `rustc`. `clippy-driver` may produce artifacts -> that are not optimized as expected, for example. - -[Installation]: installation.md -[CI]: continuous_integration/index.md diff --git a/build.rs b/build.rs deleted file mode 100644 index b79d09b0dd2d..000000000000 --- a/build.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - // Forward the profile to the main compilation - println!("cargo:rustc-env=PROFILE={}", std::env::var("PROFILE").unwrap()); - // Don't rebuild even if nothing changed - println!("cargo:rerun-if-changed=build.rs"); - rustc_tools_util::setup_version_info!(); -} diff --git a/clippy.toml b/clippy.toml deleted file mode 100644 index 62ed55beb1f3..000000000000 --- a/clippy.toml +++ /dev/null @@ -1,10 +0,0 @@ -avoid-breaking-exported-api = false - -[[disallowed-methods]] -path = "rustc_lint::context::LintContext::span_lint" -reason = "this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint*` functions instead" - - -[[disallowed-methods]] -path = "rustc_middle::ty::context::TyCtxt::node_span_lint" -reason = "this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint_hir*` functions instead" diff --git a/clippy_config/Cargo.toml b/clippy_config/Cargo.toml deleted file mode 100644 index 7f7dc9d6cfb0..000000000000 --- a/clippy_config/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "clippy_config" -version = "0.1.80" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -rustc-semver = "1.1" -serde = { version = "1.0", features = ["derive"] } -toml = "0.7.3" - -[dev-dependencies] -walkdir = "2.3" - -[features] -deny-warnings = [] - -[package.metadata.rust-analyzer] -# This crate uses #[feature(rustc_private)] -rustc_private = true diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs deleted file mode 100644 index a4b29afa7779..000000000000 --- a/clippy_config/src/conf.rs +++ /dev/null @@ -1,916 +0,0 @@ -use crate::msrvs::Msrv; -use crate::types::{DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename}; -use crate::ClippyConfiguration; -use rustc_data_structures::fx::FxHashSet; -use rustc_errors::Applicability; -use rustc_session::Session; -use rustc_span::edit_distance::edit_distance; -use rustc_span::{BytePos, Pos, SourceFile, Span, SyntaxContext}; -use serde::de::{IgnoredAny, IntoDeserializer, MapAccess, Visitor}; -use serde::{Deserialize, Deserializer, Serialize}; -use std::fmt::{Debug, Display, Formatter}; -use std::ops::Range; -use std::path::PathBuf; -use std::str::FromStr; -use std::sync::OnceLock; -use std::{cmp, env, fmt, fs, io}; - -#[rustfmt::skip] -const DEFAULT_DOC_VALID_IDENTS: &[&str] = &[ - "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", - "DirectX", - "ECMAScript", - "GPLv2", "GPLv3", - "GitHub", "GitLab", - "IPv4", "IPv6", - "ClojureScript", "CoffeeScript", "JavaScript", "PureScript", "TypeScript", - "WebAssembly", - "NaN", "NaNs", - "OAuth", "GraphQL", - "OCaml", - "OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry", - "WebGL", "WebGL2", "WebGPU", - "TensorFlow", - "TrueType", - "iOS", "macOS", "FreeBSD", - "TeX", "LaTeX", "BibTeX", "BibLaTeX", - "MinGW", - "CamelCase", -]; -const DEFAULT_DISALLOWED_NAMES: &[&str] = &["foo", "baz", "quux"]; -const DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS: &[&str] = &["i", "j", "x", "y", "z", "w", "n"]; -const DEFAULT_ALLOWED_PREFIXES: &[&str] = &["to", "as", "into", "from", "try_into", "try_from"]; -const DEFAULT_ALLOWED_TRAITS_WITH_RENAMED_PARAMS: &[&str] = - &["core::convert::From", "core::convert::TryFrom", "core::str::FromStr"]; - -/// Conf with parse errors -#[derive(Default)] -struct TryConf { - conf: Conf, - errors: Vec, - warnings: Vec, -} - -impl TryConf { - fn from_toml_error(file: &SourceFile, error: &toml::de::Error) -> Self { - Self { - conf: Conf::default(), - errors: vec![ConfError::from_toml(file, error)], - warnings: vec![], - } - } -} - -#[derive(Debug)] -struct ConfError { - message: String, - suggestion: Option, - span: Span, -} - -impl ConfError { - fn from_toml(file: &SourceFile, error: &toml::de::Error) -> Self { - let span = error.span().unwrap_or(0..file.source_len.0 as usize); - Self::spanned(file, error.message(), None, span) - } - - fn spanned( - file: &SourceFile, - message: impl Into, - suggestion: Option, - span: Range, - ) -> Self { - Self { - message: message.into(), - suggestion, - span: Span::new( - file.start_pos + BytePos::from_usize(span.start), - file.start_pos + BytePos::from_usize(span.end), - SyntaxContext::root(), - None, - ), - } - } -} - -macro_rules! wrap_option { - () => { - None - }; - ($x:literal) => { - Some($x) - }; -} - -macro_rules! default_text { - ($value:expr) => {{ - let mut text = String::new(); - $value.serialize(toml::ser::ValueSerializer::new(&mut text)).unwrap(); - text - }}; - ($value:expr, $override:expr) => { - $override.to_string() - }; -} - -macro_rules! define_Conf { - ($( - $(#[doc = $doc:literal])+ - $(#[conf_deprecated($dep:literal, $new_conf:ident)])? - $(#[default_text = $default_text:expr])? - ($name:ident: $ty:ty = $default:expr), - )*) => { - /// Clippy lint configuration - pub struct Conf { - $($(#[doc = $doc])+ pub $name: $ty,)* - } - - mod defaults { - use super::*; - $(pub fn $name() -> $ty { $default })* - } - - impl Default for Conf { - fn default() -> Self { - Self { $($name: defaults::$name(),)* } - } - } - - #[derive(Deserialize)] - #[serde(field_identifier, rename_all = "kebab-case")] - #[allow(non_camel_case_types)] - enum Field { $($name,)* third_party, } - - struct ConfVisitor<'a>(&'a SourceFile); - - impl<'de> Visitor<'de> for ConfVisitor<'_> { - type Value = TryConf; - - fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - formatter.write_str("Conf") - } - - fn visit_map(self, mut map: V) -> Result where V: MapAccess<'de> { - let mut errors = Vec::new(); - let mut warnings = Vec::new(); - $(let mut $name = None;)* - // could get `Field` here directly, but get `String` first for diagnostics - while let Some(name) = map.next_key::>()? { - match Field::deserialize(name.get_ref().as_str().into_deserializer()) { - Err(e) => { - let e: FieldError = e; - errors.push(ConfError::spanned(self.0, e.error, e.suggestion, name.span())); - } - $(Ok(Field::$name) => { - $(warnings.push(ConfError::spanned(self.0, format!("deprecated field `{}`. {}", name.get_ref(), $dep), None, name.span()));)? - let raw_value = map.next_value::>()?; - let value_span = raw_value.span(); - match <$ty>::deserialize(raw_value.into_inner()) { - Err(e) => errors.push(ConfError::spanned(self.0, e.to_string().replace('\n', " ").trim(), None, value_span)), - Ok(value) => match $name { - Some(_) => { - errors.push(ConfError::spanned(self.0, format!("duplicate field `{}`", name.get_ref()), None, name.span())); - } - None => { - $name = Some(value); - // $new_conf is the same as one of the defined `$name`s, so - // this variable is defined in line 2 of this function. - $(match $new_conf { - Some(_) => errors.push(ConfError::spanned(self.0, concat!( - "duplicate field `", stringify!($new_conf), - "` (provided as `", stringify!($name), "`)" - ), None, name.span())), - None => $new_conf = $name.clone(), - })? - }, - } - } - })* - // ignore contents of the third_party key - Ok(Field::third_party) => drop(map.next_value::()) - } - } - let conf = Conf { $($name: $name.unwrap_or_else(defaults::$name),)* }; - Ok(TryConf { conf, errors, warnings }) - } - } - - pub fn get_configuration_metadata() -> Vec { - let mut sorted = vec![ - $( - { - let deprecation_reason = wrap_option!($($dep)?); - - ClippyConfiguration::new( - stringify!($name), - default_text!(defaults::$name() $(, $default_text)?), - concat!($($doc, '\n',)*), - deprecation_reason, - ) - }, - )+ - ]; - sorted.sort_by(|a, b| a.name.cmp(&b.name)); - sorted - } - }; -} - -define_Conf! { - /// Lint: ARITHMETIC_SIDE_EFFECTS. - /// - /// Suppress checking of the passed type names in all types of operations. - /// - /// If a specific operation is desired, consider using `arithmetic_side_effects_allowed_binary` or `arithmetic_side_effects_allowed_unary` instead. - /// - /// #### Example - /// - /// ```toml - /// arithmetic-side-effects-allowed = ["SomeType", "AnotherType"] - /// ``` - /// - /// #### Noteworthy - /// - /// A type, say `SomeType`, listed in this configuration has the same behavior of - /// `["SomeType" , "*"], ["*", "SomeType"]` in `arithmetic_side_effects_allowed_binary`. - (arithmetic_side_effects_allowed: FxHashSet = <_>::default()), - /// Lint: ARITHMETIC_SIDE_EFFECTS. - /// - /// Suppress checking of the passed type pair names in binary operations like addition or - /// multiplication. - /// - /// Supports the "*" wildcard to indicate that a certain type won't trigger the lint regardless - /// of the involved counterpart. For example, `["SomeType", "*"]` or `["*", "AnotherType"]`. - /// - /// Pairs are asymmetric, which means that `["SomeType", "AnotherType"]` is not the same as - /// `["AnotherType", "SomeType"]`. - /// - /// #### Example - /// - /// ```toml - /// arithmetic-side-effects-allowed-binary = [["SomeType" , "f32"], ["AnotherType", "*"]] - /// ``` - (arithmetic_side_effects_allowed_binary: Vec<[String; 2]> = <_>::default()), - /// Lint: ARITHMETIC_SIDE_EFFECTS. - /// - /// Suppress checking of the passed type names in unary operations like "negation" (`-`). - /// - /// #### Example - /// - /// ```toml - /// arithmetic-side-effects-allowed-unary = ["SomeType", "AnotherType"] - /// ``` - (arithmetic_side_effects_allowed_unary: FxHashSet = <_>::default()), - /// Lint: ENUM_VARIANT_NAMES, LARGE_TYPES_PASSED_BY_VALUE, TRIVIALLY_COPY_PASS_BY_REF, UNNECESSARY_WRAPS, UNUSED_SELF, UPPER_CASE_ACRONYMS, WRONG_SELF_CONVENTION, BOX_COLLECTION, REDUNDANT_ALLOCATION, RC_BUFFER, VEC_BOX, OPTION_OPTION, LINKEDLIST, RC_MUTEX, UNNECESSARY_BOX_RETURNS, SINGLE_CALL_FN. - /// - /// Suppress lints whenever the suggested change would cause breakage for other crates. - (avoid_breaking_exported_api: bool = true), - /// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, OPTION_MAP_UNWRAP_OR, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP, MANUAL_LET_ELSE, UNCHECKED_DURATION_SUBTRACTION, COLLAPSIBLE_STR_REPLACE, SEEK_FROM_CURRENT, SEEK_REWIND, UNNECESSARY_LAZY_EVALUATIONS, TRANSMUTE_PTR_TO_REF, ALMOST_COMPLETE_RANGE, NEEDLESS_BORROW, DERIVABLE_IMPLS, MANUAL_IS_ASCII_CHECK, MANUAL_REM_EUCLID, MANUAL_RETAIN, TYPE_REPETITION_IN_BOUNDS, TUPLE_ARRAY_CONVERSIONS, MANUAL_TRY_FOLD, MANUAL_HASH_ONE, ITER_KV_MAP, MANUAL_C_STR_LITERALS, ASSIGNING_CLONES, LEGACY_NUMERIC_CONSTANTS. - /// - /// The minimum rust version that the project supports. Defaults to the `rust-version` field in `Cargo.toml` - #[default_text = ""] - (msrv: Msrv = Msrv::empty()), - /// DEPRECATED LINT: BLACKLISTED_NAME. - /// - /// Use the Disallowed Names lint instead - #[conf_deprecated("Please use `disallowed-names` instead", disallowed_names)] - (blacklisted_names: Vec = Vec::new()), - /// Lint: COGNITIVE_COMPLEXITY. - /// - /// The maximum cognitive complexity a function can have - (cognitive_complexity_threshold: u64 = 25), - /// Lint: EXCESSIVE_NESTING. - /// - /// The maximum amount of nesting a block can reside in - (excessive_nesting_threshold: u64 = 0), - /// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY. - /// - /// Use the Cognitive Complexity lint instead. - #[conf_deprecated("Please use `cognitive-complexity-threshold` instead", cognitive_complexity_threshold)] - (cyclomatic_complexity_threshold: u64 = 25), - /// Lint: DISALLOWED_NAMES. - /// - /// The list of disallowed names to lint about. NB: `bar` is not here since it has legitimate uses. The value - /// `".."` can be used as part of the list to indicate that the configured values should be appended to the - /// default configuration of Clippy. By default, any configuration will replace the default value. - (disallowed_names: Vec = DEFAULT_DISALLOWED_NAMES.iter().map(ToString::to_string).collect()), - /// Lint: SEMICOLON_INSIDE_BLOCK. - /// - /// Whether to lint only if it's multiline. - (semicolon_inside_block_ignore_singleline: bool = false), - /// Lint: SEMICOLON_OUTSIDE_BLOCK. - /// - /// Whether to lint only if it's singleline. - (semicolon_outside_block_ignore_multiline: bool = false), - /// Lint: DOC_MARKDOWN. - /// - /// 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 - /// default configuration of Clippy. By default, any configuration will replace the default value. For example: - /// * `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`. - /// * `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list. - (doc_valid_idents: Vec = DEFAULT_DOC_VALID_IDENTS.iter().map(ToString::to_string).collect()), - /// Lint: TOO_MANY_ARGUMENTS. - /// - /// The maximum number of argument a function or method can have - (too_many_arguments_threshold: u64 = 7), - /// Lint: TYPE_COMPLEXITY. - /// - /// The maximum complexity a type can have - (type_complexity_threshold: u64 = 250), - /// Lint: MANY_SINGLE_CHAR_NAMES. - /// - /// The maximum number of single char bindings a scope may have - (single_char_binding_names_threshold: u64 = 4), - /// Lint: BOXED_LOCAL, USELESS_VEC. - /// - /// The maximum size of objects (in bytes) that will be linted. Larger objects are ok on the heap - (too_large_for_stack: u64 = 200), - /// Lint: ENUM_VARIANT_NAMES. - /// - /// The minimum number of enum variants for the lints about variant names to trigger - (enum_variant_name_threshold: u64 = 3), - /// Lint: STRUCT_FIELD_NAMES. - /// - /// The minimum number of struct fields for the lints about field names to trigger - (struct_field_name_threshold: u64 = 3), - /// Lint: LARGE_ENUM_VARIANT. - /// - /// The maximum size of an enum's variant to avoid box suggestion - (enum_variant_size_threshold: u64 = 200), - /// Lint: VERBOSE_BIT_MASK. - /// - /// The maximum allowed size of a bit mask before suggesting to use 'trailing_zeros' - (verbose_bit_mask_threshold: u64 = 1), - /// Lint: DECIMAL_LITERAL_REPRESENTATION. - /// - /// The lower bound for linting decimal literals - (literal_representation_threshold: u64 = 16384), - /// Lint: TRIVIALLY_COPY_PASS_BY_REF. - /// - /// The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by - /// reference. By default there is no limit - #[default_text = ""] - (trivial_copy_size_limit: Option = None), - /// Lint: LARGE_TYPES_PASSED_BY_VALUE. - /// - /// The minimum size (in bytes) to consider a type for passing by reference instead of by value. - (pass_by_value_size_limit: u64 = 256), - /// Lint: TOO_MANY_LINES. - /// - /// The maximum number of lines a function or method can have - (too_many_lines_threshold: u64 = 100), - /// Lint: LARGE_STACK_ARRAYS, LARGE_CONST_ARRAYS. - /// - /// The maximum allowed size for arrays on the stack - (array_size_threshold: u64 = 512_000), - /// Lint: LARGE_STACK_FRAMES. - /// - /// The maximum allowed stack size for functions in bytes - (stack_size_threshold: u64 = 512_000), - /// Lint: VEC_BOX. - /// - /// The size of the boxed type in bytes, where boxing in a `Vec` is allowed - (vec_box_size_threshold: u64 = 4096), - /// Lint: TYPE_REPETITION_IN_BOUNDS. - /// - /// The maximum number of bounds a trait can have to be linted - (max_trait_bounds: u64 = 3), - /// Lint: STRUCT_EXCESSIVE_BOOLS. - /// - /// The maximum number of bool fields a struct can have - (max_struct_bools: u64 = 3), - /// Lint: FN_PARAMS_EXCESSIVE_BOOLS. - /// - /// The maximum number of bool parameters a function can have - (max_fn_params_bools: u64 = 3), - /// Lint: WILDCARD_IMPORTS. - /// - /// Whether to allow certain wildcard imports (prelude, super in tests). - (warn_on_all_wildcard_imports: bool = false), - /// Lint: DISALLOWED_MACROS. - /// - /// The list of disallowed macros, written as fully qualified paths. - (disallowed_macros: Vec = Vec::new()), - /// Lint: DISALLOWED_METHODS. - /// - /// The list of disallowed methods, written as fully qualified paths. - (disallowed_methods: Vec = Vec::new()), - /// Lint: DISALLOWED_TYPES. - /// - /// The list of disallowed types, written as fully qualified paths. - (disallowed_types: Vec = Vec::new()), - /// Lint: UNREADABLE_LITERAL. - /// - /// Should the fraction of a decimal be linted to include separators. - (unreadable_literal_lint_fractions: bool = true), - /// Lint: UPPER_CASE_ACRONYMS. - /// - /// Enables verbose mode. Triggers if there is more than one uppercase char next to each other - (upper_case_acronyms_aggressive: bool = false), - /// Lint: MANUAL_LET_ELSE. - /// - /// Whether the matches should be considered by the lint, and whether there should - /// be filtering for common types. - (matches_for_let_else: MatchLintBehaviour = MatchLintBehaviour::WellKnownTypes), - /// Lint: CARGO_COMMON_METADATA. - /// - /// For internal testing only, ignores the current `publish` settings in the Cargo manifest. - (cargo_ignore_publish: bool = false), - /// Lint: NONSTANDARD_MACRO_BRACES. - /// - /// Enforce the named macros always use the braces specified. - /// - /// A `MacroMatcher` can be added like so `{ name = "macro_name", brace = "(" }`. If the macro - /// could be used with a full path two `MacroMatcher`s have to be added one with the full path - /// `crate_name::macro_name` and one with just the macro name. - (standard_macro_braces: Vec = Vec::new()), - /// Lint: MISSING_ENFORCED_IMPORT_RENAMES. - /// - /// The list of imports to always rename, a fully qualified path followed by the rename. - (enforced_import_renames: Vec = Vec::new()), - /// Lint: DISALLOWED_SCRIPT_IDENTS. - /// - /// The list of unicode scripts allowed to be used in the scope. - (allowed_scripts: Vec = vec!["Latin".to_string()]), - /// Lint: NON_SEND_FIELDS_IN_SEND_TY. - /// - /// Whether to apply the raw pointer heuristic to determine if a type is `Send`. - (enable_raw_pointer_heuristic_for_send: bool = true), - /// Lint: INDEX_REFUTABLE_SLICE. - /// - /// When Clippy suggests using a slice pattern, this is the maximum number of elements allowed in - /// the slice pattern that is suggested. If more elements are necessary, the lint is suppressed. - /// For example, `[_, _, _, e, ..]` is a slice pattern with 4 elements. - (max_suggested_slice_pattern_length: u64 = 3), - /// Lint: AWAIT_HOLDING_INVALID_TYPE. - (await_holding_invalid_types: Vec = Vec::new()), - /// Lint: LARGE_INCLUDE_FILE. - /// - /// The maximum size of a file included via `include_bytes!()` or `include_str!()`, in bytes - (max_include_file_size: u64 = 1_000_000), - /// Lint: EXPECT_USED. - /// - /// Whether `expect` should be allowed in test functions or `#[cfg(test)]` - (allow_expect_in_tests: bool = false), - /// Lint: UNWRAP_USED. - /// - /// Whether `unwrap` should be allowed in test functions or `#[cfg(test)]` - (allow_unwrap_in_tests: bool = false), - /// Lint: DBG_MACRO. - /// - /// Whether `dbg!` should be allowed in test functions or `#[cfg(test)]` - (allow_dbg_in_tests: bool = false), - /// Lint: PRINT_STDOUT, PRINT_STDERR. - /// - /// Whether print macros (ex. `println!`) should be allowed in test functions or `#[cfg(test)]` - (allow_print_in_tests: bool = false), - /// Lint: USELESS_VEC. - /// - /// Whether `useless_vec` should ignore test functions or `#[cfg(test)]` - (allow_useless_vec_in_tests: bool = false), - /// Lint: RESULT_LARGE_ERR. - /// - /// The maximum size of the `Err`-variant in a `Result` returned from a function - (large_error_threshold: u64 = 128), - /// Lint: MUTABLE_KEY_TYPE, IFS_SAME_COND, BORROW_INTERIOR_MUTABLE_CONST, DECLARE_INTERIOR_MUTABLE_CONST. - /// - /// A list of paths to types that should be treated as if they do not contain interior mutability - (ignore_interior_mutability: Vec = Vec::from(["bytes::Bytes".into()])), - /// Lint: UNINLINED_FORMAT_ARGS. - /// - /// Whether to allow mixed uninlined format args, e.g. `format!("{} {}", a, foo.bar)` - (allow_mixed_uninlined_format_args: bool = true), - /// Lint: INDEXING_SLICING. - /// - /// Whether to suppress a restriction lint in constant code. In same - /// cases the restructured operation might not be unavoidable, as the - /// suggested counterparts are unavailable in constant code. This - /// configuration will cause restriction lints to trigger even - /// if no suggestion can be made. - (suppress_restriction_lint_in_const: bool = false), - /// Lint: MISSING_DOCS_IN_PRIVATE_ITEMS. - /// - /// Whether to **only** check for missing documentation in items visible within the current - /// crate. For example, `pub(crate)` items. - (missing_docs_in_crate_items: bool = false), - /// Lint: LARGE_FUTURES. - /// - /// The maximum byte size a `Future` can have, before it triggers the `clippy::large_futures` lint - (future_size_threshold: u64 = 16 * 1024), - /// Lint: UNNECESSARY_BOX_RETURNS. - /// - /// The byte size a `T` in `Box` can have, below which it triggers the `clippy::unnecessary_box` lint - (unnecessary_box_size: u64 = 128), - /// Lint: MODULE_INCEPTION. - /// - /// Whether to allow module inception if it's not public. - (allow_private_module_inception: bool = false), - /// Lint: MIN_IDENT_CHARS. - /// - /// Allowed names below the minimum allowed characters. The value `".."` can be used as part of - /// the list to indicate, that the configured values should be appended to the default - /// configuration of Clippy. By default, any configuration will replace the default value. - (allowed_idents_below_min_chars: FxHashSet = - DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS.iter().map(ToString::to_string).collect()), - /// Lint: MIN_IDENT_CHARS. - /// - /// Minimum chars an ident can have, anything below or equal to this will be linted. - (min_ident_chars_threshold: u64 = 1), - /// Lint: UNDOCUMENTED_UNSAFE_BLOCKS. - /// - /// Whether to accept a safety comment to be placed above the statement containing the `unsafe` block - (accept_comment_above_statement: bool = true), - /// Lint: UNDOCUMENTED_UNSAFE_BLOCKS. - /// - /// Whether to accept a safety comment to be placed above the attributes for the `unsafe` block - (accept_comment_above_attributes: bool = true), - /// Lint: UNNECESSARY_RAW_STRING_HASHES. - /// - /// Whether to allow `r#""#` when `r""` can be used - (allow_one_hash_in_raw_strings: bool = false), - /// Lint: ABSOLUTE_PATHS. - /// - /// The maximum number of segments a path can have before being linted, anything above this will - /// be linted. - (absolute_paths_max_segments: u64 = 2), - /// Lint: ABSOLUTE_PATHS. - /// - /// Which crates to allow absolute paths from - (absolute_paths_allowed_crates: FxHashSet = FxHashSet::default()), - /// Lint: PATH_ENDS_WITH_EXT. - /// - /// Additional dotfiles (files or directories starting with a dot) to allow - (allowed_dotfiles: FxHashSet = FxHashSet::default()), - /// Lint: MULTIPLE_CRATE_VERSIONS. - /// - /// A list of crate names to allow duplicates of - (allowed_duplicate_crates: FxHashSet = FxHashSet::default()), - /// Lint: EXPLICIT_ITER_LOOP. - /// - /// Whether to recommend using implicit into iter for reborrowed values. - /// - /// #### Example - /// ```no_run - /// let mut vec = vec![1, 2, 3]; - /// let rmvec = &mut vec; - /// for _ in rmvec.iter() {} - /// for _ in rmvec.iter_mut() {} - /// ``` - /// - /// Use instead: - /// ```no_run - /// let mut vec = vec![1, 2, 3]; - /// let rmvec = &mut vec; - /// for _ in &*rmvec {} - /// for _ in &mut *rmvec {} - /// ``` - (enforce_iter_loop_reborrow: bool = false), - /// Lint: MISSING_SAFETY_DOC, UNNECESSARY_SAFETY_DOC, MISSING_PANICS_DOC, MISSING_ERRORS_DOC. - /// - /// Whether to also run the listed lints on private items. - (check_private_items: bool = false), - /// Lint: PUB_UNDERSCORE_FIELDS. - /// - /// Lint "public" fields in a struct that are prefixed with an underscore based on their - /// exported visibility, or whether they are marked as "pub". - (pub_underscore_fields_behavior: PubUnderscoreFieldsBehaviour = PubUnderscoreFieldsBehaviour::PubliclyExported), - /// Lint: MODULO_ARITHMETIC. - /// - /// Don't lint when comparing the result of a modulo operation to zero. - (allow_comparison_to_zero: bool = true), - /// Lint: WILDCARD_IMPORTS. - /// - /// List of path segments allowed to have wildcard imports. - /// - /// #### Example - /// - /// ```toml - /// allowed-wildcard-imports = [ "utils", "common" ] - /// ``` - /// - /// #### Noteworthy - /// - /// 1. This configuration has no effects if used with `warn_on_all_wildcard_imports = true`. - /// 2. Paths with any segment that containing the word 'prelude' - /// are already allowed by default. - (allowed_wildcard_imports: FxHashSet = FxHashSet::default()), - /// Lint: MODULE_NAME_REPETITIONS. - /// - /// List of prefixes to allow when determining whether an item's name ends with the module's name. - /// If the rest of an item's name is an allowed prefix (e.g. item `ToFoo` or `to_foo` in module `foo`), - /// then don't emit a warning. - /// - /// #### Example - /// - /// ```toml - /// allowed-prefixes = [ "to", "from" ] - /// ``` - /// - /// #### Noteworthy - /// - /// - By default, the following prefixes are allowed: `to`, `as`, `into`, `from`, `try_into` and `try_from` - /// - PascalCase variant is included automatically for each snake_case variant (e.g. if `try_into` is included, - /// `TryInto` will also be included) - /// - Use `".."` as part of the list to indicate that the configured values should be appended to the - /// default configuration of Clippy. By default, any configuration will replace the default value - (allowed_prefixes: Vec = DEFAULT_ALLOWED_PREFIXES.iter().map(ToString::to_string).collect()), - /// Lint: RENAMED_FUNCTION_PARAMS. - /// - /// List of trait paths to ignore when checking renamed function parameters. - /// - /// #### Example - /// - /// ```toml - /// allow-renamed-params-for = [ "std::convert::From" ] - /// ``` - /// - /// #### Noteworthy - /// - /// - By default, the following traits are ignored: `From`, `TryFrom`, `FromStr` - /// - `".."` can be used as part of the list to indicate that the configured values should be appended to the - /// default configuration of Clippy. By default, any configuration will replace the default value. - (allow_renamed_params_for: Vec = - DEFAULT_ALLOWED_TRAITS_WITH_RENAMED_PARAMS.iter().map(ToString::to_string).collect()), - /// Lint: MACRO_METAVARS_IN_UNSAFE. - /// - /// Whether to also emit warnings for unsafe blocks with metavariable expansions in **private** macros. - (warn_unsafe_macro_metavars_in_private_macros: bool = false), -} - -/// Search for the configuration file. -/// -/// # Errors -/// -/// Returns any unexpected filesystem error encountered when searching for the config file -pub fn lookup_conf_file() -> io::Result<(Option, Vec)> { - /// Possible filename to search for. - const CONFIG_FILE_NAMES: [&str; 2] = [".clippy.toml", "clippy.toml"]; - - // Start looking for a config file in CLIPPY_CONF_DIR, or failing that, CARGO_MANIFEST_DIR. - // If neither of those exist, use ".". (Update documentation if this priority changes) - let mut current = env::var_os("CLIPPY_CONF_DIR") - .or_else(|| env::var_os("CARGO_MANIFEST_DIR")) - .map_or_else(|| PathBuf::from("."), PathBuf::from) - .canonicalize()?; - - let mut found_config: Option = None; - let mut warnings = vec![]; - - loop { - for config_file_name in &CONFIG_FILE_NAMES { - if let Ok(config_file) = current.join(config_file_name).canonicalize() { - match fs::metadata(&config_file) { - Err(e) if e.kind() == io::ErrorKind::NotFound => {}, - Err(e) => return Err(e), - Ok(md) if md.is_dir() => {}, - Ok(_) => { - // warn if we happen to find two config files #8323 - if let Some(ref found_config) = found_config { - warnings.push(format!( - "using config file `{}`, `{}` will be ignored", - found_config.display(), - config_file.display() - )); - } else { - found_config = Some(config_file); - } - }, - } - } - } - - if found_config.is_some() { - return Ok((found_config, warnings)); - } - - // If the current directory has no parent, we're done searching. - if !current.pop() { - return Ok((None, warnings)); - } - } -} - -fn deserialize(file: &SourceFile) -> TryConf { - match toml::de::Deserializer::new(file.src.as_ref().unwrap()).deserialize_map(ConfVisitor(file)) { - Ok(mut conf) => { - extend_vec_if_indicator_present(&mut conf.conf.doc_valid_idents, DEFAULT_DOC_VALID_IDENTS); - extend_vec_if_indicator_present(&mut conf.conf.disallowed_names, DEFAULT_DISALLOWED_NAMES); - extend_vec_if_indicator_present(&mut conf.conf.allowed_prefixes, DEFAULT_ALLOWED_PREFIXES); - extend_vec_if_indicator_present( - &mut conf.conf.allow_renamed_params_for, - DEFAULT_ALLOWED_TRAITS_WITH_RENAMED_PARAMS, - ); - // TODO: THIS SHOULD BE TESTED, this comment will be gone soon - if conf.conf.allowed_idents_below_min_chars.contains("..") { - conf.conf - .allowed_idents_below_min_chars - .extend(DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS.iter().map(ToString::to_string)); - } - - conf - }, - Err(e) => TryConf::from_toml_error(file, &e), - } -} - -fn extend_vec_if_indicator_present(vec: &mut Vec, default: &[&str]) { - if vec.contains(&"..".to_string()) { - vec.extend(default.iter().map(ToString::to_string)); - } -} - -impl Conf { - pub fn read(sess: &Session, path: &io::Result<(Option, Vec)>) -> &'static Conf { - static CONF: OnceLock = OnceLock::new(); - CONF.get_or_init(|| Conf::read_inner(sess, path)) - } - - fn read_inner(sess: &Session, path: &io::Result<(Option, Vec)>) -> Conf { - match path { - Ok((_, warnings)) => { - for warning in warnings { - sess.dcx().warn(warning.clone()); - } - }, - Err(error) => { - sess.dcx() - .err(format!("error finding Clippy's configuration file: {error}")); - }, - } - - let TryConf { - mut conf, - errors, - warnings, - } = match path { - Ok((Some(path), _)) => match sess.source_map().load_file(path) { - Ok(file) => deserialize(&file), - Err(error) => { - sess.dcx().err(format!("failed to read `{}`: {error}", path.display())); - TryConf::default() - }, - }, - _ => TryConf::default(), - }; - - conf.msrv.read_cargo(sess); - - // all conf errors are non-fatal, we just use the default conf in case of error - for error in errors { - let mut diag = sess.dcx().struct_span_err( - error.span, - format!("error reading Clippy's configuration file: {}", error.message), - ); - - if let Some(sugg) = error.suggestion { - diag.span_suggestion(error.span, sugg.message, sugg.suggestion, Applicability::MaybeIncorrect); - } - - diag.emit(); - } - - for warning in warnings { - sess.dcx().span_warn( - warning.span, - format!("error reading Clippy's configuration file: {}", warning.message), - ); - } - - conf - } -} - -const SEPARATOR_WIDTH: usize = 4; - -#[derive(Debug)] -struct FieldError { - error: String, - suggestion: Option, -} - -#[derive(Debug)] -struct Suggestion { - message: &'static str, - suggestion: &'static str, -} - -impl std::error::Error for FieldError {} - -impl Display for FieldError { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - f.pad(&self.error) - } -} - -impl serde::de::Error for FieldError { - fn custom(msg: T) -> Self { - Self { - error: msg.to_string(), - suggestion: None, - } - } - - fn unknown_field(field: &str, expected: &'static [&'static str]) -> Self { - // List the available fields sorted and at least one per line, more if `CLIPPY_TERMINAL_WIDTH` is - // set and allows it. - use fmt::Write; - - let mut expected = expected.to_vec(); - expected.sort_unstable(); - - let (rows, column_widths) = calculate_dimensions(&expected); - - let mut msg = format!("unknown field `{field}`, expected one of"); - for row in 0..rows { - writeln!(msg).unwrap(); - for (column, column_width) in column_widths.iter().copied().enumerate() { - let index = column * rows + row; - let field = expected.get(index).copied().unwrap_or_default(); - write!(msg, "{:SEPARATOR_WIDTH$}{field:column_width$}", " ").unwrap(); - } - } - - let suggestion = expected - .iter() - .filter_map(|expected| { - let dist = edit_distance(field, expected, 4)?; - Some((dist, expected)) - }) - .min_by_key(|&(dist, _)| dist) - .map(|(_, suggestion)| Suggestion { - message: "perhaps you meant", - suggestion, - }); - - Self { error: msg, suggestion } - } -} - -fn calculate_dimensions(fields: &[&str]) -> (usize, Vec) { - let columns = env::var("CLIPPY_TERMINAL_WIDTH") - .ok() - .and_then(|s| ::from_str(&s).ok()) - .map_or(1, |terminal_width| { - let max_field_width = fields.iter().map(|field| field.len()).max().unwrap(); - cmp::max(1, terminal_width / (SEPARATOR_WIDTH + max_field_width)) - }); - - let rows = (fields.len() + (columns - 1)) / columns; - - let column_widths = (0..columns) - .map(|column| { - if column < columns - 1 { - (0..rows) - .map(|row| { - let index = column * rows + row; - let field = fields.get(index).copied().unwrap_or_default(); - field.len() - }) - .max() - .unwrap() - } else { - // Avoid adding extra space to the last column. - 0 - } - }) - .collect::>(); - - (rows, column_widths) -} - -#[cfg(test)] -mod tests { - use rustc_data_structures::fx::{FxHashMap, FxHashSet}; - use serde::de::IgnoredAny; - use std::fs; - use walkdir::WalkDir; - - #[test] - fn configs_are_tested() { - let mut names: FxHashSet = crate::get_configuration_metadata() - .into_iter() - .map(|meta| meta.name.replace('_', "-")) - .collect(); - - let toml_files = WalkDir::new("../tests") - .into_iter() - .map(Result::unwrap) - .filter(|entry| entry.file_name() == "clippy.toml"); - - for entry in toml_files { - let file = fs::read_to_string(entry.path()).unwrap(); - #[allow(clippy::zero_sized_map_values)] - if let Ok(map) = toml::from_str::>(&file) { - for name in map.keys() { - names.remove(name.as_str()); - } - } - } - - assert!( - names.is_empty(), - "Configuration variable lacks test: {names:?}\nAdd a test to `tests/ui-toml`" - ); - } -} diff --git a/clippy_config/src/lib.rs b/clippy_config/src/lib.rs deleted file mode 100644 index ff7fa7241cb9..000000000000 --- a/clippy_config/src/lib.rs +++ /dev/null @@ -1,31 +0,0 @@ -#![feature(rustc_private, let_chains)] -#![cfg_attr(feature = "deny-warnings", deny(warnings))] -#![warn( - trivial_casts, - trivial_numeric_casts, - rust_2018_idioms, - unused_lifetimes, - unused_qualifications -)] -#![allow( - clippy::must_use_candidate, - clippy::missing_panics_doc, - rustc::diagnostic_outside_of_impl, - rustc::untranslatable_diagnostic -)] - -extern crate rustc_ast; -extern crate rustc_data_structures; -#[allow(unused_extern_crates)] -extern crate rustc_driver; -extern crate rustc_errors; -extern crate rustc_session; -extern crate rustc_span; - -mod conf; -mod metadata; -pub mod msrvs; -pub mod types; - -pub use conf::{get_configuration_metadata, lookup_conf_file, Conf}; -pub use metadata::ClippyConfiguration; diff --git a/clippy_config/src/metadata.rs b/clippy_config/src/metadata.rs deleted file mode 100644 index 400887185e8c..000000000000 --- a/clippy_config/src/metadata.rs +++ /dev/null @@ -1,121 +0,0 @@ -use std::fmt::{self, Write}; - -#[derive(Debug, Clone, Default)] -pub struct ClippyConfiguration { - pub name: String, - pub default: String, - pub lints: Vec, - pub doc: String, - pub deprecation_reason: Option<&'static str>, -} - -impl fmt::Display for ClippyConfiguration { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "- `{}`: {}", self.name, self.doc)?; - if !self.default.is_empty() { - write!(f, " (default: `{}`)", self.default)?; - } - Ok(()) - } -} - -impl ClippyConfiguration { - pub fn new( - name: &'static str, - default: String, - doc_comment: &'static str, - deprecation_reason: Option<&'static str>, - ) -> Self { - let (mut lints, doc) = parse_config_field_doc(doc_comment) - .unwrap_or_else(|| (vec![], "[ERROR] MALFORMED DOC COMMENT".to_string())); - - lints.sort(); - - Self { - name: to_kebab(name), - lints, - doc, - default, - deprecation_reason, - } - } - - pub fn to_markdown_paragraph(&self) -> String { - let mut out = format!( - "## `{}`\n{}\n\n", - self.name, - self.doc - .lines() - .map(|line| line.strip_prefix(" ").unwrap_or(line)) - .collect::>() - .join("\n"), - ); - - if !self.default.is_empty() { - write!(out, "**Default Value:** `{}`\n\n", self.default).unwrap(); - } - - write!( - out, - "---\n**Affected lints:**\n{}\n\n", - self.lints - .iter() - .map(|name| name.to_string().split_whitespace().next().unwrap().to_string()) - .map(|name| format!("* [`{name}`](https://rust-lang.github.io/rust-clippy/master/index.html#{name})")) - .collect::>() - .join("\n"), - ) - .unwrap(); - - out - } - - pub fn to_markdown_link(&self) -> String { - const BOOK_CONFIGS_PATH: &str = "https://doc.rust-lang.org/clippy/lint_configuration.html"; - format!("[`{}`]: {BOOK_CONFIGS_PATH}#{}", self.name, self.name) - } -} - -/// This parses the field documentation of the config struct. -/// -/// ```rust, ignore -/// parse_config_field_doc(cx, "Lint: LINT_NAME_1, LINT_NAME_2. Papa penguin, papa penguin") -/// ``` -/// -/// Would yield: -/// ```rust, ignore -/// Some(["lint_name_1", "lint_name_2"], "Papa penguin, papa penguin") -/// ``` -fn parse_config_field_doc(doc_comment: &str) -> Option<(Vec, String)> { - const DOC_START: &str = " Lint: "; - if doc_comment.starts_with(DOC_START) - && let Some(split_pos) = doc_comment.find('.') - { - let mut doc_comment = doc_comment.to_string(); - let mut documentation = doc_comment.split_off(split_pos); - - // Extract lints - doc_comment.make_ascii_lowercase(); - let lints: Vec = doc_comment - .split_off(DOC_START.len()) - .lines() - .next() - .unwrap() - .split(", ") - .map(str::to_string) - .collect(); - - // Format documentation correctly - // split off leading `.` from lint name list and indent for correct formatting - documentation = documentation.trim_start_matches('.').trim().replace("\n ", "\n "); - - Some((lints, documentation)) - } else { - None - } -} - -/// Transforms a given `snake_case_string` to a tasty `kebab-case-string` -fn to_kebab(config_name: &str) -> String { - config_name.replace('_', "-") -} diff --git a/clippy_config/src/msrvs.rs b/clippy_config/src/msrvs.rs deleted file mode 100644 index 14808440d48d..000000000000 --- a/clippy_config/src/msrvs.rs +++ /dev/null @@ -1,157 +0,0 @@ -use rustc_ast::Attribute; -use rustc_semver::RustcVersion; -use rustc_session::Session; -use rustc_span::{sym, Symbol}; -use serde::Deserialize; -use std::fmt; - -macro_rules! msrv_aliases { - ($($major:literal,$minor:literal,$patch:literal { - $($name:ident),* $(,)? - })*) => { - $($( - pub const $name: RustcVersion = RustcVersion::new($major, $minor, $patch); - )*)* - }; -} - -// names may refer to stabilized feature flags or library items -msrv_aliases! { - 1,77,0 { C_STR_LITERALS } - 1,76,0 { PTR_FROM_REF } - 1,71,0 { TUPLE_ARRAY_CONVERSIONS, BUILD_HASHER_HASH_ONE } - 1,70,0 { OPTION_RESULT_IS_VARIANT_AND, BINARY_HEAP_RETAIN } - 1,68,0 { PATH_MAIN_SEPARATOR_STR } - 1,65,0 { LET_ELSE, POINTER_CAST_CONSTNESS } - 1,63,0 { CLONE_INTO } - 1,62,0 { BOOL_THEN_SOME, DEFAULT_ENUM_ATTRIBUTE } - 1,59,0 { THREAD_LOCAL_INITIALIZER_CAN_BE_MADE_CONST } - 1,58,0 { FORMAT_ARGS_CAPTURE, PATTERN_TRAIT_CHAR_ARRAY } - 1,55,0 { SEEK_REWIND } - 1,54,0 { INTO_KEYS } - 1,53,0 { OR_PATTERNS, MANUAL_BITS, BTREE_MAP_RETAIN, BTREE_SET_RETAIN, ARRAY_INTO_ITERATOR } - 1,52,0 { STR_SPLIT_ONCE, REM_EUCLID_CONST } - 1,51,0 { BORROW_AS_PTR, SEEK_FROM_CURRENT, UNSIGNED_ABS } - 1,50,0 { BOOL_THEN, CLAMP } - 1,47,0 { TAU, IS_ASCII_DIGIT_CONST, ARRAY_IMPL_ANY_LEN } - 1,46,0 { CONST_IF_MATCH } - 1,45,0 { STR_STRIP_PREFIX } - 1,43,0 { LOG2_10, LOG10_2, NUMERIC_ASSOCIATED_CONSTANTS } - 1,42,0 { MATCHES_MACRO, SLICE_PATTERNS, PTR_SLICE_RAW_PARTS } - 1,41,0 { RE_REBALANCING_COHERENCE, RESULT_MAP_OR_ELSE } - 1,40,0 { MEM_TAKE, NON_EXHAUSTIVE, OPTION_AS_DEREF } - 1,38,0 { POINTER_CAST, REM_EUCLID } - 1,37,0 { TYPE_ALIAS_ENUM_VARIANTS } - 1,36,0 { ITERATOR_COPIED } - 1,35,0 { OPTION_COPIED, RANGE_CONTAINS } - 1,34,0 { TRY_FROM } - 1,30,0 { ITERATOR_FIND_MAP, TOOL_ATTRIBUTES } - 1,29,0 { ITER_FLATTEN } - 1,28,0 { FROM_BOOL } - 1,27,0 { ITERATOR_TRY_FOLD } - 1,26,0 { RANGE_INCLUSIVE, STRING_RETAIN } - 1,24,0 { IS_ASCII_DIGIT } - 1,18,0 { HASH_MAP_RETAIN, HASH_SET_RETAIN } - 1,17,0 { FIELD_INIT_SHORTHAND, STATIC_IN_CONST, EXPECT_ERR } - 1,16,0 { STR_REPEAT } - 1,15,0 { MAYBE_BOUND_IN_WHERE } -} - -/// Tracks the current MSRV from `clippy.toml`, `Cargo.toml` or set via `#[clippy::msrv]` -#[derive(Debug, Clone)] -pub struct Msrv { - stack: Vec, -} - -impl fmt::Display for Msrv { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if let Some(msrv) = self.current() { - write!(f, "{msrv}") - } else { - f.write_str("1.0.0") - } - } -} - -impl<'de> Deserialize<'de> for Msrv { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - let v = String::deserialize(deserializer)?; - RustcVersion::parse(&v) - .map(|v| Msrv { stack: vec![v] }) - .map_err(|_| serde::de::Error::custom("not a valid Rust version")) - } -} - -impl Msrv { - pub fn empty() -> Msrv { - Msrv { stack: Vec::new() } - } - - pub fn read_cargo(&mut self, sess: &Session) { - let cargo_msrv = std::env::var("CARGO_PKG_RUST_VERSION") - .ok() - .and_then(|v| RustcVersion::parse(&v).ok()); - - match (self.current(), cargo_msrv) { - (None, Some(cargo_msrv)) => self.stack = vec![cargo_msrv], - (Some(clippy_msrv), Some(cargo_msrv)) => { - if clippy_msrv != cargo_msrv { - sess.dcx().warn(format!( - "the MSRV in `clippy.toml` and `Cargo.toml` differ; using `{clippy_msrv}` from `clippy.toml`" - )); - } - }, - _ => {}, - } - } - - pub fn current(&self) -> Option { - self.stack.last().copied() - } - - pub fn meets(&self, required: RustcVersion) -> bool { - self.current().map_or(true, |version| version.meets(required)) - } - - fn parse_attr(sess: &Session, attrs: &[Attribute]) -> Option { - let sym_msrv = Symbol::intern("msrv"); - let mut msrv_attrs = attrs.iter().filter(|attr| attr.path_matches(&[sym::clippy, sym_msrv])); - - if let Some(msrv_attr) = msrv_attrs.next() { - if let Some(duplicate) = msrv_attrs.last() { - sess.dcx() - .struct_span_err(duplicate.span, "`clippy::msrv` is defined multiple times") - .with_span_note(msrv_attr.span, "first definition found here") - .emit(); - } - - if let Some(msrv) = msrv_attr.value_str() { - if let Ok(version) = RustcVersion::parse(msrv.as_str()) { - return Some(version); - } - - sess.dcx() - .span_err(msrv_attr.span, format!("`{msrv}` is not a valid Rust version")); - } else { - sess.dcx().span_err(msrv_attr.span, "bad clippy attribute"); - } - } - - None - } - - pub fn check_attributes(&mut self, sess: &Session, attrs: &[Attribute]) { - if let Some(version) = Self::parse_attr(sess, attrs) { - self.stack.push(version); - } - } - - pub fn check_attributes_post(&mut self, sess: &Session, attrs: &[Attribute]) { - if Self::parse_attr(sess, attrs).is_some() { - self.stack.pop(); - } - } -} diff --git a/clippy_config/src/types.rs b/clippy_config/src/types.rs deleted file mode 100644 index 435aa9244c52..000000000000 --- a/clippy_config/src/types.rs +++ /dev/null @@ -1,134 +0,0 @@ -use serde::de::{self, Deserializer, Visitor}; -use serde::{ser, Deserialize, Serialize}; -use std::fmt; - -#[derive(Clone, Debug, Deserialize)] -pub struct Rename { - pub path: String, - pub rename: String, -} - -#[derive(Clone, Debug, Deserialize)] -#[serde(untagged)] -pub enum DisallowedPath { - Simple(String), - WithReason { path: String, reason: Option }, -} - -impl DisallowedPath { - pub fn path(&self) -> &str { - let (Self::Simple(path) | Self::WithReason { path, .. }) = self; - - path - } - - pub fn reason(&self) -> Option { - match self { - Self::WithReason { - reason: Some(reason), .. - } => Some(format!("{reason} (from clippy.toml)")), - _ => None, - } - } -} - -#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)] -pub enum MatchLintBehaviour { - AllTypes, - WellKnownTypes, - Never, -} - -#[derive(Debug)] -pub struct MacroMatcher { - pub name: String, - pub braces: (char, char), -} - -impl<'de> Deserialize<'de> for MacroMatcher { - fn deserialize(deser: D) -> Result - where - D: Deserializer<'de>, - { - #[derive(Deserialize)] - #[serde(field_identifier, rename_all = "lowercase")] - enum Field { - Name, - Brace, - } - struct MacVisitor; - impl<'de> Visitor<'de> for MacVisitor { - type Value = MacroMatcher; - - fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - formatter.write_str("struct MacroMatcher") - } - - fn visit_map(self, mut map: V) -> Result - where - V: de::MapAccess<'de>, - { - let mut name = None; - let mut brace: Option = None; - while let Some(key) = map.next_key()? { - match key { - Field::Name => { - if name.is_some() { - return Err(de::Error::duplicate_field("name")); - } - name = Some(map.next_value()?); - }, - Field::Brace => { - if brace.is_some() { - return Err(de::Error::duplicate_field("brace")); - } - brace = Some(map.next_value()?); - }, - } - } - let name = name.ok_or_else(|| de::Error::missing_field("name"))?; - let brace = brace.ok_or_else(|| de::Error::missing_field("brace"))?; - Ok(MacroMatcher { - name, - braces: [('(', ')'), ('{', '}'), ('[', ']')] - .into_iter() - .find(|b| b.0 == brace) - .map(|(o, c)| (o.to_owned(), c.to_owned())) - .ok_or_else(|| de::Error::custom(format!("expected one of `(`, `{{`, `[` found `{brace}`")))?, - }) - } - } - - const FIELDS: &[&str] = &["name", "brace"]; - deser.deserialize_struct("MacroMatcher", FIELDS, MacVisitor) - } -} - -// these impls are never actually called but are used by the various config options that default to -// empty lists -macro_rules! unimplemented_serialize { - ($($t:ty,)*) => { - $( - impl Serialize for $t { - fn serialize(&self, _serializer: S) -> Result - where - S: ser::Serializer, - { - Err(ser::Error::custom("unimplemented")) - } - } - )* - } -} - -unimplemented_serialize! { - DisallowedPath, - Rename, - MacroMatcher, -} - -#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)] -pub enum PubUnderscoreFieldsBehaviour { - PubliclyExported, - AllPubFields, -} diff --git a/clippy_dev/Cargo.toml b/clippy_dev/Cargo.toml deleted file mode 100644 index 4104e7d94f14..000000000000 --- a/clippy_dev/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "clippy_dev" -description = "Clippy developer tooling" -version = "0.0.1" -edition = "2021" - -[dependencies] -aho-corasick = "1.0" -clap = { version = "4.4", features = ["derive"] } -indoc = "1.0" -itertools = "0.12" -opener = "0.6" -shell-escape = "0.1" -walkdir = "2.3" - -[features] -deny-warnings = [] - -[package.metadata.rust-analyzer] -# This package uses #[feature(rustc_private)] -rustc_private = true diff --git a/clippy_dev/src/dogfood.rs b/clippy_dev/src/dogfood.rs deleted file mode 100644 index a0d57f5ab483..000000000000 --- a/clippy_dev/src/dogfood.rs +++ /dev/null @@ -1,31 +0,0 @@ -use crate::{clippy_project_root, exit_if_err}; -use std::process::Command; - -/// # Panics -/// -/// Panics if unable to run the dogfood test -pub fn dogfood(fix: bool, allow_dirty: bool, allow_staged: bool) { - let mut cmd = Command::new("cargo"); - - cmd.current_dir(clippy_project_root()) - .args(["test", "--test", "dogfood"]) - .args(["--features", "internal"]) - .args(["--", "dogfood_clippy", "--nocapture"]); - - let mut dogfood_args = Vec::new(); - if fix { - dogfood_args.push("--fix"); - } - - if allow_dirty { - dogfood_args.push("--allow-dirty"); - } - - if allow_staged { - dogfood_args.push("--allow-staged"); - } - - cmd.env("__CLIPPY_DOGFOOD_ARGS", dogfood_args.join(" ")); - - exit_if_err(cmd.status()); -} diff --git a/clippy_dev/src/fmt.rs b/clippy_dev/src/fmt.rs deleted file mode 100644 index 256231441817..000000000000 --- a/clippy_dev/src/fmt.rs +++ /dev/null @@ -1,226 +0,0 @@ -use crate::clippy_project_root; -use itertools::Itertools; -use shell_escape::escape; -use std::ffi::{OsStr, OsString}; -use std::path::Path; -use std::process::{self, Command, Stdio}; -use std::{fs, io}; -use walkdir::WalkDir; - -#[derive(Debug)] -pub enum CliError { - CommandFailed(String, String), - IoError(io::Error), - RustfmtNotInstalled, - WalkDirError(walkdir::Error), - IntellijSetupActive, -} - -impl From for CliError { - fn from(error: io::Error) -> Self { - Self::IoError(error) - } -} - -impl From for CliError { - fn from(error: walkdir::Error) -> Self { - Self::WalkDirError(error) - } -} - -struct FmtContext { - check: bool, - verbose: bool, - rustfmt_path: String, -} - -// the "main" function of cargo dev fmt -pub fn run(check: bool, verbose: bool) { - fn try_run(context: &FmtContext) -> Result { - let mut success = true; - - let project_root = clippy_project_root(); - - // if we added a local rustc repo as path dependency to clippy for rust analyzer, we do NOT want to - // format because rustfmt would also format the entire rustc repo as it is a local - // dependency - if fs::read_to_string(project_root.join("Cargo.toml")) - .expect("Failed to read clippy Cargo.toml") - .contains("[target.'cfg(NOT_A_PLATFORM)'.dependencies]") - { - return Err(CliError::IntellijSetupActive); - } - - rustfmt_test(context)?; - - success &= cargo_fmt(context, project_root.as_path())?; - success &= cargo_fmt(context, &project_root.join("clippy_dev"))?; - success &= cargo_fmt(context, &project_root.join("rustc_tools_util"))?; - success &= cargo_fmt(context, &project_root.join("lintcheck"))?; - - let chunks = WalkDir::new(project_root.join("tests")) - .into_iter() - .filter_map(|entry| { - let entry = entry.expect("failed to find tests"); - let path = entry.path(); - - if path.extension() != Some("rs".as_ref()) || entry.file_name() == "ice-3891.rs" { - None - } else { - Some(entry.into_path().into_os_string()) - } - }) - .chunks(250); - - for chunk in &chunks { - success &= rustfmt(context, chunk)?; - } - - Ok(success) - } - - fn output_err(err: CliError) { - match err { - CliError::CommandFailed(command, stderr) => { - eprintln!("error: A command failed! `{command}`\nstderr: {stderr}"); - }, - CliError::IoError(err) => { - eprintln!("error: {err}"); - }, - CliError::RustfmtNotInstalled => { - eprintln!("error: rustfmt nightly is not installed."); - }, - CliError::WalkDirError(err) => { - eprintln!("error: {err}"); - }, - CliError::IntellijSetupActive => { - eprintln!( - "error: a local rustc repo is enabled as path dependency via `cargo dev setup intellij`. -Not formatting because that would format the local repo as well! -Please revert the changes to Cargo.tomls with `cargo dev remove intellij`." - ); - }, - } - } - - let output = Command::new("rustup") - .args(["which", "rustfmt"]) - .stderr(Stdio::inherit()) - .output() - .expect("error running `rustup which rustfmt`"); - if !output.status.success() { - eprintln!("`rustup which rustfmt` did not execute successfully"); - process::exit(1); - } - let mut rustfmt_path = String::from_utf8(output.stdout).expect("invalid rustfmt path"); - rustfmt_path.truncate(rustfmt_path.trim_end().len()); - - let context = FmtContext { - check, - verbose, - rustfmt_path, - }; - let result = try_run(&context); - let code = match result { - Ok(true) => 0, - Ok(false) => { - eprintln!(); - eprintln!("Formatting check failed."); - eprintln!("Run `cargo dev fmt` to update formatting."); - 1 - }, - Err(err) => { - output_err(err); - 1 - }, - }; - process::exit(code); -} - -fn format_command(program: impl AsRef, dir: impl AsRef, args: &[impl AsRef]) -> String { - let arg_display: Vec<_> = args.iter().map(|a| escape(a.as_ref().to_string_lossy())).collect(); - - format!( - "cd {} && {} {}", - escape(dir.as_ref().to_string_lossy()), - escape(program.as_ref().to_string_lossy()), - arg_display.join(" ") - ) -} - -fn exec( - context: &FmtContext, - program: impl AsRef, - dir: impl AsRef, - args: &[impl AsRef], -) -> Result { - if context.verbose { - println!("{}", format_command(&program, &dir, args)); - } - - let output = Command::new(&program) - .env("RUSTFMT", &context.rustfmt_path) - .current_dir(&dir) - .args(args.iter()) - .output() - .unwrap(); - let success = output.status.success(); - - if !context.check && !success { - let stderr = std::str::from_utf8(&output.stderr).unwrap_or(""); - return Err(CliError::CommandFailed( - format_command(&program, &dir, args), - String::from(stderr), - )); - } - - Ok(success) -} - -fn cargo_fmt(context: &FmtContext, path: &Path) -> Result { - let mut args = vec!["fmt", "--all"]; - if context.check { - args.push("--check"); - } - let success = exec(context, "cargo", path, &args)?; - - Ok(success) -} - -fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> { - let program = "rustfmt"; - let dir = std::env::current_dir()?; - let args = &["--version"]; - - if context.verbose { - println!("{}", format_command(program, &dir, args)); - } - - let output = Command::new(program).current_dir(&dir).args(args.iter()).output()?; - - if output.status.success() { - Ok(()) - } else if std::str::from_utf8(&output.stderr) - .unwrap_or("") - .starts_with("error: 'rustfmt' is not installed") - { - Err(CliError::RustfmtNotInstalled) - } else { - Err(CliError::CommandFailed( - format_command(program, &dir, args), - std::str::from_utf8(&output.stderr).unwrap_or("").to_string(), - )) - } -} - -fn rustfmt(context: &FmtContext, paths: impl Iterator) -> Result { - let mut args = Vec::new(); - if context.check { - args.push(OsString::from("--check")); - } - args.extend(paths); - - let success = exec(context, &context.rustfmt_path, std::env::current_dir()?, &args)?; - - Ok(success) -} diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs deleted file mode 100644 index 385191e0361b..000000000000 --- a/clippy_dev/src/lib.rs +++ /dev/null @@ -1,84 +0,0 @@ -#![feature(lazy_cell)] -#![feature(let_chains)] -#![feature(rustc_private)] -#![cfg_attr(feature = "deny-warnings", deny(warnings))] -#![warn( - trivial_casts, - trivial_numeric_casts, - rust_2018_idioms, - unused_lifetimes, - unused_qualifications -)] -#![allow(clippy::missing_panics_doc)] - -// The `rustc_driver` crate seems to be required in order to use the `rust_lexer` crate. -#[allow(unused_extern_crates)] -extern crate rustc_driver; -extern crate rustc_lexer; - -use std::io; -use std::path::PathBuf; -use std::process::{self, ExitStatus}; - -pub mod dogfood; -pub mod fmt; -pub mod lint; -pub mod new_lint; -pub mod serve; -pub mod setup; -pub mod update_lints; - -#[cfg(not(windows))] -static CARGO_CLIPPY_EXE: &str = "cargo-clippy"; -#[cfg(windows)] -static CARGO_CLIPPY_EXE: &str = "cargo-clippy.exe"; - -/// Returns the path to the `cargo-clippy` binary -/// -/// # Panics -/// -/// Panics if the path of current executable could not be retrieved. -#[must_use] -pub fn cargo_clippy_path() -> PathBuf { - let mut path = std::env::current_exe().expect("failed to get current executable name"); - path.set_file_name(CARGO_CLIPPY_EXE); - path -} - -/// Returns the path to the Clippy project directory -/// -/// # Panics -/// -/// Panics if the current directory could not be retrieved, there was an error reading any of the -/// Cargo.toml files or ancestor directory is the clippy root directory -#[must_use] -pub fn clippy_project_root() -> PathBuf { - let current_dir = std::env::current_dir().unwrap(); - for path in current_dir.ancestors() { - let result = std::fs::read_to_string(path.join("Cargo.toml")); - if let Err(err) = &result { - if err.kind() == io::ErrorKind::NotFound { - continue; - } - } - - let content = result.unwrap(); - if content.contains("[package]\nname = \"clippy\"") { - return path.to_path_buf(); - } - } - panic!("error: Can't determine root of project. Please run inside a Clippy working dir."); -} - -/// # Panics -/// Panics if given command result was failed. -pub fn exit_if_err(status: io::Result) { - match status.expect("failed to run command").code() { - Some(0) => {}, - Some(n) => process::exit(n), - None => { - eprintln!("Killed by signal"); - process::exit(1); - }, - } -} diff --git a/clippy_dev/src/lint.rs b/clippy_dev/src/lint.rs deleted file mode 100644 index f308f5dfdfd8..000000000000 --- a/clippy_dev/src/lint.rs +++ /dev/null @@ -1,44 +0,0 @@ -use crate::{cargo_clippy_path, exit_if_err}; -use std::process::{self, Command}; -use std::{env, fs}; - -pub fn run<'a>(path: &str, args: impl Iterator) { - let is_file = match fs::metadata(path) { - Ok(metadata) => metadata.is_file(), - Err(e) => { - eprintln!("Failed to read {path}: {e:?}"); - process::exit(1); - }, - }; - - if is_file { - exit_if_err( - Command::new(env::var("CARGO").unwrap_or("cargo".into())) - .args(["run", "--bin", "clippy-driver", "--"]) - .args(["-L", "./target/debug"]) - .args(["-Z", "no-codegen"]) - .args(["--edition", "2021"]) - .arg(path) - .args(args) - // Prevent rustc from creating `rustc-ice-*` files the console output is enough. - .env("RUSTC_ICE", "0") - .status(), - ); - } else { - exit_if_err( - Command::new(env::var("CARGO").unwrap_or("cargo".into())) - .arg("build") - .status(), - ); - - let status = Command::new(cargo_clippy_path()) - .arg("clippy") - .args(args) - // Prevent rustc from creating `rustc-ice-*` files the console output is enough. - .env("RUSTC_ICE", "0") - .current_dir(path) - .status(); - - exit_if_err(status); - } -} diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs deleted file mode 100644 index 366b52b25dfc..000000000000 --- a/clippy_dev/src/main.rs +++ /dev/null @@ -1,293 +0,0 @@ -#![cfg_attr(feature = "deny-warnings", deny(warnings))] -// warn on lints, that are included in `rust-lang/rust`s bootstrap -#![warn(rust_2018_idioms, unused_lifetimes)] - -use clap::{Args, Parser, Subcommand}; -use clippy_dev::{dogfood, fmt, lint, new_lint, serve, setup, update_lints}; -use std::convert::Infallible; - -fn main() { - let dev = Dev::parse(); - - match dev.command { - DevCommand::Bless => { - eprintln!("use `cargo bless` to automatically replace `.stderr` and `.fixed` files as tests are being run"); - }, - DevCommand::Dogfood { - fix, - allow_dirty, - allow_staged, - } => dogfood::dogfood(fix, allow_dirty, allow_staged), - DevCommand::Fmt { check, verbose } => fmt::run(check, verbose), - DevCommand::UpdateLints { print_only, check } => { - if print_only { - update_lints::print_lints(); - } else if check { - update_lints::update(update_lints::UpdateMode::Check); - } else { - update_lints::update(update_lints::UpdateMode::Change); - } - }, - DevCommand::NewLint { - pass, - name, - category, - r#type, - msrv, - } => match new_lint::create(&pass, &name, &category, r#type.as_deref(), msrv) { - Ok(()) => update_lints::update(update_lints::UpdateMode::Change), - Err(e) => eprintln!("Unable to create lint: {e}"), - }, - DevCommand::Setup(SetupCommand { subcommand }) => match subcommand { - SetupSubcommand::Intellij { remove, repo_path } => { - if remove { - setup::intellij::remove_rustc_src(); - } else { - setup::intellij::setup_rustc_src(&repo_path); - } - }, - SetupSubcommand::GitHook { remove, force_override } => { - if remove { - setup::git_hook::remove_hook(); - } else { - setup::git_hook::install_hook(force_override); - } - }, - SetupSubcommand::Toolchain { force, release, name } => setup::toolchain::create(force, release, &name), - SetupSubcommand::VscodeTasks { remove, force_override } => { - if remove { - setup::vscode::remove_tasks(); - } else { - setup::vscode::install_tasks(force_override); - } - }, - }, - DevCommand::Remove(RemoveCommand { subcommand }) => match subcommand { - RemoveSubcommand::Intellij => setup::intellij::remove_rustc_src(), - RemoveSubcommand::GitHook => setup::git_hook::remove_hook(), - RemoveSubcommand::VscodeTasks => setup::vscode::remove_tasks(), - }, - DevCommand::Serve { port, lint } => serve::run(port, lint), - DevCommand::Lint { path, args } => lint::run(&path, args.iter()), - DevCommand::RenameLint { - old_name, - new_name, - uplift, - } => update_lints::rename(&old_name, new_name.as_ref().unwrap_or(&old_name), uplift), - DevCommand::Deprecate { name, reason } => update_lints::deprecate(&name, reason.as_deref()), - } -} - -#[derive(Parser)] -#[command(name = "dev", about)] -struct Dev { - #[command(subcommand)] - command: DevCommand, -} - -#[derive(Subcommand)] -enum DevCommand { - /// Bless the test output changes - Bless, - /// Runs the dogfood test - Dogfood { - #[arg(long)] - /// Apply the suggestions when possible - fix: bool, - #[arg(long, requires = "fix")] - /// Fix code even if the working directory has changes - allow_dirty: bool, - #[arg(long, requires = "fix")] - /// Fix code even if the working directory has staged changes - allow_staged: bool, - }, - /// Run rustfmt on all projects and tests - Fmt { - #[arg(long)] - /// Use the rustfmt --check option - check: bool, - #[arg(short, long)] - /// Echo commands run - verbose: bool, - }, - #[command(name = "update_lints")] - /// Updates lint registration and information from the source code - /// - /// Makes sure that: {n} - /// * 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/lib.rs` via `pub mod` {n} - /// * all lints are registered in the lint store - UpdateLints { - #[arg(long)] - /// Print a table of lints to STDOUT - /// - /// This does not include deprecated and internal lints. (Does not modify any files) - print_only: bool, - #[arg(long)] - /// Checks that `cargo dev update_lints` has been run. Used on CI. - check: bool, - }, - #[command(name = "new_lint")] - /// Create a new lint and run `cargo dev update_lints` - NewLint { - #[arg(short, long, value_parser = ["early", "late"], conflicts_with = "type", default_value = "late")] - /// Specify whether the lint runs during the early or late pass - pass: String, - #[arg( - short, - long, - value_parser = |name: &str| Ok::<_, Infallible>(name.replace('-', "_")), - )] - /// Name of the new lint in snake case, ex: `fn_too_long` - name: String, - #[arg( - short, - long, - value_parser = [ - "style", - "correctness", - "suspicious", - "complexity", - "perf", - "pedantic", - "restriction", - "cargo", - "nursery", - "internal", - ], - default_value = "nursery", - )] - /// What category the lint belongs to - category: String, - #[arg(long)] - /// What directory the lint belongs in - r#type: Option, - #[arg(long)] - /// Add MSRV config code to the lint - msrv: bool, - }, - /// Support for setting up your personal development environment - Setup(SetupCommand), - /// Support for removing changes done by the setup command - Remove(RemoveCommand), - /// Launch a local 'ALL the Clippy Lints' website in a browser - Serve { - #[arg(short, long, default_value = "8000")] - /// Local port for the http server - port: u16, - #[arg(long)] - /// Which lint's page to load initially (optional) - lint: Option, - }, - #[allow(clippy::doc_markdown)] - /// Manually run clippy on a file or package - /// - /// ## Examples - /// - /// Lint a single file: {n} - /// cargo dev lint tests/ui/attrs.rs - /// - /// Lint a package directory: {n} - /// cargo dev lint tests/ui-cargo/wildcard_dependencies/fail {n} - /// cargo dev lint ~/my-project - /// - /// Run rustfix: {n} - /// cargo dev lint ~/my-project -- --fix - /// - /// Set lint levels: {n} - /// cargo dev lint file.rs -- -W clippy::pedantic {n} - /// cargo dev lint ~/my-project -- -- -W clippy::pedantic - Lint { - /// The path to a file or package directory to lint - path: String, - /// Pass extra arguments to cargo/clippy-driver - args: Vec, - }, - #[command(name = "rename_lint")] - /// Rename a lint - RenameLint { - /// The name of the lint to rename - old_name: String, - #[arg(required_unless_present = "uplift")] - /// The new name of the lint - new_name: Option, - #[arg(long)] - /// This lint will be uplifted into rustc - uplift: bool, - }, - /// Deprecate the given lint - Deprecate { - /// The name of the lint to deprecate - name: String, - #[arg(long, short)] - /// The reason for deprecation - reason: Option, - }, -} - -#[derive(Args)] -struct SetupCommand { - #[command(subcommand)] - subcommand: SetupSubcommand, -} - -#[derive(Subcommand)] -enum SetupSubcommand { - /// Alter dependencies so Intellij Rust can find rustc internals - Intellij { - #[arg(long)] - /// Remove the dependencies added with 'cargo dev setup intellij' - remove: bool, - #[arg(long, short, conflicts_with = "remove")] - /// The path to a rustc repo that will be used for setting the dependencies - repo_path: String, - }, - /// Add a pre-commit git hook that formats your code to make it look pretty - GitHook { - #[arg(long)] - /// Remove the pre-commit hook added with 'cargo dev setup git-hook' - remove: bool, - #[arg(long, short)] - /// Forces the override of an existing git pre-commit hook - force_override: bool, - }, - /// Install a rustup toolchain pointing to the local clippy build - Toolchain { - #[arg(long, short)] - /// Override an existing toolchain - force: bool, - #[arg(long, short)] - /// Point to --release clippy binary - release: bool, - #[arg(long, default_value = "clippy")] - /// Name of the toolchain - name: String, - }, - /// Add several tasks to vscode for formatting, validation and testing - VscodeTasks { - #[arg(long)] - /// Remove the tasks added with 'cargo dev setup vscode-tasks' - remove: bool, - #[arg(long, short)] - /// Forces the override of existing vscode tasks - force_override: bool, - }, -} - -#[derive(Args)] -struct RemoveCommand { - #[command(subcommand)] - subcommand: RemoveSubcommand, -} - -#[derive(Subcommand)] -enum RemoveSubcommand { - /// Remove the dependencies added with 'cargo dev setup intellij' - Intellij, - /// Remove the pre-commit git hook - GitHook, - /// Remove the tasks added with 'cargo dev setup vscode-tasks' - VscodeTasks, -} diff --git a/clippy_dev/src/new_lint.rs b/clippy_dev/src/new_lint.rs deleted file mode 100644 index b6481dde4dde..000000000000 --- a/clippy_dev/src/new_lint.rs +++ /dev/null @@ -1,591 +0,0 @@ -use crate::clippy_project_root; -use indoc::{formatdoc, writedoc}; -use std::fmt; -use std::fmt::Write as _; -use std::fs::{self, OpenOptions}; -use std::io::prelude::*; -use std::io::{self, ErrorKind}; -use std::path::{Path, PathBuf}; - -struct LintData<'a> { - pass: &'a str, - name: &'a str, - category: &'a str, - ty: Option<&'a str>, - project_root: PathBuf, -} - -trait Context { - fn context>(self, text: C) -> Self; -} - -impl Context for io::Result { - fn context>(self, text: C) -> Self { - match self { - Ok(t) => Ok(t), - Err(e) => { - let message = format!("{}: {e}", text.as_ref()); - Err(io::Error::new(ErrorKind::Other, message)) - }, - } - } -} - -/// Creates the files required to implement and test a new lint and runs `update_lints`. -/// -/// # Errors -/// -/// This function errors out if the files couldn't be created or written to. -pub fn create(pass: &str, name: &str, category: &str, mut ty: Option<&str>, msrv: bool) -> io::Result<()> { - if category == "cargo" && ty.is_none() { - // `cargo` is a special category, these lints should always be in `clippy_lints/src/cargo` - ty = Some("cargo"); - } - - let lint = LintData { - pass, - name, - category, - ty, - project_root: clippy_project_root(), - }; - - create_lint(&lint, msrv).context("Unable to create lint implementation")?; - create_test(&lint, msrv).context("Unable to create a test for the new lint")?; - - if lint.ty.is_none() { - add_lint(&lint, msrv).context("Unable to add lint to clippy_lints/src/lib.rs")?; - } - - if pass == "early" { - println!( - "\n\ - NOTE: Use a late pass unless you need something specific from\n\ - an early pass, as they lack many features and utilities" - ); - } - - Ok(()) -} - -fn create_lint(lint: &LintData<'_>, enable_msrv: bool) -> io::Result<()> { - if let Some(ty) = lint.ty { - create_lint_for_ty(lint, enable_msrv, ty) - } else { - let lint_contents = get_lint_file_contents(lint, enable_msrv); - let lint_path = format!("clippy_lints/src/{}.rs", lint.name); - write_file(lint.project_root.join(&lint_path), lint_contents.as_bytes())?; - println!("Generated lint file: `{lint_path}`"); - - Ok(()) - } -} - -fn create_test(lint: &LintData<'_>, msrv: bool) -> io::Result<()> { - fn create_project_layout>( - lint_name: &str, - location: P, - case: &str, - hint: &str, - msrv: bool, - ) -> io::Result<()> { - let mut path = location.into().join(case); - fs::create_dir(&path)?; - write_file(path.join("Cargo.toml"), get_manifest_contents(lint_name, hint))?; - - path.push("src"); - fs::create_dir(&path)?; - write_file(path.join("main.rs"), get_test_file_contents(lint_name, msrv))?; - - Ok(()) - } - - if lint.category == "cargo" { - let relative_test_dir = format!("tests/ui-cargo/{}", lint.name); - let test_dir = lint.project_root.join(&relative_test_dir); - fs::create_dir(&test_dir)?; - - create_project_layout( - lint.name, - &test_dir, - "fail", - "Content that triggers the lint goes here", - msrv, - )?; - create_project_layout( - lint.name, - &test_dir, - "pass", - "This file should not trigger the lint", - false, - )?; - - println!("Generated test directories: `{relative_test_dir}/pass`, `{relative_test_dir}/fail`"); - } else { - let test_path = format!("tests/ui/{}.rs", lint.name); - let test_contents = get_test_file_contents(lint.name, msrv); - write_file(lint.project_root.join(&test_path), test_contents)?; - - println!("Generated test file: `{test_path}`"); - } - - Ok(()) -} - -fn add_lint(lint: &LintData<'_>, enable_msrv: bool) -> io::Result<()> { - let path = "clippy_lints/src/lib.rs"; - let mut lib_rs = fs::read_to_string(path).context("reading")?; - - let comment_start = lib_rs.find("// add lints here,").expect("Couldn't find comment"); - - let new_lint = if enable_msrv { - format!( - "store.register_{lint_pass}_pass(move |{ctor_arg}| Box::new({module_name}::{camel_name}::new(msrv())));\n ", - lint_pass = lint.pass, - ctor_arg = if lint.pass == "late" { "_" } else { "" }, - module_name = lint.name, - camel_name = to_camel_case(lint.name), - ) - } else { - format!( - "store.register_{lint_pass}_pass(|{ctor_arg}| Box::new({module_name}::{camel_name}));\n ", - lint_pass = lint.pass, - ctor_arg = if lint.pass == "late" { "_" } else { "" }, - module_name = lint.name, - camel_name = to_camel_case(lint.name), - ) - }; - - lib_rs.insert_str(comment_start, &new_lint); - - fs::write(path, lib_rs).context("writing") -} - -fn write_file, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> { - fn inner(path: &Path, contents: &[u8]) -> io::Result<()> { - OpenOptions::new() - .write(true) - .create_new(true) - .open(path)? - .write_all(contents) - } - - inner(path.as_ref(), contents.as_ref()).context(format!("writing to file: {}", path.as_ref().display())) -} - -fn to_camel_case(name: &str) -> String { - name.split('_') - .map(|s| { - if s.is_empty() { - String::new() - } else { - [&s[0..1].to_uppercase(), &s[1..]].concat() - } - }) - .collect() -} - -pub(crate) fn get_stabilization_version() -> String { - fn parse_manifest(contents: &str) -> Option { - let version = contents - .lines() - .filter_map(|l| l.split_once('=')) - .find_map(|(k, v)| (k.trim() == "version").then(|| v.trim()))?; - let Some(("0", version)) = version.get(1..version.len() - 1)?.split_once('.') else { - return None; - }; - let (minor, patch) = version.split_once('.')?; - Some(format!( - "{}.{}.0", - minor.parse::().ok()?, - patch.parse::().ok()? - )) - } - let contents = fs::read_to_string("Cargo.toml").expect("Unable to read `Cargo.toml`"); - parse_manifest(&contents).expect("Unable to find package version in `Cargo.toml`") -} - -fn get_test_file_contents(lint_name: &str, msrv: bool) -> String { - let mut test = formatdoc!( - r#" - #![warn(clippy::{lint_name})] - - fn main() {{ - // test code goes here - }} - "# - ); - - if msrv { - let _ = writedoc!( - test, - r#" - - // TODO: set xx to the version one below the MSRV used by the lint, and yy to - // the version used by the lint - #[clippy::msrv = "1.xx"] - fn msrv_1_xx() {{ - // a simple example that would trigger the lint if the MSRV were met - }} - - #[clippy::msrv = "1.yy"] - fn msrv_1_yy() {{ - // the same example as above - }} - "# - ); - } - - test -} - -fn get_manifest_contents(lint_name: &str, hint: &str) -> String { - formatdoc!( - r#" - # {hint} - - [package] - name = "{lint_name}" - version = "0.1.0" - publish = false - - [workspace] - "# - ) -} - -fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String { - let mut result = String::new(); - - let (pass_type, pass_lifetimes, pass_import, context_import) = match lint.pass { - "early" => ("EarlyLintPass", "", "use rustc_ast::ast::*;", "EarlyContext"), - "late" => ("LateLintPass", "<'_>", "use rustc_hir::*;", "LateContext"), - _ => { - unreachable!("`pass_type` should only ever be `early` or `late`!"); - }, - }; - - let lint_name = lint.name; - let category = lint.category; - let name_camel = to_camel_case(lint.name); - let name_upper = lint_name.to_uppercase(); - - result.push_str(&if enable_msrv { - formatdoc!( - r#" - use clippy_utils::msrvs::{{self, Msrv}}; - {pass_import} - use rustc_lint::{{{context_import}, {pass_type}, LintContext}}; - use rustc_session::impl_lint_pass; - - "# - ) - } else { - formatdoc!( - r#" - {pass_import} - use rustc_lint::{{{context_import}, {pass_type}}}; - use rustc_session::declare_lint_pass; - - "# - ) - }); - - let _: fmt::Result = writeln!(result, "{}", get_lint_declaration(&name_upper, category)); - - result.push_str(&if enable_msrv { - formatdoc!( - r#" - pub struct {name_camel} {{ - msrv: Msrv, - }} - - impl {name_camel} {{ - #[must_use] - pub fn new(msrv: Msrv) -> Self {{ - Self {{ msrv }} - }} - }} - - impl_lint_pass!({name_camel} => [{name_upper}]); - - impl {pass_type}{pass_lifetimes} for {name_camel} {{ - extract_msrv_attr!({context_import}); - }} - - // TODO: Add MSRV level to `clippy_config/src/msrvs.rs` if needed. - // TODO: Update msrv config comment in `clippy_config/src/conf.rs` - "# - ) - } else { - formatdoc!( - r#" - declare_lint_pass!({name_camel} => [{name_upper}]); - - impl {pass_type}{pass_lifetimes} for {name_camel} {{}} - "# - ) - }); - - result -} - -fn get_lint_declaration(name_upper: &str, category: &str) -> String { - formatdoc!( - r#" - declare_clippy_lint! {{ - /// ### What it does - /// - /// ### Why is this bad? - /// - /// ### Example - /// ```no_run - /// // example code where clippy issues a warning - /// ``` - /// Use instead: - /// ```no_run - /// // example code which does not raise clippy warning - /// ``` - #[clippy::version = "{}"] - pub {name_upper}, - {category}, - "default lint description" - }} - "#, - get_stabilization_version(), - ) -} - -fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::Result<()> { - match ty { - "cargo" => assert_eq!( - lint.category, "cargo", - "Lints of type `cargo` must have the `cargo` category" - ), - _ if lint.category == "cargo" => panic!("Lints of category `cargo` must have the `cargo` type"), - _ => {}, - } - - let ty_dir = lint.project_root.join(format!("clippy_lints/src/{ty}")); - assert!( - ty_dir.exists() && ty_dir.is_dir(), - "Directory `{}` does not exist!", - ty_dir.display() - ); - - let lint_file_path = ty_dir.join(format!("{}.rs", lint.name)); - assert!( - !lint_file_path.exists(), - "File `{}` already exists", - lint_file_path.display() - ); - - let mod_file_path = ty_dir.join("mod.rs"); - let context_import = setup_mod_file(&mod_file_path, lint)?; - let pass_lifetimes = match context_import { - "LateContext" => "<'_>", - _ => "", - }; - - let name_upper = lint.name.to_uppercase(); - let mut lint_file_contents = String::new(); - - if enable_msrv { - let _: fmt::Result = writedoc!( - lint_file_contents, - r#" - use clippy_utils::msrvs::{{self, Msrv}}; - use rustc_lint::{{{context_import}, LintContext}}; - - use super::{name_upper}; - - // TODO: Adjust the parameters as necessary - pub(super) fn check(cx: &{context_import}{pass_lifetimes}, msrv: &Msrv) {{ - if !msrv.meets(todo!("Add a new entry in `clippy_utils/src/msrvs`")) {{ - return; - }} - todo!(); - }} - "# - ); - } else { - let _: fmt::Result = writedoc!( - lint_file_contents, - r#" - use rustc_lint::{{{context_import}, LintContext}}; - - use super::{name_upper}; - - // TODO: Adjust the parameters as necessary - pub(super) fn check(cx: &{context_import}{pass_lifetimes}) {{ - todo!(); - }} - "# - ); - } - - write_file(lint_file_path.as_path(), lint_file_contents)?; - println!("Generated lint file: `clippy_lints/src/{ty}/{}.rs`", lint.name); - println!( - "Be sure to add a call to `{}::check` in `clippy_lints/src/{ty}/mod.rs`!", - lint.name - ); - - Ok(()) -} - -#[allow(clippy::too_many_lines)] -fn setup_mod_file(path: &Path, lint: &LintData<'_>) -> io::Result<&'static str> { - use super::update_lints::{match_tokens, LintDeclSearchResult}; - use rustc_lexer::TokenKind; - - let lint_name_upper = lint.name.to_uppercase(); - - let mut file_contents = fs::read_to_string(path)?; - assert!( - !file_contents.contains(&lint_name_upper), - "Lint `{}` already defined in `{}`", - lint.name, - path.display() - ); - - let mut offset = 0usize; - let mut last_decl_curly_offset = None; - let mut lint_context = None; - - let mut iter = rustc_lexer::tokenize(&file_contents).map(|t| { - let range = offset..offset + t.len as usize; - offset = range.end; - - LintDeclSearchResult { - token_kind: t.kind, - content: &file_contents[range.clone()], - range, - } - }); - - // Find both the last lint declaration (declare_clippy_lint!) and the lint pass impl - while let Some(LintDeclSearchResult { content, .. }) = iter.find(|result| result.token_kind == TokenKind::Ident) { - let mut iter = iter - .by_ref() - .filter(|t| !matches!(t.token_kind, TokenKind::Whitespace | TokenKind::LineComment { .. })); - - match content { - "declare_clippy_lint" => { - // matches `!{` - match_tokens!(iter, Bang OpenBrace); - if let Some(LintDeclSearchResult { range, .. }) = - iter.find(|result| result.token_kind == TokenKind::CloseBrace) - { - last_decl_curly_offset = Some(range.end); - } - }, - "impl" => { - let mut token = iter.next(); - match token { - // matches <'foo> - Some(LintDeclSearchResult { - token_kind: TokenKind::Lt, - .. - }) => { - match_tokens!(iter, Lifetime { .. } Gt); - token = iter.next(); - }, - None => break, - _ => {}, - } - - if let Some(LintDeclSearchResult { - token_kind: TokenKind::Ident, - content, - .. - }) = token - { - // Get the appropriate lint context struct - lint_context = match content { - "LateLintPass" => Some("LateContext"), - "EarlyLintPass" => Some("EarlyContext"), - _ => continue, - }; - } - }, - _ => {}, - } - } - - drop(iter); - - let last_decl_curly_offset = - last_decl_curly_offset.unwrap_or_else(|| panic!("No lint declarations found in `{}`", path.display())); - let lint_context = - lint_context.unwrap_or_else(|| panic!("No lint pass implementation found in `{}`", path.display())); - - // Add the lint declaration to `mod.rs` - file_contents.replace_range( - // Remove the trailing newline, which should always be present - last_decl_curly_offset..=last_decl_curly_offset, - &format!("\n\n{}", get_lint_declaration(&lint_name_upper, lint.category)), - ); - - // Add the lint to `impl_lint_pass`/`declare_lint_pass` - let impl_lint_pass_start = file_contents.find("impl_lint_pass!").unwrap_or_else(|| { - file_contents - .find("declare_lint_pass!") - .unwrap_or_else(|| panic!("failed to find `impl_lint_pass`/`declare_lint_pass`")) - }); - - let mut arr_start = file_contents[impl_lint_pass_start..].find('[').unwrap_or_else(|| { - panic!("malformed `impl_lint_pass`/`declare_lint_pass`"); - }); - - arr_start += impl_lint_pass_start; - - let mut arr_end = file_contents[arr_start..] - .find(']') - .expect("failed to find `impl_lint_pass` terminator"); - - arr_end += arr_start; - - let mut arr_content = file_contents[arr_start + 1..arr_end].to_string(); - arr_content.retain(|c| !c.is_whitespace()); - - let mut new_arr_content = String::new(); - for ident in arr_content - .split(',') - .chain(std::iter::once(&*lint_name_upper)) - .filter(|s| !s.is_empty()) - { - let _: fmt::Result = write!(new_arr_content, "\n {ident},"); - } - new_arr_content.push('\n'); - - file_contents.replace_range(arr_start + 1..arr_end, &new_arr_content); - - // Just add the mod declaration at the top, it'll be fixed by rustfmt - file_contents.insert_str(0, &format!("mod {};\n", &lint.name)); - - let mut file = OpenOptions::new() - .write(true) - .truncate(true) - .open(path) - .context(format!("trying to open: `{}`", path.display()))?; - file.write_all(file_contents.as_bytes()) - .context(format!("writing to file: `{}`", path.display()))?; - - Ok(lint_context) -} - -#[test] -fn test_camel_case() { - let s = "a_lint"; - let s2 = to_camel_case(s); - assert_eq!(s2, "ALint"); - - let name = "a_really_long_new_lint"; - let name2 = to_camel_case(name); - assert_eq!(name2, "AReallyLongNewLint"); - - let name3 = "lint__name"; - let name4 = to_camel_case(name3); - assert_eq!(name4, "LintName"); -} diff --git a/clippy_dev/src/serve.rs b/clippy_dev/src/serve.rs deleted file mode 100644 index 4a4261d1a1e6..000000000000 --- a/clippy_dev/src/serve.rs +++ /dev/null @@ -1,65 +0,0 @@ -use std::ffi::OsStr; -use std::num::ParseIntError; -use std::path::Path; -use std::process::Command; -use std::time::{Duration, SystemTime}; -use std::{env, thread}; - -/// # Panics -/// -/// Panics if the python commands could not be spawned -pub fn run(port: u16, lint: Option) -> ! { - let mut url = Some(match lint { - None => format!("http://localhost:{port}"), - Some(lint) => format!("http://localhost:{port}/#{lint}"), - }); - - loop { - if mtime("util/gh-pages/lints.json") < mtime("clippy_lints/src") { - Command::new(env::var("CARGO").unwrap_or("cargo".into())) - .arg("collect-metadata") - .spawn() - .unwrap() - .wait() - .unwrap(); - } - if let Some(url) = url.take() { - thread::spawn(move || { - Command::new("python3") - .arg("-m") - .arg("http.server") - .arg(port.to_string()) - .current_dir("util/gh-pages") - .spawn() - .unwrap(); - // Give some time for python to start - thread::sleep(Duration::from_millis(500)); - // Launch browser after first export.py has completed and http.server is up - let _result = opener::open(url); - }); - } - thread::sleep(Duration::from_millis(1000)); - } -} - -fn mtime(path: impl AsRef) -> SystemTime { - let path = path.as_ref(); - if path.is_dir() { - path.read_dir() - .into_iter() - .flatten() - .flatten() - .map(|entry| mtime(entry.path())) - .max() - .unwrap_or(SystemTime::UNIX_EPOCH) - } else { - path.metadata() - .and_then(|metadata| metadata.modified()) - .unwrap_or(SystemTime::UNIX_EPOCH) - } -} - -#[allow(clippy::missing_errors_doc)] -pub fn validate_port(arg: &OsStr) -> Result<(), ParseIntError> { - arg.to_string_lossy().parse::().map(|_| ()) -} diff --git a/clippy_dev/src/setup/git_hook.rs b/clippy_dev/src/setup/git_hook.rs deleted file mode 100644 index c7c53bc69d0b..000000000000 --- a/clippy_dev/src/setup/git_hook.rs +++ /dev/null @@ -1,82 +0,0 @@ -use std::fs; -use std::path::Path; - -use super::verify_inside_clippy_dir; - -/// Rusts setup uses `git rev-parse --git-common-dir` to get the root directory of the repo. -/// I've decided against this for the sake of simplicity and to make sure that it doesn't install -/// the hook if `clippy_dev` would be used in the rust tree. The hook also references this tool -/// for formatting and should therefore only be used in a normal clone of clippy -const REPO_GIT_DIR: &str = ".git"; -const HOOK_SOURCE_FILE: &str = "util/etc/pre-commit.sh"; -const HOOK_TARGET_FILE: &str = ".git/hooks/pre-commit"; - -pub fn install_hook(force_override: bool) { - if !check_precondition(force_override) { - return; - } - - // So a little bit of a funny story. Git on unix requires the pre-commit file - // to have the `execute` permission to be set. The Rust functions for modifying - // these flags doesn't seem to work when executed with normal user permissions. - // - // However, there is a little hack that is also being used by Rust itself in their - // setup script. Git saves the `execute` flag when syncing files. This means - // that we can check in a file with execution permissions and the sync it to create - // a file with the flag set. We then copy this file here. The copy function will also - // include the `execute` permission. - match fs::copy(HOOK_SOURCE_FILE, HOOK_TARGET_FILE) { - Ok(_) => { - println!("info: the hook can be removed with `cargo dev remove git-hook`"); - println!("git hook successfully installed"); - }, - Err(err) => eprintln!("error: unable to copy `{HOOK_SOURCE_FILE}` to `{HOOK_TARGET_FILE}` ({err})"), - } -} - -fn check_precondition(force_override: bool) -> bool { - if !verify_inside_clippy_dir() { - return false; - } - - // Make sure that we can find the git repository - let git_path = Path::new(REPO_GIT_DIR); - if !git_path.exists() || !git_path.is_dir() { - eprintln!("error: clippy_dev was unable to find the `.git` directory"); - return false; - } - - // Make sure that we don't override an existing hook by accident - let path = Path::new(HOOK_TARGET_FILE); - if path.exists() { - if force_override { - return delete_git_hook_file(path); - } - - eprintln!("error: there is already a pre-commit hook installed"); - println!("info: use the `--force-override` flag to override the existing hook"); - return false; - } - - true -} - -pub fn remove_hook() { - let path = Path::new(HOOK_TARGET_FILE); - if path.exists() { - if delete_git_hook_file(path) { - println!("git hook successfully removed"); - } - } else { - println!("no pre-commit hook was found"); - } -} - -fn delete_git_hook_file(path: &Path) -> bool { - if let Err(err) = fs::remove_file(path) { - eprintln!("error: unable to delete existing pre-commit git hook ({err})"); - false - } else { - true - } -} diff --git a/clippy_dev/src/setup/intellij.rs b/clippy_dev/src/setup/intellij.rs deleted file mode 100644 index a7138f36a4ef..000000000000 --- a/clippy_dev/src/setup/intellij.rs +++ /dev/null @@ -1,209 +0,0 @@ -use std::fs; -use std::fs::File; -use std::io::prelude::*; -use std::path::{Path, PathBuf}; - -// This module takes an absolute path to a rustc repo and alters the dependencies to point towards -// the respective rustc subcrates instead of using extern crate xyz. -// This allows IntelliJ to analyze rustc internals and show proper information inside Clippy -// code. See https://github.com/rust-lang/rust-clippy/issues/5514 for details - -const RUSTC_PATH_SECTION: &str = "[target.'cfg(NOT_A_PLATFORM)'.dependencies]"; -const DEPENDENCIES_SECTION: &str = "[dependencies]"; - -const CLIPPY_PROJECTS: &[ClippyProjectInfo] = &[ - ClippyProjectInfo::new("root", "Cargo.toml", "src/driver.rs"), - ClippyProjectInfo::new("clippy_lints", "clippy_lints/Cargo.toml", "clippy_lints/src/lib.rs"), - ClippyProjectInfo::new("clippy_utils", "clippy_utils/Cargo.toml", "clippy_utils/src/lib.rs"), -]; - -/// Used to store clippy project information to later inject the dependency into. -struct ClippyProjectInfo { - /// Only used to display information to the user - name: &'static str, - cargo_file: &'static str, - lib_rs_file: &'static str, -} - -impl ClippyProjectInfo { - const fn new(name: &'static str, cargo_file: &'static str, lib_rs_file: &'static str) -> Self { - Self { - name, - cargo_file, - lib_rs_file, - } - } -} - -pub fn setup_rustc_src(rustc_path: &str) { - let Ok(rustc_source_dir) = check_and_get_rustc_dir(rustc_path) else { - return; - }; - - for project in CLIPPY_PROJECTS { - if inject_deps_into_project(&rustc_source_dir, project).is_err() { - return; - } - } - - println!("info: the source paths can be removed again with `cargo dev remove intellij`"); -} - -fn check_and_get_rustc_dir(rustc_path: &str) -> Result { - let mut path = PathBuf::from(rustc_path); - - if path.is_relative() { - match path.canonicalize() { - Ok(absolute_path) => { - println!("info: the rustc path was resolved to: `{}`", absolute_path.display()); - path = absolute_path; - }, - Err(err) => { - eprintln!("error: unable to get the absolute path of rustc ({err})"); - return Err(()); - }, - }; - } - - let path = path.join("compiler"); - println!("info: looking for compiler sources at: {}", path.display()); - - if !path.exists() { - eprintln!("error: the given path does not exist"); - return Err(()); - } - - if !path.is_dir() { - eprintln!("error: the given path is not a directory"); - return Err(()); - } - - Ok(path) -} - -fn inject_deps_into_project(rustc_source_dir: &Path, project: &ClippyProjectInfo) -> Result<(), ()> { - let cargo_content = read_project_file(project.cargo_file)?; - let lib_content = read_project_file(project.lib_rs_file)?; - - if inject_deps_into_manifest(rustc_source_dir, project.cargo_file, &cargo_content, &lib_content).is_err() { - eprintln!( - "error: unable to inject dependencies into {} with the Cargo file {}", - project.name, project.cargo_file - ); - Err(()) - } else { - Ok(()) - } -} - -/// `clippy_dev` expects to be executed in the root directory of Clippy. This function -/// loads the given file or returns an error. Having it in this extra function ensures -/// that the error message looks nice. -fn read_project_file(file_path: &str) -> Result { - let path = Path::new(file_path); - if !path.exists() { - eprintln!("error: unable to find the file `{file_path}`"); - return Err(()); - } - - match fs::read_to_string(path) { - Ok(content) => Ok(content), - Err(err) => { - eprintln!("error: the file `{file_path}` could not be read ({err})"); - Err(()) - }, - } -} - -fn inject_deps_into_manifest( - rustc_source_dir: &Path, - manifest_path: &str, - cargo_toml: &str, - lib_rs: &str, -) -> std::io::Result<()> { - // do not inject deps if we have already done so - if cargo_toml.contains(RUSTC_PATH_SECTION) { - eprintln!("warn: dependencies are already setup inside {manifest_path}, skipping file"); - return Ok(()); - } - - let extern_crates = lib_rs - .lines() - // only take dependencies starting with `rustc_` - .filter(|line| line.starts_with("extern crate rustc_")) - // we have something like "extern crate foo;", we only care about the "foo" - // extern crate rustc_middle; - // ^^^^^^^^^^^^ - .map(|s| &s[13..(s.len() - 1)]); - - let new_deps = extern_crates.map(|dep| { - // format the dependencies that are going to be put inside the Cargo.toml - format!("{dep} = {{ path = \"{}/{dep}\" }}\n", rustc_source_dir.display()) - }); - - // format a new [dependencies]-block with the new deps we need to inject - let mut all_deps = String::from("[target.'cfg(NOT_A_PLATFORM)'.dependencies]\n"); - new_deps.for_each(|dep_line| { - all_deps.push_str(&dep_line); - }); - all_deps.push_str("\n[dependencies]\n"); - - // replace "[dependencies]" with - // [dependencies] - // dep1 = { path = ... } - // dep2 = { path = ... } - // etc - let new_manifest = cargo_toml.replacen("[dependencies]\n", &all_deps, 1); - - // println!("{new_manifest}"); - let mut file = File::create(manifest_path)?; - file.write_all(new_manifest.as_bytes())?; - - println!("info: successfully setup dependencies inside {manifest_path}"); - - Ok(()) -} - -pub fn remove_rustc_src() { - for project in CLIPPY_PROJECTS { - remove_rustc_src_from_project(project); - } -} - -fn remove_rustc_src_from_project(project: &ClippyProjectInfo) -> bool { - let Ok(mut cargo_content) = read_project_file(project.cargo_file) else { - return false; - }; - let Some(section_start) = cargo_content.find(RUSTC_PATH_SECTION) else { - println!( - "info: dependencies could not be found in `{}` for {}, skipping file", - project.cargo_file, project.name - ); - return true; - }; - - let Some(end_point) = cargo_content.find(DEPENDENCIES_SECTION) else { - eprintln!( - "error: the end of the rustc dependencies section could not be found in `{}`", - project.cargo_file - ); - return false; - }; - - cargo_content.replace_range(section_start..end_point, ""); - - match File::create(project.cargo_file) { - Ok(mut file) => { - file.write_all(cargo_content.as_bytes()).unwrap(); - println!("info: successfully removed dependencies inside {}", project.cargo_file); - true - }, - Err(err) => { - eprintln!( - "error: unable to open file `{}` to remove rustc dependencies for {} ({err})", - project.cargo_file, project.name - ); - false - }, - } -} diff --git a/clippy_dev/src/setup/mod.rs b/clippy_dev/src/setup/mod.rs deleted file mode 100644 index b0d318146391..000000000000 --- a/clippy_dev/src/setup/mod.rs +++ /dev/null @@ -1,24 +0,0 @@ -pub mod git_hook; -pub mod intellij; -pub mod toolchain; -pub mod vscode; - -use std::path::Path; - -const CLIPPY_DEV_DIR: &str = "clippy_dev"; - -/// This function verifies that the tool is being executed in the clippy directory. -/// This is useful to ensure that setups only modify Clippy's resources. The verification -/// is done by checking that `clippy_dev` is a sub directory of the current directory. -/// -/// It will print an error message and return `false` if the directory could not be -/// verified. -fn verify_inside_clippy_dir() -> bool { - let path = Path::new(CLIPPY_DEV_DIR); - if path.exists() && path.is_dir() { - true - } else { - eprintln!("error: unable to verify that the working directory is clippy's directory"); - false - } -} diff --git a/clippy_dev/src/setup/toolchain.rs b/clippy_dev/src/setup/toolchain.rs deleted file mode 100644 index 8d98c6c92d9d..000000000000 --- a/clippy_dev/src/setup/toolchain.rs +++ /dev/null @@ -1,75 +0,0 @@ -use std::env::consts::EXE_SUFFIX; -use std::env::current_dir; -use std::ffi::OsStr; -use std::fs; -use std::path::{Path, PathBuf}; -use walkdir::WalkDir; - -use super::verify_inside_clippy_dir; - -pub fn create(force: bool, release: bool, name: &str) { - if !verify_inside_clippy_dir() { - return; - } - - let rustup_home = std::env::var("RUSTUP_HOME").unwrap(); - let toolchain = std::env::var("RUSTUP_TOOLCHAIN").unwrap(); - - let src = PathBuf::from_iter([&rustup_home, "toolchains", &toolchain]); - let dest = PathBuf::from_iter([&rustup_home, "toolchains", name]); - - if dest.exists() { - if force { - fs::remove_dir_all(&dest).unwrap(); - } else { - println!("{} already exists, pass `--force` to override it", dest.display()); - return; - } - } - - for entry in WalkDir::new(&src) { - let entry = entry.unwrap(); - let relative = entry.path().strip_prefix(&src).unwrap(); - - if relative.starts_with("bin") - && matches!( - relative.file_stem().and_then(OsStr::to_str), - Some("cargo-clippy" | "clippy-driver") - ) - { - continue; - } - - let target = dest.join(relative); - if entry.file_type().is_dir() { - fs::create_dir(&target).unwrap(); - } else { - fs::hard_link(entry.path(), target).unwrap(); - } - } - - symlink_bin("cargo-clippy", &dest, release); - symlink_bin("clippy-driver", &dest, release); - - println!("Created toolchain {name}, use it in other projects with e.g. `cargo +{name} clippy`"); - println!("Note: This will need to be re-run whenever the Clippy `rust-toolchain` changes"); -} - -fn symlink_bin(bin: &str, dest: &Path, release: bool) { - #[cfg(windows)] - use std::os::windows::fs::symlink_file as symlink; - - #[cfg(not(windows))] - use std::os::unix::fs::symlink; - - let profile = if release { "release" } else { "debug" }; - let file_name = format!("{bin}{EXE_SUFFIX}"); - - let mut src = current_dir().unwrap(); - src.extend(["target", profile, &file_name]); - - let mut dest = dest.to_path_buf(); - dest.extend(["bin", &file_name]); - - symlink(src, dest).unwrap(); -} diff --git a/clippy_dev/src/setup/vscode.rs b/clippy_dev/src/setup/vscode.rs deleted file mode 100644 index 204f4af2cf1b..000000000000 --- a/clippy_dev/src/setup/vscode.rs +++ /dev/null @@ -1,95 +0,0 @@ -use std::fs; -use std::path::Path; - -use super::verify_inside_clippy_dir; - -const VSCODE_DIR: &str = ".vscode"; -const TASK_SOURCE_FILE: &str = "util/etc/vscode-tasks.json"; -const TASK_TARGET_FILE: &str = ".vscode/tasks.json"; - -pub fn install_tasks(force_override: bool) { - if !check_install_precondition(force_override) { - return; - } - - match fs::copy(TASK_SOURCE_FILE, TASK_TARGET_FILE) { - Ok(_) => { - println!("info: the task file can be removed with `cargo dev remove vscode-tasks`"); - println!("vscode tasks successfully installed"); - }, - Err(err) => eprintln!("error: unable to copy `{TASK_SOURCE_FILE}` to `{TASK_TARGET_FILE}` ({err})"), - } -} - -fn check_install_precondition(force_override: bool) -> bool { - if !verify_inside_clippy_dir() { - return false; - } - - let vs_dir_path = Path::new(VSCODE_DIR); - if vs_dir_path.exists() { - // verify the target will be valid - if !vs_dir_path.is_dir() { - eprintln!("error: the `.vscode` path exists but seems to be a file"); - return false; - } - - // make sure that we don't override any existing tasks by accident - let path = Path::new(TASK_TARGET_FILE); - if path.exists() { - if force_override { - return delete_vs_task_file(path); - } - - eprintln!("error: there is already a `task.json` file inside the `{VSCODE_DIR}` directory"); - println!("info: use the `--force-override` flag to override the existing `task.json` file"); - return false; - } - } else { - match fs::create_dir(vs_dir_path) { - Ok(()) => { - println!("info: created `{VSCODE_DIR}` directory for clippy"); - }, - Err(err) => { - eprintln!("error: the task target directory `{VSCODE_DIR}` could not be created ({err})"); - }, - } - } - - true -} - -pub fn remove_tasks() { - let path = Path::new(TASK_TARGET_FILE); - if path.exists() { - if delete_vs_task_file(path) { - try_delete_vs_directory_if_empty(); - println!("vscode tasks successfully removed"); - } - } else { - println!("no vscode tasks were found"); - } -} - -fn delete_vs_task_file(path: &Path) -> bool { - if let Err(err) = fs::remove_file(path) { - eprintln!("error: unable to delete the existing `tasks.json` file ({err})"); - return false; - } - - true -} - -/// This function will try to delete the `.vscode` directory if it's empty. -/// It may fail silently. -fn try_delete_vs_directory_if_empty() { - let path = Path::new(VSCODE_DIR); - if path.read_dir().map_or(false, |mut iter| iter.next().is_none()) { - // The directory is empty. We just try to delete it but allow a silence - // fail as an empty `.vscode` directory is still valid - let _silence_result = fs::remove_dir(path); - } else { - // The directory is not empty or could not be read. Either way don't take - // any further actions - } -} diff --git a/clippy_dev/src/update_lints.rs b/clippy_dev/src/update_lints.rs deleted file mode 100644 index 45353901c98f..000000000000 --- a/clippy_dev/src/update_lints.rs +++ /dev/null @@ -1,1210 +0,0 @@ -use crate::clippy_project_root; -use aho_corasick::AhoCorasickBuilder; -use indoc::writedoc; -use itertools::Itertools; -use rustc_lexer::{tokenize, unescape, LiteralKind, TokenKind}; -use std::collections::{HashMap, HashSet}; -use std::ffi::OsStr; -use std::fmt::{self, Write}; -use std::fs::{self, OpenOptions}; -use std::io::{self, Read, Seek, SeekFrom, Write as _}; -use std::ops::Range; -use std::path::{Path, PathBuf}; -use walkdir::{DirEntry, WalkDir}; - -const GENERATED_FILE_COMMENT: &str = "// This file was generated by `cargo dev update_lints`.\n\ - // Use that command to update this file and do not edit by hand.\n\ - // Manual edits will be overwritten.\n\n"; - -const DOCS_LINK: &str = "https://rust-lang.github.io/rust-clippy/master/index.html"; - -#[derive(Clone, Copy, PartialEq, Eq)] -pub enum UpdateMode { - Check, - Change, -} - -/// Runs the `update_lints` command. -/// -/// This updates various generated values from the lint source code. -/// -/// `update_mode` indicates if the files should be updated or if updates should be checked for. -/// -/// # Panics -/// -/// Panics if a file path could not read from or then written to -pub fn update(update_mode: UpdateMode) { - let (lints, deprecated_lints, renamed_lints) = gather_all(); - generate_lint_files(update_mode, &lints, &deprecated_lints, &renamed_lints); -} - -fn generate_lint_files( - update_mode: UpdateMode, - lints: &[Lint], - deprecated_lints: &[DeprecatedLint], - renamed_lints: &[RenamedLint], -) { - let internal_lints = Lint::internal_lints(lints); - let mut usable_lints = Lint::usable_lints(lints); - usable_lints.sort_by_key(|lint| lint.name.clone()); - - replace_region_in_file( - update_mode, - Path::new("README.md"), - "[There are over ", - " lints included in this crate!]", - |res| { - write!(res, "{}", round_to_fifty(usable_lints.len())).unwrap(); - }, - ); - - replace_region_in_file( - update_mode, - Path::new("book/src/README.md"), - "[There are over ", - " lints included in this crate!]", - |res| { - write!(res, "{}", round_to_fifty(usable_lints.len())).unwrap(); - }, - ); - - replace_region_in_file( - update_mode, - Path::new("CHANGELOG.md"), - "\n", - "", - |res| { - for lint in usable_lints - .iter() - .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(); - } - }, - ); - - // This has to be in lib.rs, otherwise rustfmt doesn't work - replace_region_in_file( - update_mode, - Path::new("clippy_lints/src/lib.rs"), - "// begin lints modules, do not remove this comment, it’s used in `update_lints`\n", - "// end lints modules, do not remove this comment, it’s used in `update_lints`", - |res| { - for lint_mod in usable_lints.iter().map(|l| &l.module).unique().sorted() { - writeln!(res, "mod {lint_mod};").unwrap(); - } - }, - ); - - process_file( - "clippy_lints/src/declared_lints.rs", - update_mode, - &gen_declared_lints(internal_lints.iter(), usable_lints.iter()), - ); - process_file( - "clippy_lints/src/lib.deprecated.rs", - update_mode, - &gen_deprecated(deprecated_lints), - ); - - let content = gen_deprecated_lints_test(deprecated_lints); - process_file("tests/ui/deprecated.rs", update_mode, &content); - - let content = gen_renamed_lints_test(renamed_lints); - process_file("tests/ui/rename.rs", update_mode, &content); -} - -pub fn print_lints() { - let (lint_list, _, _) = gather_all(); - let usable_lints = Lint::usable_lints(&lint_list); - let usable_lint_count = usable_lints.len(); - let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter()); - - for (lint_group, mut lints) in grouped_by_lint_group { - println!("\n## {lint_group}"); - - lints.sort_by_key(|l| l.name.clone()); - - for lint in lints { - println!("* [{}]({DOCS_LINK}#{}) ({})", lint.name, lint.name, lint.desc); - } - } - - println!("there are {usable_lint_count} lints"); -} - -/// Runs the `rename_lint` command. -/// -/// This does the following: -/// * Adds an entry to `renamed_lints.rs`. -/// * Renames all lint attributes to the new name (e.g. `#[allow(clippy::lint_name)]`). -/// * Renames the lint struct to the new name. -/// * Renames the module containing the lint struct to the new name if it shares a name with the -/// lint. -/// -/// # Panics -/// Panics for the following conditions: -/// * If a file path could not read from or then written to -/// * If either lint name has a prefix -/// * If `old_name` doesn't name an existing lint. -/// * If `old_name` names a deprecated or renamed lint. -#[allow(clippy::too_many_lines)] -pub fn rename(old_name: &str, new_name: &str, uplift: bool) { - if let Some((prefix, _)) = old_name.split_once("::") { - panic!("`{old_name}` should not contain the `{prefix}` prefix"); - } - if let Some((prefix, _)) = new_name.split_once("::") { - panic!("`{new_name}` should not contain the `{prefix}` prefix"); - } - - let (mut lints, deprecated_lints, mut renamed_lints) = gather_all(); - let mut old_lint_index = None; - let mut found_new_name = false; - for (i, lint) in lints.iter().enumerate() { - if lint.name == old_name { - old_lint_index = Some(i); - } else if lint.name == new_name { - found_new_name = true; - } - } - let old_lint_index = old_lint_index.unwrap_or_else(|| panic!("could not find lint `{old_name}`")); - - let lint = RenamedLint { - old_name: format!("clippy::{old_name}"), - new_name: if uplift { - new_name.into() - } else { - format!("clippy::{new_name}") - }, - }; - - // Renamed lints and deprecated lints shouldn't have been found in the lint list, but check just in - // case. - assert!( - !renamed_lints.iter().any(|l| lint.old_name == l.old_name), - "`{old_name}` has already been renamed" - ); - assert!( - !deprecated_lints.iter().any(|l| lint.old_name == l.name), - "`{old_name}` has already been deprecated" - ); - - // Update all lint level attributes. (`clippy::lint_name`) - for file in WalkDir::new(clippy_project_root()) - .into_iter() - .map(Result::unwrap) - .filter(|f| { - let name = f.path().file_name(); - let ext = f.path().extension(); - (ext == Some(OsStr::new("rs")) || ext == Some(OsStr::new("fixed"))) - && name != Some(OsStr::new("rename.rs")) - && name != Some(OsStr::new("renamed_lints.rs")) - }) - { - rewrite_file(file.path(), |s| { - replace_ident_like(s, &[(&lint.old_name, &lint.new_name)]) - }); - } - - renamed_lints.push(lint); - renamed_lints.sort_by(|lhs, rhs| { - lhs.new_name - .starts_with("clippy::") - .cmp(&rhs.new_name.starts_with("clippy::")) - .reverse() - .then_with(|| lhs.old_name.cmp(&rhs.old_name)) - }); - - write_file( - Path::new("clippy_lints/src/renamed_lints.rs"), - &gen_renamed_lints_list(&renamed_lints), - ); - - if uplift { - write_file(Path::new("tests/ui/rename.rs"), &gen_renamed_lints_test(&renamed_lints)); - println!( - "`{old_name}` has be uplifted. All the code inside `clippy_lints` related to it needs to be removed manually." - ); - } else if found_new_name { - write_file(Path::new("tests/ui/rename.rs"), &gen_renamed_lints_test(&renamed_lints)); - println!( - "`{new_name}` is already defined. The old linting code inside `clippy_lints` needs to be updated/removed manually." - ); - } else { - // Rename the lint struct and source files sharing a name with the lint. - let lint = &mut lints[old_lint_index]; - let old_name_upper = old_name.to_uppercase(); - let new_name_upper = new_name.to_uppercase(); - lint.name = new_name.into(); - - // Rename test files. only rename `.stderr` and `.fixed` files if the new test name doesn't exist. - if try_rename_file( - Path::new(&format!("tests/ui/{old_name}.rs")), - Path::new(&format!("tests/ui/{new_name}.rs")), - ) { - try_rename_file( - Path::new(&format!("tests/ui/{old_name}.stderr")), - Path::new(&format!("tests/ui/{new_name}.stderr")), - ); - try_rename_file( - Path::new(&format!("tests/ui/{old_name}.fixed")), - Path::new(&format!("tests/ui/{new_name}.fixed")), - ); - } - - // Try to rename the file containing the lint if the file name matches the lint's name. - let replacements; - let replacements = if lint.module == old_name - && try_rename_file( - Path::new(&format!("clippy_lints/src/{old_name}.rs")), - Path::new(&format!("clippy_lints/src/{new_name}.rs")), - ) { - // Edit the module name in the lint list. Note there could be multiple lints. - for lint in lints.iter_mut().filter(|l| l.module == old_name) { - lint.module = new_name.into(); - } - replacements = [(&*old_name_upper, &*new_name_upper), (old_name, new_name)]; - replacements.as_slice() - } else if !lint.module.contains("::") - // Catch cases like `methods/lint_name.rs` where the lint is stored in `methods/mod.rs` - && try_rename_file( - Path::new(&format!("clippy_lints/src/{}/{old_name}.rs", lint.module)), - Path::new(&format!("clippy_lints/src/{}/{new_name}.rs", lint.module)), - ) - { - // Edit the module name in the lint list. Note there could be multiple lints, or none. - let renamed_mod = format!("{}::{old_name}", lint.module); - for lint in lints.iter_mut().filter(|l| l.module == renamed_mod) { - lint.module = format!("{}::{new_name}", lint.module); - } - replacements = [(&*old_name_upper, &*new_name_upper), (old_name, new_name)]; - replacements.as_slice() - } else { - replacements = [(&*old_name_upper, &*new_name_upper), ("", "")]; - &replacements[0..1] - }; - - // Don't change `clippy_utils/src/renamed_lints.rs` here as it would try to edit the lint being - // renamed. - for (_, file) in clippy_lints_src_files().filter(|(rel_path, _)| rel_path != OsStr::new("renamed_lints.rs")) { - rewrite_file(file.path(), |s| replace_ident_like(s, replacements)); - } - - generate_lint_files(UpdateMode::Change, &lints, &deprecated_lints, &renamed_lints); - println!("{old_name} has been successfully renamed"); - } - - println!("note: `cargo uitest` still needs to be run to update the test results"); -} - -const DEFAULT_DEPRECATION_REASON: &str = "default deprecation note"; -/// Runs the `deprecate` command -/// -/// This does the following: -/// * Adds an entry to `deprecated_lints.rs`. -/// * Removes the lint declaration (and the entire file if applicable) -/// -/// # Panics -/// -/// If a file path could not read from or written to -pub fn deprecate(name: &str, reason: Option<&str>) { - fn finish( - (lints, mut deprecated_lints, renamed_lints): (Vec, Vec, Vec), - name: &str, - reason: &str, - ) { - deprecated_lints.push(DeprecatedLint { - name: name.to_string(), - reason: reason.to_string(), - declaration_range: Range::default(), - }); - - generate_lint_files(UpdateMode::Change, &lints, &deprecated_lints, &renamed_lints); - println!("info: `{name}` has successfully been deprecated"); - - if reason == DEFAULT_DEPRECATION_REASON { - println!("note: the deprecation reason must be updated in `clippy_lints/src/deprecated_lints.rs`"); - } - println!("note: you must run `cargo uitest` to update the test results"); - } - - let reason = reason.unwrap_or(DEFAULT_DEPRECATION_REASON); - let name_lower = name.to_lowercase(); - let name_upper = name.to_uppercase(); - - let (mut lints, deprecated_lints, renamed_lints) = gather_all(); - let Some(lint) = lints.iter().find(|l| l.name == name_lower) else { - eprintln!("error: failed to find lint `{name}`"); - return; - }; - - let mod_path = { - let mut mod_path = PathBuf::from(format!("clippy_lints/src/{}", lint.module)); - if mod_path.is_dir() { - mod_path = mod_path.join("mod"); - } - - mod_path.set_extension("rs"); - mod_path - }; - - let deprecated_lints_path = &*clippy_project_root().join("clippy_lints/src/deprecated_lints.rs"); - - if remove_lint_declaration(&name_lower, &mod_path, &mut lints).unwrap_or(false) { - declare_deprecated(&name_upper, deprecated_lints_path, reason).unwrap(); - finish((lints, deprecated_lints, renamed_lints), name, reason); - return; - } - - eprintln!("error: lint not found"); -} - -fn remove_lint_declaration(name: &str, path: &Path, lints: &mut Vec) -> io::Result { - fn remove_lint(name: &str, lints: &mut Vec) { - lints.iter().position(|l| l.name == name).map(|pos| lints.remove(pos)); - } - - fn remove_test_assets(name: &str) { - let test_file_stem = format!("tests/ui/{name}"); - let path = Path::new(&test_file_stem); - - // Some lints have their own directories, delete them - if path.is_dir() { - fs::remove_dir_all(path).ok(); - return; - } - - // Remove all related test files - fs::remove_file(path.with_extension("rs")).ok(); - fs::remove_file(path.with_extension("stderr")).ok(); - fs::remove_file(path.with_extension("fixed")).ok(); - } - - fn remove_impl_lint_pass(lint_name_upper: &str, content: &mut String) { - let impl_lint_pass_start = content.find("impl_lint_pass!").unwrap_or_else(|| { - content - .find("declare_lint_pass!") - .unwrap_or_else(|| panic!("failed to find `impl_lint_pass`")) - }); - let mut impl_lint_pass_end = content[impl_lint_pass_start..] - .find(']') - .expect("failed to find `impl_lint_pass` terminator"); - - impl_lint_pass_end += impl_lint_pass_start; - if let Some(lint_name_pos) = content[impl_lint_pass_start..impl_lint_pass_end].find(lint_name_upper) { - let mut lint_name_end = impl_lint_pass_start + (lint_name_pos + lint_name_upper.len()); - for c in content[lint_name_end..impl_lint_pass_end].chars() { - // Remove trailing whitespace - if c == ',' || c.is_whitespace() { - lint_name_end += 1; - } else { - break; - } - } - - content.replace_range(impl_lint_pass_start + lint_name_pos..lint_name_end, ""); - } - } - - if path.exists() { - if let Some(lint) = lints.iter().find(|l| l.name == name) { - if lint.module == name { - // The lint name is the same as the file, we can just delete the entire file - fs::remove_file(path)?; - } else { - // We can't delete the entire file, just remove the declaration - - if let Some(Some("mod.rs")) = path.file_name().map(OsStr::to_str) { - // Remove clippy_lints/src/some_mod/some_lint.rs - let mut lint_mod_path = path.to_path_buf(); - lint_mod_path.set_file_name(name); - lint_mod_path.set_extension("rs"); - - fs::remove_file(lint_mod_path).ok(); - } - - let mut content = - fs::read_to_string(path).unwrap_or_else(|_| panic!("failed to read `{}`", path.to_string_lossy())); - - eprintln!( - "warn: you will have to manually remove any code related to `{name}` from `{}`", - path.display() - ); - - assert!( - content[lint.declaration_range.clone()].contains(&name.to_uppercase()), - "error: `{}` does not contain lint `{}`'s declaration", - path.display(), - lint.name - ); - - // Remove lint declaration (declare_clippy_lint!) - content.replace_range(lint.declaration_range.clone(), ""); - - // Remove the module declaration (mod xyz;) - let mod_decl = format!("\nmod {name};"); - content = content.replacen(&mod_decl, "", 1); - - remove_impl_lint_pass(&lint.name.to_uppercase(), &mut content); - fs::write(path, content).unwrap_or_else(|_| panic!("failed to write to `{}`", path.to_string_lossy())); - } - - remove_test_assets(name); - remove_lint(name, lints); - return Ok(true); - } - } - - Ok(false) -} - -fn declare_deprecated(name: &str, path: &Path, reason: &str) -> io::Result<()> { - let mut file = OpenOptions::new().write(true).open(path)?; - - file.seek(SeekFrom::End(0))?; - - let version = crate::new_lint::get_stabilization_version(); - let deprecation_reason = if reason == DEFAULT_DEPRECATION_REASON { - "TODO" - } else { - reason - }; - - writedoc!( - file, - " - - declare_deprecated_lint! {{ - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// {deprecation_reason} - #[clippy::version = \"{version}\"] - pub {name}, - \"{reason}\" - }} - - " - ) -} - -/// Replace substrings if they aren't bordered by identifier characters. Returns `None` if there -/// were no replacements. -fn replace_ident_like(contents: &str, replacements: &[(&str, &str)]) -> Option { - fn is_ident_char(c: u8) -> bool { - matches!(c, b'a'..=b'z' | b'A'..=b'Z' | b'0'..=b'9' | b'_') - } - - let searcher = AhoCorasickBuilder::new() - .match_kind(aho_corasick::MatchKind::LeftmostLongest) - .build(replacements.iter().map(|&(x, _)| x.as_bytes())) - .unwrap(); - - let mut result = String::with_capacity(contents.len() + 1024); - let mut pos = 0; - let mut edited = false; - for m in searcher.find_iter(contents) { - let (old, new) = replacements[m.pattern()]; - result.push_str(&contents[pos..m.start()]); - result.push_str( - if !is_ident_char(contents.as_bytes().get(m.start().wrapping_sub(1)).copied().unwrap_or(0)) - && !is_ident_char(contents.as_bytes().get(m.end()).copied().unwrap_or(0)) - { - edited = true; - new - } else { - old - }, - ); - pos = m.end(); - } - result.push_str(&contents[pos..]); - edited.then_some(result) -} - -fn round_to_fifty(count: usize) -> usize { - count / 50 * 50 -} - -fn process_file(path: impl AsRef, update_mode: UpdateMode, content: &str) { - if update_mode == UpdateMode::Check { - let old_content = - fs::read_to_string(&path).unwrap_or_else(|e| panic!("Cannot read from {}: {e}", path.as_ref().display())); - if content != old_content { - exit_with_failure(); - } - } else { - fs::write(&path, content.as_bytes()) - .unwrap_or_else(|e| panic!("Cannot write to {}: {e}", path.as_ref().display())); - } -} - -fn exit_with_failure() { - println!( - "Not all lints defined properly. \ - Please run `cargo dev update_lints` to make sure all lints are defined properly." - ); - std::process::exit(1); -} - -/// Lint data parsed from the Clippy source code. -#[derive(Clone, PartialEq, Eq, Debug)] -struct Lint { - name: String, - group: String, - desc: String, - module: String, - declaration_range: Range, -} - -impl Lint { - #[must_use] - fn new(name: &str, group: &str, desc: &str, module: &str, declaration_range: Range) -> Self { - Self { - name: name.to_lowercase(), - group: group.into(), - desc: remove_line_splices(desc), - module: module.into(), - declaration_range, - } - } - - /// Returns all non-deprecated lints and non-internal lints - #[must_use] - fn usable_lints(lints: &[Self]) -> Vec { - lints - .iter() - .filter(|l| !l.group.starts_with("internal")) - .cloned() - .collect() - } - - /// Returns all internal lints - #[must_use] - fn internal_lints(lints: &[Self]) -> Vec { - lints.iter().filter(|l| l.group == "internal").cloned().collect() - } - - /// Returns the lints in a `HashMap`, grouped by the different lint groups - #[must_use] - fn by_lint_group(lints: impl Iterator) -> HashMap> { - lints.map(|lint| (lint.group.to_string(), lint)).into_group_map() - } -} - -#[derive(Clone, PartialEq, Eq, Debug)] -struct DeprecatedLint { - name: String, - reason: String, - declaration_range: Range, -} -impl DeprecatedLint { - fn new(name: &str, reason: &str, declaration_range: Range) -> Self { - Self { - name: name.to_lowercase(), - reason: remove_line_splices(reason), - declaration_range, - } - } -} - -struct RenamedLint { - old_name: String, - new_name: String, -} -impl RenamedLint { - fn new(old_name: &str, new_name: &str) -> Self { - Self { - old_name: remove_line_splices(old_name), - new_name: remove_line_splices(new_name), - } - } -} - -/// Generates the `register_removed` code -#[must_use] -fn gen_deprecated(lints: &[DeprecatedLint]) -> String { - let mut output = GENERATED_FILE_COMMENT.to_string(); - output.push_str("{\n"); - for lint in lints { - let _: fmt::Result = write!( - output, - concat!( - " store.register_removed(\n", - " \"clippy::{}\",\n", - " \"{}\",\n", - " );\n" - ), - lint.name, lint.reason, - ); - } - output.push_str("}\n"); - - output -} - -/// Generates the code for registering lints -#[must_use] -fn gen_declared_lints<'a>( - internal_lints: impl Iterator, - usable_lints: impl Iterator, -) -> String { - let mut details: Vec<_> = internal_lints - .map(|l| (false, &l.module, l.name.to_uppercase())) - .chain(usable_lints.map(|l| (true, &l.module, l.name.to_uppercase()))) - .collect(); - details.sort_unstable(); - - let mut output = GENERATED_FILE_COMMENT.to_string(); - output.push_str("pub(crate) static LINTS: &[&crate::LintInfo] = &[\n"); - - for (is_public, module_name, lint_name) in details { - if !is_public { - output.push_str(" #[cfg(feature = \"internal\")]\n"); - } - let _: fmt::Result = writeln!(output, " crate::{module_name}::{lint_name}_INFO,"); - } - output.push_str("];\n"); - - output -} - -fn gen_deprecated_lints_test(lints: &[DeprecatedLint]) -> String { - let mut res: String = GENERATED_FILE_COMMENT.into(); - for lint in lints { - writeln!(res, "#![warn(clippy::{})]", lint.name).unwrap(); - } - res.push_str("\nfn main() {}\n"); - res -} - -fn gen_renamed_lints_test(lints: &[RenamedLint]) -> String { - let mut seen_lints = HashSet::new(); - let mut res: String = GENERATED_FILE_COMMENT.into(); - - res.push_str("#![allow(clippy::duplicated_attributes)]\n"); - for lint in lints { - if seen_lints.insert(&lint.new_name) { - writeln!(res, "#![allow({})]", lint.new_name).unwrap(); - } - } - seen_lints.clear(); - for lint in lints { - if seen_lints.insert(&lint.old_name) { - writeln!(res, "#![warn({})]", lint.old_name).unwrap(); - } - } - res.push_str("\nfn main() {}\n"); - res -} - -fn gen_renamed_lints_list(lints: &[RenamedLint]) -> String { - const HEADER: &str = "\ - // This file is managed by `cargo dev rename_lint`. Prefer using that when possible.\n\n\ - #[rustfmt::skip]\n\ - pub static RENAMED_LINTS: &[(&str, &str)] = &[\n"; - - let mut res = String::from(HEADER); - for lint in lints { - writeln!(res, " (\"{}\", \"{}\"),", lint.old_name, lint.new_name).unwrap(); - } - res.push_str("];\n"); - res -} - -/// Gathers all lints defined in `clippy_lints/src` -fn gather_all() -> (Vec, Vec, Vec) { - let mut lints = Vec::with_capacity(1000); - let mut deprecated_lints = Vec::with_capacity(50); - let mut renamed_lints = Vec::with_capacity(50); - - for (rel_path, file) in clippy_lints_src_files() { - let path = file.path(); - let contents = - fs::read_to_string(path).unwrap_or_else(|e| panic!("Cannot read from `{}`: {e}", path.display())); - let module = rel_path - .components() - .map(|c| c.as_os_str().to_str().unwrap()) - .collect::>() - .join("::"); - - // If the lints are stored in mod.rs, we get the module name from - // the containing directory: - let module = if let Some(module) = module.strip_suffix("::mod.rs") { - module - } else { - module.strip_suffix(".rs").unwrap_or(&module) - }; - - match module { - "deprecated_lints" => parse_deprecated_contents(&contents, &mut deprecated_lints), - "renamed_lints" => parse_renamed_contents(&contents, &mut renamed_lints), - _ => parse_contents(&contents, module, &mut lints), - } - } - (lints, deprecated_lints, renamed_lints) -} - -fn clippy_lints_src_files() -> impl Iterator { - let root_path = clippy_project_root().join("clippy_lints/src"); - let iter = WalkDir::new(&root_path).into_iter(); - iter.map(Result::unwrap) - .filter(|f| f.path().extension() == Some(OsStr::new("rs"))) - .map(move |f| (f.path().strip_prefix(&root_path).unwrap().to_path_buf(), f)) -} - -macro_rules! match_tokens { - ($iter:ident, $($token:ident $({$($fields:tt)*})? $(($capture:ident))?)*) => { - { - $(#[allow(clippy::redundant_pattern)] let Some(LintDeclSearchResult { - token_kind: TokenKind::$token $({$($fields)*})?, - content: $($capture @)? _, - .. - }) = $iter.next() else { - continue; - };)* - #[allow(clippy::unused_unit)] - { ($($($capture,)?)*) } - } - } -} - -pub(crate) use match_tokens; - -pub(crate) struct LintDeclSearchResult<'a> { - pub token_kind: TokenKind, - pub content: &'a str, - pub range: Range, -} - -/// Parse a source file looking for `declare_clippy_lint` macro invocations. -fn parse_contents(contents: &str, module: &str, lints: &mut Vec) { - let mut offset = 0usize; - let mut iter = tokenize(contents).map(|t| { - let range = offset..offset + t.len as usize; - offset = range.end; - - LintDeclSearchResult { - token_kind: t.kind, - content: &contents[range.clone()], - range, - } - }); - - while let Some(LintDeclSearchResult { range, .. }) = iter.find( - |LintDeclSearchResult { - token_kind, content, .. - }| token_kind == &TokenKind::Ident && *content == "declare_clippy_lint", - ) { - let start = range.start; - let mut iter = iter - .by_ref() - .filter(|t| !matches!(t.token_kind, TokenKind::Whitespace | TokenKind::LineComment { .. })); - // matches `!{` - match_tokens!(iter, Bang OpenBrace); - match iter.next() { - // #[clippy::version = "version"] pub - Some(LintDeclSearchResult { - token_kind: TokenKind::Pound, - .. - }) => { - match_tokens!(iter, OpenBracket Ident Colon Colon Ident Eq Literal{..} CloseBracket Ident); - }, - // pub - Some(LintDeclSearchResult { - token_kind: TokenKind::Ident, - .. - }) => (), - _ => continue, - } - - let (name, group, desc) = match_tokens!( - iter, - // LINT_NAME - Ident(name) Comma - // group, - Ident(group) Comma - // "description" - Literal{..}(desc) - ); - - if let Some(LintDeclSearchResult { - token_kind: TokenKind::CloseBrace, - range, - .. - }) = iter.next() - { - lints.push(Lint::new(name, group, desc, module, start..range.end)); - } - } -} - -/// Parse a source file looking for `declare_deprecated_lint` macro invocations. -fn parse_deprecated_contents(contents: &str, lints: &mut Vec) { - let mut offset = 0usize; - let mut iter = tokenize(contents).map(|t| { - let range = offset..offset + t.len as usize; - offset = range.end; - - LintDeclSearchResult { - token_kind: t.kind, - content: &contents[range.clone()], - range, - } - }); - - while let Some(LintDeclSearchResult { range, .. }) = iter.find( - |LintDeclSearchResult { - token_kind, content, .. - }| token_kind == &TokenKind::Ident && *content == "declare_deprecated_lint", - ) { - let start = range.start; - - let mut iter = iter.by_ref().filter(|LintDeclSearchResult { ref token_kind, .. }| { - !matches!(token_kind, TokenKind::Whitespace | TokenKind::LineComment { .. }) - }); - let (name, reason) = match_tokens!( - iter, - // !{ - Bang OpenBrace - // #[clippy::version = "version"] - Pound OpenBracket Ident Colon Colon Ident Eq Literal{..} CloseBracket - // pub LINT_NAME, - Ident Ident(name) Comma - // "description" - Literal{kind: LiteralKind::Str{..},..}(reason) - ); - - if let Some(LintDeclSearchResult { - token_kind: TokenKind::CloseBrace, - range, - .. - }) = iter.next() - { - lints.push(DeprecatedLint::new(name, reason, start..range.end)); - } - } -} - -fn parse_renamed_contents(contents: &str, lints: &mut Vec) { - for line in contents.lines() { - let mut offset = 0usize; - let mut iter = tokenize(line).map(|t| { - let range = offset..offset + t.len as usize; - offset = range.end; - - LintDeclSearchResult { - token_kind: t.kind, - content: &line[range.clone()], - range, - } - }); - - let (old_name, new_name) = match_tokens!( - iter, - // ("old_name", - Whitespace OpenParen Literal{kind: LiteralKind::Str{..},..}(old_name) Comma - // "new_name"), - Whitespace Literal{kind: LiteralKind::Str{..},..}(new_name) CloseParen Comma - ); - lints.push(RenamedLint::new(old_name, new_name)); - } -} - -/// Removes the line splices and surrounding quotes from a string literal -fn remove_line_splices(s: &str) -> String { - let s = s - .strip_prefix('r') - .unwrap_or(s) - .trim_matches('#') - .strip_prefix('"') - .and_then(|s| s.strip_suffix('"')) - .unwrap_or_else(|| panic!("expected quoted string, found `{s}`")); - let mut res = String::with_capacity(s.len()); - unescape::unescape_unicode(s, unescape::Mode::Str, &mut |range, ch| { - if ch.is_ok() { - res.push_str(&s[range]); - } - }); - res -} - -/// Replaces a region in a file delimited by two lines matching regexes. -/// -/// `path` is the relative path to the file on which you want to perform the replacement. -/// -/// See `replace_region_in_text` for documentation of the other options. -/// -/// # Panics -/// -/// Panics if the path could not read or then written -fn replace_region_in_file( - update_mode: UpdateMode, - path: &Path, - start: &str, - end: &str, - write_replacement: impl FnMut(&mut String), -) { - let contents = fs::read_to_string(path).unwrap_or_else(|e| panic!("Cannot read from `{}`: {e}", path.display())); - let new_contents = match replace_region_in_text(&contents, start, end, write_replacement) { - Ok(x) => x, - Err(delim) => panic!("Couldn't find `{delim}` in file `{}`", path.display()), - }; - - match update_mode { - UpdateMode::Check if contents != new_contents => exit_with_failure(), - UpdateMode::Check => (), - UpdateMode::Change => { - if let Err(e) = fs::write(path, new_contents.as_bytes()) { - panic!("Cannot write to `{}`: {e}", path.display()); - } - }, - } -} - -/// Replaces a region in a text delimited by two strings. Returns the new text if both delimiters -/// were found, or the missing delimiter if not. -fn replace_region_in_text<'a>( - text: &str, - start: &'a str, - end: &'a str, - mut write_replacement: impl FnMut(&mut String), -) -> Result { - let (text_start, rest) = text.split_once(start).ok_or(start)?; - let (_, text_end) = rest.split_once(end).ok_or(end)?; - - let mut res = String::with_capacity(text.len() + 4096); - res.push_str(text_start); - res.push_str(start); - write_replacement(&mut res); - res.push_str(end); - res.push_str(text_end); - - Ok(res) -} - -fn try_rename_file(old_name: &Path, new_name: &Path) -> bool { - match OpenOptions::new().create_new(true).write(true).open(new_name) { - Ok(file) => drop(file), - Err(e) if matches!(e.kind(), io::ErrorKind::AlreadyExists | io::ErrorKind::NotFound) => return false, - Err(e) => panic_file(e, new_name, "create"), - }; - match fs::rename(old_name, new_name) { - Ok(()) => true, - Err(e) => { - drop(fs::remove_file(new_name)); - if e.kind() == io::ErrorKind::NotFound { - false - } else { - panic_file(e, old_name, "rename"); - } - }, - } -} - -#[allow(clippy::needless_pass_by_value)] -fn panic_file(error: io::Error, name: &Path, action: &str) -> ! { - panic!("failed to {action} file `{}`: {error}", name.display()) -} - -fn rewrite_file(path: &Path, f: impl FnOnce(&str) -> Option) { - let mut file = OpenOptions::new() - .write(true) - .read(true) - .open(path) - .unwrap_or_else(|e| panic_file(e, path, "open")); - let mut buf = String::new(); - file.read_to_string(&mut buf) - .unwrap_or_else(|e| panic_file(e, path, "read")); - if let Some(new_contents) = f(&buf) { - file.rewind().unwrap_or_else(|e| panic_file(e, path, "write")); - file.write_all(new_contents.as_bytes()) - .unwrap_or_else(|e| panic_file(e, path, "write")); - file.set_len(new_contents.len() as u64) - .unwrap_or_else(|e| panic_file(e, path, "write")); - } -} - -fn write_file(path: &Path, contents: &str) { - fs::write(path, contents).unwrap_or_else(|e| panic_file(e, path, "write")); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_parse_contents() { - static CONTENTS: &str = r#" - declare_clippy_lint! { - #[clippy::version = "Hello Clippy!"] - pub PTR_ARG, - style, - "really long \ - text" - } - - declare_clippy_lint!{ - #[clippy::version = "Test version"] - pub DOC_MARKDOWN, - pedantic, - "single line" - } - "#; - let mut result = Vec::new(); - parse_contents(CONTENTS, "module_name", &mut result); - for r in &mut result { - r.declaration_range = Range::default(); - } - - let expected = vec![ - Lint::new( - "ptr_arg", - "style", - "\"really long text\"", - "module_name", - Range::default(), - ), - Lint::new( - "doc_markdown", - "pedantic", - "\"single line\"", - "module_name", - Range::default(), - ), - ]; - assert_eq!(expected, result); - } - - #[test] - fn test_parse_deprecated_contents() { - static DEPRECATED_CONTENTS: &str = r#" - /// some doc comment - declare_deprecated_lint! { - #[clippy::version = "I'm a version"] - pub SHOULD_ASSERT_EQ, - "`assert!()` will be more flexible with RFC 2011" - } - "#; - - let mut result = Vec::new(); - parse_deprecated_contents(DEPRECATED_CONTENTS, &mut result); - for r in &mut result { - r.declaration_range = Range::default(); - } - - let expected = vec![DeprecatedLint::new( - "should_assert_eq", - "\"`assert!()` will be more flexible with RFC 2011\"", - Range::default(), - )]; - assert_eq!(expected, result); - } - - #[test] - fn test_usable_lints() { - let lints = vec![ - Lint::new( - "should_assert_eq2", - "Not Deprecated", - "\"abc\"", - "module_name", - Range::default(), - ), - Lint::new( - "should_assert_eq2", - "internal", - "\"abc\"", - "module_name", - Range::default(), - ), - Lint::new( - "should_assert_eq2", - "internal_style", - "\"abc\"", - "module_name", - Range::default(), - ), - ]; - let expected = vec![Lint::new( - "should_assert_eq2", - "Not Deprecated", - "\"abc\"", - "module_name", - Range::default(), - )]; - assert_eq!(expected, Lint::usable_lints(&lints)); - } - - #[test] - fn test_by_lint_group() { - let lints = vec![ - Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()), - Lint::new( - "should_assert_eq2", - "group2", - "\"abc\"", - "module_name", - Range::default(), - ), - Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()), - ]; - let mut expected: HashMap> = HashMap::new(); - expected.insert( - "group1".to_string(), - vec![ - Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()), - Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()), - ], - ); - expected.insert( - "group2".to_string(), - vec![Lint::new( - "should_assert_eq2", - "group2", - "\"abc\"", - "module_name", - Range::default(), - )], - ); - assert_eq!(expected, Lint::by_lint_group(lints.into_iter())); - } - - #[test] - fn test_gen_deprecated() { - let lints = vec![ - DeprecatedLint::new( - "should_assert_eq", - "\"has been superseded by should_assert_eq2\"", - Range::default(), - ), - DeprecatedLint::new("another_deprecated", "\"will be removed\"", Range::default()), - ]; - - let expected = GENERATED_FILE_COMMENT.to_string() - + &[ - "{", - " store.register_removed(", - " \"clippy::should_assert_eq\",", - " \"has been superseded by should_assert_eq2\",", - " );", - " store.register_removed(", - " \"clippy::another_deprecated\",", - " \"will be removed\",", - " );", - "}", - ] - .join("\n") - + "\n"; - - assert_eq!(expected, gen_deprecated(&lints)); - } -} diff --git a/clippy_dummy/Cargo.toml b/clippy_dummy/Cargo.toml deleted file mode 100644 index c206a1eb07b5..000000000000 --- a/clippy_dummy/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "clippy_dummy" # rename to clippy before publishing -version = "0.0.303" -edition = "2018" -readme = "crates-readme.md" -description = "A bunch of helpful lints to avoid common pitfalls in Rust." -build = 'build.rs' - -repository = "https://github.com/rust-lang/rust-clippy" - -license = "MIT OR Apache-2.0" -keywords = ["clippy", "lint", "plugin"] -categories = ["development-tools", "development-tools::cargo-plugins"] - -[build-dependencies] -term = "0.7" diff --git a/clippy_dummy/PUBLISH.md b/clippy_dummy/PUBLISH.md deleted file mode 100644 index 8e420ec959a2..000000000000 --- a/clippy_dummy/PUBLISH.md +++ /dev/null @@ -1,6 +0,0 @@ -This is a dummy crate to publish to crates.io. It primarily exists to ensure -that folks trying to install clippy from crates.io get redirected to the -`rustup` technique. - -Before publishing, be sure to rename `clippy_dummy` to `clippy` in `Cargo.toml`, -it has a different name to avoid workspace issues. diff --git a/clippy_dummy/build.rs b/clippy_dummy/build.rs deleted file mode 100644 index 21af4f8244f4..000000000000 --- a/clippy_dummy/build.rs +++ /dev/null @@ -1,42 +0,0 @@ -use term::color::{GREEN, RED, WHITE}; -use term::{Attr, Error, Result}; - -fn main() { - if foo().is_err() { - eprintln!( - "error: Clippy is no longer available via crates.io\n\n\ - help: please run `rustup component add clippy` instead" - ); - } - std::process::exit(1); -} - -fn foo() -> Result<()> { - let mut t = term::stderr().ok_or(Error::NotSupported)?; - - t.attr(Attr::Bold)?; - t.fg(RED)?; - write!(t, "\nerror: ")?; - - t.reset()?; - t.fg(WHITE)?; - writeln!(t, "Clippy is no longer available via crates.io\n")?; - - t.attr(Attr::Bold)?; - t.fg(GREEN)?; - write!(t, "help: ")?; - - t.reset()?; - t.fg(WHITE)?; - write!(t, "please run `")?; - - t.attr(Attr::Bold)?; - write!(t, "rustup component add clippy")?; - - t.reset()?; - t.fg(WHITE)?; - writeln!(t, "` instead")?; - - t.reset()?; - Ok(()) -} diff --git a/clippy_dummy/crates-readme.md b/clippy_dummy/crates-readme.md deleted file mode 100644 index 0decae8b9103..000000000000 --- a/clippy_dummy/crates-readme.md +++ /dev/null @@ -1,9 +0,0 @@ -Installing clippy via crates.io is deprecated. Please use the following: - -```terminal -rustup component add clippy -``` - -on a Rust version 1.29 or later. You may need to run `rustup self update` if it complains about a missing clippy binary. - -See [the homepage](https://github.com/rust-lang/rust-clippy/#clippy) for more information diff --git a/clippy_dummy/src/main.rs b/clippy_dummy/src/main.rs deleted file mode 100644 index a118834f1fd4..000000000000 --- a/clippy_dummy/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - panic!("This shouldn't even compile") -} diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml deleted file mode 100644 index 5e3a119337cc..000000000000 --- a/clippy_lints/Cargo.toml +++ /dev/null @@ -1,41 +0,0 @@ -[package] -name = "clippy_lints" -version = "0.1.80" -description = "A bunch of helpful lints to avoid common pitfalls in Rust" -repository = "https://github.com/rust-lang/rust-clippy" -readme = "README.md" -license = "MIT OR Apache-2.0" -keywords = ["clippy", "lint", "plugin"] -edition = "2021" - -[dependencies] -arrayvec = { version = "0.7", default-features = false } -cargo_metadata = "0.18" -clippy_config = { path = "../clippy_config" } -clippy_utils = { path = "../clippy_utils" } -declare_clippy_lint = { path = "../declare_clippy_lint" } -itertools = "0.12" -quine-mc_cluskey = "0.2" -regex-syntax = "0.8" -serde = { version = "1.0", features = ["derive"] } -serde_json = { version = "1.0", optional = true } -tempfile = { version = "3.3.0", optional = true } -toml = "0.7.3" -regex = { version = "1.5", optional = true } -unicode-normalization = "0.1" -unicode-script = { version = "0.5", default-features = false } -semver = "1.0" -rustc-semver = "1.1" -url = "2.2" - -[dev-dependencies] -walkdir = "2.3" - -[features] -deny-warnings = ["clippy_config/deny-warnings", "clippy_utils/deny-warnings"] -# build clippy with internal lints enabled, off by default -internal = ["serde_json", "tempfile", "regex"] - -[package.metadata.rust-analyzer] -# This crate uses #[feature(rustc_private)] -rustc_private = true diff --git a/clippy_lints/README.md b/clippy_lints/README.md deleted file mode 100644 index 513583b7e349..000000000000 --- a/clippy_lints/README.md +++ /dev/null @@ -1 +0,0 @@ -This crate contains Clippy lints. For the main crate, check [GitHub](https://github.com/rust-lang/rust-clippy). diff --git a/clippy_lints/src/absolute_paths.rs b/clippy_lints/src/absolute_paths.rs deleted file mode 100644 index 8ba661afeeb6..000000000000 --- a/clippy_lints/src/absolute_paths.rs +++ /dev/null @@ -1,100 +0,0 @@ -use clippy_utils::diagnostics::span_lint; -use clippy_utils::source::snippet_opt; -use rustc_data_structures::fx::FxHashSet; -use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX}; -use rustc_hir::{HirId, ItemKind, Node, Path}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::impl_lint_pass; -use rustc_span::symbol::kw; - -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of items through absolute paths, like `std::env::current_dir`. - /// - /// ### Why is this bad? - /// Many codebases have their own style when it comes to importing, but one that is seldom used - /// is using absolute paths *everywhere*. This is generally considered unidiomatic, and you - /// should add a `use` statement. - /// - /// The default maximum segments (2) is pretty strict, you may want to increase this in - /// `clippy.toml`. - /// - /// Note: One exception to this is code from macro expansion - this does not lint such cases, as - /// using absolute paths is the proper way of referencing items in one. - /// - /// ### Example - /// ```no_run - /// let x = std::f64::consts::PI; - /// ``` - /// Use any of the below instead, or anything else: - /// ```no_run - /// use std::f64; - /// use std::f64::consts; - /// use std::f64::consts::PI; - /// let x = f64::consts::PI; - /// let x = consts::PI; - /// let x = PI; - /// use std::f64::consts as f64_consts; - /// let x = f64_consts::PI; - /// ``` - #[clippy::version = "1.73.0"] - pub ABSOLUTE_PATHS, - restriction, - "checks for usage of an item without a `use` statement" -} -impl_lint_pass!(AbsolutePaths => [ABSOLUTE_PATHS]); - -pub struct AbsolutePaths { - pub absolute_paths_max_segments: u64, - pub absolute_paths_allowed_crates: FxHashSet, -} - -impl LateLintPass<'_> for AbsolutePaths { - // We should only lint `QPath::Resolved`s, but since `Path` is only used in `Resolved` and `UsePath` - // we don't need to use a visitor or anything as we can just check if the `Node` for `hir_id` isn't - // a `Use` - #[expect(clippy::cast_possible_truncation)] - fn check_path(&mut self, cx: &LateContext<'_>, path: &Path<'_>, hir_id: HirId) { - let Self { - absolute_paths_max_segments, - absolute_paths_allowed_crates, - } = self; - - if !path.span.from_expansion() - && let node = cx.tcx.hir_node(hir_id) - && !matches!(node, Node::Item(item) if matches!(item.kind, ItemKind::Use(_, _))) - && let [first, rest @ ..] = path.segments - // Handle `::std` - && let (segment, len) = if first.ident.name == kw::PathRoot { - // Indexing is fine as `PathRoot` must be followed by another segment. `len() - 1` - // is fine here for the same reason - (&rest[0], path.segments.len() - 1) - } else { - (first, path.segments.len()) - } - && len > *absolute_paths_max_segments as usize - && let Some(segment_snippet) = snippet_opt(cx, segment.ident.span) - && segment_snippet == segment.ident.as_str() - { - let is_abs_external = - matches!(segment.res, Res::Def(DefKind::Mod, DefId { index, .. }) if index == CRATE_DEF_INDEX); - let is_abs_crate = segment.ident.name == kw::Crate; - - if is_abs_external && absolute_paths_allowed_crates.contains(segment.ident.name.as_str()) - || is_abs_crate && absolute_paths_allowed_crates.contains("crate") - { - return; - } - - if is_abs_external || is_abs_crate { - span_lint( - cx, - ABSOLUTE_PATHS, - path.span, - "consider bringing this path into scope with the `use` keyword", - ); - } - } - } -} diff --git a/clippy_lints/src/allow_attributes.rs b/clippy_lints/src/allow_attributes.rs deleted file mode 100644 index 39fc49dee377..000000000000 --- a/clippy_lints/src/allow_attributes.rs +++ /dev/null @@ -1,73 +0,0 @@ -use ast::{AttrStyle, Attribute}; -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::is_from_proc_macro; -use rustc_ast as ast; -use rustc_errors::Applicability; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_session::declare_lint_pass; - -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of the `#[allow]` attribute and suggests replacing it with - /// the `#[expect]` (See [RFC 2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html)) - /// - /// The expect attribute is still unstable and requires the `lint_reasons` - /// on nightly. It can be enabled by adding `#![feature(lint_reasons)]` to - /// the crate root. - /// - /// This lint only warns outer attributes (`#[allow]`), as inner attributes - /// (`#![allow]`) are usually used to enable or disable lints on a global scale. - /// - /// ### Why is this bad? - /// `#[expect]` attributes suppress the lint emission, but emit a warning, if - /// the expectation is unfulfilled. This can be useful to be notified when the - /// lint is no longer triggered. - /// - /// ### Example - /// ```rust,ignore - /// #[allow(unused_mut)] - /// fn foo() -> usize { - /// let mut a = Vec::new(); - /// a.len() - /// } - /// ``` - /// Use instead: - /// ```rust,ignore - /// #![feature(lint_reasons)] - /// #[expect(unused_mut)] - /// fn foo() -> usize { - /// let mut a = Vec::new(); - /// a.len() - /// } - /// ``` - #[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." -} - -declare_lint_pass!(AllowAttribute => [ALLOW_ATTRIBUTES]); - -impl LateLintPass<'_> for AllowAttribute { - // Separate each crate's features. - fn check_attribute<'cx>(&mut self, cx: &LateContext<'cx>, attr: &'cx Attribute) { - if !in_external_macro(cx.sess(), attr.span) - && cx.tcx.features().lint_reasons - && let AttrStyle::Outer = attr.style - && let Some(ident) = attr.ident() - && ident.name == rustc_span::symbol::sym::allow - && !is_from_proc_macro(cx, &attr) - { - span_lint_and_sugg( - cx, - ALLOW_ATTRIBUTES, - ident.span, - "#[allow] attribute found", - "replace it with", - "expect".into(), - Applicability::MachineApplicable, - ); - } - } -} diff --git a/clippy_lints/src/almost_complete_range.rs b/clippy_lints/src/almost_complete_range.rs deleted file mode 100644 index 57a5cd8fba81..000000000000 --- a/clippy_lints/src/almost_complete_range.rs +++ /dev/null @@ -1,101 +0,0 @@ -use clippy_config::msrvs::{self, Msrv}; -use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::{trim_span, walk_span_to_context}; -use rustc_ast::ast::{Expr, ExprKind, LitKind, Pat, PatKind, RangeEnd, RangeLimits}; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_session::impl_lint_pass; -use rustc_span::Span; - -declare_clippy_lint! { - /// ### What it does - /// Checks for ranges which almost include the entire range of letters from 'a' to 'z' - /// or digits from '0' to '9', but don't because they're a half open range. - /// - /// ### Why is this bad? - /// This (`'a'..'z'`) is almost certainly a typo meant to include all letters. - /// - /// ### Example - /// ```no_run - /// let _ = 'a'..'z'; - /// ``` - /// Use instead: - /// ```no_run - /// let _ = 'a'..='z'; - /// ``` - #[clippy::version = "1.68.0"] - pub ALMOST_COMPLETE_RANGE, - suspicious, - "almost complete range" -} -impl_lint_pass!(AlmostCompleteRange => [ALMOST_COMPLETE_RANGE]); - -pub struct AlmostCompleteRange { - msrv: Msrv, -} -impl AlmostCompleteRange { - pub fn new(msrv: Msrv) -> Self { - Self { msrv } - } -} -impl EarlyLintPass for AlmostCompleteRange { - fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) { - if let ExprKind::Range(Some(start), Some(end), RangeLimits::HalfOpen) = &e.kind { - let ctxt = e.span.ctxt(); - let sugg = if let Some(start) = walk_span_to_context(start.span, ctxt) - && let Some(end) = walk_span_to_context(end.span, ctxt) - && self.msrv.meets(msrvs::RANGE_INCLUSIVE) - { - Some((trim_span(cx.sess().source_map(), start.between(end)), "..=")) - } else { - None - }; - check_range(cx, e.span, start, end, sugg); - } - } - - fn check_pat(&mut self, cx: &EarlyContext<'_>, p: &Pat) { - if let PatKind::Range(Some(start), Some(end), kind) = &p.kind - && matches!(kind.node, RangeEnd::Excluded) - { - let sugg = if self.msrv.meets(msrvs::RANGE_INCLUSIVE) { - "..=" - } else { - "..." - }; - check_range(cx, p.span, start, end, Some((kind.span, sugg))); - } - } - - extract_msrv_attr!(EarlyContext); -} - -fn check_range(cx: &EarlyContext<'_>, span: Span, start: &Expr, end: &Expr, sugg: Option<(Span, &str)>) { - if let ExprKind::Lit(start_token_lit) = start.peel_parens().kind - && let ExprKind::Lit(end_token_lit) = end.peel_parens().kind - && matches!( - ( - LitKind::from_token_lit(start_token_lit), - LitKind::from_token_lit(end_token_lit), - ), - ( - Ok(LitKind::Byte(b'a') | LitKind::Char('a')), - Ok(LitKind::Byte(b'z') | LitKind::Char('z')) - ) | ( - Ok(LitKind::Byte(b'A') | LitKind::Char('A')), - Ok(LitKind::Byte(b'Z') | LitKind::Char('Z')), - ) | ( - Ok(LitKind::Byte(b'0') | LitKind::Char('0')), - Ok(LitKind::Byte(b'9') | LitKind::Char('9')), - ) - ) - && !in_external_macro(cx.sess(), span) - { - span_lint_and_then(cx, ALMOST_COMPLETE_RANGE, span, "almost complete ascii range", |diag| { - if let Some((span, sugg)) = sugg { - diag.span_suggestion(span, "use an inclusive range", sugg, Applicability::MaybeIncorrect); - } - }); - } -} diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs deleted file mode 100644 index ec28fd461118..000000000000 --- a/clippy_lints/src/approx_const.rs +++ /dev/null @@ -1,135 +0,0 @@ -use clippy_config::msrvs::{self, Msrv}; -use clippy_utils::diagnostics::span_lint_and_help; -use rustc_ast::ast::{FloatTy, LitFloatType, LitKind}; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_semver::RustcVersion; -use rustc_session::impl_lint_pass; -use rustc_span::symbol; -use std::f64::consts as f64; - -declare_clippy_lint! { - /// ### What it does - /// Checks for floating point literals that approximate - /// constants which are defined in - /// [`std::f32::consts`](https://doc.rust-lang.org/stable/std/f32/consts/#constants) - /// or - /// [`std::f64::consts`](https://doc.rust-lang.org/stable/std/f64/consts/#constants), - /// respectively, suggesting to use the predefined constant. - /// - /// ### Why is this bad? - /// Usually, the definition in the standard library is more - /// precise than what people come up with. If you find that your definition is - /// actually more precise, please [file a Rust - /// issue](https://github.com/rust-lang/rust/issues). - /// - /// ### Example - /// ```no_run - /// let x = 3.14; - /// let y = 1_f64 / x; - /// ``` - /// Use instead: - /// ```no_run - /// let x = std::f32::consts::PI; - /// let y = std::f64::consts::FRAC_1_PI; - /// ``` - #[clippy::version = "pre 1.29.0"] - pub APPROX_CONSTANT, - correctness, - "the approximate of a known float constant (in `std::fXX::consts`)" -} - -// Tuples are of the form (constant, name, min_digits, msrv) -const KNOWN_CONSTS: [(f64, &str, usize, Option); 19] = [ - (f64::E, "E", 4, None), - (f64::FRAC_1_PI, "FRAC_1_PI", 4, None), - (f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5, None), - (f64::FRAC_2_PI, "FRAC_2_PI", 5, None), - (f64::FRAC_2_SQRT_PI, "FRAC_2_SQRT_PI", 5, None), - (f64::FRAC_PI_2, "FRAC_PI_2", 5, None), - (f64::FRAC_PI_3, "FRAC_PI_3", 5, None), - (f64::FRAC_PI_4, "FRAC_PI_4", 5, None), - (f64::FRAC_PI_6, "FRAC_PI_6", 5, None), - (f64::FRAC_PI_8, "FRAC_PI_8", 5, None), - (f64::LN_2, "LN_2", 5, None), - (f64::LN_10, "LN_10", 5, None), - (f64::LOG2_10, "LOG2_10", 5, Some(msrvs::LOG2_10)), - (f64::LOG2_E, "LOG2_E", 5, None), - (f64::LOG10_2, "LOG10_2", 5, Some(msrvs::LOG10_2)), - (f64::LOG10_E, "LOG10_E", 5, None), - (f64::PI, "PI", 3, None), - (f64::SQRT_2, "SQRT_2", 5, None), - (f64::TAU, "TAU", 3, Some(msrvs::TAU)), -]; - -pub struct ApproxConstant { - msrv: Msrv, -} - -impl ApproxConstant { - #[must_use] - pub fn new(msrv: Msrv) -> Self { - Self { msrv } - } - - fn check_lit(&self, cx: &LateContext<'_>, lit: &LitKind, e: &Expr<'_>) { - match *lit { - LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty { - FloatTy::F16 => self.check_known_consts(cx, e, s, "f16"), - FloatTy::F32 => self.check_known_consts(cx, e, s, "f32"), - FloatTy::F64 => self.check_known_consts(cx, e, s, "f64"), - FloatTy::F128 => self.check_known_consts(cx, e, s, "f128"), - }, - // FIXME(f16_f128): add `f16` and `f128` when these types become stable. - LitKind::Float(s, LitFloatType::Unsuffixed) => self.check_known_consts(cx, e, s, "f{32, 64}"), - _ => (), - } - } - - fn check_known_consts(&self, cx: &LateContext<'_>, e: &Expr<'_>, s: symbol::Symbol, module: &str) { - let s = s.as_str(); - if s.parse::().is_ok() { - for &(constant, name, min_digits, msrv) in &KNOWN_CONSTS { - if is_approx_const(constant, s, min_digits) && msrv.map_or(true, |msrv| self.msrv.meets(msrv)) { - span_lint_and_help( - cx, - APPROX_CONSTANT, - e.span, - format!("approximate value of `{module}::consts::{}` found", &name), - None, - "consider using the constant directly", - ); - return; - } - } - } - } -} - -impl_lint_pass!(ApproxConstant => [APPROX_CONSTANT]); - -impl<'tcx> LateLintPass<'tcx> for ApproxConstant { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if let ExprKind::Lit(lit) = &e.kind { - self.check_lit(cx, &lit.node, e); - } - } - - extract_msrv_attr!(LateContext); -} - -/// Returns `false` if the number of significant figures in `value` are -/// less than `min_digits`; otherwise, returns true if `value` is equal -/// to `constant`, rounded to the number of digits present in `value`. -#[must_use] -fn is_approx_const(constant: f64, value: &str, min_digits: usize) -> bool { - if value.len() <= min_digits { - false - } else if constant.to_string().starts_with(value) { - // The value is a truncated constant - true - } else { - let round_const = format!("{constant:.*}", value.len() - 2); - value == round_const - } -} diff --git a/clippy_lints/src/arc_with_non_send_sync.rs b/clippy_lints/src/arc_with_non_send_sync.rs deleted file mode 100644 index 389338973894..000000000000 --- a/clippy_lints/src/arc_with_non_send_sync.rs +++ /dev/null @@ -1,86 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; -use clippy_utils::{is_from_proc_macro, last_path_segment}; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_middle::ty::print::with_forced_trimmed_paths; -use rustc_middle::ty::GenericArgKind; -use rustc_session::declare_lint_pass; -use rustc_span::symbol::sym; - -declare_clippy_lint! { - /// ### What it does. - /// This lint warns when you use `Arc` with a type that does not implement `Send` or `Sync`. - /// - /// ### Why is this bad? - /// `Arc` is a thread-safe `Rc` and guarantees that updates to the reference counter - /// use atomic operations. To send an `Arc` across thread boundaries and - /// share ownership between multiple threads, `T` must be [both `Send` and `Sync`](https://doc.rust-lang.org/std/sync/struct.Arc.html#thread-safety), - /// so either `T` should be made `Send + Sync` or an `Rc` should be used instead of an `Arc` - /// - /// ### Example - /// ```no_run - /// # use std::cell::RefCell; - /// # use std::sync::Arc; - /// - /// fn main() { - /// // This is fine, as `i32` implements `Send` and `Sync`. - /// let a = Arc::new(42); - /// - /// // `RefCell` is `!Sync`, so either the `Arc` should be replaced with an `Rc` - /// // or the `RefCell` replaced with something like a `RwLock` - /// let b = Arc::new(RefCell::new(42)); - /// } - /// ``` - #[clippy::version = "1.72.0"] - pub ARC_WITH_NON_SEND_SYNC, - suspicious, - "using `Arc` with a type that does not implement `Send` and `Sync`" -} -declare_lint_pass!(ArcWithNonSendSync => [ARC_WITH_NON_SEND_SYNC]); - -impl<'tcx> LateLintPass<'tcx> for ArcWithNonSendSync { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - if !expr.span.from_expansion() - && let ty = cx.typeck_results().expr_ty(expr) - && is_type_diagnostic_item(cx, ty, sym::Arc) - && let ExprKind::Call(func, [arg]) = expr.kind - && let ExprKind::Path(func_path) = func.kind - && last_path_segment(&func_path).ident.name == sym::new - && let arg_ty = cx.typeck_results().expr_ty(arg) - // make sure that the type is not and does not contain any type parameters - && arg_ty.walk().all(|arg| { - !matches!(arg.unpack(), GenericArgKind::Type(ty) if matches!(ty.kind(), ty::Param(_))) - }) - && let Some(send) = cx.tcx.get_diagnostic_item(sym::Send) - && let Some(sync) = cx.tcx.lang_items().sync_trait() - && let [is_send, is_sync] = [send, sync].map(|id| implements_trait(cx, arg_ty, id, &[])) - && let reason = match (is_send, is_sync) { - (false, false) => "neither `Send` nor `Sync`", - (false, true) => "not `Send`", - (true, false) => "not `Sync`", - _ => return, - } - && !is_from_proc_macro(cx, expr) - { - span_lint_and_then( - cx, - ARC_WITH_NON_SEND_SYNC, - expr.span, - "usage of an `Arc` that is not `Send` and `Sync`", - |diag| { - with_forced_trimmed_paths!({ - diag.note(format!( - "`Arc<{arg_ty}>` is not `Send` and `Sync` as `{arg_ty}` is {reason}" - )); - diag.help("if the `Arc` will not used be across threads replace it with an `Rc`"); - diag.help(format!( - "otherwise make `{arg_ty}` `Send` and `Sync` or consider a wrapper type such as `Mutex`" - )); - }); - }, - ); - } - } -} diff --git a/clippy_lints/src/as_conversions.rs b/clippy_lints/src/as_conversions.rs deleted file mode 100644 index e3daf75c3eb6..000000000000 --- a/clippy_lints/src/as_conversions.rs +++ /dev/null @@ -1,65 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::is_from_proc_macro; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_session::declare_lint_pass; - -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of `as` conversions. - /// - /// Note that this lint is specialized in linting *every single* use of `as` - /// regardless of whether good alternatives exist or not. - /// If you want more precise lints for `as`, please consider using these separate lints: - /// `unnecessary_cast`, `cast_lossless/cast_possible_truncation/cast_possible_wrap/cast_precision_loss/cast_sign_loss`, - /// `fn_to_numeric_cast(_with_truncation)`, `char_lit_as_u8`, `ref_to_mut` and `ptr_as_ptr`. - /// There is a good explanation the reason why this lint should work in this way and how it is useful - /// [in this issue](https://github.com/rust-lang/rust-clippy/issues/5122). - /// - /// ### Why is this bad? - /// `as` conversions will perform many kinds of - /// conversions, including silently lossy conversions and dangerous coercions. - /// There are cases when it makes sense to use `as`, so the lint is - /// Allow by default. - /// - /// ### Example - /// ```rust,ignore - /// let a: u32; - /// ... - /// f(a as u16); - /// ``` - /// - /// Use instead: - /// ```rust,ignore - /// f(a.try_into()?); - /// - /// // or - /// - /// f(a.try_into().expect("Unexpected u16 overflow in f")); - /// ``` - #[clippy::version = "1.41.0"] - pub AS_CONVERSIONS, - restriction, - "using a potentially dangerous silent `as` conversion" -} - -declare_lint_pass!(AsConversions => [AS_CONVERSIONS]); - -impl<'tcx> LateLintPass<'tcx> for AsConversions { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) { - 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, - expr.span, - "using a potentially dangerous silent `as` conversion", - None, - "consider using a safe wrapper for this conversion", - ); - } - } -} diff --git a/clippy_lints/src/asm_syntax.rs b/clippy_lints/src/asm_syntax.rs deleted file mode 100644 index 7c88bfc97ca4..000000000000 --- a/clippy_lints/src/asm_syntax.rs +++ /dev/null @@ -1,160 +0,0 @@ -use std::fmt; - -use clippy_utils::diagnostics::span_lint_and_help; -use rustc_ast::ast::{Expr, ExprKind, InlineAsmOptions}; -use rustc_ast::{InlineAsm, Item, ItemKind}; -use rustc_lint::{EarlyContext, EarlyLintPass, Lint, LintContext}; -use rustc_session::declare_lint_pass; -use rustc_span::Span; -use rustc_target::asm::InlineAsmArch; - -#[derive(Clone, Copy, PartialEq, Eq)] -enum AsmStyle { - Intel, - Att, -} - -impl fmt::Display for AsmStyle { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - AsmStyle::Intel => f.write_str("Intel"), - AsmStyle::Att => f.write_str("AT&T"), - } - } -} - -impl std::ops::Not for AsmStyle { - type Output = AsmStyle; - - fn not(self) -> AsmStyle { - match self { - AsmStyle::Intel => AsmStyle::Att, - AsmStyle::Att => AsmStyle::Intel, - } - } -} - -fn check_asm_syntax( - lint: &'static Lint, - cx: &EarlyContext<'_>, - inline_asm: &InlineAsm, - span: Span, - check_for: AsmStyle, -) { - if matches!(cx.sess().asm_arch, Some(InlineAsmArch::X86 | InlineAsmArch::X86_64)) { - let style = if inline_asm.options.contains(InlineAsmOptions::ATT_SYNTAX) { - AsmStyle::Att - } else { - AsmStyle::Intel - }; - - if style == check_for { - span_lint_and_help( - cx, - lint, - span, - format!("{style} x86 assembly syntax used"), - None, - format!("use {} x86 assembly syntax", !style), - ); - } - } -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of Intel x86 assembly syntax. - /// - /// ### Why is this bad? - /// The lint has been enabled to indicate a preference - /// for AT&T x86 assembly syntax. - /// - /// ### Example - /// - /// ```rust,no_run - /// # #![feature(asm)] - /// # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - /// # unsafe { let ptr = "".as_ptr(); - /// # use std::arch::asm; - /// asm!("lea {}, [{}]", lateout(reg) _, in(reg) ptr); - /// # } - /// ``` - /// Use instead: - /// ```rust,no_run - /// # #![feature(asm)] - /// # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - /// # unsafe { let ptr = "".as_ptr(); - /// # use std::arch::asm; - /// asm!("lea ({}), {}", in(reg) ptr, lateout(reg) _, options(att_syntax)); - /// # } - /// ``` - #[clippy::version = "1.49.0"] - pub INLINE_ASM_X86_INTEL_SYNTAX, - restriction, - "prefer AT&T x86 assembly syntax" -} - -declare_lint_pass!(InlineAsmX86IntelSyntax => [INLINE_ASM_X86_INTEL_SYNTAX]); - -impl EarlyLintPass for InlineAsmX86IntelSyntax { - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - if let ExprKind::InlineAsm(inline_asm) = &expr.kind { - check_asm_syntax(Self::get_lints()[0], cx, inline_asm, expr.span, AsmStyle::Intel); - } - } - - fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { - if let ItemKind::GlobalAsm(inline_asm) = &item.kind { - check_asm_syntax(Self::get_lints()[0], cx, inline_asm, item.span, AsmStyle::Intel); - } - } -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of AT&T x86 assembly syntax. - /// - /// ### Why is this bad? - /// The lint has been enabled to indicate a preference - /// for Intel x86 assembly syntax. - /// - /// ### Example - /// - /// ```rust,no_run - /// # #![feature(asm)] - /// # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - /// # unsafe { let ptr = "".as_ptr(); - /// # use std::arch::asm; - /// asm!("lea ({}), {}", in(reg) ptr, lateout(reg) _, options(att_syntax)); - /// # } - /// ``` - /// Use instead: - /// ```rust,no_run - /// # #![feature(asm)] - /// # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - /// # unsafe { let ptr = "".as_ptr(); - /// # use std::arch::asm; - /// asm!("lea {}, [{}]", lateout(reg) _, in(reg) ptr); - /// # } - /// ``` - #[clippy::version = "1.49.0"] - pub INLINE_ASM_X86_ATT_SYNTAX, - restriction, - "prefer Intel x86 assembly syntax" -} - -declare_lint_pass!(InlineAsmX86AttSyntax => [INLINE_ASM_X86_ATT_SYNTAX]); - -impl EarlyLintPass for InlineAsmX86AttSyntax { - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { - if let ExprKind::InlineAsm(inline_asm) = &expr.kind { - check_asm_syntax(Self::get_lints()[0], cx, inline_asm, expr.span, AsmStyle::Att); - } - } - - fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { - if let ItemKind::GlobalAsm(inline_asm) = &item.kind { - check_asm_syntax(Self::get_lints()[0], cx, inline_asm, item.span, AsmStyle::Att); - } - } -} diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs deleted file mode 100644 index 2003dd1fb0e2..000000000000 --- a/clippy_lints/src/assertions_on_constants.rs +++ /dev/null @@ -1,83 +0,0 @@ -use clippy_utils::consts::{constant_with_source, Constant, ConstantSource}; -use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::macros::{find_assert_args, root_macro_call_first_node, PanicExpn}; -use rustc_hir::{Expr, Item, ItemKind, Node}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::declare_lint_pass; -use rustc_span::sym; - -declare_clippy_lint! { - /// ### What it does - /// Checks for `assert!(true)` and `assert!(false)` calls. - /// - /// ### Why is this bad? - /// Will be optimized out by the compiler or should probably be replaced by a - /// `panic!()` or `unreachable!()` - /// - /// ### Example - /// ```rust,ignore - /// assert!(false) - /// assert!(true) - /// const B: bool = false; - /// assert!(B) - /// ``` - #[clippy::version = "1.34.0"] - pub ASSERTIONS_ON_CONSTANTS, - style, - "`assert!(true)` / `assert!(false)` will be optimized out by the compiler, and should probably be replaced by a `panic!()` or `unreachable!()`" -} - -declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]); - -impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - let Some(macro_call) = root_macro_call_first_node(cx, e) else { - return; - }; - let is_debug = match cx.tcx.get_diagnostic_name(macro_call.def_id) { - Some(sym::debug_assert_macro) => true, - Some(sym::assert_macro) => false, - _ => return, - }; - let Some((condition, panic_expn)) = find_assert_args(cx, e, macro_call.expn) else { - return; - }; - let Some((Constant::Bool(val), source)) = constant_with_source(cx, cx.typeck_results(), condition) else { - return; - }; - if let ConstantSource::Constant = source - && let Node::Item(Item { - kind: ItemKind::Const(..), - .. - }) = cx.tcx.parent_hir_node(e.hir_id) - { - return; - } - if val { - span_lint_and_help( - cx, - ASSERTIONS_ON_CONSTANTS, - macro_call.span, - format!( - "`{}!(true)` will be optimized out by the compiler", - cx.tcx.item_name(macro_call.def_id) - ), - None, - "remove it", - ); - } else if !is_debug { - let (assert_arg, panic_arg) = match panic_expn { - PanicExpn::Empty => ("", ""), - _ => (", ..", ".."), - }; - span_lint_and_help( - cx, - ASSERTIONS_ON_CONSTANTS, - macro_call.span, - format!("`assert!(false{assert_arg})` should probably be replaced"), - None, - format!("use `panic!({panic_arg})` or `unreachable!({panic_arg})`"), - ); - } - } -} diff --git a/clippy_lints/src/assertions_on_result_states.rs b/clippy_lints/src/assertions_on_result_states.rs deleted file mode 100644 index aec22965b1b0..000000000000 --- a/clippy_lints/src/assertions_on_result_states.rs +++ /dev/null @@ -1,100 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::macros::{find_assert_args, root_macro_call_first_node, PanicExpn}; -use clippy_utils::source::snippet_with_context; -use clippy_utils::ty::{has_debug_impl, is_copy, is_type_diagnostic_item}; -use clippy_utils::usage::local_used_after_expr; -use clippy_utils::{is_expr_final_block_expr, path_res}; -use rustc_errors::Applicability; -use rustc_hir::def::Res; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, Ty}; -use rustc_session::declare_lint_pass; -use rustc_span::sym; - -declare_clippy_lint! { - /// ### What it does - /// Checks for `assert!(r.is_ok())` or `assert!(r.is_err())` calls. - /// - /// ### Why is this bad? - /// An assertion failure cannot output an useful message of the error. - /// - /// ### Known problems - /// The suggested replacement decreases the readability of code and log output. - /// - /// ### Example - /// ```rust,ignore - /// # let r = Ok::<_, ()>(()); - /// assert!(r.is_ok()); - /// # let r = Err::<_, ()>(()); - /// assert!(r.is_err()); - /// ``` - #[clippy::version = "1.64.0"] - pub ASSERTIONS_ON_RESULT_STATES, - restriction, - "`assert!(r.is_ok())`/`assert!(r.is_err())` gives worse error message than directly calling `r.unwrap()`/`r.unwrap_err()`" -} - -declare_lint_pass!(AssertionsOnResultStates => [ASSERTIONS_ON_RESULT_STATES]); - -impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if let Some(macro_call) = root_macro_call_first_node(cx, e) - && matches!(cx.tcx.get_diagnostic_name(macro_call.def_id), Some(sym::assert_macro)) - && let Some((condition, panic_expn)) = find_assert_args(cx, e, macro_call.expn) - && matches!(panic_expn, PanicExpn::Empty) - && let ExprKind::MethodCall(method_segment, recv, [], _) = condition.kind - && let result_type_with_refs = cx.typeck_results().expr_ty(recv) - && let result_type = result_type_with_refs.peel_refs() - && is_type_diagnostic_item(cx, result_type, sym::Result) - && let ty::Adt(_, args) = result_type.kind() - { - if !is_copy(cx, result_type) { - if result_type_with_refs != result_type { - return; - } else if let Res::Local(binding_id) = path_res(cx, recv) - && local_used_after_expr(cx, binding_id, recv) - { - return; - } - } - let semicolon = if is_expr_final_block_expr(cx.tcx, e) { ";" } else { "" }; - let mut app = Applicability::MachineApplicable; - match method_segment.ident.as_str() { - "is_ok" if type_suitable_to_unwrap(cx, args.type_at(1)) => { - span_lint_and_sugg( - cx, - ASSERTIONS_ON_RESULT_STATES, - macro_call.span, - "called `assert!` with `Result::is_ok`", - "replace with", - format!( - "{}.unwrap(){semicolon}", - snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0 - ), - app, - ); - }, - "is_err" if type_suitable_to_unwrap(cx, args.type_at(0)) => { - span_lint_and_sugg( - cx, - ASSERTIONS_ON_RESULT_STATES, - macro_call.span, - "called `assert!` with `Result::is_err`", - "replace with", - format!( - "{}.unwrap_err(){semicolon}", - snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0 - ), - app, - ); - }, - _ => (), - }; - } - } -} - -fn type_suitable_to_unwrap<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { - has_debug_impl(cx, ty) && !ty.is_unit() && !ty.is_never() -} diff --git a/clippy_lints/src/assigning_clones.rs b/clippy_lints/src/assigning_clones.rs deleted file mode 100644 index e94a6f3e3fc5..000000000000 --- a/clippy_lints/src/assigning_clones.rs +++ /dev/null @@ -1,362 +0,0 @@ -use clippy_config::msrvs::{self, Msrv}; -use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::macros::HirNode; -use clippy_utils::sugg::Sugg; -use clippy_utils::{is_trait_method, local_is_initialized, path_to_local}; -use rustc_errors::Applicability; -use rustc_hir::{self as hir, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, Instance, Mutability}; -use rustc_session::impl_lint_pass; -use rustc_span::def_id::DefId; -use rustc_span::symbol::sym; -use rustc_span::{ExpnKind, SyntaxContext}; - -declare_clippy_lint! { - /// ### What it does - /// Checks for code like `foo = bar.clone();` - /// - /// ### Why is this bad? - /// Custom `Clone::clone_from()` or `ToOwned::clone_into` implementations allow the objects - /// to share resources and therefore avoid allocations. - /// - /// ### Example - /// ```rust - /// struct Thing; - /// - /// impl Clone for Thing { - /// fn clone(&self) -> Self { todo!() } - /// fn clone_from(&mut self, other: &Self) { todo!() } - /// } - /// - /// pub fn assign_to_ref(a: &mut Thing, b: Thing) { - /// *a = b.clone(); - /// } - /// ``` - /// Use instead: - /// ```rust - /// struct Thing; - /// - /// impl Clone for Thing { - /// fn clone(&self) -> Self { todo!() } - /// fn clone_from(&mut self, other: &Self) { todo!() } - /// } - /// - /// pub fn assign_to_ref(a: &mut Thing, b: Thing) { - /// a.clone_from(&b); - /// } - /// ``` - #[clippy::version = "1.78.0"] - pub ASSIGNING_CLONES, - pedantic, - "assigning the result of cloning may be inefficient" -} - -pub struct AssigningClones { - msrv: Msrv, -} - -impl AssigningClones { - #[must_use] - pub fn new(msrv: Msrv) -> Self { - Self { msrv } - } -} - -impl_lint_pass!(AssigningClones => [ASSIGNING_CLONES]); - -impl<'tcx> LateLintPass<'tcx> for AssigningClones { - fn check_expr(&mut self, cx: &LateContext<'tcx>, assign_expr: &'tcx Expr<'_>) { - // Do not fire the lint in macros - let ctxt = assign_expr.span().ctxt(); - let expn_data = ctxt.outer_expn_data(); - match expn_data.kind { - ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) | ExpnKind::Macro(..) => return, - ExpnKind::Root => {}, - } - - let ExprKind::Assign(lhs, rhs, _span) = assign_expr.kind else { - return; - }; - - let Some(call) = extract_call(cx, rhs) else { - return; - }; - - if is_ok_to_suggest(cx, lhs, &call, &self.msrv) { - suggest(cx, ctxt, assign_expr, lhs, &call); - } - } - - extract_msrv_attr!(LateContext); -} - -// Try to resolve the call to `Clone::clone` or `ToOwned::to_owned`. -fn extract_call<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option> { - let fn_def_id = clippy_utils::fn_def_id(cx, expr)?; - - // Fast paths to only check method calls without arguments or function calls with a single argument - let (target, kind, resolved_method) = match expr.kind { - ExprKind::MethodCall(path, receiver, [], _span) => { - let args = cx.typeck_results().node_args(expr.hir_id); - - // If we could not resolve the method, don't apply the lint - let Ok(Some(resolved_method)) = Instance::resolve(cx.tcx, cx.param_env, fn_def_id, args) else { - return None; - }; - if is_trait_method(cx, expr, sym::Clone) && path.ident.name == sym::clone { - (TargetTrait::Clone, CallKind::MethodCall { receiver }, resolved_method) - } else if is_trait_method(cx, expr, sym::ToOwned) && path.ident.name.as_str() == "to_owned" { - (TargetTrait::ToOwned, CallKind::MethodCall { receiver }, resolved_method) - } else { - return None; - } - }, - ExprKind::Call(function, [arg]) => { - let kind = cx.typeck_results().node_type(function.hir_id).kind(); - - // If we could not resolve the method, don't apply the lint - let Ok(Some(resolved_method)) = (match kind { - ty::FnDef(_, args) => Instance::resolve(cx.tcx, cx.param_env, fn_def_id, args), - _ => Ok(None), - }) else { - return None; - }; - if cx.tcx.is_diagnostic_item(sym::to_owned_method, fn_def_id) { - ( - TargetTrait::ToOwned, - CallKind::FunctionCall { self_arg: arg }, - resolved_method, - ) - } else if let Some(trait_did) = cx.tcx.trait_of_item(fn_def_id) - && cx.tcx.is_diagnostic_item(sym::Clone, trait_did) - { - ( - TargetTrait::Clone, - CallKind::FunctionCall { self_arg: arg }, - resolved_method, - ) - } else { - return None; - } - }, - _ => return None, - }; - - Some(CallCandidate { - target, - kind, - method_def_id: resolved_method.def_id(), - }) -} - -// Return true if we find that the called method has a custom implementation and isn't derived or -// provided by default by the corresponding trait. -fn is_ok_to_suggest<'tcx>(cx: &LateContext<'tcx>, lhs: &Expr<'tcx>, call: &CallCandidate<'tcx>, msrv: &Msrv) -> bool { - // For calls to .to_owned we suggest using .clone_into(), which was only stablilized in 1.63. - // If the current MSRV is below that, don't suggest the lint. - if !msrv.meets(msrvs::CLONE_INTO) && matches!(call.target, TargetTrait::ToOwned) { - return false; - } - - // If the left-hand side is a local variable, it might be uninitialized at this point. - // In that case we do not want to suggest the lint. - if let Some(local) = path_to_local(lhs) { - // TODO: This check currently bails if the local variable has no initializer. - // That is overly conservative - the lint should fire even if there was no initializer, - // but the variable has been initialized before `lhs` was evaluated. - if !local_is_initialized(cx, local) { - return false; - } - } - - let Some(impl_block) = cx.tcx.impl_of_method(call.method_def_id) else { - return false; - }; - - // If the method implementation comes from #[derive(Clone)], then don't suggest the lint. - // Automatically generated Clone impls do not currently override `clone_from`. - // See e.g. https://github.com/rust-lang/rust/pull/98445#issuecomment-1190681305 for more details. - if cx.tcx.is_builtin_derived(impl_block) { - return false; - } - - // If the call expression is inside an impl block that contains the method invoked by the - // call expression, we bail out to avoid suggesting something that could result in endless - // recursion. - if let Some(local_block_id) = impl_block.as_local() - && let Some(block) = cx.tcx.hir_node_by_def_id(local_block_id).as_owner() - { - let impl_block_owner = block.def_id(); - if cx - .tcx - .hir() - .parent_id_iter(lhs.hir_id) - .any(|parent| parent.owner == impl_block_owner) - { - return false; - } - } - - // Find the function for which we want to check that it is implemented. - let provided_fn = match call.target { - TargetTrait::Clone => cx.tcx.get_diagnostic_item(sym::Clone).and_then(|clone| { - cx.tcx - .provided_trait_methods(clone) - .find(|item| item.name == sym::clone_from) - }), - TargetTrait::ToOwned => cx.tcx.get_diagnostic_item(sym::ToOwned).and_then(|to_owned| { - cx.tcx - .provided_trait_methods(to_owned) - .find(|item| item.name.as_str() == "clone_into") - }), - }; - let Some(provided_fn) = provided_fn else { - return false; - }; - - // Now take a look if the impl block defines an implementation for the method that we're interested - // in. If not, then we're using a default implementation, which is not interesting, so we will - // not suggest the lint. - let implemented_fns = cx.tcx.impl_item_implementor_ids(impl_block); - implemented_fns.contains_key(&provided_fn.def_id) -} - -fn suggest<'tcx>( - cx: &LateContext<'tcx>, - ctxt: SyntaxContext, - assign_expr: &Expr<'tcx>, - lhs: &Expr<'tcx>, - call: &CallCandidate<'tcx>, -) { - span_lint_and_then(cx, ASSIGNING_CLONES, assign_expr.span, call.message(), |diag| { - let mut applicability = Applicability::Unspecified; - - diag.span_suggestion( - assign_expr.span, - call.suggestion_msg(), - call.suggested_replacement(cx, ctxt, lhs, &mut applicability), - applicability, - ); - }); -} - -#[derive(Copy, Clone, Debug)] -enum CallKind<'tcx> { - MethodCall { receiver: &'tcx Expr<'tcx> }, - FunctionCall { self_arg: &'tcx Expr<'tcx> }, -} - -#[derive(Copy, Clone, Debug)] -enum TargetTrait { - Clone, - ToOwned, -} - -#[derive(Debug)] -struct CallCandidate<'tcx> { - target: TargetTrait, - kind: CallKind<'tcx>, - // DefId of the called method from an impl block that implements the target trait - method_def_id: DefId, -} - -impl<'tcx> CallCandidate<'tcx> { - #[inline] - fn message(&self) -> &'static str { - match self.target { - TargetTrait::Clone => "assigning the result of `Clone::clone()` may be inefficient", - TargetTrait::ToOwned => "assigning the result of `ToOwned::to_owned()` may be inefficient", - } - } - - #[inline] - fn suggestion_msg(&self) -> &'static str { - match self.target { - TargetTrait::Clone => "use `clone_from()`", - TargetTrait::ToOwned => "use `clone_into()`", - } - } - - fn suggested_replacement( - &self, - cx: &LateContext<'tcx>, - ctxt: SyntaxContext, - lhs: &Expr<'tcx>, - applicability: &mut Applicability, - ) -> String { - match self.target { - TargetTrait::Clone => { - match self.kind { - CallKind::MethodCall { receiver } => { - let receiver_sugg = if let ExprKind::Unary(hir::UnOp::Deref, ref_expr) = lhs.kind { - // `*lhs = self_expr.clone();` -> `lhs.clone_from(self_expr)` - Sugg::hir_with_applicability(cx, ref_expr, "_", applicability) - } else { - // `lhs = self_expr.clone();` -> `lhs.clone_from(self_expr)` - Sugg::hir_with_applicability(cx, lhs, "_", applicability) - } - .maybe_par(); - - // Determine whether we need to reference the argument to clone_from(). - let clone_receiver_type = cx.typeck_results().expr_ty(receiver); - let clone_receiver_adj_type = cx.typeck_results().expr_ty_adjusted(receiver); - let mut arg_sugg = Sugg::hir_with_context(cx, receiver, ctxt, "_", applicability); - if clone_receiver_type != clone_receiver_adj_type { - // The receiver may have been a value type, so we need to add an `&` to - // be sure the argument to clone_from will be a reference. - arg_sugg = arg_sugg.addr(); - }; - - format!("{receiver_sugg}.clone_from({arg_sugg})") - }, - CallKind::FunctionCall { self_arg, .. } => { - let self_sugg = if let ExprKind::Unary(hir::UnOp::Deref, ref_expr) = lhs.kind { - // `*lhs = Clone::clone(self_expr);` -> `Clone::clone_from(lhs, self_expr)` - Sugg::hir_with_applicability(cx, ref_expr, "_", applicability) - } else { - // `lhs = Clone::clone(self_expr);` -> `Clone::clone_from(&mut lhs, self_expr)` - Sugg::hir_with_applicability(cx, lhs, "_", applicability).mut_addr() - }; - // The RHS had to be exactly correct before the call, there is no auto-deref for function calls. - let rhs_sugg = Sugg::hir_with_context(cx, self_arg, ctxt, "_", applicability); - - format!("Clone::clone_from({self_sugg}, {rhs_sugg})") - }, - } - }, - TargetTrait::ToOwned => { - let rhs_sugg = if let ExprKind::Unary(hir::UnOp::Deref, ref_expr) = lhs.kind { - // `*lhs = rhs.to_owned()` -> `rhs.clone_into(lhs)` - // `*lhs = ToOwned::to_owned(rhs)` -> `ToOwned::clone_into(rhs, lhs)` - let sugg = Sugg::hir_with_applicability(cx, ref_expr, "_", applicability).maybe_par(); - let inner_type = cx.typeck_results().expr_ty(ref_expr); - // If after unwrapping the dereference, the type is not a mutable reference, we add &mut to make it - // deref to a mutable reference. - if matches!(inner_type.kind(), ty::Ref(_, _, Mutability::Mut)) { - sugg - } else { - sugg.mut_addr() - } - } else { - // `lhs = rhs.to_owned()` -> `rhs.clone_into(&mut lhs)` - // `lhs = ToOwned::to_owned(rhs)` -> `ToOwned::clone_into(rhs, &mut lhs)` - Sugg::hir_with_applicability(cx, lhs, "_", applicability) - .maybe_par() - .mut_addr() - }; - - match self.kind { - CallKind::MethodCall { receiver } => { - let receiver_sugg = Sugg::hir_with_context(cx, receiver, ctxt, "_", applicability); - format!("{receiver_sugg}.clone_into({rhs_sugg})") - }, - CallKind::FunctionCall { self_arg, .. } => { - let self_sugg = Sugg::hir_with_context(cx, self_arg, ctxt, "_", applicability); - format!("ToOwned::clone_into({self_sugg}, {rhs_sugg})") - }, - } - }, - } - } -} diff --git a/clippy_lints/src/async_yields_async.rs b/clippy_lints/src/async_yields_async.rs deleted file mode 100644 index eeaa3de3725f..000000000000 --- a/clippy_lints/src/async_yields_async.rs +++ /dev/null @@ -1,117 +0,0 @@ -use clippy_utils::diagnostics::span_lint_hir_and_then; -use clippy_utils::source::snippet; -use clippy_utils::ty::implements_trait; -use rustc_errors::Applicability; -use rustc_hir::{Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, QPath}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::declare_lint_pass; - -declare_clippy_lint! { - /// ### What it does - /// Checks for async blocks that yield values of types - /// that can themselves be awaited. - /// - /// ### Why is this bad? - /// An await is likely missing. - /// - /// ### Example - /// ```no_run - /// async fn foo() {} - /// - /// fn bar() { - /// let x = async { - /// foo() - /// }; - /// } - /// ``` - /// - /// Use instead: - /// ```no_run - /// async fn foo() {} - /// - /// fn bar() { - /// let x = async { - /// foo().await - /// }; - /// } - /// ``` - #[clippy::version = "1.48.0"] - pub ASYNC_YIELDS_ASYNC, - correctness, - "async blocks that return a type that can be awaited" -} - -declare_lint_pass!(AsyncYieldsAsync => [ASYNC_YIELDS_ASYNC]); - -impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - let ExprKind::Closure(Closure { - kind: ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, kind)), - body: body_id, - .. - }) = expr.kind - else { - return; - }; - - let body_expr = match kind { - CoroutineSource::Fn => { - // For functions, with explicitly defined types, don't warn. - // XXXkhuey maybe we should? - return; - }, - CoroutineSource::Block => cx.tcx.hir().body(*body_id).value, - CoroutineSource::Closure => { - // Like `async fn`, async closures are wrapped in an additional block - // to move all of the closure's arguments into the future. - - let async_closure_body = cx.tcx.hir().body(*body_id).value; - let ExprKind::Block(block, _) = async_closure_body.kind else { - return; - }; - let Some(block_expr) = block.expr else { - return; - }; - let ExprKind::DropTemps(body_expr) = block_expr.kind else { - return; - }; - body_expr - }, - }; - - let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait() else { - return; - }; - - let typeck_results = cx.tcx.typeck_body(*body_id); - let expr_ty = typeck_results.expr_ty(body_expr); - - if implements_trait(cx, expr_ty, future_trait_def_id, &[]) { - let return_expr_span = match &body_expr.kind { - // XXXkhuey there has to be a better way. - ExprKind::Block(block, _) => block.expr.map(|e| e.span), - ExprKind::Path(QPath::Resolved(_, path)) => Some(path.span), - _ => None, - }; - if let Some(return_expr_span) = return_expr_span { - span_lint_hir_and_then( - cx, - ASYNC_YIELDS_ASYNC, - body_expr.hir_id, - return_expr_span, - "an async construct yields a type which is itself awaitable", - |db| { - db.span_label(body_expr.span, "outer async construct"); - db.span_label(return_expr_span, "awaitable value not awaited"); - db.span_suggestion( - return_expr_span, - "consider awaiting this value", - format!("{}.await", snippet(cx, return_expr_span, "..")), - Applicability::MaybeIncorrect, - ); - }, - ); - } - } - } -} diff --git a/clippy_lints/src/attrs/allow_attributes_without_reason.rs b/clippy_lints/src/attrs/allow_attributes_without_reason.rs deleted file mode 100644 index 4a22e17463fc..000000000000 --- a/clippy_lints/src/attrs/allow_attributes_without_reason.rs +++ /dev/null @@ -1,37 +0,0 @@ -use super::{Attribute, ALLOW_ATTRIBUTES_WITHOUT_REASON}; -use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::is_from_proc_macro; -use rustc_ast::{MetaItemKind, NestedMetaItem}; -use rustc_lint::{LateContext, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_span::sym; -use rustc_span::symbol::Symbol; - -pub(super) fn check<'cx>(cx: &LateContext<'cx>, name: Symbol, items: &[NestedMetaItem], attr: &'cx Attribute) { - // Check for the feature - if !cx.tcx.features().lint_reasons { - return; - } - - // Check if the reason is present - if let Some(item) = items.last().and_then(NestedMetaItem::meta_item) - && let MetaItemKind::NameValue(_) = &item.kind - && item.path == sym::reason - { - return; - } - - // Check if the attribute is in an external macro and therefore out of the developer's control - if in_external_macro(cx.sess(), attr.span) || is_from_proc_macro(cx, &attr) { - return; - } - - span_lint_and_help( - cx, - ALLOW_ATTRIBUTES_WITHOUT_REASON, - attr.span, - format!("`{}` attribute without specifying a reason", name.as_str()), - None, - "try adding a reason at the end with `, reason = \"..\"`", - ); -} diff --git a/clippy_lints/src/attrs/blanket_clippy_restriction_lints.rs b/clippy_lints/src/attrs/blanket_clippy_restriction_lints.rs deleted file mode 100644 index 9b08fd6d654a..000000000000 --- a/clippy_lints/src/attrs/blanket_clippy_restriction_lints.rs +++ /dev/null @@ -1,44 +0,0 @@ -use super::utils::extract_clippy_lint; -use super::BLANKET_CLIPPY_RESTRICTION_LINTS; -use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then}; -use rustc_ast::NestedMetaItem; -use rustc_lint::{LateContext, Level, LintContext}; -use rustc_span::symbol::Symbol; -use rustc_span::{sym, DUMMY_SP}; - -pub(super) fn check(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem]) { - for lint in items { - if let Some(lint_name) = extract_clippy_lint(lint) { - if lint_name.as_str() == "restriction" && name != sym::allow { - span_lint_and_help( - cx, - BLANKET_CLIPPY_RESTRICTION_LINTS, - lint.span(), - "`clippy::restriction` is not meant to be enabled as a group", - None, - "enable the restriction lints you need individually", - ); - } - } - } -} - -pub(super) fn check_command_line(cx: &LateContext<'_>) { - for (name, level) in &cx.sess().opts.lint_opts { - if name == "clippy::restriction" && *level > Level::Allow { - span_lint_and_then( - cx, - BLANKET_CLIPPY_RESTRICTION_LINTS, - DUMMY_SP, - "`clippy::restriction` is not meant to be enabled as a group", - |diag| { - diag.note(format!( - "because of the command line `--{} clippy::restriction`", - level.as_str() - )); - diag.help("enable the restriction lints you need individually"); - }, - ); - } - } -} diff --git a/clippy_lints/src/attrs/deprecated_cfg_attr.rs b/clippy_lints/src/attrs/deprecated_cfg_attr.rs deleted file mode 100644 index e872ab6b4b5f..000000000000 --- a/clippy_lints/src/attrs/deprecated_cfg_attr.rs +++ /dev/null @@ -1,87 +0,0 @@ -use super::{unnecessary_clippy_cfg, Attribute, DEPRECATED_CFG_ATTR, DEPRECATED_CLIPPY_CFG_ATTR}; -use clippy_config::msrvs::{self, Msrv}; -use clippy_utils::diagnostics::span_lint_and_sugg; -use rustc_ast::AttrStyle; -use rustc_errors::Applicability; -use rustc_lint::EarlyContext; -use rustc_span::sym; - -pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute, msrv: &Msrv) { - // check cfg_attr - if attr.has_name(sym::cfg_attr) - && let Some(items) = attr.meta_item_list() - && items.len() == 2 - && let Some(feature_item) = items[0].meta_item() - { - // check for `rustfmt` - if feature_item.has_name(sym::rustfmt) - && msrv.meets(msrvs::TOOL_ATTRIBUTES) - // check for `rustfmt_skip` and `rustfmt::skip` - && let Some(skip_item) = &items[1].meta_item() - && (skip_item.has_name(sym!(rustfmt_skip)) - || skip_item - .path - .segments - .last() - .expect("empty path in attribute") - .ident - .name - == sym::skip) - // Only lint outer attributes, because custom inner attributes are unstable - // Tracking issue: https://github.com/rust-lang/rust/issues/54726 - && attr.style == AttrStyle::Outer - { - span_lint_and_sugg( - cx, - DEPRECATED_CFG_ATTR, - attr.span, - "`cfg_attr` is deprecated for rustfmt and got replaced by tool attributes", - "use", - "#[rustfmt::skip]".to_string(), - Applicability::MachineApplicable, - ); - } else { - check_deprecated_cfg_recursively(cx, feature_item); - if let Some(behind_cfg_attr) = items[1].meta_item() { - unnecessary_clippy_cfg::check(cx, feature_item, behind_cfg_attr, attr); - } - } - } -} - -pub(super) fn check_clippy(cx: &EarlyContext<'_>, attr: &Attribute) { - if attr.has_name(sym::cfg) - && let Some(list) = attr.meta_item_list() - { - for item in list.iter().filter_map(|item| item.meta_item()) { - check_deprecated_cfg_recursively(cx, item); - } - } -} - -fn check_deprecated_cfg_recursively(cx: &EarlyContext<'_>, attr: &rustc_ast::MetaItem) { - if let Some(ident) = attr.ident() { - if ["any", "all", "not"].contains(&ident.name.as_str()) { - let Some(list) = attr.meta_item_list() else { return }; - for item in list.iter().filter_map(|item| item.meta_item()) { - check_deprecated_cfg_recursively(cx, item); - } - } else { - check_cargo_clippy_attr(cx, attr); - } - } -} - -fn check_cargo_clippy_attr(cx: &EarlyContext<'_>, item: &rustc_ast::MetaItem) { - if item.has_name(sym::feature) && item.value_str().is_some_and(|v| v.as_str() == "cargo-clippy") { - span_lint_and_sugg( - cx, - DEPRECATED_CLIPPY_CFG_ATTR, - item.span, - "`feature = \"cargo-clippy\"` was replaced by `clippy`", - "replace with", - "clippy".to_string(), - Applicability::MachineApplicable, - ); - } -} diff --git a/clippy_lints/src/attrs/deprecated_semver.rs b/clippy_lints/src/attrs/deprecated_semver.rs deleted file mode 100644 index 1898c145c76a..000000000000 --- a/clippy_lints/src/attrs/deprecated_semver.rs +++ /dev/null @@ -1,20 +0,0 @@ -use super::DEPRECATED_SEMVER; -use clippy_utils::diagnostics::span_lint; -use rustc_ast::{LitKind, MetaItemLit}; -use rustc_lint::LateContext; -use rustc_span::Span; -use semver::Version; - -pub(super) fn check(cx: &LateContext<'_>, span: Span, lit: &MetaItemLit) { - if let LitKind::Str(is, _) = lit.kind { - if is.as_str() == "TBD" || Version::parse(is.as_str()).is_ok() { - return; - } - } - span_lint( - cx, - DEPRECATED_SEMVER, - span, - "the since field must contain a semver-compliant version", - ); -} diff --git a/clippy_lints/src/attrs/duplicated_attributes.rs b/clippy_lints/src/attrs/duplicated_attributes.rs deleted file mode 100644 index 40a1c4e28842..000000000000 --- a/clippy_lints/src/attrs/duplicated_attributes.rs +++ /dev/null @@ -1,76 +0,0 @@ -use super::DUPLICATED_ATTRIBUTES; -use clippy_utils::diagnostics::span_lint_and_then; -use rustc_ast::{Attribute, MetaItem}; -use rustc_data_structures::fx::FxHashMap; -use rustc_lint::LateContext; -use rustc_span::{sym, Span}; -use std::collections::hash_map::Entry; - -fn emit_if_duplicated( - cx: &LateContext<'_>, - attr: &MetaItem, - attr_paths: &mut FxHashMap, - complete_path: String, -) { - match attr_paths.entry(complete_path) { - Entry::Vacant(v) => { - v.insert(attr.span); - }, - Entry::Occupied(o) => { - span_lint_and_then(cx, DUPLICATED_ATTRIBUTES, attr.span, "duplicated attribute", |diag| { - diag.span_note(*o.get(), "first defined here"); - diag.span_help(attr.span, "remove this attribute"); - }); - }, - } -} - -fn check_duplicated_attr( - cx: &LateContext<'_>, - attr: &MetaItem, - attr_paths: &mut FxHashMap, - parent: &mut Vec, -) { - if attr.span.from_expansion() { - return; - } - let Some(ident) = attr.ident() else { return }; - let name = ident.name; - if name == sym::doc || name == sym::cfg_attr || name == sym::rustc_on_unimplemented { - // FIXME: Would be nice to handle `cfg_attr` as well. Only problem is to check that cfg - // conditions are the same. - // `#[rustc_on_unimplemented]` contains duplicated subattributes, that's expected. - return; - } - if let Some(direct_parent) = parent.last() - && ["cfg", "cfg_attr"].contains(&direct_parent.as_str()) - && [sym::all, sym::not, sym::any].contains(&name) - { - // FIXME: We don't correctly check `cfg`s for now, so if it's more complex than just a one - // level `cfg`, we leave. - return; - } - if let Some(value) = attr.value_str() { - emit_if_duplicated(cx, attr, attr_paths, format!("{}:{name}={value}", parent.join(":"))); - } else if let Some(sub_attrs) = attr.meta_item_list() { - parent.push(name.as_str().to_string()); - for sub_attr in sub_attrs { - if let Some(meta) = sub_attr.meta_item() { - check_duplicated_attr(cx, meta, attr_paths, parent); - } - } - parent.pop(); - } else { - emit_if_duplicated(cx, attr, attr_paths, format!("{}:{name}", parent.join(":"))); - } -} - -pub fn check(cx: &LateContext<'_>, attrs: &[Attribute]) { - let mut attr_paths = FxHashMap::default(); - - for attr in attrs { - if let Some(meta) = attr.meta() { - check_duplicated_attr(cx, &meta, &mut attr_paths, &mut Vec::new()); - } - } -} diff --git a/clippy_lints/src/attrs/empty_line_after.rs b/clippy_lints/src/attrs/empty_line_after.rs deleted file mode 100644 index ca43e76ac578..000000000000 --- a/clippy_lints/src/attrs/empty_line_after.rs +++ /dev/null @@ -1,52 +0,0 @@ -use super::{EMPTY_LINE_AFTER_DOC_COMMENTS, EMPTY_LINE_AFTER_OUTER_ATTR}; -use clippy_utils::diagnostics::span_lint; -use clippy_utils::source::{is_present_in_source, snippet_opt, without_block_comments}; -use rustc_ast::{AttrKind, AttrStyle}; -use rustc_lint::EarlyContext; -use rustc_span::Span; - -/// Check for empty lines after outer attributes. -/// -/// Attributes and documentation comments are both considered outer attributes -/// by the AST. However, the average user likely considers them to be different. -/// Checking for empty lines after each of these attributes is split into two different -/// lints but can share the same logic. -pub(super) fn check(cx: &EarlyContext<'_>, item: &rustc_ast::Item) { - let mut iter = item.attrs.iter().peekable(); - while let Some(attr) = iter.next() { - if (matches!(attr.kind, AttrKind::Normal(..)) || matches!(attr.kind, AttrKind::DocComment(..))) - && 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_next_attr_or_item = Span::new( - attr.span.hi(), - iter.peek().map_or(item.span.lo(), |next_attr| next_attr.span.lo()), - item.span.ctxt(), - item.span.parent(), - ); - - if let Some(snippet) = snippet_opt(cx, end_of_attr_to_next_attr_or_item) { - let lines = snippet.split('\n').collect::>(); - let lines = without_block_comments(lines); - - if lines.iter().filter(|l| l.trim().is_empty()).count() > 2 { - let (lint_msg, lint_type) = match attr.kind { - AttrKind::DocComment(..) => ( - "found an empty line after a doc comment. \ - Perhaps you need to use `//!` to make a comment on a module, remove the empty line, or make a regular comment with `//`?", - EMPTY_LINE_AFTER_DOC_COMMENTS, - ), - AttrKind::Normal(..) => ( - "found an empty line after an outer attribute. \ - Perhaps you forgot to add a `!` to make it an inner attribute?", - EMPTY_LINE_AFTER_OUTER_ATTR, - ), - }; - - span_lint(cx, lint_type, begin_of_attr_to_item, lint_msg); - } - } - } - } -} diff --git a/clippy_lints/src/attrs/inline_always.rs b/clippy_lints/src/attrs/inline_always.rs deleted file mode 100644 index 3b5b80ffefaf..000000000000 --- a/clippy_lints/src/attrs/inline_always.rs +++ /dev/null @@ -1,29 +0,0 @@ -use super::utils::is_word; -use super::INLINE_ALWAYS; -use clippy_utils::diagnostics::span_lint; -use rustc_ast::Attribute; -use rustc_lint::LateContext; -use rustc_span::symbol::Symbol; -use rustc_span::{sym, Span}; - -pub(super) fn check(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Attribute]) { - if span.from_expansion() { - return; - } - - for attr in attrs { - if let Some(values) = attr.meta_item_list() { - if values.len() != 1 || !attr.has_name(sym::inline) { - continue; - } - if is_word(&values[0], sym::always) { - span_lint( - cx, - INLINE_ALWAYS, - attr.span, - format!("you have declared `#[inline(always)]` on `{name}`. This is usually a bad idea"), - ); - } - } - } -} diff --git a/clippy_lints/src/attrs/maybe_misused_cfg.rs b/clippy_lints/src/attrs/maybe_misused_cfg.rs deleted file mode 100644 index e6b2e835be86..000000000000 --- a/clippy_lints/src/attrs/maybe_misused_cfg.rs +++ /dev/null @@ -1,51 +0,0 @@ -use super::{Attribute, MAYBE_MISUSED_CFG}; -use clippy_utils::diagnostics::span_lint_and_sugg; -use rustc_ast::{MetaItemKind, NestedMetaItem}; -use rustc_errors::Applicability; -use rustc_lint::EarlyContext; -use rustc_span::sym; - -pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute) { - if attr.has_name(sym::cfg) - && let Some(items) = attr.meta_item_list() - { - check_nested_misused_cfg(cx, &items); - } -} - -fn check_nested_misused_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) { - for item in items { - if let NestedMetaItem::MetaItem(meta) = item { - if let Some(ident) = meta.ident() - && ident.name.as_str() == "features" - && let Some(val) = meta.value_str() - { - span_lint_and_sugg( - cx, - MAYBE_MISUSED_CFG, - meta.span, - "'feature' may be misspelled as 'features'", - "did you mean", - format!("feature = \"{val}\""), - Applicability::MaybeIncorrect, - ); - } - if let MetaItemKind::List(list) = &meta.kind { - check_nested_misused_cfg(cx, list); - // If this is not a list, then we check for `cfg(test)`. - } else if let Some(ident) = meta.ident() - && matches!(ident.name.as_str(), "tests" | "Test") - { - span_lint_and_sugg( - cx, - MAYBE_MISUSED_CFG, - meta.span, - format!("'test' may be misspelled as '{}'", ident.name.as_str()), - "did you mean", - "test".to_string(), - Applicability::MaybeIncorrect, - ); - } - } - } -} diff --git a/clippy_lints/src/attrs/mismatched_target_os.rs b/clippy_lints/src/attrs/mismatched_target_os.rs deleted file mode 100644 index b1cc0a763c5e..000000000000 --- a/clippy_lints/src/attrs/mismatched_target_os.rs +++ /dev/null @@ -1,90 +0,0 @@ -use super::{Attribute, MISMATCHED_TARGET_OS}; -use clippy_utils::diagnostics::span_lint_and_then; -use rustc_ast::{MetaItemKind, NestedMetaItem}; -use rustc_errors::Applicability; -use rustc_lint::EarlyContext; -use rustc_span::{sym, Span}; - -static UNIX_SYSTEMS: &[&str] = &[ - "android", - "dragonfly", - "emscripten", - "freebsd", - "fuchsia", - "haiku", - "illumos", - "ios", - "l4re", - "linux", - "macos", - "netbsd", - "openbsd", - "redox", - "solaris", - "vxworks", -]; - -// NOTE: windows is excluded from the list because it's also a valid target family. -static NON_UNIX_SYSTEMS: &[&str] = &["hermit", "none", "wasi"]; - -pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute) { - fn find_os(name: &str) -> Option<&'static str> { - UNIX_SYSTEMS - .iter() - .chain(NON_UNIX_SYSTEMS.iter()) - .find(|&&os| os == name) - .copied() - } - - fn is_unix(name: &str) -> bool { - UNIX_SYSTEMS.iter().any(|&os| os == name) - } - - fn find_mismatched_target_os(items: &[NestedMetaItem]) -> Vec<(&str, Span)> { - let mut mismatched = Vec::new(); - - for item in items { - if let NestedMetaItem::MetaItem(meta) = item { - match &meta.kind { - MetaItemKind::List(list) => { - mismatched.extend(find_mismatched_target_os(list)); - }, - MetaItemKind::Word => { - if let Some(ident) = meta.ident() - && let Some(os) = find_os(ident.name.as_str()) - { - mismatched.push((os, ident.span)); - } - }, - MetaItemKind::NameValue(..) => {}, - } - } - } - - mismatched - } - - if attr.has_name(sym::cfg) - && let Some(list) = attr.meta_item_list() - && let mismatched = find_mismatched_target_os(&list) - && !mismatched.is_empty() - { - let mess = "operating system used in target family position"; - - span_lint_and_then(cx, MISMATCHED_TARGET_OS, attr.span, mess, |diag| { - // Avoid showing the unix suggestion multiple times in case - // we have more than one mismatch for unix-like systems - let mut unix_suggested = false; - - for (os, span) in mismatched { - let sugg = format!("target_os = \"{os}\""); - diag.span_suggestion(span, "try", sugg, Applicability::MaybeIncorrect); - - if !unix_suggested && is_unix(os) { - diag.help("did you mean `unix`?"); - unix_suggested = true; - } - } - }); - } -} diff --git a/clippy_lints/src/attrs/mixed_attributes_style.rs b/clippy_lints/src/attrs/mixed_attributes_style.rs deleted file mode 100644 index 5d2ea36b366c..000000000000 --- a/clippy_lints/src/attrs/mixed_attributes_style.rs +++ /dev/null @@ -1,85 +0,0 @@ -use super::MIXED_ATTRIBUTES_STYLE; -use clippy_utils::diagnostics::span_lint; -use rustc_ast::{AttrKind, AttrStyle, Attribute}; -use rustc_data_structures::fx::FxHashSet; -use rustc_data_structures::sync::Lrc; -use rustc_lint::{LateContext, LintContext}; -use rustc_span::source_map::SourceMap; -use rustc_span::{SourceFile, Span, Symbol}; - -#[derive(Hash, PartialEq, Eq)] -enum SimpleAttrKind { - Doc, - /// A normal attribute, with its name symbols. - Normal(Vec), -} - -impl From<&AttrKind> for SimpleAttrKind { - fn from(value: &AttrKind) -> Self { - match value { - AttrKind::Normal(attr) => { - let path_symbols = attr - .item - .path - .segments - .iter() - .map(|seg| seg.ident.name) - .collect::>(); - Self::Normal(path_symbols) - }, - AttrKind::DocComment(..) => Self::Doc, - } - } -} - -pub(super) fn check(cx: &LateContext<'_>, item_span: Span, attrs: &[Attribute]) { - let mut inner_attr_kind: FxHashSet = FxHashSet::default(); - let mut outer_attr_kind: FxHashSet = FxHashSet::default(); - - let source_map = cx.sess().source_map(); - let item_src = source_map.lookup_source_file(item_span.lo()); - - for attr in attrs { - if attr.span.from_expansion() || !attr_in_same_src_as_item(source_map, &item_src, attr.span) { - continue; - } - - let kind: SimpleAttrKind = (&attr.kind).into(); - match attr.style { - AttrStyle::Inner => { - if outer_attr_kind.contains(&kind) { - lint_mixed_attrs(cx, attrs); - return; - } - inner_attr_kind.insert(kind); - }, - AttrStyle::Outer => { - if inner_attr_kind.contains(&kind) { - lint_mixed_attrs(cx, attrs); - return; - } - outer_attr_kind.insert(kind); - }, - }; - } -} - -fn lint_mixed_attrs(cx: &LateContext<'_>, attrs: &[Attribute]) { - let mut attrs_iter = attrs.iter().filter(|attr| !attr.span.from_expansion()); - let span = if let (Some(first), Some(last)) = (attrs_iter.next(), attrs_iter.last()) { - first.span.with_hi(last.span.hi()) - } else { - return; - }; - span_lint( - cx, - MIXED_ATTRIBUTES_STYLE, - span, - "item has both inner and outer attributes", - ); -} - -fn attr_in_same_src_as_item(source_map: &SourceMap, item_src: &Lrc, attr_span: Span) -> bool { - let attr_src = source_map.lookup_source_file(attr_span.lo()); - Lrc::ptr_eq(item_src, &attr_src) -} diff --git a/clippy_lints/src/attrs/mod.rs b/clippy_lints/src/attrs/mod.rs deleted file mode 100644 index 39f406077995..000000000000 --- a/clippy_lints/src/attrs/mod.rs +++ /dev/null @@ -1,638 +0,0 @@ -//! checks for attributes - -mod allow_attributes_without_reason; -mod blanket_clippy_restriction_lints; -mod deprecated_cfg_attr; -mod deprecated_semver; -mod duplicated_attributes; -mod empty_line_after; -mod inline_always; -mod maybe_misused_cfg; -mod mismatched_target_os; -mod mixed_attributes_style; -mod non_minimal_cfg; -mod should_panic_without_expect; -mod unnecessary_clippy_cfg; -mod useless_attribute; -mod utils; - -use clippy_config::msrvs::Msrv; -use rustc_ast::{Attribute, MetaItemKind, NestedMetaItem}; -use rustc_hir::{ImplItem, Item, ItemKind, TraitItem}; -use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, impl_lint_pass}; -use rustc_span::sym; -use utils::{is_lint_level, is_relevant_impl, is_relevant_item, is_relevant_trait}; - -declare_clippy_lint! { - /// ### What it does - /// Checks for items annotated with `#[inline(always)]`, - /// unless the annotated function is empty or simply panics. - /// - /// ### Why is this bad? - /// While there are valid uses of this annotation (and once - /// you know when to use it, by all means `allow` this lint), it's a common - /// newbie-mistake to pepper one's code with it. - /// - /// As a rule of thumb, before slapping `#[inline(always)]` on a function, - /// measure if that additional function call really affects your runtime profile - /// sufficiently to make up for the increase in compile time. - /// - /// ### Known problems - /// False positives, big time. This lint is meant to be - /// deactivated by everyone doing serious performance work. This means having - /// done the measurement. - /// - /// ### Example - /// ```ignore - /// #[inline(always)] - /// fn not_quite_hot_code(..) { ... } - /// ``` - #[clippy::version = "pre 1.29.0"] - pub INLINE_ALWAYS, - pedantic, - "use of `#[inline(always)]`" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for `extern crate` and `use` items annotated with - /// lint attributes. - /// - /// This lint permits lint attributes for lints emitted on the items themself. - /// For `use` items these lints are: - /// * ambiguous_glob_reexports - /// * dead_code - /// * deprecated - /// * hidden_glob_reexports - /// * unreachable_pub - /// * unused - /// * unused_braces - /// * unused_import_braces - /// * clippy::disallowed_types - /// * clippy::enum_glob_use - /// * clippy::macro_use_imports - /// * clippy::module_name_repetitions - /// * clippy::redundant_pub_crate - /// * clippy::single_component_path_imports - /// * clippy::unsafe_removed_from_name - /// * clippy::wildcard_imports - /// - /// For `extern crate` items these lints are: - /// * `unused_imports` on items with `#[macro_use]` - /// - /// ### Why is this bad? - /// Lint attributes have no effect on crate imports. Most - /// likely a `!` was forgotten. - /// - /// ### Example - /// ```ignore - /// #[deny(dead_code)] - /// extern crate foo; - /// #[forbid(dead_code)] - /// use foo::bar; - /// ``` - /// - /// Use instead: - /// ```rust,ignore - /// #[allow(unused_imports)] - /// use foo::baz; - /// #[allow(unused_imports)] - /// #[macro_use] - /// extern crate baz; - /// ``` - #[clippy::version = "pre 1.29.0"] - pub USELESS_ATTRIBUTE, - correctness, - "use of lint attributes on `extern crate` items" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for `#[deprecated]` annotations with a `since` - /// field that is not a valid semantic version. Also allows "TBD" to signal - /// future deprecation. - /// - /// ### Why is this bad? - /// For checking the version of the deprecation, it must be - /// a valid semver. Failing that, the contained information is useless. - /// - /// ### Example - /// ```no_run - /// #[deprecated(since = "forever")] - /// fn something_else() { /* ... */ } - /// ``` - #[clippy::version = "pre 1.29.0"] - pub DEPRECATED_SEMVER, - correctness, - "use of `#[deprecated(since = \"x\")]` where x is not semver" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for empty lines after outer attributes - /// - /// ### Why is this bad? - /// Most likely the attribute was meant to be an inner attribute using a '!'. - /// If it was meant to be an outer attribute, then the following item - /// should not be separated by empty lines. - /// - /// ### Known problems - /// Can cause false positives. - /// - /// From the clippy side it's difficult to detect empty lines between an attributes and the - /// following item because empty lines and comments are not part of the AST. The parsing - /// currently works for basic cases but is not perfect. - /// - /// ### Example - /// ```no_run - /// #[allow(dead_code)] - /// - /// fn not_quite_good_code() { } - /// ``` - /// - /// Use instead: - /// ```no_run - /// // Good (as inner attribute) - /// #![allow(dead_code)] - /// - /// fn this_is_fine() { } - /// - /// // or - /// - /// // Good (as outer attribute) - /// #[allow(dead_code)] - /// fn this_is_fine_too() { } - /// ``` - #[clippy::version = "pre 1.29.0"] - pub EMPTY_LINE_AFTER_OUTER_ATTR, - nursery, - "empty line after outer attribute" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for empty lines after documentation comments. - /// - /// ### Why is this bad? - /// The documentation comment was most likely meant to be an inner attribute or regular comment. - /// If it was intended to be a documentation comment, then the empty line should be removed to - /// be more idiomatic. - /// - /// ### Known problems - /// Only detects empty lines immediately following the documentation. If the doc comment is followed - /// by an attribute and then an empty line, this lint will not trigger. Use `empty_line_after_outer_attr` - /// in combination with this lint to detect both cases. - /// - /// Does not detect empty lines after doc attributes (e.g. `#[doc = ""]`). - /// - /// ### Example - /// ```no_run - /// /// Some doc comment with a blank line after it. - /// - /// fn not_quite_good_code() { } - /// ``` - /// - /// Use instead: - /// ```no_run - /// /// Good (no blank line) - /// fn this_is_fine() { } - /// ``` - /// - /// ```no_run - /// // Good (convert to a regular comment) - /// - /// fn this_is_fine_too() { } - /// ``` - /// - /// ```no_run - /// //! Good (convert to a comment on an inner attribute) - /// - /// fn this_is_fine_as_well() { } - /// ``` - #[clippy::version = "1.70.0"] - pub EMPTY_LINE_AFTER_DOC_COMMENTS, - nursery, - "empty line after documentation comments" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for `warn`/`deny`/`forbid` attributes targeting the whole clippy::restriction category. - /// - /// ### Why is this bad? - /// Restriction lints sometimes are in contrast with other lints or even go against idiomatic rust. - /// These lints should only be enabled on a lint-by-lint basis and with careful consideration. - /// - /// ### Example - /// ```no_run - /// #![deny(clippy::restriction)] - /// ``` - /// - /// Use instead: - /// ```no_run - /// #![deny(clippy::as_conversions)] - /// ``` - #[clippy::version = "1.47.0"] - pub BLANKET_CLIPPY_RESTRICTION_LINTS, - suspicious, - "enabling the complete restriction group" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for `#[cfg_attr(rustfmt, rustfmt_skip)]` and suggests to replace it - /// with `#[rustfmt::skip]`. - /// - /// ### Why is this bad? - /// Since tool_attributes ([rust-lang/rust#44690](https://github.com/rust-lang/rust/issues/44690)) - /// are stable now, they should be used instead of the old `cfg_attr(rustfmt)` attributes. - /// - /// ### Known problems - /// This lint doesn't detect crate level inner attributes, because they get - /// processed before the PreExpansionPass lints get executed. See - /// [#3123](https://github.com/rust-lang/rust-clippy/pull/3123#issuecomment-422321765) - /// - /// ### Example - /// ```no_run - /// #[cfg_attr(rustfmt, rustfmt_skip)] - /// fn main() { } - /// ``` - /// - /// Use instead: - /// ```no_run - /// #[rustfmt::skip] - /// fn main() { } - /// ``` - #[clippy::version = "1.32.0"] - pub DEPRECATED_CFG_ATTR, - complexity, - "usage of `cfg_attr(rustfmt)` instead of tool attributes" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for cfg attributes having operating systems used in target family position. - /// - /// ### Why is this bad? - /// The configuration option will not be recognised and the related item will not be included - /// by the conditional compilation engine. - /// - /// ### Example - /// ```no_run - /// #[cfg(linux)] - /// fn conditional() { } - /// ``` - /// - /// Use instead: - /// ```no_run - /// # mod hidden { - /// #[cfg(target_os = "linux")] - /// fn conditional() { } - /// # } - /// - /// // or - /// - /// #[cfg(unix)] - /// fn conditional() { } - /// ``` - /// Check the [Rust Reference](https://doc.rust-lang.org/reference/conditional-compilation.html#target_os) for more details. - #[clippy::version = "1.45.0"] - pub MISMATCHED_TARGET_OS, - correctness, - "usage of `cfg(operating_system)` instead of `cfg(target_os = \"operating_system\")`" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for attributes that allow lints without a reason. - /// - /// (This requires the `lint_reasons` feature) - /// - /// ### Why is this bad? - /// Allowing a lint should always have a reason. This reason should be documented to - /// ensure that others understand the reasoning - /// - /// ### Example - /// ```no_run - /// #![feature(lint_reasons)] - /// - /// #![allow(clippy::some_lint)] - /// ``` - /// - /// Use instead: - /// ```no_run - /// #![feature(lint_reasons)] - /// - /// #![allow(clippy::some_lint, reason = "False positive rust-lang/rust-clippy#1002020")] - /// ``` - #[clippy::version = "1.61.0"] - pub ALLOW_ATTRIBUTES_WITHOUT_REASON, - restriction, - "ensures that all `allow` and `expect` attributes have a reason" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for `#[should_panic]` attributes without specifying the expected panic message. - /// - /// ### Why is this bad? - /// The expected panic message should be specified to ensure that the test is actually - /// panicking with the expected message, and not another unrelated panic. - /// - /// ### Example - /// ```no_run - /// fn random() -> i32 { 0 } - /// - /// #[should_panic] - /// #[test] - /// fn my_test() { - /// let _ = 1 / random(); - /// } - /// ``` - /// - /// Use instead: - /// ```no_run - /// fn random() -> i32 { 0 } - /// - /// #[should_panic = "attempt to divide by zero"] - /// #[test] - /// fn my_test() { - /// let _ = 1 / random(); - /// } - /// ``` - #[clippy::version = "1.74.0"] - pub SHOULD_PANIC_WITHOUT_EXPECT, - pedantic, - "ensures that all `should_panic` attributes specify its expected panic message" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for `any` and `all` combinators in `cfg` with only one condition. - /// - /// ### Why is this bad? - /// If there is only one condition, no need to wrap it into `any` or `all` combinators. - /// - /// ### Example - /// ```no_run - /// #[cfg(any(unix))] - /// pub struct Bar; - /// ``` - /// - /// Use instead: - /// ```no_run - /// #[cfg(unix)] - /// pub struct Bar; - /// ``` - #[clippy::version = "1.71.0"] - pub NON_MINIMAL_CFG, - style, - "ensure that all `cfg(any())` and `cfg(all())` have more than one condition" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for `#[cfg(features = "...")]` and suggests to replace it with - /// `#[cfg(feature = "...")]`. - /// - /// It also checks if `cfg(test)` was misspelled. - /// - /// ### Why is this bad? - /// Misspelling `feature` as `features` or `test` as `tests` can be sometimes hard to spot. It - /// may cause conditional compilation not work quietly. - /// - /// ### Example - /// ```no_run - /// #[cfg(features = "some-feature")] - /// fn conditional() { } - /// #[cfg(tests)] - /// mod tests { } - /// ``` - /// - /// Use instead: - /// ```no_run - /// #[cfg(feature = "some-feature")] - /// fn conditional() { } - /// #[cfg(test)] - /// mod tests { } - /// ``` - #[clippy::version = "1.69.0"] - pub MAYBE_MISUSED_CFG, - suspicious, - "prevent from misusing the wrong attr name" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for `#[cfg_attr(feature = "cargo-clippy", ...)]` and for - /// `#[cfg(feature = "cargo-clippy")]` and suggests to replace it with - /// `#[cfg_attr(clippy, ...)]` or `#[cfg(clippy)]`. - /// - /// ### Why is this bad? - /// This feature has been deprecated for years and shouldn't be used anymore. - /// - /// ### Example - /// ```no_run - /// #[cfg(feature = "cargo-clippy")] - /// struct Bar; - /// ``` - /// - /// Use instead: - /// ```no_run - /// #[cfg(clippy)] - /// struct Bar; - /// ``` - #[clippy::version = "1.78.0"] - pub DEPRECATED_CLIPPY_CFG_ATTR, - suspicious, - "usage of `cfg(feature = \"cargo-clippy\")` instead of `cfg(clippy)`" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for `#[cfg_attr(clippy, allow(clippy::lint))]` - /// and suggests to replace it with `#[allow(clippy::lint)]`. - /// - /// ### Why is this bad? - /// There is no reason to put clippy attributes behind a clippy `cfg` as they are not - /// run by anything else than clippy. - /// - /// ### Example - /// ```no_run - /// #![cfg_attr(clippy, allow(clippy::deprecated_cfg_attr))] - /// ``` - /// - /// Use instead: - /// ```no_run - /// #![allow(clippy::deprecated_cfg_attr)] - /// ``` - #[clippy::version = "1.78.0"] - pub UNNECESSARY_CLIPPY_CFG, - suspicious, - "usage of `cfg_attr(clippy, allow(clippy::lint))` instead of `allow(clippy::lint)`" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for items that have the same kind of attributes with mixed styles (inner/outer). - /// - /// ### Why is this bad? - /// Having both style of said attributes makes it more complicated to read code. - /// - /// ### Known problems - /// This lint currently has false-negatives when mixing same attributes - /// but they have different path symbols, for example: - /// ```ignore - /// #[custom_attribute] - /// pub fn foo() { - /// #![my_crate::custom_attribute] - /// } - /// ``` - /// - /// ### Example - /// ```no_run - /// #[cfg(linux)] - /// pub fn foo() { - /// #![cfg(windows)] - /// } - /// ``` - /// Use instead: - /// ```no_run - /// #[cfg(linux)] - /// #[cfg(windows)] - /// pub fn foo() { - /// } - /// ``` - #[clippy::version = "1.78.0"] - pub MIXED_ATTRIBUTES_STYLE, - style, - "item has both inner and outer attributes" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for attributes that appear two or more times. - /// - /// ### Why is this bad? - /// Repeating an attribute on the same item (or globally on the same crate) - /// is unnecessary and doesn't have an effect. - /// - /// ### Example - /// ```no_run - /// #[allow(dead_code)] - /// #[allow(dead_code)] - /// fn foo() {} - /// ``` - /// - /// Use instead: - /// ```no_run - /// #[allow(dead_code)] - /// fn foo() {} - /// ``` - #[clippy::version = "1.78.0"] - pub DUPLICATED_ATTRIBUTES, - suspicious, - "duplicated attribute" -} - -declare_lint_pass!(Attributes => [ - ALLOW_ATTRIBUTES_WITHOUT_REASON, - INLINE_ALWAYS, - DEPRECATED_SEMVER, - USELESS_ATTRIBUTE, - BLANKET_CLIPPY_RESTRICTION_LINTS, - SHOULD_PANIC_WITHOUT_EXPECT, - MIXED_ATTRIBUTES_STYLE, - DUPLICATED_ATTRIBUTES, -]); - -impl<'tcx> LateLintPass<'tcx> for Attributes { - fn check_crate(&mut self, cx: &LateContext<'tcx>) { - blanket_clippy_restriction_lints::check_command_line(cx); - duplicated_attributes::check(cx, cx.tcx.hir().krate_attrs()); - } - - fn check_attribute(&mut self, cx: &LateContext<'tcx>, attr: &'tcx Attribute) { - if let Some(items) = &attr.meta_item_list() { - if let Some(ident) = attr.ident() { - if is_lint_level(ident.name, attr.id) { - blanket_clippy_restriction_lints::check(cx, ident.name, items); - } - if matches!(ident.name, sym::allow | sym::expect) { - allow_attributes_without_reason::check(cx, ident.name, items, attr); - } - if items.is_empty() || !attr.has_name(sym::deprecated) { - return; - } - for item in items { - if let NestedMetaItem::MetaItem(mi) = &item - && let MetaItemKind::NameValue(lit) = &mi.kind - && mi.has_name(sym::since) - { - deprecated_semver::check(cx, item.span(), lit); - } - } - } - } - if attr.has_name(sym::should_panic) { - should_panic_without_expect::check(cx, attr); - } - } - - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - let attrs = cx.tcx.hir().attrs(item.hir_id()); - if is_relevant_item(cx, item) { - inline_always::check(cx, item.span, item.ident.name, attrs); - } - match item.kind { - ItemKind::ExternCrate(..) | ItemKind::Use(..) => useless_attribute::check(cx, item, attrs), - _ => {}, - } - mixed_attributes_style::check(cx, item.span, attrs); - duplicated_attributes::check(cx, attrs); - } - - fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { - if is_relevant_impl(cx, item) { - inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id())); - } - } - - fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { - if is_relevant_trait(cx, item) { - inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id())); - } - } -} - -pub struct EarlyAttributes { - pub msrv: Msrv, -} - -impl_lint_pass!(EarlyAttributes => [ - DEPRECATED_CFG_ATTR, - MISMATCHED_TARGET_OS, - EMPTY_LINE_AFTER_OUTER_ATTR, - EMPTY_LINE_AFTER_DOC_COMMENTS, - NON_MINIMAL_CFG, - MAYBE_MISUSED_CFG, - DEPRECATED_CLIPPY_CFG_ATTR, - UNNECESSARY_CLIPPY_CFG, -]); - -impl EarlyLintPass for EarlyAttributes { - fn check_item(&mut self, cx: &EarlyContext<'_>, item: &rustc_ast::Item) { - empty_line_after::check(cx, item); - } - - fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) { - deprecated_cfg_attr::check(cx, attr, &self.msrv); - deprecated_cfg_attr::check_clippy(cx, attr); - mismatched_target_os::check(cx, attr); - non_minimal_cfg::check(cx, attr); - maybe_misused_cfg::check(cx, attr); - } - - extract_msrv_attr!(EarlyContext); -} diff --git a/clippy_lints/src/attrs/non_minimal_cfg.rs b/clippy_lints/src/attrs/non_minimal_cfg.rs deleted file mode 100644 index 3fde70615853..000000000000 --- a/clippy_lints/src/attrs/non_minimal_cfg.rs +++ /dev/null @@ -1,49 +0,0 @@ -use super::{Attribute, NON_MINIMAL_CFG}; -use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::snippet_opt; -use rustc_ast::{MetaItemKind, NestedMetaItem}; -use rustc_errors::Applicability; -use rustc_lint::EarlyContext; -use rustc_span::sym; - -pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute) { - if attr.has_name(sym::cfg) - && let Some(items) = attr.meta_item_list() - { - check_nested_cfg(cx, &items); - } -} - -fn check_nested_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) { - for item in items { - if let NestedMetaItem::MetaItem(meta) = item { - if !meta.has_name(sym::any) && !meta.has_name(sym::all) { - continue; - } - if let MetaItemKind::List(list) = &meta.kind { - check_nested_cfg(cx, list); - if list.len() == 1 { - span_lint_and_then( - cx, - NON_MINIMAL_CFG, - meta.span, - "unneeded sub `cfg` when there is only one condition", - |diag| { - if let Some(snippet) = snippet_opt(cx, list[0].span()) { - diag.span_suggestion(meta.span, "try", snippet, Applicability::MaybeIncorrect); - } - }, - ); - } else if list.is_empty() && meta.has_name(sym::all) { - span_lint_and_then( - cx, - NON_MINIMAL_CFG, - meta.span, - "unneeded sub `cfg` when there is no condition", - |_| {}, - ); - } - } - } - } -} diff --git a/clippy_lints/src/attrs/should_panic_without_expect.rs b/clippy_lints/src/attrs/should_panic_without_expect.rs deleted file mode 100644 index 2d45cbbf621f..000000000000 --- a/clippy_lints/src/attrs/should_panic_without_expect.rs +++ /dev/null @@ -1,54 +0,0 @@ -use super::{Attribute, SHOULD_PANIC_WITHOUT_EXPECT}; -use clippy_utils::diagnostics::span_lint_and_sugg; -use rustc_ast::token::{Token, TokenKind}; -use rustc_ast::tokenstream::TokenTree; -use rustc_ast::{AttrArgs, AttrArgsEq, AttrKind}; -use rustc_errors::Applicability; -use rustc_lint::LateContext; -use rustc_span::sym; - -pub(super) fn check(cx: &LateContext<'_>, attr: &Attribute) { - if let AttrKind::Normal(normal_attr) = &attr.kind { - if let AttrArgs::Eq(_, AttrArgsEq::Hir(_)) = &normal_attr.item.args { - // `#[should_panic = ".."]` found, good - return; - } - - if let AttrArgs::Delimited(args) = &normal_attr.item.args - && let mut tt_iter = args.tokens.trees() - && let Some(TokenTree::Token( - Token { - kind: TokenKind::Ident(sym::expected, _), - .. - }, - _, - )) = tt_iter.next() - && let Some(TokenTree::Token( - Token { - kind: TokenKind::Eq, .. - }, - _, - )) = tt_iter.next() - && let Some(TokenTree::Token( - Token { - kind: TokenKind::Literal(_), - .. - }, - _, - )) = tt_iter.next() - { - // `#[should_panic(expected = "..")]` found, good - return; - } - - span_lint_and_sugg( - cx, - SHOULD_PANIC_WITHOUT_EXPECT, - attr.span, - "#[should_panic] attribute without a reason", - "consider specifying the expected panic", - "#[should_panic(expected = /* panic message */)]".into(), - Applicability::HasPlaceholders, - ); - } -} diff --git a/clippy_lints/src/attrs/unnecessary_clippy_cfg.rs b/clippy_lints/src/attrs/unnecessary_clippy_cfg.rs deleted file mode 100644 index 486e7c6ec4f4..000000000000 --- a/clippy_lints/src/attrs/unnecessary_clippy_cfg.rs +++ /dev/null @@ -1,70 +0,0 @@ -use super::{Attribute, UNNECESSARY_CLIPPY_CFG}; -use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_sugg}; -use clippy_utils::source::snippet_opt; -use rustc_ast::AttrStyle; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, Level}; -use rustc_span::sym; - -pub(super) fn check( - cx: &EarlyContext<'_>, - cfg_attr: &rustc_ast::MetaItem, - behind_cfg_attr: &rustc_ast::MetaItem, - attr: &Attribute, -) { - if cfg_attr.has_name(sym::clippy) - && let Some(ident) = behind_cfg_attr.ident() - && Level::from_symbol(ident.name, Some(attr.id)).is_some() - && let Some(items) = behind_cfg_attr.meta_item_list() - { - let nb_items = items.len(); - let mut clippy_lints = Vec::with_capacity(items.len()); - for item in items { - if let Some(meta_item) = item.meta_item() - && let [part1, _] = meta_item.path.segments.as_slice() - && part1.ident.name == sym::clippy - { - clippy_lints.push(item.span()); - } - } - if clippy_lints.is_empty() { - return; - } - if nb_items == clippy_lints.len() { - if let Some(snippet) = snippet_opt(cx, behind_cfg_attr.span) { - span_lint_and_sugg( - cx, - UNNECESSARY_CLIPPY_CFG, - attr.span, - "no need to put clippy lints behind a `clippy` cfg", - "replace with", - format!( - "#{}[{}]", - if attr.style == AttrStyle::Inner { "!" } else { "" }, - snippet - ), - Applicability::MachineApplicable, - ); - } - } else { - let snippet = clippy_lints - .iter() - .filter_map(|sp| snippet_opt(cx, *sp)) - .collect::>() - .join(","); - span_lint_and_note( - cx, - UNNECESSARY_CLIPPY_CFG, - clippy_lints, - "no need to put clippy lints behind a `clippy` cfg", - None, - format!( - "write instead: `#{}[{}({})]`", - if attr.style == AttrStyle::Inner { "!" } else { "" }, - ident.name, - snippet - ), - ); - } - } -} diff --git a/clippy_lints/src/attrs/useless_attribute.rs b/clippy_lints/src/attrs/useless_attribute.rs deleted file mode 100644 index f0868231d01a..000000000000 --- a/clippy_lints/src/attrs/useless_attribute.rs +++ /dev/null @@ -1,88 +0,0 @@ -use super::utils::{extract_clippy_lint, is_lint_level, is_word}; -use super::{Attribute, USELESS_ATTRIBUTE}; -use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::{first_line_of_span, snippet_opt}; -use rustc_ast::NestedMetaItem; -use rustc_errors::Applicability; -use rustc_hir::{Item, ItemKind}; -use rustc_lint::{LateContext, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_span::sym; - -pub(super) fn check(cx: &LateContext<'_>, item: &Item<'_>, attrs: &[Attribute]) { - let skip_unused_imports = attrs.iter().any(|attr| attr.has_name(sym::macro_use)); - - for attr in attrs { - if in_external_macro(cx.sess(), attr.span) { - return; - } - if let Some(lint_list) = &attr.meta_item_list() { - if attr.ident().map_or(false, |ident| is_lint_level(ident.name, attr.id)) { - for lint in lint_list { - match item.kind { - ItemKind::Use(..) => { - if let NestedMetaItem::MetaItem(meta_item) = lint - && meta_item.is_word() - && let Some(ident) = meta_item.ident() - && matches!( - ident.name.as_str(), - "ambiguous_glob_reexports" - | "dead_code" - | "deprecated" - | "hidden_glob_reexports" - | "unreachable_pub" - | "unused" - | "unused_braces" - | "unused_import_braces" - | "unused_imports" - ) - { - return; - } - - if extract_clippy_lint(lint).is_some_and(|symbol| { - matches!( - symbol.as_str(), - "wildcard_imports" - | "enum_glob_use" - | "redundant_pub_crate" - | "macro_use_imports" - | "unsafe_removed_from_name" - | "module_name_repetitions" - | "single_component_path_imports" - | "disallowed_types" - ) - }) { - return; - } - }, - ItemKind::ExternCrate(..) => { - if is_word(lint, sym::unused_imports) && skip_unused_imports { - return; - } - if is_word(lint, sym!(unused_extern_crates)) { - return; - } - }, - _ => {}, - } - } - let line_span = first_line_of_span(cx, attr.span); - - if let Some(mut sugg) = snippet_opt(cx, line_span) { - if sugg.contains("#[") { - span_lint_and_then(cx, USELESS_ATTRIBUTE, line_span, "useless lint attribute", |diag| { - sugg = sugg.replacen("#[", "#![", 1); - diag.span_suggestion( - line_span, - "if you just forgot a `!`, use", - sugg, - Applicability::MaybeIncorrect, - ); - }); - } - } - } - } - } -} diff --git a/clippy_lints/src/attrs/utils.rs b/clippy_lints/src/attrs/utils.rs deleted file mode 100644 index 91ae19acbf7f..000000000000 --- a/clippy_lints/src/attrs/utils.rs +++ /dev/null @@ -1,87 +0,0 @@ -use clippy_utils::macros::{is_panic, macro_backtrace}; -use rustc_ast::{AttrId, NestedMetaItem}; -use rustc_hir::{ - Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind, -}; -use rustc_lint::{LateContext, Level}; -use rustc_middle::ty; -use rustc_span::sym; -use rustc_span::symbol::Symbol; - -pub(super) fn is_word(nmi: &NestedMetaItem, expected: Symbol) -> bool { - if let NestedMetaItem::MetaItem(mi) = &nmi { - mi.is_word() && mi.has_name(expected) - } else { - false - } -} - -pub(super) fn is_lint_level(symbol: Symbol, attr_id: AttrId) -> bool { - Level::from_symbol(symbol, Some(attr_id)).is_some() -} - -pub(super) fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool { - if let ItemKind::Fn(_, _, eid) = item.kind { - is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value) - } else { - true - } -} - -pub(super) fn is_relevant_impl(cx: &LateContext<'_>, item: &ImplItem<'_>) -> bool { - match item.kind { - ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value), - _ => false, - } -} - -pub(super) fn is_relevant_trait(cx: &LateContext<'_>, item: &TraitItem<'_>) -> bool { - match item.kind { - TraitItemKind::Fn(_, TraitFn::Required(_)) => true, - TraitItemKind::Fn(_, TraitFn::Provided(eid)) => { - is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value) - }, - _ => false, - } -} - -fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>, block: &Block<'_>) -> bool { - block.stmts.first().map_or( - block - .expr - .as_ref() - .map_or(false, |e| is_relevant_expr(cx, typeck_results, e)), - |stmt| match &stmt.kind { - StmtKind::Let(_) => true, - StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, typeck_results, expr), - StmtKind::Item(_) => false, - }, - ) -} - -fn is_relevant_expr(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>, expr: &Expr<'_>) -> bool { - if macro_backtrace(expr.span).last().map_or(false, |macro_call| { - is_panic(cx, macro_call.def_id) || cx.tcx.item_name(macro_call.def_id) == sym::unreachable - }) { - return false; - } - match &expr.kind { - ExprKind::Block(block, _) => is_relevant_block(cx, typeck_results, block), - ExprKind::Ret(Some(e)) => is_relevant_expr(cx, typeck_results, e), - ExprKind::Ret(None) | ExprKind::Break(_, None) => false, - _ => true, - } -} - -/// Returns the lint name if it is clippy lint. -pub(super) fn extract_clippy_lint(lint: &NestedMetaItem) -> Option { - if let Some(meta_item) = lint.meta_item() - && meta_item.path.segments.len() > 1 - && let tool_name = meta_item.path.segments[0].ident - && tool_name.name == sym::clippy - { - let lint_name = meta_item.path.segments.last().unwrap().ident.name; - return Some(lint_name); - } - None -} diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs deleted file mode 100644 index f25a474d9bbd..000000000000 --- a/clippy_lints/src/await_holding_invalid.rs +++ /dev/null @@ -1,296 +0,0 @@ -use clippy_config::types::DisallowedPath; -use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::{match_def_path, paths}; -use rustc_data_structures::fx::FxHashMap; -use rustc_hir as hir; -use rustc_hir::def_id::DefId; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::mir::CoroutineLayout; -use rustc_session::impl_lint_pass; -use rustc_span::{sym, Span}; - -declare_clippy_lint! { - /// ### What it does - /// Checks for calls to await while holding a non-async-aware MutexGuard. - /// - /// ### Why is this bad? - /// The Mutex types found in std::sync and parking_lot - /// are not designed to operate in an async context across await points. - /// - /// There are two potential solutions. One is to use an async-aware Mutex - /// type. Many asynchronous foundation crates provide such a Mutex type. The - /// other solution is to ensure the mutex is unlocked before calling await, - /// either by introducing a scope or an explicit call to Drop::drop. - /// - /// ### Known problems - /// Will report false positive for explicitly dropped guards - /// ([#6446](https://github.com/rust-lang/rust-clippy/issues/6446)). A workaround for this is - /// to wrap the `.lock()` call in a block instead of explicitly dropping the guard. - /// - /// ### Example - /// ```no_run - /// # use std::sync::Mutex; - /// # async fn baz() {} - /// async fn foo(x: &Mutex) { - /// let mut guard = x.lock().unwrap(); - /// *guard += 1; - /// baz().await; - /// } - /// - /// async fn bar(x: &Mutex) { - /// let mut guard = x.lock().unwrap(); - /// *guard += 1; - /// drop(guard); // explicit drop - /// baz().await; - /// } - /// ``` - /// - /// Use instead: - /// ```no_run - /// # use std::sync::Mutex; - /// # async fn baz() {} - /// async fn foo(x: &Mutex) { - /// { - /// let mut guard = x.lock().unwrap(); - /// *guard += 1; - /// } - /// baz().await; - /// } - /// - /// async fn bar(x: &Mutex) { - /// { - /// let mut guard = x.lock().unwrap(); - /// *guard += 1; - /// } // guard dropped here at end of scope - /// baz().await; - /// } - /// ``` - #[clippy::version = "1.45.0"] - pub AWAIT_HOLDING_LOCK, - suspicious, - "inside an async function, holding a `MutexGuard` while calling `await`" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for calls to await while holding a `RefCell` `Ref` or `RefMut`. - /// - /// ### Why is this bad? - /// `RefCell` refs only check for exclusive mutable access - /// at runtime. Holding onto a `RefCell` ref across an `await` suspension point - /// risks panics from a mutable ref shared while other refs are outstanding. - /// - /// ### Known problems - /// Will report false positive for explicitly dropped refs - /// ([#6353](https://github.com/rust-lang/rust-clippy/issues/6353)). A workaround for this is - /// to wrap the `.borrow[_mut]()` call in a block instead of explicitly dropping the ref. - /// - /// ### Example - /// ```no_run - /// # use std::cell::RefCell; - /// # async fn baz() {} - /// async fn foo(x: &RefCell) { - /// let mut y = x.borrow_mut(); - /// *y += 1; - /// baz().await; - /// } - /// - /// async fn bar(x: &RefCell) { - /// let mut y = x.borrow_mut(); - /// *y += 1; - /// drop(y); // explicit drop - /// baz().await; - /// } - /// ``` - /// - /// Use instead: - /// ```no_run - /// # use std::cell::RefCell; - /// # async fn baz() {} - /// async fn foo(x: &RefCell) { - /// { - /// let mut y = x.borrow_mut(); - /// *y += 1; - /// } - /// baz().await; - /// } - /// - /// async fn bar(x: &RefCell) { - /// { - /// let mut y = x.borrow_mut(); - /// *y += 1; - /// } // y dropped here at end of scope - /// baz().await; - /// } - /// ``` - #[clippy::version = "1.49.0"] - pub AWAIT_HOLDING_REFCELL_REF, - suspicious, - "inside an async function, holding a `RefCell` ref while calling `await`" -} - -declare_clippy_lint! { - /// ### What it does - /// Allows users to configure types which should not be held across `await` - /// suspension points. - /// - /// ### Why is this bad? - /// There are some types which are perfectly "safe" to be used concurrently - /// from a memory access perspective but will cause bugs at runtime if they - /// are held in such a way. - /// - /// ### Example - /// - /// ```toml - /// await-holding-invalid-types = [ - /// # You can specify a type name - /// "CustomLockType", - /// # You can (optionally) specify a reason - /// { path = "OtherCustomLockType", reason = "Relies on a thread local" } - /// ] - /// ``` - /// - /// ```no_run - /// # async fn baz() {} - /// struct CustomLockType; - /// struct OtherCustomLockType; - /// async fn foo() { - /// let _x = CustomLockType; - /// let _y = OtherCustomLockType; - /// baz().await; // Lint violation - /// } - /// ``` - #[clippy::version = "1.62.0"] - pub AWAIT_HOLDING_INVALID_TYPE, - suspicious, - "holding a type across an await point which is not allowed to be held as per the configuration" -} - -impl_lint_pass!(AwaitHolding => [AWAIT_HOLDING_LOCK, AWAIT_HOLDING_REFCELL_REF, AWAIT_HOLDING_INVALID_TYPE]); - -#[derive(Debug)] -pub struct AwaitHolding { - conf_invalid_types: Vec, - def_ids: FxHashMap, -} - -impl AwaitHolding { - pub(crate) fn new(conf_invalid_types: Vec) -> Self { - Self { - conf_invalid_types, - def_ids: FxHashMap::default(), - } - } -} - -impl<'tcx> LateLintPass<'tcx> for AwaitHolding { - fn check_crate(&mut self, cx: &LateContext<'tcx>) { - for conf in &self.conf_invalid_types { - let segs: Vec<_> = conf.path().split("::").collect(); - for id in clippy_utils::def_path_def_ids(cx, &segs) { - self.def_ids.insert(id, conf.clone()); - } - } - } - - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) { - if let hir::ExprKind::Closure(hir::Closure { - kind: hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)), - def_id, - .. - }) = expr.kind - { - if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(*def_id) { - self.check_interior_types(cx, coroutine_layout); - } - } - } -} - -impl AwaitHolding { - fn check_interior_types(&self, cx: &LateContext<'_>, coroutine: &CoroutineLayout<'_>) { - for (ty_index, ty_cause) in coroutine.field_tys.iter_enumerated() { - if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind() { - let await_points = || { - coroutine - .variant_source_info - .iter_enumerated() - .filter_map(|(variant, source_info)| { - coroutine.variant_fields[variant] - .raw - .contains(&ty_index) - .then_some(source_info.span) - }) - .collect::>() - }; - if is_mutex_guard(cx, adt.did()) { - span_lint_and_then( - cx, - AWAIT_HOLDING_LOCK, - ty_cause.source_info.span, - "this `MutexGuard` is held across an `await` point", - |diag| { - diag.help( - "consider using an async-aware `Mutex` type or ensuring the \ - `MutexGuard` is dropped before calling await", - ); - diag.span_note( - await_points(), - "these are all the `await` points this lock is held through", - ); - }, - ); - } else if is_refcell_ref(cx, adt.did()) { - span_lint_and_then( - cx, - AWAIT_HOLDING_REFCELL_REF, - ty_cause.source_info.span, - "this `RefCell` reference is held across an `await` point", - |diag| { - diag.help("ensure the reference is dropped before calling `await`"); - diag.span_note( - await_points(), - "these are all the `await` points this reference is held through", - ); - }, - ); - } else if let Some(disallowed) = self.def_ids.get(&adt.did()) { - emit_invalid_type(cx, ty_cause.source_info.span, disallowed); - } - } - } - } -} - -fn emit_invalid_type(cx: &LateContext<'_>, span: Span, disallowed: &DisallowedPath) { - span_lint_and_then( - cx, - AWAIT_HOLDING_INVALID_TYPE, - span, - format!( - "`{}` may not be held across an `await` point per `clippy.toml`", - disallowed.path() - ), - |diag| { - if let Some(reason) = disallowed.reason() { - diag.note(reason); - } - }, - ); -} - -fn is_mutex_guard(cx: &LateContext<'_>, def_id: DefId) -> bool { - cx.tcx.is_diagnostic_item(sym::MutexGuard, def_id) - || cx.tcx.is_diagnostic_item(sym::RwLockReadGuard, def_id) - || cx.tcx.is_diagnostic_item(sym::RwLockWriteGuard, def_id) - || match_def_path(cx, def_id, &paths::PARKING_LOT_MUTEX_GUARD) - || match_def_path(cx, def_id, &paths::PARKING_LOT_RWLOCK_READ_GUARD) - || match_def_path(cx, def_id, &paths::PARKING_LOT_RWLOCK_WRITE_GUARD) -} - -fn is_refcell_ref(cx: &LateContext<'_>, def_id: DefId) -> bool { - matches!( - cx.tcx.get_diagnostic_name(def_id), - Some(sym::RefCellRef | sym::RefCellRefMut) - ) -} diff --git a/clippy_lints/src/blocks_in_conditions.rs b/clippy_lints/src/blocks_in_conditions.rs deleted file mode 100644 index 171f30318601..000000000000 --- a/clippy_lints/src/blocks_in_conditions.rs +++ /dev/null @@ -1,153 +0,0 @@ -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, is_from_proc_macro}; -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` and `match` 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 } { /* ... */ } - /// - /// match { let e = somefunc(); e } { - /// // ... - /// # _ => {} - /// } - /// ``` - /// - /// Use instead: - /// ```no_run - /// # fn somefunc() -> bool { true }; - /// if true { /* ... */ } - /// - /// let res = { let x = somefunc(); x }; - /// if res { /* ... */ } - /// - /// let res = { let e = somefunc(); e }; - /// match 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.span.eq_ctxt(expr.span) { - // If the block comes from a macro, or as an argument to a macro, - // do not lint. - return; - } - 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() || is_from_proc_macro(cx, cond) { - 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.clone()); - return ControlFlow::Continue(Descend::No); - } - } - } - ControlFlow::Continue(Descend::Yes) - }); - } - } -} diff --git a/clippy_lints/src/bool_assert_comparison.rs b/clippy_lints/src/bool_assert_comparison.rs deleted file mode 100644 index 58c1a2f27062..000000000000 --- a/clippy_lints/src/bool_assert_comparison.rs +++ /dev/null @@ -1,147 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::macros::{find_assert_eq_args, root_macro_call_first_node}; -use clippy_utils::sugg::Sugg; -use clippy_utils::ty::{implements_trait, is_copy}; -use rustc_ast::ast::LitKind; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, Lit}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::ty::{self, Ty}; -use rustc_session::declare_lint_pass; -use rustc_span::symbol::Ident; - -declare_clippy_lint! { - /// ### What it does - /// This lint warns about boolean comparisons in assert-like macros. - /// - /// ### Why is this bad? - /// It is shorter to use the equivalent. - /// - /// ### Example - /// ```no_run - /// assert_eq!("a".is_empty(), false); - /// assert_ne!("a".is_empty(), true); - /// ``` - /// - /// Use instead: - /// ```no_run - /// assert!(!"a".is_empty()); - /// ``` - #[clippy::version = "1.53.0"] - pub BOOL_ASSERT_COMPARISON, - style, - "Using a boolean as comparison value in an assert_* macro when there is no need" -} - -declare_lint_pass!(BoolAssertComparison => [BOOL_ASSERT_COMPARISON]); - -fn extract_bool_lit(e: &Expr<'_>) -> Option { - if let ExprKind::Lit(Lit { - node: LitKind::Bool(b), .. - }) = e.kind - && !e.span.from_expansion() - { - Some(*b) - } else { - None - } -} - -fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { - cx.tcx - .lang_items() - .not_trait() - .filter(|trait_id| implements_trait(cx, ty, *trait_id, &[])) - .and_then(|trait_id| { - cx.tcx.associated_items(trait_id).find_by_name_and_kind( - cx.tcx, - Ident::from_str("Output"), - ty::AssocKind::Type, - trait_id, - ) - }) - .map_or(false, |assoc_item| { - let proj = Ty::new_projection(cx.tcx, assoc_item.def_id, cx.tcx.mk_args_trait(ty, [])); - let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj); - - nty.is_bool() - }) -} - -impl<'tcx> LateLintPass<'tcx> for BoolAssertComparison { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - let Some(macro_call) = root_macro_call_first_node(cx, expr) else { - return; - }; - let macro_name = cx.tcx.item_name(macro_call.def_id); - let eq_macro = match macro_name.as_str() { - "assert_eq" | "debug_assert_eq" => true, - "assert_ne" | "debug_assert_ne" => false, - _ => return, - }; - let Some((a, b, _)) = find_assert_eq_args(cx, expr, macro_call.expn) else { - return; - }; - - let a_span = a.span.source_callsite(); - let b_span = b.span.source_callsite(); - - let (lit_span, bool_value, non_lit_expr) = match (extract_bool_lit(a), extract_bool_lit(b)) { - // assert_eq!(true/false, b) - // ^^^^^^^^^^^^ - (Some(bool_value), None) => (a_span.until(b_span), bool_value, b), - // assert_eq!(a, true/false) - // ^^^^^^^^^^^^ - (None, Some(bool_value)) => (b_span.with_lo(a_span.hi()), bool_value, a), - // If there are two boolean arguments, we definitely don't understand - // what's going on, so better leave things as is... - // - // Or there is simply no boolean and then we can leave things as is! - _ => return, - }; - - let non_lit_ty = cx.typeck_results().expr_ty(non_lit_expr); - - if !is_impl_not_trait_with_bool_out(cx, non_lit_ty) { - // At this point the expression which is not a boolean - // literal does not implement Not trait with a bool output, - // so we cannot suggest to rewrite our code - return; - } - - if !is_copy(cx, non_lit_ty) { - // Only lint with types that are `Copy` because `assert!(x)` takes - // ownership of `x` whereas `assert_eq(x, true)` does not - return; - } - - let macro_name = macro_name.as_str(); - let non_eq_mac = ¯o_name[..macro_name.len() - 3]; - span_lint_and_then( - cx, - BOOL_ASSERT_COMPARISON, - macro_call.span, - format!("used `{macro_name}!` with a literal bool"), - |diag| { - // assert_eq!(...) - // ^^^^^^^^^ - let name_span = cx.sess().source_map().span_until_char(macro_call.span, '!'); - - let mut suggestions = vec![(name_span, non_eq_mac.to_string()), (lit_span, String::new())]; - - if bool_value ^ eq_macro { - let Some(sugg) = Sugg::hir_opt(cx, non_lit_expr) else { - return; - }; - suggestions.push((non_lit_expr.span, (!sugg).to_string())); - } - - diag.multipart_suggestion( - format!("replace it with `{non_eq_mac}!(..)`"), - suggestions, - Applicability::MachineApplicable, - ); - }, - ); - } -} diff --git a/clippy_lints/src/bool_to_int_with_if.rs b/clippy_lints/src/bool_to_int_with_if.rs deleted file mode 100644 index cfb76cab6dc2..000000000000 --- a/clippy_lints/src/bool_to_int_with_if.rs +++ /dev/null @@ -1,127 +0,0 @@ -use clippy_utils::higher::If; -use rustc_ast::LitKind; -use rustc_hir::{Block, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::declare_lint_pass; - -use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::sugg::Sugg; -use clippy_utils::{in_constant, is_else_clause, is_integer_literal}; -use rustc_errors::Applicability; - -declare_clippy_lint! { - /// ### What it does - /// Instead of using an if statement to convert a bool to an int, - /// this lint suggests using a `from()` function or an `as` coercion. - /// - /// ### Why is this bad? - /// Coercion or `from()` is another way to convert bool to a number. - /// Both methods are guaranteed to return 1 for true, and 0 for false. - /// - /// See https://doc.rust-lang.org/std/primitive.bool.html#impl-From%3Cbool%3E - /// - /// ### Example - /// ```no_run - /// # let condition = false; - /// if condition { - /// 1_i64 - /// } else { - /// 0 - /// }; - /// ``` - /// Use instead: - /// ```no_run - /// # let condition = false; - /// i64::from(condition); - /// ``` - /// or - /// ```no_run - /// # let condition = false; - /// condition as i64; - /// ``` - #[clippy::version = "1.65.0"] - pub BOOL_TO_INT_WITH_IF, - pedantic, - "using if to convert bool to int" -} -declare_lint_pass!(BoolToIntWithIf => [BOOL_TO_INT_WITH_IF]); - -impl<'tcx> LateLintPass<'tcx> for BoolToIntWithIf { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx rustc_hir::Expr<'tcx>) { - if !expr.span.from_expansion() && !in_constant(cx, expr.hir_id) { - check_if_else(cx, expr); - } - } -} - -fn check_if_else<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx rustc_hir::Expr<'tcx>) { - if let Some(If { - cond, - then, - r#else: Some(r#else), - }) = If::hir(expr) - && let Some(then_lit) = int_literal(then) - && let Some(else_lit) = int_literal(r#else) - { - let inverted = if is_integer_literal(then_lit, 1) && is_integer_literal(else_lit, 0) { - false - } else if is_integer_literal(then_lit, 0) && is_integer_literal(else_lit, 1) { - true - } else { - // Expression isn't boolean, exit - return; - }; - let mut applicability = Applicability::MachineApplicable; - let snippet = { - let mut sugg = Sugg::hir_with_applicability(cx, cond, "..", &mut applicability); - if inverted { - sugg = !sugg; - } - sugg - }; - - let ty = cx.typeck_results().expr_ty(then_lit); // then and else must be of same type - - let suggestion = { - let wrap_in_curly = is_else_clause(cx.tcx, expr); - let mut s = Sugg::NonParen(format!("{ty}::from({snippet})").into()); - if wrap_in_curly { - s = s.blockify(); - } - s - }; // when used in else clause if statement should be wrapped in curly braces - - let into_snippet = snippet.clone().maybe_par(); - let as_snippet = snippet.as_ty(ty); - - span_lint_and_then( - cx, - BOOL_TO_INT_WITH_IF, - expr.span, - "boolean to int conversion using if", - |diag| { - diag.span_suggestion(expr.span, "replace with from", suggestion, applicability); - diag.note(format!( - "`{as_snippet}` or `{into_snippet}.into()` can also be valid options" - )); - }, - ); - }; -} - -// If block contains only a int literal expression, return literal expression -fn int_literal<'tcx>(expr: &'tcx rustc_hir::Expr<'tcx>) -> Option<&'tcx rustc_hir::Expr<'tcx>> { - if let ExprKind::Block(block, _) = expr.kind - && let Block { - stmts: [], // Shouldn't lint if statements with side effects - expr: Some(expr), - .. - } = block - && let ExprKind::Lit(lit) = &expr.kind - && let LitKind::Int(_, _) = lit.node - { - Some(expr) - } else { - None - } -} diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs deleted file mode 100644 index b6341b3fe8e7..000000000000 --- a/clippy_lints/src/booleans.rs +++ /dev/null @@ -1,615 +0,0 @@ -use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then}; -use clippy_utils::eq_expr_value; -use clippy_utils::source::snippet_opt; -use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; -use rustc_ast::ast::LitKind; -use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; -use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, UnOp}; -use rustc_lint::{LateContext, LateLintPass, Level}; -use rustc_session::declare_lint_pass; -use rustc_span::def_id::LocalDefId; -use rustc_span::{sym, Span}; - -declare_clippy_lint! { - /// ### What it does - /// Checks for boolean expressions that can be written more - /// concisely. - /// - /// ### Why is this bad? - /// Readability of boolean expressions suffers from - /// unnecessary duplication. - /// - /// ### Known problems - /// Ignores short circuiting behavior of `||` and - /// `&&`. Ignores `|`, `&` and `^`. - /// - /// ### Example - /// ```ignore - /// if a && true {} - /// if !(a == b) {} - /// ``` - /// - /// Use instead: - /// ```rust,ignore - /// if a {} - /// if a != b {} - /// ``` - #[clippy::version = "pre 1.29.0"] - pub NONMINIMAL_BOOL, - complexity, - "boolean expressions that can be written more concisely" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for boolean expressions that contain terminals that - /// can be eliminated. - /// - /// ### Why is this bad? - /// This is most likely a logic bug. - /// - /// ### Known problems - /// Ignores short circuiting behavior. - /// - /// ### Example - /// ```rust,ignore - /// // The `b` is unnecessary, the expression is equivalent to `if a`. - /// if a && b || a { ... } - /// ``` - /// - /// Use instead: - /// ```rust,ignore - /// if a {} - /// ``` - #[clippy::version = "pre 1.29.0"] - pub OVERLY_COMPLEX_BOOL_EXPR, - correctness, - "boolean expressions that contain terminals which can be eliminated" -} - -// For each pairs, both orders are considered. -const METHODS_WITH_NEGATION: [(&str, &str); 2] = [("is_some", "is_none"), ("is_err", "is_ok")]; - -declare_lint_pass!(NonminimalBool => [NONMINIMAL_BOOL, OVERLY_COMPLEX_BOOL_EXPR]); - -impl<'tcx> LateLintPass<'tcx> for NonminimalBool { - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - _: FnKind<'tcx>, - _: &'tcx FnDecl<'_>, - body: &'tcx Body<'_>, - _: Span, - _: LocalDefId, - ) { - NonminimalBoolVisitor { cx }.visit_body(body); - } - - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - match expr.kind { - // This check the case where an element in a boolean comparison is inverted, like: - // - // ``` - // let a = true; - // !a == false; - // ``` - ExprKind::Binary(op, left, right) if matches!(op.node, BinOpKind::Eq | BinOpKind::Ne) => { - check_inverted_bool_in_condition(cx, expr.span, op.node, left, right); - }, - _ => {}, - } - } -} - -fn inverted_bin_op_eq_str(op: BinOpKind) -> Option<&'static str> { - match op { - BinOpKind::Eq => Some("!="), - BinOpKind::Ne => Some("=="), - _ => None, - } -} - -fn bin_op_eq_str(op: BinOpKind) -> Option<&'static str> { - match op { - BinOpKind::Eq => Some("=="), - BinOpKind::Ne => Some("!="), - _ => None, - } -} - -fn check_inverted_bool_in_condition( - cx: &LateContext<'_>, - expr_span: Span, - op: BinOpKind, - left: &Expr<'_>, - right: &Expr<'_>, -) { - if expr_span.from_expansion() - || !cx.typeck_results().node_types()[left.hir_id].is_bool() - || !cx.typeck_results().node_types()[right.hir_id].is_bool() - { - return; - } - - let suggestion = match (left.kind, right.kind) { - (ExprKind::Unary(UnOp::Not, left_sub), ExprKind::Unary(UnOp::Not, right_sub)) => { - let Some(left) = snippet_opt(cx, left_sub.span) else { - return; - }; - let Some(right) = snippet_opt(cx, right_sub.span) else { - return; - }; - let Some(op) = bin_op_eq_str(op) else { return }; - format!("{left} {op} {right}") - }, - (ExprKind::Unary(UnOp::Not, left_sub), _) => { - let Some(left) = snippet_opt(cx, left_sub.span) else { - return; - }; - let Some(right) = snippet_opt(cx, right.span) else { - return; - }; - let Some(op) = inverted_bin_op_eq_str(op) else { return }; - format!("{left} {op} {right}") - }, - (_, ExprKind::Unary(UnOp::Not, right_sub)) => { - let Some(left) = snippet_opt(cx, left.span) else { return }; - let Some(right) = snippet_opt(cx, right_sub.span) else { - return; - }; - let Some(op) = inverted_bin_op_eq_str(op) else { return }; - format!("{left} {op} {right}") - }, - _ => return, - }; - span_lint_and_sugg( - cx, - NONMINIMAL_BOOL, - expr_span, - "this boolean expression can be simplified", - "try", - suggestion, - Applicability::MachineApplicable, - ); -} - -struct NonminimalBoolVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, -} - -use quine_mc_cluskey::Bool; -struct Hir2Qmm<'a, 'tcx, 'v> { - terminals: Vec<&'v Expr<'v>>, - cx: &'a LateContext<'tcx>, -} - -impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> { - fn extract(&mut self, op: BinOpKind, a: &[&'v Expr<'_>], mut v: Vec) -> Result, String> { - for a in a { - if let ExprKind::Binary(binop, lhs, rhs) = &a.kind { - if binop.node == op { - v = self.extract(op, &[lhs, rhs], v)?; - continue; - } - } - v.push(self.run(a)?); - } - Ok(v) - } - - fn run(&mut self, e: &'v Expr<'_>) -> Result { - fn negate(bin_op_kind: BinOpKind) -> Option { - match bin_op_kind { - BinOpKind::Eq => Some(BinOpKind::Ne), - BinOpKind::Ne => Some(BinOpKind::Eq), - BinOpKind::Gt => Some(BinOpKind::Le), - BinOpKind::Ge => Some(BinOpKind::Lt), - BinOpKind::Lt => Some(BinOpKind::Ge), - BinOpKind::Le => Some(BinOpKind::Gt), - _ => None, - } - } - - // prevent folding of `cfg!` macros and the like - if !e.span.from_expansion() { - match &e.kind { - ExprKind::Unary(UnOp::Not, inner) => return Ok(Bool::Not(Box::new(self.run(inner)?))), - ExprKind::Binary(binop, lhs, rhs) => match &binop.node { - BinOpKind::Or => { - return Ok(Bool::Or(self.extract(BinOpKind::Or, &[lhs, rhs], Vec::new())?)); - }, - BinOpKind::And => { - return Ok(Bool::And(self.extract(BinOpKind::And, &[lhs, rhs], Vec::new())?)); - }, - _ => (), - }, - ExprKind::Lit(lit) => match lit.node { - LitKind::Bool(true) => return Ok(Bool::True), - LitKind::Bool(false) => return Ok(Bool::False), - _ => (), - }, - _ => (), - } - } - for (n, expr) in self.terminals.iter().enumerate() { - if eq_expr_value(self.cx, e, expr) { - #[expect(clippy::cast_possible_truncation)] - return Ok(Bool::Term(n as u8)); - } - - if let ExprKind::Binary(e_binop, e_lhs, e_rhs) = &e.kind - && implements_ord(self.cx, e_lhs) - && let ExprKind::Binary(expr_binop, expr_lhs, expr_rhs) = &expr.kind - && negate(e_binop.node) == Some(expr_binop.node) - && eq_expr_value(self.cx, e_lhs, expr_lhs) - && eq_expr_value(self.cx, e_rhs, expr_rhs) - { - #[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 { - #[expect(clippy::cast_possible_truncation)] - Ok(Bool::Term(n as u8)) - } else { - Err("too many literals".to_owned()) - } - } -} - -struct SuggestContext<'a, 'tcx, 'v> { - terminals: &'v [&'v Expr<'v>], - cx: &'a LateContext<'tcx>, - output: String, -} - -impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> { - fn recurse(&mut self, suggestion: &Bool) -> Option<()> { - use quine_mc_cluskey::Bool::{And, False, Not, Or, Term, True}; - match suggestion { - True => { - self.output.push_str("true"); - }, - False => { - self.output.push_str("false"); - }, - Not(inner) => match **inner { - And(_) | Or(_) => { - self.output.push('!'); - self.output.push('('); - self.recurse(inner); - self.output.push(')'); - }, - Term(n) => { - let terminal = self.terminals[n as usize]; - if let Some(str) = simplify_not(self.cx, terminal) { - self.output.push_str(&str); - } else { - self.output.push('!'); - let snip = snippet_opt(self.cx, terminal.span)?; - self.output.push_str(&snip); - } - }, - True | False | Not(_) => { - self.output.push('!'); - self.recurse(inner)?; - }, - }, - And(v) => { - for (index, inner) in v.iter().enumerate() { - if index > 0 { - self.output.push_str(" && "); - } - if let Or(_) = *inner { - self.output.push('('); - self.recurse(inner); - self.output.push(')'); - } else { - self.recurse(inner); - } - } - }, - Or(v) => { - for (index, inner) in v.iter().rev().enumerate() { - if index > 0 { - self.output.push_str(" || "); - } - self.recurse(inner); - } - }, - &Term(n) => { - let snip = snippet_opt(self.cx, self.terminals[n as usize].span.source_callsite())?; - self.output.push_str(&snip); - }, - } - Some(()) - } -} - -fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { - match &expr.kind { - ExprKind::Binary(binop, lhs, rhs) => { - if !implements_ord(cx, lhs) { - return None; - } - - match binop.node { - BinOpKind::Eq => Some(" != "), - BinOpKind::Ne => Some(" == "), - BinOpKind::Lt => Some(" >= "), - BinOpKind::Gt => Some(" <= "), - BinOpKind::Le => Some(" > "), - BinOpKind::Ge => Some(" < "), - _ => None, - } - .and_then(|op| { - let lhs_snippet = snippet_opt(cx, lhs.span)?; - let rhs_snippet = snippet_opt(cx, rhs.span)?; - - if !(lhs_snippet.starts_with('(') && lhs_snippet.ends_with(')')) { - if let (ExprKind::Cast(..), BinOpKind::Ge) = (&lhs.kind, binop.node) { - // e.g. `(a as u64) < b`. Without the parens the `<` is - // interpreted as a start of generic arguments for `u64` - return Some(format!("({lhs_snippet}){op}{rhs_snippet}")); - } - } - - Some(format!("{lhs_snippet}{op}{rhs_snippet}")) - }) - }, - ExprKind::MethodCall(path, receiver, [], _) => { - let type_of_receiver = cx.typeck_results().expr_ty(receiver); - if !is_type_diagnostic_item(cx, type_of_receiver, sym::Option) - && !is_type_diagnostic_item(cx, type_of_receiver, sym::Result) - { - return None; - } - METHODS_WITH_NEGATION - .iter() - .copied() - .flat_map(|(a, b)| vec![(a, b), (b, a)]) - .find(|&(a, _)| { - let path: &str = path.ident.name.as_str(); - a == path - }) - .and_then(|(_, neg_method)| Some(format!("{}.{neg_method}()", snippet_opt(cx, receiver.span)?))) - }, - _ => None, - } -} - -fn suggest(cx: &LateContext<'_>, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String { - let mut suggest_context = SuggestContext { - terminals, - cx, - output: String::new(), - }; - suggest_context.recurse(suggestion); - suggest_context.output -} - -fn simple_negate(b: Bool) -> Bool { - use quine_mc_cluskey::Bool::{And, False, Not, Or, Term, True}; - match b { - True => False, - False => True, - t @ Term(_) => Not(Box::new(t)), - And(mut v) => { - for el in &mut v { - *el = simple_negate(std::mem::replace(el, True)); - } - Or(v) - }, - Or(mut v) => { - for el in &mut v { - *el = simple_negate(std::mem::replace(el, True)); - } - And(v) - }, - Not(inner) => *inner, - } -} - -#[derive(Default)] -struct Stats { - terminals: [usize; 32], - negations: usize, - ops: usize, -} - -fn terminal_stats(b: &Bool) -> Stats { - fn recurse(b: &Bool, stats: &mut Stats) { - match b { - True | False => stats.ops += 1, - Not(inner) => { - match **inner { - And(_) | Or(_) => stats.ops += 1, // brackets are also operations - _ => stats.negations += 1, - } - recurse(inner, stats); - }, - And(v) | Or(v) => { - stats.ops += v.len() - 1; - for inner in v { - recurse(inner, stats); - } - }, - &Term(n) => stats.terminals[n as usize] += 1, - } - } - use quine_mc_cluskey::Bool::{And, False, Not, Or, Term, True}; - let mut stats = Stats::default(); - recurse(b, &mut stats); - stats -} - -impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> { - fn bool_expr(&self, e: &'tcx Expr<'_>) { - let mut h2q = Hir2Qmm { - terminals: Vec::new(), - cx: self.cx, - }; - if let Ok(expr) = h2q.run(e) { - if h2q.terminals.len() > 8 { - // QMC has exponentially slow behavior as the number of terminals increases - // 8 is reasonable, it takes approximately 0.2 seconds. - // See #825 - return; - } - - let stats = terminal_stats(&expr); - let mut simplified = expr.simplify(); - for simple in Bool::Not(Box::new(expr)).simplify() { - match simple { - Bool::Not(_) | Bool::True | Bool::False => {}, - _ => simplified.push(Bool::Not(Box::new(simple.clone()))), - } - let simple_negated = simple_negate(simple); - if simplified.iter().any(|s| *s == simple_negated) { - continue; - } - simplified.push(simple_negated); - } - let mut improvements = Vec::with_capacity(simplified.len()); - 'simplified: for suggestion in &simplified { - let simplified_stats = terminal_stats(suggestion); - let mut improvement = false; - for i in 0..32 { - // ignore any "simplifications" that end up requiring a terminal more often - // than in the original expression - if stats.terminals[i] < simplified_stats.terminals[i] { - continue 'simplified; - } - if stats.terminals[i] != 0 && simplified_stats.terminals[i] == 0 { - span_lint_hir_and_then( - self.cx, - OVERLY_COMPLEX_BOOL_EXPR, - e.hir_id, - e.span, - "this boolean expression contains a logic bug", - |diag| { - diag.span_help( - h2q.terminals[i].span, - "this expression can be optimized out by applying boolean operations to the \ - outer expression", - ); - diag.span_suggestion( - e.span, - "it would look like the following", - suggest(self.cx, suggestion, &h2q.terminals), - // nonminimal_bool can produce minimal but - // not human readable expressions (#3141) - Applicability::Unspecified, - ); - }, - ); - // don't also lint `NONMINIMAL_BOOL` - return; - } - // if the number of occurrences of a terminal decreases or any of the stats - // decreases while none increases - improvement |= (stats.terminals[i] > simplified_stats.terminals[i]) - || (stats.negations > simplified_stats.negations && stats.ops == simplified_stats.ops) - || (stats.ops > simplified_stats.ops && stats.negations == simplified_stats.negations); - } - if improvement { - improvements.push(suggestion); - } - } - let nonminimal_bool_lint = |mut suggestions: Vec<_>| { - if self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, e.hir_id).0 != Level::Allow { - suggestions.sort(); - span_lint_hir_and_then( - self.cx, - NONMINIMAL_BOOL, - e.hir_id, - e.span, - "this boolean expression can be simplified", - |diag| { - diag.span_suggestions( - e.span, - "try", - suggestions, - // nonminimal_bool can produce minimal but - // not human readable expressions (#3141) - Applicability::Unspecified, - ); - }, - ); - } - }; - if improvements.is_empty() { - let mut visitor = NotSimplificationVisitor { cx: self.cx }; - visitor.visit_expr(e); - } else { - nonminimal_bool_lint( - improvements - .into_iter() - .map(|suggestion| suggest(self.cx, suggestion, &h2q.terminals)) - .collect(), - ); - } - } - } -} - -impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { - fn visit_expr(&mut self, e: &'tcx Expr<'_>) { - if !e.span.from_expansion() { - match &e.kind { - ExprKind::Binary(binop, _, _) if binop.node == BinOpKind::Or || binop.node == BinOpKind::And => { - 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); - } - }, - _ => {}, - } - } - walk_expr(self, e); - } -} - -fn implements_ord(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - let ty = cx.typeck_results().expr_ty(expr); - cx.tcx - .get_diagnostic_item(sym::Ord) - .map_or(false, |id| implements_trait(cx, ty, id, &[])) -} - -struct NotSimplificationVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, -} - -impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind - && !expr.span.from_expansion() - && !inner.span.from_expansion() - && let Some(suggestion) = simplify_not(self.cx, inner) - && self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).0 != Level::Allow - { - span_lint_and_sugg( - self.cx, - NONMINIMAL_BOOL, - expr.span, - "this boolean expression can be simplified", - "try", - suggestion, - Applicability::MachineApplicable, - ); - } - - walk_expr(self, expr); - } -} diff --git a/clippy_lints/src/borrow_deref_ref.rs b/clippy_lints/src/borrow_deref_ref.rs deleted file mode 100644 index 0ca4a0e067d3..000000000000 --- a/clippy_lints/src/borrow_deref_ref.rs +++ /dev/null @@ -1,112 +0,0 @@ -use crate::reference::DEREF_ADDROF; -use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::snippet_opt; -use clippy_utils::ty::implements_trait; -use clippy_utils::{get_parent_expr, is_from_proc_macro, is_lint_allowed}; -use rustc_errors::Applicability; -use rustc_hir::{ExprKind, UnOp}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::mir::Mutability; -use rustc_middle::ty; -use rustc_session::declare_lint_pass; - -declare_clippy_lint! { - /// ### What it does - /// Checks for `&*(&T)`. - /// - /// ### Why is this bad? - /// Dereferencing and then borrowing a reference value has no effect in most cases. - /// - /// ### Known problems - /// False negative on such code: - /// ```no_run - /// let x = &12; - /// let addr_x = &x as *const _ as usize; - /// let addr_y = &&*x as *const _ as usize; // assert ok now, and lint triggered. - /// // But if we fix it, assert will fail. - /// assert_ne!(addr_x, addr_y); - /// ``` - /// - /// ### Example - /// ```no_run - /// let s = &String::new(); - /// - /// let a: &String = &* s; - /// ``` - /// - /// Use instead: - /// ```no_run - /// # let s = &String::new(); - /// let a: &String = s; - /// ``` - #[clippy::version = "1.63.0"] - pub BORROW_DEREF_REF, - complexity, - "deref on an immutable reference returns the same type as itself" -} - -declare_lint_pass!(BorrowDerefRef => [BORROW_DEREF_REF]); - -impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &rustc_hir::Expr<'tcx>) { - if !e.span.from_expansion() - && let ExprKind::AddrOf(_, Mutability::Not, addrof_target) = e.kind - && !addrof_target.span.from_expansion() - && let ExprKind::Unary(UnOp::Deref, deref_target) = addrof_target.kind - && !deref_target.span.from_expansion() - && !matches!(deref_target.kind, ExprKind::Unary(UnOp::Deref, ..)) - && let ref_ty = cx.typeck_results().expr_ty(deref_target) - && let ty::Ref(_, inner_ty, Mutability::Not) = ref_ty.kind() - { - if let Some(parent_expr) = get_parent_expr(cx, e) { - if matches!(parent_expr.kind, ExprKind::Unary(UnOp::Deref, ..)) - && !is_lint_allowed(cx, DEREF_ADDROF, parent_expr.hir_id) - { - return; - } - - // modification to `&mut &*x` is different from `&mut x` - if matches!( - deref_target.kind, - ExprKind::Path(..) | ExprKind::Field(..) | ExprKind::Index(..) | ExprKind::Unary(UnOp::Deref, ..) - ) && matches!(parent_expr.kind, ExprKind::AddrOf(_, Mutability::Mut, _)) - { - return; - } - } - if is_from_proc_macro(cx, e) { - return; - } - - span_lint_and_then( - cx, - BORROW_DEREF_REF, - e.span, - "deref on an immutable reference", - |diag| { - diag.span_suggestion( - e.span, - "if you would like to reborrow, try removing `&*`", - snippet_opt(cx, deref_target.span).unwrap(), - Applicability::MachineApplicable, - ); - - // has deref trait -> give 2 help - // doesn't have deref trait -> give 1 help - if let Some(deref_trait_id) = cx.tcx.lang_items().deref_trait() { - if !implements_trait(cx, *inner_ty, deref_trait_id, &[]) { - return; - } - } - - diag.span_suggestion( - e.span, - "if you would like to deref, try using `&**`", - format!("&**{}", &snippet_opt(cx, deref_target.span).unwrap()), - Applicability::MaybeIncorrect, - ); - }, - ); - } - } -} diff --git a/clippy_lints/src/box_default.rs b/clippy_lints/src/box_default.rs deleted file mode 100644 index 8459f051d3d9..000000000000 --- a/clippy_lints/src/box_default.rs +++ /dev/null @@ -1,133 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::macros::macro_backtrace; -use clippy_utils::ty::expr_sig; -use clippy_utils::{is_default_equivalent, path_def_id}; -use rustc_errors::Applicability; -use rustc_hir::def::Res; -use rustc_hir::intravisit::{walk_ty, Visitor}; -use rustc_hir::{Block, Expr, ExprKind, LetStmt, Node, QPath, Ty, TyKind}; -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 `Box::new(Default::default())`, which can be written as - /// `Box::default()`. - /// - /// ### Why is this bad? - /// `Box::default()` is equivalent and more concise. - /// - /// ### Example - /// ```no_run - /// let x: Box = Box::new(Default::default()); - /// ``` - /// Use instead: - /// ```no_run - /// let x: Box = Box::default(); - /// ``` - #[clippy::version = "1.66.0"] - pub BOX_DEFAULT, - style, - "Using Box::new(T::default()) instead of Box::default()" -} - -declare_lint_pass!(BoxDefault => [BOX_DEFAULT]); - -impl LateLintPass<'_> for BoxDefault { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - // If the expression is a call (`Box::new(...)`) - if let ExprKind::Call(box_new, [arg]) = expr.kind - // And call is of the form `::something` - // Here, it would be `::new` - && let ExprKind::Path(QPath::TypeRelative(ty, seg)) = box_new.kind - // And that method is `new` - && seg.ident.name == sym::new - // And the call is that of a `Box` method - && path_def_id(cx, ty).map_or(false, |id| Some(id) == cx.tcx.lang_items().owned_box()) - // And the single argument to the call is another function call - // This is the `T::default()` of `Box::new(T::default())` - && let ExprKind::Call(arg_path, _) = arg.kind - // And we are not in a foreign crate's macro - && !in_external_macro(cx.sess(), expr.span) - // And the argument expression has the same context as the outer call expression - // or that we are inside a `vec!` macro expansion - && (expr.span.eq_ctxt(arg.span) || is_local_vec_expn(cx, arg, expr)) - // And the argument is `Default::default()` or the type is specified - && (is_plain_default(cx, arg_path) || (given_type(cx, expr) && is_default_equivalent(cx, arg))) - { - span_lint_and_sugg( - cx, - BOX_DEFAULT, - expr.span, - "`Box::new(_)` of default value", - "try", - "Box::default()".into(), - Applicability::MachineApplicable, - ); - } - } -} - -fn is_plain_default(cx: &LateContext<'_>, arg_path: &Expr<'_>) -> bool { - // we need to match the actual path so we don't match e.g. "u8::default" - if let ExprKind::Path(QPath::Resolved(None, path)) = &arg_path.kind - && let Res::Def(_, def_id) = path.res - { - // avoid generic parameters - cx.tcx.is_diagnostic_item(sym::default_fn, def_id) && path.segments.iter().all(|seg| seg.args.is_none()) - } else { - false - } -} - -fn is_local_vec_expn(cx: &LateContext<'_>, expr: &Expr<'_>, ref_expr: &Expr<'_>) -> bool { - macro_backtrace(expr.span).next().map_or(false, |call| { - cx.tcx.is_diagnostic_item(sym::vec_macro, call.def_id) && call.span.eq_ctxt(ref_expr.span) - }) -} - -#[derive(Default)] -struct InferVisitor(bool); - -impl<'tcx> Visitor<'tcx> for InferVisitor { - fn visit_ty(&mut self, t: &Ty<'_>) { - self.0 |= matches!(t.kind, TyKind::Infer | TyKind::OpaqueDef(..) | TyKind::TraitObject(..)); - if !self.0 { - walk_ty(self, t); - } - } -} - -fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - match cx.tcx.parent_hir_node(expr.hir_id) { - Node::LetStmt(LetStmt { ty: Some(ty), .. }) => { - let mut v = InferVisitor::default(); - v.visit_ty(ty); - !v.0 - }, - Node::Expr(Expr { - kind: ExprKind::Call(path, args), - .. - }) - | Node::Block(Block { - expr: Some(Expr { - kind: ExprKind::Call(path, args), - .. - }), - .. - }) => { - if let Some(index) = args.iter().position(|arg| arg.hir_id == expr.hir_id) - && let Some(sig) = expr_sig(cx, path) - && let Some(input) = sig.input(index) - && let Some(input_ty) = input.no_bound_vars() - { - input_ty == cx.typeck_results().expr_ty_adjusted(expr) - } else { - false - } - }, - _ => false, - } -} diff --git a/clippy_lints/src/cargo/common_metadata.rs b/clippy_lints/src/cargo/common_metadata.rs deleted file mode 100644 index 3af2d8c02568..000000000000 --- a/clippy_lints/src/cargo/common_metadata.rs +++ /dev/null @@ -1,54 +0,0 @@ -//! lint on missing cargo common metadata - -use cargo_metadata::Metadata; -use clippy_utils::diagnostics::span_lint; -use rustc_lint::LateContext; -use rustc_span::DUMMY_SP; - -use super::CARGO_COMMON_METADATA; - -pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata, ignore_publish: bool) { - for package in &metadata.packages { - // only run the lint if publish is `None` (`publish = true` or skipped entirely) - // or if the vector isn't empty (`publish = ["something"]`) - if package.publish.as_ref().filter(|publish| publish.is_empty()).is_none() || ignore_publish { - if is_empty_str(&package.description) { - missing_warning(cx, package, "package.description"); - } - - if is_empty_str(&package.license) && is_empty_str(&package.license_file) { - missing_warning(cx, package, "either package.license or package.license_file"); - } - - if is_empty_str(&package.repository) { - missing_warning(cx, package, "package.repository"); - } - - if is_empty_str(&package.readme) { - missing_warning(cx, package, "package.readme"); - } - - if is_empty_vec(&package.keywords) { - missing_warning(cx, package, "package.keywords"); - } - - if is_empty_vec(&package.categories) { - missing_warning(cx, package, "package.categories"); - } - } - } -} - -fn missing_warning(cx: &LateContext<'_>, package: &cargo_metadata::Package, field: &str) { - let message = format!("package `{}` is missing `{field}` metadata", package.name); - span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, message); -} - -fn is_empty_str>(value: &Option) -> bool { - value.as_ref().map_or(true, |s| s.as_ref().is_empty()) -} - -fn is_empty_vec(value: &[String]) -> bool { - // This works because empty iterators return true - value.iter().all(String::is_empty) -} diff --git a/clippy_lints/src/cargo/feature_name.rs b/clippy_lints/src/cargo/feature_name.rs deleted file mode 100644 index 6982b96dd3b3..000000000000 --- a/clippy_lints/src/cargo/feature_name.rs +++ /dev/null @@ -1,90 +0,0 @@ -use cargo_metadata::Metadata; -use clippy_utils::diagnostics::span_lint_and_help; -use rustc_lint::LateContext; -use rustc_span::DUMMY_SP; - -use super::{NEGATIVE_FEATURE_NAMES, REDUNDANT_FEATURE_NAMES}; - -static PREFIXES: [&str; 8] = ["no-", "no_", "not-", "not_", "use-", "use_", "with-", "with_"]; -static SUFFIXES: [&str; 2] = ["-support", "_support"]; - -pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata) { - for package in &metadata.packages { - let mut features: Vec<&String> = package.features.keys().collect(); - features.sort(); - for feature in features { - let prefix_opt = { - let i = PREFIXES.partition_point(|prefix| prefix < &feature.as_str()); - if i > 0 && feature.starts_with(PREFIXES[i - 1]) { - Some(PREFIXES[i - 1]) - } else { - None - } - }; - if let Some(prefix) = prefix_opt { - lint(cx, feature, prefix, true); - } - - let suffix_opt: Option<&str> = { - let i = SUFFIXES.partition_point(|suffix| { - suffix.bytes().rev().cmp(feature.bytes().rev()) == std::cmp::Ordering::Less - }); - if i > 0 && feature.ends_with(SUFFIXES[i - 1]) { - Some(SUFFIXES[i - 1]) - } else { - None - } - }; - if let Some(suffix) = suffix_opt { - lint(cx, feature, suffix, false); - } - } - } -} - -fn is_negative_prefix(s: &str) -> bool { - s.starts_with("no") -} - -fn lint(cx: &LateContext<'_>, feature: &str, substring: &str, is_prefix: bool) { - let is_negative = is_prefix && is_negative_prefix(substring); - span_lint_and_help( - cx, - if is_negative { - NEGATIVE_FEATURE_NAMES - } else { - REDUNDANT_FEATURE_NAMES - }, - DUMMY_SP, - format!( - "the \"{substring}\" {} in the feature name \"{feature}\" is {}", - if is_prefix { "prefix" } else { "suffix" }, - if is_negative { "negative" } else { "redundant" } - ), - None, - format!( - "consider renaming the feature to \"{}\"{}", - if is_prefix { - feature.strip_prefix(substring) - } else { - feature.strip_suffix(substring) - } - .unwrap(), - if is_negative { - ", but make sure the feature adds functionality" - } else { - "" - } - ), - ); -} - -#[test] -fn test_prefixes_sorted() { - let mut sorted_prefixes = PREFIXES; - sorted_prefixes.sort_unstable(); - assert_eq!(PREFIXES, sorted_prefixes); - let mut sorted_suffixes = SUFFIXES; - sorted_suffixes.sort_by(|a, b| a.bytes().rev().cmp(b.bytes().rev())); - assert_eq!(SUFFIXES, sorted_suffixes); -} diff --git a/clippy_lints/src/cargo/lint_groups_priority.rs b/clippy_lints/src/cargo/lint_groups_priority.rs deleted file mode 100644 index 0d9eaac882f7..000000000000 --- a/clippy_lints/src/cargo/lint_groups_priority.rs +++ /dev/null @@ -1,179 +0,0 @@ -use super::LINT_GROUPS_PRIORITY; -use clippy_utils::diagnostics::span_lint_and_then; -use rustc_data_structures::fx::FxHashSet; -use rustc_errors::Applicability; -use rustc_lint::{unerased_lint_store, LateContext}; -use rustc_span::{BytePos, Pos, SourceFile, Span, SyntaxContext}; -use serde::{Deserialize, Serialize}; -use std::collections::BTreeMap; -use std::ops::Range; -use std::path::Path; -use toml::Spanned; - -#[derive(Deserialize, Serialize, Debug)] -struct LintConfigTable { - level: String, - priority: Option, -} - -#[derive(Deserialize, Debug)] -#[serde(untagged)] -enum LintConfig { - Level(String), - Table(LintConfigTable), -} - -impl LintConfig { - fn level(&self) -> &str { - match self { - LintConfig::Level(level) => level, - LintConfig::Table(table) => &table.level, - } - } - - fn priority(&self) -> i64 { - match self { - LintConfig::Level(_) => 0, - LintConfig::Table(table) => table.priority.unwrap_or(0), - } - } - - fn is_implicit(&self) -> bool { - if let LintConfig::Table(table) = self { - table.priority.is_none() - } else { - true - } - } -} - -type LintTable = BTreeMap, Spanned>; - -#[derive(Deserialize, Debug, Default)] -struct Lints { - #[serde(default)] - rust: LintTable, - #[serde(default)] - clippy: LintTable, -} - -#[derive(Deserialize, Debug, Default)] -struct Workspace { - #[serde(default)] - lints: Lints, -} - -#[derive(Deserialize, Debug)] -struct CargoToml { - #[serde(default)] - lints: Lints, - #[serde(default)] - workspace: Workspace, -} - -#[derive(Default, Debug)] -struct LintsAndGroups { - lints: Vec>, - groups: Vec<(Spanned, Spanned)>, -} - -fn toml_span(range: Range, file: &SourceFile) -> Span { - Span::new( - file.start_pos + BytePos::from_usize(range.start), - file.start_pos + BytePos::from_usize(range.end), - SyntaxContext::root(), - None, - ) -} - -fn check_table(cx: &LateContext<'_>, table: LintTable, groups: &FxHashSet<&str>, file: &SourceFile) { - let mut by_priority = BTreeMap::<_, LintsAndGroups>::new(); - for (name, config) in table { - let lints_and_groups = by_priority.entry(config.as_ref().priority()).or_default(); - if groups.contains(name.get_ref().as_str()) { - lints_and_groups.groups.push((name, config)); - } else { - lints_and_groups.lints.push(name); - } - } - let low_priority = by_priority - .iter() - .find(|(_, lints_and_groups)| !lints_and_groups.lints.is_empty()) - .map_or(-1, |(&lowest_lint_priority, _)| lowest_lint_priority - 1); - - for (priority, LintsAndGroups { lints, groups }) in by_priority { - let Some(last_lint_alphabetically) = lints.last() else { - continue; - }; - - for (group, config) in groups { - span_lint_and_then( - cx, - LINT_GROUPS_PRIORITY, - toml_span(group.span(), file), - format!( - "lint group `{}` has the same priority ({priority}) as a lint", - group.as_ref() - ), - |diag| { - let config_span = toml_span(config.span(), file); - if config.as_ref().is_implicit() { - diag.span_label(config_span, "has an implicit priority of 0"); - } - // add the label to next lint after this group that has the same priority - let lint = lints - .iter() - .filter(|lint| lint.span().start > group.span().start) - .min_by_key(|lint| lint.span().start) - .unwrap_or(last_lint_alphabetically); - diag.span_label(toml_span(lint.span(), file), "has the same priority as this lint"); - diag.note("the order of the lints in the table is ignored by Cargo"); - let mut suggestion = String::new(); - Serialize::serialize( - &LintConfigTable { - level: config.as_ref().level().into(), - priority: Some(low_priority), - }, - toml::ser::ValueSerializer::new(&mut suggestion), - ) - .unwrap(); - diag.span_suggestion_verbose( - config_span, - format!( - "to have lints override the group set `{}` to a lower priority", - group.as_ref() - ), - suggestion, - Applicability::MaybeIncorrect, - ); - }, - ); - } - } -} - -pub fn check(cx: &LateContext<'_>) { - if let Ok(file) = cx.tcx.sess.source_map().load_file(Path::new("Cargo.toml")) - && let Some(src) = file.src.as_deref() - && let Ok(cargo_toml) = toml::from_str::(src) - { - let mut rustc_groups = FxHashSet::default(); - let mut clippy_groups = FxHashSet::default(); - for (group, ..) in unerased_lint_store(cx.tcx.sess).get_lint_groups() { - match group.split_once("::") { - None => { - rustc_groups.insert(group); - }, - Some(("clippy", group)) => { - clippy_groups.insert(group); - }, - _ => {}, - } - } - - check_table(cx, cargo_toml.lints.rust, &rustc_groups, &file); - check_table(cx, cargo_toml.lints.clippy, &clippy_groups, &file); - check_table(cx, cargo_toml.workspace.lints.rust, &rustc_groups, &file); - check_table(cx, cargo_toml.workspace.lints.clippy, &clippy_groups, &file); - } -} diff --git a/clippy_lints/src/cargo/mod.rs b/clippy_lints/src/cargo/mod.rs deleted file mode 100644 index 593bc6c81ee8..000000000000 --- a/clippy_lints/src/cargo/mod.rs +++ /dev/null @@ -1,266 +0,0 @@ -mod common_metadata; -mod feature_name; -mod lint_groups_priority; -mod multiple_crate_versions; -mod wildcard_dependencies; - -use cargo_metadata::MetadataCommand; -use clippy_utils::diagnostics::span_lint; -use clippy_utils::is_lint_allowed; -use rustc_data_structures::fx::FxHashSet; -use rustc_hir::hir_id::CRATE_HIR_ID; -use rustc_lint::{LateContext, LateLintPass, Lint}; -use rustc_session::impl_lint_pass; -use rustc_span::DUMMY_SP; - -declare_clippy_lint! { - /// ### What it does - /// Checks to see if all common metadata is defined in - /// `Cargo.toml`. See: https://rust-lang-nursery.github.io/api-guidelines/documentation.html#cargotoml-includes-all-common-metadata-c-metadata - /// - /// ### Why is this bad? - /// It will be more difficult for users to discover the - /// purpose of the crate, and key information related to it. - /// - /// ### Example - /// ```toml - /// # This `Cargo.toml` is missing a description field: - /// [package] - /// name = "clippy" - /// version = "0.0.212" - /// repository = "https://github.com/rust-lang/rust-clippy" - /// readme = "README.md" - /// license = "MIT OR Apache-2.0" - /// keywords = ["clippy", "lint", "plugin"] - /// categories = ["development-tools", "development-tools::cargo-plugins"] - /// ``` - /// - /// Should include a description field like: - /// - /// ```toml - /// # This `Cargo.toml` includes all common metadata - /// [package] - /// name = "clippy" - /// version = "0.0.212" - /// description = "A bunch of helpful lints to avoid common pitfalls in Rust" - /// repository = "https://github.com/rust-lang/rust-clippy" - /// readme = "README.md" - /// license = "MIT OR Apache-2.0" - /// keywords = ["clippy", "lint", "plugin"] - /// categories = ["development-tools", "development-tools::cargo-plugins"] - /// ``` - #[clippy::version = "1.32.0"] - pub CARGO_COMMON_METADATA, - cargo, - "common metadata is defined in `Cargo.toml`" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for feature names with prefix `use-`, `with-` or suffix `-support` - /// - /// ### Why is this bad? - /// These prefixes and suffixes have no significant meaning. - /// - /// ### Example - /// ```toml - /// # The `Cargo.toml` with feature name redundancy - /// [features] - /// default = ["use-abc", "with-def", "ghi-support"] - /// use-abc = [] // redundant - /// with-def = [] // redundant - /// ghi-support = [] // redundant - /// ``` - /// - /// Use instead: - /// ```toml - /// [features] - /// default = ["abc", "def", "ghi"] - /// abc = [] - /// def = [] - /// ghi = [] - /// ``` - /// - #[clippy::version = "1.57.0"] - pub REDUNDANT_FEATURE_NAMES, - cargo, - "usage of a redundant feature name" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for negative feature names with prefix `no-` or `not-` - /// - /// ### Why is this bad? - /// Features are supposed to be additive, and negatively-named features violate it. - /// - /// ### Example - /// ```toml - /// # The `Cargo.toml` with negative feature names - /// [features] - /// default = [] - /// no-abc = [] - /// not-def = [] - /// - /// ``` - /// Use instead: - /// ```toml - /// [features] - /// default = ["abc", "def"] - /// abc = [] - /// def = [] - /// - /// ``` - #[clippy::version = "1.57.0"] - pub NEGATIVE_FEATURE_NAMES, - cargo, - "usage of a negative feature name" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks to see if multiple versions of a crate are being - /// used. - /// - /// ### Why is this bad? - /// This bloats the size of targets, and can lead to - /// confusing error messages when structs or traits are used interchangeably - /// between different versions of a crate. - /// - /// ### Known problems - /// Because this can be caused purely by the dependencies - /// themselves, it's not always possible to fix this issue. - /// In those cases, you can allow that specific crate using - /// the `allowed_duplicate_crates` configuration option. - /// - /// ### Example - /// ```toml - /// # This will pull in both winapi v0.3.x and v0.2.x, triggering a warning. - /// [dependencies] - /// ctrlc = "=3.1.0" - /// ansi_term = "=0.11.0" - /// ``` - #[clippy::version = "pre 1.29.0"] - pub MULTIPLE_CRATE_VERSIONS, - cargo, - "multiple versions of the same crate being used" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for wildcard dependencies in the `Cargo.toml`. - /// - /// ### Why is this bad? - /// [As the edition guide says](https://rust-lang-nursery.github.io/edition-guide/rust-2018/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.html), - /// it is highly unlikely that you work with any possible version of your dependency, - /// and wildcard dependencies would cause unnecessary breakage in the ecosystem. - /// - /// ### Example - /// ```toml - /// [dependencies] - /// regex = "*" - /// ``` - #[clippy::version = "1.32.0"] - pub WILDCARD_DEPENDENCIES, - cargo, - "wildcard dependencies being used" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for lint groups with the same priority as lints in the `Cargo.toml` - /// [`[lints]` table](https://doc.rust-lang.org/cargo/reference/manifest.html#the-lints-section). - /// - /// This lint will be removed once [cargo#12918](https://github.com/rust-lang/cargo/issues/12918) - /// is resolved. - /// - /// ### Why is this bad? - /// The order of lints in the `[lints]` is ignored, to have a lint override a group the - /// `priority` field needs to be used, otherwise the sort order is undefined. - /// - /// ### Known problems - /// Does not check lints inherited using `lints.workspace = true` - /// - /// ### Example - /// ```toml - /// # Passed as `--allow=clippy::similar_names --warn=clippy::pedantic` - /// # which results in `similar_names` being `warn` - /// [lints.clippy] - /// pedantic = "warn" - /// similar_names = "allow" - /// ``` - /// Use instead: - /// ```toml - /// # Passed as `--warn=clippy::pedantic --allow=clippy::similar_names` - /// # which results in `similar_names` being `allow` - /// [lints.clippy] - /// pedantic = { level = "warn", priority = -1 } - /// similar_names = "allow" - /// ``` - #[clippy::version = "1.78.0"] - pub LINT_GROUPS_PRIORITY, - correctness, - "a lint group in `Cargo.toml` at the same priority as a lint" -} - -pub struct Cargo { - pub allowed_duplicate_crates: FxHashSet, - pub ignore_publish: bool, -} - -impl_lint_pass!(Cargo => [ - CARGO_COMMON_METADATA, - REDUNDANT_FEATURE_NAMES, - NEGATIVE_FEATURE_NAMES, - MULTIPLE_CRATE_VERSIONS, - WILDCARD_DEPENDENCIES, - LINT_GROUPS_PRIORITY, -]); - -impl LateLintPass<'_> for Cargo { - fn check_crate(&mut self, cx: &LateContext<'_>) { - static NO_DEPS_LINTS: &[&Lint] = &[ - CARGO_COMMON_METADATA, - REDUNDANT_FEATURE_NAMES, - NEGATIVE_FEATURE_NAMES, - WILDCARD_DEPENDENCIES, - ]; - static WITH_DEPS_LINTS: &[&Lint] = &[MULTIPLE_CRATE_VERSIONS]; - - lint_groups_priority::check(cx); - - if !NO_DEPS_LINTS - .iter() - .all(|&lint| is_lint_allowed(cx, lint, CRATE_HIR_ID)) - { - match MetadataCommand::new().no_deps().exec() { - Ok(metadata) => { - common_metadata::check(cx, &metadata, self.ignore_publish); - feature_name::check(cx, &metadata); - wildcard_dependencies::check(cx, &metadata); - }, - Err(e) => { - for lint in NO_DEPS_LINTS { - span_lint(cx, lint, DUMMY_SP, format!("could not read cargo metadata: {e}")); - } - }, - } - } - - if !WITH_DEPS_LINTS - .iter() - .all(|&lint| is_lint_allowed(cx, lint, CRATE_HIR_ID)) - { - match MetadataCommand::new().exec() { - Ok(metadata) => { - multiple_crate_versions::check(cx, &metadata, &self.allowed_duplicate_crates); - }, - Err(e) => { - for lint in WITH_DEPS_LINTS { - span_lint(cx, lint, DUMMY_SP, format!("could not read cargo metadata: {e}")); - } - }, - } - } - } -} diff --git a/clippy_lints/src/cargo/multiple_crate_versions.rs b/clippy_lints/src/cargo/multiple_crate_versions.rs deleted file mode 100644 index 2769463c8a53..000000000000 --- a/clippy_lints/src/cargo/multiple_crate_versions.rs +++ /dev/null @@ -1,77 +0,0 @@ -//! lint on multiple versions of a crate being used - -use cargo_metadata::{DependencyKind, Metadata, Node, Package, PackageId}; -use clippy_utils::diagnostics::span_lint; -use itertools::Itertools; -use rustc_data_structures::fx::FxHashSet; -use rustc_hir::def_id::LOCAL_CRATE; -use rustc_lint::LateContext; -use rustc_span::DUMMY_SP; - -use super::MULTIPLE_CRATE_VERSIONS; - -pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata, allowed_duplicate_crates: &FxHashSet) { - let local_name = cx.tcx.crate_name(LOCAL_CRATE); - let mut packages = metadata.packages.clone(); - packages.sort_by(|a, b| a.name.cmp(&b.name)); - - if let Some(resolve) = &metadata.resolve - && let Some(local_id) = packages.iter().find_map(|p| { - // p.name contains the original crate names with dashes intact - // local_name contains the crate name as a namespace, with the dashes converted to underscores - // the code below temporarily rectifies this discrepancy - if p.name - .as_bytes() - .iter() - .map(|b| if b == &b'-' { &b'_' } else { b }) - .eq(local_name.as_str().as_bytes()) - { - Some(&p.id) - } else { - None - } - }) - { - for (name, group) in &packages - .iter() - .filter(|p| !allowed_duplicate_crates.contains(&p.name)) - .group_by(|p| &p.name) - { - let group: Vec<&Package> = group.collect(); - - if group.len() <= 1 { - continue; - } - - if group.iter().all(|p| is_normal_dep(&resolve.nodes, local_id, &p.id)) { - let mut versions: Vec<_> = group.into_iter().map(|p| &p.version).collect(); - versions.sort(); - let versions = versions.iter().join(", "); - - span_lint( - cx, - MULTIPLE_CRATE_VERSIONS, - DUMMY_SP, - format!("multiple versions for dependency `{name}`: {versions}"), - ); - } - } - } -} - -fn is_normal_dep(nodes: &[Node], local_id: &PackageId, dep_id: &PackageId) -> bool { - fn depends_on(node: &Node, dep_id: &PackageId) -> bool { - node.deps.iter().any(|dep| { - dep.pkg == *dep_id - && dep - .dep_kinds - .iter() - .any(|info| matches!(info.kind, DependencyKind::Normal)) - }) - } - - nodes - .iter() - .filter(|node| depends_on(node, dep_id)) - .any(|node| node.id == *local_id || is_normal_dep(nodes, local_id, &node.id)) -} diff --git a/clippy_lints/src/cargo/wildcard_dependencies.rs b/clippy_lints/src/cargo/wildcard_dependencies.rs deleted file mode 100644 index 0cf687d01928..000000000000 --- a/clippy_lints/src/cargo/wildcard_dependencies.rs +++ /dev/null @@ -1,24 +0,0 @@ -use cargo_metadata::Metadata; -use clippy_utils::diagnostics::span_lint; -use rustc_lint::LateContext; -use rustc_span::DUMMY_SP; - -use super::WILDCARD_DEPENDENCIES; - -pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata) { - for dep in &metadata.packages[0].dependencies { - // VersionReq::any() does not work - if let Ok(wildcard_ver) = semver::VersionReq::parse("*") - && let Some(ref source) = dep.source - && !source.starts_with("git") - && dep.req == wildcard_ver - { - span_lint( - cx, - WILDCARD_DEPENDENCIES, - DUMMY_SP, - format!("wildcard dependency for `{}`", dep.name), - ); - } - } -} diff --git a/clippy_lints/src/casts/as_ptr_cast_mut.rs b/clippy_lints/src/casts/as_ptr_cast_mut.rs deleted file mode 100644 index f05fd3fcde50..000000000000 --- a/clippy_lints/src/casts/as_ptr_cast_mut.rs +++ /dev/null @@ -1,37 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::snippet_opt; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::LateContext; -use rustc_middle::mir::Mutability; -use rustc_middle::ty::{self, Ty}; - -use super::AS_PTR_CAST_MUT; - -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>) { - if let ty::RawPtr(ptrty, Mutability::Mut) = cast_to.kind() - && let ty::RawPtr(_, Mutability::Not) = cx.typeck_results().node_type(cast_expr.hir_id).kind() - && let ExprKind::MethodCall(method_name, receiver, [], _) = cast_expr.peel_blocks().kind - && method_name.ident.name == rustc_span::sym::as_ptr - && let Some(as_ptr_did) = cx - .typeck_results() - .type_dependent_def_id(cast_expr.peel_blocks().hir_id) - && let as_ptr_sig = cx.tcx.fn_sig(as_ptr_did).instantiate_identity() - && let Some(first_param_ty) = as_ptr_sig.skip_binder().inputs().iter().next() - && let ty::Ref(_, _, Mutability::Not) = first_param_ty.kind() - && let Some(recv) = snippet_opt(cx, receiver.span) - { - // `as_mut_ptr` might not exist - let applicability = Applicability::MaybeIncorrect; - - span_lint_and_sugg( - cx, - AS_PTR_CAST_MUT, - expr.span, - format!("casting the result of `as_ptr` to *mut {ptrty}"), - "replace with", - format!("{recv}.as_mut_ptr()"), - applicability, - ); - } -} diff --git a/clippy_lints/src/casts/as_underscore.rs b/clippy_lints/src/casts/as_underscore.rs deleted file mode 100644 index 56e894c6261e..000000000000 --- a/clippy_lints/src/casts/as_underscore.rs +++ /dev/null @@ -1,25 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_then; -use rustc_errors::Applicability; -use rustc_hir::{Expr, Ty, TyKind}; -use rustc_lint::LateContext; -use rustc_middle::ty; - -use super::AS_UNDERSCORE; - -pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, ty: &'tcx Ty<'_>) { - if matches!(ty.kind, TyKind::Infer) { - span_lint_and_then(cx, AS_UNDERSCORE, expr.span, "using `as _` conversion", |diag| { - let ty_resolved = cx.typeck_results().expr_ty(expr); - if let ty::Error(_) = ty_resolved.kind() { - diag.help("consider giving the type explicitly"); - } else { - diag.span_suggestion( - ty.span, - "consider giving the type explicitly", - ty_resolved, - Applicability::MachineApplicable, - ); - } - }); - } -} diff --git a/clippy_lints/src/casts/borrow_as_ptr.rs b/clippy_lints/src/casts/borrow_as_ptr.rs deleted file mode 100644 index b7256dd2eae9..000000000000 --- a/clippy_lints/src/casts/borrow_as_ptr.rs +++ /dev/null @@ -1,47 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::is_no_std_crate; -use clippy_utils::source::snippet_with_context; -use rustc_errors::Applicability; -use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, Ty, TyKind}; -use rustc_lint::LateContext; -use rustc_middle::ty::adjustment::Adjust; - -use super::BORROW_AS_PTR; - -pub(super) fn check<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx Expr<'_>, - cast_expr: &'tcx Expr<'_>, - cast_to: &'tcx Ty<'_>, -) { - if matches!(cast_to.kind, TyKind::Ptr(_)) - && let ExprKind::AddrOf(BorrowKind::Ref, mutability, e) = cast_expr.kind - { - let core_or_std = if is_no_std_crate(cx) { "core" } else { "std" }; - let macro_name = match mutability { - Mutability::Not => "addr_of", - Mutability::Mut => "addr_of_mut", - }; - let mut app = Applicability::MachineApplicable; - let snip = snippet_with_context(cx, e.span, cast_expr.span.ctxt(), "..", &mut app).0; - // Fix #9884 - if !e.is_place_expr(|base| { - cx.typeck_results() - .adjustments() - .get(base.hir_id) - .is_some_and(|x| x.iter().any(|adj| matches!(adj.kind, Adjust::Deref(_)))) - }) { - return; - } - - span_lint_and_sugg( - cx, - BORROW_AS_PTR, - expr.span, - "borrow as raw pointer", - "try", - format!("{core_or_std}::ptr::{macro_name}!({snip})"), - Applicability::MachineApplicable, - ); - } -} diff --git a/clippy_lints/src/casts/cast_abs_to_unsigned.rs b/clippy_lints/src/casts/cast_abs_to_unsigned.rs deleted file mode 100644 index d4d5ee37bccb..000000000000 --- a/clippy_lints/src/casts/cast_abs_to_unsigned.rs +++ /dev/null @@ -1,43 +0,0 @@ -use clippy_config::msrvs::{self, Msrv}; -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::sugg::Sugg; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty}; - -use super::CAST_ABS_TO_UNSIGNED; - -pub(super) fn check( - cx: &LateContext<'_>, - expr: &Expr<'_>, - cast_expr: &Expr<'_>, - cast_from: Ty<'_>, - cast_to: Ty<'_>, - msrv: &Msrv, -) { - if msrv.meets(msrvs::UNSIGNED_ABS) - && let ty::Int(from) = cast_from.kind() - && let ty::Uint(to) = cast_to.kind() - && let ExprKind::MethodCall(method_path, receiver, ..) = cast_expr.kind - && method_path.ident.name.as_str() == "abs" - { - let span = if from.bit_width() == to.bit_width() { - expr.span - } else { - // if the result of `.unsigned_abs` would be a different type, keep the cast - // e.g. `i64 -> usize`, `i16 -> u8` - cast_expr.span - }; - - span_lint_and_sugg( - cx, - CAST_ABS_TO_UNSIGNED, - span, - format!("casting the result of `{cast_from}::abs()` to {cast_to}"), - "replace with", - format!("{}.unsigned_abs()", Sugg::hir(cx, receiver, "..").maybe_par()), - Applicability::MachineApplicable, - ); - } -} diff --git a/clippy_lints/src/casts/cast_enum_constructor.rs b/clippy_lints/src/casts/cast_enum_constructor.rs deleted file mode 100644 index 1973692e105f..000000000000 --- a/clippy_lints/src/casts/cast_enum_constructor.rs +++ /dev/null @@ -1,21 +0,0 @@ -use clippy_utils::diagnostics::span_lint; -use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty}; - -use super::CAST_ENUM_CONSTRUCTOR; - -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_from: Ty<'_>) { - if matches!(cast_from.kind(), ty::FnDef(..)) - && let ExprKind::Path(path) = &cast_expr.kind - && let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Fn), _) = cx.qpath_res(path, cast_expr.hir_id) - { - span_lint( - cx, - CAST_ENUM_CONSTRUCTOR, - expr.span, - "cast of an enum tuple constructor to an integer", - ); - } -} diff --git a/clippy_lints/src/casts/cast_lossless.rs b/clippy_lints/src/casts/cast_lossless.rs deleted file mode 100644 index d52ad1c6f23f..000000000000 --- a/clippy_lints/src/casts/cast_lossless.rs +++ /dev/null @@ -1,121 +0,0 @@ -use clippy_config::msrvs::{self, Msrv}; -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::in_constant; -use clippy_utils::source::{snippet_opt, snippet_with_applicability}; -use clippy_utils::ty::is_isize_or_usize; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, QPath, TyKind}; -use rustc_lint::LateContext; -use rustc_middle::ty::{self, FloatTy, Ty, UintTy}; - -use super::{utils, CAST_LOSSLESS}; - -pub(super) fn check( - cx: &LateContext<'_>, - expr: &Expr<'_>, - cast_op: &Expr<'_>, - cast_from: Ty<'_>, - cast_to: Ty<'_>, - cast_to_hir: &rustc_hir::Ty<'_>, - msrv: &Msrv, -) { - if !should_lint(cx, expr, cast_from, cast_to, msrv) { - return; - } - - // The suggestion is to use a function call, so if the original expression - // has parens on the outside, they are no longer needed. - let mut app = Applicability::MachineApplicable; - let opt = snippet_opt(cx, cast_op.span.source_callsite()); - let sugg = opt.as_ref().map_or_else( - || { - app = Applicability::HasPlaceholders; - ".." - }, - |snip| { - if should_strip_parens(cast_op, snip) { - &snip[1..snip.len() - 1] - } else { - snip.as_str() - } - }, - ); - - // Display the type alias instead of the aliased type. Fixes #11285 - // - // FIXME: Once `lazy_type_alias` is stabilized(?) we should use `rustc_middle` types instead, - // this will allow us to display the right type with `cast_from` as well. - let cast_to_fmt = if let TyKind::Path(QPath::Resolved(None, path)) = cast_to_hir.kind - // It's a bit annoying but the turbofish is optional for types. A type in an `as` cast - // shouldn't have these if they're primitives, which are the only things we deal with. - // - // This could be removed for performance if this check is determined to have a pretty major - // effect. - && path.segments.iter().all(|segment| segment.args.is_none()) - { - snippet_with_applicability(cx, cast_to_hir.span, "..", &mut app) - } else { - cast_to.to_string().into() - }; - - let message = if cast_from.is_bool() { - format!("casting `{cast_from}` to `{cast_to_fmt}` is more cleanly stated with `{cast_to_fmt}::from(_)`") - } else { - format!("casting `{cast_from}` to `{cast_to_fmt}` may become silently lossy if you later change the type") - }; - - span_lint_and_sugg( - cx, - CAST_LOSSLESS, - expr.span, - message, - "try", - format!("{cast_to_fmt}::from({sugg})"), - app, - ); -} - -fn should_lint(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, msrv: &Msrv) -> bool { - // Do not suggest using From in consts/statics until it is valid to do so (see #2267). - // - // If destination is u128, do not lint because source type cannot be larger - // If source is bool, still lint due to the lint message differing (refers to style) - if in_constant(cx, expr.hir_id) || (!cast_from.is_bool() && matches!(cast_to.kind(), ty::Uint(UintTy::U128))) { - return false; - } - - match (cast_from.is_integral(), cast_to.is_integral()) { - (true, true) => { - let cast_signed_to_unsigned = cast_from.is_signed() && !cast_to.is_signed(); - let from_nbits = utils::int_ty_to_nbits(cast_from, cx.tcx); - let to_nbits = utils::int_ty_to_nbits(cast_to, cx.tcx); - !is_isize_or_usize(cast_from) - && !is_isize_or_usize(cast_to) - && from_nbits < to_nbits - && !cast_signed_to_unsigned - }, - - (true, false) => { - let from_nbits = utils::int_ty_to_nbits(cast_from, cx.tcx); - let to_nbits = if let ty::Float(FloatTy::F32) = cast_to.kind() { - 32 - } else { - 64 - }; - !is_isize_or_usize(cast_from) && from_nbits < to_nbits - }, - (false, true) if matches!(cast_from.kind(), ty::Bool) && msrv.meets(msrvs::FROM_BOOL) => true, - (_, _) => { - matches!(cast_from.kind(), ty::Float(FloatTy::F32)) && matches!(cast_to.kind(), ty::Float(FloatTy::F64)) - }, - } -} - -fn should_strip_parens(cast_expr: &Expr<'_>, snip: &str) -> bool { - if let ExprKind::Binary(_, _, _) = cast_expr.kind { - if snip.starts_with('(') && snip.ends_with(')') { - return true; - } - } - false -} diff --git a/clippy_lints/src/casts/cast_nan_to_int.rs b/clippy_lints/src/casts/cast_nan_to_int.rs deleted file mode 100644 index 1743ce71adde..000000000000 --- a/clippy_lints/src/casts/cast_nan_to_int.rs +++ /dev/null @@ -1,28 +0,0 @@ -use super::CAST_NAN_TO_INT; - -use clippy_utils::consts::{constant, Constant}; -use clippy_utils::diagnostics::span_lint_and_note; -use rustc_hir::Expr; -use rustc_lint::LateContext; -use rustc_middle::ty::Ty; - -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, from_ty: Ty<'_>, to_ty: Ty<'_>) { - if from_ty.is_floating_point() && to_ty.is_integral() && is_known_nan(cx, cast_expr) { - span_lint_and_note( - cx, - CAST_NAN_TO_INT, - expr.span, - format!("casting a known NaN to {to_ty}"), - None, - "this always evaluates to 0", - ); - } -} - -fn is_known_nan(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { - match constant(cx, cx.typeck_results(), e) { - Some(Constant::F64(n)) => n.is_nan(), - Some(Constant::F32(n)) => n.is_nan(), - _ => false, - } -} diff --git a/clippy_lints/src/casts/cast_possible_truncation.rs b/clippy_lints/src/casts/cast_possible_truncation.rs deleted file mode 100644 index 7c5acd1a678d..000000000000 --- a/clippy_lints/src/casts/cast_possible_truncation.rs +++ /dev/null @@ -1,201 +0,0 @@ -use clippy_utils::consts::{constant, Constant}; -use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; -use clippy_utils::expr_or_init; -use clippy_utils::source::snippet; -use clippy_utils::sugg::Sugg; -use clippy_utils::ty::{get_discriminant_value, is_isize_or_usize}; -use rustc_errors::{Applicability, Diag, SuggestionStyle}; -use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{BinOpKind, Expr, ExprKind}; -use rustc_lint::LateContext; -use rustc_middle::ty::{self, FloatTy, Ty}; -use rustc_span::Span; -use rustc_target::abi::IntegerType; - -use super::{utils, CAST_ENUM_TRUNCATION, CAST_POSSIBLE_TRUNCATION}; - -fn constant_int(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { - if let Some(Constant::Int(c)) = constant(cx, cx.typeck_results(), expr) { - Some(c) - } else { - None - } -} - -fn get_constant_bits(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { - constant_int(cx, expr).map(|c| u64::from(128 - c.leading_zeros())) -} - -fn apply_reductions(cx: &LateContext<'_>, nbits: u64, expr: &Expr<'_>, signed: bool) -> u64 { - match expr_or_init(cx, expr).kind { - ExprKind::Cast(inner, _) => apply_reductions(cx, nbits, inner, signed), - ExprKind::Block(block, _) => block.expr.map_or(nbits, |e| apply_reductions(cx, nbits, e, signed)), - ExprKind::Binary(op, left, right) => match op.node { - BinOpKind::Div => { - apply_reductions(cx, nbits, left, signed).saturating_sub(if signed { - // let's be conservative here - 0 - } else { - // by dividing by 1, we remove 0 bits, etc. - get_constant_bits(cx, right).map_or(0, |b| b.saturating_sub(1)) - }) - }, - BinOpKind::Rem => get_constant_bits(cx, right) - .unwrap_or(u64::MAX) - .min(apply_reductions(cx, nbits, left, signed)), - BinOpKind::BitAnd => get_constant_bits(cx, right) - .unwrap_or(u64::MAX) - .min(get_constant_bits(cx, left).unwrap_or(u64::MAX)) - .min(apply_reductions(cx, nbits, right, signed)) - .min(apply_reductions(cx, nbits, left, signed)), - BinOpKind::Shr => apply_reductions(cx, nbits, left, signed) - .saturating_sub(constant_int(cx, right).map_or(0, |s| u64::try_from(s).unwrap_or_default())), - _ => nbits, - }, - ExprKind::MethodCall(method, left, [right], _) => { - if signed { - return nbits; - } - let max_bits = if method.ident.as_str() == "min" { - get_constant_bits(cx, right) - } else { - None - }; - apply_reductions(cx, nbits, left, signed).min(max_bits.unwrap_or(u64::MAX)) - }, - ExprKind::MethodCall(method, _, [lo, hi], _) => { - if method.ident.as_str() == "clamp" { - //FIXME: make this a diagnostic item - if let (Some(lo_bits), Some(hi_bits)) = (get_constant_bits(cx, lo), get_constant_bits(cx, hi)) { - return lo_bits.max(hi_bits); - } - } - nbits - }, - ExprKind::MethodCall(method, _value, [], _) => { - if method.ident.name.as_str() == "signum" { - 0 // do not lint if cast comes from a `signum` function - } else { - nbits - } - }, - _ => nbits, - } -} - -pub(super) fn check( - cx: &LateContext<'_>, - expr: &Expr<'_>, - cast_expr: &Expr<'_>, - cast_from: Ty<'_>, - cast_to: Ty<'_>, - cast_to_span: Span, -) { - let msg = match (cast_from.kind(), cast_to.is_integral()) { - (ty::Int(_) | ty::Uint(_), true) => { - let from_nbits = apply_reductions( - cx, - utils::int_ty_to_nbits(cast_from, cx.tcx), - cast_expr, - cast_from.is_signed(), - ); - let to_nbits = utils::int_ty_to_nbits(cast_to, cx.tcx); - - let (should_lint, suffix) = match (is_isize_or_usize(cast_from), is_isize_or_usize(cast_to)) { - (true, true) | (false, false) => (to_nbits < from_nbits, ""), - (true, false) => ( - to_nbits <= 32, - if to_nbits == 32 { - " on targets with 64-bit wide pointers" - } else { - "" - }, - ), - (false, true) => (from_nbits == 64, " on targets with 32-bit wide pointers"), - }; - - if !should_lint { - return; - } - - format!("casting `{cast_from}` to `{cast_to}` may truncate the value{suffix}",) - }, - - (ty::Adt(def, _), true) if def.is_enum() => { - let (from_nbits, variant) = if let ExprKind::Path(p) = &cast_expr.kind - && let Res::Def(DefKind::Ctor(..), id) = cx.qpath_res(p, cast_expr.hir_id) - { - let i = def.variant_index_with_ctor_id(id); - let variant = def.variant(i); - let nbits = utils::enum_value_nbits(get_discriminant_value(cx.tcx, *def, i)); - (nbits, Some(variant)) - } else { - (utils::enum_ty_to_nbits(*def, cx.tcx), None) - }; - let to_nbits = utils::int_ty_to_nbits(cast_to, cx.tcx); - - let cast_from_ptr_size = def.repr().int.map_or(true, |ty| matches!(ty, IntegerType::Pointer(_),)); - let suffix = match (cast_from_ptr_size, is_isize_or_usize(cast_to)) { - (_, false) if from_nbits > to_nbits => "", - (false, true) if from_nbits > 64 => "", - (false, true) if from_nbits > 32 => " on targets with 32-bit wide pointers", - _ => return, - }; - - if let Some(variant) = variant { - span_lint( - cx, - CAST_ENUM_TRUNCATION, - expr.span, - format!( - "casting `{cast_from}::{}` to `{cast_to}` will truncate the value{suffix}", - variant.name, - ), - ); - return; - } - format!("casting `{cast_from}` to `{cast_to}` may truncate the value{suffix}") - }, - - (ty::Float(_), true) => { - format!("casting `{cast_from}` to `{cast_to}` may truncate the value") - }, - - (ty::Float(FloatTy::F64), false) if matches!(cast_to.kind(), &ty::Float(FloatTy::F32)) => { - "casting `f64` to `f32` may truncate the value".to_string() - }, - - _ => return, - }; - - span_lint_and_then(cx, CAST_POSSIBLE_TRUNCATION, expr.span, msg, |diag| { - diag.help("if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ..."); - if !cast_from.is_floating_point() { - offer_suggestion(cx, expr, cast_expr, cast_to_span, diag); - } - }); -} - -fn offer_suggestion( - cx: &LateContext<'_>, - expr: &Expr<'_>, - cast_expr: &Expr<'_>, - cast_to_span: Span, - diag: &mut Diag<'_, ()>, -) { - let cast_to_snip = snippet(cx, cast_to_span, ".."); - let suggestion = if cast_to_snip == "_" { - format!("{}.try_into()", Sugg::hir(cx, cast_expr, "..").maybe_par()) - } else { - format!("{cast_to_snip}::try_from({})", Sugg::hir(cx, cast_expr, "..")) - }; - - diag.span_suggestion_with_style( - expr.span, - "... or use `try_from` and handle the error accordingly", - suggestion, - Applicability::Unspecified, - // always show the suggestion in a separate line - SuggestionStyle::ShowAlways, - ); -} diff --git a/clippy_lints/src/casts/cast_possible_wrap.rs b/clippy_lints/src/casts/cast_possible_wrap.rs deleted file mode 100644 index 11274383595a..000000000000 --- a/clippy_lints/src/casts/cast_possible_wrap.rs +++ /dev/null @@ -1,89 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_then; -use rustc_hir::Expr; -use rustc_lint::LateContext; -use rustc_middle::ty::Ty; - -use super::{utils, CAST_POSSIBLE_WRAP}; - -// this should be kept in sync with the allowed bit widths of `usize` and `isize` -const ALLOWED_POINTER_SIZES: [u64; 3] = [16, 32, 64]; - -// whether the lint should be emitted, and the required pointer size, if it matters -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -enum EmitState { - NoLint, - LintAlways, - LintOnPtrSize(u64), -} - -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { - if !(cast_from.is_integral() && cast_to.is_integral()) { - return; - } - - // emit a lint if a cast is: - // 1. unsigned to signed - // and - // 2. either: - // - // 2a. between two types of constant size that are always the same size - // 2b. between one target-dependent size and one constant size integer, - // and the constant integer is in the allowed set of target dependent sizes - // (the ptr size could be chosen to be the same as the constant size) - - if cast_from.is_signed() || !cast_to.is_signed() { - return; - } - - let from_nbits = utils::int_ty_to_nbits(cast_from, cx.tcx); - let to_nbits = utils::int_ty_to_nbits(cast_to, cx.tcx); - - let should_lint = match (cast_from.is_ptr_sized_integral(), cast_to.is_ptr_sized_integral()) { - (true, true) => { - // casts between two ptr sized integers are trivially always the same size - // so do not depend on any specific pointer size to be the same - EmitState::LintAlways - }, - (true, false) => { - // the first type is `usize` and the second is a constant sized signed integer - if ALLOWED_POINTER_SIZES.contains(&to_nbits) { - EmitState::LintOnPtrSize(to_nbits) - } else { - EmitState::NoLint - } - }, - (false, true) => { - // the first type is a constant sized unsigned integer, and the second is `isize` - if ALLOWED_POINTER_SIZES.contains(&from_nbits) { - EmitState::LintOnPtrSize(from_nbits) - } else { - EmitState::NoLint - } - }, - (false, false) => { - // the types are both a constant known size - // and do not depend on any specific pointer size to be the same - if from_nbits == to_nbits { - EmitState::LintAlways - } else { - EmitState::NoLint - } - }, - }; - - let message = match should_lint { - EmitState::NoLint => return, - EmitState::LintAlways => format!("casting `{cast_from}` to `{cast_to}` may wrap around the value"), - EmitState::LintOnPtrSize(ptr_size) => format!( - "casting `{cast_from}` to `{cast_to}` may wrap around the value on targets with {ptr_size}-bit wide pointers", - ), - }; - - span_lint_and_then(cx, CAST_POSSIBLE_WRAP, expr.span, message, |diag| { - if let EmitState::LintOnPtrSize(16) = should_lint { - diag - .note("`usize` and `isize` may be as small as 16 bits on some platforms") - .note("for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types"); - }; - }); -} diff --git a/clippy_lints/src/casts/cast_precision_loss.rs b/clippy_lints/src/casts/cast_precision_loss.rs deleted file mode 100644 index 035666e4d4c9..000000000000 --- a/clippy_lints/src/casts/cast_precision_loss.rs +++ /dev/null @@ -1,51 +0,0 @@ -use clippy_utils::diagnostics::span_lint; -use clippy_utils::ty::is_isize_or_usize; -use rustc_hir::Expr; -use rustc_lint::LateContext; -use rustc_middle::ty::{self, FloatTy, Ty}; - -use super::{utils, CAST_PRECISION_LOSS}; - -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { - if !cast_from.is_integral() || cast_to.is_integral() { - return; - } - - let from_nbits = utils::int_ty_to_nbits(cast_from, cx.tcx); - let to_nbits = if cast_to.kind() == &ty::Float(FloatTy::F32) { - 32 - } else { - 64 - }; - - if !(is_isize_or_usize(cast_from) || from_nbits >= to_nbits) { - return; - } - - let cast_to_f64 = to_nbits == 64; - let mantissa_nbits = if cast_to_f64 { 52 } else { 23 }; - let arch_dependent = is_isize_or_usize(cast_from) && cast_to_f64; - let arch_dependent_str = "on targets with 64-bit wide pointers "; - let from_nbits_str = if arch_dependent { - "64".to_owned() - } else if is_isize_or_usize(cast_from) { - "32 or 64".to_owned() - } else { - utils::int_ty_to_nbits(cast_from, cx.tcx).to_string() - }; - - span_lint( - cx, - CAST_PRECISION_LOSS, - expr.span, - format!( - "casting `{0}` to `{1}` causes a loss of precision {2}(`{0}` is {3} bits wide, \ - but `{1}`'s mantissa is only {4} bits wide)", - cast_from, - if cast_to_f64 { "f64" } else { "f32" }, - if arch_dependent { arch_dependent_str } else { "" }, - from_nbits_str, - mantissa_nbits - ), - ); -} diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs deleted file mode 100644 index 960c81045e36..000000000000 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ /dev/null @@ -1,96 +0,0 @@ -use clippy_utils::diagnostics::span_lint; -use clippy_utils::ty::is_c_void; -use clippy_utils::{get_parent_expr, is_hir_ty_cfg_dependant}; -use rustc_hir::{Expr, ExprKind, GenericArg}; -use rustc_lint::LateContext; -use rustc_middle::ty::layout::LayoutOf; -use rustc_middle::ty::{self, Ty}; -use rustc_span::sym; - -use super::CAST_PTR_ALIGNMENT; - -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { - if let ExprKind::Cast(cast_expr, cast_to) = expr.kind { - if is_hir_ty_cfg_dependant(cx, cast_to) { - return; - } - let (cast_from, cast_to) = ( - cx.typeck_results().expr_ty(cast_expr), - cx.typeck_results().expr_ty(expr), - ); - lint_cast_ptr_alignment(cx, expr, cast_from, cast_to); - } else if let ExprKind::MethodCall(method_path, self_arg, ..) = &expr.kind { - if method_path.ident.name == sym!(cast) - && let Some(generic_args) = method_path.args - && let [GenericArg::Type(cast_to)] = generic_args.args - // There probably is no obvious reason to do this, just to be consistent with `as` cases. - && !is_hir_ty_cfg_dependant(cx, cast_to) - { - let (cast_from, cast_to) = (cx.typeck_results().expr_ty(self_arg), cx.typeck_results().expr_ty(expr)); - lint_cast_ptr_alignment(cx, expr, cast_from, cast_to); - } - } -} - -fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>) { - if let ty::RawPtr(from_ptr_ty, _) = *cast_from.kind() - && let ty::RawPtr(to_ptr_ty, _) = *cast_to.kind() - && let Ok(from_layout) = cx.layout_of(from_ptr_ty) - && let Ok(to_layout) = cx.layout_of(to_ptr_ty) - && from_layout.align.abi < to_layout.align.abi - // with c_void, we inherently need to trust the user - && !is_c_void(cx, from_ptr_ty) - // when casting from a ZST, we don't know enough to properly lint - && !from_layout.is_zst() - && !is_used_as_unaligned(cx, expr) - { - span_lint( - cx, - CAST_PTR_ALIGNMENT, - expr.span, - format!( - "casting from `{cast_from}` to a more-strictly-aligned pointer (`{cast_to}`) ({} < {} bytes)", - from_layout.align.abi.bytes(), - to_layout.align.abi.bytes(), - ), - ); - } -} - -fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { - let Some(parent) = get_parent_expr(cx, e) else { - return false; - }; - match parent.kind { - ExprKind::MethodCall(name, self_arg, ..) if self_arg.hir_id == e.hir_id => { - if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned") - && let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id) - && let Some(def_id) = cx.tcx.impl_of_method(def_id) - && cx.tcx.type_of(def_id).instantiate_identity().is_unsafe_ptr() - { - true - } else { - false - } - }, - ExprKind::Call(func, [arg, ..]) if arg.hir_id == e.hir_id => { - if let ExprKind::Path(path) = &func.kind - && let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id() - && matches!( - cx.tcx.get_diagnostic_name(def_id), - Some( - sym::ptr_write_unaligned - | sym::ptr_read_unaligned - | sym::intrinsics_unaligned_volatile_load - | sym::intrinsics_unaligned_volatile_store - ) - ) - { - true - } else { - false - } - }, - _ => false, - } -} diff --git a/clippy_lints/src/casts/cast_sign_loss.rs b/clippy_lints/src/casts/cast_sign_loss.rs deleted file mode 100644 index 864489ee3fcd..000000000000 --- a/clippy_lints/src/casts/cast_sign_loss.rs +++ /dev/null @@ -1,339 +0,0 @@ -use std::convert::Infallible; -use std::ops::ControlFlow; - -use clippy_utils::consts::{constant, Constant}; -use clippy_utils::diagnostics::span_lint; -use clippy_utils::visitors::{for_each_expr, Descend}; -use clippy_utils::{method_chain_args, sext}; -use rustc_hir::{BinOpKind, Expr, ExprKind}; -use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty}; - -use super::CAST_SIGN_LOSS; - -/// A list of methods that can never return a negative value. -/// Includes methods that panic rather than returning a negative value. -/// -/// Methods that can overflow and return a negative value must not be included in this list, -/// because casting their return values can still result in sign loss. -const METHODS_RET_POSITIVE: &[&str] = &[ - "checked_abs", - "saturating_abs", - "isqrt", - "checked_isqrt", - "rem_euclid", - "checked_rem_euclid", - "wrapping_rem_euclid", -]; - -/// A list of methods that act like `pow()`. See `pow_call_result_sign()` for details. -/// -/// Methods that can overflow and return a negative value must not be included in this list, -/// because casting their return values can still result in sign loss. -const METHODS_POW: &[&str] = &["pow", "saturating_pow", "checked_pow"]; - -/// A list of methods that act like `unwrap()`, and don't change the sign of the inner value. -const METHODS_UNWRAP: &[&str] = &["unwrap", "unwrap_unchecked", "expect", "into_ok"]; - -pub(super) fn check<'cx>( - cx: &LateContext<'cx>, - expr: &Expr<'_>, - cast_op: &Expr<'_>, - cast_from: Ty<'cx>, - cast_to: Ty<'_>, -) { - if should_lint(cx, cast_op, cast_from, cast_to) { - span_lint( - cx, - CAST_SIGN_LOSS, - expr.span, - format!("casting `{cast_from}` to `{cast_to}` may lose the sign of the value"), - ); - } -} - -fn should_lint<'cx>(cx: &LateContext<'cx>, cast_op: &Expr<'_>, cast_from: Ty<'cx>, cast_to: Ty<'_>) -> bool { - match (cast_from.is_integral(), cast_to.is_integral()) { - (true, true) => { - if !cast_from.is_signed() || cast_to.is_signed() { - return false; - } - - // Don't lint if `cast_op` is known to be positive, ignoring overflow. - if let Sign::ZeroOrPositive = expr_sign(cx, cast_op, cast_from) { - return false; - } - - if let Sign::ZeroOrPositive = expr_muldiv_sign(cx, cast_op) { - return false; - } - - if let Sign::ZeroOrPositive = expr_add_sign(cx, cast_op) { - return false; - } - - true - }, - - (false, true) => !cast_to.is_signed(), - - (_, _) => false, - } -} - -fn get_const_signed_int_eval<'cx>( - cx: &LateContext<'cx>, - expr: &Expr<'_>, - ty: impl Into>>, -) -> Option { - let ty = ty.into().unwrap_or_else(|| cx.typeck_results().expr_ty(expr)); - - if let Constant::Int(n) = constant(cx, cx.typeck_results(), expr)? - && let ty::Int(ity) = *ty.kind() - { - return Some(sext(cx.tcx, n, ity)); - } - None -} - -fn get_const_unsigned_int_eval<'cx>( - cx: &LateContext<'cx>, - expr: &Expr<'_>, - ty: impl Into>>, -) -> Option { - let ty = ty.into().unwrap_or_else(|| cx.typeck_results().expr_ty(expr)); - - if let Constant::Int(n) = constant(cx, cx.typeck_results(), expr)? - && let ty::Uint(_ity) = *ty.kind() - { - return Some(n); - } - None -} - -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -enum Sign { - ZeroOrPositive, - Negative, - Uncertain, -} - -fn expr_sign<'cx, 'tcx>(cx: &LateContext<'cx>, mut expr: &'tcx Expr<'tcx>, ty: impl Into>>) -> Sign { - // Try evaluate this expr first to see if it's positive - if let Some(val) = get_const_signed_int_eval(cx, expr, ty) { - return if val >= 0 { Sign::ZeroOrPositive } else { Sign::Negative }; - } - if let Some(_val) = get_const_unsigned_int_eval(cx, expr, None) { - return Sign::ZeroOrPositive; - } - - // Calling on methods that always return non-negative values. - if let ExprKind::MethodCall(path, caller, args, ..) = expr.kind { - let mut method_name = path.ident.name.as_str(); - - // Peel unwrap(), expect(), etc. - while let Some(&found_name) = METHODS_UNWRAP.iter().find(|&name| &method_name == name) - && let Some(arglist) = method_chain_args(expr, &[found_name]) - && let ExprKind::MethodCall(inner_path, recv, ..) = &arglist[0].0.kind - { - // The original type has changed, but we can't use `ty` here anyway, because it has been - // moved. - method_name = inner_path.ident.name.as_str(); - expr = recv; - } - - if METHODS_POW.iter().any(|&name| method_name == name) - && let [arg] = args - { - return pow_call_result_sign(cx, caller, arg); - } else if METHODS_RET_POSITIVE.iter().any(|&name| method_name == name) { - return Sign::ZeroOrPositive; - } - } - - Sign::Uncertain -} - -/// Return the sign of the `pow` call's result, ignoring overflow. -/// -/// If the base is positive, the result is always positive. -/// If the exponent is a even number, the result is always positive, -/// Otherwise, if the base is negative, and the exponent is an odd number, the result is always -/// negative. -/// -/// Otherwise, returns [`Sign::Uncertain`]. -fn pow_call_result_sign(cx: &LateContext<'_>, base: &Expr<'_>, exponent: &Expr<'_>) -> Sign { - let base_sign = expr_sign(cx, base, None); - - // Rust's integer pow() functions take an unsigned exponent. - let exponent_val = get_const_unsigned_int_eval(cx, exponent, None); - let exponent_is_even = exponent_val.map(|val| val % 2 == 0); - - match (base_sign, exponent_is_even) { - // Non-negative bases always return non-negative results, ignoring overflow. - (Sign::ZeroOrPositive, _) | - // Any base raised to an even exponent is non-negative. - // These both hold even if we don't know the value of the base. - (_, Some(true)) - => Sign::ZeroOrPositive, - - // A negative base raised to an odd exponent is non-negative. - (Sign::Negative, Some(false)) => Sign::Negative, - - // Negative/unknown base to an unknown exponent, or unknown base to an odd exponent. - // Could be negative or positive depending on the actual values. - (Sign::Negative | Sign::Uncertain, None) | - (Sign::Uncertain, Some(false)) => Sign::Uncertain, - } -} - -/// Peels binary operators such as [`BinOpKind::Mul`] or [`BinOpKind::Rem`], -/// where the result could always be positive. See [`exprs_with_muldiv_binop_peeled()`] for details. -/// -/// Returns the sign of the list of peeled expressions. -fn expr_muldiv_sign(cx: &LateContext<'_>, expr: &Expr<'_>) -> Sign { - let mut negative_count = 0; - - // Peel off possible binary expressions, for example: - // x * x / y => [x, x, y] - // a % b => [a] - let exprs = exprs_with_muldiv_binop_peeled(expr); - for expr in exprs { - match expr_sign(cx, expr, None) { - Sign::Negative => negative_count += 1, - // A mul/div is: - // - uncertain if there are any uncertain values (because they could be negative or positive), - Sign::Uncertain => return Sign::Uncertain, - Sign::ZeroOrPositive => (), - }; - } - - // A mul/div is: - // - negative if there are an odd number of negative values, - // - positive or zero otherwise. - if negative_count % 2 == 1 { - Sign::Negative - } else { - Sign::ZeroOrPositive - } -} - -/// Peels binary operators such as [`BinOpKind::Add`], where the result could always be positive. -/// See [`exprs_with_add_binop_peeled()`] for details. -/// -/// Returns the sign of the list of peeled expressions. -fn expr_add_sign(cx: &LateContext<'_>, expr: &Expr<'_>) -> Sign { - let mut negative_count = 0; - let mut positive_count = 0; - - // Peel off possible binary expressions, for example: - // a + b + c => [a, b, c] - let exprs = exprs_with_add_binop_peeled(expr); - for expr in exprs { - match expr_sign(cx, expr, None) { - Sign::Negative => negative_count += 1, - // A sum is: - // - uncertain if there are any uncertain values (because they could be negative or positive), - Sign::Uncertain => return Sign::Uncertain, - Sign::ZeroOrPositive => positive_count += 1, - }; - } - - // A sum is: - // - positive or zero if there are only positive (or zero) values, - // - negative if there are only negative (or zero) values, or - // - uncertain if there are both. - // We could split Zero out into its own variant, but we don't yet. - if negative_count == 0 { - Sign::ZeroOrPositive - } else if positive_count == 0 { - Sign::Negative - } else { - Sign::Uncertain - } -} - -/// Peels binary operators such as [`BinOpKind::Mul`], [`BinOpKind::Div`] or [`BinOpKind::Rem`], -/// where the result depends on: -/// -/// - the number of negative values in the entire expression, or -/// - the number of negative values on the left hand side of the expression. -/// -/// Ignores overflow. -/// -/// -/// Expressions using other operators are preserved, so we can try to evaluate them later. -fn exprs_with_muldiv_binop_peeled<'e>(expr: &'e Expr<'_>) -> Vec<&'e Expr<'e>> { - let mut res = vec![]; - - for_each_expr(expr, |sub_expr| -> ControlFlow { - // We don't check for mul/div/rem methods here, but we could. - if let ExprKind::Binary(op, lhs, _rhs) = sub_expr.kind { - if matches!(op.node, BinOpKind::Mul | BinOpKind::Div) { - // For binary operators where both sides contribute to the sign of the result, - // collect all their operands, recursively. This ignores overflow. - ControlFlow::Continue(Descend::Yes) - } else if matches!(op.node, BinOpKind::Rem | BinOpKind::Shr) { - // For binary operators where the left hand side determines the sign of the result, - // only collect that side, recursively. Overflow panics, so this always holds. - // - // Large left shifts turn negatives into zeroes, so we can't use it here. - // - // > Given remainder = dividend % divisor, the remainder will have the same sign as the dividend - // > ... - // > Arithmetic right shift on signed integer types - // https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators - - // We want to descend into the lhs, but skip the rhs. - // That's tricky to do using for_each_expr(), so we just keep the lhs intact. - res.push(lhs); - ControlFlow::Continue(Descend::No) - } else { - // The sign of the result of other binary operators depends on the values of the operands, - // so try to evaluate the expression. - res.push(sub_expr); - ControlFlow::Continue(Descend::No) - } - } else { - // For other expressions, including unary operators and constants, try to evaluate the expression. - res.push(sub_expr); - ControlFlow::Continue(Descend::No) - } - }); - - res -} - -/// Peels binary operators such as [`BinOpKind::Add`], where the result depends on: -/// -/// - all the expressions being positive, or -/// - all the expressions being negative. -/// -/// Ignores overflow. -/// -/// Expressions using other operators are preserved, so we can try to evaluate them later. -fn exprs_with_add_binop_peeled<'e>(expr: &'e Expr<'_>) -> Vec<&'e Expr<'e>> { - let mut res = vec![]; - - for_each_expr(expr, |sub_expr| -> ControlFlow { - // We don't check for add methods here, but we could. - if let ExprKind::Binary(op, _lhs, _rhs) = sub_expr.kind { - if matches!(op.node, BinOpKind::Add) { - // For binary operators where both sides contribute to the sign of the result, - // collect all their operands, recursively. This ignores overflow. - ControlFlow::Continue(Descend::Yes) - } else { - // The sign of the result of other binary operators depends on the values of the operands, - // so try to evaluate the expression. - res.push(sub_expr); - ControlFlow::Continue(Descend::No) - } - } else { - // For other expressions, including unary operators and constants, try to evaluate the expression. - res.push(sub_expr); - ControlFlow::Continue(Descend::No) - } - }); - - res -} diff --git a/clippy_lints/src/casts/cast_slice_different_sizes.rs b/clippy_lints/src/casts/cast_slice_different_sizes.rs deleted file mode 100644 index 285f0357112b..000000000000 --- a/clippy_lints/src/casts/cast_slice_different_sizes.rs +++ /dev/null @@ -1,136 +0,0 @@ -use clippy_config::msrvs::{self, Msrv}; -use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source; -use rustc_ast::Mutability; -use rustc_hir::{Expr, ExprKind, Node}; -use rustc_lint::LateContext; -use rustc_middle::ty::layout::LayoutOf; -use rustc_middle::ty::{self, Ty, TypeAndMut}; - -use super::CAST_SLICE_DIFFERENT_SIZES; - -pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv) { - // suggestion is invalid if `ptr::slice_from_raw_parts` does not exist - if !msrv.meets(msrvs::PTR_SLICE_RAW_PARTS) { - return; - } - - // if this cast is the child of another cast expression then don't emit something for it, the full - // chain will be analyzed - if is_child_of_cast(cx, expr) { - return; - } - - if let Some(CastChainInfo { - left_cast, - start_ty, - end_ty, - }) = expr_cast_chain_tys(cx, expr) - { - if let (Ok(from_layout), Ok(to_layout)) = (cx.layout_of(start_ty.ty), cx.layout_of(end_ty.ty)) { - let from_size = from_layout.size.bytes(); - let to_size = to_layout.size.bytes(); - if from_size != to_size && from_size != 0 && to_size != 0 { - span_lint_and_then( - cx, - CAST_SLICE_DIFFERENT_SIZES, - expr.span, - format!( - "casting between raw pointers to `[{}]` (element size {from_size}) and `[{}]` (element size {to_size}) does not adjust the count", - start_ty.ty, end_ty.ty, - ), - |diag| { - let ptr_snippet = source::snippet(cx, left_cast.span, ".."); - - let (mutbl_fn_str, mutbl_ptr_str) = match end_ty.mutbl { - Mutability::Mut => ("_mut", "mut"), - Mutability::Not => ("", "const"), - }; - let sugg = format!( - "core::ptr::slice_from_raw_parts{mutbl_fn_str}({ptr_snippet} as *{mutbl_ptr_str} {}, ..)", - // get just the ty from the TypeAndMut so that the printed type isn't something like `mut - // T`, extract just the `T` - end_ty.ty - ); - - diag.span_suggestion( - expr.span, - format!("replace with `ptr::slice_from_raw_parts{mutbl_fn_str}`"), - sugg, - rustc_errors::Applicability::HasPlaceholders, - ); - }, - ); - } - } - } -} - -fn is_child_of_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - let parent = cx.tcx.parent_hir_node(expr.hir_id); - let expr = match parent { - Node::Block(block) => { - if let Some(parent_expr) = block.expr { - parent_expr - } else { - return false; - } - }, - Node::Expr(expr) => expr, - _ => return false, - }; - - matches!(expr.kind, ExprKind::Cast(..)) -} - -/// Returns the type T of the pointed to *const [T] or *mut [T] and the mutability of the slice if -/// the type is one of those slices -fn get_raw_slice_ty_mut(ty: Ty<'_>) -> Option> { - match ty.kind() { - ty::RawPtr(slice_ty, mutbl) => match slice_ty.kind() { - ty::Slice(ty) => Some(TypeAndMut { ty: *ty, mutbl: *mutbl }), - _ => None, - }, - _ => None, - } -} - -struct CastChainInfo<'tcx> { - /// The left most part of the cast chain, or in other words, the first cast in the chain - /// Used for diagnostics - left_cast: &'tcx Expr<'tcx>, - /// The starting type of the cast chain - start_ty: TypeAndMut<'tcx>, - /// The final type of the cast chain - end_ty: TypeAndMut<'tcx>, -} - -/// Returns a `CastChainInfo` with the left-most cast in the chain and the original ptr T and final -/// ptr U if the expression is composed of casts. -/// Returns None if the expr is not a Cast -fn expr_cast_chain_tys<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> Option> { - if let ExprKind::Cast(cast_expr, _cast_to_hir_ty) = expr.peel_blocks().kind { - let cast_to = cx.typeck_results().expr_ty(expr); - let to_slice_ty = get_raw_slice_ty_mut(cast_to)?; - - // If the expression that makes up the source of this cast is itself a cast, recursively - // call `expr_cast_chain_tys` and update the end type with the final target type. - // Otherwise, this cast is not immediately nested, just construct the info for this cast - if let Some(prev_info) = expr_cast_chain_tys(cx, cast_expr) { - Some(CastChainInfo { - end_ty: to_slice_ty, - ..prev_info - }) - } else { - let cast_from = cx.typeck_results().expr_ty(cast_expr); - let from_slice_ty = get_raw_slice_ty_mut(cast_from)?; - Some(CastChainInfo { - left_cast: cast_expr, - start_ty: from_slice_ty, - end_ty: to_slice_ty, - }) - } - } else { - None - } -} diff --git a/clippy_lints/src/casts/cast_slice_from_raw_parts.rs b/clippy_lints/src/casts/cast_slice_from_raw_parts.rs deleted file mode 100644 index 1d89f6c75e18..000000000000 --- a/clippy_lints/src/casts/cast_slice_from_raw_parts.rs +++ /dev/null @@ -1,55 +0,0 @@ -use clippy_config::msrvs::{self, Msrv}; -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::snippet_with_context; -use rustc_errors::Applicability; -use rustc_hir::def_id::DefId; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty}; -use rustc_span::sym; - -use super::CAST_SLICE_FROM_RAW_PARTS; - -enum RawPartsKind { - Immutable, - Mutable, -} - -fn raw_parts_kind(cx: &LateContext<'_>, did: DefId) -> Option { - match cx.tcx.get_diagnostic_name(did)? { - sym::slice_from_raw_parts => Some(RawPartsKind::Immutable), - sym::slice_from_raw_parts_mut => Some(RawPartsKind::Mutable), - _ => None, - } -} - -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>, msrv: &Msrv) { - if msrv.meets(msrvs::PTR_SLICE_RAW_PARTS) - && let ty::RawPtr(ptrty, _) = cast_to.kind() - && let ty::Slice(_) = ptrty.kind() - && let ExprKind::Call(fun, [ptr_arg, len_arg]) = cast_expr.peel_blocks().kind - && let ExprKind::Path(ref qpath) = fun.kind - && let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id() - && let Some(rpk) = raw_parts_kind(cx, fun_def_id) - && let ctxt = expr.span.ctxt() - && cast_expr.span.ctxt() == ctxt - { - let func = match rpk { - RawPartsKind::Immutable => "from_raw_parts", - RawPartsKind::Mutable => "from_raw_parts_mut", - }; - let span = expr.span; - let mut applicability = Applicability::MachineApplicable; - let ptr = snippet_with_context(cx, ptr_arg.span, ctxt, "ptr", &mut applicability).0; - let len = snippet_with_context(cx, len_arg.span, ctxt, "len", &mut applicability).0; - span_lint_and_sugg( - cx, - CAST_SLICE_FROM_RAW_PARTS, - span, - format!("casting the result of `{func}` to {cast_to}"), - "replace with", - format!("core::ptr::slice_{func}({ptr}, {len})"), - applicability, - ); - } -} diff --git a/clippy_lints/src/casts/char_lit_as_u8.rs b/clippy_lints/src/casts/char_lit_as_u8.rs deleted file mode 100644 index a7d3868f76c6..000000000000 --- a/clippy_lints/src/casts/char_lit_as_u8.rs +++ /dev/null @@ -1,39 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::snippet_with_applicability; -use rustc_ast::LitKind; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::LateContext; -use rustc_middle::ty::{self, UintTy}; - -use super::CHAR_LIT_AS_U8; - -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { - if let ExprKind::Cast(e, _) = &expr.kind - && let ExprKind::Lit(l) = &e.kind - && let LitKind::Char(c) = l.node - && ty::Uint(UintTy::U8) == *cx.typeck_results().expr_ty(expr).kind() - { - let mut applicability = Applicability::MachineApplicable; - let snippet = snippet_with_applicability(cx, e.span, "'x'", &mut applicability); - - span_lint_and_then( - cx, - CHAR_LIT_AS_U8, - expr.span, - "casting a character literal to `u8` truncates", - |diag| { - diag.note("`char` is four bytes wide, but `u8` is a single byte"); - - if c.is_ascii() { - diag.span_suggestion( - expr.span, - "use a byte literal instead", - format!("b{snippet}"), - applicability, - ); - } - }, - ); - } -} diff --git a/clippy_lints/src/casts/fn_to_numeric_cast.rs b/clippy_lints/src/casts/fn_to_numeric_cast.rs deleted file mode 100644 index f263bec1576d..000000000000 --- a/clippy_lints/src/casts/fn_to_numeric_cast.rs +++ /dev/null @@ -1,37 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::snippet_with_applicability; -use rustc_errors::Applicability; -use rustc_hir::Expr; -use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty, UintTy}; - -use super::{utils, FN_TO_NUMERIC_CAST}; - -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { - // We only want to check casts to `ty::Uint` or `ty::Int` - match cast_to.kind() { - ty::Uint(_) | ty::Int(..) => { /* continue on */ }, - _ => return, - } - - match cast_from.kind() { - ty::FnDef(..) | ty::FnPtr(_) => { - let mut applicability = Applicability::MaybeIncorrect; - let from_snippet = snippet_with_applicability(cx, cast_expr.span, "x", &mut applicability); - let to_nbits = utils::int_ty_to_nbits(cast_to, cx.tcx); - - if (to_nbits >= cx.tcx.data_layout.pointer_size.bits()) && (*cast_to.kind() != ty::Uint(UintTy::Usize)) { - span_lint_and_sugg( - cx, - FN_TO_NUMERIC_CAST, - expr.span, - format!("casting function pointer `{from_snippet}` to `{cast_to}`"), - "try", - format!("{from_snippet} as usize"), - applicability, - ); - } - }, - _ => {}, - } -} diff --git a/clippy_lints/src/casts/fn_to_numeric_cast_any.rs b/clippy_lints/src/casts/fn_to_numeric_cast_any.rs deleted file mode 100644 index 826589bf303b..000000000000 --- a/clippy_lints/src/casts/fn_to_numeric_cast_any.rs +++ /dev/null @@ -1,34 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::snippet_with_applicability; -use rustc_errors::Applicability; -use rustc_hir::Expr; -use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty}; - -use super::FN_TO_NUMERIC_CAST_ANY; - -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { - // We allow casts from any function type to any function type. - match cast_to.kind() { - ty::FnDef(..) | ty::FnPtr(..) => return, - _ => { /* continue to checks */ }, - } - - match cast_from.kind() { - ty::FnDef(..) | ty::FnPtr(_) => { - let mut applicability = Applicability::MaybeIncorrect; - let from_snippet = snippet_with_applicability(cx, cast_expr.span, "..", &mut applicability); - - span_lint_and_sugg( - cx, - FN_TO_NUMERIC_CAST_ANY, - expr.span, - format!("casting function pointer `{from_snippet}` to `{cast_to}`"), - "did you mean to invoke the function?", - format!("{from_snippet}() as {cast_to}"), - applicability, - ); - }, - _ => {}, - } -} diff --git a/clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs b/clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs deleted file mode 100644 index 0e11bcfb8ecd..000000000000 --- a/clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs +++ /dev/null @@ -1,36 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::snippet_with_applicability; -use rustc_errors::Applicability; -use rustc_hir::Expr; -use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty}; - -use super::{utils, FN_TO_NUMERIC_CAST_WITH_TRUNCATION}; - -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) { - // We only want to check casts to `ty::Uint` or `ty::Int` - match cast_to.kind() { - ty::Uint(_) | ty::Int(..) => { /* continue on */ }, - _ => return, - } - match cast_from.kind() { - ty::FnDef(..) | ty::FnPtr(_) => { - let mut applicability = Applicability::MaybeIncorrect; - let from_snippet = snippet_with_applicability(cx, cast_expr.span, "x", &mut applicability); - - let to_nbits = utils::int_ty_to_nbits(cast_to, cx.tcx); - if to_nbits < cx.tcx.data_layout.pointer_size.bits() { - span_lint_and_sugg( - cx, - FN_TO_NUMERIC_CAST_WITH_TRUNCATION, - expr.span, - format!("casting function pointer `{from_snippet}` to `{cast_to}`, which truncates the value"), - "try", - format!("{from_snippet} as usize"), - applicability, - ); - } - }, - _ => {}, - } -} diff --git a/clippy_lints/src/casts/mod.rs b/clippy_lints/src/casts/mod.rs deleted file mode 100644 index bd2c96f01f6f..000000000000 --- a/clippy_lints/src/casts/mod.rs +++ /dev/null @@ -1,810 +0,0 @@ -mod as_ptr_cast_mut; -mod as_underscore; -mod borrow_as_ptr; -mod cast_abs_to_unsigned; -mod cast_enum_constructor; -mod cast_lossless; -mod cast_nan_to_int; -mod cast_possible_truncation; -mod cast_possible_wrap; -mod cast_precision_loss; -mod cast_ptr_alignment; -mod cast_sign_loss; -mod cast_slice_different_sizes; -mod cast_slice_from_raw_parts; -mod char_lit_as_u8; -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 ref_as_ptr; -mod unnecessary_cast; -mod utils; -mod zero_ptr; - -use clippy_config::msrvs::{self, Msrv}; -use clippy_utils::is_hir_ty_cfg_dependant; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_session::impl_lint_pass; - -declare_clippy_lint! { - /// ### What it does - /// Checks for casts from any numerical to a float type where - /// the receiving type cannot store all values from the original type without - /// rounding errors. This possible rounding is to be expected, so this lint is - /// `Allow` by default. - /// - /// Basically, this warns on casting any integer with 32 or more bits to `f32` - /// or any 64-bit integer to `f64`. - /// - /// ### Why is this bad? - /// It's not bad at all. But in some applications it can be - /// helpful to know where precision loss can take place. This lint can help find - /// those places in the code. - /// - /// ### Example - /// ```no_run - /// let x = u64::MAX; - /// x as f64; - /// ``` - #[clippy::version = "pre 1.29.0"] - pub CAST_PRECISION_LOSS, - pedantic, - "casts that cause loss of precision, e.g., `x as f32` where `x: u64`" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for casts from a signed to an unsigned numerical - /// type. In this case, negative values wrap around to large positive values, - /// which can be quite surprising in practice. However, as the cast works as - /// defined, this lint is `Allow` by default. - /// - /// ### Why is this bad? - /// Possibly surprising results. You can activate this lint - /// as a one-time check to see where numerical wrapping can arise. - /// - /// ### Example - /// ```no_run - /// let y: i8 = -1; - /// y as u128; // will return 18446744073709551615 - /// ``` - #[clippy::version = "pre 1.29.0"] - pub CAST_SIGN_LOSS, - pedantic, - "casts from signed types to unsigned types, e.g., `x as u32` where `x: i32`" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for casts between numerical types that may - /// truncate large values. This is expected behavior, so the cast is `Allow` by - /// default. It suggests user either explicitly ignore the lint, - /// or use `try_from()` and handle the truncation, default, or panic explicitly. - /// - /// ### Why is this bad? - /// In some problem domains, it is good practice to avoid - /// truncation. This lint can be activated to help assess where additional - /// checks could be beneficial. - /// - /// ### Example - /// ```no_run - /// fn as_u8(x: u64) -> u8 { - /// x as u8 - /// } - /// ``` - /// Use instead: - /// ```no_run - /// fn as_u8(x: u64) -> u8 { - /// if let Ok(x) = u8::try_from(x) { - /// x - /// } else { - /// todo!(); - /// } - /// } - /// // Or - /// #[allow(clippy::cast_possible_truncation)] - /// fn as_u16(x: u64) -> u16 { - /// x as u16 - /// } - /// ``` - #[clippy::version = "pre 1.29.0"] - pub CAST_POSSIBLE_TRUNCATION, - pedantic, - "casts that may cause truncation of the value, e.g., `x as u8` where `x: u32`, or `x as i32` where `x: f32`" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for casts from an unsigned type to a signed type of - /// the same size, or possibly smaller due to target dependent integers. - /// Performing such a cast is a 'no-op' for the compiler, i.e., nothing is - /// changed at the bit level, and the binary representation of the value is - /// reinterpreted. This can cause wrapping if the value is too big - /// for the target signed type. However, the cast works as defined, so this lint - /// is `Allow` by default. - /// - /// ### Why is this bad? - /// While such a cast is not bad in itself, the results can - /// be surprising when this is not the intended behavior, as demonstrated by the - /// example below. - /// - /// ### Example - /// ```no_run - /// u32::MAX as i32; // will yield a value of `-1` - /// ``` - #[clippy::version = "pre 1.29.0"] - pub CAST_POSSIBLE_WRAP, - pedantic, - "casts that may cause wrapping around the value, e.g., `x as i32` where `x: u32` and `x > i32::MAX`" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for casts between numerical types that may - /// be replaced by safe conversion functions. - /// - /// ### Why is this bad? - /// Rust's `as` keyword will perform many kinds of - /// conversions, including silently lossy conversions. Conversion functions such - /// as `i32::from` will only perform lossless conversions. Using the conversion - /// functions prevents conversions from turning into silent lossy conversions if - /// the types of the input expressions ever change, and make it easier for - /// people reading the code to know that the conversion is lossless. - /// - /// ### Example - /// ```no_run - /// fn as_u64(x: u8) -> u64 { - /// x as u64 - /// } - /// ``` - /// - /// Using `::from` would look like this: - /// - /// ```no_run - /// fn as_u64(x: u8) -> u64 { - /// u64::from(x) - /// } - /// ``` - #[clippy::version = "pre 1.29.0"] - pub CAST_LOSSLESS, - pedantic, - "casts using `as` that are known to be lossless, e.g., `x as u64` where `x: u8`" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for casts to the same type, casts of int literals to integer types, casts of float - /// literals to float types and casts between raw pointers without changing type or constness. - /// - /// ### Why is this bad? - /// It's just unnecessary. - /// - /// ### Known problems - /// When the expression on the left is a function call, the lint considers the return type to be - /// a type alias if it's aliased through a `use` statement - /// (like `use std::io::Result as IoResult`). It will not lint such cases. - /// - /// This check is also rather primitive. It will only work on primitive types without any - /// intermediate references, raw pointers and trait objects may or may not work. - /// - /// ### Example - /// ```no_run - /// let _ = 2i32 as i32; - /// let _ = 0.5 as f32; - /// ``` - /// - /// Better: - /// - /// ```no_run - /// let _ = 2_i32; - /// let _ = 0.5_f32; - /// ``` - #[clippy::version = "pre 1.29.0"] - pub UNNECESSARY_CAST, - complexity, - "cast to the same type, e.g., `x as i32` where `x: i32`" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for casts, using `as` or `pointer::cast`, - /// from a less-strictly-aligned pointer to a more-strictly-aligned pointer - /// - /// ### Why is this bad? - /// Dereferencing the resulting pointer may be undefined - /// behavior. - /// - /// ### Known problems - /// Using `std::ptr::read_unaligned` and `std::ptr::write_unaligned` or similar - /// on the resulting pointer is fine. Is over-zealous: Casts with manual alignment checks or casts like - /// u64-> u8 -> u16 can be fine. Miri is able to do a more in-depth analysis. - /// - /// ### Example - /// ```no_run - /// let _ = (&1u8 as *const u8) as *const u16; - /// let _ = (&mut 1u8 as *mut u8) as *mut u16; - /// - /// (&1u8 as *const u8).cast::(); - /// (&mut 1u8 as *mut u8).cast::(); - /// ``` - #[clippy::version = "pre 1.29.0"] - pub CAST_PTR_ALIGNMENT, - pedantic, - "cast from a pointer to a more-strictly-aligned pointer" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for casts of function pointers to something other than usize - /// - /// ### Why is this bad? - /// Casting a function pointer to anything other than usize/isize is not portable across - /// architectures, because you end up losing bits if the target type is too small or end up with a - /// bunch of extra bits that waste space and add more instructions to the final binary than - /// strictly necessary for the problem - /// - /// Casting to isize also doesn't make sense since there are no signed addresses. - /// - /// ### Example - /// ```no_run - /// fn fun() -> i32 { 1 } - /// let _ = fun as i64; - /// ``` - /// - /// Use instead: - /// ```no_run - /// # fn fun() -> i32 { 1 } - /// let _ = fun as usize; - /// ``` - #[clippy::version = "pre 1.29.0"] - pub FN_TO_NUMERIC_CAST, - style, - "casting a function pointer to a numeric type other than usize" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for casts of a function pointer to a numeric type not wide enough to - /// store address. - /// - /// ### Why is this bad? - /// Such a cast discards some bits of the function's address. If this is intended, it would be more - /// clearly expressed by casting to usize first, then casting the usize to the intended type (with - /// a comment) to perform the truncation. - /// - /// ### Example - /// ```no_run - /// fn fn1() -> i16 { - /// 1 - /// }; - /// let _ = fn1 as i32; - /// ``` - /// - /// Use instead: - /// ```no_run - /// // Cast to usize first, then comment with the reason for the truncation - /// fn fn1() -> i16 { - /// 1 - /// }; - /// let fn_ptr = fn1 as usize; - /// let fn_ptr_truncated = fn_ptr as i32; - /// ``` - #[clippy::version = "pre 1.29.0"] - pub FN_TO_NUMERIC_CAST_WITH_TRUNCATION, - style, - "casting a function pointer to a numeric type not wide enough to store the address" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for casts of a function pointer to any integer type. - /// - /// ### Why is this bad? - /// Casting a function pointer to an integer can have surprising results and can occur - /// accidentally if parentheses are omitted from a function call. If you aren't doing anything - /// low-level with function pointers then you can opt-out of casting functions to integers in - /// order to avoid mistakes. Alternatively, you can use this lint to audit all uses of function - /// pointer casts in your code. - /// - /// ### Example - /// ```no_run - /// // fn1 is cast as `usize` - /// fn fn1() -> u16 { - /// 1 - /// }; - /// let _ = fn1 as usize; - /// ``` - /// - /// Use instead: - /// ```no_run - /// // maybe you intended to call the function? - /// fn fn2() -> u16 { - /// 1 - /// }; - /// let _ = fn2() as usize; - /// - /// // or - /// - /// // maybe you intended to cast it to a function type? - /// fn fn3() -> u16 { - /// 1 - /// } - /// let _ = fn3 as fn() -> u16; - /// ``` - #[clippy::version = "1.58.0"] - pub FN_TO_NUMERIC_CAST_ANY, - restriction, - "casting a function pointer to any integer type" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for expressions where a character literal is cast - /// to `u8` and suggests using a byte literal instead. - /// - /// ### Why is this bad? - /// In general, casting values to smaller types is - /// error-prone and should be avoided where possible. In the particular case of - /// converting a character literal to u8, it is easy to avoid by just using a - /// byte literal instead. As an added bonus, `b'a'` is even slightly shorter - /// than `'a' as u8`. - /// - /// ### Example - /// ```rust,ignore - /// 'x' as u8 - /// ``` - /// - /// A better version, using the byte literal: - /// - /// ```rust,ignore - /// b'x' - /// ``` - #[clippy::version = "pre 1.29.0"] - pub CHAR_LIT_AS_U8, - complexity, - "casting a character literal to `u8` truncates" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for `as` casts between raw pointers without changing its mutability, - /// namely `*const T` to `*const U` and `*mut T` to `*mut U`. - /// - /// ### Why is this bad? - /// 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 - /// ```no_run - /// let ptr: *const u32 = &42_u32; - /// let mut_ptr: *mut u32 = &mut 42_u32; - /// let _ = ptr as *const i32; - /// let _ = mut_ptr as *mut i32; - /// ``` - /// Use instead: - /// ```no_run - /// let ptr: *const u32 = &42_u32; - /// let mut_ptr: *mut u32 = &mut 42_u32; - /// let _ = ptr.cast::(); - /// let _ = mut_ptr.cast::(); - /// ``` - #[clippy::version = "1.51.0"] - pub PTR_AS_PTR, - pedantic, - "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 - /// ```no_run - /// let ptr: *const u32 = &42_u32; - /// let mut_ptr = ptr as *mut u32; - /// let ptr = mut_ptr as *const u32; - /// ``` - /// Use instead: - /// ```no_run - /// let ptr: *const u32 = &42_u32; - /// let mut_ptr = ptr.cast_mut(); - /// let ptr = mut_ptr.cast_const(); - /// ``` - #[clippy::version = "1.72.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 - /// value. - /// - /// ### Why is this bad? - /// The resulting integral value will not match the value of the variant it came from. - /// - /// ### Example - /// ```no_run - /// enum E { X = 256 }; - /// let _ = E::X as u8; - /// ``` - #[clippy::version = "1.61.0"] - pub CAST_ENUM_TRUNCATION, - suspicious, - "casts from an enum type to an integral type which will truncate the value" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for `as` casts between raw pointers to slices with differently sized elements. - /// - /// ### Why is this bad? - /// The produced raw pointer to a slice does not update its length metadata. The produced - /// pointer will point to a different number of bytes than the original pointer because the - /// length metadata of a raw slice pointer is in elements rather than bytes. - /// Producing a slice reference from the raw pointer will either create a slice with - /// less data (which can be surprising) or create a slice with more data and cause Undefined Behavior. - /// - /// ### Example - /// // Missing data - /// ```no_run - /// let a = [1_i32, 2, 3, 4]; - /// let p = &a as *const [i32] as *const [u8]; - /// unsafe { - /// println!("{:?}", &*p); - /// } - /// ``` - /// // Undefined Behavior (note: also potential alignment issues) - /// ```no_run - /// let a = [1_u8, 2, 3, 4]; - /// let p = &a as *const [u8] as *const [u32]; - /// unsafe { - /// println!("{:?}", &*p); - /// } - /// ``` - /// Instead use `ptr::slice_from_raw_parts` to construct a slice from a data pointer and the correct length - /// ```no_run - /// let a = [1_i32, 2, 3, 4]; - /// let old_ptr = &a as *const [i32]; - /// // The data pointer is cast to a pointer to the target `u8` not `[u8]` - /// // The length comes from the known length of 4 i32s times the 4 bytes per i32 - /// let new_ptr = core::ptr::slice_from_raw_parts(old_ptr as *const u8, 16); - /// unsafe { - /// println!("{:?}", &*new_ptr); - /// } - /// ``` - #[clippy::version = "1.61.0"] - pub CAST_SLICE_DIFFERENT_SIZES, - correctness, - "casting using `as` between raw pointers to slices of types with different sizes" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for casts from an enum tuple constructor to an integer. - /// - /// ### Why is this bad? - /// The cast is easily confused with casting a c-like enum value to an integer. - /// - /// ### Example - /// ```no_run - /// enum E { X(i32) }; - /// let _ = E::X as usize; - /// ``` - #[clippy::version = "1.61.0"] - pub CAST_ENUM_CONSTRUCTOR, - suspicious, - "casts from an enum tuple constructor to an integer" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of the `abs()` method that cast the result to unsigned. - /// - /// ### Why is this bad? - /// The `unsigned_abs()` method avoids panic when called on the MIN value. - /// - /// ### Example - /// ```no_run - /// let x: i32 = -42; - /// let y: u32 = x.abs() as u32; - /// ``` - /// Use instead: - /// ```no_run - /// let x: i32 = -42; - /// let y: u32 = x.unsigned_abs(); - /// ``` - #[clippy::version = "1.62.0"] - pub CAST_ABS_TO_UNSIGNED, - suspicious, - "casting the result of `abs()` to an unsigned integer can panic" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for the usage of `as _` conversion using inferred type. - /// - /// ### Why is this bad? - /// The conversion might include lossy conversion and dangerous cast that might go - /// undetected due to the type being inferred. - /// - /// The lint is allowed by default as using `_` is less wordy than always specifying the type. - /// - /// ### Example - /// ```no_run - /// fn foo(n: usize) {} - /// let n: u16 = 256; - /// foo(n as _); - /// ``` - /// Use instead: - /// ```no_run - /// fn foo(n: usize) {} - /// let n: u16 = 256; - /// foo(n as usize); - /// ``` - #[clippy::version = "1.63.0"] - pub AS_UNDERSCORE, - restriction, - "detects `as _` conversion" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for the usage of `&expr as *const T` or - /// `&mut expr as *mut T`, and suggest using `ptr::addr_of` or - /// `ptr::addr_of_mut` instead. - /// - /// ### Why is this bad? - /// This would improve readability and avoid creating a reference - /// that points to an uninitialized value or unaligned place. - /// Read the `ptr::addr_of` docs for more information. - /// - /// ### Example - /// ```no_run - /// let val = 1; - /// let p = &val as *const i32; - /// - /// let mut val_mut = 1; - /// let p_mut = &mut val_mut as *mut i32; - /// ``` - /// Use instead: - /// ```no_run - /// let val = 1; - /// let p = std::ptr::addr_of!(val); - /// - /// let mut val_mut = 1; - /// let p_mut = std::ptr::addr_of_mut!(val_mut); - /// ``` - #[clippy::version = "1.60.0"] - pub BORROW_AS_PTR, - pedantic, - "borrowing just to cast to a raw pointer" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for a raw slice being cast to a slice pointer - /// - /// ### Why is this bad? - /// This can result in multiple `&mut` references to the same location when only a pointer is - /// required. - /// `ptr::slice_from_raw_parts` is a safe alternative that doesn't require - /// the same [safety requirements] to be upheld. - /// - /// ### Example - /// ```rust,ignore - /// let _: *const [u8] = std::slice::from_raw_parts(ptr, len) as *const _; - /// let _: *mut [u8] = std::slice::from_raw_parts_mut(ptr, len) as *mut _; - /// ``` - /// Use instead: - /// ```rust,ignore - /// let _: *const [u8] = std::ptr::slice_from_raw_parts(ptr, len); - /// let _: *mut [u8] = std::ptr::slice_from_raw_parts_mut(ptr, len); - /// ``` - /// [safety requirements]: https://doc.rust-lang.org/std/slice/fn.from_raw_parts.html#safety - #[clippy::version = "1.65.0"] - pub CAST_SLICE_FROM_RAW_PARTS, - suspicious, - "casting a slice created from a pointer and length to a slice pointer" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for the result of a `&self`-taking `as_ptr` being cast to a mutable pointer - /// - /// ### Why is this bad? - /// Since `as_ptr` takes a `&self`, the pointer won't have write permissions unless interior - /// mutability is used, making it unlikely that having it as a mutable pointer is correct. - /// - /// ### Example - /// ```no_run - /// let mut vec = Vec::::with_capacity(1); - /// let ptr = vec.as_ptr() as *mut u8; - /// unsafe { ptr.write(4) }; // UNDEFINED BEHAVIOUR - /// ``` - /// Use instead: - /// ```no_run - /// let mut vec = Vec::::with_capacity(1); - /// let ptr = vec.as_mut_ptr(); - /// unsafe { ptr.write(4) }; - /// ``` - #[clippy::version = "1.66.0"] - pub AS_PTR_CAST_MUT, - nursery, - "casting the result of the `&self`-taking `as_ptr` to a mutable pointer" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for a known NaN float being cast to an integer - /// - /// ### Why is this bad? - /// NaNs are cast into zero, so one could simply use this and make the - /// code more readable. The lint could also hint at a programmer error. - /// - /// ### Example - /// ```rust,ignore - /// let _: (0.0_f32 / 0.0) as u64; - /// ``` - /// Use instead: - /// ```rust,ignore - /// let _: = 0_u64; - /// ``` - #[clippy::version = "1.66.0"] - pub CAST_NAN_TO_INT, - suspicious, - "casting a known floating-point NaN into an integer" -} - -declare_clippy_lint! { - /// ### What it does - /// Catch casts from `0` to some pointer type - /// - /// ### Why is this bad? - /// This generally means `null` and is better expressed as - /// {`std`, `core`}`::ptr::`{`null`, `null_mut`}. - /// - /// ### Example - /// ```no_run - /// let a = 0 as *const u32; - /// ``` - /// - /// Use instead: - /// ```no_run - /// let a = std::ptr::null::(); - /// ``` - #[clippy::version = "pre 1.29.0"] - pub ZERO_PTR, - style, - "using `0 as *{const, mut} T`" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for casts of references to pointer using `as` - /// and suggests `std::ptr::from_ref` and `std::ptr::from_mut` instead. - /// - /// ### Why is this bad? - /// Using `as` casts may result in silently changing mutability or type. - /// - /// ### Example - /// ```no_run - /// let a_ref = &1; - /// let a_ptr = a_ref as *const _; - /// ``` - /// Use instead: - /// ```no_run - /// let a_ref = &1; - /// let a_ptr = std::ptr::from_ref(a_ref); - /// ``` - #[clippy::version = "1.78.0"] - pub REF_AS_PTR, - pedantic, - "using `as` to cast a reference to pointer" -} - -pub struct Casts { - msrv: Msrv, -} - -impl Casts { - #[must_use] - pub fn new(msrv: Msrv) -> Self { - Self { msrv } - } -} - -impl_lint_pass!(Casts => [ - CAST_PRECISION_LOSS, - CAST_SIGN_LOSS, - CAST_POSSIBLE_TRUNCATION, - CAST_POSSIBLE_WRAP, - CAST_LOSSLESS, - CAST_PTR_ALIGNMENT, - CAST_SLICE_DIFFERENT_SIZES, - UNNECESSARY_CAST, - FN_TO_NUMERIC_CAST_ANY, - FN_TO_NUMERIC_CAST, - 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, - AS_UNDERSCORE, - BORROW_AS_PTR, - CAST_SLICE_FROM_RAW_PARTS, - AS_PTR_CAST_MUT, - CAST_NAN_TO_INT, - ZERO_PTR, - REF_AS_PTR, -]); - -impl<'tcx> LateLintPass<'tcx> for Casts { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if in_external_macro(cx.sess(), expr.span) { - return; - } - - if let ExprKind::Cast(cast_expr, cast_to_hir) = expr.kind { - if is_hir_ty_cfg_dependant(cx, cast_to_hir) { - return; - } - let (cast_from, cast_to) = ( - cx.typeck_results().expr_ty(cast_expr), - cx.typeck_results().expr_ty(expr), - ); - - if !expr.span.from_expansion() && unnecessary_cast::check(cx, expr, cast_expr, cast_from, cast_to) { - 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); - fn_to_numeric_cast_with_truncation::check(cx, expr, cast_expr, cast_from, cast_to); - zero_ptr::check(cx, expr, cast_expr, cast_to_hir); - - if cast_to.is_numeric() { - cast_possible_truncation::check(cx, expr, cast_expr, cast_from, cast_to, cast_to_hir.span); - if cast_from.is_numeric() { - cast_possible_wrap::check(cx, expr, cast_from, cast_to); - cast_precision_loss::check(cx, expr, cast_from, cast_to); - cast_sign_loss::check(cx, expr, cast_expr, cast_from, cast_to); - cast_abs_to_unsigned::check(cx, expr, cast_expr, cast_from, cast_to, &self.msrv); - cast_nan_to_int::check(cx, expr, cast_expr, cast_from, cast_to); - } - cast_lossless::check(cx, expr, cast_expr, cast_from, cast_to, cast_to_hir, &self.msrv); - cast_enum_constructor::check(cx, expr, cast_expr, cast_from); - } - - as_underscore::check(cx, expr, cast_to_hir); - - if self.msrv.meets(msrvs::PTR_FROM_REF) { - ref_as_ptr::check(cx, expr, cast_expr, cast_to_hir); - } else if self.msrv.meets(msrvs::BORROW_AS_PTR) { - borrow_as_ptr::check(cx, expr, cast_expr, cast_to_hir); - } - } - - cast_ptr_alignment::check(cx, expr); - char_lit_as_u8::check(cx, expr); - ptr_as_ptr::check(cx, expr, &self.msrv); - cast_slice_different_sizes::check(cx, expr, &self.msrv); - } - - extract_msrv_attr!(LateContext); -} diff --git a/clippy_lints/src/casts/ptr_as_ptr.rs b/clippy_lints/src/casts/ptr_as_ptr.rs deleted file mode 100644 index 2c168405ee26..000000000000 --- a/clippy_lints/src/casts/ptr_as_ptr.rs +++ /dev/null @@ -1,101 +0,0 @@ -use clippy_config::msrvs::{self, Msrv}; -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::snippet_with_applicability; -use clippy_utils::sugg::Sugg; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, Mutability, QPath, TyKind}; -use rustc_hir_pretty::qpath_to_string; -use rustc_lint::LateContext; -use rustc_middle::ty; -use rustc_span::sym; - -use super::PTR_AS_PTR; - -enum OmitFollowedCastReason<'a> { - None, - Null(&'a QPath<'a>), - NullMut(&'a QPath<'a>), -} - -impl OmitFollowedCastReason<'_> { - fn corresponding_item(&self) -> Option<&QPath<'_>> { - match self { - OmitFollowedCastReason::None => None, - OmitFollowedCastReason::Null(x) | OmitFollowedCastReason::NullMut(x) => Some(*x), - } - } -} - -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Msrv) { - if !msrv.meets(msrvs::POINTER_CAST) { - return; - } - - if let ExprKind::Cast(cast_expr, cast_to_hir_ty) = expr.kind - && let (cast_from, cast_to) = (cx.typeck_results().expr_ty(cast_expr), cx.typeck_results().expr_ty(expr)) - && let ty::RawPtr(_, from_mutbl) = cast_from.kind() - && let ty::RawPtr(to_pointee_ty, to_mutbl) = cast_to.kind() - && matches!((from_mutbl, to_mutbl), - (Mutability::Not, Mutability::Not) | (Mutability::Mut, Mutability::Mut)) - // The `U` in `pointer::cast` have to be `Sized` - // as explained here: https://github.com/rust-lang/rust/issues/60602. - && to_pointee_ty.is_sized(cx.tcx, cx.param_env) - { - let mut app = Applicability::MachineApplicable; - let turbofish = match &cast_to_hir_ty.kind { - TyKind::Infer => String::new(), - TyKind::Ptr(mut_ty) => { - if matches!(mut_ty.ty.kind, TyKind::Infer) { - String::new() - } else { - format!( - "::<{}>", - snippet_with_applicability(cx, mut_ty.ty.span, "/* type */", &mut app) - ) - } - }, - _ => return, - }; - - // following `cast` does not compile because it fails to infer what type is expected - // as type argument to `std::ptr::ptr_null` or `std::ptr::ptr_null_mut`, so - // we omit following `cast`: - let omit_cast = if let ExprKind::Call(func, []) = cast_expr.kind - && let ExprKind::Path(ref qpath @ QPath::Resolved(None, path)) = func.kind - && let Some(method_defid) = path.res.opt_def_id() - { - if cx.tcx.is_diagnostic_item(sym::ptr_null, method_defid) { - OmitFollowedCastReason::Null(qpath) - } else if cx.tcx.is_diagnostic_item(sym::ptr_null_mut, method_defid) { - OmitFollowedCastReason::NullMut(qpath) - } else { - OmitFollowedCastReason::None - } - } else { - OmitFollowedCastReason::None - }; - - let (help, final_suggestion) = if let Some(method) = omit_cast.corresponding_item() { - // don't force absolute path - let method = qpath_to_string(&cx.tcx, method); - ("try call directly", format!("{method}{turbofish}()")) - } else { - let cast_expr_sugg = Sugg::hir_with_applicability(cx, cast_expr, "_", &mut app); - - ( - "try `pointer::cast`, a safer alternative", - format!("{}.cast{turbofish}()", cast_expr_sugg.maybe_par()), - ) - }; - - span_lint_and_sugg( - cx, - PTR_AS_PTR, - expr.span, - "`as` casting between raw pointers without changing its mutability", - help, - final_suggestion, - app, - ); - } -} diff --git a/clippy_lints/src/casts/ptr_cast_constness.rs b/clippy_lints/src/casts/ptr_cast_constness.rs deleted file mode 100644 index 921693567fcd..000000000000 --- a/clippy_lints/src/casts/ptr_cast_constness.rs +++ /dev/null @@ -1,44 +0,0 @@ -use clippy_config::msrvs::{self, Msrv}; -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::sugg::Sugg; -use rustc_errors::Applicability; -use rustc_hir::{Expr, Mutability}; -use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty}; - -use super::PTR_CAST_CONSTNESS; - -pub(super) fn check<'tcx>( - cx: &LateContext<'_>, - expr: &Expr<'_>, - cast_expr: &Expr<'_>, - cast_from: Ty<'tcx>, - cast_to: Ty<'tcx>, - msrv: &Msrv, -) { - if msrv.meets(msrvs::POINTER_CAST_CONSTNESS) - && let ty::RawPtr(from_ty, from_mutbl) = cast_from.kind() - && let ty::RawPtr(to_ty, to_mutbl) = cast_to.kind() - && matches!( - (from_mutbl, to_mutbl), - (Mutability::Not, Mutability::Mut) | (Mutability::Mut, Mutability::Not) - ) - && from_ty == to_ty - { - let sugg = Sugg::hir(cx, cast_expr, "_"); - let constness = match *to_mutbl { - Mutability::Not => "const", - Mutability::Mut => "mut", - }; - - span_lint_and_sugg( - cx, - PTR_CAST_CONSTNESS, - expr.span, - "`as` casting between raw pointers while changing only its constness", - format!("try `pointer::cast_{constness}`, a safer alternative"), - format!("{}.cast_{constness}()", sugg.maybe_par()), - Applicability::MachineApplicable, - ); - } -} diff --git a/clippy_lints/src/casts/ref_as_ptr.rs b/clippy_lints/src/casts/ref_as_ptr.rs deleted file mode 100644 index f42bafce4dde..000000000000 --- a/clippy_lints/src/casts/ref_as_ptr.rs +++ /dev/null @@ -1,63 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::snippet_with_applicability; -use clippy_utils::sugg::Sugg; -use clippy_utils::{expr_use_ctxt, is_no_std_crate, ExprUseNode}; -use rustc_errors::Applicability; -use rustc_hir::{Expr, Mutability, Ty, TyKind}; -use rustc_lint::LateContext; -use rustc_middle::ty; - -use super::REF_AS_PTR; - -pub(super) fn check<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx Expr<'_>, - cast_expr: &'tcx Expr<'_>, - cast_to_hir_ty: &Ty<'_>, -) { - let (cast_from, cast_to) = ( - cx.typeck_results().expr_ty(cast_expr), - cx.typeck_results().expr_ty(expr), - ); - - if matches!(cast_from.kind(), ty::Ref(..)) - && let ty::RawPtr(_, to_mutbl) = cast_to.kind() - && let Some(use_cx) = expr_use_ctxt(cx, expr) - // TODO: only block the lint if `cast_expr` is a temporary - && !matches!(use_cx.node, ExprUseNode::LetStmt(_) | ExprUseNode::ConstStatic(_)) - { - let core_or_std = if is_no_std_crate(cx) { "core" } else { "std" }; - let fn_name = match to_mutbl { - Mutability::Not => "from_ref", - Mutability::Mut => "from_mut", - }; - - let mut app = Applicability::MachineApplicable; - let turbofish = match &cast_to_hir_ty.kind { - TyKind::Infer => String::new(), - TyKind::Ptr(mut_ty) => { - if matches!(mut_ty.ty.kind, TyKind::Infer) { - String::new() - } else { - format!( - "::<{}>", - snippet_with_applicability(cx, mut_ty.ty.span, "/* type */", &mut app) - ) - } - }, - _ => return, - }; - - let cast_expr_sugg = Sugg::hir_with_applicability(cx, cast_expr, "_", &mut app); - - span_lint_and_sugg( - cx, - REF_AS_PTR, - expr.span, - "reference as raw pointer", - "try", - format!("{core_or_std}::ptr::{fn_name}{turbofish}({cast_expr_sugg})"), - app, - ); - } -} diff --git a/clippy_lints/src/casts/unnecessary_cast.rs b/clippy_lints/src/casts/unnecessary_cast.rs deleted file mode 100644 index a7f7bf7854e6..000000000000 --- a/clippy_lints/src/casts/unnecessary_cast.rs +++ /dev/null @@ -1,302 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::numeric_literal::NumericLiteral; -use clippy_utils::source::snippet_opt; -use clippy_utils::visitors::{for_each_expr, Visitable}; -use clippy_utils::{get_parent_expr, is_hir_ty_cfg_dependant, is_ty_alias, path_to_local}; -use rustc_ast::{LitFloatType, LitIntType, LitKind}; -use rustc_errors::Applicability; -use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{Expr, ExprKind, Lit, Node, Path, QPath, TyKind, UnOp}; -use rustc_lint::{LateContext, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, FloatTy, InferTy, Ty}; -use std::ops::ControlFlow; - -use super::UNNECESSARY_CAST; - -#[expect(clippy::too_many_lines)] -pub(super) fn check<'tcx>( - cx: &LateContext<'tcx>, - expr: &Expr<'tcx>, - cast_expr: &Expr<'tcx>, - cast_from: Ty<'tcx>, - cast_to: Ty<'tcx>, -) -> bool { - let cast_str = snippet_opt(cx, cast_expr.span).unwrap_or_default(); - - if let ty::RawPtr(..) = cast_from.kind() - // check both mutability and type are the same - && cast_from.kind() == cast_to.kind() - && let ExprKind::Cast(_, cast_to_hir) = expr.kind - // Ignore casts to e.g. type aliases and infer types - // - p as pointer_alias - // - p as _ - && let TyKind::Ptr(to_pointee) = cast_to_hir.kind - { - match to_pointee.ty.kind { - // Ignore casts to pointers that are aliases or cfg dependant, e.g. - // - p as *const std::ffi::c_char (alias) - // - p as *const std::os::raw::c_char (cfg dependant) - TyKind::Path(qpath) => { - if is_ty_alias(&qpath) || is_hir_ty_cfg_dependant(cx, to_pointee.ty) { - return false; - } - }, - // Ignore `p as *const _` - TyKind::Infer => return false, - _ => {}, - } - - span_lint_and_sugg( - cx, - UNNECESSARY_CAST, - expr.span, - format!( - "casting raw pointers to the same type and constness is unnecessary (`{cast_from}` -> `{cast_to}`)" - ), - "try", - cast_str.clone(), - Applicability::MaybeIncorrect, - ); - } - - // skip cast of local that is a type alias - if let ExprKind::Cast(inner, ..) = expr.kind - && let ExprKind::Path(qpath) = inner.kind - && let QPath::Resolved(None, Path { res, .. }) = qpath - && let Res::Local(hir_id) = res - && let parent = cx.tcx.parent_hir_node(*hir_id) - && let Node::LetStmt(local) = parent - { - if let Some(ty) = local.ty - && let TyKind::Path(qpath) = ty.kind - && is_ty_alias(&qpath) - { - return false; - } - - if let Some(expr) = local.init - && let ExprKind::Cast(.., cast_to) = expr.kind - && let TyKind::Path(qpath) = cast_to.kind - && is_ty_alias(&qpath) - { - return false; - } - } - - // skip cast to non-primitive type - if let ExprKind::Cast(_, cast_to) = expr.kind - && let TyKind::Path(QPath::Resolved(_, path)) = &cast_to.kind - && let Res::PrimTy(_) = path.res - { - } else { - return false; - } - - // skip cast of fn call that returns type alias - if let ExprKind::Cast(inner, ..) = expr.kind - && is_cast_from_ty_alias(cx, inner, cast_from) - { - return false; - } - - if let Some(lit) = get_numeric_literal(cast_expr) { - let literal_str = &cast_str; - - if let LitKind::Int(n, _) = lit.node - && let Some(src) = snippet_opt(cx, cast_expr.span) - && cast_to.is_floating_point() - && let Some(num_lit) = NumericLiteral::from_lit_kind(&src, &lit.node) - && let from_nbits = 128 - n.get().leading_zeros() - && let to_nbits = fp_ty_mantissa_nbits(cast_to) - && from_nbits != 0 - && to_nbits != 0 - && from_nbits <= to_nbits - && num_lit.is_decimal() - { - lint_unnecessary_cast(cx, expr, num_lit.integer, cast_from, cast_to); - return true; - } - - match lit.node { - LitKind::Int(_, LitIntType::Unsuffixed) if cast_to.is_integral() => { - lint_unnecessary_cast(cx, expr, literal_str, cast_from, cast_to); - return false; - }, - LitKind::Float(_, LitFloatType::Unsuffixed) if cast_to.is_floating_point() => { - lint_unnecessary_cast(cx, expr, literal_str, cast_from, cast_to); - return false; - }, - LitKind::Int(_, LitIntType::Signed(_) | LitIntType::Unsigned(_)) - | LitKind::Float(_, LitFloatType::Suffixed(_)) - if cast_from.kind() == cast_to.kind() => - { - if let Some(src) = snippet_opt(cx, cast_expr.span) { - if let Some(num_lit) = NumericLiteral::from_lit_kind(&src, &lit.node) { - lint_unnecessary_cast(cx, expr, num_lit.integer, cast_from, cast_to); - return true; - } - } - }, - _ => {}, - } - } - - if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) { - if let Some(id) = path_to_local(cast_expr) - && !cx.tcx.hir().span(id).eq_ctxt(cast_expr.span) - { - // Binding context is different than the identifiers context. - // Weird macro wizardry could be involved here. - return false; - } - - // If the whole cast expression is a unary expression (`(*x as T)`) or an addressof - // expression (`(&x as T)`), then not surrounding the suggestion into a block risks us - // changing the precedence of operators if the cast expression is followed by an operation - // with higher precedence than the unary operator (`(*x as T).foo()` would become - // `*x.foo()`, which changes what the `*` applies on). - // The same is true if the expression encompassing the cast expression is a unary - // expression or an addressof expression. - let needs_block = matches!(cast_expr.kind, ExprKind::Unary(..) | ExprKind::AddrOf(..)) - || get_parent_expr(cx, expr) - .map_or(false, |e| matches!(e.kind, ExprKind::Unary(..) | ExprKind::AddrOf(..))); - - span_lint_and_sugg( - cx, - UNNECESSARY_CAST, - expr.span, - format!("casting to the same type is unnecessary (`{cast_from}` -> `{cast_to}`)"), - "try", - if needs_block { - format!("{{ {cast_str} }}") - } else { - cast_str - }, - Applicability::MachineApplicable, - ); - return true; - } - - false -} - -fn lint_unnecessary_cast( - cx: &LateContext<'_>, - expr: &Expr<'_>, - raw_literal_str: &str, - cast_from: Ty<'_>, - cast_to: Ty<'_>, -) { - let literal_kind_name = if cast_from.is_integral() { "integer" } else { "float" }; - // first we remove all matches so `-(1)` become `-1`, and remove trailing dots, so `1.` become `1` - let literal_str = raw_literal_str - .replace(['(', ')'], "") - .trim_end_matches('.') - .to_string(); - // we know need to check if the parent is a method call, to add parenthesis accordingly (eg: - // (-1).foo() instead of -1.foo()) - let sugg = if let Some(parent_expr) = get_parent_expr(cx, expr) - && let ExprKind::MethodCall(..) = parent_expr.kind - && literal_str.starts_with('-') - { - format!("({literal_str}_{cast_to})") - } else { - format!("{literal_str}_{cast_to}") - }; - - span_lint_and_sugg( - cx, - UNNECESSARY_CAST, - expr.span, - format!("casting {literal_kind_name} literal to `{cast_to}` is unnecessary"), - "try", - sugg, - Applicability::MachineApplicable, - ); -} - -fn get_numeric_literal<'e>(expr: &'e Expr<'e>) -> Option<&'e Lit> { - match expr.kind { - ExprKind::Lit(lit) => Some(lit), - ExprKind::Unary(UnOp::Neg, e) => { - if let ExprKind::Lit(lit) = e.kind { - Some(lit) - } else { - None - } - }, - _ => None, - } -} - -/// Returns the mantissa bits wide of a fp type. -/// Will return 0 if the type is not a fp -fn fp_ty_mantissa_nbits(typ: Ty<'_>) -> u32 { - match typ.kind() { - ty::Float(FloatTy::F32) => 23, - ty::Float(FloatTy::F64) | ty::Infer(InferTy::FloatVar(_)) => 52, - _ => 0, - } -} - -/// Finds whether an `Expr` returns a type alias. -/// -/// TODO: Maybe we should move this to `clippy_utils` so others won't need to go down this dark, -/// dark path reimplementing this (or something similar). -fn is_cast_from_ty_alias<'tcx>(cx: &LateContext<'tcx>, expr: impl Visitable<'tcx>, cast_from: Ty<'tcx>) -> bool { - for_each_expr(expr, |expr| { - // Calls are a `Path`, and usage of locals are a `Path`. So, this checks - // - call() as i32 - // - local as i32 - if let ExprKind::Path(qpath) = expr.kind { - let res = cx.qpath_res(&qpath, expr.hir_id); - // Function call - if let Res::Def(DefKind::Fn, def_id) = res { - let Some(snippet) = snippet_opt(cx, cx.tcx.def_span(def_id)) else { - return ControlFlow::Continue(()); - }; - // This is the worst part of this entire function. This is the only way I know of to - // check whether a function returns a type alias. Sure, you can get the return type - // from a function in the current crate as an hir ty, but how do you get it for - // external functions?? Simple: It's impossible. So, we check whether a part of the - // function's declaration snippet is exactly equal to the `Ty`. That way, we can - // see whether it's a type alias. - // - // FIXME: This won't work if the type is given an alias through `use`, should we - // consider this a type alias as well? - if !snippet - .split("->") - .skip(1) - .map(|s| snippet_eq_ty(s, cast_from) || s.split("where").any(|ty| snippet_eq_ty(ty, cast_from))) - .any(|a| a) - { - return ControlFlow::Break(()); - } - // Local usage - } else if let Res::Local(hir_id) = res - && let Node::LetStmt(l) = cx.tcx.parent_hir_node(hir_id) - { - if let Some(e) = l.init - && is_cast_from_ty_alias(cx, e, cast_from) - { - return ControlFlow::Break::<()>(()); - } - - if let Some(ty) = l.ty - && let TyKind::Path(qpath) = ty.kind - && is_ty_alias(&qpath) - { - return ControlFlow::Break::<()>(()); - } - } - } - - ControlFlow::Continue(()) - }) - .is_some() -} - -fn snippet_eq_ty(snippet: &str, ty: Ty<'_>) -> bool { - snippet.trim() == ty.to_string() || snippet.trim().contains(&format!("::{ty}")) -} diff --git a/clippy_lints/src/casts/utils.rs b/clippy_lints/src/casts/utils.rs deleted file mode 100644 index 5a4f20f09906..000000000000 --- a/clippy_lints/src/casts/utils.rs +++ /dev/null @@ -1,75 +0,0 @@ -use clippy_utils::ty::{read_explicit_enum_value, EnumValue}; -use rustc_middle::ty::{self, AdtDef, IntTy, Ty, TyCtxt, UintTy, VariantDiscr}; - -/// Returns the size in bits of an integral type. -/// Will return 0 if the type is not an int or uint variant -pub(super) fn int_ty_to_nbits(typ: Ty<'_>, tcx: TyCtxt<'_>) -> u64 { - match typ.kind() { - ty::Int(i) => match i { - IntTy::Isize => tcx.data_layout.pointer_size.bits(), - IntTy::I8 => 8, - IntTy::I16 => 16, - IntTy::I32 => 32, - IntTy::I64 => 64, - IntTy::I128 => 128, - }, - ty::Uint(i) => match i { - UintTy::Usize => tcx.data_layout.pointer_size.bits(), - UintTy::U8 => 8, - UintTy::U16 => 16, - UintTy::U32 => 32, - UintTy::U64 => 64, - UintTy::U128 => 128, - }, - _ => 0, - } -} - -pub(super) fn enum_value_nbits(value: EnumValue) -> u64 { - match value { - EnumValue::Unsigned(x) => 128 - x.leading_zeros(), - EnumValue::Signed(x) if x < 0 => 128 - (-(x + 1)).leading_zeros() + 1, - EnumValue::Signed(x) => 128 - x.leading_zeros(), - } - .into() -} - -pub(super) fn enum_ty_to_nbits(adt: AdtDef<'_>, tcx: TyCtxt<'_>) -> u64 { - let mut explicit = 0i128; - let (start, end) = adt - .variants() - .iter() - .fold((0, i128::MIN), |(start, end), variant| match variant.discr { - VariantDiscr::Relative(x) => match explicit.checked_add(i128::from(x)) { - Some(x) => (start, end.max(x)), - None => (i128::MIN, end), - }, - VariantDiscr::Explicit(id) => match read_explicit_enum_value(tcx, id) { - Some(EnumValue::Signed(x)) => { - explicit = x; - (start.min(x), end.max(x)) - }, - Some(EnumValue::Unsigned(x)) => match i128::try_from(x) { - Ok(x) => { - explicit = x; - (start, end.max(x)) - }, - Err(_) => (i128::MIN, end), - }, - None => (start, end), - }, - }); - - if start > end { - // No variants. - 0 - } else { - let neg_bits = if start < 0 { - 128 - (-(start + 1)).leading_zeros() + 1 - } else { - 0 - }; - let pos_bits = if end > 0 { 128 - end.leading_zeros() } else { 0 }; - neg_bits.max(pos_bits).into() - } -} diff --git a/clippy_lints/src/casts/zero_ptr.rs b/clippy_lints/src/casts/zero_ptr.rs deleted file mode 100644 index 5071af5ecb98..000000000000 --- a/clippy_lints/src/casts/zero_ptr.rs +++ /dev/null @@ -1,39 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::snippet_opt; -use clippy_utils::{in_constant, is_integer_literal, std_or_core}; -use rustc_errors::Applicability; -use rustc_hir::{Expr, Mutability, Ty, TyKind}; -use rustc_lint::LateContext; - -use super::ZERO_PTR; - -pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, from: &Expr<'_>, to: &Ty<'_>) { - if let TyKind::Ptr(ref mut_ty) = to.kind - && is_integer_literal(from, 0) - && !in_constant(cx, from.hir_id) - && let Some(std_or_core) = std_or_core(cx) - { - let (msg, sugg_fn) = match mut_ty.mutbl { - Mutability::Mut => ("`0 as *mut _` detected", "ptr::null_mut"), - Mutability::Not => ("`0 as *const _` detected", "ptr::null"), - }; - - let sugg = if let TyKind::Infer = mut_ty.ty.kind { - format!("{std_or_core}::{sugg_fn}()") - } else if let Some(mut_ty_snip) = snippet_opt(cx, mut_ty.ty.span) { - format!("{std_or_core}::{sugg_fn}::<{mut_ty_snip}>()") - } else { - return; - }; - - span_lint_and_sugg( - cx, - ZERO_PTR, - expr.span, - msg, - "try", - sugg, - Applicability::MachineApplicable, - ); - } -} diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs deleted file mode 100644 index 92810ea2aa0f..000000000000 --- a/clippy_lints/src/checked_conversions.rs +++ /dev/null @@ -1,324 +0,0 @@ -//! lint on manually implemented checked conversions that could be transformed into `try_from` - -use clippy_config::msrvs::{self, Msrv}; -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::snippet_with_applicability; -use clippy_utils::{in_constant, is_integer_literal, SpanlessEq}; -use rustc_errors::Applicability; -use rustc_hir::{BinOp, BinOpKind, Expr, ExprKind, QPath, TyKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_session::impl_lint_pass; - -declare_clippy_lint! { - /// ### What it does - /// Checks for explicit bounds checking when casting. - /// - /// ### Why is this bad? - /// Reduces the readability of statements & is error prone. - /// - /// ### Example - /// ```no_run - /// # let foo: u32 = 5; - /// foo <= i32::MAX as u32; - /// ``` - /// - /// Use instead: - /// ```no_run - /// # let foo = 1; - /// # #[allow(unused)] - /// i32::try_from(foo).is_ok(); - /// ``` - #[clippy::version = "1.37.0"] - pub CHECKED_CONVERSIONS, - pedantic, - "`try_from` could replace manual bounds checking when casting" -} - -pub struct CheckedConversions { - msrv: Msrv, -} - -impl CheckedConversions { - #[must_use] - pub fn new(msrv: Msrv) -> Self { - Self { msrv } - } -} - -impl_lint_pass!(CheckedConversions => [CHECKED_CONVERSIONS]); - -impl<'tcx> LateLintPass<'tcx> for CheckedConversions { - fn check_expr(&mut self, cx: &LateContext<'_>, item: &Expr<'_>) { - if !self.msrv.meets(msrvs::TRY_FROM) { - return; - } - - let result = if !in_constant(cx, item.hir_id) - && !in_external_macro(cx.sess(), item.span) - && let ExprKind::Binary(op, left, right) = &item.kind - { - match op.node { - BinOpKind::Ge | BinOpKind::Le => single_check(item), - BinOpKind::And => double_check(cx, left, right), - _ => None, - } - } else { - None - }; - - if let Some(cv) = result { - if let Some(to_type) = cv.to_type { - let mut applicability = Applicability::MachineApplicable; - let snippet = snippet_with_applicability(cx, cv.expr_to_cast.span, "_", &mut applicability); - span_lint_and_sugg( - cx, - CHECKED_CONVERSIONS, - item.span, - "checked cast can be simplified", - "try", - format!("{to_type}::try_from({snippet}).is_ok()"), - applicability, - ); - } - } - } - - extract_msrv_attr!(LateContext); -} - -/// Searches for a single check from unsigned to _ is done -/// todo: check for case signed -> larger unsigned == only x >= 0 -fn single_check<'tcx>(expr: &'tcx Expr<'tcx>) -> Option> { - check_upper_bound(expr).filter(|cv| cv.cvt == ConversionType::FromUnsigned) -} - -/// Searches for a combination of upper & lower bound checks -fn double_check<'a>(cx: &LateContext<'_>, left: &'a Expr<'_>, right: &'a Expr<'_>) -> Option> { - let upper_lower = |l, r| { - let upper = check_upper_bound(l); - let lower = check_lower_bound(r); - - upper.zip(lower).and_then(|(l, r)| l.combine(r, cx)) - }; - - upper_lower(left, right).or_else(|| upper_lower(right, left)) -} - -/// Contains the result of a tried conversion check -#[derive(Clone, Debug)] -struct Conversion<'a> { - cvt: ConversionType, - expr_to_cast: &'a Expr<'a>, - to_type: Option<&'a str>, -} - -/// The kind of conversion that is checked -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -enum ConversionType { - SignedToUnsigned, - SignedToSigned, - FromUnsigned, -} - -impl<'a> Conversion<'a> { - /// Combine multiple conversions if the are compatible - pub fn combine(self, other: Self, cx: &LateContext<'_>) -> Option> { - if self.is_compatible(&other, cx) { - // Prefer a Conversion that contains a type-constraint - Some(if self.to_type.is_some() { self } else { other }) - } else { - None - } - } - - /// Checks if two conversions are compatible - /// same type of conversion, same 'castee' and same 'to type' - pub fn is_compatible(&self, other: &Self, cx: &LateContext<'_>) -> bool { - (self.cvt == other.cvt) - && (SpanlessEq::new(cx).eq_expr(self.expr_to_cast, other.expr_to_cast)) - && (self.has_compatible_to_type(other)) - } - - /// Checks if the to-type is the same (if there is a type constraint) - fn has_compatible_to_type(&self, other: &Self) -> bool { - match (self.to_type, other.to_type) { - (Some(l), Some(r)) => l == r, - _ => true, - } - } - - /// Try to construct a new conversion if the conversion type is valid - fn try_new(expr_to_cast: &'a Expr<'_>, from_type: &str, to_type: &'a str) -> Option> { - ConversionType::try_new(from_type, to_type).map(|cvt| Conversion { - cvt, - expr_to_cast, - to_type: Some(to_type), - }) - } - - /// Construct a new conversion without type constraint - fn new_any(expr_to_cast: &'a Expr<'_>) -> Conversion<'a> { - Conversion { - cvt: ConversionType::SignedToUnsigned, - expr_to_cast, - to_type: None, - } - } -} - -impl ConversionType { - /// Creates a conversion type if the type is allowed & conversion is valid - #[must_use] - fn try_new(from: &str, to: &str) -> Option { - if UINTS.contains(&from) { - Some(Self::FromUnsigned) - } else if SINTS.contains(&from) { - if UINTS.contains(&to) { - Some(Self::SignedToUnsigned) - } else if SINTS.contains(&to) { - Some(Self::SignedToSigned) - } else { - None - } - } else { - None - } - } -} - -/// Check for `expr <= (to_type::MAX as from_type)` -fn check_upper_bound<'tcx>(expr: &'tcx Expr<'tcx>) -> Option> { - if let ExprKind::Binary(ref op, left, right) = &expr.kind - && let Some((candidate, check)) = normalize_le_ge(op, left, right) - && let Some((from, to)) = get_types_from_cast(check, INTS, "max_value", "MAX") - { - Conversion::try_new(candidate, from, to) - } else { - None - } -} - -/// Check for `expr >= 0|(to_type::MIN as from_type)` -fn check_lower_bound<'tcx>(expr: &'tcx Expr<'tcx>) -> Option> { - fn check_function<'a>(candidate: &'a Expr<'a>, check: &'a Expr<'a>) -> Option> { - (check_lower_bound_zero(candidate, check)).or_else(|| (check_lower_bound_min(candidate, check))) - } - - // First of we need a binary containing the expression & the cast - if let ExprKind::Binary(ref op, left, right) = &expr.kind { - normalize_le_ge(op, right, left).and_then(|(l, r)| check_function(l, r)) - } else { - None - } -} - -/// Check for `expr >= 0` -fn check_lower_bound_zero<'a>(candidate: &'a Expr<'_>, check: &'a Expr<'_>) -> Option> { - is_integer_literal(check, 0).then(|| Conversion::new_any(candidate)) -} - -/// Check for `expr >= (to_type::MIN as from_type)` -fn check_lower_bound_min<'a>(candidate: &'a Expr<'_>, check: &'a Expr<'_>) -> Option> { - if let Some((from, to)) = get_types_from_cast(check, SINTS, "min_value", "MIN") { - Conversion::try_new(candidate, from, to) - } else { - None - } -} - -/// Tries to extract the from- and to-type from a cast expression -fn get_types_from_cast<'a>( - expr: &'a Expr<'_>, - types: &'a [&str], - func: &'a str, - assoc_const: &'a str, -) -> Option<(&'a str, &'a str)> { - // `to_type::max_value() as from_type` - // or `to_type::MAX as from_type` - let call_from_cast: Option<(&Expr<'_>, &str)> = if let ExprKind::Cast(limit, from_type) = &expr.kind - // to_type::max_value(), from_type - && let TyKind::Path(ref from_type_path) = &from_type.kind - && let Some(from_sym) = int_ty_to_sym(from_type_path) - { - Some((limit, from_sym)) - } else { - None - }; - - // `from_type::from(to_type::max_value())` - let limit_from: Option<(&Expr<'_>, &str)> = call_from_cast.or_else(|| { - if let ExprKind::Call(from_func, [limit]) = &expr.kind - // `from_type::from, to_type::max_value()` - // `from_type::from` - && let ExprKind::Path(ref path) = &from_func.kind - && let Some(from_sym) = get_implementing_type(path, INTS, "from") - { - Some((limit, from_sym)) - } else { - None - } - }); - - if let Some((limit, from_type)) = limit_from { - match limit.kind { - // `from_type::from(_)` - ExprKind::Call(path, _) => { - if let ExprKind::Path(ref path) = path.kind { - // `to_type` - if let Some(to_type) = get_implementing_type(path, types, func) { - return Some((from_type, to_type)); - } - } - }, - // `to_type::MAX` - ExprKind::Path(ref path) => { - if let Some(to_type) = get_implementing_type(path, types, assoc_const) { - return Some((from_type, to_type)); - } - }, - _ => {}, - } - }; - None -} - -/// Gets the type which implements the called function -fn get_implementing_type<'a>(path: &QPath<'_>, candidates: &'a [&str], function: &str) -> Option<&'a str> { - if let QPath::TypeRelative(ty, path) = &path - && path.ident.name.as_str() == function - && let TyKind::Path(QPath::Resolved(None, tp)) = &ty.kind - && let [int] = tp.segments - { - let name = int.ident.name.as_str(); - candidates.iter().find(|c| &name == *c).copied() - } else { - None - } -} - -/// Gets the type as a string, if it is a supported integer -fn int_ty_to_sym<'tcx>(path: &QPath<'_>) -> Option<&'tcx str> { - if let QPath::Resolved(_, path) = *path - && let [ty] = path.segments - { - let name = ty.ident.name.as_str(); - INTS.iter().find(|c| &name == *c).copied() - } else { - None - } -} - -/// Will return the expressions as if they were expr1 <= expr2 -fn normalize_le_ge<'a>(op: &BinOp, left: &'a Expr<'a>, right: &'a Expr<'a>) -> Option<(&'a Expr<'a>, &'a Expr<'a>)> { - match op.node { - BinOpKind::Le => Some((left, right)), - BinOpKind::Ge => Some((right, left)), - _ => None, - } -} - -// Constants -const UINTS: &[&str] = &["u8", "u16", "u32", "u64", "usize"]; -const SINTS: &[&str] = &["i8", "i16", "i32", "i64", "isize"]; -const INTS: &[&str] = &["u8", "u16", "u32", "u64", "usize", "i8", "i16", "i32", "i64", "isize"]; diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs deleted file mode 100644 index ee1bb63b50d3..000000000000 --- a/clippy_lints/src/cognitive_complexity.rs +++ /dev/null @@ -1,167 +0,0 @@ -//! calculate cognitive complexity and warn about overly complex functions - -use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::source::snippet_opt; -use clippy_utils::ty::is_type_diagnostic_item; -use clippy_utils::visitors::for_each_expr; -use clippy_utils::{get_async_fn_body, is_async_fn, LimitStack}; -use core::ops::ControlFlow; -use rustc_ast::ast::Attribute; -use rustc_hir::intravisit::FnKind; -use rustc_hir::{Body, Expr, ExprKind, FnDecl}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_session::impl_lint_pass; -use rustc_span::def_id::LocalDefId; -use rustc_span::{sym, BytePos, Span}; - -declare_clippy_lint! { - /// ### What it does - /// Checks for methods with high cognitive complexity. - /// - /// ### Why is this bad? - /// Methods of high cognitive complexity tend to be hard to - /// both read and maintain. Also LLVM will tend to optimize small methods better. - /// - /// ### Known problems - /// Sometimes it's hard to find a way to reduce the - /// complexity. - /// - /// ### Example - /// You'll see it when you get the warning. - #[clippy::version = "1.35.0"] - pub COGNITIVE_COMPLEXITY, - nursery, - "functions that should be split up into multiple functions" -} - -pub struct CognitiveComplexity { - limit: LimitStack, -} - -impl CognitiveComplexity { - #[must_use] - pub fn new(limit: u64) -> Self { - Self { - limit: LimitStack::new(limit), - } - } -} - -impl_lint_pass!(CognitiveComplexity => [COGNITIVE_COMPLEXITY]); - -impl CognitiveComplexity { - #[expect(clippy::cast_possible_truncation)] - fn check<'tcx>( - &mut self, - cx: &LateContext<'tcx>, - kind: FnKind<'tcx>, - decl: &'tcx FnDecl<'_>, - expr: &'tcx Expr<'_>, - body_span: Span, - ) { - if body_span.from_expansion() { - return; - } - - let mut cc = 1u64; - let mut returns = 0u64; - let _: Option = for_each_expr(expr, |e| { - match e.kind { - ExprKind::If(_, _, _) => { - cc += 1; - }, - ExprKind::Match(_, arms, _) => { - if arms.len() > 1 { - cc += 1; - } - cc += arms.iter().filter(|arm| arm.guard.is_some()).count() as u64; - }, - ExprKind::Ret(_) => returns += 1, - _ => {}, - } - ControlFlow::Continue(()) - }); - - let ret_ty = cx.typeck_results().node_type(expr.hir_id); - let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym::Result) { - returns - } else { - #[expect(clippy::integer_division)] - (returns / 2) - }; - - // prevent degenerate cases where unreachable code contains `return` statements - if cc >= ret_adjust { - cc -= ret_adjust; - } - - if cc > self.limit.limit() { - let fn_span = match kind { - FnKind::ItemFn(ident, _, _) | FnKind::Method(ident, _) => ident.span, - FnKind::Closure => { - let header_span = body_span.with_hi(decl.output.span().lo()); - let pos = snippet_opt(cx, header_span).and_then(|snip| { - let low_offset = snip.find('|')?; - let high_offset = 1 + snip.get(low_offset + 1..)?.find('|')?; - let low = header_span.lo() + BytePos(low_offset as u32); - let high = low + BytePos(high_offset as u32 + 1); - - Some((low, high)) - }); - - if let Some((low, high)) = pos { - Span::new(low, high, header_span.ctxt(), header_span.parent()) - } else { - return; - } - }, - }; - - span_lint_and_help( - cx, - COGNITIVE_COMPLEXITY, - fn_span, - format!( - "the function has a cognitive complexity of ({cc}/{})", - self.limit.limit() - ), - None, - "you could split it up into multiple smaller functions", - ); - } - } -} - -impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity { - fn check_fn( - &mut self, - cx: &LateContext<'tcx>, - kind: FnKind<'tcx>, - decl: &'tcx FnDecl<'_>, - body: &'tcx Body<'_>, - span: Span, - def_id: LocalDefId, - ) { - if !cx.tcx.has_attr(def_id, sym::test) { - let expr = if is_async_fn(kind) { - match get_async_fn_body(cx.tcx, body) { - Some(b) => b, - None => { - return; - }, - } - } else { - body.value - }; - - self.check(cx, kind, decl, expr, span); - } - } - - fn check_attributes(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) { - self.limit.push_attrs(cx.sess(), attrs, "cognitive_complexity"); - } - fn check_attributes_post(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) { - self.limit.pop_attrs(cx.sess(), attrs, "cognitive_complexity"); - } -} diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs deleted file mode 100644 index 07b02c98df15..000000000000 --- a/clippy_lints/src/collapsible_if.rs +++ /dev/null @@ -1,202 +0,0 @@ -//! Checks for if expressions that contain only an if expression. -//! -//! For example, the lint would catch: -//! -//! ```rust,ignore -//! if x { -//! if y { -//! println!("Hello world"); -//! } -//! } -//! ``` -//! -//! This lint is **warn** by default - -use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; -use clippy_utils::source::{snippet, snippet_block, snippet_block_with_applicability}; -use clippy_utils::sugg::Sugg; -use rustc_ast::ast; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::declare_lint_pass; -use rustc_span::Span; - -declare_clippy_lint! { - /// ### What it does - /// Checks for nested `if` statements which can be collapsed - /// by `&&`-combining their conditions. - /// - /// ### Why is this bad? - /// Each `if`-statement adds one level of nesting, which - /// makes code look more complex than it really is. - /// - /// ### Example - /// ```no_run - /// # let (x, y) = (true, true); - /// if x { - /// if y { - /// // … - /// } - /// } - /// ``` - /// - /// Use instead: - /// ```no_run - /// # let (x, y) = (true, true); - /// if x && y { - /// // … - /// } - /// ``` - #[clippy::version = "pre 1.29.0"] - pub COLLAPSIBLE_IF, - style, - "nested `if`s that can be collapsed (e.g., `if x { if y { ... } }`" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for collapsible `else { if ... }` expressions - /// that can be collapsed to `else if ...`. - /// - /// ### Why is this bad? - /// Each `if`-statement adds one level of nesting, which - /// makes code look more complex than it really is. - /// - /// ### Example - /// ```rust,ignore - /// - /// if x { - /// … - /// } else { - /// if y { - /// … - /// } - /// } - /// ``` - /// - /// Should be written: - /// - /// ```rust,ignore - /// if x { - /// … - /// } else if y { - /// … - /// } - /// ``` - #[clippy::version = "1.51.0"] - pub COLLAPSIBLE_ELSE_IF, - style, - "nested `else`-`if` expressions that can be collapsed (e.g., `else { if x { ... } }`)" -} - -declare_lint_pass!(CollapsibleIf => [COLLAPSIBLE_IF, COLLAPSIBLE_ELSE_IF]); - -impl EarlyLintPass for CollapsibleIf { - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { - if !expr.span.from_expansion() { - check_if(cx, expr); - } - } -} - -fn check_if(cx: &EarlyContext<'_>, expr: &ast::Expr) { - if let ast::ExprKind::If(check, then, else_) = &expr.kind { - if let Some(else_) = else_ { - check_collapsible_maybe_if_let(cx, then.span, else_); - } else if let ast::ExprKind::Let(..) = check.kind { - // Prevent triggering on `if let a = b { if c { .. } }`. - } else { - check_collapsible_no_if_let(cx, expr, check, then); - } - } -} - -fn block_starts_with_comment(cx: &EarlyContext<'_>, expr: &ast::Block) -> bool { - // We trim all opening braces and whitespaces and then check if the next string is a comment. - let trimmed_block_text = snippet_block(cx, expr.span, "..", None) - .trim_start_matches(|c: char| c.is_whitespace() || c == '{') - .to_owned(); - trimmed_block_text.starts_with("//") || trimmed_block_text.starts_with("/*") -} - -fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, then_span: Span, else_: &ast::Expr) { - if let ast::ExprKind::Block(ref block, _) = else_.kind - && !block_starts_with_comment(cx, block) - && let Some(else_) = expr_block(block) - && else_.attrs.is_empty() - && !else_.span.from_expansion() - && let ast::ExprKind::If(..) = else_.kind - { - // Prevent "elseif" - // Check that the "else" is followed by whitespace - let up_to_else = then_span.between(block.span); - let requires_space = if let Some(c) = snippet(cx, up_to_else, "..").chars().last() { - !c.is_whitespace() - } else { - false - }; - - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - COLLAPSIBLE_ELSE_IF, - block.span, - "this `else { if .. }` block can be collapsed", - "collapse nested if block", - format!( - "{}{}", - if requires_space { " " } else { "" }, - snippet_block_with_applicability(cx, else_.span, "..", Some(block.span), &mut applicability) - ), - applicability, - ); - } -} - -fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: &ast::Expr, then: &ast::Block) { - if !block_starts_with_comment(cx, then) - && let Some(inner) = expr_block(then) - && inner.attrs.is_empty() - && let ast::ExprKind::If(ref check_inner, ref content, None) = inner.kind - // Prevent triggering on `if c { if let a = b { .. } }`. - && !matches!(check_inner.kind, ast::ExprKind::Let(..)) - && let ctxt = expr.span.ctxt() - && inner.span.ctxt() == ctxt - { - span_lint_and_then( - cx, - COLLAPSIBLE_IF, - expr.span, - "this `if` statement can be collapsed", - |diag| { - let mut app = Applicability::MachineApplicable; - let lhs = Sugg::ast(cx, check, "..", ctxt, &mut app); - let rhs = Sugg::ast(cx, check_inner, "..", ctxt, &mut app); - diag.span_suggestion( - expr.span, - "collapse nested if block", - format!( - "if {} {}", - lhs.and(&rhs), - snippet_block(cx, content.span, "..", Some(expr.span)), - ), - app, // snippet - ); - }, - ); - } -} - -/// If the block contains only one expression, return it. -fn expr_block(block: &ast::Block) -> Option<&ast::Expr> { - let mut it = block.stmts.iter(); - - if let (Some(stmt), None) = (it.next(), it.next()) { - match stmt.kind { - ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => Some(expr), - _ => None, - } - } else { - None - } -} diff --git a/clippy_lints/src/collection_is_never_read.rs b/clippy_lints/src/collection_is_never_read.rs deleted file mode 100644 index 70856b808810..000000000000 --- a/clippy_lints/src/collection_is_never_read.rs +++ /dev/null @@ -1,160 +0,0 @@ -use clippy_utils::diagnostics::span_lint; -use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item}; -use clippy_utils::visitors::{for_each_expr_with_closures, Visitable}; -use clippy_utils::{get_enclosing_block, path_to_local_id}; -use core::ops::ControlFlow; -use rustc_hir::{Body, ExprKind, HirId, LangItem, LetStmt, Node, PatKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::declare_lint_pass; -use rustc_span::symbol::sym; -use rustc_span::Symbol; - -declare_clippy_lint! { - /// ### What it does - /// Checks for collections that are never queried. - /// - /// ### Why is this bad? - /// Putting effort into constructing a collection but then never querying it might indicate that - /// the author forgot to do whatever they intended to do with the collection. Example: Clone - /// a vector, sort it for iteration, but then mistakenly iterate the original vector - /// instead. - /// - /// ### Example - /// ```no_run - /// # let samples = vec![3, 1, 2]; - /// let mut sorted_samples = samples.clone(); - /// sorted_samples.sort(); - /// for sample in &samples { // Oops, meant to use `sorted_samples`. - /// println!("{sample}"); - /// } - /// ``` - /// Use instead: - /// ```no_run - /// # let samples = vec![3, 1, 2]; - /// let mut sorted_samples = samples.clone(); - /// sorted_samples.sort(); - /// for sample in &sorted_samples { - /// println!("{sample}"); - /// } - /// ``` - #[clippy::version = "1.70.0"] - pub COLLECTION_IS_NEVER_READ, - nursery, - "a collection is never queried" -} -declare_lint_pass!(CollectionIsNeverRead => [COLLECTION_IS_NEVER_READ]); - -// Add `String` here when it is added to diagnostic items -static COLLECTIONS: [Symbol; 9] = [ - sym::BTreeMap, - sym::BTreeSet, - sym::BinaryHeap, - sym::HashMap, - sym::HashSet, - sym::LinkedList, - sym::Option, - sym::Vec, - sym::VecDeque, -]; - -impl<'tcx> LateLintPass<'tcx> for CollectionIsNeverRead { - fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { - // Look for local variables whose type is a container. Search surrounding bock for read access. - if match_acceptable_type(cx, local, &COLLECTIONS) - && let PatKind::Binding(_, local_id, _, _) = local.pat.kind - && let Some(enclosing_block) = get_enclosing_block(cx, local.hir_id) - && has_no_read_access(cx, local_id, enclosing_block) - { - span_lint(cx, COLLECTION_IS_NEVER_READ, local.span, "collection is never read"); - } - } -} - -fn match_acceptable_type(cx: &LateContext<'_>, local: &LetStmt<'_>, collections: &[Symbol]) -> bool { - let ty = cx.typeck_results().pat_ty(local.pat); - collections.iter().any(|&sym| is_type_diagnostic_item(cx, ty, sym)) - // String type is a lang item but not a diagnostic item for now so we need a separate check - || is_type_lang_item(cx, ty, LangItem::String) -} - -fn has_no_read_access<'tcx, T: Visitable<'tcx>>(cx: &LateContext<'tcx>, id: HirId, block: T) -> bool { - let mut has_access = false; - let mut has_read_access = false; - - // Inspect all expressions and sub-expressions in the block. - for_each_expr_with_closures(cx, block, |expr| { - // Ignore expressions that are not simply `id`. - if !path_to_local_id(expr, id) { - return ControlFlow::Continue(()); - } - - // `id` is being accessed. Investigate if it's a read access. - has_access = true; - - // `id` appearing in the left-hand side of an assignment is not a read access: - // - // id = ...; // Not reading `id`. - if let Node::Expr(parent) = cx.tcx.parent_hir_node(expr.hir_id) - && let ExprKind::Assign(lhs, ..) = parent.kind - && path_to_local_id(lhs, id) - { - return ControlFlow::Continue(()); - } - - // Look for method call with receiver `id`. It might be a non-read access: - // - // id.foo(args) - // - // Only assuming this for "official" methods defined on the type. For methods defined in extension - // traits (identified as local, based on the orphan rule), pessimistically assume that they might - // have side effects, so consider them a read. - if let Node::Expr(parent) = cx.tcx.parent_hir_node(expr.hir_id) - && let ExprKind::MethodCall(_, receiver, args, _) = parent.kind - && path_to_local_id(receiver, id) - && let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id) - && !method_def_id.is_local() - { - // If this "official" method takes closures, - // it has read access if one of the closures has read access. - // - // items.retain(|item| send_item(item).is_ok()); - let is_read_in_closure_arg = args.iter().any(|arg| { - if let ExprKind::Closure(closure) = arg.kind - // To keep things simple, we only check the first param to see if its read. - && let Body { params: [param, ..], value } = cx.tcx.hir().body(closure.body) - { - !has_no_read_access(cx, param.hir_id, *value) - } else { - false - } - }); - if is_read_in_closure_arg { - has_read_access = true; - return ControlFlow::Break(()); - } - - // The method call is a statement, so the return value is not used. That's not a read access: - // - // id.foo(args); - if let Node::Stmt(..) = cx.tcx.parent_hir_node(parent.hir_id) { - return ControlFlow::Continue(()); - } - - // The method call is not a statement, so its return value is used somehow but its type is the - // unit type, so this is not a real read access. Examples: - // - // let y = x.clear(); - // println!("{:?}", x.clear()); - if cx.typeck_results().expr_ty(parent).is_unit() { - return ControlFlow::Continue(()); - } - } - - // Any other access to `id` is a read access. Stop searching. - has_read_access = true; - ControlFlow::Break(()) - }); - - // Ignore collections that have no access at all. Other lints should catch them. - has_access && !has_read_access -} diff --git a/clippy_lints/src/comparison_chain.rs b/clippy_lints/src/comparison_chain.rs deleted file mode 100644 index 2c23c0b4f154..000000000000 --- a/clippy_lints/src/comparison_chain.rs +++ /dev/null @@ -1,136 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::ty::implements_trait; -use clippy_utils::{if_sequence, in_constant, is_else_clause, SpanlessEq}; -use rustc_hir::{BinOpKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::declare_lint_pass; -use rustc_span::sym; - -declare_clippy_lint! { - /// ### What it does - /// Checks comparison chains written with `if` that can be - /// rewritten with `match` and `cmp`. - /// - /// ### Why is this bad? - /// `if` is not guaranteed to be exhaustive and conditionals can get - /// repetitive - /// - /// ### Known problems - /// The match statement may be slower due to the compiler - /// not inlining the call to cmp. See issue [#5354](https://github.com/rust-lang/rust-clippy/issues/5354) - /// - /// ### Example - /// ```rust,ignore - /// # fn a() {} - /// # fn b() {} - /// # fn c() {} - /// fn f(x: u8, y: u8) { - /// if x > y { - /// a() - /// } else if x < y { - /// b() - /// } else { - /// c() - /// } - /// } - /// ``` - /// - /// Use instead: - /// ```rust,ignore - /// use std::cmp::Ordering; - /// # fn a() {} - /// # fn b() {} - /// # fn c() {} - /// fn f(x: u8, y: u8) { - /// match x.cmp(&y) { - /// Ordering::Greater => a(), - /// Ordering::Less => b(), - /// Ordering::Equal => c() - /// } - /// } - /// ``` - #[clippy::version = "1.40.0"] - pub COMPARISON_CHAIN, - style, - "`if`s that can be rewritten with `match` and `cmp`" -} - -declare_lint_pass!(ComparisonChain => [COMPARISON_CHAIN]); - -impl<'tcx> LateLintPass<'tcx> for ComparisonChain { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if expr.span.from_expansion() { - return; - } - - // We only care about the top-most `if` in the chain - if is_else_clause(cx.tcx, expr) { - return; - } - - if in_constant(cx, expr.hir_id) { - return; - } - - // Check that there exists at least one explicit else condition - let (conds, _) = if_sequence(expr); - if conds.len() < 2 { - return; - } - - for cond in conds.windows(2) { - if let (&ExprKind::Binary(ref kind1, lhs1, rhs1), &ExprKind::Binary(ref kind2, lhs2, rhs2)) = - (&cond[0].kind, &cond[1].kind) - { - if !kind_is_cmp(kind1.node) || !kind_is_cmp(kind2.node) { - return; - } - - // Check that both sets of operands are equal - let mut spanless_eq = SpanlessEq::new(cx); - let same_fixed_operands = spanless_eq.eq_expr(lhs1, lhs2) && spanless_eq.eq_expr(rhs1, rhs2); - let same_transposed_operands = spanless_eq.eq_expr(lhs1, rhs2) && spanless_eq.eq_expr(rhs1, lhs2); - - if !same_fixed_operands && !same_transposed_operands { - return; - } - - // Check that if the operation is the same, either it's not `==` or the operands are transposed - if kind1.node == kind2.node { - if kind1.node == BinOpKind::Eq { - return; - } - if !same_transposed_operands { - return; - } - } - - // Check that the type being compared implements `core::cmp::Ord` - let ty = cx.typeck_results().expr_ty(lhs1); - let is_ord = cx - .tcx - .get_diagnostic_item(sym::Ord) - .map_or(false, |id| implements_trait(cx, ty, id, &[])); - - if !is_ord { - return; - } - } else { - // We only care about comparison chains - return; - } - } - span_lint_and_help( - cx, - COMPARISON_CHAIN, - expr.span, - "`if` chain can be rewritten with `match`", - None, - "consider rewriting the `if` chain to use `cmp` and `match`", - ); - } -} - -fn kind_is_cmp(kind: BinOpKind) -> bool { - matches!(kind, BinOpKind::Lt | BinOpKind::Gt | BinOpKind::Eq) -} diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs deleted file mode 100644 index ccf1d9d6f8c0..000000000000 --- a/clippy_lints/src/copies.rs +++ /dev/null @@ -1,637 +0,0 @@ -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::ty::{needs_ordered_drop, InteriorMut}; -use clippy_utils::visitors::for_each_expr; -use clippy_utils::{ - capture_local_usage, eq_expr_value, find_binding_init, get_enclosing_block, hash_expr, hash_stmt, if_sequence, - is_else_clause, is_lint_allowed, path_to_local, search_same, ContainsName, HirEqInterExpr, SpanlessEq, -}; -use core::iter; -use core::ops::ControlFlow; -use rustc_errors::Applicability; -use rustc_hir::{intravisit, BinOpKind, Block, Expr, ExprKind, HirId, HirIdSet, Stmt, StmtKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::impl_lint_pass; -use rustc_span::hygiene::walk_chain; -use rustc_span::source_map::SourceMap; -use rustc_span::{BytePos, Span, Symbol}; -use std::borrow::Cow; - -declare_clippy_lint! { - /// ### What it does - /// Checks for consecutive `if`s with the same condition. - /// - /// ### Why is this bad? - /// This is probably a copy & paste error. - /// - /// ### Example - /// ```ignore - /// if a == b { - /// … - /// } else if a == b { - /// … - /// } - /// ``` - /// - /// Note that this lint ignores all conditions with a function call as it could - /// have side effects: - /// - /// ```ignore - /// if foo() { - /// … - /// } else if foo() { // not linted - /// … - /// } - /// ``` - #[clippy::version = "pre 1.29.0"] - pub IFS_SAME_COND, - correctness, - "consecutive `if`s with the same condition" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for consecutive `if`s with the same function call. - /// - /// ### Why is this bad? - /// This is probably a copy & paste error. - /// Despite the fact that function can have side effects and `if` works as - /// intended, such an approach is implicit and can be considered a "code smell". - /// - /// ### Example - /// ```ignore - /// if foo() == bar { - /// … - /// } else if foo() == bar { - /// … - /// } - /// ``` - /// - /// This probably should be: - /// ```ignore - /// if foo() == bar { - /// … - /// } else if foo() == baz { - /// … - /// } - /// ``` - /// - /// or if the original code was not a typo and called function mutates a state, - /// consider move the mutation out of the `if` condition to avoid similarity to - /// a copy & paste error: - /// - /// ```ignore - /// let first = foo(); - /// if first == bar { - /// … - /// } else { - /// let second = foo(); - /// if second == bar { - /// … - /// } - /// } - /// ``` - #[clippy::version = "1.41.0"] - pub SAME_FUNCTIONS_IN_IF_CONDITION, - pedantic, - "consecutive `if`s with the same function call" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for `if/else` with the same body as the *then* part - /// and the *else* part. - /// - /// ### Why is this bad? - /// This is probably a copy & paste error. - /// - /// ### Example - /// ```ignore - /// let foo = if … { - /// 42 - /// } else { - /// 42 - /// }; - /// ``` - #[clippy::version = "pre 1.29.0"] - pub IF_SAME_THEN_ELSE, - style, - "`if` with the same `then` and `else` blocks" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks if the `if` and `else` block contain shared code that can be - /// moved out of the blocks. - /// - /// ### Why is this bad? - /// Duplicate code is less maintainable. - /// - /// ### Known problems - /// * The lint doesn't check if the moved expressions modify values that are being 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 - /// let foo = if … { - /// println!("Hello World"); - /// 13 - /// } else { - /// println!("Hello World"); - /// 42 - /// }; - /// ``` - /// - /// Use instead: - /// ```ignore - /// println!("Hello World"); - /// let foo = if … { - /// 13 - /// } else { - /// 42 - /// }; - /// ``` - #[clippy::version = "1.53.0"] - pub BRANCHES_SHARING_CODE, - nursery, - "`if` statement with shared code in all blocks" -} - -pub struct CopyAndPaste<'tcx> { - ignore_interior_mutability: Vec, - interior_mut: InteriorMut<'tcx>, -} - -impl CopyAndPaste<'_> { - pub fn new(ignore_interior_mutability: Vec) -> Self { - Self { - ignore_interior_mutability, - interior_mut: InteriorMut::default(), - } - } -} - -impl_lint_pass!(CopyAndPaste<'_> => [ - IFS_SAME_COND, - SAME_FUNCTIONS_IN_IF_CONDITION, - IF_SAME_THEN_ELSE, - BRANCHES_SHARING_CODE -]); - -impl<'tcx> LateLintPass<'tcx> for CopyAndPaste<'tcx> { - fn check_crate(&mut self, cx: &LateContext<'tcx>) { - self.interior_mut = InteriorMut::new(cx, &self.ignore_interior_mutability); - } - - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if !expr.span.from_expansion() && matches!(expr.kind, ExprKind::If(..)) && !is_else_clause(cx.tcx, expr) { - let (conds, blocks) = if_sequence(expr); - lint_same_cond(cx, &conds, &mut self.interior_mut); - lint_same_fns_in_if_cond(cx, &conds); - let all_same = - !is_lint_allowed(cx, IF_SAME_THEN_ELSE, expr.hir_id) && lint_if_same_then_else(cx, &conds, &blocks); - if !all_same && conds.len() != blocks.len() { - lint_branches_sharing_code(cx, &conds, &blocks, expr); - } - } - } -} - -/// Checks if the given expression is a let chain. -fn contains_let(e: &Expr<'_>) -> bool { - match e.kind { - ExprKind::Let(..) => true, - ExprKind::Binary(op, lhs, rhs) if op.node == BinOpKind::And => { - matches!(lhs.kind, ExprKind::Let(..)) || contains_let(rhs) - }, - _ => false, - } -} - -fn lint_if_same_then_else(cx: &LateContext<'_>, conds: &[&Expr<'_>], blocks: &[&Block<'_>]) -> bool { - let mut eq = SpanlessEq::new(cx); - blocks - .array_windows::<2>() - .enumerate() - .fold(true, |all_eq, (i, &[lhs, rhs])| { - if eq.eq_block(lhs, rhs) && !contains_let(conds[i]) && conds.get(i + 1).map_or(true, |e| !contains_let(e)) { - span_lint_and_note( - cx, - IF_SAME_THEN_ELSE, - lhs.span, - "this `if` has identical blocks", - Some(rhs.span), - "same as this", - ); - all_eq - } else { - false - } - }) -} - -fn lint_branches_sharing_code<'tcx>( - cx: &LateContext<'tcx>, - conds: &[&'tcx Expr<'_>], - blocks: &[&'tcx Block<'_>], - expr: &'tcx Expr<'_>, -) { - // We only lint ifs with multiple blocks - let &[first_block, ref blocks @ ..] = blocks else { - return; - }; - let &[.., last_block] = blocks else { - return; - }; - - let res = scan_block_for_eq(cx, conds, first_block, blocks); - let sm = cx.tcx.sess.source_map(); - let start_suggestion = res.start_span(first_block, sm).map(|span| { - let first_line_span = first_line_of_span(cx, expr.span); - let replace_span = first_line_span.with_hi(span.hi()); - let cond_span = first_line_span.until(first_block.span); - let cond_snippet = reindent_multiline(snippet(cx, cond_span, "_"), false, None); - let cond_indent = indent_of(cx, cond_span); - let moved_snippet = reindent_multiline(snippet(cx, span, "_"), true, None); - let suggestion = moved_snippet.to_string() + "\n" + &cond_snippet + "{"; - let suggestion = reindent_multiline(Cow::Borrowed(&suggestion), true, cond_indent); - (replace_span, suggestion.to_string()) - }); - let end_suggestion = res.end_span(last_block, sm).map(|span| { - let moved_snipped = reindent_multiline(snippet(cx, span, "_"), true, None); - let indent = indent_of(cx, expr.span.shrink_to_hi()); - let suggestion = "}\n".to_string() + &moved_snipped; - let suggestion = reindent_multiline(Cow::Borrowed(&suggestion), true, indent); - - let span = span.with_hi(last_block.span.hi()); - // Improve formatting if the inner block has indention (i.e. normal Rust formatting) - let test_span = Span::new(span.lo() - BytePos(4), span.lo(), span.ctxt(), span.parent()); - let span = if snippet_opt(cx, test_span).map_or(false, |snip| snip == " ") { - span.with_lo(test_span.lo()) - } else { - span - }; - (span, suggestion.to_string()) - }); - - let (span, msg, end_span) = match (&start_suggestion, &end_suggestion) { - (&Some((span, _)), &Some((end_span, _))) => ( - span, - "all if blocks contain the same code at both the start and the end", - Some(end_span), - ), - (&Some((span, _)), None) => (span, "all if blocks contain the same code at the start", None), - (None, &Some((span, _))) => (span, "all if blocks contain the same code at the end", None), - (None, None) => return, - }; - span_lint_and_then(cx, BRANCHES_SHARING_CODE, span, msg, |diag| { - if let Some(span) = end_span { - diag.span_note(span, "this code is shared at the end"); - } - if let Some((span, sugg)) = start_suggestion { - diag.span_suggestion( - span, - "consider moving these statements before the if", - sugg, - Applicability::Unspecified, - ); - } - if let Some((span, sugg)) = end_suggestion { - diag.span_suggestion( - span, - "consider moving these statements after the if", - sugg, - Applicability::Unspecified, - ); - if !cx.typeck_results().expr_ty(expr).is_unit() { - diag.note("the end suggestion probably needs some adjustments to use the expression result correctly"); - } - } - if check_for_warn_of_moved_symbol(cx, &res.moved_locals, expr) { - diag.warn("some moved values might need to be renamed to avoid wrong references"); - } - }); -} - -struct BlockEq { - /// The end of the range of equal stmts at the start. - start_end_eq: usize, - /// The start of the range of equal stmts at the end. - end_begin_eq: Option, - /// The name and id of every local which can be moved at the beginning and the end. - moved_locals: Vec<(HirId, Symbol)>, -} -impl BlockEq { - fn start_span(&self, b: &Block<'_>, sm: &SourceMap) -> Option { - match &b.stmts[..self.start_end_eq] { - [first, .., last] => Some(sm.stmt_span(first.span, b.span).to(sm.stmt_span(last.span, b.span))), - [s] => Some(sm.stmt_span(s.span, b.span)), - [] => None, - } - } - - fn end_span(&self, b: &Block<'_>, sm: &SourceMap) -> Option { - match (&b.stmts[b.stmts.len() - self.end_begin_eq?..], b.expr) { - ([first, .., last], None) => Some(sm.stmt_span(first.span, b.span).to(sm.stmt_span(last.span, b.span))), - ([first, ..], Some(last)) => Some(sm.stmt_span(first.span, b.span).to(sm.stmt_span(last.span, b.span))), - ([s], None) => Some(sm.stmt_span(s.span, b.span)), - ([], Some(e)) => Some(walk_chain(e.span, b.span.ctxt())), - ([], None) => None, - } - } -} - -/// If the statement is a local, checks if the bound names match the expected list of names. -fn eq_binding_names(s: &Stmt<'_>, names: &[(HirId, Symbol)]) -> bool { - if let StmtKind::Let(l) = s.kind { - let mut i = 0usize; - let mut res = true; - l.pat.each_binding_or_first(&mut |_, _, _, name| { - if names.get(i).map_or(false, |&(_, n)| n == name.name) { - i += 1; - } else { - res = false; - } - }); - res && i == names.len() - } else { - false - } -} - -/// Checks if the statement modifies or moves any of the given locals. -fn modifies_any_local<'tcx>(cx: &LateContext<'tcx>, s: &'tcx Stmt<'_>, locals: &HirIdSet) -> bool { - for_each_expr(s, |e| { - if let Some(id) = path_to_local(e) - && locals.contains(&id) - && !capture_local_usage(cx, e).is_imm_ref() - { - ControlFlow::Break(()) - } else { - ControlFlow::Continue(()) - } - }) - .is_some() -} - -/// Checks if the given statement should be considered equal to the statement in the same position -/// for each block. -fn eq_stmts( - stmt: &Stmt<'_>, - blocks: &[&Block<'_>], - get_stmt: impl for<'a> Fn(&'a Block<'a>) -> Option<&'a Stmt<'a>>, - eq: &mut HirEqInterExpr<'_, '_, '_>, - moved_bindings: &mut Vec<(HirId, Symbol)>, -) -> bool { - (if let StmtKind::Let(l) = stmt.kind { - let old_count = moved_bindings.len(); - l.pat.each_binding_or_first(&mut |_, id, _, name| { - moved_bindings.push((id, name.name)); - }); - let new_bindings = &moved_bindings[old_count..]; - blocks - .iter() - .all(|b| get_stmt(b).map_or(false, |s| eq_binding_names(s, new_bindings))) - } else { - true - }) && blocks - .iter() - .all(|b| get_stmt(b).map_or(false, |s| eq.eq_stmt(s, stmt))) -} - -#[expect(clippy::too_many_lines)] -fn scan_block_for_eq<'tcx>( - cx: &LateContext<'tcx>, - conds: &[&'tcx Expr<'_>], - block: &'tcx Block<'_>, - blocks: &[&'tcx Block<'_>], -) -> BlockEq { - let mut eq = SpanlessEq::new(cx); - let mut eq = eq.inter_expr(); - let mut moved_locals = Vec::new(); - - let mut cond_locals = HirIdSet::default(); - for &cond in conds { - let _: Option = for_each_expr(cond, |e| { - if let Some(id) = path_to_local(e) { - cond_locals.insert(id); - } - ControlFlow::Continue(()) - }); - } - - let mut local_needs_ordered_drop = false; - let start_end_eq = block - .stmts - .iter() - .enumerate() - .find(|&(i, stmt)| { - if let StmtKind::Let(l) = stmt.kind - && needs_ordered_drop(cx, cx.typeck_results().node_type(l.hir_id)) - { - local_needs_ordered_drop = true; - return true; - } - modifies_any_local(cx, stmt, &cond_locals) - || !eq_stmts(stmt, blocks, |b| b.stmts.get(i), &mut eq, &mut moved_locals) - }) - .map_or(block.stmts.len(), |(i, _)| i); - - if local_needs_ordered_drop { - return BlockEq { - start_end_eq, - end_begin_eq: None, - moved_locals, - }; - } - - // Walk backwards through the final expression/statements so long as their hashes are equal. Note - // `SpanlessHash` treats all local references as equal allowing locals declared earlier in the block - // to match those in other blocks. e.g. If each block ends with the following the hash value will be - // the same even though each `x` binding will have a different `HirId`: - // let x = foo(); - // x + 50 - let expr_hash_eq = if let Some(e) = block.expr { - let hash = hash_expr(cx, e); - blocks - .iter() - .all(|b| b.expr.map_or(false, |e| hash_expr(cx, e) == hash)) - } else { - blocks.iter().all(|b| b.expr.is_none()) - }; - if !expr_hash_eq { - return BlockEq { - start_end_eq, - end_begin_eq: None, - moved_locals, - }; - } - let end_search_start = block.stmts[start_end_eq..] - .iter() - .rev() - .enumerate() - .find(|&(offset, stmt)| { - let hash = hash_stmt(cx, stmt); - blocks.iter().any(|b| { - b.stmts - // the bounds check will catch the underflow - .get(b.stmts.len().wrapping_sub(offset + 1)) - .map_or(true, |s| hash != hash_stmt(cx, s)) - }) - }) - .map_or(block.stmts.len() - start_end_eq, |(i, _)| i); - - let moved_locals_at_start = moved_locals.len(); - let mut i = end_search_start; - let end_begin_eq = block.stmts[block.stmts.len() - end_search_start..] - .iter() - .zip(iter::repeat_with(move || { - let x = i; - i -= 1; - x - })) - .fold(end_search_start, |init, (stmt, offset)| { - if eq_stmts( - stmt, - blocks, - |b| b.stmts.get(b.stmts.len() - offset), - &mut eq, - &mut moved_locals, - ) { - init - } else { - // Clear out all locals seen at the end so far. None of them can be moved. - let stmts = &blocks[0].stmts; - for stmt in &stmts[stmts.len() - init..=stmts.len() - offset] { - if let StmtKind::Let(l) = stmt.kind { - l.pat.each_binding_or_first(&mut |_, id, _, _| { - // FIXME(rust/#120456) - is `swap_remove` correct? - eq.locals.swap_remove(&id); - }); - } - } - moved_locals.truncate(moved_locals_at_start); - offset - 1 - } - }); - if let Some(e) = block.expr { - for block in blocks { - if block.expr.map_or(false, |expr| !eq.eq_expr(expr, e)) { - moved_locals.truncate(moved_locals_at_start); - return BlockEq { - start_end_eq, - end_begin_eq: None, - moved_locals, - }; - } - } - } - - BlockEq { - start_end_eq, - end_begin_eq: Some(end_begin_eq), - moved_locals, - } -} - -fn check_for_warn_of_moved_symbol(cx: &LateContext<'_>, symbols: &[(HirId, Symbol)], if_expr: &Expr<'_>) -> bool { - get_enclosing_block(cx, if_expr.hir_id).map_or(false, |block| { - let ignore_span = block.span.shrink_to_lo().to(if_expr.span); - - symbols - .iter() - .filter(|&&(_, name)| !name.as_str().starts_with('_')) - .any(|&(_, name)| { - let mut walker = ContainsName { - name, - result: false, - cx, - }; - - // Scan block - block - .stmts - .iter() - .filter(|stmt| !ignore_span.overlaps(stmt.span)) - .for_each(|stmt| intravisit::walk_stmt(&mut walker, stmt)); - - if let Some(expr) = block.expr { - intravisit::walk_expr(&mut walker, expr); - } - - walker.result - }) - }) -} - -fn method_caller_is_mutable<'tcx>( - cx: &LateContext<'tcx>, - caller_expr: &Expr<'_>, - interior_mut: &mut InteriorMut<'tcx>, -) -> bool { - let caller_ty = cx.typeck_results().expr_ty(caller_expr); - - interior_mut.is_interior_mut_ty(cx, caller_ty) - || caller_ty.is_mutable_ptr() - // `find_binding_init` will return the binding iff its not mutable - || path_to_local(caller_expr) - .and_then(|hid| find_binding_init(cx, hid)) - .is_none() -} - -/// Implementation of `IFS_SAME_COND`. -fn lint_same_cond<'tcx>(cx: &LateContext<'tcx>, conds: &[&Expr<'_>], interior_mut: &mut InteriorMut<'tcx>) { - for (i, j) in search_same( - conds, - |e| hash_expr(cx, e), - |lhs, rhs| { - // Ignore eq_expr side effects iff one of the expression kind is a method call - // and the caller is not a mutable, including inner mutable type. - if let ExprKind::MethodCall(_, caller, _, _) = lhs.kind { - if method_caller_is_mutable(cx, caller, interior_mut) { - false - } else { - SpanlessEq::new(cx).eq_expr(lhs, rhs) - } - } else { - eq_expr_value(cx, lhs, rhs) - } - }, - ) { - span_lint_and_note( - cx, - IFS_SAME_COND, - j.span, - "this `if` has the same condition as a previous `if`", - Some(i.span), - "same as this", - ); - } -} - -/// Implementation of `SAME_FUNCTIONS_IN_IF_CONDITION`. -fn lint_same_fns_in_if_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>]) { - let eq: &dyn Fn(&&Expr<'_>, &&Expr<'_>) -> bool = &|&lhs, &rhs| -> bool { - // Do not lint if any expr originates from a macro - if lhs.span.from_expansion() || rhs.span.from_expansion() { - return false; - } - // Do not spawn warning if `IFS_SAME_COND` already produced it. - if eq_expr_value(cx, lhs, rhs) { - return false; - } - SpanlessEq::new(cx).eq_expr(lhs, rhs) - }; - - for (i, j) in search_same(conds, |e| hash_expr(cx, e), eq) { - span_lint_and_note( - cx, - SAME_FUNCTIONS_IN_IF_CONDITION, - j.span, - "this `if` has the same function call as a previous `if`", - Some(i.span), - "same as this", - ); - } -} diff --git a/clippy_lints/src/copy_iterator.rs b/clippy_lints/src/copy_iterator.rs deleted file mode 100644 index 50fd76a3a477..000000000000 --- a/clippy_lints/src/copy_iterator.rs +++ /dev/null @@ -1,58 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_note; -use clippy_utils::ty::is_copy; -use rustc_hir::{Impl, Item, ItemKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::declare_lint_pass; -use rustc_span::sym; - -declare_clippy_lint! { - /// ### What it does - /// Checks for types that implement `Copy` as well as - /// `Iterator`. - /// - /// ### Why is this bad? - /// Implicit copies can be confusing when working with - /// iterator combinators. - /// - /// ### Example - /// ```rust,ignore - /// #[derive(Copy, Clone)] - /// struct Countdown(u8); - /// - /// impl Iterator for Countdown { - /// // ... - /// } - /// - /// let a: Vec<_> = my_iterator.take(1).collect(); - /// let b: Vec<_> = my_iterator.collect(); - /// ``` - #[clippy::version = "1.30.0"] - pub COPY_ITERATOR, - pedantic, - "implementing `Iterator` on a `Copy` type" -} - -declare_lint_pass!(CopyIterator => [COPY_ITERATOR]); - -impl<'tcx> LateLintPass<'tcx> for CopyIterator { - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Impl(Impl { - of_trait: Some(ref trait_ref), - .. - }) = item.kind - && let ty = cx.tcx.type_of(item.owner_id).instantiate_identity() - && is_copy(cx, ty) - && let Some(trait_id) = trait_ref.trait_def_id() - && cx.tcx.is_diagnostic_item(sym::Iterator, trait_id) - { - span_lint_and_note( - cx, - COPY_ITERATOR, - item.span, - "you are implementing `Iterator` on a `Copy` type", - None, - "consider implementing `IntoIterator` instead", - ); - } - } -} diff --git a/clippy_lints/src/crate_in_macro_def.rs b/clippy_lints/src/crate_in_macro_def.rs deleted file mode 100644 index adf6f7c47375..000000000000 --- a/clippy_lints/src/crate_in_macro_def.rs +++ /dev/null @@ -1,128 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use rustc_ast::ast::{AttrKind, Attribute, Item, ItemKind}; -use rustc_ast::token::{Token, TokenKind}; -use rustc_ast::tokenstream::{TokenStream, TokenTree}; -use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::declare_lint_pass; -use rustc_span::symbol::sym; -use rustc_span::Span; - -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of `crate` as opposed to `$crate` in a macro definition. - /// - /// ### Why is this bad? - /// `crate` refers to the macro call's crate, whereas `$crate` refers to the macro definition's - /// crate. Rarely is the former intended. See: - /// https://doc.rust-lang.org/reference/macros-by-example.html#hygiene - /// - /// ### Example - /// ```no_run - /// #[macro_export] - /// macro_rules! print_message { - /// () => { - /// println!("{}", crate::MESSAGE); - /// }; - /// } - /// pub const MESSAGE: &str = "Hello!"; - /// ``` - /// Use instead: - /// ```no_run - /// #[macro_export] - /// macro_rules! print_message { - /// () => { - /// println!("{}", $crate::MESSAGE); - /// }; - /// } - /// pub const MESSAGE: &str = "Hello!"; - /// ``` - /// - /// Note that if the use of `crate` is intentional, an `allow` attribute can be applied to the - /// macro definition, e.g.: - /// ```rust,ignore - /// #[allow(clippy::crate_in_macro_def)] - /// macro_rules! ok { ... crate::foo ... } - /// ``` - #[clippy::version = "1.62.0"] - pub CRATE_IN_MACRO_DEF, - suspicious, - "using `crate` in a macro definition" -} -declare_lint_pass!(CrateInMacroDef => [CRATE_IN_MACRO_DEF]); - -impl EarlyLintPass for CrateInMacroDef { - fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { - if item.attrs.iter().any(is_macro_export) - && let ItemKind::MacroDef(macro_def) = &item.kind - && let tts = macro_def.body.tokens.clone() - && let Some(span) = contains_unhygienic_crate_reference(&tts) - { - span_lint_and_sugg( - cx, - CRATE_IN_MACRO_DEF, - span, - "`crate` references the macro call's crate", - "to reference the macro definition's crate, use", - String::from("$crate"), - Applicability::MachineApplicable, - ); - } - } -} - -fn is_macro_export(attr: &Attribute) -> bool { - if let AttrKind::Normal(normal) = &attr.kind - && let [segment] = normal.item.path.segments.as_slice() - { - segment.ident.name == sym::macro_export - } else { - false - } -} - -fn contains_unhygienic_crate_reference(tts: &TokenStream) -> Option { - let mut prev_is_dollar = false; - let mut cursor = tts.trees(); - while let Some(curr) = cursor.next() { - if !prev_is_dollar - && let Some(span) = is_crate_keyword(curr) - && let Some(next) = cursor.look_ahead(0) - && is_token(next, &TokenKind::PathSep) - { - return Some(span); - } - if let TokenTree::Delimited(.., tts) = &curr { - let span = contains_unhygienic_crate_reference(tts); - if span.is_some() { - return span; - } - } - prev_is_dollar = is_token(curr, &TokenKind::Dollar); - } - None -} - -fn is_crate_keyword(tt: &TokenTree) -> Option { - if let TokenTree::Token( - Token { - kind: TokenKind::Ident(symbol, _), - span, - }, - _, - ) = tt - && symbol.as_str() == "crate" - { - Some(*span) - } else { - None - } -} - -fn is_token(tt: &TokenTree, kind: &TokenKind) -> bool { - if let TokenTree::Token(Token { kind: other, .. }, _) = tt { - kind == other - } else { - false - } -} diff --git a/clippy_lints/src/create_dir.rs b/clippy_lints/src/create_dir.rs deleted file mode 100644 index 7a3d5a070912..000000000000 --- a/clippy_lints/src/create_dir.rs +++ /dev/null @@ -1,51 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::snippet; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::declare_lint_pass; -use rustc_span::sym; - -declare_clippy_lint! { - /// ### What it does - /// Checks usage of `std::fs::create_dir` and suggest using `std::fs::create_dir_all` instead. - /// - /// ### Why is this bad? - /// Sometimes `std::fs::create_dir` is mistakenly chosen over `std::fs::create_dir_all`. - /// - /// ### Example - /// ```rust,ignore - /// std::fs::create_dir("foo"); - /// ``` - /// - /// Use instead: - /// ```rust,ignore - /// std::fs::create_dir_all("foo"); - /// ``` - #[clippy::version = "1.48.0"] - pub CREATE_DIR, - restriction, - "calling `std::fs::create_dir` instead of `std::fs::create_dir_all`" -} - -declare_lint_pass!(CreateDir => [CREATE_DIR]); - -impl LateLintPass<'_> for CreateDir { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - if let ExprKind::Call(func, [arg, ..]) = expr.kind - && let ExprKind::Path(ref path) = func.kind - && let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id() - && cx.tcx.is_diagnostic_item(sym::fs_create_dir, def_id) - { - span_lint_and_sugg( - cx, - CREATE_DIR, - expr.span, - "calling `std::fs::create_dir` where there may be a better way", - "consider calling `std::fs::create_dir_all` instead", - format!("create_dir_all({})", snippet(cx, arg.span, "..")), - Applicability::MaybeIncorrect, - ); - } - } -} diff --git a/clippy_lints/src/dbg_macro.rs b/clippy_lints/src/dbg_macro.rs deleted file mode 100644 index db5937266047..000000000000 --- a/clippy_lints/src/dbg_macro.rs +++ /dev/null @@ -1,134 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::is_in_test; -use clippy_utils::macros::{macro_backtrace, MacroCall}; -use clippy_utils::source::snippet_with_applicability; -use rustc_data_structures::fx::FxHashSet; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, Node}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_session::impl_lint_pass; -use rustc_span::{sym, Span, SyntaxContext}; - -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of the [`dbg!`](https://doc.rust-lang.org/std/macro.dbg.html) macro. - /// - /// ### Why is this bad? - /// The `dbg!` macro is intended as a debugging tool. It should not be present in released - /// software or committed to a version control system. - /// - /// ### Example - /// ```rust,ignore - /// dbg!(true) - /// ``` - /// - /// Use instead: - /// ```rust,ignore - /// true - /// ``` - #[clippy::version = "1.34.0"] - pub DBG_MACRO, - restriction, - "`dbg!` macro is intended as a debugging tool" -} - -#[derive(Clone)] -pub struct DbgMacro { - allow_dbg_in_tests: bool, - /// Tracks the `dbg!` macro callsites that are already checked. - checked_dbg_call_site: FxHashSet, - /// Tracks the previous `SyntaxContext`, to avoid walking the same context chain. - prev_ctxt: SyntaxContext, -} - -impl_lint_pass!(DbgMacro => [DBG_MACRO]); - -impl DbgMacro { - pub fn new(allow_dbg_in_tests: bool) -> Self { - DbgMacro { - allow_dbg_in_tests, - checked_dbg_call_site: FxHashSet::default(), - prev_ctxt: SyntaxContext::root(), - } - } -} - -impl LateLintPass<'_> for DbgMacro { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - let cur_syntax_ctxt = expr.span.ctxt(); - - if cur_syntax_ctxt != self.prev_ctxt && - let Some(macro_call) = first_dbg_macro_in_expansion(cx, expr.span) && - !in_external_macro(cx.sess(), macro_call.span) && - self.checked_dbg_call_site.insert(macro_call.span) && - // allows `dbg!` in test code if allow-dbg-in-test is set to true in clippy.toml - !(self.allow_dbg_in_tests && is_in_test(cx.tcx, expr.hir_id)) - { - let mut applicability = Applicability::MachineApplicable; - - let (sugg_span, suggestion) = match expr.peel_drop_temps().kind { - // dbg!() - ExprKind::Block(..) => { - // If the `dbg!` macro is a "free" statement and not contained within other expressions, - // remove the whole statement. - if let Node::Stmt(_) = cx.tcx.parent_hir_node(expr.hir_id) - && let Some(semi_span) = cx.sess().source_map().mac_call_stmt_semi_span(macro_call.span) - { - (macro_call.span.to(semi_span), String::new()) - } else { - (macro_call.span, String::from("()")) - } - }, - // dbg!(1) - ExprKind::Match(val, ..) => ( - macro_call.span, - snippet_with_applicability(cx, val.span.source_callsite(), "..", &mut applicability).to_string(), - ), - // dbg!(2, 3) - ExprKind::Tup( - [ - Expr { - kind: ExprKind::Match(first, ..), - .. - }, - .., - Expr { - kind: ExprKind::Match(last, ..), - .. - }, - ], - ) => { - let snippet = snippet_with_applicability( - cx, - first.span.source_callsite().to(last.span.source_callsite()), - "..", - &mut applicability, - ); - (macro_call.span, format!("({snippet})")) - }, - _ => return, - }; - - self.prev_ctxt = cur_syntax_ctxt; - - span_lint_and_sugg( - cx, - DBG_MACRO, - sugg_span, - "the `dbg!` macro is intended as a debugging tool", - "remove the invocation before committing it to a version control system", - suggestion, - applicability, - ); - } - } - - fn check_crate_post(&mut self, _: &LateContext<'_>) { - self.checked_dbg_call_site = FxHashSet::default(); - } -} - -fn first_dbg_macro_in_expansion(cx: &LateContext<'_>, span: Span) -> Option { - macro_backtrace(span).find(|mc| cx.tcx.is_diagnostic_item(sym::dbg_macro, mc.def_id)) -} diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs deleted file mode 100644 index 6850ec821e84..000000000000 --- a/clippy_lints/src/declared_lints.rs +++ /dev/null @@ -1,764 +0,0 @@ -// This file was generated by `cargo dev update_lints`. -// Use that command to update this file and do not edit by hand. -// Manual edits will be overwritten. - -pub(crate) static LINTS: &[&crate::LintInfo] = &[ - #[cfg(feature = "internal")] - crate::utils::internal_lints::almost_standard_lint_formulation::ALMOST_STANDARD_LINT_FORMULATION_INFO, - #[cfg(feature = "internal")] - crate::utils::internal_lints::collapsible_calls::COLLAPSIBLE_SPAN_LINT_CALLS_INFO, - #[cfg(feature = "internal")] - crate::utils::internal_lints::compiler_lint_functions::COMPILER_LINT_FUNCTIONS_INFO, - #[cfg(feature = "internal")] - crate::utils::internal_lints::interning_defined_symbol::INTERNING_DEFINED_SYMBOL_INFO, - #[cfg(feature = "internal")] - crate::utils::internal_lints::interning_defined_symbol::UNNECESSARY_SYMBOL_STR_INFO, - #[cfg(feature = "internal")] - crate::utils::internal_lints::invalid_paths::INVALID_PATHS_INFO, - #[cfg(feature = "internal")] - crate::utils::internal_lints::lint_without_lint_pass::DEFAULT_DEPRECATION_REASON_INFO, - #[cfg(feature = "internal")] - crate::utils::internal_lints::lint_without_lint_pass::DEFAULT_LINT_INFO, - #[cfg(feature = "internal")] - crate::utils::internal_lints::lint_without_lint_pass::INVALID_CLIPPY_VERSION_ATTRIBUTE_INFO, - #[cfg(feature = "internal")] - crate::utils::internal_lints::lint_without_lint_pass::LINT_WITHOUT_LINT_PASS_INFO, - #[cfg(feature = "internal")] - crate::utils::internal_lints::lint_without_lint_pass::MISSING_CLIPPY_VERSION_ATTRIBUTE_INFO, - #[cfg(feature = "internal")] - crate::utils::internal_lints::metadata_collector::METADATA_COLLECTOR_INFO, - #[cfg(feature = "internal")] - crate::utils::internal_lints::msrv_attr_impl::MISSING_MSRV_ATTR_IMPL_INFO, - #[cfg(feature = "internal")] - crate::utils::internal_lints::outer_expn_data_pass::OUTER_EXPN_EXPN_DATA_INFO, - #[cfg(feature = "internal")] - crate::utils::internal_lints::produce_ice::PRODUCE_ICE_INFO, - #[cfg(feature = "internal")] - crate::utils::internal_lints::unnecessary_def_path::UNNECESSARY_DEF_PATH_INFO, - #[cfg(feature = "internal")] - crate::utils::internal_lints::unsorted_clippy_utils_paths::UNSORTED_CLIPPY_UTILS_PATHS_INFO, - crate::absolute_paths::ABSOLUTE_PATHS_INFO, - crate::allow_attributes::ALLOW_ATTRIBUTES_INFO, - crate::almost_complete_range::ALMOST_COMPLETE_RANGE_INFO, - crate::approx_const::APPROX_CONSTANT_INFO, - crate::arc_with_non_send_sync::ARC_WITH_NON_SEND_SYNC_INFO, - crate::as_conversions::AS_CONVERSIONS_INFO, - crate::asm_syntax::INLINE_ASM_X86_ATT_SYNTAX_INFO, - crate::asm_syntax::INLINE_ASM_X86_INTEL_SYNTAX_INFO, - crate::assertions_on_constants::ASSERTIONS_ON_CONSTANTS_INFO, - crate::assertions_on_result_states::ASSERTIONS_ON_RESULT_STATES_INFO, - crate::assigning_clones::ASSIGNING_CLONES_INFO, - crate::async_yields_async::ASYNC_YIELDS_ASYNC_INFO, - crate::attrs::ALLOW_ATTRIBUTES_WITHOUT_REASON_INFO, - crate::attrs::BLANKET_CLIPPY_RESTRICTION_LINTS_INFO, - crate::attrs::DEPRECATED_CFG_ATTR_INFO, - crate::attrs::DEPRECATED_CLIPPY_CFG_ATTR_INFO, - crate::attrs::DEPRECATED_SEMVER_INFO, - crate::attrs::DUPLICATED_ATTRIBUTES_INFO, - crate::attrs::EMPTY_LINE_AFTER_DOC_COMMENTS_INFO, - crate::attrs::EMPTY_LINE_AFTER_OUTER_ATTR_INFO, - crate::attrs::INLINE_ALWAYS_INFO, - crate::attrs::MAYBE_MISUSED_CFG_INFO, - crate::attrs::MISMATCHED_TARGET_OS_INFO, - crate::attrs::MIXED_ATTRIBUTES_STYLE_INFO, - crate::attrs::NON_MINIMAL_CFG_INFO, - crate::attrs::SHOULD_PANIC_WITHOUT_EXPECT_INFO, - crate::attrs::UNNECESSARY_CLIPPY_CFG_INFO, - crate::attrs::USELESS_ATTRIBUTE_INFO, - crate::await_holding_invalid::AWAIT_HOLDING_INVALID_TYPE_INFO, - crate::await_holding_invalid::AWAIT_HOLDING_LOCK_INFO, - crate::await_holding_invalid::AWAIT_HOLDING_REFCELL_REF_INFO, - crate::blocks_in_conditions::BLOCKS_IN_CONDITIONS_INFO, - crate::bool_assert_comparison::BOOL_ASSERT_COMPARISON_INFO, - crate::bool_to_int_with_if::BOOL_TO_INT_WITH_IF_INFO, - crate::booleans::NONMINIMAL_BOOL_INFO, - crate::booleans::OVERLY_COMPLEX_BOOL_EXPR_INFO, - crate::borrow_deref_ref::BORROW_DEREF_REF_INFO, - crate::box_default::BOX_DEFAULT_INFO, - crate::cargo::CARGO_COMMON_METADATA_INFO, - crate::cargo::LINT_GROUPS_PRIORITY_INFO, - crate::cargo::MULTIPLE_CRATE_VERSIONS_INFO, - crate::cargo::NEGATIVE_FEATURE_NAMES_INFO, - crate::cargo::REDUNDANT_FEATURE_NAMES_INFO, - crate::cargo::WILDCARD_DEPENDENCIES_INFO, - crate::casts::AS_PTR_CAST_MUT_INFO, - crate::casts::AS_UNDERSCORE_INFO, - crate::casts::BORROW_AS_PTR_INFO, - crate::casts::CAST_ABS_TO_UNSIGNED_INFO, - crate::casts::CAST_ENUM_CONSTRUCTOR_INFO, - crate::casts::CAST_ENUM_TRUNCATION_INFO, - crate::casts::CAST_LOSSLESS_INFO, - crate::casts::CAST_NAN_TO_INT_INFO, - crate::casts::CAST_POSSIBLE_TRUNCATION_INFO, - crate::casts::CAST_POSSIBLE_WRAP_INFO, - crate::casts::CAST_PRECISION_LOSS_INFO, - crate::casts::CAST_PTR_ALIGNMENT_INFO, - crate::casts::CAST_SIGN_LOSS_INFO, - crate::casts::CAST_SLICE_DIFFERENT_SIZES_INFO, - crate::casts::CAST_SLICE_FROM_RAW_PARTS_INFO, - crate::casts::CHAR_LIT_AS_U8_INFO, - crate::casts::FN_TO_NUMERIC_CAST_INFO, - crate::casts::FN_TO_NUMERIC_CAST_ANY_INFO, - crate::casts::FN_TO_NUMERIC_CAST_WITH_TRUNCATION_INFO, - crate::casts::PTR_AS_PTR_INFO, - crate::casts::PTR_CAST_CONSTNESS_INFO, - crate::casts::REF_AS_PTR_INFO, - crate::casts::UNNECESSARY_CAST_INFO, - crate::casts::ZERO_PTR_INFO, - crate::checked_conversions::CHECKED_CONVERSIONS_INFO, - crate::cognitive_complexity::COGNITIVE_COMPLEXITY_INFO, - crate::collapsible_if::COLLAPSIBLE_ELSE_IF_INFO, - crate::collapsible_if::COLLAPSIBLE_IF_INFO, - crate::collection_is_never_read::COLLECTION_IS_NEVER_READ_INFO, - crate::comparison_chain::COMPARISON_CHAIN_INFO, - crate::copies::BRANCHES_SHARING_CODE_INFO, - crate::copies::IFS_SAME_COND_INFO, - crate::copies::IF_SAME_THEN_ELSE_INFO, - crate::copies::SAME_FUNCTIONS_IN_IF_CONDITION_INFO, - crate::copy_iterator::COPY_ITERATOR_INFO, - crate::crate_in_macro_def::CRATE_IN_MACRO_DEF_INFO, - crate::create_dir::CREATE_DIR_INFO, - crate::dbg_macro::DBG_MACRO_INFO, - crate::default::DEFAULT_TRAIT_ACCESS_INFO, - crate::default::FIELD_REASSIGN_WITH_DEFAULT_INFO, - crate::default_constructed_unit_structs::DEFAULT_CONSTRUCTED_UNIT_STRUCTS_INFO, - crate::default_instead_of_iter_empty::DEFAULT_INSTEAD_OF_ITER_EMPTY_INFO, - crate::default_numeric_fallback::DEFAULT_NUMERIC_FALLBACK_INFO, - crate::default_union_representation::DEFAULT_UNION_REPRESENTATION_INFO, - crate::dereference::EXPLICIT_AUTO_DEREF_INFO, - crate::dereference::EXPLICIT_DEREF_METHODS_INFO, - crate::dereference::NEEDLESS_BORROW_INFO, - crate::dereference::REF_BINDING_TO_REFERENCE_INFO, - crate::derivable_impls::DERIVABLE_IMPLS_INFO, - crate::derive::DERIVED_HASH_WITH_MANUAL_EQ_INFO, - crate::derive::DERIVE_ORD_XOR_PARTIAL_ORD_INFO, - crate::derive::DERIVE_PARTIAL_EQ_WITHOUT_EQ_INFO, - crate::derive::EXPL_IMPL_CLONE_ON_COPY_INFO, - crate::derive::UNSAFE_DERIVE_DESERIALIZE_INFO, - crate::disallowed_macros::DISALLOWED_MACROS_INFO, - crate::disallowed_methods::DISALLOWED_METHODS_INFO, - crate::disallowed_names::DISALLOWED_NAMES_INFO, - crate::disallowed_script_idents::DISALLOWED_SCRIPT_IDENTS_INFO, - crate::disallowed_types::DISALLOWED_TYPES_INFO, - crate::doc::DOC_LAZY_CONTINUATION_INFO, - crate::doc::DOC_LINK_WITH_QUOTES_INFO, - crate::doc::DOC_MARKDOWN_INFO, - crate::doc::EMPTY_DOCS_INFO, - crate::doc::MISSING_ERRORS_DOC_INFO, - crate::doc::MISSING_PANICS_DOC_INFO, - crate::doc::MISSING_SAFETY_DOC_INFO, - crate::doc::NEEDLESS_DOCTEST_MAIN_INFO, - crate::doc::SUSPICIOUS_DOC_COMMENTS_INFO, - crate::doc::TEST_ATTR_IN_DOCTEST_INFO, - crate::doc::UNNECESSARY_SAFETY_DOC_INFO, - crate::double_parens::DOUBLE_PARENS_INFO, - crate::drop_forget_ref::DROP_NON_DROP_INFO, - crate::drop_forget_ref::FORGET_NON_DROP_INFO, - crate::drop_forget_ref::MEM_FORGET_INFO, - crate::duplicate_mod::DUPLICATE_MOD_INFO, - crate::else_if_without_else::ELSE_IF_WITHOUT_ELSE_INFO, - crate::empty_drop::EMPTY_DROP_INFO, - crate::empty_enum::EMPTY_ENUM_INFO, - crate::empty_with_brackets::EMPTY_ENUM_VARIANTS_WITH_BRACKETS_INFO, - crate::empty_with_brackets::EMPTY_STRUCTS_WITH_BRACKETS_INFO, - crate::endian_bytes::BIG_ENDIAN_BYTES_INFO, - crate::endian_bytes::HOST_ENDIAN_BYTES_INFO, - crate::endian_bytes::LITTLE_ENDIAN_BYTES_INFO, - crate::entry::MAP_ENTRY_INFO, - crate::enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT_INFO, - crate::equatable_if_let::EQUATABLE_IF_LET_INFO, - crate::error_impl_error::ERROR_IMPL_ERROR_INFO, - crate::escape::BOXED_LOCAL_INFO, - crate::eta_reduction::REDUNDANT_CLOSURE_INFO, - crate::eta_reduction::REDUNDANT_CLOSURE_FOR_METHOD_CALLS_INFO, - crate::excessive_bools::FN_PARAMS_EXCESSIVE_BOOLS_INFO, - crate::excessive_bools::STRUCT_EXCESSIVE_BOOLS_INFO, - crate::excessive_nesting::EXCESSIVE_NESTING_INFO, - crate::exhaustive_items::EXHAUSTIVE_ENUMS_INFO, - crate::exhaustive_items::EXHAUSTIVE_STRUCTS_INFO, - crate::exit::EXIT_INFO, - crate::explicit_write::EXPLICIT_WRITE_INFO, - crate::extra_unused_type_parameters::EXTRA_UNUSED_TYPE_PARAMETERS_INFO, - crate::fallible_impl_from::FALLIBLE_IMPL_FROM_INFO, - crate::float_literal::EXCESSIVE_PRECISION_INFO, - crate::float_literal::LOSSY_FLOAT_LITERAL_INFO, - crate::floating_point_arithmetic::IMPRECISE_FLOPS_INFO, - crate::floating_point_arithmetic::SUBOPTIMAL_FLOPS_INFO, - crate::format::USELESS_FORMAT_INFO, - crate::format_args::FORMAT_IN_FORMAT_ARGS_INFO, - crate::format_args::TO_STRING_IN_FORMAT_ARGS_INFO, - crate::format_args::UNINLINED_FORMAT_ARGS_INFO, - crate::format_args::UNUSED_FORMAT_SPECS_INFO, - crate::format_impl::PRINT_IN_FORMAT_IMPL_INFO, - crate::format_impl::RECURSIVE_FORMAT_IMPL_INFO, - crate::format_push_string::FORMAT_PUSH_STRING_INFO, - crate::formatting::POSSIBLE_MISSING_COMMA_INFO, - crate::formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING_INFO, - crate::formatting::SUSPICIOUS_ELSE_FORMATTING_INFO, - crate::formatting::SUSPICIOUS_UNARY_OP_FORMATTING_INFO, - crate::four_forward_slashes::FOUR_FORWARD_SLASHES_INFO, - crate::from_over_into::FROM_OVER_INTO_INFO, - crate::from_raw_with_void_ptr::FROM_RAW_WITH_VOID_PTR_INFO, - crate::from_str_radix_10::FROM_STR_RADIX_10_INFO, - crate::functions::DOUBLE_MUST_USE_INFO, - crate::functions::IMPL_TRAIT_IN_PARAMS_INFO, - crate::functions::MISNAMED_GETTERS_INFO, - crate::functions::MUST_USE_CANDIDATE_INFO, - crate::functions::MUST_USE_UNIT_INFO, - crate::functions::NOT_UNSAFE_PTR_ARG_DEREF_INFO, - crate::functions::RENAMED_FUNCTION_PARAMS_INFO, - crate::functions::RESULT_LARGE_ERR_INFO, - crate::functions::RESULT_UNIT_ERR_INFO, - crate::functions::TOO_MANY_ARGUMENTS_INFO, - crate::functions::TOO_MANY_LINES_INFO, - crate::future_not_send::FUTURE_NOT_SEND_INFO, - crate::if_let_mutex::IF_LET_MUTEX_INFO, - crate::if_not_else::IF_NOT_ELSE_INFO, - crate::if_then_some_else_none::IF_THEN_SOME_ELSE_NONE_INFO, - crate::ignored_unit_patterns::IGNORED_UNIT_PATTERNS_INFO, - crate::impl_hash_with_borrow_str_and_bytes::IMPL_HASH_BORROW_WITH_STR_AND_BYTES_INFO, - crate::implicit_hasher::IMPLICIT_HASHER_INFO, - crate::implicit_return::IMPLICIT_RETURN_INFO, - crate::implicit_saturating_add::IMPLICIT_SATURATING_ADD_INFO, - crate::implicit_saturating_sub::IMPLICIT_SATURATING_SUB_INFO, - crate::implied_bounds_in_impls::IMPLIED_BOUNDS_IN_IMPLS_INFO, - crate::incompatible_msrv::INCOMPATIBLE_MSRV_INFO, - crate::inconsistent_struct_constructor::INCONSISTENT_STRUCT_CONSTRUCTOR_INFO, - crate::index_refutable_slice::INDEX_REFUTABLE_SLICE_INFO, - crate::indexing_slicing::INDEXING_SLICING_INFO, - crate::indexing_slicing::OUT_OF_BOUNDS_INDEXING_INFO, - crate::ineffective_open_options::INEFFECTIVE_OPEN_OPTIONS_INFO, - crate::infinite_iter::INFINITE_ITER_INFO, - crate::infinite_iter::MAYBE_INFINITE_ITER_INFO, - crate::inherent_impl::MULTIPLE_INHERENT_IMPL_INFO, - crate::inherent_to_string::INHERENT_TO_STRING_INFO, - crate::inherent_to_string::INHERENT_TO_STRING_SHADOW_DISPLAY_INFO, - crate::init_numbered_fields::INIT_NUMBERED_FIELDS_INFO, - crate::inline_fn_without_body::INLINE_FN_WITHOUT_BODY_INFO, - crate::instant_subtraction::MANUAL_INSTANT_ELAPSED_INFO, - crate::instant_subtraction::UNCHECKED_DURATION_SUBTRACTION_INFO, - crate::int_plus_one::INT_PLUS_ONE_INFO, - crate::integer_division_remainder_used::INTEGER_DIVISION_REMAINDER_USED_INFO, - crate::invalid_upcast_comparisons::INVALID_UPCAST_COMPARISONS_INFO, - crate::item_name_repetitions::ENUM_VARIANT_NAMES_INFO, - crate::item_name_repetitions::MODULE_INCEPTION_INFO, - crate::item_name_repetitions::MODULE_NAME_REPETITIONS_INFO, - crate::item_name_repetitions::STRUCT_FIELD_NAMES_INFO, - crate::items_after_statements::ITEMS_AFTER_STATEMENTS_INFO, - crate::items_after_test_module::ITEMS_AFTER_TEST_MODULE_INFO, - crate::iter_not_returning_iterator::ITER_NOT_RETURNING_ITERATOR_INFO, - crate::iter_over_hash_type::ITER_OVER_HASH_TYPE_INFO, - crate::iter_without_into_iter::INTO_ITER_WITHOUT_ITER_INFO, - crate::iter_without_into_iter::ITER_WITHOUT_INTO_ITER_INFO, - crate::large_const_arrays::LARGE_CONST_ARRAYS_INFO, - crate::large_enum_variant::LARGE_ENUM_VARIANT_INFO, - crate::large_futures::LARGE_FUTURES_INFO, - crate::large_include_file::LARGE_INCLUDE_FILE_INFO, - crate::large_stack_arrays::LARGE_STACK_ARRAYS_INFO, - crate::large_stack_frames::LARGE_STACK_FRAMES_INFO, - crate::legacy_numeric_constants::LEGACY_NUMERIC_CONSTANTS_INFO, - crate::len_zero::COMPARISON_TO_EMPTY_INFO, - crate::len_zero::LEN_WITHOUT_IS_EMPTY_INFO, - crate::len_zero::LEN_ZERO_INFO, - crate::let_if_seq::USELESS_LET_IF_SEQ_INFO, - crate::let_underscore::LET_UNDERSCORE_FUTURE_INFO, - crate::let_underscore::LET_UNDERSCORE_LOCK_INFO, - crate::let_underscore::LET_UNDERSCORE_MUST_USE_INFO, - crate::let_underscore::LET_UNDERSCORE_UNTYPED_INFO, - crate::let_with_type_underscore::LET_WITH_TYPE_UNDERSCORE_INFO, - crate::lifetimes::EXTRA_UNUSED_LIFETIMES_INFO, - crate::lifetimes::NEEDLESS_LIFETIMES_INFO, - crate::lines_filter_map_ok::LINES_FILTER_MAP_OK_INFO, - crate::literal_representation::DECIMAL_LITERAL_REPRESENTATION_INFO, - crate::literal_representation::INCONSISTENT_DIGIT_GROUPING_INFO, - crate::literal_representation::LARGE_DIGIT_GROUPS_INFO, - crate::literal_representation::MISTYPED_LITERAL_SUFFIXES_INFO, - crate::literal_representation::UNREADABLE_LITERAL_INFO, - crate::literal_representation::UNUSUAL_BYTE_GROUPINGS_INFO, - crate::loops::EMPTY_LOOP_INFO, - crate::loops::EXPLICIT_COUNTER_LOOP_INFO, - crate::loops::EXPLICIT_INTO_ITER_LOOP_INFO, - crate::loops::EXPLICIT_ITER_LOOP_INFO, - crate::loops::FOR_KV_MAP_INFO, - crate::loops::INFINITE_LOOP_INFO, - crate::loops::ITER_NEXT_LOOP_INFO, - crate::loops::MANUAL_FIND_INFO, - crate::loops::MANUAL_FLATTEN_INFO, - crate::loops::MANUAL_MEMCPY_INFO, - crate::loops::MANUAL_WHILE_LET_SOME_INFO, - crate::loops::MISSING_SPIN_LOOP_INFO, - crate::loops::MUT_RANGE_BOUND_INFO, - crate::loops::NEEDLESS_RANGE_LOOP_INFO, - crate::loops::NEVER_LOOP_INFO, - crate::loops::SAME_ITEM_PUSH_INFO, - crate::loops::SINGLE_ELEMENT_LOOP_INFO, - crate::loops::UNUSED_ENUMERATE_INDEX_INFO, - crate::loops::WHILE_IMMUTABLE_CONDITION_INFO, - crate::loops::WHILE_LET_LOOP_INFO, - crate::loops::WHILE_LET_ON_ITERATOR_INFO, - crate::macro_metavars_in_unsafe::MACRO_METAVARS_IN_UNSAFE_INFO, - crate::macro_use::MACRO_USE_IMPORTS_INFO, - crate::main_recursion::MAIN_RECURSION_INFO, - crate::manual_assert::MANUAL_ASSERT_INFO, - crate::manual_async_fn::MANUAL_ASYNC_FN_INFO, - crate::manual_bits::MANUAL_BITS_INFO, - crate::manual_clamp::MANUAL_CLAMP_INFO, - crate::manual_float_methods::MANUAL_IS_FINITE_INFO, - crate::manual_float_methods::MANUAL_IS_INFINITE_INFO, - crate::manual_hash_one::MANUAL_HASH_ONE_INFO, - crate::manual_is_ascii_check::MANUAL_IS_ASCII_CHECK_INFO, - crate::manual_let_else::MANUAL_LET_ELSE_INFO, - crate::manual_main_separator_str::MANUAL_MAIN_SEPARATOR_STR_INFO, - crate::manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE_INFO, - crate::manual_range_patterns::MANUAL_RANGE_PATTERNS_INFO, - crate::manual_rem_euclid::MANUAL_REM_EUCLID_INFO, - crate::manual_retain::MANUAL_RETAIN_INFO, - crate::manual_slice_size_calculation::MANUAL_SLICE_SIZE_CALCULATION_INFO, - crate::manual_string_new::MANUAL_STRING_NEW_INFO, - crate::manual_strip::MANUAL_STRIP_INFO, - crate::manual_unwrap_or_default::MANUAL_UNWRAP_OR_DEFAULT_INFO, - crate::map_unit_fn::OPTION_MAP_UNIT_FN_INFO, - crate::map_unit_fn::RESULT_MAP_UNIT_FN_INFO, - crate::match_result_ok::MATCH_RESULT_OK_INFO, - crate::matches::COLLAPSIBLE_MATCH_INFO, - crate::matches::INFALLIBLE_DESTRUCTURING_MATCH_INFO, - crate::matches::MANUAL_FILTER_INFO, - crate::matches::MANUAL_MAP_INFO, - crate::matches::MANUAL_UNWRAP_OR_INFO, - crate::matches::MATCH_AS_REF_INFO, - crate::matches::MATCH_BOOL_INFO, - crate::matches::MATCH_LIKE_MATCHES_MACRO_INFO, - crate::matches::MATCH_ON_VEC_ITEMS_INFO, - crate::matches::MATCH_OVERLAPPING_ARM_INFO, - crate::matches::MATCH_REF_PATS_INFO, - crate::matches::MATCH_SAME_ARMS_INFO, - crate::matches::MATCH_SINGLE_BINDING_INFO, - crate::matches::MATCH_STR_CASE_MISMATCH_INFO, - crate::matches::MATCH_WILDCARD_FOR_SINGLE_VARIANTS_INFO, - crate::matches::MATCH_WILD_ERR_ARM_INFO, - crate::matches::NEEDLESS_MATCH_INFO, - crate::matches::REDUNDANT_GUARDS_INFO, - crate::matches::REDUNDANT_PATTERN_MATCHING_INFO, - crate::matches::REST_PAT_IN_FULLY_BOUND_STRUCTS_INFO, - crate::matches::SIGNIFICANT_DROP_IN_SCRUTINEE_INFO, - crate::matches::SINGLE_MATCH_INFO, - crate::matches::SINGLE_MATCH_ELSE_INFO, - crate::matches::TRY_ERR_INFO, - crate::matches::WILDCARD_ENUM_MATCH_ARM_INFO, - crate::matches::WILDCARD_IN_OR_PATTERNS_INFO, - crate::mem_replace::MEM_REPLACE_OPTION_WITH_NONE_INFO, - crate::mem_replace::MEM_REPLACE_WITH_DEFAULT_INFO, - crate::mem_replace::MEM_REPLACE_WITH_UNINIT_INFO, - crate::methods::BIND_INSTEAD_OF_MAP_INFO, - crate::methods::BYTES_COUNT_TO_LEN_INFO, - crate::methods::BYTES_NTH_INFO, - crate::methods::CASE_SENSITIVE_FILE_EXTENSION_COMPARISONS_INFO, - crate::methods::CHARS_LAST_CMP_INFO, - crate::methods::CHARS_NEXT_CMP_INFO, - crate::methods::CLEAR_WITH_DRAIN_INFO, - crate::methods::CLONED_INSTEAD_OF_COPIED_INFO, - crate::methods::CLONE_ON_COPY_INFO, - crate::methods::CLONE_ON_REF_PTR_INFO, - crate::methods::COLLAPSIBLE_STR_REPLACE_INFO, - crate::methods::CONST_IS_EMPTY_INFO, - crate::methods::DRAIN_COLLECT_INFO, - crate::methods::ERR_EXPECT_INFO, - crate::methods::EXPECT_FUN_CALL_INFO, - crate::methods::EXPECT_USED_INFO, - crate::methods::EXTEND_WITH_DRAIN_INFO, - crate::methods::FILETYPE_IS_FILE_INFO, - crate::methods::FILTER_MAP_BOOL_THEN_INFO, - crate::methods::FILTER_MAP_IDENTITY_INFO, - crate::methods::FILTER_MAP_NEXT_INFO, - crate::methods::FILTER_NEXT_INFO, - crate::methods::FLAT_MAP_IDENTITY_INFO, - crate::methods::FLAT_MAP_OPTION_INFO, - crate::methods::FORMAT_COLLECT_INFO, - crate::methods::FROM_ITER_INSTEAD_OF_COLLECT_INFO, - crate::methods::GET_FIRST_INFO, - crate::methods::GET_LAST_WITH_LEN_INFO, - crate::methods::GET_UNWRAP_INFO, - crate::methods::IMPLICIT_CLONE_INFO, - crate::methods::INEFFICIENT_TO_STRING_INFO, - crate::methods::INSPECT_FOR_EACH_INFO, - crate::methods::INTO_ITER_ON_REF_INFO, - crate::methods::IS_DIGIT_ASCII_RADIX_INFO, - crate::methods::ITERATOR_STEP_BY_ZERO_INFO, - crate::methods::ITER_CLONED_COLLECT_INFO, - crate::methods::ITER_COUNT_INFO, - crate::methods::ITER_FILTER_IS_OK_INFO, - crate::methods::ITER_FILTER_IS_SOME_INFO, - crate::methods::ITER_KV_MAP_INFO, - crate::methods::ITER_NEXT_SLICE_INFO, - crate::methods::ITER_NTH_INFO, - crate::methods::ITER_NTH_ZERO_INFO, - crate::methods::ITER_ON_EMPTY_COLLECTIONS_INFO, - crate::methods::ITER_ON_SINGLE_ITEMS_INFO, - crate::methods::ITER_OUT_OF_BOUNDS_INFO, - crate::methods::ITER_OVEREAGER_CLONED_INFO, - crate::methods::ITER_SKIP_NEXT_INFO, - crate::methods::ITER_SKIP_ZERO_INFO, - crate::methods::ITER_WITH_DRAIN_INFO, - crate::methods::JOIN_ABSOLUTE_PATHS_INFO, - crate::methods::MANUAL_C_STR_LITERALS_INFO, - crate::methods::MANUAL_FILTER_MAP_INFO, - crate::methods::MANUAL_FIND_MAP_INFO, - crate::methods::MANUAL_IS_VARIANT_AND_INFO, - crate::methods::MANUAL_NEXT_BACK_INFO, - crate::methods::MANUAL_OK_OR_INFO, - crate::methods::MANUAL_SATURATING_ARITHMETIC_INFO, - crate::methods::MANUAL_SPLIT_ONCE_INFO, - crate::methods::MANUAL_STR_REPEAT_INFO, - crate::methods::MANUAL_TRY_FOLD_INFO, - crate::methods::MAP_CLONE_INFO, - crate::methods::MAP_COLLECT_RESULT_UNIT_INFO, - crate::methods::MAP_ERR_IGNORE_INFO, - crate::methods::MAP_FLATTEN_INFO, - crate::methods::MAP_IDENTITY_INFO, - crate::methods::MAP_UNWRAP_OR_INFO, - crate::methods::MUT_MUTEX_LOCK_INFO, - crate::methods::NAIVE_BYTECOUNT_INFO, - crate::methods::NEEDLESS_COLLECT_INFO, - crate::methods::NEEDLESS_OPTION_AS_DEREF_INFO, - crate::methods::NEEDLESS_OPTION_TAKE_INFO, - crate::methods::NEEDLESS_SPLITN_INFO, - crate::methods::NEW_RET_NO_SELF_INFO, - crate::methods::NONSENSICAL_OPEN_OPTIONS_INFO, - crate::methods::NO_EFFECT_REPLACE_INFO, - crate::methods::OBFUSCATED_IF_ELSE_INFO, - crate::methods::OK_EXPECT_INFO, - crate::methods::OPTION_AS_REF_CLONED_INFO, - crate::methods::OPTION_AS_REF_DEREF_INFO, - crate::methods::OPTION_FILTER_MAP_INFO, - crate::methods::OPTION_MAP_OR_ERR_OK_INFO, - crate::methods::OPTION_MAP_OR_NONE_INFO, - crate::methods::OR_FUN_CALL_INFO, - crate::methods::OR_THEN_UNWRAP_INFO, - crate::methods::PATH_BUF_PUSH_OVERWRITE_INFO, - crate::methods::PATH_ENDS_WITH_EXT_INFO, - crate::methods::RANGE_ZIP_WITH_LEN_INFO, - crate::methods::READONLY_WRITE_LOCK_INFO, - crate::methods::READ_LINE_WITHOUT_TRIM_INFO, - crate::methods::REDUNDANT_AS_STR_INFO, - crate::methods::REPEAT_ONCE_INFO, - crate::methods::RESULT_FILTER_MAP_INFO, - crate::methods::RESULT_MAP_OR_INTO_OPTION_INFO, - crate::methods::SEARCH_IS_SOME_INFO, - crate::methods::SEEK_FROM_CURRENT_INFO, - crate::methods::SEEK_TO_START_INSTEAD_OF_REWIND_INFO, - crate::methods::SHOULD_IMPLEMENT_TRAIT_INFO, - crate::methods::SINGLE_CHAR_ADD_STR_INFO, - crate::methods::SINGLE_CHAR_PATTERN_INFO, - crate::methods::SKIP_WHILE_NEXT_INFO, - crate::methods::STABLE_SORT_PRIMITIVE_INFO, - crate::methods::STRING_EXTEND_CHARS_INFO, - crate::methods::STRING_LIT_CHARS_ANY_INFO, - crate::methods::STR_SPLIT_AT_NEWLINE_INFO, - crate::methods::SUSPICIOUS_COMMAND_ARG_SPACE_INFO, - crate::methods::SUSPICIOUS_MAP_INFO, - crate::methods::SUSPICIOUS_OPEN_OPTIONS_INFO, - crate::methods::SUSPICIOUS_SPLITN_INFO, - crate::methods::SUSPICIOUS_TO_OWNED_INFO, - crate::methods::TYPE_ID_ON_BOX_INFO, - crate::methods::UNINIT_ASSUMED_INIT_INFO, - crate::methods::UNIT_HASH_INFO, - crate::methods::UNNECESSARY_FALLIBLE_CONVERSIONS_INFO, - crate::methods::UNNECESSARY_FILTER_MAP_INFO, - crate::methods::UNNECESSARY_FIND_MAP_INFO, - crate::methods::UNNECESSARY_FOLD_INFO, - crate::methods::UNNECESSARY_GET_THEN_CHECK_INFO, - crate::methods::UNNECESSARY_JOIN_INFO, - crate::methods::UNNECESSARY_LAZY_EVALUATIONS_INFO, - crate::methods::UNNECESSARY_LITERAL_UNWRAP_INFO, - crate::methods::UNNECESSARY_RESULT_MAP_OR_ELSE_INFO, - crate::methods::UNNECESSARY_SORT_BY_INFO, - crate::methods::UNNECESSARY_TO_OWNED_INFO, - crate::methods::UNWRAP_OR_DEFAULT_INFO, - crate::methods::UNWRAP_USED_INFO, - crate::methods::USELESS_ASREF_INFO, - crate::methods::VEC_RESIZE_TO_ZERO_INFO, - crate::methods::VERBOSE_FILE_READS_INFO, - crate::methods::WAKER_CLONE_WAKE_INFO, - crate::methods::WRONG_SELF_CONVENTION_INFO, - crate::methods::ZST_OFFSET_INFO, - crate::min_ident_chars::MIN_IDENT_CHARS_INFO, - crate::minmax::MIN_MAX_INFO, - crate::misc::SHORT_CIRCUIT_STATEMENT_INFO, - crate::misc::TOPLEVEL_REF_ARG_INFO, - crate::misc::USED_UNDERSCORE_BINDING_INFO, - crate::misc_early::BUILTIN_TYPE_SHADOW_INFO, - crate::misc_early::DOUBLE_NEG_INFO, - crate::misc_early::DUPLICATE_UNDERSCORE_ARGUMENT_INFO, - crate::misc_early::MIXED_CASE_HEX_LITERALS_INFO, - crate::misc_early::REDUNDANT_AT_REST_PATTERN_INFO, - crate::misc_early::REDUNDANT_PATTERN_INFO, - crate::misc_early::SEPARATED_LITERAL_SUFFIX_INFO, - crate::misc_early::UNNEEDED_FIELD_PATTERN_INFO, - crate::misc_early::UNNEEDED_WILDCARD_PATTERN_INFO, - crate::misc_early::UNSEPARATED_LITERAL_SUFFIX_INFO, - crate::misc_early::ZERO_PREFIXED_LITERAL_INFO, - crate::mismatching_type_param_order::MISMATCHING_TYPE_PARAM_ORDER_INFO, - crate::missing_assert_message::MISSING_ASSERT_MESSAGE_INFO, - crate::missing_asserts_for_indexing::MISSING_ASSERTS_FOR_INDEXING_INFO, - crate::missing_const_for_fn::MISSING_CONST_FOR_FN_INFO, - crate::missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS_INFO, - crate::missing_enforced_import_rename::MISSING_ENFORCED_IMPORT_RENAMES_INFO, - crate::missing_fields_in_debug::MISSING_FIELDS_IN_DEBUG_INFO, - crate::missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS_INFO, - crate::missing_trait_methods::MISSING_TRAIT_METHODS_INFO, - crate::mixed_read_write_in_expression::DIVERGING_SUB_EXPRESSION_INFO, - crate::mixed_read_write_in_expression::MIXED_READ_WRITE_IN_EXPRESSION_INFO, - crate::module_style::MOD_MODULE_FILES_INFO, - crate::module_style::SELF_NAMED_MODULE_FILES_INFO, - crate::multi_assignments::MULTI_ASSIGNMENTS_INFO, - crate::multiple_bound_locations::MULTIPLE_BOUND_LOCATIONS_INFO, - crate::multiple_unsafe_ops_per_block::MULTIPLE_UNSAFE_OPS_PER_BLOCK_INFO, - crate::mut_key::MUTABLE_KEY_TYPE_INFO, - crate::mut_mut::MUT_MUT_INFO, - crate::mut_reference::UNNECESSARY_MUT_PASSED_INFO, - crate::mutable_debug_assertion::DEBUG_ASSERT_WITH_MUT_CALL_INFO, - crate::mutex_atomic::MUTEX_ATOMIC_INFO, - crate::mutex_atomic::MUTEX_INTEGER_INFO, - crate::needless_arbitrary_self_type::NEEDLESS_ARBITRARY_SELF_TYPE_INFO, - crate::needless_bool::BOOL_COMPARISON_INFO, - crate::needless_bool::NEEDLESS_BOOL_INFO, - crate::needless_bool::NEEDLESS_BOOL_ASSIGN_INFO, - crate::needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE_INFO, - crate::needless_borrows_for_generic_args::NEEDLESS_BORROWS_FOR_GENERIC_ARGS_INFO, - crate::needless_continue::NEEDLESS_CONTINUE_INFO, - crate::needless_else::NEEDLESS_ELSE_INFO, - crate::needless_for_each::NEEDLESS_FOR_EACH_INFO, - crate::needless_if::NEEDLESS_IF_INFO, - crate::needless_late_init::NEEDLESS_LATE_INIT_INFO, - crate::needless_parens_on_range_literals::NEEDLESS_PARENS_ON_RANGE_LITERALS_INFO, - crate::needless_pass_by_ref_mut::NEEDLESS_PASS_BY_REF_MUT_INFO, - crate::needless_pass_by_value::NEEDLESS_PASS_BY_VALUE_INFO, - crate::needless_question_mark::NEEDLESS_QUESTION_MARK_INFO, - crate::needless_update::NEEDLESS_UPDATE_INFO, - crate::neg_cmp_op_on_partial_ord::NEG_CMP_OP_ON_PARTIAL_ORD_INFO, - crate::neg_multiply::NEG_MULTIPLY_INFO, - crate::new_without_default::NEW_WITHOUT_DEFAULT_INFO, - crate::no_effect::NO_EFFECT_INFO, - crate::no_effect::NO_EFFECT_UNDERSCORE_BINDING_INFO, - crate::no_effect::UNNECESSARY_OPERATION_INFO, - crate::no_mangle_with_rust_abi::NO_MANGLE_WITH_RUST_ABI_INFO, - crate::non_canonical_impls::NON_CANONICAL_CLONE_IMPL_INFO, - crate::non_canonical_impls::NON_CANONICAL_PARTIAL_ORD_IMPL_INFO, - crate::non_copy_const::BORROW_INTERIOR_MUTABLE_CONST_INFO, - crate::non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST_INFO, - crate::non_expressive_names::JUST_UNDERSCORES_AND_DIGITS_INFO, - crate::non_expressive_names::MANY_SINGLE_CHAR_NAMES_INFO, - crate::non_expressive_names::SIMILAR_NAMES_INFO, - crate::non_octal_unix_permissions::NON_OCTAL_UNIX_PERMISSIONS_INFO, - crate::non_send_fields_in_send_ty::NON_SEND_FIELDS_IN_SEND_TY_INFO, - crate::nonstandard_macro_braces::NONSTANDARD_MACRO_BRACES_INFO, - crate::octal_escapes::OCTAL_ESCAPES_INFO, - crate::only_used_in_recursion::ONLY_USED_IN_RECURSION_INFO, - crate::operators::ABSURD_EXTREME_COMPARISONS_INFO, - crate::operators::ARITHMETIC_SIDE_EFFECTS_INFO, - crate::operators::ASSIGN_OP_PATTERN_INFO, - crate::operators::BAD_BIT_MASK_INFO, - crate::operators::CMP_OWNED_INFO, - crate::operators::DOUBLE_COMPARISONS_INFO, - crate::operators::DURATION_SUBSEC_INFO, - crate::operators::EQ_OP_INFO, - crate::operators::ERASING_OP_INFO, - crate::operators::FLOAT_ARITHMETIC_INFO, - crate::operators::FLOAT_CMP_INFO, - crate::operators::FLOAT_CMP_CONST_INFO, - crate::operators::FLOAT_EQUALITY_WITHOUT_ABS_INFO, - crate::operators::IDENTITY_OP_INFO, - crate::operators::IMPOSSIBLE_COMPARISONS_INFO, - crate::operators::INEFFECTIVE_BIT_MASK_INFO, - crate::operators::INTEGER_DIVISION_INFO, - crate::operators::MISREFACTORED_ASSIGN_OP_INFO, - crate::operators::MODULO_ARITHMETIC_INFO, - crate::operators::MODULO_ONE_INFO, - crate::operators::NEEDLESS_BITWISE_BOOL_INFO, - crate::operators::OP_REF_INFO, - crate::operators::PTR_EQ_INFO, - crate::operators::REDUNDANT_COMPARISONS_INFO, - crate::operators::SELF_ASSIGNMENT_INFO, - crate::operators::VERBOSE_BIT_MASK_INFO, - crate::option_env_unwrap::OPTION_ENV_UNWRAP_INFO, - crate::option_if_let_else::OPTION_IF_LET_ELSE_INFO, - crate::overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL_INFO, - crate::panic_in_result_fn::PANIC_IN_RESULT_FN_INFO, - crate::panic_unimplemented::PANIC_INFO, - crate::panic_unimplemented::TODO_INFO, - crate::panic_unimplemented::UNIMPLEMENTED_INFO, - crate::panic_unimplemented::UNREACHABLE_INFO, - crate::partial_pub_fields::PARTIAL_PUB_FIELDS_INFO, - crate::partialeq_ne_impl::PARTIALEQ_NE_IMPL_INFO, - crate::partialeq_to_none::PARTIALEQ_TO_NONE_INFO, - crate::pass_by_ref_or_value::LARGE_TYPES_PASSED_BY_VALUE_INFO, - crate::pass_by_ref_or_value::TRIVIALLY_COPY_PASS_BY_REF_INFO, - crate::pattern_type_mismatch::PATTERN_TYPE_MISMATCH_INFO, - crate::permissions_set_readonly_false::PERMISSIONS_SET_READONLY_FALSE_INFO, - crate::precedence::PRECEDENCE_INFO, - crate::ptr::CMP_NULL_INFO, - crate::ptr::INVALID_NULL_PTR_USAGE_INFO, - crate::ptr::MUT_FROM_REF_INFO, - crate::ptr::PTR_ARG_INFO, - crate::ptr_offset_with_cast::PTR_OFFSET_WITH_CAST_INFO, - crate::pub_underscore_fields::PUB_UNDERSCORE_FIELDS_INFO, - crate::pub_use::PUB_USE_INFO, - crate::question_mark::QUESTION_MARK_INFO, - crate::question_mark_used::QUESTION_MARK_USED_INFO, - crate::ranges::MANUAL_RANGE_CONTAINS_INFO, - crate::ranges::RANGE_MINUS_ONE_INFO, - crate::ranges::RANGE_PLUS_ONE_INFO, - crate::ranges::REVERSED_EMPTY_RANGES_INFO, - crate::raw_strings::NEEDLESS_RAW_STRINGS_INFO, - crate::raw_strings::NEEDLESS_RAW_STRING_HASHES_INFO, - crate::rc_clone_in_vec_init::RC_CLONE_IN_VEC_INIT_INFO, - crate::read_zero_byte_vec::READ_ZERO_BYTE_VEC_INFO, - crate::redundant_async_block::REDUNDANT_ASYNC_BLOCK_INFO, - crate::redundant_clone::REDUNDANT_CLONE_INFO, - crate::redundant_closure_call::REDUNDANT_CLOSURE_CALL_INFO, - crate::redundant_else::REDUNDANT_ELSE_INFO, - crate::redundant_field_names::REDUNDANT_FIELD_NAMES_INFO, - crate::redundant_locals::REDUNDANT_LOCALS_INFO, - crate::redundant_pub_crate::REDUNDANT_PUB_CRATE_INFO, - crate::redundant_slicing::DEREF_BY_SLICING_INFO, - crate::redundant_slicing::REDUNDANT_SLICING_INFO, - crate::redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES_INFO, - crate::redundant_type_annotations::REDUNDANT_TYPE_ANNOTATIONS_INFO, - crate::ref_option_ref::REF_OPTION_REF_INFO, - crate::ref_patterns::REF_PATTERNS_INFO, - crate::reference::DEREF_ADDROF_INFO, - crate::regex::INVALID_REGEX_INFO, - crate::regex::TRIVIAL_REGEX_INFO, - crate::repeat_vec_with_capacity::REPEAT_VEC_WITH_CAPACITY_INFO, - crate::reserve_after_initialization::RESERVE_AFTER_INITIALIZATION_INFO, - crate::return_self_not_must_use::RETURN_SELF_NOT_MUST_USE_INFO, - crate::returns::LET_AND_RETURN_INFO, - crate::returns::NEEDLESS_RETURN_INFO, - crate::returns::NEEDLESS_RETURN_WITH_QUESTION_MARK_INFO, - crate::same_name_method::SAME_NAME_METHOD_INFO, - crate::self_named_constructors::SELF_NAMED_CONSTRUCTORS_INFO, - crate::semicolon_block::SEMICOLON_INSIDE_BLOCK_INFO, - crate::semicolon_block::SEMICOLON_OUTSIDE_BLOCK_INFO, - crate::semicolon_if_nothing_returned::SEMICOLON_IF_NOTHING_RETURNED_INFO, - crate::serde_api::SERDE_API_MISUSE_INFO, - crate::shadow::SHADOW_REUSE_INFO, - crate::shadow::SHADOW_SAME_INFO, - crate::shadow::SHADOW_UNRELATED_INFO, - crate::significant_drop_tightening::SIGNIFICANT_DROP_TIGHTENING_INFO, - crate::single_call_fn::SINGLE_CALL_FN_INFO, - crate::single_char_lifetime_names::SINGLE_CHAR_LIFETIME_NAMES_INFO, - crate::single_component_path_imports::SINGLE_COMPONENT_PATH_IMPORTS_INFO, - crate::single_range_in_vec_init::SINGLE_RANGE_IN_VEC_INIT_INFO, - crate::size_of_in_element_count::SIZE_OF_IN_ELEMENT_COUNT_INFO, - crate::size_of_ref::SIZE_OF_REF_INFO, - crate::slow_vector_initialization::SLOW_VECTOR_INITIALIZATION_INFO, - crate::std_instead_of_core::ALLOC_INSTEAD_OF_CORE_INFO, - crate::std_instead_of_core::STD_INSTEAD_OF_ALLOC_INFO, - crate::std_instead_of_core::STD_INSTEAD_OF_CORE_INFO, - crate::strings::STRING_ADD_INFO, - crate::strings::STRING_ADD_ASSIGN_INFO, - crate::strings::STRING_FROM_UTF8_AS_BYTES_INFO, - crate::strings::STRING_LIT_AS_BYTES_INFO, - crate::strings::STRING_SLICE_INFO, - crate::strings::STRING_TO_STRING_INFO, - crate::strings::STR_TO_STRING_INFO, - crate::strings::TRIM_SPLIT_WHITESPACE_INFO, - crate::strlen_on_c_strings::STRLEN_ON_C_STRINGS_INFO, - crate::suspicious_operation_groupings::SUSPICIOUS_OPERATION_GROUPINGS_INFO, - crate::suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL_INFO, - crate::suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL_INFO, - crate::suspicious_xor_used_as_pow::SUSPICIOUS_XOR_USED_AS_POW_INFO, - crate::swap::ALMOST_SWAPPED_INFO, - crate::swap::MANUAL_SWAP_INFO, - crate::swap_ptr_to_ref::SWAP_PTR_TO_REF_INFO, - crate::tabs_in_doc_comments::TABS_IN_DOC_COMMENTS_INFO, - crate::temporary_assignment::TEMPORARY_ASSIGNMENT_INFO, - crate::tests_outside_test_module::TESTS_OUTSIDE_TEST_MODULE_INFO, - crate::thread_local_initializer_can_be_made_const::THREAD_LOCAL_INITIALIZER_CAN_BE_MADE_CONST_INFO, - crate::to_digit_is_some::TO_DIGIT_IS_SOME_INFO, - crate::to_string_trait_impl::TO_STRING_TRAIT_IMPL_INFO, - crate::trailing_empty_array::TRAILING_EMPTY_ARRAY_INFO, - crate::trait_bounds::TRAIT_DUPLICATION_IN_BOUNDS_INFO, - crate::trait_bounds::TYPE_REPETITION_IN_BOUNDS_INFO, - crate::transmute::CROSSPOINTER_TRANSMUTE_INFO, - crate::transmute::EAGER_TRANSMUTE_INFO, - crate::transmute::MISSING_TRANSMUTE_ANNOTATIONS_INFO, - crate::transmute::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS_INFO, - crate::transmute::TRANSMUTE_BYTES_TO_STR_INFO, - crate::transmute::TRANSMUTE_FLOAT_TO_INT_INFO, - crate::transmute::TRANSMUTE_INT_TO_BOOL_INFO, - crate::transmute::TRANSMUTE_INT_TO_CHAR_INFO, - crate::transmute::TRANSMUTE_INT_TO_FLOAT_INFO, - crate::transmute::TRANSMUTE_INT_TO_NON_ZERO_INFO, - crate::transmute::TRANSMUTE_NULL_TO_FN_INFO, - crate::transmute::TRANSMUTE_NUM_TO_BYTES_INFO, - crate::transmute::TRANSMUTE_PTR_TO_PTR_INFO, - crate::transmute::TRANSMUTE_PTR_TO_REF_INFO, - crate::transmute::TRANSMUTE_UNDEFINED_REPR_INFO, - crate::transmute::TRANSMUTING_NULL_INFO, - crate::transmute::UNSOUND_COLLECTION_TRANSMUTE_INFO, - crate::transmute::USELESS_TRANSMUTE_INFO, - crate::transmute::WRONG_TRANSMUTE_INFO, - crate::tuple_array_conversions::TUPLE_ARRAY_CONVERSIONS_INFO, - crate::types::BORROWED_BOX_INFO, - crate::types::BOX_COLLECTION_INFO, - crate::types::LINKEDLIST_INFO, - crate::types::OPTION_OPTION_INFO, - crate::types::RC_BUFFER_INFO, - crate::types::RC_MUTEX_INFO, - crate::types::REDUNDANT_ALLOCATION_INFO, - crate::types::TYPE_COMPLEXITY_INFO, - crate::types::VEC_BOX_INFO, - crate::unconditional_recursion::UNCONDITIONAL_RECURSION_INFO, - crate::undocumented_unsafe_blocks::UNDOCUMENTED_UNSAFE_BLOCKS_INFO, - crate::undocumented_unsafe_blocks::UNNECESSARY_SAFETY_COMMENT_INFO, - crate::unicode::INVISIBLE_CHARACTERS_INFO, - crate::unicode::NON_ASCII_LITERAL_INFO, - crate::unicode::UNICODE_NOT_NFC_INFO, - crate::uninhabited_references::UNINHABITED_REFERENCES_INFO, - crate::uninit_vec::UNINIT_VEC_INFO, - crate::unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD_INFO, - crate::unit_types::LET_UNIT_VALUE_INFO, - crate::unit_types::UNIT_ARG_INFO, - crate::unit_types::UNIT_CMP_INFO, - crate::unnamed_address::FN_ADDRESS_COMPARISONS_INFO, - crate::unnecessary_box_returns::UNNECESSARY_BOX_RETURNS_INFO, - crate::unnecessary_map_on_constructor::UNNECESSARY_MAP_ON_CONSTRUCTOR_INFO, - crate::unnecessary_owned_empty_strings::UNNECESSARY_OWNED_EMPTY_STRINGS_INFO, - crate::unnecessary_self_imports::UNNECESSARY_SELF_IMPORTS_INFO, - crate::unnecessary_struct_initialization::UNNECESSARY_STRUCT_INITIALIZATION_INFO, - crate::unnecessary_wraps::UNNECESSARY_WRAPS_INFO, - crate::unnested_or_patterns::UNNESTED_OR_PATTERNS_INFO, - crate::unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME_INFO, - crate::unused_async::UNUSED_ASYNC_INFO, - crate::unused_io_amount::UNUSED_IO_AMOUNT_INFO, - crate::unused_peekable::UNUSED_PEEKABLE_INFO, - crate::unused_rounding::UNUSED_ROUNDING_INFO, - crate::unused_self::UNUSED_SELF_INFO, - crate::unused_unit::UNUSED_UNIT_INFO, - crate::unwrap::PANICKING_UNWRAP_INFO, - crate::unwrap::UNNECESSARY_UNWRAP_INFO, - crate::unwrap_in_result::UNWRAP_IN_RESULT_INFO, - crate::upper_case_acronyms::UPPER_CASE_ACRONYMS_INFO, - crate::use_self::USE_SELF_INFO, - crate::useless_conversion::USELESS_CONVERSION_INFO, - crate::vec::USELESS_VEC_INFO, - crate::vec_init_then_push::VEC_INIT_THEN_PUSH_INFO, - crate::visibility::NEEDLESS_PUB_SELF_INFO, - crate::visibility::PUB_WITHOUT_SHORTHAND_INFO, - crate::visibility::PUB_WITH_SHORTHAND_INFO, - crate::wildcard_imports::ENUM_GLOB_USE_INFO, - crate::wildcard_imports::WILDCARD_IMPORTS_INFO, - crate::write::PRINTLN_EMPTY_STRING_INFO, - crate::write::PRINT_LITERAL_INFO, - crate::write::PRINT_STDERR_INFO, - crate::write::PRINT_STDOUT_INFO, - crate::write::PRINT_WITH_NEWLINE_INFO, - crate::write::USE_DEBUG_INFO, - crate::write::WRITELN_EMPTY_STRING_INFO, - crate::write::WRITE_LITERAL_INFO, - crate::write::WRITE_WITH_NEWLINE_INFO, - crate::zero_div_zero::ZERO_DIVIDED_BY_ZERO_INFO, - crate::zero_repeat_side_effects::ZERO_REPEAT_SIDE_EFFECTS_INFO, - crate::zero_sized_map_values::ZERO_SIZED_MAP_VALUES_INFO, -]; diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs deleted file mode 100644 index 2b3f4854255c..000000000000 --- a/clippy_lints/src/default.rs +++ /dev/null @@ -1,294 +0,0 @@ -use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_sugg}; -use clippy_utils::source::snippet_with_context; -use clippy_utils::ty::{has_drop, is_copy}; -use clippy_utils::{any_parent_is_automatically_derived, contains_name, get_parent_expr, is_from_proc_macro}; -use rustc_data_structures::fx::FxHashSet; -use rustc_errors::Applicability; -use rustc_hir::def::Res; -use rustc_hir::{Block, Expr, ExprKind, PatKind, QPath, Stmt, StmtKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_middle::ty::print::with_forced_trimmed_paths; -use rustc_session::impl_lint_pass; -use rustc_span::symbol::{Ident, Symbol}; -use rustc_span::{sym, Span}; - -declare_clippy_lint! { - /// ### What it does - /// Checks for literal calls to `Default::default()`. - /// - /// ### Why is this bad? - /// It's easier for the reader if the name of the type is used, rather than the - /// generic `Default`. - /// - /// ### Example - /// ```no_run - /// let s: String = Default::default(); - /// ``` - /// - /// Use instead: - /// ```no_run - /// let s = String::default(); - /// ``` - #[clippy::version = "pre 1.29.0"] - pub DEFAULT_TRAIT_ACCESS, - pedantic, - "checks for literal calls to `Default::default()`" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for immediate reassignment of fields initialized - /// with Default::default(). - /// - /// ### Why is this bad? - ///It's more idiomatic to use the [functional update syntax](https://doc.rust-lang.org/reference/expressions/struct-expr.html#functional-update-syntax). - /// - /// ### Known problems - /// Assignments to patterns that are of tuple type are not linted. - /// - /// ### Example - /// ```no_run - /// # #[derive(Default)] - /// # struct A { i: i32 } - /// let mut a: A = Default::default(); - /// a.i = 42; - /// ``` - /// - /// Use instead: - /// ```no_run - /// # #[derive(Default)] - /// # struct A { i: i32 } - /// let a = A { - /// i: 42, - /// .. Default::default() - /// }; - /// ``` - #[clippy::version = "1.49.0"] - pub FIELD_REASSIGN_WITH_DEFAULT, - style, - "binding initialized with Default should have its fields set in the initializer" -} - -#[derive(Default)] -pub struct Default { - // Spans linted by `field_reassign_with_default`. - reassigned_linted: FxHashSet, -} - -impl_lint_pass!(Default => [DEFAULT_TRAIT_ACCESS, FIELD_REASSIGN_WITH_DEFAULT]); - -impl<'tcx> LateLintPass<'tcx> for Default { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if !expr.span.from_expansion() - // Avoid cases already linted by `field_reassign_with_default` - && !self.reassigned_linted.contains(&expr.span) - && let ExprKind::Call(path, ..) = expr.kind - && !any_parent_is_automatically_derived(cx.tcx, expr.hir_id) - && let ExprKind::Path(ref qpath) = path.kind - && let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id() - && cx.tcx.is_diagnostic_item(sym::default_fn, def_id) - && !is_update_syntax_base(cx, expr) - // Detect and ignore ::default() because these calls do explicitly name the type. - && let QPath::Resolved(None, _path) = qpath - && let expr_ty = cx.typeck_results().expr_ty(expr) - && let ty::Adt(def, ..) = expr_ty.kind() - && !is_from_proc_macro(cx, expr) - { - let replacement = with_forced_trimmed_paths!(format!("{}::default()", cx.tcx.def_path_str(def.did()))); - span_lint_and_sugg( - cx, - DEFAULT_TRAIT_ACCESS, - expr.span, - format!("calling `{replacement}` is more clear than this expression"), - "try", - replacement, - Applicability::Unspecified, // First resolve the TODO above - ); - } - } - - #[expect(clippy::too_many_lines)] - fn check_block(&mut self, cx: &LateContext<'tcx>, block: &Block<'tcx>) { - // start from the `let mut _ = _::default();` and look at all the following - // statements, see if they re-assign the fields of the binding - let stmts_head = match block.stmts { - // Skip the last statement since there cannot possibly be any following statements that re-assign fields. - [head @ .., _] if !head.is_empty() => head, - _ => return, - }; - for (stmt_idx, stmt) in stmts_head.iter().enumerate() { - // find all binding statements like `let mut _ = T::default()` where `T::default()` is the - // `default` method of the `Default` trait, and store statement index in current block being - // checked and the name of the bound variable - let (local, variant, binding_name, binding_type, span) = if let StmtKind::Let(local) = stmt.kind - // only take `let ...` statements - && let Some(expr) = local.init - && !any_parent_is_automatically_derived(cx.tcx, expr.hir_id) - && !expr.span.from_expansion() - // only take bindings to identifiers - && let PatKind::Binding(_, binding_id, ident, _) = local.pat.kind - // only when assigning `... = Default::default()` - && is_expr_default(expr, cx) - && let binding_type = cx.typeck_results().node_type(binding_id) - && let ty::Adt(adt, args) = *binding_type.kind() - && adt.is_struct() - && let variant = adt.non_enum_variant() - && (adt.did().is_local() || !variant.is_field_list_non_exhaustive()) - && let module_did = cx.tcx.parent_module(stmt.hir_id) - && variant - .fields - .iter() - .all(|field| field.vis.is_accessible_from(module_did, cx.tcx)) - && let all_fields_are_copy = variant - .fields - .iter() - .all(|field| { - is_copy(cx, cx.tcx.type_of(field.did).instantiate(cx.tcx, args)) - }) - && (!has_drop(cx, binding_type) || all_fields_are_copy) - { - (local, variant, ident.name, binding_type, expr.span) - } else { - continue; - }; - - let init_ctxt = local.span.ctxt(); - - // find all "later statement"'s where the fields of the binding set as - // Default::default() get reassigned, unless the reassignment refers to the original binding - let mut first_assign = None; - let mut assigned_fields = Vec::new(); - let mut cancel_lint = false; - for consecutive_statement in &block.stmts[stmt_idx + 1..] { - // find out if and which field was set by this `consecutive_statement` - if let Some((field_ident, assign_rhs)) = field_reassigned_by_stmt(consecutive_statement, binding_name) { - // interrupt and cancel lint if assign_rhs references the original binding - if contains_name(binding_name, assign_rhs, cx) || init_ctxt != consecutive_statement.span.ctxt() { - cancel_lint = true; - break; - } - - // if the field was previously assigned, replace the assignment, otherwise insert the assignment - if let Some(prev) = assigned_fields - .iter_mut() - .find(|(field_name, _)| field_name == &field_ident.name) - { - *prev = (field_ident.name, assign_rhs); - } else { - assigned_fields.push((field_ident.name, assign_rhs)); - } - - // also set first instance of error for help message - if first_assign.is_none() { - first_assign = Some(consecutive_statement); - } - } - // interrupt if no field was assigned, since we only want to look at consecutive statements - else { - break; - } - } - - // if there are incorrectly assigned fields, do a span_lint_and_note to suggest - // construction using `Ty { fields, ..Default::default() }` - if !assigned_fields.is_empty() && !cancel_lint { - // if all fields of the struct are not assigned, add `.. Default::default()` to the suggestion. - let ext_with_default = !variant - .fields - .iter() - .all(|field| assigned_fields.iter().any(|(a, _)| a == &field.name)); - - let mut app = Applicability::Unspecified; - let field_list = assigned_fields - .into_iter() - .map(|(field, rhs)| { - // extract and store the assigned value for help message - let value_snippet = snippet_with_context(cx, rhs.span, init_ctxt, "..", &mut app).0; - format!("{field}: {value_snippet}") - }) - .collect::>() - .join(", "); - - // give correct suggestion if generics are involved (see #6944) - let binding_type = if let ty::Adt(adt_def, args) = binding_type.kind() - && !args.is_empty() - { - let adt_def_ty_name = cx.tcx.item_name(adt_def.did()); - let generic_args = args.iter().collect::>(); - let tys_str = generic_args - .iter() - .map(ToString::to_string) - .collect::>() - .join(", "); - format!("{adt_def_ty_name}::<{}>", &tys_str) - } else { - binding_type.to_string() - }; - - let sugg = if ext_with_default { - if field_list.is_empty() { - format!("{binding_type}::default()") - } else { - format!("{binding_type} {{ {field_list}, ..Default::default() }}") - } - } else { - format!("{binding_type} {{ {field_list} }}") - }; - - // span lint once per statement that binds default - span_lint_and_note( - cx, - FIELD_REASSIGN_WITH_DEFAULT, - first_assign.unwrap().span, - "field assignment outside of initializer for an instance created with Default::default()", - Some(local.span), - format!("consider initializing the variable with `{sugg}` and removing relevant reassignments"), - ); - self.reassigned_linted.insert(span); - } - } - } -} - -/// Checks if the given expression is the `default` method belonging to the `Default` trait. -fn is_expr_default<'tcx>(expr: &'tcx Expr<'tcx>, cx: &LateContext<'tcx>) -> bool { - if let ExprKind::Call(fn_expr, _) = &expr.kind - && let ExprKind::Path(qpath) = &fn_expr.kind - && let Res::Def(_, def_id) = cx.qpath_res(qpath, fn_expr.hir_id) - { - // right hand side of assignment is `Default::default` - cx.tcx.is_diagnostic_item(sym::default_fn, def_id) - } else { - false - } -} - -/// Returns the reassigned field and the assigning expression (right-hand side of assign). -fn field_reassigned_by_stmt<'tcx>(this: &Stmt<'tcx>, binding_name: Symbol) -> Option<(Ident, &'tcx Expr<'tcx>)> { - if let StmtKind::Semi(later_expr) = this.kind - // only take assignments - && let ExprKind::Assign(assign_lhs, assign_rhs, _) = later_expr.kind - // only take assignments to fields where the left-hand side field is a field of - // the same binding as the previous statement - && let ExprKind::Field(binding, field_ident) = assign_lhs.kind - && let ExprKind::Path(QPath::Resolved(_, path)) = binding.kind - && let Some(second_binding_name) = path.segments.last() - && second_binding_name.ident.name == binding_name - { - Some((field_ident, assign_rhs)) - } else { - None - } -} - -/// Returns whether `expr` is the update syntax base: `Foo { a: 1, .. base }` -fn is_update_syntax_base<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool { - if let Some(parent) = get_parent_expr(cx, expr) - && let ExprKind::Struct(_, _, Some(base)) = parent.kind - { - base.hir_id == expr.hir_id - } else { - false - } -} diff --git a/clippy_lints/src/default_constructed_unit_structs.rs b/clippy_lints/src/default_constructed_unit_structs.rs deleted file mode 100644 index 137781754966..000000000000 --- a/clippy_lints/src/default_constructed_unit_structs.rs +++ /dev/null @@ -1,85 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::is_ty_alias; -use hir::def::Res; -use hir::ExprKind; -use rustc_errors::Applicability; -use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::declare_lint_pass; -use rustc_span::sym; - -declare_clippy_lint! { - /// ### What it does - /// Checks for construction on unit struct using `default`. - /// - /// ### Why is this bad? - /// This adds code complexity and an unnecessary function call. - /// - /// ### Example - /// ```no_run - /// # use std::marker::PhantomData; - /// #[derive(Default)] - /// struct S { - /// _marker: PhantomData - /// } - /// - /// let _: S = S { - /// _marker: PhantomData::default() - /// }; - /// ``` - /// Use instead: - /// ```no_run - /// # use std::marker::PhantomData; - /// struct S { - /// _marker: PhantomData - /// } - /// - /// let _: S = S { - /// _marker: PhantomData - /// }; - /// ``` - #[clippy::version = "1.71.0"] - pub DEFAULT_CONSTRUCTED_UNIT_STRUCTS, - complexity, - "unit structs can be constructed without calling `default`" -} -declare_lint_pass!(DefaultConstructedUnitStructs => [DEFAULT_CONSTRUCTED_UNIT_STRUCTS]); - -fn is_alias(ty: hir::Ty<'_>) -> bool { - if let hir::TyKind::Path(ref qpath) = ty.kind { - is_ty_alias(qpath) - } else { - false - } -} - -impl LateLintPass<'_> for DefaultConstructedUnitStructs { - fn check_expr<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) { - if let ExprKind::Call(fn_expr, &[]) = expr.kind - // make sure we have a call to `Default::default` - && let ExprKind::Path(ref qpath @ hir::QPath::TypeRelative(base, _)) = fn_expr.kind - // make sure this isn't a type alias: - // `::Assoc` cannot be used as a constructor - && !is_alias(*base) - && let Res::Def(_, def_id) = cx.qpath_res(qpath, fn_expr.hir_id) - && cx.tcx.is_diagnostic_item(sym::default_fn, def_id) - // make sure we have a struct with no fields (unit struct) - && let ty::Adt(def, ..) = cx.typeck_results().expr_ty(expr).kind() - && def.is_struct() - && let var @ ty::VariantDef { ctor: Some((hir::def::CtorKind::Const, _)), .. } = def.non_enum_variant() - && !var.is_field_list_non_exhaustive() - && !expr.span.from_expansion() && !qpath.span().from_expansion() - { - span_lint_and_sugg( - cx, - DEFAULT_CONSTRUCTED_UNIT_STRUCTS, - expr.span.with_lo(qpath.qself_span().hi()), - "use of `default` to create a unit struct", - "remove this call to `default`", - String::new(), - Applicability::MachineApplicable, - ); - }; - } -} diff --git a/clippy_lints/src/default_instead_of_iter_empty.rs b/clippy_lints/src/default_instead_of_iter_empty.rs deleted file mode 100644 index ac49e6f1a482..000000000000 --- a/clippy_lints/src/default_instead_of_iter_empty.rs +++ /dev/null @@ -1,81 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::snippet_with_context; -use clippy_utils::{last_path_segment, std_or_core}; -use rustc_errors::Applicability; -use rustc_hir::{def, Expr, ExprKind, GenericArg, QPath, TyKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::declare_lint_pass; -use rustc_span::{sym, SyntaxContext}; - -declare_clippy_lint! { - /// ### What it does - /// It checks for `std::iter::Empty::default()` and suggests replacing it with - /// `std::iter::empty()`. - /// ### Why is this bad? - /// `std::iter::empty()` is the more idiomatic way. - /// ### Example - /// ```no_run - /// let _ = std::iter::Empty::::default(); - /// let iter: std::iter::Empty = std::iter::Empty::default(); - /// ``` - /// Use instead: - /// ```no_run - /// let _ = std::iter::empty::(); - /// let iter: std::iter::Empty = std::iter::empty(); - /// ``` - #[clippy::version = "1.64.0"] - pub DEFAULT_INSTEAD_OF_ITER_EMPTY, - style, - "check `std::iter::Empty::default()` and replace with `std::iter::empty()`" -} -declare_lint_pass!(DefaultIterEmpty => [DEFAULT_INSTEAD_OF_ITER_EMPTY]); - -impl<'tcx> LateLintPass<'tcx> for DefaultIterEmpty { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Call(iter_expr, []) = &expr.kind - && let ExprKind::Path(QPath::TypeRelative(ty, _)) = &iter_expr.kind - && let TyKind::Path(ty_path) = &ty.kind - && let QPath::Resolved(None, path) = ty_path - && let def::Res::Def(_, def_id) = &path.res - && cx.tcx.is_diagnostic_item(sym::IterEmpty, *def_id) - && let ctxt = expr.span.ctxt() - && ty.span.ctxt() == ctxt - { - let mut applicability = Applicability::MachineApplicable; - let Some(path) = std_or_core(cx) else { return }; - let path = format!("{path}::iter::empty"); - let sugg = make_sugg(cx, ty_path, ctxt, &mut applicability, &path); - span_lint_and_sugg( - cx, - DEFAULT_INSTEAD_OF_ITER_EMPTY, - expr.span, - format!("`{path}()` is the more idiomatic way"), - "try", - sugg, - applicability, - ); - } - } -} - -fn make_sugg( - cx: &LateContext<'_>, - ty_path: &QPath<'_>, - ctxt: SyntaxContext, - applicability: &mut Applicability, - path: &str, -) -> String { - if let Some(last) = last_path_segment(ty_path).args - && let Some(iter_ty) = last.args.iter().find_map(|arg| match arg { - GenericArg::Type(ty) => Some(ty), - _ => None, - }) - { - format!( - "{path}::<{}>()", - snippet_with_context(cx, iter_ty.span, ctxt, "..", applicability).0 - ) - } else { - format!("{path}()") - } -} diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs deleted file mode 100644 index 1d6c4ce72e18..000000000000 --- a/clippy_lints/src/default_numeric_fallback.rs +++ /dev/null @@ -1,258 +0,0 @@ -use clippy_utils::diagnostics::span_lint_hir_and_then; -use clippy_utils::numeric_literal; -use clippy_utils::source::snippet_opt; -use rustc_ast::ast::{LitFloatType, LitIntType, LitKind}; -use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_expr, walk_stmt, Visitor}; -use rustc_hir::{Block, Body, ConstContext, Expr, ExprKind, FnRetTy, HirId, Lit, Stmt, StmtKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, FloatTy, IntTy, PolyFnSig, Ty}; -use rustc_session::declare_lint_pass; -use std::iter; - -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of unconstrained numeric literals which may cause default numeric fallback in type - /// inference. - /// - /// Default numeric fallback means that if numeric types have not yet been bound to concrete - /// types at the end of type inference, then integer type is bound to `i32`, and similarly - /// floating type is bound to `f64`. - /// - /// See [RFC0212](https://github.com/rust-lang/rfcs/blob/master/text/0212-restore-int-fallback.md) for more information about the fallback. - /// - /// ### Why is this bad? - /// For those who are very careful about types, default numeric fallback - /// can be a pitfall that cause unexpected runtime behavior. - /// - /// ### Known problems - /// This lint can only be allowed at the function level or above. - /// - /// ### Example - /// ```no_run - /// let i = 10; - /// let f = 1.23; - /// ``` - /// - /// Use instead: - /// ```no_run - /// let i = 10i32; - /// let f = 1.23f64; - /// ``` - #[clippy::version = "1.52.0"] - pub DEFAULT_NUMERIC_FALLBACK, - restriction, - "usage of unconstrained numeric literals which may cause default numeric fallback." -} - -declare_lint_pass!(DefaultNumericFallback => [DEFAULT_NUMERIC_FALLBACK]); - -impl<'tcx> LateLintPass<'tcx> for DefaultNumericFallback { - fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) { - let hir = cx.tcx.hir(); - let is_parent_const = matches!( - hir.body_const_context(hir.body_owner_def_id(body.id())), - Some(ConstContext::Const { inline: false } | ConstContext::Static(_)) - ); - let mut visitor = NumericFallbackVisitor::new(cx, is_parent_const); - visitor.visit_body(body); - } -} - -struct NumericFallbackVisitor<'a, 'tcx> { - /// Stack manages type bound of exprs. The top element holds current expr type. - ty_bounds: Vec, - - cx: &'a LateContext<'tcx>, -} - -impl<'a, 'tcx> NumericFallbackVisitor<'a, 'tcx> { - fn new(cx: &'a LateContext<'tcx>, is_parent_const: bool) -> Self { - Self { - ty_bounds: vec![if is_parent_const { - ExplicitTyBound(true) - } else { - ExplicitTyBound(false) - }], - cx, - } - } - - /// Check whether a passed literal has potential to cause fallback or not. - fn check_lit(&self, lit: &Lit, lit_ty: Ty<'tcx>, emit_hir_id: HirId) { - if !in_external_macro(self.cx.sess(), lit.span) - && matches!(self.ty_bounds.last(), Some(ExplicitTyBound(false))) - && matches!( - lit.node, - LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::Float(_, LitFloatType::Unsuffixed) - ) - { - 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 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_hir_and_then( - self.cx, - DEFAULT_NUMERIC_FALLBACK, - emit_hir_id, - lit.span, - "default numeric fallback might occur", - |diag| { - diag.span_suggestion(lit.span, "consider adding suffix", sugg, Applicability::MaybeIncorrect); - }, - ); - } - } -} - -impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - match &expr.kind { - ExprKind::Block( - Block { - stmts, expr: Some(_), .. - }, - _, - ) => { - if let Some(fn_sig) = self.cx.tcx.parent_hir_node(expr.hir_id).fn_sig() - && let FnRetTy::Return(_ty) = fn_sig.decl.output - { - // We cannot check the exact type since it's a `hir::Ty`` which does not implement `is_numeric` - self.ty_bounds.push(ExplicitTyBound(true)); - for stmt in *stmts { - self.visit_stmt(stmt); - } - self.ty_bounds.pop(); - // Ignore return expr since we know its type was inferred from return ty - return; - } - }, - - // Ignore return expr since we know its type was inferred from return ty - ExprKind::Ret(_) => return, - - ExprKind::Call(func, args) => { - if let Some(fn_sig) = fn_sig_opt(self.cx, func.hir_id) { - for (expr, bound) in iter::zip(*args, fn_sig.skip_binder().inputs()) { - // If is from macro, try to use last bound type (typically pushed when visiting stmt), - // otherwise push found arg type, then visit arg, - if expr.span.from_expansion() { - self.visit_expr(expr); - } else { - self.ty_bounds.push((*bound).into()); - self.visit_expr(expr); - self.ty_bounds.pop(); - } - } - return; - } - }, - - ExprKind::MethodCall(_, receiver, args, _) => { - if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) { - let fn_sig = self.cx.tcx.fn_sig(def_id).instantiate_identity().skip_binder(); - for (expr, bound) in iter::zip(iter::once(*receiver).chain(args.iter()), fn_sig.inputs()) { - self.ty_bounds.push((*bound).into()); - self.visit_expr(expr); - self.ty_bounds.pop(); - } - return; - } - }, - - ExprKind::Struct(_, fields, base) => { - let ty = self.cx.typeck_results().expr_ty(expr); - if let Some(adt_def) = ty.ty_adt_def() - && adt_def.is_struct() - && let Some(variant) = adt_def.variants().iter().next() - { - let fields_def = &variant.fields; - - // Push field type then visit each field expr. - for field in *fields { - let bound = fields_def.iter().find_map(|f_def| { - if f_def.ident(self.cx.tcx) == field.ident { - Some(self.cx.tcx.type_of(f_def.did).instantiate_identity()) - } else { - None - } - }); - self.ty_bounds.push(bound.into()); - self.visit_expr(field.expr); - self.ty_bounds.pop(); - } - - // Visit base with no bound. - if let Some(base) = base { - self.ty_bounds.push(ExplicitTyBound(false)); - self.visit_expr(base); - self.ty_bounds.pop(); - } - return; - } - }, - - ExprKind::Lit(lit) => { - let ty = self.cx.typeck_results().expr_ty(expr); - self.check_lit(lit, ty, expr.hir_id); - return; - }, - - _ => {}, - } - - walk_expr(self, expr); - } - - fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) { - match stmt.kind { - // we cannot check the exact type since it's a hir::Ty which does not implement `is_numeric` - StmtKind::Let(local) => self.ty_bounds.push(ExplicitTyBound(local.ty.is_some())), - - _ => self.ty_bounds.push(ExplicitTyBound(false)), - } - - walk_stmt(self, stmt); - self.ty_bounds.pop(); - } -} - -fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option> { - let node_ty = cx.typeck_results().node_type_opt(hir_id)?; - // We can't use `Ty::fn_sig` because it automatically performs args, this may result in FNs. - match node_ty.kind() { - ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(*def_id).instantiate_identity()), - ty::FnPtr(fn_sig) => Some(*fn_sig), - _ => None, - } -} - -/// Wrapper around a `bool` to make the meaning of the value clearer -#[derive(Debug, Clone, Copy)] -struct ExplicitTyBound(pub bool); - -impl<'tcx> From> for ExplicitTyBound { - fn from(v: Ty<'tcx>) -> Self { - Self(v.is_numeric()) - } -} - -impl<'tcx> From>> for ExplicitTyBound { - fn from(v: Option>) -> Self { - Self(v.map_or(false, Ty::is_numeric)) - } -} diff --git a/clippy_lints/src/default_union_representation.rs b/clippy_lints/src/default_union_representation.rs deleted file mode 100644 index 3f87ed8df2bf..000000000000 --- a/clippy_lints/src/default_union_representation.rs +++ /dev/null @@ -1,110 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_help; -use rustc_hir::{HirId, Item, ItemKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::layout::LayoutOf; -use rustc_middle::ty::{self, FieldDef, GenericArg, List}; -use rustc_session::declare_lint_pass; -use rustc_span::sym; - -declare_clippy_lint! { - /// ### What it does - /// Displays a warning when a union is declared with the default representation (without a `#[repr(C)]` attribute). - /// - /// ### Why is this bad? - /// Unions in Rust have unspecified layout by default, despite many people thinking that they - /// lay out each field at the start of the union (like C does). That is, there are no guarantees - /// about the offset of the fields for unions with multiple non-ZST fields without an explicitly - /// specified layout. These cases may lead to undefined behavior in unsafe blocks. - /// - /// ### Example - /// ```no_run - /// union Foo { - /// a: i32, - /// b: u32, - /// } - /// - /// fn main() { - /// let _x: u32 = unsafe { - /// Foo { a: 0_i32 }.b // Undefined behavior: `b` is allowed to be padding - /// }; - /// } - /// ``` - /// Use instead: - /// ```no_run - /// #[repr(C)] - /// union Foo { - /// a: i32, - /// b: u32, - /// } - /// - /// fn main() { - /// let _x: u32 = unsafe { - /// Foo { a: 0_i32 }.b // Now defined behavior, this is just an i32 -> u32 transmute - /// }; - /// } - /// ``` - #[clippy::version = "1.60.0"] - pub DEFAULT_UNION_REPRESENTATION, - restriction, - "unions without a `#[repr(C)]` attribute" -} -declare_lint_pass!(DefaultUnionRepresentation => [DEFAULT_UNION_REPRESENTATION]); - -impl<'tcx> LateLintPass<'tcx> for DefaultUnionRepresentation { - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { - if !item.span.from_expansion() - && is_union_with_two_non_zst_fields(cx, item) - && !has_c_repr_attr(cx, item.hir_id()) - { - span_lint_and_help( - cx, - DEFAULT_UNION_REPRESENTATION, - item.span, - "this union has the default representation", - None, - format!( - "consider annotating `{}` with `#[repr(C)]` to explicitly specify memory layout", - cx.tcx.def_path_str(item.owner_id) - ), - ); - } - } -} - -/// Returns true if the given item is a union with at least two non-ZST fields. -/// (ZST fields having an arbitrary offset is completely inconsequential, and -/// if there is only one field left after ignoring ZST fields then the offset -/// of that field does not matter either.) -fn is_union_with_two_non_zst_fields<'tcx>(cx: &LateContext<'tcx>, item: &Item<'tcx>) -> bool { - if let ItemKind::Union(..) = &item.kind - && let ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind() - { - adt_def.all_fields().filter(|f| !is_zst(cx, f, args)).count() >= 2 - } else { - false - } -} - -fn is_zst<'tcx>(cx: &LateContext<'tcx>, field: &FieldDef, args: &'tcx List>) -> bool { - let ty = field.ty(cx.tcx, args); - if let Ok(layout) = cx.layout_of(ty) { - layout.is_zst() - } else { - false - } -} - -fn has_c_repr_attr(cx: &LateContext<'_>, hir_id: HirId) -> bool { - cx.tcx.hir().attrs(hir_id).iter().any(|attr| { - if attr.has_name(sym::repr) { - if let Some(items) = attr.meta_item_list() { - for item in items { - if item.is_word() && matches!(item.name_or_empty(), sym::C) { - return true; - } - } - } - } - false - }) -} diff --git a/clippy_lints/src/deprecated_lints.rs b/clippy_lints/src/deprecated_lints.rs deleted file mode 100644 index 9aa5af3190fb..000000000000 --- a/clippy_lints/src/deprecated_lints.rs +++ /dev/null @@ -1,217 +0,0 @@ -// NOTE: Entries should be created with `cargo dev deprecate` - -/// This struct fakes the `Lint` declaration that is usually created by `declare_lint!`. This -/// enables the simple extraction of the metadata without changing the current deprecation -/// declaration. -pub struct ClippyDeprecatedLint { - #[allow(dead_code)] - pub desc: &'static str, -} - -#[macro_export] -macro_rules! declare_deprecated_lint { - { $(#[$attr:meta])* pub $name: ident, $reason: literal} => { - $(#[$attr])* - #[allow(dead_code)] - pub static $name: ClippyDeprecatedLint = ClippyDeprecatedLint { - desc: $reason - }; - } -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// This used to check for `assert!(a == b)` and recommend - /// replacement with `assert_eq!(a, b)`, but this is no longer needed after RFC 2011. - #[clippy::version = "pre 1.29.0"] - pub SHOULD_ASSERT_EQ, - "`assert!()` will be more flexible with RFC 2011" -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// This used to check for `Vec::extend`, which was slower than - /// `Vec::extend_from_slice`. Thanks to specialization, this is no longer true. - #[clippy::version = "pre 1.29.0"] - pub EXTEND_FROM_SLICE, - "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice" -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// `Range::step_by(0)` used to be linted since it's - /// an infinite iterator, which is better expressed by `iter::repeat`, - /// but the method has been removed for `Iterator::step_by` which panics - /// if given a zero - #[clippy::version = "pre 1.29.0"] - pub RANGE_STEP_BY_ZERO, - "`iterator.step_by(0)` panics nowadays" -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// This used to check for `Vec::as_slice`, which was unstable with good - /// stable alternatives. `Vec::as_slice` has now been stabilized. - #[clippy::version = "pre 1.29.0"] - pub UNSTABLE_AS_SLICE, - "`Vec::as_slice` has been stabilized in 1.7" -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// This used to check for `Vec::as_mut_slice`, which was unstable with good - /// stable alternatives. `Vec::as_mut_slice` has now been stabilized. - #[clippy::version = "pre 1.29.0"] - pub UNSTABLE_AS_MUT_SLICE, - "`Vec::as_mut_slice` has been stabilized in 1.7" -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// This lint should never have applied to non-pointer types, as transmuting - /// between non-pointer types of differing alignment is well-defined behavior (it's semantically - /// equivalent to a memcpy). This lint has thus been refactored into two separate lints: - /// cast_ptr_alignment and transmute_ptr_to_ptr. - #[clippy::version = "pre 1.29.0"] - pub MISALIGNED_TRANSMUTE, - "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr" -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// This lint is too subjective, not having a good reason for being in clippy. - /// Additionally, compound assignment operators may be overloaded separately from their non-assigning - /// counterparts, so this lint may suggest a change in behavior or the code may not compile. - #[clippy::version = "1.30.0"] - pub ASSIGN_OPS, - "using compound assignment operators (e.g., `+=`) is harmless" -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// The original rule will only lint for `if let`. After - /// making it support to lint `match`, naming as `if let` is not suitable for it. - /// So, this lint is deprecated. - #[clippy::version = "pre 1.29.0"] - pub IF_LET_REDUNDANT_PATTERN_MATCHING, - "this lint has been changed to redundant_pattern_matching" -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// This lint used to suggest replacing `let mut vec = - /// Vec::with_capacity(n); vec.set_len(n);` with `let vec = vec![0; n];`. The - /// replacement has very different performance characteristics so the lint is - /// deprecated. - #[clippy::version = "pre 1.29.0"] - pub UNSAFE_VECTOR_INITIALIZATION, - "the replacement suggested by this lint had substantially different behavior" -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// This lint has been superseded by #[must_use] in rustc. - #[clippy::version = "1.39.0"] - pub UNUSED_COLLECT, - "`collect` has been marked as #[must_use] in rustc and that covers all cases of this lint" -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// Associated-constants are now preferred. - #[clippy::version = "1.44.0"] - pub REPLACE_CONSTS, - "associated-constants `MIN`/`MAX` of integers are preferred to `{min,max}_value()` and module constants" -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// The regex! macro does not exist anymore. - #[clippy::version = "1.47.0"] - pub REGEX_MACRO, - "the regex! macro has been removed from the regex crate in 2018" -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// This lint has been replaced by `manual_find_map`, a - /// more specific lint. - #[clippy::version = "1.51.0"] - pub FIND_MAP, - "this lint has been replaced by `manual_find_map`, a more specific lint" -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// This lint has been replaced by `manual_filter_map`, a - /// more specific lint. - #[clippy::version = "1.53.0"] - pub FILTER_MAP, - "this lint has been replaced by `manual_filter_map`, a more specific lint" -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// The `avoid_breaking_exported_api` config option was added, which - /// enables the `enum_variant_names` lint for public items. - #[clippy::version = "1.54.0"] - pub PUB_ENUM_VARIANT_NAMES, - "set the `avoid-breaking-exported-api` config option to `false` to enable the `enum_variant_names` lint for public items" -} - -declare_deprecated_lint! { - /// ### What it does - /// Nothing. This lint has been deprecated. - /// - /// ### Deprecation reason - /// The `avoid_breaking_exported_api` config option was added, which - /// enables the `wrong_self_conversion` lint for public items. - #[clippy::version = "1.54.0"] - pub WRONG_PUB_SELF_CONVENTION, - "set the `avoid-breaking-exported-api` config option to `false` to enable the `wrong_self_convention` lint for public items" -} diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs deleted file mode 100644 index b936b28470b5..000000000000 --- a/clippy_lints/src/dereference.rs +++ /dev/null @@ -1,1191 +0,0 @@ -use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then}; -use clippy_utils::source::{snippet_with_applicability, snippet_with_context}; -use clippy_utils::sugg::has_enclosing_paren; -use clippy_utils::ty::{implements_trait, is_manually_drop, peel_mid_ty_refs}; -use clippy_utils::{expr_use_ctxt, get_parent_expr, is_lint_allowed, path_to_local, DefinedTy, ExprUseNode}; -use core::mem; -use rustc_ast::util::parser::{PREC_POSTFIX, PREC_PREFIX}; -use rustc_data_structures::fx::FxIndexMap; -use rustc_errors::Applicability; -use rustc_hir::intravisit::{walk_ty, Visitor}; -use rustc_hir::{ - self as hir, BindingMode, Body, BodyId, BorrowKind, Expr, ExprKind, HirId, MatchSource, Mutability, Node, Pat, - PatKind, Path, QPath, TyKind, UnOp, -}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability}; -use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, TypeVisitableExt, TypeckResults}; -use rustc_session::impl_lint_pass; -use rustc_span::symbol::sym; -use rustc_span::{Span, Symbol}; - -declare_clippy_lint! { - /// ### What it does - /// Checks for explicit `deref()` or `deref_mut()` method calls. - /// - /// ### Why is this bad? - /// Dereferencing by `&*x` or `&mut *x` is clearer and more concise, - /// when not part of a method chain. - /// - /// ### Example - /// ```no_run - /// use std::ops::Deref; - /// let a: &mut String = &mut String::from("foo"); - /// let b: &str = a.deref(); - /// ``` - /// - /// Use instead: - /// ```no_run - /// let a: &mut String = &mut String::from("foo"); - /// let b = &*a; - /// ``` - /// - /// This lint excludes all of: - /// ```rust,ignore - /// let _ = d.unwrap().deref(); - /// let _ = Foo::deref(&foo); - /// let _ = ::deref(&foo); - /// ``` - #[clippy::version = "1.44.0"] - pub EXPLICIT_DEREF_METHODS, - pedantic, - "Explicit use of deref or deref_mut method while not in a method chain." -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for address of operations (`&`) that are going to - /// be dereferenced immediately by the compiler. - /// - /// ### Why is this bad? - /// Suggests that the receiver of the expression borrows - /// the expression. - /// - /// ### Known problems - /// The lint cannot tell when the implementation of a trait - /// for `&T` and `T` do different things. Removing a borrow - /// in such a case can change the semantics of the code. - /// - /// ### Example - /// ```no_run - /// fn fun(_a: &i32) {} - /// - /// let x: &i32 = &&&&&&5; - /// fun(&x); - /// ``` - /// - /// Use instead: - /// ```no_run - /// # fn fun(_a: &i32) {} - /// let x: &i32 = &5; - /// fun(x); - /// ``` - #[clippy::version = "pre 1.29.0"] - pub NEEDLESS_BORROW, - style, - "taking a reference that is going to be automatically dereferenced" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for `ref` bindings which create a reference to a reference. - /// - /// ### Why is this bad? - /// The address-of operator at the use site is clearer about the need for a reference. - /// - /// ### Example - /// ```no_run - /// let x = Some(""); - /// if let Some(ref x) = x { - /// // use `x` here - /// } - /// ``` - /// - /// Use instead: - /// ```no_run - /// let x = Some(""); - /// if let Some(x) = x { - /// // use `&x` here - /// } - /// ``` - #[clippy::version = "1.54.0"] - pub REF_BINDING_TO_REFERENCE, - pedantic, - "`ref` binding to a reference" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for dereferencing expressions which would be covered by auto-deref. - /// - /// ### Why is this bad? - /// This unnecessarily complicates the code. - /// - /// ### Example - /// ```no_run - /// let x = String::new(); - /// let y: &str = &*x; - /// ``` - /// Use instead: - /// ```no_run - /// let x = String::new(); - /// let y: &str = &x; - /// ``` - #[clippy::version = "1.64.0"] - pub EXPLICIT_AUTO_DEREF, - complexity, - "dereferencing when the compiler would automatically dereference" -} - -impl_lint_pass!(Dereferencing<'_> => [ - EXPLICIT_DEREF_METHODS, - NEEDLESS_BORROW, - REF_BINDING_TO_REFERENCE, - EXPLICIT_AUTO_DEREF, -]); - -#[derive(Default)] -pub struct Dereferencing<'tcx> { - state: Option<(State, StateData<'tcx>)>, - - // While parsing a `deref` method call in ufcs form, the path to the function is itself an - // expression. This is to store the id of that expression so it can be skipped when - // `check_expr` is called for it. - skip_expr: Option, - - /// The body the first local was found in. Used to emit lints when the traversal of the body has - /// been finished. Note we can't lint at the end of every body as they can be nested within each - /// other. - current_body: Option, - - /// The list of locals currently being checked by the lint. - /// If the value is `None`, then the binding has been seen as a ref pattern, but is not linted. - /// This is needed for or patterns where one of the branches can be linted, but another can not - /// be. - /// - /// e.g. `m!(x) | Foo::Bar(ref x)` - ref_locals: FxIndexMap>, -} - -#[derive(Debug)] -struct StateData<'tcx> { - first_expr: &'tcx Expr<'tcx>, - adjusted_ty: Ty<'tcx>, -} - -struct DerefedBorrow { - count: usize, - msg: &'static str, - stability: TyCoercionStability, - for_field_access: Option, -} - -enum State { - // Any number of deref method calls. - DerefMethod { - // The number of calls in a sequence which changed the referenced type - ty_changed_count: usize, - is_ufcs: bool, - /// The required mutability - mutbl: Mutability, - }, - DerefedBorrow(DerefedBorrow), - ExplicitDeref { - mutability: Option, - }, - ExplicitDerefField { - name: Symbol, - derefs_manually_drop: bool, - }, - Reborrow { - mutability: Mutability, - }, - Borrow { - mutability: Mutability, - }, -} - -// A reference operation considered by this lint pass -enum RefOp { - Method { mutbl: Mutability, is_ufcs: bool }, - Deref, - AddrOf(Mutability), -} - -struct RefPat { - /// Whether every usage of the binding is dereferenced. - always_deref: bool, - /// The spans of all the ref bindings for this local. - spans: Vec, - /// The applicability of this suggestion. - app: Applicability, - /// All the replacements which need to be made. - replacements: Vec<(Span, String)>, - /// The [`HirId`] that the lint should be emitted at. - hir_id: HirId, -} - -impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> { - #[expect(clippy::too_many_lines)] - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - // Skip path expressions from deref calls. e.g. `Deref::deref(e)` - if Some(expr.hir_id) == self.skip_expr.take() { - return; - } - - if let Some(local) = path_to_local(expr) { - self.check_local_usage(cx, expr, local); - } - - // Stop processing sub expressions when a macro call is seen - if expr.span.from_expansion() { - if let Some((state, data)) = self.state.take() { - report(cx, expr, state, data, cx.typeck_results()); - } - return; - } - - let typeck = cx.typeck_results(); - let Some((kind, sub_expr)) = try_parse_ref_op(cx.tcx, typeck, expr) else { - // The whole chain of reference operations has been seen - if let Some((state, data)) = self.state.take() { - report(cx, expr, state, data, typeck); - } - return; - }; - - match (self.state.take(), kind) { - (None, kind) => { - let expr_ty = typeck.expr_ty(expr); - let use_cx = expr_use_ctxt(cx, expr); - let adjusted_ty = match &use_cx { - Some(use_cx) => match use_cx.adjustments { - [.., a] => a.target, - _ => expr_ty, - }, - _ => typeck.expr_ty_adjusted(expr), - }; - - match (use_cx, kind) { - (Some(use_cx), RefOp::Deref) => { - let sub_ty = typeck.expr_ty(sub_expr); - if let ExprUseNode::FieldAccess(name) = use_cx.node - && !use_cx.moved_before_use - && !ty_contains_field(sub_ty, name.name) - { - self.state = Some(( - State::ExplicitDerefField { - name: name.name, - derefs_manually_drop: is_manually_drop(sub_ty), - }, - StateData { - first_expr: expr, - adjusted_ty, - }, - )); - } else if sub_ty.is_ref() - // Linting method receivers would require verifying that name lookup - // would resolve the same way. This is complicated by trait methods. - && !use_cx.node.is_recv() - && let Some(ty) = use_cx.node.defined_ty(cx) - && TyCoercionStability::for_defined_ty(cx, ty, use_cx.node.is_return()).is_deref_stable() - { - self.state = Some(( - State::ExplicitDeref { mutability: None }, - StateData { - first_expr: expr, - adjusted_ty, - }, - )); - } - }, - (_, RefOp::Method { mutbl, is_ufcs }) - if !is_lint_allowed(cx, EXPLICIT_DEREF_METHODS, expr.hir_id) - // Allow explicit deref in method chains. e.g. `foo.deref().bar()` - && (is_ufcs || !in_postfix_position(cx, expr)) => - { - let ty_changed_count = usize::from(!deref_method_same_type(expr_ty, typeck.expr_ty(sub_expr))); - self.state = Some(( - State::DerefMethod { - ty_changed_count, - is_ufcs, - mutbl, - }, - StateData { - first_expr: expr, - adjusted_ty, - }, - )); - }, - (Some(use_cx), RefOp::AddrOf(mutability)) => { - // Find the number of times the borrow is auto-derefed. - let mut iter = use_cx.adjustments.iter(); - let mut deref_count = 0usize; - let next_adjust = loop { - match iter.next() { - Some(adjust) => { - if !matches!(adjust.kind, Adjust::Deref(_)) { - break Some(adjust); - } else if !adjust.target.is_ref() { - deref_count += 1; - break iter.next(); - } - deref_count += 1; - }, - None => break None, - }; - }; - - let stability = use_cx.node.defined_ty(cx).map_or(TyCoercionStability::None, |ty| { - TyCoercionStability::for_defined_ty(cx, ty, use_cx.node.is_return()) - }); - let can_auto_borrow = match use_cx.node { - ExprUseNode::FieldAccess(_) - if !use_cx.moved_before_use && matches!(sub_expr.kind, ExprKind::Field(..)) => - { - // `DerefMut` will not be automatically applied to `ManuallyDrop<_>` - // field expressions when the base type is a union and the parent - // expression is also a field access. - // - // e.g. `&mut x.y.z` where `x` is a union, and accessing `z` requires a - // deref through `ManuallyDrop<_>` will not compile. - !adjust_derefs_manually_drop(use_cx.adjustments, expr_ty) - }, - ExprUseNode::Callee | ExprUseNode::FieldAccess(_) => true, - ExprUseNode::MethodArg(hir_id, _, 0) if !use_cx.moved_before_use => { - // Check for calls to trait methods where the trait is implemented - // on a reference. - // Two cases need to be handled: - // * `self` methods on `&T` will never have auto-borrow - // * `&self` methods on `&T` can have auto-borrow, but `&self` methods on `T` will take - // priority. - if let Some(fn_id) = typeck.type_dependent_def_id(hir_id) - && let Some(trait_id) = cx.tcx.trait_of_item(fn_id) - && let arg_ty = cx - .tcx - .erase_regions(use_cx.adjustments.last().map_or(expr_ty, |a| a.target)) - && let ty::Ref(_, sub_ty, _) = *arg_ty.kind() - && let args = - typeck.node_args_opt(hir_id).map(|args| &args[1..]).unwrap_or_default() - && let impl_ty = - if cx.tcx.fn_sig(fn_id).instantiate_identity().skip_binder().inputs()[0] - .is_ref() - { - // Trait methods taking `&self` - sub_ty - } else { - // Trait methods taking `self` - arg_ty - } - && impl_ty.is_ref() - && implements_trait( - cx, - impl_ty, - trait_id, - &args[..cx.tcx.generics_of(trait_id).params.len() - 1], - ) - { - false - } else { - true - } - }, - _ => false, - }; - - let deref_msg = - "this expression creates a reference which is immediately dereferenced by the compiler"; - let borrow_msg = "this expression borrows a value the compiler would automatically borrow"; - - // Determine the required number of references before any can be removed. In all cases the - // reference made by the current expression will be removed. After that there are four cases to - // handle. - // - // 1. Auto-borrow will trigger in the current position, so no further references are required. - // 2. Auto-deref ends at a reference, or the underlying type, so one extra needs to be left to - // handle the automatically inserted re-borrow. - // 3. Auto-deref hits a user-defined `Deref` impl, so at least one reference needs to exist to - // start auto-deref. - // 4. If the chain of non-user-defined derefs ends with a mutable re-borrow, and re-borrow - // adjustments will not be inserted automatically, then leave one further reference to avoid - // moving a mutable borrow. e.g. - // - // ```rust - // fn foo(x: &mut Option<&mut T>, y: &mut T) { - // let x = match x { - // // Removing the borrow will cause `x` to be moved - // Some(x) => &mut *x, - // None => y - // }; - // } - // ``` - let (required_refs, msg) = if can_auto_borrow { - (1, if deref_count == 1 { borrow_msg } else { deref_msg }) - } else if let Some(&Adjustment { - kind: Adjust::Borrow(AutoBorrow::Ref(_, mutability)), - .. - }) = next_adjust - && matches!(mutability, AutoBorrowMutability::Mut { .. }) - && !stability.is_reborrow_stable() - { - (3, deref_msg) - } else { - (2, deref_msg) - }; - - if deref_count >= required_refs { - self.state = Some(( - State::DerefedBorrow(DerefedBorrow { - // One of the required refs is for the current borrow expression, the remaining ones - // can't be removed without breaking the code. See earlier comment. - count: deref_count - required_refs, - msg, - stability, - for_field_access: if let ExprUseNode::FieldAccess(name) = use_cx.node - && !use_cx.moved_before_use - { - Some(name.name) - } else { - None - }, - }), - StateData { - first_expr: expr, - adjusted_ty: use_cx.adjustments.last().map_or(expr_ty, |a| a.target), - }, - )); - } else if stability.is_deref_stable() - // Auto-deref doesn't combine with other adjustments - && next_adjust.map_or(true, |a| matches!(a.kind, Adjust::Deref(_) | Adjust::Borrow(_))) - && iter.all(|a| matches!(a.kind, Adjust::Deref(_) | Adjust::Borrow(_))) - { - self.state = Some(( - State::Borrow { mutability }, - StateData { - first_expr: expr, - adjusted_ty: use_cx.adjustments.last().map_or(expr_ty, |a| a.target), - }, - )); - } - }, - (None, _) | (_, RefOp::Method { .. }) => (), - } - }, - ( - Some(( - State::DerefMethod { - mutbl, - ty_changed_count, - .. - }, - data, - )), - RefOp::Method { is_ufcs, .. }, - ) => { - self.state = Some(( - State::DerefMethod { - ty_changed_count: if deref_method_same_type(typeck.expr_ty(expr), typeck.expr_ty(sub_expr)) { - ty_changed_count - } else { - ty_changed_count + 1 - }, - is_ufcs, - mutbl, - }, - data, - )); - }, - (Some((State::DerefedBorrow(state), data)), RefOp::AddrOf(_)) if state.count != 0 => { - self.state = Some(( - State::DerefedBorrow(DerefedBorrow { - count: state.count - 1, - ..state - }), - data, - )); - }, - (Some((State::DerefedBorrow(state), data)), RefOp::AddrOf(mutability)) => { - let adjusted_ty = data.adjusted_ty; - let stability = state.stability; - report(cx, expr, State::DerefedBorrow(state), data, typeck); - if stability.is_deref_stable() { - self.state = Some(( - State::Borrow { mutability }, - StateData { - first_expr: expr, - adjusted_ty, - }, - )); - } - }, - (Some((State::DerefedBorrow(state), data)), RefOp::Deref) => { - let adjusted_ty = data.adjusted_ty; - let stability = state.stability; - let for_field_access = state.for_field_access; - report(cx, expr, State::DerefedBorrow(state), data, typeck); - if let Some(name) = for_field_access - && let sub_expr_ty = typeck.expr_ty(sub_expr) - && !ty_contains_field(sub_expr_ty, name) - { - self.state = Some(( - State::ExplicitDerefField { - name, - derefs_manually_drop: is_manually_drop(sub_expr_ty), - }, - StateData { - first_expr: expr, - adjusted_ty, - }, - )); - } else if stability.is_deref_stable() - && let Some(parent) = get_parent_expr(cx, expr) - { - self.state = Some(( - State::ExplicitDeref { mutability: None }, - StateData { - first_expr: parent, - adjusted_ty, - }, - )); - } - }, - - (Some((State::Borrow { mutability }, data)), RefOp::Deref) => { - if typeck.expr_ty(sub_expr).is_ref() { - self.state = Some((State::Reborrow { mutability }, data)); - } else { - self.state = Some(( - State::ExplicitDeref { - mutability: Some(mutability), - }, - data, - )); - } - }, - (Some((State::Reborrow { mutability }, data)), RefOp::Deref) => { - self.state = Some(( - State::ExplicitDeref { - mutability: Some(mutability), - }, - data, - )); - }, - (state @ Some((State::ExplicitDeref { .. }, _)), RefOp::Deref) => { - self.state = state; - }, - ( - Some(( - State::ExplicitDerefField { - name, - derefs_manually_drop, - }, - data, - )), - RefOp::Deref, - ) if let sub_expr_ty = typeck.expr_ty(sub_expr) - && !ty_contains_field(sub_expr_ty, name) => - { - self.state = Some(( - State::ExplicitDerefField { - name, - derefs_manually_drop: derefs_manually_drop || is_manually_drop(sub_expr_ty), - }, - data, - )); - }, - - (Some((state, data)), _) => report(cx, expr, state, data, typeck), - } - } - - fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { - if let PatKind::Binding(BindingMode::REF, id, name, _) = pat.kind { - if let Some(opt_prev_pat) = self.ref_locals.get_mut(&id) { - // This binding id has been seen before. Add this pattern to the list of changes. - if let Some(prev_pat) = opt_prev_pat { - if pat.span.from_expansion() { - // Doesn't match the context of the previous pattern. Can't lint here. - *opt_prev_pat = None; - } else { - prev_pat.spans.push(pat.span); - prev_pat.replacements.push(( - pat.span, - snippet_with_context(cx, name.span, pat.span.ctxt(), "..", &mut prev_pat.app) - .0 - .into(), - )); - } - } - return; - } - - if !pat.span.from_expansion() - && let ty::Ref(_, tam, _) = *cx.typeck_results().pat_ty(pat).kind() - // only lint immutable refs, because borrowed `&mut T` cannot be moved out - && let ty::Ref(_, _, Mutability::Not) = *tam.kind() - { - let mut app = Applicability::MachineApplicable; - let snip = snippet_with_context(cx, name.span, pat.span.ctxt(), "..", &mut app).0; - self.current_body = self.current_body.or(cx.enclosing_body); - self.ref_locals.insert( - id, - Some(RefPat { - always_deref: true, - spans: vec![pat.span], - app, - replacements: vec![(pat.span, snip.into())], - hir_id: pat.hir_id, - }), - ); - } - } - } - - fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) { - if Some(body.id()) == self.current_body { - for pat in self.ref_locals.drain(..).filter_map(|(_, x)| x) { - let replacements = pat.replacements; - let app = pat.app; - let lint = if pat.always_deref { - NEEDLESS_BORROW - } else { - REF_BINDING_TO_REFERENCE - }; - span_lint_hir_and_then( - cx, - lint, - pat.hir_id, - pat.spans, - "this pattern creates a reference to a reference", - |diag| { - diag.multipart_suggestion("try", replacements, app); - }, - ); - } - self.current_body = None; - } - } -} - -fn try_parse_ref_op<'tcx>( - tcx: TyCtxt<'tcx>, - typeck: &'tcx TypeckResults<'_>, - expr: &'tcx Expr<'_>, -) -> Option<(RefOp, &'tcx Expr<'tcx>)> { - let (is_ufcs, def_id, arg) = match expr.kind { - ExprKind::MethodCall(_, arg, [], _) => (false, typeck.type_dependent_def_id(expr.hir_id)?, arg), - ExprKind::Call( - Expr { - kind: ExprKind::Path(path), - hir_id, - .. - }, - [arg], - ) => (true, typeck.qpath_res(path, *hir_id).opt_def_id()?, arg), - ExprKind::Unary(UnOp::Deref, sub_expr) if !typeck.expr_ty(sub_expr).is_unsafe_ptr() => { - return Some((RefOp::Deref, sub_expr)); - }, - ExprKind::AddrOf(BorrowKind::Ref, mutability, sub_expr) => return Some((RefOp::AddrOf(mutability), sub_expr)), - _ => return None, - }; - if tcx.is_diagnostic_item(sym::deref_method, def_id) { - Some(( - RefOp::Method { - mutbl: Mutability::Not, - is_ufcs, - }, - arg, - )) - } else if tcx.trait_of_item(def_id)? == tcx.lang_items().deref_mut_trait()? { - Some(( - RefOp::Method { - mutbl: Mutability::Mut, - is_ufcs, - }, - arg, - )) - } else { - None - } -} - -// Checks if the adjustments contains a deref of `ManuallyDrop<_>` -fn adjust_derefs_manually_drop<'tcx>(adjustments: &'tcx [Adjustment<'tcx>], mut ty: Ty<'tcx>) -> bool { - adjustments.iter().any(|a| { - let ty = mem::replace(&mut ty, a.target); - matches!(a.kind, Adjust::Deref(Some(ref op)) if op.mutbl == Mutability::Mut) && is_manually_drop(ty) - }) -} - -// Checks whether the type for a deref call actually changed the type, not just the mutability of -// the reference. -fn deref_method_same_type<'tcx>(result_ty: Ty<'tcx>, arg_ty: Ty<'tcx>) -> bool { - match (result_ty.kind(), arg_ty.kind()) { - (ty::Ref(_, result_ty, _), ty::Ref(_, arg_ty, _)) => result_ty == arg_ty, - - // The result type for a deref method is always a reference - // Not matching the previous pattern means the argument type is not a reference - // This means that the type did change - _ => false, - } -} - -fn in_postfix_position<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> bool { - if let Some(parent) = get_parent_expr(cx, e) - && parent.span.eq_ctxt(e.span) - { - match parent.kind { - ExprKind::Call(child, _) | ExprKind::MethodCall(_, child, _, _) | ExprKind::Index(child, _, _) - if child.hir_id == e.hir_id => - { - true - }, - ExprKind::Match(.., MatchSource::TryDesugar(_) | MatchSource::AwaitDesugar) | ExprKind::Field(_, _) => true, - _ => false, - } - } else { - false - } -} - -#[derive(Clone, Copy)] -enum TyCoercionStability { - Deref, - Reborrow, - None, -} -impl TyCoercionStability { - fn is_deref_stable(self) -> bool { - matches!(self, Self::Deref) - } - - fn is_reborrow_stable(self) -> bool { - matches!(self, Self::Deref | Self::Reborrow) - } - - fn for_defined_ty<'tcx>(cx: &LateContext<'tcx>, ty: DefinedTy<'tcx>, for_return: bool) -> Self { - match ty { - DefinedTy::Hir(ty) => Self::for_hir_ty(ty), - DefinedTy::Mir(ty) => Self::for_mir_ty( - cx.tcx, - ty.param_env, - cx.tcx.instantiate_bound_regions_with_erased(ty.value), - for_return, - ), - } - } - - // Checks the stability of type coercions when assigned to a binding with the given explicit type. - // - // e.g. - // let x = Box::new(Box::new(0u32)); - // let y1: &Box<_> = x.deref(); - // let y2: &Box<_> = &x; - // - // Here `y1` and `y2` would resolve to different types, so the type `&Box<_>` is not stable when - // switching to auto-dereferencing. - fn for_hir_ty<'tcx>(ty: &'tcx hir::Ty<'tcx>) -> Self { - let TyKind::Ref(_, ty) = &ty.kind else { - return Self::None; - }; - let mut ty = ty; - - loop { - break match ty.ty.kind { - TyKind::Ref(_, ref ref_ty) => { - ty = ref_ty; - continue; - }, - TyKind::Path( - QPath::TypeRelative(_, path) - | QPath::Resolved( - _, - Path { - segments: [.., path], .. - }, - ), - ) => { - if let Some(args) = path.args - && args.args.iter().any(|arg| match arg { - hir::GenericArg::Infer(_) => true, - hir::GenericArg::Type(ty) => ty_contains_infer(ty), - _ => false, - }) - { - Self::Reborrow - } else { - Self::Deref - } - }, - TyKind::Slice(_) - | TyKind::Array(..) - | TyKind::Ptr(_) - | TyKind::BareFn(_) - | TyKind::Pat(..) - | TyKind::Never - | TyKind::Tup(_) - | TyKind::Path(_) => Self::Deref, - TyKind::OpaqueDef(..) - | TyKind::Infer - | TyKind::Typeof(..) - | TyKind::TraitObject(..) - | TyKind::InferDelegation(..) - | TyKind::AnonAdt(..) - | TyKind::Err(_) => Self::Reborrow, - }; - } - } - - fn for_mir_ty<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, for_return: bool) -> Self { - let ty::Ref(_, mut ty, _) = *ty.kind() else { - return Self::None; - }; - - ty = tcx.try_normalize_erasing_regions(param_env, ty).unwrap_or(ty); - loop { - break match *ty.kind() { - ty::Ref(_, ref_ty, _) => { - ty = ref_ty; - continue; - }, - ty::Param(_) if for_return => Self::Deref, - ty::Alias(ty::Weak | ty::Inherent, _) => unreachable!("should have been normalized away above"), - ty::Alias(ty::Projection, _) if !for_return && ty.has_non_region_param() => Self::Reborrow, - ty::Infer(_) - | ty::Error(_) - | ty::Bound(..) - | ty::Alias(ty::Opaque, ..) - | ty::Placeholder(_) - | ty::Dynamic(..) - | ty::Param(_) => Self::Reborrow, - ty::Adt(_, args) - if ty.has_placeholders() - || ty.has_opaque_types() - || (!for_return && args.has_non_region_param()) => - { - Self::Reborrow - }, - ty::Bool - | ty::Char - | ty::Int(_) - | ty::Uint(_) - | ty::Array(..) - | ty::Pat(..) - | ty::Float(_) - | ty::RawPtr(..) - | ty::FnPtr(_) - | ty::Str - | ty::Slice(..) - | ty::Adt(..) - | ty::Foreign(_) - | ty::FnDef(..) - | ty::Coroutine(..) - | ty::CoroutineWitness(..) - | ty::Closure(..) - | ty::CoroutineClosure(..) - | ty::Never - | ty::Tuple(_) - | ty::Alias(ty::Projection, _) => Self::Deref, - }; - } - } -} - -// Checks whether a type is inferred at some point. -// e.g. `_`, `Box<_>`, `[_]` -fn ty_contains_infer(ty: &hir::Ty<'_>) -> bool { - struct V(bool); - impl Visitor<'_> for V { - fn visit_ty(&mut self, ty: &hir::Ty<'_>) { - if self.0 - || matches!( - ty.kind, - TyKind::OpaqueDef(..) | TyKind::Infer | TyKind::Typeof(_) | TyKind::Err(_) - ) - { - self.0 = true; - } else { - walk_ty(self, ty); - } - } - - fn visit_generic_arg(&mut self, arg: &hir::GenericArg<'_>) { - if self.0 || matches!(arg, hir::GenericArg::Infer(_)) { - self.0 = true; - } else if let hir::GenericArg::Type(ty) = arg { - self.visit_ty(ty); - } - } - } - let mut v = V(false); - v.visit_ty(ty); - v.0 -} - -fn ty_contains_field(ty: Ty<'_>, name: Symbol) -> bool { - if let ty::Adt(adt, _) = *ty.kind() { - adt.is_struct() && adt.all_fields().any(|f| f.name == name) - } else { - false - } -} - -#[expect(clippy::needless_pass_by_value, clippy::too_many_lines)] -fn report<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx Expr<'_>, - state: State, - data: StateData<'tcx>, - typeck: &'tcx TypeckResults<'tcx>, -) { - match state { - State::DerefMethod { - ty_changed_count, - is_ufcs, - mutbl, - } => { - let mut app = Applicability::MachineApplicable; - let (expr_str, _expr_is_macro_call) = - snippet_with_context(cx, expr.span, data.first_expr.span.ctxt(), "..", &mut app); - let ty = typeck.expr_ty(expr); - let (_, ref_count) = peel_mid_ty_refs(ty); - let deref_str = if ty_changed_count >= ref_count && ref_count != 0 { - // a deref call changing &T -> &U requires two deref operators the first time - // this occurs. One to remove the reference, a second to call the deref impl. - "*".repeat(ty_changed_count + 1) - } else { - "*".repeat(ty_changed_count) - }; - let addr_of_str = if ty_changed_count < ref_count { - // Check if a reborrow from &mut T -> &T is required. - if mutbl == Mutability::Not && matches!(ty.kind(), ty::Ref(_, _, Mutability::Mut)) { - "&*" - } else { - "" - } - } else if mutbl == Mutability::Mut { - "&mut " - } else { - "&" - }; - - // expr_str (the suggestion) is never shown if is_final_ufcs is true, since it's - // `expr.kind == ExprKind::Call`. Therefore, this is, afaik, always unnecessary. - /* - expr_str = if !expr_is_macro_call && is_final_ufcs && expr.precedence().order() < PREC_PREFIX { - Cow::Owned(format!("({expr_str})")) - } else { - expr_str - }; - */ - - // Fix #10850, do not lint if it's `Foo::deref` instead of `foo.deref()`. - if is_ufcs { - return; - } - - span_lint_and_sugg( - cx, - EXPLICIT_DEREF_METHODS, - data.first_expr.span, - match mutbl { - Mutability::Not => "explicit `deref` method call", - Mutability::Mut => "explicit `deref_mut` method call", - }, - "try", - format!("{addr_of_str}{deref_str}{expr_str}"), - app, - ); - }, - State::DerefedBorrow(state) => { - let mut app = Applicability::MachineApplicable; - let (snip, snip_is_macro) = - snippet_with_context(cx, expr.span, data.first_expr.span.ctxt(), "..", &mut app); - span_lint_hir_and_then( - cx, - NEEDLESS_BORROW, - data.first_expr.hir_id, - data.first_expr.span, - state.msg, - |diag| { - let (precedence, calls_field) = match cx.tcx.parent_hir_node(data.first_expr.hir_id) { - Node::Expr(e) => match e.kind { - ExprKind::Call(callee, _) if callee.hir_id != data.first_expr.hir_id => (0, false), - ExprKind::Call(..) => (PREC_POSTFIX, matches!(expr.kind, ExprKind::Field(..))), - _ => (e.precedence().order(), false), - }, - _ => (0, false), - }; - let is_in_tuple = matches!( - get_parent_expr(cx, data.first_expr), - Some(Expr { - kind: ExprKind::Tup(..), - .. - }) - ); - - let sugg = if !snip_is_macro - && (calls_field || expr.precedence().order() < precedence) - && !has_enclosing_paren(&snip) - && !is_in_tuple - { - format!("({snip})") - } else { - snip.into() - }; - diag.span_suggestion(data.first_expr.span, "change this to", sugg, app); - }, - ); - }, - State::ExplicitDeref { mutability } => { - if matches!( - expr.kind, - ExprKind::Block(..) - | ExprKind::ConstBlock(_) - | ExprKind::If(..) - | ExprKind::Loop(..) - | ExprKind::Match(..) - ) && let ty::Ref(_, ty, _) = data.adjusted_ty.kind() - && ty.is_sized(cx.tcx, cx.param_env) - { - // Rustc bug: auto deref doesn't work on block expression when targeting sized types. - return; - } - - let (prefix, precedence) = if let Some(mutability) = mutability - && !typeck.expr_ty(expr).is_ref() - { - let prefix = match mutability { - Mutability::Not => "&", - Mutability::Mut => "&mut ", - }; - (prefix, PREC_PREFIX) - } else { - ("", 0) - }; - span_lint_hir_and_then( - cx, - EXPLICIT_AUTO_DEREF, - data.first_expr.hir_id, - data.first_expr.span, - "deref which would be done by auto-deref", - |diag| { - let mut app = Applicability::MachineApplicable; - let (snip, snip_is_macro) = - snippet_with_context(cx, expr.span, data.first_expr.span.ctxt(), "..", &mut app); - let sugg = - if !snip_is_macro && expr.precedence().order() < precedence && !has_enclosing_paren(&snip) { - format!("{prefix}({snip})") - } else { - format!("{prefix}{snip}") - }; - diag.span_suggestion(data.first_expr.span, "try", sugg, app); - }, - ); - }, - State::ExplicitDerefField { - derefs_manually_drop, .. - } => { - let (snip_span, needs_parens) = if matches!(expr.kind, ExprKind::Field(..)) - && (derefs_manually_drop - || adjust_derefs_manually_drop( - typeck.expr_adjustments(data.first_expr), - typeck.expr_ty(data.first_expr), - )) { - // `DerefMut` will not be automatically applied to `ManuallyDrop<_>` - // field expressions when the base type is a union and the parent - // expression is also a field access. - // - // e.g. `&mut x.y.z` where `x` is a union, and accessing `z` requires a - // deref through `ManuallyDrop<_>` will not compile. - let parent_id = cx.tcx.parent_hir_id(expr.hir_id); - if parent_id == data.first_expr.hir_id { - return; - } - (cx.tcx.hir_node(parent_id).expect_expr().span, true) - } else { - (expr.span, false) - }; - span_lint_hir_and_then( - cx, - EXPLICIT_AUTO_DEREF, - data.first_expr.hir_id, - data.first_expr.span, - "deref which would be done by auto-deref", - |diag| { - let mut app = Applicability::MachineApplicable; - let snip = snippet_with_context(cx, snip_span, data.first_expr.span.ctxt(), "..", &mut app).0; - let sugg = if needs_parens { - format!("({snip})") - } else { - snip.into_owned() - }; - diag.span_suggestion(data.first_expr.span, "try", sugg, app); - }, - ); - }, - State::Borrow { .. } | State::Reborrow { .. } => (), - } -} - -impl<'tcx> Dereferencing<'tcx> { - fn check_local_usage(&mut self, cx: &LateContext<'tcx>, e: &Expr<'tcx>, local: HirId) { - if let Some(outer_pat) = self.ref_locals.get_mut(&local) { - if let Some(pat) = outer_pat { - // Check for auto-deref - if !matches!( - cx.typeck_results().expr_adjustments(e), - [ - Adjustment { - kind: Adjust::Deref(_), - .. - }, - Adjustment { - kind: Adjust::Deref(_), - .. - }, - .. - ] - ) { - match get_parent_expr(cx, e) { - // Field accesses are the same no matter the number of references. - Some(Expr { - kind: ExprKind::Field(..), - .. - }) => (), - Some(&Expr { - span, - kind: ExprKind::Unary(UnOp::Deref, _), - .. - }) if !span.from_expansion() => { - // Remove explicit deref. - let snip = snippet_with_context(cx, e.span, span.ctxt(), "..", &mut pat.app).0; - pat.replacements.push((span, snip.into())); - }, - Some(parent) if !parent.span.from_expansion() => { - // Double reference might be needed at this point. - if parent.precedence().order() == PREC_POSTFIX { - // Parentheses would be needed here, don't lint. - *outer_pat = None; - } else { - pat.always_deref = false; - let snip = snippet_with_context(cx, e.span, parent.span.ctxt(), "..", &mut pat.app).0; - pat.replacements.push((e.span, format!("&{snip}"))); - } - }, - _ if !e.span.from_expansion() => { - // Double reference might be needed at this point. - pat.always_deref = false; - let snip = snippet_with_applicability(cx, e.span, "..", &mut pat.app); - pat.replacements.push((e.span, format!("&{snip}"))); - }, - // Edge case for macros. The span of the identifier will usually match the context of the - // binding, but not if the identifier was created in a macro. e.g. `concat_idents` and proc - // macros - _ => *outer_pat = None, - } - } - } - } - } -} diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs deleted file mode 100644 index 0c9ad5e8d001..000000000000 --- a/clippy_lints/src/derivable_impls.rs +++ /dev/null @@ -1,215 +0,0 @@ -use clippy_config::msrvs::{self, Msrv}; -use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::indent_of; -use clippy_utils::{is_default_equivalent, peel_blocks}; -use rustc_errors::Applicability; -use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; -use rustc_hir::{ - self as hir, Body, Expr, ExprKind, GenericArg, Impl, ImplItemKind, Item, ItemKind, Node, PathSegment, QPath, TyKind, -}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::adjustment::{Adjust, PointerCoercion}; -use rustc_middle::ty::{self, AdtDef, GenericArgsRef, Ty, TypeckResults}; -use rustc_session::impl_lint_pass; -use rustc_span::sym; - -declare_clippy_lint! { - /// ### What it does - /// Detects manual `std::default::Default` implementations that are identical to a derived implementation. - /// - /// ### Why is this bad? - /// It is less concise. - /// - /// ### Example - /// ```no_run - /// struct Foo { - /// bar: bool - /// } - /// - /// impl Default for Foo { - /// fn default() -> Self { - /// Self { - /// bar: false - /// } - /// } - /// } - /// ``` - /// - /// Use instead: - /// ```no_run - /// #[derive(Default)] - /// struct Foo { - /// bar: bool - /// } - /// ``` - /// - /// ### Known problems - /// Derive macros [sometimes use incorrect bounds](https://github.com/rust-lang/rust/issues/26925) - /// in generic types and the user defined `impl` may be more generalized or - /// specialized than what derive will produce. This lint can't detect the manual `impl` - /// has exactly equal bounds, and therefore this lint is disabled for types with - /// generic parameters. - #[clippy::version = "1.57.0"] - pub DERIVABLE_IMPLS, - complexity, - "manual implementation of the `Default` trait which is equal to a derive" -} - -pub struct DerivableImpls { - msrv: Msrv, -} - -impl DerivableImpls { - #[must_use] - pub fn new(msrv: Msrv) -> Self { - DerivableImpls { msrv } - } -} - -impl_lint_pass!(DerivableImpls => [DERIVABLE_IMPLS]); - -fn is_path_self(e: &Expr<'_>) -> bool { - if let ExprKind::Path(QPath::Resolved(_, p)) = e.kind { - matches!(p.res, Res::SelfCtor(..) | Res::Def(DefKind::Ctor(..), _)) - } else { - false - } -} - -fn contains_trait_object(ty: Ty<'_>) -> bool { - match ty.kind() { - ty::Ref(_, ty, _) => contains_trait_object(*ty), - ty::Adt(def, args) => def.is_box() && args[0].as_type().map_or(false, contains_trait_object), - ty::Dynamic(..) => true, - _ => false, - } -} - -fn check_struct<'tcx>( - cx: &LateContext<'tcx>, - item: &'tcx Item<'_>, - self_ty: &hir::Ty<'_>, - func_expr: &Expr<'_>, - adt_def: AdtDef<'_>, - ty_args: GenericArgsRef<'_>, - typeck_results: &'tcx TypeckResults<'tcx>, -) { - if let TyKind::Path(QPath::Resolved(_, p)) = self_ty.kind { - if let Some(PathSegment { args, .. }) = p.segments.last() { - let args = args.map(|a| a.args).unwrap_or(&[]); - - // ty_args contains the generic parameters of the type declaration, while args contains the - // arguments used at instantiation time. If both len are not equal, it means that some - // parameters were not provided (which means that the default values were used); in this - // case we will not risk suggesting too broad a rewrite. We won't either if any argument - // is a type or a const. - if ty_args.len() != args.len() || args.iter().any(|arg| !matches!(arg, GenericArg::Lifetime(_))) { - return; - } - } - } - - // the default() call might unsize coerce to a trait object (e.g. Box to Box), - // which would not be the same if derived (see #10158). - // this closure checks both if the expr is equivalent to a `default()` call and does not - // have such coercions. - let is_default_without_adjusts = |expr| { - is_default_equivalent(cx, expr) - && typeck_results.expr_adjustments(expr).iter().all(|adj| { - !matches!(adj.kind, Adjust::Pointer(PointerCoercion::Unsize) - if contains_trait_object(adj.target)) - }) - }; - - let should_emit = match peel_blocks(func_expr).kind { - ExprKind::Tup(fields) => fields.iter().all(is_default_without_adjusts), - ExprKind::Call(callee, args) if is_path_self(callee) => args.iter().all(is_default_without_adjusts), - ExprKind::Struct(_, fields, _) => fields.iter().all(|ef| is_default_without_adjusts(ef.expr)), - _ => false, - }; - - if should_emit { - let struct_span = cx.tcx.def_span(adt_def.did()); - span_lint_and_then(cx, DERIVABLE_IMPLS, item.span, "this `impl` can be derived", |diag| { - diag.span_suggestion_hidden( - item.span, - "remove the manual implementation...", - String::new(), - Applicability::MachineApplicable, - ); - diag.span_suggestion( - struct_span.shrink_to_lo(), - "...and instead derive it", - "#[derive(Default)]\n".to_string(), - Applicability::MachineApplicable, - ); - }); - } -} - -fn check_enum<'tcx>(cx: &LateContext<'tcx>, item: &'tcx Item<'_>, func_expr: &Expr<'_>, adt_def: AdtDef<'_>) { - if let ExprKind::Path(QPath::Resolved(None, p)) = &peel_blocks(func_expr).kind - && let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const), id) = p.res - && let variant_id = cx.tcx.parent(id) - && let Some(variant_def) = adt_def.variants().iter().find(|v| v.def_id == variant_id) - && variant_def.fields.is_empty() - && !variant_def.is_field_list_non_exhaustive() - { - let enum_span = cx.tcx.def_span(adt_def.did()); - let indent_enum = indent_of(cx, enum_span).unwrap_or(0); - let variant_span = cx.tcx.def_span(variant_def.def_id); - let indent_variant = indent_of(cx, variant_span).unwrap_or(0); - span_lint_and_then(cx, DERIVABLE_IMPLS, item.span, "this `impl` can be derived", |diag| { - diag.span_suggestion_hidden( - item.span, - "remove the manual implementation...", - String::new(), - Applicability::MachineApplicable, - ); - diag.span_suggestion( - enum_span.shrink_to_lo(), - "...and instead derive it...", - format!("#[derive(Default)]\n{indent}", indent = " ".repeat(indent_enum),), - Applicability::MachineApplicable, - ); - diag.span_suggestion( - variant_span.shrink_to_lo(), - "...and mark the default variant", - format!("#[default]\n{indent}", indent = " ".repeat(indent_variant),), - Applicability::MachineApplicable, - ); - }); - } -} - -impl<'tcx> LateLintPass<'tcx> for DerivableImpls { - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Impl(Impl { - of_trait: Some(ref trait_ref), - items: [child], - self_ty, - .. - }) = item.kind - && !cx.tcx.has_attr(item.owner_id, sym::automatically_derived) - && !item.span.from_expansion() - && let Some(def_id) = trait_ref.trait_def_id() - && cx.tcx.is_diagnostic_item(sym::Default, def_id) - && let impl_item_hir = child.id.hir_id() - && let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir) - && let ImplItemKind::Fn(_, b) = &impl_item.kind - && let Body { value: func_expr, .. } = cx.tcx.hir().body(*b) - && let &ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind() - && let attrs = cx.tcx.hir().attrs(item.hir_id()) - && !attrs.iter().any(|attr| attr.doc_str().is_some()) - && cx.tcx.hir().attrs(impl_item_hir).is_empty() - { - if adt_def.is_struct() { - check_struct(cx, item, self_ty, func_expr, adt_def, args, cx.tcx.typeck_body(*b)); - } else if adt_def.is_enum() && self.msrv.meets(msrvs::DEFAULT_ENUM_ATTRIBUTE) { - check_enum(cx, item, func_expr, adt_def); - } - } - } - - extract_msrv_attr!(LateContext); -} diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs deleted file mode 100644 index 42cd19fb8eca..000000000000 --- a/clippy_lints/src/derive.rs +++ /dev/null @@ -1,511 +0,0 @@ -use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then}; -use clippy_utils::ty::{implements_trait, implements_trait_with_env, is_copy}; -use clippy_utils::{has_non_exhaustive_attr, is_lint_allowed, match_def_path, paths}; -use rustc_errors::Applicability; -use rustc_hir::def_id::DefId; -use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, Visitor}; -use rustc_hir::{ - self as hir, BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, Impl, Item, ItemKind, UnsafeSource, Unsafety, -}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::nested_filter; -use rustc_middle::traits::Reveal; -use rustc_middle::ty::{ - self, ClauseKind, GenericArgKind, GenericParamDefKind, ParamEnv, ToPredicate, TraitPredicate, Ty, TyCtxt, -}; -use rustc_session::declare_lint_pass; -use rustc_span::def_id::LocalDefId; -use rustc_span::{sym, Span}; - -declare_clippy_lint! { - /// ### What it does - /// Lints against manual `PartialEq` implementations for types with a derived `Hash` - /// implementation. - /// - /// ### Why is this bad? - /// The implementation of these traits must agree (for - /// example for use with `HashMap`) so it’s probably a bad idea to use a - /// default-generated `Hash` implementation with an explicitly defined - /// `PartialEq`. In particular, the following must hold for any type: - /// - /// ```text - /// k1 == k2 ⇒ hash(k1) == hash(k2) - /// ``` - /// - /// ### Example - /// ```ignore - /// #[derive(Hash)] - /// struct Foo; - /// - /// impl PartialEq for Foo { - /// ... - /// } - /// ``` - #[clippy::version = "pre 1.29.0"] - pub DERIVED_HASH_WITH_MANUAL_EQ, - correctness, - "deriving `Hash` but implementing `PartialEq` explicitly" -} - -declare_clippy_lint! { - /// ### What it does - /// Lints against manual `PartialOrd` and `Ord` implementations for types with a derived `Ord` - /// or `PartialOrd` implementation. - /// - /// ### Why is this bad? - /// The implementation of these traits must agree (for - /// example for use with `sort`) so it’s probably a bad idea to use a - /// default-generated `Ord` implementation with an explicitly defined - /// `PartialOrd`. In particular, the following must hold for any type - /// implementing `Ord`: - /// - /// ```text - /// k1.cmp(&k2) == k1.partial_cmp(&k2).unwrap() - /// ``` - /// - /// ### Example - /// ```rust,ignore - /// #[derive(Ord, PartialEq, Eq)] - /// struct Foo; - /// - /// impl PartialOrd for Foo { - /// ... - /// } - /// ``` - /// Use instead: - /// ```rust,ignore - /// #[derive(PartialEq, Eq)] - /// struct Foo; - /// - /// impl PartialOrd for Foo { - /// fn partial_cmp(&self, other: &Foo) -> Option { - /// Some(self.cmp(other)) - /// } - /// } - /// - /// impl Ord for Foo { - /// ... - /// } - /// ``` - /// or, if you don't need a custom ordering: - /// ```rust,ignore - /// #[derive(Ord, PartialOrd, PartialEq, Eq)] - /// struct Foo; - /// ``` - #[clippy::version = "1.47.0"] - pub DERIVE_ORD_XOR_PARTIAL_ORD, - correctness, - "deriving `Ord` but implementing `PartialOrd` explicitly" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for explicit `Clone` implementations for `Copy` - /// types. - /// - /// ### Why is this bad? - /// To avoid surprising behavior, these traits should - /// agree and the behavior of `Copy` cannot be overridden. In almost all - /// situations a `Copy` type should have a `Clone` implementation that does - /// nothing more than copy the object, which is what `#[derive(Copy, Clone)]` - /// gets you. - /// - /// ### Example - /// ```rust,ignore - /// #[derive(Copy)] - /// struct Foo; - /// - /// impl Clone for Foo { - /// // .. - /// } - /// ``` - #[clippy::version = "pre 1.29.0"] - pub EXPL_IMPL_CLONE_ON_COPY, - pedantic, - "implementing `Clone` explicitly on `Copy` types" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for deriving `serde::Deserialize` on a type that - /// has methods using `unsafe`. - /// - /// ### Why is this bad? - /// Deriving `serde::Deserialize` will create a constructor - /// that may violate invariants held by another constructor. - /// - /// ### Example - /// ```rust,ignore - /// use serde::Deserialize; - /// - /// #[derive(Deserialize)] - /// pub struct Foo { - /// // .. - /// } - /// - /// impl Foo { - /// pub fn new() -> Self { - /// // setup here .. - /// } - /// - /// pub unsafe fn parts() -> (&str, &str) { - /// // assumes invariants hold - /// } - /// } - /// ``` - #[clippy::version = "1.45.0"] - pub UNSAFE_DERIVE_DESERIALIZE, - pedantic, - "deriving `serde::Deserialize` on a type that has methods using `unsafe`" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for types that derive `PartialEq` and could implement `Eq`. - /// - /// ### Why is this bad? - /// If a type `T` derives `PartialEq` and all of its members implement `Eq`, - /// then `T` can always implement `Eq`. Implementing `Eq` allows `T` to be used - /// in APIs that require `Eq` types. It also allows structs containing `T` to derive - /// `Eq` themselves. - /// - /// ### Example - /// ```no_run - /// #[derive(PartialEq)] - /// struct Foo { - /// i_am_eq: i32, - /// i_am_eq_too: Vec, - /// } - /// ``` - /// Use instead: - /// ```no_run - /// #[derive(PartialEq, Eq)] - /// struct Foo { - /// i_am_eq: i32, - /// i_am_eq_too: Vec, - /// } - /// ``` - #[clippy::version = "1.63.0"] - pub DERIVE_PARTIAL_EQ_WITHOUT_EQ, - nursery, - "deriving `PartialEq` on a type that can implement `Eq`, without implementing `Eq`" -} - -declare_lint_pass!(Derive => [ - EXPL_IMPL_CLONE_ON_COPY, - DERIVED_HASH_WITH_MANUAL_EQ, - DERIVE_ORD_XOR_PARTIAL_ORD, - UNSAFE_DERIVE_DESERIALIZE, - DERIVE_PARTIAL_EQ_WITHOUT_EQ -]); - -impl<'tcx> LateLintPass<'tcx> for Derive { - fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Impl(Impl { - of_trait: Some(ref trait_ref), - .. - }) = item.kind - { - let ty = cx.tcx.type_of(item.owner_id).instantiate_identity(); - let is_automatically_derived = cx.tcx.has_attr(item.owner_id, sym::automatically_derived); - - check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived); - check_ord_partial_ord(cx, item.span, trait_ref, ty, is_automatically_derived); - - if is_automatically_derived { - check_unsafe_derive_deserialize(cx, item, trait_ref, ty); - check_partial_eq_without_eq(cx, item.span, trait_ref, ty); - } else { - check_copy_clone(cx, item, trait_ref, ty); - } - } - } -} - -/// Implementation of the `DERIVED_HASH_WITH_MANUAL_EQ` lint. -fn check_hash_peq<'tcx>( - cx: &LateContext<'tcx>, - span: Span, - trait_ref: &hir::TraitRef<'_>, - ty: Ty<'tcx>, - hash_is_automatically_derived: bool, -) { - if let Some(peq_trait_def_id) = cx.tcx.lang_items().eq_trait() - && let Some(def_id) = trait_ref.trait_def_id() - && cx.tcx.is_diagnostic_item(sym::Hash, def_id) - { - // Look for the PartialEq implementations for `ty` - cx.tcx.for_each_relevant_impl(peq_trait_def_id, ty, |impl_id| { - let peq_is_automatically_derived = cx.tcx.has_attr(impl_id, sym::automatically_derived); - - if !hash_is_automatically_derived || peq_is_automatically_derived { - return; - } - - let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation"); - - // Only care about `impl PartialEq for Foo` - // For `impl PartialEq for A, input_types is [A, B] - if trait_ref.instantiate_identity().args.type_at(1) == ty { - span_lint_and_then( - cx, - DERIVED_HASH_WITH_MANUAL_EQ, - span, - "you are deriving `Hash` but have implemented `PartialEq` explicitly", - |diag| { - if let Some(local_def_id) = impl_id.as_local() { - let hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id); - diag.span_note(cx.tcx.hir().span(hir_id), "`PartialEq` implemented here"); - } - }, - ); - } - }); - } -} - -/// Implementation of the `DERIVE_ORD_XOR_PARTIAL_ORD` lint. -fn check_ord_partial_ord<'tcx>( - cx: &LateContext<'tcx>, - span: Span, - trait_ref: &hir::TraitRef<'_>, - ty: Ty<'tcx>, - ord_is_automatically_derived: bool, -) { - if let Some(ord_trait_def_id) = cx.tcx.get_diagnostic_item(sym::Ord) - && let Some(partial_ord_trait_def_id) = cx.tcx.lang_items().partial_ord_trait() - && let Some(def_id) = &trait_ref.trait_def_id() - && *def_id == ord_trait_def_id - { - // Look for the PartialOrd implementations for `ty` - cx.tcx.for_each_relevant_impl(partial_ord_trait_def_id, ty, |impl_id| { - let partial_ord_is_automatically_derived = cx.tcx.has_attr(impl_id, sym::automatically_derived); - - if partial_ord_is_automatically_derived == ord_is_automatically_derived { - return; - } - - let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation"); - - // Only care about `impl PartialOrd for Foo` - // For `impl PartialOrd for A, input_types is [A, B] - if trait_ref.instantiate_identity().args.type_at(1) == ty { - let mess = if partial_ord_is_automatically_derived { - "you are implementing `Ord` explicitly but have derived `PartialOrd`" - } else { - "you are deriving `Ord` but have implemented `PartialOrd` explicitly" - }; - - span_lint_and_then(cx, DERIVE_ORD_XOR_PARTIAL_ORD, span, mess, |diag| { - if let Some(local_def_id) = impl_id.as_local() { - let hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id); - diag.span_note(cx.tcx.hir().span(hir_id), "`PartialOrd` implemented here"); - } - }); - } - }); - } -} - -/// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint. -fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &hir::TraitRef<'_>, ty: Ty<'tcx>) { - let clone_id = match cx.tcx.lang_items().clone_trait() { - Some(id) if trait_ref.trait_def_id() == Some(id) => id, - _ => return, - }; - let Some(copy_id) = cx.tcx.lang_items().copy_trait() else { - return; - }; - let (ty_adt, ty_subs) = match *ty.kind() { - // Unions can't derive clone. - ty::Adt(adt, subs) if !adt.is_union() => (adt, subs), - _ => return, - }; - // If the current self type doesn't implement Copy (due to generic constraints), search to see if - // there's a Copy impl for any instance of the adt. - if !is_copy(cx, ty) { - if ty_subs.non_erasable_generics(cx.tcx, ty_adt.did()).next().is_some() { - let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(©_id).map_or(false, |impls| { - impls.iter().any(|&id| { - matches!(cx.tcx.type_of(id).instantiate_identity().kind(), ty::Adt(adt, _) - if ty_adt.did() == adt.did()) - }) - }); - if !has_copy_impl { - return; - } - } else { - return; - } - } - // Derive constrains all generic types to requiring Clone. Check if any type is not constrained for - // this impl. - if ty_subs.types().any(|ty| !implements_trait(cx, ty, clone_id, &[])) { - return; - } - // `#[repr(packed)]` structs with type/const parameters can't derive `Clone`. - // https://github.com/rust-lang/rust-clippy/issues/10188 - if ty_adt.repr().packed() - && ty_subs - .iter() - .any(|arg| matches!(arg.unpack(), GenericArgKind::Type(_) | GenericArgKind::Const(_))) - { - return; - } - - span_lint_and_note( - cx, - EXPL_IMPL_CLONE_ON_COPY, - item.span, - "you are implementing `Clone` explicitly on a `Copy` type", - Some(item.span), - "consider deriving `Clone` or removing `Copy`", - ); -} - -/// Implementation of the `UNSAFE_DERIVE_DESERIALIZE` lint. -fn check_unsafe_derive_deserialize<'tcx>( - cx: &LateContext<'tcx>, - item: &Item<'_>, - trait_ref: &hir::TraitRef<'_>, - ty: Ty<'tcx>, -) { - fn has_unsafe<'tcx>(cx: &LateContext<'tcx>, item: &'tcx Item<'_>) -> bool { - let mut visitor = UnsafeVisitor { cx, has_unsafe: false }; - walk_item(&mut visitor, item); - visitor.has_unsafe - } - - if let Some(trait_def_id) = trait_ref.trait_def_id() - && match_def_path(cx, trait_def_id, &paths::SERDE_DESERIALIZE) - && let ty::Adt(def, _) = ty.kind() - && let Some(local_def_id) = def.did().as_local() - && let adt_hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id) - && !is_lint_allowed(cx, UNSAFE_DERIVE_DESERIALIZE, adt_hir_id) - && cx - .tcx - .inherent_impls(def.did()) - .into_iter() - .flatten() - .map(|imp_did| cx.tcx.hir().expect_item(imp_did.expect_local())) - .any(|imp| has_unsafe(cx, imp)) - { - span_lint_and_help( - cx, - UNSAFE_DERIVE_DESERIALIZE, - item.span, - "you are deriving `serde::Deserialize` on a type that has methods using `unsafe`", - None, - "consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html", - ); - } -} - -struct UnsafeVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, - has_unsafe: bool, -} - -impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> { - type NestedFilter = nested_filter::All; - - fn visit_fn(&mut self, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body_id: BodyId, _: Span, id: LocalDefId) { - if self.has_unsafe { - return; - } - - if let Some(header) = kind.header() - && header.unsafety == Unsafety::Unsafe - { - self.has_unsafe = true; - } - - walk_fn(self, kind, decl, body_id, id); - } - - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if self.has_unsafe { - return; - } - - if let ExprKind::Block(block, _) = expr.kind { - if block.rules == BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) { - self.has_unsafe = true; - } - } - - walk_expr(self, expr); - } - - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() - } -} - -/// Implementation of the `DERIVE_PARTIAL_EQ_WITHOUT_EQ` lint. -fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_ref: &hir::TraitRef<'_>, ty: Ty<'tcx>) { - if let ty::Adt(adt, args) = ty.kind() - && cx.tcx.visibility(adt.did()).is_public() - && let Some(eq_trait_def_id) = cx.tcx.get_diagnostic_item(sym::Eq) - && let Some(def_id) = trait_ref.trait_def_id() - && cx.tcx.is_diagnostic_item(sym::PartialEq, def_id) - && !has_non_exhaustive_attr(cx.tcx, *adt) - && !ty_implements_eq_trait(cx.tcx, ty, eq_trait_def_id) - && let param_env = param_env_for_derived_eq(cx.tcx, adt.did(), eq_trait_def_id) - // If all of our fields implement `Eq`, we can implement `Eq` too - && adt - .all_fields() - .map(|f| f.ty(cx.tcx, args)) - .all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, None, &[])) - { - span_lint_and_sugg( - cx, - DERIVE_PARTIAL_EQ_WITHOUT_EQ, - span.ctxt().outer_expn_data().call_site, - "you are deriving `PartialEq` and can implement `Eq`", - "consider deriving `Eq` as well", - "PartialEq, Eq".to_string(), - Applicability::MachineApplicable, - ); - } -} - -fn ty_implements_eq_trait<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, eq_trait_id: DefId) -> bool { - tcx.non_blanket_impls_for_ty(eq_trait_id, ty).next().is_some() -} - -/// Creates the `ParamEnv` used for the give type's derived `Eq` impl. -fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> ParamEnv<'_> { - // Initial map from generic index to param def. - // Vec<(param_def, needs_eq)> - let mut params = tcx - .generics_of(did) - .params - .iter() - .map(|p| (p, matches!(p.kind, GenericParamDefKind::Type { .. }))) - .collect::>(); - - let ty_predicates = tcx.predicates_of(did).predicates; - for (p, _) in ty_predicates { - if let ClauseKind::Trait(p) = p.kind().skip_binder() - && p.trait_ref.def_id == eq_trait_id - && let ty::Param(self_ty) = p.trait_ref.self_ty().kind() - { - // Flag types which already have an `Eq` bound. - params[self_ty.index as usize].1 = false; - } - } - - ParamEnv::new( - tcx.mk_clauses_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain( - params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| { - ClauseKind::Trait(TraitPredicate { - trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]), - polarity: ty::PredicatePolarity::Positive, - }) - .to_predicate(tcx) - }), - )), - Reveal::UserFacing, - ) -} diff --git a/clippy_lints/src/disallowed_macros.rs b/clippy_lints/src/disallowed_macros.rs deleted file mode 100644 index 871f529da6c4..000000000000 --- a/clippy_lints/src/disallowed_macros.rs +++ /dev/null @@ -1,182 +0,0 @@ -use clippy_config::types::DisallowedPath; -use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then}; -use clippy_utils::macros::macro_backtrace; -use rustc_ast::Attribute; -use rustc_data_structures::fx::FxHashSet; -use rustc_errors::Diag; -use rustc_hir::def_id::DefIdMap; -use rustc_hir::{ - Expr, ExprKind, ForeignItem, HirId, ImplItem, Item, ItemKind, OwnerId, Pat, Path, Stmt, TraitItem, Ty, -}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::impl_lint_pass; -use rustc_span::{ExpnId, MacroKind, Span}; - -declare_clippy_lint! { - /// ### What it does - /// Denies the configured macros in clippy.toml - /// - /// Note: Even though this lint is warn-by-default, it will only trigger if - /// macros are defined in the clippy.toml file. - /// - /// ### Why is this bad? - /// Some macros are undesirable in certain contexts, and it's beneficial to - /// lint for them as needed. - /// - /// ### Example - /// An example clippy.toml configuration: - /// ```toml - /// # clippy.toml - /// disallowed-macros = [ - /// # Can use a string as the path of the disallowed macro. - /// "std::print", - /// # Can also use an inline table with a `path` key. - /// { path = "std::println" }, - /// # When using an inline table, can add a `reason` for why the macro - /// # is disallowed. - /// { path = "serde::Serialize", reason = "no serializing" }, - /// ] - /// ``` - /// ```no_run - /// use serde::Serialize; - /// - /// // Example code where clippy issues a warning - /// println!("warns"); - /// - /// // The diagnostic will contain the message "no serializing" - /// #[derive(Serialize)] - /// struct Data { - /// name: String, - /// value: usize, - /// } - /// ``` - #[clippy::version = "1.66.0"] - pub DISALLOWED_MACROS, - style, - "use of a disallowed macro" -} - -pub struct DisallowedMacros { - conf_disallowed: Vec, - disallowed: DefIdMap, - seen: FxHashSet, - - // Track the most recently seen node that can have a `derive` attribute. - // Needed to use the correct lint level. - derive_src: Option, -} - -impl DisallowedMacros { - pub fn new(conf_disallowed: Vec) -> Self { - Self { - conf_disallowed, - disallowed: DefIdMap::default(), - seen: FxHashSet::default(), - derive_src: None, - } - } - - fn check(&mut self, cx: &LateContext<'_>, span: Span, derive_src: Option) { - if self.conf_disallowed.is_empty() { - return; - } - - for mac in macro_backtrace(span) { - if !self.seen.insert(mac.expn) { - return; - } - - if let Some(&index) = self.disallowed.get(&mac.def_id) { - let conf = &self.conf_disallowed[index]; - let msg = format!("use of a disallowed macro `{}`", conf.path()); - let add_note = |diag: &mut Diag<'_, _>| { - if let Some(reason) = conf.reason() { - diag.note(reason); - } - }; - if matches!(mac.kind, MacroKind::Derive) - && let Some(derive_src) = derive_src - { - span_lint_hir_and_then( - cx, - DISALLOWED_MACROS, - cx.tcx.local_def_id_to_hir_id(derive_src.def_id), - mac.span, - msg, - add_note, - ); - } else { - span_lint_and_then(cx, DISALLOWED_MACROS, mac.span, msg, add_note); - } - } - } - } -} - -impl_lint_pass!(DisallowedMacros => [DISALLOWED_MACROS]); - -impl LateLintPass<'_> for DisallowedMacros { - fn check_crate(&mut self, cx: &LateContext<'_>) { - for (index, conf) in self.conf_disallowed.iter().enumerate() { - let segs: Vec<_> = conf.path().split("::").collect(); - for id in clippy_utils::def_path_def_ids(cx, &segs) { - self.disallowed.insert(id, index); - } - } - } - - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - self.check(cx, expr.span, None); - // `$t + $t` can have the context of $t, check also the span of the binary operator - if let ExprKind::Binary(op, ..) = expr.kind { - self.check(cx, op.span, None); - } - } - - fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &Stmt<'_>) { - self.check(cx, stmt.span, None); - } - - fn check_ty(&mut self, cx: &LateContext<'_>, ty: &Ty<'_>) { - self.check(cx, ty.span, None); - } - - fn check_pat(&mut self, cx: &LateContext<'_>, pat: &Pat<'_>) { - self.check(cx, pat.span, None); - } - - fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { - self.check(cx, item.span, self.derive_src); - self.check(cx, item.vis_span, None); - - if matches!( - item.kind, - ItemKind::Struct(..) | ItemKind::Enum(..) | ItemKind::Union(..) - ) && macro_backtrace(item.span).all(|m| !matches!(m.kind, MacroKind::Derive)) - { - self.derive_src = Some(item.owner_id); - } - } - - fn check_foreign_item(&mut self, cx: &LateContext<'_>, item: &ForeignItem<'_>) { - self.check(cx, item.span, None); - self.check(cx, item.vis_span, None); - } - - fn check_impl_item(&mut self, cx: &LateContext<'_>, item: &ImplItem<'_>) { - self.check(cx, item.span, None); - self.check(cx, item.vis_span, None); - } - - fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &TraitItem<'_>) { - self.check(cx, item.span, None); - } - - fn check_path(&mut self, cx: &LateContext<'_>, path: &Path<'_>, _: HirId) { - self.check(cx, path.span, None); - } - - fn check_attribute(&mut self, cx: &LateContext<'_>, attr: &Attribute) { - self.check(cx, attr.span, self.derive_src); - } -} diff --git a/clippy_lints/src/disallowed_methods.rs b/clippy_lints/src/disallowed_methods.rs deleted file mode 100644 index 9de879604e2e..000000000000 --- a/clippy_lints/src/disallowed_methods.rs +++ /dev/null @@ -1,108 +0,0 @@ -use clippy_config::types::DisallowedPath; -use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::{fn_def_id, get_parent_expr, path_def_id}; -use rustc_hir::def_id::DefIdMap; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::impl_lint_pass; - -declare_clippy_lint! { - /// ### What it does - /// Denies the configured methods and functions in clippy.toml - /// - /// Note: Even though this lint is warn-by-default, it will only trigger if - /// methods are defined in the clippy.toml file. - /// - /// ### Why is this bad? - /// Some methods are undesirable in certain contexts, and it's beneficial to - /// lint for them as needed. - /// - /// ### Example - /// An example clippy.toml configuration: - /// ```toml - /// # clippy.toml - /// disallowed-methods = [ - /// # Can use a string as the path of the disallowed method. - /// "std::boxed::Box::new", - /// # Can also use an inline table with a `path` key. - /// { path = "std::time::Instant::now" }, - /// # When using an inline table, can add a `reason` for why the method - /// # is disallowed. - /// { path = "std::vec::Vec::leak", reason = "no leaking memory" }, - /// ] - /// ``` - /// - /// ```rust,ignore - /// // Example code where clippy issues a warning - /// let xs = vec![1, 2, 3, 4]; - /// xs.leak(); // Vec::leak is disallowed in the config. - /// // The diagnostic contains the message "no leaking memory". - /// - /// let _now = Instant::now(); // Instant::now is disallowed in the config. - /// - /// let _box = Box::new(3); // Box::new is disallowed in the config. - /// ``` - /// - /// Use instead: - /// ```rust,ignore - /// // Example code which does not raise clippy warning - /// let mut xs = Vec::new(); // Vec::new is _not_ disallowed in the config. - /// xs.push(123); // Vec::push is _not_ disallowed in the config. - /// ``` - #[clippy::version = "1.49.0"] - pub DISALLOWED_METHODS, - style, - "use of a disallowed method call" -} - -#[derive(Clone, Debug)] -pub struct DisallowedMethods { - conf_disallowed: Vec, - disallowed: DefIdMap, -} - -impl DisallowedMethods { - pub fn new(conf_disallowed: Vec) -> Self { - Self { - conf_disallowed, - disallowed: DefIdMap::default(), - } - } -} - -impl_lint_pass!(DisallowedMethods => [DISALLOWED_METHODS]); - -impl<'tcx> LateLintPass<'tcx> for DisallowedMethods { - fn check_crate(&mut self, cx: &LateContext<'_>) { - for (index, conf) in self.conf_disallowed.iter().enumerate() { - let segs: Vec<_> = conf.path().split("::").collect(); - for id in clippy_utils::def_path_def_ids(cx, &segs) { - self.disallowed.insert(id, index); - } - } - } - - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - let uncalled_path = if let Some(parent) = get_parent_expr(cx, expr) - && let ExprKind::Call(receiver, _) = parent.kind - && receiver.hir_id == expr.hir_id - { - None - } else { - path_def_id(cx, expr) - }; - let Some(def_id) = uncalled_path.or_else(|| fn_def_id(cx, expr)) else { - return; - }; - let conf = match self.disallowed.get(&def_id) { - Some(&index) => &self.conf_disallowed[index], - None => return, - }; - let msg = format!("use of a disallowed method `{}`", conf.path()); - span_lint_and_then(cx, DISALLOWED_METHODS, expr.span, msg, |diag| { - if let Some(reason) = conf.reason() { - diag.note(reason); - } - }); - } -} diff --git a/clippy_lints/src/disallowed_names.rs b/clippy_lints/src/disallowed_names.rs deleted file mode 100644 index 2afbf184117e..000000000000 --- a/clippy_lints/src/disallowed_names.rs +++ /dev/null @@ -1,78 +0,0 @@ -use clippy_utils::diagnostics::span_lint; -use clippy_utils::is_test_module_or_function; -use rustc_data_structures::fx::FxHashSet; -use rustc_hir::{Item, Pat, PatKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::impl_lint_pass; - -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of disallowed names for variables, such - /// as `foo`. - /// - /// ### Why is this bad? - /// These names are usually placeholder names and should be - /// avoided. - /// - /// ### Example - /// ```no_run - /// let foo = 3.14; - /// ``` - #[clippy::version = "pre 1.29.0"] - pub DISALLOWED_NAMES, - style, - "usage of a disallowed/placeholder name" -} - -#[derive(Clone, Debug)] -pub struct DisallowedNames { - disallow: FxHashSet, - test_modules_deep: u32, -} - -impl DisallowedNames { - pub fn new(disallowed_names: &[String]) -> Self { - Self { - disallow: disallowed_names.iter().cloned().collect(), - test_modules_deep: 0, - } - } - - fn in_test_module(&self) -> bool { - self.test_modules_deep != 0 - } -} - -impl_lint_pass!(DisallowedNames => [DISALLOWED_NAMES]); - -impl<'tcx> LateLintPass<'tcx> for DisallowedNames { - fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { - if is_test_module_or_function(cx.tcx, item) { - self.test_modules_deep = self.test_modules_deep.saturating_add(1); - } - } - - fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { - // Check whether we are under the `test` attribute. - if self.in_test_module() { - return; - } - - if let PatKind::Binding(.., ident, _) = pat.kind { - if self.disallow.contains(&ident.name.to_string()) { - span_lint( - cx, - DISALLOWED_NAMES, - ident.span, - format!("use of a disallowed/placeholder name `{}`", ident.name), - ); - } - } - } - - fn check_item_post(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { - if is_test_module_or_function(cx.tcx, item) { - self.test_modules_deep = self.test_modules_deep.saturating_sub(1); - } - } -} diff --git a/clippy_lints/src/disallowed_script_idents.rs b/clippy_lints/src/disallowed_script_idents.rs deleted file mode 100644 index def4b5932b4b..000000000000 --- a/clippy_lints/src/disallowed_script_idents.rs +++ /dev/null @@ -1,112 +0,0 @@ -use clippy_utils::diagnostics::span_lint; -use rustc_ast::ast; -use rustc_data_structures::fx::FxHashSet; -use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext}; -use rustc_session::impl_lint_pass; -use unicode_script::{Script, UnicodeScript}; - -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of unicode scripts other than those explicitly allowed - /// by the lint config. - /// - /// This lint doesn't take into account non-text scripts such as `Unknown` and `Linear_A`. - /// It also ignores the `Common` script type. - /// While configuring, be sure to use official script name [aliases] from - /// [the list of supported scripts][supported_scripts]. - /// - /// See also: [`non_ascii_idents`]. - /// - /// [aliases]: http://www.unicode.org/reports/tr24/tr24-31.html#Script_Value_Aliases - /// [supported_scripts]: https://www.unicode.org/iso15924/iso15924-codes.html - /// - /// ### Why is this bad? - /// It may be not desired to have many different scripts for - /// identifiers in the codebase. - /// - /// Note that if you only want to allow plain English, you might want to use - /// built-in [`non_ascii_idents`] lint instead. - /// - /// [`non_ascii_idents`]: https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#non-ascii-idents - /// - /// ### Example - /// ```no_run - /// // Assuming that `clippy.toml` contains the following line: - /// // allowed-scripts = ["Latin", "Cyrillic"] - /// let counter = 10; // OK, latin is allowed. - /// let счётчик = 10; // OK, cyrillic is allowed. - /// let zähler = 10; // OK, it's still latin. - /// let カウンタ = 10; // Will spawn the lint. - /// ``` - #[clippy::version = "1.55.0"] - pub DISALLOWED_SCRIPT_IDENTS, - restriction, - "usage of non-allowed Unicode scripts" -} - -#[derive(Clone, Debug)] -pub struct DisallowedScriptIdents { - whitelist: FxHashSet - - - - - - diff --git a/util/gh-pages/script.js b/util/gh-pages/script.js deleted file mode 100644 index 7fd779fe9a46..000000000000 --- a/util/gh-pages/script.js +++ /dev/null @@ -1,550 +0,0 @@ -(function () { - var md = window.markdownit({ - html: true, - linkify: true, - typographer: true, - highlight: function (str, lang) { - if (lang && hljs.getLanguage(lang)) { - try { - return '
' +
-                        hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
-                        '
'; - } catch (__) {} - } - - return '
' + md.utils.escapeHtml(str) + '
'; - } - }); - - function scrollToLint(lintId) { - var target = document.getElementById(lintId); - if (!target) { - return; - } - target.scrollIntoView(); - } - - function scrollToLintByURL($scope, $location) { - var removeListener = $scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) { - scrollToLint($location.path().substring(1)); - removeListener(); - }); - } - - function selectGroup($scope, selectedGroup) { - var groups = $scope.groups; - for (var group in groups) { - if (groups.hasOwnProperty(group)) { - if (group === selectedGroup) { - groups[group] = true; - } else { - groups[group] = false; - } - } - } - } - - angular.module("clippy", []) - .filter('markdown', function ($sce) { - return function (text) { - return $sce.trustAsHtml( - md.render(text || '') - // Oh deer, what a hack :O - .replace(' [value, key]) - ); - - // loadFromURLParameters retrieves filter settings from the URL parameters and assigns them - // to corresponding $scope variables. - function loadFromURLParameters() { - // Extract parameters from URL - const urlParameters = $location.search(); - - // Define a helper function that assigns URL parameters to a provided scope variable - const handleParameter = (parameter, scopeVariable, defaultValues) => { - if (urlParameters[parameter]) { - const items = urlParameters[parameter].split(','); - for (const key in scopeVariable) { - if (scopeVariable.hasOwnProperty(key)) { - scopeVariable[key] = items.includes(key); - } - } - } else if (defaultValues) { - for (const key in defaultValues) { - if (scopeVariable.hasOwnProperty(key)) { - scopeVariable[key] = defaultValues[key]; - } - } - } - }; - - handleParameter('levels', $scope.levels, LEVEL_FILTERS_DEFAULT); - handleParameter('groups', $scope.groups, GROUPS_FILTER_DEFAULT); - - // Handle 'versions' parameter separately because it needs additional processing - if (urlParameters.versions) { - const versionFilters = urlParameters.versions.split(','); - for (const versionFilter of versionFilters) { - const [key, minorVersion] = versionFilter.split(':'); - const parsedMinorVersion = parseInt(minorVersion); - - // Map the key from the URL parameter to its original form - const originalKey = reverseVersionFilterKeyMap[key]; - - if (originalKey in $scope.versionFilters && !isNaN(parsedMinorVersion)) { - $scope.versionFilters[originalKey].enabled = true; - $scope.versionFilters[originalKey].minorVersion = parsedMinorVersion; - } - } - } - - // Load the search parameter from the URL path - const searchParameter = $location.path().substring(1); // Remove the leading slash - if (searchParameter) { - $scope.search = searchParameter; - $scope.open[searchParameter] = true; - scrollToLintByURL($scope, $location); - } - } - - // updateURLParameter updates the URL parameter with the given key to the given value - function updateURLParameter(filterObj, urlKey, defaultValue = {}, processFilter = filter => filter) { - const parameter = Object.keys(filterObj) - .filter(filter => filterObj[filter]) - .sort() - .map(processFilter) - .filter(Boolean) // Filters out any falsy values, including null - .join(','); - - const defaultParameter = Object.keys(defaultValue) - .filter(filter => defaultValue[filter]) - .sort() - .map(processFilter) - .filter(Boolean) // Filters out any falsy values, including null - .join(','); - - // if we ended up back at the defaults, just remove it from the URL - if (parameter === defaultParameter) { - $location.search(urlKey, null); - } else { - $location.search(urlKey, parameter || null); - } - } - - // updateVersionURLParameter updates the version URL parameter with the given version filters - function updateVersionURLParameter(versionFilters) { - updateURLParameter( - versionFilters, - 'versions', {}, - versionFilter => versionFilters[versionFilter].enabled && versionFilters[versionFilter].minorVersion != null - ? `${versionFilterKeyMap[versionFilter]}:${versionFilters[versionFilter].minorVersion}` - : null - ); - } - - // updateAllURLParameters updates all the URL parameters with the current filter settings - function updateAllURLParameters() { - updateURLParameter($scope.levels, 'levels', LEVEL_FILTERS_DEFAULT); - updateURLParameter($scope.groups, 'groups', GROUPS_FILTER_DEFAULT); - updateVersionURLParameter($scope.versionFilters); - } - - // Add $watches to automatically update URL parameters when the data changes - $scope.$watch('levels', function (newVal, oldVal) { - if (newVal !== oldVal) { - updateURLParameter(newVal, 'levels', LEVEL_FILTERS_DEFAULT); - } - }, true); - - $scope.$watch('groups', function (newVal, oldVal) { - if (newVal !== oldVal) { - updateURLParameter(newVal, 'groups', GROUPS_FILTER_DEFAULT); - } - }, true); - - $scope.$watch('versionFilters', function (newVal, oldVal) { - if (newVal !== oldVal) { - updateVersionURLParameter(newVal); - } - }, true); - - // Watch for changes in the URL path and update the search and lint display - $scope.$watch(function () { return $location.path(); }, function (newPath) { - const searchParameter = newPath.substring(1); - if ($scope.search !== searchParameter) { - $scope.search = searchParameter; - $scope.open[searchParameter] = true; - scrollToLintByURL($scope, $location); - } - }); - - let debounceTimeout; - $scope.$watch('search', function (newVal, oldVal) { - if (newVal !== oldVal) { - if (debounceTimeout) { - $timeout.cancel(debounceTimeout); - } - - debounceTimeout = $timeout(function () { - $location.path(newVal); - }, 1000); - } - }); - - $scope.$watch(function () { return $location.search(); }, function (newParameters) { - loadFromURLParameters(); - }, true); - - $scope.updatePath = function () { - if (debounceTimeout) { - $timeout.cancel(debounceTimeout); - } - - $location.path($scope.search); - } - - $scope.selectTheme = function (theme) { - setTheme(theme, true); - } - - $scope.toggleLevels = function (value) { - const levels = $scope.levels; - for (const key in levels) { - if (levels.hasOwnProperty(key)) { - levels[key] = value; - } - } - }; - - $scope.toggleGroups = function (value) { - const groups = $scope.groups; - for (const key in groups) { - if (groups.hasOwnProperty(key)) { - groups[key] = value; - } - } - }; - - $scope.resetGroupsToDefault = function () { - $scope.groups = { - ...GROUPS_FILTER_DEFAULT - }; - }; - - $scope.selectedValuesCount = function (obj) { - return Object.values(obj).filter(x => x).length; - } - - $scope.clearVersionFilters = function () { - for (let filter in $scope.versionFilters) { - $scope.versionFilters[filter] = { enabled: false, minorVersion: null }; - } - } - - $scope.versionFilterCount = function(obj) { - return Object.values(obj).filter(x => x.enabled).length; - } - - $scope.updateVersionFilters = function() { - for (const filter in $scope.versionFilters) { - let minorVersion = $scope.versionFilters[filter].minorVersion; - - // 1.29.0 and greater - if (minorVersion && minorVersion > 28) { - $scope.versionFilters[filter].enabled = true; - continue; - } - - $scope.versionFilters[filter].enabled = false; - } - } - - $scope.byVersion = function(lint) { - let filters = $scope.versionFilters; - for (const filter in filters) { - if (filters[filter].enabled) { - let minorVersion = filters[filter].minorVersion; - - // Strip the "pre " prefix for pre 1.29.0 lints - let lintVersion = lint.version.startsWith("pre ") ? lint.version.substring(4, lint.version.length) : lint.version; - let lintMinorVersion = lintVersion.substring(2, 4); - - switch (filter) { - // "=" gets the highest priority, since all filters are inclusive - case "=": - return (lintMinorVersion == minorVersion); - case "≥": - if (lintMinorVersion < minorVersion) { return false; } - break; - case "≤": - if (lintMinorVersion > minorVersion) { return false; } - break; - default: - return true - } - } - } - - return true; - } - - $scope.byGroups = function (lint) { - return $scope.groups[lint.group]; - }; - - $scope.bySearch = function (lint, index, array) { - let searchStr = $scope.search; - // It can be `null` I haven't missed this value - if (searchStr == null || searchStr.length < 3) { - return true; - } - searchStr = searchStr.toLowerCase(); - if (searchStr.startsWith("clippy::")) { - searchStr = searchStr.slice(8); - } - - // Search by id - if (lint.id.indexOf(searchStr.replaceAll("-", "_")) !== -1) { - return true; - } - - // Search the description - // The use of `for`-loops instead of `foreach` enables us to return early - let terms = searchStr.split(" "); - let docsLowerCase = lint.docs.toLowerCase(); - for (index = 0; index < terms.length; index++) { - // This is more likely and will therefore be checked first - if (docsLowerCase.indexOf(terms[index]) !== -1) { - continue; - } - - if (lint.id.indexOf(terms[index]) !== -1) { - continue; - } - - return false; - } - - return true; - } - - // Show details for one lint - $scope.openLint = function (lint) { - $scope.open[lint.id] = true; - $location.path(lint.id); - }; - - $scope.copyToClipboard = function (lint) { - const clipboard = document.getElementById("clipboard-" + lint.id); - if (clipboard) { - let resetClipboardTimeout = null; - let resetClipboardIcon = clipboard.innerHTML; - - function resetClipboard() { - resetClipboardTimeout = null; - clipboard.innerHTML = resetClipboardIcon; - } - - navigator.clipboard.writeText("clippy::" + lint.id); - - clipboard.innerHTML = "✓"; - if (resetClipboardTimeout !== null) { - clearTimeout(resetClipboardTimeout); - } - resetClipboardTimeout = setTimeout(resetClipboard, 1000); - } - } - - // Get data - $scope.open = {}; - $scope.loading = true; - - // This will be used to jump into the source code of the version that this documentation is for. - $scope.docVersion = window.location.pathname.split('/')[2] || "master"; - - // Set up the filters from the URL parameters before we start loading the data - loadFromURLParameters(); - - $http.get('./lints.json') - .success(function (data) { - $scope.data = data; - $scope.loading = false; - - var selectedGroup = getQueryVariable("sel"); - if (selectedGroup) { - selectGroup($scope, selectedGroup.toLowerCase()); - } - - scrollToLintByURL($scope, $location); - - setTimeout(function () { - var el = document.getElementById('filter-input'); - if (el) { el.focus() } - }, 0); - }) - .error(function (data) { - $scope.error = data; - $scope.loading = false; - }); - }); -})(); - -function getQueryVariable(variable) { - var query = window.location.search.substring(1); - var vars = query.split('&'); - for (var i = 0; i < vars.length; i++) { - var pair = vars[i].split('='); - if (decodeURIComponent(pair[0]) == variable) { - return decodeURIComponent(pair[1]); - } - } -} - -function setTheme(theme, store) { - let enableHighlight = false; - let enableNight = false; - let enableAyu = false; - - switch(theme) { - case "ayu": - enableAyu = true; - break; - case "coal": - case "navy": - enableNight = true; - break; - case "rust": - enableHighlight = true; - break; - default: - enableHighlight = true; - theme = "light"; - break; - } - - document.getElementsByTagName("body")[0].className = theme; - - document.getElementById("githubLightHighlight").disabled = enableNight || !enableHighlight; - document.getElementById("githubDarkHighlight").disabled = !enableNight && !enableAyu; - - document.getElementById("styleHighlight").disabled = !enableHighlight; - document.getElementById("styleNight").disabled = !enableNight; - document.getElementById("styleAyu").disabled = !enableAyu; - - if (store) { - try { - localStorage.setItem('clippy-lint-list-theme', theme); - } catch (e) { } - } -} - -// loading the theme after the initial load -const prefersDark = window.matchMedia("(prefers-color-scheme: dark)"); -const theme = localStorage.getItem('clippy-lint-list-theme'); -if (prefersDark.matches && !theme) { - setTheme("coal", false); -} else { - setTheme(theme, false); -} diff --git a/util/gh-pages/versions.html b/util/gh-pages/versions.html deleted file mode 100644 index 31ce88193295..000000000000 --- a/util/gh-pages/versions.html +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - Clippy lints documentation - - - - - -
- - - - - - - - - - diff --git a/util/versions.py b/util/versions.py deleted file mode 100755 index c041fc606a8f..000000000000 --- a/util/versions.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python - -import json -import logging as log -import os -import sys - -log.basicConfig(level=log.INFO, format="%(levelname)s: %(message)s") - - -def key(v): - if v == "master": - return float("inf") - if v == "stable": - return sys.maxsize - if v == "beta": - return sys.maxsize - 1 - if v == "pre-1.29.0": - return -1 - - v = v.replace("rust-", "") - - s = 0 - for i, val in enumerate(v.split(".")[::-1]): - s += int(val) * 100**i - - return s - - -def main(): - if len(sys.argv) < 2: - log.error("specify output directory") - return - - outdir = sys.argv[1] - versions = [ - dir - for dir in os.listdir(outdir) - if not dir.startswith(".") - and not dir.startswith("v") - and os.path.isdir(os.path.join(outdir, dir)) - ] - versions.sort(key=key) - - with open(os.path.join(outdir, "versions.json"), "w") as fp: - json.dump(versions, fp, indent=2) - log.info("wrote JSON for great justice") - - -if __name__ == "__main__": - main() From 17cf2540cbeba5f3e38eb38b7c3ef972629a45fb Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 15 May 2024 11:51:55 -0400 Subject: [PATCH 1177/1222] Fix tools --- clippy_lints/src/derive.rs | 4 ++-- clippy_utils/src/ty.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 9662c8f4fe2f..bb6d8b180a0d 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -11,7 +11,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::traits::Reveal; use rustc_middle::ty::{ - self, ClauseKind, GenericArgKind, GenericParamDefKind, ParamEnv, ToPredicate, TraitPredicate, Ty, TyCtxt, + self, ClauseKind, GenericArgKind, GenericParamDefKind, ParamEnv, Upcast, TraitPredicate, Ty, TyCtxt, }; use rustc_session::declare_lint_pass; use rustc_span::def_id::LocalDefId; @@ -503,7 +503,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]), polarity: ty::PredicatePolarity::Positive, }) - .to_predicate(tcx) + .upcast(tcx) }), )), Reveal::UserFacing, diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index e3ab42c3107c..b604f3ff65fc 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -18,7 +18,7 @@ use rustc_middle::traits::EvaluationResult; use rustc_middle::ty::layout::ValidityRequirement; use rustc_middle::ty::{ self, AdtDef, AliasTy, AssocKind, Binder, BoundRegion, FnSig, GenericArg, GenericArgKind, GenericArgsRef, - GenericParamDefKind, IntTy, ParamEnv, Region, RegionKind, ToPredicate, TraitRef, Ty, TyCtxt, + GenericParamDefKind, IntTy, ParamEnv, Region, RegionKind, Upcast, TraitRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, UintTy, VariantDef, VariantDiscr, }; use rustc_span::symbol::Ident; @@ -311,7 +311,7 @@ pub fn implements_trait_with_env_from_iter<'tcx>( cause: ObligationCause::dummy(), param_env, recursion_depth: 0, - predicate: Binder::dummy(trait_ref).to_predicate(tcx), + predicate: Binder::dummy(trait_ref).upcast(tcx), }; infcx .evaluate_obligation(&obligation) From 66ea064d02bb156bf47d5f85d22b0a53a58826db Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 15 May 2024 12:52:12 -0400 Subject: [PATCH 1178/1222] Remove trivial Binder::dummy calls --- clippy_utils/src/ty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index b604f3ff65fc..50c387bd59ec 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -311,7 +311,7 @@ pub fn implements_trait_with_env_from_iter<'tcx>( cause: ObligationCause::dummy(), param_env, recursion_depth: 0, - predicate: Binder::dummy(trait_ref).upcast(tcx), + predicate: trait_ref.upcast(tcx), }; infcx .evaluate_obligation(&obligation) From 0ee4ca5306a4d27fa91c3b2390752bc92a99fde1 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 17 May 2024 14:17:48 -0300 Subject: [PATCH 1179/1222] Rename Unsafe to Safety --- clippy_lints/src/derive.rs | 4 ++-- clippy_lints/src/doc/missing_headers.rs | 8 ++++---- clippy_lints/src/doc/mod.rs | 6 +++--- clippy_lints/src/eta_reduction.rs | 12 +++++------- clippy_lints/src/functions/misnamed_getters.rs | 4 ++-- .../src/functions/not_unsafe_ptr_arg_deref.rs | 16 ++++++++-------- clippy_lints/src/inherent_to_string.rs | 4 ++-- clippy_lints/src/methods/mod.rs | 6 ++---- .../src/multiple_unsafe_ops_per_block.rs | 6 +++--- clippy_lints/src/new_without_default.rs | 2 +- clippy_lints/src/ptr.rs | 4 ++-- clippy_lints/src/undocumented_unsafe_blocks.rs | 4 ++-- clippy_utils/src/ast_utils.rs | 16 ++++++++-------- clippy_utils/src/check_proc_macro.rs | 11 +++++------ clippy_utils/src/hir_utils.rs | 2 +- clippy_utils/src/ty.rs | 4 ++-- clippy_utils/src/visitors.rs | 10 +++++----- 17 files changed, 57 insertions(+), 62 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 9662c8f4fe2f..53e0cef361aa 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -5,7 +5,7 @@ use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, Visitor}; use rustc_hir::{ - self as hir, BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, Impl, Item, ItemKind, UnsafeSource, Unsafety, + self as hir, BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, Safety, Impl, Item, ItemKind, UnsafeSource, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; @@ -415,7 +415,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> { } if let Some(header) = kind.header() - && header.unsafety == Unsafety::Unsafe + && header.safety == Safety::Unsafe { self.has_unsafe = true; } diff --git a/clippy_lints/src/doc/missing_headers.rs b/clippy_lints/src/doc/missing_headers.rs index f935ae2e3e48..36ba19698c72 100644 --- a/clippy_lints/src/doc/missing_headers.rs +++ b/clippy_lints/src/doc/missing_headers.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_note}; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; use clippy_utils::{is_doc_hidden, return_ty}; -use rustc_hir::{BodyId, FnSig, OwnerId, Unsafety}; +use rustc_hir::{BodyId, FnSig, OwnerId, Safety}; use rustc_lint::LateContext; use rustc_middle::ty; use rustc_span::{sym, Span}; @@ -33,14 +33,14 @@ pub fn check( } let span = cx.tcx.def_span(owner_id); - match (headers.safety, sig.header.unsafety) { - (false, Unsafety::Unsafe) => span_lint( + match (headers.safety, sig.header.safety) { + (false, Safety::Unsafe) => span_lint( cx, MISSING_SAFETY_DOC, span, "unsafe function's docs miss `# Safety` section", ), - (true, Unsafety::Normal) => span_lint( + (true, Safety::Safe) => span_lint( cx, UNNECESSARY_SAFETY_DOC, span, diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 4bced104d3bc..7fdb582e6403 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -12,7 +12,7 @@ use pulldown_cmark::{BrokenLink, CodeBlockKind, CowStr, Options}; use rustc_ast::ast::Attribute; use rustc_data_structures::fx::FxHashSet; use rustc_hir::intravisit::{self, Visitor}; -use rustc_hir::{AnonConst, Expr, ImplItemKind, ItemKind, Node, TraitItemKind, Unsafety}; +use rustc_hir::{AnonConst, Expr, ImplItemKind, ItemKind, Node, Safety, TraitItemKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; @@ -415,13 +415,13 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { } }, ItemKind::Trait(_, unsafety, ..) => match (headers.safety, unsafety) { - (false, Unsafety::Unsafe) => span_lint( + (false, Safety::Unsafe) => span_lint( cx, MISSING_SAFETY_DOC, cx.tcx.def_span(item.owner_id), "docs for unsafe trait missing `# Safety` section", ), - (true, Unsafety::Normal) => span_lint( + (true, Safety::Safe) => span_lint( cx, UNNECESSARY_SAFETY_DOC, cx.tcx.def_span(item.owner_id), diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 306a4a9e55c9..b58018ca0353 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -5,7 +5,7 @@ use clippy_utils::ty::type_diagnostic_name; use clippy_utils::usage::{local_used_after_expr, local_used_in}; use clippy_utils::{get_path_from_caller_to_method_type, is_adjusted, path_to_local, path_to_local_id}; use rustc_errors::Applicability; -use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, Param, PatKind, QPath, TyKind, Unsafety}; +use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, Param, PatKind, QPath, Safety, TyKind}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{ @@ -146,7 +146,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { ty::FnPtr(sig) => sig.skip_binder(), ty::Closure(_, subs) => cx .tcx - .signature_unclosure(subs.as_closure().sig(), Unsafety::Normal) + .signature_unclosure(subs.as_closure().sig(), Safety::Safe) .skip_binder(), _ => { if typeck.type_dependent_def_id(body.value.hir_id).is_some() @@ -154,7 +154,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { && let output = typeck.expr_ty(body.value) && let ty::Tuple(tys) = *subs.type_at(1).kind() { - cx.tcx.mk_fn_sig(tys, output, false, Unsafety::Normal, Abi::Rust) + cx.tcx.mk_fn_sig(tys, output, false, Safety::Safe, Abi::Rust) } else { return; } @@ -241,11 +241,9 @@ fn check_inputs( } fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure: ClosureArgs<'tcx>, call_sig: FnSig<'_>) -> bool { - call_sig.unsafety == Unsafety::Normal + call_sig.safety == Safety::Safe && !has_late_bound_to_non_late_bound_regions( - cx.tcx - .signature_unclosure(closure.sig(), Unsafety::Normal) - .skip_binder(), + cx.tcx.signature_unclosure(closure.sig(), Safety::Safe).skip_binder(), call_sig, ) } diff --git a/clippy_lints/src/functions/misnamed_getters.rs b/clippy_lints/src/functions/misnamed_getters.rs index 8ac17e17688d..7729c556e1fc 100644 --- a/clippy_lints/src/functions/misnamed_getters.rs +++ b/clippy_lints/src/functions/misnamed_getters.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; -use rustc_hir::{Body, ExprKind, FnDecl, ImplicitSelfKind, Unsafety}; +use rustc_hir::{Body, ExprKind, FnDecl, Safety, ImplicitSelfKind}; use rustc_lint::LateContext; use rustc_middle::ty; use rustc_span::Span; @@ -34,7 +34,7 @@ pub fn check_fn(cx: &LateContext<'_>, kind: FnKind<'_>, decl: &FnDecl<'_>, body: ImplicitSelfKind::None => return, }; - let name = if sig.header.unsafety == Unsafety::Unsafe { + let name = if sig.header.safety == Safety::Unsafe { name.strip_suffix("_unchecked").unwrap_or(name) } else { name diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index 995dd782cbbd..b44a5f20ef68 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -19,30 +19,30 @@ pub(super) fn check_fn<'tcx>( body: &'tcx hir::Body<'tcx>, def_id: LocalDefId, ) { - let unsafety = match kind { - intravisit::FnKind::ItemFn(_, _, hir::FnHeader { unsafety, .. }) => unsafety, - intravisit::FnKind::Method(_, sig) => sig.header.unsafety, + let safety = match kind { + intravisit::FnKind::ItemFn(_, _, hir::FnHeader { safety, .. }) => safety, + intravisit::FnKind::Method(_, sig) => sig.header.safety, intravisit::FnKind::Closure => return, }; - check_raw_ptr(cx, unsafety, decl, body, def_id); + check_raw_ptr(cx, safety, decl, body, def_id); } pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { if let hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(eid)) = item.kind { let body = cx.tcx.hir().body(eid); - check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.owner_id.def_id); + check_raw_ptr(cx, sig.header.safety, sig.decl, body, item.owner_id.def_id); } } fn check_raw_ptr<'tcx>( cx: &LateContext<'tcx>, - unsafety: hir::Unsafety, + safety: hir::Safety, decl: &'tcx hir::FnDecl<'tcx>, body: &'tcx hir::Body<'tcx>, def_id: LocalDefId, ) { - if unsafety == hir::Unsafety::Normal && cx.effective_visibilities.is_exported(def_id) { + if safety == hir::Safety::Safe && cx.effective_visibilities.is_exported(def_id) { let raw_ptrs = iter_input_pats(decl, body) .filter_map(|arg| raw_ptr_arg(cx, arg)) .collect::(); @@ -58,7 +58,7 @@ fn check_raw_ptr<'tcx>( }, hir::ExprKind::MethodCall(_, recv, args, _) => { let def_id = typeck.type_dependent_def_id(e.hir_id).unwrap(); - if cx.tcx.fn_sig(def_id).skip_binder().skip_binder().unsafety == hir::Unsafety::Unsafe { + if cx.tcx.fn_sig(def_id).skip_binder().skip_binder().safety == hir::Safety::Unsafe { check_arg(cx, &raw_ptrs, recv); for arg in args { check_arg(cx, &raw_ptrs, arg); diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index 157f61059847..9aedf5ec7e85 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::{implements_trait, is_type_lang_item}; use clippy_utils::{return_ty, trait_ref_of_method}; -use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind, LangItem, Unsafety}; +use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind, LangItem, Safety}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; use rustc_span::sym; @@ -99,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString { if let ImplItemKind::Fn(ref signature, _) = impl_item.kind // #11201 && let header = signature.header - && header.unsafety == Unsafety::Normal + && header.safety == Safety::Safe && header.abi == Abi::Rust && impl_item.ident.name == sym::to_string && let decl = signature.decl diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 63545d6c5035..2b92bff016db 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -5038,7 +5038,7 @@ fn lint_binary_expr_with_method_call(cx: &LateContext<'_>, info: &mut BinaryExpr } const FN_HEADER: hir::FnHeader = hir::FnHeader { - unsafety: hir::Unsafety::Normal, + safety: hir::Safety::Safe, constness: hir::Constness::NotConst, asyncness: hir::IsAsync::NotAsync, abi: rustc_target::spec::abi::Abi::Rust, @@ -5214,7 +5214,5 @@ impl OutType { } fn fn_header_equals(expected: hir::FnHeader, actual: hir::FnHeader) -> bool { - expected.constness == actual.constness - && expected.unsafety == actual.unsafety - && expected.asyncness == actual.asyncness + expected.constness == actual.constness && expected.safety == actual.safety && expected.asyncness == actual.asyncness } diff --git a/clippy_lints/src/multiple_unsafe_ops_per_block.rs b/clippy_lints/src/multiple_unsafe_ops_per_block.rs index 0e1380667805..5306205aed7e 100644 --- a/clippy_lints/src/multiple_unsafe_ops_per_block.rs +++ b/clippy_lints/src/multiple_unsafe_ops_per_block.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::visitors::{for_each_expr_with_closures, Descend, Visitable}; use core::ops::ControlFlow::Continue; use hir::def::{DefKind, Res}; -use hir::{BlockCheckMode, ExprKind, QPath, UnOp, Unsafety}; +use hir::{BlockCheckMode, ExprKind, Safety, QPath, UnOp}; use rustc_ast::Mutability; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; @@ -133,7 +133,7 @@ fn collect_unsafe_exprs<'tcx>( ty::FnPtr(sig) => sig, _ => return Continue(Descend::Yes), }; - if sig.unsafety() == Unsafety::Unsafe { + if sig.safety() == Safety::Unsafe { unsafe_ops.push(("unsafe function call occurs here", expr.span)); } }, @@ -144,7 +144,7 @@ fn collect_unsafe_exprs<'tcx>( .type_dependent_def_id(expr.hir_id) .map(|def_id| cx.tcx.fn_sig(def_id)) { - if sig.skip_binder().unsafety() == Unsafety::Unsafe { + if sig.skip_binder().safety() == Safety::Unsafe { unsafe_ops.push(("unsafe method call occurs here", expr.span)); } } diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 78dd1e051627..b60fea3f03e0 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { if let hir::ImplItemKind::Fn(ref sig, _) = impl_item.kind { let name = impl_item.ident.name; let id = impl_item.owner_id; - if sig.header.unsafety == hir::Unsafety::Unsafe { + if sig.header.safety == hir::Safety::Unsafe { // can't be implemented for unsafe new return; } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 2534e3c8468c..65929cd5fea9 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -12,7 +12,7 @@ use rustc_hir::hir_id::{HirId, HirIdMap}; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{ self as hir, AnonConst, BinOpKind, BindingMode, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg, ImplItemKind, - ItemKind, Lifetime, Mutability, Node, Param, PatKind, QPath, TraitFn, TraitItem, TraitItemKind, TyKind, Unsafety, + ItemKind, Lifetime, Mutability, Node, Param, PatKind, QPath, Safety, TraitFn, TraitItem, TraitItemKind, TyKind, }; use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::traits::{Obligation, ObligationCause}; @@ -542,7 +542,7 @@ fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Optio if let Some(args) = args && !args.is_empty() && body.map_or(true, |body| { - sig.header.unsafety == Unsafety::Unsafe || contains_unsafe_block(cx, body.value) + sig.header.safety == Safety::Unsafe || contains_unsafe_block(cx, body.value) }) { span_lint_and_then( diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index cbd161800770..4120bb1331bd 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -200,7 +200,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks { let item_has_safety_comment = item_has_safety_comment(cx, item); match (&item.kind, item_has_safety_comment) { // lint unsafe impl without safety comment - (ItemKind::Impl(impl_), HasSafetyComment::No) if impl_.unsafety == hir::Unsafety::Unsafe => { + (ItemKind::Impl(impl_), HasSafetyComment::No) if impl_.safety == hir::Safety::Unsafe => { if !is_lint_allowed(cx, UNDOCUMENTED_UNSAFE_BLOCKS, item.hir_id()) && !is_unsafe_from_proc_macro(cx, item.span) { @@ -222,7 +222,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks { } }, // lint safe impl with unnecessary safety comment - (ItemKind::Impl(impl_), HasSafetyComment::Yes(pos)) if impl_.unsafety == hir::Unsafety::Normal => { + (ItemKind::Impl(impl_), HasSafetyComment::Yes(pos)) if impl_.safety == hir::Safety::Safe => { if !is_lint_allowed(cx, UNNECESSARY_SAFETY_COMMENT, item.hir_id()) { let (span, help_span) = mk_spans(pos); diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index d3bbc66bcaea..d4a5f547211a 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -386,21 +386,21 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { ( Trait(box ast::Trait { is_auto: la, - unsafety: lu, + safety: lu, generics: lg, bounds: lb, items: li, }), Trait(box ast::Trait { is_auto: ra, - unsafety: ru, + safety: ru, generics: rg, bounds: rb, items: ri, }), ) => { la == ra - && matches!(lu, Unsafe::No) == matches!(ru, Unsafe::No) + && matches!(lu, Safety::Default) == matches!(ru, Safety::Default) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound) && over(li, ri, |l, r| eq_item(l, r, eq_assoc_item_kind)) @@ -408,7 +408,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { (TraitAlias(lg, lb), TraitAlias(rg, rb)) => eq_generics(lg, rg) && over(lb, rb, eq_generic_bound), ( Impl(box ast::Impl { - unsafety: lu, + safety: lu, polarity: lp, defaultness: ld, constness: lc, @@ -418,7 +418,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { items: li, }), Impl(box ast::Impl { - unsafety: ru, + safety: ru, polarity: rp, defaultness: rd, constness: rc, @@ -428,7 +428,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { items: ri, }), ) => { - matches!(lu, Unsafe::No) == matches!(ru, Unsafe::No) + matches!(lu, Safety::Default) == matches!(ru, Safety::Default) && matches!(lp, ImplPolarity::Positive) == matches!(rp, ImplPolarity::Positive) && eq_defaultness(*ld, *rd) && matches!(lc, ast::Const::No) == matches!(rc, ast::Const::No) @@ -605,7 +605,7 @@ fn eq_opt_coroutine_kind(l: Option, r: Option) -> } pub fn eq_fn_header(l: &FnHeader, r: &FnHeader) -> bool { - matches!(l.unsafety, Unsafe::No) == matches!(r.unsafety, Unsafe::No) + matches!(l.safety, Safety::Default) == matches!(r.safety, Safety::Default) && eq_opt_coroutine_kind(l.coroutine_kind, r.coroutine_kind) && matches!(l.constness, Const::No) == matches!(r.constness, Const::No) && eq_ext(&l.ext, &r.ext) @@ -712,7 +712,7 @@ pub fn eq_ty(l: &Ty, r: &Ty) -> bool { both(ll, rl, |l, r| eq_id(l.ident, r.ident)) && l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty) }, (BareFn(l), BareFn(r)) => { - l.unsafety == r.unsafety + l.safety == r.safety && eq_ext(&l.ext, &r.ext) && over(&l.generic_params, &r.generic_params, eq_generic_param) && eq_fn_decl(&l.decl, &r.decl) diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index 422673105136..553e89999750 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -18,8 +18,8 @@ use rustc_ast::AttrStyle; use rustc_hir::intravisit::FnKind; use rustc_hir::{ Block, BlockCheckMode, Body, Closure, Destination, Expr, ExprKind, FieldDef, FnHeader, FnRetTy, HirId, Impl, - ImplItem, ImplItemKind, IsAuto, Item, ItemKind, LoopSource, MatchSource, MutTy, Node, QPath, TraitItem, - TraitItemKind, Ty, TyKind, UnOp, UnsafeSource, Unsafety, Variant, VariantData, YieldSource, + ImplItem, ImplItemKind, IsAuto, Item, ItemKind, LoopSource, MatchSource, MutTy, Node, QPath, Safety, TraitItem, + TraitItemKind, Ty, TyKind, UnOp, UnsafeSource, Variant, VariantData, YieldSource, }; use rustc_lint::{LateContext, LintContext}; use rustc_middle::ty::TyCtxt; @@ -207,10 +207,9 @@ fn item_search_pat(item: &Item<'_>) -> (Pat, Pat) { ItemKind::Struct(VariantData::Struct { .. }, _) => (Pat::Str("struct"), Pat::Str("}")), ItemKind::Struct(..) => (Pat::Str("struct"), Pat::Str(";")), ItemKind::Union(..) => (Pat::Str("union"), Pat::Str("}")), - ItemKind::Trait(_, Unsafety::Unsafe, ..) + ItemKind::Trait(_, Safety::Unsafe, ..) | ItemKind::Impl(Impl { - unsafety: Unsafety::Unsafe, - .. + safety: Safety::Unsafe, .. }) => (Pat::Str("unsafe"), Pat::Str("}")), ItemKind::Trait(IsAuto::Yes, ..) => (Pat::Str("auto"), Pat::Str("}")), ItemKind::Trait(..) => (Pat::Str("trait"), Pat::Str("}")), @@ -323,7 +322,7 @@ fn ty_search_pat(ty: &Ty<'_>) -> (Pat, Pat) { TyKind::Ptr(MutTy { ty, .. }) => (Pat::Str("*"), ty_search_pat(ty).1), TyKind::Ref(_, MutTy { ty, .. }) => (Pat::Str("&"), ty_search_pat(ty).1), TyKind::BareFn(bare_fn) => ( - if bare_fn.unsafety == Unsafety::Unsafe { + if bare_fn.safety == Safety::Unsafe { Pat::Str("unsafe") } else if bare_fn.abi != Abi::Rust { Pat::Str("extern") diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index c921168df290..9f285621e0c9 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -1082,7 +1082,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { mut_ty.mutbl.hash(&mut self.s); }, TyKind::BareFn(bfn) => { - bfn.unsafety.hash(&mut self.s); + bfn.safety.hash(&mut self.s); bfn.abi.hash(&mut self.s); for arg in bfn.decl.inputs { self.hash_ty(arg); diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index e3ab42c3107c..4f71453d8db8 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -9,7 +9,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; -use rustc_hir::{Expr, FnDecl, LangItem, TyKind, Unsafety}; +use rustc_hir::{Expr, FnDecl, Safety, LangItem, TyKind}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::mir::interpret::Scalar; @@ -562,7 +562,7 @@ pub fn peel_mid_ty_refs_is_mutable(ty: Ty<'_>) -> (Ty<'_>, usize, Mutability) { /// Returns `true` if the given type is an `unsafe` function. pub fn type_is_unsafe_function<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { match ty.kind() { - ty::FnDef(..) | ty::FnPtr(_) => ty.fn_sig(cx.tcx).unsafety() == Unsafety::Unsafe, + ty::FnDef(..) | ty::FnPtr(_) => ty.fn_sig(cx.tcx).safety() == Safety::Unsafe, _ => false, } } diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index a3f3b32ed372..90b56297bb55 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -6,7 +6,7 @@ use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::intravisit::{self, walk_block, walk_expr, Visitor}; use rustc_hir::{ AnonConst, Arm, Block, BlockCheckMode, Body, BodyId, Expr, ExprKind, HirId, ItemId, ItemKind, LetExpr, Pat, QPath, - Stmt, UnOp, UnsafeSource, Unsafety, + Safety, Stmt, UnOp, UnsafeSource, }; use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; @@ -421,16 +421,16 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool { .typeck_results() .type_dependent_def_id(e.hir_id) .map_or(false, |id| { - self.cx.tcx.fn_sig(id).skip_binder().unsafety() == Unsafety::Unsafe + self.cx.tcx.fn_sig(id).skip_binder().safety() == Safety::Unsafe }) => { self.is_unsafe = true; }, ExprKind::Call(func, _) => match *self.cx.typeck_results().expr_ty(func).peel_refs().kind() { - ty::FnDef(id, _) if self.cx.tcx.fn_sig(id).skip_binder().unsafety() == Unsafety::Unsafe => { + ty::FnDef(id, _) if self.cx.tcx.fn_sig(id).skip_binder().safety() == Safety::Unsafe => { self.is_unsafe = true; }, - ty::FnPtr(sig) if sig.unsafety() == Unsafety::Unsafe => self.is_unsafe = true, + ty::FnPtr(sig) if sig.safety() == Safety::Unsafe => self.is_unsafe = true, _ => walk_expr(self, e), }, ExprKind::Path(ref p) @@ -452,7 +452,7 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool { } fn visit_nested_item(&mut self, id: ItemId) { if let ItemKind::Impl(i) = &self.cx.tcx.hir().item(id).kind { - self.is_unsafe = i.unsafety == Unsafety::Unsafe; + self.is_unsafe = i.safety == Safety::Unsafe; } } } From d9742beb3b68b25ced882d269d95278a5656ee31 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Thu, 16 May 2024 03:00:48 -0700 Subject: [PATCH 1180/1222] Fix clippy --- clippy_utils/src/mir/possible_borrower.rs | 4 ++-- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_utils/src/mir/possible_borrower.rs b/clippy_utils/src/mir/possible_borrower.rs index 06229ac938f9..7b4fd8a210ed 100644 --- a/clippy_utils/src/mir/possible_borrower.rs +++ b/clippy_utils/src/mir/possible_borrower.rs @@ -149,7 +149,7 @@ impl TypeVisitor> for ContainsRegion { } fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) { - use rustc_middle::mir::Rvalue::{Aggregate, BinaryOp, Cast, CheckedBinaryOp, Repeat, UnaryOp, Use}; + use rustc_middle::mir::Rvalue::{Aggregate, BinaryOp, Cast, Repeat, UnaryOp, Use}; let mut visit_op = |op: &mir::Operand<'_>| match op { mir::Operand::Copy(p) | mir::Operand::Move(p) => visit(p.local), @@ -159,7 +159,7 @@ fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) { match rvalue { Use(op) | Repeat(op, _) | Cast(_, op, _) | UnaryOp(_, op) => visit_op(op), Aggregate(_, ops) => ops.iter().for_each(visit_op), - BinaryOp(_, box (lhs, rhs)) | CheckedBinaryOp(_, box (lhs, rhs)) => { + BinaryOp(_, box (lhs, rhs)) => { visit_op(lhs); visit_op(rhs); }, diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 95851a2eed81..ff9f06531ea1 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -161,7 +161,7 @@ fn check_rvalue<'tcx>( "transmute can attempt to turn pointers into integers, so is unstable in const fn".into(), )), // binops are fine on integers - Rvalue::BinaryOp(_, box (lhs, rhs)) | Rvalue::CheckedBinaryOp(_, box (lhs, rhs)) => { + Rvalue::BinaryOp(_, box (lhs, rhs)) => { check_operand(tcx, lhs, span, body)?; check_operand(tcx, rhs, span, body)?; let ty = lhs.ty(body, tcx); From e46e97dd1f7c91a0cd718412566288e595bc0583 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Sat, 18 May 2024 18:08:11 +0200 Subject: [PATCH 1181/1222] Fix typos (taking into account review comments) --- clippy_lints/src/methods/needless_collect.rs | 2 +- tests/ui/ptr_arg.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index 1c695655536c..f26f164fa54a 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -127,7 +127,7 @@ pub(super) fn check<'tcx>( } } -/// checks for for collecting into a (generic) method or function argument +/// checks for collecting into a (generic) method or function argument /// taking an `IntoIterator` fn check_collect_into_intoiterator<'tcx>( cx: &LateContext<'tcx>, diff --git a/tests/ui/ptr_arg.rs b/tests/ui/ptr_arg.rs index fcd716f41444..5d6e488972cd 100644 --- a/tests/ui/ptr_arg.rs +++ b/tests/ui/ptr_arg.rs @@ -282,7 +282,7 @@ mod issue_9218 { todo!() } - // These two's return types don't use use 'a so it's not okay + // These two's return types don't use 'a so it's not okay fn cow_bad_ret_ty_1<'a>(input: &'a Cow<'a, str>) -> &'static str { //~^ ERROR: using a reference to `Cow` is not recommended todo!() From 5e942a1a24672f5c1212c6c0676fec6a939b6195 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 11 May 2024 11:46:25 +0200 Subject: [PATCH 1182/1222] Add and use generics.is_empty() and generics.is_own_empty, rather than using generics' attributes --- clippy_lints/src/iter_without_into_iter.rs | 2 +- clippy_utils/src/ty/type_certainty/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/iter_without_into_iter.rs b/clippy_lints/src/iter_without_into_iter.rs index a75dfaf286fd..601d0e151aae 100644 --- a/clippy_lints/src/iter_without_into_iter.rs +++ b/clippy_lints/src/iter_without_into_iter.rs @@ -225,7 +225,7 @@ impl {self_ty_without_ref} {{ && let ImplItemKind::Fn(sig, _) = item.kind && let FnRetTy::Return(ret) = sig.decl.output && is_nameable_in_impl_trait(ret) - && cx.tcx.generics_of(item_did).own_params.is_empty() + && cx.tcx.generics_of(item_did).is_own_empty() && sig.decl.implicit_self == expected_implicit_self && sig.decl.inputs.len() == 1 && let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id()) diff --git a/clippy_utils/src/ty/type_certainty/mod.rs b/clippy_utils/src/ty/type_certainty/mod.rs index c2ff19931d5c..802193034502 100644 --- a/clippy_utils/src/ty/type_certainty/mod.rs +++ b/clippy_utils/src/ty/type_certainty/mod.rs @@ -176,7 +176,7 @@ fn qpath_certainty(cx: &LateContext<'_>, qpath: &QPath<'_>, resolves_to_type: bo .get(*lang_item) .map_or(Certainty::Uncertain, |def_id| { let generics = cx.tcx.generics_of(def_id); - if generics.parent_count == 0 && generics.own_params.is_empty() { + if generics.is_empty() { Certainty::Certain(if resolves_to_type { Some(def_id) } else { None }) } else { Certainty::Uncertain From 93a77ae21a51b7498011788e1fe8dd9398961f37 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 17 Apr 2024 19:54:06 -0400 Subject: [PATCH 1183/1222] Remove a clippy test that doesn't apply anymore --- tests/ui/into_iter_on_ref.fixed | 1 - tests/ui/into_iter_on_ref.rs | 1 - tests/ui/into_iter_on_ref.stderr | 58 ++++++++++++++------------------ 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/tests/ui/into_iter_on_ref.fixed b/tests/ui/into_iter_on_ref.fixed index c03d91c797c8..72b39c982bf7 100644 --- a/tests/ui/into_iter_on_ref.fixed +++ b/tests/ui/into_iter_on_ref.fixed @@ -11,7 +11,6 @@ fn main() { let _ = vec![1, 2, 3].into_iter(); let _ = (&vec![1, 2, 3]).iter(); //~ ERROR: equivalent to `.iter() - let _ = vec![1, 2, 3].into_boxed_slice().iter(); //~ ERROR: equivalent to `.iter() let _ = std::rc::Rc::from(&[X][..]).iter(); //~ ERROR: equivalent to `.iter() let _ = std::sync::Arc::from(&[X][..]).iter(); //~ ERROR: equivalent to `.iter() diff --git a/tests/ui/into_iter_on_ref.rs b/tests/ui/into_iter_on_ref.rs index 93c732fd6ccf..5ba224720d34 100644 --- a/tests/ui/into_iter_on_ref.rs +++ b/tests/ui/into_iter_on_ref.rs @@ -11,7 +11,6 @@ fn main() { let _ = vec![1, 2, 3].into_iter(); let _ = (&vec![1, 2, 3]).into_iter(); //~ ERROR: equivalent to `.iter() - let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); //~ ERROR: equivalent to `.iter() let _ = std::rc::Rc::from(&[X][..]).into_iter(); //~ ERROR: equivalent to `.iter() let _ = std::sync::Arc::from(&[X][..]).into_iter(); //~ ERROR: equivalent to `.iter() diff --git a/tests/ui/into_iter_on_ref.stderr b/tests/ui/into_iter_on_ref.stderr index 0e9d485f1a9d..64d814074da4 100644 --- a/tests/ui/into_iter_on_ref.stderr +++ b/tests/ui/into_iter_on_ref.stderr @@ -8,160 +8,154 @@ LL | let _ = (&vec![1, 2, 3]).into_iter(); = help: to override `-D warnings` add `#[allow(clippy::into_iter_on_ref)]` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` - --> tests/ui/into_iter_on_ref.rs:14:46 - | -LL | let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); - | ^^^^^^^^^ help: call directly: `iter` - -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` - --> tests/ui/into_iter_on_ref.rs:15:41 + --> tests/ui/into_iter_on_ref.rs:14:41 | LL | let _ = std::rc::Rc::from(&[X][..]).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` - --> tests/ui/into_iter_on_ref.rs:16:44 + --> tests/ui/into_iter_on_ref.rs:15:44 | LL | let _ = std::sync::Arc::from(&[X][..]).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `array` - --> tests/ui/into_iter_on_ref.rs:18:32 + --> tests/ui/into_iter_on_ref.rs:17:32 | LL | let _ = (&&&&&&&[1, 2, 3]).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `array` - --> tests/ui/into_iter_on_ref.rs:19:36 + --> tests/ui/into_iter_on_ref.rs:18:36 | LL | let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `array` - --> tests/ui/into_iter_on_ref.rs:20:40 + --> tests/ui/into_iter_on_ref.rs:19:40 | LL | let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Option` - --> tests/ui/into_iter_on_ref.rs:22:24 + --> tests/ui/into_iter_on_ref.rs:21:24 | LL | let _ = (&Some(4)).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `Option` - --> tests/ui/into_iter_on_ref.rs:23:28 + --> tests/ui/into_iter_on_ref.rs:22:28 | LL | let _ = (&mut Some(5)).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Result` - --> tests/ui/into_iter_on_ref.rs:24:32 + --> tests/ui/into_iter_on_ref.rs:23:32 | LL | let _ = (&Ok::<_, i32>(6)).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `Result` - --> tests/ui/into_iter_on_ref.rs:25:37 + --> tests/ui/into_iter_on_ref.rs:24:37 | LL | let _ = (&mut Err::(7)).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Vec` - --> tests/ui/into_iter_on_ref.rs:26:34 + --> tests/ui/into_iter_on_ref.rs:25:34 | LL | let _ = (&Vec::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `Vec` - --> tests/ui/into_iter_on_ref.rs:27:38 + --> tests/ui/into_iter_on_ref.rs:26:38 | LL | let _ = (&mut Vec::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `BTreeMap` - --> tests/ui/into_iter_on_ref.rs:28:44 + --> tests/ui/into_iter_on_ref.rs:27:44 | LL | let _ = (&BTreeMap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `BTreeMap` - --> tests/ui/into_iter_on_ref.rs:29:48 + --> tests/ui/into_iter_on_ref.rs:28:48 | LL | let _ = (&mut BTreeMap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `VecDeque` - --> tests/ui/into_iter_on_ref.rs:30:39 + --> tests/ui/into_iter_on_ref.rs:29:39 | LL | let _ = (&VecDeque::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `VecDeque` - --> tests/ui/into_iter_on_ref.rs:31:43 + --> tests/ui/into_iter_on_ref.rs:30:43 | LL | let _ = (&mut VecDeque::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `LinkedList` - --> tests/ui/into_iter_on_ref.rs:32:41 + --> tests/ui/into_iter_on_ref.rs:31:41 | LL | let _ = (&LinkedList::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `LinkedList` - --> tests/ui/into_iter_on_ref.rs:33:45 + --> tests/ui/into_iter_on_ref.rs:32:45 | LL | let _ = (&mut LinkedList::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `HashMap` - --> tests/ui/into_iter_on_ref.rs:34:43 + --> tests/ui/into_iter_on_ref.rs:33:43 | LL | let _ = (&HashMap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `HashMap` - --> tests/ui/into_iter_on_ref.rs:35:47 + --> tests/ui/into_iter_on_ref.rs:34:47 | LL | let _ = (&mut HashMap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `BTreeSet` - --> tests/ui/into_iter_on_ref.rs:37:39 + --> tests/ui/into_iter_on_ref.rs:36:39 | LL | let _ = (&BTreeSet::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `BinaryHeap` - --> tests/ui/into_iter_on_ref.rs:38:41 + --> tests/ui/into_iter_on_ref.rs:37:41 | LL | let _ = (&BinaryHeap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `HashSet` - --> tests/ui/into_iter_on_ref.rs:39:38 + --> tests/ui/into_iter_on_ref.rs:38:38 | LL | let _ = (&HashSet::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Path` - --> tests/ui/into_iter_on_ref.rs:40:43 + --> tests/ui/into_iter_on_ref.rs:39:43 | LL | let _ = std::path::Path::new("12/34").into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `PathBuf` - --> tests/ui/into_iter_on_ref.rs:41:47 + --> tests/ui/into_iter_on_ref.rs:40:47 | LL | let _ = std::path::PathBuf::from("12/34").into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `array` - --> tests/ui/into_iter_on_ref.rs:43:26 + --> tests/ui/into_iter_on_ref.rs:42:26 | LL | let _ = (&[1, 2, 3]).into_iter().next(); | ^^^^^^^^^ help: call directly: `iter` -error: aborting due to 27 previous errors +error: aborting due to 26 previous errors From 45735ce1ea41b886119abcb94268a929c710b8be Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 21 May 2024 14:07:02 +0200 Subject: [PATCH 1184/1222] don't inhibit random field reordering on repr(packed(1)) --- clippy_lints/src/transmute/transmute_undefined_repr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/transmute/transmute_undefined_repr.rs b/clippy_lints/src/transmute/transmute_undefined_repr.rs index 9c8dd37d53dc..3b32e4396b9f 100644 --- a/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -278,7 +278,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> ty = sized_ty; continue; } - if def.repr().inhibit_struct_field_reordering_opt() { + if def.repr().inhibit_struct_field_reordering() { ReducedTy::OrderedFields(Some(sized_ty)) } else { ReducedTy::UnorderedFields(ty) From a2d9f34b002e141228ef20e0c374d7b36808685e Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 10 May 2024 17:29:02 +0300 Subject: [PATCH 1185/1222] rustc: Use `tcx.used_crates(())` more And explain when it should be used. --- clippy_utils/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 4c603bda770a..94d4656377f9 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -647,7 +647,7 @@ fn item_children_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) -> Vec, path: &[&str]) -> Vec { fn find_crates(tcx: TyCtxt<'_>, name: Symbol) -> impl Iterator + '_ { - tcx.crates(()) + tcx.crates_including_speculative(()) .iter() .copied() .filter(move |&num| tcx.crate_name(num) == name) From d1726cfdcf8c239df79ed27104c788c712bc2075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Wed, 22 May 2024 16:46:05 +0200 Subject: [PATCH 1186/1222] Remove `LintDiagnostic::msg` * instead simply set the primary message inside the lint decorator functions * it used to be this way before [#]101986 which introduced `msg` to prevent good path delayed bugs (which no longer exist) from firing under certain circumstances when lints were suppressed / silenced * this is no longer necessary for various reasons I presume * it shaves off complexity and makes further changes easier to implement --- clippy_utils/src/diagnostics.rs | 18 ++++++++++++------ tests/ui-internal/disallow_span_lint.rs | 4 ++-- tests/ui-internal/disallow_span_lint.stderr | 8 ++++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs index dc0a139e3c78..0641d37cd9a6 100644 --- a/clippy_utils/src/diagnostics.rs +++ b/clippy_utils/src/diagnostics.rs @@ -61,7 +61,8 @@ fn docs_link(diag: &mut Diag<'_, ()>, lint: &'static Lint) { /// ``` pub fn span_lint(cx: &T, lint: &'static Lint, sp: impl Into, msg: impl Into) { #[expect(clippy::disallowed_methods)] - cx.span_lint(lint, sp, msg.into(), |diag| { + cx.span_lint(lint, sp, |diag| { + diag.primary_message(msg); docs_link(diag, lint); }); } @@ -109,7 +110,8 @@ pub fn span_lint_and_help( help: impl Into, ) { #[expect(clippy::disallowed_methods)] - cx.span_lint(lint, span, msg.into(), |diag| { + cx.span_lint(lint, span, |diag| { + diag.primary_message(msg); if let Some(help_span) = help_span { diag.span_help(help_span, help.into()); } else { @@ -165,7 +167,8 @@ pub fn span_lint_and_note( note: impl Into, ) { #[expect(clippy::disallowed_methods)] - cx.span_lint(lint, span, msg.into(), |diag| { + cx.span_lint(lint, span, |diag| { + diag.primary_message(msg); if let Some(note_span) = note_span { diag.span_note(note_span, note.into()); } else { @@ -201,7 +204,8 @@ where F: FnOnce(&mut Diag<'_, ()>), { #[expect(clippy::disallowed_methods)] - cx.span_lint(lint, sp, msg, |diag| { + cx.span_lint(lint, sp, |diag| { + diag.primary_message(msg); f(diag); docs_link(diag, lint); }); @@ -233,7 +237,8 @@ where /// the `#[allow]` will work. pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: impl Into) { #[expect(clippy::disallowed_methods)] - cx.tcx.node_span_lint(lint, hir_id, sp, msg.into(), |diag| { + cx.tcx.node_span_lint(lint, hir_id, sp, |diag| { + diag.primary_message(msg); docs_link(diag, lint); }); } @@ -271,7 +276,8 @@ pub fn span_lint_hir_and_then( f: impl FnOnce(&mut Diag<'_, ()>), ) { #[expect(clippy::disallowed_methods)] - cx.tcx.node_span_lint(lint, hir_id, sp, msg.into(), |diag| { + cx.tcx.node_span_lint(lint, hir_id, sp, |diag| { + diag.primary_message(msg); f(diag); docs_link(diag, lint); }); diff --git a/tests/ui-internal/disallow_span_lint.rs b/tests/ui-internal/disallow_span_lint.rs index 5a2a868ed3ec..b91a83308b5f 100644 --- a/tests/ui-internal/disallow_span_lint.rs +++ b/tests/ui-internal/disallow_span_lint.rs @@ -11,11 +11,11 @@ use rustc_lint::{Lint, LintContext}; use rustc_middle::ty::TyCtxt; pub fn a(cx: impl LintContext, lint: &'static Lint, span: impl Into, msg: impl Into) { - cx.span_lint(lint, span, msg, |_| {}); + cx.span_lint(lint, span, |lint| { lint.primary_message(msg); }); } pub fn b(tcx: TyCtxt<'_>, lint: &'static Lint, hir_id: HirId, span: impl Into, msg: impl Into) { - tcx.node_span_lint(lint, hir_id, span, msg, |_| {}); + tcx.node_span_lint(lint, hir_id, span, |lint| { lint.primary_message(msg); }); } fn main() {} diff --git a/tests/ui-internal/disallow_span_lint.stderr b/tests/ui-internal/disallow_span_lint.stderr index cfc590bed369..1cfbc8efc8ed 100644 --- a/tests/ui-internal/disallow_span_lint.stderr +++ b/tests/ui-internal/disallow_span_lint.stderr @@ -1,8 +1,8 @@ error: use of a disallowed method `rustc_lint::context::LintContext::span_lint` --> tests/ui-internal/disallow_span_lint.rs:14:5 | -LL | cx.span_lint(lint, span, msg, |_| {}); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | cx.span_lint(lint, span, |lint| { lint.primary_message(msg); }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint*` functions instead (from clippy.toml) = note: `-D clippy::disallowed-methods` implied by `-D warnings` @@ -11,8 +11,8 @@ LL | cx.span_lint(lint, span, msg, |_| {}); error: use of a disallowed method `rustc_middle::ty::context::TyCtxt::node_span_lint` --> tests/ui-internal/disallow_span_lint.rs:18:5 | -LL | tcx.node_span_lint(lint, hir_id, span, msg, |_| {}); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | tcx.node_span_lint(lint, hir_id, span, |lint| { lint.primary_message(msg); }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint_hir*` functions instead (from clippy.toml) From 00a82c4e0747e78d3a4b6ab3615370291df0fcd0 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Fri, 24 May 2024 01:33:55 -0700 Subject: [PATCH 1187/1222] clippy: unnest check_consts --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 8ee7d87acb3e..81e94725a70c 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -6,7 +6,7 @@ use clippy_config::msrvs::{self, Msrv}; use hir::LangItem; use rustc_attr::StableSince; -use rustc_const_eval::transform::check_consts::ConstCx; +use rustc_const_eval::check_consts::ConstCx; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_infer::infer::TyCtxtInferExt; From c4b0d4bbc9da0177f364acb704ebd91b7e13b3fc Mon Sep 17 00:00:00 2001 From: Boxy Date: Fri, 24 May 2024 17:25:50 +0100 Subject: [PATCH 1188/1222] Remove `DefId` from `EarlyParamRegion` (clippy/smir) --- clippy_lints/src/ptr.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 65929cd5fea9..38580dc58226 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -460,13 +460,19 @@ fn check_fn_args<'cx, 'tcx: 'cx>( } None }) { - if !lifetime.is_anonymous() + if let LifetimeName::Param(param_def_id) = lifetime.res + && !lifetime.is_anonymous() && fn_sig .output() .walk() .filter_map(|arg| { arg.as_region().and_then(|lifetime| match lifetime.kind() { - ty::ReEarlyParam(r) => Some(r.def_id), + ty::ReEarlyParam(r) => Some( + cx.tcx + .generics_of(cx.tcx.parent(param_def_id.to_def_id())) + .region_param(r, cx.tcx) + .def_id, + ), ty::ReBound(_, r) => r.kind.get_id(), ty::ReLateParam(r) => r.bound_region.get_id(), ty::ReStatic @@ -476,14 +482,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>( | ty::ReError(_) => None, }) }) - .any(|def_id| { - matches!( - lifetime.res, - LifetimeName::Param(param_def_id) if def_id - .as_local() - .is_some_and(|def_id| def_id == param_def_id), - ) - }) + .any(|def_id| def_id.as_local().is_some_and(|def_id| def_id == param_def_id)) { // `&Cow<'a, T>` when the return type uses 'a is okay return None; From ee430470ddab275755b36997817c19b5a2f0ef09 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 3 May 2024 09:22:55 +0000 Subject: [PATCH 1189/1222] Create const block DefIds in typeck instead of ast lowering --- clippy_utils/src/consts.rs | 6 ++--- clippy_utils/src/hir_utils.rs | 4 ++-- tests/ui/arithmetic_side_effects.stderr | 32 +++++++++++++++++++++---- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 253ae3aca689..f5d3967d130d 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -6,7 +6,7 @@ use crate::{clip, is_direct_expn_of, sext, unsext}; use rustc_ast::ast::{self, LitFloatType, LitKind}; use rustc_data_structures::sync::Lrc; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{BinOp, BinOpKind, Block, ConstBlock, Expr, ExprKind, HirId, Item, ItemKind, Node, QPath, UnOp}; +use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, Item, ItemKind, Node, QPath, UnOp}; use rustc_lexer::tokenize; use rustc_lint::LateContext; use rustc_middle::mir::interpret::{alloc_range, Scalar}; @@ -412,7 +412,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { /// Simple constant folding: Insert an expression, get a constant or none. pub fn expr(&mut self, e: &Expr<'_>) -> Option> { match e.kind { - ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.lcx.tcx.hir().body(body).value), + ExprKind::ConstBlock(e) | ExprKind::DropTemps(e) => self.expr(e), ExprKind::Path(ref qpath) => { self.fetch_path_and_apply(qpath, e.hir_id, self.typeck_results.expr_ty(e), |this, result| { @@ -491,7 +491,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { /// leaves the local crate. pub fn expr_is_empty(&mut self, e: &Expr<'_>) -> Option { match e.kind { - ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr_is_empty(self.lcx.tcx.hir().body(body).value), + ExprKind::ConstBlock(e) | ExprKind::DropTemps(e) => self.expr_is_empty(e), ExprKind::Path(ref qpath) => { if !self diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 9f285621e0c9..cc5ccd4053a2 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -295,7 +295,7 @@ impl HirEqInterExpr<'_, '_, '_> { self.eq_expr(lx, rx) && self.eq_ty(lt, rt) }, (&ExprKind::Closure(_l), &ExprKind::Closure(_r)) => false, - (&ExprKind::ConstBlock(lb), &ExprKind::ConstBlock(rb)) => self.eq_body(lb.body, rb.body), + (&ExprKind::ConstBlock(lb), &ExprKind::ConstBlock(rb)) => self.eq_expr(lb, rb), (&ExprKind::Continue(li), &ExprKind::Continue(ri)) => { both(&li.label, &ri.label, |l, r| l.ident.name == r.ident.name) }, @@ -770,7 +770,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_expr(self.cx.tcx.hir().body(body).value); }, ExprKind::ConstBlock(ref l_id) => { - self.hash_body(l_id.body); + self.hash_expr(l_id); }, ExprKind::DropTemps(e) | ExprKind::Yield(e, _) => { self.hash_expr(e); diff --git a/tests/ui/arithmetic_side_effects.stderr b/tests/ui/arithmetic_side_effects.stderr index 8039c0bfa248..df14ff396f6c 100644 --- a/tests/ui/arithmetic_side_effects.stderr +++ b/tests/ui/arithmetic_side_effects.stderr @@ -1,12 +1,36 @@ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:304:5 + --> tests/ui/arithmetic_side_effects.rs:188:36 | -LL | _n += 1; - | ^^^^^^^ +LL | let _ = const { let mut n = 1; n += 1; n }; + | ^^^^^^ | = note: `-D clippy::arithmetic-side-effects` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]` +error: arithmetic operation that can potentially result in unexpected side-effects + --> tests/ui/arithmetic_side_effects.rs:191:40 + | +LL | let _ = const { let mut n = 1; n = n + 1; n }; + | ^^^^^ + +error: arithmetic operation that can potentially result in unexpected side-effects + --> tests/ui/arithmetic_side_effects.rs:194:40 + | +LL | let _ = const { let mut n = 1; n = 1 + n; n }; + | ^^^^^ + +error: arithmetic operation that can potentially result in unexpected side-effects + --> tests/ui/arithmetic_side_effects.rs:200:59 + | +LL | let _ = const { let mut n = 1; n = -1; n = -(-1); n = -n; n }; + | ^^ + +error: arithmetic operation that can potentially result in unexpected side-effects + --> tests/ui/arithmetic_side_effects.rs:304:5 + | +LL | _n += 1; + | ^^^^^^^ + error: arithmetic operation that can potentially result in unexpected side-effects --> tests/ui/arithmetic_side_effects.rs:305:5 | @@ -727,5 +751,5 @@ error: arithmetic operation that can potentially result in unexpected side-effec LL | one.sub_assign(1); | ^^^^^^^^^^^^^^^^^ -error: aborting due to 121 previous errors +error: aborting due to 125 previous errors From b2daa0c6f3ab4ab39ff068509c41ce160b493525 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 29 May 2024 09:08:22 +0000 Subject: [PATCH 1190/1222] Don't require `visit_body` to take a lifetime that must outlive the function call --- clippy_lints/src/default_numeric_fallback.rs | 2 +- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/implicit_hasher.rs | 2 +- clippy_lints/src/macro_metavars_in_unsafe.rs | 2 +- clippy_lints/src/needless_borrows_for_generic_args.rs | 2 +- clippy_lints/src/only_used_in_recursion.rs | 4 ++-- clippy_lints/src/operators/mod.rs | 4 ++-- clippy_lints/src/ptr.rs | 6 +++--- clippy_lints/src/question_mark.rs | 4 ++-- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index 1d6c4ce72e18..4d8c066fea54 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -49,7 +49,7 @@ declare_clippy_lint! { declare_lint_pass!(DefaultNumericFallback => [DEFAULT_NUMERIC_FALLBACK]); impl<'tcx> LateLintPass<'tcx> for DefaultNumericFallback { - fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) { + fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) { let hir = cx.tcx.hir(); let is_parent_const = matches!( hir.body_const_context(hir.body_owner_def_id(body.id())), diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index c6aef9ac2d60..297082354ff1 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -641,7 +641,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> { } } - fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) { + fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &Body<'_>) { if Some(body.id()) == self.current_body { for pat in self.ref_locals.drain(..).filter_map(|(_, x)| x) { let replacements = pat.replacements; diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index a46aae36d5c5..ca830af3b2f3 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -328,7 +328,7 @@ impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { type NestedFilter = nested_filter::OnlyBodies; - fn visit_body(&mut self, body: &'tcx Body<'_>) { + fn visit_body(&mut self, body: &Body<'tcx>) { let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body.id())); walk_body(self, body); self.maybe_typeck_results = old_maybe_typeck_results; diff --git a/clippy_lints/src/macro_metavars_in_unsafe.rs b/clippy_lints/src/macro_metavars_in_unsafe.rs index aea3d26e1878..d1ae243877d7 100644 --- a/clippy_lints/src/macro_metavars_in_unsafe.rs +++ b/clippy_lints/src/macro_metavars_in_unsafe.rs @@ -186,7 +186,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BodyVisitor<'a, 'tcx> { } impl<'tcx> LateLintPass<'tcx> for ExprMetavarsInUnsafe { - fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx rustc_hir::Body<'tcx>) { + fn check_body(&mut self, cx: &LateContext<'tcx>, body: &rustc_hir::Body<'tcx>) { if is_lint_allowed(cx, MACRO_METAVARS_IN_UNSAFE, body.value.hir_id) { return; } diff --git a/clippy_lints/src/needless_borrows_for_generic_args.rs b/clippy_lints/src/needless_borrows_for_generic_args.rs index daf166bad90d..5b5e1c234245 100644 --- a/clippy_lints/src/needless_borrows_for_generic_args.rs +++ b/clippy_lints/src/needless_borrows_for_generic_args.rs @@ -129,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowsForGenericArgs<'tcx> { } } - fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) { + fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &Body<'_>) { if self.possible_borrowers.last().map_or(false, |&(local_def_id, _)| { local_def_id == cx.tcx.hir().body_owner_def_id(body.id()) }) { diff --git a/clippy_lints/src/only_used_in_recursion.rs b/clippy_lints/src/only_used_in_recursion.rs index b3ff5ecae862..8b8aabe7accc 100644 --- a/clippy_lints/src/only_used_in_recursion.rs +++ b/clippy_lints/src/only_used_in_recursion.rs @@ -221,7 +221,7 @@ pub struct OnlyUsedInRecursion { } impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion { - fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'tcx>) { + fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) { if body.value.span.from_expansion() { return; } @@ -350,7 +350,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion { } } - fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'tcx>) { + fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) { if self.entered_body == Some(body.value.hir_id) { self.entered_body = None; self.params.flag_for_linting(); diff --git a/clippy_lints/src/operators/mod.rs b/clippy_lints/src/operators/mod.rs index e002429e3a47..9e77d0e09c48 100644 --- a/clippy_lints/src/operators/mod.rs +++ b/clippy_lints/src/operators/mod.rs @@ -868,11 +868,11 @@ impl<'tcx> LateLintPass<'tcx> for Operators { self.arithmetic_context.expr_post(e.hir_id); } - fn check_body(&mut self, cx: &LateContext<'tcx>, b: &'tcx Body<'_>) { + fn check_body(&mut self, cx: &LateContext<'tcx>, b: &Body<'_>) { self.arithmetic_context.enter_body(cx, b); } - fn check_body_post(&mut self, cx: &LateContext<'tcx>, b: &'tcx Body<'_>) { + fn check_body_post(&mut self, cx: &LateContext<'tcx>, b: &Body<'_>) { self.arithmetic_context.body_post(cx, b); } } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 38580dc58226..02c05e0aaf9c 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -188,7 +188,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { } } - fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) { + fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) { let hir = cx.tcx.hir(); let mut parents = hir.parent_iter(body.value.hir_id); let (item_id, sig, is_trait_item) = match parents.next() { @@ -525,7 +525,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>( }) } -fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Option<&'tcx Body<'_>>) { +fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Option<&Body<'tcx>>) { if let FnRetTy::Return(ty) = sig.decl.output && let Some((out, Mutability::Mut, _)) = get_ref_lm(ty) { @@ -559,7 +559,7 @@ fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Optio } #[expect(clippy::too_many_lines)] -fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: &[PtrArg<'tcx>]) -> Vec { +fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &Body<'tcx>, args: &[PtrArg<'tcx>]) -> Vec { struct V<'cx, 'tcx> { cx: &'cx LateContext<'tcx>, /// Map from a local id to which argument it came from (index into `Self::args` and diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 1f1ce147ca24..7cf98ad9e09a 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -370,11 +370,11 @@ impl<'tcx> LateLintPass<'tcx> for QuestionMark { } } - fn check_body(&mut self, _: &LateContext<'tcx>, _: &'tcx Body<'tcx>) { + fn check_body(&mut self, _: &LateContext<'tcx>, _: &Body<'tcx>) { self.try_block_depth_stack.push(0); } - fn check_body_post(&mut self, _: &LateContext<'tcx>, _: &'tcx Body<'tcx>) { + fn check_body_post(&mut self, _: &LateContext<'tcx>, _: &Body<'tcx>) { self.try_block_depth_stack.pop(); } From 7af47abef9447903d20c1871fa3fa59bf1fb4d22 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 29 May 2024 10:03:40 +0000 Subject: [PATCH 1191/1222] Make `body_owned_by` return the body directly. Almost all callers want this anyway, and now we can use it to also return fed bodies --- clippy_lints/src/methods/option_map_unwrap_or.rs | 4 ++-- clippy_lints/src/single_call_fn.rs | 1 - clippy_lints/src/transmute/missing_transmute_annotations.rs | 4 ++-- clippy_lints/src/unconditional_recursion.rs | 2 +- clippy_lints/src/utils/author.rs | 4 ++-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index efec9dd716dc..ca331f3e7568 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -59,8 +59,8 @@ pub(super) fn check<'tcx>( }; let map = cx.tcx.hir(); - let body = map.body(map.body_owned_by(map.enclosing_body_owner(expr.hir_id))); - reference_visitor.visit_body(body); + let body = map.body_owned_by(map.enclosing_body_owner(expr.hir_id)); + reference_visitor.visit_body(&body); if reference_visitor.found_reference { return; diff --git a/clippy_lints/src/single_call_fn.rs b/clippy_lints/src/single_call_fn.rs index 2ce7e714c642..f8e09d517f57 100644 --- a/clippy_lints/src/single_call_fn.rs +++ b/clippy_lints/src/single_call_fn.rs @@ -79,7 +79,6 @@ impl SingleCallFn { .tcx .hir() .maybe_body_owned_by(fn_def_id) - .map(|body| cx.tcx.hir().body(body)) .map_or(true, |body| is_in_test_function(cx.tcx, body.value.hir_id)) || match cx.tcx.hir_node(fn_hir_id) { Node::Item(item) => is_from_proc_macro(cx, item), diff --git a/clippy_lints/src/transmute/missing_transmute_annotations.rs b/clippy_lints/src/transmute/missing_transmute_annotations.rs index cc6ff1cf3b42..f98ea59a15d8 100644 --- a/clippy_lints/src/transmute/missing_transmute_annotations.rs +++ b/clippy_lints/src/transmute/missing_transmute_annotations.rs @@ -30,8 +30,8 @@ fn get_parent_local_binding_ty<'tcx>(cx: &LateContext<'tcx>, expr_hir_id: HirId) fn is_function_block(cx: &LateContext<'_>, expr_hir_id: HirId) -> bool { let def_id = cx.tcx.hir().enclosing_body_owner(expr_hir_id); - if let Some(body_id) = cx.tcx.hir().maybe_body_owned_by(def_id) { - let body = cx.tcx.hir().body(body_id); + if let Some(body) = cx.tcx.hir().maybe_body_owned_by(def_id) { + let body = cx.tcx.hir().body(body.id()); return body.value.peel_blocks().hir_id == expr_hir_id; } false diff --git a/clippy_lints/src/unconditional_recursion.rs b/clippy_lints/src/unconditional_recursion.rs index 0c4e2c91aec5..5e41b3f4914f 100644 --- a/clippy_lints/src/unconditional_recursion.rs +++ b/clippy_lints/src/unconditional_recursion.rs @@ -336,7 +336,7 @@ impl UnconditionalRecursion { // We need to use typeck here to infer the actual function being called. && let body_def_id = cx.tcx.hir().enclosing_body_owner(call_expr.hir_id) && let Some(body_owner) = cx.tcx.hir().maybe_body_owned_by(body_def_id) - && let typeck = cx.tcx.typeck_body(body_owner) + && let typeck = cx.tcx.typeck_body(body_owner.id()) && let Some(call_def_id) = typeck.type_dependent_def_id(call_expr.hir_id) { self.default_impl_for_type.insert(self_def_id, call_def_id); diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 4448c9ae3df7..18a31abddd0a 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -137,9 +137,9 @@ impl<'tcx> LateLintPass<'tcx> for Author { fn check_item(cx: &LateContext<'_>, hir_id: HirId) { let hir = cx.tcx.hir(); - if let Some(body_id) = hir.maybe_body_owned_by(hir_id.expect_owner().def_id) { + if let Some(body) = hir.maybe_body_owned_by(hir_id.expect_owner().def_id) { check_node(cx, hir_id, |v| { - v.expr(&v.bind("expr", hir.body(body_id).value)); + v.expr(&v.bind("expr", body.value)); }); } } From 699fbe40dd8dac0581f00c77a3bb086012891c05 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 29 May 2024 21:30:21 +0300 Subject: [PATCH 1192/1222] ast: Revert a breaking attribute visiting order change --- tests/ui/tabs_in_doc_comments.stderr | 48 ++++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/ui/tabs_in_doc_comments.stderr b/tests/ui/tabs_in_doc_comments.stderr index aef6c3914526..23d5dcd3a8da 100644 --- a/tests/ui/tabs_in_doc_comments.stderr +++ b/tests/ui/tabs_in_doc_comments.stderr @@ -1,53 +1,53 @@ error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:6:5 + --> tests/ui/tabs_in_doc_comments.rs:10:9 | -LL | /// - first one - | ^^^^ help: consider using four spaces per tab +LL | /// - First String: + | ^^^^ help: consider using four spaces per tab | = note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::tabs_in_doc_comments)]` error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:6:13 + --> tests/ui/tabs_in_doc_comments.rs:11:9 | -LL | /// - first one - | ^^^^^^^^ help: consider using four spaces per tab +LL | /// - needs to be inside here + | ^^^^^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:7:5 + --> tests/ui/tabs_in_doc_comments.rs:14:9 | -LL | /// - second one - | ^^^^ help: consider using four spaces per tab +LL | /// - Second String: + | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:7:14 + --> tests/ui/tabs_in_doc_comments.rs:15:9 | -LL | /// - second one - | ^^^^ help: consider using four spaces per tab +LL | /// - needs to be inside here + | ^^^^^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:10:9 + --> tests/ui/tabs_in_doc_comments.rs:6:5 | -LL | /// - First String: - | ^^^^ help: consider using four spaces per tab +LL | /// - first one + | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:11:9 + --> tests/ui/tabs_in_doc_comments.rs:6:13 | -LL | /// - needs to be inside here - | ^^^^^^^^ help: consider using four spaces per tab +LL | /// - first one + | ^^^^^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:14:9 + --> tests/ui/tabs_in_doc_comments.rs:7:5 | -LL | /// - Second String: - | ^^^^ help: consider using four spaces per tab +LL | /// - second one + | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:15:9 + --> tests/ui/tabs_in_doc_comments.rs:7:14 | -LL | /// - needs to be inside here - | ^^^^^^^^ help: consider using four spaces per tab +LL | /// - second one + | ^^^^ help: consider using four spaces per tab error: aborting due to 8 previous errors From 84125d8a7d2c4155a2ec35479725916c378f7c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Mon, 27 May 2024 23:53:46 +0200 Subject: [PATCH 1193/1222] Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanup --- clippy_lints/src/implied_bounds_in_impls.rs | 54 ++++++++++----------- clippy_lints/src/len_zero.rs | 17 +++---- clippy_lints/src/manual_async_fn.rs | 10 ++-- clippy_utils/src/ast_utils.rs | 6 +-- clippy_utils/src/hir_utils.rs | 8 +-- 5 files changed, 44 insertions(+), 51 deletions(-) diff --git a/clippy_lints/src/implied_bounds_in_impls.rs b/clippy_lints/src/implied_bounds_in_impls.rs index dc935ed3d7fe..2b389d4f9b19 100644 --- a/clippy_lints/src/implied_bounds_in_impls.rs +++ b/clippy_lints/src/implied_bounds_in_impls.rs @@ -3,7 +3,7 @@ use clippy_utils::source::snippet; use rustc_errors::{Applicability, SuggestionStyle}; use rustc_hir::def_id::DefId; use rustc_hir::{ - GenericArg, GenericBound, GenericBounds, ItemKind, PredicateOrigin, TraitBoundModifier, TyKind, TypeBinding, + GenericArg, GenericBound, GenericBounds, ItemKind, PredicateOrigin, TraitBoundModifier, TyKind, AssocItemConstraint, WherePredicate, }; use rustc_hir_analysis::lower_ty; @@ -54,9 +54,9 @@ fn emit_lint( poly_trait: &rustc_hir::PolyTraitRef<'_>, bounds: GenericBounds<'_>, index: usize, - // The bindings that were implied, used for suggestion purposes since removing a bound with associated types - // means we might need to then move it to a different bound - implied_bindings: &[TypeBinding<'_>], + // The constraints that were implied, used for suggestion purposes since removing a bound with + // associated types means we might need to then move it to a different bound. + implied_constraints: &[AssocItemConstraint<'_>], bound: &ImplTraitBound<'_>, ) { let implied_by = snippet(cx, bound.span, ".."); @@ -83,29 +83,29 @@ fn emit_lint( let mut sugg = vec![(implied_span_extended, String::new())]; - // We also might need to include associated type binding that were specified in the implied bound, + // We also might need to include associated item constraints that were specified in the implied bound, // but omitted in the implied-by bound: // `fn f() -> impl Deref + DerefMut` // If we're going to suggest removing `Deref<..>`, we'll need to put `` on `DerefMut` - let omitted_assoc_tys: Vec<_> = implied_bindings + let omitted_constraints: Vec<_> = implied_constraints .iter() - .filter(|binding| !bound.bindings.iter().any(|b| b.ident == binding.ident)) + .filter(|constraint| !bound.constraints.iter().any(|c| c.ident == constraint.ident)) .collect(); - if !omitted_assoc_tys.is_empty() { - // `<>` needs to be added if there aren't yet any generic arguments or bindings - let needs_angle_brackets = bound.args.is_empty() && bound.bindings.is_empty(); - let insert_span = match (bound.args, bound.bindings) { - ([.., arg], [.., binding]) => arg.span().max(binding.span).shrink_to_hi(), + if !omitted_constraints.is_empty() { + // `<>` needs to be added if there aren't yet any generic arguments or constraints + let needs_angle_brackets = bound.args.is_empty() && bound.constraints.is_empty(); + let insert_span = match (bound.args, bound.constraints) { + ([.., arg], [.., constraint]) => arg.span().max(constraint.span).shrink_to_hi(), ([.., arg], []) => arg.span().shrink_to_hi(), - ([], [.., binding]) => binding.span.shrink_to_hi(), + ([], [.., constraint]) => constraint.span.shrink_to_hi(), ([], []) => bound.span.shrink_to_hi(), }; - let mut associated_tys_sugg = if needs_angle_brackets { + let mut constraints_sugg = if needs_angle_brackets { "<".to_owned() } else { - // If angle brackets aren't needed (i.e., there are already generic arguments or bindings), + // If angle brackets aren't needed (i.e., there are already generic arguments or constraints), // we need to add a comma: // `impl A` // ^ if we insert `Assoc=i32` without a comma here, that'd be invalid syntax: @@ -113,16 +113,16 @@ fn emit_lint( ", ".to_owned() }; - for (index, binding) in omitted_assoc_tys.into_iter().enumerate() { + for (index, constraint) in omitted_constraints.into_iter().enumerate() { if index > 0 { - associated_tys_sugg += ", "; + constraints_sugg += ", "; } - associated_tys_sugg += &snippet(cx, binding.span, ".."); + constraints_sugg += &snippet(cx, constraint.span, ".."); } if needs_angle_brackets { - associated_tys_sugg += ">"; + constraints_sugg += ">"; } - sugg.push((insert_span, associated_tys_sugg)); + sugg.push((insert_span, constraints_sugg)); } diag.multipart_suggestion_with_style( @@ -229,8 +229,8 @@ struct ImplTraitBound<'tcx> { trait_def_id: DefId, /// The generic arguments on the `impl Trait` bound args: &'tcx [GenericArg<'tcx>], - /// The associated types on this bound - bindings: &'tcx [TypeBinding<'tcx>], + /// The associated item constraints of this bound + constraints: &'tcx [AssocItemConstraint<'tcx>], } /// Given an `impl Trait` type, gets all the supertraits from each bound ("implied bounds"). @@ -253,7 +253,7 @@ fn collect_supertrait_bounds<'tcx>(cx: &LateContext<'tcx>, bounds: GenericBounds Some(ImplTraitBound { predicates, args: path.args.map_or([].as_slice(), |p| p.args), - bindings: path.args.map_or([].as_slice(), |p| p.bindings), + constraints: path.args.map_or([].as_slice(), |p| p.constraints), trait_def_id, span: bound.span(), }) @@ -310,20 +310,20 @@ fn check<'tcx>(cx: &LateContext<'tcx>, bounds: GenericBounds<'tcx>) { if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound && let [.., path] = poly_trait.trait_ref.path.segments && let implied_args = path.args.map_or([].as_slice(), |a| a.args) - && let implied_bindings = path.args.map_or([].as_slice(), |a| a.bindings) + && let implied_constraints = path.args.map_or([].as_slice(), |a| a.constraints) && let Some(def_id) = poly_trait.trait_ref.path.res.opt_def_id() && let Some(bound) = find_bound_in_supertraits(cx, def_id, implied_args, &supertraits) // If the implied bound has a type binding that also exists in the implied-by trait, // then we shouldn't lint. See #11880 for an example. && let assocs = cx.tcx.associated_items(bound.trait_def_id) - && !implied_bindings.iter().any(|binding| { + && !implied_constraints.iter().any(|constraint| { assocs - .filter_by_name_unhygienic(binding.ident.name) + .filter_by_name_unhygienic(constraint.ident.name) .next() .is_some_and(|assoc| assoc.kind == ty::AssocKind::Type) }) { - emit_lint(cx, poly_trait, bounds, index, implied_bindings, bound); + emit_lint(cx, poly_trait, bounds, index, implied_constraints, bound); } } } diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 97a245b76d44..2091e74665fb 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -9,7 +9,7 @@ use rustc_hir::def_id::{DefId, DefIdSet}; use rustc_hir::{ AssocItemKind, BinOpKind, Expr, ExprKind, FnRetTy, GenericArg, GenericBound, ImplItem, ImplItemKind, ImplicitSelfKind, Item, ItemKind, Mutability, Node, OpaqueTyOrigin, PatKind, PathSegment, PrimTy, QPath, - TraitItemRef, TyKind, TypeBindingKind, + TraitItemRef, TyKind, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, AssocKind, FnSig, Ty}; @@ -307,17 +307,12 @@ fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<& && let [GenericBound::Trait(trait_ref, _)] = &opaque.bounds && let Some(segment) = trait_ref.trait_ref.path.segments.last() && let Some(generic_args) = segment.args - && generic_args.bindings.len() == 1 - && let TypeBindingKind::Equality { - term: - rustc_hir::Term::Ty(rustc_hir::Ty { - kind: TyKind::Path(QPath::Resolved(_, path)), - .. - }), - } = &generic_args.bindings[0].kind - && path.segments.len() == 1 + && let [constraint] = generic_args.constraints + && let Some(ty) = constraint.ty() + && let TyKind::Path(QPath::Resolved(_, path)) = ty.kind + && let [segment] = path.segments { - return Some(&path.segments[0]); + return Some(segment); } None diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 4cd5f3b81e52..25c7e5d38b31 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -4,8 +4,7 @@ use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{ Block, Body, Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, FnDecl, - FnRetTy, GenericArg, GenericBound, ImplItem, Item, ItemKind, LifetimeName, Node, Term, TraitRef, Ty, TyKind, - TypeBindingKind, + FnRetTy, GenericArg, GenericBound, ImplItem, Item, ItemKind, LifetimeName, Node, TraitRef, Ty, TyKind, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; @@ -138,10 +137,9 @@ fn future_trait_ref<'tcx>( fn future_output_ty<'tcx>(trait_ref: &'tcx TraitRef<'tcx>) -> Option<&'tcx Ty<'tcx>> { if let Some(segment) = trait_ref.path.segments.last() && let Some(args) = segment.args - && args.bindings.len() == 1 - && let binding = &args.bindings[0] - && binding.ident.name == sym::Output - && let TypeBindingKind::Equality { term: Term::Ty(output) } = binding.kind + && let [constraint] = args.constraints + && constraint.ident.name == sym::Output + && let Some(output) = constraint.ty() { return Some(output); } diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index d4a5f547211a..bbdde3049dbd 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -108,7 +108,7 @@ pub fn eq_generic_args(l: &GenericArgs, r: &GenericArgs) -> bool { pub fn eq_angle_arg(l: &AngleBracketedArg, r: &AngleBracketedArg) -> bool { match (l, r) { (AngleBracketedArg::Arg(l), AngleBracketedArg::Arg(r)) => eq_generic_arg(l, r), - (AngleBracketedArg::Constraint(l), AngleBracketedArg::Constraint(r)) => eq_assoc_constraint(l, r), + (AngleBracketedArg::Constraint(l), AngleBracketedArg::Constraint(r)) => eq_assoc_item_constraint(l, r), _ => false, } } @@ -802,8 +802,8 @@ fn eq_term(l: &Term, r: &Term) -> bool { } } -pub fn eq_assoc_constraint(l: &AssocConstraint, r: &AssocConstraint) -> bool { - use AssocConstraintKind::*; +pub fn eq_assoc_item_constraint(l: &AssocItemConstraint, r: &AssocItemConstraint) -> bool { + use AssocItemConstraintKind::*; eq_id(l.ident, r.ident) && match (&l.kind, &r.kind) { (Equality { term: l }, Equality { term: r }) => eq_term(l, r), diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 9f285621e0c9..36634817fc91 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -9,7 +9,7 @@ use rustc_hir::MatchSource::TryDesugar; use rustc_hir::{ ArrayLen, BinOpKind, BindingMode, Block, BodyId, Closure, Expr, ExprField, ExprKind, FnRetTy, GenericArg, GenericArgs, HirId, HirIdMap, InlineAsmOperand, LetExpr, Lifetime, LifetimeName, Pat, PatField, PatKind, Path, - PathSegment, PrimTy, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding, + PathSegment, PrimTy, QPath, Stmt, StmtKind, Ty, TyKind, AssocItemConstraint, }; use rustc_lexer::{tokenize, TokenKind}; use rustc_lint::LateContext; @@ -486,7 +486,7 @@ impl HirEqInterExpr<'_, '_, '_> { fn eq_path_parameters(&mut self, left: &GenericArgs<'_>, right: &GenericArgs<'_>) -> bool { if left.parenthesized == right.parenthesized { over(left.args, right.args, |l, r| self.eq_generic_arg(l, r)) // FIXME(flip1995): may not work - && over(left.bindings, right.bindings, |l, r| self.eq_type_binding(l, r)) + && over(left.constraints, right.constraints, |l, r| self.eq_assoc_type_binding(l, r)) } else { false } @@ -518,8 +518,8 @@ impl HirEqInterExpr<'_, '_, '_> { } } - fn eq_type_binding(&mut self, left: &TypeBinding<'_>, right: &TypeBinding<'_>) -> bool { - left.ident.name == right.ident.name && self.eq_ty(left.ty(), right.ty()) + fn eq_assoc_type_binding(&mut self, left: &AssocItemConstraint<'_>, right: &AssocItemConstraint<'_>) -> bool { + left.ident.name == right.ident.name && self.eq_ty(left.ty().expect("expected assoc type binding"), right.ty().expect("expected assoc type binding")) } fn check_ctxt(&mut self, left: SyntaxContext, right: SyntaxContext) -> bool { From 1f723695b837976b8f4c12e4cf227d1f02572765 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 27 Apr 2024 13:58:37 -0400 Subject: [PATCH 1194/1222] Deduplicate supertrait_def_ids code --- clippy_lints/src/len_zero.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 2091e74665fb..57e0a7aa2c7e 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -253,7 +253,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items // fill the set with current and super traits fn fill_trait_set(traitt: DefId, set: &mut DefIdSet, cx: &LateContext<'_>) { if set.insert(traitt) { - for supertrait in rustc_trait_selection::traits::supertrait_def_ids(cx.tcx, traitt) { + for supertrait in cx.tcx.supertrait_def_ids(traitt) { fill_trait_set(supertrait, set, cx); } } From 0cc8167eb1e27f5c04ab6e0fbcec6c845e31f649 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 31 May 2024 14:13:46 -0400 Subject: [PATCH 1195/1222] Uplift TypeRelation and Relate --- clippy_lints/src/eta_reduction.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index b58018ca0353..48c4c4206fe8 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -10,7 +10,7 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{ self, Binder, ClosureArgs, ClosureKind, FnSig, GenericArg, GenericArgKind, List, Region, RegionKind, Ty, - TypeVisitableExt, TypeckResults, + TypeVisitableExt, TypeckResults, TyCtxt, }; use rustc_session::declare_lint_pass; use rustc_span::symbol::sym; @@ -240,7 +240,7 @@ fn check_inputs( }) } -fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure: ClosureArgs<'tcx>, call_sig: FnSig<'_>) -> bool { +fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure: ClosureArgs>, call_sig: FnSig<'_>) -> bool { call_sig.safety == Safety::Safe && !has_late_bound_to_non_late_bound_regions( cx.tcx.signature_unclosure(closure.sig(), Safety::Safe).skip_binder(), From 9ebfc68c48ce5a30359c779a233459504dfa855f Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 1 Jun 2024 14:51:31 -0400 Subject: [PATCH 1196/1222] Opt-in diagnostics reporting to avoid doing extra work in the new solver --- clippy_lints/src/future_not_send.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 192fb611c2d4..cb1d0de1edff 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -79,7 +79,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap(); let span = decl.output.span(); let infcx = cx.tcx.infer_ctxt().build(); - let ocx = ObligationCtxt::new(&infcx); + let ocx = ObligationCtxt::new_with_diagnostics(&infcx); let cause = traits::ObligationCause::misc(span, fn_def_id); ocx.register_bound(cause, cx.param_env, ret_ty, send_trait); let send_errors = ocx.select_all_or_error(); From 5827cacab760099e4f6c74423f70ebf29a4bf5df Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 29 May 2024 22:23:49 -0400 Subject: [PATCH 1197/1222] Align Term methods with GenericArg methods --- .../src/methods/iter_on_single_or_empty_collections.rs | 2 +- clippy_lints/src/needless_borrows_for_generic_args.rs | 4 ++-- clippy_lints/src/unit_return_expecting_ord.rs | 4 ++-- clippy_utils/src/ty.rs | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs b/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs index f4397212cf66..7f6b666e434e 100644 --- a/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs +++ b/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs @@ -42,7 +42,7 @@ fn is_arg_ty_unified_in_fn<'tcx>( cx.tcx.predicates_of(fn_id).predicates.iter().any(|(clause, _)| { clause .as_projection_clause() - .and_then(|p| p.map_bound(|p| p.term.ty()).transpose()) + .and_then(|p| p.map_bound(|p| p.term.as_type()).transpose()) .is_some_and(|ty| ty.skip_binder() == arg_ty_in_args) }) || fn_sig .inputs() diff --git a/clippy_lints/src/needless_borrows_for_generic_args.rs b/clippy_lints/src/needless_borrows_for_generic_args.rs index 5b5e1c234245..4f99eaa40c29 100644 --- a/clippy_lints/src/needless_borrows_for_generic_args.rs +++ b/clippy_lints/src/needless_borrows_for_generic_args.rs @@ -311,7 +311,7 @@ fn is_mixed_projection_predicate<'tcx>( ) -> bool { let generics = cx.tcx.generics_of(callee_def_id); // The predicate requires the projected type to equal a type parameter from the parent context. - if let Some(term_ty) = projection_predicate.term.ty() + if let Some(term_ty) = projection_predicate.term.as_type() && let ty::Param(term_param_ty) = term_ty.kind() && (term_param_ty.index as usize) < generics.parent_count { @@ -370,7 +370,7 @@ fn replace_types<'tcx>( if replaced.insert(param_ty.index) { for projection_predicate in projection_predicates { if projection_predicate.projection_term.self_ty() == param_ty.to_ty(cx.tcx) - && let Some(term_ty) = projection_predicate.term.ty() + && let Some(term_ty) = projection_predicate.term.as_type() && let ty::Param(term_param_ty) = term_ty.kind() { let projection = projection_predicate diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index f0d1458a59b2..a8cc2f979633 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -100,12 +100,12 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve { if ord_preds .iter() - .any(|ord| Some(ord.self_ty()) == return_ty_pred.term.ty()) + .any(|ord| Some(ord.self_ty()) == return_ty_pred.term.as_type()) { args_to_check.push((i, "Ord".to_string())); } else if partial_ord_preds .iter() - .any(|pord| pord.self_ty() == return_ty_pred.term.ty().unwrap()) + .any(|pord| pord.self_ty() == return_ty_pred.term.expect_type()) { args_to_check.push((i, "PartialOrd".to_string())); } diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 3414b5ef680c..f0dac6f5d9c4 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -750,7 +750,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option None, @@ -798,7 +798,7 @@ fn sig_from_bounds<'tcx>( // Multiple different fn trait impls. Is this even allowed? return None; } - output = Some(pred.kind().rebind(p.term.ty().unwrap())); + output = Some(pred.kind().rebind(p.term.expect_type())); }, _ => (), } @@ -836,7 +836,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option // Multiple different fn trait impls. Is this even allowed? return None; } - output = pred.kind().rebind(p.term.ty()).transpose(); + output = pred.kind().rebind(p.term.as_type()).transpose(); }, _ => (), } From d517233d2719a4dbf6e15e6cacbc56fd57298f6e Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 23 May 2024 10:01:05 -0300 Subject: [PATCH 1198/1222] Handle safety keyword for extern block inner items --- clippy_utils/src/ast_utils.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index bbdde3049dbd..14f9ef8966d6 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -451,13 +451,15 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { ty: lt, mutability: lm, expr: le, + safety: ls, }), Static(box StaticForeignItem { ty: rt, mutability: rm, expr: re, + safety: rs, }), - ) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), + ) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re) && ls == rs, ( Fn(box ast::Fn { defaultness: ld, From 4dbf79bd0488eb37a50886273280a902f121423b Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 7 May 2024 14:43:23 +0200 Subject: [PATCH 1199/1222] Add safe/unsafe to static inside extern blocks --- clippy_utils/src/ast_utils.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 14f9ef8966d6..c70f5c2df842 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -308,13 +308,15 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { ty: lt, mutability: lm, expr: le, + safety: ls, }), Static(box StaticItem { ty: rt, mutability: rm, expr: re, + safety: rs, }), - ) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), + ) => lm == rm && ls == rs && eq_ty(lt, rt) && eq_expr_opt(le, re), ( Const(box ConstItem { defaultness: ld, From 66cba9d42763ca3b3b0484cb58694206c7d6e770 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 31 May 2024 15:43:18 +1000 Subject: [PATCH 1200/1222] Make top-level `rustc_parse` functions fallible. Currently we have an awkward mix of fallible and infallible functions: ``` new_parser_from_source_str maybe_new_parser_from_source_str new_parser_from_file (maybe_new_parser_from_file) // missing (new_parser_from_source_file) // missing maybe_new_parser_from_source_file source_str_to_stream maybe_source_file_to_stream ``` We could add the two missing functions, but instead this commit removes of all the infallible ones and renames the fallible ones leaving us with these which are all fallible: ``` new_parser_from_source_str new_parser_from_file new_parser_from_source_file source_str_to_stream source_file_to_stream ``` This requires making `unwrap_or_emit_fatal` public so callers of formerly infallible functions can still work. This does make some of the call sites slightly more verbose, but I think it's worth it for the simpler API. Also, there are two `catch_unwind` calls and one `catch_fatal_errors` call in this diff that become removable thanks this change. (I will do that in a follow-up PR.) --- clippy_lints/src/doc/needless_doctest_main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/doc/needless_doctest_main.rs b/clippy_lints/src/doc/needless_doctest_main.rs index 651f2ebaee6f..c3e3c0431e6b 100644 --- a/clippy_lints/src/doc/needless_doctest_main.rs +++ b/clippy_lints/src/doc/needless_doctest_main.rs @@ -8,7 +8,7 @@ use rustc_data_structures::sync::Lrc; use rustc_errors::emitter::HumanEmitter; use rustc_errors::{Diag, DiagCtxt}; use rustc_lint::LateContext; -use rustc_parse::maybe_new_parser_from_source_str; +use rustc_parse::new_parser_from_source_str; use rustc_parse::parser::ForceCollect; use rustc_session::parse::ParseSess; use rustc_span::edition::Edition; @@ -50,7 +50,7 @@ pub fn check( let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let psess = ParseSess::with_dcx(dcx, sm); - let mut parser = match maybe_new_parser_from_source_str(&psess, filename, code) { + let mut parser = match new_parser_from_source_str(&psess, filename, code) { Ok(p) => p, Err(errs) => { errs.into_iter().for_each(Diag::cancel); From 6d33bdf2d47e2c5cabb1ed96420cee42d88689ab Mon Sep 17 00:00:00 2001 From: Boxy Date: Tue, 4 Jun 2024 07:01:58 +0100 Subject: [PATCH 1201/1222] Misc fixes to cranelift/clippy/miri --- clippy_lints/src/large_const_arrays.rs | 2 +- clippy_lints/src/large_stack_arrays.rs | 2 +- clippy_lints/src/matches/overlapping_arms.rs | 4 ++-- clippy_lints/src/zero_repeat_side_effects.rs | 2 +- clippy_utils/src/lib.rs | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index b561054b5824..77d05020c828 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays { && generics.params.is_empty() && !generics.has_where_clause_predicates && let ty = cx.tcx.type_of(item.owner_id).instantiate_identity() && let ty::Array(element_type, cst) = ty.kind() - && let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind() + && let ConstKind::Value(_, ty::ValTree::Leaf(element_count)) = cst.kind() && let Ok(element_count) = element_count.try_to_target_usize(cx.tcx) && let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()) && self.maximum_allowed_size < u128::from(element_count) * u128::from(element_size) diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index 208d1bb6e68a..f0f3f53647b9 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays { if let ExprKind::Repeat(_, _) | ExprKind::Array(_) = expr.kind && !self.is_from_vec_macro(cx, expr.span) && let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind() - && let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind() + && let ConstKind::Value(_, ty::ValTree::Leaf(element_count)) = cst.kind() && let Ok(element_count) = element_count.try_to_target_usize(cx.tcx) && let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()) && !cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, node)| { diff --git a/clippy_lints/src/matches/overlapping_arms.rs b/clippy_lints/src/matches/overlapping_arms.rs index 8199366d175f..45b375dbe3d7 100644 --- a/clippy_lints/src/matches/overlapping_arms.rs +++ b/clippy_lints/src/matches/overlapping_arms.rs @@ -37,14 +37,14 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>) Some(lhs) => constant(cx, cx.typeck_results(), lhs)?, None => { let min_val_const = ty.numeric_min_val(cx.tcx)?; - mir_to_const(cx, mir::Const::from_ty_const(min_val_const, cx.tcx))? + mir_to_const(cx, mir::Const::from_ty_const(min_val_const, ty, cx.tcx))? }, }; let rhs_const = match rhs { Some(rhs) => constant(cx, cx.typeck_results(), rhs)?, None => { let max_val_const = ty.numeric_max_val(cx.tcx)?; - mir_to_const(cx, mir::Const::from_ty_const(max_val_const, cx.tcx))? + mir_to_const(cx, mir::Const::from_ty_const(max_val_const, ty, cx.tcx))? }, }; let lhs_val = lhs_const.int_value(cx, ty)?; diff --git a/clippy_lints/src/zero_repeat_side_effects.rs b/clippy_lints/src/zero_repeat_side_effects.rs index 143fecdd237d..848b49130dc2 100644 --- a/clippy_lints/src/zero_repeat_side_effects.rs +++ b/clippy_lints/src/zero_repeat_side_effects.rs @@ -55,7 +55,7 @@ impl LateLintPass<'_> for ZeroRepeatSideEffects { inner_check(cx, expr, inner_expr, true); } else if let ExprKind::Repeat(inner_expr, _) = expr.kind && let ty::Array(_, cst) = cx.typeck_results().expr_ty(expr).kind() - && let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind() + && let ConstKind::Value(_, ty::ValTree::Leaf(element_count)) = cst.kind() && let Ok(element_count) = element_count.try_to_target_usize(cx.tcx) && element_count == 0 { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index b10830b24e1f..1147dce6215f 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1534,7 +1534,7 @@ pub fn is_range_full(cx: &LateContext<'_>, expr: &Expr<'_>, container_path: Opti if let rustc_ty::Adt(_, subst) = ty.kind() && let bnd_ty = subst.type_at(0) && let Some(min_val) = bnd_ty.numeric_min_val(cx.tcx) - && let Some(min_const) = mir_to_const(cx, Const::from_ty_const(min_val, cx.tcx)) + && let Some(min_const) = mir_to_const(cx, Const::from_ty_const(min_val, bnd_ty, cx.tcx)) && let Some(start_const) = constant(cx, cx.typeck_results(), start) { start_const == min_const @@ -1547,7 +1547,7 @@ pub fn is_range_full(cx: &LateContext<'_>, expr: &Expr<'_>, container_path: Opti if let rustc_ty::Adt(_, subst) = ty.kind() && let bnd_ty = subst.type_at(0) && let Some(max_val) = bnd_ty.numeric_max_val(cx.tcx) - && let Some(max_const) = mir_to_const(cx, Const::from_ty_const(max_val, cx.tcx)) + && let Some(max_const) = mir_to_const(cx, Const::from_ty_const(max_val, bnd_ty, cx.tcx)) && let Some(end_const) = constant(cx, cx.typeck_results(), end) { end_const == max_const From e27da9074427b149621398d3805d8ea1d86794f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Thu, 6 Jun 2024 09:45:50 +0000 Subject: [PATCH 1202/1222] Revert "Rollup merge of #124976 - petrochenkov:usedcrates, r=oli-obk" This reverts commit eda4a35f365535af72118118a3597edf5a13c12d, reversing changes made to eb6b35b5bcb3c2a594cb29cd478aeb2893f49d30. --- clippy_utils/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 1147dce6215f..2f6bf9209677 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -647,7 +647,7 @@ fn item_children_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) -> Vec, path: &[&str]) -> Vec { fn find_crates(tcx: TyCtxt<'_>, name: Symbol) -> impl Iterator + '_ { - tcx.crates_including_speculative(()) + tcx.crates(()) .iter() .copied() .filter(move |&num| tcx.crate_name(num) == name) From 9910dbb4ca2d67cca29402e8ff8fc66ac73a5d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Thu, 6 Jun 2024 20:39:54 +0000 Subject: [PATCH 1203/1222] Revert "Rollup merge of #124099 - voidc:disallow-ambiguous-expr-attrs, r=davidtwco" This reverts commit 57dad1d75e562ff73051c1c43b07eaf65c7dbd74, reversing changes made to 36316df9fe6c3e246153fe6e78967643cf08c148. --- tests/ui/cfg_attr_rustfmt.fixed | 6 +++--- tests/ui/cfg_attr_rustfmt.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/ui/cfg_attr_rustfmt.fixed b/tests/ui/cfg_attr_rustfmt.fixed index 84dac431169a..05d5b3d10eaf 100644 --- a/tests/ui/cfg_attr_rustfmt.fixed +++ b/tests/ui/cfg_attr_rustfmt.fixed @@ -16,7 +16,7 @@ fn foo( fn skip_on_statements() { #[rustfmt::skip] - { 5+3; } + 5+3; } #[rustfmt::skip] @@ -33,11 +33,11 @@ mod foo { #[clippy::msrv = "1.29"] fn msrv_1_29() { #[cfg_attr(rustfmt, rustfmt::skip)] - { 1+29; } + 1+29; } #[clippy::msrv = "1.30"] fn msrv_1_30() { #[rustfmt::skip] - { 1+30; } + 1+30; } diff --git a/tests/ui/cfg_attr_rustfmt.rs b/tests/ui/cfg_attr_rustfmt.rs index 4ab5c70e13b5..bc29e20210e8 100644 --- a/tests/ui/cfg_attr_rustfmt.rs +++ b/tests/ui/cfg_attr_rustfmt.rs @@ -16,7 +16,7 @@ fn foo( fn skip_on_statements() { #[cfg_attr(rustfmt, rustfmt::skip)] - { 5+3; } + 5+3; } #[cfg_attr(rustfmt, rustfmt_skip)] @@ -33,11 +33,11 @@ mod foo { #[clippy::msrv = "1.29"] fn msrv_1_29() { #[cfg_attr(rustfmt, rustfmt::skip)] - { 1+29; } + 1+29; } #[clippy::msrv = "1.30"] fn msrv_1_30() { #[cfg_attr(rustfmt, rustfmt::skip)] - { 1+30; } + 1+30; } From 28c2932d571a04162ca1f07c140f95f32860012d Mon Sep 17 00:00:00 2001 From: Slanterns Date: Fri, 7 Jun 2024 08:37:05 +0800 Subject: [PATCH 1204/1222] bless `std_instead_of_core` --- tests/ui/std_instead_of_core.fixed | 4 ++-- tests/ui/std_instead_of_core.rs | 2 +- tests/ui/std_instead_of_core.stderr | 8 +++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/ui/std_instead_of_core.fixed b/tests/ui/std_instead_of_core.fixed index ec4ae2ea13c5..6ede7bfcd9f6 100644 --- a/tests/ui/std_instead_of_core.fixed +++ b/tests/ui/std_instead_of_core.fixed @@ -45,8 +45,8 @@ fn std_instead_of_core() { let _ = std::env!("PATH"); - // do not lint until `error_in_core` is stable - use std::error::Error; + use core::error::Error; + //~^ ERROR: used import from `std` instead of `core` // lint items re-exported from private modules, `core::iter::traits::iterator::Iterator` use core::iter::Iterator; diff --git a/tests/ui/std_instead_of_core.rs b/tests/ui/std_instead_of_core.rs index c12c459c7eb4..e22b4f61f3ec 100644 --- a/tests/ui/std_instead_of_core.rs +++ b/tests/ui/std_instead_of_core.rs @@ -45,8 +45,8 @@ fn std_instead_of_core() { let _ = std::env!("PATH"); - // do not lint until `error_in_core` is stable use std::error::Error; + //~^ ERROR: used import from `std` instead of `core` // lint items re-exported from private modules, `core::iter::traits::iterator::Iterator` use std::iter::Iterator; diff --git a/tests/ui/std_instead_of_core.stderr b/tests/ui/std_instead_of_core.stderr index 8f920511cc5d..22cb9db7050b 100644 --- a/tests/ui/std_instead_of_core.stderr +++ b/tests/ui/std_instead_of_core.stderr @@ -49,6 +49,12 @@ error: used import from `std` instead of `core` LL | let cell_absolute = ::std::cell::Cell::new(8u32); | ^^^ help: consider importing the item from `core`: `core` +error: used import from `std` instead of `core` + --> tests/ui/std_instead_of_core.rs:48:9 + | +LL | use std::error::Error; + | ^^^ help: consider importing the item from `core`: `core` + error: used import from `std` instead of `core` --> tests/ui/std_instead_of_core.rs:52:9 | @@ -79,5 +85,5 @@ LL | use alloc::slice::from_ref; = note: `-D clippy::alloc-instead-of-core` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::alloc_instead_of_core)]` -error: aborting due to 12 previous errors +error: aborting due to 13 previous errors From 76bf67307ea59c708508cfbd030e40f07ad951a5 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 3 Jun 2024 09:11:58 +0000 Subject: [PATCH 1205/1222] Revert "Create const block DefIds in typeck instead of ast lowering" This reverts commit ddc5f9b6c1f21da5d4596bf7980185a00984ac42. --- clippy_utils/src/consts.rs | 6 ++--- clippy_utils/src/hir_utils.rs | 6 ++--- tests/ui/arithmetic_side_effects.stderr | 32 ++++--------------------- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index cd88ccd87cf0..5c9cad2b45d4 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -6,7 +6,7 @@ use crate::{clip, is_direct_expn_of, sext, unsext}; use rustc_ast::ast::{self, LitFloatType, LitKind}; use rustc_data_structures::sync::Lrc; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, Item, ItemKind, Node, QPath, UnOp}; +use rustc_hir::{BinOp, BinOpKind, Block, ConstBlock, Expr, ExprKind, HirId, Item, ItemKind, Node, QPath, UnOp}; use rustc_lexer::tokenize; use rustc_lint::LateContext; use rustc_middle::mir::interpret::{alloc_range, Scalar}; @@ -412,7 +412,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { /// Simple constant folding: Insert an expression, get a constant or none. pub fn expr(&mut self, e: &Expr<'_>) -> Option> { match e.kind { - ExprKind::ConstBlock(e) | ExprKind::DropTemps(e) => self.expr(e), + ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.lcx.tcx.hir().body(body).value), ExprKind::DropTemps(e) => self.expr(e), ExprKind::Path(ref qpath) => { self.fetch_path_and_apply(qpath, e.hir_id, self.typeck_results.expr_ty(e), |this, result| { let result = mir_to_const(this.lcx, result)?; @@ -490,7 +490,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { /// leaves the local crate. pub fn expr_is_empty(&mut self, e: &Expr<'_>) -> Option { match e.kind { - ExprKind::ConstBlock(e) | ExprKind::DropTemps(e) => self.expr_is_empty(e), + ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr_is_empty(self.lcx.tcx.hir().body(body).value), ExprKind::DropTemps(e) => self.expr_is_empty(e), ExprKind::Path(ref qpath) => { if !self .typeck_results diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index c649c1794684..36634817fc91 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -295,7 +295,7 @@ impl HirEqInterExpr<'_, '_, '_> { self.eq_expr(lx, rx) && self.eq_ty(lt, rt) }, (&ExprKind::Closure(_l), &ExprKind::Closure(_r)) => false, - (&ExprKind::ConstBlock(lb), &ExprKind::ConstBlock(rb)) => self.eq_expr(lb, rb), + (&ExprKind::ConstBlock(lb), &ExprKind::ConstBlock(rb)) => self.eq_body(lb.body, rb.body), (&ExprKind::Continue(li), &ExprKind::Continue(ri)) => { both(&li.label, &ri.label, |l, r| l.ident.name == r.ident.name) }, @@ -769,8 +769,8 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { // closures inherit TypeckResults self.hash_expr(self.cx.tcx.hir().body(body).value); }, - ExprKind::ConstBlock(l_id) => { - self.hash_expr(l_id); + ExprKind::ConstBlock(ref l_id) => { + self.hash_body(l_id.body); }, ExprKind::DropTemps(e) | ExprKind::Yield(e, _) => { self.hash_expr(e); diff --git a/tests/ui/arithmetic_side_effects.stderr b/tests/ui/arithmetic_side_effects.stderr index df14ff396f6c..8039c0bfa248 100644 --- a/tests/ui/arithmetic_side_effects.stderr +++ b/tests/ui/arithmetic_side_effects.stderr @@ -1,35 +1,11 @@ -error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:188:36 - | -LL | let _ = const { let mut n = 1; n += 1; n }; - | ^^^^^^ - | - = note: `-D clippy::arithmetic-side-effects` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]` - -error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:191:40 - | -LL | let _ = const { let mut n = 1; n = n + 1; n }; - | ^^^^^ - -error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:194:40 - | -LL | let _ = const { let mut n = 1; n = 1 + n; n }; - | ^^^^^ - -error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:200:59 - | -LL | let _ = const { let mut n = 1; n = -1; n = -(-1); n = -n; n }; - | ^^ - error: arithmetic operation that can potentially result in unexpected side-effects --> tests/ui/arithmetic_side_effects.rs:304:5 | LL | _n += 1; | ^^^^^^^ + | + = note: `-D clippy::arithmetic-side-effects` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]` error: arithmetic operation that can potentially result in unexpected side-effects --> tests/ui/arithmetic_side_effects.rs:305:5 @@ -751,5 +727,5 @@ error: arithmetic operation that can potentially result in unexpected side-effec LL | one.sub_assign(1); | ^^^^^^^^^^^^^^^^^ -error: aborting due to 125 previous errors +error: aborting due to 121 previous errors From c097267cb5e2938be64c6687c151e8047f15f959 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Sat, 8 Jun 2024 20:18:31 +0100 Subject: [PATCH 1206/1222] Update `icu4x` dependencies --- tests/ui/unicode.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/unicode.stderr b/tests/ui/unicode.stderr index 9c365e1097db..b004493300ee 100644 --- a/tests/ui/unicode.stderr +++ b/tests/ui/unicode.stderr @@ -11,7 +11,7 @@ error: invisible character detected --> tests/ui/unicode.rs:7:12 | LL | print!("Here >­< is a SHY, and ­another"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >\u{AD}< is a SHY, and \u{AD}another"` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >\u{AD}< is a SHY, and \u{AD}another"` error: invisible character detected --> tests/ui/unicode.rs:9:12 From dc453dd1bb7e5e85b8a944ee2e741a8dbde8275d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 8 Jun 2024 16:13:45 +0200 Subject: [PATCH 1207/1222] ScalarInt: size mismatches are a bug, do not delay the panic --- clippy_lints/src/large_const_arrays.rs | 2 +- clippy_lints/src/large_stack_arrays.rs | 2 +- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/zero_repeat_side_effects.rs | 3 +-- clippy_utils/src/consts.rs | 4 ++-- clippy_utils/src/ty.rs | 20 +++----------------- 6 files changed, 9 insertions(+), 24 deletions(-) diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index 77d05020c828..7f8197c0cc01 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays { && let ty = cx.tcx.type_of(item.owner_id).instantiate_identity() && let ty::Array(element_type, cst) = ty.kind() && let ConstKind::Value(_, ty::ValTree::Leaf(element_count)) = cst.kind() - && let Ok(element_count) = element_count.try_to_target_usize(cx.tcx) + && let element_count = element_count.to_target_usize(cx.tcx) && let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()) && self.maximum_allowed_size < u128::from(element_count) * u128::from(element_size) { diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index f0f3f53647b9..c9bfc9c85d95 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -65,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays { && !self.is_from_vec_macro(cx, expr.span) && let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind() && let ConstKind::Value(_, ty::ValTree::Leaf(element_count)) = cst.kind() - && let Ok(element_count) = element_count.try_to_target_usize(cx.tcx) + && let element_count = element_count.to_target_usize(cx.tcx) && let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()) && !cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, node)| { matches!( diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 76d9cee18aa7..20a97645af95 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -199,7 +199,7 @@ impl<'tcx> NonCopyConst<'tcx> { .any(|field| Self::is_value_unfrozen_raw_inner(cx, *field, ty)), ty::Adt(def, args) if def.is_enum() => { let (&variant_index, fields) = val.unwrap_branch().split_first().unwrap(); - let variant_index = VariantIdx::from_u32(variant_index.unwrap_leaf().try_to_u32().ok().unwrap()); + let variant_index = VariantIdx::from_u32(variant_index.unwrap_leaf().to_u32()); fields .iter() .copied() diff --git a/clippy_lints/src/zero_repeat_side_effects.rs b/clippy_lints/src/zero_repeat_side_effects.rs index 848b49130dc2..8796b8f61d16 100644 --- a/clippy_lints/src/zero_repeat_side_effects.rs +++ b/clippy_lints/src/zero_repeat_side_effects.rs @@ -56,8 +56,7 @@ impl LateLintPass<'_> for ZeroRepeatSideEffects { } else if let ExprKind::Repeat(inner_expr, _) = expr.kind && let ty::Array(_, cst) = cx.typeck_results().expr_ty(expr).kind() && let ConstKind::Value(_, ty::ValTree::Leaf(element_count)) = cst.kind() - && let Ok(element_count) = element_count.try_to_target_usize(cx.tcx) - && element_count == 0 + && element_count.to_target_usize(cx.tcx) == 0 { inner_check(cx, expr, inner_expr, false); } diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 5c9cad2b45d4..e9e1aa7e4453 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -810,14 +810,14 @@ pub fn mir_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::Const<'tcx>) -> (ConstValue::Scalar(Scalar::Int(int)), _) => match result.ty().kind() { ty::Adt(adt_def, _) if adt_def.is_struct() => Some(Constant::Adt(result)), ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)), - ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.assert_bits(int.size()))), + ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.to_bits(int.size()))), ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits( int.try_into().expect("invalid f32 bit representation"), ))), ty::Float(FloatTy::F64) => Some(Constant::F64(f64::from_bits( int.try_into().expect("invalid f64 bit representation"), ))), - ty::RawPtr(_, _) => Some(Constant::RawPtr(int.assert_bits(int.size()))), + ty::RawPtr(_, _) => Some(Constant::RawPtr(int.to_bits(int.size()))), _ => None, }, (_, ty::Ref(_, inner_ty, _)) if matches!(inner_ty.kind(), ty::Str) => { diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index f0dac6f5d9c4..6e5626297c95 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -23,7 +23,7 @@ use rustc_middle::ty::{ }; use rustc_span::symbol::Ident; use rustc_span::{sym, Span, Symbol, DUMMY_SP}; -use rustc_target::abi::{Size, VariantIdx}; +use rustc_target::abi::VariantIdx; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt; use rustc_trait_selection::traits::{Obligation, ObligationCause}; @@ -865,22 +865,8 @@ impl core::ops::Add for EnumValue { pub fn read_explicit_enum_value(tcx: TyCtxt<'_>, id: DefId) -> Option { if let Ok(ConstValue::Scalar(Scalar::Int(value))) = tcx.const_eval_poly(id) { match tcx.type_of(id).instantiate_identity().kind() { - ty::Int(_) => Some(EnumValue::Signed(match value.size().bytes() { - 1 => i128::from(value.assert_bits(Size::from_bytes(1)) as u8 as i8), - 2 => i128::from(value.assert_bits(Size::from_bytes(2)) as u16 as i16), - 4 => i128::from(value.assert_bits(Size::from_bytes(4)) as u32 as i32), - 8 => i128::from(value.assert_bits(Size::from_bytes(8)) as u64 as i64), - 16 => value.assert_bits(Size::from_bytes(16)) as i128, - _ => return None, - })), - ty::Uint(_) => Some(EnumValue::Unsigned(match value.size().bytes() { - 1 => value.assert_bits(Size::from_bytes(1)), - 2 => value.assert_bits(Size::from_bytes(2)), - 4 => value.assert_bits(Size::from_bytes(4)), - 8 => value.assert_bits(Size::from_bytes(8)), - 16 => value.assert_bits(Size::from_bytes(16)), - _ => return None, - })), + ty::Int(_) => Some(EnumValue::Signed(value.to_int(value.size()))), + ty::Uint(_) => Some(EnumValue::Unsigned(value.to_uint(value.size()))), _ => None, } } else { From bd9a7a23a1f8a7d530db685404719c5485eeb770 Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Thu, 23 May 2024 18:02:13 +0200 Subject: [PATCH 1208/1222] Fixup clippy tests Don't depend on the fact that `!` falls back to `()` and so panic-ish things can be used in `-> impl ImplementedForUnit` functions --- tests/ui/new_ret_no_self.rs | 5 +---- tests/ui/new_ret_no_self.stderr | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/ui/new_ret_no_self.rs b/tests/ui/new_ret_no_self.rs index b944f531ef66..175b14d815a2 100644 --- a/tests/ui/new_ret_no_self.rs +++ b/tests/ui/new_ret_no_self.rs @@ -390,9 +390,7 @@ mod issue7344 { impl RetImplTraitSelf2 { // should not trigger lint - fn new(t: T) -> impl Trait2<(), Self> { - unimplemented!() - } + fn new(t: T) -> impl Trait2<(), Self> {} } struct RetImplTraitNoSelf2(T); @@ -401,7 +399,6 @@ mod issue7344 { // should trigger lint fn new(t: T) -> impl Trait2<(), i32> { //~^ ERROR: methods called `new` usually return `Self` - unimplemented!() } } diff --git a/tests/ui/new_ret_no_self.stderr b/tests/ui/new_ret_no_self.stderr index d440a9f45fcd..3597ad65838f 100644 --- a/tests/ui/new_ret_no_self.stderr +++ b/tests/ui/new_ret_no_self.stderr @@ -96,11 +96,10 @@ LL | | } | |_________^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:402:9 + --> tests/ui/new_ret_no_self.rs:400:9 | LL | / fn new(t: T) -> impl Trait2<(), i32> { LL | | -LL | | unimplemented!() LL | | } | |_________^ From b255c06e056fb795cd1be34cd64ce8dca89719fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 12 Jun 2024 23:51:31 +0000 Subject: [PATCH 1209/1222] Tweak output of import suggestions When both `std::` and `core::` items are available, only suggest the `std::` ones. We ensure that in `no_std` crates we suggest `core::` items. Ensure that the list of items suggested to be imported are always in the order of local crate items, `std`/`core` items and finally foreign crate items. Tweak wording of import suggestion: if there are multiple items but they are all of the same kind, we use the kind name and not the generic "items". Fix #83564. --- tests/ui/crashes/ice-6252.stderr | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index ce3b9495eb1e..cd2031af1c6d 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -4,9 +4,7 @@ error[E0412]: cannot find type `PhantomData` in this scope LL | _n: PhantomData, | ^^^^^^^^^^^ not found in this scope | -help: consider importing one of these items - | -LL + use core::marker::PhantomData; +help: consider importing this struct | LL + use std::marker::PhantomData; | From 149ab8908f8057b481c4c648497d21c2bc447045 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 5 Jun 2024 16:18:52 -0400 Subject: [PATCH 1210/1222] Rework precise capturing syntax --- clippy_lints/src/needless_maybe_sized.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/needless_maybe_sized.rs b/clippy_lints/src/needless_maybe_sized.rs index 06ae1723a03d..4922c87b206c 100644 --- a/clippy_lints/src/needless_maybe_sized.rs +++ b/clippy_lints/src/needless_maybe_sized.rs @@ -73,7 +73,7 @@ fn type_param_bounds<'tcx>(generics: &'tcx Generics<'tcx>) -> impl Iterator None, + GenericBound::Outlives(_) | GenericBound::Use(..) => None, }) .filter(|bound| !bound.trait_bound.span.from_expansion()), ) From 192fe3c43996b509c41077e1f759bc3356289022 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 6 Jun 2024 09:01:45 -0400 Subject: [PATCH 1211/1222] Fix other tools --- clippy_utils/src/ast_utils.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index c70f5c2df842..fb43f7d80aff 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -724,11 +724,8 @@ pub fn eq_ty(l: &Ty, r: &Ty) -> bool { (Tup(l), Tup(r)) => over(l, r, |l, r| eq_ty(l, r)), (Path(lq, lp), Path(rq, rp)) => both(lq, rq, eq_qself) && eq_path(lp, rp), (TraitObject(lg, ls), TraitObject(rg, rs)) => ls == rs && over(lg, rg, eq_generic_bound), - (ImplTrait(_, lg, lc), ImplTrait(_, rg, rc)) => { + (ImplTrait(_, lg), ImplTrait(_, rg)) => { over(lg, rg, eq_generic_bound) - && both(lc, rc, |lc, rc| { - over(lc.0.as_slice(), rc.0.as_slice(), eq_precise_capture) - }) }, (Typeof(l), Typeof(r)) => eq_expr(&l.value, &r.value), (MacCall(l), MacCall(r)) => eq_mac_call(l, r), From c02b53c8b23b3828cad80521d92ae9de3f001cf7 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 18 Jun 2024 10:35:56 +0000 Subject: [PATCH 1212/1222] Use a dedicated type instead of a reference for the diagnostic context This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle --- src/driver.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index f79da26964f3..6117e76897f2 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -180,12 +180,12 @@ pub fn main() { rustc_driver::init_rustc_env_logger(&early_dcx); - let using_internal_features = rustc_driver::install_ice_hook(BUG_REPORT_URL, |handler| { + let using_internal_features = rustc_driver::install_ice_hook(BUG_REPORT_URL, |dcx| { // FIXME: this macro calls unwrap internally but is called in a panicking context! It's not // as simple as moving the call from the hook to main, because `install_ice_hook` doesn't // accept a generic closure. let version_info = rustc_tools_util::get_version_info!(); - handler.note(format!("Clippy version: {version_info}")); + dcx.handle().note(format!("Clippy version: {version_info}")); }); exit(rustc_driver::catch_with_exit_code(move || { From 7374300c64887cf67b562fea5e7b0df432ed7f4c Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 18 Jun 2024 11:46:26 -0500 Subject: [PATCH 1213/1222] Resolve Clippy `f16` and `f128` `unimplemented!`/`FIXME`s This removes the ICE codepaths for `f16` and `f128` in Clippy. `rustc_apfloat` is used as a dependency for the parsing of these types, since their `FromStr` implementation will not be available in the standard library for a while. --- clippy_lints/src/casts/cast_nan_to_int.rs | 1 + clippy_lints/src/float_literal.rs | 7 ++- clippy_lints/src/lib.rs | 2 + clippy_lints/src/manual_float_methods.rs | 2 + clippy_lints/src/operators/float_cmp.rs | 1 + .../src/operators/modulo_arithmetic.rs | 1 + clippy_lints/src/zero_div_zero.rs | 1 + clippy_utils/Cargo.toml | 2 + clippy_utils/src/consts.rs | 43 ++++++++++++++++--- clippy_utils/src/lib.rs | 2 + 10 files changed, 52 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/casts/cast_nan_to_int.rs b/clippy_lints/src/casts/cast_nan_to_int.rs index 1743ce71adde..5bc8692c289f 100644 --- a/clippy_lints/src/casts/cast_nan_to_int.rs +++ b/clippy_lints/src/casts/cast_nan_to_int.rs @@ -21,6 +21,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, fn is_known_nan(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { match constant(cx, cx.typeck_results(), e) { + // FIXME(f16_f128): add these types when nan checks are available on all platforms Some(Constant::F64(n)) => n.is_nan(), Some(Constant::F32(n)) => n.is_nan(), _ => false, diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index 4d301daabe4c..2261fcdbdabc 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -141,18 +141,17 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral { #[must_use] fn max_digits(fty: FloatTy) -> u32 { match fty { - // FIXME(f16_f128): replace the magic numbers once `{f16,f128}::DIGITS` are available - FloatTy::F16 => 3, + FloatTy::F16 => f16::DIGITS, FloatTy::F32 => f32::DIGITS, FloatTy::F64 => f64::DIGITS, - FloatTy::F128 => 33, + FloatTy::F128 => f128::DIGITS, } } /// Counts the digits excluding leading zeros #[must_use] fn count_digits(s: &str) -> usize { - // Note that s does not contain the f32/64 suffix, and underscores have been stripped + // Note that s does not contain the `f{16,32,64,128}` suffix, and underscores have been stripped s.chars() .filter(|c| *c != '-' && *c != '.') .take_while(|c| *c != 'e' && *c != 'E') diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index c65581d5203e..ef322786dbcd 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -1,6 +1,8 @@ #![feature(array_windows)] #![feature(binary_heap_into_iter_sorted)] #![feature(box_patterns)] +#![feature(f128)] +#![feature(f16)] #![feature(if_let_guard)] #![feature(iter_intersperse)] #![feature(let_chains)] diff --git a/clippy_lints/src/manual_float_methods.rs b/clippy_lints/src/manual_float_methods.rs index 72cf1d7a3546..89eea0b4456d 100644 --- a/clippy_lints/src/manual_float_methods.rs +++ b/clippy_lints/src/manual_float_methods.rs @@ -156,6 +156,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods { fn is_infinity(constant: &Constant<'_>) -> bool { match constant { + // FIXME(f16_f128): add f16 and f128 when constants are available Constant::F32(float) => *float == f32::INFINITY, Constant::F64(float) => *float == f64::INFINITY, _ => false, @@ -164,6 +165,7 @@ fn is_infinity(constant: &Constant<'_>) -> bool { fn is_neg_infinity(constant: &Constant<'_>) -> bool { match constant { + // FIXME(f16_f128): add f16 and f128 when constants are available Constant::F32(float) => *float == f32::NEG_INFINITY, Constant::F64(float) => *float == f64::NEG_INFINITY, _ => false, diff --git a/clippy_lints/src/operators/float_cmp.rs b/clippy_lints/src/operators/float_cmp.rs index 0561739d160f..faab79de9d3c 100644 --- a/clippy_lints/src/operators/float_cmp.rs +++ b/clippy_lints/src/operators/float_cmp.rs @@ -86,6 +86,7 @@ fn get_lint_and_message(is_local: bool, is_comparing_arrays: bool) -> (&'static fn is_allowed(val: &Constant<'_>) -> bool { match val { + // FIXME(f16_f128): add when equality check is available on all platforms &Constant::F32(f) => f == 0.0 || f.is_infinite(), &Constant::F64(f) => f == 0.0 || f.is_infinite(), Constant::Vec(vec) => vec.iter().all(|f| match f { diff --git a/clippy_lints/src/operators/modulo_arithmetic.rs b/clippy_lints/src/operators/modulo_arithmetic.rs index c56518ac72a4..d65fffac5a82 100644 --- a/clippy_lints/src/operators/modulo_arithmetic.rs +++ b/clippy_lints/src/operators/modulo_arithmetic.rs @@ -79,6 +79,7 @@ fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_>, expr: &Expr<'_>) -> }, _ => {}, }, + // FIXME(f16_f128): add when casting is available on all platforms Some(Constant::F32(f)) => { return Some(floating_point_operand_info(&f)); }, diff --git a/clippy_lints/src/zero_div_zero.rs b/clippy_lints/src/zero_div_zero.rs index 662242f6196b..60d8a13d3599 100644 --- a/clippy_lints/src/zero_div_zero.rs +++ b/clippy_lints/src/zero_div_zero.rs @@ -38,6 +38,7 @@ impl<'tcx> LateLintPass<'tcx> for ZeroDiv { // do something like 0.0/(2.0 - 2.0), but it would be nice to warn on that case too. && let Some(lhs_value) = constant_simple(cx, cx.typeck_results(), left) && let Some(rhs_value) = constant_simple(cx, cx.typeck_results(), right) + // FIXME(f16_f128): add these types when eq is available on all platforms && (Constant::F32(0.0) == lhs_value || Constant::F64(0.0) == lhs_value) && (Constant::F32(0.0) == rhs_value || Constant::F64(0.0) == rhs_value) { diff --git a/clippy_utils/Cargo.toml b/clippy_utils/Cargo.toml index 3a3aeb882164..6e53ff3ee6e9 100644 --- a/clippy_utils/Cargo.toml +++ b/clippy_utils/Cargo.toml @@ -9,6 +9,8 @@ clippy_config = { path = "../clippy_config" } arrayvec = { version = "0.7", default-features = false } itertools = "0.12" rustc-semver = "1.1" +# FIXME(f16_f128): remove when no longer needed for parsing +rustc_apfloat = "0.2.0" [features] deny-warnings = ["clippy_config/deny-warnings"] diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index cfd142fe1ff6..681c86f76d07 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -3,6 +3,8 @@ use crate::source::{get_source_text, walk_span_to_context}; use crate::{clip, is_direct_expn_of, sext, unsext}; +use rustc_apfloat::ieee::{Half, Quad}; +use rustc_apfloat::Float; use rustc_ast::ast::{self, LitFloatType, LitKind}; use rustc_data_structures::sync::Lrc; use rustc_hir::def::{DefKind, Res}; @@ -33,10 +35,14 @@ pub enum Constant<'tcx> { Char(char), /// An integer's bit representation. Int(u128), + /// An `f16`. + F16(f16), /// An `f32`. F32(f32), /// An `f64`. F64(f64), + /// An `f128`. + F128(f128), /// `true` or `false`. Bool(bool), /// An array of constants. @@ -161,12 +167,19 @@ impl<'tcx> Hash for Constant<'tcx> { Self::Int(i) => { i.hash(state); }, + Self::F16(f) => { + // FIXME(f16_f128): once conversions to/from `f128` are available on all platforms, + f.to_bits().hash(state); + }, Self::F32(f) => { f64::from(f).to_bits().hash(state); }, Self::F64(f) => { f.to_bits().hash(state); }, + Self::F128(f) => { + f.to_bits().hash(state); + }, Self::Bool(b) => { b.hash(state); }, @@ -268,6 +281,16 @@ impl<'tcx> Constant<'tcx> { } self } + + fn parse_f16(s: &str) -> Self { + let f: Half = s.parse().unwrap(); + Self::F16(f16::from_bits(f.to_bits().try_into().unwrap())) + } + + fn parse_f128(s: &str) -> Self { + let f: Quad = s.parse().unwrap(); + Self::F128(f128::from_bits(f.to_bits())) + } } /// Parses a `LitKind` to a `Constant`. @@ -279,16 +302,17 @@ pub fn lit_to_mir_constant<'tcx>(lit: &LitKind, ty: Option>) -> Constan LitKind::Char(c) => Constant::Char(c), LitKind::Int(n, _) => Constant::Int(n.get()), LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty { - ast::FloatTy::F16 => unimplemented!("f16_f128"), + // FIXME(f16_f128): just use `parse()` directly when available for `f16`/`f128` + ast::FloatTy::F16 => Constant::parse_f16(is.as_str()), ast::FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()), ast::FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()), - ast::FloatTy::F128 => unimplemented!("f16_f128"), + ast::FloatTy::F128 => Constant::parse_f128(is.as_str()), }, LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind() { - ty::Float(FloatTy::F16) => unimplemented!("f16_f128"), + ty::Float(FloatTy::F16) => Constant::parse_f16(is.as_str()), ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()), ty::Float(FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()), - ty::Float(FloatTy::F128) => unimplemented!("f16_f128"), + ty::Float(FloatTy::F128) => Constant::parse_f128(is.as_str()), _ => bug!(), }, LitKind::Bool(b) => Constant::Bool(b), @@ -625,15 +649,19 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { match (lhs, index) { (Some(Constant::Vec(vec)), Some(Constant::Int(index))) => match vec.get(index as usize) { + Some(Constant::F16(x)) => Some(Constant::F16(*x)), Some(Constant::F32(x)) => Some(Constant::F32(*x)), Some(Constant::F64(x)) => Some(Constant::F64(*x)), + Some(Constant::F128(x)) => Some(Constant::F128(*x)), _ => None, }, (Some(Constant::Vec(vec)), _) => { if !vec.is_empty() && vec.iter().all(|x| *x == vec[0]) { match vec.first() { + Some(Constant::F16(x)) => Some(Constant::F16(*x)), Some(Constant::F32(x)) => Some(Constant::F32(*x)), Some(Constant::F64(x)) => Some(Constant::F64(*x)), + Some(Constant::F128(x)) => Some(Constant::F128(*x)), _ => None, } } else { @@ -760,6 +788,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { }, _ => None, }, + // FIXME(f16_f128): add these types when binary operations are available on all platforms (Constant::F32(l), Some(Constant::F32(r))) => match op.node { BinOpKind::Add => Some(Constant::F32(l + r)), BinOpKind::Sub => Some(Constant::F32(l - r)), @@ -813,8 +842,10 @@ pub fn mir_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::Const<'tcx>) -> ty::Adt(adt_def, _) if adt_def.is_struct() => Some(Constant::Adt(result)), ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)), ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.to_bits(int.size()))), + ty::Float(FloatTy::F16) => Some(Constant::F16(f16::from_bits(int.into()))), ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits(int.into()))), ty::Float(FloatTy::F64) => Some(Constant::F64(f64::from_bits(int.into()))), + ty::Float(FloatTy::F128) => Some(Constant::F128(f128::from_bits(int.into()))), ty::RawPtr(_, _) => Some(Constant::RawPtr(int.to_bits(int.size()))), _ => None, }, @@ -835,10 +866,10 @@ pub fn mir_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::Const<'tcx>) -> let range = alloc_range(offset + size * idx, size); let val = alloc.read_scalar(&lcx.tcx, range, /* read_provenance */ false).ok()?; res.push(match flt { - FloatTy::F16 => unimplemented!("f16_f128"), + FloatTy::F16 => Constant::F16(f16::from_bits(val.to_u16().ok()?)), FloatTy::F32 => Constant::F32(f32::from_bits(val.to_u32().ok()?)), FloatTy::F64 => Constant::F64(f64::from_bits(val.to_u64().ok()?)), - FloatTy::F128 => unimplemented!("f16_f128"), + FloatTy::F128 => Constant::F128(f128::from_bits(val.to_u128().ok()?)), }); } Some(Constant::Vec(res)) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 7dc341ec8d71..6848e8e5c304 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1,6 +1,8 @@ #![feature(array_chunks)] #![feature(box_patterns)] #![feature(control_flow_enum)] +#![feature(f128)] +#![feature(f16)] #![feature(if_let_guard)] #![feature(let_chains)] #![feature(lint_reasons)] From 1d6ed4330e348e3d622436d8d7f61fc8193ca182 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 18 Jun 2024 12:34:49 -0500 Subject: [PATCH 1214/1222] Update float tests to include `f16` and `f128` --- .../conf_disallowed_methods.rs | 1 + .../conf_disallowed_methods.stderr | 20 +- tests/ui/arithmetic_side_effects.rs | 4 + tests/ui/arithmetic_side_effects.stderr | 260 +++++++++--------- tests/ui/cast.rs | 2 + tests/ui/cast.stderr | 184 ++++++------- tests/ui/cast_lossless_float.fixed | 2 + tests/ui/cast_lossless_float.rs | 2 + tests/ui/cast_lossless_float.stderr | 26 +- tests/ui/cast_nan_to_int.rs | 2 + tests/ui/cast_nan_to_int.stderr | 12 +- tests/ui/cast_size.64bit.stderr | 50 ++-- tests/ui/cast_size.rs | 13 +- tests/ui/endian_bytes.rs | 2 + tests/ui/endian_bytes.stderr | 172 ++++++------ tests/ui/float_cmp.rs | 2 + tests/ui/float_cmp.stderr | 12 +- tests/ui/float_equality_without_abs.rs | 3 + tests/ui/float_equality_without_abs.stderr | 22 +- tests/ui/floating_point_arithmetic_nostd.rs | 4 +- tests/ui/floating_point_exp.fixed | 2 + tests/ui/floating_point_exp.rs | 2 + tests/ui/floating_point_exp.stderr | 10 +- tests/ui/floating_point_log.fixed | 2 + tests/ui/floating_point_log.rs | 2 + tests/ui/floating_point_log.stderr | 58 ++-- tests/ui/floating_point_powf.fixed | 2 + tests/ui/floating_point_powf.rs | 2 + tests/ui/floating_point_powf.stderr | 62 ++--- tests/ui/lossy_float_literal.fixed | 24 ++ tests/ui/lossy_float_literal.rs | 24 ++ tests/ui/lossy_float_literal.stderr | 22 +- tests/ui/manual_float_methods.rs | 2 + tests/ui/manual_float_methods.stderr | 12 +- tests/ui/modulo_arithmetic_float.rs | 27 ++ tests/ui/modulo_arithmetic_float.stderr | 70 ++++- tests/ui/transmute.rs | 30 +- tests/ui/transmute.stderr | 116 +++++--- tests/ui/transmute_float_to_int.fixed | 12 + tests/ui/transmute_float_to_int.rs | 12 + tests/ui/transmute_float_to_int.stderr | 12 +- tests/ui/unused_rounding.fixed | 2 + tests/ui/unused_rounding.rs | 2 + tests/ui/unused_rounding.stderr | 10 +- 44 files changed, 792 insertions(+), 522 deletions(-) diff --git a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs index 63fdea710cb6..17fceae01780 100644 --- a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs +++ b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs @@ -40,6 +40,7 @@ fn main() { a.sort_unstable(); + // FIXME(f16_f128): add a clamp test once the function is available let _ = 2.0f32.clamp(3.0f32, 4.0f32); let _ = 2.0f64.clamp(3.0f64, 4.0f64); diff --git a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr index 55e867d5f393..4afbbf5f8079 100644 --- a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr +++ b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr @@ -28,61 +28,61 @@ LL | a.sort_unstable(); | ^^^^^^^^^^^^^^^^^ error: use of a disallowed method `f32::clamp` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:43:13 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:44:13 | LL | let _ = 2.0f32.clamp(3.0f32, 4.0f32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of a disallowed method `regex::Regex::new` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:46:61 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:47:61 | LL | let indirect: fn(&str) -> Result = Regex::new; | ^^^^^^^^^^ error: use of a disallowed method `f32::clamp` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:49:28 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:50:28 | LL | let in_call = Box::new(f32::clamp); | ^^^^^^^^^^ error: use of a disallowed method `regex::Regex::new` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:50:53 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:51:53 | LL | let in_method_call = ["^", "$"].into_iter().map(Regex::new); | ^^^^^^^^^^ error: use of a disallowed method `futures::stream::select_all` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:53:31 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:54:31 | LL | let same_name_as_module = select_all(vec![empty::<()>()]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::local_fn` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:55:5 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:56:5 | LL | local_fn(); | ^^^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::local_mod::f` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:56:5 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:57:5 | LL | local_mod::f(); | ^^^^^^^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::Struct::method` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:58:5 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:59:5 | LL | s.method(); | ^^^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::Trait::provided_method` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:59:5 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:60:5 | LL | s.provided_method(); | ^^^^^^^^^^^^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::Trait::implemented_method` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:60:5 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:61:5 | LL | s.implemented_method(); | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/arithmetic_side_effects.rs b/tests/ui/arithmetic_side_effects.rs index 33a91e8bbbe5..9d06e14e88c5 100644 --- a/tests/ui/arithmetic_side_effects.rs +++ b/tests/ui/arithmetic_side_effects.rs @@ -11,6 +11,8 @@ unconditional_panic )] #![feature(const_mut_refs)] +#![feature(f128)] +#![feature(f16)] #![warn(clippy::arithmetic_side_effects)] extern crate proc_macro_derive; @@ -162,8 +164,10 @@ pub fn association_with_structures_should_not_trigger_the_lint() { } pub fn hard_coded_allowed() { + let _ = 1f16 + 1f16; let _ = 1f32 + 1f32; let _ = 1f64 + 1f64; + let _ = 1f128 + 1f128; let _ = Saturating(0u32) + Saturating(0u32); let _ = String::new() + ""; diff --git a/tests/ui/arithmetic_side_effects.stderr b/tests/ui/arithmetic_side_effects.stderr index 8039c0bfa248..78914667bf30 100644 --- a/tests/ui/arithmetic_side_effects.stderr +++ b/tests/ui/arithmetic_side_effects.stderr @@ -1,731 +1,743 @@ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:304:5 + --> tests/ui/arithmetic_side_effects.rs:167:13 | -LL | _n += 1; - | ^^^^^^^ +LL | let _ = 1f16 + 1f16; + | ^^^^^^^^^^^ | = note: `-D clippy::arithmetic-side-effects` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]` error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:305:5 + --> tests/ui/arithmetic_side_effects.rs:170:13 + | +LL | let _ = 1f128 + 1f128; + | ^^^^^^^^^^^^^ + +error: arithmetic operation that can potentially result in unexpected side-effects + --> tests/ui/arithmetic_side_effects.rs:308:5 + | +LL | _n += 1; + | ^^^^^^^ + +error: arithmetic operation that can potentially result in unexpected side-effects + --> tests/ui/arithmetic_side_effects.rs:309:5 | LL | _n += &1; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:306:5 + --> tests/ui/arithmetic_side_effects.rs:310:5 | LL | _n -= 1; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:307:5 + --> tests/ui/arithmetic_side_effects.rs:311:5 | LL | _n -= &1; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:308:5 + --> tests/ui/arithmetic_side_effects.rs:312:5 | LL | _n /= 0; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:309:5 + --> tests/ui/arithmetic_side_effects.rs:313:5 | LL | _n /= &0; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:310:5 + --> tests/ui/arithmetic_side_effects.rs:314:5 | LL | _n %= 0; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:311:5 + --> tests/ui/arithmetic_side_effects.rs:315:5 | LL | _n %= &0; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:312:5 + --> tests/ui/arithmetic_side_effects.rs:316:5 | LL | _n *= 2; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:313:5 + --> tests/ui/arithmetic_side_effects.rs:317:5 | LL | _n *= &2; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:314:5 + --> tests/ui/arithmetic_side_effects.rs:318:5 | LL | _n += -1; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:315:5 + --> tests/ui/arithmetic_side_effects.rs:319:5 | LL | _n += &-1; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:316:5 + --> tests/ui/arithmetic_side_effects.rs:320:5 | LL | _n -= -1; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:317:5 + --> tests/ui/arithmetic_side_effects.rs:321:5 | LL | _n -= &-1; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:318:5 + --> tests/ui/arithmetic_side_effects.rs:322:5 | LL | _n /= -0; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:319:5 + --> tests/ui/arithmetic_side_effects.rs:323:5 | LL | _n /= &-0; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:320:5 + --> tests/ui/arithmetic_side_effects.rs:324:5 | LL | _n %= -0; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:321:5 + --> tests/ui/arithmetic_side_effects.rs:325:5 | LL | _n %= &-0; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:322:5 + --> tests/ui/arithmetic_side_effects.rs:326:5 | LL | _n *= -2; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:323:5 + --> tests/ui/arithmetic_side_effects.rs:327:5 | LL | _n *= &-2; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:324:5 + --> tests/ui/arithmetic_side_effects.rs:328:5 | LL | _custom += Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:325:5 + --> tests/ui/arithmetic_side_effects.rs:329:5 | LL | _custom += &Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:326:5 + --> tests/ui/arithmetic_side_effects.rs:330:5 | LL | _custom -= Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:327:5 + --> tests/ui/arithmetic_side_effects.rs:331:5 | LL | _custom -= &Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:328:5 + --> tests/ui/arithmetic_side_effects.rs:332:5 | LL | _custom /= Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:329:5 + --> tests/ui/arithmetic_side_effects.rs:333:5 | LL | _custom /= &Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:330:5 + --> tests/ui/arithmetic_side_effects.rs:334:5 | LL | _custom %= Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:331:5 + --> tests/ui/arithmetic_side_effects.rs:335:5 | LL | _custom %= &Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:332:5 + --> tests/ui/arithmetic_side_effects.rs:336:5 | LL | _custom *= Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:333:5 + --> tests/ui/arithmetic_side_effects.rs:337:5 | LL | _custom *= &Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:334:5 + --> tests/ui/arithmetic_side_effects.rs:338:5 | LL | _custom >>= Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:335:5 + --> tests/ui/arithmetic_side_effects.rs:339:5 | LL | _custom >>= &Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:336:5 + --> tests/ui/arithmetic_side_effects.rs:340:5 | LL | _custom <<= Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:337:5 + --> tests/ui/arithmetic_side_effects.rs:341:5 | LL | _custom <<= &Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:338:5 + --> tests/ui/arithmetic_side_effects.rs:342:5 | LL | _custom += -Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:339:5 + --> tests/ui/arithmetic_side_effects.rs:343:5 | LL | _custom += &-Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:340:5 + --> tests/ui/arithmetic_side_effects.rs:344:5 | LL | _custom -= -Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:341:5 + --> tests/ui/arithmetic_side_effects.rs:345:5 | LL | _custom -= &-Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:342:5 + --> tests/ui/arithmetic_side_effects.rs:346:5 | LL | _custom /= -Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:343:5 + --> tests/ui/arithmetic_side_effects.rs:347:5 | LL | _custom /= &-Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:344:5 + --> tests/ui/arithmetic_side_effects.rs:348:5 | LL | _custom %= -Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:345:5 + --> tests/ui/arithmetic_side_effects.rs:349:5 | LL | _custom %= &-Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:346:5 + --> tests/ui/arithmetic_side_effects.rs:350:5 | LL | _custom *= -Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:347:5 + --> tests/ui/arithmetic_side_effects.rs:351:5 | LL | _custom *= &-Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:348:5 + --> tests/ui/arithmetic_side_effects.rs:352:5 | LL | _custom >>= -Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:349:5 + --> tests/ui/arithmetic_side_effects.rs:353:5 | LL | _custom >>= &-Custom; | ^^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:350:5 + --> tests/ui/arithmetic_side_effects.rs:354:5 | LL | _custom <<= -Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:351:5 + --> tests/ui/arithmetic_side_effects.rs:355:5 | LL | _custom <<= &-Custom; | ^^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:354:10 + --> tests/ui/arithmetic_side_effects.rs:358:10 | LL | _n = _n + 1; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:355:10 + --> tests/ui/arithmetic_side_effects.rs:359:10 | LL | _n = _n + &1; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:356:10 + --> tests/ui/arithmetic_side_effects.rs:360:10 | LL | _n = 1 + _n; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:357:10 + --> tests/ui/arithmetic_side_effects.rs:361:10 | LL | _n = &1 + _n; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:358:10 + --> tests/ui/arithmetic_side_effects.rs:362:10 | LL | _n = _n - 1; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:359:10 + --> tests/ui/arithmetic_side_effects.rs:363:10 | LL | _n = _n - &1; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:360:10 + --> tests/ui/arithmetic_side_effects.rs:364:10 | LL | _n = 1 - _n; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:361:10 + --> tests/ui/arithmetic_side_effects.rs:365:10 | LL | _n = &1 - _n; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:362:10 + --> tests/ui/arithmetic_side_effects.rs:366:10 | LL | _n = _n / 0; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:363:10 + --> tests/ui/arithmetic_side_effects.rs:367:10 | LL | _n = _n / &0; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:364:10 + --> tests/ui/arithmetic_side_effects.rs:368:10 | LL | _n = _n % 0; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:365:10 + --> tests/ui/arithmetic_side_effects.rs:369:10 | LL | _n = _n % &0; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:366:10 + --> tests/ui/arithmetic_side_effects.rs:370:10 | LL | _n = _n * 2; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:367:10 + --> tests/ui/arithmetic_side_effects.rs:371:10 | LL | _n = _n * &2; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:368:10 + --> tests/ui/arithmetic_side_effects.rs:372:10 | LL | _n = 2 * _n; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:369:10 + --> tests/ui/arithmetic_side_effects.rs:373:10 | LL | _n = &2 * _n; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:370:10 + --> tests/ui/arithmetic_side_effects.rs:374:10 | LL | _n = 23 + &85; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:371:10 + --> tests/ui/arithmetic_side_effects.rs:375:10 | LL | _n = &23 + 85; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:372:10 + --> tests/ui/arithmetic_side_effects.rs:376:10 | LL | _n = &23 + &85; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:373:15 + --> tests/ui/arithmetic_side_effects.rs:377:15 | LL | _custom = _custom + _custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:374:15 + --> tests/ui/arithmetic_side_effects.rs:378:15 | LL | _custom = _custom + &_custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:375:15 + --> tests/ui/arithmetic_side_effects.rs:379:15 | LL | _custom = Custom + _custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:376:15 + --> tests/ui/arithmetic_side_effects.rs:380:15 | LL | _custom = &Custom + _custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:377:15 + --> tests/ui/arithmetic_side_effects.rs:381:15 | LL | _custom = _custom - Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:378:15 + --> tests/ui/arithmetic_side_effects.rs:382:15 | LL | _custom = _custom - &Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:379:15 + --> tests/ui/arithmetic_side_effects.rs:383:15 | LL | _custom = Custom - _custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:380:15 + --> tests/ui/arithmetic_side_effects.rs:384:15 | LL | _custom = &Custom - _custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:381:15 + --> tests/ui/arithmetic_side_effects.rs:385:15 | LL | _custom = _custom / Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:382:15 + --> tests/ui/arithmetic_side_effects.rs:386:15 | LL | _custom = _custom / &Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:383:15 + --> tests/ui/arithmetic_side_effects.rs:387:15 | LL | _custom = _custom % Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:384:15 + --> tests/ui/arithmetic_side_effects.rs:388:15 | LL | _custom = _custom % &Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:385:15 + --> tests/ui/arithmetic_side_effects.rs:389:15 | LL | _custom = _custom * Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:386:15 + --> tests/ui/arithmetic_side_effects.rs:390:15 | LL | _custom = _custom * &Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:387:15 + --> tests/ui/arithmetic_side_effects.rs:391:15 | LL | _custom = Custom * _custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:388:15 + --> tests/ui/arithmetic_side_effects.rs:392:15 | LL | _custom = &Custom * _custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:389:15 + --> tests/ui/arithmetic_side_effects.rs:393:15 | LL | _custom = Custom + &Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:390:15 + --> tests/ui/arithmetic_side_effects.rs:394:15 | LL | _custom = &Custom + Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:391:15 + --> tests/ui/arithmetic_side_effects.rs:395:15 | LL | _custom = &Custom + &Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:392:15 + --> tests/ui/arithmetic_side_effects.rs:396:15 | LL | _custom = _custom >> _custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:393:15 + --> tests/ui/arithmetic_side_effects.rs:397:15 | LL | _custom = _custom >> &_custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:394:15 + --> tests/ui/arithmetic_side_effects.rs:398:15 | LL | _custom = Custom << _custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:395:15 + --> tests/ui/arithmetic_side_effects.rs:399:15 | LL | _custom = &Custom << _custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:398:23 + --> tests/ui/arithmetic_side_effects.rs:402:23 | LL | _n.saturating_div(0); | ^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:399:21 + --> tests/ui/arithmetic_side_effects.rs:403:21 | LL | _n.wrapping_div(0); | ^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:400:21 + --> tests/ui/arithmetic_side_effects.rs:404:21 | LL | _n.wrapping_rem(0); | ^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:401:28 + --> tests/ui/arithmetic_side_effects.rs:405:28 | LL | _n.wrapping_rem_euclid(0); | ^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:403:23 + --> tests/ui/arithmetic_side_effects.rs:407:23 | LL | _n.saturating_div(_n); | ^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:404:21 + --> tests/ui/arithmetic_side_effects.rs:408:21 | LL | _n.wrapping_div(_n); | ^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:405:21 + --> tests/ui/arithmetic_side_effects.rs:409:21 | LL | _n.wrapping_rem(_n); | ^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:406:28 + --> tests/ui/arithmetic_side_effects.rs:410:28 | LL | _n.wrapping_rem_euclid(_n); | ^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:409:10 + --> tests/ui/arithmetic_side_effects.rs:413:10 | LL | _n = -_n; | ^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:410:10 + --> tests/ui/arithmetic_side_effects.rs:414:10 | LL | _n = -&_n; | ^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:411:15 + --> tests/ui/arithmetic_side_effects.rs:415:15 | LL | _custom = -_custom; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:412:15 + --> tests/ui/arithmetic_side_effects.rs:416:15 | LL | _custom = -&_custom; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:421:5 + --> tests/ui/arithmetic_side_effects.rs:425:5 | LL | 1 + i; | ^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:422:5 + --> tests/ui/arithmetic_side_effects.rs:426:5 | LL | i * 2; | ^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:423:5 + --> tests/ui/arithmetic_side_effects.rs:427:5 | LL | 1 % i / 2; | ^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:424:5 + --> tests/ui/arithmetic_side_effects.rs:428:5 | LL | i - 2 + 2 - i; | ^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:425:5 + --> tests/ui/arithmetic_side_effects.rs:429:5 | LL | -i; | ^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:436:5 + --> tests/ui/arithmetic_side_effects.rs:440:5 | LL | i += 1; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:437:5 + --> tests/ui/arithmetic_side_effects.rs:441:5 | LL | i -= 1; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:438:5 + --> tests/ui/arithmetic_side_effects.rs:442:5 | LL | i *= 2; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:440:5 + --> tests/ui/arithmetic_side_effects.rs:444:5 | LL | i /= 0; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:442:5 + --> tests/ui/arithmetic_side_effects.rs:446:5 | LL | i /= var1; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:443:5 + --> tests/ui/arithmetic_side_effects.rs:447:5 | LL | i /= var2; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:445:5 + --> tests/ui/arithmetic_side_effects.rs:449:5 | LL | i %= 0; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:447:5 + --> tests/ui/arithmetic_side_effects.rs:451:5 | LL | i %= var1; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:448:5 + --> tests/ui/arithmetic_side_effects.rs:452:5 | LL | i %= var2; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:458:5 + --> tests/ui/arithmetic_side_effects.rs:462:5 | LL | 10 / a | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:512:9 + --> tests/ui/arithmetic_side_effects.rs:516:9 | LL | x / maybe_zero | ^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:516:9 + --> tests/ui/arithmetic_side_effects.rs:520:9 | LL | x % maybe_zero | ^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:527:5 + --> tests/ui/arithmetic_side_effects.rs:531:5 | LL | one.add_assign(1); | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:531:5 + --> tests/ui/arithmetic_side_effects.rs:535:5 | LL | one.sub_assign(1); | ^^^^^^^^^^^^^^^^^ -error: aborting due to 121 previous errors +error: aborting due to 123 previous errors diff --git a/tests/ui/cast.rs b/tests/ui/cast.rs index 453d62ce6075..c39f65a43e39 100644 --- a/tests/ui/cast.rs +++ b/tests/ui/cast.rs @@ -17,6 +17,8 @@ clippy::identity_op )] +// FIXME(f16_f128): add tests once const casting is available for these types + fn main() { // Test clippy::cast_precision_loss let x0 = 1i32; diff --git a/tests/ui/cast.stderr b/tests/ui/cast.stderr index 43c0d8f4ed73..452482fc88e2 100644 --- a/tests/ui/cast.stderr +++ b/tests/ui/cast.stderr @@ -1,5 +1,5 @@ error: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> tests/ui/cast.rs:23:5 + --> tests/ui/cast.rs:25:5 | LL | x0 as f32; | ^^^^^^^^^ @@ -8,37 +8,37 @@ LL | x0 as f32; = help: to override `-D warnings` add `#[allow(clippy::cast_precision_loss)]` error: casting `i64` to `f32` causes a loss of precision (`i64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> tests/ui/cast.rs:27:5 + --> tests/ui/cast.rs:29:5 | LL | x1 as f32; | ^^^^^^^^^ error: casting `i64` to `f64` causes a loss of precision (`i64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> tests/ui/cast.rs:29:5 + --> tests/ui/cast.rs:31:5 | LL | x1 as f64; | ^^^^^^^^^ error: casting `u32` to `f32` causes a loss of precision (`u32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> tests/ui/cast.rs:32:5 + --> tests/ui/cast.rs:34:5 | LL | x2 as f32; | ^^^^^^^^^ error: casting `u64` to `f32` causes a loss of precision (`u64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> tests/ui/cast.rs:35:5 + --> tests/ui/cast.rs:37:5 | LL | x3 as f32; | ^^^^^^^^^ error: casting `u64` to `f64` causes a loss of precision (`u64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> tests/ui/cast.rs:37:5 + --> tests/ui/cast.rs:39:5 | LL | x3 as f64; | ^^^^^^^^^ error: casting `f32` to `i32` may truncate the value - --> tests/ui/cast.rs:40:5 + --> tests/ui/cast.rs:42:5 | LL | 1f32 as i32; | ^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | 1f32 as i32; = help: to override `-D warnings` add `#[allow(clippy::cast_possible_truncation)]` error: casting `f32` to `u32` may truncate the value - --> tests/ui/cast.rs:42:5 + --> tests/ui/cast.rs:44:5 | LL | 1f32 as u32; | ^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | 1f32 as u32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:42:5 + --> tests/ui/cast.rs:44:5 | LL | 1f32 as u32; | ^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | 1f32 as u32; = help: to override `-D warnings` add `#[allow(clippy::cast_sign_loss)]` error: casting `f64` to `f32` may truncate the value - --> tests/ui/cast.rs:46:5 + --> tests/ui/cast.rs:48:5 | LL | 1f64 as f32; | ^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | 1f64 as f32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `i32` to `i8` may truncate the value - --> tests/ui/cast.rs:48:5 + --> tests/ui/cast.rs:50:5 | LL | 1i32 as i8; | ^^^^^^^^^^ @@ -85,7 +85,7 @@ LL | i8::try_from(1i32); | ~~~~~~~~~~~~~~~~~~ error: casting `i32` to `u8` may truncate the value - --> tests/ui/cast.rs:50:5 + --> tests/ui/cast.rs:52:5 | LL | 1i32 as u8; | ^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | u8::try_from(1i32); | ~~~~~~~~~~~~~~~~~~ error: casting `f64` to `isize` may truncate the value - --> tests/ui/cast.rs:52:5 + --> tests/ui/cast.rs:54:5 | LL | 1f64 as isize; | ^^^^^^^^^^^^^ @@ -105,7 +105,7 @@ LL | 1f64 as isize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f64` to `usize` may truncate the value - --> tests/ui/cast.rs:54:5 + --> tests/ui/cast.rs:56:5 | LL | 1f64 as usize; | ^^^^^^^^^^^^^ @@ -113,13 +113,13 @@ LL | 1f64 as usize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f64` to `usize` may lose the sign of the value - --> tests/ui/cast.rs:54:5 + --> tests/ui/cast.rs:56:5 | LL | 1f64 as usize; | ^^^^^^^^^^^^^ error: casting `u32` to `u16` may truncate the value - --> tests/ui/cast.rs:57:5 + --> tests/ui/cast.rs:59:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^^^^^^^^ @@ -131,7 +131,7 @@ LL | u16::try_from(1f32 as u32); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `f32` to `u32` may truncate the value - --> tests/ui/cast.rs:57:5 + --> tests/ui/cast.rs:59:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^ @@ -139,13 +139,13 @@ LL | 1f32 as u32 as u16; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:57:5 + --> tests/ui/cast.rs:59:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^ error: casting `i32` to `i8` may truncate the value - --> tests/ui/cast.rs:62:22 + --> tests/ui/cast.rs:64:22 | LL | let _x: i8 = 1i32 as _; | ^^^^^^^^^ @@ -157,7 +157,7 @@ LL | let _x: i8 = 1i32.try_into(); | ~~~~~~~~~~~~~~~ error: casting `f32` to `i32` may truncate the value - --> tests/ui/cast.rs:64:9 + --> tests/ui/cast.rs:66:9 | LL | 1f32 as i32; | ^^^^^^^^^^^ @@ -165,7 +165,7 @@ LL | 1f32 as i32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f64` to `i32` may truncate the value - --> tests/ui/cast.rs:66:9 + --> tests/ui/cast.rs:68:9 | LL | 1f64 as i32; | ^^^^^^^^^^^ @@ -173,7 +173,7 @@ LL | 1f64 as i32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u8` may truncate the value - --> tests/ui/cast.rs:68:9 + --> tests/ui/cast.rs:70:9 | LL | 1f32 as u8; | ^^^^^^^^^^ @@ -181,13 +181,13 @@ LL | 1f32 as u8; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u8` may lose the sign of the value - --> tests/ui/cast.rs:68:9 + --> tests/ui/cast.rs:70:9 | LL | 1f32 as u8; | ^^^^^^^^^^ error: casting `u8` to `i8` may wrap around the value - --> tests/ui/cast.rs:73:5 + --> tests/ui/cast.rs:75:5 | LL | 1u8 as i8; | ^^^^^^^^^ @@ -196,31 +196,31 @@ LL | 1u8 as i8; = help: to override `-D warnings` add `#[allow(clippy::cast_possible_wrap)]` error: casting `u16` to `i16` may wrap around the value - --> tests/ui/cast.rs:76:5 + --> tests/ui/cast.rs:78:5 | LL | 1u16 as i16; | ^^^^^^^^^^^ error: casting `u32` to `i32` may wrap around the value - --> tests/ui/cast.rs:78:5 + --> tests/ui/cast.rs:80:5 | LL | 1u32 as i32; | ^^^^^^^^^^^ error: casting `u64` to `i64` may wrap around the value - --> tests/ui/cast.rs:80:5 + --> tests/ui/cast.rs:82:5 | LL | 1u64 as i64; | ^^^^^^^^^^^ error: casting `usize` to `isize` may wrap around the value - --> tests/ui/cast.rs:82:5 + --> tests/ui/cast.rs:84:5 | LL | 1usize as isize; | ^^^^^^^^^^^^^^^ error: casting `usize` to `i8` may truncate the value - --> tests/ui/cast.rs:85:5 + --> tests/ui/cast.rs:87:5 | LL | 1usize as i8; | ^^^^^^^^^^^^ @@ -232,7 +232,7 @@ LL | i8::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may truncate the value - --> tests/ui/cast.rs:88:5 + --> tests/ui/cast.rs:90:5 | LL | 1usize as i16; | ^^^^^^^^^^^^^ @@ -244,7 +244,7 @@ LL | i16::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may wrap around the value on targets with 16-bit wide pointers - --> tests/ui/cast.rs:88:5 + --> tests/ui/cast.rs:90:5 | LL | 1usize as i16; | ^^^^^^^^^^^^^ @@ -253,7 +253,7 @@ LL | 1usize as i16; = note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast.rs:93:5 + --> tests/ui/cast.rs:95:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -265,19 +265,19 @@ LL | i32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> tests/ui/cast.rs:93:5 + --> tests/ui/cast.rs:95:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ error: casting `usize` to `i64` may wrap around the value on targets with 64-bit wide pointers - --> tests/ui/cast.rs:97:5 + --> tests/ui/cast.rs:99:5 | LL | 1usize as i64; | ^^^^^^^^^^^^^ error: casting `u16` to `isize` may wrap around the value on targets with 16-bit wide pointers - --> tests/ui/cast.rs:102:5 + --> tests/ui/cast.rs:104:5 | LL | 1u16 as isize; | ^^^^^^^^^^^^^ @@ -286,13 +286,13 @@ LL | 1u16 as isize; = note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers - --> tests/ui/cast.rs:106:5 + --> tests/ui/cast.rs:108:5 | LL | 1u32 as isize; | ^^^^^^^^^^^^^ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast.rs:109:5 + --> tests/ui/cast.rs:111:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ @@ -304,55 +304,55 @@ LL | isize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> tests/ui/cast.rs:109:5 + --> tests/ui/cast.rs:111:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:114:5 + --> tests/ui/cast.rs:116:5 | LL | -1i32 as u32; | ^^^^^^^^^^^^ error: casting `isize` to `usize` may lose the sign of the value - --> tests/ui/cast.rs:117:5 + --> tests/ui/cast.rs:119:5 | LL | -1isize as usize; | ^^^^^^^^^^^^^^^^ error: casting `i8` to `u8` may lose the sign of the value - --> tests/ui/cast.rs:128:5 + --> tests/ui/cast.rs:130:5 | LL | (i8::MIN).abs() as u8; | ^^^^^^^^^^^^^^^^^^^^^ error: casting `i64` to `u64` may lose the sign of the value - --> tests/ui/cast.rs:132:5 + --> tests/ui/cast.rs:134:5 | LL | (-1i64).abs() as u64; | ^^^^^^^^^^^^^^^^^^^^ error: casting `isize` to `usize` may lose the sign of the value - --> tests/ui/cast.rs:133:5 + --> tests/ui/cast.rs:135:5 | LL | (-1isize).abs() as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i64` to `u64` may lose the sign of the value - --> tests/ui/cast.rs:140:5 + --> tests/ui/cast.rs:142:5 | LL | (unsafe { (-1i64).checked_abs().unwrap_unchecked() }) as u64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i64` to `u64` may lose the sign of the value - --> tests/ui/cast.rs:155:5 + --> tests/ui/cast.rs:157:5 | LL | (unsafe { (-1i64).checked_isqrt().unwrap_unchecked() }) as u64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i64` to `i8` may truncate the value - --> tests/ui/cast.rs:206:5 + --> tests/ui/cast.rs:208:5 | LL | (-99999999999i64).min(1) as i8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -364,7 +364,7 @@ LL | i8::try_from((-99999999999i64).min(1)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `u8` may truncate the value - --> tests/ui/cast.rs:220:5 + --> tests/ui/cast.rs:222:5 | LL | 999999u64.clamp(0, 256) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -376,7 +376,7 @@ LL | u8::try_from(999999u64.clamp(0, 256)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E2` to `u8` may truncate the value - --> tests/ui/cast.rs:243:21 + --> tests/ui/cast.rs:245:21 | LL | let _ = self as u8; | ^^^^^^^^^^ @@ -388,7 +388,7 @@ LL | let _ = u8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E2::B` to `u8` will truncate the value - --> tests/ui/cast.rs:245:21 + --> tests/ui/cast.rs:247:21 | LL | let _ = Self::B as u8; | ^^^^^^^^^^^^^ @@ -397,7 +397,7 @@ LL | let _ = Self::B as u8; = help: to override `-D warnings` add `#[allow(clippy::cast_enum_truncation)]` error: casting `main::E5` to `i8` may truncate the value - --> tests/ui/cast.rs:287:21 + --> tests/ui/cast.rs:289:21 | LL | let _ = self as i8; | ^^^^^^^^^^ @@ -409,13 +409,13 @@ LL | let _ = i8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E5::A` to `i8` will truncate the value - --> tests/ui/cast.rs:289:21 + --> tests/ui/cast.rs:291:21 | LL | let _ = Self::A as i8; | ^^^^^^^^^^^^^ error: casting `main::E6` to `i16` may truncate the value - --> tests/ui/cast.rs:306:21 + --> tests/ui/cast.rs:308:21 | LL | let _ = self as i16; | ^^^^^^^^^^^ @@ -427,7 +427,7 @@ LL | let _ = i16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast.rs:325:21 + --> tests/ui/cast.rs:327:21 | LL | let _ = self as usize; | ^^^^^^^^^^^^^ @@ -439,7 +439,7 @@ LL | let _ = usize::try_from(self); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E10` to `u16` may truncate the value - --> tests/ui/cast.rs:372:21 + --> tests/ui/cast.rs:374:21 | LL | let _ = self as u16; | ^^^^^^^^^^^ @@ -451,7 +451,7 @@ LL | let _ = u16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> tests/ui/cast.rs:383:13 + --> tests/ui/cast.rs:385:13 | LL | let c = (q >> 16) as u8; | ^^^^^^^^^^^^^^^ @@ -463,7 +463,7 @@ LL | let c = u8::try_from(q >> 16); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> tests/ui/cast.rs:387:13 + --> tests/ui/cast.rs:389:13 | LL | let c = (q / 1000) as u8; | ^^^^^^^^^^^^^^^^ @@ -475,85 +475,85 @@ LL | let c = u8::try_from(q / 1000); | ~~~~~~~~~~~~~~~~~~~~~~ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:399:9 + --> tests/ui/cast.rs:401:9 | LL | (x * x) as u32; | ^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:404:32 + --> tests/ui/cast.rs:406:32 | LL | let _a = |x: i32| -> u32 { (x * x * x * x) as u32 }; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:406:5 + --> tests/ui/cast.rs:408:5 | LL | (2_i32).checked_pow(3).unwrap() as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:407:5 + --> tests/ui/cast.rs:409:5 | LL | (-2_i32).pow(3) as u32; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:412:5 + --> tests/ui/cast.rs:414:5 | LL | (-5_i32 % 2) as u32; | ^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:414:5 + --> tests/ui/cast.rs:416:5 | LL | (-5_i32 % -2) as u32; | ^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:417:5 + --> tests/ui/cast.rs:419:5 | LL | (-2_i32 >> 1) as u32; | ^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:421:5 + --> tests/ui/cast.rs:423:5 | LL | (x * x) as u32; | ^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:422:5 + --> tests/ui/cast.rs:424:5 | LL | (x * x * x) as u32; | ^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:426:5 + --> tests/ui/cast.rs:428:5 | LL | (y * y * y * y * -2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:428:5 + --> tests/ui/cast.rs:430:5 | LL | (y * y * y / y * 2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:429:5 + --> tests/ui/cast.rs:431:5 | LL | (y * y / y * 2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:431:5 + --> tests/ui/cast.rs:433:5 | LL | (y / y * y * -2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `/` - --> tests/ui/cast.rs:431:6 + --> tests/ui/cast.rs:433:6 | LL | (y / y * y * -2) as u16; | ^^^^^ @@ -561,97 +561,97 @@ LL | (y / y * y * -2) as u16; = note: `#[deny(clippy::eq_op)]` on by default error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:434:5 + --> tests/ui/cast.rs:436:5 | LL | (y + y + y + -2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:436:5 + --> tests/ui/cast.rs:438:5 | LL | (y + y + y + 2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:440:5 + --> tests/ui/cast.rs:442:5 | LL | (z + -2) as u16; | ^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:442:5 + --> tests/ui/cast.rs:444:5 | LL | (z + z + 2) as u16; | ^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:445:9 + --> tests/ui/cast.rs:447:9 | LL | (a * a * b * b * c * c) as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:446:9 + --> tests/ui/cast.rs:448:9 | LL | (a * b * c) as u32; | ^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:448:9 + --> tests/ui/cast.rs:450:9 | LL | (a * -b * c) as u32; | ^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:450:9 + --> tests/ui/cast.rs:452:9 | LL | (a * b * c * c) as u32; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:451:9 + --> tests/ui/cast.rs:453:9 | LL | (a * -2) as u32; | ^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:453:9 + --> tests/ui/cast.rs:455:9 | LL | (a * b * c * -2) as u32; | ^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:455:9 + --> tests/ui/cast.rs:457:9 | LL | (a / b) as u32; | ^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:456:9 + --> tests/ui/cast.rs:458:9 | LL | (a / b * c) as u32; | ^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:458:9 + --> tests/ui/cast.rs:460:9 | LL | (a / b + b * c) as u32; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:460:9 + --> tests/ui/cast.rs:462:9 | LL | a.saturating_pow(3) as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:462:9 + --> tests/ui/cast.rs:464:9 | LL | (a.abs() * b.pow(2) / c.abs()) as u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:470:21 + --> tests/ui/cast.rs:472:21 | LL | let _ = i32::MIN as u32; // cast_sign_loss | ^^^^^^^^^^^^^^^ @@ -662,7 +662,7 @@ LL | m!(); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: casting `u32` to `u8` may truncate the value - --> tests/ui/cast.rs:471:21 + --> tests/ui/cast.rs:473:21 | LL | let _ = u32::MAX as u8; // cast_possible_truncation | ^^^^^^^^^^^^^^ @@ -678,7 +678,7 @@ LL | let _ = u8::try_from(u32::MAX); // cast_possible_truncation | ~~~~~~~~~~~~~~~~~~~~~~ error: casting `f64` to `f32` may truncate the value - --> tests/ui/cast.rs:472:21 + --> tests/ui/cast.rs:474:21 | LL | let _ = std::f64::consts::PI as f32; // cast_possible_truncation | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -690,7 +690,7 @@ LL | m!(); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast.rs:481:5 + --> tests/ui/cast.rs:483:5 | LL | bar.unwrap().unwrap() as usize | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -702,13 +702,13 @@ LL | usize::try_from(bar.unwrap().unwrap()) | error: casting `i64` to `usize` may lose the sign of the value - --> tests/ui/cast.rs:481:5 + --> tests/ui/cast.rs:483:5 | LL | bar.unwrap().unwrap() as usize | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `u64` to `u8` may truncate the value - --> tests/ui/cast.rs:496:5 + --> tests/ui/cast.rs:498:5 | LL | (256 & 999999u64) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -720,7 +720,7 @@ LL | u8::try_from(256 & 999999u64); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `u8` may truncate the value - --> tests/ui/cast.rs:498:5 + --> tests/ui/cast.rs:500:5 | LL | (255 % 999999u64) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_lossless_float.fixed b/tests/ui/cast_lossless_float.fixed index 96a67b1945ca..163432631e13 100644 --- a/tests/ui/cast_lossless_float.fixed +++ b/tests/ui/cast_lossless_float.fixed @@ -1,6 +1,8 @@ #![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)] #![warn(clippy::cast_lossless)] +// FIXME(f16_f128): add tests for these types once const casting is available + type F32 = f32; type F64 = f64; diff --git a/tests/ui/cast_lossless_float.rs b/tests/ui/cast_lossless_float.rs index d37b2c1d920e..afb2a3d890ee 100644 --- a/tests/ui/cast_lossless_float.rs +++ b/tests/ui/cast_lossless_float.rs @@ -1,6 +1,8 @@ #![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)] #![warn(clippy::cast_lossless)] +// FIXME(f16_f128): add tests for these types once const casting is available + type F32 = f32; type F64 = f64; diff --git a/tests/ui/cast_lossless_float.stderr b/tests/ui/cast_lossless_float.stderr index ad7de760adfb..f2ba4e3b9903 100644 --- a/tests/ui/cast_lossless_float.stderr +++ b/tests/ui/cast_lossless_float.stderr @@ -1,5 +1,5 @@ error: casting `i8` to `f32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:10:13 + --> tests/ui/cast_lossless_float.rs:12:13 | LL | let _ = x0 as f32; | ^^^^^^^^^ help: try: `f32::from(x0)` @@ -8,73 +8,73 @@ LL | let _ = x0 as f32; = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` error: casting `i8` to `f64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:11:13 + --> tests/ui/cast_lossless_float.rs:13:13 | LL | let _ = x0 as f64; | ^^^^^^^^^ help: try: `f64::from(x0)` error: casting `i8` to `F32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:12:13 + --> tests/ui/cast_lossless_float.rs:14:13 | LL | let _ = x0 as F32; | ^^^^^^^^^ help: try: `F32::from(x0)` error: casting `i8` to `F64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:13:13 + --> tests/ui/cast_lossless_float.rs:15:13 | LL | let _ = x0 as F64; | ^^^^^^^^^ help: try: `F64::from(x0)` error: casting `u8` to `f32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:15:13 + --> tests/ui/cast_lossless_float.rs:17:13 | LL | let _ = x1 as f32; | ^^^^^^^^^ help: try: `f32::from(x1)` error: casting `u8` to `f64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:16:13 + --> tests/ui/cast_lossless_float.rs:18:13 | LL | let _ = x1 as f64; | ^^^^^^^^^ help: try: `f64::from(x1)` error: casting `i16` to `f32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:18:13 + --> tests/ui/cast_lossless_float.rs:20:13 | LL | let _ = x2 as f32; | ^^^^^^^^^ help: try: `f32::from(x2)` error: casting `i16` to `f64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:19:13 + --> tests/ui/cast_lossless_float.rs:21:13 | LL | let _ = x2 as f64; | ^^^^^^^^^ help: try: `f64::from(x2)` error: casting `u16` to `f32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:21:13 + --> tests/ui/cast_lossless_float.rs:23:13 | LL | let _ = x3 as f32; | ^^^^^^^^^ help: try: `f32::from(x3)` error: casting `u16` to `f64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:22:13 + --> tests/ui/cast_lossless_float.rs:24:13 | LL | let _ = x3 as f64; | ^^^^^^^^^ help: try: `f64::from(x3)` error: casting `i32` to `f64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:24:13 + --> tests/ui/cast_lossless_float.rs:26:13 | LL | let _ = x4 as f64; | ^^^^^^^^^ help: try: `f64::from(x4)` error: casting `u32` to `f64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:26:13 + --> tests/ui/cast_lossless_float.rs:28:13 | LL | let _ = x5 as f64; | ^^^^^^^^^ help: try: `f64::from(x5)` error: casting `f32` to `f64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:29:13 + --> tests/ui/cast_lossless_float.rs:31:13 | LL | let _ = 1.0f32 as f64; | ^^^^^^^^^^^^^ help: try: `f64::from(1.0f32)` diff --git a/tests/ui/cast_nan_to_int.rs b/tests/ui/cast_nan_to_int.rs index 2d7467ff0400..aee38da9a159 100644 --- a/tests/ui/cast_nan_to_int.rs +++ b/tests/ui/cast_nan_to_int.rs @@ -1,3 +1,5 @@ +// FIXME(f16_f128): add tests when constants are available + #![warn(clippy::cast_nan_to_int)] #![allow(clippy::eq_op)] diff --git a/tests/ui/cast_nan_to_int.stderr b/tests/ui/cast_nan_to_int.stderr index 3cb46d1e79bb..3aeb2d545251 100644 --- a/tests/ui/cast_nan_to_int.stderr +++ b/tests/ui/cast_nan_to_int.stderr @@ -1,5 +1,5 @@ error: casting a known NaN to usize - --> tests/ui/cast_nan_to_int.rs:5:13 + --> tests/ui/cast_nan_to_int.rs:7:13 | LL | let _ = (0.0_f32 / -0.0) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | let _ = (0.0_f32 / -0.0) as usize; = help: to override `-D warnings` add `#[allow(clippy::cast_nan_to_int)]` error: casting a known NaN to usize - --> tests/ui/cast_nan_to_int.rs:8:13 + --> tests/ui/cast_nan_to_int.rs:10:13 | LL | let _ = (f64::INFINITY * -0.0) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let _ = (f64::INFINITY * -0.0) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> tests/ui/cast_nan_to_int.rs:11:13 + --> tests/ui/cast_nan_to_int.rs:13:13 | LL | let _ = (0.0 * f32::INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = (0.0 * f32::INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> tests/ui/cast_nan_to_int.rs:15:13 + --> tests/ui/cast_nan_to_int.rs:17:13 | LL | let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> tests/ui/cast_nan_to_int.rs:18:13 + --> tests/ui/cast_nan_to_int.rs:20:13 | LL | let _ = (f32::INFINITY - f32::INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | let _ = (f32::INFINITY - f32::INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> tests/ui/cast_nan_to_int.rs:21:13 + --> tests/ui/cast_nan_to_int.rs:23:13 | LL | let _ = (f32::INFINITY / f32::NEG_INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_size.64bit.stderr b/tests/ui/cast_size.64bit.stderr index 0dc4ca91529c..bc37107d80e3 100644 --- a/tests/ui/cast_size.64bit.stderr +++ b/tests/ui/cast_size.64bit.stderr @@ -12,35 +12,35 @@ help: ... or use `try_from` and handle the error accordingly LL | i8::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~ -error: casting `isize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`isize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> tests/ui/cast_size.rs:18:5 +error: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) + --> tests/ui/cast_size.rs:21:5 | -LL | x0 as f64; +LL | x0 as f32; | ^^^^^^^^^ | = note: `-D clippy::cast-precision-loss` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::cast_precision_loss)]` -error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> tests/ui/cast_size.rs:19:5 +error: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) + --> tests/ui/cast_size.rs:22:5 | -LL | x1 as f64; +LL | x1 as f32; | ^^^^^^^^^ -error: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> tests/ui/cast_size.rs:20:5 +error: casting `isize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`isize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) + --> tests/ui/cast_size.rs:23:5 | -LL | x0 as f32; +LL | x0 as f64; | ^^^^^^^^^ -error: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> tests/ui/cast_size.rs:21:5 +error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) + --> tests/ui/cast_size.rs:24:5 | -LL | x1 as f32; +LL | x1 as f64; | ^^^^^^^^^ error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:22:5 + --> tests/ui/cast_size.rs:28:5 | LL | 1isize as i32; | ^^^^^^^^^^^^^ @@ -52,7 +52,7 @@ LL | i32::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:23:5 + --> tests/ui/cast_size.rs:29:5 | LL | 1isize as u32; | ^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | u32::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:24:5 + --> tests/ui/cast_size.rs:30:5 | LL | 1usize as u32; | ^^^^^^^^^^^^^ @@ -76,7 +76,7 @@ LL | u32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:25:5 + --> tests/ui/cast_size.rs:31:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | i32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:25:5 + --> tests/ui/cast_size.rs:31:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | 1usize as i32; = help: to override `-D warnings` add `#[allow(clippy::cast_possible_wrap)]` error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:26:5 + --> tests/ui/cast_size.rs:32:5 | LL | 1i64 as isize; | ^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL | isize::try_from(1i64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:27:5 + --> tests/ui/cast_size.rs:33:5 | LL | 1i64 as usize; | ^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | usize::try_from(1i64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:28:5 + --> tests/ui/cast_size.rs:34:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ @@ -133,13 +133,13 @@ LL | isize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:28:5 + --> tests/ui/cast_size.rs:34:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:29:5 + --> tests/ui/cast_size.rs:35:5 | LL | 1u64 as usize; | ^^^^^^^^^^^^^ @@ -151,19 +151,19 @@ LL | usize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:30:5 + --> tests/ui/cast_size.rs:36:5 | LL | 1u32 as isize; | ^^^^^^^^^^^^^ error: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> tests/ui/cast_size.rs:35:5 + --> tests/ui/cast_size.rs:43:5 | LL | 999_999_999 as f32; | ^^^^^^^^^^^^^^^^^^ error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> tests/ui/cast_size.rs:36:5 + --> tests/ui/cast_size.rs:44:5 | LL | 9_999_999_999_999_999usize as f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_size.rs b/tests/ui/cast_size.rs index d063a70ccdfc..d0ed8e57d7ae 100644 --- a/tests/ui/cast_size.rs +++ b/tests/ui/cast_size.rs @@ -15,10 +15,16 @@ fn main() { 1isize as i8; let x0 = 1isize; let x1 = 1usize; - x0 as f64; - x1 as f64; + // FIXME(f16_f128): enable f16 and f128 conversions once const eval supports them + // x0 as f16; + // x1 as f16; x0 as f32; x1 as f32; + x0 as f64; + x1 as f64; + // x0 as f128; + // x1 as f128; + 1isize as i32; 1isize as u32; 1usize as u32; @@ -31,7 +37,10 @@ fn main() { 1u32 as usize; // Should not trigger any lint 1i32 as isize; // Neither should this 1i32 as usize; + // Big integer literal to float + // 999_999 as f16; 999_999_999 as f32; 9_999_999_999_999_999usize as f64; + // 999_999_999_999_999_999_999_999_999_999u128 as f128; } diff --git a/tests/ui/endian_bytes.rs b/tests/ui/endian_bytes.rs index 6bf014fc8095..580fc2fc24d7 100644 --- a/tests/ui/endian_bytes.rs +++ b/tests/ui/endian_bytes.rs @@ -2,6 +2,8 @@ #![allow(clippy::diverging_sub_expression)] #![no_main] +// FIXME(f16_f128): add these types when `{to_from}_*_bytes` are available + macro_rules! fn_body { () => { 2u8.to_ne_bytes(); diff --git a/tests/ui/endian_bytes.stderr b/tests/ui/endian_bytes.stderr index 3fc26dcab886..fd19ec45872b 100644 --- a/tests/ui/endian_bytes.stderr +++ b/tests/ui/endian_bytes.stderr @@ -1,5 +1,5 @@ error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:7:9 + --> tests/ui/endian_bytes.rs:9:9 | LL | 2u8.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:8:9 + --> tests/ui/endian_bytes.rs:10:9 | LL | 2i8.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u16::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:9:9 + --> tests/ui/endian_bytes.rs:11:9 | LL | 2u16.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i16::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:10:9 + --> tests/ui/endian_bytes.rs:12:9 | LL | 2i16.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u32::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:11:9 + --> tests/ui/endian_bytes.rs:13:9 | LL | 2u32.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i32::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:12:9 + --> tests/ui/endian_bytes.rs:14:9 | LL | 2i32.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u64::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:13:9 + --> tests/ui/endian_bytes.rs:15:9 | LL | 2u64.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i64::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:14:9 + --> tests/ui/endian_bytes.rs:16:9 | LL | 2i64.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u128::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:15:9 + --> tests/ui/endian_bytes.rs:17:9 | LL | 2u128.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i128::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:16:9 + --> tests/ui/endian_bytes.rs:18:9 | LL | 2i128.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `f32::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:17:9 + --> tests/ui/endian_bytes.rs:19:9 | LL | 2.0f32.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `f64::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:18:9 + --> tests/ui/endian_bytes.rs:20:9 | LL | 2.0f64.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `usize::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:19:9 + --> tests/ui/endian_bytes.rs:21:9 | LL | 2usize.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `isize::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:20:9 + --> tests/ui/endian_bytes.rs:22:9 | LL | 2isize.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:21:9 + --> tests/ui/endian_bytes.rs:23:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:22:9 + --> tests/ui/endian_bytes.rs:24:9 | LL | i8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u16::from_ne_bytes` - --> tests/ui/endian_bytes.rs:23:9 + --> tests/ui/endian_bytes.rs:25:9 | LL | u16::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -205,7 +205,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i16::from_ne_bytes` - --> tests/ui/endian_bytes.rs:24:9 + --> tests/ui/endian_bytes.rs:26:9 | LL | i16::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u32::from_ne_bytes` - --> tests/ui/endian_bytes.rs:25:9 + --> tests/ui/endian_bytes.rs:27:9 | LL | u32::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -229,7 +229,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i32::from_ne_bytes` - --> tests/ui/endian_bytes.rs:26:9 + --> tests/ui/endian_bytes.rs:28:9 | LL | i32::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,7 +241,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u64::from_ne_bytes` - --> tests/ui/endian_bytes.rs:27:9 + --> tests/ui/endian_bytes.rs:29:9 | LL | u64::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -253,7 +253,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i64::from_ne_bytes` - --> tests/ui/endian_bytes.rs:28:9 + --> tests/ui/endian_bytes.rs:30:9 | LL | i64::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -265,7 +265,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u128::from_ne_bytes` - --> tests/ui/endian_bytes.rs:29:9 + --> tests/ui/endian_bytes.rs:31:9 | LL | u128::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -277,7 +277,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i128::from_ne_bytes` - --> tests/ui/endian_bytes.rs:30:9 + --> tests/ui/endian_bytes.rs:32:9 | LL | i128::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -289,7 +289,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `usize::from_ne_bytes` - --> tests/ui/endian_bytes.rs:31:9 + --> tests/ui/endian_bytes.rs:33:9 | LL | usize::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -301,7 +301,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `isize::from_ne_bytes` - --> tests/ui/endian_bytes.rs:32:9 + --> tests/ui/endian_bytes.rs:34:9 | LL | isize::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -313,7 +313,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `f32::from_ne_bytes` - --> tests/ui/endian_bytes.rs:33:9 + --> tests/ui/endian_bytes.rs:35:9 | LL | f32::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -325,7 +325,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `f64::from_ne_bytes` - --> tests/ui/endian_bytes.rs:34:9 + --> tests/ui/endian_bytes.rs:36:9 | LL | f64::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -337,7 +337,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:36:9 + --> tests/ui/endian_bytes.rs:38:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -351,7 +351,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:37:9 + --> tests/ui/endian_bytes.rs:39:9 | LL | 2i8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -363,7 +363,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u16::to_le_bytes` method - --> tests/ui/endian_bytes.rs:38:9 + --> tests/ui/endian_bytes.rs:40:9 | LL | 2u16.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -375,7 +375,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i16::to_le_bytes` method - --> tests/ui/endian_bytes.rs:39:9 + --> tests/ui/endian_bytes.rs:41:9 | LL | 2i16.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -387,7 +387,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u32::to_le_bytes` method - --> tests/ui/endian_bytes.rs:40:9 + --> tests/ui/endian_bytes.rs:42:9 | LL | 2u32.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -399,7 +399,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i32::to_le_bytes` method - --> tests/ui/endian_bytes.rs:41:9 + --> tests/ui/endian_bytes.rs:43:9 | LL | 2i32.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -411,7 +411,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u64::to_le_bytes` method - --> tests/ui/endian_bytes.rs:42:9 + --> tests/ui/endian_bytes.rs:44:9 | LL | 2u64.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -423,7 +423,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i64::to_le_bytes` method - --> tests/ui/endian_bytes.rs:43:9 + --> tests/ui/endian_bytes.rs:45:9 | LL | 2i64.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -435,7 +435,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u128::to_le_bytes` method - --> tests/ui/endian_bytes.rs:44:9 + --> tests/ui/endian_bytes.rs:46:9 | LL | 2u128.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^^ @@ -447,7 +447,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i128::to_le_bytes` method - --> tests/ui/endian_bytes.rs:45:9 + --> tests/ui/endian_bytes.rs:47:9 | LL | 2i128.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^^ @@ -459,7 +459,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `f32::to_le_bytes` method - --> tests/ui/endian_bytes.rs:46:9 + --> tests/ui/endian_bytes.rs:48:9 | LL | 2.0f32.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^^^ @@ -471,7 +471,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `f64::to_le_bytes` method - --> tests/ui/endian_bytes.rs:47:9 + --> tests/ui/endian_bytes.rs:49:9 | LL | 2.0f64.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^^^ @@ -483,7 +483,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `usize::to_le_bytes` method - --> tests/ui/endian_bytes.rs:48:9 + --> tests/ui/endian_bytes.rs:50:9 | LL | 2usize.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^^^ @@ -495,7 +495,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `isize::to_le_bytes` method - --> tests/ui/endian_bytes.rs:49:9 + --> tests/ui/endian_bytes.rs:51:9 | LL | 2isize.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^^^ @@ -507,7 +507,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:50:9 + --> tests/ui/endian_bytes.rs:52:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -519,7 +519,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i8::from_le_bytes` - --> tests/ui/endian_bytes.rs:51:9 + --> tests/ui/endian_bytes.rs:53:9 | LL | i8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -531,7 +531,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u16::from_le_bytes` - --> tests/ui/endian_bytes.rs:52:9 + --> tests/ui/endian_bytes.rs:54:9 | LL | u16::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -543,7 +543,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i16::from_le_bytes` - --> tests/ui/endian_bytes.rs:53:9 + --> tests/ui/endian_bytes.rs:55:9 | LL | i16::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -555,7 +555,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u32::from_le_bytes` - --> tests/ui/endian_bytes.rs:54:9 + --> tests/ui/endian_bytes.rs:56:9 | LL | u32::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -567,7 +567,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i32::from_le_bytes` - --> tests/ui/endian_bytes.rs:55:9 + --> tests/ui/endian_bytes.rs:57:9 | LL | i32::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -579,7 +579,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u64::from_le_bytes` - --> tests/ui/endian_bytes.rs:56:9 + --> tests/ui/endian_bytes.rs:58:9 | LL | u64::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -591,7 +591,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i64::from_le_bytes` - --> tests/ui/endian_bytes.rs:57:9 + --> tests/ui/endian_bytes.rs:59:9 | LL | i64::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -603,7 +603,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u128::from_le_bytes` - --> tests/ui/endian_bytes.rs:58:9 + --> tests/ui/endian_bytes.rs:60:9 | LL | u128::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -615,7 +615,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i128::from_le_bytes` - --> tests/ui/endian_bytes.rs:59:9 + --> tests/ui/endian_bytes.rs:61:9 | LL | i128::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -627,7 +627,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `usize::from_le_bytes` - --> tests/ui/endian_bytes.rs:60:9 + --> tests/ui/endian_bytes.rs:62:9 | LL | usize::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -639,7 +639,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `isize::from_le_bytes` - --> tests/ui/endian_bytes.rs:61:9 + --> tests/ui/endian_bytes.rs:63:9 | LL | isize::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -651,7 +651,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `f32::from_le_bytes` - --> tests/ui/endian_bytes.rs:62:9 + --> tests/ui/endian_bytes.rs:64:9 | LL | f32::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -663,7 +663,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `f64::from_le_bytes` - --> tests/ui/endian_bytes.rs:63:9 + --> tests/ui/endian_bytes.rs:65:9 | LL | f64::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -675,7 +675,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:70:9 + --> tests/ui/endian_bytes.rs:72:9 | LL | 2u8.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -687,7 +687,7 @@ LL | fn host_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:71:9 + --> tests/ui/endian_bytes.rs:73:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -699,7 +699,7 @@ LL | fn host_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_be_bytes` method - --> tests/ui/endian_bytes.rs:76:9 + --> tests/ui/endian_bytes.rs:78:9 | LL | 2u8.to_be_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -713,7 +713,7 @@ LL | fn host_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_be_bytes` - --> tests/ui/endian_bytes.rs:77:9 + --> tests/ui/endian_bytes.rs:79:9 | LL | u8::from_be_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -725,7 +725,7 @@ LL | fn host_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:70:9 + --> tests/ui/endian_bytes.rs:72:9 | LL | 2u8.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -737,7 +737,7 @@ LL | fn host_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:71:9 + --> tests/ui/endian_bytes.rs:73:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -749,7 +749,7 @@ LL | fn host_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:73:9 + --> tests/ui/endian_bytes.rs:75:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -761,7 +761,7 @@ LL | fn host_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:74:9 + --> tests/ui/endian_bytes.rs:76:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -773,7 +773,7 @@ LL | fn host_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:70:9 + --> tests/ui/endian_bytes.rs:72:9 | LL | 2u8.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -784,7 +784,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:71:9 + --> tests/ui/endian_bytes.rs:73:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -795,7 +795,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:73:9 + --> tests/ui/endian_bytes.rs:75:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -806,7 +806,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:74:9 + --> tests/ui/endian_bytes.rs:76:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -817,7 +817,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_be_bytes` method - --> tests/ui/endian_bytes.rs:76:9 + --> tests/ui/endian_bytes.rs:78:9 | LL | 2u8.to_be_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -828,7 +828,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_be_bytes` - --> tests/ui/endian_bytes.rs:77:9 + --> tests/ui/endian_bytes.rs:79:9 | LL | u8::from_be_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -839,7 +839,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:73:9 + --> tests/ui/endian_bytes.rs:75:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -851,7 +851,7 @@ LL | fn little_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:74:9 + --> tests/ui/endian_bytes.rs:76:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -863,7 +863,7 @@ LL | fn little_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_be_bytes` method - --> tests/ui/endian_bytes.rs:76:9 + --> tests/ui/endian_bytes.rs:78:9 | LL | 2u8.to_be_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -875,7 +875,7 @@ LL | fn little_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_be_bytes` - --> tests/ui/endian_bytes.rs:77:9 + --> tests/ui/endian_bytes.rs:79:9 | LL | u8::from_be_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -887,7 +887,7 @@ LL | fn little_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:70:9 + --> tests/ui/endian_bytes.rs:72:9 | LL | 2u8.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -899,7 +899,7 @@ LL | fn little_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:71:9 + --> tests/ui/endian_bytes.rs:73:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -911,7 +911,7 @@ LL | fn little_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:73:9 + --> tests/ui/endian_bytes.rs:75:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -923,7 +923,7 @@ LL | fn little_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:74:9 + --> tests/ui/endian_bytes.rs:76:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -935,7 +935,7 @@ LL | fn little_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:73:9 + --> tests/ui/endian_bytes.rs:75:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -947,7 +947,7 @@ LL | fn big_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:74:9 + --> tests/ui/endian_bytes.rs:76:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -959,7 +959,7 @@ LL | fn big_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_be_bytes` method - --> tests/ui/endian_bytes.rs:76:9 + --> tests/ui/endian_bytes.rs:78:9 | LL | 2u8.to_be_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -971,7 +971,7 @@ LL | fn big_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_be_bytes` - --> tests/ui/endian_bytes.rs:77:9 + --> tests/ui/endian_bytes.rs:79:9 | LL | u8::from_be_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -983,7 +983,7 @@ LL | fn big_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:70:9 + --> tests/ui/endian_bytes.rs:72:9 | LL | 2u8.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -995,7 +995,7 @@ LL | fn big_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:71:9 + --> tests/ui/endian_bytes.rs:73:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -1007,7 +1007,7 @@ LL | fn big_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_be_bytes` method - --> tests/ui/endian_bytes.rs:76:9 + --> tests/ui/endian_bytes.rs:78:9 | LL | 2u8.to_be_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -1019,7 +1019,7 @@ LL | fn big_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_be_bytes` - --> tests/ui/endian_bytes.rs:77:9 + --> tests/ui/endian_bytes.rs:79:9 | LL | u8::from_be_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/float_cmp.rs b/tests/ui/float_cmp.rs index 5057c6437329..1923ad7c677e 100644 --- a/tests/ui/float_cmp.rs +++ b/tests/ui/float_cmp.rs @@ -1,3 +1,5 @@ +// FIXME(f16_f128): const casting is not yet supported for these types. Add when available. + #![warn(clippy::float_cmp)] #![allow( unused, diff --git a/tests/ui/float_cmp.stderr b/tests/ui/float_cmp.stderr index 49b65184f731..c8a0bde6e63a 100644 --- a/tests/ui/float_cmp.stderr +++ b/tests/ui/float_cmp.stderr @@ -1,5 +1,5 @@ error: strict comparison of `f32` or `f64` - --> tests/ui/float_cmp.rs:70:5 + --> tests/ui/float_cmp.rs:72:5 | LL | ONE as f64 != 2.0; | ^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE as f64 - 2.0).abs() > error_margin` @@ -9,7 +9,7 @@ LL | ONE as f64 != 2.0; = help: to override `-D warnings` add `#[allow(clippy::float_cmp)]` error: strict comparison of `f32` or `f64` - --> tests/ui/float_cmp.rs:77:5 + --> tests/ui/float_cmp.rs:79:5 | LL | x == 1.0; | ^^^^^^^^ help: consider comparing them within some margin of error: `(x - 1.0).abs() < error_margin` @@ -17,7 +17,7 @@ LL | x == 1.0; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` - --> tests/ui/float_cmp.rs:82:5 + --> tests/ui/float_cmp.rs:84:5 | LL | twice(x) != twice(ONE as f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(twice(x) - twice(ONE as f64)).abs() > error_margin` @@ -25,7 +25,7 @@ LL | twice(x) != twice(ONE as f64); = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` - --> tests/ui/float_cmp.rs:104:5 + --> tests/ui/float_cmp.rs:106:5 | LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(NON_ZERO_ARRAY[i] - NON_ZERO_ARRAY[j]).abs() < error_margin` @@ -33,7 +33,7 @@ LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` arrays - --> tests/ui/float_cmp.rs:111:5 + --> tests/ui/float_cmp.rs:113:5 | LL | a1 == a2; | ^^^^^^^^ @@ -41,7 +41,7 @@ LL | a1 == a2; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` - --> tests/ui/float_cmp.rs:114:5 + --> tests/ui/float_cmp.rs:116:5 | LL | a1[0] == a2[0]; | ^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(a1[0] - a2[0]).abs() < error_margin` diff --git a/tests/ui/float_equality_without_abs.rs b/tests/ui/float_equality_without_abs.rs index 6363472d8990..2b67c8bec103 100644 --- a/tests/ui/float_equality_without_abs.rs +++ b/tests/ui/float_equality_without_abs.rs @@ -1,5 +1,8 @@ #![warn(clippy::float_equality_without_abs)] //@no-rustfix + +// FIXME(f16_f128): add tests for these types when abs is available + pub fn is_roughly_equal(a: f32, b: f32) -> bool { (a - b) < f32::EPSILON //~^ ERROR: float equality check without `.abs()` diff --git a/tests/ui/float_equality_without_abs.stderr b/tests/ui/float_equality_without_abs.stderr index 0124dd983a39..cdaaf0cdbcf7 100644 --- a/tests/ui/float_equality_without_abs.stderr +++ b/tests/ui/float_equality_without_abs.stderr @@ -1,5 +1,5 @@ error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:4:5 + --> tests/ui/float_equality_without_abs.rs:7:5 | LL | (a - b) < f32::EPSILON | -------^^^^^^^^^^^^^^^ @@ -10,7 +10,7 @@ LL | (a - b) < f32::EPSILON = help: to override `-D warnings` add `#[allow(clippy::float_equality_without_abs)]` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:15:13 + --> tests/ui/float_equality_without_abs.rs:18:13 | LL | let _ = (a - b) < f32::EPSILON; | -------^^^^^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | let _ = (a - b) < f32::EPSILON; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:17:13 + --> tests/ui/float_equality_without_abs.rs:20:13 | LL | let _ = a - b < f32::EPSILON; | -----^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | let _ = a - b < f32::EPSILON; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:19:13 + --> tests/ui/float_equality_without_abs.rs:22:13 | LL | let _ = a - b.abs() < f32::EPSILON; | -----------^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = a - b.abs() < f32::EPSILON; | help: add `.abs()`: `(a - b.abs()).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:21:13 + --> tests/ui/float_equality_without_abs.rs:24:13 | LL | let _ = (a as f64 - b as f64) < f64::EPSILON; | ---------------------^^^^^^^^^^^^^^^ @@ -42,7 +42,7 @@ LL | let _ = (a as f64 - b as f64) < f64::EPSILON; | help: add `.abs()`: `(a as f64 - b as f64).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:23:13 + --> tests/ui/float_equality_without_abs.rs:26:13 | LL | let _ = 1.0 - 2.0 < f32::EPSILON; | ---------^^^^^^^^^^^^^^^ @@ -50,7 +50,7 @@ LL | let _ = 1.0 - 2.0 < f32::EPSILON; | help: add `.abs()`: `(1.0 - 2.0).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:26:13 + --> tests/ui/float_equality_without_abs.rs:29:13 | LL | let _ = f32::EPSILON > (a - b); | ^^^^^^^^^^^^^^^------- @@ -58,7 +58,7 @@ LL | let _ = f32::EPSILON > (a - b); | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:28:13 + --> tests/ui/float_equality_without_abs.rs:31:13 | LL | let _ = f32::EPSILON > a - b; | ^^^^^^^^^^^^^^^----- @@ -66,7 +66,7 @@ LL | let _ = f32::EPSILON > a - b; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:30:13 + --> tests/ui/float_equality_without_abs.rs:33:13 | LL | let _ = f32::EPSILON > a - b.abs(); | ^^^^^^^^^^^^^^^----------- @@ -74,7 +74,7 @@ LL | let _ = f32::EPSILON > a - b.abs(); | help: add `.abs()`: `(a - b.abs()).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:32:13 + --> tests/ui/float_equality_without_abs.rs:35:13 | LL | let _ = f64::EPSILON > (a as f64 - b as f64); | ^^^^^^^^^^^^^^^--------------------- @@ -82,7 +82,7 @@ LL | let _ = f64::EPSILON > (a as f64 - b as f64); | help: add `.abs()`: `(a as f64 - b as f64).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:34:13 + --> tests/ui/float_equality_without_abs.rs:37:13 | LL | let _ = f32::EPSILON > 1.0 - 2.0; | ^^^^^^^^^^^^^^^--------- diff --git a/tests/ui/floating_point_arithmetic_nostd.rs b/tests/ui/floating_point_arithmetic_nostd.rs index a42c6383ccea..47c113d61c04 100644 --- a/tests/ui/floating_point_arithmetic_nostd.rs +++ b/tests/ui/floating_point_arithmetic_nostd.rs @@ -3,8 +3,8 @@ #![warn(clippy::suboptimal_flops)] #![no_std] -// The following should not lint, as the suggested methods {f32,f64}.mul_add() -// and {f32,f64}::abs() are not available in no_std +// The following should not lint, as the suggested methods `{f16,f32,f64,f128}.mul_add()` +// and ``{f16,f32,f64,f128}::abs()` are not available in no_std pub fn mul_add() { let a: f64 = 1234.567; diff --git a/tests/ui/floating_point_exp.fixed b/tests/ui/floating_point_exp.fixed index 15072bb1ee9a..fbd91cbc9d70 100644 --- a/tests/ui/floating_point_exp.fixed +++ b/tests/ui/floating_point_exp.fixed @@ -1,3 +1,5 @@ +// FIXME(f16_f128): add tests when exp is available + #![warn(clippy::imprecise_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/tests/ui/floating_point_exp.rs b/tests/ui/floating_point_exp.rs index 7d8b17946d0a..340bacaf56b5 100644 --- a/tests/ui/floating_point_exp.rs +++ b/tests/ui/floating_point_exp.rs @@ -1,3 +1,5 @@ +// FIXME(f16_f128): add tests when exp is available + #![warn(clippy::imprecise_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/tests/ui/floating_point_exp.stderr b/tests/ui/floating_point_exp.stderr index a19edf87e244..6ce67254abc9 100644 --- a/tests/ui/floating_point_exp.stderr +++ b/tests/ui/floating_point_exp.stderr @@ -1,5 +1,5 @@ error: (e.pow(x) - 1) can be computed more accurately - --> tests/ui/floating_point_exp.rs:6:13 + --> tests/ui/floating_point_exp.rs:8:13 | LL | let _ = x.exp() - 1.0; | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` @@ -8,25 +8,25 @@ LL | let _ = x.exp() - 1.0; = help: to override `-D warnings` add `#[allow(clippy::imprecise_flops)]` error: (e.pow(x) - 1) can be computed more accurately - --> tests/ui/floating_point_exp.rs:7:13 + --> tests/ui/floating_point_exp.rs:9:13 | LL | let _ = x.exp() - 1.0 + 2.0; | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` error: (e.pow(x) - 1) can be computed more accurately - --> tests/ui/floating_point_exp.rs:8:13 + --> tests/ui/floating_point_exp.rs:10:13 | LL | let _ = (x as f32).exp() - 1.0 + 2.0; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).exp_m1()` error: (e.pow(x) - 1) can be computed more accurately - --> tests/ui/floating_point_exp.rs:14:13 + --> tests/ui/floating_point_exp.rs:16:13 | LL | let _ = x.exp() - 1.0; | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` error: (e.pow(x) - 1) can be computed more accurately - --> tests/ui/floating_point_exp.rs:15:13 + --> tests/ui/floating_point_exp.rs:17:13 | LL | let _ = x.exp() - 1.0 + 2.0; | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` diff --git a/tests/ui/floating_point_log.fixed b/tests/ui/floating_point_log.fixed index 15cc47eef0dd..75e9c40a5218 100644 --- a/tests/ui/floating_point_log.fixed +++ b/tests/ui/floating_point_log.fixed @@ -1,6 +1,8 @@ #![allow(dead_code, clippy::double_parens, clippy::unnecessary_cast)] #![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] +// FIXME(f16_f128): add tests for these types once math functions are available + const TWO: f32 = 2.0; const E: f32 = std::f32::consts::E; diff --git a/tests/ui/floating_point_log.rs b/tests/ui/floating_point_log.rs index 1241af828593..d68369a38618 100644 --- a/tests/ui/floating_point_log.rs +++ b/tests/ui/floating_point_log.rs @@ -1,6 +1,8 @@ #![allow(dead_code, clippy::double_parens, clippy::unnecessary_cast)] #![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] +// FIXME(f16_f128): add tests for these types once math functions are available + const TWO: f32 = 2.0; const E: f32 = std::f32::consts::E; diff --git a/tests/ui/floating_point_log.stderr b/tests/ui/floating_point_log.stderr index 3a449a98eadd..19c28de8e39a 100644 --- a/tests/ui/floating_point_log.stderr +++ b/tests/ui/floating_point_log.stderr @@ -1,5 +1,5 @@ error: logarithm for bases 2, 10 and e can be computed more accurately - --> tests/ui/floating_point_log.rs:9:13 + --> tests/ui/floating_point_log.rs:11:13 | LL | let _ = x.log(2f32); | ^^^^^^^^^^^ help: consider using: `x.log2()` @@ -8,55 +8,55 @@ LL | let _ = x.log(2f32); = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: logarithm for bases 2, 10 and e can be computed more accurately - --> tests/ui/floating_point_log.rs:10:13 + --> tests/ui/floating_point_log.rs:12:13 | LL | let _ = x.log(10f32); | ^^^^^^^^^^^^ help: consider using: `x.log10()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> tests/ui/floating_point_log.rs:11:13 + --> tests/ui/floating_point_log.rs:13:13 | LL | let _ = x.log(std::f32::consts::E); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> tests/ui/floating_point_log.rs:12:13 + --> tests/ui/floating_point_log.rs:14:13 | LL | let _ = x.log(TWO); | ^^^^^^^^^^ help: consider using: `x.log2()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> tests/ui/floating_point_log.rs:13:13 + --> tests/ui/floating_point_log.rs:15:13 | LL | let _ = x.log(E); | ^^^^^^^^ help: consider using: `x.ln()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> tests/ui/floating_point_log.rs:14:13 + --> tests/ui/floating_point_log.rs:16:13 | LL | let _ = (x as f32).log(2f32); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).log2()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> tests/ui/floating_point_log.rs:17:13 + --> tests/ui/floating_point_log.rs:19:13 | LL | let _ = x.log(2f64); | ^^^^^^^^^^^ help: consider using: `x.log2()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> tests/ui/floating_point_log.rs:18:13 + --> tests/ui/floating_point_log.rs:20:13 | LL | let _ = x.log(10f64); | ^^^^^^^^^^^^ help: consider using: `x.log10()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> tests/ui/floating_point_log.rs:19:13 + --> tests/ui/floating_point_log.rs:21:13 | LL | let _ = x.log(std::f64::consts::E); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:24:13 + --> tests/ui/floating_point_log.rs:26:13 | LL | let _ = (1f32 + 2.).ln(); | ^^^^^^^^^^^^^^^^ help: consider using: `2.0f32.ln_1p()` @@ -65,115 +65,115 @@ LL | let _ = (1f32 + 2.).ln(); = help: to override `-D warnings` add `#[allow(clippy::imprecise_flops)]` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:25:13 + --> tests/ui/floating_point_log.rs:27:13 | LL | let _ = (1f32 + 2.0).ln(); | ^^^^^^^^^^^^^^^^^ help: consider using: `2.0f32.ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:26:13 + --> tests/ui/floating_point_log.rs:28:13 | LL | let _ = (1.0 + x).ln(); | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:27:13 + --> tests/ui/floating_point_log.rs:29:13 | LL | let _ = (1.0 + x / 2.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x / 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:28:13 + --> tests/ui/floating_point_log.rs:30:13 | LL | let _ = (1.0 + x.powi(3)).ln(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(3).ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:29:13 + --> tests/ui/floating_point_log.rs:31:13 | LL | let _ = (1.0 + x.powi(3) / 2.0).ln(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x.powi(3) / 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:30:13 + --> tests/ui/floating_point_log.rs:32:13 | LL | let _ = (1.0 + (std::f32::consts::E - 1.0)).ln(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(std::f32::consts::E - 1.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:31:13 + --> tests/ui/floating_point_log.rs:33:13 | LL | let _ = (x + 1.0).ln(); | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:32:13 + --> tests/ui/floating_point_log.rs:34:13 | LL | let _ = (x.powi(3) + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(3).ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:33:13 + --> tests/ui/floating_point_log.rs:35:13 | LL | let _ = (x + 2.0 + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:34:13 + --> tests/ui/floating_point_log.rs:36:13 | LL | let _ = (x / 2.0 + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x / 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:42:13 + --> tests/ui/floating_point_log.rs:44:13 | LL | let _ = (1f64 + 2.).ln(); | ^^^^^^^^^^^^^^^^ help: consider using: `2.0f64.ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:43:13 + --> tests/ui/floating_point_log.rs:45:13 | LL | let _ = (1f64 + 2.0).ln(); | ^^^^^^^^^^^^^^^^^ help: consider using: `2.0f64.ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:44:13 + --> tests/ui/floating_point_log.rs:46:13 | LL | let _ = (1.0 + x).ln(); | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:45:13 + --> tests/ui/floating_point_log.rs:47:13 | LL | let _ = (1.0 + x / 2.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x / 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:46:13 + --> tests/ui/floating_point_log.rs:48:13 | LL | let _ = (1.0 + x.powi(3)).ln(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(3).ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:47:13 + --> tests/ui/floating_point_log.rs:49:13 | LL | let _ = (x + 1.0).ln(); | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:48:13 + --> tests/ui/floating_point_log.rs:50:13 | LL | let _ = (x.powi(3) + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(3).ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:49:13 + --> tests/ui/floating_point_log.rs:51:13 | LL | let _ = (x + 2.0 + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:50:13 + --> tests/ui/floating_point_log.rs:52:13 | LL | let _ = (x / 2.0 + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x / 2.0).ln_1p()` diff --git a/tests/ui/floating_point_powf.fixed b/tests/ui/floating_point_powf.fixed index c2884ca318c6..a44938fdf692 100644 --- a/tests/ui/floating_point_powf.fixed +++ b/tests/ui/floating_point_powf.fixed @@ -1,6 +1,8 @@ #![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] #![allow(clippy::unnecessary_cast)] +// FIXME(f16_f128): add tests for these types when `powf` is available + fn main() { let x = 3f32; let _ = x.exp2(); diff --git a/tests/ui/floating_point_powf.rs b/tests/ui/floating_point_powf.rs index 37d58af05513..80f6c1791d7c 100644 --- a/tests/ui/floating_point_powf.rs +++ b/tests/ui/floating_point_powf.rs @@ -1,6 +1,8 @@ #![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] #![allow(clippy::unnecessary_cast)] +// FIXME(f16_f128): add tests for these types when `powf` is available + fn main() { let x = 3f32; let _ = 2f32.powf(x); diff --git a/tests/ui/floating_point_powf.stderr b/tests/ui/floating_point_powf.stderr index bd3fa771fe50..671383401b55 100644 --- a/tests/ui/floating_point_powf.stderr +++ b/tests/ui/floating_point_powf.stderr @@ -1,5 +1,5 @@ error: exponent for bases 2 and e can be computed more accurately - --> tests/ui/floating_point_powf.rs:6:13 + --> tests/ui/floating_point_powf.rs:8:13 | LL | let _ = 2f32.powf(x); | ^^^^^^^^^^^^ help: consider using: `x.exp2()` @@ -8,43 +8,43 @@ LL | let _ = 2f32.powf(x); = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: exponent for bases 2 and e can be computed more accurately - --> tests/ui/floating_point_powf.rs:7:13 + --> tests/ui/floating_point_powf.rs:9:13 | LL | let _ = 2f32.powf(3.1); | ^^^^^^^^^^^^^^ help: consider using: `3.1f32.exp2()` error: exponent for bases 2 and e can be computed more accurately - --> tests/ui/floating_point_powf.rs:8:13 + --> tests/ui/floating_point_powf.rs:10:13 | LL | let _ = 2f32.powf(-3.1); | ^^^^^^^^^^^^^^^ help: consider using: `(-3.1f32).exp2()` error: exponent for bases 2 and e can be computed more accurately - --> tests/ui/floating_point_powf.rs:9:13 + --> tests/ui/floating_point_powf.rs:11:13 | LL | let _ = std::f32::consts::E.powf(x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()` error: exponent for bases 2 and e can be computed more accurately - --> tests/ui/floating_point_powf.rs:10:13 + --> tests/ui/floating_point_powf.rs:12:13 | LL | let _ = std::f32::consts::E.powf(3.1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `3.1f32.exp()` error: exponent for bases 2 and e can be computed more accurately - --> tests/ui/floating_point_powf.rs:11:13 + --> tests/ui/floating_point_powf.rs:13:13 | LL | let _ = std::f32::consts::E.powf(-3.1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-3.1f32).exp()` error: square-root of a number can be computed more efficiently and accurately - --> tests/ui/floating_point_powf.rs:12:13 + --> tests/ui/floating_point_powf.rs:14:13 | LL | let _ = x.powf(1.0 / 2.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()` error: cube-root of a number can be computed more accurately - --> tests/ui/floating_point_powf.rs:13:13 + --> tests/ui/floating_point_powf.rs:15:13 | LL | let _ = x.powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()` @@ -53,139 +53,139 @@ LL | let _ = x.powf(1.0 / 3.0); = help: to override `-D warnings` add `#[allow(clippy::imprecise_flops)]` error: cube-root of a number can be computed more accurately - --> tests/ui/floating_point_powf.rs:14:13 + --> tests/ui/floating_point_powf.rs:16:13 | LL | let _ = (x as f32).powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).cbrt()` error: exponentiation with integer powers can be computed more efficiently - --> tests/ui/floating_point_powf.rs:15:13 + --> tests/ui/floating_point_powf.rs:17:13 | LL | let _ = x.powf(3.0); | ^^^^^^^^^^^ help: consider using: `x.powi(3)` error: exponentiation with integer powers can be computed more efficiently - --> tests/ui/floating_point_powf.rs:16:13 + --> tests/ui/floating_point_powf.rs:18:13 | LL | let _ = x.powf(-2.0); | ^^^^^^^^^^^^ help: consider using: `x.powi(-2)` error: exponentiation with integer powers can be computed more efficiently - --> tests/ui/floating_point_powf.rs:17:13 + --> tests/ui/floating_point_powf.rs:19:13 | LL | let _ = x.powf(16_777_215.0); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(16_777_215)` error: exponentiation with integer powers can be computed more efficiently - --> tests/ui/floating_point_powf.rs:18:13 + --> tests/ui/floating_point_powf.rs:20:13 | LL | let _ = x.powf(-16_777_215.0); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(-16_777_215)` error: exponentiation with integer powers can be computed more efficiently - --> tests/ui/floating_point_powf.rs:19:13 + --> tests/ui/floating_point_powf.rs:21:13 | LL | let _ = (x as f32).powf(-16_777_215.0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).powi(-16_777_215)` error: exponentiation with integer powers can be computed more efficiently - --> tests/ui/floating_point_powf.rs:20:13 + --> tests/ui/floating_point_powf.rs:22:13 | LL | let _ = (x as f32).powf(3.0); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).powi(3)` error: cube-root of a number can be computed more accurately - --> tests/ui/floating_point_powf.rs:21:13 + --> tests/ui/floating_point_powf.rs:23:13 | LL | let _ = (1.5_f32 + 1.0).powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(1.5_f32 + 1.0).cbrt()` error: cube-root of a number can be computed more accurately - --> tests/ui/floating_point_powf.rs:22:13 + --> tests/ui/floating_point_powf.rs:24:13 | LL | let _ = 1.5_f64.powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.5_f64.cbrt()` error: square-root of a number can be computed more efficiently and accurately - --> tests/ui/floating_point_powf.rs:23:13 + --> tests/ui/floating_point_powf.rs:25:13 | LL | let _ = 1.5_f64.powf(1.0 / 2.0); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.5_f64.sqrt()` error: exponentiation with integer powers can be computed more efficiently - --> tests/ui/floating_point_powf.rs:24:13 + --> tests/ui/floating_point_powf.rs:26:13 | LL | let _ = 1.5_f64.powf(3.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `1.5_f64.powi(3)` error: exponent for bases 2 and e can be computed more accurately - --> tests/ui/floating_point_powf.rs:33:13 + --> tests/ui/floating_point_powf.rs:35:13 | LL | let _ = 2f64.powf(x); | ^^^^^^^^^^^^ help: consider using: `x.exp2()` error: exponent for bases 2 and e can be computed more accurately - --> tests/ui/floating_point_powf.rs:34:13 + --> tests/ui/floating_point_powf.rs:36:13 | LL | let _ = 2f64.powf(3.1); | ^^^^^^^^^^^^^^ help: consider using: `3.1f64.exp2()` error: exponent for bases 2 and e can be computed more accurately - --> tests/ui/floating_point_powf.rs:35:13 + --> tests/ui/floating_point_powf.rs:37:13 | LL | let _ = 2f64.powf(-3.1); | ^^^^^^^^^^^^^^^ help: consider using: `(-3.1f64).exp2()` error: exponent for bases 2 and e can be computed more accurately - --> tests/ui/floating_point_powf.rs:36:13 + --> tests/ui/floating_point_powf.rs:38:13 | LL | let _ = std::f64::consts::E.powf(x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()` error: exponent for bases 2 and e can be computed more accurately - --> tests/ui/floating_point_powf.rs:37:13 + --> tests/ui/floating_point_powf.rs:39:13 | LL | let _ = std::f64::consts::E.powf(3.1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `3.1f64.exp()` error: exponent for bases 2 and e can be computed more accurately - --> tests/ui/floating_point_powf.rs:38:13 + --> tests/ui/floating_point_powf.rs:40:13 | LL | let _ = std::f64::consts::E.powf(-3.1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-3.1f64).exp()` error: square-root of a number can be computed more efficiently and accurately - --> tests/ui/floating_point_powf.rs:39:13 + --> tests/ui/floating_point_powf.rs:41:13 | LL | let _ = x.powf(1.0 / 2.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()` error: cube-root of a number can be computed more accurately - --> tests/ui/floating_point_powf.rs:40:13 + --> tests/ui/floating_point_powf.rs:42:13 | LL | let _ = x.powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()` error: exponentiation with integer powers can be computed more efficiently - --> tests/ui/floating_point_powf.rs:41:13 + --> tests/ui/floating_point_powf.rs:43:13 | LL | let _ = x.powf(3.0); | ^^^^^^^^^^^ help: consider using: `x.powi(3)` error: exponentiation with integer powers can be computed more efficiently - --> tests/ui/floating_point_powf.rs:42:13 + --> tests/ui/floating_point_powf.rs:44:13 | LL | let _ = x.powf(-2.0); | ^^^^^^^^^^^^ help: consider using: `x.powi(-2)` error: exponentiation with integer powers can be computed more efficiently - --> tests/ui/floating_point_powf.rs:43:13 + --> tests/ui/floating_point_powf.rs:45:13 | LL | let _ = x.powf(-2_147_483_648.0); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(-2_147_483_648)` error: exponentiation with integer powers can be computed more efficiently - --> tests/ui/floating_point_powf.rs:44:13 + --> tests/ui/floating_point_powf.rs:46:13 | LL | let _ = x.powf(2_147_483_647.0); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2_147_483_647)` diff --git a/tests/ui/lossy_float_literal.fixed b/tests/ui/lossy_float_literal.fixed index 92a0084a6aeb..cc8c0b4a0d17 100644 --- a/tests/ui/lossy_float_literal.fixed +++ b/tests/ui/lossy_float_literal.fixed @@ -1,31 +1,55 @@ #![warn(clippy::lossy_float_literal)] #![allow(overflowing_literals, unused)] +#![feature(f128)] +#![feature(f16)] fn main() { // Lossy whole-number float literals + let _: f16 = 4_097.0; + let _: f16 = 4_097.; + let _: f16 = 4_097.000; + let _ = 4_097f16; + let _: f16 = -4_097.0; + let _: f32 = 16_777_216.0; let _: f32 = 16_777_220.0; let _: f32 = 16_777_220.0; let _: f32 = 16_777_220.0; let _ = 16_777_220_f32; let _: f32 = -16_777_220.0; + let _: f64 = 9_007_199_254_740_992.0; let _: f64 = 9_007_199_254_740_992.0; let _: f64 = 9_007_199_254_740_992.0; let _ = 9_007_199_254_740_992_f64; let _: f64 = -9_007_199_254_740_992.0; + let _: f128 = 10_384_593_717_069_655_257_060_992_658_440_193.0; + let _: f128 = 10_384_593_717_069_655_257_060_992_658_440_193.; + let _: f128 = 10_384_593_717_069_655_257_060_992_658_440_193.00; + let _ = 10_384_593_717_069_655_257_060_992_658_440_193f128; + let _: f128 = -10_384_593_717_069_655_257_060_992_658_440_193.0; + // Lossless whole number float literals + let _: f16 = 4_096.0; + let _: f16 = -4_096.0; + let _: f32 = 16_777_216.0; let _: f32 = 16_777_218.0; let _: f32 = 16_777_220.0; let _: f32 = -16_777_216.0; let _: f32 = -16_777_220.0; + let _: f64 = 16_777_217.0; let _: f64 = -16_777_217.0; let _: f64 = 9_007_199_254_740_992.0; let _: f64 = -9_007_199_254_740_992.0; + let _: f128 = 9_007_199_254_740_993.0; + let _: f128 = -9_007_199_254_740_993.0; + let _: f128 = 10_384_593_717_069_655_257_060_992_658_440_192.0; + let _: f128 = -10_384_593_717_069_655_257_060_992_658_440_192.0; + // Ignored whole number float literals let _: f32 = 1e25; let _: f32 = 1E25; diff --git a/tests/ui/lossy_float_literal.rs b/tests/ui/lossy_float_literal.rs index 5abef3c442ec..c84eef396d58 100644 --- a/tests/ui/lossy_float_literal.rs +++ b/tests/ui/lossy_float_literal.rs @@ -1,31 +1,55 @@ #![warn(clippy::lossy_float_literal)] #![allow(overflowing_literals, unused)] +#![feature(f128)] +#![feature(f16)] fn main() { // Lossy whole-number float literals + let _: f16 = 4_097.0; + let _: f16 = 4_097.; + let _: f16 = 4_097.000; + let _ = 4_097f16; + let _: f16 = -4_097.0; + let _: f32 = 16_777_217.0; let _: f32 = 16_777_219.0; let _: f32 = 16_777_219.; let _: f32 = 16_777_219.000; let _ = 16_777_219f32; let _: f32 = -16_777_219.0; + let _: f64 = 9_007_199_254_740_993.0; let _: f64 = 9_007_199_254_740_993.; let _: f64 = 9_007_199_254_740_993.00; let _ = 9_007_199_254_740_993f64; let _: f64 = -9_007_199_254_740_993.0; + let _: f128 = 10_384_593_717_069_655_257_060_992_658_440_193.0; + let _: f128 = 10_384_593_717_069_655_257_060_992_658_440_193.; + let _: f128 = 10_384_593_717_069_655_257_060_992_658_440_193.00; + let _ = 10_384_593_717_069_655_257_060_992_658_440_193f128; + let _: f128 = -10_384_593_717_069_655_257_060_992_658_440_193.0; + // Lossless whole number float literals + let _: f16 = 4_096.0; + let _: f16 = -4_096.0; + let _: f32 = 16_777_216.0; let _: f32 = 16_777_218.0; let _: f32 = 16_777_220.0; let _: f32 = -16_777_216.0; let _: f32 = -16_777_220.0; + let _: f64 = 16_777_217.0; let _: f64 = -16_777_217.0; let _: f64 = 9_007_199_254_740_992.0; let _: f64 = -9_007_199_254_740_992.0; + let _: f128 = 9_007_199_254_740_993.0; + let _: f128 = -9_007_199_254_740_993.0; + let _: f128 = 10_384_593_717_069_655_257_060_992_658_440_192.0; + let _: f128 = -10_384_593_717_069_655_257_060_992_658_440_192.0; + // Ignored whole number float literals let _: f32 = 1e25; let _: f32 = 1E25; diff --git a/tests/ui/lossy_float_literal.stderr b/tests/ui/lossy_float_literal.stderr index 7904719141c1..b5a07418734c 100644 --- a/tests/ui/lossy_float_literal.stderr +++ b/tests/ui/lossy_float_literal.stderr @@ -1,5 +1,5 @@ error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:6:18 + --> tests/ui/lossy_float_literal.rs:14:18 | LL | let _: f32 = 16_777_217.0; | ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_216.0` @@ -8,61 +8,61 @@ LL | let _: f32 = 16_777_217.0; = help: to override `-D warnings` add `#[allow(clippy::lossy_float_literal)]` error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:7:18 + --> tests/ui/lossy_float_literal.rs:15:18 | LL | let _: f32 = 16_777_219.0; | ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:8:18 + --> tests/ui/lossy_float_literal.rs:16:18 | LL | let _: f32 = 16_777_219.; | ^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:9:18 + --> tests/ui/lossy_float_literal.rs:17:18 | LL | let _: f32 = 16_777_219.000; | ^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:10:13 + --> tests/ui/lossy_float_literal.rs:18:13 | LL | let _ = 16_777_219f32; | ^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220_f32` error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:11:19 + --> tests/ui/lossy_float_literal.rs:19:19 | LL | let _: f32 = -16_777_219.0; | ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:12:18 + --> tests/ui/lossy_float_literal.rs:21:18 | LL | let _: f64 = 9_007_199_254_740_993.0; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:13:18 + --> tests/ui/lossy_float_literal.rs:22:18 | LL | let _: f64 = 9_007_199_254_740_993.; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:14:18 + --> tests/ui/lossy_float_literal.rs:23:18 | LL | let _: f64 = 9_007_199_254_740_993.00; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:15:13 + --> tests/ui/lossy_float_literal.rs:24:13 | LL | let _ = 9_007_199_254_740_993f64; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992_f64` error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:16:19 + --> tests/ui/lossy_float_literal.rs:25:19 | LL | let _: f64 = -9_007_199_254_740_993.0; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` diff --git a/tests/ui/manual_float_methods.rs b/tests/ui/manual_float_methods.rs index 80781ecda721..ee3daa12834b 100644 --- a/tests/ui/manual_float_methods.rs +++ b/tests/ui/manual_float_methods.rs @@ -3,6 +3,8 @@ #![allow(clippy::needless_if, unused)] #![warn(clippy::manual_is_infinite, clippy::manual_is_finite)] +// FIXME(f16_f128): add tests for these types once constants are available + #[macro_use] extern crate proc_macros; diff --git a/tests/ui/manual_float_methods.stderr b/tests/ui/manual_float_methods.stderr index 930df0b97cb3..70057620a4a8 100644 --- a/tests/ui/manual_float_methods.stderr +++ b/tests/ui/manual_float_methods.stderr @@ -1,5 +1,5 @@ error: manually checking if a float is infinite - --> tests/ui/manual_float_methods.rs:22:8 + --> tests/ui/manual_float_methods.rs:24:8 | LL | if x == f32::INFINITY || x == f32::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()` @@ -8,7 +8,7 @@ LL | if x == f32::INFINITY || x == f32::NEG_INFINITY {} = help: to override `-D warnings` add `#[allow(clippy::manual_is_infinite)]` error: manually checking if a float is finite - --> tests/ui/manual_float_methods.rs:23:8 + --> tests/ui/manual_float_methods.rs:25:8 | LL | if x != f32::INFINITY && x != f32::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -29,13 +29,13 @@ LL | if !x.is_infinite() {} | ~~~~~~~~~~~~~~~~ error: manually checking if a float is infinite - --> tests/ui/manual_float_methods.rs:24:8 + --> tests/ui/manual_float_methods.rs:26:8 | LL | if x == INFINITE || x == NEG_INFINITE {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()` error: manually checking if a float is finite - --> tests/ui/manual_float_methods.rs:25:8 + --> tests/ui/manual_float_methods.rs:27:8 | LL | if x != INFINITE && x != NEG_INFINITE {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,13 +54,13 @@ LL | if !x.is_infinite() {} | ~~~~~~~~~~~~~~~~ error: manually checking if a float is infinite - --> tests/ui/manual_float_methods.rs:27:8 + --> tests/ui/manual_float_methods.rs:29:8 | LL | if x == f64::INFINITY || x == f64::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()` error: manually checking if a float is finite - --> tests/ui/manual_float_methods.rs:28:8 + --> tests/ui/manual_float_methods.rs:30:8 | LL | if x != f64::INFINITY && x != f64::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/modulo_arithmetic_float.rs b/tests/ui/modulo_arithmetic_float.rs index 37895ea09e72..a5b63bed531b 100644 --- a/tests/ui/modulo_arithmetic_float.rs +++ b/tests/ui/modulo_arithmetic_float.rs @@ -1,3 +1,5 @@ +#![feature(f128)] +#![feature(f16)] #![warn(clippy::modulo_arithmetic)] #![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::modulo_one)] @@ -16,6 +18,19 @@ fn main() { //~^ ERROR: you are using modulo operator on constants with different signs: `3.400 % //~| NOTE: double check for expected result especially when interoperating with differ + // Lint on floating point numbers + let a_f16: f16 = -1.6; + let mut b_f16: f16 = 2.1; + a_f16 % b_f16; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ + b_f16 % a_f16; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ + b_f16 %= a_f16; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ + // Lint on floating point numbers let a_f32: f32 = -1.6; let mut b_f32: f32 = 2.1; @@ -41,6 +56,18 @@ fn main() { //~^ ERROR: you are using modulo operator on types that might have different signs //~| NOTE: double check for expected result especially when interoperating with differ + let a_f128: f128 = -1.6; + let mut b_f128: f128 = 2.1; + a_f128 % b_f128; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ + b_f128 % a_f128; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ + b_f128 %= a_f128; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ + // No lint when both sides are const and of the same sign 1.6 % 2.1; -1.6 % -2.1; diff --git a/tests/ui/modulo_arithmetic_float.stderr b/tests/ui/modulo_arithmetic_float.stderr index fa3a64cfb714..2b4937552bda 100644 --- a/tests/ui/modulo_arithmetic_float.stderr +++ b/tests/ui/modulo_arithmetic_float.stderr @@ -1,5 +1,5 @@ error: you are using modulo operator on constants with different signs: `-1.600 % 2.100` - --> tests/ui/modulo_arithmetic_float.rs:6:5 + --> tests/ui/modulo_arithmetic_float.rs:8:5 | LL | -1.6 % 2.1; | ^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | -1.6 % 2.1; = help: to override `-D warnings` add `#[allow(clippy::modulo_arithmetic)]` error: you are using modulo operator on constants with different signs: `1.600 % -2.100` - --> tests/ui/modulo_arithmetic_float.rs:9:5 + --> tests/ui/modulo_arithmetic_float.rs:11:5 | LL | 1.6 % -2.1; | ^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | 1.6 % -2.1; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on constants with different signs: `-1.200 % 3.400` - --> tests/ui/modulo_arithmetic_float.rs:12:5 + --> tests/ui/modulo_arithmetic_float.rs:14:5 | LL | (1.1 - 2.3) % (1.1 + 2.3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | (1.1 - 2.3) % (1.1 + 2.3); = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on constants with different signs: `3.400 % -1.200` - --> tests/ui/modulo_arithmetic_float.rs:15:5 + --> tests/ui/modulo_arithmetic_float.rs:17:5 | LL | (1.1 + 2.3) % (1.1 - 2.3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,31 @@ LL | (1.1 + 2.3) % (1.1 - 2.3); = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> tests/ui/modulo_arithmetic_float.rs:22:5 + --> tests/ui/modulo_arithmetic_float.rs:24:5 + | +LL | a_f16 % b_f16; + | ^^^^^^^^^^^^^ + | + = note: double check for expected result especially when interoperating with different languages + +error: you are using modulo operator on types that might have different signs + --> tests/ui/modulo_arithmetic_float.rs:27:5 + | +LL | b_f16 % a_f16; + | ^^^^^^^^^^^^^ + | + = note: double check for expected result especially when interoperating with different languages + +error: you are using modulo operator on types that might have different signs + --> tests/ui/modulo_arithmetic_float.rs:30:5 + | +LL | b_f16 %= a_f16; + | ^^^^^^^^^^^^^^ + | + = note: double check for expected result especially when interoperating with different languages + +error: you are using modulo operator on types that might have different signs + --> tests/ui/modulo_arithmetic_float.rs:37:5 | LL | a_f32 % b_f32; | ^^^^^^^^^^^^^ @@ -41,7 +65,7 @@ LL | a_f32 % b_f32; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> tests/ui/modulo_arithmetic_float.rs:25:5 + --> tests/ui/modulo_arithmetic_float.rs:40:5 | LL | b_f32 % a_f32; | ^^^^^^^^^^^^^ @@ -49,7 +73,7 @@ LL | b_f32 % a_f32; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> tests/ui/modulo_arithmetic_float.rs:28:5 + --> tests/ui/modulo_arithmetic_float.rs:43:5 | LL | b_f32 %= a_f32; | ^^^^^^^^^^^^^^ @@ -57,7 +81,7 @@ LL | b_f32 %= a_f32; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> tests/ui/modulo_arithmetic_float.rs:34:5 + --> tests/ui/modulo_arithmetic_float.rs:49:5 | LL | a_f64 % b_f64; | ^^^^^^^^^^^^^ @@ -65,7 +89,7 @@ LL | a_f64 % b_f64; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> tests/ui/modulo_arithmetic_float.rs:37:5 + --> tests/ui/modulo_arithmetic_float.rs:52:5 | LL | b_f64 % a_f64; | ^^^^^^^^^^^^^ @@ -73,12 +97,36 @@ LL | b_f64 % a_f64; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> tests/ui/modulo_arithmetic_float.rs:40:5 + --> tests/ui/modulo_arithmetic_float.rs:55:5 | LL | b_f64 %= a_f64; | ^^^^^^^^^^^^^^ | = note: double check for expected result especially when interoperating with different languages -error: aborting due to 10 previous errors +error: you are using modulo operator on types that might have different signs + --> tests/ui/modulo_arithmetic_float.rs:61:5 + | +LL | a_f128 % b_f128; + | ^^^^^^^^^^^^^^^ + | + = note: double check for expected result especially when interoperating with different languages + +error: you are using modulo operator on types that might have different signs + --> tests/ui/modulo_arithmetic_float.rs:64:5 + | +LL | b_f128 % a_f128; + | ^^^^^^^^^^^^^^^ + | + = note: double check for expected result especially when interoperating with different languages + +error: you are using modulo operator on types that might have different signs + --> tests/ui/modulo_arithmetic_float.rs:67:5 + | +LL | b_f128 %= a_f128; + | ^^^^^^^^^^^^^^^^ + | + = note: double check for expected result especially when interoperating with different languages + +error: aborting due to 16 previous errors diff --git a/tests/ui/transmute.rs b/tests/ui/transmute.rs index be6e071767d9..46629526367e 100644 --- a/tests/ui/transmute.rs +++ b/tests/ui/transmute.rs @@ -1,3 +1,5 @@ +#![feature(f128)] +#![feature(f16)] #![allow( dead_code, clippy::borrow_as_ptr, @@ -117,20 +119,34 @@ fn int_to_bool() { #[warn(clippy::transmute_int_to_float)] mod int_to_float { fn test() { + let _: f16 = unsafe { std::mem::transmute(0_u16) }; + //~^ ERROR: transmute from a `u16` to a `f16` + //~| NOTE: `-D clippy::transmute-int-to-float` implied by `-D warnings` + let _: f16 = unsafe { std::mem::transmute(0_i16) }; + //~^ ERROR: transmute from a `i16` to a `f16` let _: f32 = unsafe { std::mem::transmute(0_u32) }; //~^ ERROR: transmute from a `u32` to a `f32` - //~| NOTE: `-D clippy::transmute-int-to-float` implied by `-D warnings` let _: f32 = unsafe { std::mem::transmute(0_i32) }; //~^ ERROR: transmute from a `i32` to a `f32` let _: f64 = unsafe { std::mem::transmute(0_u64) }; //~^ ERROR: transmute from a `u64` to a `f64` let _: f64 = unsafe { std::mem::transmute(0_i64) }; //~^ ERROR: transmute from a `i64` to a `f64` + let _: f128 = unsafe { std::mem::transmute(0_u128) }; + //~^ ERROR: transmute from a `u128` to a `f128` + let _: f128 = unsafe { std::mem::transmute(0_i128) }; + //~^ ERROR: transmute from a `i128` to a `f128` } mod issue_5747 { + const VALUE16: f16 = unsafe { std::mem::transmute(0_u16) }; const VALUE32: f32 = unsafe { std::mem::transmute(0_u32) }; const VALUE64: f64 = unsafe { std::mem::transmute(0_i64) }; + const VALUE128: f128 = unsafe { std::mem::transmute(0_i128) }; + + const fn from_bits_16(v: i16) -> f16 { + unsafe { std::mem::transmute(v) } + } const fn from_bits_32(v: i32) -> f32 { unsafe { std::mem::transmute(v) } @@ -139,6 +155,10 @@ mod int_to_float { const fn from_bits_64(v: u64) -> f64 { unsafe { std::mem::transmute(v) } } + + const fn from_bits_128(v: u128) -> f128 { + unsafe { std::mem::transmute(v) } + } } } @@ -158,10 +178,15 @@ mod num_to_bytes { //~^ ERROR: transmute from a `i32` to a `[u8; 4]` let _: [u8; 16] = std::mem::transmute(0i128); //~^ ERROR: transmute from a `i128` to a `[u8; 16]` + + let _: [u8; 2] = std::mem::transmute(0.0f16); + //~^ ERROR: transmute from a `f16` to a `[u8; 2]` let _: [u8; 4] = std::mem::transmute(0.0f32); //~^ ERROR: transmute from a `f32` to a `[u8; 4]` let _: [u8; 8] = std::mem::transmute(0.0f64); //~^ ERROR: transmute from a `f64` to a `[u8; 8]` + let _: [u8; 16] = std::mem::transmute(0.0f128); + //~^ ERROR: transmute from a `f128` to a `[u8; 16]` } } const fn test_const() { @@ -178,8 +203,11 @@ mod num_to_bytes { //~^ ERROR: transmute from a `i32` to a `[u8; 4]` let _: [u8; 16] = std::mem::transmute(0i128); //~^ ERROR: transmute from a `i128` to a `[u8; 16]` + + let _: [u8; 2] = std::mem::transmute(0.0f16); let _: [u8; 4] = std::mem::transmute(0.0f32); let _: [u8; 8] = std::mem::transmute(0.0f64); + let _: [u8; 16] = std::mem::transmute(0.0f128); } } } diff --git a/tests/ui/transmute.stderr b/tests/ui/transmute.stderr index 375e8f19dd6b..0072f62962a7 100644 --- a/tests/ui/transmute.stderr +++ b/tests/ui/transmute.stderr @@ -1,5 +1,5 @@ error: transmute from a reference to a pointer - --> tests/ui/transmute.rs:29:23 + --> tests/ui/transmute.rs:31:23 | LL | let _: *const T = core::intrinsics::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T` @@ -8,61 +8,61 @@ LL | let _: *const T = core::intrinsics::transmute(t); = help: to override `-D warnings` add `#[allow(clippy::useless_transmute)]` error: transmute from a reference to a pointer - --> tests/ui/transmute.rs:33:21 + --> tests/ui/transmute.rs:35:21 | LL | let _: *mut T = core::intrinsics::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *mut T` error: transmute from a reference to a pointer - --> tests/ui/transmute.rs:36:23 + --> tests/ui/transmute.rs:38:23 | LL | let _: *const U = core::intrinsics::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *const U` error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:43:27 + --> tests/ui/transmute.rs:45:27 | LL | let _: Vec = core::intrinsics::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:46:27 + --> tests/ui/transmute.rs:48:27 | LL | let _: Vec = core::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:49:27 + --> tests/ui/transmute.rs:51:27 | LL | let _: Vec = std::intrinsics::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:52:27 + --> tests/ui/transmute.rs:54:27 | LL | let _: Vec = std::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:55:27 + --> tests/ui/transmute.rs:57:27 | LL | let _: Vec = my_transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^ error: transmute from an integer to a pointer - --> tests/ui/transmute.rs:58:31 + --> tests/ui/transmute.rs:60:31 | LL | let _: *const usize = std::mem::transmute(5_isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `5_isize as *const usize` error: transmute from an integer to a pointer - --> tests/ui/transmute.rs:63:31 + --> tests/ui/transmute.rs:65:31 | LL | let _: *const usize = std::mem::transmute(1 + 1usize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(1 + 1usize) as *const usize` error: transmute from a type (`*const Usize`) to the type that it points to (`Usize`) - --> tests/ui/transmute.rs:95:24 + --> tests/ui/transmute.rs:97:24 | LL | let _: Usize = core::intrinsics::transmute(int_const_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -71,25 +71,25 @@ LL | let _: Usize = core::intrinsics::transmute(int_const_ptr); = help: to override `-D warnings` add `#[allow(clippy::crosspointer_transmute)]` error: transmute from a type (`*mut Usize`) to the type that it points to (`Usize`) - --> tests/ui/transmute.rs:99:24 + --> tests/ui/transmute.rs:101:24 | LL | let _: Usize = core::intrinsics::transmute(int_mut_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`Usize`) to a pointer to that type (`*const Usize`) - --> tests/ui/transmute.rs:102:31 + --> tests/ui/transmute.rs:104:31 | LL | let _: *const Usize = core::intrinsics::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize`) - --> tests/ui/transmute.rs:105:29 + --> tests/ui/transmute.rs:107:29 | LL | let _: *mut Usize = core::intrinsics::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a `u8` to a `bool` - --> tests/ui/transmute.rs:112:28 + --> tests/ui/transmute.rs:114:28 | LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `0_u8 != 0` @@ -97,35 +97,59 @@ LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; = note: `-D clippy::transmute-int-to-bool` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_bool)]` -error: transmute from a `u32` to a `f32` - --> tests/ui/transmute.rs:120:31 +error: transmute from a `u16` to a `f16` + --> tests/ui/transmute.rs:122:31 | -LL | let _: f32 = unsafe { std::mem::transmute(0_u32) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_u32)` +LL | let _: f16 = unsafe { std::mem::transmute(0_u16) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f16::from_bits(0_u16)` | = note: `-D clippy::transmute-int-to-float` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_float)]` +error: transmute from a `i16` to a `f16` + --> tests/ui/transmute.rs:125:31 + | +LL | let _: f16 = unsafe { std::mem::transmute(0_i16) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f16::from_bits(0_i16 as u16)` + +error: transmute from a `u32` to a `f32` + --> tests/ui/transmute.rs:127:31 + | +LL | let _: f32 = unsafe { std::mem::transmute(0_u32) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_u32)` + error: transmute from a `i32` to a `f32` - --> tests/ui/transmute.rs:123:31 + --> tests/ui/transmute.rs:129:31 | LL | let _: f32 = unsafe { std::mem::transmute(0_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_i32 as u32)` error: transmute from a `u64` to a `f64` - --> tests/ui/transmute.rs:125:31 + --> tests/ui/transmute.rs:131:31 | LL | let _: f64 = unsafe { std::mem::transmute(0_u64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_u64)` error: transmute from a `i64` to a `f64` - --> tests/ui/transmute.rs:127:31 + --> tests/ui/transmute.rs:133:31 | LL | let _: f64 = unsafe { std::mem::transmute(0_i64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_i64 as u64)` +error: transmute from a `u128` to a `f128` + --> tests/ui/transmute.rs:135:32 + | +LL | let _: f128 = unsafe { std::mem::transmute(0_u128) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f128::from_bits(0_u128)` + +error: transmute from a `i128` to a `f128` + --> tests/ui/transmute.rs:137:32 + | +LL | let _: f128 = unsafe { std::mem::transmute(0_i128) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f128::from_bits(0_i128 as u128)` + error: transmute from a `u8` to a `[u8; 1]` - --> tests/ui/transmute.rs:148:30 + --> tests/ui/transmute.rs:168:30 | LL | let _: [u8; 1] = std::mem::transmute(0u8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u8.to_ne_bytes()` @@ -134,85 +158,97 @@ LL | let _: [u8; 1] = std::mem::transmute(0u8); = help: to override `-D warnings` add `#[allow(clippy::transmute_num_to_bytes)]` error: transmute from a `u32` to a `[u8; 4]` - --> tests/ui/transmute.rs:151:30 + --> tests/ui/transmute.rs:171:30 | LL | let _: [u8; 4] = std::mem::transmute(0u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u32.to_ne_bytes()` error: transmute from a `u128` to a `[u8; 16]` - --> tests/ui/transmute.rs:153:31 + --> tests/ui/transmute.rs:173:31 | LL | let _: [u8; 16] = std::mem::transmute(0u128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u128.to_ne_bytes()` error: transmute from a `i8` to a `[u8; 1]` - --> tests/ui/transmute.rs:155:30 + --> tests/ui/transmute.rs:175:30 | LL | let _: [u8; 1] = std::mem::transmute(0i8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i8.to_ne_bytes()` error: transmute from a `i32` to a `[u8; 4]` - --> tests/ui/transmute.rs:157:30 + --> tests/ui/transmute.rs:177:30 | LL | let _: [u8; 4] = std::mem::transmute(0i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i32.to_ne_bytes()` error: transmute from a `i128` to a `[u8; 16]` - --> tests/ui/transmute.rs:159:31 + --> tests/ui/transmute.rs:179:31 | LL | let _: [u8; 16] = std::mem::transmute(0i128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i128.to_ne_bytes()` +error: transmute from a `f16` to a `[u8; 2]` + --> tests/ui/transmute.rs:182:30 + | +LL | let _: [u8; 2] = std::mem::transmute(0.0f16); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f16.to_ne_bytes()` + error: transmute from a `f32` to a `[u8; 4]` - --> tests/ui/transmute.rs:161:30 + --> tests/ui/transmute.rs:184:30 | LL | let _: [u8; 4] = std::mem::transmute(0.0f32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f32.to_ne_bytes()` error: transmute from a `f64` to a `[u8; 8]` - --> tests/ui/transmute.rs:163:30 + --> tests/ui/transmute.rs:186:30 | LL | let _: [u8; 8] = std::mem::transmute(0.0f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f64.to_ne_bytes()` +error: transmute from a `f128` to a `[u8; 16]` + --> tests/ui/transmute.rs:188:31 + | +LL | let _: [u8; 16] = std::mem::transmute(0.0f128); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f128.to_ne_bytes()` + error: transmute from a `u8` to a `[u8; 1]` - --> tests/ui/transmute.rs:169:30 + --> tests/ui/transmute.rs:194:30 | LL | let _: [u8; 1] = std::mem::transmute(0u8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u8.to_ne_bytes()` error: transmute from a `u32` to a `[u8; 4]` - --> tests/ui/transmute.rs:171:30 + --> tests/ui/transmute.rs:196:30 | LL | let _: [u8; 4] = std::mem::transmute(0u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u32.to_ne_bytes()` error: transmute from a `u128` to a `[u8; 16]` - --> tests/ui/transmute.rs:173:31 + --> tests/ui/transmute.rs:198:31 | LL | let _: [u8; 16] = std::mem::transmute(0u128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u128.to_ne_bytes()` error: transmute from a `i8` to a `[u8; 1]` - --> tests/ui/transmute.rs:175:30 + --> tests/ui/transmute.rs:200:30 | LL | let _: [u8; 1] = std::mem::transmute(0i8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i8.to_ne_bytes()` error: transmute from a `i32` to a `[u8; 4]` - --> tests/ui/transmute.rs:177:30 + --> tests/ui/transmute.rs:202:30 | LL | let _: [u8; 4] = std::mem::transmute(0i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i32.to_ne_bytes()` error: transmute from a `i128` to a `[u8; 16]` - --> tests/ui/transmute.rs:179:31 + --> tests/ui/transmute.rs:204:31 | LL | let _: [u8; 16] = std::mem::transmute(0i128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i128.to_ne_bytes()` error: transmute from a `&[u8]` to a `&str` - --> tests/ui/transmute.rs:190:28 + --> tests/ui/transmute.rs:218:28 | LL | let _: &str = unsafe { std::mem::transmute(B) }; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8(B).unwrap()` @@ -221,16 +257,16 @@ LL | let _: &str = unsafe { std::mem::transmute(B) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_bytes_to_str)]` error: transmute from a `&mut [u8]` to a `&mut str` - --> tests/ui/transmute.rs:193:32 + --> tests/ui/transmute.rs:221:32 | LL | let _: &mut str = unsafe { std::mem::transmute(mb) }; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_mut(mb).unwrap()` error: transmute from a `&[u8]` to a `&str` - --> tests/ui/transmute.rs:195:30 + --> tests/ui/transmute.rs:223:30 | LL | const _: &str = unsafe { std::mem::transmute(B) }; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_unchecked(B)` -error: aborting due to 36 previous errors +error: aborting due to 42 previous errors diff --git a/tests/ui/transmute_float_to_int.fixed b/tests/ui/transmute_float_to_int.fixed index 82d5f7fdca10..4361a7407d11 100644 --- a/tests/ui/transmute_float_to_int.fixed +++ b/tests/ui/transmute_float_to_int.fixed @@ -1,5 +1,7 @@ #![warn(clippy::transmute_float_to_int)] #![allow(clippy::missing_transmute_annotations)] +#![feature(f128)] +#![feature(f16)] fn float_to_int() { let _: u32 = unsafe { 1f32.to_bits() }; @@ -18,8 +20,14 @@ fn float_to_int() { } mod issue_5747 { + const VALUE16: i16 = unsafe { std::mem::transmute(1f16) }; const VALUE32: i32 = unsafe { std::mem::transmute(1f32) }; const VALUE64: u64 = unsafe { std::mem::transmute(1f64) }; + const VALUE128: u128 = unsafe { std::mem::transmute(1f128) }; + + const fn to_bits_16(v: f16) -> u16 { + unsafe { std::mem::transmute(v) } + } const fn to_bits_32(v: f32) -> u32 { unsafe { std::mem::transmute(v) } @@ -28,6 +36,10 @@ mod issue_5747 { const fn to_bits_64(v: f64) -> i64 { unsafe { std::mem::transmute(v) } } + + const fn to_bits_128(v: f128) -> i128 { + unsafe { std::mem::transmute(v) } + } } fn main() {} diff --git a/tests/ui/transmute_float_to_int.rs b/tests/ui/transmute_float_to_int.rs index 9f056330adf9..363ce0bcb16d 100644 --- a/tests/ui/transmute_float_to_int.rs +++ b/tests/ui/transmute_float_to_int.rs @@ -1,5 +1,7 @@ #![warn(clippy::transmute_float_to_int)] #![allow(clippy::missing_transmute_annotations)] +#![feature(f128)] +#![feature(f16)] fn float_to_int() { let _: u32 = unsafe { std::mem::transmute(1f32) }; @@ -18,8 +20,14 @@ fn float_to_int() { } mod issue_5747 { + const VALUE16: i16 = unsafe { std::mem::transmute(1f16) }; const VALUE32: i32 = unsafe { std::mem::transmute(1f32) }; const VALUE64: u64 = unsafe { std::mem::transmute(1f64) }; + const VALUE128: u128 = unsafe { std::mem::transmute(1f128) }; + + const fn to_bits_16(v: f16) -> u16 { + unsafe { std::mem::transmute(v) } + } const fn to_bits_32(v: f32) -> u32 { unsafe { std::mem::transmute(v) } @@ -28,6 +36,10 @@ mod issue_5747 { const fn to_bits_64(v: f64) -> i64 { unsafe { std::mem::transmute(v) } } + + const fn to_bits_128(v: f128) -> i128 { + unsafe { std::mem::transmute(v) } + } } fn main() {} diff --git a/tests/ui/transmute_float_to_int.stderr b/tests/ui/transmute_float_to_int.stderr index ac3aae5f8b78..9cac75f72cdd 100644 --- a/tests/ui/transmute_float_to_int.stderr +++ b/tests/ui/transmute_float_to_int.stderr @@ -1,5 +1,5 @@ error: transmute from a `f32` to a `u32` - --> tests/ui/transmute_float_to_int.rs:5:27 + --> tests/ui/transmute_float_to_int.rs:7:27 | LL | let _: u32 = unsafe { std::mem::transmute(1f32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits()` @@ -8,31 +8,31 @@ LL | let _: u32 = unsafe { std::mem::transmute(1f32) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_float_to_int)]` error: transmute from a `f32` to a `i32` - --> tests/ui/transmute_float_to_int.rs:8:27 + --> tests/ui/transmute_float_to_int.rs:10:27 | LL | let _: i32 = unsafe { std::mem::transmute(1f32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits() as i32` error: transmute from a `f64` to a `u64` - --> tests/ui/transmute_float_to_int.rs:10:27 + --> tests/ui/transmute_float_to_int.rs:12:27 | LL | let _: u64 = unsafe { std::mem::transmute(1f64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits()` error: transmute from a `f64` to a `i64` - --> tests/ui/transmute_float_to_int.rs:12:27 + --> tests/ui/transmute_float_to_int.rs:14:27 | LL | let _: i64 = unsafe { std::mem::transmute(1f64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits() as i64` error: transmute from a `f64` to a `u64` - --> tests/ui/transmute_float_to_int.rs:14:27 + --> tests/ui/transmute_float_to_int.rs:16:27 | LL | let _: u64 = unsafe { std::mem::transmute(1.0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.0f64.to_bits()` error: transmute from a `f64` to a `u64` - --> tests/ui/transmute_float_to_int.rs:16:27 + --> tests/ui/transmute_float_to_int.rs:18:27 | LL | let _: u64 = unsafe { std::mem::transmute(-1.0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-1.0f64).to_bits()` diff --git a/tests/ui/unused_rounding.fixed b/tests/ui/unused_rounding.fixed index 02f970f42a42..7af2c8650a3d 100644 --- a/tests/ui/unused_rounding.fixed +++ b/tests/ui/unused_rounding.fixed @@ -1,3 +1,5 @@ +// FIXME(f16_f128): add tests when math functions are available + #![warn(clippy::unused_rounding)] fn main() { diff --git a/tests/ui/unused_rounding.rs b/tests/ui/unused_rounding.rs index fd14c466f120..1b0b22a9b685 100644 --- a/tests/ui/unused_rounding.rs +++ b/tests/ui/unused_rounding.rs @@ -1,3 +1,5 @@ +// FIXME(f16_f128): add tests when math functions are available + #![warn(clippy::unused_rounding)] fn main() { diff --git a/tests/ui/unused_rounding.stderr b/tests/ui/unused_rounding.stderr index 75ad895012b3..c5ae2da75f84 100644 --- a/tests/ui/unused_rounding.stderr +++ b/tests/ui/unused_rounding.stderr @@ -1,5 +1,5 @@ error: used the `ceil` method with a whole number float - --> tests/ui/unused_rounding.rs:4:13 + --> tests/ui/unused_rounding.rs:6:13 | LL | let _ = 1f32.ceil(); | ^^^^^^^^^^^ help: remove the `ceil` method call: `1f32` @@ -8,25 +8,25 @@ LL | let _ = 1f32.ceil(); = help: to override `-D warnings` add `#[allow(clippy::unused_rounding)]` error: used the `floor` method with a whole number float - --> tests/ui/unused_rounding.rs:5:13 + --> tests/ui/unused_rounding.rs:7:13 | LL | let _ = 1.0f64.floor(); | ^^^^^^^^^^^^^^ help: remove the `floor` method call: `1.0f64` error: used the `round` method with a whole number float - --> tests/ui/unused_rounding.rs:6:13 + --> tests/ui/unused_rounding.rs:8:13 | LL | let _ = 1.00f32.round(); | ^^^^^^^^^^^^^^^ help: remove the `round` method call: `1.00f32` error: used the `round` method with a whole number float - --> tests/ui/unused_rounding.rs:12:13 + --> tests/ui/unused_rounding.rs:14:13 | LL | let _ = 3.0_f32.round(); | ^^^^^^^^^^^^^^^ help: remove the `round` method call: `3.0_f32` error: used the `round` method with a whole number float - --> tests/ui/unused_rounding.rs:14:13 + --> tests/ui/unused_rounding.rs:16:13 | LL | let _ = 3_3.0_0_f32.round(); | ^^^^^^^^^^^^^^^^^^^ help: remove the `round` method call: `3_3.0_0_f32` From e266a5562260c8de07e915d1d8d6d0483bf7be68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 20 Jun 2024 04:25:17 +0000 Subject: [PATCH 1215/1222] Fix `...` in multline code-skips in suggestions When we have long code skips, we write `...` in the line number gutter. For suggestions, we were "centering" the `...` with the line, but that was consistent with what we do in every other case. --- tests/ui/bind_instead_of_map_multipart.stderr | 2 +- tests/ui/needless_collect_indirect.stderr | 2 +- tests/ui/needless_late_init.stderr | 2 +- tests/ui/needless_return.stderr | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ui/bind_instead_of_map_multipart.stderr b/tests/ui/bind_instead_of_map_multipart.stderr index 73255651abea..b15857c325ae 100644 --- a/tests/ui/bind_instead_of_map_multipart.stderr +++ b/tests/ui/bind_instead_of_map_multipart.stderr @@ -62,7 +62,7 @@ LL | } LL | match s.len() { LL ~ 10 => 2, LL | 20 => { - ... +... LL | if foo() { LL ~ return 20; LL | } diff --git a/tests/ui/needless_collect_indirect.stderr b/tests/ui/needless_collect_indirect.stderr index 0cce718a1ac7..f25c02937545 100644 --- a/tests/ui/needless_collect_indirect.stderr +++ b/tests/ui/needless_collect_indirect.stderr @@ -212,7 +212,7 @@ help: check if the original Iterator contains an element instead of collecting t | LL ~ LL | - ... +... LL | // Do lint LL ~ vec.iter().map(|k| k * k).any(|x| x == n); | diff --git a/tests/ui/needless_late_init.stderr b/tests/ui/needless_late_init.stderr index ce64861fa40a..de048091cfbe 100644 --- a/tests/ui/needless_late_init.stderr +++ b/tests/ui/needless_late_init.stderr @@ -215,7 +215,7 @@ help: move the declaration `x` here | LL ~ LL | // types that should be considered insignificant - ... +... LL | let y = Box::new(4); LL ~ let x = SignificantDrop; | diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr index bf5a89d8b75d..b49f199ba5ab 100644 --- a/tests/ui/needless_return.stderr +++ b/tests/ui/needless_return.stderr @@ -518,7 +518,7 @@ help: remove `return` | LL ~ 10 LL | }, - ... +... LL | }, LL ~ } | From ad49fb5428acd4c1e07945db46488ff5760f7dd4 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 20 Jun 2024 19:50:57 -0400 Subject: [PATCH 1216/1222] StaticForeignItem and StaticItem are the same --- clippy_utils/src/ast_utils.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index fb43f7d80aff..785d5ed5dbeb 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -449,13 +449,13 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { use ForeignItemKind::*; match (l, r) { ( - Static(box StaticForeignItem { + Static(box StaticItem { ty: lt, mutability: lm, expr: le, safety: ls, }), - Static(box StaticForeignItem { + Static(box StaticItem { ty: rt, mutability: rm, expr: re, From 73dce1f141e7bf7c0a3fdc91b205656dae84da00 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 23 Jun 2024 18:30:13 -0700 Subject: [PATCH 1217/1222] Rename the 2 unambiguous precedence levels to PREC_UNAMBIGUOUS --- clippy_lints/src/dereference.rs | 6 +++--- clippy_lints/src/matches/manual_utils.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index d60320d82825..f451758c3350 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -6,7 +6,7 @@ use clippy_utils::{ expr_use_ctxt, get_parent_expr, is_block_like, is_lint_allowed, path_to_local, DefinedTy, ExprUseNode, }; use core::mem; -use rustc_ast::util::parser::{PREC_POSTFIX, PREC_PREFIX}; +use rustc_ast::util::parser::{PREC_UNAMBIGUOUS, PREC_PREFIX}; use rustc_data_structures::fx::FxIndexMap; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_ty, Visitor}; @@ -1013,7 +1013,7 @@ fn report<'tcx>( let (precedence, calls_field) = match cx.tcx.parent_hir_node(data.first_expr.hir_id) { Node::Expr(e) => match e.kind { ExprKind::Call(callee, _) if callee.hir_id != data.first_expr.hir_id => (0, false), - ExprKind::Call(..) => (PREC_POSTFIX, matches!(expr.kind, ExprKind::Field(..))), + ExprKind::Call(..) => (PREC_UNAMBIGUOUS, matches!(expr.kind, ExprKind::Field(..))), _ => (e.precedence().order(), false), }, _ => (0, false), @@ -1160,7 +1160,7 @@ impl<'tcx> Dereferencing<'tcx> { }, Some(parent) if !parent.span.from_expansion() => { // Double reference might be needed at this point. - if parent.precedence().order() == PREC_POSTFIX { + if parent.precedence().order() == PREC_UNAMBIGUOUS { // Parentheses would be needed here, don't lint. *outer_pat = None; } else { diff --git a/clippy_lints/src/matches/manual_utils.rs b/clippy_lints/src/matches/manual_utils.rs index 183caab56c59..be80aebed6df 100644 --- a/clippy_lints/src/matches/manual_utils.rs +++ b/clippy_lints/src/matches/manual_utils.rs @@ -7,7 +7,7 @@ use clippy_utils::{ can_move_expr_to_closure, is_else_clause, is_lint_allowed, is_res_lang_ctor, path_res, path_to_local_id, peel_blocks, peel_hir_expr_refs, peel_hir_expr_while, CaptureKind, }; -use rustc_ast::util::parser::PREC_POSTFIX; +use rustc_ast::util::parser::PREC_UNAMBIGUOUS; use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::LangItem::{OptionNone, OptionSome}; @@ -117,7 +117,7 @@ where // it's being passed by value. let scrutinee = peel_hir_expr_refs(scrutinee).0; let (scrutinee_str, _) = snippet_with_context(cx, scrutinee.span, expr_ctxt, "..", &mut app); - let scrutinee_str = if scrutinee.span.eq_ctxt(expr.span) && scrutinee.precedence().order() < PREC_POSTFIX { + let scrutinee_str = if scrutinee.span.eq_ctxt(expr.span) && scrutinee.precedence().order() < PREC_UNAMBIGUOUS { format!("({scrutinee_str})") } else { scrutinee_str.into() From 17bc95da4dc8a30590631b5aa5e1a4978eb30762 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 29 May 2024 23:36:11 +0300 Subject: [PATCH 1218/1222] ast: Standardize visiting order for attributes and node IDs --- tests/ui/cfg_attr_cargo_clippy.stderr | 18 ++++----- tests/ui/tabs_in_doc_comments.stderr | 48 +++++++++++----------- tests/ui/unnecessary_clippy_cfg.stderr | 56 +++++++++++++------------- 3 files changed, 61 insertions(+), 61 deletions(-) diff --git a/tests/ui/cfg_attr_cargo_clippy.stderr b/tests/ui/cfg_attr_cargo_clippy.stderr index ddec0e648d10..0a358f1a6847 100644 --- a/tests/ui/cfg_attr_cargo_clippy.stderr +++ b/tests/ui/cfg_attr_cargo_clippy.stderr @@ -1,12 +1,18 @@ error: `feature = "cargo-clippy"` was replaced by `clippy` - --> tests/ui/cfg_attr_cargo_clippy.rs:5:12 + --> tests/ui/cfg_attr_cargo_clippy.rs:3:13 | -LL | #[cfg_attr(feature = "cargo-clippy", derive(Debug))] - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy` +LL | #![cfg_attr(feature = "cargo-clippy", doc = "a")] + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy` | = note: `-D clippy::deprecated-clippy-cfg-attr` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::deprecated_clippy_cfg_attr)]` +error: `feature = "cargo-clippy"` was replaced by `clippy` + --> tests/ui/cfg_attr_cargo_clippy.rs:5:12 + | +LL | #[cfg_attr(feature = "cargo-clippy", derive(Debug))] + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy` + error: `feature = "cargo-clippy"` was replaced by `clippy` --> tests/ui/cfg_attr_cargo_clippy.rs:6:16 | @@ -37,11 +43,5 @@ error: `feature = "cargo-clippy"` was replaced by `clippy` LL | #[cfg(all(feature = "cargo-clippy"))] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy` -error: `feature = "cargo-clippy"` was replaced by `clippy` - --> tests/ui/cfg_attr_cargo_clippy.rs:3:13 - | -LL | #![cfg_attr(feature = "cargo-clippy", doc = "a")] - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy` - error: aborting due to 7 previous errors diff --git a/tests/ui/tabs_in_doc_comments.stderr b/tests/ui/tabs_in_doc_comments.stderr index 23d5dcd3a8da..aef6c3914526 100644 --- a/tests/ui/tabs_in_doc_comments.stderr +++ b/tests/ui/tabs_in_doc_comments.stderr @@ -1,53 +1,53 @@ error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:10:9 + --> tests/ui/tabs_in_doc_comments.rs:6:5 | -LL | /// - First String: - | ^^^^ help: consider using four spaces per tab +LL | /// - first one + | ^^^^ help: consider using four spaces per tab | = note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::tabs_in_doc_comments)]` error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:11:9 + --> tests/ui/tabs_in_doc_comments.rs:6:13 | -LL | /// - needs to be inside here - | ^^^^^^^^ help: consider using four spaces per tab +LL | /// - first one + | ^^^^^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:14:9 + --> tests/ui/tabs_in_doc_comments.rs:7:5 | -LL | /// - Second String: - | ^^^^ help: consider using four spaces per tab +LL | /// - second one + | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:15:9 + --> tests/ui/tabs_in_doc_comments.rs:7:14 | -LL | /// - needs to be inside here - | ^^^^^^^^ help: consider using four spaces per tab +LL | /// - second one + | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:6:5 + --> tests/ui/tabs_in_doc_comments.rs:10:9 | -LL | /// - first one - | ^^^^ help: consider using four spaces per tab +LL | /// - First String: + | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:6:13 + --> tests/ui/tabs_in_doc_comments.rs:11:9 | -LL | /// - first one - | ^^^^^^^^ help: consider using four spaces per tab +LL | /// - needs to be inside here + | ^^^^^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:7:5 + --> tests/ui/tabs_in_doc_comments.rs:14:9 | -LL | /// - second one - | ^^^^ help: consider using four spaces per tab +LL | /// - Second String: + | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:7:14 + --> tests/ui/tabs_in_doc_comments.rs:15:9 | -LL | /// - second one - | ^^^^ help: consider using four spaces per tab +LL | /// - needs to be inside here + | ^^^^^^^^ help: consider using four spaces per tab error: aborting due to 8 previous errors diff --git a/tests/ui/unnecessary_clippy_cfg.stderr b/tests/ui/unnecessary_clippy_cfg.stderr index 16a861652956..01f842a657de 100644 --- a/tests/ui/unnecessary_clippy_cfg.stderr +++ b/tests/ui/unnecessary_clippy_cfg.stderr @@ -1,61 +1,61 @@ error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:13:1 + --> tests/ui/unnecessary_clippy_cfg.rs:4:1 | -LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#[deny(clippy::non_minimal_cfg)]` +LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#![deny(clippy::non_minimal_cfg)]` | = note: `-D clippy::unnecessary-clippy-cfg` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::unnecessary_clippy_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:15:36 + --> tests/ui/unnecessary_clippy_cfg.rs:6:37 | -LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ | - = note: write instead: `#[deny(clippy::non_minimal_cfg)]` + = note: write instead: `#![deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:17:36 + --> tests/ui/unnecessary_clippy_cfg.rs:8:37 | -LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ | - = note: write instead: `#[deny(clippy::non_minimal_cfg)]` + = note: write instead: `#![deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:19:1 + --> tests/ui/unnecessary_clippy_cfg.rs:10:1 | -LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#[deny(clippy::non_minimal_cfg)]` +LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#![deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:4:1 + --> tests/ui/unnecessary_clippy_cfg.rs:13:1 | -LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#![deny(clippy::non_minimal_cfg)]` +LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#[deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:6:37 + --> tests/ui/unnecessary_clippy_cfg.rs:15:36 | -LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ | - = note: write instead: `#![deny(clippy::non_minimal_cfg)]` + = note: write instead: `#[deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:8:37 + --> tests/ui/unnecessary_clippy_cfg.rs:17:36 | -LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ | - = note: write instead: `#![deny(clippy::non_minimal_cfg)]` + = note: write instead: `#[deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:10:1 + --> tests/ui/unnecessary_clippy_cfg.rs:19:1 | -LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#![deny(clippy::non_minimal_cfg)]` +LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#[deny(clippy::non_minimal_cfg)]` error: duplicated attribute --> tests/ui/unnecessary_clippy_cfg.rs:8:26 From d892d97b4e31f9c21ade927c80e963cd06fe16fc Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 21 Jun 2024 13:33:08 -0400 Subject: [PATCH 1219/1222] Split out IntoIterator and non-Iterator constructors for AliasTy/AliasTerm/TraitRef/projection --- clippy_lints/src/bool_assert_comparison.rs | 2 +- clippy_lints/src/methods/needless_collect.rs | 4 ++-- clippy_lints/src/redundant_slicing.rs | 2 +- clippy_utils/src/ty.rs | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/bool_assert_comparison.rs b/clippy_lints/src/bool_assert_comparison.rs index 58c1a2f27062..db5792188dd4 100644 --- a/clippy_lints/src/bool_assert_comparison.rs +++ b/clippy_lints/src/bool_assert_comparison.rs @@ -61,7 +61,7 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) - ) }) .map_or(false, |assoc_item| { - let proj = Ty::new_projection(cx.tcx, assoc_item.def_id, cx.tcx.mk_args_trait(ty, [])); + let proj = Ty::new_projection_from_args(cx.tcx, assoc_item.def_id, cx.tcx.mk_args_trait(ty, [])); let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj); nty.is_bool() diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index f26f164fa54a..46b457daf707 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -206,7 +206,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty: && let Some(into_iter_item_proj) = make_projection(cx.tcx, into_iter_trait, sym::Item, [collect_ty]) && let Ok(into_iter_item_ty) = cx.tcx.try_normalize_erasing_regions( cx.param_env, - Ty::new_projection(cx.tcx, into_iter_item_proj.def_id, into_iter_item_proj.args), + Ty::new_projection_from_args(cx.tcx, into_iter_item_proj.def_id, into_iter_item_proj.args), ) { iter_item_ty == into_iter_item_ty @@ -235,7 +235,7 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) - iter_trait, ) && let args = cx.tcx.mk_args(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))]) - && let proj_ty = Ty::new_projection(cx.tcx, iter_item.def_id, args) + && let proj_ty = Ty::new_projection_from_args(cx.tcx, iter_item.def_id, args) && let Ok(item_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, proj_ty) { item_ty == EarlyBinder::bind(search_ty).instantiate(cx.tcx, cx.typeck_results().node_args(call_id)) diff --git a/clippy_lints/src/redundant_slicing.rs b/clippy_lints/src/redundant_slicing.rs index 7f87d18e5023..82f22ad693d7 100644 --- a/clippy_lints/src/redundant_slicing.rs +++ b/clippy_lints/src/redundant_slicing.rs @@ -133,7 +133,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing { } else if let Some(target_id) = cx.tcx.lang_items().deref_target() { if let Ok(deref_ty) = cx.tcx.try_normalize_erasing_regions( cx.param_env, - Ty::new_projection(cx.tcx, target_id, cx.tcx.mk_args(&[GenericArg::from(indexed_ty)])), + Ty::new_projection_from_args(cx.tcx, target_id, cx.tcx.mk_args(&[GenericArg::from(indexed_ty)])), ) { if deref_ty == expr_ty { let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0; diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 7d4332a3d9de..3790a852f7ed 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -292,7 +292,7 @@ pub fn implements_trait_with_env_from_iter<'tcx>( let trait_ref = TraitRef::new( tcx, trait_id, - Some(GenericArg::from(ty)).into_iter().chain(args).chain(effect_arg), + [GenericArg::from(ty)].into_iter().chain(args).chain(effect_arg), ); debug_assert_matches!( @@ -1126,7 +1126,7 @@ pub fn make_projection<'tcx>( #[cfg(debug_assertions)] assert_generic_args_match(tcx, assoc_item.def_id, args); - Some(AliasTy::new(tcx, assoc_item.def_id, args)) + Some(AliasTy::new_from_args(tcx, assoc_item.def_id, args)) } helper( tcx, @@ -1165,7 +1165,7 @@ pub fn make_normalized_projection<'tcx>( ); return None; } - match tcx.try_normalize_erasing_regions(param_env, Ty::new_projection(tcx, ty.def_id, ty.args)) { + match tcx.try_normalize_erasing_regions(param_env, Ty::new_projection_from_args(tcx, ty.def_id, ty.args)) { Ok(ty) => Some(ty), Err(e) => { debug_assert!(false, "failed to normalize type `{ty}`: {e:#?}"); @@ -1289,7 +1289,7 @@ pub fn make_normalized_projection_with_regions<'tcx>( .infer_ctxt() .build() .at(&cause, param_env) - .query_normalize(Ty::new_projection(tcx, ty.def_id, ty.args)) + .query_normalize(Ty::new_projection_from_args(tcx, ty.def_id, ty.args)) { Ok(ty) => Some(ty.value), Err(e) => { From 306dbaca48244ea457826f08dfd6fceacaa91d9a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 21 Jun 2024 13:55:21 -0400 Subject: [PATCH 1220/1222] Replace Deref bounds on Interner in favor of a SliceLike trait --- clippy_lints/src/needless_borrows_for_generic_args.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/needless_borrows_for_generic_args.rs b/clippy_lints/src/needless_borrows_for_generic_args.rs index 4f99eaa40c29..f4846a1753f7 100644 --- a/clippy_lints/src/needless_borrows_for_generic_args.rs +++ b/clippy_lints/src/needless_borrows_for_generic_args.rs @@ -267,7 +267,7 @@ fn needless_borrow_count<'tcx>( return false; } - let predicate = EarlyBinder::bind(predicate).instantiate(cx.tcx, &args_with_referent_ty); + let predicate = EarlyBinder::bind(predicate).instantiate(cx.tcx, &args_with_referent_ty[..]); let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate); let infcx = cx.tcx.infer_ctxt().build(); infcx.predicate_must_hold_modulo_regions(&obligation) From 880a8327bac0ad474ffd7b937d2b8c0ba3f01ad1 Mon Sep 17 00:00:00 2001 From: xFrednet Date: Sat, 10 Feb 2024 22:31:36 +0000 Subject: [PATCH 1221/1222] RFC 2383: Stabilize `lint_reasons` in Clippy :paperclips: --- CHANGELOG.md | 2 +- book/src/lint_configuration.md | 2 + clippy_config/src/conf.rs | 2 +- clippy_config/src/msrvs.rs | 1 + clippy_lints/src/allow_attributes.rs | 74 ------------ clippy_lints/src/attrs/allow_attributes.rs | 26 +++++ .../attrs/allow_attributes_without_reason.rs | 5 - clippy_lints/src/attrs/mod.rs | 71 ++++++++++-- clippy_lints/src/declared_lints.rs | 2 +- clippy_lints/src/lib.rs | 6 +- clippy_utils/src/lib.rs | 2 +- src/driver.rs | 2 +- tests/ui-cargo/duplicate_mod/fail/src/main.rs | 1 - .../default/test.stderr | 11 +- .../undocumented_unsafe_blocks.default.stderr | 74 ++++++------ ...undocumented_unsafe_blocks.disabled.stderr | 94 ++++++++-------- .../undocumented_unsafe_blocks.rs | 1 - tests/ui/allow_attributes.fixed | 13 ++- tests/ui/allow_attributes.rs | 13 ++- tests/ui/allow_attributes.stderr | 20 +++- tests/ui/allow_attributes_without_reason.rs | 13 ++- .../ui/allow_attributes_without_reason.stderr | 29 ++++- tests/ui/async_yields_async.fixed | 1 - tests/ui/async_yields_async.rs | 1 - tests/ui/async_yields_async.stderr | 12 +- tests/ui/boxed_local.rs | 1 - tests/ui/boxed_local.stderr | 8 +- .../ui/checked_unwrap/simple_conditionals.rs | 1 - .../checked_unwrap/simple_conditionals.stderr | 54 ++++----- tests/ui/default_numeric_fallback_i32.fixed | 1 - tests/ui/default_numeric_fallback_i32.rs | 1 - tests/ui/default_numeric_fallback_i32.stderr | 56 ++++----- tests/ui/derive_partial_eq_without_eq.fixed | 1 - tests/ui/derive_partial_eq_without_eq.rs | 1 - tests/ui/derive_partial_eq_without_eq.stderr | 26 ++--- tests/ui/expect_tool_lint_rfc_2383.rs | 1 - tests/ui/expect_tool_lint_rfc_2383.stderr | 12 +- tests/ui/implicit_return.fixed | 1 - tests/ui/implicit_return.rs | 1 - tests/ui/implicit_return.stderr | 32 +++--- tests/ui/let_unit.fixed | 1 - tests/ui/let_unit.rs | 1 - tests/ui/let_unit.stderr | 8 +- tests/ui/macro_use_imports.fixed | 1 - tests/ui/macro_use_imports.rs | 1 - tests/ui/macro_use_imports.stderr | 8 +- tests/ui/macro_use_imports_expect.rs | 1 - tests/ui/manual_non_exhaustive_enum.rs | 1 - tests/ui/manual_non_exhaustive_enum.stderr | 8 +- tests/ui/needless_borrow.fixed | 1 - tests/ui/needless_borrow.rs | 1 - tests/ui/needless_borrow.stderr | 56 ++++----- tests/ui/needless_pass_by_ref_mut.rs | 1 - tests/ui/needless_pass_by_ref_mut.stderr | 68 +++++------ tests/ui/needless_return.fixed | 1 - tests/ui/needless_return.rs | 1 - tests/ui/needless_return.stderr | 106 +++++++++--------- tests/ui/nonminimal_bool.rs | 2 - tests/ui/nonminimal_bool.stderr | 58 +++++----- tests/ui/overly_complex_bool_expr.fixed | 1 - tests/ui/overly_complex_bool_expr.rs | 1 - tests/ui/overly_complex_bool_expr.stderr | 20 ++-- tests/ui/ptr_arg.rs | 1 - tests/ui/ptr_arg.stderr | 48 ++++---- tests/ui/redundant_clone.fixed | 1 - tests/ui/redundant_clone.rs | 1 - tests/ui/redundant_clone.stderr | 60 +++++----- tests/ui/ref_binding_to_reference.rs | 1 - tests/ui/ref_binding_to_reference.stderr | 14 +-- tests/ui/same_name_method.rs | 1 - tests/ui/same_name_method.stderr | 24 ++-- tests/ui/unsafe_derive_deserialize.rs | 1 - tests/ui/unsafe_derive_deserialize.stderr | 8 +- tests/ui/used_underscore_binding.rs | 2 +- 74 files changed, 611 insertions(+), 573 deletions(-) delete mode 100644 clippy_lints/src/allow_attributes.rs create mode 100644 clippy_lints/src/attrs/allow_attributes.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index d7bcd7a19687..d1cd87473cef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1943,7 +1943,7 @@ Released 2022-05-19 [#8218](https://github.com/rust-lang/rust-clippy/pull/8218) * [`needless_match`] [#8471](https://github.com/rust-lang/rust-clippy/pull/8471) -* [`allow_attributes_without_reason`] (Requires `#![feature(lint_reasons)]`) +* [`allow_attributes_without_reason`] [#8504](https://github.com/rust-lang/rust-clippy/pull/8504) * [`print_in_format_impl`] [#8253](https://github.com/rust-lang/rust-clippy/pull/8253) diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index c8223007df7b..6dad3463aa47 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -669,6 +669,8 @@ The minimum rust version that the project supports. Defaults to the `rust-versio --- **Affected lints:** +* [`allow_attributes`](https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes) +* [`allow_attributes_without_reason`](https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes_without_reason) * [`almost_complete_range`](https://rust-lang.github.io/rust-clippy/master/index.html#almost_complete_range) * [`approx_constant`](https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant) * [`assigning_clones`](https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones) diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index cfdf620b7d07..279193e516e9 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -265,7 +265,7 @@ define_Conf! { /// /// Suppress lints whenever the suggested change would cause breakage for other crates. (avoid_breaking_exported_api: bool = true), - /// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, OPTION_MAP_UNWRAP_OR, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP, MANUAL_LET_ELSE, UNCHECKED_DURATION_SUBTRACTION, COLLAPSIBLE_STR_REPLACE, SEEK_FROM_CURRENT, SEEK_REWIND, UNNECESSARY_LAZY_EVALUATIONS, TRANSMUTE_PTR_TO_REF, ALMOST_COMPLETE_RANGE, NEEDLESS_BORROW, DERIVABLE_IMPLS, MANUAL_IS_ASCII_CHECK, MANUAL_REM_EUCLID, MANUAL_RETAIN, TYPE_REPETITION_IN_BOUNDS, TUPLE_ARRAY_CONVERSIONS, MANUAL_TRY_FOLD, MANUAL_HASH_ONE, ITER_KV_MAP, MANUAL_C_STR_LITERALS, ASSIGNING_CLONES, LEGACY_NUMERIC_CONSTANTS. + /// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, OPTION_MAP_UNWRAP_OR, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP, MANUAL_LET_ELSE, UNCHECKED_DURATION_SUBTRACTION, COLLAPSIBLE_STR_REPLACE, SEEK_FROM_CURRENT, SEEK_REWIND, UNNECESSARY_LAZY_EVALUATIONS, TRANSMUTE_PTR_TO_REF, ALMOST_COMPLETE_RANGE, NEEDLESS_BORROW, DERIVABLE_IMPLS, MANUAL_IS_ASCII_CHECK, MANUAL_REM_EUCLID, MANUAL_RETAIN, TYPE_REPETITION_IN_BOUNDS, TUPLE_ARRAY_CONVERSIONS, MANUAL_TRY_FOLD, MANUAL_HASH_ONE, ITER_KV_MAP, MANUAL_C_STR_LITERALS, ASSIGNING_CLONES, LEGACY_NUMERIC_CONSTANTS, ALLOW_ATTRIBUTES, ALLOW_ATTRIBUTES_WITHOUT_REASON. /// /// The minimum rust version that the project supports. Defaults to the `rust-version` field in `Cargo.toml` #[default_text = ""] diff --git a/clippy_config/src/msrvs.rs b/clippy_config/src/msrvs.rs index a3e7d0c3fa5f..8bdb5b317e5d 100644 --- a/clippy_config/src/msrvs.rs +++ b/clippy_config/src/msrvs.rs @@ -17,6 +17,7 @@ macro_rules! msrv_aliases { // names may refer to stabilized feature flags or library items msrv_aliases! { + 1,81,0 { LINT_REASONS_STABILIZATION } 1,77,0 { C_STR_LITERALS } 1,76,0 { PTR_FROM_REF } 1,71,0 { TUPLE_ARRAY_CONVERSIONS, BUILD_HASHER_HASH_ONE } diff --git a/clippy_lints/src/allow_attributes.rs b/clippy_lints/src/allow_attributes.rs deleted file mode 100644 index 123d0e51eeee..000000000000 --- a/clippy_lints/src/allow_attributes.rs +++ /dev/null @@ -1,74 +0,0 @@ -use ast::{AttrStyle, Attribute}; -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::is_from_proc_macro; -use rustc_ast as ast; -use rustc_errors::Applicability; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_session::declare_lint_pass; - -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of the `#[allow]` attribute and suggests replacing it with - /// the `#[expect]` (See [RFC 2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html)) - /// - /// The expect attribute is still unstable and requires the `lint_reasons` - /// on nightly. It can be enabled by adding `#![feature(lint_reasons)]` to - /// the crate root. - /// - /// This lint only warns outer attributes (`#[allow]`), as inner attributes - /// (`#![allow]`) are usually used to enable or disable lints on a global scale. - /// - /// ### Why restrict this? - /// `#[allow]` attributes can linger after their reason for existence is gone. - /// `#[expect]` attributes suppress the lint emission, but emit a warning if - /// the expectation is unfulfilled. This can be useful to be notified when the - /// lint is no longer triggered, which may indicate the attribute can be removed. - /// - /// ### Example - /// ```rust,ignore - /// #[allow(unused_mut)] - /// fn foo() -> usize { - /// let mut a = Vec::new(); - /// a.len() - /// } - /// ``` - /// Use instead: - /// ```rust,ignore - /// #![feature(lint_reasons)] - /// #[expect(unused_mut)] - /// fn foo() -> usize { - /// let mut a = Vec::new(); - /// a.len() - /// } - /// ``` - #[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." -} - -declare_lint_pass!(AllowAttribute => [ALLOW_ATTRIBUTES]); - -impl LateLintPass<'_> for AllowAttribute { - // Separate each crate's features. - fn check_attribute<'cx>(&mut self, cx: &LateContext<'cx>, attr: &'cx Attribute) { - if !in_external_macro(cx.sess(), attr.span) - && cx.tcx.features().lint_reasons - && let AttrStyle::Outer = attr.style - && let Some(ident) = attr.ident() - && ident.name == rustc_span::symbol::sym::allow - && !is_from_proc_macro(cx, &attr) - { - span_lint_and_sugg( - cx, - ALLOW_ATTRIBUTES, - ident.span, - "#[allow] attribute found", - "replace it with", - "expect".into(), - Applicability::MachineApplicable, - ); - } - } -} diff --git a/clippy_lints/src/attrs/allow_attributes.rs b/clippy_lints/src/attrs/allow_attributes.rs new file mode 100644 index 000000000000..c5b6980b0b90 --- /dev/null +++ b/clippy_lints/src/attrs/allow_attributes.rs @@ -0,0 +1,26 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::is_from_proc_macro; +use rustc_ast::{AttrStyle, Attribute}; +use rustc_errors::Applicability; +use rustc_lint::{LateContext, LintContext}; +use rustc_middle::lint::in_external_macro; +use super::ALLOW_ATTRIBUTES; + +// Separate each crate's features. +pub fn check<'cx>(cx: &LateContext<'cx>, attr: &'cx Attribute) { + if !in_external_macro(cx.sess(), attr.span) + && let AttrStyle::Outer = attr.style + && let Some(ident) = attr.ident() + && !is_from_proc_macro(cx, &attr) + { + span_lint_and_sugg( + cx, + ALLOW_ATTRIBUTES, + ident.span, + "#[allow] attribute found", + "replace it with", + "expect".into(), + Applicability::MachineApplicable, + ); + } +} diff --git a/clippy_lints/src/attrs/allow_attributes_without_reason.rs b/clippy_lints/src/attrs/allow_attributes_without_reason.rs index 4a22e17463fc..8bf985a36c7a 100644 --- a/clippy_lints/src/attrs/allow_attributes_without_reason.rs +++ b/clippy_lints/src/attrs/allow_attributes_without_reason.rs @@ -8,11 +8,6 @@ use rustc_span::sym; use rustc_span::symbol::Symbol; pub(super) fn check<'cx>(cx: &LateContext<'cx>, name: Symbol, items: &[NestedMetaItem], attr: &'cx Attribute) { - // Check for the feature - if !cx.tcx.features().lint_reasons { - return; - } - // Check if the reason is present if let Some(item) = items.last().and_then(NestedMetaItem::meta_item) && let MetaItemKind::NameValue(_) = &item.kind diff --git a/clippy_lints/src/attrs/mod.rs b/clippy_lints/src/attrs/mod.rs index e4c98a32fd67..da19f17998af 100644 --- a/clippy_lints/src/attrs/mod.rs +++ b/clippy_lints/src/attrs/mod.rs @@ -1,6 +1,7 @@ //! checks for attributes mod allow_attributes_without_reason; +mod allow_attributes; mod blanket_clippy_restriction_lints; mod deprecated_cfg_attr; mod deprecated_semver; @@ -14,11 +15,11 @@ mod unnecessary_clippy_cfg; mod useless_attribute; mod utils; -use clippy_config::msrvs::Msrv; +use clippy_config::msrvs::{self, Msrv}; use rustc_ast::{Attribute, MetaItemKind, NestedMetaItem}; use rustc_hir::{ImplItem, Item, ItemKind, TraitItem}; use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, impl_lint_pass}; +use rustc_session::impl_lint_pass; use rustc_span::sym; use utils::{is_lint_level, is_relevant_impl, is_relevant_item, is_relevant_trait}; @@ -272,23 +273,17 @@ declare_clippy_lint! { /// ### What it does /// Checks for attributes that allow lints without a reason. /// - /// (This requires the `lint_reasons` feature) - /// /// ### Why restrict this? /// Justifying each `allow` helps readers understand the reasoning, /// and may allow removing `allow` attributes if their purpose is obsolete. /// /// ### Example /// ```no_run - /// #![feature(lint_reasons)] - /// /// #![allow(clippy::some_lint)] /// ``` /// /// Use instead: /// ```no_run - /// #![feature(lint_reasons)] - /// /// #![allow(clippy::some_lint, reason = "False positive rust-lang/rust-clippy#1002020")] /// ``` #[clippy::version = "1.61.0"] @@ -297,6 +292,41 @@ declare_clippy_lint! { "ensures that all `allow` and `expect` attributes have a reason" } +declare_clippy_lint! { + /// ### What it does + /// Checks for usage of the `#[allow]` attribute and suggests replacing it with + /// the `#[expect]` (See [RFC 2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html)) + /// + /// This lint only warns outer attributes (`#[allow]`), as inner attributes + /// (`#![allow]`) are usually used to enable or disable lints on a global scale. + /// + /// ### Why is this bad? + /// `#[expect]` attributes suppress the lint emission, but emit a warning, if + /// the expectation is unfulfilled. This can be useful to be notified when the + /// lint is no longer triggered. + /// + /// ### Example + /// ```rust,ignore + /// #[allow(unused_mut)] + /// fn foo() -> usize { + /// let mut a = Vec::new(); + /// a.len() + /// } + /// ``` + /// Use instead: + /// ```rust,ignore + /// #[expect(unused_mut)] + /// fn foo() -> usize { + /// let mut a = Vec::new(); + /// a.len() + /// } + /// ``` + #[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." +} + declare_clippy_lint! { /// ### What it does /// Checks for `#[should_panic]` attributes without specifying the expected panic message. @@ -469,7 +499,12 @@ declare_clippy_lint! { "duplicated attribute" } -declare_lint_pass!(Attributes => [ +#[derive(Clone)] +pub struct Attributes { + msrv: Msrv, +} + +impl_lint_pass!(Attributes => [ ALLOW_ATTRIBUTES_WITHOUT_REASON, INLINE_ALWAYS, DEPRECATED_SEMVER, @@ -480,6 +515,13 @@ declare_lint_pass!(Attributes => [ DUPLICATED_ATTRIBUTES, ]); +impl Attributes { + #[must_use] + pub fn new(msrv: Msrv) -> Self { + Self { msrv } + } +} + impl<'tcx> LateLintPass<'tcx> for Attributes { fn check_crate(&mut self, cx: &LateContext<'tcx>) { blanket_clippy_restriction_lints::check_command_line(cx); @@ -492,8 +534,15 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { if is_lint_level(ident.name, attr.id) { blanket_clippy_restriction_lints::check(cx, ident.name, items); } + if matches!(ident.name, sym::allow) { + if self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) { + allow_attributes::check(cx, attr); + } + } if matches!(ident.name, sym::allow | sym::expect) { - allow_attributes_without_reason::check(cx, ident.name, items, attr); + if self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) { + allow_attributes_without_reason::check(cx, ident.name, items, attr); + } } if items.is_empty() || !attr.has_name(sym::deprecated) { return; @@ -537,6 +586,8 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id())); } } + + extract_msrv_attr!(LateContext); } pub struct EarlyAttributes { diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 7e43a99e9f24..76a0e450e59a 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -38,7 +38,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ #[cfg(feature = "internal")] crate::utils::internal_lints::unsorted_clippy_utils_paths::UNSORTED_CLIPPY_UTILS_PATHS_INFO, crate::absolute_paths::ABSOLUTE_PATHS_INFO, - crate::allow_attributes::ALLOW_ATTRIBUTES_INFO, crate::almost_complete_range::ALMOST_COMPLETE_RANGE_INFO, crate::approx_const::APPROX_CONSTANT_INFO, crate::arc_with_non_send_sync::ARC_WITH_NON_SEND_SYNC_INFO, @@ -49,6 +48,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::assertions_on_result_states::ASSERTIONS_ON_RESULT_STATES_INFO, crate::assigning_clones::ASSIGNING_CLONES_INFO, crate::async_yields_async::ASYNC_YIELDS_ASYNC_INFO, + crate::attrs::ALLOW_ATTRIBUTES_INFO, crate::attrs::ALLOW_ATTRIBUTES_WITHOUT_REASON_INFO, crate::attrs::BLANKET_CLIPPY_RESTRICTION_LINTS_INFO, crate::attrs::DEPRECATED_CFG_ATTR_INFO, diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index ef322786dbcd..63461c14d779 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -6,7 +6,7 @@ #![feature(if_let_guard)] #![feature(iter_intersperse)] #![feature(let_chains)] -#![feature(lint_reasons)] +#![cfg_attr(bootstrap, feature(lint_reasons))] #![feature(never_type)] #![feature(rustc_private)] #![feature(stmt_expr_attributes)] @@ -73,7 +73,6 @@ mod renamed_lints; // begin lints modules, do not remove this comment, it’s used in `update_lints` mod absolute_paths; -mod allow_attributes; mod almost_complete_range; mod approx_const; mod arc_with_non_send_sync; @@ -699,7 +698,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(|_| Box::new(mut_reference::UnnecessaryMutPassed)); store.register_late_pass(|_| Box::>::default()); store.register_late_pass(|_| Box::new(len_zero::LenZero)); - store.register_late_pass(|_| Box::new(attrs::Attributes)); + store.register_late_pass(move |_| Box::new(attrs::Attributes::new(msrv()))); store.register_late_pass(|_| Box::new(blocks_in_conditions::BlocksInConditions)); store.register_late_pass(|_| Box::new(unicode::Unicode)); store.register_late_pass(|_| Box::new(uninit_vec::UninitVec)); @@ -1065,7 +1064,6 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(|_| Box::new(needless_maybe_sized::NeedlessMaybeSized)); store.register_late_pass(|_| Box::new(redundant_async_block::RedundantAsyncBlock)); store.register_late_pass(|_| Box::new(let_with_type_underscore::UnderscoreTyped)); - store.register_late_pass(|_| Box::new(allow_attributes::AllowAttribute)); store.register_late_pass(move |_| Box::new(manual_main_separator_str::ManualMainSeparatorStr::new(msrv()))); store.register_late_pass(|_| Box::new(unnecessary_struct_initialization::UnnecessaryStruct)); store.register_late_pass(move |_| { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 6848e8e5c304..ee43d95272a0 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -5,7 +5,7 @@ #![feature(f16)] #![feature(if_let_guard)] #![feature(let_chains)] -#![feature(lint_reasons)] +#![cfg_attr(bootstrap, feature(lint_reasons))] #![feature(never_type)] #![feature(rustc_private)] #![feature(assert_matches)] diff --git a/src/driver.rs b/src/driver.rs index 6117e76897f2..9b1577f24b8e 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -2,7 +2,7 @@ #![allow(rustc::untranslatable_diagnostic)] #![feature(rustc_private)] #![feature(let_chains)] -#![feature(lint_reasons)] +#![cfg_attr(bootstrap, feature(lint_reasons))] #![cfg_attr(feature = "deny-warnings", deny(warnings))] // warn on lints, that are included in `rust-lang/rust`s bootstrap #![warn(rust_2018_idioms, unused_lifetimes)] diff --git a/tests/ui-cargo/duplicate_mod/fail/src/main.rs b/tests/ui-cargo/duplicate_mod/fail/src/main.rs index 6478e65ac81a..a99fe2e12bb2 100644 --- a/tests/ui-cargo/duplicate_mod/fail/src/main.rs +++ b/tests/ui-cargo/duplicate_mod/fail/src/main.rs @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] mod a; diff --git a/tests/ui-toml/macro_metavars_in_unsafe/default/test.stderr b/tests/ui-toml/macro_metavars_in_unsafe/default/test.stderr index d6b97f6fde1e..138eb6029494 100644 --- a/tests/ui-toml/macro_metavars_in_unsafe/default/test.stderr +++ b/tests/ui-toml/macro_metavars_in_unsafe/default/test.stderr @@ -1,3 +1,12 @@ +error: the feature `lint_reasons` has been stable since 1.81.0-dev and no longer requires an attribute to enable + --> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:2:24 + | +LL | #![feature(decl_macro, lint_reasons)] + | ^^^^^^^^^^^^ + | + = note: `-D stable-features` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(stable_features)]` + error: this macro expands metavariables in an unsafe block --> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:19:9 | @@ -183,5 +192,5 @@ LL | | } = help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable = help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite -error: aborting due to 14 previous errors +error: aborting due to 15 previous errors diff --git a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr index 37d690557370..a44c810b1350 100644 --- a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr +++ b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr @@ -1,5 +1,5 @@ error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:271:19 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:270:19 | LL | /* Safety: */ unsafe {} | ^^^^^^^^^ @@ -9,7 +9,7 @@ LL | /* Safety: */ unsafe {} = help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]` error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:275:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:274:5 | LL | unsafe {} | ^^^^^^^^^ @@ -17,7 +17,7 @@ LL | unsafe {} = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:279:14 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:278:14 | LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; | ^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:279:29 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:278:29 | LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; | ^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:279:48 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:278:48 | LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; | ^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:283:18 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:282:18 | LL | let _ = (42, unsafe {}, "test", unsafe {}); | ^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:283:37 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:282:37 | LL | let _ = (42, unsafe {}, "test", unsafe {}); | ^^^^^^^^^ @@ -57,7 +57,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:287:14 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:286:14 | LL | let _ = *unsafe { &42 }; | ^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | let _ = *unsafe { &42 }; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:292:19 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:291:19 | LL | let _ = match unsafe {} { | ^^^^^^^^^ @@ -73,7 +73,7 @@ LL | let _ = match unsafe {} { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:298:14 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:297:14 | LL | let _ = &unsafe {}; | ^^^^^^^^^ @@ -81,7 +81,7 @@ LL | let _ = &unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:302:14 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:301:14 | LL | let _ = [unsafe {}; 5]; | ^^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _ = [unsafe {}; 5]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:306:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:305:13 | LL | let _ = unsafe {}; | ^^^^^^^^^ @@ -97,7 +97,7 @@ LL | let _ = unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:316:8 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:315:8 | LL | t!(unsafe {}); | ^^^^^^^^^ @@ -105,7 +105,7 @@ LL | t!(unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:322:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:321:13 | LL | unsafe {} | ^^^^^^^^^ @@ -117,7 +117,7 @@ LL | t!(); = note: this error originates in the macro `t` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:330:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:329:5 | LL | unsafe {} // SAFETY: | ^^^^^^^^^ @@ -125,7 +125,7 @@ LL | unsafe {} // SAFETY: = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:334:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:333:5 | LL | unsafe { | ^^^^^^^^ @@ -133,7 +133,7 @@ LL | unsafe { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:344:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:343:5 | LL | unsafe {}; | ^^^^^^^^^ @@ -141,7 +141,7 @@ LL | unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:348:20 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:347:20 | LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -149,7 +149,7 @@ LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) }); = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:355:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:354:5 | LL | unsafe impl A for () {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL | unsafe impl A for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:362:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:361:9 | LL | unsafe impl B for (u32) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -165,7 +165,7 @@ LL | unsafe impl B for (u32) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:383:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:382:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | no_safety_comment!(()); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:408:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:407:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -189,7 +189,7 @@ LL | no_safety_comment!(()); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:416:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:415:5 | LL | unsafe impl T for (i32) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -197,7 +197,7 @@ LL | unsafe impl T for (i32) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:408:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:407:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -209,7 +209,7 @@ LL | no_safety_comment!(u32); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:422:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:421:5 | LL | unsafe impl T for (bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL | unsafe impl T for (bool) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:468:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:467:5 | LL | unsafe impl NoComment for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -225,7 +225,7 @@ LL | unsafe impl NoComment for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:472:19 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:471:19 | LL | /* SAFETY: */ unsafe impl InlineComment for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -233,7 +233,7 @@ LL | /* SAFETY: */ unsafe impl InlineComment for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:476:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:475:5 | LL | unsafe impl TrailingComment for () {} // SAFETY: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,13 +241,13 @@ LL | unsafe impl TrailingComment for () {} // SAFETY: = help: consider adding a safety comment on the preceding line error: constant item has unnecessary safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:480:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:479:5 | LL | const BIG_NUMBER: i32 = 1000000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:479:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:478:5 | LL | // SAFETY: | ^^^^^^^^^^ @@ -255,7 +255,7 @@ LL | // SAFETY: = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]` error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:481:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:480:5 | LL | unsafe impl Interference for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -263,7 +263,7 @@ LL | unsafe impl Interference for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:488:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:487:5 | LL | unsafe impl ImplInFn for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -271,7 +271,7 @@ LL | unsafe impl ImplInFn for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:497:1 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:496:1 | LL | unsafe impl CrateRoot for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -279,7 +279,7 @@ LL | unsafe impl CrateRoot for () {} = help: consider adding a safety comment on the preceding line error: statement has unnecessary safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:510:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:509:5 | LL | / let _ = { LL | | if unsafe { true } { @@ -291,13 +291,13 @@ LL | | }; | |______^ | help: consider removing the safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:509:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:508:5 | LL | // SAFETY: this is more than one level away, so it should warn | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:511:12 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:510:12 | LL | if unsafe { true } { | ^^^^^^^^^^^^^^^ @@ -305,7 +305,7 @@ LL | if unsafe { true } { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:514:23 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:513:23 | LL | let bar = unsafe {}; | ^^^^^^^^^ diff --git a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr index 400fde997e9f..db5ea5b62890 100644 --- a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr +++ b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr @@ -1,5 +1,5 @@ error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:271:19 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:270:19 | LL | /* Safety: */ unsafe {} | ^^^^^^^^^ @@ -9,7 +9,7 @@ LL | /* Safety: */ unsafe {} = help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]` error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:275:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:274:5 | LL | unsafe {} | ^^^^^^^^^ @@ -17,7 +17,7 @@ LL | unsafe {} = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:279:14 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:278:14 | LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; | ^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:279:29 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:278:29 | LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; | ^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:279:48 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:278:48 | LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; | ^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:283:18 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:282:18 | LL | let _ = (42, unsafe {}, "test", unsafe {}); | ^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:283:37 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:282:37 | LL | let _ = (42, unsafe {}, "test", unsafe {}); | ^^^^^^^^^ @@ -57,7 +57,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:287:14 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:286:14 | LL | let _ = *unsafe { &42 }; | ^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | let _ = *unsafe { &42 }; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:292:19 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:291:19 | LL | let _ = match unsafe {} { | ^^^^^^^^^ @@ -73,7 +73,7 @@ LL | let _ = match unsafe {} { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:298:14 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:297:14 | LL | let _ = &unsafe {}; | ^^^^^^^^^ @@ -81,7 +81,7 @@ LL | let _ = &unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:302:14 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:301:14 | LL | let _ = [unsafe {}; 5]; | ^^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _ = [unsafe {}; 5]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:306:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:305:13 | LL | let _ = unsafe {}; | ^^^^^^^^^ @@ -97,7 +97,7 @@ LL | let _ = unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:316:8 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:315:8 | LL | t!(unsafe {}); | ^^^^^^^^^ @@ -105,7 +105,7 @@ LL | t!(unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:322:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:321:13 | LL | unsafe {} | ^^^^^^^^^ @@ -117,7 +117,7 @@ LL | t!(); = note: this error originates in the macro `t` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:330:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:329:5 | LL | unsafe {} // SAFETY: | ^^^^^^^^^ @@ -125,7 +125,7 @@ LL | unsafe {} // SAFETY: = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:334:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:333:5 | LL | unsafe { | ^^^^^^^^ @@ -133,7 +133,7 @@ LL | unsafe { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:344:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:343:5 | LL | unsafe {}; | ^^^^^^^^^ @@ -141,7 +141,7 @@ LL | unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:348:20 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:347:20 | LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -149,7 +149,7 @@ LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) }); = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:355:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:354:5 | LL | unsafe impl A for () {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL | unsafe impl A for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:362:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:361:9 | LL | unsafe impl B for (u32) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -165,7 +165,7 @@ LL | unsafe impl B for (u32) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:383:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:382:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | no_safety_comment!(()); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:408:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:407:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -189,7 +189,7 @@ LL | no_safety_comment!(()); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:416:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:415:5 | LL | unsafe impl T for (i32) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -197,7 +197,7 @@ LL | unsafe impl T for (i32) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:408:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:407:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -209,7 +209,7 @@ LL | no_safety_comment!(u32); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:422:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:421:5 | LL | unsafe impl T for (bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL | unsafe impl T for (bool) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:468:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:467:5 | LL | unsafe impl NoComment for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -225,7 +225,7 @@ LL | unsafe impl NoComment for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:472:19 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:471:19 | LL | /* SAFETY: */ unsafe impl InlineComment for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -233,7 +233,7 @@ LL | /* SAFETY: */ unsafe impl InlineComment for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:476:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:475:5 | LL | unsafe impl TrailingComment for () {} // SAFETY: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,13 +241,13 @@ LL | unsafe impl TrailingComment for () {} // SAFETY: = help: consider adding a safety comment on the preceding line error: constant item has unnecessary safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:480:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:479:5 | LL | const BIG_NUMBER: i32 = 1000000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:479:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:478:5 | LL | // SAFETY: | ^^^^^^^^^^ @@ -255,7 +255,7 @@ LL | // SAFETY: = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]` error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:481:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:480:5 | LL | unsafe impl Interference for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -263,7 +263,7 @@ LL | unsafe impl Interference for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:488:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:487:5 | LL | unsafe impl ImplInFn for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -271,7 +271,7 @@ LL | unsafe impl ImplInFn for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:497:1 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:496:1 | LL | unsafe impl CrateRoot for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -279,7 +279,7 @@ LL | unsafe impl CrateRoot for () {} = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:507:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:506:9 | LL | unsafe {}; | ^^^^^^^^^ @@ -287,7 +287,7 @@ LL | unsafe {}; = help: consider adding a safety comment on the preceding line error: statement has unnecessary safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:510:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:509:5 | LL | / let _ = { LL | | if unsafe { true } { @@ -299,13 +299,13 @@ LL | | }; | |______^ | help: consider removing the safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:509:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:508:5 | LL | // SAFETY: this is more than one level away, so it should warn | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:511:12 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:510:12 | LL | if unsafe { true } { | ^^^^^^^^^^^^^^^ @@ -313,7 +313,7 @@ LL | if unsafe { true } { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:514:23 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:513:23 | LL | let bar = unsafe {}; | ^^^^^^^^^ @@ -321,7 +321,7 @@ LL | let bar = unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:532:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:531:9 | LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -329,7 +329,7 @@ LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() }; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:536:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:535:9 | LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -337,7 +337,7 @@ LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:540:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:539:9 | LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -345,7 +345,7 @@ LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:546:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:545:5 | LL | unsafe {} | ^^^^^^^^^ @@ -353,7 +353,7 @@ LL | unsafe {} = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:550:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:549:5 | LL | unsafe { | ^^^^^^^^ @@ -361,7 +361,7 @@ LL | unsafe { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:557:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:556:9 | LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -369,7 +369,7 @@ LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() }; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:562:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:561:9 | LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -377,7 +377,7 @@ LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:568:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:567:9 | LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -385,7 +385,7 @@ LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:573:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:572:5 | LL | unsafe {} | ^^^^^^^^^ diff --git a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs index e5ef9d35fb6b..02170e1f7402 100644 --- a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs +++ b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs @@ -10,7 +10,6 @@ clippy::let_unit_value, clippy::missing_safety_doc )] -#![feature(lint_reasons)] extern crate proc_macro_unsafe; diff --git a/tests/ui/allow_attributes.fixed b/tests/ui/allow_attributes.fixed index b506a9890f5b..49ee3ee17c70 100644 --- a/tests/ui/allow_attributes.fixed +++ b/tests/ui/allow_attributes.fixed @@ -1,7 +1,6 @@ //@aux-build:proc_macros.rs #![allow(unused)] #![warn(clippy::allow_attributes)] -#![feature(lint_reasons)] #![no_main] extern crate proc_macros; @@ -47,3 +46,15 @@ fn ignore_proc_macro() { fn ignore_inner_attr() { #![allow(unused)] // Should not lint } + +#[clippy::msrv = "1.81"] +fn msrv_1_81() { + #[expect(unused)] + let x = 1; +} + +#[clippy::msrv = "1.80"] +fn msrv_1_80() { + #[allow(unused)] + let x = 1; +} diff --git a/tests/ui/allow_attributes.rs b/tests/ui/allow_attributes.rs index c7daa7abd9d4..854acf8348dc 100644 --- a/tests/ui/allow_attributes.rs +++ b/tests/ui/allow_attributes.rs @@ -1,7 +1,6 @@ //@aux-build:proc_macros.rs #![allow(unused)] #![warn(clippy::allow_attributes)] -#![feature(lint_reasons)] #![no_main] extern crate proc_macros; @@ -47,3 +46,15 @@ fn ignore_proc_macro() { fn ignore_inner_attr() { #![allow(unused)] // Should not lint } + +#[clippy::msrv = "1.81"] +fn msrv_1_81() { + #[allow(unused)] + let x = 1; +} + +#[clippy::msrv = "1.80"] +fn msrv_1_80() { + #[allow(unused)] + let x = 1; +} diff --git a/tests/ui/allow_attributes.stderr b/tests/ui/allow_attributes.stderr index 9c99e88c796a..10dac0bc8080 100644 --- a/tests/ui/allow_attributes.stderr +++ b/tests/ui/allow_attributes.stderr @@ -1,5 +1,5 @@ error: #[allow] attribute found - --> tests/ui/allow_attributes.rs:13:3 + --> tests/ui/allow_attributes.rs:12:3 | LL | #[allow(dead_code)] | ^^^^^ help: replace it with: `expect` @@ -8,10 +8,24 @@ LL | #[allow(dead_code)] = help: to override `-D warnings` add `#[allow(clippy::allow_attributes)]` error: #[allow] attribute found - --> tests/ui/allow_attributes.rs:22:30 + --> tests/ui/allow_attributes.rs:21:30 | LL | #[cfg_attr(panic = "unwind", allow(dead_code))] | ^^^^^ help: replace it with: `expect` -error: aborting due to 2 previous errors +error: #[allow] attribute found + --> tests/ui/allow_attributes.rs:52:7 + | +LL | #[allow(unused)] + | ^^^^^ help: replace it with: `expect` + +error: #[allow] attribute found + --> tests/ui/allow_attributes.rs:52:7 + | +LL | #[allow(unused)] + | ^^^^^ help: replace it with: `expect` + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 4 previous errors diff --git a/tests/ui/allow_attributes_without_reason.rs b/tests/ui/allow_attributes_without_reason.rs index 523148d65869..86f6b2c5742a 100644 --- a/tests/ui/allow_attributes_without_reason.rs +++ b/tests/ui/allow_attributes_without_reason.rs @@ -1,5 +1,4 @@ //@aux-build:proc_macros.rs -#![feature(lint_reasons)] #![deny(clippy::allow_attributes_without_reason)] #![allow(unfulfilled_lint_expectations, clippy::duplicated_attributes)] @@ -42,3 +41,15 @@ pub fn trigger_fp_result() -> Result<(), &'static str> { Err("asdf")?; Ok(()) } + +#[clippy::msrv = "1.81"] +fn msrv_1_81() { + #[allow(unused)] + let _ = 1; +} + +#[clippy::msrv = "1.80"] +fn msrv_1_80() { + #[allow(unused)] + let _ = 1; +} diff --git a/tests/ui/allow_attributes_without_reason.stderr b/tests/ui/allow_attributes_without_reason.stderr index 770a771ec3d1..9bc3ca0f2afd 100644 --- a/tests/ui/allow_attributes_without_reason.stderr +++ b/tests/ui/allow_attributes_without_reason.stderr @@ -1,18 +1,18 @@ error: `allow` attribute without specifying a reason - --> tests/ui/allow_attributes_without_reason.rs:4:1 + --> tests/ui/allow_attributes_without_reason.rs:3:1 | LL | #![allow(unfulfilled_lint_expectations, clippy::duplicated_attributes)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: try adding a reason at the end with `, reason = ".."` note: the lint level is defined here - --> tests/ui/allow_attributes_without_reason.rs:3:9 + --> tests/ui/allow_attributes_without_reason.rs:2:9 | LL | #![deny(clippy::allow_attributes_without_reason)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `allow` attribute without specifying a reason - --> tests/ui/allow_attributes_without_reason.rs:10:1 + --> tests/ui/allow_attributes_without_reason.rs:9:1 | LL | #[allow(dead_code)] | ^^^^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | #[allow(dead_code)] = help: try adding a reason at the end with `, reason = ".."` error: `allow` attribute without specifying a reason - --> tests/ui/allow_attributes_without_reason.rs:11:1 + --> tests/ui/allow_attributes_without_reason.rs:10:1 | LL | #[allow(dead_code, deprecated)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,12 +28,29 @@ LL | #[allow(dead_code, deprecated)] = help: try adding a reason at the end with `, reason = ".."` error: `expect` attribute without specifying a reason - --> tests/ui/allow_attributes_without_reason.rs:12:1 + --> tests/ui/allow_attributes_without_reason.rs:11:1 | LL | #[expect(dead_code)] | ^^^^^^^^^^^^^^^^^^^^ | = help: try adding a reason at the end with `, reason = ".."` -error: aborting due to 4 previous errors +error: `allow` attribute without specifying a reason + --> tests/ui/allow_attributes_without_reason.rs:47:5 + | +LL | #[allow(unused)] + | ^^^^^^^^^^^^^^^^ + | + = help: try adding a reason at the end with `, reason = ".."` + +error: `allow` attribute without specifying a reason + --> tests/ui/allow_attributes_without_reason.rs:47:5 + | +LL | #[allow(unused)] + | ^^^^^^^^^^^^^^^^ + | + = help: try adding a reason at the end with `, reason = ".."` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 6 previous errors diff --git a/tests/ui/async_yields_async.fixed b/tests/ui/async_yields_async.fixed index cfad78138053..208651bab1fd 100644 --- a/tests/ui/async_yields_async.fixed +++ b/tests/ui/async_yields_async.fixed @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![feature(async_closure)] #![warn(clippy::async_yields_async)] #![allow(clippy::redundant_async_block)] diff --git a/tests/ui/async_yields_async.rs b/tests/ui/async_yields_async.rs index 7bc26647943f..b124c994442b 100644 --- a/tests/ui/async_yields_async.rs +++ b/tests/ui/async_yields_async.rs @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![feature(async_closure)] #![warn(clippy::async_yields_async)] #![allow(clippy::redundant_async_block)] diff --git a/tests/ui/async_yields_async.stderr b/tests/ui/async_yields_async.stderr index 991ad7ae0ae2..861c3f2ce4a5 100644 --- a/tests/ui/async_yields_async.stderr +++ b/tests/ui/async_yields_async.stderr @@ -1,5 +1,5 @@ error: an async construct yields a type which is itself awaitable - --> tests/ui/async_yields_async.rs:39:9 + --> tests/ui/async_yields_async.rs:38:9 | LL | let _h = async { | _____________________- @@ -20,7 +20,7 @@ LL + }.await | error: an async construct yields a type which is itself awaitable - --> tests/ui/async_yields_async.rs:44:9 + --> tests/ui/async_yields_async.rs:43:9 | LL | let _i = async { | ____________________- @@ -33,7 +33,7 @@ LL | | }; | |_____- outer async construct error: an async construct yields a type which is itself awaitable - --> tests/ui/async_yields_async.rs:50:9 + --> tests/ui/async_yields_async.rs:49:9 | LL | let _j = async || { | ________________________- @@ -52,7 +52,7 @@ LL + }.await | error: an async construct yields a type which is itself awaitable - --> tests/ui/async_yields_async.rs:55:9 + --> tests/ui/async_yields_async.rs:54:9 | LL | let _k = async || { | _______________________- @@ -65,7 +65,7 @@ LL | | }; | |_____- outer async construct error: an async construct yields a type which is itself awaitable - --> tests/ui/async_yields_async.rs:57:23 + --> tests/ui/async_yields_async.rs:56:23 | LL | let _l = async || CustomFutureType; | ^^^^^^^^^^^^^^^^ @@ -75,7 +75,7 @@ LL | let _l = async || CustomFutureType; | help: consider awaiting this value: `CustomFutureType.await` error: an async construct yields a type which is itself awaitable - --> tests/ui/async_yields_async.rs:63:9 + --> tests/ui/async_yields_async.rs:62:9 | LL | let _m = async || { | _______________________- diff --git a/tests/ui/boxed_local.rs b/tests/ui/boxed_local.rs index e888154c46de..fbd9e12fc189 100644 --- a/tests/ui/boxed_local.rs +++ b/tests/ui/boxed_local.rs @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![allow( clippy::borrowed_box, clippy::needless_pass_by_value, diff --git a/tests/ui/boxed_local.stderr b/tests/ui/boxed_local.stderr index d3156c820b2c..7710233fa4db 100644 --- a/tests/ui/boxed_local.stderr +++ b/tests/ui/boxed_local.stderr @@ -1,5 +1,5 @@ error: local variable doesn't need to be boxed here - --> tests/ui/boxed_local.rs:40:13 + --> tests/ui/boxed_local.rs:39:13 | LL | fn warn_arg(x: Box) { | ^ @@ -8,19 +8,19 @@ LL | fn warn_arg(x: Box) { = help: to override `-D warnings` add `#[allow(clippy::boxed_local)]` error: local variable doesn't need to be boxed here - --> tests/ui/boxed_local.rs:123:12 + --> tests/ui/boxed_local.rs:122:12 | LL | pub fn new(_needs_name: Box>) -> () {} | ^^^^^^^^^^^ error: local variable doesn't need to be boxed here - --> tests/ui/boxed_local.rs:188:44 + --> tests/ui/boxed_local.rs:187:44 | LL | fn default_impl_x(self: Box, x: Box) -> u32 { | ^ error: local variable doesn't need to be boxed here - --> tests/ui/boxed_local.rs:196:16 + --> tests/ui/boxed_local.rs:195:16 | LL | fn foo(x: Box) {} | ^ diff --git a/tests/ui/checked_unwrap/simple_conditionals.rs b/tests/ui/checked_unwrap/simple_conditionals.rs index 02f80cc52ac7..c3c8562edffb 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.rs +++ b/tests/ui/checked_unwrap/simple_conditionals.rs @@ -1,5 +1,4 @@ //@no-rustfix: overlapping suggestions -#![feature(lint_reasons)] #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] #![allow( clippy::if_same_then_else, diff --git a/tests/ui/checked_unwrap/simple_conditionals.stderr b/tests/ui/checked_unwrap/simple_conditionals.stderr index bae621337601..ddd600418afe 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.stderr +++ b/tests/ui/checked_unwrap/simple_conditionals.stderr @@ -1,5 +1,5 @@ error: called `unwrap` on `x` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:47:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:46:9 | LL | if x.is_some() { | -------------- help: try: `if let Some(..) = x` @@ -8,13 +8,13 @@ LL | x.unwrap(); | ^^^^^^^^^^ | note: the lint level is defined here - --> tests/ui/checked_unwrap/simple_conditionals.rs:3:35 + --> tests/ui/checked_unwrap/simple_conditionals.rs:2:35 | LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `expect` on `x` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:50:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:49:9 | LL | if x.is_some() { | -------------- help: try: `if let Some(..) = x` @@ -23,7 +23,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:54:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:53:9 | LL | if x.is_some() { | ----------- because of this check @@ -32,13 +32,13 @@ LL | x.unwrap(); | ^^^^^^^^^^ | note: the lint level is defined here - --> tests/ui/checked_unwrap/simple_conditionals.rs:3:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:2:9 | LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `expect()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:57:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:56:9 | LL | if x.is_some() { | ----------- because of this check @@ -47,7 +47,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:62:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:61:9 | LL | if x.is_none() { | ----------- because of this check @@ -56,7 +56,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_none` - --> tests/ui/checked_unwrap/simple_conditionals.rs:66:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:65:9 | LL | if x.is_none() { | -------------- help: try: `if let Some(..) = x` @@ -65,7 +65,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:14:13 + --> tests/ui/checked_unwrap/simple_conditionals.rs:13:13 | LL | if $a.is_some() { | --------------- help: try: `if let Some(..) = x` @@ -79,7 +79,7 @@ LL | m!(x); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: called `unwrap` on `x` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:79:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:78:9 | LL | if x.is_ok() { | ------------ help: try: `if let Ok(..) = x` @@ -88,7 +88,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `expect` on `x` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:82:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:81:9 | LL | if x.is_ok() { | ------------ help: try: `if let Ok(..) = x` @@ -97,7 +97,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:85:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:84:9 | LL | if x.is_ok() { | --------- because of this check @@ -106,7 +106,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:89:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:88:9 | LL | if x.is_ok() { | --------- because of this check @@ -115,7 +115,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: this call to `expect()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:92:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:91:9 | LL | if x.is_ok() { | --------- because of this check @@ -124,7 +124,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:95:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:94:9 | LL | if x.is_ok() { | ------------ help: try: `if let Err(..) = x` @@ -133,7 +133,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:100:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:99:9 | LL | if x.is_err() { | ---------- because of this check @@ -142,7 +142,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_err` - --> tests/ui/checked_unwrap/simple_conditionals.rs:103:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:102:9 | LL | if x.is_err() { | ------------- help: try: `if let Err(..) = x` @@ -151,7 +151,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_err` - --> tests/ui/checked_unwrap/simple_conditionals.rs:107:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:106:9 | LL | if x.is_err() { | ------------- help: try: `if let Ok(..) = x` @@ -160,7 +160,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:110:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:109:9 | LL | if x.is_err() { | ---------- because of this check @@ -169,7 +169,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: called `unwrap` on `option` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:135:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:134:9 | LL | if option.is_some() { | ------------------- help: try: `if let Some(..) = &option` @@ -177,7 +177,7 @@ LL | option.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:138:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:137:9 | LL | if option.is_some() { | ---------------- because of this check @@ -186,7 +186,7 @@ LL | option.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `result` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:145:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:144:9 | LL | if result.is_ok() { | ----------------- help: try: `if let Ok(..) = &result` @@ -194,7 +194,7 @@ LL | result.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:148:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:147:9 | LL | if result.is_ok() { | -------------- because of this check @@ -203,7 +203,7 @@ LL | result.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `option` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:154:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:153:9 | LL | if option.is_some() { | ------------------- help: try: `if let Some(..) = &mut option` @@ -211,7 +211,7 @@ LL | option.as_mut().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:157:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:156:9 | LL | if option.is_some() { | ---------------- because of this check @@ -220,7 +220,7 @@ LL | option.as_mut().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `result` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:163:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:162:9 | LL | if result.is_ok() { | ----------------- help: try: `if let Ok(..) = &mut result` @@ -228,7 +228,7 @@ LL | result.as_mut().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:166:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:165:9 | LL | if result.is_ok() { | -------------- because of this check diff --git a/tests/ui/default_numeric_fallback_i32.fixed b/tests/ui/default_numeric_fallback_i32.fixed index e7038082c089..f28ae04fd0a4 100644 --- a/tests/ui/default_numeric_fallback_i32.fixed +++ b/tests/ui/default_numeric_fallback_i32.fixed @@ -1,6 +1,5 @@ //@aux-build:proc_macros.rs -#![feature(lint_reasons)] #![warn(clippy::default_numeric_fallback)] #![allow( unused, diff --git a/tests/ui/default_numeric_fallback_i32.rs b/tests/ui/default_numeric_fallback_i32.rs index d8eeda704919..78a5006444ee 100644 --- a/tests/ui/default_numeric_fallback_i32.rs +++ b/tests/ui/default_numeric_fallback_i32.rs @@ -1,6 +1,5 @@ //@aux-build:proc_macros.rs -#![feature(lint_reasons)] #![warn(clippy::default_numeric_fallback)] #![allow( unused, diff --git a/tests/ui/default_numeric_fallback_i32.stderr b/tests/ui/default_numeric_fallback_i32.stderr index 9961a3669ef2..67ab923ecf5f 100644 --- a/tests/ui/default_numeric_fallback_i32.stderr +++ b/tests/ui/default_numeric_fallback_i32.stderr @@ -1,5 +1,5 @@ error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:21:17 + --> tests/ui/default_numeric_fallback_i32.rs:20:17 | LL | let x = 22; | ^^ help: consider adding suffix: `22_i32` @@ -8,145 +8,145 @@ LL | let x = 22; = help: to override `-D warnings` add `#[allow(clippy::default_numeric_fallback)]` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:22:18 + --> tests/ui/default_numeric_fallback_i32.rs:21:18 | LL | let x = [1, 2, 3]; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:22:21 + --> tests/ui/default_numeric_fallback_i32.rs:21:21 | LL | let x = [1, 2, 3]; | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:22:24 + --> tests/ui/default_numeric_fallback_i32.rs:21:24 | LL | let x = [1, 2, 3]; | ^ help: consider adding suffix: `3_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:23:28 + --> tests/ui/default_numeric_fallback_i32.rs:22:28 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:23:31 + --> tests/ui/default_numeric_fallback_i32.rs:22:31 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:23:44 + --> tests/ui/default_numeric_fallback_i32.rs:22:44 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `3_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:23:47 + --> tests/ui/default_numeric_fallback_i32.rs:22:47 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `4_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:24:23 + --> tests/ui/default_numeric_fallback_i32.rs:23:23 | LL | let x = match 1 { | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:25:13 + --> tests/ui/default_numeric_fallback_i32.rs:24:13 | LL | 1 => 1, | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:25:18 + --> tests/ui/default_numeric_fallback_i32.rs:24:18 | LL | 1 => 1, | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:26:18 + --> tests/ui/default_numeric_fallback_i32.rs:25:18 | LL | _ => 2, | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:45:21 + --> tests/ui/default_numeric_fallback_i32.rs:44:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:53:21 + --> tests/ui/default_numeric_fallback_i32.rs:52:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:59:21 + --> tests/ui/default_numeric_fallback_i32.rs:58:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:67:21 + --> tests/ui/default_numeric_fallback_i32.rs:66:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:83:27 + --> tests/ui/default_numeric_fallback_i32.rs:82:27 | LL | let f = || -> _ { 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:87:29 + --> tests/ui/default_numeric_fallback_i32.rs:86:29 | LL | let f = || -> i32 { 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:101:21 + --> tests/ui/default_numeric_fallback_i32.rs:100:21 | LL | generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:104:32 + --> tests/ui/default_numeric_fallback_i32.rs:103:32 | LL | let x: _ = generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:122:28 + --> tests/ui/default_numeric_fallback_i32.rs:121:28 | LL | GenericStruct { x: 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:125:36 + --> tests/ui/default_numeric_fallback_i32.rs:124:36 | LL | let _ = GenericStruct { x: 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:143:24 + --> tests/ui/default_numeric_fallback_i32.rs:142:24 | LL | GenericEnum::X(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:163:23 + --> tests/ui/default_numeric_fallback_i32.rs:162:23 | LL | s.generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:173:25 + --> tests/ui/default_numeric_fallback_i32.rs:172:25 | LL | inline!(let x = 22;); | ^^ help: consider adding suffix: `22_i32` @@ -154,19 +154,19 @@ LL | inline!(let x = 22;); = note: this error originates in the macro `__inline_mac_fn_internal` (in Nightly builds, run with -Z macro-backtrace for more info) error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:215:29 + --> tests/ui/default_numeric_fallback_i32.rs:214:29 | LL | let data_i32 = vec![1, 2, 3]; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:215:32 + --> tests/ui/default_numeric_fallback_i32.rs:214:32 | LL | let data_i32 = vec![1, 2, 3]; | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:215:35 + --> tests/ui/default_numeric_fallback_i32.rs:214:35 | LL | let data_i32 = vec![1, 2, 3]; | ^ help: consider adding suffix: `3_i32` diff --git a/tests/ui/derive_partial_eq_without_eq.fixed b/tests/ui/derive_partial_eq_without_eq.fixed index eb93eb8e8ed4..e4a33193a1ab 100644 --- a/tests/ui/derive_partial_eq_without_eq.fixed +++ b/tests/ui/derive_partial_eq_without_eq.fixed @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![allow(unused)] #![warn(clippy::derive_partial_eq_without_eq)] diff --git a/tests/ui/derive_partial_eq_without_eq.rs b/tests/ui/derive_partial_eq_without_eq.rs index 42dc435bdd52..a418b38e3499 100644 --- a/tests/ui/derive_partial_eq_without_eq.rs +++ b/tests/ui/derive_partial_eq_without_eq.rs @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![allow(unused)] #![warn(clippy::derive_partial_eq_without_eq)] diff --git a/tests/ui/derive_partial_eq_without_eq.stderr b/tests/ui/derive_partial_eq_without_eq.stderr index 29cd7da6b77d..7436114fadb2 100644 --- a/tests/ui/derive_partial_eq_without_eq.stderr +++ b/tests/ui/derive_partial_eq_without_eq.stderr @@ -1,5 +1,5 @@ error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:12:17 + --> tests/ui/derive_partial_eq_without_eq.rs:11:17 | LL | #[derive(Debug, PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` @@ -8,73 +8,73 @@ LL | #[derive(Debug, PartialEq)] = help: to override `-D warnings` add `#[allow(clippy::derive_partial_eq_without_eq)]` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:70:10 + --> tests/ui/derive_partial_eq_without_eq.rs:69:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:76:10 + --> tests/ui/derive_partial_eq_without_eq.rs:75:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:82:10 + --> tests/ui/derive_partial_eq_without_eq.rs:81:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:85:10 + --> tests/ui/derive_partial_eq_without_eq.rs:84:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:91:10 + --> tests/ui/derive_partial_eq_without_eq.rs:90:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:97:10 + --> tests/ui/derive_partial_eq_without_eq.rs:96:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:110:17 + --> tests/ui/derive_partial_eq_without_eq.rs:109:17 | LL | #[derive(Debug, PartialEq, Clone)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:113:10 + --> tests/ui/derive_partial_eq_without_eq.rs:112:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:120:14 + --> tests/ui/derive_partial_eq_without_eq.rs:119:14 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:123:14 + --> tests/ui/derive_partial_eq_without_eq.rs:122:14 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:183:14 + --> tests/ui/derive_partial_eq_without_eq.rs:182:14 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:191:14 + --> tests/ui/derive_partial_eq_without_eq.rs:190:14 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` diff --git a/tests/ui/expect_tool_lint_rfc_2383.rs b/tests/ui/expect_tool_lint_rfc_2383.rs index 72097bfabd72..2634c56794e7 100644 --- a/tests/ui/expect_tool_lint_rfc_2383.rs +++ b/tests/ui/expect_tool_lint_rfc_2383.rs @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] //! This file tests the `#[expect]` attribute implementation for tool lints. The same //! file is used to test clippy and rustdoc. Any changes to this file should be synced //! to the other test files as well. diff --git a/tests/ui/expect_tool_lint_rfc_2383.stderr b/tests/ui/expect_tool_lint_rfc_2383.stderr index 43e0b9279e4b..f70d3408aa4d 100644 --- a/tests/ui/expect_tool_lint_rfc_2383.stderr +++ b/tests/ui/expect_tool_lint_rfc_2383.stderr @@ -1,5 +1,5 @@ error: this lint expectation is unfulfilled - --> tests/ui/expect_tool_lint_rfc_2383.rs:31:14 + --> tests/ui/expect_tool_lint_rfc_2383.rs:30:14 | LL | #[expect(dead_code)] | ^^^^^^^^^ @@ -8,31 +8,31 @@ LL | #[expect(dead_code)] = help: to override `-D warnings` add `#[allow(unfulfilled_lint_expectations)]` error: this lint expectation is unfulfilled - --> tests/ui/expect_tool_lint_rfc_2383.rs:37:18 + --> tests/ui/expect_tool_lint_rfc_2383.rs:36:18 | LL | #[expect(invalid_nan_comparisons)] | ^^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> tests/ui/expect_tool_lint_rfc_2383.rs:108:14 + --> tests/ui/expect_tool_lint_rfc_2383.rs:107:14 | LL | #[expect(clippy::almost_swapped)] | ^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> tests/ui/expect_tool_lint_rfc_2383.rs:116:14 + --> tests/ui/expect_tool_lint_rfc_2383.rs:115:14 | LL | #[expect(clippy::bytes_nth)] | ^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> tests/ui/expect_tool_lint_rfc_2383.rs:122:14 + --> tests/ui/expect_tool_lint_rfc_2383.rs:121:14 | LL | #[expect(clippy::if_same_then_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> tests/ui/expect_tool_lint_rfc_2383.rs:128:14 + --> tests/ui/expect_tool_lint_rfc_2383.rs:127:14 | LL | #[expect(clippy::overly_complex_bool_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/implicit_return.fixed b/tests/ui/implicit_return.fixed index 897f1b766163..ba73e64f1862 100644 --- a/tests/ui/implicit_return.fixed +++ b/tests/ui/implicit_return.fixed @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![warn(clippy::implicit_return)] #![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)] diff --git a/tests/ui/implicit_return.rs b/tests/ui/implicit_return.rs index fcff67b58071..522fc6a0a447 100644 --- a/tests/ui/implicit_return.rs +++ b/tests/ui/implicit_return.rs @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![warn(clippy::implicit_return)] #![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)] diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr index 3ffed273e0f1..b2f7bc694395 100644 --- a/tests/ui/implicit_return.stderr +++ b/tests/ui/implicit_return.stderr @@ -1,5 +1,5 @@ error: missing `return` statement - --> tests/ui/implicit_return.rs:11:5 + --> tests/ui/implicit_return.rs:10:5 | LL | true | ^^^^ help: add `return` as shown: `return true` @@ -8,85 +8,85 @@ LL | true = help: to override `-D warnings` add `#[allow(clippy::implicit_return)]` error: missing `return` statement - --> tests/ui/implicit_return.rs:15:15 + --> tests/ui/implicit_return.rs:14:15 | LL | if true { true } else { false } | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> tests/ui/implicit_return.rs:15:29 + --> tests/ui/implicit_return.rs:14:29 | LL | if true { true } else { false } | ^^^^^ help: add `return` as shown: `return false` error: missing `return` statement - --> tests/ui/implicit_return.rs:21:17 + --> tests/ui/implicit_return.rs:20:17 | LL | true => false, | ^^^^^ help: add `return` as shown: `return false` error: missing `return` statement - --> tests/ui/implicit_return.rs:22:20 + --> tests/ui/implicit_return.rs:21:20 | LL | false => { true }, | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> tests/ui/implicit_return.rs:35:9 + --> tests/ui/implicit_return.rs:34:9 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> tests/ui/implicit_return.rs:42:13 + --> tests/ui/implicit_return.rs:41:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> tests/ui/implicit_return.rs:50:13 + --> tests/ui/implicit_return.rs:49:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> tests/ui/implicit_return.rs:68:18 + --> tests/ui/implicit_return.rs:67:18 | LL | let _ = || { true }; | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> tests/ui/implicit_return.rs:69:16 + --> tests/ui/implicit_return.rs:68:16 | LL | let _ = || true; | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> tests/ui/implicit_return.rs:77:5 + --> tests/ui/implicit_return.rs:76:5 | LL | format!("test {}", "test") | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")` error: missing `return` statement - --> tests/ui/implicit_return.rs:86:5 + --> tests/ui/implicit_return.rs:85:5 | LL | m!(true, false) | ^^^^^^^^^^^^^^^ help: add `return` as shown: `return m!(true, false)` error: missing `return` statement - --> tests/ui/implicit_return.rs:92:13 + --> tests/ui/implicit_return.rs:91:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> tests/ui/implicit_return.rs:97:17 + --> tests/ui/implicit_return.rs:96:17 | LL | break 'outer false; | ^^^^^^^^^^^^^^^^^^ help: change `break` to `return` as shown: `return false` error: missing `return` statement - --> tests/ui/implicit_return.rs:112:5 + --> tests/ui/implicit_return.rs:111:5 | LL | / loop { LL | | m!(true); @@ -101,7 +101,7 @@ LL + } | error: missing `return` statement - --> tests/ui/implicit_return.rs:126:5 + --> tests/ui/implicit_return.rs:125:5 | LL | true | ^^^^ help: add `return` as shown: `return true` diff --git a/tests/ui/let_unit.fixed b/tests/ui/let_unit.fixed index 20940daffa7a..3456e274f6a4 100644 --- a/tests/ui/let_unit.fixed +++ b/tests/ui/let_unit.fixed @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![warn(clippy::let_unit_value)] #![allow(unused, clippy::no_effect, clippy::needless_late_init, path_statements)] diff --git a/tests/ui/let_unit.rs b/tests/ui/let_unit.rs index dca66f2e3edb..e2dafbcb7714 100644 --- a/tests/ui/let_unit.rs +++ b/tests/ui/let_unit.rs @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![warn(clippy::let_unit_value)] #![allow(unused, clippy::no_effect, clippy::needless_late_init, path_statements)] diff --git a/tests/ui/let_unit.stderr b/tests/ui/let_unit.stderr index aafb77bcd0d6..2f62c33c8873 100644 --- a/tests/ui/let_unit.stderr +++ b/tests/ui/let_unit.stderr @@ -1,5 +1,5 @@ error: this let-binding has unit value - --> tests/ui/let_unit.rs:12:5 + --> tests/ui/let_unit.rs:11:5 | LL | let _x = println!("x"); | ^^^^^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `println!("x");` @@ -8,7 +8,7 @@ LL | let _x = println!("x"); = help: to override `-D warnings` add `#[allow(clippy::let_unit_value)]` error: this let-binding has unit value - --> tests/ui/let_unit.rs:60:5 + --> tests/ui/let_unit.rs:59:5 | LL | / let _ = v LL | | .into_iter() @@ -31,7 +31,7 @@ LL + .unwrap(); | error: this let-binding has unit value - --> tests/ui/let_unit.rs:109:5 + --> tests/ui/let_unit.rs:108:5 | LL | / let x = match Some(0) { LL | | None => f2(1), @@ -52,7 +52,7 @@ LL + }; | error: this let-binding has unit value - --> tests/ui/let_unit.rs:190:9 + --> tests/ui/let_unit.rs:189:9 | LL | let res = returns_unit(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/macro_use_imports.fixed b/tests/ui/macro_use_imports.fixed index 46c053b779e7..38ed5a957e73 100644 --- a/tests/ui/macro_use_imports.fixed +++ b/tests/ui/macro_use_imports.fixed @@ -4,7 +4,6 @@ //@ignore-32bit -#![feature(lint_reasons)] #![allow(unused_imports, unreachable_code, unused_variables, dead_code, unused_attributes)] #![allow(clippy::single_component_path_imports)] #![warn(clippy::macro_use_imports)] diff --git a/tests/ui/macro_use_imports.rs b/tests/ui/macro_use_imports.rs index 47f5c9bf8845..ae6cc16ed276 100644 --- a/tests/ui/macro_use_imports.rs +++ b/tests/ui/macro_use_imports.rs @@ -4,7 +4,6 @@ //@ignore-32bit -#![feature(lint_reasons)] #![allow(unused_imports, unreachable_code, unused_variables, dead_code, unused_attributes)] #![allow(clippy::single_component_path_imports)] #![warn(clippy::macro_use_imports)] diff --git a/tests/ui/macro_use_imports.stderr b/tests/ui/macro_use_imports.stderr index a3733b1c0c96..ea0670d36667 100644 --- a/tests/ui/macro_use_imports.stderr +++ b/tests/ui/macro_use_imports.stderr @@ -1,5 +1,5 @@ error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> tests/ui/macro_use_imports.rs:19:5 + --> tests/ui/macro_use_imports.rs:18:5 | LL | #[macro_use] | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro};` @@ -8,19 +8,19 @@ LL | #[macro_use] = help: to override `-D warnings` add `#[allow(clippy::macro_use_imports)]` error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> tests/ui/macro_use_imports.rs:23:5 + --> tests/ui/macro_use_imports.rs:22:5 | LL | #[macro_use] | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::mut_mut, inner::try_err};` error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> tests/ui/macro_use_imports.rs:25:5 + --> tests/ui/macro_use_imports.rs:24:5 | LL | #[macro_use] | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;` error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> tests/ui/macro_use_imports.rs:21:5 + --> tests/ui/macro_use_imports.rs:20:5 | LL | #[macro_use] | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;` diff --git a/tests/ui/macro_use_imports_expect.rs b/tests/ui/macro_use_imports_expect.rs index b9677851b92d..df6d5b9fbabf 100644 --- a/tests/ui/macro_use_imports_expect.rs +++ b/tests/ui/macro_use_imports_expect.rs @@ -3,7 +3,6 @@ //@aux-build:proc_macro_derive.rs //@ignore-32bit -#![feature(lint_reasons)] #![allow(unused_imports, unreachable_code, unused_variables, dead_code, unused_attributes)] #![allow(clippy::single_component_path_imports)] #![warn(clippy::macro_use_imports)] diff --git a/tests/ui/manual_non_exhaustive_enum.rs b/tests/ui/manual_non_exhaustive_enum.rs index eb3875320311..31c3cc801372 100644 --- a/tests/ui/manual_non_exhaustive_enum.rs +++ b/tests/ui/manual_non_exhaustive_enum.rs @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![warn(clippy::manual_non_exhaustive)] #![allow(unused)] //@no-rustfix diff --git a/tests/ui/manual_non_exhaustive_enum.stderr b/tests/ui/manual_non_exhaustive_enum.stderr index ee43b8ddc024..dc669568dd2d 100644 --- a/tests/ui/manual_non_exhaustive_enum.stderr +++ b/tests/ui/manual_non_exhaustive_enum.stderr @@ -1,5 +1,5 @@ error: this seems like a manual implementation of the non-exhaustive pattern - --> tests/ui/manual_non_exhaustive_enum.rs:5:1 + --> tests/ui/manual_non_exhaustive_enum.rs:4:1 | LL | enum E { | ^----- @@ -15,7 +15,7 @@ LL | | } | |_^ | help: remove this variant - --> tests/ui/manual_non_exhaustive_enum.rs:10:5 + --> tests/ui/manual_non_exhaustive_enum.rs:9:5 | LL | _C, | ^^ @@ -23,7 +23,7 @@ LL | _C, = help: to override `-D warnings` add `#[allow(clippy::manual_non_exhaustive)]` error: this seems like a manual implementation of the non-exhaustive pattern - --> tests/ui/manual_non_exhaustive_enum.rs:30:1 + --> tests/ui/manual_non_exhaustive_enum.rs:29:1 | LL | enum NoUnderscore { | ^---------------- @@ -38,7 +38,7 @@ LL | | } | |_^ | help: remove this variant - --> tests/ui/manual_non_exhaustive_enum.rs:34:5 + --> tests/ui/manual_non_exhaustive_enum.rs:33:5 | LL | C, | ^ diff --git a/tests/ui/needless_borrow.fixed b/tests/ui/needless_borrow.fixed index 5121077b4cab..cabdc22bda84 100644 --- a/tests/ui/needless_borrow.fixed +++ b/tests/ui/needless_borrow.fixed @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![allow( unused, non_local_definitions, diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs index e3a5cb280bad..50062589645f 100644 --- a/tests/ui/needless_borrow.rs +++ b/tests/ui/needless_borrow.rs @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![allow( unused, non_local_definitions, diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr index 4b2b17e7e570..bf0e265c2503 100644 --- a/tests/ui/needless_borrow.stderr +++ b/tests/ui/needless_borrow.stderr @@ -1,5 +1,5 @@ error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:16:15 + --> tests/ui/needless_borrow.rs:15:15 | LL | let _ = x(&&a); // warn | ^^^ help: change this to: `&a` @@ -8,163 +8,163 @@ LL | let _ = x(&&a); // warn = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:20:13 + --> tests/ui/needless_borrow.rs:19:13 | LL | mut_ref(&mut &mut b); // warn | ^^^^^^^^^^^ help: change this to: `&mut b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:32:13 + --> tests/ui/needless_borrow.rs:31:13 | LL | &&a | ^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:34:15 + --> tests/ui/needless_borrow.rs:33:15 | LL | 46 => &&a, | ^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:40:27 + --> tests/ui/needless_borrow.rs:39:27 | LL | break &ref_a; | ^^^^^^ help: change this to: `ref_a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:47:15 + --> tests/ui/needless_borrow.rs:46:15 | LL | let _ = x(&&&a); | ^^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:48:15 + --> tests/ui/needless_borrow.rs:47:15 | LL | let _ = x(&mut &&a); | ^^^^^^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:49:15 + --> tests/ui/needless_borrow.rs:48:15 | LL | let _ = x(&&&mut b); | ^^^^^^^^ help: change this to: `&mut b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:50:15 + --> tests/ui/needless_borrow.rs:49:15 | LL | let _ = x(&&ref_a); | ^^^^^^^ help: change this to: `ref_a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:53:11 + --> tests/ui/needless_borrow.rs:52:11 | LL | x(&b); | ^^ help: change this to: `b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:60:13 + --> tests/ui/needless_borrow.rs:59:13 | LL | mut_ref(&mut x); | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:61:13 + --> tests/ui/needless_borrow.rs:60:13 | LL | mut_ref(&mut &mut x); | ^^^^^^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:62:23 + --> tests/ui/needless_borrow.rs:61:23 | LL | let y: &mut i32 = &mut x; | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:63:23 + --> tests/ui/needless_borrow.rs:62:23 | LL | let y: &mut i32 = &mut &mut x; | ^^^^^^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:72:14 + --> tests/ui/needless_borrow.rs:71:14 | LL | 0 => &mut x, | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:78:14 + --> tests/ui/needless_borrow.rs:77:14 | LL | 0 => &mut x, | ^^^^^^ help: change this to: `x` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:90:13 + --> tests/ui/needless_borrow.rs:89:13 | LL | let _ = (&x).0; | ^^^^ help: change this to: `x` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:92:22 + --> tests/ui/needless_borrow.rs:91:22 | LL | let _ = unsafe { (&*x).0 }; | ^^^^^ help: change this to: `(*x)` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:102:5 + --> tests/ui/needless_borrow.rs:101:5 | LL | (&&()).foo(); | ^^^^^^ help: change this to: `(&())` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:111:5 + --> tests/ui/needless_borrow.rs:110:5 | LL | (&&5).foo(); | ^^^^^ help: change this to: `(&5)` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:137:23 + --> tests/ui/needless_borrow.rs:136:23 | LL | let x: (&str,) = (&"",); | ^^^ help: change this to: `""` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:179:13 + --> tests/ui/needless_borrow.rs:178:13 | LL | (&self.f)() | ^^^^^^^^^ help: change this to: `(self.f)` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:188:13 + --> tests/ui/needless_borrow.rs:187:13 | LL | (&mut self.f)() | ^^^^^^^^^^^^^ help: change this to: `(self.f)` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:225:22 + --> tests/ui/needless_borrow.rs:224:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:232:22 + --> tests/ui/needless_borrow.rs:231:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:236:22 + --> tests/ui/needless_borrow.rs:235:22 | LL | let _ = &mut (&mut x.u).x; | ^^^^^^^^^^ help: change this to: `x.u` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:237:22 + --> tests/ui/needless_borrow.rs:236:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:258:23 + --> tests/ui/needless_borrow.rs:257:23 | LL | option.unwrap_or((&x.0,)); | ^^^^ help: change this to: `x.0` diff --git a/tests/ui/needless_pass_by_ref_mut.rs b/tests/ui/needless_pass_by_ref_mut.rs index 3f5f55f40020..eee62122fdfd 100644 --- a/tests/ui/needless_pass_by_ref_mut.rs +++ b/tests/ui/needless_pass_by_ref_mut.rs @@ -5,7 +5,6 @@ clippy::ptr_arg )] #![warn(clippy::needless_pass_by_ref_mut)] -#![feature(lint_reasons)] //@no-rustfix use std::ptr::NonNull; diff --git a/tests/ui/needless_pass_by_ref_mut.stderr b/tests/ui/needless_pass_by_ref_mut.stderr index 21ca393dcb63..51e3ba37dede 100644 --- a/tests/ui/needless_pass_by_ref_mut.stderr +++ b/tests/ui/needless_pass_by_ref_mut.stderr @@ -1,5 +1,5 @@ error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:12:11 + --> tests/ui/needless_pass_by_ref_mut.rs:11:11 | LL | fn foo(s: &mut Vec, b: &u32, x: &mut u32) { | ^^^^^^^^^^^^^ help: consider changing to: `&Vec` @@ -8,79 +8,79 @@ LL | fn foo(s: &mut Vec, b: &u32, x: &mut u32) { = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:37:12 + --> tests/ui/needless_pass_by_ref_mut.rs:36:12 | LL | fn foo6(s: &mut Vec) { | ^^^^^^^^^^^^^ help: consider changing to: `&Vec` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:47:12 + --> tests/ui/needless_pass_by_ref_mut.rs:46:12 | LL | fn bar(&mut self) {} | ^^^^^^^^^ help: consider changing to: `&self` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:50:29 + --> tests/ui/needless_pass_by_ref_mut.rs:49:29 | LL | fn mushroom(&self, vec: &mut Vec) -> usize { | ^^^^^^^^^^^^^ help: consider changing to: `&Vec` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:127:16 + --> tests/ui/needless_pass_by_ref_mut.rs:126:16 | LL | async fn a1(x: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:131:16 + --> tests/ui/needless_pass_by_ref_mut.rs:130:16 | LL | async fn a2(x: &mut i32, y: String) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:135:16 + --> tests/ui/needless_pass_by_ref_mut.rs:134:16 | LL | async fn a3(x: &mut i32, y: String, z: String) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:139:16 + --> tests/ui/needless_pass_by_ref_mut.rs:138:16 | LL | async fn a4(x: &mut i32, y: i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:143:24 + --> tests/ui/needless_pass_by_ref_mut.rs:142:24 | LL | async fn a5(x: i32, y: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:147:24 + --> tests/ui/needless_pass_by_ref_mut.rs:146:24 | LL | async fn a6(x: i32, y: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:151:32 + --> tests/ui/needless_pass_by_ref_mut.rs:150:32 | LL | async fn a7(x: i32, y: i32, z: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:155:24 + --> tests/ui/needless_pass_by_ref_mut.rs:154:24 | LL | async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:155:45 + --> tests/ui/needless_pass_by_ref_mut.rs:154:45 | LL | async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:189:16 + --> tests/ui/needless_pass_by_ref_mut.rs:188:16 | LL | fn cfg_warn(s: &mut u32) {} | ^^^^^^^^ help: consider changing to: `&u32` @@ -88,7 +88,7 @@ LL | fn cfg_warn(s: &mut u32) {} = note: this is cfg-gated and may require further changes error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:195:20 + --> tests/ui/needless_pass_by_ref_mut.rs:194:20 | LL | fn cfg_warn(s: &mut u32) {} | ^^^^^^^^ help: consider changing to: `&u32` @@ -96,19 +96,19 @@ LL | fn cfg_warn(s: &mut u32) {} = note: this is cfg-gated and may require further changes error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:209:39 + --> tests/ui/needless_pass_by_ref_mut.rs:208:39 | LL | async fn inner_async2(x: &mut i32, y: &mut u32) { | ^^^^^^^^ help: consider changing to: `&u32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:217:26 + --> tests/ui/needless_pass_by_ref_mut.rs:216:26 | LL | async fn inner_async3(x: &mut i32, y: &mut u32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:236:34 + --> tests/ui/needless_pass_by_ref_mut.rs:235:34 | LL | pub async fn call_in_closure1(n: &mut str) { | ^^^^^^^^ help: consider changing to: `&str` @@ -116,7 +116,7 @@ LL | pub async fn call_in_closure1(n: &mut str) { = warning: changing this function will impact semver compatibility error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:255:20 + --> tests/ui/needless_pass_by_ref_mut.rs:254:20 | LL | pub fn closure2(n: &mut usize) -> impl '_ + FnMut() -> usize { | ^^^^^^^^^^ help: consider changing to: `&usize` @@ -124,7 +124,7 @@ LL | pub fn closure2(n: &mut usize) -> impl '_ + FnMut() -> usize { = warning: changing this function will impact semver compatibility error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:266:26 + --> tests/ui/needless_pass_by_ref_mut.rs:265:26 | LL | pub async fn closure4(n: &mut usize) { | ^^^^^^^^^^ help: consider changing to: `&usize` @@ -132,85 +132,85 @@ LL | pub async fn closure4(n: &mut usize) { = warning: changing this function will impact semver compatibility error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:315:12 + --> tests/ui/needless_pass_by_ref_mut.rs:314:12 | LL | fn bar(&mut self) {} | ^^^^^^^^^ help: consider changing to: `&self` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:317:18 + --> tests/ui/needless_pass_by_ref_mut.rs:316:18 | LL | async fn foo(&mut self, u: &mut i32, v: &mut u32) { | ^^^^^^^^^ help: consider changing to: `&self` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:317:45 + --> tests/ui/needless_pass_by_ref_mut.rs:316:45 | LL | async fn foo(&mut self, u: &mut i32, v: &mut u32) { | ^^^^^^^^ help: consider changing to: `&u32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:325:46 + --> tests/ui/needless_pass_by_ref_mut.rs:324:46 | LL | async fn foo2(&mut self, u: &mut i32, v: &mut u32) { | ^^^^^^^^ help: consider changing to: `&u32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:341:18 + --> tests/ui/needless_pass_by_ref_mut.rs:340:18 | LL | fn _empty_tup(x: &mut (())) {} | ^^^^^^^^^ help: consider changing to: `&()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:342:19 + --> tests/ui/needless_pass_by_ref_mut.rs:341:19 | LL | fn _single_tup(x: &mut ((i32,))) {} | ^^^^^^^^^^^^^ help: consider changing to: `&(i32,)` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:343:18 + --> tests/ui/needless_pass_by_ref_mut.rs:342:18 | LL | fn _multi_tup(x: &mut ((i32, u32))) {} | ^^^^^^^^^^^^^^^^^ help: consider changing to: `&(i32, u32)` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:344:11 + --> tests/ui/needless_pass_by_ref_mut.rs:343:11 | LL | fn _fn(x: &mut (fn())) {} | ^^^^^^^^^^^ help: consider changing to: `&fn()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:346:23 + --> tests/ui/needless_pass_by_ref_mut.rs:345:23 | LL | fn _extern_rust_fn(x: &mut extern "Rust" fn()) {} | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&extern "Rust" fn()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:347:20 + --> tests/ui/needless_pass_by_ref_mut.rs:346:20 | LL | fn _extern_c_fn(x: &mut extern "C" fn()) {} | ^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&extern "C" fn()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:348:18 + --> tests/ui/needless_pass_by_ref_mut.rs:347:18 | LL | fn _unsafe_fn(x: &mut unsafe fn()) {} | ^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe fn()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:349:25 + --> tests/ui/needless_pass_by_ref_mut.rs:348:25 | LL | fn _unsafe_extern_fn(x: &mut unsafe extern "C" fn()) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe extern "C" fn()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:350:20 + --> tests/ui/needless_pass_by_ref_mut.rs:349:20 | LL | fn _fn_with_arg(x: &mut unsafe extern "C" fn(i32)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe extern "C" fn(i32)` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:351:20 + --> tests/ui/needless_pass_by_ref_mut.rs:350:20 | LL | fn _fn_with_ret(x: &mut unsafe extern "C" fn() -> (i32)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe extern "C" fn() -> (i32)` diff --git a/tests/ui/needless_return.fixed b/tests/ui/needless_return.fixed index a9271cb399d8..853f685f04c7 100644 --- a/tests/ui/needless_return.fixed +++ b/tests/ui/needless_return.fixed @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![feature(yeet_expr)] #![allow(unused)] #![allow( diff --git a/tests/ui/needless_return.rs b/tests/ui/needless_return.rs index dc888bf667f1..e9c1e0e8ae8e 100644 --- a/tests/ui/needless_return.rs +++ b/tests/ui/needless_return.rs @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![feature(yeet_expr)] #![allow(unused)] #![allow( diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr index b49f199ba5ab..6c891fe7ad3f 100644 --- a/tests/ui/needless_return.stderr +++ b/tests/ui/needless_return.stderr @@ -1,5 +1,5 @@ error: unneeded `return` statement - --> tests/ui/needless_return.rs:26:5 + --> tests/ui/needless_return.rs:25:5 | LL | return true; | ^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:30:5 + --> tests/ui/needless_return.rs:29:5 | LL | return true; | ^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:35:5 + --> tests/ui/needless_return.rs:34:5 | LL | return true;;; | ^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:40:5 + --> tests/ui/needless_return.rs:39:5 | LL | return true;; ; ; | ^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:45:9 + --> tests/ui/needless_return.rs:44:9 | LL | return true; | ^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:47:9 + --> tests/ui/needless_return.rs:46:9 | LL | return false; | ^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + false | error: unneeded `return` statement - --> tests/ui/needless_return.rs:53:17 + --> tests/ui/needless_return.rs:52:17 | LL | true => return false, | ^^^^^^^^^^^^ @@ -84,7 +84,7 @@ LL | true => false, | ~~~~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:55:13 + --> tests/ui/needless_return.rs:54:13 | LL | return true; | ^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:62:9 + --> tests/ui/needless_return.rs:61:9 | LL | return true; | ^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:64:16 + --> tests/ui/needless_return.rs:63:16 | LL | let _ = || return true; | ^^^^^^^^^^^ @@ -119,7 +119,7 @@ LL | let _ = || true; | ~~~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:68:5 + --> tests/ui/needless_return.rs:67:5 | LL | return the_answer!(); | ^^^^^^^^^^^^^^^^^^^^ @@ -131,7 +131,7 @@ LL + the_answer!() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:71:21 + --> tests/ui/needless_return.rs:70:21 | LL | fn test_void_fun() { | _____________________^ @@ -146,7 +146,7 @@ LL + fn test_void_fun() { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:76:11 + --> tests/ui/needless_return.rs:75:11 | LL | if b { | ___________^ @@ -161,7 +161,7 @@ LL + if b { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:78:13 + --> tests/ui/needless_return.rs:77:13 | LL | } else { | _____________^ @@ -176,7 +176,7 @@ LL + } else { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:86:14 + --> tests/ui/needless_return.rs:85:14 | LL | _ => return, | ^^^^^^ @@ -187,7 +187,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:94:24 + --> tests/ui/needless_return.rs:93:24 | LL | let _ = 42; | ________________________^ @@ -202,7 +202,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> tests/ui/needless_return.rs:97:14 + --> tests/ui/needless_return.rs:96:14 | LL | _ => return, | ^^^^^^ @@ -213,7 +213,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:110:9 + --> tests/ui/needless_return.rs:109:9 | LL | return String::from("test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -225,7 +225,7 @@ LL + String::from("test") | error: unneeded `return` statement - --> tests/ui/needless_return.rs:112:9 + --> tests/ui/needless_return.rs:111:9 | LL | return String::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -237,7 +237,7 @@ LL + String::new() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:134:32 + --> tests/ui/needless_return.rs:133:32 | LL | bar.unwrap_or_else(|_| return) | ^^^^^^ @@ -248,7 +248,7 @@ LL | bar.unwrap_or_else(|_| {}) | ~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:138:21 + --> tests/ui/needless_return.rs:137:21 | LL | let _ = || { | _____________________^ @@ -263,7 +263,7 @@ LL + let _ = || { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:141:20 + --> tests/ui/needless_return.rs:140:20 | LL | let _ = || return; | ^^^^^^ @@ -274,7 +274,7 @@ LL | let _ = || {}; | ~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:147:32 + --> tests/ui/needless_return.rs:146:32 | LL | res.unwrap_or_else(|_| return Foo) | ^^^^^^^^^^ @@ -285,7 +285,7 @@ LL | res.unwrap_or_else(|_| Foo) | ~~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:156:5 + --> tests/ui/needless_return.rs:155:5 | LL | return true; | ^^^^^^^^^^^ @@ -297,7 +297,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:160:5 + --> tests/ui/needless_return.rs:159:5 | LL | return true; | ^^^^^^^^^^^ @@ -309,7 +309,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:165:9 + --> tests/ui/needless_return.rs:164:9 | LL | return true; | ^^^^^^^^^^^ @@ -321,7 +321,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:167:9 + --> tests/ui/needless_return.rs:166:9 | LL | return false; | ^^^^^^^^^^^^ @@ -333,7 +333,7 @@ LL + false | error: unneeded `return` statement - --> tests/ui/needless_return.rs:173:17 + --> tests/ui/needless_return.rs:172:17 | LL | true => return false, | ^^^^^^^^^^^^ @@ -344,7 +344,7 @@ LL | true => false, | ~~~~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:175:13 + --> tests/ui/needless_return.rs:174:13 | LL | return true; | ^^^^^^^^^^^ @@ -356,7 +356,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:182:9 + --> tests/ui/needless_return.rs:181:9 | LL | return true; | ^^^^^^^^^^^ @@ -368,7 +368,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:184:16 + --> tests/ui/needless_return.rs:183:16 | LL | let _ = || return true; | ^^^^^^^^^^^ @@ -379,7 +379,7 @@ LL | let _ = || true; | ~~~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:188:5 + --> tests/ui/needless_return.rs:187:5 | LL | return the_answer!(); | ^^^^^^^^^^^^^^^^^^^^ @@ -391,7 +391,7 @@ LL + the_answer!() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:191:33 + --> tests/ui/needless_return.rs:190:33 | LL | async fn async_test_void_fun() { | _________________________________^ @@ -406,7 +406,7 @@ LL + async fn async_test_void_fun() { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:196:11 + --> tests/ui/needless_return.rs:195:11 | LL | if b { | ___________^ @@ -421,7 +421,7 @@ LL + if b { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:198:13 + --> tests/ui/needless_return.rs:197:13 | LL | } else { | _____________^ @@ -436,7 +436,7 @@ LL + } else { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:206:14 + --> tests/ui/needless_return.rs:205:14 | LL | _ => return, | ^^^^^^ @@ -447,7 +447,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:219:9 + --> tests/ui/needless_return.rs:218:9 | LL | return String::from("test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -459,7 +459,7 @@ LL + String::from("test") | error: unneeded `return` statement - --> tests/ui/needless_return.rs:221:9 + --> tests/ui/needless_return.rs:220:9 | LL | return String::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -471,7 +471,7 @@ LL + String::new() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:237:5 + --> tests/ui/needless_return.rs:236:5 | LL | return format!("Hello {}", "world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -483,7 +483,7 @@ LL + format!("Hello {}", "world!") | error: unneeded `return` statement - --> tests/ui/needless_return.rs:249:9 + --> tests/ui/needless_return.rs:248:9 | LL | return true; | ^^^^^^^^^^^ @@ -497,7 +497,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:251:9 + --> tests/ui/needless_return.rs:250:9 | LL | return false; | ^^^^^^^^^^^^ @@ -509,7 +509,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:258:13 + --> tests/ui/needless_return.rs:257:13 | LL | return 10; | ^^^^^^^^^ @@ -524,7 +524,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:261:13 + --> tests/ui/needless_return.rs:260:13 | LL | return 100; | ^^^^^^^^^^ @@ -537,7 +537,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:269:9 + --> tests/ui/needless_return.rs:268:9 | LL | return 0; | ^^^^^^^^ @@ -549,7 +549,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:276:13 + --> tests/ui/needless_return.rs:275:13 | LL | return *(x as *const isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -564,7 +564,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:278:13 + --> tests/ui/needless_return.rs:277:13 | LL | return !*(x as *const isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -577,7 +577,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:285:20 + --> tests/ui/needless_return.rs:284:20 | LL | let _ = 42; | ____________________^ @@ -594,7 +594,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> tests/ui/needless_return.rs:292:20 + --> tests/ui/needless_return.rs:291:20 | LL | let _ = 42; return; | ^^^^^^^ @@ -606,7 +606,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> tests/ui/needless_return.rs:304:9 + --> tests/ui/needless_return.rs:303:9 | LL | return Ok(format!("ok!")); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -618,7 +618,7 @@ LL + Ok(format!("ok!")) | error: unneeded `return` statement - --> tests/ui/needless_return.rs:306:9 + --> tests/ui/needless_return.rs:305:9 | LL | return Err(format!("err!")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -630,7 +630,7 @@ LL + Err(format!("err!")) | error: unneeded `return` statement - --> tests/ui/needless_return.rs:312:9 + --> tests/ui/needless_return.rs:311:9 | LL | return if true { 1 } else { 2 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -642,7 +642,7 @@ LL + if true { 1 } else { 2 } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:316:9 + --> tests/ui/needless_return.rs:315:9 | LL | return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -654,7 +654,7 @@ LL + (if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else | error: unneeded `return` statement - --> tests/ui/needless_return.rs:337:5 + --> tests/ui/needless_return.rs:336:5 | LL | return { "a".to_string() } + "b" + { "c" }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/nonminimal_bool.rs b/tests/ui/nonminimal_bool.rs index 38157116e910..d117e8bf9c7a 100644 --- a/tests/ui/nonminimal_bool.rs +++ b/tests/ui/nonminimal_bool.rs @@ -1,6 +1,4 @@ //@no-rustfix: overlapping suggestions - -#![feature(lint_reasons)] #![allow( unused, clippy::diverging_sub_expression, diff --git a/tests/ui/nonminimal_bool.stderr b/tests/ui/nonminimal_bool.stderr index b6af06d845ae..eafffdaf8a63 100644 --- a/tests/ui/nonminimal_bool.stderr +++ b/tests/ui/nonminimal_bool.stderr @@ -1,5 +1,5 @@ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:19:13 + --> tests/ui/nonminimal_bool.rs:17:13 | LL | let _ = !true; | ^^^^^ help: try: `false` @@ -8,43 +8,43 @@ LL | let _ = !true; = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:22:13 + --> tests/ui/nonminimal_bool.rs:20:13 | LL | let _ = !false; | ^^^^^^ help: try: `true` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:24:13 + --> tests/ui/nonminimal_bool.rs:22:13 | LL | let _ = !!a; | ^^^ help: try: `a` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:26:13 + --> tests/ui/nonminimal_bool.rs:24:13 | LL | let _ = false || a; | ^^^^^^^^^^ help: try: `a` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:31:13 + --> tests/ui/nonminimal_bool.rs:29:13 | LL | let _ = !(!a && b); | ^^^^^^^^^^ help: try: `a || !b` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:33:13 + --> tests/ui/nonminimal_bool.rs:31:13 | LL | let _ = !(!a || b); | ^^^^^^^^^^ help: try: `a && !b` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:35:13 + --> tests/ui/nonminimal_bool.rs:33:13 | LL | let _ = !a && !(b && c); | ^^^^^^^^^^^^^^^ help: try: `!(a || b && c)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:44:13 + --> tests/ui/nonminimal_bool.rs:42:13 | LL | let _ = a == b && c == 5 && a == b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | let _ = a == b && c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:46:13 + --> tests/ui/nonminimal_bool.rs:44:13 | LL | let _ = a == b || c == 5 || a == b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -70,7 +70,7 @@ LL | let _ = a == b || c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:48:13 + --> tests/ui/nonminimal_bool.rs:46:13 | LL | let _ = a == b && c == 5 && b == a; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -83,7 +83,7 @@ LL | let _ = a == b && c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:50:13 + --> tests/ui/nonminimal_bool.rs:48:13 | LL | let _ = a != b || !(a != b || c == d); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | let _ = a != b || c != d; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:52:13 + --> tests/ui/nonminimal_bool.rs:50:13 | LL | let _ = a != b && !(a != b && c == d); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,43 +109,43 @@ LL | let _ = a != b && c != d; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:83:8 + --> tests/ui/nonminimal_bool.rs:81:8 | LL | if matches!(true, true) && true { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(true, true)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:163:8 + --> tests/ui/nonminimal_bool.rs:161:8 | LL | if !(12 == a) {} | ^^^^^^^^^^ help: try: `12 != a` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:164:8 + --> tests/ui/nonminimal_bool.rs:162:8 | LL | if !(a == 12) {} | ^^^^^^^^^^ help: try: `a != 12` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:165:8 + --> tests/ui/nonminimal_bool.rs:163:8 | LL | if !(12 != a) {} | ^^^^^^^^^^ help: try: `12 == a` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:166:8 + --> tests/ui/nonminimal_bool.rs:164:8 | LL | if !(a != 12) {} | ^^^^^^^^^^ help: try: `a == 12` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:170:8 + --> tests/ui/nonminimal_bool.rs:168:8 | LL | if !b == true {} | ^^^^^^^^^^ help: try: `b != true` error: this comparison might be written more concisely - --> tests/ui/nonminimal_bool.rs:170:8 + --> tests/ui/nonminimal_bool.rs:168:8 | LL | if !b == true {} | ^^^^^^^^^^ help: try simplifying it as shown: `b != true` @@ -154,61 +154,61 @@ LL | if !b == true {} = help: to override `-D warnings` add `#[allow(clippy::bool_comparison)]` error: equality checks against true are unnecessary - --> tests/ui/nonminimal_bool.rs:170:8 + --> tests/ui/nonminimal_bool.rs:168:8 | LL | if !b == true {} | ^^^^^^^^^^ help: try simplifying it as shown: `!b` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:171:8 + --> tests/ui/nonminimal_bool.rs:169:8 | LL | if !b != true {} | ^^^^^^^^^^ help: try: `b == true` error: inequality checks against true can be replaced by a negation - --> tests/ui/nonminimal_bool.rs:171:8 + --> tests/ui/nonminimal_bool.rs:169:8 | LL | if !b != true {} | ^^^^^^^^^^ help: try simplifying it as shown: `!(!b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:172:8 + --> tests/ui/nonminimal_bool.rs:170:8 | LL | if true == !b {} | ^^^^^^^^^^ help: try: `true != b` error: this comparison might be written more concisely - --> tests/ui/nonminimal_bool.rs:172:8 + --> tests/ui/nonminimal_bool.rs:170:8 | LL | if true == !b {} | ^^^^^^^^^^ help: try simplifying it as shown: `true != b` error: equality checks against true are unnecessary - --> tests/ui/nonminimal_bool.rs:172:8 + --> tests/ui/nonminimal_bool.rs:170:8 | LL | if true == !b {} | ^^^^^^^^^^ help: try simplifying it as shown: `!b` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:173:8 + --> tests/ui/nonminimal_bool.rs:171:8 | LL | if true != !b {} | ^^^^^^^^^^ help: try: `true == b` error: inequality checks against true can be replaced by a negation - --> tests/ui/nonminimal_bool.rs:173:8 + --> tests/ui/nonminimal_bool.rs:171:8 | LL | if true != !b {} | ^^^^^^^^^^ help: try simplifying it as shown: `!(!b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:174:8 + --> tests/ui/nonminimal_bool.rs:172:8 | LL | if !b == !c {} | ^^^^^^^^ help: try: `b == c` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:175:8 + --> tests/ui/nonminimal_bool.rs:173:8 | LL | if !b != !c {} | ^^^^^^^^ help: try: `b != c` diff --git a/tests/ui/overly_complex_bool_expr.fixed b/tests/ui/overly_complex_bool_expr.fixed index 439b1145431c..b21e91aa3ad4 100644 --- a/tests/ui/overly_complex_bool_expr.fixed +++ b/tests/ui/overly_complex_bool_expr.fixed @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![allow(unused, clippy::diverging_sub_expression)] #![warn(clippy::overly_complex_bool_expr)] diff --git a/tests/ui/overly_complex_bool_expr.rs b/tests/ui/overly_complex_bool_expr.rs index b96fd1adf118..35ef0a1240a5 100644 --- a/tests/ui/overly_complex_bool_expr.rs +++ b/tests/ui/overly_complex_bool_expr.rs @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![allow(unused, clippy::diverging_sub_expression)] #![warn(clippy::overly_complex_bool_expr)] diff --git a/tests/ui/overly_complex_bool_expr.stderr b/tests/ui/overly_complex_bool_expr.stderr index 21dd5ade5356..5a754236fe4b 100644 --- a/tests/ui/overly_complex_bool_expr.stderr +++ b/tests/ui/overly_complex_bool_expr.stderr @@ -1,11 +1,11 @@ error: this boolean expression contains a logic bug - --> tests/ui/overly_complex_bool_expr.rs:11:13 + --> tests/ui/overly_complex_bool_expr.rs:10:13 | LL | let _ = a && b || a; | ^^^^^^^^^^^ help: it would look like the following: `a` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> tests/ui/overly_complex_bool_expr.rs:11:18 + --> tests/ui/overly_complex_bool_expr.rs:10:18 | LL | let _ = a && b || a; | ^ @@ -13,49 +13,49 @@ LL | let _ = a && b || a; = help: to override `-D warnings` add `#[allow(clippy::overly_complex_bool_expr)]` error: this boolean expression contains a logic bug - --> tests/ui/overly_complex_bool_expr.rs:14:13 + --> tests/ui/overly_complex_bool_expr.rs:13:13 | LL | let _ = false && a; | ^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> tests/ui/overly_complex_bool_expr.rs:14:22 + --> tests/ui/overly_complex_bool_expr.rs:13:22 | LL | let _ = false && a; | ^ error: this boolean expression contains a logic bug - --> tests/ui/overly_complex_bool_expr.rs:25:13 + --> tests/ui/overly_complex_bool_expr.rs:24:13 | LL | let _ = a == b && a != b; | ^^^^^^^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> tests/ui/overly_complex_bool_expr.rs:25:13 + --> tests/ui/overly_complex_bool_expr.rs:24:13 | LL | let _ = a == b && a != b; | ^^^^^^ error: this boolean expression contains a logic bug - --> tests/ui/overly_complex_bool_expr.rs:27:13 + --> tests/ui/overly_complex_bool_expr.rs:26:13 | LL | let _ = a < b && a >= b; | ^^^^^^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> tests/ui/overly_complex_bool_expr.rs:27:13 + --> tests/ui/overly_complex_bool_expr.rs:26:13 | LL | let _ = a < b && a >= b; | ^^^^^ error: this boolean expression contains a logic bug - --> tests/ui/overly_complex_bool_expr.rs:29:13 + --> tests/ui/overly_complex_bool_expr.rs:28:13 | LL | let _ = a > b && a <= b; | ^^^^^^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> tests/ui/overly_complex_bool_expr.rs:29:13 + --> tests/ui/overly_complex_bool_expr.rs:28:13 | LL | let _ = a > b && a <= b; | ^^^^^ diff --git a/tests/ui/ptr_arg.rs b/tests/ui/ptr_arg.rs index 5d6e488972cd..e6ef62681212 100644 --- a/tests/ui/ptr_arg.rs +++ b/tests/ui/ptr_arg.rs @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![allow( unused, clippy::many_single_char_names, diff --git a/tests/ui/ptr_arg.stderr b/tests/ui/ptr_arg.stderr index 0342130c992b..1848ef80fc49 100644 --- a/tests/ui/ptr_arg.stderr +++ b/tests/ui/ptr_arg.stderr @@ -1,5 +1,5 @@ error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:14:14 + --> tests/ui/ptr_arg.rs:13:14 | LL | fn do_vec(x: &Vec) { | ^^^^^^^^^ help: change this to: `&[i64]` @@ -8,49 +8,49 @@ LL | fn do_vec(x: &Vec) { = help: to override `-D warnings` add `#[allow(clippy::ptr_arg)]` error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:20:18 + --> tests/ui/ptr_arg.rs:19:18 | LL | fn do_vec_mut(x: &mut Vec) { | ^^^^^^^^^^^^^ help: change this to: `&mut [i64]` error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:25:19 + --> tests/ui/ptr_arg.rs:24:19 | LL | fn do_vec_mut2(x: &mut Vec) { | ^^^^^^^^^^^^^ help: change this to: `&mut [i64]` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:31:14 + --> tests/ui/ptr_arg.rs:30:14 | LL | fn do_str(x: &String) { | ^^^^^^^ help: change this to: `&str` error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:36:18 + --> tests/ui/ptr_arg.rs:35:18 | LL | fn do_str_mut(x: &mut String) { | ^^^^^^^^^^^ help: change this to: `&mut str` error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:41:15 + --> tests/ui/ptr_arg.rs:40:15 | LL | fn do_path(x: &PathBuf) { | ^^^^^^^^ help: change this to: `&Path` error: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:46:19 + --> tests/ui/ptr_arg.rs:45:19 | LL | fn do_path_mut(x: &mut PathBuf) { | ^^^^^^^^^^^^ help: change this to: `&mut Path` error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:55:18 + --> tests/ui/ptr_arg.rs:54:18 | LL | fn do_vec(x: &Vec); | ^^^^^^^^^ help: change this to: `&[i64]` error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:69:14 + --> tests/ui/ptr_arg.rs:68:14 | LL | fn cloned(x: &Vec) -> Vec { | ^^^^^^^^ @@ -68,7 +68,7 @@ LL ~ x.to_owned() | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:79:18 + --> tests/ui/ptr_arg.rs:78:18 | LL | fn str_cloned(x: &String) -> String { | ^^^^^^^ @@ -85,7 +85,7 @@ LL ~ x.to_owned() | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:88:19 + --> tests/ui/ptr_arg.rs:87:19 | LL | fn path_cloned(x: &PathBuf) -> PathBuf { | ^^^^^^^^ @@ -102,7 +102,7 @@ LL ~ x.to_path_buf() | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:97:44 + --> tests/ui/ptr_arg.rs:96:44 | LL | fn false_positive_capacity(x: &Vec, y: &String) { | ^^^^^^^ @@ -117,19 +117,19 @@ LL ~ let c = y; | error: using a reference to `Cow` is not recommended - --> tests/ui/ptr_arg.rs:112:25 + --> tests/ui/ptr_arg.rs:111:25 | LL | fn test_cow_with_ref(c: &Cow<[i32]>) {} | ^^^^^^^^^^^ help: change this to: `&[i32]` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:142:66 + --> tests/ui/ptr_arg.rs:141:66 | LL | fn some_allowed(#[allow(clippy::ptr_arg)] _v: &Vec, _s: &String) {} | ^^^^^^^ help: change this to: `&str` error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:172:21 + --> tests/ui/ptr_arg.rs:171:21 | LL | fn foo_vec(vec: &Vec) { | ^^^^^^^^ @@ -143,7 +143,7 @@ LL ~ let _ = vec.to_owned().clone(); | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:178:23 + --> tests/ui/ptr_arg.rs:177:23 | LL | fn foo_path(path: &PathBuf) { | ^^^^^^^^ @@ -157,7 +157,7 @@ LL ~ let _ = path.to_path_buf().clone(); | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:184:21 + --> tests/ui/ptr_arg.rs:183:21 | LL | fn foo_str(str: &PathBuf) { | ^^^^^^^^ @@ -171,43 +171,43 @@ LL ~ let _ = str.to_path_buf().clone(); | error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:191:29 + --> tests/ui/ptr_arg.rs:190:29 | LL | fn mut_vec_slice_methods(v: &mut Vec) { | ^^^^^^^^^^^^^ help: change this to: `&mut [u32]` error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:254:17 + --> tests/ui/ptr_arg.rs:253:17 | LL | fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { | ^^^^^^^^^^^^^ help: change this to: `&mut [u32]` error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:254:35 + --> tests/ui/ptr_arg.rs:253:35 | LL | fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { | ^^^^^^^^^^^ help: change this to: `&mut str` error: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:254:51 + --> tests/ui/ptr_arg.rs:253:51 | LL | fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { | ^^^^^^^^^^^^ help: change this to: `&mut Path` error: using a reference to `Cow` is not recommended - --> tests/ui/ptr_arg.rs:280:39 + --> tests/ui/ptr_arg.rs:279:39 | LL | fn cow_elided_lifetime<'a>(input: &'a Cow) -> &'a str { | ^^^^^^^^^^^^ help: change this to: `&str` error: using a reference to `Cow` is not recommended - --> tests/ui/ptr_arg.rs:286:36 + --> tests/ui/ptr_arg.rs:285:36 | LL | fn cow_bad_ret_ty_1<'a>(input: &'a Cow<'a, str>) -> &'static str { | ^^^^^^^^^^^^^^^^ help: change this to: `&str` error: using a reference to `Cow` is not recommended - --> tests/ui/ptr_arg.rs:290:40 + --> tests/ui/ptr_arg.rs:289:40 | LL | fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str { | ^^^^^^^^^^^^^^^^ help: change this to: `&str` diff --git a/tests/ui/redundant_clone.fixed b/tests/ui/redundant_clone.fixed index 867f5b210171..1f79b5e53600 100644 --- a/tests/ui/redundant_clone.fixed +++ b/tests/ui/redundant_clone.fixed @@ -1,5 +1,4 @@ // rustfix-only-machine-applicable -#![feature(lint_reasons)] #![warn(clippy::redundant_clone)] #![allow( clippy::drop_non_drop, diff --git a/tests/ui/redundant_clone.rs b/tests/ui/redundant_clone.rs index adcbd01e819c..6909faebc993 100644 --- a/tests/ui/redundant_clone.rs +++ b/tests/ui/redundant_clone.rs @@ -1,5 +1,4 @@ // rustfix-only-machine-applicable -#![feature(lint_reasons)] #![warn(clippy::redundant_clone)] #![allow( clippy::drop_non_drop, diff --git a/tests/ui/redundant_clone.stderr b/tests/ui/redundant_clone.stderr index 3c37288f5507..d66972bcb5b3 100644 --- a/tests/ui/redundant_clone.stderr +++ b/tests/ui/redundant_clone.stderr @@ -1,11 +1,11 @@ error: redundant clone - --> tests/ui/redundant_clone.rs:15:42 + --> tests/ui/redundant_clone.rs:14:42 | LL | let _s = ["lorem", "ipsum"].join(" ").to_string(); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:15:14 + --> tests/ui/redundant_clone.rs:14:14 | LL | let _s = ["lorem", "ipsum"].join(" ").to_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,169 +13,169 @@ LL | let _s = ["lorem", "ipsum"].join(" ").to_string(); = help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]` error: redundant clone - --> tests/ui/redundant_clone.rs:18:15 + --> tests/ui/redundant_clone.rs:17:15 | LL | let _s = s.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:18:14 + --> tests/ui/redundant_clone.rs:17:14 | LL | let _s = s.clone(); | ^ error: redundant clone - --> tests/ui/redundant_clone.rs:21:15 + --> tests/ui/redundant_clone.rs:20:15 | LL | let _s = s.to_string(); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:21:14 + --> tests/ui/redundant_clone.rs:20:14 | LL | let _s = s.to_string(); | ^ error: redundant clone - --> tests/ui/redundant_clone.rs:24:15 + --> tests/ui/redundant_clone.rs:23:15 | LL | let _s = s.to_owned(); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:24:14 + --> tests/ui/redundant_clone.rs:23:14 | LL | let _s = s.to_owned(); | ^ error: redundant clone - --> tests/ui/redundant_clone.rs:26:42 + --> tests/ui/redundant_clone.rs:25:42 | LL | let _s = Path::new("/a/b/").join("c").to_owned(); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:26:14 + --> tests/ui/redundant_clone.rs:25:14 | LL | let _s = Path::new("/a/b/").join("c").to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/redundant_clone.rs:28:42 + --> tests/ui/redundant_clone.rs:27:42 | LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); | ^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:28:14 + --> tests/ui/redundant_clone.rs:27:14 | LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/redundant_clone.rs:30:29 + --> tests/ui/redundant_clone.rs:29:29 | LL | let _s = OsString::new().to_owned(); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:30:14 + --> tests/ui/redundant_clone.rs:29:14 | LL | let _s = OsString::new().to_owned(); | ^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/redundant_clone.rs:32:29 + --> tests/ui/redundant_clone.rs:31:29 | LL | let _s = OsString::new().to_os_string(); | ^^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:32:14 + --> tests/ui/redundant_clone.rs:31:14 | LL | let _s = OsString::new().to_os_string(); | ^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/redundant_clone.rs:43:19 + --> tests/ui/redundant_clone.rs:42:19 | LL | let _t = tup.0.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:43:14 + --> tests/ui/redundant_clone.rs:42:14 | LL | let _t = tup.0.clone(); | ^^^^^ error: redundant clone - --> tests/ui/redundant_clone.rs:75:25 + --> tests/ui/redundant_clone.rs:74:25 | LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) } | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:75:24 + --> tests/ui/redundant_clone.rs:74:24 | LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) } | ^ error: redundant clone - --> tests/ui/redundant_clone.rs:132:15 + --> tests/ui/redundant_clone.rs:131:15 | LL | let _s = s.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:132:14 + --> tests/ui/redundant_clone.rs:131:14 | LL | let _s = s.clone(); | ^ error: redundant clone - --> tests/ui/redundant_clone.rs:133:15 + --> tests/ui/redundant_clone.rs:132:15 | LL | let _t = t.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:133:14 + --> tests/ui/redundant_clone.rs:132:14 | LL | let _t = t.clone(); | ^ error: redundant clone - --> tests/ui/redundant_clone.rs:143:19 + --> tests/ui/redundant_clone.rs:142:19 | LL | let _f = f.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:143:18 + --> tests/ui/redundant_clone.rs:142:18 | LL | let _f = f.clone(); | ^ error: redundant clone - --> tests/ui/redundant_clone.rs:155:14 + --> tests/ui/redundant_clone.rs:154:14 | LL | let y = x.clone().join("matthias"); | ^^^^^^^^ help: remove this | note: cloned value is neither consumed nor mutated - --> tests/ui/redundant_clone.rs:155:13 + --> tests/ui/redundant_clone.rs:154:13 | LL | let y = x.clone().join("matthias"); | ^^^^^^^^^ error: redundant clone - --> tests/ui/redundant_clone.rs:209:11 + --> tests/ui/redundant_clone.rs:208:11 | LL | foo(&x.clone(), move || { | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:209:10 + --> tests/ui/redundant_clone.rs:208:10 | LL | foo(&x.clone(), move || { | ^ diff --git a/tests/ui/ref_binding_to_reference.rs b/tests/ui/ref_binding_to_reference.rs index a4444c95e33c..001ed3119490 100644 --- a/tests/ui/ref_binding_to_reference.rs +++ b/tests/ui/ref_binding_to_reference.rs @@ -1,6 +1,5 @@ // FIXME: run-rustfix waiting on multi-span suggestions //@no-rustfix -#![feature(lint_reasons)] #![warn(clippy::ref_binding_to_reference)] #![allow(clippy::needless_borrowed_reference, clippy::explicit_auto_deref)] diff --git a/tests/ui/ref_binding_to_reference.stderr b/tests/ui/ref_binding_to_reference.stderr index 96886f80265d..25ab98223827 100644 --- a/tests/ui/ref_binding_to_reference.stderr +++ b/tests/ui/ref_binding_to_reference.stderr @@ -1,5 +1,5 @@ error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:31:14 + --> tests/ui/ref_binding_to_reference.rs:30:14 | LL | Some(ref x) => x, | ^^^^^ @@ -12,7 +12,7 @@ LL | Some(x) => &x, | ~ ~~ error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:39:14 + --> tests/ui/ref_binding_to_reference.rs:38:14 | LL | Some(ref x) => { | ^^^^^ @@ -27,7 +27,7 @@ LL ~ &x | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:50:14 + --> tests/ui/ref_binding_to_reference.rs:49:14 | LL | Some(ref x) => m2!(x), | ^^^^^ @@ -38,7 +38,7 @@ LL | Some(x) => m2!(&x), | ~ ~~ error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:56:15 + --> tests/ui/ref_binding_to_reference.rs:55:15 | LL | let _ = |&ref x: &&String| { | ^^^^^ @@ -51,7 +51,7 @@ LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:63:12 + --> tests/ui/ref_binding_to_reference.rs:62:12 | LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { | ^^^^^ @@ -65,7 +65,7 @@ LL ~ x | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:71:11 + --> tests/ui/ref_binding_to_reference.rs:70:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -78,7 +78,7 @@ LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:80:11 + --> tests/ui/ref_binding_to_reference.rs:79:11 | LL | fn f(&ref x: &&String) { | ^^^^^ diff --git a/tests/ui/same_name_method.rs b/tests/ui/same_name_method.rs index 26b1a299ba1c..ba876c2b5a3f 100644 --- a/tests/ui/same_name_method.rs +++ b/tests/ui/same_name_method.rs @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![warn(clippy::same_name_method)] #![allow(dead_code, non_camel_case_types)] diff --git a/tests/ui/same_name_method.stderr b/tests/ui/same_name_method.stderr index 6c87a64b5051..fefdb5c9c23d 100644 --- a/tests/ui/same_name_method.stderr +++ b/tests/ui/same_name_method.stderr @@ -1,11 +1,11 @@ error: method's name is the same as an existing method in a trait - --> tests/ui/same_name_method.rs:21:13 + --> tests/ui/same_name_method.rs:20:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> tests/ui/same_name_method.rs:26:13 + --> tests/ui/same_name_method.rs:25:13 | LL | fn foo() {} | ^^^^^^^^^^^ @@ -13,62 +13,62 @@ LL | fn foo() {} = help: to override `-D warnings` add `#[allow(clippy::same_name_method)]` error: method's name is the same as an existing method in a trait - --> tests/ui/same_name_method.rs:36:13 + --> tests/ui/same_name_method.rs:35:13 | LL | fn clone() {} | ^^^^^^^^^^^^^ | note: existing `clone` defined here - --> tests/ui/same_name_method.rs:32:18 + --> tests/ui/same_name_method.rs:31:18 | LL | #[derive(Clone)] | ^^^^^ = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) error: method's name is the same as an existing method in a trait - --> tests/ui/same_name_method.rs:47:13 + --> tests/ui/same_name_method.rs:46:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> tests/ui/same_name_method.rs:52:13 + --> tests/ui/same_name_method.rs:51:13 | LL | fn foo() {} | ^^^^^^^^^^^ error: method's name is the same as an existing method in a trait - --> tests/ui/same_name_method.rs:62:13 + --> tests/ui/same_name_method.rs:61:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> tests/ui/same_name_method.rs:66:9 + --> tests/ui/same_name_method.rs:65:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ error: method's name is the same as an existing method in a trait - --> tests/ui/same_name_method.rs:75:13 + --> tests/ui/same_name_method.rs:74:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> tests/ui/same_name_method.rs:80:9 + --> tests/ui/same_name_method.rs:79:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ error: method's name is the same as an existing method in a trait - --> tests/ui/same_name_method.rs:75:13 + --> tests/ui/same_name_method.rs:74:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> tests/ui/same_name_method.rs:82:9 + --> tests/ui/same_name_method.rs:81:9 | LL | impl T2 for S {} | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unsafe_derive_deserialize.rs b/tests/ui/unsafe_derive_deserialize.rs index 5187e0790423..14371bc203b3 100644 --- a/tests/ui/unsafe_derive_deserialize.rs +++ b/tests/ui/unsafe_derive_deserialize.rs @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![warn(clippy::unsafe_derive_deserialize)] #![allow(unused, clippy::missing_safety_doc)] diff --git a/tests/ui/unsafe_derive_deserialize.stderr b/tests/ui/unsafe_derive_deserialize.stderr index 06719f23d57f..f2d4429f707a 100644 --- a/tests/ui/unsafe_derive_deserialize.stderr +++ b/tests/ui/unsafe_derive_deserialize.stderr @@ -1,5 +1,5 @@ error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> tests/ui/unsafe_derive_deserialize.rs:9:10 + --> tests/ui/unsafe_derive_deserialize.rs:8:10 | LL | #[derive(Deserialize)] | ^^^^^^^^^^^ @@ -10,7 +10,7 @@ LL | #[derive(Deserialize)] = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> tests/ui/unsafe_derive_deserialize.rs:18:10 + --> tests/ui/unsafe_derive_deserialize.rs:17:10 | LL | #[derive(Deserialize)] | ^^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | #[derive(Deserialize)] = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> tests/ui/unsafe_derive_deserialize.rs:25:10 + --> tests/ui/unsafe_derive_deserialize.rs:24:10 | LL | #[derive(Deserialize)] | ^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | #[derive(Deserialize)] = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> tests/ui/unsafe_derive_deserialize.rs:34:10 + --> tests/ui/unsafe_derive_deserialize.rs:33:10 | LL | #[derive(Deserialize)] | ^^^^^^^^^^^ diff --git a/tests/ui/used_underscore_binding.rs b/tests/ui/used_underscore_binding.rs index a8f404b1400c..84dccf28f3b2 100644 --- a/tests/ui/used_underscore_binding.rs +++ b/tests/ui/used_underscore_binding.rs @@ -1,5 +1,5 @@ //@aux-build:proc_macro_derive.rs -#![feature(rustc_private, lint_reasons)] +#![feature(rustc_private)] #![warn(clippy::used_underscore_binding)] #![allow(clippy::disallowed_names, clippy::eq_op, clippy::uninlined_format_args)] From 97f8bc825c075b725b8bb2f445289ae30e93051f Mon Sep 17 00:00:00 2001 From: xFrednet Date: Tue, 4 Jun 2024 11:02:03 +0200 Subject: [PATCH 1222/1222] `sudo CI=green` && Review changes <3 --- .../ui-toml/macro_metavars_in_unsafe/default/test.rs | 2 +- .../macro_metavars_in_unsafe/default/test.stderr | 11 +---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/tests/ui-toml/macro_metavars_in_unsafe/default/test.rs b/tests/ui-toml/macro_metavars_in_unsafe/default/test.rs index f5e01b431ad9..a312df5a43a0 100644 --- a/tests/ui-toml/macro_metavars_in_unsafe/default/test.rs +++ b/tests/ui-toml/macro_metavars_in_unsafe/default/test.rs @@ -1,5 +1,5 @@ //! Tests macro_metavars_in_unsafe with default configuration -#![feature(decl_macro, lint_reasons)] +#![feature(decl_macro)] #![warn(clippy::macro_metavars_in_unsafe)] #![allow(clippy::no_effect)] diff --git a/tests/ui-toml/macro_metavars_in_unsafe/default/test.stderr b/tests/ui-toml/macro_metavars_in_unsafe/default/test.stderr index 138eb6029494..d6b97f6fde1e 100644 --- a/tests/ui-toml/macro_metavars_in_unsafe/default/test.stderr +++ b/tests/ui-toml/macro_metavars_in_unsafe/default/test.stderr @@ -1,12 +1,3 @@ -error: the feature `lint_reasons` has been stable since 1.81.0-dev and no longer requires an attribute to enable - --> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:2:24 - | -LL | #![feature(decl_macro, lint_reasons)] - | ^^^^^^^^^^^^ - | - = note: `-D stable-features` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(stable_features)]` - error: this macro expands metavariables in an unsafe block --> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:19:9 | @@ -192,5 +183,5 @@ LL | | } = help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable = help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite -error: aborting due to 15 previous errors +error: aborting due to 14 previous errors